File Index
Files and directories
Sign in
FILE

ipv6.h

File preview with syntax highlighting.

linux-6.19.14/include/linux/ipv6.h C
  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/cache.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 */
 13struct ipv6_devconf {
 14	/* RX & TX fastpath fields. */
 15	__cacheline_group_begin(ipv6_devconf_read_txrx);
 16	__s32		disable_ipv6;
 17	__s32		hop_limit;
 18	__s32		mtu6;
 19	__s32		forwarding;
 20	__s32		force_forwarding;
 21	__s32		disable_policy;
 22	__s32		proxy_ndp;
 23	__cacheline_group_end(ipv6_devconf_read_txrx);
 24
 25	__s32		accept_ra;
 26	__s32		accept_redirects;
 27	__s32		autoconf;
 28	__s32		dad_transmits;
 29	__s32		rtr_solicits;
 30	__s32		rtr_solicit_interval;
 31	__s32		rtr_solicit_max_interval;
 32	__s32		rtr_solicit_delay;
 33	__s32		force_mld_version;
 34	__s32		mldv1_unsolicited_report_interval;
 35	__s32		mldv2_unsolicited_report_interval;
 36	__s32		use_tempaddr;
 37	__s32		temp_valid_lft;
 38	__s32		temp_prefered_lft;
 39	__s32		regen_min_advance;
 40	__s32		regen_max_retry;
 41	__s32		max_desync_factor;
 42	__s32		max_addresses;
 43	__s32		accept_ra_defrtr;
 44	__u32		ra_defrtr_metric;
 45	__s32		accept_ra_min_hop_limit;
 46	__s32		accept_ra_min_lft;
 47	__s32		accept_ra_pinfo;
 48	__s32		ignore_routes_with_linkdown;
 49#ifdef CONFIG_IPV6_ROUTER_PREF
 50	__s32		accept_ra_rtr_pref;
 51	__s32		rtr_probe_interval;
 52#ifdef CONFIG_IPV6_ROUTE_INFO
 53	__s32		accept_ra_rt_info_min_plen;
 54	__s32		accept_ra_rt_info_max_plen;
 55#endif
 56#endif
 57	__s32		accept_source_route;
 58	__s32		accept_ra_from_local;
 59#ifdef CONFIG_IPV6_OPTIMISTIC_DAD
 60	__s32		optimistic_dad;
 61	__s32		use_optimistic;
 62#endif
 63#ifdef CONFIG_IPV6_MROUTE
 64	atomic_t	mc_forwarding;
 65#endif
 66	__s32		drop_unicast_in_l2_multicast;
 67	__s32		accept_dad;
 68	__s32		force_tllao;
 69	__s32           ndisc_notify;
 70	__s32		suppress_frag_ndisc;
 71	__s32		accept_ra_mtu;
 72	__s32		drop_unsolicited_na;
 73	__s32		accept_untracked_na;
 74	struct ipv6_stable_secret {
 75		bool initialized;
 76		struct in6_addr secret;
 77	} stable_secret;
 78	__s32		use_oif_addrs_only;
 79	__s32		keep_addr_on_down;
 80	__s32		seg6_enabled;
 81#ifdef CONFIG_IPV6_SEG6_HMAC
 82	__s32		seg6_require_hmac;
 83#endif
 84	__u32		enhanced_dad;
 85	__u32		addr_gen_mode;
 86	__s32           ndisc_tclass;
 87	__s32		rpl_seg_enabled;
 88	__u32		ioam6_id;
 89	__u32		ioam6_id_wide;
 90	__u8		ioam6_enabled;
 91	__u8		ndisc_evict_nocarrier;
 92	__u8		ra_honor_pio_life;
 93	__u8		ra_honor_pio_pflag;
 94
 95	struct ctl_table_header *sysctl_header;
 96};
 97
 98struct ipv6_params {
 99	__s32 disable_ipv6;
100	__s32 autoconf;
101};
102extern struct ipv6_params ipv6_defaults;
103#include <linux/tcp.h>
104#include <linux/udp.h>
105
106#include <net/inet_sock.h>
107
108static inline struct ipv6hdr *ipv6_hdr(const struct sk_buff *skb)
109{
110	return (struct ipv6hdr *)skb_network_header(skb);
111}
112
113static inline struct ipv6hdr *inner_ipv6_hdr(const struct sk_buff *skb)
114{
115	return (struct ipv6hdr *)skb_inner_network_header(skb);
116}
117
118static inline struct ipv6hdr *ipipv6_hdr(const struct sk_buff *skb)
119{
120	return (struct ipv6hdr *)skb_transport_header(skb);
121}
122
123static inline unsigned int ipv6_transport_len(const struct sk_buff *skb)
124{
125	return ntohs(ipv6_hdr(skb)->payload_len) + sizeof(struct ipv6hdr) -
126	       skb_network_header_len(skb);
127}
128
129/* 
130   This structure contains results of exthdrs parsing
131   as offsets from skb->nh.
132 */
133
134struct inet6_skb_parm {
135	int			iif;
136	__be16			ra;
137	__u16			dst0;
138	__u16			srcrt;
139	__u16			dst1;
140	__u16			lastopt;
141	__u16			nhoff;
142	__u16			flags;
143#if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
144	__u16			dsthao;
145#endif
146	__u16			frag_max_size;
147	__u16			srhoff;
148
149#define IP6SKB_XFRM_TRANSFORMED	1
150#define IP6SKB_FORWARDED	2
151#define IP6SKB_REROUTED		4
152#define IP6SKB_ROUTERALERT	8
153#define IP6SKB_FRAGMENTED      16
154#define IP6SKB_HOPBYHOP        32
155#define IP6SKB_L3SLAVE         64
156#define IP6SKB_JUMBOGRAM      128
157#define IP6SKB_SEG6	      256
158#define IP6SKB_FAKEJUMBO      512
159#define IP6SKB_MULTIPATH      1024
160#define IP6SKB_MCROUTE        2048
161};
162
163#if defined(CONFIG_NET_L3_MASTER_DEV)
164static inline bool ipv6_l3mdev_skb(__u16 flags)
165{
166	return flags & IP6SKB_L3SLAVE;
167}
168#else
169static inline bool ipv6_l3mdev_skb(__u16 flags)
170{
171	return false;
172}
173#endif
174
175#define IP6CB(skb)	((struct inet6_skb_parm*)((skb)->cb))
176#define IP6CBMTU(skb)	((struct ip6_mtuinfo *)((skb)->cb))
177
178static inline int inet6_iif(const struct sk_buff *skb)
179{
180	bool l3_slave = ipv6_l3mdev_skb(IP6CB(skb)->flags);
181
182	return l3_slave ? skb->skb_iif : IP6CB(skb)->iif;
183}
184
185static inline bool inet6_is_jumbogram(const struct sk_buff *skb)
186{
187	return !!(IP6CB(skb)->flags & IP6SKB_JUMBOGRAM);
188}
189
190/* can not be used in TCP layer after tcp_v6_fill_cb */
191static inline int inet6_sdif(const struct sk_buff *skb)
192{
193#if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV)
194	if (skb && ipv6_l3mdev_skb(IP6CB(skb)->flags))
195		return IP6CB(skb)->iif;
196#endif
197	return 0;
198}
199
200struct tcp6_request_sock {
201	struct tcp_request_sock	  tcp6rsk_tcp;
202};
203
204struct ipv6_mc_socklist;
205struct ipv6_ac_socklist;
206struct ipv6_fl_socklist;
207
208struct inet6_cork {
209	struct ipv6_txoptions *opt;
210	u8 hop_limit;
211	u8 tclass;
212	u8 dontfrag:1;
213};
214
215/* struct ipv6_pinfo - ipv6 private area */
216struct ipv6_pinfo {
217	/* Used in tx path (inet6_csk_route_socket(), ip6_xmit()) */
218	struct in6_addr 	saddr;
219	__be32			flow_label;
220	u32			dst_cookie;
221	struct ipv6_txoptions __rcu	*opt;
222	s16			hop_limit;
223	u8			pmtudisc;
224	u8			tclass;
225#ifdef CONFIG_IPV6_SUBTREES
226	bool			saddr_cache;
227#endif
228	bool			daddr_cache;
229
230	u8			mcast_hops;
231	u32			frag_size;
232
233	int			ucast_oif;
234	int			mcast_oif;
235
236	/* pktoption flags */
237	union {
238		struct {
239			u16	srcrt:1,
240				osrcrt:1,
241			        rxinfo:1,
242			        rxoinfo:1,
243				rxhlim:1,
244				rxohlim:1,
245				hopopts:1,
246				ohopopts:1,
247				dstopts:1,
248				odstopts:1,
249                                rxflow:1,
250				rxtclass:1,
251				rxpmtu:1,
252				rxorigdstaddr:1,
253				recvfragsize:1;
254				/* 1 bits hole */
255		} bits;
256		u16		all;
257	} rxopt;
258
259	/* sockopt flags */
260	u8			srcprefs;	/* 001: prefer temporary address
261						 * 010: prefer public address
262						 * 100: prefer care-of address
263						 */
264	u8			min_hopcount;
265	__be32			rcv_flowinfo;
266	struct in6_pktinfo	sticky_pktinfo;
267
268	struct sk_buff		*pktoptions;
269	struct sk_buff		*rxpmtu;
270	struct inet6_cork	cork;
271
272	struct ipv6_mc_socklist	__rcu *ipv6_mc_list;
273	struct ipv6_ac_socklist	*ipv6_ac_list;
274};
275
276/* We currently use available bits from inet_sk(sk)->inet_flags,
277 * this could change in the future.
278 */
279#define inet6_test_bit(nr, sk)			\
280	test_bit(INET_FLAGS_##nr, &inet_sk(sk)->inet_flags)
281#define inet6_set_bit(nr, sk)			\
282	set_bit(INET_FLAGS_##nr, &inet_sk(sk)->inet_flags)
283#define inet6_clear_bit(nr, sk)			\
284	clear_bit(INET_FLAGS_##nr, &inet_sk(sk)->inet_flags)
285#define inet6_assign_bit(nr, sk, val)		\
286	assign_bit(INET_FLAGS_##nr, &inet_sk(sk)->inet_flags, val)
287
288/* WARNING: don't change the layout of the members in {raw,udp,tcp}6_sock! */
289struct raw6_sock {
290	/* inet_sock has to be the first member of raw6_sock */
291	struct inet_sock	inet;
292	__u32			checksum;	/* perform checksum */
293	__u32			offset;		/* checksum offset  */
294	struct icmp6_filter	filter;
295	__u32			ip6mr_table;
296	struct numa_drop_counters drop_counters;
297	struct ipv6_pinfo	inet6;
298};
299
300struct udp6_sock {
301	struct udp_sock	  udp;
302
303	struct ipv6_pinfo inet6;
304};
305
306struct tcp6_sock {
307	struct tcp_sock	  tcp;
308
309	struct ipv6_pinfo inet6;
310};
311
312extern int inet6_sk_rebuild_header(struct sock *sk);
313
314struct tcp6_timewait_sock {
315	struct tcp_timewait_sock   tcp6tw_tcp;
316};
317
318#if IS_ENABLED(CONFIG_IPV6)
319bool ipv6_mod_enabled(void);
320
321static inline struct ipv6_pinfo *inet6_sk(const struct sock *__sk)
322{
323	return sk_fullsock(__sk) ? inet_sk(__sk)->pinet6 : NULL;
324}
325
326#define raw6_sk(ptr) container_of_const(ptr, struct raw6_sock, inet.sk)
327
328#define ipv6_only_sock(sk)	(sk->sk_ipv6only)
329#define ipv6_sk_rxinfo(sk)	((sk)->sk_family == PF_INET6 && \
330				 inet6_sk(sk)->rxopt.bits.rxinfo)
331
332static inline const struct in6_addr *inet6_rcv_saddr(const struct sock *sk)
333{
334	if (sk->sk_family == AF_INET6)
335		return &sk->sk_v6_rcv_saddr;
336	return NULL;
337}
338
339static inline int inet_v6_ipv6only(const struct sock *sk)
340{
341	/* ipv6only field is at same position for timewait and other sockets */
342	return ipv6_only_sock(sk);
343}
344#else
345#define ipv6_only_sock(sk)	0
346#define ipv6_sk_rxinfo(sk)	0
347
348static inline bool ipv6_mod_enabled(void)
349{
350	return false;
351}
352
353static inline struct ipv6_pinfo * inet6_sk(const struct sock *__sk)
354{
355	return NULL;
356}
357
358static inline struct raw6_sock *raw6_sk(const struct sock *sk)
359{
360	return NULL;
361}
362
363#define inet6_rcv_saddr(__sk)	NULL
364#define inet_v6_ipv6only(__sk)		0
365#endif /* IS_ENABLED(CONFIG_IPV6) */
366#endif /* _IPV6_H */
~/ Read-only file preview.