#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-ospf6.c,v 1.1 1999-10-30 05:11:19 itojun Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/tcpdump/print-ospf6.c,v 1.11 2002-12-11 22:29:22 guy Exp $ (LBL)";
#endif
-#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/socket.h>
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
-#include <netinet/in.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <netinet/ip_var.h>
+#include <tcpdump-stdinc.h>
-#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include "interface.h"
#include "addrtoname.h"
+#include "extract.h"
#include "ospf6.h"
{ 0, NULL }
};
+static const struct bits ospf6_asla_flag_bits[] = {
+ { ASLA_FLAG_EXTERNAL, "E" },
+ { ASLA_FLAG_FWDADDR, "F" },
+ { ASLA_FLAG_ROUTETAG, "T" },
+ { 0, NULL }
+};
+
static struct tok type2str[] = {
{ OSPF_TYPE_UMD, "umd" },
{ OSPF_TYPE_HELLO, "hello" },
static char tstr[] = " [|ospf]";
+#ifdef WIN32
+#define inline __inline
+#endif /* WIN32 */
+
/* Forwards */
static inline void ospf6_print_seqage(u_int32_t, time_t);
static inline void ospf6_print_bits(const struct bits *, u_char);
register const rtrid_t *ls_stateid,
register const rtrid_t *ls_router, register const char *fmt)
{
- char *scope;
+ const char *scope;
switch (ls_type & LS_SCOPE_MASK) {
case LS_SCOPE_LINKLOCAL:
printf(" {"); /* } (ctags) */
TCHECK(lshp->ls_seq);
- ospf6_print_seqage(ntohl(lshp->ls_seq), ntohs(lshp->ls_age));
- ospf6_print_ls_type(ntohs(lshp->ls_type), &lshp->ls_stateid,
+ ospf6_print_seqage(EXTRACT_32BITS(&lshp->ls_seq), EXTRACT_16BITS(&lshp->ls_age));
+ ospf6_print_ls_type(EXTRACT_16BITS(&lshp->ls_type), &lshp->ls_stateid,
&lshp->ls_router, "ls_type %d");
return (0);
static int
ospf6_print_lsaprefix(register const struct lsa_prefix *lsapp)
{
- int k;
+ u_int k;
struct in6_addr prefix;
TCHECK(*lsapp);
}
memset(&prefix, 0, sizeof(prefix));
memcpy(&prefix, lsapp->lsa_p_prefix, k * 4);
- printf(" %s/%d", ip6addr_string(&prefix),
+ printf(" %s/%d", ip6addr_string(&prefix),
lsapp->lsa_p_len);
if (lsapp->lsa_p_opt)
printf("(opt=%x)", lsapp->lsa_p_opt);
+ if (lsapp->lsa_p_mbz)
+ printf("(mbz=%x)", EXTRACT_16BITS(&lsapp->lsa_p_mbz)); /* XXX */
return sizeof(*lsapp) - 4 + k * 4;
trunc:
static int
ospf6_print_lsa(register const struct lsa *lsap)
{
- register const u_char *ls_end;
+ register const u_char *ls_end, *ls_opt;
register const struct rlalink *rlp;
#if 0
register const struct tos_metric *tosp;
#if 0
register const u_int32_t *lp;
#endif
- register int j, k;
+ register u_int j;
+ register int k;
+ u_int32_t flags32;
if (ospf6_print_lshdr(&lsap->ls_hdr))
return (1);
TCHECK(lsap->ls_hdr.ls_length);
- ls_end = (u_char *)lsap + ntohs(lsap->ls_hdr.ls_length);
- switch (ntohs(lsap->ls_hdr.ls_type)) {
+ ls_end = (u_char *)lsap + EXTRACT_16BITS(&lsap->ls_hdr.ls_length);
+ switch (EXTRACT_16BITS(&lsap->ls_hdr.ls_type)) {
case LS_TYPE_ROUTER | LS_SCOPE_AREA:
TCHECK(lsap->lsa_un.un_rla.rla_flags);
ospf6_print_bits(ospf6_rla_flag_bits,
lsap->lsa_un.un_rla.rla_flags);
TCHECK(lsap->lsa_un.un_rla.rla_options);
ospf6_print_bits(ospf6_option_bits,
- ntohl(lsap->lsa_un.un_rla.rla_options));
+ EXTRACT_32BITS(&lsap->lsa_un.un_rla.rla_options));
TCHECK(lsap->lsa_un.un_rla.rla_link);
rlp = lsap->lsa_un.un_rla.rla_link;
rlp->link_type);
return (0);
}
- printf(" metric %d", ntohs(rlp->link_metric));
+ printf(" metric %d", EXTRACT_16BITS(&rlp->link_metric));
/* { (ctags) */
printf(" }");
rlp++;
case LS_TYPE_NETWORK | LS_SCOPE_AREA:
TCHECK(lsap->lsa_un.un_nla.nla_options);
ospf6_print_bits(ospf6_option_bits,
- ntohl(lsap->lsa_un.un_nla.nla_options));
+ EXTRACT_32BITS(&lsap->lsa_un.un_nla.nla_options));
printf(" rtrs");
ap = lsap->lsa_un.un_nla.nla_router;
while ((u_char *)ap < ls_end) {
case LS_TYPE_INTER_AP | LS_SCOPE_AREA:
TCHECK(lsap->lsa_un.un_inter_ap.inter_ap_metric);
printf(" metric %u",
- (u_int32_t)ntohl(lsap->lsa_un.un_inter_ap.inter_ap_metric) & SLA_MASK_METRIC);
+ EXTRACT_32BITS(&lsap->lsa_un.un_inter_ap.inter_ap_metric) & SLA_MASK_METRIC);
lsapp = lsap->lsa_un.un_inter_ap.inter_ap_prefix;
while (lsapp + sizeof(lsapp) <= (struct lsa_prefix *)ls_end) {
k = ospf6_print_lsaprefix(lsapp);
- if (k < 0)
+ if (k)
goto trunc;
lsapp = (struct lsa_prefix *)(((u_char *)lsapp) + k);
}
break;
+ case LS_SCOPE_AS | LS_TYPE_ASE:
+ TCHECK(lsap->lsa_un.un_asla.asla_metric);
+ flags32 = EXTRACT_32BITS(&lsap->lsa_un.un_asla.asla_metric);
+ ospf6_print_bits(ospf6_asla_flag_bits, flags32);
+ printf(" metric %u",
+ EXTRACT_32BITS(&lsap->lsa_un.un_asla.asla_metric) &
+ ASLA_MASK_METRIC);
+ lsapp = lsap->lsa_un.un_asla.asla_prefix;
+ k = ospf6_print_lsaprefix(lsapp);
+ if (k < 0)
+ goto trunc;
+ if ((ls_opt = (u_char *)(((u_char *)lsapp) + k)) < ls_end) {
+ struct in6_addr *fwdaddr6;
+
+ if ((flags32 & ASLA_FLAG_FWDADDR) != 0) {
+ fwdaddr6 = (struct in6_addr *)ls_opt;
+ TCHECK(*fwdaddr6);
+ printf(" forward %s",
+ ip6addr_string(fwdaddr6));
+
+ ls_opt += sizeof(struct in6_addr);
+ }
+
+ if ((flags32 & ASLA_FLAG_ROUTETAG) != 0) {
+ TCHECK(*(u_int32_t *)ls_opt);
+ printf(" tag %s",
+ ipaddr_string((u_int32_t *)ls_opt));
+
+ ls_opt += sizeof(u_int32_t);
+ }
+
+ if (lsapp->lsa_p_mbz) {
+ TCHECK(*(u_int32_t *)ls_opt);
+ printf(" RefLSID: %s",
+ ipaddr_string((u_int32_t *)ls_opt));
+ ls_opt += sizeof(u_int32_t);
+ }
+ }
+ break;
#if 0
case LS_TYPE_SUM_ABR:
TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
register u_int32_t ul;
TCHECK(*lp);
- ul = ntohl(*lp);
+ ul = EXTRACT_32BITS(lp);
printf(" tos %d metric %d",
(ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS,
ul & SLA_MASK_METRIC);
}
break;
- case LS_TYPE_ASE:
- TCHECK(lsap->lsa_un.un_nla.nla_mask);
- printf(" mask %s",
- ipaddr_string(&lsap->lsa_un.un_asla.asla_mask));
-
- TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
- almp = lsap->lsa_un.un_asla.asla_metric;
- while ((u_char *)almp < ls_end) {
- register u_int32_t ul;
-
- TCHECK(almp->asla_tosmetric);
- ul = ntohl(almp->asla_tosmetric);
- printf(" type %d tos %d metric %d",
- (ul & ASLA_FLAG_EXTERNAL) ? 2 : 1,
- (ul & ASLA_MASK_TOS) >> ASLA_SHIFT_TOS,
- (ul & ASLA_MASK_METRIC));
- TCHECK(almp->asla_forward);
- if (almp->asla_forward.s_addr) {
- printf(" forward %s",
- ipaddr_string(&almp->asla_forward));
- }
- TCHECK(almp->asla_tag);
- if (almp->asla_tag.s_addr) {
- printf(" tag %s",
- ipaddr_string(&almp->asla_tag));
- }
- ++almp;
- }
- break;
-
case LS_TYPE_GROUP:
/* Multicast extensions as of 23 July 1991 */
mcp = lsap->lsa_un.un_mcla;
while ((u_char *)mcp < ls_end) {
TCHECK(mcp->mcla_vid);
- switch (ntohl(mcp->mcla_vtype)) {
+ switch (EXTRACT_32BITS(&mcp->mcla_vtype)) {
case MCLA_VERTEX_ROUTER:
printf(" rtr rtrid %s",
default:
printf(" ??VertexType %u??",
- (u_int32_t)ntohl(mcp->mcla_vtype));
+ EXTRACT_32BITS(&mcp->mcla_vtype));
break;
}
++mcp;
/* Link LSA */
llsap = &lsap->lsa_un.un_llsa;
TCHECK(llsap->llsa_options);
- ospf6_print_bits(ospf6_option_bits, ntohl(llsap->llsa_options));
+ ospf6_print_bits(ospf6_option_bits, EXTRACT_32BITS(&llsap->llsa_options));
TCHECK(llsap->llsa_nprefix);
printf(" pri %d lladdr %s npref %d", llsap->llsa_priority,
ip6addr_string(&llsap->llsa_lladdr),
- (u_int32_t)ntohl(llsap->llsa_nprefix));
+ EXTRACT_32BITS(&llsap->llsa_nprefix));
lsapp = llsap->llsa_prefix;
- for (j = 0; j < ntohl(llsap->llsa_nprefix); j++) {
+ for (j = 0; j < EXTRACT_32BITS(&llsap->llsa_nprefix); j++) {
k = ospf6_print_lsaprefix(lsapp);
- if (k < 0)
+ if (k)
goto trunc;
lsapp = (struct lsa_prefix *)(((u_char *)lsapp) + k);
}
/* Intra-Area-Prefix LSA */
TCHECK(lsap->lsa_un.un_intra_ap.intra_ap_rtid);
ospf6_print_ls_type(
- ntohs(lsap->lsa_un.un_intra_ap.intra_ap_lstype),
+ EXTRACT_16BITS(&lsap->lsa_un.un_intra_ap.intra_ap_lstype),
&lsap->lsa_un.un_intra_ap.intra_ap_lsid,
&lsap->lsa_un.un_intra_ap.intra_ap_rtid,
"LinkStateType %d");
TCHECK(lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
printf(" npref %d",
- ntohs(lsap->lsa_un.un_intra_ap.intra_ap_nprefix));
+ EXTRACT_16BITS(&lsap->lsa_un.un_intra_ap.intra_ap_nprefix));
lsapp = lsap->lsa_un.un_intra_ap.intra_ap_prefix;
for (j = 0;
- j < ntohs(lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
+ j < EXTRACT_16BITS(&lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
j++) {
k = ospf6_print_lsaprefix(lsapp);
- if (k < 0)
+ if (k)
goto trunc;
lsapp = (struct lsa_prefix *)(((u_char *)lsapp) + k);
}
default:
printf(" ??LinkStateType 0x%04x??",
- ntohs(lsap->ls_hdr.ls_type));
+ EXTRACT_16BITS(&lsap->ls_hdr.ls_type));
}
/* { (ctags) */
if (vflag) {
TCHECK(op->ospf6_hello.hello_deadint);
ospf6_print_bits(ospf6_option_bits,
- ntohl(op->ospf6_hello.hello_options));
+ EXTRACT_32BITS(&op->ospf6_hello.hello_options));
printf(" ifid %s pri %d int %d dead %u",
ipaddr_string(&op->ospf6_hello.hello_ifid),
op->ospf6_hello.hello_priority,
- ntohs(op->ospf6_hello.hello_helloint),
- ntohs(op->ospf6_hello.hello_deadint));
+ EXTRACT_16BITS(&op->ospf6_hello.hello_helloint),
+ EXTRACT_16BITS(&op->ospf6_hello.hello_deadint));
}
TCHECK(op->ospf6_hello.hello_dr);
if (op->ospf6_hello.hello_dr != 0)
case OSPF_TYPE_DB:
TCHECK(op->ospf6_db.db_options);
ospf6_print_bits(ospf6_option_bits,
- ntohl(op->ospf6_db.db_options));
+ EXTRACT_32BITS(&op->ospf6_db.db_options));
sep = ' ';
TCHECK(op->ospf6_db.db_flags);
if (op->ospf6_db.db_flags & OSPF6_DB_INIT) {
sep = '/';
}
TCHECK(op->ospf6_db.db_seq);
- printf(" mtu %u S %X", ntohs(op->ospf6_db.db_mtu),
- (u_int32_t)ntohl(op->ospf6_db.db_seq));
+ printf(" mtu %u S %X", EXTRACT_16BITS(&op->ospf6_db.db_mtu),
+ EXTRACT_32BITS(&op->ospf6_db.db_seq));
if (vflag) {
/* Print all the LS adv's */
while ((u_char *)lsrp < dataend) {
TCHECK(*lsrp);
printf(" {"); /* } (ctags) */
- ospf6_print_ls_type(ntohs(lsrp->ls_type),
+ ospf6_print_ls_type(EXTRACT_16BITS(&lsrp->ls_type),
&lsrp->ls_stateid,
&lsrp->ls_router,
"LinkStateType %d");
if (vflag) {
lsap = op->ospf6_lsu.lsu_lsa;
TCHECK(op->ospf6_lsu.lsu_count);
- i = ntohl(op->ospf6_lsu.lsu_count);
+ i = EXTRACT_32BITS(&op->ospf6_lsu.lsu_count);
while (i--) {
if (ospf6_print_lsa(lsap))
goto trunc;
lsap = (struct lsa *)((u_char *)lsap +
- ntohs(lsap->ls_hdr.ls_length));
+ EXTRACT_16BITS(&lsap->ls_hdr.ls_length));
}
}
break;
/* value. If it's not valid, say so and return */
TCHECK(op->ospf6_type);
cp = tok2str(type2str, "type%d", op->ospf6_type);
- printf(" OSPFv%d-%s %d:", op->ospf6_version, cp, length);
+ printf("OSPFv%d-%s %d:", op->ospf6_version, cp, length);
if (*cp == 't')
return;
TCHECK(op->ospf6_len);
- if (length != ntohs(op->ospf6_len)) {
- printf(" [len %d]", ntohs(op->ospf6_len));
+ if (length != EXTRACT_16BITS(&op->ospf6_len)) {
+ printf(" [len %d]", EXTRACT_16BITS(&op->ospf6_len));
return;
}
dataend = bp + length;