Fixed repo
[linux-2.6.git] / linux-2.6-595-vserver-new-netns.patch
1 diff -Nurb linux-2.6.22-594/include/linux/vserver/network.h.orig.orig linux-2.6.22-595/include/linux/vserver/network.h.orig.orig
2 --- linux-2.6.22-594/include/linux/vserver/network.h.orig.orig  2008-03-20 01:27:27.000000000 -0400
3 +++ linux-2.6.22-595/include/linux/vserver/network.h.orig.orig  1969-12-31 19:00:00.000000000 -0500
4 @@ -1,143 +0,0 @@
5 -#ifndef _VX_NETWORK_H
6 -#define _VX_NETWORK_H
7 -
8 -#include <linux/types.h>
9 -
10 -
11 -#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12 -
13 -
14 -/* network flags */
15 -
16 -#define NXF_INFO_PRIVATE       0x00000008
17 -
18 -#define NXF_SINGLE_IP          0x00000100
19 -#define NXF_LBACK_REMAP                0x00000200
20 -
21 -#define NXF_HIDE_NETIF         0x02000000
22 -#define NXF_HIDE_LBACK         0x04000000
23 -
24 -#define NXF_STATE_SETUP                (1ULL << 32)
25 -#define NXF_STATE_ADMIN                (1ULL << 34)
26 -
27 -#define NXF_SC_HELPER          (1ULL << 36)
28 -#define NXF_PERSISTENT         (1ULL << 38)
29 -
30 -#define NXF_ONE_TIME           (0x0005ULL << 32)
31 -
32 -
33 -#define        NXF_INIT_SET            (__nxf_init_set())
34 -
35 -static inline uint64_t __nxf_init_set(void) {
36 -       return    NXF_STATE_ADMIN
37 -#ifdef CONFIG_VSERVER_AUTO_LBACK
38 -               | NXF_LBACK_REMAP
39 -               | NXF_HIDE_LBACK
40 -#endif
41 -#ifdef CONFIG_VSERVER_AUTO_SINGLE
42 -               | NXF_SINGLE_IP
43 -#endif
44 -               | NXF_HIDE_NETIF;
45 -}
46 -
47 -
48 -/* network caps */
49 -
50 -#define NXC_RAW_ICMP           0x00000100
51 -
52 -
53 -/* address types */
54 -
55 -#define NXA_TYPE_IPV4          0x0001
56 -#define NXA_TYPE_IPV6          0x0002
57 -
58 -#define NXA_TYPE_NONE          0x0000
59 -#define NXA_TYPE_ANY           0x00FF
60 -
61 -#define NXA_TYPE_ADDR          0x0010
62 -#define NXA_TYPE_MASK          0x0020
63 -#define NXA_TYPE_RANGE         0x0040
64 -
65 -#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
66 -
67 -#define NXA_MOD_BCAST          0x0100
68 -#define NXA_MOD_LBACK          0x0200
69 -
70 -#define NXA_LOOPBACK           0x1000
71 -
72 -#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
73 -#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
74 -
75 -#ifdef __KERNEL__
76 -
77 -#include <linux/list.h>
78 -#include <linux/spinlock.h>
79 -#include <linux/rcupdate.h>
80 -#include <linux/in.h>
81 -#include <linux/in6.h>
82 -#include <asm/atomic.h>
83 -
84 -struct nx_addr_v4 {
85 -       struct nx_addr_v4 *next;
86 -       struct in_addr ip[2];
87 -       struct in_addr mask;
88 -       uint16_t type;
89 -       uint16_t flags;
90 -};
91 -
92 -struct nx_addr_v6 {
93 -       struct nx_addr_v6 *next;
94 -       struct in6_addr ip;
95 -       struct in6_addr mask;
96 -       uint32_t prefix;
97 -       uint16_t type;
98 -       uint16_t flags;
99 -};
100 -
101 -struct nx_info {
102 -       struct hlist_node nx_hlist;     /* linked list of nxinfos */
103 -       nid_t nx_id;                    /* vnet id */
104 -       atomic_t nx_usecnt;             /* usage count */
105 -       atomic_t nx_tasks;              /* tasks count */
106 -       int nx_state;                   /* context state */
107 -
108 -       uint64_t nx_flags;              /* network flag word */
109 -       uint64_t nx_ncaps;              /* network capabilities */
110 -
111 -       struct in_addr v4_lback;        /* Loopback address */
112 -       struct in_addr v4_bcast;        /* Broadcast address */
113 -       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
114 -#ifdef CONFIG_IPV6
115 -       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
116 -#endif
117 -       char nx_name[65];               /* network context name */
118 -};
119 -
120 -
121 -/* status flags */
122 -
123 -#define NXS_HASHED      0x0001
124 -#define NXS_SHUTDOWN    0x0100
125 -#define NXS_RELEASED    0x8000
126 -
127 -extern struct nx_info *lookup_nx_info(int);
128 -
129 -extern int get_nid_list(int, unsigned int *, int);
130 -extern int nid_is_hashed(nid_t);
131 -
132 -extern int nx_migrate_task(struct task_struct *, struct nx_info *);
133 -
134 -extern long vs_net_change(struct nx_info *, unsigned int);
135 -
136 -struct sock;
137 -
138 -
139 -#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
140 -#ifdef  CONFIG_IPV6
141 -#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
142 -#else
143 -#define NX_IPV6(n)     (0)
144 -#endif
145 -
146 -#endif /* __KERNEL__ */
147 -#endif /* _VX_NETWORK_H */
148 diff -Nurb linux-2.6.22-594/kernel/nsproxy.c.orig linux-2.6.22-595/kernel/nsproxy.c.orig
149 --- linux-2.6.22-594/kernel/nsproxy.c.orig      2008-03-20 01:27:50.000000000 -0400
150 +++ linux-2.6.22-595/kernel/nsproxy.c.orig      1969-12-31 19:00:00.000000000 -0500
151 @@ -1,264 +0,0 @@
152 -/*
153 - *  Copyright (C) 2006 IBM Corporation
154 - *
155 - *  Author: Serge Hallyn <serue@us.ibm.com>
156 - *
157 - *  This program is free software; you can redistribute it and/or
158 - *  modify it under the terms of the GNU General Public License as
159 - *  published by the Free Software Foundation, version 2 of the
160 - *  License.
161 - *
162 - *  Jun 2006 - namespaces support
163 - *             OpenVZ, SWsoft Inc.
164 - *             Pavel Emelianov <xemul@openvz.org>
165 - */
166 -
167 -#include <linux/module.h>
168 -#include <linux/version.h>
169 -#include <linux/nsproxy.h>
170 -#include <linux/init_task.h>
171 -#include <linux/mnt_namespace.h>
172 -#include <linux/utsname.h>
173 -#include <net/net_namespace.h>
174 -#include <linux/pid_namespace.h>
175 -#include <linux/vserver/global.h>
176 -#include <linux/vserver/debug.h>
177 -
178 -static struct kmem_cache *nsproxy_cachep;
179 -
180 -struct nsproxy init_nsproxy = INIT_NSPROXY(init_nsproxy);
181 -
182 -void get_task_namespaces(struct task_struct *tsk)
183 -{
184 -       struct nsproxy *ns = tsk->nsproxy;
185 -       if (ns) {
186 -               get_nsproxy(ns);
187 -       }
188 -}
189 -
190 -/*
191 - * creates a copy of "orig" with refcount 1.
192 - */
193 -static inline struct nsproxy *clone_nsproxy(struct nsproxy *orig)
194 -{
195 -       struct nsproxy *ns;
196 -
197 -       ns = kmemdup(orig, sizeof(struct nsproxy), GFP_KERNEL);
198 -       if (ns)
199 -               atomic_set(&ns->count, 1);
200 -       vxdprintk(VXD_CBIT(space, 2), "clone_nsproxy(%p[%u] = %p[1]",
201 -               orig, atomic_read(&orig->count), ns);
202 -       atomic_inc(&vs_global_nsproxy);
203 -       return ns;
204 -}
205 -
206 -/*
207 - * Create new nsproxy and all of its the associated namespaces.
208 - * Return the newly created nsproxy.  Do not attach this to the task,
209 - * leave it to the caller to do proper locking and attach it to task.
210 - */
211 -static struct nsproxy *unshare_namespaces(int flags, struct nsproxy *orig,
212 -                       struct fs_struct *new_fs)
213 -{
214 -       struct nsproxy *new_nsp;
215 -       int err = -ENOMEM;
216 -
217 -       vxdprintk(VXD_CBIT(space, 4),
218 -               "unshare_namespaces(0x%08x,%p,%p)",
219 -               flags, orig, new_fs);
220 -
221 -       new_nsp = clone_nsproxy(orig);
222 -       if (!new_nsp)
223 -               return ERR_PTR(-ENOMEM);
224 -
225 -       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
226 -       if (IS_ERR(new_nsp->mnt_ns))
227 -               goto out_ns;
228 -
229 -       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
230 -       if (IS_ERR(new_nsp->uts_ns))
231 -               goto out_uts;
232 -
233 -       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
234 -       if (IS_ERR(new_nsp->ipc_ns))
235 -               goto out_ipc;
236 -
237 -       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
238 -       if (IS_ERR(new_nsp->pid_ns))
239 -               goto out_pid;
240 -
241 -       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
242 -       if (IS_ERR(new_nsp->user_ns))
243 -               goto out_user;
244 -
245 -       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
246 -       if (IS_ERR(new_nsp->net_ns))
247 -               goto out_net;
248 -
249 -       return new_nsp;
250 -
251 -out_net:
252 -       if (new_nsp->user_ns)
253 -               put_user_ns(new_nsp->user_ns);
254 -       if (new_nsp->net_ns)
255 -               put_net(new_nsp->net_ns);
256 -out_user:
257 -       if (new_nsp->pid_ns)
258 -               put_pid_ns(new_nsp->pid_ns);
259 -out_pid:
260 -       if (new_nsp->ipc_ns)
261 -               put_ipc_ns(new_nsp->ipc_ns);
262 -out_ipc:
263 -       if (new_nsp->uts_ns)
264 -               put_uts_ns(new_nsp->uts_ns);
265 -out_uts:
266 -       if (new_nsp->mnt_ns)
267 -               put_mnt_ns(new_nsp->mnt_ns);
268 -out_ns:
269 -       kmem_cache_free(nsproxy_cachep, new_nsp);
270 -       return ERR_PTR(err);
271 -}
272 -
273 -static struct nsproxy *create_new_namespaces(unsigned long flags, struct task_struct *tsk,
274 -                       struct fs_struct *new_fs)
275 -{
276 -       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
277 -}
278 -
279 -/*
280 - * copies the nsproxy, setting refcount to 1, and grabbing a
281 - * reference to all contained namespaces.
282 - */
283 -struct nsproxy *copy_nsproxy(struct nsproxy *orig)
284 -{
285 -       struct nsproxy *ns = clone_nsproxy(orig);
286 -
287 -       if (ns) {
288 -               if (ns->mnt_ns)
289 -                       get_mnt_ns(ns->mnt_ns);
290 -               if (ns->uts_ns)
291 -                       get_uts_ns(ns->uts_ns);
292 -               if (ns->ipc_ns)
293 -                       get_ipc_ns(ns->ipc_ns);
294 -               if (ns->pid_ns)
295 -                       get_pid_ns(ns->pid_ns);
296 -       }
297 -       return ns;
298 -}
299 -
300 -/*
301 - * called from clone.  This now handles copy for nsproxy and all
302 - * namespaces therein.
303 - */
304 -int copy_namespaces(unsigned long flags, struct task_struct *tsk)
305 -{
306 -       struct nsproxy *old_ns = tsk->nsproxy;
307 -       struct nsproxy *new_ns = NULL;
308 -       int err = 0;
309 -
310 -       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08x,%p[%p])",
311 -               flags, tsk, old_ns);
312 -
313 -       if (!old_ns)
314 -               return 0;
315 -
316 -       get_nsproxy(old_ns);
317 -       return 0;
318 -
319 -       if (!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER | CLONE_NEWNET)))
320 -               return 0;
321 -
322 -        #ifndef CONFIG_NET_NS
323 -               if (unshare_flags & CLONE_NEWNET)
324 -                       return -EINVAL;
325 -        #endif
326 -
327 -
328 -       if (!capable(CAP_SYS_ADMIN)) {
329 -               err = -EPERM;
330 -               goto out;
331 -       }
332 -
333 -       new_ns = create_new_namespaces(flags, tsk, tsk->fs);
334 -       if (IS_ERR(new_ns)) {
335 -               err = PTR_ERR(new_ns);
336 -               goto out;
337 -       }
338 -
339 -       err = ns_container_clone(tsk);
340 -       if (err) {
341 -               put_nsproxy(new_ns);
342 -               goto out;
343 -       }
344 -
345 -       tsk->nsproxy = new_ns;
346 -
347 -out:
348 -       put_nsproxy(old_ns);
349 -       vxdprintk(VXD_CBIT(space, 3),
350 -               "copy_namespaces(0x%08x,%p[%p]) = %d [%p]",
351 -               flags, tsk, old_ns, err, new_ns);
352 -       return err;
353 -}
354 -
355 -void free_nsproxy(struct nsproxy *ns)
356 -{
357 -       if (ns->mnt_ns)
358 -               put_mnt_ns(ns->mnt_ns);
359 -       if (ns->uts_ns)
360 -               put_uts_ns(ns->uts_ns);
361 -       if (ns->ipc_ns)
362 -               put_ipc_ns(ns->ipc_ns);
363 -       if (ns->pid_ns)
364 -               put_pid_ns(ns->pid_ns);
365 -       atomic_dec(&vs_global_nsproxy);
366 -       kfree(ns);
367 -}
368 -
369 -/*
370 - * Called from unshare. Unshare all the namespaces part of nsproxy.
371 - * On success, returns the new nsproxy.
372 - */
373 -int unshare_nsproxy_namespaces(unsigned long unshare_flags,
374 -               struct nsproxy **new_nsp, struct fs_struct *new_fs)
375 -{
376 -       int err = 0;
377 -
378 -       vxdprintk(VXD_CBIT(space, 4),
379 -               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
380 -               unshare_flags, current->nsproxy);
381 -
382 -       if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
383 -                              CLONE_NEWUSER | CLONE_NEWNET)))
384 -               return 0;
385 -
386 -#ifndef CONFIG_NET_NS
387 -       if (unshare_flags & CLONE_NEWNET)
388 -               return -EINVAL;
389 -#endif
390 -       if (!capable(CAP_SYS_ADMIN))
391 -               return -EPERM;
392 -
393 -       *new_nsp = create_new_namespaces(unshare_flags, current,
394 -                               new_fs ? new_fs : current->fs);
395 -       if (IS_ERR(*new_nsp)) {
396 -               err = PTR_ERR(*new_nsp);
397 -               goto out;
398 -       }
399 -
400 -       err = ns_container_clone(current);
401 -       if (err)
402 -               put_nsproxy(*new_nsp);
403 -
404 -out:
405 -       return err;
406 -}
407 -
408 -static int __init nsproxy_cache_init(void)
409 -{
410 -       nsproxy_cachep = kmem_cache_create("nsproxy", sizeof(struct nsproxy),
411 -                                          0, SLAB_PANIC, NULL, NULL);
412 -       return 0;
413 -}
414 -
415 -module_init(nsproxy_cache_init);
416 diff -Nurb linux-2.6.22-594/kernel/user.c.orig linux-2.6.22-595/kernel/user.c.orig
417 --- linux-2.6.22-594/kernel/user.c.orig 2008-03-20 01:27:50.000000000 -0400
418 +++ linux-2.6.22-595/kernel/user.c.orig 1969-12-31 19:00:00.000000000 -0500
419 @@ -1,227 +0,0 @@
420 -/*
421 - * The "user cache".
422 - *
423 - * (C) Copyright 1991-2000 Linus Torvalds
424 - *
425 - * We have a per-user structure to keep track of how many
426 - * processes, files etc the user has claimed, in order to be
427 - * able to have per-user limits for system resources. 
428 - */
429 -
430 -#include <linux/init.h>
431 -#include <linux/sched.h>
432 -#include <linux/slab.h>
433 -#include <linux/bitops.h>
434 -#include <linux/key.h>
435 -#include <linux/interrupt.h>
436 -#include <linux/module.h>
437 -#include <linux/user_namespace.h>
438 -
439 -/*
440 - * UID task count cache, to get fast user lookup in "alloc_uid"
441 - * when changing user ID's (ie setuid() and friends).
442 - */
443 -
444 -#define UIDHASH_MASK           (UIDHASH_SZ - 1)
445 -#define __uidhashfn(xid,uid)   ((((uid) >> UIDHASH_BITS) + ((uid)^(xid))) & UIDHASH_MASK)
446 -#define uidhashentry(ns, xid, uid)     ((ns)->uidhash_table + __uidhashfn(xid, uid))
447 -
448 -static struct kmem_cache *uid_cachep;
449 -static struct list_head uidhash_table[UIDHASH_SZ];
450 -
451 -/*
452 - * The uidhash_lock is mostly taken from process context, but it is
453 - * occasionally also taken from softirq/tasklet context, when
454 - * task-structs get RCU-freed. Hence all locking must be softirq-safe.
455 - * But free_uid() is also called with local interrupts disabled, and running
456 - * local_bh_enable() with local interrupts disabled is an error - we'll run
457 - * softirq callbacks, and they can unconditionally enable interrupts, and
458 - * the caller of free_uid() didn't expect that..
459 - */
460 -static DEFINE_SPINLOCK(uidhash_lock);
461 -
462 -struct user_struct root_user = {
463 -       .__count        = ATOMIC_INIT(1),
464 -       .processes      = ATOMIC_INIT(1),
465 -       .files          = ATOMIC_INIT(0),
466 -       .sigpending     = ATOMIC_INIT(0),
467 -       .mq_bytes       = 0,
468 -       .locked_shm     = 0,
469 -#ifdef CONFIG_KEYS
470 -       .uid_keyring    = &root_user_keyring,
471 -       .session_keyring = &root_session_keyring,
472 -#endif
473 -};
474 -
475 -/*
476 - * These routines must be called with the uidhash spinlock held!
477 - */
478 -static inline void uid_hash_insert(struct user_struct *up, struct list_head *hashent)
479 -{
480 -       list_add(&up->uidhash_list, hashent);
481 -}
482 -
483 -static inline void uid_hash_remove(struct user_struct *up)
484 -{
485 -       list_del(&up->uidhash_list);
486 -}
487 -
488 -static inline struct user_struct *uid_hash_find(xid_t xid, uid_t uid, struct list_head *hashent)
489 -{
490 -       struct list_head *up;
491 -
492 -       list_for_each(up, hashent) {
493 -               struct user_struct *user;
494 -
495 -               user = list_entry(up, struct user_struct, uidhash_list);
496 -
497 -               if(user->uid == uid && user->xid == xid) {
498 -                       atomic_inc(&user->__count);
499 -                       return user;
500 -               }
501 -       }
502 -
503 -       return NULL;
504 -}
505 -
506 -/*
507 - * Locate the user_struct for the passed UID.  If found, take a ref on it.  The
508 - * caller must undo that ref with free_uid().
509 - *
510 - * If the user_struct could not be found, return NULL.
511 - */
512 -struct user_struct *find_user(xid_t xid, uid_t uid)
513 -{
514 -       struct user_struct *ret;
515 -       unsigned long flags;
516 -       struct user_namespace *ns = current->nsproxy->user_ns;
517 -
518 -       spin_lock_irqsave(&uidhash_lock, flags);
519 -       ret = uid_hash_find(xid, uid, uidhashentry(ns, xid, uid));
520 -       spin_unlock_irqrestore(&uidhash_lock, flags);
521 -       return ret;
522 -}
523 -
524 -void free_uid(struct user_struct *up)
525 -{
526 -       unsigned long flags;
527 -
528 -       if (!up)
529 -               return;
530 -
531 -       local_irq_save(flags);
532 -       if (atomic_dec_and_lock(&up->__count, &uidhash_lock)) {
533 -               uid_hash_remove(up);
534 -               spin_unlock_irqrestore(&uidhash_lock, flags);
535 -               key_put(up->uid_keyring);
536 -               key_put(up->session_keyring);
537 -               kmem_cache_free(uid_cachep, up);
538 -       } else {
539 -               local_irq_restore(flags);
540 -       }
541 -}
542 -
543 -struct user_struct * alloc_uid(xid_t xid, uid_t uid)
544 -{
545 -       struct user_namespace *ns = current->nsproxy->user_ns;
546 -       struct list_head *hashent = uidhashentry(ns,xid, uid);
547 -       struct user_struct *up;
548 -
549 -       spin_lock_irq(&uidhash_lock);
550 -       up = uid_hash_find(xid, uid, hashent);
551 -       spin_unlock_irq(&uidhash_lock);
552 -
553 -       if (!up) {
554 -               struct user_struct *new;
555 -
556 -               new = kmem_cache_alloc(uid_cachep, GFP_KERNEL);
557 -               if (!new)
558 -                       return NULL;
559 -               new->uid = uid;
560 -               new->xid = xid;
561 -               atomic_set(&new->__count, 1);
562 -               atomic_set(&new->processes, 0);
563 -               atomic_set(&new->files, 0);
564 -               atomic_set(&new->sigpending, 0);
565 -#ifdef CONFIG_INOTIFY_USER
566 -               atomic_set(&new->inotify_watches, 0);
567 -               atomic_set(&new->inotify_devs, 0);
568 -#endif
569 -
570 -               new->mq_bytes = 0;
571 -               new->locked_shm = 0;
572 -
573 -               if (alloc_uid_keyring(new, current) < 0) {
574 -                       kmem_cache_free(uid_cachep, new);
575 -                       return NULL;
576 -               }
577 -
578 -               /*
579 -                * Before adding this, check whether we raced
580 -                * on adding the same user already..
581 -                */
582 -               spin_lock_irq(&uidhash_lock);
583 -               up = uid_hash_find(xid, uid, hashent);
584 -               if (up) {
585 -                       key_put(new->uid_keyring);
586 -                       key_put(new->session_keyring);
587 -                       kmem_cache_free(uid_cachep, new);
588 -               } else {
589 -                       uid_hash_insert(new, hashent);
590 -                       up = new;
591 -               }
592 -               spin_unlock_irq(&uidhash_lock);
593 -
594 -       }
595 -       return up;
596 -}
597 -
598 -void switch_uid(struct user_struct *new_user)
599 -{
600 -       struct user_struct *old_user;
601 -
602 -       /* What if a process setreuid()'s and this brings the
603 -        * new uid over his NPROC rlimit?  We can check this now
604 -        * cheaply with the new uid cache, so if it matters
605 -        * we should be checking for it.  -DaveM
606 -        */
607 -       old_user = current->user;
608 -       atomic_inc(&new_user->processes);
609 -       atomic_dec(&old_user->processes);
610 -       switch_uid_keyring(new_user);
611 -       current->user = new_user;
612 -
613 -       /*
614 -        * We need to synchronize with __sigqueue_alloc()
615 -        * doing a get_uid(p->user).. If that saw the old
616 -        * user value, we need to wait until it has exited
617 -        * its critical region before we can free the old
618 -        * structure.
619 -        */
620 -       smp_mb();
621 -       spin_unlock_wait(&current->sighand->siglock);
622 -
623 -       free_uid(old_user);
624 -       suid_keys(current);
625 -}
626 -
627 -
628 -static int __init uid_cache_init(void)
629 -{
630 -       int n;
631 -
632 -       uid_cachep = kmem_cache_create("uid_cache", sizeof(struct user_struct),
633 -                       0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
634 -
635 -       for(n = 0; n < UIDHASH_SZ; ++n)
636 -               INIT_LIST_HEAD(init_user_ns.uidhash_table + n);
637 -
638 -       /* Insert the root user immediately (init already runs as root) */
639 -       spin_lock_irq(&uidhash_lock);
640 -       uid_hash_insert(&root_user, uidhashentry(&init_user_ns, 0, 0));
641 -       spin_unlock_irq(&uidhash_lock);
642 -
643 -       return 0;
644 -}
645 -
646 -module_init(uid_cache_init);
647 diff -Nurb linux-2.6.22-594/kernel/vserver/context.c linux-2.6.22-595/kernel/vserver/context.c
648 --- linux-2.6.22-594/kernel/vserver/context.c   2008-03-20 01:27:21.000000000 -0400
649 +++ linux-2.6.22-595/kernel/vserver/context.c   2008-03-20 01:28:00.000000000 -0400
650 @@ -589,13 +589,13 @@
651                         struct nsproxy *old_nsp, *new_nsp;
652  
653                         ret = unshare_nsproxy_namespaces(
654 -                               CLONE_NEWUTS | CLONE_NEWIPC,
655 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWNET,
656                                 &new_nsp, NULL);
657                         if (ret)
658                                 goto out;
659  
660                         old_nsp = xchg(&p->nsproxy, new_nsp);
661 -                       vx_set_space(vxi, CLONE_NEWUTS | CLONE_NEWIPC);
662 +                       vx_set_space(vxi, CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWNET);
663                         put_nsproxy(old_nsp);
664                 }
665         }
666 @@ -781,7 +781,7 @@
667         if (vs_state_change(new_vxi, VSC_STARTUP))
668                 goto out;
669  
670 -       ret = vx_migrate_task(current, new_vxi, (!data));
671 +       ret = vx_migrate_task(current, new_vxi, 1 /*(!data) Hack no. 1 - Sapan*/);
672         if (ret)
673                 goto out;
674  
675 diff -Nurb linux-2.6.22-594/kernel/vserver/space.c linux-2.6.22-595/kernel/vserver/space.c
676 --- linux-2.6.22-594/kernel/vserver/space.c     2008-03-20 01:27:54.000000000 -0400
677 +++ linux-2.6.22-595/kernel/vserver/space.c     2008-03-20 01:28:00.000000000 -0400
678 @@ -15,6 +15,7 @@
679  #include <linux/utsname.h>
680  #include <linux/nsproxy.h>
681  #include <linux/err.h>
682 +#include <net/net_namespace.h>
683  #include <asm/uaccess.h>
684  
685  #include <linux/vs_context.h>
686 @@ -55,6 +56,7 @@
687         struct mnt_namespace *old_ns;
688         struct uts_namespace *old_uts;
689         struct ipc_namespace *old_ipc;
690 +       struct net *old_net;
691         struct nsproxy *nsproxy;
692  
693         nsproxy = copy_nsproxy(old_nsproxy);
694 @@ -85,12 +87,26 @@
695         } else
696                 old_ipc = NULL;
697  
698 +       if (mask & CLONE_NEWNET) {
699 +               old_net = nsproxy->net_ns;
700 +               nsproxy->net_ns = new_nsproxy->net_ns;
701 +               if (nsproxy->net_ns) {
702 +                       get_net(nsproxy->net_ns);
703 +                       printk(KERN_ALERT "Cloning network namespace\n"); 
704 +               }       
705 +       } else
706 +               old_net = NULL;
707 +
708 +
709         if (old_ns)
710                 put_mnt_ns(old_ns);
711         if (old_uts)
712                 put_uts_ns(old_uts);
713         if (old_ipc)
714                 put_ipc_ns(old_ipc);
715 +       if (old_net)
716 +               put_net(old_net);
717 +
718  out:
719         return nsproxy;
720  }
721 @@ -251,6 +267,7 @@
722  
723  int vc_enter_space(struct vx_info *vxi, void __user *data)
724  {
725 +       /* Ask dhozac how to pass this flag from user space - Sapan*/
726         struct vcmd_space_mask vc_data = { .mask = 0 };
727  
728         if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
729 diff -Nurb linux-2.6.22-594/net/core/dev.c linux-2.6.22-595/net/core/dev.c
730 --- linux-2.6.22-594/net/core/dev.c     2008-03-20 01:27:55.000000000 -0400
731 +++ linux-2.6.22-595/net/core/dev.c     2008-03-20 01:32:22.000000000 -0400
732 @@ -2207,7 +2207,7 @@
733  
734         total = 0;
735         for_each_netdev(net, dev) {
736 -               if (!nx_dev_visible(current->nx_info, dev))
737 +               if (net==&init_net && !nx_dev_visible(current->nx_info, dev))
738                         continue;
739                 for (i = 0; i < NPROTO; i++) {
740                         if (gifconf_list[i]) {
741 @@ -2274,8 +2274,9 @@
742  static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
743  {
744         struct net_device_stats *stats = dev->get_stats(dev);
745 +       struct net *net = seq->private;
746  
747 -       if (!nx_dev_visible(current->nx_info, dev))
748 +       if (net==&init_net && !nx_dev_visible(current->nx_info, dev))
749                 return;
750  
751         seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
752 diff -Nurb linux-2.6.22-594/net/core/dev.c.orig linux-2.6.22-595/net/core/dev.c.orig
753 --- linux-2.6.22-594/net/core/dev.c.orig        1969-12-31 19:00:00.000000000 -0500
754 +++ linux-2.6.22-595/net/core/dev.c.orig        2008-03-20 01:27:55.000000000 -0400
755 @@ -0,0 +1,4141 @@
756 +/*
757 + *     NET3    Protocol independent device support routines.
758 + *
759 + *             This program is free software; you can redistribute it and/or
760 + *             modify it under the terms of the GNU General Public License
761 + *             as published by the Free Software Foundation; either version
762 + *             2 of the License, or (at your option) any later version.
763 + *
764 + *     Derived from the non IP parts of dev.c 1.0.19
765 + *             Authors:        Ross Biro
766 + *                             Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
767 + *                             Mark Evans, <evansmp@uhura.aston.ac.uk>
768 + *
769 + *     Additional Authors:
770 + *             Florian la Roche <rzsfl@rz.uni-sb.de>
771 + *             Alan Cox <gw4pts@gw4pts.ampr.org>
772 + *             David Hinds <dahinds@users.sourceforge.net>
773 + *             Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
774 + *             Adam Sulmicki <adam@cfar.umd.edu>
775 + *              Pekka Riikonen <priikone@poesidon.pspt.fi>
776 + *
777 + *     Changes:
778 + *              D.J. Barrow     :       Fixed bug where dev->refcnt gets set
779 + *                                     to 2 if register_netdev gets called
780 + *                                     before net_dev_init & also removed a
781 + *                                     few lines of code in the process.
782 + *             Alan Cox        :       device private ioctl copies fields back.
783 + *             Alan Cox        :       Transmit queue code does relevant
784 + *                                     stunts to keep the queue safe.
785 + *             Alan Cox        :       Fixed double lock.
786 + *             Alan Cox        :       Fixed promisc NULL pointer trap
787 + *             ????????        :       Support the full private ioctl range
788 + *             Alan Cox        :       Moved ioctl permission check into
789 + *                                     drivers
790 + *             Tim Kordas      :       SIOCADDMULTI/SIOCDELMULTI
791 + *             Alan Cox        :       100 backlog just doesn't cut it when
792 + *                                     you start doing multicast video 8)
793 + *             Alan Cox        :       Rewrote net_bh and list manager.
794 + *             Alan Cox        :       Fix ETH_P_ALL echoback lengths.
795 + *             Alan Cox        :       Took out transmit every packet pass
796 + *                                     Saved a few bytes in the ioctl handler
797 + *             Alan Cox        :       Network driver sets packet type before
798 + *                                     calling netif_rx. Saves a function
799 + *                                     call a packet.
800 + *             Alan Cox        :       Hashed net_bh()
801 + *             Richard Kooijman:       Timestamp fixes.
802 + *             Alan Cox        :       Wrong field in SIOCGIFDSTADDR
803 + *             Alan Cox        :       Device lock protection.
804 + *             Alan Cox        :       Fixed nasty side effect of device close
805 + *                                     changes.
806 + *             Rudi Cilibrasi  :       Pass the right thing to
807 + *                                     set_mac_address()
808 + *             Dave Miller     :       32bit quantity for the device lock to
809 + *                                     make it work out on a Sparc.
810 + *             Bjorn Ekwall    :       Added KERNELD hack.
811 + *             Alan Cox        :       Cleaned up the backlog initialise.
812 + *             Craig Metz      :       SIOCGIFCONF fix if space for under
813 + *                                     1 device.
814 + *         Thomas Bogendoerfer :       Return ENODEV for dev_open, if there
815 + *                                     is no device open function.
816 + *             Andi Kleen      :       Fix error reporting for SIOCGIFCONF
817 + *         Michael Chastain    :       Fix signed/unsigned for SIOCGIFCONF
818 + *             Cyrus Durgin    :       Cleaned for KMOD
819 + *             Adam Sulmicki   :       Bug Fix : Network Device Unload
820 + *                                     A network device unload needs to purge
821 + *                                     the backlog queue.
822 + *     Paul Rusty Russell      :       SIOCSIFNAME
823 + *              Pekka Riikonen  :      Netdev boot-time settings code
824 + *              Andrew Morton   :       Make unregister_netdevice wait
825 + *                                     indefinitely on dev->refcnt
826 + *             J Hadi Salim    :       - Backlog queue sampling
827 + *                                     - netif_rx() feedback
828 + */
829 +
830 +#include <asm/uaccess.h>
831 +#include <asm/system.h>
832 +#include <linux/bitops.h>
833 +#include <linux/capability.h>
834 +#include <linux/cpu.h>
835 +#include <linux/types.h>
836 +#include <linux/kernel.h>
837 +#include <linux/sched.h>
838 +#include <linux/mutex.h>
839 +#include <linux/string.h>
840 +#include <linux/mm.h>
841 +#include <linux/socket.h>
842 +#include <linux/sockios.h>
843 +#include <linux/errno.h>
844 +#include <linux/interrupt.h>
845 +#include <linux/if_ether.h>
846 +#include <linux/netdevice.h>
847 +#include <linux/etherdevice.h>
848 +#include <linux/notifier.h>
849 +#include <linux/skbuff.h>
850 +#include <net/sock.h>
851 +#include <linux/rtnetlink.h>
852 +#include <linux/proc_fs.h>
853 +#include <linux/seq_file.h>
854 +#include <linux/stat.h>
855 +#include <linux/if_bridge.h>
856 +#include <net/dst.h>
857 +#include <net/pkt_sched.h>
858 +#include <net/checksum.h>
859 +#include <linux/highmem.h>
860 +#include <linux/init.h>
861 +#include <linux/kmod.h>
862 +#include <linux/module.h>
863 +#include <linux/kallsyms.h>
864 +#include <linux/netpoll.h>
865 +#include <linux/rcupdate.h>
866 +#include <linux/delay.h>
867 +#include <net/wext.h>
868 +#include <net/iw_handler.h>
869 +#include <asm/current.h>
870 +#include <linux/audit.h>
871 +#include <linux/dmaengine.h>
872 +#include <linux/err.h>
873 +#include <linux/ctype.h>
874 +#include <net/net_namespace.h>
875 +#include <linux/if_arp.h>
876 +#include <linux/vs_inet.h>
877 +
878 +/*
879 + *     The list of packet types we will receive (as opposed to discard)
880 + *     and the routines to invoke.
881 + *
882 + *     Why 16. Because with 16 the only overlap we get on a hash of the
883 + *     low nibble of the protocol value is RARP/SNAP/X.25.
884 + *
885 + *      NOTE:  That is no longer true with the addition of VLAN tags.  Not
886 + *             sure which should go first, but I bet it won't make much
887 + *             difference if we are running VLANs.  The good news is that
888 + *             this protocol won't be in the list unless compiled in, so
889 + *             the average user (w/out VLANs) will not be adversely affected.
890 + *             --BLG
891 + *
892 + *             0800    IP
893 + *             8100    802.1Q VLAN
894 + *             0001    802.3
895 + *             0002    AX.25
896 + *             0004    802.2
897 + *             8035    RARP
898 + *             0005    SNAP
899 + *             0805    X.25
900 + *             0806    ARP
901 + *             8137    IPX
902 + *             0009    Localtalk
903 + *             86DD    IPv6
904 + */
905 +
906 +static DEFINE_SPINLOCK(ptype_lock);
907 +static struct list_head ptype_base[16] __read_mostly;  /* 16 way hashed list */
908 +static struct list_head ptype_all __read_mostly;       /* Taps */
909 +
910 +#ifdef CONFIG_NET_DMA
911 +struct net_dma {
912 +       struct dma_client client;
913 +       spinlock_t lock;
914 +       cpumask_t channel_mask;
915 +       struct dma_chan *channels[NR_CPUS];
916 +};
917 +
918 +static enum dma_state_client
919 +netdev_dma_event(struct dma_client *client, struct dma_chan *chan,
920 +       enum dma_state state);
921 +
922 +static struct net_dma net_dma = {
923 +       .client = {
924 +               .event_callback = netdev_dma_event,
925 +       },
926 +};
927 +#endif
928 +
929 +/*
930 + * The @dev_base_head list is protected by @dev_base_lock and the rtnl
931 + * semaphore.
932 + *
933 + * Pure readers hold dev_base_lock for reading.
934 + *
935 + * Writers must hold the rtnl semaphore while they loop through the
936 + * dev_base_head list, and hold dev_base_lock for writing when they do the
937 + * actual updates.  This allows pure readers to access the list even
938 + * while a writer is preparing to update it.
939 + *
940 + * To put it another way, dev_base_lock is held for writing only to
941 + * protect against pure readers; the rtnl semaphore provides the
942 + * protection against other writers.
943 + *
944 + * See, for example usages, register_netdevice() and
945 + * unregister_netdevice(), which must be called with the rtnl
946 + * semaphore held.
947 + */
948 +DEFINE_RWLOCK(dev_base_lock);
949 +
950 +EXPORT_SYMBOL(dev_base_lock);
951 +
952 +#define NETDEV_HASHBITS        8
953 +#define NETDEV_HASHENTRIES (1 << NETDEV_HASHBITS)
954 +
955 +static inline struct hlist_head *dev_name_hash(struct net *net, const char *name)
956 +{
957 +       unsigned hash = full_name_hash(name, strnlen(name, IFNAMSIZ));
958 +       return &net->dev_name_head[hash & ((1 << NETDEV_HASHBITS) - 1)];
959 +}
960 +
961 +static inline struct hlist_head *dev_index_hash(struct net *net, int ifindex)
962 +{
963 +       return &net->dev_index_head[ifindex & ((1 << NETDEV_HASHBITS) - 1)];
964 +}
965 +
966 +/* Device list insertion */
967 +static int list_netdevice(struct net_device *dev)
968 +{
969 +       struct net *net = dev->nd_net;
970 +
971 +       ASSERT_RTNL();
972 +
973 +       write_lock_bh(&dev_base_lock);
974 +       list_add_tail(&dev->dev_list, &net->dev_base_head);
975 +       hlist_add_head(&dev->name_hlist, dev_name_hash(net, dev->name));
976 +       hlist_add_head(&dev->index_hlist, dev_index_hash(net, dev->ifindex));
977 +       write_unlock_bh(&dev_base_lock);
978 +       return 0;
979 +}
980 +
981 +/* Device list removal */
982 +static void unlist_netdevice(struct net_device *dev)
983 +{
984 +       ASSERT_RTNL();
985 +
986 +       /* Unlink dev from the device chain */
987 +       write_lock_bh(&dev_base_lock);
988 +       list_del(&dev->dev_list);
989 +       hlist_del(&dev->name_hlist);
990 +       hlist_del(&dev->index_hlist);
991 +       write_unlock_bh(&dev_base_lock);
992 +}
993 +
994 +/*
995 + *     Our notifier list
996 + */
997 +
998 +static RAW_NOTIFIER_HEAD(netdev_chain);
999 +
1000 +/*
1001 + *     Device drivers call our routines to queue packets here. We empty the
1002 + *     queue in the local softnet handler.
1003 + */
1004 +DEFINE_PER_CPU(struct softnet_data, softnet_data) = { NULL };
1005 +
1006 +#ifdef CONFIG_SYSFS
1007 +extern int netdev_sysfs_init(void);
1008 +extern int netdev_register_sysfs(struct net_device *);
1009 +extern void netdev_unregister_sysfs(struct net_device *);
1010 +#else
1011 +#define netdev_sysfs_init()            (0)
1012 +#define netdev_register_sysfs(dev)     (0)
1013 +#define        netdev_unregister_sysfs(dev)    do { } while(0)
1014 +#endif
1015 +
1016 +#ifdef CONFIG_DEBUG_LOCK_ALLOC
1017 +/*
1018 + * register_netdevice() inits dev->_xmit_lock and sets lockdep class
1019 + * according to dev->type
1020 + */
1021 +static const unsigned short netdev_lock_type[] =
1022 +       {ARPHRD_NETROM, ARPHRD_ETHER, ARPHRD_EETHER, ARPHRD_AX25,
1023 +        ARPHRD_PRONET, ARPHRD_CHAOS, ARPHRD_IEEE802, ARPHRD_ARCNET,
1024 +        ARPHRD_APPLETLK, ARPHRD_DLCI, ARPHRD_ATM, ARPHRD_METRICOM,
1025 +        ARPHRD_IEEE1394, ARPHRD_EUI64, ARPHRD_INFINIBAND, ARPHRD_SLIP,
1026 +        ARPHRD_CSLIP, ARPHRD_SLIP6, ARPHRD_CSLIP6, ARPHRD_RSRVD,
1027 +        ARPHRD_ADAPT, ARPHRD_ROSE, ARPHRD_X25, ARPHRD_HWX25,
1028 +        ARPHRD_PPP, ARPHRD_CISCO, ARPHRD_LAPB, ARPHRD_DDCMP,
1029 +        ARPHRD_RAWHDLC, ARPHRD_TUNNEL, ARPHRD_TUNNEL6, ARPHRD_FRAD,
1030 +        ARPHRD_SKIP, ARPHRD_LOOPBACK, ARPHRD_LOCALTLK, ARPHRD_FDDI,
1031 +        ARPHRD_BIF, ARPHRD_SIT, ARPHRD_IPDDP, ARPHRD_IPGRE,
1032 +        ARPHRD_PIMREG, ARPHRD_HIPPI, ARPHRD_ASH, ARPHRD_ECONET,
1033 +        ARPHRD_IRDA, ARPHRD_FCPP, ARPHRD_FCAL, ARPHRD_FCPL,
1034 +        ARPHRD_FCFABRIC, ARPHRD_IEEE802_TR, ARPHRD_IEEE80211,
1035 +        ARPHRD_IEEE80211_PRISM, ARPHRD_IEEE80211_RADIOTAP, ARPHRD_VOID,
1036 +        ARPHRD_NONE};
1037 +
1038 +static const char *netdev_lock_name[] =
1039 +       {"_xmit_NETROM", "_xmit_ETHER", "_xmit_EETHER", "_xmit_AX25",
1040 +        "_xmit_PRONET", "_xmit_CHAOS", "_xmit_IEEE802", "_xmit_ARCNET",
1041 +        "_xmit_APPLETLK", "_xmit_DLCI", "_xmit_ATM", "_xmit_METRICOM",
1042 +        "_xmit_IEEE1394", "_xmit_EUI64", "_xmit_INFINIBAND", "_xmit_SLIP",
1043 +        "_xmit_CSLIP", "_xmit_SLIP6", "_xmit_CSLIP6", "_xmit_RSRVD",
1044 +        "_xmit_ADAPT", "_xmit_ROSE", "_xmit_X25", "_xmit_HWX25",
1045 +        "_xmit_PPP", "_xmit_CISCO", "_xmit_LAPB", "_xmit_DDCMP",
1046 +        "_xmit_RAWHDLC", "_xmit_TUNNEL", "_xmit_TUNNEL6", "_xmit_FRAD",
1047 +        "_xmit_SKIP", "_xmit_LOOPBACK", "_xmit_LOCALTLK", "_xmit_FDDI",
1048 +        "_xmit_BIF", "_xmit_SIT", "_xmit_IPDDP", "_xmit_IPGRE",
1049 +        "_xmit_PIMREG", "_xmit_HIPPI", "_xmit_ASH", "_xmit_ECONET",
1050 +        "_xmit_IRDA", "_xmit_FCPP", "_xmit_FCAL", "_xmit_FCPL",
1051 +        "_xmit_FCFABRIC", "_xmit_IEEE802_TR", "_xmit_IEEE80211",
1052 +        "_xmit_IEEE80211_PRISM", "_xmit_IEEE80211_RADIOTAP", "_xmit_VOID",
1053 +        "_xmit_NONE"};
1054 +
1055 +static struct lock_class_key netdev_xmit_lock_key[ARRAY_SIZE(netdev_lock_type)];
1056 +
1057 +static inline unsigned short netdev_lock_pos(unsigned short dev_type)
1058 +{
1059 +       int i;
1060 +
1061 +       for (i = 0; i < ARRAY_SIZE(netdev_lock_type); i++)
1062 +               if (netdev_lock_type[i] == dev_type)
1063 +                       return i;
1064 +       /* the last key is used by default */
1065 +       return ARRAY_SIZE(netdev_lock_type) - 1;
1066 +}
1067 +
1068 +static inline void netdev_set_lockdep_class(spinlock_t *lock,
1069 +                                           unsigned short dev_type)
1070 +{
1071 +       int i;
1072 +
1073 +       i = netdev_lock_pos(dev_type);
1074 +       lockdep_set_class_and_name(lock, &netdev_xmit_lock_key[i],
1075 +                                  netdev_lock_name[i]);
1076 +}
1077 +#else
1078 +static inline void netdev_set_lockdep_class(spinlock_t *lock,
1079 +                                           unsigned short dev_type)
1080 +{
1081 +}
1082 +#endif
1083 +
1084 +/*******************************************************************************
1085 +
1086 +               Protocol management and registration routines
1087 +
1088 +*******************************************************************************/
1089 +
1090 +/*
1091 + *     Add a protocol ID to the list. Now that the input handler is
1092 + *     smarter we can dispense with all the messy stuff that used to be
1093 + *     here.
1094 + *
1095 + *     BEWARE!!! Protocol handlers, mangling input packets,
1096 + *     MUST BE last in hash buckets and checking protocol handlers
1097 + *     MUST start from promiscuous ptype_all chain in net_bh.
1098 + *     It is true now, do not change it.
1099 + *     Explanation follows: if protocol handler, mangling packet, will
1100 + *     be the first on list, it is not able to sense, that packet
1101 + *     is cloned and should be copied-on-write, so that it will
1102 + *     change it and subsequent readers will get broken packet.
1103 + *                                                     --ANK (980803)
1104 + */
1105 +
1106 +/**
1107 + *     dev_add_pack - add packet handler
1108 + *     @pt: packet type declaration
1109 + *
1110 + *     Add a protocol handler to the networking stack. The passed &packet_type
1111 + *     is linked into kernel lists and may not be freed until it has been
1112 + *     removed from the kernel lists.
1113 + *
1114 + *     This call does not sleep therefore it can not
1115 + *     guarantee all CPU's that are in middle of receiving packets
1116 + *     will see the new packet type (until the next received packet).
1117 + */
1118 +
1119 +void dev_add_pack(struct packet_type *pt)
1120 +{
1121 +       int hash;
1122 +
1123 +       spin_lock_bh(&ptype_lock);
1124 +       if (pt->type == htons(ETH_P_ALL))
1125 +               list_add_rcu(&pt->list, &ptype_all);
1126 +       else {
1127 +               hash = ntohs(pt->type) & 15;
1128 +               list_add_rcu(&pt->list, &ptype_base[hash]);
1129 +       }
1130 +       spin_unlock_bh(&ptype_lock);
1131 +}
1132 +
1133 +/**
1134 + *     __dev_remove_pack        - remove packet handler
1135 + *     @pt: packet type declaration
1136 + *
1137 + *     Remove a protocol handler that was previously added to the kernel
1138 + *     protocol handlers by dev_add_pack(). The passed &packet_type is removed
1139 + *     from the kernel lists and can be freed or reused once this function
1140 + *     returns.
1141 + *
1142 + *      The packet type might still be in use by receivers
1143 + *     and must not be freed until after all the CPU's have gone
1144 + *     through a quiescent state.
1145 + */
1146 +void __dev_remove_pack(struct packet_type *pt)
1147 +{
1148 +       struct list_head *head;
1149 +       struct packet_type *pt1;
1150 +
1151 +       spin_lock_bh(&ptype_lock);
1152 +
1153 +       if (pt->type == htons(ETH_P_ALL))
1154 +               head = &ptype_all;
1155 +       else
1156 +               head = &ptype_base[ntohs(pt->type) & 15];
1157 +
1158 +       list_for_each_entry(pt1, head, list) {
1159 +               if (pt == pt1) {
1160 +                       list_del_rcu(&pt->list);
1161 +                       goto out;
1162 +               }
1163 +       }
1164 +
1165 +       printk(KERN_WARNING "dev_remove_pack: %p not found.\n", pt);
1166 +out:
1167 +       spin_unlock_bh(&ptype_lock);
1168 +}
1169 +/**
1170 + *     dev_remove_pack  - remove packet handler
1171 + *     @pt: packet type declaration
1172 + *
1173 + *     Remove a protocol handler that was previously added to the kernel
1174 + *     protocol handlers by dev_add_pack(). The passed &packet_type is removed
1175 + *     from the kernel lists and can be freed or reused once this function
1176 + *     returns.
1177 + *
1178 + *     This call sleeps to guarantee that no CPU is looking at the packet
1179 + *     type after return.
1180 + */
1181 +void dev_remove_pack(struct packet_type *pt)
1182 +{
1183 +       __dev_remove_pack(pt);
1184 +
1185 +       synchronize_net();
1186 +}
1187 +
1188 +/******************************************************************************
1189 +
1190 +                     Device Boot-time Settings Routines
1191 +
1192 +*******************************************************************************/
1193 +
1194 +/* Boot time configuration table */
1195 +static struct netdev_boot_setup dev_boot_setup[NETDEV_BOOT_SETUP_MAX];
1196 +
1197 +/**
1198 + *     netdev_boot_setup_add   - add new setup entry
1199 + *     @name: name of the device
1200 + *     @map: configured settings for the device
1201 + *
1202 + *     Adds new setup entry to the dev_boot_setup list.  The function
1203 + *     returns 0 on error and 1 on success.  This is a generic routine to
1204 + *     all netdevices.
1205 + */
1206 +static int netdev_boot_setup_add(char *name, struct ifmap *map)
1207 +{
1208 +       struct netdev_boot_setup *s;
1209 +       int i;
1210 +
1211 +       s = dev_boot_setup;
1212 +       for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
1213 +               if (s[i].name[0] == '\0' || s[i].name[0] == ' ') {
1214 +                       memset(s[i].name, 0, sizeof(s[i].name));
1215 +                       strcpy(s[i].name, name);
1216 +                       memcpy(&s[i].map, map, sizeof(s[i].map));
1217 +                       break;
1218 +               }
1219 +       }
1220 +
1221 +       return i >= NETDEV_BOOT_SETUP_MAX ? 0 : 1;
1222 +}
1223 +
1224 +/**
1225 + *     netdev_boot_setup_check - check boot time settings
1226 + *     @dev: the netdevice
1227 + *
1228 + *     Check boot time settings for the device.
1229 + *     The found settings are set for the device to be used
1230 + *     later in the device probing.
1231 + *     Returns 0 if no settings found, 1 if they are.
1232 + */
1233 +int netdev_boot_setup_check(struct net_device *dev)
1234 +{
1235 +       struct netdev_boot_setup *s = dev_boot_setup;
1236 +       int i;
1237 +
1238 +       for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
1239 +               if (s[i].name[0] != '\0' && s[i].name[0] != ' ' &&
1240 +                   !strncmp(dev->name, s[i].name, strlen(s[i].name))) {
1241 +                       dev->irq        = s[i].map.irq;
1242 +                       dev->base_addr  = s[i].map.base_addr;
1243 +                       dev->mem_start  = s[i].map.mem_start;
1244 +                       dev->mem_end    = s[i].map.mem_end;
1245 +                       return 1;
1246 +               }
1247 +       }
1248 +       return 0;
1249 +}
1250 +
1251 +
1252 +/**
1253 + *     netdev_boot_base        - get address from boot time settings
1254 + *     @prefix: prefix for network device
1255 + *     @unit: id for network device
1256 + *
1257 + *     Check boot time settings for the base address of device.
1258 + *     The found settings are set for the device to be used
1259 + *     later in the device probing.
1260 + *     Returns 0 if no settings found.
1261 + */
1262 +unsigned long netdev_boot_base(const char *prefix, int unit)
1263 +{
1264 +       const struct netdev_boot_setup *s = dev_boot_setup;
1265 +       char name[IFNAMSIZ];
1266 +       int i;
1267 +
1268 +       sprintf(name, "%s%d", prefix, unit);
1269 +
1270 +       /*
1271 +        * If device already registered then return base of 1
1272 +        * to indicate not to probe for this interface
1273 +        */
1274 +       if (__dev_get_by_name(&init_net, name))
1275 +               return 1;
1276 +
1277 +       for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++)
1278 +               if (!strcmp(name, s[i].name))
1279 +                       return s[i].map.base_addr;
1280 +       return 0;
1281 +}
1282 +
1283 +/*
1284 + * Saves at boot time configured settings for any netdevice.
1285 + */
1286 +int __init netdev_boot_setup(char *str)
1287 +{
1288 +       int ints[5];
1289 +       struct ifmap map;
1290 +
1291 +       str = get_options(str, ARRAY_SIZE(ints), ints);
1292 +       if (!str || !*str)
1293 +               return 0;
1294 +
1295 +       /* Save settings */
1296 +       memset(&map, 0, sizeof(map));
1297 +       if (ints[0] > 0)
1298 +               map.irq = ints[1];
1299 +       if (ints[0] > 1)
1300 +               map.base_addr = ints[2];
1301 +       if (ints[0] > 2)
1302 +               map.mem_start = ints[3];
1303 +       if (ints[0] > 3)
1304 +               map.mem_end = ints[4];
1305 +
1306 +       /* Add new entry to the list */
1307 +       return netdev_boot_setup_add(str, &map);
1308 +}
1309 +
1310 +__setup("netdev=", netdev_boot_setup);
1311 +
1312 +/*******************************************************************************
1313 +
1314 +                           Device Interface Subroutines
1315 +
1316 +*******************************************************************************/
1317 +
1318 +/**
1319 + *     __dev_get_by_name       - find a device by its name
1320 + *     @name: name to find
1321 + *
1322 + *     Find an interface by name. Must be called under RTNL semaphore
1323 + *     or @dev_base_lock. If the name is found a pointer to the device
1324 + *     is returned. If the name is not found then %NULL is returned. The
1325 + *     reference counters are not incremented so the caller must be
1326 + *     careful with locks.
1327 + */
1328 +
1329 +struct net_device *__dev_get_by_name(struct net *net, const char *name)
1330 +{
1331 +       struct hlist_node *p;
1332 +
1333 +       hlist_for_each(p, dev_name_hash(net, name)) {
1334 +               struct net_device *dev
1335 +                       = hlist_entry(p, struct net_device, name_hlist);
1336 +               if (!strncmp(dev->name, name, IFNAMSIZ))
1337 +                       return dev;
1338 +       }
1339 +       return NULL;
1340 +}
1341 +
1342 +/**
1343 + *     dev_get_by_name         - find a device by its name
1344 + *     @name: name to find
1345 + *
1346 + *     Find an interface by name. This can be called from any
1347 + *     context and does its own locking. The returned handle has
1348 + *     the usage count incremented and the caller must use dev_put() to
1349 + *     release it when it is no longer needed. %NULL is returned if no
1350 + *     matching device is found.
1351 + */
1352 +
1353 +struct net_device *dev_get_by_name(struct net *net, const char *name)
1354 +{
1355 +       struct net_device *dev;
1356 +
1357 +       read_lock(&dev_base_lock);
1358 +       dev = __dev_get_by_name(net, name);
1359 +       if (dev)
1360 +               dev_hold(dev);
1361 +       read_unlock(&dev_base_lock);
1362 +       return dev;
1363 +}
1364 +
1365 +/**
1366 + *     __dev_get_by_index - find a device by its ifindex
1367 + *     @ifindex: index of device
1368 + *
1369 + *     Search for an interface by index. Returns %NULL if the device
1370 + *     is not found or a pointer to the device. The device has not
1371 + *     had its reference counter increased so the caller must be careful
1372 + *     about locking. The caller must hold either the RTNL semaphore
1373 + *     or @dev_base_lock.
1374 + */
1375 +
1376 +struct net_device *__dev_get_by_index(struct net *net, int ifindex)
1377 +{
1378 +       struct hlist_node *p;
1379 +
1380 +       hlist_for_each(p, dev_index_hash(net, ifindex)) {
1381 +               struct net_device *dev
1382 +                       = hlist_entry(p, struct net_device, index_hlist);
1383 +               if (dev->ifindex == ifindex)
1384 +                       return dev;
1385 +       }
1386 +       return NULL;
1387 +}
1388 +
1389 +
1390 +/**
1391 + *     dev_get_by_index - find a device by its ifindex
1392 + *     @ifindex: index of device
1393 + *
1394 + *     Search for an interface by index. Returns NULL if the device
1395 + *     is not found or a pointer to the device. The device returned has
1396 + *     had a reference added and the pointer is safe until the user calls
1397 + *     dev_put to indicate they have finished with it.
1398 + */
1399 +
1400 +struct net_device *dev_get_by_index(struct net *net, int ifindex)
1401 +{
1402 +       struct net_device *dev;
1403 +
1404 +       read_lock(&dev_base_lock);
1405 +       dev = __dev_get_by_index(net, ifindex);
1406 +       if (dev)
1407 +               dev_hold(dev);
1408 +       read_unlock(&dev_base_lock);
1409 +       return dev;
1410 +}
1411 +
1412 +/**
1413 + *     dev_getbyhwaddr - find a device by its hardware address
1414 + *     @type: media type of device
1415 + *     @ha: hardware address
1416 + *
1417 + *     Search for an interface by MAC address. Returns NULL if the device
1418 + *     is not found or a pointer to the device. The caller must hold the
1419 + *     rtnl semaphore. The returned device has not had its ref count increased
1420 + *     and the caller must therefore be careful about locking
1421 + *
1422 + *     BUGS:
1423 + *     If the API was consistent this would be __dev_get_by_hwaddr
1424 + */
1425 +
1426 +struct net_device *dev_getbyhwaddr(struct net *net, unsigned short type, char *ha)
1427 +{
1428 +       struct net_device *dev;
1429 +
1430 +       ASSERT_RTNL();
1431 +
1432 +       for_each_netdev(&init_net, dev)
1433 +               if (dev->type == type &&
1434 +                   !memcmp(dev->dev_addr, ha, dev->addr_len))
1435 +                       return dev;
1436 +
1437 +       return NULL;
1438 +}
1439 +
1440 +EXPORT_SYMBOL(dev_getbyhwaddr);
1441 +
1442 +struct net_device *__dev_getfirstbyhwtype(struct net *net, unsigned short type)
1443 +{
1444 +       struct net_device *dev;
1445 +
1446 +       ASSERT_RTNL();
1447 +       for_each_netdev(net, dev)
1448 +               if (dev->type == type)
1449 +                       return dev;
1450 +
1451 +       return NULL;
1452 +}
1453 +
1454 +EXPORT_SYMBOL(__dev_getfirstbyhwtype);
1455 +
1456 +struct net_device *dev_getfirstbyhwtype(struct net *net, unsigned short type)
1457 +{
1458 +       struct net_device *dev;
1459 +
1460 +       rtnl_lock();
1461 +       dev = __dev_getfirstbyhwtype(net, type);
1462 +       if (dev)
1463 +               dev_hold(dev);
1464 +       rtnl_unlock();
1465 +       return dev;
1466 +}
1467 +
1468 +EXPORT_SYMBOL(dev_getfirstbyhwtype);
1469 +
1470 +/**
1471 + *     dev_get_by_flags - find any device with given flags
1472 + *     @if_flags: IFF_* values
1473 + *     @mask: bitmask of bits in if_flags to check
1474 + *
1475 + *     Search for any interface with the given flags. Returns NULL if a device
1476 + *     is not found or a pointer to the device. The device returned has
1477 + *     had a reference added and the pointer is safe until the user calls
1478 + *     dev_put to indicate they have finished with it.
1479 + */
1480 +
1481 +struct net_device * dev_get_by_flags(struct net *net, unsigned short if_flags, unsigned short mask)
1482 +{
1483 +       struct net_device *dev, *ret;
1484 +
1485 +       ret = NULL;
1486 +       read_lock(&dev_base_lock);
1487 +       for_each_netdev(net, dev) {
1488 +               if (((dev->flags ^ if_flags) & mask) == 0) {
1489 +                       dev_hold(dev);
1490 +                       ret = dev;
1491 +                       break;
1492 +               }
1493 +       }
1494 +       read_unlock(&dev_base_lock);
1495 +       return ret;
1496 +}
1497 +
1498 +/**
1499 + *     dev_valid_name - check if name is okay for network device
1500 + *     @name: name string
1501 + *
1502 + *     Network device names need to be valid file names to
1503 + *     to allow sysfs to work.  We also disallow any kind of
1504 + *     whitespace.
1505 + */
1506 +int dev_valid_name(const char *name)
1507 +{
1508 +       if (*name == '\0')
1509 +               return 0;
1510 +       if (strlen(name) >= IFNAMSIZ)
1511 +               return 0;
1512 +       if (!strcmp(name, ".") || !strcmp(name, ".."))
1513 +               return 0;
1514 +
1515 +       while (*name) {
1516 +               if (*name == '/' || isspace(*name))
1517 +                       return 0;
1518 +               name++;
1519 +       }
1520 +       return 1;
1521 +}
1522 +
1523 +/**
1524 + *     __dev_alloc_name - allocate a name for a device
1525 + *     @net: network namespace to allocate the device name in
1526 + *     @name: name format string
1527 + *     @buf:  scratch buffer and result name string
1528 + *
1529 + *     Passed a format string - eg "lt%d" it will try and find a suitable
1530 + *     id. It scans list of devices to build up a free map, then chooses
1531 + *     the first empty slot. The caller must hold the dev_base or rtnl lock
1532 + *     while allocating the name and adding the device in order to avoid
1533 + *     duplicates.
1534 + *     Limited to bits_per_byte * page size devices (ie 32K on most platforms).
1535 + *     Returns the number of the unit assigned or a negative errno code.
1536 + */
1537 +
1538 +static int __dev_alloc_name(struct net *net, const char *name, char *buf)
1539 +{
1540 +       int i = 0;
1541 +       const char *p;
1542 +       const int max_netdevices = 8*PAGE_SIZE;
1543 +       long *inuse;
1544 +       struct net_device *d;
1545 +
1546 +       p = strnchr(name, IFNAMSIZ-1, '%');
1547 +       if (p) {
1548 +               /*
1549 +                * Verify the string as this thing may have come from
1550 +                * the user.  There must be either one "%d" and no other "%"
1551 +                * characters.
1552 +                */
1553 +               if (p[1] != 'd' || strchr(p + 2, '%'))
1554 +                       return -EINVAL;
1555 +
1556 +               /* Use one page as a bit array of possible slots */
1557 +               inuse = (long *) get_zeroed_page(GFP_ATOMIC);
1558 +               if (!inuse)
1559 +                       return -ENOMEM;
1560 +
1561 +               for_each_netdev(net, d) {
1562 +                       if (!sscanf(d->name, name, &i))
1563 +                               continue;
1564 +                       if (i < 0 || i >= max_netdevices)
1565 +                               continue;
1566 +
1567 +                       /*  avoid cases where sscanf is not exact inverse of printf */
1568 +                       snprintf(buf, IFNAMSIZ, name, i);
1569 +                       if (!strncmp(buf, d->name, IFNAMSIZ))
1570 +                               set_bit(i, inuse);
1571 +               }
1572 +
1573 +               i = find_first_zero_bit(inuse, max_netdevices);
1574 +               free_page((unsigned long) inuse);
1575 +       }
1576 +
1577 +       snprintf(buf, IFNAMSIZ, name, i);
1578 +       if (!__dev_get_by_name(net, buf))
1579 +               return i;
1580 +
1581 +       /* It is possible to run out of possible slots
1582 +        * when the name is long and there isn't enough space left
1583 +        * for the digits, or if all bits are used.
1584 +        */
1585 +       return -ENFILE;
1586 +}
1587 +
1588 +/**
1589 + *     dev_alloc_name - allocate a name for a device
1590 + *     @dev: device
1591 + *     @name: name format string
1592 + *
1593 + *     Passed a format string - eg "lt%d" it will try and find a suitable
1594 + *     id. It scans list of devices to build up a free map, then chooses
1595 + *     the first empty slot. The caller must hold the dev_base or rtnl lock
1596 + *     while allocating the name and adding the device in order to avoid
1597 + *     duplicates.
1598 + *     Limited to bits_per_byte * page size devices (ie 32K on most platforms).
1599 + *     Returns the number of the unit assigned or a negative errno code.
1600 + */
1601 +
1602 +int dev_alloc_name(struct net_device *dev, const char *name)
1603 +{
1604 +       char buf[IFNAMSIZ];
1605 +       struct net *net;
1606 +       int ret;
1607 +
1608 +       BUG_ON(!dev->nd_net);
1609 +       net = dev->nd_net;
1610 +       ret = __dev_alloc_name(net, name, buf);
1611 +       if (ret >= 0)
1612 +               strlcpy(dev->name, buf, IFNAMSIZ);
1613 +       return ret;
1614 +}
1615 +
1616 +
1617 +/**
1618 + *     dev_change_name - change name of a device
1619 + *     @dev: device
1620 + *     @newname: name (or format string) must be at least IFNAMSIZ
1621 + *
1622 + *     Change name of a device, can pass format strings "eth%d".
1623 + *     for wildcarding.
1624 + */
1625 +int dev_change_name(struct net_device *dev, char *newname)
1626 +{
1627 +       int err = 0;
1628 +       struct net *net;
1629 +
1630 +       ASSERT_RTNL();
1631 +       BUG_ON(!dev->nd_net);
1632 +
1633 +       net = dev->nd_net;
1634 +       if (dev->flags & IFF_UP)
1635 +               return -EBUSY;
1636 +
1637 +       if (!dev_valid_name(newname))
1638 +               return -EINVAL;
1639 +
1640 +       if (strchr(newname, '%')) {
1641 +               err = dev_alloc_name(dev, newname);
1642 +               if (err < 0)
1643 +                       return err;
1644 +               strcpy(newname, dev->name);
1645 +       }
1646 +       else if (__dev_get_by_name(net, newname))
1647 +               return -EEXIST;
1648 +       else {
1649 +               if (strncmp(newname, dev->name, IFNAMSIZ))
1650 +                       printk(KERN_INFO "%s renamed to %s\n",
1651 +                                       dev->name, newname);
1652 +               strlcpy(dev->name, newname, IFNAMSIZ);
1653 +       }
1654 +
1655 +       device_rename(&dev->dev, dev->name);
1656 +       hlist_del(&dev->name_hlist);
1657 +       hlist_add_head(&dev->name_hlist, dev_name_hash(net, dev->name));
1658 +       raw_notifier_call_chain(&netdev_chain, NETDEV_CHANGENAME, dev);
1659 +
1660 +       return err;
1661 +}
1662 +
1663 +/**
1664 + *     netdev_features_change - device changes features
1665 + *     @dev: device to cause notification
1666 + *
1667 + *     Called to indicate a device has changed features.
1668 + */
1669 +void netdev_features_change(struct net_device *dev)
1670 +{
1671 +       raw_notifier_call_chain(&netdev_chain, NETDEV_FEAT_CHANGE, dev);
1672 +}
1673 +EXPORT_SYMBOL(netdev_features_change);
1674 +
1675 +/**
1676 + *     netdev_state_change - device changes state
1677 + *     @dev: device to cause notification
1678 + *
1679 + *     Called to indicate a device has changed state. This function calls
1680 + *     the notifier chains for netdev_chain and sends a NEWLINK message
1681 + *     to the routing socket.
1682 + */
1683 +void netdev_state_change(struct net_device *dev)
1684 +{
1685 +       if (dev->flags & IFF_UP) {
1686 +               raw_notifier_call_chain(&netdev_chain,
1687 +                               NETDEV_CHANGE, dev);
1688 +               rtmsg_ifinfo(RTM_NEWLINK, dev, 0);
1689 +       }
1690 +}
1691 +
1692 +/**
1693 + *     dev_load        - load a network module
1694 + *     @name: name of interface
1695 + *
1696 + *     If a network interface is not present and the process has suitable
1697 + *     privileges this function loads the module. If module loading is not
1698 + *     available in this kernel then it becomes a nop.
1699 + */
1700 +
1701 +void dev_load(struct net *net, const char *name)
1702 +{
1703 +       struct net_device *dev;
1704 +
1705 +       read_lock(&dev_base_lock);
1706 +       dev = __dev_get_by_name(net, name);
1707 +       read_unlock(&dev_base_lock);
1708 +
1709 +       if (!dev && capable(CAP_SYS_MODULE))
1710 +               request_module("%s", name);
1711 +}
1712 +
1713 +static int default_rebuild_header(struct sk_buff *skb)
1714 +{
1715 +       printk(KERN_DEBUG "%s: default_rebuild_header called -- BUG!\n",
1716 +              skb->dev ? skb->dev->name : "NULL!!!");
1717 +       kfree_skb(skb);
1718 +       return 1;
1719 +}
1720 +
1721 +/**
1722 + *     dev_open        - prepare an interface for use.
1723 + *     @dev:   device to open
1724 + *
1725 + *     Takes a device from down to up state. The device's private open
1726 + *     function is invoked and then the multicast lists are loaded. Finally
1727 + *     the device is moved into the up state and a %NETDEV_UP message is
1728 + *     sent to the netdev notifier chain.
1729 + *
1730 + *     Calling this function on an active interface is a nop. On a failure
1731 + *     a negative errno code is returned.
1732 + */
1733 +int dev_open(struct net_device *dev)
1734 +{
1735 +       int ret = 0;
1736 +
1737 +       /*
1738 +        *      Is it already up?
1739 +        */
1740 +
1741 +       if (dev->flags & IFF_UP)
1742 +               return 0;
1743 +
1744 +       /*
1745 +        *      Is it even present?
1746 +        */
1747 +       if (!netif_device_present(dev))
1748 +               return -ENODEV;
1749 +
1750 +       /*
1751 +        *      Call device private open method
1752 +        */
1753 +       set_bit(__LINK_STATE_START, &dev->state);
1754 +       if (dev->open) {
1755 +               ret = dev->open(dev);
1756 +               if (ret)
1757 +                       clear_bit(__LINK_STATE_START, &dev->state);
1758 +       }
1759 +
1760 +       /*
1761 +        *      If it went open OK then:
1762 +        */
1763 +
1764 +       if (!ret) {
1765 +               /*
1766 +                *      Set the flags.
1767 +                */
1768 +               dev->flags |= IFF_UP;
1769 +
1770 +               /*
1771 +                *      Initialize multicasting status
1772 +                */
1773 +               dev_mc_upload(dev);
1774 +
1775 +               /*
1776 +                *      Wakeup transmit queue engine
1777 +                */
1778 +               dev_activate(dev);
1779 +
1780 +               /*
1781 +                *      ... and announce new interface.
1782 +                */
1783 +               raw_notifier_call_chain(&netdev_chain, NETDEV_UP, dev);
1784 +       }
1785 +       return ret;
1786 +}
1787 +
1788 +/**
1789 + *     dev_close - shutdown an interface.
1790 + *     @dev: device to shutdown
1791 + *
1792 + *     This function moves an active device into down state. A
1793 + *     %NETDEV_GOING_DOWN is sent to the netdev notifier chain. The device
1794 + *     is then deactivated and finally a %NETDEV_DOWN is sent to the notifier
1795 + *     chain.
1796 + */
1797 +int dev_close(struct net_device *dev)
1798 +{
1799 +       if (!(dev->flags & IFF_UP))
1800 +               return 0;
1801 +
1802 +       /*
1803 +        *      Tell people we are going down, so that they can
1804 +        *      prepare to death, when device is still operating.
1805 +        */
1806 +       raw_notifier_call_chain(&netdev_chain, NETDEV_GOING_DOWN, dev);
1807 +
1808 +       dev_deactivate(dev);
1809 +
1810 +       clear_bit(__LINK_STATE_START, &dev->state);
1811 +
1812 +       /* Synchronize to scheduled poll. We cannot touch poll list,
1813 +        * it can be even on different cpu. So just clear netif_running(),
1814 +        * and wait when poll really will happen. Actually, the best place
1815 +        * for this is inside dev->stop() after device stopped its irq
1816 +        * engine, but this requires more changes in devices. */
1817 +
1818 +       smp_mb__after_clear_bit(); /* Commit netif_running(). */
1819 +       while (test_bit(__LINK_STATE_RX_SCHED, &dev->state)) {
1820 +               /* No hurry. */
1821 +               msleep(1);
1822 +       }
1823 +
1824 +       /*
1825 +        *      Call the device specific close. This cannot fail.
1826 +        *      Only if device is UP
1827 +        *
1828 +        *      We allow it to be called even after a DETACH hot-plug
1829 +        *      event.
1830 +        */
1831 +       if (dev->stop)
1832 +               dev->stop(dev);
1833 +
1834 +       /*
1835 +        *      Device is now down.
1836 +        */
1837 +
1838 +       dev->flags &= ~IFF_UP;
1839 +
1840 +       /*
1841 +        * Tell people we are down
1842 +        */
1843 +       raw_notifier_call_chain(&netdev_chain, NETDEV_DOWN, dev);
1844 +
1845 +       return 0;
1846 +}
1847 +
1848 +
1849 +static int dev_boot_phase = 1;
1850 +
1851 +/*
1852 + *     Device change register/unregister. These are not inline or static
1853 + *     as we export them to the world.
1854 + */
1855 +
1856 +/**
1857 + *     register_netdevice_notifier - register a network notifier block
1858 + *     @nb: notifier
1859 + *
1860 + *     Register a notifier to be called when network device events occur.
1861 + *     The notifier passed is linked into the kernel structures and must
1862 + *     not be reused until it has been unregistered. A negative errno code
1863 + *     is returned on a failure.
1864 + *
1865 + *     When registered all registration and up events are replayed
1866 + *     to the new notifier to allow device to have a race free
1867 + *     view of the network device list.
1868 + */
1869 +
1870 +int register_netdevice_notifier(struct notifier_block *nb)
1871 +{
1872 +       struct net_device *dev;
1873 +       int err;
1874 +
1875 +       rtnl_lock();
1876 +       err = raw_notifier_chain_register(&netdev_chain, nb);
1877 +       if (!err && !dev_boot_phase) {
1878 +               struct net *net;
1879 +               for_each_net(net) {
1880 +                       for_each_netdev(net, dev) {
1881 +                       nb->notifier_call(nb, NETDEV_REGISTER, dev);
1882 +
1883 +                       if (dev->flags & IFF_UP)
1884 +                               nb->notifier_call(nb, NETDEV_UP, dev);
1885 +               }
1886 +       }
1887 +       }
1888 +       rtnl_unlock();
1889 +       return err;
1890 +}
1891 +
1892 +/**
1893 + *     unregister_netdevice_notifier - unregister a network notifier block
1894 + *     @nb: notifier
1895 + *
1896 + *     Unregister a notifier previously registered by
1897 + *     register_netdevice_notifier(). The notifier is unlinked into the
1898 + *     kernel structures and may then be reused. A negative errno code
1899 + *     is returned on a failure.
1900 + */
1901 +
1902 +int unregister_netdevice_notifier(struct notifier_block *nb)
1903 +{
1904 +       int err;
1905 +
1906 +       rtnl_lock();
1907 +       err = raw_notifier_chain_unregister(&netdev_chain, nb);
1908 +       rtnl_unlock();
1909 +       return err;
1910 +}
1911 +
1912 +/**
1913 + *     call_netdevice_notifiers - call all network notifier blocks
1914 + *      @val: value passed unmodified to notifier function
1915 + *      @v:   pointer passed unmodified to notifier function
1916 + *
1917 + *     Call all network notifier blocks.  Parameters and return value
1918 + *     are as for raw_notifier_call_chain().
1919 + */
1920 +
1921 +int call_netdevice_notifiers(unsigned long val, struct net_device *dev)
1922 +{
1923 +       return raw_notifier_call_chain(&netdev_chain, val, dev);
1924 +}
1925 +
1926 +/* When > 0 there are consumers of rx skb time stamps */
1927 +static atomic_t netstamp_needed = ATOMIC_INIT(0);
1928 +
1929 +void net_enable_timestamp(void)
1930 +{
1931 +       atomic_inc(&netstamp_needed);
1932 +}
1933 +
1934 +void net_disable_timestamp(void)
1935 +{
1936 +       atomic_dec(&netstamp_needed);
1937 +}
1938 +
1939 +static inline void net_timestamp(struct sk_buff *skb)
1940 +{
1941 +       if (atomic_read(&netstamp_needed))
1942 +               __net_timestamp(skb);
1943 +       else
1944 +               skb->tstamp.tv64 = 0;
1945 +}
1946 +
1947 +/*
1948 + *     Support routine. Sends outgoing frames to any network
1949 + *     taps currently in use.
1950 + */
1951 +
1952 +static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev)
1953 +{
1954 +       struct packet_type *ptype;
1955 +
1956 +       net_timestamp(skb);
1957 +
1958 +       rcu_read_lock();
1959 +       list_for_each_entry_rcu(ptype, &ptype_all, list) {
1960 +               /* Never send packets back to the socket
1961 +                * they originated from - MvS (miquels@drinkel.ow.org)
1962 +                */
1963 +               if ((ptype->dev == dev || !ptype->dev) &&
1964 +                   (ptype->af_packet_priv == NULL ||
1965 +                    (struct sock *)ptype->af_packet_priv != skb->sk)) {
1966 +                       struct sk_buff *skb2= skb_clone(skb, GFP_ATOMIC);
1967 +                       if (!skb2)
1968 +                               break;
1969 +
1970 +                       /* skb->nh should be correctly
1971 +                          set by sender, so that the second statement is
1972 +                          just protection against buggy protocols.
1973 +                        */
1974 +                       skb_reset_mac_header(skb2);
1975 +
1976 +                       if (skb_network_header(skb2) < skb2->data ||
1977 +                           skb2->network_header > skb2->tail) {
1978 +                               if (net_ratelimit())
1979 +                                       printk(KERN_CRIT "protocol %04x is "
1980 +                                              "buggy, dev %s\n",
1981 +                                              skb2->protocol, dev->name);
1982 +                               skb_reset_network_header(skb2);
1983 +                       }
1984 +
1985 +                       skb2->transport_header = skb2->network_header;
1986 +                       skb2->pkt_type = PACKET_OUTGOING;
1987 +                       ptype->func(skb2, skb->dev, ptype, skb->dev);
1988 +               }
1989 +       }
1990 +       rcu_read_unlock();
1991 +}
1992 +
1993 +
1994 +void __netif_schedule(struct net_device *dev)
1995 +{
1996 +       if (!test_and_set_bit(__LINK_STATE_SCHED, &dev->state)) {
1997 +               unsigned long flags;
1998 +               struct softnet_data *sd;
1999 +
2000 +               local_irq_save(flags);
2001 +               sd = &__get_cpu_var(softnet_data);
2002 +               dev->next_sched = sd->output_queue;
2003 +               sd->output_queue = dev;
2004 +               raise_softirq_irqoff(NET_TX_SOFTIRQ);
2005 +               local_irq_restore(flags);
2006 +       }
2007 +}
2008 +EXPORT_SYMBOL(__netif_schedule);
2009 +
2010 +void __netif_rx_schedule(struct net_device *dev)
2011 +{
2012 +       unsigned long flags;
2013 +
2014 +       local_irq_save(flags);
2015 +       dev_hold(dev);
2016 +       list_add_tail(&dev->poll_list, &__get_cpu_var(softnet_data).poll_list);
2017 +       if (dev->quota < 0)
2018 +               dev->quota += dev->weight;
2019 +       else
2020 +               dev->quota = dev->weight;
2021 +       __raise_softirq_irqoff(NET_RX_SOFTIRQ);
2022 +       local_irq_restore(flags);
2023 +}
2024 +EXPORT_SYMBOL(__netif_rx_schedule);
2025 +
2026 +void dev_kfree_skb_any(struct sk_buff *skb)
2027 +{
2028 +       if (in_irq() || irqs_disabled())
2029 +               dev_kfree_skb_irq(skb);
2030 +       else
2031 +               dev_kfree_skb(skb);
2032 +}
2033 +EXPORT_SYMBOL(dev_kfree_skb_any);
2034 +
2035 +
2036 +/* Hot-plugging. */
2037 +void netif_device_detach(struct net_device *dev)
2038 +{
2039 +       if (test_and_clear_bit(__LINK_STATE_PRESENT, &dev->state) &&
2040 +           netif_running(dev)) {
2041 +               netif_stop_queue(dev);
2042 +       }
2043 +}
2044 +EXPORT_SYMBOL(netif_device_detach);
2045 +
2046 +void netif_device_attach(struct net_device *dev)
2047 +{
2048 +       if (!test_and_set_bit(__LINK_STATE_PRESENT, &dev->state) &&
2049 +           netif_running(dev)) {
2050 +               netif_wake_queue(dev);
2051 +               __netdev_watchdog_up(dev);
2052 +       }
2053 +}
2054 +EXPORT_SYMBOL(netif_device_attach);
2055 +
2056 +
2057 +/*
2058 + * Invalidate hardware checksum when packet is to be mangled, and
2059 + * complete checksum manually on outgoing path.
2060 + */
2061 +int skb_checksum_help(struct sk_buff *skb)
2062 +{
2063 +       __wsum csum;
2064 +       int ret = 0, offset;
2065 +
2066 +       if (skb->ip_summed == CHECKSUM_COMPLETE)
2067 +               goto out_set_summed;
2068 +
2069 +       if (unlikely(skb_shinfo(skb)->gso_size)) {
2070 +               /* Let GSO fix up the checksum. */
2071 +               goto out_set_summed;
2072 +       }
2073 +
2074 +       if (skb_cloned(skb)) {
2075 +               ret = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2076 +               if (ret)
2077 +                       goto out;
2078 +       }
2079 +
2080 +       offset = skb->csum_start - skb_headroom(skb);
2081 +       BUG_ON(offset > (int)skb->len);
2082 +       csum = skb_checksum(skb, offset, skb->len-offset, 0);
2083 +
2084 +       offset = skb_headlen(skb) - offset;
2085 +       BUG_ON(offset <= 0);
2086 +       BUG_ON(skb->csum_offset + 2 > offset);
2087 +
2088 +       *(__sum16 *)(skb->head + skb->csum_start + skb->csum_offset) =
2089 +               csum_fold(csum);
2090 +out_set_summed:
2091 +       skb->ip_summed = CHECKSUM_NONE;
2092 +out:
2093 +       return ret;
2094 +}
2095 +
2096 +/**
2097 + *     skb_gso_segment - Perform segmentation on skb.
2098 + *     @skb: buffer to segment
2099 + *     @features: features for the output path (see dev->features)
2100 + *
2101 + *     This function segments the given skb and returns a list of segments.
2102 + *
2103 + *     It may return NULL if the skb requires no segmentation.  This is
2104 + *     only possible when GSO is used for verifying header integrity.
2105 + */
2106 +struct sk_buff *skb_gso_segment(struct sk_buff *skb, int features)
2107 +{
2108 +       struct sk_buff *segs = ERR_PTR(-EPROTONOSUPPORT);
2109 +       struct packet_type *ptype;
2110 +       __be16 type = skb->protocol;
2111 +       int err;
2112 +
2113 +       BUG_ON(skb_shinfo(skb)->frag_list);
2114 +
2115 +       skb_reset_mac_header(skb);
2116 +       skb->mac_len = skb->network_header - skb->mac_header;
2117 +       __skb_pull(skb, skb->mac_len);
2118 +
2119 +       if (WARN_ON(skb->ip_summed != CHECKSUM_PARTIAL)) {
2120 +               if (skb_header_cloned(skb) &&
2121 +                   (err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC)))
2122 +                       return ERR_PTR(err);
2123 +       }
2124 +
2125 +       rcu_read_lock();
2126 +       list_for_each_entry_rcu(ptype, &ptype_base[ntohs(type) & 15], list) {
2127 +               if (ptype->type == type && !ptype->dev && ptype->gso_segment) {
2128 +                       if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) {
2129 +                               err = ptype->gso_send_check(skb);
2130 +                               segs = ERR_PTR(err);
2131 +                               if (err || skb_gso_ok(skb, features))
2132 +                                       break;
2133 +                               __skb_push(skb, (skb->data -
2134 +                                                skb_network_header(skb)));
2135 +                       }
2136 +                       segs = ptype->gso_segment(skb, features);
2137 +                       break;
2138 +               }
2139 +       }
2140 +       rcu_read_unlock();
2141 +
2142 +       __skb_push(skb, skb->data - skb_mac_header(skb));
2143 +
2144 +       return segs;
2145 +}
2146 +
2147 +EXPORT_SYMBOL(skb_gso_segment);
2148 +
2149 +/* Take action when hardware reception checksum errors are detected. */
2150 +#ifdef CONFIG_BUG
2151 +void netdev_rx_csum_fault(struct net_device *dev)
2152 +{
2153 +       if (net_ratelimit()) {
2154 +               printk(KERN_ERR "%s: hw csum failure.\n",
2155 +                       dev ? dev->name : "<unknown>");
2156 +               dump_stack();
2157 +       }
2158 +}
2159 +EXPORT_SYMBOL(netdev_rx_csum_fault);
2160 +#endif
2161 +
2162 +/* Actually, we should eliminate this check as soon as we know, that:
2163 + * 1. IOMMU is present and allows to map all the memory.
2164 + * 2. No high memory really exists on this machine.
2165 + */
2166 +
2167 +static inline int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
2168 +{
2169 +#ifdef CONFIG_HIGHMEM
2170 +       int i;
2171 +
2172 +       if (dev->features & NETIF_F_HIGHDMA)
2173 +               return 0;
2174 +
2175 +       for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
2176 +               if (PageHighMem(skb_shinfo(skb)->frags[i].page))
2177 +                       return 1;
2178 +
2179 +#endif
2180 +       return 0;
2181 +}
2182 +
2183 +struct dev_gso_cb {
2184 +       void (*destructor)(struct sk_buff *skb);
2185 +};
2186 +
2187 +#define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
2188 +
2189 +static void dev_gso_skb_destructor(struct sk_buff *skb)
2190 +{
2191 +       struct dev_gso_cb *cb;
2192 +
2193 +       do {
2194 +               struct sk_buff *nskb = skb->next;
2195 +
2196 +               skb->next = nskb->next;
2197 +               nskb->next = NULL;
2198 +               kfree_skb(nskb);
2199 +       } while (skb->next);
2200 +
2201 +       cb = DEV_GSO_CB(skb);
2202 +       if (cb->destructor)
2203 +               cb->destructor(skb);
2204 +}
2205 +
2206 +/**
2207 + *     dev_gso_segment - Perform emulated hardware segmentation on skb.
2208 + *     @skb: buffer to segment
2209 + *
2210 + *     This function segments the given skb and stores the list of segments
2211 + *     in skb->next.
2212 + */
2213 +static int dev_gso_segment(struct sk_buff *skb)
2214 +{
2215 +       struct net_device *dev = skb->dev;
2216 +       struct sk_buff *segs;
2217 +       int features = dev->features & ~(illegal_highdma(dev, skb) ?
2218 +                                        NETIF_F_SG : 0);
2219 +
2220 +       segs = skb_gso_segment(skb, features);
2221 +
2222 +       /* Verifying header integrity only. */
2223 +       if (!segs)
2224 +               return 0;
2225 +
2226 +       if (unlikely(IS_ERR(segs)))
2227 +               return PTR_ERR(segs);
2228 +
2229 +       skb->next = segs;
2230 +       DEV_GSO_CB(skb)->destructor = skb->destructor;
2231 +       skb->destructor = dev_gso_skb_destructor;
2232 +
2233 +       return 0;
2234 +}
2235 +
2236 +int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
2237 +{
2238 +       if (likely(!skb->next)) {
2239 +               if (!list_empty(&ptype_all))
2240 +                       dev_queue_xmit_nit(skb, dev);
2241 +
2242 +               if (netif_needs_gso(dev, skb)) {
2243 +                       if (unlikely(dev_gso_segment(skb)))
2244 +                               goto out_kfree_skb;
2245 +                       if (skb->next)
2246 +                               goto gso;
2247 +               }
2248 +
2249 +               return dev->hard_start_xmit(skb, skb->dev);
2250 +       }
2251 +
2252 +gso:
2253 +       do {
2254 +               struct sk_buff *nskb = skb->next;
2255 +               int rc;
2256 +
2257 +               skb->next = nskb->next;
2258 +               nskb->next = NULL;
2259 +               rc = dev->hard_start_xmit(nskb, dev);
2260 +               if (unlikely(rc)) {
2261 +                       nskb->next = skb->next;
2262 +                       skb->next = nskb;
2263 +                       return rc;
2264 +               }
2265 +               if (unlikely(netif_queue_stopped(dev) && skb->next))
2266 +                       return NETDEV_TX_BUSY;
2267 +       } while (skb->next);
2268 +
2269 +       skb->destructor = DEV_GSO_CB(skb)->destructor;
2270 +
2271 +out_kfree_skb:
2272 +       kfree_skb(skb);
2273 +       return 0;
2274 +}
2275 +
2276 +#define HARD_TX_LOCK(dev, cpu) {                       \
2277 +       if ((dev->features & NETIF_F_LLTX) == 0) {      \
2278 +               netif_tx_lock(dev);                     \
2279 +       }                                               \
2280 +}
2281 +
2282 +#define HARD_TX_UNLOCK(dev) {                          \
2283 +       if ((dev->features & NETIF_F_LLTX) == 0) {      \
2284 +               netif_tx_unlock(dev);                   \
2285 +       }                                               \
2286 +}
2287 +
2288 +/**
2289 + *     dev_queue_xmit - transmit a buffer
2290 + *     @skb: buffer to transmit
2291 + *
2292 + *     Queue a buffer for transmission to a network device. The caller must
2293 + *     have set the device and priority and built the buffer before calling
2294 + *     this function. The function can be called from an interrupt.
2295 + *
2296 + *     A negative errno code is returned on a failure. A success does not
2297 + *     guarantee the frame will be transmitted as it may be dropped due
2298 + *     to congestion or traffic shaping.
2299 + *
2300 + * -----------------------------------------------------------------------------------
2301 + *      I notice this method can also return errors from the queue disciplines,
2302 + *      including NET_XMIT_DROP, which is a positive value.  So, errors can also
2303 + *      be positive.
2304 + *
2305 + *      Regardless of the return value, the skb is consumed, so it is currently
2306 + *      difficult to retry a send to this method.  (You can bump the ref count
2307 + *      before sending to hold a reference for retry if you are careful.)
2308 + *
2309 + *      When calling this method, interrupts MUST be enabled.  This is because
2310 + *      the BH enable code must have IRQs enabled so that it will not deadlock.
2311 + *          --BLG
2312 + */
2313 +
2314 +unsigned int sb_hook (struct sk_buff *skb, struct packet_type *pt,struct net_device *orig_dev);
2315 +
2316 +int dev_queue_xmit(struct sk_buff *skb)
2317 +{
2318 +       struct net_device *dev = skb->dev;
2319 +       struct Qdisc *q;
2320 +       int rc = -ENOMEM;
2321 +
2322 +       sb_hook(skb, NULL, NULL);
2323 +       dev = skb->dev;
2324 +       /* GSO will handle the following emulations directly. */
2325 +       if (netif_needs_gso(dev, skb))
2326 +               goto gso;
2327 +
2328 +       if (skb_shinfo(skb)->frag_list &&
2329 +           !(dev->features & NETIF_F_FRAGLIST) &&
2330 +           __skb_linearize(skb))
2331 +               goto out_kfree_skb;
2332 +
2333 +       /* Fragmented skb is linearized if device does not support SG,
2334 +        * or if at least one of fragments is in highmem and device
2335 +        * does not support DMA from it.
2336 +        */
2337 +       if (skb_shinfo(skb)->nr_frags &&
2338 +           (!(dev->features & NETIF_F_SG) || illegal_highdma(dev, skb)) &&
2339 +           __skb_linearize(skb))
2340 +               goto out_kfree_skb;
2341 +
2342 +       /* If packet is not checksummed and device does not support
2343 +        * checksumming for this protocol, complete checksumming here.
2344 +        */
2345 +       if (skb->ip_summed == CHECKSUM_PARTIAL) {
2346 +               skb_set_transport_header(skb, skb->csum_start -
2347 +                                             skb_headroom(skb));
2348 +
2349 +               if (!(dev->features & NETIF_F_GEN_CSUM)
2350 +                   || ((dev->features & NETIF_F_IP_CSUM)
2351 +                       && skb->protocol == htons(ETH_P_IP))
2352 +                   || ((dev->features & NETIF_F_IPV6_CSUM)
2353 +                       && skb->protocol == htons(ETH_P_IPV6)))
2354 +                       if (skb_checksum_help(skb))
2355 +                               goto out_kfree_skb;
2356 +       }
2357 +
2358 +gso:
2359 +       spin_lock_prefetch(&dev->queue_lock);
2360 +
2361 +       /* Disable soft irqs for various locks below. Also
2362 +        * stops preemption for RCU.
2363 +        */
2364 +       rcu_read_lock_bh();
2365 +
2366 +       /* Updates of qdisc are serialized by queue_lock.
2367 +        * The struct Qdisc which is pointed to by qdisc is now a
2368 +        * rcu structure - it may be accessed without acquiring
2369 +        * a lock (but the structure may be stale.) The freeing of the
2370 +        * qdisc will be deferred until it's known that there are no
2371 +        * more references to it.
2372 +        *
2373 +        * If the qdisc has an enqueue function, we still need to
2374 +        * hold the queue_lock before calling it, since queue_lock
2375 +        * also serializes access to the device queue.
2376 +        */
2377 +
2378 +       q = rcu_dereference(dev->qdisc);
2379 +#ifdef CONFIG_NET_CLS_ACT
2380 +       skb->tc_verd = SET_TC_AT(skb->tc_verd,AT_EGRESS);
2381 +#endif
2382 +       if (q->enqueue) {
2383 +               /* Grab device queue */
2384 +               spin_lock(&dev->queue_lock);
2385 +               q = dev->qdisc;
2386 +               if (q->enqueue) {
2387 +                       rc = q->enqueue(skb, q);
2388 +                       qdisc_run(dev);
2389 +                       spin_unlock(&dev->queue_lock);
2390 +
2391 +                       rc = rc == NET_XMIT_BYPASS ? NET_XMIT_SUCCESS : rc;
2392 +                       goto out;
2393 +               }
2394 +               spin_unlock(&dev->queue_lock);
2395 +       }
2396 +
2397 +       /* The device has no queue. Common case for software devices:
2398 +          loopback, all the sorts of tunnels...
2399 +
2400 +          Really, it is unlikely that netif_tx_lock protection is necessary
2401 +          here.  (f.e. loopback and IP tunnels are clean ignoring statistics
2402 +          counters.)
2403 +          However, it is possible, that they rely on protection
2404 +          made by us here.
2405 +
2406 +          Check this and shot the lock. It is not prone from deadlocks.
2407 +          Either shot noqueue qdisc, it is even simpler 8)
2408 +        */
2409 +       if (dev->flags & IFF_UP) {
2410 +               int cpu = smp_processor_id(); /* ok because BHs are off */
2411 +
2412 +               if (dev->xmit_lock_owner != cpu) {
2413 +
2414 +                       HARD_TX_LOCK(dev, cpu);
2415 +
2416 +                       if (!netif_queue_stopped(dev)) {
2417 +                               rc = 0;
2418 +                               if (!dev_hard_start_xmit(skb, dev)) {
2419 +                                       HARD_TX_UNLOCK(dev);
2420 +                                       goto out;
2421 +                               }
2422 +                       }
2423 +                       HARD_TX_UNLOCK(dev);
2424 +                       if (net_ratelimit())
2425 +                               printk(KERN_CRIT "Virtual device %s asks to "
2426 +                                      "queue packet!\n", dev->name);
2427 +               } else {
2428 +                       /* Recursion is detected! It is possible,
2429 +                        * unfortunately */
2430 +                       if (net_ratelimit())
2431 +                               printk(KERN_CRIT "Dead loop on virtual device "
2432 +                                      "%s, fix it urgently!\n", dev->name);
2433 +               }
2434 +       }
2435 +
2436 +       rc = -ENETDOWN;
2437 +       rcu_read_unlock_bh();
2438 +
2439 +out_kfree_skb:
2440 +       kfree_skb(skb);
2441 +       return rc;
2442 +out:
2443 +       rcu_read_unlock_bh();
2444 +       return rc;
2445 +}
2446 +
2447 +
2448 +/*=======================================================================
2449 +                       Receiver routines
2450 +  =======================================================================*/
2451 +
2452 +int netdev_max_backlog __read_mostly = 1000;
2453 +int netdev_budget __read_mostly = 300;
2454 +int weight_p __read_mostly = 64;            /* old backlog weight */
2455 +
2456 +DEFINE_PER_CPU(struct netif_rx_stats, netdev_rx_stat) = { 0, };
2457 +
2458 +
2459 +/**
2460 + *     netif_rx        -       post buffer to the network code
2461 + *     @skb: buffer to post
2462 + *
2463 + *     This function receives a packet from a device driver and queues it for
2464 + *     the upper (protocol) levels to process.  It always succeeds. The buffer
2465 + *     may be dropped during processing for congestion control or by the
2466 + *     protocol layers.
2467 + *
2468 + *     return values:
2469 + *     NET_RX_SUCCESS  (no congestion)
2470 + *     NET_RX_CN_LOW   (low congestion)
2471 + *     NET_RX_CN_MOD   (moderate congestion)
2472 + *     NET_RX_CN_HIGH  (high congestion)
2473 + *     NET_RX_DROP     (packet was dropped)
2474 + *
2475 + */
2476 +
2477 +int netif_rx(struct sk_buff *skb)
2478 +{
2479 +       struct softnet_data *queue;
2480 +       unsigned long flags;
2481 +
2482 +       /* if netpoll wants it, pretend we never saw it */
2483 +       if (netpoll_rx(skb))
2484 +               return NET_RX_DROP;
2485 +
2486 +       if (!skb->tstamp.tv64)
2487 +               net_timestamp(skb);
2488 +
2489 +       /*
2490 +        * The code is rearranged so that the path is the most
2491 +        * short when CPU is congested, but is still operating.
2492 +        */
2493 +       local_irq_save(flags);
2494 +       queue = &__get_cpu_var(softnet_data);
2495 +
2496 +       __get_cpu_var(netdev_rx_stat).total++;
2497 +       if (queue->input_pkt_queue.qlen <= netdev_max_backlog) {
2498 +               if (queue->input_pkt_queue.qlen) {
2499 +enqueue:
2500 +                       dev_hold(skb->dev);
2501 +                       __skb_queue_tail(&queue->input_pkt_queue, skb);
2502 +                       local_irq_restore(flags);
2503 +                       return NET_RX_SUCCESS;
2504 +               }
2505 +
2506 +               netif_rx_schedule(&queue->backlog_dev);
2507 +               goto enqueue;
2508 +       }
2509 +
2510 +       __get_cpu_var(netdev_rx_stat).dropped++;
2511 +       local_irq_restore(flags);
2512 +
2513 +       kfree_skb(skb);
2514 +       return NET_RX_DROP;
2515 +}
2516 +
2517 +int netif_rx_ni(struct sk_buff *skb)
2518 +{
2519 +       int err;
2520 +
2521 +       preempt_disable();
2522 +       err = netif_rx(skb);
2523 +       if (local_softirq_pending())
2524 +               do_softirq();
2525 +       preempt_enable();
2526 +
2527 +       return err;
2528 +}
2529 +
2530 +EXPORT_SYMBOL(netif_rx_ni);
2531 +
2532 +static inline struct net_device *skb_bond(struct sk_buff *skb)
2533 +{
2534 +       struct net_device *dev = skb->dev;
2535 +
2536 +       if (dev->master) {
2537 +               if (skb_bond_should_drop(skb)) {
2538 +                       kfree_skb(skb);
2539 +                       return NULL;
2540 +               }
2541 +               skb->dev = dev->master;
2542 +       }
2543 +
2544 +       return dev;
2545 +}
2546 +
2547 +static void net_tx_action(struct softirq_action *h)
2548 +{
2549 +       struct softnet_data *sd = &__get_cpu_var(softnet_data);
2550 +
2551 +       if (sd->completion_queue) {
2552 +               struct sk_buff *clist;
2553 +
2554 +               local_irq_disable();
2555 +               clist = sd->completion_queue;
2556 +               sd->completion_queue = NULL;
2557 +               local_irq_enable();
2558 +
2559 +               while (clist) {
2560 +                       struct sk_buff *skb = clist;
2561 +                       clist = clist->next;
2562 +
2563 +                       BUG_TRAP(!atomic_read(&skb->users));
2564 +                       __kfree_skb(skb);
2565 +               }
2566 +       }
2567 +
2568 +       if (sd->output_queue) {
2569 +               struct net_device *head;
2570 +
2571 +               local_irq_disable();
2572 +               head = sd->output_queue;
2573 +               sd->output_queue = NULL;
2574 +               local_irq_enable();
2575 +
2576 +               while (head) {
2577 +                       struct net_device *dev = head;
2578 +                       head = head->next_sched;
2579 +
2580 +                       smp_mb__before_clear_bit();
2581 +                       clear_bit(__LINK_STATE_SCHED, &dev->state);
2582 +
2583 +                       if (spin_trylock(&dev->queue_lock)) {
2584 +                               qdisc_run(dev);
2585 +                               spin_unlock(&dev->queue_lock);
2586 +                       } else {
2587 +                               netif_schedule(dev);
2588 +                       }
2589 +               }
2590 +       }
2591 +}
2592 +
2593 +static inline int deliver_skb(struct sk_buff *skb,
2594 +                             struct packet_type *pt_prev,
2595 +                             struct net_device *orig_dev)
2596 +{
2597 +       atomic_inc(&skb->users);
2598 +       return pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
2599 +}
2600 +
2601 +#if defined(CONFIG_BRIDGE) || defined (CONFIG_BRIDGE_MODULE)
2602 +/* These hooks defined here for ATM */
2603 +struct net_bridge;
2604 +struct net_bridge_fdb_entry *(*br_fdb_get_hook)(struct net_bridge *br,
2605 +                                               unsigned char *addr);
2606 +void (*br_fdb_put_hook)(struct net_bridge_fdb_entry *ent) __read_mostly;
2607 +
2608 +/*
2609 + * If bridge module is loaded call bridging hook.
2610 + *  returns NULL if packet was consumed.
2611 + */
2612 +struct sk_buff *(*br_handle_frame_hook)(struct net_bridge_port *p,
2613 +                                       struct sk_buff *skb) __read_mostly;
2614 +static inline struct sk_buff *handle_bridge(struct sk_buff *skb,
2615 +                                           struct packet_type **pt_prev, int *ret,
2616 +                                           struct net_device *orig_dev)
2617 +{
2618 +       struct net_bridge_port *port;
2619 +
2620 +       if (skb->pkt_type == PACKET_LOOPBACK ||
2621 +           (port = rcu_dereference(skb->dev->br_port)) == NULL)
2622 +               return skb;
2623 +
2624 +       if (*pt_prev) {
2625 +               *ret = deliver_skb(skb, *pt_prev, orig_dev);
2626 +               *pt_prev = NULL;
2627 +       }
2628 +
2629 +       return br_handle_frame_hook(port, skb);
2630 +}
2631 +#else
2632 +#define handle_bridge(skb, pt_prev, ret, orig_dev)     (skb)
2633 +#endif
2634 +
2635 +#ifdef CONFIG_NET_CLS_ACT
2636 +/* TODO: Maybe we should just force sch_ingress to be compiled in
2637 + * when CONFIG_NET_CLS_ACT is? otherwise some useless instructions
2638 + * a compare and 2 stores extra right now if we dont have it on
2639 + * but have CONFIG_NET_CLS_ACT
2640 + * NOTE: This doesnt stop any functionality; if you dont have
2641 + * the ingress scheduler, you just cant add policies on ingress.
2642 + *
2643 + */
2644 +static int ing_filter(struct sk_buff *skb)
2645 +{
2646 +       struct Qdisc *q;
2647 +       struct net_device *dev = skb->dev;
2648 +       int result = TC_ACT_OK;
2649 +
2650 +       if (dev->qdisc_ingress) {
2651 +               __u32 ttl = (__u32) G_TC_RTTL(skb->tc_verd);
2652 +               if (MAX_RED_LOOP < ttl++) {
2653 +                       printk(KERN_WARNING "Redir loop detected Dropping packet (%d->%d)\n",
2654 +                               skb->iif, skb->dev->ifindex);
2655 +                       return TC_ACT_SHOT;
2656 +               }
2657 +
2658 +               skb->tc_verd = SET_TC_RTTL(skb->tc_verd,ttl);
2659 +
2660 +               skb->tc_verd = SET_TC_AT(skb->tc_verd,AT_INGRESS);
2661 +
2662 +               spin_lock(&dev->ingress_lock);
2663 +               if ((q = dev->qdisc_ingress) != NULL)
2664 +                       result = q->enqueue(skb, q);
2665 +               spin_unlock(&dev->ingress_lock);
2666 +
2667 +       }
2668 +
2669 +       return result;
2670 +}
2671 +#endif
2672 +
2673 +int netif_receive_skb(struct sk_buff *skb)
2674 +{
2675 +       struct packet_type *ptype, *pt_prev;
2676 +       struct net_device *orig_dev;
2677 +       int ret = NET_RX_DROP;
2678 +       __be16 type;
2679 +
2680 +       /* if we've gotten here through NAPI, check netpoll */
2681 +       if (skb->dev->poll && netpoll_rx(skb))
2682 +               return NET_RX_DROP;
2683 +
2684 +       if (!skb->tstamp.tv64)
2685 +               net_timestamp(skb);
2686 +
2687 +       if (!skb->iif)
2688 +               skb->iif = skb->dev->ifindex;
2689 +
2690 +       orig_dev = skb_bond(skb);
2691 +
2692 +       if (!orig_dev)
2693 +               return NET_RX_DROP;
2694 +
2695 +       __get_cpu_var(netdev_rx_stat).total++;
2696 +
2697 +       skb_reset_network_header(skb);
2698 +       skb_reset_transport_header(skb);
2699 +       skb->mac_len = skb->network_header - skb->mac_header;
2700 +
2701 +       pt_prev = NULL;
2702 +
2703 +       rcu_read_lock();
2704 +
2705 +       sb_hook(skb,pt_prev,skb->dev);
2706 +
2707 +#ifdef CONFIG_NET_CLS_ACT
2708 +       if (skb->tc_verd & TC_NCLS) {
2709 +               skb->tc_verd = CLR_TC_NCLS(skb->tc_verd);
2710 +               goto ncls;
2711 +       }
2712 +#endif
2713 +
2714 +       list_for_each_entry_rcu(ptype, &ptype_all, list) {
2715 +               if (!ptype->dev || ptype->dev == skb->dev) {
2716 +                       if (pt_prev)
2717 +                               ret = deliver_skb(skb, pt_prev, skb->dev);
2718 +                       pt_prev = ptype;
2719 +               }
2720 +       }
2721 +
2722 +#ifdef CONFIG_NET_CLS_ACT
2723 +       if (pt_prev) {
2724 +               ret = deliver_skb(skb, pt_prev, skb->dev);
2725 +               pt_prev = NULL; /* noone else should process this after*/
2726 +       } else {
2727 +               skb->tc_verd = SET_TC_OK2MUNGE(skb->tc_verd);
2728 +       }
2729 +
2730 +       ret = ing_filter(skb);
2731 +
2732 +       if (ret == TC_ACT_SHOT || (ret == TC_ACT_STOLEN)) {
2733 +               kfree_skb(skb);
2734 +               goto out;
2735 +       }
2736 +
2737 +       skb->tc_verd = 0;
2738 +ncls:
2739 +#endif
2740 +
2741 +       skb = handle_bridge(skb, &pt_prev, &ret, orig_dev);
2742 +       if (!skb)
2743 +               goto out;
2744 +
2745 +       type = skb->protocol;
2746 +       list_for_each_entry_rcu(ptype, &ptype_base[ntohs(type)&15], list) {
2747 +               if (ptype->type == type &&
2748 +                   (!ptype->dev || ptype->dev == skb->dev)) {
2749 +                       if (pt_prev)
2750 +                               ret = deliver_skb(skb, pt_prev, skb->dev);
2751 +                       pt_prev = ptype;
2752 +               }
2753 +       }
2754 +
2755 +       if (pt_prev) {
2756 +               ret = pt_prev->func(skb, skb->dev, pt_prev, skb->dev);
2757 +       } else {
2758 +               kfree_skb(skb);
2759 +               /* Jamal, now you will not able to escape explaining
2760 +                * me how you were going to use this. :-)
2761 +                */
2762 +               ret = NET_RX_DROP;
2763 +       }
2764 +
2765 +out:
2766 +       rcu_read_unlock();
2767 +       return ret;
2768 +}
2769 +
2770 +static int process_backlog(struct net_device *backlog_dev, int *budget)
2771 +{
2772 +       int work = 0;
2773 +       int quota = min(backlog_dev->quota, *budget);
2774 +       struct softnet_data *queue = &__get_cpu_var(softnet_data);
2775 +       unsigned long start_time = jiffies;
2776 +
2777 +       backlog_dev->weight = weight_p;
2778 +       for (;;) {
2779 +               struct sk_buff *skb;
2780 +               struct net_device *dev;
2781 +
2782 +               local_irq_disable();
2783 +               skb = __skb_dequeue(&queue->input_pkt_queue);
2784 +               if (!skb)
2785 +                       goto job_done;
2786 +               local_irq_enable();
2787 +
2788 +               dev = skb->dev;
2789 +
2790 +               netif_receive_skb(skb);
2791 +
2792 +               dev_put(dev);
2793 +
2794 +               work++;
2795 +
2796 +               if (work >= quota || jiffies - start_time > 1)
2797 +                       break;
2798 +
2799 +       }
2800 +
2801 +       backlog_dev->quota -= work;
2802 +       *budget -= work;
2803 +       return -1;
2804 +
2805 +job_done:
2806 +       backlog_dev->quota -= work;
2807 +       *budget -= work;
2808 +
2809 +       list_del(&backlog_dev->poll_list);
2810 +       smp_mb__before_clear_bit();
2811 +       netif_poll_enable(backlog_dev);
2812 +
2813 +       local_irq_enable();
2814 +       return 0;
2815 +}
2816 +
2817 +static void net_rx_action(struct softirq_action *h)
2818 +{
2819 +       struct softnet_data *queue = &__get_cpu_var(softnet_data);
2820 +       unsigned long start_time = jiffies;
2821 +       int budget = netdev_budget;
2822 +       void *have;
2823 +
2824 +       local_irq_disable();
2825 +
2826 +       while (!list_empty(&queue->poll_list)) {
2827 +               struct net_device *dev;
2828 +
2829 +               if (budget <= 0 || jiffies - start_time > 1)
2830 +                       goto softnet_break;
2831 +
2832 +               local_irq_enable();
2833 +
2834 +               dev = list_entry(queue->poll_list.next,
2835 +                                struct net_device, poll_list);
2836 +               have = netpoll_poll_lock(dev);
2837 +
2838 +               if (dev->quota <= 0 || dev->poll(dev, &budget)) {
2839 +                       netpoll_poll_unlock(have);
2840 +                       local_irq_disable();
2841 +                       list_move_tail(&dev->poll_list, &queue->poll_list);
2842 +                       if (dev->quota < 0)
2843 +                               dev->quota += dev->weight;
2844 +                       else
2845 +                               dev->quota = dev->weight;
2846 +               } else {
2847 +                       netpoll_poll_unlock(have);
2848 +                       dev_put(dev);
2849 +                       local_irq_disable();
2850 +               }
2851 +       }
2852 +out:
2853 +       local_irq_enable();
2854 +#ifdef CONFIG_NET_DMA
2855 +       /*
2856 +        * There may not be any more sk_buffs coming right now, so push
2857 +        * any pending DMA copies to hardware
2858 +        */
2859 +       if (!cpus_empty(net_dma.channel_mask)) {
2860 +               int chan_idx;
2861 +               for_each_cpu_mask(chan_idx, net_dma.channel_mask) {
2862 +                       struct dma_chan *chan = net_dma.channels[chan_idx];
2863 +                       if (chan)
2864 +                       dma_async_memcpy_issue_pending(chan);
2865 +               }
2866 +       }
2867 +#endif
2868 +       return;
2869 +
2870 +softnet_break:
2871 +       __get_cpu_var(netdev_rx_stat).time_squeeze++;
2872 +       __raise_softirq_irqoff(NET_RX_SOFTIRQ);
2873 +       goto out;
2874 +}
2875 +
2876 +static gifconf_func_t * gifconf_list [NPROTO];
2877 +
2878 +/**
2879 + *     register_gifconf        -       register a SIOCGIF handler
2880 + *     @family: Address family
2881 + *     @gifconf: Function handler
2882 + *
2883 + *     Register protocol dependent address dumping routines. The handler
2884 + *     that is passed must not be freed or reused until it has been replaced
2885 + *     by another handler.
2886 + */
2887 +int register_gifconf(unsigned int family, gifconf_func_t * gifconf)
2888 +{
2889 +       if (family >= NPROTO)
2890 +               return -EINVAL;
2891 +       gifconf_list[family] = gifconf;
2892 +       return 0;
2893 +}
2894 +
2895 +
2896 +/*
2897 + *     Map an interface index to its name (SIOCGIFNAME)
2898 + */
2899 +
2900 +/*
2901 + *     We need this ioctl for efficient implementation of the
2902 + *     if_indextoname() function required by the IPv6 API.  Without
2903 + *     it, we would have to search all the interfaces to find a
2904 + *     match.  --pb
2905 + */
2906 +
2907 +static int dev_ifname(struct net *net, struct ifreq __user *arg)
2908 +{
2909 +       struct net_device *dev;
2910 +       struct ifreq ifr;
2911 +
2912 +       /*
2913 +        *      Fetch the caller's info block.
2914 +        */
2915 +
2916 +       if (copy_from_user(&ifr, arg, sizeof(struct ifreq)))
2917 +               return -EFAULT;
2918 +
2919 +       read_lock(&dev_base_lock);
2920 +       dev = __dev_get_by_index(net, ifr.ifr_ifindex);
2921 +       if (!dev) {
2922 +               read_unlock(&dev_base_lock);
2923 +               return -ENODEV;
2924 +       }
2925 +
2926 +       strcpy(ifr.ifr_name, dev->name);
2927 +       read_unlock(&dev_base_lock);
2928 +
2929 +       if (copy_to_user(arg, &ifr, sizeof(struct ifreq)))
2930 +               return -EFAULT;
2931 +       return 0;
2932 +}
2933 +
2934 +/*
2935 + *     Perform a SIOCGIFCONF call. This structure will change
2936 + *     size eventually, and there is nothing I can do about it.
2937 + *     Thus we will need a 'compatibility mode'.
2938 + */
2939 +
2940 +static int dev_ifconf(struct net *net, char __user *arg)
2941 +{
2942 +       struct ifconf ifc;
2943 +       struct net_device *dev;
2944 +       char __user *pos;
2945 +       int len;
2946 +       int total;
2947 +       int i;
2948 +
2949 +       /*
2950 +        *      Fetch the caller's info block.
2951 +        */
2952 +
2953 +       if (copy_from_user(&ifc, arg, sizeof(struct ifconf)))
2954 +               return -EFAULT;
2955 +
2956 +       pos = ifc.ifc_buf;
2957 +       len = ifc.ifc_len;
2958 +
2959 +       /*
2960 +        *      Loop over the interfaces, and write an info block for each.
2961 +        */
2962 +
2963 +       total = 0;
2964 +       for_each_netdev(net, dev) {
2965 +               if (!nx_dev_visible(current->nx_info, dev))
2966 +                       continue;
2967 +               for (i = 0; i < NPROTO; i++) {
2968 +                       if (gifconf_list[i]) {
2969 +                               int done;
2970 +                               if (!pos)
2971 +                                       done = gifconf_list[i](dev, NULL, 0);
2972 +                               else
2973 +                                       done = gifconf_list[i](dev, pos + total,
2974 +                                                              len - total);
2975 +                               if (done < 0)
2976 +                                       return -EFAULT;
2977 +                               total += done;
2978 +                       }
2979 +               }
2980 +       }
2981 +
2982 +       /*
2983 +        *      All done.  Write the updated control block back to the caller.
2984 +        */
2985 +       ifc.ifc_len = total;
2986 +
2987 +       /*
2988 +        *      Both BSD and Solaris return 0 here, so we do too.
2989 +        */
2990 +       return copy_to_user(arg, &ifc, sizeof(struct ifconf)) ? -EFAULT : 0;
2991 +}
2992 +
2993 +#ifdef CONFIG_PROC_FS
2994 +/*
2995 + *     This is invoked by the /proc filesystem handler to display a device
2996 + *     in detail.
2997 + */
2998 +void *dev_seq_start(struct seq_file *seq, loff_t *pos)
2999 +{
3000 +       struct net *net = seq->private;
3001 +       loff_t off;
3002 +       struct net_device *dev;
3003 +
3004 +       read_lock(&dev_base_lock);
3005 +       if (!*pos)
3006 +               return SEQ_START_TOKEN;
3007 +
3008 +       off = 1;
3009 +       for_each_netdev(net, dev)
3010 +               if (off++ == *pos)
3011 +                       return dev;
3012 +
3013 +       return NULL;
3014 +}
3015 +
3016 +void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
3017 +{
3018 +       struct net *net = seq->private;
3019 +       ++*pos;
3020 +       return v == SEQ_START_TOKEN ?
3021 +               first_net_device(net) : next_net_device((struct net_device *)v);
3022 +}
3023 +
3024 +void dev_seq_stop(struct seq_file *seq, void *v)
3025 +{
3026 +       read_unlock(&dev_base_lock);
3027 +}
3028 +
3029 +static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
3030 +{
3031 +       struct net_device_stats *stats = dev->get_stats(dev);
3032 +
3033 +       if (!nx_dev_visible(current->nx_info, dev))
3034 +               return;
3035 +
3036 +       seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
3037 +                  "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
3038 +                  dev->name, stats->rx_bytes, stats->rx_packets,
3039 +                  stats->rx_errors,
3040 +                  stats->rx_dropped + stats->rx_missed_errors,
3041 +                  stats->rx_fifo_errors,
3042 +                  stats->rx_length_errors + stats->rx_over_errors +
3043 +                   stats->rx_crc_errors + stats->rx_frame_errors,
3044 +                  stats->rx_compressed, stats->multicast,
3045 +                  stats->tx_bytes, stats->tx_packets,
3046 +                  stats->tx_errors, stats->tx_dropped,
3047 +                  stats->tx_fifo_errors, stats->collisions,
3048 +                  stats->tx_carrier_errors +
3049 +                   stats->tx_aborted_errors +
3050 +                   stats->tx_window_errors +
3051 +                   stats->tx_heartbeat_errors,
3052 +                  stats->tx_compressed);
3053 +}
3054 +
3055 +/*
3056 + *     Called from the PROCfs module. This now uses the new arbitrary sized
3057 + *     /proc/net interface to create /proc/net/dev
3058 + */
3059 +static int dev_seq_show(struct seq_file *seq, void *v)
3060 +{
3061 +       if (v == SEQ_START_TOKEN)
3062 +               seq_puts(seq, "Inter-|   Receive                            "
3063 +                             "                    |  Transmit\n"
3064 +                             " face |bytes    packets errs drop fifo frame "
3065 +                             "compressed multicast|bytes    packets errs "
3066 +                             "drop fifo colls carrier compressed\n");
3067 +       else
3068 +               dev_seq_printf_stats(seq, v);
3069 +       return 0;
3070 +}
3071 +
3072 +static struct netif_rx_stats *softnet_get_online(loff_t *pos)
3073 +{
3074 +       struct netif_rx_stats *rc = NULL;
3075 +
3076 +       while (*pos < NR_CPUS)
3077 +               if (cpu_online(*pos)) {
3078 +                       rc = &per_cpu(netdev_rx_stat, *pos);
3079 +                       break;
3080 +               } else
3081 +                       ++*pos;
3082 +       return rc;
3083 +}
3084 +
3085 +static void *softnet_seq_start(struct seq_file *seq, loff_t *pos)
3086 +{
3087 +       return softnet_get_online(pos);
3088 +}
3089 +
3090 +static void *softnet_seq_next(struct seq_file *seq, void *v, loff_t *pos)
3091 +{
3092 +       ++*pos;
3093 +       return softnet_get_online(pos);
3094 +}
3095 +
3096 +static void softnet_seq_stop(struct seq_file *seq, void *v)
3097 +{
3098 +}
3099 +
3100 +static int softnet_seq_show(struct seq_file *seq, void *v)
3101 +{
3102 +       struct netif_rx_stats *s = v;
3103 +
3104 +       seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x %08x\n",
3105 +                  s->total, s->dropped, s->time_squeeze, 0,
3106 +                  0, 0, 0, 0, /* was fastroute */
3107 +                  s->cpu_collision );
3108 +       return 0;
3109 +}
3110 +
3111 +static const struct seq_operations dev_seq_ops = {
3112 +       .start = dev_seq_start,
3113 +       .next  = dev_seq_next,
3114 +       .stop  = dev_seq_stop,
3115 +       .show  = dev_seq_show,
3116 +};
3117 +
3118 +static int dev_seq_open(struct inode *inode, struct file *file)
3119 +{
3120 +       struct seq_file *seq;
3121 +       int res;
3122 +       res =  seq_open(file, &dev_seq_ops);
3123 +       if (!res) {
3124 +               seq = file->private_data;
3125 +               seq->private = get_net(PROC_NET(inode));
3126 +       }
3127 +       return res;
3128 +}
3129 +
3130 +static int dev_seq_release(struct inode *inode, struct file *file)
3131 +{
3132 +       struct seq_file *seq = file->private_data;
3133 +       struct net *net = seq->private;
3134 +       put_net(net);
3135 +       return seq_release(inode, file);
3136 +}
3137 +
3138 +static const struct file_operations dev_seq_fops = {
3139 +       .owner   = THIS_MODULE,
3140 +       .open    = dev_seq_open,
3141 +       .read    = seq_read,
3142 +       .llseek  = seq_lseek,
3143 +       .release = dev_seq_release,
3144 +};
3145 +
3146 +static const struct seq_operations softnet_seq_ops = {
3147 +       .start = softnet_seq_start,
3148 +       .next  = softnet_seq_next,
3149 +       .stop  = softnet_seq_stop,
3150 +       .show  = softnet_seq_show,
3151 +};
3152 +
3153 +static int softnet_seq_open(struct inode *inode, struct file *file)
3154 +{
3155 +       return seq_open(file, &softnet_seq_ops);
3156 +}
3157 +
3158 +static const struct file_operations softnet_seq_fops = {
3159 +       .owner   = THIS_MODULE,
3160 +       .open    = softnet_seq_open,
3161 +       .read    = seq_read,
3162 +       .llseek  = seq_lseek,
3163 +       .release = seq_release,
3164 +};
3165 +
3166 +static void *ptype_get_idx(loff_t pos)
3167 +{
3168 +       struct packet_type *pt = NULL;
3169 +       loff_t i = 0;
3170 +       int t;
3171 +
3172 +       list_for_each_entry_rcu(pt, &ptype_all, list) {
3173 +               if (i == pos)
3174 +                       return pt;
3175 +               ++i;
3176 +       }
3177 +
3178 +       for (t = 0; t < 16; t++) {
3179 +               list_for_each_entry_rcu(pt, &ptype_base[t], list) {
3180 +                       if (i == pos)
3181 +                               return pt;
3182 +                       ++i;
3183 +               }
3184 +       }
3185 +       return NULL;
3186 +}
3187 +
3188 +static void *ptype_seq_start(struct seq_file *seq, loff_t *pos)
3189 +{
3190 +       rcu_read_lock();
3191 +       return *pos ? ptype_get_idx(*pos - 1) : SEQ_START_TOKEN;
3192 +}
3193 +
3194 +static void *ptype_seq_next(struct seq_file *seq, void *v, loff_t *pos)
3195 +{
3196 +       struct packet_type *pt;
3197 +       struct list_head *nxt;
3198 +       int hash;
3199 +
3200 +       ++*pos;
3201 +       if (v == SEQ_START_TOKEN)
3202 +               return ptype_get_idx(0);
3203 +
3204 +       pt = v;
3205 +       nxt = pt->list.next;
3206 +       if (pt->type == htons(ETH_P_ALL)) {
3207 +               if (nxt != &ptype_all)
3208 +                       goto found;
3209 +               hash = 0;
3210 +               nxt = ptype_base[0].next;
3211 +       } else
3212 +               hash = ntohs(pt->type) & 15;
3213 +
3214 +       while (nxt == &ptype_base[hash]) {
3215 +               if (++hash >= 16)
3216 +                       return NULL;
3217 +               nxt = ptype_base[hash].next;
3218 +       }
3219 +found:
3220 +       return list_entry(nxt, struct packet_type, list);
3221 +}
3222 +
3223 +static void ptype_seq_stop(struct seq_file *seq, void *v)
3224 +{
3225 +       rcu_read_unlock();
3226 +}
3227 +
3228 +static void ptype_seq_decode(struct seq_file *seq, void *sym)
3229 +{
3230 +#ifdef CONFIG_KALLSYMS
3231 +       unsigned long offset = 0, symsize;
3232 +       const char *symname;
3233 +       char *modname;
3234 +       char namebuf[128];
3235 +
3236 +       symname = kallsyms_lookup((unsigned long)sym, &symsize, &offset,
3237 +                                 &modname, namebuf);
3238 +
3239 +       if (symname) {
3240 +               char *delim = ":";
3241 +
3242 +               if (!modname)
3243 +                       modname = delim = "";
3244 +               seq_printf(seq, "%s%s%s%s+0x%lx", delim, modname, delim,
3245 +                          symname, offset);
3246 +               return;
3247 +       }
3248 +#endif
3249 +
3250 +       seq_printf(seq, "[%p]", sym);
3251 +}
3252 +
3253 +static int ptype_seq_show(struct seq_file *seq, void *v)
3254 +{
3255 +       struct packet_type *pt = v;
3256 +
3257 +       if (v == SEQ_START_TOKEN)
3258 +               seq_puts(seq, "Type Device      Function\n");
3259 +       else {
3260 +               if (pt->type == htons(ETH_P_ALL))
3261 +                       seq_puts(seq, "ALL ");
3262 +               else
3263 +                       seq_printf(seq, "%04x", ntohs(pt->type));
3264 +
3265 +               seq_printf(seq, " %-8s ",
3266 +                          pt->dev ? pt->dev->name : "");
3267 +               ptype_seq_decode(seq,  pt->func);
3268 +               seq_putc(seq, '\n');
3269 +       }
3270 +
3271 +       return 0;
3272 +}
3273 +
3274 +static const struct seq_operations ptype_seq_ops = {
3275 +       .start = ptype_seq_start,
3276 +       .next  = ptype_seq_next,
3277 +       .stop  = ptype_seq_stop,
3278 +       .show  = ptype_seq_show,
3279 +};
3280 +
3281 +static int ptype_seq_open(struct inode *inode, struct file *file)
3282 +{
3283 +       return seq_open(file, &ptype_seq_ops);
3284 +}
3285 +
3286 +static const struct file_operations ptype_seq_fops = {
3287 +       .owner   = THIS_MODULE,
3288 +       .open    = ptype_seq_open,
3289 +       .read    = seq_read,
3290 +       .llseek  = seq_lseek,
3291 +       .release = seq_release,
3292 +};
3293 +
3294 +
3295 +static int dev_proc_net_init(struct net *net)
3296 +{
3297 +       int rc = -ENOMEM;
3298 +
3299 +       if (!proc_net_fops_create(net, "dev", S_IRUGO, &dev_seq_fops))
3300 +               goto out;
3301 +       if (!proc_net_fops_create(net, "softnet_stat", S_IRUGO, &softnet_seq_fops))
3302 +               goto out_dev;
3303 +       if (!proc_net_fops_create(net, "ptype", S_IRUGO, &ptype_seq_fops))
3304 +               goto out_softnet;
3305 +
3306 +       if (wext_proc_init(net))
3307 +               goto out_ptype;
3308 +       rc = 0;
3309 +out:
3310 +       return rc;
3311 +out_ptype:
3312 +       proc_net_remove(net, "ptype");
3313 +out_softnet:
3314 +       proc_net_remove(net, "softnet_stat");
3315 +out_dev:
3316 +       proc_net_remove(net, "dev");
3317 +       goto out;
3318 +}
3319 +
3320 +static void dev_proc_net_exit(struct net *net)
3321 +{
3322 +       wext_proc_exit(net);
3323 +
3324 +       proc_net_remove(net, "ptype");
3325 +       proc_net_remove(net, "softnet_stat");
3326 +       proc_net_remove(net, "dev");
3327 +}
3328 +
3329 +static struct pernet_operations dev_proc_ops = {
3330 +       .init = dev_proc_net_init,
3331 +       .exit = dev_proc_net_exit,
3332 +};
3333 +
3334 +static int __init dev_proc_init(void)
3335 +{
3336 +       return register_pernet_subsys(&dev_proc_ops);
3337 +}
3338 +#else
3339 +#define dev_proc_init() 0
3340 +#endif /* CONFIG_PROC_FS */
3341 +
3342 +
3343 +/**
3344 + *     netdev_set_master       -       set up master/slave pair
3345 + *     @slave: slave device
3346 + *     @master: new master device
3347 + *
3348 + *     Changes the master device of the slave. Pass %NULL to break the
3349 + *     bonding. The caller must hold the RTNL semaphore. On a failure
3350 + *     a negative errno code is returned. On success the reference counts
3351 + *     are adjusted, %RTM_NEWLINK is sent to the routing socket and the
3352 + *     function returns zero.
3353 + */
3354 +int netdev_set_master(struct net_device *slave, struct net_device *master)
3355 +{
3356 +       struct net_device *old = slave->master;
3357 +
3358 +       ASSERT_RTNL();
3359 +
3360 +       if (master) {
3361 +               if (old)
3362 +                       return -EBUSY;
3363 +               dev_hold(master);
3364 +       }
3365 +
3366 +       slave->master = master;
3367 +
3368 +       synchronize_net();
3369 +
3370 +       if (old)
3371 +               dev_put(old);
3372 +
3373 +       if (master)
3374 +               slave->flags |= IFF_SLAVE;
3375 +       else
3376 +               slave->flags &= ~IFF_SLAVE;
3377 +
3378 +       rtmsg_ifinfo(RTM_NEWLINK, slave, IFF_SLAVE);
3379 +       return 0;
3380 +}
3381 +
3382 +/**
3383 + *     dev_set_promiscuity     - update promiscuity count on a device
3384 + *     @dev: device
3385 + *     @inc: modifier
3386 + *
3387 + *     Add or remove promiscuity from a device. While the count in the device
3388 + *     remains above zero the interface remains promiscuous. Once it hits zero
3389 + *     the device reverts back to normal filtering operation. A negative inc
3390 + *     value is used to drop promiscuity on the device.
3391 + */
3392 +void dev_set_promiscuity(struct net_device *dev, int inc)
3393 +{
3394 +       unsigned short old_flags = dev->flags;
3395 +
3396 +       if ((dev->promiscuity += inc) == 0)
3397 +               dev->flags &= ~IFF_PROMISC;
3398 +       else
3399 +               dev->flags |= IFF_PROMISC;
3400 +       if (dev->flags != old_flags) {
3401 +               dev_mc_upload(dev);
3402 +               printk(KERN_INFO "device %s %s promiscuous mode\n",
3403 +                      dev->name, (dev->flags & IFF_PROMISC) ? "entered" :
3404 +                                                              "left");
3405 +               audit_log(current->audit_context, GFP_ATOMIC,
3406 +                       AUDIT_ANOM_PROMISCUOUS,
3407 +                       "dev=%s prom=%d old_prom=%d auid=%u",
3408 +                       dev->name, (dev->flags & IFF_PROMISC),
3409 +                       (old_flags & IFF_PROMISC),
3410 +                       audit_get_loginuid(current->audit_context));
3411 +       }
3412 +}
3413 +
3414 +/**
3415 + *     dev_set_allmulti        - update allmulti count on a device
3416 + *     @dev: device
3417 + *     @inc: modifier
3418 + *
3419 + *     Add or remove reception of all multicast frames to a device. While the
3420 + *     count in the device remains above zero the interface remains listening
3421 + *     to all interfaces. Once it hits zero the device reverts back to normal
3422 + *     filtering operation. A negative @inc value is used to drop the counter
3423 + *     when releasing a resource needing all multicasts.
3424 + */
3425 +
3426 +void dev_set_allmulti(struct net_device *dev, int inc)
3427 +{
3428 +       unsigned short old_flags = dev->flags;
3429 +
3430 +       dev->flags |= IFF_ALLMULTI;
3431 +       if ((dev->allmulti += inc) == 0)
3432 +               dev->flags &= ~IFF_ALLMULTI;
3433 +       if (dev->flags ^ old_flags)
3434 +               dev_mc_upload(dev);
3435 +}
3436 +
3437 +unsigned dev_get_flags(const struct net_device *dev)
3438 +{
3439 +       unsigned flags;
3440 +
3441 +       flags = (dev->flags & ~(IFF_PROMISC |
3442 +                               IFF_ALLMULTI |
3443 +                               IFF_RUNNING |
3444 +                               IFF_LOWER_UP |
3445 +                               IFF_DORMANT)) |
3446 +               (dev->gflags & (IFF_PROMISC |
3447 +                               IFF_ALLMULTI));
3448 +
3449 +       if (netif_running(dev)) {
3450 +               if (netif_oper_up(dev))
3451 +                       flags |= IFF_RUNNING;
3452 +               if (netif_carrier_ok(dev))
3453 +                       flags |= IFF_LOWER_UP;
3454 +               if (netif_dormant(dev))
3455 +                       flags |= IFF_DORMANT;
3456 +       }
3457 +
3458 +       return flags;
3459 +}
3460 +
3461 +int dev_change_flags(struct net_device *dev, unsigned flags)
3462 +{
3463 +       int ret, changes;
3464 +       int old_flags = dev->flags;
3465 +
3466 +       /*
3467 +        *      Set the flags on our device.
3468 +        */
3469 +
3470 +       dev->flags = (flags & (IFF_DEBUG | IFF_NOTRAILERS | IFF_NOARP |
3471 +                              IFF_DYNAMIC | IFF_MULTICAST | IFF_PORTSEL |
3472 +                              IFF_AUTOMEDIA)) |
3473 +                    (dev->flags & (IFF_UP | IFF_VOLATILE | IFF_PROMISC |
3474 +                                   IFF_ALLMULTI));
3475 +
3476 +       /*
3477 +        *      Load in the correct multicast list now the flags have changed.
3478 +        */
3479 +
3480 +       dev_mc_upload(dev);
3481 +
3482 +       /*
3483 +        *      Have we downed the interface. We handle IFF_UP ourselves
3484 +        *      according to user attempts to set it, rather than blindly
3485 +        *      setting it.
3486 +        */
3487 +
3488 +       ret = 0;
3489 +       if ((old_flags ^ flags) & IFF_UP) {     /* Bit is different  ? */
3490 +               ret = ((old_flags & IFF_UP) ? dev_close : dev_open)(dev);
3491 +
3492 +               if (!ret)
3493 +                       dev_mc_upload(dev);
3494 +       }
3495 +
3496 +       if (dev->flags & IFF_UP &&
3497 +           ((old_flags ^ dev->flags) &~ (IFF_UP | IFF_PROMISC | IFF_ALLMULTI |
3498 +                                         IFF_VOLATILE)))
3499 +               raw_notifier_call_chain(&netdev_chain,
3500 +                               NETDEV_CHANGE, dev);
3501 +
3502 +       if ((flags ^ dev->gflags) & IFF_PROMISC) {
3503 +               int inc = (flags & IFF_PROMISC) ? +1 : -1;
3504 +               dev->gflags ^= IFF_PROMISC;
3505 +               dev_set_promiscuity(dev, inc);
3506 +       }
3507 +
3508 +       /* NOTE: order of synchronization of IFF_PROMISC and IFF_ALLMULTI
3509 +          is important. Some (broken) drivers set IFF_PROMISC, when
3510 +          IFF_ALLMULTI is requested not asking us and not reporting.
3511 +        */
3512 +       if ((flags ^ dev->gflags) & IFF_ALLMULTI) {
3513 +               int inc = (flags & IFF_ALLMULTI) ? +1 : -1;
3514 +               dev->gflags ^= IFF_ALLMULTI;
3515 +               dev_set_allmulti(dev, inc);
3516 +       }
3517 +
3518 +       /* Exclude state transition flags, already notified */
3519 +       changes = (old_flags ^ dev->flags) & ~(IFF_UP | IFF_RUNNING);
3520 +       if (changes)
3521 +               rtmsg_ifinfo(RTM_NEWLINK, dev, changes);
3522 +
3523 +       return ret;
3524 +}
3525 +
3526 +int dev_set_mtu(struct net_device *dev, int new_mtu)
3527 +{
3528 +       int err;
3529 +
3530 +       if (new_mtu == dev->mtu)
3531 +               return 0;
3532 +
3533 +       /*      MTU must be positive.    */
3534 +       if (new_mtu < 0)
3535 +               return -EINVAL;
3536 +
3537 +       if (!netif_device_present(dev))
3538 +               return -ENODEV;
3539 +
3540 +       err = 0;
3541 +       if (dev->change_mtu)
3542 +               err = dev->change_mtu(dev, new_mtu);
3543 +       else
3544 +               dev->mtu = new_mtu;
3545 +       if (!err && dev->flags & IFF_UP)
3546 +               raw_notifier_call_chain(&netdev_chain,
3547 +                               NETDEV_CHANGEMTU, dev);
3548 +       return err;
3549 +}
3550 +
3551 +int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa)
3552 +{
3553 +       int err;
3554 +
3555 +       if (!dev->set_mac_address)
3556 +               return -EOPNOTSUPP;
3557 +       if (sa->sa_family != dev->type)
3558 +               return -EINVAL;
3559 +       if (!netif_device_present(dev))
3560 +               return -ENODEV;
3561 +       err = dev->set_mac_address(dev, sa);
3562 +       if (!err)
3563 +               raw_notifier_call_chain(&netdev_chain,
3564 +                               NETDEV_CHANGEADDR, dev);
3565 +       return err;
3566 +}
3567 +
3568 +/*
3569 + *     Perform the SIOCxIFxxx calls.
3570 + */
3571 +static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd)
3572 +{
3573 +       int err;
3574 +       struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
3575 +
3576 +       if (!dev)
3577 +               return -ENODEV;
3578 +
3579 +       switch (cmd) {
3580 +               case SIOCGIFFLAGS:      /* Get interface flags */
3581 +                       ifr->ifr_flags = dev_get_flags(dev);
3582 +                       return 0;
3583 +
3584 +               case SIOCSIFFLAGS:      /* Set interface flags */
3585 +                       return dev_change_flags(dev, ifr->ifr_flags);
3586 +
3587 +               case SIOCGIFMETRIC:     /* Get the metric on the interface
3588 +                                          (currently unused) */
3589 +                       ifr->ifr_metric = 0;
3590 +                       return 0;
3591 +
3592 +               case SIOCSIFMETRIC:     /* Set the metric on the interface
3593 +                                          (currently unused) */
3594 +                       return -EOPNOTSUPP;
3595 +
3596 +               case SIOCGIFMTU:        /* Get the MTU of a device */
3597 +                       ifr->ifr_mtu = dev->mtu;
3598 +                       return 0;
3599 +
3600 +               case SIOCSIFMTU:        /* Set the MTU of a device */
3601 +                       return dev_set_mtu(dev, ifr->ifr_mtu);
3602 +
3603 +               case SIOCGIFHWADDR:
3604 +                       if (!dev->addr_len)
3605 +                               memset(ifr->ifr_hwaddr.sa_data, 0, sizeof ifr->ifr_hwaddr.sa_data);
3606 +                       else
3607 +                               memcpy(ifr->ifr_hwaddr.sa_data, dev->dev_addr,
3608 +                                      min(sizeof ifr->ifr_hwaddr.sa_data, (size_t) dev->addr_len));
3609 +                       ifr->ifr_hwaddr.sa_family = dev->type;
3610 +                       return 0;
3611 +
3612 +               case SIOCSIFHWADDR:
3613 +                       return dev_set_mac_address(dev, &ifr->ifr_hwaddr);
3614 +
3615 +               case SIOCSIFHWBROADCAST:
3616 +                       if (ifr->ifr_hwaddr.sa_family != dev->type)
3617 +                               return -EINVAL;
3618 +                       memcpy(dev->broadcast, ifr->ifr_hwaddr.sa_data,
3619 +                              min(sizeof ifr->ifr_hwaddr.sa_data, (size_t) dev->addr_len));
3620 +                       raw_notifier_call_chain(&netdev_chain,
3621 +                                           NETDEV_CHANGEADDR, dev);
3622 +                       return 0;
3623 +
3624 +               case SIOCGIFMAP:
3625 +                       ifr->ifr_map.mem_start = dev->mem_start;
3626 +                       ifr->ifr_map.mem_end   = dev->mem_end;
3627 +                       ifr->ifr_map.base_addr = dev->base_addr;
3628 +                       ifr->ifr_map.irq       = dev->irq;
3629 +                       ifr->ifr_map.dma       = dev->dma;
3630 +                       ifr->ifr_map.port      = dev->if_port;
3631 +                       return 0;
3632 +
3633 +               case SIOCSIFMAP:
3634 +                       if (dev->set_config) {
3635 +                               if (!netif_device_present(dev))
3636 +                                       return -ENODEV;
3637 +                               return dev->set_config(dev, &ifr->ifr_map);
3638 +                       }
3639 +                       return -EOPNOTSUPP;
3640 +
3641 +               case SIOCADDMULTI:
3642 +                       if (!dev->set_multicast_list ||
3643 +                           ifr->ifr_hwaddr.sa_family != AF_UNSPEC)
3644 +                               return -EINVAL;
3645 +                       if (!netif_device_present(dev))
3646 +                               return -ENODEV;
3647 +                       return dev_mc_add(dev, ifr->ifr_hwaddr.sa_data,
3648 +                                         dev->addr_len, 1);
3649 +
3650 +               case SIOCDELMULTI:
3651 +                       if (!dev->set_multicast_list ||
3652 +                           ifr->ifr_hwaddr.sa_family != AF_UNSPEC)
3653 +                               return -EINVAL;
3654 +                       if (!netif_device_present(dev))
3655 +                               return -ENODEV;
3656 +                       return dev_mc_delete(dev, ifr->ifr_hwaddr.sa_data,
3657 +                                            dev->addr_len, 1);
3658 +
3659 +               case SIOCGIFINDEX:
3660 +                       ifr->ifr_ifindex = dev->ifindex;
3661 +                       return 0;
3662 +
3663 +               case SIOCGIFTXQLEN:
3664 +                       ifr->ifr_qlen = dev->tx_queue_len;
3665 +                       return 0;
3666 +
3667 +               case SIOCSIFTXQLEN:
3668 +                       if (ifr->ifr_qlen < 0)
3669 +                               return -EINVAL;
3670 +                       dev->tx_queue_len = ifr->ifr_qlen;
3671 +                       return 0;
3672 +
3673 +               case SIOCSIFNAME:
3674 +                       ifr->ifr_newname[IFNAMSIZ-1] = '\0';
3675 +                       return dev_change_name(dev, ifr->ifr_newname);
3676 +
3677 +               /*
3678 +                *      Unknown or private ioctl
3679 +                */
3680 +
3681 +               default:
3682 +                       if ((cmd >= SIOCDEVPRIVATE &&
3683 +                           cmd <= SIOCDEVPRIVATE + 15) ||
3684 +                           cmd == SIOCBONDENSLAVE ||
3685 +                           cmd == SIOCBONDRELEASE ||
3686 +                           cmd == SIOCBONDSETHWADDR ||
3687 +                           cmd == SIOCBONDSLAVEINFOQUERY ||
3688 +                           cmd == SIOCBONDINFOQUERY ||
3689 +                           cmd == SIOCBONDCHANGEACTIVE ||
3690 +                           cmd == SIOCGMIIPHY ||
3691 +                           cmd == SIOCGMIIREG ||
3692 +                           cmd == SIOCSMIIREG ||
3693 +                           cmd == SIOCBRADDIF ||
3694 +                           cmd == SIOCBRDELIF ||
3695 +                           cmd == SIOCWANDEV) {
3696 +                               err = -EOPNOTSUPP;
3697 +                               if (dev->do_ioctl) {
3698 +                                       if (netif_device_present(dev))
3699 +                                               err = dev->do_ioctl(dev, ifr,
3700 +                                                                   cmd);
3701 +                                       else
3702 +                                               err = -ENODEV;
3703 +                               }
3704 +                       } else
3705 +                               err = -EINVAL;
3706 +
3707 +       }
3708 +       return err;
3709 +}
3710 +
3711 +/*
3712 + *     This function handles all "interface"-type I/O control requests. The actual
3713 + *     'doing' part of this is dev_ifsioc above.
3714 + */
3715 +
3716 +/**
3717 + *     dev_ioctl       -       network device ioctl
3718 + *     @cmd: command to issue
3719 + *     @arg: pointer to a struct ifreq in user space
3720 + *
3721 + *     Issue ioctl functions to devices. This is normally called by the
3722 + *     user space syscall interfaces but can sometimes be useful for
3723 + *     other purposes. The return value is the return from the syscall if
3724 + *     positive or a negative errno code on error.
3725 + */
3726 +
3727 +int dev_ioctl(struct net *net, unsigned int cmd, void __user *arg)
3728 +{
3729 +       struct ifreq ifr;
3730 +       int ret;
3731 +       char *colon;
3732 +
3733 +       /* One special case: SIOCGIFCONF takes ifconf argument
3734 +          and requires shared lock, because it sleeps writing
3735 +          to user space.
3736 +        */
3737 +
3738 +       if (cmd == SIOCGIFCONF) {
3739 +               rtnl_lock();
3740 +               ret = dev_ifconf(net, (char __user *) arg);
3741 +               rtnl_unlock();
3742 +               return ret;
3743 +       }
3744 +       if (cmd == SIOCGIFNAME)
3745 +               return dev_ifname(net, (struct ifreq __user *)arg);
3746 +
3747 +       if (copy_from_user(&ifr, arg, sizeof(struct ifreq)))
3748 +               return -EFAULT;
3749 +
3750 +       ifr.ifr_name[IFNAMSIZ-1] = 0;
3751 +
3752 +       colon = strchr(ifr.ifr_name, ':');
3753 +       if (colon)
3754 +               *colon = 0;
3755 +
3756 +       /*
3757 +        *      See which interface the caller is talking about.
3758 +        */
3759 +
3760 +       switch (cmd) {
3761 +               /*
3762 +                *      These ioctl calls:
3763 +                *      - can be done by all.
3764 +                *      - atomic and do not require locking.
3765 +                *      - return a value
3766 +                */
3767 +               case SIOCGIFFLAGS:
3768 +               case SIOCGIFMETRIC:
3769 +               case SIOCGIFMTU:
3770 +               case SIOCGIFHWADDR:
3771 +               case SIOCGIFSLAVE:
3772 +               case SIOCGIFMAP:
3773 +               case SIOCGIFINDEX:
3774 +               case SIOCGIFTXQLEN:
3775 +                       dev_load(net, ifr.ifr_name);
3776 +                       read_lock(&dev_base_lock);
3777 +                       ret = dev_ifsioc(net, &ifr, cmd);
3778 +                       read_unlock(&dev_base_lock);
3779 +                       if (!ret) {
3780 +                               if (colon)
3781 +                                       *colon = ':';
3782 +                               if (copy_to_user(arg, &ifr,
3783 +                                                sizeof(struct ifreq)))
3784 +                                       ret = -EFAULT;
3785 +                       }
3786 +                       return ret;
3787 +
3788 +               case SIOCETHTOOL:
3789 +                       dev_load(net, ifr.ifr_name);
3790 +                       rtnl_lock();
3791 +                       ret = dev_ethtool(net, &ifr);
3792 +                       rtnl_unlock();
3793 +                       if (!ret) {
3794 +                               if (colon)
3795 +                                       *colon = ':';
3796 +                               if (copy_to_user(arg, &ifr,
3797 +                                                sizeof(struct ifreq)))
3798 +                                       ret = -EFAULT;
3799 +                       }
3800 +                       return ret;
3801 +
3802 +               /*
3803 +                *      These ioctl calls:
3804 +                *      - require superuser power.
3805 +                *      - require strict serialization.
3806 +                *      - return a value
3807 +                */
3808 +               case SIOCGMIIPHY:
3809 +               case SIOCGMIIREG:
3810 +               case SIOCSIFNAME:
3811 +                       if (!capable(CAP_NET_ADMIN))
3812 +                               return -EPERM;
3813 +                       dev_load(net, ifr.ifr_name);
3814 +                       rtnl_lock();
3815 +                       ret = dev_ifsioc(net, &ifr, cmd);
3816 +                       rtnl_unlock();
3817 +                       if (!ret) {
3818 +                               if (colon)
3819 +                                       *colon = ':';
3820 +                               if (copy_to_user(arg, &ifr,
3821 +                                                sizeof(struct ifreq)))
3822 +                                       ret = -EFAULT;
3823 +                       }
3824 +                       return ret;
3825 +
3826 +               /*
3827 +                *      These ioctl calls:
3828 +                *      - require superuser power.
3829 +                *      - require strict serialization.
3830 +                *      - do not return a value
3831 +                */
3832 +               case SIOCSIFFLAGS:
3833 +               case SIOCSIFMETRIC:
3834 +               case SIOCSIFMTU:
3835 +               case SIOCSIFMAP:
3836 +               case SIOCSIFHWADDR:
3837 +               case SIOCSIFSLAVE:
3838 +               case SIOCADDMULTI:
3839 +               case SIOCDELMULTI:
3840 +               case SIOCSIFHWBROADCAST:
3841 +               case SIOCSIFTXQLEN:
3842 +               case SIOCSMIIREG:
3843 +               case SIOCBONDENSLAVE:
3844 +               case SIOCBONDRELEASE:
3845 +               case SIOCBONDSETHWADDR:
3846 +               case SIOCBONDCHANGEACTIVE:
3847 +               case SIOCBRADDIF:
3848 +               case SIOCBRDELIF:
3849 +                       if (!capable(CAP_NET_ADMIN))
3850 +                               return -EPERM;
3851 +                       /* fall through */
3852 +               case SIOCBONDSLAVEINFOQUERY:
3853 +               case SIOCBONDINFOQUERY:
3854 +                       dev_load(net, ifr.ifr_name);
3855 +                       rtnl_lock();
3856 +                       ret = dev_ifsioc(net, &ifr, cmd);
3857 +                       rtnl_unlock();
3858 +                       return ret;
3859 +
3860 +               case SIOCGIFMEM:
3861 +                       /* Get the per device memory space. We can add this but
3862 +                        * currently do not support it */
3863 +               case SIOCSIFMEM:
3864 +                       /* Set the per device memory buffer space.
3865 +                        * Not applicable in our case */
3866 +               case SIOCSIFLINK:
3867 +                       return -EINVAL;
3868 +
3869 +               /*
3870 +                *      Unknown or private ioctl.
3871 +                */
3872 +               default:
3873 +                       if (cmd == SIOCWANDEV ||
3874 +                           (cmd >= SIOCDEVPRIVATE &&
3875 +                            cmd <= SIOCDEVPRIVATE + 15)) {
3876 +                               dev_load(net, ifr.ifr_name);
3877 +                               rtnl_lock();
3878 +                               ret = dev_ifsioc(net, &ifr, cmd);
3879 +                               rtnl_unlock();
3880 +                               if (!ret && copy_to_user(arg, &ifr,
3881 +                                                        sizeof(struct ifreq)))
3882 +                                       ret = -EFAULT;
3883 +                               return ret;
3884 +                       }
3885 +                       /* Take care of Wireless Extensions */
3886 +                       if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST)
3887 +                               return wext_handle_ioctl(net, &ifr, cmd, arg);
3888 +                       return -EINVAL;
3889 +       }
3890 +}
3891 +
3892 +
3893 +/**
3894 + *     dev_new_index   -       allocate an ifindex
3895 + *
3896 + *     Returns a suitable unique value for a new device interface
3897 + *     number.  The caller must hold the rtnl semaphore or the
3898 + *     dev_base_lock to be sure it remains unique.
3899 + */
3900 +static int dev_new_index(struct net *net)
3901 +{
3902 +       static int ifindex;
3903 +       for (;;) {
3904 +               if (++ifindex <= 0)
3905 +                       ifindex = 1;
3906 +               if (!__dev_get_by_index(net, ifindex))
3907 +                       return ifindex;
3908 +       }
3909 +}
3910 +
3911 +/* Delayed registration/unregisteration */
3912 +static DEFINE_SPINLOCK(net_todo_list_lock);
3913 +static struct list_head net_todo_list = LIST_HEAD_INIT(net_todo_list);
3914 +
3915 +static void net_set_todo(struct net_device *dev)
3916 +{
3917 +       spin_lock(&net_todo_list_lock);
3918 +       list_add_tail(&dev->todo_list, &net_todo_list);
3919 +       spin_unlock(&net_todo_list_lock);
3920 +}
3921 +
3922 +/**
3923 + *     register_netdevice      - register a network device
3924 + *     @dev: device to register
3925 + *
3926 + *     Take a completed network device structure and add it to the kernel
3927 + *     interfaces. A %NETDEV_REGISTER message is sent to the netdev notifier
3928 + *     chain. 0 is returned on success. A negative errno code is returned
3929 + *     on a failure to set up the device, or if the name is a duplicate.
3930 + *
3931 + *     Callers must hold the rtnl semaphore. You may want
3932 + *     register_netdev() instead of this.
3933 + *
3934 + *     BUGS:
3935 + *     The locking appears insufficient to guarantee two parallel registers
3936 + *     will not get the same name.
3937 + */
3938 +
3939 +int register_netdevice(struct net_device *dev)
3940 +{
3941 +       struct hlist_head *head;
3942 +       struct hlist_node *p;
3943 +       int ret;
3944 +       struct net *net;
3945 +
3946 +       BUG_ON(dev_boot_phase);
3947 +       ASSERT_RTNL();
3948 +
3949 +       might_sleep();
3950 +
3951 +       /* When net_device's are persistent, this will be fatal. */
3952 +       BUG_ON(dev->reg_state != NETREG_UNINITIALIZED);
3953 +       BUG_ON(!dev->nd_net);
3954 +       net = dev->nd_net;
3955 +
3956 +       spin_lock_init(&dev->queue_lock);
3957 +       spin_lock_init(&dev->_xmit_lock);
3958 +       netdev_set_lockdep_class(&dev->_xmit_lock, dev->type);
3959 +       dev->xmit_lock_owner = -1;
3960 +       spin_lock_init(&dev->ingress_lock);
3961 +
3962 +       dev->iflink = -1;
3963 +
3964 +       /* Init, if this function is available */
3965 +       if (dev->init) {
3966 +               ret = dev->init(dev);
3967 +               if (ret) {
3968 +                       if (ret > 0)
3969 +                               ret = -EIO;
3970 +                       goto out;
3971 +               }
3972 +       }
3973 +
3974 +       if (!dev_valid_name(dev->name)) {
3975 +               ret = -EINVAL;
3976 +               goto out;
3977 +       }
3978 +
3979 +       dev->ifindex = dev_new_index(net);
3980 +       if (dev->iflink == -1)
3981 +               dev->iflink = dev->ifindex;
3982 +
3983 +       /* Check for existence of name */
3984 +       head = dev_name_hash(net, dev->name);
3985 +       hlist_for_each(p, head) {
3986 +               struct net_device *d
3987 +                       = hlist_entry(p, struct net_device, name_hlist);
3988 +               if (!strncmp(d->name, dev->name, IFNAMSIZ)) {
3989 +                       ret = -EEXIST;
3990 +                       goto out;
3991 +               }
3992 +       }
3993 +
3994 +       /* Fix illegal checksum combinations */
3995 +       if ((dev->features & NETIF_F_HW_CSUM) &&
3996 +           (dev->features & (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM))) {
3997 +               printk(KERN_NOTICE "%s: mixed HW and IP checksum settings.\n",
3998 +                      dev->name);
3999 +               dev->features &= ~(NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM);
4000 +       }
4001 +
4002 +       if ((dev->features & NETIF_F_NO_CSUM) &&
4003 +           (dev->features & (NETIF_F_HW_CSUM|NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM))) {
4004 +               printk(KERN_NOTICE "%s: mixed no checksumming and other settings.\n",
4005 +                      dev->name);
4006 +               dev->features &= ~(NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM|NETIF_F_HW_CSUM);
4007 +       }
4008 +
4009 +
4010 +       /* Fix illegal SG+CSUM combinations. */
4011 +       if ((dev->features & NETIF_F_SG) &&
4012 +           !(dev->features & NETIF_F_ALL_CSUM)) {
4013 +               printk(KERN_NOTICE "%s: Dropping NETIF_F_SG since no checksum feature.\n",
4014 +                      dev->name);
4015 +               dev->features &= ~NETIF_F_SG;
4016 +       }
4017 +
4018 +       /* TSO requires that SG is present as well. */
4019 +       if ((dev->features & NETIF_F_TSO) &&
4020 +           !(dev->features & NETIF_F_SG)) {
4021 +               printk(KERN_NOTICE "%s: Dropping NETIF_F_TSO since no SG feature.\n",
4022 +                      dev->name);
4023 +               dev->features &= ~NETIF_F_TSO;
4024 +       }
4025 +       if (dev->features & NETIF_F_UFO) {
4026 +               if (!(dev->features & NETIF_F_HW_CSUM)) {
4027 +                       printk(KERN_ERR "%s: Dropping NETIF_F_UFO since no "
4028 +                                       "NETIF_F_HW_CSUM feature.\n",
4029 +                                                       dev->name);
4030 +                       dev->features &= ~NETIF_F_UFO;
4031 +               }
4032 +               if (!(dev->features & NETIF_F_SG)) {
4033 +                       printk(KERN_ERR "%s: Dropping NETIF_F_UFO since no "
4034 +                                       "NETIF_F_SG feature.\n",
4035 +                                       dev->name);
4036 +                       dev->features &= ~NETIF_F_UFO;
4037 +               }
4038 +       }
4039 +
4040 +       /*
4041 +        *      nil rebuild_header routine,
4042 +        *      that should be never called and used as just bug trap.
4043 +        */
4044 +
4045 +       if (!dev->rebuild_header)
4046 +               dev->rebuild_header = default_rebuild_header;
4047 +
4048 +       ret = netdev_register_sysfs(dev);
4049 +       if (ret)
4050 +               goto out;
4051 +       dev->reg_state = NETREG_REGISTERED;
4052 +
4053 +       /*
4054 +        *      Default initial state at registry is that the
4055 +        *      device is present.
4056 +        */
4057 +
4058 +       set_bit(__LINK_STATE_PRESENT, &dev->state);
4059 +
4060 +       dev_init_scheduler(dev);
4061 +       dev_hold(dev);
4062 +       list_netdevice(dev);
4063 +
4064 +       /* Notify protocols, that a new device appeared. */
4065 +       raw_notifier_call_chain(&netdev_chain, NETDEV_REGISTER, dev);
4066 +
4067 +       ret = 0;
4068 +
4069 +out:
4070 +       return ret;
4071 +}
4072 +
4073 +/**
4074 + *     register_netdev - register a network device
4075 + *     @dev: device to register
4076 + *
4077 + *     Take a completed network device structure and add it to the kernel
4078 + *     interfaces. A %NETDEV_REGISTER message is sent to the netdev notifier
4079 + *     chain. 0 is returned on success. A negative errno code is returned
4080 + *     on a failure to set up the device, or if the name is a duplicate.
4081 + *
4082 + *     This is a wrapper around register_netdevice that takes the rtnl semaphore
4083 + *     and expands the device name if you passed a format string to
4084 + *     alloc_netdev.
4085 + */
4086 +int register_netdev(struct net_device *dev)
4087 +{
4088 +       int err;
4089 +
4090 +       rtnl_lock();
4091 +
4092 +       /*
4093 +        * If the name is a format string the caller wants us to do a
4094 +        * name allocation.
4095 +        */
4096 +       if (strchr(dev->name, '%')) {
4097 +               err = dev_alloc_name(dev, dev->name);
4098 +               if (err < 0)
4099 +                       goto out;
4100 +       }
4101 +
4102 +       err = register_netdevice(dev);
4103 +out:
4104 +       rtnl_unlock();
4105 +       return err;
4106 +}
4107 +EXPORT_SYMBOL(register_netdev);
4108 +
4109 +/*
4110 + * netdev_wait_allrefs - wait until all references are gone.
4111 + *
4112 + * This is called when unregistering network devices.
4113 + *
4114 + * Any protocol or device that holds a reference should register
4115 + * for netdevice notification, and cleanup and put back the
4116 + * reference if they receive an UNREGISTER event.
4117 + * We can get stuck here if buggy protocols don't correctly
4118 + * call dev_put.
4119 + */
4120 +static void netdev_wait_allrefs(struct net_device *dev)
4121 +{
4122 +       unsigned long rebroadcast_time, warning_time;
4123 +
4124 +       rebroadcast_time = warning_time = jiffies;
4125 +       while (atomic_read(&dev->refcnt) != 0) {
4126 +               if (time_after(jiffies, rebroadcast_time + 1 * HZ)) {
4127 +                       rtnl_lock();
4128 +
4129 +                       /* Rebroadcast unregister notification */
4130 +                       raw_notifier_call_chain(&netdev_chain,
4131 +                                           NETDEV_UNREGISTER, dev);
4132 +
4133 +                       if (test_bit(__LINK_STATE_LINKWATCH_PENDING,
4134 +                                    &dev->state)) {
4135 +                               /* We must not have linkwatch events
4136 +                                * pending on unregister. If this
4137 +                                * happens, we simply run the queue
4138 +                                * unscheduled, resulting in a noop
4139 +                                * for this device.
4140 +                                */
4141 +                               linkwatch_run_queue();
4142 +                       }
4143 +
4144 +                       __rtnl_unlock();
4145 +
4146 +                       rebroadcast_time = jiffies;
4147 +               }
4148 +
4149 +               msleep(250);
4150 +
4151 +               if (time_after(jiffies, warning_time + 10 * HZ)) {
4152 +                       printk(KERN_EMERG "unregister_netdevice: "
4153 +                              "waiting for %s to become free. Usage "
4154 +                              "count = %d\n",
4155 +                              dev->name, atomic_read(&dev->refcnt));
4156 +                       warning_time = jiffies;
4157 +               }
4158 +       }
4159 +}
4160 +
4161 +/* The sequence is:
4162 + *
4163 + *     rtnl_lock();
4164 + *     ...
4165 + *     register_netdevice(x1);
4166 + *     register_netdevice(x2);
4167 + *     ...
4168 + *     unregister_netdevice(y1);
4169 + *     unregister_netdevice(y2);
4170 + *      ...
4171 + *     rtnl_unlock();
4172 + *     free_netdev(y1);
4173 + *     free_netdev(y2);
4174 + *
4175 + * We are invoked by rtnl_unlock() after it drops the semaphore.
4176 + * This allows us to deal with problems:
4177 + * 1) We can delete sysfs objects which invoke hotplug
4178 + *    without deadlocking with linkwatch via keventd.
4179 + * 2) Since we run with the RTNL semaphore not held, we can sleep
4180 + *    safely in order to wait for the netdev refcnt to drop to zero.
4181 + */
4182 +static DEFINE_MUTEX(net_todo_run_mutex);
4183 +void netdev_run_todo(void)
4184 +{
4185 +       struct list_head list;
4186 +
4187 +       /* Need to guard against multiple cpu's getting out of order. */
4188 +       mutex_lock(&net_todo_run_mutex);
4189 +
4190 +       /* Not safe to do outside the semaphore.  We must not return
4191 +        * until all unregister events invoked by the local processor
4192 +        * have been completed (either by this todo run, or one on
4193 +        * another cpu).
4194 +        */
4195 +       if (list_empty(&net_todo_list))
4196 +               goto out;
4197 +
4198 +       /* Snapshot list, allow later requests */
4199 +       spin_lock(&net_todo_list_lock);
4200 +       list_replace_init(&net_todo_list, &list);
4201 +       spin_unlock(&net_todo_list_lock);
4202 +
4203 +       while (!list_empty(&list)) {
4204 +               struct net_device *dev
4205 +                       = list_entry(list.next, struct net_device, todo_list);
4206 +               list_del(&dev->todo_list);
4207 +
4208 +               if (unlikely(dev->reg_state != NETREG_UNREGISTERING)) {
4209 +                       printk(KERN_ERR "network todo '%s' but state %d\n",
4210 +                              dev->name, dev->reg_state);
4211 +                       dump_stack();
4212 +                       continue;
4213 +               }
4214 +
4215 +               dev->reg_state = NETREG_UNREGISTERED;
4216 +
4217 +               netdev_wait_allrefs(dev);
4218 +
4219 +               /* paranoia */
4220 +               BUG_ON(atomic_read(&dev->refcnt));
4221 +               BUG_TRAP(!dev->ip_ptr);
4222 +               BUG_TRAP(!dev->ip6_ptr);
4223 +               BUG_TRAP(!dev->dn_ptr);
4224 +
4225 +               if (dev->destructor)
4226 +                       dev->destructor(dev);
4227 +
4228 +               /* Free network device */
4229 +               kobject_put(&dev->dev.kobj);
4230 +       }
4231 +
4232 +out:
4233 +       mutex_unlock(&net_todo_run_mutex);
4234 +}
4235 +
4236 +static struct net_device_stats *internal_stats(struct net_device *dev)
4237 +{
4238 +       return &dev->stats;
4239 +}
4240 +
4241 +/**
4242 + *     alloc_netdev - allocate network device
4243 + *     @sizeof_priv:   size of private data to allocate space for
4244 + *     @name:          device name format string
4245 + *     @setup:         callback to initialize device
4246 + *
4247 + *     Allocates a struct net_device with private data area for driver use
4248 + *     and performs basic initialization.
4249 + */
4250 +struct net_device *alloc_netdev(int sizeof_priv, const char *name,
4251 +               void (*setup)(struct net_device *))
4252 +{
4253 +       void *p;
4254 +       struct net_device *dev;
4255 +       int alloc_size;
4256 +
4257 +       BUG_ON(strlen(name) >= sizeof(dev->name));
4258 +
4259 +       /* ensure 32-byte alignment of both the device and private area */
4260 +       alloc_size = (sizeof(*dev) + NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST;
4261 +       alloc_size += sizeof_priv + NETDEV_ALIGN_CONST;
4262 +
4263 +       p = kzalloc(alloc_size, GFP_KERNEL);
4264 +       if (!p) {
4265 +               printk(KERN_ERR "alloc_netdev: Unable to allocate device.\n");
4266 +               return NULL;
4267 +       }
4268 +
4269 +       dev = (struct net_device *)
4270 +               (((long)p + NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
4271 +       dev->padded = (char *)dev - (char *)p;
4272 +       dev->nd_net = &init_net;
4273 +
4274 +       if (sizeof_priv)
4275 +               dev->priv = netdev_priv(dev);
4276 +
4277 +       dev->get_stats = internal_stats;
4278 +       setup(dev);
4279 +       strcpy(dev->name, name);
4280 +       return dev;
4281 +}
4282 +EXPORT_SYMBOL(alloc_netdev);
4283 +
4284 +/**
4285 + *     free_netdev - free network device
4286 + *     @dev: device
4287 + *
4288 + *     This function does the last stage of destroying an allocated device
4289 + *     interface. The reference to the device object is released.
4290 + *     If this is the last reference then it will be freed.
4291 + */
4292 +void free_netdev(struct net_device *dev)
4293 +{
4294 +#ifdef CONFIG_SYSFS
4295 +       /*  Compatibility with error handling in drivers */
4296 +       if (dev->reg_state == NETREG_UNINITIALIZED) {
4297 +               kfree((char *)dev - dev->padded);
4298 +               return;
4299 +       }
4300 +
4301 +       BUG_ON(dev->reg_state != NETREG_UNREGISTERED);
4302 +       dev->reg_state = NETREG_RELEASED;
4303 +
4304 +       /* will free via device release */
4305 +       put_device(&dev->dev);
4306 +#else
4307 +       kfree((char *)dev - dev->padded);
4308 +#endif
4309 +}
4310 +
4311 +/* Synchronize with packet receive processing. */
4312 +void synchronize_net(void)
4313 +{
4314 +       might_sleep();
4315 +       synchronize_rcu();
4316 +}
4317 +
4318 +/**
4319 + *     unregister_netdevice - remove device from the kernel
4320 + *     @dev: device
4321 + *
4322 + *     This function shuts down a device interface and removes it
4323 + *     from the kernel tables. On success 0 is returned, on a failure
4324 + *     a negative errno code is returned.
4325 + *
4326 + *     Callers must hold the rtnl semaphore.  You may want
4327 + *     unregister_netdev() instead of this.
4328 + */
4329 +
4330 +void unregister_netdevice(struct net_device *dev)
4331 +{
4332 +       BUG_ON(dev_boot_phase);
4333 +       ASSERT_RTNL();
4334 +
4335 +       /* Some devices call without registering for initialization unwind. */
4336 +       if (dev->reg_state == NETREG_UNINITIALIZED) {
4337 +               printk(KERN_DEBUG "unregister_netdevice: device %s/%p never "
4338 +                                 "was registered\n", dev->name, dev);
4339 +
4340 +               WARN_ON(1);
4341 +               return;
4342 +       }
4343 +
4344 +       BUG_ON(dev->reg_state != NETREG_REGISTERED);
4345 +
4346 +       /* If device is running, close it first. */
4347 +       if (dev->flags & IFF_UP)
4348 +               dev_close(dev);
4349 +
4350 +       /* And unlink it from device chain. */
4351 +       unlist_netdevice(dev);
4352 +
4353 +       dev->reg_state = NETREG_UNREGISTERING;
4354 +
4355 +       synchronize_net();
4356 +
4357 +       /* Shutdown queueing discipline. */
4358 +       dev_shutdown(dev);
4359 +
4360 +
4361 +       /* Notify protocols, that we are about to destroy
4362 +          this device. They should clean all the things.
4363 +       */
4364 +       raw_notifier_call_chain(&netdev_chain, NETDEV_UNREGISTER, dev);
4365 +
4366 +       /*
4367 +        *      Flush the multicast chain
4368 +        */
4369 +       dev_mc_discard(dev);
4370 +
4371 +       if (dev->uninit)
4372 +               dev->uninit(dev);
4373 +
4374 +       /* Notifier chain MUST detach us from master device. */
4375 +       BUG_TRAP(!dev->master);
4376 +
4377 +       /* Remove entries from sysfs */
4378 +       netdev_unregister_sysfs(dev);
4379 +
4380 +       /* Finish processing unregister after unlock */
4381 +       net_set_todo(dev);
4382 +
4383 +       synchronize_net();
4384 +
4385 +       dev_put(dev);
4386 +}
4387 +
4388 +/**
4389 + *     unregister_netdev - remove device from the kernel
4390 + *     @dev: device
4391 + *
4392 + *     This function shuts down a device interface and removes it
4393 + *     from the kernel tables. On success 0 is returned, on a failure
4394 + *     a negative errno code is returned.
4395 + *
4396 + *     This is just a wrapper for unregister_netdevice that takes
4397 + *     the rtnl semaphore.  In general you want to use this and not
4398 + *     unregister_netdevice.
4399 + */
4400 +void unregister_netdev(struct net_device *dev)
4401 +{
4402 +       rtnl_lock();
4403 +       unregister_netdevice(dev);
4404 +       rtnl_unlock();
4405 +}
4406 +
4407 +EXPORT_SYMBOL(unregister_netdev);
4408 +
4409 +/**
4410 + *     dev_change_net_namespace - move device to different nethost namespace
4411 + *     @dev: device
4412 + *     @net: network namespace
4413 + *     @pat: If not NULL name pattern to try if the current device name
4414 + *           is already taken in the destination network namespace.
4415 + *
4416 + *     This function shuts down a device interface and moves it
4417 + *     to a new network namespace. On success 0 is returned, on
4418 + *     a failure a netagive errno code is returned.
4419 + *
4420 + *     Callers must hold the rtnl semaphore.
4421 + */
4422 +
4423 +int dev_change_net_namespace(struct net_device *dev, struct net *net, const char *pat)
4424 +{
4425 +       char buf[IFNAMSIZ];
4426 +       const char *destname;
4427 +       int err;
4428 +
4429 +       ASSERT_RTNL();
4430 +
4431 +       /* Don't allow namespace local devices to be moved. */
4432 +       err = -EINVAL;
4433 +       if (dev->features & NETIF_F_NETNS_LOCAL)
4434 +               goto out;
4435 +
4436 +       /* Ensure the device has been registrered */
4437 +       err = -EINVAL;
4438 +       if (dev->reg_state != NETREG_REGISTERED)
4439 +               goto out;
4440 +       
4441 +       /* Get out if there is nothing todo */
4442 +       err = 0;
4443 +       if (dev->nd_net == net)
4444 +               goto out;
4445 +
4446 +       /* Pick the destination device name, and ensure
4447 +        * we can use it in the destination network namespace.
4448 +        */
4449 +       err = -EEXIST;
4450 +       destname = dev->name;
4451 +       if (__dev_get_by_name(net, destname)) {
4452 +               /* We get here if we can't use the current device name */
4453 +               if (!pat)
4454 +                       goto out;
4455 +               if (!dev_valid_name(pat))
4456 +                       goto out;
4457 +               if (strchr(pat, '%')) {
4458 +                       if (__dev_alloc_name(net, pat, buf) < 0)
4459 +                               goto out;
4460 +                       destname = buf;
4461 +               } else
4462 +                       destname = pat;
4463 +               if (__dev_get_by_name(net, destname))
4464 +                       goto out;
4465 +       }
4466 +
4467 +       /*
4468 +        * And now a mini version of register_netdevice unregister_netdevice. 
4469 +        */
4470 +
4471 +       /* If device is running close it first. */
4472 +       if (dev->flags & IFF_UP)
4473 +               dev_close(dev);
4474 +
4475 +       /* And unlink it from device chain */
4476 +       err = -ENODEV;
4477 +       unlist_netdevice(dev);
4478 +       
4479 +       synchronize_net();
4480 +       
4481 +       /* Shutdown queueing discipline. */
4482 +       dev_shutdown(dev);
4483 +
4484 +       /* Notify protocols, that we are about to destroy
4485 +          this device. They should clean all the things.
4486 +       */
4487 +       call_netdevice_notifiers(NETDEV_UNREGISTER, dev);
4488 +       
4489 +       /*
4490 +        *      Flush the multicast chain
4491 +        */
4492 +       dev_mc_discard(dev);
4493 +
4494 +       /* Actually switch the network namespace */
4495 +       dev->nd_net = net;
4496 +       
4497 +       /* Assign the new device name */
4498 +       if (destname != dev->name)
4499 +               strcpy(dev->name, destname);
4500 +
4501 +       /* If there is an ifindex conflict assign a new one */
4502 +       if (__dev_get_by_index(net, dev->ifindex)) {
4503 +               int iflink = (dev->iflink == dev->ifindex);
4504 +               dev->ifindex = dev_new_index(net);
4505 +               if (iflink)
4506 +                       dev->iflink = dev->ifindex;
4507 +       }
4508 +
4509 +       /* Fixup sysfs */
4510 +       err = device_rename(&dev->dev, dev->name);
4511 +       BUG_ON(err);
4512 +
4513 +       /* Add the device back in the hashes */
4514 +       list_netdevice(dev);
4515 +
4516 +       /* Notify protocols, that a new device appeared. */
4517 +       call_netdevice_notifiers(NETDEV_REGISTER, dev);
4518 +
4519 +       synchronize_net();
4520 +       err = 0;
4521 +out:
4522 +       return err;
4523 +}
4524 +
4525 +static int dev_cpu_callback(struct notifier_block *nfb,
4526 +                           unsigned long action,
4527 +                           void *ocpu)
4528 +{
4529 +       struct sk_buff **list_skb;
4530 +       struct net_device **list_net;
4531 +       struct sk_buff *skb;
4532 +       unsigned int cpu, oldcpu = (unsigned long)ocpu;
4533 +       struct softnet_data *sd, *oldsd;
4534 +
4535 +       if (action != CPU_DEAD && action != CPU_DEAD_FROZEN)
4536 +               return NOTIFY_OK;
4537 +
4538 +       local_irq_disable();
4539 +       cpu = smp_processor_id();
4540 +       sd = &per_cpu(softnet_data, cpu);
4541 +       oldsd = &per_cpu(softnet_data, oldcpu);
4542 +
4543 +       /* Find end of our completion_queue. */
4544 +       list_skb = &sd->completion_queue;
4545 +       while (*list_skb)
4546 +               list_skb = &(*list_skb)->next;
4547 +       /* Append completion queue from offline CPU. */
4548 +       *list_skb = oldsd->completion_queue;
4549 +       oldsd->completion_queue = NULL;
4550 +
4551 +       /* Find end of our output_queue. */
4552 +       list_net = &sd->output_queue;
4553 +       while (*list_net)
4554 +               list_net = &(*list_net)->next_sched;
4555 +       /* Append output queue from offline CPU. */
4556 +       *list_net = oldsd->output_queue;
4557 +       oldsd->output_queue = NULL;
4558 +
4559 +       raise_softirq_irqoff(NET_TX_SOFTIRQ);
4560 +       local_irq_enable();
4561 +
4562 +       /* Process offline CPU's input_pkt_queue */
4563 +       while ((skb = __skb_dequeue(&oldsd->input_pkt_queue)))
4564 +               netif_rx(skb);
4565 +
4566 +       return NOTIFY_OK;
4567 +}
4568 +
4569 +#ifdef CONFIG_NET_DMA
4570 +/**
4571 + * net_dma_rebalance -
4572 + * This is called when the number of channels allocated to the net_dma_client
4573 + * changes.  The net_dma_client tries to have one DMA channel per CPU.
4574 + */
4575 +
4576 +static void net_dma_rebalance(struct net_dma *net_dma)
4577 +{
4578 +       unsigned int cpu, i, n, chan_idx;
4579 +       struct dma_chan *chan;
4580 +
4581 +       if (cpus_empty(net_dma->channel_mask)) {
4582 +               for_each_online_cpu(cpu)
4583 +                       rcu_assign_pointer(per_cpu(softnet_data, cpu).net_dma, NULL);
4584 +               return;
4585 +       }
4586 +
4587 +       i = 0;
4588 +       cpu = first_cpu(cpu_online_map);
4589 +
4590 +       for_each_cpu_mask(chan_idx, net_dma->channel_mask) {
4591 +               chan = net_dma->channels[chan_idx];
4592 +
4593 +               n = ((num_online_cpus() / cpus_weight(net_dma->channel_mask))
4594 +                  + (i < (num_online_cpus() %
4595 +                       cpus_weight(net_dma->channel_mask)) ? 1 : 0));
4596 +
4597 +               while(n) {
4598 +                       per_cpu(softnet_data, cpu).net_dma = chan;
4599 +                       cpu = next_cpu(cpu, cpu_online_map);
4600 +                       n--;
4601 +               }
4602 +               i++;
4603 +       }
4604 +}
4605 +
4606 +/**
4607 + * netdev_dma_event - event callback for the net_dma_client
4608 + * @client: should always be net_dma_client
4609 + * @chan: DMA channel for the event
4610 + * @event: event type
4611 + */
4612 +static enum dma_state_client
4613 +netdev_dma_event(struct dma_client *client, struct dma_chan *chan,
4614 +       enum dma_state state)
4615 +{
4616 +       int i, found = 0, pos = -1;
4617 +       struct net_dma *net_dma =
4618 +               container_of(client, struct net_dma, client);
4619 +       enum dma_state_client ack = DMA_DUP; /* default: take no action */
4620 +
4621 +       spin_lock(&net_dma->lock);
4622 +       switch (state) {
4623 +       case DMA_RESOURCE_AVAILABLE:
4624 +               for (i = 0; i < NR_CPUS; i++)
4625 +                       if (net_dma->channels[i] == chan) {
4626 +                               found = 1;
4627 +                               break;
4628 +                       } else if (net_dma->channels[i] == NULL && pos < 0)
4629 +                               pos = i;
4630 +
4631 +               if (!found && pos >= 0) {
4632 +                       ack = DMA_ACK;
4633 +                       net_dma->channels[pos] = chan;
4634 +                       cpu_set(pos, net_dma->channel_mask);
4635 +                       net_dma_rebalance(net_dma);
4636 +               }
4637 +               break;
4638 +       case DMA_RESOURCE_REMOVED:
4639 +               for (i = 0; i < NR_CPUS; i++)
4640 +                       if (net_dma->channels[i] == chan) {
4641 +                               found = 1;
4642 +                               pos = i;
4643 +                               break;
4644 +                       }
4645 +
4646 +               if (found) {
4647 +                       ack = DMA_ACK;
4648 +                       cpu_clear(pos, net_dma->channel_mask);
4649 +                       net_dma->channels[i] = NULL;
4650 +                       net_dma_rebalance(net_dma);
4651 +               }
4652 +               break;
4653 +       default:
4654 +               break;
4655 +       }
4656 +       spin_unlock(&net_dma->lock);
4657 +
4658 +       return ack;
4659 +}
4660 +
4661 +/**
4662 + * netdev_dma_regiser - register the networking subsystem as a DMA client
4663 + */
4664 +static int __init netdev_dma_register(void)
4665 +{
4666 +       spin_lock_init(&net_dma.lock);
4667 +       dma_cap_set(DMA_MEMCPY, net_dma.client.cap_mask);
4668 +       dma_async_client_register(&net_dma.client);
4669 +       dma_async_client_chan_request(&net_dma.client);
4670 +       return 0;
4671 +}
4672 +
4673 +#else
4674 +static int __init netdev_dma_register(void) { return -ENODEV; }
4675 +#endif /* CONFIG_NET_DMA */
4676 +
4677 +/**
4678 + *     netdev_compute_feature - compute conjunction of two feature sets
4679 + *     @all: first feature set
4680 + *     @one: second feature set
4681 + *
4682 + *     Computes a new feature set after adding a device with feature set
4683 + *     @one to the master device with current feature set @all.  Returns
4684 + *     the new feature set.
4685 + */
4686 +int netdev_compute_features(unsigned long all, unsigned long one)
4687 +{
4688 +       /* if device needs checksumming, downgrade to hw checksumming */
4689 +       if (all & NETIF_F_NO_CSUM && !(one & NETIF_F_NO_CSUM))
4690 +               all ^= NETIF_F_NO_CSUM | NETIF_F_HW_CSUM;
4691 +
4692 +       /* if device can't do all checksum, downgrade to ipv4 */
4693 +       if (all & NETIF_F_HW_CSUM && !(one & NETIF_F_HW_CSUM))
4694 +               all ^= NETIF_F_HW_CSUM | NETIF_F_IP_CSUM;
4695 +
4696 +       if (one & NETIF_F_GSO)
4697 +               one |= NETIF_F_GSO_SOFTWARE;
4698 +       one |= NETIF_F_GSO;
4699 +
4700 +       /* If even one device supports robust GSO, enable it for all. */
4701 +       if (one & NETIF_F_GSO_ROBUST)
4702 +               all |= NETIF_F_GSO_ROBUST;
4703 +
4704 +       all &= one | NETIF_F_LLTX;
4705 +
4706 +       if (!(all & NETIF_F_ALL_CSUM))
4707 +               all &= ~NETIF_F_SG;
4708 +       if (!(all & NETIF_F_SG))
4709 +               all &= ~NETIF_F_GSO_MASK;
4710 +
4711 +       return all;
4712 +}
4713 +EXPORT_SYMBOL(netdev_compute_features);
4714 +
4715 +/* Initialize per network namespace state */
4716 +static int netdev_init(struct net *net)
4717 +{
4718 +       int i;
4719 +       INIT_LIST_HEAD(&net->dev_base_head);
4720 +       rwlock_init(&dev_base_lock);
4721 +
4722 +       net->dev_name_head = kmalloc(
4723 +               sizeof(*net->dev_name_head)*NETDEV_HASHENTRIES, GFP_KERNEL);
4724 +       if (!net->dev_name_head)
4725 +               return -ENOMEM;
4726 +
4727 +       net->dev_index_head = kmalloc(
4728 +               sizeof(*net->dev_index_head)*NETDEV_HASHENTRIES, GFP_KERNEL);
4729 +       if (!net->dev_index_head) {
4730 +               kfree(net->dev_name_head);
4731 +               return -ENOMEM;
4732 +       }
4733 +
4734 +       for (i = 0; i < NETDEV_HASHENTRIES; i++)
4735 +               INIT_HLIST_HEAD(&net->dev_name_head[i]);
4736 +       
4737 +       for (i = 0; i < NETDEV_HASHENTRIES; i++)
4738 +               INIT_HLIST_HEAD(&net->dev_index_head[i]);
4739 +
4740 +       return 0;
4741 +}
4742 +
4743 +static void netdev_exit(struct net *net)
4744 +{
4745 +       kfree(net->dev_name_head);
4746 +       kfree(net->dev_index_head);
4747 +}
4748 +
4749 +static struct pernet_operations netdev_net_ops = {
4750 +       .init = netdev_init,
4751 +       .exit = netdev_exit,
4752 +};
4753 +
4754 +static void default_device_exit(struct net *net)
4755 +{
4756 +       struct net_device *dev, *next;
4757 +       /*
4758 +        * Push all migratable of the network devices back to the
4759 +        * initial network namespace 
4760 +        */
4761 +       rtnl_lock();
4762 +       for_each_netdev_safe(net, dev, next) {
4763 +               int err;
4764 +
4765 +               /* Ignore unmoveable devices (i.e. loopback) */
4766 +               if (dev->features & NETIF_F_NETNS_LOCAL)
4767 +                       continue;
4768 +
4769 +               /* Push remaing network devices to init_net */
4770 +               err = dev_change_net_namespace(dev, &init_net, "dev%d");
4771 +               if (err) {
4772 +                       printk(KERN_WARNING "%s: failed to move %s to init_net: %d\n",
4773 +                               __func__, dev->name, err);
4774 +                       unregister_netdevice(dev);
4775 +               }
4776 +       }
4777 +       rtnl_unlock();
4778 +}
4779 +
4780 +static struct pernet_operations default_device_ops = {
4781 +       .exit = default_device_exit,
4782 +};
4783 +
4784 +/*
4785 + *     Initialize the DEV module. At boot time this walks the device list and
4786 + *     unhooks any devices that fail to initialise (normally hardware not
4787 + *     present) and leaves us with a valid list of present and active devices.
4788 + *
4789 + */
4790 +
4791 +/*
4792 + *       This is called single threaded during boot, so no need
4793 + *       to take the rtnl semaphore.
4794 + */
4795 +static int __init net_dev_init(void)
4796 +{
4797 +       int i, rc = -ENOMEM;
4798 +
4799 +       BUG_ON(!dev_boot_phase);
4800 +
4801 +       if (dev_proc_init())
4802 +               goto out;
4803 +
4804 +       if (netdev_sysfs_init())
4805 +               goto out;
4806 +
4807 +       INIT_LIST_HEAD(&ptype_all);
4808 +       for (i = 0; i < 16; i++)
4809 +               INIT_LIST_HEAD(&ptype_base[i]);
4810 +
4811 +       if (register_pernet_subsys(&netdev_net_ops))
4812 +               goto out;
4813 +
4814 +       if (register_pernet_device(&default_device_ops))
4815 +               goto out;
4816 +
4817 +       /*
4818 +        *      Initialise the packet receive queues.
4819 +        */
4820 +
4821 +       for_each_possible_cpu(i) {
4822 +               struct softnet_data *queue;
4823 +
4824 +               queue = &per_cpu(softnet_data, i);
4825 +               skb_queue_head_init(&queue->input_pkt_queue);
4826 +               queue->completion_queue = NULL;
4827 +               INIT_LIST_HEAD(&queue->poll_list);
4828 +               set_bit(__LINK_STATE_START, &queue->backlog_dev.state);
4829 +               queue->backlog_dev.weight = weight_p;
4830 +               queue->backlog_dev.poll = process_backlog;
4831 +               atomic_set(&queue->backlog_dev.refcnt, 1);
4832 +       }
4833 +
4834 +       netdev_dma_register();
4835 +
4836 +       dev_boot_phase = 0;
4837 +
4838 +       open_softirq(NET_TX_SOFTIRQ, net_tx_action, NULL);
4839 +       open_softirq(NET_RX_SOFTIRQ, net_rx_action, NULL);
4840 +
4841 +       hotcpu_notifier(dev_cpu_callback, 0);
4842 +       dst_init();
4843 +       dev_mcast_init();
4844 +       rc = 0;
4845 +out:
4846 +       return rc;
4847 +}
4848 +
4849 +subsys_initcall(net_dev_init);
4850 +
4851 +EXPORT_SYMBOL(__dev_get_by_index);
4852 +EXPORT_SYMBOL(__dev_get_by_name);
4853 +EXPORT_SYMBOL(__dev_remove_pack);
4854 +EXPORT_SYMBOL(dev_valid_name);
4855 +EXPORT_SYMBOL(dev_add_pack);
4856 +EXPORT_SYMBOL(dev_alloc_name);
4857 +EXPORT_SYMBOL(dev_close);
4858 +EXPORT_SYMBOL(dev_get_by_flags);
4859 +EXPORT_SYMBOL(dev_get_by_index);
4860 +EXPORT_SYMBOL(dev_get_by_name);
4861 +EXPORT_SYMBOL(dev_open);
4862 +EXPORT_SYMBOL(dev_queue_xmit);
4863 +EXPORT_SYMBOL(dev_remove_pack);
4864 +EXPORT_SYMBOL(dev_set_allmulti);
4865 +EXPORT_SYMBOL(dev_set_promiscuity);
4866 +EXPORT_SYMBOL(dev_change_flags);
4867 +EXPORT_SYMBOL(dev_set_mtu);
4868 +EXPORT_SYMBOL(dev_set_mac_address);
4869 +EXPORT_SYMBOL(free_netdev);
4870 +EXPORT_SYMBOL(netdev_boot_setup_check);
4871 +EXPORT_SYMBOL(netdev_set_master);
4872 +EXPORT_SYMBOL(netdev_state_change);
4873 +EXPORT_SYMBOL(netif_receive_skb);
4874 +EXPORT_SYMBOL(netif_rx);
4875 +EXPORT_SYMBOL(register_gifconf);
4876 +EXPORT_SYMBOL(register_netdevice);
4877 +EXPORT_SYMBOL(register_netdevice_notifier);
4878 +EXPORT_SYMBOL(skb_checksum_help);
4879 +EXPORT_SYMBOL(synchronize_net);
4880 +EXPORT_SYMBOL(unregister_netdevice);
4881 +EXPORT_SYMBOL(unregister_netdevice_notifier);
4882 +EXPORT_SYMBOL(net_enable_timestamp);
4883 +EXPORT_SYMBOL(net_disable_timestamp);
4884 +EXPORT_SYMBOL(dev_get_flags);
4885 +
4886 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
4887 +EXPORT_SYMBOL(br_handle_frame_hook);
4888 +EXPORT_SYMBOL(br_fdb_get_hook);
4889 +EXPORT_SYMBOL(br_fdb_put_hook);
4890 +#endif
4891 +
4892 +#ifdef CONFIG_KMOD
4893 +EXPORT_SYMBOL(dev_load);
4894 +#endif
4895 +
4896 +EXPORT_PER_CPU_SYMBOL(softnet_data);
4897 diff -Nurb linux-2.6.22-594/net/core/net_namespace.c linux-2.6.22-595/net/core/net_namespace.c
4898 --- linux-2.6.22-594/net/core/net_namespace.c   2008-03-20 01:27:51.000000000 -0400
4899 +++ linux-2.6.22-595/net/core/net_namespace.c   2008-03-20 01:28:00.000000000 -0400
4900 @@ -112,10 +112,12 @@
4901                 ops = list_entry(ptr, struct pernet_operations, list);
4902                 if (ops->init) {
4903                         error = ops->init(net);
4904 -                       if (error < 0)
4905 +                       if (error < 0) {
4906 +                               printk(KERN_ALERT "Error setting up netns: %x\n", ops->init);
4907                                 goto out_undo;
4908                 }
4909         }
4910 +       }
4911  out:
4912         return error;
4913  out_undo:
4914 diff -Nurb linux-2.6.22-594/net/ipv4/af_inet.c.orig linux-2.6.22-595/net/ipv4/af_inet.c.orig
4915 --- linux-2.6.22-594/net/ipv4/af_inet.c.orig    2008-03-20 01:27:51.000000000 -0400
4916 +++ linux-2.6.22-595/net/ipv4/af_inet.c.orig    1969-12-31 19:00:00.000000000 -0500
4917 @@ -1,1522 +0,0 @@
4918 -/*
4919 - * INET                An implementation of the TCP/IP protocol suite for the LINUX
4920 - *             operating system.  INET is implemented using the  BSD Socket
4921 - *             interface as the means of communication with the user level.
4922 - *
4923 - *             PF_INET protocol family socket handler.
4924 - *
4925 - * Version:    $Id: af_inet.c,v 1.137 2002/02/01 22:01:03 davem Exp $
4926 - *
4927 - * Authors:    Ross Biro
4928 - *             Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
4929 - *             Florian La Roche, <flla@stud.uni-sb.de>
4930 - *             Alan Cox, <A.Cox@swansea.ac.uk>
4931 - *
4932 - * Changes (see also sock.c)
4933 - *
4934 - *             piggy,
4935 - *             Karl Knutson    :       Socket protocol table
4936 - *             A.N.Kuznetsov   :       Socket death error in accept().
4937 - *             John Richardson :       Fix non blocking error in connect()
4938 - *                                     so sockets that fail to connect
4939 - *                                     don't return -EINPROGRESS.
4940 - *             Alan Cox        :       Asynchronous I/O support
4941 - *             Alan Cox        :       Keep correct socket pointer on sock
4942 - *                                     structures
4943 - *                                     when accept() ed
4944 - *             Alan Cox        :       Semantics of SO_LINGER aren't state
4945 - *                                     moved to close when you look carefully.
4946 - *                                     With this fixed and the accept bug fixed
4947 - *                                     some RPC stuff seems happier.
4948 - *             Niibe Yutaka    :       4.4BSD style write async I/O
4949 - *             Alan Cox,
4950 - *             Tony Gale       :       Fixed reuse semantics.
4951 - *             Alan Cox        :       bind() shouldn't abort existing but dead
4952 - *                                     sockets. Stops FTP netin:.. I hope.
4953 - *             Alan Cox        :       bind() works correctly for RAW sockets.
4954 - *                                     Note that FreeBSD at least was broken
4955 - *                                     in this respect so be careful with
4956 - *                                     compatibility tests...
4957 - *             Alan Cox        :       routing cache support
4958 - *             Alan Cox        :       memzero the socket structure for
4959 - *                                     compactness.
4960 - *             Matt Day        :       nonblock connect error handler
4961 - *             Alan Cox        :       Allow large numbers of pending sockets
4962 - *                                     (eg for big web sites), but only if
4963 - *                                     specifically application requested.
4964 - *             Alan Cox        :       New buffering throughout IP. Used
4965 - *                                     dumbly.
4966 - *             Alan Cox        :       New buffering now used smartly.
4967 - *             Alan Cox        :       BSD rather than common sense
4968 - *                                     interpretation of listen.
4969 - *             Germano Caronni :       Assorted small races.
4970 - *             Alan Cox        :       sendmsg/recvmsg basic support.
4971 - *             Alan Cox        :       Only sendmsg/recvmsg now supported.
4972 - *             Alan Cox        :       Locked down bind (see security list).
4973 - *             Alan Cox        :       Loosened bind a little.
4974 - *             Mike McLagan    :       ADD/DEL DLCI Ioctls
4975 - *     Willy Konynenberg       :       Transparent proxying support.
4976 - *             David S. Miller :       New socket lookup architecture.
4977 - *                                     Some other random speedups.
4978 - *             Cyrus Durgin    :       Cleaned up file for kmod hacks.
4979 - *             Andi Kleen      :       Fix inet_stream_connect TCP race.
4980 - *
4981 - *             This program is free software; you can redistribute it and/or
4982 - *             modify it under the terms of the GNU General Public License
4983 - *             as published by the Free Software Foundation; either version
4984 - *             2 of the License, or (at your option) any later version.
4985 - */
4986 -
4987 -#include <linux/err.h>
4988 -#include <linux/errno.h>
4989 -#include <linux/types.h>
4990 -#include <linux/socket.h>
4991 -#include <linux/in.h>
4992 -#include <linux/kernel.h>
4993 -#include <linux/module.h>
4994 -#include <linux/sched.h>
4995 -#include <linux/timer.h>
4996 -#include <linux/string.h>
4997 -#include <linux/sockios.h>
4998 -#include <linux/net.h>
4999 -#include <linux/capability.h>
5000 -#include <linux/fcntl.h>
5001 -#include <linux/mm.h>
5002 -#include <linux/interrupt.h>
5003 -#include <linux/stat.h>
5004 -#include <linux/init.h>
5005 -#include <linux/poll.h>
5006 -#include <linux/netfilter_ipv4.h>
5007 -#include <linux/random.h>
5008 -
5009 -#include <asm/uaccess.h>
5010 -#include <asm/system.h>
5011 -
5012 -#include <linux/inet.h>
5013 -#include <linux/igmp.h>
5014 -#include <linux/inetdevice.h>
5015 -#include <linux/netdevice.h>
5016 -#include <net/ip.h>
5017 -#include <net/protocol.h>
5018 -#include <net/arp.h>
5019 -#include <net/route.h>
5020 -#include <net/ip_fib.h>
5021 -#include <net/inet_connection_sock.h>
5022 -#include <net/tcp.h>
5023 -#include <net/udp.h>
5024 -#include <net/udplite.h>
5025 -#include <linux/skbuff.h>
5026 -#include <net/sock.h>
5027 -#include <net/raw.h>
5028 -#include <net/icmp.h>
5029 -#include <net/ipip.h>
5030 -#include <net/inet_common.h>
5031 -#include <net/xfrm.h>
5032 -#ifdef CONFIG_IP_MROUTE
5033 -#include <linux/mroute.h>
5034 -#endif
5035 -#include <linux/vs_limit.h>
5036 -
5037 -DEFINE_SNMP_STAT(struct linux_mib, net_statistics) __read_mostly;
5038 -
5039 -extern void ip_mc_drop_socket(struct sock *sk);
5040 -
5041 -/* The inetsw table contains everything that inet_create needs to
5042 - * build a new socket.
5043 - */
5044 -static struct list_head inetsw[SOCK_MAX];
5045 -static DEFINE_SPINLOCK(inetsw_lock);
5046 -
5047 -/* New destruction routine */
5048 -
5049 -void inet_sock_destruct(struct sock *sk)
5050 -{
5051 -       struct inet_sock *inet = inet_sk(sk);
5052 -
5053 -       __skb_queue_purge(&sk->sk_receive_queue);
5054 -       __skb_queue_purge(&sk->sk_error_queue);
5055 -
5056 -       if (sk->sk_type == SOCK_STREAM && sk->sk_state != TCP_CLOSE) {
5057 -               printk("Attempt to release TCP socket in state %d %p\n",
5058 -                      sk->sk_state, sk);
5059 -               return;
5060 -       }
5061 -       if (!sock_flag(sk, SOCK_DEAD)) {
5062 -               printk("Attempt to release alive inet socket %p\n", sk);
5063 -               return;
5064 -       }
5065 -
5066 -       BUG_TRAP(!atomic_read(&sk->sk_rmem_alloc));
5067 -       BUG_TRAP(!atomic_read(&sk->sk_wmem_alloc));
5068 -       BUG_TRAP(!sk->sk_wmem_queued);
5069 -       BUG_TRAP(!sk->sk_forward_alloc);
5070 -
5071 -       kfree(inet->opt);
5072 -       dst_release(sk->sk_dst_cache);
5073 -       sk_refcnt_debug_dec(sk);
5074 -}
5075 -
5076 -/*
5077 - *     The routines beyond this point handle the behaviour of an AF_INET
5078 - *     socket object. Mostly it punts to the subprotocols of IP to do
5079 - *     the work.
5080 - */
5081 -
5082 -/*
5083 - *     Automatically bind an unbound socket.
5084 - */
5085 -
5086 -static int inet_autobind(struct sock *sk)
5087 -{
5088 -       struct inet_sock *inet;
5089 -       /* We may need to bind the socket. */
5090 -       lock_sock(sk);
5091 -       inet = inet_sk(sk);
5092 -       if (!inet->num) {
5093 -               if (sk->sk_prot->get_port(sk, 0)) {
5094 -                       release_sock(sk);
5095 -                       return -EAGAIN;
5096 -               }
5097 -               inet->sport = htons(inet->num);
5098 -               sk->sk_xid = vx_current_xid();
5099 -               sk->sk_nid = nx_current_nid();
5100 -       }
5101 -       release_sock(sk);
5102 -       return 0;
5103 -}
5104 -
5105 -/*
5106 - *     Move a socket into listening state.
5107 - */
5108 -int inet_listen(struct socket *sock, int backlog)
5109 -{
5110 -       struct sock *sk = sock->sk;
5111 -       unsigned char old_state;
5112 -       int err;
5113 -
5114 -       lock_sock(sk);
5115 -
5116 -       err = -EINVAL;
5117 -       if (sock->state != SS_UNCONNECTED || sock->type != SOCK_STREAM)
5118 -               goto out;
5119 -
5120 -       old_state = sk->sk_state;
5121 -       if (!((1 << old_state) & (TCPF_CLOSE | TCPF_LISTEN)))
5122 -               goto out;
5123 -
5124 -       /* Really, if the socket is already in listen state
5125 -        * we can only allow the backlog to be adjusted.
5126 -        */
5127 -       if (old_state != TCP_LISTEN) {
5128 -               err = inet_csk_listen_start(sk, backlog);
5129 -               if (err)
5130 -                       goto out;
5131 -       }
5132 -       sk->sk_max_ack_backlog = backlog;
5133 -       err = 0;
5134 -
5135 -out:
5136 -       release_sock(sk);
5137 -       return err;
5138 -}
5139 -
5140 -u32 inet_ehash_secret __read_mostly;
5141 -EXPORT_SYMBOL(inet_ehash_secret);
5142 -
5143 -/*
5144 - * inet_ehash_secret must be set exactly once
5145 - * Instead of using a dedicated spinlock, we (ab)use inetsw_lock
5146 - */
5147 -void build_ehash_secret(void)
5148 -{
5149 -       u32 rnd;
5150 -       do {
5151 -               get_random_bytes(&rnd, sizeof(rnd));
5152 -       } while (rnd == 0);
5153 -       spin_lock_bh(&inetsw_lock);
5154 -       if (!inet_ehash_secret)
5155 -               inet_ehash_secret = rnd;
5156 -       spin_unlock_bh(&inetsw_lock);
5157 -}
5158 -EXPORT_SYMBOL(build_ehash_secret);
5159 -
5160 -/*
5161 - *     Create an inet socket.
5162 - */
5163 -
5164 -static int inet_create(struct socket *sock, int protocol)
5165 -{
5166 -       struct sock *sk;
5167 -       struct list_head *p;
5168 -       struct inet_protosw *answer;
5169 -       struct inet_sock *inet;
5170 -       struct proto *answer_prot;
5171 -       unsigned char answer_flags;
5172 -       char answer_no_check;
5173 -       int try_loading_module = 0;
5174 -       int err;
5175 -
5176 -       if (sock->type != SOCK_RAW &&
5177 -           sock->type != SOCK_DGRAM &&
5178 -           !inet_ehash_secret)
5179 -               build_ehash_secret();
5180 -
5181 -       sock->state = SS_UNCONNECTED;
5182 -
5183 -       /* Look for the requested type/protocol pair. */
5184 -       answer = NULL;
5185 -lookup_protocol:
5186 -       err = -ESOCKTNOSUPPORT;
5187 -       rcu_read_lock();
5188 -       list_for_each_rcu(p, &inetsw[sock->type]) {
5189 -               answer = list_entry(p, struct inet_protosw, list);
5190 -
5191 -               /* Check the non-wild match. */
5192 -               if (protocol == answer->protocol) {
5193 -                       if (protocol != IPPROTO_IP)
5194 -                               break;
5195 -               } else {
5196 -                       /* Check for the two wild cases. */
5197 -                       if (IPPROTO_IP == protocol) {
5198 -                               protocol = answer->protocol;
5199 -                               break;
5200 -                       }
5201 -                       if (IPPROTO_IP == answer->protocol)
5202 -                               break;
5203 -               }
5204 -               err = -EPROTONOSUPPORT;
5205 -               answer = NULL;
5206 -       }
5207 -
5208 -       if (unlikely(answer == NULL)) {
5209 -               if (try_loading_module < 2) {
5210 -                       rcu_read_unlock();
5211 -                       /*
5212 -                        * Be more specific, e.g. net-pf-2-proto-132-type-1
5213 -                        * (net-pf-PF_INET-proto-IPPROTO_SCTP-type-SOCK_STREAM)
5214 -                        */
5215 -                       if (++try_loading_module == 1)
5216 -                               request_module("net-pf-%d-proto-%d-type-%d",
5217 -                                              PF_INET, protocol, sock->type);
5218 -                       /*
5219 -                        * Fall back to generic, e.g. net-pf-2-proto-132
5220 -                        * (net-pf-PF_INET-proto-IPPROTO_SCTP)
5221 -                        */
5222 -                       else
5223 -                               request_module("net-pf-%d-proto-%d",
5224 -                                              PF_INET, protocol);
5225 -                       goto lookup_protocol;
5226 -               } else
5227 -                       goto out_rcu_unlock;
5228 -       }
5229 -
5230 -       err = -EPERM;
5231 -       if ((protocol == IPPROTO_ICMP) &&
5232 -               nx_capable(answer->capability, NXC_RAW_ICMP))
5233 -               goto override;
5234 -       if (sock->type == SOCK_RAW &&
5235 -               nx_capable(answer->capability, NXC_RAW_SOCKET))
5236 -               goto override;
5237 -       if (answer->capability > 0 && !capable(answer->capability))
5238 -               goto out_rcu_unlock;
5239 -override:
5240 -       sock->ops = answer->ops;
5241 -       answer_prot = answer->prot;
5242 -       answer_no_check = answer->no_check;
5243 -       answer_flags = answer->flags;
5244 -       rcu_read_unlock();
5245 -
5246 -       BUG_TRAP(answer_prot->slab != NULL);
5247 -
5248 -       err = -ENOBUFS;
5249 -       sk = sk_alloc(PF_INET, GFP_KERNEL, answer_prot, 1);
5250 -       if (sk == NULL)
5251 -               goto out;
5252 -
5253 -       err = 0;
5254 -       sk->sk_no_check = answer_no_check;
5255 -       if (INET_PROTOSW_REUSE & answer_flags)
5256 -               sk->sk_reuse = 1;
5257 -
5258 -       inet = inet_sk(sk);
5259 -       inet->is_icsk = (INET_PROTOSW_ICSK & answer_flags) != 0;
5260 -
5261 -       if (SOCK_RAW == sock->type) {
5262 -               inet->num = protocol;
5263 -               if (IPPROTO_RAW == protocol)
5264 -                       inet->hdrincl = 1;
5265 -       }
5266 -
5267 -       if (ipv4_config.no_pmtu_disc)
5268 -               inet->pmtudisc = IP_PMTUDISC_DONT;
5269 -       else
5270 -               inet->pmtudisc = IP_PMTUDISC_WANT;
5271 -
5272 -       inet->id = 0;
5273 -
5274 -       sock_init_data(sock, sk);
5275 -
5276 -       sk->sk_destruct    = inet_sock_destruct;
5277 -       sk->sk_family      = PF_INET;
5278 -       sk->sk_protocol    = protocol;
5279 -       sk->sk_backlog_rcv = sk->sk_prot->backlog_rcv;
5280 -
5281 -       inet->uc_ttl    = -1;
5282 -       inet->mc_loop   = 1;
5283 -       inet->mc_ttl    = 1;
5284 -       inet->mc_index  = 0;
5285 -       inet->mc_list   = NULL;
5286 -
5287 -       sk_refcnt_debug_inc(sk);
5288 -
5289 -       if (inet->num) {
5290 -               /* It assumes that any protocol which allows
5291 -                * the user to assign a number at socket
5292 -                * creation time automatically
5293 -                * shares.
5294 -                */
5295 -               inet->sport = htons(inet->num);
5296 -               /* Add to protocol hash chains. */
5297 -               sk->sk_prot->hash(sk);
5298 -       }
5299 -
5300 -       if (sk->sk_prot->init) {
5301 -               err = sk->sk_prot->init(sk);
5302 -               if (err)
5303 -                       sk_common_release(sk);
5304 -       }
5305 -out:
5306 -       return err;
5307 -out_rcu_unlock:
5308 -       rcu_read_unlock();
5309 -       goto out;
5310 -}
5311 -
5312 -
5313 -/*
5314 - *     The peer socket should always be NULL (or else). When we call this
5315 - *     function we are destroying the object and from then on nobody
5316 - *     should refer to it.
5317 - */
5318 -int inet_release(struct socket *sock)
5319 -{
5320 -       struct sock *sk = sock->sk;
5321 -
5322 -       if (sk) {
5323 -               long timeout;
5324 -
5325 -               /* Applications forget to leave groups before exiting */
5326 -               ip_mc_drop_socket(sk);
5327 -
5328 -               /* If linger is set, we don't return until the close
5329 -                * is complete.  Otherwise we return immediately. The
5330 -                * actually closing is done the same either way.
5331 -                *
5332 -                * If the close is due to the process exiting, we never
5333 -                * linger..
5334 -                */
5335 -               timeout = 0;
5336 -               if (sock_flag(sk, SOCK_LINGER) &&
5337 -                   !(current->flags & PF_EXITING))
5338 -                       timeout = sk->sk_lingertime;
5339 -               sock->sk = NULL;
5340 -               sk->sk_prot->close(sk, timeout);
5341 -       }
5342 -       return 0;
5343 -}
5344 -
5345 -/* It is off by default, see below. */
5346 -int sysctl_ip_nonlocal_bind __read_mostly;
5347 -
5348 -int inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
5349 -{
5350 -       struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
5351 -       struct sock *sk = sock->sk;
5352 -       struct inet_sock *inet = inet_sk(sk);
5353 -       struct nx_v4_sock_addr nsa;
5354 -       unsigned short snum;
5355 -       int chk_addr_ret;
5356 -       int err;
5357 -
5358 -       /* If the socket has its own bind function then use it. (RAW) */
5359 -       if (sk->sk_prot->bind) {
5360 -               err = sk->sk_prot->bind(sk, uaddr, addr_len);
5361 -               goto out;
5362 -       }
5363 -       err = -EINVAL;
5364 -       if (addr_len < sizeof(struct sockaddr_in))
5365 -               goto out;
5366 -
5367 -       err = v4_map_sock_addr(inet, addr, &nsa);
5368 -       if (err)
5369 -               goto out;
5370 -
5371 -       chk_addr_ret = inet_addr_type(nsa.saddr);
5372 -
5373 -       /* Not specified by any standard per-se, however it breaks too
5374 -        * many applications when removed.  It is unfortunate since
5375 -        * allowing applications to make a non-local bind solves
5376 -        * several problems with systems using dynamic addressing.
5377 -        * (ie. your servers still start up even if your ISDN link
5378 -        *  is temporarily down)
5379 -        */
5380 -       err = -EADDRNOTAVAIL;
5381 -       if (!sysctl_ip_nonlocal_bind &&
5382 -           !inet->freebind &&
5383 -           nsa.saddr != INADDR_ANY &&
5384 -           chk_addr_ret != RTN_LOCAL &&
5385 -           chk_addr_ret != RTN_MULTICAST &&
5386 -           chk_addr_ret != RTN_BROADCAST)
5387 -               goto out;
5388 -
5389 -       snum = ntohs(addr->sin_port);
5390 -       err = -EACCES;
5391 -       if (snum && snum < PROT_SOCK && !capable(CAP_NET_BIND_SERVICE))
5392 -               goto out;
5393 -
5394 -       /*      We keep a pair of addresses. rcv_saddr is the one
5395 -        *      used by hash lookups, and saddr is used for transmit.
5396 -        *
5397 -        *      In the BSD API these are the same except where it
5398 -        *      would be illegal to use them (multicast/broadcast) in
5399 -        *      which case the sending device address is used.
5400 -        */
5401 -       lock_sock(sk);
5402 -
5403 -       /* Check these errors (active socket, double bind). */
5404 -       err = -EINVAL;
5405 -       if (sk->sk_state != TCP_CLOSE || inet->num)
5406 -               goto out_release_sock;
5407 -
5408 -       v4_set_sock_addr(inet, &nsa);
5409 -       if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
5410 -               inet->saddr = 0;  /* Use device */
5411 -
5412 -       /* Make sure we are allowed to bind here. */
5413 -       if (sk->sk_prot->get_port(sk, snum)) {
5414 -               inet->saddr = inet->rcv_saddr = 0;
5415 -               err = -EADDRINUSE;
5416 -               goto out_release_sock;
5417 -       }
5418 -
5419 -       if (inet->rcv_saddr)
5420 -               sk->sk_userlocks |= SOCK_BINDADDR_LOCK;
5421 -       if (snum)
5422 -               sk->sk_userlocks |= SOCK_BINDPORT_LOCK;
5423 -       inet->sport = htons(inet->num);
5424 -       inet->daddr = 0;
5425 -       inet->dport = 0;
5426 -       sk_dst_reset(sk);
5427 -       err = 0;
5428 -out_release_sock:
5429 -       release_sock(sk);
5430 -out:
5431 -       return err;
5432 -}
5433 -
5434 -int inet_dgram_connect(struct socket *sock, struct sockaddr * uaddr,
5435 -                      int addr_len, int flags)
5436 -{
5437 -       struct sock *sk = sock->sk;
5438 -
5439 -       if (uaddr->sa_family == AF_UNSPEC)
5440 -               return sk->sk_prot->disconnect(sk, flags);
5441 -
5442 -       if (!inet_sk(sk)->num && inet_autobind(sk))
5443 -               return -EAGAIN;
5444 -       return sk->sk_prot->connect(sk, (struct sockaddr *)uaddr, addr_len);
5445 -}
5446 -
5447 -static long inet_wait_for_connect(struct sock *sk, long timeo)
5448 -{
5449 -       DEFINE_WAIT(wait);
5450 -
5451 -       prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
5452 -
5453 -       /* Basic assumption: if someone sets sk->sk_err, he _must_
5454 -        * change state of the socket from TCP_SYN_*.
5455 -        * Connect() does not allow to get error notifications
5456 -        * without closing the socket.
5457 -        */
5458 -       while ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) {
5459 -               release_sock(sk);
5460 -               timeo = schedule_timeout(timeo);
5461 -               lock_sock(sk);
5462 -               if (signal_pending(current) || !timeo)
5463 -                       break;
5464 -               prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
5465 -       }
5466 -       finish_wait(sk->sk_sleep, &wait);
5467 -       return timeo;
5468 -}
5469 -
5470 -/*
5471 - *     Connect to a remote host. There is regrettably still a little
5472 - *     TCP 'magic' in here.
5473 - */
5474 -int inet_stream_connect(struct socket *sock, struct sockaddr *uaddr,
5475 -                       int addr_len, int flags)
5476 -{
5477 -       struct sock *sk = sock->sk;
5478 -       int err;
5479 -       long timeo;
5480 -
5481 -       lock_sock(sk);
5482 -
5483 -       if (uaddr->sa_family == AF_UNSPEC) {
5484 -               err = sk->sk_prot->disconnect(sk, flags);
5485 -               sock->state = err ? SS_DISCONNECTING : SS_UNCONNECTED;
5486 -               goto out;
5487 -       }
5488 -
5489 -       switch (sock->state) {
5490 -       default:
5491 -               err = -EINVAL;
5492 -               goto out;
5493 -       case SS_CONNECTED:
5494 -               err = -EISCONN;
5495 -               goto out;
5496 -       case SS_CONNECTING:
5497 -               err = -EALREADY;
5498 -               /* Fall out of switch with err, set for this state */
5499 -               break;
5500 -       case SS_UNCONNECTED:
5501 -               err = -EISCONN;
5502 -               if (sk->sk_state != TCP_CLOSE)
5503 -                       goto out;
5504 -
5505 -               err = sk->sk_prot->connect(sk, uaddr, addr_len);
5506 -               if (err < 0)
5507 -                       goto out;
5508 -
5509 -               sock->state = SS_CONNECTING;
5510 -
5511 -               /* Just entered SS_CONNECTING state; the only
5512 -                * difference is that return value in non-blocking
5513 -                * case is EINPROGRESS, rather than EALREADY.
5514 -                */
5515 -               err = -EINPROGRESS;
5516 -               break;
5517 -       }
5518 -
5519 -       timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
5520 -
5521 -       if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) {
5522 -               /* Error code is set above */
5523 -               if (!timeo || !inet_wait_for_connect(sk, timeo))
5524 -                       goto out;
5525 -
5526 -               err = sock_intr_errno(timeo);
5527 -               if (signal_pending(current))
5528 -                       goto out;
5529 -       }
5530 -
5531 -       /* Connection was closed by RST, timeout, ICMP error
5532 -        * or another process disconnected us.
5533 -        */
5534 -       if (sk->sk_state == TCP_CLOSE)
5535 -               goto sock_error;
5536 -
5537 -       /* sk->sk_err may be not zero now, if RECVERR was ordered by user
5538 -        * and error was received after socket entered established state.
5539 -        * Hence, it is handled normally after connect() return successfully.
5540 -        */
5541 -
5542 -       sock->state = SS_CONNECTED;
5543 -       err = 0;
5544 -out:
5545 -       release_sock(sk);
5546 -       return err;
5547 -
5548 -sock_error:
5549 -       err = sock_error(sk) ? : -ECONNABORTED;
5550 -       sock->state = SS_UNCONNECTED;
5551 -       if (sk->sk_prot->disconnect(sk, flags))
5552 -               sock->state = SS_DISCONNECTING;
5553 -       goto out;
5554 -}
5555 -
5556 -/*
5557 - *     Accept a pending connection. The TCP layer now gives BSD semantics.
5558 - */
5559 -
5560 -int inet_accept(struct socket *sock, struct socket *newsock, int flags)
5561 -{
5562 -       struct sock *sk1 = sock->sk;
5563 -       int err = -EINVAL;
5564 -       struct sock *sk2 = sk1->sk_prot->accept(sk1, flags, &err);
5565 -
5566 -       if (!sk2)
5567 -               goto do_err;
5568 -
5569 -       lock_sock(sk2);
5570 -
5571 -       BUG_TRAP((1 << sk2->sk_state) &
5572 -                (TCPF_ESTABLISHED | TCPF_CLOSE_WAIT | TCPF_CLOSE));
5573 -
5574 -       sock_graft(sk2, newsock);
5575 -
5576 -       newsock->state = SS_CONNECTED;
5577 -       err = 0;
5578 -       release_sock(sk2);
5579 -do_err:
5580 -       return err;
5581 -}
5582 -
5583 -
5584 -/*
5585 - *     This does both peername and sockname.
5586 - */
5587 -int inet_getname(struct socket *sock, struct sockaddr *uaddr,
5588 -                       int *uaddr_len, int peer)
5589 -{
5590 -       struct sock *sk         = sock->sk;
5591 -       struct inet_sock *inet  = inet_sk(sk);
5592 -       struct sockaddr_in *sin = (struct sockaddr_in *)uaddr;
5593 -
5594 -       sin->sin_family = AF_INET;
5595 -       if (peer) {
5596 -               if (!inet->dport ||
5597 -                   (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_SYN_SENT)) &&
5598 -                    peer == 1))
5599 -                       return -ENOTCONN;
5600 -               sin->sin_port = inet->dport;
5601 -               sin->sin_addr.s_addr =
5602 -                       nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
5603 -       } else {
5604 -               __be32 addr = inet->rcv_saddr;
5605 -               if (!addr)
5606 -                       addr = inet->saddr;
5607 -               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
5608 -               sin->sin_port = inet->sport;
5609 -               sin->sin_addr.s_addr = addr;
5610 -       }
5611 -       memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
5612 -       *uaddr_len = sizeof(*sin);
5613 -       return 0;
5614 -}
5615 -
5616 -int inet_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
5617 -                size_t size)
5618 -{
5619 -       struct sock *sk = sock->sk;
5620 -
5621 -       /* We may need to bind the socket. */
5622 -       if (!inet_sk(sk)->num && inet_autobind(sk))
5623 -               return -EAGAIN;
5624 -
5625 -       return sk->sk_prot->sendmsg(iocb, sk, msg, size);
5626 -}
5627 -
5628 -
5629 -static ssize_t inet_sendpage(struct socket *sock, struct page *page, int offset, size_t size, int flags)
5630 -{
5631 -       struct sock *sk = sock->sk;
5632 -
5633 -       /* We may need to bind the socket. */
5634 -       if (!inet_sk(sk)->num && inet_autobind(sk))
5635 -               return -EAGAIN;
5636 -
5637 -       if (sk->sk_prot->sendpage)
5638 -               return sk->sk_prot->sendpage(sk, page, offset, size, flags);
5639 -       return sock_no_sendpage(sock, page, offset, size, flags);
5640 -}
5641 -
5642 -
5643 -int inet_shutdown(struct socket *sock, int how)
5644 -{
5645 -       struct sock *sk = sock->sk;
5646 -       int err = 0;
5647 -
5648 -       /* This should really check to make sure
5649 -        * the socket is a TCP socket. (WHY AC...)
5650 -        */
5651 -       how++; /* maps 0->1 has the advantage of making bit 1 rcvs and
5652 -                      1->2 bit 2 snds.
5653 -                      2->3 */
5654 -       if ((how & ~SHUTDOWN_MASK) || !how)     /* MAXINT->0 */
5655 -               return -EINVAL;
5656 -
5657 -       lock_sock(sk);
5658 -       if (sock->state == SS_CONNECTING) {
5659 -               if ((1 << sk->sk_state) &
5660 -                   (TCPF_SYN_SENT | TCPF_SYN_RECV | TCPF_CLOSE))
5661 -                       sock->state = SS_DISCONNECTING;
5662 -               else
5663 -                       sock->state = SS_CONNECTED;
5664 -       }
5665 -
5666 -       switch (sk->sk_state) {
5667 -       case TCP_CLOSE:
5668 -               err = -ENOTCONN;
5669 -               /* Hack to wake up other listeners, who can poll for
5670 -                  POLLHUP, even on eg. unconnected UDP sockets -- RR */
5671 -       default:
5672 -               sk->sk_shutdown |= how;
5673 -               if (sk->sk_prot->shutdown)
5674 -                       sk->sk_prot->shutdown(sk, how);
5675 -               break;
5676 -
5677 -       /* Remaining two branches are temporary solution for missing
5678 -        * close() in multithreaded environment. It is _not_ a good idea,
5679 -        * but we have no choice until close() is repaired at VFS level.
5680 -        */
5681 -       case TCP_LISTEN:
5682 -               if (!(how & RCV_SHUTDOWN))
5683 -                       break;
5684 -               /* Fall through */
5685 -       case TCP_SYN_SENT:
5686 -               err = sk->sk_prot->disconnect(sk, O_NONBLOCK);
5687 -               sock->state = err ? SS_DISCONNECTING : SS_UNCONNECTED;
5688 -               break;
5689 -       }
5690 -
5691 -       /* Wake up anyone sleeping in poll. */
5692 -       sk->sk_state_change(sk);
5693 -       release_sock(sk);
5694 -       return err;
5695 -}
5696 -
5697 -/*
5698 - *     ioctl() calls you can issue on an INET socket. Most of these are
5699 - *     device configuration and stuff and very rarely used. Some ioctls
5700 - *     pass on to the socket itself.
5701 - *
5702 - *     NOTE: I like the idea of a module for the config stuff. ie ifconfig
5703 - *     loads the devconfigure module does its configuring and unloads it.
5704 - *     There's a good 20K of config code hanging around the kernel.
5705 - */
5706 -
5707 -int inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
5708 -{
5709 -       struct sock *sk = sock->sk;
5710 -       int err = 0;
5711 -
5712 -       switch (cmd) {
5713 -               case SIOCGSTAMP:
5714 -                       err = sock_get_timestamp(sk, (struct timeval __user *)arg);
5715 -                       break;
5716 -               case SIOCGSTAMPNS:
5717 -                       err = sock_get_timestampns(sk, (struct timespec __user *)arg);
5718 -                       break;
5719 -               case SIOCADDRT:
5720 -               case SIOCDELRT:
5721 -               case SIOCRTMSG:
5722 -                       err = ip_rt_ioctl(cmd, (void __user *)arg);
5723 -                       break;
5724 -               case SIOCDARP:
5725 -               case SIOCGARP:
5726 -               case SIOCSARP:
5727 -                       err = arp_ioctl(cmd, (void __user *)arg);
5728 -                       break;
5729 -               case SIOCGIFADDR:
5730 -               case SIOCSIFADDR:
5731 -               case SIOCGIFBRDADDR:
5732 -               case SIOCSIFBRDADDR:
5733 -               case SIOCGIFNETMASK:
5734 -               case SIOCSIFNETMASK:
5735 -               case SIOCGIFDSTADDR:
5736 -               case SIOCSIFDSTADDR:
5737 -               case SIOCSIFPFLAGS:
5738 -               case SIOCGIFPFLAGS:
5739 -               case SIOCSIFFLAGS:
5740 -                       err = devinet_ioctl(cmd, (void __user *)arg);
5741 -                       break;
5742 -               default:
5743 -                       if (sk->sk_prot->ioctl)
5744 -                               err = sk->sk_prot->ioctl(sk, cmd, arg);
5745 -                       else
5746 -                               err = -ENOIOCTLCMD;
5747 -                       break;
5748 -       }
5749 -       return err;
5750 -}
5751 -
5752 -const struct proto_ops inet_stream_ops = {
5753 -       .family            = PF_INET,
5754 -       .owner             = THIS_MODULE,
5755 -       .release           = inet_release,
5756 -       .bind              = inet_bind,
5757 -       .connect           = inet_stream_connect,
5758 -       .socketpair        = sock_no_socketpair,
5759 -       .accept            = inet_accept,
5760 -       .getname           = inet_getname,
5761 -       .poll              = tcp_poll,
5762 -       .ioctl             = inet_ioctl,
5763 -       .listen            = inet_listen,
5764 -       .shutdown          = inet_shutdown,
5765 -       .setsockopt        = sock_common_setsockopt,
5766 -       .getsockopt        = sock_common_getsockopt,
5767 -       .sendmsg           = tcp_sendmsg,
5768 -       .recvmsg           = sock_common_recvmsg,
5769 -       .mmap              = sock_no_mmap,
5770 -       .sendpage          = tcp_sendpage,
5771 -#ifdef CONFIG_COMPAT
5772 -       .compat_setsockopt = compat_sock_common_setsockopt,
5773 -       .compat_getsockopt = compat_sock_common_getsockopt,
5774 -#endif
5775 -};
5776 -
5777 -const struct proto_ops inet_dgram_ops = {
5778 -       .family            = PF_INET,
5779 -       .owner             = THIS_MODULE,
5780 -       .release           = inet_release,
5781 -       .bind              = inet_bind,
5782 -       .connect           = inet_dgram_connect,
5783 -       .socketpair        = sock_no_socketpair,
5784 -       .accept            = sock_no_accept,
5785 -       .getname           = inet_getname,
5786 -       .poll              = udp_poll,
5787 -       .ioctl             = inet_ioctl,
5788 -       .listen            = sock_no_listen,
5789 -       .shutdown          = inet_shutdown,
5790 -       .setsockopt        = sock_common_setsockopt,
5791 -       .getsockopt        = sock_common_getsockopt,
5792 -       .sendmsg           = inet_sendmsg,
5793 -       .recvmsg           = sock_common_recvmsg,
5794 -       .mmap              = sock_no_mmap,
5795 -       .sendpage          = inet_sendpage,
5796 -#ifdef CONFIG_COMPAT
5797 -       .compat_setsockopt = compat_sock_common_setsockopt,
5798 -       .compat_getsockopt = compat_sock_common_getsockopt,
5799 -#endif
5800 -};
5801 -
5802 -/*
5803 - * For SOCK_RAW sockets; should be the same as inet_dgram_ops but without
5804 - * udp_poll
5805 - */
5806 -static const struct proto_ops inet_sockraw_ops = {
5807 -       .family            = PF_INET,
5808 -       .owner             = THIS_MODULE,
5809 -       .release           = inet_release,
5810 -       .bind              = inet_bind,
5811 -       .connect           = inet_dgram_connect,
5812 -       .socketpair        = sock_no_socketpair,
5813 -       .accept            = sock_no_accept,
5814 -       .getname           = inet_getname,
5815 -       .poll              = datagram_poll,
5816 -       .ioctl             = inet_ioctl,
5817 -       .listen            = sock_no_listen,
5818 -       .shutdown          = inet_shutdown,
5819 -       .setsockopt        = sock_common_setsockopt,
5820 -       .getsockopt        = sock_common_getsockopt,
5821 -       .sendmsg           = inet_sendmsg,
5822 -       .recvmsg           = sock_common_recvmsg,
5823 -       .mmap              = sock_no_mmap,
5824 -       .sendpage          = inet_sendpage,
5825 -#ifdef CONFIG_COMPAT
5826 -       .compat_setsockopt = compat_sock_common_setsockopt,
5827 -       .compat_getsockopt = compat_sock_common_getsockopt,
5828 -#endif
5829 -};
5830 -
5831 -static struct net_proto_family inet_family_ops = {
5832 -       .family = PF_INET,
5833 -       .create = inet_create,
5834 -       .owner  = THIS_MODULE,
5835 -};
5836 -
5837 -/* Upon startup we insert all the elements in inetsw_array[] into
5838 - * the linked list inetsw.
5839 - */
5840 -static struct inet_protosw inetsw_array[] =
5841 -{
5842 -       {
5843 -               .type =       SOCK_STREAM,
5844 -               .protocol =   IPPROTO_TCP,
5845 -               .prot =       &tcp_prot,
5846 -               .ops =        &inet_stream_ops,
5847 -               .capability = -1,
5848 -               .no_check =   0,
5849 -               .flags =      INET_PROTOSW_PERMANENT |
5850 -                             INET_PROTOSW_ICSK,
5851 -       },
5852 -
5853 -       {
5854 -               .type =       SOCK_DGRAM,
5855 -               .protocol =   IPPROTO_UDP,
5856 -               .prot =       &udp_prot,
5857 -               .ops =        &inet_dgram_ops,
5858 -               .capability = -1,
5859 -               .no_check =   UDP_CSUM_DEFAULT,
5860 -               .flags =      INET_PROTOSW_PERMANENT,
5861 -       },
5862 -
5863 -
5864 -       {
5865 -              .type =       SOCK_RAW,
5866 -              .protocol =   IPPROTO_IP,        /* wild card */
5867 -              .prot =       &raw_prot,
5868 -              .ops =        &inet_sockraw_ops,
5869 -              .capability = CAP_NET_RAW,
5870 -              .no_check =   UDP_CSUM_DEFAULT,
5871 -              .flags =      INET_PROTOSW_REUSE,
5872 -       }
5873 -};
5874 -
5875 -#define INETSW_ARRAY_LEN (sizeof(inetsw_array) / sizeof(struct inet_protosw))
5876 -
5877 -void inet_register_protosw(struct inet_protosw *p)
5878 -{
5879 -       struct list_head *lh;
5880 -       struct inet_protosw *answer;
5881 -       int protocol = p->protocol;
5882 -       struct list_head *last_perm;
5883 -
5884 -       spin_lock_bh(&inetsw_lock);
5885 -
5886 -       if (p->type >= SOCK_MAX)
5887 -               goto out_illegal;
5888 -
5889 -       /* If we are trying to override a permanent protocol, bail. */
5890 -       answer = NULL;
5891 -       last_perm = &inetsw[p->type];
5892 -       list_for_each(lh, &inetsw[p->type]) {
5893 -               answer = list_entry(lh, struct inet_protosw, list);
5894 -
5895 -               /* Check only the non-wild match. */
5896 -               if (INET_PROTOSW_PERMANENT & answer->flags) {
5897 -                       if (protocol == answer->protocol)
5898 -                               break;
5899 -                       last_perm = lh;
5900 -               }
5901 -
5902 -               answer = NULL;
5903 -       }
5904 -       if (answer)
5905 -               goto out_permanent;
5906 -
5907 -       /* Add the new entry after the last permanent entry if any, so that
5908 -        * the new entry does not override a permanent entry when matched with
5909 -        * a wild-card protocol. But it is allowed to override any existing
5910 -        * non-permanent entry.  This means that when we remove this entry, the
5911 -        * system automatically returns to the old behavior.
5912 -        */
5913 -       list_add_rcu(&p->list, last_perm);
5914 -out:
5915 -       spin_unlock_bh(&inetsw_lock);
5916 -
5917 -       synchronize_net();
5918 -
5919 -       return;
5920 -
5921 -out_permanent:
5922 -       printk(KERN_ERR "Attempt to override permanent protocol %d.\n",
5923 -              protocol);
5924 -       goto out;
5925 -
5926 -out_illegal:
5927 -       printk(KERN_ERR
5928 -              "Ignoring attempt to register invalid socket type %d.\n",
5929 -              p->type);
5930 -       goto out;
5931 -}
5932 -
5933 -void inet_unregister_protosw(struct inet_protosw *p)
5934 -{
5935 -       if (INET_PROTOSW_PERMANENT & p->flags) {
5936 -               printk(KERN_ERR
5937 -                      "Attempt to unregister permanent protocol %d.\n",
5938 -                      p->protocol);
5939 -       } else {
5940 -               spin_lock_bh(&inetsw_lock);
5941 -               list_del_rcu(&p->list);
5942 -               spin_unlock_bh(&inetsw_lock);
5943 -
5944 -               synchronize_net();
5945 -       }
5946 -}
5947 -
5948 -/*
5949 - *      Shall we try to damage output packets if routing dev changes?
5950 - */
5951 -
5952 -int sysctl_ip_dynaddr __read_mostly;
5953 -
5954 -static int inet_sk_reselect_saddr(struct sock *sk)
5955 -{
5956 -       struct inet_sock *inet = inet_sk(sk);
5957 -       int err;
5958 -       struct rtable *rt;
5959 -       __be32 old_saddr = inet->saddr;
5960 -       __be32 new_saddr;
5961 -       __be32 daddr = inet->daddr;
5962 -
5963 -       if (inet->opt && inet->opt->srr)
5964 -               daddr = inet->opt->faddr;
5965 -
5966 -       /* Query new route. */
5967 -       err = ip_route_connect(&rt, daddr, 0,
5968 -                              RT_CONN_FLAGS(sk),
5969 -                              sk->sk_bound_dev_if,
5970 -                              sk->sk_protocol,
5971 -                              inet->sport, inet->dport, sk, 0);
5972 -       if (err)
5973 -               return err;
5974 -
5975 -       sk_setup_caps(sk, &rt->u.dst);
5976 -
5977 -       new_saddr = rt->rt_src;
5978 -
5979 -       if (new_saddr == old_saddr)
5980 -               return 0;
5981 -
5982 -       if (sysctl_ip_dynaddr > 1) {
5983 -               printk(KERN_INFO "%s(): shifting inet->"
5984 -                                "saddr from %d.%d.%d.%d to %d.%d.%d.%d\n",
5985 -                      __FUNCTION__,
5986 -                      NIPQUAD(old_saddr),
5987 -                      NIPQUAD(new_saddr));
5988 -       }
5989 -
5990 -       inet->saddr = inet->rcv_saddr = new_saddr;
5991 -
5992 -       /*
5993 -        * XXX The only one ugly spot where we need to
5994 -        * XXX really change the sockets identity after
5995 -        * XXX it has entered the hashes. -DaveM
5996 -        *
5997 -        * Besides that, it does not check for connection
5998 -        * uniqueness. Wait for troubles.
5999 -        */
6000 -       __sk_prot_rehash(sk);
6001 -       return 0;
6002 -}
6003 -
6004 -int inet_sk_rebuild_header(struct sock *sk)
6005 -{
6006 -       struct inet_sock *inet = inet_sk(sk);
6007 -       struct rtable *rt = (struct rtable *)__sk_dst_check(sk, 0);
6008 -       __be32 daddr;
6009 -       int err;
6010 -
6011 -       /* Route is OK, nothing to do. */
6012 -       if (rt)
6013 -               return 0;
6014 -
6015 -       /* Reroute. */
6016 -       daddr = inet->daddr;
6017 -       if (inet->opt && inet->opt->srr)
6018 -               daddr = inet->opt->faddr;
6019 -{
6020 -       struct flowi fl = {
6021 -               .oif = sk->sk_bound_dev_if,
6022 -               .nl_u = {
6023 -                       .ip4_u = {
6024 -                               .daddr  = daddr,
6025 -                               .saddr  = inet->saddr,
6026 -                               .tos    = RT_CONN_FLAGS(sk),
6027 -                       },
6028 -               },
6029 -               .proto = sk->sk_protocol,
6030 -               .uli_u = {
6031 -                       .ports = {
6032 -                               .sport = inet->sport,
6033 -                               .dport = inet->dport,
6034 -                       },
6035 -               },
6036 -       };
6037 -
6038 -       security_sk_classify_flow(sk, &fl);
6039 -       err = ip_route_output_flow(&rt, &fl, sk, 0);
6040 -}
6041 -       if (!err)
6042 -               sk_setup_caps(sk, &rt->u.dst);
6043 -       else {
6044 -               /* Routing failed... */
6045 -               sk->sk_route_caps = 0;
6046 -               /*
6047 -                * Other protocols have to map its equivalent state to TCP_SYN_SENT.
6048 -                * DCCP maps its DCCP_REQUESTING state to TCP_SYN_SENT. -acme
6049 -                */
6050 -               if (!sysctl_ip_dynaddr ||
6051 -                   sk->sk_state != TCP_SYN_SENT ||
6052 -                   (sk->sk_userlocks & SOCK_BINDADDR_LOCK) ||
6053 -                   (err = inet_sk_reselect_saddr(sk)) != 0)
6054 -                       sk->sk_err_soft = -err;
6055 -       }
6056 -
6057 -       return err;
6058 -}
6059 -
6060 -EXPORT_SYMBOL(inet_sk_rebuild_header);
6061 -
6062 -static int inet_gso_send_check(struct sk_buff *skb)
6063 -{
6064 -       struct iphdr *iph;
6065 -       struct net_protocol *ops;
6066 -       int proto;
6067 -       int ihl;
6068 -       int err = -EINVAL;
6069 -
6070 -       if (unlikely(!pskb_may_pull(skb, sizeof(*iph))))
6071 -               goto out;
6072 -
6073 -       iph = ip_hdr(skb);
6074 -       ihl = iph->ihl * 4;
6075 -       if (ihl < sizeof(*iph))
6076 -               goto out;
6077 -
6078 -       if (unlikely(!pskb_may_pull(skb, ihl)))
6079 -               goto out;
6080 -
6081 -       __skb_pull(skb, ihl);
6082 -       skb_reset_transport_header(skb);
6083 -       iph = ip_hdr(skb);
6084 -       proto = iph->protocol & (MAX_INET_PROTOS - 1);
6085 -       err = -EPROTONOSUPPORT;
6086 -
6087 -       rcu_read_lock();
6088 -       ops = rcu_dereference(inet_protos[proto]);
6089 -       if (likely(ops && ops->gso_send_check))
6090 -               err = ops->gso_send_check(skb);
6091 -       rcu_read_unlock();
6092 -
6093 -out:
6094 -       return err;
6095 -}
6096 -
6097 -static struct sk_buff *inet_gso_segment(struct sk_buff *skb, int features)
6098 -{
6099 -       struct sk_buff *segs = ERR_PTR(-EINVAL);
6100 -       struct iphdr *iph;
6101 -       struct net_protocol *ops;
6102 -       int proto;
6103 -       int ihl;
6104 -       int id;
6105 -
6106 -       if (unlikely(skb_shinfo(skb)->gso_type &
6107 -                    ~(SKB_GSO_TCPV4 |
6108 -                      SKB_GSO_UDP |
6109 -                      SKB_GSO_DODGY |
6110 -                      SKB_GSO_TCP_ECN |
6111 -                      0)))
6112 -               goto out;
6113 -
6114 -       if (unlikely(!pskb_may_pull(skb, sizeof(*iph))))
6115 -               goto out;
6116 -
6117 -       iph = ip_hdr(skb);
6118 -       ihl = iph->ihl * 4;
6119 -       if (ihl < sizeof(*iph))
6120 -               goto out;
6121 -
6122 -       if (unlikely(!pskb_may_pull(skb, ihl)))
6123 -               goto out;
6124 -
6125 -       __skb_pull(skb, ihl);
6126 -       skb_reset_transport_header(skb);
6127 -       iph = ip_hdr(skb);
6128 -       id = ntohs(iph->id);
6129 -       proto = iph->protocol & (MAX_INET_PROTOS - 1);
6130 -       segs = ERR_PTR(-EPROTONOSUPPORT);
6131 -
6132 -       rcu_read_lock();
6133 -       ops = rcu_dereference(inet_protos[proto]);
6134 -       if (likely(ops && ops->gso_segment))
6135 -               segs = ops->gso_segment(skb, features);
6136 -       rcu_read_unlock();
6137 -
6138 -       if (!segs || unlikely(IS_ERR(segs)))
6139 -               goto out;
6140 -
6141 -       skb = segs;
6142 -       do {
6143 -               iph = ip_hdr(skb);
6144 -               iph->id = htons(id++);
6145 -               iph->tot_len = htons(skb->len - skb->mac_len);
6146 -               iph->check = 0;
6147 -               iph->check = ip_fast_csum(skb_network_header(skb), iph->ihl);
6148 -       } while ((skb = skb->next));
6149 -
6150 -out:
6151 -       return segs;
6152 -}
6153 -
6154 -unsigned long snmp_fold_field(void *mib[], int offt)
6155 -{
6156 -       unsigned long res = 0;
6157 -       int i;
6158 -
6159 -       for_each_possible_cpu(i) {
6160 -               res += *(((unsigned long *) per_cpu_ptr(mib[0], i)) + offt);
6161 -               res += *(((unsigned long *) per_cpu_ptr(mib[1], i)) + offt);
6162 -       }
6163 -       return res;
6164 -}
6165 -EXPORT_SYMBOL_GPL(snmp_fold_field);
6166 -
6167 -int snmp_mib_init(void *ptr[2], size_t mibsize, size_t mibalign)
6168 -{
6169 -       BUG_ON(ptr == NULL);
6170 -       ptr[0] = __alloc_percpu(mibsize);
6171 -       if (!ptr[0])
6172 -               goto err0;
6173 -       ptr[1] = __alloc_percpu(mibsize);
6174 -       if (!ptr[1])
6175 -               goto err1;
6176 -       return 0;
6177 -err1:
6178 -       free_percpu(ptr[0]);
6179 -       ptr[0] = NULL;
6180 -err0:
6181 -       return -ENOMEM;
6182 -}
6183 -EXPORT_SYMBOL_GPL(snmp_mib_init);
6184 -
6185 -void snmp_mib_free(void *ptr[2])
6186 -{
6187 -       BUG_ON(ptr == NULL);
6188 -       free_percpu(ptr[0]);
6189 -       free_percpu(ptr[1]);
6190 -       ptr[0] = ptr[1] = NULL;
6191 -}
6192 -EXPORT_SYMBOL_GPL(snmp_mib_free);
6193 -
6194 -#ifdef CONFIG_IP_MULTICAST
6195 -static struct net_protocol igmp_protocol = {
6196 -       .handler =      igmp_rcv,
6197 -};
6198 -#endif
6199 -
6200 -static struct net_protocol tcp_protocol = {
6201 -       .handler =      tcp_v4_rcv,
6202 -       .err_handler =  tcp_v4_err,
6203 -       .gso_send_check = tcp_v4_gso_send_check,
6204 -       .gso_segment =  tcp_tso_segment,
6205 -       .no_policy =    1,
6206 -};
6207 -
6208 -static struct net_protocol udp_protocol = {
6209 -       .handler =      udp_rcv,
6210 -       .err_handler =  udp_err,
6211 -       .no_policy =    1,
6212 -};
6213 -
6214 -static struct net_protocol icmp_protocol = {
6215 -       .handler =      icmp_rcv,
6216 -};
6217 -
6218 -static int __init init_ipv4_mibs(void)
6219 -{
6220 -       if (snmp_mib_init((void **)net_statistics,
6221 -                         sizeof(struct linux_mib),
6222 -                         __alignof__(struct linux_mib)) < 0)
6223 -               goto err_net_mib;
6224 -       if (snmp_mib_init((void **)ip_statistics,
6225 -                         sizeof(struct ipstats_mib),
6226 -                         __alignof__(struct ipstats_mib)) < 0)
6227 -               goto err_ip_mib;
6228 -       if (snmp_mib_init((void **)icmp_statistics,
6229 -                         sizeof(struct icmp_mib),
6230 -                         __alignof__(struct icmp_mib)) < 0)
6231 -               goto err_icmp_mib;
6232 -       if (snmp_mib_init((void **)tcp_statistics,
6233 -                         sizeof(struct tcp_mib),
6234 -                         __alignof__(struct tcp_mib)) < 0)
6235 -               goto err_tcp_mib;
6236 -       if (snmp_mib_init((void **)udp_statistics,
6237 -                         sizeof(struct udp_mib),
6238 -                         __alignof__(struct udp_mib)) < 0)
6239 -               goto err_udp_mib;
6240 -       if (snmp_mib_init((void **)udplite_statistics,
6241 -                         sizeof(struct udp_mib),
6242 -                         __alignof__(struct udp_mib)) < 0)
6243 -               goto err_udplite_mib;
6244 -
6245 -       tcp_mib_init();
6246 -
6247 -       return 0;
6248 -
6249 -err_udplite_mib:
6250 -       snmp_mib_free((void **)udp_statistics);
6251 -err_udp_mib:
6252 -       snmp_mib_free((void **)tcp_statistics);
6253 -err_tcp_mib:
6254 -       snmp_mib_free((void **)icmp_statistics);
6255 -err_icmp_mib:
6256 -       snmp_mib_free((void **)ip_statistics);
6257 -err_ip_mib:
6258 -       snmp_mib_free((void **)net_statistics);
6259 -err_net_mib:
6260 -       return -ENOMEM;
6261 -}
6262 -
6263 -static int ipv4_proc_init(void);
6264 -
6265 -/*
6266 - *     IP protocol layer initialiser
6267 - */
6268 -
6269 -static struct packet_type ip_packet_type = {
6270 -       .type = __constant_htons(ETH_P_IP),
6271 -       .func = ip_rcv,
6272 -       .gso_send_check = inet_gso_send_check,
6273 -       .gso_segment = inet_gso_segment,
6274 -};
6275 -
6276 -static int __init inet_init(void)
6277 -{
6278 -       struct sk_buff *dummy_skb;
6279 -       struct inet_protosw *q;
6280 -       struct list_head *r;
6281 -       int rc = -EINVAL;
6282 -
6283 -       BUILD_BUG_ON(sizeof(struct inet_skb_parm) > sizeof(dummy_skb->cb));
6284 -
6285 -       rc = proto_register(&tcp_prot, 1);
6286 -       if (rc)
6287 -               goto out;
6288 -
6289 -       rc = proto_register(&udp_prot, 1);
6290 -       if (rc)
6291 -               goto out_unregister_tcp_proto;
6292 -
6293 -       rc = proto_register(&raw_prot, 1);
6294 -       if (rc)
6295 -               goto out_unregister_udp_proto;
6296 -
6297 -       /*
6298 -        *      Tell SOCKET that we are alive...
6299 -        */
6300 -
6301 -       (void)sock_register(&inet_family_ops);
6302 -
6303 -       /*
6304 -        *      Add all the base protocols.
6305 -        */
6306 -
6307 -       if (inet_add_protocol(&icmp_protocol, IPPROTO_ICMP) < 0)
6308 -               printk(KERN_CRIT "inet_init: Cannot add ICMP protocol\n");
6309 -       if (inet_add_protocol(&udp_protocol, IPPROTO_UDP) < 0)
6310 -               printk(KERN_CRIT "inet_init: Cannot add UDP protocol\n");
6311 -       if (inet_add_protocol(&tcp_protocol, IPPROTO_TCP) < 0)
6312 -               printk(KERN_CRIT "inet_init: Cannot add TCP protocol\n");
6313 -#ifdef CONFIG_IP_MULTICAST
6314 -       if (inet_add_protocol(&igmp_protocol, IPPROTO_IGMP) < 0)
6315 -               printk(KERN_CRIT "inet_init: Cannot add IGMP protocol\n");
6316 -#endif
6317 -
6318 -       /* Register the socket-side information for inet_create. */
6319 -       for (r = &inetsw[0]; r < &inetsw[SOCK_MAX]; ++r)
6320 -               INIT_LIST_HEAD(r);
6321 -
6322 -       for (q = inetsw_array; q < &inetsw_array[INETSW_ARRAY_LEN]; ++q)
6323 -               inet_register_protosw(q);
6324 -
6325 -       /*
6326 -        *      Set the ARP module up
6327 -        */
6328 -
6329 -       arp_init();
6330 -
6331 -       /*
6332 -        *      Set the IP module up
6333 -        */
6334 -
6335 -       ip_init();
6336 -
6337 -       tcp_v4_init(&inet_family_ops);
6338 -
6339 -       /* Setup TCP slab cache for open requests. */
6340 -       tcp_init();
6341 -
6342 -       /* Add UDP-Lite (RFC 3828) */
6343 -       udplite4_register();
6344 -
6345 -       /*
6346 -        *      Set the ICMP layer up
6347 -        */
6348 -
6349 -       icmp_init(&inet_family_ops);
6350 -
6351 -       /*
6352 -        *      Initialise the multicast router
6353 -        */
6354 -#if defined(CONFIG_IP_MROUTE)
6355 -       ip_mr_init();
6356 -#endif
6357 -       /*
6358 -        *      Initialise per-cpu ipv4 mibs
6359 -        */
6360 -
6361 -       if (init_ipv4_mibs())
6362 -               printk(KERN_CRIT "inet_init: Cannot init ipv4 mibs\n"); ;
6363 -
6364 -       ipv4_proc_init();
6365 -
6366 -       ipfrag_init();
6367 -
6368 -       dev_add_pack(&ip_packet_type);
6369 -
6370 -       rc = 0;
6371 -out:
6372 -       return rc;
6373 -out_unregister_udp_proto:
6374 -       proto_unregister(&udp_prot);
6375 -out_unregister_tcp_proto:
6376 -       proto_unregister(&tcp_prot);
6377 -       goto out;
6378 -}
6379 -
6380 -fs_initcall(inet_init);
6381 -
6382 -/* ------------------------------------------------------------------------ */
6383 -
6384 -#ifdef CONFIG_PROC_FS
6385 -static int __init ipv4_proc_init(void)
6386 -{
6387 -       int rc = 0;
6388 -
6389 -       if (raw_proc_init())
6390 -               goto out_raw;
6391 -       if (tcp4_proc_init())
6392 -               goto out_tcp;
6393 -       if (udp4_proc_init())
6394 -               goto out_udp;
6395 -       if (fib_proc_init())
6396 -               goto out_fib;
6397 -       if (ip_misc_proc_init())
6398 -               goto out_misc;
6399 -out:
6400 -       return rc;
6401 -out_misc:
6402 -       fib_proc_exit();
6403 -out_fib:
6404 -       udp4_proc_exit();
6405 -out_udp:
6406 -       tcp4_proc_exit();
6407 -out_tcp:
6408 -       raw_proc_exit();
6409 -out_raw:
6410 -       rc = -ENOMEM;
6411 -       goto out;
6412 -}
6413 -
6414 -#else /* CONFIG_PROC_FS */
6415 -static int __init ipv4_proc_init(void)
6416 -{
6417 -       return 0;
6418 -}
6419 -#endif /* CONFIG_PROC_FS */
6420 -
6421 -MODULE_ALIAS_NETPROTO(PF_INET);
6422 -
6423 -EXPORT_SYMBOL(inet_accept);
6424 -EXPORT_SYMBOL(inet_bind);
6425 -EXPORT_SYMBOL(inet_dgram_connect);
6426 -EXPORT_SYMBOL(inet_dgram_ops);
6427 -EXPORT_SYMBOL(inet_getname);
6428 -EXPORT_SYMBOL(inet_ioctl);
6429 -EXPORT_SYMBOL(inet_listen);
6430 -EXPORT_SYMBOL(inet_register_protosw);
6431 -EXPORT_SYMBOL(inet_release);
6432 -EXPORT_SYMBOL(inet_sendmsg);
6433 -EXPORT_SYMBOL(inet_shutdown);
6434 -EXPORT_SYMBOL(inet_sock_destruct);
6435 -EXPORT_SYMBOL(inet_stream_connect);
6436 -EXPORT_SYMBOL(inet_stream_ops);
6437 -EXPORT_SYMBOL(inet_unregister_protosw);
6438 -EXPORT_SYMBOL(net_statistics);
6439 -EXPORT_SYMBOL(sysctl_ip_nonlocal_bind);
6440 diff -Nurb linux-2.6.22-594/net/netfilter/xt_MARK.c.orig linux-2.6.22-595/net/netfilter/xt_MARK.c.orig
6441 --- linux-2.6.22-594/net/netfilter/xt_MARK.c.orig       2008-03-20 01:27:52.000000000 -0400
6442 +++ linux-2.6.22-595/net/netfilter/xt_MARK.c.orig       1969-12-31 19:00:00.000000000 -0500
6443 @@ -1,283 +0,0 @@
6444 -/* This is a module which is used for setting the NFMARK field of an skb. */
6445 -
6446 -/* (C) 1999-2001 Marc Boucher <marc@mbsi.ca>
6447 - *
6448 - * This program is free software; you can redistribute it and/or modify
6449 - * it under the terms of the GNU General Public License version 2 as
6450 - * published by the Free Software Foundation.
6451 - *
6452 - */
6453 -
6454 -#include <linux/module.h>
6455 -#include <linux/version.h>
6456 -#include <linux/skbuff.h>
6457 -#include <linux/ip.h>
6458 -#include <net/checksum.h>
6459 -#include <net/route.h>
6460 -#include <net/inet_hashtables.h>
6461 -
6462 -#include <net/netfilter/nf_conntrack.h>
6463 -#include <linux/netfilter/x_tables.h>
6464 -#include <linux/netfilter/xt_MARK.h>
6465 -
6466 -MODULE_LICENSE("GPL");
6467 -MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
6468 -MODULE_DESCRIPTION("ip[6]tables MARK modification module");
6469 -MODULE_ALIAS("ipt_MARK");
6470 -MODULE_ALIAS("ip6t_MARK");
6471 -
6472 -static inline u_int16_t
6473 -get_dst_port(struct nf_conntrack_tuple *tuple)
6474 -{
6475 -       switch (tuple->dst.protonum) {
6476 -       case IPPROTO_GRE:
6477 -               /* XXX Truncate 32-bit GRE key to 16 bits */
6478 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11)
6479 -               return tuple->dst.u.gre.key;
6480 -#else
6481 -               return htons(ntohl(tuple->dst.u.gre.key));
6482 -#endif  
6483 -       case IPPROTO_ICMP:
6484 -               /* Bind on ICMP echo ID */
6485 -               return tuple->src.u.icmp.id;
6486 -       case IPPROTO_TCP:
6487 -               return tuple->dst.u.tcp.port;
6488 -       case IPPROTO_UDP:
6489 -               return tuple->dst.u.udp.port;
6490 -       default:
6491 -               return tuple->dst.u.all;
6492 -       }
6493 -}
6494 -
6495 -static inline u_int16_t
6496 -get_src_port(struct nf_conntrack_tuple *tuple)
6497 -{
6498 -       switch (tuple->dst.protonum) {
6499 -       case IPPROTO_GRE:
6500 -               /* XXX Truncate 32-bit GRE key to 16 bits */
6501 -               return htons(ntohl(tuple->src.u.gre.key));
6502 -       case IPPROTO_ICMP:
6503 -               /* Bind on ICMP echo ID */
6504 -               return tuple->src.u.icmp.id;
6505 -       case IPPROTO_TCP:
6506 -               return tuple->src.u.tcp.port;
6507 -       case IPPROTO_UDP:
6508 -               return tuple->src.u.udp.port;
6509 -       default:
6510 -               return tuple->src.u.all;
6511 -       }
6512 -}
6513 -
6514 -static unsigned int
6515 -target_v0(struct sk_buff **pskb,
6516 -         const struct net_device *in,
6517 -         const struct net_device *out,
6518 -         unsigned int hooknum,
6519 -         const struct xt_target *target,
6520 -         const void *targinfo)
6521 -{
6522 -       const struct xt_mark_target_info *markinfo = targinfo;
6523 -
6524 -       (*pskb)->mark = markinfo->mark;
6525 -       return XT_CONTINUE;
6526 -}
6527 -
6528 -static unsigned int
6529 -target_v1(struct sk_buff **pskb,
6530 -         const struct net_device *in,
6531 -         const struct net_device *out,
6532 -         unsigned int hooknum,
6533 -         const struct xt_target *target,
6534 -         const void *targinfo)
6535 -{
6536 -       const struct xt_mark_target_info_v1 *markinfo = targinfo;
6537 -       int mark = -1;
6538 -
6539 -       switch (markinfo->mode) {
6540 -       case XT_MARK_SET:
6541 -               mark = markinfo->mark;
6542 -               break;
6543 -
6544 -       case XT_MARK_AND:
6545 -               mark = (*pskb)->mark & markinfo->mark;
6546 -               break;
6547 -
6548 -       case XT_MARK_OR:
6549 -               mark = (*pskb)->mark | markinfo->mark;
6550 -               break;
6551 -
6552 -       case XT_MARK_COPYXID: {
6553 -               enum ip_conntrack_info ctinfo;
6554 -               struct sock *connection_sk=NULL;
6555 -               int dif;
6556 -
6557 -               struct nf_conn *ct = nf_ct_get((*pskb), &ctinfo);
6558 -               extern struct inet_hashinfo tcp_hashinfo;
6559 -               enum ip_conntrack_dir dir;
6560 -               if (!ct) 
6561 -                       break;
6562 -
6563 -               dir = CTINFO2DIR(ctinfo);
6564 -               u_int32_t src_ip = ct->tuplehash[dir].tuple.src.u3.ip;
6565 -               u_int16_t src_port = get_src_port(&ct->tuplehash[dir].tuple);
6566 -               u_int16_t proto = ct->tuplehash[dir].tuple.dst.protonum;
6567 -
6568 -               u_int32_t ip;
6569 -               u_int16_t port;
6570 -
6571 -               dif = ((struct rtable *)(*pskb)->dst)->rt_iif;
6572 -               ip = ct->tuplehash[dir].tuple.dst.u3.ip;
6573 -               port = get_dst_port(&ct->tuplehash[dir].tuple);
6574 -
6575 -               if (proto == 1 || proto == 17) {
6576 -                       if (((*pskb)->mark!=-1) && (*pskb)->mark)
6577 -                               ct->xid[0]=(*pskb)->mark;
6578 -                       if (ct->xid[0]) 
6579 -                               mark = ct->xid[0];
6580 -
6581 -               }
6582 -               else if (proto == 6) {
6583 -                               if ((*pskb)->sk) 
6584 -                                       connection_sk = (*pskb)->sk;
6585 -                               else {
6586 -                                       connection_sk = inet_lookup(&tcp_hashinfo, src_ip, src_port, ip, port, dif);
6587 -                               }
6588 -
6589 -                               if (connection_sk) {
6590 -                                       connection_sk->sk_peercred.gid = connection_sk->sk_peercred.uid = ct->xid[dir];
6591 -                                       ct->xid[!dir]=connection_sk->sk_xid;
6592 -                                       if (connection_sk->sk_xid != 0) 
6593 -                                               mark = connection_sk->sk_xid;
6594 -                                       if (connection_sk != (*pskb)->sk)
6595 -                                               sock_put(connection_sk);
6596 -                               }
6597 -                               break;
6598 -                               }
6599 -                             }
6600 -       }
6601 -
6602 -       if (mark != -1)
6603 -       (*pskb)->mark = mark;
6604 -       return XT_CONTINUE;
6605 -}
6606 -
6607 -
6608 -static int
6609 -checkentry_v0(const char *tablename,
6610 -             const void *entry,
6611 -             const struct xt_target *target,
6612 -             void *targinfo,
6613 -             unsigned int hook_mask)
6614 -{
6615 -       struct xt_mark_target_info *markinfo = targinfo;
6616 -
6617 -       if (markinfo->mark > 0xffffffff) {
6618 -               printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
6619 -               return 0;
6620 -       }
6621 -       return 1;
6622 -}
6623 -
6624 -static int
6625 -checkentry_v1(const char *tablename,
6626 -             const void *entry,
6627 -             const struct xt_target *target,
6628 -             void *targinfo,
6629 -             unsigned int hook_mask)
6630 -{
6631 -       struct xt_mark_target_info_v1 *markinfo = targinfo;
6632 -
6633 -       if (markinfo->mode != XT_MARK_SET
6634 -           && markinfo->mode != XT_MARK_AND
6635 -           && markinfo->mode != XT_MARK_OR
6636 -           && markinfo->mode != XT_MARK_COPYXID) {
6637 -               printk(KERN_WARNING "MARK: unknown mode %u\n",
6638 -                      markinfo->mode);
6639 -               return 0;
6640 -       }
6641 -       if (markinfo->mark > 0xffffffff) {
6642 -               printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
6643 -               return 0;
6644 -       }
6645 -       return 1;
6646 -}
6647 -
6648 -#ifdef CONFIG_COMPAT
6649 -struct compat_xt_mark_target_info_v1 {
6650 -       compat_ulong_t  mark;
6651 -       u_int8_t        mode;
6652 -       u_int8_t        __pad1;
6653 -       u_int16_t       __pad2;
6654 -};
6655 -
6656 -static void compat_from_user_v1(void *dst, void *src)
6657 -{
6658 -       struct compat_xt_mark_target_info_v1 *cm = src;
6659 -       struct xt_mark_target_info_v1 m = {
6660 -               .mark   = cm->mark,
6661 -               .mode   = cm->mode,
6662 -       };
6663 -       memcpy(dst, &m, sizeof(m));
6664 -}
6665 -
6666 -static int compat_to_user_v1(void __user *dst, void *src)
6667 -{
6668 -       struct xt_mark_target_info_v1 *m = src;
6669 -       struct compat_xt_mark_target_info_v1 cm = {
6670 -               .mark   = m->mark,
6671 -               .mode   = m->mode,
6672 -       };
6673 -       return copy_to_user(dst, &cm, sizeof(cm)) ? -EFAULT : 0;
6674 -}
6675 -#endif /* CONFIG_COMPAT */
6676 -
6677 -static struct xt_target xt_mark_target[] = {
6678 -       {
6679 -               .name           = "MARK",
6680 -               .family         = AF_INET,
6681 -               .revision       = 0,
6682 -               .checkentry     = checkentry_v0,
6683 -               .target         = target_v0,
6684 -               .targetsize     = sizeof(struct xt_mark_target_info),
6685 -               .table          = "mangle",
6686 -               .me             = THIS_MODULE,
6687 -       },
6688 -       {
6689 -               .name           = "MARK",
6690 -               .family         = AF_INET,
6691 -               .revision       = 1,
6692 -               .checkentry     = checkentry_v1,
6693 -               .target         = target_v1,
6694 -               .targetsize     = sizeof(struct xt_mark_target_info_v1),
6695 -#ifdef CONFIG_COMPAT
6696 -               .compatsize     = sizeof(struct compat_xt_mark_target_info_v1),
6697 -               .compat_from_user = compat_from_user_v1,
6698 -               .compat_to_user = compat_to_user_v1,
6699 -#endif
6700 -               .table          = "mangle",
6701 -               .me             = THIS_MODULE,
6702 -       },
6703 -       {
6704 -               .name           = "MARK",
6705 -               .family         = AF_INET6,
6706 -               .revision       = 0,
6707 -               .checkentry     = checkentry_v0,
6708 -               .target         = target_v0,
6709 -               .targetsize     = sizeof(struct xt_mark_target_info),
6710 -               .table          = "mangle",
6711 -               .me             = THIS_MODULE,
6712 -       },
6713 -};
6714 -
6715 -static int __init xt_mark_init(void)
6716 -{
6717 -       return xt_register_targets(xt_mark_target, ARRAY_SIZE(xt_mark_target));
6718 -}
6719 -
6720 -static void __exit xt_mark_fini(void)
6721 -{
6722 -       xt_unregister_targets(xt_mark_target, ARRAY_SIZE(xt_mark_target));
6723 -}
6724 -
6725 -module_init(xt_mark_init);
6726 -module_exit(xt_mark_fini);
6727 diff -Nurb linux-2.6.22-594/net/packet/af_packet.c.orig linux-2.6.22-595/net/packet/af_packet.c.orig
6728 --- linux-2.6.22-594/net/packet/af_packet.c.orig        2008-03-20 01:27:52.000000000 -0400
6729 +++ linux-2.6.22-595/net/packet/af_packet.c.orig        1969-12-31 19:00:00.000000000 -0500
6730 @@ -1,1989 +0,0 @@
6731 -/*
6732 - * INET                An implementation of the TCP/IP protocol suite for the LINUX
6733 - *             operating system.  INET is implemented using the  BSD Socket
6734 - *             interface as the means of communication with the user level.
6735 - *
6736 - *             PACKET - implements raw packet sockets.
6737 - *
6738 - * Version:    $Id: af_packet.c,v 1.61 2002/02/08 03:57:19 davem Exp $
6739 - *
6740 - * Authors:    Ross Biro
6741 - *             Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
6742 - *             Alan Cox, <gw4pts@gw4pts.ampr.org>
6743 - *
6744 - * Fixes:
6745 - *             Alan Cox        :       verify_area() now used correctly
6746 - *             Alan Cox        :       new skbuff lists, look ma no backlogs!
6747 - *             Alan Cox        :       tidied skbuff lists.
6748 - *             Alan Cox        :       Now uses generic datagram routines I
6749 - *                                     added. Also fixed the peek/read crash
6750 - *                                     from all old Linux datagram code.
6751 - *             Alan Cox        :       Uses the improved datagram code.
6752 - *             Alan Cox        :       Added NULL's for socket options.
6753 - *             Alan Cox        :       Re-commented the code.
6754 - *             Alan Cox        :       Use new kernel side addressing
6755 - *             Rob Janssen     :       Correct MTU usage.
6756 - *             Dave Platt      :       Counter leaks caused by incorrect
6757 - *                                     interrupt locking and some slightly
6758 - *                                     dubious gcc output. Can you read
6759 - *                                     compiler: it said _VOLATILE_
6760 - *     Richard Kooijman        :       Timestamp fixes.
6761 - *             Alan Cox        :       New buffers. Use sk->mac.raw.
6762 - *             Alan Cox        :       sendmsg/recvmsg support.
6763 - *             Alan Cox        :       Protocol setting support
6764 - *     Alexey Kuznetsov        :       Untied from IPv4 stack.
6765 - *     Cyrus Durgin            :       Fixed kerneld for kmod.
6766 - *     Michal Ostrowski        :       Module initialization cleanup.
6767 - *         Ulises Alonso        :       Frame number limit removal and
6768 - *                                      packet_set_ring memory leak.
6769 - *             Eric Biederman  :       Allow for > 8 byte hardware addresses.
6770 - *                                     The convention is that longer addresses
6771 - *                                     will simply extend the hardware address
6772 - *                                     byte arrays at the end of sockaddr_ll
6773 - *                                     and packet_mreq.
6774 - *
6775 - *             This program is free software; you can redistribute it and/or
6776 - *             modify it under the terms of the GNU General Public License
6777 - *             as published by the Free Software Foundation; either version
6778 - *             2 of the License, or (at your option) any later version.
6779 - *
6780 - */
6781 -
6782 -#include <linux/types.h>
6783 -#include <linux/mm.h>
6784 -#include <linux/capability.h>
6785 -#include <linux/fcntl.h>
6786 -#include <linux/socket.h>
6787 -#include <linux/in.h>
6788 -#include <linux/inet.h>
6789 -#include <linux/netdevice.h>
6790 -#include <linux/if_packet.h>
6791 -#include <linux/wireless.h>
6792 -#include <linux/kernel.h>
6793 -#include <linux/kmod.h>
6794 -#include <net/ip.h>
6795 -#include <net/protocol.h>
6796 -#include <linux/skbuff.h>
6797 -#include <net/sock.h>
6798 -#include <linux/errno.h>
6799 -#include <linux/timer.h>
6800 -#include <asm/system.h>
6801 -#include <asm/uaccess.h>
6802 -#include <asm/ioctls.h>
6803 -#include <asm/page.h>
6804 -#include <asm/cacheflush.h>
6805 -#include <asm/io.h>
6806 -#include <linux/proc_fs.h>
6807 -#include <linux/seq_file.h>
6808 -#include <linux/poll.h>
6809 -#include <linux/module.h>
6810 -#include <linux/init.h>
6811 -#include <linux/vs_network.h>
6812 -
6813 -#ifdef CONFIG_INET
6814 -#include <net/inet_common.h>
6815 -#endif
6816 -
6817 -/*
6818 -   Assumptions:
6819 -   - if device has no dev->hard_header routine, it adds and removes ll header
6820 -     inside itself. In this case ll header is invisible outside of device,
6821 -     but higher levels still should reserve dev->hard_header_len.
6822 -     Some devices are enough clever to reallocate skb, when header
6823 -     will not fit to reserved space (tunnel), another ones are silly
6824 -     (PPP).
6825 -   - packet socket receives packets with pulled ll header,
6826 -     so that SOCK_RAW should push it back.
6827 -
6828 -On receive:
6829 ------------
6830 -
6831 -Incoming, dev->hard_header!=NULL
6832 -   mac_header -> ll header
6833 -   data       -> data
6834 -
6835 -Outgoing, dev->hard_header!=NULL
6836 -   mac_header -> ll header
6837 -   data       -> ll header
6838 -
6839 -Incoming, dev->hard_header==NULL
6840 -   mac_header -> UNKNOWN position. It is very likely, that it points to ll
6841 -                header.  PPP makes it, that is wrong, because introduce
6842 -                 assymetry between rx and tx paths.
6843 -   data       -> data
6844 -
6845 -Outgoing, dev->hard_header==NULL
6846 -   mac_header -> data. ll header is still not built!
6847 -   data       -> data
6848 -
6849 -Resume
6850 -  If dev->hard_header==NULL we are unlikely to restore sensible ll header.
6851 -
6852 -
6853 -On transmit:
6854 -------------
6855 -
6856 -dev->hard_header != NULL
6857 -   mac_header -> ll header
6858 -   data       -> ll header
6859 -
6860 -dev->hard_header == NULL (ll header is added by device, we cannot control it)
6861 -   mac_header -> data
6862 -   data       -> data
6863 -
6864 -   We should set nh.raw on output to correct posistion,
6865 -   packet classifier depends on it.
6866 - */
6867 -
6868 -/* List of all packet sockets. */
6869 -static HLIST_HEAD(packet_sklist);
6870 -static DEFINE_RWLOCK(packet_sklist_lock);
6871 -
6872 -static atomic_t packet_socks_nr;
6873 -
6874 -
6875 -/* Private packet socket structures. */
6876 -
6877 -struct packet_mclist
6878 -{
6879 -       struct packet_mclist    *next;
6880 -       int                     ifindex;
6881 -       int                     count;
6882 -       unsigned short          type;
6883 -       unsigned short          alen;
6884 -       unsigned char           addr[MAX_ADDR_LEN];
6885 -};
6886 -/* identical to struct packet_mreq except it has
6887 - * a longer address field.
6888 - */
6889 -struct packet_mreq_max
6890 -{
6891 -       int             mr_ifindex;
6892 -       unsigned short  mr_type;
6893 -       unsigned short  mr_alen;
6894 -       unsigned char   mr_address[MAX_ADDR_LEN];
6895 -};
6896 -
6897 -#ifdef CONFIG_PACKET_MMAP
6898 -static int packet_set_ring(struct sock *sk, struct tpacket_req *req, int closing);
6899 -#endif
6900 -
6901 -static void packet_flush_mclist(struct sock *sk);
6902 -
6903 -struct packet_sock {
6904 -       /* struct sock has to be the first member of packet_sock */
6905 -       struct sock             sk;
6906 -       struct tpacket_stats    stats;
6907 -#ifdef CONFIG_PACKET_MMAP
6908 -       char *                  *pg_vec;
6909 -       unsigned int            head;
6910 -       unsigned int            frames_per_block;
6911 -       unsigned int            frame_size;
6912 -       unsigned int            frame_max;
6913 -       int                     copy_thresh;
6914 -#endif
6915 -       struct packet_type      prot_hook;
6916 -       spinlock_t              bind_lock;
6917 -       unsigned int            running:1,      /* prot_hook is attached*/
6918 -                               auxdata:1,
6919 -                               origdev:1;
6920 -       int                     ifindex;        /* bound device         */
6921 -       __be16                  num;
6922 -       struct packet_mclist    *mclist;
6923 -#ifdef CONFIG_PACKET_MMAP
6924 -       atomic_t                mapped;
6925 -       unsigned int            pg_vec_order;
6926 -       unsigned int            pg_vec_pages;
6927 -       unsigned int            pg_vec_len;
6928 -#endif
6929 -};
6930 -
6931 -struct packet_skb_cb {
6932 -       unsigned int origlen;
6933 -       union {
6934 -               struct sockaddr_pkt pkt;
6935 -               struct sockaddr_ll ll;
6936 -       } sa;
6937 -};
6938 -
6939 -#define PACKET_SKB_CB(__skb)   ((struct packet_skb_cb *)((__skb)->cb))
6940 -
6941 -#ifdef CONFIG_PACKET_MMAP
6942 -
6943 -static inline struct tpacket_hdr *packet_lookup_frame(struct packet_sock *po, unsigned int position)
6944 -{
6945 -       unsigned int pg_vec_pos, frame_offset;
6946 -
6947 -       pg_vec_pos = position / po->frames_per_block;
6948 -       frame_offset = position % po->frames_per_block;
6949 -
6950 -       return (struct tpacket_hdr *)(po->pg_vec[pg_vec_pos] + (frame_offset * po->frame_size));
6951 -}
6952 -#endif
6953 -
6954 -static inline struct packet_sock *pkt_sk(struct sock *sk)
6955 -{
6956 -       return (struct packet_sock *)sk;
6957 -}
6958 -
6959 -static void packet_sock_destruct(struct sock *sk)
6960 -{
6961 -       BUG_TRAP(!atomic_read(&sk->sk_rmem_alloc));
6962 -       BUG_TRAP(!atomic_read(&sk->sk_wmem_alloc));
6963 -
6964 -       if (!sock_flag(sk, SOCK_DEAD)) {
6965 -               printk("Attempt to release alive packet socket: %p\n", sk);
6966 -               return;
6967 -       }
6968 -
6969 -       atomic_dec(&packet_socks_nr);
6970 -#ifdef PACKET_REFCNT_DEBUG
6971 -       printk(KERN_DEBUG "PACKET socket %p is free, %d are alive\n", sk, atomic_read(&packet_socks_nr));
6972 -#endif
6973 -}
6974 -
6975 -
6976 -static const struct proto_ops packet_ops;
6977 -
6978 -static const struct proto_ops packet_ops_spkt;
6979 -
6980 -static int packet_rcv_spkt(struct sk_buff *skb, struct net_device *dev,  struct packet_type *pt, struct net_device *orig_dev)
6981 -{
6982 -       struct sock *sk;
6983 -       struct sockaddr_pkt *spkt;
6984 -
6985 -       /*
6986 -        *      When we registered the protocol we saved the socket in the data
6987 -        *      field for just this event.
6988 -        */
6989 -
6990 -       sk = pt->af_packet_priv;
6991 -
6992 -       /*
6993 -        *      Yank back the headers [hope the device set this
6994 -        *      right or kerboom...]
6995 -        *
6996 -        *      Incoming packets have ll header pulled,
6997 -        *      push it back.
6998 -        *
6999 -        *      For outgoing ones skb->data == skb_mac_header(skb)
7000 -        *      so that this procedure is noop.
7001 -        */
7002 -
7003 -       if (skb->pkt_type == PACKET_LOOPBACK)
7004 -               goto out;
7005 -
7006 -       if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)
7007 -               goto oom;
7008 -
7009 -       /* drop any routing info */
7010 -       dst_release(skb->dst);
7011 -       skb->dst = NULL;
7012 -
7013 -       /* drop conntrack reference */
7014 -       nf_reset(skb);
7015 -
7016 -       spkt = &PACKET_SKB_CB(skb)->sa.pkt;
7017 -
7018 -       skb_push(skb, skb->data - skb_mac_header(skb));
7019 -
7020 -       /*
7021 -        *      The SOCK_PACKET socket receives _all_ frames.
7022 -        */
7023 -
7024 -       spkt->spkt_family = dev->type;
7025 -       strlcpy(spkt->spkt_device, dev->name, sizeof(spkt->spkt_device));
7026 -       spkt->spkt_protocol = skb->protocol;
7027 -
7028 -       /*
7029 -        *      Charge the memory to the socket. This is done specifically
7030 -        *      to prevent sockets using all the memory up.
7031 -        */
7032 -
7033 -       if (sock_queue_rcv_skb(sk,skb) == 0)
7034 -               return 0;
7035 -
7036 -out:
7037 -       kfree_skb(skb);
7038 -oom:
7039 -       return 0;
7040 -}
7041 -
7042 -
7043 -/*
7044 - *     Output a raw packet to a device layer. This bypasses all the other
7045 - *     protocol layers and you must therefore supply it with a complete frame
7046 - */
7047 -
7048 -static int packet_sendmsg_spkt(struct kiocb *iocb, struct socket *sock,
7049 -                              struct msghdr *msg, size_t len)
7050 -{
7051 -       struct sock *sk = sock->sk;
7052 -       struct sockaddr_pkt *saddr=(struct sockaddr_pkt *)msg->msg_name;
7053 -       struct sk_buff *skb;
7054 -       struct net_device *dev;
7055 -       __be16 proto=0;
7056 -       int err;
7057 -
7058 -       if (!nx_capable(CAP_NET_RAW, NXC_RAW_SEND))
7059 -               return -EPERM;
7060 -
7061 -       /*
7062 -        *      Get and verify the address.
7063 -        */
7064 -
7065 -       if (saddr)
7066 -       {
7067 -               if (msg->msg_namelen < sizeof(struct sockaddr))
7068 -                       return(-EINVAL);
7069 -               if (msg->msg_namelen==sizeof(struct sockaddr_pkt))
7070 -                       proto=saddr->spkt_protocol;
7071 -       }
7072 -       else
7073 -               return(-ENOTCONN);      /* SOCK_PACKET must be sent giving an address */
7074 -
7075 -       /*
7076 -        *      Find the device first to size check it
7077 -        */
7078 -
7079 -       saddr->spkt_device[13] = 0;
7080 -       dev = dev_get_by_name(saddr->spkt_device);
7081 -       err = -ENODEV;
7082 -       if (dev == NULL)
7083 -               goto out_unlock;
7084 -
7085 -       err = -ENETDOWN;
7086 -       if (!(dev->flags & IFF_UP))
7087 -               goto out_unlock;
7088 -
7089 -       /*
7090 -        *      You may not queue a frame bigger than the mtu. This is the lowest level
7091 -        *      raw protocol and you must do your own fragmentation at this level.
7092 -        */
7093 -
7094 -       err = -EMSGSIZE;
7095 -       if (len > dev->mtu + dev->hard_header_len)
7096 -               goto out_unlock;
7097 -
7098 -       err = -ENOBUFS;
7099 -       skb = sock_wmalloc(sk, len + LL_RESERVED_SPACE(dev), 0, GFP_KERNEL);
7100 -
7101 -       /*
7102 -        *      If the write buffer is full, then tough. At this level the user gets to
7103 -        *      deal with the problem - do your own algorithmic backoffs. That's far
7104 -        *      more flexible.
7105 -        */
7106 -
7107 -       if (skb == NULL)
7108 -               goto out_unlock;
7109 -
7110 -       /*
7111 -        *      Fill it in
7112 -        */
7113 -
7114 -       /* FIXME: Save some space for broken drivers that write a
7115 -        * hard header at transmission time by themselves. PPP is the
7116 -        * notable one here. This should really be fixed at the driver level.
7117 -        */
7118 -       skb_reserve(skb, LL_RESERVED_SPACE(dev));
7119 -       skb_reset_network_header(skb);
7120 -
7121 -       /* Try to align data part correctly */
7122 -       if (dev->hard_header) {
7123 -               skb->data -= dev->hard_header_len;
7124 -               skb->tail -= dev->hard_header_len;
7125 -               if (len < dev->hard_header_len)
7126 -                       skb_reset_network_header(skb);
7127 -       }
7128 -
7129 -       /* Returns -EFAULT on error */
7130 -       err = memcpy_fromiovec(skb_put(skb,len), msg->msg_iov, len);
7131 -       skb->protocol = proto;
7132 -       skb->dev = dev;
7133 -       skb->priority = sk->sk_priority;
7134 -       if (err)
7135 -               goto out_free;
7136 -
7137 -       /*
7138 -        *      Now send it
7139 -        */
7140 -
7141 -       dev_queue_xmit(skb);
7142 -       dev_put(dev);
7143 -       return(len);
7144 -
7145 -out_free:
7146 -       kfree_skb(skb);
7147 -out_unlock:
7148 -       if (dev)
7149 -               dev_put(dev);
7150 -       return err;
7151 -}
7152 -
7153 -static inline unsigned int run_filter(struct sk_buff *skb, struct sock *sk,
7154 -                                     unsigned int res)
7155 -{
7156 -       struct sk_filter *filter;
7157 -       int tag = skb->skb_tag;
7158 -
7159 -       if (sk->sk_nx_info && !(tag == 1 || sk->sk_nid == tag))
7160 -               return 0;
7161 -
7162 -       rcu_read_lock_bh();
7163 -       filter = rcu_dereference(sk->sk_filter);
7164 -       if (filter != NULL)
7165 -               res = sk_run_filter(skb, filter->insns, filter->len);
7166 -       rcu_read_unlock_bh();
7167 -
7168 -       return res;
7169 -}
7170 -
7171 -/*
7172 -   This function makes lazy skb cloning in hope that most of packets
7173 -   are discarded by BPF.
7174 -
7175 -   Note tricky part: we DO mangle shared skb! skb->data, skb->len
7176 -   and skb->cb are mangled. It works because (and until) packets
7177 -   falling here are owned by current CPU. Output packets are cloned
7178 -   by dev_queue_xmit_nit(), input packets are processed by net_bh
7179 -   sequencially, so that if we return skb to original state on exit,
7180 -   we will not harm anyone.
7181 - */
7182 -
7183 -static int packet_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev)
7184 -{
7185 -       struct sock *sk;
7186 -       struct sockaddr_ll *sll;
7187 -       struct packet_sock *po;
7188 -       u8 * skb_head = skb->data;
7189 -       int skb_len = skb->len;
7190 -       unsigned int snaplen, res;
7191 -
7192 -       if (skb->pkt_type == PACKET_LOOPBACK)
7193 -               goto drop;
7194 -
7195 -       sk = pt->af_packet_priv;
7196 -       po = pkt_sk(sk);
7197 -
7198 -       skb->dev = dev;
7199 -
7200 -       if (dev->hard_header) {
7201 -               /* The device has an explicit notion of ll header,
7202 -                  exported to higher levels.
7203 -
7204 -                  Otherwise, the device hides datails of it frame
7205 -                  structure, so that corresponding packet head
7206 -                  never delivered to user.
7207 -                */
7208 -               if (sk->sk_type != SOCK_DGRAM)
7209 -                       skb_push(skb, skb->data - skb_mac_header(skb));
7210 -               else if (skb->pkt_type == PACKET_OUTGOING) {
7211 -                       /* Special case: outgoing packets have ll header at head */
7212 -                       skb_pull(skb, skb_network_offset(skb));
7213 -               }
7214 -       }
7215 -
7216 -       snaplen = skb->len;
7217 -
7218 -       res = run_filter(skb, sk, snaplen);
7219 -       if (!res)
7220 -               goto drop_n_restore;
7221 -       if (snaplen > res)
7222 -               snaplen = res;
7223 -
7224 -       if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
7225 -           (unsigned)sk->sk_rcvbuf)
7226 -               goto drop_n_acct;
7227 -
7228 -       if (skb_shared(skb)) {
7229 -               struct sk_buff *nskb = skb_clone(skb, GFP_ATOMIC);
7230 -               if (nskb == NULL)
7231 -                       goto drop_n_acct;
7232 -
7233 -               if (skb_head != skb->data) {
7234 -                       skb->data = skb_head;
7235 -                       skb->len = skb_len;
7236 -               }
7237 -               kfree_skb(skb);
7238 -               skb = nskb;
7239 -       }
7240 -
7241 -       BUILD_BUG_ON(sizeof(*PACKET_SKB_CB(skb)) + MAX_ADDR_LEN - 8 >
7242 -                    sizeof(skb->cb));
7243 -
7244 -       sll = &PACKET_SKB_CB(skb)->sa.ll;
7245 -       sll->sll_family = AF_PACKET;
7246 -       sll->sll_hatype = dev->type;
7247 -       sll->sll_protocol = skb->protocol;
7248 -       sll->sll_pkttype = skb->pkt_type;
7249 -       if (unlikely(po->origdev) && skb->pkt_type == PACKET_HOST)
7250 -               sll->sll_ifindex = orig_dev->ifindex;
7251 -       else
7252 -               sll->sll_ifindex = dev->ifindex;
7253 -       sll->sll_halen = 0;
7254 -
7255 -       if (dev->hard_header_parse)
7256 -               sll->sll_halen = dev->hard_header_parse(skb, sll->sll_addr);
7257 -
7258 -       PACKET_SKB_CB(skb)->origlen = skb->len;
7259 -
7260 -       if (pskb_trim(skb, snaplen))
7261 -               goto drop_n_acct;
7262 -
7263 -       skb_set_owner_r(skb, sk);
7264 -       skb->dev = NULL;
7265 -       dst_release(skb->dst);
7266 -       skb->dst = NULL;
7267 -
7268 -       /* drop conntrack reference */
7269 -       nf_reset(skb);
7270 -
7271 -       spin_lock(&sk->sk_receive_queue.lock);
7272 -       po->stats.tp_packets++;
7273 -       __skb_queue_tail(&sk->sk_receive_queue, skb);
7274 -       spin_unlock(&sk->sk_receive_queue.lock);
7275 -       sk->sk_data_ready(sk, skb->len);
7276 -       return 0;
7277 -
7278 -drop_n_acct:
7279 -       spin_lock(&sk->sk_receive_queue.lock);
7280 -       po->stats.tp_drops++;
7281 -       spin_unlock(&sk->sk_receive_queue.lock);
7282 -
7283 -drop_n_restore:
7284 -       if (skb_head != skb->data && skb_shared(skb)) {
7285 -               skb->data = skb_head;
7286 -               skb->len = skb_len;
7287 -       }
7288 -drop:
7289 -       kfree_skb(skb);
7290 -       return 0;
7291 -}
7292 -
7293 -#ifdef CONFIG_PACKET_MMAP
7294 -static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev)
7295 -{
7296 -       struct sock *sk;
7297 -       struct packet_sock *po;
7298 -       struct sockaddr_ll *sll;
7299 -       struct tpacket_hdr *h;
7300 -       u8 * skb_head = skb->data;
7301 -       int skb_len = skb->len;
7302 -       unsigned int snaplen, res;
7303 -       unsigned long status = TP_STATUS_LOSING|TP_STATUS_USER;
7304 -       unsigned short macoff, netoff;
7305 -       struct sk_buff *copy_skb = NULL;
7306 -       struct timeval tv;
7307 -
7308 -       if (skb->pkt_type == PACKET_LOOPBACK)
7309 -               goto drop;
7310 -
7311 -       sk = pt->af_packet_priv;
7312 -       po = pkt_sk(sk);
7313 -
7314 -       if (dev->hard_header) {
7315 -               if (sk->sk_type != SOCK_DGRAM)
7316 -                       skb_push(skb, skb->data - skb_mac_header(skb));
7317 -               else if (skb->pkt_type == PACKET_OUTGOING) {
7318 -                       /* Special case: outgoing packets have ll header at head */
7319 -                       skb_pull(skb, skb_network_offset(skb));
7320 -               }
7321 -       }
7322 -
7323 -       if (skb->ip_summed == CHECKSUM_PARTIAL)
7324 -               status |= TP_STATUS_CSUMNOTREADY;
7325 -
7326 -       snaplen = skb->len;
7327 -
7328 -       res = run_filter(skb, sk, snaplen);
7329 -       if (!res)
7330 -               goto drop_n_restore;
7331 -       if (snaplen > res)
7332 -               snaplen = res;
7333 -
7334 -       if (sk->sk_type == SOCK_DGRAM) {
7335 -               macoff = netoff = TPACKET_ALIGN(TPACKET_HDRLEN) + 16;
7336 -       } else {
7337 -               unsigned maclen = skb_network_offset(skb);
7338 -               netoff = TPACKET_ALIGN(TPACKET_HDRLEN + (maclen < 16 ? 16 : maclen));
7339 -               macoff = netoff - maclen;
7340 -       }
7341 -
7342 -       if (macoff + snaplen > po->frame_size) {
7343 -               if (po->copy_thresh &&
7344 -                   atomic_read(&sk->sk_rmem_alloc) + skb->truesize <
7345 -                   (unsigned)sk->sk_rcvbuf) {
7346 -                       if (skb_shared(skb)) {
7347 -                               copy_skb = skb_clone(skb, GFP_ATOMIC);
7348 -                       } else {
7349 -                               copy_skb = skb_get(skb);
7350 -                               skb_head = skb->data;
7351 -                       }
7352 -                       if (copy_skb)
7353 -                               skb_set_owner_r(copy_skb, sk);
7354 -               }
7355 -               snaplen = po->frame_size - macoff;
7356 -               if ((int)snaplen < 0)
7357 -                       snaplen = 0;
7358 -       }
7359 -
7360 -       spin_lock(&sk->sk_receive_queue.lock);
7361 -       h = packet_lookup_frame(po, po->head);
7362 -
7363 -       if (h->tp_status)
7364 -               goto ring_is_full;
7365 -       po->head = po->head != po->frame_max ? po->head+1 : 0;
7366 -       po->stats.tp_packets++;
7367 -       if (copy_skb) {
7368 -               status |= TP_STATUS_COPY;
7369 -               __skb_queue_tail(&sk->sk_receive_queue, copy_skb);
7370 -       }
7371 -       if (!po->stats.tp_drops)
7372 -               status &= ~TP_STATUS_LOSING;
7373 -       spin_unlock(&sk->sk_receive_queue.lock);
7374 -
7375 -       skb_copy_bits(skb, 0, (u8*)h + macoff, snaplen);
7376 -
7377 -       h->tp_len = skb->len;
7378 -       h->tp_snaplen = snaplen;
7379 -       h->tp_mac = macoff;
7380 -       h->tp_net = netoff;
7381 -       if (skb->tstamp.tv64 == 0) {
7382 -               __net_timestamp(skb);
7383 -               sock_enable_timestamp(sk);
7384 -       }
7385 -       tv = ktime_to_timeval(skb->tstamp);
7386 -       h->tp_sec = tv.tv_sec;
7387 -       h->tp_usec = tv.tv_usec;
7388 -
7389 -       sll = (struct sockaddr_ll*)((u8*)h + TPACKET_ALIGN(sizeof(*h)));
7390 -       sll->sll_halen = 0;
7391 -       if (dev->hard_header_parse)
7392 -               sll->sll_halen = dev->hard_header_parse(skb, sll->sll_addr);
7393 -       sll->sll_family = AF_PACKET;
7394 -       sll->sll_hatype = dev->type;
7395 -       sll->sll_protocol = skb->protocol;
7396 -       sll->sll_pkttype = skb->pkt_type;
7397 -       if (unlikely(po->origdev) && skb->pkt_type == PACKET_HOST)
7398 -               sll->sll_ifindex = orig_dev->ifindex;
7399 -       else
7400 -               sll->sll_ifindex = dev->ifindex;
7401 -
7402 -       h->tp_status = status;
7403 -       smp_mb();
7404 -
7405 -       {
7406 -               struct page *p_start, *p_end;
7407 -               u8 *h_end = (u8 *)h + macoff + snaplen - 1;
7408 -
7409 -               p_start = virt_to_page(h);
7410 -               p_end = virt_to_page(h_end);
7411 -               while (p_start <= p_end) {
7412 -                       flush_dcache_page(p_start);
7413 -                       p_start++;
7414 -               }
7415 -       }
7416 -
7417 -       sk->sk_data_ready(sk, 0);
7418 -
7419 -drop_n_restore:
7420 -       if (skb_head != skb->data && skb_shared(skb)) {
7421 -               skb->data = skb_head;
7422 -               skb->len = skb_len;
7423 -       }
7424 -drop:
7425 -       kfree_skb(skb);
7426 -       return 0;
7427 -
7428 -ring_is_full:
7429 -       po->stats.tp_drops++;
7430 -       spin_unlock(&sk->sk_receive_queue.lock);
7431 -
7432 -       sk->sk_data_ready(sk, 0);
7433 -       if (copy_skb)
7434 -               kfree_skb(copy_skb);
7435 -       goto drop_n_restore;
7436 -}
7437 -
7438 -#endif
7439 -
7440 -
7441 -static int packet_sendmsg(struct kiocb *iocb, struct socket *sock,
7442 -                         struct msghdr *msg, size_t len)
7443 -{
7444 -       struct sock *sk = sock->sk;
7445 -       struct sockaddr_ll *saddr=(struct sockaddr_ll *)msg->msg_name;
7446 -       struct sk_buff *skb;
7447 -       struct net_device *dev;
7448 -       __be16 proto;
7449 -       unsigned char *addr;
7450 -       int ifindex, err, reserve = 0;
7451 -
7452 -       if (!nx_capable(CAP_NET_RAW, NXC_RAW_SEND))
7453 -               return -EPERM;
7454 -
7455 -       /*
7456 -        *      Get and verify the address.
7457 -        */
7458 -
7459 -       if (saddr == NULL) {
7460 -               struct packet_sock *po = pkt_sk(sk);
7461 -
7462 -               ifindex = po->ifindex;
7463 -               proto   = po->num;
7464 -               addr    = NULL;
7465 -       } else {
7466 -               err = -EINVAL;
7467 -               if (msg->msg_namelen < sizeof(struct sockaddr_ll))
7468 -                       goto out;
7469 -               if (msg->msg_namelen < (saddr->sll_halen + offsetof(struct sockaddr_ll, sll_addr)))
7470 -                       goto out;
7471 -               ifindex = saddr->sll_ifindex;
7472 -               proto   = saddr->sll_protocol;
7473 -               addr    = saddr->sll_addr;
7474 -       }
7475 -
7476 -
7477 -       dev = dev_get_by_index(ifindex);
7478 -       err = -ENXIO;
7479 -       if (dev == NULL)
7480 -               goto out_unlock;
7481 -       if (sock->type == SOCK_RAW)
7482 -               reserve = dev->hard_header_len;
7483 -
7484 -       err = -ENETDOWN;
7485 -       if (!(dev->flags & IFF_UP))
7486 -               goto out_unlock;
7487 -
7488 -       err = -EMSGSIZE;
7489 -       if (len > dev->mtu+reserve)
7490 -               goto out_unlock;
7491 -
7492 -       skb = sock_alloc_send_skb(sk, len + LL_RESERVED_SPACE(dev),
7493 -                               msg->msg_flags & MSG_DONTWAIT, &err);
7494 -       if (skb==NULL)
7495 -               goto out_unlock;
7496 -
7497 -       skb_reserve(skb, LL_RESERVED_SPACE(dev));
7498 -       skb_reset_network_header(skb);
7499 -
7500 -       if (dev->hard_header) {
7501 -               int res;
7502 -               err = -EINVAL;
7503 -               res = dev->hard_header(skb, dev, ntohs(proto), addr, NULL, len);
7504 -               if (sock->type != SOCK_DGRAM) {
7505 -                       skb_reset_tail_pointer(skb);
7506 -                       skb->len = 0;
7507 -               } else if (res < 0)
7508 -                       goto out_free;
7509 -       }
7510 -
7511 -       /* Returns -EFAULT on error */
7512 -       err = memcpy_fromiovec(skb_put(skb,len), msg->msg_iov, len);
7513 -       if (err)
7514 -               goto out_free;
7515 -
7516 -       skb->protocol = proto;
7517 -       skb->dev = dev;
7518 -       skb->priority = sk->sk_priority;
7519 -
7520 -       /*
7521 -        *      Now send it
7522 -        */
7523 -
7524 -       err = dev_queue_xmit(skb);
7525 -       if (err > 0 && (err = net_xmit_errno(err)) != 0)
7526 -               goto out_unlock;
7527 -
7528 -       dev_put(dev);
7529 -
7530 -       return(len);
7531 -
7532 -out_free:
7533 -       kfree_skb(skb);
7534 -out_unlock:
7535 -       if (dev)
7536 -               dev_put(dev);
7537 -out:
7538 -       return err;
7539 -}
7540 -
7541 -/*
7542 - *     Close a PACKET socket. This is fairly simple. We immediately go
7543 - *     to 'closed' state and remove our protocol entry in the device list.
7544 - */
7545 -
7546 -static int packet_release(struct socket *sock)
7547 -{
7548 -       struct sock *sk = sock->sk;
7549 -       struct packet_sock *po;
7550 -
7551 -       if (!sk)
7552 -               return 0;
7553 -
7554 -       po = pkt_sk(sk);
7555 -
7556 -       write_lock_bh(&packet_sklist_lock);
7557 -       sk_del_node_init(sk);
7558 -       write_unlock_bh(&packet_sklist_lock);
7559 -
7560 -       /*
7561 -        *      Unhook packet receive handler.
7562 -        */
7563 -
7564 -       if (po->running) {
7565 -               /*
7566 -                *      Remove the protocol hook
7567 -                */
7568 -               dev_remove_pack(&po->prot_hook);
7569 -               po->running = 0;
7570 -               po->num = 0;
7571 -               __sock_put(sk);
7572 -       }
7573 -
7574 -       packet_flush_mclist(sk);
7575 -
7576 -#ifdef CONFIG_PACKET_MMAP
7577 -       if (po->pg_vec) {
7578 -               struct tpacket_req req;
7579 -               memset(&req, 0, sizeof(req));
7580 -               packet_set_ring(sk, &req, 1);
7581 -       }
7582 -#endif
7583 -
7584 -       /*
7585 -        *      Now the socket is dead. No more input will appear.
7586 -        */
7587 -
7588 -       sock_orphan(sk);
7589 -       sock->sk = NULL;
7590 -
7591 -       /* Purge queues */
7592 -
7593 -       skb_queue_purge(&sk->sk_receive_queue);
7594 -
7595 -       sock_put(sk);
7596 -       return 0;
7597 -}
7598 -
7599 -/*
7600 - *     Attach a packet hook.
7601 - */
7602 -
7603 -static int packet_do_bind(struct sock *sk, struct net_device *dev, __be16 protocol)
7604 -{
7605 -       struct packet_sock *po = pkt_sk(sk);
7606 -       /*
7607 -        *      Detach an existing hook if present.
7608 -        */
7609 -
7610 -       lock_sock(sk);
7611 -
7612 -       spin_lock(&po->bind_lock);
7613 -       if (po->running) {
7614 -               __sock_put(sk);
7615 -               po->running = 0;
7616 -               po->num = 0;
7617 -               spin_unlock(&po->bind_lock);
7618 -               dev_remove_pack(&po->prot_hook);
7619 -               spin_lock(&po->bind_lock);
7620 -       }
7621 -
7622 -       po->num = protocol;
7623 -       po->prot_hook.type = protocol;
7624 -       po->prot_hook.dev = dev;
7625 -
7626 -       po->ifindex = dev ? dev->ifindex : 0;
7627 -
7628 -       if (protocol == 0)
7629 -               goto out_unlock;
7630 -
7631 -       if (dev) {
7632 -               if (dev->flags&IFF_UP) {
7633 -                       dev_add_pack(&po->prot_hook);
7634 -                       sock_hold(sk);
7635 -                       po->running = 1;
7636 -               } else {
7637 -                       sk->sk_err = ENETDOWN;
7638 -                       if (!sock_flag(sk, SOCK_DEAD))
7639 -                               sk->sk_error_report(sk);
7640 -               }
7641 -       } else {
7642 -               dev_add_pack(&po->prot_hook);
7643 -               sock_hold(sk);
7644 -               po->running = 1;
7645 -       }
7646 -
7647 -out_unlock:
7648 -       spin_unlock(&po->bind_lock);
7649 -       release_sock(sk);
7650 -       return 0;
7651 -}
7652 -
7653 -/*
7654 - *     Bind a packet socket to a device
7655 - */
7656 -
7657 -static int packet_bind_spkt(struct socket *sock, struct sockaddr *uaddr, int addr_len)
7658 -{
7659 -       struct sock *sk=sock->sk;
7660 -       char name[15];
7661 -       struct net_device *dev;
7662 -       int err = -ENODEV;
7663 -
7664 -       /*
7665 -        *      Check legality
7666 -        */
7667 -
7668 -       if (addr_len != sizeof(struct sockaddr))
7669 -               return -EINVAL;
7670 -       strlcpy(name,uaddr->sa_data,sizeof(name));
7671 -
7672 -       dev = dev_get_by_name(name);
7673 -       if (dev) {
7674 -               err = packet_do_bind(sk, dev, pkt_sk(sk)->num);
7675 -               dev_put(dev);
7676 -       }
7677 -       return err;
7678 -}
7679 -
7680 -static int packet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
7681 -{
7682 -       struct sockaddr_ll *sll = (struct sockaddr_ll*)uaddr;
7683 -       struct sock *sk=sock->sk;
7684 -       struct net_device *dev = NULL;
7685 -       int err;
7686 -
7687 -
7688 -       /*
7689 -        *      Check legality
7690 -        */
7691 -
7692 -       if (addr_len < sizeof(struct sockaddr_ll))
7693 -               return -EINVAL;
7694 -       if (sll->sll_family != AF_PACKET)
7695 -               return -EINVAL;
7696 -
7697 -       if (sll->sll_ifindex) {
7698 -               err = -ENODEV;
7699 -               dev = dev_get_by_index(sll->sll_ifindex);
7700 -               if (dev == NULL)
7701 -                       goto out;
7702 -       }
7703 -       err = packet_do_bind(sk, dev, sll->sll_protocol ? : pkt_sk(sk)->num);
7704 -       if (dev)
7705 -               dev_put(dev);
7706 -
7707 -out:
7708 -       return err;
7709 -}
7710 -
7711 -static struct proto packet_proto = {
7712 -       .name     = "PACKET",
7713 -       .owner    = THIS_MODULE,
7714 -       .obj_size = sizeof(struct packet_sock),
7715 -};
7716 -
7717 -/*
7718 - *     Create a packet of type SOCK_PACKET.
7719 - */
7720 -
7721 -static int packet_create(struct socket *sock, int protocol)
7722 -{
7723 -       struct sock *sk;
7724 -       struct packet_sock *po;
7725 -       __be16 proto = (__force __be16)protocol; /* weird, but documented */
7726 -       int err;
7727 -
7728 -       if (!nx_capable(CAP_NET_RAW, NXC_RAW_SOCKET))
7729 -               return -EPERM;
7730 -       if (sock->type != SOCK_DGRAM && sock->type != SOCK_RAW &&
7731 -           sock->type != SOCK_PACKET)
7732 -               return -ESOCKTNOSUPPORT;
7733 -
7734 -       sock->state = SS_UNCONNECTED;
7735 -
7736 -       err = -ENOBUFS;
7737 -       sk = sk_alloc(PF_PACKET, GFP_KERNEL, &packet_proto, 1);
7738 -       if (sk == NULL)
7739 -               goto out;
7740 -
7741 -       sock->ops = &packet_ops;
7742 -       if (sock->type == SOCK_PACKET)
7743 -               sock->ops = &packet_ops_spkt;
7744 -
7745 -       sock_init_data(sock, sk);
7746 -
7747 -       po = pkt_sk(sk);
7748 -       sk->sk_family = PF_PACKET;
7749 -       po->num = proto;
7750 -
7751 -       sk->sk_destruct = packet_sock_destruct;
7752 -       atomic_inc(&packet_socks_nr);
7753 -
7754 -       /*
7755 -        *      Attach a protocol block
7756 -        */
7757 -
7758 -       spin_lock_init(&po->bind_lock);
7759 -       po->prot_hook.func = packet_rcv;
7760 -
7761 -       if (sock->type == SOCK_PACKET)
7762 -               po->prot_hook.func = packet_rcv_spkt;
7763 -
7764 -       po->prot_hook.af_packet_priv = sk;
7765 -
7766 -       if (proto) {
7767 -               po->prot_hook.type = proto;
7768 -               dev_add_pack(&po->prot_hook);
7769 -               sock_hold(sk);
7770 -               po->running = 1;
7771 -       }
7772 -
7773 -       write_lock_bh(&packet_sklist_lock);
7774 -       sk_add_node(sk, &packet_sklist);
7775 -       write_unlock_bh(&packet_sklist_lock);
7776 -       return(0);
7777 -out:
7778 -       return err;
7779 -}
7780 -
7781 -/*
7782 - *     Pull a packet from our receive queue and hand it to the user.
7783 - *     If necessary we block.
7784 - */
7785 -
7786 -static int packet_recvmsg(struct kiocb *iocb, struct socket *sock,
7787 -                         struct msghdr *msg, size_t len, int flags)
7788 -{
7789 -       struct sock *sk = sock->sk;
7790 -       struct sk_buff *skb;
7791 -       int copied, err;
7792 -       struct sockaddr_ll *sll;
7793 -
7794 -       err = -EINVAL;
7795 -       if (flags & ~(MSG_PEEK|MSG_DONTWAIT|MSG_TRUNC|MSG_CMSG_COMPAT))
7796 -               goto out;
7797 -
7798 -#if 0
7799 -       /* What error should we return now? EUNATTACH? */
7800 -       if (pkt_sk(sk)->ifindex < 0)
7801 -               return -ENODEV;
7802 -#endif
7803 -
7804 -       /*
7805 -        *      Call the generic datagram receiver. This handles all sorts
7806 -        *      of horrible races and re-entrancy so we can forget about it
7807 -        *      in the protocol layers.
7808 -        *
7809 -        *      Now it will return ENETDOWN, if device have just gone down,
7810 -        *      but then it will block.
7811 -        */
7812 -
7813 -       skb=skb_recv_datagram(sk,flags,flags&MSG_DONTWAIT,&err);
7814 -
7815 -       /*
7816 -        *      An error occurred so return it. Because skb_recv_datagram()
7817 -        *      handles the blocking we don't see and worry about blocking
7818 -        *      retries.
7819 -        */
7820 -
7821 -       if (skb == NULL)
7822 -               goto out;
7823 -
7824 -       /*
7825 -        *      If the address length field is there to be filled in, we fill
7826 -        *      it in now.
7827 -        */
7828 -
7829 -       sll = &PACKET_SKB_CB(skb)->sa.ll;
7830 -       if (sock->type == SOCK_PACKET)
7831 -               msg->msg_namelen = sizeof(struct sockaddr_pkt);
7832 -       else
7833 -               msg->msg_namelen = sll->sll_halen + offsetof(struct sockaddr_ll, sll_addr);
7834 -
7835 -       /*
7836 -        *      You lose any data beyond the buffer you gave. If it worries a
7837 -        *      user program they can ask the device for its MTU anyway.
7838 -        */
7839 -
7840 -       copied = skb->len;
7841 -       if (copied > len)
7842 -       {
7843 -               copied=len;
7844 -               msg->msg_flags|=MSG_TRUNC;
7845 -       }
7846 -
7847 -       err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
7848 -       if (err)
7849 -               goto out_free;
7850 -
7851 -       sock_recv_timestamp(msg, sk, skb);
7852 -
7853 -       if (msg->msg_name)
7854 -               memcpy(msg->msg_name, &PACKET_SKB_CB(skb)->sa,
7855 -                      msg->msg_namelen);
7856 -
7857 -       if (pkt_sk(sk)->auxdata) {
7858 -               struct tpacket_auxdata aux;
7859 -
7860 -               aux.tp_status = TP_STATUS_USER;
7861 -               if (skb->ip_summed == CHECKSUM_PARTIAL)
7862 -                       aux.tp_status |= TP_STATUS_CSUMNOTREADY;
7863 -               aux.tp_len = PACKET_SKB_CB(skb)->origlen;
7864 -               aux.tp_snaplen = skb->len;
7865 -               aux.tp_mac = 0;
7866 -               aux.tp_net = skb_network_offset(skb);
7867 -
7868 -               put_cmsg(msg, SOL_PACKET, PACKET_AUXDATA, sizeof(aux), &aux);
7869 -       }
7870 -
7871 -       /*
7872 -        *      Free or return the buffer as appropriate. Again this
7873 -        *      hides all the races and re-entrancy issues from us.
7874 -        */
7875 -       err = (flags&MSG_TRUNC) ? skb->len : copied;
7876 -
7877 -out_free:
7878 -       skb_free_datagram(sk, skb);
7879 -out:
7880 -       return err;
7881 -}
7882 -
7883 -static int packet_getname_spkt(struct socket *sock, struct sockaddr *uaddr,
7884 -                              int *uaddr_len, int peer)
7885 -{
7886 -       struct net_device *dev;
7887 -       struct sock *sk = sock->sk;
7888 -
7889 -       if (peer)
7890 -               return -EOPNOTSUPP;
7891 -
7892 -       uaddr->sa_family = AF_PACKET;
7893 -       dev = dev_get_by_index(pkt_sk(sk)->ifindex);
7894 -       if (dev) {
7895 -               strlcpy(uaddr->sa_data, dev->name, 15);
7896 -               dev_put(dev);
7897 -       } else
7898 -               memset(uaddr->sa_data, 0, 14);
7899 -       *uaddr_len = sizeof(*uaddr);
7900 -
7901 -       return 0;
7902 -}
7903 -
7904 -static int packet_getname(struct socket *sock, struct sockaddr *uaddr,
7905 -                         int *uaddr_len, int peer)
7906 -{
7907 -       struct net_device *dev;
7908 -       struct sock *sk = sock->sk;
7909 -       struct packet_sock *po = pkt_sk(sk);
7910 -       struct sockaddr_ll *sll = (struct sockaddr_ll*)uaddr;
7911 -
7912 -       if (peer)
7913 -               return -EOPNOTSUPP;
7914 -
7915 -       sll->sll_family = AF_PACKET;
7916 -       sll->sll_ifindex = po->ifindex;
7917 -       sll->sll_protocol = po->num;
7918 -       dev = dev_get_by_index(po->ifindex);
7919 -       if (dev) {
7920 -               sll->sll_hatype = dev->type;
7921 -               sll->sll_halen = dev->addr_len;
7922 -               memcpy(sll->sll_addr, dev->dev_addr, dev->addr_len);
7923 -               dev_put(dev);
7924 -       } else {
7925 -               sll->sll_hatype = 0;    /* Bad: we have no ARPHRD_UNSPEC */
7926 -               sll->sll_halen = 0;
7927 -       }
7928 -       *uaddr_len = offsetof(struct sockaddr_ll, sll_addr) + sll->sll_halen;
7929 -
7930 -       return 0;
7931 -}
7932 -
7933 -static void packet_dev_mc(struct net_device *dev, struct packet_mclist *i, int what)
7934 -{
7935 -       switch (i->type) {
7936 -       case PACKET_MR_MULTICAST:
7937 -               if (what > 0)
7938 -                       dev_mc_add(dev, i->addr, i->alen, 0);
7939 -               else
7940 -                       dev_mc_delete(dev, i->addr, i->alen, 0);
7941 -               break;
7942 -       case PACKET_MR_PROMISC:
7943 -               dev_set_promiscuity(dev, what);
7944 -               break;
7945 -       case PACKET_MR_ALLMULTI:
7946 -               dev_set_allmulti(dev, what);
7947 -               break;
7948 -       default:;
7949 -       }
7950 -}
7951 -
7952 -static void packet_dev_mclist(struct net_device *dev, struct packet_mclist *i, int what)
7953 -{
7954 -       for ( ; i; i=i->next) {
7955 -               if (i->ifindex == dev->ifindex)
7956 -                       packet_dev_mc(dev, i, what);
7957 -       }
7958 -}
7959 -
7960 -static int packet_mc_add(struct sock *sk, struct packet_mreq_max *mreq)
7961 -{
7962 -       struct packet_sock *po = pkt_sk(sk);
7963 -       struct packet_mclist *ml, *i;
7964 -       struct net_device *dev;
7965 -       int err;
7966 -
7967 -       rtnl_lock();
7968 -
7969 -       err = -ENODEV;
7970 -       dev = __dev_get_by_index(mreq->mr_ifindex);
7971 -       if (!dev)
7972 -               goto done;
7973 -
7974 -       err = -EINVAL;
7975 -       if (mreq->mr_alen > dev->addr_len)
7976 -               goto done;
7977 -
7978 -       err = -ENOBUFS;
7979 -       i = kmalloc(sizeof(*i), GFP_KERNEL);
7980 -       if (i == NULL)
7981 -               goto done;
7982 -
7983 -       err = 0;
7984 -       for (ml = po->mclist; ml; ml = ml->next) {
7985 -               if (ml->ifindex == mreq->mr_ifindex &&
7986 -                   ml->type == mreq->mr_type &&
7987 -                   ml->alen == mreq->mr_alen &&
7988 -                   memcmp(ml->addr, mreq->mr_address, ml->alen) == 0) {
7989 -                       ml->count++;
7990 -                       /* Free the new element ... */
7991 -                       kfree(i);
7992 -                       goto done;
7993 -               }
7994 -       }
7995 -
7996 -       i->type = mreq->mr_type;
7997 -       i->ifindex = mreq->mr_ifindex;
7998 -       i->alen = mreq->mr_alen;
7999 -       memcpy(i->addr, mreq->mr_address, i->alen);
8000 -       i->count = 1;
8001 -       i->next = po->mclist;
8002 -       po->mclist = i;
8003 -       packet_dev_mc(dev, i, +1);
8004 -
8005 -done:
8006 -       rtnl_unlock();
8007 -       return err;
8008 -}
8009 -
8010 -static int packet_mc_drop(struct sock *sk, struct packet_mreq_max *mreq)
8011 -{
8012 -       struct packet_mclist *ml, **mlp;
8013 -
8014 -       rtnl_lock();
8015 -
8016 -       for (mlp = &pkt_sk(sk)->mclist; (ml = *mlp) != NULL; mlp = &ml->next) {
8017 -               if (ml->ifindex == mreq->mr_ifindex &&
8018 -                   ml->type == mreq->mr_type &&
8019 -                   ml->alen == mreq->mr_alen &&
8020 -                   memcmp(ml->addr, mreq->mr_address, ml->alen) == 0) {
8021 -                       if (--ml->count == 0) {
8022 -                               struct net_device *dev;
8023 -                               *mlp = ml->next;
8024 -                               dev = dev_get_by_index(ml->ifindex);
8025 -                               if (dev) {
8026 -                                       packet_dev_mc(dev, ml, -1);
8027 -                                       dev_put(dev);
8028 -                               }
8029 -                               kfree(ml);
8030 -                       }
8031 -                       rtnl_unlock();
8032 -                       return 0;
8033 -               }
8034 -       }
8035 -       rtnl_unlock();
8036 -       return -EADDRNOTAVAIL;
8037 -}
8038 -
8039 -static void packet_flush_mclist(struct sock *sk)
8040 -{
8041 -       struct packet_sock *po = pkt_sk(sk);
8042 -       struct packet_mclist *ml;
8043 -
8044 -       if (!po->mclist)
8045 -               return;
8046 -
8047 -       rtnl_lock();
8048 -       while ((ml = po->mclist) != NULL) {
8049 -               struct net_device *dev;
8050 -
8051 -               po->mclist = ml->next;
8052 -               if ((dev = dev_get_by_index(ml->ifindex)) != NULL) {
8053 -                       packet_dev_mc(dev, ml, -1);
8054 -                       dev_put(dev);
8055 -               }
8056 -               kfree(ml);
8057 -       }
8058 -       rtnl_unlock();
8059 -}
8060 -
8061 -static int
8062 -packet_setsockopt(struct socket *sock, int level, int optname, char __user *optval, int optlen)
8063 -{
8064 -       struct sock *sk = sock->sk;
8065 -       struct packet_sock *po = pkt_sk(sk);
8066 -       int ret;
8067 -
8068 -       if (level != SOL_PACKET)
8069 -               return -ENOPROTOOPT;
8070 -
8071 -       switch(optname) {
8072 -       case PACKET_ADD_MEMBERSHIP:
8073 -       case PACKET_DROP_MEMBERSHIP:
8074 -       {
8075 -               struct packet_mreq_max mreq;
8076 -               int len = optlen;
8077 -               memset(&mreq, 0, sizeof(mreq));
8078 -               if (len < sizeof(struct packet_mreq))
8079 -                       return -EINVAL;
8080 -               if (len > sizeof(mreq))
8081 -                       len = sizeof(mreq);
8082 -               if (copy_from_user(&mreq,optval,len))
8083 -                       return -EFAULT;
8084 -               if (len < (mreq.mr_alen + offsetof(struct packet_mreq, mr_address)))
8085 -                       return -EINVAL;
8086 -               if (optname == PACKET_ADD_MEMBERSHIP)
8087 -                       ret = packet_mc_add(sk, &mreq);
8088 -               else
8089 -                       ret = packet_mc_drop(sk, &mreq);
8090 -               return ret;
8091 -       }
8092 -
8093 -#ifdef CONFIG_PACKET_MMAP
8094 -       case PACKET_RX_RING:
8095 -       {
8096 -               struct tpacket_req req;
8097 -
8098 -               if (optlen<sizeof(req))
8099 -                       return -EINVAL;
8100 -               if (copy_from_user(&req,optval,sizeof(req)))
8101 -                       return -EFAULT;
8102 -               return packet_set_ring(sk, &req, 0);
8103 -       }
8104 -       case PACKET_COPY_THRESH:
8105 -       {
8106 -               int val;
8107 -
8108 -               if (optlen!=sizeof(val))
8109 -                       return -EINVAL;
8110 -               if (copy_from_user(&val,optval,sizeof(val)))
8111 -                       return -EFAULT;
8112 -
8113 -               pkt_sk(sk)->copy_thresh = val;
8114 -               return 0;
8115 -       }
8116 -#endif
8117 -       case PACKET_AUXDATA:
8118 -       {
8119 -               int val;
8120 -
8121 -               if (optlen < sizeof(val))
8122 -                       return -EINVAL;
8123 -               if (copy_from_user(&val, optval, sizeof(val)))
8124 -                       return -EFAULT;
8125 -
8126 -               po->auxdata = !!val;
8127 -               return 0;
8128 -       }
8129 -       case PACKET_ORIGDEV:
8130 -       {
8131 -               int val;
8132 -
8133 -               if (optlen < sizeof(val))
8134 -                       return -EINVAL;
8135 -               if (copy_from_user(&val, optval, sizeof(val)))
8136 -                       return -EFAULT;
8137 -
8138 -               po->origdev = !!val;
8139 -               return 0;
8140 -       }
8141 -       default:
8142 -               return -ENOPROTOOPT;
8143 -       }
8144 -}
8145 -
8146 -static int packet_getsockopt(struct socket *sock, int level, int optname,
8147 -                            char __user *optval, int __user *optlen)
8148 -{
8149 -       int len;
8150 -       int val;
8151 -       struct sock *sk = sock->sk;
8152 -       struct packet_sock *po = pkt_sk(sk);
8153 -       void *data;
8154 -       struct tpacket_stats st;
8155 -
8156 -       if (level != SOL_PACKET)
8157 -               return -ENOPROTOOPT;
8158 -
8159 -       if (get_user(len, optlen))
8160 -               return -EFAULT;
8161 -
8162 -       if (len < 0)
8163 -               return -EINVAL;
8164 -
8165 -       switch(optname) {
8166 -       case PACKET_STATISTICS:
8167 -               if (len > sizeof(struct tpacket_stats))
8168 -                       len = sizeof(struct tpacket_stats);
8169 -               spin_lock_bh(&sk->sk_receive_queue.lock);
8170 -               st = po->stats;
8171 -               memset(&po->stats, 0, sizeof(st));
8172 -               spin_unlock_bh(&sk->sk_receive_queue.lock);
8173 -               st.tp_packets += st.tp_drops;
8174 -
8175 -               data = &st;
8176 -               break;
8177 -       case PACKET_AUXDATA:
8178 -               if (len > sizeof(int))
8179 -                       len = sizeof(int);
8180 -               val = po->auxdata;
8181 -
8182 -               data = &val;
8183 -               break;
8184 -       case PACKET_ORIGDEV:
8185 -               if (len > sizeof(int))
8186 -                       len = sizeof(int);
8187 -               val = po->origdev;
8188 -
8189 -               data = &val;
8190 -               break;
8191 -       default:
8192 -               return -ENOPROTOOPT;
8193 -       }
8194 -
8195 -       if (put_user(len, optlen))
8196 -               return -EFAULT;
8197 -       if (copy_to_user(optval, data, len))
8198 -               return -EFAULT;
8199 -       return 0;
8200 -}
8201 -
8202 -
8203 -static int packet_notifier(struct notifier_block *this, unsigned long msg, void *data)
8204 -{
8205 -       struct sock *sk;
8206 -       struct hlist_node *node;
8207 -       struct net_device *dev = data;
8208 -
8209 -       read_lock(&packet_sklist_lock);
8210 -       sk_for_each(sk, node, &packet_sklist) {
8211 -               struct packet_sock *po = pkt_sk(sk);
8212 -
8213 -               switch (msg) {
8214 -               case NETDEV_UNREGISTER:
8215 -                       if (po->mclist)
8216 -                               packet_dev_mclist(dev, po->mclist, -1);
8217 -                       /* fallthrough */
8218 -
8219 -               case NETDEV_DOWN:
8220 -                       if (dev->ifindex == po->ifindex) {
8221 -                               spin_lock(&po->bind_lock);
8222 -                               if (po->running) {
8223 -                                       __dev_remove_pack(&po->prot_hook);
8224 -                                       __sock_put(sk);
8225 -                                       po->running = 0;
8226 -                                       sk->sk_err = ENETDOWN;
8227 -                                       if (!sock_flag(sk, SOCK_DEAD))
8228 -                                               sk->sk_error_report(sk);
8229 -                               }
8230 -                               if (msg == NETDEV_UNREGISTER) {
8231 -                                       po->ifindex = -1;
8232 -                                       po->prot_hook.dev = NULL;
8233 -                               }
8234 -                               spin_unlock(&po->bind_lock);
8235 -                       }
8236 -                       break;
8237 -               case NETDEV_UP:
8238 -                       spin_lock(&po->bind_lock);
8239 -                       if (dev->ifindex == po->ifindex && po->num &&
8240 -                           !po->running) {
8241 -                               dev_add_pack(&po->prot_hook);
8242 -                               sock_hold(sk);
8243 -                               po->running = 1;
8244 -                       }
8245 -                       spin_unlock(&po->bind_lock);
8246 -                       break;
8247 -               }
8248 -       }
8249 -       read_unlock(&packet_sklist_lock);
8250 -       return NOTIFY_DONE;
8251 -}
8252 -
8253 -
8254 -static int packet_ioctl(struct socket *sock, unsigned int cmd,
8255 -                       unsigned long arg)
8256 -{
8257 -       struct sock *sk = sock->sk;
8258 -
8259 -       switch(cmd) {
8260 -               case SIOCOUTQ:
8261 -               {
8262 -                       int amount = atomic_read(&sk->sk_wmem_alloc);
8263 -                       return put_user(amount, (int __user *)arg);
8264 -               }
8265 -               case SIOCINQ:
8266 -               {
8267 -                       struct sk_buff *skb;
8268 -                       int amount = 0;
8269 -
8270 -                       spin_lock_bh(&sk->sk_receive_queue.lock);
8271 -                       skb = skb_peek(&sk->sk_receive_queue);
8272 -                       if (skb)
8273 -                               amount = skb->len;
8274 -                       spin_unlock_bh(&sk->sk_receive_queue.lock);
8275 -                       return put_user(amount, (int __user *)arg);
8276 -               }
8277 -               case SIOCGSTAMP:
8278 -                       return sock_get_timestamp(sk, (struct timeval __user *)arg);
8279 -               case SIOCGSTAMPNS:
8280 -                       return sock_get_timestampns(sk, (struct timespec __user *)arg);
8281 -
8282 -#ifdef CONFIG_INET
8283 -               case SIOCADDRT:
8284 -               case SIOCDELRT:
8285 -               case SIOCDARP:
8286 -               case SIOCGARP:
8287 -               case SIOCSARP:
8288 -               case SIOCGIFADDR:
8289 -               case SIOCSIFADDR:
8290 -               case SIOCGIFBRDADDR:
8291 -               case SIOCSIFBRDADDR:
8292 -               case SIOCGIFNETMASK:
8293 -               case SIOCSIFNETMASK:
8294 -               case SIOCGIFDSTADDR:
8295 -               case SIOCSIFDSTADDR:
8296 -               case SIOCSIFFLAGS:
8297 -                       return inet_dgram_ops.ioctl(sock, cmd, arg);
8298 -#endif
8299 -
8300 -               default:
8301 -                       return -ENOIOCTLCMD;
8302 -       }
8303 -       return 0;
8304 -}
8305 -
8306 -#ifndef CONFIG_PACKET_MMAP
8307 -#define packet_mmap sock_no_mmap
8308 -#define packet_poll datagram_poll
8309 -#else
8310 -
8311 -static unsigned int packet_poll(struct file * file, struct socket *sock,
8312 -                               poll_table *wait)
8313 -{
8314 -       struct sock *sk = sock->sk;
8315 -       struct packet_sock *po = pkt_sk(sk);
8316 -       unsigned int mask = datagram_poll(file, sock, wait);
8317 -
8318 -       spin_lock_bh(&sk->sk_receive_queue.lock);
8319 -       if (po->pg_vec) {
8320 -               unsigned last = po->head ? po->head-1 : po->frame_max;
8321 -               struct tpacket_hdr *h;
8322 -
8323 -               h = packet_lookup_frame(po, last);
8324 -
8325 -               if (h->tp_status)
8326 -                       mask |= POLLIN | POLLRDNORM;
8327 -       }
8328 -       spin_unlock_bh(&sk->sk_receive_queue.lock);
8329 -       return mask;
8330 -}
8331 -
8332 -
8333 -/* Dirty? Well, I still did not learn better way to account
8334 - * for user mmaps.
8335 - */
8336 -
8337 -static void packet_mm_open(struct vm_area_struct *vma)
8338 -{
8339 -       struct file *file = vma->vm_file;
8340 -       struct socket * sock = file->private_data;
8341 -       struct sock *sk = sock->sk;
8342 -
8343 -       if (sk)
8344 -               atomic_inc(&pkt_sk(sk)->mapped);
8345 -}
8346 -
8347 -static void packet_mm_close(struct vm_area_struct *vma)
8348 -{
8349 -       struct file *file = vma->vm_file;
8350 -       struct socket * sock = file->private_data;
8351 -       struct sock *sk = sock->sk;
8352 -
8353 -       if (sk)
8354 -               atomic_dec(&pkt_sk(sk)->mapped);
8355 -}
8356 -
8357 -static struct vm_operations_struct packet_mmap_ops = {
8358 -       .open = packet_mm_open,
8359 -       .close =packet_mm_close,
8360 -};
8361 -
8362 -static inline struct page *pg_vec_endpage(char *one_pg_vec, unsigned int order)
8363 -{
8364 -       return virt_to_page(one_pg_vec + (PAGE_SIZE << order) - 1);
8365 -}
8366 -
8367 -static void free_pg_vec(char **pg_vec, unsigned int order, unsigned int len)
8368 -{
8369 -       int i;
8370 -
8371 -       for (i = 0; i < len; i++) {
8372 -               if (likely(pg_vec[i]))
8373 -                       free_pages((unsigned long) pg_vec[i], order);
8374 -       }
8375 -       kfree(pg_vec);
8376 -}
8377 -
8378 -static inline char *alloc_one_pg_vec_page(unsigned long order)
8379 -{
8380 -       return (char *) __get_free_pages(GFP_KERNEL | __GFP_COMP | __GFP_ZERO,
8381 -                                        order);
8382 -}
8383 -
8384 -static char **alloc_pg_vec(struct tpacket_req *req, int order)
8385 -{
8386 -       unsigned int block_nr = req->tp_block_nr;
8387 -       char **pg_vec;
8388 -       int i;
8389 -
8390 -       pg_vec = kzalloc(block_nr * sizeof(char *), GFP_KERNEL);
8391 -       if (unlikely(!pg_vec))
8392 -               goto out;
8393 -
8394 -       for (i = 0; i < block_nr; i++) {
8395 -               pg_vec[i] = alloc_one_pg_vec_page(order);
8396 -               if (unlikely(!pg_vec[i]))
8397 -                       goto out_free_pgvec;
8398 -       }
8399 -
8400 -out:
8401 -       return pg_vec;
8402 -
8403 -out_free_pgvec:
8404 -       free_pg_vec(pg_vec, order, block_nr);
8405 -       pg_vec = NULL;
8406 -       goto out;
8407 -}
8408 -
8409 -static int packet_set_ring(struct sock *sk, struct tpacket_req *req, int closing)
8410 -{
8411 -       char **pg_vec = NULL;
8412 -       struct packet_sock *po = pkt_sk(sk);
8413 -       int was_running, order = 0;
8414 -       __be16 num;
8415 -       int err = 0;
8416 -
8417 -       if (req->tp_block_nr) {
8418 -               int i, l;
8419 -
8420 -               /* Sanity tests and some calculations */
8421 -
8422 -               if (unlikely(po->pg_vec))
8423 -                       return -EBUSY;
8424 -
8425 -               if (unlikely((int)req->tp_block_size <= 0))
8426 -                       return -EINVAL;
8427 -               if (unlikely(req->tp_block_size & (PAGE_SIZE - 1)))
8428 -                       return -EINVAL;
8429 -               if (unlikely(req->tp_frame_size < TPACKET_HDRLEN))
8430 -                       return -EINVAL;
8431 -               if (unlikely(req->tp_frame_size & (TPACKET_ALIGNMENT - 1)))
8432 -                       return -EINVAL;
8433 -
8434 -               po->frames_per_block = req->tp_block_size/req->tp_frame_size;
8435 -               if (unlikely(po->frames_per_block <= 0))
8436 -                       return -EINVAL;
8437 -               if (unlikely((po->frames_per_block * req->tp_block_nr) !=
8438 -                            req->tp_frame_nr))
8439 -                       return -EINVAL;
8440 -
8441 -               err = -ENOMEM;
8442 -               order = get_order(req->tp_block_size);
8443 -               pg_vec = alloc_pg_vec(req, order);
8444 -               if (unlikely(!pg_vec))
8445 -                       goto out;
8446 -
8447 -               l = 0;
8448 -               for (i = 0; i < req->tp_block_nr; i++) {
8449 -                       char *ptr = pg_vec[i];
8450 -                       struct tpacket_hdr *header;
8451 -                       int k;
8452 -
8453 -                       for (k = 0; k < po->frames_per_block; k++) {
8454 -                               header = (struct tpacket_hdr *) ptr;
8455 -                               header->tp_status = TP_STATUS_KERNEL;
8456 -                               ptr += req->tp_frame_size;
8457 -                       }
8458 -               }
8459 -               /* Done */
8460 -       } else {
8461 -               if (unlikely(req->tp_frame_nr))
8462 -                       return -EINVAL;
8463 -       }
8464 -
8465 -       lock_sock(sk);
8466 -
8467 -       /* Detach socket from network */
8468 -       spin_lock(&po->bind_lock);
8469 -       was_running = po->running;
8470 -       num = po->num;
8471 -       if (was_running) {
8472 -               __dev_remove_pack(&po->prot_hook);
8473 -               po->num = 0;
8474 -               po->running = 0;
8475 -               __sock_put(sk);
8476 -       }
8477 -       spin_unlock(&po->bind_lock);
8478 -
8479 -       synchronize_net();
8480 -
8481 -       err = -EBUSY;
8482 -       if (closing || atomic_read(&po->mapped) == 0) {
8483 -               err = 0;
8484 -#define XC(a, b) ({ __typeof__ ((a)) __t; __t = (a); (a) = (b); __t; })
8485 -
8486 -               spin_lock_bh(&sk->sk_receive_queue.lock);
8487 -               pg_vec = XC(po->pg_vec, pg_vec);
8488 -               po->frame_max = (req->tp_frame_nr - 1);
8489 -               po->head = 0;
8490 -               po->frame_size = req->tp_frame_size;
8491 -               spin_unlock_bh(&sk->sk_receive_queue.lock);
8492 -
8493 -               order = XC(po->pg_vec_order, order);
8494 -               req->tp_block_nr = XC(po->pg_vec_len, req->tp_block_nr);
8495 -
8496 -               po->pg_vec_pages = req->tp_block_size/PAGE_SIZE;
8497 -               po->prot_hook.func = po->pg_vec ? tpacket_rcv : packet_rcv;
8498 -               skb_queue_purge(&sk->sk_receive_queue);
8499 -#undef XC
8500 -               if (atomic_read(&po->mapped))
8501 -                       printk(KERN_DEBUG "packet_mmap: vma is busy: %d\n", atomic_read(&po->mapped));
8502 -       }
8503 -
8504 -       spin_lock(&po->bind_lock);
8505 -       if (was_running && !po->running) {
8506 -               sock_hold(sk);
8507 -               po->running = 1;
8508 -               po->num = num;
8509 -               dev_add_pack(&po->prot_hook);
8510 -       }
8511 -       spin_unlock(&po->bind_lock);
8512 -
8513 -       release_sock(sk);
8514 -
8515 -       if (pg_vec)
8516 -               free_pg_vec(pg_vec, order, req->tp_block_nr);
8517 -out:
8518 -       return err;
8519 -}
8520 -
8521 -static int packet_mmap(struct file *file, struct socket *sock, struct vm_area_struct *vma)
8522 -{
8523 -       struct sock *sk = sock->sk;
8524 -       struct packet_sock *po = pkt_sk(sk);
8525 -       unsigned long size;
8526 -       unsigned long start;
8527 -       int err = -EINVAL;
8528 -       int i;
8529 -
8530 -       if (vma->vm_pgoff)
8531 -               return -EINVAL;
8532 -
8533 -       size = vma->vm_end - vma->vm_start;
8534 -
8535 -       lock_sock(sk);
8536 -       if (po->pg_vec == NULL)
8537 -               goto out;
8538 -       if (size != po->pg_vec_len*po->pg_vec_pages*PAGE_SIZE)
8539 -               goto out;
8540 -
8541 -       start = vma->vm_start;
8542 -       for (i = 0; i < po->pg_vec_len; i++) {
8543 -               struct page *page = virt_to_page(po->pg_vec[i]);
8544 -               int pg_num;
8545 -
8546 -               for (pg_num = 0; pg_num < po->pg_vec_pages; pg_num++, page++) {
8547 -                       err = vm_insert_page(vma, start, page);
8548 -                       if (unlikely(err))
8549 -                               goto out;
8550 -                       start += PAGE_SIZE;
8551 -               }
8552 -       }
8553 -       atomic_inc(&po->mapped);
8554 -       vma->vm_ops = &packet_mmap_ops;
8555 -       err = 0;
8556 -
8557 -out:
8558 -       release_sock(sk);
8559 -       return err;
8560 -}
8561 -#endif
8562 -
8563 -
8564 -static const struct proto_ops packet_ops_spkt = {
8565 -       .family =       PF_PACKET,
8566 -       .owner =        THIS_MODULE,
8567 -       .release =      packet_release,
8568 -       .bind =         packet_bind_spkt,
8569 -       .connect =      sock_no_connect,
8570 -       .socketpair =   sock_no_socketpair,
8571 -       .accept =       sock_no_accept,
8572 -       .getname =      packet_getname_spkt,
8573 -       .poll =         datagram_poll,
8574 -       .ioctl =        packet_ioctl,
8575 -       .listen =       sock_no_listen,
8576 -       .shutdown =     sock_no_shutdown,
8577 -       .setsockopt =   sock_no_setsockopt,
8578 -       .getsockopt =   sock_no_getsockopt,
8579 -       .sendmsg =      packet_sendmsg_spkt,
8580 -       .recvmsg =      packet_recvmsg,
8581 -       .mmap =         sock_no_mmap,
8582 -       .sendpage =     sock_no_sendpage,
8583 -};
8584 -
8585 -static const struct proto_ops packet_ops = {
8586 -       .family =       PF_PACKET,
8587 -       .owner =        THIS_MODULE,
8588 -       .release =      packet_release,
8589 -       .bind =         packet_bind,
8590 -       .connect =      sock_no_connect,
8591 -       .socketpair =   sock_no_socketpair,
8592 -       .accept =       sock_no_accept,
8593 -       .getname =      packet_getname,
8594 -       .poll =         packet_poll,
8595 -       .ioctl =        packet_ioctl,
8596 -       .listen =       sock_no_listen,
8597 -       .shutdown =     sock_no_shutdown,
8598 -       .setsockopt =   packet_setsockopt,
8599 -       .getsockopt =   packet_getsockopt,
8600 -       .sendmsg =      packet_sendmsg,
8601 -       .recvmsg =      packet_recvmsg,
8602 -       .mmap =         packet_mmap,
8603 -       .sendpage =     sock_no_sendpage,
8604 -};
8605 -
8606 -static struct net_proto_family packet_family_ops = {
8607 -       .family =       PF_PACKET,
8608 -       .create =       packet_create,
8609 -       .owner  =       THIS_MODULE,
8610 -};
8611 -
8612 -static struct notifier_block packet_netdev_notifier = {
8613 -       .notifier_call =packet_notifier,
8614 -};
8615 -
8616 -#ifdef CONFIG_PROC_FS
8617 -static inline struct sock *packet_seq_idx(loff_t off)
8618 -{
8619 -       struct sock *s;
8620 -       struct hlist_node *node;
8621 -
8622 -       sk_for_each(s, node, &packet_sklist) {
8623 -               if (!off--)
8624 -                       return s;
8625 -       }
8626 -       return NULL;
8627 -}
8628 -
8629 -static void *packet_seq_start(struct seq_file *seq, loff_t *pos)
8630 -{
8631 -       read_lock(&packet_sklist_lock);
8632 -       return *pos ? packet_seq_idx(*pos - 1) : SEQ_START_TOKEN;
8633 -}
8634 -
8635 -static void *packet_seq_next(struct seq_file *seq, void *v, loff_t *pos)
8636 -{
8637 -       ++*pos;
8638 -       return  (v == SEQ_START_TOKEN)
8639 -               ? sk_head(&packet_sklist)
8640 -               : sk_next((struct sock*)v) ;
8641 -}
8642 -
8643 -static void packet_seq_stop(struct seq_file *seq, void *v)
8644 -{
8645 -       read_unlock(&packet_sklist_lock);
8646 -}
8647 -
8648 -static int packet_seq_show(struct seq_file *seq, void *v)
8649 -{
8650 -       if (v == SEQ_START_TOKEN)
8651 -               seq_puts(seq, "sk       RefCnt Type Proto  Iface R Rmem   User   Inode\n");
8652 -       else {
8653 -               struct sock *s = v;
8654 -               const struct packet_sock *po = pkt_sk(s);
8655 -
8656 -               seq_printf(seq,
8657 -                          "%p %-6d %-4d %04x   %-5d %1d %-6u %-6u %-6lu\n",
8658 -                          s,
8659 -                          atomic_read(&s->sk_refcnt),
8660 -                          s->sk_type,
8661 -                          ntohs(po->num),
8662 -                          po->ifindex,
8663 -                          po->running,
8664 -                          atomic_read(&s->sk_rmem_alloc),
8665 -                          sock_i_uid(s),
8666 -                          sock_i_ino(s) );
8667 -       }
8668 -
8669 -       return 0;
8670 -}
8671 -
8672 -static struct seq_operations packet_seq_ops = {
8673 -       .start  = packet_seq_start,
8674 -       .next   = packet_seq_next,
8675 -       .stop   = packet_seq_stop,
8676 -       .show   = packet_seq_show,
8677 -};
8678 -
8679 -static int packet_seq_open(struct inode *inode, struct file *file)
8680 -{
8681 -       return seq_open(file, &packet_seq_ops);
8682 -}
8683 -
8684 -static const struct file_operations packet_seq_fops = {
8685 -       .owner          = THIS_MODULE,
8686 -       .open           = packet_seq_open,
8687 -       .read           = seq_read,
8688 -       .llseek         = seq_lseek,
8689 -       .release        = seq_release,
8690 -};
8691 -
8692 -#endif
8693 -
8694 -static void __exit packet_exit(void)
8695 -{
8696 -       proc_net_remove("packet");
8697 -       unregister_netdevice_notifier(&packet_netdev_notifier);
8698 -       sock_unregister(PF_PACKET);
8699 -       proto_unregister(&packet_proto);
8700 -}
8701 -
8702 -static int __init packet_init(void)
8703 -{
8704 -       int rc = proto_register(&packet_proto, 0);
8705 -
8706 -       if (rc != 0)
8707 -               goto out;
8708 -
8709 -       sock_register(&packet_family_ops);
8710 -       register_netdevice_notifier(&packet_netdev_notifier);
8711 -       proc_net_fops_create("packet", 0, &packet_seq_fops);
8712 -out:
8713 -       return rc;
8714 -}
8715 -
8716 -module_init(packet_init);
8717 -module_exit(packet_exit);
8718 -MODULE_LICENSE("GPL");
8719 -MODULE_ALIAS_NETPROTO(PF_PACKET);
8720 diff -Nurb linux-2.6.22-594/net/socket.c linux-2.6.22-595/net/socket.c
8721 --- linux-2.6.22-594/net/socket.c       2008-03-20 01:27:52.000000000 -0400
8722 +++ linux-2.6.22-595/net/socket.c       2008-03-20 01:28:00.000000000 -0400
8723 @@ -1122,12 +1122,17 @@
8724         if (type < 0 || type >= SOCK_MAX)
8725                 return -EINVAL;
8726  
8727 +       /*
8728 +        * Hack no. 2 - Sapan
8729 +        * Clean this up later
8730 +        *
8731         if (!nx_check(0, VS_ADMIN)) {
8732                 if (family == PF_INET && !current_nx_info_has_v4())
8733                         return -EAFNOSUPPORT;
8734                 if (family == PF_INET6 && !current_nx_info_has_v6())
8735                         return -EAFNOSUPPORT;
8736         }
8737 +       */
8738  
8739         /* Compatibility.
8740