1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright IBM Corp. 2007
4 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
5 * Frank Pavlic <fpavlic@de.ibm.com>,
6 * Thomas Spatzier <tspat@de.ibm.com>,
7 * Frank Blaschka <frank.blaschka@de.ibm.com>
13 #include "qeth_core.h"
14 #include <linux/hashtable.h>
16 #define QETH_SNIFF_AVAIL 0x0008
19 struct hlist_node hnode;
20 enum qeth_ip_types type;
21 enum qeth_ipa_setdelip_flags set_flags;
22 enum qeth_ipa_setdelip_flags del_flags;
27 /* is changed only for normal ip addresses
28 * for non-normal addresses it always is 1
31 enum qeth_prot_versions proto;
32 unsigned char mac[OSA_ADDR_LEN];
45 static inline bool qeth_l3_addr_match_ip(struct qeth_ipaddr *a1,
46 struct qeth_ipaddr *a2)
48 if (a1->proto != a2->proto)
50 if (a1->proto == QETH_PROT_IPV6)
51 return ipv6_addr_equal(&a1->u.a6.addr, &a2->u.a6.addr);
52 return a1->u.a4.addr == a2->u.a4.addr;
55 static inline bool qeth_l3_addr_match_all(struct qeth_ipaddr *a1,
56 struct qeth_ipaddr *a2)
58 /* Assumes that the pair was obtained via qeth_l3_addr_find_by_ip(),
59 * so 'proto' and 'addr' match for sure.
62 * - 'mac' is always 0.
63 * - 'mask'/'pfxlen' for RXIP/VIPA is always 0. For NORMAL, matching
64 * values are required to avoid mixups in takeover eligibility.
67 * - 'mac' is mapped from the IP, and thus always matches.
68 * - 'mask'/'pfxlen' is always 0.
70 if (a1->type != a2->type)
72 if (a1->proto == QETH_PROT_IPV6)
73 return a1->u.a6.pfxlen == a2->u.a6.pfxlen;
74 return a1->u.a4.mask == a2->u.a4.mask;
77 static inline u64 qeth_l3_ipaddr_hash(struct qeth_ipaddr *addr)
82 if (addr->proto == QETH_PROT_IPV6) {
83 point = (u8 *) &addr->u.a6.addr;
84 ret = get_unaligned((u64 *)point) ^
85 get_unaligned((u64 *) (point + 8));
87 if (addr->proto == QETH_PROT_IPV4) {
88 point = (u8 *) &addr->u.a4.addr;
89 ret = get_unaligned((u32 *) point);
94 struct qeth_ipato_entry {
95 struct list_head entry;
96 enum qeth_prot_versions proto;
101 extern const struct attribute_group *qeth_l3_attr_groups[];
103 void qeth_l3_ipaddr_to_string(enum qeth_prot_versions, const __u8 *, char *);
104 int qeth_l3_string_to_ipaddr(const char *, enum qeth_prot_versions, __u8 *);
105 int qeth_l3_create_device_attributes(struct device *);
106 void qeth_l3_remove_device_attributes(struct device *);
107 int qeth_l3_setrouting_v4(struct qeth_card *);
108 int qeth_l3_setrouting_v6(struct qeth_card *);
109 int qeth_l3_add_ipato_entry(struct qeth_card *, struct qeth_ipato_entry *);
110 void qeth_l3_del_ipato_entry(struct qeth_card *, enum qeth_prot_versions,
112 int qeth_l3_add_vipa(struct qeth_card *, enum qeth_prot_versions, const u8 *);
113 void qeth_l3_del_vipa(struct qeth_card *, enum qeth_prot_versions, const u8 *);
114 int qeth_l3_add_rxip(struct qeth_card *, enum qeth_prot_versions, const u8 *);
115 void qeth_l3_del_rxip(struct qeth_card *card, enum qeth_prot_versions,
117 void qeth_l3_update_ipato(struct qeth_card *card);
118 struct qeth_ipaddr *qeth_l3_get_addr_buffer(enum qeth_prot_versions);
119 int qeth_l3_add_ip(struct qeth_card *, struct qeth_ipaddr *);
120 int qeth_l3_delete_ip(struct qeth_card *, struct qeth_ipaddr *);
122 #endif /* __QETH_L3_H__ */