diff options
Diffstat (limited to 'contrib/libpcap')
-rw-r--r-- | contrib/libpcap/FREEBSD-upgrade | 35 | ||||
-rw-r--r-- | contrib/libpcap/aclocal.m4 | 900 | ||||
-rw-r--r-- | contrib/libpcap/bpf/net/bpf.h | 419 | ||||
-rw-r--r-- | contrib/libpcap/gencode.c | 1165 | ||||
-rw-r--r-- | contrib/libpcap/gencode.h | 21 | ||||
-rw-r--r-- | contrib/libpcap/grammar.y | 91 | ||||
-rw-r--r-- | contrib/libpcap/nametoaddr.c | 19 | ||||
-rw-r--r-- | contrib/libpcap/nlpid.h | 1 | ||||
-rw-r--r-- | contrib/libpcap/packaging/pcap.spec | 65 | ||||
-rw-r--r-- | contrib/libpcap/pcap-bpf.c | 15 | ||||
-rw-r--r-- | contrib/libpcap/pcap-int.h | 48 | ||||
-rw-r--r-- | contrib/libpcap/pcap-namedb.h | 3 | ||||
-rw-r--r-- | contrib/libpcap/pcap.3 | 42 | ||||
-rw-r--r-- | contrib/libpcap/pcap.h | 37 | ||||
-rw-r--r-- | contrib/libpcap/rawss7.h | 105 | ||||
-rw-r--r-- | contrib/libpcap/scanner.l | 21 | ||||
-rw-r--r-- | contrib/libpcap/snprintf.c | 632 |
17 files changed, 512 insertions, 3107 deletions
diff --git a/contrib/libpcap/FREEBSD-upgrade b/contrib/libpcap/FREEBSD-upgrade new file mode 100644 index 0000000..eea75c2 --- /dev/null +++ b/contrib/libpcap/FREEBSD-upgrade @@ -0,0 +1,35 @@ +$FreeBSD$ + +This directory contains virgin copies of the original distribution files +on a "vendor" branch. Do not, under any circumstances, attempt to upgrade +the files in this directory via patches and a cvs commit. + +To upgrade to a newer version of libpcap, when it is available: + 1. Unpack the new version into an empty directory. + [Do not make ANY changes to the files.] + + 2. Use the command: + cvs import -m 'Import of libpcap v<version>' \ + -I SUNOS4 -I msdos -I Win32 -I missing \ + -I ChmodBPF -I linux-include \ + src/contrib/libpcap TCPDUMP_ORG v<version> + + For example, to do the import of version 0.9.4, I typed: + cvs import -m 'Import of libpcap v0.9.4 \ + -I SUNOS4 -I msdos -I Win32 -I missing \ + -I ChmodBPF -I linux-include \ + src/contrib/libpcap TCPDUMP_ORG v0_9_4 + + 3. Follow the instructions printed out in step 2 to resolve any + conflicts between local FreeBSD changes and the newer version. + 4. Bump __FreeBSD_version in sys/param.h as appropriate + +Do not, under any circumstances, deviate from this procedure. + +To make local changes to libpcap, simply patch and commit to the main +branch (aka HEAD). Never make local changes on the TCPDUMP_ORG branch. + +All local changes should be submitted to "tcpdump-workers@tcpdump.org" for +inclusion in the next vendor release of tcpdump and libpcap. + +sam@freebsd.org - 4 September 2006 diff --git a/contrib/libpcap/aclocal.m4 b/contrib/libpcap/aclocal.m4 deleted file mode 100644 index 1efb474..0000000 --- a/contrib/libpcap/aclocal.m4 +++ /dev/null @@ -1,900 +0,0 @@ -dnl @(#) $Header: /tcpdump/master/libpcap/aclocal.m4,v 1.85.2.1 2005/04/21 03:42:09 guy Exp $ (LBL) -dnl -dnl Copyright (c) 1995, 1996, 1997, 1998 -dnl The Regents of the University of California. All rights reserved. -dnl -dnl Redistribution and use in source and binary forms, with or without -dnl modification, are permitted provided that: (1) source code distributions -dnl retain the above copyright notice and this paragraph in its entirety, (2) -dnl distributions including binary code include the above copyright notice and -dnl this paragraph in its entirety in the documentation or other materials -dnl provided with the distribution, and (3) all advertising materials mentioning -dnl features or use of this software display the following acknowledgement: -dnl ``This product includes software developed by the University of California, -dnl Lawrence Berkeley Laboratory and its contributors.'' Neither the name of -dnl the University nor the names of its contributors may be used to endorse -dnl or promote products derived from this software without specific prior -dnl written permission. -dnl THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED -dnl WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF -dnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -dnl -dnl LBL autoconf macros -dnl - -dnl -dnl Determine which compiler we're using (cc or gcc) -dnl If using gcc, determine the version number -dnl If using cc, require that it support ansi prototypes -dnl If using gcc, use -O2 (otherwise use -O) -dnl If using cc, explicitly specify /usr/local/include -dnl -dnl usage: -dnl -dnl AC_LBL_C_INIT(copt, incls) -dnl -dnl results: -dnl -dnl $1 (copt set) -dnl $2 (incls set) -dnl CC -dnl LDFLAGS -dnl ac_cv_lbl_gcc_vers -dnl LBL_CFLAGS -dnl -AC_DEFUN(AC_LBL_C_INIT, - [AC_PREREQ(2.12) - AC_BEFORE([$0], [AC_PROG_CC]) - AC_BEFORE([$0], [AC_LBL_FIXINCLUDES]) - AC_BEFORE([$0], [AC_LBL_DEVEL]) - AC_ARG_WITH(gcc, [ --without-gcc don't use gcc]) - $1="-O" - $2="" - if test "${srcdir}" != "." ; then - $2="-I\$(srcdir)" - fi - if test "${CFLAGS+set}" = set; then - LBL_CFLAGS="$CFLAGS" - fi - if test -z "$CC" ; then - case "$target_os" in - - bsdi*) - AC_CHECK_PROG(SHLICC2, shlicc2, yes, no) - if test $SHLICC2 = yes ; then - CC=shlicc2 - export CC - fi - ;; - esac - fi - if test -z "$CC" -a "$with_gcc" = no ; then - CC=cc - export CC - fi - AC_PROG_CC - if test "$GCC" = yes ; then - if test "$SHLICC2" = yes ; then - ac_cv_lbl_gcc_vers=2 - $1="-O2" - else - AC_MSG_CHECKING(gcc version) - AC_CACHE_VAL(ac_cv_lbl_gcc_vers, - ac_cv_lbl_gcc_vers=`$CC -v 2>&1 | \ - sed -e '/^gcc version /!d' \ - -e 's/^gcc version //' \ - -e 's/ .*//' -e 's/^[[[^0-9]]]*//' \ - -e 's/\..*//'`) - AC_MSG_RESULT($ac_cv_lbl_gcc_vers) - if test $ac_cv_lbl_gcc_vers -gt 1 ; then - $1="-O2" - fi - fi - else - AC_MSG_CHECKING(that $CC handles ansi prototypes) - AC_CACHE_VAL(ac_cv_lbl_cc_ansi_prototypes, - AC_TRY_COMPILE( - [#include <sys/types.h>], - [int frob(int, char *)], - ac_cv_lbl_cc_ansi_prototypes=yes, - ac_cv_lbl_cc_ansi_prototypes=no)) - AC_MSG_RESULT($ac_cv_lbl_cc_ansi_prototypes) - if test $ac_cv_lbl_cc_ansi_prototypes = no ; then - case "$target_os" in - - hpux*) - AC_MSG_CHECKING(for HP-UX ansi compiler ($CC -Aa -D_HPUX_SOURCE)) - savedcflags="$CFLAGS" - CFLAGS="-Aa -D_HPUX_SOURCE $CFLAGS" - AC_CACHE_VAL(ac_cv_lbl_cc_hpux_cc_aa, - AC_TRY_COMPILE( - [#include <sys/types.h>], - [int frob(int, char *)], - ac_cv_lbl_cc_hpux_cc_aa=yes, - ac_cv_lbl_cc_hpux_cc_aa=no)) - AC_MSG_RESULT($ac_cv_lbl_cc_hpux_cc_aa) - if test $ac_cv_lbl_cc_hpux_cc_aa = no ; then - AC_MSG_ERROR(see the INSTALL doc for more info) - fi - CFLAGS="$savedcflags" - V_CCOPT="-Aa $V_CCOPT" - AC_DEFINE(_HPUX_SOURCE,1,[needed on HP-UX]) - ;; - - *) - AC_MSG_ERROR(see the INSTALL doc for more info) - ;; - esac - fi - $2="$$2 -I/usr/local/include" - LDFLAGS="$LDFLAGS -L/usr/local/lib" - - case "$target_os" in - - irix*) - V_CCOPT="$V_CCOPT -xansi -signed -g3" - ;; - - osf*) - V_CCOPT="$V_CCOPT -std1 -g3" - ;; - - ultrix*) - AC_MSG_CHECKING(that Ultrix $CC hacks const in prototypes) - AC_CACHE_VAL(ac_cv_lbl_cc_const_proto, - AC_TRY_COMPILE( - [#include <sys/types.h>], - [struct a { int b; }; - void c(const struct a *)], - ac_cv_lbl_cc_const_proto=yes, - ac_cv_lbl_cc_const_proto=no)) - AC_MSG_RESULT($ac_cv_lbl_cc_const_proto) - if test $ac_cv_lbl_cc_const_proto = no ; then - AC_DEFINE(const,) - fi - ;; - esac - fi -]) - -# -# Try compiling a sample of the type of code that appears in -# gencode.c with "inline", "__inline__", and "__inline". -# -# Autoconf's AC_C_INLINE, at least in autoconf 2.13, isn't good enough, -# as it just tests whether a function returning "int" can be inlined; -# at least some versions of HP's C compiler can inline that, but can't -# inline a function that returns a struct pointer. -# -# Make sure we use the V_CCOPT flags, because some of those might -# disable inlining. -# -AC_DEFUN(AC_LBL_C_INLINE, - [AC_MSG_CHECKING(for inline) - save_CFLAGS="$CFLAGS" - CFLAGS="$V_CCOPT" - AC_CACHE_VAL(ac_cv_lbl_inline, [ - ac_cv_lbl_inline="" - ac_lbl_cc_inline=no - for ac_lbl_inline in inline __inline__ __inline - do - AC_TRY_COMPILE( - [#define inline $ac_lbl_inline - static inline struct iltest *foo(void); - struct iltest { - int iltest1; - int iltest2; - }; - - static inline struct iltest * - foo() - { - static struct iltest xxx; - - return &xxx; - }],,ac_lbl_cc_inline=yes,) - if test "$ac_lbl_cc_inline" = yes ; then - break; - fi - done - if test "$ac_lbl_cc_inline" = yes ; then - ac_cv_lbl_inline=$ac_lbl_inline - fi]) - CFLAGS="$save_CFLAGS" - if test ! -z "$ac_cv_lbl_inline" ; then - AC_MSG_RESULT($ac_cv_lbl_inline) - else - AC_MSG_RESULT(no) - fi - AC_DEFINE_UNQUOTED(inline, $ac_cv_lbl_inline, [Define as token for inline if inlining supported])]) - -dnl -dnl Use pfopen.c if available and pfopen() not in standard libraries -dnl Require libpcap -dnl Look for libpcap in .. -dnl Use the installed libpcap if there is no local version -dnl -dnl usage: -dnl -dnl AC_LBL_LIBPCAP(pcapdep, incls) -dnl -dnl results: -dnl -dnl $1 (pcapdep set) -dnl $2 (incls appended) -dnl LIBS -dnl LBL_LIBS -dnl -AC_DEFUN(AC_LBL_LIBPCAP, - [AC_REQUIRE([AC_LBL_LIBRARY_NET]) - dnl - dnl save a copy before locating libpcap.a - dnl - LBL_LIBS="$LIBS" - pfopen=/usr/examples/packetfilter/pfopen.c - if test -f $pfopen ; then - AC_CHECK_FUNCS(pfopen) - if test $ac_cv_func_pfopen = "no" ; then - AC_MSG_RESULT(Using $pfopen) - LIBS="$LIBS $pfopen" - fi - fi - AC_MSG_CHECKING(for local pcap library) - libpcap=FAIL - lastdir=FAIL - places=`ls .. | sed -e 's,/$,,' -e 's,^,../,' | \ - egrep '/libpcap-[[0-9]]*\.[[0-9]]*(\.[[0-9]]*)?([[ab]][[0-9]]*)?$'` - for dir in $places ../libpcap libpcap ; do - basedir=`echo $dir | sed -e 's/[[ab]][[0-9]]*$//'` - if test $lastdir = $basedir ; then - dnl skip alphas when an actual release is present - continue; - fi - lastdir=$dir - if test -r $dir/pcap.c ; then - libpcap=$dir/libpcap.a - d=$dir - dnl continue and select the last one that exists - fi - done - if test $libpcap = FAIL ; then - AC_MSG_RESULT(not found) - AC_CHECK_LIB(pcap, main, libpcap="-lpcap") - if test $libpcap = FAIL ; then - AC_MSG_ERROR(see the INSTALL doc for more info) - fi - else - $1=$libpcap - $2="-I$d $$2" - AC_MSG_RESULT($libpcap) - fi - LIBS="$libpcap $LIBS" - case "$target_os" in - - aix*) - pseexe="/lib/pse.exp" - AC_MSG_CHECKING(for $pseexe) - if test -f $pseexe ; then - AC_MSG_RESULT(yes) - LIBS="$LIBS -I:$pseexe" - fi - ;; - esac]) - -dnl -dnl Define RETSIGTYPE and RETSIGVAL -dnl -dnl usage: -dnl -dnl AC_LBL_TYPE_SIGNAL -dnl -dnl results: -dnl -dnl RETSIGTYPE (defined) -dnl RETSIGVAL (defined) -dnl -AC_DEFUN(AC_LBL_TYPE_SIGNAL, - [AC_BEFORE([$0], [AC_LBL_LIBPCAP]) - AC_TYPE_SIGNAL - if test "$ac_cv_type_signal" = void ; then - AC_DEFINE(RETSIGVAL,[],[return value of signal handlers]) - else - AC_DEFINE(RETSIGVAL,(0),[return value of signal handlers]) - fi - case "$target_os" in - - irix*) - AC_DEFINE(_BSD_SIGNALS,1,[get BSD semantics on Irix]) - ;; - - *) - dnl prefer sigset() to sigaction() - AC_CHECK_FUNCS(sigset) - if test $ac_cv_func_sigset = no ; then - AC_CHECK_FUNCS(sigaction) - fi - ;; - esac]) - -dnl -dnl If using gcc, make sure we have ANSI ioctl definitions -dnl -dnl usage: -dnl -dnl AC_LBL_FIXINCLUDES -dnl -AC_DEFUN(AC_LBL_FIXINCLUDES, - [if test "$GCC" = yes ; then - AC_MSG_CHECKING(for ANSI ioctl definitions) - AC_CACHE_VAL(ac_cv_lbl_gcc_fixincludes, - AC_TRY_COMPILE( - [/* - * This generates a "duplicate case value" when fixincludes - * has not be run. - */ -# include <sys/types.h> -# include <sys/time.h> -# include <sys/ioctl.h> -# ifdef HAVE_SYS_IOCCOM_H -# include <sys/ioccom.h> -# endif], - [switch (0) { - case _IO('A', 1):; - case _IO('B', 1):; - }], - ac_cv_lbl_gcc_fixincludes=yes, - ac_cv_lbl_gcc_fixincludes=no)) - AC_MSG_RESULT($ac_cv_lbl_gcc_fixincludes) - if test $ac_cv_lbl_gcc_fixincludes = no ; then - # Don't cache failure - unset ac_cv_lbl_gcc_fixincludes - AC_MSG_ERROR(see the INSTALL for more info) - fi - fi]) - -dnl -dnl Check for flex, default to lex -dnl Require flex 2.4 or higher -dnl Check for bison, default to yacc -dnl Default to lex/yacc if both flex and bison are not available -dnl Define the yy prefix string if using flex and bison -dnl -dnl usage: -dnl -dnl AC_LBL_LEX_AND_YACC(lex, yacc, yyprefix) -dnl -dnl results: -dnl -dnl $1 (lex set) -dnl $2 (yacc appended) -dnl $3 (optional flex and bison -P prefix) -dnl -AC_DEFUN(AC_LBL_LEX_AND_YACC, - [AC_ARG_WITH(flex, [ --without-flex don't use flex]) - AC_ARG_WITH(bison, [ --without-bison don't use bison]) - if test "$with_flex" = no ; then - $1=lex - else - AC_CHECK_PROGS($1, flex, lex) - fi - if test "$$1" = flex ; then - # The -V flag was added in 2.4 - AC_MSG_CHECKING(for flex 2.4 or higher) - AC_CACHE_VAL(ac_cv_lbl_flex_v24, - if flex -V >/dev/null 2>&1; then - ac_cv_lbl_flex_v24=yes - else - ac_cv_lbl_flex_v24=no - fi) - AC_MSG_RESULT($ac_cv_lbl_flex_v24) - if test $ac_cv_lbl_flex_v24 = no ; then - s="2.4 or higher required" - AC_MSG_WARN(ignoring obsolete flex executable ($s)) - $1=lex - fi - fi - if test "$with_bison" = no ; then - $2=yacc - else - AC_CHECK_PROGS($2, bison, yacc) - fi - if test "$$2" = bison ; then - $2="$$2 -y" - fi - if test "$$1" != lex -a "$$2" = yacc -o "$$1" = lex -a "$$2" != yacc ; then - AC_MSG_WARN(don't have both flex and bison; reverting to lex/yacc) - $1=lex - $2=yacc - fi - if test "$$1" = flex -a -n "$3" ; then - $1="$$1 -P$3" - $2="$$2 -p $3" - fi]) - -dnl -dnl Checks to see if union wait is used with WEXITSTATUS() -dnl -dnl usage: -dnl -dnl AC_LBL_UNION_WAIT -dnl -dnl results: -dnl -dnl DECLWAITSTATUS (defined) -dnl -AC_DEFUN(AC_LBL_UNION_WAIT, - [AC_MSG_CHECKING(if union wait is used) - AC_CACHE_VAL(ac_cv_lbl_union_wait, - AC_TRY_COMPILE([ -# include <sys/types.h> -# include <sys/wait.h>], - [int status; - u_int i = WEXITSTATUS(status); - u_int j = waitpid(0, &status, 0);], - ac_cv_lbl_union_wait=no, - ac_cv_lbl_union_wait=yes)) - AC_MSG_RESULT($ac_cv_lbl_union_wait) - if test $ac_cv_lbl_union_wait = yes ; then - AC_DEFINE(DECLWAITSTATUS,union wait,[type for wait]) - else - AC_DEFINE(DECLWAITSTATUS,int,[type for wait]) - fi]) - -dnl -dnl Checks to see if the sockaddr struct has the 4.4 BSD sa_len member -dnl -dnl usage: -dnl -dnl AC_LBL_SOCKADDR_SA_LEN -dnl -dnl results: -dnl -dnl HAVE_SOCKADDR_SA_LEN (defined) -dnl -AC_DEFUN(AC_LBL_SOCKADDR_SA_LEN, - [AC_MSG_CHECKING(if sockaddr struct has sa_len member) - AC_CACHE_VAL(ac_cv_lbl_sockaddr_has_sa_len, - AC_TRY_COMPILE([ -# include <sys/types.h> -# include <sys/socket.h>], - [u_int i = sizeof(((struct sockaddr *)0)->sa_len)], - ac_cv_lbl_sockaddr_has_sa_len=yes, - ac_cv_lbl_sockaddr_has_sa_len=no)) - AC_MSG_RESULT($ac_cv_lbl_sockaddr_has_sa_len) - if test $ac_cv_lbl_sockaddr_has_sa_len = yes ; then - AC_DEFINE(HAVE_SOCKADDR_SA_LEN,1,[if struct sockaddr has sa_len]) - fi]) - -dnl -dnl Checks to see if there's a sockaddr_storage structure -dnl -dnl usage: -dnl -dnl AC_LBL_SOCKADDR_STORAGE -dnl -dnl results: -dnl -dnl HAVE_SOCKADDR_STORAGE (defined) -dnl -AC_DEFUN(AC_LBL_SOCKADDR_STORAGE, - [AC_MSG_CHECKING(if sockaddr_storage struct exists) - AC_CACHE_VAL(ac_cv_lbl_has_sockaddr_storage, - AC_TRY_COMPILE([ -# include <sys/types.h> -# include <sys/socket.h>], - [u_int i = sizeof (struct sockaddr_storage)], - ac_cv_lbl_has_sockaddr_storage=yes, - ac_cv_lbl_has_sockaddr_storage=no)) - AC_MSG_RESULT($ac_cv_lbl_has_sockaddr_storage) - if test $ac_cv_lbl_has_sockaddr_storage = yes ; then - AC_DEFINE(HAVE_SOCKADDR_STORAGE,1,[if struct sockaddr_storage exists]) - fi]) - -dnl -dnl Checks to see if the dl_hp_ppa_info_t struct has the HP-UX 11.00 -dnl dl_module_id_1 member -dnl -dnl usage: -dnl -dnl AC_LBL_HP_PPA_INFO_T_DL_MODULE_ID_1 -dnl -dnl results: -dnl -dnl HAVE_HP_PPA_INFO_T_DL_MODULE_ID_1 (defined) -dnl -dnl NOTE: any compile failure means we conclude that it doesn't have -dnl that member, so if we don't have DLPI, don't have a <sys/dlpi_ext.h> -dnl header, or have one that doesn't declare a dl_hp_ppa_info_t type, -dnl we conclude it doesn't have that member (which is OK, as either we -dnl won't be using code that would use that member, or we wouldn't -dnl compile in any case). -dnl -AC_DEFUN(AC_LBL_HP_PPA_INFO_T_DL_MODULE_ID_1, - [AC_MSG_CHECKING(if dl_hp_ppa_info_t struct has dl_module_id_1 member) - AC_CACHE_VAL(ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1, - AC_TRY_COMPILE([ -# include <sys/types.h> -# include <sys/dlpi.h> -# include <sys/dlpi_ext.h>], - [u_int i = sizeof(((dl_hp_ppa_info_t *)0)->dl_module_id_1)], - ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1=yes, - ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1=no)) - AC_MSG_RESULT($ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1) - if test $ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1 = yes ; then - AC_DEFINE(HAVE_HP_PPA_INFO_T_DL_MODULE_ID_1,1,[if ppa_info_t_dl_module_id exists]) - fi]) - -dnl -dnl Checks to see if -R is used -dnl -dnl usage: -dnl -dnl AC_LBL_HAVE_RUN_PATH -dnl -dnl results: -dnl -dnl ac_cv_lbl_have_run_path (yes or no) -dnl -AC_DEFUN(AC_LBL_HAVE_RUN_PATH, - [AC_MSG_CHECKING(for ${CC-cc} -R) - AC_CACHE_VAL(ac_cv_lbl_have_run_path, - [echo 'main(){}' > conftest.c - ${CC-cc} -o conftest conftest.c -R/a1/b2/c3 >conftest.out 2>&1 - if test ! -s conftest.out ; then - ac_cv_lbl_have_run_path=yes - else - ac_cv_lbl_have_run_path=no - fi - rm -f conftest*]) - AC_MSG_RESULT($ac_cv_lbl_have_run_path) - ]) - -dnl -dnl Due to the stupid way it's implemented, AC_CHECK_TYPE is nearly useless. -dnl -dnl usage: -dnl -dnl AC_LBL_CHECK_TYPE -dnl -dnl results: -dnl -dnl int32_t (defined) -dnl u_int32_t (defined) -dnl -AC_DEFUN(AC_LBL_CHECK_TYPE, - [AC_MSG_CHECKING(for $1 using $CC) - AC_CACHE_VAL(ac_cv_lbl_have_$1, - AC_TRY_COMPILE([ -# include "confdefs.h" -# include <sys/types.h> -# if STDC_HEADERS -# include <stdlib.h> -# include <stddef.h> -# endif], - [$1 i], - ac_cv_lbl_have_$1=yes, - ac_cv_lbl_have_$1=no)) - AC_MSG_RESULT($ac_cv_lbl_have_$1) - if test $ac_cv_lbl_have_$1 = no ; then - AC_DEFINE($1, $2, [if we have $1]) - fi]) - -dnl -dnl Checks to see if unaligned memory accesses fail -dnl -dnl usage: -dnl -dnl AC_LBL_UNALIGNED_ACCESS -dnl -dnl results: -dnl -dnl LBL_ALIGN (DEFINED) -dnl -AC_DEFUN(AC_LBL_UNALIGNED_ACCESS, - [AC_MSG_CHECKING(if unaligned accesses fail) - AC_CACHE_VAL(ac_cv_lbl_unaligned_fail, - [case "$host_cpu" in - - # - # These are CPU types where: - # - # the CPU faults on an unaligned access, but at least some - # OSes that support that CPU catch the fault and simulate - # the unaligned access (e.g., Alpha/{Digital,Tru64} UNIX) - - # the simulation is slow, so we don't want to use it; - # - # the CPU, I infer (from the old - # - # XXX: should also check that they don't do weird things (like on arm) - # - # comment) doesn't fault on unaligned accesses, but doesn't - # do a normal unaligned fetch, either (e.g., presumably, ARM); - # - # for whatever reason, the test program doesn't work - # (this has been claimed to be the case for several of those - # CPUs - I don't know what the problem is; the problem - # was reported as "the test program dumps core" for SuperH, - # but that's what the test program is *supposed* to do - - # it dumps core before it writes anything, so the test - # for an empty output file should find an empty output - # file and conclude that unaligned accesses don't work). - # - # This run-time test won't work if you're cross-compiling, so - # in order to support cross-compiling for a particular CPU, - # we have to wire in the list of CPU types anyway, as far as - # I know, so perhaps we should just have a set of CPUs on - # which we know it doesn't work, a set of CPUs on which we - # know it does work, and have the script just fail on other - # cpu types and update it when such a failure occurs. - # - alpha*|arm*|hp*|mips*|sh*|sparc*|ia64|nv1) - ac_cv_lbl_unaligned_fail=yes - ;; - - *) - cat >conftest.c <<EOF -# include <sys/types.h> -# include <sys/wait.h> -# include <stdio.h> - unsigned char a[[5]] = { 1, 2, 3, 4, 5 }; - main() { - unsigned int i; - pid_t pid; - int status; - /* avoid "core dumped" message */ - pid = fork(); - if (pid < 0) - exit(2); - if (pid > 0) { - /* parent */ - pid = waitpid(pid, &status, 0); - if (pid < 0) - exit(3); - exit(!WIFEXITED(status)); - } - /* child */ - i = *(unsigned int *)&a[[1]]; - printf("%d\n", i); - exit(0); - } -EOF - ${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS \ - conftest.c $LIBS >/dev/null 2>&1 - if test ! -x conftest ; then - dnl failed to compile for some reason - ac_cv_lbl_unaligned_fail=yes - else - ./conftest >conftest.out - if test ! -s conftest.out ; then - ac_cv_lbl_unaligned_fail=yes - else - ac_cv_lbl_unaligned_fail=no - fi - fi - rm -f conftest* core core.conftest - ;; - esac]) - AC_MSG_RESULT($ac_cv_lbl_unaligned_fail) - if test $ac_cv_lbl_unaligned_fail = yes ; then - AC_DEFINE(LBL_ALIGN,1,[if unaligned access fails]) - fi]) - -dnl -dnl If using gcc and the file .devel exists: -dnl Compile with -g (if supported) and -Wall -dnl If using gcc 2, do extra prototype checking -dnl If an os prototype include exists, symlink os-proto.h to it -dnl -dnl usage: -dnl -dnl AC_LBL_DEVEL(copt) -dnl -dnl results: -dnl -dnl $1 (copt appended) -dnl HAVE_OS_PROTO_H (defined) -dnl os-proto.h (symlinked) -dnl -AC_DEFUN(AC_LBL_DEVEL, - [rm -f os-proto.h - if test "${LBL_CFLAGS+set}" = set; then - $1="$$1 ${LBL_CFLAGS}" - fi - if test -f .devel ; then - if test "$GCC" = yes ; then - if test "${LBL_CFLAGS+set}" != set; then - if test "$ac_cv_prog_cc_g" = yes ; then - $1="-g $$1" - fi - $1="$$1 -Wall" - if test $ac_cv_lbl_gcc_vers -gt 1 ; then - $1="$$1 -Wmissing-prototypes -Wstrict-prototypes" - fi - fi - else - case "$target_os" in - - irix6*) - V_CCOPT="$V_CCOPT -n32" - ;; - - *) - ;; - esac - fi - os=`echo $target_os | sed -e 's/\([[0-9]][[0-9]]*\)[[^0-9]].*$/\1/'` - name="lbl/os-$os.h" - if test -f $name ; then - ln -s $name os-proto.h - AC_DEFINE(HAVE_OS_PROTO_H,1,[if there's an os_proto.h]) - else - AC_MSG_WARN(can't find $name) - fi - fi]) - -dnl -dnl Improved version of AC_CHECK_LIB -dnl -dnl Thanks to John Hawkinson (jhawk@mit.edu) -dnl -dnl usage: -dnl -dnl AC_LBL_CHECK_LIB(LIBRARY, FUNCTION [, ACTION-IF-FOUND [, -dnl ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]]) -dnl -dnl results: -dnl -dnl LIBS -dnl - -define(AC_LBL_CHECK_LIB, -[AC_MSG_CHECKING([for $2 in -l$1]) -dnl Use a cache variable name containing both the library and function name, -dnl because the test really is for library $1 defining function $2, not -dnl just for library $1. Separate tests with the same $1 and different $2's -dnl may have different results. -ac_lib_var=`echo $1['_']$2['_']$5 | sed 'y%./+- %__p__%'` -AC_CACHE_VAL(ac_cv_lbl_lib_$ac_lib_var, -[ac_save_LIBS="$LIBS" -LIBS="-l$1 $5 $LIBS" -AC_TRY_LINK(dnl -ifelse([$2], [main], , dnl Avoid conflicting decl of main. -[/* Override any gcc2 internal prototype to avoid an error. */ -]ifelse(AC_LANG, CPLUSPLUS, [#ifdef __cplusplus -extern "C" -#endif -])dnl -[/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $2(); -]), - [$2()], - eval "ac_cv_lbl_lib_$ac_lib_var=yes", - eval "ac_cv_lbl_lib_$ac_lib_var=no") -LIBS="$ac_save_LIBS" -])dnl -if eval "test \"`echo '$ac_cv_lbl_lib_'$ac_lib_var`\" = yes"; then - AC_MSG_RESULT(yes) - ifelse([$3], , -[changequote(, )dnl - ac_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \ - -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` -changequote([, ])dnl - AC_DEFINE_UNQUOTED($ac_tr_lib) - LIBS="-l$1 $LIBS" -], [$3]) -else - AC_MSG_RESULT(no) -ifelse([$4], , , [$4 -])dnl -fi -]) - -dnl -dnl AC_LBL_LIBRARY_NET -dnl -dnl This test is for network applications that need socket() and -dnl gethostbyname() -ish functions. Under Solaris, those applications -dnl need to link with "-lsocket -lnsl". Under IRIX, they need to link -dnl with "-lnsl" but should *not* link with "-lsocket" because -dnl libsocket.a breaks a number of things (for instance: -dnl gethostbyname() under IRIX 5.2, and snoop sockets under most -dnl versions of IRIX). -dnl -dnl Unfortunately, many application developers are not aware of this, -dnl and mistakenly write tests that cause -lsocket to be used under -dnl IRIX. It is also easy to write tests that cause -lnsl to be used -dnl under operating systems where neither are necessary (or useful), -dnl such as SunOS 4.1.4, which uses -lnsl for TLI. -dnl -dnl This test exists so that every application developer does not test -dnl this in a different, and subtly broken fashion. - -dnl It has been argued that this test should be broken up into two -dnl seperate tests, one for the resolver libraries, and one for the -dnl libraries necessary for using Sockets API. Unfortunately, the two -dnl are carefully intertwined and allowing the autoconf user to use -dnl them independantly potentially results in unfortunate ordering -dnl dependancies -- as such, such component macros would have to -dnl carefully use indirection and be aware if the other components were -dnl executed. Since other autoconf macros do not go to this trouble, -dnl and almost no applications use sockets without the resolver, this -dnl complexity has not been implemented. -dnl -dnl The check for libresolv is in case you are attempting to link -dnl statically and happen to have a libresolv.a lying around (and no -dnl libnsl.a). -dnl -AC_DEFUN(AC_LBL_LIBRARY_NET, [ - # Most operating systems have gethostbyname() in the default searched - # libraries (i.e. libc): - # Some OSes (eg. Solaris) place it in libnsl - # Some strange OSes (SINIX) have it in libsocket: - AC_SEARCH_LIBS(gethostbyname, nsl socket resolv) - # Unfortunately libsocket sometimes depends on libnsl and - # AC_SEARCH_LIBS isn't up to the task of handling dependencies like this. - if test "$ac_cv_search_gethostbyname" = "no" - then - AC_CHECK_LIB(socket, gethostbyname, - LIBS="-lsocket -lnsl $LIBS", , -lnsl) - fi - AC_SEARCH_LIBS(socket, socket, , - AC_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", , -lnsl)) - # DLPI needs putmsg under HPUX so test for -lstr while we're at it - AC_SEARCH_LIBS(putmsg, str) - ]) - -dnl -dnl Test for __attribute__ -dnl - -AC_DEFUN(AC_C___ATTRIBUTE__, [ -AC_MSG_CHECKING(for __attribute__) -AC_CACHE_VAL(ac_cv___attribute__, [ -AC_COMPILE_IFELSE( - AC_LANG_SOURCE([[ -#include <stdlib.h> - -static void foo(void) __attribute__ ((noreturn)); - -static void -foo(void) -{ - exit(1); -} - -int -main(int argc, char **argv) -{ - foo(); -} - ]]), -ac_cv___attribute__=yes, -ac_cv___attribute__=no)]) -if test "$ac_cv___attribute__" = "yes"; then - AC_DEFINE(HAVE___ATTRIBUTE__, 1, [define if your compiler has __attribute__]) - V_DEFS="$V_DEFS -D_U_=\"__attribute__((unused))\"" -else - V_DEFS="$V_DEFS -D_U_=\"\"" -fi -AC_MSG_RESULT($ac_cv___attribute__) -]) - -dnl -dnl Checks to see if tpacket_stats is defined in linux/if_packet.h -dnl If so then pcap-linux.c can use this to report proper statistics. -dnl -dnl -Scott Barron -dnl -AC_DEFUN(AC_LBL_TPACKET_STATS, - [AC_MSG_CHECKING(if if_packet.h has tpacket_stats defined) - AC_CACHE_VAL(ac_cv_lbl_tpacket_stats, - AC_TRY_COMPILE([ -# include <linux/if_packet.h>], - [struct tpacket_stats stats], - ac_cv_lbl_tpacket_stats=yes, - ac_cv_lbl_tpacket_stats=no)) - AC_MSG_RESULT($ac_cv_lbl_tpacket_stats) - if test $ac_cv_lbl_tpacket_stats = yes; then - AC_DEFINE(HAVE_TPACKET_STATS,1,[if if_packet.h has tpacket_stats defined]) - fi]) diff --git a/contrib/libpcap/bpf/net/bpf.h b/contrib/libpcap/bpf/net/bpf.h deleted file mode 100644 index 8c73f3a..0000000 --- a/contrib/libpcap/bpf/net/bpf.h +++ /dev/null @@ -1,419 +0,0 @@ -/*- - * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from the Stanford/CMU enet packet filter, - * (net/enet.c) distributed as part of 4.3BSD, and code contributed - * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence - * Berkeley Laboratory. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)bpf.h 7.1 (Berkeley) 5/7/91 - * - * @(#) $Header: /tcpdump/master/libpcap/bpf/net/bpf.h,v 1.51 2001/11/28 05:50:05 guy Exp $ (LBL) - */ - -#ifndef BPF_MAJOR_VERSION - -/* BSD style release date */ -#define BPF_RELEASE 199606 - -typedef int bpf_int32; -typedef u_int bpf_u_int32; - -/* - * Alignment macros. BPF_WORDALIGN rounds up to the next - * even multiple of BPF_ALIGNMENT. - */ -#ifndef __NetBSD__ -#define BPF_ALIGNMENT sizeof(bpf_int32) -#else -#define BPF_ALIGNMENT sizeof(long) -#endif -#define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1)) - -#define BPF_MAXINSNS 512 -#define BPF_MAXBUFSIZE 0x8000 -#define BPF_MINBUFSIZE 32 - -/* - * Structure for BIOCSETF. - */ -struct bpf_program { - u_int bf_len; - struct bpf_insn *bf_insns; -}; - -/* - * Struct returned by BIOCGSTATS. - */ -struct bpf_stat { - u_int bs_recv; /* number of packets received */ - u_int bs_drop; /* number of packets dropped */ -}; - -/* - * Struct return by BIOCVERSION. This represents the version number of - * the filter language described by the instruction encodings below. - * bpf understands a program iff kernel_major == filter_major && - * kernel_minor >= filter_minor, that is, if the value returned by the - * running kernel has the same major number and a minor number equal - * equal to or less than the filter being downloaded. Otherwise, the - * results are undefined, meaning an error may be returned or packets - * may be accepted haphazardly. - * It has nothing to do with the source code version. - */ -struct bpf_version { - u_short bv_major; - u_short bv_minor; -}; -/* Current version number of filter architecture. */ -#define BPF_MAJOR_VERSION 1 -#define BPF_MINOR_VERSION 1 - -/* - * BPF ioctls - * - * The first set is for compatibility with Sun's pcc style - * header files. If your using gcc, we assume that you - * have run fixincludes so the latter set should work. - */ -#if (defined(sun) || defined(ibm032)) && !defined(__GNUC__) -#define BIOCGBLEN _IOR(B,102, u_int) -#define BIOCSBLEN _IOWR(B,102, u_int) -#define BIOCSETF _IOW(B,103, struct bpf_program) -#define BIOCFLUSH _IO(B,104) -#define BIOCPROMISC _IO(B,105) -#define BIOCGDLT _IOR(B,106, u_int) -#define BIOCGETIF _IOR(B,107, struct ifreq) -#define BIOCSETIF _IOW(B,108, struct ifreq) -#define BIOCSRTIMEOUT _IOW(B,109, struct timeval) -#define BIOCGRTIMEOUT _IOR(B,110, struct timeval) -#define BIOCGSTATS _IOR(B,111, struct bpf_stat) -#define BIOCIMMEDIATE _IOW(B,112, u_int) -#define BIOCVERSION _IOR(B,113, struct bpf_version) -#define BIOCSTCPF _IOW(B,114, struct bpf_program) -#define BIOCSUDPF _IOW(B,115, struct bpf_program) -#else -#define BIOCGBLEN _IOR('B',102, u_int) -#define BIOCSBLEN _IOWR('B',102, u_int) -#define BIOCSETF _IOW('B',103, struct bpf_program) -#define BIOCFLUSH _IO('B',104) -#define BIOCPROMISC _IO('B',105) -#define BIOCGDLT _IOR('B',106, u_int) -#define BIOCGETIF _IOR('B',107, struct ifreq) -#define BIOCSETIF _IOW('B',108, struct ifreq) -#define BIOCSRTIMEOUT _IOW('B',109, struct timeval) -#define BIOCGRTIMEOUT _IOR('B',110, struct timeval) -#define BIOCGSTATS _IOR('B',111, struct bpf_stat) -#define BIOCIMMEDIATE _IOW('B',112, u_int) -#define BIOCVERSION _IOR('B',113, struct bpf_version) -#define BIOCSTCPF _IOW('B',114, struct bpf_program) -#define BIOCSUDPF _IOW('B',115, struct bpf_program) -#endif - -/* - * Structure prepended to each packet. - */ -struct bpf_hdr { - struct timeval bh_tstamp; /* time stamp */ - bpf_u_int32 bh_caplen; /* length of captured portion */ - bpf_u_int32 bh_datalen; /* original length of packet */ - u_short bh_hdrlen; /* length of bpf header (this struct - plus alignment padding) */ -}; -/* - * Because the structure above is not a multiple of 4 bytes, some compilers - * will insist on inserting padding; hence, sizeof(struct bpf_hdr) won't work. - * Only the kernel needs to know about it; applications use bh_hdrlen. - */ -#if defined(KERNEL) || defined(_KERNEL) -#define SIZEOF_BPF_HDR 18 -#endif - -/* - * Data-link level type codes. - */ - -/* - * These are the types that are the same on all platforms; on other - * platforms, a <net/bpf.h> should be supplied that defines the additional - * DLT_* codes appropriately for that platform (the BSDs, for example, - * should not just pick up this version of "bpf.h"; they should also define - * the additional DLT_* codes used by their kernels, as well as the values - * defined here - and, if the values they use for particular DLT_ types - * differ from those here, they should use their values, not the ones - * here). - */ -#define DLT_NULL 0 /* no link-layer encapsulation */ -#define DLT_EN10MB 1 /* Ethernet (10Mb) */ -#define DLT_EN3MB 2 /* Experimental Ethernet (3Mb) */ -#define DLT_AX25 3 /* Amateur Radio AX.25 */ -#define DLT_PRONET 4 /* Proteon ProNET Token Ring */ -#define DLT_CHAOS 5 /* Chaos */ -#define DLT_IEEE802 6 /* IEEE 802 Networks */ -#define DLT_ARCNET 7 /* ARCNET */ -#define DLT_SLIP 8 /* Serial Line IP */ -#define DLT_PPP 9 /* Point-to-point Protocol */ -#define DLT_FDDI 10 /* FDDI */ - -/* - * These are values from the traditional libpcap "bpf.h". - * Ports of this to particular platforms should replace these definitions - * with the ones appropriate to that platform, if the values are - * different on that platform. - */ -#define DLT_ATM_RFC1483 11 /* LLC/SNAP encapsulated atm */ -#define DLT_RAW 12 /* raw IP */ - -/* - * These are values from BSD/OS's "bpf.h". - * These are not the same as the values from the traditional libpcap - * "bpf.h"; however, these values shouldn't be generated by any - * OS other than BSD/OS, so the correct values to use here are the - * BSD/OS values. - * - * Platforms that have already assigned these values to other - * DLT_ codes, however, should give these codes the values - * from that platform, so that programs that use these codes will - * continue to compile - even though they won't correctly read - * files of these types. - */ -#define DLT_SLIP_BSDOS 15 /* BSD/OS Serial Line IP */ -#define DLT_PPP_BSDOS 16 /* BSD/OS Point-to-point Protocol */ - -#define DLT_ATM_CLIP 19 /* Linux Classical-IP over ATM */ - -/* - * These values are defined by NetBSD; other platforms should refrain from - * using them for other purposes, so that NetBSD savefiles with link - * types of 50 or 51 can be read as this type on all platforms. - */ -#define DLT_PPP_SERIAL 50 /* PPP over serial with HDLC encapsulation */ -#define DLT_PPP_ETHER 51 /* PPP over Ethernet */ - -/* - * Values between 100 and 103 are used in capture file headers as - * link-layer types corresponding to DLT_ types that differ - * between platforms; don't use those values for new DLT_ new types. - */ - -/* - * This value was defined by libpcap 0.5; platforms that have defined - * it with a different value should define it here with that value - - * a link type of 104 in a save file will be mapped to DLT_C_HDLC, - * whatever value that happens to be, so programs will correctly - * handle files with that link type regardless of the value of - * DLT_C_HDLC. - * - * The name DLT_C_HDLC was used by BSD/OS; we use that name for source - * compatibility with programs written for BSD/OS. - * - * libpcap 0.5 defined it as DLT_CHDLC; we define DLT_CHDLC as well, - * for source compatibility with programs written for libpcap 0.5. - */ -#define DLT_C_HDLC 104 /* Cisco HDLC */ -#define DLT_CHDLC DLT_C_HDLC - -#define DLT_IEEE802_11 105 /* IEEE 802.11 wireless */ - -/* - * Values between 106 and 107 are used in capture file headers as - * link-layer types corresponding to DLT_ types that might differ - * between platforms; don't use those values for new DLT_ new types. - */ - -/* - * OpenBSD DLT_LOOP, for loopback devices; it's like DLT_NULL, except - * that the AF_ type in the link-layer header is in network byte order. - * - * OpenBSD defines it as 12, but that collides with DLT_RAW, so we - * define it as 108 here. If OpenBSD picks up this file, it should - * define DLT_LOOP as 12 in its version, as per the comment above - - * and should not use 108 as a DLT_ value. - */ -#define DLT_LOOP 108 - -/* - * Values between 109 and 112 are used in capture file headers as - * link-layer types corresponding to DLT_ types that might differ - * between platforms; don't use those values for new DLT_ types - * other than the corresponding DLT_ types. - */ - -/* - * This is for Linux cooked sockets. - */ -#define DLT_LINUX_SLL 113 - -/* - * Apple LocalTalk hardware. - */ -#define DLT_LTALK 114 - -/* - * Acorn Econet. - */ -#define DLT_ECONET 115 - -/* - * Reserved for use with OpenBSD ipfilter. - */ -#define DLT_IPFILTER 116 - -/* - * Reserved for use in capture-file headers as a link-layer type - * corresponding to OpenBSD DLT_PFLOG; DLT_PFLOG is 17 in OpenBSD, - * but that's DLT_LANE8023 in SuSE 6.3, so we can't use 17 for it - * in capture-file headers. - */ -#define DLT_PFLOG 117 - -/* - * Registered for Cisco-internal use. - */ -#define DLT_CISCO_IOS 118 - -/* - * Reserved for 802.11 cards using the Prism II chips, with a link-layer - * header including Prism monitor mode information plus an 802.11 - * header. - */ -#define DLT_PRISM_HEADER 119 - -/* - * Reserved for Aironet 802.11 cards, with an Aironet link-layer header - * (see Doug Ambrisko's FreeBSD patches). - */ -#define DLT_AIRONET_HEADER 120 - -/* - * The instruction encodings. - */ -/* instruction classes */ -#define BPF_CLASS(code) ((code) & 0x07) -#define BPF_LD 0x00 -#define BPF_LDX 0x01 -#define BPF_ST 0x02 -#define BPF_STX 0x03 -#define BPF_ALU 0x04 -#define BPF_JMP 0x05 -#define BPF_RET 0x06 -#define BPF_MISC 0x07 - -/* ld/ldx fields */ -#define BPF_SIZE(code) ((code) & 0x18) -#define BPF_W 0x00 -#define BPF_H 0x08 -#define BPF_B 0x10 -#define BPF_MODE(code) ((code) & 0xe0) -#define BPF_IMM 0x00 -#define BPF_ABS 0x20 -#define BPF_IND 0x40 -#define BPF_MEM 0x60 -#define BPF_LEN 0x80 -#define BPF_MSH 0xa0 - -/* alu/jmp fields */ -#define BPF_OP(code) ((code) & 0xf0) -#define BPF_ADD 0x00 -#define BPF_SUB 0x10 -#define BPF_MUL 0x20 -#define BPF_DIV 0x30 -#define BPF_OR 0x40 -#define BPF_AND 0x50 -#define BPF_LSH 0x60 -#define BPF_RSH 0x70 -#define BPF_NEG 0x80 -#define BPF_JA 0x00 -#define BPF_JEQ 0x10 -#define BPF_JGT 0x20 -#define BPF_JGE 0x30 -#define BPF_JSET 0x40 -#define BPF_SRC(code) ((code) & 0x08) -#define BPF_K 0x00 -#define BPF_X 0x08 - -/* ret - BPF_K and BPF_X also apply */ -#define BPF_RVAL(code) ((code) & 0x18) -#define BPF_A 0x10 - -/* misc */ -#define BPF_MISCOP(code) ((code) & 0xf8) -#define BPF_TAX 0x00 -#define BPF_TXA 0x80 - -/* - * The instruction data structure. - */ -struct bpf_insn { - u_short code; - u_char jt; - u_char jf; - bpf_int32 k; -}; - -/* - * Macros for insn array initializers. - */ -#define BPF_STMT(code, k) { (u_short)(code), 0, 0, k } -#define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k } - -#if defined(BSD) && (defined(KERNEL) || defined(_KERNEL)) -/* - * Systems based on non-BSD kernels don't have ifnet's (or they don't mean - * anything if it is in <net/if.h>) and won't work like this. - */ -# if __STDC__ -extern void bpf_tap(struct ifnet *, u_char *, u_int); -extern void bpf_mtap(struct ifnet *, struct mbuf *); -extern void bpfattach(struct ifnet *, u_int, u_int); -extern void bpfilterattach(int); -# else -extern void bpf_tap(); -extern void bpf_mtap(); -extern void bpfattach(); -extern void bpfilterattach(); -# endif /* __STDC__ */ -#endif /* BSD && (_KERNEL || KERNEL) */ -#if __STDC__ -extern int bpf_validate(struct bpf_insn *, int); -extern u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int); -#else -extern int bpf_validate(); -extern u_int bpf_filter(); -#endif - -/* - * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST). - */ -#define BPF_MEMWORDS 16 - -#endif diff --git a/contrib/libpcap/gencode.c b/contrib/libpcap/gencode.c index d2cae21..b2981f5 100644 --- a/contrib/libpcap/gencode.c +++ b/contrib/libpcap/gencode.c @@ -18,10 +18,12 @@ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * $FreeBSD$ */ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.221.2.53 2007/09/12 19:17:24 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.221.2.34 2005/09/05 09:08:04 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -73,12 +75,7 @@ static const char rcsid[] _U_ = #include "ppp.h" #include "sll.h" #include "arcnet.h" -#ifdef HAVE_NET_PFVAR_H -#include <sys/socket.h> -#include <net/if.h> -#include <net/pfvar.h> -#include <net/if_pflog.h> -#endif +#include "pf.h" #ifndef offsetof #define offsetof(s, e) ((size_t)&((s *)0)->e) #endif @@ -105,12 +102,8 @@ static const char rcsid[] _U_ = static jmp_buf top_ctx; static pcap_t *bpf_pcap; -#ifdef WIN32 /* Hack for updating VLAN, MPLS, and PPPoE offsets. */ -static u_int orig_linktype = (u_int)-1, orig_nl = (u_int)-1, label_stack_depth = (u_int)-1; -#else static u_int orig_linktype = -1U, orig_nl = -1U, label_stack_depth = -1U; -#endif /* XXX */ #ifdef PCAP_FDDIPAD @@ -198,7 +191,6 @@ static inline struct block *gen_false(void); static struct block *gen_ether_linktype(int); static struct block *gen_linux_sll_linktype(int); static void insert_radiotap_load_llprefixlen(struct block *); -static void insert_ppi_load_llprefixlen(struct block *); static void insert_load_llprefixlen(struct block *); static struct slist *gen_llprefixlen(void); static struct block *gen_linktype(int); @@ -216,9 +208,9 @@ static struct block *gen_wlanhostop(const u_char *, int); static struct block *gen_ipfchostop(const u_char *, int); static struct block *gen_dnhostop(bpf_u_int32, int); static struct block *gen_mpls_linktype(int); -static struct block *gen_host(bpf_u_int32, bpf_u_int32, int, int, int); +static struct block *gen_host(bpf_u_int32, bpf_u_int32, int, int); #ifdef INET6 -static struct block *gen_host6(struct in6_addr *, struct in6_addr *, int, int, int); +static struct block *gen_host6(struct in6_addr *, struct in6_addr *, int, int); #endif #ifndef INET6 static struct block *gen_gateway(const u_char *, bpf_u_int32 **, int, int); @@ -248,7 +240,6 @@ static struct slist *xfer_to_a(struct arth *); static struct block *gen_mac_multicast(int); static struct block *gen_len(int, int); -static struct block *gen_ppi_dlt_check(void); static struct block *gen_msg_abbrev(int type); static void * @@ -359,10 +350,9 @@ int no_optimize; int pcap_compile(pcap_t *p, struct bpf_program *program, - const char *buf, int optimize, bpf_u_int32 mask) + char *buf, int optimize, bpf_u_int32 mask) { extern int n_errors; - const char * volatile xbuf = buf; int len; no_optimize = 0; @@ -384,7 +374,7 @@ pcap_compile(pcap_t *p, struct bpf_program *program, return -1; } - lex_init(xbuf ? xbuf : ""); + lex_init(buf ? buf : ""); init_linktype(p); (void)pcap_parse(); @@ -415,7 +405,7 @@ pcap_compile(pcap_t *p, struct bpf_program *program, int pcap_compile_nopcap(int snaplen_arg, int linktype_arg, struct bpf_program *program, - const char *buf, int optimize, bpf_u_int32 mask) + char *buf, int optimize, bpf_u_int32 mask) { pcap_t *p; int ret; @@ -484,20 +474,10 @@ merge(b0, b1) *p = b1; } - void finish_parse(p) struct block *p; { - struct block *ppi_dlt_check; - - ppi_dlt_check = gen_ppi_dlt_check(); - - if (ppi_dlt_check != NULL) - { - gen_and(ppi_dlt_check, p); - } - backpatch(p, gen_retblk(snaplen)); p->sense = !p->sense; backpatch(p, gen_retblk(0)); @@ -518,7 +498,6 @@ finish_parse(p) * require the length of that header, doing more for that * header length isn't really worth the effort. */ - insert_load_llprefixlen(root); } @@ -691,26 +670,20 @@ gen_ncmp(offrel, offset, size, mask, jtype, reverse, v) static int reg_ll_size; /* - * This is the offset of the beginning of the link-layer header from - * the beginning of the raw packet data. - * + * This is the offset of the beginning of the link-layer header. * It's usually 0, except for 802.11 with a fixed-length radio header. - * (For 802.11 with a variable-length radio header, we have to generate - * code to compute that offset; off_ll is 0 in that case.) */ static u_int off_ll; /* * This is the offset of the beginning of the MAC-layer header. - * It's usually 0, except for ATM LANE, where it's the offset, relative - * to the beginning of the raw packet data, of the Ethernet header. + * It's usually 0, except for ATM LANE. */ static u_int off_mac; /* * "off_linktype" is the offset to information in the link-layer header - * giving the packet type. This offset is relative to the beginning - * of the link-layer header (i.e., it doesn't include off_ll). + * giving the packet type. * * For Ethernet, it's the offset of the Ethernet type field. * @@ -748,11 +721,6 @@ static u_int off_vci; static u_int off_proto; /* - * These are offsets for the MTP2 fields. - */ -static u_int off_li; - -/* * These are offsets for the MTP3 fields. */ static u_int off_sio; @@ -768,8 +736,6 @@ static u_int off_payload; /* * These are offsets to the beginning of the network-layer header. - * They are relative to the beginning of the link-layer header (i.e., - * they don't include off_ll). * * If the link layer never uses 802.2 LLC: * @@ -818,7 +784,6 @@ init_linktype(p) /* * And assume we're not doing SS7. */ - off_li = -1; off_sio = -1; off_opc = -1; off_dpc = -1; @@ -993,9 +958,9 @@ init_linktype(p) * the Prism header is fixed-length. */ off_ll = 144; - off_linktype = 24; - off_nl = 32; /* Prism+802.11+802.2+SNAP */ - off_nl_nosnap = 27; /* Prism+802.11+802.2 */ + off_linktype = 144+24; + off_nl = 144+32; /* Prism+802.11+802.2+SNAP */ + off_nl_nosnap = 144+27; /* Prism+802.11+802.2 */ return; case DLT_IEEE802_11_RADIO_AVS: @@ -1011,35 +976,14 @@ init_linktype(p) * more so; this header is also variable-length, * with the length being the 32-bit big-endian * number at an offset of 4 from the beginning - * of the radio header. We should handle that the - * same way we handle the length at the beginning - * of the radiotap header. - * - * XXX - in Linux, do any drivers that supply an AVS - * header supply a link-layer type other than - * ARPHRD_IEEE80211_PRISM? If so, we should map that - * to DLT_IEEE802_11_RADIO_AVS; if not, or if there are - * any drivers that supply an AVS header but supply - * an ARPHRD value of ARPHRD_IEEE80211_PRISM, we'll - * have to check the header in the generated code to - * determine whether it's Prism or AVS. + * of the radio header. */ off_ll = 64; - off_linktype = 24; - off_nl = 32; /* Radio+802.11+802.2+SNAP */ - off_nl_nosnap = 27; /* Radio+802.11+802.2 */ + off_linktype = 64+24; + off_nl = 64+32; /* Radio+802.11+802.2+SNAP */ + off_nl_nosnap = 64+27; /* Radio+802.11+802.2 */ return; - - /* - * At the moment we treat PPI as normal Radiotap encoded - * packets. The difference is in the function that generates - * the code at the beginning to compute the header length. - * Since this code generator of PPI supports bare 802.11 - * encapsulation only (i.e. the encapsulated DLT should be - * DLT_IEEE802_11) we generate code to check for this too. - */ - case DLT_PPI: case DLT_IEEE802_11_RADIO: /* * Same as 802.11, but with an additional header before @@ -1139,17 +1083,6 @@ init_linktype(p) off_nl_nosnap = 0; /* no 802.2 LLC */ return; - /* - * the only BPF-interesting FRF.16 frames are non-control frames; - * Frame Relay has a variable length link-layer - * so lets start with offset 4 for now and increments later on (FIXME); - */ - case DLT_MFR: - off_linktype = -1; - off_nl = 4; - off_nl_nosnap = 0; /* XXX - for now -> no 802.2 LLC */ - return; - case DLT_APPLE_IP_OVER_IEEE1394: off_linktype = 16; off_nl = 18; @@ -1180,13 +1113,12 @@ init_linktype(p) off_nl_nosnap = 44; /* XXX - what does it do with 802.3 packets? */ return; -#ifdef HAVE_NET_PFVAR_H case DLT_PFLOG: off_linktype = 0; + /* XXX read this from pf.h? */ off_nl = PFLOG_HDRLEN; off_nl_nosnap = PFLOG_HDRLEN; /* no 802.2 LLC */ return; -#endif case DLT_JUNIPER_MFR: case DLT_JUNIPER_MLFR: @@ -1250,14 +1182,7 @@ init_linktype(p) off_nl_nosnap = -1; /* no 802.2 LLC */ return; - case DLT_JUNIPER_VP: - off_linktype = 18; - off_nl = -1; - off_nl_nosnap = -1; - return; - case DLT_MTP2: - off_li = 2; off_sio = 3; off_opc = 4; off_dpc = 4; @@ -1267,17 +1192,6 @@ init_linktype(p) off_nl_nosnap = -1; return; - case DLT_MTP2_WITH_PHDR: - off_li = 6; - off_sio = 7; - off_opc = 8; - off_dpc = 8; - off_sls = 11; - off_linktype = -1; - off_nl = -1; - off_nl_nosnap = -1; - return; - #ifdef DLT_PFSYNC case DLT_PFSYNC: off_linktype = -1; @@ -1294,24 +1208,6 @@ init_linktype(p) off_nl = -1; off_nl_nosnap = -1; return; - - case DLT_USB: - /* - * Currently, only raw "link[N:M]" filtering is supported. - */ - off_linktype = -1; - off_nl = -1; - off_nl_nosnap = -1; - return; - - case DLT_BLUETOOTH_HCI_H4: - /* - * Currently, only raw "link[N:M]" filtering is supported. - */ - off_linktype = -1; - off_nl = -1; - off_nl_nosnap = -1; - return; } bpf_error("unknown data link type %d", linktype); /* NOTREACHED */ @@ -1335,34 +1231,18 @@ gen_load_llrel(offset, size) * If "s" is non-null, it has code to arrange that the X register * contains the length of the prefix preceding the link-layer * header. - * - * Otherwise, the length of the prefix preceding the link-layer - * header is "off_ll". */ if (s != NULL) { - /* - * There's a variable-length prefix preceding the - * link-layer header. "s" points to a list of statements - * that put the length of that prefix into the X register. - * do an indirect load, to use the X register as an offset. - */ s2 = new_stmt(BPF_LD|BPF_IND|size); s2->s.k = offset; sappend(s, s2); } else { - /* - * There is no variable-length header preceding the - * link-layer header; add in off_ll, which, if there's - * a fixed-length header preceding the link-layer header, - * is the length of that header. - */ s = new_stmt(BPF_LD|BPF_ABS|size); - s->s.k = offset + off_ll; + s->s.k = offset; } return s; } - /* * Load a value relative to the beginning of the specified header. */ @@ -1376,12 +1256,11 @@ gen_load_a(offrel, offset, size) switch (offrel) { case OR_PACKET: - s = new_stmt(BPF_LD|BPF_ABS|size); - s->s.k = offset; + s = gen_load_llrel(offset, size); break; case OR_LINK: - s = gen_load_llrel(offset, size); + s = gen_load_llrel(off_ll + offset, size); break; case OR_NET: @@ -1394,24 +1273,17 @@ gen_load_a(offrel, offset, size) case OR_TRAN_IPV4: /* - * Load the X register with the length of the IPv4 header - * (plus the offset of the link-layer header, if it's - * preceded by a variable-length header such as a radio - * header), in bytes. + * Load the X register with the length of the IPv4 header, + * in bytes. */ s = gen_loadx_iphdrlen(); /* - * Load the item at {offset of the link-layer header} + - * {offset, relative to the start of the link-layer - * header, of the IPv4 header} + {length of the IPv4 header} + - * {specified offset}. - * - * (If the link-layer is variable-length, it's included - * in the value in the X register, and off_ll is 0.) + * Load the item at {length of the link-layer header} + + * {length of the IPv4 header} + {specified offset}. */ s2 = new_stmt(BPF_LD|BPF_IND|size); - s2->s.k = off_ll + off_nl + offset; + s2->s.k = off_nl + offset; sappend(s, s2); break; @@ -1469,12 +1341,12 @@ gen_loadx_iphdrlen() } else { /* * There is no variable-length header preceding the - * link-layer header; add in off_ll, which, if there's - * a fixed-length header preceding the link-layer header, - * is the length of that header. + * link-layer header; if there's a fixed-length + * header preceding it, its length is included in + * the off_ variables, so it doesn't need to be added. */ s = new_stmt(BPF_LDX|BPF_MSH|BPF_B); - s->s.k = off_ll + off_nl; + s->s.k = off_nl; } return s; } @@ -1924,104 +1796,6 @@ insert_radiotap_load_llprefixlen(b) } } -/* - * At the moment we treat PPI as normal Radiotap encoded - * packets. The difference is in the function that generates - * the code at the beginning to compute the header length. - * Since this code generator of PPI supports bare 802.11 - * encapsulation only (i.e. the encapsulated DLT should be - * DLT_IEEE802_11) we generate code to check for this too. - */ -static void -insert_ppi_load_llprefixlen(b) - struct block *b; -{ - struct slist *s1, *s2; - - /* - * Prepend to the statements in this block code to load the - * length of the radiotap header into the register assigned - * to hold that length, if one has been assigned. - */ - if (reg_ll_size != -1) { - /* - * The 2 bytes at offsets of 2 and 3 from the beginning - * of the radiotap header are the length of the radiotap - * header; unfortunately, it's little-endian, so we have - * to load it a byte at a time and construct the value. - */ - - /* - * Load the high-order byte, at an offset of 3, shift it - * left a byte, and put the result in the X register. - */ - s1 = new_stmt(BPF_LD|BPF_B|BPF_ABS); - s1->s.k = 3; - s2 = new_stmt(BPF_ALU|BPF_LSH|BPF_K); - sappend(s1, s2); - s2->s.k = 8; - s2 = new_stmt(BPF_MISC|BPF_TAX); - sappend(s1, s2); - - /* - * Load the next byte, at an offset of 2, and OR the - * value from the X register into it. - */ - s2 = new_stmt(BPF_LD|BPF_B|BPF_ABS); - sappend(s1, s2); - s2->s.k = 2; - s2 = new_stmt(BPF_ALU|BPF_OR|BPF_X); - sappend(s1, s2); - - /* - * Now allocate a register to hold that value and store - * it. - */ - s2 = new_stmt(BPF_ST); - s2->s.k = reg_ll_size; - sappend(s1, s2); - - /* - * Now move it into the X register. - */ - s2 = new_stmt(BPF_MISC|BPF_TAX); - sappend(s1, s2); - - /* - * Now append all the existing statements in this - * block to these statements. - */ - sappend(s1, b->stmts); - b->stmts = s1; - - } -} - -static struct block * -gen_ppi_dlt_check(void) -{ - struct slist *s_load_dlt; - struct block *b; - - if (linktype == DLT_PPI) - { - /* Create the statements that check for the DLT - */ - s_load_dlt = new_stmt(BPF_LD|BPF_W|BPF_ABS); - s_load_dlt->s.k = 4; - - b = new_block(JMP(BPF_JEQ)); - - b->stmts = s_load_dlt; - b->s.k = SWAPLONG(DLT_IEEE802_11); - } - else - { - b = NULL; - } - - return b; -} static void insert_load_llprefixlen(b) @@ -2029,21 +1803,8 @@ insert_load_llprefixlen(b) { switch (linktype) { - /* - * At the moment we treat PPI as normal Radiotap encoded - * packets. The difference is in the function that generates - * the code at the beginning to compute the header length. - * Since this code generator of PPI supports bare 802.11 - * encapsulation only (i.e. the encapsulated DLT should be - * DLT_IEEE802_11) we generate code to check for this too. - */ - case DLT_PPI: - insert_ppi_load_llprefixlen(b); - break; - case DLT_IEEE802_11_RADIO: insert_radiotap_load_llprefixlen(b); - break; } } @@ -2070,38 +1831,6 @@ gen_radiotap_llprefixlen(void) return s; } -/* - * At the moment we treat PPI as normal Radiotap encoded - * packets. The difference is in the function that generates - * the code at the beginning to compute the header length. - * Since this code generator of PPI supports bare 802.11 - * encapsulation only (i.e. the encapsulated DLT should be - * DLT_IEEE802_11) we generate code to check for this too. - */ -static struct slist * -gen_ppi_llprefixlen(void) -{ - struct slist *s; - - if (reg_ll_size == -1) { - /* - * We haven't yet assigned a register for the length - * of the radiotap header; allocate one. - */ - reg_ll_size = alloc_reg(); - } - - /* - * Load the register containing the radiotap length - * into the X register. - */ - s = new_stmt(BPF_LDX|BPF_MEM); - s->s.k = reg_ll_size; - return s; -} - - - /* * Generate code to compute the link-layer header length, if necessary, * putting it into the X register, and to return either a pointer to a @@ -2113,10 +1842,6 @@ gen_llprefixlen(void) { switch (linktype) { - case DLT_PPI: - return gen_ppi_llprefixlen(); - - case DLT_IEEE802_11_RADIO: return gen_radiotap_llprefixlen(); @@ -2179,7 +1904,6 @@ gen_linktype(proto) } break; - case DLT_PPI: case DLT_FDDI: case DLT_IEEE802: case DLT_IEEE802_11: @@ -2240,7 +1964,7 @@ gen_linktype(proto) case DLT_RAW: /* * These types don't provide any type field; packets - * are always IPv4 or IPv6. + * are always IP. * * XXX - for IPv4, check for a version number of 4, and, * for IPv6, check for a version number of 6? @@ -2248,13 +1972,10 @@ gen_linktype(proto) switch (proto) { case ETHERTYPE_IP: - /* Check for a version number of 4. */ - return gen_mcmp(OR_LINK, 0, BPF_B, 0x40, 0xF0); #ifdef INET6 case ETHERTYPE_IPV6: - /* Check for a version number of 6. */ - return gen_mcmp(OR_LINK, 0, BPF_B, 0x60, 0xF0); #endif + return gen_true(); /* always true */ default: return gen_false(); /* always false */ @@ -2432,7 +2153,6 @@ gen_linktype(proto) } return (gen_cmp(OR_LINK, 0, BPF_W, (bpf_int32)proto)); -#ifdef HAVE_NET_PFVAR_H case DLT_PFLOG: /* * af field is host byte order in contrast to the rest of @@ -2450,7 +2170,6 @@ gen_linktype(proto) return gen_false(); /*NOTREACHED*/ break; -#endif /* HAVE_NET_PFVAR_H */ case DLT_ARCNET: case DLT_ARCNET_LINUX: @@ -2567,7 +2286,6 @@ gen_linktype(proto) case DLT_JUNIPER_PPP: case DLT_JUNIPER_FRELAY: case DLT_JUNIPER_CHDLC: - case DLT_JUNIPER_VP: /* just lets verify the magic number for now - * on ATM we may have up to 6 different encapsulations on the wire * and need a lot of heuristics to figure out that the payload @@ -3328,22 +3046,22 @@ gen_dnhostop(addr, dir) tmp = gen_mcmp(OR_NET, 2, BPF_H, (bpf_int32)ntohs(0x0681), (bpf_int32)ntohs(0x07FF)); b1 = gen_cmp(OR_NET, 2 + 1 + offset_lh, - BPF_H, (bpf_int32)ntohs((u_short)addr)); + BPF_H, (bpf_int32)ntohs(addr)); gen_and(tmp, b1); /* Check for pad = 0, long header case */ tmp = gen_mcmp(OR_NET, 2, BPF_B, (bpf_int32)0x06, (bpf_int32)0x7); - b2 = gen_cmp(OR_NET, 2 + offset_lh, BPF_H, (bpf_int32)ntohs((u_short)addr)); + b2 = gen_cmp(OR_NET, 2 + offset_lh, BPF_H, (bpf_int32)ntohs(addr)); gen_and(tmp, b2); gen_or(b2, b1); /* Check for pad = 1, short header case */ tmp = gen_mcmp(OR_NET, 2, BPF_H, (bpf_int32)ntohs(0x0281), (bpf_int32)ntohs(0x07FF)); - b2 = gen_cmp(OR_NET, 2 + 1 + offset_sh, BPF_H, (bpf_int32)ntohs((u_short)addr)); + b2 = gen_cmp(OR_NET, 2 + 1 + offset_sh, BPF_H, (bpf_int32)ntohs(addr)); gen_and(tmp, b2); gen_or(b2, b1); /* Check for pad = 0, short header case */ tmp = gen_mcmp(OR_NET, 2, BPF_B, (bpf_int32)0x02, (bpf_int32)0x7); - b2 = gen_cmp(OR_NET, 2 + offset_sh, BPF_H, (bpf_int32)ntohs((u_short)addr)); + b2 = gen_cmp(OR_NET, 2 + offset_sh, BPF_H, (bpf_int32)ntohs(addr)); gen_and(tmp, b2); gen_or(b2, b1); @@ -3387,33 +3105,26 @@ gen_mpls_linktype(proto) } static struct block * -gen_host(addr, mask, proto, dir, type) +gen_host(addr, mask, proto, dir) bpf_u_int32 addr; bpf_u_int32 mask; int proto; int dir; - int type; { struct block *b0, *b1; - const char *typestr; - - if (type == Q_NET) - typestr = "net"; - else - typestr = "host"; switch (proto) { case Q_DEFAULT: - b0 = gen_host(addr, mask, Q_IP, dir, type); + b0 = gen_host(addr, mask, Q_IP, dir); /* * Only check for non-IPv4 addresses if we're not * checking MPLS-encapsulated packets. */ if (label_stack_depth == 0) { - b1 = gen_host(addr, mask, Q_ARP, dir, type); + b1 = gen_host(addr, mask, Q_ARP, dir); gen_or(b0, b1); - b0 = gen_host(addr, mask, Q_RARP, dir, type); + b0 = gen_host(addr, mask, Q_RARP, dir); gen_or(b1, b0); } return b0; @@ -3428,28 +3139,28 @@ gen_host(addr, mask, proto, dir, type) return gen_hostop(addr, mask, dir, ETHERTYPE_ARP, 14, 24); case Q_TCP: - bpf_error("'tcp' modifier applied to %s", typestr); + bpf_error("'tcp' modifier applied to host"); case Q_SCTP: - bpf_error("'sctp' modifier applied to %s", typestr); + bpf_error("'sctp' modifier applied to host"); case Q_UDP: - bpf_error("'udp' modifier applied to %s", typestr); + bpf_error("'udp' modifier applied to host"); case Q_ICMP: - bpf_error("'icmp' modifier applied to %s", typestr); + bpf_error("'icmp' modifier applied to host"); case Q_IGMP: - bpf_error("'igmp' modifier applied to %s", typestr); + bpf_error("'igmp' modifier applied to host"); case Q_IGRP: - bpf_error("'igrp' modifier applied to %s", typestr); + bpf_error("'igrp' modifier applied to host"); case Q_PIM: - bpf_error("'pim' modifier applied to %s", typestr); + bpf_error("'pim' modifier applied to host"); case Q_VRRP: - bpf_error("'vrrp' modifier applied to %s", typestr); + bpf_error("'vrrp' modifier applied to host"); case Q_ATALK: bpf_error("ATALK host filtering not implemented"); @@ -3477,38 +3188,38 @@ gen_host(addr, mask, proto, dir, type) bpf_error("'ip6' modifier applied to ip host"); case Q_ICMPV6: - bpf_error("'icmp6' modifier applied to %s", typestr); + bpf_error("'icmp6' modifier applied to host"); #endif /* INET6 */ case Q_AH: - bpf_error("'ah' modifier applied to %s", typestr); + bpf_error("'ah' modifier applied to host"); case Q_ESP: - bpf_error("'esp' modifier applied to %s", typestr); + bpf_error("'esp' modifier applied to host"); case Q_ISO: bpf_error("ISO host filtering not implemented"); case Q_ESIS: - bpf_error("'esis' modifier applied to %s", typestr); + bpf_error("'esis' modifier applied to host"); case Q_ISIS: - bpf_error("'isis' modifier applied to %s", typestr); + bpf_error("'isis' modifier applied to host"); case Q_CLNP: - bpf_error("'clnp' modifier applied to %s", typestr); + bpf_error("'clnp' modifier applied to host"); case Q_STP: - bpf_error("'stp' modifier applied to %s", typestr); + bpf_error("'stp' modifier applied to host"); case Q_IPX: bpf_error("IPX host filtering not implemented"); case Q_NETBEUI: - bpf_error("'netbeui' modifier applied to %s", typestr); + bpf_error("'netbeui' modifier applied to host"); case Q_RADIO: - bpf_error("'radio' modifier applied to %s", typestr); + bpf_error("'radio' modifier applied to host"); default: abort(); @@ -3518,57 +3229,49 @@ gen_host(addr, mask, proto, dir, type) #ifdef INET6 static struct block * -gen_host6(addr, mask, proto, dir, type) +gen_host6(addr, mask, proto, dir) struct in6_addr *addr; struct in6_addr *mask; int proto; int dir; - int type; { - const char *typestr; - - if (type == Q_NET) - typestr = "net"; - else - typestr = "host"; - switch (proto) { case Q_DEFAULT: - return gen_host6(addr, mask, Q_IPV6, dir, type); + return gen_host6(addr, mask, Q_IPV6, dir); case Q_IP: - bpf_error("'ip' modifier applied to ip6 %s", typestr); + bpf_error("'ip' modifier applied to ip6 host"); case Q_RARP: - bpf_error("'rarp' modifier applied to ip6 %s", typestr); + bpf_error("'rarp' modifier applied to ip6 host"); case Q_ARP: - bpf_error("'arp' modifier applied to ip6 %s", typestr); + bpf_error("'arp' modifier applied to ip6 host"); case Q_SCTP: - bpf_error("'sctp' modifier applied to %s", typestr); + bpf_error("'sctp' modifier applied to host"); case Q_TCP: - bpf_error("'tcp' modifier applied to %s", typestr); + bpf_error("'tcp' modifier applied to host"); case Q_UDP: - bpf_error("'udp' modifier applied to %s", typestr); + bpf_error("'udp' modifier applied to host"); case Q_ICMP: - bpf_error("'icmp' modifier applied to %s", typestr); + bpf_error("'icmp' modifier applied to host"); case Q_IGMP: - bpf_error("'igmp' modifier applied to %s", typestr); + bpf_error("'igmp' modifier applied to host"); case Q_IGRP: - bpf_error("'igrp' modifier applied to %s", typestr); + bpf_error("'igrp' modifier applied to host"); case Q_PIM: - bpf_error("'pim' modifier applied to %s", typestr); + bpf_error("'pim' modifier applied to host"); case Q_VRRP: - bpf_error("'vrrp' modifier applied to %s", typestr); + bpf_error("'vrrp' modifier applied to host"); case Q_ATALK: bpf_error("ATALK host filtering not implemented"); @@ -3577,7 +3280,7 @@ gen_host6(addr, mask, proto, dir, type) bpf_error("AARP host filtering not implemented"); case Q_DECNET: - bpf_error("'decnet' modifier applied to ip6 %s", typestr); + bpf_error("'decnet' modifier applied to ip6 host"); case Q_SCA: bpf_error("SCA host filtering not implemented"); @@ -3595,37 +3298,37 @@ gen_host6(addr, mask, proto, dir, type) return gen_hostop6(addr, mask, dir, ETHERTYPE_IPV6, 8, 24); case Q_ICMPV6: - bpf_error("'icmp6' modifier applied to %s", typestr); + bpf_error("'icmp6' modifier applied to host"); case Q_AH: - bpf_error("'ah' modifier applied to %s", typestr); + bpf_error("'ah' modifier applied to host"); case Q_ESP: - bpf_error("'esp' modifier applied to %s", typestr); + bpf_error("'esp' modifier applied to host"); case Q_ISO: bpf_error("ISO host filtering not implemented"); case Q_ESIS: - bpf_error("'esis' modifier applied to %s", typestr); + bpf_error("'esis' modifier applied to host"); case Q_ISIS: - bpf_error("'isis' modifier applied to %s", typestr); + bpf_error("'isis' modifier applied to host"); case Q_CLNP: - bpf_error("'clnp' modifier applied to %s", typestr); + bpf_error("'clnp' modifier applied to host"); case Q_STP: - bpf_error("'stp' modifier applied to %s", typestr); + bpf_error("'stp' modifier applied to host"); case Q_IPX: bpf_error("IPX host filtering not implemented"); case Q_NETBEUI: - bpf_error("'netbeui' modifier applied to %s", typestr); + bpf_error("'netbeui' modifier applied to host"); case Q_RADIO: - bpf_error("'radio' modifier applied to %s", typestr); + bpf_error("'radio' modifier applied to host"); default: abort(); @@ -3652,25 +3355,18 @@ gen_gateway(eaddr, alist, proto, dir) case Q_IP: case Q_ARP: case Q_RARP: - switch (linktype) { - case DLT_EN10MB: - b0 = gen_ehostop(eaddr, Q_OR); - break; - case DLT_FDDI: - b0 = gen_fhostop(eaddr, Q_OR); - break; - case DLT_IEEE802: - b0 = gen_thostop(eaddr, Q_OR); - break; - case DLT_IEEE802_11: - case DLT_IEEE802_11_RADIO_AVS: - case DLT_PPI: - case DLT_IEEE802_11_RADIO: - case DLT_PRISM_HEADER: - b0 = gen_wlanhostop(eaddr, Q_OR); - break; - case DLT_SUNATM: - if (is_lane) { + if (linktype == DLT_EN10MB) + b0 = gen_ehostop(eaddr, Q_OR); + else if (linktype == DLT_FDDI) + b0 = gen_fhostop(eaddr, Q_OR); + else if (linktype == DLT_IEEE802) + b0 = gen_thostop(eaddr, Q_OR); + else if (linktype == DLT_IEEE802_11 || + linktype == DLT_IEEE802_11_RADIO_AVS || + linktype == DLT_IEEE802_11_RADIO || + linktype == DLT_PRISM_HEADER) + b0 = gen_wlanhostop(eaddr, Q_OR); + else if (linktype == DLT_SUNATM && is_lane) { /* * Check that the packet doesn't begin with an * LE Control marker. (We've already generated @@ -3685,19 +3381,15 @@ gen_gateway(eaddr, alist, proto, dir) */ b0 = gen_ehostop(eaddr, Q_OR); gen_and(b1, b0); - } - break; - case DLT_IP_OVER_FC: - b0 = gen_ipfchostop(eaddr, Q_OR); - break; - default: - bpf_error( + } else if (linktype == DLT_IP_OVER_FC) + b0 = gen_ipfchostop(eaddr, Q_OR); + else + bpf_error( "'gateway' supported only on ethernet/FDDI/token ring/802.11/Fibre Channel"); - } - b1 = gen_host(**alist++, 0xffffffff, proto, Q_OR, Q_HOST); + + b1 = gen_host(**alist++, 0xffffffff, proto, Q_OR); while (*alist) { - tmp = gen_host(**alist++, 0xffffffff, proto, Q_OR, - Q_HOST); + tmp = gen_host(**alist++, 0xffffffff, proto, Q_OR); gen_or(b1, tmp); b1 = tmp; } @@ -4470,9 +4162,6 @@ gen_protochain(v, proto, dir) if (linktype == DLT_IEEE802_11_RADIO) bpf_error("'protochain' not supported with radiotap headers"); - if (linktype == DLT_PPI) - bpf_error("'protochain' not supported with PPI headers"); - no_optimize = 1; /*this code is not compatible with optimzer yet */ /* @@ -4490,11 +4179,11 @@ gen_protochain(v, proto, dir) /* A = ip->ip_p */ s[i] = new_stmt(BPF_LD|BPF_ABS|BPF_B); - s[i]->s.k = off_ll + off_nl + 9; + s[i]->s.k = off_nl + 9; i++; /* X = ip->ip_hl << 2 */ s[i] = new_stmt(BPF_LDX|BPF_MSH|BPF_B); - s[i]->s.k = off_ll + off_nl; + s[i]->s.k = off_nl; i++; break; #ifdef INET6 @@ -4503,7 +4192,7 @@ gen_protochain(v, proto, dir) /* A = ip6->ip_nxt */ s[i] = new_stmt(BPF_LD|BPF_ABS|BPF_B); - s[i]->s.k = off_ll + off_nl + 6; + s[i]->s.k = off_nl + 6; i++; /* X = sizeof(struct ip6_hdr) */ s[i] = new_stmt(BPF_LDX|BPF_IMM); @@ -4583,7 +4272,7 @@ gen_protochain(v, proto, dir) i++; /* A = P[X + packet head] */ s[i] = new_stmt(BPF_LD|BPF_IND|BPF_B); - s[i]->s.k = off_ll + off_nl; + s[i]->s.k = off_nl; i++; /* MEM[reg2] = A */ s[i] = new_stmt(BPF_ST); @@ -4601,7 +4290,7 @@ gen_protochain(v, proto, dir) i++; /* A = P[X + packet head]; */ s[i] = new_stmt(BPF_LD|BPF_IND|BPF_B); - s[i]->s.k = off_ll + off_nl; + s[i]->s.k = off_nl; i++; /* A += 1 */ s[i] = new_stmt(BPF_ALU|BPF_ADD|BPF_K); @@ -4660,7 +4349,7 @@ gen_protochain(v, proto, dir) i++; /* A = P[X + packet head]; */ s[i] = new_stmt(BPF_LD|BPF_IND|BPF_B); - s[i]->s.k = off_ll + off_nl; + s[i]->s.k = off_nl; i++; /* MEM[reg2] = A */ s[i] = new_stmt(BPF_ST); @@ -4678,7 +4367,7 @@ gen_protochain(v, proto, dir) i++; /* A = P[X + packet head] */ s[i] = new_stmt(BPF_LD|BPF_IND|BPF_B); - s[i]->s.k = off_ll + off_nl; + s[i]->s.k = off_nl; i++; /* A += 2 */ s[i] = new_stmt(BPF_ALU|BPF_ADD|BPF_K); @@ -4732,7 +4421,6 @@ gen_protochain(v, proto, dir) #endif } - /* * Generate code that checks whether the packet is a packet for protocol * <proto> and whether the type field in that protocol's header has @@ -4779,6 +4467,7 @@ gen_proto(v, proto, dir) * * So we always check for ETHERTYPE_IP. */ + b0 = gen_linktype(ETHERTYPE_IP); #ifndef CHASE_CHAIN b1 = gen_cmp(OR_NET, 9, BPF_B, (bpf_int32)v); @@ -4963,7 +4652,7 @@ gen_scode(name, q) bpf_u_int32 **alist; #else int tproto6; - struct sockaddr_in *sin4; + struct sockaddr_in *sin; struct sockaddr_in6 *sin6; struct addrinfo *res, *res0; struct in6_addr mask128; @@ -4984,7 +4673,7 @@ gen_scode(name, q) addr <<= 8; mask <<= 8; } - return gen_host(addr, mask, proto, dir, q.addr); + return gen_host(addr, mask, proto, dir); case Q_DEFAULT: case Q_HOST: @@ -5022,7 +4711,6 @@ gen_scode(name, q) case DLT_IEEE802_11_RADIO_AVS: case DLT_IEEE802_11_RADIO: case DLT_PRISM_HEADER: - case DLT_PPI: eaddr = pcap_ether_hostton(name); if (eaddr == NULL) bpf_error( @@ -5070,7 +4758,7 @@ gen_scode(name, q) * I don't think DECNET hosts can be multihomed, so * there is no need to build up a list of addresses */ - return (gen_host(dn_addr, 0, proto, dir, q.addr)); + return (gen_host(dn_addr, 0, proto, dir)); } else { #ifndef INET6 alist = pcap_nametoaddr(name); @@ -5079,10 +4767,10 @@ gen_scode(name, q) tproto = proto; if (off_linktype == (u_int)-1 && tproto == Q_DEFAULT) tproto = Q_IP; - b = gen_host(**alist++, 0xffffffff, tproto, dir, q.addr); + b = gen_host(**alist++, 0xffffffff, tproto, dir); while (*alist) { tmp = gen_host(**alist++, 0xffffffff, - tproto, dir, q.addr); + tproto, dir); gen_or(b, tmp); b = tmp; } @@ -5104,10 +4792,10 @@ gen_scode(name, q) if (tproto == Q_IPV6) continue; - sin4 = (struct sockaddr_in *) + sin = (struct sockaddr_in *) res->ai_addr; - tmp = gen_host(ntohl(sin4->sin_addr.s_addr), - 0xffffffff, tproto, dir, q.addr); + tmp = gen_host(ntohl(sin->sin_addr.s_addr), + 0xffffffff, tproto, dir); break; case AF_INET6: if (tproto6 == Q_IP) @@ -5116,7 +4804,7 @@ gen_scode(name, q) sin6 = (struct sockaddr_in6 *) res->ai_addr; tmp = gen_host6(&sin6->sin6_addr, - &mask128, tproto6, dir, q.addr); + &mask128, tproto6, dir); break; default: continue; @@ -5174,9 +4862,12 @@ gen_scode(name, q) #ifndef INET6 return gen_port(port, real_proto, dir); #else + { + struct block *b; b = gen_port(port, real_proto, dir); gen_or(gen_port6(port, real_proto, dir), b); return b; + } #endif /* INET6 */ case Q_PORTRANGE: @@ -5215,9 +4906,12 @@ gen_scode(name, q) #ifndef INET6 return gen_portrange(port1, port2, real_proto, dir); #else + { + struct block *b; b = gen_portrange(port1, port2, real_proto, dir); gen_or(gen_portrange6(port1, port2, real_proto, dir), b); return b; + } #endif /* INET6 */ case Q_GATEWAY: @@ -5283,14 +4977,7 @@ gen_mcode(s1, s2, masklen, q) /* Convert mask len to mask */ if (masklen > 32) bpf_error("mask length must be <= 32"); - if (masklen == 0) { - /* - * X << 32 is not guaranteed by C to be 0; it's - * undefined. - */ - m = 0; - } else - m = 0xffffffff << (32 - masklen); + m = 0xffffffff << (32 - masklen); if ((n & ~m) != 0) bpf_error("non-network bits set in \"%s/%d\"", s1, masklen); @@ -5299,14 +4986,13 @@ gen_mcode(s1, s2, masklen, q) switch (q.addr) { case Q_NET: - return gen_host(n, m, q.proto, q.dir, q.addr); + return gen_host(n, m, q.proto, q.dir); default: bpf_error("Mask syntax for networks only"); /* NOTREACHED */ } /* NOTREACHED */ - return NULL; } struct block * @@ -5333,7 +5019,7 @@ gen_ncode(s, v, q) case Q_HOST: case Q_NET: if (proto == Q_DECNET) - return gen_host(v, 0, proto, dir, q.addr); + return gen_host(v, 0, proto, dir); else if (proto == Q_LINK) { bpf_error("illegal link layer address"); } else { @@ -5349,7 +5035,7 @@ gen_ncode(s, v, q) v <<= 32 - vlen; mask <<= 32 - vlen; } - return gen_host(v, mask, proto, dir, q.addr); + return gen_host(v, mask, proto, dir); } case Q_PORT: @@ -5467,7 +5153,7 @@ gen_mcode6(s1, s2, masklen, q) /* FALLTHROUGH */ case Q_NET: - b = gen_host6(addr, &mask, q.proto, q.dir, q.addr); + b = gen_host6(addr, &mask, q.proto, q.dir); freeaddrinfo(res); return b; @@ -5475,7 +5161,6 @@ gen_mcode6(s1, s2, masklen, q) bpf_error("invalid qualifier against IPv6 address"); /* NOTREACHED */ } - return NULL; } #endif /*INET6*/ @@ -5487,48 +5172,40 @@ gen_ecode(eaddr, q) struct block *b, *tmp; if ((q.addr == Q_HOST || q.addr == Q_DEFAULT) && q.proto == Q_LINK) { - switch (linktype) { - case DLT_EN10MB: - return gen_ehostop(eaddr, (int)q.dir); - case DLT_FDDI: - return gen_fhostop(eaddr, (int)q.dir); - case DLT_IEEE802: - return gen_thostop(eaddr, (int)q.dir); - case DLT_IEEE802_11: - case DLT_IEEE802_11_RADIO_AVS: - case DLT_IEEE802_11_RADIO: - case DLT_PRISM_HEADER: - case DLT_PPI: - return gen_wlanhostop(eaddr, (int)q.dir); - case DLT_SUNATM: - if (is_lane) { - /* - * Check that the packet doesn't begin with an - * LE Control marker. (We've already generated - * a test for LANE.) - */ - tmp = gen_cmp(OR_LINK, SUNATM_PKT_BEGIN_POS, BPF_H, - 0xFF00); - gen_not(tmp); - - /* - * Now check the MAC address. - */ - b = gen_ehostop(eaddr, (int)q.dir); - gen_and(tmp, b); - return b; - } - break; - case DLT_IP_OVER_FC: - return gen_ipfchostop(eaddr, (int)q.dir); - default: - bpf_error("ethernet addresses supported only on ethernet/FDDI/token ring/802.11/ATM LANE/Fibre Channel"); - break; - } + if (linktype == DLT_EN10MB) + return gen_ehostop(eaddr, (int)q.dir); + if (linktype == DLT_FDDI) + return gen_fhostop(eaddr, (int)q.dir); + if (linktype == DLT_IEEE802) + return gen_thostop(eaddr, (int)q.dir); + if (linktype == DLT_IEEE802_11 || + linktype == DLT_IEEE802_11_RADIO_AVS || + linktype == DLT_IEEE802_11_RADIO || + linktype == DLT_PRISM_HEADER) + return gen_wlanhostop(eaddr, (int)q.dir); + if (linktype == DLT_SUNATM && is_lane) { + /* + * Check that the packet doesn't begin with an + * LE Control marker. (We've already generated + * a test for LANE.) + */ + tmp = gen_cmp(OR_LINK, SUNATM_PKT_BEGIN_POS, BPF_H, + 0xFF00); + gen_not(tmp); + + /* + * Now check the MAC address. + */ + b = gen_ehostop(eaddr, (int)q.dir); + gen_and(tmp, b); + return b; + } + if (linktype == DLT_IP_OVER_FC) + return gen_ipfchostop(eaddr, (int)q.dir); + bpf_error("ethernet addresses supported only on ethernet/FDDI/token ring/802.11/ATM LANE/Fibre Channel"); } bpf_error("ethernet address used in non-ether expression"); /* NOTREACHED */ - return NULL; } void @@ -5574,16 +5251,16 @@ xfer_to_a(a) * for "index". */ struct arth * -gen_load(proto, inst, size) +gen_load(proto, index, size) int proto; - struct arth *inst; + struct arth *index; int size; { struct slist *s, *tmp; struct block *b; int regno = alloc_reg(); - free_reg(inst->regno); + free_reg(index->regno); switch (size) { default: @@ -5620,14 +5297,14 @@ gen_load(proto, inst, size) * Load into the X register the offset computed into the * register specifed by "index". */ - s = xfer_to_x(inst); + s = xfer_to_x(index); /* * Load the item at that offset. */ tmp = new_stmt(BPF_LD|BPF_IND|size); sappend(s, tmp); - sappend(inst->s, s); + sappend(index->s, s); break; case Q_LINK: @@ -5654,11 +5331,11 @@ gen_load(proto, inst, size) * by "index". */ if (s != NULL) { - sappend(s, xfer_to_a(inst)); + sappend(s, xfer_to_a(index)); sappend(s, new_stmt(BPF_ALU|BPF_ADD|BPF_X)); sappend(s, new_stmt(BPF_MISC|BPF_TAX)); } else - s = xfer_to_x(inst); + s = xfer_to_x(index); /* * Load the item at the sum of the offset we've put in the @@ -5670,7 +5347,7 @@ gen_load(proto, inst, size) tmp = new_stmt(BPF_LD|BPF_IND|size); tmp->s.k = off_ll; sappend(s, tmp); - sappend(inst->s, s); + sappend(index->s, s); break; case Q_IP: @@ -5703,33 +5380,30 @@ gen_load(proto, inst, size) * by "index". */ if (s != NULL) { - sappend(s, xfer_to_a(inst)); + sappend(s, xfer_to_a(index)); sappend(s, new_stmt(BPF_ALU|BPF_ADD|BPF_X)); sappend(s, new_stmt(BPF_MISC|BPF_TAX)); } else - s = xfer_to_x(inst); + s = xfer_to_x(index); /* * Load the item at the sum of the offset we've put in the - * X register, the offset of the start of the network - * layer header, and the offset of the start of the link - * layer header (which is 0 if the radio header is - * variable-length; that header length is what we put - * into the X register and then added to the index). + * X register and the offset of the start of the network + * layer header. */ tmp = new_stmt(BPF_LD|BPF_IND|size); - tmp->s.k = off_ll + off_nl; + tmp->s.k = off_nl; sappend(s, tmp); - sappend(inst->s, s); + sappend(index->s, s); /* * Do the computation only if the packet contains * the protocol in question. */ b = gen_proto_abbrev(proto); - if (inst->b) - gen_and(inst->b, b); - inst->b = b; + if (index->b) + gen_and(index->b, b); + index->b = b; break; case Q_SCTP: @@ -5743,11 +5417,6 @@ gen_load(proto, inst, size) /* * The offset is relative to the beginning of * the transport-layer header. - * - * Load the X register with the length of the IPv4 header - * (plus the offset of the link-layer header, if it's - * a variable-length header), in bytes. - * * XXX - are there any cases where we want * off_nl_nosnap? * XXX - we should, if we're built with @@ -5757,25 +5426,23 @@ gen_load(proto, inst, size) s = gen_loadx_iphdrlen(); /* - * The X register now contains the sum of the length - * of any variable-length header preceding the link-layer - * header and the length of the network-layer header. - * Load into the A register the offset relative to + * The X register now contains the sum of the offset + * of the beginning of the link-layer header and + * the length of the network-layer header. Load + * into the A register the offset relative to * the beginning of the transport layer header, * add the X register to that, move that to the * X register, and load with an offset from the * X register equal to the offset of the network * layer header relative to the beginning of - * the link-layer header plus the length of any - * fixed-length header preceding the link-layer - * header. + * the link-layer header. */ - sappend(s, xfer_to_a(inst)); + sappend(s, xfer_to_a(index)); sappend(s, new_stmt(BPF_ALU|BPF_ADD|BPF_X)); sappend(s, new_stmt(BPF_MISC|BPF_TAX)); sappend(s, tmp = new_stmt(BPF_LD|BPF_IND|size)); - tmp->s.k = off_ll + off_nl; - sappend(inst->s, s); + tmp->s.k = off_nl; + sappend(index->s, s); /* * Do the computation only if the packet contains @@ -5784,12 +5451,12 @@ gen_load(proto, inst, size) * only fragment of that datagram. */ gen_and(gen_proto_abbrev(proto), b = gen_ipfrag()); - if (inst->b) - gen_and(inst->b, b); + if (index->b) + gen_and(index->b, b); #ifdef INET6 gen_and(gen_proto_abbrev(Q_IP), b); #endif - inst->b = b; + index->b = b; break; #ifdef INET6 case Q_ICMPV6: @@ -5797,12 +5464,12 @@ gen_load(proto, inst, size) /*NOTREACHED*/ #endif } - inst->regno = regno; + index->regno = regno; s = new_stmt(BPF_ST); s->s.k = regno; - sappend(inst->s, s); + sappend(index->s, s); - return inst; + return index; } struct block * @@ -5958,7 +5625,6 @@ alloc_reg() } bpf_error("too many registers needed to evaluate expression"); /* NOTREACHED */ - return 0; } /* @@ -6071,26 +5737,22 @@ gen_broadcast(proto) case Q_DEFAULT: case Q_LINK: - switch (linktype) { - case DLT_ARCNET: - case DLT_ARCNET_LINUX: - return gen_ahostop(abroadcast, Q_DST); - case DLT_EN10MB: - return gen_ehostop(ebroadcast, Q_DST); - case DLT_FDDI: - return gen_fhostop(ebroadcast, Q_DST); - case DLT_IEEE802: - return gen_thostop(ebroadcast, Q_DST); - case DLT_IEEE802_11: - case DLT_IEEE802_11_RADIO_AVS: - case DLT_IEEE802_11_RADIO: - case DLT_PPI: - case DLT_PRISM_HEADER: - return gen_wlanhostop(ebroadcast, Q_DST); - case DLT_IP_OVER_FC: - return gen_ipfchostop(ebroadcast, Q_DST); - case DLT_SUNATM: - if (is_lane) { + if (linktype == DLT_ARCNET || linktype == DLT_ARCNET_LINUX) + return gen_ahostop(abroadcast, Q_DST); + if (linktype == DLT_EN10MB) + return gen_ehostop(ebroadcast, Q_DST); + if (linktype == DLT_FDDI) + return gen_fhostop(ebroadcast, Q_DST); + if (linktype == DLT_IEEE802) + return gen_thostop(ebroadcast, Q_DST); + if (linktype == DLT_IEEE802_11 || + linktype == DLT_IEEE802_11_RADIO_AVS || + linktype == DLT_IEEE802_11_RADIO || + linktype == DLT_PRISM_HEADER) + return gen_wlanhostop(ebroadcast, Q_DST); + if (linktype == DLT_IP_OVER_FC) + return gen_ipfchostop(ebroadcast, Q_DST); + if (linktype == DLT_SUNATM && is_lane) { /* * Check that the packet doesn't begin with an * LE Control marker. (We've already generated @@ -6106,11 +5768,8 @@ gen_broadcast(proto) b0 = gen_ehostop(ebroadcast, Q_DST); gen_and(b1, b0); return b0; - } - break; - default: - bpf_error("not a broadcast link"); - } + } + bpf_error("not a broadcast link"); break; case Q_IP: @@ -6125,7 +5784,6 @@ gen_broadcast(proto) } bpf_error("only link-layer/IP broadcast filters supported"); /* NOTREACHED */ - return NULL; } /* @@ -6158,147 +5816,154 @@ gen_multicast(proto) case Q_DEFAULT: case Q_LINK: - switch (linktype) { - case DLT_ARCNET: - case DLT_ARCNET_LINUX: - /* all ARCnet multicasts use the same address */ - return gen_ahostop(abroadcast, Q_DST); - case DLT_EN10MB: - /* ether[0] & 1 != 0 */ - return gen_mac_multicast(0); - case DLT_FDDI: - /* - * XXX TEST THIS: MIGHT NOT PORT PROPERLY XXX - * - * XXX - was that referring to bit-order issues? - */ - /* fddi[1] & 1 != 0 */ - return gen_mac_multicast(1); - case DLT_IEEE802: - /* tr[2] & 1 != 0 */ - return gen_mac_multicast(2); - case DLT_IEEE802_11: - case DLT_IEEE802_11_RADIO_AVS: - case DLT_PPI: - case DLT_IEEE802_11_RADIO: - case DLT_PRISM_HEADER: - /* - * Oh, yuk. - * - * For control frames, there is no DA. - * - * For management frames, DA is at an - * offset of 4 from the beginning of - * the packet. - * - * For data frames, DA is at an offset - * of 4 from the beginning of the packet - * if To DS is clear and at an offset of - * 16 from the beginning of the packet - * if To DS is set. - */ - - /* - * Generate the tests to be done for data frames. - * - * First, check for To DS set, i.e. "link[1] & 0x01". - */ - s = gen_load_a(OR_LINK, 1, BPF_B); - b1 = new_block(JMP(BPF_JSET)); - b1->s.k = 0x01; /* To DS */ - b1->stmts = s; - - /* - * If To DS is set, the DA is at 16. - */ - b0 = gen_mac_multicast(16); - gen_and(b1, b0); - - /* - * Now, check for To DS not set, i.e. check - * "!(link[1] & 0x01)". - */ - s = gen_load_a(OR_LINK, 1, BPF_B); - b2 = new_block(JMP(BPF_JSET)); - b2->s.k = 0x01; /* To DS */ - b2->stmts = s; - gen_not(b2); - - /* - * If To DS is not set, the DA is at 4. - */ - b1 = gen_mac_multicast(4); - gen_and(b2, b1); - - /* - * Now OR together the last two checks. That gives - * the complete set of checks for data frames. - */ - gen_or(b1, b0); - - /* - * Now check for a data frame. - * I.e, check "link[0] & 0x08". - */ - s = gen_load_a(OR_LINK, 0, BPF_B); - b1 = new_block(JMP(BPF_JSET)); - b1->s.k = 0x08; - b1->stmts = s; - - /* - * AND that with the checks done for data frames. - */ - gen_and(b1, b0); - - /* - * If the high-order bit of the type value is 0, this - * is a management frame. - * I.e, check "!(link[0] & 0x08)". - */ - s = gen_load_a(OR_LINK, 0, BPF_B); - b2 = new_block(JMP(BPF_JSET)); - b2->s.k = 0x08; - b2->stmts = s; - gen_not(b2); - - /* - * For management frames, the DA is at 4. - */ - b1 = gen_mac_multicast(4); - gen_and(b2, b1); - - /* - * OR that with the checks done for data frames. - * That gives the checks done for management and - * data frames. - */ - gen_or(b1, b0); - - /* - * If the low-order bit of the type value is 1, - * this is either a control frame or a frame - * with a reserved type, and thus not a - * frame with an SA. - * - * I.e., check "!(link[0] & 0x04)". - */ - s = gen_load_a(OR_LINK, 0, BPF_B); - b1 = new_block(JMP(BPF_JSET)); - b1->s.k = 0x04; - b1->stmts = s; - gen_not(b1); - - /* - * AND that with the checks for data and management - * frames. - */ - gen_and(b1, b0); - return b0; - case DLT_IP_OVER_FC: - b0 = gen_mac_multicast(2); - return b0; - case DLT_SUNATM: - if (is_lane) { + if (linktype == DLT_ARCNET || linktype == DLT_ARCNET_LINUX) + /* all ARCnet multicasts use the same address */ + return gen_ahostop(abroadcast, Q_DST); + + if (linktype == DLT_EN10MB) { + /* ether[0] & 1 != 0 */ + return gen_mac_multicast(0); + } + + if (linktype == DLT_FDDI) { + /* + * XXX TEST THIS: MIGHT NOT PORT PROPERLY XXX + * + * XXX - was that referring to bit-order issues? + */ + /* fddi[1] & 1 != 0 */ + return gen_mac_multicast(1); + } + + if (linktype == DLT_IEEE802) { + /* tr[2] & 1 != 0 */ + return gen_mac_multicast(2); + } + + if (linktype == DLT_IEEE802_11 || + linktype == DLT_IEEE802_11_RADIO_AVS || + linktype == DLT_IEEE802_11_RADIO || + linktype == DLT_PRISM_HEADER) { + /* + * Oh, yuk. + * + * For control frames, there is no DA. + * + * For management frames, DA is at an + * offset of 4 from the beginning of + * the packet. + * + * For data frames, DA is at an offset + * of 4 from the beginning of the packet + * if To DS is clear and at an offset of + * 16 from the beginning of the packet + * if To DS is set. + */ + + /* + * Generate the tests to be done for data frames. + * + * First, check for To DS set, i.e. "link[1] & 0x01". + */ + s = gen_load_a(OR_LINK, 1, BPF_B); + b1 = new_block(JMP(BPF_JSET)); + b1->s.k = 0x01; /* To DS */ + b1->stmts = s; + + /* + * If To DS is set, the DA is at 16. + */ + b0 = gen_mac_multicast(16); + gen_and(b1, b0); + + /* + * Now, check for To DS not set, i.e. check + * "!(link[1] & 0x01)". + */ + s = gen_load_a(OR_LINK, 1, BPF_B); + b2 = new_block(JMP(BPF_JSET)); + b2->s.k = 0x01; /* To DS */ + b2->stmts = s; + gen_not(b2); + + /* + * If To DS is not set, the DA is at 4. + */ + b1 = gen_mac_multicast(4); + gen_and(b2, b1); + + /* + * Now OR together the last two checks. That gives + * the complete set of checks for data frames. + */ + gen_or(b1, b0); + + /* + * Now check for a data frame. + * I.e, check "link[0] & 0x08". + */ + s = gen_load_a(OR_LINK, 0, BPF_B); + b1 = new_block(JMP(BPF_JSET)); + b1->s.k = 0x08; + b1->stmts = s; + + /* + * AND that with the checks done for data frames. + */ + gen_and(b1, b0); + + /* + * If the high-order bit of the type value is 0, this + * is a management frame. + * I.e, check "!(link[0] & 0x08)". + */ + s = gen_load_a(OR_LINK, 0, BPF_B); + b2 = new_block(JMP(BPF_JSET)); + b2->s.k = 0x08; + b2->stmts = s; + gen_not(b2); + + /* + * For management frames, the DA is at 4. + */ + b1 = gen_mac_multicast(4); + gen_and(b2, b1); + + /* + * OR that with the checks done for data frames. + * That gives the checks done for management and + * data frames. + */ + gen_or(b1, b0); + + /* + * If the low-order bit of the type value is 1, + * this is either a control frame or a frame + * with a reserved type, and thus not a + * frame with an SA. + * + * I.e., check "!(link[0] & 0x04)". + */ + s = gen_load_a(OR_LINK, 0, BPF_B); + b1 = new_block(JMP(BPF_JSET)); + b1->s.k = 0x04; + b1->stmts = s; + gen_not(b1); + + /* + * AND that with the checks for data and management + * frames. + */ + gen_and(b1, b0); + return b0; + } + + if (linktype == DLT_IP_OVER_FC) { + b0 = gen_mac_multicast(2); + return b0; + } + + if (linktype == DLT_SUNATM && is_lane) { /* * Check that the packet doesn't begin with an * LE Control marker. (We've already generated @@ -6312,13 +5977,10 @@ gen_multicast(proto) b0 = gen_mac_multicast(off_mac); gen_and(b1, b0); return b0; - } - break; - default: - break; - } - /* Link not known to support multicasts */ - break; + } + + /* Link not known to support multicasts */ + break; case Q_IP: b0 = gen_linktype(ETHERTYPE_IP); @@ -6336,7 +5998,6 @@ gen_multicast(proto) } bpf_error("link-layer multicast filters supported only on ethernet/FDDI/token ring/ARCNET/802.11/ATM LANE/Fibre Channel"); /* NOTREACHED */ - return NULL; } /* @@ -6382,12 +6043,10 @@ gen_inbound(dir) } break; -#ifdef HAVE_NET_PFVAR_H case DLT_PFLOG: b0 = gen_cmp(OR_LINK, offsetof(struct pfloghdr, dir), BPF_B, (bpf_int32)((dir == 0) ? PF_IN : PF_OUT)); break; -#endif case DLT_PPP_PPPD: if (dir) { @@ -6414,7 +6073,6 @@ gen_inbound(dir) case DLT_JUNIPER_PPP: case DLT_JUNIPER_FRELAY: case DLT_JUNIPER_CHDLC: - case DLT_JUNIPER_VP: /* juniper flags (including direction) are stored * the byte after the 3-byte magic number */ if (dir) { @@ -6435,7 +6093,6 @@ gen_inbound(dir) return (b0); } -#ifdef HAVE_NET_PFVAR_H /* PF firewall log matched interface */ struct block * gen_pf_ifname(const char *ifname) @@ -6545,55 +6202,6 @@ gen_pf_action(int action) return (b0); } -#else /* !HAVE_NET_PFVAR_H */ -struct block * -gen_pf_ifname(const char *ifname) -{ - bpf_error("libpcap was compiled without pf support"); - /* NOTREACHED */ - return (NULL); -} - -struct block * -gen_pf_ruleset(char *ruleset) -{ - bpf_error("libpcap was compiled on a machine without pf support"); - /* NOTREACHED */ - return (NULL); -} - -struct block * -gen_pf_rnr(int rnr) -{ - bpf_error("libpcap was compiled on a machine without pf support"); - /* NOTREACHED */ - return (NULL); -} - -struct block * -gen_pf_srnr(int srnr) -{ - bpf_error("libpcap was compiled on a machine without pf support"); - /* NOTREACHED */ - return (NULL); -} - -struct block * -gen_pf_reason(int reason) -{ - bpf_error("libpcap was compiled on a machine without pf support"); - /* NOTREACHED */ - return (NULL); -} - -struct block * -gen_pf_action(int action) -{ - bpf_error("libpcap was compiled on a machine without pf support"); - /* NOTREACHED */ - return (NULL); -} -#endif /* HAVE_NET_PFVAR_H */ struct block * gen_acode(eaddr, q) @@ -6606,7 +6214,6 @@ gen_acode(eaddr, q) } bpf_error("ARCnet address used in non-arc expression"); /* NOTREACHED */ - return NULL; } static struct block * @@ -6749,11 +6356,13 @@ gen_mpls(label_num) case DLT_C_HDLC: /* fall through */ case DLT_EN10MB: - b0 = gen_linktype(ETHERTYPE_MPLS); + b0 = gen_cmp(OR_LINK, off_linktype, BPF_H, + (bpf_int32)ETHERTYPE_MPLS); break; case DLT_PPP: - b0 = gen_linktype(PPP_MPLS_UCAST); + b0 = gen_cmp(OR_LINK, off_linktype, BPF_H, + (bpf_int32)PPP_MPLS_UCAST); break; /* FIXME add other DLT_s ... @@ -7015,50 +6624,6 @@ gen_atmtype_abbrev(type) return b1; } -/* - * Filtering for MTP2 messages based on li value - * FISU, length is null - * LSSU, length is 1 or 2 - * MSU, length is 3 or more - */ -struct block * -gen_mtp2type_abbrev(type) - int type; -{ - struct block *b0, *b1; - - switch (type) { - - case M_FISU: - if ( (linktype != DLT_MTP2) && - (linktype != DLT_MTP2_WITH_PHDR) ) - bpf_error("'fisu' supported only on MTP2"); - /* gen_ncmp(offrel, offset, size, mask, jtype, reverse, value) */ - b0 = gen_ncmp(OR_PACKET, off_li, BPF_B, 0x3f, BPF_JEQ, 0, 0); - break; - - case M_LSSU: - if ( (linktype != DLT_MTP2) && - (linktype != DLT_MTP2_WITH_PHDR) ) - bpf_error("'lssu' supported only on MTP2"); - b0 = gen_ncmp(OR_PACKET, off_li, BPF_B, 0x3f, BPF_JGT, 1, 2); - b1 = gen_ncmp(OR_PACKET, off_li, BPF_B, 0x3f, BPF_JGT, 0, 0); - gen_and(b1, b0); - break; - - case M_MSU: - if ( (linktype != DLT_MTP2) && - (linktype != DLT_MTP2_WITH_PHDR) ) - bpf_error("'msu' supported only on MTP2"); - b0 = gen_ncmp(OR_PACKET, off_li, BPF_B, 0x3f, BPF_JGT, 0, 2); - break; - - default: - abort(); - } - return b0; -} - struct block * gen_mtp3field_code(mtp3field, jvalue, jtype, reverse) int mtp3field; diff --git a/contrib/libpcap/gencode.h b/contrib/libpcap/gencode.h index f4c5cf7..15aef6d 100644 --- a/contrib/libpcap/gencode.h +++ b/contrib/libpcap/gencode.h @@ -18,7 +18,8 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: /tcpdump/master/libpcap/gencode.h,v 1.60.2.11 2007/06/11 09:52:04 guy Exp $ (LBL) + * $FreeBSD$ + * @(#) $Header: /tcpdump/master/libpcap/gencode.h,v 1.60.2.6 2005/09/05 09:08:06 guy Exp $ (LBL) */ /* @@ -173,16 +174,11 @@ end-to-end circuits, ILMI circuits or connection signalling circuit. */ -/* MTP2 types */ -#define M_FISU 22 /* FISU */ -#define M_LSSU 23 /* LSSU */ -#define M_MSU 24 /* MSU */ - -/* MTP3 field types */ -#define M_SIO 1 -#define M_OPC 2 -#define M_DPC 3 -#define M_SLS 4 +/*MTP3 field types */ +#define M_SIO 1 +#define M_OPC 2 +#define M_DPC 3 +#define M_SLS 4 struct slist; @@ -301,7 +297,6 @@ struct block *gen_atmfield_code(int atmfield, bpf_int32 jvalue, bpf_u_int32 jtyp struct block *gen_atmtype_abbrev(int type); struct block *gen_atmmulti_abbrev(int type); -struct block *gen_mtp2type_abbrev(int type); struct block *gen_mtp3field_code(int mtp3field, bpf_u_int32 jvalue, bpf_u_int32 jtype, int reverse); struct block *gen_pf_ifname(const char *); @@ -321,7 +316,7 @@ char *sdup(const char *); struct bpf_insn *icode_to_fcode(struct block *, int *); int pcap_parse(void); -void lex_init(const char *); +void lex_init(char *); void lex_cleanup(void); void sappend(struct slist *, struct slist *); diff --git a/contrib/libpcap/grammar.y b/contrib/libpcap/grammar.y index f9b7cb1..1072f96 100644 --- a/contrib/libpcap/grammar.y +++ b/contrib/libpcap/grammar.y @@ -19,10 +19,11 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * + * $FreeBSD$ */ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/libpcap/grammar.y,v 1.86.2.9 2007/09/12 19:17:25 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/grammar.y,v 1.86.2.5 2005/09/05 09:08:06 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -52,11 +53,7 @@ struct rtentry; #include "pcap-int.h" #include "gencode.h" -#ifdef HAVE_NET_PFVAR_H -#include <net/if.h> -#include <net/pfvar.h> -#include <net/if_pflog.h> -#endif +#include "pf.h" #include <pcap-namedb.h> #ifdef HAVE_OS_PROTO_H @@ -72,7 +69,7 @@ int n_errors = 0; static struct qual qerr = { Q_UNDEF, Q_UNDEF, Q_UNDEF, Q_UNDEF }; static void -yyerror(const char *msg) +yyerror(char *msg) { ++n_errors; bpf_error("%s", msg); @@ -89,50 +86,6 @@ pcap_parse() } #endif -#ifdef HAVE_NET_PFVAR_H -static int -pfreason_to_num(const char *reason) -{ - const char *reasons[] = PFRES_NAMES; - int i; - - for (i = 0; reasons[i]; i++) { - if (pcap_strcasecmp(reason, reasons[i]) == 0) - return (i); - } - bpf_error("unknown PF reason"); - /*NOTREACHED*/ -} - -static int -pfaction_to_num(const char *action) -{ - if (pcap_strcasecmp(action, "pass") == 0 || - pcap_strcasecmp(action, "accept") == 0) - return (PF_PASS); - else if (pcap_strcasecmp(action, "drop") == 0 || - pcap_strcasecmp(action, "block") == 0) - return (PF_DROP); - else { - bpf_error("unknown PF action"); - /*NOTREACHED*/ - } -} -#else /* !HAVE_NET_PFVAR_H */ -static int -pfreason_to_num(const char *reason) -{ - bpf_error("libpcap was compiled on a machine without pf support"); - /*NOTREACHED*/ -} - -static int -pfaction_to_num(const char *action) -{ - bpf_error("libpcap was compiled on a machine without pf support"); - /*NOTREACHED*/ -} -#endif /* HAVE_NET_PFVAR_H */ %} %union { @@ -161,9 +114,8 @@ pfaction_to_num(const char *action) %type <i> atmtype atmmultitype %type <blk> atmfield %type <blk> atmfieldvalue atmvalue atmlistvalue -%type <i> mtp2type -%type <blk> mtp3field -%type <blk> mtp3fieldvalue mtp3value mtp3listvalue +%type <blk> mtp3field +%type <blk> mtp3fieldvalue mtp3value mtp3listvalue %token DST SRC HOST GATEWAY @@ -189,8 +141,7 @@ pfaction_to_num(const char *action) %token OAM OAMF4 CONNECTMSG METACONNECT %token VPI VCI %token RADIO -%token FISU LSSU MSU -%token SIO OPC DPC SLS +%token SIO OPC DPC SLS %type <s> ID %type <e> EID @@ -311,7 +262,6 @@ rterm: head id { $$ = $2; } | atmtype { $$.b = gen_atmtype_abbrev($1); $$.q = qerr; } | atmmultitype { $$.b = gen_atmmulti_abbrev($1); $$.q = qerr; } | atmfield atmvalue { $$.b = $2.b; $$.q = qerr; } - | mtp2type { $$.b = gen_mtp2type_abbrev($1); $$.q = qerr; } | mtp3field mtp3value { $$.b = $2.b; $$.q = qerr; } ; /* protocol level qualifiers */ @@ -399,10 +349,28 @@ pfvar: PF_IFNAME ID { $$ = gen_pf_ifname($2); } ; reason: NUM { $$ = $1; } - | ID { $$ = pfreason_to_num($1); } + | ID { const char *reasons[] = PFRES_NAMES; + int i; + for (i = 0; reasons[i]; i++) { + if (pcap_strcasecmp($1, reasons[i]) == 0) { + $$ = i; + break; + } + } + if (reasons[i] == NULL) + bpf_error("unknown PF reason"); + } ; -action: ID { $$ = pfaction_to_num($1); } +action: ID { if (pcap_strcasecmp($1, "pass") == 0 || + pcap_strcasecmp($1, "accept") == 0) + $$ = PF_PASS; + else if (pcap_strcasecmp($1, "drop") == 0 || + pcap_strcasecmp($1, "block") == 0) + $$ = PF_DROP; + else + bpf_error("unknown PF action"); + } ; relop: '>' { $$ = BPF_JGT; } @@ -472,11 +440,6 @@ atmfieldvalue: NUM { atmlistvalue: atmfieldvalue | atmlistvalue or atmfieldvalue { gen_or($1.b, $3.b); $$ = $3; } ; - /* MTP2 types quantifier */ -mtp2type: FISU { $$ = M_FISU; } - | LSSU { $$ = M_LSSU; } - | MSU { $$ = M_MSU; } - ; /* MTP3 field types quantifier */ mtp3field: SIO { $$.mtp3fieldtype = M_SIO; } | OPC { $$.mtp3fieldtype = M_OPC; } diff --git a/contrib/libpcap/nametoaddr.c b/contrib/libpcap/nametoaddr.c index d60e93d..fe4c582 100644 --- a/contrib/libpcap/nametoaddr.c +++ b/contrib/libpcap/nametoaddr.c @@ -20,11 +20,13 @@ * * Name to id translation routines used by the scanner. * These functions are not time critical. + * + * $FreeBSD$ */ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/libpcap/nametoaddr.c,v 1.77.2.4 2007/06/11 09:52:05 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/nametoaddr.c,v 1.77.2.3 2005/04/20 11:13:51 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -276,13 +278,22 @@ pcap_nametoproto(const char *str) #include "ethertype.h" struct eproto { - const char *s; + char *s; u_short p; }; /* Static data base of ether protocol types. */ struct eproto eproto_db[] = { +#if 0 + /* The FreeBSD elf linker generates a request to copy this array + * (including its size) when you link with -lpcap. In order to + * not bump the major version number of this libpcap.so, we need + * to ensure that the array stays the same size. Since PUP is + * likely never seen in real life any more, it's the first to + * be sacrificed (in favor of ip6). + */ { "pup", ETHERTYPE_PUP }, +#endif { "xns", ETHERTYPE_NS }, { "ip", ETHERTYPE_IP }, #ifdef INET6 @@ -388,7 +399,7 @@ __pcap_atodn(const char *s, bpf_u_int32 *addr) u_int node, area; - if (sscanf(s, "%d.%d", &area, &node) != 2) + if (sscanf((char *)s, "%d.%d", &area, &node) != 2) bpf_error("malformed decnet address '%s'", s); *addr = (area << AREASHIFT) & AREAMASK; @@ -474,7 +485,7 @@ pcap_ether_hostton(const char *name) u_char a[6]; ap = NULL; - if (ether_hostton(name, (struct ether_addr *)a) == 0) { + if (ether_hostton((char *)name, (struct ether_addr *)a) == 0) { ap = (u_char *)malloc(6); if (ap != NULL) memcpy((char *)ap, (char *)a, 6); diff --git a/contrib/libpcap/nlpid.h b/contrib/libpcap/nlpid.h index c3ab8c2..7ea2963 100644 --- a/contrib/libpcap/nlpid.h +++ b/contrib/libpcap/nlpid.h @@ -15,6 +15,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * + * $FreeBSD$ * @(#) $Header: /tcpdump/master/libpcap/nlpid.h,v 1.2 2002/12/06 00:01:34 hannes Exp $ (Juniper) */ diff --git a/contrib/libpcap/packaging/pcap.spec b/contrib/libpcap/packaging/pcap.spec deleted file mode 100644 index 7df7abc..0000000 --- a/contrib/libpcap/packaging/pcap.spec +++ /dev/null @@ -1,65 +0,0 @@ -%define prefix /usr -%define version 0.9.4 - -Summary: packet capture library -Name: libpcap -Version: %version -Release: 1 -Group: Development/Libraries -Copyright: BSD -Source: libpcap-0.9.4.tar.gz -BuildRoot: /tmp/%{name}-buildroot -URL: http://www.tcpdump.org - -%description -Packet-capture library LIBPCAP 0.9.4 -Now maintained by "The Tcpdump Group" -See http://www.tcpdump.org -Please send inquiries/comments/reports to tcpdump-workers@tcpdump.org - -%prep -%setup - -%post -ldconfig - -%build -CFLAGS="$RPM_OPT_FLAGS" ./configure --prefix=%prefix -make - -%install -rm -rf $RPM_BUILD_ROOT -mkdir -p $RPM_BUILD_ROOT/usr/{lib,include} -mkdir -p $RPM_BUILD_ROOT/usr/share/man -mkdir -p $RPM_BUILD_ROOT/usr/include/net -mkdir -p $RPM_BUILD_ROOT/usr/man/man3 -make install DESTDIR=$RPM_BUILD_ROOT mandir=/usr/share/man -cd $RPM_BUILD_ROOT/usr/lib -V1=`echo 0.9.4 | sed 's/\\.[^\.]*$//g'` -V2=`echo 0.9.4 | sed 's/\\.[^\.]*\.[^\.]*$//g'` -ln -sf libpcap.so.0.9.4 libpcap.so.$V1 -if test "$V2" -ne "$V1"; then - ln -sf libpcap.so.$V1 libpcap.so.$V2 - ln -sf libpcap.so.$V2 libpcap.so -else - ln -sf libpcap.so.$V1 libpcap.so -fi - -#install -m 755 -o root libpcap.a $RPM_BUILD_ROOT/usr/lib -#install -m 644 -o root pcap.3 $RPM_BUILD_ROOT/usr/man/man3 -#install -m 644 -o root pcap.h $RPM_BUILD_ROOT/usr/include -#install -m 644 -o root pcap-bpf.h $RPM_BUILD_ROOT/usr/include/net -#install -m 644 -o root pcap-namedb.h $RPM_BUILD_ROOT/usr/include - -%clean -rm -rf $RPM_BUILD_ROOT - -%files -%defattr(-,root,root) -%doc LICENSE CHANGES INSTALL.txt README.linux TODO VERSION CREDITS packaging/pcap.spec -/usr/lib/libpcap.a -/usr/share/man/man3/* -/usr/include/pcap.h -/usr/include/pcap-bpf.h -/usr/include/pcap-namedb.h -/usr/lib/libpcap.so* diff --git a/contrib/libpcap/pcap-bpf.c b/contrib/libpcap/pcap-bpf.c index 027913e..e8492d3 100644 --- a/contrib/libpcap/pcap-bpf.c +++ b/contrib/libpcap/pcap-bpf.c @@ -17,10 +17,12 @@ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * $FreeBSD$ */ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.86.2.12 2007/06/15 17:57:27 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.86.2.8 2005/07/10 10:55:31 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -523,12 +525,8 @@ static inline int bpf_open(pcap_t *p, char *errbuf) { int fd; -#ifdef HAVE_CLONING_BPF - static const char device[] = "/dev/bpf"; -#else int n = 0; char device[sizeof "/dev/bpf0000000000"]; -#endif #ifdef _AIX /* @@ -540,12 +538,6 @@ bpf_open(pcap_t *p, char *errbuf) return (-1); #endif -#ifdef HAVE_CLONING_BPF - if ((fd = open(device, O_RDWR)) == -1 && - (errno != EACCES || (fd = open(device, O_RDONLY)) == -1)) - snprintf(errbuf, PCAP_ERRBUF_SIZE, - "(cannot open device) %s: %s", device, pcap_strerror(errno)); -#else /* * Go through all the minors and find one that isn't in use. */ @@ -576,7 +568,6 @@ bpf_open(pcap_t *p, char *errbuf) if (fd < 0) snprintf(errbuf, PCAP_ERRBUF_SIZE, "(no devices found) %s: %s", device, pcap_strerror(errno)); -#endif return (fd); } diff --git a/contrib/libpcap/pcap-int.h b/contrib/libpcap/pcap-int.h index 3071c77..5ca621a 100644 --- a/contrib/libpcap/pcap-int.h +++ b/contrib/libpcap/pcap-int.h @@ -30,7 +30,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#) $Header: /tcpdump/master/libpcap/pcap-int.h,v 1.68.2.11 2007/06/22 06:43:58 guy Exp $ (LBL) + * $FreeBSD$ + * @(#) $Header: /tcpdump/master/libpcap/pcap-int.h,v 1.68.2.6 2005/07/07 06:56:04 guy Exp $ (LBL) */ #ifndef pcap_int_h @@ -43,7 +44,7 @@ extern "C" { #include <pcap.h> #ifdef WIN32 -#include <Packet32.h> +#include <packet32.h> #endif /* WIN32 */ #ifdef MSDOS @@ -52,19 +53,6 @@ extern "C" { #endif /* - * Swap byte ordering of unsigned long long timestamp on a big endian - * machine. - */ -#define SWAPLL(ull) ((ull & 0xff00000000000000LL) >> 56) | \ - ((ull & 0x00ff000000000000LL) >> 40) | \ - ((ull & 0x0000ff0000000000LL) >> 24) | \ - ((ull & 0x000000ff00000000LL) >> 8) | \ - ((ull & 0x00000000ff000000LL) << 8) | \ - ((ull & 0x0000000000ff0000LL) << 24) | \ - ((ull & 0x000000000000ff00LL) << 40) | \ - ((ull & 0x00000000000000ffLL) << 56) - -/* * Savefile */ typedef enum { @@ -101,7 +89,6 @@ struct pcap_md { int ifindex; /* interface index of device we're bound to */ int lo_ifindex; /* interface index of the loopback device */ struct pcap *next; /* list of open promiscuous sock_packet pcaps */ - u_int packets_read; /* count of packets read with recvfrom() */ #endif #ifdef HAVE_DAG_API @@ -124,13 +111,8 @@ struct pcap_md { /* * Ultrix, DEC OSF/1^H^H^H^H^H^H^H^H^HDigital UNIX^H^H^H^H^H^H^H^H^H^H^H^H - * Tru64 UNIX, and some versions of NetBSD pad FDDI packets to make everything - * line up on a nice boundary. + * Tru64 UNIX, and NetBSD pad to make everything line up on a nice boundary. */ -#ifdef __NetBSD__ -#include <sys/param.h> /* needed to declare __NetBSD_Version__ */ -#endif - #if defined(ultrix) || defined(__osf__) || (defined(__NetBSD__) && __NetBSD_Version__ > 106000000) #define PCAP_FDDIPAD 3 #endif @@ -207,13 +189,9 @@ struct pcap { }; /* - * This is a timeval as stored in a savefile. + * This is a timeval as stored in disk in a dumpfile. * It has to use the same types everywhere, independent of the actual - * `struct timeval'; `struct timeval' has 32-bit tv_sec values on some - * platforms and 64-bit tv_sec values on other platforms, and writing - * out native `struct timeval' values would mean files could only be - * read on systems with the same tv_sec size as the system on which - * the file was written. + * `struct timeval' */ struct pcap_timeval { @@ -222,7 +200,7 @@ struct pcap_timeval { }; /* - * This is a `pcap_pkthdr' as actually stored in a savefile. + * How a `pcap_pkthdr' is actually stored in the dumpfile. * * Do not change the format of this structure, in any way (this includes * changes that only affect the length of fields in this structure), @@ -254,7 +232,7 @@ struct pcap_sf_pkthdr { }; /* - * How a `pcap_pkthdr' is actually stored in savefiles written + * How a `pcap_pkthdr' is actually stored in dumpfiles written * by some patched versions of libpcap (e.g. the ones in Red * Hat Linux 6.1 and 6.2). * @@ -291,16 +269,6 @@ int pcap_read(pcap_t *, int cnt, pcap_handler, u_char *); #include <stdarg.h> -#if !defined(HAVE_SNPRINTF) -#define snprintf pcap_snprintf -extern int snprintf (char *, size_t, const char *, ...); -#endif - -#if !defined(HAVE_VSNPRINTF) -#define vsnprintf pcap_vsnprintf -extern int vsnprintf (char *, size_t, const char *, va_list ap); -#endif - /* * Routines that most pcap implementations can use for non-blocking mode. */ diff --git a/contrib/libpcap/pcap-namedb.h b/contrib/libpcap/pcap-namedb.h index acaabd9..bbd06b0 100644 --- a/contrib/libpcap/pcap-namedb.h +++ b/contrib/libpcap/pcap-namedb.h @@ -30,7 +30,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#) $Header: /tcpdump/master/libpcap/pcap-namedb.h,v 1.10.2.1 2005/04/19 04:26:08 guy Exp $ (LBL) + * $FreeBSD$ + * @(#) $Header: /tcpdump/master/libpcap/pcap-namedb.h,v 1.10 2005/03/17 07:02:32 guy Exp $ (LBL) */ #ifndef lib_pcap_namedb_h diff --git a/contrib/libpcap/pcap.3 b/contrib/libpcap/pcap.3 index 94b1f6a..6fd0a07 100644 --- a/contrib/libpcap/pcap.3 +++ b/contrib/libpcap/pcap.3 @@ -1,4 +1,4 @@ -.\" @(#) $Header: /tcpdump/master/libpcap/pcap.3,v 1.64.2.11 2007/06/11 09:52:05 guy Exp $ +.\" @(#) $Header: /tcpdump/master/libpcap/pcap.3,v 1.64.2.8 2005/09/07 08:29:17 guy Exp $ .\" .\" Copyright (c) 1994, 1996, 1997 .\" The Regents of the University of California. All rights reserved. @@ -19,6 +19,8 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" +.\" $FreeBSD$ +.\" .TH PCAP 3 "27 February 2004" .SH NAME pcap \- Packet Capture library @@ -77,7 +79,7 @@ u_char *sp) .ft B int pcap_compile(pcap_t *p, struct bpf_program *fp, .ti +8 -const char *str, int optimize, bpf_u_int32 netmask) +char *str, int optimize, bpf_u_int32 netmask) int pcap_setfilter(pcap_t *p, struct bpf_program *fp) void pcap_freecode(struct bpf_program *) int pcap_setdirection(pcap_t *p, pcap_direction_t d) @@ -116,7 +118,7 @@ int pcap_fileno(pcap_t *p) int pcap_get_selectable_fd(pcap_t *p); void pcap_perror(pcap_t *p, char *prefix) char *pcap_geterr(pcap_t *p) -const char *pcap_strerror(int error) +char *pcap_strerror(int error) const char *pcap_lib_version(void) .ft .LP @@ -1079,11 +1081,6 @@ and type bytes. Linux-IrDA packets, with a .B DLT_LINUX_SLL header followed by the IrLAP header. -.TP 5 -.B DLT_LINUX_LAPD -LAPD (Q.921) frames, with a -.B DLT_LINUX_SLL -header captured via vISDN. .RE .PP .B pcap_list_datalinks() @@ -1122,6 +1119,24 @@ name. NULL is returned on failure. translates a data link type value to a short description of that data link type. NULL is returned on failure. .PP +.B pcap_list_datalinks() +is used to get a list of the supported data link types of the interface +associated with the pcap descriptor. +.B pcap_list_datalinks() +allocates an array to hold the list and sets +.IR *dlt_buf . +The caller is responsible for freeing the array. +.B \-1 +is returned on failure; +otherwise, the number of data link types in the array is returned. +.PP +.B pcap_set_datalink() +is used to set the current data link type of the pcap descriptor +to the type specified by +.IR dlt . +.B \-1 +is returned on failure. +.PP .B pcap_snapshot() returns the snapshot length specified when .B pcap_open_live() @@ -1145,13 +1160,12 @@ or NULL, if a network device was opened with .BR pcap_open_live() . .PP .B pcap_stats() -returns 0 and fills in the +returns 0 and fills in a .B pcap_stat -structure pointed to by its second argument. The values represent -packet statistics from the start of the run to the time of the call. If -there is an error or the underlying packet capture doesn't support -packet statistics, \-1 is returned and the error text can be obtained -with +struct. The values represent packet statistics from the start of the +run to the time of the call. If there is an error or the underlying +packet capture doesn't support packet statistics, \-1 is returned and +the error text can be obtained with .B pcap_perror() or .BR pcap_geterr() . diff --git a/contrib/libpcap/pcap.h b/contrib/libpcap/pcap.h index 9c8767e..e91b9d5 100644 --- a/contrib/libpcap/pcap.h +++ b/contrib/libpcap/pcap.h @@ -31,25 +31,17 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#) $Header: /tcpdump/master/libpcap/pcap.h,v 1.52.2.7 2007/06/11 09:52:05 guy Exp $ (LBL) + * $FreeBSD$ + * @(#) $Header: /tcpdump/master/libpcap/pcap.h,v 1.52.2.5 2005/07/07 02:04:36 guy Exp $ (LBL) */ #ifndef lib_pcap_h #define lib_pcap_h -#if defined(WIN32) - #include <pcap-stdinc.h> -#elif defined(MSDOS) - #include <sys/types.h> - #include <sys/socket.h> /* u_int, u_char etc. */ -#else /* UN*X */ - #include <sys/types.h> - #include <sys/time.h> -#endif /* WIN32/MSDOS/UN*X */ +#include <sys/types.h> +#include <sys/time.h> -#ifndef PCAP_DONT_INCLUDE_PCAP_BPF_H -#include <pcap-bpf.h> -#endif +#include <net/bpf.h> #include <stdio.h> @@ -127,16 +119,9 @@ typedef enum { } pcap_direction_t; /* - * Generic per-packet information, as supplied by libpcap. - * - * The time stamp can and should be a "struct timeval", regardless of - * whether your system supports 32-bit tv_sec in "struct timeval", - * 64-bit tv_sec in "struct timeval", or both if it supports both 32-bit - * and 64-bit applications. The on-disk format of savefiles uses 32-bit - * tv_sec (and tv_usec); this structure is irrelevant to that. 32-bit - * and 64-bit versions of libpcap, even if they're on the same platform, - * should supply the appropriate version of "struct timeval", even if - * that's not what the underlying packet capture mechanism supplies. + * Each packet in the dump file is prepended with this generic header. + * This gets around the problem of different headers for different + * packet interfaces. */ struct pcap_pkthdr { struct timeval ts; /* time stamp */ @@ -237,12 +222,12 @@ int pcap_setnonblock(pcap_t *, int, char *); void pcap_perror(pcap_t *, char *); int pcap_inject(pcap_t *, const void *, size_t); int pcap_sendpacket(pcap_t *, const u_char *, int); -const char *pcap_strerror(int); +char *pcap_strerror(int); char *pcap_geterr(pcap_t *); -int pcap_compile(pcap_t *, struct bpf_program *, const char *, int, +int pcap_compile(pcap_t *, struct bpf_program *, char *, int, bpf_u_int32); int pcap_compile_nopcap(int, int, struct bpf_program *, - const char *, int, bpf_u_int32); + char *, int, bpf_u_int32); void pcap_freecode(struct bpf_program *); int pcap_datalink(pcap_t *); int pcap_list_datalinks(pcap_t *, int **); diff --git a/contrib/libpcap/rawss7.h b/contrib/libpcap/rawss7.h deleted file mode 100644 index 8f8d058..0000000 --- a/contrib/libpcap/rawss7.h +++ /dev/null @@ -1,105 +0,0 @@ -/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */ -/* - * Copyright (c) 2003 - The tcpdump group. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor of the Laboratory may be used - * to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#) $Header: /tcpdump/master/libpcap/rawss7.h,v 1.1 2003/09/10 19:55:36 mcr Exp $ (LBL) - */ - -/* - * This file is never used in libpcap or tcpdump. It is provided as - * documentation linktypes 139 through 142 only. - */ - -/* - * Date: Tue, 09 Sep 2003 09:41:04 -0400 - * From: Jeff Morriss <jeff.morriss[AT]ulticom.com> - * To: tcpdump-workers@tcpdump.org - * Subject: [tcpdump-workers] request for LINKTYPE_ - * - * We've had some discussion over on ethereal-dev about a "fake link" or - * "raw SS7" dissector that allows dumping an arbitrary protocol into a - * file without any (otherwise necessary) lower level protocols. The - * common example has been dumping MTP3 into a file without, well, MTP2 or - * M2PA. - * - * We want to store these protocols directly in PCAP file format because - * it's well defined and there isn't another (popular) file format for - * capturing SS7 messages that we can reverse engineer (and we want to read - * these files into Ethereal). Rather than creating a new file format, it's - * a lot easier to just allocate a LINKTYPE_. - * - * Here is the original post thread: - * - * http://ethereal.com/lists/ethereal-dev/200306/threads.html#00200 - * - * July's thread on the subject: - * - * http://ethereal.com/lists/ethereal-dev/200307/threads.html#00124 - * - * August's thread: - * - * http://ethereal.com/lists/ethereal-dev/200308/threads.html#00193 - * - * - * and one of the last messages--which is why I'm mailing you today: - * - * http://ethereal.com/lists/ethereal-dev/200308/msg00193.html - * - * - * Based on the message in the last URL, I'd like to request a new - * LINKTYPE_: LINKTYPE_RAWSS7. - * - * This packets in this file type will contain a header: - */ - -typedef struct _rawss7_hdr { - /* NOTE: These are in network-byte order. */ - guint32 type; - guint16 length; - guint16 spare; -} rawss7_hdr; - -/* - * - * followed by protocol data for whatever protocol 'type' indicates. - * - * There was some discussion about these protocol 'type's being allocated by - * tcpdump-workers as well. In fact it would be handy to have one place to - * allocate such numbers, so what do you think about allocating 3 more (for - * now) LINKTYPE_'s: - */ - -#define LINKTYPE_RAWSS7_MTP2 140 -#define LINKTYPE_RAWSS7_MTP3 141 -#define LINKTYPE_RAWSS7_SCCP 142 - -/* - * - * There is no reason this can't be used to store non-SS7 protocols, but - * it's what we need to use it for now... - * - */ diff --git a/contrib/libpcap/scanner.l b/contrib/libpcap/scanner.l index 01face1..e231b0b 100644 --- a/contrib/libpcap/scanner.l +++ b/contrib/libpcap/scanner.l @@ -18,11 +18,13 @@ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * $FreeBSD$ */ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/libpcap/scanner.l,v 1.99.2.9 2007/06/11 09:52:05 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/scanner.l,v 1.99.2.4 2005/09/05 09:08:07 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -72,7 +74,6 @@ static char *in_buffer; #define getc(fp) (*in_buffer == 0 ? EOF : *in_buffer++) #endif -#define yylval pcap_lval extern YYSTYPE yylval; %} @@ -81,11 +82,11 @@ N ([0-9]+|(0X|0x)[0-9A-Fa-f]+) B ([0-9A-Fa-f][0-9A-Fa-f]?) W ([0-9A-Fa-f][0-9A-Fa-f]?[0-9A-Fa-f]?[0-9A-Fa-f]?) -%a 18400 -%o 21500 -%e 7600 -%k 4550 -%p 27600 +%a 16000 +%o 19000 +%e 6000 +%k 4000 +%p 25000 %n 2000 V680 {W}:{W}:{W}:{W}:{W}:{W}:{W}:{W} @@ -288,10 +289,6 @@ srnr|subrulenum return PF_SRNR; reason return PF_REASON; action return PF_ACTION; -fisu return FISU; -lssu return LSSU; -lsu return LSSU; -msu return MSU; sio return SIO; opc return OPC; dpc return DPC; @@ -361,7 +358,7 @@ tcp-urg { yylval.i = 0x20; return NUM; } %% void lex_init(buf) - const char *buf; + char *buf; { #ifdef FLEX_SCANNER in_buffer = yy_scan_string(buf); diff --git a/contrib/libpcap/snprintf.c b/contrib/libpcap/snprintf.c deleted file mode 100644 index 111e78e..0000000 --- a/contrib/libpcap/snprintf.c +++ /dev/null @@ -1,632 +0,0 @@ -/* - * Copyright (c) 1995-1999 Kungliga Tekniska Högskolan - * (Royal Institute of Technology, Stockholm, Sweden). - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* $Id: snprintf.c,v 1.1 2003/12/15 01:35:05 guy Exp $ */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#ifndef lint -static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/libpcap/snprintf.c,v 1.1 2003/12/15 01:35:05 guy Exp $"; -#endif - -#include <stdio.h> -#include <stdarg.h> -#include <stdlib.h> -#include <string.h> -#include <ctype.h> -#include <sys/types.h> - -#include <pcap-int.h> - -enum format_flags { - minus_flag = 1, - plus_flag = 2, - space_flag = 4, - alternate_flag = 8, - zero_flag = 16 -}; - -/* - * Common state - */ - -struct state { - unsigned char *str; - unsigned char *s; - unsigned char *theend; - size_t sz; - size_t max_sz; - int (*append_char)(struct state *, unsigned char); - int (*reserve)(struct state *, size_t); - /* XXX - methods */ -}; - -#ifndef HAVE_VSNPRINTF -static int -sn_reserve (struct state *state, size_t n) -{ - return state->s + n > state->theend; -} - -static int -sn_append_char (struct state *state, unsigned char c) -{ - if (sn_reserve (state, 1)) { - return 1; - } else { - *state->s++ = c; - return 0; - } -} -#endif - -#if 0 -static int -as_reserve (struct state *state, size_t n) -{ - if (state->s + n > state->theend) { - int off = state->s - state->str; - unsigned char *tmp; - - if (state->max_sz && state->sz >= state->max_sz) - return 1; - - state->sz = max(state->sz * 2, state->sz + n); - if (state->max_sz) - state->sz = min(state->sz, state->max_sz); - tmp = realloc (state->str, state->sz); - if (tmp == NULL) - return 1; - state->str = tmp; - state->s = state->str + off; - state->theend = state->str + state->sz - 1; - } - return 0; -} - -static int -as_append_char (struct state *state, unsigned char c) -{ - if(as_reserve (state, 1)) - return 1; - else { - *state->s++ = c; - return 0; - } -} -#endif - -static int -append_number(struct state *state, - unsigned long num, unsigned base, char *rep, - int width, int prec, int flags, int minusp) -{ - int len = 0; - int i; - - /* given precision, ignore zero flag */ - if(prec != -1) - flags &= ~zero_flag; - else - prec = 1; - /* zero value with zero precision -> "" */ - if(prec == 0 && num == 0) - return 0; - do{ - if((*state->append_char)(state, rep[num % base])) - return 1; - len++; - num /= base; - }while(num); - prec -= len; - /* pad with prec zeros */ - while(prec-- > 0){ - if((*state->append_char)(state, '0')) - return 1; - len++; - } - /* add length of alternate prefix (added later) to len */ - if(flags & alternate_flag && (base == 16 || base == 8)) - len += base / 8; - /* pad with zeros */ - if(flags & zero_flag){ - width -= len; - if(minusp || (flags & space_flag) || (flags & plus_flag)) - width--; - while(width-- > 0){ - if((*state->append_char)(state, '0')) - return 1; - len++; - } - } - /* add alternate prefix */ - if(flags & alternate_flag && (base == 16 || base == 8)){ - if(base == 16) - if((*state->append_char)(state, rep[10] + 23)) /* XXX */ - return 1; - if((*state->append_char)(state, '0')) - return 1; - } - /* add sign */ - if(minusp){ - if((*state->append_char)(state, '-')) - return 1; - len++; - } else if(flags & plus_flag) { - if((*state->append_char)(state, '+')) - return 1; - len++; - } else if(flags & space_flag) { - if((*state->append_char)(state, ' ')) - return 1; - len++; - } - if(flags & minus_flag) - /* swap before padding with spaces */ - for(i = 0; i < len / 2; i++){ - char c = state->s[-i-1]; - state->s[-i-1] = state->s[-len+i]; - state->s[-len+i] = c; - } - width -= len; - while(width-- > 0){ - if((*state->append_char)(state, ' ')) - return 1; - len++; - } - if(!(flags & minus_flag)) - /* swap after padding with spaces */ - for(i = 0; i < len / 2; i++){ - char c = state->s[-i-1]; - state->s[-i-1] = state->s[-len+i]; - state->s[-len+i] = c; - } - - return 0; -} - -static int -append_string (struct state *state, - unsigned char *arg, - int width, - int prec, - int flags) -{ - if(prec != -1) - width -= prec; - else - width -= strlen((char *)arg); - if(!(flags & minus_flag)) - while(width-- > 0) - if((*state->append_char) (state, ' ')) - return 1; - if (prec != -1) { - while (*arg && prec--) - if ((*state->append_char) (state, *arg++)) - return 1; - } else { - while (*arg) - if ((*state->append_char) (state, *arg++)) - return 1; - } - if(flags & minus_flag) - while(width-- > 0) - if((*state->append_char) (state, ' ')) - return 1; - return 0; -} - -static int -append_char(struct state *state, - unsigned char arg, - int width, - int flags) -{ - while(!(flags & minus_flag) && --width > 0) - if((*state->append_char) (state, ' ')) - return 1; - - if((*state->append_char) (state, arg)) - return 1; - while((flags & minus_flag) && --width > 0) - if((*state->append_char) (state, ' ')) - return 1; - - return 0; -} - -/* - * This can't be made into a function... - */ - -#define PARSE_INT_FORMAT(res, arg, unsig) \ -if (long_flag) \ - res = (unsig long)va_arg(arg, unsig long); \ -else if (short_flag) \ - res = (unsig short)va_arg(arg, unsig int); \ -else \ - res = (unsig int)va_arg(arg, unsig int) - -/* - * zyxprintf - return 0 or -1 - */ - -static int -xyzprintf (struct state *state, const char *char_format, va_list ap) -{ - const unsigned char *format = (const unsigned char *)char_format; - unsigned char c; - - while((c = *format++)) { - if (c == '%') { - int flags = 0; - int width = 0; - int prec = -1; - int long_flag = 0; - int short_flag = 0; - - /* flags */ - while((c = *format++)){ - if(c == '-') - flags |= minus_flag; - else if(c == '+') - flags |= plus_flag; - else if(c == ' ') - flags |= space_flag; - else if(c == '#') - flags |= alternate_flag; - else if(c == '0') - flags |= zero_flag; - else - break; - } - - if((flags & space_flag) && (flags & plus_flag)) - flags ^= space_flag; - - if((flags & minus_flag) && (flags & zero_flag)) - flags ^= zero_flag; - - /* width */ - if (isdigit(c)) - do { - width = width * 10 + c - '0'; - c = *format++; - } while(isdigit(c)); - else if(c == '*') { - width = va_arg(ap, int); - c = *format++; - } - - /* precision */ - if (c == '.') { - prec = 0; - c = *format++; - if (isdigit(c)) - do { - prec = prec * 10 + c - '0'; - c = *format++; - } while(isdigit(c)); - else if (c == '*') { - prec = va_arg(ap, int); - c = *format++; - } - } - - /* size */ - - if (c == 'h') { - short_flag = 1; - c = *format++; - } else if (c == 'l') { - long_flag = 1; - c = *format++; - } - - switch (c) { - case 'c' : - if(append_char(state, va_arg(ap, int), width, flags)) - return -1; - break; - case 's' : - if (append_string(state, - va_arg(ap, unsigned char*), - width, - prec, - flags)) - return -1; - break; - case 'd' : - case 'i' : { - long arg; - unsigned long num; - int minusp = 0; - - PARSE_INT_FORMAT(arg, ap, signed); - - if (arg < 0) { - minusp = 1; - num = -arg; - } else - num = arg; - - if (append_number (state, num, 10, "0123456789", - width, prec, flags, minusp)) - return -1; - break; - } - case 'u' : { - unsigned long arg; - - PARSE_INT_FORMAT(arg, ap, unsigned); - - if (append_number (state, arg, 10, "0123456789", - width, prec, flags, 0)) - return -1; - break; - } - case 'o' : { - unsigned long arg; - - PARSE_INT_FORMAT(arg, ap, unsigned); - - if (append_number (state, arg, 010, "01234567", - width, prec, flags, 0)) - return -1; - break; - } - case 'x' : { - unsigned long arg; - - PARSE_INT_FORMAT(arg, ap, unsigned); - - if (append_number (state, arg, 0x10, "0123456789abcdef", - width, prec, flags, 0)) - return -1; - break; - } - case 'X' :{ - unsigned long arg; - - PARSE_INT_FORMAT(arg, ap, unsigned); - - if (append_number (state, arg, 0x10, "0123456789ABCDEF", - width, prec, flags, 0)) - return -1; - break; - } - case 'p' : { - unsigned long arg = (unsigned long)va_arg(ap, void*); - - if (append_number (state, arg, 0x10, "0123456789ABCDEF", - width, prec, flags, 0)) - return -1; - break; - } - case 'n' : { - int *arg = va_arg(ap, int*); - *arg = state->s - state->str; - break; - } - case '\0' : - --format; - /* FALLTHROUGH */ - case '%' : - if ((*state->append_char)(state, c)) - return -1; - break; - default : - if ( (*state->append_char)(state, '%') - || (*state->append_char)(state, c)) - return -1; - break; - } - } else - if ((*state->append_char) (state, c)) - return -1; - } - return 0; -} - -#ifndef HAVE_SNPRINTF -int -snprintf (char *str, size_t sz, const char *format, ...) -{ - va_list args; - int ret; - - va_start(args, format); - ret = vsnprintf (str, sz, format, args); - -#ifdef PARANOIA - { - int ret2; - char *tmp; - - tmp = malloc (sz); - if (tmp == NULL) - abort (); - - ret2 = vsprintf (tmp, format, args); - if (ret != ret2 || strcmp(str, tmp)) - abort (); - free (tmp); - } -#endif - - va_end(args); - return ret; -} -#endif - -#if 0 -#ifndef HAVE_ASPRINTF -int -asprintf (char **ret, const char *format, ...) -{ - va_list args; - int val; - - va_start(args, format); - val = vasprintf (ret, format, args); - -#ifdef PARANOIA - { - int ret2; - char *tmp; - tmp = malloc (val + 1); - if (tmp == NULL) - abort (); - - ret2 = vsprintf (tmp, format, args); - if (val != ret2 || strcmp(*ret, tmp)) - abort (); - free (tmp); - } -#endif - - va_end(args); - return val; -} -#endif - -#ifndef HAVE_ASNPRINTF -int -asnprintf (char **ret, size_t max_sz, const char *format, ...) -{ - va_list args; - int val; - - va_start(args, format); - val = vasnprintf (ret, max_sz, format, args); - -#ifdef PARANOIA - { - int ret2; - char *tmp; - tmp = malloc (val + 1); - if (tmp == NULL) - abort (); - - ret2 = vsprintf (tmp, format, args); - if (val != ret2 || strcmp(*ret, tmp)) - abort (); - free (tmp); - } -#endif - - va_end(args); - return val; -} -#endif - -#ifndef HAVE_VASPRINTF -int -vasprintf (char **ret, const char *format, va_list args) -{ - return vasnprintf (ret, 0, format, args); -} -#endif - - -#ifndef HAVE_VASNPRINTF -int -vasnprintf (char **ret, size_t max_sz, const char *format, va_list args) -{ - int st; - size_t len; - struct state state; - - state.max_sz = max_sz; - state.sz = 1; - state.str = malloc(state.sz); - if (state.str == NULL) { - *ret = NULL; - return -1; - } - state.s = state.str; - state.theend = state.s + state.sz - 1; - state.append_char = as_append_char; - state.reserve = as_reserve; - - st = xyzprintf (&state, format, args); - if (st) { - free (state.str); - *ret = NULL; - return -1; - } else { - char *tmp; - - *state.s = '\0'; - len = state.s - state.str; - tmp = realloc (state.str, len+1); - if (tmp == NULL) { - free (state.str); - *ret = NULL; - return -1; - } - *ret = tmp; - return len; - } -} -#endif -#endif - -#ifndef HAVE_VSNPRINTF -int -vsnprintf (char *str, size_t sz, const char *format, va_list args) -{ - struct state state; - int ret; - unsigned char *ustr = (unsigned char *)str; - - state.max_sz = 0; - state.sz = sz; - state.str = ustr; - state.s = ustr; - state.theend = ustr + sz - 1; - state.append_char = sn_append_char; - state.reserve = sn_reserve; - - ret = xyzprintf (&state, format, args); - *state.s = '\0'; - if (ret) - return sz; - else - return state.s - state.str; -} -#endif - |