]> The Tcpdump Group git mirrors - libpcap/commitdiff
Handle NetBSD DLT_HDLC.
authorGuy Harris <[email protected]>
Tue, 21 Dec 2021 08:35:05 +0000 (00:35 -0800)
committerGuy Harris <[email protected]>
Tue, 21 Dec 2021 08:35:05 +0000 (00:35 -0800)
We'd reserved LINKTYPE_HDLC for it; we rename that to
LINKTYPE_NETBSD_HDLC, define DLT_HDLC as 16 on NetBSD (that's the value
they use) and as the same value as LINKTYPE_NETBSD_HDLC on others, so
it's at least defined everywhere, map between DLT_HDLC and
LINKTYPE_NETBSD_HDLC in capture files, and make sure we treat DLT_C_HDLC
and DLT_HDLC the same (as NetBSD appears to use DLT_HDLC for Cisco
HDLC).

Also, expand some comments.

gencode.c
pcap-common.c
pcap/dlt.h

index aef078e2533de458564c784f277164d32a10aae6..703bb20e2ca86171d6c6e69e2c07aa7454cde698 100644 (file)
--- a/gencode.c
+++ b/gencode.c
@@ -1268,6 +1268,7 @@ init_linktype(compiler_state_t *cstate, pcap_t *p)
        case DLT_PPP:
        case DLT_PPP_PPPD:
        case DLT_C_HDLC:                /* BSD/OS Cisco HDLC */
+       case DLT_HDLC:                  /* NetBSD (Cisco) HDLC */
        case DLT_PPP_SERIAL:            /* NetBSD sync/async serial PPP */
                cstate->off_linktype.constant_part = 2; /* skip HDLC-like framing */
                cstate->off_linkpl.constant_part = 4;   /* skip HDLC-like framing and protocol field */
@@ -3170,6 +3171,7 @@ gen_linktype(compiler_state_t *cstate, bpf_u_int32 ll_proto)
                /*NOTREACHED*/
 
        case DLT_C_HDLC:
