2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
8 * Version: $Id: ip_sockglue.c,v 1.62 2002/02/01 22:01:04 davem Exp $
13 * Many : Split from ip.c , see ip.c for history.
14 * Martin Mares : TOS setting fixed.
15 * Alan Cox : Fixed a couple of oopses in Martin's
17 * Mike McLagan : Routing by source
20 #include <linux/config.h>
21 #include <linux/module.h>
22 #include <linux/types.h>
24 #include <linux/sched.h>
25 #include <linux/skbuff.h>
27 #include <linux/icmp.h>
28 #include <linux/netdevice.h>
33 #include <linux/tcp.h>
34 #include <linux/udp.h>
35 #include <linux/igmp.h>
36 #include <linux/netfilter.h>
37 #include <linux/route.h>
38 #include <linux/mroute.h>
39 #include <net/route.h>
41 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
42 #include <net/transp_v6.h>
45 #include <linux/errqueue.h>
46 #include <asm/uaccess.h>
48 #define IP_CMSG_PKTINFO 1
51 #define IP_CMSG_RECVOPTS 8
52 #define IP_CMSG_RETOPTS 16
55 * SOL_IP control messages.
58 static void ip_cmsg_recv_pktinfo(struct msghdr *msg, struct sk_buff *skb)
60 struct in_pktinfo info;
61 struct rtable *rt = (struct rtable *)skb->dst;
63 info.ipi_addr.s_addr = skb->nh.iph->daddr;
65 info.ipi_ifindex = rt->rt_iif;
66 info.ipi_spec_dst.s_addr = rt->rt_spec_dst;
69 info.ipi_spec_dst.s_addr = 0;
72 put_cmsg(msg, SOL_IP, IP_PKTINFO, sizeof(info), &info);
75 static void ip_cmsg_recv_ttl(struct msghdr *msg, struct sk_buff *skb)
77 int ttl = skb->nh.iph->ttl;
78 put_cmsg(msg, SOL_IP, IP_TTL, sizeof(int), &ttl);
81 static void ip_cmsg_recv_tos(struct msghdr *msg, struct sk_buff *skb)
83 put_cmsg(msg, SOL_IP, IP_TOS, 1, &skb->nh.iph->tos);
86 static void ip_cmsg_recv_opts(struct msghdr *msg, struct sk_buff *skb)
88 if (IPCB(skb)->opt.optlen == 0)
91 put_cmsg(msg, SOL_IP, IP_RECVOPTS, IPCB(skb)->opt.optlen, skb->nh.iph+1);
95 static void ip_cmsg_recv_retopts(struct msghdr *msg, struct sk_buff *skb)
97 unsigned char optbuf[sizeof(struct ip_options) + 40];
98 struct ip_options * opt = (struct ip_options*)optbuf;
100 if (IPCB(skb)->opt.optlen == 0)
103 if (ip_options_echo(opt, skb)) {
104 msg->msg_flags |= MSG_CTRUNC;
107 ip_options_undo(opt);
109 put_cmsg(msg, SOL_IP, IP_RETOPTS, opt->optlen, opt->__data);
113 void ip_cmsg_recv(struct msghdr *msg, struct sk_buff *skb)
115 struct inet_sock *inet = inet_sk(skb->sk);
116 unsigned flags = inet->cmsg_flags;
118 /* Ordered by supposed usage frequency */
120 ip_cmsg_recv_pktinfo(msg, skb);
121 if ((flags>>=1) == 0)
125 ip_cmsg_recv_ttl(msg, skb);
126 if ((flags>>=1) == 0)
130 ip_cmsg_recv_tos(msg, skb);
131 if ((flags>>=1) == 0)
135 ip_cmsg_recv_opts(msg, skb);
136 if ((flags>>=1) == 0)
140 ip_cmsg_recv_retopts(msg, skb);
143 int ip_cmsg_send(struct msghdr *msg, struct ipcm_cookie *ipc)
146 struct cmsghdr *cmsg;
148 for (cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) {
149 if (!CMSG_OK(msg, cmsg))
151 if (cmsg->cmsg_level != SOL_IP)
153 switch (cmsg->cmsg_type) {
155 err = cmsg->cmsg_len - CMSG_ALIGN(sizeof(struct cmsghdr));
156 err = ip_options_get(&ipc->opt, CMSG_DATA(cmsg), err < 40 ? err : 40);
162 struct in_pktinfo *info;
163 if (cmsg->cmsg_len != CMSG_LEN(sizeof(struct in_pktinfo)))
165 info = (struct in_pktinfo *)CMSG_DATA(cmsg);
166 ipc->oif = info->ipi_ifindex;
167 ipc->addr = info->ipi_spec_dst.s_addr;
178 /* Special input handler for packets caught by router alert option.
179 They are selected only by protocol field, and then processed likely
180 local ones; but only if someone wants them! Otherwise, router
181 not running rsvpd will kill RSVP.
183 It is user level problem, what it will make with them.
184 I have no idea, how it will masquearde or NAT them (it is joke, joke :-)),
185 but receiver should be enough clever f.e. to forward mtrace requests,
186 sent to multicast group to reach destination designated router.
188 struct ip_ra_chain *ip_ra_chain;
189 DEFINE_RWLOCK(ip_ra_lock);
191 int ip_ra_control(struct sock *sk, unsigned char on, void (*destructor)(struct sock *))
193 struct ip_ra_chain *ra, *new_ra, **rap;
195 if (sk->sk_type != SOCK_RAW || inet_sk(sk)->num == IPPROTO_RAW)
198 new_ra = on ? kmalloc(sizeof(*new_ra), GFP_KERNEL) : NULL;
200 write_lock_bh(&ip_ra_lock);
201 for (rap = &ip_ra_chain; (ra=*rap) != NULL; rap = &ra->next) {
204 write_unlock_bh(&ip_ra_lock);
209 write_unlock_bh(&ip_ra_lock);
218 if (new_ra == NULL) {
219 write_unlock_bh(&ip_ra_lock);
223 new_ra->destructor = destructor;
228 write_unlock_bh(&ip_ra_lock);
233 void ip_icmp_error(struct sock *sk, struct sk_buff *skb, int err,
234 u16 port, u32 info, u8 *payload)
236 struct inet_sock *inet = inet_sk(sk);
237 struct sock_exterr_skb *serr;
242 skb = skb_clone(skb, GFP_ATOMIC);
246 serr = SKB_EXT_ERR(skb);
247 serr->ee.ee_errno = err;
248 serr->ee.ee_origin = SO_EE_ORIGIN_ICMP;
249 serr->ee.ee_type = skb->h.icmph->type;
250 serr->ee.ee_code = skb->h.icmph->code;
252 serr->ee.ee_info = info;
253 serr->ee.ee_data = 0;
254 serr->addr_offset = (u8*)&(((struct iphdr*)(skb->h.icmph+1))->daddr) - skb->nh.raw;
257 skb->h.raw = payload;
258 if (!skb_pull(skb, payload - skb->data) ||
259 sock_queue_err_skb(sk, skb))
263 void ip_local_error(struct sock *sk, int err, u32 daddr, u16 port, u32 info)
265 struct inet_sock *inet = inet_sk(sk);
266 struct sock_exterr_skb *serr;
273 skb = alloc_skb(sizeof(struct iphdr), GFP_ATOMIC);
277 iph = (struct iphdr*)skb_put(skb, sizeof(struct iphdr));
281 serr = SKB_EXT_ERR(skb);
282 serr->ee.ee_errno = err;
283 serr->ee.ee_origin = SO_EE_ORIGIN_LOCAL;
284 serr->ee.ee_type = 0;
285 serr->ee.ee_code = 0;
287 serr->ee.ee_info = info;
288 serr->ee.ee_data = 0;
289 serr->addr_offset = (u8*)&iph->daddr - skb->nh.raw;
292 skb->h.raw = skb->tail;
293 __skb_pull(skb, skb->tail - skb->data);
295 if (sock_queue_err_skb(sk, skb))
300 * Handle MSG_ERRQUEUE
302 int ip_recv_error(struct sock *sk, struct msghdr *msg, int len)
304 struct sock_exterr_skb *serr;
305 struct sk_buff *skb, *skb2;
306 struct sockaddr_in *sin;
308 struct sock_extended_err ee;
309 struct sockaddr_in offender;
315 skb = skb_dequeue(&sk->sk_error_queue);
321 msg->msg_flags |= MSG_TRUNC;
324 err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
328 sock_recv_timestamp(msg, sk, skb);
330 serr = SKB_EXT_ERR(skb);
332 sin = (struct sockaddr_in *)msg->msg_name;
334 sin->sin_family = AF_INET;
335 sin->sin_addr.s_addr = *(u32*)(skb->nh.raw + serr->addr_offset);
336 sin->sin_port = serr->port;
337 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
340 memcpy(&errhdr.ee, &serr->ee, sizeof(struct sock_extended_err));
341 sin = &errhdr.offender;
342 sin->sin_family = AF_UNSPEC;
343 if (serr->ee.ee_origin == SO_EE_ORIGIN_ICMP) {
344 struct inet_sock *inet = inet_sk(sk);
346 sin->sin_family = AF_INET;
347 sin->sin_addr.s_addr = skb->nh.iph->saddr;
349 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
350 if (inet->cmsg_flags)
351 ip_cmsg_recv(msg, skb);
354 put_cmsg(msg, SOL_IP, IP_RECVERR, sizeof(errhdr), &errhdr);
356 /* Now we could try to dump offended packet options */
358 msg->msg_flags |= MSG_ERRQUEUE;
361 /* Reset and regenerate socket error */
362 spin_lock_bh(&sk->sk_error_queue.lock);
364 if ((skb2 = skb_peek(&sk->sk_error_queue)) != NULL) {
365 sk->sk_err = SKB_EXT_ERR(skb2)->ee.ee_errno;
366 spin_unlock_bh(&sk->sk_error_queue.lock);
367 sk->sk_error_report(sk);
369 spin_unlock_bh(&sk->sk_error_queue.lock);
379 * Socket option code for IP. This is the end of the line after any TCP,UDP etc options on
383 int ip_setsockopt(struct sock *sk, int level, int optname, char __user *optval, int optlen)
385 struct inet_sock *inet = inet_sk(sk);
391 if (((1<<optname) & ((1<<IP_PKTINFO) | (1<<IP_RECVTTL) |
392 (1<<IP_RECVOPTS) | (1<<IP_RECVTOS) |
393 (1<<IP_RETOPTS) | (1<<IP_TOS) |
394 (1<<IP_TTL) | (1<<IP_HDRINCL) |
395 (1<<IP_MTU_DISCOVER) | (1<<IP_RECVERR) |
396 (1<<IP_ROUTER_ALERT) | (1<<IP_FREEBIND))) ||
397 optname == IP_MULTICAST_TTL ||
398 optname == IP_MULTICAST_LOOP) {
399 if (optlen >= sizeof(int)) {
400 if (get_user(val, (int __user *) optval))
402 } else if (optlen >= sizeof(char)) {
405 if (get_user(ucval, (unsigned char __user *) optval))
411 /* If optlen==0, it is equivalent to val == 0 */
413 #ifdef CONFIG_IP_MROUTE
414 if (optname >= MRT_BASE && optname <= (MRT_BASE + 10))
415 return ip_mroute_setsockopt(sk,optname,optval,optlen);
424 struct ip_options * opt = NULL;
425 if (optlen > 40 || optlen < 0)
427 err = ip_options_get_from_user(&opt, optval, optlen);
430 if (sk->sk_type == SOCK_STREAM) {
431 struct tcp_sock *tp = tcp_sk(sk);
432 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
433 if (sk->sk_family == PF_INET ||
434 (!((1 << sk->sk_state) &
435 (TCPF_LISTEN | TCPF_CLOSE)) &&
436 inet->daddr != LOOPBACK4_IPV6)) {
439 tp->ext_header_len -= inet->opt->optlen;
441 tp->ext_header_len += opt->optlen;
442 tcp_sync_mss(sk, tp->pmtu_cookie);
443 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
447 opt = xchg(&inet->opt, opt);
453 inet->cmsg_flags |= IP_CMSG_PKTINFO;
455 inet->cmsg_flags &= ~IP_CMSG_PKTINFO;
459 inet->cmsg_flags |= IP_CMSG_TTL;
461 inet->cmsg_flags &= ~IP_CMSG_TTL;
465 inet->cmsg_flags |= IP_CMSG_TOS;
467 inet->cmsg_flags &= ~IP_CMSG_TOS;
471 inet->cmsg_flags |= IP_CMSG_RECVOPTS;
473 inet->cmsg_flags &= ~IP_CMSG_RECVOPTS;
477 inet->cmsg_flags |= IP_CMSG_RETOPTS;
479 inet->cmsg_flags &= ~IP_CMSG_RETOPTS;
481 case IP_TOS: /* This sets both TOS and Precedence */
482 if (sk->sk_type == SOCK_STREAM) {
484 val |= inet->tos & 3;
486 if (IPTOS_PREC(val) >= IPTOS_PREC_CRITIC_ECP &&
487 !capable(CAP_NET_ADMIN)) {
491 if (inet->tos != val) {
493 sk->sk_priority = rt_tos2priority(val);
500 if (val != -1 && (val < 1 || val>255))
505 if (sk->sk_type != SOCK_RAW) {
509 inet->hdrincl = val ? 1 : 0;
511 case IP_MTU_DISCOVER:
514 inet->pmtudisc = val;
517 inet->recverr = !!val;
519 skb_queue_purge(&sk->sk_error_queue);
521 case IP_MULTICAST_TTL:
522 if (sk->sk_type == SOCK_STREAM)
528 if (val < 0 || val > 255)
532 case IP_MULTICAST_LOOP:
535 inet->mc_loop = !!val;
537 case IP_MULTICAST_IF:
539 struct ip_mreqn mreq;
540 struct net_device *dev = NULL;
542 if (sk->sk_type == SOCK_STREAM)
545 * Check the arguments are allowable
549 if (optlen >= sizeof(struct ip_mreqn)) {
550 if (copy_from_user(&mreq,optval,sizeof(mreq)))
553 memset(&mreq, 0, sizeof(mreq));
554 if (optlen >= sizeof(struct in_addr) &&
555 copy_from_user(&mreq.imr_address,optval,sizeof(struct in_addr)))
559 if (!mreq.imr_ifindex) {
560 if (mreq.imr_address.s_addr == INADDR_ANY) {
566 dev = ip_dev_find(mreq.imr_address.s_addr);
568 mreq.imr_ifindex = dev->ifindex;
572 dev = __dev_get_by_index(mreq.imr_ifindex);
575 err = -EADDRNOTAVAIL;
580 if (sk->sk_bound_dev_if &&
581 mreq.imr_ifindex != sk->sk_bound_dev_if)
584 inet->mc_index = mreq.imr_ifindex;
585 inet->mc_addr = mreq.imr_address.s_addr;
590 case IP_ADD_MEMBERSHIP:
591 case IP_DROP_MEMBERSHIP:
593 struct ip_mreqn mreq;
595 if (optlen < sizeof(struct ip_mreq))
598 if (optlen >= sizeof(struct ip_mreqn)) {
599 if(copy_from_user(&mreq,optval,sizeof(mreq)))
602 memset(&mreq, 0, sizeof(mreq));
603 if (copy_from_user(&mreq,optval,sizeof(struct ip_mreq)))
607 if (optname == IP_ADD_MEMBERSHIP)
608 err = ip_mc_join_group(sk, &mreq);
610 err = ip_mc_leave_group(sk, &mreq);
615 extern int sysctl_igmp_max_msf;
616 struct ip_msfilter *msf;
618 if (optlen < IP_MSFILTER_SIZE(0))
620 if (optlen > sysctl_optmem_max) {
624 msf = (struct ip_msfilter *)kmalloc(optlen, GFP_KERNEL);
630 if (copy_from_user(msf, optval, optlen)) {
634 /* numsrc >= (1G-4) overflow in 32 bits */
635 if (msf->imsf_numsrc >= 0x3ffffffcU ||
636 msf->imsf_numsrc > sysctl_igmp_max_msf) {
641 if (IP_MSFILTER_SIZE(msf->imsf_numsrc) > optlen) {
646 err = ip_mc_msfilter(sk, msf, 0);
650 case IP_BLOCK_SOURCE:
651 case IP_UNBLOCK_SOURCE:
652 case IP_ADD_SOURCE_MEMBERSHIP:
653 case IP_DROP_SOURCE_MEMBERSHIP:
655 struct ip_mreq_source mreqs;
658 if (optlen != sizeof(struct ip_mreq_source))
660 if (copy_from_user(&mreqs, optval, sizeof(mreqs))) {
664 if (optname == IP_BLOCK_SOURCE) {
665 omode = MCAST_EXCLUDE;
667 } else if (optname == IP_UNBLOCK_SOURCE) {
668 omode = MCAST_EXCLUDE;
670 } else if (optname == IP_ADD_SOURCE_MEMBERSHIP) {
671 struct ip_mreqn mreq;
673 mreq.imr_multiaddr.s_addr = mreqs.imr_multiaddr;
674 mreq.imr_address.s_addr = mreqs.imr_interface;
675 mreq.imr_ifindex = 0;
676 err = ip_mc_join_group(sk, &mreq);
677 if (err && err != -EADDRINUSE)
679 omode = MCAST_INCLUDE;
681 } else /* IP_DROP_SOURCE_MEMBERSHIP */ {
682 omode = MCAST_INCLUDE;
685 err = ip_mc_source(add, omode, sk, &mreqs, 0);
688 case MCAST_JOIN_GROUP:
689 case MCAST_LEAVE_GROUP:
691 struct group_req greq;
692 struct sockaddr_in *psin;
693 struct ip_mreqn mreq;
695 if (optlen < sizeof(struct group_req))
698 if(copy_from_user(&greq, optval, sizeof(greq)))
700 psin = (struct sockaddr_in *)&greq.gr_group;
701 if (psin->sin_family != AF_INET)
703 memset(&mreq, 0, sizeof(mreq));
704 mreq.imr_multiaddr = psin->sin_addr;
705 mreq.imr_ifindex = greq.gr_interface;
707 if (optname == MCAST_JOIN_GROUP)
708 err = ip_mc_join_group(sk, &mreq);
710 err = ip_mc_leave_group(sk, &mreq);
713 case MCAST_JOIN_SOURCE_GROUP:
714 case MCAST_LEAVE_SOURCE_GROUP:
715 case MCAST_BLOCK_SOURCE:
716 case MCAST_UNBLOCK_SOURCE:
718 struct group_source_req greqs;
719 struct ip_mreq_source mreqs;
720 struct sockaddr_in *psin;
723 if (optlen != sizeof(struct group_source_req))
725 if (copy_from_user(&greqs, optval, sizeof(greqs))) {
729 if (greqs.gsr_group.ss_family != AF_INET ||
730 greqs.gsr_source.ss_family != AF_INET) {
731 err = -EADDRNOTAVAIL;
734 psin = (struct sockaddr_in *)&greqs.gsr_group;
735 mreqs.imr_multiaddr = psin->sin_addr.s_addr;
736 psin = (struct sockaddr_in *)&greqs.gsr_source;
737 mreqs.imr_sourceaddr = psin->sin_addr.s_addr;
738 mreqs.imr_interface = 0; /* use index for mc_source */
740 if (optname == MCAST_BLOCK_SOURCE) {
741 omode = MCAST_EXCLUDE;
743 } else if (optname == MCAST_UNBLOCK_SOURCE) {
744 omode = MCAST_EXCLUDE;
746 } else if (optname == MCAST_JOIN_SOURCE_GROUP) {
747 struct ip_mreqn mreq;
749 psin = (struct sockaddr_in *)&greqs.gsr_group;
750 mreq.imr_multiaddr = psin->sin_addr;
751 mreq.imr_address.s_addr = 0;
752 mreq.imr_ifindex = greqs.gsr_interface;
753 err = ip_mc_join_group(sk, &mreq);
754 if (err && err != -EADDRINUSE)
756 greqs.gsr_interface = mreq.imr_ifindex;
757 omode = MCAST_INCLUDE;
759 } else /* MCAST_LEAVE_SOURCE_GROUP */ {
760 omode = MCAST_INCLUDE;
763 err = ip_mc_source(add, omode, sk, &mreqs,
764 greqs.gsr_interface);
769 extern int sysctl_igmp_max_msf;
770 struct sockaddr_in *psin;
771 struct ip_msfilter *msf = NULL;
772 struct group_filter *gsf = NULL;
773 int msize, i, ifindex;
775 if (optlen < GROUP_FILTER_SIZE(0))
777 if (optlen > sysctl_optmem_max) {
781 gsf = (struct group_filter *)kmalloc(optlen,GFP_KERNEL);
787 if (copy_from_user(gsf, optval, optlen)) {
790 /* numsrc >= (4G-140)/128 overflow in 32 bits */
791 if (gsf->gf_numsrc >= 0x1ffffff ||
792 gsf->gf_numsrc > sysctl_igmp_max_msf) {
796 if (GROUP_FILTER_SIZE(gsf->gf_numsrc) > optlen) {
800 msize = IP_MSFILTER_SIZE(gsf->gf_numsrc);
801 msf = (struct ip_msfilter *)kmalloc(msize,GFP_KERNEL);
806 ifindex = gsf->gf_interface;
807 psin = (struct sockaddr_in *)&gsf->gf_group;
808 if (psin->sin_family != AF_INET) {
809 err = -EADDRNOTAVAIL;
812 msf->imsf_multiaddr = psin->sin_addr.s_addr;
813 msf->imsf_interface = 0;
814 msf->imsf_fmode = gsf->gf_fmode;
815 msf->imsf_numsrc = gsf->gf_numsrc;
816 err = -EADDRNOTAVAIL;
817 for (i=0; i<gsf->gf_numsrc; ++i) {
818 psin = (struct sockaddr_in *)&gsf->gf_slist[i];
820 if (psin->sin_family != AF_INET)
822 msf->imsf_slist[i] = psin->sin_addr.s_addr;
827 err = ip_mc_msfilter(sk, msf, ifindex);
833 case IP_ROUTER_ALERT:
834 err = ip_ra_control(sk, val ? 1 : 0, NULL);
840 inet->freebind = !!val;
843 case IP_IPSEC_POLICY:
846 if (!capable(CAP_NET_ADMIN))
848 err = xfrm_user_policy(sk, optname, optval, optlen);
852 #ifdef CONFIG_NETFILTER
853 err = nf_setsockopt(sk, PF_INET, optname, optval,
869 * Get the options. Note for future reference. The GET of IP options gets the
870 * _received_ ones. The set sets the _sent_ ones.
873 int ip_getsockopt(struct sock *sk, int level, int optname, char __user *optval, int __user *optlen)
875 struct inet_sock *inet = inet_sk(sk);
882 #ifdef CONFIG_IP_MROUTE
883 if(optname>=MRT_BASE && optname <=MRT_BASE+10)
885 return ip_mroute_getsockopt(sk,optname,optval,optlen);
889 if(get_user(len,optlen))
899 unsigned char optbuf[sizeof(struct ip_options)+40];
900 struct ip_options * opt = (struct ip_options*)optbuf;
903 memcpy(optbuf, inet->opt,
904 sizeof(struct ip_options)+
908 if (opt->optlen == 0)
909 return put_user(0, optlen);
911 ip_options_undo(opt);
913 len = min_t(unsigned int, len, opt->optlen);
914 if(put_user(len, optlen))
916 if(copy_to_user(optval, opt->__data, len))
921 val = (inet->cmsg_flags & IP_CMSG_PKTINFO) != 0;
924 val = (inet->cmsg_flags & IP_CMSG_TTL) != 0;
927 val = (inet->cmsg_flags & IP_CMSG_TOS) != 0;
930 val = (inet->cmsg_flags & IP_CMSG_RECVOPTS) != 0;
933 val = (inet->cmsg_flags & IP_CMSG_RETOPTS) != 0;
939 val = (inet->uc_ttl == -1 ?
940 sysctl_ip_default_ttl :
946 case IP_MTU_DISCOVER:
947 val = inet->pmtudisc;
951 struct dst_entry *dst;
953 dst = sk_dst_get(sk);
967 case IP_MULTICAST_TTL:
970 case IP_MULTICAST_LOOP:
973 case IP_MULTICAST_IF:
976 len = min_t(unsigned int, len, sizeof(struct in_addr));
977 addr.s_addr = inet->mc_addr;
980 if(put_user(len, optlen))
982 if(copy_to_user(optval, &addr, len))
988 struct ip_msfilter msf;
991 if (len < IP_MSFILTER_SIZE(0)) {
995 if (copy_from_user(&msf, optval, IP_MSFILTER_SIZE(0))) {
999 err = ip_mc_msfget(sk, &msf,
1000 (struct ip_msfilter __user *)optval, optlen);
1004 case MCAST_MSFILTER:
1006 struct group_filter gsf;
1009 if (len < GROUP_FILTER_SIZE(0)) {
1013 if (copy_from_user(&gsf, optval, GROUP_FILTER_SIZE(0))) {
1017 err = ip_mc_gsfget(sk, &gsf,
1018 (struct group_filter __user *)optval, optlen);
1028 if (sk->sk_type != SOCK_STREAM)
1029 return -ENOPROTOOPT;
1031 msg.msg_control = optval;
1032 msg.msg_controllen = len;
1035 if (inet->cmsg_flags & IP_CMSG_PKTINFO) {
1036 struct in_pktinfo info;
1038 info.ipi_addr.s_addr = inet->rcv_saddr;
1039 info.ipi_spec_dst.s_addr = inet->rcv_saddr;
1040 info.ipi_ifindex = inet->mc_index;
1041 put_cmsg(&msg, SOL_IP, IP_PKTINFO, sizeof(info), &info);
1043 if (inet->cmsg_flags & IP_CMSG_TTL) {
1044 int hlim = inet->mc_ttl;
1045 put_cmsg(&msg, SOL_IP, IP_TTL, sizeof(hlim), &hlim);
1047 len -= msg.msg_controllen;
1048 return put_user(len, optlen);
1051 val = inet->freebind;
1054 #ifdef CONFIG_NETFILTER
1055 val = nf_getsockopt(sk, PF_INET, optname, optval,
1059 val = put_user(len, optlen);
1063 return -ENOPROTOOPT;
1068 if (len < sizeof(int) && len > 0 && val>=0 && val<255) {
1069 unsigned char ucval = (unsigned char)val;
1071 if(put_user(len, optlen))
1073 if(copy_to_user(optval,&ucval,1))
1076 len = min_t(unsigned int, sizeof(int), len);
1077 if(put_user(len, optlen))
1079 if(copy_to_user(optval,&val,len))
1085 EXPORT_SYMBOL(ip_cmsg_recv);
1087 EXPORT_SYMBOL(ip_getsockopt);
1088 EXPORT_SYMBOL(ip_setsockopt);