1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <uapi/linux/ipv6.h>
6 #include <linux/cache.h>
8 #define ipv6_optlen(p) (((p)->hdrlen+1) << 3)
9 #define ipv6_authlen(p) (((p)->hdrlen+2) << 2)
11 * This structure contains configuration options per IPv6 link.
14 /* RX & TX fastpath fields. */
15 __cacheline_group_begin(ipv6_devconf_read_txrx);
22 __cacheline_group_end(ipv6_devconf_read_txrx);
25 __s32 accept_redirects;
29 __s32 rtr_solicit_interval;
30 __s32 rtr_solicit_max_interval;
31 __s32 rtr_solicit_delay;
32 __s32 force_mld_version;
33 __s32 mldv1_unsolicited_report_interval;
34 __s32 mldv2_unsolicited_report_interval;
37 __s32 temp_prefered_lft;
38 __s32 regen_min_advance;
39 __s32 regen_max_retry;
40 __s32 max_desync_factor;
42 __s32 accept_ra_defrtr;
43 __u32 ra_defrtr_metric;
44 __s32 accept_ra_min_hop_limit;
45 __s32 accept_ra_min_lft;
46 __s32 accept_ra_pinfo;
47 __s32 ignore_routes_with_linkdown;
48 #ifdef CONFIG_IPV6_ROUTER_PREF
49 __s32 accept_ra_rtr_pref;
50 __s32 rtr_probe_interval;
51 #ifdef CONFIG_IPV6_ROUTE_INFO
52 __s32 accept_ra_rt_info_min_plen;
53 __s32 accept_ra_rt_info_max_plen;
56 __s32 accept_source_route;
57 __s32 accept_ra_from_local;
58 #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
62 #ifdef CONFIG_IPV6_MROUTE
63 atomic_t mc_forwarding;
65 __s32 drop_unicast_in_l2_multicast;
69 __s32 suppress_frag_ndisc;
71 __s32 drop_unsolicited_na;
72 __s32 accept_untracked_na;
73 struct ipv6_stable_secret {
75 struct in6_addr secret;
77 __s32 use_oif_addrs_only;
78 __s32 keep_addr_on_down;
80 #ifdef CONFIG_IPV6_SEG6_HMAC
81 __s32 seg6_require_hmac;
86 __s32 rpl_seg_enabled;
90 __u8 ndisc_evict_nocarrier;
91 __u8 ra_honor_pio_life;
93 struct ctl_table_header *sysctl_header;
100 extern struct ipv6_params ipv6_defaults;
101 #include <linux/tcp.h>
102 #include <linux/udp.h>
104 #include <net/inet_sock.h>
106 static inline struct ipv6hdr *ipv6_hdr(const struct sk_buff *skb)
108 return (struct ipv6hdr *)skb_network_header(skb);
111 static inline struct ipv6hdr *inner_ipv6_hdr(const struct sk_buff *skb)
113 return (struct ipv6hdr *)skb_inner_network_header(skb);
116 static inline struct ipv6hdr *ipipv6_hdr(const struct sk_buff *skb)
118 return (struct ipv6hdr *)skb_transport_header(skb);
121 static inline unsigned int ipv6_transport_len(const struct sk_buff *skb)
123 return ntohs(ipv6_hdr(skb)->payload_len) + sizeof(struct ipv6hdr) -
124 skb_network_header_len(skb);
128 This structure contains results of exthdrs parsing
129 as offsets from skb->nh.
132 struct inet6_skb_parm {
141 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
147 #define IP6SKB_XFRM_TRANSFORMED 1
148 #define IP6SKB_FORWARDED 2
149 #define IP6SKB_REROUTED 4
150 #define IP6SKB_ROUTERALERT 8
151 #define IP6SKB_FRAGMENTED 16
152 #define IP6SKB_HOPBYHOP 32
153 #define IP6SKB_L3SLAVE 64
154 #define IP6SKB_JUMBOGRAM 128
155 #define IP6SKB_SEG6 256
156 #define IP6SKB_FAKEJUMBO 512
157 #define IP6SKB_MULTIPATH 1024
160 #if defined(CONFIG_NET_L3_MASTER_DEV)
161 static inline bool ipv6_l3mdev_skb(__u16 flags)
163 return flags & IP6SKB_L3SLAVE;
166 static inline bool ipv6_l3mdev_skb(__u16 flags)
172 #define IP6CB(skb) ((struct inet6_skb_parm*)((skb)->cb))
173 #define IP6CBMTU(skb) ((struct ip6_mtuinfo *)((skb)->cb))
175 static inline int inet6_iif(const struct sk_buff *skb)
177 bool l3_slave = ipv6_l3mdev_skb(IP6CB(skb)->flags);
179 return l3_slave ? skb->skb_iif : IP6CB(skb)->iif;
182 static inline bool inet6_is_jumbogram(const struct sk_buff *skb)
184 return !!(IP6CB(skb)->flags & IP6SKB_JUMBOGRAM);
187 /* can not be used in TCP layer after tcp_v6_fill_cb */
188 static inline int inet6_sdif(const struct sk_buff *skb)
190 #if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV)
191 if (skb && ipv6_l3mdev_skb(IP6CB(skb)->flags))
192 return IP6CB(skb)->iif;
197 struct tcp6_request_sock {
198 struct tcp_request_sock tcp6rsk_tcp;
201 struct ipv6_mc_socklist;
202 struct ipv6_ac_socklist;
203 struct ipv6_fl_socklist;
206 struct ipv6_txoptions *opt;
211 /* struct ipv6_pinfo - ipv6 private area */
213 struct in6_addr saddr;
214 struct in6_pktinfo sticky_pktinfo;
215 const struct in6_addr *daddr_cache;
216 #ifdef CONFIG_IPV6_SUBTREES
217 const struct in6_addr *saddr_cache;
229 /* pktoption flags */
253 __u8 srcprefs; /* 001: prefer temporary address
254 * 010: prefer public address
255 * 100: prefer care-of address
264 struct ipv6_mc_socklist __rcu *ipv6_mc_list;
265 struct ipv6_ac_socklist *ipv6_ac_list;
266 struct ipv6_fl_socklist __rcu *ipv6_fl_list;
268 struct ipv6_txoptions __rcu *opt;
269 struct sk_buff *pktoptions;
270 struct sk_buff *rxpmtu;
271 struct inet6_cork cork;
274 /* We currently use available bits from inet_sk(sk)->inet_flags,
275 * this could change in the future.
277 #define inet6_test_bit(nr, sk) \
278 test_bit(INET_FLAGS_##nr, &inet_sk(sk)->inet_flags)
279 #define inet6_set_bit(nr, sk) \
280 set_bit(INET_FLAGS_##nr, &inet_sk(sk)->inet_flags)
281 #define inet6_clear_bit(nr, sk) \
282 clear_bit(INET_FLAGS_##nr, &inet_sk(sk)->inet_flags)
283 #define inet6_assign_bit(nr, sk, val) \
284 assign_bit(INET_FLAGS_##nr, &inet_sk(sk)->inet_flags, val)
286 /* WARNING: don't change the layout of the members in {raw,udp,tcp}6_sock! */
288 /* inet_sock has to be the first member of raw6_sock */
289 struct inet_sock inet;
290 __u32 checksum; /* perform checksum */
291 __u32 offset; /* checksum offset */
292 struct icmp6_filter filter;
295 struct ipv6_pinfo inet6;
301 struct ipv6_pinfo inet6;
307 struct ipv6_pinfo inet6;
310 extern int inet6_sk_rebuild_header(struct sock *sk);
312 struct tcp6_timewait_sock {
313 struct tcp_timewait_sock tcp6tw_tcp;
316 #if IS_ENABLED(CONFIG_IPV6)
317 bool ipv6_mod_enabled(void);
319 static inline struct ipv6_pinfo *inet6_sk(const struct sock *__sk)
321 return sk_fullsock(__sk) ? inet_sk(__sk)->pinet6 : NULL;
324 #define raw6_sk(ptr) container_of_const(ptr, struct raw6_sock, inet.sk)
326 #define ipv6_only_sock(sk) (sk->sk_ipv6only)
327 #define ipv6_sk_rxinfo(sk) ((sk)->sk_family == PF_INET6 && \
328 inet6_sk(sk)->rxopt.bits.rxinfo)
330 static inline const struct in6_addr *inet6_rcv_saddr(const struct sock *sk)
332 if (sk->sk_family == AF_INET6)
333 return &sk->sk_v6_rcv_saddr;
337 static inline int inet_v6_ipv6only(const struct sock *sk)
339 /* ipv6only field is at same position for timewait and other sockets */
340 return ipv6_only_sock(sk);
343 #define ipv6_only_sock(sk) 0
344 #define ipv6_sk_rxinfo(sk) 0
346 static inline bool ipv6_mod_enabled(void)
351 static inline struct ipv6_pinfo * inet6_sk(const struct sock *__sk)
356 static inline struct raw6_sock *raw6_sk(const struct sock *sk)
361 #define inet6_rcv_saddr(__sk) NULL
362 #define inet_v6_ipv6only(__sk) 0
363 #endif /* IS_ENABLED(CONFIG_IPV6) */