12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds * Linux INET6 implementation 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Authors: 61da177e4SLinus Torvalds * Pedro Roque <[email protected]> 71da177e4SLinus Torvalds */ 81da177e4SLinus Torvalds 91da177e4SLinus Torvalds #ifndef _NET_IPV6_H 101da177e4SLinus Torvalds #define _NET_IPV6_H 111da177e4SLinus Torvalds 121da177e4SLinus Torvalds #include <linux/ipv6.h> 131da177e4SLinus Torvalds #include <linux/hardirq.h> 1408dcdbf6SEric Dumazet #include <linux/jhash.h> 150aeea21aSReshetova, Elena #include <linux/refcount.h> 1620283d84SHerbert Xu #include <net/if_inet6.h> 171da177e4SLinus Torvalds #include <net/ndisc.h> 181da177e4SLinus Torvalds #include <net/flow.h> 191bd758ebSJiri Pirko #include <net/flow_dissector.h> 201da177e4SLinus Torvalds #include <net/snmp.h> 21f0b1e64cSMartin KaFai Lau #include <net/netns/hash.h> 221da177e4SLinus Torvalds 231da177e4SLinus Torvalds #define SIN6_LEN_RFC2133 24 241da177e4SLinus Torvalds 251da177e4SLinus Torvalds #define IPV6_MAXPLEN 65535 261da177e4SLinus Torvalds 271da177e4SLinus Torvalds /* 281da177e4SLinus Torvalds * NextHeader field of IPv6 header 291da177e4SLinus Torvalds */ 301da177e4SLinus Torvalds 311da177e4SLinus Torvalds #define NEXTHDR_HOP 0 /* Hop-by-hop option header. */ 321da177e4SLinus Torvalds #define NEXTHDR_TCP 6 /* TCP segment. */ 331da177e4SLinus Torvalds #define NEXTHDR_UDP 17 /* UDP message. */ 341da177e4SLinus Torvalds #define NEXTHDR_IPV6 41 /* IPv6 in IPv6 */ 351da177e4SLinus Torvalds #define NEXTHDR_ROUTING 43 /* Routing header. */ 361da177e4SLinus Torvalds #define NEXTHDR_FRAGMENT 44 /* Fragmentation/reassembly header. */ 37c12b395aS[email protected] #define NEXTHDR_GRE 47 /* GRE header. */ 381da177e4SLinus Torvalds #define NEXTHDR_ESP 50 /* Encapsulating security payload. */ 391da177e4SLinus Torvalds #define NEXTHDR_AUTH 51 /* Authentication header. */ 401da177e4SLinus Torvalds #define NEXTHDR_ICMP 58 /* ICMP for IPv6. */ 411da177e4SLinus Torvalds #define NEXTHDR_NONE 59 /* No next header */ 421da177e4SLinus Torvalds #define NEXTHDR_DEST 60 /* Destination options header. */ 43280c571eSJoe Stringer #define NEXTHDR_SCTP 132 /* SCTP message. */ 442b741653SMasahide NAKAMURA #define NEXTHDR_MOBILITY 135 /* Mobility header. */ 451da177e4SLinus Torvalds 461da177e4SLinus Torvalds #define NEXTHDR_MAX 255 471da177e4SLinus Torvalds 481da177e4SLinus Torvalds #define IPV6_DEFAULT_HOPLIMIT 64 491da177e4SLinus Torvalds #define IPV6_DEFAULT_MCASTHOPS 1 501da177e4SLinus Torvalds 5147d3d7acSTom Herbert /* Limits on Hop-by-Hop and Destination options. 5247d3d7acSTom Herbert * 5347d3d7acSTom Herbert * Per RFC8200 there is no limit on the maximum number or lengths of options in 5447d3d7acSTom Herbert * Hop-by-Hop or Destination options other then the packet must fit in an MTU. 5547d3d7acSTom Herbert * We allow configurable limits in order to mitigate potential denial of 5647d3d7acSTom Herbert * service attacks. 5747d3d7acSTom Herbert * 5847d3d7acSTom Herbert * There are three limits that may be set: 5947d3d7acSTom Herbert * - Limit the number of options in a Hop-by-Hop or Destination options 6047d3d7acSTom Herbert * extension header 6147d3d7acSTom Herbert * - Limit the byte length of a Hop-by-Hop or Destination options extension 6247d3d7acSTom Herbert * header 6347d3d7acSTom Herbert * - Disallow unknown options 6447d3d7acSTom Herbert * 6547d3d7acSTom Herbert * The limits are expressed in corresponding sysctls: 6647d3d7acSTom Herbert * 6747d3d7acSTom Herbert * ipv6.sysctl.max_dst_opts_cnt 6847d3d7acSTom Herbert * ipv6.sysctl.max_hbh_opts_cnt 6947d3d7acSTom Herbert * ipv6.sysctl.max_dst_opts_len 7047d3d7acSTom Herbert * ipv6.sysctl.max_hbh_opts_len 7147d3d7acSTom Herbert * 7247d3d7acSTom Herbert * max_*_opts_cnt is the number of TLVs that are allowed for Destination 7347d3d7acSTom Herbert * options or Hop-by-Hop options. If the number is less than zero then unknown 7447d3d7acSTom Herbert * TLVs are disallowed and the number of known options that are allowed is the 7547d3d7acSTom Herbert * absolute value. Setting the value to INT_MAX indicates no limit. 7647d3d7acSTom Herbert * 7747d3d7acSTom Herbert * max_*_opts_len is the length limit in bytes of a Destination or 7847d3d7acSTom Herbert * Hop-by-Hop options extension header. Setting the value to INT_MAX 7947d3d7acSTom Herbert * indicates no length limit. 8047d3d7acSTom Herbert * 8147d3d7acSTom Herbert * If a limit is exceeded when processing an extension header the packet is 8247d3d7acSTom Herbert * silently discarded. 8347d3d7acSTom Herbert */ 8447d3d7acSTom Herbert 8547d3d7acSTom Herbert /* Default limits for Hop-by-Hop and Destination options */ 8647d3d7acSTom Herbert #define IP6_DEFAULT_MAX_DST_OPTS_CNT 8 8747d3d7acSTom Herbert #define IP6_DEFAULT_MAX_HBH_OPTS_CNT 8 8847d3d7acSTom Herbert #define IP6_DEFAULT_MAX_DST_OPTS_LEN INT_MAX /* No limit */ 8947d3d7acSTom Herbert #define IP6_DEFAULT_MAX_HBH_OPTS_LEN INT_MAX /* No limit */ 9047d3d7acSTom Herbert 911da177e4SLinus Torvalds /* 921da177e4SLinus Torvalds * Addr type 931da177e4SLinus Torvalds * 941da177e4SLinus Torvalds * type - unicast | multicast 951da177e4SLinus Torvalds * scope - local | site | global 961da177e4SLinus Torvalds * v4 - compat 971da177e4SLinus Torvalds * v4mapped 981da177e4SLinus Torvalds * any 991da177e4SLinus Torvalds * loopback 1001da177e4SLinus Torvalds */ 1011da177e4SLinus Torvalds 1021da177e4SLinus Torvalds #define IPV6_ADDR_ANY 0x0000U 1031da177e4SLinus Torvalds 1041da177e4SLinus Torvalds #define IPV6_ADDR_UNICAST 0x0001U 1051da177e4SLinus Torvalds #define IPV6_ADDR_MULTICAST 0x0002U 1061da177e4SLinus Torvalds 1071da177e4SLinus Torvalds #define IPV6_ADDR_LOOPBACK 0x0010U 1081da177e4SLinus Torvalds #define IPV6_ADDR_LINKLOCAL 0x0020U 1091da177e4SLinus Torvalds #define IPV6_ADDR_SITELOCAL 0x0040U 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds #define IPV6_ADDR_COMPATv4 0x0080U 1121da177e4SLinus Torvalds 1131da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_MASK 0x00f0U 1141da177e4SLinus Torvalds 1151da177e4SLinus Torvalds #define IPV6_ADDR_MAPPED 0x1000U 1161da177e4SLinus Torvalds 1171da177e4SLinus Torvalds /* 1181da177e4SLinus Torvalds * Addr scopes 1191da177e4SLinus Torvalds */ 1201da177e4SLinus Torvalds #define IPV6_ADDR_MC_SCOPE(a) \ 1211da177e4SLinus Torvalds ((a)->s6_addr[1] & 0x0f) /* nonstandard */ 1221da177e4SLinus Torvalds #define __IPV6_ADDR_SCOPE_INVALID -1 1231da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_NODELOCAL 0x01 1241da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_LINKLOCAL 0x02 1251da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_SITELOCAL 0x05 1261da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_ORGLOCAL 0x08 1271da177e4SLinus Torvalds #define IPV6_ADDR_SCOPE_GLOBAL 0x0e 1281da177e4SLinus Torvalds 1291da177e4SLinus Torvalds /* 1305ced1339SLinus Lüssing * Addr flags 1315ced1339SLinus Lüssing */ 1325ced1339SLinus Lüssing #define IPV6_ADDR_MC_FLAG_TRANSIENT(a) \ 1335ced1339SLinus Lüssing ((a)->s6_addr[1] & 0x10) 1345ced1339SLinus Lüssing #define IPV6_ADDR_MC_FLAG_PREFIX(a) \ 1355ced1339SLinus Lüssing ((a)->s6_addr[1] & 0x20) 1365ced1339SLinus Lüssing #define IPV6_ADDR_MC_FLAG_RENDEZVOUS(a) \ 1375ced1339SLinus Lüssing ((a)->s6_addr[1] & 0x40) 1385ced1339SLinus Lüssing 1395ced1339SLinus Lüssing /* 1401da177e4SLinus Torvalds * fragmentation header 1411da177e4SLinus Torvalds */ 1421da177e4SLinus Torvalds 1431da177e4SLinus Torvalds struct frag_hdr { 14444473a6bSAl Viro __u8 nexthdr; 14544473a6bSAl Viro __u8 reserved; 14644473a6bSAl Viro __be16 frag_off; 14744473a6bSAl Viro __be32 identification; 1481da177e4SLinus Torvalds }; 1491da177e4SLinus Torvalds 1501da177e4SLinus Torvalds #define IP6_MF 0x0001 1511431fb31SPaul Durrant #define IP6_OFFSET 0xFFF8 1521da177e4SLinus Torvalds 1530feca619SPablo Neira Ayuso struct ip6_fraglist_iter { 1540feca619SPablo Neira Ayuso struct ipv6hdr *tmp_hdr; 1550feca619SPablo Neira Ayuso struct sk_buff *frag; 1560feca619SPablo Neira Ayuso int offset; 1570feca619SPablo Neira Ayuso unsigned int hlen; 1580feca619SPablo Neira Ayuso __be32 frag_id; 1590feca619SPablo Neira Ayuso u8 nexthdr; 1600feca619SPablo Neira Ayuso }; 1610feca619SPablo Neira Ayuso 1620feca619SPablo Neira Ayuso int ip6_fraglist_init(struct sk_buff *skb, unsigned int hlen, u8 *prevhdr, 1630feca619SPablo Neira Ayuso u8 nexthdr, __be32 frag_id, 1640feca619SPablo Neira Ayuso struct ip6_fraglist_iter *iter); 1650feca619SPablo Neira Ayuso void ip6_fraglist_prepare(struct sk_buff *skb, struct ip6_fraglist_iter *iter); 1660feca619SPablo Neira Ayuso 1670feca619SPablo Neira Ayuso static inline struct sk_buff *ip6_fraglist_next(struct ip6_fraglist_iter *iter) 1680feca619SPablo Neira Ayuso { 1690feca619SPablo Neira Ayuso struct sk_buff *skb = iter->frag; 1700feca619SPablo Neira Ayuso 1710feca619SPablo Neira Ayuso iter->frag = skb->next; 1720feca619SPablo Neira Ayuso skb_mark_not_on_list(skb); 1730feca619SPablo Neira Ayuso 1740feca619SPablo Neira Ayuso return skb; 1750feca619SPablo Neira Ayuso } 1760feca619SPablo Neira Ayuso 1778a6a1f17SPablo Neira Ayuso struct ip6_frag_state { 1788a6a1f17SPablo Neira Ayuso u8 *prevhdr; 1798a6a1f17SPablo Neira Ayuso unsigned int hlen; 1808a6a1f17SPablo Neira Ayuso unsigned int mtu; 1818a6a1f17SPablo Neira Ayuso unsigned int left; 1828a6a1f17SPablo Neira Ayuso int offset; 1838a6a1f17SPablo Neira Ayuso int ptr; 1848a6a1f17SPablo Neira Ayuso int hroom; 1858a6a1f17SPablo Neira Ayuso int troom; 1868a6a1f17SPablo Neira Ayuso __be32 frag_id; 1878a6a1f17SPablo Neira Ayuso u8 nexthdr; 1888a6a1f17SPablo Neira Ayuso }; 1898a6a1f17SPablo Neira Ayuso 1908a6a1f17SPablo Neira Ayuso void ip6_frag_init(struct sk_buff *skb, unsigned int hlen, unsigned int mtu, 1918a6a1f17SPablo Neira Ayuso unsigned short needed_tailroom, int hdr_room, u8 *prevhdr, 1928a6a1f17SPablo Neira Ayuso u8 nexthdr, __be32 frag_id, struct ip6_frag_state *state); 1938a6a1f17SPablo Neira Ayuso struct sk_buff *ip6_frag_next(struct sk_buff *skb, 1948a6a1f17SPablo Neira Ayuso struct ip6_frag_state *state); 1958a6a1f17SPablo Neira Ayuso 196e110861fSLorenzo Colitti #define IP6_REPLY_MARK(net, mark) \ 197e110861fSLorenzo Colitti ((net)->ipv6.sysctl.fwmark_reflect ? (mark) : 0) 198e110861fSLorenzo Colitti 1991da177e4SLinus Torvalds #include <net/sock.h> 2001da177e4SLinus Torvalds 2011da177e4SLinus Torvalds /* sysctls */ 2021da177e4SLinus Torvalds extern int sysctl_mld_max_msf; 2032f711939SHannes Frederic Sowa extern int sysctl_mld_qrv; 2043d7cc2baSPavel Emelyanov 20513415e46SEric Dumazet #define _DEVINC(net, statname, mod, idev, field) \ 20614878f75SDavid L Stevens ({ \ 20714878f75SDavid L Stevens struct inet6_dev *_idev = (idev); \ 20814878f75SDavid L Stevens if (likely(_idev != NULL)) \ 20913415e46SEric Dumazet mod##SNMP_INC_STATS64((_idev)->stats.statname, (field));\ 21013415e46SEric Dumazet mod##SNMP_INC_STATS64((net)->mib.statname##_statistics, (field));\ 21114878f75SDavid L Stevens }) 21214878f75SDavid L Stevens 213be281e55SEric Dumazet /* per device counters are atomic_long_t */ 21413415e46SEric Dumazet #define _DEVINCATOMIC(net, statname, mod, idev, field) \ 215be281e55SEric Dumazet ({ \ 216be281e55SEric Dumazet struct inet6_dev *_idev = (idev); \ 217be281e55SEric Dumazet if (likely(_idev != NULL)) \ 218be281e55SEric Dumazet SNMP_INC_STATS_ATOMIC_LONG((_idev)->stats.statname##dev, (field)); \ 21913415e46SEric Dumazet mod##SNMP_INC_STATS((net)->mib.statname##_statistics, (field));\ 220be281e55SEric Dumazet }) 221be281e55SEric Dumazet 2222a24444fSEric Dumazet /* per device and per net counters are atomic_long_t */ 2232a24444fSEric Dumazet #define _DEVINC_ATOMIC_ATOMIC(net, statname, idev, field) \ 2242a24444fSEric Dumazet ({ \ 2252a24444fSEric Dumazet struct inet6_dev *_idev = (idev); \ 2262a24444fSEric Dumazet if (likely(_idev != NULL)) \ 2272a24444fSEric Dumazet SNMP_INC_STATS_ATOMIC_LONG((_idev)->stats.statname##dev, (field)); \ 2282a24444fSEric Dumazet SNMP_INC_STATS_ATOMIC_LONG((net)->mib.statname##_statistics, (field));\ 2292a24444fSEric Dumazet }) 2302a24444fSEric Dumazet 23113415e46SEric Dumazet #define _DEVADD(net, statname, mod, idev, field, val) \ 2328e7999c4SPavel Emelyanov ({ \ 2338e7999c4SPavel Emelyanov struct inet6_dev *_idev = (idev); \ 2348e7999c4SPavel Emelyanov if (likely(_idev != NULL)) \ 23513415e46SEric Dumazet mod##SNMP_ADD_STATS((_idev)->stats.statname, (field), (val)); \ 23613415e46SEric Dumazet mod##SNMP_ADD_STATS((net)->mib.statname##_statistics, (field), (val));\ 2378e7999c4SPavel Emelyanov }) 2388e7999c4SPavel Emelyanov 23913415e46SEric Dumazet #define _DEVUPD(net, statname, mod, idev, field, val) \ 240edf391ffSNeil Horman ({ \ 241edf391ffSNeil Horman struct inet6_dev *_idev = (idev); \ 242edf391ffSNeil Horman if (likely(_idev != NULL)) \ 24313415e46SEric Dumazet mod##SNMP_UPD_PO_STATS((_idev)->stats.statname, field, (val)); \ 24413415e46SEric Dumazet mod##SNMP_UPD_PO_STATS((net)->mib.statname##_statistics, field, (val));\ 245edf391ffSNeil Horman }) 246edf391ffSNeil Horman 2471da177e4SLinus Torvalds /* MIBs */ 24814878f75SDavid L Stevens 249087fe240SDenis V. Lunev #define IP6_INC_STATS(net, idev,field) \ 25013415e46SEric Dumazet _DEVINC(net, ipv6, , idev, field) 2511d015503SEric Dumazet #define __IP6_INC_STATS(net, idev,field) \ 25213415e46SEric Dumazet _DEVINC(net, ipv6, __, idev, field) 253edf391ffSNeil Horman #define IP6_ADD_STATS(net, idev,field,val) \ 25413415e46SEric Dumazet _DEVADD(net, ipv6, , idev, field, val) 2551d015503SEric Dumazet #define __IP6_ADD_STATS(net, idev,field,val) \ 25613415e46SEric Dumazet _DEVADD(net, ipv6, __, idev, field, val) 257edf391ffSNeil Horman #define IP6_UPD_PO_STATS(net, idev,field,val) \ 25813415e46SEric Dumazet _DEVUPD(net, ipv6, , idev, field, val) 259c2005eb0SEric Dumazet #define __IP6_UPD_PO_STATS(net, idev,field,val) \ 26013415e46SEric Dumazet _DEVUPD(net, ipv6, __, idev, field, val) 261087fe240SDenis V. Lunev #define ICMP6_INC_STATS(net, idev, field) \ 262be281e55SEric Dumazet _DEVINCATOMIC(net, icmpv6, , idev, field) 263a16292a0SEric Dumazet #define __ICMP6_INC_STATS(net, idev, field) \ 26413415e46SEric Dumazet _DEVINCATOMIC(net, icmpv6, __, idev, field) 26514878f75SDavid L Stevens 266087fe240SDenis V. Lunev #define ICMP6MSGOUT_INC_STATS(net, idev, field) \ 2672a24444fSEric Dumazet _DEVINC_ATOMIC_ATOMIC(net, icmpv6msg, idev, field +256) 268f3832ed2SEric Dumazet #define ICMP6MSGIN_INC_STATS(net, idev, field) \ 2692a24444fSEric Dumazet _DEVINC_ATOMIC_ATOMIC(net, icmpv6msg, idev, field) 27014878f75SDavid L Stevens 271fd2c3ef7SEric Dumazet struct ip6_ra_chain { 2721da177e4SLinus Torvalds struct ip6_ra_chain *next; 2731da177e4SLinus Torvalds struct sock *sk; 2741da177e4SLinus Torvalds int sel; 2751da177e4SLinus Torvalds void (*destructor)(struct sock *); 2761da177e4SLinus Torvalds }; 2771da177e4SLinus Torvalds 2781da177e4SLinus Torvalds extern struct ip6_ra_chain *ip6_ra_chain; 2791da177e4SLinus Torvalds extern rwlock_t ip6_ra_lock; 2801da177e4SLinus Torvalds 2811da177e4SLinus Torvalds /* 2821da177e4SLinus Torvalds This structure is prepared by protocol, when parsing 2831da177e4SLinus Torvalds ancillary data and passed to IPv6. 2841da177e4SLinus Torvalds */ 2851da177e4SLinus Torvalds 286fd2c3ef7SEric Dumazet struct ipv6_txoptions { 2870aeea21aSReshetova, Elena refcount_t refcnt; 2881da177e4SLinus Torvalds /* Length of this structure */ 2891da177e4SLinus Torvalds int tot_len; 2901da177e4SLinus Torvalds 2911da177e4SLinus Torvalds /* length of extension headers */ 2921da177e4SLinus Torvalds 2931da177e4SLinus Torvalds __u16 opt_flen; /* after fragment hdr */ 2941da177e4SLinus Torvalds __u16 opt_nflen; /* before fragment hdr */ 2951da177e4SLinus Torvalds 2961da177e4SLinus Torvalds struct ipv6_opt_hdr *hopopt; 2971da177e4SLinus Torvalds struct ipv6_opt_hdr *dst0opt; 2981da177e4SLinus Torvalds struct ipv6_rt_hdr *srcrt; /* Routing Header */ 2991da177e4SLinus Torvalds struct ipv6_opt_hdr *dst1opt; 30045f6fad8SEric Dumazet struct rcu_head rcu; 3011da177e4SLinus Torvalds /* Option buffer, as read by IPV6_PKTOPTIONS, starts here. */ 3021da177e4SLinus Torvalds }; 3031da177e4SLinus Torvalds 304*a346abe0SEric Dumazet /* flowlabel_reflect sysctl values */ 305*a346abe0SEric Dumazet enum flowlabel_reflect { 306*a346abe0SEric Dumazet FLOWLABEL_REFLECT_ESTABLISHED = 1, 307*a346abe0SEric Dumazet FLOWLABEL_REFLECT_TCP_RESET = 2, 308*a346abe0SEric Dumazet FLOWLABEL_REFLECT_ICMPV6_ECHO_REPLIES = 4, 309*a346abe0SEric Dumazet }; 310*a346abe0SEric Dumazet 311fd2c3ef7SEric Dumazet struct ip6_flowlabel { 3127f0e44acSEric Dumazet struct ip6_flowlabel __rcu *next; 31390bcaf7bSAl Viro __be32 label; 314db3459d1SEric Dumazet atomic_t users; 3151da177e4SLinus Torvalds struct in6_addr dst; 3161da177e4SLinus Torvalds struct ipv6_txoptions *opt; 3171da177e4SLinus Torvalds unsigned long linger; 318d3aedd5eSYOSHIFUJI Hideaki / 吉藤英明 struct rcu_head rcu; 3191da177e4SLinus Torvalds u8 share; 3204f82f457SEric W. Biederman union { 3214f82f457SEric W. Biederman struct pid *pid; 3224f82f457SEric W. Biederman kuid_t uid; 3234f82f457SEric W. Biederman } owner; 3241da177e4SLinus Torvalds unsigned long lastuse; 3251da177e4SLinus Torvalds unsigned long expires; 32660e8fbc4SBenjamin Thery struct net *fl_net; 3271da177e4SLinus Torvalds }; 3281da177e4SLinus Torvalds 329f3a7c66bSHarvey Harrison #define IPV6_FLOWINFO_MASK cpu_to_be32(0x0FFFFFFF) 330f3a7c66bSHarvey Harrison #define IPV6_FLOWLABEL_MASK cpu_to_be32(0x000FFFFF) 33182a584b7STom Herbert #define IPV6_FLOWLABEL_STATELESS_FLAG cpu_to_be32(0x00080000) 33282a584b7STom Herbert 33337cfee90SFlorent Fourcot #define IPV6_TCLASS_MASK (IPV6_FLOWINFO_MASK & ~IPV6_FLOWLABEL_MASK) 334d76ed22bSLi RongQing #define IPV6_TCLASS_SHIFT 20 3351da177e4SLinus Torvalds 336fd2c3ef7SEric Dumazet struct ipv6_fl_socklist { 3377f0e44acSEric Dumazet struct ipv6_fl_socklist __rcu *next; 3381da177e4SLinus Torvalds struct ip6_flowlabel *fl; 33918367681SYOSHIFUJI Hideaki / 吉藤英明 struct rcu_head rcu; 3401da177e4SLinus Torvalds }; 3411da177e4SLinus Torvalds 34226879da5SWei Wang struct ipcm6_cookie { 3435fdaa88dSWillem de Bruijn struct sockcm_cookie sockc; 34426879da5SWei Wang __s16 hlimit; 34526879da5SWei Wang __s16 tclass; 34626879da5SWei Wang __s8 dontfrag; 34726879da5SWei Wang struct ipv6_txoptions *opt; 348bec1f6f6SWillem de Bruijn __u16 gso_size; 34926879da5SWei Wang }; 35026879da5SWei Wang 351b515430aSWillem de Bruijn static inline void ipcm6_init(struct ipcm6_cookie *ipc6) 352b515430aSWillem de Bruijn { 353b515430aSWillem de Bruijn *ipc6 = (struct ipcm6_cookie) { 354b515430aSWillem de Bruijn .hlimit = -1, 355b515430aSWillem de Bruijn .tclass = -1, 356b515430aSWillem de Bruijn .dontfrag = -1, 357b515430aSWillem de Bruijn }; 358b515430aSWillem de Bruijn } 359b515430aSWillem de Bruijn 360b515430aSWillem de Bruijn static inline void ipcm6_init_sk(struct ipcm6_cookie *ipc6, 361b515430aSWillem de Bruijn const struct ipv6_pinfo *np) 362b515430aSWillem de Bruijn { 363b515430aSWillem de Bruijn *ipc6 = (struct ipcm6_cookie) { 364b515430aSWillem de Bruijn .hlimit = -1, 365b515430aSWillem de Bruijn .tclass = np->tclass, 366b515430aSWillem de Bruijn .dontfrag = np->dontfrag, 367b515430aSWillem de Bruijn }; 368b515430aSWillem de Bruijn } 369b515430aSWillem de Bruijn 37045f6fad8SEric Dumazet static inline struct ipv6_txoptions *txopt_get(const struct ipv6_pinfo *np) 37145f6fad8SEric Dumazet { 37245f6fad8SEric Dumazet struct ipv6_txoptions *opt; 37345f6fad8SEric Dumazet 37445f6fad8SEric Dumazet rcu_read_lock(); 37545f6fad8SEric Dumazet opt = rcu_dereference(np->opt); 376e550785cSBenjamin Poirier if (opt) { 3770aeea21aSReshetova, Elena if (!refcount_inc_not_zero(&opt->refcnt)) 37845f6fad8SEric Dumazet opt = NULL; 379e550785cSBenjamin Poirier else 380e550785cSBenjamin Poirier opt = rcu_pointer_handoff(opt); 381e550785cSBenjamin Poirier } 38245f6fad8SEric Dumazet rcu_read_unlock(); 38345f6fad8SEric Dumazet return opt; 38445f6fad8SEric Dumazet } 38545f6fad8SEric Dumazet 38645f6fad8SEric Dumazet static inline void txopt_put(struct ipv6_txoptions *opt) 38745f6fad8SEric Dumazet { 3880aeea21aSReshetova, Elena if (opt && refcount_dec_and_test(&opt->refcnt)) 38945f6fad8SEric Dumazet kfree_rcu(opt, rcu); 39045f6fad8SEric Dumazet } 39145f6fad8SEric Dumazet 3925c3a0fd7SJoe Perches struct ip6_flowlabel *fl6_sock_lookup(struct sock *sk, __be32 label); 3935c3a0fd7SJoe Perches struct ipv6_txoptions *fl6_merge_options(struct ipv6_txoptions *opt_space, 3941da177e4SLinus Torvalds struct ip6_flowlabel *fl, 3951da177e4SLinus Torvalds struct ipv6_txoptions *fopt); 3965c3a0fd7SJoe Perches void fl6_free_socklist(struct sock *sk); 3975c3a0fd7SJoe Perches int ipv6_flowlabel_opt(struct sock *sk, char __user *optval, int optlen); 39846e5f401SFlorent Fourcot int ipv6_flowlabel_opt_get(struct sock *sk, struct in6_flowlabel_req *freq, 39946e5f401SFlorent Fourcot int flags); 4005c3a0fd7SJoe Perches int ip6_flowlabel_init(void); 4015c3a0fd7SJoe Perches void ip6_flowlabel_cleanup(void); 402e9191ffbSBen Hutchings bool ip6_autoflowlabel(struct net *net, const struct ipv6_pinfo *np); 4031da177e4SLinus Torvalds 4041da177e4SLinus Torvalds static inline void fl6_sock_release(struct ip6_flowlabel *fl) 4051da177e4SLinus Torvalds { 4061da177e4SLinus Torvalds if (fl) 4071da177e4SLinus Torvalds atomic_dec(&fl->users); 4081da177e4SLinus Torvalds } 4091da177e4SLinus Torvalds 4105c3a0fd7SJoe Perches void icmpv6_notify(struct sk_buff *skb, u8 type, u8 code, __be32 info); 411b94f1c09SDavid S. Miller 4124e64b1edSJoe Perches void icmpv6_push_pending_frames(struct sock *sk, struct flowi6 *fl6, 4136d0bfe22SLorenzo Colitti struct icmp6hdr *thdr, int len); 4146d0bfe22SLorenzo Colitti 4155c3a0fd7SJoe Perches int ip6_ra_control(struct sock *sk, int sel); 4161da177e4SLinus Torvalds 4175c3a0fd7SJoe Perches int ipv6_parse_hopopts(struct sk_buff *skb); 4181da177e4SLinus Torvalds 4195c3a0fd7SJoe Perches struct ipv6_txoptions *ipv6_dup_options(struct sock *sk, 4205c3a0fd7SJoe Perches struct ipv6_txoptions *opt); 4215c3a0fd7SJoe Perches struct ipv6_txoptions *ipv6_renew_options(struct sock *sk, 4225c3a0fd7SJoe Perches struct ipv6_txoptions *opt, 423333fad53SYOSHIFUJI Hideaki int newtype, 424a9ba23d4SPaul Moore struct ipv6_opt_hdr *newopt); 425df9890c3SYOSHIFUJI Hideaki struct ipv6_txoptions *ipv6_fixup_options(struct ipv6_txoptions *opt_space, 426df9890c3SYOSHIFUJI Hideaki struct ipv6_txoptions *opt); 4271da177e4SLinus Torvalds 428a224772dSEric Dumazet bool ipv6_opt_accepted(const struct sock *sk, const struct sk_buff *skb, 429a224772dSEric Dumazet const struct inet6_skb_parm *opt); 430ceba1832SHuw Davies struct ipv6_txoptions *ipv6_update_options(struct sock *sk, 431ceba1832SHuw Davies struct ipv6_txoptions *opt); 432399c07deSArnaldo Carvalho de Melo 433aeaf6e9dSShmulik Ladkani static inline bool ipv6_accept_ra(struct inet6_dev *idev) 434aeaf6e9dSShmulik Ladkani { 435aeaf6e9dSShmulik Ladkani /* If forwarding is enabled, RA are not accepted unless the special 436aeaf6e9dSShmulik Ladkani * hybrid mode (accept_ra=2) is enabled. 437aeaf6e9dSShmulik Ladkani */ 438aeaf6e9dSShmulik Ladkani return idev->cnf.forwarding ? idev->cnf.accept_ra == 2 : 439aeaf6e9dSShmulik Ladkani idev->cnf.accept_ra; 440aeaf6e9dSShmulik Ladkani } 441aeaf6e9dSShmulik Ladkani 442c2a93660SJesper Dangaard Brouer #define IPV6_FRAG_HIGH_THRESH (4 * 1024*1024) /* 4194304 */ 443c2a93660SJesper Dangaard Brouer #define IPV6_FRAG_LOW_THRESH (3 * 1024*1024) /* 3145728 */ 4441da177e4SLinus Torvalds #define IPV6_FRAG_TIMEOUT (60 * HZ) /* 60 seconds */ 4451da177e4SLinus Torvalds 4465c3a0fd7SJoe Perches int __ipv6_addr_type(const struct in6_addr *addr); 447b1cacb68SYOSHIFUJI Hideaki static inline int ipv6_addr_type(const struct in6_addr *addr) 448b1cacb68SYOSHIFUJI Hideaki { 449b1cacb68SYOSHIFUJI Hideaki return __ipv6_addr_type(addr) & 0xffff; 450b1cacb68SYOSHIFUJI Hideaki } 4511da177e4SLinus Torvalds 4521da177e4SLinus Torvalds static inline int ipv6_addr_scope(const struct in6_addr *addr) 4531da177e4SLinus Torvalds { 454b1cacb68SYOSHIFUJI Hideaki return __ipv6_addr_type(addr) & IPV6_ADDR_SCOPE_MASK; 455b1cacb68SYOSHIFUJI Hideaki } 456b1cacb68SYOSHIFUJI Hideaki 457b1cacb68SYOSHIFUJI Hideaki static inline int __ipv6_addr_src_scope(int type) 458b1cacb68SYOSHIFUJI Hideaki { 459a02cec21SEric Dumazet return (type == IPV6_ADDR_ANY) ? __IPV6_ADDR_SCOPE_INVALID : (type >> 16); 460b1cacb68SYOSHIFUJI Hideaki } 461b1cacb68SYOSHIFUJI Hideaki 462b1cacb68SYOSHIFUJI Hideaki static inline int ipv6_addr_src_scope(const struct in6_addr *addr) 463b1cacb68SYOSHIFUJI Hideaki { 464b1cacb68SYOSHIFUJI Hideaki return __ipv6_addr_src_scope(__ipv6_addr_type(addr)); 4651da177e4SLinus Torvalds } 4661da177e4SLinus Torvalds 467b7ef213eSHannes Frederic Sowa static inline bool __ipv6_addr_needs_scope_id(int type) 468b7ef213eSHannes Frederic Sowa { 469b7ef213eSHannes Frederic Sowa return type & IPV6_ADDR_LINKLOCAL || 470b7ef213eSHannes Frederic Sowa (type & IPV6_ADDR_MULTICAST && 471b7ef213eSHannes Frederic Sowa (type & (IPV6_ADDR_LOOPBACK|IPV6_ADDR_LINKLOCAL))); 472b7ef213eSHannes Frederic Sowa } 473b7ef213eSHannes Frederic Sowa 474b7ef213eSHannes Frederic Sowa static inline __u32 ipv6_iface_scope_id(const struct in6_addr *addr, int iface) 475b7ef213eSHannes Frederic Sowa { 476b7ef213eSHannes Frederic Sowa return __ipv6_addr_needs_scope_id(__ipv6_addr_type(addr)) ? iface : 0; 477b7ef213eSHannes Frederic Sowa } 478b7ef213eSHannes Frederic Sowa 4791da177e4SLinus Torvalds static inline int ipv6_addr_cmp(const struct in6_addr *a1, const struct in6_addr *a2) 4801da177e4SLinus Torvalds { 481db3459d1SEric Dumazet return memcmp(a1, a2, sizeof(struct in6_addr)); 4821da177e4SLinus Torvalds } 4831da177e4SLinus Torvalds 4841a203cb3SEric Dumazet static inline bool 485f2ffd9eeSPatrick McHardy ipv6_masked_addr_cmp(const struct in6_addr *a1, const struct in6_addr *m, 486f2ffd9eeSPatrick McHardy const struct in6_addr *a2) 487f2ffd9eeSPatrick McHardy { 4881a203cb3SEric Dumazet #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 4891a203cb3SEric Dumazet const unsigned long *ul1 = (const unsigned long *)a1; 4901a203cb3SEric Dumazet const unsigned long *ulm = (const unsigned long *)m; 4911a203cb3SEric Dumazet const unsigned long *ul2 = (const unsigned long *)a2; 4921a203cb3SEric Dumazet 4931a203cb3SEric Dumazet return !!(((ul1[0] ^ ul2[0]) & ulm[0]) | 4941a203cb3SEric Dumazet ((ul1[1] ^ ul2[1]) & ulm[1])); 4951a203cb3SEric Dumazet #else 496a02cec21SEric Dumazet return !!(((a1->s6_addr32[0] ^ a2->s6_addr32[0]) & m->s6_addr32[0]) | 497fed85383SYOSHIFUJI Hideaki ((a1->s6_addr32[1] ^ a2->s6_addr32[1]) & m->s6_addr32[1]) | 498fed85383SYOSHIFUJI Hideaki ((a1->s6_addr32[2] ^ a2->s6_addr32[2]) & m->s6_addr32[2]) | 499a02cec21SEric Dumazet ((a1->s6_addr32[3] ^ a2->s6_addr32[3]) & m->s6_addr32[3])); 5001a203cb3SEric Dumazet #endif 501f2ffd9eeSPatrick McHardy } 502f2ffd9eeSPatrick McHardy 5031da177e4SLinus Torvalds static inline void ipv6_addr_prefix(struct in6_addr *pfx, 5041da177e4SLinus Torvalds const struct in6_addr *addr, 5051da177e4SLinus Torvalds int plen) 5061da177e4SLinus Torvalds { 5071da177e4SLinus Torvalds /* caller must guarantee 0 <= plen <= 128 */ 5081da177e4SLinus Torvalds int o = plen >> 3, 5091da177e4SLinus Torvalds b = plen & 0x7; 5101da177e4SLinus Torvalds 511db3459d1SEric Dumazet memset(pfx->s6_addr, 0, sizeof(pfx->s6_addr)); 5121da177e4SLinus Torvalds memcpy(pfx->s6_addr, addr, o); 513db3459d1SEric Dumazet if (b != 0) 5141da177e4SLinus Torvalds pfx->s6_addr[o] = addr->s6_addr[o] & (0xff00 >> b); 5151da177e4SLinus Torvalds } 5161da177e4SLinus Torvalds 517818f1f3eSAlexander Aring static inline void ipv6_addr_prefix_copy(struct in6_addr *addr, 518818f1f3eSAlexander Aring const struct in6_addr *pfx, 519818f1f3eSAlexander Aring int plen) 520818f1f3eSAlexander Aring { 521818f1f3eSAlexander Aring /* caller must guarantee 0 <= plen <= 128 */ 522818f1f3eSAlexander Aring int o = plen >> 3, 523818f1f3eSAlexander Aring b = plen & 0x7; 524818f1f3eSAlexander Aring 525818f1f3eSAlexander Aring memcpy(addr->s6_addr, pfx, o); 526818f1f3eSAlexander Aring if (b != 0) { 527818f1f3eSAlexander Aring addr->s6_addr[o] &= ~(0xff00 >> b); 528818f1f3eSAlexander Aring addr->s6_addr[o] |= (pfx->s6_addr[o] & (0xff00 >> b)); 529818f1f3eSAlexander Aring } 530818f1f3eSAlexander Aring } 531818f1f3eSAlexander Aring 5325206c579SYOSHIFUJI Hideaki / 吉藤英明 static inline void __ipv6_addr_set_half(__be32 *addr, 5335206c579SYOSHIFUJI Hideaki / 吉藤英明 __be32 wh, __be32 wl) 5345206c579SYOSHIFUJI Hideaki / 吉藤英明 { 5355206c579SYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 5365206c579SYOSHIFUJI Hideaki / 吉藤英明 #if defined(__BIG_ENDIAN) 5375206c579SYOSHIFUJI Hideaki / 吉藤英明 if (__builtin_constant_p(wh) && __builtin_constant_p(wl)) { 5385206c579SYOSHIFUJI Hideaki / 吉藤英明 *(__force u64 *)addr = ((__force u64)(wh) << 32 | (__force u64)(wl)); 5395206c579SYOSHIFUJI Hideaki / 吉藤英明 return; 5405206c579SYOSHIFUJI Hideaki / 吉藤英明 } 5415206c579SYOSHIFUJI Hideaki / 吉藤英明 #elif defined(__LITTLE_ENDIAN) 5425206c579SYOSHIFUJI Hideaki / 吉藤英明 if (__builtin_constant_p(wl) && __builtin_constant_p(wh)) { 5435206c579SYOSHIFUJI Hideaki / 吉藤英明 *(__force u64 *)addr = ((__force u64)(wl) << 32 | (__force u64)(wh)); 5445206c579SYOSHIFUJI Hideaki / 吉藤英明 return; 5455206c579SYOSHIFUJI Hideaki / 吉藤英明 } 5465206c579SYOSHIFUJI Hideaki / 吉藤英明 #endif 5475206c579SYOSHIFUJI Hideaki / 吉藤英明 #endif 5485206c579SYOSHIFUJI Hideaki / 吉藤英明 addr[0] = wh; 5495206c579SYOSHIFUJI Hideaki / 吉藤英明 addr[1] = wl; 5505206c579SYOSHIFUJI Hideaki / 吉藤英明 } 5515206c579SYOSHIFUJI Hideaki / 吉藤英明 5521da177e4SLinus Torvalds static inline void ipv6_addr_set(struct in6_addr *addr, 55348818f82SAl Viro __be32 w1, __be32 w2, 55448818f82SAl Viro __be32 w3, __be32 w4) 5551da177e4SLinus Torvalds { 5565206c579SYOSHIFUJI Hideaki / 吉藤英明 __ipv6_addr_set_half(&addr->s6_addr32[0], w1, w2); 5575206c579SYOSHIFUJI Hideaki / 吉藤英明 __ipv6_addr_set_half(&addr->s6_addr32[2], w3, w4); 5581da177e4SLinus Torvalds } 5591da177e4SLinus Torvalds 56092113bfdSEric Dumazet static inline bool ipv6_addr_equal(const struct in6_addr *a1, 5611da177e4SLinus Torvalds const struct in6_addr *a2) 5621da177e4SLinus Torvalds { 5631a203cb3SEric Dumazet #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 5641a203cb3SEric Dumazet const unsigned long *ul1 = (const unsigned long *)a1; 5651a203cb3SEric Dumazet const unsigned long *ul2 = (const unsigned long *)a2; 5661a203cb3SEric Dumazet 5671a203cb3SEric Dumazet return ((ul1[0] ^ ul2[0]) | (ul1[1] ^ ul2[1])) == 0UL; 5681a203cb3SEric Dumazet #else 569a02cec21SEric Dumazet return ((a1->s6_addr32[0] ^ a2->s6_addr32[0]) | 570fed85383SYOSHIFUJI Hideaki (a1->s6_addr32[1] ^ a2->s6_addr32[1]) | 571fed85383SYOSHIFUJI Hideaki (a1->s6_addr32[2] ^ a2->s6_addr32[2]) | 572a02cec21SEric Dumazet (a1->s6_addr32[3] ^ a2->s6_addr32[3])) == 0; 5731a203cb3SEric Dumazet #endif 5741da177e4SLinus Torvalds } 5751da177e4SLinus Torvalds 57638675170SYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 57738675170SYOSHIFUJI Hideaki / 吉藤英明 static inline bool __ipv6_prefix_equal64_half(const __be64 *a1, 57838675170SYOSHIFUJI Hideaki / 吉藤英明 const __be64 *a2, 57938675170SYOSHIFUJI Hideaki / 吉藤英明 unsigned int len) 58038675170SYOSHIFUJI Hideaki / 吉藤英明 { 581512613d7SFabio Baltieri if (len && ((*a1 ^ *a2) & cpu_to_be64((~0UL) << (64 - len)))) 58238675170SYOSHIFUJI Hideaki / 吉藤英明 return false; 58338675170SYOSHIFUJI Hideaki / 吉藤英明 return true; 58438675170SYOSHIFUJI Hideaki / 吉藤英明 } 58538675170SYOSHIFUJI Hideaki / 吉藤英明 58638675170SYOSHIFUJI Hideaki / 吉藤英明 static inline bool ipv6_prefix_equal(const struct in6_addr *addr1, 58738675170SYOSHIFUJI Hideaki / 吉藤英明 const struct in6_addr *addr2, 58838675170SYOSHIFUJI Hideaki / 吉藤英明 unsigned int prefixlen) 58938675170SYOSHIFUJI Hideaki / 吉藤英明 { 59038675170SYOSHIFUJI Hideaki / 吉藤英明 const __be64 *a1 = (const __be64 *)addr1; 59138675170SYOSHIFUJI Hideaki / 吉藤英明 const __be64 *a2 = (const __be64 *)addr2; 59238675170SYOSHIFUJI Hideaki / 吉藤英明 59338675170SYOSHIFUJI Hideaki / 吉藤英明 if (prefixlen >= 64) { 59438675170SYOSHIFUJI Hideaki / 吉藤英明 if (a1[0] ^ a2[0]) 59538675170SYOSHIFUJI Hideaki / 吉藤英明 return false; 59638675170SYOSHIFUJI Hideaki / 吉藤英明 return __ipv6_prefix_equal64_half(a1 + 1, a2 + 1, prefixlen - 64); 59738675170SYOSHIFUJI Hideaki / 吉藤英明 } 59838675170SYOSHIFUJI Hideaki / 吉藤英明 return __ipv6_prefix_equal64_half(a1, a2, prefixlen); 59938675170SYOSHIFUJI Hideaki / 吉藤英明 } 60038675170SYOSHIFUJI Hideaki / 吉藤英明 #else 6012ef97332SYOSHIFUJI Hideaki / 吉藤英明 static inline bool ipv6_prefix_equal(const struct in6_addr *addr1, 6022ef97332SYOSHIFUJI Hideaki / 吉藤英明 const struct in6_addr *addr2, 6031da177e4SLinus Torvalds unsigned int prefixlen) 6041da177e4SLinus Torvalds { 6052ef97332SYOSHIFUJI Hideaki / 吉藤英明 const __be32 *a1 = addr1->s6_addr32; 6062ef97332SYOSHIFUJI Hideaki / 吉藤英明 const __be32 *a2 = addr2->s6_addr32; 60795c96174SEric Dumazet unsigned int pdw, pbi; 6081da177e4SLinus Torvalds 6091da177e4SLinus Torvalds /* check complete u32 in prefix */ 6101da177e4SLinus Torvalds pdw = prefixlen >> 5; 6111da177e4SLinus Torvalds if (pdw && memcmp(a1, a2, pdw << 2)) 61292113bfdSEric Dumazet return false; 6131da177e4SLinus Torvalds 6141da177e4SLinus Torvalds /* check incomplete u32 in prefix */ 6151da177e4SLinus Torvalds pbi = prefixlen & 0x1f; 6161da177e4SLinus Torvalds if (pbi && ((a1[pdw] ^ a2[pdw]) & htonl((0xffffffff) << (32 - pbi)))) 61792113bfdSEric Dumazet return false; 6181da177e4SLinus Torvalds 61992113bfdSEric Dumazet return true; 6201da177e4SLinus Torvalds } 62138675170SYOSHIFUJI Hideaki / 吉藤英明 #endif 6221da177e4SLinus Torvalds 62392113bfdSEric Dumazet static inline bool ipv6_addr_any(const struct in6_addr *a) 6241da177e4SLinus Torvalds { 6251a203cb3SEric Dumazet #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 6261a203cb3SEric Dumazet const unsigned long *ul = (const unsigned long *)a; 6271a203cb3SEric Dumazet 6281a203cb3SEric Dumazet return (ul[0] | ul[1]) == 0UL; 6291a203cb3SEric Dumazet #else 630a02cec21SEric Dumazet return (a->s6_addr32[0] | a->s6_addr32[1] | 631a02cec21SEric Dumazet a->s6_addr32[2] | a->s6_addr32[3]) == 0; 6321a203cb3SEric Dumazet #endif 6331da177e4SLinus Torvalds } 6341da177e4SLinus Torvalds 635ddbe5032SEric Dumazet static inline u32 ipv6_addr_hash(const struct in6_addr *a) 636ddbe5032SEric Dumazet { 637ddbe5032SEric Dumazet #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 638ddbe5032SEric Dumazet const unsigned long *ul = (const unsigned long *)a; 639ddbe5032SEric Dumazet unsigned long x = ul[0] ^ ul[1]; 640ddbe5032SEric Dumazet 641ddbe5032SEric Dumazet return (u32)(x ^ (x >> 32)); 642ddbe5032SEric Dumazet #else 643ddbe5032SEric Dumazet return (__force u32)(a->s6_addr32[0] ^ a->s6_addr32[1] ^ 644ddbe5032SEric Dumazet a->s6_addr32[2] ^ a->s6_addr32[3]); 645ddbe5032SEric Dumazet #endif 646ddbe5032SEric Dumazet } 647ddbe5032SEric Dumazet 64808dcdbf6SEric Dumazet /* more secured version of ipv6_addr_hash() */ 649b50026b5SHannes Frederic Sowa static inline u32 __ipv6_addr_jhash(const struct in6_addr *a, const u32 initval) 65008dcdbf6SEric Dumazet { 65108dcdbf6SEric Dumazet u32 v = (__force u32)a->s6_addr32[0] ^ (__force u32)a->s6_addr32[1]; 65208dcdbf6SEric Dumazet 65308dcdbf6SEric Dumazet return jhash_3words(v, 65408dcdbf6SEric Dumazet (__force u32)a->s6_addr32[2], 65508dcdbf6SEric Dumazet (__force u32)a->s6_addr32[3], 656b50026b5SHannes Frederic Sowa initval); 65708dcdbf6SEric Dumazet } 65808dcdbf6SEric Dumazet 65992113bfdSEric Dumazet static inline bool ipv6_addr_loopback(const struct in6_addr *a) 660f630e43aSYOSHIFUJI Hideaki { 661e287656bSYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 6621373a773SJeff Layton const __be64 *be = (const __be64 *)a; 663e287656bSYOSHIFUJI Hideaki / 吉藤英明 6641373a773SJeff Layton return (be[0] | (be[1] ^ cpu_to_be64(1))) == 0UL; 665e287656bSYOSHIFUJI Hideaki / 吉藤英明 #else 666a02cec21SEric Dumazet return (a->s6_addr32[0] | a->s6_addr32[1] | 6671373a773SJeff Layton a->s6_addr32[2] | (a->s6_addr32[3] ^ cpu_to_be32(1))) == 0; 668e287656bSYOSHIFUJI Hideaki / 吉藤英明 #endif 669f630e43aSYOSHIFUJI Hideaki } 670f630e43aSYOSHIFUJI Hideaki 6711373a773SJeff Layton /* 6721373a773SJeff Layton * Note that we must __force cast these to unsigned long to make sparse happy, 6731373a773SJeff Layton * since all of the endian-annotated types are fixed size regardless of arch. 6741373a773SJeff Layton */ 67592113bfdSEric Dumazet static inline bool ipv6_addr_v4mapped(const struct in6_addr *a) 676e773e4faSBrian Haley { 677a04d40b8SYOSHIFUJI Hideaki / 吉藤英明 return ( 678a04d40b8SYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 6791373a773SJeff Layton *(unsigned long *)a | 680a04d40b8SYOSHIFUJI Hideaki / 吉藤英明 #else 6811373a773SJeff Layton (__force unsigned long)(a->s6_addr32[0] | a->s6_addr32[1]) | 682a04d40b8SYOSHIFUJI Hideaki / 吉藤英明 #endif 6831373a773SJeff Layton (__force unsigned long)(a->s6_addr32[2] ^ 6841373a773SJeff Layton cpu_to_be32(0x0000ffff))) == 0UL; 685e773e4faSBrian Haley } 686e773e4faSBrian Haley 687f0b1e64cSMartin KaFai Lau static inline u32 ipv6_portaddr_hash(const struct net *net, 688f0b1e64cSMartin KaFai Lau const struct in6_addr *addr6, 689f0b1e64cSMartin KaFai Lau unsigned int port) 690f0b1e64cSMartin KaFai Lau { 691f0b1e64cSMartin KaFai Lau unsigned int hash, mix = net_hash_mix(net); 692f0b1e64cSMartin KaFai Lau 693f0b1e64cSMartin KaFai Lau if (ipv6_addr_any(addr6)) 694f0b1e64cSMartin KaFai Lau hash = jhash_1word(0, mix); 695f0b1e64cSMartin KaFai Lau else if (ipv6_addr_v4mapped(addr6)) 696f0b1e64cSMartin KaFai Lau hash = jhash_1word((__force u32)addr6->s6_addr32[3], mix); 697f0b1e64cSMartin KaFai Lau else 698f0b1e64cSMartin KaFai Lau hash = jhash2((__force u32 *)addr6->s6_addr32, 4, mix); 699f0b1e64cSMartin KaFai Lau 700f0b1e64cSMartin KaFai Lau return hash ^ port; 701f0b1e64cSMartin KaFai Lau } 702f0b1e64cSMartin KaFai Lau 7031da177e4SLinus Torvalds /* 70499cd07a5SJuha-Matti Tapio * Check for a RFC 4843 ORCHID address 70599cd07a5SJuha-Matti Tapio * (Overlay Routable Cryptographic Hash Identifiers) 70699cd07a5SJuha-Matti Tapio */ 70792113bfdSEric Dumazet static inline bool ipv6_addr_orchid(const struct in6_addr *a) 70899cd07a5SJuha-Matti Tapio { 709a02cec21SEric Dumazet return (a->s6_addr32[0] & htonl(0xfffffff0)) == htonl(0x20010010); 71099cd07a5SJuha-Matti Tapio } 71199cd07a5SJuha-Matti Tapio 7125c98631cSLorenzo Colitti static inline bool ipv6_addr_is_multicast(const struct in6_addr *addr) 7135c98631cSLorenzo Colitti { 7145c98631cSLorenzo Colitti return (addr->s6_addr32[0] & htonl(0xFF000000)) == htonl(0xFF000000); 7155c98631cSLorenzo Colitti } 7165c98631cSLorenzo Colitti 717f15364bdSAurélien Charbon static inline void ipv6_addr_set_v4mapped(const __be32 addr, 718f15364bdSAurélien Charbon struct in6_addr *v4mapped) 719f15364bdSAurélien Charbon { 720f15364bdSAurélien Charbon ipv6_addr_set(v4mapped, 721f15364bdSAurélien Charbon 0, 0, 722f15364bdSAurélien Charbon htonl(0x0000FFFF), 723f15364bdSAurélien Charbon addr); 724f15364bdSAurélien Charbon } 725f15364bdSAurélien Charbon 72699cd07a5SJuha-Matti Tapio /* 727971f359dSYOSHIFUJI Hideaki * find the first different bit between two addresses 728971f359dSYOSHIFUJI Hideaki * length of address must be a multiple of 32bits 729971f359dSYOSHIFUJI Hideaki */ 7309f2e7334SYOSHIFUJI Hideaki / 吉藤英明 static inline int __ipv6_addr_diff32(const void *token1, const void *token2, int addrlen) 731971f359dSYOSHIFUJI Hideaki { 732ef296f56SAl Viro const __be32 *a1 = token1, *a2 = token2; 733971f359dSYOSHIFUJI Hideaki int i; 734971f359dSYOSHIFUJI Hideaki 735971f359dSYOSHIFUJI Hideaki addrlen >>= 2; 736971f359dSYOSHIFUJI Hideaki 737971f359dSYOSHIFUJI Hideaki for (i = 0; i < addrlen; i++) { 738ef296f56SAl Viro __be32 xb = a1[i] ^ a2[i]; 739ef296f56SAl Viro if (xb) 740d57b8fb8SYOSHIFUJI Hideaki / 吉藤英明 return i * 32 + 31 - __fls(ntohl(xb)); 741971f359dSYOSHIFUJI Hideaki } 742971f359dSYOSHIFUJI Hideaki 743971f359dSYOSHIFUJI Hideaki /* 744971f359dSYOSHIFUJI Hideaki * we should *never* get to this point since that 745971f359dSYOSHIFUJI Hideaki * would mean the addrs are equal 746971f359dSYOSHIFUJI Hideaki * 747971f359dSYOSHIFUJI Hideaki * However, we do get to it 8) And exacly, when 748971f359dSYOSHIFUJI Hideaki * addresses are equal 8) 749971f359dSYOSHIFUJI Hideaki * 750971f359dSYOSHIFUJI Hideaki * ip route add 1111::/128 via ... 751971f359dSYOSHIFUJI Hideaki * ip route add 1111::/64 via ... 752971f359dSYOSHIFUJI Hideaki * and we are here. 753971f359dSYOSHIFUJI Hideaki * 754971f359dSYOSHIFUJI Hideaki * Ideally, this function should stop comparison 755971f359dSYOSHIFUJI Hideaki * at prefix length. It does not, but it is still OK, 756971f359dSYOSHIFUJI Hideaki * if returned value is greater than prefix length. 757971f359dSYOSHIFUJI Hideaki * --ANK (980803) 758971f359dSYOSHIFUJI Hideaki */ 759a02cec21SEric Dumazet return addrlen << 5; 760971f359dSYOSHIFUJI Hideaki } 761971f359dSYOSHIFUJI Hideaki 7629f2e7334SYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 7639f2e7334SYOSHIFUJI Hideaki / 吉藤英明 static inline int __ipv6_addr_diff64(const void *token1, const void *token2, int addrlen) 7649f2e7334SYOSHIFUJI Hideaki / 吉藤英明 { 7659f2e7334SYOSHIFUJI Hideaki / 吉藤英明 const __be64 *a1 = token1, *a2 = token2; 7669f2e7334SYOSHIFUJI Hideaki / 吉藤英明 int i; 7679f2e7334SYOSHIFUJI Hideaki / 吉藤英明 7689f2e7334SYOSHIFUJI Hideaki / 吉藤英明 addrlen >>= 3; 7699f2e7334SYOSHIFUJI Hideaki / 吉藤英明 7709f2e7334SYOSHIFUJI Hideaki / 吉藤英明 for (i = 0; i < addrlen; i++) { 7719f2e7334SYOSHIFUJI Hideaki / 吉藤英明 __be64 xb = a1[i] ^ a2[i]; 7729f2e7334SYOSHIFUJI Hideaki / 吉藤英明 if (xb) 7739f2e7334SYOSHIFUJI Hideaki / 吉藤英明 return i * 64 + 63 - __fls(be64_to_cpu(xb)); 7749f2e7334SYOSHIFUJI Hideaki / 吉藤英明 } 7759f2e7334SYOSHIFUJI Hideaki / 吉藤英明 7769f2e7334SYOSHIFUJI Hideaki / 吉藤英明 return addrlen << 6; 7779f2e7334SYOSHIFUJI Hideaki / 吉藤英明 } 7789f2e7334SYOSHIFUJI Hideaki / 吉藤英明 #endif 7799f2e7334SYOSHIFUJI Hideaki / 吉藤英明 7809f2e7334SYOSHIFUJI Hideaki / 吉藤英明 static inline int __ipv6_addr_diff(const void *token1, const void *token2, int addrlen) 7819f2e7334SYOSHIFUJI Hideaki / 吉藤英明 { 7829f2e7334SYOSHIFUJI Hideaki / 吉藤英明 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 7839f2e7334SYOSHIFUJI Hideaki / 吉藤英明 if (__builtin_constant_p(addrlen) && !(addrlen & 7)) 7849f2e7334SYOSHIFUJI Hideaki / 吉藤英明 return __ipv6_addr_diff64(token1, token2, addrlen); 7859f2e7334SYOSHIFUJI Hideaki / 吉藤英明 #endif 7869f2e7334SYOSHIFUJI Hideaki / 吉藤英明 return __ipv6_addr_diff32(token1, token2, addrlen); 7879f2e7334SYOSHIFUJI Hideaki / 吉藤英明 } 7889f2e7334SYOSHIFUJI Hideaki / 吉藤英明 789971f359dSYOSHIFUJI Hideaki static inline int ipv6_addr_diff(const struct in6_addr *a1, const struct in6_addr *a2) 790971f359dSYOSHIFUJI Hideaki { 791971f359dSYOSHIFUJI Hideaki return __ipv6_addr_diff(a1, a2, sizeof(struct in6_addr)); 792971f359dSYOSHIFUJI Hideaki } 793971f359dSYOSHIFUJI Hideaki 7947f159867SEric Dumazet __be32 ipv6_select_ident(struct net *net, 795fd0273d7SMartin KaFai Lau const struct in6_addr *daddr, 796fd0273d7SMartin KaFai Lau const struct in6_addr *saddr); 7970c19f846SWillem de Bruijn __be32 ipv6_proxy_select_ident(struct net *net, struct sk_buff *skb); 7985188cd44SBen Hutchings 7995c3a0fd7SJoe Perches int ip6_dst_hoplimit(struct dst_entry *dst); 8003ce9b35fSCong Wang 8015c98631cSLorenzo Colitti static inline int ip6_sk_dst_hoplimit(struct ipv6_pinfo *np, struct flowi6 *fl6, 8025c98631cSLorenzo Colitti struct dst_entry *dst) 8035c98631cSLorenzo Colitti { 8045c98631cSLorenzo Colitti int hlimit; 8055c98631cSLorenzo Colitti 8065c98631cSLorenzo Colitti if (ipv6_addr_is_multicast(&fl6->daddr)) 8075c98631cSLorenzo Colitti hlimit = np->mcast_hops; 8085c98631cSLorenzo Colitti else 8095c98631cSLorenzo Colitti hlimit = np->hop_limit; 8105c98631cSLorenzo Colitti if (hlimit < 0) 8115c98631cSLorenzo Colitti hlimit = ip6_dst_hoplimit(dst); 8125c98631cSLorenzo Colitti return hlimit; 8135c98631cSLorenzo Colitti } 8145c98631cSLorenzo Colitti 815c3f83241STom Herbert /* copy IPv6 saddr & daddr to flow_keys, possibly using 64bit load/store 816c3f83241STom Herbert * Equivalent to : flow->v6addrs.src = iph->saddr; 817c3f83241STom Herbert * flow->v6addrs.dst = iph->daddr; 818c3f83241STom Herbert */ 819c3f83241STom Herbert static inline void iph_to_flow_copy_v6addrs(struct flow_keys *flow, 820c3f83241STom Herbert const struct ipv6hdr *iph) 821c3f83241STom Herbert { 822c3f83241STom Herbert BUILD_BUG_ON(offsetof(typeof(flow->addrs), v6addrs.dst) != 823c3f83241STom Herbert offsetof(typeof(flow->addrs), v6addrs.src) + 824c3f83241STom Herbert sizeof(flow->addrs.v6addrs.src)); 825c3f83241STom Herbert memcpy(&flow->addrs.v6addrs, &iph->saddr, sizeof(flow->addrs.v6addrs)); 826c3f83241STom Herbert flow->control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS; 827c3f83241STom Herbert } 828c3f83241STom Herbert 829a37934fcSFlorian Fainelli #if IS_ENABLED(CONFIG_IPV6) 83042240901STom Herbert 831db57dc7cSVincent Bernat static inline bool ipv6_can_nonlocal_bind(struct net *net, 832db57dc7cSVincent Bernat struct inet_sock *inet) 833db57dc7cSVincent Bernat { 834db57dc7cSVincent Bernat return net->ipv6.sysctl.ip_nonlocal_bind || 835db57dc7cSVincent Bernat inet->freebind || inet->transparent; 836db57dc7cSVincent Bernat } 837db57dc7cSVincent Bernat 83842240901STom Herbert /* Sysctl settings for net ipv6.auto_flowlabels */ 83942240901STom Herbert #define IP6_AUTO_FLOW_LABEL_OFF 0 84042240901STom Herbert #define IP6_AUTO_FLOW_LABEL_OPTOUT 1 84142240901STom Herbert #define IP6_AUTO_FLOW_LABEL_OPTIN 2 84242240901STom Herbert #define IP6_AUTO_FLOW_LABEL_FORCED 3 84342240901STom Herbert 84442240901STom Herbert #define IP6_AUTO_FLOW_LABEL_MAX IP6_AUTO_FLOW_LABEL_FORCED 84542240901STom Herbert 846b5677416STom Herbert #define IP6_DEFAULT_AUTO_FLOW_LABELS IP6_AUTO_FLOW_LABEL_OPTOUT 84742240901STom Herbert 848cb1ce2efSTom Herbert static inline __be32 ip6_make_flowlabel(struct net *net, struct sk_buff *skb, 84967800f9bSTom Herbert __be32 flowlabel, bool autolabel, 85067800f9bSTom Herbert struct flowi6 *fl6) 851cb1ce2efSTom Herbert { 85267765146SEric Dumazet u32 hash; 853cb1ce2efSTom Herbert 85490427ef5SDimitris Michailidis /* @flowlabel may include more than a flow label, eg, the traffic class. 85590427ef5SDimitris Michailidis * Here we want only the flow label value. 85690427ef5SDimitris Michailidis */ 85790427ef5SDimitris Michailidis flowlabel &= IPV6_FLOWLABEL_MASK; 85890427ef5SDimitris Michailidis 85942240901STom Herbert if (flowlabel || 86042240901STom Herbert net->ipv6.sysctl.auto_flowlabels == IP6_AUTO_FLOW_LABEL_OFF || 86142240901STom Herbert (!autolabel && 86242240901STom Herbert net->ipv6.sysctl.auto_flowlabels != IP6_AUTO_FLOW_LABEL_FORCED)) 86342240901STom Herbert return flowlabel; 86442240901STom Herbert 86567800f9bSTom Herbert hash = skb_get_hash_flowi6(skb, fl6); 866cb1ce2efSTom Herbert 867cb1ce2efSTom Herbert /* Since this is being sent on the wire obfuscate hash a bit 868cb1ce2efSTom Herbert * to minimize possbility that any useful information to an 869cb1ce2efSTom Herbert * attacker is leaked. Only lower 20 bits are relevant. 870cb1ce2efSTom Herbert */ 871169dc027SColin Ian King hash = rol32(hash, 16); 872cb1ce2efSTom Herbert 87367765146SEric Dumazet flowlabel = (__force __be32)hash & IPV6_FLOWLABEL_MASK; 87482a584b7STom Herbert 87582a584b7STom Herbert if (net->ipv6.sysctl.flowlabel_state_ranges) 87682a584b7STom Herbert flowlabel |= IPV6_FLOWLABEL_STATELESS_FLAG; 877cb1ce2efSTom Herbert 878cb1ce2efSTom Herbert return flowlabel; 879cb1ce2efSTom Herbert } 88042240901STom Herbert 88142240901STom Herbert static inline int ip6_default_np_autolabel(struct net *net) 88242240901STom Herbert { 88342240901STom Herbert switch (net->ipv6.sysctl.auto_flowlabels) { 88442240901STom Herbert case IP6_AUTO_FLOW_LABEL_OFF: 88542240901STom Herbert case IP6_AUTO_FLOW_LABEL_OPTIN: 88642240901STom Herbert default: 88742240901STom Herbert return 0; 88842240901STom Herbert case IP6_AUTO_FLOW_LABEL_OPTOUT: 88942240901STom Herbert case IP6_AUTO_FLOW_LABEL_FORCED: 89042240901STom Herbert return 1; 89142240901STom Herbert } 89242240901STom Herbert } 893a37934fcSFlorian Fainelli #else 894a37934fcSFlorian Fainelli static inline void ip6_set_txhash(struct sock *sk) { } 895a37934fcSFlorian Fainelli static inline __be32 ip6_make_flowlabel(struct net *net, struct sk_buff *skb, 89642240901STom Herbert __be32 flowlabel, bool autolabel, 89742240901STom Herbert struct flowi6 *fl6) 898a37934fcSFlorian Fainelli { 899a37934fcSFlorian Fainelli return flowlabel; 900a37934fcSFlorian Fainelli } 90142240901STom Herbert static inline int ip6_default_np_autolabel(struct net *net) 90242240901STom Herbert { 90342240901STom Herbert return 0; 90442240901STom Herbert } 905a37934fcSFlorian Fainelli #endif 906a37934fcSFlorian Fainelli 907918ee507SPetr Machata #if IS_ENABLED(CONFIG_IPV6) 908918ee507SPetr Machata static inline int ip6_multipath_hash_policy(const struct net *net) 909918ee507SPetr Machata { 910918ee507SPetr Machata return net->ipv6.sysctl.multipath_hash_policy; 911918ee507SPetr Machata } 912918ee507SPetr Machata #else 913918ee507SPetr Machata static inline int ip6_multipath_hash_policy(const struct net *net) 914918ee507SPetr Machata { 915918ee507SPetr Machata return 0; 916918ee507SPetr Machata } 917918ee507SPetr Machata #endif 918cb1ce2efSTom Herbert 919971f359dSYOSHIFUJI Hideaki /* 9203e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 * Header manipulation 9213e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 */ 9223e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 static inline void ip6_flow_hdr(struct ipv6hdr *hdr, unsigned int tclass, 9233e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 __be32 flowlabel) 9243e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 { 92507f623d3SYOSHIFUJI Hideaki *(__be32 *)hdr = htonl(0x60000000 | (tclass << 20)) | flowlabel; 9263e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 } 9273e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 9286502ca52SYOSHIFUJI Hideaki / 吉藤英明 static inline __be32 ip6_flowinfo(const struct ipv6hdr *hdr) 9296502ca52SYOSHIFUJI Hideaki / 吉藤英明 { 9306502ca52SYOSHIFUJI Hideaki / 吉藤英明 return *(__be32 *)hdr & IPV6_FLOWINFO_MASK; 9316502ca52SYOSHIFUJI Hideaki / 吉藤英明 } 9326502ca52SYOSHIFUJI Hideaki / 吉藤英明 9333308de2bSFlorent Fourcot static inline __be32 ip6_flowlabel(const struct ipv6hdr *hdr) 9343308de2bSFlorent Fourcot { 9353308de2bSFlorent Fourcot return *(__be32 *)hdr & IPV6_FLOWLABEL_MASK; 9363308de2bSFlorent Fourcot } 9373308de2bSFlorent Fourcot 938d76ed22bSLi RongQing static inline u8 ip6_tclass(__be32 flowinfo) 939d76ed22bSLi RongQing { 940d76ed22bSLi RongQing return ntohl(flowinfo & IPV6_TCLASS_MASK) >> IPV6_TCLASS_SHIFT; 941d76ed22bSLi RongQing } 942eaa93bf4SDaniel Borkmann 943eaa93bf4SDaniel Borkmann static inline __be32 ip6_make_flowinfo(unsigned int tclass, __be32 flowlabel) 944eaa93bf4SDaniel Borkmann { 945eaa93bf4SDaniel Borkmann return htonl(tclass << IPV6_TCLASS_SHIFT) | flowlabel; 946eaa93bf4SDaniel Borkmann } 947eaa93bf4SDaniel Borkmann 948fa1be7e0SMichal Kubecek static inline __be32 flowi6_get_flowlabel(const struct flowi6 *fl6) 949fa1be7e0SMichal Kubecek { 950fa1be7e0SMichal Kubecek return fl6->flowlabel & IPV6_FLOWLABEL_MASK; 951fa1be7e0SMichal Kubecek } 952fa1be7e0SMichal Kubecek 9533e4e4c1fSYOSHIFUJI Hideaki / 吉藤英明 /* 9541da177e4SLinus Torvalds * Prototypes exported by ipv6 9551da177e4SLinus Torvalds */ 9561da177e4SLinus Torvalds 9571da177e4SLinus Torvalds /* 9581da177e4SLinus Torvalds * rcv function (called from netdevice level) 9591da177e4SLinus Torvalds */ 9601da177e4SLinus Torvalds 9615c3a0fd7SJoe Perches int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, 9625c3a0fd7SJoe Perches struct packet_type *pt, struct net_device *orig_dev); 963d8269e2cSEdward Cree void ipv6_list_rcv(struct list_head *head, struct packet_type *pt, 964d8269e2cSEdward Cree struct net_device *orig_dev); 9651da177e4SLinus Torvalds 9660c4b51f0SEric W. Biederman int ip6_rcv_finish(struct net *net, struct sock *sk, struct sk_buff *skb); 967b05e1066SPatrick McHardy 9681da177e4SLinus Torvalds /* 9691da177e4SLinus Torvalds * upper-layer output functions 9701da177e4SLinus Torvalds */ 9711c1e9d2bSEric Dumazet int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6, 97292e55f41SPablo Neira __u32 mark, struct ipv6_txoptions *opt, int tclass); 9731da177e4SLinus Torvalds 9745c3a0fd7SJoe Perches int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr); 9751da177e4SLinus Torvalds 9765c3a0fd7SJoe Perches int ip6_append_data(struct sock *sk, 9775c3a0fd7SJoe Perches int getfrag(void *from, char *to, int offset, int len, 9785c3a0fd7SJoe Perches int odd, struct sk_buff *skb), 97926879da5SWei Wang void *from, int length, int transhdrlen, 98026879da5SWei Wang struct ipcm6_cookie *ipc6, struct flowi6 *fl6, 9815fdaa88dSWillem de Bruijn struct rt6_info *rt, unsigned int flags); 9821da177e4SLinus Torvalds 9835c3a0fd7SJoe Perches int ip6_push_pending_frames(struct sock *sk); 9841da177e4SLinus Torvalds 9855c3a0fd7SJoe Perches void ip6_flush_pending_frames(struct sock *sk); 9861da177e4SLinus Torvalds 9876422398cSVlad Yasevich int ip6_send_skb(struct sk_buff *skb); 9886422398cSVlad Yasevich 9896422398cSVlad Yasevich struct sk_buff *__ip6_make_skb(struct sock *sk, struct sk_buff_head *queue, 9906422398cSVlad Yasevich struct inet_cork_full *cork, 9916422398cSVlad Yasevich struct inet6_cork *v6_cork); 9926422398cSVlad Yasevich struct sk_buff *ip6_make_skb(struct sock *sk, 9936422398cSVlad Yasevich int getfrag(void *from, char *to, int offset, 9946422398cSVlad Yasevich int len, int odd, struct sk_buff *skb), 9956422398cSVlad Yasevich void *from, int length, int transhdrlen, 99626879da5SWei Wang struct ipcm6_cookie *ipc6, struct flowi6 *fl6, 99726879da5SWei Wang struct rt6_info *rt, unsigned int flags, 9985fdaa88dSWillem de Bruijn struct inet_cork_full *cork); 9996422398cSVlad Yasevich 10006422398cSVlad Yasevich static inline struct sk_buff *ip6_finish_skb(struct sock *sk) 10016422398cSVlad Yasevich { 10026422398cSVlad Yasevich return __ip6_make_skb(sk, &sk->sk_write_queue, &inet_sk(sk)->cork, 10036422398cSVlad Yasevich &inet6_sk(sk)->cork); 10046422398cSVlad Yasevich } 10056422398cSVlad Yasevich 1006343d60aaSRoopa Prabhu int ip6_dst_lookup(struct net *net, struct sock *sk, struct dst_entry **dst, 1007343d60aaSRoopa Prabhu struct flowi6 *fl6); 10083aef934fSEric Dumazet struct dst_entry *ip6_dst_lookup_flow(const struct sock *sk, struct flowi6 *fl6, 10090e0d44abSSteffen Klassert const struct in6_addr *final_dst); 10105c3a0fd7SJoe Perches struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6, 101196818159SAlexey Kodanev const struct in6_addr *final_dst, 101296818159SAlexey Kodanev bool connected); 10135c3a0fd7SJoe Perches struct dst_entry *ip6_blackhole_route(struct net *net, 101469ead7afSDavid S. Miller struct dst_entry *orig_dst); 10151da177e4SLinus Torvalds 10161da177e4SLinus Torvalds /* 10171da177e4SLinus Torvalds * skb processing functions 10181da177e4SLinus Torvalds */ 10191da177e4SLinus Torvalds 1020ede2059dSEric W. Biederman int ip6_output(struct net *net, struct sock *sk, struct sk_buff *skb); 10215c3a0fd7SJoe Perches int ip6_forward(struct sk_buff *skb); 10225c3a0fd7SJoe Perches int ip6_input(struct sk_buff *skb); 10235c3a0fd7SJoe Perches int ip6_mc_input(struct sk_buff *skb); 102480bde363SPaolo Abeni void ip6_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int nexthdr, 102580bde363SPaolo Abeni bool have_final); 10261da177e4SLinus Torvalds 1027cf91a99dSEric W. Biederman int __ip6_local_out(struct net *net, struct sock *sk, struct sk_buff *skb); 102833224b16SEric W. Biederman int ip6_local_out(struct net *net, struct sock *sk, struct sk_buff *skb); 1029ef76bc23SHerbert Xu 10301da177e4SLinus Torvalds /* 10311da177e4SLinus Torvalds * Extension header (options) processing 10321da177e4SLinus Torvalds */ 10331da177e4SLinus Torvalds 10345c3a0fd7SJoe Perches void ipv6_push_nfrag_opts(struct sk_buff *skb, struct ipv6_txoptions *opt, 1035613fa3caSDavid Lebrun u8 *proto, struct in6_addr **daddr_p, 1036613fa3caSDavid Lebrun struct in6_addr *saddr); 10375c3a0fd7SJoe Perches void ipv6_push_frag_opts(struct sk_buff *skb, struct ipv6_txoptions *opt, 10381da177e4SLinus Torvalds u8 *proto); 10391da177e4SLinus Torvalds 10405c3a0fd7SJoe Perches int ipv6_skip_exthdr(const struct sk_buff *, int start, u8 *nexthdrp, 10415c3a0fd7SJoe Perches __be16 *frag_offp); 10421da177e4SLinus Torvalds 10435c3a0fd7SJoe Perches bool ipv6_ext_hdr(u8 nexthdr); 10441da177e4SLinus Torvalds 1045f8f62675SJesse Gross enum { 1046f8f62675SJesse Gross IP6_FH_F_FRAG = (1 << 0), 1047f8f62675SJesse Gross IP6_FH_F_AUTH = (1 << 1), 10489195bb8eSAnsis Atteka IP6_FH_F_SKIP_RH = (1 << 2), 1049f8f62675SJesse Gross }; 1050f8f62675SJesse Gross 1051f8f62675SJesse Gross /* find specified header and get offset to it */ 10525c3a0fd7SJoe Perches int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset, int target, 10535c3a0fd7SJoe Perches unsigned short *fragoff, int *fragflg); 1054f8f62675SJesse Gross 10550868383bSHuw Davies int ipv6_find_tlv(const struct sk_buff *skb, int offset, int type); 1056c61a4043SMasahide NAKAMURA 10575c3a0fd7SJoe Perches struct in6_addr *fl6_update_dst(struct flowi6 *fl6, 105820c59de2SArnaud Ebalard const struct ipv6_txoptions *opt, 105920c59de2SArnaud Ebalard struct in6_addr *orig); 106020c59de2SArnaud Ebalard 10611da177e4SLinus Torvalds /* 10621da177e4SLinus Torvalds * socket options (ipv6_sockglue.c) 10631da177e4SLinus Torvalds */ 10641da177e4SLinus Torvalds 10655c3a0fd7SJoe Perches int ipv6_setsockopt(struct sock *sk, int level, int optname, 10665c3a0fd7SJoe Perches char __user *optval, unsigned int optlen); 10675c3a0fd7SJoe Perches int ipv6_getsockopt(struct sock *sk, int level, int optname, 10685c3a0fd7SJoe Perches char __user *optval, int __user *optlen); 10695c3a0fd7SJoe Perches int compat_ipv6_setsockopt(struct sock *sk, int level, int optname, 10705c3a0fd7SJoe Perches char __user *optval, unsigned int optlen); 10715c3a0fd7SJoe Perches int compat_ipv6_getsockopt(struct sock *sk, int level, int optname, 10725c3a0fd7SJoe Perches char __user *optval, int __user *optlen); 10731da177e4SLinus Torvalds 10740382a25aSGuillaume Nault int __ip6_datagram_connect(struct sock *sk, struct sockaddr *addr, 10750382a25aSGuillaume Nault int addr_len); 10765c3a0fd7SJoe Perches int ip6_datagram_connect(struct sock *sk, struct sockaddr *addr, int addr_len); 107782b276cdSHannes Frederic Sowa int ip6_datagram_connect_v6_only(struct sock *sk, struct sockaddr *addr, 107882b276cdSHannes Frederic Sowa int addr_len); 107933c162a9SMartin KaFai Lau int ip6_datagram_dst_update(struct sock *sk, bool fix_sk_saddr); 1080e646b657SMartin KaFai Lau void ip6_datagram_release_cb(struct sock *sk); 10811da177e4SLinus Torvalds 108285fbaa75SHannes Frederic Sowa int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len, 108385fbaa75SHannes Frederic Sowa int *addr_len); 108485fbaa75SHannes Frederic Sowa int ipv6_recv_rxpmtu(struct sock *sk, struct msghdr *msg, int len, 108585fbaa75SHannes Frederic Sowa int *addr_len); 10865c3a0fd7SJoe Perches void ipv6_icmp_error(struct sock *sk, struct sk_buff *skb, int err, __be16 port, 10871da177e4SLinus Torvalds u32 info, u8 *payload); 10885c3a0fd7SJoe Perches void ipv6_local_error(struct sock *sk, int err, struct flowi6 *fl6, u32 info); 10895c3a0fd7SJoe Perches void ipv6_local_rxpmtu(struct sock *sk, struct flowi6 *fl6, u32 mtu); 10901da177e4SLinus Torvalds 10915c3a0fd7SJoe Perches int inet6_release(struct socket *sock); 10925c3a0fd7SJoe Perches int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len); 10939b2c45d4SDenys Vlasenko int inet6_getname(struct socket *sock, struct sockaddr *uaddr, 10945c3a0fd7SJoe Perches int peer); 10955c3a0fd7SJoe Perches int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg); 10961da177e4SLinus Torvalds 10975c3a0fd7SJoe Perches int inet6_hash_connect(struct inet_timewait_death_row *death_row, 1098d8313f5cSArnaldo Carvalho de Melo struct sock *sk); 1099d8313f5cSArnaldo Carvalho de Melo 11001da177e4SLinus Torvalds /* 11011da177e4SLinus Torvalds * reassembly.c 11021da177e4SLinus Torvalds */ 110390ddc4f0SEric Dumazet extern const struct proto_ops inet6_stream_ops; 110490ddc4f0SEric Dumazet extern const struct proto_ops inet6_dgram_ops; 110577d4b1d3SEric Dumazet extern const struct proto_ops inet6_sockraw_ops; 110620380731SArnaldo Carvalho de Melo 110714c85021SArnaldo Carvalho de Melo struct group_source_req; 110814c85021SArnaldo Carvalho de Melo struct group_filter; 110914c85021SArnaldo Carvalho de Melo 11105c3a0fd7SJoe Perches int ip6_mc_source(int add, int omode, struct sock *sk, 111120380731SArnaldo Carvalho de Melo struct group_source_req *pgsr); 11125c3a0fd7SJoe Perches int ip6_mc_msfilter(struct sock *sk, struct group_filter *gsf); 11135c3a0fd7SJoe Perches int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf, 11145c3a0fd7SJoe Perches struct group_filter __user *optval, int __user *optlen); 111520380731SArnaldo Carvalho de Melo 111620380731SArnaldo Carvalho de Melo #ifdef CONFIG_PROC_FS 11175c3a0fd7SJoe Perches int ac6_proc_init(struct net *net); 11185c3a0fd7SJoe Perches void ac6_proc_exit(struct net *net); 11195c3a0fd7SJoe Perches int raw6_proc_init(void); 11205c3a0fd7SJoe Perches void raw6_proc_exit(void); 11215c3a0fd7SJoe Perches int tcp6_proc_init(struct net *net); 11225c3a0fd7SJoe Perches void tcp6_proc_exit(struct net *net); 11235c3a0fd7SJoe Perches int udp6_proc_init(struct net *net); 11245c3a0fd7SJoe Perches void udp6_proc_exit(struct net *net); 11255c3a0fd7SJoe Perches int udplite6_proc_init(void); 11265c3a0fd7SJoe Perches void udplite6_proc_exit(void); 11275c3a0fd7SJoe Perches int ipv6_misc_proc_init(void); 11285c3a0fd7SJoe Perches void ipv6_misc_proc_exit(void); 11295c3a0fd7SJoe Perches int snmp6_register_dev(struct inet6_dev *idev); 11305c3a0fd7SJoe Perches int snmp6_unregister_dev(struct inet6_dev *idev); 113120380731SArnaldo Carvalho de Melo 11327f7d9a6bSHerbert Xu #else 11336ab57e7eSDaniel Lezcano static inline int ac6_proc_init(struct net *net) { return 0; } 11346ab57e7eSDaniel Lezcano static inline void ac6_proc_exit(struct net *net) { } 11356ab57e7eSDaniel Lezcano static inline int snmp6_register_dev(struct inet6_dev *idev) { return 0; } 11366ab57e7eSDaniel Lezcano static inline int snmp6_unregister_dev(struct inet6_dev *idev) { return 0; } 113720380731SArnaldo Carvalho de Melo #endif 113820380731SArnaldo Carvalho de Melo 113920380731SArnaldo Carvalho de Melo #ifdef CONFIG_SYSCTL 11405c3a0fd7SJoe Perches struct ctl_table *ipv6_icmp_sysctl_init(struct net *net); 11415c3a0fd7SJoe Perches struct ctl_table *ipv6_route_sysctl_init(struct net *net); 11425c3a0fd7SJoe Perches int ipv6_sysctl_register(void); 11435c3a0fd7SJoe Perches void ipv6_sysctl_unregister(void); 114420380731SArnaldo Carvalho de Melo #endif 114520380731SArnaldo Carvalho de Melo 114646a4dee0SMadhu Challa int ipv6_sock_mc_join(struct sock *sk, int ifindex, 114746a4dee0SMadhu Challa const struct in6_addr *addr); 1148c7ea20c9SHangbin Liu int ipv6_sock_mc_join_ssm(struct sock *sk, int ifindex, 1149c7ea20c9SHangbin Liu const struct in6_addr *addr, unsigned int mode); 115046a4dee0SMadhu Challa int ipv6_sock_mc_drop(struct sock *sk, int ifindex, 115146a4dee0SMadhu Challa const struct in6_addr *addr); 11521da177e4SLinus Torvalds #endif /* _NET_IPV6_H */ 1153