• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *    Copyright IBM Corp. 2007
3  *    Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
4  *		 Frank Pavlic <fpavlic@de.ibm.com>,
5  *		 Thomas Spatzier <tspat@de.ibm.com>,
6  *		 Frank Blaschka <frank.blaschka@de.ibm.com>
7  */
8 
9 #ifndef __QETH_L3_H__
10 #define __QETH_L3_H__
11 
12 #include "qeth_core.h"
13 #include <linux/hashtable.h>
14 
15 #define QETH_SNIFF_AVAIL	0x0008
16 
17 struct qeth_ipaddr {
18 	struct hlist_node hnode;
19 	enum qeth_ip_types type;
20 	enum qeth_ipa_setdelip_flags set_flags;
21 	enum qeth_ipa_setdelip_flags del_flags;
22 	u8 is_multicast:1;
23 	u8 in_progress:1;
24 	u8 disp_flag:2;
25 
26 	/* is changed only for normal ip addresses
27 	 * for non-normal addresses it always is  1
28 	 */
29 	int  ref_counter;
30 	enum qeth_prot_versions proto;
31 	unsigned char mac[OSA_ADDR_LEN];
32 	union {
33 		struct {
34 			unsigned int addr;
35 			unsigned int mask;
36 		} a4;
37 		struct {
38 			struct in6_addr addr;
39 			unsigned int pfxlen;
40 		} a6;
41 	} u;
42 };
43 
qeth_l3_addr_match_ip(struct qeth_ipaddr * a1,struct qeth_ipaddr * a2)44 static inline bool qeth_l3_addr_match_ip(struct qeth_ipaddr *a1,
45 					 struct qeth_ipaddr *a2)
46 {
47 	if (a1->proto != a2->proto)
48 		return false;
49 	if (a1->proto == QETH_PROT_IPV6)
50 		return ipv6_addr_equal(&a1->u.a6.addr, &a2->u.a6.addr);
51 	return a1->u.a4.addr == a2->u.a4.addr;
52 }
53 
qeth_l3_addr_match_all(struct qeth_ipaddr * a1,struct qeth_ipaddr * a2)54 static inline bool qeth_l3_addr_match_all(struct qeth_ipaddr *a1,
55 					  struct qeth_ipaddr *a2)
56 {
57 	/* Assumes that the pair was obtained via qeth_l3_addr_find_by_ip(),
58 	 * so 'proto' and 'addr' match for sure.
59 	 *
60 	 * For ucast:
61 	 * -	'mac' is always 0.
62 	 * -	'mask'/'pfxlen' for RXIP/VIPA is always 0. For NORMAL, matching
63 	 *	values are required to avoid mixups in takeover eligibility.
64 	 *
65 	 * For mcast,
66 	 * -	'mac' is mapped from the IP, and thus always matches.
67 	 * -	'mask'/'pfxlen' is always 0.
68 	 */
69 	if (a1->type != a2->type)
70 		return false;
71 	if (a1->proto == QETH_PROT_IPV6)
72 		return a1->u.a6.pfxlen == a2->u.a6.pfxlen;
73 	return a1->u.a4.mask == a2->u.a4.mask;
74 }
75 
qeth_l3_ipaddr_hash(struct qeth_ipaddr * addr)76 static inline  u64 qeth_l3_ipaddr_hash(struct qeth_ipaddr *addr)
77 {
78 	u64  ret = 0;
79 	u8 *point;
80 
81 	if (addr->proto == QETH_PROT_IPV6) {
82 		point = (u8 *) &addr->u.a6.addr;
83 		ret = get_unaligned((u64 *)point) ^
84 			get_unaligned((u64 *) (point + 8));
85 	}
86 	if (addr->proto == QETH_PROT_IPV4) {
87 		point = (u8 *) &addr->u.a4.addr;
88 		ret = get_unaligned((u32 *) point);
89 	}
90 	return ret;
91 }
92 
93 struct qeth_ipato_entry {
94 	struct list_head entry;
95 	enum qeth_prot_versions proto;
96 	char addr[16];
97 	int mask_bits;
98 };
99 
100 
101 void qeth_l3_ipaddr_to_string(enum qeth_prot_versions, const __u8 *, char *);
102 int qeth_l3_string_to_ipaddr(const char *, enum qeth_prot_versions, __u8 *);
103 int qeth_l3_create_device_attributes(struct device *);
104 void qeth_l3_remove_device_attributes(struct device *);
105 int qeth_l3_setrouting_v4(struct qeth_card *);
106 int qeth_l3_setrouting_v6(struct qeth_card *);
107 int qeth_l3_add_ipato_entry(struct qeth_card *, struct qeth_ipato_entry *);
108 void qeth_l3_del_ipato_entry(struct qeth_card *, enum qeth_prot_versions,
109 			u8 *, int);
110 int qeth_l3_add_vipa(struct qeth_card *, enum qeth_prot_versions, const u8 *);
111 void qeth_l3_del_vipa(struct qeth_card *, enum qeth_prot_versions, const u8 *);
112 int qeth_l3_add_rxip(struct qeth_card *, enum qeth_prot_versions, const u8 *);
113 void qeth_l3_del_rxip(struct qeth_card *card, enum qeth_prot_versions,
114 			const u8 *);
115 void qeth_l3_update_ipato(struct qeth_card *card);
116 struct qeth_ipaddr *qeth_l3_get_addr_buffer(enum qeth_prot_versions);
117 int qeth_l3_add_ip(struct qeth_card *, struct qeth_ipaddr *);
118 int qeth_l3_delete_ip(struct qeth_card *, struct qeth_ipaddr *);
119 
120 #endif /* __QETH_L3_H__ */
121