xref: /linux-6.15/include/net/ipv6.h (revision f3832ed2)
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>
1920283d84SHerbert Xu #include <net/if_inet6.h>
201da177e4SLinus Torvalds #include <net/ndisc.h>
211da177e4SLinus Torvalds #include <net/flow.h>
221bd758ebSJiri Pirko #include <net/flow_dissector.h>
231da177e4SLinus Torvalds #include <net/snmp.h>
241da177e4SLinus Torvalds 
251da177e4SLinus Torvalds #define SIN6_LEN_RFC2133	24
261da177e4SLinus Torvalds 
271da177e4SLinus Torvalds #define IPV6_MAXPLEN		65535
281da177e4SLinus Torvalds 
291da177e4SLinus Torvalds /*
301da177e4SLinus Torvalds  *	NextHeader field of IPv6 header
311da177e4SLinus Torvalds  */
321da177e4SLinus Torvalds 
331da177e4SLinus Torvalds #define NEXTHDR_HOP		0	/* Hop-by-hop option header. */
341da177e4SLinus Torvalds #define NEXTHDR_TCP		6	/* TCP segment. */
351da177e4SLinus Torvalds #define NEXTHDR_UDP		17	/* UDP message. */
361da177e4SLinus Torvalds #define NEXTHDR_IPV6		41	/* IPv6 in IPv6 */
371da177e4SLinus Torvalds #define NEXTHDR_ROUTING		43	/* Routing header. */
381da177e4SLinus Torvalds #define NEXTHDR_FRAGMENT	44	/* Fragmentation/reassembly header. */
39c12b395aS[email protected] #define NEXTHDR_GRE		47	/* GRE header. */
401da177e4SLinus Torvalds #define NEXTHDR_ESP		50	/* Encapsulating security payload. */
411da177e4SLinus Torvalds #define NEXTHDR_AUTH		51	/* Authentication header. */
421da177e4SLinus Torvalds #define NEXTHDR_ICMP		58	/* ICMP for IPv6. */
431da177e4SLinus Torvalds #define NEXTHDR_NONE		59	/* No next header */
441da177e4SLinus Torvalds #define NEXTHDR_DEST		60	/* Destination options header. */
45280c571eSJoe Stringer #define NEXTHDR_SCTP		132	/* SCTP message. */
462b741653SMasahide NAKAMURA #define NEXTHDR_MOBILITY	135	/* Mobility header. */
471da177e4SLinus Torvalds 
481da177e4SLinus Torvalds #define NEXTHDR_MAX		255
491da177e4SLinus Torvalds 
501da177e4SLinus Torvalds #define IPV6_DEFAULT_HOPLIMIT   64
511da177e4SLinus Torvalds #define IPV6_DEFAULT_MCASTHOPS	1
521da177e4SLinus Torvalds 
531da177e4SLinus Torvalds /*
541da177e4SLinus Torvalds  *	Addr type
551da177e4SLinus Torvalds  *
561da177e4SLinus Torvalds  *	type	-	unicast | multicast
571da177e4SLinus Torvalds  *	scope	-	local	| site	    | global
581da177e4SLinus Torvalds  *	v4	-	compat
591da177e4SLinus Torvalds  *	v4mapped
601da177e4SLinus Torvalds  *	any
611da177e4SLinus Torvalds  *	loopback
621da177e4SLinus Torvalds  */
631da177e4SLinus Torvalds 
641da177e4SLinus Torvalds #define IPV6_ADDR_ANY		0x0000U
651da177e4SLinus Torvalds 
661da177e4SLinus Torvalds #define IPV6_ADDR_UNICAST      	0x0001U
671da177e4SLinus Torvalds #define IPV6_ADDR_MULTICAST    	0x0002U
681da177e4SLinus Torvalds 
691da177e4SLinus Torvalds #define IPV6_ADDR_LOOPBACK	0x0010U
701da177e4SLinus Torvalds #define IPV6_ADDR_LINKLOCAL	0x0020U
711da177e4SLinus Torvalds #define IPV6_ADDR_SITELOCAL	0x0040U
721da177e4SLinus Torvalds 
731da177e4SLinus Torvalds #define IPV6_ADDR_COMPATv4	0x0080U
741da177e4SLinus Torvalds 
751da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_MASK	0x00f0U
761da177e4SLinus Torvalds 
771da177e4SLinus Torvalds #define IPV6_ADDR_MAPPED	0x1000U
781da177e4SLinus Torvalds 
791da177e4SLinus Torvalds /*
801da177e4SLinus Torvalds  *	Addr scopes
811da177e4SLinus Torvalds  */
821da177e4SLinus Torvalds #define IPV6_ADDR_MC_SCOPE(a)	\
831da177e4SLinus Torvalds 	((a)->s6_addr[1] & 0x0f)	/* nonstandard */
841da177e4SLinus Torvalds #define __IPV6_ADDR_SCOPE_INVALID	-1
851da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_NODELOCAL	0x01
861da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_LINKLOCAL	0x02
871da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_SITELOCAL	0x05
881da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_ORGLOCAL	0x08
891da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_GLOBAL		0x0e
901da177e4SLinus Torvalds 
911da177e4SLinus Torvalds /*
925ced1339SLinus Lüssing  *	Addr flags
935ced1339SLinus Lüssing  */
945ced1339SLinus Lüssing #define IPV6_ADDR_MC_FLAG_TRANSIENT(a)	\
955ced1339SLinus Lüssing 	((a)->s6_addr[1] & 0x10)
965ced1339SLinus Lüssing #define IPV6_ADDR_MC_FLAG_PREFIX(a)	\
975ced1339SLinus Lüssing 	((a)->s6_addr[1] & 0x20)
985ced1339SLinus Lüssing #define IPV6_ADDR_MC_FLAG_RENDEZVOUS(a)	\
995ced1339SLinus Lüssing 	((a)->s6_addr[1] & 0x40)
1005ced1339SLinus Lüssing 
1015ced1339SLinus Lüssing /*
1021da177e4SLinus Torvalds  *	fragmentation header
1031da177e4SLinus Torvalds  */
1041da177e4SLinus Torvalds 
1051da177e4SLinus Torvalds struct frag_hdr {
10644473a6bSAl Viro 	__u8	nexthdr;
10744473a6bSAl Viro 	__u8	reserved;
10844473a6bSAl Viro 	__be16	frag_off;
10944473a6bSAl Viro 	__be32	identification;
1101da177e4SLinus Torvalds };
1111da177e4SLinus Torvalds 
1121da177e4SLinus Torvalds #define	IP6_MF		0x0001
1131431fb31SPaul Durrant #define	IP6_OFFSET	0xFFF8
1141da177e4SLinus Torvalds 
115e110861fSLorenzo Colitti #define IP6_REPLY_MARK(net, mark) \
116e110861fSLorenzo Colitti 	((net)->ipv6.sysctl.fwmark_reflect ? (mark) : 0)
117e110861fSLorenzo Colitti 
1181da177e4SLinus Torvalds #include <net/sock.h>
1191da177e4SLinus Torvalds 
1201da177e4SLinus Torvalds /* sysctls */
1211da177e4SLinus Torvalds extern int sysctl_mld_max_msf;
1222f711939SHannes Frederic Sowa extern int sysctl_mld_qrv;
1233d7cc2baSPavel Emelyanov 
124087fe240SDenis V. Lunev #define _DEVINC(net, statname, modifier, idev, field)			\
12514878f75SDavid L Stevens ({									\
12614878f75SDavid L Stevens 	struct inet6_dev *_idev = (idev);				\
12714878f75SDavid L Stevens 	if (likely(_idev != NULL))					\
12814878f75SDavid L Stevens 		SNMP_INC_STATS##modifier((_idev)->stats.statname, (field)); \
1299261e537SDenis V. Lunev 	SNMP_INC_STATS##modifier((net)->mib.statname##_statistics, (field));\
13014878f75SDavid L Stevens })
13114878f75SDavid L Stevens 
132be281e55SEric Dumazet /* per device counters are atomic_long_t */
133be281e55SEric Dumazet #define _DEVINCATOMIC(net, statname, modifier, idev, field)		\
134be281e55SEric Dumazet ({									\
135be281e55SEric Dumazet 	struct inet6_dev *_idev = (idev);				\
136be281e55SEric Dumazet 	if (likely(_idev != NULL))					\
137be281e55SEric Dumazet 		SNMP_INC_STATS_ATOMIC_LONG((_idev)->stats.statname##dev, (field)); \
138be281e55SEric Dumazet 	SNMP_INC_STATS##modifier((net)->mib.statname##_statistics, (field));\
139be281e55SEric Dumazet })
140be281e55SEric Dumazet 
1412a24444fSEric Dumazet /* per device and per net counters are atomic_long_t */
1422a24444fSEric Dumazet #define _DEVINC_ATOMIC_ATOMIC(net, statname, idev, field)		\
1432a24444fSEric Dumazet ({									\
1442a24444fSEric Dumazet 	struct inet6_dev *_idev = (idev);				\
1452a24444fSEric Dumazet 	if (likely(_idev != NULL))					\
1462a24444fSEric Dumazet 		SNMP_INC_STATS_ATOMIC_LONG((_idev)->stats.statname##dev, (field)); \
1472a24444fSEric Dumazet 	SNMP_INC_STATS_ATOMIC_LONG((net)->mib.statname##_statistics, (field));\
1482a24444fSEric Dumazet })
1492a24444fSEric Dumazet 
150087fe240SDenis V. Lunev #define _DEVADD(net, statname, modifier, idev, field, val)		\
1518e7999c4SPavel Emelyanov ({									\
1528e7999c4SPavel Emelyanov 	struct inet6_dev *_idev = (idev);				\
1538e7999c4SPavel Emelyanov 	if (likely(_idev != NULL))					\
1548e7999c4SPavel Emelyanov 		SNMP_ADD_STATS##modifier((_idev)->stats.statname, (field), (val)); \
1559261e537SDenis V. Lunev 	SNMP_ADD_STATS##modifier((net)->mib.statname##_statistics, (field), (val));\
1568e7999c4SPavel Emelyanov })
1578e7999c4SPavel Emelyanov 
158edf391ffSNeil Horman #define _DEVUPD(net, statname, modifier, idev, field, val)		\
159edf391ffSNeil Horman ({									\
160edf391ffSNeil Horman 	struct inet6_dev *_idev = (idev);				\
161edf391ffSNeil Horman 	if (likely(_idev != NULL))					\
162edf391ffSNeil Horman 		SNMP_UPD_PO_STATS##modifier((_idev)->stats.statname, field, (val)); \
163edf391ffSNeil Horman 	SNMP_UPD_PO_STATS##modifier((net)->mib.statname##_statistics, field, (val));\
164edf391ffSNeil Horman })
165edf391ffSNeil Horman 
1661da177e4SLinus Torvalds /* MIBs */
16714878f75SDavid L Stevens 
168087fe240SDenis V. Lunev #define IP6_INC_STATS(net, idev,field)		\
1694ce3c183SEric Dumazet 		_DEVINC(net, ipv6, 64, idev, field)
1701d015503SEric Dumazet #define __IP6_INC_STATS(net, idev,field)	\
1714ce3c183SEric Dumazet 		_DEVINC(net, ipv6, 64_BH, idev, field)
172edf391ffSNeil Horman #define IP6_ADD_STATS(net, idev,field,val)	\
1734ce3c183SEric Dumazet 		_DEVADD(net, ipv6, 64, idev, field, val)
1741d015503SEric Dumazet #define __IP6_ADD_STATS(net, idev,field,val)	\
1754ce3c183SEric Dumazet 		_DEVADD(net, ipv6, 64_BH, idev, field, val)
176edf391ffSNeil Horman #define IP6_UPD_PO_STATS(net, idev,field,val)   \
1774ce3c183SEric Dumazet 		_DEVUPD(net, ipv6, 64, idev, field, val)
178c2005eb0SEric Dumazet #define __IP6_UPD_PO_STATS(net, idev,field,val)   \
1794ce3c183SEric Dumazet 		_DEVUPD(net, ipv6, 64_BH, idev, field, val)
180087fe240SDenis V. Lunev #define ICMP6_INC_STATS(net, idev, field)	\
181be281e55SEric Dumazet 		_DEVINCATOMIC(net, icmpv6, , idev, field)
182a16292a0SEric Dumazet #define __ICMP6_INC_STATS(net, idev, field)	\
183be281e55SEric Dumazet 		_DEVINCATOMIC(net, icmpv6, _BH, idev, field)
18414878f75SDavid L Stevens 
185087fe240SDenis V. Lunev #define ICMP6MSGOUT_INC_STATS(net, idev, field)		\
1862a24444fSEric Dumazet 	_DEVINC_ATOMIC_ATOMIC(net, icmpv6msg, idev, field +256)
187*f3832ed2SEric Dumazet #define ICMP6MSGIN_INC_STATS(net, idev, field)	\
1882a24444fSEric Dumazet 	_DEVINC_ATOMIC_ATOMIC(net, icmpv6msg, idev, field)
18914878f75SDavid L Stevens 
190fd2c3ef7SEric Dumazet struct ip6_ra_chain {
1911da177e4SLinus Torvalds 	struct ip6_ra_chain	*next;
1921da177e4SLinus Torvalds 	struct sock		*sk;
1931da177e4SLinus Torvalds 	int			sel;
1941da177e4SLinus Torvalds 	void			(*destructor)(struct sock *);
1951da177e4SLinus Torvalds };
1961da177e4SLinus Torvalds 
1971da177e4SLinus Torvalds extern struct ip6_ra_chain	*ip6_ra_chain;
1981da177e4SLinus Torvalds extern rwlock_t ip6_ra_lock;
1991da177e4SLinus Torvalds 
2001da177e4SLinus Torvalds /*
2011da177e4SLinus Torvalds    This structure is prepared by protocol, when parsing
2021da177e4SLinus Torvalds    ancillary data and passed to IPv6.
2031da177e4SLinus Torvalds  */
2041da177e4SLinus Torvalds 
205fd2c3ef7SEric Dumazet struct ipv6_txoptions {
20645f6fad8SEric Dumazet 	atomic_t		refcnt;
2071da177e4SLinus Torvalds 	/* Length of this structure */
2081da177e4SLinus Torvalds 	int			tot_len;
2091da177e4SLinus Torvalds 
2101da177e4SLinus Torvalds 	/* length of extension headers   */
2111da177e4SLinus Torvalds 
2121da177e4SLinus Torvalds 	__u16			opt_flen;	/* after fragment hdr */
2131da177e4SLinus Torvalds 	__u16			opt_nflen;	/* before fragment hdr */
2141da177e4SLinus Torvalds 
2151da177e4SLinus Torvalds 	struct ipv6_opt_hdr	*hopopt;
2161da177e4SLinus Torvalds 	struct ipv6_opt_hdr	*dst0opt;
2171da177e4SLinus Torvalds 	struct ipv6_rt_hdr	*srcrt;	/* Routing Header */
2181da177e4SLinus Torvalds 	struct ipv6_opt_hdr	*dst1opt;
21945f6fad8SEric Dumazet 	struct rcu_head		rcu;
2201da177e4SLinus Torvalds 	/* Option buffer, as read by IPV6_PKTOPTIONS, starts here. */
2211da177e4SLinus Torvalds };
2221da177e4SLinus Torvalds 
223fd2c3ef7SEric Dumazet struct ip6_flowlabel {
2247f0e44acSEric Dumazet 	struct ip6_flowlabel __rcu *next;
22590bcaf7bSAl Viro 	__be32			label;
226db3459d1SEric Dumazet 	atomic_t		users;
2271da177e4SLinus Torvalds 	struct in6_addr		dst;
2281da177e4SLinus Torvalds 	struct ipv6_txoptions	*opt;
2291da177e4SLinus Torvalds 	unsigned long		linger;
230d3aedd5eSYOSHIFUJI Hideaki / 吉藤英明 	struct rcu_head		rcu;
2311da177e4SLinus Torvalds 	u8			share;
2324f82f457SEric W. Biederman 	union {
2334f82f457SEric W. Biederman 		struct pid *pid;
2344f82f457SEric W. Biederman 		kuid_t uid;
2354f82f457SEric W. Biederman 	} owner;
2361da177e4SLinus Torvalds 	unsigned long		lastuse;
2371da177e4SLinus Torvalds 	unsigned long		expires;
23860e8fbc4SBenjamin Thery 	struct net		*fl_net;
2391da177e4SLinus Torvalds };
2401da177e4SLinus Torvalds 
241f3a7c66bSHarvey Harrison #define IPV6_FLOWINFO_MASK		cpu_to_be32(0x0FFFFFFF)
242f3a7c66bSHarvey Harrison #define IPV6_FLOWLABEL_MASK		cpu_to_be32(0x000FFFFF)
24382a584b7STom Herbert #define IPV6_FLOWLABEL_STATELESS_FLAG	cpu_to_be32(0x00080000)
24482a584b7STom Herbert 
24537cfee90SFlorent Fourcot #define IPV6_TCLASS_MASK (IPV6_FLOWINFO_MASK & ~IPV6_FLOWLABEL_MASK)
246d76ed22bSLi RongQing #define IPV6_TCLASS_SHIFT	20
2471da177e4SLinus Torvalds 
248fd2c3ef7SEric Dumazet struct ipv6_fl_socklist {
2497f0e44acSEric Dumazet 	struct ipv6_fl_socklist	__rcu	*next;
2501da177e4SLinus Torvalds 	struct ip6_flowlabel		*fl;
25118367681SYOSHIFUJI Hideaki / 吉藤英明 	struct rcu_head			rcu;
2521da177e4SLinus Torvalds };
2531da177e4SLinus Torvalds 
25445f6fad8SEric Dumazet static inline struct ipv6_txoptions *txopt_get(const struct ipv6_pinfo *np)
25545f6fad8SEric Dumazet {
25645f6fad8SEric Dumazet 	struct ipv6_txoptions *opt;
25745f6fad8SEric Dumazet 
25845f6fad8SEric Dumazet 	rcu_read_lock();
25945f6fad8SEric Dumazet 	opt = rcu_dereference(np->opt);
260e550785cSBenjamin Poirier 	if (opt) {
261e550785cSBenjamin Poirier 		if (!atomic_inc_not_zero(&opt->refcnt))
26245f6fad8SEric Dumazet 			opt = NULL;
263e550785cSBenjamin Poirier 		else
264e550785cSBenjamin Poirier 			opt = rcu_pointer_handoff(opt);
265e550785cSBenjamin Poirier 	}
26645f6fad8SEric Dumazet 	rcu_read_unlock();
26745f6fad8SEric Dumazet 	return opt;
26845f6fad8SEric Dumazet }
26945f6fad8SEric Dumazet 
27045f6fad8SEric Dumazet static inline void txopt_put(struct ipv6_txoptions *opt)
27145f6fad8SEric Dumazet {
27245f6fad8SEric Dumazet 	if (opt && atomic_dec_and_test(&opt->refcnt))
27345f6fad8SEric Dumazet 		kfree_rcu(opt, rcu);
27445f6fad8SEric Dumazet }
27545f6fad8SEric Dumazet 
2765c3a0fd7SJoe Perches struct ip6_flowlabel *fl6_sock_lookup(struct sock *sk, __be32 label);
2775c3a0fd7SJoe Perches struct ipv6_txoptions *fl6_merge_options(struct ipv6_txoptions *opt_space,
2781da177e4SLinus Torvalds 					 struct ip6_flowlabel *fl,
2791da177e4SLinus Torvalds 					 struct ipv6_txoptions *fopt);
2805c3a0fd7SJoe Perches void fl6_free_socklist(struct sock *sk);
2815c3a0fd7SJoe Perches int ipv6_flowlabel_opt(struct sock *sk, char __user *optval, int optlen);
28246e5f401SFlorent Fourcot int ipv6_flowlabel_opt_get(struct sock *sk, struct in6_flowlabel_req *freq,
28346e5f401SFlorent Fourcot 			   int flags);
2845c3a0fd7SJoe Perches int ip6_flowlabel_init(void);
2855c3a0fd7SJoe Perches void ip6_flowlabel_cleanup(void);
2861da177e4SLinus Torvalds 
2871da177e4SLinus Torvalds static inline void fl6_sock_release(struct ip6_flowlabel *fl)
2881da177e4SLinus Torvalds {
2891da177e4SLinus Torvalds 	if (fl)
2901da177e4SLinus Torvalds 		atomic_dec(&fl->users);
2911da177e4SLinus Torvalds }
2921da177e4SLinus Torvalds 
2935c3a0fd7SJoe Perches void icmpv6_notify(struct sk_buff *skb, u8 type, u8 code, __be32 info);
294b94f1c09SDavid S. Miller 
2956d0bfe22SLorenzo Colitti int icmpv6_push_pending_frames(struct sock *sk, struct flowi6 *fl6,
2966d0bfe22SLorenzo Colitti 			       struct icmp6hdr *thdr, int len);
2976d0bfe22SLorenzo Colitti 
2985c3a0fd7SJoe Perches int ip6_ra_control(struct sock *sk, int sel);
2991da177e4SLinus Torvalds 
3005c3a0fd7SJoe Perches int ipv6_parse_hopopts(struct sk_buff *skb);
3011da177e4SLinus Torvalds 
3025c3a0fd7SJoe Perches struct ipv6_txoptions *ipv6_dup_options(struct sock *sk,
3035c3a0fd7SJoe Perches 					struct ipv6_txoptions *opt);
3045c3a0fd7SJoe Perches struct ipv6_txoptions *ipv6_renew_options(struct sock *sk,
3055c3a0fd7SJoe Perches 					  struct ipv6_txoptions *opt,
306333fad53SYOSHIFUJI Hideaki 					  int newtype,
307333fad53SYOSHIFUJI Hideaki 					  struct ipv6_opt_hdr __user *newopt,
308333fad53SYOSHIFUJI Hideaki 					  int newoptlen);
309df9890c3SYOSHIFUJI Hideaki struct ipv6_txoptions *ipv6_fixup_options(struct ipv6_txoptions *opt_space,
310df9890c3SYOSHIFUJI Hideaki 					  struct ipv6_txoptions *opt);
3111da177e4SLinus Torvalds 
312a224772dSEric Dumazet bool ipv6_opt_accepted(const struct sock *sk, const struct sk_buff *skb,
313a224772dSEric Dumazet 		       const struct inet6_skb_parm *opt);
314399c07deSArnaldo Carvalho de Melo 
315aeaf6e9dSShmulik Ladkani static inline bool ipv6_accept_ra(struct inet6_dev *idev)
316aeaf6e9dSShmulik Ladkani {
317aeaf6e9dSShmulik Ladkani 	/* If forwarding is enabled, RA are not accepted unless the special
318aeaf6e9dSShmulik Ladkani 	 * hybrid mode (accept_ra=2) is enabled.
319aeaf6e9dSShmulik Ladkani 	 */
320aeaf6e9dSShmulik Ladkani 	return idev->cnf.forwarding ? idev->cnf.accept_ra == 2 :
321aeaf6e9dSShmulik Ladkani 	    idev->cnf.accept_ra;
322aeaf6e9dSShmulik Ladkani }
323aeaf6e9dSShmulik Ladkani 
324d4915c08SAmerigo Wang #if IS_ENABLED(CONFIG_IPV6)
325d4915c08SAmerigo Wang static inline int ip6_frag_mem(struct net *net)
326d4915c08SAmerigo Wang {
327d433673eSJesper Dangaard Brouer 	return sum_frag_mem_limit(&net->ipv6.frags);
328d4915c08SAmerigo Wang }
329d4915c08SAmerigo Wang #endif
3301da177e4SLinus Torvalds 
331c2a93660SJesper Dangaard Brouer #define IPV6_FRAG_HIGH_THRESH	(4 * 1024*1024)	/* 4194304 */
332c2a93660SJesper Dangaard Brouer #define IPV6_FRAG_LOW_THRESH	(3 * 1024*1024)	/* 3145728 */
3331da177e4SLinus Torvalds #define IPV6_FRAG_TIMEOUT	(60 * HZ)	/* 60 seconds */
3341da177e4SLinus Torvalds 
3355c3a0fd7SJoe Perches int __ipv6_addr_type(const struct in6_addr *addr);
336b1cacb68SYOSHIFUJI Hideaki static inline int ipv6_addr_type(const struct in6_addr *addr)
337b1cacb68SYOSHIFUJI Hideaki {
338b1cacb68SYOSHIFUJI Hideaki 	return __ipv6_addr_type(addr) & 0xffff;
339b1cacb68SYOSHIFUJI Hideaki }
3401da177e4SLinus Torvalds 
3411da177e4SLinus Torvalds static inline int ipv6_addr_scope(const struct in6_addr *addr)
3421da177e4SLinus Torvalds {
343b1cacb68SYOSHIFUJI Hideaki 	return __ipv6_addr_type(addr) & IPV6_ADDR_SCOPE_MASK;
344b1cacb68SYOSHIFUJI Hideaki }
345b1cacb68SYOSHIFUJI Hideaki 
346b1cacb68SYOSHIFUJI Hideaki static inline int __ipv6_addr_src_scope(int type)
347b1cacb68SYOSHIFUJI Hideaki {
348a02cec21SEric Dumazet 	return (type == IPV6_ADDR_ANY) ? __IPV6_ADDR_SCOPE_INVALID : (type >> 16);
349b1cacb68SYOSHIFUJI Hideaki }
350b1cacb68SYOSHIFUJI Hideaki 
351b1cacb68SYOSHIFUJI Hideaki static inline int ipv6_addr_src_scope(const struct in6_addr *addr)
352b1cacb68SYOSHIFUJI Hideaki {
353b1cacb68SYOSHIFUJI Hideaki 	return __ipv6_addr_src_scope(__ipv6_addr_type(addr));
3541da177e4SLinus Torvalds }
3551da177e4SLinus Torvalds 
356b7ef213eSHannes Frederic Sowa static inline bool __ipv6_addr_needs_scope_id(int type)
357b7ef213eSHannes Frederic Sowa {
358b7ef213eSHannes Frederic Sowa 	return type & IPV6_ADDR_LINKLOCAL ||
359b7ef213eSHannes Frederic Sowa 	       (type & IPV6_ADDR_MULTICAST &&
360b7ef213eSHannes Frederic Sowa 		(type & (IPV6_ADDR_LOOPBACK|IPV6_ADDR_LINKLOCAL)));
361b7ef213eSHannes Frederic Sowa }
362b7ef213eSHannes Frederic Sowa 
363b7ef213eSHannes Frederic Sowa static inline __u32 ipv6_iface_scope_id(const struct in6_addr *addr, int iface)
364b7ef213eSHannes Frederic Sowa {
365b7ef213eSHannes Frederic Sowa 	return __ipv6_addr_needs_scope_id(__ipv6_addr_type(addr)) ? iface : 0;
366b7ef213eSHannes Frederic Sowa }
367b7ef213eSHannes Frederic Sowa 
3681da177e4SLinus Torvalds static inline int ipv6_addr_cmp(const struct in6_addr *a1, const struct in6_addr *a2)
3691da177e4SLinus Torvalds {
370db3459d1SEric Dumazet 	return memcmp(a1, a2, sizeof(struct in6_addr));
3711da177e4SLinus Torvalds }
3721da177e4SLinus Torvalds 
3731a203cb3SEric Dumazet static inline bool
374f2ffd9eeSPatrick McHardy ipv6_masked_addr_cmp(const struct in6_addr *a1, const struct in6_addr *m,
375f2ffd9eeSPatrick McHardy 		     const struct in6_addr *a2)
376f2ffd9eeSPatrick McHardy {
3771a203cb3SEric Dumazet #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
3781a203cb3SEric Dumazet 	const unsigned long *ul1 = (const unsigned long *)a1;
3791a203cb3SEric Dumazet 	const unsigned long *ulm = (const unsigned long *)m;
3801a203cb3SEric Dumazet 	const unsigned long *ul2 = (const unsigned long *)a2;
3811a203cb3SEric Dumazet 
3821a203cb3SEric Dumazet 	return !!(((ul1[0] ^ ul2[0]) & ulm[0]) |
3831a203cb3SEric Dumazet 		  ((ul1[1] ^ ul2[1]) & ulm[1]));
3841a203cb3SEric Dumazet #else
385a02cec21SEric Dumazet 	return !!(((a1->s6_addr32[0] ^ a2->s6_addr32[0]) & m->s6_addr32[0]) |
386fed85383SYOSHIFUJI Hideaki 		  ((a1->s6_addr32[1] ^ a2->s6_addr32[1]) & m->s6_addr32[1]) |
387fed85383SYOSHIFUJI Hideaki 		  ((a1->s6_addr32[2] ^ a2->s6_addr32[2]) & m->s6_addr32[2]) |
388a02cec21SEric Dumazet 		  ((a1->s6_addr32[3] ^ a2->s6_addr32[3]) & m->s6_addr32[3]));
3891a203cb3SEric Dumazet #endif
390f2ffd9eeSPatrick McHardy }
391f2ffd9eeSPatrick McHardy 
3921da177e4SLinus Torvalds static inline void ipv6_addr_prefix(struct in6_addr *pfx,
3931da177e4SLinus Torvalds 				    const struct in6_addr *addr,
3941da177e4SLinus Torvalds 				    int plen)
3951da177e4SLinus Torvalds {
3961da177e4SLinus Torvalds 	/* caller must guarantee 0 <= plen <= 128 */
3971da177e4SLinus Torvalds 	int o = plen >> 3,
3981da177e4SLinus Torvalds 	    b = plen & 0x7;
3991da177e4SLinus Torvalds 
400db3459d1SEric Dumazet 	memset(pfx->s6_addr, 0, sizeof(pfx->s6_addr));
4011da177e4SLinus Torvalds 	memcpy(pfx->s6_addr, addr, o);
402db3459d1SEric Dumazet 	if (b != 0)
4031da177e4SLinus Torvalds 		pfx->s6_addr[o] = addr->s6_addr[o] & (0xff00 >> b);
4041da177e4SLinus Torvalds }
4051da177e4SLinus Torvalds 
406818f1f3eSAlexander Aring static inline void ipv6_addr_prefix_copy(struct in6_addr *addr,
407818f1f3eSAlexander Aring 					 const struct in6_addr *pfx,
408818f1f3eSAlexander Aring 					 int plen)
409818f1f3eSAlexander Aring {
410818f1f3eSAlexander Aring 	/* caller must guarantee 0 <= plen <= 128 */
411818f1f3eSAlexander Aring 	int o = plen >> 3,
412818f1f3eSAlexander Aring 	    b = plen & 0x7;
413818f1f3eSAlexander Aring 
414818f1f3eSAlexander Aring 	memcpy(addr->s6_addr, pfx, o);
415818f1f3eSAlexander Aring 	if (b != 0) {
416818f1f3eSAlexander Aring 		addr->s6_addr[o] &= ~(0xff00 >> b);
417818f1f3eSAlexander Aring 		addr->s6_addr[o] |= (pfx->s6_addr[o] & (0xff00 >> b));
418818f1f3eSAlexander Aring 	}
419818f1f3eSAlexander Aring }
420818f1f3eSAlexander Aring 
4215206c579SYOSHIFUJI Hideaki / 吉藤英明 static inline void __ipv6_addr_set_half(__be32 *addr,
4225206c579SYOSHIFUJI Hideaki / 吉藤英明 					__be32 wh, __be32 wl)
4235206c579SYOSHIFUJI Hideaki / 吉藤英明 {
4245206c579SYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
4255206c579SYOSHIFUJI Hideaki / 吉藤英明 #if defined(__BIG_ENDIAN)
4265206c579SYOSHIFUJI Hideaki / 吉藤英明 	if (__builtin_constant_p(wh) && __builtin_constant_p(wl)) {
4275206c579SYOSHIFUJI Hideaki / 吉藤英明 		*(__force u64 *)addr = ((__force u64)(wh) << 32 | (__force u64)(wl));
4285206c579SYOSHIFUJI Hideaki / 吉藤英明 		return;
4295206c579SYOSHIFUJI Hideaki / 吉藤英明 	}
4305206c579SYOSHIFUJI Hideaki / 吉藤英明 #elif defined(__LITTLE_ENDIAN)
4315206c579SYOSHIFUJI Hideaki / 吉藤英明 	if (__builtin_constant_p(wl) && __builtin_constant_p(wh)) {
4325206c579SYOSHIFUJI Hideaki / 吉藤英明 		*(__force u64 *)addr = ((__force u64)(wl) << 32 | (__force u64)(wh));
4335206c579SYOSHIFUJI Hideaki / 吉藤英明 		return;
4345206c579SYOSHIFUJI Hideaki / 吉藤英明 	}
4355206c579SYOSHIFUJI Hideaki / 吉藤英明 #endif
4365206c579SYOSHIFUJI Hideaki / 吉藤英明 #endif
4375206c579SYOSHIFUJI Hideaki / 吉藤英明 	addr[0] = wh;
4385206c579SYOSHIFUJI Hideaki / 吉藤英明 	addr[1] = wl;
4395206c579SYOSHIFUJI Hideaki / 吉藤英明 }
4405206c579SYOSHIFUJI Hideaki / 吉藤英明 
4411da177e4SLinus Torvalds static inline void ipv6_addr_set(struct in6_addr *addr,
44248818f82SAl Viro 				     __be32 w1, __be32 w2,
44348818f82SAl Viro 				     __be32 w3, __be32 w4)
4441da177e4SLinus Torvalds {
4455206c579SYOSHIFUJI Hideaki / 吉藤英明 	__ipv6_addr_set_half(&addr->s6_addr32[0], w1, w2);
4465206c579SYOSHIFUJI Hideaki / 吉藤英明 	__ipv6_addr_set_half(&addr->s6_addr32[2], w3, w4);
4471da177e4SLinus Torvalds }
4481da177e4SLinus Torvalds 
44992113bfdSEric Dumazet static inline bool ipv6_addr_equal(const struct in6_addr *a1,
4501da177e4SLinus Torvalds 				   const struct in6_addr *a2)
4511da177e4SLinus Torvalds {
4521a203cb3SEric Dumazet #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
4531a203cb3SEric Dumazet 	const unsigned long *ul1 = (const unsigned long *)a1;
4541a203cb3SEric Dumazet 	const unsigned long *ul2 = (const unsigned long *)a2;
4551a203cb3SEric Dumazet 
4561a203cb3SEric Dumazet 	return ((ul1[0] ^ ul2[0]) | (ul1[1] ^ ul2[1])) == 0UL;
4571a203cb3SEric Dumazet #else
458a02cec21SEric Dumazet 	return ((a1->s6_addr32[0] ^ a2->s6_addr32[0]) |
459fed85383SYOSHIFUJI Hideaki 		(a1->s6_addr32[1] ^ a2->s6_addr32[1]) |
460fed85383SYOSHIFUJI Hideaki 		(a1->s6_addr32[2] ^ a2->s6_addr32[2]) |
461a02cec21SEric Dumazet 		(a1->s6_addr32[3] ^ a2->s6_addr32[3])) == 0;
4621a203cb3SEric Dumazet #endif
4631da177e4SLinus Torvalds }
4641da177e4SLinus Torvalds 
46538675170SYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
46638675170SYOSHIFUJI Hideaki / 吉藤英明 static inline bool __ipv6_prefix_equal64_half(const __be64 *a1,
46738675170SYOSHIFUJI Hideaki / 吉藤英明 					      const __be64 *a2,
46838675170SYOSHIFUJI Hideaki / 吉藤英明 					      unsigned int len)
46938675170SYOSHIFUJI Hideaki / 吉藤英明 {
470512613d7SFabio Baltieri 	if (len && ((*a1 ^ *a2) & cpu_to_be64((~0UL) << (64 - len))))
47138675170SYOSHIFUJI Hideaki / 吉藤英明 		return false;
47238675170SYOSHIFUJI Hideaki / 吉藤英明 	return true;
47338675170SYOSHIFUJI Hideaki / 吉藤英明 }
47438675170SYOSHIFUJI Hideaki / 吉藤英明 
47538675170SYOSHIFUJI Hideaki / 吉藤英明 static inline bool ipv6_prefix_equal(const struct in6_addr *addr1,
47638675170SYOSHIFUJI Hideaki / 吉藤英明 				     const struct in6_addr *addr2,
47738675170SYOSHIFUJI Hideaki / 吉藤英明 				     unsigned int prefixlen)
47838675170SYOSHIFUJI Hideaki / 吉藤英明 {
47938675170SYOSHIFUJI Hideaki / 吉藤英明 	const __be64 *a1 = (const __be64 *)addr1;
48038675170SYOSHIFUJI Hideaki / 吉藤英明 	const __be64 *a2 = (const __be64 *)addr2;
48138675170SYOSHIFUJI Hideaki / 吉藤英明 
48238675170SYOSHIFUJI Hideaki / 吉藤英明 	if (prefixlen >= 64) {
48338675170SYOSHIFUJI Hideaki / 吉藤英明 		if (a1[0] ^ a2[0])
48438675170SYOSHIFUJI Hideaki / 吉藤英明 			return false;
48538675170SYOSHIFUJI Hideaki / 吉藤英明 		return __ipv6_prefix_equal64_half(a1 + 1, a2 + 1, prefixlen - 64);
48638675170SYOSHIFUJI Hideaki / 吉藤英明 	}
48738675170SYOSHIFUJI Hideaki / 吉藤英明 	return __ipv6_prefix_equal64_half(a1, a2, prefixlen);
48838675170SYOSHIFUJI Hideaki / 吉藤英明 }
48938675170SYOSHIFUJI Hideaki / 吉藤英明 #else
4902ef97332SYOSHIFUJI Hideaki / 吉藤英明 static inline bool ipv6_prefix_equal(const struct in6_addr *addr1,
4912ef97332SYOSHIFUJI Hideaki / 吉藤英明 				     const struct in6_addr *addr2,
4921da177e4SLinus Torvalds 				     unsigned int prefixlen)
4931da177e4SLinus Torvalds {
4942ef97332SYOSHIFUJI Hideaki / 吉藤英明 	const __be32 *a1 = addr1->s6_addr32;
4952ef97332SYOSHIFUJI Hideaki / 吉藤英明 	const __be32 *a2 = addr2->s6_addr32;
49695c96174SEric Dumazet 	unsigned int pdw, pbi;
4971da177e4SLinus Torvalds 
4981da177e4SLinus Torvalds 	/* check complete u32 in prefix */
4991da177e4SLinus Torvalds 	pdw = prefixlen >> 5;
5001da177e4SLinus Torvalds 	if (pdw && memcmp(a1, a2, pdw << 2))
50192113bfdSEric Dumazet 		return false;
5021da177e4SLinus Torvalds 
5031da177e4SLinus Torvalds 	/* check incomplete u32 in prefix */
5041da177e4SLinus Torvalds 	pbi = prefixlen & 0x1f;
5051da177e4SLinus Torvalds 	if (pbi && ((a1[pdw] ^ a2[pdw]) & htonl((0xffffffff) << (32 - pbi))))
50692113bfdSEric Dumazet 		return false;
5071da177e4SLinus Torvalds 
50892113bfdSEric Dumazet 	return true;
5091da177e4SLinus Torvalds }
51038675170SYOSHIFUJI Hideaki / 吉藤英明 #endif
5111da177e4SLinus Torvalds 
5122588fe1dSPavel Emelyanov struct inet_frag_queue;
5132588fe1dSPavel Emelyanov 
5140b5ccb2eSPatrick McHardy enum ip6_defrag_users {
5150b5ccb2eSPatrick McHardy 	IP6_DEFRAG_LOCAL_DELIVER,
5160b5ccb2eSPatrick McHardy 	IP6_DEFRAG_CONNTRACK_IN,
5174be929beSAlexey Dobriyan 	__IP6_DEFRAG_CONNTRACK_IN	= IP6_DEFRAG_CONNTRACK_IN + USHRT_MAX,
5180b5ccb2eSPatrick McHardy 	IP6_DEFRAG_CONNTRACK_OUT,
5194be929beSAlexey Dobriyan 	__IP6_DEFRAG_CONNTRACK_OUT	= IP6_DEFRAG_CONNTRACK_OUT + USHRT_MAX,
5208fa9ff68SPatrick McHardy 	IP6_DEFRAG_CONNTRACK_BRIDGE_IN,
5214be929beSAlexey Dobriyan 	__IP6_DEFRAG_CONNTRACK_BRIDGE_IN = IP6_DEFRAG_CONNTRACK_BRIDGE_IN + USHRT_MAX,
5220b5ccb2eSPatrick McHardy };
5230b5ccb2eSPatrick McHardy 
524c6fda282SPavel Emelyanov struct ip6_create_arg {
525c6fda282SPavel Emelyanov 	__be32 id;
5260b5ccb2eSPatrick McHardy 	u32 user;
527b71d1d42SEric Dumazet 	const struct in6_addr *src;
528b71d1d42SEric Dumazet 	const struct in6_addr *dst;
529264640fcSMichal Kubeček 	int iif;
530eec2e618SHannes Frederic Sowa 	u8 ecn;
531c6fda282SPavel Emelyanov };
532c6fda282SPavel Emelyanov 
53336c77782SFlorian Westphal void ip6_frag_init(struct inet_frag_queue *q, const void *a);
53436c77782SFlorian Westphal bool ip6_frag_match(const struct inet_frag_queue *q, const void *a);
535c6fda282SPavel Emelyanov 
536b836c99fSAmerigo Wang /*
537b836c99fSAmerigo Wang  *	Equivalent of ipv4 struct ip
538b836c99fSAmerigo Wang  */
539b836c99fSAmerigo Wang struct frag_queue {
540b836c99fSAmerigo Wang 	struct inet_frag_queue	q;
541b836c99fSAmerigo Wang 
542b836c99fSAmerigo Wang 	__be32			id;		/* fragment id		*/
543b836c99fSAmerigo Wang 	u32			user;
544b836c99fSAmerigo Wang 	struct in6_addr		saddr;
545b836c99fSAmerigo Wang 	struct in6_addr		daddr;
546b836c99fSAmerigo Wang 
547b836c99fSAmerigo Wang 	int			iif;
548b836c99fSAmerigo Wang 	unsigned int		csum;
549b836c99fSAmerigo Wang 	__u16			nhoffset;
550eec2e618SHannes Frederic Sowa 	u8			ecn;
551b836c99fSAmerigo Wang };
552b836c99fSAmerigo Wang 
553b836c99fSAmerigo Wang void ip6_expire_frag_queue(struct net *net, struct frag_queue *fq,
554b836c99fSAmerigo Wang 			   struct inet_frags *frags);
555b836c99fSAmerigo Wang 
55692113bfdSEric Dumazet static inline bool ipv6_addr_any(const struct in6_addr *a)
5571da177e4SLinus Torvalds {
5581a203cb3SEric Dumazet #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
5591a203cb3SEric Dumazet 	const unsigned long *ul = (const unsigned long *)a;
5601a203cb3SEric Dumazet 
5611a203cb3SEric Dumazet 	return (ul[0] | ul[1]) == 0UL;
5621a203cb3SEric Dumazet #else
563a02cec21SEric Dumazet 	return (a->s6_addr32[0] | a->s6_addr32[1] |
564a02cec21SEric Dumazet 		a->s6_addr32[2] | a->s6_addr32[3]) == 0;
5651a203cb3SEric Dumazet #endif
5661da177e4SLinus Torvalds }
5671da177e4SLinus Torvalds 
568ddbe5032SEric Dumazet static inline u32 ipv6_addr_hash(const struct in6_addr *a)
569ddbe5032SEric Dumazet {
570ddbe5032SEric Dumazet #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
571ddbe5032SEric Dumazet 	const unsigned long *ul = (const unsigned long *)a;
572ddbe5032SEric Dumazet 	unsigned long x = ul[0] ^ ul[1];
573ddbe5032SEric Dumazet 
574ddbe5032SEric Dumazet 	return (u32)(x ^ (x >> 32));
575ddbe5032SEric Dumazet #else
576ddbe5032SEric Dumazet 	return (__force u32)(a->s6_addr32[0] ^ a->s6_addr32[1] ^
577ddbe5032SEric Dumazet 			     a->s6_addr32[2] ^ a->s6_addr32[3]);
578ddbe5032SEric Dumazet #endif
579ddbe5032SEric Dumazet }
580ddbe5032SEric Dumazet 
58108dcdbf6SEric Dumazet /* more secured version of ipv6_addr_hash() */
582b50026b5SHannes Frederic Sowa static inline u32 __ipv6_addr_jhash(const struct in6_addr *a, const u32 initval)
58308dcdbf6SEric Dumazet {
58408dcdbf6SEric Dumazet 	u32 v = (__force u32)a->s6_addr32[0] ^ (__force u32)a->s6_addr32[1];
58508dcdbf6SEric Dumazet 
58608dcdbf6SEric Dumazet 	return jhash_3words(v,
58708dcdbf6SEric Dumazet 			    (__force u32)a->s6_addr32[2],
58808dcdbf6SEric Dumazet 			    (__force u32)a->s6_addr32[3],
589b50026b5SHannes Frederic Sowa 			    initval);
59008dcdbf6SEric Dumazet }
59108dcdbf6SEric Dumazet 
59292113bfdSEric Dumazet static inline bool ipv6_addr_loopback(const struct in6_addr *a)
593f630e43aSYOSHIFUJI Hideaki {
594e287656bSYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
5951373a773SJeff Layton 	const __be64 *be = (const __be64 *)a;
596e287656bSYOSHIFUJI Hideaki / 吉藤英明 
5971373a773SJeff Layton 	return (be[0] | (be[1] ^ cpu_to_be64(1))) == 0UL;
598e287656bSYOSHIFUJI Hideaki / 吉藤英明 #else
599a02cec21SEric Dumazet 	return (a->s6_addr32[0] | a->s6_addr32[1] |
6001373a773SJeff Layton 		a->s6_addr32[2] | (a->s6_addr32[3] ^ cpu_to_be32(1))) == 0;
601e287656bSYOSHIFUJI Hideaki / 吉藤英明 #endif
602f630e43aSYOSHIFUJI Hideaki }
603f630e43aSYOSHIFUJI Hideaki 
6041373a773SJeff Layton /*
6051373a773SJeff Layton  * Note that we must __force cast these to unsigned long to make sparse happy,
6061373a773SJeff Layton  * since all of the endian-annotated types are fixed size regardless of arch.
6071373a773SJeff Layton  */
60892113bfdSEric Dumazet static inline bool ipv6_addr_v4mapped(const struct in6_addr *a)
609e773e4faSBrian Haley {
610a04d40b8SYOSHIFUJI Hideaki / 吉藤英明 	return (
611a04d40b8SYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
6121373a773SJeff Layton 		*(unsigned long *)a |
613a04d40b8SYOSHIFUJI Hideaki / 吉藤英明 #else
6141373a773SJeff Layton 		(__force unsigned long)(a->s6_addr32[0] | a->s6_addr32[1]) |
615a04d40b8SYOSHIFUJI Hideaki / 吉藤英明 #endif
6161373a773SJeff Layton 		(__force unsigned long)(a->s6_addr32[2] ^
6171373a773SJeff Layton 					cpu_to_be32(0x0000ffff))) == 0UL;
618e773e4faSBrian Haley }
619e773e4faSBrian Haley 
6201da177e4SLinus Torvalds /*
62199cd07a5SJuha-Matti Tapio  * Check for a RFC 4843 ORCHID address
62299cd07a5SJuha-Matti Tapio  * (Overlay Routable Cryptographic Hash Identifiers)
62399cd07a5SJuha-Matti Tapio  */
62492113bfdSEric Dumazet static inline bool ipv6_addr_orchid(const struct in6_addr *a)
62599cd07a5SJuha-Matti Tapio {
626a02cec21SEric Dumazet 	return (a->s6_addr32[0] & htonl(0xfffffff0)) == htonl(0x20010010);
62799cd07a5SJuha-Matti Tapio }
62899cd07a5SJuha-Matti Tapio 
6295c98631cSLorenzo Colitti static inline bool ipv6_addr_is_multicast(const struct in6_addr *addr)
6305c98631cSLorenzo Colitti {
6315c98631cSLorenzo Colitti 	return (addr->s6_addr32[0] & htonl(0xFF000000)) == htonl(0xFF000000);
6325c98631cSLorenzo Colitti }
6335c98631cSLorenzo Colitti 
634f15364bdSAurélien Charbon static inline void ipv6_addr_set_v4mapped(const __be32 addr,
635f15364bdSAurélien Charbon 					  struct in6_addr *v4mapped)
636f15364bdSAurélien Charbon {
637f15364bdSAurélien Charbon 	ipv6_addr_set(v4mapped,
638f15364bdSAurélien Charbon 			0, 0,
639f15364bdSAurélien Charbon 			htonl(0x0000FFFF),
640f15364bdSAurélien Charbon 			addr);
641f15364bdSAurélien Charbon }
642f15364bdSAurélien Charbon 
64399cd07a5SJuha-Matti Tapio /*
644971f359dSYOSHIFUJI Hideaki  * find the first different bit between two addresses
645971f359dSYOSHIFUJI Hideaki  * length of address must be a multiple of 32bits
646971f359dSYOSHIFUJI Hideaki  */
6479f2e7334SYOSHIFUJI Hideaki / 吉藤英明 static inline int __ipv6_addr_diff32(const void *token1, const void *token2, int addrlen)
648971f359dSYOSHIFUJI Hideaki {
649ef296f56SAl Viro 	const __be32 *a1 = token1, *a2 = token2;
650971f359dSYOSHIFUJI Hideaki 	int i;
651971f359dSYOSHIFUJI Hideaki 
652971f359dSYOSHIFUJI Hideaki 	addrlen >>= 2;
653971f359dSYOSHIFUJI Hideaki 
654971f359dSYOSHIFUJI Hideaki 	for (i = 0; i < addrlen; i++) {
655ef296f56SAl Viro 		__be32 xb = a1[i] ^ a2[i];
656ef296f56SAl Viro 		if (xb)
657d57b8fb8SYOSHIFUJI Hideaki / 吉藤英明 			return i * 32 + 31 - __fls(ntohl(xb));
658971f359dSYOSHIFUJI Hideaki 	}
659971f359dSYOSHIFUJI Hideaki 
660971f359dSYOSHIFUJI Hideaki 	/*
661971f359dSYOSHIFUJI Hideaki 	 *	we should *never* get to this point since that
662971f359dSYOSHIFUJI Hideaki 	 *	would mean the addrs are equal
663971f359dSYOSHIFUJI Hideaki 	 *
664971f359dSYOSHIFUJI Hideaki 	 *	However, we do get to it 8) And exacly, when
665971f359dSYOSHIFUJI Hideaki 	 *	addresses are equal 8)
666971f359dSYOSHIFUJI Hideaki 	 *
667971f359dSYOSHIFUJI Hideaki 	 *	ip route add 1111::/128 via ...
668971f359dSYOSHIFUJI Hideaki 	 *	ip route add 1111::/64 via ...
669971f359dSYOSHIFUJI Hideaki 	 *	and we are here.
670971f359dSYOSHIFUJI Hideaki 	 *
671971f359dSYOSHIFUJI Hideaki 	 *	Ideally, this function should stop comparison
672971f359dSYOSHIFUJI Hideaki 	 *	at prefix length. It does not, but it is still OK,
673971f359dSYOSHIFUJI Hideaki 	 *	if returned value is greater than prefix length.
674971f359dSYOSHIFUJI Hideaki 	 *					--ANK (980803)
675971f359dSYOSHIFUJI Hideaki 	 */
676a02cec21SEric Dumazet 	return addrlen << 5;
677971f359dSYOSHIFUJI Hideaki }
678971f359dSYOSHIFUJI Hideaki 
6799f2e7334SYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
6809f2e7334SYOSHIFUJI Hideaki / 吉藤英明 static inline int __ipv6_addr_diff64(const void *token1, const void *token2, int addrlen)
6819f2e7334SYOSHIFUJI Hideaki / 吉藤英明 {
6829f2e7334SYOSHIFUJI Hideaki / 吉藤英明 	const __be64 *a1 = token1, *a2 = token2;
6839f2e7334SYOSHIFUJI Hideaki / 吉藤英明 	int i;
6849f2e7334SYOSHIFUJI Hideaki / 吉藤英明 
6859f2e7334SYOSHIFUJI Hideaki / 吉藤英明 	addrlen >>= 3;
6869f2e7334SYOSHIFUJI Hideaki / 吉藤英明 
6879f2e7334SYOSHIFUJI Hideaki / 吉藤英明 	for (i = 0; i < addrlen; i++) {
6889f2e7334SYOSHIFUJI Hideaki / 吉藤英明 		__be64 xb = a1[i] ^ a2[i];
6899f2e7334SYOSHIFUJI Hideaki / 吉藤英明 		if (xb)
6909f2e7334SYOSHIFUJI Hideaki / 吉藤英明 			return i * 64 + 63 - __fls(be64_to_cpu(xb));
6919f2e7334SYOSHIFUJI Hideaki / 吉藤英明 	}
6929f2e7334SYOSHIFUJI Hideaki / 吉藤英明 
6939f2e7334SYOSHIFUJI Hideaki / 吉藤英明 	return addrlen << 6;
6949f2e7334SYOSHIFUJI Hideaki / 吉藤英明 }
6959f2e7334SYOSHIFUJI Hideaki / 吉藤英明 #endif
6969f2e7334SYOSHIFUJI Hideaki / 吉藤英明 
6979f2e7334SYOSHIFUJI Hideaki / 吉藤英明 static inline int __ipv6_addr_diff(const void *token1, const void *token2, int addrlen)
6989f2e7334SYOSHIFUJI Hideaki / 吉藤英明 {
6999f2e7334SYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
7009f2e7334SYOSHIFUJI Hideaki / 吉藤英明 	if (__builtin_constant_p(addrlen) && !(addrlen & 7))
7019f2e7334SYOSHIFUJI Hideaki / 吉藤英明 		return __ipv6_addr_diff64(token1, token2, addrlen);
7029f2e7334SYOSHIFUJI Hideaki / 吉藤英明 #endif
7039f2e7334SYOSHIFUJI Hideaki / 吉藤英明 	return __ipv6_addr_diff32(token1, token2, addrlen);
7049f2e7334SYOSHIFUJI Hideaki / 吉藤英明 }
7059f2e7334SYOSHIFUJI Hideaki / 吉藤英明 
706971f359dSYOSHIFUJI Hideaki static inline int ipv6_addr_diff(const struct in6_addr *a1, const struct in6_addr *a2)
707971f359dSYOSHIFUJI Hideaki {
708971f359dSYOSHIFUJI Hideaki 	return __ipv6_addr_diff(a1, a2, sizeof(struct in6_addr));
709971f359dSYOSHIFUJI Hideaki }
710971f359dSYOSHIFUJI Hideaki 
7117f159867SEric Dumazet __be32 ipv6_select_ident(struct net *net,
712fd0273d7SMartin KaFai Lau 			 const struct in6_addr *daddr,
713fd0273d7SMartin KaFai Lau 			 const struct in6_addr *saddr);
7145a352dd0SHannes Frederic Sowa void ipv6_proxy_select_ident(struct net *net, struct sk_buff *skb);
7155188cd44SBen Hutchings 
7165c3a0fd7SJoe Perches int ip6_dst_hoplimit(struct dst_entry *dst);
7173ce9b35fSCong Wang 
7185c98631cSLorenzo Colitti static inline int ip6_sk_dst_hoplimit(struct ipv6_pinfo *np, struct flowi6 *fl6,
7195c98631cSLorenzo Colitti 				      struct dst_entry *dst)
7205c98631cSLorenzo Colitti {
7215c98631cSLorenzo Colitti 	int hlimit;
7225c98631cSLorenzo Colitti 
7235c98631cSLorenzo Colitti 	if (ipv6_addr_is_multicast(&fl6->daddr))
7245c98631cSLorenzo Colitti 		hlimit = np->mcast_hops;
7255c98631cSLorenzo Colitti 	else
7265c98631cSLorenzo Colitti 		hlimit = np->hop_limit;
7275c98631cSLorenzo Colitti 	if (hlimit < 0)
7285c98631cSLorenzo Colitti 		hlimit = ip6_dst_hoplimit(dst);
7295c98631cSLorenzo Colitti 	return hlimit;
7305c98631cSLorenzo Colitti }
7315c98631cSLorenzo Colitti 
732c3f83241STom Herbert /* copy IPv6 saddr & daddr to flow_keys, possibly using 64bit load/store
733c3f83241STom Herbert  * Equivalent to :	flow->v6addrs.src = iph->saddr;
734c3f83241STom Herbert  *			flow->v6addrs.dst = iph->daddr;
735c3f83241STom Herbert  */
736c3f83241STom Herbert static inline void iph_to_flow_copy_v6addrs(struct flow_keys *flow,
737c3f83241STom Herbert 					    const struct ipv6hdr *iph)
738c3f83241STom Herbert {
739c3f83241STom Herbert 	BUILD_BUG_ON(offsetof(typeof(flow->addrs), v6addrs.dst) !=
740c3f83241STom Herbert 		     offsetof(typeof(flow->addrs), v6addrs.src) +
741c3f83241STom Herbert 		     sizeof(flow->addrs.v6addrs.src));
742c3f83241STom Herbert 	memcpy(&flow->addrs.v6addrs, &iph->saddr, sizeof(flow->addrs.v6addrs));
743c3f83241STom Herbert 	flow->control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
744c3f83241STom Herbert }
745c3f83241STom Herbert 
746a37934fcSFlorian Fainelli #if IS_ENABLED(CONFIG_IPV6)
74742240901STom Herbert 
74842240901STom Herbert /* Sysctl settings for net ipv6.auto_flowlabels */
74942240901STom Herbert #define IP6_AUTO_FLOW_LABEL_OFF		0
75042240901STom Herbert #define IP6_AUTO_FLOW_LABEL_OPTOUT	1
75142240901STom Herbert #define IP6_AUTO_FLOW_LABEL_OPTIN	2
75242240901STom Herbert #define IP6_AUTO_FLOW_LABEL_FORCED	3
75342240901STom Herbert 
75442240901STom Herbert #define IP6_AUTO_FLOW_LABEL_MAX		IP6_AUTO_FLOW_LABEL_FORCED
75542240901STom Herbert 
756b5677416STom Herbert #define IP6_DEFAULT_AUTO_FLOW_LABELS	IP6_AUTO_FLOW_LABEL_OPTOUT
75742240901STom Herbert 
758cb1ce2efSTom Herbert static inline __be32 ip6_make_flowlabel(struct net *net, struct sk_buff *skb,
75967800f9bSTom Herbert 					__be32 flowlabel, bool autolabel,
76067800f9bSTom Herbert 					struct flowi6 *fl6)
761cb1ce2efSTom Herbert {
76267765146SEric Dumazet 	u32 hash;
763cb1ce2efSTom Herbert 
76442240901STom Herbert 	if (flowlabel ||
76542240901STom Herbert 	    net->ipv6.sysctl.auto_flowlabels == IP6_AUTO_FLOW_LABEL_OFF ||
76642240901STom Herbert 	    (!autolabel &&
76742240901STom Herbert 	     net->ipv6.sysctl.auto_flowlabels != IP6_AUTO_FLOW_LABEL_FORCED))
76842240901STom Herbert 		return flowlabel;
76942240901STom Herbert 
77067800f9bSTom Herbert 	hash = skb_get_hash_flowi6(skb, fl6);
771cb1ce2efSTom Herbert 
772cb1ce2efSTom Herbert 	/* Since this is being sent on the wire obfuscate hash a bit
773cb1ce2efSTom Herbert 	 * to minimize possbility that any useful information to an
774cb1ce2efSTom Herbert 	 * attacker is leaked. Only lower 20 bits are relevant.
775cb1ce2efSTom Herbert 	 */
77642240901STom Herbert 	rol32(hash, 16);
777cb1ce2efSTom Herbert 
77867765146SEric Dumazet 	flowlabel = (__force __be32)hash & IPV6_FLOWLABEL_MASK;
77982a584b7STom Herbert 
78082a584b7STom Herbert 	if (net->ipv6.sysctl.flowlabel_state_ranges)
78182a584b7STom Herbert 		flowlabel |= IPV6_FLOWLABEL_STATELESS_FLAG;
782cb1ce2efSTom Herbert 
783cb1ce2efSTom Herbert 	return flowlabel;
784cb1ce2efSTom Herbert }
78542240901STom Herbert 
78642240901STom Herbert static inline int ip6_default_np_autolabel(struct net *net)
78742240901STom Herbert {
78842240901STom Herbert 	switch (net->ipv6.sysctl.auto_flowlabels) {
78942240901STom Herbert 	case IP6_AUTO_FLOW_LABEL_OFF:
79042240901STom Herbert 	case IP6_AUTO_FLOW_LABEL_OPTIN:
79142240901STom Herbert 	default:
79242240901STom Herbert 		return 0;
79342240901STom Herbert 	case IP6_AUTO_FLOW_LABEL_OPTOUT:
79442240901STom Herbert 	case IP6_AUTO_FLOW_LABEL_FORCED:
79542240901STom Herbert 		return 1;
79642240901STom Herbert 	}
79742240901STom Herbert }
798a37934fcSFlorian Fainelli #else
799a37934fcSFlorian Fainelli static inline void ip6_set_txhash(struct sock *sk) { }
800a37934fcSFlorian Fainelli static inline __be32 ip6_make_flowlabel(struct net *net, struct sk_buff *skb,
80142240901STom Herbert 					__be32 flowlabel, bool autolabel,
80242240901STom Herbert 					struct flowi6 *fl6)
803a37934fcSFlorian Fainelli {
804a37934fcSFlorian Fainelli 	return flowlabel;
805a37934fcSFlorian Fainelli }
80642240901STom Herbert static inline int ip6_default_np_autolabel(struct net *net)
80742240901STom Herbert {
80842240901STom Herbert 	return 0;
80942240901STom Herbert }
810a37934fcSFlorian Fainelli #endif
811a37934fcSFlorian Fainelli 
812cb1ce2efSTom Herbert 
813971f359dSYOSHIFUJI Hideaki /*
8143e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明  *	Header manipulation
8153e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明  */
8163e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 static inline void ip6_flow_hdr(struct ipv6hdr *hdr, unsigned int tclass,
8173e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 				__be32 flowlabel)
8183e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 {
81907f623d3SYOSHIFUJI Hideaki 	*(__be32 *)hdr = htonl(0x60000000 | (tclass << 20)) | flowlabel;
8203e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 }
8213e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 
8226502ca52SYOSHIFUJI Hideaki / 吉藤英明 static inline __be32 ip6_flowinfo(const struct ipv6hdr *hdr)
8236502ca52SYOSHIFUJI Hideaki / 吉藤英明 {
8246502ca52SYOSHIFUJI Hideaki / 吉藤英明 	return *(__be32 *)hdr & IPV6_FLOWINFO_MASK;
8256502ca52SYOSHIFUJI Hideaki / 吉藤英明 }
8266502ca52SYOSHIFUJI Hideaki / 吉藤英明 
8273308de2bSFlorent Fourcot static inline __be32 ip6_flowlabel(const struct ipv6hdr *hdr)
8283308de2bSFlorent Fourcot {
8293308de2bSFlorent Fourcot 	return *(__be32 *)hdr & IPV6_FLOWLABEL_MASK;
8303308de2bSFlorent Fourcot }
8313308de2bSFlorent Fourcot 
832d76ed22bSLi RongQing static inline u8 ip6_tclass(__be32 flowinfo)
833d76ed22bSLi RongQing {
834d76ed22bSLi RongQing 	return ntohl(flowinfo & IPV6_TCLASS_MASK) >> IPV6_TCLASS_SHIFT;
835d76ed22bSLi RongQing }
836eaa93bf4SDaniel Borkmann 
837eaa93bf4SDaniel Borkmann static inline __be32 ip6_make_flowinfo(unsigned int tclass, __be32 flowlabel)
838eaa93bf4SDaniel Borkmann {
839eaa93bf4SDaniel Borkmann 	return htonl(tclass << IPV6_TCLASS_SHIFT) | flowlabel;
840eaa93bf4SDaniel Borkmann }
841eaa93bf4SDaniel Borkmann 
8423e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 /*
8431da177e4SLinus Torvalds  *	Prototypes exported by ipv6
8441da177e4SLinus Torvalds  */
8451da177e4SLinus Torvalds 
8461da177e4SLinus Torvalds /*
8471da177e4SLinus Torvalds  *	rcv function (called from netdevice level)
8481da177e4SLinus Torvalds  */
8491da177e4SLinus Torvalds 
8505c3a0fd7SJoe Perches int ipv6_rcv(struct sk_buff *skb, struct net_device *dev,
8515c3a0fd7SJoe Perches 	     struct packet_type *pt, struct net_device *orig_dev);
8521da177e4SLinus Torvalds 
8530c4b51f0SEric W. Biederman int ip6_rcv_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
854b05e1066SPatrick McHardy 
8551da177e4SLinus Torvalds /*
8561da177e4SLinus Torvalds  *	upper-layer output functions
8571da177e4SLinus Torvalds  */
8581c1e9d2bSEric Dumazet int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6,
8595c3a0fd7SJoe Perches 	     struct ipv6_txoptions *opt, int tclass);
8601da177e4SLinus Torvalds 
8615c3a0fd7SJoe Perches int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr);
8621da177e4SLinus Torvalds 
8635c3a0fd7SJoe Perches int ip6_append_data(struct sock *sk,
8645c3a0fd7SJoe Perches 		    int getfrag(void *from, char *to, int offset, int len,
8655c3a0fd7SJoe Perches 				int odd, struct sk_buff *skb),
8665c3a0fd7SJoe Perches 		    void *from, int length, int transhdrlen, int hlimit,
8675c3a0fd7SJoe Perches 		    int tclass, struct ipv6_txoptions *opt, struct flowi6 *fl6,
868c14ac945SSoheil Hassas Yeganeh 		    struct rt6_info *rt, unsigned int flags, int dontfrag,
869c14ac945SSoheil Hassas Yeganeh 		    const struct sockcm_cookie *sockc);
8701da177e4SLinus Torvalds 
8715c3a0fd7SJoe Perches int ip6_push_pending_frames(struct sock *sk);
8721da177e4SLinus Torvalds 
8735c3a0fd7SJoe Perches void ip6_flush_pending_frames(struct sock *sk);
8741da177e4SLinus Torvalds 
8756422398cSVlad Yasevich int ip6_send_skb(struct sk_buff *skb);
8766422398cSVlad Yasevich 
8776422398cSVlad Yasevich struct sk_buff *__ip6_make_skb(struct sock *sk, struct sk_buff_head *queue,
8786422398cSVlad Yasevich 			       struct inet_cork_full *cork,
8796422398cSVlad Yasevich 			       struct inet6_cork *v6_cork);
8806422398cSVlad Yasevich struct sk_buff *ip6_make_skb(struct sock *sk,
8816422398cSVlad Yasevich 			     int getfrag(void *from, char *to, int offset,
8826422398cSVlad Yasevich 					 int len, int odd, struct sk_buff *skb),
8836422398cSVlad Yasevich 			     void *from, int length, int transhdrlen,
8846422398cSVlad Yasevich 			     int hlimit, int tclass, struct ipv6_txoptions *opt,
8856422398cSVlad Yasevich 			     struct flowi6 *fl6, struct rt6_info *rt,
886c14ac945SSoheil Hassas Yeganeh 			     unsigned int flags, int dontfrag,
887c14ac945SSoheil Hassas Yeganeh 			     const struct sockcm_cookie *sockc);
8886422398cSVlad Yasevich 
8896422398cSVlad Yasevich static inline struct sk_buff *ip6_finish_skb(struct sock *sk)
8906422398cSVlad Yasevich {
8916422398cSVlad Yasevich 	return __ip6_make_skb(sk, &sk->sk_write_queue, &inet_sk(sk)->cork,
8926422398cSVlad Yasevich 			      &inet6_sk(sk)->cork);
8936422398cSVlad Yasevich }
8946422398cSVlad Yasevich 
895343d60aaSRoopa Prabhu int ip6_dst_lookup(struct net *net, struct sock *sk, struct dst_entry **dst,
896343d60aaSRoopa Prabhu 		   struct flowi6 *fl6);
8973aef934fSEric Dumazet struct dst_entry *ip6_dst_lookup_flow(const struct sock *sk, struct flowi6 *fl6,
8980e0d44abSSteffen Klassert 				      const struct in6_addr *final_dst);
8995c3a0fd7SJoe Perches struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
9000e0d44abSSteffen Klassert 					 const struct in6_addr *final_dst);
9015c3a0fd7SJoe Perches struct dst_entry *ip6_blackhole_route(struct net *net,
90269ead7afSDavid S. Miller 				      struct dst_entry *orig_dst);
9031da177e4SLinus Torvalds 
9041da177e4SLinus Torvalds /*
9051da177e4SLinus Torvalds  *	skb processing functions
9061da177e4SLinus Torvalds  */
9071da177e4SLinus Torvalds 
908ede2059dSEric W. Biederman int ip6_output(struct net *net, struct sock *sk, struct sk_buff *skb);
9095c3a0fd7SJoe Perches int ip6_forward(struct sk_buff *skb);
9105c3a0fd7SJoe Perches int ip6_input(struct sk_buff *skb);
9115c3a0fd7SJoe Perches int ip6_mc_input(struct sk_buff *skb);
9121da177e4SLinus Torvalds 
913cf91a99dSEric W. Biederman int __ip6_local_out(struct net *net, struct sock *sk, struct sk_buff *skb);
91433224b16SEric W. Biederman int ip6_local_out(struct net *net, struct sock *sk, struct sk_buff *skb);
915ef76bc23SHerbert Xu 
9161da177e4SLinus Torvalds /*
9171da177e4SLinus Torvalds  *	Extension header (options) processing
9181da177e4SLinus Torvalds  */
9191da177e4SLinus Torvalds 
9205c3a0fd7SJoe Perches void ipv6_push_nfrag_opts(struct sk_buff *skb, struct ipv6_txoptions *opt,
9215c3a0fd7SJoe Perches 			  u8 *proto, struct in6_addr **daddr_p);
9225c3a0fd7SJoe Perches void ipv6_push_frag_opts(struct sk_buff *skb, struct ipv6_txoptions *opt,
9231da177e4SLinus Torvalds 			 u8 *proto);
9241da177e4SLinus Torvalds 
9255c3a0fd7SJoe Perches int ipv6_skip_exthdr(const struct sk_buff *, int start, u8 *nexthdrp,
9265c3a0fd7SJoe Perches 		     __be16 *frag_offp);
9271da177e4SLinus Torvalds 
9285c3a0fd7SJoe Perches bool ipv6_ext_hdr(u8 nexthdr);
9291da177e4SLinus Torvalds 
930f8f62675SJesse Gross enum {
931f8f62675SJesse Gross 	IP6_FH_F_FRAG		= (1 << 0),
932f8f62675SJesse Gross 	IP6_FH_F_AUTH		= (1 << 1),
9339195bb8eSAnsis Atteka 	IP6_FH_F_SKIP_RH	= (1 << 2),
934f8f62675SJesse Gross };
935f8f62675SJesse Gross 
936f8f62675SJesse Gross /* find specified header and get offset to it */
9375c3a0fd7SJoe Perches int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset, int target,
9385c3a0fd7SJoe Perches 		  unsigned short *fragoff, int *fragflg);
939f8f62675SJesse Gross 
9405c3a0fd7SJoe Perches int ipv6_find_tlv(struct sk_buff *skb, int offset, int type);
941c61a4043SMasahide NAKAMURA 
9425c3a0fd7SJoe Perches struct in6_addr *fl6_update_dst(struct flowi6 *fl6,
94320c59de2SArnaud Ebalard 				const struct ipv6_txoptions *opt,
94420c59de2SArnaud Ebalard 				struct in6_addr *orig);
94520c59de2SArnaud Ebalard 
9461da177e4SLinus Torvalds /*
9471da177e4SLinus Torvalds  *	socket options (ipv6_sockglue.c)
9481da177e4SLinus Torvalds  */
9491da177e4SLinus Torvalds 
9505c3a0fd7SJoe Perches int ipv6_setsockopt(struct sock *sk, int level, int optname,
9515c3a0fd7SJoe Perches 		    char __user *optval, unsigned int optlen);
9525c3a0fd7SJoe Perches int ipv6_getsockopt(struct sock *sk, int level, int optname,
9535c3a0fd7SJoe Perches 		    char __user *optval, int __user *optlen);
9545c3a0fd7SJoe Perches int compat_ipv6_setsockopt(struct sock *sk, int level, int optname,
9555c3a0fd7SJoe Perches 			   char __user *optval, unsigned int optlen);
9565c3a0fd7SJoe Perches int compat_ipv6_getsockopt(struct sock *sk, int level, int optname,
9575c3a0fd7SJoe Perches 			   char __user *optval, int __user *optlen);
9581da177e4SLinus Torvalds 
9595c3a0fd7SJoe Perches int ip6_datagram_connect(struct sock *sk, struct sockaddr *addr, int addr_len);
96082b276cdSHannes Frederic Sowa int ip6_datagram_connect_v6_only(struct sock *sk, struct sockaddr *addr,
96182b276cdSHannes Frederic Sowa 				 int addr_len);
96233c162a9SMartin KaFai Lau int ip6_datagram_dst_update(struct sock *sk, bool fix_sk_saddr);
963e646b657SMartin KaFai Lau void ip6_datagram_release_cb(struct sock *sk);
9641da177e4SLinus Torvalds 
96585fbaa75SHannes Frederic Sowa int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len,
96685fbaa75SHannes Frederic Sowa 		    int *addr_len);
96785fbaa75SHannes Frederic Sowa int ipv6_recv_rxpmtu(struct sock *sk, struct msghdr *msg, int len,
96885fbaa75SHannes Frederic Sowa 		     int *addr_len);
9695c3a0fd7SJoe Perches void ipv6_icmp_error(struct sock *sk, struct sk_buff *skb, int err, __be16 port,
9701da177e4SLinus Torvalds 		     u32 info, u8 *payload);
9715c3a0fd7SJoe Perches void ipv6_local_error(struct sock *sk, int err, struct flowi6 *fl6, u32 info);
9725c3a0fd7SJoe Perches void ipv6_local_rxpmtu(struct sock *sk, struct flowi6 *fl6, u32 mtu);
9731da177e4SLinus Torvalds 
9745c3a0fd7SJoe Perches int inet6_release(struct socket *sock);
9755c3a0fd7SJoe Perches int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len);
9765c3a0fd7SJoe Perches int inet6_getname(struct socket *sock, struct sockaddr *uaddr, int *uaddr_len,
9775c3a0fd7SJoe Perches 		  int peer);
9785c3a0fd7SJoe Perches int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
9791da177e4SLinus Torvalds 
9805c3a0fd7SJoe Perches int inet6_hash_connect(struct inet_timewait_death_row *death_row,
981d8313f5cSArnaldo Carvalho de Melo 			      struct sock *sk);
982d8313f5cSArnaldo Carvalho de Melo 
9831da177e4SLinus Torvalds /*
9841da177e4SLinus Torvalds  * reassembly.c
9851da177e4SLinus Torvalds  */
98690ddc4f0SEric Dumazet extern const struct proto_ops inet6_stream_ops;
98790ddc4f0SEric Dumazet extern const struct proto_ops inet6_dgram_ops;
98820380731SArnaldo Carvalho de Melo 
98914c85021SArnaldo Carvalho de Melo struct group_source_req;
99014c85021SArnaldo Carvalho de Melo struct group_filter;
99114c85021SArnaldo Carvalho de Melo 
9925c3a0fd7SJoe Perches int ip6_mc_source(int add, int omode, struct sock *sk,
99320380731SArnaldo Carvalho de Melo 		  struct group_source_req *pgsr);
9945c3a0fd7SJoe Perches int ip6_mc_msfilter(struct sock *sk, struct group_filter *gsf);
9955c3a0fd7SJoe Perches int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf,
9965c3a0fd7SJoe Perches 		  struct group_filter __user *optval, int __user *optlen);
99720380731SArnaldo Carvalho de Melo 
99820380731SArnaldo Carvalho de Melo #ifdef CONFIG_PROC_FS
9995c3a0fd7SJoe Perches int ac6_proc_init(struct net *net);
10005c3a0fd7SJoe Perches void ac6_proc_exit(struct net *net);
10015c3a0fd7SJoe Perches int raw6_proc_init(void);
10025c3a0fd7SJoe Perches void raw6_proc_exit(void);
10035c3a0fd7SJoe Perches int tcp6_proc_init(struct net *net);
10045c3a0fd7SJoe Perches void tcp6_proc_exit(struct net *net);
10055c3a0fd7SJoe Perches int udp6_proc_init(struct net *net);
10065c3a0fd7SJoe Perches void udp6_proc_exit(struct net *net);
10075c3a0fd7SJoe Perches int udplite6_proc_init(void);
10085c3a0fd7SJoe Perches void udplite6_proc_exit(void);
10095c3a0fd7SJoe Perches int ipv6_misc_proc_init(void);
10105c3a0fd7SJoe Perches void ipv6_misc_proc_exit(void);
10115c3a0fd7SJoe Perches int snmp6_register_dev(struct inet6_dev *idev);
10125c3a0fd7SJoe Perches int snmp6_unregister_dev(struct inet6_dev *idev);
101320380731SArnaldo Carvalho de Melo 
10147f7d9a6bSHerbert Xu #else
10156ab57e7eSDaniel Lezcano static inline int ac6_proc_init(struct net *net) { return 0; }
10166ab57e7eSDaniel Lezcano static inline void ac6_proc_exit(struct net *net) { }
10176ab57e7eSDaniel Lezcano static inline int snmp6_register_dev(struct inet6_dev *idev) { return 0; }
10186ab57e7eSDaniel Lezcano static inline int snmp6_unregister_dev(struct inet6_dev *idev) { return 0; }
101920380731SArnaldo Carvalho de Melo #endif
102020380731SArnaldo Carvalho de Melo 
102120380731SArnaldo Carvalho de Melo #ifdef CONFIG_SYSCTL
10229e8cda3bSJoe Perches extern struct ctl_table ipv6_route_table_template[];
102320380731SArnaldo Carvalho de Melo 
10245c3a0fd7SJoe Perches struct ctl_table *ipv6_icmp_sysctl_init(struct net *net);
10255c3a0fd7SJoe Perches struct ctl_table *ipv6_route_sysctl_init(struct net *net);
10265c3a0fd7SJoe Perches int ipv6_sysctl_register(void);
10275c3a0fd7SJoe Perches void ipv6_sysctl_unregister(void);
102820380731SArnaldo Carvalho de Melo #endif
102920380731SArnaldo Carvalho de Melo 
103046a4dee0SMadhu Challa int ipv6_sock_mc_join(struct sock *sk, int ifindex,
103146a4dee0SMadhu Challa 		      const struct in6_addr *addr);
103246a4dee0SMadhu Challa int ipv6_sock_mc_drop(struct sock *sk, int ifindex,
103346a4dee0SMadhu Challa 		      const struct in6_addr *addr);
10341da177e4SLinus Torvalds #endif /* _NET_IPV6_H */
1035