1db8dac20SDavid S. Miller /* 2db8dac20SDavid S. Miller * UDP over IPv6 3db8dac20SDavid S. Miller * Linux INET6 implementation 4db8dac20SDavid S. Miller * 5db8dac20SDavid S. Miller * Authors: 6db8dac20SDavid S. Miller * Pedro Roque <roque@di.fc.ul.pt> 7db8dac20SDavid S. Miller * 8db8dac20SDavid S. Miller * Based on linux/ipv4/udp.c 9db8dac20SDavid S. Miller * 10db8dac20SDavid S. Miller * Fixes: 11db8dac20SDavid S. Miller * Hideaki YOSHIFUJI : sin6_scope_id support 12db8dac20SDavid S. Miller * YOSHIFUJI Hideaki @USAGI and: Support IPV6_V6ONLY socket option, which 13db8dac20SDavid S. Miller * Alexey Kuznetsov allow both IPv4 and IPv6 sockets to bind 14db8dac20SDavid S. Miller * a single port at the same time. 15db8dac20SDavid S. Miller * Kazunori MIYAZAWA @USAGI: change process style to use ip6_append_data 16db8dac20SDavid S. Miller * YOSHIFUJI Hideaki @USAGI: convert /proc/net/udp6 to seq_file. 17db8dac20SDavid S. Miller * 18db8dac20SDavid S. Miller * This program is free software; you can redistribute it and/or 19db8dac20SDavid S. Miller * modify it under the terms of the GNU General Public License 20db8dac20SDavid S. Miller * as published by the Free Software Foundation; either version 21db8dac20SDavid S. Miller * 2 of the License, or (at your option) any later version. 22db8dac20SDavid S. Miller */ 23db8dac20SDavid S. Miller 24db8dac20SDavid S. Miller #include <linux/errno.h> 25db8dac20SDavid S. Miller #include <linux/types.h> 26db8dac20SDavid S. Miller #include <linux/socket.h> 27db8dac20SDavid S. Miller #include <linux/sockios.h> 28db8dac20SDavid S. Miller #include <linux/net.h> 29db8dac20SDavid S. Miller #include <linux/in6.h> 30db8dac20SDavid S. Miller #include <linux/netdevice.h> 31db8dac20SDavid S. Miller #include <linux/if_arp.h> 32db8dac20SDavid S. Miller #include <linux/ipv6.h> 33db8dac20SDavid S. Miller #include <linux/icmpv6.h> 34db8dac20SDavid S. Miller #include <linux/init.h> 35db8dac20SDavid S. Miller #include <linux/module.h> 36db8dac20SDavid S. Miller #include <linux/skbuff.h> 37db8dac20SDavid S. Miller #include <asm/uaccess.h> 38db8dac20SDavid S. Miller 39db8dac20SDavid S. Miller #include <net/ndisc.h> 40db8dac20SDavid S. Miller #include <net/protocol.h> 41db8dac20SDavid S. Miller #include <net/transp_v6.h> 42db8dac20SDavid S. Miller #include <net/ip6_route.h> 43db8dac20SDavid S. Miller #include <net/raw.h> 44db8dac20SDavid S. Miller #include <net/tcp_states.h> 45db8dac20SDavid S. Miller #include <net/ip6_checksum.h> 46db8dac20SDavid S. Miller #include <net/xfrm.h> 47db8dac20SDavid S. Miller 48db8dac20SDavid S. Miller #include <linux/proc_fs.h> 49db8dac20SDavid S. Miller #include <linux/seq_file.h> 50db8dac20SDavid S. Miller #include "udp_impl.h" 51db8dac20SDavid S. Miller 526ba5a3c5SPavel Emelyanov int udp_v6_get_port(struct sock *sk, unsigned short snum) 53db8dac20SDavid S. Miller { 546ba5a3c5SPavel Emelyanov return udp_lib_get_port(sk, snum, ipv6_rcv_saddr_equal); 55db8dac20SDavid S. Miller } 56db8dac20SDavid S. Miller 57645ca708SEric Dumazet static inline int compute_score(struct sock *sk, struct net *net, 58645ca708SEric Dumazet unsigned short hnum, 59db8dac20SDavid S. Miller struct in6_addr *saddr, __be16 sport, 60db8dac20SDavid S. Miller struct in6_addr *daddr, __be16 dport, 61645ca708SEric Dumazet int dif) 62db8dac20SDavid S. Miller { 63645ca708SEric Dumazet int score = -1; 64db8dac20SDavid S. Miller 65878628fbSYOSHIFUJI Hideaki if (net_eq(sock_net(sk), net) && sk->sk_hash == hnum && 66db8dac20SDavid S. Miller sk->sk_family == PF_INET6) { 67db8dac20SDavid S. Miller struct ipv6_pinfo *np = inet6_sk(sk); 68645ca708SEric Dumazet struct inet_sock *inet = inet_sk(sk); 69645ca708SEric Dumazet 70645ca708SEric Dumazet score = 0; 71db8dac20SDavid S. Miller if (inet->dport) { 72db8dac20SDavid S. Miller if (inet->dport != sport) 73645ca708SEric Dumazet return -1; 74db8dac20SDavid S. Miller score++; 75db8dac20SDavid S. Miller } 76db8dac20SDavid S. Miller if (!ipv6_addr_any(&np->rcv_saddr)) { 77db8dac20SDavid S. Miller if (!ipv6_addr_equal(&np->rcv_saddr, daddr)) 78645ca708SEric Dumazet return -1; 79db8dac20SDavid S. Miller score++; 80db8dac20SDavid S. Miller } 81db8dac20SDavid S. Miller if (!ipv6_addr_any(&np->daddr)) { 82db8dac20SDavid S. Miller if (!ipv6_addr_equal(&np->daddr, saddr)) 83645ca708SEric Dumazet return -1; 84db8dac20SDavid S. Miller score++; 85db8dac20SDavid S. Miller } 86db8dac20SDavid S. Miller if (sk->sk_bound_dev_if) { 87db8dac20SDavid S. Miller if (sk->sk_bound_dev_if != dif) 88645ca708SEric Dumazet return -1; 89db8dac20SDavid S. Miller score++; 90db8dac20SDavid S. Miller } 91645ca708SEric Dumazet } 92645ca708SEric Dumazet return score; 93645ca708SEric Dumazet } 94645ca708SEric Dumazet 95645ca708SEric Dumazet static struct sock *__udp6_lib_lookup(struct net *net, 96645ca708SEric Dumazet struct in6_addr *saddr, __be16 sport, 97645ca708SEric Dumazet struct in6_addr *daddr, __be16 dport, 98645ca708SEric Dumazet int dif, struct udp_table *udptable) 99645ca708SEric Dumazet { 100271b72c7SEric Dumazet struct sock *sk, *result; 10188ab1932SEric Dumazet struct hlist_nulls_node *node; 102645ca708SEric Dumazet unsigned short hnum = ntohs(dport); 103645ca708SEric Dumazet unsigned int hash = udp_hashfn(net, hnum); 104645ca708SEric Dumazet struct udp_hslot *hslot = &udptable->hash[hash]; 105271b72c7SEric Dumazet int score, badness; 106645ca708SEric Dumazet 107271b72c7SEric Dumazet rcu_read_lock(); 108271b72c7SEric Dumazet begin: 109271b72c7SEric Dumazet result = NULL; 110271b72c7SEric Dumazet badness = -1; 11188ab1932SEric Dumazet sk_nulls_for_each_rcu(sk, node, &hslot->head) { 112645ca708SEric Dumazet score = compute_score(sk, net, hnum, saddr, sport, daddr, dport, dif); 113645ca708SEric Dumazet if (score > badness) { 114db8dac20SDavid S. Miller result = sk; 115db8dac20SDavid S. Miller badness = score; 116db8dac20SDavid S. Miller } 117db8dac20SDavid S. Miller } 11888ab1932SEric Dumazet /* 11988ab1932SEric Dumazet * if the nulls value we got at the end of this lookup is 12088ab1932SEric Dumazet * not the expected one, we must restart lookup. 12188ab1932SEric Dumazet * We probably met an item that was moved to another chain. 12288ab1932SEric Dumazet */ 12388ab1932SEric Dumazet if (get_nulls_value(node) != hash) 12488ab1932SEric Dumazet goto begin; 12588ab1932SEric Dumazet 126271b72c7SEric Dumazet if (result) { 127271b72c7SEric Dumazet if (unlikely(!atomic_inc_not_zero(&result->sk_refcnt))) 128271b72c7SEric Dumazet result = NULL; 129271b72c7SEric Dumazet else if (unlikely(compute_score(result, net, hnum, saddr, sport, 130271b72c7SEric Dumazet daddr, dport, dif) < badness)) { 131271b72c7SEric Dumazet sock_put(result); 132271b72c7SEric Dumazet goto begin; 133271b72c7SEric Dumazet } 134271b72c7SEric Dumazet } 135271b72c7SEric Dumazet rcu_read_unlock(); 136db8dac20SDavid S. Miller return result; 137db8dac20SDavid S. Miller } 138db8dac20SDavid S. Miller 139607c4aafSKOVACS Krisztian static struct sock *__udp6_lib_lookup_skb(struct sk_buff *skb, 140607c4aafSKOVACS Krisztian __be16 sport, __be16 dport, 141645ca708SEric Dumazet struct udp_table *udptable) 142607c4aafSKOVACS Krisztian { 14323542618SKOVACS Krisztian struct sock *sk; 144607c4aafSKOVACS Krisztian struct ipv6hdr *iph = ipv6_hdr(skb); 145607c4aafSKOVACS Krisztian 14623542618SKOVACS Krisztian if (unlikely(sk = skb_steal_sock(skb))) 14723542618SKOVACS Krisztian return sk; 14823542618SKOVACS Krisztian else 149607c4aafSKOVACS Krisztian return __udp6_lib_lookup(dev_net(skb->dst->dev), &iph->saddr, sport, 150607c4aafSKOVACS Krisztian &iph->daddr, dport, inet6_iif(skb), 151607c4aafSKOVACS Krisztian udptable); 152607c4aafSKOVACS Krisztian } 153607c4aafSKOVACS Krisztian 154db8dac20SDavid S. Miller /* 155db8dac20SDavid S. Miller * This should be easy, if there is something there we 156db8dac20SDavid S. Miller * return it, otherwise we block. 157db8dac20SDavid S. Miller */ 158db8dac20SDavid S. Miller 159db8dac20SDavid S. Miller int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk, 160db8dac20SDavid S. Miller struct msghdr *msg, size_t len, 161db8dac20SDavid S. Miller int noblock, int flags, int *addr_len) 162db8dac20SDavid S. Miller { 163db8dac20SDavid S. Miller struct ipv6_pinfo *np = inet6_sk(sk); 164db8dac20SDavid S. Miller struct inet_sock *inet = inet_sk(sk); 165db8dac20SDavid S. Miller struct sk_buff *skb; 166db8dac20SDavid S. Miller unsigned int ulen, copied; 167db8dac20SDavid S. Miller int peeked; 168db8dac20SDavid S. Miller int err; 169db8dac20SDavid S. Miller int is_udplite = IS_UDPLITE(sk); 170f26ba175SWei Yongjun int is_udp4; 171db8dac20SDavid S. Miller 172db8dac20SDavid S. Miller if (addr_len) 173db8dac20SDavid S. Miller *addr_len=sizeof(struct sockaddr_in6); 174db8dac20SDavid S. Miller 175db8dac20SDavid S. Miller if (flags & MSG_ERRQUEUE) 176db8dac20SDavid S. Miller return ipv6_recv_error(sk, msg, len); 177db8dac20SDavid S. Miller 178db8dac20SDavid S. Miller try_again: 179db8dac20SDavid S. Miller skb = __skb_recv_datagram(sk, flags | (noblock ? MSG_DONTWAIT : 0), 180db8dac20SDavid S. Miller &peeked, &err); 181db8dac20SDavid S. Miller if (!skb) 182db8dac20SDavid S. Miller goto out; 183db8dac20SDavid S. Miller 184db8dac20SDavid S. Miller ulen = skb->len - sizeof(struct udphdr); 185db8dac20SDavid S. Miller copied = len; 186db8dac20SDavid S. Miller if (copied > ulen) 187db8dac20SDavid S. Miller copied = ulen; 188db8dac20SDavid S. Miller else if (copied < ulen) 189db8dac20SDavid S. Miller msg->msg_flags |= MSG_TRUNC; 190db8dac20SDavid S. Miller 191f26ba175SWei Yongjun is_udp4 = (skb->protocol == htons(ETH_P_IP)); 192f26ba175SWei Yongjun 193db8dac20SDavid S. Miller /* 194db8dac20SDavid S. Miller * If checksum is needed at all, try to do it while copying the 195db8dac20SDavid S. Miller * data. If the data is truncated, or if we only want a partial 196db8dac20SDavid S. Miller * coverage checksum (UDP-Lite), do it before the copy. 197db8dac20SDavid S. Miller */ 198db8dac20SDavid S. Miller 199db8dac20SDavid S. Miller if (copied < ulen || UDP_SKB_CB(skb)->partial_cov) { 200db8dac20SDavid S. Miller if (udp_lib_checksum_complete(skb)) 201db8dac20SDavid S. Miller goto csum_copy_err; 202db8dac20SDavid S. Miller } 203db8dac20SDavid S. Miller 204db8dac20SDavid S. Miller if (skb_csum_unnecessary(skb)) 205db8dac20SDavid S. Miller err = skb_copy_datagram_iovec(skb, sizeof(struct udphdr), 206db8dac20SDavid S. Miller msg->msg_iov, copied ); 207db8dac20SDavid S. Miller else { 208db8dac20SDavid S. Miller err = skb_copy_and_csum_datagram_iovec(skb, sizeof(struct udphdr), msg->msg_iov); 209db8dac20SDavid S. Miller if (err == -EINVAL) 210db8dac20SDavid S. Miller goto csum_copy_err; 211db8dac20SDavid S. Miller } 212db8dac20SDavid S. Miller if (err) 213db8dac20SDavid S. Miller goto out_free; 214db8dac20SDavid S. Miller 215f26ba175SWei Yongjun if (!peeked) { 216f26ba175SWei Yongjun if (is_udp4) 217f26ba175SWei Yongjun UDP_INC_STATS_USER(sock_net(sk), 218f26ba175SWei Yongjun UDP_MIB_INDATAGRAMS, is_udplite); 219f26ba175SWei Yongjun else 220235b9f7aSPavel Emelyanov UDP6_INC_STATS_USER(sock_net(sk), 221235b9f7aSPavel Emelyanov UDP_MIB_INDATAGRAMS, is_udplite); 222f26ba175SWei Yongjun } 223db8dac20SDavid S. Miller 224db8dac20SDavid S. Miller sock_recv_timestamp(msg, sk, skb); 225db8dac20SDavid S. Miller 226db8dac20SDavid S. Miller /* Copy the address. */ 227db8dac20SDavid S. Miller if (msg->msg_name) { 228db8dac20SDavid S. Miller struct sockaddr_in6 *sin6; 229db8dac20SDavid S. Miller 230db8dac20SDavid S. Miller sin6 = (struct sockaddr_in6 *) msg->msg_name; 231db8dac20SDavid S. Miller sin6->sin6_family = AF_INET6; 232db8dac20SDavid S. Miller sin6->sin6_port = udp_hdr(skb)->source; 233db8dac20SDavid S. Miller sin6->sin6_flowinfo = 0; 234db8dac20SDavid S. Miller sin6->sin6_scope_id = 0; 235db8dac20SDavid S. Miller 236f26ba175SWei Yongjun if (is_udp4) 237db8dac20SDavid S. Miller ipv6_addr_set(&sin6->sin6_addr, 0, 0, 238db8dac20SDavid S. Miller htonl(0xffff), ip_hdr(skb)->saddr); 239db8dac20SDavid S. Miller else { 240db8dac20SDavid S. Miller ipv6_addr_copy(&sin6->sin6_addr, 241db8dac20SDavid S. Miller &ipv6_hdr(skb)->saddr); 242db8dac20SDavid S. Miller if (ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL) 243db8dac20SDavid S. Miller sin6->sin6_scope_id = IP6CB(skb)->iif; 244db8dac20SDavid S. Miller } 245db8dac20SDavid S. Miller 246db8dac20SDavid S. Miller } 247f26ba175SWei Yongjun if (is_udp4) { 248db8dac20SDavid S. Miller if (inet->cmsg_flags) 249db8dac20SDavid S. Miller ip_cmsg_recv(msg, skb); 250db8dac20SDavid S. Miller } else { 251db8dac20SDavid S. Miller if (np->rxopt.all) 252db8dac20SDavid S. Miller datagram_recv_ctl(sk, msg, skb); 253db8dac20SDavid S. Miller } 254db8dac20SDavid S. Miller 255db8dac20SDavid S. Miller err = copied; 256db8dac20SDavid S. Miller if (flags & MSG_TRUNC) 257db8dac20SDavid S. Miller err = ulen; 258db8dac20SDavid S. Miller 259db8dac20SDavid S. Miller out_free: 260db8dac20SDavid S. Miller lock_sock(sk); 261db8dac20SDavid S. Miller skb_free_datagram(sk, skb); 262db8dac20SDavid S. Miller release_sock(sk); 263db8dac20SDavid S. Miller out: 264db8dac20SDavid S. Miller return err; 265db8dac20SDavid S. Miller 266db8dac20SDavid S. Miller csum_copy_err: 267db8dac20SDavid S. Miller lock_sock(sk); 2680856f939SWei Yongjun if (!skb_kill_datagram(sk, skb, flags)) { 2690856f939SWei Yongjun if (is_udp4) 2700856f939SWei Yongjun UDP_INC_STATS_USER(sock_net(sk), 2710856f939SWei Yongjun UDP_MIB_INERRORS, is_udplite); 2720856f939SWei Yongjun else 2730856f939SWei Yongjun UDP6_INC_STATS_USER(sock_net(sk), 2740856f939SWei Yongjun UDP_MIB_INERRORS, is_udplite); 2750856f939SWei Yongjun } 276db8dac20SDavid S. Miller release_sock(sk); 277db8dac20SDavid S. Miller 278db8dac20SDavid S. Miller if (flags & MSG_DONTWAIT) 279db8dac20SDavid S. Miller return -EAGAIN; 280db8dac20SDavid S. Miller goto try_again; 281db8dac20SDavid S. Miller } 282db8dac20SDavid S. Miller 283db8dac20SDavid S. Miller void __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt, 284db8dac20SDavid S. Miller int type, int code, int offset, __be32 info, 285645ca708SEric Dumazet struct udp_table *udptable) 286db8dac20SDavid S. Miller { 287db8dac20SDavid S. Miller struct ipv6_pinfo *np; 288db8dac20SDavid S. Miller struct ipv6hdr *hdr = (struct ipv6hdr*)skb->data; 289db8dac20SDavid S. Miller struct in6_addr *saddr = &hdr->saddr; 290db8dac20SDavid S. Miller struct in6_addr *daddr = &hdr->daddr; 291db8dac20SDavid S. Miller struct udphdr *uh = (struct udphdr*)(skb->data+offset); 292db8dac20SDavid S. Miller struct sock *sk; 293db8dac20SDavid S. Miller int err; 294db8dac20SDavid S. Miller 295c346dca1SYOSHIFUJI Hideaki sk = __udp6_lib_lookup(dev_net(skb->dev), daddr, uh->dest, 296db8dac20SDavid S. Miller saddr, uh->source, inet6_iif(skb), udptable); 297db8dac20SDavid S. Miller if (sk == NULL) 298db8dac20SDavid S. Miller return; 299db8dac20SDavid S. Miller 300db8dac20SDavid S. Miller np = inet6_sk(sk); 301db8dac20SDavid S. Miller 302db8dac20SDavid S. Miller if (!icmpv6_err_convert(type, code, &err) && !np->recverr) 303db8dac20SDavid S. Miller goto out; 304db8dac20SDavid S. Miller 305db8dac20SDavid S. Miller if (sk->sk_state != TCP_ESTABLISHED && !np->recverr) 306db8dac20SDavid S. Miller goto out; 307db8dac20SDavid S. Miller 308db8dac20SDavid S. Miller if (np->recverr) 309db8dac20SDavid S. Miller ipv6_icmp_error(sk, skb, err, uh->dest, ntohl(info), (u8 *)(uh+1)); 310db8dac20SDavid S. Miller 311db8dac20SDavid S. Miller sk->sk_err = err; 312db8dac20SDavid S. Miller sk->sk_error_report(sk); 313db8dac20SDavid S. Miller out: 314db8dac20SDavid S. Miller sock_put(sk); 315db8dac20SDavid S. Miller } 316db8dac20SDavid S. Miller 317db8dac20SDavid S. Miller static __inline__ void udpv6_err(struct sk_buff *skb, 318db8dac20SDavid S. Miller struct inet6_skb_parm *opt, int type, 319db8dac20SDavid S. Miller int code, int offset, __be32 info ) 320db8dac20SDavid S. Miller { 321645ca708SEric Dumazet __udp6_lib_err(skb, opt, type, code, offset, info, &udp_table); 322db8dac20SDavid S. Miller } 323db8dac20SDavid S. Miller 324db8dac20SDavid S. Miller int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb) 325db8dac20SDavid S. Miller { 326db8dac20SDavid S. Miller struct udp_sock *up = udp_sk(sk); 327db8dac20SDavid S. Miller int rc; 328db8dac20SDavid S. Miller int is_udplite = IS_UDPLITE(sk); 329db8dac20SDavid S. Miller 330db8dac20SDavid S. Miller if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) 331db8dac20SDavid S. Miller goto drop; 332db8dac20SDavid S. Miller 333db8dac20SDavid S. Miller /* 334db8dac20SDavid S. Miller * UDP-Lite specific tests, ignored on UDP sockets (see net/ipv4/udp.c). 335db8dac20SDavid S. Miller */ 336db8dac20SDavid S. Miller if ((is_udplite & UDPLITE_RECV_CC) && UDP_SKB_CB(skb)->partial_cov) { 337db8dac20SDavid S. Miller 338db8dac20SDavid S. Miller if (up->pcrlen == 0) { /* full coverage was set */ 339db8dac20SDavid S. Miller LIMIT_NETDEBUG(KERN_WARNING "UDPLITE6: partial coverage" 340db8dac20SDavid S. Miller " %d while full coverage %d requested\n", 341db8dac20SDavid S. Miller UDP_SKB_CB(skb)->cscov, skb->len); 342db8dac20SDavid S. Miller goto drop; 343db8dac20SDavid S. Miller } 344db8dac20SDavid S. Miller if (UDP_SKB_CB(skb)->cscov < up->pcrlen) { 345db8dac20SDavid S. Miller LIMIT_NETDEBUG(KERN_WARNING "UDPLITE6: coverage %d " 346db8dac20SDavid S. Miller "too small, need min %d\n", 347db8dac20SDavid S. Miller UDP_SKB_CB(skb)->cscov, up->pcrlen); 348db8dac20SDavid S. Miller goto drop; 349db8dac20SDavid S. Miller } 350db8dac20SDavid S. Miller } 351db8dac20SDavid S. Miller 352db8dac20SDavid S. Miller if (sk->sk_filter) { 353db8dac20SDavid S. Miller if (udp_lib_checksum_complete(skb)) 354db8dac20SDavid S. Miller goto drop; 355db8dac20SDavid S. Miller } 356db8dac20SDavid S. Miller 357db8dac20SDavid S. Miller if ((rc = sock_queue_rcv_skb(sk,skb)) < 0) { 358db8dac20SDavid S. Miller /* Note that an ENOMEM error is charged twice */ 359cb61cb9bSEric Dumazet if (rc == -ENOMEM) { 360ef28d1a2SPavel Emelyanov UDP6_INC_STATS_BH(sock_net(sk), 361ef28d1a2SPavel Emelyanov UDP_MIB_RCVBUFERRORS, is_udplite); 362cb61cb9bSEric Dumazet atomic_inc(&sk->sk_drops); 363cb61cb9bSEric Dumazet } 364db8dac20SDavid S. Miller goto drop; 365db8dac20SDavid S. Miller } 366db8dac20SDavid S. Miller 367db8dac20SDavid S. Miller return 0; 368db8dac20SDavid S. Miller drop: 369ef28d1a2SPavel Emelyanov UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite); 370db8dac20SDavid S. Miller kfree_skb(skb); 371db8dac20SDavid S. Miller return -1; 372db8dac20SDavid S. Miller } 373db8dac20SDavid S. Miller 374920a4611SEric Dumazet static struct sock *udp_v6_mcast_next(struct net *net, struct sock *sk, 375db8dac20SDavid S. Miller __be16 loc_port, struct in6_addr *loc_addr, 376db8dac20SDavid S. Miller __be16 rmt_port, struct in6_addr *rmt_addr, 377db8dac20SDavid S. Miller int dif) 378db8dac20SDavid S. Miller { 37988ab1932SEric Dumazet struct hlist_nulls_node *node; 380db8dac20SDavid S. Miller struct sock *s = sk; 381db8dac20SDavid S. Miller unsigned short num = ntohs(loc_port); 382db8dac20SDavid S. Miller 38388ab1932SEric Dumazet sk_nulls_for_each_from(s, node) { 384db8dac20SDavid S. Miller struct inet_sock *inet = inet_sk(s); 385db8dac20SDavid S. Miller 386920a4611SEric Dumazet if (!net_eq(sock_net(s), net)) 387b8ad0cbcSDaniel Lezcano continue; 388b8ad0cbcSDaniel Lezcano 389db8dac20SDavid S. Miller if (s->sk_hash == num && s->sk_family == PF_INET6) { 390db8dac20SDavid S. Miller struct ipv6_pinfo *np = inet6_sk(s); 391db8dac20SDavid S. Miller if (inet->dport) { 392db8dac20SDavid S. Miller if (inet->dport != rmt_port) 393db8dac20SDavid S. Miller continue; 394db8dac20SDavid S. Miller } 395db8dac20SDavid S. Miller if (!ipv6_addr_any(&np->daddr) && 396db8dac20SDavid S. Miller !ipv6_addr_equal(&np->daddr, rmt_addr)) 397db8dac20SDavid S. Miller continue; 398db8dac20SDavid S. Miller 399db8dac20SDavid S. Miller if (s->sk_bound_dev_if && s->sk_bound_dev_if != dif) 400db8dac20SDavid S. Miller continue; 401db8dac20SDavid S. Miller 402db8dac20SDavid S. Miller if (!ipv6_addr_any(&np->rcv_saddr)) { 403db8dac20SDavid S. Miller if (!ipv6_addr_equal(&np->rcv_saddr, loc_addr)) 404db8dac20SDavid S. Miller continue; 405db8dac20SDavid S. Miller } 406db8dac20SDavid S. Miller if (!inet6_mc_check(s, loc_addr, rmt_addr)) 407db8dac20SDavid S. Miller continue; 408db8dac20SDavid S. Miller return s; 409db8dac20SDavid S. Miller } 410db8dac20SDavid S. Miller } 411db8dac20SDavid S. Miller return NULL; 412db8dac20SDavid S. Miller } 413db8dac20SDavid S. Miller 414db8dac20SDavid S. Miller /* 415db8dac20SDavid S. Miller * Note: called only from the BH handler context, 416db8dac20SDavid S. Miller * so we don't need to lock the hashes. 417db8dac20SDavid S. Miller */ 418e3163493SPavel Emelyanov static int __udp6_lib_mcast_deliver(struct net *net, struct sk_buff *skb, 419e3163493SPavel Emelyanov struct in6_addr *saddr, struct in6_addr *daddr, 420645ca708SEric Dumazet struct udp_table *udptable) 421db8dac20SDavid S. Miller { 422db8dac20SDavid S. Miller struct sock *sk, *sk2; 423db8dac20SDavid S. Miller const struct udphdr *uh = udp_hdr(skb); 424645ca708SEric Dumazet struct udp_hslot *hslot = &udptable->hash[udp_hashfn(net, ntohs(uh->dest))]; 425db8dac20SDavid S. Miller int dif; 426db8dac20SDavid S. Miller 427645ca708SEric Dumazet spin_lock(&hslot->lock); 42888ab1932SEric Dumazet sk = sk_nulls_head(&hslot->head); 429db8dac20SDavid S. Miller dif = inet6_iif(skb); 430920a4611SEric Dumazet sk = udp_v6_mcast_next(net, sk, uh->dest, daddr, uh->source, saddr, dif); 431db8dac20SDavid S. Miller if (!sk) { 432db8dac20SDavid S. Miller kfree_skb(skb); 433db8dac20SDavid S. Miller goto out; 434db8dac20SDavid S. Miller } 435db8dac20SDavid S. Miller 436db8dac20SDavid S. Miller sk2 = sk; 43788ab1932SEric Dumazet while ((sk2 = udp_v6_mcast_next(net, sk_nulls_next(sk2), uh->dest, daddr, 438db8dac20SDavid S. Miller uh->source, saddr, dif))) { 439db8dac20SDavid S. Miller struct sk_buff *buff = skb_clone(skb, GFP_ATOMIC); 440db8dac20SDavid S. Miller if (buff) { 441d97106eaSHerbert Xu bh_lock_sock(sk2); 442db8dac20SDavid S. Miller if (!sock_owned_by_user(sk2)) 443db8dac20SDavid S. Miller udpv6_queue_rcv_skb(sk2, buff); 444db8dac20SDavid S. Miller else 445db8dac20SDavid S. Miller sk_add_backlog(sk2, buff); 446db8dac20SDavid S. Miller bh_unlock_sock(sk2); 447db8dac20SDavid S. Miller } 448db8dac20SDavid S. Miller } 449d97106eaSHerbert Xu bh_lock_sock(sk); 450db8dac20SDavid S. Miller if (!sock_owned_by_user(sk)) 451db8dac20SDavid S. Miller udpv6_queue_rcv_skb(sk, skb); 452db8dac20SDavid S. Miller else 453db8dac20SDavid S. Miller sk_add_backlog(sk, skb); 454db8dac20SDavid S. Miller bh_unlock_sock(sk); 455db8dac20SDavid S. Miller out: 456645ca708SEric Dumazet spin_unlock(&hslot->lock); 457db8dac20SDavid S. Miller return 0; 458db8dac20SDavid S. Miller } 459db8dac20SDavid S. Miller 460db8dac20SDavid S. Miller static inline int udp6_csum_init(struct sk_buff *skb, struct udphdr *uh, 461db8dac20SDavid S. Miller int proto) 462db8dac20SDavid S. Miller { 463db8dac20SDavid S. Miller int err; 464db8dac20SDavid S. Miller 465db8dac20SDavid S. Miller UDP_SKB_CB(skb)->partial_cov = 0; 466db8dac20SDavid S. Miller UDP_SKB_CB(skb)->cscov = skb->len; 467db8dac20SDavid S. Miller 468db8dac20SDavid S. Miller if (proto == IPPROTO_UDPLITE) { 469db8dac20SDavid S. Miller err = udplite_checksum_init(skb, uh); 470db8dac20SDavid S. Miller if (err) 471db8dac20SDavid S. Miller return err; 472db8dac20SDavid S. Miller } 473db8dac20SDavid S. Miller 474db8dac20SDavid S. Miller if (uh->check == 0) { 475db8dac20SDavid S. Miller /* RFC 2460 section 8.1 says that we SHOULD log 476db8dac20SDavid S. Miller this error. Well, it is reasonable. 477db8dac20SDavid S. Miller */ 478db8dac20SDavid S. Miller LIMIT_NETDEBUG(KERN_INFO "IPv6: udp checksum is 0\n"); 479db8dac20SDavid S. Miller return 1; 480db8dac20SDavid S. Miller } 481db8dac20SDavid S. Miller if (skb->ip_summed == CHECKSUM_COMPLETE && 482db8dac20SDavid S. Miller !csum_ipv6_magic(&ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr, 483db8dac20SDavid S. Miller skb->len, proto, skb->csum)) 484db8dac20SDavid S. Miller skb->ip_summed = CHECKSUM_UNNECESSARY; 485db8dac20SDavid S. Miller 486db8dac20SDavid S. Miller if (!skb_csum_unnecessary(skb)) 487db8dac20SDavid S. Miller skb->csum = ~csum_unfold(csum_ipv6_magic(&ipv6_hdr(skb)->saddr, 488db8dac20SDavid S. Miller &ipv6_hdr(skb)->daddr, 489db8dac20SDavid S. Miller skb->len, proto, 0)); 490db8dac20SDavid S. Miller 491db8dac20SDavid S. Miller return 0; 492db8dac20SDavid S. Miller } 493db8dac20SDavid S. Miller 494645ca708SEric Dumazet int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable, 495db8dac20SDavid S. Miller int proto) 496db8dac20SDavid S. Miller { 497db8dac20SDavid S. Miller struct sock *sk; 498db8dac20SDavid S. Miller struct udphdr *uh; 499db8dac20SDavid S. Miller struct net_device *dev = skb->dev; 500db8dac20SDavid S. Miller struct in6_addr *saddr, *daddr; 501db8dac20SDavid S. Miller u32 ulen = 0; 502ef28d1a2SPavel Emelyanov struct net *net = dev_net(skb->dev); 503db8dac20SDavid S. Miller 504db8dac20SDavid S. Miller if (!pskb_may_pull(skb, sizeof(struct udphdr))) 505db8dac20SDavid S. Miller goto short_packet; 506db8dac20SDavid S. Miller 507db8dac20SDavid S. Miller saddr = &ipv6_hdr(skb)->saddr; 508db8dac20SDavid S. Miller daddr = &ipv6_hdr(skb)->daddr; 509db8dac20SDavid S. Miller uh = udp_hdr(skb); 510db8dac20SDavid S. Miller 511db8dac20SDavid S. Miller ulen = ntohs(uh->len); 512db8dac20SDavid S. Miller if (ulen > skb->len) 513db8dac20SDavid S. Miller goto short_packet; 514db8dac20SDavid S. Miller 515db8dac20SDavid S. Miller if (proto == IPPROTO_UDP) { 516db8dac20SDavid S. Miller /* UDP validates ulen. */ 517db8dac20SDavid S. Miller 518db8dac20SDavid S. Miller /* Check for jumbo payload */ 519db8dac20SDavid S. Miller if (ulen == 0) 520db8dac20SDavid S. Miller ulen = skb->len; 521db8dac20SDavid S. Miller 522db8dac20SDavid S. Miller if (ulen < sizeof(*uh)) 523db8dac20SDavid S. Miller goto short_packet; 524db8dac20SDavid S. Miller 525db8dac20SDavid S. Miller if (ulen < skb->len) { 526db8dac20SDavid S. Miller if (pskb_trim_rcsum(skb, ulen)) 527db8dac20SDavid S. Miller goto short_packet; 528db8dac20SDavid S. Miller saddr = &ipv6_hdr(skb)->saddr; 529db8dac20SDavid S. Miller daddr = &ipv6_hdr(skb)->daddr; 530db8dac20SDavid S. Miller uh = udp_hdr(skb); 531db8dac20SDavid S. Miller } 532db8dac20SDavid S. Miller } 533db8dac20SDavid S. Miller 534db8dac20SDavid S. Miller if (udp6_csum_init(skb, uh, proto)) 535db8dac20SDavid S. Miller goto discard; 536db8dac20SDavid S. Miller 537db8dac20SDavid S. Miller /* 538db8dac20SDavid S. Miller * Multicast receive code 539db8dac20SDavid S. Miller */ 540db8dac20SDavid S. Miller if (ipv6_addr_is_multicast(daddr)) 541e3163493SPavel Emelyanov return __udp6_lib_mcast_deliver(net, skb, 542e3163493SPavel Emelyanov saddr, daddr, udptable); 543db8dac20SDavid S. Miller 544db8dac20SDavid S. Miller /* Unicast */ 545db8dac20SDavid S. Miller 546db8dac20SDavid S. Miller /* 547db8dac20SDavid S. Miller * check socket cache ... must talk to Alan about his plans 548db8dac20SDavid S. Miller * for sock caches... i'll skip this for now. 549db8dac20SDavid S. Miller */ 550607c4aafSKOVACS Krisztian sk = __udp6_lib_lookup_skb(skb, uh->source, uh->dest, udptable); 551db8dac20SDavid S. Miller 552db8dac20SDavid S. Miller if (sk == NULL) { 553db8dac20SDavid S. Miller if (!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) 554db8dac20SDavid S. Miller goto discard; 555db8dac20SDavid S. Miller 556db8dac20SDavid S. Miller if (udp_lib_checksum_complete(skb)) 557db8dac20SDavid S. Miller goto discard; 558ef28d1a2SPavel Emelyanov UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, 559ef28d1a2SPavel Emelyanov proto == IPPROTO_UDPLITE); 560db8dac20SDavid S. Miller 561db8dac20SDavid S. Miller icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0, dev); 562db8dac20SDavid S. Miller 563db8dac20SDavid S. Miller kfree_skb(skb); 564db8dac20SDavid S. Miller return 0; 565db8dac20SDavid S. Miller } 566db8dac20SDavid S. Miller 567db8dac20SDavid S. Miller /* deliver */ 568db8dac20SDavid S. Miller 569d97106eaSHerbert Xu bh_lock_sock(sk); 570db8dac20SDavid S. Miller if (!sock_owned_by_user(sk)) 571db8dac20SDavid S. Miller udpv6_queue_rcv_skb(sk, skb); 572db8dac20SDavid S. Miller else 573db8dac20SDavid S. Miller sk_add_backlog(sk, skb); 574db8dac20SDavid S. Miller bh_unlock_sock(sk); 575db8dac20SDavid S. Miller sock_put(sk); 576db8dac20SDavid S. Miller return 0; 577db8dac20SDavid S. Miller 578db8dac20SDavid S. Miller short_packet: 579db8dac20SDavid S. Miller LIMIT_NETDEBUG(KERN_DEBUG "UDP%sv6: short packet: %d/%u\n", 580db8dac20SDavid S. Miller proto == IPPROTO_UDPLITE ? "-Lite" : "", 581db8dac20SDavid S. Miller ulen, skb->len); 582db8dac20SDavid S. Miller 583db8dac20SDavid S. Miller discard: 584ef28d1a2SPavel Emelyanov UDP6_INC_STATS_BH(net, UDP_MIB_INERRORS, proto == IPPROTO_UDPLITE); 585db8dac20SDavid S. Miller kfree_skb(skb); 586db8dac20SDavid S. Miller return 0; 587db8dac20SDavid S. Miller } 588db8dac20SDavid S. Miller 589db8dac20SDavid S. Miller static __inline__ int udpv6_rcv(struct sk_buff *skb) 590db8dac20SDavid S. Miller { 591645ca708SEric Dumazet return __udp6_lib_rcv(skb, &udp_table, IPPROTO_UDP); 592db8dac20SDavid S. Miller } 593db8dac20SDavid S. Miller 594db8dac20SDavid S. Miller /* 595db8dac20SDavid S. Miller * Throw away all pending data and cancel the corking. Socket is locked. 596db8dac20SDavid S. Miller */ 597db8dac20SDavid S. Miller static void udp_v6_flush_pending_frames(struct sock *sk) 598db8dac20SDavid S. Miller { 599db8dac20SDavid S. Miller struct udp_sock *up = udp_sk(sk); 600db8dac20SDavid S. Miller 60136d926b9SDenis V. Lunev if (up->pending == AF_INET) 60236d926b9SDenis V. Lunev udp_flush_pending_frames(sk); 60336d926b9SDenis V. Lunev else if (up->pending) { 604db8dac20SDavid S. Miller up->len = 0; 605db8dac20SDavid S. Miller up->pending = 0; 606db8dac20SDavid S. Miller ip6_flush_pending_frames(sk); 607db8dac20SDavid S. Miller } 608db8dac20SDavid S. Miller } 609db8dac20SDavid S. Miller 610db8dac20SDavid S. Miller /* 611db8dac20SDavid S. Miller * Sending 612db8dac20SDavid S. Miller */ 613db8dac20SDavid S. Miller 614db8dac20SDavid S. Miller static int udp_v6_push_pending_frames(struct sock *sk) 615db8dac20SDavid S. Miller { 616db8dac20SDavid S. Miller struct sk_buff *skb; 617db8dac20SDavid S. Miller struct udphdr *uh; 618db8dac20SDavid S. Miller struct udp_sock *up = udp_sk(sk); 619db8dac20SDavid S. Miller struct inet_sock *inet = inet_sk(sk); 620db8dac20SDavid S. Miller struct flowi *fl = &inet->cork.fl; 621db8dac20SDavid S. Miller int err = 0; 622db8dac20SDavid S. Miller int is_udplite = IS_UDPLITE(sk); 623db8dac20SDavid S. Miller __wsum csum = 0; 624db8dac20SDavid S. Miller 625db8dac20SDavid S. Miller /* Grab the skbuff where UDP header space exists. */ 626db8dac20SDavid S. Miller if ((skb = skb_peek(&sk->sk_write_queue)) == NULL) 627db8dac20SDavid S. Miller goto out; 628db8dac20SDavid S. Miller 629db8dac20SDavid S. Miller /* 630db8dac20SDavid S. Miller * Create a UDP header 631db8dac20SDavid S. Miller */ 632db8dac20SDavid S. Miller uh = udp_hdr(skb); 633db8dac20SDavid S. Miller uh->source = fl->fl_ip_sport; 634db8dac20SDavid S. Miller uh->dest = fl->fl_ip_dport; 635db8dac20SDavid S. Miller uh->len = htons(up->len); 636db8dac20SDavid S. Miller uh->check = 0; 637db8dac20SDavid S. Miller 638db8dac20SDavid S. Miller if (is_udplite) 639db8dac20SDavid S. Miller csum = udplite_csum_outgoing(sk, skb); 640db8dac20SDavid S. Miller else 641db8dac20SDavid S. Miller csum = udp_csum_outgoing(sk, skb); 642db8dac20SDavid S. Miller 643db8dac20SDavid S. Miller /* add protocol-dependent pseudo-header */ 644db8dac20SDavid S. Miller uh->check = csum_ipv6_magic(&fl->fl6_src, &fl->fl6_dst, 645db8dac20SDavid S. Miller up->len, fl->proto, csum ); 646db8dac20SDavid S. Miller if (uh->check == 0) 647db8dac20SDavid S. Miller uh->check = CSUM_MANGLED_0; 648db8dac20SDavid S. Miller 649db8dac20SDavid S. Miller err = ip6_push_pending_frames(sk); 650db8dac20SDavid S. Miller out: 651db8dac20SDavid S. Miller up->len = 0; 652db8dac20SDavid S. Miller up->pending = 0; 653db8dac20SDavid S. Miller if (!err) 654235b9f7aSPavel Emelyanov UDP6_INC_STATS_USER(sock_net(sk), 655235b9f7aSPavel Emelyanov UDP_MIB_OUTDATAGRAMS, is_udplite); 656db8dac20SDavid S. Miller return err; 657db8dac20SDavid S. Miller } 658db8dac20SDavid S. Miller 659db8dac20SDavid S. Miller int udpv6_sendmsg(struct kiocb *iocb, struct sock *sk, 660db8dac20SDavid S. Miller struct msghdr *msg, size_t len) 661db8dac20SDavid S. Miller { 662db8dac20SDavid S. Miller struct ipv6_txoptions opt_space; 663db8dac20SDavid S. Miller struct udp_sock *up = udp_sk(sk); 664db8dac20SDavid S. Miller struct inet_sock *inet = inet_sk(sk); 665db8dac20SDavid S. Miller struct ipv6_pinfo *np = inet6_sk(sk); 666db8dac20SDavid S. Miller struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) msg->msg_name; 667db8dac20SDavid S. Miller struct in6_addr *daddr, *final_p = NULL, final; 668db8dac20SDavid S. Miller struct ipv6_txoptions *opt = NULL; 669db8dac20SDavid S. Miller struct ip6_flowlabel *flowlabel = NULL; 670db8dac20SDavid S. Miller struct flowi fl; 671db8dac20SDavid S. Miller struct dst_entry *dst; 672db8dac20SDavid S. Miller int addr_len = msg->msg_namelen; 673db8dac20SDavid S. Miller int ulen = len; 674db8dac20SDavid S. Miller int hlimit = -1; 675db8dac20SDavid S. Miller int tclass = -1; 676db8dac20SDavid S. Miller int corkreq = up->corkflag || msg->msg_flags&MSG_MORE; 677db8dac20SDavid S. Miller int err; 678db8dac20SDavid S. Miller int connected = 0; 679db8dac20SDavid S. Miller int is_udplite = IS_UDPLITE(sk); 680db8dac20SDavid S. Miller int (*getfrag)(void *, char *, int, int, int, struct sk_buff *); 681db8dac20SDavid S. Miller 682db8dac20SDavid S. Miller /* destination address check */ 683db8dac20SDavid S. Miller if (sin6) { 684db8dac20SDavid S. Miller if (addr_len < offsetof(struct sockaddr, sa_data)) 685db8dac20SDavid S. Miller return -EINVAL; 686db8dac20SDavid S. Miller 687db8dac20SDavid S. Miller switch (sin6->sin6_family) { 688db8dac20SDavid S. Miller case AF_INET6: 689db8dac20SDavid S. Miller if (addr_len < SIN6_LEN_RFC2133) 690db8dac20SDavid S. Miller return -EINVAL; 691db8dac20SDavid S. Miller daddr = &sin6->sin6_addr; 692db8dac20SDavid S. Miller break; 693db8dac20SDavid S. Miller case AF_INET: 694db8dac20SDavid S. Miller goto do_udp_sendmsg; 695db8dac20SDavid S. Miller case AF_UNSPEC: 696db8dac20SDavid S. Miller msg->msg_name = sin6 = NULL; 697db8dac20SDavid S. Miller msg->msg_namelen = addr_len = 0; 698db8dac20SDavid S. Miller daddr = NULL; 699db8dac20SDavid S. Miller break; 700db8dac20SDavid S. Miller default: 701db8dac20SDavid S. Miller return -EINVAL; 702db8dac20SDavid S. Miller } 703db8dac20SDavid S. Miller } else if (!up->pending) { 704db8dac20SDavid S. Miller if (sk->sk_state != TCP_ESTABLISHED) 705db8dac20SDavid S. Miller return -EDESTADDRREQ; 706db8dac20SDavid S. Miller daddr = &np->daddr; 707db8dac20SDavid S. Miller } else 708db8dac20SDavid S. Miller daddr = NULL; 709db8dac20SDavid S. Miller 710db8dac20SDavid S. Miller if (daddr) { 711db8dac20SDavid S. Miller if (ipv6_addr_v4mapped(daddr)) { 712db8dac20SDavid S. Miller struct sockaddr_in sin; 713db8dac20SDavid S. Miller sin.sin_family = AF_INET; 714db8dac20SDavid S. Miller sin.sin_port = sin6 ? sin6->sin6_port : inet->dport; 715db8dac20SDavid S. Miller sin.sin_addr.s_addr = daddr->s6_addr32[3]; 716db8dac20SDavid S. Miller msg->msg_name = &sin; 717db8dac20SDavid S. Miller msg->msg_namelen = sizeof(sin); 718db8dac20SDavid S. Miller do_udp_sendmsg: 719db8dac20SDavid S. Miller if (__ipv6_only_sock(sk)) 720db8dac20SDavid S. Miller return -ENETUNREACH; 721db8dac20SDavid S. Miller return udp_sendmsg(iocb, sk, msg, len); 722db8dac20SDavid S. Miller } 723db8dac20SDavid S. Miller } 724db8dac20SDavid S. Miller 725db8dac20SDavid S. Miller if (up->pending == AF_INET) 726db8dac20SDavid S. Miller return udp_sendmsg(iocb, sk, msg, len); 727db8dac20SDavid S. Miller 728db8dac20SDavid S. Miller /* Rough check on arithmetic overflow, 729db8dac20SDavid S. Miller better check is made in ip6_append_data(). 730db8dac20SDavid S. Miller */ 731db8dac20SDavid S. Miller if (len > INT_MAX - sizeof(struct udphdr)) 732db8dac20SDavid S. Miller return -EMSGSIZE; 733db8dac20SDavid S. Miller 734db8dac20SDavid S. Miller if (up->pending) { 735db8dac20SDavid S. Miller /* 736db8dac20SDavid S. Miller * There are pending frames. 737db8dac20SDavid S. Miller * The socket lock must be held while it's corked. 738db8dac20SDavid S. Miller */ 739db8dac20SDavid S. Miller lock_sock(sk); 740db8dac20SDavid S. Miller if (likely(up->pending)) { 741db8dac20SDavid S. Miller if (unlikely(up->pending != AF_INET6)) { 742db8dac20SDavid S. Miller release_sock(sk); 743db8dac20SDavid S. Miller return -EAFNOSUPPORT; 744db8dac20SDavid S. Miller } 745db8dac20SDavid S. Miller dst = NULL; 746db8dac20SDavid S. Miller goto do_append_data; 747db8dac20SDavid S. Miller } 748db8dac20SDavid S. Miller release_sock(sk); 749db8dac20SDavid S. Miller } 750db8dac20SDavid S. Miller ulen += sizeof(struct udphdr); 751db8dac20SDavid S. Miller 752db8dac20SDavid S. Miller memset(&fl, 0, sizeof(fl)); 753db8dac20SDavid S. Miller 754db8dac20SDavid S. Miller if (sin6) { 755db8dac20SDavid S. Miller if (sin6->sin6_port == 0) 756db8dac20SDavid S. Miller return -EINVAL; 757db8dac20SDavid S. Miller 758db8dac20SDavid S. Miller fl.fl_ip_dport = sin6->sin6_port; 759db8dac20SDavid S. Miller daddr = &sin6->sin6_addr; 760db8dac20SDavid S. Miller 761db8dac20SDavid S. Miller if (np->sndflow) { 762db8dac20SDavid S. Miller fl.fl6_flowlabel = sin6->sin6_flowinfo&IPV6_FLOWINFO_MASK; 763db8dac20SDavid S. Miller if (fl.fl6_flowlabel&IPV6_FLOWLABEL_MASK) { 764db8dac20SDavid S. Miller flowlabel = fl6_sock_lookup(sk, fl.fl6_flowlabel); 765db8dac20SDavid S. Miller if (flowlabel == NULL) 766db8dac20SDavid S. Miller return -EINVAL; 767db8dac20SDavid S. Miller daddr = &flowlabel->dst; 768db8dac20SDavid S. Miller } 769db8dac20SDavid S. Miller } 770db8dac20SDavid S. Miller 771db8dac20SDavid S. Miller /* 772db8dac20SDavid S. Miller * Otherwise it will be difficult to maintain 773db8dac20SDavid S. Miller * sk->sk_dst_cache. 774db8dac20SDavid S. Miller */ 775db8dac20SDavid S. Miller if (sk->sk_state == TCP_ESTABLISHED && 776db8dac20SDavid S. Miller ipv6_addr_equal(daddr, &np->daddr)) 777db8dac20SDavid S. Miller daddr = &np->daddr; 778db8dac20SDavid S. Miller 779db8dac20SDavid S. Miller if (addr_len >= sizeof(struct sockaddr_in6) && 780db8dac20SDavid S. Miller sin6->sin6_scope_id && 781db8dac20SDavid S. Miller ipv6_addr_type(daddr)&IPV6_ADDR_LINKLOCAL) 782db8dac20SDavid S. Miller fl.oif = sin6->sin6_scope_id; 783db8dac20SDavid S. Miller } else { 784db8dac20SDavid S. Miller if (sk->sk_state != TCP_ESTABLISHED) 785db8dac20SDavid S. Miller return -EDESTADDRREQ; 786db8dac20SDavid S. Miller 787db8dac20SDavid S. Miller fl.fl_ip_dport = inet->dport; 788db8dac20SDavid S. Miller daddr = &np->daddr; 789db8dac20SDavid S. Miller fl.fl6_flowlabel = np->flow_label; 790db8dac20SDavid S. Miller connected = 1; 791db8dac20SDavid S. Miller } 792db8dac20SDavid S. Miller 793db8dac20SDavid S. Miller if (!fl.oif) 794db8dac20SDavid S. Miller fl.oif = sk->sk_bound_dev_if; 795db8dac20SDavid S. Miller 796db8dac20SDavid S. Miller if (msg->msg_controllen) { 797db8dac20SDavid S. Miller opt = &opt_space; 798db8dac20SDavid S. Miller memset(opt, 0, sizeof(struct ipv6_txoptions)); 799db8dac20SDavid S. Miller opt->tot_len = sizeof(*opt); 800db8dac20SDavid S. Miller 80191e1908fSYOSHIFUJI Hideaki err = datagram_send_ctl(sock_net(sk), msg, &fl, opt, &hlimit, &tclass); 802db8dac20SDavid S. Miller if (err < 0) { 803db8dac20SDavid S. Miller fl6_sock_release(flowlabel); 804db8dac20SDavid S. Miller return err; 805db8dac20SDavid S. Miller } 806db8dac20SDavid S. Miller if ((fl.fl6_flowlabel&IPV6_FLOWLABEL_MASK) && !flowlabel) { 807db8dac20SDavid S. Miller flowlabel = fl6_sock_lookup(sk, fl.fl6_flowlabel); 808db8dac20SDavid S. Miller if (flowlabel == NULL) 809db8dac20SDavid S. Miller return -EINVAL; 810db8dac20SDavid S. Miller } 811db8dac20SDavid S. Miller if (!(opt->opt_nflen|opt->opt_flen)) 812db8dac20SDavid S. Miller opt = NULL; 813db8dac20SDavid S. Miller connected = 0; 814db8dac20SDavid S. Miller } 815db8dac20SDavid S. Miller if (opt == NULL) 816db8dac20SDavid S. Miller opt = np->opt; 817db8dac20SDavid S. Miller if (flowlabel) 818db8dac20SDavid S. Miller opt = fl6_merge_options(&opt_space, flowlabel, opt); 819db8dac20SDavid S. Miller opt = ipv6_fixup_options(&opt_space, opt); 820db8dac20SDavid S. Miller 821db8dac20SDavid S. Miller fl.proto = sk->sk_protocol; 822876c7f41SBrian Haley if (!ipv6_addr_any(daddr)) 823db8dac20SDavid S. Miller ipv6_addr_copy(&fl.fl6_dst, daddr); 824876c7f41SBrian Haley else 825876c7f41SBrian Haley fl.fl6_dst.s6_addr[15] = 0x1; /* :: means loopback (BSD'ism) */ 826db8dac20SDavid S. Miller if (ipv6_addr_any(&fl.fl6_src) && !ipv6_addr_any(&np->saddr)) 827db8dac20SDavid S. Miller ipv6_addr_copy(&fl.fl6_src, &np->saddr); 828db8dac20SDavid S. Miller fl.fl_ip_sport = inet->sport; 829db8dac20SDavid S. Miller 830db8dac20SDavid S. Miller /* merge ip6_build_xmit from ip6_output */ 831db8dac20SDavid S. Miller if (opt && opt->srcrt) { 832db8dac20SDavid S. Miller struct rt0_hdr *rt0 = (struct rt0_hdr *) opt->srcrt; 833db8dac20SDavid S. Miller ipv6_addr_copy(&final, &fl.fl6_dst); 834db8dac20SDavid S. Miller ipv6_addr_copy(&fl.fl6_dst, rt0->addr); 835db8dac20SDavid S. Miller final_p = &final; 836db8dac20SDavid S. Miller connected = 0; 837db8dac20SDavid S. Miller } 838db8dac20SDavid S. Miller 839db8dac20SDavid S. Miller if (!fl.oif && ipv6_addr_is_multicast(&fl.fl6_dst)) { 840db8dac20SDavid S. Miller fl.oif = np->mcast_oif; 841db8dac20SDavid S. Miller connected = 0; 842db8dac20SDavid S. Miller } 843db8dac20SDavid S. Miller 844db8dac20SDavid S. Miller security_sk_classify_flow(sk, &fl); 845db8dac20SDavid S. Miller 846db8dac20SDavid S. Miller err = ip6_sk_dst_lookup(sk, &dst, &fl); 847db8dac20SDavid S. Miller if (err) 848db8dac20SDavid S. Miller goto out; 849db8dac20SDavid S. Miller if (final_p) 850db8dac20SDavid S. Miller ipv6_addr_copy(&fl.fl6_dst, final_p); 851db8dac20SDavid S. Miller 85252479b62SAlexey Dobriyan err = __xfrm_lookup(sock_net(sk), &dst, &fl, sk, XFRM_LOOKUP_WAIT); 85352479b62SAlexey Dobriyan if (err < 0) { 854db8dac20SDavid S. Miller if (err == -EREMOTE) 855db8dac20SDavid S. Miller err = ip6_dst_blackhole(sk, &dst, &fl); 856db8dac20SDavid S. Miller if (err < 0) 857db8dac20SDavid S. Miller goto out; 858db8dac20SDavid S. Miller } 859db8dac20SDavid S. Miller 860db8dac20SDavid S. Miller if (hlimit < 0) { 861db8dac20SDavid S. Miller if (ipv6_addr_is_multicast(&fl.fl6_dst)) 862db8dac20SDavid S. Miller hlimit = np->mcast_hops; 863db8dac20SDavid S. Miller else 864db8dac20SDavid S. Miller hlimit = np->hop_limit; 865db8dac20SDavid S. Miller if (hlimit < 0) 8666b75d090SYOSHIFUJI Hideaki hlimit = ip6_dst_hoplimit(dst); 867db8dac20SDavid S. Miller } 868db8dac20SDavid S. Miller 869db8dac20SDavid S. Miller if (tclass < 0) { 870db8dac20SDavid S. Miller tclass = np->tclass; 871db8dac20SDavid S. Miller if (tclass < 0) 872db8dac20SDavid S. Miller tclass = 0; 873db8dac20SDavid S. Miller } 874db8dac20SDavid S. Miller 875db8dac20SDavid S. Miller if (msg->msg_flags&MSG_CONFIRM) 876db8dac20SDavid S. Miller goto do_confirm; 877db8dac20SDavid S. Miller back_from_confirm: 878db8dac20SDavid S. Miller 879db8dac20SDavid S. Miller lock_sock(sk); 880db8dac20SDavid S. Miller if (unlikely(up->pending)) { 881db8dac20SDavid S. Miller /* The socket is already corked while preparing it. */ 882db8dac20SDavid S. Miller /* ... which is an evident application bug. --ANK */ 883db8dac20SDavid S. Miller release_sock(sk); 884db8dac20SDavid S. Miller 885db8dac20SDavid S. Miller LIMIT_NETDEBUG(KERN_DEBUG "udp cork app bug 2\n"); 886db8dac20SDavid S. Miller err = -EINVAL; 887db8dac20SDavid S. Miller goto out; 888db8dac20SDavid S. Miller } 889db8dac20SDavid S. Miller 890db8dac20SDavid S. Miller up->pending = AF_INET6; 891db8dac20SDavid S. Miller 892db8dac20SDavid S. Miller do_append_data: 893db8dac20SDavid S. Miller up->len += ulen; 894db8dac20SDavid S. Miller getfrag = is_udplite ? udplite_getfrag : ip_generic_getfrag; 895db8dac20SDavid S. Miller err = ip6_append_data(sk, getfrag, msg->msg_iov, ulen, 896db8dac20SDavid S. Miller sizeof(struct udphdr), hlimit, tclass, opt, &fl, 897db8dac20SDavid S. Miller (struct rt6_info*)dst, 898db8dac20SDavid S. Miller corkreq ? msg->msg_flags|MSG_MORE : msg->msg_flags); 899db8dac20SDavid S. Miller if (err) 900db8dac20SDavid S. Miller udp_v6_flush_pending_frames(sk); 901db8dac20SDavid S. Miller else if (!corkreq) 902db8dac20SDavid S. Miller err = udp_v6_push_pending_frames(sk); 903db8dac20SDavid S. Miller else if (unlikely(skb_queue_empty(&sk->sk_write_queue))) 904db8dac20SDavid S. Miller up->pending = 0; 905db8dac20SDavid S. Miller 906db8dac20SDavid S. Miller if (dst) { 907db8dac20SDavid S. Miller if (connected) { 908db8dac20SDavid S. Miller ip6_dst_store(sk, dst, 909db8dac20SDavid S. Miller ipv6_addr_equal(&fl.fl6_dst, &np->daddr) ? 910db8dac20SDavid S. Miller &np->daddr : NULL, 911db8dac20SDavid S. Miller #ifdef CONFIG_IPV6_SUBTREES 912db8dac20SDavid S. Miller ipv6_addr_equal(&fl.fl6_src, &np->saddr) ? 913db8dac20SDavid S. Miller &np->saddr : 914db8dac20SDavid S. Miller #endif 915db8dac20SDavid S. Miller NULL); 916db8dac20SDavid S. Miller } else { 917db8dac20SDavid S. Miller dst_release(dst); 918db8dac20SDavid S. Miller } 919a3c96089SYOSHIFUJI Hideaki dst = NULL; 920db8dac20SDavid S. Miller } 921db8dac20SDavid S. Miller 922db8dac20SDavid S. Miller if (err > 0) 923db8dac20SDavid S. Miller err = np->recverr ? net_xmit_errno(err) : 0; 924db8dac20SDavid S. Miller release_sock(sk); 925db8dac20SDavid S. Miller out: 926a3c96089SYOSHIFUJI Hideaki dst_release(dst); 927db8dac20SDavid S. Miller fl6_sock_release(flowlabel); 928db8dac20SDavid S. Miller if (!err) 929db8dac20SDavid S. Miller return len; 930db8dac20SDavid S. Miller /* 931db8dac20SDavid S. Miller * ENOBUFS = no kernel mem, SOCK_NOSPACE = no sndbuf space. Reporting 932db8dac20SDavid S. Miller * ENOBUFS might not be good (it's not tunable per se), but otherwise 933db8dac20SDavid S. Miller * we don't have a good statistic (IpOutDiscards but it can be too many 934db8dac20SDavid S. Miller * things). We could add another new stat but at least for now that 935db8dac20SDavid S. Miller * seems like overkill. 936db8dac20SDavid S. Miller */ 937db8dac20SDavid S. Miller if (err == -ENOBUFS || test_bit(SOCK_NOSPACE, &sk->sk_socket->flags)) { 938235b9f7aSPavel Emelyanov UDP6_INC_STATS_USER(sock_net(sk), 939235b9f7aSPavel Emelyanov UDP_MIB_SNDBUFERRORS, is_udplite); 940db8dac20SDavid S. Miller } 941db8dac20SDavid S. Miller return err; 942db8dac20SDavid S. Miller 943db8dac20SDavid S. Miller do_confirm: 944db8dac20SDavid S. Miller dst_confirm(dst); 945db8dac20SDavid S. Miller if (!(msg->msg_flags&MSG_PROBE) || len) 946db8dac20SDavid S. Miller goto back_from_confirm; 947db8dac20SDavid S. Miller err = 0; 948db8dac20SDavid S. Miller goto out; 949db8dac20SDavid S. Miller } 950db8dac20SDavid S. Miller 9517d06b2e0SBrian Haley void udpv6_destroy_sock(struct sock *sk) 952db8dac20SDavid S. Miller { 953db8dac20SDavid S. Miller lock_sock(sk); 954db8dac20SDavid S. Miller udp_v6_flush_pending_frames(sk); 955db8dac20SDavid S. Miller release_sock(sk); 956db8dac20SDavid S. Miller 957db8dac20SDavid S. Miller inet6_destroy_sock(sk); 958db8dac20SDavid S. Miller } 959db8dac20SDavid S. Miller 960db8dac20SDavid S. Miller /* 961db8dac20SDavid S. Miller * Socket option code for UDP 962db8dac20SDavid S. Miller */ 963db8dac20SDavid S. Miller int udpv6_setsockopt(struct sock *sk, int level, int optname, 964db8dac20SDavid S. Miller char __user *optval, int optlen) 965db8dac20SDavid S. Miller { 966db8dac20SDavid S. Miller if (level == SOL_UDP || level == SOL_UDPLITE) 967db8dac20SDavid S. Miller return udp_lib_setsockopt(sk, level, optname, optval, optlen, 968db8dac20SDavid S. Miller udp_v6_push_pending_frames); 969db8dac20SDavid S. Miller return ipv6_setsockopt(sk, level, optname, optval, optlen); 970db8dac20SDavid S. Miller } 971db8dac20SDavid S. Miller 972db8dac20SDavid S. Miller #ifdef CONFIG_COMPAT 973db8dac20SDavid S. Miller int compat_udpv6_setsockopt(struct sock *sk, int level, int optname, 974db8dac20SDavid S. Miller char __user *optval, int optlen) 975db8dac20SDavid S. Miller { 976db8dac20SDavid S. Miller if (level == SOL_UDP || level == SOL_UDPLITE) 977db8dac20SDavid S. Miller return udp_lib_setsockopt(sk, level, optname, optval, optlen, 978db8dac20SDavid S. Miller udp_v6_push_pending_frames); 979db8dac20SDavid S. Miller return compat_ipv6_setsockopt(sk, level, optname, optval, optlen); 980db8dac20SDavid S. Miller } 981db8dac20SDavid S. Miller #endif 982db8dac20SDavid S. Miller 983db8dac20SDavid S. Miller int udpv6_getsockopt(struct sock *sk, int level, int optname, 984db8dac20SDavid S. Miller char __user *optval, int __user *optlen) 985db8dac20SDavid S. Miller { 986db8dac20SDavid S. Miller if (level == SOL_UDP || level == SOL_UDPLITE) 987db8dac20SDavid S. Miller return udp_lib_getsockopt(sk, level, optname, optval, optlen); 988db8dac20SDavid S. Miller return ipv6_getsockopt(sk, level, optname, optval, optlen); 989db8dac20SDavid S. Miller } 990db8dac20SDavid S. Miller 991db8dac20SDavid S. Miller #ifdef CONFIG_COMPAT 992db8dac20SDavid S. Miller int compat_udpv6_getsockopt(struct sock *sk, int level, int optname, 993db8dac20SDavid S. Miller char __user *optval, int __user *optlen) 994db8dac20SDavid S. Miller { 995db8dac20SDavid S. Miller if (level == SOL_UDP || level == SOL_UDPLITE) 996db8dac20SDavid S. Miller return udp_lib_getsockopt(sk, level, optname, optval, optlen); 997db8dac20SDavid S. Miller return compat_ipv6_getsockopt(sk, level, optname, optval, optlen); 998db8dac20SDavid S. Miller } 999db8dac20SDavid S. Miller #endif 1000db8dac20SDavid S. Miller 1001db8dac20SDavid S. Miller static struct inet6_protocol udpv6_protocol = { 1002db8dac20SDavid S. Miller .handler = udpv6_rcv, 1003db8dac20SDavid S. Miller .err_handler = udpv6_err, 1004db8dac20SDavid S. Miller .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL, 1005db8dac20SDavid S. Miller }; 1006db8dac20SDavid S. Miller 1007db8dac20SDavid S. Miller /* ------------------------------------------------------------------------ */ 1008db8dac20SDavid S. Miller #ifdef CONFIG_PROC_FS 1009db8dac20SDavid S. Miller 1010db8dac20SDavid S. Miller static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket) 1011db8dac20SDavid S. Miller { 1012db8dac20SDavid S. Miller struct inet_sock *inet = inet_sk(sp); 1013db8dac20SDavid S. Miller struct ipv6_pinfo *np = inet6_sk(sp); 1014db8dac20SDavid S. Miller struct in6_addr *dest, *src; 1015db8dac20SDavid S. Miller __u16 destp, srcp; 1016db8dac20SDavid S. Miller 1017db8dac20SDavid S. Miller dest = &np->daddr; 1018db8dac20SDavid S. Miller src = &np->rcv_saddr; 1019db8dac20SDavid S. Miller destp = ntohs(inet->dport); 1020db8dac20SDavid S. Miller srcp = ntohs(inet->sport); 1021db8dac20SDavid S. Miller seq_printf(seq, 1022db8dac20SDavid S. Miller "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X " 1023cb61cb9bSEric Dumazet "%02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n", 1024db8dac20SDavid S. Miller bucket, 1025db8dac20SDavid S. Miller src->s6_addr32[0], src->s6_addr32[1], 1026db8dac20SDavid S. Miller src->s6_addr32[2], src->s6_addr32[3], srcp, 1027db8dac20SDavid S. Miller dest->s6_addr32[0], dest->s6_addr32[1], 1028db8dac20SDavid S. Miller dest->s6_addr32[2], dest->s6_addr32[3], destp, 1029db8dac20SDavid S. Miller sp->sk_state, 1030db8dac20SDavid S. Miller atomic_read(&sp->sk_wmem_alloc), 1031db8dac20SDavid S. Miller atomic_read(&sp->sk_rmem_alloc), 1032db8dac20SDavid S. Miller 0, 0L, 0, 1033db8dac20SDavid S. Miller sock_i_uid(sp), 0, 1034db8dac20SDavid S. Miller sock_i_ino(sp), 1035cb61cb9bSEric Dumazet atomic_read(&sp->sk_refcnt), sp, 1036cb61cb9bSEric Dumazet atomic_read(&sp->sk_drops)); 1037db8dac20SDavid S. Miller } 1038db8dac20SDavid S. Miller 1039db8dac20SDavid S. Miller int udp6_seq_show(struct seq_file *seq, void *v) 1040db8dac20SDavid S. Miller { 1041db8dac20SDavid S. Miller if (v == SEQ_START_TOKEN) 1042db8dac20SDavid S. Miller seq_printf(seq, 1043db8dac20SDavid S. Miller " sl " 1044db8dac20SDavid S. Miller "local_address " 1045db8dac20SDavid S. Miller "remote_address " 1046db8dac20SDavid S. Miller "st tx_queue rx_queue tr tm->when retrnsmt" 1047cb61cb9bSEric Dumazet " uid timeout inode ref pointer drops\n"); 1048db8dac20SDavid S. Miller else 1049db8dac20SDavid S. Miller udp6_sock_seq_show(seq, v, ((struct udp_iter_state *)seq->private)->bucket); 1050db8dac20SDavid S. Miller return 0; 1051db8dac20SDavid S. Miller } 1052db8dac20SDavid S. Miller 1053db8dac20SDavid S. Miller static struct udp_seq_afinfo udp6_seq_afinfo = { 1054db8dac20SDavid S. Miller .name = "udp6", 1055db8dac20SDavid S. Miller .family = AF_INET6, 1056645ca708SEric Dumazet .udp_table = &udp_table, 10574ad96d39SDenis V. Lunev .seq_fops = { 10584ad96d39SDenis V. Lunev .owner = THIS_MODULE, 10594ad96d39SDenis V. Lunev }, 1060dda61925SDenis V. Lunev .seq_ops = { 1061dda61925SDenis V. Lunev .show = udp6_seq_show, 1062dda61925SDenis V. Lunev }, 1063db8dac20SDavid S. Miller }; 1064db8dac20SDavid S. Miller 10650c96d8c5SDaniel Lezcano int udp6_proc_init(struct net *net) 1066db8dac20SDavid S. Miller { 10670c96d8c5SDaniel Lezcano return udp_proc_register(net, &udp6_seq_afinfo); 1068db8dac20SDavid S. Miller } 1069db8dac20SDavid S. Miller 10700c96d8c5SDaniel Lezcano void udp6_proc_exit(struct net *net) { 10710c96d8c5SDaniel Lezcano udp_proc_unregister(net, &udp6_seq_afinfo); 1072db8dac20SDavid S. Miller } 1073db8dac20SDavid S. Miller #endif /* CONFIG_PROC_FS */ 1074db8dac20SDavid S. Miller 1075db8dac20SDavid S. Miller /* ------------------------------------------------------------------------ */ 1076db8dac20SDavid S. Miller 1077db8dac20SDavid S. Miller struct proto udpv6_prot = { 1078db8dac20SDavid S. Miller .name = "UDPv6", 1079db8dac20SDavid S. Miller .owner = THIS_MODULE, 1080db8dac20SDavid S. Miller .close = udp_lib_close, 1081db8dac20SDavid S. Miller .connect = ip6_datagram_connect, 1082db8dac20SDavid S. Miller .disconnect = udp_disconnect, 1083db8dac20SDavid S. Miller .ioctl = udp_ioctl, 1084db8dac20SDavid S. Miller .destroy = udpv6_destroy_sock, 1085db8dac20SDavid S. Miller .setsockopt = udpv6_setsockopt, 1086db8dac20SDavid S. Miller .getsockopt = udpv6_getsockopt, 1087db8dac20SDavid S. Miller .sendmsg = udpv6_sendmsg, 1088db8dac20SDavid S. Miller .recvmsg = udpv6_recvmsg, 1089db8dac20SDavid S. Miller .backlog_rcv = udpv6_queue_rcv_skb, 1090db8dac20SDavid S. Miller .hash = udp_lib_hash, 1091db8dac20SDavid S. Miller .unhash = udp_lib_unhash, 1092db8dac20SDavid S. Miller .get_port = udp_v6_get_port, 1093db8dac20SDavid S. Miller .memory_allocated = &udp_memory_allocated, 1094db8dac20SDavid S. Miller .sysctl_mem = sysctl_udp_mem, 1095db8dac20SDavid S. Miller .sysctl_wmem = &sysctl_udp_wmem_min, 1096db8dac20SDavid S. Miller .sysctl_rmem = &sysctl_udp_rmem_min, 1097db8dac20SDavid S. Miller .obj_size = sizeof(struct udp6_sock), 1098271b72c7SEric Dumazet .slab_flags = SLAB_DESTROY_BY_RCU, 1099645ca708SEric Dumazet .h.udp_table = &udp_table, 1100db8dac20SDavid S. Miller #ifdef CONFIG_COMPAT 1101db8dac20SDavid S. Miller .compat_setsockopt = compat_udpv6_setsockopt, 1102db8dac20SDavid S. Miller .compat_getsockopt = compat_udpv6_getsockopt, 1103db8dac20SDavid S. Miller #endif 1104db8dac20SDavid S. Miller }; 1105db8dac20SDavid S. Miller 1106db8dac20SDavid S. Miller static struct inet_protosw udpv6_protosw = { 1107db8dac20SDavid S. Miller .type = SOCK_DGRAM, 1108db8dac20SDavid S. Miller .protocol = IPPROTO_UDP, 1109db8dac20SDavid S. Miller .prot = &udpv6_prot, 1110db8dac20SDavid S. Miller .ops = &inet6_dgram_ops, 1111db8dac20SDavid S. Miller .capability =-1, 1112db8dac20SDavid S. Miller .no_check = UDP_CSUM_DEFAULT, 1113db8dac20SDavid S. Miller .flags = INET_PROTOSW_PERMANENT, 1114db8dac20SDavid S. Miller }; 1115db8dac20SDavid S. Miller 1116db8dac20SDavid S. Miller 1117db8dac20SDavid S. Miller int __init udpv6_init(void) 1118db8dac20SDavid S. Miller { 1119db8dac20SDavid S. Miller int ret; 1120db8dac20SDavid S. Miller 1121db8dac20SDavid S. Miller ret = inet6_add_protocol(&udpv6_protocol, IPPROTO_UDP); 1122db8dac20SDavid S. Miller if (ret) 1123db8dac20SDavid S. Miller goto out; 1124db8dac20SDavid S. Miller 1125db8dac20SDavid S. Miller ret = inet6_register_protosw(&udpv6_protosw); 1126db8dac20SDavid S. Miller if (ret) 1127db8dac20SDavid S. Miller goto out_udpv6_protocol; 1128db8dac20SDavid S. Miller out: 1129db8dac20SDavid S. Miller return ret; 1130db8dac20SDavid S. Miller 1131db8dac20SDavid S. Miller out_udpv6_protocol: 1132db8dac20SDavid S. Miller inet6_del_protocol(&udpv6_protocol, IPPROTO_UDP); 1133db8dac20SDavid S. Miller goto out; 1134db8dac20SDavid S. Miller } 1135db8dac20SDavid S. Miller 1136db8dac20SDavid S. Miller void udpv6_exit(void) 1137db8dac20SDavid S. Miller { 1138db8dac20SDavid S. Miller inet6_unregister_protosw(&udpv6_protosw); 1139db8dac20SDavid S. Miller inet6_del_protocol(&udpv6_protocol, IPPROTO_UDP); 1140db8dac20SDavid S. Miller } 1141