LCOV - code coverage report
Current view: top level - net/ipv6 - udp.c (source / functions) Hit Total Coverage
Test: gcov_data_raspi2_real_modules_combined.info Lines: 257 636 40.4 %
Date: 2020-09-30 20:25:40 Functions: 19 40 47.5 %
Branches: 132 590 22.4 %

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

Generated by: LCOV version 1.14