brintos

brintos / linux-shallow public Read only

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