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/errno.h>
27 #include <linux/types.h>
28 #include <linux/socket.h>
29 #include <linux/sockios.h>
30 #include <linux/sched.h>
31 #include <linux/net.h>
32 #include <linux/in6.h>
33 #include <linux/netdevice.h>
34 #include <linux/if_arp.h>
35 #include <linux/ipv6.h>
36 #include <linux/icmpv6.h>
37 #include <linux/init.h>
38 #include <linux/skbuff.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 static inline int udp_v6_get_port(struct sock
*sk
, unsigned short snum
)
66 return udp_get_port(sk
, snum
, ipv6_rcv_saddr_equal
);
69 static void udp_v6_hash(struct sock
*sk
)
74 static void udp_v6_unhash(struct sock
*sk
)
76 write_lock_bh(&udp_hash_lock
);
77 if (sk_del_node_init(sk
)) {
79 sock_prot_dec_use(sk
->sk_prot
);
81 write_unlock_bh(&udp_hash_lock
);
84 static struct sock
*udp_v6_lookup(struct in6_addr
*saddr
, u16 sport
,
85 struct in6_addr
*daddr
, u16 dport
, int dif
)
87 struct sock
*sk
, *result
= NULL
;
88 struct hlist_node
*node
;
89 unsigned short hnum
= ntohs(dport
);
92 read_lock(&udp_hash_lock
);
93 sk_for_each(sk
, node
, &udp_hash
[hnum
& (UDP_HTABLE_SIZE
- 1)]) {
94 struct inet_sock
*inet
= inet_sk(sk
);
96 if (inet
->num
== hnum
&& sk
->sk_family
== PF_INET6
) {
97 struct ipv6_pinfo
*np
= inet6_sk(sk
);
100 if (inet
->dport
!= sport
)
104 if (!ipv6_addr_any(&np
->rcv_saddr
)) {
105 if (!ipv6_addr_equal(&np
->rcv_saddr
, daddr
))
109 if (!ipv6_addr_any(&np
->daddr
)) {
110 if (!ipv6_addr_equal(&np
->daddr
, saddr
))
114 if (sk
->sk_bound_dev_if
) {
115 if (sk
->sk_bound_dev_if
!= dif
)
122 } else if(score
> badness
) {
130 read_unlock(&udp_hash_lock
);
138 static void udpv6_close(struct sock
*sk
, long timeout
)
140 sk_common_release(sk
);
144 * This should be easy, if there is something there we
145 * return it, otherwise we block.
148 static int udpv6_recvmsg(struct kiocb
*iocb
, struct sock
*sk
,
149 struct msghdr
*msg
, size_t len
,
150 int noblock
, int flags
, int *addr_len
)
152 struct ipv6_pinfo
*np
= inet6_sk(sk
);
153 struct inet_sock
*inet
= inet_sk(sk
);
159 *addr_len
=sizeof(struct sockaddr_in6
);
161 if (flags
& MSG_ERRQUEUE
)
162 return ipv6_recv_error(sk
, msg
, len
);
165 skb
= skb_recv_datagram(sk
, flags
, noblock
, &err
);
169 copied
= skb
->len
- sizeof(struct udphdr
);
172 msg
->msg_flags
|= MSG_TRUNC
;
175 if (skb
->ip_summed
==CHECKSUM_UNNECESSARY
) {
176 err
= skb_copy_datagram_iovec(skb
, sizeof(struct udphdr
), msg
->msg_iov
,
178 } else if (msg
->msg_flags
&MSG_TRUNC
) {
179 if (__skb_checksum_complete(skb
))
181 err
= skb_copy_datagram_iovec(skb
, sizeof(struct udphdr
), msg
->msg_iov
,
184 err
= skb_copy_and_csum_datagram_iovec(skb
, sizeof(struct udphdr
), msg
->msg_iov
);
191 sock_recv_timestamp(msg
, sk
, skb
);
193 /* Copy the address. */
195 struct sockaddr_in6
*sin6
;
197 sin6
= (struct sockaddr_in6
*) msg
->msg_name
;
198 sin6
->sin6_family
= AF_INET6
;
199 sin6
->sin6_port
= skb
->h
.uh
->source
;
200 sin6
->sin6_flowinfo
= 0;
201 sin6
->sin6_scope_id
= 0;
203 if (skb
->protocol
== htons(ETH_P_IP
))
204 ipv6_addr_set(&sin6
->sin6_addr
, 0, 0,
205 htonl(0xffff), skb
->nh
.iph
->saddr
);
207 ipv6_addr_copy(&sin6
->sin6_addr
, &skb
->nh
.ipv6h
->saddr
);
208 if (ipv6_addr_type(&sin6
->sin6_addr
) & IPV6_ADDR_LINKLOCAL
)
209 sin6
->sin6_scope_id
= IP6CB(skb
)->iif
;
213 if (skb
->protocol
== htons(ETH_P_IP
)) {
214 if (inet
->cmsg_flags
)
215 ip_cmsg_recv(msg
, skb
);
218 datagram_recv_ctl(sk
, msg
, skb
);
222 if (flags
& MSG_TRUNC
)
223 err
= skb
->len
- sizeof(struct udphdr
);
226 skb_free_datagram(sk
, skb
);
231 skb_kill_datagram(sk
, skb
, flags
);
233 if (flags
& MSG_DONTWAIT
) {
234 UDP6_INC_STATS_USER(UDP_MIB_INERRORS
);
240 static void udpv6_err(struct sk_buff
*skb
, struct inet6_skb_parm
*opt
,
241 int type
, int code
, int offset
, __u32 info
)
243 struct ipv6_pinfo
*np
;
244 struct ipv6hdr
*hdr
= (struct ipv6hdr
*)skb
->data
;
245 struct in6_addr
*saddr
= &hdr
->saddr
;
246 struct in6_addr
*daddr
= &hdr
->daddr
;
247 struct udphdr
*uh
= (struct udphdr
*)(skb
->data
+offset
);
251 sk
= udp_v6_lookup(daddr
, uh
->dest
, saddr
, uh
->source
, inet6_iif(skb
));
258 if (!icmpv6_err_convert(type
, code
, &err
) && !np
->recverr
)
261 if (sk
->sk_state
!= TCP_ESTABLISHED
&& !np
->recverr
)
265 ipv6_icmp_error(sk
, skb
, err
, uh
->dest
, ntohl(info
), (u8
*)(uh
+1));
268 sk
->sk_error_report(sk
);
273 static inline int udpv6_queue_rcv_skb(struct sock
* sk
, struct sk_buff
*skb
)
277 if (!xfrm6_policy_check(sk
, XFRM_POLICY_IN
, skb
)) {
282 if (skb_checksum_complete(skb
)) {
283 UDP6_INC_STATS_BH(UDP_MIB_INERRORS
);
288 if ((rc
= sock_queue_rcv_skb(sk
,skb
)) < 0) {
289 /* Note that an ENOMEM error is charged twice */
291 UDP6_INC_STATS_BH(UDP_MIB_RCVBUFERRORS
);
292 UDP6_INC_STATS_BH(UDP_MIB_INERRORS
);
296 UDP6_INC_STATS_BH(UDP_MIB_INDATAGRAMS
);
300 static struct sock
*udp_v6_mcast_next(struct sock
*sk
,
301 u16 loc_port
, struct in6_addr
*loc_addr
,
302 u16 rmt_port
, struct in6_addr
*rmt_addr
,
305 struct hlist_node
*node
;
307 unsigned short num
= ntohs(loc_port
);
309 sk_for_each_from(s
, node
) {
310 struct inet_sock
*inet
= inet_sk(s
);
312 if (inet
->num
== num
&& s
->sk_family
== PF_INET6
) {
313 struct ipv6_pinfo
*np
= inet6_sk(s
);
315 if (inet
->dport
!= rmt_port
)
318 if (!ipv6_addr_any(&np
->daddr
) &&
319 !ipv6_addr_equal(&np
->daddr
, rmt_addr
))
322 if (s
->sk_bound_dev_if
&& s
->sk_bound_dev_if
!= dif
)
325 if (!ipv6_addr_any(&np
->rcv_saddr
)) {
326 if (!ipv6_addr_equal(&np
->rcv_saddr
, loc_addr
))
329 if(!inet6_mc_check(s
, loc_addr
, rmt_addr
))
338 * Note: called only from the BH handler context,
339 * so we don't need to lock the hashes.
341 static void udpv6_mcast_deliver(struct udphdr
*uh
,
342 struct in6_addr
*saddr
, struct in6_addr
*daddr
,
345 struct sock
*sk
, *sk2
;
348 read_lock(&udp_hash_lock
);
349 sk
= sk_head(&udp_hash
[ntohs(uh
->dest
) & (UDP_HTABLE_SIZE
- 1)]);
350 dif
= inet6_iif(skb
);
351 sk
= udp_v6_mcast_next(sk
, uh
->dest
, daddr
, uh
->source
, saddr
, dif
);
358 while ((sk2
= udp_v6_mcast_next(sk_next(sk2
), uh
->dest
, daddr
,
359 uh
->source
, saddr
, dif
))) {
360 struct sk_buff
*buff
= skb_clone(skb
, GFP_ATOMIC
);
362 udpv6_queue_rcv_skb(sk2
, buff
);
364 udpv6_queue_rcv_skb(sk
, skb
);
366 read_unlock(&udp_hash_lock
);
369 static int udpv6_rcv(struct sk_buff
**pskb
)
371 struct sk_buff
*skb
= *pskb
;
374 struct net_device
*dev
= skb
->dev
;
375 struct in6_addr
*saddr
, *daddr
;
378 if (!pskb_may_pull(skb
, sizeof(struct udphdr
)))
381 saddr
= &skb
->nh
.ipv6h
->saddr
;
382 daddr
= &skb
->nh
.ipv6h
->daddr
;
385 ulen
= ntohs(uh
->len
);
387 /* Check for jumbo payload */
391 if (ulen
> skb
->len
|| ulen
< sizeof(*uh
))
394 if (uh
->check
== 0) {
395 /* RFC 2460 section 8.1 says that we SHOULD log
396 this error. Well, it is reasonable.
398 LIMIT_NETDEBUG(KERN_INFO
"IPv6: udp checksum is 0\n");
402 if (ulen
< skb
->len
) {
403 if (pskb_trim_rcsum(skb
, ulen
))
405 saddr
= &skb
->nh
.ipv6h
->saddr
;
406 daddr
= &skb
->nh
.ipv6h
->daddr
;
410 if (skb
->ip_summed
== CHECKSUM_COMPLETE
&&
411 !csum_ipv6_magic(saddr
, daddr
, ulen
, IPPROTO_UDP
, skb
->csum
))
412 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
414 if (skb
->ip_summed
!= CHECKSUM_UNNECESSARY
)
415 skb
->csum
= ~csum_ipv6_magic(saddr
, daddr
, ulen
, IPPROTO_UDP
, 0);
418 * Multicast receive code
420 if (ipv6_addr_is_multicast(daddr
)) {
421 udpv6_mcast_deliver(uh
, saddr
, daddr
, skb
);
428 * check socket cache ... must talk to Alan about his plans
429 * for sock caches... i'll skip this for now.
431 sk
= udp_v6_lookup(saddr
, uh
->source
, daddr
, uh
->dest
, inet6_iif(skb
));
434 if (!xfrm6_policy_check(NULL
, XFRM_POLICY_IN
, skb
))
437 if (skb_checksum_complete(skb
))
439 UDP6_INC_STATS_BH(UDP_MIB_NOPORTS
);
441 icmpv6_send(skb
, ICMPV6_DEST_UNREACH
, ICMPV6_PORT_UNREACH
, 0, dev
);
449 udpv6_queue_rcv_skb(sk
, skb
);
455 printk(KERN_DEBUG
"UDP: short packet: %d/%u\n", ulen
, skb
->len
);
458 UDP6_INC_STATS_BH(UDP_MIB_INERRORS
);
463 * Throw away all pending data and cancel the corking. Socket is locked.
465 static void udp_v6_flush_pending_frames(struct sock
*sk
)
467 struct udp_sock
*up
= udp_sk(sk
);
472 ip6_flush_pending_frames(sk
);
480 static int udp_v6_push_pending_frames(struct sock
*sk
, struct udp_sock
*up
)
484 struct inet_sock
*inet
= inet_sk(sk
);
485 struct flowi
*fl
= &inet
->cork
.fl
;
488 /* Grab the skbuff where UDP header space exists. */
489 if ((skb
= skb_peek(&sk
->sk_write_queue
)) == NULL
)
493 * Create a UDP header
496 uh
->source
= fl
->fl_ip_sport
;
497 uh
->dest
= fl
->fl_ip_dport
;
498 uh
->len
= htons(up
->len
);
501 if (sk
->sk_no_check
== UDP_CSUM_NOXMIT
) {
502 skb
->ip_summed
= CHECKSUM_NONE
;
506 if (skb_queue_len(&sk
->sk_write_queue
) == 1) {
507 skb
->csum
= csum_partial((char *)uh
,
508 sizeof(struct udphdr
), skb
->csum
);
509 uh
->check
= csum_ipv6_magic(&fl
->fl6_src
,
511 up
->len
, fl
->proto
, skb
->csum
);
515 skb_queue_walk(&sk
->sk_write_queue
, skb
) {
516 tmp_csum
= csum_add(tmp_csum
, skb
->csum
);
518 tmp_csum
= csum_partial((char *)uh
,
519 sizeof(struct udphdr
), tmp_csum
);
520 tmp_csum
= csum_ipv6_magic(&fl
->fl6_src
,
522 up
->len
, fl
->proto
, tmp_csum
);
523 uh
->check
= tmp_csum
;
530 err
= ip6_push_pending_frames(sk
);
537 static int udpv6_sendmsg(struct kiocb
*iocb
, struct sock
*sk
,
538 struct msghdr
*msg
, size_t len
)
540 struct ipv6_txoptions opt_space
;
541 struct udp_sock
*up
= udp_sk(sk
);
542 struct inet_sock
*inet
= inet_sk(sk
);
543 struct ipv6_pinfo
*np
= inet6_sk(sk
);
544 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*) msg
->msg_name
;
545 struct in6_addr
*daddr
, *final_p
= NULL
, final
;
546 struct ipv6_txoptions
*opt
= NULL
;
547 struct ip6_flowlabel
*flowlabel
= NULL
;
549 struct dst_entry
*dst
;
550 int addr_len
= msg
->msg_namelen
;
554 int corkreq
= up
->corkflag
|| msg
->msg_flags
&MSG_MORE
;
558 /* destination address check */
560 if (addr_len
< offsetof(struct sockaddr
, sa_data
))
563 switch (sin6
->sin6_family
) {
565 if (addr_len
< SIN6_LEN_RFC2133
)
567 daddr
= &sin6
->sin6_addr
;
572 msg
->msg_name
= sin6
= NULL
;
573 msg
->msg_namelen
= addr_len
= 0;
579 } else if (!up
->pending
) {
580 if (sk
->sk_state
!= TCP_ESTABLISHED
)
581 return -EDESTADDRREQ
;
587 if (ipv6_addr_type(daddr
) == IPV6_ADDR_MAPPED
) {
588 struct sockaddr_in sin
;
589 sin
.sin_family
= AF_INET
;
590 sin
.sin_port
= sin6
? sin6
->sin6_port
: inet
->dport
;
591 sin
.sin_addr
.s_addr
= daddr
->s6_addr32
[3];
592 msg
->msg_name
= &sin
;
593 msg
->msg_namelen
= sizeof(sin
);
595 if (__ipv6_only_sock(sk
))
597 return udp_sendmsg(iocb
, sk
, msg
, len
);
601 if (up
->pending
== AF_INET
)
602 return udp_sendmsg(iocb
, sk
, msg
, len
);
604 /* Rough check on arithmetic overflow,
605 better check is made in ip6_build_xmit
607 if (len
> INT_MAX
- sizeof(struct udphdr
))
612 * There are pending frames.
613 * The socket lock must be held while it's corked.
616 if (likely(up
->pending
)) {
617 if (unlikely(up
->pending
!= AF_INET6
)) {
619 return -EAFNOSUPPORT
;
626 ulen
+= sizeof(struct udphdr
);
628 memset(&fl
, 0, sizeof(fl
));
631 if (sin6
->sin6_port
== 0)
634 fl
.fl_ip_dport
= sin6
->sin6_port
;
635 daddr
= &sin6
->sin6_addr
;
638 fl
.fl6_flowlabel
= sin6
->sin6_flowinfo
&IPV6_FLOWINFO_MASK
;
639 if (fl
.fl6_flowlabel
&IPV6_FLOWLABEL_MASK
) {
640 flowlabel
= fl6_sock_lookup(sk
, fl
.fl6_flowlabel
);
641 if (flowlabel
== NULL
)
643 daddr
= &flowlabel
->dst
;
648 * Otherwise it will be difficult to maintain
651 if (sk
->sk_state
== TCP_ESTABLISHED
&&
652 ipv6_addr_equal(daddr
, &np
->daddr
))
655 if (addr_len
>= sizeof(struct sockaddr_in6
) &&
656 sin6
->sin6_scope_id
&&
657 ipv6_addr_type(daddr
)&IPV6_ADDR_LINKLOCAL
)
658 fl
.oif
= sin6
->sin6_scope_id
;
660 if (sk
->sk_state
!= TCP_ESTABLISHED
)
661 return -EDESTADDRREQ
;
663 fl
.fl_ip_dport
= inet
->dport
;
665 fl
.fl6_flowlabel
= np
->flow_label
;
670 fl
.oif
= sk
->sk_bound_dev_if
;
672 if (msg
->msg_controllen
) {
674 memset(opt
, 0, sizeof(struct ipv6_txoptions
));
675 opt
->tot_len
= sizeof(*opt
);
677 err
= datagram_send_ctl(msg
, &fl
, opt
, &hlimit
, &tclass
);
679 fl6_sock_release(flowlabel
);
682 if ((fl
.fl6_flowlabel
&IPV6_FLOWLABEL_MASK
) && !flowlabel
) {
683 flowlabel
= fl6_sock_lookup(sk
, fl
.fl6_flowlabel
);
684 if (flowlabel
== NULL
)
687 if (!(opt
->opt_nflen
|opt
->opt_flen
))
694 opt
= fl6_merge_options(&opt_space
, flowlabel
, opt
);
695 opt
= ipv6_fixup_options(&opt_space
, opt
);
697 fl
.proto
= IPPROTO_UDP
;
698 ipv6_addr_copy(&fl
.fl6_dst
, daddr
);
699 if (ipv6_addr_any(&fl
.fl6_src
) && !ipv6_addr_any(&np
->saddr
))
700 ipv6_addr_copy(&fl
.fl6_src
, &np
->saddr
);
701 fl
.fl_ip_sport
= inet
->sport
;
703 /* merge ip6_build_xmit from ip6_output */
704 if (opt
&& opt
->srcrt
) {
705 struct rt0_hdr
*rt0
= (struct rt0_hdr
*) opt
->srcrt
;
706 ipv6_addr_copy(&final
, &fl
.fl6_dst
);
707 ipv6_addr_copy(&fl
.fl6_dst
, rt0
->addr
);
712 if (!fl
.oif
&& ipv6_addr_is_multicast(&fl
.fl6_dst
)) {
713 fl
.oif
= np
->mcast_oif
;
717 security_sk_classify_flow(sk
, &fl
);
719 err
= ip6_sk_dst_lookup(sk
, &dst
, &fl
);
723 ipv6_addr_copy(&fl
.fl6_dst
, final_p
);
725 if ((err
= xfrm_lookup(&dst
, &fl
, sk
, 0)) < 0)
729 if (ipv6_addr_is_multicast(&fl
.fl6_dst
))
730 hlimit
= np
->mcast_hops
;
732 hlimit
= np
->hop_limit
;
734 hlimit
= dst_metric(dst
, RTAX_HOPLIMIT
);
736 hlimit
= ipv6_get_hoplimit(dst
->dev
);
745 if (msg
->msg_flags
&MSG_CONFIRM
)
750 if (unlikely(up
->pending
)) {
751 /* The socket is already corked while preparing it. */
752 /* ... which is an evident application bug. --ANK */
755 LIMIT_NETDEBUG(KERN_DEBUG
"udp cork app bug 2\n");
760 up
->pending
= AF_INET6
;
764 err
= ip6_append_data(sk
, ip_generic_getfrag
, msg
->msg_iov
, ulen
,
765 sizeof(struct udphdr
), hlimit
, tclass
, opt
, &fl
,
766 (struct rt6_info
*)dst
,
767 corkreq
? msg
->msg_flags
|MSG_MORE
: msg
->msg_flags
);
769 udp_v6_flush_pending_frames(sk
);
771 err
= udp_v6_push_pending_frames(sk
, up
);
772 else if (unlikely(skb_queue_empty(&sk
->sk_write_queue
)))
777 ip6_dst_store(sk
, dst
,
778 ipv6_addr_equal(&fl
.fl6_dst
, &np
->daddr
) ?
780 #ifdef CONFIG_IPV6_SUBTREES
781 ipv6_addr_equal(&fl
.fl6_src
, &np
->saddr
) ?
791 err
= np
->recverr
? net_xmit_errno(err
) : 0;
794 fl6_sock_release(flowlabel
);
796 UDP6_INC_STATS_USER(UDP_MIB_OUTDATAGRAMS
);
800 * ENOBUFS = no kernel mem, SOCK_NOSPACE = no sndbuf space. Reporting
801 * ENOBUFS might not be good (it's not tunable per se), but otherwise
802 * we don't have a good statistic (IpOutDiscards but it can be too many
803 * things). We could add another new stat but at least for now that
804 * seems like overkill.
806 if (err
== -ENOBUFS
|| test_bit(SOCK_NOSPACE
, &sk
->sk_socket
->flags
)) {
807 UDP6_INC_STATS_USER(UDP_MIB_SNDBUFERRORS
);
813 if (!(msg
->msg_flags
&MSG_PROBE
) || len
)
814 goto back_from_confirm
;
819 static int udpv6_destroy_sock(struct sock
*sk
)
822 udp_v6_flush_pending_frames(sk
);
825 inet6_destroy_sock(sk
);
831 * Socket option code for UDP
833 static int do_udpv6_setsockopt(struct sock
*sk
, int level
, int optname
,
834 char __user
*optval
, int optlen
)
836 struct udp_sock
*up
= udp_sk(sk
);
840 if(optlen
<sizeof(int))
843 if (get_user(val
, (int __user
*)optval
))
853 udp_v6_push_pending_frames(sk
, up
);
861 up
->encap_type
= val
;
877 static int udpv6_setsockopt(struct sock
*sk
, int level
, int optname
,
878 char __user
*optval
, int optlen
)
880 if (level
!= SOL_UDP
)
881 return ipv6_setsockopt(sk
, level
, optname
, optval
, optlen
);
882 return do_udpv6_setsockopt(sk
, level
, optname
, optval
, optlen
);
886 static int compat_udpv6_setsockopt(struct sock
*sk
, int level
, int optname
,
887 char __user
*optval
, int optlen
)
889 if (level
!= SOL_UDP
)
890 return compat_ipv6_setsockopt(sk
, level
, optname
,
892 return do_udpv6_setsockopt(sk
, level
, optname
, optval
, optlen
);
896 static int do_udpv6_getsockopt(struct sock
*sk
, int level
, int optname
,
897 char __user
*optval
, int __user
*optlen
)
899 struct udp_sock
*up
= udp_sk(sk
);
902 if(get_user(len
,optlen
))
905 len
= min_t(unsigned int, len
, sizeof(int));
916 val
= up
->encap_type
;
923 if(put_user(len
, optlen
))
925 if(copy_to_user(optval
, &val
,len
))
930 static int udpv6_getsockopt(struct sock
*sk
, int level
, int optname
,
931 char __user
*optval
, int __user
*optlen
)
933 if (level
!= SOL_UDP
)
934 return ipv6_getsockopt(sk
, level
, optname
, optval
, optlen
);
935 return do_udpv6_getsockopt(sk
, level
, optname
, optval
, optlen
);
939 static int compat_udpv6_getsockopt(struct sock
*sk
, int level
, int optname
,
940 char __user
*optval
, int __user
*optlen
)
942 if (level
!= SOL_UDP
)
943 return compat_ipv6_getsockopt(sk
, level
, optname
,
945 return do_udpv6_getsockopt(sk
, level
, optname
, optval
, optlen
);
949 static struct inet6_protocol udpv6_protocol
= {
950 .handler
= udpv6_rcv
,
951 .err_handler
= udpv6_err
,
952 .flags
= INET6_PROTO_NOPOLICY
|INET6_PROTO_FINAL
,
955 /* ------------------------------------------------------------------------ */
956 #ifdef CONFIG_PROC_FS
958 static void udp6_sock_seq_show(struct seq_file
*seq
, struct sock
*sp
, int bucket
)
960 struct inet_sock
*inet
= inet_sk(sp
);
961 struct ipv6_pinfo
*np
= inet6_sk(sp
);
962 struct in6_addr
*dest
, *src
;
966 src
= &np
->rcv_saddr
;
967 destp
= ntohs(inet
->dport
);
968 srcp
= ntohs(inet
->sport
);
970 "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X "
971 "%02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p\n",
973 src
->s6_addr32
[0], src
->s6_addr32
[1],
974 src
->s6_addr32
[2], src
->s6_addr32
[3], srcp
,
975 dest
->s6_addr32
[0], dest
->s6_addr32
[1],
976 dest
->s6_addr32
[2], dest
->s6_addr32
[3], destp
,
978 atomic_read(&sp
->sk_wmem_alloc
),
979 atomic_read(&sp
->sk_rmem_alloc
),
983 atomic_read(&sp
->sk_refcnt
), sp
);
986 static int udp6_seq_show(struct seq_file
*seq
, void *v
)
988 if (v
== SEQ_START_TOKEN
)
993 "st tx_queue rx_queue tr tm->when retrnsmt"
994 " uid timeout inode\n");
996 udp6_sock_seq_show(seq
, v
, ((struct udp_iter_state
*)seq
->private)->bucket
);
1000 static struct file_operations udp6_seq_fops
;
1001 static struct udp_seq_afinfo udp6_seq_afinfo
= {
1002 .owner
= THIS_MODULE
,
1005 .seq_show
= udp6_seq_show
,
1006 .seq_fops
= &udp6_seq_fops
,
1009 int __init
udp6_proc_init(void)
1011 return udp_proc_register(&udp6_seq_afinfo
);
1014 void udp6_proc_exit(void) {
1015 udp_proc_unregister(&udp6_seq_afinfo
);
1017 #endif /* CONFIG_PROC_FS */
1019 /* ------------------------------------------------------------------------ */
1021 struct proto udpv6_prot
= {
1023 .owner
= THIS_MODULE
,
1024 .close
= udpv6_close
,
1025 .connect
= ip6_datagram_connect
,
1026 .disconnect
= udp_disconnect
,
1028 .destroy
= udpv6_destroy_sock
,
1029 .setsockopt
= udpv6_setsockopt
,
1030 .getsockopt
= udpv6_getsockopt
,
1031 .sendmsg
= udpv6_sendmsg
,
1032 .recvmsg
= udpv6_recvmsg
,
1033 .backlog_rcv
= udpv6_queue_rcv_skb
,
1034 .hash
= udp_v6_hash
,
1035 .unhash
= udp_v6_unhash
,
1036 .get_port
= udp_v6_get_port
,
1037 .obj_size
= sizeof(struct udp6_sock
),
1038 #ifdef CONFIG_COMPAT
1039 .compat_setsockopt
= compat_udpv6_setsockopt
,
1040 .compat_getsockopt
= compat_udpv6_getsockopt
,
1044 static struct inet_protosw udpv6_protosw
= {
1046 .protocol
= IPPROTO_UDP
,
1047 .prot
= &udpv6_prot
,
1048 .ops
= &inet6_dgram_ops
,
1050 .no_check
= UDP_CSUM_DEFAULT
,
1051 .flags
= INET_PROTOSW_PERMANENT
,
1055 void __init
udpv6_init(void)
1057 if (inet6_add_protocol(&udpv6_protocol
, IPPROTO_UDP
) < 0)
1058 printk(KERN_ERR
"udpv6_init: Could not register protocol\n");
1059 inet6_register_protosw(&udpv6_protosw
);