-+EXPORT_SYMBOL_GPL(unregister_pernet_device);
-diff -Nurb linux-2.6.22-594/net/ipv4/af_inet.c.orig linux-2.6.22-595/net/ipv4/af_inet.c.orig
---- linux-2.6.22-594/net/ipv4/af_inet.c.orig 2008-03-20 00:05:18.000000000 -0400
-+++ linux-2.6.22-595/net/ipv4/af_inet.c.orig 1969-12-31 19:00:00.000000000 -0500
-@@ -1,1522 +0,0 @@
--/*
-- * INET An implementation of the TCP/IP protocol suite for the LINUX
-- * operating system. INET is implemented using the BSD Socket
-- * interface as the means of communication with the user level.
-- *
-- * PF_INET protocol family socket handler.
-- *
-- * Version: $Id: af_inet.c,v 1.137 2002/02/01 22:01:03 davem Exp $
-- *
-- * Authors: Ross Biro
-- * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
-- * Florian La Roche, <flla@stud.uni-sb.de>
-- * Alan Cox, <A.Cox@swansea.ac.uk>
-- *
-- * Changes (see also sock.c)
-- *
-- * piggy,
-- * Karl Knutson : Socket protocol table
-- * A.N.Kuznetsov : Socket death error in accept().
-- * John Richardson : Fix non blocking error in connect()
-- * so sockets that fail to connect
-- * don't return -EINPROGRESS.
-- * Alan Cox : Asynchronous I/O support
-- * Alan Cox : Keep correct socket pointer on sock
-- * structures
-- * when accept() ed
-- * Alan Cox : Semantics of SO_LINGER aren't state
-- * moved to close when you look carefully.
-- * With this fixed and the accept bug fixed
-- * some RPC stuff seems happier.
-- * Niibe Yutaka : 4.4BSD style write async I/O
-- * Alan Cox,
-- * Tony Gale : Fixed reuse semantics.
-- * Alan Cox : bind() shouldn't abort existing but dead
-- * sockets. Stops FTP netin:.. I hope.
-- * Alan Cox : bind() works correctly for RAW sockets.
-- * Note that FreeBSD at least was broken
-- * in this respect so be careful with
-- * compatibility tests...
-- * Alan Cox : routing cache support
-- * Alan Cox : memzero the socket structure for
-- * compactness.
-- * Matt Day : nonblock connect error handler
-- * Alan Cox : Allow large numbers of pending sockets
-- * (eg for big web sites), but only if
-- * specifically application requested.
-- * Alan Cox : New buffering throughout IP. Used
-- * dumbly.
-- * Alan Cox : New buffering now used smartly.
-- * Alan Cox : BSD rather than common sense
-- * interpretation of listen.
-- * Germano Caronni : Assorted small races.
-- * Alan Cox : sendmsg/recvmsg basic support.
-- * Alan Cox : Only sendmsg/recvmsg now supported.
-- * Alan Cox : Locked down bind (see security list).
-- * Alan Cox : Loosened bind a little.
-- * Mike McLagan : ADD/DEL DLCI Ioctls
-- * Willy Konynenberg : Transparent proxying support.
-- * David S. Miller : New socket lookup architecture.
-- * Some other random speedups.
-- * Cyrus Durgin : Cleaned up file for kmod hacks.
-- * Andi Kleen : Fix inet_stream_connect TCP race.
-- *
-- * This program is free software; you can redistribute it and/or
-- * modify it under the terms of the GNU General Public License
-- * as published by the Free Software Foundation; either version
-- * 2 of the License, or (at your option) any later version.
-- */
--
--#include <linux/err.h>
--#include <linux/errno.h>
--#include <linux/types.h>
--#include <linux/socket.h>
--#include <linux/in.h>
--#include <linux/kernel.h>
--#include <linux/module.h>
--#include <linux/sched.h>
--#include <linux/timer.h>
--#include <linux/string.h>
--#include <linux/sockios.h>
--#include <linux/net.h>
--#include <linux/capability.h>
--#include <linux/fcntl.h>
--#include <linux/mm.h>
--#include <linux/interrupt.h>
--#include <linux/stat.h>
--#include <linux/init.h>
--#include <linux/poll.h>
--#include <linux/netfilter_ipv4.h>
--#include <linux/random.h>
--
--#include <asm/uaccess.h>
--#include <asm/system.h>
--
--#include <linux/inet.h>
--#include <linux/igmp.h>
--#include <linux/inetdevice.h>
--#include <linux/netdevice.h>
--#include <net/ip.h>
--#include <net/protocol.h>
--#include <net/arp.h>
--#include <net/route.h>
--#include <net/ip_fib.h>
--#include <net/inet_connection_sock.h>
--#include <net/tcp.h>
--#include <net/udp.h>
--#include <net/udplite.h>
--#include <linux/skbuff.h>
--#include <net/sock.h>
--#include <net/raw.h>
--#include <net/icmp.h>
--#include <net/ipip.h>
--#include <net/inet_common.h>
--#include <net/xfrm.h>
--#ifdef CONFIG_IP_MROUTE
--#include <linux/mroute.h>
--#endif
--#include <linux/vs_limit.h>
--
--DEFINE_SNMP_STAT(struct linux_mib, net_statistics) __read_mostly;
--
--extern void ip_mc_drop_socket(struct sock *sk);
--
--/* The inetsw table contains everything that inet_create needs to
-- * build a new socket.
-- */
--static struct list_head inetsw[SOCK_MAX];
--static DEFINE_SPINLOCK(inetsw_lock);
--
--/* New destruction routine */
--
--void inet_sock_destruct(struct sock *sk)
--{
-- struct inet_sock *inet = inet_sk(sk);
--
-- __skb_queue_purge(&sk->sk_receive_queue);
-- __skb_queue_purge(&sk->sk_error_queue);
--
-- if (sk->sk_type == SOCK_STREAM && sk->sk_state != TCP_CLOSE) {
-- printk("Attempt to release TCP socket in state %d %p\n",
-- sk->sk_state, sk);
-- return;
-- }
-- if (!sock_flag(sk, SOCK_DEAD)) {
-- printk("Attempt to release alive inet socket %p\n", sk);
-- return;
-- }
--
-- BUG_TRAP(!atomic_read(&sk->sk_rmem_alloc));
-- BUG_TRAP(!atomic_read(&sk->sk_wmem_alloc));
-- BUG_TRAP(!sk->sk_wmem_queued);
-- BUG_TRAP(!sk->sk_forward_alloc);
--
-- kfree(inet->opt);
-- dst_release(sk->sk_dst_cache);
-- sk_refcnt_debug_dec(sk);
--}
--
--/*
-- * The routines beyond this point handle the behaviour of an AF_INET
-- * socket object. Mostly it punts to the subprotocols of IP to do
-- * the work.
-- */
--
--/*
-- * Automatically bind an unbound socket.
-- */
--
--static int inet_autobind(struct sock *sk)
--{
-- struct inet_sock *inet;
-- /* We may need to bind the socket. */
-- lock_sock(sk);
-- inet = inet_sk(sk);
-- if (!inet->num) {
-- if (sk->sk_prot->get_port(sk, 0)) {
-- release_sock(sk);
-- return -EAGAIN;
-- }
-- inet->sport = htons(inet->num);
-- sk->sk_xid = vx_current_xid();
-- sk->sk_nid = nx_current_nid();
-- }
-- release_sock(sk);
-- return 0;
--}
--
--/*
-- * Move a socket into listening state.
-- */
--int inet_listen(struct socket *sock, int backlog)
--{
-- struct sock *sk = sock->sk;
-- unsigned char old_state;
-- int err;
--
-- lock_sock(sk);
--
-- err = -EINVAL;
-- if (sock->state != SS_UNCONNECTED || sock->type != SOCK_STREAM)
-- goto out;
--
-- old_state = sk->sk_state;
-- if (!((1 << old_state) & (TCPF_CLOSE | TCPF_LISTEN)))
-- goto out;
--
-- /* Really, if the socket is already in listen state
-- * we can only allow the backlog to be adjusted.
-- */
-- if (old_state != TCP_LISTEN) {
-- err = inet_csk_listen_start(sk, backlog);
-- if (err)
-- goto out;
-- }
-- sk->sk_max_ack_backlog = backlog;
-- err = 0;
--
--out:
-- release_sock(sk);
-- return err;
--}
--
--u32 inet_ehash_secret __read_mostly;
--EXPORT_SYMBOL(inet_ehash_secret);
--
--/*
-- * inet_ehash_secret must be set exactly once
-- * Instead of using a dedicated spinlock, we (ab)use inetsw_lock
-- */
--void build_ehash_secret(void)
--{
-- u32 rnd;
-- do {
-- get_random_bytes(&rnd, sizeof(rnd));
-- } while (rnd == 0);
-- spin_lock_bh(&inetsw_lock);
-- if (!inet_ehash_secret)
-- inet_ehash_secret = rnd;
-- spin_unlock_bh(&inetsw_lock);
--}
--EXPORT_SYMBOL(build_ehash_secret);
--
--/*
-- * Create an inet socket.
-- */
--
--static int inet_create(struct socket *sock, int protocol)
--{
-- struct sock *sk;
-- struct list_head *p;
-- struct inet_protosw *answer;
-- struct inet_sock *inet;
-- struct proto *answer_prot;
-- unsigned char answer_flags;
-- char answer_no_check;
-- int try_loading_module = 0;
-- int err;
--
-- if (sock->type != SOCK_RAW &&
-- sock->type != SOCK_DGRAM &&
-- !inet_ehash_secret)
-- build_ehash_secret();
--
-- sock->state = SS_UNCONNECTED;
--
-- /* Look for the requested type/protocol pair. */
-- answer = NULL;
--lookup_protocol:
-- err = -ESOCKTNOSUPPORT;
-- rcu_read_lock();
-- list_for_each_rcu(p, &inetsw[sock->type]) {
-- answer = list_entry(p, struct inet_protosw, list);
--
-- /* Check the non-wild match. */
-- if (protocol == answer->protocol) {
-- if (protocol != IPPROTO_IP)
-- break;
-- } else {
-- /* Check for the two wild cases. */
-- if (IPPROTO_IP == protocol) {
-- protocol = answer->protocol;
-- break;
-- }
-- if (IPPROTO_IP == answer->protocol)
-- break;
-- }
-- err = -EPROTONOSUPPORT;
-- answer = NULL;
-- }
--
-- if (unlikely(answer == NULL)) {
-- if (try_loading_module < 2) {
-- rcu_read_unlock();
-- /*
-- * Be more specific, e.g. net-pf-2-proto-132-type-1
-- * (net-pf-PF_INET-proto-IPPROTO_SCTP-type-SOCK_STREAM)
-- */
-- if (++try_loading_module == 1)
-- request_module("net-pf-%d-proto-%d-type-%d",
-- PF_INET, protocol, sock->type);
-- /*
-- * Fall back to generic, e.g. net-pf-2-proto-132
-- * (net-pf-PF_INET-proto-IPPROTO_SCTP)
-- */
-- else
-- request_module("net-pf-%d-proto-%d",
-- PF_INET, protocol);
-- goto lookup_protocol;
-- } else
-- goto out_rcu_unlock;
-- }
--
-- err = -EPERM;
-- if ((protocol == IPPROTO_ICMP) &&
-- nx_capable(answer->capability, NXC_RAW_ICMP))
-- goto override;
-- if (sock->type == SOCK_RAW &&
-- nx_capable(answer->capability, NXC_RAW_SOCKET))
-- goto override;
-- if (answer->capability > 0 && !capable(answer->capability))
-- goto out_rcu_unlock;
--override:
-- sock->ops = answer->ops;
-- answer_prot = answer->prot;
-- answer_no_check = answer->no_check;
-- answer_flags = answer->flags;
-- rcu_read_unlock();
--
-- BUG_TRAP(answer_prot->slab != NULL);
--
-- err = -ENOBUFS;
-- sk = sk_alloc(PF_INET, GFP_KERNEL, answer_prot, 1);
-- if (sk == NULL)
-- goto out;
--
-- err = 0;
-- sk->sk_no_check = answer_no_check;
-- if (INET_PROTOSW_REUSE & answer_flags)
-- sk->sk_reuse = 1;
--
-- inet = inet_sk(sk);
-- inet->is_icsk = (INET_PROTOSW_ICSK & answer_flags) != 0;
--
-- if (SOCK_RAW == sock->type) {
-- inet->num = protocol;
-- if (IPPROTO_RAW == protocol)
-- inet->hdrincl = 1;
-- }
--
-- if (ipv4_config.no_pmtu_disc)
-- inet->pmtudisc = IP_PMTUDISC_DONT;
-- else
-- inet->pmtudisc = IP_PMTUDISC_WANT;
--
-- inet->id = 0;
--
-- sock_init_data(sock, sk);
--
-- sk->sk_destruct = inet_sock_destruct;
-- sk->sk_family = PF_INET;
-- sk->sk_protocol = protocol;
-- sk->sk_backlog_rcv = sk->sk_prot->backlog_rcv;
--
-- inet->uc_ttl = -1;
-- inet->mc_loop = 1;
-- inet->mc_ttl = 1;
-- inet->mc_index = 0;
-- inet->mc_list = NULL;
--
-- sk_refcnt_debug_inc(sk);
--
-- if (inet->num) {
-- /* It assumes that any protocol which allows
-- * the user to assign a number at socket
-- * creation time automatically
-- * shares.
-- */
-- inet->sport = htons(inet->num);
-- /* Add to protocol hash chains. */
-- sk->sk_prot->hash(sk);
-- }
--
-- if (sk->sk_prot->init) {
-- err = sk->sk_prot->init(sk);
-- if (err)
-- sk_common_release(sk);
-- }
--out:
-- return err;
--out_rcu_unlock:
-- rcu_read_unlock();
-- goto out;
--}
--
--
--/*
-- * The peer socket should always be NULL (or else). When we call this
-- * function we are destroying the object and from then on nobody
-- * should refer to it.
-- */
--int inet_release(struct socket *sock)
--{
-- struct sock *sk = sock->sk;
--
-- if (sk) {
-- long timeout;
--
-- /* Applications forget to leave groups before exiting */
-- ip_mc_drop_socket(sk);
--
-- /* If linger is set, we don't return until the close
-- * is complete. Otherwise we return immediately. The
-- * actually closing is done the same either way.
-- *
-- * If the close is due to the process exiting, we never
-- * linger..
-- */
-- timeout = 0;
-- if (sock_flag(sk, SOCK_LINGER) &&
-- !(current->flags & PF_EXITING))
-- timeout = sk->sk_lingertime;
-- sock->sk = NULL;
-- sk->sk_prot->close(sk, timeout);
-- }
-- return 0;
--}
--
--/* It is off by default, see below. */
--int sysctl_ip_nonlocal_bind __read_mostly;
--
--int inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
--{
-- struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
-- struct sock *sk = sock->sk;
-- struct inet_sock *inet = inet_sk(sk);
-- struct nx_v4_sock_addr nsa;
-- unsigned short snum;
-- int chk_addr_ret;
-- int err;
--
-- /* If the socket has its own bind function then use it. (RAW) */
-- if (sk->sk_prot->bind) {
-- err = sk->sk_prot->bind(sk, uaddr, addr_len);
-- goto out;
-- }
-- err = -EINVAL;
-- if (addr_len < sizeof(struct sockaddr_in))
-- goto out;
--
-- err = v4_map_sock_addr(inet, addr, &nsa);
-- if (err)
-- goto out;
--
-- chk_addr_ret = inet_addr_type(nsa.saddr);
--
-- /* Not specified by any standard per-se, however it breaks too
-- * many applications when removed. It is unfortunate since
-- * allowing applications to make a non-local bind solves
-- * several problems with systems using dynamic addressing.
-- * (ie. your servers still start up even if your ISDN link
-- * is temporarily down)
-- */
-- err = -EADDRNOTAVAIL;
-- if (!sysctl_ip_nonlocal_bind &&
-- !inet->freebind &&
-- nsa.saddr != INADDR_ANY &&
-- chk_addr_ret != RTN_LOCAL &&
-- chk_addr_ret != RTN_MULTICAST &&
-- chk_addr_ret != RTN_BROADCAST)
-- goto out;
--
-- snum = ntohs(addr->sin_port);
-- err = -EACCES;
-- if (snum && snum < PROT_SOCK && !capable(CAP_NET_BIND_SERVICE))
-- goto out;
--
-- /* We keep a pair of addresses. rcv_saddr is the one
-- * used by hash lookups, and saddr is used for transmit.
-- *
-- * In the BSD API these are the same except where it
-- * would be illegal to use them (multicast/broadcast) in
-- * which case the sending device address is used.
-- */
-- lock_sock(sk);
--
-- /* Check these errors (active socket, double bind). */
-- err = -EINVAL;
-- if (sk->sk_state != TCP_CLOSE || inet->num)
-- goto out_release_sock;
--
-- v4_set_sock_addr(inet, &nsa);
-- if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
-- inet->saddr = 0; /* Use device */
--
-- /* Make sure we are allowed to bind here. */
-- if (sk->sk_prot->get_port(sk, snum)) {
-- inet->saddr = inet->rcv_saddr = 0;
-- err = -EADDRINUSE;
-- goto out_release_sock;
-- }
--
-- if (inet->rcv_saddr)
-- sk->sk_userlocks |= SOCK_BINDADDR_LOCK;
-- if (snum)
-- sk->sk_userlocks |= SOCK_BINDPORT_LOCK;
-- inet->sport = htons(inet->num);
-- inet->daddr = 0;
-- inet->dport = 0;
-- sk_dst_reset(sk);
-- err = 0;
--out_release_sock:
-- release_sock(sk);
--out:
-- return err;
--}
--
--int inet_dgram_connect(struct socket *sock, struct sockaddr * uaddr,
-- int addr_len, int flags)
--{
-- struct sock *sk = sock->sk;
--
-- if (uaddr->sa_family == AF_UNSPEC)
-- return sk->sk_prot->disconnect(sk, flags);
--
-- if (!inet_sk(sk)->num && inet_autobind(sk))
-- return -EAGAIN;
-- return sk->sk_prot->connect(sk, (struct sockaddr *)uaddr, addr_len);
--}
--
--static long inet_wait_for_connect(struct sock *sk, long timeo)
--{
-- DEFINE_WAIT(wait);
--
-- prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
--
-- /* Basic assumption: if someone sets sk->sk_err, he _must_
-- * change state of the socket from TCP_SYN_*.
-- * Connect() does not allow to get error notifications
-- * without closing the socket.
-- */
-- while ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) {
-- release_sock(sk);
-- timeo = schedule_timeout(timeo);
-- lock_sock(sk);
-- if (signal_pending(current) || !timeo)
-- break;
-- prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
-- }
-- finish_wait(sk->sk_sleep, &wait);
-- return timeo;
--}
--
--/*
-- * Connect to a remote host. There is regrettably still a little
-- * TCP 'magic' in here.
-- */
--int inet_stream_connect(struct socket *sock, struct sockaddr *uaddr,
-- int addr_len, int flags)
--{
-- struct sock *sk = sock->sk;
-- int err;
-- long timeo;
--
-- lock_sock(sk);
--
-- if (uaddr->sa_family == AF_UNSPEC) {
-- err = sk->sk_prot->disconnect(sk, flags);
-- sock->state = err ? SS_DISCONNECTING : SS_UNCONNECTED;
-- goto out;
-- }
--
-- switch (sock->state) {
-- default:
-- err = -EINVAL;
-- goto out;
-- case SS_CONNECTED:
-- err = -EISCONN;
-- goto out;
-- case SS_CONNECTING:
-- err = -EALREADY;
-- /* Fall out of switch with err, set for this state */
-- break;
-- case SS_UNCONNECTED:
-- err = -EISCONN;
-- if (sk->sk_state != TCP_CLOSE)
-- goto out;
--
-- err = sk->sk_prot->connect(sk, uaddr, addr_len);
-- if (err < 0)
-- goto out;
--
-- sock->state = SS_CONNECTING;
--
-- /* Just entered SS_CONNECTING state; the only
-- * difference is that return value in non-blocking
-- * case is EINPROGRESS, rather than EALREADY.
-- */
-- err = -EINPROGRESS;
-- break;
-- }
--
-- timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
--
-- if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) {
-- /* Error code is set above */
-- if (!timeo || !inet_wait_for_connect(sk, timeo))
-- goto out;
--
-- err = sock_intr_errno(timeo);
-- if (signal_pending(current))
-- goto out;
-- }
--
-- /* Connection was closed by RST, timeout, ICMP error
-- * or another process disconnected us.
-- */
-- if (sk->sk_state == TCP_CLOSE)
-- goto sock_error;
--
-- /* sk->sk_err may be not zero now, if RECVERR was ordered by user
-- * and error was received after socket entered established state.
-- * Hence, it is handled normally after connect() return successfully.
-- */
--
-- sock->state = SS_CONNECTED;
-- err = 0;
--out:
-- release_sock(sk);
-- return err;
--
--sock_error:
-- err = sock_error(sk) ? : -ECONNABORTED;
-- sock->state = SS_UNCONNECTED;
-- if (sk->sk_prot->disconnect(sk, flags))
-- sock->state = SS_DISCONNECTING;
-- goto out;
--}
--
--/*
-- * Accept a pending connection. The TCP layer now gives BSD semantics.
-- */
--
--int inet_accept(struct socket *sock, struct socket *newsock, int flags)
--{
-- struct sock *sk1 = sock->sk;
-- int err = -EINVAL;
-- struct sock *sk2 = sk1->sk_prot->accept(sk1, flags, &err);
--
-- if (!sk2)
-- goto do_err;
--
-- lock_sock(sk2);
--
-- BUG_TRAP((1 << sk2->sk_state) &
-- (TCPF_ESTABLISHED | TCPF_CLOSE_WAIT | TCPF_CLOSE));
--
-- sock_graft(sk2, newsock);
--
-- newsock->state = SS_CONNECTED;
-- err = 0;
-- release_sock(sk2);
--do_err:
-- return err;
--}
--
--
--/*
-- * This does both peername and sockname.
-- */
--int inet_getname(struct socket *sock, struct sockaddr *uaddr,
-- int *uaddr_len, int peer)
--{
-- struct sock *sk = sock->sk;
-- struct inet_sock *inet = inet_sk(sk);
-- struct sockaddr_in *sin = (struct sockaddr_in *)uaddr;
--
-- sin->sin_family = AF_INET;
-- if (peer) {
-- if (!inet->dport ||
-- (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_SYN_SENT)) &&
-- peer == 1))
-- return -ENOTCONN;
-- sin->sin_port = inet->dport;
-- sin->sin_addr.s_addr =
-- nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
-- } else {
-- __be32 addr = inet->rcv_saddr;
-- if (!addr)
-- addr = inet->saddr;
-- addr = nx_map_sock_lback(sk->sk_nx_info, addr);
-- sin->sin_port = inet->sport;
-- sin->sin_addr.s_addr = addr;
-- }
-- memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
-- *uaddr_len = sizeof(*sin);
-- return 0;
--}
--
--int inet_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
-- size_t size)
--{
-- struct sock *sk = sock->sk;
--
-- /* We may need to bind the socket. */
-- if (!inet_sk(sk)->num && inet_autobind(sk))
-- return -EAGAIN;
--
-- return sk->sk_prot->sendmsg(iocb, sk, msg, size);
--}
--
--
--static ssize_t inet_sendpage(struct socket *sock, struct page *page, int offset, size_t size, int flags)
--{
-- struct sock *sk = sock->sk;
--
-- /* We may need to bind the socket. */
-- if (!inet_sk(sk)->num && inet_autobind(sk))
-- return -EAGAIN;
--
-- if (sk->sk_prot->sendpage)
-- return sk->sk_prot->sendpage(sk, page, offset, size, flags);
-- return sock_no_sendpage(sock, page, offset, size, flags);
--}
--
--
--int inet_shutdown(struct socket *sock, int how)
--{
-- struct sock *sk = sock->sk;
-- int err = 0;
--
-- /* This should really check to make sure
-- * the socket is a TCP socket. (WHY AC...)
-- */
-- how++; /* maps 0->1 has the advantage of making bit 1 rcvs and
-- 1->2 bit 2 snds.
-- 2->3 */
-- if ((how & ~SHUTDOWN_MASK) || !how) /* MAXINT->0 */
-- return -EINVAL;
--
-- lock_sock(sk);
-- if (sock->state == SS_CONNECTING) {
-- if ((1 << sk->sk_state) &
-- (TCPF_SYN_SENT | TCPF_SYN_RECV | TCPF_CLOSE))
-- sock->state = SS_DISCONNECTING;
-- else
-- sock->state = SS_CONNECTED;
-- }
--
-- switch (sk->sk_state) {
-- case TCP_CLOSE:
-- err = -ENOTCONN;
-- /* Hack to wake up other listeners, who can poll for
-- POLLHUP, even on eg. unconnected UDP sockets -- RR */
-- default:
-- sk->sk_shutdown |= how;
-- if (sk->sk_prot->shutdown)
-- sk->sk_prot->shutdown(sk, how);
-- break;
--
-- /* Remaining two branches are temporary solution for missing
-- * close() in multithreaded environment. It is _not_ a good idea,
-- * but we have no choice until close() is repaired at VFS level.
-- */
-- case TCP_LISTEN:
-- if (!(how & RCV_SHUTDOWN))
-- break;
-- /* Fall through */
-- case TCP_SYN_SENT:
-- err = sk->sk_prot->disconnect(sk, O_NONBLOCK);
-- sock->state = err ? SS_DISCONNECTING : SS_UNCONNECTED;
-- break;
-- }
--
-- /* Wake up anyone sleeping in poll. */
-- sk->sk_state_change(sk);
-- release_sock(sk);
-- return err;
--}
--
--/*
-- * ioctl() calls you can issue on an INET socket. Most of these are
-- * device configuration and stuff and very rarely used. Some ioctls
-- * pass on to the socket itself.
-- *
-- * NOTE: I like the idea of a module for the config stuff. ie ifconfig
-- * loads the devconfigure module does its configuring and unloads it.
-- * There's a good 20K of config code hanging around the kernel.
-- */
--
--int inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
--{
-- struct sock *sk = sock->sk;
-- int err = 0;
--
-- switch (cmd) {
-- case SIOCGSTAMP:
-- err = sock_get_timestamp(sk, (struct timeval __user *)arg);
-- break;
-- case SIOCGSTAMPNS:
-- err = sock_get_timestampns(sk, (struct timespec __user *)arg);
-- break;
-- case SIOCADDRT:
-- case SIOCDELRT:
-- case SIOCRTMSG:
-- err = ip_rt_ioctl(cmd, (void __user *)arg);
-- break;
-- case SIOCDARP:
-- case SIOCGARP:
-- case SIOCSARP:
-- err = arp_ioctl(cmd, (void __user *)arg);
-- break;
-- case SIOCGIFADDR:
-- case SIOCSIFADDR:
-- case SIOCGIFBRDADDR:
-- case SIOCSIFBRDADDR:
-- case SIOCGIFNETMASK:
-- case SIOCSIFNETMASK:
-- case SIOCGIFDSTADDR:
-- case SIOCSIFDSTADDR:
-- case SIOCSIFPFLAGS:
-- case SIOCGIFPFLAGS:
-- case SIOCSIFFLAGS:
-- err = devinet_ioctl(cmd, (void __user *)arg);
-- break;
-- default:
-- if (sk->sk_prot->ioctl)
-- err = sk->sk_prot->ioctl(sk, cmd, arg);
-- else
-- err = -ENOIOCTLCMD;
-- break;
-- }
-- return err;
--}
--
--const struct proto_ops inet_stream_ops = {
-- .family = PF_INET,
-- .owner = THIS_MODULE,
-- .release = inet_release,
-- .bind = inet_bind,
-- .connect = inet_stream_connect,
-- .socketpair = sock_no_socketpair,
-- .accept = inet_accept,
-- .getname = inet_getname,
-- .poll = tcp_poll,
-- .ioctl = inet_ioctl,
-- .listen = inet_listen,
-- .shutdown = inet_shutdown,
-- .setsockopt = sock_common_setsockopt,
-- .getsockopt = sock_common_getsockopt,
-- .sendmsg = tcp_sendmsg,
-- .recvmsg = sock_common_recvmsg,
-- .mmap = sock_no_mmap,
-- .sendpage = tcp_sendpage,
--#ifdef CONFIG_COMPAT
-- .compat_setsockopt = compat_sock_common_setsockopt,
-- .compat_getsockopt = compat_sock_common_getsockopt,
--#endif
--};
--
--const struct proto_ops inet_dgram_ops = {
-- .family = PF_INET,
-- .owner = THIS_MODULE,
-- .release = inet_release,
-- .bind = inet_bind,
-- .connect = inet_dgram_connect,
-- .socketpair = sock_no_socketpair,
-- .accept = sock_no_accept,
-- .getname = inet_getname,
-- .poll = udp_poll,
-- .ioctl = inet_ioctl,
-- .listen = sock_no_listen,
-- .shutdown = inet_shutdown,
-- .setsockopt = sock_common_setsockopt,
-- .getsockopt = sock_common_getsockopt,
-- .sendmsg = inet_sendmsg,
-- .recvmsg = sock_common_recvmsg,
-- .mmap = sock_no_mmap,
-- .sendpage = inet_sendpage,
--#ifdef CONFIG_COMPAT
-- .compat_setsockopt = compat_sock_common_setsockopt,
-- .compat_getsockopt = compat_sock_common_getsockopt,
--#endif
--};
--
--/*
-- * For SOCK_RAW sockets; should be the same as inet_dgram_ops but without
-- * udp_poll
-- */
--static const struct proto_ops inet_sockraw_ops = {
-- .family = PF_INET,
-- .owner = THIS_MODULE,
-- .release = inet_release,
-- .bind = inet_bind,
-- .connect = inet_dgram_connect,
-- .socketpair = sock_no_socketpair,
-- .accept = sock_no_accept,
-- .getname = inet_getname,
-- .poll = datagram_poll,
-- .ioctl = inet_ioctl,
-- .listen = sock_no_listen,
-- .shutdown = inet_shutdown,
-- .setsockopt = sock_common_setsockopt,
-- .getsockopt = sock_common_getsockopt,
-- .sendmsg = inet_sendmsg,
-- .recvmsg = sock_common_recvmsg,
-- .mmap = sock_no_mmap,
-- .sendpage = inet_sendpage,
--#ifdef CONFIG_COMPAT
-- .compat_setsockopt = compat_sock_common_setsockopt,
-- .compat_getsockopt = compat_sock_common_getsockopt,
--#endif
--};
--
--static struct net_proto_family inet_family_ops = {
-- .family = PF_INET,
-- .create = inet_create,
-- .owner = THIS_MODULE,
--};
--
--/* Upon startup we insert all the elements in inetsw_array[] into
-- * the linked list inetsw.
-- */
--static struct inet_protosw inetsw_array[] =
--{
-- {
-- .type = SOCK_STREAM,
-- .protocol = IPPROTO_TCP,
-- .prot = &tcp_prot,
-- .ops = &inet_stream_ops,
-- .capability = -1,
-- .no_check = 0,
-- .flags = INET_PROTOSW_PERMANENT |
-- INET_PROTOSW_ICSK,
-- },
--
-- {
-- .type = SOCK_DGRAM,
-- .protocol = IPPROTO_UDP,
-- .prot = &udp_prot,
-- .ops = &inet_dgram_ops,
-- .capability = -1,
-- .no_check = UDP_CSUM_DEFAULT,
-- .flags = INET_PROTOSW_PERMANENT,
-- },
--
--
-- {
-- .type = SOCK_RAW,
-- .protocol = IPPROTO_IP, /* wild card */
-- .prot = &raw_prot,
-- .ops = &inet_sockraw_ops,
-- .capability = CAP_NET_RAW,
-- .no_check = UDP_CSUM_DEFAULT,
-- .flags = INET_PROTOSW_REUSE,
-- }
--};
--
--#define INETSW_ARRAY_LEN (sizeof(inetsw_array) / sizeof(struct inet_protosw))
--
--void inet_register_protosw(struct inet_protosw *p)
--{
-- struct list_head *lh;
-- struct inet_protosw *answer;
-- int protocol = p->protocol;
-- struct list_head *last_perm;
--
-- spin_lock_bh(&inetsw_lock);
--
-- if (p->type >= SOCK_MAX)
-- goto out_illegal;
--
-- /* If we are trying to override a permanent protocol, bail. */
-- answer = NULL;
-- last_perm = &inetsw[p->type];
-- list_for_each(lh, &inetsw[p->type]) {
-- answer = list_entry(lh, struct inet_protosw, list);
--
-- /* Check only the non-wild match. */
-- if (INET_PROTOSW_PERMANENT & answer->flags) {
-- if (protocol == answer->protocol)
-- break;
-- last_perm = lh;
-- }
--
-- answer = NULL;
-- }
-- if (answer)
-- goto out_permanent;
--
-- /* Add the new entry after the last permanent entry if any, so that
-- * the new entry does not override a permanent entry when matched with
-- * a wild-card protocol. But it is allowed to override any existing
-- * non-permanent entry. This means that when we remove this entry, the
-- * system automatically returns to the old behavior.
-- */
-- list_add_rcu(&p->list, last_perm);
--out:
-- spin_unlock_bh(&inetsw_lock);
--
-- synchronize_net();
--
-- return;
--
--out_permanent:
-- printk(KERN_ERR "Attempt to override permanent protocol %d.\n",
-- protocol);
-- goto out;
--
--out_illegal:
-- printk(KERN_ERR
-- "Ignoring attempt to register invalid socket type %d.\n",
-- p->type);
-- goto out;
--}
--
--void inet_unregister_protosw(struct inet_protosw *p)
--{
-- if (INET_PROTOSW_PERMANENT & p->flags) {
-- printk(KERN_ERR
-- "Attempt to unregister permanent protocol %d.\n",
-- p->protocol);
-- } else {
-- spin_lock_bh(&inetsw_lock);
-- list_del_rcu(&p->list);
-- spin_unlock_bh(&inetsw_lock);
--
-- synchronize_net();
-- }
--}
--
--/*
-- * Shall we try to damage output packets if routing dev changes?
-- */
--
--int sysctl_ip_dynaddr __read_mostly;
--
--static int inet_sk_reselect_saddr(struct sock *sk)
--{
-- struct inet_sock *inet = inet_sk(sk);
-- int err;
-- struct rtable *rt;
-- __be32 old_saddr = inet->saddr;
-- __be32 new_saddr;
-- __be32 daddr = inet->daddr;
--
-- if (inet->opt && inet->opt->srr)
-- daddr = inet->opt->faddr;
--
-- /* Query new route. */
-- err = ip_route_connect(&rt, daddr, 0,
-- RT_CONN_FLAGS(sk),
-- sk->sk_bound_dev_if,
-- sk->sk_protocol,
-- inet->sport, inet->dport, sk, 0);
-- if (err)
-- return err;
--
-- sk_setup_caps(sk, &rt->u.dst);
--
-- new_saddr = rt->rt_src;
--
-- if (new_saddr == old_saddr)
-- return 0;
--
-- if (sysctl_ip_dynaddr > 1) {
-- printk(KERN_INFO "%s(): shifting inet->"
-- "saddr from %d.%d.%d.%d to %d.%d.%d.%d\n",
-- __FUNCTION__,
-- NIPQUAD(old_saddr),
-- NIPQUAD(new_saddr));
-- }
--
-- inet->saddr = inet->rcv_saddr = new_saddr;
--
-- /*
-- * XXX The only one ugly spot where we need to
-- * XXX really change the sockets identity after
-- * XXX it has entered the hashes. -DaveM
-- *
-- * Besides that, it does not check for connection
-- * uniqueness. Wait for troubles.
-- */
-- __sk_prot_rehash(sk);
-- return 0;
--}
--
--int inet_sk_rebuild_header(struct sock *sk)
--{
-- struct inet_sock *inet = inet_sk(sk);
-- struct rtable *rt = (struct rtable *)__sk_dst_check(sk, 0);
-- __be32 daddr;
-- int err;
--
-- /* Route is OK, nothing to do. */
-- if (rt)
-- return 0;
--
-- /* Reroute. */
-- daddr = inet->daddr;
-- if (inet->opt && inet->opt->srr)
-- daddr = inet->opt->faddr;
--{
-- struct flowi fl = {
-- .oif = sk->sk_bound_dev_if,
-- .nl_u = {
-- .ip4_u = {
-- .daddr = daddr,
-- .saddr = inet->saddr,
-- .tos = RT_CONN_FLAGS(sk),
-- },
-- },
-- .proto = sk->sk_protocol,
-- .uli_u = {
-- .ports = {
-- .sport = inet->sport,
-- .dport = inet->dport,
-- },
-- },
-- };
--
-- security_sk_classify_flow(sk, &fl);
-- err = ip_route_output_flow(&rt, &fl, sk, 0);
--}
-- if (!err)
-- sk_setup_caps(sk, &rt->u.dst);
-- else {
-- /* Routing failed... */
-- sk->sk_route_caps = 0;
-- /*
-- * Other protocols have to map its equivalent state to TCP_SYN_SENT.
-- * DCCP maps its DCCP_REQUESTING state to TCP_SYN_SENT. -acme
-- */
-- if (!sysctl_ip_dynaddr ||
-- sk->sk_state != TCP_SYN_SENT ||
-- (sk->sk_userlocks & SOCK_BINDADDR_LOCK) ||
-- (err = inet_sk_reselect_saddr(sk)) != 0)
-- sk->sk_err_soft = -err;
-- }
--
-- return err;
--}
--
--EXPORT_SYMBOL(inet_sk_rebuild_header);
--
--static int inet_gso_send_check(struct sk_buff *skb)
--{
-- struct iphdr *iph;
-- struct net_protocol *ops;
-- int proto;
-- int ihl;
-- int err = -EINVAL;
--
-- if (unlikely(!pskb_may_pull(skb, sizeof(*iph))))
-- goto out;
--
-- iph = ip_hdr(skb);
-- ihl = iph->ihl * 4;
-- if (ihl < sizeof(*iph))
-- goto out;
--
-- if (unlikely(!pskb_may_pull(skb, ihl)))
-- goto out;
--
-- __skb_pull(skb, ihl);
-- skb_reset_transport_header(skb);
-- iph = ip_hdr(skb);
-- proto = iph->protocol & (MAX_INET_PROTOS - 1);
-- err = -EPROTONOSUPPORT;
--
-- rcu_read_lock();
-- ops = rcu_dereference(inet_protos[proto]);
-- if (likely(ops && ops->gso_send_check))
-- err = ops->gso_send_check(skb);
-- rcu_read_unlock();
--
--out:
-- return err;
--}
--
--static struct sk_buff *inet_gso_segment(struct sk_buff *skb, int features)
--{
-- struct sk_buff *segs = ERR_PTR(-EINVAL);
-- struct iphdr *iph;
-- struct net_protocol *ops;
-- int proto;
-- int ihl;
-- int id;
--
-- if (unlikely(skb_shinfo(skb)->gso_type &
-- ~(SKB_GSO_TCPV4 |
-- SKB_GSO_UDP |
-- SKB_GSO_DODGY |
-- SKB_GSO_TCP_ECN |
-- 0)))
-- goto out;
--
-- if (unlikely(!pskb_may_pull(skb, sizeof(*iph))))
-- goto out;
--
-- iph = ip_hdr(skb);
-- ihl = iph->ihl * 4;
-- if (ihl < sizeof(*iph))
-- goto out;
--
-- if (unlikely(!pskb_may_pull(skb, ihl)))
-- goto out;
--
-- __skb_pull(skb, ihl);
-- skb_reset_transport_header(skb);
-- iph = ip_hdr(skb);
-- id = ntohs(iph->id);
-- proto = iph->protocol & (MAX_INET_PROTOS - 1);
-- segs = ERR_PTR(-EPROTONOSUPPORT);
--
-- rcu_read_lock();
-- ops = rcu_dereference(inet_protos[proto]);
-- if (likely(ops && ops->gso_segment))
-- segs = ops->gso_segment(skb, features);
-- rcu_read_unlock();
--
-- if (!segs || unlikely(IS_ERR(segs)))
-- goto out;
--
-- skb = segs;
-- do {
-- iph = ip_hdr(skb);
-- iph->id = htons(id++);
-- iph->tot_len = htons(skb->len - skb->mac_len);
-- iph->check = 0;
-- iph->check = ip_fast_csum(skb_network_header(skb), iph->ihl);
-- } while ((skb = skb->next));
--
--out:
-- return segs;
--}
--
--unsigned long snmp_fold_field(void *mib[], int offt)
--{
-- unsigned long res = 0;
-- int i;
--
-- for_each_possible_cpu(i) {
-- res += *(((unsigned long *) per_cpu_ptr(mib[0], i)) + offt);
-- res += *(((unsigned long *) per_cpu_ptr(mib[1], i)) + offt);
-- }
-- return res;
--}
--EXPORT_SYMBOL_GPL(snmp_fold_field);
--
--int snmp_mib_init(void *ptr[2], size_t mibsize, size_t mibalign)
--{
-- BUG_ON(ptr == NULL);
-- ptr[0] = __alloc_percpu(mibsize);
-- if (!ptr[0])
-- goto err0;
-- ptr[1] = __alloc_percpu(mibsize);
-- if (!ptr[1])
-- goto err1;
-- return 0;
--err1:
-- free_percpu(ptr[0]);
-- ptr[0] = NULL;
--err0:
-- return -ENOMEM;
--}
--EXPORT_SYMBOL_GPL(snmp_mib_init);
--
--void snmp_mib_free(void *ptr[2])
--{
-- BUG_ON(ptr == NULL);
-- free_percpu(ptr[0]);
-- free_percpu(ptr[1]);
-- ptr[0] = ptr[1] = NULL;
--}
--EXPORT_SYMBOL_GPL(snmp_mib_free);
--
--#ifdef CONFIG_IP_MULTICAST
--static struct net_protocol igmp_protocol = {
-- .handler = igmp_rcv,
--};
--#endif
--
--static struct net_protocol tcp_protocol = {
-- .handler = tcp_v4_rcv,
-- .err_handler = tcp_v4_err,
-- .gso_send_check = tcp_v4_gso_send_check,
-- .gso_segment = tcp_tso_segment,
-- .no_policy = 1,
--};
--
--static struct net_protocol udp_protocol = {
-- .handler = udp_rcv,
-- .err_handler = udp_err,
-- .no_policy = 1,
--};
--
--static struct net_protocol icmp_protocol = {
-- .handler = icmp_rcv,
--};
--
--static int __init init_ipv4_mibs(void)
--{
-- if (snmp_mib_init((void **)net_statistics,
-- sizeof(struct linux_mib),
-- __alignof__(struct linux_mib)) < 0)
-- goto err_net_mib;
-- if (snmp_mib_init((void **)ip_statistics,
-- sizeof(struct ipstats_mib),
-- __alignof__(struct ipstats_mib)) < 0)
-- goto err_ip_mib;
-- if (snmp_mib_init((void **)icmp_statistics,
-- sizeof(struct icmp_mib),
-- __alignof__(struct icmp_mib)) < 0)
-- goto err_icmp_mib;
-- if (snmp_mib_init((void **)tcp_statistics,
-- sizeof(struct tcp_mib),
-- __alignof__(struct tcp_mib)) < 0)
-- goto err_tcp_mib;
-- if (snmp_mib_init((void **)udp_statistics,
-- sizeof(struct udp_mib),
-- __alignof__(struct udp_mib)) < 0)
-- goto err_udp_mib;
-- if (snmp_mib_init((void **)udplite_statistics,
-- sizeof(struct udp_mib),
-- __alignof__(struct udp_mib)) < 0)
-- goto err_udplite_mib;
--
-- tcp_mib_init();
--
-- return 0;
--
--err_udplite_mib:
-- snmp_mib_free((void **)udp_statistics);
--err_udp_mib:
-- snmp_mib_free((void **)tcp_statistics);
--err_tcp_mib:
-- snmp_mib_free((void **)icmp_statistics);
--err_icmp_mib:
-- snmp_mib_free((void **)ip_statistics);
--err_ip_mib:
-- snmp_mib_free((void **)net_statistics);
--err_net_mib:
-- return -ENOMEM;
--}
--
--static int ipv4_proc_init(void);
--
--/*
-- * IP protocol layer initialiser
-- */
--
--static struct packet_type ip_packet_type = {
-- .type = __constant_htons(ETH_P_IP),
-- .func = ip_rcv,
-- .gso_send_check = inet_gso_send_check,
-- .gso_segment = inet_gso_segment,
--};
--
--static int __init inet_init(void)
--{
-- struct sk_buff *dummy_skb;
-- struct inet_protosw *q;
-- struct list_head *r;
-- int rc = -EINVAL;
--
-- BUILD_BUG_ON(sizeof(struct inet_skb_parm) > sizeof(dummy_skb->cb));
--
-- rc = proto_register(&tcp_prot, 1);
-- if (rc)
-- goto out;
--
-- rc = proto_register(&udp_prot, 1);
-- if (rc)
-- goto out_unregister_tcp_proto;
--
-- rc = proto_register(&raw_prot, 1);
-- if (rc)
-- goto out_unregister_udp_proto;
--
-- /*
-- * Tell SOCKET that we are alive...
-- */
--
-- (void)sock_register(&inet_family_ops);
--
-- /*
-- * Add all the base protocols.
-- */
--
-- if (inet_add_protocol(&icmp_protocol, IPPROTO_ICMP) < 0)
-- printk(KERN_CRIT "inet_init: Cannot add ICMP protocol\n");
-- if (inet_add_protocol(&udp_protocol, IPPROTO_UDP) < 0)
-- printk(KERN_CRIT "inet_init: Cannot add UDP protocol\n");
-- if (inet_add_protocol(&tcp_protocol, IPPROTO_TCP) < 0)
-- printk(KERN_CRIT "inet_init: Cannot add TCP protocol\n");
--#ifdef CONFIG_IP_MULTICAST
-- if (inet_add_protocol(&igmp_protocol, IPPROTO_IGMP) < 0)
-- printk(KERN_CRIT "inet_init: Cannot add IGMP protocol\n");
--#endif
--
-- /* Register the socket-side information for inet_create. */
-- for (r = &inetsw[0]; r < &inetsw[SOCK_MAX]; ++r)
-- INIT_LIST_HEAD(r);
--
-- for (q = inetsw_array; q < &inetsw_array[INETSW_ARRAY_LEN]; ++q)
-- inet_register_protosw(q);
--
-- /*
-- * Set the ARP module up
-- */
--
-- arp_init();
--
-- /*
-- * Set the IP module up
-- */
--
-- ip_init();
--
-- tcp_v4_init(&inet_family_ops);
--
-- /* Setup TCP slab cache for open requests. */
-- tcp_init();
--
-- /* Add UDP-Lite (RFC 3828) */
-- udplite4_register();
--
-- /*
-- * Set the ICMP layer up
-- */
--
-- icmp_init(&inet_family_ops);
--
-- /*
-- * Initialise the multicast router
-- */
--#if defined(CONFIG_IP_MROUTE)
-- ip_mr_init();
--#endif
-- /*
-- * Initialise per-cpu ipv4 mibs
-- */
--
-- if (init_ipv4_mibs())
-- printk(KERN_CRIT "inet_init: Cannot init ipv4 mibs\n"); ;
--
-- ipv4_proc_init();
--
-- ipfrag_init();
--
-- dev_add_pack(&ip_packet_type);
--
-- rc = 0;
--out:
-- return rc;
--out_unregister_udp_proto:
-- proto_unregister(&udp_prot);
--out_unregister_tcp_proto:
-- proto_unregister(&tcp_prot);
-- goto out;
--}
--
--fs_initcall(inet_init);
--
--/* ------------------------------------------------------------------------ */
--
--#ifdef CONFIG_PROC_FS
--static int __init ipv4_proc_init(void)
--{
-- int rc = 0;
--
-- if (raw_proc_init())
-- goto out_raw;
-- if (tcp4_proc_init())
-- goto out_tcp;
-- if (udp4_proc_init())
-- goto out_udp;
-- if (fib_proc_init())
-- goto out_fib;
-- if (ip_misc_proc_init())
-- goto out_misc;
--out:
-- return rc;
--out_misc:
-- fib_proc_exit();
--out_fib:
-- udp4_proc_exit();
--out_udp:
-- tcp4_proc_exit();
--out_tcp:
-- raw_proc_exit();
--out_raw:
-- rc = -ENOMEM;
-- goto out;
--}
--
--#else /* CONFIG_PROC_FS */
--static int __init ipv4_proc_init(void)
--{
-- return 0;
--}
--#endif /* CONFIG_PROC_FS */
--
--MODULE_ALIAS_NETPROTO(PF_INET);
--
--EXPORT_SYMBOL(inet_accept);
--EXPORT_SYMBOL(inet_bind);
--EXPORT_SYMBOL(inet_dgram_connect);
--EXPORT_SYMBOL(inet_dgram_ops);
--EXPORT_SYMBOL(inet_getname);
--EXPORT_SYMBOL(inet_ioctl);
--EXPORT_SYMBOL(inet_listen);
--EXPORT_SYMBOL(inet_register_protosw);
--EXPORT_SYMBOL(inet_release);
--EXPORT_SYMBOL(inet_sendmsg);
--EXPORT_SYMBOL(inet_shutdown);
--EXPORT_SYMBOL(inet_sock_destruct);
--EXPORT_SYMBOL(inet_stream_connect);
--EXPORT_SYMBOL(inet_stream_ops);
--EXPORT_SYMBOL(inet_unregister_protosw);
--EXPORT_SYMBOL(net_statistics);
--EXPORT_SYMBOL(sysctl_ip_nonlocal_bind);
-diff -Nurb linux-2.6.22-594/net/netfilter/xt_MARK.c.orig linux-2.6.22-595/net/netfilter/xt_MARK.c.orig
---- linux-2.6.22-594/net/netfilter/xt_MARK.c.orig 2008-03-20 00:05:19.000000000 -0400
-+++ linux-2.6.22-595/net/netfilter/xt_MARK.c.orig 1969-12-31 19:00:00.000000000 -0500
-@@ -1,283 +0,0 @@
--/* This is a module which is used for setting the NFMARK field of an skb. */
--
--/* (C) 1999-2001 Marc Boucher <marc@mbsi.ca>
-- *
-- * This program is free software; you can redistribute it and/or modify
-- * it under the terms of the GNU General Public License version 2 as
-- * published by the Free Software Foundation.
-- *
-- */
--
--#include <linux/module.h>
--#include <linux/version.h>
--#include <linux/skbuff.h>
--#include <linux/ip.h>
--#include <net/checksum.h>
--#include <net/route.h>
--#include <net/inet_hashtables.h>
--
--#include <net/netfilter/nf_conntrack.h>
--#include <linux/netfilter/x_tables.h>
--#include <linux/netfilter/xt_MARK.h>
--
--MODULE_LICENSE("GPL");
--MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
--MODULE_DESCRIPTION("ip[6]tables MARK modification module");
--MODULE_ALIAS("ipt_MARK");
--MODULE_ALIAS("ip6t_MARK");
--
--static inline u_int16_t
--get_dst_port(struct nf_conntrack_tuple *tuple)
--{
-- switch (tuple->dst.protonum) {
-- case IPPROTO_GRE:
-- /* XXX Truncate 32-bit GRE key to 16 bits */
--#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11)
-- return tuple->dst.u.gre.key;
--#else
-- return htons(ntohl(tuple->dst.u.gre.key));
--#endif
-- case IPPROTO_ICMP:
-- /* Bind on ICMP echo ID */
-- return tuple->src.u.icmp.id;
-- case IPPROTO_TCP:
-- return tuple->dst.u.tcp.port;
-- case IPPROTO_UDP:
-- return tuple->dst.u.udp.port;
-- default:
-- return tuple->dst.u.all;
-- }
--}
--
--static inline u_int16_t
--get_src_port(struct nf_conntrack_tuple *tuple)
--{
-- switch (tuple->dst.protonum) {
-- case IPPROTO_GRE:
-- /* XXX Truncate 32-bit GRE key to 16 bits */
-- return htons(ntohl(tuple->src.u.gre.key));
-- case IPPROTO_ICMP:
-- /* Bind on ICMP echo ID */
-- return tuple->src.u.icmp.id;
-- case IPPROTO_TCP:
-- return tuple->src.u.tcp.port;
-- case IPPROTO_UDP:
-- return tuple->src.u.udp.port;
-- default:
-- return tuple->src.u.all;
-- }
--}
--
--static unsigned int
--target_v0(struct sk_buff **pskb,
-- const struct net_device *in,
-- const struct net_device *out,
-- unsigned int hooknum,
-- const struct xt_target *target,
-- const void *targinfo)
--{
-- const struct xt_mark_target_info *markinfo = targinfo;
--
-- (*pskb)->mark = markinfo->mark;
-- return XT_CONTINUE;
--}
--
--static unsigned int
--target_v1(struct sk_buff **pskb,
-- const struct net_device *in,
-- const struct net_device *out,
-- unsigned int hooknum,
-- const struct xt_target *target,
-- const void *targinfo)
--{
-- const struct xt_mark_target_info_v1 *markinfo = targinfo;
-- int mark = -1;
--
-- switch (markinfo->mode) {
-- case XT_MARK_SET:
-- mark = markinfo->mark;
-- break;
--
-- case XT_MARK_AND:
-- mark = (*pskb)->mark & markinfo->mark;
-- break;
--
-- case XT_MARK_OR:
-- mark = (*pskb)->mark | markinfo->mark;
-- break;
--
-- case XT_MARK_COPYXID: {
-- enum ip_conntrack_info ctinfo;
-- struct sock *connection_sk=NULL;
-- int dif;
--
-- struct nf_conn *ct = nf_ct_get((*pskb), &ctinfo);
-- extern struct inet_hashinfo tcp_hashinfo;
-- enum ip_conntrack_dir dir;
-- if (!ct)
-- break;
--
-- dir = CTINFO2DIR(ctinfo);
-- u_int32_t src_ip = ct->tuplehash[dir].tuple.src.u3.ip;
-- u_int16_t src_port = get_src_port(&ct->tuplehash[dir].tuple);
-- u_int16_t proto = ct->tuplehash[dir].tuple.dst.protonum;
--
-- u_int32_t ip;
-- u_int16_t port;
--
-- dif = ((struct rtable *)(*pskb)->dst)->rt_iif;
-- ip = ct->tuplehash[dir].tuple.dst.u3.ip;
-- port = get_dst_port(&ct->tuplehash[dir].tuple);
--
-- if (proto == 1 || proto == 17) {
-- if (((*pskb)->mark!=-1) && (*pskb)->mark)
-- ct->xid[0]=(*pskb)->mark;
-- if (ct->xid[0])
-- mark = ct->xid[0];
--
-- }
-- else if (proto == 6) {
-- if ((*pskb)->sk)
-- connection_sk = (*pskb)->sk;
-- else {
-- connection_sk = inet_lookup(&tcp_hashinfo, src_ip, src_port, ip, port, dif);
-- }
--
-- if (connection_sk) {
-- connection_sk->sk_peercred.gid = connection_sk->sk_peercred.uid = ct->xid[dir];
-- ct->xid[!dir]=connection_sk->sk_xid;
-- if (connection_sk->sk_xid != 0)
-- mark = connection_sk->sk_xid;
-- if (connection_sk != (*pskb)->sk)
-- sock_put(connection_sk);
-- }
-- break;
-- }
-- }
-- }
--
-- if (mark != -1)
-- (*pskb)->mark = mark;
-- return XT_CONTINUE;
--}
--
--
--static int
--checkentry_v0(const char *tablename,
-- const void *entry,
-- const struct xt_target *target,
-- void *targinfo,
-- unsigned int hook_mask)
--{
-- struct xt_mark_target_info *markinfo = targinfo;
--
-- if (markinfo->mark > 0xffffffff) {
-- printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
-- return 0;
-- }
-- return 1;
--}
--
--static int
--checkentry_v1(const char *tablename,
-- const void *entry,
-- const struct xt_target *target,
-- void *targinfo,
-- unsigned int hook_mask)
--{
-- struct xt_mark_target_info_v1 *markinfo = targinfo;
--
-- if (markinfo->mode != XT_MARK_SET
-- && markinfo->mode != XT_MARK_AND
-- && markinfo->mode != XT_MARK_OR
-- && markinfo->mode != XT_MARK_COPYXID) {
-- printk(KERN_WARNING "MARK: unknown mode %u\n",
-- markinfo->mode);
-- return 0;
-- }
-- if (markinfo->mark > 0xffffffff) {
-- printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
-- return 0;
-- }
-- return 1;
--}
--
--#ifdef CONFIG_COMPAT
--struct compat_xt_mark_target_info_v1 {
-- compat_ulong_t mark;
-- u_int8_t mode;
-- u_int8_t __pad1;
-- u_int16_t __pad2;
--};
--
--static void compat_from_user_v1(void *dst, void *src)
--{
-- struct compat_xt_mark_target_info_v1 *cm = src;
-- struct xt_mark_target_info_v1 m = {
-- .mark = cm->mark,
-- .mode = cm->mode,
-- };
-- memcpy(dst, &m, sizeof(m));
--}
--
--static int compat_to_user_v1(void __user *dst, void *src)
--{
-- struct xt_mark_target_info_v1 *m = src;
-- struct compat_xt_mark_target_info_v1 cm = {
-- .mark = m->mark,
-- .mode = m->mode,
-- };
-- return copy_to_user(dst, &cm, sizeof(cm)) ? -EFAULT : 0;
--}
--#endif /* CONFIG_COMPAT */
--
--static struct xt_target xt_mark_target[] = {
-- {
-- .name = "MARK",
-- .family = AF_INET,
-- .revision = 0,
-- .checkentry = checkentry_v0,
-- .target = target_v0,
-- .targetsize = sizeof(struct xt_mark_target_info),
-- .table = "mangle",
-- .me = THIS_MODULE,
-- },
-- {
-- .name = "MARK",
-- .family = AF_INET,
-- .revision = 1,
-- .checkentry = checkentry_v1,
-- .target = target_v1,
-- .targetsize = sizeof(struct xt_mark_target_info_v1),
--#ifdef CONFIG_COMPAT
-- .compatsize = sizeof(struct compat_xt_mark_target_info_v1),
-- .compat_from_user = compat_from_user_v1,
-- .compat_to_user = compat_to_user_v1,
--#endif
-- .table = "mangle",
-- .me = THIS_MODULE,
-- },
-- {
-- .name = "MARK",
-- .family = AF_INET6,
-- .revision = 0,
-- .checkentry = checkentry_v0,
-- .target = target_v0,
-- .targetsize = sizeof(struct xt_mark_target_info),
-- .table = "mangle",
-- .me = THIS_MODULE,
-- },
--};
--
--static int __init xt_mark_init(void)
--{
-- return xt_register_targets(xt_mark_target, ARRAY_SIZE(xt_mark_target));
--}
--
--static void __exit xt_mark_fini(void)
--{
-- xt_unregister_targets(xt_mark_target, ARRAY_SIZE(xt_mark_target));
--}
--
--module_init(xt_mark_init);
--module_exit(xt_mark_fini);
-diff -Nurb linux-2.6.22-594/net/packet/af_packet.c.orig linux-2.6.22-595/net/packet/af_packet.c.orig
---- linux-2.6.22-594/net/packet/af_packet.c.orig 2008-03-20 00:05:19.000000000 -0400
-+++ linux-2.6.22-595/net/packet/af_packet.c.orig 1969-12-31 19:00:00.000000000 -0500
-@@ -1,1989 +0,0 @@
--/*
-- * INET An implementation of the TCP/IP protocol suite for the LINUX
-- * operating system. INET is implemented using the BSD Socket
-- * interface as the means of communication with the user level.
-- *
-- * PACKET - implements raw packet sockets.
-- *
-- * Version: $Id: af_packet.c,v 1.61 2002/02/08 03:57:19 davem Exp $
-- *
-- * Authors: Ross Biro
-- * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
-- * Alan Cox, <gw4pts@gw4pts.ampr.org>
-- *
-- * Fixes:
-- * Alan Cox : verify_area() now used correctly
-- * Alan Cox : new skbuff lists, look ma no backlogs!
-- * Alan Cox : tidied skbuff lists.
-- * Alan Cox : Now uses generic datagram routines I
-- * added. Also fixed the peek/read crash
-- * from all old Linux datagram code.
-- * Alan Cox : Uses the improved datagram code.
-- * Alan Cox : Added NULL's for socket options.
-- * Alan Cox : Re-commented the code.
-- * Alan Cox : Use new kernel side addressing
-- * Rob Janssen : Correct MTU usage.
-- * Dave Platt : Counter leaks caused by incorrect
-- * interrupt locking and some slightly
-- * dubious gcc output. Can you read
-- * compiler: it said _VOLATILE_
-- * Richard Kooijman : Timestamp fixes.
-- * Alan Cox : New buffers. Use sk->mac.raw.
-- * Alan Cox : sendmsg/recvmsg support.
-- * Alan Cox : Protocol setting support
-- * Alexey Kuznetsov : Untied from IPv4 stack.
-- * Cyrus Durgin : Fixed kerneld for kmod.
-- * Michal Ostrowski : Module initialization cleanup.
-- * Ulises Alonso : Frame number limit removal and
-- * packet_set_ring memory leak.
-- * Eric Biederman : Allow for > 8 byte hardware addresses.
-- * The convention is that longer addresses
-- * will simply extend the hardware address
-- * byte arrays at the end of sockaddr_ll
-- * and packet_mreq.
-- *
-- * This program is free software; you can redistribute it and/or
-- * modify it under the terms of the GNU General Public License
-- * as published by the Free Software Foundation; either version
-- * 2 of the License, or (at your option) any later version.
-- *
-- */
--
--#include <linux/types.h>
--#include <linux/mm.h>
--#include <linux/capability.h>
--#include <linux/fcntl.h>
--#include <linux/socket.h>
--#include <linux/in.h>
--#include <linux/inet.h>
--#include <linux/netdevice.h>
--#include <linux/if_packet.h>
--#include <linux/wireless.h>
--#include <linux/kernel.h>
--#include <linux/kmod.h>
--#include <net/ip.h>
--#include <net/protocol.h>
--#include <linux/skbuff.h>
--#include <net/sock.h>
--#include <linux/errno.h>
--#include <linux/timer.h>
--#include <asm/system.h>
--#include <asm/uaccess.h>
--#include <asm/ioctls.h>
--#include <asm/page.h>
--#include <asm/cacheflush.h>
--#include <asm/io.h>
--#include <linux/proc_fs.h>
--#include <linux/seq_file.h>
--#include <linux/poll.h>
--#include <linux/module.h>
--#include <linux/init.h>
--#include <linux/vs_network.h>
--
--#ifdef CONFIG_INET
--#include <net/inet_common.h>
--#endif
--
--/*
-- Assumptions:
-- - if device has no dev->hard_header routine, it adds and removes ll header
-- inside itself. In this case ll header is invisible outside of device,
-- but higher levels still should reserve dev->hard_header_len.
-- Some devices are enough clever to reallocate skb, when header
-- will not fit to reserved space (tunnel), another ones are silly
-- (PPP).
-- - packet socket receives packets with pulled ll header,
-- so that SOCK_RAW should push it back.
--
--On receive:
-------------
--
--Incoming, dev->hard_header!=NULL
-- mac_header -> ll header
-- data -> data
--
--Outgoing, dev->hard_header!=NULL
-- mac_header -> ll header
-- data -> ll header
--
--Incoming, dev->hard_header==NULL
-- mac_header -> UNKNOWN position. It is very likely, that it points to ll
-- header. PPP makes it, that is wrong, because introduce
-- assymetry between rx and tx paths.
-- data -> data
--
--Outgoing, dev->hard_header==NULL
-- mac_header -> data. ll header is still not built!
-- data -> data
--
--Resume
-- If dev->hard_header==NULL we are unlikely to restore sensible ll header.
--
--
--On transmit:
--------------
--
--dev->hard_header != NULL
-- mac_header -> ll header
-- data -> ll header
--
--dev->hard_header == NULL (ll header is added by device, we cannot control it)
-- mac_header -> data
-- data -> data
--
-- We should set nh.raw on output to correct posistion,
-- packet classifier depends on it.
-- */
--
--/* List of all packet sockets. */
--static HLIST_HEAD(packet_sklist);
--static DEFINE_RWLOCK(packet_sklist_lock);
--
--static atomic_t packet_socks_nr;
--
--
--/* Private packet socket structures. */
--
--struct packet_mclist
--{
-- struct packet_mclist *next;
-- int ifindex;
-- int count;
-- unsigned short type;
-- unsigned short alen;
-- unsigned char addr[MAX_ADDR_LEN];
--};
--/* identical to struct packet_mreq except it has
-- * a longer address field.
-- */
--struct packet_mreq_max
--{
-- int mr_ifindex;
-- unsigned short mr_type;
-- unsigned short mr_alen;
-- unsigned char mr_address[MAX_ADDR_LEN];
--};
--
--#ifdef CONFIG_PACKET_MMAP
--static int packet_set_ring(struct sock *sk, struct tpacket_req *req, int closing);
--#endif
--
--static void packet_flush_mclist(struct sock *sk);
--
--struct packet_sock {
-- /* struct sock has to be the first member of packet_sock */
-- struct sock sk;
-- struct tpacket_stats stats;
--#ifdef CONFIG_PACKET_MMAP
-- char * *pg_vec;
-- unsigned int head;
-- unsigned int frames_per_block;
-- unsigned int frame_size;
-- unsigned int frame_max;
-- int copy_thresh;
--#endif
-- struct packet_type prot_hook;
-- spinlock_t bind_lock;
-- unsigned int running:1, /* prot_hook is attached*/
-- auxdata:1,
-- origdev:1;
-- int ifindex; /* bound device */
-- __be16 num;
-- struct packet_mclist *mclist;
--#ifdef CONFIG_PACKET_MMAP
-- atomic_t mapped;
-- unsigned int pg_vec_order;
-- unsigned int pg_vec_pages;
-- unsigned int pg_vec_len;
--#endif
--};
--
--struct packet_skb_cb {
-- unsigned int origlen;
-- union {
-- struct sockaddr_pkt pkt;
-- struct sockaddr_ll ll;
-- } sa;
--};
--
--#define PACKET_SKB_CB(__skb) ((struct packet_skb_cb *)((__skb)->cb))
--
--#ifdef CONFIG_PACKET_MMAP
--
--static inline struct tpacket_hdr *packet_lookup_frame(struct packet_sock *po, unsigned int position)
--{
-- unsigned int pg_vec_pos, frame_offset;
--
-- pg_vec_pos = position / po->frames_per_block;
-- frame_offset = position % po->frames_per_block;
--
-- return (struct tpacket_hdr *)(po->pg_vec[pg_vec_pos] + (frame_offset * po->frame_size));
--}
--#endif
--
--static inline struct packet_sock *pkt_sk(struct sock *sk)
--{
-- return (struct packet_sock *)sk;
--}
--
--static void packet_sock_destruct(struct sock *sk)
--{
-- BUG_TRAP(!atomic_read(&sk->sk_rmem_alloc));
-- BUG_TRAP(!atomic_read(&sk->sk_wmem_alloc));
--
-- if (!sock_flag(sk, SOCK_DEAD)) {
-- printk("Attempt to release alive packet socket: %p\n", sk);
-- return;
-- }
--
-- atomic_dec(&packet_socks_nr);
--#ifdef PACKET_REFCNT_DEBUG
-- printk(KERN_DEBUG "PACKET socket %p is free, %d are alive\n", sk, atomic_read(&packet_socks_nr));
--#endif
--}
--
--
--static const struct proto_ops packet_ops;
--
--static const struct proto_ops packet_ops_spkt;
--
--static int packet_rcv_spkt(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev)
--{
-- struct sock *sk;
-- struct sockaddr_pkt *spkt;
--
-- /*
-- * When we registered the protocol we saved the socket in the data
-- * field for just this event.
-- */
--
-- sk = pt->af_packet_priv;
--
-- /*
-- * Yank back the headers [hope the device set this
-- * right or kerboom...]
-- *
-- * Incoming packets have ll header pulled,
-- * push it back.
-- *
-- * For outgoing ones skb->data == skb_mac_header(skb)
-- * so that this procedure is noop.
-- */
--
-- if (skb->pkt_type == PACKET_LOOPBACK)
-- goto out;
--
-- if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)
-- goto oom;
--
-- /* drop any routing info */
-- dst_release(skb->dst);
-- skb->dst = NULL;
--
-- /* drop conntrack reference */
-- nf_reset(skb);
--
-- spkt = &PACKET_SKB_CB(skb)->sa.pkt;
--
-- skb_push(skb, skb->data - skb_mac_header(skb));
--
-- /*
-- * The SOCK_PACKET socket receives _all_ frames.
-- */
--
-- spkt->spkt_family = dev->type;
-- strlcpy(spkt->spkt_device, dev->name, sizeof(spkt->spkt_device));
-- spkt->spkt_protocol = skb->protocol;
--
-- /*
-- * Charge the memory to the socket. This is done specifically
-- * to prevent sockets using all the memory up.
-- */
--
-- if (sock_queue_rcv_skb(sk,skb) == 0)
-- return 0;
--
--out:
-- kfree_skb(skb);
--oom:
-- return 0;
--}
--
--
--/*
-- * Output a raw packet to a device layer. This bypasses all the other
-- * protocol layers and you must therefore supply it with a complete frame
-- */
--
--static int packet_sendmsg_spkt(struct kiocb *iocb, struct socket *sock,
-- struct msghdr *msg, size_t len)
--{
-- struct sock *sk = sock->sk;
-- struct sockaddr_pkt *saddr=(struct sockaddr_pkt *)msg->msg_name;
-- struct sk_buff *skb;
-- struct net_device *dev;
-- __be16 proto=0;
-- int err;
--
-- if (!nx_capable(CAP_NET_RAW, NXC_RAW_SEND))
-- return -EPERM;
--
-- /*
-- * Get and verify the address.
-- */
--
-- if (saddr)
-- {
-- if (msg->msg_namelen < sizeof(struct sockaddr))
-- return(-EINVAL);
-- if (msg->msg_namelen==sizeof(struct sockaddr_pkt))
-- proto=saddr->spkt_protocol;
-- }
-- else
-- return(-ENOTCONN); /* SOCK_PACKET must be sent giving an address */
--
-- /*
-- * Find the device first to size check it
-- */
--
-- saddr->spkt_device[13] = 0;
-- dev = dev_get_by_name(saddr->spkt_device);
-- err = -ENODEV;
-- if (dev == NULL)
-- goto out_unlock;
--
-- err = -ENETDOWN;
-- if (!(dev->flags & IFF_UP))
-- goto out_unlock;
--
-- /*
-- * You may not queue a frame bigger than the mtu. This is the lowest level
-- * raw protocol and you must do your own fragmentation at this level.
-- */
--
-- err = -EMSGSIZE;
-- if (len > dev->mtu + dev->hard_header_len)
-- goto out_unlock;
--
-- err = -ENOBUFS;
-- skb = sock_wmalloc(sk, len + LL_RESERVED_SPACE(dev), 0, GFP_KERNEL);
--
-- /*
-- * If the write buffer is full, then tough. At this level the user gets to
-- * deal with the problem - do your own algorithmic backoffs. That's far
-- * more flexible.
-- */
--
-- if (skb == NULL)
-- goto out_unlock;
--
-- /*
-- * Fill it in
-- */
--
-- /* FIXME: Save some space for broken drivers that write a
-- * hard header at transmission time by themselves. PPP is the
-- * notable one here. This should really be fixed at the driver level.
-- */
-- skb_reserve(skb, LL_RESERVED_SPACE(dev));
-- skb_reset_network_header(skb);
--
-- /* Try to align data part correctly */
-- if (dev->hard_header) {
-- skb->data -= dev->hard_header_len;
-- skb->tail -= dev->hard_header_len;
-- if (len < dev->hard_header_len)
-- skb_reset_network_header(skb);
-- }
--
-- /* Returns -EFAULT on error */
-- err = memcpy_fromiovec(skb_put(skb,len), msg->msg_iov, len);
-- skb->protocol = proto;
-- skb->dev = dev;
-- skb->priority = sk->sk_priority;
-- if (err)
-- goto out_free;
--
-- /*
-- * Now send it
-- */
--
-- dev_queue_xmit(skb);
-- dev_put(dev);
-- return(len);
--
--out_free:
-- kfree_skb(skb);
--out_unlock:
-- if (dev)
-- dev_put(dev);
-- return err;
--}
--
--static inline unsigned int run_filter(struct sk_buff *skb, struct sock *sk,
-- unsigned int res)
--{
-- struct sk_filter *filter;
-- int tag = skb->skb_tag;
--
-- if (sk->sk_nx_info && !(tag == 1 || sk->sk_nid == tag))
-- return 0;
--
-- rcu_read_lock_bh();
-- filter = rcu_dereference(sk->sk_filter);
-- if (filter != NULL)
-- res = sk_run_filter(skb, filter->insns, filter->len);
-- rcu_read_unlock_bh();
--
-- return res;
--}
--
--/*
-- This function makes lazy skb cloning in hope that most of packets
-- are discarded by BPF.
--
-- Note tricky part: we DO mangle shared skb! skb->data, skb->len
-- and skb->cb are mangled. It works because (and until) packets
-- falling here are owned by current CPU. Output packets are cloned
-- by dev_queue_xmit_nit(), input packets are processed by net_bh
-- sequencially, so that if we return skb to original state on exit,
-- we will not harm anyone.
-- */
--
--static int packet_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev)
--{
-- struct sock *sk;
-- struct sockaddr_ll *sll;
-- struct packet_sock *po;
-- u8 * skb_head = skb->data;
-- int skb_len = skb->len;
-- unsigned int snaplen, res;
--
-- if (skb->pkt_type == PACKET_LOOPBACK)
-- goto drop;
--
-- sk = pt->af_packet_priv;
-- po = pkt_sk(sk);
--
-- skb->dev = dev;
--
-- if (dev->hard_header) {
-- /* The device has an explicit notion of ll header,
-- exported to higher levels.
--
-- Otherwise, the device hides datails of it frame
-- structure, so that corresponding packet head
-- never delivered to user.
-- */
-- if (sk->sk_type != SOCK_DGRAM)
-- skb_push(skb, skb->data - skb_mac_header(skb));
-- else if (skb->pkt_type == PACKET_OUTGOING) {
-- /* Special case: outgoing packets have ll header at head */
-- skb_pull(skb, skb_network_offset(skb));
-- }
-- }
--
-- snaplen = skb->len;
--
-- res = run_filter(skb, sk, snaplen);
-- if (!res)
-- goto drop_n_restore;
-- if (snaplen > res)
-- snaplen = res;
--
-- if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
-- (unsigned)sk->sk_rcvbuf)
-- goto drop_n_acct;
--
-- if (skb_shared(skb)) {
-- struct sk_buff *nskb = skb_clone(skb, GFP_ATOMIC);
-- if (nskb == NULL)
-- goto drop_n_acct;
--
-- if (skb_head != skb->data) {
-- skb->data = skb_head;
-- skb->len = skb_len;
-- }
-- kfree_skb(skb);
-- skb = nskb;
-- }
--
-- BUILD_BUG_ON(sizeof(*PACKET_SKB_CB(skb)) + MAX_ADDR_LEN - 8 >
-- sizeof(skb->cb));
--
-- sll = &PACKET_SKB_CB(skb)->sa.ll;
-- sll->sll_family = AF_PACKET;
-- sll->sll_hatype = dev->type;
-- sll->sll_protocol = skb->protocol;
-- sll->sll_pkttype = skb->pkt_type;
-- if (unlikely(po->origdev) && skb->pkt_type == PACKET_HOST)
-- sll->sll_ifindex = orig_dev->ifindex;
-- else
-- sll->sll_ifindex = dev->ifindex;
-- sll->sll_halen = 0;
--
-- if (dev->hard_header_parse)
-- sll->sll_halen = dev->hard_header_parse(skb, sll->sll_addr);
--
-- PACKET_SKB_CB(skb)->origlen = skb->len;
--
-- if (pskb_trim(skb, snaplen))
-- goto drop_n_acct;
--
-- skb_set_owner_r(skb, sk);
-- skb->dev = NULL;
-- dst_release(skb->dst);
-- skb->dst = NULL;
--
-- /* drop conntrack reference */
-- nf_reset(skb);
--
-- spin_lock(&sk->sk_receive_queue.lock);
-- po->stats.tp_packets++;
-- __skb_queue_tail(&sk->sk_receive_queue, skb);
-- spin_unlock(&sk->sk_receive_queue.lock);
-- sk->sk_data_ready(sk, skb->len);
-- return 0;
--
--drop_n_acct:
-- spin_lock(&sk->sk_receive_queue.lock);
-- po->stats.tp_drops++;
-- spin_unlock(&sk->sk_receive_queue.lock);
--
--drop_n_restore:
-- if (skb_head != skb->data && skb_shared(skb)) {
-- skb->data = skb_head;
-- skb->len = skb_len;
-- }
--drop:
-- kfree_skb(skb);
-- return 0;
--}
--
--#ifdef CONFIG_PACKET_MMAP
--static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev)
--{
-- struct sock *sk;
-- struct packet_sock *po;
-- struct sockaddr_ll *sll;
-- struct tpacket_hdr *h;
-- u8 * skb_head = skb->data;
-- int skb_len = skb->len;
-- unsigned int snaplen, res;
-- unsigned long status = TP_STATUS_LOSING|TP_STATUS_USER;
-- unsigned short macoff, netoff;
-- struct sk_buff *copy_skb = NULL;
-- struct timeval tv;
--
-- if (skb->pkt_type == PACKET_LOOPBACK)
-- goto drop;
--
-- sk = pt->af_packet_priv;
-- po = pkt_sk(sk);
--
-- if (dev->hard_header) {
-- if (sk->sk_type != SOCK_DGRAM)
-- skb_push(skb, skb->data - skb_mac_header(skb));
-- else if (skb->pkt_type == PACKET_OUTGOING) {
-- /* Special case: outgoing packets have ll header at head */
-- skb_pull(skb, skb_network_offset(skb));
-- }
-- }
--
-- if (skb->ip_summed == CHECKSUM_PARTIAL)
-- status |= TP_STATUS_CSUMNOTREADY;
--
-- snaplen = skb->len;
--
-- res = run_filter(skb, sk, snaplen);
-- if (!res)
-- goto drop_n_restore;
-- if (snaplen > res)
-- snaplen = res;
--
-- if (sk->sk_type == SOCK_DGRAM) {
-- macoff = netoff = TPACKET_ALIGN(TPACKET_HDRLEN) + 16;
-- } else {
-- unsigned maclen = skb_network_offset(skb);
-- netoff = TPACKET_ALIGN(TPACKET_HDRLEN + (maclen < 16 ? 16 : maclen));
-- macoff = netoff - maclen;
-- }
--
-- if (macoff + snaplen > po->frame_size) {
-- if (po->copy_thresh &&
-- atomic_read(&sk->sk_rmem_alloc) + skb->truesize <
-- (unsigned)sk->sk_rcvbuf) {
-- if (skb_shared(skb)) {
-- copy_skb = skb_clone(skb, GFP_ATOMIC);
-- } else {
-- copy_skb = skb_get(skb);
-- skb_head = skb->data;
-- }
-- if (copy_skb)
-- skb_set_owner_r(copy_skb, sk);
-- }
-- snaplen = po->frame_size - macoff;
-- if ((int)snaplen < 0)
-- snaplen = 0;
-- }
--
-- spin_lock(&sk->sk_receive_queue.lock);
-- h = packet_lookup_frame(po, po->head);
--
-- if (h->tp_status)
-- goto ring_is_full;
-- po->head = po->head != po->frame_max ? po->head+1 : 0;
-- po->stats.tp_packets++;
-- if (copy_skb) {
-- status |= TP_STATUS_COPY;
-- __skb_queue_tail(&sk->sk_receive_queue, copy_skb);
-- }
-- if (!po->stats.tp_drops)
-- status &= ~TP_STATUS_LOSING;
-- spin_unlock(&sk->sk_receive_queue.lock);
--
-- skb_copy_bits(skb, 0, (u8*)h + macoff, snaplen);
--
-- h->tp_len = skb->len;
-- h->tp_snaplen = snaplen;
-- h->tp_mac = macoff;
-- h->tp_net = netoff;
-- if (skb->tstamp.tv64 == 0) {
-- __net_timestamp(skb);
-- sock_enable_timestamp(sk);
-- }
-- tv = ktime_to_timeval(skb->tstamp);
-- h->tp_sec = tv.tv_sec;
-- h->tp_usec = tv.tv_usec;
--
-- sll = (struct sockaddr_ll*)((u8*)h + TPACKET_ALIGN(sizeof(*h)));
-- sll->sll_halen = 0;
-- if (dev->hard_header_parse)
-- sll->sll_halen = dev->hard_header_parse(skb, sll->sll_addr);
-- sll->sll_family = AF_PACKET;
-- sll->sll_hatype = dev->type;
-- sll->sll_protocol = skb->protocol;
-- sll->sll_pkttype = skb->pkt_type;
-- if (unlikely(po->origdev) && skb->pkt_type == PACKET_HOST)
-- sll->sll_ifindex = orig_dev->ifindex;
-- else
-- sll->sll_ifindex = dev->ifindex;
--
-- h->tp_status = status;
-- smp_mb();
--
-- {
-- struct page *p_start, *p_end;
-- u8 *h_end = (u8 *)h + macoff + snaplen - 1;
--
-- p_start = virt_to_page(h);
-- p_end = virt_to_page(h_end);
-- while (p_start <= p_end) {
-- flush_dcache_page(p_start);
-- p_start++;
-- }
-- }
--
-- sk->sk_data_ready(sk, 0);
--
--drop_n_restore:
-- if (skb_head != skb->data && skb_shared(skb)) {
-- skb->data = skb_head;
-- skb->len = skb_len;
-- }
--drop:
-- kfree_skb(skb);
-- return 0;
--
--ring_is_full:
-- po->stats.tp_drops++;
-- spin_unlock(&sk->sk_receive_queue.lock);
--
-- sk->sk_data_ready(sk, 0);
-- if (copy_skb)
-- kfree_skb(copy_skb);
-- goto drop_n_restore;
--}
--
--#endif
--
--
--static int packet_sendmsg(struct kiocb *iocb, struct socket *sock,
-- struct msghdr *msg, size_t len)
--{
-- struct sock *sk = sock->sk;
-- struct sockaddr_ll *saddr=(struct sockaddr_ll *)msg->msg_name;
-- struct sk_buff *skb;
-- struct net_device *dev;
-- __be16 proto;
-- unsigned char *addr;
-- int ifindex, err, reserve = 0;
--
-- if (!nx_capable(CAP_NET_RAW, NXC_RAW_SEND))
-- return -EPERM;
--
-- /*
-- * Get and verify the address.
-- */
--
-- if (saddr == NULL) {
-- struct packet_sock *po = pkt_sk(sk);
--
-- ifindex = po->ifindex;
-- proto = po->num;
-- addr = NULL;
-- } else {
-- err = -EINVAL;
-- if (msg->msg_namelen < sizeof(struct sockaddr_ll))
-- goto out;
-- if (msg->msg_namelen < (saddr->sll_halen + offsetof(struct sockaddr_ll, sll_addr)))
-- goto out;
-- ifindex = saddr->sll_ifindex;
-- proto = saddr->sll_protocol;
-- addr = saddr->sll_addr;
-- }
--
--
-- dev = dev_get_by_index(ifindex);
-- err = -ENXIO;
-- if (dev == NULL)
-- goto out_unlock;
-- if (sock->type == SOCK_RAW)
-- reserve = dev->hard_header_len;
--
-- err = -ENETDOWN;
-- if (!(dev->flags & IFF_UP))
-- goto out_unlock;
--
-- err = -EMSGSIZE;
-- if (len > dev->mtu+reserve)
-- goto out_unlock;
--
-- skb = sock_alloc_send_skb(sk, len + LL_RESERVED_SPACE(dev),
-- msg->msg_flags & MSG_DONTWAIT, &err);
-- if (skb==NULL)
-- goto out_unlock;
--
-- skb_reserve(skb, LL_RESERVED_SPACE(dev));
-- skb_reset_network_header(skb);
--
-- if (dev->hard_header) {
-- int res;
-- err = -EINVAL;
-- res = dev->hard_header(skb, dev, ntohs(proto), addr, NULL, len);
-- if (sock->type != SOCK_DGRAM) {
-- skb_reset_tail_pointer(skb);
-- skb->len = 0;
-- } else if (res < 0)
-- goto out_free;
-- }
--
-- /* Returns -EFAULT on error */
-- err = memcpy_fromiovec(skb_put(skb,len), msg->msg_iov, len);
-- if (err)
-- goto out_free;
--
-- skb->protocol = proto;
-- skb->dev = dev;
-- skb->priority = sk->sk_priority;
--
-- /*
-- * Now send it
-- */
--
-- err = dev_queue_xmit(skb);
-- if (err > 0 && (err = net_xmit_errno(err)) != 0)
-- goto out_unlock;
--
-- dev_put(dev);
--
-- return(len);
--
--out_free:
-- kfree_skb(skb);
--out_unlock:
-- if (dev)
-- dev_put(dev);
--out:
-- return err;
--}
--
--/*
-- * Close a PACKET socket. This is fairly simple. We immediately go
-- * to 'closed' state and remove our protocol entry in the device list.
-- */
--
--static int packet_release(struct socket *sock)
--{
-- struct sock *sk = sock->sk;
-- struct packet_sock *po;
--
-- if (!sk)
-- return 0;
--
-- po = pkt_sk(sk);
--
-- write_lock_bh(&packet_sklist_lock);
-- sk_del_node_init(sk);
-- write_unlock_bh(&packet_sklist_lock);
--
-- /*
-- * Unhook packet receive handler.
-- */
--
-- if (po->running) {
-- /*
-- * Remove the protocol hook
-- */
-- dev_remove_pack(&po->prot_hook);
-- po->running = 0;
-- po->num = 0;
-- __sock_put(sk);
-- }
--
-- packet_flush_mclist(sk);
--
--#ifdef CONFIG_PACKET_MMAP
-- if (po->pg_vec) {
-- struct tpacket_req req;
-- memset(&req, 0, sizeof(req));
-- packet_set_ring(sk, &req, 1);
-- }
--#endif
--
-- /*
-- * Now the socket is dead. No more input will appear.
-- */
--
-- sock_orphan(sk);
-- sock->sk = NULL;
--
-- /* Purge queues */
--
-- skb_queue_purge(&sk->sk_receive_queue);
--
-- sock_put(sk);
-- return 0;
--}
--
--/*
-- * Attach a packet hook.
-- */
--
--static int packet_do_bind(struct sock *sk, struct net_device *dev, __be16 protocol)
--{
-- struct packet_sock *po = pkt_sk(sk);
-- /*
-- * Detach an existing hook if present.
-- */
--
-- lock_sock(sk);
--
-- spin_lock(&po->bind_lock);
-- if (po->running) {
-- __sock_put(sk);
-- po->running = 0;
-- po->num = 0;
-- spin_unlock(&po->bind_lock);
-- dev_remove_pack(&po->prot_hook);
-- spin_lock(&po->bind_lock);
-- }
--
-- po->num = protocol;
-- po->prot_hook.type = protocol;
-- po->prot_hook.dev = dev;
--
-- po->ifindex = dev ? dev->ifindex : 0;
--
-- if (protocol == 0)
-- goto out_unlock;
--
-- if (dev) {
-- if (dev->flags&IFF_UP) {
-- dev_add_pack(&po->prot_hook);
-- sock_hold(sk);
-- po->running = 1;
-- } else {
-- sk->sk_err = ENETDOWN;
-- if (!sock_flag(sk, SOCK_DEAD))
-- sk->sk_error_report(sk);
-- }
-- } else {
-- dev_add_pack(&po->prot_hook);
-- sock_hold(sk);
-- po->running = 1;
-- }
--
--out_unlock:
-- spin_unlock(&po->bind_lock);
-- release_sock(sk);
-- return 0;
--}
--
--/*
-- * Bind a packet socket to a device
-- */
--
--static int packet_bind_spkt(struct socket *sock, struct sockaddr *uaddr, int addr_len)
--{
-- struct sock *sk=sock->sk;
-- char name[15];
-- struct net_device *dev;
-- int err = -ENODEV;
--
-- /*
-- * Check legality
-- */
--
-- if (addr_len != sizeof(struct sockaddr))
-- return -EINVAL;
-- strlcpy(name,uaddr->sa_data,sizeof(name));
--
-- dev = dev_get_by_name(name);
-- if (dev) {
-- err = packet_do_bind(sk, dev, pkt_sk(sk)->num);
-- dev_put(dev);
-- }
-- return err;
--}
--
--static int packet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
--{
-- struct sockaddr_ll *sll = (struct sockaddr_ll*)uaddr;
-- struct sock *sk=sock->sk;
-- struct net_device *dev = NULL;
-- int err;
--
--
-- /*
-- * Check legality
-- */
--
-- if (addr_len < sizeof(struct sockaddr_ll))
-- return -EINVAL;
-- if (sll->sll_family != AF_PACKET)
-- return -EINVAL;
--
-- if (sll->sll_ifindex) {
-- err = -ENODEV;
-- dev = dev_get_by_index(sll->sll_ifindex);
-- if (dev == NULL)
-- goto out;
-- }
-- err = packet_do_bind(sk, dev, sll->sll_protocol ? : pkt_sk(sk)->num);
-- if (dev)
-- dev_put(dev);
--
--out:
-- return err;
--}
--
--static struct proto packet_proto = {
-- .name = "PACKET",
-- .owner = THIS_MODULE,
-- .obj_size = sizeof(struct packet_sock),
--};
--
--/*
-- * Create a packet of type SOCK_PACKET.
-- */
--
--static int packet_create(struct socket *sock, int protocol)
--{
-- struct sock *sk;
-- struct packet_sock *po;
-- __be16 proto = (__force __be16)protocol; /* weird, but documented */
-- int err;
--
-- if (!nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET))
-- return -EPERM;
-- if (sock->type != SOCK_DGRAM && sock->type != SOCK_RAW &&
-- sock->type != SOCK_PACKET)
-- return -ESOCKTNOSUPPORT;
--
-- sock->state = SS_UNCONNECTED;
--
-- err = -ENOBUFS;
-- sk = sk_alloc(PF_PACKET, GFP_KERNEL, &packet_proto, 1);
-- if (sk == NULL)
-- goto out;
--
-- sock->ops = &packet_ops;
-- if (sock->type == SOCK_PACKET)
-- sock->ops = &packet_ops_spkt;
--
-- sock_init_data(sock, sk);
--
-- po = pkt_sk(sk);
-- sk->sk_family = PF_PACKET;
-- po->num = proto;
--
-- sk->sk_destruct = packet_sock_destruct;
-- atomic_inc(&packet_socks_nr);
--
-- /*
-- * Attach a protocol block
-- */
--
-- spin_lock_init(&po->bind_lock);
-- po->prot_hook.func = packet_rcv;
--
-- if (sock->type == SOCK_PACKET)
-- po->prot_hook.func = packet_rcv_spkt;
--
-- po->prot_hook.af_packet_priv = sk;
--
-- if (proto) {
-- po->prot_hook.type = proto;
-- dev_add_pack(&po->prot_hook);
-- sock_hold(sk);
-- po->running = 1;
-- }
--
-- write_lock_bh(&packet_sklist_lock);
-- sk_add_node(sk, &packet_sklist);
-- write_unlock_bh(&packet_sklist_lock);
-- return(0);
--out:
-- return err;
--}
--
--/*
-- * Pull a packet from our receive queue and hand it to the user.
-- * If necessary we block.
-- */
--
--static int packet_recvmsg(struct kiocb *iocb, struct socket *sock,
-- struct msghdr *msg, size_t len, int flags)
--{
-- struct sock *sk = sock->sk;
-- struct sk_buff *skb;
-- int copied, err;
-- struct sockaddr_ll *sll;
--
-- err = -EINVAL;
-- if (flags & ~(MSG_PEEK|MSG_DONTWAIT|MSG_TRUNC|MSG_CMSG_COMPAT))
-- goto out;
--
--#if 0
-- /* What error should we return now? EUNATTACH? */
-- if (pkt_sk(sk)->ifindex < 0)
-- return -ENODEV;
--#endif
--
-- /*
-- * Call the generic datagram receiver. This handles all sorts
-- * of horrible races and re-entrancy so we can forget about it
-- * in the protocol layers.
-- *
-- * Now it will return ENETDOWN, if device have just gone down,
-- * but then it will block.
-- */
--
-- skb=skb_recv_datagram(sk,flags,flags&MSG_DONTWAIT,&err);
--
-- /*
-- * An error occurred so return it. Because skb_recv_datagram()
-- * handles the blocking we don't see and worry about blocking
-- * retries.
-- */
--
-- if (skb == NULL)
-- goto out;
--
-- /*
-- * If the address length field is there to be filled in, we fill
-- * it in now.
-- */
--
-- sll = &PACKET_SKB_CB(skb)->sa.ll;
-- if (sock->type == SOCK_PACKET)
-- msg->msg_namelen = sizeof(struct sockaddr_pkt);
-- else
-- msg->msg_namelen = sll->sll_halen + offsetof(struct sockaddr_ll, sll_addr);
--
-- /*
-- * You lose any data beyond the buffer you gave. If it worries a
-- * user program they can ask the device for its MTU anyway.
-- */
--
-- copied = skb->len;
-- if (copied > len)
-- {
-- copied=len;
-- msg->msg_flags|=MSG_TRUNC;
-- }
--
-- err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
-- if (err)
-- goto out_free;
--
-- sock_recv_timestamp(msg, sk, skb);
--
-- if (msg->msg_name)
-- memcpy(msg->msg_name, &PACKET_SKB_CB(skb)->sa,
-- msg->msg_namelen);
--
-- if (pkt_sk(sk)->auxdata) {
-- struct tpacket_auxdata aux;
--
-- aux.tp_status = TP_STATUS_USER;
-- if (skb->ip_summed == CHECKSUM_PARTIAL)
-- aux.tp_status |= TP_STATUS_CSUMNOTREADY;
-- aux.tp_len = PACKET_SKB_CB(skb)->origlen;
-- aux.tp_snaplen = skb->len;
-- aux.tp_mac = 0;
-- aux.tp_net = skb_network_offset(skb);
--
-- put_cmsg(msg, SOL_PACKET, PACKET_AUXDATA, sizeof(aux), &aux);
-- }
--
-- /*
-- * Free or return the buffer as appropriate. Again this
-- * hides all the races and re-entrancy issues from us.
-- */
-- err = (flags&MSG_TRUNC) ? skb->len : copied;
--
--out_free:
-- skb_free_datagram(sk, skb);
--out:
-- return err;
--}
--
--static int packet_getname_spkt(struct socket *sock, struct sockaddr *uaddr,
-- int *uaddr_len, int peer)
--{
-- struct net_device *dev;
-- struct sock *sk = sock->sk;
--
-- if (peer)
-- return -EOPNOTSUPP;
--
-- uaddr->sa_family = AF_PACKET;
-- dev = dev_get_by_index(pkt_sk(sk)->ifindex);
-- if (dev) {
-- strlcpy(uaddr->sa_data, dev->name, 15);
-- dev_put(dev);
-- } else
-- memset(uaddr->sa_data, 0, 14);
-- *uaddr_len = sizeof(*uaddr);
--
-- return 0;
--}
--
--static int packet_getname(struct socket *sock, struct sockaddr *uaddr,
-- int *uaddr_len, int peer)
--{
-- struct net_device *dev;
-- struct sock *sk = sock->sk;
-- struct packet_sock *po = pkt_sk(sk);
-- struct sockaddr_ll *sll = (struct sockaddr_ll*)uaddr;
--
-- if (peer)
-- return -EOPNOTSUPP;
--
-- sll->sll_family = AF_PACKET;
-- sll->sll_ifindex = po->ifindex;
-- sll->sll_protocol = po->num;
-- dev = dev_get_by_index(po->ifindex);
-- if (dev) {
-- sll->sll_hatype = dev->type;
-- sll->sll_halen = dev->addr_len;
-- memcpy(sll->sll_addr, dev->dev_addr, dev->addr_len);
-- dev_put(dev);
-- } else {
-- sll->sll_hatype = 0; /* Bad: we have no ARPHRD_UNSPEC */
-- sll->sll_halen = 0;
-- }
-- *uaddr_len = offsetof(struct sockaddr_ll, sll_addr) + sll->sll_halen;
--
-- return 0;
--}
--
--static void packet_dev_mc(struct net_device *dev, struct packet_mclist *i, int what)
--{
-- switch (i->type) {
-- case PACKET_MR_MULTICAST:
-- if (what > 0)
-- dev_mc_add(dev, i->addr, i->alen, 0);
-- else
-- dev_mc_delete(dev, i->addr, i->alen, 0);
-- break;
-- case PACKET_MR_PROMISC:
-- dev_set_promiscuity(dev, what);
-- break;
-- case PACKET_MR_ALLMULTI:
-- dev_set_allmulti(dev, what);
-- break;
-- default:;
-- }
--}
--
--static void packet_dev_mclist(struct net_device *dev, struct packet_mclist *i, int what)
--{
-- for ( ; i; i=i->next) {
-- if (i->ifindex == dev->ifindex)
-- packet_dev_mc(dev, i, what);
-- }
--}
--
--static int packet_mc_add(struct sock *sk, struct packet_mreq_max *mreq)
--{
-- struct packet_sock *po = pkt_sk(sk);
-- struct packet_mclist *ml, *i;
-- struct net_device *dev;
-- int err;
--
-- rtnl_lock();
--
-- err = -ENODEV;
-- dev = __dev_get_by_index(mreq->mr_ifindex);
-- if (!dev)
-- goto done;
--
-- err = -EINVAL;
-- if (mreq->mr_alen > dev->addr_len)
-- goto done;
--
-- err = -ENOBUFS;
-- i = kmalloc(sizeof(*i), GFP_KERNEL);
-- if (i == NULL)
-- goto done;
--
-- err = 0;
-- for (ml = po->mclist; ml; ml = ml->next) {
-- if (ml->ifindex == mreq->mr_ifindex &&
-- ml->type == mreq->mr_type &&
-- ml->alen == mreq->mr_alen &&
-- memcmp(ml->addr, mreq->mr_address, ml->alen) == 0) {
-- ml->count++;
-- /* Free the new element ... */
-- kfree(i);
-- goto done;
-- }
-- }
--
-- i->type = mreq->mr_type;
-- i->ifindex = mreq->mr_ifindex;
-- i->alen = mreq->mr_alen;
-- memcpy(i->addr, mreq->mr_address, i->alen);
-- i->count = 1;
-- i->next = po->mclist;
-- po->mclist = i;
-- packet_dev_mc(dev, i, +1);
--
--done:
-- rtnl_unlock();
-- return err;
--}
--
--static int packet_mc_drop(struct sock *sk, struct packet_mreq_max *mreq)
--{
-- struct packet_mclist *ml, **mlp;
--
-- rtnl_lock();
--
-- for (mlp = &pkt_sk(sk)->mclist; (ml = *mlp) != NULL; mlp = &ml->next) {
-- if (ml->ifindex == mreq->mr_ifindex &&
-- ml->type == mreq->mr_type &&
-- ml->alen == mreq->mr_alen &&
-- memcmp(ml->addr, mreq->mr_address, ml->alen) == 0) {
-- if (--ml->count == 0) {
-- struct net_device *dev;
-- *mlp = ml->next;
-- dev = dev_get_by_index(ml->ifindex);
-- if (dev) {
-- packet_dev_mc(dev, ml, -1);
-- dev_put(dev);
-- }
-- kfree(ml);
-- }
-- rtnl_unlock();
-- return 0;
-- }
-- }
-- rtnl_unlock();
-- return -EADDRNOTAVAIL;
--}
--
--static void packet_flush_mclist(struct sock *sk)
--{
-- struct packet_sock *po = pkt_sk(sk);
-- struct packet_mclist *ml;
--
-- if (!po->mclist)
-- return;
--
-- rtnl_lock();
-- while ((ml = po->mclist) != NULL) {
-- struct net_device *dev;
--
-- po->mclist = ml->next;
-- if ((dev = dev_get_by_index(ml->ifindex)) != NULL) {
-- packet_dev_mc(dev, ml, -1);
-- dev_put(dev);
-- }
-- kfree(ml);
-- }
-- rtnl_unlock();
--}
--
--static int
--packet_setsockopt(struct socket *sock, int level, int optname, char __user *optval, int optlen)
--{
-- struct sock *sk = sock->sk;
-- struct packet_sock *po = pkt_sk(sk);
-- int ret;
--
-- if (level != SOL_PACKET)
-- return -ENOPROTOOPT;
--
-- switch(optname) {
-- case PACKET_ADD_MEMBERSHIP:
-- case PACKET_DROP_MEMBERSHIP:
-- {
-- struct packet_mreq_max mreq;
-- int len = optlen;
-- memset(&mreq, 0, sizeof(mreq));
-- if (len < sizeof(struct packet_mreq))
-- return -EINVAL;
-- if (len > sizeof(mreq))
-- len = sizeof(mreq);
-- if (copy_from_user(&mreq,optval,len))
-- return -EFAULT;
-- if (len < (mreq.mr_alen + offsetof(struct packet_mreq, mr_address)))
-- return -EINVAL;
-- if (optname == PACKET_ADD_MEMBERSHIP)
-- ret = packet_mc_add(sk, &mreq);
-- else
-- ret = packet_mc_drop(sk, &mreq);
-- return ret;
-- }
--
--#ifdef CONFIG_PACKET_MMAP
-- case PACKET_RX_RING:
-- {
-- struct tpacket_req req;
--
-- if (optlen<sizeof(req))
-- return -EINVAL;
-- if (copy_from_user(&req,optval,sizeof(req)))
-- return -EFAULT;
-- return packet_set_ring(sk, &req, 0);
-- }
-- case PACKET_COPY_THRESH:
-- {
-- int val;
--
-- if (optlen!=sizeof(val))
-- return -EINVAL;
-- if (copy_from_user(&val,optval,sizeof(val)))
-- return -EFAULT;
--
-- pkt_sk(sk)->copy_thresh = val;
-- return 0;
-- }
--#endif
-- case PACKET_AUXDATA:
-- {
-- int val;
--
-- if (optlen < sizeof(val))
-- return -EINVAL;
-- if (copy_from_user(&val, optval, sizeof(val)))
-- return -EFAULT;
--
-- po->auxdata = !!val;
-- return 0;
-- }
-- case PACKET_ORIGDEV:
-- {
-- int val;
--
-- if (optlen < sizeof(val))
-- return -EINVAL;
-- if (copy_from_user(&val, optval, sizeof(val)))
-- return -EFAULT;
--
-- po->origdev = !!val;
-- return 0;
-- }
-- default:
-- return -ENOPROTOOPT;
-- }
--}
--
--static int packet_getsockopt(struct socket *sock, int level, int optname,
-- char __user *optval, int __user *optlen)
--{
-- int len;
-- int val;
-- struct sock *sk = sock->sk;
-- struct packet_sock *po = pkt_sk(sk);
-- void *data;
-- struct tpacket_stats st;
--
-- if (level != SOL_PACKET)
-- return -ENOPROTOOPT;
--
-- if (get_user(len, optlen))
-- return -EFAULT;
--
-- if (len < 0)
-- return -EINVAL;
--
-- switch(optname) {
-- case PACKET_STATISTICS:
-- if (len > sizeof(struct tpacket_stats))
-- len = sizeof(struct tpacket_stats);
-- spin_lock_bh(&sk->sk_receive_queue.lock);
-- st = po->stats;
-- memset(&po->stats, 0, sizeof(st));
-- spin_unlock_bh(&sk->sk_receive_queue.lock);
-- st.tp_packets += st.tp_drops;
--
-- data = &st;
-- break;
-- case PACKET_AUXDATA:
-- if (len > sizeof(int))
-- len = sizeof(int);
-- val = po->auxdata;
--
-- data = &val;
-- break;
-- case PACKET_ORIGDEV:
-- if (len > sizeof(int))
-- len = sizeof(int);
-- val = po->origdev;
--
-- data = &val;
-- break;
-- default:
-- return -ENOPROTOOPT;
-- }
--
-- if (put_user(len, optlen))
-- return -EFAULT;
-- if (copy_to_user(optval, data, len))
-- return -EFAULT;
-- return 0;
--}
--
--
--static int packet_notifier(struct notifier_block *this, unsigned long msg, void *data)
--{
-- struct sock *sk;
-- struct hlist_node *node;
-- struct net_device *dev = data;
--
-- read_lock(&packet_sklist_lock);
-- sk_for_each(sk, node, &packet_sklist) {
-- struct packet_sock *po = pkt_sk(sk);
--
-- switch (msg) {
-- case NETDEV_UNREGISTER:
-- if (po->mclist)
-- packet_dev_mclist(dev, po->mclist, -1);
-- /* fallthrough */
--
-- case NETDEV_DOWN:
-- if (dev->ifindex == po->ifindex) {
-- spin_lock(&po->bind_lock);
-- if (po->running) {
-- __dev_remove_pack(&po->prot_hook);
-- __sock_put(sk);
-- po->running = 0;
-- sk->sk_err = ENETDOWN;
-- if (!sock_flag(sk, SOCK_DEAD))
-- sk->sk_error_report(sk);
-- }
-- if (msg == NETDEV_UNREGISTER) {
-- po->ifindex = -1;
-- po->prot_hook.dev = NULL;
-- }
-- spin_unlock(&po->bind_lock);
-- }
-- break;
-- case NETDEV_UP:
-- spin_lock(&po->bind_lock);
-- if (dev->ifindex == po->ifindex && po->num &&
-- !po->running) {
-- dev_add_pack(&po->prot_hook);
-- sock_hold(sk);
-- po->running = 1;
-- }
-- spin_unlock(&po->bind_lock);
-- break;
-- }
-- }
-- read_unlock(&packet_sklist_lock);
-- return NOTIFY_DONE;
--}
--
--
--static int packet_ioctl(struct socket *sock, unsigned int cmd,
-- unsigned long arg)
--{
-- struct sock *sk = sock->sk;
--
-- switch(cmd) {
-- case SIOCOUTQ:
-- {
-- int amount = atomic_read(&sk->sk_wmem_alloc);
-- return put_user(amount, (int __user *)arg);
-- }
-- case SIOCINQ:
-- {
-- struct sk_buff *skb;
-- int amount = 0;
--
-- spin_lock_bh(&sk->sk_receive_queue.lock);
-- skb = skb_peek(&sk->sk_receive_queue);
-- if (skb)
-- amount = skb->len;
-- spin_unlock_bh(&sk->sk_receive_queue.lock);
-- return put_user(amount, (int __user *)arg);
-- }
-- case SIOCGSTAMP:
-- return sock_get_timestamp(sk, (struct timeval __user *)arg);
-- case SIOCGSTAMPNS:
-- return sock_get_timestampns(sk, (struct timespec __user *)arg);
--
--#ifdef CONFIG_INET
-- case SIOCADDRT:
-- case SIOCDELRT:
-- case SIOCDARP:
-- case SIOCGARP:
-- case SIOCSARP:
-- case SIOCGIFADDR:
-- case SIOCSIFADDR:
-- case SIOCGIFBRDADDR:
-- case SIOCSIFBRDADDR:
-- case SIOCGIFNETMASK:
-- case SIOCSIFNETMASK:
-- case SIOCGIFDSTADDR:
-- case SIOCSIFDSTADDR:
-- case SIOCSIFFLAGS:
-- return inet_dgram_ops.ioctl(sock, cmd, arg);
--#endif
--
-- default:
-- return -ENOIOCTLCMD;
-- }
-- return 0;
--}
--
--#ifndef CONFIG_PACKET_MMAP
--#define packet_mmap sock_no_mmap
--#define packet_poll datagram_poll
--#else
--
--static unsigned int packet_poll(struct file * file, struct socket *sock,
-- poll_table *wait)
--{
-- struct sock *sk = sock->sk;
-- struct packet_sock *po = pkt_sk(sk);
-- unsigned int mask = datagram_poll(file, sock, wait);
--
-- spin_lock_bh(&sk->sk_receive_queue.lock);
-- if (po->pg_vec) {
-- unsigned last = po->head ? po->head-1 : po->frame_max;
-- struct tpacket_hdr *h;
--
-- h = packet_lookup_frame(po, last);
--
-- if (h->tp_status)
-- mask |= POLLIN | POLLRDNORM;
-- }
-- spin_unlock_bh(&sk->sk_receive_queue.lock);
-- return mask;
--}
--
--
--/* Dirty? Well, I still did not learn better way to account
-- * for user mmaps.
-- */
--
--static void packet_mm_open(struct vm_area_struct *vma)
--{
-- struct file *file = vma->vm_file;
-- struct socket * sock = file->private_data;
-- struct sock *sk = sock->sk;
--
-- if (sk)
-- atomic_inc(&pkt_sk(sk)->mapped);
--}
--
--static void packet_mm_close(struct vm_area_struct *vma)
--{
-- struct file *file = vma->vm_file;
-- struct socket * sock = file->private_data;
-- struct sock *sk = sock->sk;
--
-- if (sk)
-- atomic_dec(&pkt_sk(sk)->mapped);
--}
--
--static struct vm_operations_struct packet_mmap_ops = {
-- .open = packet_mm_open,
-- .close =packet_mm_close,
--};
--
--static inline struct page *pg_vec_endpage(char *one_pg_vec, unsigned int order)
--{
-- return virt_to_page(one_pg_vec + (PAGE_SIZE << order) - 1);
--}
--
--static void free_pg_vec(char **pg_vec, unsigned int order, unsigned int len)
--{
-- int i;
--
-- for (i = 0; i < len; i++) {
-- if (likely(pg_vec[i]))
-- free_pages((unsigned long) pg_vec[i], order);
-- }
-- kfree(pg_vec);
--}
--
--static inline char *alloc_one_pg_vec_page(unsigned long order)
--{
-- return (char *) __get_free_pages(GFP_KERNEL | __GFP_COMP | __GFP_ZERO,
-- order);
--}
--
--static char **alloc_pg_vec(struct tpacket_req *req, int order)
--{
-- unsigned int block_nr = req->tp_block_nr;
-- char **pg_vec;
-- int i;
--
-- pg_vec = kzalloc(block_nr * sizeof(char *), GFP_KERNEL);
-- if (unlikely(!pg_vec))
-- goto out;
--
-- for (i = 0; i < block_nr; i++) {
-- pg_vec[i] = alloc_one_pg_vec_page(order);
-- if (unlikely(!pg_vec[i]))
-- goto out_free_pgvec;
-- }
--
--out:
-- return pg_vec;
--
--out_free_pgvec:
-- free_pg_vec(pg_vec, order, block_nr);
-- pg_vec = NULL;
-- goto out;
--}
--
--static int packet_set_ring(struct sock *sk, struct tpacket_req *req, int closing)
--{
-- char **pg_vec = NULL;
-- struct packet_sock *po = pkt_sk(sk);
-- int was_running, order = 0;
-- __be16 num;
-- int err = 0;
--
-- if (req->tp_block_nr) {
-- int i, l;
--
-- /* Sanity tests and some calculations */
--
-- if (unlikely(po->pg_vec))
-- return -EBUSY;
--
-- if (unlikely((int)req->tp_block_size <= 0))
-- return -EINVAL;
-- if (unlikely(req->tp_block_size & (PAGE_SIZE - 1)))
-- return -EINVAL;
-- if (unlikely(req->tp_frame_size < TPACKET_HDRLEN))
-- return -EINVAL;
-- if (unlikely(req->tp_frame_size & (TPACKET_ALIGNMENT - 1)))
-- return -EINVAL;
--
-- po->frames_per_block = req->tp_block_size/req->tp_frame_size;
-- if (unlikely(po->frames_per_block <= 0))
-- return -EINVAL;
-- if (unlikely((po->frames_per_block * req->tp_block_nr) !=
-- req->tp_frame_nr))
-- return -EINVAL;
--
-- err = -ENOMEM;
-- order = get_order(req->tp_block_size);
-- pg_vec = alloc_pg_vec(req, order);
-- if (unlikely(!pg_vec))
-- goto out;
--
-- l = 0;
-- for (i = 0; i < req->tp_block_nr; i++) {
-- char *ptr = pg_vec[i];
-- struct tpacket_hdr *header;
-- int k;
--
-- for (k = 0; k < po->frames_per_block; k++) {
-- header = (struct tpacket_hdr *) ptr;
-- header->tp_status = TP_STATUS_KERNEL;
-- ptr += req->tp_frame_size;
-- }
-- }
-- /* Done */
-- } else {
-- if (unlikely(req->tp_frame_nr))
-- return -EINVAL;
-- }
--
-- lock_sock(sk);
--
-- /* Detach socket from network */
-- spin_lock(&po->bind_lock);
-- was_running = po->running;
-- num = po->num;
-- if (was_running) {
-- __dev_remove_pack(&po->prot_hook);
-- po->num = 0;
-- po->running = 0;
-- __sock_put(sk);
-- }
-- spin_unlock(&po->bind_lock);
--
-- synchronize_net();
--
-- err = -EBUSY;
-- if (closing || atomic_read(&po->mapped) == 0) {
-- err = 0;
--#define XC(a, b) ({ __typeof__ ((a)) __t; __t = (a); (a) = (b); __t; })
--
-- spin_lock_bh(&sk->sk_receive_queue.lock);
-- pg_vec = XC(po->pg_vec, pg_vec);
-- po->frame_max = (req->tp_frame_nr - 1);
-- po->head = 0;
-- po->frame_size = req->tp_frame_size;
-- spin_unlock_bh(&sk->sk_receive_queue.lock);
--
-- order = XC(po->pg_vec_order, order);
-- req->tp_block_nr = XC(po->pg_vec_len, req->tp_block_nr);
--
-- po->pg_vec_pages = req->tp_block_size/PAGE_SIZE;
-- po->prot_hook.func = po->pg_vec ? tpacket_rcv : packet_rcv;
-- skb_queue_purge(&sk->sk_receive_queue);
--#undef XC
-- if (atomic_read(&po->mapped))
-- printk(KERN_DEBUG "packet_mmap: vma is busy: %d\n", atomic_read(&po->mapped));
-- }
--
-- spin_lock(&po->bind_lock);
-- if (was_running && !po->running) {
-- sock_hold(sk);
-- po->running = 1;
-- po->num = num;
-- dev_add_pack(&po->prot_hook);
-- }
-- spin_unlock(&po->bind_lock);
--
-- release_sock(sk);
--
-- if (pg_vec)
-- free_pg_vec(pg_vec, order, req->tp_block_nr);
--out:
-- return err;
--}
--
--static int packet_mmap(struct file *file, struct socket *sock, struct vm_area_struct *vma)
--{
-- struct sock *sk = sock->sk;
-- struct packet_sock *po = pkt_sk(sk);
-- unsigned long size;
-- unsigned long start;
-- int err = -EINVAL;
-- int i;
--
-- if (vma->vm_pgoff)
-- return -EINVAL;
--
-- size = vma->vm_end - vma->vm_start;
--
-- lock_sock(sk);
-- if (po->pg_vec == NULL)
-- goto out;
-- if (size != po->pg_vec_len*po->pg_vec_pages*PAGE_SIZE)
-- goto out;
--
-- start = vma->vm_start;
-- for (i = 0; i < po->pg_vec_len; i++) {
-- struct page *page = virt_to_page(po->pg_vec[i]);
-- int pg_num;
--
-- for (pg_num = 0; pg_num < po->pg_vec_pages; pg_num++, page++) {
-- err = vm_insert_page(vma, start, page);
-- if (unlikely(err))
-- goto out;
-- start += PAGE_SIZE;
-- }
-- }
-- atomic_inc(&po->mapped);
-- vma->vm_ops = &packet_mmap_ops;
-- err = 0;
--
--out:
-- release_sock(sk);
-- return err;
--}
--#endif
--
--
--static const struct proto_ops packet_ops_spkt = {
-- .family = PF_PACKET,
-- .owner = THIS_MODULE,
-- .release = packet_release,
-- .bind = packet_bind_spkt,
-- .connect = sock_no_connect,
-- .socketpair = sock_no_socketpair,
-- .accept = sock_no_accept,
-- .getname = packet_getname_spkt,
-- .poll = datagram_poll,
-- .ioctl = packet_ioctl,
-- .listen = sock_no_listen,
-- .shutdown = sock_no_shutdown,
-- .setsockopt = sock_no_setsockopt,
-- .getsockopt = sock_no_getsockopt,
-- .sendmsg = packet_sendmsg_spkt,
-- .recvmsg = packet_recvmsg,
-- .mmap = sock_no_mmap,
-- .sendpage = sock_no_sendpage,
--};
--
--static const struct proto_ops packet_ops = {
-- .family = PF_PACKET,
-- .owner = THIS_MODULE,
-- .release = packet_release,
-- .bind = packet_bind,
-- .connect = sock_no_connect,
-- .socketpair = sock_no_socketpair,
-- .accept = sock_no_accept,
-- .getname = packet_getname,
-- .poll = packet_poll,
-- .ioctl = packet_ioctl,
-- .listen = sock_no_listen,
-- .shutdown = sock_no_shutdown,
-- .setsockopt = packet_setsockopt,
-- .getsockopt = packet_getsockopt,
-- .sendmsg = packet_sendmsg,
-- .recvmsg = packet_recvmsg,
-- .mmap = packet_mmap,
-- .sendpage = sock_no_sendpage,
--};
--
--static struct net_proto_family packet_family_ops = {
-- .family = PF_PACKET,
-- .create = packet_create,
-- .owner = THIS_MODULE,
--};
--
--static struct notifier_block packet_netdev_notifier = {
-- .notifier_call =packet_notifier,
--};
--
--#ifdef CONFIG_PROC_FS
--static inline struct sock *packet_seq_idx(loff_t off)
--{
-- struct sock *s;
-- struct hlist_node *node;
--
-- sk_for_each(s, node, &packet_sklist) {
-- if (!off--)
-- return s;
-- }
-- return NULL;
--}
--
--static void *packet_seq_start(struct seq_file *seq, loff_t *pos)
--{
-- read_lock(&packet_sklist_lock);
-- return *pos ? packet_seq_idx(*pos - 1) : SEQ_START_TOKEN;
--}
--
--static void *packet_seq_next(struct seq_file *seq, void *v, loff_t *pos)
--{
-- ++*pos;
-- return (v == SEQ_START_TOKEN)
-- ? sk_head(&packet_sklist)
-- : sk_next((struct sock*)v) ;
--}
--
--static void packet_seq_stop(struct seq_file *seq, void *v)
--{
-- read_unlock(&packet_sklist_lock);
--}
--
--static int packet_seq_show(struct seq_file *seq, void *v)
--{
-- if (v == SEQ_START_TOKEN)
-- seq_puts(seq, "sk RefCnt Type Proto Iface R Rmem User Inode\n");
-- else {
-- struct sock *s = v;
-- const struct packet_sock *po = pkt_sk(s);
--
-- seq_printf(seq,
-- "%p %-6d %-4d %04x %-5d %1d %-6u %-6u %-6lu\n",
-- s,
-- atomic_read(&s->sk_refcnt),
-- s->sk_type,
-- ntohs(po->num),
-- po->ifindex,
-- po->running,
-- atomic_read(&s->sk_rmem_alloc),
-- sock_i_uid(s),
-- sock_i_ino(s) );
-- }
--
-- return 0;
--}
--
--static struct seq_operations packet_seq_ops = {
-- .start = packet_seq_start,
-- .next = packet_seq_next,
-- .stop = packet_seq_stop,
-- .show = packet_seq_show,
--};
--
--static int packet_seq_open(struct inode *inode, struct file *file)
--{
-- return seq_open(file, &packet_seq_ops);
--}
--
--static const struct file_operations packet_seq_fops = {
-- .owner = THIS_MODULE,
-- .open = packet_seq_open,
-- .read = seq_read,
-- .llseek = seq_lseek,
-- .release = seq_release,
--};
--
--#endif
--
--static void __exit packet_exit(void)
--{
-- proc_net_remove("packet");
-- unregister_netdevice_notifier(&packet_netdev_notifier);
-- sock_unregister(PF_PACKET);
-- proto_unregister(&packet_proto);
--}
--
--static int __init packet_init(void)
--{
-- int rc = proto_register(&packet_proto, 0);
--
-- if (rc != 0)
-- goto out;
--
-- sock_register(&packet_family_ops);
-- register_netdevice_notifier(&packet_netdev_notifier);
-- proc_net_fops_create("packet", 0, &packet_seq_fops);
--out:
-- return rc;
--}
--
--module_init(packet_init);
--module_exit(packet_exit);
--MODULE_LICENSE("GPL");
--MODULE_ALIAS_NETPROTO(PF_PACKET);
-diff -Nurb linux-2.6.22-594/net/socket.c linux-2.6.22-595/net/socket.c
---- linux-2.6.22-594/net/socket.c 2008-03-20 00:05:19.000000000 -0400
-+++ linux-2.6.22-595/net/socket.c 2008-03-20 00:14:03.000000000 -0400
-@@ -1122,12 +1122,17 @@
- if (type < 0 || type >= SOCK_MAX)
- return -EINVAL;
-
-+ /*
-+ * Hack no. 2 - Sapan
-+ * Clean this up later
-+ *
- if (!nx_check(0, VS_ADMIN)) {
- if (family == PF_INET && !current_nx_info_has_v4())
- return -EAFNOSUPPORT;
- if (family == PF_INET6 && !current_nx_info_has_v6())
- return -EAFNOSUPPORT;
- }
-+ */
-
- /* Compatibility.
-
-diff -Nurb linux-2.6.22-594/net/socket.c.orig linux-2.6.22-595/net/socket.c.orig
---- linux-2.6.22-594/net/socket.c.orig 1969-12-31 19:00:00.000000000 -0500
-+++ linux-2.6.22-595/net/socket.c.orig 2008-03-20 00:05:19.000000000 -0400
-@@ -0,0 +1,2400 @@
-+/*
-+ * NET An implementation of the SOCKET network access protocol.
-+ *
-+ * Version: @(#)socket.c 1.1.93 18/02/95
-+ *
-+ * Authors: Orest Zborowski, <obz@Kodak.COM>
-+ * Ross Biro
-+ * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
-+ *
-+ * Fixes:
-+ * Anonymous : NOTSOCK/BADF cleanup. Error fix in
-+ * shutdown()
-+ * Alan Cox : verify_area() fixes
-+ * Alan Cox : Removed DDI
-+ * Jonathan Kamens : SOCK_DGRAM reconnect bug
-+ * Alan Cox : Moved a load of checks to the very
-+ * top level.
-+ * Alan Cox : Move address structures to/from user
-+ * mode above the protocol layers.
-+ * Rob Janssen : Allow 0 length sends.
-+ * Alan Cox : Asynchronous I/O support (cribbed from the
-+ * tty drivers).
-+ * Niibe Yutaka : Asynchronous I/O for writes (4.4BSD style)
-+ * Jeff Uphoff : Made max number of sockets command-line
-+ * configurable.
-+ * Matti Aarnio : Made the number of sockets dynamic,
-+ * to be allocated when needed, and mr.
-+ * Uphoff's max is used as max to be
-+ * allowed to allocate.
-+ * Linus : Argh. removed all the socket allocation
-+ * altogether: it's in the inode now.
-+ * Alan Cox : Made sock_alloc()/sock_release() public
-+ * for NetROM and future kernel nfsd type
-+ * stuff.
-+ * Alan Cox : sendmsg/recvmsg basics.
-+ * Tom Dyas : Export net symbols.
-+ * Marcin Dalecki : Fixed problems with CONFIG_NET="n".
-+ * Alan Cox : Added thread locking to sys_* calls
-+ * for sockets. May have errors at the
-+ * moment.
-+ * Kevin Buhr : Fixed the dumb errors in the above.
-+ * Andi Kleen : Some small cleanups, optimizations,
-+ * and fixed a copy_from_user() bug.
-+ * Tigran Aivazian : sys_send(args) calls sys_sendto(args, NULL, 0)
-+ * Tigran Aivazian : Made listen(2) backlog sanity checks
-+ * protocol-independent
-+ *
-+ *
-+ * This program is free software; you can redistribute it and/or
-+ * modify it under the terms of the GNU General Public License
-+ * as published by the Free Software Foundation; either version
-+ * 2 of the License, or (at your option) any later version.
-+ *
-+ *
-+ * This module is effectively the top level interface to the BSD socket
-+ * paradigm.
-+ *
-+ * Based upon Swansea University Computer Society NET3.039
-+ */
-+
-+#include <linux/mm.h>
-+#include <linux/socket.h>
-+#include <linux/file.h>
-+#include <linux/net.h>
-+#include <linux/interrupt.h>
-+#include <linux/rcupdate.h>
-+#include <linux/netdevice.h>
-+#include <linux/proc_fs.h>
-+#include <linux/seq_file.h>
-+#include <linux/mutex.h>
-+#include <linux/wanrouter.h>
-+#include <linux/if_bridge.h>
-+#include <linux/if_frad.h>
-+#include <linux/if_vlan.h>
-+#include <linux/init.h>
-+#include <linux/poll.h>
-+#include <linux/cache.h>
-+#include <linux/module.h>
-+#include <linux/highmem.h>
-+#include <linux/mount.h>
-+#include <linux/security.h>
-+#include <linux/syscalls.h>
-+#include <linux/compat.h>
-+#include <linux/kmod.h>
-+#include <linux/audit.h>
-+#include <linux/wireless.h>
-+#include <linux/nsproxy.h>
-+
-+#include <asm/uaccess.h>
-+#include <asm/unistd.h>
-+
-+#include <net/compat.h>
-+
-+#include <net/sock.h>
-+#include <linux/netfilter.h>
-+#include <linux/vs_base.h>
-+#include <linux/vs_socket.h>
-+#include <linux/vs_inet.h>
-+#include <linux/vs_inet6.h>
-+
-+static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
-+static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
-+ unsigned long nr_segs, loff_t pos);
-+static ssize_t sock_aio_write(struct kiocb *iocb, const struct iovec *iov,
-+ unsigned long nr_segs, loff_t pos);
-+static int sock_mmap(struct file *file, struct vm_area_struct *vma);
-+
-+static int sock_close(struct inode *inode, struct file *file);
-+static unsigned int sock_poll(struct file *file,
-+ struct poll_table_struct *wait);
-+static long sock_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
-+#ifdef CONFIG_COMPAT
-+static long compat_sock_ioctl(struct file *file,
-+ unsigned int cmd, unsigned long arg);
-+#endif
-+static int sock_fasync(int fd, struct file *filp, int on);
-+static ssize_t sock_sendpage(struct file *file, struct page *page,
-+ int offset, size_t size, loff_t *ppos, int more);
-+
-+/*
-+ * Socket files have a set of 'special' operations as well as the generic file ones. These don't appear
-+ * in the operation structures but are done directly via the socketcall() multiplexor.
-+ */
-+
-+static const struct file_operations socket_file_ops = {
-+ .owner = THIS_MODULE,
-+ .llseek = no_llseek,
-+ .aio_read = sock_aio_read,
-+ .aio_write = sock_aio_write,
-+ .poll = sock_poll,
-+ .unlocked_ioctl = sock_ioctl,
-+#ifdef CONFIG_COMPAT
-+ .compat_ioctl = compat_sock_ioctl,
-+#endif
-+ .mmap = sock_mmap,
-+ .open = sock_no_open, /* special open code to disallow open via /proc */
-+ .release = sock_close,
-+ .fasync = sock_fasync,
-+ .sendpage = sock_sendpage,
-+ .splice_write = generic_splice_sendpage,
-+};
-+
-+/*
-+ * The protocol list. Each protocol is registered in here.
-+ */
-+
-+static DEFINE_SPINLOCK(net_family_lock);
-+static const struct net_proto_family *net_families[NPROTO] __read_mostly;
-+
-+/*
-+ * Statistics counters of the socket lists
-+ */
-+
-+static DEFINE_PER_CPU(int, sockets_in_use) = 0;
-+
-+/*
-+ * Support routines.
-+ * Move socket addresses back and forth across the kernel/user
-+ * divide and look after the messy bits.
-+ */
-+
-+#define MAX_SOCK_ADDR 128 /* 108 for Unix domain -
-+ 16 for IP, 16 for IPX,
-+ 24 for IPv6,
-+ about 80 for AX.25
-+ must be at least one bigger than
-+ the AF_UNIX size (see net/unix/af_unix.c
-+ :unix_mkname()).
-+ */
-+
-+/**
-+ * move_addr_to_kernel - copy a socket address into kernel space
-+ * @uaddr: Address in user space
-+ * @kaddr: Address in kernel space
-+ * @ulen: Length in user space
-+ *
-+ * The address is copied into kernel space. If the provided address is
-+ * too long an error code of -EINVAL is returned. If the copy gives
-+ * invalid addresses -EFAULT is returned. On a success 0 is returned.
-+ */
-+
-+int move_addr_to_kernel(void __user *uaddr, int ulen, void *kaddr)
-+{
-+ if (ulen < 0 || ulen > MAX_SOCK_ADDR)
-+ return -EINVAL;
-+ if (ulen == 0)
-+ return 0;
-+ if (copy_from_user(kaddr, uaddr, ulen))
-+ return -EFAULT;
-+ return audit_sockaddr(ulen, kaddr);
-+}
-+
-+/**
-+ * move_addr_to_user - copy an address to user space
-+ * @kaddr: kernel space address
-+ * @klen: length of address in kernel
-+ * @uaddr: user space address
-+ * @ulen: pointer to user length field
-+ *
-+ * The value pointed to by ulen on entry is the buffer length available.
-+ * This is overwritten with the buffer space used. -EINVAL is returned
-+ * if an overlong buffer is specified or a negative buffer size. -EFAULT
-+ * is returned if either the buffer or the length field are not
-+ * accessible.
-+ * After copying the data up to the limit the user specifies, the true
-+ * length of the data is written over the length limit the user
-+ * specified. Zero is returned for a success.
-+ */
-+
-+int move_addr_to_user(void *kaddr, int klen, void __user *uaddr,
-+ int __user *ulen)
-+{
-+ int err;
-+ int len;
-+
-+ err = get_user(len, ulen);
-+ if (err)
-+ return err;
-+ if (len > klen)
-+ len = klen;
-+ if (len < 0 || len > MAX_SOCK_ADDR)
-+ return -EINVAL;
-+ if (len) {
-+ if (audit_sockaddr(klen, kaddr))
-+ return -ENOMEM;
-+ if (copy_to_user(uaddr, kaddr, len))
-+ return -EFAULT;
-+ }
-+ /*
-+ * "fromlen shall refer to the value before truncation.."
-+ * 1003.1g
-+ */
-+ return __put_user(klen, ulen);
-+}
-+
-+#define SOCKFS_MAGIC 0x534F434B
-+
-+static struct kmem_cache *sock_inode_cachep __read_mostly;
-+
-+static struct inode *sock_alloc_inode(struct super_block *sb)
-+{
-+ struct socket_alloc *ei;
-+
-+ ei = kmem_cache_alloc(sock_inode_cachep, GFP_KERNEL);
-+ if (!ei)
-+ return NULL;
-+ init_waitqueue_head(&ei->socket.wait);