net: ipv4: split skbuff into fragments transformer
[linux-block.git] / include / net / ipv6.h
CommitLineData
1da177e4
LT
1/*
2 * Linux INET6 implementation
3 *
4 * Authors:
5 * Pedro Roque <roque@di.fc.ul.pt>
6 *
1da177e4
LT
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 */
12
13#ifndef _NET_IPV6_H
14#define _NET_IPV6_H
15
16#include <linux/ipv6.h>
17#include <linux/hardirq.h>
08dcdbf6 18#include <linux/jhash.h>
0aeea21a 19#include <linux/refcount.h>
20283d84 20#include <net/if_inet6.h>
1da177e4
LT
21#include <net/ndisc.h>
22#include <net/flow.h>
1bd758eb 23#include <net/flow_dissector.h>
1da177e4 24#include <net/snmp.h>
f0b1e64c 25#include <net/netns/hash.h>
1da177e4
LT
26
27#define SIN6_LEN_RFC2133 24
28
29#define IPV6_MAXPLEN 65535
30
31/*
32 * NextHeader field of IPv6 header
33 */
34
35#define NEXTHDR_HOP 0 /* Hop-by-hop option header. */
36#define NEXTHDR_TCP 6 /* TCP segment. */
37#define NEXTHDR_UDP 17 /* UDP message. */
38#define NEXTHDR_IPV6 41 /* IPv6 in IPv6 */
39#define NEXTHDR_ROUTING 43 /* Routing header. */
40#define NEXTHDR_FRAGMENT 44 /* Fragmentation/reassembly header. */
c12b395a 41#define NEXTHDR_GRE 47 /* GRE header. */
1da177e4
LT
42#define NEXTHDR_ESP 50 /* Encapsulating security payload. */
43#define NEXTHDR_AUTH 51 /* Authentication header. */
44#define NEXTHDR_ICMP 58 /* ICMP for IPv6. */
45#define NEXTHDR_NONE 59 /* No next header */
46#define NEXTHDR_DEST 60 /* Destination options header. */
280c571e 47#define NEXTHDR_SCTP 132 /* SCTP message. */
2b741653 48#define NEXTHDR_MOBILITY 135 /* Mobility header. */
1da177e4
LT
49
50#define NEXTHDR_MAX 255
51
1da177e4
LT
52#define IPV6_DEFAULT_HOPLIMIT 64
53#define IPV6_DEFAULT_MCASTHOPS 1
54
47d3d7ac
TH
55/* Limits on Hop-by-Hop and Destination options.
56 *
57 * Per RFC8200 there is no limit on the maximum number or lengths of options in
58 * Hop-by-Hop or Destination options other then the packet must fit in an MTU.
59 * We allow configurable limits in order to mitigate potential denial of
60 * service attacks.
61 *
62 * There are three limits that may be set:
63 * - Limit the number of options in a Hop-by-Hop or Destination options
64 * extension header
65 * - Limit the byte length of a Hop-by-Hop or Destination options extension
66 * header
67 * - Disallow unknown options
68 *
69 * The limits are expressed in corresponding sysctls:
70 *
71 * ipv6.sysctl.max_dst_opts_cnt
72 * ipv6.sysctl.max_hbh_opts_cnt
73 * ipv6.sysctl.max_dst_opts_len
74 * ipv6.sysctl.max_hbh_opts_len
75 *
76 * max_*_opts_cnt is the number of TLVs that are allowed for Destination
77 * options or Hop-by-Hop options. If the number is less than zero then unknown
78 * TLVs are disallowed and the number of known options that are allowed is the
79 * absolute value. Setting the value to INT_MAX indicates no limit.
80 *
81 * max_*_opts_len is the length limit in bytes of a Destination or
82 * Hop-by-Hop options extension header. Setting the value to INT_MAX
83 * indicates no length limit.
84 *
85 * If a limit is exceeded when processing an extension header the packet is
86 * silently discarded.
87 */
88
89/* Default limits for Hop-by-Hop and Destination options */
90#define IP6_DEFAULT_MAX_DST_OPTS_CNT 8
91#define IP6_DEFAULT_MAX_HBH_OPTS_CNT 8
92#define IP6_DEFAULT_MAX_DST_OPTS_LEN INT_MAX /* No limit */
93#define IP6_DEFAULT_MAX_HBH_OPTS_LEN INT_MAX /* No limit */
94
1da177e4
LT
95/*
96 * Addr type
97 *
98 * type - unicast | multicast
99 * scope - local | site | global
100 * v4 - compat
101 * v4mapped
102 * any
103 * loopback
104 */
105
106#define IPV6_ADDR_ANY 0x0000U
107
82695b30
SH
108#define IPV6_ADDR_UNICAST 0x0001U
109#define IPV6_ADDR_MULTICAST 0x0002U
1da177e4
LT
110
111#define IPV6_ADDR_LOOPBACK 0x0010U
112#define IPV6_ADDR_LINKLOCAL 0x0020U
113#define IPV6_ADDR_SITELOCAL 0x0040U
114
115#define IPV6_ADDR_COMPATv4 0x0080U
116
117#define IPV6_ADDR_SCOPE_MASK 0x00f0U
118
119#define IPV6_ADDR_MAPPED 0x1000U
1da177e4
LT
120
121/*
122 * Addr scopes
123 */
1da177e4
LT
124#define IPV6_ADDR_MC_SCOPE(a) \
125 ((a)->s6_addr[1] & 0x0f) /* nonstandard */
126#define __IPV6_ADDR_SCOPE_INVALID -1
1da177e4
LT
127#define IPV6_ADDR_SCOPE_NODELOCAL 0x01
128#define IPV6_ADDR_SCOPE_LINKLOCAL 0x02
129#define IPV6_ADDR_SCOPE_SITELOCAL 0x05
130#define IPV6_ADDR_SCOPE_ORGLOCAL 0x08
131#define IPV6_ADDR_SCOPE_GLOBAL 0x0e
132
5ced1339
LL
133/*
134 * Addr flags
135 */
5ced1339
LL
136#define IPV6_ADDR_MC_FLAG_TRANSIENT(a) \
137 ((a)->s6_addr[1] & 0x10)
138#define IPV6_ADDR_MC_FLAG_PREFIX(a) \
139 ((a)->s6_addr[1] & 0x20)
140#define IPV6_ADDR_MC_FLAG_RENDEZVOUS(a) \
141 ((a)->s6_addr[1] & 0x40)
5ced1339 142
1da177e4
LT
143/*
144 * fragmentation header
145 */
146
147struct frag_hdr {
44473a6b
AV
148 __u8 nexthdr;
149 __u8 reserved;
150 __be16 frag_off;
151 __be32 identification;
1da177e4
LT
152};
153
1431fb31
PD
154#define IP6_MF 0x0001
155#define IP6_OFFSET 0xFFF8
1da177e4 156
0feca619
PNA
157struct ip6_fraglist_iter {
158 struct ipv6hdr *tmp_hdr;
159 struct sk_buff *frag_list;
160 struct sk_buff *frag;
161 int offset;
162 unsigned int hlen;
163 __be32 frag_id;
164 u8 nexthdr;
165};
166
167int ip6_fraglist_init(struct sk_buff *skb, unsigned int hlen, u8 *prevhdr,
168 u8 nexthdr, __be32 frag_id,
169 struct ip6_fraglist_iter *iter);
170void ip6_fraglist_prepare(struct sk_buff *skb, struct ip6_fraglist_iter *iter);
171
172static inline struct sk_buff *ip6_fraglist_next(struct ip6_fraglist_iter *iter)
173{
174 struct sk_buff *skb = iter->frag;
175
176 iter->frag = skb->next;
177 skb_mark_not_on_list(skb);
178
179 return skb;
180}
181
e110861f
LC
182#define IP6_REPLY_MARK(net, mark) \
183 ((net)->ipv6.sysctl.fwmark_reflect ? (mark) : 0)
184
1da177e4
LT
185#include <net/sock.h>
186
187/* sysctls */
1da177e4 188extern int sysctl_mld_max_msf;
2f711939 189extern int sysctl_mld_qrv;
3d7cc2ba 190
13415e46 191#define _DEVINC(net, statname, mod, idev, field) \
14878f75 192({ \
a11d206d
YH
193 struct inet6_dev *_idev = (idev); \
194 if (likely(_idev != NULL)) \
13415e46
ED
195 mod##SNMP_INC_STATS64((_idev)->stats.statname, (field));\
196 mod##SNMP_INC_STATS64((net)->mib.statname##_statistics, (field));\
a11d206d 197})
14878f75 198
be281e55 199/* per device counters are atomic_long_t */
13415e46 200#define _DEVINCATOMIC(net, statname, mod, idev, field) \
be281e55
ED
201({ \
202 struct inet6_dev *_idev = (idev); \
203 if (likely(_idev != NULL)) \
204 SNMP_INC_STATS_ATOMIC_LONG((_idev)->stats.statname##dev, (field)); \
13415e46 205 mod##SNMP_INC_STATS((net)->mib.statname##_statistics, (field));\
be281e55
ED
206})
207
2a24444f
ED
208/* per device and per net counters are atomic_long_t */
209#define _DEVINC_ATOMIC_ATOMIC(net, statname, idev, field) \
210({ \
211 struct inet6_dev *_idev = (idev); \
212 if (likely(_idev != NULL)) \
213 SNMP_INC_STATS_ATOMIC_LONG((_idev)->stats.statname##dev, (field)); \
214 SNMP_INC_STATS_ATOMIC_LONG((net)->mib.statname##_statistics, (field));\
215})
216
13415e46 217#define _DEVADD(net, statname, mod, idev, field, val) \
8e7999c4
PE
218({ \
219 struct inet6_dev *_idev = (idev); \
220 if (likely(_idev != NULL)) \
13415e46
ED
221 mod##SNMP_ADD_STATS((_idev)->stats.statname, (field), (val)); \
222 mod##SNMP_ADD_STATS((net)->mib.statname##_statistics, (field), (val));\
8e7999c4
PE
223})
224
13415e46 225#define _DEVUPD(net, statname, mod, idev, field, val) \
edf391ff
NH
226({ \
227 struct inet6_dev *_idev = (idev); \
228 if (likely(_idev != NULL)) \
13415e46
ED
229 mod##SNMP_UPD_PO_STATS((_idev)->stats.statname, field, (val)); \
230 mod##SNMP_UPD_PO_STATS((net)->mib.statname##_statistics, field, (val));\
edf391ff
NH
231})
232
14878f75 233/* MIBs */
14878f75 234
087fe240 235#define IP6_INC_STATS(net, idev,field) \
13415e46 236 _DEVINC(net, ipv6, , idev, field)
1d015503 237#define __IP6_INC_STATS(net, idev,field) \
13415e46 238 _DEVINC(net, ipv6, __, idev, field)
edf391ff 239#define IP6_ADD_STATS(net, idev,field,val) \
13415e46 240 _DEVADD(net, ipv6, , idev, field, val)
1d015503 241#define __IP6_ADD_STATS(net, idev,field,val) \
13415e46 242 _DEVADD(net, ipv6, __, idev, field, val)
edf391ff 243#define IP6_UPD_PO_STATS(net, idev,field,val) \
13415e46 244 _DEVUPD(net, ipv6, , idev, field, val)
c2005eb0 245#define __IP6_UPD_PO_STATS(net, idev,field,val) \
13415e46 246 _DEVUPD(net, ipv6, __, idev, field, val)
087fe240 247#define ICMP6_INC_STATS(net, idev, field) \
be281e55 248 _DEVINCATOMIC(net, icmpv6, , idev, field)
a16292a0 249#define __ICMP6_INC_STATS(net, idev, field) \
13415e46 250 _DEVINCATOMIC(net, icmpv6, __, idev, field)
087fe240
DL
251
252#define ICMP6MSGOUT_INC_STATS(net, idev, field) \
2a24444f 253 _DEVINC_ATOMIC_ATOMIC(net, icmpv6msg, idev, field +256)
f3832ed2 254#define ICMP6MSGIN_INC_STATS(net, idev, field) \
2a24444f 255 _DEVINC_ATOMIC_ATOMIC(net, icmpv6msg, idev, field)
14878f75 256
fd2c3ef7 257struct ip6_ra_chain {
1da177e4
LT
258 struct ip6_ra_chain *next;
259 struct sock *sk;
260 int sel;
261 void (*destructor)(struct sock *);
262};
263
264extern struct ip6_ra_chain *ip6_ra_chain;
265extern rwlock_t ip6_ra_lock;
266
267/*
268 This structure is prepared by protocol, when parsing
269 ancillary data and passed to IPv6.
270 */
271
fd2c3ef7 272struct ipv6_txoptions {
0aeea21a 273 refcount_t refcnt;
1da177e4
LT
274 /* Length of this structure */
275 int tot_len;
276
277 /* length of extension headers */
278
279 __u16 opt_flen; /* after fragment hdr */
280 __u16 opt_nflen; /* before fragment hdr */
281
282 struct ipv6_opt_hdr *hopopt;
283 struct ipv6_opt_hdr *dst0opt;
284 struct ipv6_rt_hdr *srcrt; /* Routing Header */
1da177e4 285 struct ipv6_opt_hdr *dst1opt;
45f6fad8 286 struct rcu_head rcu;
1da177e4
LT
287 /* Option buffer, as read by IPV6_PKTOPTIONS, starts here. */
288};
289
fd2c3ef7 290struct ip6_flowlabel {
7f0e44ac 291 struct ip6_flowlabel __rcu *next;
90bcaf7b 292 __be32 label;
db3459d1 293 atomic_t users;
1da177e4
LT
294 struct in6_addr dst;
295 struct ipv6_txoptions *opt;
1da177e4 296 unsigned long linger;
d3aedd5e 297 struct rcu_head rcu;
1da177e4 298 u8 share;
4f82f457
EB
299 union {
300 struct pid *pid;
301 kuid_t uid;
302 } owner;
1da177e4
LT
303 unsigned long lastuse;
304 unsigned long expires;
60e8fbc4 305 struct net *fl_net;
1da177e4
LT
306};
307
82a584b7
TH
308#define IPV6_FLOWINFO_MASK cpu_to_be32(0x0FFFFFFF)
309#define IPV6_FLOWLABEL_MASK cpu_to_be32(0x000FFFFF)
310#define IPV6_FLOWLABEL_STATELESS_FLAG cpu_to_be32(0x00080000)
311
37cfee90 312#define IPV6_TCLASS_MASK (IPV6_FLOWINFO_MASK & ~IPV6_FLOWLABEL_MASK)
d76ed22b 313#define IPV6_TCLASS_SHIFT 20
1da177e4 314
fd2c3ef7 315struct ipv6_fl_socklist {
7f0e44ac
ED
316 struct ipv6_fl_socklist __rcu *next;
317 struct ip6_flowlabel *fl;
318 struct rcu_head rcu;
1da177e4
LT
319};
320
26879da5 321struct ipcm6_cookie {
5fdaa88d 322 struct sockcm_cookie sockc;
26879da5
WW
323 __s16 hlimit;
324 __s16 tclass;
325 __s8 dontfrag;
326 struct ipv6_txoptions *opt;
bec1f6f6 327 __u16 gso_size;
26879da5
WW
328};
329
b515430a
WB
330static inline void ipcm6_init(struct ipcm6_cookie *ipc6)
331{
332 *ipc6 = (struct ipcm6_cookie) {
333 .hlimit = -1,
334 .tclass = -1,
335 .dontfrag = -1,
336 };
337}
338
339static inline void ipcm6_init_sk(struct ipcm6_cookie *ipc6,
340 const struct ipv6_pinfo *np)
341{
342 *ipc6 = (struct ipcm6_cookie) {
343 .hlimit = -1,
344 .tclass = np->tclass,
345 .dontfrag = np->dontfrag,
346 };
347}
348
45f6fad8
ED
349static inline struct ipv6_txoptions *txopt_get(const struct ipv6_pinfo *np)
350{
351 struct ipv6_txoptions *opt;
352
353 rcu_read_lock();
354 opt = rcu_dereference(np->opt);
e550785c 355 if (opt) {
0aeea21a 356 if (!refcount_inc_not_zero(&opt->refcnt))
e550785c
BP
357 opt = NULL;
358 else
359 opt = rcu_pointer_handoff(opt);
360 }
45f6fad8
ED
361 rcu_read_unlock();
362 return opt;
363}
364
365static inline void txopt_put(struct ipv6_txoptions *opt)
366{
0aeea21a 367 if (opt && refcount_dec_and_test(&opt->refcnt))
45f6fad8
ED
368 kfree_rcu(opt, rcu);
369}
370
5c3a0fd7
JP
371struct ip6_flowlabel *fl6_sock_lookup(struct sock *sk, __be32 label);
372struct ipv6_txoptions *fl6_merge_options(struct ipv6_txoptions *opt_space,
373 struct ip6_flowlabel *fl,
374 struct ipv6_txoptions *fopt);
375void fl6_free_socklist(struct sock *sk);
376int ipv6_flowlabel_opt(struct sock *sk, char __user *optval, int optlen);
46e5f401
FF
377int ipv6_flowlabel_opt_get(struct sock *sk, struct in6_flowlabel_req *freq,
378 int flags);
5c3a0fd7
JP
379int ip6_flowlabel_init(void);
380void ip6_flowlabel_cleanup(void);
e9191ffb 381bool ip6_autoflowlabel(struct net *net, const struct ipv6_pinfo *np);
1da177e4
LT
382
383static inline void fl6_sock_release(struct ip6_flowlabel *fl)
384{
385 if (fl)
386 atomic_dec(&fl->users);
387}
388
5c3a0fd7 389void icmpv6_notify(struct sk_buff *skb, u8 type, u8 code, __be32 info);
b94f1c09 390
4e64b1ed
JP
391void icmpv6_push_pending_frames(struct sock *sk, struct flowi6 *fl6,
392 struct icmp6hdr *thdr, int len);
6d0bfe22 393
5c3a0fd7 394int ip6_ra_control(struct sock *sk, int sel);
1da177e4 395
5c3a0fd7 396int ipv6_parse_hopopts(struct sk_buff *skb);
1da177e4 397
5c3a0fd7
JP
398struct ipv6_txoptions *ipv6_dup_options(struct sock *sk,
399 struct ipv6_txoptions *opt);
400struct ipv6_txoptions *ipv6_renew_options(struct sock *sk,
401 struct ipv6_txoptions *opt,
402 int newtype,
a9ba23d4 403 struct ipv6_opt_hdr *newopt);
df9890c3
YH
404struct ipv6_txoptions *ipv6_fixup_options(struct ipv6_txoptions *opt_space,
405 struct ipv6_txoptions *opt);
1da177e4 406
a224772d
ED
407bool ipv6_opt_accepted(const struct sock *sk, const struct sk_buff *skb,
408 const struct inet6_skb_parm *opt);
ceba1832
HD
409struct ipv6_txoptions *ipv6_update_options(struct sock *sk,
410 struct ipv6_txoptions *opt);
399c07de 411
aeaf6e9d
SL
412static inline bool ipv6_accept_ra(struct inet6_dev *idev)
413{
414 /* If forwarding is enabled, RA are not accepted unless the special
415 * hybrid mode (accept_ra=2) is enabled.
416 */
417 return idev->cnf.forwarding ? idev->cnf.accept_ra == 2 :
418 idev->cnf.accept_ra;
419}
420
c2a93660
JDB
421#define IPV6_FRAG_HIGH_THRESH (4 * 1024*1024) /* 4194304 */
422#define IPV6_FRAG_LOW_THRESH (3 * 1024*1024) /* 3145728 */
9874c41c 423#define IPV6_FRAG_TIMEOUT (60 * HZ) /* 60 seconds */
1da177e4 424
5c3a0fd7 425int __ipv6_addr_type(const struct in6_addr *addr);
b1cacb68
YH
426static inline int ipv6_addr_type(const struct in6_addr *addr)
427{
428 return __ipv6_addr_type(addr) & 0xffff;
429}
1da177e4
LT
430
431static inline int ipv6_addr_scope(const struct in6_addr *addr)
432{
b1cacb68
YH
433 return __ipv6_addr_type(addr) & IPV6_ADDR_SCOPE_MASK;
434}
435
436static inline int __ipv6_addr_src_scope(int type)
437{
a02cec21 438 return (type == IPV6_ADDR_ANY) ? __IPV6_ADDR_SCOPE_INVALID : (type >> 16);
b1cacb68
YH
439}
440
441static inline int ipv6_addr_src_scope(const struct in6_addr *addr)
442{
443 return __ipv6_addr_src_scope(__ipv6_addr_type(addr));
1da177e4
LT
444}
445
b7ef213e
HFS
446static inline bool __ipv6_addr_needs_scope_id(int type)
447{
448 return type & IPV6_ADDR_LINKLOCAL ||
449 (type & IPV6_ADDR_MULTICAST &&
450 (type & (IPV6_ADDR_LOOPBACK|IPV6_ADDR_LINKLOCAL)));
451}
452
453static inline __u32 ipv6_iface_scope_id(const struct in6_addr *addr, int iface)
454{
455 return __ipv6_addr_needs_scope_id(__ipv6_addr_type(addr)) ? iface : 0;
456}
457
1da177e4
LT
458static inline int ipv6_addr_cmp(const struct in6_addr *a1, const struct in6_addr *a2)
459{
db3459d1 460 return memcmp(a1, a2, sizeof(struct in6_addr));
1da177e4
LT
461}
462
1a203cb3 463static inline bool
f2ffd9ee
PM
464ipv6_masked_addr_cmp(const struct in6_addr *a1, const struct in6_addr *m,
465 const struct in6_addr *a2)
466{
1a203cb3
ED
467#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
468 const unsigned long *ul1 = (const unsigned long *)a1;
469 const unsigned long *ulm = (const unsigned long *)m;
470 const unsigned long *ul2 = (const unsigned long *)a2;
471
472 return !!(((ul1[0] ^ ul2[0]) & ulm[0]) |
473 ((ul1[1] ^ ul2[1]) & ulm[1]));
474#else
a02cec21
ED
475 return !!(((a1->s6_addr32[0] ^ a2->s6_addr32[0]) & m->s6_addr32[0]) |
476 ((a1->s6_addr32[1] ^ a2->s6_addr32[1]) & m->s6_addr32[1]) |
477 ((a1->s6_addr32[2] ^ a2->s6_addr32[2]) & m->s6_addr32[2]) |
478 ((a1->s6_addr32[3] ^ a2->s6_addr32[3]) & m->s6_addr32[3]));
1a203cb3 479#endif
f2ffd9ee
PM
480}
481
82695b30 482static inline void ipv6_addr_prefix(struct in6_addr *pfx,
1da177e4
LT
483 const struct in6_addr *addr,
484 int plen)
485{
486 /* caller must guarantee 0 <= plen <= 128 */
487 int o = plen >> 3,
488 b = plen & 0x7;
489
db3459d1 490 memset(pfx->s6_addr, 0, sizeof(pfx->s6_addr));
1da177e4 491 memcpy(pfx->s6_addr, addr, o);
db3459d1 492 if (b != 0)
1da177e4 493 pfx->s6_addr[o] = addr->s6_addr[o] & (0xff00 >> b);
1da177e4
LT
494}
495
818f1f3e
AA
496static inline void ipv6_addr_prefix_copy(struct in6_addr *addr,
497 const struct in6_addr *pfx,
498 int plen)
499{
500 /* caller must guarantee 0 <= plen <= 128 */
501 int o = plen >> 3,
502 b = plen & 0x7;
503
504 memcpy(addr->s6_addr, pfx, o);
505 if (b != 0) {
506 addr->s6_addr[o] &= ~(0xff00 >> b);
507 addr->s6_addr[o] |= (pfx->s6_addr[o] & (0xff00 >> b));
508 }
509}
510
5206c579
YH
511static inline void __ipv6_addr_set_half(__be32 *addr,
512 __be32 wh, __be32 wl)
513{
514#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
515#if defined(__BIG_ENDIAN)
516 if (__builtin_constant_p(wh) && __builtin_constant_p(wl)) {
517 *(__force u64 *)addr = ((__force u64)(wh) << 32 | (__force u64)(wl));
518 return;
519 }
520#elif defined(__LITTLE_ENDIAN)
521 if (__builtin_constant_p(wl) && __builtin_constant_p(wh)) {
522 *(__force u64 *)addr = ((__force u64)(wl) << 32 | (__force u64)(wh));
523 return;
524 }
525#endif
526#endif
527 addr[0] = wh;
528 addr[1] = wl;
529}
530
82695b30 531static inline void ipv6_addr_set(struct in6_addr *addr,
48818f82
AV
532 __be32 w1, __be32 w2,
533 __be32 w3, __be32 w4)
1da177e4 534{
5206c579
YH
535 __ipv6_addr_set_half(&addr->s6_addr32[0], w1, w2);
536 __ipv6_addr_set_half(&addr->s6_addr32[2], w3, w4);
1da177e4 537}
1da177e4 538
92113bfd
ED
539static inline bool ipv6_addr_equal(const struct in6_addr *a1,
540 const struct in6_addr *a2)
1da177e4 541{
1a203cb3
ED
542#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
543 const unsigned long *ul1 = (const unsigned long *)a1;
544 const unsigned long *ul2 = (const unsigned long *)a2;
545
546 return ((ul1[0] ^ ul2[0]) | (ul1[1] ^ ul2[1])) == 0UL;
547#else
a02cec21
ED
548 return ((a1->s6_addr32[0] ^ a2->s6_addr32[0]) |
549 (a1->s6_addr32[1] ^ a2->s6_addr32[1]) |
550 (a1->s6_addr32[2] ^ a2->s6_addr32[2]) |
551 (a1->s6_addr32[3] ^ a2->s6_addr32[3])) == 0;
1a203cb3 552#endif
1da177e4
LT
553}
554
38675170
YH
555#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
556static inline bool __ipv6_prefix_equal64_half(const __be64 *a1,
557 const __be64 *a2,
558 unsigned int len)
559{
512613d7 560 if (len && ((*a1 ^ *a2) & cpu_to_be64((~0UL) << (64 - len))))
38675170
YH
561 return false;
562 return true;
563}
564
565static inline bool ipv6_prefix_equal(const struct in6_addr *addr1,
566 const struct in6_addr *addr2,
567 unsigned int prefixlen)
568{
569 const __be64 *a1 = (const __be64 *)addr1;
570 const __be64 *a2 = (const __be64 *)addr2;
571
572 if (prefixlen >= 64) {
573 if (a1[0] ^ a2[0])
574 return false;
575 return __ipv6_prefix_equal64_half(a1 + 1, a2 + 1, prefixlen - 64);
576 }
577 return __ipv6_prefix_equal64_half(a1, a2, prefixlen);
578}
579#else
2ef97332
YH
580static inline bool ipv6_prefix_equal(const struct in6_addr *addr1,
581 const struct in6_addr *addr2,
582 unsigned int prefixlen)
1da177e4 583{
2ef97332
YH
584 const __be32 *a1 = addr1->s6_addr32;
585 const __be32 *a2 = addr2->s6_addr32;
95c96174 586 unsigned int pdw, pbi;
1da177e4
LT
587
588 /* check complete u32 in prefix */
589 pdw = prefixlen >> 5;
590 if (pdw && memcmp(a1, a2, pdw << 2))
92113bfd 591 return false;
1da177e4
LT
592
593 /* check incomplete u32 in prefix */
594 pbi = prefixlen & 0x1f;
595 if (pbi && ((a1[pdw] ^ a2[pdw]) & htonl((0xffffffff) << (32 - pbi))))
92113bfd 596 return false;
1da177e4 597
92113bfd 598 return true;
1da177e4 599}
38675170 600#endif
1da177e4 601
92113bfd 602static inline bool ipv6_addr_any(const struct in6_addr *a)
1da177e4 603{
1a203cb3
ED
604#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
605 const unsigned long *ul = (const unsigned long *)a;
606
607 return (ul[0] | ul[1]) == 0UL;
608#else
a02cec21
ED
609 return (a->s6_addr32[0] | a->s6_addr32[1] |
610 a->s6_addr32[2] | a->s6_addr32[3]) == 0;
1a203cb3 611#endif
1da177e4
LT
612}
613
ddbe5032
ED
614static inline u32 ipv6_addr_hash(const struct in6_addr *a)
615{
616#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
617 const unsigned long *ul = (const unsigned long *)a;
618 unsigned long x = ul[0] ^ ul[1];
619
620 return (u32)(x ^ (x >> 32));
621#else
622 return (__force u32)(a->s6_addr32[0] ^ a->s6_addr32[1] ^
623 a->s6_addr32[2] ^ a->s6_addr32[3]);
624#endif
625}
626
08dcdbf6 627/* more secured version of ipv6_addr_hash() */
b50026b5 628static inline u32 __ipv6_addr_jhash(const struct in6_addr *a, const u32 initval)
08dcdbf6
ED
629{
630 u32 v = (__force u32)a->s6_addr32[0] ^ (__force u32)a->s6_addr32[1];
631
632 return jhash_3words(v,
633 (__force u32)a->s6_addr32[2],
634 (__force u32)a->s6_addr32[3],
b50026b5 635 initval);
08dcdbf6
ED
636}
637
92113bfd 638static inline bool ipv6_addr_loopback(const struct in6_addr *a)
f630e43a 639{
e287656b 640#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
1373a773 641 const __be64 *be = (const __be64 *)a;
e287656b 642
1373a773 643 return (be[0] | (be[1] ^ cpu_to_be64(1))) == 0UL;
e287656b 644#else
a02cec21 645 return (a->s6_addr32[0] | a->s6_addr32[1] |
1373a773 646 a->s6_addr32[2] | (a->s6_addr32[3] ^ cpu_to_be32(1))) == 0;
e287656b 647#endif
f630e43a
YH
648}
649
1373a773
JL
650/*
651 * Note that we must __force cast these to unsigned long to make sparse happy,
652 * since all of the endian-annotated types are fixed size regardless of arch.
653 */
92113bfd 654static inline bool ipv6_addr_v4mapped(const struct in6_addr *a)
e773e4fa 655{
a04d40b8
YH
656 return (
657#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
1373a773 658 *(unsigned long *)a |
a04d40b8 659#else
1373a773 660 (__force unsigned long)(a->s6_addr32[0] | a->s6_addr32[1]) |
a04d40b8 661#endif
1373a773
JL
662 (__force unsigned long)(a->s6_addr32[2] ^
663 cpu_to_be32(0x0000ffff))) == 0UL;
e773e4fa
BH
664}
665
f0b1e64c
MKL
666static inline u32 ipv6_portaddr_hash(const struct net *net,
667 const struct in6_addr *addr6,
668 unsigned int port)
669{
670 unsigned int hash, mix = net_hash_mix(net);
671
672 if (ipv6_addr_any(addr6))
673 hash = jhash_1word(0, mix);
674 else if (ipv6_addr_v4mapped(addr6))
675 hash = jhash_1word((__force u32)addr6->s6_addr32[3], mix);
676 else
677 hash = jhash2((__force u32 *)addr6->s6_addr32, 4, mix);
678
679 return hash ^ port;
680}
681
99cd07a5
JMT
682/*
683 * Check for a RFC 4843 ORCHID address
684 * (Overlay Routable Cryptographic Hash Identifiers)
685 */
92113bfd 686static inline bool ipv6_addr_orchid(const struct in6_addr *a)
99cd07a5 687{
a02cec21 688 return (a->s6_addr32[0] & htonl(0xfffffff0)) == htonl(0x20010010);
99cd07a5
JMT
689}
690
5c98631c
LC
691static inline bool ipv6_addr_is_multicast(const struct in6_addr *addr)
692{
693 return (addr->s6_addr32[0] & htonl(0xFF000000)) == htonl(0xFF000000);
694}
695
f15364bd
AC
696static inline void ipv6_addr_set_v4mapped(const __be32 addr,
697 struct in6_addr *v4mapped)
698{
699 ipv6_addr_set(v4mapped,
700 0, 0,
701 htonl(0x0000FFFF),
702 addr);
703}
704
971f359d
YH
705/*
706 * find the first different bit between two addresses
707 * length of address must be a multiple of 32bits
708 */
9f2e7334 709static inline int __ipv6_addr_diff32(const void *token1, const void *token2, int addrlen)
971f359d 710{
ef296f56 711 const __be32 *a1 = token1, *a2 = token2;
971f359d
YH
712 int i;
713
714 addrlen >>= 2;
715
716 for (i = 0; i < addrlen; i++) {
ef296f56
AV
717 __be32 xb = a1[i] ^ a2[i];
718 if (xb)
d57b8fb8 719 return i * 32 + 31 - __fls(ntohl(xb));
971f359d
YH
720 }
721
722 /*
82695b30 723 * we should *never* get to this point since that
971f359d
YH
724 * would mean the addrs are equal
725 *
726 * However, we do get to it 8) And exacly, when
727 * addresses are equal 8)
728 *
729 * ip route add 1111::/128 via ...
730 * ip route add 1111::/64 via ...
731 * and we are here.
732 *
733 * Ideally, this function should stop comparison
734 * at prefix length. It does not, but it is still OK,
735 * if returned value is greater than prefix length.
736 * --ANK (980803)
737 */
a02cec21 738 return addrlen << 5;
971f359d
YH
739}
740
9f2e7334
YH
741#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
742static inline int __ipv6_addr_diff64(const void *token1, const void *token2, int addrlen)
743{
744 const __be64 *a1 = token1, *a2 = token2;
745 int i;
746
747 addrlen >>= 3;
748
749 for (i = 0; i < addrlen; i++) {
750 __be64 xb = a1[i] ^ a2[i];
751 if (xb)
752 return i * 64 + 63 - __fls(be64_to_cpu(xb));
753 }
754
755 return addrlen << 6;
756}
757#endif
758
759static inline int __ipv6_addr_diff(const void *token1, const void *token2, int addrlen)
760{
761#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
762 if (__builtin_constant_p(addrlen) && !(addrlen & 7))
763 return __ipv6_addr_diff64(token1, token2, addrlen);
764#endif
765 return __ipv6_addr_diff32(token1, token2, addrlen);
766}
767
971f359d
YH
768static inline int ipv6_addr_diff(const struct in6_addr *a1, const struct in6_addr *a2)
769{
770 return __ipv6_addr_diff(a1, a2, sizeof(struct in6_addr));
771}
772
7f159867
ED
773__be32 ipv6_select_ident(struct net *net,
774 const struct in6_addr *daddr,
775 const struct in6_addr *saddr);
0c19f846 776__be32 ipv6_proxy_select_ident(struct net *net, struct sk_buff *skb);
5188cd44 777
5c3a0fd7 778int ip6_dst_hoplimit(struct dst_entry *dst);
3ce9b35f 779
5c98631c
LC
780static inline int ip6_sk_dst_hoplimit(struct ipv6_pinfo *np, struct flowi6 *fl6,
781 struct dst_entry *dst)
782{
783 int hlimit;
784
785 if (ipv6_addr_is_multicast(&fl6->daddr))
786 hlimit = np->mcast_hops;
787 else
788 hlimit = np->hop_limit;
789 if (hlimit < 0)
790 hlimit = ip6_dst_hoplimit(dst);
791 return hlimit;
792}
793
c3f83241
TH
794/* copy IPv6 saddr & daddr to flow_keys, possibly using 64bit load/store
795 * Equivalent to : flow->v6addrs.src = iph->saddr;
796 * flow->v6addrs.dst = iph->daddr;
797 */
798static inline void iph_to_flow_copy_v6addrs(struct flow_keys *flow,
799 const struct ipv6hdr *iph)
800{
801 BUILD_BUG_ON(offsetof(typeof(flow->addrs), v6addrs.dst) !=
802 offsetof(typeof(flow->addrs), v6addrs.src) +
803 sizeof(flow->addrs.v6addrs.src));
804 memcpy(&flow->addrs.v6addrs, &iph->saddr, sizeof(flow->addrs.v6addrs));
805 flow->control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
806}
807
a37934fc 808#if IS_ENABLED(CONFIG_IPV6)
42240901 809
db57dc7c
VB
810static inline bool ipv6_can_nonlocal_bind(struct net *net,
811 struct inet_sock *inet)
812{
813 return net->ipv6.sysctl.ip_nonlocal_bind ||
814 inet->freebind || inet->transparent;
815}
816
42240901
TH
817/* Sysctl settings for net ipv6.auto_flowlabels */
818#define IP6_AUTO_FLOW_LABEL_OFF 0
819#define IP6_AUTO_FLOW_LABEL_OPTOUT 1
820#define IP6_AUTO_FLOW_LABEL_OPTIN 2
821#define IP6_AUTO_FLOW_LABEL_FORCED 3
822
823#define IP6_AUTO_FLOW_LABEL_MAX IP6_AUTO_FLOW_LABEL_FORCED
824
b5677416 825#define IP6_DEFAULT_AUTO_FLOW_LABELS IP6_AUTO_FLOW_LABEL_OPTOUT
42240901 826
cb1ce2ef 827static inline __be32 ip6_make_flowlabel(struct net *net, struct sk_buff *skb,
67800f9b
TH
828 __be32 flowlabel, bool autolabel,
829 struct flowi6 *fl6)
cb1ce2ef 830{
42240901 831 u32 hash;
cb1ce2ef 832
90427ef5
DM
833 /* @flowlabel may include more than a flow label, eg, the traffic class.
834 * Here we want only the flow label value.
835 */
836 flowlabel &= IPV6_FLOWLABEL_MASK;
837
42240901
TH
838 if (flowlabel ||
839 net->ipv6.sysctl.auto_flowlabels == IP6_AUTO_FLOW_LABEL_OFF ||
840 (!autolabel &&
841 net->ipv6.sysctl.auto_flowlabels != IP6_AUTO_FLOW_LABEL_FORCED))
842 return flowlabel;
cb1ce2ef 843
42240901 844 hash = skb_get_hash_flowi6(skb, fl6);
cb1ce2ef 845
42240901
TH
846 /* Since this is being sent on the wire obfuscate hash a bit
847 * to minimize possbility that any useful information to an
848 * attacker is leaked. Only lower 20 bits are relevant.
849 */
169dc027 850 hash = rol32(hash, 16);
82a584b7 851
42240901
TH
852 flowlabel = (__force __be32)hash & IPV6_FLOWLABEL_MASK;
853
854 if (net->ipv6.sysctl.flowlabel_state_ranges)
855 flowlabel |= IPV6_FLOWLABEL_STATELESS_FLAG;
cb1ce2ef
TH
856
857 return flowlabel;
858}
42240901
TH
859
860static inline int ip6_default_np_autolabel(struct net *net)
861{
862 switch (net->ipv6.sysctl.auto_flowlabels) {
863 case IP6_AUTO_FLOW_LABEL_OFF:
864 case IP6_AUTO_FLOW_LABEL_OPTIN:
865 default:
866 return 0;
867 case IP6_AUTO_FLOW_LABEL_OPTOUT:
868 case IP6_AUTO_FLOW_LABEL_FORCED:
869 return 1;
870 }
871}
a37934fc
FF
872#else
873static inline void ip6_set_txhash(struct sock *sk) { }
874static inline __be32 ip6_make_flowlabel(struct net *net, struct sk_buff *skb,
42240901
TH
875 __be32 flowlabel, bool autolabel,
876 struct flowi6 *fl6)
a37934fc
FF
877{
878 return flowlabel;
879}
42240901
TH
880static inline int ip6_default_np_autolabel(struct net *net)
881{
882 return 0;
883}
a37934fc
FF
884#endif
885
918ee507
PM
886#if IS_ENABLED(CONFIG_IPV6)
887static inline int ip6_multipath_hash_policy(const struct net *net)
888{
889 return net->ipv6.sysctl.multipath_hash_policy;
890}
891#else
892static inline int ip6_multipath_hash_policy(const struct net *net)
893{
894 return 0;
895}
896#endif
cb1ce2ef 897
3e4e4c1f
YH
898/*
899 * Header manipulation
900 */
901static inline void ip6_flow_hdr(struct ipv6hdr *hdr, unsigned int tclass,
902 __be32 flowlabel)
903{
07f623d3 904 *(__be32 *)hdr = htonl(0x60000000 | (tclass << 20)) | flowlabel;
3e4e4c1f
YH
905}
906
6502ca52
YH
907static inline __be32 ip6_flowinfo(const struct ipv6hdr *hdr)
908{
909 return *(__be32 *)hdr & IPV6_FLOWINFO_MASK;
910}
911
3308de2b
FF
912static inline __be32 ip6_flowlabel(const struct ipv6hdr *hdr)
913{
914 return *(__be32 *)hdr & IPV6_FLOWLABEL_MASK;
915}
916
d76ed22b
LR
917static inline u8 ip6_tclass(__be32 flowinfo)
918{
919 return ntohl(flowinfo & IPV6_TCLASS_MASK) >> IPV6_TCLASS_SHIFT;
920}
eaa93bf4
DB
921
922static inline __be32 ip6_make_flowinfo(unsigned int tclass, __be32 flowlabel)
923{
924 return htonl(tclass << IPV6_TCLASS_SHIFT) | flowlabel;
925}
926
fa1be7e0
MK
927static inline __be32 flowi6_get_flowlabel(const struct flowi6 *fl6)
928{
929 return fl6->flowlabel & IPV6_FLOWLABEL_MASK;
930}
931
1da177e4
LT
932/*
933 * Prototypes exported by ipv6
934 */
935
936/*
937 * rcv function (called from netdevice level)
938 */
939
5c3a0fd7
JP
940int ipv6_rcv(struct sk_buff *skb, struct net_device *dev,
941 struct packet_type *pt, struct net_device *orig_dev);
d8269e2c
EC
942void ipv6_list_rcv(struct list_head *head, struct packet_type *pt,
943 struct net_device *orig_dev);
1da177e4 944
0c4b51f0 945int ip6_rcv_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
b05e1066 946
1da177e4
LT
947/*
948 * upper-layer output functions
949 */
1c1e9d2b 950int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6,
92e55f41 951 __u32 mark, struct ipv6_txoptions *opt, int tclass);
5c3a0fd7
JP
952
953int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr);
954
955int ip6_append_data(struct sock *sk,
956 int getfrag(void *from, char *to, int offset, int len,
957 int odd, struct sk_buff *skb),
26879da5
WW
958 void *from, int length, int transhdrlen,
959 struct ipcm6_cookie *ipc6, struct flowi6 *fl6,
5fdaa88d 960 struct rt6_info *rt, unsigned int flags);
5c3a0fd7
JP
961
962int ip6_push_pending_frames(struct sock *sk);
963
964void ip6_flush_pending_frames(struct sock *sk);
965
6422398c
VY
966int ip6_send_skb(struct sk_buff *skb);
967
968struct sk_buff *__ip6_make_skb(struct sock *sk, struct sk_buff_head *queue,
969 struct inet_cork_full *cork,
970 struct inet6_cork *v6_cork);
971struct sk_buff *ip6_make_skb(struct sock *sk,
972 int getfrag(void *from, char *to, int offset,
973 int len, int odd, struct sk_buff *skb),
974 void *from, int length, int transhdrlen,
26879da5
WW
975 struct ipcm6_cookie *ipc6, struct flowi6 *fl6,
976 struct rt6_info *rt, unsigned int flags,
5fdaa88d 977 struct inet_cork_full *cork);
6422398c
VY
978
979static inline struct sk_buff *ip6_finish_skb(struct sock *sk)
980{
981 return __ip6_make_skb(sk, &sk->sk_write_queue, &inet_sk(sk)->cork,
982 &inet6_sk(sk)->cork);
983}
984
343d60aa
RP
985int ip6_dst_lookup(struct net *net, struct sock *sk, struct dst_entry **dst,
986 struct flowi6 *fl6);
3aef934f 987struct dst_entry *ip6_dst_lookup_flow(const struct sock *sk, struct flowi6 *fl6,
0e0d44ab 988 const struct in6_addr *final_dst);
5c3a0fd7 989struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
96818159
AK
990 const struct in6_addr *final_dst,
991 bool connected);
5c3a0fd7
JP
992struct dst_entry *ip6_blackhole_route(struct net *net,
993 struct dst_entry *orig_dst);
1da177e4
LT
994
995/*
996 * skb processing functions
997 */
998
ede2059d 999int ip6_output(struct net *net, struct sock *sk, struct sk_buff *skb);
5c3a0fd7
JP
1000int ip6_forward(struct sk_buff *skb);
1001int ip6_input(struct sk_buff *skb);
1002int ip6_mc_input(struct sk_buff *skb);
80bde363
PA
1003void ip6_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int nexthdr,
1004 bool have_final);
1da177e4 1005
cf91a99d 1006int __ip6_local_out(struct net *net, struct sock *sk, struct sk_buff *skb);
33224b16 1007int ip6_local_out(struct net *net, struct sock *sk, struct sk_buff *skb);
ef76bc23 1008
1da177e4
LT
1009/*
1010 * Extension header (options) processing
1011 */
1012
5c3a0fd7 1013void ipv6_push_nfrag_opts(struct sk_buff *skb, struct ipv6_txoptions *opt,
613fa3ca
DL
1014 u8 *proto, struct in6_addr **daddr_p,
1015 struct in6_addr *saddr);
5c3a0fd7
JP
1016void ipv6_push_frag_opts(struct sk_buff *skb, struct ipv6_txoptions *opt,
1017 u8 *proto);
1da177e4 1018
5c3a0fd7
JP
1019int ipv6_skip_exthdr(const struct sk_buff *, int start, u8 *nexthdrp,
1020 __be16 *frag_offp);
1da177e4 1021
5c3a0fd7 1022bool ipv6_ext_hdr(u8 nexthdr);
1da177e4 1023
f8f62675 1024enum {
9195bb8e
AA
1025 IP6_FH_F_FRAG = (1 << 0),
1026 IP6_FH_F_AUTH = (1 << 1),
1027 IP6_FH_F_SKIP_RH = (1 << 2),
f8f62675
JG
1028};
1029
1030/* find specified header and get offset to it */
5c3a0fd7
JP
1031int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset, int target,
1032 unsigned short *fragoff, int *fragflg);
f8f62675 1033
0868383b 1034int ipv6_find_tlv(const struct sk_buff *skb, int offset, int type);
c61a4043 1035
5c3a0fd7
JP
1036struct in6_addr *fl6_update_dst(struct flowi6 *fl6,
1037 const struct ipv6_txoptions *opt,
1038 struct in6_addr *orig);
20c59de2 1039
1da177e4
LT
1040/*
1041 * socket options (ipv6_sockglue.c)
1042 */
1043
5c3a0fd7
JP
1044int ipv6_setsockopt(struct sock *sk, int level, int optname,
1045 char __user *optval, unsigned int optlen);
1046int ipv6_getsockopt(struct sock *sk, int level, int optname,
1047 char __user *optval, int __user *optlen);
1048int compat_ipv6_setsockopt(struct sock *sk, int level, int optname,
1049 char __user *optval, unsigned int optlen);
1050int compat_ipv6_getsockopt(struct sock *sk, int level, int optname,
1051 char __user *optval, int __user *optlen);
1052
0382a25a
GN
1053int __ip6_datagram_connect(struct sock *sk, struct sockaddr *addr,
1054 int addr_len);
5c3a0fd7 1055int ip6_datagram_connect(struct sock *sk, struct sockaddr *addr, int addr_len);
82b276cd
HFS
1056int ip6_datagram_connect_v6_only(struct sock *sk, struct sockaddr *addr,
1057 int addr_len);
33c162a9 1058int ip6_datagram_dst_update(struct sock *sk, bool fix_sk_saddr);
e646b657 1059void ip6_datagram_release_cb(struct sock *sk);
5c3a0fd7 1060
85fbaa75
HFS
1061int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len,
1062 int *addr_len);
1063int ipv6_recv_rxpmtu(struct sock *sk, struct msghdr *msg, int len,
1064 int *addr_len);
5c3a0fd7
JP
1065void ipv6_icmp_error(struct sock *sk, struct sk_buff *skb, int err, __be16 port,
1066 u32 info, u8 *payload);
1067void ipv6_local_error(struct sock *sk, int err, struct flowi6 *fl6, u32 info);
1068void ipv6_local_rxpmtu(struct sock *sk, struct flowi6 *fl6, u32 mtu);
1069
1070int inet6_release(struct socket *sock);
1071int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len);
9b2c45d4 1072int inet6_getname(struct socket *sock, struct sockaddr *uaddr,
5c3a0fd7
JP
1073 int peer);
1074int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
1075
1076int inet6_hash_connect(struct inet_timewait_death_row *death_row,
d8313f5c
ACM
1077 struct sock *sk);
1078
1da177e4
LT
1079/*
1080 * reassembly.c
1081 */
90ddc4f0
ED
1082extern const struct proto_ops inet6_stream_ops;
1083extern const struct proto_ops inet6_dgram_ops;
77d4b1d3 1084extern const struct proto_ops inet6_sockraw_ops;
20380731 1085
14c85021
ACM
1086struct group_source_req;
1087struct group_filter;
1088
5c3a0fd7
JP
1089int ip6_mc_source(int add, int omode, struct sock *sk,
1090 struct group_source_req *pgsr);
1091int ip6_mc_msfilter(struct sock *sk, struct group_filter *gsf);
1092int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf,
1093 struct group_filter __user *optval, int __user *optlen);
20380731
ACM
1094
1095#ifdef CONFIG_PROC_FS
5c3a0fd7
JP
1096int ac6_proc_init(struct net *net);
1097void ac6_proc_exit(struct net *net);
1098int raw6_proc_init(void);
1099void raw6_proc_exit(void);
1100int tcp6_proc_init(struct net *net);
1101void tcp6_proc_exit(struct net *net);
1102int udp6_proc_init(struct net *net);
1103void udp6_proc_exit(struct net *net);
1104int udplite6_proc_init(void);
1105void udplite6_proc_exit(void);
1106int ipv6_misc_proc_init(void);
1107void ipv6_misc_proc_exit(void);
1108int snmp6_register_dev(struct inet6_dev *idev);
1109int snmp6_unregister_dev(struct inet6_dev *idev);
20380731 1110
7f7d9a6b 1111#else
6ab57e7e
DL
1112static inline int ac6_proc_init(struct net *net) { return 0; }
1113static inline void ac6_proc_exit(struct net *net) { }
1114static inline int snmp6_register_dev(struct inet6_dev *idev) { return 0; }
1115static inline int snmp6_unregister_dev(struct inet6_dev *idev) { return 0; }
20380731 1116#endif
1da177e4 1117
20380731 1118#ifdef CONFIG_SYSCTL
5c3a0fd7
JP
1119struct ctl_table *ipv6_icmp_sysctl_init(struct net *net);
1120struct ctl_table *ipv6_route_sysctl_init(struct net *net);
1121int ipv6_sysctl_register(void);
1122void ipv6_sysctl_unregister(void);
20380731 1123#endif
1da177e4 1124
46a4dee0
MC
1125int ipv6_sock_mc_join(struct sock *sk, int ifindex,
1126 const struct in6_addr *addr);
c7ea20c9
HL
1127int ipv6_sock_mc_join_ssm(struct sock *sk, int ifindex,
1128 const struct in6_addr *addr, unsigned int mode);
46a4dee0
MC
1129int ipv6_sock_mc_drop(struct sock *sk, int ifindex,
1130 const struct in6_addr *addr);
20380731 1131#endif /* _NET_IPV6_H */