From: guy Date: Fri, 22 Jun 2007 06:43:58 +0000 (+0000) Subject: From Stephen Donnelly of Endace: X-Git-Tag: libpcap-0.9.7~4 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/03dc37ff028e33355dd006eeee544734b5de1705?ds=sidebyside From Stephen Donnelly of Endace: This patch introduces support for the DAG ERF type TYPE_COLOR_MC_HDLC_POS. The patch also allows appropriate DAG cards (DAG 3.7T, DAG 7.1S) to optionally produce DLT_MTP2_WITH_PHDR (139) traces when capturing from channelised HDLC links, as an alternative to DLT_MTP2 (140). When using the new DLT, the 'DAG channel' is recorded in the pcap record pseudo header as the 'link_number'. Basic BPF filtering support for DLT_MTP2_WITH_PHDR is also added. Fix some warnings. Update the version numbers. Rename SWAP_TS() to SWAPLL() and move it to pcap-int.h, to make the x.9 code more closely match the top-of-tree code. --- diff --git a/VERSION b/VERSION index b0bb8785..c81aa44a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.9.5 +0.9.7 diff --git a/gencode.c b/gencode.c index 51385af2..76a9514b 100644 --- a/gencode.c +++ b/gencode.c @@ -21,7 +21,7 @@ */ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.221.2.51 2007-06-14 20:54:12 gianluca Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.221.2.52 2007-06-22 06:43:58 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -243,7 +243,7 @@ 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(); +static struct block *gen_ppi_dlt_check(void); static struct block *gen_msg_abbrev(int type); static void * @@ -1261,6 +1261,17 @@ 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; @@ -1981,7 +1992,7 @@ insert_ppi_load_llprefixlen(b) } static struct block * -gen_ppi_dlt_check() +gen_ppi_dlt_check(void) { struct slist *s_load_dlt; struct block *b; @@ -6959,14 +6970,16 @@ gen_mtp2type_abbrev(type) switch (type) { case M_FISU: - if (linktype != DLT_MTP2) + 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) + 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); @@ -6974,7 +6987,8 @@ gen_mtp2type_abbrev(type) break; case M_MSU: - if (linktype != DLT_MTP2) + 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; diff --git a/pcap-dag.c b/pcap-dag.c index 07fba144..3da7da59 100644 --- a/pcap-dag.c +++ b/pcap-dag.c @@ -17,7 +17,7 @@ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/libpcap/pcap-dag.c,v 1.21.2.6 2007-02-01 02:59:34 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/pcap-dag.c,v 1.21.2.7 2007-06-22 06:43:58 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -49,6 +49,18 @@ struct rtentry; /* declarations in */ #define ATM_CELL_SIZE 52 #define ATM_HDR_SIZE 4 +/* + * A header containing additional MTP information. + */ +#define MTP2_SENT_OFFSET 0 /* 1 byte */ +#define MTP2_ANNEX_A_USED_OFFSET 1 /* 1 byte */ +#define MTP2_LINK_NUMBER_OFFSET 2 /* 2 bytes */ +#define MTP2_HDR_LEN 4 /* length of the header */ + +#define MTP2_ANNEX_A_NOT_USED 0 +#define MTP2_ANNEX_A_USED 1 +#define MTP2_ANNEX_A_USED_UNKNOWN 2 + /* SunATM pseudo header */ struct sunatm_hdr { unsigned char flags; /* destination and traffic type */ @@ -68,19 +80,6 @@ static const unsigned short endian_test_word = 0x0100; #define IS_BIGENDIAN() (*((unsigned char *)&endian_test_word)) -/* - * Swap byte ordering of unsigned long long timestamp on a big endian - * machine. - */ -#define SWAP_TS(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) - #ifdef DAG_ONLY /* This code is required when compiling for a DAG device only. */ @@ -91,6 +90,10 @@ static const unsigned short endian_test_word = 0x0100; #define dag_platform_finddevs pcap_platform_finddevs #endif /* DAG_ONLY */ +#define MAX_DAG_PACKET 65536 + +static unsigned char TempPkt[MAX_DAG_PACKET]; + static int dag_setfilter(pcap_t *p, struct bpf_program *fp); static int dag_stats(pcap_t *p, struct pcap_stat *ps); static int dag_set_datalink(pcap_t *p, int dlt); @@ -353,6 +356,9 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user) caplen = packet_len; } break; +#ifdef TYPE_COLOR_MC_HDLC_POS + case TYPE_COLOR_MC_HDLC_POS: +#endif #ifdef TYPE_MC_HDLC case TYPE_MC_HDLC: packet_len = ntohs(header->wlen); @@ -361,7 +367,20 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user) if (caplen > packet_len) { caplen = packet_len; } + /* jump the MC_HDLC_HEADER */ dp += 4; + if (p->linktype == DLT_MTP2_WITH_PHDR) { + /* Add the MTP2 Pseudo Header */ + caplen += MTP2_HDR_LEN; + packet_len += MTP2_HDR_LEN; + + TempPkt[MTP2_SENT_OFFSET] = 0; + TempPkt[MTP2_ANNEX_A_USED_OFFSET] = MTP2_ANNEX_A_USED_UNKNOWN; + *(TempPkt+MTP2_LINK_NUMBER_OFFSET) = ((header->rec.mc_hdlc.mc_header>>16)&0x01); + *(TempPkt+MTP2_LINK_NUMBER_OFFSET+1) = ((header->rec.mc_hdlc.mc_header>>24)&0xff); + memcpy(TempPkt+MTP2_HDR_LEN, dp, caplen); + dp = TempPkt; + } break; #endif default: @@ -396,6 +415,10 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user) case TYPE_DSM_COLOR_ETH: break; #endif +#ifdef TYPE_COLOR_MC_HDLC_POS + case TYPE_COLOR_MC_HDLC_POS: + break; +#endif default: if (header->lctr) { @@ -414,7 +437,7 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user) register unsigned long long ts; if (IS_BIGENDIAN()) { - ts = SWAP_TS(header->ts); + ts = SWAPLL(header->ts); } else { ts = header->ts; } @@ -949,6 +972,9 @@ dag_get_datalink(pcap_t *p) p->linktype = DLT_ATM_RFC1483; break; +#ifdef TYPE_COLOR_MC_HDLC_POS + case TYPE_COLOR_MC_HDLC_POS: +#endif #ifdef TYPE_MC_HDLC case TYPE_MC_HDLC: if (p->dlt_list != NULL) { @@ -956,6 +982,7 @@ dag_get_datalink(pcap_t *p) p->dlt_list[index++] = DLT_PPP_SERIAL; p->dlt_list[index++] = DLT_FRELAY; p->dlt_list[index++] = DLT_MTP2; + p->dlt_list[index++] = DLT_MTP2_WITH_PHDR; } if(!p->linktype) p->linktype = DLT_CHDLC; diff --git a/pcap-int.h b/pcap-int.h index eff9cee5..fda836cf 100644 --- a/pcap-int.h +++ b/pcap-int.h @@ -30,7 +30,7 @@ * 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.10 2007-03-11 21:44:51 guy Exp $ (LBL) + * @(#) $Header: /tcpdump/master/libpcap/pcap-int.h,v 1.68.2.11 2007-06-22 06:43:58 guy Exp $ (LBL) */ #ifndef pcap_int_h @@ -51,6 +51,19 @@ extern "C" { #include #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 */ diff --git a/pcap.c b/pcap.c index 6539ea59..44ceb843 100644 --- a/pcap.c +++ b/pcap.c @@ -33,7 +33,7 @@ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.88.2.16 2007-06-11 09:52:05 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.88.2.17 2007-06-22 06:43:58 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -387,6 +387,7 @@ static struct dlt_choice dlt_choices[] = { DLT_CHOICE(DLT_USB, "USB"), DLT_CHOICE(DLT_BLUETOOTH_HCI_H4, "Bluetooth HCI UART transport layer"), DLT_CHOICE(DLT_CAN20B, "Controller Area Network (CAN) v. 2.0B"), + DLT_CHOICE(DLT_MTP2_WITH_PHDR, "SS7 MTP2 with Pseudo-header"), DLT_CHOICE_SENTINEL }; @@ -816,7 +817,7 @@ pcap_close(pcap_t *p) #ifdef HAVE_VERSION_H #include "version.h" #else -static const char pcap_version_string[] = "libpcap version 0.9.4"; +static const char pcap_version_string[] = "libpcap version 0.9.7"; #endif #ifdef WIN32 @@ -825,7 +826,7 @@ static const char pcap_version_string[] = "libpcap version 0.9.4"; * version numbers when building WinPcap. (It'd be nice to do so for * the packet.dll version number as well.) */ -static const char wpcap_version_string[] = "3.2 alpha1"; +static const char wpcap_version_string[] = "4.0"; static const char pcap_version_string_fmt[] = "WinPcap version %s, based on %s"; static const char pcap_version_string_packet_dll_fmt[] =