/* \summary: Open Shortest Path First (OSPF) printer */
#ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
#endif
-#include <netdissect-stdinc.h>
+#include "netdissect-stdinc.h"
#include "netdissect.h"
#include "addrtoname.h"
#include "ospf.h"
-static const char tstr[] = " [|ospf2]";
static const struct tok ospf_option_values[] = {
{ OSPF_OPTION_T, "MultiTopology" }, /* draft-ietf-ospf-mt-09 */
};
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;
}
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;
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);
}
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)
trunc:
return -1;
invalid:
- ND_PRINT("%s", istr);
+ nd_print_invalid(ndo);
return -1;
}
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,
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 */
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,
/* 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));
+ 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);
{
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;
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);
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:
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;
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);
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;
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);
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 %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);
- 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;
}
/* 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:
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);
}
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;
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 */
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));
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;
}
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);
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;
/* 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')
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)) {
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");
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:
return;
trunc:
- ND_PRINT("%s", tstr);
+ nd_print_trunc(ndo);
}