Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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. |
| 5 | * |
| 6 | * The IP to API glue. |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 7 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * Authors: see ip.c |
| 9 | * |
| 10 | * Fixes: |
| 11 | * Many : Split from ip.c , see ip.c for history. |
| 12 | * Martin Mares : TOS setting fixed. |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 13 | * Alan Cox : Fixed a couple of oopses in Martin's |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | * TOS tweaks. |
| 15 | * Mike McLagan : Routing by source |
| 16 | */ |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/module.h> |
| 19 | #include <linux/types.h> |
| 20 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/skbuff.h> |
| 22 | #include <linux/ip.h> |
| 23 | #include <linux/icmp.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 24 | #include <linux/inetdevice.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/netdevice.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <net/sock.h> |
| 28 | #include <net/ip.h> |
| 29 | #include <net/icmp.h> |
Arnaldo Carvalho de Melo | d83d846 | 2005-12-13 23:26:10 -0800 | [diff] [blame] | 30 | #include <net/tcp_states.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/udp.h> |
| 32 | #include <linux/igmp.h> |
| 33 | #include <linux/netfilter.h> |
| 34 | #include <linux/route.h> |
| 35 | #include <linux/mroute.h> |
| 36 | #include <net/route.h> |
| 37 | #include <net/xfrm.h> |
David L Stevens | dae5029 | 2008-04-27 01:06:07 -0700 | [diff] [blame] | 38 | #include <net/compat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) |
| 40 | #include <net/transp_v6.h> |
| 41 | #endif |
| 42 | |
| 43 | #include <linux/errqueue.h> |
| 44 | #include <asm/uaccess.h> |
| 45 | |
| 46 | #define IP_CMSG_PKTINFO 1 |
| 47 | #define IP_CMSG_TTL 2 |
| 48 | #define IP_CMSG_TOS 4 |
| 49 | #define IP_CMSG_RECVOPTS 8 |
| 50 | #define IP_CMSG_RETOPTS 16 |
Catherine Zhang | 2c7946a | 2006-03-20 22:41:23 -0800 | [diff] [blame] | 51 | #define IP_CMSG_PASSSEC 32 |
Balazs Scheidler | e8b2dfe | 2008-11-16 19:32:39 -0800 | [diff] [blame] | 52 | #define IP_CMSG_ORIGDSTADDR 64 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | /* |
| 55 | * SOL_IP control messages. |
| 56 | */ |
| 57 | |
| 58 | static void ip_cmsg_recv_pktinfo(struct msghdr *msg, struct sk_buff *skb) |
| 59 | { |
| 60 | struct in_pktinfo info; |
Eric Dumazet | 511c3f9 | 2009-06-02 05:14:27 +0000 | [diff] [blame] | 61 | struct rtable *rt = skb_rtable(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 63 | info.ipi_addr.s_addr = ip_hdr(skb)->daddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | if (rt) { |
| 65 | info.ipi_ifindex = rt->rt_iif; |
| 66 | info.ipi_spec_dst.s_addr = rt->rt_spec_dst; |
| 67 | } else { |
| 68 | info.ipi_ifindex = 0; |
| 69 | info.ipi_spec_dst.s_addr = 0; |
| 70 | } |
| 71 | |
| 72 | put_cmsg(msg, SOL_IP, IP_PKTINFO, sizeof(info), &info); |
| 73 | } |
| 74 | |
| 75 | static void ip_cmsg_recv_ttl(struct msghdr *msg, struct sk_buff *skb) |
| 76 | { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 77 | int ttl = ip_hdr(skb)->ttl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | put_cmsg(msg, SOL_IP, IP_TTL, sizeof(int), &ttl); |
| 79 | } |
| 80 | |
| 81 | static void ip_cmsg_recv_tos(struct msghdr *msg, struct sk_buff *skb) |
| 82 | { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 83 | put_cmsg(msg, SOL_IP, IP_TOS, 1, &ip_hdr(skb)->tos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | static void ip_cmsg_recv_opts(struct msghdr *msg, struct sk_buff *skb) |
| 87 | { |
| 88 | if (IPCB(skb)->opt.optlen == 0) |
| 89 | return; |
| 90 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 91 | put_cmsg(msg, SOL_IP, IP_RECVOPTS, IPCB(skb)->opt.optlen, |
| 92 | ip_hdr(skb) + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | |
| 96 | static void ip_cmsg_recv_retopts(struct msghdr *msg, struct sk_buff *skb) |
| 97 | { |
| 98 | unsigned char optbuf[sizeof(struct ip_options) + 40]; |
Jianjun Kong | 09cb105 | 2008-11-03 00:27:11 -0800 | [diff] [blame] | 99 | struct ip_options * opt = (struct ip_options *)optbuf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
| 101 | if (IPCB(skb)->opt.optlen == 0) |
| 102 | return; |
| 103 | |
| 104 | if (ip_options_echo(opt, skb)) { |
| 105 | msg->msg_flags |= MSG_CTRUNC; |
| 106 | return; |
| 107 | } |
| 108 | ip_options_undo(opt); |
| 109 | |
| 110 | put_cmsg(msg, SOL_IP, IP_RETOPTS, opt->optlen, opt->__data); |
| 111 | } |
| 112 | |
Catherine Zhang | 2c7946a | 2006-03-20 22:41:23 -0800 | [diff] [blame] | 113 | static void ip_cmsg_recv_security(struct msghdr *msg, struct sk_buff *skb) |
| 114 | { |
| 115 | char *secdata; |
Catherine Zhang | dc49c1f | 2006-08-02 14:12:06 -0700 | [diff] [blame] | 116 | u32 seclen, secid; |
Catherine Zhang | 2c7946a | 2006-03-20 22:41:23 -0800 | [diff] [blame] | 117 | int err; |
| 118 | |
Catherine Zhang | dc49c1f | 2006-08-02 14:12:06 -0700 | [diff] [blame] | 119 | err = security_socket_getpeersec_dgram(NULL, skb, &secid); |
| 120 | if (err) |
| 121 | return; |
| 122 | |
| 123 | err = security_secid_to_secctx(secid, &secdata, &seclen); |
Catherine Zhang | 2c7946a | 2006-03-20 22:41:23 -0800 | [diff] [blame] | 124 | if (err) |
| 125 | return; |
| 126 | |
| 127 | put_cmsg(msg, SOL_IP, SCM_SECURITY, seclen, secdata); |
Catherine Zhang | dc49c1f | 2006-08-02 14:12:06 -0700 | [diff] [blame] | 128 | security_release_secctx(secdata, seclen); |
Catherine Zhang | 2c7946a | 2006-03-20 22:41:23 -0800 | [diff] [blame] | 129 | } |
| 130 | |
Harvey Harrison | 21d1a16 | 2008-11-20 01:54:27 -0800 | [diff] [blame] | 131 | static void ip_cmsg_recv_dstaddr(struct msghdr *msg, struct sk_buff *skb) |
Balazs Scheidler | e8b2dfe | 2008-11-16 19:32:39 -0800 | [diff] [blame] | 132 | { |
| 133 | struct sockaddr_in sin; |
Eric Dumazet | b71d1d4 | 2011-04-22 04:53:02 +0000 | [diff] [blame^] | 134 | const struct iphdr *iph = ip_hdr(skb); |
Harvey Harrison | 21d1a16 | 2008-11-20 01:54:27 -0800 | [diff] [blame] | 135 | __be16 *ports = (__be16 *)skb_transport_header(skb); |
Balazs Scheidler | e8b2dfe | 2008-11-16 19:32:39 -0800 | [diff] [blame] | 136 | |
| 137 | if (skb_transport_offset(skb) + 4 > skb->len) |
| 138 | return; |
| 139 | |
| 140 | /* All current transport protocols have the port numbers in the |
| 141 | * first four bytes of the transport header and this function is |
| 142 | * written with this assumption in mind. |
| 143 | */ |
| 144 | |
| 145 | sin.sin_family = AF_INET; |
| 146 | sin.sin_addr.s_addr = iph->daddr; |
| 147 | sin.sin_port = ports[1]; |
| 148 | memset(sin.sin_zero, 0, sizeof(sin.sin_zero)); |
| 149 | |
| 150 | put_cmsg(msg, SOL_IP, IP_ORIGDSTADDR, sizeof(sin), &sin); |
| 151 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
| 153 | void ip_cmsg_recv(struct msghdr *msg, struct sk_buff *skb) |
| 154 | { |
| 155 | struct inet_sock *inet = inet_sk(skb->sk); |
| 156 | unsigned flags = inet->cmsg_flags; |
| 157 | |
| 158 | /* Ordered by supposed usage frequency */ |
| 159 | if (flags & 1) |
| 160 | ip_cmsg_recv_pktinfo(msg, skb); |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 161 | if ((flags >>= 1) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | return; |
| 163 | |
| 164 | if (flags & 1) |
| 165 | ip_cmsg_recv_ttl(msg, skb); |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 166 | if ((flags >>= 1) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | return; |
| 168 | |
| 169 | if (flags & 1) |
| 170 | ip_cmsg_recv_tos(msg, skb); |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 171 | if ((flags >>= 1) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | return; |
| 173 | |
| 174 | if (flags & 1) |
| 175 | ip_cmsg_recv_opts(msg, skb); |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 176 | if ((flags >>= 1) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | return; |
| 178 | |
| 179 | if (flags & 1) |
| 180 | ip_cmsg_recv_retopts(msg, skb); |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 181 | if ((flags >>= 1) == 0) |
Catherine Zhang | 2c7946a | 2006-03-20 22:41:23 -0800 | [diff] [blame] | 182 | return; |
| 183 | |
| 184 | if (flags & 1) |
| 185 | ip_cmsg_recv_security(msg, skb); |
Balazs Scheidler | e8b2dfe | 2008-11-16 19:32:39 -0800 | [diff] [blame] | 186 | |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 187 | if ((flags >>= 1) == 0) |
Balazs Scheidler | e8b2dfe | 2008-11-16 19:32:39 -0800 | [diff] [blame] | 188 | return; |
| 189 | if (flags & 1) |
| 190 | ip_cmsg_recv_dstaddr(msg, skb); |
| 191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | } |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 193 | EXPORT_SYMBOL(ip_cmsg_recv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
Denis V. Lunev | 7a6adb9 | 2008-03-24 15:30:27 -0700 | [diff] [blame] | 195 | int ip_cmsg_send(struct net *net, struct msghdr *msg, struct ipcm_cookie *ipc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | { |
| 197 | int err; |
| 198 | struct cmsghdr *cmsg; |
| 199 | |
| 200 | for (cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) { |
| 201 | if (!CMSG_OK(msg, cmsg)) |
| 202 | return -EINVAL; |
| 203 | if (cmsg->cmsg_level != SOL_IP) |
| 204 | continue; |
| 205 | switch (cmsg->cmsg_type) { |
| 206 | case IP_RETOPTS: |
| 207 | err = cmsg->cmsg_len - CMSG_ALIGN(sizeof(struct cmsghdr)); |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 208 | err = ip_options_get(net, &ipc->opt, CMSG_DATA(cmsg), |
| 209 | err < 40 ? err : 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | if (err) |
| 211 | return err; |
| 212 | break; |
| 213 | case IP_PKTINFO: |
| 214 | { |
| 215 | struct in_pktinfo *info; |
| 216 | if (cmsg->cmsg_len != CMSG_LEN(sizeof(struct in_pktinfo))) |
| 217 | return -EINVAL; |
| 218 | info = (struct in_pktinfo *)CMSG_DATA(cmsg); |
| 219 | ipc->oif = info->ipi_ifindex; |
| 220 | ipc->addr = info->ipi_spec_dst.s_addr; |
| 221 | break; |
| 222 | } |
| 223 | default: |
| 224 | return -EINVAL; |
| 225 | } |
| 226 | } |
| 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | |
| 231 | /* Special input handler for packets caught by router alert option. |
| 232 | They are selected only by protocol field, and then processed likely |
| 233 | local ones; but only if someone wants them! Otherwise, router |
| 234 | not running rsvpd will kill RSVP. |
| 235 | |
| 236 | It is user level problem, what it will make with them. |
| 237 | I have no idea, how it will masquearde or NAT them (it is joke, joke :-)), |
| 238 | but receiver should be enough clever f.e. to forward mtrace requests, |
| 239 | sent to multicast group to reach destination designated router. |
| 240 | */ |
Eric Dumazet | 43a951e | 2010-10-25 03:32:44 +0000 | [diff] [blame] | 241 | struct ip_ra_chain __rcu *ip_ra_chain; |
Eric Dumazet | 6601850 | 2010-06-07 03:12:08 +0000 | [diff] [blame] | 242 | static DEFINE_SPINLOCK(ip_ra_lock); |
| 243 | |
Eric Dumazet | 592fcb9 | 2010-06-09 16:21:07 +0000 | [diff] [blame] | 244 | |
| 245 | static void ip_ra_destroy_rcu(struct rcu_head *head) |
Eric Dumazet | 6601850 | 2010-06-07 03:12:08 +0000 | [diff] [blame] | 246 | { |
Eric Dumazet | 592fcb9 | 2010-06-09 16:21:07 +0000 | [diff] [blame] | 247 | struct ip_ra_chain *ra = container_of(head, struct ip_ra_chain, rcu); |
| 248 | |
| 249 | sock_put(ra->saved_sk); |
| 250 | kfree(ra); |
Eric Dumazet | 6601850 | 2010-06-07 03:12:08 +0000 | [diff] [blame] | 251 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 253 | int ip_ra_control(struct sock *sk, unsigned char on, |
| 254 | void (*destructor)(struct sock *)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | { |
Eric Dumazet | 43a951e | 2010-10-25 03:32:44 +0000 | [diff] [blame] | 256 | struct ip_ra_chain *ra, *new_ra; |
| 257 | struct ip_ra_chain __rcu **rap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
Eric Dumazet | c720c7e | 2009-10-15 06:30:45 +0000 | [diff] [blame] | 259 | if (sk->sk_type != SOCK_RAW || inet_sk(sk)->inet_num == IPPROTO_RAW) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | return -EINVAL; |
| 261 | |
| 262 | new_ra = on ? kmalloc(sizeof(*new_ra), GFP_KERNEL) : NULL; |
| 263 | |
Eric Dumazet | 6601850 | 2010-06-07 03:12:08 +0000 | [diff] [blame] | 264 | spin_lock_bh(&ip_ra_lock); |
Eric Dumazet | 43a951e | 2010-10-25 03:32:44 +0000 | [diff] [blame] | 265 | for (rap = &ip_ra_chain; |
| 266 | (ra = rcu_dereference_protected(*rap, |
| 267 | lockdep_is_held(&ip_ra_lock))) != NULL; |
| 268 | rap = &ra->next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | if (ra->sk == sk) { |
| 270 | if (on) { |
Eric Dumazet | 6601850 | 2010-06-07 03:12:08 +0000 | [diff] [blame] | 271 | spin_unlock_bh(&ip_ra_lock); |
Jesper Juhl | a51482b | 2005-11-08 09:41:34 -0800 | [diff] [blame] | 272 | kfree(new_ra); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | return -EADDRINUSE; |
| 274 | } |
Eric Dumazet | 592fcb9 | 2010-06-09 16:21:07 +0000 | [diff] [blame] | 275 | /* dont let ip_call_ra_chain() use sk again */ |
| 276 | ra->sk = NULL; |
Eric Dumazet | 6601850 | 2010-06-07 03:12:08 +0000 | [diff] [blame] | 277 | rcu_assign_pointer(*rap, ra->next); |
| 278 | spin_unlock_bh(&ip_ra_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
| 280 | if (ra->destructor) |
| 281 | ra->destructor(sk); |
Eric Dumazet | 592fcb9 | 2010-06-09 16:21:07 +0000 | [diff] [blame] | 282 | /* |
| 283 | * Delay sock_put(sk) and kfree(ra) after one rcu grace |
| 284 | * period. This guarantee ip_call_ra_chain() dont need |
| 285 | * to mess with socket refcounts. |
| 286 | */ |
| 287 | ra->saved_sk = sk; |
| 288 | call_rcu(&ra->rcu, ip_ra_destroy_rcu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | return 0; |
| 290 | } |
| 291 | } |
| 292 | if (new_ra == NULL) { |
Eric Dumazet | 6601850 | 2010-06-07 03:12:08 +0000 | [diff] [blame] | 293 | spin_unlock_bh(&ip_ra_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | return -ENOBUFS; |
| 295 | } |
| 296 | new_ra->sk = sk; |
| 297 | new_ra->destructor = destructor; |
| 298 | |
| 299 | new_ra->next = ra; |
Eric Dumazet | 6601850 | 2010-06-07 03:12:08 +0000 | [diff] [blame] | 300 | rcu_assign_pointer(*rap, new_ra); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | sock_hold(sk); |
Eric Dumazet | 6601850 | 2010-06-07 03:12:08 +0000 | [diff] [blame] | 302 | spin_unlock_bh(&ip_ra_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
| 304 | return 0; |
| 305 | } |
| 306 | |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 307 | void ip_icmp_error(struct sock *sk, struct sk_buff *skb, int err, |
Al Viro | 35986b3 | 2006-09-27 18:34:21 -0700 | [diff] [blame] | 308 | __be16 port, u32 info, u8 *payload) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | struct sock_exterr_skb *serr; |
| 311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | skb = skb_clone(skb, GFP_ATOMIC); |
| 313 | if (!skb) |
| 314 | return; |
| 315 | |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 316 | serr = SKB_EXT_ERR(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | serr->ee.ee_errno = err; |
| 318 | serr->ee.ee_origin = SO_EE_ORIGIN_ICMP; |
Arnaldo Carvalho de Melo | 88c7664 | 2007-03-13 14:43:18 -0300 | [diff] [blame] | 319 | serr->ee.ee_type = icmp_hdr(skb)->type; |
| 320 | serr->ee.ee_code = icmp_hdr(skb)->code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | serr->ee.ee_pad = 0; |
| 322 | serr->ee.ee_info = info; |
| 323 | serr->ee.ee_data = 0; |
Arnaldo Carvalho de Melo | 88c7664 | 2007-03-13 14:43:18 -0300 | [diff] [blame] | 324 | serr->addr_offset = (u8 *)&(((struct iphdr *)(icmp_hdr(skb) + 1))->daddr) - |
Arnaldo Carvalho de Melo | d56f90a | 2007-04-10 20:50:43 -0700 | [diff] [blame] | 325 | skb_network_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | serr->port = port; |
| 327 | |
Arnaldo Carvalho de Melo | bd82393 | 2007-03-13 17:10:43 -0300 | [diff] [blame] | 328 | if (skb_pull(skb, payload - skb->data) != NULL) { |
| 329 | skb_reset_transport_header(skb); |
| 330 | if (sock_queue_err_skb(sk, skb) == 0) |
| 331 | return; |
| 332 | } |
| 333 | kfree_skb(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Al Viro | 0579016 | 2006-09-27 18:33:40 -0700 | [diff] [blame] | 336 | void ip_local_error(struct sock *sk, int err, __be32 daddr, __be16 port, u32 info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | { |
| 338 | struct inet_sock *inet = inet_sk(sk); |
| 339 | struct sock_exterr_skb *serr; |
| 340 | struct iphdr *iph; |
| 341 | struct sk_buff *skb; |
| 342 | |
| 343 | if (!inet->recverr) |
| 344 | return; |
| 345 | |
| 346 | skb = alloc_skb(sizeof(struct iphdr), GFP_ATOMIC); |
| 347 | if (!skb) |
| 348 | return; |
| 349 | |
Arnaldo Carvalho de Melo | 2ca9e6f | 2007-03-10 19:15:25 -0300 | [diff] [blame] | 350 | skb_put(skb, sizeof(struct iphdr)); |
| 351 | skb_reset_network_header(skb); |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 352 | iph = ip_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | iph->daddr = daddr; |
| 354 | |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 355 | serr = SKB_EXT_ERR(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | serr->ee.ee_errno = err; |
| 357 | serr->ee.ee_origin = SO_EE_ORIGIN_LOCAL; |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 358 | serr->ee.ee_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | serr->ee.ee_code = 0; |
| 360 | serr->ee.ee_pad = 0; |
| 361 | serr->ee.ee_info = info; |
| 362 | serr->ee.ee_data = 0; |
Arnaldo Carvalho de Melo | d56f90a | 2007-04-10 20:50:43 -0700 | [diff] [blame] | 363 | serr->addr_offset = (u8 *)&iph->daddr - skb_network_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | serr->port = port; |
| 365 | |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 366 | __skb_pull(skb, skb_tail_pointer(skb) - skb->data); |
Arnaldo Carvalho de Melo | bd82393 | 2007-03-13 17:10:43 -0300 | [diff] [blame] | 367 | skb_reset_transport_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
| 369 | if (sock_queue_err_skb(sk, skb)) |
| 370 | kfree_skb(skb); |
| 371 | } |
| 372 | |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 373 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | * Handle MSG_ERRQUEUE |
| 375 | */ |
| 376 | int ip_recv_error(struct sock *sk, struct msghdr *msg, int len) |
| 377 | { |
| 378 | struct sock_exterr_skb *serr; |
| 379 | struct sk_buff *skb, *skb2; |
| 380 | struct sockaddr_in *sin; |
| 381 | struct { |
| 382 | struct sock_extended_err ee; |
| 383 | struct sockaddr_in offender; |
| 384 | } errhdr; |
| 385 | int err; |
| 386 | int copied; |
| 387 | |
| 388 | err = -EAGAIN; |
| 389 | skb = skb_dequeue(&sk->sk_error_queue); |
| 390 | if (skb == NULL) |
| 391 | goto out; |
| 392 | |
| 393 | copied = skb->len; |
| 394 | if (copied > len) { |
| 395 | msg->msg_flags |= MSG_TRUNC; |
| 396 | copied = len; |
| 397 | } |
| 398 | err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied); |
| 399 | if (err) |
| 400 | goto out_free_skb; |
| 401 | |
| 402 | sock_recv_timestamp(msg, sk, skb); |
| 403 | |
| 404 | serr = SKB_EXT_ERR(skb); |
| 405 | |
| 406 | sin = (struct sockaddr_in *)msg->msg_name; |
| 407 | if (sin) { |
| 408 | sin->sin_family = AF_INET; |
Arnaldo Carvalho de Melo | d56f90a | 2007-04-10 20:50:43 -0700 | [diff] [blame] | 409 | sin->sin_addr.s_addr = *(__be32 *)(skb_network_header(skb) + |
| 410 | serr->addr_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | sin->sin_port = serr->port; |
| 412 | memset(&sin->sin_zero, 0, sizeof(sin->sin_zero)); |
| 413 | } |
| 414 | |
| 415 | memcpy(&errhdr.ee, &serr->ee, sizeof(struct sock_extended_err)); |
| 416 | sin = &errhdr.offender; |
| 417 | sin->sin_family = AF_UNSPEC; |
| 418 | if (serr->ee.ee_origin == SO_EE_ORIGIN_ICMP) { |
| 419 | struct inet_sock *inet = inet_sk(sk); |
| 420 | |
| 421 | sin->sin_family = AF_INET; |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 422 | sin->sin_addr.s_addr = ip_hdr(skb)->saddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | sin->sin_port = 0; |
| 424 | memset(&sin->sin_zero, 0, sizeof(sin->sin_zero)); |
| 425 | if (inet->cmsg_flags) |
| 426 | ip_cmsg_recv(msg, skb); |
| 427 | } |
| 428 | |
| 429 | put_cmsg(msg, SOL_IP, IP_RECVERR, sizeof(errhdr), &errhdr); |
| 430 | |
| 431 | /* Now we could try to dump offended packet options */ |
| 432 | |
| 433 | msg->msg_flags |= MSG_ERRQUEUE; |
| 434 | err = copied; |
| 435 | |
| 436 | /* Reset and regenerate socket error */ |
Herbert Xu | e0f9f85 | 2005-06-18 22:56:18 -0700 | [diff] [blame] | 437 | spin_lock_bh(&sk->sk_error_queue.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | sk->sk_err = 0; |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 439 | skb2 = skb_peek(&sk->sk_error_queue); |
| 440 | if (skb2 != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | sk->sk_err = SKB_EXT_ERR(skb2)->ee.ee_errno; |
Herbert Xu | e0f9f85 | 2005-06-18 22:56:18 -0700 | [diff] [blame] | 442 | spin_unlock_bh(&sk->sk_error_queue.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | sk->sk_error_report(sk); |
| 444 | } else |
Herbert Xu | e0f9f85 | 2005-06-18 22:56:18 -0700 | [diff] [blame] | 445 | spin_unlock_bh(&sk->sk_error_queue.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 447 | out_free_skb: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | kfree_skb(skb); |
| 449 | out: |
| 450 | return err; |
| 451 | } |
| 452 | |
| 453 | |
| 454 | /* |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 455 | * Socket option code for IP. This is the end of the line after any |
| 456 | * TCP,UDP etc options on an IP socket. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | */ |
| 458 | |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 459 | static int do_ip_setsockopt(struct sock *sk, int level, |
David S. Miller | b705884 | 2009-09-30 16:12:20 -0700 | [diff] [blame] | 460 | int optname, char __user *optval, unsigned int optlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | { |
| 462 | struct inet_sock *inet = inet_sk(sk); |
Jianjun Kong | 09cb105 | 2008-11-03 00:27:11 -0800 | [diff] [blame] | 463 | int val = 0, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 465 | if (((1<<optname) & ((1<<IP_PKTINFO) | (1<<IP_RECVTTL) | |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 466 | (1<<IP_RECVOPTS) | (1<<IP_RECVTOS) | |
| 467 | (1<<IP_RETOPTS) | (1<<IP_TOS) | |
| 468 | (1<<IP_TTL) | (1<<IP_HDRINCL) | |
| 469 | (1<<IP_MTU_DISCOVER) | (1<<IP_RECVERR) | |
| 470 | (1<<IP_ROUTER_ALERT) | (1<<IP_FREEBIND) | |
Stephen Hemminger | d218d11 | 2010-01-11 16:28:01 -0800 | [diff] [blame] | 471 | (1<<IP_PASSSEC) | (1<<IP_TRANSPARENT) | |
Jiri Olsa | 7b2ff18 | 2010-06-15 01:07:31 +0000 | [diff] [blame] | 472 | (1<<IP_MINTTL) | (1<<IP_NODEFRAG))) || |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 473 | optname == IP_MULTICAST_TTL || |
Nivedita Singhvi | f771bef | 2009-05-28 07:00:46 +0000 | [diff] [blame] | 474 | optname == IP_MULTICAST_ALL || |
Balazs Scheidler | e8b2dfe | 2008-11-16 19:32:39 -0800 | [diff] [blame] | 475 | optname == IP_MULTICAST_LOOP || |
| 476 | optname == IP_RECVORIGDSTADDR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | if (optlen >= sizeof(int)) { |
| 478 | if (get_user(val, (int __user *) optval)) |
| 479 | return -EFAULT; |
| 480 | } else if (optlen >= sizeof(char)) { |
| 481 | unsigned char ucval; |
| 482 | |
| 483 | if (get_user(ucval, (unsigned char __user *) optval)) |
| 484 | return -EFAULT; |
| 485 | val = (int) ucval; |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | /* If optlen==0, it is equivalent to val == 0 */ |
| 490 | |
Pavel Emelyanov | 6a9fb94 | 2007-11-05 21:32:31 -0800 | [diff] [blame] | 491 | if (ip_mroute_opt(optname)) |
Jianjun Kong | 09cb105 | 2008-11-03 00:27:11 -0800 | [diff] [blame] | 492 | return ip_mroute_setsockopt(sk, optname, optval, optlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | |
| 494 | err = 0; |
| 495 | lock_sock(sk); |
| 496 | |
| 497 | switch (optname) { |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 498 | case IP_OPTIONS: |
| 499 | { |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 500 | struct ip_options *opt = NULL; |
roel kluin | 65a1c4f | 2009-10-23 05:59:21 +0000 | [diff] [blame] | 501 | if (optlen > 40) |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 502 | goto e_inval; |
YOSHIFUJI Hideaki | 3b1e0a6 | 2008-03-26 02:26:21 +0900 | [diff] [blame] | 503 | err = ip_options_get_from_user(sock_net(sk), &opt, |
Denis V. Lunev | cb84663 | 2008-03-24 15:31:00 -0700 | [diff] [blame] | 504 | optval, optlen); |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 505 | if (err) |
| 506 | break; |
| 507 | if (inet->is_icsk) { |
| 508 | struct inet_connection_sock *icsk = inet_csk(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 510 | if (sk->sk_family == PF_INET || |
| 511 | (!((1 << sk->sk_state) & |
| 512 | (TCPF_LISTEN | TCPF_CLOSE)) && |
Eric Dumazet | c720c7e | 2009-10-15 06:30:45 +0000 | [diff] [blame] | 513 | inet->inet_daddr != LOOPBACK4_IPV6)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | #endif |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 515 | if (inet->opt) |
| 516 | icsk->icsk_ext_hdr_len -= inet->opt->optlen; |
| 517 | if (opt) |
| 518 | icsk->icsk_ext_hdr_len += opt->optlen; |
| 519 | icsk->icsk_sync_mss(sk, icsk->icsk_pmtu_cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 521 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | } |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 524 | opt = xchg(&inet->opt, opt); |
| 525 | kfree(opt); |
| 526 | break; |
| 527 | } |
| 528 | case IP_PKTINFO: |
| 529 | if (val) |
| 530 | inet->cmsg_flags |= IP_CMSG_PKTINFO; |
| 531 | else |
| 532 | inet->cmsg_flags &= ~IP_CMSG_PKTINFO; |
| 533 | break; |
| 534 | case IP_RECVTTL: |
| 535 | if (val) |
| 536 | inet->cmsg_flags |= IP_CMSG_TTL; |
| 537 | else |
| 538 | inet->cmsg_flags &= ~IP_CMSG_TTL; |
| 539 | break; |
| 540 | case IP_RECVTOS: |
| 541 | if (val) |
| 542 | inet->cmsg_flags |= IP_CMSG_TOS; |
| 543 | else |
| 544 | inet->cmsg_flags &= ~IP_CMSG_TOS; |
| 545 | break; |
| 546 | case IP_RECVOPTS: |
| 547 | if (val) |
| 548 | inet->cmsg_flags |= IP_CMSG_RECVOPTS; |
| 549 | else |
| 550 | inet->cmsg_flags &= ~IP_CMSG_RECVOPTS; |
| 551 | break; |
| 552 | case IP_RETOPTS: |
| 553 | if (val) |
| 554 | inet->cmsg_flags |= IP_CMSG_RETOPTS; |
| 555 | else |
| 556 | inet->cmsg_flags &= ~IP_CMSG_RETOPTS; |
| 557 | break; |
| 558 | case IP_PASSSEC: |
| 559 | if (val) |
| 560 | inet->cmsg_flags |= IP_CMSG_PASSSEC; |
| 561 | else |
| 562 | inet->cmsg_flags &= ~IP_CMSG_PASSSEC; |
| 563 | break; |
Balazs Scheidler | e8b2dfe | 2008-11-16 19:32:39 -0800 | [diff] [blame] | 564 | case IP_RECVORIGDSTADDR: |
| 565 | if (val) |
| 566 | inet->cmsg_flags |= IP_CMSG_ORIGDSTADDR; |
| 567 | else |
| 568 | inet->cmsg_flags &= ~IP_CMSG_ORIGDSTADDR; |
| 569 | break; |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 570 | case IP_TOS: /* This sets both TOS and Precedence */ |
| 571 | if (sk->sk_type == SOCK_STREAM) { |
| 572 | val &= ~3; |
| 573 | val |= inet->tos & 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | } |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 575 | if (inet->tos != val) { |
| 576 | inet->tos = val; |
| 577 | sk->sk_priority = rt_tos2priority(val); |
| 578 | sk_dst_reset(sk); |
| 579 | } |
| 580 | break; |
| 581 | case IP_TTL: |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 582 | if (optlen < 1) |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 583 | goto e_inval; |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 584 | if (val != -1 && (val < 0 || val > 255)) |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 585 | goto e_inval; |
| 586 | inet->uc_ttl = val; |
| 587 | break; |
| 588 | case IP_HDRINCL: |
| 589 | if (sk->sk_type != SOCK_RAW) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | err = -ENOPROTOOPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | break; |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 592 | } |
| 593 | inet->hdrincl = val ? 1 : 0; |
| 594 | break; |
Jiri Olsa | 7b2ff18 | 2010-06-15 01:07:31 +0000 | [diff] [blame] | 595 | case IP_NODEFRAG: |
| 596 | if (sk->sk_type != SOCK_RAW) { |
| 597 | err = -ENOPROTOOPT; |
| 598 | break; |
| 599 | } |
| 600 | inet->nodefrag = val ? 1 : 0; |
| 601 | break; |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 602 | case IP_MTU_DISCOVER: |
John Dykstra | 0eae750 | 2009-10-19 21:53:53 -0700 | [diff] [blame] | 603 | if (val < IP_PMTUDISC_DONT || val > IP_PMTUDISC_PROBE) |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 604 | goto e_inval; |
| 605 | inet->pmtudisc = val; |
| 606 | break; |
| 607 | case IP_RECVERR: |
| 608 | inet->recverr = !!val; |
| 609 | if (!val) |
| 610 | skb_queue_purge(&sk->sk_error_queue); |
| 611 | break; |
| 612 | case IP_MULTICAST_TTL: |
| 613 | if (sk->sk_type == SOCK_STREAM) |
| 614 | goto e_inval; |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 615 | if (optlen < 1) |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 616 | goto e_inval; |
Jianjun Kong | 09cb105 | 2008-11-03 00:27:11 -0800 | [diff] [blame] | 617 | if (val == -1) |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 618 | val = 1; |
| 619 | if (val < 0 || val > 255) |
| 620 | goto e_inval; |
| 621 | inet->mc_ttl = val; |
| 622 | break; |
| 623 | case IP_MULTICAST_LOOP: |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 624 | if (optlen < 1) |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 625 | goto e_inval; |
| 626 | inet->mc_loop = !!val; |
| 627 | break; |
| 628 | case IP_MULTICAST_IF: |
| 629 | { |
| 630 | struct ip_mreqn mreq; |
| 631 | struct net_device *dev = NULL; |
| 632 | |
| 633 | if (sk->sk_type == SOCK_STREAM) |
| 634 | goto e_inval; |
| 635 | /* |
| 636 | * Check the arguments are allowable |
| 637 | */ |
| 638 | |
Shan Wei | 0915921 | 2009-09-22 15:41:10 +0000 | [diff] [blame] | 639 | if (optlen < sizeof(struct in_addr)) |
| 640 | goto e_inval; |
| 641 | |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 642 | err = -EFAULT; |
| 643 | if (optlen >= sizeof(struct ip_mreqn)) { |
Jianjun Kong | 09cb105 | 2008-11-03 00:27:11 -0800 | [diff] [blame] | 644 | if (copy_from_user(&mreq, optval, sizeof(mreq))) |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 645 | break; |
| 646 | } else { |
| 647 | memset(&mreq, 0, sizeof(mreq)); |
| 648 | if (optlen >= sizeof(struct in_addr) && |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 649 | copy_from_user(&mreq.imr_address, optval, |
| 650 | sizeof(struct in_addr))) |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 651 | break; |
| 652 | } |
| 653 | |
| 654 | if (!mreq.imr_ifindex) { |
Al Viro | e6f1ceb | 2008-03-17 22:44:53 -0700 | [diff] [blame] | 655 | if (mreq.imr_address.s_addr == htonl(INADDR_ANY)) { |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 656 | inet->mc_index = 0; |
| 657 | inet->mc_addr = 0; |
| 658 | err = 0; |
| 659 | break; |
| 660 | } |
YOSHIFUJI Hideaki | 3b1e0a6 | 2008-03-26 02:26:21 +0900 | [diff] [blame] | 661 | dev = ip_dev_find(sock_net(sk), mreq.imr_address.s_addr); |
Eric Dumazet | 55b8050 | 2009-10-19 06:41:58 +0000 | [diff] [blame] | 662 | if (dev) |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 663 | mreq.imr_ifindex = dev->ifindex; |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 664 | } else |
Eric Dumazet | 55b8050 | 2009-10-19 06:41:58 +0000 | [diff] [blame] | 665 | dev = dev_get_by_index(sock_net(sk), mreq.imr_ifindex); |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 666 | |
| 667 | |
| 668 | err = -EADDRNOTAVAIL; |
| 669 | if (!dev) |
| 670 | break; |
Eric Dumazet | 55b8050 | 2009-10-19 06:41:58 +0000 | [diff] [blame] | 671 | dev_put(dev); |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 672 | |
| 673 | err = -EINVAL; |
| 674 | if (sk->sk_bound_dev_if && |
| 675 | mreq.imr_ifindex != sk->sk_bound_dev_if) |
| 676 | break; |
| 677 | |
| 678 | inet->mc_index = mreq.imr_ifindex; |
| 679 | inet->mc_addr = mreq.imr_address.s_addr; |
| 680 | err = 0; |
| 681 | break; |
| 682 | } |
| 683 | |
| 684 | case IP_ADD_MEMBERSHIP: |
| 685 | case IP_DROP_MEMBERSHIP: |
| 686 | { |
| 687 | struct ip_mreqn mreq; |
| 688 | |
Flavio Leitner | a96fb49 | 2007-08-24 22:16:39 -0700 | [diff] [blame] | 689 | err = -EPROTO; |
| 690 | if (inet_sk(sk)->is_icsk) |
| 691 | break; |
| 692 | |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 693 | if (optlen < sizeof(struct ip_mreq)) |
| 694 | goto e_inval; |
| 695 | err = -EFAULT; |
| 696 | if (optlen >= sizeof(struct ip_mreqn)) { |
Jianjun Kong | 09cb105 | 2008-11-03 00:27:11 -0800 | [diff] [blame] | 697 | if (copy_from_user(&mreq, optval, sizeof(mreq))) |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 698 | break; |
| 699 | } else { |
| 700 | memset(&mreq, 0, sizeof(mreq)); |
Jianjun Kong | 09cb105 | 2008-11-03 00:27:11 -0800 | [diff] [blame] | 701 | if (copy_from_user(&mreq, optval, sizeof(struct ip_mreq))) |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 702 | break; |
| 703 | } |
| 704 | |
| 705 | if (optname == IP_ADD_MEMBERSHIP) |
| 706 | err = ip_mc_join_group(sk, &mreq); |
| 707 | else |
| 708 | err = ip_mc_leave_group(sk, &mreq); |
| 709 | break; |
| 710 | } |
| 711 | case IP_MSFILTER: |
| 712 | { |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 713 | struct ip_msfilter *msf; |
| 714 | |
| 715 | if (optlen < IP_MSFILTER_SIZE(0)) |
| 716 | goto e_inval; |
| 717 | if (optlen > sysctl_optmem_max) { |
| 718 | err = -ENOBUFS; |
| 719 | break; |
| 720 | } |
| 721 | msf = kmalloc(optlen, GFP_KERNEL); |
Stephen Hemminger | cfcabdc | 2007-10-09 01:59:42 -0700 | [diff] [blame] | 722 | if (!msf) { |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 723 | err = -ENOBUFS; |
| 724 | break; |
| 725 | } |
| 726 | err = -EFAULT; |
| 727 | if (copy_from_user(msf, optval, optlen)) { |
| 728 | kfree(msf); |
| 729 | break; |
| 730 | } |
| 731 | /* numsrc >= (1G-4) overflow in 32 bits */ |
| 732 | if (msf->imsf_numsrc >= 0x3ffffffcU || |
| 733 | msf->imsf_numsrc > sysctl_igmp_max_msf) { |
| 734 | kfree(msf); |
| 735 | err = -ENOBUFS; |
| 736 | break; |
| 737 | } |
| 738 | if (IP_MSFILTER_SIZE(msf->imsf_numsrc) > optlen) { |
| 739 | kfree(msf); |
| 740 | err = -EINVAL; |
| 741 | break; |
| 742 | } |
| 743 | err = ip_mc_msfilter(sk, msf, 0); |
| 744 | kfree(msf); |
| 745 | break; |
| 746 | } |
| 747 | case IP_BLOCK_SOURCE: |
| 748 | case IP_UNBLOCK_SOURCE: |
| 749 | case IP_ADD_SOURCE_MEMBERSHIP: |
| 750 | case IP_DROP_SOURCE_MEMBERSHIP: |
| 751 | { |
| 752 | struct ip_mreq_source mreqs; |
| 753 | int omode, add; |
| 754 | |
| 755 | if (optlen != sizeof(struct ip_mreq_source)) |
| 756 | goto e_inval; |
| 757 | if (copy_from_user(&mreqs, optval, sizeof(mreqs))) { |
| 758 | err = -EFAULT; |
| 759 | break; |
| 760 | } |
| 761 | if (optname == IP_BLOCK_SOURCE) { |
| 762 | omode = MCAST_EXCLUDE; |
| 763 | add = 1; |
| 764 | } else if (optname == IP_UNBLOCK_SOURCE) { |
| 765 | omode = MCAST_EXCLUDE; |
| 766 | add = 0; |
| 767 | } else if (optname == IP_ADD_SOURCE_MEMBERSHIP) { |
| 768 | struct ip_mreqn mreq; |
| 769 | |
| 770 | mreq.imr_multiaddr.s_addr = mreqs.imr_multiaddr; |
| 771 | mreq.imr_address.s_addr = mreqs.imr_interface; |
| 772 | mreq.imr_ifindex = 0; |
| 773 | err = ip_mc_join_group(sk, &mreq); |
| 774 | if (err && err != -EADDRINUSE) |
| 775 | break; |
| 776 | omode = MCAST_INCLUDE; |
| 777 | add = 1; |
| 778 | } else /* IP_DROP_SOURCE_MEMBERSHIP */ { |
| 779 | omode = MCAST_INCLUDE; |
| 780 | add = 0; |
| 781 | } |
| 782 | err = ip_mc_source(add, omode, sk, &mreqs, 0); |
| 783 | break; |
| 784 | } |
| 785 | case MCAST_JOIN_GROUP: |
| 786 | case MCAST_LEAVE_GROUP: |
| 787 | { |
| 788 | struct group_req greq; |
| 789 | struct sockaddr_in *psin; |
| 790 | struct ip_mreqn mreq; |
| 791 | |
| 792 | if (optlen < sizeof(struct group_req)) |
| 793 | goto e_inval; |
| 794 | err = -EFAULT; |
| 795 | if (copy_from_user(&greq, optval, sizeof(greq))) |
| 796 | break; |
| 797 | psin = (struct sockaddr_in *)&greq.gr_group; |
| 798 | if (psin->sin_family != AF_INET) |
| 799 | goto e_inval; |
| 800 | memset(&mreq, 0, sizeof(mreq)); |
| 801 | mreq.imr_multiaddr = psin->sin_addr; |
| 802 | mreq.imr_ifindex = greq.gr_interface; |
| 803 | |
| 804 | if (optname == MCAST_JOIN_GROUP) |
| 805 | err = ip_mc_join_group(sk, &mreq); |
| 806 | else |
| 807 | err = ip_mc_leave_group(sk, &mreq); |
| 808 | break; |
| 809 | } |
| 810 | case MCAST_JOIN_SOURCE_GROUP: |
| 811 | case MCAST_LEAVE_SOURCE_GROUP: |
| 812 | case MCAST_BLOCK_SOURCE: |
| 813 | case MCAST_UNBLOCK_SOURCE: |
| 814 | { |
| 815 | struct group_source_req greqs; |
| 816 | struct ip_mreq_source mreqs; |
| 817 | struct sockaddr_in *psin; |
| 818 | int omode, add; |
| 819 | |
| 820 | if (optlen != sizeof(struct group_source_req)) |
| 821 | goto e_inval; |
| 822 | if (copy_from_user(&greqs, optval, sizeof(greqs))) { |
| 823 | err = -EFAULT; |
| 824 | break; |
| 825 | } |
| 826 | if (greqs.gsr_group.ss_family != AF_INET || |
| 827 | greqs.gsr_source.ss_family != AF_INET) { |
| 828 | err = -EADDRNOTAVAIL; |
| 829 | break; |
| 830 | } |
| 831 | psin = (struct sockaddr_in *)&greqs.gsr_group; |
| 832 | mreqs.imr_multiaddr = psin->sin_addr.s_addr; |
| 833 | psin = (struct sockaddr_in *)&greqs.gsr_source; |
| 834 | mreqs.imr_sourceaddr = psin->sin_addr.s_addr; |
| 835 | mreqs.imr_interface = 0; /* use index for mc_source */ |
| 836 | |
| 837 | if (optname == MCAST_BLOCK_SOURCE) { |
| 838 | omode = MCAST_EXCLUDE; |
| 839 | add = 1; |
| 840 | } else if (optname == MCAST_UNBLOCK_SOURCE) { |
| 841 | omode = MCAST_EXCLUDE; |
| 842 | add = 0; |
| 843 | } else if (optname == MCAST_JOIN_SOURCE_GROUP) { |
| 844 | struct ip_mreqn mreq; |
| 845 | |
| 846 | psin = (struct sockaddr_in *)&greqs.gsr_group; |
| 847 | mreq.imr_multiaddr = psin->sin_addr; |
| 848 | mreq.imr_address.s_addr = 0; |
| 849 | mreq.imr_ifindex = greqs.gsr_interface; |
| 850 | err = ip_mc_join_group(sk, &mreq); |
| 851 | if (err && err != -EADDRINUSE) |
| 852 | break; |
| 853 | greqs.gsr_interface = mreq.imr_ifindex; |
| 854 | omode = MCAST_INCLUDE; |
| 855 | add = 1; |
| 856 | } else /* MCAST_LEAVE_SOURCE_GROUP */ { |
| 857 | omode = MCAST_INCLUDE; |
| 858 | add = 0; |
| 859 | } |
| 860 | err = ip_mc_source(add, omode, sk, &mreqs, |
| 861 | greqs.gsr_interface); |
| 862 | break; |
| 863 | } |
| 864 | case MCAST_MSFILTER: |
| 865 | { |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 866 | struct sockaddr_in *psin; |
| 867 | struct ip_msfilter *msf = NULL; |
| 868 | struct group_filter *gsf = NULL; |
| 869 | int msize, i, ifindex; |
| 870 | |
| 871 | if (optlen < GROUP_FILTER_SIZE(0)) |
| 872 | goto e_inval; |
| 873 | if (optlen > sysctl_optmem_max) { |
| 874 | err = -ENOBUFS; |
| 875 | break; |
| 876 | } |
Jianjun Kong | 09cb105 | 2008-11-03 00:27:11 -0800 | [diff] [blame] | 877 | gsf = kmalloc(optlen, GFP_KERNEL); |
Stephen Hemminger | cfcabdc | 2007-10-09 01:59:42 -0700 | [diff] [blame] | 878 | if (!gsf) { |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 879 | err = -ENOBUFS; |
| 880 | break; |
| 881 | } |
| 882 | err = -EFAULT; |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 883 | if (copy_from_user(gsf, optval, optlen)) |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 884 | goto mc_msf_out; |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 885 | |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 886 | /* numsrc >= (4G-140)/128 overflow in 32 bits */ |
| 887 | if (gsf->gf_numsrc >= 0x1ffffff || |
| 888 | gsf->gf_numsrc > sysctl_igmp_max_msf) { |
| 889 | err = -ENOBUFS; |
| 890 | goto mc_msf_out; |
| 891 | } |
| 892 | if (GROUP_FILTER_SIZE(gsf->gf_numsrc) > optlen) { |
| 893 | err = -EINVAL; |
| 894 | goto mc_msf_out; |
| 895 | } |
| 896 | msize = IP_MSFILTER_SIZE(gsf->gf_numsrc); |
Jianjun Kong | 09cb105 | 2008-11-03 00:27:11 -0800 | [diff] [blame] | 897 | msf = kmalloc(msize, GFP_KERNEL); |
Stephen Hemminger | cfcabdc | 2007-10-09 01:59:42 -0700 | [diff] [blame] | 898 | if (!msf) { |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 899 | err = -ENOBUFS; |
| 900 | goto mc_msf_out; |
| 901 | } |
| 902 | ifindex = gsf->gf_interface; |
| 903 | psin = (struct sockaddr_in *)&gsf->gf_group; |
| 904 | if (psin->sin_family != AF_INET) { |
| 905 | err = -EADDRNOTAVAIL; |
| 906 | goto mc_msf_out; |
| 907 | } |
| 908 | msf->imsf_multiaddr = psin->sin_addr.s_addr; |
| 909 | msf->imsf_interface = 0; |
| 910 | msf->imsf_fmode = gsf->gf_fmode; |
| 911 | msf->imsf_numsrc = gsf->gf_numsrc; |
| 912 | err = -EADDRNOTAVAIL; |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 913 | for (i = 0; i < gsf->gf_numsrc; ++i) { |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 914 | psin = (struct sockaddr_in *)&gsf->gf_slist[i]; |
| 915 | |
| 916 | if (psin->sin_family != AF_INET) |
| 917 | goto mc_msf_out; |
| 918 | msf->imsf_slist[i] = psin->sin_addr.s_addr; |
| 919 | } |
| 920 | kfree(gsf); |
| 921 | gsf = NULL; |
| 922 | |
| 923 | err = ip_mc_msfilter(sk, msf, ifindex); |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 924 | mc_msf_out: |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 925 | kfree(msf); |
| 926 | kfree(gsf); |
| 927 | break; |
| 928 | } |
Nivedita Singhvi | f771bef | 2009-05-28 07:00:46 +0000 | [diff] [blame] | 929 | case IP_MULTICAST_ALL: |
| 930 | if (optlen < 1) |
| 931 | goto e_inval; |
| 932 | if (val != 0 && val != 1) |
| 933 | goto e_inval; |
| 934 | inet->mc_all = val; |
| 935 | break; |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 936 | case IP_ROUTER_ALERT: |
| 937 | err = ip_ra_control(sk, val ? 1 : 0, NULL); |
| 938 | break; |
| 939 | |
| 940 | case IP_FREEBIND: |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 941 | if (optlen < 1) |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 942 | goto e_inval; |
| 943 | inet->freebind = !!val; |
| 944 | break; |
| 945 | |
| 946 | case IP_IPSEC_POLICY: |
| 947 | case IP_XFRM_POLICY: |
| 948 | err = -EPERM; |
| 949 | if (!capable(CAP_NET_ADMIN)) |
| 950 | break; |
| 951 | err = xfrm_user_policy(sk, optname, optval, optlen); |
| 952 | break; |
| 953 | |
KOVACS Krisztian | f5715ae | 2008-10-01 07:30:02 -0700 | [diff] [blame] | 954 | case IP_TRANSPARENT: |
| 955 | if (!capable(CAP_NET_ADMIN)) { |
| 956 | err = -EPERM; |
| 957 | break; |
| 958 | } |
| 959 | if (optlen < 1) |
| 960 | goto e_inval; |
| 961 | inet->transparent = !!val; |
| 962 | break; |
| 963 | |
Stephen Hemminger | d218d11 | 2010-01-11 16:28:01 -0800 | [diff] [blame] | 964 | case IP_MINTTL: |
| 965 | if (optlen < 1) |
| 966 | goto e_inval; |
| 967 | if (val < 0 || val > 255) |
| 968 | goto e_inval; |
| 969 | inet->min_ttl = val; |
| 970 | break; |
| 971 | |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 972 | default: |
| 973 | err = -ENOPROTOOPT; |
| 974 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | } |
| 976 | release_sock(sk); |
| 977 | return err; |
| 978 | |
| 979 | e_inval: |
| 980 | release_sock(sk); |
| 981 | return -EINVAL; |
| 982 | } |
| 983 | |
Eric Dumazet | f84af32 | 2010-04-28 15:31:51 -0700 | [diff] [blame] | 984 | /** |
| 985 | * ip_queue_rcv_skb - Queue an skb into sock receive queue |
| 986 | * @sk: socket |
| 987 | * @skb: buffer |
| 988 | * |
| 989 | * Queues an skb into socket receive queue. If IP_CMSG_PKTINFO option |
| 990 | * is not set, we drop skb dst entry now, while dst cache line is hot. |
| 991 | */ |
| 992 | int ip_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) |
| 993 | { |
| 994 | if (!(inet_sk(sk)->cmsg_flags & IP_CMSG_PKTINFO)) |
| 995 | skb_dst_drop(skb); |
| 996 | return sock_queue_rcv_skb(sk, skb); |
| 997 | } |
| 998 | EXPORT_SYMBOL(ip_queue_rcv_skb); |
| 999 | |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 1000 | int ip_setsockopt(struct sock *sk, int level, |
David S. Miller | b705884 | 2009-09-30 16:12:20 -0700 | [diff] [blame] | 1001 | int optname, char __user *optval, unsigned int optlen) |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 1002 | { |
| 1003 | int err; |
| 1004 | |
| 1005 | if (level != SOL_IP) |
| 1006 | return -ENOPROTOOPT; |
| 1007 | |
| 1008 | err = do_ip_setsockopt(sk, level, optname, optval, optlen); |
| 1009 | #ifdef CONFIG_NETFILTER |
| 1010 | /* we need to exclude all possible ENOPROTOOPTs except default case */ |
| 1011 | if (err == -ENOPROTOOPT && optname != IP_HDRINCL && |
Pavel Emelyanov | 6a9fb94 | 2007-11-05 21:32:31 -0800 | [diff] [blame] | 1012 | optname != IP_IPSEC_POLICY && |
| 1013 | optname != IP_XFRM_POLICY && |
| 1014 | !ip_mroute_opt(optname)) { |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 1015 | lock_sock(sk); |
| 1016 | err = nf_setsockopt(sk, PF_INET, optname, optval, optlen); |
| 1017 | release_sock(sk); |
| 1018 | } |
| 1019 | #endif |
| 1020 | return err; |
| 1021 | } |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 1022 | EXPORT_SYMBOL(ip_setsockopt); |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 1023 | |
| 1024 | #ifdef CONFIG_COMPAT |
Arnaldo Carvalho de Melo | 543d9cf | 2006-03-20 22:48:35 -0800 | [diff] [blame] | 1025 | int compat_ip_setsockopt(struct sock *sk, int level, int optname, |
David S. Miller | b705884 | 2009-09-30 16:12:20 -0700 | [diff] [blame] | 1026 | char __user *optval, unsigned int optlen) |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 1027 | { |
| 1028 | int err; |
| 1029 | |
| 1030 | if (level != SOL_IP) |
| 1031 | return -ENOPROTOOPT; |
| 1032 | |
David L Stevens | dae5029 | 2008-04-27 01:06:07 -0700 | [diff] [blame] | 1033 | if (optname >= MCAST_JOIN_GROUP && optname <= MCAST_MSFILTER) |
| 1034 | return compat_mc_setsockopt(sk, level, optname, optval, optlen, |
| 1035 | ip_setsockopt); |
| 1036 | |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 1037 | err = do_ip_setsockopt(sk, level, optname, optval, optlen); |
| 1038 | #ifdef CONFIG_NETFILTER |
| 1039 | /* we need to exclude all possible ENOPROTOOPTs except default case */ |
| 1040 | if (err == -ENOPROTOOPT && optname != IP_HDRINCL && |
Pavel Emelyanov | 6a9fb94 | 2007-11-05 21:32:31 -0800 | [diff] [blame] | 1041 | optname != IP_IPSEC_POLICY && |
| 1042 | optname != IP_XFRM_POLICY && |
| 1043 | !ip_mroute_opt(optname)) { |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 1044 | lock_sock(sk); |
Arnaldo Carvalho de Melo | 543d9cf | 2006-03-20 22:48:35 -0800 | [diff] [blame] | 1045 | err = compat_nf_setsockopt(sk, PF_INET, optname, |
| 1046 | optval, optlen); |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 1047 | release_sock(sk); |
| 1048 | } |
| 1049 | #endif |
| 1050 | return err; |
| 1051 | } |
Arnaldo Carvalho de Melo | 543d9cf | 2006-03-20 22:48:35 -0800 | [diff] [blame] | 1052 | EXPORT_SYMBOL(compat_ip_setsockopt); |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 1053 | #endif |
| 1054 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | /* |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 1056 | * Get the options. Note for future reference. The GET of IP options gets |
| 1057 | * the _received_ ones. The set sets the _sent_ ones. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | */ |
| 1059 | |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 1060 | static int do_ip_getsockopt(struct sock *sk, int level, int optname, |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1061 | char __user *optval, int __user *optlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | { |
| 1063 | struct inet_sock *inet = inet_sk(sk); |
| 1064 | int val; |
| 1065 | int len; |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1066 | |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1067 | if (level != SOL_IP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | return -EOPNOTSUPP; |
| 1069 | |
Pavel Emelyanov | 6a9fb94 | 2007-11-05 21:32:31 -0800 | [diff] [blame] | 1070 | if (ip_mroute_opt(optname)) |
Jianjun Kong | 09cb105 | 2008-11-03 00:27:11 -0800 | [diff] [blame] | 1071 | return ip_mroute_getsockopt(sk, optname, optval, optlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | |
Jianjun Kong | 09cb105 | 2008-11-03 00:27:11 -0800 | [diff] [blame] | 1073 | if (get_user(len, optlen)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | return -EFAULT; |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1075 | if (len < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | return -EINVAL; |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1077 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | lock_sock(sk); |
| 1079 | |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1080 | switch (optname) { |
| 1081 | case IP_OPTIONS: |
| 1082 | { |
| 1083 | unsigned char optbuf[sizeof(struct ip_options)+40]; |
Jianjun Kong | 09cb105 | 2008-11-03 00:27:11 -0800 | [diff] [blame] | 1084 | struct ip_options * opt = (struct ip_options *)optbuf; |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1085 | opt->optlen = 0; |
| 1086 | if (inet->opt) |
| 1087 | memcpy(optbuf, inet->opt, |
| 1088 | sizeof(struct ip_options)+ |
| 1089 | inet->opt->optlen); |
| 1090 | release_sock(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1092 | if (opt->optlen == 0) |
| 1093 | return put_user(0, optlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1095 | ip_options_undo(opt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1097 | len = min_t(unsigned int, len, opt->optlen); |
| 1098 | if (put_user(len, optlen)) |
| 1099 | return -EFAULT; |
| 1100 | if (copy_to_user(optval, opt->__data, len)) |
| 1101 | return -EFAULT; |
| 1102 | return 0; |
| 1103 | } |
| 1104 | case IP_PKTINFO: |
| 1105 | val = (inet->cmsg_flags & IP_CMSG_PKTINFO) != 0; |
| 1106 | break; |
| 1107 | case IP_RECVTTL: |
| 1108 | val = (inet->cmsg_flags & IP_CMSG_TTL) != 0; |
| 1109 | break; |
| 1110 | case IP_RECVTOS: |
| 1111 | val = (inet->cmsg_flags & IP_CMSG_TOS) != 0; |
| 1112 | break; |
| 1113 | case IP_RECVOPTS: |
| 1114 | val = (inet->cmsg_flags & IP_CMSG_RECVOPTS) != 0; |
| 1115 | break; |
| 1116 | case IP_RETOPTS: |
| 1117 | val = (inet->cmsg_flags & IP_CMSG_RETOPTS) != 0; |
| 1118 | break; |
| 1119 | case IP_PASSSEC: |
| 1120 | val = (inet->cmsg_flags & IP_CMSG_PASSSEC) != 0; |
| 1121 | break; |
Balazs Scheidler | e8b2dfe | 2008-11-16 19:32:39 -0800 | [diff] [blame] | 1122 | case IP_RECVORIGDSTADDR: |
| 1123 | val = (inet->cmsg_flags & IP_CMSG_ORIGDSTADDR) != 0; |
| 1124 | break; |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1125 | case IP_TOS: |
| 1126 | val = inet->tos; |
| 1127 | break; |
| 1128 | case IP_TTL: |
| 1129 | val = (inet->uc_ttl == -1 ? |
| 1130 | sysctl_ip_default_ttl : |
| 1131 | inet->uc_ttl); |
| 1132 | break; |
| 1133 | case IP_HDRINCL: |
| 1134 | val = inet->hdrincl; |
| 1135 | break; |
Michael Kerrisk | a89b476 | 2010-09-10 20:26:56 +0000 | [diff] [blame] | 1136 | case IP_NODEFRAG: |
| 1137 | val = inet->nodefrag; |
| 1138 | break; |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1139 | case IP_MTU_DISCOVER: |
| 1140 | val = inet->pmtudisc; |
| 1141 | break; |
| 1142 | case IP_MTU: |
| 1143 | { |
| 1144 | struct dst_entry *dst; |
| 1145 | val = 0; |
| 1146 | dst = sk_dst_get(sk); |
| 1147 | if (dst) { |
| 1148 | val = dst_mtu(dst); |
| 1149 | dst_release(dst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | } |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1151 | if (!val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | release_sock(sk); |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1153 | return -ENOTCONN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | } |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1155 | break; |
| 1156 | } |
| 1157 | case IP_RECVERR: |
| 1158 | val = inet->recverr; |
| 1159 | break; |
| 1160 | case IP_MULTICAST_TTL: |
| 1161 | val = inet->mc_ttl; |
| 1162 | break; |
| 1163 | case IP_MULTICAST_LOOP: |
| 1164 | val = inet->mc_loop; |
| 1165 | break; |
| 1166 | case IP_MULTICAST_IF: |
| 1167 | { |
| 1168 | struct in_addr addr; |
| 1169 | len = min_t(unsigned int, len, sizeof(struct in_addr)); |
| 1170 | addr.s_addr = inet->mc_addr; |
| 1171 | release_sock(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1173 | if (put_user(len, optlen)) |
| 1174 | return -EFAULT; |
| 1175 | if (copy_to_user(optval, &addr, len)) |
| 1176 | return -EFAULT; |
| 1177 | return 0; |
| 1178 | } |
| 1179 | case IP_MSFILTER: |
| 1180 | { |
| 1181 | struct ip_msfilter msf; |
| 1182 | int err; |
| 1183 | |
| 1184 | if (len < IP_MSFILTER_SIZE(0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | release_sock(sk); |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1186 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | } |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1188 | if (copy_from_user(&msf, optval, IP_MSFILTER_SIZE(0))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | release_sock(sk); |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1190 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | } |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1192 | err = ip_mc_msfget(sk, &msf, |
| 1193 | (struct ip_msfilter __user *)optval, optlen); |
| 1194 | release_sock(sk); |
| 1195 | return err; |
| 1196 | } |
| 1197 | case MCAST_MSFILTER: |
| 1198 | { |
| 1199 | struct group_filter gsf; |
| 1200 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1202 | if (len < GROUP_FILTER_SIZE(0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | release_sock(sk); |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1204 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | } |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1206 | if (copy_from_user(&gsf, optval, GROUP_FILTER_SIZE(0))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | release_sock(sk); |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1208 | return -EFAULT; |
| 1209 | } |
| 1210 | err = ip_mc_gsfget(sk, &gsf, |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 1211 | (struct group_filter __user *)optval, |
| 1212 | optlen); |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1213 | release_sock(sk); |
| 1214 | return err; |
| 1215 | } |
Nivedita Singhvi | f771bef | 2009-05-28 07:00:46 +0000 | [diff] [blame] | 1216 | case IP_MULTICAST_ALL: |
| 1217 | val = inet->mc_all; |
| 1218 | break; |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1219 | case IP_PKTOPTIONS: |
| 1220 | { |
| 1221 | struct msghdr msg; |
| 1222 | |
| 1223 | release_sock(sk); |
| 1224 | |
| 1225 | if (sk->sk_type != SOCK_STREAM) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | return -ENOPROTOOPT; |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1227 | |
| 1228 | msg.msg_control = optval; |
| 1229 | msg.msg_controllen = len; |
| 1230 | msg.msg_flags = 0; |
| 1231 | |
| 1232 | if (inet->cmsg_flags & IP_CMSG_PKTINFO) { |
| 1233 | struct in_pktinfo info; |
| 1234 | |
Eric Dumazet | c720c7e | 2009-10-15 06:30:45 +0000 | [diff] [blame] | 1235 | info.ipi_addr.s_addr = inet->inet_rcv_saddr; |
| 1236 | info.ipi_spec_dst.s_addr = inet->inet_rcv_saddr; |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1237 | info.ipi_ifindex = inet->mc_index; |
| 1238 | put_cmsg(&msg, SOL_IP, IP_PKTINFO, sizeof(info), &info); |
| 1239 | } |
| 1240 | if (inet->cmsg_flags & IP_CMSG_TTL) { |
| 1241 | int hlim = inet->mc_ttl; |
| 1242 | put_cmsg(&msg, SOL_IP, IP_TTL, sizeof(hlim), &hlim); |
| 1243 | } |
| 1244 | len -= msg.msg_controllen; |
| 1245 | return put_user(len, optlen); |
| 1246 | } |
| 1247 | case IP_FREEBIND: |
| 1248 | val = inet->freebind; |
| 1249 | break; |
KOVACS Krisztian | f5715ae | 2008-10-01 07:30:02 -0700 | [diff] [blame] | 1250 | case IP_TRANSPARENT: |
| 1251 | val = inet->transparent; |
| 1252 | break; |
Stephen Hemminger | d218d11 | 2010-01-11 16:28:01 -0800 | [diff] [blame] | 1253 | case IP_MINTTL: |
| 1254 | val = inet->min_ttl; |
| 1255 | break; |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1256 | default: |
| 1257 | release_sock(sk); |
| 1258 | return -ENOPROTOOPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | } |
| 1260 | release_sock(sk); |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1261 | |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 1262 | if (len < sizeof(int) && len > 0 && val >= 0 && val <= 255) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | unsigned char ucval = (unsigned char)val; |
| 1264 | len = 1; |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1265 | if (put_user(len, optlen)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | return -EFAULT; |
Jianjun Kong | 09cb105 | 2008-11-03 00:27:11 -0800 | [diff] [blame] | 1267 | if (copy_to_user(optval, &ucval, 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | return -EFAULT; |
| 1269 | } else { |
| 1270 | len = min_t(unsigned int, sizeof(int), len); |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1271 | if (put_user(len, optlen)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | return -EFAULT; |
Jianjun Kong | 09cb105 | 2008-11-03 00:27:11 -0800 | [diff] [blame] | 1273 | if (copy_to_user(optval, &val, len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | return -EFAULT; |
| 1275 | } |
| 1276 | return 0; |
| 1277 | } |
| 1278 | |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 1279 | int ip_getsockopt(struct sock *sk, int level, |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1280 | int optname, char __user *optval, int __user *optlen) |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 1281 | { |
| 1282 | int err; |
| 1283 | |
| 1284 | err = do_ip_getsockopt(sk, level, optname, optval, optlen); |
| 1285 | #ifdef CONFIG_NETFILTER |
| 1286 | /* we need to exclude all possible ENOPROTOOPTs except default case */ |
Pavel Emelyanov | 6a9fb94 | 2007-11-05 21:32:31 -0800 | [diff] [blame] | 1287 | if (err == -ENOPROTOOPT && optname != IP_PKTOPTIONS && |
| 1288 | !ip_mroute_opt(optname)) { |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1289 | int len; |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 1290 | |
Jianjun Kong | 09cb105 | 2008-11-03 00:27:11 -0800 | [diff] [blame] | 1291 | if (get_user(len, optlen)) |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 1292 | return -EFAULT; |
| 1293 | |
| 1294 | lock_sock(sk); |
| 1295 | err = nf_getsockopt(sk, PF_INET, optname, optval, |
| 1296 | &len); |
| 1297 | release_sock(sk); |
| 1298 | if (err >= 0) |
| 1299 | err = put_user(len, optlen); |
| 1300 | return err; |
| 1301 | } |
| 1302 | #endif |
| 1303 | return err; |
| 1304 | } |
Eric Dumazet | 4d52cfb | 2009-06-02 00:42:16 -0700 | [diff] [blame] | 1305 | EXPORT_SYMBOL(ip_getsockopt); |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 1306 | |
| 1307 | #ifdef CONFIG_COMPAT |
Arnaldo Carvalho de Melo | 543d9cf | 2006-03-20 22:48:35 -0800 | [diff] [blame] | 1308 | int compat_ip_getsockopt(struct sock *sk, int level, int optname, |
| 1309 | char __user *optval, int __user *optlen) |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 1310 | { |
David L Stevens | 42908c6 | 2008-04-29 03:23:22 -0700 | [diff] [blame] | 1311 | int err; |
| 1312 | |
| 1313 | if (optname == MCAST_MSFILTER) |
| 1314 | return compat_mc_getsockopt(sk, level, optname, optval, optlen, |
| 1315 | ip_getsockopt); |
| 1316 | |
| 1317 | err = do_ip_getsockopt(sk, level, optname, optval, optlen); |
| 1318 | |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 1319 | #ifdef CONFIG_NETFILTER |
| 1320 | /* we need to exclude all possible ENOPROTOOPTs except default case */ |
Pavel Emelyanov | 6a9fb94 | 2007-11-05 21:32:31 -0800 | [diff] [blame] | 1321 | if (err == -ENOPROTOOPT && optname != IP_PKTOPTIONS && |
| 1322 | !ip_mroute_opt(optname)) { |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1323 | int len; |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 1324 | |
Arnaldo Carvalho de Melo | 543d9cf | 2006-03-20 22:48:35 -0800 | [diff] [blame] | 1325 | if (get_user(len, optlen)) |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 1326 | return -EFAULT; |
| 1327 | |
| 1328 | lock_sock(sk); |
Arnaldo Carvalho de Melo | 543d9cf | 2006-03-20 22:48:35 -0800 | [diff] [blame] | 1329 | err = compat_nf_getsockopt(sk, PF_INET, optname, optval, &len); |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 1330 | release_sock(sk); |
| 1331 | if (err >= 0) |
| 1332 | err = put_user(len, optlen); |
| 1333 | return err; |
| 1334 | } |
| 1335 | #endif |
| 1336 | return err; |
| 1337 | } |
Arnaldo Carvalho de Melo | 543d9cf | 2006-03-20 22:48:35 -0800 | [diff] [blame] | 1338 | EXPORT_SYMBOL(compat_ip_getsockopt); |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 1339 | #endif |