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