3 * Linux INET6 implementation
6 * Pedro Roque <roque@di.fc.ul.pt>
8 * Based on linux/ipv4/udp.c
10 * $Id: udp.c,v 1.65 2002/02/01 22:01:04 davem Exp $
13 * Hideaki YOSHIFUJI : sin6_scope_id support
14 * YOSHIFUJI Hideaki @USAGI and: Support IPV6_V6ONLY socket option, which
15 * Alexey Kuznetsov allow both IPv4 and IPv6 sockets to bind
16 * a single port at the same time.
17 * Kazunori MIYAZAWA @USAGI: change process style to use ip6_append_data
18 * YOSHIFUJI Hideaki @USAGI: convert /proc/net/udp6 to seq_file.
20 * This program is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU General Public License
22 * as published by the Free Software Foundation; either version
23 * 2 of the License, or (at your option) any later version.
26 #include <linux/config.h>
27 #include <linux/errno.h>
28 #include <linux/types.h>
29 #include <linux/socket.h>
30 #include <linux/sockios.h>
31 #include <linux/sched.h>
32 #include <linux/net.h>
33 #include <linux/in6.h>
34 #include <linux/netdevice.h>
35 #include <linux/if_arp.h>
36 #include <linux/ipv6.h>
37 #include <linux/icmpv6.h>
38 #include <linux/init.h>
39 #include <asm/uaccess.h>
45 #include <net/ndisc.h>
46 #include <net/protocol.h>
47 #include <net/transp_v6.h>
48 #include <net/ip6_route.h>
49 #include <net/addrconf.h>
53 #include <net/inet_common.h>
54 #include <net/tcp_states.h>
56 #include <net/ip6_checksum.h>
59 #include <linux/proc_fs.h>
60 #include <linux/seq_file.h>
62 DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6) __read_mostly;
64 /* Grrr, addr_type already calculated by caller, but I don't want
65 * to add some silly "cookie" argument to this method just for that.
67 static int udp_v6_get_port(struct sock *sk, unsigned short snum)
70 struct hlist_node *node;
72 write_lock_bh(&udp_hash_lock);
74 int best_size_so_far, best, result, i;
76 if (udp_port_rover > sysctl_local_port_range[1] ||
77 udp_port_rover < sysctl_local_port_range[0])
78 udp_port_rover = sysctl_local_port_range[0];
79 best_size_so_far = 32767;
80 best = result = udp_port_rover;
81 for (i = 0; i < UDP_HTABLE_SIZE; i++, result++) {
83 struct hlist_head *list;
85 list = &udp_hash[result & (UDP_HTABLE_SIZE - 1)];
86 if (hlist_empty(list)) {
87 if (result > sysctl_local_port_range[1])
88 result = sysctl_local_port_range[0] +
89 ((result - sysctl_local_port_range[0]) &
90 (UDP_HTABLE_SIZE - 1));
94 sk_for_each(sk2, node, list)
95 if (++size >= best_size_so_far)
97 best_size_so_far = size;
102 for(;; result += UDP_HTABLE_SIZE) {
103 if (result > sysctl_local_port_range[1])
104 result = sysctl_local_port_range[0]
105 + ((result - sysctl_local_port_range[0]) &
106 (UDP_HTABLE_SIZE - 1));
107 if (!udp_lport_inuse(result))
111 udp_port_rover = snum = result;
113 sk_for_each(sk2, node,
114 &udp_hash[snum & (UDP_HTABLE_SIZE - 1)]) {
115 if (inet_sk(sk2)->num == snum &&
117 (!sk2->sk_bound_dev_if ||
118 !sk->sk_bound_dev_if ||
119 sk2->sk_bound_dev_if == sk->sk_bound_dev_if) &&
120 (!sk2->sk_reuse || !sk->sk_reuse) &&
121 ipv6_rcv_saddr_equal(sk, sk2))
126 inet_sk(sk)->num = snum;
127 if (sk_unhashed(sk)) {
128 sk_add_node(sk, &udp_hash[snum & (UDP_HTABLE_SIZE - 1)]);
129 sock_prot_inc_use(sk->sk_prot);
131 write_unlock_bh(&udp_hash_lock);
135 write_unlock_bh(&udp_hash_lock);
139 static void udp_v6_hash(struct sock *sk)
144 static void udp_v6_unhash(struct sock *sk)
146 write_lock_bh(&udp_hash_lock);
147 if (sk_del_node_init(sk)) {
148 inet_sk(sk)->num = 0;
149 sock_prot_dec_use(sk->sk_prot);
151 write_unlock_bh(&udp_hash_lock);
154 static struct sock *udp_v6_lookup(struct in6_addr *saddr, u16 sport,
155 struct in6_addr *daddr, u16 dport, int dif)
157 struct sock *sk, *result = NULL;
158 struct hlist_node *node;
159 unsigned short hnum = ntohs(dport);
162 read_lock(&udp_hash_lock);
163 sk_for_each(sk, node, &udp_hash[hnum & (UDP_HTABLE_SIZE - 1)]) {
164 struct inet_sock *inet = inet_sk(sk);
166 if (inet->num == hnum && sk->sk_family == PF_INET6) {
167 struct ipv6_pinfo *np = inet6_sk(sk);
170 if (inet->dport != sport)
174 if (!ipv6_addr_any(&np->rcv_saddr)) {
175 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
179 if (!ipv6_addr_any(&np->daddr)) {
180 if (!ipv6_addr_equal(&np->daddr, saddr))
184 if (sk->sk_bound_dev_if) {
185 if (sk->sk_bound_dev_if != dif)
192 } else if(score > badness) {
200 read_unlock(&udp_hash_lock);
208 static void udpv6_close(struct sock *sk, long timeout)
210 sk_common_release(sk);
214 * This should be easy, if there is something there we
215 * return it, otherwise we block.
218 static int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
219 struct msghdr *msg, size_t len,
220 int noblock, int flags, int *addr_len)
222 struct ipv6_pinfo *np = inet6_sk(sk);
223 struct inet_sock *inet = inet_sk(sk);
229 *addr_len=sizeof(struct sockaddr_in6);
231 if (flags & MSG_ERRQUEUE)
232 return ipv6_recv_error(sk, msg, len);
235 skb = skb_recv_datagram(sk, flags, noblock, &err);
239 copied = skb->len - sizeof(struct udphdr);
242 msg->msg_flags |= MSG_TRUNC;
245 if (skb->ip_summed==CHECKSUM_UNNECESSARY) {
246 err = skb_copy_datagram_iovec(skb, sizeof(struct udphdr), msg->msg_iov,
248 } else if (msg->msg_flags&MSG_TRUNC) {
249 if ((unsigned short)csum_fold(skb_checksum(skb, 0, skb->len, skb->csum)))
251 err = skb_copy_datagram_iovec(skb, sizeof(struct udphdr), msg->msg_iov,
254 err = skb_copy_and_csum_datagram_iovec(skb, sizeof(struct udphdr), msg->msg_iov);
261 sock_recv_timestamp(msg, sk, skb);
263 /* Copy the address. */
265 struct sockaddr_in6 *sin6;
267 sin6 = (struct sockaddr_in6 *) msg->msg_name;
268 sin6->sin6_family = AF_INET6;
269 sin6->sin6_port = skb->h.uh->source;
270 sin6->sin6_flowinfo = 0;
271 sin6->sin6_scope_id = 0;
273 if (skb->protocol == htons(ETH_P_IP))
274 ipv6_addr_set(&sin6->sin6_addr, 0, 0,
275 htonl(0xffff), skb->nh.iph->saddr);
277 ipv6_addr_copy(&sin6->sin6_addr, &skb->nh.ipv6h->saddr);
278 if (ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL)
279 sin6->sin6_scope_id = IP6CB(skb)->iif;
283 if (skb->protocol == htons(ETH_P_IP)) {
284 if (inet->cmsg_flags)
285 ip_cmsg_recv(msg, skb);
288 datagram_recv_ctl(sk, msg, skb);
292 if (flags & MSG_TRUNC)
293 err = skb->len - sizeof(struct udphdr);
296 skb_free_datagram(sk, skb);
302 if (flags&MSG_PEEK) {
304 spin_lock_bh(&sk->sk_receive_queue.lock);
305 if (skb == skb_peek(&sk->sk_receive_queue)) {
306 __skb_unlink(skb, &sk->sk_receive_queue);
309 spin_unlock_bh(&sk->sk_receive_queue.lock);
314 skb_free_datagram(sk, skb);
316 if (flags & MSG_DONTWAIT) {
317 UDP6_INC_STATS_USER(UDP_MIB_INERRORS);
323 static void udpv6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
324 int type, int code, int offset, __u32 info)
326 struct ipv6_pinfo *np;
327 struct ipv6hdr *hdr = (struct ipv6hdr*)skb->data;
328 struct net_device *dev = skb->dev;
329 struct in6_addr *saddr = &hdr->saddr;
330 struct in6_addr *daddr = &hdr->daddr;
331 struct udphdr *uh = (struct udphdr*)(skb->data+offset);
335 sk = udp_v6_lookup(daddr, uh->dest, saddr, uh->source, dev->ifindex);
342 if (!icmpv6_err_convert(type, code, &err) && !np->recverr)
345 if (sk->sk_state != TCP_ESTABLISHED && !np->recverr)
349 ipv6_icmp_error(sk, skb, err, uh->dest, ntohl(info), (u8 *)(uh+1));
352 sk->sk_error_report(sk);
357 static inline int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
359 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
364 if (skb->ip_summed != CHECKSUM_UNNECESSARY) {
365 if ((unsigned short)csum_fold(skb_checksum(skb, 0, skb->len, skb->csum))) {
366 UDP6_INC_STATS_BH(UDP_MIB_INERRORS);
370 skb->ip_summed = CHECKSUM_UNNECESSARY;
373 if (sock_queue_rcv_skb(sk,skb)<0) {
374 UDP6_INC_STATS_BH(UDP_MIB_INERRORS);
378 UDP6_INC_STATS_BH(UDP_MIB_INDATAGRAMS);
382 static struct sock *udp_v6_mcast_next(struct sock *sk,
383 u16 loc_port, struct in6_addr *loc_addr,
384 u16 rmt_port, struct in6_addr *rmt_addr,
387 struct hlist_node *node;
389 unsigned short num = ntohs(loc_port);
391 sk_for_each_from(s, node) {
392 struct inet_sock *inet = inet_sk(s);
394 if (inet->num == num && s->sk_family == PF_INET6) {
395 struct ipv6_pinfo *np = inet6_sk(s);
397 if (inet->dport != rmt_port)
400 if (!ipv6_addr_any(&np->daddr) &&
401 !ipv6_addr_equal(&np->daddr, rmt_addr))
404 if (s->sk_bound_dev_if && s->sk_bound_dev_if != dif)
407 if (!ipv6_addr_any(&np->rcv_saddr)) {
408 if (ipv6_addr_equal(&np->rcv_saddr, loc_addr))
412 if(!inet6_mc_check(s, loc_addr, rmt_addr))
421 * Note: called only from the BH handler context,
422 * so we don't need to lock the hashes.
424 static void udpv6_mcast_deliver(struct udphdr *uh,
425 struct in6_addr *saddr, struct in6_addr *daddr,
428 struct sock *sk, *sk2;
431 read_lock(&udp_hash_lock);
432 sk = sk_head(&udp_hash[ntohs(uh->dest) & (UDP_HTABLE_SIZE - 1)]);
433 dif = skb->dev->ifindex;
434 sk = udp_v6_mcast_next(sk, uh->dest, daddr, uh->source, saddr, dif);
441 while ((sk2 = udp_v6_mcast_next(sk_next(sk2), uh->dest, daddr,
442 uh->source, saddr, dif))) {
443 struct sk_buff *buff = skb_clone(skb, GFP_ATOMIC);
445 udpv6_queue_rcv_skb(sk2, buff);
447 udpv6_queue_rcv_skb(sk, skb);
449 read_unlock(&udp_hash_lock);
452 static int udpv6_rcv(struct sk_buff **pskb, unsigned int *nhoffp)
454 struct sk_buff *skb = *pskb;
457 struct net_device *dev = skb->dev;
458 struct in6_addr *saddr, *daddr;
461 if (!pskb_may_pull(skb, sizeof(struct udphdr)))
464 saddr = &skb->nh.ipv6h->saddr;
465 daddr = &skb->nh.ipv6h->daddr;
468 ulen = ntohs(uh->len);
470 /* Check for jumbo payload */
474 if (ulen > skb->len || ulen < sizeof(*uh))
477 if (uh->check == 0) {
478 /* RFC 2460 section 8.1 says that we SHOULD log
479 this error. Well, it is reasonable.
481 LIMIT_NETDEBUG(KERN_INFO "IPv6: udp checksum is 0\n");
485 if (ulen < skb->len) {
486 if (pskb_trim_rcsum(skb, ulen))
488 saddr = &skb->nh.ipv6h->saddr;
489 daddr = &skb->nh.ipv6h->daddr;
493 if (skb->ip_summed==CHECKSUM_HW) {
494 skb->ip_summed = CHECKSUM_UNNECESSARY;
495 if (csum_ipv6_magic(saddr, daddr, ulen, IPPROTO_UDP, skb->csum)) {
496 LIMIT_NETDEBUG(KERN_DEBUG "udp v6 hw csum failure.\n");
497 skb->ip_summed = CHECKSUM_NONE;
500 if (skb->ip_summed != CHECKSUM_UNNECESSARY)
501 skb->csum = ~csum_ipv6_magic(saddr, daddr, ulen, IPPROTO_UDP, 0);
504 * Multicast receive code
506 if (ipv6_addr_is_multicast(daddr)) {
507 udpv6_mcast_deliver(uh, saddr, daddr, skb);
514 * check socket cache ... must talk to Alan about his plans
515 * for sock caches... i'll skip this for now.
517 sk = udp_v6_lookup(saddr, uh->source, daddr, uh->dest, dev->ifindex);
520 if (!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb))
523 if (skb->ip_summed != CHECKSUM_UNNECESSARY &&
524 (unsigned short)csum_fold(skb_checksum(skb, 0, skb->len, skb->csum)))
526 UDP6_INC_STATS_BH(UDP_MIB_NOPORTS);
528 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0, dev);
536 udpv6_queue_rcv_skb(sk, skb);
542 printk(KERN_DEBUG "UDP: short packet: %d/%u\n", ulen, skb->len);
545 UDP6_INC_STATS_BH(UDP_MIB_INERRORS);
550 * Throw away all pending data and cancel the corking. Socket is locked.
552 static void udp_v6_flush_pending_frames(struct sock *sk)
554 struct udp_sock *up = udp_sk(sk);
559 ip6_flush_pending_frames(sk);
567 static int udp_v6_push_pending_frames(struct sock *sk, struct udp_sock *up)
571 struct inet_sock *inet = inet_sk(sk);
572 struct flowi *fl = &inet->cork.fl;
575 /* Grab the skbuff where UDP header space exists. */
576 if ((skb = skb_peek(&sk->sk_write_queue)) == NULL)
580 * Create a UDP header
583 uh->source = fl->fl_ip_sport;
584 uh->dest = fl->fl_ip_dport;
585 uh->len = htons(up->len);
588 if (sk->sk_no_check == UDP_CSUM_NOXMIT) {
589 skb->ip_summed = CHECKSUM_NONE;
593 if (skb_queue_len(&sk->sk_write_queue) == 1) {
594 skb->csum = csum_partial((char *)uh,
595 sizeof(struct udphdr), skb->csum);
596 uh->check = csum_ipv6_magic(&fl->fl6_src,
598 up->len, fl->proto, skb->csum);
602 skb_queue_walk(&sk->sk_write_queue, skb) {
603 tmp_csum = csum_add(tmp_csum, skb->csum);
605 tmp_csum = csum_partial((char *)uh,
606 sizeof(struct udphdr), tmp_csum);
607 tmp_csum = csum_ipv6_magic(&fl->fl6_src,
609 up->len, fl->proto, tmp_csum);
610 uh->check = tmp_csum;
617 err = ip6_push_pending_frames(sk);
624 static int udpv6_sendmsg(struct kiocb *iocb, struct sock *sk,
625 struct msghdr *msg, size_t len)
627 struct ipv6_txoptions opt_space;
628 struct udp_sock *up = udp_sk(sk);
629 struct inet_sock *inet = inet_sk(sk);
630 struct ipv6_pinfo *np = inet6_sk(sk);
631 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) msg->msg_name;
632 struct in6_addr *daddr, *final_p = NULL, final;
633 struct ipv6_txoptions *opt = NULL;
634 struct ip6_flowlabel *flowlabel = NULL;
635 struct flowi *fl = &inet->cork.fl;
636 struct dst_entry *dst;
637 int addr_len = msg->msg_namelen;
641 int corkreq = up->corkflag || msg->msg_flags&MSG_MORE;
644 /* destination address check */
646 if (addr_len < offsetof(struct sockaddr, sa_data))
649 switch (sin6->sin6_family) {
651 if (addr_len < SIN6_LEN_RFC2133)
653 daddr = &sin6->sin6_addr;
658 msg->msg_name = sin6 = NULL;
659 msg->msg_namelen = addr_len = 0;
665 } else if (!up->pending) {
666 if (sk->sk_state != TCP_ESTABLISHED)
667 return -EDESTADDRREQ;
673 if (ipv6_addr_type(daddr) == IPV6_ADDR_MAPPED) {
674 struct sockaddr_in sin;
675 sin.sin_family = AF_INET;
676 sin.sin_port = sin6 ? sin6->sin6_port : inet->dport;
677 sin.sin_addr.s_addr = daddr->s6_addr32[3];
678 msg->msg_name = &sin;
679 msg->msg_namelen = sizeof(sin);
681 if (__ipv6_only_sock(sk))
683 return udp_sendmsg(iocb, sk, msg, len);
687 if (up->pending == AF_INET)
688 return udp_sendmsg(iocb, sk, msg, len);
690 /* Rough check on arithmetic overflow,
691 better check is made in ip6_build_xmit
693 if (len > INT_MAX - sizeof(struct udphdr))
698 * There are pending frames.
699 * The socket lock must be held while it's corked.
702 if (likely(up->pending)) {
703 if (unlikely(up->pending != AF_INET6)) {
705 return -EAFNOSUPPORT;
712 ulen += sizeof(struct udphdr);
714 memset(fl, 0, sizeof(*fl));
717 if (sin6->sin6_port == 0)
720 fl->fl_ip_dport = sin6->sin6_port;
721 daddr = &sin6->sin6_addr;
724 fl->fl6_flowlabel = sin6->sin6_flowinfo&IPV6_FLOWINFO_MASK;
725 if (fl->fl6_flowlabel&IPV6_FLOWLABEL_MASK) {
726 flowlabel = fl6_sock_lookup(sk, fl->fl6_flowlabel);
727 if (flowlabel == NULL)
729 daddr = &flowlabel->dst;
734 * Otherwise it will be difficult to maintain
737 if (sk->sk_state == TCP_ESTABLISHED &&
738 ipv6_addr_equal(daddr, &np->daddr))
741 if (addr_len >= sizeof(struct sockaddr_in6) &&
742 sin6->sin6_scope_id &&
743 ipv6_addr_type(daddr)&IPV6_ADDR_LINKLOCAL)
744 fl->oif = sin6->sin6_scope_id;
746 if (sk->sk_state != TCP_ESTABLISHED)
747 return -EDESTADDRREQ;
749 fl->fl_ip_dport = inet->dport;
751 fl->fl6_flowlabel = np->flow_label;
755 fl->oif = sk->sk_bound_dev_if;
757 if (msg->msg_controllen) {
759 memset(opt, 0, sizeof(struct ipv6_txoptions));
760 opt->tot_len = sizeof(*opt);
762 err = datagram_send_ctl(msg, fl, opt, &hlimit, &tclass);
764 fl6_sock_release(flowlabel);
767 if ((fl->fl6_flowlabel&IPV6_FLOWLABEL_MASK) && !flowlabel) {
768 flowlabel = fl6_sock_lookup(sk, fl->fl6_flowlabel);
769 if (flowlabel == NULL)
772 if (!(opt->opt_nflen|opt->opt_flen))
777 opt = fl6_merge_options(&opt_space, flowlabel, opt);
779 fl->proto = IPPROTO_UDP;
780 ipv6_addr_copy(&fl->fl6_dst, daddr);
781 if (ipv6_addr_any(&fl->fl6_src) && !ipv6_addr_any(&np->saddr))
782 ipv6_addr_copy(&fl->fl6_src, &np->saddr);
783 fl->fl_ip_sport = inet->sport;
785 /* merge ip6_build_xmit from ip6_output */
786 if (opt && opt->srcrt) {
787 struct rt0_hdr *rt0 = (struct rt0_hdr *) opt->srcrt;
788 ipv6_addr_copy(&final, &fl->fl6_dst);
789 ipv6_addr_copy(&fl->fl6_dst, rt0->addr);
793 if (!fl->oif && ipv6_addr_is_multicast(&fl->fl6_dst))
794 fl->oif = np->mcast_oif;
796 err = ip6_dst_lookup(sk, &dst, fl);
800 ipv6_addr_copy(&fl->fl6_dst, final_p);
802 if ((err = xfrm_lookup(&dst, fl, sk, 0)) < 0)
806 if (ipv6_addr_is_multicast(&fl->fl6_dst))
807 hlimit = np->mcast_hops;
809 hlimit = np->hop_limit;
811 hlimit = dst_metric(dst, RTAX_HOPLIMIT);
813 hlimit = ipv6_get_hoplimit(dst->dev);
822 if (msg->msg_flags&MSG_CONFIRM)
827 if (unlikely(up->pending)) {
828 /* The socket is already corked while preparing it. */
829 /* ... which is an evident application bug. --ANK */
832 LIMIT_NETDEBUG(KERN_DEBUG "udp cork app bug 2\n");
837 up->pending = AF_INET6;
841 err = ip6_append_data(sk, ip_generic_getfrag, msg->msg_iov, ulen,
842 sizeof(struct udphdr), hlimit, tclass, opt, fl,
843 (struct rt6_info*)dst,
844 corkreq ? msg->msg_flags|MSG_MORE : msg->msg_flags);
846 udp_v6_flush_pending_frames(sk);
848 err = udp_v6_push_pending_frames(sk, up);
851 ip6_dst_store(sk, dst,
852 ipv6_addr_equal(&fl->fl6_dst, &np->daddr) ?
855 err = np->recverr ? net_xmit_errno(err) : 0;
858 fl6_sock_release(flowlabel);
860 UDP6_INC_STATS_USER(UDP_MIB_OUTDATAGRAMS);
867 if (!(msg->msg_flags&MSG_PROBE) || len)
868 goto back_from_confirm;
873 static int udpv6_destroy_sock(struct sock *sk)
876 udp_v6_flush_pending_frames(sk);
879 inet6_destroy_sock(sk);
885 * Socket option code for UDP
887 static int udpv6_setsockopt(struct sock *sk, int level, int optname,
888 char __user *optval, int optlen)
890 struct udp_sock *up = udp_sk(sk);
894 if (level != SOL_UDP)
895 return ipv6_setsockopt(sk, level, optname, optval, optlen);
897 if(optlen<sizeof(int))
900 if (get_user(val, (int __user *)optval))
910 udp_v6_push_pending_frames(sk, up);
918 up->encap_type = val;
934 static int udpv6_getsockopt(struct sock *sk, int level, int optname,
935 char __user *optval, int __user *optlen)
937 struct udp_sock *up = udp_sk(sk);
940 if (level != SOL_UDP)
941 return ipv6_getsockopt(sk, level, optname, optval, optlen);
943 if(get_user(len,optlen))
946 len = min_t(unsigned int, len, sizeof(int));
957 val = up->encap_type;
964 if(put_user(len, optlen))
966 if(copy_to_user(optval, &val,len))
971 static struct inet6_protocol udpv6_protocol = {
972 .handler = udpv6_rcv,
973 .err_handler = udpv6_err,
974 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
977 /* ------------------------------------------------------------------------ */
978 #ifdef CONFIG_PROC_FS
980 static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket)
982 struct inet_sock *inet = inet_sk(sp);
983 struct ipv6_pinfo *np = inet6_sk(sp);
984 struct in6_addr *dest, *src;
988 src = &np->rcv_saddr;
989 destp = ntohs(inet->dport);
990 srcp = ntohs(inet->sport);
992 "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X "
993 "%02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p\n",
995 src->s6_addr32[0], src->s6_addr32[1],
996 src->s6_addr32[2], src->s6_addr32[3], srcp,
997 dest->s6_addr32[0], dest->s6_addr32[1],
998 dest->s6_addr32[2], dest->s6_addr32[3], destp,
1000 atomic_read(&sp->sk_wmem_alloc),
1001 atomic_read(&sp->sk_rmem_alloc),
1005 atomic_read(&sp->sk_refcnt), sp);
1008 static int udp6_seq_show(struct seq_file *seq, void *v)
1010 if (v == SEQ_START_TOKEN)
1015 "st tx_queue rx_queue tr tm->when retrnsmt"
1016 " uid timeout inode\n");
1018 udp6_sock_seq_show(seq, v, ((struct udp_iter_state *)seq->private)->bucket);
1022 static struct file_operations udp6_seq_fops;
1023 static struct udp_seq_afinfo udp6_seq_afinfo = {
1024 .owner = THIS_MODULE,
1027 .seq_show = udp6_seq_show,
1028 .seq_fops = &udp6_seq_fops,
1031 int __init udp6_proc_init(void)
1033 return udp_proc_register(&udp6_seq_afinfo);
1036 void udp6_proc_exit(void) {
1037 udp_proc_unregister(&udp6_seq_afinfo);
1039 #endif /* CONFIG_PROC_FS */
1041 /* ------------------------------------------------------------------------ */
1043 struct proto udpv6_prot = {
1045 .owner = THIS_MODULE,
1046 .close = udpv6_close,
1047 .connect = ip6_datagram_connect,
1048 .disconnect = udp_disconnect,
1050 .destroy = udpv6_destroy_sock,
1051 .setsockopt = udpv6_setsockopt,
1052 .getsockopt = udpv6_getsockopt,
1053 .sendmsg = udpv6_sendmsg,
1054 .recvmsg = udpv6_recvmsg,
1055 .backlog_rcv = udpv6_queue_rcv_skb,
1056 .hash = udp_v6_hash,
1057 .unhash = udp_v6_unhash,
1058 .get_port = udp_v6_get_port,
1059 .obj_size = sizeof(struct udp6_sock),
1062 static struct inet_protosw udpv6_protosw = {
1064 .protocol = IPPROTO_UDP,
1065 .prot = &udpv6_prot,
1066 .ops = &inet6_dgram_ops,
1068 .no_check = UDP_CSUM_DEFAULT,
1069 .flags = INET_PROTOSW_PERMANENT,
1073 void __init udpv6_init(void)
1075 if (inet6_add_protocol(&udpv6_protocol, IPPROTO_UDP) < 0)
1076 printk(KERN_ERR "udpv6_init: Could not register protocol\n");
1077 inet6_register_protosw(&udpv6_protosw);