• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _IPV6_H
3 #define _IPV6_H
4 
5 #include <uapi/linux/ipv6.h>
6 #include <linux/android_kabi.h>
7 
8 #define ipv6_optlen(p)  (((p)->hdrlen+1) << 3)
9 #define ipv6_authlen(p) (((p)->hdrlen+2) << 2)
10 /*
11  * This structure contains configuration options per IPv6 link.
12  */
13 struct ipv6_devconf {
14 	__s32		forwarding;
15 	__s32		hop_limit;
16 	__s32		mtu6;
17 	__s32		accept_ra;
18 	__s32		accept_redirects;
19 	__s32		autoconf;
20 	__s32		dad_transmits;
21 	__s32		rtr_solicits;
22 	__s32		rtr_solicit_interval;
23 	__s32		rtr_solicit_max_interval;
24 	__s32		rtr_solicit_delay;
25 	__s32		force_mld_version;
26 	__s32		mldv1_unsolicited_report_interval;
27 	__s32		mldv2_unsolicited_report_interval;
28 	__s32		use_tempaddr;
29 	__s32		temp_valid_lft;
30 	__s32		temp_prefered_lft;
31 	__s32		regen_max_retry;
32 	__s32		max_desync_factor;
33 	__s32		max_addresses;
34 	__s32		accept_ra_defrtr;
35 	__u32		ra_defrtr_metric;
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		accept_ra_rt_table;
48 	__s32		proxy_ndp;
49 	__s32		accept_source_route;
50 	__s32		accept_ra_from_local;
51 #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
52 	__s32		optimistic_dad;
53 	__s32		use_optimistic;
54 #endif
55 #ifdef CONFIG_IPV6_MROUTE
56 	atomic_t	mc_forwarding;
57 #endif
58 	__s32		disable_ipv6;
59 	__s32		drop_unicast_in_l2_multicast;
60 	__s32		accept_dad;
61 	__s32		force_tllao;
62 	__s32           ndisc_notify;
63 	__s32		suppress_frag_ndisc;
64 	__s32		accept_ra_mtu;
65 	__s32		drop_unsolicited_na;
66 	__s32		accept_untracked_na;
67 	struct ipv6_stable_secret {
68 		bool initialized;
69 		struct in6_addr secret;
70 	} stable_secret;
71 	__s32		use_oif_addrs_only;
72 	__s32		keep_addr_on_down;
73 	__s32		seg6_enabled;
74 #ifdef CONFIG_IPV6_SEG6_HMAC
75 	__s32		seg6_require_hmac;
76 #endif
77 	__u32		enhanced_dad;
78 	__u32		addr_gen_mode;
79 	__s32		disable_policy;
80 	__s32           ndisc_tclass;
81 	__s32		rpl_seg_enabled;
82 	__u32		ioam6_id;
83 	__u32		ioam6_id_wide;
84 	__u8		ioam6_enabled;
85 	__u8		ndisc_evict_nocarrier;
86 
87 	struct ctl_table_header *sysctl_header;
88 
89 	ANDROID_KABI_USE(1, struct { __s32 accept_ra_min_lft; u32 padding; });
90 
91 	ANDROID_KABI_RESERVE(2);
92 	ANDROID_KABI_RESERVE(3);
93 	ANDROID_KABI_RESERVE(4);
94 };
95 
96 struct ipv6_params {
97 	__s32 disable_ipv6;
98 	__s32 autoconf;
99 };
100 extern struct ipv6_params ipv6_defaults;
101 #include <linux/tcp.h>
102 #include <linux/udp.h>
103 
104 #include <net/inet_sock.h>
105 
ipv6_hdr(const struct sk_buff * skb)106 static inline struct ipv6hdr *ipv6_hdr(const struct sk_buff *skb)
107 {
108 	return (struct ipv6hdr *)skb_network_header(skb);
109 }
110 
inner_ipv6_hdr(const struct sk_buff * skb)111 static inline struct ipv6hdr *inner_ipv6_hdr(const struct sk_buff *skb)
112 {
113 	return (struct ipv6hdr *)skb_inner_network_header(skb);
114 }
115 
ipipv6_hdr(const struct sk_buff * skb)116 static inline struct ipv6hdr *ipipv6_hdr(const struct sk_buff *skb)
117 {
118 	return (struct ipv6hdr *)skb_transport_header(skb);
119 }
120 
ipv6_transport_len(const struct sk_buff * skb)121 static inline unsigned int ipv6_transport_len(const struct sk_buff *skb)
122 {
123 	return ntohs(ipv6_hdr(skb)->payload_len) + sizeof(struct ipv6hdr) -
124 	       skb_network_header_len(skb);
125 }
126 
127 /*
128    This structure contains results of exthdrs parsing
129    as offsets from skb->nh.
130  */
131 
132 struct inet6_skb_parm {
133 	int			iif;
134 	__be16			ra;
135 	__u16			dst0;
136 	__u16			srcrt;
137 	__u16			dst1;
138 	__u16			lastopt;
139 	__u16			nhoff;
140 	__u16			flags;
141 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
142 	__u16			dsthao;
143 #endif
144 	__u16			frag_max_size;
145 	__u16			srhoff;
146 
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
158 };
159 
160 #if defined(CONFIG_NET_L3_MASTER_DEV)
ipv6_l3mdev_skb(__u16 flags)161 static inline bool ipv6_l3mdev_skb(__u16 flags)
162 {
163 	return flags & IP6SKB_L3SLAVE;
164 }
165 #else
ipv6_l3mdev_skb(__u16 flags)166 static inline bool ipv6_l3mdev_skb(__u16 flags)
167 {
168 	return false;
169 }
170 #endif
171 
172 #define IP6CB(skb)	((struct inet6_skb_parm*)((skb)->cb))
173 #define IP6CBMTU(skb)	((struct ip6_mtuinfo *)((skb)->cb))
174 
inet6_iif(const struct sk_buff * skb)175 static inline int inet6_iif(const struct sk_buff *skb)
176 {
177 	bool l3_slave = ipv6_l3mdev_skb(IP6CB(skb)->flags);
178 
179 	return l3_slave ? skb->skb_iif : IP6CB(skb)->iif;
180 }
181 
inet6_is_jumbogram(const struct sk_buff * skb)182 static inline bool inet6_is_jumbogram(const struct sk_buff *skb)
183 {
184 	return !!(IP6CB(skb)->flags & IP6SKB_JUMBOGRAM);
185 }
186 
187 /* can not be used in TCP layer after tcp_v6_fill_cb */
inet6_sdif(const struct sk_buff * skb)188 static inline int inet6_sdif(const struct sk_buff *skb)
189 {
190 #if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV)
191 	if (skb && ipv6_l3mdev_skb(IP6CB(skb)->flags))
192 		return IP6CB(skb)->iif;
193 #endif
194 	return 0;
195 }
196 
197 struct tcp6_request_sock {
198 	struct tcp_request_sock	  tcp6rsk_tcp;
199 };
200 
201 struct ipv6_mc_socklist;
202 struct ipv6_ac_socklist;
203 struct ipv6_fl_socklist;
204 
205 struct inet6_cork {
206 	struct ipv6_txoptions *opt;
207 	u8 hop_limit;
208 	u8 tclass;
209 };
210 
211 /**
212  * struct ipv6_pinfo - ipv6 private area
213  *
214  * In the struct sock hierarchy (tcp6_sock, upd6_sock, etc)
215  * this _must_ be the last member, so that inet6_sk_generic
216  * is able to calculate its offset from the base struct sock
217  * by using the struct proto->slab_obj_size member. -acme
218  */
219 struct ipv6_pinfo {
220 	struct in6_addr 	saddr;
221 	struct in6_pktinfo	sticky_pktinfo;
222 	const struct in6_addr		*daddr_cache;
223 #ifdef CONFIG_IPV6_SUBTREES
224 	const struct in6_addr		*saddr_cache;
225 #endif
226 
227 	__be32			flow_label;
228 	__u32			frag_size;
229 
230 	/*
231 	 * Packed in 16bits.
232 	 * Omit one shift by putting the signed field at MSB.
233 	 */
234 #if defined(__BIG_ENDIAN_BITFIELD)
235 	__s16			hop_limit:9;
236 	__u16			__unused_1:7;
237 #else
238 	__u16			__unused_1:7;
239 	__s16			hop_limit:9;
240 #endif
241 
242 #if defined(__BIG_ENDIAN_BITFIELD)
243 	/* Packed in 16bits. */
244 	__s16			mcast_hops:9;
245 	__u16			__unused_2:6,
246 				mc_loop:1;
247 #else
248 	__u16			mc_loop:1,
249 				__unused_2:6;
250 	__s16			mcast_hops:9;
251 #endif
252 	int			ucast_oif;
253 	int			mcast_oif;
254 
255 	/* pktoption flags */
256 	union {
257 		struct {
258 			__u16	srcrt:1,
259 				osrcrt:1,
260 			        rxinfo:1,
261 			        rxoinfo:1,
262 				rxhlim:1,
263 				rxohlim:1,
264 				hopopts:1,
265 				ohopopts:1,
266 				dstopts:1,
267 				odstopts:1,
268                                 rxflow:1,
269 				rxtclass:1,
270 				rxpmtu:1,
271 				rxorigdstaddr:1,
272 				recvfragsize:1;
273 				/* 1 bits hole */
274 		} bits;
275 		__u16		all;
276 	} rxopt;
277 
278 	/* sockopt flags */
279 	__u16			recverr:1,
280 	                        sndflow:1,
281 				repflow:1,
282 				pmtudisc:3,
283 				padding:1,	/* 1 bit hole */
284 				srcprefs:3,	/* 001: prefer temporary address
285 						 * 010: prefer public address
286 						 * 100: prefer care-of address
287 						 */
288 				dontfrag:1,
289 				autoflowlabel:1,
290 				autoflowlabel_set:1,
291 				mc_all:1,
292 				recverr_rfc4884:1,
293 				rtalert_isolate:1;
294 	__u8			min_hopcount;
295 	__u8			tclass;
296 	__be32			rcv_flowinfo;
297 
298 	__u32			dst_cookie;
299 
300 	struct ipv6_mc_socklist	__rcu *ipv6_mc_list;
301 	struct ipv6_ac_socklist	*ipv6_ac_list;
302 	struct ipv6_fl_socklist __rcu *ipv6_fl_list;
303 
304 	struct ipv6_txoptions __rcu	*opt;
305 	struct sk_buff		*pktoptions;
306 	struct sk_buff		*rxpmtu;
307 	struct inet6_cork	cork;
308 };
309 
310 /* WARNING: don't change the layout of the members in {raw,udp,tcp}6_sock! */
311 struct raw6_sock {
312 	/* inet_sock has to be the first member of raw6_sock */
313 	struct inet_sock	inet;
314 	__u32			checksum;	/* perform checksum */
315 	__u32			offset;		/* checksum offset  */
316 	struct icmp6_filter	filter;
317 	__u32			ip6mr_table;
318 	/* ipv6_pinfo has to be the last member of raw6_sock, see inet6_sk_generic */
319 	struct ipv6_pinfo	inet6;
320 };
321 
322 struct udp6_sock {
323 	struct udp_sock	  udp;
324 	/* ipv6_pinfo has to be the last member of udp6_sock, see inet6_sk_generic */
325 	struct ipv6_pinfo inet6;
326 };
327 
328 struct tcp6_sock {
329 	struct tcp_sock	  tcp;
330 	/* ipv6_pinfo has to be the last member of tcp6_sock, see inet6_sk_generic */
331 	struct ipv6_pinfo inet6;
332 };
333 
334 extern int inet6_sk_rebuild_header(struct sock *sk);
335 
336 struct tcp6_timewait_sock {
337 	struct tcp_timewait_sock   tcp6tw_tcp;
338 };
339 
340 #if IS_ENABLED(CONFIG_IPV6)
341 bool ipv6_mod_enabled(void);
342 
inet6_sk(const struct sock * __sk)343 static inline struct ipv6_pinfo *inet6_sk(const struct sock *__sk)
344 {
345 	return sk_fullsock(__sk) ? inet_sk(__sk)->pinet6 : NULL;
346 }
347 
raw6_sk(const struct sock * sk)348 static inline struct raw6_sock *raw6_sk(const struct sock *sk)
349 {
350 	return (struct raw6_sock *)sk;
351 }
352 
353 #define ipv6_only_sock(sk)	(sk->sk_ipv6only)
354 #define ipv6_sk_rxinfo(sk)	((sk)->sk_family == PF_INET6 && \
355 				 inet6_sk(sk)->rxopt.bits.rxinfo)
356 
inet6_rcv_saddr(const struct sock * sk)357 static inline const struct in6_addr *inet6_rcv_saddr(const struct sock *sk)
358 {
359 	if (sk->sk_family == AF_INET6)
360 		return &sk->sk_v6_rcv_saddr;
361 	return NULL;
362 }
363 
inet_v6_ipv6only(const struct sock * sk)364 static inline int inet_v6_ipv6only(const struct sock *sk)
365 {
366 	/* ipv6only field is at same position for timewait and other sockets */
367 	return ipv6_only_sock(sk);
368 }
369 #else
370 #define ipv6_only_sock(sk)	0
371 #define ipv6_sk_rxinfo(sk)	0
372 
ipv6_mod_enabled(void)373 static inline bool ipv6_mod_enabled(void)
374 {
375 	return false;
376 }
377 
inet6_sk(const struct sock * __sk)378 static inline struct ipv6_pinfo * inet6_sk(const struct sock *__sk)
379 {
380 	return NULL;
381 }
382 
raw6_sk(const struct sock * sk)383 static inline struct raw6_sock *raw6_sk(const struct sock *sk)
384 {
385 	return NULL;
386 }
387 
388 #define inet6_rcv_saddr(__sk)	NULL
389 #define inet_v6_ipv6only(__sk)		0
390 #endif /* IS_ENABLED(CONFIG_IPV6) */
391 #endif /* _IPV6_H */
392