Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _IPV6_H
0003 #define _IPV6_H
0004 
0005 #include <uapi/linux/ipv6.h>
0006 
0007 #define ipv6_optlen(p)  (((p)->hdrlen+1) << 3)
0008 #define ipv6_authlen(p) (((p)->hdrlen+2) << 2)
0009 /*
0010  * This structure contains configuration options per IPv6 link.
0011  */
0012 struct ipv6_devconf {
0013     __s32       forwarding;
0014     __s32       hop_limit;
0015     __s32       mtu6;
0016     __s32       accept_ra;
0017     __s32       accept_redirects;
0018     __s32       autoconf;
0019     __s32       dad_transmits;
0020     __s32       rtr_solicits;
0021     __s32       rtr_solicit_interval;
0022     __s32       rtr_solicit_max_interval;
0023     __s32       rtr_solicit_delay;
0024     __s32       force_mld_version;
0025     __s32       mldv1_unsolicited_report_interval;
0026     __s32       mldv2_unsolicited_report_interval;
0027     __s32       use_tempaddr;
0028     __s32       temp_valid_lft;
0029     __s32       temp_prefered_lft;
0030     __s32       regen_max_retry;
0031     __s32       max_desync_factor;
0032     __s32       max_addresses;
0033     __s32       accept_ra_defrtr;
0034     __u32       ra_defrtr_metric;
0035     __s32       accept_ra_min_hop_limit;
0036     __s32       accept_ra_pinfo;
0037     __s32       ignore_routes_with_linkdown;
0038 #ifdef CONFIG_IPV6_ROUTER_PREF
0039     __s32       accept_ra_rtr_pref;
0040     __s32       rtr_probe_interval;
0041 #ifdef CONFIG_IPV6_ROUTE_INFO
0042     __s32       accept_ra_rt_info_min_plen;
0043     __s32       accept_ra_rt_info_max_plen;
0044 #endif
0045 #endif
0046     __s32       proxy_ndp;
0047     __s32       accept_source_route;
0048     __s32       accept_ra_from_local;
0049 #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
0050     __s32       optimistic_dad;
0051     __s32       use_optimistic;
0052 #endif
0053 #ifdef CONFIG_IPV6_MROUTE
0054     atomic_t    mc_forwarding;
0055 #endif
0056     __s32       disable_ipv6;
0057     __s32       drop_unicast_in_l2_multicast;
0058     __s32       accept_dad;
0059     __s32       force_tllao;
0060     __s32           ndisc_notify;
0061     __s32       suppress_frag_ndisc;
0062     __s32       accept_ra_mtu;
0063     __s32       drop_unsolicited_na;
0064     __s32       accept_untracked_na;
0065     struct ipv6_stable_secret {
0066         bool initialized;
0067         struct in6_addr secret;
0068     } stable_secret;
0069     __s32       use_oif_addrs_only;
0070     __s32       keep_addr_on_down;
0071     __s32       seg6_enabled;
0072 #ifdef CONFIG_IPV6_SEG6_HMAC
0073     __s32       seg6_require_hmac;
0074 #endif
0075     __u32       enhanced_dad;
0076     __u32       addr_gen_mode;
0077     __s32       disable_policy;
0078     __s32           ndisc_tclass;
0079     __s32       rpl_seg_enabled;
0080     __u32       ioam6_id;
0081     __u32       ioam6_id_wide;
0082     __u8        ioam6_enabled;
0083     __u8        ndisc_evict_nocarrier;
0084 
0085     struct ctl_table_header *sysctl_header;
0086 };
0087 
0088 struct ipv6_params {
0089     __s32 disable_ipv6;
0090     __s32 autoconf;
0091 };
0092 extern struct ipv6_params ipv6_defaults;
0093 #include <linux/tcp.h>
0094 #include <linux/udp.h>
0095 
0096 #include <net/inet_sock.h>
0097 
0098 static inline struct ipv6hdr *ipv6_hdr(const struct sk_buff *skb)
0099 {
0100     return (struct ipv6hdr *)skb_network_header(skb);
0101 }
0102 
0103 static inline struct ipv6hdr *inner_ipv6_hdr(const struct sk_buff *skb)
0104 {
0105     return (struct ipv6hdr *)skb_inner_network_header(skb);
0106 }
0107 
0108 static inline struct ipv6hdr *ipipv6_hdr(const struct sk_buff *skb)
0109 {
0110     return (struct ipv6hdr *)skb_transport_header(skb);
0111 }
0112 
0113 static inline unsigned int ipv6_transport_len(const struct sk_buff *skb)
0114 {
0115     return ntohs(ipv6_hdr(skb)->payload_len) + sizeof(struct ipv6hdr) -
0116            skb_network_header_len(skb);
0117 }
0118 
0119 /* 
0120    This structure contains results of exthdrs parsing
0121    as offsets from skb->nh.
0122  */
0123 
0124 struct inet6_skb_parm {
0125     int         iif;
0126     __be16          ra;
0127     __u16           dst0;
0128     __u16           srcrt;
0129     __u16           dst1;
0130     __u16           lastopt;
0131     __u16           nhoff;
0132     __u16           flags;
0133 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
0134     __u16           dsthao;
0135 #endif
0136     __u16           frag_max_size;
0137     __u16           srhoff;
0138 
0139 #define IP6SKB_XFRM_TRANSFORMED 1
0140 #define IP6SKB_FORWARDED    2
0141 #define IP6SKB_REROUTED     4
0142 #define IP6SKB_ROUTERALERT  8
0143 #define IP6SKB_FRAGMENTED      16
0144 #define IP6SKB_HOPBYHOP        32
0145 #define IP6SKB_L3SLAVE         64
0146 #define IP6SKB_JUMBOGRAM      128
0147 #define IP6SKB_SEG6       256
0148 #define IP6SKB_FAKEJUMBO      512
0149 };
0150 
0151 #if defined(CONFIG_NET_L3_MASTER_DEV)
0152 static inline bool ipv6_l3mdev_skb(__u16 flags)
0153 {
0154     return flags & IP6SKB_L3SLAVE;
0155 }
0156 #else
0157 static inline bool ipv6_l3mdev_skb(__u16 flags)
0158 {
0159     return false;
0160 }
0161 #endif
0162 
0163 #define IP6CB(skb)  ((struct inet6_skb_parm*)((skb)->cb))
0164 #define IP6CBMTU(skb)   ((struct ip6_mtuinfo *)((skb)->cb))
0165 
0166 static inline int inet6_iif(const struct sk_buff *skb)
0167 {
0168     bool l3_slave = ipv6_l3mdev_skb(IP6CB(skb)->flags);
0169 
0170     return l3_slave ? skb->skb_iif : IP6CB(skb)->iif;
0171 }
0172 
0173 static inline bool inet6_is_jumbogram(const struct sk_buff *skb)
0174 {
0175     return !!(IP6CB(skb)->flags & IP6SKB_JUMBOGRAM);
0176 }
0177 
0178 /* can not be used in TCP layer after tcp_v6_fill_cb */
0179 static inline int inet6_sdif(const struct sk_buff *skb)
0180 {
0181 #if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV)
0182     if (skb && ipv6_l3mdev_skb(IP6CB(skb)->flags))
0183         return IP6CB(skb)->iif;
0184 #endif
0185     return 0;
0186 }
0187 
0188 struct tcp6_request_sock {
0189     struct tcp_request_sock   tcp6rsk_tcp;
0190 };
0191 
0192 struct ipv6_mc_socklist;
0193 struct ipv6_ac_socklist;
0194 struct ipv6_fl_socklist;
0195 
0196 struct inet6_cork {
0197     struct ipv6_txoptions *opt;
0198     u8 hop_limit;
0199     u8 tclass;
0200 };
0201 
0202 /**
0203  * struct ipv6_pinfo - ipv6 private area
0204  *
0205  * In the struct sock hierarchy (tcp6_sock, upd6_sock, etc)
0206  * this _must_ be the last member, so that inet6_sk_generic
0207  * is able to calculate its offset from the base struct sock
0208  * by using the struct proto->slab_obj_size member. -acme
0209  */
0210 struct ipv6_pinfo {
0211     struct in6_addr     saddr;
0212     struct in6_pktinfo  sticky_pktinfo;
0213     const struct in6_addr       *daddr_cache;
0214 #ifdef CONFIG_IPV6_SUBTREES
0215     const struct in6_addr       *saddr_cache;
0216 #endif
0217 
0218     __be32          flow_label;
0219     __u32           frag_size;
0220 
0221     /*
0222      * Packed in 16bits.
0223      * Omit one shift by putting the signed field at MSB.
0224      */
0225 #if defined(__BIG_ENDIAN_BITFIELD)
0226     __s16           hop_limit:9;
0227     __u16           __unused_1:7;
0228 #else
0229     __u16           __unused_1:7;
0230     __s16           hop_limit:9;
0231 #endif
0232 
0233 #if defined(__BIG_ENDIAN_BITFIELD)
0234     /* Packed in 16bits. */
0235     __s16           mcast_hops:9;
0236     __u16           __unused_2:6,
0237                 mc_loop:1;
0238 #else
0239     __u16           mc_loop:1,
0240                 __unused_2:6;
0241     __s16           mcast_hops:9;
0242 #endif
0243     int         ucast_oif;
0244     int         mcast_oif;
0245 
0246     /* pktoption flags */
0247     union {
0248         struct {
0249             __u16   srcrt:1,
0250                 osrcrt:1,
0251                     rxinfo:1,
0252                     rxoinfo:1,
0253                 rxhlim:1,
0254                 rxohlim:1,
0255                 hopopts:1,
0256                 ohopopts:1,
0257                 dstopts:1,
0258                 odstopts:1,
0259                                 rxflow:1,
0260                 rxtclass:1,
0261                 rxpmtu:1,
0262                 rxorigdstaddr:1,
0263                 recvfragsize:1;
0264                 /* 1 bits hole */
0265         } bits;
0266         __u16       all;
0267     } rxopt;
0268 
0269     /* sockopt flags */
0270     __u16           recverr:1,
0271                             sndflow:1,
0272                 repflow:1,
0273                 pmtudisc:3,
0274                 padding:1,  /* 1 bit hole */
0275                 srcprefs:3, /* 001: prefer temporary address
0276                          * 010: prefer public address
0277                          * 100: prefer care-of address
0278                          */
0279                 dontfrag:1,
0280                 autoflowlabel:1,
0281                 autoflowlabel_set:1,
0282                 mc_all:1,
0283                 recverr_rfc4884:1,
0284                 rtalert_isolate:1;
0285     __u8            min_hopcount;
0286     __u8            tclass;
0287     __be32          rcv_flowinfo;
0288 
0289     __u32           dst_cookie;
0290 
0291     struct ipv6_mc_socklist __rcu *ipv6_mc_list;
0292     struct ipv6_ac_socklist *ipv6_ac_list;
0293     struct ipv6_fl_socklist __rcu *ipv6_fl_list;
0294 
0295     struct ipv6_txoptions __rcu *opt;
0296     struct sk_buff      *pktoptions;
0297     struct sk_buff      *rxpmtu;
0298     struct inet6_cork   cork;
0299 };
0300 
0301 /* WARNING: don't change the layout of the members in {raw,udp,tcp}6_sock! */
0302 struct raw6_sock {
0303     /* inet_sock has to be the first member of raw6_sock */
0304     struct inet_sock    inet;
0305     __u32           checksum;   /* perform checksum */
0306     __u32           offset;     /* checksum offset  */
0307     struct icmp6_filter filter;
0308     __u32           ip6mr_table;
0309     /* ipv6_pinfo has to be the last member of raw6_sock, see inet6_sk_generic */
0310     struct ipv6_pinfo   inet6;
0311 };
0312 
0313 struct udp6_sock {
0314     struct udp_sock   udp;
0315     /* ipv6_pinfo has to be the last member of udp6_sock, see inet6_sk_generic */
0316     struct ipv6_pinfo inet6;
0317 };
0318 
0319 struct tcp6_sock {
0320     struct tcp_sock   tcp;
0321     /* ipv6_pinfo has to be the last member of tcp6_sock, see inet6_sk_generic */
0322     struct ipv6_pinfo inet6;
0323 };
0324 
0325 extern int inet6_sk_rebuild_header(struct sock *sk);
0326 
0327 struct tcp6_timewait_sock {
0328     struct tcp_timewait_sock   tcp6tw_tcp;
0329 };
0330 
0331 #if IS_ENABLED(CONFIG_IPV6)
0332 bool ipv6_mod_enabled(void);
0333 
0334 static inline struct ipv6_pinfo *inet6_sk(const struct sock *__sk)
0335 {
0336     return sk_fullsock(__sk) ? inet_sk(__sk)->pinet6 : NULL;
0337 }
0338 
0339 static inline struct raw6_sock *raw6_sk(const struct sock *sk)
0340 {
0341     return (struct raw6_sock *)sk;
0342 }
0343 
0344 #define ipv6_only_sock(sk)  (sk->sk_ipv6only)
0345 #define ipv6_sk_rxinfo(sk)  ((sk)->sk_family == PF_INET6 && \
0346                  inet6_sk(sk)->rxopt.bits.rxinfo)
0347 
0348 static inline const struct in6_addr *inet6_rcv_saddr(const struct sock *sk)
0349 {
0350     if (sk->sk_family == AF_INET6)
0351         return &sk->sk_v6_rcv_saddr;
0352     return NULL;
0353 }
0354 
0355 static inline int inet_v6_ipv6only(const struct sock *sk)
0356 {
0357     /* ipv6only field is at same position for timewait and other sockets */
0358     return ipv6_only_sock(sk);
0359 }
0360 #else
0361 #define ipv6_only_sock(sk)  0
0362 #define ipv6_sk_rxinfo(sk)  0
0363 
0364 static inline bool ipv6_mod_enabled(void)
0365 {
0366     return false;
0367 }
0368 
0369 static inline struct ipv6_pinfo * inet6_sk(const struct sock *__sk)
0370 {
0371     return NULL;
0372 }
0373 
0374 static inline struct raw6_sock *raw6_sk(const struct sock *sk)
0375 {
0376     return NULL;
0377 }
0378 
0379 #define inet6_rcv_saddr(__sk)   NULL
0380 #define inet_v6_ipv6only(__sk)      0
0381 #endif /* IS_ENABLED(CONFIG_IPV6) */
0382 #endif /* _IPV6_H */