1 diff --unified --recursive --new-file linux-2.4.30/include/linux/ring.h linux-2.4.30-1-686-smp-ring3/include/linux/ring.h
2 --- linux-2.4.30/include/linux/ring.h 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-2.4.30-1-686-smp-ring3/include/linux/ring.h 2005-10-22 23:08:27.388011250 +0200
6 + * Definitions for packet ring
8 + * 2004 - Luca Deri <deri@ntop.org>
14 +#define INCLUDE_MAC_INFO
16 +#ifdef INCLUDE_MAC_INFO
17 +#define SKB_DISPLACEMENT 14 /* Include MAC address information */
19 +#define SKB_DISPLACEMENT 0 /* Do NOT include MAC address information */
23 +#define RING_MAGIC_VALUE 0x88
24 +#define RING_FLOWSLOT_VERSION 5
25 +#define RING_VERSION "3.0"
27 +#define SO_ADD_TO_CLUSTER 99
28 +#define SO_REMOVE_FROM_CLUSTER 100
29 +#define SO_SET_REFLECTOR 101
31 +/* *********************************** */
35 + struct timeval ts; /* time stamp */
36 + u_int32_t caplen; /* length of portion present */
37 + u_int32_t len; /* length this packet (off wire) */
41 +/* *********************************** */
44 + cluster_per_flow = 0,
48 +/* *********************************** */
50 +#define RING_MIN_SLOT_SIZE (60+sizeof(struct pcap_pkthdr))
51 +#define RING_MAX_SLOT_SIZE (1514+sizeof(struct pcap_pkthdr))
53 +/* *********************************** */
55 +typedef struct flowSlotInfo {
56 + u_int16_t version, sample_rate;
57 + u_int32_t tot_slots, slot_len, tot_mem;
59 + u_int64_t tot_pkts, tot_lost;
60 + u_int64_t tot_insert, tot_read;
61 + u_int16_t insert_idx;
62 + u_int16_t remove_idx;
65 +/* *********************************** */
67 +typedef struct flowSlot {
69 + u_char magic; /* It must alwasy be zero */
71 + u_char slot_state; /* 0=empty, 1=full */
72 + u_char bucket; /* bucket[bucketLen] */
75 +/* *********************************** */
79 +FlowSlotInfo* getRingPtr(void);
80 +int allocateRing(char *deviceName, u_int numSlots,
81 + u_int bucketLen, u_int sampleRate);
82 +unsigned int pollRing(struct file *fp, struct poll_table_struct * wait);
83 +void deallocateRing(void);
85 +/* ************************* */
87 +typedef int (*handle_ring_skb)(struct sk_buff *skb,
88 + u_char recv_packet, u_char real_skb);
89 +extern handle_ring_skb get_skb_ring_handler(void);
90 +extern void set_skb_ring_handler(handle_ring_skb the_handler);
91 +extern void do_skb_ring_handler(struct sk_buff *skb,
92 + u_char recv_packet, u_char real_skb);
94 +typedef int (*handle_ring_buffer)(struct net_device *dev,
95 + char *data, int len);
96 +extern handle_ring_buffer get_buffer_ring_handler(void);
97 +extern void set_buffer_ring_handler(handle_ring_buffer the_handler);
98 +extern int do_buffer_ring_handler(struct net_device *dev,
99 + char *data, int len);
100 +#endif /* __KERNEL__ */
102 +/* *********************************** */
104 +#define PF_RING 27 /* Packet Ring */
105 +#define SOCK_RING PF_RING
108 +#define SIORINGPOLL 0x8888
110 +/* *********************************** */
112 +#endif /* __RING_H */
113 diff --unified --recursive --new-file linux-2.4.30/include/net/sock.h linux-2.4.30-1-686-smp-ring3/include/net/sock.h
114 --- linux-2.4.30/include/net/sock.h 2004-11-17 12:54:22.000000000 +0100
115 +++ linux-2.4.30-1-686-smp-ring3/include/net/sock.h 2005-10-22 23:08:27.976048000 +0200
117 #if defined (CONFIG_PACKET) || defined(CONFIG_PACKET_MODULE)
118 struct packet_opt *af_packet;
120 +#if defined(CONFIG_RING) || defined(CONFIG_RING_MODULE)
121 + struct ring_opt *pf_ring;
123 #if defined(CONFIG_X25) || defined(CONFIG_X25_MODULE)
126 diff --unified --recursive --new-file linux-2.4.30/include/net/sock.h.ORG linux-2.4.30-1-686-smp-ring3/include/net/sock.h.ORG
127 --- linux-2.4.30/include/net/sock.h.ORG 1970-01-01 01:00:00.000000000 +0100
128 +++ linux-2.4.30-1-686-smp-ring3/include/net/sock.h.ORG 2005-10-22 23:08:27.940045750 +0200
131 + * INET An implementation of the TCP/IP protocol suite for the LINUX
132 + * operating system. INET is implemented using the BSD Socket
133 + * interface as the means of communication with the user level.
135 + * Definitions for the AF_INET socket handler.
137 + * Version: @(#)sock.h 1.0.4 05/13/93
139 + * Authors: Ross Biro, <bir7@leland.Stanford.Edu>
140 + * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
141 + * Corey Minyard <wf-rch!minyard@relay.EU.net>
142 + * Florian La Roche <flla@stud.uni-sb.de>
145 + * Alan Cox : Volatiles in skbuff pointers. See
146 + * skbuff comments. May be overdone,
147 + * better to prove they can be removed
148 + * than the reverse.
149 + * Alan Cox : Added a zapped field for tcp to note
150 + * a socket is reset and must stay shut up
151 + * Alan Cox : New fields for options
152 + * Pauline Middelink : identd support
153 + * Alan Cox : Eliminate low level recv/recvfrom
154 + * David S. Miller : New socket lookup architecture.
155 + * Steve Whitehouse: Default routines for sock_ops
157 + * This program is free software; you can redistribute it and/or
158 + * modify it under the terms of the GNU General Public License
159 + * as published by the Free Software Foundation; either version
160 + * 2 of the License, or (at your option) any later version.
165 +#include <linux/config.h>
166 +#include <linux/timer.h>
167 +#include <linux/cache.h>
168 +#include <linux/in.h> /* struct sockaddr_in */
170 +#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
171 +#include <linux/in6.h> /* struct sockaddr_in6 */
172 +#include <linux/ipv6.h> /* dest_cache, inet6_options */
173 +#include <linux/icmpv6.h>
174 +#include <net/if_inet6.h> /* struct ipv6_mc_socklist */
177 +#if defined(CONFIG_INET) || defined (CONFIG_INET_MODULE)
178 +#include <linux/icmp.h>
180 +#include <linux/tcp.h> /* struct tcphdr */
181 +#if defined(CONFIG_IP_SCTP) || defined (CONFIG_IP_SCTP_MODULE)
182 +#include <net/sctp/structs.h> /* struct sctp_opt */
185 +#include <linux/netdevice.h>
186 +#include <linux/skbuff.h> /* struct sk_buff */
187 +#include <net/protocol.h> /* struct inet_protocol */
188 +#if defined(CONFIG_X25) || defined(CONFIG_X25_MODULE)
189 +#include <net/x25.h>
191 +#if defined(CONFIG_WAN_ROUTER) || defined(CONFIG_WAN_ROUTER_MODULE)
192 +#include <linux/if_wanpipe.h>
195 +#if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
196 +#include <net/ax25.h>
197 +#if defined(CONFIG_NETROM) || defined(CONFIG_NETROM_MODULE)
198 +#include <net/netrom.h>
200 +#if defined(CONFIG_ROSE) || defined(CONFIG_ROSE_MODULE)
201 +#include <net/rose.h>
205 +#if defined(CONFIG_PPPOE) || defined(CONFIG_PPPOE_MODULE)
206 +#include <linux/if_pppox.h>
207 +#include <linux/ppp_channel.h> /* struct ppp_channel */
210 +#if defined(CONFIG_IPX) || defined(CONFIG_IPX_MODULE)
211 +#if defined(CONFIG_SPX) || defined(CONFIG_SPX_MODULE)
212 +#include <net/spx.h>
214 +#include <net/ipx.h>
215 +#endif /* CONFIG_SPX */
216 +#endif /* CONFIG_IPX */
218 +#if defined(CONFIG_ATALK) || defined(CONFIG_ATALK_MODULE)
219 +#include <linux/atalk.h>
222 +#if defined(CONFIG_DECNET) || defined(CONFIG_DECNET_MODULE)
226 +#if defined(CONFIG_IRDA) || defined(CONFIG_IRDA_MODULE)
227 +#include <net/irda/irda.h>
230 +#if defined(CONFIG_ATM) || defined(CONFIG_ATM_MODULE)
234 +#ifdef CONFIG_FILTER
235 +#include <linux/filter.h>
238 +#include <asm/atomic.h>
239 +#include <net/dst.h>
242 +/* The AF_UNIX specific socket options */
244 + struct unix_address *addr;
245 + struct dentry * dentry;
246 + struct vfsmount * mnt;
247 + struct semaphore readsem;
248 + struct sock * other;
249 + struct sock ** list;
250 + struct sock * gc_tree;
253 + wait_queue_head_t peer_wait;
257 +/* Once the IPX ncpd patches are in these are going into protinfo. */
258 +#if defined(CONFIG_IPX) || defined(CONFIG_IPX_MODULE)
260 + ipx_address dest_addr;
261 + ipx_interface *intrfc;
262 + unsigned short port;
263 +#ifdef CONFIG_IPX_INTERN
264 + unsigned char node[IPX_NODE_LEN];
266 + unsigned short type;
268 + * To handle special ncp connection-handling sockets for mars_nwe,
269 + * the connection number must be stored in the socket.
271 + unsigned short ipx_ncp_conn;
275 +#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
277 + struct in6_addr saddr;
278 + struct in6_addr rcv_saddr;
279 + struct in6_addr daddr;
280 + struct in6_addr *daddr_cache;
288 + /* pktoption flags */
302 + /* sockopt flags */
309 + struct ipv6_mc_socklist *ipv6_mc_list;
310 + struct ipv6_ac_socklist *ipv6_ac_list;
311 + struct ipv6_fl_socklist *ipv6_fl_list;
314 + struct ipv6_txoptions *opt;
315 + struct sk_buff *pktoptions;
319 + __u32 checksum; /* perform checksum */
320 + __u32 offset; /* checksum offset */
322 + struct icmp6_filter filter;
325 +#define __ipv6_only_sock(sk) ((sk)->net_pinfo.af_inet6.ipv6only)
326 +#define ipv6_only_sock(sk) ((sk)->family == PF_INET6 && \
327 + (sk)->net_pinfo.af_inet6.ipv6only)
329 +#define __ipv6_only_sock(sk) 0
330 +#define ipv6_only_sock(sk) 0
333 +#if defined(CONFIG_INET) || defined(CONFIG_INET_MODULE)
335 + struct icmp_filter filter;
339 +#if defined(CONFIG_INET) || defined (CONFIG_INET_MODULE)
342 + int ttl; /* TTL setting */
344 + unsigned cmsg_flags;
345 + struct ip_options *opt;
346 + unsigned char hdrincl; /* Include headers ? */
347 + __u8 mc_ttl; /* Multicasting TTL */
348 + __u8 mc_loop; /* Loopback */
349 + unsigned recverr : 1,
351 + __u16 id; /* ID counter for DF pkts */
353 + int mc_index; /* Multicast device index */
355 + struct ip_mc_socklist *mc_list; /* Group array */
359 +#if defined(CONFIG_PPPOE) || defined (CONFIG_PPPOE_MODULE)
362 + struct net_device *dev; /* device associated with socket*/
363 + struct pppoe_addr pa; /* what this socket is bound to*/
364 + struct sockaddr_pppox relay; /* what socket data will be
365 + relayed to (PPPoE relaying) */
370 + struct ppp_channel chan;
372 + struct pppox_opt *next; /* for hash table */
374 + struct pppoe_opt pppoe;
377 +#define pppoe_dev proto.pppoe.dev
378 +#define pppoe_pa proto.pppoe.pa
379 +#define pppoe_relay proto.pppoe.relay
382 +/* This defines a selective acknowledgement block. */
383 +struct tcp_sack_block {
388 +enum tcp_congestion_algo {
396 + int tcp_header_len; /* Bytes of tcp header to send */
399 + * Header prediction flags
400 + * 0x5?10 << 16 + snd_wnd in net byte order
405 + * RFC793 variables by their proper names. This means you can
406 + * read the code and the spec side by side (and laugh ...)
407 + * See RFC793 and RFC1122. The RFC writes these in capitals.
409 + __u32 rcv_nxt; /* What we want to receive next */
410 + __u32 snd_nxt; /* Next sequence we send */
412 + __u32 snd_una; /* First byte we want an ack for */
413 + __u32 snd_sml; /* Last byte of the most recently transmitted small packet */
414 + __u32 rcv_tstamp; /* timestamp of last received ACK (for keepalives) */
415 + __u32 lsndtime; /* timestamp of last sent data packet (for restart window) */
417 + /* Delayed ACK control data */
419 + __u8 pending; /* ACK is pending */
420 + __u8 quick; /* Scheduled number of quick acks */
421 + __u8 pingpong; /* The session is interactive */
422 + __u8 blocked; /* Delayed ACK was blocked by socket lock*/
423 + __u32 ato; /* Predicted tick of soft clock */
424 + unsigned long timeout; /* Currently scheduled timeout */
425 + __u32 lrcvtime; /* timestamp of last received data packet*/
426 + __u16 last_seg_size; /* Size of last incoming segment */
427 + __u16 rcv_mss; /* MSS used for delayed ACK decisions */
430 + /* Data for direct copy to user */
432 + struct sk_buff_head prequeue;
433 + struct task_struct *task;
439 + __u32 snd_wl1; /* Sequence for window update */
440 + __u32 snd_wnd; /* The window we expect to receive */
441 + __u32 max_window; /* Maximal window ever seen from peer */
442 + __u32 pmtu_cookie; /* Last pmtu seen by socket */
443 + __u16 mss_cache; /* Cached effective mss, not including SACKS */
444 + __u16 mss_clamp; /* Maximal mss, negotiated at connection setup */
445 + __u16 ext_header_len; /* Network protocol overhead (IP/IPv6 options) */
446 + __u8 ca_state; /* State of fast-retransmit machine */
447 + __u8 retransmits; /* Number of unrecovered RTO timeouts. */
449 + __u8 reordering; /* Packet reordering metric. */
450 + __u8 queue_shrunk; /* Write queue has been shrunk recently.*/
451 + __u8 defer_accept; /* User waits for some data after accept() */
453 +/* RTT measurement */
454 + __u8 backoff; /* backoff */
455 + __u32 srtt; /* smothed round trip time << 3 */
456 + __u32 mdev; /* medium deviation */
457 + __u32 mdev_max; /* maximal mdev for the last rtt period */
458 + __u32 rttvar; /* smoothed mdev_max */
459 + __u32 rtt_seq; /* sequence number to update rttvar */
460 + __u32 rto; /* retransmit timeout */
462 + __u32 packets_out; /* Packets which are "in flight" */
463 + __u32 left_out; /* Packets which leaved network */
464 + __u32 retrans_out; /* Retransmitted packets out */
468 + * Slow start and congestion control (see also Nagle, and Karn & Partridge)
470 + __u32 snd_ssthresh; /* Slow start size threshold */
471 + __u32 snd_cwnd; /* Sending congestion window */
472 + __u16 snd_cwnd_cnt; /* Linear increase counter */
473 + __u16 snd_cwnd_clamp; /* Do not allow snd_cwnd to grow above this */
474 + __u32 snd_cwnd_used;
475 + __u32 snd_cwnd_stamp;
477 + /* Two commonly used timers in both sender and receiver paths. */
478 + unsigned long timeout;
479 + struct timer_list retransmit_timer; /* Resend (no ack) */
480 + struct timer_list delack_timer; /* Ack delay */
482 + struct sk_buff_head out_of_order_queue; /* Out of order segments go here */
484 + struct tcp_func *af_specific; /* Operations which are AF_INET{4,6} specific */
485 + struct sk_buff *send_head; /* Front of stuff to transmit */
486 + struct page *sndmsg_page; /* Cached page for sendmsg */
487 + u32 sndmsg_off; /* Cached offset for sendmsg */
489 + __u32 rcv_wnd; /* Current receiver window */
490 + __u32 rcv_wup; /* rcv_nxt on last window update sent */
491 + __u32 write_seq; /* Tail(+1) of data held in tcp send buffer */
492 + __u32 pushed_seq; /* Last pushed seq, required to talk to windows */
493 + __u32 copied_seq; /* Head of yet unread data */
495 + * Options received (usually on last packet, some only on SYN packets).
497 + char tstamp_ok, /* TIMESTAMP seen on SYN packet */
498 + wscale_ok, /* Wscale seen on SYN packet */
499 + sack_ok; /* SACK seen on SYN packet */
500 + char saw_tstamp; /* Saw TIMESTAMP on last packet */
501 + __u8 snd_wscale; /* Window scaling received from sender */
502 + __u8 rcv_wscale; /* Window scaling to send to receiver */
503 + __u8 nonagle; /* Disable Nagle algorithm? */
504 + __u8 keepalive_probes; /* num of allowed keep alive probes */
506 +/* PAWS/RTTM data */
507 + __u32 rcv_tsval; /* Time stamp value */
508 + __u32 rcv_tsecr; /* Time stamp echo reply */
509 + __u32 ts_recent; /* Time stamp to echo next */
510 + long ts_recent_stamp;/* Time we stored ts_recent (for aging) */
513 + __u16 user_mss; /* mss requested by user in ioctl */
514 + __u8 dsack; /* D-SACK is scheduled */
515 + __u8 eff_sacks; /* Size of SACK array to send with next packet */
516 + struct tcp_sack_block duplicate_sack[1]; /* D-SACK block */
517 + struct tcp_sack_block selective_acks[4]; /* The SACKS themselves*/
519 + __u32 window_clamp; /* Maximal window to advertise */
520 + __u32 rcv_ssthresh; /* Current window clamp */
521 + __u8 probes_out; /* unanswered 0 window probes */
522 + __u8 num_sacks; /* Number of SACK blocks */
523 + __u16 advmss; /* Advertised MSS */
525 + __u8 syn_retries; /* num of allowed syn retries */
526 + __u8 ecn_flags; /* ECN status bits. */
527 + __u16 prior_ssthresh; /* ssthresh saved at recovery start */
528 + __u32 lost_out; /* Lost packets */
529 + __u32 sacked_out; /* SACK'd packets */
530 + __u32 fackets_out; /* FACK'd packets */
531 + __u32 high_seq; /* snd_nxt at onset of congestion */
533 + __u32 retrans_stamp; /* Timestamp of the last retransmit,
534 + * also used in SYN-SENT to remember stamp of
535 + * the first SYN. */
536 + __u32 undo_marker; /* tracking retrans started here. */
537 + int undo_retrans; /* number of undoable retransmissions. */
538 + __u32 urg_seq; /* Seq of received urgent pointer */
539 + __u16 urg_data; /* Saved octet of OOB data and control flags */
540 + __u8 pending; /* Scheduled timer event */
541 + __u8 urg_mode; /* In urgent mode */
542 + __u32 snd_up; /* Urgent pointer */
544 + /* The syn_wait_lock is necessary only to avoid tcp_get_info having
545 + * to grab the main lock sock while browsing the listening hash
546 + * (otherwise it's deadlock prone).
547 + * This lock is acquired in read mode only from tcp_get_info() and
548 + * it's acquired in write mode _only_ from code that is actively
549 + * changing the syn_wait_queue. All readers that are holding
550 + * the master sock lock don't need to grab this lock in read mode
551 + * too as the syn_wait_queue writes are always protected from
552 + * the main sock lock.
554 + rwlock_t syn_wait_lock;
555 + struct tcp_listen_opt *listen_opt;
557 + /* FIFO of established children */
558 + struct open_request *accept_queue;
559 + struct open_request *accept_queue_tail;
561 + int write_pending; /* A write to socket waits to start. */
563 + unsigned int keepalive_time; /* time before keep alive takes place */
564 + unsigned int keepalive_intvl; /* time interval between keep alive probes */
567 + __u8 adv_cong; /* Using Vegas, Westwood, or BIC */
568 + __u8 frto_counter; /* Number of new acks after RTO */
569 + __u32 frto_highmark; /* snd_nxt when RTO occurred */
571 + unsigned long last_synq_overflow;
573 +/* Receiver side RTT estimation */
580 +/* Receiver queue space */
587 +/* TCP Westwood structure */
589 + __u32 bw_ns_est; /* first bandwidth estimation..not too smoothed 8) */
590 + __u32 bw_est; /* bandwidth estimate */
591 + __u32 rtt_win_sx; /* here starts a new evaluation... */
593 + __u32 snd_una; /* used for evaluating the number of acked bytes */
597 + __u32 rtt_min; /* minimum observed RTT */
600 +/* Vegas variables */
602 + __u32 beg_snd_nxt; /* right edge during last RTT */
603 + __u32 beg_snd_una; /* left edge during last RTT */
604 + __u32 beg_snd_cwnd; /* saves the size of the cwnd */
605 + __u8 doing_vegas_now;/* if true, do vegas for this RTT */
606 + __u16 cntRTT; /* # of RTTs measured within last RTT */
607 + __u32 minRTT; /* min of RTTs measured within last RTT (in usec) */
608 + __u32 baseRTT; /* the min of all Vegas RTT measurements seen (in usec) */
611 + /* BI TCP Parameters */
613 + __u32 cnt; /* increase cwnd by 1 after this number of ACKs */
614 + __u32 last_max_cwnd; /* last maximium snd_cwnd */
615 + __u32 last_cwnd; /* the last snd_cwnd */
616 + __u32 last_stamp; /* time when updated last_cwnd */
622 + * This structure really needs to be cleaned up.
623 + * Most of it is for TCP, and not used by any of
624 + * the other protocols.
628 + * The idea is to start moving to a newer struct gradualy
630 + * IMHO the newer struct should have the following format:
633 + * sockmem [mem, proto, callbacks]
635 + * union or struct {
657 + * The idea failed because IPv6 transition asssumes dual IP/IPv6 sockets.
658 + * So, net_pinfo is IPv6 are really, and protinfo unifies all another
662 +/* Define this to get the sk->debug debugging facility. */
663 +#define SOCK_DEBUGGING
664 +#ifdef SOCK_DEBUGGING
665 +#define SOCK_DEBUG(sk, msg...) do { if((sk) && ((sk)->debug)) printk(KERN_DEBUG msg); } while (0)
667 +#define SOCK_DEBUG(sk, msg...) do { } while (0)
670 +/* This is the per-socket lock. The spinlock provides a synchronization
671 + * between user contexts and software interrupt processing, whereas the
672 + * mini-semaphore synchronizes multiple users amongst themselves.
676 + unsigned int users;
677 + wait_queue_head_t wq;
680 +#define sock_lock_init(__sk) \
681 +do { spin_lock_init(&((__sk)->lock.slock)); \
682 + (__sk)->lock.users = 0; \
683 + init_waitqueue_head(&((__sk)->lock.wq)); \
687 + /* Socket demultiplex comparisons on incoming packets. */
688 + __u32 daddr; /* Foreign IPv4 addr */
689 + __u32 rcv_saddr; /* Bound local IPv4 addr */
690 + __u16 dport; /* Destination port */
691 + unsigned short num; /* Local port */
692 + int bound_dev_if; /* Bound device index if != 0 */
694 + /* Main hash linkage for various protocol lookup tables. */
696 + struct sock **pprev;
697 + struct sock *bind_next;
698 + struct sock **bind_pprev;
700 + volatile unsigned char state, /* Connection state */
701 + zapped; /* In ax25 & ipx means not linked */
702 + __u16 sport; /* Source port */
704 + unsigned short family; /* Address family */
705 + unsigned char reuse; /* SO_REUSEADDR setting */
706 + unsigned char shutdown;
707 + atomic_t refcnt; /* Reference count */
709 + socket_lock_t lock; /* Synchronizer... */
710 + int rcvbuf; /* Size of receive buffer in bytes */
712 + wait_queue_head_t *sleep; /* Sock wait queue */
713 + struct dst_entry *dst_cache; /* Destination cache */
715 + atomic_t rmem_alloc; /* Receive queue bytes committed */
716 + struct sk_buff_head receive_queue; /* Incoming packets */
717 + atomic_t wmem_alloc; /* Transmit queue bytes committed */
718 + struct sk_buff_head write_queue; /* Packet sending queue */
719 + atomic_t omem_alloc; /* "o" is "option" or "other" */
720 + int wmem_queued; /* Persistent queue size */
721 + int forward_alloc; /* Space allocated forward. */
722 + __u32 saddr; /* Sending source */
723 + unsigned int allocation; /* Allocation mode */
724 + int sndbuf; /* Size of send buffer in bytes */
727 + /* Not all are volatile, but some are, so we might as well say they all are.
728 + * XXX Make this a flag word -DaveM
730 + volatile char dead,
739 + unsigned char debug;
740 + unsigned char rcvtstamp;
741 + unsigned char use_write_queue;
742 + unsigned char userlocks;
743 + /* Hole of 3 bytes. Try to pack. */
746 + unsigned long lingertime;
751 + /* The backlog queue is special, it is always used with
752 + * the per-socket spinlock held and requires low latency
753 + * access. Therefore we special case it's implementation.
756 + struct sk_buff *head;
757 + struct sk_buff *tail;
760 + rwlock_t callback_lock;
762 + /* Error queue, rarely used. */
763 + struct sk_buff_head error_queue;
765 + struct proto *prot;
767 +#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
769 + struct ipv6_pinfo af_inet6;
774 + struct tcp_opt af_tcp;
775 +#if defined(CONFIG_IP_SCTP) || defined (CONFIG_IP_SCTP_MODULE)
776 + struct sctp_opt af_sctp;
778 +#if defined(CONFIG_INET) || defined (CONFIG_INET_MODULE)
779 + struct raw_opt tp_raw4;
781 +#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
782 + struct raw6_opt tp_raw;
783 +#endif /* CONFIG_IPV6 */
784 +#if defined(CONFIG_SPX) || defined (CONFIG_SPX_MODULE)
785 + struct spx_opt af_spx;
786 +#endif /* CONFIG_SPX */
790 + int err, err_soft; /* Soft holds errors that don't
791 + cause failure but are the cause
792 + of a persistent failure not just
794 + unsigned short ack_backlog;
795 + unsigned short max_ack_backlog;
797 + unsigned short type;
798 + unsigned char localroute; /* Route locally only */
799 + unsigned char protocol;
800 + struct ucred peercred;
805 +#ifdef CONFIG_FILTER
806 + /* Socket Filtering Instructions */
807 + struct sk_filter *filter;
808 +#endif /* CONFIG_FILTER */
810 + /* This is where all the private (optional) areas that don't
811 + * overlap will eventually live.
814 + void *destruct_hook;
815 + struct unix_opt af_unix;
816 +#if defined(CONFIG_INET) || defined (CONFIG_INET_MODULE)
817 + struct inet_opt af_inet;
819 +#if defined(CONFIG_ATALK) || defined(CONFIG_ATALK_MODULE)
820 + struct atalk_sock af_at;
822 +#if defined(CONFIG_IPX) || defined(CONFIG_IPX_MODULE)
823 + struct ipx_opt af_ipx;
825 +#if defined (CONFIG_DECNET) || defined(CONFIG_DECNET_MODULE)
828 +#if defined (CONFIG_PACKET) || defined(CONFIG_PACKET_MODULE)
829 + struct packet_opt *af_packet;
831 +#if defined(CONFIG_X25) || defined(CONFIG_X25_MODULE)
834 +#if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
837 +#if defined(CONFIG_NETROM) || defined(CONFIG_NETROM_MODULE)
840 +#if defined(CONFIG_ROSE) || defined(CONFIG_ROSE_MODULE)
843 +#if defined(CONFIG_PPPOE) || defined(CONFIG_PPPOE_MODULE)
844 + struct pppox_opt *pppox;
846 + struct netlink_opt *af_netlink;
847 +#if defined(CONFIG_ECONET) || defined(CONFIG_ECONET_MODULE)
848 + struct econet_opt *af_econet;
850 +#if defined(CONFIG_ATM) || defined(CONFIG_ATM_MODULE)
851 + struct atm_vcc *af_atm;
853 +#if defined(CONFIG_IRDA) || defined(CONFIG_IRDA_MODULE)
854 + struct irda_sock *irda;
856 +#if defined(CONFIG_WAN_ROUTER) || defined(CONFIG_WAN_ROUTER_MODULE)
857 + struct wanpipe_opt *af_wanpipe;
862 + /* This part is used for the timeout functions. */
863 + struct timer_list timer; /* This is the sock cleanup timer. */
864 + struct timeval stamp;
866 + /* Identd and reporting IO signals */
867 + struct socket *socket;
869 + /* RPC layer private data */
873 + void (*state_change)(struct sock *sk);
874 + void (*data_ready)(struct sock *sk,int bytes);
875 + void (*write_space)(struct sock *sk);
876 + void (*error_report)(struct sock *sk);
878 + int (*backlog_rcv) (struct sock *sk,
879 + struct sk_buff *skb);
880 + void (*destruct)(struct sock *sk);
883 +/* The per-socket spinlock must be held here. */
884 +#define sk_add_backlog(__sk, __skb) \
885 +do { if((__sk)->backlog.tail == NULL) { \
886 + (__sk)->backlog.head = \
887 + (__sk)->backlog.tail = (__skb); \
889 + ((__sk)->backlog.tail)->next = (__skb); \
890 + (__sk)->backlog.tail = (__skb); \
892 + (__skb)->next = NULL; \
895 +/* IP protocol blocks we attach to sockets.
896 + * socket layer -> transport layer interface
897 + * transport -> network interface is defined by struct inet_proto
900 + void (*close)(struct sock *sk,
902 + int (*connect)(struct sock *sk,
903 + struct sockaddr *uaddr,
905 + int (*disconnect)(struct sock *sk, int flags);
907 + struct sock * (*accept) (struct sock *sk, int flags, int *err);
909 + int (*ioctl)(struct sock *sk, int cmd,
910 + unsigned long arg);
911 + int (*init)(struct sock *sk);
912 + int (*destroy)(struct sock *sk);
913 + void (*shutdown)(struct sock *sk, int how);
914 + int (*setsockopt)(struct sock *sk, int level,
915 + int optname, char *optval, int optlen);
916 + int (*getsockopt)(struct sock *sk, int level,
917 + int optname, char *optval,
919 + int (*sendmsg)(struct sock *sk, struct msghdr *msg,
921 + int (*recvmsg)(struct sock *sk, struct msghdr *msg,
922 + int len, int noblock, int flags,
924 + int (*bind)(struct sock *sk,
925 + struct sockaddr *uaddr, int addr_len);
927 + int (*backlog_rcv) (struct sock *sk,
928 + struct sk_buff *skb);
930 + /* Keeping track of sk's, looking them up, and port selection methods. */
931 + void (*hash)(struct sock *sk);
932 + void (*unhash)(struct sock *sk);
933 + int (*get_port)(struct sock *sk, unsigned short snum);
939 + u8 __pad[SMP_CACHE_BYTES - sizeof(int)];
943 +/* Called with local bh disabled */
944 +static __inline__ void sock_prot_inc_use(struct proto *prot)
946 + prot->stats[smp_processor_id()].inuse++;
949 +static __inline__ void sock_prot_dec_use(struct proto *prot)
951 + prot->stats[smp_processor_id()].inuse--;
954 +/* About 10 seconds */
955 +#define SOCK_DESTROY_TIME (10*HZ)
957 +/* Sockets 0-1023 can't be bound to unless you are superuser */
958 +#define PROT_SOCK 1024
960 +#define SHUTDOWN_MASK 3
961 +#define RCV_SHUTDOWN 1
962 +#define SEND_SHUTDOWN 2
964 +#define SOCK_SNDBUF_LOCK 1
965 +#define SOCK_RCVBUF_LOCK 2
966 +#define SOCK_BINDADDR_LOCK 4
967 +#define SOCK_BINDPORT_LOCK 8
970 +/* Used by processes to "lock" a socket state, so that
971 + * interrupts and bottom half handlers won't change it
972 + * from under us. It essentially blocks any incoming
973 + * packets, so that we won't get any new data or any
974 + * packets that change the state of the socket.
976 + * While locked, BH processing will add new packets to
977 + * the backlog queue. This queue is processed by the
978 + * owner of the socket lock right before it is released.
980 + * Since ~2.3.5 it is also exclusive sleep lock serializing
981 + * accesses from user process context.
983 +extern void __lock_sock(struct sock *sk);
984 +extern void __release_sock(struct sock *sk);
985 +#define lock_sock(__sk) \
986 +do { spin_lock_bh(&((__sk)->lock.slock)); \
987 + if ((__sk)->lock.users != 0) \
988 + __lock_sock(__sk); \
989 + (__sk)->lock.users = 1; \
990 + spin_unlock_bh(&((__sk)->lock.slock)); \
993 +#define release_sock(__sk) \
994 +do { spin_lock_bh(&((__sk)->lock.slock)); \
995 + if ((__sk)->backlog.tail != NULL) \
996 + __release_sock(__sk); \
997 + (__sk)->lock.users = 0; \
998 + if (waitqueue_active(&((__sk)->lock.wq))) wake_up(&((__sk)->lock.wq)); \
999 + spin_unlock_bh(&((__sk)->lock.slock)); \
1002 +/* BH context may only use the following locking interface. */
1003 +#define bh_lock_sock(__sk) spin_lock(&((__sk)->lock.slock))
1004 +#define bh_unlock_sock(__sk) spin_unlock(&((__sk)->lock.slock))
1006 +extern struct sock * sk_alloc(int family, int priority, int zero_it);
1007 +extern void sk_free(struct sock *sk);
1009 +extern struct sk_buff *sock_wmalloc(struct sock *sk,
1010 + unsigned long size, int force,
1012 +extern struct sk_buff *sock_rmalloc(struct sock *sk,
1013 + unsigned long size, int force,
1015 +extern void sock_wfree(struct sk_buff *skb);
1016 +extern void sock_rfree(struct sk_buff *skb);
1018 +extern int sock_setsockopt(struct socket *sock, int level,
1019 + int op, char *optval,
1022 +extern int sock_getsockopt(struct socket *sock, int level,
1023 + int op, char *optval,
1025 +extern struct sk_buff *sock_alloc_send_skb(struct sock *sk,
1026 + unsigned long size,
1029 +extern struct sk_buff *sock_alloc_send_pskb(struct sock *sk,
1030 + unsigned long header_len,
1031 + unsigned long data_len,
1034 +extern void *sock_kmalloc(struct sock *sk, int size, int priority);
1035 +extern void sock_kfree_s(struct sock *sk, void *mem, int size);
1038 + * Functions to fill in entries in struct proto_ops when a protocol
1039 + * does not implement a particular function.
1041 +extern int sock_no_release(struct socket *);
1042 +extern int sock_no_bind(struct socket *,
1043 + struct sockaddr *, int);
1044 +extern int sock_no_connect(struct socket *,
1045 + struct sockaddr *, int, int);
1046 +extern int sock_no_socketpair(struct socket *,
1048 +extern int sock_no_accept(struct socket *,
1049 + struct socket *, int);
1050 +extern int sock_no_getname(struct socket *,
1051 + struct sockaddr *, int *, int);
1052 +extern unsigned int sock_no_poll(struct file *, struct socket *,
1053 + struct poll_table_struct *);
1054 +extern int sock_no_ioctl(struct socket *, unsigned int,
1056 +extern int sock_no_listen(struct socket *, int);
1057 +extern int sock_no_shutdown(struct socket *, int);
1058 +extern int sock_no_getsockopt(struct socket *, int , int,
1060 +extern int sock_no_setsockopt(struct socket *, int, int,
1062 +extern int sock_no_fcntl(struct socket *,
1063 + unsigned int, unsigned long);
1064 +extern int sock_no_sendmsg(struct socket *,
1065 + struct msghdr *, int,
1066 + struct scm_cookie *);
1067 +extern int sock_no_recvmsg(struct socket *,
1068 + struct msghdr *, int, int,
1069 + struct scm_cookie *);
1070 +extern int sock_no_mmap(struct file *file,
1071 + struct socket *sock,
1072 + struct vm_area_struct *vma);
1073 +extern ssize_t sock_no_sendpage(struct socket *sock,
1074 + struct page *page,
1075 + int offset, size_t size,
1079 + * Default socket callbacks and setup code
1082 +extern void sock_def_destruct(struct sock *);
1084 +/* Initialise core socket variables */
1085 +extern void sock_init_data(struct socket *sock, struct sock *sk);
1087 +extern void sklist_remove_socket(struct sock **list, struct sock *sk);
1088 +extern void sklist_insert_socket(struct sock **list, struct sock *sk);
1089 +extern void sklist_destroy_socket(struct sock **list, struct sock *sk);
1091 +#ifdef CONFIG_FILTER
1094 + * sk_filter - run a packet through a socket filter
1095 + * @sk: sock associated with &sk_buff
1096 + * @skb: buffer to filter
1097 + * @needlock: set to 1 if the sock is not locked by caller.
1099 + * Run the filter code and then cut skb->data to correct size returned by
1100 + * sk_run_filter. If pkt_len is 0 we toss packet. If skb->len is smaller
1101 + * than pkt_len we keep whole skb->data. This is the socket level
1102 + * wrapper to sk_run_filter. It returns 0 if the packet should
1103 + * be accepted or -EPERM if the packet should be tossed.
1106 +static inline int sk_filter(struct sock *sk, struct sk_buff *skb, int needlock)
1111 + struct sk_filter *filter;
1116 + filter = sk->filter;
1118 + int pkt_len = sk_run_filter(skb, filter->insns,
1123 + skb_trim(skb, pkt_len);
1127 + bh_unlock_sock(sk);
1133 + * sk_filter_release: Release a socket filter
1135 + * @fp: filter to remove
1137 + * Remove a filter from a socket and release its resources.
1140 +static inline void sk_filter_release(struct sock *sk, struct sk_filter *fp)
1142 + unsigned int size = sk_filter_len(fp);
1144 + atomic_sub(size, &sk->omem_alloc);
1146 + if (atomic_dec_and_test(&fp->refcnt))
1150 +static inline void sk_filter_charge(struct sock *sk, struct sk_filter *fp)
1152 + atomic_inc(&fp->refcnt);
1153 + atomic_add(sk_filter_len(fp), &sk->omem_alloc);
1158 +static inline int sk_filter(struct sock *sk, struct sk_buff *skb, int needlock)
1163 +#endif /* CONFIG_FILTER */
1166 + * Socket reference counting postulates.
1168 + * * Each user of socket SHOULD hold a reference count.
1169 + * * Each access point to socket (an hash table bucket, reference from a list,
1170 + * running timer, skb in flight MUST hold a reference count.
1171 + * * When reference count hits 0, it means it will never increase back.
1172 + * * When reference count hits 0, it means that no references from
1173 + * outside exist to this socket and current process on current CPU
1174 + * is last user and may/should destroy this socket.
1175 + * * sk_free is called from any context: process, BH, IRQ. When
1176 + * it is called, socket has no references from outside -> sk_free
1177 + * may release descendant resources allocated by the socket, but
1178 + * to the time when it is called, socket is NOT referenced by any
1179 + * hash tables, lists etc.
1180 + * * Packets, delivered from outside (from network or from another process)
1181 + * and enqueued on receive/error queues SHOULD NOT grab reference count,
1182 + * when they sit in queue. Otherwise, packets will leak to hole, when
1183 + * socket is looked up by one cpu and unhasing is made by another CPU.
1184 + * It is true for udp/raw, netlink (leak to receive and error queues), tcp
1185 + * (leak to backlog). Packet socket does all the processing inside
1186 + * BR_NETPROTO_LOCK, so that it has not this race condition. UNIX sockets
1187 + * use separate SMP lock, so that they are prone too.
1190 +/* Grab socket reference count. This operation is valid only
1191 + when sk is ALREADY grabbed f.e. it is found in hash table
1192 + or a list and the lookup is made under lock preventing hash table
1196 +static inline void sock_hold(struct sock *sk)
1198 + atomic_inc(&sk->refcnt);
1201 +/* Ungrab socket in the context, which assumes that socket refcnt
1202 + cannot hit zero, f.e. it is true in context of any socketcall.
1204 +static inline void __sock_put(struct sock *sk)
1206 + atomic_dec(&sk->refcnt);
1209 +/* Ungrab socket and destroy it, if it was the last reference. */
1210 +static inline void sock_put(struct sock *sk)
1212 + if (atomic_dec_and_test(&sk->refcnt))
1216 +/* Detach socket from process context.
1217 + * Announce socket dead, detach it from wait queue and inode.
1218 + * Note that parent inode held reference count on this struct sock,
1219 + * we do not release it in this function, because protocol
1220 + * probably wants some additional cleanups or even continuing
1221 + * to work with this socket (TCP).
1223 +static inline void sock_orphan(struct sock *sk)
1225 + write_lock_bh(&sk->callback_lock);
1227 + sk->socket = NULL;
1229 + write_unlock_bh(&sk->callback_lock);
1232 +static inline void sock_graft(struct sock *sk, struct socket *parent)
1234 + write_lock_bh(&sk->callback_lock);
1235 + sk->sleep = &parent->wait;
1237 + sk->socket = parent;
1238 + write_unlock_bh(&sk->callback_lock);
1241 +static inline int sock_i_uid(struct sock *sk)
1245 + read_lock(&sk->callback_lock);
1246 + uid = sk->socket ? sk->socket->inode->i_uid : 0;
1247 + read_unlock(&sk->callback_lock);
1251 +static inline unsigned long sock_i_ino(struct sock *sk)
1253 + unsigned long ino;
1255 + read_lock(&sk->callback_lock);
1256 + ino = sk->socket ? sk->socket->inode->i_ino : 0;
1257 + read_unlock(&sk->callback_lock);
1261 +static inline struct dst_entry *
1262 +__sk_dst_get(struct sock *sk)
1264 + return sk->dst_cache;
1267 +static inline struct dst_entry *
1268 +sk_dst_get(struct sock *sk)
1270 + struct dst_entry *dst;
1272 + read_lock(&sk->dst_lock);
1273 + dst = sk->dst_cache;
1276 + read_unlock(&sk->dst_lock);
1281 +__sk_dst_set(struct sock *sk, struct dst_entry *dst)
1283 + struct dst_entry *old_dst;
1285 + old_dst = sk->dst_cache;
1286 + sk->dst_cache = dst;
1287 + dst_release(old_dst);
1291 +sk_dst_set(struct sock *sk, struct dst_entry *dst)
1293 + write_lock(&sk->dst_lock);
1294 + __sk_dst_set(sk, dst);
1295 + write_unlock(&sk->dst_lock);
1299 +__sk_dst_reset(struct sock *sk)
1301 + struct dst_entry *old_dst;
1303 + old_dst = sk->dst_cache;
1304 + sk->dst_cache = NULL;
1305 + dst_release(old_dst);
1309 +sk_dst_reset(struct sock *sk)
1311 + write_lock(&sk->dst_lock);
1312 + __sk_dst_reset(sk);
1313 + write_unlock(&sk->dst_lock);
1316 +static inline struct dst_entry *
1317 +__sk_dst_check(struct sock *sk, u32 cookie)
1319 + struct dst_entry *dst = sk->dst_cache;
1321 + if (dst && dst->obsolete && dst->ops->check(dst, cookie) == NULL) {
1322 + sk->dst_cache = NULL;
1329 +static inline struct dst_entry *
1330 +sk_dst_check(struct sock *sk, u32 cookie)
1332 + struct dst_entry *dst = sk_dst_get(sk);
1334 + if (dst && dst->obsolete && dst->ops->check(dst, cookie) == NULL) {
1344 + * Queue a received datagram if it will fit. Stream and sequenced
1345 + * protocols can't normally use this as they need to fit buffers in
1346 + * and play with them.
1348 + * Inlined as it's very short and called for pretty much every
1349 + * packet ever received.
1352 +static inline void skb_set_owner_w(struct sk_buff *skb, struct sock *sk)
1356 + skb->destructor = sock_wfree;
1357 + atomic_add(skb->truesize, &sk->wmem_alloc);
1360 +static inline void skb_set_owner_r(struct sk_buff *skb, struct sock *sk)
1363 + skb->destructor = sock_rfree;
1364 + atomic_add(skb->truesize, &sk->rmem_alloc);
1367 +static inline int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
1372 + /* Cast skb->rcvbuf to unsigned... It's pointless, but reduces
1373 + number of warnings when compiling with -W --ANK
1375 + if (atomic_read(&sk->rmem_alloc) + skb->truesize >= (unsigned)sk->rcvbuf) {
1380 + /* It would be deadlock, if sock_queue_rcv_skb is used
1381 + with socket lock! We assume that users of this
1382 + function are lock free.
1384 + err = sk_filter(sk, skb, 1);
1389 + skb_set_owner_r(skb, sk);
1391 + /* Cache the SKB length before we tack it onto the receive
1392 + * queue. Once it is added it no longer belongs to us and
1393 + * may be freed by other threads of control pulling packets
1396 + skb_len = skb->len;
1398 + skb_queue_tail(&sk->receive_queue, skb);
1400 + sk->data_ready(sk,skb_len);
1405 +static inline int sock_queue_err_skb(struct sock *sk, struct sk_buff *skb)
1407 + /* Cast skb->rcvbuf to unsigned... It's pointless, but reduces
1408 + number of warnings when compiling with -W --ANK
1410 + if (atomic_read(&sk->rmem_alloc) + skb->truesize >= (unsigned)sk->rcvbuf)
1412 + skb_set_owner_r(skb, sk);
1413 + skb_queue_tail(&sk->error_queue,skb);
1415 + sk->data_ready(sk,skb->len);
1420 + * Recover an error report and clear atomically
1423 +static inline int sock_error(struct sock *sk)
1425 + int err=xchg(&sk->err,0);
1429 +static inline unsigned long sock_wspace(struct sock *sk)
1433 + if (!(sk->shutdown & SEND_SHUTDOWN)) {
1434 + amt = sk->sndbuf - atomic_read(&sk->wmem_alloc);
1441 +static inline void sk_wake_async(struct sock *sk, int how, int band)
1443 + if (sk->socket && sk->socket->fasync_list)
1444 + sock_wake_async(sk->socket, how, band);
1447 +#define SOCK_MIN_SNDBUF 2048
1448 +#define SOCK_MIN_RCVBUF 256
1451 + * Default write policy as shown to user space via poll/select/SIGIO
1453 +static inline int sock_writeable(struct sock *sk)
1455 + return atomic_read(&sk->wmem_alloc) < (sk->sndbuf / 2);
1458 +static inline int gfp_any(void)
1460 + return in_softirq() ? GFP_ATOMIC : GFP_KERNEL;
1463 +static inline long sock_rcvtimeo(struct sock *sk, int noblock)
1465 + return noblock ? 0 : sk->rcvtimeo;
1468 +static inline long sock_sndtimeo(struct sock *sk, int noblock)
1470 + return noblock ? 0 : sk->sndtimeo;
1473 +static inline int sock_rcvlowat(struct sock *sk, int waitall, int len)
1475 + return (waitall ? len : min_t(int, sk->rcvlowat, len)) ? : 1;
1478 +/* Alas, with timeout socket operations are not restartable.
1479 + * Compare this to poll().
1481 +static inline int sock_intr_errno(long timeo)
1483 + return timeo == MAX_SCHEDULE_TIMEOUT ? -ERESTARTSYS : -EINTR;
1486 +static __inline__ void
1487 +sock_recv_timestamp(struct msghdr *msg, struct sock *sk, struct sk_buff *skb)
1489 + if (sk->rcvtstamp)
1490 + put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMP, sizeof(skb->stamp), &skb->stamp);
1492 + sk->stamp = skb->stamp;
1496 + * Enable debug/info messages
1500 +#define NETDEBUG(x) do { } while (0)
1502 +#define NETDEBUG(x) do { x; } while (0)
1506 + * Macros for sleeping on a socket. Use them like this:
1508 + * SOCK_SLEEP_PRE(sk)
1511 + * SOCK_SLEEP_POST(sk)
1515 +#define SOCK_SLEEP_PRE(sk) { struct task_struct *tsk = current; \
1516 + DECLARE_WAITQUEUE(wait, tsk); \
1517 + tsk->state = TASK_INTERRUPTIBLE; \
1518 + add_wait_queue((sk)->sleep, &wait); \
1521 +#define SOCK_SLEEP_POST(sk) tsk->state = TASK_RUNNING; \
1522 + remove_wait_queue((sk)->sleep, &wait); \
1526 +extern __u32 sysctl_wmem_max;
1527 +extern __u32 sysctl_rmem_max;
1529 +#endif /* _SOCK_H */
1530 diff --unified --recursive --new-file linux-2.4.30/net/Config.in linux-2.4.30-1-686-smp-ring3/net/Config.in
1531 --- linux-2.4.30/net/Config.in 2005-01-19 15:10:13.000000000 +0100
1532 +++ linux-2.4.30-1-686-smp-ring3/net/Config.in 2005-10-22 23:08:28.028051250 +0200
1534 bool ' Network packet filtering debugging' CONFIG_NETFILTER_DEBUG
1536 bool 'Socket Filtering' CONFIG_FILTER
1537 +if [ "$CONFIG_EXPERIMENTAL" = "y" -a "$CONFIG_FILTER" = "y" ]; then
1538 + source net/ring/Config.in
1540 tristate 'Unix domain sockets' CONFIG_UNIX
1541 bool 'TCP/IP networking' CONFIG_INET
1542 if [ "$CONFIG_INET" = "y" ]; then
1543 diff --unified --recursive --new-file linux-2.4.30/net/Config.in.ORG linux-2.4.30-1-686-smp-ring3/net/Config.in.ORG
1544 --- linux-2.4.30/net/Config.in.ORG 1970-01-01 01:00:00.000000000 +0100
1545 +++ linux-2.4.30-1-686-smp-ring3/net/Config.in.ORG 2005-10-22 23:08:28.020050750 +0200
1548 +# Network configuration
1550 +mainmenu_option next_comment
1551 +comment 'Networking options'
1552 +tristate 'Packet socket' CONFIG_PACKET
1553 +if [ "$CONFIG_PACKET" != "n" ]; then
1554 + bool ' Packet socket: mmapped IO' CONFIG_PACKET_MMAP
1557 +tristate 'Netlink device emulation' CONFIG_NETLINK_DEV
1559 +bool 'Network packet filtering (replaces ipchains)' CONFIG_NETFILTER
1560 +if [ "$CONFIG_NETFILTER" = "y" ]; then
1561 + bool ' Network packet filtering debugging' CONFIG_NETFILTER_DEBUG
1563 +bool 'Socket Filtering' CONFIG_FILTER
1564 +tristate 'Unix domain sockets' CONFIG_UNIX
1565 +bool 'TCP/IP networking' CONFIG_INET
1566 +if [ "$CONFIG_INET" = "y" ]; then
1567 + source net/ipv4/Config.in
1568 + if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
1569 +# IPv6 as module will cause a CRASH if you try to unload it
1570 + tristate ' The IPv6 protocol (EXPERIMENTAL)' CONFIG_IPV6
1571 + if [ "$CONFIG_IPV6" != "n" ]; then
1572 + source net/ipv6/Config.in
1575 + if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
1576 + source net/khttpd/Config.in
1578 + if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
1579 + source net/sctp/Config.in
1582 +if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
1583 + tristate 'Asynchronous Transfer Mode (ATM) (EXPERIMENTAL)' CONFIG_ATM
1584 + if [ "$CONFIG_ATM" = "y" -o "$CONFIG_ATM" = "m" ]; then
1585 + if [ "$CONFIG_INET" = "y" ]; then
1586 + dep_tristate ' Classical IP over ATM' CONFIG_ATM_CLIP $CONFIG_ATM
1587 + if [ "$CONFIG_ATM_CLIP" != "n" ]; then
1588 + bool ' Do NOT send ICMP if no neighbour' CONFIG_ATM_CLIP_NO_ICMP
1591 + dep_tristate ' LAN Emulation (LANE) support' CONFIG_ATM_LANE $CONFIG_ATM
1592 + if [ "$CONFIG_INET" = "y" -a "$CONFIG_ATM_LANE" != "n" ]; then
1593 + tristate ' Multi-Protocol Over ATM (MPOA) support' CONFIG_ATM_MPOA
1595 + dep_tristate ' RFC1483/2684 Bridged protocols' CONFIG_ATM_BR2684 $CONFIG_ATM
1596 + if [ "$CONFIG_ATM_BR2684" != "n" ]; then
1597 + bool ' Per-VC IP filter kludge' CONFIG_ATM_BR2684_IPFILTER
1601 +tristate '802.1Q VLAN Support' CONFIG_VLAN_8021Q
1604 +tristate 'The IPX protocol' CONFIG_IPX
1605 +if [ "$CONFIG_IPX" != "n" ]; then
1606 + source net/ipx/Config.in
1609 +tristate 'Appletalk protocol support' CONFIG_ATALK
1610 +if [ "$CONFIG_ATALK" != "n" ]; then
1611 + source drivers/net/appletalk/Config.in
1614 +tristate 'DECnet Support' CONFIG_DECNET
1615 +if [ "$CONFIG_DECNET" != "n" ]; then
1616 + source net/decnet/Config.in
1618 +dep_tristate '802.1d Ethernet Bridging' CONFIG_BRIDGE $CONFIG_INET
1619 +if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
1620 + tristate 'CCITT X.25 Packet Layer (EXPERIMENTAL)' CONFIG_X25
1621 + tristate 'LAPB Data Link Driver (EXPERIMENTAL)' CONFIG_LAPB
1622 + bool '802.2 LLC (EXPERIMENTAL)' CONFIG_LLC
1623 + bool 'Frame Diverter (EXPERIMENTAL)' CONFIG_NET_DIVERT
1624 +# if [ "$CONFIG_LLC" = "y" ]; then
1625 +# bool ' Netbeui (EXPERIMENTAL)' CONFIG_NETBEUI
1627 + if [ "$CONFIG_INET" = "y" ]; then
1628 + tristate 'Acorn Econet/AUN protocols (EXPERIMENTAL)' CONFIG_ECONET
1629 + if [ "$CONFIG_ECONET" != "n" ]; then
1630 + bool ' AUN over UDP' CONFIG_ECONET_AUNUDP
1631 + bool ' Native Econet' CONFIG_ECONET_NATIVE
1634 + tristate 'WAN router' CONFIG_WAN_ROUTER
1635 + bool 'Fast switching (read help!)' CONFIG_NET_FASTROUTE
1636 + bool 'Forwarding between high speed interfaces' CONFIG_NET_HW_FLOWCONTROL
1639 +mainmenu_option next_comment
1640 +comment 'QoS and/or fair queueing'
1641 +bool 'QoS and/or fair queueing' CONFIG_NET_SCHED
1642 +if [ "$CONFIG_NET_SCHED" = "y" ]; then
1643 + source net/sched/Config.in
1645 +#bool 'Network code profiler' CONFIG_NET_PROFILE
1648 +mainmenu_option next_comment
1649 +comment 'Network testing'
1650 +dep_tristate 'Packet Generator (USE WITH CAUTION)' CONFIG_NET_PKTGEN $CONFIG_PROC_FS
1654 diff --unified --recursive --new-file linux-2.4.30/net/Makefile linux-2.4.30-1-686-smp-ring3/net/Makefile
1655 --- linux-2.4.30/net/Makefile 2004-08-08 01:26:06.000000000 +0200
1656 +++ linux-2.4.30-1-686-smp-ring3/net/Makefile 2005-10-22 23:08:27.928045000 +0200
1659 O_TARGET := network.o
1661 -mod-subdirs := ipv4/netfilter ipv6/netfilter ipx irda bluetooth atm netlink sched core sctp 802
1662 +mod-subdirs := ipv4/netfilter ipv6/netfilter ipx irda bluetooth atm netlink sched core sctp 802 ring
1663 export-objs := netsyms.o
1665 subdir-y := core ethernet
1667 subdir-$(CONFIG_DECNET) += decnet
1668 subdir-$(CONFIG_ECONET) += econet
1669 subdir-$(CONFIG_VLAN_8021Q) += 8021q
1670 +subdir-$(CONFIG_RING) += ring
1672 ifeq ($(CONFIG_NETFILTER),y)
1673 mod-subdirs += ipv4/ipvs
1674 diff --unified --recursive --new-file linux-2.4.30/net/Makefile.ORG linux-2.4.30-1-686-smp-ring3/net/Makefile.ORG
1675 --- linux-2.4.30/net/Makefile.ORG 1970-01-01 01:00:00.000000000 +0100
1676 +++ linux-2.4.30-1-686-smp-ring3/net/Makefile.ORG 2005-10-22 23:08:27.916044250 +0200
1679 +# Makefile for the linux networking.
1681 +# 2 Sep 2000, Christoph Hellwig <hch@infradead.org>
1682 +# Rewritten to use lists instead of if-statements.
1685 +O_TARGET := network.o
1687 +mod-subdirs := ipv4/netfilter ipv6/netfilter ipx irda bluetooth atm netlink sched core sctp 802
1688 +export-objs := netsyms.o
1690 +subdir-y := core ethernet
1691 +subdir-m := ipv4 # hum?
1694 +subdir-$(CONFIG_NET) += 802 sched netlink
1695 +subdir-$(CONFIG_IPV6) += ipv6
1696 +subdir-$(CONFIG_INET) += ipv4
1697 +subdir-$(CONFIG_NETFILTER) += ipv4/netfilter
1698 +subdir-$(CONFIG_UNIX) += unix
1699 +subdir-$(CONFIG_IP_SCTP) += sctp
1701 +ifneq ($(CONFIG_IPV6),n)
1702 +ifneq ($(CONFIG_IPV6),)
1703 +subdir-$(CONFIG_NETFILTER) += ipv6/netfilter
1707 +subdir-$(CONFIG_KHTTPD) += khttpd
1708 +subdir-$(CONFIG_PACKET) += packet
1709 +subdir-$(CONFIG_NET_SCHED) += sched
1710 +subdir-$(CONFIG_BRIDGE) += bridge
1711 +subdir-$(CONFIG_IPX) += ipx
1712 +subdir-$(CONFIG_ATALK) += appletalk
1713 +subdir-$(CONFIG_WAN_ROUTER) += wanrouter
1714 +subdir-$(CONFIG_X25) += x25
1715 +subdir-$(CONFIG_LAPB) += lapb
1716 +subdir-$(CONFIG_NETROM) += netrom
1717 +subdir-$(CONFIG_ROSE) += rose
1718 +subdir-$(CONFIG_AX25) += ax25
1719 +subdir-$(CONFIG_IRDA) += irda
1720 +subdir-$(CONFIG_BLUEZ) += bluetooth
1721 +subdir-$(CONFIG_SUNRPC) += sunrpc
1722 +subdir-$(CONFIG_ATM) += atm
1723 +subdir-$(CONFIG_DECNET) += decnet
1724 +subdir-$(CONFIG_ECONET) += econet
1725 +subdir-$(CONFIG_VLAN_8021Q) += 8021q
1727 +ifeq ($(CONFIG_NETFILTER),y)
1728 + mod-subdirs += ipv4/ipvs
1729 + subdir-$(CONFIG_IP_VS) += ipv4/ipvs
1732 +obj-y := socket.o $(join $(subdir-y), $(patsubst %,/%.o,$(notdir $(subdir-y))))
1733 +ifeq ($(CONFIG_NET),y)
1734 +obj-$(CONFIG_MODULES) += netsyms.o
1735 +obj-$(CONFIG_SYSCTL) += sysctl_net.o
1738 +include $(TOPDIR)/Rules.make
1739 diff --unified --recursive --new-file linux-2.4.30/net/core/dev.c linux-2.4.30-1-686-smp-ring3/net/core/dev.c
1740 --- linux-2.4.30/net/core/dev.c 2005-04-04 03:42:20.000000000 +0200
1741 +++ linux-2.4.30-1-686-smp-ring3/net/core/dev.c 2005-10-22 23:08:27.900043250 +0200
1742 @@ -104,6 +104,56 @@
1743 #include <linux/wireless.h> /* Note : will define WIRELESS_EXT */
1744 #include <net/iw_handler.h>
1745 #endif /* CONFIG_NET_RADIO || CONFIG_NET_PCMCIA_RADIO */
1746 +#if defined (CONFIG_RING) || defined(CONFIG_RING_MODULE)
1748 +/* #define RING_DEBUG */
1750 +#include <linux/ring.h>
1751 +#include <linux/version.h>
1753 +static handle_ring_skb ring_handler = NULL;
1755 +handle_ring_skb get_skb_ring_handler() { return(ring_handler); }
1757 +void set_skb_ring_handler(handle_ring_skb the_handler) {
1758 + ring_handler = the_handler;
1761 +void do_skb_ring_handler(struct sk_buff *skb,
1762 + u_char recv_packet, u_char real_skb) {
1764 + ring_handler(skb, recv_packet, real_skb);
1767 +/* ******************* */
1769 +static handle_ring_buffer buffer_ring_handler = NULL;
1771 +handle_ring_buffer get_buffer_ring_handler() { return(buffer_ring_handler); }
1773 +void set_buffer_ring_handler(handle_ring_buffer the_handler) {
1774 + buffer_ring_handler = the_handler;
1777 +int do_buffer_ring_handler(struct net_device *dev, char *data, int len) {
1778 + if(buffer_ring_handler) {
1779 + buffer_ring_handler(dev, data, len);
1785 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
1786 +EXPORT_SYMBOL(get_skb_ring_handler);
1787 +EXPORT_SYMBOL(set_skb_ring_handler);
1788 +EXPORT_SYMBOL(do_skb_ring_handler);
1790 +EXPORT_SYMBOL(get_buffer_ring_handler);
1791 +EXPORT_SYMBOL(set_buffer_ring_handler);
1792 +EXPORT_SYMBOL(do_buffer_ring_handler);
1797 extern int plip_init(void);
1799 @@ -1066,6 +1116,10 @@
1803 +#if defined (CONFIG_RING) || defined(CONFIG_RING_MODULE)
1804 + if(ring_handler) ring_handler(skb, 0, 1);
1805 +#endif /* CONFIG_RING */
1807 /* Grab device queue */
1808 spin_lock_bh(&dev->queue_lock);
1810 @@ -1278,6 +1332,13 @@
1811 struct softnet_data *queue;
1812 unsigned long flags;
1814 +#if defined (CONFIG_RING) || defined(CONFIG_RING_MODULE)
1815 + if(ring_handler && ring_handler(skb, 1, 1)) {
1816 + /* The packet has been copied into a ring */
1817 + return(NET_RX_SUCCESS);
1819 +#endif /* CONFIG_RING */
1821 if (skb->stamp.tv_sec == 0)
1822 do_gettimeofday(&skb->stamp);
1824 @@ -1464,6 +1525,13 @@
1825 int ret = NET_RX_DROP;
1826 unsigned short type;
1828 +#if defined (CONFIG_RING) || defined(CONFIG_RING_MODULE)
1829 + if(ring_handler && ring_handler(skb, 1, 1)) {
1830 + /* The packet has been copied into a ring */
1831 + return(NET_RX_SUCCESS);
1833 +#endif /* CONFIG_RING */
1835 if (skb->stamp.tv_sec == 0)
1836 do_gettimeofday(&skb->stamp);
1838 diff --unified --recursive --new-file linux-2.4.30/net/core/dev.c.ORG linux-2.4.30-1-686-smp-ring3/net/core/dev.c.ORG
1839 --- linux-2.4.30/net/core/dev.c.ORG 1970-01-01 01:00:00.000000000 +0100
1840 +++ linux-2.4.30-1-686-smp-ring3/net/core/dev.c.ORG 2005-10-22 23:08:27.472016500 +0200
1843 + * NET3 Protocol independent device support routines.
1845 + * This program is free software; you can redistribute it and/or
1846 + * modify it under the terms of the GNU General Public License
1847 + * as published by the Free Software Foundation; either version
1848 + * 2 of the License, or (at your option) any later version.
1850 + * Derived from the non IP parts of dev.c 1.0.19
1851 + * Authors: Ross Biro, <bir7@leland.Stanford.Edu>
1852 + * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
1853 + * Mark Evans, <evansmp@uhura.aston.ac.uk>
1855 + * Additional Authors:
1856 + * Florian la Roche <rzsfl@rz.uni-sb.de>
1857 + * Alan Cox <gw4pts@gw4pts.ampr.org>
1858 + * David Hinds <dahinds@users.sourceforge.net>
1859 + * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
1860 + * Adam Sulmicki <adam@cfar.umd.edu>
1861 + * Pekka Riikonen <priikone@poesidon.pspt.fi>
1864 + * D.J. Barrow : Fixed bug where dev->refcnt gets set to 2
1865 + * if register_netdev gets called before
1866 + * net_dev_init & also removed a few lines
1867 + * of code in the process.
1868 + * Alan Cox : device private ioctl copies fields back.
1869 + * Alan Cox : Transmit queue code does relevant stunts to
1870 + * keep the queue safe.
1871 + * Alan Cox : Fixed double lock.
1872 + * Alan Cox : Fixed promisc NULL pointer trap
1873 + * ???????? : Support the full private ioctl range
1874 + * Alan Cox : Moved ioctl permission check into drivers
1875 + * Tim Kordas : SIOCADDMULTI/SIOCDELMULTI
1876 + * Alan Cox : 100 backlog just doesn't cut it when
1877 + * you start doing multicast video 8)
1878 + * Alan Cox : Rewrote net_bh and list manager.
1879 + * Alan Cox : Fix ETH_P_ALL echoback lengths.
1880 + * Alan Cox : Took out transmit every packet pass
1881 + * Saved a few bytes in the ioctl handler
1882 + * Alan Cox : Network driver sets packet type before calling netif_rx. Saves
1883 + * a function call a packet.
1884 + * Alan Cox : Hashed net_bh()
1885 + * Richard Kooijman: Timestamp fixes.
1886 + * Alan Cox : Wrong field in SIOCGIFDSTADDR
1887 + * Alan Cox : Device lock protection.
1888 + * Alan Cox : Fixed nasty side effect of device close changes.
1889 + * Rudi Cilibrasi : Pass the right thing to set_mac_address()
1890 + * Dave Miller : 32bit quantity for the device lock to make it work out
1892 + * Bjorn Ekwall : Added KERNELD hack.
1893 + * Alan Cox : Cleaned up the backlog initialise.
1894 + * Craig Metz : SIOCGIFCONF fix if space for under
1896 + * Thomas Bogendoerfer : Return ENODEV for dev_open, if there
1897 + * is no device open function.
1898 + * Andi Kleen : Fix error reporting for SIOCGIFCONF
1899 + * Michael Chastain : Fix signed/unsigned for SIOCGIFCONF
1900 + * Cyrus Durgin : Cleaned for KMOD
1901 + * Adam Sulmicki : Bug Fix : Network Device Unload
1902 + * A network device unload needs to purge
1903 + * the backlog queue.
1904 + * Paul Rusty Russell : SIOCSIFNAME
1905 + * Pekka Riikonen : Netdev boot-time settings code
1906 + * Andrew Morton : Make unregister_netdevice wait indefinitely on dev->refcnt
1907 + * J Hadi Salim : - Backlog queue sampling
1908 + * - netif_rx() feedback
1911 +#include <asm/uaccess.h>
1912 +#include <asm/system.h>
1913 +#include <asm/bitops.h>
1914 +#include <linux/config.h>
1915 +#include <linux/types.h>
1916 +#include <linux/kernel.h>
1917 +#include <linux/sched.h>
1918 +#include <linux/string.h>
1919 +#include <linux/mm.h>
1920 +#include <linux/socket.h>
1921 +#include <linux/sockios.h>
1922 +#include <linux/errno.h>
1923 +#include <linux/interrupt.h>
1924 +#include <linux/if_ether.h>
1925 +#include <linux/netdevice.h>
1926 +#include <linux/etherdevice.h>
1927 +#include <linux/notifier.h>
1928 +#include <linux/skbuff.h>
1929 +#include <linux/brlock.h>
1930 +#include <net/sock.h>
1931 +#include <linux/rtnetlink.h>
1932 +#include <linux/proc_fs.h>
1933 +#include <linux/stat.h>
1934 +#include <linux/if_bridge.h>
1935 +#include <linux/divert.h>
1936 +#include <net/dst.h>
1937 +#include <net/pkt_sched.h>
1938 +#include <net/profile.h>
1939 +#include <net/checksum.h>
1940 +#include <linux/highmem.h>
1941 +#include <linux/init.h>
1942 +#include <linux/kmod.h>
1943 +#include <linux/module.h>
1944 +#if defined(CONFIG_NET_RADIO) || defined(CONFIG_NET_PCMCIA_RADIO)
1945 +#include <linux/wireless.h> /* Note : will define WIRELESS_EXT */
1946 +#include <net/iw_handler.h>
1947 +#endif /* CONFIG_NET_RADIO || CONFIG_NET_PCMCIA_RADIO */
1949 +extern int plip_init(void);
1953 +/* This define, if set, will randomly drop a packet when congestion
1954 + * is more than moderate. It helps fairness in the multi-interface
1955 + * case when one of them is a hog, but it kills performance for the
1956 + * single interface case so it is off now by default.
1960 +/* Setting this will sample the queue lengths and thus congestion
1961 + * via a timer instead of as each packet is received.
1963 +#undef OFFLINE_SAMPLE
1965 +NET_PROFILE_DEFINE(dev_queue_xmit)
1966 +NET_PROFILE_DEFINE(softnet_process)
1968 +const char *if_port_text[] = {
1979 + * The list of packet types we will receive (as opposed to discard)
1980 + * and the routines to invoke.
1982 + * Why 16. Because with 16 the only overlap we get on a hash of the
1983 + * low nibble of the protocol value is RARP/SNAP/X.25.
1985 + * NOTE: That is no longer true with the addition of VLAN tags. Not
1986 + * sure which should go first, but I bet it won't make much
1987 + * difference if we are running VLANs. The good news is that
1988 + * this protocol won't be in the list unless compiled in, so
1989 + * the average user (w/out VLANs) will not be adversly affected.
1993 + * 8100 802.1Q VLAN
2006 +static struct packet_type *ptype_base[16]; /* 16 way hashed list */
2007 +static struct packet_type *ptype_all = NULL; /* Taps */
2009 +#ifdef OFFLINE_SAMPLE
2010 +static void sample_queue(unsigned long dummy);
2011 +static struct timer_list samp_timer = { function: sample_queue };
2014 +#ifdef CONFIG_HOTPLUG
2015 +static int net_run_sbin_hotplug(struct net_device *dev, char *action);
2017 +#define net_run_sbin_hotplug(dev, action) ({ 0; })
2021 + * Our notifier list
2024 +static struct notifier_block *netdev_chain=NULL;
2027 + * Device drivers call our routines to queue packets here. We empty the
2028 + * queue in the local softnet handler.
2030 +struct softnet_data softnet_data[NR_CPUS] __cacheline_aligned;
2032 +#ifdef CONFIG_NET_FASTROUTE
2033 +int netdev_fastroute;
2034 +int netdev_fastroute_obstacles;
2038 +/******************************************************************************************
2040 + Protocol management and registration routines
2042 +*******************************************************************************************/
2051 + * Add a protocol ID to the list. Now that the input handler is
2052 + * smarter we can dispense with all the messy stuff that used to be
2055 + * BEWARE!!! Protocol handlers, mangling input packets,
2056 + * MUST BE last in hash buckets and checking protocol handlers
2057 + * MUST start from promiscous ptype_all chain in net_bh.
2058 + * It is true now, do not change it.
2059 + * Explantion follows: if protocol handler, mangling packet, will
2060 + * be the first on list, it is not able to sense, that packet
2061 + * is cloned and should be copied-on-write, so that it will
2062 + * change it and subsequent readers will get broken packet.
2067 + * dev_add_pack - add packet handler
2068 + * @pt: packet type declaration
2070 + * Add a protocol handler to the networking stack. The passed &packet_type
2071 + * is linked into kernel lists and may not be freed until it has been
2072 + * removed from the kernel lists.
2075 +void dev_add_pack(struct packet_type *pt)
2079 + br_write_lock_bh(BR_NETPROTO_LOCK);
2081 +#ifdef CONFIG_NET_FASTROUTE
2082 + /* Hack to detect packet socket */
2083 + if ((pt->data) && ((int)(pt->data)!=1)) {
2084 + netdev_fastroute_obstacles++;
2085 + dev_clear_fastroute(pt->dev);
2088 + if (pt->type == htons(ETH_P_ALL)) {
2090 + pt->next=ptype_all;
2093 + hash=ntohs(pt->type)&15;
2094 + pt->next = ptype_base[hash];
2095 + ptype_base[hash] = pt;
2097 + br_write_unlock_bh(BR_NETPROTO_LOCK);
2102 + * dev_remove_pack - remove packet handler
2103 + * @pt: packet type declaration
2105 + * Remove a protocol handler that was previously added to the kernel
2106 + * protocol handlers by dev_add_pack(). The passed &packet_type is removed
2107 + * from the kernel lists and can be freed or reused once this function
2111 +void dev_remove_pack(struct packet_type *pt)
2113 + struct packet_type **pt1;
2115 + br_write_lock_bh(BR_NETPROTO_LOCK);
2117 + if (pt->type == htons(ETH_P_ALL)) {
2121 + pt1=&ptype_base[ntohs(pt->type)&15];
2124 + for (; (*pt1) != NULL; pt1 = &((*pt1)->next)) {
2125 + if (pt == (*pt1)) {
2127 +#ifdef CONFIG_NET_FASTROUTE
2129 + netdev_fastroute_obstacles--;
2131 + br_write_unlock_bh(BR_NETPROTO_LOCK);
2135 + br_write_unlock_bh(BR_NETPROTO_LOCK);
2136 + printk(KERN_WARNING "dev_remove_pack: %p not found.\n", pt);
2139 +/******************************************************************************
2141 + Device Boot-time Settings Routines
2143 +*******************************************************************************/
2145 +/* Boot time configuration table */
2146 +static struct netdev_boot_setup dev_boot_setup[NETDEV_BOOT_SETUP_MAX];
2149 + * netdev_boot_setup_add - add new setup entry
2150 + * @name: name of the device
2151 + * @map: configured settings for the device
2153 + * Adds new setup entry to the dev_boot_setup list. The function
2154 + * returns 0 on error and 1 on success. This is a generic routine to
2157 +int netdev_boot_setup_add(char *name, struct ifmap *map)
2159 + struct netdev_boot_setup *s;
2162 + s = dev_boot_setup;
2163 + for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
2164 + if (s[i].name[0] == '\0' || s[i].name[0] == ' ') {
2165 + memset(s[i].name, 0, sizeof(s[i].name));
2166 + strcpy(s[i].name, name);
2167 + memcpy(&s[i].map, map, sizeof(s[i].map));
2172 + if (i >= NETDEV_BOOT_SETUP_MAX)
2179 + * netdev_boot_setup_check - check boot time settings
2180 + * @dev: the netdevice
2182 + * Check boot time settings for the device.
2183 + * The found settings are set for the device to be used
2184 + * later in the device probing.
2185 + * Returns 0 if no settings found, 1 if they are.
2187 +int netdev_boot_setup_check(struct net_device *dev)
2189 + struct netdev_boot_setup *s;
2192 + s = dev_boot_setup;
2193 + for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
2194 + if (s[i].name[0] != '\0' && s[i].name[0] != ' ' &&
2195 + !strncmp(dev->name, s[i].name, strlen(s[i].name))) {
2196 + dev->irq = s[i].map.irq;
2197 + dev->base_addr = s[i].map.base_addr;
2198 + dev->mem_start = s[i].map.mem_start;
2199 + dev->mem_end = s[i].map.mem_end;
2207 + * Saves at boot time configured settings for any netdevice.
2209 +int __init netdev_boot_setup(char *str)
2214 + str = get_options(str, ARRAY_SIZE(ints), ints);
2215 + if (!str || !*str)
2218 + /* Save settings */
2219 + memset(&map, 0, sizeof(map));
2221 + map.irq = ints[1];
2223 + map.base_addr = ints[2];
2225 + map.mem_start = ints[3];
2227 + map.mem_end = ints[4];
2229 + /* Add new entry to the list */
2230 + return netdev_boot_setup_add(str, &map);
2233 +__setup("netdev=", netdev_boot_setup);
2235 +/*****************************************************************************************
2237 + Device Interface Subroutines
2239 +******************************************************************************************/
2242 + * __dev_get_by_name - find a device by its name
2243 + * @name: name to find
2245 + * Find an interface by name. Must be called under RTNL semaphore
2246 + * or @dev_base_lock. If the name is found a pointer to the device
2247 + * is returned. If the name is not found then %NULL is returned. The
2248 + * reference counters are not incremented so the caller must be
2249 + * careful with locks.
2253 +struct net_device *__dev_get_by_name(const char *name)
2255 + struct net_device *dev;
2257 + for (dev = dev_base; dev != NULL; dev = dev->next) {
2258 + if (strncmp(dev->name, name, IFNAMSIZ) == 0)
2265 + * dev_get_by_name - find a device by its name
2266 + * @name: name to find
2268 + * Find an interface by name. This can be called from any
2269 + * context and does its own locking. The returned handle has
2270 + * the usage count incremented and the caller must use dev_put() to
2271 + * release it when it is no longer needed. %NULL is returned if no
2272 + * matching device is found.
2275 +struct net_device *dev_get_by_name(const char *name)
2277 + struct net_device *dev;
2279 + read_lock(&dev_base_lock);
2280 + dev = __dev_get_by_name(name);
2283 + read_unlock(&dev_base_lock);
2288 + Return value is changed to int to prevent illegal usage in future.
2289 + It is still legal to use to check for device existence.
2291 + User should understand, that the result returned by this function
2292 + is meaningless, if it was not issued under rtnl semaphore.
2296 + * dev_get - test if a device exists
2297 + * @name: name to test for
2299 + * Test if a name exists. Returns true if the name is found. In order
2300 + * to be sure the name is not allocated or removed during the test the
2301 + * caller must hold the rtnl semaphore.
2303 + * This function primarily exists for back compatibility with older
2307 +int dev_get(const char *name)
2309 + struct net_device *dev;
2311 + read_lock(&dev_base_lock);
2312 + dev = __dev_get_by_name(name);
2313 + read_unlock(&dev_base_lock);
2314 + return dev != NULL;
2318 + * __dev_get_by_index - find a device by its ifindex
2319 + * @ifindex: index of device
2321 + * Search for an interface by index. Returns %NULL if the device
2322 + * is not found or a pointer to the device. The device has not
2323 + * had its reference counter increased so the caller must be careful
2324 + * about locking. The caller must hold either the RTNL semaphore
2325 + * or @dev_base_lock.
2328 +struct net_device * __dev_get_by_index(int ifindex)
2330 + struct net_device *dev;
2332 + for (dev = dev_base; dev != NULL; dev = dev->next) {
2333 + if (dev->ifindex == ifindex)
2341 + * dev_get_by_index - find a device by its ifindex
2342 + * @ifindex: index of device
2344 + * Search for an interface by index. Returns NULL if the device
2345 + * is not found or a pointer to the device. The device returned has
2346 + * had a reference added and the pointer is safe until the user calls
2347 + * dev_put to indicate they have finished with it.
2350 +struct net_device * dev_get_by_index(int ifindex)
2352 + struct net_device *dev;
2354 + read_lock(&dev_base_lock);
2355 + dev = __dev_get_by_index(ifindex);
2358 + read_unlock(&dev_base_lock);
2363 + * dev_getbyhwaddr - find a device by its hardware address
2364 + * @type: media type of device
2365 + * @ha: hardware address
2367 + * Search for an interface by MAC address. Returns NULL if the device
2368 + * is not found or a pointer to the device. The caller must hold the
2369 + * rtnl semaphore. The returned device has not had its ref count increased
2370 + * and the caller must therefore be careful about locking
2373 + * If the API was consistent this would be __dev_get_by_hwaddr
2376 +struct net_device *dev_getbyhwaddr(unsigned short type, char *ha)
2378 + struct net_device *dev;
2382 + for (dev = dev_base; dev != NULL; dev = dev->next) {
2383 + if (dev->type == type &&
2384 + memcmp(dev->dev_addr, ha, dev->addr_len) == 0)
2391 + * dev_get_by_flags - find any device with given flags
2392 + * @if_flags: IFF_* values
2393 + * @mask: bitmask of bits in if_flags to check
2395 + * Search for any interface with the given flags. Returns NULL if a device
2396 + * is not found or a pointer to the device. The device returned has
2397 + * had a reference added and the pointer is safe until the user calls
2398 + * dev_put to indicate they have finished with it.
2401 +struct net_device * dev_get_by_flags(unsigned short if_flags, unsigned short mask)
2403 + struct net_device *dev;
2405 + read_lock(&dev_base_lock);
2406 + dev = __dev_get_by_flags(if_flags, mask);
2409 + read_unlock(&dev_base_lock);
2414 + * __dev_get_by_flags - find any device with given flags
2415 + * @if_flags: IFF_* values
2416 + * @mask: bitmask of bits in if_flags to check
2418 + * Search for any interface with the given flags. Returns NULL if a device
2419 + * is not found or a pointer to the device. The caller must hold either
2420 + * the RTNL semaphore or @dev_base_lock.
2423 +struct net_device *__dev_get_by_flags(unsigned short if_flags, unsigned short mask)
2425 + struct net_device *dev;
2427 + for (dev = dev_base; dev != NULL; dev = dev->next) {
2428 + if (((dev->flags ^ if_flags) & mask) == 0)
2435 + * dev_alloc_name - allocate a name for a device
2437 + * @name: name format string
2439 + * Passed a format string - eg "lt%d" it will try and find a suitable
2440 + * id. Not efficient for many devices, not called a lot. The caller
2441 + * must hold the dev_base or rtnl lock while allocating the name and
2442 + * adding the device in order to avoid duplicates. Returns the number
2443 + * of the unit assigned or a negative errno code.
2446 +int dev_alloc_name(struct net_device *dev, const char *name)
2453 + * Verify the string as this thing may have come from
2454 + * the user. There must be either one "%d" and no other "%"
2455 + * characters, or no "%" characters at all.
2457 + p = strchr(name, '%');
2458 + if (p && (p[1] != 'd' || strchr(p+2, '%')))
2462 + * If you need over 100 please also fix the algorithm...
2464 + for (i = 0; i < 100; i++) {
2465 + snprintf(buf,sizeof(buf),name,i);
2466 + if (__dev_get_by_name(buf) == NULL) {
2467 + strcpy(dev->name, buf);
2471 + return -ENFILE; /* Over 100 of the things .. bail out! */
2475 + * dev_alloc - allocate a network device and name
2476 + * @name: name format string
2477 + * @err: error return pointer
2479 + * Passed a format string, eg. "lt%d", it will allocate a network device
2480 + * and space for the name. %NULL is returned if no memory is available.
2481 + * If the allocation succeeds then the name is assigned and the
2482 + * device pointer returned. %NULL is returned if the name allocation
2483 + * failed. The cause of an error is returned as a negative errno code
2484 + * in the variable @err points to.
2486 + * The caller must hold the @dev_base or RTNL locks when doing this in
2487 + * order to avoid duplicate name allocations.
2490 +struct net_device *dev_alloc(const char *name, int *err)
2492 + struct net_device *dev=kmalloc(sizeof(struct net_device), GFP_KERNEL);
2493 + if (dev == NULL) {
2497 + memset(dev, 0, sizeof(struct net_device));
2498 + *err = dev_alloc_name(dev, name);
2507 + * netdev_state_change - device changes state
2508 + * @dev: device to cause notification
2510 + * Called to indicate a device has changed state. This function calls
2511 + * the notifier chains for netdev_chain and sends a NEWLINK message
2512 + * to the routing socket.
2515 +void netdev_state_change(struct net_device *dev)
2517 + if (dev->flags&IFF_UP) {
2518 + notifier_call_chain(&netdev_chain, NETDEV_CHANGE, dev);
2519 + rtmsg_ifinfo(RTM_NEWLINK, dev, 0);
2527 + * dev_load - load a network module
2528 + * @name: name of interface
2530 + * If a network interface is not present and the process has suitable
2531 + * privileges this function loads the module. If module loading is not
2532 + * available in this kernel then it becomes a nop.
2535 +void dev_load(const char *name)
2537 + if (!dev_get(name) && capable(CAP_SYS_MODULE))
2538 + request_module(name);
2543 +extern inline void dev_load(const char *unused){;}
2547 +static int default_rebuild_header(struct sk_buff *skb)
2549 + printk(KERN_DEBUG "%s: default_rebuild_header called -- BUG!\n", skb->dev ? skb->dev->name : "NULL!!!");
2555 + * dev_open - prepare an interface for use.
2556 + * @dev: device to open
2558 + * Takes a device from down to up state. The device's private open
2559 + * function is invoked and then the multicast lists are loaded. Finally
2560 + * the device is moved into the up state and a %NETDEV_UP message is
2561 + * sent to the netdev notifier chain.
2563 + * Calling this function on an active interface is a nop. On a failure
2564 + * a negative errno code is returned.
2567 +int dev_open(struct net_device *dev)
2572 + * Is it already up?
2575 + if (dev->flags&IFF_UP)
2579 + * Is it even present?
2581 + if (!netif_device_present(dev))
2585 + * Call device private open method
2587 + if (try_inc_mod_count(dev->owner)) {
2588 + set_bit(__LINK_STATE_START, &dev->state);
2590 + ret = dev->open(dev);
2592 + clear_bit(__LINK_STATE_START, &dev->state);
2594 + __MOD_DEC_USE_COUNT(dev->owner);
2602 + * If it went open OK then:
2610 + dev->flags |= IFF_UP;
2613 + * Initialize multicasting status
2615 + dev_mc_upload(dev);
2618 + * Wakeup transmit queue engine
2620 + dev_activate(dev);
2623 + * ... and announce new interface.
2625 + notifier_call_chain(&netdev_chain, NETDEV_UP, dev);
2630 +#ifdef CONFIG_NET_FASTROUTE
2632 +static void dev_do_clear_fastroute(struct net_device *dev)
2634 + if (dev->accept_fastpath) {
2637 + for (i=0; i<=NETDEV_FASTROUTE_HMASK; i++) {
2638 + struct dst_entry *dst;
2640 + write_lock_irq(&dev->fastpath_lock);
2641 + dst = dev->fastpath[i];
2642 + dev->fastpath[i] = NULL;
2643 + write_unlock_irq(&dev->fastpath_lock);
2650 +void dev_clear_fastroute(struct net_device *dev)
2653 + dev_do_clear_fastroute(dev);
2655 + read_lock(&dev_base_lock);
2656 + for (dev = dev_base; dev; dev = dev->next)
2657 + dev_do_clear_fastroute(dev);
2658 + read_unlock(&dev_base_lock);
2664 + * dev_close - shutdown an interface.
2665 + * @dev: device to shutdown
2667 + * This function moves an active device into down state. A
2668 + * %NETDEV_GOING_DOWN is sent to the netdev notifier chain. The device
2669 + * is then deactivated and finally a %NETDEV_DOWN is sent to the notifier
2673 +int dev_close(struct net_device *dev)
2675 + if (!(dev->flags&IFF_UP))
2679 + * Tell people we are going down, so that they can
2680 + * prepare to death, when device is still operating.
2682 + notifier_call_chain(&netdev_chain, NETDEV_GOING_DOWN, dev);
2684 + dev_deactivate(dev);
2686 + clear_bit(__LINK_STATE_START, &dev->state);
2688 + /* Synchronize to scheduled poll. We cannot touch poll list,
2689 + * it can be even on different cpu. So just clear netif_running(),
2690 + * and wait when poll really will happen. Actually, the best place
2691 + * for this is inside dev->stop() after device stopped its irq
2692 + * engine, but this requires more changes in devices. */
2694 + smp_mb__after_clear_bit(); /* Commit netif_running(). */
2695 + while (test_bit(__LINK_STATE_RX_SCHED, &dev->state)) {
2697 + current->state = TASK_INTERRUPTIBLE;
2698 + schedule_timeout(1);
2702 + * Call the device specific close. This cannot fail.
2703 + * Only if device is UP
2705 + * We allow it to be called even after a DETACH hot-plug
2713 + * Device is now down.
2716 + dev->flags &= ~IFF_UP;
2717 +#ifdef CONFIG_NET_FASTROUTE
2718 + dev_clear_fastroute(dev);
2722 + * Tell people we are down
2724 + notifier_call_chain(&netdev_chain, NETDEV_DOWN, dev);
2727 + * Drop the module refcount
2730 + __MOD_DEC_USE_COUNT(dev->owner);
2737 + * Device change register/unregister. These are not inline or static
2738 + * as we export them to the world.
2742 + * register_netdevice_notifier - register a network notifier block
2745 + * Register a notifier to be called when network device events occur.
2746 + * The notifier passed is linked into the kernel structures and must
2747 + * not be reused until it has been unregistered. A negative errno code
2748 + * is returned on a failure.
2751 +int register_netdevice_notifier(struct notifier_block *nb)
2753 + return notifier_chain_register(&netdev_chain, nb);
2757 + * unregister_netdevice_notifier - unregister a network notifier block
2760 + * Unregister a notifier previously registered by
2761 + * register_netdevice_notifier(). The notifier is unlinked into the
2762 + * kernel structures and may then be reused. A negative errno code
2763 + * is returned on a failure.
2766 +int unregister_netdevice_notifier(struct notifier_block *nb)
2768 + return notifier_chain_unregister(&netdev_chain,nb);
2772 + * Support routine. Sends outgoing frames to any network
2773 + * taps currently in use.
2776 +void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev)
2778 + struct packet_type *ptype;
2779 + do_gettimeofday(&skb->stamp);
2781 + br_read_lock(BR_NETPROTO_LOCK);
2782 + for (ptype = ptype_all; ptype!=NULL; ptype = ptype->next)
2784 + /* Never send packets back to the socket
2785 + * they originated from - MvS (miquels@drinkel.ow.org)
2787 + if ((ptype->dev == dev || !ptype->dev) &&
2788 + ((struct sock *)ptype->data != skb->sk))
2790 + struct sk_buff *skb2;
2791 + if ((skb2 = skb_clone(skb, GFP_ATOMIC)) == NULL)
2794 + /* skb->nh should be correctly
2795 + set by sender, so that the second statement is
2796 + just protection against buggy protocols.
2798 + skb2->mac.raw = skb2->data;
2800 + if (skb2->nh.raw < skb2->data || skb2->nh.raw > skb2->tail) {
2801 + if (net_ratelimit())
2802 + printk(KERN_CRIT "protocol %04x is buggy, dev %s\n", skb2->protocol, dev->name);
2803 + skb2->nh.raw = skb2->data;
2806 + skb2->h.raw = skb2->nh.raw;
2807 + skb2->pkt_type = PACKET_OUTGOING;
2808 + ptype->func(skb2, skb->dev, ptype);
2811 + br_read_unlock(BR_NETPROTO_LOCK);
2814 +/* Calculate csum in the case, when packet is misrouted.
2815 + * If it failed by some reason, ignore and send skb with wrong
2818 +struct sk_buff * skb_checksum_help(struct sk_buff *skb)
2821 + unsigned int csum;
2823 + offset = skb->h.raw - skb->data;
2824 + if (offset > (int)skb->len)
2826 + csum = skb_checksum(skb, offset, skb->len-offset, 0);
2828 + offset = skb->tail - skb->h.raw;
2831 + if (skb->csum+2 > offset)
2834 + *(u16*)(skb->h.raw + skb->csum) = csum_fold(csum);
2835 + skb->ip_summed = CHECKSUM_NONE;
2839 +#ifdef CONFIG_HIGHMEM
2840 +/* Actually, we should eliminate this check as soon as we know, that:
2841 + * 1. IOMMU is present and allows to map all the memory.
2842 + * 2. No high memory really exists on this machine.
2846 +illegal_highdma(struct net_device *dev, struct sk_buff *skb)
2850 + if (dev->features&NETIF_F_HIGHDMA)
2853 + for (i=0; i<skb_shinfo(skb)->nr_frags; i++)
2854 + if (skb_shinfo(skb)->frags[i].page >= highmem_start_page)
2860 +#define illegal_highdma(dev, skb) (0)
2864 + * dev_queue_xmit - transmit a buffer
2865 + * @skb: buffer to transmit
2867 + * Queue a buffer for transmission to a network device. The caller must
2868 + * have set the device and priority and built the buffer before calling this
2869 + * function. The function can be called from an interrupt.
2871 + * A negative errno code is returned on a failure. A success does not
2872 + * guarantee the frame will be transmitted as it may be dropped due
2873 + * to congestion or traffic shaping.
2876 +int dev_queue_xmit(struct sk_buff *skb)
2878 + struct net_device *dev = skb->dev;
2881 + if (skb_shinfo(skb)->frag_list &&
2882 + !(dev->features&NETIF_F_FRAGLIST) &&
2883 + skb_linearize(skb, GFP_ATOMIC) != 0) {
2888 + /* Fragmented skb is linearized if device does not support SG,
2889 + * or if at least one of fragments is in highmem and device
2890 + * does not support DMA from it.
2892 + if (skb_shinfo(skb)->nr_frags &&
2893 + (!(dev->features&NETIF_F_SG) || illegal_highdma(dev, skb)) &&
2894 + skb_linearize(skb, GFP_ATOMIC) != 0) {
2899 + /* If packet is not checksummed and device does not support
2900 + * checksumming for this protocol, complete checksumming here.
2902 + if (skb->ip_summed == CHECKSUM_HW &&
2903 + (!(dev->features&(NETIF_F_HW_CSUM|NETIF_F_NO_CSUM)) &&
2904 + (!(dev->features&NETIF_F_IP_CSUM) ||
2905 + skb->protocol != htons(ETH_P_IP)))) {
2906 + if ((skb = skb_checksum_help(skb)) == NULL)
2910 + /* Grab device queue */
2911 + spin_lock_bh(&dev->queue_lock);
2914 + int ret = q->enqueue(skb, q);
2918 + spin_unlock_bh(&dev->queue_lock);
2919 + return ret == NET_XMIT_BYPASS ? NET_XMIT_SUCCESS : ret;
2922 + /* The device has no queue. Common case for software devices:
2923 + loopback, all the sorts of tunnels...
2925 + Really, it is unlikely that xmit_lock protection is necessary here.
2926 + (f.e. loopback and IP tunnels are clean ignoring statistics counters.)
2927 + However, it is possible, that they rely on protection
2930 + Check this and shot the lock. It is not prone from deadlocks.
2931 + Either shot noqueue qdisc, it is even simpler 8)
2933 + if (dev->flags&IFF_UP) {
2934 + int cpu = smp_processor_id();
2936 + if (dev->xmit_lock_owner != cpu) {
2937 + spin_unlock(&dev->queue_lock);
2938 + spin_lock(&dev->xmit_lock);
2939 + dev->xmit_lock_owner = cpu;
2941 + if (!netif_queue_stopped(dev)) {
2943 + dev_queue_xmit_nit(skb,dev);
2945 + if (dev->hard_start_xmit(skb, dev) == 0) {
2946 + dev->xmit_lock_owner = -1;
2947 + spin_unlock_bh(&dev->xmit_lock);
2951 + dev->xmit_lock_owner = -1;
2952 + spin_unlock_bh(&dev->xmit_lock);
2953 + if (net_ratelimit())
2954 + printk(KERN_CRIT "Virtual device %s asks to queue packet!\n", dev->name);
2958 + /* Recursion is detected! It is possible, unfortunately */
2959 + if (net_ratelimit())
2960 + printk(KERN_CRIT "Dead loop on virtual device %s, fix it urgently!\n", dev->name);
2963 + spin_unlock_bh(&dev->queue_lock);
2970 +/*=======================================================================
2972 + =======================================================================*/
2974 +int netdev_max_backlog = 300;
2975 +int weight_p = 64; /* old backlog weight */
2976 +/* These numbers are selected based on intuition and some
2977 + * experimentatiom, if you have more scientific way of doing this
2978 + * please go ahead and fix things.
2980 +int no_cong_thresh = 10;
2983 +int mod_cong = 290;
2985 +struct netif_rx_stats netdev_rx_stat[NR_CPUS];
2988 +#ifdef CONFIG_NET_HW_FLOWCONTROL
2989 +atomic_t netdev_dropping = ATOMIC_INIT(0);
2990 +static unsigned long netdev_fc_mask = 1;
2991 +unsigned long netdev_fc_xoff = 0;
2992 +spinlock_t netdev_fc_lock = SPIN_LOCK_UNLOCKED;
2996 + void (*stimul)(struct net_device *);
2997 + struct net_device *dev;
2998 +} netdev_fc_slots[BITS_PER_LONG];
3000 +int netdev_register_fc(struct net_device *dev, void (*stimul)(struct net_device *dev))
3003 + unsigned long flags;
3005 + spin_lock_irqsave(&netdev_fc_lock, flags);
3006 + if (netdev_fc_mask != ~0UL) {
3007 + bit = ffz(netdev_fc_mask);
3008 + netdev_fc_slots[bit].stimul = stimul;
3009 + netdev_fc_slots[bit].dev = dev;
3010 + set_bit(bit, &netdev_fc_mask);
3011 + clear_bit(bit, &netdev_fc_xoff);
3013 + spin_unlock_irqrestore(&netdev_fc_lock, flags);
3017 +void netdev_unregister_fc(int bit)
3019 + unsigned long flags;
3021 + spin_lock_irqsave(&netdev_fc_lock, flags);
3023 + netdev_fc_slots[bit].stimul = NULL;
3024 + netdev_fc_slots[bit].dev = NULL;
3025 + clear_bit(bit, &netdev_fc_mask);
3026 + clear_bit(bit, &netdev_fc_xoff);
3028 + spin_unlock_irqrestore(&netdev_fc_lock, flags);
3031 +static void netdev_wakeup(void)
3033 + unsigned long xoff;
3035 + spin_lock(&netdev_fc_lock);
3036 + xoff = netdev_fc_xoff;
3037 + netdev_fc_xoff = 0;
3039 + int i = ffz(~xoff);
3041 + netdev_fc_slots[i].stimul(netdev_fc_slots[i].dev);
3043 + spin_unlock(&netdev_fc_lock);
3047 +static void get_sample_stats(int cpu)
3053 + int blog = softnet_data[cpu].input_pkt_queue.qlen;
3054 + int avg_blog = softnet_data[cpu].avg_blog;
3056 + avg_blog = (avg_blog >> 1)+ (blog >> 1);
3058 + if (avg_blog > mod_cong) {
3059 + /* Above moderate congestion levels. */
3060 + softnet_data[cpu].cng_level = NET_RX_CN_HIGH;
3062 + rd = net_random();
3063 + rq = rd % netdev_max_backlog;
3064 + if (rq < avg_blog) /* unlucky bastard */
3065 + softnet_data[cpu].cng_level = NET_RX_DROP;
3067 + } else if (avg_blog > lo_cong) {
3068 + softnet_data[cpu].cng_level = NET_RX_CN_MOD;
3070 + rd = net_random();
3071 + rq = rd % netdev_max_backlog;
3072 + if (rq < avg_blog) /* unlucky bastard */
3073 + softnet_data[cpu].cng_level = NET_RX_CN_HIGH;
3075 + } else if (avg_blog > no_cong)
3076 + softnet_data[cpu].cng_level = NET_RX_CN_LOW;
3077 + else /* no congestion */
3078 + softnet_data[cpu].cng_level = NET_RX_SUCCESS;
3080 + softnet_data[cpu].avg_blog = avg_blog;
3083 +#ifdef OFFLINE_SAMPLE
3084 +static void sample_queue(unsigned long dummy)
3086 +/* 10 ms 0r 1ms -- i dont care -- JHS */
3087 + int next_tick = 1;
3088 + int cpu = smp_processor_id();
3090 + get_sample_stats(cpu);
3091 + next_tick += jiffies;
3092 + mod_timer(&samp_timer, next_tick);
3098 + * netif_rx - post buffer to the network code
3099 + * @skb: buffer to post
3101 + * This function receives a packet from a device driver and queues it for
3102 + * the upper (protocol) levels to process. It always succeeds. The buffer
3103 + * may be dropped during processing for congestion control or by the
3104 + * protocol layers.
3107 + * NET_RX_SUCCESS (no congestion)
3108 + * NET_RX_CN_LOW (low congestion)
3109 + * NET_RX_CN_MOD (moderate congestion)
3110 + * NET_RX_CN_HIGH (high congestion)
3111 + * NET_RX_DROP (packet was dropped)
3116 +int netif_rx(struct sk_buff *skb)
3118 + int this_cpu = smp_processor_id();
3119 + struct softnet_data *queue;
3120 + unsigned long flags;
3122 + if (skb->stamp.tv_sec == 0)
3123 + do_gettimeofday(&skb->stamp);
3125 + /* The code is rearranged so that the path is the most
3126 + short when CPU is congested, but is still operating.
3128 + queue = &softnet_data[this_cpu];
3130 + local_irq_save(flags);
3132 + netdev_rx_stat[this_cpu].total++;
3133 + if (queue->input_pkt_queue.qlen <= netdev_max_backlog) {
3134 + if (queue->input_pkt_queue.qlen) {
3135 + if (queue->throttle)
3139 + dev_hold(skb->dev);
3140 + __skb_queue_tail(&queue->input_pkt_queue,skb);
3141 + local_irq_restore(flags);
3142 +#ifndef OFFLINE_SAMPLE
3143 + get_sample_stats(this_cpu);
3145 + return queue->cng_level;
3148 + if (queue->throttle) {
3149 + queue->throttle = 0;
3150 +#ifdef CONFIG_NET_HW_FLOWCONTROL
3151 + if (atomic_dec_and_test(&netdev_dropping))
3156 + netif_rx_schedule(&queue->blog_dev);
3160 + if (queue->throttle == 0) {
3161 + queue->throttle = 1;
3162 + netdev_rx_stat[this_cpu].throttled++;
3163 +#ifdef CONFIG_NET_HW_FLOWCONTROL
3164 + atomic_inc(&netdev_dropping);
3169 + netdev_rx_stat[this_cpu].dropped++;
3170 + local_irq_restore(flags);
3173 + return NET_RX_DROP;
3176 +/* Deliver skb to an old protocol, which is not threaded well
3177 + or which do not understand shared skbs.
3179 +static int deliver_to_old_ones(struct packet_type *pt, struct sk_buff *skb, int last)
3181 + static spinlock_t net_bh_lock = SPIN_LOCK_UNLOCKED;
3182 + int ret = NET_RX_DROP;
3186 + skb = skb_clone(skb, GFP_ATOMIC);
3190 + if (skb_is_nonlinear(skb) && skb_linearize(skb, GFP_ATOMIC) != 0) {
3195 + /* The assumption (correct one) is that old protocols
3196 + did not depened on BHs different of NET_BH and TIMER_BH.
3199 + /* Emulate NET_BH with special spinlock */
3200 + spin_lock(&net_bh_lock);
3202 + /* Disable timers and wait for all timers completion */
3203 + tasklet_disable(bh_task_vec+TIMER_BH);
3205 + ret = pt->func(skb, skb->dev, pt);
3207 + tasklet_hi_enable(bh_task_vec+TIMER_BH);
3208 + spin_unlock(&net_bh_lock);
3212 +static __inline__ void skb_bond(struct sk_buff *skb)
3214 + struct net_device *dev = skb->dev;
3216 + if (dev->master) {
3217 + skb->real_dev = skb->dev;
3218 + skb->dev = dev->master;
3222 +static void net_tx_action(struct softirq_action *h)
3224 + int cpu = smp_processor_id();
3226 + if (softnet_data[cpu].completion_queue) {
3227 + struct sk_buff *clist;
3229 + local_irq_disable();
3230 + clist = softnet_data[cpu].completion_queue;
3231 + softnet_data[cpu].completion_queue = NULL;
3232 + local_irq_enable();
3234 + while (clist != NULL) {
3235 + struct sk_buff *skb = clist;
3236 + clist = clist->next;
3238 + BUG_TRAP(atomic_read(&skb->users) == 0);
3243 + if (softnet_data[cpu].output_queue) {
3244 + struct net_device *head;
3246 + local_irq_disable();
3247 + head = softnet_data[cpu].output_queue;
3248 + softnet_data[cpu].output_queue = NULL;
3249 + local_irq_enable();
3251 + while (head != NULL) {
3252 + struct net_device *dev = head;
3253 + head = head->next_sched;
3255 + smp_mb__before_clear_bit();
3256 + clear_bit(__LINK_STATE_SCHED, &dev->state);
3258 + if (spin_trylock(&dev->queue_lock)) {
3260 + spin_unlock(&dev->queue_lock);
3262 + netif_schedule(dev);
3269 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
3270 +void (*br_handle_frame_hook)(struct sk_buff *skb) = NULL;
3273 +static __inline__ int handle_bridge(struct sk_buff *skb,
3274 + struct packet_type *pt_prev)
3276 + int ret = NET_RX_DROP;
3279 + if (!pt_prev->data)
3280 + ret = deliver_to_old_ones(pt_prev, skb, 0);
3282 + atomic_inc(&skb->users);
3283 + ret = pt_prev->func(skb, skb->dev, pt_prev);
3287 + br_handle_frame_hook(skb);
3292 +#ifdef CONFIG_NET_DIVERT
3293 +static inline int handle_diverter(struct sk_buff *skb)
3295 + /* if diversion is supported on device, then divert */
3296 + if (skb->dev->divert && skb->dev->divert->divert)
3297 + divert_frame(skb);
3300 +#endif /* CONFIG_NET_DIVERT */
3302 +int netif_receive_skb(struct sk_buff *skb)
3304 + struct packet_type *ptype, *pt_prev;
3305 + int ret = NET_RX_DROP;
3306 + unsigned short type;
3308 + if (skb->stamp.tv_sec == 0)
3309 + do_gettimeofday(&skb->stamp);
3313 + netdev_rx_stat[smp_processor_id()].total++;
3315 +#ifdef CONFIG_NET_FASTROUTE
3316 + if (skb->pkt_type == PACKET_FASTROUTE) {
3317 + netdev_rx_stat[smp_processor_id()].fastroute_deferred_out++;
3318 + return dev_queue_xmit(skb);
3322 + skb->h.raw = skb->nh.raw = skb->data;
3325 + for (ptype = ptype_all; ptype; ptype = ptype->next) {
3326 + if (!ptype->dev || ptype->dev == skb->dev) {
3328 + if (!pt_prev->data) {
3329 + ret = deliver_to_old_ones(pt_prev, skb, 0);
3331 + atomic_inc(&skb->users);
3332 + ret = pt_prev->func(skb, skb->dev, pt_prev);
3339 +#ifdef CONFIG_NET_DIVERT
3340 + if (skb->dev->divert && skb->dev->divert->divert)
3341 + ret = handle_diverter(skb);
3342 +#endif /* CONFIG_NET_DIVERT */
3344 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
3345 + if (skb->dev->br_port != NULL && br_handle_frame_hook != NULL &&
3346 + skb->pkt_type != PACKET_LOOPBACK) {
3347 + return handle_bridge(skb, pt_prev);
3351 + type = skb->protocol;
3352 + for (ptype=ptype_base[ntohs(type)&15];ptype;ptype=ptype->next) {
3353 + if (ptype->type == type &&
3354 + (!ptype->dev || ptype->dev == skb->dev)) {
3356 + if (!pt_prev->data) {
3357 + ret = deliver_to_old_ones(pt_prev, skb, 0);
3359 + atomic_inc(&skb->users);
3360 + ret = pt_prev->func(skb, skb->dev, pt_prev);
3368 + if (!pt_prev->data) {
3369 + ret = deliver_to_old_ones(pt_prev, skb, 1);
3371 + ret = pt_prev->func(skb, skb->dev, pt_prev);
3375 + /* Jamal, now you will not able to escape explaining
3376 + * me how you were going to use this. :-)
3378 + ret = NET_RX_DROP;
3384 +static int process_backlog(struct net_device *backlog_dev, int *budget)
3387 + int quota = min(backlog_dev->quota, *budget);
3388 + int this_cpu = smp_processor_id();
3389 + struct softnet_data *queue = &softnet_data[this_cpu];
3390 + unsigned long start_time = jiffies;
3393 + struct sk_buff *skb;
3394 + struct net_device *dev;
3396 + local_irq_disable();
3397 + skb = __skb_dequeue(&queue->input_pkt_queue);
3400 + local_irq_enable();
3404 + netif_receive_skb(skb);
3410 + if (work >= quota || jiffies - start_time > 1)
3413 +#ifdef CONFIG_NET_HW_FLOWCONTROL
3414 + if (queue->throttle && queue->input_pkt_queue.qlen < no_cong_thresh ) {
3415 + queue->throttle = 0;
3416 + if (atomic_dec_and_test(&netdev_dropping)) {
3424 + backlog_dev->quota -= work;
3429 + backlog_dev->quota -= work;
3432 + list_del(&backlog_dev->poll_list);
3433 + smp_mb__before_clear_bit();
3434 + netif_poll_enable(backlog_dev);
3436 + if (queue->throttle) {
3437 + queue->throttle = 0;
3438 +#ifdef CONFIG_NET_HW_FLOWCONTROL
3439 + if (atomic_dec_and_test(&netdev_dropping))
3443 + local_irq_enable();
3447 +static void net_rx_action(struct softirq_action *h)
3449 + int this_cpu = smp_processor_id();
3450 + struct softnet_data *queue = &softnet_data[this_cpu];
3451 + unsigned long start_time = jiffies;
3452 + int budget = netdev_max_backlog;
3454 + br_read_lock(BR_NETPROTO_LOCK);
3455 + local_irq_disable();
3457 + while (!list_empty(&queue->poll_list)) {
3458 + struct net_device *dev;
3460 + if (budget <= 0 || jiffies - start_time > 1)
3461 + goto softnet_break;
3463 + local_irq_enable();
3465 + dev = list_entry(queue->poll_list.next, struct net_device, poll_list);
3467 + if (dev->quota <= 0 || dev->poll(dev, &budget)) {
3468 + local_irq_disable();
3469 + list_del(&dev->poll_list);
3470 + list_add_tail(&dev->poll_list, &queue->poll_list);
3471 + if (dev->quota < 0)
3472 + dev->quota += dev->weight;
3474 + dev->quota = dev->weight;
3477 + local_irq_disable();
3481 + local_irq_enable();
3482 + br_read_unlock(BR_NETPROTO_LOCK);
3486 + netdev_rx_stat[this_cpu].time_squeeze++;
3487 + __cpu_raise_softirq(this_cpu, NET_RX_SOFTIRQ);
3489 + local_irq_enable();
3490 + br_read_unlock(BR_NETPROTO_LOCK);
3493 +static gifconf_func_t * gifconf_list [NPROTO];
3496 + * register_gifconf - register a SIOCGIF handler
3497 + * @family: Address family
3498 + * @gifconf: Function handler
3500 + * Register protocol dependent address dumping routines. The handler
3501 + * that is passed must not be freed or reused until it has been replaced
3502 + * by another handler.
3505 +int register_gifconf(unsigned int family, gifconf_func_t * gifconf)
3507 + if (family>=NPROTO)
3509 + gifconf_list[family] = gifconf;
3515 + * Map an interface index to its name (SIOCGIFNAME)
3519 + * We need this ioctl for efficient implementation of the
3520 + * if_indextoname() function required by the IPv6 API. Without
3521 + * it, we would have to search all the interfaces to find a
3525 +static int dev_ifname(struct ifreq *arg)
3527 + struct net_device *dev;
3531 + * Fetch the caller's info block.
3534 + if (copy_from_user(&ifr, arg, sizeof(struct ifreq)))
3537 + read_lock(&dev_base_lock);
3538 + dev = __dev_get_by_index(ifr.ifr_ifindex);
3540 + read_unlock(&dev_base_lock);
3544 + strcpy(ifr.ifr_name, dev->name);
3545 + read_unlock(&dev_base_lock);
3547 + if (copy_to_user(arg, &ifr, sizeof(struct ifreq)))
3553 + * Perform a SIOCGIFCONF call. This structure will change
3554 + * size eventually, and there is nothing I can do about it.
3555 + * Thus we will need a 'compatibility mode'.
3558 +static int dev_ifconf(char *arg)
3560 + struct ifconf ifc;
3561 + struct net_device *dev;
3568 + * Fetch the caller's info block.
3571 + if (copy_from_user(&ifc, arg, sizeof(struct ifconf)))
3574 + pos = ifc.ifc_buf;
3575 + len = ifc.ifc_len;
3578 + * Loop over the interfaces, and write an info block for each.
3582 + for (dev = dev_base; dev != NULL; dev = dev->next) {
3583 + for (i=0; i<NPROTO; i++) {
3584 + if (gifconf_list[i]) {
3587 + done = gifconf_list[i](dev, NULL, 0);
3589 + done = gifconf_list[i](dev, pos+total, len-total);
3600 + * All done. Write the updated control block back to the caller.
3602 + ifc.ifc_len = total;
3604 + if (copy_to_user(arg, &ifc, sizeof(struct ifconf)))
3608 + * Both BSD and Solaris return 0 here, so we do too.
3614 + * This is invoked by the /proc filesystem handler to display a device
3618 +#ifdef CONFIG_PROC_FS
3620 +static int sprintf_stats(char *buffer, struct net_device *dev)
3622 + struct net_device_stats *stats = (dev->get_stats ? dev->get_stats(dev): NULL);
3626 + size = sprintf(buffer, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu %8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
3629 + stats->rx_packets, stats->rx_errors,
3630 + stats->rx_dropped + stats->rx_missed_errors,
3631 + stats->rx_fifo_errors,
3632 + stats->rx_length_errors + stats->rx_over_errors
3633 + + stats->rx_crc_errors + stats->rx_frame_errors,
3634 + stats->rx_compressed, stats->multicast,
3636 + stats->tx_packets, stats->tx_errors, stats->tx_dropped,
3637 + stats->tx_fifo_errors, stats->collisions,
3638 + stats->tx_carrier_errors + stats->tx_aborted_errors
3639 + + stats->tx_window_errors + stats->tx_heartbeat_errors,
3640 + stats->tx_compressed);
3642 + size = sprintf(buffer, "%6s: No statistics available.\n", dev->name);
3648 + * Called from the PROCfs module. This now uses the new arbitrary sized /proc/net interface
3649 + * to create /proc/net/dev
3652 +static int dev_get_info(char *buffer, char **start, off_t offset, int length)
3658 + struct net_device *dev;
3661 + size = sprintf(buffer,
3662 + "Inter-| Receive | Transmit\n"
3663 + " face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed\n");
3669 + read_lock(&dev_base_lock);
3670 + for (dev = dev_base; dev != NULL; dev = dev->next) {
3671 + size = sprintf_stats(buffer+len, dev);
3673 + pos = begin + len;
3675 + if (pos < offset) {
3679 + if (pos > offset + length)
3682 + read_unlock(&dev_base_lock);
3684 + *start = buffer + (offset - begin); /* Start of wanted data */
3685 + len -= (offset - begin); /* Start slop */
3687 + len = length; /* Ending slop */
3693 +static int dev_proc_stats(char *buffer, char **start, off_t offset,
3694 + int length, int *eof, void *data)
3699 + for (lcpu=0; lcpu<smp_num_cpus; lcpu++) {
3700 + i = cpu_logical_map(lcpu);
3701 + len += sprintf(buffer+len, "%08x %08x %08x %08x %08x %08x %08x %08x %08x\n",
3702 + netdev_rx_stat[i].total,
3703 + netdev_rx_stat[i].dropped,
3704 + netdev_rx_stat[i].time_squeeze,
3705 + netdev_rx_stat[i].throttled,
3706 + netdev_rx_stat[i].fastroute_hit,
3707 + netdev_rx_stat[i].fastroute_success,
3708 + netdev_rx_stat[i].fastroute_defer,
3709 + netdev_rx_stat[i].fastroute_deferred_out,
3711 + netdev_rx_stat[i].fastroute_latency_reduction
3713 + netdev_rx_stat[i].cpu_collision
3725 + *start = buffer + offset;
3731 +#endif /* CONFIG_PROC_FS */
3735 + * netdev_set_master - set up master/slave pair
3736 + * @slave: slave device
3737 + * @master: new master device
3739 + * Changes the master device of the slave. Pass %NULL to break the
3740 + * bonding. The caller must hold the RTNL semaphore. On a failure
3741 + * a negative errno code is returned. On success the reference counts
3742 + * are adjusted, %RTM_NEWLINK is sent to the routing socket and the
3743 + * function returns zero.
3746 +int netdev_set_master(struct net_device *slave, struct net_device *master)
3748 + struct net_device *old = slave->master;
3758 + br_write_lock_bh(BR_NETPROTO_LOCK);
3759 + slave->master = master;
3760 + br_write_unlock_bh(BR_NETPROTO_LOCK);
3766 + slave->flags |= IFF_SLAVE;
3768 + slave->flags &= ~IFF_SLAVE;
3770 + rtmsg_ifinfo(RTM_NEWLINK, slave, IFF_SLAVE);
3775 + * dev_set_promiscuity - update promiscuity count on a device
3779 + * Add or remove promsicuity from a device. While the count in the device
3780 + * remains above zero the interface remains promiscuous. Once it hits zero
3781 + * the device reverts back to normal filtering operation. A negative inc
3782 + * value is used to drop promiscuity on the device.
3785 +void dev_set_promiscuity(struct net_device *dev, int inc)
3787 + unsigned short old_flags = dev->flags;
3789 + dev->flags |= IFF_PROMISC;
3790 + if ((dev->promiscuity += inc) == 0)
3791 + dev->flags &= ~IFF_PROMISC;
3792 + if (dev->flags^old_flags) {
3793 +#ifdef CONFIG_NET_FASTROUTE
3794 + if (dev->flags&IFF_PROMISC) {
3795 + netdev_fastroute_obstacles++;
3796 + dev_clear_fastroute(dev);
3798 + netdev_fastroute_obstacles--;
3800 + dev_mc_upload(dev);
3801 + printk(KERN_INFO "device %s %s promiscuous mode\n",
3802 + dev->name, (dev->flags&IFF_PROMISC) ? "entered" : "left");
3807 + * dev_set_allmulti - update allmulti count on a device
3811 + * Add or remove reception of all multicast frames to a device. While the
3812 + * count in the device remains above zero the interface remains listening
3813 + * to all interfaces. Once it hits zero the device reverts back to normal
3814 + * filtering operation. A negative @inc value is used to drop the counter
3815 + * when releasing a resource needing all multicasts.
3818 +void dev_set_allmulti(struct net_device *dev, int inc)
3820 + unsigned short old_flags = dev->flags;
3822 + dev->flags |= IFF_ALLMULTI;
3823 + if ((dev->allmulti += inc) == 0)
3824 + dev->flags &= ~IFF_ALLMULTI;
3825 + if (dev->flags^old_flags)
3826 + dev_mc_upload(dev);
3829 +int dev_change_flags(struct net_device *dev, unsigned flags)
3832 + int old_flags = dev->flags;
3835 + * Set the flags on our device.
3838 + dev->flags = (flags & (IFF_DEBUG|IFF_NOTRAILERS|IFF_NOARP|IFF_DYNAMIC|
3839 + IFF_MULTICAST|IFF_PORTSEL|IFF_AUTOMEDIA)) |
3840 + (dev->flags & (IFF_UP|IFF_VOLATILE|IFF_PROMISC|IFF_ALLMULTI));
3843 + * Load in the correct multicast list now the flags have changed.
3846 + dev_mc_upload(dev);
3849 + * Have we downed the interface. We handle IFF_UP ourselves
3850 + * according to user attempts to set it, rather than blindly
3855 + if ((old_flags^flags)&IFF_UP) /* Bit is different ? */
3857 + ret = ((old_flags & IFF_UP) ? dev_close : dev_open)(dev);
3860 + dev_mc_upload(dev);
3863 + if (dev->flags&IFF_UP &&
3864 + ((old_flags^dev->flags)&~(IFF_UP|IFF_PROMISC|IFF_ALLMULTI|IFF_VOLATILE)))
3865 + notifier_call_chain(&netdev_chain, NETDEV_CHANGE, dev);
3867 + if ((flags^dev->gflags)&IFF_PROMISC) {
3868 + int inc = (flags&IFF_PROMISC) ? +1 : -1;
3869 + dev->gflags ^= IFF_PROMISC;
3870 + dev_set_promiscuity(dev, inc);
3873 + /* NOTE: order of synchronization of IFF_PROMISC and IFF_ALLMULTI
3874 + is important. Some (broken) drivers set IFF_PROMISC, when
3875 + IFF_ALLMULTI is requested not asking us and not reporting.
3877 + if ((flags^dev->gflags)&IFF_ALLMULTI) {
3878 + int inc = (flags&IFF_ALLMULTI) ? +1 : -1;
3879 + dev->gflags ^= IFF_ALLMULTI;
3880 + dev_set_allmulti(dev, inc);
3883 + if (old_flags^dev->flags)
3884 + rtmsg_ifinfo(RTM_NEWLINK, dev, old_flags^dev->flags);
3890 + * Perform the SIOCxIFxxx calls.
3893 +static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
3895 + struct net_device *dev;
3898 + if ((dev = __dev_get_by_name(ifr->ifr_name)) == NULL)
3903 + case SIOCGIFFLAGS: /* Get interface flags */
3904 + ifr->ifr_flags = (dev->flags&~(IFF_PROMISC|IFF_ALLMULTI|IFF_RUNNING))
3905 + |(dev->gflags&(IFF_PROMISC|IFF_ALLMULTI));
3906 + if (netif_running(dev) && netif_carrier_ok(dev))
3907 + ifr->ifr_flags |= IFF_RUNNING;
3910 + case SIOCSIFFLAGS: /* Set interface flags */
3911 + return dev_change_flags(dev, ifr->ifr_flags);
3913 + case SIOCGIFMETRIC: /* Get the metric on the interface (currently unused) */
3914 + ifr->ifr_metric = 0;
3917 + case SIOCSIFMETRIC: /* Set the metric on the interface (currently unused) */
3918 + return -EOPNOTSUPP;
3920 + case SIOCGIFMTU: /* Get the MTU of a device */
3921 + ifr->ifr_mtu = dev->mtu;
3924 + case SIOCSIFMTU: /* Set the MTU of a device */
3925 + if (ifr->ifr_mtu == dev->mtu)
3929 + * MTU must be positive.
3932 + if (ifr->ifr_mtu<0)
3935 + if (!netif_device_present(dev))
3938 + if (dev->change_mtu)
3939 + err = dev->change_mtu(dev, ifr->ifr_mtu);
3941 + dev->mtu = ifr->ifr_mtu;
3944 + if (!err && dev->flags&IFF_UP)
3945 + notifier_call_chain(&netdev_chain, NETDEV_CHANGEMTU, dev);
3948 + case SIOCGIFHWADDR:
3949 + memcpy(ifr->ifr_hwaddr.sa_data,dev->dev_addr, MAX_ADDR_LEN);
3950 + ifr->ifr_hwaddr.sa_family=dev->type;
3953 + case SIOCSIFHWADDR:
3954 + if (dev->set_mac_address == NULL)
3955 + return -EOPNOTSUPP;
3956 + if (ifr->ifr_hwaddr.sa_family!=dev->type)
3958 + if (!netif_device_present(dev))
3960 + err = dev->set_mac_address(dev, &ifr->ifr_hwaddr);
3962 + notifier_call_chain(&netdev_chain, NETDEV_CHANGEADDR, dev);
3965 + case SIOCSIFHWBROADCAST:
3966 + if (ifr->ifr_hwaddr.sa_family!=dev->type)
3968 + memcpy(dev->broadcast, ifr->ifr_hwaddr.sa_data, MAX_ADDR_LEN);
3969 + notifier_call_chain(&netdev_chain, NETDEV_CHANGEADDR, dev);
3973 + ifr->ifr_map.mem_start=dev->mem_start;
3974 + ifr->ifr_map.mem_end=dev->mem_end;
3975 + ifr->ifr_map.base_addr=dev->base_addr;
3976 + ifr->ifr_map.irq=dev->irq;
3977 + ifr->ifr_map.dma=dev->dma;
3978 + ifr->ifr_map.port=dev->if_port;
3982 + if (dev->set_config) {
3983 + if (!netif_device_present(dev))
3985 + return dev->set_config(dev,&ifr->ifr_map);
3987 + return -EOPNOTSUPP;
3989 + case SIOCADDMULTI:
3990 + if (dev->set_multicast_list == NULL ||
3991 + ifr->ifr_hwaddr.sa_family != AF_UNSPEC)
3993 + if (!netif_device_present(dev))
3995 + dev_mc_add(dev,ifr->ifr_hwaddr.sa_data, dev->addr_len, 1);
3998 + case SIOCDELMULTI:
3999 + if (dev->set_multicast_list == NULL ||
4000 + ifr->ifr_hwaddr.sa_family!=AF_UNSPEC)
4002 + if (!netif_device_present(dev))
4004 + dev_mc_delete(dev,ifr->ifr_hwaddr.sa_data,dev->addr_len, 1);
4007 + case SIOCGIFINDEX:
4008 + ifr->ifr_ifindex = dev->ifindex;
4011 + case SIOCGIFTXQLEN:
4012 + ifr->ifr_qlen = dev->tx_queue_len;
4015 + case SIOCSIFTXQLEN:
4016 + if (ifr->ifr_qlen<0)
4018 + dev->tx_queue_len = ifr->ifr_qlen;
4022 + if (dev->flags&IFF_UP)
4024 + /* Check if name contains a wildcard */
4025 + if (strchr(ifr->ifr_newname, '%')) {
4026 + char format[IFNAMSIZ + 1];
4028 + memcpy(format, ifr->ifr_newname, IFNAMSIZ);
4029 + format[IFNAMSIZ-1] = 0;
4030 + /* Find a free name based on format.
4031 + * dev_alloc_name() replaces "%d" with at max
4032 + * 2 digits, so no name overflow. - Jean II */
4033 + ret = dev_alloc_name(dev, format);
4036 + /* Copy the new name back to caller. */
4037 + strncpy(ifr->ifr_newname, dev->name, IFNAMSIZ);
4039 + if (__dev_get_by_name(ifr->ifr_newname))
4041 + memcpy(dev->name, ifr->ifr_newname, IFNAMSIZ);
4042 + dev->name[IFNAMSIZ-1] = 0;
4044 + notifier_call_chain(&netdev_chain, NETDEV_CHANGENAME, dev);
4048 + * Unknown or private ioctl
4052 + if ((cmd >= SIOCDEVPRIVATE &&
4053 + cmd <= SIOCDEVPRIVATE + 15) ||
4054 + cmd == SIOCBONDENSLAVE ||
4055 + cmd == SIOCBONDRELEASE ||
4056 + cmd == SIOCBONDSETHWADDR ||
4057 + cmd == SIOCBONDSLAVEINFOQUERY ||
4058 + cmd == SIOCBONDINFOQUERY ||
4059 + cmd == SIOCBONDCHANGEACTIVE ||
4060 + cmd == SIOCGMIIPHY ||
4061 + cmd == SIOCGMIIREG ||
4062 + cmd == SIOCSMIIREG ||
4063 + cmd == SIOCWANDEV) {
4064 + if (dev->do_ioctl) {
4065 + if (!netif_device_present(dev))
4067 + return dev->do_ioctl(dev, ifr, cmd);
4069 + return -EOPNOTSUPP;
4077 + * This function handles all "interface"-type I/O control requests. The actual
4078 + * 'doing' part of this is dev_ifsioc above.
4082 + * dev_ioctl - network device ioctl
4083 + * @cmd: command to issue
4084 + * @arg: pointer to a struct ifreq in user space
4086 + * Issue ioctl functions to devices. This is normally called by the
4087 + * user space syscall interfaces but can sometimes be useful for
4088 + * other purposes. The return value is the return from the syscall if
4089 + * positive or a negative errno code on error.
4092 +int dev_ioctl(unsigned int cmd, void *arg)
4098 + /* One special case: SIOCGIFCONF takes ifconf argument
4099 + and requires shared lock, because it sleeps writing
4103 + if (cmd == SIOCGIFCONF) {
4105 + ret = dev_ifconf((char *) arg);
4109 + if (cmd == SIOCGIFNAME) {
4110 + return dev_ifname((struct ifreq *)arg);
4113 + if (copy_from_user(&ifr, arg, sizeof(struct ifreq)))
4116 + ifr.ifr_name[IFNAMSIZ-1] = 0;
4118 + colon = strchr(ifr.ifr_name, ':');
4123 + * See which interface the caller is talking about.
4129 + * These ioctl calls:
4130 + * - can be done by all.
4131 + * - atomic and do not require locking.
4132 + * - return a value
4135 + case SIOCGIFFLAGS:
4136 + case SIOCGIFMETRIC:
4138 + case SIOCGIFHWADDR:
4139 + case SIOCGIFSLAVE:
4141 + case SIOCGIFINDEX:
4142 + case SIOCGIFTXQLEN:
4143 + dev_load(ifr.ifr_name);
4144 + read_lock(&dev_base_lock);
4145 + ret = dev_ifsioc(&ifr, cmd);
4146 + read_unlock(&dev_base_lock);
4150 + if (copy_to_user(arg, &ifr, sizeof(struct ifreq)))
4156 + dev_load(ifr.ifr_name);
4158 + ret = dev_ethtool(&ifr);
4163 + if (copy_to_user(arg, &ifr,
4164 + sizeof(struct ifreq)))
4170 + * These ioctl calls:
4171 + * - require superuser power.
4172 + * - require strict serialization.
4173 + * - return a value
4179 + if (!capable(CAP_NET_ADMIN))
4181 + dev_load(ifr.ifr_name);
4184 + ret = dev_ifsioc(&ifr, cmd);
4186 + dev_probe_unlock();
4190 + if (copy_to_user(arg, &ifr, sizeof(struct ifreq)))
4196 + * These ioctl calls:
4197 + * - require superuser power.
4198 + * - require strict serialization.
4199 + * - do not return a value
4202 + case SIOCSIFFLAGS:
4203 + case SIOCSIFMETRIC:
4206 + case SIOCSIFHWADDR:
4207 + case SIOCSIFSLAVE:
4208 + case SIOCADDMULTI:
4209 + case SIOCDELMULTI:
4210 + case SIOCSIFHWBROADCAST:
4211 + case SIOCSIFTXQLEN:
4213 + case SIOCBONDENSLAVE:
4214 + case SIOCBONDRELEASE:
4215 + case SIOCBONDSETHWADDR:
4216 + case SIOCBONDSLAVEINFOQUERY:
4217 + case SIOCBONDINFOQUERY:
4218 + case SIOCBONDCHANGEACTIVE:
4219 + if (!capable(CAP_NET_ADMIN))
4221 + dev_load(ifr.ifr_name);
4224 + ret = dev_ifsioc(&ifr, cmd);
4226 + dev_probe_unlock();
4230 + /* Get the per device memory space. We can add this but currently
4231 + do not support it */
4233 + /* Set the per device memory buffer space. Not applicable in our case */
4238 + * Unknown or private ioctl.
4242 + if (cmd == SIOCWANDEV ||
4243 + (cmd >= SIOCDEVPRIVATE &&
4244 + cmd <= SIOCDEVPRIVATE + 15)) {
4245 + dev_load(ifr.ifr_name);
4248 + ret = dev_ifsioc(&ifr, cmd);
4250 + dev_probe_unlock();
4251 + if (!ret && copy_to_user(arg, &ifr, sizeof(struct ifreq)))
4255 +#ifdef WIRELESS_EXT
4256 + /* Take care of Wireless Extensions */
4257 + if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) {
4258 + /* If command is `set a parameter', or
4259 + * `get the encoding parameters', check if
4260 + * the user has the right to do it */
4261 + if (IW_IS_SET(cmd) || (cmd == SIOCGIWENCODE)) {
4262 + if(!capable(CAP_NET_ADMIN))
4265 + dev_load(ifr.ifr_name);
4267 + /* Follow me in net/core/wireless.c */
4268 + ret = wireless_process_ioctl(&ifr, cmd);
4270 + if (!ret && IW_IS_GET(cmd) &&
4271 + copy_to_user(arg, &ifr, sizeof(struct ifreq)))
4275 +#endif /* WIRELESS_EXT */
4282 + * dev_new_index - allocate an ifindex
4284 + * Returns a suitable unique value for a new device interface
4285 + * number. The caller must hold the rtnl semaphore or the
4286 + * dev_base_lock to be sure it remains unique.
4289 +int dev_new_index(void)
4291 + static int ifindex;
4293 + if (++ifindex <= 0)
4295 + if (__dev_get_by_index(ifindex) == NULL)
4300 +static int dev_boot_phase = 1;
4303 + * register_netdevice - register a network device
4304 + * @dev: device to register
4306 + * Take a completed network device structure and add it to the kernel
4307 + * interfaces. A %NETDEV_REGISTER message is sent to the netdev notifier
4308 + * chain. 0 is returned on success. A negative errno code is returned
4309 + * on a failure to set up the device, or if the name is a duplicate.
4311 + * Callers must hold the rtnl semaphore. See the comment at the
4312 + * end of Space.c for details about the locking. You may want
4313 + * register_netdev() instead of this.
4316 + * The locking appears insufficient to guarantee two parallel registers
4317 + * will not get the same name.
4320 +int net_dev_init(void);
4322 +int register_netdevice(struct net_device *dev)
4324 + struct net_device *d, **dp;
4325 +#ifdef CONFIG_NET_DIVERT
4329 + spin_lock_init(&dev->queue_lock);
4330 + spin_lock_init(&dev->xmit_lock);
4331 + dev->xmit_lock_owner = -1;
4332 +#ifdef CONFIG_NET_FASTROUTE
4333 + dev->fastpath_lock=RW_LOCK_UNLOCKED;
4336 + if (dev_boot_phase)
4339 +#ifdef CONFIG_NET_DIVERT
4340 + ret = alloc_divert_blk(dev);
4343 +#endif /* CONFIG_NET_DIVERT */
4347 + /* Init, if this function is available */
4348 + if (dev->init && dev->init(dev) != 0) {
4349 +#ifdef CONFIG_NET_DIVERT
4350 + free_divert_blk(dev);
4355 + dev->ifindex = dev_new_index();
4356 + if (dev->iflink == -1)
4357 + dev->iflink = dev->ifindex;
4359 + /* Check for existence, and append to tail of chain */
4360 + for (dp=&dev_base; (d=*dp) != NULL; dp=&d->next) {
4361 + if (d == dev || strcmp(d->name, dev->name) == 0) {
4362 +#ifdef CONFIG_NET_DIVERT
4363 + free_divert_blk(dev);
4369 + /* Fix illegal SG+CSUM combinations. */
4370 + if ((dev->features & NETIF_F_SG) &&
4371 + !(dev->features & (NETIF_F_IP_CSUM |
4373 + NETIF_F_HW_CSUM))) {
4374 + printk("%s: Dropping NETIF_F_SG since no checksum feature.\n",
4376 + dev->features &= ~NETIF_F_SG;
4380 + * nil rebuild_header routine,
4381 + * that should be never called and used as just bug trap.
4384 + if (dev->rebuild_header == NULL)
4385 + dev->rebuild_header = default_rebuild_header;
4388 + * Default initial state at registry is that the
4389 + * device is present.
4392 + set_bit(__LINK_STATE_PRESENT, &dev->state);
4395 + dev_init_scheduler(dev);
4396 + write_lock_bh(&dev_base_lock);
4399 + dev->deadbeaf = 0;
4400 + write_unlock_bh(&dev_base_lock);
4402 + /* Notify protocols, that a new device appeared. */
4403 + notifier_call_chain(&netdev_chain, NETDEV_REGISTER, dev);
4405 + net_run_sbin_hotplug(dev, "register");
4411 + * netdev_finish_unregister - complete unregistration
4414 + * Destroy and free a dead device. A value of zero is returned on
4418 +int netdev_finish_unregister(struct net_device *dev)
4420 + BUG_TRAP(dev->ip_ptr==NULL);
4421 + BUG_TRAP(dev->ip6_ptr==NULL);
4422 + BUG_TRAP(dev->dn_ptr==NULL);
4424 + if (!dev->deadbeaf) {
4425 + printk(KERN_ERR "Freeing alive device %p, %s\n", dev, dev->name);
4428 +#ifdef NET_REFCNT_DEBUG
4429 + printk(KERN_DEBUG "netdev_finish_unregister: %s%s.\n", dev->name,
4430 + (dev->features & NETIF_F_DYNALLOC)?"":", old style");
4432 + if (dev->destructor)
4433 + dev->destructor(dev);
4434 + if (dev->features & NETIF_F_DYNALLOC)
4440 + * unregister_netdevice - remove device from the kernel
4443 + * This function shuts down a device interface and removes it
4444 + * from the kernel tables. On success 0 is returned, on a failure
4445 + * a negative errno code is returned.
4447 + * Callers must hold the rtnl semaphore. See the comment at the
4448 + * end of Space.c for details about the locking. You may want
4449 + * unregister_netdev() instead of this.
4452 +int unregister_netdevice(struct net_device *dev)
4454 + unsigned long now, warning_time;
4455 + struct net_device *d, **dp;
4457 + /* If device is running, close it first. */
4458 + if (dev->flags & IFF_UP)
4461 + BUG_TRAP(dev->deadbeaf==0);
4462 + dev->deadbeaf = 1;
4464 + /* And unlink it from device chain. */
4465 + for (dp = &dev_base; (d=*dp) != NULL; dp=&d->next) {
4467 + write_lock_bh(&dev_base_lock);
4469 + write_unlock_bh(&dev_base_lock);
4474 + printk(KERN_DEBUG "unregister_netdevice: device %s/%p never was registered\n", dev->name, dev);
4478 + /* Synchronize to net_rx_action. */
4479 + br_write_lock_bh(BR_NETPROTO_LOCK);
4480 + br_write_unlock_bh(BR_NETPROTO_LOCK);
4482 + if (dev_boot_phase == 0) {
4483 +#ifdef CONFIG_NET_FASTROUTE
4484 + dev_clear_fastroute(dev);
4487 + /* Shutdown queueing discipline. */
4488 + dev_shutdown(dev);
4490 + net_run_sbin_hotplug(dev, "unregister");
4492 + /* Notify protocols, that we are about to destroy
4493 + this device. They should clean all the things.
4495 + notifier_call_chain(&netdev_chain, NETDEV_UNREGISTER, dev);
4498 + * Flush the multicast chain
4500 + dev_mc_discard(dev);
4506 + /* Notifier chain MUST detach us from master device. */
4507 + BUG_TRAP(dev->master==NULL);
4509 +#ifdef CONFIG_NET_DIVERT
4510 + free_divert_blk(dev);
4513 + if (dev->features & NETIF_F_DYNALLOC) {
4514 +#ifdef NET_REFCNT_DEBUG
4515 + if (atomic_read(&dev->refcnt) != 1)
4516 + printk(KERN_DEBUG "unregister_netdevice: holding %s refcnt=%d\n", dev->name, atomic_read(&dev->refcnt)-1);
4522 + /* Last reference is our one */
4523 + if (atomic_read(&dev->refcnt) == 1) {
4528 +#ifdef NET_REFCNT_DEBUG
4529 + printk("unregister_netdevice: waiting %s refcnt=%d\n", dev->name, atomic_read(&dev->refcnt));
4532 + /* EXPLANATION. If dev->refcnt is not now 1 (our own reference)
4533 + it means that someone in the kernel still has a reference
4534 + to this device and we cannot release it.
4536 + "New style" devices have destructors, hence we can return from this
4537 + function and destructor will do all the work later. As of kernel 2.4.0
4538 + there are very few "New Style" devices.
4540 + "Old style" devices expect that the device is free of any references
4541 + upon exit from this function.
4542 + We cannot return from this function until all such references have
4543 + fallen away. This is because the caller of this function will probably
4544 + immediately kfree(*dev) and then be unloaded via sys_delete_module.
4546 + So, we linger until all references fall away. The duration of the
4547 + linger is basically unbounded! It is driven by, for example, the
4548 + current setting of sysctl_ipfrag_time.
4550 + After 1 second, we start to rebroadcast unregister notifications
4551 + in hope that careless clients will release the device.
4555 + now = warning_time = jiffies;
4556 + while (atomic_read(&dev->refcnt) != 1) {
4557 + if ((jiffies - now) > 1*HZ) {
4558 + /* Rebroadcast unregister notification */
4559 + notifier_call_chain(&netdev_chain, NETDEV_UNREGISTER, dev);
4561 + current->state = TASK_INTERRUPTIBLE;
4562 + schedule_timeout(HZ/4);
4563 + current->state = TASK_RUNNING;
4564 + if ((jiffies - warning_time) > 10*HZ) {
4565 + printk(KERN_EMERG "unregister_netdevice: waiting for %s to "
4566 + "become free. Usage count = %d\n",
4567 + dev->name, atomic_read(&dev->refcnt));
4568 + warning_time = jiffies;
4577 + * Initialize the DEV module. At boot time this walks the device list and
4578 + * unhooks any devices that fail to initialise (normally hardware not
4579 + * present) and leaves us with a valid list of present and active devices.
4583 +extern void net_device_init(void);
4584 +extern void ip_auto_config(void);
4585 +struct proc_dir_entry *proc_net_drivers;
4586 +#ifdef CONFIG_NET_DIVERT
4587 +extern void dv_init(void);
4588 +#endif /* CONFIG_NET_DIVERT */
4592 + * Callers must hold the rtnl semaphore. See the comment at the
4593 + * end of Space.c for details about the locking.
4595 +int __init net_dev_init(void)
4597 + struct net_device *dev, **dp;
4600 + if (!dev_boot_phase)
4604 +#ifdef CONFIG_NET_DIVERT
4606 +#endif /* CONFIG_NET_DIVERT */
4609 + * Initialise the packet receive queues.
4612 + for (i = 0; i < NR_CPUS; i++) {
4613 + struct softnet_data *queue;
4615 + queue = &softnet_data[i];
4616 + skb_queue_head_init(&queue->input_pkt_queue);
4617 + queue->throttle = 0;
4618 + queue->cng_level = 0;
4619 + queue->avg_blog = 10; /* arbitrary non-zero */
4620 + queue->completion_queue = NULL;
4621 + INIT_LIST_HEAD(&queue->poll_list);
4622 + set_bit(__LINK_STATE_START, &queue->blog_dev.state);
4623 + queue->blog_dev.weight = weight_p;
4624 + queue->blog_dev.poll = process_backlog;
4625 + atomic_set(&queue->blog_dev.refcnt, 1);
4628 +#ifdef CONFIG_NET_PROFILE
4629 + net_profile_init();
4630 + NET_PROFILE_REGISTER(dev_queue_xmit);
4631 + NET_PROFILE_REGISTER(softnet_process);
4634 +#ifdef OFFLINE_SAMPLE
4635 + samp_timer.expires = jiffies + (10 * HZ);
4636 + add_timer(&samp_timer);
4640 + * Add the devices.
4641 + * If the call to dev->init fails, the dev is removed
4642 + * from the chain disconnecting the device until the
4645 + * NB At boot phase networking is dead. No locking is required.
4646 + * But we still preserve dev_base_lock for sanity.
4650 + while ((dev = *dp) != NULL) {
4651 + spin_lock_init(&dev->queue_lock);
4652 + spin_lock_init(&dev->xmit_lock);
4653 +#ifdef CONFIG_NET_FASTROUTE
4654 + dev->fastpath_lock = RW_LOCK_UNLOCKED;
4656 + dev->xmit_lock_owner = -1;
4661 + * Allocate name. If the init() fails
4662 + * the name will be reissued correctly.
4664 + if (strchr(dev->name, '%'))
4665 + dev_alloc_name(dev, dev->name);
4668 + * Check boot time settings for the device.
4670 + netdev_boot_setup_check(dev);
4672 + if (dev->init && dev->init(dev)) {
4674 + * It failed to come up. It will be unhooked later.
4675 + * dev_alloc_name can now advance to next suitable
4676 + * name that is checked next.
4678 + dev->deadbeaf = 1;
4682 + dev->ifindex = dev_new_index();
4683 + if (dev->iflink == -1)
4684 + dev->iflink = dev->ifindex;
4685 + if (dev->rebuild_header == NULL)
4686 + dev->rebuild_header = default_rebuild_header;
4687 + dev_init_scheduler(dev);
4688 + set_bit(__LINK_STATE_PRESENT, &dev->state);
4693 + * Unhook devices that failed to come up
4696 + while ((dev = *dp) != NULL) {
4697 + if (dev->deadbeaf) {
4698 + write_lock_bh(&dev_base_lock);
4700 + write_unlock_bh(&dev_base_lock);
4707 +#ifdef CONFIG_PROC_FS
4708 + proc_net_create("dev", 0, dev_get_info);
4709 + create_proc_read_entry("net/softnet_stat", 0, 0, dev_proc_stats, NULL);
4710 + proc_net_drivers = proc_mkdir("net/drivers", 0);
4711 +#ifdef WIRELESS_EXT
4712 + /* Available in net/core/wireless.c */
4713 + proc_net_create("wireless", 0, dev_get_wireless_info);
4714 +#endif /* WIRELESS_EXT */
4715 +#endif /* CONFIG_PROC_FS */
4717 + dev_boot_phase = 0;
4719 + open_softirq(NET_TX_SOFTIRQ, net_tx_action, NULL);
4720 + open_softirq(NET_RX_SOFTIRQ, net_rx_action, NULL);
4725 +#ifdef CONFIG_NET_SCHED
4729 + * Initialise network devices
4732 + net_device_init();
4737 +#ifdef CONFIG_HOTPLUG
4739 +/* Notify userspace when a netdevice event occurs,
4740 + * by running '/sbin/hotplug net' with certain
4741 + * environment variables set.
4744 +static int net_run_sbin_hotplug(struct net_device *dev, char *action)
4746 + char *argv[3], *envp[5], ifname[12 + IFNAMSIZ], action_str[32];
4749 + sprintf(ifname, "INTERFACE=%s", dev->name);
4750 + sprintf(action_str, "ACTION=%s", action);
4753 + argv[i++] = hotplug_path;
4754 + argv[i++] = "net";
4758 + /* minimal command environment */
4759 + envp [i++] = "HOME=/";
4760 + envp [i++] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
4761 + envp [i++] = ifname;
4762 + envp [i++] = action_str;
4765 + return call_usermodehelper(argv [0], argv, envp);
4768 diff --unified --recursive --new-file linux-2.4.30/net/netsyms.c linux-2.4.30-1-686-smp-ring3/net/netsyms.c
4769 --- linux-2.4.30/net/netsyms.c 2005-04-04 03:42:20.000000000 +0200
4770 +++ linux-2.4.30-1-686-smp-ring3/net/netsyms.c 2005-10-22 23:08:28.016050500 +0200
4771 @@ -628,3 +628,18 @@
4772 #endif /* CONFIG_NET_RADIO || CONFIG_NET_PCMCIA_RADIO */
4774 #endif /* CONFIG_NET */
4775 +#if defined (CONFIG_RING) || defined(CONFIG_RING_MODULE)
4776 +#include <linux/version.h>
4778 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
4779 +#include <linux/ring.h>
4781 +EXPORT_SYMBOL(get_skb_ring_handler);
4782 +EXPORT_SYMBOL(set_skb_ring_handler);
4783 +EXPORT_SYMBOL(do_skb_ring_handler);
4784 +EXPORT_SYMBOL(get_buffer_ring_handler);
4785 +EXPORT_SYMBOL(set_buffer_ring_handler);
4786 +EXPORT_SYMBOL(do_buffer_ring_handler);
4790 diff --unified --recursive --new-file linux-2.4.30/net/ring/Config.in linux-2.4.30-1-686-smp-ring3/net/ring/Config.in
4791 --- linux-2.4.30/net/ring/Config.in 1970-01-01 01:00:00.000000000 +0100
4792 +++ linux-2.4.30-1-686-smp-ring3/net/ring/Config.in 2005-10-22 23:08:28.048052500 +0200
4797 +tristate ' PF_RING (EXPERIMENTAL)' CONFIG_RING
4798 diff --unified --recursive --new-file linux-2.4.30/net/ring/Makefile linux-2.4.30-1-686-smp-ring3/net/ring/Makefile
4799 --- linux-2.4.30/net/ring/Makefile 1970-01-01 01:00:00.000000000 +0100
4800 +++ linux-2.4.30-1-686-smp-ring3/net/ring/Makefile 2005-10-22 23:08:27.420013250 +0200
4803 +# Makefile for the ring driver.
4808 +export-objs := ring_packet.o
4810 +obj-y := ring_packet.o
4812 +ifeq ($(CONFIG_RING),m)
4813 + obj-m += $(O_TARGET)
4816 +include $(TOPDIR)/Rules.make
4818 diff --unified --recursive --new-file linux-2.4.30/net/ring/ring_packet.c linux-2.4.30-1-686-smp-ring3/net/ring/ring_packet.c
4819 --- linux-2.4.30/net/ring/ring_packet.c 1970-01-01 01:00:00.000000000 +0100
4820 +++ linux-2.4.30-1-686-smp-ring3/net/ring/ring_packet.c 2005-10-22 23:08:27.440014500 +0200
4824 + * (C) 2004-05 - Luca Deri <deri@ntop.org>
4826 + * This code includes patches courtesy of
4827 + * - Jeff Randall <jrandall@nexvu.com>
4828 + * - Helmut Manck <helmut.manck@secunet.com>
4829 + * - Brad Doctor <bdoctor@ps-ax.com>
4833 +/* FIX: add an entry inside the /proc filesystem */
4835 +#include <linux/version.h>
4836 +#include <linux/config.h>
4837 +#include <linux/module.h>
4838 +#include <linux/kernel.h>
4839 +#include <linux/socket.h>
4840 +#include <linux/skbuff.h>
4841 +#include <linux/rtnetlink.h>
4842 +#include <linux/in.h>
4843 +#include <linux/in6.h>
4844 +#include <linux/init.h>
4845 +#include <linux/filter.h>
4846 +#include <linux/ring.h>
4847 +#include <linux/ip.h>
4848 +#include <linux/tcp.h>
4849 +#include <linux/udp.h>
4850 +#include <linux/list.h>
4851 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
4852 +#include <net/xfrm.h>
4854 +#include <linux/poll.h>
4856 +#include <net/sock.h>
4857 +#include <asm/io.h> /* needed for virt_to_phys() */
4859 +/* #define RING_DEBUG */
4861 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11))
4862 +static inline int remap_page_range(struct vm_area_struct *vma,
4863 + unsigned long uvaddr,
4864 + unsigned long paddr,
4865 + unsigned long size,
4867 + return(remap_pfn_range(vma, uvaddr, paddr >> PAGE_SHIFT,
4872 +/* ************************************************* */
4874 +#define CLUSTER_LEN 8
4876 +struct ring_cluster {
4877 + u_short cluster_id; /* 0 = no cluster */
4878 + u_short num_cluster_elements;
4879 + enum cluster_type hashing_mode;
4880 + u_short hashing_id;
4881 + struct sock *sk[CLUSTER_LEN];
4882 + struct ring_cluster *next; /* NULL = last element of the cluster */
4885 +/* ************************************************* */
4887 +struct ring_element {
4888 + struct list_head list;
4892 +/* ************************************************* */
4895 + struct net_device *ring_netdev;
4898 + u_short cluster_id; /* 0 = no cluster */
4901 + struct net_device *reflector_dev;
4903 + /* Packet buffers */
4904 + unsigned long order;
4907 + unsigned long ring_memory;
4908 + FlowSlotInfo *slots_info; /* Basically it points to ring_memory */
4909 + char *ring_slots; /* Basically it points to ring_memory
4910 + +sizeof(FlowSlotInfo) */
4912 + /* Packet Sampling */
4913 + u_int pktToSample, sample_rate;
4916 + struct sk_filter *bpfFilter;
4919 + atomic_t num_ring_slots_waiters;
4920 + wait_queue_head_t ring_slots_waitqueue;
4921 + rwlock_t ring_index_lock;
4923 + /* Indexes (Internal) */
4924 + u_int insert_page_id, insert_slot_id;
4927 +/* ************************************************* */
4929 +/* List of all ring sockets. */
4930 +static struct list_head ring_table;
4932 +/* List of all clusters */
4933 +static struct ring_cluster *ring_cluster_list;
4935 +static rwlock_t ring_mgmt_lock = RW_LOCK_UNLOCKED;
4937 +/* ********************************** */
4940 +static struct proto_ops ring_ops;
4942 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,11))
4943 +static struct proto ring_proto;
4946 +static int skb_ring_handler(struct sk_buff *skb, u_char recv_packet,
4948 +static int buffer_ring_handler(struct net_device *dev, char *data, int len);
4949 +static int remove_from_cluster(struct sock *sock, struct ring_opt *pfr);
4953 +/* ********************************** */
4956 +static u_int bucket_len = 128, num_slots = 4096, sample_rate = 1,
4957 + transparent_mode = 0, enable_tx_capture = 0;
4959 +MODULE_PARM(bucket_len, "i");
4960 +MODULE_PARM_DESC(bucket_len, "Number of ring buckets");
4961 +MODULE_PARM(num_slots, "i");
4962 +MODULE_PARM_DESC(num_slots, "Number of ring slots");
4963 +MODULE_PARM(sample_rate, "i");
4964 +MODULE_PARM_DESC(sample_rate, "Ring packet sample rate");
4965 +MODULE_PARM(transparent_mode, "i");
4966 +MODULE_PARM_DESC(transparent_mode,
4967 + "Set to 1 to set transparent mode "
4968 + "(slower but backwards compatible)");
4969 +MODULE_PARM(enable_tx_capture, "i");
4970 +MODULE_PARM_DESC(enable_tx_capture, "Set to 1 to capture outgoing packets");
4972 +/* ********************************** */
4974 +#define MIN_QUEUED_PKTS 64
4975 +#define MAX_QUEUE_LOOPS 64
4978 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
4979 +#define ring_sk_datatype(__sk) ((struct ring_opt *)__sk)
4980 +#define ring_sk(__sk) ((__sk)->sk_protinfo)
4982 +#define ring_sk_datatype(a) (a)
4983 +#define ring_sk(__sk) ((__sk)->protinfo.pf_ring)
4986 +#define _rdtsc() ({ uint64_t x; asm volatile("rdtsc" : "=A" (x)); x; })
4989 + int dev_queue_xmit(struct sk_buff *skb)
4991 + struct net_device *dev_get_by_name(const char *name)
4994 +/* ********************************** */
4996 +static void ring_sock_destruct(struct sock *sk) {
4998 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
4999 + skb_queue_purge(&sk->sk_receive_queue);
5001 + if (!sock_flag(sk, SOCK_DEAD)) {
5002 +#if defined(RING_DEBUG)
5003 + printk("Attempt to release alive ring socket: %p\n", sk);
5008 + BUG_TRAP(!atomic_read(&sk->sk_rmem_alloc));
5009 + BUG_TRAP(!atomic_read(&sk->sk_wmem_alloc));
5012 + BUG_TRAP(atomic_read(&sk->rmem_alloc)==0);
5013 + BUG_TRAP(atomic_read(&sk->wmem_alloc)==0);
5016 +#if defined(RING_DEBUG)
5017 + printk("Attempt to release alive ring socket: %p\n", sk);
5023 + kfree(ring_sk(sk));
5025 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
5026 + MOD_DEC_USE_COUNT;
5030 +/* ********************************** */
5034 + * store the sk in a new element and add it
5035 + * to the head of the list.
5037 +static inline void ring_insert(struct sock *sk) {
5038 + struct ring_element *next;
5040 +#if defined(RING_DEBUG)
5041 + printk("RING: ring_insert()\n");
5044 + next = kmalloc(sizeof(struct ring_element), GFP_ATOMIC);
5045 + if(next != NULL) {
5047 + write_lock_irq(&ring_mgmt_lock);
5048 + list_add(&next->list, &ring_table);
5049 + write_unlock_irq(&ring_mgmt_lock);
5051 + if (net_ratelimit())
5052 + printk("RING: could not kmalloc slot!!\n");
5056 +/* ********************************** */
5060 + * For each of the elements in the list:
5061 + * - check if this is the element we want to delete
5062 + * - if it is, remove it from the list, and free it.
5064 + * stop when we find the one we're looking for (break),
5065 + * or when we reach the end of the list.
5067 +static inline void ring_remove(struct sock *sk) {
5068 + struct list_head *ptr;
5069 + struct ring_element *entry;
5072 + for(ptr = ring_table.next; ptr != &ring_table; ptr = ptr->next) {
5073 + entry = list_entry(ptr, struct ring_element, list);
5075 + if(entry->sk == sk) {
5076 + write_lock_irq(&ring_mgmt_lock);
5079 + write_unlock_irq(&ring_mgmt_lock);
5086 +/* ********************************** */
5088 +static u_int32_t num_queued_pkts(struct ring_opt *pfr) {
5090 + if(pfr->ring_slots != NULL) {
5092 + u_int32_t tot_insert = pfr->slots_info->insert_idx,
5093 +#if defined(RING_DEBUG)
5094 + tot_read = pfr->slots_info->tot_read, tot_pkts;
5096 + tot_read = pfr->slots_info->tot_read;
5099 + if(tot_insert >= tot_read) {
5100 +#if defined(RING_DEBUG)
5101 + tot_pkts = tot_insert-tot_read;
5103 + return(tot_insert-tot_read);
5105 +#if defined(RING_DEBUG)
5106 + tot_pkts = ((u_int32_t)-1)+tot_insert-tot_read;
5108 + return(((u_int32_t)-1)+tot_insert-tot_read);
5111 +#if defined(RING_DEBUG)
5112 + printk("-> num_queued_pkts=%d [tot_insert=%d][tot_read=%d]\n",
5113 + tot_pkts, tot_insert, tot_read);
5120 +/* ********************************** */
5122 +static inline FlowSlot* get_insert_slot(struct ring_opt *pfr) {
5123 +#if defined(RING_DEBUG)
5124 + printk("get_insert_slot(%d)\n", pfr->slots_info->insert_idx);
5127 + if(pfr->ring_slots != NULL) {
5128 + FlowSlot *slot = (FlowSlot*)&(pfr->ring_slots[pfr->slots_info->insert_idx
5129 + *pfr->slots_info->slot_len]);
5135 +/* ********************************** */
5137 +static inline FlowSlot* get_remove_slot(struct ring_opt *pfr) {
5138 +#if defined(RING_DEBUG)
5139 + printk("get_remove_slot(%d)\n", pfr->slots_info->remove_idx);
5142 + if(pfr->ring_slots != NULL)
5143 + return((FlowSlot*)&(pfr->ring_slots[pfr->slots_info->remove_idx*
5144 + pfr->slots_info->slot_len]));
5149 +/* ********************************** */
5151 +static void add_skb_to_ring(struct sk_buff *skb,
5152 + struct ring_opt *pfr,
5153 + u_char recv_packet,
5154 + u_char real_skb /* 1=skb 0=faked skb */) {
5155 + FlowSlot *theSlot;
5159 + /* Hack for identifying a packet received by the e1000 */
5161 + displ = SKB_DISPLACEMENT;
5163 + displ = 0; /* Received by the e1000 wrapper */
5167 + write_lock(&pfr->ring_index_lock);
5168 + pfr->slots_info->tot_pkts++;
5169 + write_unlock(&pfr->ring_index_lock);
5171 + /* BPF Filtering (from af_packet.c) */
5172 + if(pfr->bpfFilter != NULL) {
5173 + unsigned res = 1, len;
5175 + len = skb->len-skb->data_len;
5177 + write_lock(&pfr->ring_index_lock);
5178 + skb->data -= displ;
5179 + res = sk_run_filter(skb, pfr->bpfFilter->insns, pfr->bpfFilter->len);
5180 + skb->data += displ;
5181 + write_unlock(&pfr->ring_index_lock);
5184 + /* Filter failed */
5186 +#if defined(RING_DEBUG)
5187 + printk("add_skb_to_ring(skb): Filter failed [len=%d][tot=%llu]"
5188 + "[insertIdx=%d][pkt_type=%d][cloned=%d]\n",
5189 + (int)skb->len, pfr->slots_info->tot_pkts,
5190 + pfr->slots_info->insert_idx,
5191 + skb->pkt_type, skb->cloned);
5198 + /* ************************** */
5200 + if(pfr->sample_rate > 1) {
5201 + if(pfr->pktToSample == 0) {
5202 + write_lock(&pfr->ring_index_lock);
5203 + pfr->pktToSample = pfr->sample_rate;
5204 + write_unlock(&pfr->ring_index_lock);
5206 + write_lock(&pfr->ring_index_lock);
5207 + pfr->pktToSample--;
5208 + write_unlock(&pfr->ring_index_lock);
5210 +#if defined(RING_DEBUG)
5211 + printk("add_skb_to_ring(skb): sampled packet [len=%d]"
5212 + "[tot=%llu][insertIdx=%d][pkt_type=%d][cloned=%d]\n",
5213 + (int)skb->len, pfr->slots_info->tot_pkts,
5214 + pfr->slots_info->insert_idx,
5215 + skb->pkt_type, skb->cloned);
5221 + /* ************************************* */
5223 + if((pfr->reflector_dev != NULL)
5224 + && (!netif_queue_stopped(pfr->reflector_dev))) {
5225 + int cpu = smp_processor_id();
5227 + /* increase reference counter so that this skb is not freed */
5228 + atomic_inc(&skb->users);
5230 + skb->data -= displ;
5233 + if (pfr->reflector_dev->xmit_lock_owner != cpu) {
5234 + spin_lock_bh(&pfr->reflector_dev->xmit_lock);
5235 + pfr->reflector_dev->xmit_lock_owner = cpu;
5236 + spin_unlock_bh(&pfr->reflector_dev->xmit_lock);
5238 + if (pfr->reflector_dev->hard_start_xmit(skb,
5239 + pfr->reflector_dev) == 0) {
5240 + spin_lock_bh(&pfr->reflector_dev->xmit_lock);
5241 + pfr->reflector_dev->xmit_lock_owner = -1;
5242 + skb->data += displ;
5243 + spin_unlock_bh(&pfr->reflector_dev->xmit_lock);
5244 +#if defined(RING_DEBUG)
5245 + printk("++ hard_start_xmit succeeded\n");
5250 + spin_lock_bh(&pfr->reflector_dev->xmit_lock);
5251 + pfr->reflector_dev->xmit_lock_owner = -1;
5252 + spin_unlock_bh(&pfr->reflector_dev->xmit_lock);
5255 +#if defined(RING_DEBUG)
5256 + printk("++ hard_start_xmit failed\n");
5258 + skb->data += displ;
5259 + return; /* -ENETDOWN */
5262 + /* ************************************* */
5264 +#if defined(RING_DEBUG)
5265 + printk("add_skb_to_ring(skb) [len=%d][tot=%llu][insertIdx=%d]"
5266 + "[pkt_type=%d][cloned=%d]\n",
5267 + (int)skb->len, pfr->slots_info->tot_pkts,
5268 + pfr->slots_info->insert_idx,
5269 + skb->pkt_type, skb->cloned);
5272 + idx = pfr->slots_info->insert_idx;
5273 + theSlot = get_insert_slot(pfr);
5275 + if((theSlot != NULL) && (theSlot->slot_state == 0)) {
5276 + struct pcap_pkthdr *hdr;
5277 + unsigned int bucketSpace;
5280 + /* Update Index */
5283 + if(idx == pfr->slots_info->tot_slots) {
5284 + write_lock(&pfr->ring_index_lock);
5285 + pfr->slots_info->insert_idx = 0;
5286 + write_unlock(&pfr->ring_index_lock);
5288 + write_lock(&pfr->ring_index_lock);
5289 + pfr->slots_info->insert_idx = idx;
5290 + write_unlock(&pfr->ring_index_lock);
5293 + bucketSpace = pfr->slots_info->slot_len
5297 + - sizeof(u_char) /* flowSlot.slot_state */
5298 + - sizeof(struct pcap_pkthdr)
5299 + - 1 /* 10 */ /* safe boundary */;
5301 + bucket = &theSlot->bucket;
5302 + hdr = (struct pcap_pkthdr*)bucket;
5304 + if(skb->stamp.tv_sec == 0) do_gettimeofday(&skb->stamp);
5306 + hdr->ts.tv_sec = skb->stamp.tv_sec, hdr->ts.tv_usec = skb->stamp.tv_usec;
5307 + hdr->caplen = skb->len+displ;
5309 + if(hdr->caplen > bucketSpace)
5310 + hdr->caplen = bucketSpace;
5312 + hdr->len = skb->len+displ;
5313 + memcpy(&bucket[sizeof(struct pcap_pkthdr)],
5314 + skb->data-displ, hdr->caplen);
5316 +#if defined(RING_DEBUG)
5318 + static unsigned int lastLoss = 0;
5320 + if(pfr->slots_info->tot_lost
5321 + && (lastLoss != pfr->slots_info->tot_lost)) {
5322 + printk("add_skb_to_ring(%d): [bucketSpace=%d]"
5323 + "[hdr.caplen=%d][skb->len=%d]"
5324 + "[pcap_pkthdr=%d][removeIdx=%d]"
5325 + "[loss=%lu][page=%u][slot=%u]\n",
5326 + idx-1, bucketSpace, hdr->caplen, skb->len,
5327 + sizeof(struct pcap_pkthdr),
5328 + pfr->slots_info->remove_idx,
5329 + (long unsigned int)pfr->slots_info->tot_lost,
5330 + pfr->insert_page_id, pfr->insert_slot_id);
5332 + lastLoss = pfr->slots_info->tot_lost;
5337 + write_lock(&pfr->ring_index_lock);
5338 + pfr->slots_info->tot_insert++;
5339 + theSlot->slot_state = 1;
5340 + write_unlock(&pfr->ring_index_lock);
5342 + write_lock(&pfr->ring_index_lock);
5343 + pfr->slots_info->tot_lost++;
5344 + write_unlock(&pfr->ring_index_lock);
5346 +#if defined(RING_DEBUG)
5347 + printk("add_skb_to_ring(skb): packet lost [loss=%lu]"
5348 + "[removeIdx=%u][insertIdx=%u]\n",
5349 + (long unsigned int)pfr->slots_info->tot_lost,
5350 + pfr->slots_info->remove_idx, pfr->slots_info->insert_idx);
5354 + /* wakeup in case of poll() */
5355 + if(waitqueue_active(&pfr->ring_slots_waitqueue))
5356 + wake_up_interruptible(&pfr->ring_slots_waitqueue);
5359 +/* ********************************** */
5361 +static u_int hash_skb(struct ring_cluster *cluster_ptr,
5362 + struct sk_buff *skb, u_char recv_packet) {
5367 + if(cluster_ptr->hashing_mode == cluster_round_robin) {
5368 + idx = cluster_ptr->hashing_id++;
5370 + /* Per-flow clustering */
5371 + if(skb->len > sizeof(struct iphdr)+sizeof(struct tcphdr)) {
5375 + displ = SKB_DISPLACEMENT;
5380 + Always points to to the IP part of the packet
5383 + ip = (struct iphdr*)(skb->data+displ);
5385 + idx = ip->saddr+ip->daddr+ip->protocol;
5387 + if(ip->protocol == IPPROTO_TCP) {
5388 + struct tcphdr *tcp = (struct tcphdr*)(skb->data+displ
5389 + +sizeof(struct iphdr));
5390 + idx += tcp->source+tcp->dest;
5391 + } else if(ip->protocol == IPPROTO_UDP) {
5392 + struct udphdr *udp = (struct udphdr*)(skb->data+displ
5393 + +sizeof(struct iphdr));
5394 + idx += udp->source+udp->dest;
5400 + return(idx % cluster_ptr->num_cluster_elements);
5403 +/* ********************************** */
5405 +static int skb_ring_handler(struct sk_buff *skb,
5406 + u_char recv_packet,
5407 + u_char real_skb /* 1=skb 0=faked skb */) {
5408 + struct sock *skElement;
5410 + struct list_head *ptr;
5411 + struct ring_cluster *cluster_ptr;
5414 + uint64_t rdt = _rdtsc(), rdt1, rdt2;
5417 + if((!skb) /* Invalid skb */
5418 + || ((!enable_tx_capture) && (!recv_packet))) {
5420 + An outgoing packet is about to be sent out
5421 + but we decided not to handle transmitted
5427 +#if defined(RING_DEBUG)
5429 + printk("skb_ring_handler() [len=%d][dev=%s]\n", skb->len,
5430 + skb->dev->name == NULL ? "<NULL>" : skb->dev->name);
5438 + /* [1] Check unclustered sockets */
5439 + for (ptr = ring_table.next; ptr != &ring_table; ptr = ptr->next) {
5440 + struct ring_opt *pfr;
5441 + struct ring_element *entry;
5443 + entry = list_entry(ptr, struct ring_element, list);
5445 + read_lock(&ring_mgmt_lock);
5446 + skElement = entry->sk;
5447 + pfr = ring_sk(skElement);
5448 + read_unlock(&ring_mgmt_lock);
5451 + && (pfr->cluster_id == 0 /* No cluster */)
5452 + && (pfr->ring_slots != NULL)
5453 + && (pfr->ring_netdev == skb->dev)) {
5454 + /* We've found the ring where the packet can be stored */
5455 + read_lock(&ring_mgmt_lock);
5456 + add_skb_to_ring(skb, pfr, recv_packet, real_skb);
5457 + read_unlock(&ring_mgmt_lock);
5459 + rc = 1; /* Ring found: we've done our job */
5463 + /* [2] Check socket clusters */
5464 + cluster_ptr = ring_cluster_list;
5466 + while(cluster_ptr != NULL) {
5467 + struct ring_opt *pfr;
5469 + if(cluster_ptr->num_cluster_elements > 0) {
5470 + u_int skb_hash = hash_skb(cluster_ptr, skb, recv_packet);
5472 + read_lock(&ring_mgmt_lock);
5473 + skElement = cluster_ptr->sk[skb_hash];
5474 + read_unlock(&ring_mgmt_lock);
5476 + if(skElement != NULL) {
5477 + pfr = ring_sk(skElement);
5480 + && (pfr->ring_slots != NULL)
5481 + && (pfr->ring_netdev == skb->dev)) {
5482 + /* We've found the ring where the packet can be stored */
5483 + read_lock(&ring_mgmt_lock);
5484 + add_skb_to_ring(skb, pfr, recv_packet, real_skb);
5485 + read_unlock(&ring_mgmt_lock);
5487 + rc = 1; /* Ring found: we've done our job */
5492 + cluster_ptr = cluster_ptr->next;
5496 + rdt1 = _rdtsc()-rdt1;
5503 + if(transparent_mode) rc = 0;
5505 + if((rc != 0) && real_skb)
5506 + dev_kfree_skb(skb); /* Free the skb */
5509 + rdt2 = _rdtsc()-rdt2;
5510 + rdt = _rdtsc()-rdt;
5512 +#if defined(RING_DEBUG)
5513 + printk("# cycles: %d [lock costed %d %d%%][free costed %d %d%%]\n",
5514 + (int)rdt, rdt-rdt1,
5515 + (int)((float)((rdt-rdt1)*100)/(float)rdt),
5517 + (int)((float)(rdt2*100)/(float)rdt));
5521 + return(rc); /* 0 = packet not handled */
5524 +/* ********************************** */
5526 +struct sk_buff skb;
5528 +static int buffer_ring_handler(struct net_device *dev,
5529 + char *data, int len) {
5531 +#if defined(RING_DEBUG)
5532 + printk("buffer_ring_handler: [dev=%s][len=%d]\n",
5533 + dev->name == NULL ? "<NULL>" : dev->name, len);
5536 + skb.dev = dev, skb.len = len, skb.data = data,
5537 + skb.data_len = len, skb.stamp.tv_sec = 0; /* Calculate the time */
5539 + skb_ring_handler(&skb, 1, 0 /* fake skb */);
5544 +/* ********************************** */
5546 +static int ring_create(struct socket *sock, int protocol) {
5548 + struct ring_opt *pfr;
5551 +#if defined(RING_DEBUG)
5552 + printk("RING: ring_create()\n");
5555 + /* Are you root, superuser or so ? */
5556 + if(!capable(CAP_NET_ADMIN))
5559 + if(sock->type != SOCK_RAW)
5560 + return -ESOCKTNOSUPPORT;
5562 + if(protocol != htons(ETH_P_ALL))
5563 + return -EPROTONOSUPPORT;
5565 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
5566 + MOD_INC_USE_COUNT;
5571 + // BD: -- broke this out to keep it more simple and clear as to what the
5573 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
5574 +#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,11))
5575 + sk = sk_alloc(PF_RING, GFP_KERNEL, 1, NULL);
5579 + // BD: API changed in 2.6.12, ref:
5580 + // http://svn.clkao.org/svnweb/linux/revision/?rev=28201
5581 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,11))
5582 + sk = sk_alloc(PF_RING, GFP_ATOMIC, &ring_proto, 1);
5588 + sock->ops = &ring_ops;
5589 + sock_init_data(sock, sk);
5590 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
5591 +#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,11))
5592 + sk_set_owner(sk, THIS_MODULE);
5597 + ring_sk(sk) = ring_sk_datatype(kmalloc(sizeof(*pfr), GFP_KERNEL));
5599 + if (!(pfr = ring_sk(sk))) {
5603 + memset(pfr, 0, sizeof(*pfr));
5604 + init_waitqueue_head(&pfr->ring_slots_waitqueue);
5605 + pfr->ring_index_lock = RW_LOCK_UNLOCKED;
5606 + atomic_set(&pfr->num_ring_slots_waiters, 0);
5607 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
5608 + sk->sk_family = PF_RING;
5609 + sk->sk_destruct = ring_sock_destruct;
5611 + sk->family = PF_RING;
5612 + sk->destruct = ring_sock_destruct;
5613 + sk->num = protocol;
5618 +#if defined(RING_DEBUG)
5619 + printk("RING: ring_create() - created\n");
5624 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
5625 + MOD_DEC_USE_COUNT;
5630 +/* *********************************************** */
5632 +static int ring_release(struct socket *sock)
5634 + struct sock *sk = sock->sk;
5635 + struct ring_opt *pfr = ring_sk(sk);
5640 +#if defined(RING_DEBUG)
5641 + printk("RING: called ring_release\n");
5644 +#if defined(RING_DEBUG)
5645 + printk("RING: ring_release entered\n");
5653 + /* Free the ring buffer */
5654 + if(pfr->ring_memory) {
5655 + struct page *page, *page_end;
5657 + page_end = virt_to_page(pfr->ring_memory + (PAGE_SIZE << pfr->order) - 1);
5658 + for(page = virt_to_page(pfr->ring_memory); page <= page_end; page++)
5659 + ClearPageReserved(page);
5661 + free_pages(pfr->ring_memory, pfr->order);
5665 + ring_sk(sk) = NULL;
5667 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
5668 + skb_queue_purge(&sk->sk_write_queue);
5672 +#if defined(RING_DEBUG)
5673 + printk("RING: ring_release leaving\n");
5679 +/* ********************************** */
5681 + * We create a ring for this socket and bind it to the specified device
5683 +static int packet_ring_bind(struct sock *sk, struct net_device *dev)
5685 + u_int the_slot_len;
5686 + u_int32_t tot_mem;
5687 + struct ring_opt *pfr = ring_sk(sk);
5688 + struct page *page, *page_end;
5690 + if(!dev) return(-1);
5692 +#if defined(RING_DEBUG)
5693 + printk("RING: packet_ring_bind(%s) called\n", dev->name);
5696 + /* **********************************************
5698 + *************************************
5702 + ************************************* <-+
5704 + ************************************* |
5706 + ************************************* +- num_slots
5708 + ************************************* |
5710 + ************************************* <-+
5712 + ********************************************** */
5714 + the_slot_len = sizeof(u_char) /* flowSlot.slot_state */
5715 + + sizeof(u_short) /* flowSlot.slot_len */
5716 + + bucket_len /* flowSlot.bucket */;
5718 + tot_mem = sizeof(FlowSlotInfo) + num_slots*the_slot_len;
5721 + Calculate the value of the order parameter used later.
5722 + See http://www.linuxjournal.com/article.php?sid=1133
5724 + for(pfr->order = 0;(PAGE_SIZE << pfr->order) < tot_mem; pfr->order++) ;
5727 + We now try to allocate the memory as required. If we fail
5728 + we try to allocate a smaller amount or memory (hence a
5731 + while((pfr->ring_memory = __get_free_pages(GFP_ATOMIC, pfr->order)) == 0)
5732 + if(pfr->order-- == 0)
5735 + if(pfr->order == 0) {
5736 +#if defined(RING_DEBUG)
5737 + printk("ERROR: not enough memory\n");
5741 +#if defined(RING_DEBUG)
5742 + printk("RING: succesfully allocated %lu KB [tot_mem=%d][order=%ld]\n",
5743 + PAGE_SIZE >> (10 - pfr->order), tot_mem, pfr->order);
5747 + tot_mem = PAGE_SIZE << pfr->order;
5748 + memset((char*)pfr->ring_memory, 0, tot_mem);
5750 + /* Now we need to reserve the pages */
5751 + page_end = virt_to_page(pfr->ring_memory + (PAGE_SIZE << pfr->order) - 1);
5752 + for(page = virt_to_page(pfr->ring_memory); page <= page_end; page++)
5753 + SetPageReserved(page);
5755 + pfr->slots_info = (FlowSlotInfo*)pfr->ring_memory;
5756 + pfr->ring_slots = (char*)(pfr->ring_memory+sizeof(FlowSlotInfo));
5758 + pfr->slots_info->version = RING_FLOWSLOT_VERSION;
5759 + pfr->slots_info->slot_len = the_slot_len;
5760 + pfr->slots_info->tot_slots = (tot_mem-sizeof(FlowSlotInfo))/the_slot_len;
5761 + pfr->slots_info->tot_mem = tot_mem;
5762 + pfr->slots_info->sample_rate = sample_rate;
5764 +#if defined(RING_DEBUG)
5765 + printk("RING: allocated %d slots [slot_len=%d][tot_mem=%u]\n",
5766 + pfr->slots_info->tot_slots, pfr->slots_info->slot_len,
5767 + pfr->slots_info->tot_mem);
5774 + for(i=0; i<pfr->slots_info->tot_slots; i++) {
5775 + unsigned long idx = i*pfr->slots_info->slot_len;
5776 + FlowSlot *slot = (FlowSlot*)&pfr->ring_slots[idx];
5777 + slot->magic = RING_MAGIC_VALUE; slot->slot_state = 0;
5782 + pfr->insert_page_id = 1, pfr->insert_slot_id = 0;
5786 + Leave this statement here as last one. In fact when
5787 + the ring_netdev != NULL the socket is ready to be used.
5789 + pfr->ring_netdev = dev;
5794 +/* ************************************* */
5796 +/* Bind to a device */
5797 +static int ring_bind(struct socket *sock,
5798 + struct sockaddr *sa, int addr_len)
5800 + struct sock *sk=sock->sk;
5801 + struct net_device *dev = NULL;
5803 +#if defined(RING_DEBUG)
5804 + printk("RING: ring_bind() called\n");
5810 + if (addr_len != sizeof(struct sockaddr))
5812 + if (sa->sa_family != PF_RING)
5815 + /* Safety check: add trailing zero if missing */
5816 + sa->sa_data[sizeof(sa->sa_data)-1] = '\0';
5818 +#if defined(RING_DEBUG)
5819 + printk("RING: searching device %s\n", sa->sa_data);
5822 + if((dev = __dev_get_by_name(sa->sa_data)) == NULL) {
5823 +#if defined(RING_DEBUG)
5824 + printk("RING: search failed\n");
5828 + return(packet_ring_bind(sk, dev));
5831 +/* ************************************* */
5833 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
5835 +volatile void* virt_to_kseg(volatile void* address) {
5838 + unsigned long addr = (unsigned long)address;
5840 + pud = pud_offset(pgd_offset_k((unsigned long) address),
5841 + (unsigned long) address);
5844 + High-memory support courtesy of
5845 + Brad Doctor <bdoctor@ps-ax.com>
5847 +#if defined(CONFIG_X86_PAE) && (!defined(CONFIG_NOHIGHMEM))
5848 + pte = pte_offset_map(pmd_offset(pud, addr), addr);
5850 + pte = pmd_offset_map(pud, addr);
5853 + return((volatile void*)pte_page(*pte));
5858 +/* http://www.scs.ch/~frey/linux/memorymap.html */
5859 +volatile void *virt_to_kseg(volatile void *address)
5861 + pgd_t *pgd; pmd_t *pmd; pte_t *ptep, pte;
5862 + unsigned long va, ret = 0UL;
5864 + va=VMALLOC_VMADDR((unsigned long)address);
5866 + /* get the page directory. Use the kernel memory map. */
5867 + pgd = pgd_offset_k(va);
5869 + /* check whether we found an entry */
5870 + if (!pgd_none(*pgd))
5872 + /* get the page middle directory */
5873 + pmd = pmd_offset(pgd, va);
5874 + /* check whether we found an entry */
5875 + if (!pmd_none(*pmd))
5877 + /* get a pointer to the page table entry */
5878 + ptep = pte_offset(pmd, va);
5880 + /* check for a valid page */
5881 + if (pte_present(pte))
5883 + /* get the address the page is refering to */
5884 + ret = (unsigned long)page_address(pte_page(pte));
5885 + /* add the offset within the page to the page address */
5886 + ret |= (va & (PAGE_SIZE -1));
5890 + return((volatile void *)ret);
5894 +/* ************************************* */
5896 +static int ring_mmap(struct file *file,
5897 + struct socket *sock,
5898 + struct vm_area_struct *vma)
5900 + struct sock *sk = sock->sk;
5901 + struct ring_opt *pfr = ring_sk(sk);
5902 + unsigned long size, start;
5906 +#if defined(RING_DEBUG)
5907 + printk("RING: ring_mmap() called\n");
5910 + if(pfr->ring_memory == 0) {
5911 +#if defined(RING_DEBUG)
5912 + printk("RING: ring_mmap() failed: mapping area to an unbound socket\n");
5917 + size = (unsigned long)(vma->vm_end-vma->vm_start);
5919 + if(size % PAGE_SIZE) {
5920 +#if defined(RING_DEBUG)
5921 + printk("RING: ring_mmap() failed: len is not multiple of PAGE_SIZE\n");
5926 + /* if userspace tries to mmap beyond end of our buffer, fail */
5927 + if(size > pfr->slots_info->tot_mem) {
5928 +#if defined(RING_DEBUG)
5929 + printk("proc_mmap() failed: area too large [%ld > %d]\n", size, pfr->slots_info->tot_mem);
5934 + pagesToMap = size/PAGE_SIZE;
5936 +#if defined(RING_DEBUG)
5937 + printk("RING: ring_mmap() called. %d pages to map\n", pagesToMap);
5940 +#if defined(RING_DEBUG)
5941 + printk("RING: mmap [slot_len=%d][tot_slots=%d] for ring on device %s\n",
5942 + pfr->slots_info->slot_len, pfr->slots_info->tot_slots,
5943 + pfr->ring_netdev->name);
5946 + /* we do not want to have this area swapped out, lock it */
5947 + vma->vm_flags |= VM_LOCKED;
5948 + start = vma->vm_start;
5950 + /* Ring slots start from page 1 (page 0 is reserved for FlowSlotInfo) */
5951 + ptr = (char*)(start+PAGE_SIZE);
5953 + if(remap_page_range(
5954 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
5958 + __pa(pfr->ring_memory),
5959 + PAGE_SIZE*pagesToMap, vma->vm_page_prot)) {
5960 +#if defined(RING_DEBUG)
5961 + printk("remap_page_range() failed\n");
5966 +#if defined(RING_DEBUG)
5967 + printk("proc_mmap(pagesToMap=%d): success.\n", pagesToMap);
5973 +/* ************************************* */
5975 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
5976 +static int ring_recvmsg(struct kiocb *iocb, struct socket *sock,
5977 + struct msghdr *msg, size_t len, int flags)
5979 + static int ring_recvmsg(struct socket *sock, struct msghdr *msg, int len,
5980 + int flags, struct scm_cookie *scm)
5984 + struct ring_opt *pfr = ring_sk(sock->sk);
5985 + u_int32_t queued_pkts, num_loops = 0;
5987 +#if defined(RING_DEBUG)
5988 + printk("ring_recvmsg called\n");
5991 + slot = get_remove_slot(pfr);
5993 + while((queued_pkts = num_queued_pkts(pfr)) < MIN_QUEUED_PKTS) {
5994 + wait_event_interruptible(pfr->ring_slots_waitqueue, 1);
5996 +#if defined(RING_DEBUG)
5997 + printk("-> ring_recvmsg returning %d [queued_pkts=%d][num_loops=%d]\n",
5998 + slot->slot_state, queued_pkts, num_loops);
6001 + if(queued_pkts > 0) {
6002 + if(num_loops++ > MAX_QUEUE_LOOPS)
6007 +#if defined(RING_DEBUG)
6009 + printk("ring_recvmsg is returning [queued_pkts=%d][num_loops=%d]\n",
6010 + queued_pkts, num_loops);
6013 + return(queued_pkts);
6016 +/* ************************************* */
6018 +unsigned int ring_poll(struct file * file,
6019 + struct socket *sock, poll_table *wait)
6022 + struct ring_opt *pfr = ring_sk(sock->sk);
6024 +#if defined(RING_DEBUG)
6025 + printk("poll called\n");
6028 + slot = get_remove_slot(pfr);
6030 + if((slot != NULL) && (slot->slot_state == 0))
6031 + poll_wait(file, &pfr->ring_slots_waitqueue, wait);
6033 +#if defined(RING_DEBUG)
6034 + printk("poll returning %d\n", slot->slot_state);
6037 + if((slot != NULL) && (slot->slot_state == 1))
6038 + return(POLLIN | POLLRDNORM);
6043 +/* ************************************* */
6045 +int add_to_cluster_list(struct ring_cluster *el,
6046 + struct sock *sock) {
6048 + if(el->num_cluster_elements == CLUSTER_LEN)
6049 + return(-1); /* Cluster full */
6051 + ring_sk_datatype(ring_sk(sock))->cluster_id = el->cluster_id;
6052 + el->sk[el->num_cluster_elements] = sock;
6053 + el->num_cluster_elements++;
6057 +/* ************************************* */
6059 +int remove_from_cluster_list(struct ring_cluster *el,
6060 + struct sock *sock) {
6063 + for(i=0; i<CLUSTER_LEN; i++)
6064 + if(el->sk[i] == sock) {
6065 + el->num_cluster_elements--;
6067 + if(el->num_cluster_elements > 0) {
6068 + /* The cluster contains other elements */
6069 + for(j=i; j<CLUSTER_LEN-1; j++)
6070 + el->sk[j] = el->sk[j+1];
6072 + el->sk[CLUSTER_LEN-1] = NULL;
6074 + /* Empty cluster */
6075 + memset(el->sk, 0, sizeof(el->sk));
6081 + return(-1); /* Not found */
6084 +/* ************************************* */
6086 +static int remove_from_cluster(struct sock *sock,
6087 + struct ring_opt *pfr)
6089 + struct ring_cluster *el;
6091 +#if defined(RING_DEBUG)
6092 + printk("--> remove_from_cluster(%d)\n", pfr->cluster_id);
6095 + if(pfr->cluster_id == 0 /* 0 = No Cluster */)
6096 + return(0); /* Noting to do */
6098 + el = ring_cluster_list;
6100 + while(el != NULL) {
6101 + if(el->cluster_id == pfr->cluster_id) {
6102 + return(remove_from_cluster_list(el, sock));
6107 + return(-EINVAL); /* Not found */
6110 +/* ************************************* */
6112 +static int add_to_cluster(struct sock *sock,
6113 + struct ring_opt *pfr,
6114 + u_short cluster_id)
6116 + struct ring_cluster *el;
6119 + printk("--> add_to_cluster(%d)\n", cluster_id);
6122 + if(cluster_id == 0 /* 0 = No Cluster */) return(-EINVAL);
6124 + if(pfr->cluster_id != 0)
6125 + remove_from_cluster(sock, pfr);
6127 + el = ring_cluster_list;
6129 + while(el != NULL) {
6130 + if(el->cluster_id == cluster_id) {
6131 + return(add_to_cluster_list(el, sock));
6136 + /* There's no existing cluster. We need to create one */
6137 + if((el = kmalloc(sizeof(struct ring_cluster), GFP_KERNEL)) == NULL)
6140 + el->cluster_id = cluster_id;
6141 + el->num_cluster_elements = 1;
6142 + el->hashing_mode = cluster_per_flow; /* Default */
6143 + el->hashing_id = 0;
6145 + memset(el->sk, 0, sizeof(el->sk));
6147 + el->next = ring_cluster_list;
6148 + ring_cluster_list = el;
6149 + pfr->cluster_id = cluster_id;
6151 + return(0); /* 0 = OK */
6154 +/* ************************************* */
6156 +/* Code taken/inspired from core/sock.c */
6157 +static int ring_setsockopt(struct socket *sock,
6158 + int level, int optname,
6159 + char *optval, int optlen)
6161 + struct ring_opt *pfr = ring_sk(sock->sk);
6162 + int val, found, ret = 0;
6166 + if((optlen<sizeof(int)) || (pfr == NULL))
6169 + if (get_user(val, (int *)optval))
6176 + case SO_ATTACH_FILTER:
6178 + if (optlen == sizeof(struct sock_fprog)) {
6179 + unsigned int fsize;
6180 + struct sock_fprog fprog;
6181 + struct sk_filter *filter;
6188 + Do not call copy_from_user within a held
6189 + splinlock (e.g. ring_mgmt_lock) as this caused
6190 + problems when certain debugging was enabled under
6191 + 2.6.5 -- including hard lockups of the machine.
6193 + if(copy_from_user(&fprog, optval, sizeof(fprog)))
6196 + fsize = sizeof(struct sock_filter) * fprog.len;
6197 + filter = kmalloc(fsize, GFP_KERNEL);
6199 + if(filter == NULL) {
6204 + if(copy_from_user(filter->insns, fprog.filter, fsize))
6207 + filter->len = fprog.len;
6209 + if(sk_chk_filter(filter->insns, filter->len) != 0) {
6210 + /* Bad filter specified */
6212 + pfr->bpfFilter = NULL;
6216 + /* get the lock, set the filter, release the lock */
6217 + write_lock(&ring_mgmt_lock);
6218 + pfr->bpfFilter = filter;
6219 + write_unlock(&ring_mgmt_lock);
6224 + case SO_DETACH_FILTER:
6225 + write_lock(&ring_mgmt_lock);
6227 + if(pfr->bpfFilter != NULL) {
6228 + kfree(pfr->bpfFilter);
6229 + pfr->bpfFilter = NULL;
6230 + write_unlock(&ring_mgmt_lock);
6236 + case SO_ADD_TO_CLUSTER:
6237 + if (optlen!=sizeof(val))
6240 + if (copy_from_user(&cluster_id, optval, sizeof(cluster_id)))
6243 + write_lock(&ring_mgmt_lock);
6244 + ret = add_to_cluster(sock->sk, pfr, cluster_id);
6245 + write_unlock(&ring_mgmt_lock);
6248 + case SO_REMOVE_FROM_CLUSTER:
6249 + write_lock(&ring_mgmt_lock);
6250 + ret = remove_from_cluster(sock->sk, pfr);
6251 + write_unlock(&ring_mgmt_lock);
6254 + case SO_SET_REFLECTOR:
6255 + if(optlen >= (sizeof(devName)-1))
6259 + if(copy_from_user(devName, optval, optlen))
6263 + devName[optlen] = '\0';
6265 +#if defined(RING_DEBUG)
6266 + printk("+++ SO_SET_REFLECTOR(%s)\n", devName);
6269 + write_lock(&ring_mgmt_lock);
6270 + pfr->reflector_dev = dev_get_by_name(devName);
6271 + write_unlock(&ring_mgmt_lock);
6273 +#if defined(RING_DEBUG)
6274 + if(pfr->reflector_dev != NULL)
6275 + printk("SO_SET_REFLECTOR(%s): succeded\n", devName);
6277 + printk("SO_SET_REFLECTOR(%s): device unknown\n", devName);
6289 + return(sock_setsockopt(sock, level, optname, optval, optlen));
6292 +/* ************************************* */
6294 +static int ring_ioctl(struct socket *sock,
6295 + unsigned int cmd, unsigned long arg)
6299 + case SIOCGIFFLAGS:
6300 + case SIOCSIFFLAGS:
6302 + case SIOCGIFMETRIC:
6303 + case SIOCSIFMETRIC:
6309 + case SIOCGIFHWADDR:
6310 + case SIOCSIFHWADDR:
6313 + case SIOCSIFSLAVE:
6314 + case SIOCGIFSLAVE:
6315 + case SIOCGIFINDEX:
6317 + case SIOCGIFCOUNT:
6318 + case SIOCSIFHWBROADCAST:
6319 + return(dev_ioctl(cmd,(void *) arg));
6322 + return -EOPNOTSUPP;
6328 +/* ************************************* */
6330 +static struct proto_ops ring_ops = {
6331 + .family = PF_RING,
6332 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
6333 + .owner = THIS_MODULE,
6336 + /* Operations that make no sense on ring sockets. */
6337 + .connect = sock_no_connect,
6338 + .socketpair = sock_no_socketpair,
6339 + .accept = sock_no_accept,
6340 + .getname = sock_no_getname,
6341 + .listen = sock_no_listen,
6342 + .shutdown = sock_no_shutdown,
6343 + .sendpage = sock_no_sendpage,
6344 + .sendmsg = sock_no_sendmsg,
6345 + .getsockopt = sock_no_getsockopt,
6347 + /* Now the operations that really occur. */
6348 + .release = ring_release,
6349 + .bind = ring_bind,
6350 + .mmap = ring_mmap,
6351 + .poll = ring_poll,
6352 + .setsockopt = ring_setsockopt,
6353 + .ioctl = ring_ioctl,
6354 + .recvmsg = ring_recvmsg,
6357 +/* ************************************ */
6359 +static struct net_proto_family ring_family_ops = {
6360 + .family = PF_RING,
6361 + .create = ring_create,
6362 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
6363 + .owner = THIS_MODULE,
6367 +// BD: API changed in 2.6.12, ref:
6368 +// http://svn.clkao.org/svnweb/linux/revision/?rev=28201
6369 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,11))
6370 +static struct proto ring_proto = {
6371 + .name = "PF_RING",
6372 + .owner = THIS_MODULE,
6373 + .obj_size = sizeof(struct sock),
6377 +/* ************************************ */
6379 +static void __exit ring_exit(void)
6381 + struct list_head *ptr;
6382 + struct ring_element *entry;
6384 + for(ptr = ring_table.next; ptr != &ring_table; ptr = ptr->next) {
6385 + entry = list_entry(ptr, struct ring_element, list);
6389 + while(ring_cluster_list != NULL) {
6390 + struct ring_cluster *next = ring_cluster_list->next;
6391 + kfree(ring_cluster_list);
6392 + ring_cluster_list = next;
6395 + set_skb_ring_handler(NULL);
6396 + set_buffer_ring_handler(NULL);
6397 + sock_unregister(PF_RING);
6399 + printk("PF_RING shut down.\n");
6402 +/* ************************************ */
6404 +static int __init ring_init(void)
6406 + printk("Welcome to PF_RING %s\n(C) 2004 L.Deri <deri@ntop.org>\n",
6409 + INIT_LIST_HEAD(&ring_table);
6410 + ring_cluster_list = NULL;
6412 + sock_register(&ring_family_ops);
6414 + set_skb_ring_handler(skb_ring_handler);
6415 + set_buffer_ring_handler(buffer_ring_handler);
6417 + if(get_buffer_ring_handler() != buffer_ring_handler) {
6418 + printk("PF_RING: set_buffer_ring_handler FAILED\n");
6420 + set_skb_ring_handler(NULL);
6421 + set_buffer_ring_handler(NULL);
6422 + sock_unregister(PF_RING);
6425 + printk("PF_RING: bucket length %d bytes\n", bucket_len);
6426 + printk("PF_RING: ring slots %d\n", num_slots);
6427 + printk("PF_RING: sample rate %d [1=no sampling]\n", sample_rate);
6428 + printk("PF_RING: capture TX %s\n",
6429 + enable_tx_capture ? "Yes [RX+TX]" : "No [RX only]");
6430 + printk("PF_RING: transparent mode %s\n",
6431 + transparent_mode ? "Yes" : "No");
6433 + printk("PF_RING initialized correctly.\n");
6438 +module_init(ring_init);
6439 +module_exit(ring_exit);
6440 +MODULE_LICENSE("GPL");
6442 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
6443 +MODULE_ALIAS_NETPROTO(PF_RING);