xref: /linux-6.15/include/net/ipv6.h (revision 0aeea21a)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  *	Linux INET6 implementation
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  *	Authors:
51da177e4SLinus Torvalds  *	Pedro Roque		<[email protected]>
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  *	This program is free software; you can redistribute it and/or
81da177e4SLinus Torvalds  *      modify it under the terms of the GNU General Public License
91da177e4SLinus Torvalds  *      as published by the Free Software Foundation; either version
101da177e4SLinus Torvalds  *      2 of the License, or (at your option) any later version.
111da177e4SLinus Torvalds  */
121da177e4SLinus Torvalds 
131da177e4SLinus Torvalds #ifndef _NET_IPV6_H
141da177e4SLinus Torvalds #define _NET_IPV6_H
151da177e4SLinus Torvalds 
161da177e4SLinus Torvalds #include <linux/ipv6.h>
171da177e4SLinus Torvalds #include <linux/hardirq.h>
1808dcdbf6SEric Dumazet #include <linux/jhash.h>
19*0aeea21aSReshetova, Elena #include <linux/refcount.h>
2020283d84SHerbert Xu #include <net/if_inet6.h>
211da177e4SLinus Torvalds #include <net/ndisc.h>
221da177e4SLinus Torvalds #include <net/flow.h>
231bd758ebSJiri Pirko #include <net/flow_dissector.h>
241da177e4SLinus Torvalds #include <net/snmp.h>
251da177e4SLinus Torvalds 
261da177e4SLinus Torvalds #define SIN6_LEN_RFC2133	24
271da177e4SLinus Torvalds 
281da177e4SLinus Torvalds #define IPV6_MAXPLEN		65535
291da177e4SLinus Torvalds 
301da177e4SLinus Torvalds /*
311da177e4SLinus Torvalds  *	NextHeader field of IPv6 header
321da177e4SLinus Torvalds  */
331da177e4SLinus Torvalds 
341da177e4SLinus Torvalds #define NEXTHDR_HOP		0	/* Hop-by-hop option header. */
351da177e4SLinus Torvalds #define NEXTHDR_TCP		6	/* TCP segment. */
361da177e4SLinus Torvalds #define NEXTHDR_UDP		17	/* UDP message. */
371da177e4SLinus Torvalds #define NEXTHDR_IPV6		41	/* IPv6 in IPv6 */
381da177e4SLinus Torvalds #define NEXTHDR_ROUTING		43	/* Routing header. */
391da177e4SLinus Torvalds #define NEXTHDR_FRAGMENT	44	/* Fragmentation/reassembly header. */
40c12b395aS[email protected] #define NEXTHDR_GRE		47	/* GRE header. */
411da177e4SLinus Torvalds #define NEXTHDR_ESP		50	/* Encapsulating security payload. */
421da177e4SLinus Torvalds #define NEXTHDR_AUTH		51	/* Authentication header. */
431da177e4SLinus Torvalds #define NEXTHDR_ICMP		58	/* ICMP for IPv6. */
441da177e4SLinus Torvalds #define NEXTHDR_NONE		59	/* No next header */
451da177e4SLinus Torvalds #define NEXTHDR_DEST		60	/* Destination options header. */
46280c571eSJoe Stringer #define NEXTHDR_SCTP		132	/* SCTP message. */
472b741653SMasahide NAKAMURA #define NEXTHDR_MOBILITY	135	/* Mobility header. */
481da177e4SLinus Torvalds 
491da177e4SLinus Torvalds #define NEXTHDR_MAX		255
501da177e4SLinus Torvalds 
511da177e4SLinus Torvalds #define IPV6_DEFAULT_HOPLIMIT   64
521da177e4SLinus Torvalds #define IPV6_DEFAULT_MCASTHOPS	1
531da177e4SLinus Torvalds 
541da177e4SLinus Torvalds /*
551da177e4SLinus Torvalds  *	Addr type
561da177e4SLinus Torvalds  *
571da177e4SLinus Torvalds  *	type	-	unicast | multicast
581da177e4SLinus Torvalds  *	scope	-	local	| site	    | global
591da177e4SLinus Torvalds  *	v4	-	compat
601da177e4SLinus Torvalds  *	v4mapped
611da177e4SLinus Torvalds  *	any
621da177e4SLinus Torvalds  *	loopback
631da177e4SLinus Torvalds  */
641da177e4SLinus Torvalds 
651da177e4SLinus Torvalds #define IPV6_ADDR_ANY		0x0000U
661da177e4SLinus Torvalds 
671da177e4SLinus Torvalds #define IPV6_ADDR_UNICAST      	0x0001U
681da177e4SLinus Torvalds #define IPV6_ADDR_MULTICAST    	0x0002U
691da177e4SLinus Torvalds 
701da177e4SLinus Torvalds #define IPV6_ADDR_LOOPBACK	0x0010U
711da177e4SLinus Torvalds #define IPV6_ADDR_LINKLOCAL	0x0020U
721da177e4SLinus Torvalds #define IPV6_ADDR_SITELOCAL	0x0040U
731da177e4SLinus Torvalds 
741da177e4SLinus Torvalds #define IPV6_ADDR_COMPATv4	0x0080U
751da177e4SLinus Torvalds 
761da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_MASK	0x00f0U
771da177e4SLinus Torvalds 
781da177e4SLinus Torvalds #define IPV6_ADDR_MAPPED	0x1000U
791da177e4SLinus Torvalds 
801da177e4SLinus Torvalds /*
811da177e4SLinus Torvalds  *	Addr scopes
821da177e4SLinus Torvalds  */
831da177e4SLinus Torvalds #define IPV6_ADDR_MC_SCOPE(a)	\
841da177e4SLinus Torvalds 	((a)->s6_addr[1] & 0x0f)	/* nonstandard */
851da177e4SLinus Torvalds #define __IPV6_ADDR_SCOPE_INVALID	-1
861da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_NODELOCAL	0x01
871da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_LINKLOCAL	0x02
881da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_SITELOCAL	0x05
891da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_ORGLOCAL	0x08
901da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_GLOBAL		0x0e
911da177e4SLinus Torvalds 
921da177e4SLinus Torvalds /*
935ced1339SLinus Lüssing  *	Addr flags
945ced1339SLinus Lüssing  */
955ced1339SLinus Lüssing #define IPV6_ADDR_MC_FLAG_TRANSIENT(a)	\
965ced1339SLinus Lüssing 	((a)->s6_addr[1] & 0x10)
975ced1339SLinus Lüssing #define IPV6_ADDR_MC_FLAG_PREFIX(a)	\
985ced1339SLinus Lüssing 	((a)->s6_addr[1] & 0x20)
995ced1339SLinus Lüssing #define IPV6_ADDR_MC_FLAG_RENDEZVOUS(a)	\
1005ced1339SLinus Lüssing 	((a)->s6_addr[1] & 0x40)
1015ced1339SLinus Lüssing 
1025ced1339SLinus Lüssing /*
1031da177e4SLinus Torvalds  *	fragmentation header
1041da177e4SLinus Torvalds  */
1051da177e4SLinus Torvalds 
1061da177e4SLinus Torvalds struct frag_hdr {
10744473a6bSAl Viro 	__u8	nexthdr;
10844473a6bSAl Viro 	__u8	reserved;
10944473a6bSAl Viro 	__be16	frag_off;
11044473a6bSAl Viro 	__be32	identification;
1111da177e4SLinus Torvalds };
1121da177e4SLinus Torvalds 
1131da177e4SLinus Torvalds #define	IP6_MF		0x0001
1141431fb31SPaul Durrant #define	IP6_OFFSET	0xFFF8
1151da177e4SLinus Torvalds 
116e110861fSLorenzo Colitti #define IP6_REPLY_MARK(net, mark) \
117e110861fSLorenzo Colitti 	((net)->ipv6.sysctl.fwmark_reflect ? (mark) : 0)
118e110861fSLorenzo Colitti 
1191da177e4SLinus Torvalds #include <net/sock.h>
1201da177e4SLinus Torvalds 
1211da177e4SLinus Torvalds /* sysctls */
1221da177e4SLinus Torvalds extern int sysctl_mld_max_msf;
1232f711939SHannes Frederic Sowa extern int sysctl_mld_qrv;
1243d7cc2baSPavel Emelyanov 
12513415e46SEric Dumazet #define _DEVINC(net, statname, mod, idev, field)			\
12614878f75SDavid L Stevens ({									\
12714878f75SDavid L Stevens 	struct inet6_dev *_idev = (idev);				\
12814878f75SDavid L Stevens 	if (likely(_idev != NULL))					\
12913415e46SEric Dumazet 		mod##SNMP_INC_STATS64((_idev)->stats.statname, (field));\
13013415e46SEric Dumazet 	mod##SNMP_INC_STATS64((net)->mib.statname##_statistics, (field));\
13114878f75SDavid L Stevens })
13214878f75SDavid L Stevens 
133be281e55SEric Dumazet /* per device counters are atomic_long_t */
13413415e46SEric Dumazet #define _DEVINCATOMIC(net, statname, mod, idev, field)			\
135be281e55SEric Dumazet ({									\
136be281e55SEric Dumazet 	struct inet6_dev *_idev = (idev);				\
137be281e55SEric Dumazet 	if (likely(_idev != NULL))					\
138be281e55SEric Dumazet 		SNMP_INC_STATS_ATOMIC_LONG((_idev)->stats.statname##dev, (field)); \
13913415e46SEric Dumazet 	mod##SNMP_INC_STATS((net)->mib.statname##_statistics, (field));\
140be281e55SEric Dumazet })
141be281e55SEric Dumazet 
1422a24444fSEric Dumazet /* per device and per net counters are atomic_long_t */
1432a24444fSEric Dumazet #define _DEVINC_ATOMIC_ATOMIC(net, statname, idev, field)		\
1442a24444fSEric Dumazet ({									\
1452a24444fSEric Dumazet 	struct inet6_dev *_idev = (idev);				\
1462a24444fSEric Dumazet 	if (likely(_idev != NULL))					\
1472a24444fSEric Dumazet 		SNMP_INC_STATS_ATOMIC_LONG((_idev)->stats.statname##dev, (field)); \
1482a24444fSEric Dumazet 	SNMP_INC_STATS_ATOMIC_LONG((net)->mib.statname##_statistics, (field));\
1492a24444fSEric Dumazet })
1502a24444fSEric Dumazet 
15113415e46SEric Dumazet #define _DEVADD(net, statname, mod, idev, field, val)			\
1528e7999c4SPavel Emelyanov ({									\
1538e7999c4SPavel Emelyanov 	struct inet6_dev *_idev = (idev);				\
1548e7999c4SPavel Emelyanov 	if (likely(_idev != NULL))					\
15513415e46SEric Dumazet 		mod##SNMP_ADD_STATS((_idev)->stats.statname, (field), (val)); \
15613415e46SEric Dumazet 	mod##SNMP_ADD_STATS((net)->mib.statname##_statistics, (field), (val));\
1578e7999c4SPavel Emelyanov })
1588e7999c4SPavel Emelyanov 
15913415e46SEric Dumazet #define _DEVUPD(net, statname, mod, idev, field, val)			\
160edf391ffSNeil Horman ({									\
161edf391ffSNeil Horman 	struct inet6_dev *_idev = (idev);				\
162edf391ffSNeil Horman 	if (likely(_idev != NULL))					\
16313415e46SEric Dumazet 		mod##SNMP_UPD_PO_STATS((_idev)->stats.statname, field, (val)); \
16413415e46SEric Dumazet 	mod##SNMP_UPD_PO_STATS((net)->mib.statname##_statistics, field, (val));\
165edf391ffSNeil Horman })
166edf391ffSNeil Horman 
1671da177e4SLinus Torvalds /* MIBs */
16814878f75SDavid L Stevens 
169087fe240SDenis V. Lunev #define IP6_INC_STATS(net, idev,field)		\
17013415e46SEric Dumazet 		_DEVINC(net, ipv6, , idev, field)
1711d015503SEric Dumazet #define __IP6_INC_STATS(net, idev,field)	\
17213415e46SEric Dumazet 		_DEVINC(net, ipv6, __, idev, field)
173edf391ffSNeil Horman #define IP6_ADD_STATS(net, idev,field,val)	\
17413415e46SEric Dumazet 		_DEVADD(net, ipv6, , idev, field, val)
1751d015503SEric Dumazet #define __IP6_ADD_STATS(net, idev,field,val)	\
17613415e46SEric Dumazet 		_DEVADD(net, ipv6, __, idev, field, val)
177edf391ffSNeil Horman #define IP6_UPD_PO_STATS(net, idev,field,val)   \
17813415e46SEric Dumazet 		_DEVUPD(net, ipv6, , idev, field, val)
179c2005eb0SEric Dumazet #define __IP6_UPD_PO_STATS(net, idev,field,val)   \
18013415e46SEric Dumazet 		_DEVUPD(net, ipv6, __, idev, field, val)
181087fe240SDenis V. Lunev #define ICMP6_INC_STATS(net, idev, field)	\
182be281e55SEric Dumazet 		_DEVINCATOMIC(net, icmpv6, , idev, field)
183a16292a0SEric Dumazet #define __ICMP6_INC_STATS(net, idev, field)	\
18413415e46SEric Dumazet 		_DEVINCATOMIC(net, icmpv6, __, idev, field)
18514878f75SDavid L Stevens 
186087fe240SDenis V. Lunev #define ICMP6MSGOUT_INC_STATS(net, idev, field)		\
1872a24444fSEric Dumazet 	_DEVINC_ATOMIC_ATOMIC(net, icmpv6msg, idev, field +256)
188f3832ed2SEric Dumazet #define ICMP6MSGIN_INC_STATS(net, idev, field)	\
1892a24444fSEric Dumazet 	_DEVINC_ATOMIC_ATOMIC(net, icmpv6msg, idev, field)
19014878f75SDavid L Stevens 
191fd2c3ef7SEric Dumazet struct ip6_ra_chain {
1921da177e4SLinus Torvalds 	struct ip6_ra_chain	*next;
1931da177e4SLinus Torvalds 	struct sock		*sk;
1941da177e4SLinus Torvalds 	int			sel;
1951da177e4SLinus Torvalds 	void			(*destructor)(struct sock *);
1961da177e4SLinus Torvalds };
1971da177e4SLinus Torvalds 
1981da177e4SLinus Torvalds extern struct ip6_ra_chain	*ip6_ra_chain;
1991da177e4SLinus Torvalds extern rwlock_t ip6_ra_lock;
2001da177e4SLinus Torvalds 
2011da177e4SLinus Torvalds /*
2021da177e4SLinus Torvalds    This structure is prepared by protocol, when parsing
2031da177e4SLinus Torvalds    ancillary data and passed to IPv6.
2041da177e4SLinus Torvalds  */
2051da177e4SLinus Torvalds 
206fd2c3ef7SEric Dumazet struct ipv6_txoptions {
207*0aeea21aSReshetova, Elena 	refcount_t		refcnt;
2081da177e4SLinus Torvalds 	/* Length of this structure */
2091da177e4SLinus Torvalds 	int			tot_len;
2101da177e4SLinus Torvalds 
2111da177e4SLinus Torvalds 	/* length of extension headers   */
2121da177e4SLinus Torvalds 
2131da177e4SLinus Torvalds 	__u16			opt_flen;	/* after fragment hdr */
2141da177e4SLinus Torvalds 	__u16			opt_nflen;	/* before fragment hdr */
2151da177e4SLinus Torvalds 
2161da177e4SLinus Torvalds 	struct ipv6_opt_hdr	*hopopt;
2171da177e4SLinus Torvalds 	struct ipv6_opt_hdr	*dst0opt;
2181da177e4SLinus Torvalds 	struct ipv6_rt_hdr	*srcrt;	/* Routing Header */
2191da177e4SLinus Torvalds 	struct ipv6_opt_hdr	*dst1opt;
22045f6fad8SEric Dumazet 	struct rcu_head		rcu;
2211da177e4SLinus Torvalds 	/* Option buffer, as read by IPV6_PKTOPTIONS, starts here. */
2221da177e4SLinus Torvalds };
2231da177e4SLinus Torvalds 
224fd2c3ef7SEric Dumazet struct ip6_flowlabel {
2257f0e44acSEric Dumazet 	struct ip6_flowlabel __rcu *next;
22690bcaf7bSAl Viro 	__be32			label;
227db3459d1SEric Dumazet 	atomic_t		users;
2281da177e4SLinus Torvalds 	struct in6_addr		dst;
2291da177e4SLinus Torvalds 	struct ipv6_txoptions	*opt;
2301da177e4SLinus Torvalds 	unsigned long		linger;
231d3aedd5eSYOSHIFUJI Hideaki / 吉藤英明 	struct rcu_head		rcu;
2321da177e4SLinus Torvalds 	u8			share;
2334f82f457SEric W. Biederman 	union {
2344f82f457SEric W. Biederman 		struct pid *pid;
2354f82f457SEric W. Biederman 		kuid_t uid;
2364f82f457SEric W. Biederman 	} owner;
2371da177e4SLinus Torvalds 	unsigned long		lastuse;
2381da177e4SLinus Torvalds 	unsigned long		expires;
23960e8fbc4SBenjamin Thery 	struct net		*fl_net;
2401da177e4SLinus Torvalds };
2411da177e4SLinus Torvalds 
242f3a7c66bSHarvey Harrison #define IPV6_FLOWINFO_MASK		cpu_to_be32(0x0FFFFFFF)
243f3a7c66bSHarvey Harrison #define IPV6_FLOWLABEL_MASK		cpu_to_be32(0x000FFFFF)
24482a584b7STom Herbert #define IPV6_FLOWLABEL_STATELESS_FLAG	cpu_to_be32(0x00080000)
24582a584b7STom Herbert 
24637cfee90SFlorent Fourcot #define IPV6_TCLASS_MASK (IPV6_FLOWINFO_MASK & ~IPV6_FLOWLABEL_MASK)
247d76ed22bSLi RongQing #define IPV6_TCLASS_SHIFT	20
2481da177e4SLinus Torvalds 
249fd2c3ef7SEric Dumazet struct ipv6_fl_socklist {
2507f0e44acSEric Dumazet 	struct ipv6_fl_socklist	__rcu	*next;
2511da177e4SLinus Torvalds 	struct ip6_flowlabel		*fl;
25218367681SYOSHIFUJI Hideaki / 吉藤英明 	struct rcu_head			rcu;
2531da177e4SLinus Torvalds };
2541da177e4SLinus Torvalds 
25526879da5SWei Wang struct ipcm6_cookie {
25626879da5SWei Wang 	__s16 hlimit;
25726879da5SWei Wang 	__s16 tclass;
25826879da5SWei Wang 	__s8  dontfrag;
25926879da5SWei Wang 	struct ipv6_txoptions *opt;
26026879da5SWei Wang };
26126879da5SWei Wang 
26245f6fad8SEric Dumazet static inline struct ipv6_txoptions *txopt_get(const struct ipv6_pinfo *np)
26345f6fad8SEric Dumazet {
26445f6fad8SEric Dumazet 	struct ipv6_txoptions *opt;
26545f6fad8SEric Dumazet 
26645f6fad8SEric Dumazet 	rcu_read_lock();
26745f6fad8SEric Dumazet 	opt = rcu_dereference(np->opt);
268e550785cSBenjamin Poirier 	if (opt) {
269*0aeea21aSReshetova, Elena 		if (!refcount_inc_not_zero(&opt->refcnt))
27045f6fad8SEric Dumazet 			opt = NULL;
271e550785cSBenjamin Poirier 		else
272e550785cSBenjamin Poirier 			opt = rcu_pointer_handoff(opt);
273e550785cSBenjamin Poirier 	}
27445f6fad8SEric Dumazet 	rcu_read_unlock();
27545f6fad8SEric Dumazet 	return opt;
27645f6fad8SEric Dumazet }
27745f6fad8SEric Dumazet 
27845f6fad8SEric Dumazet static inline void txopt_put(struct ipv6_txoptions *opt)
27945f6fad8SEric Dumazet {
280*0aeea21aSReshetova, Elena 	if (opt && refcount_dec_and_test(&opt->refcnt))
28145f6fad8SEric Dumazet 		kfree_rcu(opt, rcu);
28245f6fad8SEric Dumazet }
28345f6fad8SEric Dumazet 
2845c3a0fd7SJoe Perches struct ip6_flowlabel *fl6_sock_lookup(struct sock *sk, __be32 label);
2855c3a0fd7SJoe Perches struct ipv6_txoptions *fl6_merge_options(struct ipv6_txoptions *opt_space,
2861da177e4SLinus Torvalds 					 struct ip6_flowlabel *fl,
2871da177e4SLinus Torvalds 					 struct ipv6_txoptions *fopt);
2885c3a0fd7SJoe Perches void fl6_free_socklist(struct sock *sk);
2895c3a0fd7SJoe Perches int ipv6_flowlabel_opt(struct sock *sk, char __user *optval, int optlen);
29046e5f401SFlorent Fourcot int ipv6_flowlabel_opt_get(struct sock *sk, struct in6_flowlabel_req *freq,
29146e5f401SFlorent Fourcot 			   int flags);
2925c3a0fd7SJoe Perches int ip6_flowlabel_init(void);
2935c3a0fd7SJoe Perches void ip6_flowlabel_cleanup(void);
2941da177e4SLinus Torvalds 
2951da177e4SLinus Torvalds static inline void fl6_sock_release(struct ip6_flowlabel *fl)
2961da177e4SLinus Torvalds {
2971da177e4SLinus Torvalds 	if (fl)
2981da177e4SLinus Torvalds 		atomic_dec(&fl->users);
2991da177e4SLinus Torvalds }
3001da177e4SLinus Torvalds 
3015c3a0fd7SJoe Perches void icmpv6_notify(struct sk_buff *skb, u8 type, u8 code, __be32 info);
302b94f1c09SDavid S. Miller 
3036d0bfe22SLorenzo Colitti int icmpv6_push_pending_frames(struct sock *sk, struct flowi6 *fl6,
3046d0bfe22SLorenzo Colitti 			       struct icmp6hdr *thdr, int len);
3056d0bfe22SLorenzo Colitti 
3065c3a0fd7SJoe Perches int ip6_ra_control(struct sock *sk, int sel);
3071da177e4SLinus Torvalds 
3085c3a0fd7SJoe Perches int ipv6_parse_hopopts(struct sk_buff *skb);
3091da177e4SLinus Torvalds 
3105c3a0fd7SJoe Perches struct ipv6_txoptions *ipv6_dup_options(struct sock *sk,
3115c3a0fd7SJoe Perches 					struct ipv6_txoptions *opt);
3125c3a0fd7SJoe Perches struct ipv6_txoptions *ipv6_renew_options(struct sock *sk,
3135c3a0fd7SJoe Perches 					  struct ipv6_txoptions *opt,
314333fad53SYOSHIFUJI Hideaki 					  int newtype,
315333fad53SYOSHIFUJI Hideaki 					  struct ipv6_opt_hdr __user *newopt,
316333fad53SYOSHIFUJI Hideaki 					  int newoptlen);
317e67ae213SHuw Davies struct ipv6_txoptions *
318e67ae213SHuw Davies ipv6_renew_options_kern(struct sock *sk,
319e67ae213SHuw Davies 			struct ipv6_txoptions *opt,
320e67ae213SHuw Davies 			int newtype,
321e67ae213SHuw Davies 			struct ipv6_opt_hdr *newopt,
322e67ae213SHuw Davies 			int newoptlen);
323df9890c3SYOSHIFUJI Hideaki struct ipv6_txoptions *ipv6_fixup_options(struct ipv6_txoptions *opt_space,
324df9890c3SYOSHIFUJI Hideaki 					  struct ipv6_txoptions *opt);
3251da177e4SLinus Torvalds 
326a224772dSEric Dumazet bool ipv6_opt_accepted(const struct sock *sk, const struct sk_buff *skb,
327a224772dSEric Dumazet 		       const struct inet6_skb_parm *opt);
328ceba1832SHuw Davies struct ipv6_txoptions *ipv6_update_options(struct sock *sk,
329ceba1832SHuw Davies 					   struct ipv6_txoptions *opt);
330399c07deSArnaldo Carvalho de Melo 
331aeaf6e9dSShmulik Ladkani static inline bool ipv6_accept_ra(struct inet6_dev *idev)
332aeaf6e9dSShmulik Ladkani {
333aeaf6e9dSShmulik Ladkani 	/* If forwarding is enabled, RA are not accepted unless the special
334aeaf6e9dSShmulik Ladkani 	 * hybrid mode (accept_ra=2) is enabled.
335aeaf6e9dSShmulik Ladkani 	 */
336aeaf6e9dSShmulik Ladkani 	return idev->cnf.forwarding ? idev->cnf.accept_ra == 2 :
337aeaf6e9dSShmulik Ladkani 	    idev->cnf.accept_ra;
338aeaf6e9dSShmulik Ladkani }
339aeaf6e9dSShmulik Ladkani 
340d4915c08SAmerigo Wang #if IS_ENABLED(CONFIG_IPV6)
341d4915c08SAmerigo Wang static inline int ip6_frag_mem(struct net *net)
342d4915c08SAmerigo Wang {
343d433673eSJesper Dangaard Brouer 	return sum_frag_mem_limit(&net->ipv6.frags);
344d4915c08SAmerigo Wang }
345d4915c08SAmerigo Wang #endif
3461da177e4SLinus Torvalds 
347c2a93660SJesper Dangaard Brouer #define IPV6_FRAG_HIGH_THRESH	(4 * 1024*1024)	/* 4194304 */
348c2a93660SJesper Dangaard Brouer #define IPV6_FRAG_LOW_THRESH	(3 * 1024*1024)	/* 3145728 */
3491da177e4SLinus Torvalds #define IPV6_FRAG_TIMEOUT	(60 * HZ)	/* 60 seconds */
3501da177e4SLinus Torvalds 
3515c3a0fd7SJoe Perches int __ipv6_addr_type(const struct in6_addr *addr);
352b1cacb68SYOSHIFUJI Hideaki static inline int ipv6_addr_type(const struct in6_addr *addr)
353b1cacb68SYOSHIFUJI Hideaki {
354b1cacb68SYOSHIFUJI Hideaki 	return __ipv6_addr_type(addr) & 0xffff;
355b1cacb68SYOSHIFUJI Hideaki }
3561da177e4SLinus Torvalds 
3571da177e4SLinus Torvalds static inline int ipv6_addr_scope(const struct in6_addr *addr)
3581da177e4SLinus Torvalds {
359b1cacb68SYOSHIFUJI Hideaki 	return __ipv6_addr_type(addr) & IPV6_ADDR_SCOPE_MASK;
360b1cacb68SYOSHIFUJI Hideaki }
361b1cacb68SYOSHIFUJI Hideaki 
362b1cacb68SYOSHIFUJI Hideaki static inline int __ipv6_addr_src_scope(int type)
363b1cacb68SYOSHIFUJI Hideaki {
364a02cec21SEric Dumazet 	return (type == IPV6_ADDR_ANY) ? __IPV6_ADDR_SCOPE_INVALID : (type >> 16);
365b1cacb68SYOSHIFUJI Hideaki }
366b1cacb68SYOSHIFUJI Hideaki 
367b1cacb68SYOSHIFUJI Hideaki static inline int ipv6_addr_src_scope(const struct in6_addr *addr)
368b1cacb68SYOSHIFUJI Hideaki {
369b1cacb68SYOSHIFUJI Hideaki 	return __ipv6_addr_src_scope(__ipv6_addr_type(addr));
3701da177e4SLinus Torvalds }
3711da177e4SLinus Torvalds 
372b7ef213eSHannes Frederic Sowa static inline bool __ipv6_addr_needs_scope_id(int type)
373b7ef213eSHannes Frederic Sowa {
374b7ef213eSHannes Frederic Sowa 	return type & IPV6_ADDR_LINKLOCAL ||
375b7ef213eSHannes Frederic Sowa 	       (type & IPV6_ADDR_MULTICAST &&
376b7ef213eSHannes Frederic Sowa 		(type & (IPV6_ADDR_LOOPBACK|IPV6_ADDR_LINKLOCAL)));
377b7ef213eSHannes Frederic Sowa }
378b7ef213eSHannes Frederic Sowa 
379b7ef213eSHannes Frederic Sowa static inline __u32 ipv6_iface_scope_id(const struct in6_addr *addr, int iface)
380b7ef213eSHannes Frederic Sowa {
381b7ef213eSHannes Frederic Sowa 	return __ipv6_addr_needs_scope_id(__ipv6_addr_type(addr)) ? iface : 0;
382b7ef213eSHannes Frederic Sowa }
383b7ef213eSHannes Frederic Sowa 
3841da177e4SLinus Torvalds static inline int ipv6_addr_cmp(const struct in6_addr *a1, const struct in6_addr *a2)
3851da177e4SLinus Torvalds {
386db3459d1SEric Dumazet 	return memcmp(a1, a2, sizeof(struct in6_addr));
3871da177e4SLinus Torvalds }
3881da177e4SLinus Torvalds 
3891a203cb3SEric Dumazet static inline bool
390f2ffd9eeSPatrick McHardy ipv6_masked_addr_cmp(const struct in6_addr *a1, const struct in6_addr *m,
391f2ffd9eeSPatrick McHardy 		     const struct in6_addr *a2)
392f2ffd9eeSPatrick McHardy {
3931a203cb3SEric Dumazet #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
3941a203cb3SEric Dumazet 	const unsigned long *ul1 = (const unsigned long *)a1;
3951a203cb3SEric Dumazet 	const unsigned long *ulm = (const unsigned long *)m;
3961a203cb3SEric Dumazet 	const unsigned long *ul2 = (const unsigned long *)a2;
3971a203cb3SEric Dumazet 
3981a203cb3SEric Dumazet 	return !!(((ul1[0] ^ ul2[0]) & ulm[0]) |
3991a203cb3SEric Dumazet 		  ((ul1[1] ^ ul2[1]) & ulm[1]));
4001a203cb3SEric Dumazet #else
401a02cec21SEric Dumazet 	return !!(((a1->s6_addr32[0] ^ a2->s6_addr32[0]) & m->s6_addr32[0]) |
402fed85383SYOSHIFUJI Hideaki 		  ((a1->s6_addr32[1] ^ a2->s6_addr32[1]) & m->s6_addr32[1]) |
403fed85383SYOSHIFUJI Hideaki 		  ((a1->s6_addr32[2] ^ a2->s6_addr32[2]) & m->s6_addr32[2]) |
404a02cec21SEric Dumazet 		  ((a1->s6_addr32[3] ^ a2->s6_addr32[3]) & m->s6_addr32[3]));
4051a203cb3SEric Dumazet #endif
406f2ffd9eeSPatrick McHardy }
407f2ffd9eeSPatrick McHardy 
4081da177e4SLinus Torvalds static inline void ipv6_addr_prefix(struct in6_addr *pfx,
4091da177e4SLinus Torvalds 				    const struct in6_addr *addr,
4101da177e4SLinus Torvalds 				    int plen)
4111da177e4SLinus Torvalds {
4121da177e4SLinus Torvalds 	/* caller must guarantee 0 <= plen <= 128 */
4131da177e4SLinus Torvalds 	int o = plen >> 3,
4141da177e4SLinus Torvalds 	    b = plen & 0x7;
4151da177e4SLinus Torvalds 
416db3459d1SEric Dumazet 	memset(pfx->s6_addr, 0, sizeof(pfx->s6_addr));
4171da177e4SLinus Torvalds 	memcpy(pfx->s6_addr, addr, o);
418db3459d1SEric Dumazet 	if (b != 0)
4191da177e4SLinus Torvalds 		pfx->s6_addr[o] = addr->s6_addr[o] & (0xff00 >> b);
4201da177e4SLinus Torvalds }
4211da177e4SLinus Torvalds 
422818f1f3eSAlexander Aring static inline void ipv6_addr_prefix_copy(struct in6_addr *addr,
423818f1f3eSAlexander Aring 					 const struct in6_addr *pfx,
424818f1f3eSAlexander Aring 					 int plen)
425818f1f3eSAlexander Aring {
426818f1f3eSAlexander Aring 	/* caller must guarantee 0 <= plen <= 128 */
427818f1f3eSAlexander Aring 	int o = plen >> 3,
428818f1f3eSAlexander Aring 	    b = plen & 0x7;
429818f1f3eSAlexander Aring 
430818f1f3eSAlexander Aring 	memcpy(addr->s6_addr, pfx, o);
431818f1f3eSAlexander Aring 	if (b != 0) {
432818f1f3eSAlexander Aring 		addr->s6_addr[o] &= ~(0xff00 >> b);
433818f1f3eSAlexander Aring 		addr->s6_addr[o] |= (pfx->s6_addr[o] & (0xff00 >> b));
434818f1f3eSAlexander Aring 	}
435818f1f3eSAlexander Aring }
436818f1f3eSAlexander Aring 
4375206c579SYOSHIFUJI Hideaki / 吉藤英明 static inline void __ipv6_addr_set_half(__be32 *addr,
4385206c579SYOSHIFUJI Hideaki / 吉藤英明 					__be32 wh, __be32 wl)
4395206c579SYOSHIFUJI Hideaki / 吉藤英明 {
4405206c579SYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
4415206c579SYOSHIFUJI Hideaki / 吉藤英明 #if defined(__BIG_ENDIAN)
4425206c579SYOSHIFUJI Hideaki / 吉藤英明 	if (__builtin_constant_p(wh) && __builtin_constant_p(wl)) {
4435206c579SYOSHIFUJI Hideaki / 吉藤英明 		*(__force u64 *)addr = ((__force u64)(wh) << 32 | (__force u64)(wl));
4445206c579SYOSHIFUJI Hideaki / 吉藤英明 		return;
4455206c579SYOSHIFUJI Hideaki / 吉藤英明 	}
4465206c579SYOSHIFUJI Hideaki / 吉藤英明 #elif defined(__LITTLE_ENDIAN)
4475206c579SYOSHIFUJI Hideaki / 吉藤英明 	if (__builtin_constant_p(wl) && __builtin_constant_p(wh)) {
4485206c579SYOSHIFUJI Hideaki / 吉藤英明 		*(__force u64 *)addr = ((__force u64)(wl) << 32 | (__force u64)(wh));
4495206c579SYOSHIFUJI Hideaki / 吉藤英明 		return;
4505206c579SYOSHIFUJI Hideaki / 吉藤英明 	}
4515206c579SYOSHIFUJI Hideaki / 吉藤英明 #endif
4525206c579SYOSHIFUJI Hideaki / 吉藤英明 #endif
4535206c579SYOSHIFUJI Hideaki / 吉藤英明 	addr[0] = wh;
4545206c579SYOSHIFUJI Hideaki / 吉藤英明 	addr[1] = wl;
4555206c579SYOSHIFUJI Hideaki / 吉藤英明 }
4565206c579SYOSHIFUJI Hideaki / 吉藤英明 
4571da177e4SLinus Torvalds static inline void ipv6_addr_set(struct in6_addr *addr,
45848818f82SAl Viro 				     __be32 w1, __be32 w2,
45948818f82SAl Viro 				     __be32 w3, __be32 w4)
4601da177e4SLinus Torvalds {
4615206c579SYOSHIFUJI Hideaki / 吉藤英明 	__ipv6_addr_set_half(&addr->s6_addr32[0], w1, w2);
4625206c579SYOSHIFUJI Hideaki / 吉藤英明 	__ipv6_addr_set_half(&addr->s6_addr32[2], w3, w4);
4631da177e4SLinus Torvalds }
4641da177e4SLinus Torvalds 
46592113bfdSEric Dumazet static inline bool ipv6_addr_equal(const struct in6_addr *a1,
4661da177e4SLinus Torvalds 				   const struct in6_addr *a2)
4671da177e4SLinus Torvalds {
4681a203cb3SEric Dumazet #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
4691a203cb3SEric Dumazet 	const unsigned long *ul1 = (const unsigned long *)a1;
4701a203cb3SEric Dumazet 	const unsigned long *ul2 = (const unsigned long *)a2;
4711a203cb3SEric Dumazet 
4721a203cb3SEric Dumazet 	return ((ul1[0] ^ ul2[0]) | (ul1[1] ^ ul2[1])) == 0UL;
4731a203cb3SEric Dumazet #else
474a02cec21SEric Dumazet 	return ((a1->s6_addr32[0] ^ a2->s6_addr32[0]) |
475fed85383SYOSHIFUJI Hideaki 		(a1->s6_addr32[1] ^ a2->s6_addr32[1]) |
476fed85383SYOSHIFUJI Hideaki 		(a1->s6_addr32[2] ^ a2->s6_addr32[2]) |
477a02cec21SEric Dumazet 		(a1->s6_addr32[3] ^ a2->s6_addr32[3])) == 0;
4781a203cb3SEric Dumazet #endif
4791da177e4SLinus Torvalds }
4801da177e4SLinus Torvalds 
48138675170SYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
48238675170SYOSHIFUJI Hideaki / 吉藤英明 static inline bool __ipv6_prefix_equal64_half(const __be64 *a1,
48338675170SYOSHIFUJI Hideaki / 吉藤英明 					      const __be64 *a2,
48438675170SYOSHIFUJI Hideaki / 吉藤英明 					      unsigned int len)
48538675170SYOSHIFUJI Hideaki / 吉藤英明 {
486512613d7SFabio Baltieri 	if (len && ((*a1 ^ *a2) & cpu_to_be64((~0UL) << (64 - len))))
48738675170SYOSHIFUJI Hideaki / 吉藤英明 		return false;
48838675170SYOSHIFUJI Hideaki / 吉藤英明 	return true;
48938675170SYOSHIFUJI Hideaki / 吉藤英明 }
49038675170SYOSHIFUJI Hideaki / 吉藤英明 
49138675170SYOSHIFUJI Hideaki / 吉藤英明 static inline bool ipv6_prefix_equal(const struct in6_addr *addr1,
49238675170SYOSHIFUJI Hideaki / 吉藤英明 				     const struct in6_addr *addr2,
49338675170SYOSHIFUJI Hideaki / 吉藤英明 				     unsigned int prefixlen)
49438675170SYOSHIFUJI Hideaki / 吉藤英明 {
49538675170SYOSHIFUJI Hideaki / 吉藤英明 	const __be64 *a1 = (const __be64 *)addr1;
49638675170SYOSHIFUJI Hideaki / 吉藤英明 	const __be64 *a2 = (const __be64 *)addr2;
49738675170SYOSHIFUJI Hideaki / 吉藤英明 
49838675170SYOSHIFUJI Hideaki / 吉藤英明 	if (prefixlen >= 64) {
49938675170SYOSHIFUJI Hideaki / 吉藤英明 		if (a1[0] ^ a2[0])
50038675170SYOSHIFUJI Hideaki / 吉藤英明 			return false;
50138675170SYOSHIFUJI Hideaki / 吉藤英明 		return __ipv6_prefix_equal64_half(a1 + 1, a2 + 1, prefixlen - 64);
50238675170SYOSHIFUJI Hideaki / 吉藤英明 	}
50338675170SYOSHIFUJI Hideaki / 吉藤英明 	return __ipv6_prefix_equal64_half(a1, a2, prefixlen);
50438675170SYOSHIFUJI Hideaki / 吉藤英明 }
50538675170SYOSHIFUJI Hideaki / 吉藤英明 #else
5062ef97332SYOSHIFUJI Hideaki / 吉藤英明 static inline bool ipv6_prefix_equal(const struct in6_addr *addr1,
5072ef97332SYOSHIFUJI Hideaki / 吉藤英明 				     const struct in6_addr *addr2,
5081da177e4SLinus Torvalds 				     unsigned int prefixlen)
5091da177e4SLinus Torvalds {
5102ef97332SYOSHIFUJI Hideaki / 吉藤英明 	const __be32 *a1 = addr1->s6_addr32;
5112ef97332SYOSHIFUJI Hideaki / 吉藤英明 	const __be32 *a2 = addr2->s6_addr32;
51295c96174SEric Dumazet 	unsigned int pdw, pbi;
5131da177e4SLinus Torvalds 
5141da177e4SLinus Torvalds 	/* check complete u32 in prefix */
5151da177e4SLinus Torvalds 	pdw = prefixlen >> 5;
5161da177e4SLinus Torvalds 	if (pdw && memcmp(a1, a2, pdw << 2))
51792113bfdSEric Dumazet 		return false;
5181da177e4SLinus Torvalds 
5191da177e4SLinus Torvalds 	/* check incomplete u32 in prefix */
5201da177e4SLinus Torvalds 	pbi = prefixlen & 0x1f;
5211da177e4SLinus Torvalds 	if (pbi && ((a1[pdw] ^ a2[pdw]) & htonl((0xffffffff) << (32 - pbi))))
52292113bfdSEric Dumazet 		return false;
5231da177e4SLinus Torvalds 
52492113bfdSEric Dumazet 	return true;
5251da177e4SLinus Torvalds }
52638675170SYOSHIFUJI Hideaki / 吉藤英明 #endif
5271da177e4SLinus Torvalds 
5282588fe1dSPavel Emelyanov struct inet_frag_queue;
5292588fe1dSPavel Emelyanov 
5300b5ccb2eSPatrick McHardy enum ip6_defrag_users {
5310b5ccb2eSPatrick McHardy 	IP6_DEFRAG_LOCAL_DELIVER,
5320b5ccb2eSPatrick McHardy 	IP6_DEFRAG_CONNTRACK_IN,
5334be929beSAlexey Dobriyan 	__IP6_DEFRAG_CONNTRACK_IN	= IP6_DEFRAG_CONNTRACK_IN + USHRT_MAX,
5340b5ccb2eSPatrick McHardy 	IP6_DEFRAG_CONNTRACK_OUT,
5354be929beSAlexey Dobriyan 	__IP6_DEFRAG_CONNTRACK_OUT	= IP6_DEFRAG_CONNTRACK_OUT + USHRT_MAX,
5368fa9ff68SPatrick McHardy 	IP6_DEFRAG_CONNTRACK_BRIDGE_IN,
5374be929beSAlexey Dobriyan 	__IP6_DEFRAG_CONNTRACK_BRIDGE_IN = IP6_DEFRAG_CONNTRACK_BRIDGE_IN + USHRT_MAX,
5380b5ccb2eSPatrick McHardy };
5390b5ccb2eSPatrick McHardy 
540c6fda282SPavel Emelyanov struct ip6_create_arg {
541c6fda282SPavel Emelyanov 	__be32 id;
5420b5ccb2eSPatrick McHardy 	u32 user;
543b71d1d42SEric Dumazet 	const struct in6_addr *src;
544b71d1d42SEric Dumazet 	const struct in6_addr *dst;
545264640fcSMichal Kubeček 	int iif;
546eec2e618SHannes Frederic Sowa 	u8 ecn;
547c6fda282SPavel Emelyanov };
548c6fda282SPavel Emelyanov 
54936c77782SFlorian Westphal void ip6_frag_init(struct inet_frag_queue *q, const void *a);
55036c77782SFlorian Westphal bool ip6_frag_match(const struct inet_frag_queue *q, const void *a);
551c6fda282SPavel Emelyanov 
552b836c99fSAmerigo Wang /*
553b836c99fSAmerigo Wang  *	Equivalent of ipv4 struct ip
554b836c99fSAmerigo Wang  */
555b836c99fSAmerigo Wang struct frag_queue {
556b836c99fSAmerigo Wang 	struct inet_frag_queue	q;
557b836c99fSAmerigo Wang 
558b836c99fSAmerigo Wang 	__be32			id;		/* fragment id		*/
559b836c99fSAmerigo Wang 	u32			user;
560b836c99fSAmerigo Wang 	struct in6_addr		saddr;
561b836c99fSAmerigo Wang 	struct in6_addr		daddr;
562b836c99fSAmerigo Wang 
563b836c99fSAmerigo Wang 	int			iif;
564b836c99fSAmerigo Wang 	unsigned int		csum;
565b836c99fSAmerigo Wang 	__u16			nhoffset;
566eec2e618SHannes Frederic Sowa 	u8			ecn;
567b836c99fSAmerigo Wang };
568b836c99fSAmerigo Wang 
569b836c99fSAmerigo Wang void ip6_expire_frag_queue(struct net *net, struct frag_queue *fq,
570b836c99fSAmerigo Wang 			   struct inet_frags *frags);
571b836c99fSAmerigo Wang 
57292113bfdSEric Dumazet static inline bool ipv6_addr_any(const struct in6_addr *a)
5731da177e4SLinus Torvalds {
5741a203cb3SEric Dumazet #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
5751a203cb3SEric Dumazet 	const unsigned long *ul = (const unsigned long *)a;
5761a203cb3SEric Dumazet 
5771a203cb3SEric Dumazet 	return (ul[0] | ul[1]) == 0UL;
5781a203cb3SEric Dumazet #else
579a02cec21SEric Dumazet 	return (a->s6_addr32[0] | a->s6_addr32[1] |
580a02cec21SEric Dumazet 		a->s6_addr32[2] | a->s6_addr32[3]) == 0;
5811a203cb3SEric Dumazet #endif
5821da177e4SLinus Torvalds }
5831da177e4SLinus Torvalds 
584ddbe5032SEric Dumazet static inline u32 ipv6_addr_hash(const struct in6_addr *a)
585ddbe5032SEric Dumazet {
586ddbe5032SEric Dumazet #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
587ddbe5032SEric Dumazet 	const unsigned long *ul = (const unsigned long *)a;
588ddbe5032SEric Dumazet 	unsigned long x = ul[0] ^ ul[1];
589ddbe5032SEric Dumazet 
590ddbe5032SEric Dumazet 	return (u32)(x ^ (x >> 32));
591ddbe5032SEric Dumazet #else
592ddbe5032SEric Dumazet 	return (__force u32)(a->s6_addr32[0] ^ a->s6_addr32[1] ^
593ddbe5032SEric Dumazet 			     a->s6_addr32[2] ^ a->s6_addr32[3]);
594ddbe5032SEric Dumazet #endif
595ddbe5032SEric Dumazet }
596ddbe5032SEric Dumazet 
59708dcdbf6SEric Dumazet /* more secured version of ipv6_addr_hash() */
598b50026b5SHannes Frederic Sowa static inline u32 __ipv6_addr_jhash(const struct in6_addr *a, const u32 initval)
59908dcdbf6SEric Dumazet {
60008dcdbf6SEric Dumazet 	u32 v = (__force u32)a->s6_addr32[0] ^ (__force u32)a->s6_addr32[1];
60108dcdbf6SEric Dumazet 
60208dcdbf6SEric Dumazet 	return jhash_3words(v,
60308dcdbf6SEric Dumazet 			    (__force u32)a->s6_addr32[2],
60408dcdbf6SEric Dumazet 			    (__force u32)a->s6_addr32[3],
605b50026b5SHannes Frederic Sowa 			    initval);
60608dcdbf6SEric Dumazet }
60708dcdbf6SEric Dumazet 
60892113bfdSEric Dumazet static inline bool ipv6_addr_loopback(const struct in6_addr *a)
609f630e43aSYOSHIFUJI Hideaki {
610e287656bSYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
6111373a773SJeff Layton 	const __be64 *be = (const __be64 *)a;
612e287656bSYOSHIFUJI Hideaki / 吉藤英明 
6131373a773SJeff Layton 	return (be[0] | (be[1] ^ cpu_to_be64(1))) == 0UL;
614e287656bSYOSHIFUJI Hideaki / 吉藤英明 #else
615a02cec21SEric Dumazet 	return (a->s6_addr32[0] | a->s6_addr32[1] |
6161373a773SJeff Layton 		a->s6_addr32[2] | (a->s6_addr32[3] ^ cpu_to_be32(1))) == 0;
617e287656bSYOSHIFUJI Hideaki / 吉藤英明 #endif
618f630e43aSYOSHIFUJI Hideaki }
619f630e43aSYOSHIFUJI Hideaki 
6201373a773SJeff Layton /*
6211373a773SJeff Layton  * Note that we must __force cast these to unsigned long to make sparse happy,
6221373a773SJeff Layton  * since all of the endian-annotated types are fixed size regardless of arch.
6231373a773SJeff Layton  */
62492113bfdSEric Dumazet static inline bool ipv6_addr_v4mapped(const struct in6_addr *a)
625e773e4faSBrian Haley {
626a04d40b8SYOSHIFUJI Hideaki / 吉藤英明 	return (
627a04d40b8SYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
6281373a773SJeff Layton 		*(unsigned long *)a |
629a04d40b8SYOSHIFUJI Hideaki / 吉藤英明 #else
6301373a773SJeff Layton 		(__force unsigned long)(a->s6_addr32[0] | a->s6_addr32[1]) |
631a04d40b8SYOSHIFUJI Hideaki / 吉藤英明 #endif
6321373a773SJeff Layton 		(__force unsigned long)(a->s6_addr32[2] ^
6331373a773SJeff Layton 					cpu_to_be32(0x0000ffff))) == 0UL;
634e773e4faSBrian Haley }
635e773e4faSBrian Haley 
6361da177e4SLinus Torvalds /*
63799cd07a5SJuha-Matti Tapio  * Check for a RFC 4843 ORCHID address
63899cd07a5SJuha-Matti Tapio  * (Overlay Routable Cryptographic Hash Identifiers)
63999cd07a5SJuha-Matti Tapio  */
64092113bfdSEric Dumazet static inline bool ipv6_addr_orchid(const struct in6_addr *a)
64199cd07a5SJuha-Matti Tapio {
642a02cec21SEric Dumazet 	return (a->s6_addr32[0] & htonl(0xfffffff0)) == htonl(0x20010010);
64399cd07a5SJuha-Matti Tapio }
64499cd07a5SJuha-Matti Tapio 
6455c98631cSLorenzo Colitti static inline bool ipv6_addr_is_multicast(const struct in6_addr *addr)
6465c98631cSLorenzo Colitti {
6475c98631cSLorenzo Colitti 	return (addr->s6_addr32[0] & htonl(0xFF000000)) == htonl(0xFF000000);
6485c98631cSLorenzo Colitti }
6495c98631cSLorenzo Colitti 
650f15364bdSAurélien Charbon static inline void ipv6_addr_set_v4mapped(const __be32 addr,
651f15364bdSAurélien Charbon 					  struct in6_addr *v4mapped)
652f15364bdSAurélien Charbon {
653f15364bdSAurélien Charbon 	ipv6_addr_set(v4mapped,
654f15364bdSAurélien Charbon 			0, 0,
655f15364bdSAurélien Charbon 			htonl(0x0000FFFF),
656f15364bdSAurélien Charbon 			addr);
657f15364bdSAurélien Charbon }
658f15364bdSAurélien Charbon 
65999cd07a5SJuha-Matti Tapio /*
660971f359dSYOSHIFUJI Hideaki  * find the first different bit between two addresses
661971f359dSYOSHIFUJI Hideaki  * length of address must be a multiple of 32bits
662971f359dSYOSHIFUJI Hideaki  */
6639f2e7334SYOSHIFUJI Hideaki / 吉藤英明 static inline int __ipv6_addr_diff32(const void *token1, const void *token2, int addrlen)
664971f359dSYOSHIFUJI Hideaki {
665ef296f56SAl Viro 	const __be32 *a1 = token1, *a2 = token2;
666971f359dSYOSHIFUJI Hideaki 	int i;
667971f359dSYOSHIFUJI Hideaki 
668971f359dSYOSHIFUJI Hideaki 	addrlen >>= 2;
669971f359dSYOSHIFUJI Hideaki 
670971f359dSYOSHIFUJI Hideaki 	for (i = 0; i < addrlen; i++) {
671ef296f56SAl Viro 		__be32 xb = a1[i] ^ a2[i];
672ef296f56SAl Viro 		if (xb)
673d57b8fb8SYOSHIFUJI Hideaki / 吉藤英明 			return i * 32 + 31 - __fls(ntohl(xb));
674971f359dSYOSHIFUJI Hideaki 	}
675971f359dSYOSHIFUJI Hideaki 
676971f359dSYOSHIFUJI Hideaki 	/*
677971f359dSYOSHIFUJI Hideaki 	 *	we should *never* get to this point since that
678971f359dSYOSHIFUJI Hideaki 	 *	would mean the addrs are equal
679971f359dSYOSHIFUJI Hideaki 	 *
680971f359dSYOSHIFUJI Hideaki 	 *	However, we do get to it 8) And exacly, when
681971f359dSYOSHIFUJI Hideaki 	 *	addresses are equal 8)
682971f359dSYOSHIFUJI Hideaki 	 *
683971f359dSYOSHIFUJI Hideaki 	 *	ip route add 1111::/128 via ...
684971f359dSYOSHIFUJI Hideaki 	 *	ip route add 1111::/64 via ...
685971f359dSYOSHIFUJI Hideaki 	 *	and we are here.
686971f359dSYOSHIFUJI Hideaki 	 *
687971f359dSYOSHIFUJI Hideaki 	 *	Ideally, this function should stop comparison
688971f359dSYOSHIFUJI Hideaki 	 *	at prefix length. It does not, but it is still OK,
689971f359dSYOSHIFUJI Hideaki 	 *	if returned value is greater than prefix length.
690971f359dSYOSHIFUJI Hideaki 	 *					--ANK (980803)
691971f359dSYOSHIFUJI Hideaki 	 */
692a02cec21SEric Dumazet 	return addrlen << 5;
693971f359dSYOSHIFUJI Hideaki }
694971f359dSYOSHIFUJI Hideaki 
6959f2e7334SYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
6969f2e7334SYOSHIFUJI Hideaki / 吉藤英明 static inline int __ipv6_addr_diff64(const void *token1, const void *token2, int addrlen)
6979f2e7334SYOSHIFUJI Hideaki / 吉藤英明 {
6989f2e7334SYOSHIFUJI Hideaki / 吉藤英明 	const __be64 *a1 = token1, *a2 = token2;
6999f2e7334SYOSHIFUJI Hideaki / 吉藤英明 	int i;
7009f2e7334SYOSHIFUJI Hideaki / 吉藤英明 
7019f2e7334SYOSHIFUJI Hideaki / 吉藤英明 	addrlen >>= 3;
7029f2e7334SYOSHIFUJI Hideaki / 吉藤英明 
7039f2e7334SYOSHIFUJI Hideaki / 吉藤英明 	for (i = 0; i < addrlen; i++) {
7049f2e7334SYOSHIFUJI Hideaki / 吉藤英明 		__be64 xb = a1[i] ^ a2[i];
7059f2e7334SYOSHIFUJI Hideaki / 吉藤英明 		if (xb)
7069f2e7334SYOSHIFUJI Hideaki / 吉藤英明 			return i * 64 + 63 - __fls(be64_to_cpu(xb));
7079f2e7334SYOSHIFUJI Hideaki / 吉藤英明 	}
7089f2e7334SYOSHIFUJI Hideaki / 吉藤英明 
7099f2e7334SYOSHIFUJI Hideaki / 吉藤英明 	return addrlen << 6;
7109f2e7334SYOSHIFUJI Hideaki / 吉藤英明 }
7119f2e7334SYOSHIFUJI Hideaki / 吉藤英明 #endif
7129f2e7334SYOSHIFUJI Hideaki / 吉藤英明 
7139f2e7334SYOSHIFUJI Hideaki / 吉藤英明 static inline int __ipv6_addr_diff(const void *token1, const void *token2, int addrlen)
7149f2e7334SYOSHIFUJI Hideaki / 吉藤英明 {
7159f2e7334SYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
7169f2e7334SYOSHIFUJI Hideaki / 吉藤英明 	if (__builtin_constant_p(addrlen) && !(addrlen & 7))
7179f2e7334SYOSHIFUJI Hideaki / 吉藤英明 		return __ipv6_addr_diff64(token1, token2, addrlen);
7189f2e7334SYOSHIFUJI Hideaki / 吉藤英明 #endif
7199f2e7334SYOSHIFUJI Hideaki / 吉藤英明 	return __ipv6_addr_diff32(token1, token2, addrlen);
7209f2e7334SYOSHIFUJI Hideaki / 吉藤英明 }
7219f2e7334SYOSHIFUJI Hideaki / 吉藤英明 
722971f359dSYOSHIFUJI Hideaki static inline int ipv6_addr_diff(const struct in6_addr *a1, const struct in6_addr *a2)
723971f359dSYOSHIFUJI Hideaki {
724971f359dSYOSHIFUJI Hideaki 	return __ipv6_addr_diff(a1, a2, sizeof(struct in6_addr));
725971f359dSYOSHIFUJI Hideaki }
726971f359dSYOSHIFUJI Hideaki 
7277f159867SEric Dumazet __be32 ipv6_select_ident(struct net *net,
728fd0273d7SMartin KaFai Lau 			 const struct in6_addr *daddr,
729fd0273d7SMartin KaFai Lau 			 const struct in6_addr *saddr);
7305a352dd0SHannes Frederic Sowa void ipv6_proxy_select_ident(struct net *net, struct sk_buff *skb);
7315188cd44SBen Hutchings 
7325c3a0fd7SJoe Perches int ip6_dst_hoplimit(struct dst_entry *dst);
7333ce9b35fSCong Wang 
7345c98631cSLorenzo Colitti static inline int ip6_sk_dst_hoplimit(struct ipv6_pinfo *np, struct flowi6 *fl6,
7355c98631cSLorenzo Colitti 				      struct dst_entry *dst)
7365c98631cSLorenzo Colitti {
7375c98631cSLorenzo Colitti 	int hlimit;
7385c98631cSLorenzo Colitti 
7395c98631cSLorenzo Colitti 	if (ipv6_addr_is_multicast(&fl6->daddr))
7405c98631cSLorenzo Colitti 		hlimit = np->mcast_hops;
7415c98631cSLorenzo Colitti 	else
7425c98631cSLorenzo Colitti 		hlimit = np->hop_limit;
7435c98631cSLorenzo Colitti 	if (hlimit < 0)
7445c98631cSLorenzo Colitti 		hlimit = ip6_dst_hoplimit(dst);
7455c98631cSLorenzo Colitti 	return hlimit;
7465c98631cSLorenzo Colitti }
7475c98631cSLorenzo Colitti 
748c3f83241STom Herbert /* copy IPv6 saddr & daddr to flow_keys, possibly using 64bit load/store
749c3f83241STom Herbert  * Equivalent to :	flow->v6addrs.src = iph->saddr;
750c3f83241STom Herbert  *			flow->v6addrs.dst = iph->daddr;
751c3f83241STom Herbert  */
752c3f83241STom Herbert static inline void iph_to_flow_copy_v6addrs(struct flow_keys *flow,
753c3f83241STom Herbert 					    const struct ipv6hdr *iph)
754c3f83241STom Herbert {
755c3f83241STom Herbert 	BUILD_BUG_ON(offsetof(typeof(flow->addrs), v6addrs.dst) !=
756c3f83241STom Herbert 		     offsetof(typeof(flow->addrs), v6addrs.src) +
757c3f83241STom Herbert 		     sizeof(flow->addrs.v6addrs.src));
758c3f83241STom Herbert 	memcpy(&flow->addrs.v6addrs, &iph->saddr, sizeof(flow->addrs.v6addrs));
759c3f83241STom Herbert 	flow->control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
760c3f83241STom Herbert }
761c3f83241STom Herbert 
762a37934fcSFlorian Fainelli #if IS_ENABLED(CONFIG_IPV6)
76342240901STom Herbert 
76442240901STom Herbert /* Sysctl settings for net ipv6.auto_flowlabels */
76542240901STom Herbert #define IP6_AUTO_FLOW_LABEL_OFF		0
76642240901STom Herbert #define IP6_AUTO_FLOW_LABEL_OPTOUT	1
76742240901STom Herbert #define IP6_AUTO_FLOW_LABEL_OPTIN	2
76842240901STom Herbert #define IP6_AUTO_FLOW_LABEL_FORCED	3
76942240901STom Herbert 
77042240901STom Herbert #define IP6_AUTO_FLOW_LABEL_MAX		IP6_AUTO_FLOW_LABEL_FORCED
77142240901STom Herbert 
772b5677416STom Herbert #define IP6_DEFAULT_AUTO_FLOW_LABELS	IP6_AUTO_FLOW_LABEL_OPTOUT
77342240901STom Herbert 
774cb1ce2efSTom Herbert static inline __be32 ip6_make_flowlabel(struct net *net, struct sk_buff *skb,
77567800f9bSTom Herbert 					__be32 flowlabel, bool autolabel,
77667800f9bSTom Herbert 					struct flowi6 *fl6)
777cb1ce2efSTom Herbert {
77867765146SEric Dumazet 	u32 hash;
779cb1ce2efSTom Herbert 
78090427ef5SDimitris Michailidis 	/* @flowlabel may include more than a flow label, eg, the traffic class.
78190427ef5SDimitris Michailidis 	 * Here we want only the flow label value.
78290427ef5SDimitris Michailidis 	 */
78390427ef5SDimitris Michailidis 	flowlabel &= IPV6_FLOWLABEL_MASK;
78490427ef5SDimitris Michailidis 
78542240901STom Herbert 	if (flowlabel ||
78642240901STom Herbert 	    net->ipv6.sysctl.auto_flowlabels == IP6_AUTO_FLOW_LABEL_OFF ||
78742240901STom Herbert 	    (!autolabel &&
78842240901STom Herbert 	     net->ipv6.sysctl.auto_flowlabels != IP6_AUTO_FLOW_LABEL_FORCED))
78942240901STom Herbert 		return flowlabel;
79042240901STom Herbert 
79167800f9bSTom Herbert 	hash = skb_get_hash_flowi6(skb, fl6);
792cb1ce2efSTom Herbert 
793cb1ce2efSTom Herbert 	/* Since this is being sent on the wire obfuscate hash a bit
794cb1ce2efSTom Herbert 	 * to minimize possbility that any useful information to an
795cb1ce2efSTom Herbert 	 * attacker is leaked. Only lower 20 bits are relevant.
796cb1ce2efSTom Herbert 	 */
79742240901STom Herbert 	rol32(hash, 16);
798cb1ce2efSTom Herbert 
79967765146SEric Dumazet 	flowlabel = (__force __be32)hash & IPV6_FLOWLABEL_MASK;
80082a584b7STom Herbert 
80182a584b7STom Herbert 	if (net->ipv6.sysctl.flowlabel_state_ranges)
80282a584b7STom Herbert 		flowlabel |= IPV6_FLOWLABEL_STATELESS_FLAG;
803cb1ce2efSTom Herbert 
804cb1ce2efSTom Herbert 	return flowlabel;
805cb1ce2efSTom Herbert }
80642240901STom Herbert 
80742240901STom Herbert static inline int ip6_default_np_autolabel(struct net *net)
80842240901STom Herbert {
80942240901STom Herbert 	switch (net->ipv6.sysctl.auto_flowlabels) {
81042240901STom Herbert 	case IP6_AUTO_FLOW_LABEL_OFF:
81142240901STom Herbert 	case IP6_AUTO_FLOW_LABEL_OPTIN:
81242240901STom Herbert 	default:
81342240901STom Herbert 		return 0;
81442240901STom Herbert 	case IP6_AUTO_FLOW_LABEL_OPTOUT:
81542240901STom Herbert 	case IP6_AUTO_FLOW_LABEL_FORCED:
81642240901STom Herbert 		return 1;
81742240901STom Herbert 	}
81842240901STom Herbert }
819a37934fcSFlorian Fainelli #else
820a37934fcSFlorian Fainelli static inline void ip6_set_txhash(struct sock *sk) { }
821a37934fcSFlorian Fainelli static inline __be32 ip6_make_flowlabel(struct net *net, struct sk_buff *skb,
82242240901STom Herbert 					__be32 flowlabel, bool autolabel,
82342240901STom Herbert 					struct flowi6 *fl6)
824a37934fcSFlorian Fainelli {
825a37934fcSFlorian Fainelli 	return flowlabel;
826a37934fcSFlorian Fainelli }
82742240901STom Herbert static inline int ip6_default_np_autolabel(struct net *net)
82842240901STom Herbert {
82942240901STom Herbert 	return 0;
83042240901STom Herbert }
831a37934fcSFlorian Fainelli #endif
832a37934fcSFlorian Fainelli 
833cb1ce2efSTom Herbert 
834971f359dSYOSHIFUJI Hideaki /*
8353e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明  *	Header manipulation
8363e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明  */
8373e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 static inline void ip6_flow_hdr(struct ipv6hdr *hdr, unsigned int tclass,
8383e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 				__be32 flowlabel)
8393e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 {
84007f623d3SYOSHIFUJI Hideaki 	*(__be32 *)hdr = htonl(0x60000000 | (tclass << 20)) | flowlabel;
8413e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 }
8423e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 
8436502ca52SYOSHIFUJI Hideaki / 吉藤英明 static inline __be32 ip6_flowinfo(const struct ipv6hdr *hdr)
8446502ca52SYOSHIFUJI Hideaki / 吉藤英明 {
8456502ca52SYOSHIFUJI Hideaki / 吉藤英明 	return *(__be32 *)hdr & IPV6_FLOWINFO_MASK;
8466502ca52SYOSHIFUJI Hideaki / 吉藤英明 }
8476502ca52SYOSHIFUJI Hideaki / 吉藤英明 
8483308de2bSFlorent Fourcot static inline __be32 ip6_flowlabel(const struct ipv6hdr *hdr)
8493308de2bSFlorent Fourcot {
8503308de2bSFlorent Fourcot 	return *(__be32 *)hdr & IPV6_FLOWLABEL_MASK;
8513308de2bSFlorent Fourcot }
8523308de2bSFlorent Fourcot 
853d76ed22bSLi RongQing static inline u8 ip6_tclass(__be32 flowinfo)
854d76ed22bSLi RongQing {
855d76ed22bSLi RongQing 	return ntohl(flowinfo & IPV6_TCLASS_MASK) >> IPV6_TCLASS_SHIFT;
856d76ed22bSLi RongQing }
857eaa93bf4SDaniel Borkmann 
858eaa93bf4SDaniel Borkmann static inline __be32 ip6_make_flowinfo(unsigned int tclass, __be32 flowlabel)
859eaa93bf4SDaniel Borkmann {
860eaa93bf4SDaniel Borkmann 	return htonl(tclass << IPV6_TCLASS_SHIFT) | flowlabel;
861eaa93bf4SDaniel Borkmann }
862eaa93bf4SDaniel Borkmann 
8633e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 /*
8641da177e4SLinus Torvalds  *	Prototypes exported by ipv6
8651da177e4SLinus Torvalds  */
8661da177e4SLinus Torvalds 
8671da177e4SLinus Torvalds /*
8681da177e4SLinus Torvalds  *	rcv function (called from netdevice level)
8691da177e4SLinus Torvalds  */
8701da177e4SLinus Torvalds 
8715c3a0fd7SJoe Perches int ipv6_rcv(struct sk_buff *skb, struct net_device *dev,
8725c3a0fd7SJoe Perches 	     struct packet_type *pt, struct net_device *orig_dev);
8731da177e4SLinus Torvalds 
8740c4b51f0SEric W. Biederman int ip6_rcv_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
875b05e1066SPatrick McHardy 
8761da177e4SLinus Torvalds /*
8771da177e4SLinus Torvalds  *	upper-layer output functions
8781da177e4SLinus Torvalds  */
8791c1e9d2bSEric Dumazet int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6,
88092e55f41SPablo Neira 	     __u32 mark, struct ipv6_txoptions *opt, int tclass);
8811da177e4SLinus Torvalds 
8825c3a0fd7SJoe Perches int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr);
8831da177e4SLinus Torvalds 
8845c3a0fd7SJoe Perches int ip6_append_data(struct sock *sk,
8855c3a0fd7SJoe Perches 		    int getfrag(void *from, char *to, int offset, int len,
8865c3a0fd7SJoe Perches 				int odd, struct sk_buff *skb),
88726879da5SWei Wang 		    void *from, int length, int transhdrlen,
88826879da5SWei Wang 		    struct ipcm6_cookie *ipc6, struct flowi6 *fl6,
88926879da5SWei Wang 		    struct rt6_info *rt, unsigned int flags,
890c14ac945SSoheil Hassas Yeganeh 		    const struct sockcm_cookie *sockc);
8911da177e4SLinus Torvalds 
8925c3a0fd7SJoe Perches int ip6_push_pending_frames(struct sock *sk);
8931da177e4SLinus Torvalds 
8945c3a0fd7SJoe Perches void ip6_flush_pending_frames(struct sock *sk);
8951da177e4SLinus Torvalds 
8966422398cSVlad Yasevich int ip6_send_skb(struct sk_buff *skb);
8976422398cSVlad Yasevich 
8986422398cSVlad Yasevich struct sk_buff *__ip6_make_skb(struct sock *sk, struct sk_buff_head *queue,
8996422398cSVlad Yasevich 			       struct inet_cork_full *cork,
9006422398cSVlad Yasevich 			       struct inet6_cork *v6_cork);
9016422398cSVlad Yasevich struct sk_buff *ip6_make_skb(struct sock *sk,
9026422398cSVlad Yasevich 			     int getfrag(void *from, char *to, int offset,
9036422398cSVlad Yasevich 					 int len, int odd, struct sk_buff *skb),
9046422398cSVlad Yasevich 			     void *from, int length, int transhdrlen,
90526879da5SWei Wang 			     struct ipcm6_cookie *ipc6, struct flowi6 *fl6,
90626879da5SWei Wang 			     struct rt6_info *rt, unsigned int flags,
907c14ac945SSoheil Hassas Yeganeh 			     const struct sockcm_cookie *sockc);
9086422398cSVlad Yasevich 
9096422398cSVlad Yasevich static inline struct sk_buff *ip6_finish_skb(struct sock *sk)
9106422398cSVlad Yasevich {
9116422398cSVlad Yasevich 	return __ip6_make_skb(sk, &sk->sk_write_queue, &inet_sk(sk)->cork,
9126422398cSVlad Yasevich 			      &inet6_sk(sk)->cork);
9136422398cSVlad Yasevich }
9146422398cSVlad Yasevich 
915343d60aaSRoopa Prabhu int ip6_dst_lookup(struct net *net, struct sock *sk, struct dst_entry **dst,
916343d60aaSRoopa Prabhu 		   struct flowi6 *fl6);
9173aef934fSEric Dumazet struct dst_entry *ip6_dst_lookup_flow(const struct sock *sk, struct flowi6 *fl6,
9180e0d44abSSteffen Klassert 				      const struct in6_addr *final_dst);
9195c3a0fd7SJoe Perches struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
9200e0d44abSSteffen Klassert 					 const struct in6_addr *final_dst);
9215c3a0fd7SJoe Perches struct dst_entry *ip6_blackhole_route(struct net *net,
92269ead7afSDavid S. Miller 				      struct dst_entry *orig_dst);
9231da177e4SLinus Torvalds 
9241da177e4SLinus Torvalds /*
9251da177e4SLinus Torvalds  *	skb processing functions
9261da177e4SLinus Torvalds  */
9271da177e4SLinus Torvalds 
928ede2059dSEric W. Biederman int ip6_output(struct net *net, struct sock *sk, struct sk_buff *skb);
9295c3a0fd7SJoe Perches int ip6_forward(struct sk_buff *skb);
9305c3a0fd7SJoe Perches int ip6_input(struct sk_buff *skb);
9315c3a0fd7SJoe Perches int ip6_mc_input(struct sk_buff *skb);
9321da177e4SLinus Torvalds 
933cf91a99dSEric W. Biederman int __ip6_local_out(struct net *net, struct sock *sk, struct sk_buff *skb);
93433224b16SEric W. Biederman int ip6_local_out(struct net *net, struct sock *sk, struct sk_buff *skb);
935ef76bc23SHerbert Xu 
9361da177e4SLinus Torvalds /*
9371da177e4SLinus Torvalds  *	Extension header (options) processing
9381da177e4SLinus Torvalds  */
9391da177e4SLinus Torvalds 
9405c3a0fd7SJoe Perches void ipv6_push_nfrag_opts(struct sk_buff *skb, struct ipv6_txoptions *opt,
941613fa3caSDavid Lebrun 			  u8 *proto, struct in6_addr **daddr_p,
942613fa3caSDavid Lebrun 			  struct in6_addr *saddr);
9435c3a0fd7SJoe Perches void ipv6_push_frag_opts(struct sk_buff *skb, struct ipv6_txoptions *opt,
9441da177e4SLinus Torvalds 			 u8 *proto);
9451da177e4SLinus Torvalds 
9465c3a0fd7SJoe Perches int ipv6_skip_exthdr(const struct sk_buff *, int start, u8 *nexthdrp,
9475c3a0fd7SJoe Perches 		     __be16 *frag_offp);
9481da177e4SLinus Torvalds 
9495c3a0fd7SJoe Perches bool ipv6_ext_hdr(u8 nexthdr);
9501da177e4SLinus Torvalds 
951f8f62675SJesse Gross enum {
952f8f62675SJesse Gross 	IP6_FH_F_FRAG		= (1 << 0),
953f8f62675SJesse Gross 	IP6_FH_F_AUTH		= (1 << 1),
9549195bb8eSAnsis Atteka 	IP6_FH_F_SKIP_RH	= (1 << 2),
955f8f62675SJesse Gross };
956f8f62675SJesse Gross 
957f8f62675SJesse Gross /* find specified header and get offset to it */
9585c3a0fd7SJoe Perches int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset, int target,
9595c3a0fd7SJoe Perches 		  unsigned short *fragoff, int *fragflg);
960f8f62675SJesse Gross 
9610868383bSHuw Davies int ipv6_find_tlv(const struct sk_buff *skb, int offset, int type);
962c61a4043SMasahide NAKAMURA 
9635c3a0fd7SJoe Perches struct in6_addr *fl6_update_dst(struct flowi6 *fl6,
96420c59de2SArnaud Ebalard 				const struct ipv6_txoptions *opt,
96520c59de2SArnaud Ebalard 				struct in6_addr *orig);
96620c59de2SArnaud Ebalard 
9671da177e4SLinus Torvalds /*
9681da177e4SLinus Torvalds  *	socket options (ipv6_sockglue.c)
9691da177e4SLinus Torvalds  */
9701da177e4SLinus Torvalds 
9715c3a0fd7SJoe Perches int ipv6_setsockopt(struct sock *sk, int level, int optname,
9725c3a0fd7SJoe Perches 		    char __user *optval, unsigned int optlen);
9735c3a0fd7SJoe Perches int ipv6_getsockopt(struct sock *sk, int level, int optname,
9745c3a0fd7SJoe Perches 		    char __user *optval, int __user *optlen);
9755c3a0fd7SJoe Perches int compat_ipv6_setsockopt(struct sock *sk, int level, int optname,
9765c3a0fd7SJoe Perches 			   char __user *optval, unsigned int optlen);
9775c3a0fd7SJoe Perches int compat_ipv6_getsockopt(struct sock *sk, int level, int optname,
9785c3a0fd7SJoe Perches 			   char __user *optval, int __user *optlen);
9791da177e4SLinus Torvalds 
9800382a25aSGuillaume Nault int __ip6_datagram_connect(struct sock *sk, struct sockaddr *addr,
9810382a25aSGuillaume Nault 			   int addr_len);
9825c3a0fd7SJoe Perches int ip6_datagram_connect(struct sock *sk, struct sockaddr *addr, int addr_len);
98382b276cdSHannes Frederic Sowa int ip6_datagram_connect_v6_only(struct sock *sk, struct sockaddr *addr,
98482b276cdSHannes Frederic Sowa 				 int addr_len);
98533c162a9SMartin KaFai Lau int ip6_datagram_dst_update(struct sock *sk, bool fix_sk_saddr);
986e646b657SMartin KaFai Lau void ip6_datagram_release_cb(struct sock *sk);
9871da177e4SLinus Torvalds 
98885fbaa75SHannes Frederic Sowa int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len,
98985fbaa75SHannes Frederic Sowa 		    int *addr_len);
99085fbaa75SHannes Frederic Sowa int ipv6_recv_rxpmtu(struct sock *sk, struct msghdr *msg, int len,
99185fbaa75SHannes Frederic Sowa 		     int *addr_len);
9925c3a0fd7SJoe Perches void ipv6_icmp_error(struct sock *sk, struct sk_buff *skb, int err, __be16 port,
9931da177e4SLinus Torvalds 		     u32 info, u8 *payload);
9945c3a0fd7SJoe Perches void ipv6_local_error(struct sock *sk, int err, struct flowi6 *fl6, u32 info);
9955c3a0fd7SJoe Perches void ipv6_local_rxpmtu(struct sock *sk, struct flowi6 *fl6, u32 mtu);
9961da177e4SLinus Torvalds 
9975c3a0fd7SJoe Perches int inet6_release(struct socket *sock);
9985c3a0fd7SJoe Perches int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len);
9995c3a0fd7SJoe Perches int inet6_getname(struct socket *sock, struct sockaddr *uaddr, int *uaddr_len,
10005c3a0fd7SJoe Perches 		  int peer);
10015c3a0fd7SJoe Perches int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
10021da177e4SLinus Torvalds 
10035c3a0fd7SJoe Perches int inet6_hash_connect(struct inet_timewait_death_row *death_row,
1004d8313f5cSArnaldo Carvalho de Melo 			      struct sock *sk);
1005d8313f5cSArnaldo Carvalho de Melo 
10061da177e4SLinus Torvalds /*
10071da177e4SLinus Torvalds  * reassembly.c
10081da177e4SLinus Torvalds  */
100990ddc4f0SEric Dumazet extern const struct proto_ops inet6_stream_ops;
101090ddc4f0SEric Dumazet extern const struct proto_ops inet6_dgram_ops;
101177d4b1d3SEric Dumazet extern const struct proto_ops inet6_sockraw_ops;
101220380731SArnaldo Carvalho de Melo 
101314c85021SArnaldo Carvalho de Melo struct group_source_req;
101414c85021SArnaldo Carvalho de Melo struct group_filter;
101514c85021SArnaldo Carvalho de Melo 
10165c3a0fd7SJoe Perches int ip6_mc_source(int add, int omode, struct sock *sk,
101720380731SArnaldo Carvalho de Melo 		  struct group_source_req *pgsr);
10185c3a0fd7SJoe Perches int ip6_mc_msfilter(struct sock *sk, struct group_filter *gsf);
10195c3a0fd7SJoe Perches int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf,
10205c3a0fd7SJoe Perches 		  struct group_filter __user *optval, int __user *optlen);
102120380731SArnaldo Carvalho de Melo 
102220380731SArnaldo Carvalho de Melo #ifdef CONFIG_PROC_FS
10235c3a0fd7SJoe Perches int ac6_proc_init(struct net *net);
10245c3a0fd7SJoe Perches void ac6_proc_exit(struct net *net);
10255c3a0fd7SJoe Perches int raw6_proc_init(void);
10265c3a0fd7SJoe Perches void raw6_proc_exit(void);
10275c3a0fd7SJoe Perches int tcp6_proc_init(struct net *net);
10285c3a0fd7SJoe Perches void tcp6_proc_exit(struct net *net);
10295c3a0fd7SJoe Perches int udp6_proc_init(struct net *net);
10305c3a0fd7SJoe Perches void udp6_proc_exit(struct net *net);
10315c3a0fd7SJoe Perches int udplite6_proc_init(void);
10325c3a0fd7SJoe Perches void udplite6_proc_exit(void);
10335c3a0fd7SJoe Perches int ipv6_misc_proc_init(void);
10345c3a0fd7SJoe Perches void ipv6_misc_proc_exit(void);
10355c3a0fd7SJoe Perches int snmp6_register_dev(struct inet6_dev *idev);
10365c3a0fd7SJoe Perches int snmp6_unregister_dev(struct inet6_dev *idev);
103720380731SArnaldo Carvalho de Melo 
10387f7d9a6bSHerbert Xu #else
10396ab57e7eSDaniel Lezcano static inline int ac6_proc_init(struct net *net) { return 0; }
10406ab57e7eSDaniel Lezcano static inline void ac6_proc_exit(struct net *net) { }
10416ab57e7eSDaniel Lezcano static inline int snmp6_register_dev(struct inet6_dev *idev) { return 0; }
10426ab57e7eSDaniel Lezcano static inline int snmp6_unregister_dev(struct inet6_dev *idev) { return 0; }
104320380731SArnaldo Carvalho de Melo #endif
104420380731SArnaldo Carvalho de Melo 
104520380731SArnaldo Carvalho de Melo #ifdef CONFIG_SYSCTL
10469e8cda3bSJoe Perches extern struct ctl_table ipv6_route_table_template[];
104720380731SArnaldo Carvalho de Melo 
10485c3a0fd7SJoe Perches struct ctl_table *ipv6_icmp_sysctl_init(struct net *net);
10495c3a0fd7SJoe Perches struct ctl_table *ipv6_route_sysctl_init(struct net *net);
10505c3a0fd7SJoe Perches int ipv6_sysctl_register(void);
10515c3a0fd7SJoe Perches void ipv6_sysctl_unregister(void);
105220380731SArnaldo Carvalho de Melo #endif
105320380731SArnaldo Carvalho de Melo 
105446a4dee0SMadhu Challa int ipv6_sock_mc_join(struct sock *sk, int ifindex,
105546a4dee0SMadhu Challa 		      const struct in6_addr *addr);
105646a4dee0SMadhu Challa int ipv6_sock_mc_drop(struct sock *sk, int ifindex,
105746a4dee0SMadhu Challa 		      const struct in6_addr *addr);
10581da177e4SLinus Torvalds #endif /* _NET_IPV6_H */
1059