^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) * UDP over IPv6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Linux INET6 implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Authors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Pedro Roque <roque@di.fc.ul.pt>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Based on linux/ipv4/udp.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Fixes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Hideaki YOSHIFUJI : sin6_scope_id support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * YOSHIFUJI Hideaki @USAGI and: Support IPV6_V6ONLY socket option, which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Alexey Kuznetsov allow both IPv4 and IPv6 sockets to bind
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * a single port at the same time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Kazunori MIYAZAWA @USAGI: change process style to use ip6_append_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * YOSHIFUJI Hideaki @USAGI: convert /proc/net/udp6 to seq_file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/sockios.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/in6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/if_arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/icmpv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/indirect_call_wrapper.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <net/addrconf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <net/ndisc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <net/protocol.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <net/transp_v6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <net/ip6_route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <net/raw.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <net/tcp_states.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include <net/ip6_checksum.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include <net/ip6_tunnel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include <net/xfrm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include <net/inet_hashtables.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include <net/inet6_hashtables.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include <net/busy_poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #include <net/sock_reuseport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #include <trace/events/skb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #include "udp_impl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static u32 udp6_ehashfn(const struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) const struct in6_addr *laddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) const u16 lport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) const struct in6_addr *faddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) const __be16 fport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static u32 udp6_ehash_secret __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static u32 udp_ipv6_hash_secret __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) u32 lhash, fhash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) net_get_random_once(&udp6_ehash_secret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) sizeof(udp6_ehash_secret));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) net_get_random_once(&udp_ipv6_hash_secret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) sizeof(udp_ipv6_hash_secret));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) lhash = (__force u32)laddr->s6_addr32[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) fhash = __ipv6_addr_jhash(faddr, udp_ipv6_hash_secret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return __inet6_ehashfn(lhash, lport, fhash, fport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) udp_ipv6_hash_secret + net_hash_mix(net));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) int udp_v6_get_port(struct sock *sk, unsigned short snum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) unsigned int hash2_nulladdr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) ipv6_portaddr_hash(sock_net(sk), &in6addr_any, snum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) unsigned int hash2_partial =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) ipv6_portaddr_hash(sock_net(sk), &sk->sk_v6_rcv_saddr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) /* precompute partial secondary hash */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) udp_sk(sk)->udp_portaddr_hash = hash2_partial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) return udp_lib_get_port(sk, snum, hash2_nulladdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) void udp_v6_rehash(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) u16 new_hash = ipv6_portaddr_hash(sock_net(sk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) &sk->sk_v6_rcv_saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) inet_sk(sk)->inet_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) udp_lib_rehash(sk, new_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static int compute_score(struct sock *sk, struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) const struct in6_addr *saddr, __be16 sport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) const struct in6_addr *daddr, unsigned short hnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) int dif, int sdif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) int score;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct inet_sock *inet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) bool dev_match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) if (!net_eq(sock_net(sk), net) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) udp_sk(sk)->udp_port_hash != hnum ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) sk->sk_family != PF_INET6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) score = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) inet = inet_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) if (inet->inet_dport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) if (inet->inet_dport != sport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) score++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (!ipv6_addr_any(&sk->sk_v6_daddr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) if (!ipv6_addr_equal(&sk->sk_v6_daddr, saddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) score++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) dev_match = udp_sk_bound_dev_eq(net, sk->sk_bound_dev_if, dif, sdif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) if (!dev_match)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (sk->sk_bound_dev_if)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) score++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (READ_ONCE(sk->sk_incoming_cpu) == raw_smp_processor_id())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) score++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) return score;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static struct sock *lookup_reuseport(struct net *net, struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) const struct in6_addr *saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) __be16 sport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) const struct in6_addr *daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) unsigned int hnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct sock *reuse_sk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) u32 hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (sk->sk_reuseport && sk->sk_state != TCP_ESTABLISHED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) hash = udp6_ehashfn(net, daddr, hnum, saddr, sport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) reuse_sk = reuseport_select_sock(sk, hash, skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) sizeof(struct udphdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return reuse_sk;
^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) /* called with rcu_read_lock() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static struct sock *udp6_lib_lookup2(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) const struct in6_addr *saddr, __be16 sport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) const struct in6_addr *daddr, unsigned int hnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) int dif, int sdif, struct udp_hslot *hslot2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct sock *sk, *result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) int score, badness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) result = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) badness = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) udp_portaddr_for_each_entry_rcu(sk, &hslot2->head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) score = compute_score(sk, net, saddr, sport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) daddr, hnum, dif, sdif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (score > badness) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) result = lookup_reuseport(net, sk, skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) saddr, sport, daddr, hnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) /* Fall back to scoring if group has connections */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (result && !reuseport_has_conns(sk, false))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) result = result ? : sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) badness = score;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static inline struct sock *udp6_lookup_run_bpf(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) struct udp_table *udptable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) const struct in6_addr *saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) __be16 sport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) const struct in6_addr *daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) u16 hnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) struct sock *sk, *reuse_sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) bool no_reuseport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (udptable != &udp_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return NULL; /* only UDP is supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) no_reuseport = bpf_sk_lookup_run_v6(net, IPPROTO_UDP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) saddr, sport, daddr, hnum, &sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) if (no_reuseport || IS_ERR_OR_NULL(sk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) return sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) reuse_sk = lookup_reuseport(net, sk, skb, saddr, sport, daddr, hnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (reuse_sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) sk = reuse_sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /* rcu_read_lock() must be held */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) struct sock *__udp6_lib_lookup(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) const struct in6_addr *saddr, __be16 sport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) const struct in6_addr *daddr, __be16 dport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) int dif, int sdif, struct udp_table *udptable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) unsigned short hnum = ntohs(dport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) unsigned int hash2, slot2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) struct udp_hslot *hslot2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) struct sock *result, *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) hash2 = ipv6_portaddr_hash(net, daddr, hnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) slot2 = hash2 & udptable->mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) hslot2 = &udptable->hash2[slot2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /* Lookup connected or non-wildcard sockets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) result = udp6_lib_lookup2(net, saddr, sport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) daddr, hnum, dif, sdif,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) hslot2, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (!IS_ERR_OR_NULL(result) && result->sk_state == TCP_ESTABLISHED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) /* Lookup redirect from BPF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (static_branch_unlikely(&bpf_sk_lookup_enabled)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) sk = udp6_lookup_run_bpf(net, udptable, skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) saddr, sport, daddr, hnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (sk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) result = sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) /* Got non-wildcard socket or error on first lookup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) /* Lookup wildcard sockets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) hash2 = ipv6_portaddr_hash(net, &in6addr_any, hnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) slot2 = hash2 & udptable->mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) hslot2 = &udptable->hash2[slot2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) result = udp6_lib_lookup2(net, saddr, sport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) &in6addr_any, hnum, dif, sdif,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) hslot2, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) if (IS_ERR(result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) EXPORT_SYMBOL_GPL(__udp6_lib_lookup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static struct sock *__udp6_lib_lookup_skb(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) __be16 sport, __be16 dport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) struct udp_table *udptable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) const struct ipv6hdr *iph = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) return __udp6_lib_lookup(dev_net(skb->dev), &iph->saddr, sport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) &iph->daddr, dport, inet6_iif(skb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) inet6_sdif(skb), udptable, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) struct sock *udp6_lib_lookup_skb(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) __be16 sport, __be16 dport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) const struct ipv6hdr *iph = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) return __udp6_lib_lookup(dev_net(skb->dev), &iph->saddr, sport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) &iph->daddr, dport, inet6_iif(skb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) inet6_sdif(skb), &udp_table, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) EXPORT_SYMBOL_GPL(udp6_lib_lookup_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) /* Must be called under rcu_read_lock().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) * Does increment socket refcount.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) #if IS_ENABLED(CONFIG_NF_TPROXY_IPV6) || IS_ENABLED(CONFIG_NF_SOCKET_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) struct sock *udp6_lib_lookup(struct net *net, const struct in6_addr *saddr, __be16 sport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) const struct in6_addr *daddr, __be16 dport, int dif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) sk = __udp6_lib_lookup(net, saddr, sport, daddr, dport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) dif, 0, &udp_table, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) if (sk && !refcount_inc_not_zero(&sk->sk_refcnt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) sk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) return sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) EXPORT_SYMBOL_GPL(udp6_lib_lookup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) /* do not use the scratch area len for jumbogram: their length execeeds the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) * scratch area space; note that the IP6CB flags is still in the first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) * cacheline, so checking for jumbograms is cheap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) static int udp6_skb_len(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) return unlikely(inet6_is_jumbogram(skb)) ? skb->len : udp_skb_len(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) * This should be easy, if there is something there we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) * return it, otherwise we block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) int udpv6_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) int noblock, int flags, int *addr_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) struct ipv6_pinfo *np = inet6_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) struct inet_sock *inet = inet_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) unsigned int ulen, copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) int off, err, peeking = flags & MSG_PEEK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) int is_udplite = IS_UDPLITE(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) struct udp_mib __percpu *mib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) bool checksum_valid = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) int is_udp4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (flags & MSG_ERRQUEUE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) return ipv6_recv_error(sk, msg, len, addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) if (np->rxpmtu && np->rxopt.bits.rxpmtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) return ipv6_recv_rxpmtu(sk, msg, len, addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) try_again:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) off = sk_peek_offset(sk, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) skb = __skb_recv_udp(sk, flags, noblock, &off, &err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) ulen = udp6_skb_len(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) copied = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) if (copied > ulen - off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) copied = ulen - off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) else if (copied < ulen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) msg->msg_flags |= MSG_TRUNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) is_udp4 = (skb->protocol == htons(ETH_P_IP));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) mib = __UDPX_MIB(sk, is_udp4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * If checksum is needed at all, try to do it while copying the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) * data. If the data is truncated, or if we only want a partial
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) * coverage checksum (UDP-Lite), do it before the copy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) if (copied < ulen || peeking ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) (is_udplite && UDP_SKB_CB(skb)->partial_cov)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) checksum_valid = udp_skb_csum_unnecessary(skb) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) !__udp_lib_checksum_complete(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) if (!checksum_valid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) goto csum_copy_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) if (checksum_valid || udp_skb_csum_unnecessary(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) if (udp_skb_is_linear(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) err = copy_linear_skb(skb, copied, off, &msg->msg_iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) err = skb_copy_datagram_msg(skb, off, msg, copied);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) err = skb_copy_and_csum_datagram_msg(skb, off, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) if (err == -EINVAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) goto csum_copy_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) if (unlikely(err)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (!peeking) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) atomic_inc(&sk->sk_drops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) SNMP_INC_STATS(mib, UDP_MIB_INERRORS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) if (!peeking)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) SNMP_INC_STATS(mib, UDP_MIB_INDATAGRAMS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) sock_recv_ts_and_drops(msg, sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) /* Copy the address. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) if (msg->msg_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) DECLARE_SOCKADDR(struct sockaddr_in6 *, sin6, msg->msg_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) sin6->sin6_family = AF_INET6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) sin6->sin6_port = udp_hdr(skb)->source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) sin6->sin6_flowinfo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) if (is_udp4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) ipv6_addr_set_v4mapped(ip_hdr(skb)->saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) &sin6->sin6_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) sin6->sin6_scope_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) sin6->sin6_addr = ipv6_hdr(skb)->saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) sin6->sin6_scope_id =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) ipv6_iface_scope_id(&sin6->sin6_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) inet6_iif(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) *addr_len = sizeof(*sin6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) if (cgroup_bpf_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) BPF_CGROUP_RUN_PROG_UDP6_RECVMSG_LOCK(sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) (struct sockaddr *)sin6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) if (udp_sk(sk)->gro_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) udp_cmsg_recv(msg, sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) if (np->rxopt.all)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) ip6_datagram_recv_common_ctl(sk, msg, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) if (is_udp4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) if (inet->cmsg_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) ip_cmsg_recv_offset(msg, sk, skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) sizeof(struct udphdr), off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) if (np->rxopt.all)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) ip6_datagram_recv_specific_ctl(sk, msg, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) err = copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) if (flags & MSG_TRUNC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) err = ulen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) skb_consume_udp(sk, skb, peeking ? -err : err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) csum_copy_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) if (!__sk_queue_drop_skb(sk, &udp_sk(sk)->reader_queue, skb, flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) udp_skb_destructor)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) SNMP_INC_STATS(mib, UDP_MIB_CSUMERRORS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) SNMP_INC_STATS(mib, UDP_MIB_INERRORS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) /* starting over for a new packet, but check if we need to yield */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) msg->msg_flags &= ~MSG_TRUNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) goto try_again;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) DEFINE_STATIC_KEY_FALSE(udpv6_encap_needed_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) void udpv6_encap_enable(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) static_branch_inc(&udpv6_encap_needed_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) EXPORT_SYMBOL(udpv6_encap_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) /* Handler for tunnels with arbitrary destination ports: no socket lookup, go
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) * through error handlers in encapsulations looking for a match.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) static int __udp6_lib_err_encap_no_sk(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) struct inet6_skb_parm *opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) u8 type, u8 code, int offset, __be32 info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) for (i = 0; i < MAX_IPTUN_ENCAP_OPS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) int (*handler)(struct sk_buff *skb, struct inet6_skb_parm *opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) u8 type, u8 code, int offset, __be32 info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) const struct ip6_tnl_encap_ops *encap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) encap = rcu_dereference(ip6tun_encaps[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) if (!encap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) handler = encap->err_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) if (handler && !handler(skb, opt, type, code, offset, info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) /* Try to match ICMP errors to UDP tunnels by looking up a socket without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) * reversing source and destination port: this will match tunnels that force the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) * same destination port on both endpoints (e.g. VXLAN, GENEVE). Note that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) * lwtunnels might actually break this assumption by being configured with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) * different destination ports on endpoints, in this case we won't be able to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) * trace ICMP messages back to them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) * If this doesn't match any socket, probe tunnels with arbitrary destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) * ports (e.g. FoU, GUE): there, the receiving socket is useless, as the port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) * we've sent packets to won't necessarily match the local destination port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) * Then ask the tunnel implementation to match the error against a valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) * association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) * Return an error if we can't find a match, the socket if we need further
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) * processing, zero otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) static struct sock *__udp6_lib_err_encap(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) const struct ipv6hdr *hdr, int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) struct udphdr *uh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) struct udp_table *udptable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) struct inet6_skb_parm *opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) u8 type, u8 code, __be32 info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) int network_offset, transport_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) network_offset = skb_network_offset(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) transport_offset = skb_transport_offset(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) /* Network header needs to point to the outer IPv6 header inside ICMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) skb_reset_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) /* Transport header needs to point to the UDP header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) skb_set_transport_header(skb, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) sk = __udp6_lib_lookup(net, &hdr->daddr, uh->source,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) &hdr->saddr, uh->dest,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) inet6_iif(skb), 0, udptable, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) if (sk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) int (*lookup)(struct sock *sk, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) struct udp_sock *up = udp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) lookup = READ_ONCE(up->encap_err_lookup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) if (!lookup || lookup(sk, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) sk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) if (!sk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) sk = ERR_PTR(__udp6_lib_err_encap_no_sk(skb, opt, type, code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) offset, info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) skb_set_transport_header(skb, transport_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) skb_set_network_header(skb, network_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) return sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) int __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) u8 type, u8 code, int offset, __be32 info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) struct udp_table *udptable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) struct ipv6_pinfo *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) const struct ipv6hdr *hdr = (const struct ipv6hdr *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) const struct in6_addr *saddr = &hdr->saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) const struct in6_addr *daddr = &hdr->daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) struct udphdr *uh = (struct udphdr *)(skb->data+offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) bool tunnel = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) int harderr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) struct net *net = dev_net(skb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) sk = __udp6_lib_lookup(net, daddr, uh->dest, saddr, uh->source,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) inet6_iif(skb), inet6_sdif(skb), udptable, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) if (!sk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) /* No socket for error: try tunnels before discarding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) sk = ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) if (static_branch_unlikely(&udpv6_encap_needed_key)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) sk = __udp6_lib_err_encap(net, hdr, offset, uh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) udptable, skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) opt, type, code, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) if (!sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) if (IS_ERR(sk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) __ICMP6_INC_STATS(net, __in6_dev_get(skb->dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) ICMP6_MIB_INERRORS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) return PTR_ERR(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) tunnel = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) harderr = icmpv6_err_convert(type, code, &err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) np = inet6_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) if (type == ICMPV6_PKT_TOOBIG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) if (!ip6_sk_accept_pmtu(sk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) ip6_sk_update_pmtu(skb, sk, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) if (np->pmtudisc != IPV6_PMTUDISC_DONT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) harderr = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) if (type == NDISC_REDIRECT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) if (tunnel) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) ip6_redirect(skb, sock_net(sk), inet6_iif(skb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) sk->sk_mark, sk->sk_uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) ip6_sk_redirect(skb, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) /* Tunnels don't have an application socket: don't pass errors back */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) if (tunnel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) if (!np->recverr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) if (!harderr || sk->sk_state != TCP_ESTABLISHED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) ipv6_icmp_error(sk, skb, err, uh->dest, ntohl(info), (u8 *)(uh+1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) sk->sk_err = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) sk->sk_error_report(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) static int __udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) if (!ipv6_addr_any(&sk->sk_v6_daddr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) sock_rps_save_rxhash(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) sk_mark_napi_id(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) sk_incoming_cpu_update(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) sk_mark_napi_id_once(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) rc = __udp_enqueue_schedule_skb(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) int is_udplite = IS_UDPLITE(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) /* Note that an ENOMEM error is charged twice */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) if (rc == -ENOMEM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) UDP6_INC_STATS(sock_net(sk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) UDP_MIB_RCVBUFERRORS, is_udplite);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) UDP6_INC_STATS(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) static __inline__ int udpv6_err(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) struct inet6_skb_parm *opt, u8 type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) u8 code, int offset, __be32 info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) return __udp6_lib_err(skb, opt, type, code, offset, info, &udp_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) static int udpv6_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) struct udp_sock *up = udp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) int is_udplite = IS_UDPLITE(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) if (static_branch_unlikely(&udpv6_encap_needed_key) && up->encap_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) int (*encap_rcv)(struct sock *sk, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) * This is an encapsulation socket so pass the skb to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) * the socket's udp_encap_rcv() hook. Otherwise, just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) * fall through and pass this up the UDP socket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) * up->encap_rcv() returns the following value:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) * =0 if skb was successfully passed to the encap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) * handler or was discarded by it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) * >0 if skb should be passed on to UDP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) * <0 if skb should be resubmitted as proto -N
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) /* if we're overly short, let UDP handle it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) encap_rcv = READ_ONCE(up->encap_rcv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) if (encap_rcv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) /* Verify checksum before giving to encap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) if (udp_lib_checksum_complete(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) goto csum_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) ret = encap_rcv(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) if (ret <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) __UDP_INC_STATS(sock_net(sk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) UDP_MIB_INDATAGRAMS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) is_udplite);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) return -ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) /* FALLTHROUGH -- it's a UDP Packet */
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) * UDP-Lite specific tests, ignored on UDP sockets (see net/ipv4/udp.c).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) if ((up->pcflag & UDPLITE_RECV_CC) && UDP_SKB_CB(skb)->partial_cov) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) if (up->pcrlen == 0) { /* full coverage was set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) net_dbg_ratelimited("UDPLITE6: partial coverage %d while full coverage %d requested\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) UDP_SKB_CB(skb)->cscov, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) if (UDP_SKB_CB(skb)->cscov < up->pcrlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) net_dbg_ratelimited("UDPLITE6: coverage %d too small, need min %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) UDP_SKB_CB(skb)->cscov, up->pcrlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) prefetch(&sk->sk_rmem_alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) if (rcu_access_pointer(sk->sk_filter) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) udp_lib_checksum_complete(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) goto csum_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) if (sk_filter_trim_cap(sk, skb, sizeof(struct udphdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) udp_csum_pull_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) skb_dst_drop(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) return __udpv6_queue_rcv_skb(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) csum_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) __UDP6_INC_STATS(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) __UDP6_INC_STATS(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) atomic_inc(&sk->sk_drops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) static int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) struct sk_buff *next, *segs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) if (likely(!udp_unexpected_gso(sk, skb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) return udpv6_queue_rcv_one_skb(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) __skb_push(skb, -skb_mac_offset(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) segs = udp_rcv_segment(sk, skb, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) skb_list_walk_safe(segs, skb, next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) __skb_pull(skb, skb_transport_offset(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) ret = udpv6_queue_rcv_one_skb(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) if (ret > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) ip6_protocol_deliver_rcu(dev_net(skb->dev), skb, ret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) return 0;
^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) static bool __udp_v6_is_mcast_sock(struct net *net, struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) __be16 loc_port, const struct in6_addr *loc_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) __be16 rmt_port, const struct in6_addr *rmt_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) int dif, int sdif, unsigned short hnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) struct inet_sock *inet = inet_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) if (!net_eq(sock_net(sk), net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) if (udp_sk(sk)->udp_port_hash != hnum ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) sk->sk_family != PF_INET6 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) (inet->inet_dport && inet->inet_dport != rmt_port) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) (!ipv6_addr_any(&sk->sk_v6_daddr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) !ipv6_addr_equal(&sk->sk_v6_daddr, rmt_addr)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) !udp_sk_bound_dev_eq(net, sk->sk_bound_dev_if, dif, sdif) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) (!ipv6_addr_any(&sk->sk_v6_rcv_saddr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) !ipv6_addr_equal(&sk->sk_v6_rcv_saddr, loc_addr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) if (!inet6_mc_check(sk, loc_addr, rmt_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) static void udp6_csum_zero_error(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) /* RFC 2460 section 8.1 says that we SHOULD log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) * this error. Well, it is reasonable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) net_dbg_ratelimited("IPv6: udp checksum is 0 for [%pI6c]:%u->[%pI6c]:%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) &ipv6_hdr(skb)->saddr, ntohs(udp_hdr(skb)->source),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) &ipv6_hdr(skb)->daddr, ntohs(udp_hdr(skb)->dest));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) * Note: called only from the BH handler context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) * so we don't need to lock the hashes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) static int __udp6_lib_mcast_deliver(struct net *net, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) const struct in6_addr *saddr, const struct in6_addr *daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) struct udp_table *udptable, int proto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) struct sock *sk, *first = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) const struct udphdr *uh = udp_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) unsigned short hnum = ntohs(uh->dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) struct udp_hslot *hslot = udp_hashslot(udptable, net, hnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) unsigned int offset = offsetof(typeof(*sk), sk_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) unsigned int hash2 = 0, hash2_any = 0, use_hash2 = (hslot->count > 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) int dif = inet6_iif(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) int sdif = inet6_sdif(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) struct hlist_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) struct sk_buff *nskb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) if (use_hash2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) hash2_any = ipv6_portaddr_hash(net, &in6addr_any, hnum) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) udptable->mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) hash2 = ipv6_portaddr_hash(net, daddr, hnum) & udptable->mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) start_lookup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) hslot = &udptable->hash2[hash2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) offset = offsetof(typeof(*sk), __sk_common.skc_portaddr_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) sk_for_each_entry_offset_rcu(sk, node, &hslot->head, offset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) if (!__udp_v6_is_mcast_sock(net, sk, uh->dest, daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) uh->source, saddr, dif, sdif,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) hnum))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) /* If zero checksum and no_check is not on for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) * the socket then skip it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) if (!uh->check && !udp_sk(sk)->no_check6_rx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) if (!first) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) first = sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) nskb = skb_clone(skb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) if (unlikely(!nskb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) atomic_inc(&sk->sk_drops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) __UDP6_INC_STATS(net, UDP_MIB_RCVBUFERRORS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) IS_UDPLITE(sk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) __UDP6_INC_STATS(net, UDP_MIB_INERRORS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) IS_UDPLITE(sk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) continue;
^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 (udpv6_queue_rcv_skb(sk, nskb) > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) consume_skb(nskb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) /* Also lookup *:port if we are using hash2 and haven't done so yet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) if (use_hash2 && hash2 != hash2_any) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) hash2 = hash2_any;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) goto start_lookup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) if (first) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) if (udpv6_queue_rcv_skb(first, skb) > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) consume_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) __UDP6_INC_STATS(net, UDP_MIB_IGNOREDMULTI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) proto == IPPROTO_UDPLITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) static void udp6_sk_rx_dst_set(struct sock *sk, struct dst_entry *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) if (udp_sk_rx_dst_set(sk, dst)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) const struct rt6_info *rt = (const struct rt6_info *)dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) inet6_sk(sk)->rx_dst_cookie = rt6_get_cookie(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) /* wrapper for udp_queue_rcv_skb tacking care of csum conversion and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) * return code conversion for ip layer consumption
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) static int udp6_unicast_rcv_skb(struct sock *sk, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) struct udphdr *uh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) if (inet_get_convert_csum(sk) && uh->check && !IS_UDPLITE(sk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) skb_checksum_try_convert(skb, IPPROTO_UDP, ip6_compute_pseudo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) ret = udpv6_queue_rcv_skb(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) /* a return value > 0 means to resubmit the input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) if (ret > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) int proto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) const struct in6_addr *saddr, *daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) struct net *net = dev_net(skb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) struct udphdr *uh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) bool refcounted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) u32 ulen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) if (!pskb_may_pull(skb, sizeof(struct udphdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) saddr = &ipv6_hdr(skb)->saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) daddr = &ipv6_hdr(skb)->daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) uh = udp_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) ulen = ntohs(uh->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) if (ulen > skb->len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) goto short_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) if (proto == IPPROTO_UDP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) /* UDP validates ulen. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) /* Check for jumbo payload */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) if (ulen == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) ulen = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) if (ulen < sizeof(*uh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) goto short_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) if (ulen < skb->len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) if (pskb_trim_rcsum(skb, ulen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) goto short_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) saddr = &ipv6_hdr(skb)->saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) daddr = &ipv6_hdr(skb)->daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) uh = udp_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) if (udp6_csum_init(skb, uh, proto))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) goto csum_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) /* Check if the socket is already available, e.g. due to early demux */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) sk = skb_steal_sock(skb, &refcounted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) if (sk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) struct dst_entry *dst = skb_dst(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) if (unlikely(sk->sk_rx_dst != dst))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) udp6_sk_rx_dst_set(sk, dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) if (!uh->check && !udp_sk(sk)->no_check6_rx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) if (refcounted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) sock_put(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) goto report_csum_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) ret = udp6_unicast_rcv_skb(sk, skb, uh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) if (refcounted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) sock_put(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) return ret;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) * Multicast receive code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) if (ipv6_addr_is_multicast(daddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) return __udp6_lib_mcast_deliver(net, skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) saddr, daddr, udptable, proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) /* Unicast */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) sk = __udp6_lib_lookup_skb(skb, uh->source, uh->dest, udptable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) if (sk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) if (!uh->check && !udp_sk(sk)->no_check6_rx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) goto report_csum_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) return udp6_unicast_rcv_skb(sk, skb, uh);
^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) if (!uh->check)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) goto report_csum_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) if (!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) if (udp_lib_checksum_complete(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) goto csum_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) __UDP6_INC_STATS(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) short_packet:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) net_dbg_ratelimited("UDP%sv6: short packet: From [%pI6c]:%u %d/%d to [%pI6c]:%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) proto == IPPROTO_UDPLITE ? "-Lite" : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) saddr, ntohs(uh->source),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) ulen, skb->len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) daddr, ntohs(uh->dest));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) report_csum_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) udp6_csum_zero_error(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) csum_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) __UDP6_INC_STATS(net, UDP_MIB_CSUMERRORS, proto == IPPROTO_UDPLITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) discard:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) __UDP6_INC_STATS(net, UDP_MIB_INERRORS, proto == IPPROTO_UDPLITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) static struct sock *__udp6_lib_demux_lookup(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) __be16 loc_port, const struct in6_addr *loc_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) __be16 rmt_port, const struct in6_addr *rmt_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) int dif, int sdif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) unsigned short hnum = ntohs(loc_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) unsigned int hash2 = ipv6_portaddr_hash(net, loc_addr, hnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) unsigned int slot2 = hash2 & udp_table.mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) struct udp_hslot *hslot2 = &udp_table.hash2[slot2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) const __portpair ports = INET_COMBINED_PORTS(rmt_port, hnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) udp_portaddr_for_each_entry_rcu(sk, &hslot2->head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) if (sk->sk_state == TCP_ESTABLISHED &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) INET6_MATCH(sk, net, rmt_addr, loc_addr, ports, dif, sdif))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) return sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) /* Only check first socket in chain */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) INDIRECT_CALLABLE_SCOPE void udp_v6_early_demux(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) struct net *net = dev_net(skb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) const struct udphdr *uh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) struct dst_entry *dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) int dif = skb->dev->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) int sdif = inet6_sdif(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) if (!pskb_may_pull(skb, skb_transport_offset(skb) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) sizeof(struct udphdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) uh = udp_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) if (skb->pkt_type == PACKET_HOST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) sk = __udp6_lib_demux_lookup(net, uh->dest,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) &ipv6_hdr(skb)->daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) uh->source, &ipv6_hdr(skb)->saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) dif, sdif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) if (!sk || !refcount_inc_not_zero(&sk->sk_refcnt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) skb->sk = sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) skb->destructor = sock_efree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) dst = READ_ONCE(sk->sk_rx_dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) if (dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) dst = dst_check(dst, inet6_sk(sk)->rx_dst_cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) if (dst) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) /* set noref for now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) * any place which wants to hold dst has to call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) * dst_hold_safe()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) skb_dst_set_noref(skb, dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) INDIRECT_CALLABLE_SCOPE int udpv6_rcv(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) return __udp6_lib_rcv(skb, &udp_table, IPPROTO_UDP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) * Throw away all pending data and cancel the corking. Socket is locked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) static void udp_v6_flush_pending_frames(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) struct udp_sock *up = udp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) if (up->pending == AF_INET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) udp_flush_pending_frames(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) else if (up->pending) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) up->len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) up->pending = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) ip6_flush_pending_frames(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) static int udpv6_pre_connect(struct sock *sk, struct sockaddr *uaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) int addr_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) if (addr_len < offsetofend(struct sockaddr, sa_family))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) /* The following checks are replicated from __ip6_datagram_connect()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) * and intended to prevent BPF program called below from accessing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) * bytes that are out of the bound specified by user in addr_len.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) if (uaddr->sa_family == AF_INET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) if (__ipv6_only_sock(sk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) return -EAFNOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) return udp_pre_connect(sk, uaddr, addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) if (addr_len < SIN6_LEN_RFC2133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) return BPF_CGROUP_RUN_PROG_INET6_CONNECT_LOCK(sk, uaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) * udp6_hwcsum_outgoing - handle outgoing HW checksumming
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) * @sk: socket we are sending on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) * @skb: sk_buff containing the filled-in UDP header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) * (checksum field must be zeroed out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) * @saddr: source address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) * @daddr: destination address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) * @len: length of packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) static void udp6_hwcsum_outgoing(struct sock *sk, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) const struct in6_addr *saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) const struct in6_addr *daddr, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) unsigned int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) struct udphdr *uh = udp_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) struct sk_buff *frags = skb_shinfo(skb)->frag_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) __wsum csum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) if (!frags) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) /* Only one fragment on the socket. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) skb->csum_start = skb_transport_header(skb) - skb->head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) skb->csum_offset = offsetof(struct udphdr, check);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) uh->check = ~csum_ipv6_magic(saddr, daddr, len, IPPROTO_UDP, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) * HW-checksum won't work as there are two or more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) * fragments on the socket so that all csums of sk_buffs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) * should be together
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) offset = skb_transport_offset(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) skb->csum = skb_checksum(skb, offset, skb->len - offset, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) csum = skb->csum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) skb->ip_summed = CHECKSUM_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) csum = csum_add(csum, frags->csum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) } while ((frags = frags->next));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) uh->check = csum_ipv6_magic(saddr, daddr, len, IPPROTO_UDP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) csum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) if (uh->check == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) uh->check = CSUM_MANGLED_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) * Sending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) static int udp_v6_send_skb(struct sk_buff *skb, struct flowi6 *fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) struct inet_cork *cork)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) struct sock *sk = skb->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) struct udphdr *uh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) int is_udplite = IS_UDPLITE(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) __wsum csum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) int offset = skb_transport_offset(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) int len = skb->len - offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) int datalen = len - sizeof(*uh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) * Create a UDP header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) uh = udp_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) uh->source = fl6->fl6_sport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) uh->dest = fl6->fl6_dport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) uh->len = htons(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) uh->check = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) if (cork->gso_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) const int hlen = skb_network_header_len(skb) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) sizeof(struct udphdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) if (hlen + cork->gso_size > cork->fragsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) if (datalen > cork->gso_size * UDP_MAX_SEGMENTS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) if (udp_sk(sk)->no_check6_tx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) if (skb->ip_summed != CHECKSUM_PARTIAL || is_udplite ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) dst_xfrm(skb_dst(skb))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) if (datalen > cork->gso_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) skb_shinfo(skb)->gso_size = cork->gso_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) skb_shinfo(skb)->gso_type = SKB_GSO_UDP_L4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(datalen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) cork->gso_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) goto csum_partial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) if (is_udplite)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) csum = udplite_csum(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) else if (udp_sk(sk)->no_check6_tx) { /* UDP csum disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) skb->ip_summed = CHECKSUM_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) goto send;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) } else if (skb->ip_summed == CHECKSUM_PARTIAL) { /* UDP hardware csum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) csum_partial:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) udp6_hwcsum_outgoing(sk, skb, &fl6->saddr, &fl6->daddr, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) goto send;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) csum = udp_csum(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) /* add protocol-dependent pseudo-header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) uh->check = csum_ipv6_magic(&fl6->saddr, &fl6->daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) len, fl6->flowi6_proto, csum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) if (uh->check == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) uh->check = CSUM_MANGLED_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) send:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) err = ip6_send_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) if (err == -ENOBUFS && !inet6_sk(sk)->recverr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) UDP6_INC_STATS(sock_net(sk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) UDP_MIB_SNDBUFERRORS, is_udplite);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) UDP6_INC_STATS(sock_net(sk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) UDP_MIB_OUTDATAGRAMS, is_udplite);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) static int udp_v6_push_pending_frames(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) struct udp_sock *up = udp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) struct flowi6 fl6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) if (up->pending == AF_INET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) return udp_push_pending_frames(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) /* ip6_finish_skb will release the cork, so make a copy of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) * fl6 here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) fl6 = inet_sk(sk)->cork.fl.u.ip6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) skb = ip6_finish_skb(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) err = udp_v6_send_skb(skb, &fl6, &inet_sk(sk)->cork.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) up->len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) up->pending = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) struct ipv6_txoptions opt_space;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) struct udp_sock *up = udp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) struct inet_sock *inet = inet_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) struct ipv6_pinfo *np = inet6_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) DECLARE_SOCKADDR(struct sockaddr_in6 *, sin6, msg->msg_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) struct in6_addr *daddr, *final_p, final;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) struct ipv6_txoptions *opt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) struct ipv6_txoptions *opt_to_free = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) struct ip6_flowlabel *flowlabel = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) struct flowi6 fl6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) struct dst_entry *dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) struct ipcm6_cookie ipc6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) int addr_len = msg->msg_namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) bool connected = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) int ulen = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) int corkreq = READ_ONCE(up->corkflag) || msg->msg_flags&MSG_MORE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) int is_udplite = IS_UDPLITE(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) int (*getfrag)(void *, char *, int, int, int, struct sk_buff *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) ipcm6_init(&ipc6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) ipc6.gso_size = READ_ONCE(up->gso_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) ipc6.sockc.tsflags = sk->sk_tsflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) ipc6.sockc.mark = sk->sk_mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) /* destination address check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) if (sin6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) if (addr_len < offsetof(struct sockaddr, sa_data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) switch (sin6->sin6_family) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) case AF_INET6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) if (addr_len < SIN6_LEN_RFC2133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) daddr = &sin6->sin6_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) if (ipv6_addr_any(daddr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) ipv6_addr_v4mapped(&np->saddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) ipv6_addr_set_v4mapped(htonl(INADDR_LOOPBACK),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) case AF_INET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) goto do_udp_sendmsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) case AF_UNSPEC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) msg->msg_name = sin6 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) msg->msg_namelen = addr_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) daddr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) } else if (!up->pending) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) if (sk->sk_state != TCP_ESTABLISHED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) return -EDESTADDRREQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) daddr = &sk->sk_v6_daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) daddr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) if (daddr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) if (ipv6_addr_v4mapped(daddr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) struct sockaddr_in sin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) sin.sin_family = AF_INET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) sin.sin_port = sin6 ? sin6->sin6_port : inet->inet_dport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) sin.sin_addr.s_addr = daddr->s6_addr32[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) msg->msg_name = &sin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) msg->msg_namelen = sizeof(sin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) do_udp_sendmsg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) if (__ipv6_only_sock(sk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) return -ENETUNREACH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) return udp_sendmsg(sk, msg, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) if (up->pending == AF_INET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) return udp_sendmsg(sk, msg, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) /* Rough check on arithmetic overflow,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) better check is made in ip6_append_data().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) if (len > INT_MAX - sizeof(struct udphdr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) getfrag = is_udplite ? udplite_getfrag : ip_generic_getfrag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) if (up->pending) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) * There are pending frames.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) * The socket lock must be held while it's corked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) if (likely(up->pending)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) if (unlikely(up->pending != AF_INET6)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) return -EAFNOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) dst = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) goto do_append_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) ulen += sizeof(struct udphdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) memset(&fl6, 0, sizeof(fl6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) if (sin6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) if (sin6->sin6_port == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) fl6.fl6_dport = sin6->sin6_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) daddr = &sin6->sin6_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) if (np->sndflow) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) fl6.flowlabel = sin6->sin6_flowinfo&IPV6_FLOWINFO_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) if (fl6.flowlabel&IPV6_FLOWLABEL_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) flowlabel = fl6_sock_lookup(sk, fl6.flowlabel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) if (IS_ERR(flowlabel))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) * Otherwise it will be difficult to maintain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) * sk->sk_dst_cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) if (sk->sk_state == TCP_ESTABLISHED &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) ipv6_addr_equal(daddr, &sk->sk_v6_daddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) daddr = &sk->sk_v6_daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) if (addr_len >= sizeof(struct sockaddr_in6) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) sin6->sin6_scope_id &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) __ipv6_addr_needs_scope_id(__ipv6_addr_type(daddr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) fl6.flowi6_oif = sin6->sin6_scope_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) if (sk->sk_state != TCP_ESTABLISHED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) return -EDESTADDRREQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) fl6.fl6_dport = inet->inet_dport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) daddr = &sk->sk_v6_daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) fl6.flowlabel = np->flow_label;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) connected = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) if (!fl6.flowi6_oif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) fl6.flowi6_oif = sk->sk_bound_dev_if;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) if (!fl6.flowi6_oif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) fl6.flowi6_oif = np->sticky_pktinfo.ipi6_ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) fl6.flowi6_uid = sk->sk_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) if (msg->msg_controllen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) opt = &opt_space;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) memset(opt, 0, sizeof(struct ipv6_txoptions));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) opt->tot_len = sizeof(*opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) ipc6.opt = opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) err = udp_cmsg_send(sk, msg, &ipc6.gso_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) if (err > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) err = ip6_datagram_send_ctl(sock_net(sk), sk, msg, &fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) &ipc6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) fl6_sock_release(flowlabel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) if ((fl6.flowlabel&IPV6_FLOWLABEL_MASK) && !flowlabel) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) flowlabel = fl6_sock_lookup(sk, fl6.flowlabel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) if (IS_ERR(flowlabel))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) if (!(opt->opt_nflen|opt->opt_flen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) opt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) connected = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) if (!opt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) opt = txopt_get(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) opt_to_free = opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) if (flowlabel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) opt = fl6_merge_options(&opt_space, flowlabel, opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) opt = ipv6_fixup_options(&opt_space, opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) ipc6.opt = opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) fl6.flowi6_proto = sk->sk_protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) fl6.flowi6_mark = ipc6.sockc.mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) fl6.daddr = *daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) if (ipv6_addr_any(&fl6.saddr) && !ipv6_addr_any(&np->saddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) fl6.saddr = np->saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) fl6.fl6_sport = inet->inet_sport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) if (cgroup_bpf_enabled && !connected) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) err = BPF_CGROUP_RUN_PROG_UDP6_SENDMSG_LOCK(sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) (struct sockaddr *)sin6, &fl6.saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) goto out_no_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) if (sin6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) if (ipv6_addr_v4mapped(&sin6->sin6_addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) /* BPF program rewrote IPv6-only by IPv4-mapped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) * IPv6. It's currently unsupported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) err = -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) goto out_no_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) if (sin6->sin6_port == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) /* BPF program set invalid port. Reject it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) goto out_no_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) fl6.fl6_dport = sin6->sin6_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) fl6.daddr = sin6->sin6_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) if (ipv6_addr_any(&fl6.daddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) fl6.daddr.s6_addr[15] = 0x1; /* :: means loopback (BSD'ism) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) final_p = fl6_update_dst(&fl6, opt, &final);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) if (final_p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) connected = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) if (!fl6.flowi6_oif && ipv6_addr_is_multicast(&fl6.daddr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) fl6.flowi6_oif = np->mcast_oif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) connected = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) } else if (!fl6.flowi6_oif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) fl6.flowi6_oif = np->ucast_oif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) security_sk_classify_flow(sk, flowi6_to_flowi(&fl6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) if (ipc6.tclass < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) ipc6.tclass = np->tclass;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) fl6.flowlabel = ip6_make_flowinfo(ipc6.tclass, fl6.flowlabel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) dst = ip6_sk_dst_lookup_flow(sk, &fl6, final_p, connected);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) if (IS_ERR(dst)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) err = PTR_ERR(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) dst = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) if (ipc6.hlimit < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) ipc6.hlimit = ip6_sk_dst_hoplimit(np, &fl6, dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) if (msg->msg_flags&MSG_CONFIRM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) goto do_confirm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) back_from_confirm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) /* Lockless fast path for the non-corking case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) if (!corkreq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) struct inet_cork_full cork;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) skb = ip6_make_skb(sk, getfrag, msg, ulen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) sizeof(struct udphdr), &ipc6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) &fl6, (struct rt6_info *)dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) msg->msg_flags, &cork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) err = PTR_ERR(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) if (!IS_ERR_OR_NULL(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) err = udp_v6_send_skb(skb, &fl6, &cork.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) if (unlikely(up->pending)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) /* The socket is already corked while preparing it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) /* ... which is an evident application bug. --ANK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) net_dbg_ratelimited("udp cork app bug 2\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) up->pending = AF_INET6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) do_append_data:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) if (ipc6.dontfrag < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) ipc6.dontfrag = np->dontfrag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) up->len += ulen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) err = ip6_append_data(sk, getfrag, msg, ulen, sizeof(struct udphdr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) &ipc6, &fl6, (struct rt6_info *)dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) corkreq ? msg->msg_flags|MSG_MORE : msg->msg_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) udp_v6_flush_pending_frames(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) else if (!corkreq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) err = udp_v6_push_pending_frames(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) else if (unlikely(skb_queue_empty(&sk->sk_write_queue)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) up->pending = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) if (err > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) err = np->recverr ? net_xmit_errno(err) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) dst_release(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) out_no_dst:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) fl6_sock_release(flowlabel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) txopt_put(opt_to_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) * ENOBUFS = no kernel mem, SOCK_NOSPACE = no sndbuf space. Reporting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) * ENOBUFS might not be good (it's not tunable per se), but otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) * we don't have a good statistic (IpOutDiscards but it can be too many
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) * things). We could add another new stat but at least for now that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) * seems like overkill.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) if (err == -ENOBUFS || test_bit(SOCK_NOSPACE, &sk->sk_socket->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) UDP6_INC_STATS(sock_net(sk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) UDP_MIB_SNDBUFERRORS, is_udplite);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) do_confirm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) if (msg->msg_flags & MSG_PROBE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) dst_confirm_neigh(dst, &fl6.daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) if (!(msg->msg_flags&MSG_PROBE) || len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) goto back_from_confirm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) void udpv6_destroy_sock(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) struct udp_sock *up = udp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) /* protects from races with udp_abort() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) sock_set_flag(sk, SOCK_DEAD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) udp_v6_flush_pending_frames(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) if (static_branch_unlikely(&udpv6_encap_needed_key)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) if (up->encap_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) void (*encap_destroy)(struct sock *sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) encap_destroy = READ_ONCE(up->encap_destroy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) if (encap_destroy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) encap_destroy(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) if (up->encap_enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) static_branch_dec(&udpv6_encap_needed_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) udp_encap_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) inet6_destroy_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) * Socket option code for UDP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) int udpv6_setsockopt(struct sock *sk, int level, int optname, sockptr_t optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) if (level == SOL_UDP || level == SOL_UDPLITE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) return udp_lib_setsockopt(sk, level, optname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) optval, optlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) udp_v6_push_pending_frames);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) return ipv6_setsockopt(sk, level, optname, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) int udpv6_getsockopt(struct sock *sk, int level, int optname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) if (level == SOL_UDP || level == SOL_UDPLITE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) return udp_lib_getsockopt(sk, level, optname, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) return ipv6_getsockopt(sk, level, optname, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) /* thinking of making this const? Don't.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) * early_demux can change based on sysctl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) static struct inet6_protocol udpv6_protocol = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) .early_demux = udp_v6_early_demux,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) .early_demux_handler = udp_v6_early_demux,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) .handler = udpv6_rcv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) .err_handler = udpv6_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) /* ------------------------------------------------------------------------ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) int udp6_seq_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) if (v == SEQ_START_TOKEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) seq_puts(seq, IPV6_SEQ_DGRAM_HEADER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) int bucket = ((struct udp_iter_state *)seq->private)->bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) struct inet_sock *inet = inet_sk(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) __u16 srcp = ntohs(inet->inet_sport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) __u16 destp = ntohs(inet->inet_dport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) __ip6_dgram_sock_seq_show(seq, v, srcp, destp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) udp_rqueue_get(v), bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) const struct seq_operations udp6_seq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) .start = udp_seq_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) .next = udp_seq_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) .stop = udp_seq_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) .show = udp6_seq_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) EXPORT_SYMBOL(udp6_seq_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) static struct udp_seq_afinfo udp6_seq_afinfo = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) .family = AF_INET6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) .udp_table = &udp_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) int __net_init udp6_proc_init(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) if (!proc_create_net_data("udp6", 0444, net->proc_net, &udp6_seq_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) sizeof(struct udp_iter_state), &udp6_seq_afinfo))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) void udp6_proc_exit(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) remove_proc_entry("udp6", net->proc_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) #endif /* CONFIG_PROC_FS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) /* ------------------------------------------------------------------------ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) struct proto udpv6_prot = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) .name = "UDPv6",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) .close = udp_lib_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) .pre_connect = udpv6_pre_connect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) .connect = ip6_datagram_connect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) .disconnect = udp_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) .ioctl = udp_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) .init = udp_init_sock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) .destroy = udpv6_destroy_sock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) .setsockopt = udpv6_setsockopt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) .getsockopt = udpv6_getsockopt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) .sendmsg = udpv6_sendmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) .recvmsg = udpv6_recvmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) .release_cb = ip6_datagram_release_cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) .hash = udp_lib_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) .unhash = udp_lib_unhash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) .rehash = udp_v6_rehash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) .get_port = udp_v6_get_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) .memory_allocated = &udp_memory_allocated,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) .sysctl_mem = sysctl_udp_mem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) .sysctl_wmem_offset = offsetof(struct net, ipv4.sysctl_udp_wmem_min),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) .sysctl_rmem_offset = offsetof(struct net, ipv4.sysctl_udp_rmem_min),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) .obj_size = sizeof(struct udp6_sock),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) .h.udp_table = &udp_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) .diag_destroy = udp_abort,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) static struct inet_protosw udpv6_protosw = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) .type = SOCK_DGRAM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) .protocol = IPPROTO_UDP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) .prot = &udpv6_prot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) .ops = &inet6_dgram_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) .flags = INET_PROTOSW_PERMANENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) int __init udpv6_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) ret = inet6_add_protocol(&udpv6_protocol, IPPROTO_UDP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) ret = inet6_register_protosw(&udpv6_protosw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) goto out_udpv6_protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) out_udpv6_protocol:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) inet6_del_protocol(&udpv6_protocol, IPPROTO_UDP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) void udpv6_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) inet6_unregister_protosw(&udpv6_protosw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) inet6_del_protocol(&udpv6_protocol, IPPROTO_UDP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) }