xref: /linux-6.15/include/net/ipv6.h (revision e9191ffb)
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>
190aeea21aSReshetova, 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 
5447d3d7acSTom Herbert /* Limits on Hop-by-Hop and Destination options.
5547d3d7acSTom Herbert  *
5647d3d7acSTom Herbert  * Per RFC8200 there is no limit on the maximum number or lengths of options in
5747d3d7acSTom Herbert  * Hop-by-Hop or Destination options other then the packet must fit in an MTU.
5847d3d7acSTom Herbert  * We allow configurable limits in order to mitigate potential denial of
5947d3d7acSTom Herbert  * service attacks.
6047d3d7acSTom Herbert  *
6147d3d7acSTom Herbert  * There are three limits that may be set:
6247d3d7acSTom Herbert  *   - Limit the number of options in a Hop-by-Hop or Destination options
6347d3d7acSTom Herbert  *     extension header
6447d3d7acSTom Herbert  *   - Limit the byte length of a Hop-by-Hop or Destination options extension
6547d3d7acSTom Herbert  *     header
6647d3d7acSTom Herbert  *   - Disallow unknown options
6747d3d7acSTom Herbert  *
6847d3d7acSTom Herbert  * The limits are expressed in corresponding sysctls:
6947d3d7acSTom Herbert  *
7047d3d7acSTom Herbert  * ipv6.sysctl.max_dst_opts_cnt
7147d3d7acSTom Herbert  * ipv6.sysctl.max_hbh_opts_cnt
7247d3d7acSTom Herbert  * ipv6.sysctl.max_dst_opts_len
7347d3d7acSTom Herbert  * ipv6.sysctl.max_hbh_opts_len
7447d3d7acSTom Herbert  *
7547d3d7acSTom Herbert  * max_*_opts_cnt is the number of TLVs that are allowed for Destination
7647d3d7acSTom Herbert  * options or Hop-by-Hop options. If the number is less than zero then unknown
7747d3d7acSTom Herbert  * TLVs are disallowed and the number of known options that are allowed is the
7847d3d7acSTom Herbert  * absolute value. Setting the value to INT_MAX indicates no limit.
7947d3d7acSTom Herbert  *
8047d3d7acSTom Herbert  * max_*_opts_len is the length limit in bytes of a Destination or
8147d3d7acSTom Herbert  * Hop-by-Hop options extension header. Setting the value to INT_MAX
8247d3d7acSTom Herbert  * indicates no length limit.
8347d3d7acSTom Herbert  *
8447d3d7acSTom Herbert  * If a limit is exceeded when processing an extension header the packet is
8547d3d7acSTom Herbert  * silently discarded.
8647d3d7acSTom Herbert  */
8747d3d7acSTom Herbert 
8847d3d7acSTom Herbert /* Default limits for Hop-by-Hop and Destination options */
8947d3d7acSTom Herbert #define IP6_DEFAULT_MAX_DST_OPTS_CNT	 8
9047d3d7acSTom Herbert #define IP6_DEFAULT_MAX_HBH_OPTS_CNT	 8
9147d3d7acSTom Herbert #define IP6_DEFAULT_MAX_DST_OPTS_LEN	 INT_MAX /* No limit */
9247d3d7acSTom Herbert #define IP6_DEFAULT_MAX_HBH_OPTS_LEN	 INT_MAX /* No limit */
9347d3d7acSTom Herbert 
941da177e4SLinus Torvalds /*
951da177e4SLinus Torvalds  *	Addr type
961da177e4SLinus Torvalds  *
971da177e4SLinus Torvalds  *	type	-	unicast | multicast
981da177e4SLinus Torvalds  *	scope	-	local	| site	    | global
991da177e4SLinus Torvalds  *	v4	-	compat
1001da177e4SLinus Torvalds  *	v4mapped
1011da177e4SLinus Torvalds  *	any
1021da177e4SLinus Torvalds  *	loopback
1031da177e4SLinus Torvalds  */
1041da177e4SLinus Torvalds 
1051da177e4SLinus Torvalds #define IPV6_ADDR_ANY		0x0000U
1061da177e4SLinus Torvalds 
1071da177e4SLinus Torvalds #define IPV6_ADDR_UNICAST      	0x0001U
1081da177e4SLinus Torvalds #define IPV6_ADDR_MULTICAST    	0x0002U
1091da177e4SLinus Torvalds 
1101da177e4SLinus Torvalds #define IPV6_ADDR_LOOPBACK	0x0010U
1111da177e4SLinus Torvalds #define IPV6_ADDR_LINKLOCAL	0x0020U
1121da177e4SLinus Torvalds #define IPV6_ADDR_SITELOCAL	0x0040U
1131da177e4SLinus Torvalds 
1141da177e4SLinus Torvalds #define IPV6_ADDR_COMPATv4	0x0080U
1151da177e4SLinus Torvalds 
1161da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_MASK	0x00f0U
1171da177e4SLinus Torvalds 
1181da177e4SLinus Torvalds #define IPV6_ADDR_MAPPED	0x1000U
1191da177e4SLinus Torvalds 
1201da177e4SLinus Torvalds /*
1211da177e4SLinus Torvalds  *	Addr scopes
1221da177e4SLinus Torvalds  */
1231da177e4SLinus Torvalds #define IPV6_ADDR_MC_SCOPE(a)	\
1241da177e4SLinus Torvalds 	((a)->s6_addr[1] & 0x0f)	/* nonstandard */
1251da177e4SLinus Torvalds #define __IPV6_ADDR_SCOPE_INVALID	-1
1261da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_NODELOCAL	0x01
1271da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_LINKLOCAL	0x02
1281da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_SITELOCAL	0x05
1291da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_ORGLOCAL	0x08
1301da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_GLOBAL		0x0e
1311da177e4SLinus Torvalds 
1321da177e4SLinus Torvalds /*
1335ced1339SLinus Lüssing  *	Addr flags
1345ced1339SLinus Lüssing  */
1355ced1339SLinus Lüssing #define IPV6_ADDR_MC_FLAG_TRANSIENT(a)	\
1365ced1339SLinus Lüssing 	((a)->s6_addr[1] & 0x10)
1375ced1339SLinus Lüssing #define IPV6_ADDR_MC_FLAG_PREFIX(a)	\
1385ced1339SLinus Lüssing 	((a)->s6_addr[1] & 0x20)
1395ced1339SLinus Lüssing #define IPV6_ADDR_MC_FLAG_RENDEZVOUS(a)	\
1405ced1339SLinus Lüssing 	((a)->s6_addr[1] & 0x40)
1415ced1339SLinus Lüssing 
1425ced1339SLinus Lüssing /*
1431da177e4SLinus Torvalds  *	fragmentation header
1441da177e4SLinus Torvalds  */
1451da177e4SLinus Torvalds 
1461da177e4SLinus Torvalds struct frag_hdr {
14744473a6bSAl Viro 	__u8	nexthdr;
14844473a6bSAl Viro 	__u8	reserved;
14944473a6bSAl Viro 	__be16	frag_off;
15044473a6bSAl Viro 	__be32	identification;
1511da177e4SLinus Torvalds };
1521da177e4SLinus Torvalds 
1531da177e4SLinus Torvalds #define	IP6_MF		0x0001
1541431fb31SPaul Durrant #define	IP6_OFFSET	0xFFF8
1551da177e4SLinus Torvalds 
156e110861fSLorenzo Colitti #define IP6_REPLY_MARK(net, mark) \
157e110861fSLorenzo Colitti 	((net)->ipv6.sysctl.fwmark_reflect ? (mark) : 0)
158e110861fSLorenzo Colitti 
1591da177e4SLinus Torvalds #include <net/sock.h>
1601da177e4SLinus Torvalds 
1611da177e4SLinus Torvalds /* sysctls */
1621da177e4SLinus Torvalds extern int sysctl_mld_max_msf;
1632f711939SHannes Frederic Sowa extern int sysctl_mld_qrv;
1643d7cc2baSPavel Emelyanov 
16513415e46SEric Dumazet #define _DEVINC(net, statname, mod, idev, field)			\
16614878f75SDavid L Stevens ({									\
16714878f75SDavid L Stevens 	struct inet6_dev *_idev = (idev);				\
16814878f75SDavid L Stevens 	if (likely(_idev != NULL))					\
16913415e46SEric Dumazet 		mod##SNMP_INC_STATS64((_idev)->stats.statname, (field));\
17013415e46SEric Dumazet 	mod##SNMP_INC_STATS64((net)->mib.statname##_statistics, (field));\
17114878f75SDavid L Stevens })
17214878f75SDavid L Stevens 
173be281e55SEric Dumazet /* per device counters are atomic_long_t */
17413415e46SEric Dumazet #define _DEVINCATOMIC(net, statname, mod, idev, field)			\
175be281e55SEric Dumazet ({									\
176be281e55SEric Dumazet 	struct inet6_dev *_idev = (idev);				\
177be281e55SEric Dumazet 	if (likely(_idev != NULL))					\
178be281e55SEric Dumazet 		SNMP_INC_STATS_ATOMIC_LONG((_idev)->stats.statname##dev, (field)); \
17913415e46SEric Dumazet 	mod##SNMP_INC_STATS((net)->mib.statname##_statistics, (field));\
180be281e55SEric Dumazet })
181be281e55SEric Dumazet 
1822a24444fSEric Dumazet /* per device and per net counters are atomic_long_t */
1832a24444fSEric Dumazet #define _DEVINC_ATOMIC_ATOMIC(net, statname, idev, field)		\
1842a24444fSEric Dumazet ({									\
1852a24444fSEric Dumazet 	struct inet6_dev *_idev = (idev);				\
1862a24444fSEric Dumazet 	if (likely(_idev != NULL))					\
1872a24444fSEric Dumazet 		SNMP_INC_STATS_ATOMIC_LONG((_idev)->stats.statname##dev, (field)); \
1882a24444fSEric Dumazet 	SNMP_INC_STATS_ATOMIC_LONG((net)->mib.statname##_statistics, (field));\
1892a24444fSEric Dumazet })
1902a24444fSEric Dumazet 
19113415e46SEric Dumazet #define _DEVADD(net, statname, mod, idev, field, val)			\
1928e7999c4SPavel Emelyanov ({									\
1938e7999c4SPavel Emelyanov 	struct inet6_dev *_idev = (idev);				\
1948e7999c4SPavel Emelyanov 	if (likely(_idev != NULL))					\
19513415e46SEric Dumazet 		mod##SNMP_ADD_STATS((_idev)->stats.statname, (field), (val)); \
19613415e46SEric Dumazet 	mod##SNMP_ADD_STATS((net)->mib.statname##_statistics, (field), (val));\
1978e7999c4SPavel Emelyanov })
1988e7999c4SPavel Emelyanov 
19913415e46SEric Dumazet #define _DEVUPD(net, statname, mod, idev, field, val)			\
200edf391ffSNeil Horman ({									\
201edf391ffSNeil Horman 	struct inet6_dev *_idev = (idev);				\
202edf391ffSNeil Horman 	if (likely(_idev != NULL))					\
20313415e46SEric Dumazet 		mod##SNMP_UPD_PO_STATS((_idev)->stats.statname, field, (val)); \
20413415e46SEric Dumazet 	mod##SNMP_UPD_PO_STATS((net)->mib.statname##_statistics, field, (val));\
205edf391ffSNeil Horman })
206edf391ffSNeil Horman 
2071da177e4SLinus Torvalds /* MIBs */
20814878f75SDavid L Stevens 
209087fe240SDenis V. Lunev #define IP6_INC_STATS(net, idev,field)		\
21013415e46SEric Dumazet 		_DEVINC(net, ipv6, , idev, field)
2111d015503SEric Dumazet #define __IP6_INC_STATS(net, idev,field)	\
21213415e46SEric Dumazet 		_DEVINC(net, ipv6, __, idev, field)
213edf391ffSNeil Horman #define IP6_ADD_STATS(net, idev,field,val)	\
21413415e46SEric Dumazet 		_DEVADD(net, ipv6, , idev, field, val)
2151d015503SEric Dumazet #define __IP6_ADD_STATS(net, idev,field,val)	\
21613415e46SEric Dumazet 		_DEVADD(net, ipv6, __, idev, field, val)
217edf391ffSNeil Horman #define IP6_UPD_PO_STATS(net, idev,field,val)   \
21813415e46SEric Dumazet 		_DEVUPD(net, ipv6, , idev, field, val)
219c2005eb0SEric Dumazet #define __IP6_UPD_PO_STATS(net, idev,field,val)   \
22013415e46SEric Dumazet 		_DEVUPD(net, ipv6, __, idev, field, val)
221087fe240SDenis V. Lunev #define ICMP6_INC_STATS(net, idev, field)	\
222be281e55SEric Dumazet 		_DEVINCATOMIC(net, icmpv6, , idev, field)
223a16292a0SEric Dumazet #define __ICMP6_INC_STATS(net, idev, field)	\
22413415e46SEric Dumazet 		_DEVINCATOMIC(net, icmpv6, __, idev, field)
22514878f75SDavid L Stevens 
226087fe240SDenis V. Lunev #define ICMP6MSGOUT_INC_STATS(net, idev, field)		\
2272a24444fSEric Dumazet 	_DEVINC_ATOMIC_ATOMIC(net, icmpv6msg, idev, field +256)
228f3832ed2SEric Dumazet #define ICMP6MSGIN_INC_STATS(net, idev, field)	\
2292a24444fSEric Dumazet 	_DEVINC_ATOMIC_ATOMIC(net, icmpv6msg, idev, field)
23014878f75SDavid L Stevens 
231fd2c3ef7SEric Dumazet struct ip6_ra_chain {
2321da177e4SLinus Torvalds 	struct ip6_ra_chain	*next;
2331da177e4SLinus Torvalds 	struct sock		*sk;
2341da177e4SLinus Torvalds 	int			sel;
2351da177e4SLinus Torvalds 	void			(*destructor)(struct sock *);
2361da177e4SLinus Torvalds };
2371da177e4SLinus Torvalds 
2381da177e4SLinus Torvalds extern struct ip6_ra_chain	*ip6_ra_chain;
2391da177e4SLinus Torvalds extern rwlock_t ip6_ra_lock;
2401da177e4SLinus Torvalds 
2411da177e4SLinus Torvalds /*
2421da177e4SLinus Torvalds    This structure is prepared by protocol, when parsing
2431da177e4SLinus Torvalds    ancillary data and passed to IPv6.
2441da177e4SLinus Torvalds  */
2451da177e4SLinus Torvalds 
246fd2c3ef7SEric Dumazet struct ipv6_txoptions {
2470aeea21aSReshetova, Elena 	refcount_t		refcnt;
2481da177e4SLinus Torvalds 	/* Length of this structure */
2491da177e4SLinus Torvalds 	int			tot_len;
2501da177e4SLinus Torvalds 
2511da177e4SLinus Torvalds 	/* length of extension headers   */
2521da177e4SLinus Torvalds 
2531da177e4SLinus Torvalds 	__u16			opt_flen;	/* after fragment hdr */
2541da177e4SLinus Torvalds 	__u16			opt_nflen;	/* before fragment hdr */
2551da177e4SLinus Torvalds 
2561da177e4SLinus Torvalds 	struct ipv6_opt_hdr	*hopopt;
2571da177e4SLinus Torvalds 	struct ipv6_opt_hdr	*dst0opt;
2581da177e4SLinus Torvalds 	struct ipv6_rt_hdr	*srcrt;	/* Routing Header */
2591da177e4SLinus Torvalds 	struct ipv6_opt_hdr	*dst1opt;
26045f6fad8SEric Dumazet 	struct rcu_head		rcu;
2611da177e4SLinus Torvalds 	/* Option buffer, as read by IPV6_PKTOPTIONS, starts here. */
2621da177e4SLinus Torvalds };
2631da177e4SLinus Torvalds 
264fd2c3ef7SEric Dumazet struct ip6_flowlabel {
2657f0e44acSEric Dumazet 	struct ip6_flowlabel __rcu *next;
26690bcaf7bSAl Viro 	__be32			label;
267db3459d1SEric Dumazet 	atomic_t		users;
2681da177e4SLinus Torvalds 	struct in6_addr		dst;
2691da177e4SLinus Torvalds 	struct ipv6_txoptions	*opt;
2701da177e4SLinus Torvalds 	unsigned long		linger;
271d3aedd5eSYOSHIFUJI Hideaki / 吉藤英明 	struct rcu_head		rcu;
2721da177e4SLinus Torvalds 	u8			share;
2734f82f457SEric W. Biederman 	union {
2744f82f457SEric W. Biederman 		struct pid *pid;
2754f82f457SEric W. Biederman 		kuid_t uid;
2764f82f457SEric W. Biederman 	} owner;
2771da177e4SLinus Torvalds 	unsigned long		lastuse;
2781da177e4SLinus Torvalds 	unsigned long		expires;
27960e8fbc4SBenjamin Thery 	struct net		*fl_net;
2801da177e4SLinus Torvalds };
2811da177e4SLinus Torvalds 
282f3a7c66bSHarvey Harrison #define IPV6_FLOWINFO_MASK		cpu_to_be32(0x0FFFFFFF)
283f3a7c66bSHarvey Harrison #define IPV6_FLOWLABEL_MASK		cpu_to_be32(0x000FFFFF)
28482a584b7STom Herbert #define IPV6_FLOWLABEL_STATELESS_FLAG	cpu_to_be32(0x00080000)
28582a584b7STom Herbert 
28637cfee90SFlorent Fourcot #define IPV6_TCLASS_MASK (IPV6_FLOWINFO_MASK & ~IPV6_FLOWLABEL_MASK)
287d76ed22bSLi RongQing #define IPV6_TCLASS_SHIFT	20
2881da177e4SLinus Torvalds 
289fd2c3ef7SEric Dumazet struct ipv6_fl_socklist {
2907f0e44acSEric Dumazet 	struct ipv6_fl_socklist	__rcu	*next;
2911da177e4SLinus Torvalds 	struct ip6_flowlabel		*fl;
29218367681SYOSHIFUJI Hideaki / 吉藤英明 	struct rcu_head			rcu;
2931da177e4SLinus Torvalds };
2941da177e4SLinus Torvalds 
29526879da5SWei Wang struct ipcm6_cookie {
29626879da5SWei Wang 	__s16 hlimit;
29726879da5SWei Wang 	__s16 tclass;
29826879da5SWei Wang 	__s8  dontfrag;
29926879da5SWei Wang 	struct ipv6_txoptions *opt;
30026879da5SWei Wang };
30126879da5SWei Wang 
30245f6fad8SEric Dumazet static inline struct ipv6_txoptions *txopt_get(const struct ipv6_pinfo *np)
30345f6fad8SEric Dumazet {
30445f6fad8SEric Dumazet 	struct ipv6_txoptions *opt;
30545f6fad8SEric Dumazet 
30645f6fad8SEric Dumazet 	rcu_read_lock();
30745f6fad8SEric Dumazet 	opt = rcu_dereference(np->opt);
308e550785cSBenjamin Poirier 	if (opt) {
3090aeea21aSReshetova, Elena 		if (!refcount_inc_not_zero(&opt->refcnt))
31045f6fad8SEric Dumazet 			opt = NULL;
311e550785cSBenjamin Poirier 		else
312e550785cSBenjamin Poirier 			opt = rcu_pointer_handoff(opt);
313e550785cSBenjamin Poirier 	}
31445f6fad8SEric Dumazet 	rcu_read_unlock();
31545f6fad8SEric Dumazet 	return opt;
31645f6fad8SEric Dumazet }
31745f6fad8SEric Dumazet 
31845f6fad8SEric Dumazet static inline void txopt_put(struct ipv6_txoptions *opt)
31945f6fad8SEric Dumazet {
3200aeea21aSReshetova, Elena 	if (opt && refcount_dec_and_test(&opt->refcnt))
32145f6fad8SEric Dumazet 		kfree_rcu(opt, rcu);
32245f6fad8SEric Dumazet }
32345f6fad8SEric Dumazet 
3245c3a0fd7SJoe Perches struct ip6_flowlabel *fl6_sock_lookup(struct sock *sk, __be32 label);
3255c3a0fd7SJoe Perches struct ipv6_txoptions *fl6_merge_options(struct ipv6_txoptions *opt_space,
3261da177e4SLinus Torvalds 					 struct ip6_flowlabel *fl,
3271da177e4SLinus Torvalds 					 struct ipv6_txoptions *fopt);
3285c3a0fd7SJoe Perches void fl6_free_socklist(struct sock *sk);
3295c3a0fd7SJoe Perches int ipv6_flowlabel_opt(struct sock *sk, char __user *optval, int optlen);
33046e5f401SFlorent Fourcot int ipv6_flowlabel_opt_get(struct sock *sk, struct in6_flowlabel_req *freq,
33146e5f401SFlorent Fourcot 			   int flags);
3325c3a0fd7SJoe Perches int ip6_flowlabel_init(void);
3335c3a0fd7SJoe Perches void ip6_flowlabel_cleanup(void);
334*e9191ffbSBen Hutchings bool ip6_autoflowlabel(struct net *net, const struct ipv6_pinfo *np);
3351da177e4SLinus Torvalds 
3361da177e4SLinus Torvalds static inline void fl6_sock_release(struct ip6_flowlabel *fl)
3371da177e4SLinus Torvalds {
3381da177e4SLinus Torvalds 	if (fl)
3391da177e4SLinus Torvalds 		atomic_dec(&fl->users);
3401da177e4SLinus Torvalds }
3411da177e4SLinus Torvalds 
3425c3a0fd7SJoe Perches void icmpv6_notify(struct sk_buff *skb, u8 type, u8 code, __be32 info);
343b94f1c09SDavid S. Miller 
3444e64b1edSJoe Perches void icmpv6_push_pending_frames(struct sock *sk, struct flowi6 *fl6,
3456d0bfe22SLorenzo Colitti 				struct icmp6hdr *thdr, int len);
3466d0bfe22SLorenzo Colitti 
3475c3a0fd7SJoe Perches int ip6_ra_control(struct sock *sk, int sel);
3481da177e4SLinus Torvalds 
3495c3a0fd7SJoe Perches int ipv6_parse_hopopts(struct sk_buff *skb);
3501da177e4SLinus Torvalds 
3515c3a0fd7SJoe Perches struct ipv6_txoptions *ipv6_dup_options(struct sock *sk,
3525c3a0fd7SJoe Perches 					struct ipv6_txoptions *opt);
3535c3a0fd7SJoe Perches struct ipv6_txoptions *ipv6_renew_options(struct sock *sk,
3545c3a0fd7SJoe Perches 					  struct ipv6_txoptions *opt,
355333fad53SYOSHIFUJI Hideaki 					  int newtype,
356333fad53SYOSHIFUJI Hideaki 					  struct ipv6_opt_hdr __user *newopt,
357333fad53SYOSHIFUJI Hideaki 					  int newoptlen);
358e67ae213SHuw Davies struct ipv6_txoptions *
359e67ae213SHuw Davies ipv6_renew_options_kern(struct sock *sk,
360e67ae213SHuw Davies 			struct ipv6_txoptions *opt,
361e67ae213SHuw Davies 			int newtype,
362e67ae213SHuw Davies 			struct ipv6_opt_hdr *newopt,
363e67ae213SHuw Davies 			int newoptlen);
364df9890c3SYOSHIFUJI Hideaki struct ipv6_txoptions *ipv6_fixup_options(struct ipv6_txoptions *opt_space,
365df9890c3SYOSHIFUJI Hideaki 					  struct ipv6_txoptions *opt);
3661da177e4SLinus Torvalds 
367a224772dSEric Dumazet bool ipv6_opt_accepted(const struct sock *sk, const struct sk_buff *skb,
368a224772dSEric Dumazet 		       const struct inet6_skb_parm *opt);
369ceba1832SHuw Davies struct ipv6_txoptions *ipv6_update_options(struct sock *sk,
370ceba1832SHuw Davies 					   struct ipv6_txoptions *opt);
371399c07deSArnaldo Carvalho de Melo 
372aeaf6e9dSShmulik Ladkani static inline bool ipv6_accept_ra(struct inet6_dev *idev)
373aeaf6e9dSShmulik Ladkani {
374aeaf6e9dSShmulik Ladkani 	/* If forwarding is enabled, RA are not accepted unless the special
375aeaf6e9dSShmulik Ladkani 	 * hybrid mode (accept_ra=2) is enabled.
376aeaf6e9dSShmulik Ladkani 	 */
377aeaf6e9dSShmulik Ladkani 	return idev->cnf.forwarding ? idev->cnf.accept_ra == 2 :
378aeaf6e9dSShmulik Ladkani 	    idev->cnf.accept_ra;
379aeaf6e9dSShmulik Ladkani }
380aeaf6e9dSShmulik Ladkani 
381d4915c08SAmerigo Wang #if IS_ENABLED(CONFIG_IPV6)
382d4915c08SAmerigo Wang static inline int ip6_frag_mem(struct net *net)
383d4915c08SAmerigo Wang {
384d433673eSJesper Dangaard Brouer 	return sum_frag_mem_limit(&net->ipv6.frags);
385d4915c08SAmerigo Wang }
386d4915c08SAmerigo Wang #endif
3871da177e4SLinus Torvalds 
388c2a93660SJesper Dangaard Brouer #define IPV6_FRAG_HIGH_THRESH	(4 * 1024*1024)	/* 4194304 */
389c2a93660SJesper Dangaard Brouer #define IPV6_FRAG_LOW_THRESH	(3 * 1024*1024)	/* 3145728 */
3901da177e4SLinus Torvalds #define IPV6_FRAG_TIMEOUT	(60 * HZ)	/* 60 seconds */
3911da177e4SLinus Torvalds 
3925c3a0fd7SJoe Perches int __ipv6_addr_type(const struct in6_addr *addr);
393b1cacb68SYOSHIFUJI Hideaki static inline int ipv6_addr_type(const struct in6_addr *addr)
394b1cacb68SYOSHIFUJI Hideaki {
395b1cacb68SYOSHIFUJI Hideaki 	return __ipv6_addr_type(addr) & 0xffff;
396b1cacb68SYOSHIFUJI Hideaki }
3971da177e4SLinus Torvalds 
3981da177e4SLinus Torvalds static inline int ipv6_addr_scope(const struct in6_addr *addr)
3991da177e4SLinus Torvalds {
400b1cacb68SYOSHIFUJI Hideaki 	return __ipv6_addr_type(addr) & IPV6_ADDR_SCOPE_MASK;
401b1cacb68SYOSHIFUJI Hideaki }
402b1cacb68SYOSHIFUJI Hideaki 
403b1cacb68SYOSHIFUJI Hideaki static inline int __ipv6_addr_src_scope(int type)
404b1cacb68SYOSHIFUJI Hideaki {
405a02cec21SEric Dumazet 	return (type == IPV6_ADDR_ANY) ? __IPV6_ADDR_SCOPE_INVALID : (type >> 16);
406b1cacb68SYOSHIFUJI Hideaki }
407b1cacb68SYOSHIFUJI Hideaki 
408b1cacb68SYOSHIFUJI Hideaki static inline int ipv6_addr_src_scope(const struct in6_addr *addr)
409b1cacb68SYOSHIFUJI Hideaki {
410b1cacb68SYOSHIFUJI Hideaki 	return __ipv6_addr_src_scope(__ipv6_addr_type(addr));
4111da177e4SLinus Torvalds }
4121da177e4SLinus Torvalds 
413b7ef213eSHannes Frederic Sowa static inline bool __ipv6_addr_needs_scope_id(int type)
414b7ef213eSHannes Frederic Sowa {
415b7ef213eSHannes Frederic Sowa 	return type & IPV6_ADDR_LINKLOCAL ||
416b7ef213eSHannes Frederic Sowa 	       (type & IPV6_ADDR_MULTICAST &&
417b7ef213eSHannes Frederic Sowa 		(type & (IPV6_ADDR_LOOPBACK|IPV6_ADDR_LINKLOCAL)));
418b7ef213eSHannes Frederic Sowa }
419b7ef213eSHannes Frederic Sowa 
420b7ef213eSHannes Frederic Sowa static inline __u32 ipv6_iface_scope_id(const struct in6_addr *addr, int iface)
421b7ef213eSHannes Frederic Sowa {
422b7ef213eSHannes Frederic Sowa 	return __ipv6_addr_needs_scope_id(__ipv6_addr_type(addr)) ? iface : 0;
423b7ef213eSHannes Frederic Sowa }
424b7ef213eSHannes Frederic Sowa 
4251da177e4SLinus Torvalds static inline int ipv6_addr_cmp(const struct in6_addr *a1, const struct in6_addr *a2)
4261da177e4SLinus Torvalds {
427db3459d1SEric Dumazet 	return memcmp(a1, a2, sizeof(struct in6_addr));
4281da177e4SLinus Torvalds }
4291da177e4SLinus Torvalds 
4301a203cb3SEric Dumazet static inline bool
431f2ffd9eeSPatrick McHardy ipv6_masked_addr_cmp(const struct in6_addr *a1, const struct in6_addr *m,
432f2ffd9eeSPatrick McHardy 		     const struct in6_addr *a2)
433f2ffd9eeSPatrick McHardy {
4341a203cb3SEric Dumazet #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
4351a203cb3SEric Dumazet 	const unsigned long *ul1 = (const unsigned long *)a1;
4361a203cb3SEric Dumazet 	const unsigned long *ulm = (const unsigned long *)m;
4371a203cb3SEric Dumazet 	const unsigned long *ul2 = (const unsigned long *)a2;
4381a203cb3SEric Dumazet 
4391a203cb3SEric Dumazet 	return !!(((ul1[0] ^ ul2[0]) & ulm[0]) |
4401a203cb3SEric Dumazet 		  ((ul1[1] ^ ul2[1]) & ulm[1]));
4411a203cb3SEric Dumazet #else
442a02cec21SEric Dumazet 	return !!(((a1->s6_addr32[0] ^ a2->s6_addr32[0]) & m->s6_addr32[0]) |
443fed85383SYOSHIFUJI Hideaki 		  ((a1->s6_addr32[1] ^ a2->s6_addr32[1]) & m->s6_addr32[1]) |
444fed85383SYOSHIFUJI Hideaki 		  ((a1->s6_addr32[2] ^ a2->s6_addr32[2]) & m->s6_addr32[2]) |
445a02cec21SEric Dumazet 		  ((a1->s6_addr32[3] ^ a2->s6_addr32[3]) & m->s6_addr32[3]));
4461a203cb3SEric Dumazet #endif
447f2ffd9eeSPatrick McHardy }
448f2ffd9eeSPatrick McHardy 
4491da177e4SLinus Torvalds static inline void ipv6_addr_prefix(struct in6_addr *pfx,
4501da177e4SLinus Torvalds 				    const struct in6_addr *addr,
4511da177e4SLinus Torvalds 				    int plen)
4521da177e4SLinus Torvalds {
4531da177e4SLinus Torvalds 	/* caller must guarantee 0 <= plen <= 128 */
4541da177e4SLinus Torvalds 	int o = plen >> 3,
4551da177e4SLinus Torvalds 	    b = plen & 0x7;
4561da177e4SLinus Torvalds 
457db3459d1SEric Dumazet 	memset(pfx->s6_addr, 0, sizeof(pfx->s6_addr));
4581da177e4SLinus Torvalds 	memcpy(pfx->s6_addr, addr, o);
459db3459d1SEric Dumazet 	if (b != 0)
4601da177e4SLinus Torvalds 		pfx->s6_addr[o] = addr->s6_addr[o] & (0xff00 >> b);
4611da177e4SLinus Torvalds }
4621da177e4SLinus Torvalds 
463818f1f3eSAlexander Aring static inline void ipv6_addr_prefix_copy(struct in6_addr *addr,
464818f1f3eSAlexander Aring 					 const struct in6_addr *pfx,
465818f1f3eSAlexander Aring 					 int plen)
466818f1f3eSAlexander Aring {
467818f1f3eSAlexander Aring 	/* caller must guarantee 0 <= plen <= 128 */
468818f1f3eSAlexander Aring 	int o = plen >> 3,
469818f1f3eSAlexander Aring 	    b = plen & 0x7;
470818f1f3eSAlexander Aring 
471818f1f3eSAlexander Aring 	memcpy(addr->s6_addr, pfx, o);
472818f1f3eSAlexander Aring 	if (b != 0) {
473818f1f3eSAlexander Aring 		addr->s6_addr[o] &= ~(0xff00 >> b);
474818f1f3eSAlexander Aring 		addr->s6_addr[o] |= (pfx->s6_addr[o] & (0xff00 >> b));
475818f1f3eSAlexander Aring 	}
476818f1f3eSAlexander Aring }
477818f1f3eSAlexander Aring 
4785206c579SYOSHIFUJI Hideaki / 吉藤英明 static inline void __ipv6_addr_set_half(__be32 *addr,
4795206c579SYOSHIFUJI Hideaki / 吉藤英明 					__be32 wh, __be32 wl)
4805206c579SYOSHIFUJI Hideaki / 吉藤英明 {
4815206c579SYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
4825206c579SYOSHIFUJI Hideaki / 吉藤英明 #if defined(__BIG_ENDIAN)
4835206c579SYOSHIFUJI Hideaki / 吉藤英明 	if (__builtin_constant_p(wh) && __builtin_constant_p(wl)) {
4845206c579SYOSHIFUJI Hideaki / 吉藤英明 		*(__force u64 *)addr = ((__force u64)(wh) << 32 | (__force u64)(wl));
4855206c579SYOSHIFUJI Hideaki / 吉藤英明 		return;
4865206c579SYOSHIFUJI Hideaki / 吉藤英明 	}
4875206c579SYOSHIFUJI Hideaki / 吉藤英明 #elif defined(__LITTLE_ENDIAN)
4885206c579SYOSHIFUJI Hideaki / 吉藤英明 	if (__builtin_constant_p(wl) && __builtin_constant_p(wh)) {
4895206c579SYOSHIFUJI Hideaki / 吉藤英明 		*(__force u64 *)addr = ((__force u64)(wl) << 32 | (__force u64)(wh));
4905206c579SYOSHIFUJI Hideaki / 吉藤英明 		return;
4915206c579SYOSHIFUJI Hideaki / 吉藤英明 	}
4925206c579SYOSHIFUJI Hideaki / 吉藤英明 #endif
4935206c579SYOSHIFUJI Hideaki / 吉藤英明 #endif
4945206c579SYOSHIFUJI Hideaki / 吉藤英明 	addr[0] = wh;
4955206c579SYOSHIFUJI Hideaki / 吉藤英明 	addr[1] = wl;
4965206c579SYOSHIFUJI Hideaki / 吉藤英明 }
4975206c579SYOSHIFUJI Hideaki / 吉藤英明 
4981da177e4SLinus Torvalds static inline void ipv6_addr_set(struct in6_addr *addr,
49948818f82SAl Viro 				     __be32 w1, __be32 w2,
50048818f82SAl Viro 				     __be32 w3, __be32 w4)
5011da177e4SLinus Torvalds {
5025206c579SYOSHIFUJI Hideaki / 吉藤英明 	__ipv6_addr_set_half(&addr->s6_addr32[0], w1, w2);
5035206c579SYOSHIFUJI Hideaki / 吉藤英明 	__ipv6_addr_set_half(&addr->s6_addr32[2], w3, w4);
5041da177e4SLinus Torvalds }
5051da177e4SLinus Torvalds 
50692113bfdSEric Dumazet static inline bool ipv6_addr_equal(const struct in6_addr *a1,
5071da177e4SLinus Torvalds 				   const struct in6_addr *a2)
5081da177e4SLinus Torvalds {
5091a203cb3SEric Dumazet #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
5101a203cb3SEric Dumazet 	const unsigned long *ul1 = (const unsigned long *)a1;
5111a203cb3SEric Dumazet 	const unsigned long *ul2 = (const unsigned long *)a2;
5121a203cb3SEric Dumazet 
5131a203cb3SEric Dumazet 	return ((ul1[0] ^ ul2[0]) | (ul1[1] ^ ul2[1])) == 0UL;
5141a203cb3SEric Dumazet #else
515a02cec21SEric Dumazet 	return ((a1->s6_addr32[0] ^ a2->s6_addr32[0]) |
516fed85383SYOSHIFUJI Hideaki 		(a1->s6_addr32[1] ^ a2->s6_addr32[1]) |
517fed85383SYOSHIFUJI Hideaki 		(a1->s6_addr32[2] ^ a2->s6_addr32[2]) |
518a02cec21SEric Dumazet 		(a1->s6_addr32[3] ^ a2->s6_addr32[3])) == 0;
5191a203cb3SEric Dumazet #endif
5201da177e4SLinus Torvalds }
5211da177e4SLinus Torvalds 
52238675170SYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
52338675170SYOSHIFUJI Hideaki / 吉藤英明 static inline bool __ipv6_prefix_equal64_half(const __be64 *a1,
52438675170SYOSHIFUJI Hideaki / 吉藤英明 					      const __be64 *a2,
52538675170SYOSHIFUJI Hideaki / 吉藤英明 					      unsigned int len)
52638675170SYOSHIFUJI Hideaki / 吉藤英明 {
527512613d7SFabio Baltieri 	if (len && ((*a1 ^ *a2) & cpu_to_be64((~0UL) << (64 - len))))
52838675170SYOSHIFUJI Hideaki / 吉藤英明 		return false;
52938675170SYOSHIFUJI Hideaki / 吉藤英明 	return true;
53038675170SYOSHIFUJI Hideaki / 吉藤英明 }
53138675170SYOSHIFUJI Hideaki / 吉藤英明 
53238675170SYOSHIFUJI Hideaki / 吉藤英明 static inline bool ipv6_prefix_equal(const struct in6_addr *addr1,
53338675170SYOSHIFUJI Hideaki / 吉藤英明 				     const struct in6_addr *addr2,
53438675170SYOSHIFUJI Hideaki / 吉藤英明 				     unsigned int prefixlen)
53538675170SYOSHIFUJI Hideaki / 吉藤英明 {
53638675170SYOSHIFUJI Hideaki / 吉藤英明 	const __be64 *a1 = (const __be64 *)addr1;
53738675170SYOSHIFUJI Hideaki / 吉藤英明 	const __be64 *a2 = (const __be64 *)addr2;
53838675170SYOSHIFUJI Hideaki / 吉藤英明 
53938675170SYOSHIFUJI Hideaki / 吉藤英明 	if (prefixlen >= 64) {
54038675170SYOSHIFUJI Hideaki / 吉藤英明 		if (a1[0] ^ a2[0])
54138675170SYOSHIFUJI Hideaki / 吉藤英明 			return false;
54238675170SYOSHIFUJI Hideaki / 吉藤英明 		return __ipv6_prefix_equal64_half(a1 + 1, a2 + 1, prefixlen - 64);
54338675170SYOSHIFUJI Hideaki / 吉藤英明 	}
54438675170SYOSHIFUJI Hideaki / 吉藤英明 	return __ipv6_prefix_equal64_half(a1, a2, prefixlen);
54538675170SYOSHIFUJI Hideaki / 吉藤英明 }
54638675170SYOSHIFUJI Hideaki / 吉藤英明 #else
5472ef97332SYOSHIFUJI Hideaki / 吉藤英明 static inline bool ipv6_prefix_equal(const struct in6_addr *addr1,
5482ef97332SYOSHIFUJI Hideaki / 吉藤英明 				     const struct in6_addr *addr2,
5491da177e4SLinus Torvalds 				     unsigned int prefixlen)
5501da177e4SLinus Torvalds {
5512ef97332SYOSHIFUJI Hideaki / 吉藤英明 	const __be32 *a1 = addr1->s6_addr32;
5522ef97332SYOSHIFUJI Hideaki / 吉藤英明 	const __be32 *a2 = addr2->s6_addr32;
55395c96174SEric Dumazet 	unsigned int pdw, pbi;
5541da177e4SLinus Torvalds 
5551da177e4SLinus Torvalds 	/* check complete u32 in prefix */
5561da177e4SLinus Torvalds 	pdw = prefixlen >> 5;
5571da177e4SLinus Torvalds 	if (pdw && memcmp(a1, a2, pdw << 2))
55892113bfdSEric Dumazet 		return false;
5591da177e4SLinus Torvalds 
5601da177e4SLinus Torvalds 	/* check incomplete u32 in prefix */
5611da177e4SLinus Torvalds 	pbi = prefixlen & 0x1f;
5621da177e4SLinus Torvalds 	if (pbi && ((a1[pdw] ^ a2[pdw]) & htonl((0xffffffff) << (32 - pbi))))
56392113bfdSEric Dumazet 		return false;
5641da177e4SLinus Torvalds 
56592113bfdSEric Dumazet 	return true;
5661da177e4SLinus Torvalds }
56738675170SYOSHIFUJI Hideaki / 吉藤英明 #endif
5681da177e4SLinus Torvalds 
5692588fe1dSPavel Emelyanov struct inet_frag_queue;
5702588fe1dSPavel Emelyanov 
5710b5ccb2eSPatrick McHardy enum ip6_defrag_users {
5720b5ccb2eSPatrick McHardy 	IP6_DEFRAG_LOCAL_DELIVER,
5730b5ccb2eSPatrick McHardy 	IP6_DEFRAG_CONNTRACK_IN,
5744be929beSAlexey Dobriyan 	__IP6_DEFRAG_CONNTRACK_IN	= IP6_DEFRAG_CONNTRACK_IN + USHRT_MAX,
5750b5ccb2eSPatrick McHardy 	IP6_DEFRAG_CONNTRACK_OUT,
5764be929beSAlexey Dobriyan 	__IP6_DEFRAG_CONNTRACK_OUT	= IP6_DEFRAG_CONNTRACK_OUT + USHRT_MAX,
5778fa9ff68SPatrick McHardy 	IP6_DEFRAG_CONNTRACK_BRIDGE_IN,
5784be929beSAlexey Dobriyan 	__IP6_DEFRAG_CONNTRACK_BRIDGE_IN = IP6_DEFRAG_CONNTRACK_BRIDGE_IN + USHRT_MAX,
5790b5ccb2eSPatrick McHardy };
5800b5ccb2eSPatrick McHardy 
581c6fda282SPavel Emelyanov struct ip6_create_arg {
582c6fda282SPavel Emelyanov 	__be32 id;
5830b5ccb2eSPatrick McHardy 	u32 user;
584b71d1d42SEric Dumazet 	const struct in6_addr *src;
585b71d1d42SEric Dumazet 	const struct in6_addr *dst;
586264640fcSMichal Kubeček 	int iif;
587eec2e618SHannes Frederic Sowa 	u8 ecn;
588c6fda282SPavel Emelyanov };
589c6fda282SPavel Emelyanov 
59036c77782SFlorian Westphal void ip6_frag_init(struct inet_frag_queue *q, const void *a);
59136c77782SFlorian Westphal bool ip6_frag_match(const struct inet_frag_queue *q, const void *a);
592c6fda282SPavel Emelyanov 
593b836c99fSAmerigo Wang /*
594b836c99fSAmerigo Wang  *	Equivalent of ipv4 struct ip
595b836c99fSAmerigo Wang  */
596b836c99fSAmerigo Wang struct frag_queue {
597b836c99fSAmerigo Wang 	struct inet_frag_queue	q;
598b836c99fSAmerigo Wang 
599b836c99fSAmerigo Wang 	__be32			id;		/* fragment id		*/
600b836c99fSAmerigo Wang 	u32			user;
601b836c99fSAmerigo Wang 	struct in6_addr		saddr;
602b836c99fSAmerigo Wang 	struct in6_addr		daddr;
603b836c99fSAmerigo Wang 
604b836c99fSAmerigo Wang 	int			iif;
605b836c99fSAmerigo Wang 	unsigned int		csum;
606b836c99fSAmerigo Wang 	__u16			nhoffset;
607eec2e618SHannes Frederic Sowa 	u8			ecn;
608b836c99fSAmerigo Wang };
609b836c99fSAmerigo Wang 
610b836c99fSAmerigo Wang void ip6_expire_frag_queue(struct net *net, struct frag_queue *fq,
611b836c99fSAmerigo Wang 			   struct inet_frags *frags);
612b836c99fSAmerigo Wang 
61392113bfdSEric Dumazet static inline bool ipv6_addr_any(const struct in6_addr *a)
6141da177e4SLinus Torvalds {
6151a203cb3SEric Dumazet #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
6161a203cb3SEric Dumazet 	const unsigned long *ul = (const unsigned long *)a;
6171a203cb3SEric Dumazet 
6181a203cb3SEric Dumazet 	return (ul[0] | ul[1]) == 0UL;
6191a203cb3SEric Dumazet #else
620a02cec21SEric Dumazet 	return (a->s6_addr32[0] | a->s6_addr32[1] |
621a02cec21SEric Dumazet 		a->s6_addr32[2] | a->s6_addr32[3]) == 0;
6221a203cb3SEric Dumazet #endif
6231da177e4SLinus Torvalds }
6241da177e4SLinus Torvalds 
625ddbe5032SEric Dumazet static inline u32 ipv6_addr_hash(const struct in6_addr *a)
626ddbe5032SEric Dumazet {
627ddbe5032SEric Dumazet #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
628ddbe5032SEric Dumazet 	const unsigned long *ul = (const unsigned long *)a;
629ddbe5032SEric Dumazet 	unsigned long x = ul[0] ^ ul[1];
630ddbe5032SEric Dumazet 
631ddbe5032SEric Dumazet 	return (u32)(x ^ (x >> 32));
632ddbe5032SEric Dumazet #else
633ddbe5032SEric Dumazet 	return (__force u32)(a->s6_addr32[0] ^ a->s6_addr32[1] ^
634ddbe5032SEric Dumazet 			     a->s6_addr32[2] ^ a->s6_addr32[3]);
635ddbe5032SEric Dumazet #endif
636ddbe5032SEric Dumazet }
637ddbe5032SEric Dumazet 
63808dcdbf6SEric Dumazet /* more secured version of ipv6_addr_hash() */
639b50026b5SHannes Frederic Sowa static inline u32 __ipv6_addr_jhash(const struct in6_addr *a, const u32 initval)
64008dcdbf6SEric Dumazet {
64108dcdbf6SEric Dumazet 	u32 v = (__force u32)a->s6_addr32[0] ^ (__force u32)a->s6_addr32[1];
64208dcdbf6SEric Dumazet 
64308dcdbf6SEric Dumazet 	return jhash_3words(v,
64408dcdbf6SEric Dumazet 			    (__force u32)a->s6_addr32[2],
64508dcdbf6SEric Dumazet 			    (__force u32)a->s6_addr32[3],
646b50026b5SHannes Frederic Sowa 			    initval);
64708dcdbf6SEric Dumazet }
64808dcdbf6SEric Dumazet 
64992113bfdSEric Dumazet static inline bool ipv6_addr_loopback(const struct in6_addr *a)
650f630e43aSYOSHIFUJI Hideaki {
651e287656bSYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
6521373a773SJeff Layton 	const __be64 *be = (const __be64 *)a;
653e287656bSYOSHIFUJI Hideaki / 吉藤英明 
6541373a773SJeff Layton 	return (be[0] | (be[1] ^ cpu_to_be64(1))) == 0UL;
655e287656bSYOSHIFUJI Hideaki / 吉藤英明 #else
656a02cec21SEric Dumazet 	return (a->s6_addr32[0] | a->s6_addr32[1] |
6571373a773SJeff Layton 		a->s6_addr32[2] | (a->s6_addr32[3] ^ cpu_to_be32(1))) == 0;
658e287656bSYOSHIFUJI Hideaki / 吉藤英明 #endif
659f630e43aSYOSHIFUJI Hideaki }
660f630e43aSYOSHIFUJI Hideaki 
6611373a773SJeff Layton /*
6621373a773SJeff Layton  * Note that we must __force cast these to unsigned long to make sparse happy,
6631373a773SJeff Layton  * since all of the endian-annotated types are fixed size regardless of arch.
6641373a773SJeff Layton  */
66592113bfdSEric Dumazet static inline bool ipv6_addr_v4mapped(const struct in6_addr *a)
666e773e4faSBrian Haley {
667a04d40b8SYOSHIFUJI Hideaki / 吉藤英明 	return (
668a04d40b8SYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
6691373a773SJeff Layton 		*(unsigned long *)a |
670a04d40b8SYOSHIFUJI Hideaki / 吉藤英明 #else
6711373a773SJeff Layton 		(__force unsigned long)(a->s6_addr32[0] | a->s6_addr32[1]) |
672a04d40b8SYOSHIFUJI Hideaki / 吉藤英明 #endif
6731373a773SJeff Layton 		(__force unsigned long)(a->s6_addr32[2] ^
6741373a773SJeff Layton 					cpu_to_be32(0x0000ffff))) == 0UL;
675e773e4faSBrian Haley }
676e773e4faSBrian Haley 
6771da177e4SLinus Torvalds /*
67899cd07a5SJuha-Matti Tapio  * Check for a RFC 4843 ORCHID address
67999cd07a5SJuha-Matti Tapio  * (Overlay Routable Cryptographic Hash Identifiers)
68099cd07a5SJuha-Matti Tapio  */
68192113bfdSEric Dumazet static inline bool ipv6_addr_orchid(const struct in6_addr *a)
68299cd07a5SJuha-Matti Tapio {
683a02cec21SEric Dumazet 	return (a->s6_addr32[0] & htonl(0xfffffff0)) == htonl(0x20010010);
68499cd07a5SJuha-Matti Tapio }
68599cd07a5SJuha-Matti Tapio 
6865c98631cSLorenzo Colitti static inline bool ipv6_addr_is_multicast(const struct in6_addr *addr)
6875c98631cSLorenzo Colitti {
6885c98631cSLorenzo Colitti 	return (addr->s6_addr32[0] & htonl(0xFF000000)) == htonl(0xFF000000);
6895c98631cSLorenzo Colitti }
6905c98631cSLorenzo Colitti 
691f15364bdSAurélien Charbon static inline void ipv6_addr_set_v4mapped(const __be32 addr,
692f15364bdSAurélien Charbon 					  struct in6_addr *v4mapped)
693f15364bdSAurélien Charbon {
694f15364bdSAurélien Charbon 	ipv6_addr_set(v4mapped,
695f15364bdSAurélien Charbon 			0, 0,
696f15364bdSAurélien Charbon 			htonl(0x0000FFFF),
697f15364bdSAurélien Charbon 			addr);
698f15364bdSAurélien Charbon }
699f15364bdSAurélien Charbon 
70099cd07a5SJuha-Matti Tapio /*
701971f359dSYOSHIFUJI Hideaki  * find the first different bit between two addresses
702971f359dSYOSHIFUJI Hideaki  * length of address must be a multiple of 32bits
703971f359dSYOSHIFUJI Hideaki  */
7049f2e7334SYOSHIFUJI Hideaki / 吉藤英明 static inline int __ipv6_addr_diff32(const void *token1, const void *token2, int addrlen)
705971f359dSYOSHIFUJI Hideaki {
706ef296f56SAl Viro 	const __be32 *a1 = token1, *a2 = token2;
707971f359dSYOSHIFUJI Hideaki 	int i;
708971f359dSYOSHIFUJI Hideaki 
709971f359dSYOSHIFUJI Hideaki 	addrlen >>= 2;
710971f359dSYOSHIFUJI Hideaki 
711971f359dSYOSHIFUJI Hideaki 	for (i = 0; i < addrlen; i++) {
712ef296f56SAl Viro 		__be32 xb = a1[i] ^ a2[i];
713ef296f56SAl Viro 		if (xb)
714d57b8fb8SYOSHIFUJI Hideaki / 吉藤英明 			return i * 32 + 31 - __fls(ntohl(xb));
715971f359dSYOSHIFUJI Hideaki 	}
716971f359dSYOSHIFUJI Hideaki 
717971f359dSYOSHIFUJI Hideaki 	/*
718971f359dSYOSHIFUJI Hideaki 	 *	we should *never* get to this point since that
719971f359dSYOSHIFUJI Hideaki 	 *	would mean the addrs are equal
720971f359dSYOSHIFUJI Hideaki 	 *
721971f359dSYOSHIFUJI Hideaki 	 *	However, we do get to it 8) And exacly, when
722971f359dSYOSHIFUJI Hideaki 	 *	addresses are equal 8)
723971f359dSYOSHIFUJI Hideaki 	 *
724971f359dSYOSHIFUJI Hideaki 	 *	ip route add 1111::/128 via ...
725971f359dSYOSHIFUJI Hideaki 	 *	ip route add 1111::/64 via ...
726971f359dSYOSHIFUJI Hideaki 	 *	and we are here.
727971f359dSYOSHIFUJI Hideaki 	 *
728971f359dSYOSHIFUJI Hideaki 	 *	Ideally, this function should stop comparison
729971f359dSYOSHIFUJI Hideaki 	 *	at prefix length. It does not, but it is still OK,
730971f359dSYOSHIFUJI Hideaki 	 *	if returned value is greater than prefix length.
731971f359dSYOSHIFUJI Hideaki 	 *					--ANK (980803)
732971f359dSYOSHIFUJI Hideaki 	 */
733a02cec21SEric Dumazet 	return addrlen << 5;
734971f359dSYOSHIFUJI Hideaki }
735971f359dSYOSHIFUJI Hideaki 
7369f2e7334SYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
7379f2e7334SYOSHIFUJI Hideaki / 吉藤英明 static inline int __ipv6_addr_diff64(const void *token1, const void *token2, int addrlen)
7389f2e7334SYOSHIFUJI Hideaki / 吉藤英明 {
7399f2e7334SYOSHIFUJI Hideaki / 吉藤英明 	const __be64 *a1 = token1, *a2 = token2;
7409f2e7334SYOSHIFUJI Hideaki / 吉藤英明 	int i;
7419f2e7334SYOSHIFUJI Hideaki / 吉藤英明 
7429f2e7334SYOSHIFUJI Hideaki / 吉藤英明 	addrlen >>= 3;
7439f2e7334SYOSHIFUJI Hideaki / 吉藤英明 
7449f2e7334SYOSHIFUJI Hideaki / 吉藤英明 	for (i = 0; i < addrlen; i++) {
7459f2e7334SYOSHIFUJI Hideaki / 吉藤英明 		__be64 xb = a1[i] ^ a2[i];
7469f2e7334SYOSHIFUJI Hideaki / 吉藤英明 		if (xb)
7479f2e7334SYOSHIFUJI Hideaki / 吉藤英明 			return i * 64 + 63 - __fls(be64_to_cpu(xb));
7489f2e7334SYOSHIFUJI Hideaki / 吉藤英明 	}
7499f2e7334SYOSHIFUJI Hideaki / 吉藤英明 
7509f2e7334SYOSHIFUJI Hideaki / 吉藤英明 	return addrlen << 6;
7519f2e7334SYOSHIFUJI Hideaki / 吉藤英明 }
7529f2e7334SYOSHIFUJI Hideaki / 吉藤英明 #endif
7539f2e7334SYOSHIFUJI Hideaki / 吉藤英明 
7549f2e7334SYOSHIFUJI Hideaki / 吉藤英明 static inline int __ipv6_addr_diff(const void *token1, const void *token2, int addrlen)
7559f2e7334SYOSHIFUJI Hideaki / 吉藤英明 {
7569f2e7334SYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
7579f2e7334SYOSHIFUJI Hideaki / 吉藤英明 	if (__builtin_constant_p(addrlen) && !(addrlen & 7))
7589f2e7334SYOSHIFUJI Hideaki / 吉藤英明 		return __ipv6_addr_diff64(token1, token2, addrlen);
7599f2e7334SYOSHIFUJI Hideaki / 吉藤英明 #endif
7609f2e7334SYOSHIFUJI Hideaki / 吉藤英明 	return __ipv6_addr_diff32(token1, token2, addrlen);
7619f2e7334SYOSHIFUJI Hideaki / 吉藤英明 }
7629f2e7334SYOSHIFUJI Hideaki / 吉藤英明 
763971f359dSYOSHIFUJI Hideaki static inline int ipv6_addr_diff(const struct in6_addr *a1, const struct in6_addr *a2)
764971f359dSYOSHIFUJI Hideaki {
765971f359dSYOSHIFUJI Hideaki 	return __ipv6_addr_diff(a1, a2, sizeof(struct in6_addr));
766971f359dSYOSHIFUJI Hideaki }
767971f359dSYOSHIFUJI Hideaki 
7687f159867SEric Dumazet __be32 ipv6_select_ident(struct net *net,
769fd0273d7SMartin KaFai Lau 			 const struct in6_addr *daddr,
770fd0273d7SMartin KaFai Lau 			 const struct in6_addr *saddr);
7710c19f846SWillem de Bruijn __be32 ipv6_proxy_select_ident(struct net *net, struct sk_buff *skb);
7725188cd44SBen Hutchings 
7735c3a0fd7SJoe Perches int ip6_dst_hoplimit(struct dst_entry *dst);
7743ce9b35fSCong Wang 
7755c98631cSLorenzo Colitti static inline int ip6_sk_dst_hoplimit(struct ipv6_pinfo *np, struct flowi6 *fl6,
7765c98631cSLorenzo Colitti 				      struct dst_entry *dst)
7775c98631cSLorenzo Colitti {
7785c98631cSLorenzo Colitti 	int hlimit;
7795c98631cSLorenzo Colitti 
7805c98631cSLorenzo Colitti 	if (ipv6_addr_is_multicast(&fl6->daddr))
7815c98631cSLorenzo Colitti 		hlimit = np->mcast_hops;
7825c98631cSLorenzo Colitti 	else
7835c98631cSLorenzo Colitti 		hlimit = np->hop_limit;
7845c98631cSLorenzo Colitti 	if (hlimit < 0)
7855c98631cSLorenzo Colitti 		hlimit = ip6_dst_hoplimit(dst);
7865c98631cSLorenzo Colitti 	return hlimit;
7875c98631cSLorenzo Colitti }
7885c98631cSLorenzo Colitti 
789c3f83241STom Herbert /* copy IPv6 saddr & daddr to flow_keys, possibly using 64bit load/store
790c3f83241STom Herbert  * Equivalent to :	flow->v6addrs.src = iph->saddr;
791c3f83241STom Herbert  *			flow->v6addrs.dst = iph->daddr;
792c3f83241STom Herbert  */
793c3f83241STom Herbert static inline void iph_to_flow_copy_v6addrs(struct flow_keys *flow,
794c3f83241STom Herbert 					    const struct ipv6hdr *iph)
795c3f83241STom Herbert {
796c3f83241STom Herbert 	BUILD_BUG_ON(offsetof(typeof(flow->addrs), v6addrs.dst) !=
797c3f83241STom Herbert 		     offsetof(typeof(flow->addrs), v6addrs.src) +
798c3f83241STom Herbert 		     sizeof(flow->addrs.v6addrs.src));
799c3f83241STom Herbert 	memcpy(&flow->addrs.v6addrs, &iph->saddr, sizeof(flow->addrs.v6addrs));
800c3f83241STom Herbert 	flow->control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
801c3f83241STom Herbert }
802c3f83241STom Herbert 
803a37934fcSFlorian Fainelli #if IS_ENABLED(CONFIG_IPV6)
80442240901STom Herbert 
80542240901STom Herbert /* Sysctl settings for net ipv6.auto_flowlabels */
80642240901STom Herbert #define IP6_AUTO_FLOW_LABEL_OFF		0
80742240901STom Herbert #define IP6_AUTO_FLOW_LABEL_OPTOUT	1
80842240901STom Herbert #define IP6_AUTO_FLOW_LABEL_OPTIN	2
80942240901STom Herbert #define IP6_AUTO_FLOW_LABEL_FORCED	3
81042240901STom Herbert 
81142240901STom Herbert #define IP6_AUTO_FLOW_LABEL_MAX		IP6_AUTO_FLOW_LABEL_FORCED
81242240901STom Herbert 
813b5677416STom Herbert #define IP6_DEFAULT_AUTO_FLOW_LABELS	IP6_AUTO_FLOW_LABEL_OPTOUT
81442240901STom Herbert 
815cb1ce2efSTom Herbert static inline __be32 ip6_make_flowlabel(struct net *net, struct sk_buff *skb,
81667800f9bSTom Herbert 					__be32 flowlabel, bool autolabel,
81767800f9bSTom Herbert 					struct flowi6 *fl6)
818cb1ce2efSTom Herbert {
81967765146SEric Dumazet 	u32 hash;
820cb1ce2efSTom Herbert 
82190427ef5SDimitris Michailidis 	/* @flowlabel may include more than a flow label, eg, the traffic class.
82290427ef5SDimitris Michailidis 	 * Here we want only the flow label value.
82390427ef5SDimitris Michailidis 	 */
82490427ef5SDimitris Michailidis 	flowlabel &= IPV6_FLOWLABEL_MASK;
82590427ef5SDimitris Michailidis 
82642240901STom Herbert 	if (flowlabel ||
82742240901STom Herbert 	    net->ipv6.sysctl.auto_flowlabels == IP6_AUTO_FLOW_LABEL_OFF ||
82842240901STom Herbert 	    (!autolabel &&
82942240901STom Herbert 	     net->ipv6.sysctl.auto_flowlabels != IP6_AUTO_FLOW_LABEL_FORCED))
83042240901STom Herbert 		return flowlabel;
83142240901STom Herbert 
83267800f9bSTom Herbert 	hash = skb_get_hash_flowi6(skb, fl6);
833cb1ce2efSTom Herbert 
834cb1ce2efSTom Herbert 	/* Since this is being sent on the wire obfuscate hash a bit
835cb1ce2efSTom Herbert 	 * to minimize possbility that any useful information to an
836cb1ce2efSTom Herbert 	 * attacker is leaked. Only lower 20 bits are relevant.
837cb1ce2efSTom Herbert 	 */
83842240901STom Herbert 	rol32(hash, 16);
839cb1ce2efSTom Herbert 
84067765146SEric Dumazet 	flowlabel = (__force __be32)hash & IPV6_FLOWLABEL_MASK;
84182a584b7STom Herbert 
84282a584b7STom Herbert 	if (net->ipv6.sysctl.flowlabel_state_ranges)
84382a584b7STom Herbert 		flowlabel |= IPV6_FLOWLABEL_STATELESS_FLAG;
844cb1ce2efSTom Herbert 
845cb1ce2efSTom Herbert 	return flowlabel;
846cb1ce2efSTom Herbert }
84742240901STom Herbert 
84842240901STom Herbert static inline int ip6_default_np_autolabel(struct net *net)
84942240901STom Herbert {
85042240901STom Herbert 	switch (net->ipv6.sysctl.auto_flowlabels) {
85142240901STom Herbert 	case IP6_AUTO_FLOW_LABEL_OFF:
85242240901STom Herbert 	case IP6_AUTO_FLOW_LABEL_OPTIN:
85342240901STom Herbert 	default:
85442240901STom Herbert 		return 0;
85542240901STom Herbert 	case IP6_AUTO_FLOW_LABEL_OPTOUT:
85642240901STom Herbert 	case IP6_AUTO_FLOW_LABEL_FORCED:
85742240901STom Herbert 		return 1;
85842240901STom Herbert 	}
85942240901STom Herbert }
860a37934fcSFlorian Fainelli #else
861a37934fcSFlorian Fainelli static inline void ip6_set_txhash(struct sock *sk) { }
862a37934fcSFlorian Fainelli static inline __be32 ip6_make_flowlabel(struct net *net, struct sk_buff *skb,
86342240901STom Herbert 					__be32 flowlabel, bool autolabel,
86442240901STom Herbert 					struct flowi6 *fl6)
865a37934fcSFlorian Fainelli {
866a37934fcSFlorian Fainelli 	return flowlabel;
867a37934fcSFlorian Fainelli }
86842240901STom Herbert static inline int ip6_default_np_autolabel(struct net *net)
86942240901STom Herbert {
87042240901STom Herbert 	return 0;
87142240901STom Herbert }
872a37934fcSFlorian Fainelli #endif
873a37934fcSFlorian Fainelli 
874cb1ce2efSTom Herbert 
875971f359dSYOSHIFUJI Hideaki /*
8763e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明  *	Header manipulation
8773e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明  */
8783e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 static inline void ip6_flow_hdr(struct ipv6hdr *hdr, unsigned int tclass,
8793e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 				__be32 flowlabel)
8803e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 {
88107f623d3SYOSHIFUJI Hideaki 	*(__be32 *)hdr = htonl(0x60000000 | (tclass << 20)) | flowlabel;
8823e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 }
8833e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 
8846502ca52SYOSHIFUJI Hideaki / 吉藤英明 static inline __be32 ip6_flowinfo(const struct ipv6hdr *hdr)
8856502ca52SYOSHIFUJI Hideaki / 吉藤英明 {
8866502ca52SYOSHIFUJI Hideaki / 吉藤英明 	return *(__be32 *)hdr & IPV6_FLOWINFO_MASK;
8876502ca52SYOSHIFUJI Hideaki / 吉藤英明 }
8886502ca52SYOSHIFUJI Hideaki / 吉藤英明 
8893308de2bSFlorent Fourcot static inline __be32 ip6_flowlabel(const struct ipv6hdr *hdr)
8903308de2bSFlorent Fourcot {
8913308de2bSFlorent Fourcot 	return *(__be32 *)hdr & IPV6_FLOWLABEL_MASK;
8923308de2bSFlorent Fourcot }
8933308de2bSFlorent Fourcot 
894d76ed22bSLi RongQing static inline u8 ip6_tclass(__be32 flowinfo)
895d76ed22bSLi RongQing {
896d76ed22bSLi RongQing 	return ntohl(flowinfo & IPV6_TCLASS_MASK) >> IPV6_TCLASS_SHIFT;
897d76ed22bSLi RongQing }
898eaa93bf4SDaniel Borkmann 
899eaa93bf4SDaniel Borkmann static inline __be32 ip6_make_flowinfo(unsigned int tclass, __be32 flowlabel)
900eaa93bf4SDaniel Borkmann {
901eaa93bf4SDaniel Borkmann 	return htonl(tclass << IPV6_TCLASS_SHIFT) | flowlabel;
902eaa93bf4SDaniel Borkmann }
903eaa93bf4SDaniel Borkmann 
9043e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 /*
9051da177e4SLinus Torvalds  *	Prototypes exported by ipv6
9061da177e4SLinus Torvalds  */
9071da177e4SLinus Torvalds 
9081da177e4SLinus Torvalds /*
9091da177e4SLinus Torvalds  *	rcv function (called from netdevice level)
9101da177e4SLinus Torvalds  */
9111da177e4SLinus Torvalds 
9125c3a0fd7SJoe Perches int ipv6_rcv(struct sk_buff *skb, struct net_device *dev,
9135c3a0fd7SJoe Perches 	     struct packet_type *pt, struct net_device *orig_dev);
9141da177e4SLinus Torvalds 
9150c4b51f0SEric W. Biederman int ip6_rcv_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
916b05e1066SPatrick McHardy 
9171da177e4SLinus Torvalds /*
9181da177e4SLinus Torvalds  *	upper-layer output functions
9191da177e4SLinus Torvalds  */
9201c1e9d2bSEric Dumazet int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6,
92192e55f41SPablo Neira 	     __u32 mark, struct ipv6_txoptions *opt, int tclass);
9221da177e4SLinus Torvalds 
9235c3a0fd7SJoe Perches int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr);
9241da177e4SLinus Torvalds 
9255c3a0fd7SJoe Perches int ip6_append_data(struct sock *sk,
9265c3a0fd7SJoe Perches 		    int getfrag(void *from, char *to, int offset, int len,
9275c3a0fd7SJoe Perches 				int odd, struct sk_buff *skb),
92826879da5SWei Wang 		    void *from, int length, int transhdrlen,
92926879da5SWei Wang 		    struct ipcm6_cookie *ipc6, struct flowi6 *fl6,
93026879da5SWei Wang 		    struct rt6_info *rt, unsigned int flags,
931c14ac945SSoheil Hassas Yeganeh 		    const struct sockcm_cookie *sockc);
9321da177e4SLinus Torvalds 
9335c3a0fd7SJoe Perches int ip6_push_pending_frames(struct sock *sk);
9341da177e4SLinus Torvalds 
9355c3a0fd7SJoe Perches void ip6_flush_pending_frames(struct sock *sk);
9361da177e4SLinus Torvalds 
9376422398cSVlad Yasevich int ip6_send_skb(struct sk_buff *skb);
9386422398cSVlad Yasevich 
9396422398cSVlad Yasevich struct sk_buff *__ip6_make_skb(struct sock *sk, struct sk_buff_head *queue,
9406422398cSVlad Yasevich 			       struct inet_cork_full *cork,
9416422398cSVlad Yasevich 			       struct inet6_cork *v6_cork);
9426422398cSVlad Yasevich struct sk_buff *ip6_make_skb(struct sock *sk,
9436422398cSVlad Yasevich 			     int getfrag(void *from, char *to, int offset,
9446422398cSVlad Yasevich 					 int len, int odd, struct sk_buff *skb),
9456422398cSVlad Yasevich 			     void *from, int length, int transhdrlen,
94626879da5SWei Wang 			     struct ipcm6_cookie *ipc6, struct flowi6 *fl6,
94726879da5SWei Wang 			     struct rt6_info *rt, unsigned int flags,
948c14ac945SSoheil Hassas Yeganeh 			     const struct sockcm_cookie *sockc);
9496422398cSVlad Yasevich 
9506422398cSVlad Yasevich static inline struct sk_buff *ip6_finish_skb(struct sock *sk)
9516422398cSVlad Yasevich {
9526422398cSVlad Yasevich 	return __ip6_make_skb(sk, &sk->sk_write_queue, &inet_sk(sk)->cork,
9536422398cSVlad Yasevich 			      &inet6_sk(sk)->cork);
9546422398cSVlad Yasevich }
9556422398cSVlad Yasevich 
956343d60aaSRoopa Prabhu int ip6_dst_lookup(struct net *net, struct sock *sk, struct dst_entry **dst,
957343d60aaSRoopa Prabhu 		   struct flowi6 *fl6);
9583aef934fSEric Dumazet struct dst_entry *ip6_dst_lookup_flow(const struct sock *sk, struct flowi6 *fl6,
9590e0d44abSSteffen Klassert 				      const struct in6_addr *final_dst);
9605c3a0fd7SJoe Perches struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
9610e0d44abSSteffen Klassert 					 const struct in6_addr *final_dst);
9625c3a0fd7SJoe Perches struct dst_entry *ip6_blackhole_route(struct net *net,
96369ead7afSDavid S. Miller 				      struct dst_entry *orig_dst);
9641da177e4SLinus Torvalds 
9651da177e4SLinus Torvalds /*
9661da177e4SLinus Torvalds  *	skb processing functions
9671da177e4SLinus Torvalds  */
9681da177e4SLinus Torvalds 
969ede2059dSEric W. Biederman int ip6_output(struct net *net, struct sock *sk, struct sk_buff *skb);
9705c3a0fd7SJoe Perches int ip6_forward(struct sk_buff *skb);
9715c3a0fd7SJoe Perches int ip6_input(struct sk_buff *skb);
9725c3a0fd7SJoe Perches int ip6_mc_input(struct sk_buff *skb);
9731da177e4SLinus Torvalds 
974cf91a99dSEric W. Biederman int __ip6_local_out(struct net *net, struct sock *sk, struct sk_buff *skb);
97533224b16SEric W. Biederman int ip6_local_out(struct net *net, struct sock *sk, struct sk_buff *skb);
976ef76bc23SHerbert Xu 
9771da177e4SLinus Torvalds /*
9781da177e4SLinus Torvalds  *	Extension header (options) processing
9791da177e4SLinus Torvalds  */
9801da177e4SLinus Torvalds 
9815c3a0fd7SJoe Perches void ipv6_push_nfrag_opts(struct sk_buff *skb, struct ipv6_txoptions *opt,
982613fa3caSDavid Lebrun 			  u8 *proto, struct in6_addr **daddr_p,
983613fa3caSDavid Lebrun 			  struct in6_addr *saddr);
9845c3a0fd7SJoe Perches void ipv6_push_frag_opts(struct sk_buff *skb, struct ipv6_txoptions *opt,
9851da177e4SLinus Torvalds 			 u8 *proto);
9861da177e4SLinus Torvalds 
9875c3a0fd7SJoe Perches int ipv6_skip_exthdr(const struct sk_buff *, int start, u8 *nexthdrp,
9885c3a0fd7SJoe Perches 		     __be16 *frag_offp);
9891da177e4SLinus Torvalds 
9905c3a0fd7SJoe Perches bool ipv6_ext_hdr(u8 nexthdr);
9911da177e4SLinus Torvalds 
992f8f62675SJesse Gross enum {
993f8f62675SJesse Gross 	IP6_FH_F_FRAG		= (1 << 0),
994f8f62675SJesse Gross 	IP6_FH_F_AUTH		= (1 << 1),
9959195bb8eSAnsis Atteka 	IP6_FH_F_SKIP_RH	= (1 << 2),
996f8f62675SJesse Gross };
997f8f62675SJesse Gross 
998f8f62675SJesse Gross /* find specified header and get offset to it */
9995c3a0fd7SJoe Perches int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset, int target,
10005c3a0fd7SJoe Perches 		  unsigned short *fragoff, int *fragflg);
1001f8f62675SJesse Gross 
10020868383bSHuw Davies int ipv6_find_tlv(const struct sk_buff *skb, int offset, int type);
1003c61a4043SMasahide NAKAMURA 
10045c3a0fd7SJoe Perches struct in6_addr *fl6_update_dst(struct flowi6 *fl6,
100520c59de2SArnaud Ebalard 				const struct ipv6_txoptions *opt,
100620c59de2SArnaud Ebalard 				struct in6_addr *orig);
100720c59de2SArnaud Ebalard 
10081da177e4SLinus Torvalds /*
10091da177e4SLinus Torvalds  *	socket options (ipv6_sockglue.c)
10101da177e4SLinus Torvalds  */
10111da177e4SLinus Torvalds 
10125c3a0fd7SJoe Perches int ipv6_setsockopt(struct sock *sk, int level, int optname,
10135c3a0fd7SJoe Perches 		    char __user *optval, unsigned int optlen);
10145c3a0fd7SJoe Perches int ipv6_getsockopt(struct sock *sk, int level, int optname,
10155c3a0fd7SJoe Perches 		    char __user *optval, int __user *optlen);
10165c3a0fd7SJoe Perches int compat_ipv6_setsockopt(struct sock *sk, int level, int optname,
10175c3a0fd7SJoe Perches 			   char __user *optval, unsigned int optlen);
10185c3a0fd7SJoe Perches int compat_ipv6_getsockopt(struct sock *sk, int level, int optname,
10195c3a0fd7SJoe Perches 			   char __user *optval, int __user *optlen);
10201da177e4SLinus Torvalds 
10210382a25aSGuillaume Nault int __ip6_datagram_connect(struct sock *sk, struct sockaddr *addr,
10220382a25aSGuillaume Nault 			   int addr_len);
10235c3a0fd7SJoe Perches int ip6_datagram_connect(struct sock *sk, struct sockaddr *addr, int addr_len);
102482b276cdSHannes Frederic Sowa int ip6_datagram_connect_v6_only(struct sock *sk, struct sockaddr *addr,
102582b276cdSHannes Frederic Sowa 				 int addr_len);
102633c162a9SMartin KaFai Lau int ip6_datagram_dst_update(struct sock *sk, bool fix_sk_saddr);
1027e646b657SMartin KaFai Lau void ip6_datagram_release_cb(struct sock *sk);
10281da177e4SLinus Torvalds 
102985fbaa75SHannes Frederic Sowa int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len,
103085fbaa75SHannes Frederic Sowa 		    int *addr_len);
103185fbaa75SHannes Frederic Sowa int ipv6_recv_rxpmtu(struct sock *sk, struct msghdr *msg, int len,
103285fbaa75SHannes Frederic Sowa 		     int *addr_len);
10335c3a0fd7SJoe Perches void ipv6_icmp_error(struct sock *sk, struct sk_buff *skb, int err, __be16 port,
10341da177e4SLinus Torvalds 		     u32 info, u8 *payload);
10355c3a0fd7SJoe Perches void ipv6_local_error(struct sock *sk, int err, struct flowi6 *fl6, u32 info);
10365c3a0fd7SJoe Perches void ipv6_local_rxpmtu(struct sock *sk, struct flowi6 *fl6, u32 mtu);
10371da177e4SLinus Torvalds 
10385c3a0fd7SJoe Perches int inet6_release(struct socket *sock);
10395c3a0fd7SJoe Perches int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len);
10405c3a0fd7SJoe Perches int inet6_getname(struct socket *sock, struct sockaddr *uaddr, int *uaddr_len,
10415c3a0fd7SJoe Perches 		  int peer);
10425c3a0fd7SJoe Perches int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
10431da177e4SLinus Torvalds 
10445c3a0fd7SJoe Perches int inet6_hash_connect(struct inet_timewait_death_row *death_row,
1045d8313f5cSArnaldo Carvalho de Melo 			      struct sock *sk);
1046d8313f5cSArnaldo Carvalho de Melo 
10471da177e4SLinus Torvalds /*
10481da177e4SLinus Torvalds  * reassembly.c
10491da177e4SLinus Torvalds  */
105090ddc4f0SEric Dumazet extern const struct proto_ops inet6_stream_ops;
105190ddc4f0SEric Dumazet extern const struct proto_ops inet6_dgram_ops;
105277d4b1d3SEric Dumazet extern const struct proto_ops inet6_sockraw_ops;
105320380731SArnaldo Carvalho de Melo 
105414c85021SArnaldo Carvalho de Melo struct group_source_req;
105514c85021SArnaldo Carvalho de Melo struct group_filter;
105614c85021SArnaldo Carvalho de Melo 
10575c3a0fd7SJoe Perches int ip6_mc_source(int add, int omode, struct sock *sk,
105820380731SArnaldo Carvalho de Melo 		  struct group_source_req *pgsr);
10595c3a0fd7SJoe Perches int ip6_mc_msfilter(struct sock *sk, struct group_filter *gsf);
10605c3a0fd7SJoe Perches int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf,
10615c3a0fd7SJoe Perches 		  struct group_filter __user *optval, int __user *optlen);
106220380731SArnaldo Carvalho de Melo 
106320380731SArnaldo Carvalho de Melo #ifdef CONFIG_PROC_FS
10645c3a0fd7SJoe Perches int ac6_proc_init(struct net *net);
10655c3a0fd7SJoe Perches void ac6_proc_exit(struct net *net);
10665c3a0fd7SJoe Perches int raw6_proc_init(void);
10675c3a0fd7SJoe Perches void raw6_proc_exit(void);
10685c3a0fd7SJoe Perches int tcp6_proc_init(struct net *net);
10695c3a0fd7SJoe Perches void tcp6_proc_exit(struct net *net);
10705c3a0fd7SJoe Perches int udp6_proc_init(struct net *net);
10715c3a0fd7SJoe Perches void udp6_proc_exit(struct net *net);
10725c3a0fd7SJoe Perches int udplite6_proc_init(void);
10735c3a0fd7SJoe Perches void udplite6_proc_exit(void);
10745c3a0fd7SJoe Perches int ipv6_misc_proc_init(void);
10755c3a0fd7SJoe Perches void ipv6_misc_proc_exit(void);
10765c3a0fd7SJoe Perches int snmp6_register_dev(struct inet6_dev *idev);
10775c3a0fd7SJoe Perches int snmp6_unregister_dev(struct inet6_dev *idev);
107820380731SArnaldo Carvalho de Melo 
10797f7d9a6bSHerbert Xu #else
10806ab57e7eSDaniel Lezcano static inline int ac6_proc_init(struct net *net) { return 0; }
10816ab57e7eSDaniel Lezcano static inline void ac6_proc_exit(struct net *net) { }
10826ab57e7eSDaniel Lezcano static inline int snmp6_register_dev(struct inet6_dev *idev) { return 0; }
10836ab57e7eSDaniel Lezcano static inline int snmp6_unregister_dev(struct inet6_dev *idev) { return 0; }
108420380731SArnaldo Carvalho de Melo #endif
108520380731SArnaldo Carvalho de Melo 
108620380731SArnaldo Carvalho de Melo #ifdef CONFIG_SYSCTL
10879e8cda3bSJoe Perches extern struct ctl_table ipv6_route_table_template[];
108820380731SArnaldo Carvalho de Melo 
10895c3a0fd7SJoe Perches struct ctl_table *ipv6_icmp_sysctl_init(struct net *net);
10905c3a0fd7SJoe Perches struct ctl_table *ipv6_route_sysctl_init(struct net *net);
10915c3a0fd7SJoe Perches int ipv6_sysctl_register(void);
10925c3a0fd7SJoe Perches void ipv6_sysctl_unregister(void);
109320380731SArnaldo Carvalho de Melo #endif
109420380731SArnaldo Carvalho de Melo 
109546a4dee0SMadhu Challa int ipv6_sock_mc_join(struct sock *sk, int ifindex,
109646a4dee0SMadhu Challa 		      const struct in6_addr *addr);
109746a4dee0SMadhu Challa int ipv6_sock_mc_drop(struct sock *sk, int ifindex,
109846a4dee0SMadhu Challa 		      const struct in6_addr *addr);
10991da177e4SLinus Torvalds #endif /* _NET_IPV6_H */
1100