PF_RING patch for Linux 2.6.5 made by Georg Lukas This patch is based on work by Luca Deri (see http://luca.ntop.org/Ring.pdf for more details). diff -uNr linux-2.6.5/include/linux/ring.h linux-2.6.5-pfring/include/linux/ring.h --- linux-2.6.5/include/linux/ring.h 1970-01-01 01:00:00.000000000 +0100 +++ linux-2.6.5-pfring/include/linux/ring.h 2004-04-20 17:05:59.883265512 +0200 @@ -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 */ diff -uNr linux-2.6.5/net/core/dev.c linux-2.6.5-pfring/net/core/dev.c --- linux-2.6.5/net/core/dev.c 2004-04-20 17:19:00.674567192 +0200 +++ linux-2.6.5-pfring/net/core/dev.c 2004-04-20 17:09:18.821022376 +0200 @@ -224,6 +224,16 @@ extern int netdev_register_sysfs(struct net_device *); extern int netdev_unregister_sysfs(struct net_device *); +#define RING +/* #define RING_DEBUG */ + +#ifdef RING +#include + +handle_ring_skb ring_handler = NULL; +EXPORT_SYMBOL(ring_handler); + +#endif /******************************************************************************* @@ -1540,6 +1550,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 */ + #ifdef CONFIG_NETPOLL_RX if (skb->dev->netpoll_rx && netpoll_rx(skb)) { kfree_skb(skb); @@ -1702,6 +1719,13 @@ int ret = NET_RX_DROP; unsigned short type; +#ifdef RING + if(ring_handler && ring_handler(skb)) { + /* The packet has been copied into a ring */ + return(NET_RX_SUCCESS); + } +#endif /* RING */ + #ifdef CONFIG_NETPOLL_RX if (skb->dev->netpoll_rx && skb->dev->poll && netpoll_rx(skb)) { kfree_skb(skb);