]> The Tcpdump Group git mirrors - libpcap/commitdiff
From Shaun <[email protected]>: on AIX, load the BPF driver and
authorguy <guy>
Tue, 11 Feb 2003 01:46:05 +0000 (01:46 +0000)
committerguy <guy>
Tue, 11 Feb 2003 01:46:05 +0000 (01:46 +0000)
create the BPF device nodes if necessary, and rename our "bpf.h" to
"pcap-bpf.h" and install it in "/usr/include", so that "pcap-bpf.c" gets
the system's bpf.h file if it includes <net/bpf.h> - on AIX, it needs to
get an AIX-specific structure from that header in order to support
loading the driver and creating the nodes.

Update "packaging/pcap.spec".

CREDITS
FILES
Makefile.in
bpf/net/bpf_filter.c
packaging/pcap.spec
pcap-bpf.c
pcap-bpf.h [moved from bpf/net/bpf.h with 81% similarity]
pcap-enet.c
pcap.h

diff --git a/CREDITS b/CREDITS
index ee26f8c79f0b220763ac669f9aa965ed4156600b..1f16f69e33588e7c60f3fbc48fe1117955dd3631 100644 (file)
--- a/CREDITS
+++ b/CREDITS
@@ -60,6 +60,7 @@ Additional people who have contributed patches:
        Rick Jones                      <[email protected]>
        Scott Barron                    <[email protected]>
        Scott Gifford                   <[email protected]>
+       Shaun                           <[email protected]>
        Solomon Peachy                  <[email protected]>
        Stefan Hudson                   <[email protected]>
        Tony Li                         <[email protected]>
diff --git a/FILES b/FILES
index 18a14a09c8b54c96d1e2b4ac6567d62f5a496761..ff0ef9896ef0262cbcb4ae67b3647a5fd6c73961 100644 (file)
--- a/FILES
+++ b/FILES
@@ -16,7 +16,6 @@ VERSION
 aclocal.m4
 arcnet.h
 atmuni31.h
-bpf/net/bpf.h
 bpf/net/bpf_filter.c
 bpf_dump.c
 bpf_image.c
@@ -50,6 +49,7 @@ nametoaddr.c
 nlpid.h
 optimize.c
 pcap-bpf.c
+pcap-bpf.h
 pcap-dlpi.c
 pcap-enet.c
 pcap-int.h
index cfd5c4cce0ec99e6ba65246bd10aa8c575ceee40..0b94eb1dab1c5713ac5c8e1c7adac9bc0b452531 100644 (file)
@@ -17,7 +17,7 @@
 #  WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 #  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 #
-# @(#) $Header: /tcpdump/master/libpcap/Makefile.in,v 1.89 2002-07-27 18:45:34 guy Exp $ (LBL)
+# @(#) $Header: /tcpdump/master/libpcap/Makefile.in,v 1.90 2003-02-11 01:46:05 guy Exp $ (LBL)
 
 #
 # Various configurable paths (remember to edit Makefile.in, not Makefile)
@@ -87,7 +87,7 @@ GENHDR = \
        tokdefs.h
 
 TAGHDR = \
-       bpf/net/bpf.h
+       pcap-bpf.h
 
 TAGFILES = \
        $(SRC) $(HDR) $(TAGHDR)
@@ -144,12 +144,10 @@ install:
        [ -d $(DESTDIR)$(includedir) ] || \
            (mkdir -p $(DESTDIR)$(includedir); chmod 755 $(DESTDIR)$(includedir))
        $(INSTALL_DATA) $(srcdir)/pcap.h $(DESTDIR)$(includedir)/pcap.h
+       $(INSTALL_DATA) $(srcdir)/pcap-bpf.h \
+           $(DESTDIR)$(includedir)/pcap-bpf.h
        $(INSTALL_DATA) $(srcdir)/pcap-namedb.h \
            $(DESTDIR)$(includedir)/pcap-namedb.h
-       [ -d $(DESTDIR)$(includedir)/net ] || \
-           (mkdir -p $(DESTDIR)$(includedir)/net; chmod 755 $(DESTDIR)$(includedir)/net)
-       $(INSTALL_DATA) $(srcdir)/bpf/net/bpf.h \
-           $(DESTDIR)$(includedir)/net/bpf.h
        [ -d $(DESTDIR)$(mandir)/man3 ] || \
                (mkdir -p $(DESTDIR)$(mandir)/man3; chmod 755 $(DESTDIR)$(mandir)/man3)
        $(INSTALL_DATA) $(srcdir)/pcap.3 \
@@ -158,8 +156,8 @@ install:
 uninstall:
        rm -f $(DESTDIR)$(libdir)/libpcap.a
        rm -f $(DESTDIR)$(includedir)/pcap.h
