1
2#ifndef _IPV6_H
3#define _IPV6_H
4
5#include <uapi/linux/ipv6.h>
6
7#include <linux/rh_kabi.h>
8
9#define ipv6_optlen(p) (((p)->hdrlen+1) << 3)
10#define ipv6_authlen(p) (((p)->hdrlen+2) << 2)
11
12
13
14struct ipv6_devconf {
15 __s32 forwarding;
16 __s32 hop_limit;
17 __s32 mtu6;
18 __s32 accept_ra;
19 __s32 accept_redirects;
20 __s32 autoconf;
21 __s32 dad_transmits;
22 __s32 rtr_solicits;
23 __s32 rtr_solicit_interval;
24 __s32 rtr_solicit_max_interval;
25 __s32 rtr_solicit_delay;
26 __s32 force_mld_version;
27 __s32 mldv1_unsolicited_report_interval;
28 __s32 mldv2_unsolicited_report_interval;
29 __s32 use_tempaddr;
30 __s32 temp_valid_lft;
31 __s32 temp_prefered_lft;
32 __s32 regen_max_retry;
33 __s32 max_desync_factor;
34 __s32 max_addresses;
35 __s32 accept_ra_defrtr;
36 __s32 accept_ra_min_hop_limit;
37 __s32 accept_ra_pinfo;
38 __s32 ignore_routes_with_linkdown;
39#ifdef CONFIG_IPV6_ROUTER_PREF
40 __s32 accept_ra_rtr_pref;
41 __s32 rtr_probe_interval;
42#ifdef CONFIG_IPV6_ROUTE_INFO
43 __s32 accept_ra_rt_info_min_plen;
44 __s32 accept_ra_rt_info_max_plen;
45#endif
46#endif
47 __s32 proxy_ndp;
48 __s32 accept_source_route;
49 __s32 accept_ra_from_local;
50#ifdef CONFIG_IPV6_OPTIMISTIC_DAD
51 __s32 optimistic_dad;
52 __s32 use_optimistic;
53#endif
54#ifdef CONFIG_IPV6_MROUTE
55 __s32 mc_forwarding;
56#endif
57 __s32 disable_ipv6;
58 __s32 drop_unicast_in_l2_multicast;
59 __s32 accept_dad;
60 __s32 force_tllao;
61 __s32 ndisc_notify;
62 __s32 suppress_frag_ndisc;
63 __s32 accept_ra_mtu;
64 __s32 drop_unsolicited_na;
65 struct ipv6_stable_secret {
66 bool initialized;
67 struct in6_addr secret;
68 } stable_secret;
69 __s32 use_oif_addrs_only;
70 __s32 keep_addr_on_down;
71 __s32 seg6_enabled;
72#ifdef CONFIG_IPV6_SEG6_HMAC
73 __s32 seg6_require_hmac;
74#endif
75 __u32 enhanced_dad;
76 __u32 addr_gen_mode;
77 __s32 disable_policy;
78 __s32 ndisc_tclass;
79
80 struct ctl_table_header *sysctl_header;
81
82 RH_KABI_RESERVE(1)
83 RH_KABI_RESERVE(2)
84 RH_KABI_RESERVE(3)
85 RH_KABI_RESERVE(4)
86 RH_KABI_RESERVE(5)
87 RH_KABI_RESERVE(6)
88 RH_KABI_RESERVE(7)
89 RH_KABI_RESERVE(8)
90 RH_KABI_RESERVE(9)
91 RH_KABI_RESERVE(10)
92 RH_KABI_RESERVE(11)
93 RH_KABI_RESERVE(12)
94 RH_KABI_RESERVE(13)
95 RH_KABI_RESERVE(14)
96 RH_KABI_RESERVE(15)
97 RH_KABI_RESERVE(16)
98};
99
100struct ipv6_params {
101 __s32 disable_ipv6;
102 __s32 autoconf;
103};
104extern struct ipv6_params ipv6_defaults;
105#include <linux/icmpv6.h>
106#include <linux/tcp.h>
107#include <linux/udp.h>
108
109#include <net/inet_sock.h>
110
111static inline struct ipv6hdr *ipv6_hdr(const struct sk_buff *skb)
112{
113 return (struct ipv6hdr *)skb_network_header(skb);
114}
115
116static inline struct ipv6hdr *inner_ipv6_hdr(const struct sk_buff *skb)
117{
118 return (struct ipv6hdr *)skb_inner_network_header(skb);
119}
120
121static inline struct ipv6hdr *ipipv6_hdr(const struct sk_buff *skb)
122{
123 return (struct ipv6hdr *)skb_transport_header(skb);
124}
125
126static inline unsigned int ipv6_transport_len(const struct sk_buff *skb)
127{
128 return ntohs(ipv6_hdr(skb)->payload_len) + sizeof(struct ipv6hdr) -
129 skb_network_header_len(skb);
130}
131
132
133
134
135
136
137struct inet6_skb_parm {
138 int iif;
139 __be16 ra;
140 __u16 dst0;
141 __u16 srcrt;
142 __u16 dst1;
143 __u16 lastopt;
144 __u16 nhoff;
145 __u16 flags;
146#if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
147 __u16 dsthao;
148#endif
149 __u16 frag_max_size;
150
151#define IP6SKB_XFRM_TRANSFORMED 1
152#define IP6SKB_FORWARDED 2
153#define IP6SKB_REROUTED 4
154#define IP6SKB_ROUTERALERT 8
155#define IP6SKB_FRAGMENTED 16
156#define IP6SKB_HOPBYHOP 32
157#define IP6SKB_L3SLAVE 64
158#define IP6SKB_JUMBOGRAM 128
159};
160
161#if defined(CONFIG_NET_L3_MASTER_DEV)
162static inline bool ipv6_l3mdev_skb(__u16 flags)
163{
164 return flags & IP6SKB_L3SLAVE;
165}
166#else
167static inline bool ipv6_l3mdev_skb(__u16 flags)
168{
169 return false;
170}
171#endif
172
173#define IP6CB(skb) ((struct inet6_skb_parm*)((skb)->cb))
174#define IP6CBMTU(skb) ((struct ip6_mtuinfo *)((skb)->cb))
175
176static inline int inet6_iif(const struct sk_buff *skb)
177{
178 bool l3_slave = ipv6_l3mdev_skb(IP6CB(skb)->flags);
179
180 return l3_slave ? skb->skb_iif : IP6CB(skb)->iif;
181}
182
183static inline bool inet6_is_jumbogram(const struct sk_buff *skb)
184{
185 return !!(IP6CB(skb)->flags & IP6SKB_JUMBOGRAM);
186}
187
188
189static inline int inet6_sdif(const struct sk_buff *skb)
190{
191#if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV)
192 if (skb && ipv6_l3mdev_skb(IP6CB(skb)->flags))
193 return IP6CB(skb)->iif;
194#endif
195 return 0;
196}
197
198
199static inline bool inet6_exact_dif_match(struct net *net, struct sk_buff *skb)
200{
201#if defined(CONFIG_NET_L3_MASTER_DEV)
202 if (!net->ipv4.sysctl_tcp_l3mdev_accept &&
203 skb && ipv6_l3mdev_skb(IP6CB(skb)->flags))
204 return true;
205#endif
206 return false;
207}
208
209struct tcp6_request_sock {
210 struct tcp_request_sock tcp6rsk_tcp;
211};
212
213struct ipv6_mc_socklist;
214struct ipv6_ac_socklist;
215struct ipv6_fl_socklist;
216
217struct inet6_cork {
218 struct ipv6_txoptions *opt;
219 u8 hop_limit;
220 u8 tclass;
221};
222
223
224
225
226
227
228
229
230
231struct ipv6_pinfo {
232 struct in6_addr saddr;
233 struct in6_pktinfo sticky_pktinfo;
234 const struct in6_addr *daddr_cache;
235#ifdef CONFIG_IPV6_SUBTREES
236 const struct in6_addr *saddr_cache;
237#endif
238
239 __be32 flow_label;
240 __u32 frag_size;
241
242
243
244
245
246#if defined(__BIG_ENDIAN_BITFIELD)
247 __s16 hop_limit:9;
248 __u16 __unused_1:7;
249#else
250 __u16 __unused_1:7;
251 __s16 hop_limit:9;
252#endif
253
254#if defined(__BIG_ENDIAN_BITFIELD)
255
256 __s16 mcast_hops:9;
257 __u16 __unused_2:6,
258 mc_loop:1;
259#else
260 __u16 mc_loop:1,
261 __unused_2:6;
262 __s16 mcast_hops:9;
263#endif
264 int ucast_oif;
265 int mcast_oif;
266
267
268 union {
269 struct {
270 __u16 srcrt:1,
271 osrcrt:1,
272 rxinfo:1,
273 rxoinfo:1,
274 rxhlim:1,
275 rxohlim:1,
276 hopopts:1,
277 ohopopts:1,
278 dstopts:1,
279 odstopts:1,
280 rxflow:1,
281 rxtclass:1,
282 rxpmtu:1,
283 rxorigdstaddr:1,
284 recvfragsize:1;
285
286 } bits;
287 __u16 all;
288 } rxopt;
289
290
291 __u16 recverr:1,
292 sndflow:1,
293 repflow:1,
294 pmtudisc:3,
295 padding:1,
296 srcprefs:3,
297
298
299
300 dontfrag:1,
301 autoflowlabel:1,
302 autoflowlabel_set:1;
303 __u8 min_hopcount;
304 __u8 tclass;
305 __be32 rcv_flowinfo;
306
307 __u32 dst_cookie;
308 __u32 rx_dst_cookie;
309
310 struct ipv6_mc_socklist __rcu *ipv6_mc_list;
311 struct ipv6_ac_socklist *ipv6_ac_list;
312 struct ipv6_fl_socklist __rcu *ipv6_fl_list;
313
314 struct ipv6_txoptions __rcu *opt;
315 struct sk_buff *pktoptions;
316 struct sk_buff *rxpmtu;
317 struct inet6_cork cork;
318};
319
320
321struct raw6_sock {
322
323 struct inet_sock inet;
324 __u32 checksum;
325 __u32 offset;
326 struct icmp6_filter filter;
327 __u32 ip6mr_table;
328
329 struct ipv6_pinfo inet6;
330};
331
332struct udp6_sock {
333 struct udp_sock udp;
334
335 struct ipv6_pinfo inet6;
336};
337
338struct tcp6_sock {
339 struct tcp_sock tcp;
340
341 struct ipv6_pinfo inet6;
342};
343
344extern int inet6_sk_rebuild_header(struct sock *sk);
345
346struct tcp6_timewait_sock {
347 struct tcp_timewait_sock tcp6tw_tcp;
348};
349
350#if IS_ENABLED(CONFIG_IPV6)
351bool ipv6_mod_enabled(void);
352
353static inline struct ipv6_pinfo *inet6_sk(const struct sock *__sk)
354{
355 return sk_fullsock(__sk) ? inet_sk(__sk)->pinet6 : NULL;
356}
357
358static inline struct raw6_sock *raw6_sk(const struct sock *sk)
359{
360 return (struct raw6_sock *)sk;
361}
362
363static inline void inet_sk_copy_descendant(struct sock *sk_to,
364 const struct sock *sk_from)
365{
366 int ancestor_size = sizeof(struct inet_sock);
367
368 if (sk_from->sk_family == PF_INET6)
369 ancestor_size += sizeof(struct ipv6_pinfo);
370
371 __inet_sk_copy_descendant(sk_to, sk_from, ancestor_size);
372}
373
374#define __ipv6_only_sock(sk) (sk->sk_ipv6only)
375#define ipv6_only_sock(sk) (__ipv6_only_sock(sk))
376#define ipv6_sk_rxinfo(sk) ((sk)->sk_family == PF_INET6 && \
377 inet6_sk(sk)->rxopt.bits.rxinfo)
378
379static inline const struct in6_addr *inet6_rcv_saddr(const struct sock *sk)
380{
381 if (sk->sk_family == AF_INET6)
382 return &sk->sk_v6_rcv_saddr;
383 return NULL;
384}
385
386static inline int inet_v6_ipv6only(const struct sock *sk)
387{
388
389 return ipv6_only_sock(sk);
390}
391#else
392#define __ipv6_only_sock(sk) 0
393#define ipv6_only_sock(sk) 0
394#define ipv6_sk_rxinfo(sk) 0
395
396static inline bool ipv6_mod_enabled(void)
397{
398 return false;
399}
400
401static inline struct ipv6_pinfo * inet6_sk(const struct sock *__sk)
402{
403 return NULL;
404}
405
406static inline struct inet6_request_sock *
407 inet6_rsk(const struct request_sock *rsk)
408{
409 return NULL;
410}
411
412static inline struct raw6_sock *raw6_sk(const struct sock *sk)
413{
414 return NULL;
415}
416
417#define inet6_rcv_saddr(__sk) NULL
418#define tcp_twsk_ipv6only(__sk) 0
419#define inet_v6_ipv6only(__sk) 0
420#endif
421#endif
422