X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/e2982e7f6f0b624a773ec5a58885ee80fab46d34..a909db55ebc50de487e65f19b3250d0b45763d2d:/print-ospf.c diff --git a/print-ospf.c b/print-ospf.c index 1bf03652..a37b5b1f 100644 --- a/print-ospf.c +++ b/print-ospf.c @@ -24,10 +24,10 @@ /* \summary: Open Shortest Path First (OSPF) printer */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include #endif -#include +#include "netdissect-stdinc.h" #include "netdissect.h" #include "addrtoname.h" @@ -428,7 +428,7 @@ ospf_print_te_lsa(netdissect_options *ndo, tok2str(gmpls_encoding_values, "Unknown", EXTRACT_U_1((tptr + 1)))); for (priority_level = 0; priority_level < 8; priority_level++) { bw.i = EXTRACT_BE_U_4(tptr + 4 + (priority_level * 4)); - ND_PRINT("\n\t\t priority level %d: %.3f Mbps", + ND_PRINT("\n\t\t priority level %u: %.3f Mbps", priority_level, bw.f * 8 / 1000000); } @@ -453,7 +453,7 @@ ospf_print_te_lsa(netdissect_options *ndo, ND_PRINT("\n\t\t Shared risk group: "); while (count_srlg > 0) { bw.i = EXTRACT_BE_U_4(tptr); - ND_PRINT("%d", bw.i); + ND_PRINT("%u", bw.i); tptr+=4; count_srlg--; if (count_srlg > 0) @@ -515,7 +515,7 @@ ospf_print_lshdr(netdissect_options *ndo, u_int ls_type; u_int ls_length; - ND_TCHECK(lshp->ls_length); + ND_TCHECK_2(lshp->ls_length); ls_length = EXTRACT_BE_U_2(lshp->ls_length); if (ls_length < sizeof(struct lsa_hdr)) { ND_PRINT("\n\t Bogus length %u < header (%lu)", ls_length, @@ -523,21 +523,21 @@ ospf_print_lshdr(netdissect_options *ndo, return(-1); } - ND_TCHECK(lshp->ls_seq); /* XXX - ls_length check checked this */ + ND_TCHECK_4(lshp->ls_seq); /* XXX - ls_length check checked this */ ND_PRINT("\n\t Advertising Router %s, seq 0x%08x, age %us, length %u", ipaddr_string(ndo, &lshp->ls_router), EXTRACT_BE_U_4(lshp->ls_seq), EXTRACT_BE_U_2(lshp->ls_age), ls_length - (u_int)sizeof(struct lsa_hdr)); - ND_TCHECK(lshp->ls_type); /* XXX - ls_length check checked this */ + ND_TCHECK_1(lshp->ls_type); /* XXX - ls_length check checked this */ ls_type = EXTRACT_U_1(lshp->ls_type); switch (ls_type) { /* the LSA header for opaque LSAs was slightly changed */ case LS_TYPE_OPAQUE_LL: case LS_TYPE_OPAQUE_AL: case LS_TYPE_OPAQUE_DW: - ND_PRINT("\n\t %s LSA (%d), Opaque-Type %s LSA (%u), Opaque-ID %u", + ND_PRINT("\n\t %s LSA (%u), Opaque-Type %s LSA (%u), Opaque-ID %u", tok2str(lsa_values,"unknown",ls_type), ls_type, @@ -552,14 +552,14 @@ ospf_print_lshdr(netdissect_options *ndo, /* all other LSA types use regular style LSA headers */ default: - ND_PRINT("\n\t %s LSA (%d), LSA-ID: %s", + ND_PRINT("\n\t %s LSA (%u), LSA-ID: %s", tok2str(lsa_values,"unknown",ls_type), ls_type, ipaddr_string(ndo, &lshp->un_lsa_id.lsa_id)); break; } - ND_TCHECK(lshp->ls_options); /* XXX - ls_length check checked this */ + ND_TCHECK_1(lshp->ls_options); /* XXX - ls_length check checked this */ ND_PRINT("\n\t Options: [%s]", bittok2str(ospf_option_values, "none", EXTRACT_U_1(lshp->ls_options))); return (ls_length); @@ -638,13 +638,13 @@ ospf_print_lsa(netdissect_options *ndo, switch (EXTRACT_U_1(lsap->ls_hdr.ls_type)) { case LS_TYPE_ROUTER: - ND_TCHECK(lsap->lsa_un.un_rla.rla_flags); + ND_TCHECK_1(lsap->lsa_un.un_rla.rla_flags); ND_PRINT("\n\t Router LSA Options: [%s]", bittok2str(ospf_rla_flag_values, "none", EXTRACT_U_1(lsap->lsa_un.un_rla.rla_flags))); - ND_TCHECK(lsap->lsa_un.un_rla.rla_count); + ND_TCHECK_2(lsap->lsa_un.un_rla.rla_count); j = EXTRACT_BE_U_2(lsap->lsa_un.un_rla.rla_count); - ND_TCHECK(lsap->lsa_un.un_rla.rla_link); + ND_TCHECK_SIZE(lsap->lsa_un.un_rla.rla_link); rlp = lsap->lsa_un.un_rla.rla_link; while (j--) { ND_TCHECK_SIZE(rlp); @@ -689,7 +689,7 @@ ospf_print_lsa(netdissect_options *ndo, break; case LS_TYPE_NETWORK: - ND_TCHECK(lsap->lsa_un.un_nla.nla_mask); + ND_TCHECK_4(&lsap->lsa_un.un_nla.nla_mask); ND_PRINT("\n\t Mask %s\n\t Connected Routers:", ipaddr_string(ndo, &lsap->lsa_un.un_nla.nla_mask)); ap = lsap->lsa_un.un_nla.nla_router; @@ -701,10 +701,10 @@ ospf_print_lsa(netdissect_options *ndo, break; case LS_TYPE_SUM_IP: - ND_TCHECK(lsap->lsa_un.un_nla.nla_mask); + ND_TCHECK_4(&lsap->lsa_un.un_nla.nla_mask); ND_PRINT("\n\t Mask %s", ipaddr_string(ndo, &lsap->lsa_un.un_sla.sla_mask)); - ND_TCHECK(lsap->lsa_un.un_sla.sla_tosmetric); + ND_TCHECK_SIZE(lsap->lsa_un.un_sla.sla_tosmetric); lp = (const uint8_t *)lsap->lsa_un.un_sla.sla_tosmetric; while (lp < ls_end) { uint32_t ul; @@ -712,7 +712,7 @@ ospf_print_lsa(netdissect_options *ndo, ND_TCHECK_4(lp); ul = EXTRACT_BE_U_4(lp); topology = (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS; - ND_PRINT("\n\t\ttopology %s (%u) metric %d", + ND_PRINT("\n\t\ttopology %s (%u) metric %u", tok2str(ospf_topology_values, "Unknown", topology), topology, ul & SLA_MASK_METRIC); @@ -721,7 +721,7 @@ ospf_print_lsa(netdissect_options *ndo, break; case LS_TYPE_SUM_ABR: - ND_TCHECK(lsap->lsa_un.un_sla.sla_tosmetric); + ND_TCHECK_SIZE(lsap->lsa_un.un_sla.sla_tosmetric); lp = (const uint8_t *)lsap->lsa_un.un_sla.sla_tosmetric; while (lp < ls_end) { uint32_t ul; @@ -729,7 +729,7 @@ ospf_print_lsa(netdissect_options *ndo, ND_TCHECK_4(lp); ul = EXTRACT_BE_U_4(lp); topology = (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS; - ND_PRINT("\n\t\ttopology %s (%u) metric %d", + ND_PRINT("\n\t\ttopology %s (%u) metric %u", tok2str(ospf_topology_values, "Unknown", topology), topology, ul & SLA_MASK_METRIC); @@ -739,32 +739,32 @@ ospf_print_lsa(netdissect_options *ndo, case LS_TYPE_ASE: case LS_TYPE_NSSA: /* fall through - those LSAs share the same format */ - ND_TCHECK(lsap->lsa_un.un_nla.nla_mask); + ND_TCHECK_4(&lsap->lsa_un.un_nla.nla_mask); ND_PRINT("\n\t Mask %s", ipaddr_string(ndo, &lsap->lsa_un.un_asla.asla_mask)); - ND_TCHECK(lsap->lsa_un.un_sla.sla_tosmetric); + ND_TCHECK_SIZE(lsap->lsa_un.un_sla.sla_tosmetric); almp = lsap->lsa_un.un_asla.asla_metric; while ((const u_char *)almp < ls_end) { uint32_t ul; - ND_TCHECK(almp->asla_tosmetric); + ND_TCHECK_4(almp->asla_tosmetric); ul = EXTRACT_BE_U_4(almp->asla_tosmetric); topology = ((ul & ASLA_MASK_TOS) >> ASLA_SHIFT_TOS); - ND_PRINT("\n\t\ttopology %s (%u), type %d, metric", + ND_PRINT("\n\t\ttopology %s (%u), type %u, metric", tok2str(ospf_topology_values, "Unknown", topology), topology, (ul & ASLA_FLAG_EXTERNAL) ? 2 : 1); if ((ul & ASLA_MASK_METRIC) == 0xffffff) ND_PRINT(" infinite"); else - ND_PRINT(" %d", (ul & ASLA_MASK_METRIC)); + ND_PRINT(" %u", (ul & ASLA_MASK_METRIC)); - ND_TCHECK(almp->asla_forward); + ND_TCHECK_4(&almp->asla_forward); if (almp->asla_forward.s_addr) { ND_PRINT(", forward %s", ipaddr_string(ndo, &almp->asla_forward)); } - ND_TCHECK(almp->asla_tag); + ND_TCHECK_4(&almp->asla_tag); if (almp->asla_tag.s_addr) { ND_PRINT(", tag %s", ipaddr_string(ndo, &almp->asla_tag)); } @@ -776,7 +776,7 @@ ospf_print_lsa(netdissect_options *ndo, /* Multicast extensions as of 23 July 1991 */ mcp = lsap->lsa_un.un_mcla; while ((const u_char *)mcp < ls_end) { - ND_TCHECK(mcp->mcla_vid); + ND_TCHECK_4(&mcp->mcla_vid); switch (EXTRACT_BE_U_4(mcp->mcla_vtype)) { case MCLA_VERTEX_ROUTER: @@ -992,23 +992,23 @@ ospf_decode_v2(netdissect_options *ndo, switch (EXTRACT_U_1(op->ospf_type)) { case OSPF_TYPE_HELLO: - ND_TCHECK(op->ospf_hello.hello_options); + ND_TCHECK_1(op->ospf_hello.hello_options); ND_PRINT("\n\tOptions [%s]", bittok2str(ospf_option_values,"none",EXTRACT_U_1(op->ospf_hello.hello_options))); - ND_TCHECK(op->ospf_hello.hello_deadint); + ND_TCHECK_4(op->ospf_hello.hello_deadint); ND_PRINT("\n\t Hello Timer %us, Dead Timer %us, Mask %s, Priority %u", EXTRACT_BE_U_2(op->ospf_hello.hello_helloint), EXTRACT_BE_U_4(op->ospf_hello.hello_deadint), ipaddr_string(ndo, &op->ospf_hello.hello_mask), EXTRACT_U_1(op->ospf_hello.hello_priority)); - ND_TCHECK(op->ospf_hello.hello_dr); + ND_TCHECK_4(&op->ospf_hello.hello_dr); if (op->ospf_hello.hello_dr.s_addr != 0) ND_PRINT("\n\t Designated Router %s", ipaddr_string(ndo, &op->ospf_hello.hello_dr)); - ND_TCHECK(op->ospf_hello.hello_bdr); + ND_TCHECK_4(&op->ospf_hello.hello_bdr); if (op->ospf_hello.hello_bdr.s_addr != 0) ND_PRINT(", Backup Designated Router %s", ipaddr_string(ndo, &op->ospf_hello.hello_bdr)); @@ -1024,17 +1024,17 @@ ospf_decode_v2(netdissect_options *ndo, break; /* HELLO */ case OSPF_TYPE_DD: - ND_TCHECK(op->ospf_db.db_options); + ND_TCHECK_1(op->ospf_db.db_options); ND_PRINT("\n\tOptions [%s]", bittok2str(ospf_option_values, "none", EXTRACT_U_1(op->ospf_db.db_options))); - ND_TCHECK(op->ospf_db.db_flags); + ND_TCHECK_1(op->ospf_db.db_flags); ND_PRINT(", DD Flags [%s]", bittok2str(ospf_dd_flag_values, "none", EXTRACT_U_1(op->ospf_db.db_flags))); - ND_TCHECK(op->ospf_db.db_ifmtu); + ND_TCHECK_2(op->ospf_db.db_ifmtu); if (EXTRACT_BE_U_2(op->ospf_db.db_ifmtu)) { ND_PRINT(", MTU: %u", EXTRACT_BE_U_2(op->ospf_db.db_ifmtu)); } - ND_TCHECK(op->ospf_db.db_seq); + ND_TCHECK_4(op->ospf_db.db_seq); ND_PRINT(", Sequence: 0x%08x", EXTRACT_BE_U_4(op->ospf_db.db_seq)); /* Print all the LS adv's */ @@ -1076,9 +1076,9 @@ ospf_decode_v2(netdissect_options *ndo, case OSPF_TYPE_LS_UPDATE: lsap = op->ospf_lsu.lsu_lsa; - ND_TCHECK(op->ospf_lsu.lsu_count); + ND_TCHECK_4(op->ospf_lsu.lsu_count); lsa_count_max = EXTRACT_BE_U_4(op->ospf_lsu.lsu_count); - ND_PRINT(", %d LSA%s", lsa_count_max, PLURAL_SUFFIX(lsa_count_max)); + ND_PRINT(", %u LSA%s", lsa_count_max, PLURAL_SUFFIX(lsa_count_max)); for (lsa_count=1;lsa_count <= lsa_count_max;lsa_count++) { ND_PRINT("\n\t LSA #%u", lsa_count); lsap = (const struct lsa *)ospf_print_lsa(ndo, lsap); @@ -1114,7 +1114,7 @@ ospf_print(netdissect_options *ndo, op = (const struct ospfhdr *)bp; /* XXX Before we do anything else, strip off the MD5 trailer */ - ND_TCHECK(op->ospf_authtype); + ND_TCHECK_2(op->ospf_authtype); if (EXTRACT_BE_U_2(op->ospf_authtype) == OSPF_AUTH_MD5) { length -= OSPF_AUTH_MD5_LEN; ndo->ndo_snapend -= OSPF_AUTH_MD5_LEN; @@ -1122,7 +1122,7 @@ ospf_print(netdissect_options *ndo, /* If the type is valid translate it, or just print the type */ /* value. If it's not valid, say so and return */ - ND_TCHECK(op->ospf_type); + ND_TCHECK_1(op->ospf_type); cp = tok2str(type2str, "unknown LS-type %u", EXTRACT_U_1(op->ospf_type)); ND_PRINT("OSPFv%u, %s, length %u", EXTRACT_U_1(op->ospf_version), cp, length); if (*cp == 'u') @@ -1132,9 +1132,9 @@ ospf_print(netdissect_options *ndo, return; } - ND_TCHECK(op->ospf_len); + ND_TCHECK_2(op->ospf_len); if (length != EXTRACT_BE_U_2(op->ospf_len)) { - ND_PRINT(" [len %d]", EXTRACT_BE_U_2(op->ospf_len)); + ND_PRINT(" [len %u]", EXTRACT_BE_U_2(op->ospf_len)); } if (length > EXTRACT_BE_U_2(op->ospf_len)) { @@ -1143,10 +1143,10 @@ ospf_print(netdissect_options *ndo, dataend = bp + length; } - ND_TCHECK(op->ospf_routerid); + ND_TCHECK_4(&op->ospf_routerid); ND_PRINT("\n\tRouter-ID %s", ipaddr_string(ndo, &op->ospf_routerid)); - ND_TCHECK(op->ospf_areaid); + ND_TCHECK_4(&op->ospf_areaid); if (op->ospf_areaid.s_addr != 0) ND_PRINT(", Area %s", ipaddr_string(ndo, &op->ospf_areaid)); else