X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/ec799d60f6cd3f41041b57efe3963c28dda94d4a..a3d09832c69a1b261d0e1f1fc61d4b14ddd5f4a4:/print-juniper.c diff --git a/print-juniper.c b/print-juniper.c index 55ca1c9c..87bf9e98 100644 --- a/print-juniper.c +++ b/print-juniper.c @@ -1,6 +1,6 @@ /* NetBSD: print-juniper.c,v 1.2 2007/07/24 11:53:45 drochner Exp */ -/* +/* * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code * distributions retain the above copyright notice and this paragraph @@ -16,8 +16,6 @@ */ #ifndef lint -static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/tcpdump/print-juniper.c,v 1.34 2007-08-29 02:31:44 mcr Exp $ (LBL)"; #else __RCSID("NetBSD: print-juniper.c,v 1.3 2007/07/25 06:31:32 dogcow Exp "); #endif @@ -28,7 +26,6 @@ __RCSID("NetBSD: print-juniper.c,v 1.3 2007/07/25 06:31:32 dogcow Exp "); #include -#include #include #include "interface.h" @@ -65,7 +62,7 @@ __RCSID("NetBSD: print-juniper.c,v 1.3 2007/07/25 06:31:32 dogcow Exp "); #define JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE 4 #define JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE 5 -static struct tok juniper_ipsec_type_values[] = { +static const struct tok juniper_ipsec_type_values[] = { { JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE, "ESP ENCR-AUTH" }, { JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE, "ESP ENCR-AH AUTH" }, { JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE, "ESP AUTH" }, @@ -74,7 +71,7 @@ static struct tok juniper_ipsec_type_values[] = { { 0, NULL} }; -static struct tok juniper_direction_values[] = { +static const struct tok juniper_direction_values[] = { { JUNIPER_BPF_IN, "In"}, { JUNIPER_BPF_OUT, "Out"}, { 0, NULL} @@ -87,15 +84,15 @@ enum { JUNIPER_EXT_TLV_IFD_MEDIATYPE = 3, JUNIPER_EXT_TLV_IFL_IDX = 4, JUNIPER_EXT_TLV_IFL_UNIT = 5, - JUNIPER_EXT_TLV_IFL_ENCAPS = 6, - JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE = 7, + JUNIPER_EXT_TLV_IFL_ENCAPS = 6, + JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE = 7, JUNIPER_EXT_TLV_TTP_IFL_ENCAPS = 8 }; /* 1 byte type and 1-byte length */ #define JUNIPER_EXT_TLV_OVERHEAD 2 -struct tok jnx_ext_tlv_values[] = { +static const struct tok jnx_ext_tlv_values[] = { { JUNIPER_EXT_TLV_IFD_IDX, "Device Interface Index" }, { JUNIPER_EXT_TLV_IFD_NAME,"Device Interface Name" }, { JUNIPER_EXT_TLV_IFD_MEDIATYPE, "Device Media Type" }, @@ -107,7 +104,7 @@ struct tok jnx_ext_tlv_values[] = { { 0, NULL } }; -struct tok jnx_flag_values[] = { +static const struct tok jnx_flag_values[] = { { JUNIPER_BPF_EXT, "Ext" }, { JUNIPER_BPF_FILTER, "Filter" }, { JUNIPER_BPF_IIF, "IIF" }, @@ -177,7 +174,7 @@ struct tok jnx_flag_values[] = { #define JUNIPER_IFML_DFC 59 #define JUNIPER_IFML_PICPEER 60 -struct tok juniper_ifmt_values[] = { +static const struct tok juniper_ifmt_values[] = { { JUNIPER_IFML_ETHER, "Ethernet" }, { JUNIPER_IFML_FDDI, "FDDI" }, { JUNIPER_IFML_TOKENRING, "Token-Ring" }, @@ -300,7 +297,7 @@ struct tok juniper_ifmt_values[] = { #define JUNIPER_IFLE_DFC 66 #define JUNIPER_IFLE_PICPEER 67 -struct tok juniper_ifle_values[] = { +static const struct tok juniper_ifle_values[] = { { JUNIPER_IFLE_AGGREGATOR, "Aggregator" }, { JUNIPER_IFLE_ATM_CCC, "CCC over ATM" }, { JUNIPER_IFLE_ATM_CELLRELAY_CCC, "ATM CCC Cell Relay" }, @@ -371,7 +368,7 @@ struct juniper_cookie_table_t { const char *s; /* pic name */ }; -static struct juniper_cookie_table_t juniper_cookie_table[] = { +static const struct juniper_cookie_table_t juniper_cookie_table[] = { #ifdef DLT_JUNIPER_ATM1 { DLT_JUNIPER_ATM1, 4, "ATM1"}, #endif @@ -439,7 +436,7 @@ struct juniper_l2info_t { #define MFR_BE_MASK 0xc0 -static struct tok juniper_protocol_values[] = { +static const struct tok juniper_protocol_values[] = { { JUNIPER_PROTO_NULL, "Null" }, { JUNIPER_PROTO_IPV4, "IPv4" }, { JUNIPER_PROTO_IPV6, "IPv6" }, @@ -486,7 +483,7 @@ juniper_ggsn_print(const struct pcap_pkthdr *h, register const u_char *p) break; #ifdef INET6 case JUNIPER_PROTO_IPV6: - ip6_print(p, l2info.length); + ip6_print(gndo, p, l2info.length); break; #endif /* INET6 */ default: @@ -544,9 +541,9 @@ juniper_es_print(const struct pcap_pkthdr *h, register const u_char *p) if (eflag) { if (!es_type_bundle) { - printf("ES SA, index %u, ttl %u type %s (%u), spi %u, Tunnel %s > %s, length %u\n", + printf("ES SA, index %u, ttl %u type %s (%u), spi %u, Tunnel %s > %s, length %u\n", EXTRACT_16BITS(&ih->sa_index), - ih->ttl, + ih->ttl, tok2str(juniper_ipsec_type_values,"Unknown",ih->type), ih->type, EXTRACT_32BITS(&ih->spi), @@ -554,9 +551,9 @@ juniper_es_print(const struct pcap_pkthdr *h, register const u_char *p) ipaddr_string(&ih->dst_ip), l2info.length); } else { - printf("ES SA, index %u, ttl %u type %s (%u), length %u\n", + printf("ES SA, index %u, ttl %u type %s (%u), length %u\n", EXTRACT_16BITS(&ih->sa_index), - ih->ttl, + ih->ttl, tok2str(juniper_ipsec_type_values,"Unknown",ih->type), ih->type, l2info.length); @@ -647,7 +644,7 @@ juniper_pppoe_print(const struct pcap_pkthdr *h, register const u_char *p) p+=l2info.header_len; /* this DLT contains nothing but raw ethernet frames */ - ether_print(p, l2info.length, l2info.caplen, NULL, NULL); + ether_print(gndo, p, l2info.length, l2info.caplen, NULL, NULL); return l2info.header_len; } #endif @@ -664,7 +661,7 @@ juniper_ether_print(const struct pcap_pkthdr *h, register const u_char *p) p+=l2info.header_len; /* this DLT contains nothing but raw Ethernet frames */ - ether_print(p, l2info.length, l2info.caplen, NULL, NULL); + ether_print(gndo, p, l2info.length, l2info.caplen, NULL, NULL); return l2info.header_len; } #endif @@ -698,7 +695,7 @@ juniper_frelay_print(const struct pcap_pkthdr *h, register const u_char *p) p+=l2info.header_len; /* this DLT contains nothing but raw frame-relay frames */ - fr_print(p, l2info.length); + fr_print(gndo, p, l2info.length); return l2info.header_len; } #endif @@ -715,7 +712,7 @@ juniper_chdlc_print(const struct pcap_pkthdr *h, register const u_char *p) p+=l2info.header_len; /* this DLT contains nothing but raw c-hdlc frames */ - chdlc_print(p, l2info.length); + chdlc_print(gndo, p, l2info.length); return l2info.header_len; } #endif @@ -736,13 +733,13 @@ juniper_pppoe_atm_print(const struct pcap_pkthdr *h, register const u_char *p) extracted_ethertype = EXTRACT_16BITS(p); /* this DLT contains nothing but raw PPPoE frames, * prepended with a type field*/ - if (ethertype_print(extracted_ethertype, + if (ethertype_print(gndo, extracted_ethertype, p+ETHERTYPE_LEN, l2info.length-ETHERTYPE_LEN, l2info.caplen-ETHERTYPE_LEN) == 0) /* ether_type not known, probably it wasn't one */ printf("unknown ethertype 0x%04x", extracted_ethertype); - + return l2info.header_len; } #endif @@ -779,11 +776,11 @@ juniper_mlppp_print(const struct pcap_pkthdr *h, register const u_char *p) return l2info.header_len; #ifdef INET6 case JUNIPER_LSQ_L3_PROTO_IPV6: - ip6_print(p,l2info.length); + ip6_print(gndo, p,l2info.length); return l2info.header_len; #endif case JUNIPER_LSQ_L3_PROTO_MPLS: - mpls_print(p,l2info.length); + mpls_print(gndo, p, l2info.length); return l2info.header_len; case JUNIPER_LSQ_L3_PROTO_ISO: isoclns_print(p,l2info.length,l2info.caplen); @@ -817,12 +814,12 @@ juniper_mfr_print(const struct pcap_pkthdr *h, register const u_char *p) l2info.pictype = DLT_JUNIPER_MFR; if(juniper_parse_header(p, h, &l2info) == 0) return l2info.header_len; - + p+=l2info.header_len; /* child-link ? */ if (l2info.cookie_len == 0) { - mfr_print(p,l2info.length); + mfr_print(gndo, p, l2info.length); return l2info.header_len; } @@ -834,11 +831,11 @@ juniper_mfr_print(const struct pcap_pkthdr *h, register const u_char *p) return l2info.header_len; #ifdef INET6 case JUNIPER_LSQ_L3_PROTO_IPV6: - ip6_print(p,l2info.length); + ip6_print(gndo, p,l2info.length); return l2info.header_len; #endif case JUNIPER_LSQ_L3_PROTO_MPLS: - mpls_print(p,l2info.length); + mpls_print(gndo, p, l2info.length); return l2info.header_len; case JUNIPER_LSQ_L3_PROTO_ISO: isoclns_print(p,l2info.length,l2info.caplen); @@ -859,7 +856,7 @@ juniper_mfr_print(const struct pcap_pkthdr *h, register const u_char *p) case (LLC_UI<<8 | NLPID_IP): case (LLC_UI<<8 | NLPID_IP6): /* pass IP{4,6} to the OSI layer for proper link-layer printing */ - isoclns_print(p-1, l2info.length+1, l2info.caplen+1); + isoclns_print(p-1, l2info.length+1, l2info.caplen+1); break; default: printf("unknown protocol 0x%04x, length %u",l2info.proto, l2info.length); @@ -925,14 +922,14 @@ juniper_atm1_print(const struct pcap_pkthdr *h, register const u_char *p) p+=l2info.header_len; if (l2info.cookie[0] == 0x80) { /* OAM cell ? */ - oam_print(p,l2info.length,ATM_OAM_NOHEC); + oam_print(gndo, p, l2info.length, ATM_OAM_NOHEC); return l2info.header_len; } if (EXTRACT_24BITS(p) == 0xfefe03 || /* NLPID encaps ? */ EXTRACT_24BITS(p) == 0xaaaa03) { /* SNAP encaps ? */ - if (llc_print(p, l2info.length, l2info.caplen, NULL, NULL, + if (llc_print(gndo, p, l2info.length, l2info.caplen, NULL, NULL, &extracted_ethertype) != 0) return l2info.header_len; } @@ -973,21 +970,21 @@ juniper_atm2_print(const struct pcap_pkthdr *h, register const u_char *p) p+=l2info.header_len; if (l2info.cookie[7] & ATM2_PKT_TYPE_MASK) { /* OAM cell ? */ - oam_print(p,l2info.length,ATM_OAM_NOHEC); + oam_print(gndo, p, l2info.length, ATM_OAM_NOHEC); return l2info.header_len; } if (EXTRACT_24BITS(p) == 0xfefe03 || /* NLPID encaps ? */ EXTRACT_24BITS(p) == 0xaaaa03) { /* SNAP encaps ? */ - if (llc_print(p, l2info.length, l2info.caplen, NULL, NULL, + if (llc_print(gndo, p, l2info.length, l2info.caplen, NULL, NULL, &extracted_ethertype) != 0) return l2info.header_len; } if (l2info.direction != JUNIPER_BPF_PKT_IN && /* ether-over-1483 encaps ? */ (EXTRACT_32BITS(l2info.cookie) & ATM2_GAP_COUNT_MASK)) { - ether_print(p, l2info.length, l2info.caplen, NULL, NULL); + ether_print(gndo, p, l2info.length, l2info.caplen, NULL, NULL); return l2info.header_len; } @@ -1073,7 +1070,7 @@ ip_heuristic_guess(register const u_char *p, u_int length) { case 0x6d: case 0x6e: case 0x6f: - ip6_print(p, length); + ip6_print(gndo, p, length); break; #endif default: @@ -1133,7 +1130,7 @@ juniper_read_tlv_value(const u_char *p, u_int tlv_type, u_int tlv_len) { static int juniper_parse_header (const u_char *p, const struct pcap_pkthdr *h, struct juniper_l2info_t *l2info) { - struct juniper_cookie_table_t *lp = juniper_cookie_table; + const struct juniper_cookie_table_t *lp = juniper_cookie_table; u_int idx, jnx_ext_len, jnx_header_len = 0; u_int8_t tlv_type,tlv_len; u_int32_t control_word; @@ -1151,11 +1148,11 @@ juniper_parse_header (const u_char *p, const struct pcap_pkthdr *h, struct junip TCHECK2(p[0],4); l2info->flags = p[3]; l2info->direction = p[3]&JUNIPER_BPF_PKT_IN; - + if (EXTRACT_24BITS(p) != JUNIPER_MGC_NUMBER) { /* magic number found ? */ printf("no magic-number found!"); return 0; - } + } if (eflag) /* print direction */ printf("%3s ",tok2str(juniper_direction_values,"---",l2info->direction)); @@ -1177,32 +1174,32 @@ juniper_parse_header (const u_char *p, const struct pcap_pkthdr *h, struct junip jnx_ext_len = EXTRACT_16BITS(tptr); jnx_header_len += 2; tptr +=2; - + /* nail up the total length - * just in case something goes wrong * with TLV parsing */ jnx_header_len += jnx_ext_len; - + if (vflag>1) printf(", PCAP Extension(s) total length %u", jnx_ext_len); - + TCHECK2(tptr[0], jnx_ext_len); while (jnx_ext_len > JUNIPER_EXT_TLV_OVERHEAD) { tlv_type = *(tptr++); tlv_len = *(tptr++); tlv_value = 0; - + /* sanity check */ if (tlv_type == 0 || tlv_len == 0) break; - + if (vflag>1) printf("\n\t %s Extension TLV #%u, length %u, value ", tok2str(jnx_ext_tlv_values,"Unknown",tlv_type), tlv_type, tlv_len); - + tlv_value = juniper_read_tlv_value(tptr, tlv_type, tlv_len); switch (tlv_type) { case JUNIPER_EXT_TLV_IFD_NAME: @@ -1236,16 +1233,16 @@ juniper_parse_header (const u_char *p, const struct pcap_pkthdr *h, struct junip } break; } - + tptr+=tlv_len; jnx_ext_len -= tlv_len+JUNIPER_EXT_TLV_OVERHEAD; } - + if (vflag>1) printf("\n\t-----original packet-----\n\t"); - } - - if ((l2info->flags & JUNIPER_BPF_NO_L2 ) == JUNIPER_BPF_NO_L2 ) { + } + + if ((l2info->flags & JUNIPER_BPF_NO_L2 ) == JUNIPER_BPF_NO_L2 ) { if (eflag) printf("no-L2-hdr, "); @@ -1259,7 +1256,7 @@ juniper_parse_header (const u_char *p, const struct pcap_pkthdr *h, struct junip l2info->header_len=jnx_header_len+4; return 0; /* stop parsing the output further */ - + } l2info->header_len = jnx_header_len; p+=l2info->header_len; @@ -1281,7 +1278,7 @@ juniper_parse_header (const u_char *p, const struct pcap_pkthdr *h, struct junip l2info->cookie_type = AS_COOKIE_ID; l2info->cookie_len = 8; break; - + default: l2info->bundle = l2info->cookie[0]; break; @@ -1316,9 +1313,9 @@ juniper_parse_header (const u_char *p, const struct pcap_pkthdr *h, struct junip } if (eflag) printf(": "); /* print demarc b/w L2/L3*/ - - l2info->proto = EXTRACT_16BITS(p+l2info->cookie_len); + + l2info->proto = EXTRACT_16BITS(p+l2info->cookie_len); break; } ++lp; @@ -1335,7 +1332,7 @@ juniper_parse_header (const u_char *p, const struct pcap_pkthdr *h, struct junip break; case AS_COOKIE_ID: l2info->bundle = (EXTRACT_16BITS(&l2info->cookie[6])>>3)&0xfff; - l2info->proto = (l2info->cookie[5])&JUNIPER_LSQ_L3_PROTO_MASK; + l2info->proto = (l2info->cookie[5])&JUNIPER_LSQ_L3_PROTO_MASK; break; default: l2info->bundle = l2info->cookie[0]; @@ -1348,7 +1345,7 @@ juniper_parse_header (const u_char *p, const struct pcap_pkthdr *h, struct junip switch (l2info->cookie_type) { case LS_COOKIE_ID: l2info->bundle = l2info->cookie[1]; - l2info->proto = EXTRACT_16BITS(p); + l2info->proto = EXTRACT_16BITS(p); l2info->header_len += 2; l2info->length -= 2; l2info->caplen -= 2; @@ -1371,7 +1368,7 @@ juniper_parse_header (const u_char *p, const struct pcap_pkthdr *h, struct junip switch (l2info->cookie_type) { case LS_COOKIE_ID: l2info->bundle = l2info->cookie[1]; - l2info->proto = EXTRACT_16BITS(p); + l2info->proto = EXTRACT_16BITS(p); l2info->header_len += 2; l2info->length -= 2; l2info->caplen -= 2; @@ -1402,7 +1399,7 @@ juniper_parse_header (const u_char *p, const struct pcap_pkthdr *h, struct junip default: break; } - + if (eflag) printf("control-word 0x%08x ", control_word); } @@ -1437,7 +1434,7 @@ juniper_parse_header (const u_char *p, const struct pcap_pkthdr *h, struct junip printf("Unknown Juniper DLT_ type %u: ", l2info->pictype); break; } - + if (eflag > 1) printf("hlen %u, proto 0x%04x, ",l2info->header_len,l2info->proto);