xref: /linux-6.15/include/net/ipv6.h (revision d4915c08)
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>
1820283d84SHerbert Xu #include <net/if_inet6.h>
191da177e4SLinus Torvalds #include <net/ndisc.h>
201da177e4SLinus Torvalds #include <net/flow.h>
211da177e4SLinus Torvalds #include <net/snmp.h>
221da177e4SLinus Torvalds 
231da177e4SLinus Torvalds #define SIN6_LEN_RFC2133	24
241da177e4SLinus Torvalds 
251da177e4SLinus Torvalds #define IPV6_MAXPLEN		65535
261da177e4SLinus Torvalds 
271da177e4SLinus Torvalds /*
281da177e4SLinus Torvalds  *	NextHeader field of IPv6 header
291da177e4SLinus Torvalds  */
301da177e4SLinus Torvalds 
311da177e4SLinus Torvalds #define NEXTHDR_HOP		0	/* Hop-by-hop option header. */
321da177e4SLinus Torvalds #define NEXTHDR_TCP		6	/* TCP segment. */
331da177e4SLinus Torvalds #define NEXTHDR_UDP		17	/* UDP message. */
341da177e4SLinus Torvalds #define NEXTHDR_IPV6		41	/* IPv6 in IPv6 */
351da177e4SLinus Torvalds #define NEXTHDR_ROUTING		43	/* Routing header. */
361da177e4SLinus Torvalds #define NEXTHDR_FRAGMENT	44	/* Fragmentation/reassembly header. */
37c12b395aS[email protected] #define NEXTHDR_GRE		47	/* GRE header. */
381da177e4SLinus Torvalds #define NEXTHDR_ESP		50	/* Encapsulating security payload. */
391da177e4SLinus Torvalds #define NEXTHDR_AUTH		51	/* Authentication header. */
401da177e4SLinus Torvalds #define NEXTHDR_ICMP		58	/* ICMP for IPv6. */
411da177e4SLinus Torvalds #define NEXTHDR_NONE		59	/* No next header */
421da177e4SLinus Torvalds #define NEXTHDR_DEST		60	/* Destination options header. */
432b741653SMasahide NAKAMURA #define NEXTHDR_MOBILITY	135	/* Mobility header. */
441da177e4SLinus Torvalds 
451da177e4SLinus Torvalds #define NEXTHDR_MAX		255
461da177e4SLinus Torvalds 
471da177e4SLinus Torvalds 
481da177e4SLinus Torvalds 
491da177e4SLinus Torvalds #define IPV6_DEFAULT_HOPLIMIT   64
501da177e4SLinus Torvalds #define IPV6_DEFAULT_MCASTHOPS	1
511da177e4SLinus Torvalds 
521da177e4SLinus Torvalds /*
531da177e4SLinus Torvalds  *	Addr type
541da177e4SLinus Torvalds  *
551da177e4SLinus Torvalds  *	type	-	unicast | multicast
561da177e4SLinus Torvalds  *	scope	-	local	| site	    | global
571da177e4SLinus Torvalds  *	v4	-	compat
581da177e4SLinus Torvalds  *	v4mapped
591da177e4SLinus Torvalds  *	any
601da177e4SLinus Torvalds  *	loopback
611da177e4SLinus Torvalds  */
621da177e4SLinus Torvalds 
631da177e4SLinus Torvalds #define IPV6_ADDR_ANY		0x0000U
641da177e4SLinus Torvalds 
651da177e4SLinus Torvalds #define IPV6_ADDR_UNICAST      	0x0001U
661da177e4SLinus Torvalds #define IPV6_ADDR_MULTICAST    	0x0002U
671da177e4SLinus Torvalds 
681da177e4SLinus Torvalds #define IPV6_ADDR_LOOPBACK	0x0010U
691da177e4SLinus Torvalds #define IPV6_ADDR_LINKLOCAL	0x0020U
701da177e4SLinus Torvalds #define IPV6_ADDR_SITELOCAL	0x0040U
711da177e4SLinus Torvalds 
721da177e4SLinus Torvalds #define IPV6_ADDR_COMPATv4	0x0080U
731da177e4SLinus Torvalds 
741da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_MASK	0x00f0U
751da177e4SLinus Torvalds 
761da177e4SLinus Torvalds #define IPV6_ADDR_MAPPED	0x1000U
771da177e4SLinus Torvalds 
781da177e4SLinus Torvalds /*
791da177e4SLinus Torvalds  *	Addr scopes
801da177e4SLinus Torvalds  */
811da177e4SLinus Torvalds #define IPV6_ADDR_MC_SCOPE(a)	\
821da177e4SLinus Torvalds 	((a)->s6_addr[1] & 0x0f)	/* nonstandard */
831da177e4SLinus Torvalds #define __IPV6_ADDR_SCOPE_INVALID	-1
841da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_NODELOCAL	0x01
851da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_LINKLOCAL	0x02
861da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_SITELOCAL	0x05
871da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_ORGLOCAL	0x08
881da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_GLOBAL		0x0e
891da177e4SLinus Torvalds 
901da177e4SLinus Torvalds /*
915ced1339SLinus Lüssing  *	Addr flags
925ced1339SLinus Lüssing  */
935ced1339SLinus Lüssing #define IPV6_ADDR_MC_FLAG_TRANSIENT(a)	\
945ced1339SLinus Lüssing 	((a)->s6_addr[1] & 0x10)
955ced1339SLinus Lüssing #define IPV6_ADDR_MC_FLAG_PREFIX(a)	\
965ced1339SLinus Lüssing 	((a)->s6_addr[1] & 0x20)
975ced1339SLinus Lüssing #define IPV6_ADDR_MC_FLAG_RENDEZVOUS(a)	\
985ced1339SLinus Lüssing 	((a)->s6_addr[1] & 0x40)
995ced1339SLinus Lüssing 
1005ced1339SLinus Lüssing /*
1011da177e4SLinus Torvalds  *	fragmentation header
1021da177e4SLinus Torvalds  */
1031da177e4SLinus Torvalds 
1041da177e4SLinus Torvalds struct frag_hdr {
10544473a6bSAl Viro 	__u8	nexthdr;
10644473a6bSAl Viro 	__u8	reserved;
10744473a6bSAl Viro 	__be16	frag_off;
10844473a6bSAl Viro 	__be32	identification;
1091da177e4SLinus Torvalds };
1101da177e4SLinus Torvalds 
1111da177e4SLinus Torvalds #define	IP6_MF	0x0001
1121da177e4SLinus Torvalds 
1131da177e4SLinus Torvalds #include <net/sock.h>
1141da177e4SLinus Torvalds 
1151da177e4SLinus Torvalds /* sysctls */
1161da177e4SLinus Torvalds extern int sysctl_mld_max_msf;
1173d7cc2baSPavel Emelyanov 
118087fe240SDenis V. Lunev #define _DEVINC(net, statname, modifier, idev, field)			\
11914878f75SDavid L Stevens ({									\
12014878f75SDavid L Stevens 	struct inet6_dev *_idev = (idev);				\
12114878f75SDavid L Stevens 	if (likely(_idev != NULL))					\
12214878f75SDavid L Stevens 		SNMP_INC_STATS##modifier((_idev)->stats.statname, (field)); \
1239261e537SDenis V. Lunev 	SNMP_INC_STATS##modifier((net)->mib.statname##_statistics, (field));\
12414878f75SDavid L Stevens })
12514878f75SDavid L Stevens 
126be281e55SEric Dumazet /* per device counters are atomic_long_t */
127be281e55SEric Dumazet #define _DEVINCATOMIC(net, statname, modifier, idev, field)		\
128be281e55SEric Dumazet ({									\
129be281e55SEric Dumazet 	struct inet6_dev *_idev = (idev);				\
130be281e55SEric Dumazet 	if (likely(_idev != NULL))					\
131be281e55SEric Dumazet 		SNMP_INC_STATS_ATOMIC_LONG((_idev)->stats.statname##dev, (field)); \
132be281e55SEric Dumazet 	SNMP_INC_STATS##modifier((net)->mib.statname##_statistics, (field));\
133be281e55SEric Dumazet })
134be281e55SEric Dumazet 
1352a24444fSEric Dumazet /* per device and per net counters are atomic_long_t */
1362a24444fSEric Dumazet #define _DEVINC_ATOMIC_ATOMIC(net, statname, idev, field)		\
1372a24444fSEric Dumazet ({									\
1382a24444fSEric Dumazet 	struct inet6_dev *_idev = (idev);				\
1392a24444fSEric Dumazet 	if (likely(_idev != NULL))					\
1402a24444fSEric Dumazet 		SNMP_INC_STATS_ATOMIC_LONG((_idev)->stats.statname##dev, (field)); \
1412a24444fSEric Dumazet 	SNMP_INC_STATS_ATOMIC_LONG((net)->mib.statname##_statistics, (field));\
1422a24444fSEric Dumazet })
1432a24444fSEric Dumazet 
144087fe240SDenis V. Lunev #define _DEVADD(net, statname, modifier, idev, field, val)		\
1458e7999c4SPavel Emelyanov ({									\
1468e7999c4SPavel Emelyanov 	struct inet6_dev *_idev = (idev);				\
1478e7999c4SPavel Emelyanov 	if (likely(_idev != NULL))					\
1488e7999c4SPavel Emelyanov 		SNMP_ADD_STATS##modifier((_idev)->stats.statname, (field), (val)); \
1499261e537SDenis V. Lunev 	SNMP_ADD_STATS##modifier((net)->mib.statname##_statistics, (field), (val));\
1508e7999c4SPavel Emelyanov })
1518e7999c4SPavel Emelyanov 
152edf391ffSNeil Horman #define _DEVUPD(net, statname, modifier, idev, field, val)		\
153edf391ffSNeil Horman ({									\
154edf391ffSNeil Horman 	struct inet6_dev *_idev = (idev);				\
155edf391ffSNeil Horman 	if (likely(_idev != NULL))					\
156edf391ffSNeil Horman 		SNMP_UPD_PO_STATS##modifier((_idev)->stats.statname, field, (val)); \
157edf391ffSNeil Horman 	SNMP_UPD_PO_STATS##modifier((net)->mib.statname##_statistics, field, (val));\
158edf391ffSNeil Horman })
159edf391ffSNeil Horman 
1601da177e4SLinus Torvalds /* MIBs */
16114878f75SDavid L Stevens 
162087fe240SDenis V. Lunev #define IP6_INC_STATS(net, idev,field)		\
1634ce3c183SEric Dumazet 		_DEVINC(net, ipv6, 64, idev, field)
164087fe240SDenis V. Lunev #define IP6_INC_STATS_BH(net, idev,field)	\
1654ce3c183SEric Dumazet 		_DEVINC(net, ipv6, 64_BH, idev, field)
166edf391ffSNeil Horman #define IP6_ADD_STATS(net, idev,field,val)	\
1674ce3c183SEric Dumazet 		_DEVADD(net, ipv6, 64, idev, field, val)
168087fe240SDenis V. Lunev #define IP6_ADD_STATS_BH(net, idev,field,val)	\
1694ce3c183SEric Dumazet 		_DEVADD(net, ipv6, 64_BH, idev, field, val)
170edf391ffSNeil Horman #define IP6_UPD_PO_STATS(net, idev,field,val)   \
1714ce3c183SEric Dumazet 		_DEVUPD(net, ipv6, 64, idev, field, val)
172edf391ffSNeil Horman #define IP6_UPD_PO_STATS_BH(net, idev,field,val)   \
1734ce3c183SEric Dumazet 		_DEVUPD(net, ipv6, 64_BH, idev, field, val)
174087fe240SDenis V. Lunev #define ICMP6_INC_STATS(net, idev, field)	\
175be281e55SEric Dumazet 		_DEVINCATOMIC(net, icmpv6, , idev, field)
176087fe240SDenis V. Lunev #define ICMP6_INC_STATS_BH(net, idev, field)	\
177be281e55SEric Dumazet 		_DEVINCATOMIC(net, icmpv6, _BH, idev, field)
17814878f75SDavid L Stevens 
179087fe240SDenis V. Lunev #define ICMP6MSGOUT_INC_STATS(net, idev, field)		\
1802a24444fSEric Dumazet 	_DEVINC_ATOMIC_ATOMIC(net, icmpv6msg, idev, field +256)
181087fe240SDenis V. Lunev #define ICMP6MSGOUT_INC_STATS_BH(net, idev, field)	\
1822a24444fSEric Dumazet 	_DEVINC_ATOMIC_ATOMIC(net, icmpv6msg, idev, field +256)
183087fe240SDenis V. Lunev #define ICMP6MSGIN_INC_STATS_BH(net, idev, field)	\
1842a24444fSEric Dumazet 	_DEVINC_ATOMIC_ATOMIC(net, icmpv6msg, idev, field)
18514878f75SDavid L Stevens 
186fd2c3ef7SEric Dumazet struct ip6_ra_chain {
1871da177e4SLinus Torvalds 	struct ip6_ra_chain	*next;
1881da177e4SLinus Torvalds 	struct sock		*sk;
1891da177e4SLinus Torvalds 	int			sel;
1901da177e4SLinus Torvalds 	void			(*destructor)(struct sock *);
1911da177e4SLinus Torvalds };
1921da177e4SLinus Torvalds 
1931da177e4SLinus Torvalds extern struct ip6_ra_chain	*ip6_ra_chain;
1941da177e4SLinus Torvalds extern rwlock_t ip6_ra_lock;
1951da177e4SLinus Torvalds 
1961da177e4SLinus Torvalds /*
1971da177e4SLinus Torvalds    This structure is prepared by protocol, when parsing
1981da177e4SLinus Torvalds    ancillary data and passed to IPv6.
1991da177e4SLinus Torvalds  */
2001da177e4SLinus Torvalds 
201fd2c3ef7SEric Dumazet struct ipv6_txoptions {
2021da177e4SLinus Torvalds 	/* Length of this structure */
2031da177e4SLinus Torvalds 	int			tot_len;
2041da177e4SLinus Torvalds 
2051da177e4SLinus Torvalds 	/* length of extension headers   */
2061da177e4SLinus Torvalds 
2071da177e4SLinus Torvalds 	__u16			opt_flen;	/* after fragment hdr */
2081da177e4SLinus Torvalds 	__u16			opt_nflen;	/* before fragment hdr */
2091da177e4SLinus Torvalds 
2101da177e4SLinus Torvalds 	struct ipv6_opt_hdr	*hopopt;
2111da177e4SLinus Torvalds 	struct ipv6_opt_hdr	*dst0opt;
2121da177e4SLinus Torvalds 	struct ipv6_rt_hdr	*srcrt;	/* Routing Header */
2131da177e4SLinus Torvalds 	struct ipv6_opt_hdr	*dst1opt;
2141da177e4SLinus Torvalds 
2151da177e4SLinus Torvalds 	/* Option buffer, as read by IPV6_PKTOPTIONS, starts here. */
2161da177e4SLinus Torvalds };
2171da177e4SLinus Torvalds 
218fd2c3ef7SEric Dumazet struct ip6_flowlabel {
2191da177e4SLinus Torvalds 	struct ip6_flowlabel	*next;
22090bcaf7bSAl Viro 	__be32			label;
221db3459d1SEric Dumazet 	atomic_t		users;
2221da177e4SLinus Torvalds 	struct in6_addr		dst;
2231da177e4SLinus Torvalds 	struct ipv6_txoptions	*opt;
2241da177e4SLinus Torvalds 	unsigned long		linger;
2251da177e4SLinus Torvalds 	u8			share;
2264f82f457SEric W. Biederman 	union {
2274f82f457SEric W. Biederman 		struct pid *pid;
2284f82f457SEric W. Biederman 		kuid_t uid;
2294f82f457SEric W. Biederman 	} owner;
2301da177e4SLinus Torvalds 	unsigned long		lastuse;
2311da177e4SLinus Torvalds 	unsigned long		expires;
23260e8fbc4SBenjamin Thery 	struct net		*fl_net;
2331da177e4SLinus Torvalds };
2341da177e4SLinus Torvalds 
235f3a7c66bSHarvey Harrison #define IPV6_FLOWINFO_MASK	cpu_to_be32(0x0FFFFFFF)
236f3a7c66bSHarvey Harrison #define IPV6_FLOWLABEL_MASK	cpu_to_be32(0x000FFFFF)
2371da177e4SLinus Torvalds 
238fd2c3ef7SEric Dumazet struct ipv6_fl_socklist {
2391da177e4SLinus Torvalds 	struct ipv6_fl_socklist	*next;
2401da177e4SLinus Torvalds 	struct ip6_flowlabel	*fl;
2411da177e4SLinus Torvalds };
2421da177e4SLinus Torvalds 
24390bcaf7bSAl Viro extern struct ip6_flowlabel	*fl6_sock_lookup(struct sock *sk, __be32 label);
2441da177e4SLinus Torvalds extern struct ipv6_txoptions	*fl6_merge_options(struct ipv6_txoptions * opt_space,
2451da177e4SLinus Torvalds 						   struct ip6_flowlabel * fl,
2461da177e4SLinus Torvalds 						   struct ipv6_txoptions * fopt);
2471da177e4SLinus Torvalds extern void			fl6_free_socklist(struct sock *sk);
2481da177e4SLinus Torvalds extern int			ipv6_flowlabel_opt(struct sock *sk, char __user *optval, int optlen);
2490a3e78acSDaniel Lezcano extern int			ip6_flowlabel_init(void);
2501da177e4SLinus Torvalds extern void			ip6_flowlabel_cleanup(void);
2511da177e4SLinus Torvalds 
2521da177e4SLinus Torvalds static inline void fl6_sock_release(struct ip6_flowlabel *fl)
2531da177e4SLinus Torvalds {
2541da177e4SLinus Torvalds 	if (fl)
2551da177e4SLinus Torvalds 		atomic_dec(&fl->users);
2561da177e4SLinus Torvalds }
2571da177e4SLinus Torvalds 
258b94f1c09SDavid S. Miller extern void icmpv6_notify(struct sk_buff *skb, u8 type, u8 code, __be32 info);
259b94f1c09SDavid S. Miller 
260725a8ff0SDenis V. Lunev extern int 			ip6_ra_control(struct sock *sk, int sel);
2611da177e4SLinus Torvalds 
262e5bbef20SHerbert Xu extern int			ipv6_parse_hopopts(struct sk_buff *skb);
2631da177e4SLinus Torvalds 
2641da177e4SLinus Torvalds extern struct ipv6_txoptions *  ipv6_dup_options(struct sock *sk, struct ipv6_txoptions *opt);
265333fad53SYOSHIFUJI Hideaki extern struct ipv6_txoptions *	ipv6_renew_options(struct sock *sk, struct ipv6_txoptions *opt,
266333fad53SYOSHIFUJI Hideaki 						   int newtype,
267333fad53SYOSHIFUJI Hideaki 						   struct ipv6_opt_hdr __user *newopt,
268333fad53SYOSHIFUJI Hideaki 						   int newoptlen);
269df9890c3SYOSHIFUJI Hideaki struct ipv6_txoptions *ipv6_fixup_options(struct ipv6_txoptions *opt_space,
270df9890c3SYOSHIFUJI Hideaki 					  struct ipv6_txoptions *opt);
2711da177e4SLinus Torvalds 
27292113bfdSEric Dumazet extern bool ipv6_opt_accepted(const struct sock *sk, const struct sk_buff *skb);
273399c07deSArnaldo Carvalho de Melo 
274*d4915c08SAmerigo Wang #if IS_ENABLED(CONFIG_IPV6)
275*d4915c08SAmerigo Wang static inline int ip6_frag_nqueues(struct net *net)
276*d4915c08SAmerigo Wang {
277*d4915c08SAmerigo Wang 	return net->ipv6.frags.nqueues;
278*d4915c08SAmerigo Wang }
279*d4915c08SAmerigo Wang 
280*d4915c08SAmerigo Wang static inline int ip6_frag_mem(struct net *net)
281*d4915c08SAmerigo Wang {
282*d4915c08SAmerigo Wang 	return atomic_read(&net->ipv6.frags.mem);
283*d4915c08SAmerigo Wang }
284*d4915c08SAmerigo Wang #endif
2851da177e4SLinus Torvalds 
2869874c41cSJoe Perches #define IPV6_FRAG_HIGH_THRESH	(256 * 1024)	/* 262144 */
2879874c41cSJoe Perches #define IPV6_FRAG_LOW_THRESH	(192 * 1024)	/* 196608 */
2881da177e4SLinus Torvalds #define IPV6_FRAG_TIMEOUT	(60 * HZ)	/* 60 seconds */
2891da177e4SLinus Torvalds 
290b1cacb68SYOSHIFUJI Hideaki extern int __ipv6_addr_type(const struct in6_addr *addr);
291b1cacb68SYOSHIFUJI Hideaki static inline int ipv6_addr_type(const struct in6_addr *addr)
292b1cacb68SYOSHIFUJI Hideaki {
293b1cacb68SYOSHIFUJI Hideaki 	return __ipv6_addr_type(addr) & 0xffff;
294b1cacb68SYOSHIFUJI Hideaki }
2951da177e4SLinus Torvalds 
2961da177e4SLinus Torvalds static inline int ipv6_addr_scope(const struct in6_addr *addr)
2971da177e4SLinus Torvalds {
298b1cacb68SYOSHIFUJI Hideaki 	return __ipv6_addr_type(addr) & IPV6_ADDR_SCOPE_MASK;
299b1cacb68SYOSHIFUJI Hideaki }
300b1cacb68SYOSHIFUJI Hideaki 
301b1cacb68SYOSHIFUJI Hideaki static inline int __ipv6_addr_src_scope(int type)
302b1cacb68SYOSHIFUJI Hideaki {
303a02cec21SEric Dumazet 	return (type == IPV6_ADDR_ANY) ? __IPV6_ADDR_SCOPE_INVALID : (type >> 16);
304b1cacb68SYOSHIFUJI Hideaki }
305b1cacb68SYOSHIFUJI Hideaki 
306b1cacb68SYOSHIFUJI Hideaki static inline int ipv6_addr_src_scope(const struct in6_addr *addr)
307b1cacb68SYOSHIFUJI Hideaki {
308b1cacb68SYOSHIFUJI Hideaki 	return __ipv6_addr_src_scope(__ipv6_addr_type(addr));
3091da177e4SLinus Torvalds }
3101da177e4SLinus Torvalds 
3111da177e4SLinus Torvalds static inline int ipv6_addr_cmp(const struct in6_addr *a1, const struct in6_addr *a2)
3121da177e4SLinus Torvalds {
313db3459d1SEric Dumazet 	return memcmp(a1, a2, sizeof(struct in6_addr));
3141da177e4SLinus Torvalds }
3151da177e4SLinus Torvalds 
3161a203cb3SEric Dumazet static inline bool
317f2ffd9eeSPatrick McHardy ipv6_masked_addr_cmp(const struct in6_addr *a1, const struct in6_addr *m,
318f2ffd9eeSPatrick McHardy 		     const struct in6_addr *a2)
319f2ffd9eeSPatrick McHardy {
3201a203cb3SEric Dumazet #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
3211a203cb3SEric Dumazet 	const unsigned long *ul1 = (const unsigned long *)a1;
3221a203cb3SEric Dumazet 	const unsigned long *ulm = (const unsigned long *)m;
3231a203cb3SEric Dumazet 	const unsigned long *ul2 = (const unsigned long *)a2;
3241a203cb3SEric Dumazet 
3251a203cb3SEric Dumazet 	return !!(((ul1[0] ^ ul2[0]) & ulm[0]) |
3261a203cb3SEric Dumazet 		  ((ul1[1] ^ ul2[1]) & ulm[1]));
3271a203cb3SEric Dumazet #else
328a02cec21SEric Dumazet 	return !!(((a1->s6_addr32[0] ^ a2->s6_addr32[0]) & m->s6_addr32[0]) |
329fed85383SYOSHIFUJI Hideaki 		  ((a1->s6_addr32[1] ^ a2->s6_addr32[1]) & m->s6_addr32[1]) |
330fed85383SYOSHIFUJI Hideaki 		  ((a1->s6_addr32[2] ^ a2->s6_addr32[2]) & m->s6_addr32[2]) |
331a02cec21SEric Dumazet 		  ((a1->s6_addr32[3] ^ a2->s6_addr32[3]) & m->s6_addr32[3]));
3321a203cb3SEric Dumazet #endif
333f2ffd9eeSPatrick McHardy }
334f2ffd9eeSPatrick McHardy 
3351da177e4SLinus Torvalds static inline void ipv6_addr_prefix(struct in6_addr *pfx,
3361da177e4SLinus Torvalds 				    const struct in6_addr *addr,
3371da177e4SLinus Torvalds 				    int plen)
3381da177e4SLinus Torvalds {
3391da177e4SLinus Torvalds 	/* caller must guarantee 0 <= plen <= 128 */
3401da177e4SLinus Torvalds 	int o = plen >> 3,
3411da177e4SLinus Torvalds 	    b = plen & 0x7;
3421da177e4SLinus Torvalds 
343db3459d1SEric Dumazet 	memset(pfx->s6_addr, 0, sizeof(pfx->s6_addr));
3441da177e4SLinus Torvalds 	memcpy(pfx->s6_addr, addr, o);
345db3459d1SEric Dumazet 	if (b != 0)
3461da177e4SLinus Torvalds 		pfx->s6_addr[o] = addr->s6_addr[o] & (0xff00 >> b);
3471da177e4SLinus Torvalds }
3481da177e4SLinus Torvalds 
3491da177e4SLinus Torvalds static inline void ipv6_addr_set(struct in6_addr *addr,
35048818f82SAl Viro 				     __be32 w1, __be32 w2,
35148818f82SAl Viro 				     __be32 w3, __be32 w4)
3521da177e4SLinus Torvalds {
3531da177e4SLinus Torvalds 	addr->s6_addr32[0] = w1;
3541da177e4SLinus Torvalds 	addr->s6_addr32[1] = w2;
3551da177e4SLinus Torvalds 	addr->s6_addr32[2] = w3;
3561da177e4SLinus Torvalds 	addr->s6_addr32[3] = w4;
3571da177e4SLinus Torvalds }
3581da177e4SLinus Torvalds 
35992113bfdSEric Dumazet static inline bool ipv6_addr_equal(const struct in6_addr *a1,
3601da177e4SLinus Torvalds 				   const struct in6_addr *a2)
3611da177e4SLinus Torvalds {
3621a203cb3SEric Dumazet #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
3631a203cb3SEric Dumazet 	const unsigned long *ul1 = (const unsigned long *)a1;
3641a203cb3SEric Dumazet 	const unsigned long *ul2 = (const unsigned long *)a2;
3651a203cb3SEric Dumazet 
3661a203cb3SEric Dumazet 	return ((ul1[0] ^ ul2[0]) | (ul1[1] ^ ul2[1])) == 0UL;
3671a203cb3SEric Dumazet #else
368a02cec21SEric Dumazet 	return ((a1->s6_addr32[0] ^ a2->s6_addr32[0]) |
369fed85383SYOSHIFUJI Hideaki 		(a1->s6_addr32[1] ^ a2->s6_addr32[1]) |
370fed85383SYOSHIFUJI Hideaki 		(a1->s6_addr32[2] ^ a2->s6_addr32[2]) |
371a02cec21SEric Dumazet 		(a1->s6_addr32[3] ^ a2->s6_addr32[3])) == 0;
3721a203cb3SEric Dumazet #endif
3731da177e4SLinus Torvalds }
3741da177e4SLinus Torvalds 
37592113bfdSEric Dumazet static inline bool __ipv6_prefix_equal(const __be32 *a1, const __be32 *a2,
3761da177e4SLinus Torvalds 				       unsigned int prefixlen)
3771da177e4SLinus Torvalds {
37895c96174SEric Dumazet 	unsigned int pdw, pbi;
3791da177e4SLinus Torvalds 
3801da177e4SLinus Torvalds 	/* check complete u32 in prefix */
3811da177e4SLinus Torvalds 	pdw = prefixlen >> 5;
3821da177e4SLinus Torvalds 	if (pdw && memcmp(a1, a2, pdw << 2))
38392113bfdSEric Dumazet 		return false;
3841da177e4SLinus Torvalds 
3851da177e4SLinus Torvalds 	/* check incomplete u32 in prefix */
3861da177e4SLinus Torvalds 	pbi = prefixlen & 0x1f;
3871da177e4SLinus Torvalds 	if (pbi && ((a1[pdw] ^ a2[pdw]) & htonl((0xffffffff) << (32 - pbi))))
38892113bfdSEric Dumazet 		return false;
3891da177e4SLinus Torvalds 
39092113bfdSEric Dumazet 	return true;
3911da177e4SLinus Torvalds }
3921da177e4SLinus Torvalds 
39392113bfdSEric Dumazet static inline bool ipv6_prefix_equal(const struct in6_addr *a1,
3941da177e4SLinus Torvalds 				     const struct in6_addr *a2,
3951da177e4SLinus Torvalds 				     unsigned int prefixlen)
3961da177e4SLinus Torvalds {
3971da177e4SLinus Torvalds 	return __ipv6_prefix_equal(a1->s6_addr32, a2->s6_addr32,
3981da177e4SLinus Torvalds 				   prefixlen);
3991da177e4SLinus Torvalds }
4001da177e4SLinus Torvalds 
4012588fe1dSPavel Emelyanov struct inet_frag_queue;
4022588fe1dSPavel Emelyanov 
4030b5ccb2eSPatrick McHardy enum ip6_defrag_users {
4040b5ccb2eSPatrick McHardy 	IP6_DEFRAG_LOCAL_DELIVER,
4050b5ccb2eSPatrick McHardy 	IP6_DEFRAG_CONNTRACK_IN,
4064be929beSAlexey Dobriyan 	__IP6_DEFRAG_CONNTRACK_IN	= IP6_DEFRAG_CONNTRACK_IN + USHRT_MAX,
4070b5ccb2eSPatrick McHardy 	IP6_DEFRAG_CONNTRACK_OUT,
4084be929beSAlexey Dobriyan 	__IP6_DEFRAG_CONNTRACK_OUT	= IP6_DEFRAG_CONNTRACK_OUT + USHRT_MAX,
4098fa9ff68SPatrick McHardy 	IP6_DEFRAG_CONNTRACK_BRIDGE_IN,
4104be929beSAlexey Dobriyan 	__IP6_DEFRAG_CONNTRACK_BRIDGE_IN = IP6_DEFRAG_CONNTRACK_BRIDGE_IN + USHRT_MAX,
4110b5ccb2eSPatrick McHardy };
4120b5ccb2eSPatrick McHardy 
413c6fda282SPavel Emelyanov struct ip6_create_arg {
414c6fda282SPavel Emelyanov 	__be32 id;
4150b5ccb2eSPatrick McHardy 	u32 user;
416b71d1d42SEric Dumazet 	const struct in6_addr *src;
417b71d1d42SEric Dumazet 	const struct in6_addr *dst;
418c6fda282SPavel Emelyanov };
419c6fda282SPavel Emelyanov 
420c6fda282SPavel Emelyanov void ip6_frag_init(struct inet_frag_queue *q, void *a);
421cbc264caSEric Dumazet bool ip6_frag_match(struct inet_frag_queue *q, void *a);
422c6fda282SPavel Emelyanov 
423b836c99fSAmerigo Wang /*
424b836c99fSAmerigo Wang  *	Equivalent of ipv4 struct ip
425b836c99fSAmerigo Wang  */
426b836c99fSAmerigo Wang struct frag_queue {
427b836c99fSAmerigo Wang 	struct inet_frag_queue	q;
428b836c99fSAmerigo Wang 
429b836c99fSAmerigo Wang 	__be32			id;		/* fragment id		*/
430b836c99fSAmerigo Wang 	u32			user;
431b836c99fSAmerigo Wang 	struct in6_addr		saddr;
432b836c99fSAmerigo Wang 	struct in6_addr		daddr;
433b836c99fSAmerigo Wang 
434b836c99fSAmerigo Wang 	int			iif;
435b836c99fSAmerigo Wang 	unsigned int		csum;
436b836c99fSAmerigo Wang 	__u16			nhoffset;
437b836c99fSAmerigo Wang };
438b836c99fSAmerigo Wang 
439b836c99fSAmerigo Wang void ip6_expire_frag_queue(struct net *net, struct frag_queue *fq,
440b836c99fSAmerigo Wang 			   struct inet_frags *frags);
441b836c99fSAmerigo Wang 
44292113bfdSEric Dumazet static inline bool ipv6_addr_any(const struct in6_addr *a)
4431da177e4SLinus Torvalds {
4441a203cb3SEric Dumazet #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
4451a203cb3SEric Dumazet 	const unsigned long *ul = (const unsigned long *)a;
4461a203cb3SEric Dumazet 
4471a203cb3SEric Dumazet 	return (ul[0] | ul[1]) == 0UL;
4481a203cb3SEric Dumazet #else
449a02cec21SEric Dumazet 	return (a->s6_addr32[0] | a->s6_addr32[1] |
450a02cec21SEric Dumazet 		a->s6_addr32[2] | a->s6_addr32[3]) == 0;
4511a203cb3SEric Dumazet #endif
4521da177e4SLinus Torvalds }
4531da177e4SLinus Torvalds 
454ddbe5032SEric Dumazet static inline u32 ipv6_addr_hash(const struct in6_addr *a)
455ddbe5032SEric Dumazet {
456ddbe5032SEric Dumazet #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
457ddbe5032SEric Dumazet 	const unsigned long *ul = (const unsigned long *)a;
458ddbe5032SEric Dumazet 	unsigned long x = ul[0] ^ ul[1];
459ddbe5032SEric Dumazet 
460ddbe5032SEric Dumazet 	return (u32)(x ^ (x >> 32));
461ddbe5032SEric Dumazet #else
462ddbe5032SEric Dumazet 	return (__force u32)(a->s6_addr32[0] ^ a->s6_addr32[1] ^
463ddbe5032SEric Dumazet 			     a->s6_addr32[2] ^ a->s6_addr32[3]);
464ddbe5032SEric Dumazet #endif
465ddbe5032SEric Dumazet }
466ddbe5032SEric Dumazet 
46792113bfdSEric Dumazet static inline bool ipv6_addr_loopback(const struct in6_addr *a)
468f630e43aSYOSHIFUJI Hideaki {
469a02cec21SEric Dumazet 	return (a->s6_addr32[0] | a->s6_addr32[1] |
470a02cec21SEric Dumazet 		a->s6_addr32[2] | (a->s6_addr32[3] ^ htonl(1))) == 0;
471f630e43aSYOSHIFUJI Hideaki }
472f630e43aSYOSHIFUJI Hideaki 
47392113bfdSEric Dumazet static inline bool ipv6_addr_v4mapped(const struct in6_addr *a)
474e773e4faSBrian Haley {
475a02cec21SEric Dumazet 	return (a->s6_addr32[0] | a->s6_addr32[1] |
476a02cec21SEric Dumazet 		 (a->s6_addr32[2] ^ htonl(0x0000ffff))) == 0;
477e773e4faSBrian Haley }
478e773e4faSBrian Haley 
4791da177e4SLinus Torvalds /*
48099cd07a5SJuha-Matti Tapio  * Check for a RFC 4843 ORCHID address
48199cd07a5SJuha-Matti Tapio  * (Overlay Routable Cryptographic Hash Identifiers)
48299cd07a5SJuha-Matti Tapio  */
48392113bfdSEric Dumazet static inline bool ipv6_addr_orchid(const struct in6_addr *a)
48499cd07a5SJuha-Matti Tapio {
485a02cec21SEric Dumazet 	return (a->s6_addr32[0] & htonl(0xfffffff0)) == htonl(0x20010010);
48699cd07a5SJuha-Matti Tapio }
48799cd07a5SJuha-Matti Tapio 
488f15364bdSAurélien Charbon static inline void ipv6_addr_set_v4mapped(const __be32 addr,
489f15364bdSAurélien Charbon 					  struct in6_addr *v4mapped)
490f15364bdSAurélien Charbon {
491f15364bdSAurélien Charbon 	ipv6_addr_set(v4mapped,
492f15364bdSAurélien Charbon 			0, 0,
493f15364bdSAurélien Charbon 			htonl(0x0000FFFF),
494f15364bdSAurélien Charbon 			addr);
495f15364bdSAurélien Charbon }
496f15364bdSAurélien Charbon 
49799cd07a5SJuha-Matti Tapio /*
498971f359dSYOSHIFUJI Hideaki  * find the first different bit between two addresses
499971f359dSYOSHIFUJI Hideaki  * length of address must be a multiple of 32bits
500971f359dSYOSHIFUJI Hideaki  */
501971f359dSYOSHIFUJI Hideaki static inline int __ipv6_addr_diff(const void *token1, const void *token2, int addrlen)
502971f359dSYOSHIFUJI Hideaki {
503ef296f56SAl Viro 	const __be32 *a1 = token1, *a2 = token2;
504971f359dSYOSHIFUJI Hideaki 	int i;
505971f359dSYOSHIFUJI Hideaki 
506971f359dSYOSHIFUJI Hideaki 	addrlen >>= 2;
507971f359dSYOSHIFUJI Hideaki 
508971f359dSYOSHIFUJI Hideaki 	for (i = 0; i < addrlen; i++) {
509ef296f56SAl Viro 		__be32 xb = a1[i] ^ a2[i];
510ef296f56SAl Viro 		if (xb)
511d57b8fb8SYOSHIFUJI Hideaki / 吉藤英明 			return i * 32 + 31 - __fls(ntohl(xb));
512971f359dSYOSHIFUJI Hideaki 	}
513971f359dSYOSHIFUJI Hideaki 
514971f359dSYOSHIFUJI Hideaki 	/*
515971f359dSYOSHIFUJI Hideaki 	 *	we should *never* get to this point since that
516971f359dSYOSHIFUJI Hideaki 	 *	would mean the addrs are equal
517971f359dSYOSHIFUJI Hideaki 	 *
518971f359dSYOSHIFUJI Hideaki 	 *	However, we do get to it 8) And exacly, when
519971f359dSYOSHIFUJI Hideaki 	 *	addresses are equal 8)
520971f359dSYOSHIFUJI Hideaki 	 *
521971f359dSYOSHIFUJI Hideaki 	 *	ip route add 1111::/128 via ...
522971f359dSYOSHIFUJI Hideaki 	 *	ip route add 1111::/64 via ...
523971f359dSYOSHIFUJI Hideaki 	 *	and we are here.
524971f359dSYOSHIFUJI Hideaki 	 *
525971f359dSYOSHIFUJI Hideaki 	 *	Ideally, this function should stop comparison
526971f359dSYOSHIFUJI Hideaki 	 *	at prefix length. It does not, but it is still OK,
527971f359dSYOSHIFUJI Hideaki 	 *	if returned value is greater than prefix length.
528971f359dSYOSHIFUJI Hideaki 	 *					--ANK (980803)
529971f359dSYOSHIFUJI Hideaki 	 */
530a02cec21SEric Dumazet 	return addrlen << 5;
531971f359dSYOSHIFUJI Hideaki }
532971f359dSYOSHIFUJI Hideaki 
533971f359dSYOSHIFUJI Hideaki static inline int ipv6_addr_diff(const struct in6_addr *a1, const struct in6_addr *a2)
534971f359dSYOSHIFUJI Hideaki {
535971f359dSYOSHIFUJI Hideaki 	return __ipv6_addr_diff(a1, a2, sizeof(struct in6_addr));
536971f359dSYOSHIFUJI Hideaki }
537971f359dSYOSHIFUJI Hideaki 
53887c48fa3SEric Dumazet extern void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt);
5397ea2f2c5SSridhar Samudrala 
540971f359dSYOSHIFUJI Hideaki /*
5411da177e4SLinus Torvalds  *	Prototypes exported by ipv6
5421da177e4SLinus Torvalds  */
5431da177e4SLinus Torvalds 
5441da177e4SLinus Torvalds /*
5451da177e4SLinus Torvalds  *	rcv function (called from netdevice level)
5461da177e4SLinus Torvalds  */
5471da177e4SLinus Torvalds 
5481da177e4SLinus Torvalds extern int			ipv6_rcv(struct sk_buff *skb,
5491da177e4SLinus Torvalds 					 struct net_device *dev,
550f2ccd8faSDavid S. Miller 					 struct packet_type *pt,
551f2ccd8faSDavid S. Miller 					 struct net_device *orig_dev);
5521da177e4SLinus Torvalds 
553b05e1066SPatrick McHardy extern int			ip6_rcv_finish(struct sk_buff *skb);
554b05e1066SPatrick McHardy 
5551da177e4SLinus Torvalds /*
5561da177e4SLinus Torvalds  *	upper-layer output functions
5571da177e4SLinus Torvalds  */
5581da177e4SLinus Torvalds extern int			ip6_xmit(struct sock *sk,
5591da177e4SLinus Torvalds 					 struct sk_buff *skb,
5604c9483b2SDavid S. Miller 					 struct flowi6 *fl6,
561b903d324SEric Dumazet 					 struct ipv6_txoptions *opt,
562b903d324SEric Dumazet 					 int tclass);
5631da177e4SLinus Torvalds 
5641da177e4SLinus Torvalds extern int			ip6_nd_hdr(struct sock *sk,
5651da177e4SLinus Torvalds 					   struct sk_buff *skb,
5661da177e4SLinus Torvalds 					   struct net_device *dev,
5679acd9f3aSYOSHIFUJI Hideaki 					   const struct in6_addr *saddr,
5689acd9f3aSYOSHIFUJI Hideaki 					   const struct in6_addr *daddr,
5691da177e4SLinus Torvalds 					   int proto, int len);
5701da177e4SLinus Torvalds 
5711da177e4SLinus Torvalds extern int			ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr);
5721da177e4SLinus Torvalds 
5731da177e4SLinus Torvalds extern int			ip6_append_data(struct sock *sk,
5741da177e4SLinus Torvalds 						int getfrag(void *from, char *to, int offset, int len, int odd, struct sk_buff *skb),
5751da177e4SLinus Torvalds 		    				void *from,
5761da177e4SLinus Torvalds 						int length,
5771da177e4SLinus Torvalds 						int transhdrlen,
5781da177e4SLinus Torvalds 		      				int hlimit,
57941a1f8eaSYOSHIFUJI Hideaki 		      				int tclass,
5801da177e4SLinus Torvalds 						struct ipv6_txoptions *opt,
5814c9483b2SDavid S. Miller 						struct flowi6 *fl6,
5821da177e4SLinus Torvalds 						struct rt6_info *rt,
58313b52cd4SBrian Haley 						unsigned int flags,
58413b52cd4SBrian Haley 						int dontfrag);
5851da177e4SLinus Torvalds 
5861da177e4SLinus Torvalds extern int			ip6_push_pending_frames(struct sock *sk);
5871da177e4SLinus Torvalds 
5881da177e4SLinus Torvalds extern void			ip6_flush_pending_frames(struct sock *sk);
5891da177e4SLinus Torvalds 
5901da177e4SLinus Torvalds extern int			ip6_dst_lookup(struct sock *sk,
5911da177e4SLinus Torvalds 					       struct dst_entry **dst,
5924c9483b2SDavid S. Miller 					       struct flowi6 *fl6);
59368d0c6d3SDavid S. Miller extern struct dst_entry *	ip6_dst_lookup_flow(struct sock *sk,
5944c9483b2SDavid S. Miller 						    struct flowi6 *fl6,
59568d0c6d3SDavid S. Miller 						    const struct in6_addr *final_dst,
596a1414715SDavid S. Miller 						    bool can_sleep);
59768d0c6d3SDavid S. Miller extern struct dst_entry *	ip6_sk_dst_lookup_flow(struct sock *sk,
5984c9483b2SDavid S. Miller 						       struct flowi6 *fl6,
59968d0c6d3SDavid S. Miller 						       const struct in6_addr *final_dst,
600a1414715SDavid S. Miller 						       bool can_sleep);
6012774c131SDavid S. Miller extern struct dst_entry *	ip6_blackhole_route(struct net *net,
60269ead7afSDavid S. Miller 						    struct dst_entry *orig_dst);
6031da177e4SLinus Torvalds 
6041da177e4SLinus Torvalds /*
6051da177e4SLinus Torvalds  *	skb processing functions
6061da177e4SLinus Torvalds  */
6071da177e4SLinus Torvalds 
6081da177e4SLinus Torvalds extern int			ip6_output(struct sk_buff *skb);
6091da177e4SLinus Torvalds extern int			ip6_forward(struct sk_buff *skb);
6101da177e4SLinus Torvalds extern int			ip6_input(struct sk_buff *skb);
6111da177e4SLinus Torvalds extern int			ip6_mc_input(struct sk_buff *skb);
6121da177e4SLinus Torvalds 
613ef76bc23SHerbert Xu extern int			__ip6_local_out(struct sk_buff *skb);
614ef76bc23SHerbert Xu extern int			ip6_local_out(struct sk_buff *skb);
615ef76bc23SHerbert Xu 
6161da177e4SLinus Torvalds /*
6171da177e4SLinus Torvalds  *	Extension header (options) processing
6181da177e4SLinus Torvalds  */
6191da177e4SLinus Torvalds 
6201da177e4SLinus Torvalds extern void 			ipv6_push_nfrag_opts(struct sk_buff *skb,
6211da177e4SLinus Torvalds 						     struct ipv6_txoptions *opt,
6221da177e4SLinus Torvalds 						     u8 *proto,
6231da177e4SLinus Torvalds 						     struct in6_addr **daddr_p);
6241da177e4SLinus Torvalds extern void			ipv6_push_frag_opts(struct sk_buff *skb,
6251da177e4SLinus Torvalds 						    struct ipv6_txoptions *opt,
6261da177e4SLinus Torvalds 						    u8 *proto);
6271da177e4SLinus Torvalds 
6281da177e4SLinus Torvalds extern int			ipv6_skip_exthdr(const struct sk_buff *, int start,
62975f2811cSJesse Gross 					         u8 *nexthdrp, __be16 *frag_offp);
6301da177e4SLinus Torvalds 
631a50feda5SEric Dumazet extern bool			ipv6_ext_hdr(u8 nexthdr);
6321da177e4SLinus Torvalds 
633c61a4043SMasahide NAKAMURA extern int ipv6_find_tlv(struct sk_buff *skb, int offset, int type);
634c61a4043SMasahide NAKAMURA 
6354c9483b2SDavid S. Miller extern struct in6_addr *fl6_update_dst(struct flowi6 *fl6,
63620c59de2SArnaud Ebalard 				       const struct ipv6_txoptions *opt,
63720c59de2SArnaud Ebalard 				       struct in6_addr *orig);
63820c59de2SArnaud Ebalard 
6391da177e4SLinus Torvalds /*
6401da177e4SLinus Torvalds  *	socket options (ipv6_sockglue.c)
6411da177e4SLinus Torvalds  */
6421da177e4SLinus Torvalds 
6431da177e4SLinus Torvalds extern int			ipv6_setsockopt(struct sock *sk, int level,
6441da177e4SLinus Torvalds 						int optname,
6451da177e4SLinus Torvalds 						char __user *optval,
646b7058842SDavid S. Miller 						unsigned int optlen);
6471da177e4SLinus Torvalds extern int			ipv6_getsockopt(struct sock *sk, int level,
6481da177e4SLinus Torvalds 						int optname,
6491da177e4SLinus Torvalds 						char __user *optval,
6501da177e4SLinus Torvalds 						int __user *optlen);
6513fdadf7dSDmitry Mishin extern int			compat_ipv6_setsockopt(struct sock *sk,
6523fdadf7dSDmitry Mishin 						int level,
6533fdadf7dSDmitry Mishin 						int optname,
6543fdadf7dSDmitry Mishin 						char __user *optval,
655b7058842SDavid S. Miller 						unsigned int optlen);
6563fdadf7dSDmitry Mishin extern int			compat_ipv6_getsockopt(struct sock *sk,
6573fdadf7dSDmitry Mishin 						int level,
6583fdadf7dSDmitry Mishin 						int optname,
6593fdadf7dSDmitry Mishin 						char __user *optval,
6603fdadf7dSDmitry Mishin 						int __user *optlen);
6611da177e4SLinus Torvalds 
6621da177e4SLinus Torvalds extern int			ip6_datagram_connect(struct sock *sk,
6631da177e4SLinus Torvalds 						     struct sockaddr *addr, int addr_len);
6641da177e4SLinus Torvalds 
6651da177e4SLinus Torvalds extern int 			ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len);
6664b340ae2SBrian Haley extern int 			ipv6_recv_rxpmtu(struct sock *sk, struct msghdr *msg, int len);
667e69a4adcSAl Viro extern void			ipv6_icmp_error(struct sock *sk, struct sk_buff *skb, int err, __be16 port,
6681da177e4SLinus Torvalds 						u32 info, u8 *payload);
6694c9483b2SDavid S. Miller extern void			ipv6_local_error(struct sock *sk, int err, struct flowi6 *fl6, u32 info);
6704c9483b2SDavid S. Miller extern void			ipv6_local_rxpmtu(struct sock *sk, struct flowi6 *fl6, u32 mtu);
6711da177e4SLinus Torvalds 
6721da177e4SLinus Torvalds extern int inet6_release(struct socket *sock);
6731da177e4SLinus Torvalds extern int inet6_bind(struct socket *sock, struct sockaddr *uaddr,
6741da177e4SLinus Torvalds 		      int addr_len);
6751da177e4SLinus Torvalds extern int inet6_getname(struct socket *sock, struct sockaddr *uaddr,
6761da177e4SLinus Torvalds 			 int *uaddr_len, int peer);
6771da177e4SLinus Torvalds extern int inet6_ioctl(struct socket *sock, unsigned int cmd,
6781da177e4SLinus Torvalds 		       unsigned long arg);
6791da177e4SLinus Torvalds 
680d8313f5cSArnaldo Carvalho de Melo extern int inet6_hash_connect(struct inet_timewait_death_row *death_row,
681d8313f5cSArnaldo Carvalho de Melo 			      struct sock *sk);
682d8313f5cSArnaldo Carvalho de Melo 
6831da177e4SLinus Torvalds /*
6841da177e4SLinus Torvalds  * reassembly.c
6851da177e4SLinus Torvalds  */
68690ddc4f0SEric Dumazet extern const struct proto_ops inet6_stream_ops;
68790ddc4f0SEric Dumazet extern const struct proto_ops inet6_dgram_ops;
68820380731SArnaldo Carvalho de Melo 
68914c85021SArnaldo Carvalho de Melo struct group_source_req;
69014c85021SArnaldo Carvalho de Melo struct group_filter;
69114c85021SArnaldo Carvalho de Melo 
69220380731SArnaldo Carvalho de Melo extern int ip6_mc_source(int add, int omode, struct sock *sk,
69320380731SArnaldo Carvalho de Melo 			 struct group_source_req *pgsr);
69420380731SArnaldo Carvalho de Melo extern int ip6_mc_msfilter(struct sock *sk, struct group_filter *gsf);
69520380731SArnaldo Carvalho de Melo extern int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf,
69620380731SArnaldo Carvalho de Melo 			 struct group_filter __user *optval,
69720380731SArnaldo Carvalho de Melo 			 int __user *optlen);
69893c8b90fSIlpo Järvinen extern unsigned int inet6_hash_frag(__be32 id, const struct in6_addr *saddr,
69993c8b90fSIlpo Järvinen 				    const struct in6_addr *daddr, u32 rnd);
70020380731SArnaldo Carvalho de Melo 
70120380731SArnaldo Carvalho de Melo #ifdef CONFIG_PROC_FS
7026ab57e7eSDaniel Lezcano extern int  ac6_proc_init(struct net *net);
7036ab57e7eSDaniel Lezcano extern void ac6_proc_exit(struct net *net);
70420380731SArnaldo Carvalho de Melo extern int  raw6_proc_init(void);
70520380731SArnaldo Carvalho de Melo extern void raw6_proc_exit(void);
7066f8b13bcSDaniel Lezcano extern int  tcp6_proc_init(struct net *net);
7076f8b13bcSDaniel Lezcano extern void tcp6_proc_exit(struct net *net);
7080c96d8c5SDaniel Lezcano extern int  udp6_proc_init(struct net *net);
7090c96d8c5SDaniel Lezcano extern void udp6_proc_exit(struct net *net);
710ba4e58ecSGerrit Renker extern int  udplite6_proc_init(void);
711ba4e58ecSGerrit Renker extern void udplite6_proc_exit(void);
71220380731SArnaldo Carvalho de Melo extern int  ipv6_misc_proc_init(void);
71320380731SArnaldo Carvalho de Melo extern void ipv6_misc_proc_exit(void);
7147f7d9a6bSHerbert Xu extern int snmp6_register_dev(struct inet6_dev *idev);
7157f7d9a6bSHerbert Xu extern int snmp6_unregister_dev(struct inet6_dev *idev);
71620380731SArnaldo Carvalho de Melo 
7177f7d9a6bSHerbert Xu #else
7186ab57e7eSDaniel Lezcano static inline int ac6_proc_init(struct net *net) { return 0; }
7196ab57e7eSDaniel Lezcano static inline void ac6_proc_exit(struct net *net) { }
7206ab57e7eSDaniel Lezcano static inline int snmp6_register_dev(struct inet6_dev *idev) { return 0; }
7216ab57e7eSDaniel Lezcano static inline int snmp6_unregister_dev(struct inet6_dev *idev) { return 0; }
72220380731SArnaldo Carvalho de Melo #endif
72320380731SArnaldo Carvalho de Melo 
72420380731SArnaldo Carvalho de Melo #ifdef CONFIG_SYSCTL
725760f2d01SDaniel Lezcano extern ctl_table ipv6_route_table_template[];
726760f2d01SDaniel Lezcano extern ctl_table ipv6_icmp_table_template[];
72720380731SArnaldo Carvalho de Melo 
7286de1a910SDaniel Lezcano extern struct ctl_table *ipv6_icmp_sysctl_init(struct net *net);
7296de1a910SDaniel Lezcano extern struct ctl_table *ipv6_route_sysctl_init(struct net *net);
730291480c0SDaniel Lezcano extern int ipv6_sysctl_register(void);
73120380731SArnaldo Carvalho de Melo extern void ipv6_sysctl_unregister(void);
73220380731SArnaldo Carvalho de Melo #endif
73320380731SArnaldo Carvalho de Melo 
7341da177e4SLinus Torvalds #endif /* _NET_IPV6_H */
735