1 diff -urN ppp.old/pppd/Makefile.linux ppp.dev/pppd/Makefile.linux
2 --- ppp.old/pppd/Makefile.linux 2006-03-18 15:58:00.000000000 +0100
3 +++ ppp.dev/pppd/Makefile.linux 2006-03-18 16:52:01.000000000 +0100
5 # and that the kernel driver support PPP packet filtering.
8 +# Support for precompiled filters
11 # Uncomment the next line to enable multilink PPP (enabled by default)
12 # Linux distributions: Please leave multilink ENABLED in your builds
18 +ifdef PRECOMPILED_FILTER
19 +PPPDSRCS += pcap_pcc.c
20 +HEADERS += pcap_pcc.h
21 +PPPDOBJS += pcap_pcc.o
22 +LIBS += $(STAGING_DIR)/usr/lib/libpcap.a
23 +CFLAGS += -DPPP_FILTER -DPPP_PRECOMPILED_FILTER -I$(STAGING_DIR)/usr/include
27 PPPDSRCS += ipv6cp.c eui64.c
28 HEADERS += ipv6cp.h eui64.h
29 diff -urN ppp.old/pppd/demand.c ppp.dev/pppd/demand.c
30 --- ppp.old/pppd/demand.c 2006-03-18 15:58:00.000000000 +0100
31 +++ ppp.dev/pppd/demand.c 2006-03-18 18:09:16.000000000 +0100
34 proto = PPP_PROTOCOL(p);
36 + *p = 1; /* set outbound for the filter rule */
37 if (pass_filter.bf_len != 0
38 && bpf_filter(pass_filter.bf_insns, p, len, len) == 0)
40 if (active_filter.bf_len != 0
41 && bpf_filter(active_filter.bf_insns, p, len, len) == 0)
43 + *p = 0xff; /* restore original ppp header */
45 for (i = 0; (protp = protocols[i]) != NULL; ++i) {
46 if (protp->protocol < 0xC000 && (protp->protocol & ~0x8000) == proto) {
47 diff -urN ppp.old/pppd/options.c ppp.dev/pppd/options.c
48 --- ppp.old/pppd/options.c 2006-03-18 15:58:00.000000000 +0100
49 +++ ppp.dev/pppd/options.c 2006-03-18 18:05:58.000000000 +0100
55 - * DLT_PPP_WITH_DIRECTION is in current libpcap cvs, and should be in
56 - * libpcap-0.8.4. Until that is released, use DLT_PPP - but that means
57 - * we lose the inbound and outbound qualifiers.
59 -#ifndef DLT_PPP_WITH_DIRECTION
60 -#define DLT_PPP_WITH_DIRECTION DLT_PPP
62 +#include <pcap-bpf.h>
67 static int loadplugin __P((char **));
70 +#ifdef PPP_PRECOMPILED_FILTER
71 +#include "pcap_pcc.h"
72 +static int setprecompiledpassfilter __P((char **));
73 +static int setprecompiledactivefilter __P((char **));
78 static int setpassfilter __P((char **));
79 static int setactivefilter __P((char **));
81 "set filter for active pkts", OPT_PRIO },
84 +#ifdef PPP_PRECOMPILED_FILTER
85 + { "precompiled-pass-filter", 1, setprecompiledpassfilter,
86 + "set precompiled filter for packets to pass", OPT_PRIO },
88 + { "precompiled-active-filter", 1, setprecompiledactivefilter,
89 + "set precompiled filter for active pkts", OPT_PRIO },
93 { "maxoctets", o_int, &maxoctets,
94 "Set connection traffic limit",
95 @@ -1447,6 +1455,29 @@
99 +#ifdef PPP_PRECOMPILED_FILTER
101 + * setprecompiledpassfilter - Set the pass filter for packets using a
102 + * precompiled expression
105 +setprecompiledpassfilter(argv)
108 + return pcap_pre_compiled (*argv, &pass_filter);
112 + * setactivefilter - Set the active filter for packets
115 +setprecompiledactivefilter(argv)
118 + return pcap_pre_compiled (*argv, &active_filter);
124 * setpassfilter - Set the pass filter for packets
125 @@ -1458,7 +1489,7 @@
129 - pc = pcap_open_dead(DLT_PPP_WITH_DIRECTION, 65535);
130 + pc = pcap_open_dead(DLT_PPP_PPPD, 65535);
131 if (pcap_compile(pc, &pass_filter, *argv, 1, netmask) == -1) {
132 option_error("error in pass-filter expression: %s\n",
134 @@ -1479,7 +1510,7 @@
138 - pc = pcap_open_dead(DLT_PPP_WITH_DIRECTION, 65535);
139 + pc = pcap_open_dead(DLT_PPP_PPPD, 65535);
140 if (pcap_compile(pc, &active_filter, *argv, 1, netmask) == -1) {
141 option_error("error in active-filter expression: %s\n",
143 diff -urN ppp.old/pppd/pcap_pcc.c ppp.dev/pppd/pcap_pcc.c
144 --- ppp.old/pppd/pcap_pcc.c 1970-01-01 01:00:00.000000000 +0100
145 +++ ppp.dev/pppd/pcap_pcc.c 2006-03-18 16:51:31.000000000 +0100
148 +#include <pcap-bpf.h>
155 +int pcap_pre_compiled (char * fname, struct bpf_program *p)
158 + int line = 0, size = 0, index=0, ret=1;
159 + FILE *f = fopen (fname, "r");
162 + option_error("error opening precompiled active-filter '%s': %s",
163 + fname, strerror (errno));
166 + while (fgets (buf, 127, f))
181 + struct bpf_insn * insn = & p->bf_insns[index];
182 + unsigned code, jt, jf, k;
183 + if (sscanf (buf, "%u %u %u %u", &code, &jt, &jf, &k) != 4)
195 + if (sscanf (buf, "%u", &size) != 1)
200 + p->bf_insns = (struct bpf_insn *)
201 + malloc (size * sizeof (struct bpf_insn));
206 + option_error("error in precompiled active-filter,"
207 + " expected %d expressions, got %dn",
215 + option_error("error in precompiled active-filter"
216 + " expression line %s:%d (wrong size)\n",
221 diff -urN ppp.old/pppd/pcap_pcc.h ppp.dev/pppd/pcap_pcc.h
222 --- ppp.old/pppd/pcap_pcc.h 1970-01-01 01:00:00.000000000 +0100
223 +++ ppp.dev/pppd/pcap_pcc.h 2006-03-18 15:59:14.000000000 +0100
230 +int pcap_pre_compiled (char * fname, struct bpf_program *p);
231 +#endif /* PCAP_PCC_H */