+       case DLT_HDLC:
                switch (ll_proto) {
 
                case LLCSAP_ISONS:
@@ -6554,6 +6556,7 @@ gen_proto(compiler_state_t *cstate, bpf_u_int32 v, int proto, int dir)
                        /*NOTREACHED*/
 
                case DLT_C_HDLC:
+               case DLT_HDLC:
                        /*
                         * Cisco uses an Ethertype lookalike - for OSI,
                         * it's 0xfefe.
@@ -9099,6 +9102,7 @@ gen_mpls(compiler_state_t *cstate, bpf_u_int32 label_num_arg,
             switch (cstate->linktype) {
 
             case DLT_C_HDLC: /* fall through */
+            case DLT_HDLC:
             case DLT_EN10MB:
             case DLT_NETANALYZER:
             case DLT_NETANALYZER_TRANSPARENT:
index ffefe5ac8c5781bc7b0f2fc045c7b5c486f910bb..0f5e94510c2a3954a6741f18e592afe7eb36e297 100644 (file)
 #define LINKTYPE_ENC           109             /* OpenBSD IPSEC enc */
 
 /*
- * These three types are reserved for future use.
+ * These two types are reserved for future use.
  */
 #define LINKTYPE_LANE8023      110             /* ATM LANE + 802.3 */
 #define LINKTYPE_HIPPI         111             /* NetBSD HIPPI */
-#define LINKTYPE_HDLC          112             /* NetBSD HDLC framing */
+
+/*
+ * Used for NetBSD DLT_HDLC; from looking at the one driver in NetBSD
+ * that uses it, it's Cisco HDLC, so it's the same as DLT_C_HDLC/
+ * LINKTYPE_C_HDLC, but we define a separate value to avoid some
+ * compatibility issues with programs on NetBSD.
+ *
+ * All code should treat LINKTYPE_NETBSD_HDLC and LINKTYPE_C_HDLC the same.
+ */
+#define LINKTYPE_NETBSD_HDLC   112             /* NetBSD HDLC framing */
 
 #define LINKTYPE_LINUX_SLL     113             /* Linux cooked socket capture */
 #define LINKTYPE_LTALK         114             /* Apple LocalTalk hardware */
@@ -1264,6 +1273,7 @@ static struct linktype_map {
        { DLT_RAW,              LINKTYPE_RAW },
        { DLT_SLIP_BSDOS,       LINKTYPE_SLIP_BSDOS },
        { DLT_PPP_BSDOS,        LINKTYPE_PPP_BSDOS },
+       { DLT_HDLC,             LINKTYPE_NETBSD_HDLC },
 
        /* BSD/OS Cisco HDLC */
        { DLT_C_HDLC,           LINKTYPE_C_HDLC },
index d3229441e87fc94d87adf4c1ed88b7913cb5ee5f..80af832687a851a9380941a78e083561a722ee5a 100644 (file)
 #define DLT_PPP_BSDOS  16      /* BSD/OS Point-to-point Protocol */
 #endif
 
+/*
+ * NetBSD uses 15 for HIPPI.
+ * 
+ * From a quick look at sys/net/if_hippi.h and sys/net/if_hippisubr.c
+ * in an older version of NetBSD , the header appears to be:
+ *
+ *     a 1-byte ULP field (ULP-id)?
+ *
+ *     a 1-byte flags field;
+ *
+ *     a 2-byte "offsets" field;
+ *
+ *     a 4-byte "D2 length" field (D2_Size?);
+ *
+ *     a 4-byte "destination switch" field (or a 1-byte field
+ *     containing the Forwarding Class, Double_Wide, and Message_Type
+ *     sub fields, followed by a 3-byte Destination_Switch_Address
+ *     field?, HIPPI-LE 3.4-style?);
+ *
+ *     a 4-byte "source switch" field (or a 1-byte field containing the
+ *     Destination_Address_type and Source_Address_Type fields, followed
+ *     by a 3-byte Source_Switch_Address field, HIPPI-LE 3.4-style?);
+ *
+ *     a 2-byte reserved field;
+ *
+ *     a 6-byte destination address field;
+ *
+ *     a 2-byte "local admin" field;
+ *
+ *     a 6-byte source address field;
+ *
+ * followed by an 802.2 LLC header.
+ *
+ * This looks somewhat like something derived from the HIPPI-FP 4.4
+ * Header_Area, followed an HIPPI-FP 4.4 D1_Area containing a D1 data set
+ * with the header in HIPPI-LE 3.4 (ANSI X3.218-1993), followed by an
+ * HIPPI-FP 4.4 D2_Area (with no Offset) containing the 802.2 LLC header
+ * and payload?  Or does the "offsets" field contain the D2_Offset,
+ * with that many bytes of offset before the payload?
+ *
+ * See http://wotug.org/parallel/standards/hippi/ for an archive of
+ * HIPPI specifications.
+ *
+ * HIPPI is long-gone, and the source files found in an older version
+ * of NetBSD don't appear to be in the main CVS branch, so we may never
+ * see a capture with this link-layer type.
+ */
+#if defined(__NetBSD__)
+#define DLT_HIPPI      15      /* HIPPI */
+#endif
+
+/*
+ * NetBSD uses 16 for DLT_HDLC; see below.
+ * BSD/OS uses it for PPP; see above.
+ * As far as I know, no other OS uses it for anything; don't use it
+ * for anything else.
+ */
+
 /*
  * 17 was used for DLT_PFLOG in OpenBSD; it no longer is.
  *
  * that the AF_ type in the link-layer header is in network byte order.
  *
  * DLT_LOOP is 12 in OpenBSD, but that's DLT_RAW in other OSes, so
- * we don't use 12 for it in OSes other than OpenBSD.
+ * we don't use 12 for it in OSes other than OpenBSD; instead, we
+ * use the same value as LINKTYPE_LOOP.
  */
 #ifdef __OpenBSD__
 #define DLT_LOOP       12
 /*
  * Encapsulated packets for IPsec; DLT_ENC is 13 in OpenBSD, but that's
  * DLT_SLIP_BSDOS in NetBSD, so we don't use 13 for it in OSes other
- * than OpenBSD.
+ * than OpenBSD; instead, we use the same value as LINKTYPE_ENC.
  */
 #ifdef __OpenBSD__
 #define DLT_ENC                13
 #endif
 
 /*
- * Values between 110 and 112 are reserved for use in capture file headers
+ * Values 110 and 111 are reserved for use 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.
  */
 
+/*
+ * NetBSD uses 16 for (Cisco) "HDLC framing".  For other platforms,
+ * we define it to have the same value as LINKTYPE_NETBSD_HDLC.
+ */
+#if defined(__NetBSD__)
+#define DLT_HDLC       16      /* Cisco HDLC */
+#else
+#define DLT_HDLC       112
+#endif
+
 /*
  * Linux cooked sockets.
  */