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