16 #include <linux/ipv6.h>
23 #define SIN6_LEN_RFC2133 24
25 #define IPV6_MAXPLEN 65535
33 #define NEXTHDR_UDP 17
34 #define NEXTHDR_IPV6 41
35 #define NEXTHDR_ROUTING 43
36 #define NEXTHDR_FRAGMENT 44
37 #define NEXTHDR_GRE 47
38 #define NEXTHDR_ESP 50
39 #define NEXTHDR_AUTH 51
40 #define NEXTHDR_ICMP 58
41 #define NEXTHDR_NONE 59
42 #define NEXTHDR_DEST 60
43 #define NEXTHDR_MOBILITY 135
45 #define NEXTHDR_MAX 255
49 #define IPV6_DEFAULT_HOPLIMIT 64
50 #define IPV6_DEFAULT_MCASTHOPS 1
63 #define IPV6_ADDR_ANY 0x0000U
65 #define IPV6_ADDR_UNICAST 0x0001U
66 #define IPV6_ADDR_MULTICAST 0x0002U
68 #define IPV6_ADDR_LOOPBACK 0x0010U
69 #define IPV6_ADDR_LINKLOCAL 0x0020U
70 #define IPV6_ADDR_SITELOCAL 0x0040U
72 #define IPV6_ADDR_COMPATv4 0x0080U
74 #define IPV6_ADDR_SCOPE_MASK 0x00f0U
76 #define IPV6_ADDR_MAPPED 0x1000U
81 #define IPV6_ADDR_MC_SCOPE(a) \
82 ((a)->s6_addr[1] & 0x0f)
83 #define __IPV6_ADDR_SCOPE_INVALID -1
84 #define IPV6_ADDR_SCOPE_NODELOCAL 0x01
85 #define IPV6_ADDR_SCOPE_LINKLOCAL 0x02
86 #define IPV6_ADDR_SCOPE_SITELOCAL 0x05
87 #define IPV6_ADDR_SCOPE_ORGLOCAL 0x08
88 #define IPV6_ADDR_SCOPE_GLOBAL 0x0e
93 #define IPV6_ADDR_MC_FLAG_TRANSIENT(a) \
94 ((a)->s6_addr[1] & 0x10)
95 #define IPV6_ADDR_MC_FLAG_PREFIX(a) \
96 ((a)->s6_addr[1] & 0x20)
97 #define IPV6_ADDR_MC_FLAG_RENDEZVOUS(a) \
98 ((a)->s6_addr[1] & 0x40)
111 #define IP6_MF 0x0001
118 #define _DEVINC(net, statname, modifier, idev, field) \
120 struct inet6_dev *_idev = (idev); \
121 if (likely(_idev != NULL)) \
122 SNMP_INC_STATS##modifier((_idev)->stats.statname, (field)); \
123 SNMP_INC_STATS##modifier((net)->mib.statname##_statistics, (field));\
127 #define _DEVINCATOMIC(net, statname, modifier, idev, field) \
129 struct inet6_dev *_idev = (idev); \
130 if (likely(_idev != NULL)) \
131 SNMP_INC_STATS_ATOMIC_LONG((_idev)->stats.statname##dev, (field)); \
132 SNMP_INC_STATS##modifier((net)->mib.statname##_statistics, (field));\
136 #define _DEVINC_ATOMIC_ATOMIC(net, statname, idev, field) \
138 struct inet6_dev *_idev = (idev); \
139 if (likely(_idev != NULL)) \
140 SNMP_INC_STATS_ATOMIC_LONG((_idev)->stats.statname##dev, (field)); \
141 SNMP_INC_STATS_ATOMIC_LONG((net)->mib.statname##_statistics, (field));\
144 #define _DEVADD(net, statname, modifier, idev, field, val) \
146 struct inet6_dev *_idev = (idev); \
147 if (likely(_idev != NULL)) \
148 SNMP_ADD_STATS##modifier((_idev)->stats.statname, (field), (val)); \
149 SNMP_ADD_STATS##modifier((net)->mib.statname##_statistics, (field), (val));\
152 #define _DEVUPD(net, statname, modifier, idev, field, val) \
154 struct inet6_dev *_idev = (idev); \
155 if (likely(_idev != NULL)) \
156 SNMP_UPD_PO_STATS##modifier((_idev)->stats.statname, field, (val)); \
157 SNMP_UPD_PO_STATS##modifier((net)->mib.statname##_statistics, field, (val));\
162 #define IP6_INC_STATS(net, idev,field) \
163 _DEVINC(net, ipv6, 64, idev, field)
164 #define IP6_INC_STATS_BH(net, idev,field) \
165 _DEVINC(net, ipv6, 64_BH, idev, field)
166 #define IP6_ADD_STATS(net, idev,field,val) \
167 _DEVADD(net, ipv6, 64, idev, field, val)
168 #define IP6_ADD_STATS_BH(net, idev,field,val) \
169 _DEVADD(net, ipv6, 64_BH, idev, field, val)
170 #define IP6_UPD_PO_STATS(net, idev,field,val) \
171 _DEVUPD(net, ipv6, 64, idev, field, val)
172 #define IP6_UPD_PO_STATS_BH(net, idev,field,val) \
173 _DEVUPD(net, ipv6, 64_BH, idev, field, val)
174 #define ICMP6_INC_STATS(net, idev, field) \
175 _DEVINCATOMIC(net, icmpv6, , idev, field)
176 #define ICMP6_INC_STATS_BH(net, idev, field) \
177 _DEVINCATOMIC(net, icmpv6, _BH, idev, field)
179 #define ICMP6MSGOUT_INC_STATS(net, idev, field) \
180 _DEVINC_ATOMIC_ATOMIC(net, icmpv6msg, idev, field +256)
181 #define ICMP6MSGOUT_INC_STATS_BH(net, idev, field) \
182 _DEVINC_ATOMIC_ATOMIC(net, icmpv6msg, idev, field +256)
183 #define ICMP6MSGIN_INC_STATS_BH(net, idev, field) \
184 _DEVINC_ATOMIC_ATOMIC(net, icmpv6msg, idev, field)
235 #define IPV6_FLOWINFO_MASK cpu_to_be32(0x0FFFFFFF)
236 #define IPV6_FLOWLABEL_MASK cpu_to_be32(0x000FFFFF)
274 #if IS_ENABLED(CONFIG_IPV6)
275 static inline int ip6_frag_nqueues(
struct net *
net)
277 return net->ipv6.frags.nqueues;
280 static inline int ip6_frag_mem(
struct net *
net)
286 #define IPV6_FRAG_HIGH_THRESH (256 * 1024)
287 #define IPV6_FRAG_LOW_THRESH (192 * 1024)
288 #define IPV6_FRAG_TIMEOUT (60 * HZ)
291 static inline int ipv6_addr_type(
const struct in6_addr *
addr)
296 static inline int ipv6_addr_scope(
const struct in6_addr *
addr)
301 static inline int __ipv6_addr_src_scope(
int type)
306 static inline int ipv6_addr_src_scope(
const struct in6_addr *
addr)
320 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
321 const unsigned long *ul1 = (
const unsigned long *)a1;
322 const unsigned long *ulm = (
const unsigned long *)m;
323 const unsigned long *ul2 = (
const unsigned long *)a2;
325 return !!(((ul1[0] ^ ul2[0]) & ulm[0]) |
326 ((ul1[1] ^ ul2[1]) & ulm[1]));
328 return !!(((a1->s6_addr32[0] ^ a2->s6_addr32[0]) & m->s6_addr32[0]) |
329 ((a1->s6_addr32[1] ^ a2->s6_addr32[1]) & m->s6_addr32[1]) |
330 ((a1->s6_addr32[2] ^ a2->s6_addr32[2]) & m->s6_addr32[2]) |
331 ((a1->s6_addr32[3] ^ a2->s6_addr32[3]) & m->s6_addr32[3]));
335 static inline void ipv6_addr_prefix(
struct in6_addr *pfx,
343 memset(pfx->s6_addr, 0,
sizeof(pfx->s6_addr));
344 memcpy(pfx->s6_addr, addr, o);
346 pfx->s6_addr[o] = addr->s6_addr[o] & (0xff00 >>
b);
349 static inline void ipv6_addr_set(
struct in6_addr *addr,
353 addr->s6_addr32[0] =
w1;
354 addr->s6_addr32[1] =
w2;
355 addr->s6_addr32[2] =
w3;
356 addr->s6_addr32[3] =
w4;
359 static inline bool ipv6_addr_equal(
const struct in6_addr *a1,
362 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
363 const unsigned long *ul1 = (
const unsigned long *)a1;
364 const unsigned long *ul2 = (
const unsigned long *)a2;
366 return ((ul1[0] ^ ul2[0]) | (ul1[1] ^ ul2[1])) == 0
UL;
368 return ((a1->s6_addr32[0] ^ a2->s6_addr32[0]) |
369 (a1->s6_addr32[1] ^ a2->s6_addr32[1]) |
370 (a1->s6_addr32[2] ^ a2->s6_addr32[2]) |
371 (a1->s6_addr32[3] ^ a2->s6_addr32[3])) == 0;
375 static inline bool __ipv6_prefix_equal(
const __be32 *a1,
const __be32 *a2,
376 unsigned int prefixlen)
378 unsigned int pdw, pbi;
381 pdw = prefixlen >> 5;
382 if (pdw &&
memcmp(a1, a2, pdw << 2))
386 pbi = prefixlen & 0x1f;
387 if (pbi && ((a1[pdw] ^ a2[pdw]) &
htonl((0xffffffff) << (32 - pbi))))
393 static inline bool ipv6_prefix_equal(
const struct in6_addr *a1,
395 unsigned int prefixlen)
397 return __ipv6_prefix_equal(a1->s6_addr32, a2->s6_addr32,
442 static inline bool ipv6_addr_any(
const struct in6_addr *
a)
444 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
445 const unsigned long *ul = (
const unsigned long *)a;
447 return (ul[0] | ul[1]) == 0
UL;
449 return (a->s6_addr32[0] | a->s6_addr32[1] |
450 a->s6_addr32[2] | a->s6_addr32[3]) == 0;
454 static inline u32 ipv6_addr_hash(
const struct in6_addr *a)
456 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
457 const unsigned long *ul = (
const unsigned long *)a;
458 unsigned long x = ul[0] ^ ul[1];
460 return (
u32)(x ^ (x >> 32));
462 return (
__force u32)(a->s6_addr32[0] ^ a->s6_addr32[1] ^
463 a->s6_addr32[2] ^ a->s6_addr32[3]);
467 static inline bool ipv6_addr_loopback(
const struct in6_addr *a)
469 return (a->s6_addr32[0] | a->s6_addr32[1] |
470 a->s6_addr32[2] | (a->s6_addr32[3] ^
htonl(1))) == 0;
473 static inline bool ipv6_addr_v4mapped(
const struct in6_addr *a)
475 return (a->s6_addr32[0] | a->s6_addr32[1] |
476 (a->s6_addr32[2] ^
htonl(0x0000ffff))) == 0;
483 static inline bool ipv6_addr_orchid(
const struct in6_addr *a)
485 return (a->s6_addr32[0] &
htonl(0xfffffff0)) ==
htonl(0x20010010);
488 static inline void ipv6_addr_set_v4mapped(
const __be32 addr,
491 ipv6_addr_set(v4mapped,
501 static inline int __ipv6_addr_diff(
const void *token1,
const void *token2,
int addrlen)
503 const __be32 *a1 = token1, *a2 = token2;
508 for (i = 0; i < addrlen; i++) {
533 static inline int ipv6_addr_diff(
const struct in6_addr *a1,
const struct in6_addr *a2)
535 return __ipv6_addr_diff(a1, a2,
sizeof(
struct in6_addr));
646 unsigned int optlen);
655 unsigned int optlen);
663 struct sockaddr *addr,
int addr_len);
676 int *uaddr_len,
int peer);
701 #ifdef CONFIG_PROC_FS
702 extern int ac6_proc_init(
struct net *
net);
703 extern void ac6_proc_exit(
struct net *
net);
704 extern int raw6_proc_init(
void);
705 extern void raw6_proc_exit(
void);
706 extern int tcp6_proc_init(
struct net *
net);
707 extern void tcp6_proc_exit(
struct net *
net);
708 extern int udp6_proc_init(
struct net *
net);
709 extern void udp6_proc_exit(
struct net *
net);
710 extern int udplite6_proc_init(
void);
711 extern void udplite6_proc_exit(
void);
718 static inline int ac6_proc_init(
struct net *
net) {
return 0; }
719 static inline void ac6_proc_exit(
struct net *
net) { }
725 extern ctl_table ipv6_route_table_template[];
726 extern ctl_table ipv6_icmp_table_template[];