Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  *  inet6 interface/address list definitions
0004  *  Linux INET6 implementation 
0005  *
0006  *  Authors:
0007  *  Pedro Roque     <roque@di.fc.ul.pt> 
0008  */
0009 
0010 #ifndef _NET_IF_INET6_H
0011 #define _NET_IF_INET6_H
0012 
0013 #include <net/snmp.h>
0014 #include <linux/ipv6.h>
0015 #include <linux/refcount.h>
0016 
0017 /* inet6_dev.if_flags */
0018 
0019 #define IF_RA_OTHERCONF 0x80
0020 #define IF_RA_MANAGED   0x40
0021 #define IF_RA_RCVD  0x20
0022 #define IF_RS_SENT  0x10
0023 #define IF_READY    0x80000000
0024 
0025 /* prefix flags */
0026 #define IF_PREFIX_ONLINK    0x01
0027 #define IF_PREFIX_AUTOCONF  0x02
0028 
0029 enum {
0030     INET6_IFADDR_STATE_PREDAD,
0031     INET6_IFADDR_STATE_DAD,
0032     INET6_IFADDR_STATE_POSTDAD,
0033     INET6_IFADDR_STATE_ERRDAD,
0034     INET6_IFADDR_STATE_DEAD,
0035 };
0036 
0037 struct inet6_ifaddr {
0038     struct in6_addr     addr;
0039     __u32           prefix_len;
0040     __u32           rt_priority;
0041 
0042     /* In seconds, relative to tstamp. Expiry is at tstamp + HZ * lft. */
0043     __u32           valid_lft;
0044     __u32           prefered_lft;
0045     refcount_t      refcnt;
0046     spinlock_t      lock;
0047 
0048     int         state;
0049 
0050     __u32           flags;
0051     __u8            dad_probes;
0052     __u8            stable_privacy_retry;
0053 
0054     __u16           scope;
0055     __u64           dad_nonce;
0056 
0057     unsigned long       cstamp; /* created timestamp */
0058     unsigned long       tstamp; /* updated timestamp */
0059 
0060     struct delayed_work dad_work;
0061 
0062     struct inet6_dev    *idev;
0063     struct fib6_info    *rt;
0064 
0065     struct hlist_node   addr_lst;
0066     struct list_head    if_list;
0067     /*
0068      * Used to safely traverse idev->addr_list in process context
0069      * if the idev->lock needed to protect idev->addr_list cannot be held.
0070      * In that case, add the items to this list temporarily and iterate
0071      * without holding idev->lock.
0072      * See addrconf_ifdown and dev_forward_change.
0073      */
0074     struct list_head    if_list_aux;
0075 
0076     struct list_head    tmp_list;
0077     struct inet6_ifaddr *ifpub;
0078     int         regen_count;
0079 
0080     bool            tokenized;
0081 
0082     u8          ifa_proto;
0083 
0084     struct rcu_head     rcu;
0085     struct in6_addr     peer_addr;
0086 };
0087 
0088 struct ip6_sf_socklist {
0089     unsigned int        sl_max;
0090     unsigned int        sl_count;
0091     struct rcu_head     rcu;
0092     struct in6_addr     sl_addr[];
0093 };
0094 
0095 #define IP6_SFBLOCK 10  /* allocate this many at once */
0096 
0097 struct ipv6_mc_socklist {
0098     struct in6_addr     addr;
0099     int         ifindex;
0100     unsigned int        sfmode;     /* MCAST_{INCLUDE,EXCLUDE} */
0101     struct ipv6_mc_socklist __rcu *next;
0102     struct ip6_sf_socklist  __rcu *sflist;
0103     struct rcu_head     rcu;
0104 };
0105 
0106 struct ip6_sf_list {
0107     struct ip6_sf_list __rcu *sf_next;
0108     struct in6_addr     sf_addr;
0109     unsigned long       sf_count[2];    /* include/exclude counts */
0110     unsigned char       sf_gsresp;  /* include in g & s response? */
0111     unsigned char       sf_oldin;   /* change state */
0112     unsigned char       sf_crcount; /* retrans. left to send */
0113     struct rcu_head     rcu;
0114 };
0115 
0116 #define MAF_TIMER_RUNNING   0x01
0117 #define MAF_LAST_REPORTER   0x02
0118 #define MAF_LOADED      0x04
0119 #define MAF_NOREPORT        0x08
0120 #define MAF_GSQUERY     0x10
0121 
0122 struct ifmcaddr6 {
0123     struct in6_addr     mca_addr;
0124     struct inet6_dev    *idev;
0125     struct ifmcaddr6    __rcu *next;
0126     struct ip6_sf_list  __rcu *mca_sources;
0127     struct ip6_sf_list  __rcu *mca_tomb;
0128     unsigned int        mca_sfmode;
0129     unsigned char       mca_crcount;
0130     unsigned long       mca_sfcount[2];
0131     struct delayed_work mca_work;
0132     unsigned int        mca_flags;
0133     int         mca_users;
0134     refcount_t      mca_refcnt;
0135     unsigned long       mca_cstamp;
0136     unsigned long       mca_tstamp;
0137     struct rcu_head     rcu;
0138 };
0139 
0140 /* Anycast stuff */
0141 
0142 struct ipv6_ac_socklist {
0143     struct in6_addr     acl_addr;
0144     int         acl_ifindex;
0145     struct ipv6_ac_socklist *acl_next;
0146 };
0147 
0148 struct ifacaddr6 {
0149     struct in6_addr     aca_addr;
0150     struct fib6_info    *aca_rt;
0151     struct ifacaddr6    *aca_next;
0152     struct hlist_node   aca_addr_lst;
0153     int         aca_users;
0154     refcount_t      aca_refcnt;
0155     unsigned long       aca_cstamp;
0156     unsigned long       aca_tstamp;
0157     struct rcu_head     rcu;
0158 };
0159 
0160 #define IFA_HOST    IPV6_ADDR_LOOPBACK
0161 #define IFA_LINK    IPV6_ADDR_LINKLOCAL
0162 #define IFA_SITE    IPV6_ADDR_SITELOCAL
0163 
0164 struct ipv6_devstat {
0165     struct proc_dir_entry   *proc_dir_entry;
0166     DEFINE_SNMP_STAT(struct ipstats_mib, ipv6);
0167     DEFINE_SNMP_STAT_ATOMIC(struct icmpv6_mib_device, icmpv6dev);
0168     DEFINE_SNMP_STAT_ATOMIC(struct icmpv6msg_mib_device, icmpv6msgdev);
0169 };
0170 
0171 struct inet6_dev {
0172     struct net_device   *dev;
0173     netdevice_tracker   dev_tracker;
0174 
0175     struct list_head    addr_list;
0176 
0177     struct ifmcaddr6    __rcu *mc_list;
0178     struct ifmcaddr6    __rcu *mc_tomb;
0179 
0180     unsigned char       mc_qrv;     /* Query Robustness Variable */
0181     unsigned char       mc_gq_running;
0182     unsigned char       mc_ifc_count;
0183     unsigned char       mc_dad_count;
0184 
0185     unsigned long       mc_v1_seen; /* Max time we stay in MLDv1 mode */
0186     unsigned long       mc_qi;      /* Query Interval */
0187     unsigned long       mc_qri;     /* Query Response Interval */
0188     unsigned long       mc_maxdelay;
0189 
0190     struct delayed_work mc_gq_work; /* general query work */
0191     struct delayed_work mc_ifc_work;    /* interface change work */
0192     struct delayed_work mc_dad_work;    /* dad complete mc work */
0193     struct delayed_work mc_query_work;  /* mld query work */
0194     struct delayed_work mc_report_work; /* mld report work */
0195 
0196     struct sk_buff_head mc_query_queue;     /* mld query queue */
0197     struct sk_buff_head mc_report_queue;    /* mld report queue */
0198 
0199     spinlock_t      mc_query_lock;  /* mld query queue lock */
0200     spinlock_t      mc_report_lock; /* mld query report lock */
0201     struct mutex        mc_lock;    /* mld global lock */
0202 
0203     struct ifacaddr6    *ac_list;
0204     rwlock_t        lock;
0205     refcount_t      refcnt;
0206     __u32           if_flags;
0207     int         dead;
0208 
0209     u32         desync_factor;
0210     struct list_head    tempaddr_list;
0211 
0212     struct in6_addr     token;
0213 
0214     struct neigh_parms  *nd_parms;
0215     struct ipv6_devconf cnf;
0216     struct ipv6_devstat stats;
0217 
0218     struct timer_list   rs_timer;
0219     __s32           rs_interval;    /* in jiffies */
0220     __u8            rs_probes;
0221 
0222     unsigned long       tstamp; /* ipv6InterfaceTable update timestamp */
0223     struct rcu_head     rcu;
0224 
0225     unsigned int        ra_mtu;
0226 };
0227 
0228 static inline void ipv6_eth_mc_map(const struct in6_addr *addr, char *buf)
0229 {
0230     /*
0231      *  +-------+-------+-------+-------+-------+-------+
0232      *      |   33  |   33  | DST13 | DST14 | DST15 | DST16 |
0233      *      +-------+-------+-------+-------+-------+-------+
0234      */
0235 
0236     buf[0]= 0x33;
0237     buf[1]= 0x33;
0238 
0239     memcpy(buf + 2, &addr->s6_addr32[3], sizeof(__u32));
0240 }
0241 
0242 static inline void ipv6_arcnet_mc_map(const struct in6_addr *addr, char *buf)
0243 {
0244     buf[0] = 0x00;
0245 }
0246 
0247 static inline void ipv6_ib_mc_map(const struct in6_addr *addr,
0248                   const unsigned char *broadcast, char *buf)
0249 {
0250     unsigned char scope = broadcast[5] & 0xF;
0251 
0252     buf[0]  = 0;        /* Reserved */
0253     buf[1]  = 0xff;     /* Multicast QPN */
0254     buf[2]  = 0xff;
0255     buf[3]  = 0xff;
0256     buf[4]  = 0xff;
0257     buf[5]  = 0x10 | scope; /* scope from broadcast address */
0258     buf[6]  = 0x60;     /* IPv6 signature */
0259     buf[7]  = 0x1b;
0260     buf[8]  = broadcast[8]; /* P_Key */
0261     buf[9]  = broadcast[9];
0262     memcpy(buf + 10, addr->s6_addr + 6, 10);
0263 }
0264 
0265 static inline int ipv6_ipgre_mc_map(const struct in6_addr *addr,
0266                     const unsigned char *broadcast, char *buf)
0267 {
0268     if ((broadcast[0] | broadcast[1] | broadcast[2] | broadcast[3]) != 0) {
0269         memcpy(buf, broadcast, 4);
0270     } else {
0271         /* v4mapped? */
0272         if ((addr->s6_addr32[0] | addr->s6_addr32[1] |
0273              (addr->s6_addr32[2] ^ htonl(0x0000ffff))) != 0)
0274             return -EINVAL;
0275         memcpy(buf, &addr->s6_addr32[3], 4);
0276     }
0277     return 0;
0278 }
0279 
0280 #endif