Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  *    Copyright IBM Corp. 2007
0004  *    Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
0005  *       Frank Pavlic <fpavlic@de.ibm.com>,
0006  *       Thomas Spatzier <tspat@de.ibm.com>,
0007  *       Frank Blaschka <frank.blaschka@de.ibm.com>
0008  */
0009 
0010 #ifndef __QETH_L3_H__
0011 #define __QETH_L3_H__
0012 
0013 #include "qeth_core.h"
0014 #include <linux/hashtable.h>
0015 
0016 enum qeth_ip_types {
0017     QETH_IP_TYPE_NORMAL,
0018     QETH_IP_TYPE_VIPA,
0019     QETH_IP_TYPE_RXIP,
0020 };
0021 
0022 struct qeth_ipaddr {
0023     struct hlist_node hnode;
0024     enum qeth_ip_types type;
0025     u8 is_multicast:1;
0026     u8 disp_flag:2;
0027     u8 ipato:1;         /* ucast only */
0028 
0029     /* is changed only for normal ip addresses
0030      * for non-normal addresses it always is  1
0031      */
0032     int  ref_counter;
0033     enum qeth_prot_versions proto;
0034     union {
0035         struct {
0036             __be32 addr;
0037             __be32 mask;
0038         } a4;
0039         struct {
0040             struct in6_addr addr;
0041             unsigned int pfxlen;
0042         } a6;
0043     } u;
0044 };
0045 
0046 static inline void qeth_l3_init_ipaddr(struct qeth_ipaddr *addr,
0047                        enum qeth_ip_types type,
0048                        enum qeth_prot_versions proto)
0049 {
0050     memset(addr, 0, sizeof(*addr));
0051     addr->type = type;
0052     addr->proto = proto;
0053     addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
0054     addr->ref_counter = 1;
0055 }
0056 
0057 static inline bool qeth_l3_addr_match_ip(struct qeth_ipaddr *a1,
0058                      struct qeth_ipaddr *a2)
0059 {
0060     if (a1->proto != a2->proto)
0061         return false;
0062     if (a1->proto == QETH_PROT_IPV6)
0063         return ipv6_addr_equal(&a1->u.a6.addr, &a2->u.a6.addr);
0064     return a1->u.a4.addr == a2->u.a4.addr;
0065 }
0066 
0067 static inline bool qeth_l3_addr_match_all(struct qeth_ipaddr *a1,
0068                       struct qeth_ipaddr *a2)
0069 {
0070     /* Assumes that the pair was obtained via qeth_l3_addr_find_by_ip(),
0071      * so 'proto' and 'addr' match for sure.
0072      *
0073      * For ucast:
0074      * -    'mask'/'pfxlen' for RXIP/VIPA is always 0. For NORMAL, matching
0075      *  values are required to avoid mixups in takeover eligibility.
0076      *
0077      * For mcast,
0078      * -    'mask'/'pfxlen' is always 0.
0079      */
0080     if (a1->type != a2->type)
0081         return false;
0082     if (a1->proto == QETH_PROT_IPV6)
0083         return a1->u.a6.pfxlen == a2->u.a6.pfxlen;
0084     return a1->u.a4.mask == a2->u.a4.mask;
0085 }
0086 
0087 static inline u32 qeth_l3_ipaddr_hash(struct qeth_ipaddr *addr)
0088 {
0089     if (addr->proto == QETH_PROT_IPV6)
0090         return ipv6_addr_hash(&addr->u.a6.addr);
0091     else
0092         return ipv4_addr_hash(addr->u.a4.addr);
0093 }
0094 
0095 struct qeth_ipato_entry {
0096     struct list_head entry;
0097     enum qeth_prot_versions proto;
0098     char addr[16];
0099     unsigned int mask_bits;
0100 };
0101 
0102 extern const struct attribute_group *qeth_l3_attr_groups[];
0103 
0104 int qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const u8 *addr,
0105                  char *buf);
0106 int qeth_l3_setrouting_v4(struct qeth_card *);
0107 int qeth_l3_setrouting_v6(struct qeth_card *);
0108 int qeth_l3_add_ipato_entry(struct qeth_card *, struct qeth_ipato_entry *);
0109 int qeth_l3_del_ipato_entry(struct qeth_card *card,
0110                 enum qeth_prot_versions proto, u8 *addr,
0111                 unsigned int mask_bits);
0112 void qeth_l3_update_ipato(struct qeth_card *card);
0113 int qeth_l3_modify_hsuid(struct qeth_card *card, bool add);
0114 int qeth_l3_modify_rxip_vipa(struct qeth_card *card, bool add, const u8 *ip,
0115                  enum qeth_ip_types type,
0116                  enum qeth_prot_versions proto);
0117 
0118 #endif /* __QETH_L3_H__ */