PF_RING patch for Linux 2.4.26 (tested with 2.4.26 and .25, but should work with earlier versions too) made by Georg Lukas This patch is based on work by Luca Deri (see http://luca.ntop.org/Ring.pdf for more details). --- linux-2.4.26/net/core/dev.c 2004-02-18 14:36:32.000000000 +0100 +++ linux-2.4.26-pfring/net/core/dev.c 2004-02-06 12:40:47.000000000 +0100 @@ -108,6 +108,16 @@ extern int plip_init(void); #endif +#define RING +/* #define RING_DEBUG */ + +#ifdef RING +#include + +handle_ring_skb ring_handler = NULL; +EXPORT_SYMBOL(ring_handler); + +#endif /* This define, if set, will randomly drop a packet when congestion * is more than moderate. It helps fairness in the multi-interface @@ -1278,6 +1288,13 @@ struct softnet_data *queue; unsigned long flags; +#ifdef RING + if(ring_handler && ring_handler(skb)) { + /* The packet has been copied into a ring */ + return(NET_RX_SUCCESS); + } +#endif /* RING */ + if (skb->stamp.tv_sec == 0) do_gettimeofday(&skb->stamp); @@ -1464,6 +1481,13 @@ int ret = NET_RX_DROP; unsigned short type = skb->protocol; +#ifdef RING + if(ring_handler && ring_handler(skb)) { + /* The packet has been copied into a ring */ + return(NET_RX_SUCCESS); + } +#endif /* RING */ + if (skb->stamp.tv_sec == 0) do_gettimeofday(&skb->stamp); --- linux-2.4.26/include/net/sock.h 2004-03-04 12:14:43.000000000 +0100 +++ linux-2.4.26-pfring/include/net/sock.h 2004-02-06 12:37:24.000000000 +0100 @@ -645,6 +645,9 @@ #if defined (CONFIG_PACKET) || defined(CONFIG_PACKET_MODULE) struct packet_opt *af_packet; #endif + /* L. Deri */ + struct ring_opt *pf_ring; + #if defined(CONFIG_X25) || defined(CONFIG_X25_MODULE) x25_cb *x25; #endif --- linux-2.4.26/include/linux/ring.h 1970-01-01 01:00:00.000000000 +0100 +++ linux-2.4.26-pfring/include/linux/ring.h 2004-02-06 12:37:24.000000000 +0100 @@ -0,0 +1,65 @@ +/* + * Definitions for packet ring + * + * 2004 - Luca Deri + */ +#ifndef __RING_H +#define __RING_H + + +#define INCLUDE_MAC_INFO + +#ifdef INCLUDE_MAC_INFO +#define SKB_DISPLACEMENT 14 /* Include MAC address information */ +#else +#define SKB_DISPLACEMENT 0 /* Do NOT include MAC address information */ +#endif + +typedef struct flowSlotInfo { + u_int tot_slots, slot_len, sample_rate, tot_num_pages, pkts_per_page; + u_int32_t tot_pkts, tot_lost; + u_short insert_idx; + u_short remove_idx; +} FlowSlotInfo; + +typedef struct flowSlot { + u_char slot_state; /* 0=empty, 1=full */ + u_short slot_len; + u_char bucket; /* bucket[bucketLen] */ +} FlowSlot; + +/* *********************************** */ + +#ifndef HAVE_PCAP +struct pcap_pkthdr { + struct timeval ts; /* time stamp */ + u_int32_t caplen; /* length of portion present */ + u_int32_t len; /* length this packet (off wire) */ +}; +#endif + +/* *********************************** */ + +#ifdef __KERNEL__ +FlowSlotInfo* getRingPtr(void); +int allocateRing(char *deviceName, u_int numSlots, u_int bucketLen, u_int sampleRate); +unsigned int pollRing(struct file *fp, struct poll_table_struct * wait); +void deallocateRing(void); + +/* ************************* */ + +typedef int (*handle_ring_skb)(struct sk_buff *skb); + +#endif /* __KERNEL__ */ + +/* *********************************** */ + +#define PF_RING 27 /* Packet Ring */ +#define SOCK_RING PF_RING + +/* ioctl() */ +#define SIORINGPOLL 0x8888 + +/* *********************************** */ + +#endif /* __RING_H */ --- linux-2.4.26/net/core/Makefile 2003-11-28 19:26:21.000000000 +0100 +++ linux-2.4.26-pfring/net/core/Makefile 2004-04-23 01:01:59.000000000 +0200 @@ -9,7 +9,7 @@ O_TARGET := core.o -export-objs := netfilter.o profile.o +export-objs := dev.o netfilter.o profile.o obj-y := sock.o skbuff.o iovec.o datagram.o scm.o