X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/64677b0d78ff168d98c3035e894c4910c021136e..e67f4fcae8173ccd4a7de1a0c5fedd2265675f81:/print-ospf.c diff --git a/print-ospf.c b/print-ospf.c index 4a409d1a..2a502a6c 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" @@ -36,7 +36,6 @@ #include "ospf.h" -static const char tstr[] = " [|ospf2]"; static const struct tok ospf_option_values[] = { { OSPF_OPTION_T, "MultiTopology" }, /* draft-ietf-ospf-mt-09 */ @@ -180,7 +179,7 @@ static const struct tok ospf_lls_eo_options[] = { }; int -ospf_print_grace_lsa(netdissect_options *ndo, +ospf_grace_lsa_print(netdissect_options *ndo, const u_char *tptr, u_int ls_length) { u_int tlv_type, tlv_length; @@ -263,7 +262,7 @@ trunc: } int -ospf_print_te_lsa(netdissect_options *ndo, +ospf_te_lsa_print(netdissect_options *ndo, const u_char *tptr, u_int ls_length) { u_int tlv_type, tlv_length, subtlv_type, subtlv_length; @@ -504,7 +503,7 @@ ospf_print_te_lsa(netdissect_options *ndo, trunc: return -1; invalid: - ND_PRINT("%s", istr); + nd_print_invalid(ndo); return -1; } @@ -515,7 +514,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,14 +522,14 @@ 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), + 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 */ @@ -555,11 +554,11 @@ ospf_print_lshdr(netdissect_options *ndo, 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)); + 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); @@ -620,7 +619,7 @@ ospf_print_lsa(netdissect_options *ndo, { const uint8_t *ls_end; const struct rlalink *rlp; - const struct in_addr *ap; + const nd_ipv4 *ap; const struct aslametric *almp; const struct mcla *mcp; const uint8_t *lp; @@ -638,13 +637,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); @@ -652,26 +651,26 @@ ospf_print_lsa(netdissect_options *ndo, case RLA_TYPE_VIRTUAL: ND_PRINT("\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s", - ipaddr_string(ndo, &rlp->link_id), - ipaddr_string(ndo, &rlp->link_data)); + ipaddr_string(ndo, rlp->link_id), + ipaddr_string(ndo, rlp->link_data)); break; case RLA_TYPE_ROUTER: ND_PRINT("\n\t Neighbor Router-ID: %s, Interface Address: %s", - ipaddr_string(ndo, &rlp->link_id), - ipaddr_string(ndo, &rlp->link_data)); + ipaddr_string(ndo, rlp->link_id), + ipaddr_string(ndo, rlp->link_data)); break; case RLA_TYPE_TRANSIT: ND_PRINT("\n\t Neighbor Network-ID: %s, Interface Address: %s", - ipaddr_string(ndo, &rlp->link_id), - ipaddr_string(ndo, &rlp->link_data)); + ipaddr_string(ndo, rlp->link_id), + ipaddr_string(ndo, rlp->link_data)); break; case RLA_TYPE_STUB: ND_PRINT("\n\t Stub Network: %s, Mask: %s", - ipaddr_string(ndo, &rlp->link_id), - ipaddr_string(ndo, &rlp->link_data)); + ipaddr_string(ndo, rlp->link_id), + ipaddr_string(ndo, rlp->link_data)); break; default: @@ -689,22 +688,22 @@ 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)); + ipaddr_string(ndo, lsap->lsa_un.un_nla.nla_mask)); ap = lsap->lsa_un.un_nla.nla_router; while ((const u_char *)ap < ls_end) { ND_TCHECK_SIZE(ap); - ND_PRINT("\n\t %s", ipaddr_string(ndo, ap)); + ND_PRINT("\n\t %s", ipaddr_string(ndo, *ap)); ++ap; } 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); + ipaddr_string(ndo, lsap->lsa_un.un_sla.sla_mask)); + 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; @@ -721,7 +720,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; @@ -739,16 +738,16 @@ 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)); + 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 %u, metric", @@ -760,13 +759,13 @@ ospf_print_lsa(netdissect_options *ndo, else ND_PRINT(" %u", (ul & ASLA_MASK_METRIC)); - ND_TCHECK(almp->asla_forward); - if (almp->asla_forward.s_addr) { - ND_PRINT(", forward %s", ipaddr_string(ndo, &almp->asla_forward)); + ND_TCHECK_4(almp->asla_forward); + if (EXTRACT_IPV4_TO_NETWORK_ORDER(almp->asla_forward) != 0) { + ND_PRINT(", forward %s", ipaddr_string(ndo, almp->asla_forward)); } - ND_TCHECK(almp->asla_tag); - if (almp->asla_tag.s_addr) { - ND_PRINT(", tag %s", ipaddr_string(ndo, &almp->asla_tag)); + ND_TCHECK_4(almp->asla_tag); + if (EXTRACT_IPV4_TO_NETWORK_ORDER(almp->asla_tag) != 0) { + ND_PRINT(", tag %s", ipaddr_string(ndo, almp->asla_tag)); } ++almp; } @@ -776,17 +775,17 @@ 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: ND_PRINT("\n\t Router Router-ID %s", - ipaddr_string(ndo, &mcp->mcla_vid)); + ipaddr_string(ndo, mcp->mcla_vid)); break; case MCLA_VERTEX_NETWORK: ND_PRINT("\n\t Network Designated Router %s", - ipaddr_string(ndo, &mcp->mcla_vid)); + ipaddr_string(ndo, mcp->mcla_vid)); break; default: @@ -852,14 +851,14 @@ ospf_print_lsa(netdissect_options *ndo, break; case LS_OPAQUE_TYPE_GRACE: - if (ospf_print_grace_lsa(ndo, (const u_char *)(lsap->lsa_un.un_grace_tlv), + if (ospf_grace_lsa_print(ndo, (const u_char *)(lsap->lsa_un.un_grace_tlv), ls_length) == -1) { return(ls_end); } break; case LS_OPAQUE_TYPE_TE: - if (ospf_print_te_lsa(ndo, (const u_char *)(lsap->lsa_un.un_te_lsa_tlv), + if (ospf_te_lsa_print(ndo, (const u_char *)(lsap->lsa_un.un_te_lsa_tlv), ls_length) == -1) { return(ls_end); } @@ -983,7 +982,7 @@ static int ospf_decode_v2(netdissect_options *ndo, const struct ospfhdr *op, const u_char *dataend) { - const struct in_addr *ap; + const nd_ipv4 *ap; const struct lsr *lsrp; const struct lsa_hdr *lshp; const struct lsa *lsap; @@ -992,49 +991,49 @@ 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), + ipaddr_string(ndo, op->ospf_hello.hello_mask), EXTRACT_U_1(op->ospf_hello.hello_priority)); - ND_TCHECK(op->ospf_hello.hello_dr); - if (op->ospf_hello.hello_dr.s_addr != 0) + ND_TCHECK_4(op->ospf_hello.hello_dr); + if (EXTRACT_IPV4_TO_NETWORK_ORDER(op->ospf_hello.hello_dr) != 0) ND_PRINT("\n\t Designated Router %s", - ipaddr_string(ndo, &op->ospf_hello.hello_dr)); + ipaddr_string(ndo, op->ospf_hello.hello_dr)); - ND_TCHECK(op->ospf_hello.hello_bdr); - if (op->ospf_hello.hello_bdr.s_addr != 0) + ND_TCHECK_4(op->ospf_hello.hello_bdr); + if (EXTRACT_IPV4_TO_NETWORK_ORDER(op->ospf_hello.hello_bdr) != 0) ND_PRINT(", Backup Designated Router %s", - ipaddr_string(ndo, &op->ospf_hello.hello_bdr)); + ipaddr_string(ndo, op->ospf_hello.hello_bdr)); ap = op->ospf_hello.hello_neighbor; if ((const u_char *)ap < dataend) ND_PRINT("\n\t Neighbor List:"); while ((const u_char *)ap < dataend) { ND_TCHECK_SIZE(ap); - ND_PRINT("\n\t %s", ipaddr_string(ndo, ap)); + ND_PRINT("\n\t %s", ipaddr_string(ndo, *ap)); ++ap; } 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 */ @@ -1050,7 +1049,7 @@ ospf_decode_v2(netdissect_options *ndo, ND_TCHECK_SIZE(lsrp); ND_PRINT("\n\t Advertising Router: %s, %s LSA (%u)", - ipaddr_string(ndo, &lsrp->ls_router), + ipaddr_string(ndo, lsrp->ls_router), tok2str(lsa_values,"unknown",EXTRACT_BE_U_4(lsrp->ls_type)), EXTRACT_BE_U_4(lsrp->ls_type)); @@ -1066,7 +1065,7 @@ ospf_decode_v2(netdissect_options *ndo, break; default: ND_PRINT(", LSA-ID: %s", - ipaddr_string(ndo, &lsrp->un_ls_stateid.ls_stateid)); + ipaddr_string(ndo, lsrp->un_ls_stateid.ls_stateid)); break; } @@ -1076,7 +1075,7 @@ 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(", %u LSA%s", lsa_count_max, PLURAL_SUFFIX(lsa_count_max)); for (lsa_count=1;lsa_count <= lsa_count_max;lsa_count++) { @@ -1111,10 +1110,11 @@ ospf_print(netdissect_options *ndo, const u_char *dataend; const char *cp; + ndo->ndo_protocol = "ospf2"; 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,7 +1132,7 @@ 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 %u]", EXTRACT_BE_U_2(op->ospf_len)); } @@ -1143,12 +1143,12 @@ ospf_print(netdissect_options *ndo, dataend = bp + length; } - ND_TCHECK(op->ospf_routerid); - ND_PRINT("\n\tRouter-ID %s", ipaddr_string(ndo, &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); - if (op->ospf_areaid.s_addr != 0) - ND_PRINT(", Area %s", ipaddr_string(ndo, &op->ospf_areaid)); + ND_TCHECK_4(op->ospf_areaid); + if (EXTRACT_IPV4_TO_NETWORK_ORDER(op->ospf_areaid) != 0) + ND_PRINT(", Area %s", ipaddr_string(ndo, op->ospf_areaid)); else ND_PRINT(", Backbone Area"); @@ -1167,7 +1167,7 @@ ospf_print(netdissect_options *ndo, case OSPF_AUTH_SIMPLE: ND_PRINT("\n\tSimple text password: "); - safeputs(ndo, op->ospf_authdata, OSPF_AUTH_SIMPLE_LEN); + (void)nd_printzp(ndo, op->ospf_authdata, OSPF_AUTH_SIMPLE_LEN, NULL); break; case OSPF_AUTH_MD5: @@ -1201,5 +1201,5 @@ ospf_print(netdissect_options *ndo, return; trunc: - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); }