+       rm -f $(DESTDIR)$(includedir)/pcap-bpf.h
        rm -f $(DESTDIR)$(includedir)/pcap-namedb.h
-       rm -f $(DESTDIR)$(includedir)/net/bpf.h
        rm -f $(DESTDIR)$(mandir)/man3/pcap.3
 
 clean:
@@ -167,7 +165,7 @@ clean:
 
 distclean:
        rm -f $(CLEANFILES) Makefile config.cache config.log config.status \
-           config.h gnuc.h os-proto.h net bpf_filter.c stamp-h stamp-h.in
+           config.h gnuc.h os-proto.h bpf_filter.c stamp-h stamp-h.in
 
 tags: $(TAGFILES)
        ctags -wtd $(TAGFILES)
index 5534f623085f9ec1e52de67bacfbc20cc9195ed4..2de7e528a3b700fb449106feef9197ff47a4db1d 100644 (file)
@@ -40,7 +40,7 @@
 
 #if !(defined(lint) || defined(KERNEL) || defined(_KERNEL))
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/libpcap/bpf/net/bpf_filter.c,v 1.40 2003-01-10 09:15:18 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/bpf/net/bpf_filter.c,v 1.41 2003-02-11 01:46:07 guy Exp $ (LBL)";
 #endif
 
 #ifdef WIN32
@@ -67,7 +67,7 @@ static const char rcsid[] =
 
 #endif /* WIN32 */
 
-#include <net/bpf.h>
+#include <pcap-bpf.h>
 
 #if !defined(KERNEL) && !defined(_KERNEL)
 #include <stdlib.h>
index e550adce675c6698e091ed6638826053e9350755..7ec8516e204314d568990f97e4c89e3d2f0d673a 100644 (file)
@@ -1,5 +1,5 @@
 %define prefix   /usr
-%define version 2001.02.22 
+%define version 2003.02.10
 
 Summary: packet capture library
 Name: libpcap
@@ -12,7 +12,7 @@ BuildRoot: /tmp/%{name}-buildroot
 URL: http://www.tcpdump.org
 
 %description
-Packet-capture library LIBPCAP 0.5
+Packet-capture library LIBPCAP 0.8
 Now maintained by "The Tcpdump Group"
 See http://www.tcpdump.org
 Please send inquiries/comments/reports to [email protected]
@@ -35,8 +35,8 @@ mkdir -p $RPM_BUILD_ROOT/usr/man/man3
 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
-install -m 644 -o root net/bpf.h $RPM_BUILD_ROOT/usr/include/net
 
 %clean
 rm -rf $RPM_BUILD_ROOT
@@ -46,5 +46,5 @@ rm -rf $RPM_BUILD_ROOT
 %doc LICENSE CHANGES INSTALL README.linux TODO VERSION CREDITS pcap.spec
 /usr/lib/libpcap.a
 /usr/include/pcap.h
+/usr/include/pcap-bpf.h
 /usr/include/pcap-namedb.h
-/usr/include/net/bpf.h
index 0a46f04b2b17c515b4bb9bfc2f1db075f1db8cd1..b3972815c7852c8ab09bec6a5e313315e5efcf13 100644 (file)
@@ -20,7 +20,7 @@
  */
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.55 2002-12-22 02:36:48 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.56 2003-02-11 01:46:05 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -35,9 +35,53 @@ static const char rcsid[] =
 #include <sys/ioctl.h>
 
 #include <net/if.h>
+
 #ifdef _AIX
+
+/*
+ * Make "pcap.h" not include "pcap-bpf.h"; we are going to include the
+ * native OS version, as we need "struct bpf_config" from it.
+ */
+#define PCAP_DONT_INCLUDE_PCAP_BPF_H
+
+#include <sys/types.h>
+
+/*
+ * Prevent bpf.h from redefining the DLT_ values to their
+ * IFT_ values, as we're going to return the standard libpcap
+ * values, not IBM's non-standard IFT_ values.
+ */
+#undef _AIX
+#include <net/bpf.h>
+#define _AIX
+
 #include <net/if_types.h>              /* for IFT_ values */
-#endif
+#include <sys/sysconfig.h>
+#include <sys/device.h>
+#include <odmi.h>
+#include <cf.h>
+
+#ifdef __64BIT__
+#define domakedev makedev64
+#define getmajor major64
+#define bpf_hdr bpf_hdr32
+#else /* __64BIT__ */
+#define domakedev makedev
+#define getmajor major
+#endif /* __64BIT__ */
+
+#define BPF_NAME "bpf"
+#define BPF_MINORS 4
+#define DRIVER_PATH "/usr/lib/drivers"
+#define BPF_NODE "/dev/bpf"
+static int bpfloadedflag = 0;
+static int odmlockid = 0;
+
+#else /* _AIX */
+
+#include <net/bpf.h>
+
+#endif /* _AIX */
 
 #include <ctype.h>
 #include <errno.h>
