diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2009-05-20 22:36:38 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2009-05-20 22:36:38 +0000 |
commit | 9137c11605e9bd0f7cc67895fd852e0b04cb672d (patch) | |
tree | 1796065955c8d3cb89a35b12741566a7198d93fd /package/ppp/patches/310-precompile_filter.patch | |
parent | 89127a67f2707136d0219cba44138aa65889ebef (diff) | |
download | master-31e0f0ae-9137c11605e9bd0f7cc67895fd852e0b04cb672d.tar.gz master-31e0f0ae-9137c11605e9bd0f7cc67895fd852e0b04cb672d.tar.bz2 master-31e0f0ae-9137c11605e9bd0f7cc67895fd852e0b04cb672d.zip |
update ppp to v2.4.4 (#5102)
SVN-Revision: 15955
Diffstat (limited to 'package/ppp/patches/310-precompile_filter.patch')
-rw-r--r-- | package/ppp/patches/310-precompile_filter.patch | 374 |
1 files changed, 374 insertions, 0 deletions
diff --git a/package/ppp/patches/310-precompile_filter.patch b/package/ppp/patches/310-precompile_filter.patch new file mode 100644 index 0000000000..f392e430ab --- /dev/null +++ b/package/ppp/patches/310-precompile_filter.patch @@ -0,0 +1,374 @@ +diff -Naur ppp-2.4.4.orig/pppd/Makefile.linux ppp-2.4.4/pppd/Makefile.linux +--- ppp-2.4.4.orig/pppd/Makefile.linux 2009-05-07 22:31:54.000000000 -0400 ++++ ppp-2.4.4/pppd/Makefile.linux 2009-05-07 22:33:12.000000000 -0400 +@@ -50,6 +50,9 @@ + # and that the kernel driver support PPP packet filtering. + #FILTER=y + ++# Support for precompiled filters ++PRECOMPILED_FILTER=y ++ + # Uncomment the next line to enable multilink PPP (enabled by default) + # Linux distributions: Please leave multilink ENABLED in your builds + # of pppd! +@@ -175,6 +178,14 @@ + endif + endif + ++ifdef PRECOMPILED_FILTER ++PPPDSRCS += pcap_pcc.c ++HEADERS += pcap_pcc.h ++PPPDOBJS += pcap_pcc.o ++LIBS += $(STAGING_DIR)/usr/lib/libpcap.a ++CFLAGS += -DPPP_FILTER -DPPP_PRECOMPILED_FILTER -I$(STAGING_DIR)/usr/include ++endif ++ + ifdef HAVE_INET6 + PPPDSRCS += ipv6cp.c eui64.c + HEADERS += ipv6cp.h eui64.h +diff -Naur ppp-2.4.4.orig/pppd/options.c ppp-2.4.4/pppd/options.c +--- ppp-2.4.4.orig/pppd/options.c 2009-05-07 22:25:24.000000000 -0400 ++++ ppp-2.4.4/pppd/options.c 2009-05-07 22:38:28.000000000 -0400 +@@ -57,6 +57,7 @@ + + #ifdef PPP_FILTER + #include <pcap.h> ++#include <pcap-bpf.h> + /* + * There have been 3 or 4 different names for this in libpcap CVS, but + * this seems to be what they have settled on... +@@ -160,6 +161,13 @@ + static int loadplugin __P((char **)); + #endif + ++#ifdef PPP_PRECOMPILED_FILTER ++#include "pcap_pcc.h" ++static int setprecompiledpassfilter __P((char **)); ++static int setprecompiledactivefilter __P((char **)); ++#undef PPP_FILTER ++#endif ++ + #ifdef PPP_FILTER + static int setpassfilter __P((char **)); + static int setactivefilter __P((char **)); +@@ -317,6 +325,14 @@ + "set filter for active pkts", OPT_PRIO }, + #endif + ++#ifdef PPP_PRECOMPILED_FILTER ++ { "precompiled-pass-filter", 1, setprecompiledpassfilter, ++ "set precompiled filter for packets to pass", OPT_PRIO }, ++ ++ { "precompiled-active-filter", 1, setprecompiledactivefilter, ++ "set precompiled filter for active pkts", OPT_PRIO }, ++#endif ++ + #ifdef MAXOCTETS + { "maxoctets", o_int, &maxoctets, + "Set connection traffic limit", +@@ -1456,6 +1472,29 @@ + return ok; + } + ++#ifdef PPP_PRECOMPILED_FILTER ++/* ++ * setprecompiledpassfilter - Set the pass filter for packets using a ++ * precompiled expression ++ */ ++static int ++setprecompiledpassfilter(argv) ++ char **argv; ++{ ++ return pcap_pre_compiled (*argv, &pass_filter); ++} ++ ++/* ++ * setactivefilter - Set the active filter for packets ++ */ ++static int ++setprecompiledactivefilter(argv) ++ char **argv; ++{ ++ return pcap_pre_compiled (*argv, &active_filter); ++} ++#endif ++ + #ifdef PPP_FILTER + /* + * setpassfilter - Set the pass filter for packets +diff -Naur ppp-2.4.4.orig/pppd/pcap_pcc.c ppp-2.4.4/pppd/pcap_pcc.c +--- ppp-2.4.4.orig/pppd/pcap_pcc.c 1969-12-31 19:00:00.000000000 -0500 ++++ ppp-2.4.4/pppd/pcap_pcc.c 2009-05-07 22:33:12.000000000 -0400 +@@ -0,0 +1,74 @@ ++#include <pcap.h> ++#include <pcap-bpf.h> ++#include <stdio.h> ++#include <stdlib.h> ++#include <string.h> ++#include <errno.h> ++#include "pppd.h" ++ ++int pcap_pre_compiled (char * fname, struct bpf_program *p) ++{ ++ char buf[128]; ++ int line = 0, size = 0, index=0, ret=1; ++ FILE *f = fopen (fname, "r"); ++ if (!f) ++ { ++ option_error("error opening precompiled active-filter '%s': %s", ++ fname, strerror (errno)); ++ return 0; ++ } ++ while (fgets (buf, 127, f)) ++ { ++ line++; ++ if (*buf == '#') ++ continue; ++ if (size) ++ { ++ /* ++ struct bpf_insn { ++ u_short code; ++ u_char jt; ++ u_char jf; ++ bpf_int32 k; ++ } ++ */ ++ struct bpf_insn * insn = & p->bf_insns[index]; ++ unsigned code, jt, jf, k; ++ if (sscanf (buf, "%u %u %u %u", &code, &jt, &jf, &k) != 4) ++ { ++ goto err; ++ } ++ insn->code = code; ++ insn->jt = jt; ++ insn->jf = jf; ++ insn->k = k; ++ index++; ++ } ++ else ++ { ++ if (sscanf (buf, "%u", &size) != 1) ++ { ++ goto err; ++ } ++ p->bf_len = size; ++ p->bf_insns = (struct bpf_insn *) ++ malloc (size * sizeof (struct bpf_insn)); ++ } ++ } ++ if (size != index) ++ { ++ option_error("error in precompiled active-filter," ++ " expected %d expressions, got %dn", ++ size, index); ++ ret = 0; ++ } ++ fclose(f); ++ return ret; ++ ++err: ++ option_error("error in precompiled active-filter" ++ " expression line %s:%d (wrong size)\n", ++ fname, line); ++ fclose (f); ++ return 0; ++} +diff -Naur ppp-2.4.4.orig/pppd/pcap_pcc.h ppp-2.4.4/pppd/pcap_pcc.h +--- ppp-2.4.4.orig/pppd/pcap_pcc.h 1969-12-31 19:00:00.000000000 -0500 ++++ ppp-2.4.4/pppd/pcap_pcc.h 2009-05-07 22:33:12.000000000 -0400 +@@ -0,0 +1,7 @@ ++#ifndef PCAP_PCC_H ++#define PCAP_PCC_H ++ ++#include <pcap.h> ++ ++int pcap_pre_compiled (char * fname, struct bpf_program *p); ++#endif /* PCAP_PCC_H */ +diff -Naur ppp-2.4.4.orig/pppd/Makefile.linux ppp-2.4.4/pppd/Makefile.linux +--- ppp-2.4.4.orig/pppd/Makefile.linux 2009-05-07 22:31:54.000000000 -0400 ++++ ppp-2.4.4/pppd/Makefile.linux 2009-05-07 22:33:12.000000000 -0400 +@@ -50,6 +50,9 @@ + # and that the kernel driver support PPP packet filtering. + #FILTER=y + ++# Support for precompiled filters ++PRECOMPILED_FILTER=y ++ + # Uncomment the next line to enable multilink PPP (enabled by default) + # Linux distributions: Please leave multilink ENABLED in your builds + # of pppd! +@@ -175,6 +178,14 @@ + endif + endif + ++ifdef PRECOMPILED_FILTER ++PPPDSRCS += pcap_pcc.c ++HEADERS += pcap_pcc.h ++PPPDOBJS += pcap_pcc.o ++LIBS += $(STAGING_DIR)/usr/lib/libpcap.a ++CFLAGS += -DPPP_FILTER -DPPP_PRECOMPILED_FILTER -I$(STAGING_DIR)/usr/include ++endif ++ + ifdef HAVE_INET6 + PPPDSRCS += ipv6cp.c eui64.c + HEADERS += ipv6cp.h eui64.h +diff -Naur ppp-2.4.4.orig/pppd/options.c ppp-2.4.4/pppd/options.c +--- ppp-2.4.4.orig/pppd/options.c 2009-05-07 22:25:24.000000000 -0400 ++++ ppp-2.4.4/pppd/options.c 2009-05-07 22:38:28.000000000 -0400 +@@ -57,6 +57,7 @@ + + #ifdef PPP_FILTER + #include <pcap.h> ++#include <pcap-bpf.h> + /* + * There have been 3 or 4 different names for this in libpcap CVS, but + * this seems to be what they have settled on... +@@ -160,6 +161,13 @@ + static int loadplugin __P((char **)); + #endif + ++#ifdef PPP_PRECOMPILED_FILTER ++#include "pcap_pcc.h" ++static int setprecompiledpassfilter __P((char **)); ++static int setprecompiledactivefilter __P((char **)); ++#undef PPP_FILTER ++#endif ++ + #ifdef PPP_FILTER + static int setpassfilter __P((char **)); + static int setactivefilter __P((char **)); +@@ -317,6 +325,14 @@ + "set filter for active pkts", OPT_PRIO }, + #endif + ++#ifdef PPP_PRECOMPILED_FILTER ++ { "precompiled-pass-filter", 1, setprecompiledpassfilter, ++ "set precompiled filter for packets to pass", OPT_PRIO }, ++ ++ { "precompiled-active-filter", 1, setprecompiledactivefilter, ++ "set precompiled filter for active pkts", OPT_PRIO }, ++#endif ++ + #ifdef MAXOCTETS + { "maxoctets", o_int, &maxoctets, + "Set connection traffic limit", +@@ -1456,6 +1472,29 @@ + return ok; + } + ++#ifdef PPP_PRECOMPILED_FILTER ++/* ++ * setprecompiledpassfilter - Set the pass filter for packets using a ++ * precompiled expression ++ */ ++static int ++setprecompiledpassfilter(argv) ++ char **argv; ++{ ++ return pcap_pre_compiled (*argv, &pass_filter); ++} ++ ++/* ++ * setactivefilter - Set the active filter for packets ++ */ ++static int ++setprecompiledactivefilter(argv) ++ char **argv; ++{ ++ return pcap_pre_compiled (*argv, &active_filter); ++} ++#endif ++ + #ifdef PPP_FILTER + /* + * setpassfilter - Set the pass filter for packets +diff -Naur ppp-2.4.4.orig/pppd/pcap_pcc.c ppp-2.4.4/pppd/pcap_pcc.c +--- ppp-2.4.4.orig/pppd/pcap_pcc.c 1969-12-31 19:00:00.000000000 -0500 ++++ ppp-2.4.4/pppd/pcap_pcc.c 2009-05-07 22:33:12.000000000 -0400 +@@ -0,0 +1,74 @@ ++#include <pcap.h> ++#include <pcap-bpf.h> ++#include <stdio.h> ++#include <stdlib.h> ++#include <string.h> ++#include <errno.h> ++#include "pppd.h" ++ ++int pcap_pre_compiled (char * fname, struct bpf_program *p) ++{ ++ char buf[128]; ++ int line = 0, size = 0, index=0, ret=1; ++ FILE *f = fopen (fname, "r"); ++ if (!f) ++ { ++ option_error("error opening precompiled active-filter '%s': %s", ++ fname, strerror (errno)); ++ return 0; ++ } ++ while (fgets (buf, 127, f)) ++ { ++ line++; ++ if (*buf == '#') ++ continue; ++ if (size) ++ { ++ /* ++ struct bpf_insn { ++ u_short code; ++ u_char jt; ++ u_char jf; ++ bpf_int32 k; ++ } ++ */ ++ struct bpf_insn * insn = & p->bf_insns[index]; ++ unsigned code, jt, jf, k; ++ if (sscanf (buf, "%u %u %u %u", &code, &jt, &jf, &k) != 4) ++ { ++ goto err; ++ } ++ insn->code = code; ++ insn->jt = jt; ++ insn->jf = jf; ++ insn->k = k; ++ index++; ++ } ++ else ++ { ++ if (sscanf (buf, "%u", &size) != 1) ++ { ++ goto err; ++ } ++ p->bf_len = size; ++ p->bf_insns = (struct bpf_insn *) ++ malloc (size * sizeof (struct bpf_insn)); ++ } ++ } ++ if (size != index) ++ { ++ option_error("error in precompiled active-filter," ++ " expected %d expressions, got %dn", ++ size, index); ++ ret = 0; ++ } ++ fclose(f); ++ return ret; ++ ++err: ++ option_error("error in precompiled active-filter" ++ " expression line %s:%d (wrong size)\n", ++ fname, line); ++ fclose (f); ++ return 0; ++} +diff -Naur ppp-2.4.4.orig/pppd/pcap_pcc.h ppp-2.4.4/pppd/pcap_pcc.h +--- ppp-2.4.4.orig/pppd/pcap_pcc.h 1969-12-31 19:00:00.000000000 -0500 ++++ ppp-2.4.4/pppd/pcap_pcc.h 2009-05-07 22:33:12.000000000 -0400 +@@ -0,0 +1,7 @@ ++#ifndef PCAP_PCC_H ++#define PCAP_PCC_H ++ ++#include <pcap.h> ++ ++int pcap_pre_compiled (char * fname, struct bpf_program *p); ++#endif /* PCAP_PCC_H */ |