📄 ospf_dump.c
字号:
voidospf_as_external_lsa_dump (struct stream *s, u_int16_t length){ struct as_external_lsa *al; int size; int i; al = (struct as_external_lsa *) STREAM_PNT (s); zlog_info (" AS-external-LSA"); zlog_info (" Network Mask %s", inet_ntoa (al->mask)); size = ntohs (al->header.length) - OSPF_LSA_HEADER_SIZE -4; for (i = 0; size > 0; size -= 12, i++) { zlog_info (" bit %s TOS=%d metric %d", IS_EXTERNAL_METRIC (al->e[i].tos) ? "E" : "-", al->e[i].tos & 0x7f, GET_METRIC (al->e[i].metric)); zlog_info (" Forwarding address %s", inet_ntoa (al->e[i].fwd_addr)); zlog_info (" External Route Tag %d", al->e[i].route_tag); }}voidospf_lsa_header_list_dump (struct stream *s, u_int16_t length){ struct lsa_header *lsa; zlog_info (" # LSA Headers %d", length / OSPF_LSA_HEADER_SIZE); /* LSA Headers. */ while (length > 0) { lsa = (struct lsa_header *) STREAM_PNT (s); ospf_lsa_header_dump (lsa); stream_forward (s, OSPF_LSA_HEADER_SIZE); length -= OSPF_LSA_HEADER_SIZE; }}voidospf_packet_db_desc_dump (struct stream *s, u_int16_t length){ struct ospf_db_desc *dd; char dd_flags[8]; u_int32_t gp; gp = stream_get_getp (s); dd = (struct ospf_db_desc *) STREAM_PNT (s); zlog_info ("Database Description"); zlog_info (" Interface MTU %d", ntohs (dd->mtu)); zlog_info (" Options %d (%s)", dd->options, ospf_options_dump (dd->options)); zlog_info (" Flags %d (%s)", dd->flags, ospf_dd_flags_dump (dd->flags, dd_flags, sizeof dd_flags)); zlog_info (" Sequence Number 0x%08lx", (u_long)ntohl (dd->dd_seqnum)); length -= OSPF_HEADER_SIZE + OSPF_DB_DESC_MIN_SIZE; stream_forward (s, OSPF_DB_DESC_MIN_SIZE); ospf_lsa_header_list_dump (s, length); stream_set_getp (s, gp);}voidospf_packet_ls_req_dump (struct stream *s, u_int16_t length){ u_int32_t sp; u_int32_t ls_type; struct in_addr ls_id; struct in_addr adv_router; sp = stream_get_getp (s); length -= OSPF_HEADER_SIZE; zlog_info ("Link State Request"); zlog_info (" # Requests %d", length / 12); for (; length > 0; length -= 12) { ls_type = stream_getl (s); ls_id.s_addr = stream_get_ipv4 (s); adv_router.s_addr = stream_get_ipv4 (s); zlog_info (" LS type %d", ls_type); zlog_info (" Link State ID %s", inet_ntoa (ls_id)); zlog_info (" Advertising Router %s", inet_ntoa (adv_router)); } stream_set_getp (s, sp);}voidospf_packet_ls_upd_dump (struct stream *s, u_int16_t length){ u_int32_t sp; struct lsa_header *lsa; int lsa_len; u_int32_t count; length -= OSPF_HEADER_SIZE; sp = stream_get_getp (s); count = stream_getl (s); length -= 4; zlog_info ("Link State Update"); zlog_info (" # LSAs %d", count); while (length > 0 && count > 0) { if (length < OSPF_HEADER_SIZE || length % 4 != 0) { zlog_info (" Remaining %d bytes; Incorrect length.", length); break; } lsa = (struct lsa_header *) STREAM_PNT (s); lsa_len = ntohs (lsa->length); ospf_lsa_header_dump (lsa); switch (lsa->type) { case OSPF_ROUTER_LSA: ospf_router_lsa_dump (s, length); break; case OSPF_NETWORK_LSA: ospf_network_lsa_dump (s, length); break; case OSPF_SUMMARY_LSA: case OSPF_ASBR_SUMMARY_LSA: ospf_summary_lsa_dump (s, length); break; case OSPF_AS_EXTERNAL_LSA: ospf_as_external_lsa_dump (s, length); break;#ifdef HAVE_NSSA case OSPF_AS_NSSA_LSA: /* XXX */ break;#endif /* HAVE_NSSA */#ifdef HAVE_OPAQUE_LSA case OSPF_OPAQUE_LINK_LSA: case OSPF_OPAQUE_AREA_LSA: case OSPF_OPAQUE_AS_LSA: ospf_opaque_lsa_dump (s, length); break;#endif /* HAVE_OPAQUE_LSA */ default: break; } stream_forward (s, lsa_len); length -= lsa_len; count--; } stream_set_getp (s, sp);}voidospf_packet_ls_ack_dump (struct stream *s, u_int16_t length){ u_int32_t sp; length -= OSPF_HEADER_SIZE; sp = stream_get_getp (s); zlog_info ("Link State Acknowledgment"); ospf_lsa_header_list_dump (s, length); stream_set_getp (s, sp);}voidospf_ip_header_dump (struct stream *s){ u_int16_t length; struct ip *iph; iph = (struct ip *) STREAM_PNT (s);#ifdef GNU_LINUX length = ntohs (iph->ip_len);#else /* GNU_LINUX */ length = iph->ip_len;#endif /* GNU_LINUX */ /* IP Header dump. */ zlog_info ("ip_v %d", iph->ip_v); zlog_info ("ip_hl %d", iph->ip_hl); zlog_info ("ip_tos %d", iph->ip_tos); zlog_info ("ip_len %d", length); zlog_info ("ip_id %u", (u_int32_t) iph->ip_id); zlog_info ("ip_off %u", (u_int32_t) iph->ip_off); zlog_info ("ip_ttl %d", iph->ip_ttl); zlog_info ("ip_p %d", iph->ip_p); /* There is a report that Linux 2.0.37 does not have ip_sum. But I'm not sure. Temporary commented out by kunihiro. */ /* zlog_info ("ip_sum 0x%x", (u_int32_t) ntohs (iph->ip_sum)); */ zlog_info ("ip_src %s", inet_ntoa (iph->ip_src)); zlog_info ("ip_dst %s", inet_ntoa (iph->ip_dst));}voidospf_header_dump (struct ospf_header *ospfh){ char buf[9]; zlog_info ("Header"); zlog_info (" Version %d", ospfh->version); zlog_info (" Type %d (%s)", ospfh->type, ospf_packet_type_str[ospfh->type]); zlog_info (" Packet Len %d", ntohs (ospfh->length)); zlog_info (" Router ID %s", inet_ntoa (ospfh->router_id)); zlog_info (" Area ID %s", inet_ntoa (ospfh->area_id)); zlog_info (" Checksum 0x%x", ntohs (ospfh->checksum)); zlog_info (" AuType %d", ntohs (ospfh->auth_type)); switch (ntohs (ospfh->auth_type)) { case OSPF_AUTH_NULL: break; case OSPF_AUTH_SIMPLE: memset (buf, 0, 9); strncpy (buf, ospfh->u.auth_data, 8); zlog_info (" Simple Password %s", buf); break; case OSPF_AUTH_CRYPTOGRAPHIC: zlog_info (" Cryptographic Authentication"); zlog_info (" Key ID %d", ospfh->u.crypt.key_id); zlog_info (" Auth Data Len %d", ospfh->u.crypt.auth_data_len); zlog_info (" Sequence number %ld", (u_long)ntohl (ospfh->u.crypt.crypt_seqnum)); break; default: zlog_info ("* This is not supported authentication type"); break; } }voidospf_packet_dump (struct stream *s){ struct ospf_header *ospfh; unsigned long gp; /* Preserve pointer. */ gp = stream_get_getp (s); /* OSPF Header dump. */ ospfh = (struct ospf_header *) STREAM_PNT (s); /* Until detail flag is set, return. */ if (!(term_debug_ospf_packet[ospfh->type - 1] & OSPF_DEBUG_DETAIL)) return; /* Show OSPF header detail. */ ospf_header_dump (ospfh); stream_forward (s, OSPF_HEADER_SIZE); switch (ospfh->type) { case OSPF_MSG_HELLO: ospf_packet_hello_dump (s, ntohs (ospfh->length)); break; case OSPF_MSG_DB_DESC: ospf_packet_db_desc_dump (s, ntohs (ospfh->length)); break; case OSPF_MSG_LS_REQ: ospf_packet_ls_req_dump (s, ntohs (ospfh->length)); break; case OSPF_MSG_LS_UPD: ospf_packet_ls_upd_dump (s, ntohs (ospfh->length)); break; case OSPF_MSG_LS_ACK: ospf_packet_ls_ack_dump (s, ntohs (ospfh->length)); break; default: break; } stream_set_getp (s, gp);}/* [no] debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all) [send|recv [detail]]*/DEFUN (debug_ospf_packet, debug_ospf_packet_all_cmd, "debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all)", DEBUG_STR OSPF_STR "OSPF packets\n" "OSPF Hello\n" "OSPF Database Description\n" "OSPF Link State Request\n" "OSPF Link State Update\n" "OSPF Link State Acknowledgment\n" "OSPF all packets\n"){ int type = 0; int flag = 0; int i; assert (argc > 0); /* Check packet type. */ if (strncmp (argv[0], "h", 1) == 0) type = OSPF_DEBUG_HELLO; else if (strncmp (argv[0], "d", 1) == 0) type = OSPF_DEBUG_DB_DESC; else if (strncmp (argv[0], "ls-r", 4) == 0) type = OSPF_DEBUG_LS_REQ; else if (strncmp (argv[0], "ls-u", 4) == 0) type = OSPF_DEBUG_LS_UPD; else if (strncmp (argv[0], "ls-a", 4) == 0) type = OSPF_DEBUG_LS_ACK; else if (strncmp (argv[0], "a", 1) == 0) type = OSPF_DEBUG_ALL; /* Default, both send and recv. */ if (argc == 1) flag = OSPF_DEBUG_SEND | OSPF_DEBUG_RECV; /* send or recv. */ if (argc >= 2) { if (strncmp (argv[1], "s", 1) == 0) flag = OSPF_DEBUG_SEND; else if (strncmp (argv[1], "r", 1) == 0) flag = OSPF_DEBUG_RECV; else if (strncmp (argv[1], "d", 1) == 0) flag = OSPF_DEBUG_SEND | OSPF_DEBUG_RECV | OSPF_DEBUG_DETAIL; } /* detail. */ if (argc == 3) if (strncmp (argv[2], "d", 1) == 0) flag |= OSPF_DEBUG_DETAIL; for (i = 0; i < 5; i++) if (type & (0x01 << i)) { if (vty->node == CONFIG_NODE) DEBUG_PACKET_ON (i, flag); else TERM_DEBUG_PACKET_ON (i, flag); } return CMD_SUCCESS;}ALIAS (debug_ospf_packet, debug_ospf_packet_send_recv_cmd, "debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all) (send|recv|detail)", "Debugging functions\n" "OSPF information\n" "OSPF packets\n" "OSPF Hello\n" "OSPF Database Description\n" "OSPF Link State Request\n" "OSPF Link State Update\n" "OSPF Link State Acknowledgment\n" "OSPF all packets\n" "Packet sent\n" "Packet received\n" "Detail information\n");ALIAS (debug_ospf_packet, debug_ospf_packet_send_recv_detail_cmd, "debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all) (send|recv) (detail|)", "Debugging functions\n" "OSPF information\n" "OSPF packets\n" "OSPF Hello\n" "OSPF Database Description\n" "OSPF Link State Request\n" "OSPF Link State Update\n" "OSPF Link State Acknowledgment\n" "OSPF all packets\n" "Packet sent\n" "Packet received\n" "Detail Information\n"); DEFUN (no_debug_ospf_packet, no_debug_ospf_packet_all_cmd, "no debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all)", NO_STR DEBUG_STR OSPF_STR "OSPF packets\n" "OSPF Hello\n" "OSPF Database Description\n" "OSPF Link State Request\n" "OSPF Link State Update\n" "OSPF Link State Acknowledgment\n" "OSPF all packets\n"){ int type = 0; int flag = 0; int i; assert (argc > 0); /* Check packet type. */ if (strncmp (argv[0], "h", 1) == 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -