11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Linux INET6 implementation 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Authors: 51da177e4SLinus Torvalds * Pedro Roque <[email protected]> 61da177e4SLinus Torvalds * 71da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or 81da177e4SLinus Torvalds * modify it under the terms of the GNU General Public License 91da177e4SLinus Torvalds * as published by the Free Software Foundation; either version 101da177e4SLinus Torvalds * 2 of the License, or (at your option) any later version. 111da177e4SLinus Torvalds */ 121da177e4SLinus Torvalds 131da177e4SLinus Torvalds #ifndef _NET_IPV6_H 141da177e4SLinus Torvalds #define _NET_IPV6_H 151da177e4SLinus Torvalds 161da177e4SLinus Torvalds #include <linux/ipv6.h> 171da177e4SLinus Torvalds #include <linux/hardirq.h> 1808dcdbf6SEric Dumazet #include <linux/jhash.h> 1920283d84SHerbert Xu #include <net/if_inet6.h> 201da177e4SLinus Torvalds #include <net/ndisc.h> 211da177e4SLinus Torvalds #include <net/flow.h> 221da177e4SLinus Torvalds #include <net/snmp.h> 231da177e4SLinus Torvalds 241da177e4SLinus Torvalds #define SIN6_LEN_RFC2133 24 251da177e4SLinus Torvalds 261da177e4SLinus Torvalds #define IPV6_MAXPLEN 65535 271da177e4SLinus Torvalds 281da177e4SLinus Torvalds /* 291da177e4SLinus Torvalds * NextHeader field of IPv6 header 301da177e4SLinus Torvalds */ 311da177e4SLinus Torvalds 321da177e4SLinus Torvalds #define NEXTHDR_HOP 0 /* Hop-by-hop option header. */ 331da177e4SLinus Torvalds #define NEXTHDR_TCP 6 /* TCP segment. */ 341da177e4SLinus Torvalds #define NEXTHDR_UDP 17 /* UDP message. */ 351da177e4SLinus Torvalds #define NEXTHDR_IPV6 41 /* IPv6 in IPv6 */ 361da177e4SLinus Torvalds #define NEXTHDR_ROUTING 43 /* Routing header. */ 371da177e4SLinus Torvalds #define NEXTHDR_FRAGMENT 44 /* Fragmentation/reassembly header. */ 38c12b395aS[email protected] #define NEXTHDR_GRE 47 /* GRE header. */ 391da177e4SLinus Torvalds #define NEXTHDR_ESP 50 /* Encapsulating security payload. */ 401da177e4SLinus Torvalds #define NEXTHDR_AUTH 51 /* Authentication header. */ 411da177e4SLinus Torvalds #define NEXTHDR_ICMP 58 /* ICMP for IPv6. */ 421da177e4SLinus Torvalds #define NEXTHDR_NONE 59 /* No next header */ 431da177e4SLinus Torvalds #define NEXTHDR_DEST 60 /* Destination options header. */ 442b741653SMasahide NAKAMURA #define NEXTHDR_MOBILITY 135 /* Mobility header. */ 451da177e4SLinus Torvalds 461da177e4SLinus Torvalds #define NEXTHDR_MAX 255 471da177e4SLinus Torvalds 481da177e4SLinus Torvalds 491da177e4SLinus Torvalds 501da177e4SLinus Torvalds #define IPV6_DEFAULT_HOPLIMIT 64 511da177e4SLinus Torvalds #define IPV6_DEFAULT_MCASTHOPS 1 521da177e4SLinus Torvalds 531da177e4SLinus Torvalds /* 541da177e4SLinus Torvalds * Addr type 551da177e4SLinus Torvalds * 561da177e4SLinus Torvalds * type - unicast | multicast 571da177e4SLinus Torvalds * scope - local | site | global 581da177e4SLinus Torvalds * v4 - compat 591da177e4SLinus Torvalds * v4mapped 601da177e4SLinus Torvalds * any 611da177e4SLinus Torvalds * loopback 621da177e4SLinus Torvalds */ 631da177e4SLinus Torvalds 641da177e4SLinus Torvalds #define IPV6_ADDR_ANY 0x0000U 651da177e4SLinus Torvalds 661da177e4SLinus Torvalds #define IPV6_ADDR_UNICAST 0x0001U 671da177e4SLinus Torvalds #define IPV6_ADDR_MULTICAST 0x0002U 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds #define IPV6_ADDR_LOOPBACK 0x0010U 701da177e4SLinus Torvalds #define IPV6_ADDR_LINKLOCAL 0x0020U 711da177e4SLinus Torvalds #define IPV6_ADDR_SITELOCAL 0x0040U 721da177e4SLinus Torvalds 731da177e4SLinus Torvalds #define IPV6_ADDR_COMPATv4 0x0080U 741da177e4SLinus Torvalds 751da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_MASK 0x00f0U 761da177e4SLinus Torvalds 771da177e4SLinus Torvalds #define IPV6_ADDR_MAPPED 0x1000U 781da177e4SLinus Torvalds 791da177e4SLinus Torvalds /* 801da177e4SLinus Torvalds * Addr scopes 811da177e4SLinus Torvalds */ 821da177e4SLinus Torvalds #define IPV6_ADDR_MC_SCOPE(a) \ 831da177e4SLinus Torvalds ((a)->s6_addr[1] & 0x0f) /* nonstandard */ 841da177e4SLinus Torvalds #define __IPV6_ADDR_SCOPE_INVALID -1 851da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_NODELOCAL 0x01 861da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_LINKLOCAL 0x02 871da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_SITELOCAL 0x05 881da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_ORGLOCAL 0x08 891da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_GLOBAL 0x0e 901da177e4SLinus Torvalds 911da177e4SLinus Torvalds /* 925ced1339SLinus Lüssing * Addr flags 935ced1339SLinus Lüssing */ 945ced1339SLinus Lüssing #define IPV6_ADDR_MC_FLAG_TRANSIENT(a) \ 955ced1339SLinus Lüssing ((a)->s6_addr[1] & 0x10) 965ced1339SLinus Lüssing #define IPV6_ADDR_MC_FLAG_PREFIX(a) \ 975ced1339SLinus Lüssing ((a)->s6_addr[1] & 0x20) 985ced1339SLinus Lüssing #define IPV6_ADDR_MC_FLAG_RENDEZVOUS(a) \ 995ced1339SLinus Lüssing ((a)->s6_addr[1] & 0x40) 1005ced1339SLinus Lüssing 1015ced1339SLinus Lüssing /* 1021da177e4SLinus Torvalds * fragmentation header 1031da177e4SLinus Torvalds */ 1041da177e4SLinus Torvalds 1051da177e4SLinus Torvalds struct frag_hdr { 10644473a6bSAl Viro __u8 nexthdr; 10744473a6bSAl Viro __u8 reserved; 10844473a6bSAl Viro __be16 frag_off; 10944473a6bSAl Viro __be32 identification; 1101da177e4SLinus Torvalds }; 1111da177e4SLinus Torvalds 1121da177e4SLinus Torvalds #define IP6_MF 0x0001 1131da177e4SLinus Torvalds 1141da177e4SLinus Torvalds #include <net/sock.h> 1151da177e4SLinus Torvalds 1161da177e4SLinus Torvalds /* sysctls */ 1171da177e4SLinus Torvalds extern int sysctl_mld_max_msf; 1183d7cc2baSPavel Emelyanov 119087fe240SDenis V. Lunev #define _DEVINC(net, statname, modifier, idev, field) \ 12014878f75SDavid L Stevens ({ \ 12114878f75SDavid L Stevens struct inet6_dev *_idev = (idev); \ 12214878f75SDavid L Stevens if (likely(_idev != NULL)) \ 12314878f75SDavid L Stevens SNMP_INC_STATS##modifier((_idev)->stats.statname, (field)); \ 1249261e537SDenis V. Lunev SNMP_INC_STATS##modifier((net)->mib.statname##_statistics, (field));\ 12514878f75SDavid L Stevens }) 12614878f75SDavid L Stevens 127be281e55SEric Dumazet /* per device counters are atomic_long_t */ 128be281e55SEric Dumazet #define _DEVINCATOMIC(net, statname, modifier, idev, field) \ 129be281e55SEric Dumazet ({ \ 130be281e55SEric Dumazet struct inet6_dev *_idev = (idev); \ 131be281e55SEric Dumazet if (likely(_idev != NULL)) \ 132be281e55SEric Dumazet SNMP_INC_STATS_ATOMIC_LONG((_idev)->stats.statname##dev, (field)); \ 133be281e55SEric Dumazet SNMP_INC_STATS##modifier((net)->mib.statname##_statistics, (field));\ 134be281e55SEric Dumazet }) 135be281e55SEric Dumazet 1362a24444fSEric Dumazet /* per device and per net counters are atomic_long_t */ 1372a24444fSEric Dumazet #define _DEVINC_ATOMIC_ATOMIC(net, statname, idev, field) \ 1382a24444fSEric Dumazet ({ \ 1392a24444fSEric Dumazet struct inet6_dev *_idev = (idev); \ 1402a24444fSEric Dumazet if (likely(_idev != NULL)) \ 1412a24444fSEric Dumazet SNMP_INC_STATS_ATOMIC_LONG((_idev)->stats.statname##dev, (field)); \ 1422a24444fSEric Dumazet SNMP_INC_STATS_ATOMIC_LONG((net)->mib.statname##_statistics, (field));\ 1432a24444fSEric Dumazet }) 1442a24444fSEric Dumazet 145087fe240SDenis V. Lunev #define _DEVADD(net, statname, modifier, idev, field, val) \ 1468e7999c4SPavel Emelyanov ({ \ 1478e7999c4SPavel Emelyanov struct inet6_dev *_idev = (idev); \ 1488e7999c4SPavel Emelyanov if (likely(_idev != NULL)) \ 1498e7999c4SPavel Emelyanov SNMP_ADD_STATS##modifier((_idev)->stats.statname, (field), (val)); \ 1509261e537SDenis V. Lunev SNMP_ADD_STATS##modifier((net)->mib.statname##_statistics, (field), (val));\ 1518e7999c4SPavel Emelyanov }) 1528e7999c4SPavel Emelyanov 153edf391ffSNeil Horman #define _DEVUPD(net, statname, modifier, idev, field, val) \ 154edf391ffSNeil Horman ({ \ 155edf391ffSNeil Horman struct inet6_dev *_idev = (idev); \ 156edf391ffSNeil Horman if (likely(_idev != NULL)) \ 157edf391ffSNeil Horman SNMP_UPD_PO_STATS##modifier((_idev)->stats.statname, field, (val)); \ 158edf391ffSNeil Horman SNMP_UPD_PO_STATS##modifier((net)->mib.statname##_statistics, field, (val));\ 159edf391ffSNeil Horman }) 160edf391ffSNeil Horman 1611da177e4SLinus Torvalds /* MIBs */ 16214878f75SDavid L Stevens 163087fe240SDenis V. Lunev #define IP6_INC_STATS(net, idev,field) \ 1644ce3c183SEric Dumazet _DEVINC(net, ipv6, 64, idev, field) 165087fe240SDenis V. Lunev #define IP6_INC_STATS_BH(net, idev,field) \ 1664ce3c183SEric Dumazet _DEVINC(net, ipv6, 64_BH, idev, field) 167edf391ffSNeil Horman #define IP6_ADD_STATS(net, idev,field,val) \ 1684ce3c183SEric Dumazet _DEVADD(net, ipv6, 64, idev, field, val) 169087fe240SDenis V. Lunev #define IP6_ADD_STATS_BH(net, idev,field,val) \ 1704ce3c183SEric Dumazet _DEVADD(net, ipv6, 64_BH, idev, field, val) 171edf391ffSNeil Horman #define IP6_UPD_PO_STATS(net, idev,field,val) \ 1724ce3c183SEric Dumazet _DEVUPD(net, ipv6, 64, idev, field, val) 173edf391ffSNeil Horman #define IP6_UPD_PO_STATS_BH(net, idev,field,val) \ 1744ce3c183SEric Dumazet _DEVUPD(net, ipv6, 64_BH, idev, field, val) 175087fe240SDenis V. Lunev #define ICMP6_INC_STATS(net, idev, field) \ 176be281e55SEric Dumazet _DEVINCATOMIC(net, icmpv6, , idev, field) 177087fe240SDenis V. Lunev #define ICMP6_INC_STATS_BH(net, idev, field) \ 178be281e55SEric Dumazet _DEVINCATOMIC(net, icmpv6, _BH, idev, field) 17914878f75SDavid L Stevens 180087fe240SDenis V. Lunev #define ICMP6MSGOUT_INC_STATS(net, idev, field) \ 1812a24444fSEric Dumazet _DEVINC_ATOMIC_ATOMIC(net, icmpv6msg, idev, field +256) 182087fe240SDenis V. Lunev #define ICMP6MSGOUT_INC_STATS_BH(net, idev, field) \ 1832a24444fSEric Dumazet _DEVINC_ATOMIC_ATOMIC(net, icmpv6msg, idev, field +256) 184087fe240SDenis V. Lunev #define ICMP6MSGIN_INC_STATS_BH(net, idev, field) \ 1852a24444fSEric Dumazet _DEVINC_ATOMIC_ATOMIC(net, icmpv6msg, idev, field) 18614878f75SDavid L Stevens 187fd2c3ef7SEric Dumazet struct ip6_ra_chain { 1881da177e4SLinus Torvalds struct ip6_ra_chain *next; 1891da177e4SLinus Torvalds struct sock *sk; 1901da177e4SLinus Torvalds int sel; 1911da177e4SLinus Torvalds void (*destructor)(struct sock *); 1921da177e4SLinus Torvalds }; 1931da177e4SLinus Torvalds 1941da177e4SLinus Torvalds extern struct ip6_ra_chain *ip6_ra_chain; 1951da177e4SLinus Torvalds extern rwlock_t ip6_ra_lock; 1961da177e4SLinus Torvalds 1971da177e4SLinus Torvalds /* 1981da177e4SLinus Torvalds This structure is prepared by protocol, when parsing 1991da177e4SLinus Torvalds ancillary data and passed to IPv6. 2001da177e4SLinus Torvalds */ 2011da177e4SLinus Torvalds 202fd2c3ef7SEric Dumazet struct ipv6_txoptions { 2031da177e4SLinus Torvalds /* Length of this structure */ 2041da177e4SLinus Torvalds int tot_len; 2051da177e4SLinus Torvalds 2061da177e4SLinus Torvalds /* length of extension headers */ 2071da177e4SLinus Torvalds 2081da177e4SLinus Torvalds __u16 opt_flen; /* after fragment hdr */ 2091da177e4SLinus Torvalds __u16 opt_nflen; /* before fragment hdr */ 2101da177e4SLinus Torvalds 2111da177e4SLinus Torvalds struct ipv6_opt_hdr *hopopt; 2121da177e4SLinus Torvalds struct ipv6_opt_hdr *dst0opt; 2131da177e4SLinus Torvalds struct ipv6_rt_hdr *srcrt; /* Routing Header */ 2141da177e4SLinus Torvalds struct ipv6_opt_hdr *dst1opt; 2151da177e4SLinus Torvalds 2161da177e4SLinus Torvalds /* Option buffer, as read by IPV6_PKTOPTIONS, starts here. */ 2171da177e4SLinus Torvalds }; 2181da177e4SLinus Torvalds 219fd2c3ef7SEric Dumazet struct ip6_flowlabel { 220*7f0e44acSEric Dumazet struct ip6_flowlabel __rcu *next; 22190bcaf7bSAl Viro __be32 label; 222db3459d1SEric Dumazet atomic_t users; 2231da177e4SLinus Torvalds struct in6_addr dst; 2241da177e4SLinus Torvalds struct ipv6_txoptions *opt; 2251da177e4SLinus Torvalds unsigned long linger; 226d3aedd5eSYOSHIFUJI Hideaki / 吉藤英明 struct rcu_head rcu; 2271da177e4SLinus Torvalds u8 share; 2284f82f457SEric W. Biederman union { 2294f82f457SEric W. Biederman struct pid *pid; 2304f82f457SEric W. Biederman kuid_t uid; 2314f82f457SEric W. Biederman } owner; 2321da177e4SLinus Torvalds unsigned long lastuse; 2331da177e4SLinus Torvalds unsigned long expires; 23460e8fbc4SBenjamin Thery struct net *fl_net; 2351da177e4SLinus Torvalds }; 2361da177e4SLinus Torvalds 237f3a7c66bSHarvey Harrison #define IPV6_FLOWINFO_MASK cpu_to_be32(0x0FFFFFFF) 238f3a7c66bSHarvey Harrison #define IPV6_FLOWLABEL_MASK cpu_to_be32(0x000FFFFF) 2391da177e4SLinus Torvalds 240fd2c3ef7SEric Dumazet struct ipv6_fl_socklist { 241*7f0e44acSEric Dumazet struct ipv6_fl_socklist __rcu *next; 2421da177e4SLinus Torvalds struct ip6_flowlabel *fl; 24318367681SYOSHIFUJI Hideaki / 吉藤英明 struct rcu_head rcu; 2441da177e4SLinus Torvalds }; 2451da177e4SLinus Torvalds 24690bcaf7bSAl Viro extern struct ip6_flowlabel *fl6_sock_lookup(struct sock *sk, __be32 label); 2471da177e4SLinus Torvalds extern struct ipv6_txoptions *fl6_merge_options(struct ipv6_txoptions * opt_space, 2481da177e4SLinus Torvalds struct ip6_flowlabel * fl, 2491da177e4SLinus Torvalds struct ipv6_txoptions * fopt); 2501da177e4SLinus Torvalds extern void fl6_free_socklist(struct sock *sk); 2511da177e4SLinus Torvalds extern int ipv6_flowlabel_opt(struct sock *sk, char __user *optval, int optlen); 2520a3e78acSDaniel Lezcano extern int ip6_flowlabel_init(void); 2531da177e4SLinus Torvalds extern void ip6_flowlabel_cleanup(void); 2541da177e4SLinus Torvalds 2551da177e4SLinus Torvalds static inline void fl6_sock_release(struct ip6_flowlabel *fl) 2561da177e4SLinus Torvalds { 2571da177e4SLinus Torvalds if (fl) 2581da177e4SLinus Torvalds atomic_dec(&fl->users); 2591da177e4SLinus Torvalds } 2601da177e4SLinus Torvalds 261b94f1c09SDavid S. Miller extern void icmpv6_notify(struct sk_buff *skb, u8 type, u8 code, __be32 info); 262b94f1c09SDavid S. Miller 263725a8ff0SDenis V. Lunev extern int ip6_ra_control(struct sock *sk, int sel); 2641da177e4SLinus Torvalds 265e5bbef20SHerbert Xu extern int ipv6_parse_hopopts(struct sk_buff *skb); 2661da177e4SLinus Torvalds 2671da177e4SLinus Torvalds extern struct ipv6_txoptions * ipv6_dup_options(struct sock *sk, struct ipv6_txoptions *opt); 268333fad53SYOSHIFUJI Hideaki extern struct ipv6_txoptions * ipv6_renew_options(struct sock *sk, struct ipv6_txoptions *opt, 269333fad53SYOSHIFUJI Hideaki int newtype, 270333fad53SYOSHIFUJI Hideaki struct ipv6_opt_hdr __user *newopt, 271333fad53SYOSHIFUJI Hideaki int newoptlen); 272df9890c3SYOSHIFUJI Hideaki struct ipv6_txoptions *ipv6_fixup_options(struct ipv6_txoptions *opt_space, 273df9890c3SYOSHIFUJI Hideaki struct ipv6_txoptions *opt); 2741da177e4SLinus Torvalds 27592113bfdSEric Dumazet extern bool ipv6_opt_accepted(const struct sock *sk, const struct sk_buff *skb); 276399c07deSArnaldo Carvalho de Melo 277aeaf6e9dSShmulik Ladkani static inline bool ipv6_accept_ra(struct inet6_dev *idev) 278aeaf6e9dSShmulik Ladkani { 279aeaf6e9dSShmulik Ladkani /* If forwarding is enabled, RA are not accepted unless the special 280aeaf6e9dSShmulik Ladkani * hybrid mode (accept_ra=2) is enabled. 281aeaf6e9dSShmulik Ladkani */ 282aeaf6e9dSShmulik Ladkani return idev->cnf.forwarding ? idev->cnf.accept_ra == 2 : 283aeaf6e9dSShmulik Ladkani idev->cnf.accept_ra; 284aeaf6e9dSShmulik Ladkani } 285aeaf6e9dSShmulik Ladkani 286d4915c08SAmerigo Wang #if IS_ENABLED(CONFIG_IPV6) 287d4915c08SAmerigo Wang static inline int ip6_frag_nqueues(struct net *net) 288d4915c08SAmerigo Wang { 289d4915c08SAmerigo Wang return net->ipv6.frags.nqueues; 290d4915c08SAmerigo Wang } 291d4915c08SAmerigo Wang 292d4915c08SAmerigo Wang static inline int ip6_frag_mem(struct net *net) 293d4915c08SAmerigo Wang { 294d433673eSJesper Dangaard Brouer return sum_frag_mem_limit(&net->ipv6.frags); 295d4915c08SAmerigo Wang } 296d4915c08SAmerigo Wang #endif 2971da177e4SLinus Torvalds 298c2a93660SJesper Dangaard Brouer #define IPV6_FRAG_HIGH_THRESH (4 * 1024*1024) /* 4194304 */ 299c2a93660SJesper Dangaard Brouer #define IPV6_FRAG_LOW_THRESH (3 * 1024*1024) /* 3145728 */ 3001da177e4SLinus Torvalds #define IPV6_FRAG_TIMEOUT (60 * HZ) /* 60 seconds */ 3011da177e4SLinus Torvalds 302b1cacb68SYOSHIFUJI Hideaki extern int __ipv6_addr_type(const struct in6_addr *addr); 303b1cacb68SYOSHIFUJI Hideaki static inline int ipv6_addr_type(const struct in6_addr *addr) 304b1cacb68SYOSHIFUJI Hideaki { 305b1cacb68SYOSHIFUJI Hideaki return __ipv6_addr_type(addr) & 0xffff; 306b1cacb68SYOSHIFUJI Hideaki } 3071da177e4SLinus Torvalds 3081da177e4SLinus Torvalds static inline int ipv6_addr_scope(const struct in6_addr *addr) 3091da177e4SLinus Torvalds { 310b1cacb68SYOSHIFUJI Hideaki return __ipv6_addr_type(addr) & IPV6_ADDR_SCOPE_MASK; 311b1cacb68SYOSHIFUJI Hideaki } 312b1cacb68SYOSHIFUJI Hideaki 313b1cacb68SYOSHIFUJI Hideaki static inline int __ipv6_addr_src_scope(int type) 314b1cacb68SYOSHIFUJI Hideaki { 315a02cec21SEric Dumazet return (type == IPV6_ADDR_ANY) ? __IPV6_ADDR_SCOPE_INVALID : (type >> 16); 316b1cacb68SYOSHIFUJI Hideaki } 317b1cacb68SYOSHIFUJI Hideaki 318b1cacb68SYOSHIFUJI Hideaki static inline int ipv6_addr_src_scope(const struct in6_addr *addr) 319b1cacb68SYOSHIFUJI Hideaki { 320b1cacb68SYOSHIFUJI Hideaki return __ipv6_addr_src_scope(__ipv6_addr_type(addr)); 3211da177e4SLinus Torvalds } 3221da177e4SLinus Torvalds 3231da177e4SLinus Torvalds static inline int ipv6_addr_cmp(const struct in6_addr *a1, const struct in6_addr *a2) 3241da177e4SLinus Torvalds { 325db3459d1SEric Dumazet return memcmp(a1, a2, sizeof(struct in6_addr)); 3261da177e4SLinus Torvalds } 3271da177e4SLinus Torvalds 3281a203cb3SEric Dumazet static inline bool 329f2ffd9eeSPatrick McHardy ipv6_masked_addr_cmp(const struct in6_addr *a1, const struct in6_addr *m, 330f2ffd9eeSPatrick McHardy const struct in6_addr *a2) 331f2ffd9eeSPatrick McHardy { 3321a203cb3SEric Dumazet #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 3331a203cb3SEric Dumazet const unsigned long *ul1 = (const unsigned long *)a1; 3341a203cb3SEric Dumazet const unsigned long *ulm = (const unsigned long *)m; 3351a203cb3SEric Dumazet const unsigned long *ul2 = (const unsigned long *)a2; 3361a203cb3SEric Dumazet 3371a203cb3SEric Dumazet return !!(((ul1[0] ^ ul2[0]) & ulm[0]) | 3381a203cb3SEric Dumazet ((ul1[1] ^ ul2[1]) & ulm[1])); 3391a203cb3SEric Dumazet #else 340a02cec21SEric Dumazet return !!(((a1->s6_addr32[0] ^ a2->s6_addr32[0]) & m->s6_addr32[0]) | 341fed85383SYOSHIFUJI Hideaki ((a1->s6_addr32[1] ^ a2->s6_addr32[1]) & m->s6_addr32[1]) | 342fed85383SYOSHIFUJI Hideaki ((a1->s6_addr32[2] ^ a2->s6_addr32[2]) & m->s6_addr32[2]) | 343a02cec21SEric Dumazet ((a1->s6_addr32[3] ^ a2->s6_addr32[3]) & m->s6_addr32[3])); 3441a203cb3SEric Dumazet #endif 345f2ffd9eeSPatrick McHardy } 346f2ffd9eeSPatrick McHardy 3471da177e4SLinus Torvalds static inline void ipv6_addr_prefix(struct in6_addr *pfx, 3481da177e4SLinus Torvalds const struct in6_addr *addr, 3491da177e4SLinus Torvalds int plen) 3501da177e4SLinus Torvalds { 3511da177e4SLinus Torvalds /* caller must guarantee 0 <= plen <= 128 */ 3521da177e4SLinus Torvalds int o = plen >> 3, 3531da177e4SLinus Torvalds b = plen & 0x7; 3541da177e4SLinus Torvalds 355db3459d1SEric Dumazet memset(pfx->s6_addr, 0, sizeof(pfx->s6_addr)); 3561da177e4SLinus Torvalds memcpy(pfx->s6_addr, addr, o); 357db3459d1SEric Dumazet if (b != 0) 3581da177e4SLinus Torvalds pfx->s6_addr[o] = addr->s6_addr[o] & (0xff00 >> b); 3591da177e4SLinus Torvalds } 3601da177e4SLinus Torvalds 3615206c579SYOSHIFUJI Hideaki / 吉藤英明 static inline void __ipv6_addr_set_half(__be32 *addr, 3625206c579SYOSHIFUJI Hideaki / 吉藤英明 __be32 wh, __be32 wl) 3635206c579SYOSHIFUJI Hideaki / 吉藤英明 { 3645206c579SYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 3655206c579SYOSHIFUJI Hideaki / 吉藤英明 #if defined(__BIG_ENDIAN) 3665206c579SYOSHIFUJI Hideaki / 吉藤英明 if (__builtin_constant_p(wh) && __builtin_constant_p(wl)) { 3675206c579SYOSHIFUJI Hideaki / 吉藤英明 *(__force u64 *)addr = ((__force u64)(wh) << 32 | (__force u64)(wl)); 3685206c579SYOSHIFUJI Hideaki / 吉藤英明 return; 3695206c579SYOSHIFUJI Hideaki / 吉藤英明 } 3705206c579SYOSHIFUJI Hideaki / 吉藤英明 #elif defined(__LITTLE_ENDIAN) 3715206c579SYOSHIFUJI Hideaki / 吉藤英明 if (__builtin_constant_p(wl) && __builtin_constant_p(wh)) { 3725206c579SYOSHIFUJI Hideaki / 吉藤英明 *(__force u64 *)addr = ((__force u64)(wl) << 32 | (__force u64)(wh)); 3735206c579SYOSHIFUJI Hideaki / 吉藤英明 return; 3745206c579SYOSHIFUJI Hideaki / 吉藤英明 } 3755206c579SYOSHIFUJI Hideaki / 吉藤英明 #endif 3765206c579SYOSHIFUJI Hideaki / 吉藤英明 #endif 3775206c579SYOSHIFUJI Hideaki / 吉藤英明 addr[0] = wh; 3785206c579SYOSHIFUJI Hideaki / 吉藤英明 addr[1] = wl; 3795206c579SYOSHIFUJI Hideaki / 吉藤英明 } 3805206c579SYOSHIFUJI Hideaki / 吉藤英明 3811da177e4SLinus Torvalds static inline void ipv6_addr_set(struct in6_addr *addr, 38248818f82SAl Viro __be32 w1, __be32 w2, 38348818f82SAl Viro __be32 w3, __be32 w4) 3841da177e4SLinus Torvalds { 3855206c579SYOSHIFUJI Hideaki / 吉藤英明 __ipv6_addr_set_half(&addr->s6_addr32[0], w1, w2); 3865206c579SYOSHIFUJI Hideaki / 吉藤英明 __ipv6_addr_set_half(&addr->s6_addr32[2], w3, w4); 3871da177e4SLinus Torvalds } 3881da177e4SLinus Torvalds 38992113bfdSEric Dumazet static inline bool ipv6_addr_equal(const struct in6_addr *a1, 3901da177e4SLinus Torvalds const struct in6_addr *a2) 3911da177e4SLinus Torvalds { 3921a203cb3SEric Dumazet #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 3931a203cb3SEric Dumazet const unsigned long *ul1 = (const unsigned long *)a1; 3941a203cb3SEric Dumazet const unsigned long *ul2 = (const unsigned long *)a2; 3951a203cb3SEric Dumazet 3961a203cb3SEric Dumazet return ((ul1[0] ^ ul2[0]) | (ul1[1] ^ ul2[1])) == 0UL; 3971a203cb3SEric Dumazet #else 398a02cec21SEric Dumazet return ((a1->s6_addr32[0] ^ a2->s6_addr32[0]) | 399fed85383SYOSHIFUJI Hideaki (a1->s6_addr32[1] ^ a2->s6_addr32[1]) | 400fed85383SYOSHIFUJI Hideaki (a1->s6_addr32[2] ^ a2->s6_addr32[2]) | 401a02cec21SEric Dumazet (a1->s6_addr32[3] ^ a2->s6_addr32[3])) == 0; 4021a203cb3SEric Dumazet #endif 4031da177e4SLinus Torvalds } 4041da177e4SLinus Torvalds 40538675170SYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 40638675170SYOSHIFUJI Hideaki / 吉藤英明 static inline bool __ipv6_prefix_equal64_half(const __be64 *a1, 40738675170SYOSHIFUJI Hideaki / 吉藤英明 const __be64 *a2, 40838675170SYOSHIFUJI Hideaki / 吉藤英明 unsigned int len) 40938675170SYOSHIFUJI Hideaki / 吉藤英明 { 410512613d7SFabio Baltieri if (len && ((*a1 ^ *a2) & cpu_to_be64((~0UL) << (64 - len)))) 41138675170SYOSHIFUJI Hideaki / 吉藤英明 return false; 41238675170SYOSHIFUJI Hideaki / 吉藤英明 return true; 41338675170SYOSHIFUJI Hideaki / 吉藤英明 } 41438675170SYOSHIFUJI Hideaki / 吉藤英明 41538675170SYOSHIFUJI Hideaki / 吉藤英明 static inline bool ipv6_prefix_equal(const struct in6_addr *addr1, 41638675170SYOSHIFUJI Hideaki / 吉藤英明 const struct in6_addr *addr2, 41738675170SYOSHIFUJI Hideaki / 吉藤英明 unsigned int prefixlen) 41838675170SYOSHIFUJI Hideaki / 吉藤英明 { 41938675170SYOSHIFUJI Hideaki / 吉藤英明 const __be64 *a1 = (const __be64 *)addr1; 42038675170SYOSHIFUJI Hideaki / 吉藤英明 const __be64 *a2 = (const __be64 *)addr2; 42138675170SYOSHIFUJI Hideaki / 吉藤英明 42238675170SYOSHIFUJI Hideaki / 吉藤英明 if (prefixlen >= 64) { 42338675170SYOSHIFUJI Hideaki / 吉藤英明 if (a1[0] ^ a2[0]) 42438675170SYOSHIFUJI Hideaki / 吉藤英明 return false; 42538675170SYOSHIFUJI Hideaki / 吉藤英明 return __ipv6_prefix_equal64_half(a1 + 1, a2 + 1, prefixlen - 64); 42638675170SYOSHIFUJI Hideaki / 吉藤英明 } 42738675170SYOSHIFUJI Hideaki / 吉藤英明 return __ipv6_prefix_equal64_half(a1, a2, prefixlen); 42838675170SYOSHIFUJI Hideaki / 吉藤英明 } 42938675170SYOSHIFUJI Hideaki / 吉藤英明 #else 4302ef97332SYOSHIFUJI Hideaki / 吉藤英明 static inline bool ipv6_prefix_equal(const struct in6_addr *addr1, 4312ef97332SYOSHIFUJI Hideaki / 吉藤英明 const struct in6_addr *addr2, 4321da177e4SLinus Torvalds unsigned int prefixlen) 4331da177e4SLinus Torvalds { 4342ef97332SYOSHIFUJI Hideaki / 吉藤英明 const __be32 *a1 = addr1->s6_addr32; 4352ef97332SYOSHIFUJI Hideaki / 吉藤英明 const __be32 *a2 = addr2->s6_addr32; 43695c96174SEric Dumazet unsigned int pdw, pbi; 4371da177e4SLinus Torvalds 4381da177e4SLinus Torvalds /* check complete u32 in prefix */ 4391da177e4SLinus Torvalds pdw = prefixlen >> 5; 4401da177e4SLinus Torvalds if (pdw && memcmp(a1, a2, pdw << 2)) 44192113bfdSEric Dumazet return false; 4421da177e4SLinus Torvalds 4431da177e4SLinus Torvalds /* check incomplete u32 in prefix */ 4441da177e4SLinus Torvalds pbi = prefixlen & 0x1f; 4451da177e4SLinus Torvalds if (pbi && ((a1[pdw] ^ a2[pdw]) & htonl((0xffffffff) << (32 - pbi)))) 44692113bfdSEric Dumazet return false; 4471da177e4SLinus Torvalds 44892113bfdSEric Dumazet return true; 4491da177e4SLinus Torvalds } 45038675170SYOSHIFUJI Hideaki / 吉藤英明 #endif 4511da177e4SLinus Torvalds 4522588fe1dSPavel Emelyanov struct inet_frag_queue; 4532588fe1dSPavel Emelyanov 4540b5ccb2eSPatrick McHardy enum ip6_defrag_users { 4550b5ccb2eSPatrick McHardy IP6_DEFRAG_LOCAL_DELIVER, 4560b5ccb2eSPatrick McHardy IP6_DEFRAG_CONNTRACK_IN, 4574be929beSAlexey Dobriyan __IP6_DEFRAG_CONNTRACK_IN = IP6_DEFRAG_CONNTRACK_IN + USHRT_MAX, 4580b5ccb2eSPatrick McHardy IP6_DEFRAG_CONNTRACK_OUT, 4594be929beSAlexey Dobriyan __IP6_DEFRAG_CONNTRACK_OUT = IP6_DEFRAG_CONNTRACK_OUT + USHRT_MAX, 4608fa9ff68SPatrick McHardy IP6_DEFRAG_CONNTRACK_BRIDGE_IN, 4614be929beSAlexey Dobriyan __IP6_DEFRAG_CONNTRACK_BRIDGE_IN = IP6_DEFRAG_CONNTRACK_BRIDGE_IN + USHRT_MAX, 4620b5ccb2eSPatrick McHardy }; 4630b5ccb2eSPatrick McHardy 464c6fda282SPavel Emelyanov struct ip6_create_arg { 465c6fda282SPavel Emelyanov __be32 id; 4660b5ccb2eSPatrick McHardy u32 user; 467b71d1d42SEric Dumazet const struct in6_addr *src; 468b71d1d42SEric Dumazet const struct in6_addr *dst; 469c6fda282SPavel Emelyanov }; 470c6fda282SPavel Emelyanov 471c6fda282SPavel Emelyanov void ip6_frag_init(struct inet_frag_queue *q, void *a); 472cbc264caSEric Dumazet bool ip6_frag_match(struct inet_frag_queue *q, void *a); 473c6fda282SPavel Emelyanov 474b836c99fSAmerigo Wang /* 475b836c99fSAmerigo Wang * Equivalent of ipv4 struct ip 476b836c99fSAmerigo Wang */ 477b836c99fSAmerigo Wang struct frag_queue { 478b836c99fSAmerigo Wang struct inet_frag_queue q; 479b836c99fSAmerigo Wang 480b836c99fSAmerigo Wang __be32 id; /* fragment id */ 481b836c99fSAmerigo Wang u32 user; 482b836c99fSAmerigo Wang struct in6_addr saddr; 483b836c99fSAmerigo Wang struct in6_addr daddr; 484b836c99fSAmerigo Wang 485b836c99fSAmerigo Wang int iif; 486b836c99fSAmerigo Wang unsigned int csum; 487b836c99fSAmerigo Wang __u16 nhoffset; 488b836c99fSAmerigo Wang }; 489b836c99fSAmerigo Wang 490b836c99fSAmerigo Wang void ip6_expire_frag_queue(struct net *net, struct frag_queue *fq, 491b836c99fSAmerigo Wang struct inet_frags *frags); 492b836c99fSAmerigo Wang 49392113bfdSEric Dumazet static inline bool ipv6_addr_any(const struct in6_addr *a) 4941da177e4SLinus Torvalds { 4951a203cb3SEric Dumazet #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 4961a203cb3SEric Dumazet const unsigned long *ul = (const unsigned long *)a; 4971a203cb3SEric Dumazet 4981a203cb3SEric Dumazet return (ul[0] | ul[1]) == 0UL; 4991a203cb3SEric Dumazet #else 500a02cec21SEric Dumazet return (a->s6_addr32[0] | a->s6_addr32[1] | 501a02cec21SEric Dumazet a->s6_addr32[2] | a->s6_addr32[3]) == 0; 5021a203cb3SEric Dumazet #endif 5031da177e4SLinus Torvalds } 5041da177e4SLinus Torvalds 505ddbe5032SEric Dumazet static inline u32 ipv6_addr_hash(const struct in6_addr *a) 506ddbe5032SEric Dumazet { 507ddbe5032SEric Dumazet #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 508ddbe5032SEric Dumazet const unsigned long *ul = (const unsigned long *)a; 509ddbe5032SEric Dumazet unsigned long x = ul[0] ^ ul[1]; 510ddbe5032SEric Dumazet 511ddbe5032SEric Dumazet return (u32)(x ^ (x >> 32)); 512ddbe5032SEric Dumazet #else 513ddbe5032SEric Dumazet return (__force u32)(a->s6_addr32[0] ^ a->s6_addr32[1] ^ 514ddbe5032SEric Dumazet a->s6_addr32[2] ^ a->s6_addr32[3]); 515ddbe5032SEric Dumazet #endif 516ddbe5032SEric Dumazet } 517ddbe5032SEric Dumazet 51808dcdbf6SEric Dumazet /* more secured version of ipv6_addr_hash() */ 51908dcdbf6SEric Dumazet static inline u32 ipv6_addr_jhash(const struct in6_addr *a) 52008dcdbf6SEric Dumazet { 52108dcdbf6SEric Dumazet u32 v = (__force u32)a->s6_addr32[0] ^ (__force u32)a->s6_addr32[1]; 52208dcdbf6SEric Dumazet 52308dcdbf6SEric Dumazet return jhash_3words(v, 52408dcdbf6SEric Dumazet (__force u32)a->s6_addr32[2], 52508dcdbf6SEric Dumazet (__force u32)a->s6_addr32[3], 52608dcdbf6SEric Dumazet ipv6_hash_secret); 52708dcdbf6SEric Dumazet } 52808dcdbf6SEric Dumazet 52992113bfdSEric Dumazet static inline bool ipv6_addr_loopback(const struct in6_addr *a) 530f630e43aSYOSHIFUJI Hideaki { 531e287656bSYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 532e287656bSYOSHIFUJI Hideaki / 吉藤英明 const unsigned long *ul = (const unsigned long *)a; 533e287656bSYOSHIFUJI Hideaki / 吉藤英明 534e287656bSYOSHIFUJI Hideaki / 吉藤英明 return (ul[0] | (ul[1] ^ cpu_to_be64(1))) == 0UL; 535e287656bSYOSHIFUJI Hideaki / 吉藤英明 #else 536a02cec21SEric Dumazet return (a->s6_addr32[0] | a->s6_addr32[1] | 537a02cec21SEric Dumazet a->s6_addr32[2] | (a->s6_addr32[3] ^ htonl(1))) == 0; 538e287656bSYOSHIFUJI Hideaki / 吉藤英明 #endif 539f630e43aSYOSHIFUJI Hideaki } 540f630e43aSYOSHIFUJI Hideaki 54192113bfdSEric Dumazet static inline bool ipv6_addr_v4mapped(const struct in6_addr *a) 542e773e4faSBrian Haley { 543a04d40b8SYOSHIFUJI Hideaki / 吉藤英明 return ( 544a04d40b8SYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 545a04d40b8SYOSHIFUJI Hideaki / 吉藤英明 *(__be64 *)a | 546a04d40b8SYOSHIFUJI Hideaki / 吉藤英明 #else 547a04d40b8SYOSHIFUJI Hideaki / 吉藤英明 (a->s6_addr32[0] | a->s6_addr32[1]) | 548a04d40b8SYOSHIFUJI Hideaki / 吉藤英明 #endif 549a04d40b8SYOSHIFUJI Hideaki / 吉藤英明 (a->s6_addr32[2] ^ htonl(0x0000ffff))) == 0UL; 550e773e4faSBrian Haley } 551e773e4faSBrian Haley 5521da177e4SLinus Torvalds /* 55399cd07a5SJuha-Matti Tapio * Check for a RFC 4843 ORCHID address 55499cd07a5SJuha-Matti Tapio * (Overlay Routable Cryptographic Hash Identifiers) 55599cd07a5SJuha-Matti Tapio */ 55692113bfdSEric Dumazet static inline bool ipv6_addr_orchid(const struct in6_addr *a) 55799cd07a5SJuha-Matti Tapio { 558a02cec21SEric Dumazet return (a->s6_addr32[0] & htonl(0xfffffff0)) == htonl(0x20010010); 55999cd07a5SJuha-Matti Tapio } 56099cd07a5SJuha-Matti Tapio 561f15364bdSAurélien Charbon static inline void ipv6_addr_set_v4mapped(const __be32 addr, 562f15364bdSAurélien Charbon struct in6_addr *v4mapped) 563f15364bdSAurélien Charbon { 564f15364bdSAurélien Charbon ipv6_addr_set(v4mapped, 565f15364bdSAurélien Charbon 0, 0, 566f15364bdSAurélien Charbon htonl(0x0000FFFF), 567f15364bdSAurélien Charbon addr); 568f15364bdSAurélien Charbon } 569f15364bdSAurélien Charbon 57099cd07a5SJuha-Matti Tapio /* 571971f359dSYOSHIFUJI Hideaki * find the first different bit between two addresses 572971f359dSYOSHIFUJI Hideaki * length of address must be a multiple of 32bits 573971f359dSYOSHIFUJI Hideaki */ 5749f2e7334SYOSHIFUJI Hideaki / 吉藤英明 static inline int __ipv6_addr_diff32(const void *token1, const void *token2, int addrlen) 575971f359dSYOSHIFUJI Hideaki { 576ef296f56SAl Viro const __be32 *a1 = token1, *a2 = token2; 577971f359dSYOSHIFUJI Hideaki int i; 578971f359dSYOSHIFUJI Hideaki 579971f359dSYOSHIFUJI Hideaki addrlen >>= 2; 580971f359dSYOSHIFUJI Hideaki 581971f359dSYOSHIFUJI Hideaki for (i = 0; i < addrlen; i++) { 582ef296f56SAl Viro __be32 xb = a1[i] ^ a2[i]; 583ef296f56SAl Viro if (xb) 584d57b8fb8SYOSHIFUJI Hideaki / 吉藤英明 return i * 32 + 31 - __fls(ntohl(xb)); 585971f359dSYOSHIFUJI Hideaki } 586971f359dSYOSHIFUJI Hideaki 587971f359dSYOSHIFUJI Hideaki /* 588971f359dSYOSHIFUJI Hideaki * we should *never* get to this point since that 589971f359dSYOSHIFUJI Hideaki * would mean the addrs are equal 590971f359dSYOSHIFUJI Hideaki * 591971f359dSYOSHIFUJI Hideaki * However, we do get to it 8) And exacly, when 592971f359dSYOSHIFUJI Hideaki * addresses are equal 8) 593971f359dSYOSHIFUJI Hideaki * 594971f359dSYOSHIFUJI Hideaki * ip route add 1111::/128 via ... 595971f359dSYOSHIFUJI Hideaki * ip route add 1111::/64 via ... 596971f359dSYOSHIFUJI Hideaki * and we are here. 597971f359dSYOSHIFUJI Hideaki * 598971f359dSYOSHIFUJI Hideaki * Ideally, this function should stop comparison 599971f359dSYOSHIFUJI Hideaki * at prefix length. It does not, but it is still OK, 600971f359dSYOSHIFUJI Hideaki * if returned value is greater than prefix length. 601971f359dSYOSHIFUJI Hideaki * --ANK (980803) 602971f359dSYOSHIFUJI Hideaki */ 603a02cec21SEric Dumazet return addrlen << 5; 604971f359dSYOSHIFUJI Hideaki } 605971f359dSYOSHIFUJI Hideaki 6069f2e7334SYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 6079f2e7334SYOSHIFUJI Hideaki / 吉藤英明 static inline int __ipv6_addr_diff64(const void *token1, const void *token2, int addrlen) 6089f2e7334SYOSHIFUJI Hideaki / 吉藤英明 { 6099f2e7334SYOSHIFUJI Hideaki / 吉藤英明 const __be64 *a1 = token1, *a2 = token2; 6109f2e7334SYOSHIFUJI Hideaki / 吉藤英明 int i; 6119f2e7334SYOSHIFUJI Hideaki / 吉藤英明 6129f2e7334SYOSHIFUJI Hideaki / 吉藤英明 addrlen >>= 3; 6139f2e7334SYOSHIFUJI Hideaki / 吉藤英明 6149f2e7334SYOSHIFUJI Hideaki / 吉藤英明 for (i = 0; i < addrlen; i++) { 6159f2e7334SYOSHIFUJI Hideaki / 吉藤英明 __be64 xb = a1[i] ^ a2[i]; 6169f2e7334SYOSHIFUJI Hideaki / 吉藤英明 if (xb) 6179f2e7334SYOSHIFUJI Hideaki / 吉藤英明 return i * 64 + 63 - __fls(be64_to_cpu(xb)); 6189f2e7334SYOSHIFUJI Hideaki / 吉藤英明 } 6199f2e7334SYOSHIFUJI Hideaki / 吉藤英明 6209f2e7334SYOSHIFUJI Hideaki / 吉藤英明 return addrlen << 6; 6219f2e7334SYOSHIFUJI Hideaki / 吉藤英明 } 6229f2e7334SYOSHIFUJI Hideaki / 吉藤英明 #endif 6239f2e7334SYOSHIFUJI Hideaki / 吉藤英明 6249f2e7334SYOSHIFUJI Hideaki / 吉藤英明 static inline int __ipv6_addr_diff(const void *token1, const void *token2, int addrlen) 6259f2e7334SYOSHIFUJI Hideaki / 吉藤英明 { 6269f2e7334SYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 6279f2e7334SYOSHIFUJI Hideaki / 吉藤英明 if (__builtin_constant_p(addrlen) && !(addrlen & 7)) 6289f2e7334SYOSHIFUJI Hideaki / 吉藤英明 return __ipv6_addr_diff64(token1, token2, addrlen); 6299f2e7334SYOSHIFUJI Hideaki / 吉藤英明 #endif 6309f2e7334SYOSHIFUJI Hideaki / 吉藤英明 return __ipv6_addr_diff32(token1, token2, addrlen); 6319f2e7334SYOSHIFUJI Hideaki / 吉藤英明 } 6329f2e7334SYOSHIFUJI Hideaki / 吉藤英明 633971f359dSYOSHIFUJI Hideaki static inline int ipv6_addr_diff(const struct in6_addr *a1, const struct in6_addr *a2) 634971f359dSYOSHIFUJI Hideaki { 635971f359dSYOSHIFUJI Hideaki return __ipv6_addr_diff(a1, a2, sizeof(struct in6_addr)); 636971f359dSYOSHIFUJI Hideaki } 637971f359dSYOSHIFUJI Hideaki 63887c48fa3SEric Dumazet extern void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt); 6397ea2f2c5SSridhar Samudrala 640971f359dSYOSHIFUJI Hideaki /* 6413e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 * Header manipulation 6423e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 */ 6433e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 static inline void ip6_flow_hdr(struct ipv6hdr *hdr, unsigned int tclass, 6443e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 __be32 flowlabel) 6453e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 { 64607f623d3SYOSHIFUJI Hideaki *(__be32 *)hdr = htonl(0x60000000 | (tclass << 20)) | flowlabel; 6473e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 } 6483e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 6496502ca52SYOSHIFUJI Hideaki / 吉藤英明 static inline __be32 ip6_flowinfo(const struct ipv6hdr *hdr) 6506502ca52SYOSHIFUJI Hideaki / 吉藤英明 { 6516502ca52SYOSHIFUJI Hideaki / 吉藤英明 return *(__be32 *)hdr & IPV6_FLOWINFO_MASK; 6526502ca52SYOSHIFUJI Hideaki / 吉藤英明 } 6536502ca52SYOSHIFUJI Hideaki / 吉藤英明 6543e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 /* 6551da177e4SLinus Torvalds * Prototypes exported by ipv6 6561da177e4SLinus Torvalds */ 6571da177e4SLinus Torvalds 6581da177e4SLinus Torvalds /* 6591da177e4SLinus Torvalds * rcv function (called from netdevice level) 6601da177e4SLinus Torvalds */ 6611da177e4SLinus Torvalds 6621da177e4SLinus Torvalds extern int ipv6_rcv(struct sk_buff *skb, 6631da177e4SLinus Torvalds struct net_device *dev, 664f2ccd8faSDavid S. Miller struct packet_type *pt, 665f2ccd8faSDavid S. Miller struct net_device *orig_dev); 6661da177e4SLinus Torvalds 667b05e1066SPatrick McHardy extern int ip6_rcv_finish(struct sk_buff *skb); 668b05e1066SPatrick McHardy 6691da177e4SLinus Torvalds /* 6701da177e4SLinus Torvalds * upper-layer output functions 6711da177e4SLinus Torvalds */ 6721da177e4SLinus Torvalds extern int ip6_xmit(struct sock *sk, 6731da177e4SLinus Torvalds struct sk_buff *skb, 6744c9483b2SDavid S. Miller struct flowi6 *fl6, 675b903d324SEric Dumazet struct ipv6_txoptions *opt, 676b903d324SEric Dumazet int tclass); 6771da177e4SLinus Torvalds 6781da177e4SLinus Torvalds extern int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr); 6791da177e4SLinus Torvalds 6801da177e4SLinus Torvalds extern int ip6_append_data(struct sock *sk, 6811da177e4SLinus Torvalds int getfrag(void *from, char *to, int offset, int len, int odd, struct sk_buff *skb), 6821da177e4SLinus Torvalds void *from, 6831da177e4SLinus Torvalds int length, 6841da177e4SLinus Torvalds int transhdrlen, 6851da177e4SLinus Torvalds int hlimit, 68641a1f8eaSYOSHIFUJI Hideaki int tclass, 6871da177e4SLinus Torvalds struct ipv6_txoptions *opt, 6884c9483b2SDavid S. Miller struct flowi6 *fl6, 6891da177e4SLinus Torvalds struct rt6_info *rt, 69013b52cd4SBrian Haley unsigned int flags, 69113b52cd4SBrian Haley int dontfrag); 6921da177e4SLinus Torvalds 6931da177e4SLinus Torvalds extern int ip6_push_pending_frames(struct sock *sk); 6941da177e4SLinus Torvalds 6951da177e4SLinus Torvalds extern void ip6_flush_pending_frames(struct sock *sk); 6961da177e4SLinus Torvalds 6971da177e4SLinus Torvalds extern int ip6_dst_lookup(struct sock *sk, 6981da177e4SLinus Torvalds struct dst_entry **dst, 6994c9483b2SDavid S. Miller struct flowi6 *fl6); 70068d0c6d3SDavid S. Miller extern struct dst_entry * ip6_dst_lookup_flow(struct sock *sk, 7014c9483b2SDavid S. Miller struct flowi6 *fl6, 70268d0c6d3SDavid S. Miller const struct in6_addr *final_dst, 703a1414715SDavid S. Miller bool can_sleep); 70468d0c6d3SDavid S. Miller extern struct dst_entry * ip6_sk_dst_lookup_flow(struct sock *sk, 7054c9483b2SDavid S. Miller struct flowi6 *fl6, 70668d0c6d3SDavid S. Miller const struct in6_addr *final_dst, 707a1414715SDavid S. Miller bool can_sleep); 7082774c131SDavid S. Miller extern struct dst_entry * ip6_blackhole_route(struct net *net, 70969ead7afSDavid S. Miller struct dst_entry *orig_dst); 7101da177e4SLinus Torvalds 7111da177e4SLinus Torvalds /* 7121da177e4SLinus Torvalds * skb processing functions 7131da177e4SLinus Torvalds */ 7141da177e4SLinus Torvalds 7151da177e4SLinus Torvalds extern int ip6_output(struct sk_buff *skb); 7161da177e4SLinus Torvalds extern int ip6_forward(struct sk_buff *skb); 7171da177e4SLinus Torvalds extern int ip6_input(struct sk_buff *skb); 7181da177e4SLinus Torvalds extern int ip6_mc_input(struct sk_buff *skb); 7191da177e4SLinus Torvalds 720ef76bc23SHerbert Xu extern int __ip6_local_out(struct sk_buff *skb); 721ef76bc23SHerbert Xu extern int ip6_local_out(struct sk_buff *skb); 722ef76bc23SHerbert Xu 7231da177e4SLinus Torvalds /* 7241da177e4SLinus Torvalds * Extension header (options) processing 7251da177e4SLinus Torvalds */ 7261da177e4SLinus Torvalds 7271da177e4SLinus Torvalds extern void ipv6_push_nfrag_opts(struct sk_buff *skb, 7281da177e4SLinus Torvalds struct ipv6_txoptions *opt, 7291da177e4SLinus Torvalds u8 *proto, 7301da177e4SLinus Torvalds struct in6_addr **daddr_p); 7311da177e4SLinus Torvalds extern void ipv6_push_frag_opts(struct sk_buff *skb, 7321da177e4SLinus Torvalds struct ipv6_txoptions *opt, 7331da177e4SLinus Torvalds u8 *proto); 7341da177e4SLinus Torvalds 7351da177e4SLinus Torvalds extern int ipv6_skip_exthdr(const struct sk_buff *, int start, 73675f2811cSJesse Gross u8 *nexthdrp, __be16 *frag_offp); 7371da177e4SLinus Torvalds 738a50feda5SEric Dumazet extern bool ipv6_ext_hdr(u8 nexthdr); 7391da177e4SLinus Torvalds 740f8f62675SJesse Gross enum { 741f8f62675SJesse Gross IP6_FH_F_FRAG = (1 << 0), 742f8f62675SJesse Gross IP6_FH_F_AUTH = (1 << 1), 7439195bb8eSAnsis Atteka IP6_FH_F_SKIP_RH = (1 << 2), 744f8f62675SJesse Gross }; 745f8f62675SJesse Gross 746f8f62675SJesse Gross /* find specified header and get offset to it */ 747f8f62675SJesse Gross extern int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset, 748f8f62675SJesse Gross int target, unsigned short *fragoff, int *fragflg); 749f8f62675SJesse Gross 750c61a4043SMasahide NAKAMURA extern int ipv6_find_tlv(struct sk_buff *skb, int offset, int type); 751c61a4043SMasahide NAKAMURA 7524c9483b2SDavid S. Miller extern struct in6_addr *fl6_update_dst(struct flowi6 *fl6, 75320c59de2SArnaud Ebalard const struct ipv6_txoptions *opt, 75420c59de2SArnaud Ebalard struct in6_addr *orig); 75520c59de2SArnaud Ebalard 7561da177e4SLinus Torvalds /* 7571da177e4SLinus Torvalds * socket options (ipv6_sockglue.c) 7581da177e4SLinus Torvalds */ 7591da177e4SLinus Torvalds 7601da177e4SLinus Torvalds extern int ipv6_setsockopt(struct sock *sk, int level, 7611da177e4SLinus Torvalds int optname, 7621da177e4SLinus Torvalds char __user *optval, 763b7058842SDavid S. Miller unsigned int optlen); 7641da177e4SLinus Torvalds extern int ipv6_getsockopt(struct sock *sk, int level, 7651da177e4SLinus Torvalds int optname, 7661da177e4SLinus Torvalds char __user *optval, 7671da177e4SLinus Torvalds int __user *optlen); 7683fdadf7dSDmitry Mishin extern int compat_ipv6_setsockopt(struct sock *sk, 7693fdadf7dSDmitry Mishin int level, 7703fdadf7dSDmitry Mishin int optname, 7713fdadf7dSDmitry Mishin char __user *optval, 772b7058842SDavid S. Miller unsigned int optlen); 7733fdadf7dSDmitry Mishin extern int compat_ipv6_getsockopt(struct sock *sk, 7743fdadf7dSDmitry Mishin int level, 7753fdadf7dSDmitry Mishin int optname, 7763fdadf7dSDmitry Mishin char __user *optval, 7773fdadf7dSDmitry Mishin int __user *optlen); 7781da177e4SLinus Torvalds 7791da177e4SLinus Torvalds extern int ip6_datagram_connect(struct sock *sk, 7801da177e4SLinus Torvalds struct sockaddr *addr, int addr_len); 7811da177e4SLinus Torvalds 7821da177e4SLinus Torvalds extern int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len); 7834b340ae2SBrian Haley extern int ipv6_recv_rxpmtu(struct sock *sk, struct msghdr *msg, int len); 784e69a4adcSAl Viro extern void ipv6_icmp_error(struct sock *sk, struct sk_buff *skb, int err, __be16 port, 7851da177e4SLinus Torvalds u32 info, u8 *payload); 7864c9483b2SDavid S. Miller extern void ipv6_local_error(struct sock *sk, int err, struct flowi6 *fl6, u32 info); 7874c9483b2SDavid S. Miller extern void ipv6_local_rxpmtu(struct sock *sk, struct flowi6 *fl6, u32 mtu); 7881da177e4SLinus Torvalds 7891da177e4SLinus Torvalds extern int inet6_release(struct socket *sock); 7901da177e4SLinus Torvalds extern int inet6_bind(struct socket *sock, struct sockaddr *uaddr, 7911da177e4SLinus Torvalds int addr_len); 7921da177e4SLinus Torvalds extern int inet6_getname(struct socket *sock, struct sockaddr *uaddr, 7931da177e4SLinus Torvalds int *uaddr_len, int peer); 7941da177e4SLinus Torvalds extern int inet6_ioctl(struct socket *sock, unsigned int cmd, 7951da177e4SLinus Torvalds unsigned long arg); 7961da177e4SLinus Torvalds 797d8313f5cSArnaldo Carvalho de Melo extern int inet6_hash_connect(struct inet_timewait_death_row *death_row, 798d8313f5cSArnaldo Carvalho de Melo struct sock *sk); 799d8313f5cSArnaldo Carvalho de Melo 8001da177e4SLinus Torvalds /* 8011da177e4SLinus Torvalds * reassembly.c 8021da177e4SLinus Torvalds */ 80390ddc4f0SEric Dumazet extern const struct proto_ops inet6_stream_ops; 80490ddc4f0SEric Dumazet extern const struct proto_ops inet6_dgram_ops; 80520380731SArnaldo Carvalho de Melo 80614c85021SArnaldo Carvalho de Melo struct group_source_req; 80714c85021SArnaldo Carvalho de Melo struct group_filter; 80814c85021SArnaldo Carvalho de Melo 80920380731SArnaldo Carvalho de Melo extern int ip6_mc_source(int add, int omode, struct sock *sk, 81020380731SArnaldo Carvalho de Melo struct group_source_req *pgsr); 81120380731SArnaldo Carvalho de Melo extern int ip6_mc_msfilter(struct sock *sk, struct group_filter *gsf); 81220380731SArnaldo Carvalho de Melo extern int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf, 81320380731SArnaldo Carvalho de Melo struct group_filter __user *optval, 81420380731SArnaldo Carvalho de Melo int __user *optlen); 81593c8b90fSIlpo Järvinen extern unsigned int inet6_hash_frag(__be32 id, const struct in6_addr *saddr, 81693c8b90fSIlpo Järvinen const struct in6_addr *daddr, u32 rnd); 81720380731SArnaldo Carvalho de Melo 81820380731SArnaldo Carvalho de Melo #ifdef CONFIG_PROC_FS 8196ab57e7eSDaniel Lezcano extern int ac6_proc_init(struct net *net); 8206ab57e7eSDaniel Lezcano extern void ac6_proc_exit(struct net *net); 82120380731SArnaldo Carvalho de Melo extern int raw6_proc_init(void); 82220380731SArnaldo Carvalho de Melo extern void raw6_proc_exit(void); 8236f8b13bcSDaniel Lezcano extern int tcp6_proc_init(struct net *net); 8246f8b13bcSDaniel Lezcano extern void tcp6_proc_exit(struct net *net); 8250c96d8c5SDaniel Lezcano extern int udp6_proc_init(struct net *net); 8260c96d8c5SDaniel Lezcano extern void udp6_proc_exit(struct net *net); 827ba4e58ecSGerrit Renker extern int udplite6_proc_init(void); 828ba4e58ecSGerrit Renker extern void udplite6_proc_exit(void); 82920380731SArnaldo Carvalho de Melo extern int ipv6_misc_proc_init(void); 83020380731SArnaldo Carvalho de Melo extern void ipv6_misc_proc_exit(void); 8317f7d9a6bSHerbert Xu extern int snmp6_register_dev(struct inet6_dev *idev); 8327f7d9a6bSHerbert Xu extern int snmp6_unregister_dev(struct inet6_dev *idev); 83320380731SArnaldo Carvalho de Melo 8347f7d9a6bSHerbert Xu #else 8356ab57e7eSDaniel Lezcano static inline int ac6_proc_init(struct net *net) { return 0; } 8366ab57e7eSDaniel Lezcano static inline void ac6_proc_exit(struct net *net) { } 8376ab57e7eSDaniel Lezcano static inline int snmp6_register_dev(struct inet6_dev *idev) { return 0; } 8386ab57e7eSDaniel Lezcano static inline int snmp6_unregister_dev(struct inet6_dev *idev) { return 0; } 83920380731SArnaldo Carvalho de Melo #endif 84020380731SArnaldo Carvalho de Melo 84120380731SArnaldo Carvalho de Melo #ifdef CONFIG_SYSCTL 842760f2d01SDaniel Lezcano extern ctl_table ipv6_route_table_template[]; 843760f2d01SDaniel Lezcano extern ctl_table ipv6_icmp_table_template[]; 84420380731SArnaldo Carvalho de Melo 8456de1a910SDaniel Lezcano extern struct ctl_table *ipv6_icmp_sysctl_init(struct net *net); 8466de1a910SDaniel Lezcano extern struct ctl_table *ipv6_route_sysctl_init(struct net *net); 847291480c0SDaniel Lezcano extern int ipv6_sysctl_register(void); 84820380731SArnaldo Carvalho de Melo extern void ipv6_sysctl_unregister(void); 84920380731SArnaldo Carvalho de Melo #endif 85020380731SArnaldo Carvalho de Melo 8511da177e4SLinus Torvalds #endif /* _NET_IPV6_H */ 852