]> git.pld-linux.org Git - packages/libpcap.git/blame - libpcap-pf_ring.patch
- updated to 1.10.4
[packages/libpcap.git] / libpcap-pf_ring.patch
CommitLineData
04696e3a 1--- Makefile.in.org 2007-06-10 22:02:36.594026862 +0000
2+++ Makefile.in 2007-06-10 22:03:08.811408859 +0000
04696e3a 3@@ -58,7 +58,7 @@
4
5 # Standard CFLAGS
6 CFLAGS = $(CCOPT) $(INCLS) $(DEFS)
7-CFLAGS_SHAREDLIB = -shared -Wl,-soname,$(SOLIBRARY).$(MAJ)
8+CFLAGS_SHAREDLIB = -shared -Wl,-soname,$(SOLIBRARY).$(MAJ) -lpfring
9
10 INSTALL = @INSTALL@
11 INSTALL_PROGRAM = @INSTALL_PROGRAM@
12--- pcap-int.h_ 2005-07-07 06:56:04.000000000 +0000
13+++ pcap-int.h 2006-01-11 17:47:18.000000000 +0000
14@@ -51,6 +51,11 @@
15 #include <io.h>
16 #endif
17
18+#ifdef HAVE_PF_RING
19+#define HAVE_PCAP
20+#include "pfring.h"
21+#endif
22+
23 /*
24 * Savefile
25 */
26@@ -185,6 +190,10 @@
27 u_int *dlt_list;
28
29 struct pcap_pkthdr pcap_header; /* This is needed for the pcap_next_ex() to work */
30+
31+#ifdef HAVE_PF_RING
32+ pfring *ring;
33+#endif
34 };
35
36 /*
37--- pcap-linux.c_ 2005-08-16 04:25:26.000000000 +0000
38+++ pcap-linux.c 2007-04-09 22:42:47.000000000 +0000
39@@ -72,6 +72,7 @@
40 * shorter, on the wire, than the IP header said it should have been.
41 */
42
43+#define HAVE_PF_RING
44
45 #ifdef HAVE_CONFIG_H
46 #include "config.h"
47@@ -270,6 +271,19 @@
48 handle->snapshot = snaplen;
49 handle->md.timeout = to_ms;
50
51+#ifdef HAVE_PF_RING
52+ handle->ring = pfring_open((char*)device, promisc);
53+
54+ if(handle->ring != NULL) {
55+ handle->fd = handle->ring->fd;
56+ handle->bufsize = handle->snapshot;
57+ handle->linktype = DLT_EN10MB;
58+ handle->offset = 2;
59+
60+ /* printf("Open HAVE_PF_RING(%s)\n", device); */
61+ } else {
62+ /* printf("Open HAVE_PF_RING(%s) failed. Fallback to pcap\n", device); */
63+#endif
64 /*
65 * NULL and "any" are special devices which give us the hint to
66 * monitor all devices.
8814db0c 67@@ -406,6 +420,9 @@
68 }
04696e3a 69 handle->bufsize = handle->snapshot;
70 }
71+#ifdef HAVE_PF_RING
72+ }
73+#endif
74
75 /* Allocate the buffer */
76
50b3dd17 77@@ -472,6 +489,47 @@
04696e3a 78 int packet_len, caplen;
79 struct pcap_pkthdr pcap_header;
80
81+#ifdef HAVE_PF_RING
82+ if(handle->ring) {
83+ retry:
84+
85+ if (handle->break_loop) {
86+ /*
87+ * Yes - clear the flag that indicates that it
88+ * has, and return -2 as an indication that we
89+ * were told to break out of the loop.
90+ *
91+ * Patch courtesy of Michael Stiller <ms@2scale.net>
92+ */
93+ handle->break_loop = 0;
94+ return -2;
95+ }
96+
97+ packet_len = pfring_recv(handle->ring, (char*)handle->buffer,
98+ handle->bufsize,
99+ (struct pfring_pkthdr*)&pcap_header,
100+ 1 /* wait_for_incoming_packet */);
101+ if (packet_len > 0) {
102+ bp = handle->buffer;
50b3dd17 103+ packet_len = pcap_header.len;
104+ caplen = pcap_header.caplen; /* ensure that our capture length does not exceed our snapshot length */
8814db0c 105+
50b3dd17 106+ if (caplen > handle->snapshot)
107+ caplen = handle->snapshot;
108+ if (caplen > handle->bufsize) /* sanity check and prevent buffer overruns, paranoia in the extreme */
109+ caplen = handle->bufsize;
8814db0c 110+
50b3dd17 111+ pcap_header.caplen = caplen; /* reset our header capture length for the callee! */
8814db0c 112+
04696e3a 113+ goto pfring_pcap_read_packet;
114+ } else if (packet_len == -1 && errno == EINTR)
115+ goto retry;
116+ else
117+ return(-1);
118+ }
119+
120+#endif
121+
122 #ifdef HAVE_PF_PACKET_SOCKETS
123 /*
124 * If this is a cooked device, leave extra room for a
8814db0c 125@@ -632,6 +691,10 @@
04696e3a 126 }
127 #endif
128
129+#ifdef HAVE_PF_RING
130+ pfring_pcap_read_packet:
131+#endif
132+
133 /*
134 * XXX: According to the kernel source we should get the real
135 * packet len if calling recvfrom with MSG_TRUNC set. It does
8814db0c 136@@ -678,8 +741,8 @@
04696e3a 137 }
138 }
139
140+#ifndef HAVE_PF_RING
141 /* Fill in our own header data */
142-
143 if (ioctl(handle->fd, SIOCGSTAMP, &pcap_header.ts) == -1) {
144 snprintf(handle->errbuf, sizeof(handle->errbuf),
8814db0c 145 "SIOCGSTAMP: %s", pcap_strerror(errno));
146@@ -687,6 +750,7 @@
04696e3a 147 }
148 pcap_header.caplen = caplen;
149 pcap_header.len = packet_len;
150+#endif
151
152 /*
153 * Count the packet.
8814db0c 154@@ -1701,6 +1765,13 @@
04696e3a 155 struct pcap *p, *prevp;
156 struct ifreq ifr;
157
158+#ifdef HAVE_PF_RING
159+ if(handle->ring) {
160+ pfring_close(handle->ring);
161+ return;
162+ }
163+#endif
164+
165 if (handle->md.clear_promisc) {
166 /*
167 * We put the interface into promiscuous mode; take
8814db0c 168@@ -2140,7 +2211,13 @@
04696e3a 169 * the filtering done in userland even if it could have been
170 * done in the kernel.
171 */
172- if (setsockopt(handle->fd, SOL_SOCKET, SO_ATTACH_FILTER,
173+ if (setsockopt(handle->fd,
174+#ifdef HAVE_PF_RING
175+ 0,
176+#else
177+ SOL_SOCKET,
178+#endif
179+ SO_ATTACH_FILTER,
180 &total_fcode, sizeof(total_fcode)) == 0) {
181 char drain[1];
182
8814db0c 183@@ -2149,6 +2226,7 @@
04696e3a 184 */
185 total_filter_on = 1;
186
187+#ifndef HAVE_PF_RING
188 /*
189 * Save the socket's current mode, and put it in
190 * non-blocking mode; we drain it by reading packets
8814db0c 191@@ -2171,12 +2249,19 @@
04696e3a 192 return -2;
193 }
194 }
195+#endif
196 }
197
198 /*
199 * Now attach the new filter.
200 */
201- ret = setsockopt(handle->fd, SOL_SOCKET, SO_ATTACH_FILTER,
202+ ret = setsockopt(handle->fd,
203+#ifdef HAVE_PF_RING
204+ 0,
205+#else
206+ SOL_SOCKET,
207+#endif
208+ SO_ATTACH_FILTER,
209 fcode, sizeof(*fcode));
210 if (ret == -1 && total_filter_on) {
211 /*
8814db0c 212@@ -2213,3 +2298,9 @@
04696e3a 213 &dummy, sizeof(dummy));
214 }
215 #endif
216+
217+#ifdef HAVE_PF_RING
218+int pcap_set_cluster(pfring *ring, u_int clusterId) { return(pfring_set_cluster(ring, clusterId)); }
219+int pcap_remove_from_cluster(pfring *ring) { return(pfring_remove_from_cluster(ring)); }
220+int pcap_set_reflector(pfring *ring, char *reflectorDevice) { return(pfring_set_reflector(ring, reflectorDevice)); }
221+#endif
This page took 0.384136 seconds and 4 git commands to generate.