• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _IPV6_H
2 #define _IPV6_H
3 
4 #include <uapi/linux/ipv6.h>
5 
6 #define ipv6_optlen(p)  (((p)->hdrlen+1) << 3)
7 #define ipv6_authlen(p) (((p)->hdrlen+2) << 2)
8 /*
9  * This structure contains configuration options per IPv6 link.
10  */
11 struct ipv6_devconf {
12 	__s32		forwarding;
13 	__s32		hop_limit;
14 	__s32		mtu6;
15 	__s32		accept_ra;
16 	__s32		accept_redirects;
17 	__s32		autoconf;
18 	__s32		dad_transmits;
19 	__s32		rtr_solicits;
20 	__s32		rtr_solicit_interval;
21 	__s32		rtr_solicit_max_interval;
22 	__s32		rtr_solicit_delay;
23 	__s32		force_mld_version;
24 	__s32		mldv1_unsolicited_report_interval;
25 	__s32		mldv2_unsolicited_report_interval;
26 	__s32		use_tempaddr;
27 	__s32		temp_valid_lft;
28 	__s32		temp_prefered_lft;
29 	__s32		regen_max_retry;
30 	__s32		max_desync_factor;
31 	__s32		max_addresses;
32 	__s32		accept_ra_defrtr;
33 	__s32		accept_ra_pinfo;
34 #ifdef CONFIG_IPV6_ROUTER_PREF
35 	__s32		accept_ra_rtr_pref;
36 	__s32		rtr_probe_interval;
37 #ifdef CONFIG_IPV6_ROUTE_INFO
38 	__s32		accept_ra_rt_info_min_plen;
39 	__s32		accept_ra_rt_info_max_plen;
40 #endif
41 #endif
42 	__s32		accept_ra_rt_table;
43 	__s32		proxy_ndp;
44 	__s32		accept_source_route;
45 	__s32		accept_ra_from_local;
46 #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
47 	__s32		optimistic_dad;
48 	__s32		use_optimistic;
49 #endif
50 #ifdef CONFIG_IPV6_MROUTE
51 	__s32		mc_forwarding;
52 #endif
53 	__s32		disable_ipv6;
54 	__s32		accept_dad;
55 	__s32		force_tllao;
56 	__s32           ndisc_notify;
57 	__s32		suppress_frag_ndisc;
58 	__s32		use_oif_addrs_only;
59 	void		*sysctl;
60 };
61 
62 struct ipv6_params {
63 	__s32 disable_ipv6;
64 	__s32 autoconf;
65 };
66 extern struct ipv6_params ipv6_defaults;
67 #include <linux/icmpv6.h>
68 #include <linux/tcp.h>
69 #include <linux/udp.h>
70 
71 #include <net/inet_sock.h>
72 
ipv6_hdr(const struct sk_buff * skb)73 static inline struct ipv6hdr *ipv6_hdr(const struct sk_buff *skb)
74 {
75 	return (struct ipv6hdr *)skb_network_header(skb);
76 }
77 
inner_ipv6_hdr(const struct sk_buff * skb)78 static inline struct ipv6hdr *inner_ipv6_hdr(const struct sk_buff *skb)
79 {
80 	return (struct ipv6hdr *)skb_inner_network_header(skb);
81 }
82 
ipipv6_hdr(const struct sk_buff * skb)83 static inline struct ipv6hdr *ipipv6_hdr(const struct sk_buff *skb)
84 {
85 	return (struct ipv6hdr *)skb_transport_header(skb);
86 }
87 
88 /*
89    This structure contains results of exthdrs parsing
90    as offsets from skb->nh.
91  */
92 
93 struct inet6_skb_parm {
94 	int			iif;
95 	__be16			ra;
96 	__u16			hop;
97 	__u16			dst0;
98 	__u16			srcrt;
99 	__u16			dst1;
100 	__u16			lastopt;
101 	__u16			nhoff;
102 	__u16			flags;
103 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
104 	__u16			dsthao;
105 #endif
106 	__u16			frag_max_size;
107 
108 #define IP6SKB_XFRM_TRANSFORMED	1
109 #define IP6SKB_FORWARDED	2
110 #define IP6SKB_REROUTED		4
111 #define IP6SKB_ROUTERALERT	8
112 #define IP6SKB_FRAGMENTED      16
113 };
114 
115 #define IP6CB(skb)	((struct inet6_skb_parm*)((skb)->cb))
116 #define IP6CBMTU(skb)	((struct ip6_mtuinfo *)((skb)->cb))
117 
inet6_iif(const struct sk_buff * skb)118 static inline int inet6_iif(const struct sk_buff *skb)
119 {
120 	return IP6CB(skb)->iif;
121 }
122 
123 struct tcp6_request_sock {
124 	struct tcp_request_sock	  tcp6rsk_tcp;
125 };
126 
127 struct ipv6_mc_socklist;
128 struct ipv6_ac_socklist;
129 struct ipv6_fl_socklist;
130 
131 /**
132  * struct ipv6_pinfo - ipv6 private area
133  *
134  * In the struct sock hierarchy (tcp6_sock, upd6_sock, etc)
135  * this _must_ be the last member, so that inet6_sk_generic
136  * is able to calculate its offset from the base struct sock
137  * by using the struct proto->slab_obj_size member. -acme
138  */
139 struct ipv6_pinfo {
140 	struct in6_addr 	saddr;
141 	struct in6_pktinfo	sticky_pktinfo;
142 	const struct in6_addr		*daddr_cache;
143 #ifdef CONFIG_IPV6_SUBTREES
144 	const struct in6_addr		*saddr_cache;
145 #endif
146 
147 	__be32			flow_label;
148 	__u32			frag_size;
149 
150 	/*
151 	 * Packed in 16bits.
152 	 * Omit one shift by by putting the signed field at MSB.
153 	 */
154 #if defined(__BIG_ENDIAN_BITFIELD)
155 	__s16			hop_limit:9;
156 	__u16			__unused_1:7;
157 #else
158 	__u16			__unused_1:7;
159 	__s16			hop_limit:9;
160 #endif
161 
162 #if defined(__BIG_ENDIAN_BITFIELD)
163 	/* Packed in 16bits. */
164 	__s16			mcast_hops:9;
165 	__u16			__unused_2:6,
166 				mc_loop:1;
167 #else
168 	__u16			mc_loop:1,
169 				__unused_2:6;
170 	__s16			mcast_hops:9;
171 #endif
172 	int			ucast_oif;
173 	int			mcast_oif;
174 
175 	/* pktoption flags */
176 	union {
177 		struct {
178 			__u16	srcrt:1,
179 				osrcrt:1,
180 			        rxinfo:1,
181 			        rxoinfo:1,
182 				rxhlim:1,
183 				rxohlim:1,
184 				hopopts:1,
185 				ohopopts:1,
186 				dstopts:1,
187 				odstopts:1,
188                                 rxflow:1,
189 				rxtclass:1,
190 				rxpmtu:1,
191 				rxorigdstaddr:1;
192 				/* 2 bits hole */
193 		} bits;
194 		__u16		all;
195 	} rxopt;
196 
197 	/* sockopt flags */
198 	__u16			recverr:1,
199 	                        sndflow:1,
200 				repflow:1,
201 				pmtudisc:3,
202 				padding:1,	/* 1 bit hole */
203 				srcprefs:3,	/* 001: prefer temporary address
204 						 * 010: prefer public address
205 						 * 100: prefer care-of address
206 						 */
207 				dontfrag:1,
208 				autoflowlabel:1;
209 	__u8			min_hopcount;
210 	__u8			tclass;
211 	__be32			rcv_flowinfo;
212 
213 	__u32			dst_cookie;
214 	__u32			rx_dst_cookie;
215 
216 	struct ipv6_mc_socklist	__rcu *ipv6_mc_list;
217 	struct ipv6_ac_socklist	*ipv6_ac_list;
218 	struct ipv6_fl_socklist __rcu *ipv6_fl_list;
219 
220 	struct ipv6_txoptions __rcu	*opt;
221 	struct sk_buff		*pktoptions;
222 	struct sk_buff		*rxpmtu;
223 	struct {
224 		struct ipv6_txoptions *opt;
225 		u8 hop_limit;
226 		u8 tclass;
227 	} cork;
228 };
229 
230 /* WARNING: don't change the layout of the members in {raw,udp,tcp}6_sock! */
231 struct raw6_sock {
232 	/* inet_sock has to be the first member of raw6_sock */
233 	struct inet_sock	inet;
234 	__u32			checksum;	/* perform checksum */
235 	__u32			offset;		/* checksum offset  */
236 	struct icmp6_filter	filter;
237 	__u32			ip6mr_table;
238 	/* ipv6_pinfo has to be the last member of raw6_sock, see inet6_sk_generic */
239 	struct ipv6_pinfo	inet6;
240 };
241 
242 struct udp6_sock {
243 	struct udp_sock	  udp;
244 	/* ipv6_pinfo has to be the last member of udp6_sock, see inet6_sk_generic */
245 	struct ipv6_pinfo inet6;
246 };
247 
248 struct tcp6_sock {
249 	struct tcp_sock	  tcp;
250 	/* ipv6_pinfo has to be the last member of tcp6_sock, see inet6_sk_generic */
251 	struct ipv6_pinfo inet6;
252 };
253 
254 extern int inet6_sk_rebuild_header(struct sock *sk);
255 
256 struct tcp6_timewait_sock {
257 	struct tcp_timewait_sock   tcp6tw_tcp;
258 };
259 
260 #if IS_ENABLED(CONFIG_IPV6)
inet6_sk(const struct sock * __sk)261 static inline struct ipv6_pinfo *inet6_sk(const struct sock *__sk)
262 {
263 	return sk_fullsock(__sk) ? inet_sk(__sk)->pinet6 : NULL;
264 }
265 
raw6_sk(const struct sock * sk)266 static inline struct raw6_sock *raw6_sk(const struct sock *sk)
267 {
268 	return (struct raw6_sock *)sk;
269 }
270 
inet_sk_copy_descendant(struct sock * sk_to,const struct sock * sk_from)271 static inline void inet_sk_copy_descendant(struct sock *sk_to,
272 					   const struct sock *sk_from)
273 {
274 	int ancestor_size = sizeof(struct inet_sock);
275 
276 	if (sk_from->sk_family == PF_INET6)
277 		ancestor_size += sizeof(struct ipv6_pinfo);
278 
279 	__inet_sk_copy_descendant(sk_to, sk_from, ancestor_size);
280 }
281 
282 #define __ipv6_only_sock(sk)	(sk->sk_ipv6only)
283 #define ipv6_only_sock(sk)	(__ipv6_only_sock(sk))
284 #define ipv6_sk_rxinfo(sk)	((sk)->sk_family == PF_INET6 && \
285 				 inet6_sk(sk)->rxopt.bits.rxinfo)
286 
inet6_rcv_saddr(const struct sock * sk)287 static inline const struct in6_addr *inet6_rcv_saddr(const struct sock *sk)
288 {
289 	if (sk->sk_family == AF_INET6)
290 		return &sk->sk_v6_rcv_saddr;
291 	return NULL;
292 }
293 
inet_v6_ipv6only(const struct sock * sk)294 static inline int inet_v6_ipv6only(const struct sock *sk)
295 {
296 	/* ipv6only field is at same position for timewait and other sockets */
297 	return ipv6_only_sock(sk);
298 }
299 #else
300 #define __ipv6_only_sock(sk)	0
301 #define ipv6_only_sock(sk)	0
302 #define ipv6_sk_rxinfo(sk)	0
303 
inet6_sk(const struct sock * __sk)304 static inline struct ipv6_pinfo * inet6_sk(const struct sock *__sk)
305 {
306 	return NULL;
307 }
308 
309 static inline struct inet6_request_sock *
inet6_rsk(const struct request_sock * rsk)310 			inet6_rsk(const struct request_sock *rsk)
311 {
312 	return NULL;
313 }
314 
raw6_sk(const struct sock * sk)315 static inline struct raw6_sock *raw6_sk(const struct sock *sk)
316 {
317 	return NULL;
318 }
319 
320 #define inet6_rcv_saddr(__sk)	NULL
321 #define tcp_twsk_ipv6only(__sk)		0
322 #define inet_v6_ipv6only(__sk)		0
323 #endif /* IS_ENABLED(CONFIG_IPV6) */
324 
325 #define INET6_MATCH(__sk, __net, __saddr, __daddr, __ports, __dif)	\
326 	(((__sk)->sk_portpair == (__ports))			&&	\
327 	 ((__sk)->sk_family == AF_INET6)			&&	\
328 	 ipv6_addr_equal(&(__sk)->sk_v6_daddr, (__saddr))		&&	\
329 	 ipv6_addr_equal(&(__sk)->sk_v6_rcv_saddr, (__daddr))	&&	\
330 	 (!(__sk)->sk_bound_dev_if	||				\
331 	   ((__sk)->sk_bound_dev_if == (__dif))) 		&&	\
332 	 net_eq(sock_net(__sk), (__net)))
333 
334 #endif /* _IPV6_H */
335