[ppp] Make patches apply agagin.
[openwrt/svn-archive/archive.git] / package / ppp / patches / 310-precompile_filter.patch
1 diff -Naur ppp-2.4.4.orig/pppd/Makefile.linux ppp-2.4.4/pppd/Makefile.linux
2 --- ppp-2.4.4.orig/pppd/Makefile.linux 2009-05-07 22:31:54.000000000 -0400
3 +++ ppp-2.4.4/pppd/Makefile.linux 2009-05-07 22:33:12.000000000 -0400
4 @@ -50,6 +50,9 @@
5 # and that the kernel driver support PPP packet filtering.
6 #FILTER=y
7
8 +# Support for precompiled filters
9 +PRECOMPILED_FILTER=y
10 +
11 # Uncomment the next line to enable multilink PPP (enabled by default)
12 # Linux distributions: Please leave multilink ENABLED in your builds
13 # of pppd!
14 @@ -175,6 +178,14 @@
15 endif
16 endif
17
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
24 +endif
25 +
26 ifdef HAVE_INET6
27 PPPDSRCS += ipv6cp.c eui64.c
28 HEADERS += ipv6cp.h eui64.h
29 diff -Naur ppp-2.4.4.orig/pppd/options.c ppp-2.4.4/pppd/options.c
30 --- ppp-2.4.4.orig/pppd/options.c 2009-05-07 22:25:24.000000000 -0400
31 +++ ppp-2.4.4/pppd/options.c 2009-05-07 22:38:28.000000000 -0400
32 @@ -57,6 +57,7 @@
33
34 #ifdef PPP_FILTER
35 #include <pcap.h>
36 +#include <pcap-bpf.h>
37 /*
38 * There have been 3 or 4 different names for this in libpcap CVS, but
39 * this seems to be what they have settled on...
40 @@ -160,6 +161,13 @@
41 static int loadplugin __P((char **));
42 #endif
43
44 +#ifdef PPP_PRECOMPILED_FILTER
45 +#include "pcap_pcc.h"
46 +static int setprecompiledpassfilter __P((char **));
47 +static int setprecompiledactivefilter __P((char **));
48 +#undef PPP_FILTER
49 +#endif
50 +
51 #ifdef PPP_FILTER
52 static int setpassfilter __P((char **));
53 static int setactivefilter __P((char **));
54 @@ -317,6 +325,14 @@
55 "set filter for active pkts", OPT_PRIO },
56 #endif
57
58 +#ifdef PPP_PRECOMPILED_FILTER
59 + { "precompiled-pass-filter", 1, setprecompiledpassfilter,
60 + "set precompiled filter for packets to pass", OPT_PRIO },
61 +
62 + { "precompiled-active-filter", 1, setprecompiledactivefilter,
63 + "set precompiled filter for active pkts", OPT_PRIO },
64 +#endif
65 +
66 #ifdef MAXOCTETS
67 { "maxoctets", o_int, &maxoctets,
68 "Set connection traffic limit",
69 @@ -1456,6 +1472,29 @@
70 return ok;
71 }
72
73 +#ifdef PPP_PRECOMPILED_FILTER
74 +/*
75 + * setprecompiledpassfilter - Set the pass filter for packets using a
76 + * precompiled expression
77 + */
78 +static int
79 +setprecompiledpassfilter(argv)
80 + char **argv;
81 +{
82 + return pcap_pre_compiled (*argv, &pass_filter);
83 +}
84 +
85 +/*
86 + * setactivefilter - Set the active filter for packets
87 + */
88 +static int
89 +setprecompiledactivefilter(argv)
90 + char **argv;
91 +{
92 + return pcap_pre_compiled (*argv, &active_filter);
93 +}
94 +#endif
95 +
96 #ifdef PPP_FILTER
97 /*
98 * setpassfilter - Set the pass filter for packets
99 diff -Naur ppp-2.4.4.orig/pppd/pcap_pcc.c ppp-2.4.4/pppd/pcap_pcc.c
100 --- ppp-2.4.4.orig/pppd/pcap_pcc.c 1969-12-31 19:00:00.000000000 -0500
101 +++ ppp-2.4.4/pppd/pcap_pcc.c 2009-05-07 22:33:12.000000000 -0400
102 @@ -0,0 +1,74 @@
103 +#include <pcap.h>
104 +#include <pcap-bpf.h>
105 +#include <stdio.h>
106 +#include <stdlib.h>
107 +#include <string.h>
108 +#include <errno.h>
109 +#include "pppd.h"
110 +
111 +int pcap_pre_compiled (char * fname, struct bpf_program *p)
112 +{
113 + char buf[128];
114 + int line = 0, size = 0, index=0, ret=1;
115 + FILE *f = fopen (fname, "r");
116 + if (!f)
117 + {
118 + option_error("error opening precompiled active-filter '%s': %s",
119 + fname, strerror (errno));
120 + return 0;
121 + }
122 + while (fgets (buf, 127, f))
123 + {
124 + line++;
125 + if (*buf == '#')
126 + continue;
127 + if (size)
128 + {
129 + /*
130 + struct bpf_insn {
131 + u_short code;
132 + u_char jt;
133 + u_char jf;
134 + bpf_int32 k;
135 + }
136 + */
137 + struct bpf_insn * insn = & p->bf_insns[index];
138 + unsigned code, jt, jf, k;
139 + if (sscanf (buf, "%u %u %u %u", &code, &jt, &jf, &k) != 4)
140 + {
141 + goto err;
142 + }
143 + insn->code = code;
144 + insn->jt = jt;
145 + insn->jf = jf;
146 + insn->k = k;
147 + index++;
148 + }
149 + else
150 + {
151 + if (sscanf (buf, "%u", &size) != 1)
152 + {
153 + goto err;
154 + }
155 + p->bf_len = size;
156 + p->bf_insns = (struct bpf_insn *)
157 + malloc (size * sizeof (struct bpf_insn));
158 + }
159 + }
160 + if (size != index)
161 + {
162 + option_error("error in precompiled active-filter,"
163 + " expected %d expressions, got %dn",
164 + size, index);
165 + ret = 0;
166 + }
167 + fclose(f);
168 + return ret;
169 +
170 +err:
171 + option_error("error in precompiled active-filter"
172 + " expression line %s:%d (wrong size)\n",
173 + fname, line);
174 + fclose (f);
175 + return 0;
176 +}
177 diff -Naur ppp-2.4.4.orig/pppd/pcap_pcc.h ppp-2.4.4/pppd/pcap_pcc.h
178 --- ppp-2.4.4.orig/pppd/pcap_pcc.h 1969-12-31 19:00:00.000000000 -0500
179 +++ ppp-2.4.4/pppd/pcap_pcc.h 2009-05-07 22:33:12.000000000 -0400
180 @@ -0,0 +1,7 @@
181 +#ifndef PCAP_PCC_H
182 +#define PCAP_PCC_H
183 +
184 +#include <pcap.h>
185 +
186 +int pcap_pre_compiled (char * fname, struct bpf_program *p);
187 +#endif /* PCAP_PCC_H */