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