ia64/xen-unstable

changeset 3257:40ee875afa3b

bitkeeper revision 1.1159.170.63 (41b65949_dZA-RJn9QoHubiKswWy4Q)

.del-raw.c~2e8c27c4e23863e9:
Delete: linux-2.6.10-rc3-xen-sparse/net/ipv4/raw.c
author cl349@arcadians.cl.cam.ac.uk
date Wed Dec 08 01:30:49 2004 +0000 (2004-12-08)
parents 054fad40be91
children 708bd9c8362b
files .rootkeys linux-2.6.10-rc3-xen-sparse/net/ipv4/raw.c
line diff
     1.1 --- a/.rootkeys	Wed Dec 08 01:29:27 2004 +0000
     1.2 +++ b/.rootkeys	Wed Dec 08 01:30:49 2004 +0000
     1.3 @@ -254,7 +254,6 @@ 40f56a0ddHCSs3501MY4hRf22tctOw linux-2.6
     1.4  412f46c0LJuKAgSPGoC0Z1DEkLfuLA linux-2.6.10-rc3-xen-sparse/mm/memory.c
     1.5  410a94a4KT6I6X0LVc7djB39tRDp4g linux-2.6.10-rc3-xen-sparse/mm/page_alloc.c
     1.6  41505c572m-s9ATiO1LiD1GPznTTIg linux-2.6.10-rc3-xen-sparse/net/core/skbuff.c
     1.7 -4149ec79wMpIHdvbntxqVGLRZZjPxw linux-2.6.10-rc3-xen-sparse/net/ipv4/raw.c
     1.8  413cb1e4zst25MDYjg63Y-NGC5_pLg netbsd-2.0-xen-sparse/Makefile
     1.9  413cb1e5c_Mkxf_X0zimEhTKI_l4DA netbsd-2.0-xen-sparse/mkbuildtree
    1.10  413cb1e5kY_Zil7-b0kI6hvCIxBEYg netbsd-2.0-xen-sparse/nbconfig-xen
     2.1 --- a/linux-2.6.10-rc3-xen-sparse/net/ipv4/raw.c	Wed Dec 08 01:29:27 2004 +0000
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,887 +0,0 @@
     2.4 -/*
     2.5 - * INET		An implementation of the TCP/IP protocol suite for the LINUX
     2.6 - *		operating system.  INET is implemented using the  BSD Socket
     2.7 - *		interface as the means of communication with the user level.
     2.8 - *
     2.9 - *		RAW - implementation of IP "raw" sockets.
    2.10 - *
    2.11 - * Version:	$Id: raw.c,v 1.64 2002/02/01 22:01:04 davem Exp $
    2.12 - *
    2.13 - * Authors:	Ross Biro, <bir7@leland.Stanford.Edu>
    2.14 - *		Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
    2.15 - *
    2.16 - * Fixes:
    2.17 - *		Alan Cox	:	verify_area() fixed up
    2.18 - *		Alan Cox	:	ICMP error handling
    2.19 - *		Alan Cox	:	EMSGSIZE if you send too big a packet
    2.20 - *		Alan Cox	: 	Now uses generic datagrams and shared
    2.21 - *					skbuff library. No more peek crashes,
    2.22 - *					no more backlogs
    2.23 - *		Alan Cox	:	Checks sk->broadcast.
    2.24 - *		Alan Cox	:	Uses skb_free_datagram/skb_copy_datagram
    2.25 - *		Alan Cox	:	Raw passes ip options too
    2.26 - *		Alan Cox	:	Setsocketopt added
    2.27 - *		Alan Cox	:	Fixed error return for broadcasts
    2.28 - *		Alan Cox	:	Removed wake_up calls
    2.29 - *		Alan Cox	:	Use ttl/tos
    2.30 - *		Alan Cox	:	Cleaned up old debugging
    2.31 - *		Alan Cox	:	Use new kernel side addresses
    2.32 - *	Arnt Gulbrandsen	:	Fixed MSG_DONTROUTE in raw sockets.
    2.33 - *		Alan Cox	:	BSD style RAW socket demultiplexing.
    2.34 - *		Alan Cox	:	Beginnings of mrouted support.
    2.35 - *		Alan Cox	:	Added IP_HDRINCL option.
    2.36 - *		Alan Cox	:	Skip broadcast check if BSDism set.
    2.37 - *		David S. Miller	:	New socket lookup architecture.
    2.38 - *
    2.39 - *		This program is free software; you can redistribute it and/or
    2.40 - *		modify it under the terms of the GNU General Public License
    2.41 - *		as published by the Free Software Foundation; either version
    2.42 - *		2 of the License, or (at your option) any later version.
    2.43 - */
    2.44 - 
    2.45 -#include <linux/config.h> 
    2.46 -#include <asm/atomic.h>
    2.47 -#include <asm/byteorder.h>
    2.48 -#include <asm/current.h>
    2.49 -#include <asm/uaccess.h>
    2.50 -#include <asm/ioctls.h>
    2.51 -#include <linux/types.h>
    2.52 -#include <linux/stddef.h>
    2.53 -#include <linux/slab.h>
    2.54 -#include <linux/errno.h>
    2.55 -#include <linux/aio.h>
    2.56 -#include <linux/kernel.h>
    2.57 -#include <linux/spinlock.h>
    2.58 -#include <linux/sockios.h>
    2.59 -#include <linux/socket.h>
    2.60 -#include <linux/in.h>
    2.61 -#include <linux/mroute.h>
    2.62 -#include <linux/netdevice.h>
    2.63 -#include <linux/in_route.h>
    2.64 -#include <linux/route.h>
    2.65 -#include <linux/tcp.h>
    2.66 -#include <linux/skbuff.h>
    2.67 -#include <net/dst.h>
    2.68 -#include <net/sock.h>
    2.69 -#include <linux/gfp.h>
    2.70 -#include <linux/ip.h>
    2.71 -#include <linux/net.h>
    2.72 -#include <net/ip.h>
    2.73 -#include <net/icmp.h>
    2.74 -#include <net/udp.h>
    2.75 -#include <net/raw.h>
    2.76 -#include <net/snmp.h>
    2.77 -#include <net/inet_common.h>
    2.78 -#include <net/checksum.h>
    2.79 -#include <net/xfrm.h>
    2.80 -#include <linux/rtnetlink.h>
    2.81 -#include <linux/proc_fs.h>
    2.82 -#include <linux/seq_file.h>
    2.83 -#include <linux/netfilter.h>
    2.84 -#include <linux/netfilter_ipv4.h>
    2.85 -
    2.86 -struct hlist_head raw_v4_htable[RAWV4_HTABLE_SIZE];
    2.87 -rwlock_t raw_v4_lock = RW_LOCK_UNLOCKED;
    2.88 -
    2.89 -static void raw_v4_hash(struct sock *sk)
    2.90 -{
    2.91 -	struct hlist_head *head = &raw_v4_htable[inet_sk(sk)->num &
    2.92 -						 (RAWV4_HTABLE_SIZE - 1)];
    2.93 -
    2.94 -	write_lock_bh(&raw_v4_lock);
    2.95 -	sk_add_node(sk, head);
    2.96 -	sock_prot_inc_use(sk->sk_prot);
    2.97 -	write_unlock_bh(&raw_v4_lock);
    2.98 -}
    2.99 -
   2.100 -static void raw_v4_unhash(struct sock *sk)
   2.101 -{
   2.102 - 	write_lock_bh(&raw_v4_lock);
   2.103 -	if (sk_del_node_init(sk))
   2.104 -		sock_prot_dec_use(sk->sk_prot);
   2.105 -	write_unlock_bh(&raw_v4_lock);
   2.106 -}
   2.107 -
   2.108 -struct sock *__raw_v4_lookup(struct sock *sk, unsigned short num,
   2.109 -			     unsigned long raddr, unsigned long laddr,
   2.110 -			     int dif)
   2.111 -{
   2.112 -	struct hlist_node *node;
   2.113 -
   2.114 -	sk_for_each_from(sk, node) {
   2.115 -		struct inet_opt *inet = inet_sk(sk);
   2.116 -
   2.117 -		if (inet->num == num 					&&
   2.118 -		    !(inet->daddr && inet->daddr != raddr) 		&&
   2.119 -		    !(inet->rcv_saddr && inet->rcv_saddr != laddr)	&&
   2.120 -		    !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
   2.121 -			goto found; /* gotcha */
   2.122 -	}
   2.123 -	sk = NULL;
   2.124 -found:
   2.125 -	return sk;
   2.126 -}
   2.127 -
   2.128 -/*
   2.129 - *	0 - deliver
   2.130 - *	1 - block
   2.131 - */
   2.132 -static __inline__ int icmp_filter(struct sock *sk, struct sk_buff *skb)
   2.133 -{
   2.134 -	int type;
   2.135 -
   2.136 -	if (!pskb_may_pull(skb, sizeof(struct icmphdr)))
   2.137 -		return 1;
   2.138 -
   2.139 -	type = skb->h.icmph->type;
   2.140 -	if (type < 32) {
   2.141 -		__u32 data = raw4_sk(sk)->filter.data;
   2.142 -
   2.143 -		return ((1 << type) & data) != 0;
   2.144 -	}
   2.145 -
   2.146 -	/* Do not block unknown ICMP types */
   2.147 -	return 0;
   2.148 -}
   2.149 -
   2.150 -/* IP input processing comes here for RAW socket delivery.
   2.151 - * Caller owns SKB, so we must make clones.
   2.152 - *
   2.153 - * RFC 1122: SHOULD pass TOS value up to the transport layer.
   2.154 - * -> It does. And not only TOS, but all IP header.
   2.155 - */
   2.156 -void raw_v4_input(struct sk_buff *skb, struct iphdr *iph, int hash)
   2.157 -{
   2.158 -	struct sock *sk;
   2.159 -	struct hlist_head *head;
   2.160 -
   2.161 -	read_lock(&raw_v4_lock);
   2.162 -	head = &raw_v4_htable[hash];
   2.163 -	if (hlist_empty(head))
   2.164 -		goto out;
   2.165 -	sk = __raw_v4_lookup(__sk_head(head), iph->protocol,
   2.166 -			     iph->saddr, iph->daddr,
   2.167 -			     skb->dev->ifindex);
   2.168 -
   2.169 -	while (sk) {
   2.170 -		if (iph->protocol != IPPROTO_ICMP || !icmp_filter(sk, skb)) {
   2.171 -			struct sk_buff *clone = skb_clone(skb, GFP_ATOMIC);
   2.172 -
   2.173 -			/* Not releasing hash table! */
   2.174 -			if (clone)
   2.175 -				raw_rcv(sk, clone);
   2.176 -		}
   2.177 -		sk = __raw_v4_lookup(sk_next(sk), iph->protocol,
   2.178 -				     iph->saddr, iph->daddr,
   2.179 -				     skb->dev->ifindex);
   2.180 -	}
   2.181 -out:
   2.182 -	read_unlock(&raw_v4_lock);
   2.183 -}
   2.184 -
   2.185 -void raw_err (struct sock *sk, struct sk_buff *skb, u32 info)
   2.186 -{
   2.187 -	struct inet_opt *inet = inet_sk(sk);
   2.188 -	int type = skb->h.icmph->type;
   2.189 -	int code = skb->h.icmph->code;
   2.190 -	int err = 0;
   2.191 -	int harderr = 0;
   2.192 -
   2.193 -	/* Report error on raw socket, if:
   2.194 -	   1. User requested ip_recverr.
   2.195 -	   2. Socket is connected (otherwise the error indication
   2.196 -	      is useless without ip_recverr and error is hard.
   2.197 -	 */
   2.198 -	if (!inet->recverr && sk->sk_state != TCP_ESTABLISHED)
   2.199 -		return;
   2.200 -
   2.201 -	switch (type) {
   2.202 -	default:
   2.203 -	case ICMP_TIME_EXCEEDED:
   2.204 -		err = EHOSTUNREACH;
   2.205 -		break;
   2.206 -	case ICMP_SOURCE_QUENCH:
   2.207 -		return;
   2.208 -	case ICMP_PARAMETERPROB:
   2.209 -		err = EPROTO;
   2.210 -		harderr = 1;
   2.211 -		break;
   2.212 -	case ICMP_DEST_UNREACH:
   2.213 -		err = EHOSTUNREACH;
   2.214 -		if (code > NR_ICMP_UNREACH)
   2.215 -			break;
   2.216 -		err = icmp_err_convert[code].errno;
   2.217 -		harderr = icmp_err_convert[code].fatal;
   2.218 -		if (code == ICMP_FRAG_NEEDED) {
   2.219 -			harderr = inet->pmtudisc != IP_PMTUDISC_DONT;
   2.220 -			err = EMSGSIZE;
   2.221 -		}
   2.222 -	}
   2.223 -
   2.224 -	if (inet->recverr) {
   2.225 -		struct iphdr *iph = (struct iphdr*)skb->data;
   2.226 -		u8 *payload = skb->data + (iph->ihl << 2);
   2.227 -
   2.228 -		if (inet->hdrincl)
   2.229 -			payload = skb->data;
   2.230 -		ip_icmp_error(sk, skb, err, 0, info, payload);
   2.231 -	}
   2.232 -
   2.233 -	if (inet->recverr || harderr) {
   2.234 -		sk->sk_err = err;
   2.235 -		sk->sk_error_report(sk);
   2.236 -	}
   2.237 -}
   2.238 -
   2.239 -static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
   2.240 -{
   2.241 -	/* Charge it to the socket. */
   2.242 -	
   2.243 -	if (sock_queue_rcv_skb(sk, skb) < 0) {
   2.244 -		/* FIXME: increment a raw drops counter here */
   2.245 -		kfree_skb(skb);
   2.246 -		return NET_RX_DROP;
   2.247 -	}
   2.248 -
   2.249 -	return NET_RX_SUCCESS;
   2.250 -}
   2.251 -
   2.252 -int raw_rcv(struct sock *sk, struct sk_buff *skb)
   2.253 -{
   2.254 -	if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
   2.255 -		kfree_skb(skb);
   2.256 -		return NET_RX_DROP;
   2.257 -	}
   2.258 -
   2.259 -	skb_push(skb, skb->data - skb->nh.raw);
   2.260 -
   2.261 -	raw_rcv_skb(sk, skb);
   2.262 -	return 0;
   2.263 -}
   2.264 -
   2.265 -static int raw_send_hdrinc(struct sock *sk, void *from, int length,
   2.266 -			struct rtable *rt, 
   2.267 -			unsigned int flags)
   2.268 -{
   2.269 -	struct inet_opt *inet = inet_sk(sk);
   2.270 -	int hh_len;
   2.271 -	struct iphdr *iph;
   2.272 -	struct sk_buff *skb;
   2.273 -	int err;
   2.274 -
   2.275 -	if (length > rt->u.dst.dev->mtu) {
   2.276 -		ip_local_error(sk, EMSGSIZE, rt->rt_dst, inet->dport,
   2.277 -			       rt->u.dst.dev->mtu);
   2.278 -		return -EMSGSIZE;
   2.279 -	}
   2.280 -	if (flags&MSG_PROBE)
   2.281 -		goto out;
   2.282 -
   2.283 -	hh_len = LL_RESERVED_SPACE(rt->u.dst.dev);
   2.284 -
   2.285 -	skb = sock_alloc_send_skb(sk, length+hh_len+15,
   2.286 -				  flags&MSG_DONTWAIT, &err);
   2.287 -	if (skb == NULL)
   2.288 -		goto error; 
   2.289 -	skb_reserve(skb, hh_len);
   2.290 -
   2.291 -	skb->priority = sk->sk_priority;
   2.292 -	skb->dst = dst_clone(&rt->u.dst);
   2.293 -
   2.294 -	skb->nh.iph = iph = (struct iphdr *)skb_put(skb, length);
   2.295 -
   2.296 -	skb->ip_summed = CHECKSUM_NONE;
   2.297 -
   2.298 -	skb->h.raw = skb->nh.raw;
   2.299 -	err = memcpy_fromiovecend((void *)iph, from, 0, length);
   2.300 -	if (err)
   2.301 -		goto error_fault;
   2.302 -
   2.303 -	/* We don't modify invalid header */
   2.304 -	if (length >= sizeof(*iph) && iph->ihl * 4 <= length) {
   2.305 -		if (!iph->saddr)
   2.306 -			iph->saddr = rt->rt_src;
   2.307 -		iph->check   = 0;
   2.308 -		iph->tot_len = htons(length);
   2.309 -		if (!iph->id)
   2.310 -			ip_select_ident(iph, &rt->u.dst, NULL);
   2.311 -
   2.312 -		iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
   2.313 -	}
   2.314 -
   2.315 -	err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
   2.316 -		      dst_output);
   2.317 -	if (err > 0)
   2.318 -		err = inet->recverr ? net_xmit_errno(err) : 0;
   2.319 -	if (err)
   2.320 -		goto error;
   2.321 -out:
   2.322 -	return 0;
   2.323 -
   2.324 -error_fault:
   2.325 -	err = -EFAULT;
   2.326 -	kfree_skb(skb);
   2.327 -error:
   2.328 -	IP_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
   2.329 -	return err; 
   2.330 -}
   2.331 -
   2.332 -static void raw_probe_proto_opt(struct flowi *fl, struct msghdr *msg)
   2.333 -{
   2.334 -	struct iovec *iov;
   2.335 -	u8 __user *type = NULL;
   2.336 -	u8 __user *code = NULL;
   2.337 -	int probed = 0;
   2.338 -	int i;
   2.339 -
   2.340 -	if (!msg->msg_iov)
   2.341 -		return;
   2.342 -
   2.343 -	for (i = 0; i < msg->msg_iovlen; i++) {
   2.344 -		iov = &msg->msg_iov[i];
   2.345 -		if (!iov)
   2.346 -			continue;
   2.347 -
   2.348 -		switch (fl->proto) {
   2.349 -		case IPPROTO_ICMP:
   2.350 -			/* check if one-byte field is readable or not. */
   2.351 -			if (iov->iov_base && iov->iov_len < 1)
   2.352 -				break;
   2.353 -
   2.354 -			if (!type) {
   2.355 -				type = iov->iov_base;
   2.356 -				/* check if code field is readable or not. */
   2.357 -				if (iov->iov_len > 1)
   2.358 -					code = type + 1;
   2.359 -			} else if (!code)
   2.360 -				code = iov->iov_base;
   2.361 -
   2.362 -			if (type && code) {
   2.363 -				get_user(fl->fl_icmp_type, type);
   2.364 -				__get_user(fl->fl_icmp_code, code);
   2.365 -				probed = 1;
   2.366 -			}
   2.367 -			break;
   2.368 -		default:
   2.369 -			probed = 1;
   2.370 -			break;
   2.371 -		}
   2.372 -		if (probed)
   2.373 -			break;
   2.374 -	}
   2.375 -}
   2.376 -
   2.377 -static int raw_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
   2.378 -		       size_t len)
   2.379 -{
   2.380 -	struct inet_opt *inet = inet_sk(sk);
   2.381 -	struct ipcm_cookie ipc;
   2.382 -	struct rtable *rt = NULL;
   2.383 -	int free = 0;
   2.384 -	u32 daddr;
   2.385 -	u32 saddr;
   2.386 -	u8  tos;
   2.387 -	int err;
   2.388 -
   2.389 -	err = -EMSGSIZE;
   2.390 -	if (len < 0 || len > 0xFFFF)
   2.391 -		goto out;
   2.392 -
   2.393 -	/*
   2.394 -	 *	Check the flags.
   2.395 -	 */
   2.396 -
   2.397 -	err = -EOPNOTSUPP;
   2.398 -	if (msg->msg_flags & MSG_OOB)	/* Mirror BSD error message */
   2.399 -		goto out;               /* compatibility */
   2.400 -			 
   2.401 -	/*
   2.402 -	 *	Get and verify the address. 
   2.403 -	 */
   2.404 -
   2.405 -	if (msg->msg_namelen) {
   2.406 -		struct sockaddr_in *usin = (struct sockaddr_in*)msg->msg_name;
   2.407 -		err = -EINVAL;
   2.408 -		if (msg->msg_namelen < sizeof(*usin))
   2.409 -			goto out;
   2.410 -		if (usin->sin_family != AF_INET) {
   2.411 -			static int complained;
   2.412 -			if (!complained++)
   2.413 -				printk(KERN_INFO "%s forgot to set AF_INET in "
   2.414 -						 "raw sendmsg. Fix it!\n",
   2.415 -						 current->comm);
   2.416 -			err = -EAFNOSUPPORT;
   2.417 -			if (usin->sin_family)
   2.418 -				goto out;
   2.419 -		}
   2.420 -		daddr = usin->sin_addr.s_addr;
   2.421 -		/* ANK: I did not forget to get protocol from port field.
   2.422 -		 * I just do not know, who uses this weirdness.
   2.423 -		 * IP_HDRINCL is much more convenient.
   2.424 -		 */
   2.425 -	} else {
   2.426 -		err = -EDESTADDRREQ;
   2.427 -		if (sk->sk_state != TCP_ESTABLISHED) 
   2.428 -			goto out;
   2.429 -		daddr = inet->daddr;
   2.430 -	}
   2.431 -
   2.432 -	ipc.addr = inet->saddr;
   2.433 -	ipc.opt = NULL;
   2.434 -	ipc.oif = sk->sk_bound_dev_if;
   2.435 -
   2.436 -	if (msg->msg_controllen) {
   2.437 -		err = ip_cmsg_send(msg, &ipc);
   2.438 -		if (err)
   2.439 -			goto out;
   2.440 -		if (ipc.opt)
   2.441 -			free = 1;
   2.442 -	}
   2.443 -
   2.444 -	saddr = ipc.addr;
   2.445 -	ipc.addr = daddr;
   2.446 -
   2.447 -	if (!ipc.opt)
   2.448 -		ipc.opt = inet->opt;
   2.449 -
   2.450 -	if (ipc.opt) {
   2.451 -		err = -EINVAL;
   2.452 -		/* Linux does not mangle headers on raw sockets,
   2.453 -		 * so that IP options + IP_HDRINCL is non-sense.
   2.454 -		 */
   2.455 -		if (inet->hdrincl)
   2.456 -			goto done;
   2.457 -		if (ipc.opt->srr) {
   2.458 -			if (!daddr)
   2.459 -				goto done;
   2.460 -			daddr = ipc.opt->faddr;
   2.461 -		}
   2.462 -	}
   2.463 -	tos = RT_TOS(inet->tos) | sk->sk_localroute;
   2.464 -	if (msg->msg_flags & MSG_DONTROUTE)
   2.465 -		tos |= RTO_ONLINK;
   2.466 -
   2.467 -	if (MULTICAST(daddr)) {
   2.468 -		if (!ipc.oif)
   2.469 -			ipc.oif = inet->mc_index;
   2.470 -		if (!saddr)
   2.471 -			saddr = inet->mc_addr;
   2.472 -	}
   2.473 -
   2.474 -	{
   2.475 -		struct flowi fl = { .oif = ipc.oif,
   2.476 -				    .nl_u = { .ip4_u =
   2.477 -					      { .daddr = daddr,
   2.478 -						.saddr = saddr,
   2.479 -						.tos = tos } },
   2.480 -				    .proto = inet->hdrincl ? IPPROTO_RAW :
   2.481 -					    		     sk->sk_protocol,
   2.482 -				  };
   2.483 -		if (!inet->hdrincl)
   2.484 -			raw_probe_proto_opt(&fl, msg);
   2.485 -
   2.486 -		err = ip_route_output_flow(&rt, &fl, sk, !(msg->msg_flags&MSG_DONTWAIT));
   2.487 -	}
   2.488 -	if (err)
   2.489 -		goto done;
   2.490 -
   2.491 -	err = -EACCES;
   2.492 -	if (rt->rt_flags & RTCF_BROADCAST && !sock_flag(sk, SOCK_BROADCAST))
   2.493 -		goto done;
   2.494 -
   2.495 -	if (msg->msg_flags & MSG_CONFIRM)
   2.496 -		goto do_confirm;
   2.497 -back_from_confirm:
   2.498 -
   2.499 -	if (inet->hdrincl)
   2.500 -		err = raw_send_hdrinc(sk, msg->msg_iov, len, 
   2.501 -					rt, msg->msg_flags);
   2.502 -	
   2.503 -	 else {
   2.504 -		if (!ipc.addr)
   2.505 -			ipc.addr = rt->rt_dst;
   2.506 -		lock_sock(sk);
   2.507 -		err = ip_append_data(sk, ip_generic_getfrag, msg->msg_iov, len, 0,
   2.508 -					&ipc, rt, msg->msg_flags);
   2.509 -		if (err)
   2.510 -			ip_flush_pending_frames(sk);
   2.511 -		else if (!(msg->msg_flags & MSG_MORE))
   2.512 -			err = ip_push_pending_frames(sk);
   2.513 -		release_sock(sk);
   2.514 -	}
   2.515 -done:
   2.516 -	if (free)
   2.517 -		kfree(ipc.opt);
   2.518 -	ip_rt_put(rt);
   2.519 -
   2.520 -out:	return err < 0 ? err : len;
   2.521 -
   2.522 -do_confirm:
   2.523 -	dst_confirm(&rt->u.dst);
   2.524 -	if (!(msg->msg_flags & MSG_PROBE) || len)
   2.525 -		goto back_from_confirm;
   2.526 -	err = 0;
   2.527 -	goto done;
   2.528 -}
   2.529 -
   2.530 -static void raw_close(struct sock *sk, long timeout)
   2.531 -{
   2.532 -        /*
   2.533 -	 * Raw sockets may have direct kernel refereneces. Kill them.
   2.534 -	 */
   2.535 -	ip_ra_control(sk, 0, NULL);
   2.536 -
   2.537 -	sk_common_release(sk);
   2.538 -}
   2.539 -
   2.540 -/* This gets rid of all the nasties in af_inet. -DaveM */
   2.541 -static int raw_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
   2.542 -{
   2.543 -	struct inet_opt *inet = inet_sk(sk);
   2.544 -	struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
   2.545 -	int ret = -EINVAL;
   2.546 -	int chk_addr_ret;
   2.547 -
   2.548 -	if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
   2.549 -		goto out;
   2.550 -	chk_addr_ret = inet_addr_type(addr->sin_addr.s_addr);
   2.551 -	ret = -EADDRNOTAVAIL;
   2.552 -	if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
   2.553 -	    chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
   2.554 -		goto out;
   2.555 -	inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
   2.556 -	if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
   2.557 -		inet->saddr = 0;  /* Use device */
   2.558 -	sk_dst_reset(sk);
   2.559 -	ret = 0;
   2.560 -out:	return ret;
   2.561 -}
   2.562 -
   2.563 -/*
   2.564 - *	This should be easy, if there is something there
   2.565 - *	we return it, otherwise we block.
   2.566 - */
   2.567 -
   2.568 -int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
   2.569 -		size_t len, int noblock, int flags, int *addr_len)
   2.570 -{
   2.571 -	struct inet_opt *inet = inet_sk(sk);
   2.572 -	size_t copied = 0;
   2.573 -	int err = -EOPNOTSUPP;
   2.574 -	struct sockaddr_in *sin = (struct sockaddr_in *)msg->msg_name;
   2.575 -	struct sk_buff *skb;
   2.576 -
   2.577 -	if (flags & MSG_OOB)
   2.578 -		goto out;
   2.579 -
   2.580 -	if (addr_len)
   2.581 -		*addr_len = sizeof(*sin);
   2.582 -
   2.583 -	if (flags & MSG_ERRQUEUE) {
   2.584 -		err = ip_recv_error(sk, msg, len);
   2.585 -		goto out;
   2.586 -	}
   2.587 -
   2.588 -	skb = skb_recv_datagram(sk, flags, noblock, &err);
   2.589 -	if (!skb)
   2.590 -		goto out;
   2.591 -
   2.592 -	copied = skb->len;
   2.593 -	if (len < copied) {
   2.594 -		msg->msg_flags |= MSG_TRUNC;
   2.595 -		copied = len;
   2.596 -	}
   2.597 -
   2.598 -	err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
   2.599 -	if (err)
   2.600 -		goto done;
   2.601 -
   2.602 -	sock_recv_timestamp(msg, sk, skb);
   2.603 -
   2.604 -	/* Copy the address. */
   2.605 -	if (sin) {
   2.606 -		sin->sin_family = AF_INET;
   2.607 -		sin->sin_addr.s_addr = skb->nh.iph->saddr;
   2.608 -		memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
   2.609 -	}
   2.610 -	if (inet->cmsg_flags)
   2.611 -		ip_cmsg_recv(msg, skb);
   2.612 -	if (flags & MSG_TRUNC)
   2.613 -		copied = skb->len;
   2.614 -done:
   2.615 -	skb_free_datagram(sk, skb);
   2.616 -out:	return err ? err : copied;
   2.617 -}
   2.618 -
   2.619 -static int raw_init(struct sock *sk)
   2.620 -{
   2.621 -	struct raw_opt *tp = raw4_sk(sk);
   2.622 -	if (inet_sk(sk)->num == IPPROTO_ICMP)
   2.623 -		memset(&tp->filter, 0, sizeof(tp->filter));
   2.624 -	return 0;
   2.625 -}
   2.626 -
   2.627 -static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
   2.628 -{
   2.629 -	if (optlen > sizeof(struct icmp_filter))
   2.630 -		optlen = sizeof(struct icmp_filter);
   2.631 -	if (copy_from_user(&raw4_sk(sk)->filter, optval, optlen))
   2.632 -		return -EFAULT;
   2.633 -	return 0;
   2.634 -}
   2.635 -
   2.636 -static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
   2.637 -{
   2.638 -	int len, ret = -EFAULT;
   2.639 -
   2.640 -	if (get_user(len, optlen))
   2.641 -		goto out;
   2.642 -	ret = -EINVAL;
   2.643 -	if (len < 0)
   2.644 -		goto out;
   2.645 -	if (len > sizeof(struct icmp_filter))
   2.646 -		len = sizeof(struct icmp_filter);
   2.647 -	ret = -EFAULT;
   2.648 -	if (put_user(len, optlen) ||
   2.649 -	    copy_to_user(optval, &raw4_sk(sk)->filter, len))
   2.650 -		goto out;
   2.651 -	ret = 0;
   2.652 -out:	return ret;
   2.653 -}
   2.654 -
   2.655 -static int raw_setsockopt(struct sock *sk, int level, int optname, 
   2.656 -			  char __user *optval, int optlen)
   2.657 -{
   2.658 -	if (level != SOL_RAW)
   2.659 -		return ip_setsockopt(sk, level, optname, optval, optlen);
   2.660 -
   2.661 -	if (optname == ICMP_FILTER) {
   2.662 -		if (inet_sk(sk)->num != IPPROTO_ICMP)
   2.663 -			return -EOPNOTSUPP;
   2.664 -		else
   2.665 -			return raw_seticmpfilter(sk, optval, optlen);
   2.666 -	}
   2.667 -	return -ENOPROTOOPT;
   2.668 -}
   2.669 -
   2.670 -static int raw_getsockopt(struct sock *sk, int level, int optname, 
   2.671 -			  char __user *optval, int __user *optlen)
   2.672 -{
   2.673 -	if (level != SOL_RAW)
   2.674 -		return ip_getsockopt(sk, level, optname, optval, optlen);
   2.675 -
   2.676 -	if (optname == ICMP_FILTER) {
   2.677 -		if (inet_sk(sk)->num != IPPROTO_ICMP)
   2.678 -			return -EOPNOTSUPP;
   2.679 -		else
   2.680 -			return raw_geticmpfilter(sk, optval, optlen);
   2.681 -	}
   2.682 -	return -ENOPROTOOPT;
   2.683 -}
   2.684 -
   2.685 -static int raw_ioctl(struct sock *sk, int cmd, unsigned long arg)
   2.686 -{
   2.687 -	switch (cmd) {
   2.688 -		case SIOCOUTQ: {
   2.689 -			int amount = atomic_read(&sk->sk_wmem_alloc);
   2.690 -			return put_user(amount, (int __user *)arg);
   2.691 -		}
   2.692 -		case SIOCINQ: {
   2.693 -			struct sk_buff *skb;
   2.694 -			int amount = 0;
   2.695 -
   2.696 -			spin_lock_irq(&sk->sk_receive_queue.lock);
   2.697 -			skb = skb_peek(&sk->sk_receive_queue);
   2.698 -			if (skb != NULL)
   2.699 -				amount = skb->len;
   2.700 -			spin_unlock_irq(&sk->sk_receive_queue.lock);
   2.701 -			return put_user(amount, (int __user *)arg);
   2.702 -		}
   2.703 -
   2.704 -		default:
   2.705 -#ifdef CONFIG_IP_MROUTE
   2.706 -			return ipmr_ioctl(sk, cmd, (void __user *)arg);
   2.707 -#else
   2.708 -			return -ENOIOCTLCMD;
   2.709 -#endif
   2.710 -	}
   2.711 -}
   2.712 -
   2.713 -struct proto raw_prot = {
   2.714 -	.name =		"RAW",
   2.715 -	.owner =	THIS_MODULE,
   2.716 -	.close =	raw_close,
   2.717 -	.connect =	ip4_datagram_connect,
   2.718 -	.disconnect =	udp_disconnect,
   2.719 -	.ioctl =	raw_ioctl,
   2.720 -	.init =		raw_init,
   2.721 -	.setsockopt =	raw_setsockopt,
   2.722 -	.getsockopt =	raw_getsockopt,
   2.723 -	.sendmsg =	raw_sendmsg,
   2.724 -	.recvmsg =	raw_recvmsg,
   2.725 -	.bind =		raw_bind,
   2.726 -	.backlog_rcv =	raw_rcv_skb,
   2.727 -	.hash =		raw_v4_hash,
   2.728 -	.unhash =	raw_v4_unhash,
   2.729 -	.slab_obj_size = sizeof(struct raw_sock),
   2.730 -};
   2.731 -
   2.732 -#ifdef CONFIG_PROC_FS
   2.733 -struct raw_iter_state {
   2.734 -	int bucket;
   2.735 -};
   2.736 -
   2.737 -#define raw_seq_private(seq) ((struct raw_iter_state *)(seq)->private)
   2.738 -
   2.739 -static struct sock *raw_get_first(struct seq_file *seq)
   2.740 -{
   2.741 -	struct sock *sk;
   2.742 -	struct raw_iter_state* state = raw_seq_private(seq);
   2.743 -
   2.744 -	for (state->bucket = 0; state->bucket < RAWV4_HTABLE_SIZE; ++state->bucket) {
   2.745 -		struct hlist_node *node;
   2.746 -
   2.747 -		sk_for_each(sk, node, &raw_v4_htable[state->bucket])
   2.748 -			if (sk->sk_family == PF_INET)
   2.749 -				goto found;
   2.750 -	}
   2.751 -	sk = NULL;
   2.752 -found:
   2.753 -	return sk;
   2.754 -}
   2.755 -
   2.756 -static struct sock *raw_get_next(struct seq_file *seq, struct sock *sk)
   2.757 -{
   2.758 -	struct raw_iter_state* state = raw_seq_private(seq);
   2.759 -
   2.760 -	do {
   2.761 -		sk = sk_next(sk);
   2.762 -try_again:
   2.763 -		;
   2.764 -	} while (sk && sk->sk_family != PF_INET);
   2.765 -
   2.766 -	if (!sk && ++state->bucket < RAWV4_HTABLE_SIZE) {
   2.767 -		sk = sk_head(&raw_v4_htable[state->bucket]);
   2.768 -		goto try_again;
   2.769 -	}
   2.770 -	return sk;
   2.771 -}
   2.772 -
   2.773 -static struct sock *raw_get_idx(struct seq_file *seq, loff_t pos)
   2.774 -{
   2.775 -	struct sock *sk = raw_get_first(seq);
   2.776 -
   2.777 -	if (sk)
   2.778 -		while (pos && (sk = raw_get_next(seq, sk)) != NULL)
   2.779 -			--pos;
   2.780 -	return pos ? NULL : sk;
   2.781 -}
   2.782 -
   2.783 -static void *raw_seq_start(struct seq_file *seq, loff_t *pos)
   2.784 -{
   2.785 -	read_lock(&raw_v4_lock);
   2.786 -	return *pos ? raw_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
   2.787 -}
   2.788 -
   2.789 -static void *raw_seq_next(struct seq_file *seq, void *v, loff_t *pos)
   2.790 -{
   2.791 -	struct sock *sk;
   2.792 -
   2.793 -	if (v == SEQ_START_TOKEN)
   2.794 -		sk = raw_get_first(seq);
   2.795 -	else
   2.796 -		sk = raw_get_next(seq, v);
   2.797 -	++*pos;
   2.798 -	return sk;
   2.799 -}
   2.800 -
   2.801 -static void raw_seq_stop(struct seq_file *seq, void *v)
   2.802 -{
   2.803 -	read_unlock(&raw_v4_lock);
   2.804 -}
   2.805 -
   2.806 -static __inline__ char *get_raw_sock(struct sock *sp, char *tmpbuf, int i)
   2.807 -{
   2.808 -	struct inet_opt *inet = inet_sk(sp);
   2.809 -	unsigned int dest = inet->daddr,
   2.810 -		     src = inet->rcv_saddr;
   2.811 -	__u16 destp = 0,
   2.812 -	      srcp  = inet->num;
   2.813 -
   2.814 -	sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
   2.815 -		" %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p",
   2.816 -		i, src, srcp, dest, destp, sp->sk_state, 
   2.817 -		atomic_read(&sp->sk_wmem_alloc),
   2.818 -		atomic_read(&sp->sk_rmem_alloc),
   2.819 -		0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
   2.820 -		atomic_read(&sp->sk_refcnt), sp);
   2.821 -	return tmpbuf;
   2.822 -}
   2.823 -
   2.824 -static int raw_seq_show(struct seq_file *seq, void *v)
   2.825 -{
   2.826 -	char tmpbuf[129];
   2.827 -
   2.828 -	if (v == SEQ_START_TOKEN)
   2.829 -		seq_printf(seq, "%-127s\n",
   2.830 -			       "  sl  local_address rem_address   st tx_queue "
   2.831 -			       "rx_queue tr tm->when retrnsmt   uid  timeout "
   2.832 -			       "inode");
   2.833 -	else {
   2.834 -		struct raw_iter_state *state = raw_seq_private(seq);
   2.835 -
   2.836 -		seq_printf(seq, "%-127s\n",
   2.837 -			   get_raw_sock(v, tmpbuf, state->bucket));
   2.838 -	}
   2.839 -	return 0;
   2.840 -}
   2.841 -
   2.842 -static struct seq_operations raw_seq_ops = {
   2.843 -	.start = raw_seq_start,
   2.844 -	.next  = raw_seq_next,
   2.845 -	.stop  = raw_seq_stop,
   2.846 -	.show  = raw_seq_show,
   2.847 -};
   2.848 -
   2.849 -static int raw_seq_open(struct inode *inode, struct file *file)
   2.850 -{
   2.851 -	struct seq_file *seq;
   2.852 -	int rc = -ENOMEM;
   2.853 -	struct raw_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL);
   2.854 -
   2.855 -	if (!s)
   2.856 -		goto out;
   2.857 -	rc = seq_open(file, &raw_seq_ops);
   2.858 -	if (rc)
   2.859 -		goto out_kfree;
   2.860 -
   2.861 -	seq = file->private_data;
   2.862 -	seq->private = s;
   2.863 -	memset(s, 0, sizeof(*s));
   2.864 -out:
   2.865 -	return rc;
   2.866 -out_kfree:
   2.867 -	kfree(s);
   2.868 -	goto out;
   2.869 -}
   2.870 -
   2.871 -static struct file_operations raw_seq_fops = {
   2.872 -	.owner	 = THIS_MODULE,
   2.873 -	.open	 = raw_seq_open,
   2.874 -	.read	 = seq_read,
   2.875 -	.llseek	 = seq_lseek,
   2.876 -	.release = seq_release_private,
   2.877 -};
   2.878 -
   2.879 -int __init raw_proc_init(void)
   2.880 -{
   2.881 -	if (!proc_net_fops_create("raw", S_IRUGO, &raw_seq_fops))
   2.882 -		return -ENOMEM;
   2.883 -	return 0;
   2.884 -}
   2.885 -
   2.886 -void __init raw_proc_exit(void)
   2.887 -{
   2.888 -	proc_net_remove("raw");
   2.889 -}
   2.890 -#endif /* CONFIG_PROC_FS */