@@ -188,6 +232,143 @@ pcap_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
        return (n);
 }
 
+#ifdef _AIX
+static int 
+bpf_odminit(char *errbuf)
+{
+       if (odm_initialize() == -1) {
+               snprintf(errbuf, PCAP_ERRBUF_SIZE,
+                   "bpf_load: odm_initialize failed: %s",
+                   pcap_strerror(errno));
+               return (-1);
+       }
+
+       if ((odmlockid = odm_lock("/etc/objrepos/config_lock", ODM_WAIT)) == -1) {
+               snprintf(errbuf, PCAP_ERRBUF_SIZE,
+                   "bpf_load: odm_lock of /etc/objrepos/config_lock failed: %s",
+                   pcap_strerror(errno));
+               return (-1);
+       }
+
+       return (0);
+}
+
+static int 
+bpf_odmcleanup(char *errbuf)
+{
+       if (odm_unlock(odmlockid) == -1) {
+               snprintf(errbuf, PCAP_ERRBUF_SIZE,
+                   "bpf_load: odm_unlock failed: %s",
+                   pcap_strerror(errno));
+               return (-1);
+       }
+
+       odm_terminate();
+
+       return (0);
+}
+
+static int
+bpf_load(char *errbuf)
+{
+       long major;
+       int *minors;
+       int numminors, i, rc;
+       char buf[1024];
+       struct stat sbuf;
+       struct bpf_config cfg_bpf;
+       struct cfg_load cfg_ld;
+       struct cfg_kmod cfg_km;
+
+       /*
+        * This is very very close to what happens in the real implementation
+        * but I've fixed some (unlikely) bug situations.
+        */
+       if (bpfloadedflag)
+               return (0);
+
+       if (bpf_odminit(errbuf) != 0)
+               return (-1);
+
+       major = genmajor(BPF_NAME);
+       if (major == -1) {
+               snprintf(errbuf, PCAP_ERRBUF_SIZE,
+                   "bpf_load: genmajor failed: %s", pcap_strerror(errno));
+               return (-1);
+       }
+
+       minors = getminor(major, &numminors, BPF_NAME);
+       if (!minors) {
+               minors = genminor("bpf", major, 0, BPF_MINORS, 1, 1);
+               if (!minors) {
+                       snprintf(errbuf, PCAP_ERRBUF_SIZE,
+                           "bpf_load: genminor failed: %s",
+                           pcap_strerror(errno));
+                       return (-1);
+               }
+
+       }
+
+       if (bpf_odmcleanup(errbuf))
+               return (-1);
+
+       rc = stat(BPF_NODE "0", &sbuf);
+       if (rc == -1 && errno != ENOENT) {
+               snprintf(errbuf, PCAP_ERRBUF_SIZE,
+                   "bpf_load: can't stat %s: %s",
+                   BPF_NODE "0", pcap_strerror(errno));
+               return (-1);
+       }
+
+       if (rc == -1 || getmajor(sbuf.st_rdev) != major) {
+               for (i = 0; i < BPF_MINORS; i++) {
+                       sprintf(buf, "%s%d", BPF_NODE, i);
+                       unlink(buf);
+                       if (mknod(buf, S_IRUSR | S_IFCHR, domakedev(major, i)) == -1) {
+                               snprintf(errbuf, PCAP_ERRBUF_SIZE,
+                                   "bpf_load: can't mknod %s: %s",
+                                   buf pcap_strerror(errno));
+                               return (-1);
+                       }
+               }
+       }
+
+       /* Check if the driver is loaded */
+       memset(&cfg_ld, 0x0, sizeof(cfg_ld));
+       cfg_ld.path = buf;
+       sprintf(cfg_ld.path, "%s/%s", DRIVER_PATH, BPF_NAME);
+       if (sysconfig(SYS_QUERYLOAD, (void *) &cfg_ld, sizeof(cfg_ld) == -1) ||
+           (cfg_ld.kmid == 0)) {
+               /* Driver isn't loaded, load it now */
+               if (sysconfig(SYS_SINGLELOAD, (void *) &cfg_ld, sizeof(cfg_ld)) == -1) {
+                       snprintf(errbuf, PCAP_ERRBUF_SIZE,
+                           "bpf_load: could not load driver: %s",
+                           strerror(errno));
+                       return (-1);
+               }
+       }
+
+       /* Configure the driver */
+       cfg_km.cmd = CFG_INIT;
+       cfg_km.kmid = cfg_ld.kmid;
+       cfg_km.mdilen = sizeof(cfg_bpf);
+       cfg_km.mdiptr = (void *) &cfg_bpf; 
+       for (i = 0; i < BPF_MINORS; i++) {
+               cfg_bpf.devno = domakedev(major, i);
+               if (sysconfig(SYS_CFGKMOD, (void *) &cfg_km, sizeof(cfg_km)) == -1) {
+                       snprintf(errbuf, PCAP_ERRBUF_SIZE,
+                           "bpf_load: could not configure driver: %s",
+                           strerror(errno));
+                       return (-1);
+               }
+       }
+       
+       bpfloadedflag = 1;
+
+       return (0);
+}
+#endif
+
 static inline int
 bpf_open(pcap_t *p, char *errbuf)
 {
@@ -195,6 +376,16 @@ bpf_open(pcap_t *p, char *errbuf)
        int n = 0;
        char device[sizeof "/dev/bpf0000000000"];
 
+#ifdef _AIX
+       /*
+        * Load the bpf driver, if it isn't already loaded,
+        * and create the BPF device entries, if they don't
+        * already exist.
+        */
+       if (bpf_load(errbuf) == -1)
+               return (-1);
+#endif
+
        /*
         * Go through all the minors and find one that isn't in use.
         */
similarity index 81%
rename from bpf/net/bpf.h
rename to pcap-bpf.h
index 6d7adcb57cbf2881d2b75ff0f8bcb0b8bcfaa242..f37f9790ae50546420453596bd2583730a0d522d 100644 (file)
  *
  *      @(#)bpf.h       7.1 (Berkeley) 5/7/91
  *
- * @(#) $Header: /tcpdump/master/libpcap/bpf/net/Attic/bpf.h,v 1.67 2003-01-23 07:24:53 guy Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/libpcap/pcap-bpf.h,v 1.1 2003-02-11 01:46:06 guy Exp $ (LBL)
+ */
+
+/*
+ * This is libpcap's cut-down version of bpf.h; it includes only
+ * the stuff needed for the code generator and the userland BPF
+ * interpreter, and the libpcap APIs for setting filters, etc..
+ *
+ * "pcap-bpf.c" will include the native OS version, as it deals with
+ * the OS's BPF implementation.
+ *
+ * XXX - should this all just be moved to "pcap.h"?
  */
 
 #ifndef BPF_MAJOR_VERSION
@@ -68,21 +79,13 @@ typedef     u_int bpf_u_int32;
 #define BPF_MINBUFSIZE 32
 
 /*
- *  Structure for BIOCSETF.
+ * Structure for "pcap_compile()", "pcap_setfilter()", etc..
  */
 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.
@@ -102,66 +105,6 @@ struct bpf_version {
 #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.
  */
@@ -479,23 +422,6 @@ struct bpf_insn {
 #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__ || defined(__cplusplus)
 extern int bpf_validate(struct bpf_insn *, int);
 extern u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int);
index 2e478c457a63465d7591c6efbad24577c6753a87..4458d6ca116a24a6c53c30d364b4dee0f87a1dd5 100644 (file)
@@ -8,7 +8,7 @@
  */
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/libpcap/pcap-enet.c,v 1.6 2002-06-11 17:04:46 itojun Exp $";
+    "@(#) $Header: /tcpdump/master/libpcap/pcap-enet.c,v 1.7 2003-02-11 01:46:06 guy Exp $";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -22,7 +22,7 @@ static const char rcsid[] =
 #include <sys/socket.h>
 
 #include <net/if.h>
-#include <net/bpf.h>
+#include <pcap-bpf.h>
 #include <net/enet.h>
 
 #include <netinet/in.h>
diff --git a/pcap.h b/pcap.h
index 7d4e0ad1f179b2fc2f04b453a1b3381c8eed887e..fbd3907fd17cc00af8ba28bf3b991a712ec639d6 100644 (file)
--- a/pcap.h
+++ b/pcap.h
@@ -31,7 +31,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * @(#) $Header: /tcpdump/master/libpcap/pcap.h,v 1.41 2002-12-22 23:05:53 guy Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/libpcap/pcap.h,v 1.42 2003-02-11 01:46:06 guy Exp $ (LBL)
  */
 
 #ifndef lib_pcap_h
@@ -44,7 +44,9 @@
 #include <sys/time.h>
 #endif /* WIN32 */
 
-#include <net/bpf.h>
+#ifndef PCAP_DONT_INCLUDE_PCAP_BPF_H
+#include <pcap-bpf.h>
+#endif
 
 #include <stdio.h>