*: simplify log message lookup

log.c provides functionality for associating a constant (typically a
protocol constant) with a string and finding the string given the
constant. However this is highly delicate code that is extremely prone
to stack overflows and off-by-one's due to requiring the developer to
always remember to update the array size constant and to do so correctly
which, as shown by example, is never a good idea.b

The original goal of this code was to try to implement lookups in O(1)
time without a linear search through the message array. Since this code
is used 99% of the time for debugs, it's worth the 5-6 additional cmp's
worst case if it means we avoid explitable bugs due to oversights...

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
This commit is contained in:
Quentin Young 2017-06-20 23:56:50 +00:00
parent d368cd48b9
commit 56b4067930
33 changed files with 198 additions and 244 deletions

View File

@ -79,9 +79,9 @@ static const struct message attr_str [] =
{ BGP_ATTR_VNC, "VNC" }, { BGP_ATTR_VNC, "VNC" },
#endif #endif
{ BGP_ATTR_LARGE_COMMUNITIES, "LARGE_COMMUNITY" }, { BGP_ATTR_LARGE_COMMUNITIES, "LARGE_COMMUNITY" },
{ BGP_ATTR_PREFIX_SID, "PREFIX_SID" } { BGP_ATTR_PREFIX_SID, "PREFIX_SID" },
{ 0 }
}; };
static const int attr_str_max = array_size(attr_str);
static const struct message attr_flag_str[] = static const struct message attr_flag_str[] =
{ {
@ -90,6 +90,7 @@ static const struct message attr_flag_str[] =
{ BGP_ATTR_FLAG_PARTIAL, "Partial" }, { BGP_ATTR_FLAG_PARTIAL, "Partial" },
/* bgp_attr_flags_diagnose() relies on this bit being last in this list */ /* bgp_attr_flags_diagnose() relies on this bit being last in this list */
{ BGP_ATTR_FLAG_EXTLEN, "Extended Length" }, { BGP_ATTR_FLAG_EXTLEN, "Extended Length" },
{ 0 }
}; };
static struct hash *cluster_hash; static struct hash *cluster_hash;
@ -1239,7 +1240,7 @@ bgp_attr_flags_diagnose (struct bgp_attr_parser_args *args,
) )
{ {
zlog_err ("%s attribute must%s be flagged as \"%s\"", zlog_err ("%s attribute must%s be flagged as \"%s\"",
LOOKUP (attr_str, attr_code), lookup_msg(attr_str, attr_code, NULL),
CHECK_FLAG (desired_flags, attr_flag_str[i].key) ? "" : " not", CHECK_FLAG (desired_flags, attr_flag_str[i].key) ? "" : " not",
attr_flag_str[i].str); attr_flag_str[i].str);
seen = 1; seen = 1;
@ -1248,7 +1249,7 @@ bgp_attr_flags_diagnose (struct bgp_attr_parser_args *args,
{ {
zlog_debug ("Strange, %s called for attr %s, but no problem found with flags" zlog_debug ("Strange, %s called for attr %s, but no problem found with flags"
" (real flags 0x%x, desired 0x%x)", " (real flags 0x%x, desired 0x%x)",
__func__, LOOKUP (attr_str, attr_code), __func__, lookup_msg(attr_str, attr_code, NULL),
real_flags, desired_flags); real_flags, desired_flags);
} }
} }
@ -1297,7 +1298,7 @@ bgp_attr_flag_invalid (struct bgp_attr_parser_args *args)
&& !CHECK_FLAG (BGP_ATTR_FLAG_TRANS, flags)) && !CHECK_FLAG (BGP_ATTR_FLAG_TRANS, flags))
{ {
zlog_err ("%s well-known attributes must have transitive flag set (%x)", zlog_err ("%s well-known attributes must have transitive flag set (%x)",
LOOKUP (attr_str, attr_code), flags); lookup_msg(attr_str, attr_code, NULL), flags);
return 1; return 1;
} }
@ -1310,7 +1311,7 @@ bgp_attr_flag_invalid (struct bgp_attr_parser_args *args)
{ {
zlog_err ("%s well-known attribute " zlog_err ("%s well-known attribute "
"must NOT have the partial flag set (%x)", "must NOT have the partial flag set (%x)",
LOOKUP (attr_str, attr_code), flags); lookup_msg(attr_str, attr_code, NULL), flags);
return 1; return 1;
} }
if (CHECK_FLAG (flags, BGP_ATTR_FLAG_OPTIONAL) if (CHECK_FLAG (flags, BGP_ATTR_FLAG_OPTIONAL)
@ -1318,7 +1319,7 @@ bgp_attr_flag_invalid (struct bgp_attr_parser_args *args)
{ {
zlog_err ("%s optional + transitive attribute " zlog_err ("%s optional + transitive attribute "
"must NOT have the partial flag set (%x)", "must NOT have the partial flag set (%x)",
LOOKUP (attr_str, attr_code), flags); lookup_msg(attr_str, attr_code, NULL), flags);
return 1; return 1;
} }
} }
@ -2460,7 +2461,7 @@ bgp_attr_check (struct peer *peer, struct attr *attr)
if (type) if (type)
{ {
zlog_warn ("%s Missing well-known attribute %s.", peer->host, zlog_warn ("%s Missing well-known attribute %s.", peer->host,
LOOKUP (attr_str, type)); lookup_msg(attr_str, type, NULL));
bgp_notify_send_with_data (peer, bgp_notify_send_with_data (peer,
BGP_NOTIFY_UPDATE_ERR, BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_MISS_ATTR, BGP_NOTIFY_UPDATE_MISS_ATTR,
@ -2679,7 +2680,7 @@ bgp_attr_parse (struct peer *peer, struct attr *attr, bgp_size_t size,
{ {
zlog_warn ("%s: Attribute %s, parse error", zlog_warn ("%s: Attribute %s, parse error",
peer->host, peer->host,
LOOKUP (attr_str, type)); lookup_msg(attr_str, type, NULL));
if (as4_path) if (as4_path)
aspath_unintern (&as4_path); aspath_unintern (&as4_path);
return ret; return ret;
@ -2689,7 +2690,7 @@ bgp_attr_parse (struct peer *peer, struct attr *attr, bgp_size_t size,
zlog_warn ("%s: Attribute %s, parse error - treating as withdrawal", zlog_warn ("%s: Attribute %s, parse error - treating as withdrawal",
peer->host, peer->host,
LOOKUP (attr_str, type)); lookup_msg(attr_str, type, NULL));
if (as4_path) if (as4_path)
aspath_unintern (&as4_path); aspath_unintern (&as4_path);
return ret; return ret;
@ -2699,7 +2700,7 @@ bgp_attr_parse (struct peer *peer, struct attr *attr, bgp_size_t size,
if (BGP_INPUT_PNT (peer) != attr_endp) if (BGP_INPUT_PNT (peer) != attr_endp)
{ {
zlog_warn ("%s: BGP attribute %s, fetch error", zlog_warn ("%s: BGP attribute %s, fetch error",
peer->host, LOOKUP (attr_str, type)); peer->host, lookup_msg(attr_str, type, NULL));
bgp_notify_send (peer, bgp_notify_send (peer,
BGP_NOTIFY_UPDATE_ERR, BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR); BGP_NOTIFY_UPDATE_ATTR_LENG_ERR);
@ -2713,7 +2714,7 @@ bgp_attr_parse (struct peer *peer, struct attr *attr, bgp_size_t size,
if (BGP_INPUT_PNT (peer) != endp) if (BGP_INPUT_PNT (peer) != endp)
{ {
zlog_warn ("%s: BGP attribute %s, length mismatch", zlog_warn ("%s: BGP attribute %s, length mismatch",
peer->host, LOOKUP (attr_str, type)); peer->host, lookup_msg(attr_str, type, NULL));
bgp_notify_send (peer, bgp_notify_send (peer,
BGP_NOTIFY_UPDATE_ERR, BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR); BGP_NOTIFY_UPDATE_ATTR_LENG_ERR);

View File

@ -85,8 +85,8 @@ const struct message bgp_status_msg[] =
{ Established, "Established" }, { Established, "Established" },
{ Clearing, "Clearing" }, { Clearing, "Clearing" },
{ Deleted, "Deleted" }, { Deleted, "Deleted" },
{ 0 }
}; };
const int bgp_status_msg_max = BGP_STATUS_MAX;
/* BGP message type string. */ /* BGP message type string. */
const char *bgp_type_str[] = const char *bgp_type_str[] =
@ -110,16 +110,16 @@ static const struct message bgp_notify_msg[] =
{ BGP_NOTIFY_FSM_ERR, "Neighbor Events Error"}, { BGP_NOTIFY_FSM_ERR, "Neighbor Events Error"},
{ BGP_NOTIFY_CEASE, "Cease"}, { BGP_NOTIFY_CEASE, "Cease"},
{ BGP_NOTIFY_CAPABILITY_ERR, "CAPABILITY Message Error"}, { BGP_NOTIFY_CAPABILITY_ERR, "CAPABILITY Message Error"},
{ 0 }
}; };
static const int bgp_notify_msg_max = BGP_NOTIFY_MAX;
static const struct message bgp_notify_head_msg[] = static const struct message bgp_notify_head_msg[] =
{ {
{ BGP_NOTIFY_HEADER_NOT_SYNC, "/Connection Not Synchronized"}, { BGP_NOTIFY_HEADER_NOT_SYNC, "/Connection Not Synchronized"},
{ BGP_NOTIFY_HEADER_BAD_MESLEN, "/Bad Message Length"}, { BGP_NOTIFY_HEADER_BAD_MESLEN, "/Bad Message Length"},
{ BGP_NOTIFY_HEADER_BAD_MESTYPE, "/Bad Message Type"} { BGP_NOTIFY_HEADER_BAD_MESTYPE, "/Bad Message Type"},
{ 0 }
}; };
static const int bgp_notify_head_msg_max = BGP_NOTIFY_HEADER_MAX;
static const struct message bgp_notify_open_msg[] = static const struct message bgp_notify_open_msg[] =
{ {
@ -131,8 +131,8 @@ static const struct message bgp_notify_open_msg[] =
{ BGP_NOTIFY_OPEN_AUTH_FAILURE, "/Authentication Failure"}, { BGP_NOTIFY_OPEN_AUTH_FAILURE, "/Authentication Failure"},
{ BGP_NOTIFY_OPEN_UNACEP_HOLDTIME, "/Unacceptable Hold Time"}, { BGP_NOTIFY_OPEN_UNACEP_HOLDTIME, "/Unacceptable Hold Time"},
{ BGP_NOTIFY_OPEN_UNSUP_CAPBL, "/Unsupported Capability"}, { BGP_NOTIFY_OPEN_UNSUP_CAPBL, "/Unsupported Capability"},
{ 0 }
}; };
static const int bgp_notify_open_msg_max = BGP_NOTIFY_OPEN_MAX;
static const struct message bgp_notify_update_msg[] = static const struct message bgp_notify_update_msg[] =
{ {
@ -148,8 +148,8 @@ static const struct message bgp_notify_update_msg[] =
{ BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, "/Optional Attribute Error"}, { BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, "/Optional Attribute Error"},
{ BGP_NOTIFY_UPDATE_INVAL_NETWORK, "/Invalid Network Field"}, { BGP_NOTIFY_UPDATE_INVAL_NETWORK, "/Invalid Network Field"},
{ BGP_NOTIFY_UPDATE_MAL_AS_PATH, "/Malformed AS_PATH"}, { BGP_NOTIFY_UPDATE_MAL_AS_PATH, "/Malformed AS_PATH"},
{ 0 }
}; };
static const int bgp_notify_update_msg_max = BGP_NOTIFY_UPDATE_MAX;
static const struct message bgp_notify_cease_msg[] = static const struct message bgp_notify_cease_msg[] =
{ {
@ -162,8 +162,8 @@ static const struct message bgp_notify_cease_msg[] =
{ BGP_NOTIFY_CEASE_CONFIG_CHANGE, "/Other Configuration Change"}, { BGP_NOTIFY_CEASE_CONFIG_CHANGE, "/Other Configuration Change"},
{ BGP_NOTIFY_CEASE_COLLISION_RESOLUTION, "/Connection collision resolution"}, { BGP_NOTIFY_CEASE_COLLISION_RESOLUTION, "/Connection collision resolution"},
{ BGP_NOTIFY_CEASE_OUT_OF_RESOURCE, "/Out of Resource"}, { BGP_NOTIFY_CEASE_OUT_OF_RESOURCE, "/Out of Resource"},
{ 0 }
}; };
static const int bgp_notify_cease_msg_max = BGP_NOTIFY_CEASE_MAX;
static const struct message bgp_notify_capability_msg[] = static const struct message bgp_notify_capability_msg[] =
{ {
@ -171,8 +171,8 @@ static const struct message bgp_notify_capability_msg[] =
{ BGP_NOTIFY_CAPABILITY_INVALID_ACTION, "/Invalid Action Value" }, { BGP_NOTIFY_CAPABILITY_INVALID_ACTION, "/Invalid Action Value" },
{ BGP_NOTIFY_CAPABILITY_INVALID_LENGTH, "/Invalid Capability Length"}, { BGP_NOTIFY_CAPABILITY_INVALID_LENGTH, "/Invalid Capability Length"},
{ BGP_NOTIFY_CAPABILITY_MALFORMED_CODE, "/Malformed Capability Value"}, { BGP_NOTIFY_CAPABILITY_MALFORMED_CODE, "/Malformed Capability Value"},
{ 0 }
}; };
static const int bgp_notify_capability_msg_max = BGP_NOTIFY_CAPABILITY_MAX;
/* Origin strings. */ /* Origin strings. */
const char *bgp_origin_str[] = {"i","e","?"}; const char *bgp_origin_str[] = {"i","e","?"};
@ -464,7 +464,7 @@ bgp_dump_attr (struct attr *attr, char *buf, size_t size)
const char * const char *
bgp_notify_code_str (char code) bgp_notify_code_str (char code)
{ {
return LOOKUP_DEF (bgp_notify_msg, code, "Unrecognized Error Code"); return lookup_msg (bgp_notify_msg, code, "Unrecognized Error Code");
} }
const char * const char *
@ -474,23 +474,23 @@ bgp_notify_subcode_str (char code, char subcode)
switch (code) switch (code)
{ {
case BGP_NOTIFY_HEADER_ERR: case BGP_NOTIFY_HEADER_ERR:
return LOOKUP_DEF (bgp_notify_head_msg, subcode, return lookup_msg (bgp_notify_head_msg, subcode,
"Unrecognized Error Subcode"); "Unrecognized Error Subcode");
case BGP_NOTIFY_OPEN_ERR: case BGP_NOTIFY_OPEN_ERR:
return LOOKUP_DEF (bgp_notify_open_msg, subcode, return lookup_msg (bgp_notify_open_msg, subcode,
"Unrecognized Error Subcode"); "Unrecognized Error Subcode");
case BGP_NOTIFY_UPDATE_ERR: case BGP_NOTIFY_UPDATE_ERR:
return LOOKUP_DEF (bgp_notify_update_msg, subcode, return lookup_msg (bgp_notify_update_msg, subcode,
"Unrecognized Error Subcode"); "Unrecognized Error Subcode");
case BGP_NOTIFY_HOLD_ERR: case BGP_NOTIFY_HOLD_ERR:
break; break;
case BGP_NOTIFY_FSM_ERR: case BGP_NOTIFY_FSM_ERR:
break; break;
case BGP_NOTIFY_CEASE: case BGP_NOTIFY_CEASE:
return LOOKUP_DEF (bgp_notify_cease_msg, subcode, return lookup_msg (bgp_notify_cease_msg, subcode,
"Unrecognized Error Subcode"); "Unrecognized Error Subcode");
case BGP_NOTIFY_CAPABILITY_ERR: case BGP_NOTIFY_CAPABILITY_ERR:
return LOOKUP_DEF (bgp_notify_capability_msg, subcode, return lookup_msg (bgp_notify_capability_msg, subcode,
"Unrecognized Error Subcode"); "Unrecognized Error Subcode");
} }
return ""; return "";

View File

@ -145,7 +145,6 @@ extern const char *bgp_notify_subcode_str(char, char);
extern void bgp_notify_print (struct peer *, struct bgp_notify *, const char *); extern void bgp_notify_print (struct peer *, struct bgp_notify *, const char *);
extern const struct message bgp_status_msg[]; extern const struct message bgp_status_msg[];
extern const int bgp_status_msg_max;
extern int bgp_debug_neighbor_events(struct peer *peer); extern int bgp_debug_neighbor_events(struct peer *peer);
extern int bgp_debug_keepalive(struct peer *peer); extern int bgp_debug_keepalive(struct peer *peer);
extern int bgp_debug_update(struct peer *peer, struct prefix *p, extern int bgp_debug_update(struct peer *peer, struct prefix *p,

View File

@ -971,8 +971,8 @@ bgp_fsm_change_status (struct peer *peer, int status)
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug ("%s went from %s to %s", zlog_debug ("%s went from %s to %s",
peer->host, peer->host,
LOOKUP (bgp_status_msg, peer->ostatus), lookup_msg(bgp_status_msg, peer->ostatus, NULL),
LOOKUP (bgp_status_msg, peer->status)); lookup_msg(bgp_status_msg, peer->status, NULL));
} }
/* Flush the event queue and ensure the peer is shut down */ /* Flush the event queue and ensure the peer is shut down */
@ -1413,7 +1413,7 @@ static int
bgp_fsm_event_error (struct peer *peer) bgp_fsm_event_error (struct peer *peer)
{ {
zlog_err ("%s [FSM] unexpected packet received in state %s", zlog_err ("%s [FSM] unexpected packet received in state %s",
peer->host, LOOKUP (bgp_status_msg, peer->status)); peer->host, lookup_msg(bgp_status_msg, peer->status, NULL));
return bgp_stop_with_notify (peer, BGP_NOTIFY_FSM_ERR, 0); return bgp_stop_with_notify (peer, BGP_NOTIFY_FSM_ERR, 0);
} }
@ -1599,7 +1599,7 @@ bgp_ignore (struct peer *peer)
{ {
zlog_err ("%s [FSM] Ignoring event %s in state %s, prior events %s, %s, fd %d", zlog_err ("%s [FSM] Ignoring event %s in state %s, prior events %s, %s, fd %d",
peer->host, bgp_event_str[peer->cur_event], peer->host, bgp_event_str[peer->cur_event],
LOOKUP (bgp_status_msg, peer->status), lookup_msg(bgp_status_msg, peer->status, NULL),
bgp_event_str[peer->last_event], bgp_event_str[peer->last_event],
bgp_event_str[peer->last_major_event], peer->fd); bgp_event_str[peer->last_major_event], peer->fd);
return 0; return 0;
@ -1611,7 +1611,7 @@ bgp_fsm_exeption (struct peer *peer)
{ {
zlog_err ("%s [FSM] Unexpected event %s in state %s, prior events %s, %s, fd %d", zlog_err ("%s [FSM] Unexpected event %s in state %s, prior events %s, %s, fd %d",
peer->host, bgp_event_str[peer->cur_event], peer->host, bgp_event_str[peer->cur_event],
LOOKUP (bgp_status_msg, peer->status), lookup_msg(bgp_status_msg, peer->status, NULL),
bgp_event_str[peer->last_event], bgp_event_str[peer->last_event],
bgp_event_str[peer->last_major_event], peer->fd); bgp_event_str[peer->last_major_event], peer->fd);
return(bgp_stop (peer)); return(bgp_stop (peer));
@ -1837,8 +1837,8 @@ bgp_event_update (struct peer *peer, int event)
if (bgp_debug_neighbor_events(peer) && peer->status != next) if (bgp_debug_neighbor_events(peer) && peer->status != next)
zlog_debug ("%s [FSM] %s (%s->%s), fd %d", peer->host, zlog_debug ("%s [FSM] %s (%s->%s), fd %d", peer->host,
bgp_event_str[event], bgp_event_str[event],
LOOKUP (bgp_status_msg, peer->status), lookup_msg(bgp_status_msg, peer->status, NULL),
LOOKUP (bgp_status_msg, next), peer->fd); lookup_msg(bgp_status_msg, next, NULL), peer->fd);
peer->last_event = peer->cur_event; peer->last_event = peer->cur_event;
peer->cur_event = event; peer->cur_event = event;
@ -1873,7 +1873,7 @@ bgp_event_update (struct peer *peer, int event)
zlog_err ("%s [FSM] Failure handling event %s in state %s, " zlog_err ("%s [FSM] Failure handling event %s in state %s, "
"prior events %s, %s, fd %d", "prior events %s, %s, fd %d",
peer->host, bgp_event_str[peer->cur_event], peer->host, bgp_event_str[peer->cur_event],
LOOKUP (bgp_status_msg, peer->status), lookup_msg(bgp_status_msg, peer->status, NULL),
bgp_event_str[peer->last_event], bgp_event_str[peer->last_event],
bgp_event_str[peer->last_major_event], peer->fd); bgp_event_str[peer->last_major_event], peer->fd);
bgp_stop (peer); bgp_stop (peer);

View File

@ -251,16 +251,16 @@ static const struct message orf_type_str[] =
{ {
{ ORF_TYPE_PREFIX, "Prefixlist" }, { ORF_TYPE_PREFIX, "Prefixlist" },
{ ORF_TYPE_PREFIX_OLD, "Prefixlist (old)" }, { ORF_TYPE_PREFIX_OLD, "Prefixlist (old)" },
{ 0 }
}; };
static const int orf_type_str_max = array_size(orf_type_str);
static const struct message orf_mode_str[] = static const struct message orf_mode_str[] =
{ {
{ ORF_MODE_RECEIVE, "Receive" }, { ORF_MODE_RECEIVE, "Receive" },
{ ORF_MODE_SEND, "Send" }, { ORF_MODE_SEND, "Send" },
{ ORF_MODE_BOTH, "Both" }, { ORF_MODE_BOTH, "Both" },
{ 0 }
}; };
static const int orf_mode_str_max = array_size(orf_mode_str);
static int static int
bgp_capability_orf_entry (struct peer *peer, struct capability_header *hdr) bgp_capability_orf_entry (struct peer *peer, struct capability_header *hdr)
@ -366,8 +366,8 @@ bgp_capability_orf_entry (struct peer *peer, struct capability_header *hdr)
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug ("%s OPEN has %s ORF capability" zlog_debug ("%s OPEN has %s ORF capability"
" as %s for afi/safi: %d/%d", " as %s for afi/safi: %d/%d",
peer->host, LOOKUP (orf_type_str, type), peer->host, lookup_msg(orf_type_str, type, NULL),
LOOKUP (orf_mode_str, mode), lookup_msg(orf_mode_str, mode, NULL),
pkt_afi, pkt_safi); pkt_afi, pkt_safi);
if (hdr->code == CAPABILITY_CODE_ORF) if (hdr->code == CAPABILITY_CODE_ORF)
@ -717,8 +717,8 @@ bgp_capability_hostname (struct peer *peer, struct capability_header *hdr)
{ CAPABILITY_CODE_REFRESH_OLD, "Route Refresh (Old)" }, { CAPABILITY_CODE_REFRESH_OLD, "Route Refresh (Old)" },
{ CAPABILITY_CODE_ORF_OLD, "ORF (Old)" }, { CAPABILITY_CODE_ORF_OLD, "ORF (Old)" },
{ CAPABILITY_CODE_FQDN, "FQDN" }, { CAPABILITY_CODE_FQDN, "FQDN" },
{ 0 }
}; };
static const int capcode_str_max = array_size(capcode_str);
/* Minimum sizes for length field of each cap (so not inc. the header) */ /* Minimum sizes for length field of each cap (so not inc. the header) */
static const size_t cap_minsizes[] = static const size_t cap_minsizes[] =
@ -805,7 +805,7 @@ bgp_capability_parse (struct peer *peer, size_t length, int *mp_capability,
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug ("%s OPEN has %s capability (%u), length %u", zlog_debug ("%s OPEN has %s capability (%u), length %u",
peer->host, peer->host,
LOOKUP (capcode_str, caphdr.code), lookup_msg(capcode_str, caphdr.code, NULL),
caphdr.code, caphdr.length); caphdr.code, caphdr.length);
/* Length sanity check, type-specific, for known capabilities */ /* Length sanity check, type-specific, for known capabilities */
@ -829,7 +829,7 @@ bgp_capability_parse (struct peer *peer, size_t length, int *mp_capability,
zlog_info ("%s %s Capability length error: got %u," zlog_info ("%s %s Capability length error: got %u,"
" expected at least %u", " expected at least %u",
peer->host, peer->host,
LOOKUP (capcode_str, caphdr.code), lookup_msg(capcode_str, caphdr.code, NULL),
caphdr.length, caphdr.length,
(unsigned) cap_minsizes[caphdr.code]); (unsigned) cap_minsizes[caphdr.code]);
bgp_notify_send (peer, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_MALFORMED_ATTR); bgp_notify_send (peer, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_MALFORMED_ATTR);
@ -841,7 +841,7 @@ bgp_capability_parse (struct peer *peer, size_t length, int *mp_capability,
zlog_info ("%s %s Capability length error: got %u," zlog_info ("%s %s Capability length error: got %u,"
" expected a multiple of %u", " expected a multiple of %u",
peer->host, peer->host,
LOOKUP (capcode_str, caphdr.code), lookup_msg(capcode_str, caphdr.code, NULL),
caphdr.length, caphdr.length,
(unsigned) cap_modsizes[caphdr.code]); (unsigned) cap_modsizes[caphdr.code]);
bgp_notify_send (peer, BGP_NOTIFY_OPEN_ERR, bgp_notify_send (peer, BGP_NOTIFY_OPEN_ERR,
@ -940,7 +940,7 @@ bgp_capability_parse (struct peer *peer, size_t length, int *mp_capability,
{ {
if (stream_get_getp(s) > (start + caphdr.length)) if (stream_get_getp(s) > (start + caphdr.length))
zlog_warn ("%s Cap-parser for %s read past cap-length, %u!", zlog_warn ("%s Cap-parser for %s read past cap-length, %u!",
peer->host, LOOKUP (capcode_str, caphdr.code), peer->host, lookup_msg(capcode_str, caphdr.code, NULL),
caphdr.length); caphdr.length);
stream_set_getp (s, start + caphdr.length); stream_set_getp (s, start + caphdr.length);
} }

View File

@ -1382,7 +1382,7 @@ bgp_update_receive (struct peer *peer, bgp_size_t size)
if (peer->status != Established) if (peer->status != Established)
{ {
zlog_err ("%s [FSM] Update packet received under status %s", zlog_err ("%s [FSM] Update packet received under status %s",
peer->host, LOOKUP (bgp_status_msg, peer->status)); peer->host, lookup_msg(bgp_status_msg, peer->status, NULL));
bgp_notify_send (peer, BGP_NOTIFY_FSM_ERR, 0); bgp_notify_send (peer, BGP_NOTIFY_FSM_ERR, 0);
return -1; return -1;
} }
@ -1749,7 +1749,7 @@ bgp_route_refresh_receive (struct peer *peer, bgp_size_t size)
if (peer->status != Established) if (peer->status != Established)
{ {
zlog_err ("%s [Error] Route refresh packet received under status %s", zlog_err ("%s [Error] Route refresh packet received under status %s",
peer->host, LOOKUP (bgp_status_msg, peer->status)); peer->host, lookup_msg(bgp_status_msg, peer->status, NULL));
bgp_notify_send (peer, BGP_NOTIFY_FSM_ERR, 0); bgp_notify_send (peer, BGP_NOTIFY_FSM_ERR, 0);
return; return;
} }
@ -2078,7 +2078,7 @@ bgp_capability_receive (struct peer *peer, bgp_size_t size)
if (peer->status != Established) if (peer->status != Established)
{ {
zlog_err ("%s [Error] Dynamic capability packet received under status %s", zlog_err ("%s [Error] Dynamic capability packet received under status %s",
peer->host, LOOKUP (bgp_status_msg, peer->status)); peer->host, lookup_msg(bgp_status_msg, peer->status, NULL));
bgp_notify_send (peer, BGP_NOTIFY_FSM_ERR, 0); bgp_notify_send (peer, BGP_NOTIFY_FSM_ERR, 0);
return -1; return -1;
} }

View File

@ -7207,7 +7207,7 @@ bgp_show_summary (struct vty *vty, struct bgp *bgp, int afi, int safi,
else if (CHECK_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW)) else if (CHECK_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW))
json_object_string_add(json_peer, "state", "Idle (PfxCt)"); json_object_string_add(json_peer, "state", "Idle (PfxCt)");
else else
json_object_string_add(json_peer, "state", LOOKUP(bgp_status_msg, peer->status)); json_object_string_add(json_peer, "state", lookup_msg(bgp_status_msg, peer->status, NULL));
if (peer->conf_if) if (peer->conf_if)
json_object_string_add(json_peer, "idType", "interface"); json_object_string_add(json_peer, "idType", "interface");
@ -7259,7 +7259,7 @@ bgp_show_summary (struct vty *vty, struct bgp *bgp, int afi, int safi,
else if (CHECK_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW)) else if (CHECK_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW))
vty_out (vty, " Idle (PfxCt)"); vty_out (vty, " Idle (PfxCt)");
else else
vty_out (vty, " %12s", LOOKUP(bgp_status_msg, peer->status)); vty_out (vty, " %12s", lookup_msg(bgp_status_msg, peer->status, NULL));
} }
vty_out (vty, "%s", VTY_NEWLINE); vty_out (vty, "%s", VTY_NEWLINE);
} }
@ -8249,7 +8249,7 @@ bgp_show_peer (struct vty *vty, struct peer *p, u_char use_json, json_object *js
json_object_boolean_true_add(json_neigh, "nbrCommonAdmin"); json_object_boolean_true_add(json_neigh, "nbrCommonAdmin");
/* Status. */ /* Status. */
json_object_string_add(json_neigh, "bgpState", LOOKUP (bgp_status_msg, p->status)); json_object_string_add(json_neigh, "bgpState", lookup_msg(bgp_status_msg, p->status, NULL));
if (p->status == Established) if (p->status == Established)
{ {
@ -8322,7 +8322,7 @@ bgp_show_peer (struct vty *vty, struct peer *p, u_char use_json, json_object *js
vty_out (vty, " Neighbor under common administration%s", VTY_NEWLINE); vty_out (vty, " Neighbor under common administration%s", VTY_NEWLINE);
/* Status. */ /* Status. */
vty_out (vty, " BGP state = %s", LOOKUP (bgp_status_msg, p->status)); vty_out (vty, " BGP state = %s", lookup_msg(bgp_status_msg, p->status, NULL));
if (p->status == Established) if (p->status == Established)
vty_out (vty, ", up for %8s", peer_uptime (p->uptime, timebuf, BGP_UPTIME_LEN, 0, NULL)); vty_out (vty, ", up for %8s", peer_uptime (p->uptime, timebuf, BGP_UPTIME_LEN, 0, NULL));
@ -10027,7 +10027,7 @@ bgp_show_one_peer_group (struct vty *vty, struct peer_group *group)
else if (CHECK_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW)) else if (CHECK_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW))
peer_status = "Idle (PfxCt)"; peer_status = "Idle (PfxCt)";
else else
peer_status = LOOKUP(bgp_status_msg, peer->status); peer_status = lookup_msg(bgp_status_msg, peer->status, NULL);
dynamic = peer_dynamic_neighbor(peer); dynamic = peer_dynamic_neighbor(peer);
vty_out (vty, " %s %s %s %s", vty_out (vty, " %s %s %s %s",

View File

@ -991,7 +991,6 @@ struct bgp_nlri
#define BGP_NOTIFY_FSM_ERR 5 #define BGP_NOTIFY_FSM_ERR 5
#define BGP_NOTIFY_CEASE 6 #define BGP_NOTIFY_CEASE 6
#define BGP_NOTIFY_CAPABILITY_ERR 7 #define BGP_NOTIFY_CAPABILITY_ERR 7
#define BGP_NOTIFY_MAX 8
#define BGP_NOTIFY_SUBCODE_UNSPECIFIC 0 #define BGP_NOTIFY_SUBCODE_UNSPECIFIC 0
@ -999,7 +998,6 @@ struct bgp_nlri
#define BGP_NOTIFY_HEADER_NOT_SYNC 1 #define BGP_NOTIFY_HEADER_NOT_SYNC 1
#define BGP_NOTIFY_HEADER_BAD_MESLEN 2 #define BGP_NOTIFY_HEADER_BAD_MESLEN 2
#define BGP_NOTIFY_HEADER_BAD_MESTYPE 3 #define BGP_NOTIFY_HEADER_BAD_MESTYPE 3
#define BGP_NOTIFY_HEADER_MAX 4
/* BGP_NOTIFY_OPEN_ERR sub codes. */ /* BGP_NOTIFY_OPEN_ERR sub codes. */
#define BGP_NOTIFY_OPEN_MALFORMED_ATTR 0 #define BGP_NOTIFY_OPEN_MALFORMED_ATTR 0
@ -1010,7 +1008,6 @@ struct bgp_nlri
#define BGP_NOTIFY_OPEN_AUTH_FAILURE 5 #define BGP_NOTIFY_OPEN_AUTH_FAILURE 5
#define BGP_NOTIFY_OPEN_UNACEP_HOLDTIME 6 #define BGP_NOTIFY_OPEN_UNACEP_HOLDTIME 6
#define BGP_NOTIFY_OPEN_UNSUP_CAPBL 7 #define BGP_NOTIFY_OPEN_UNSUP_CAPBL 7
#define BGP_NOTIFY_OPEN_MAX 8
/* BGP_NOTIFY_UPDATE_ERR sub codes. */ /* BGP_NOTIFY_UPDATE_ERR sub codes. */
#define BGP_NOTIFY_UPDATE_MAL_ATTR 1 #define BGP_NOTIFY_UPDATE_MAL_ATTR 1
@ -1024,7 +1021,6 @@ struct bgp_nlri
#define BGP_NOTIFY_UPDATE_OPT_ATTR_ERR 9 #define BGP_NOTIFY_UPDATE_OPT_ATTR_ERR 9
#define BGP_NOTIFY_UPDATE_INVAL_NETWORK 10 #define BGP_NOTIFY_UPDATE_INVAL_NETWORK 10
#define BGP_NOTIFY_UPDATE_MAL_AS_PATH 11 #define BGP_NOTIFY_UPDATE_MAL_AS_PATH 11
#define BGP_NOTIFY_UPDATE_MAX 12
/* BGP_NOTIFY_CEASE sub codes (RFC 4486). */ /* BGP_NOTIFY_CEASE sub codes (RFC 4486). */
#define BGP_NOTIFY_CEASE_MAX_PREFIX 1 #define BGP_NOTIFY_CEASE_MAX_PREFIX 1
@ -1035,13 +1031,11 @@ struct bgp_nlri
#define BGP_NOTIFY_CEASE_CONFIG_CHANGE 6 #define BGP_NOTIFY_CEASE_CONFIG_CHANGE 6
#define BGP_NOTIFY_CEASE_COLLISION_RESOLUTION 7 #define BGP_NOTIFY_CEASE_COLLISION_RESOLUTION 7
#define BGP_NOTIFY_CEASE_OUT_OF_RESOURCE 8 #define BGP_NOTIFY_CEASE_OUT_OF_RESOURCE 8
#define BGP_NOTIFY_CEASE_MAX 9
/* BGP_NOTIFY_CAPABILITY_ERR sub codes (draft-ietf-idr-dynamic-cap-02). */ /* BGP_NOTIFY_CAPABILITY_ERR sub codes (draft-ietf-idr-dynamic-cap-02). */
#define BGP_NOTIFY_CAPABILITY_INVALID_ACTION 1 #define BGP_NOTIFY_CAPABILITY_INVALID_ACTION 1
#define BGP_NOTIFY_CAPABILITY_INVALID_LENGTH 2 #define BGP_NOTIFY_CAPABILITY_INVALID_LENGTH 2
#define BGP_NOTIFY_CAPABILITY_MALFORMED_CODE 3 #define BGP_NOTIFY_CAPABILITY_MALFORMED_CODE 3
#define BGP_NOTIFY_CAPABILITY_MAX 4
/* BGP finite state machine status. */ /* BGP finite state machine status. */
#define Idle 1 #define Idle 1

View File

@ -371,7 +371,7 @@ DEFUN (show_debugging_eigrp,
if (IS_DEBUG_EIGRP_PACKET (i, SEND) && IS_DEBUG_EIGRP_PACKET (i, RECV)) if (IS_DEBUG_EIGRP_PACKET (i, SEND) && IS_DEBUG_EIGRP_PACKET (i, RECV))
{ {
vty_out (vty, " EIGRP packet %s%s debugging is on%s", vty_out (vty, " EIGRP packet %s%s debugging is on%s",
LOOKUP (eigrp_packet_type_str, i + 1), lookup_msg(eigrp_packet_type_str, i + 1, NULL),
IS_DEBUG_EIGRP_PACKET (i, PACKET_DETAIL) ? " detail" : "", IS_DEBUG_EIGRP_PACKET (i, PACKET_DETAIL) ? " detail" : "",
VTY_NEWLINE); VTY_NEWLINE);
} }
@ -379,12 +379,12 @@ DEFUN (show_debugging_eigrp,
{ {
if (IS_DEBUG_EIGRP_PACKET (i, SEND)) if (IS_DEBUG_EIGRP_PACKET (i, SEND))
vty_out (vty, " EIGRP packet %s send%s debugging is on%s", vty_out (vty, " EIGRP packet %s send%s debugging is on%s",
LOOKUP (eigrp_packet_type_str, i + 1), lookup_msg(eigrp_packet_type_str, i + 1, NULL),
IS_DEBUG_EIGRP_PACKET (i, PACKET_DETAIL) ? " detail" : "", IS_DEBUG_EIGRP_PACKET (i, PACKET_DETAIL) ? " detail" : "",
VTY_NEWLINE); VTY_NEWLINE);
if (IS_DEBUG_EIGRP_PACKET (i, RECV)) if (IS_DEBUG_EIGRP_PACKET (i, RECV))
vty_out (vty, " EIGRP packet %s receive%s debugging is on%s", vty_out (vty, " EIGRP packet %s receive%s debugging is on%s",
LOOKUP (eigrp_packet_type_str, i + 1), lookup_msg(eigrp_packet_type_str, i + 1, NULL),
IS_DEBUG_EIGRP_PACKET (i, PACKET_DETAIL) ? " detail" : "", IS_DEBUG_EIGRP_PACKET (i, PACKET_DETAIL) ? " detail" : "",
VTY_NEWLINE); VTY_NEWLINE);
} }

View File

@ -66,11 +66,9 @@ static const struct message eigrp_general_tlv_type_str[] =
{ EIGRP_TLV_PEER_TERMINATION, "PEER_TERMINATION" }, { EIGRP_TLV_PEER_TERMINATION, "PEER_TERMINATION" },
{ EIGRP_TLV_PEER_MTRLIST, "PEER_MTRLIST" }, { EIGRP_TLV_PEER_MTRLIST, "PEER_MTRLIST" },
{ EIGRP_TLV_PEER_TIDLIST, "PEER_TIDLIST" }, { EIGRP_TLV_PEER_TIDLIST, "PEER_TIDLIST" },
{ 0 }
}; };
static const size_t eigrp_general_tlv_type_str_max = sizeof(eigrp_general_tlv_type_str) /
sizeof(eigrp_general_tlv_type_str[0]);
/* /*
* @fn eigrp_hello_timer * @fn eigrp_hello_timer
@ -346,7 +344,7 @@ eigrp_hello_receive (struct eigrp *eigrp, struct ip *iph, struct eigrp_header *e
if ((length > 0) && (length <= size)) if ((length > 0) && (length <= size))
{ {
if (IS_DEBUG_EIGRP_PACKET(0, RECV)) if (IS_DEBUG_EIGRP_PACKET(0, RECV))
zlog_debug(" General TLV(%s)", LOOKUP(eigrp_general_tlv_type_str, type)); zlog_debug(" General TLV(%s)", lookup_msg(eigrp_general_tlv_type_str, type, NULL));
// determine what General TLV is being processed // determine what General TLV is being processed
switch (type) switch (type)

View File

@ -69,10 +69,9 @@ const struct message eigrp_packet_type_str[] =
{ EIGRP_OPC_ACK, "Ack"}, { EIGRP_OPC_ACK, "Ack"},
{ EIGRP_OPC_SIAQUERY, "SIAQuery"}, { EIGRP_OPC_SIAQUERY, "SIAQuery"},
{ EIGRP_OPC_SIAREPLY, "SIAReply"}, { EIGRP_OPC_SIAREPLY, "SIAReply"},
{ 0 }
}; };
const size_t eigrp_packet_type_str_max = sizeof(eigrp_packet_type_str) /
sizeof(eigrp_packet_type_str[0]);
static unsigned char zeropad[16] = {0}; static unsigned char zeropad[16] = {0};
@ -419,7 +418,8 @@ eigrp_write (struct thread *thread)
eigrph = (struct eigrp_header *) STREAM_DATA(ep->s); eigrph = (struct eigrp_header *) STREAM_DATA(ep->s);
opcode = eigrph->opcode; opcode = eigrph->opcode;
zlog_debug("Sending [%s] to [%s] via [%s] ret [%d].", zlog_debug("Sending [%s] to [%s] via [%s] ret [%d].",
LOOKUP(eigrp_packet_type_str, opcode), inet_ntoa(ep->dst), lookup_msg(eigrp_packet_type_str, opcode, NULL),
inet_ntoa(ep->dst),
IF_NAME(ei), ret); IF_NAME(ei), ret);
} }
@ -612,7 +612,7 @@ eigrp_read (struct thread *thread)
if (IS_DEBUG_EIGRP_TRANSMIT(0, RECV)) if (IS_DEBUG_EIGRP_TRANSMIT(0, RECV))
zlog_debug("Received [%s] length [%u] via [%s] src [%s] dst [%s]", zlog_debug("Received [%s] length [%u] via [%s] src [%s] dst [%s]",
LOOKUP(eigrp_packet_type_str, opcode), length, lookup_msg(eigrp_packet_type_str, opcode, NULL), length,
IF_NAME(ei), inet_ntoa(iph->ip_src), inet_ntoa(iph->ip_dst)); IF_NAME(ei), inet_ntoa(iph->ip_src), inet_ntoa(iph->ip_dst));
/* Read rest of the packet and call each sort of packet routine. */ /* Read rest of the packet and call each sort of packet routine. */

View File

@ -503,9 +503,8 @@ struct message tokennames[] = {
item(JOIN_TKN), item(JOIN_TKN),
item(START_TKN), // first token in line item(START_TKN), // first token in line
item(END_TKN), // last token in line item(END_TKN), // last token in line
{ 0, NULL } { 0 }
}; };
size_t tokennames_max = array_size(tokennames);
/** /**
* Pretty-prints a graph, assuming it is a tree. * Pretty-prints a graph, assuming it is a tree.
@ -522,7 +521,7 @@ pretty_print_graph (struct vty *vty, struct graph_node *start, int level,
struct cmd_token *tok = start->data; struct cmd_token *tok = start->data;
snprintf(tokennum, sizeof(tokennum), "%d?", tok->type); snprintf(tokennum, sizeof(tokennum), "%d?", tok->type);
vty_out(vty, "%s", LOOKUP_DEF(tokennames, tok->type, tokennum)); vty_out(vty, "%s", lookup_msg(tokennames, tok->type, NULL));
if (tok->text) if (tok->text)
vty_out(vty, ":\"%s\"", tok->text); vty_out(vty, ":\"%s\"", tok->text);
if (tok->varname) if (tok->varname)
@ -591,7 +590,7 @@ pretty_print_dot (FILE *ofd, unsigned opts, struct graph_node *start,
snprintf(tokennum, sizeof(tokennum), "%d?", tok->type); snprintf(tokennum, sizeof(tokennum), "%d?", tok->type);
fprintf(ofd, " n%p [ shape=box, label=<", start); fprintf(ofd, " n%p [ shape=box, label=<", start);
fprintf(ofd, "<b>%s</b>", LOOKUP_DEF(tokennames, tok->type, tokennum)); fprintf(ofd, "<b>%s</b>", lookup_msg(tokennames, tok->type, NULL));
if (tok->attr == CMD_ATTR_DEPRECATED) if (tok->attr == CMD_ATTR_DEPRECATED)
fprintf(ofd, " (d)"); fprintf(ofd, " (d)");
else if (tok->attr == CMD_ATTR_HIDDEN) else if (tok->attr == CMD_ATTR_HIDDEN)

View File

@ -85,8 +85,33 @@ static void write_wrapper (int fd, const void *buf, size_t count)
return; return;
} }
/* For time string format. */ /**
* Looks up a message in a message list by key.
*
* If the message is not found, returns the provided error message.
*
* Terminates when it hits a struct message that's all zeros.
*
* @param mz the message list
* @param kz the message key
* @param nf the message to return if not found
* @return the message
*/
const char *
lookup_msg(const struct message *mz, int kz, const char *nf)
{
static struct message nt = { 0 };
const char *rz = nf ? nf : "(no message found)";
const struct message *pnt;
for (pnt = mz; memcmp(pnt, &nt, sizeof(struct message)); pnt++)
if (pnt->key == kz) {
rz = pnt->str ? pnt->str : rz;
break;
}
return rz;
}
/* For time string format. */
size_t size_t
quagga_timestamp(int timestamp_precision, char *buf, size_t buflen) quagga_timestamp(int timestamp_precision, char *buf, size_t buflen)
{ {
@ -851,61 +876,6 @@ zlog_rotate (void)
return 1; return 1;
} }
/* Message lookup function. */
const char *
lookup (const struct message *mes, int key)
{
const struct message *pnt;
for (pnt = mes; pnt->key != 0; pnt++)
if (pnt->key == key)
return pnt->str;
return "";
}
/* Older/faster version of message lookup function, but requires caller to pass
* in the array size (instead of relying on a 0 key to terminate the search).
*
* The return value is the message string if found, or the 'none' pointer
* provided otherwise.
*/
const char *
mes_lookup (const struct message *meslist, int max, int index,
const char *none, const char *mesname)
{
int pos = index - meslist[0].key;
/* first check for best case: index is in range and matches the key
* value in that slot.
* NB: key numbering might be offset from 0. E.g. protocol constants
* often start at 1.
*/
if ((pos >= 0) && (pos < max)
&& (meslist[pos].key == index))
return meslist[pos].str;
/* fall back to linear search */
{
int i;
for (i = 0; i < max; i++, meslist++)
{
if (meslist->key == index)
{
const char *str = (meslist->str ? meslist->str : none);
zlog_debug ("message index %d [%s] found in %s at position %d (max is %d)",
index, str, mesname, i, max);
return str;
}
}
}
zlog_err("message index %d not found in %s (max is %d)", index, mesname, max);
assert (none);
return none;
}
/* Wrapper around strerror to handle case where it returns NULL. */ /* Wrapper around strerror to handle case where it returns NULL. */
const char * const char *
safe_strerror(int errnum) safe_strerror(int errnum)

View File

@ -99,14 +99,7 @@ extern int zlog_reset_file (void);
/* Rotate log. */ /* Rotate log. */
extern int zlog_rotate (void); extern int zlog_rotate (void);
/* For hackey message lookup and check */ const char *lookup_msg (const struct message *mz, int kz, const char *nf);
#define LOOKUP_DEF(x, y, def) mes_lookup(x, x ## _max, y, def, #x)
#define LOOKUP(x, y) LOOKUP_DEF(x, y, "(no item found)")
extern const char *lookup (const struct message *, int);
extern const char *mes_lookup (const struct message *meslist,
int max, int index,
const char *no_item, const char *mesname);
/* Safe version of strerror -- never returns NULL. */ /* Safe version of strerror -- never returns NULL. */
extern const char *safe_strerror(int errnum); extern const char *safe_strerror(int errnum);

View File

@ -47,14 +47,14 @@ static const struct message debug_flags_desc[] = {
{ NHRP_DEBUG_ROUTE, "route" }, { NHRP_DEBUG_ROUTE, "route" },
{ NHRP_DEBUG_VICI, "vici" }, { NHRP_DEBUG_VICI, "vici" },
{ NHRP_DEBUG_EVENT, "event" }, { NHRP_DEBUG_EVENT, "event" },
{ 0, NULL }, { 0 }
}; };
static const struct message interface_flags_desc[] = { static const struct message interface_flags_desc[] = {
{ NHRP_IFF_SHORTCUT, "shortcut" }, { NHRP_IFF_SHORTCUT, "shortcut" },
{ NHRP_IFF_REDIRECT, "redirect" }, { NHRP_IFF_REDIRECT, "redirect" },
{ NHRP_IFF_REG_NO_UNIQUE, "registration no-unique" }, { NHRP_IFF_REG_NO_UNIQUE, "registration no-unique" },
{ 0, NULL }, { 0 }
}; };
static int nhrp_vty_return(struct vty *vty, int ret) static int nhrp_vty_return(struct vty *vty, int ret)

View File

@ -56,8 +56,8 @@ static const struct message ospf6_message_type_str [] =
{ OSPF6_MESSAGE_TYPE_LSREQ, "LSReq" }, { OSPF6_MESSAGE_TYPE_LSREQ, "LSReq" },
{ OSPF6_MESSAGE_TYPE_LSUPDATE, "LSUpdate" }, { OSPF6_MESSAGE_TYPE_LSUPDATE, "LSUpdate" },
{ OSPF6_MESSAGE_TYPE_LSACK, "LSAck" }, { OSPF6_MESSAGE_TYPE_LSACK, "LSAck" },
{ 0 }
}; };
static const size_t ospf6_message_type_str_max = array_size(ospf6_message_type_str);
/* Minimum (besides the standard OSPF packet header) lengths for OSPF /* Minimum (besides the standard OSPF packet header) lengths for OSPF
packets of particular types, offset is the "type" field. */ packets of particular types, offset is the "type" field. */
@ -1207,7 +1207,7 @@ ospf6_packet_examin (struct ospf6_header *oh, const unsigned bytesonwire)
{ {
if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV))
zlog_debug ("%s: undersized (%u B) %s packet", __func__, zlog_debug ("%s: undersized (%u B) %s packet", __func__,
bytesonwire, LOOKUP (ospf6_message_type_str, oh->type)); bytesonwire, lookup_msg(ospf6_message_type_str, oh->type, NULL));
return MSG_NG; return MSG_NG;
} }
/* type-specific deeper validation */ /* type-specific deeper validation */
@ -1220,7 +1220,7 @@ ospf6_packet_examin (struct ospf6_header *oh, const unsigned bytesonwire)
return MSG_OK; return MSG_OK;
if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV))
zlog_debug ("%s: alignment error in %s packet", zlog_debug ("%s: alignment error in %s packet",
__func__, LOOKUP (ospf6_message_type_str, oh->type)); __func__, lookup_msg(ospf6_message_type_str, oh->type, NULL));
return MSG_NG; return MSG_NG;
case OSPF6_MESSAGE_TYPE_DBDESC: case OSPF6_MESSAGE_TYPE_DBDESC:
/* RFC5340 A.3.3, packet header + OSPF6_DB_DESC_MIN_SIZE bytes followed /* RFC5340 A.3.3, packet header + OSPF6_DB_DESC_MIN_SIZE bytes followed
@ -1239,7 +1239,7 @@ ospf6_packet_examin (struct ospf6_header *oh, const unsigned bytesonwire)
return MSG_OK; return MSG_OK;
if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV))
zlog_debug ("%s: alignment error in %s packet", zlog_debug ("%s: alignment error in %s packet",
__func__, LOOKUP (ospf6_message_type_str, oh->type)); __func__, lookup_msg(ospf6_message_type_str, oh->type, NULL));
return MSG_NG; return MSG_NG;
case OSPF6_MESSAGE_TYPE_LSUPDATE: case OSPF6_MESSAGE_TYPE_LSUPDATE:
/* RFC5340 A.3.5, packet header + OSPF6_LS_UPD_MIN_SIZE bytes followed /* RFC5340 A.3.5, packet header + OSPF6_LS_UPD_MIN_SIZE bytes followed
@ -1269,7 +1269,7 @@ ospf6_packet_examin (struct ospf6_header *oh, const unsigned bytesonwire)
return MSG_NG; return MSG_NG;
} }
if (test != MSG_OK && IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) if (test != MSG_OK && IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV))
zlog_debug ("%s: anomaly in %s packet", __func__, LOOKUP (ospf6_message_type_str, oh->type)); zlog_debug ("%s: anomaly in %s packet", __func__, lookup_msg(ospf6_message_type_str, oh->type, NULL));
return test; return test;
} }
@ -1577,7 +1577,7 @@ ospf6_receive (struct thread *thread)
inet_ntop (AF_INET6, &src, srcname, sizeof (srcname)); inet_ntop (AF_INET6, &src, srcname, sizeof (srcname));
inet_ntop (AF_INET6, &dst, dstname, sizeof (dstname)); inet_ntop (AF_INET6, &dst, dstname, sizeof (dstname));
zlog_debug ("%s received on %s", zlog_debug ("%s received on %s",
LOOKUP (ospf6_message_type_str, oh->type), oi->interface->name); lookup_msg(ospf6_message_type_str, oh->type, NULL), oi->interface->name);
zlog_debug (" src: %s", srcname); zlog_debug (" src: %s", srcname);
zlog_debug (" dst: %s", dstname); zlog_debug (" dst: %s", dstname);
@ -1665,7 +1665,7 @@ ospf6_send (struct in6_addr *src, struct in6_addr *dst,
else else
memset (srcname, 0, sizeof (srcname)); memset (srcname, 0, sizeof (srcname));
zlog_debug ("%s send on %s", zlog_debug ("%s send on %s",
LOOKUP (ospf6_message_type_str, oh->type), oi->interface->name); lookup_msg(ospf6_message_type_str, oh->type, NULL), oi->interface->name);
zlog_debug (" src: %s", srcname); zlog_debug (" src: %s", srcname);
zlog_debug (" dst: %s", dstname); zlog_debug (" dst: %s", dstname);

View File

@ -267,7 +267,7 @@ ism_change_callback (struct in_addr ifaddr, struct in_addr area_id,
{ {
printf ("ism_change: ifaddr: %s ", inet_ntoa (ifaddr)); printf ("ism_change: ifaddr: %s ", inet_ntoa (ifaddr));
printf ("area_id: %s\n", inet_ntoa (area_id)); printf ("area_id: %s\n", inet_ntoa (area_id));
printf ("state: %d [%s]\n", state, LOOKUP (ospf_ism_state_msg, state)); printf ("state: %d [%s]\n", state, lookup_msg(ospf_ism_state_msg, state, NULL));
} }
static void static void
@ -277,7 +277,7 @@ nsm_change_callback (struct in_addr ifaddr, struct in_addr nbraddr,
printf ("nsm_change: ifaddr: %s ", inet_ntoa (ifaddr)); printf ("nsm_change: ifaddr: %s ", inet_ntoa (ifaddr));
printf ("nbraddr: %s\n", inet_ntoa (nbraddr)); printf ("nbraddr: %s\n", inet_ntoa (nbraddr));
printf ("router_id: %s\n", inet_ntoa (router_id)); printf ("router_id: %s\n", inet_ntoa (router_id));
printf ("state: %d [%s]\n", state, LOOKUP (ospf_nsm_state_msg, state)); printf ("state: %d [%s]\n", state, lookup_msg(ospf_nsm_state_msg, state, NULL));
} }

View File

@ -153,8 +153,8 @@ ospf_nbr_state_message (struct ospf_neighbor *nbr, char *buf, size_t size)
memset (buf, 0, size); memset (buf, 0, size);
snprintf (buf, size, "%s/%s", snprintf (buf, size, "%s/%s",
LOOKUP (ospf_nsm_state_msg, nbr->state), lookup_msg(ospf_nsm_state_msg, nbr->state, NULL),
LOOKUP (ospf_ism_state_msg, state)); lookup_msg(ospf_ism_state_msg, state, NULL));
} }
const char * const char *
@ -559,12 +559,12 @@ ospf_header_dump (struct ospf_header *ospfh)
zlog_debug ("Header"); zlog_debug ("Header");
zlog_debug (" Version %d", ospfh->version); zlog_debug (" Version %d", ospfh->version);
zlog_debug (" Type %d (%s)", ospfh->type, zlog_debug (" Type %d (%s)", ospfh->type,
LOOKUP (ospf_packet_type_str, ospfh->type)); lookup_msg(ospf_packet_type_str, ospfh->type, NULL));
zlog_debug (" Packet Len %d", ntohs (ospfh->length)); zlog_debug (" Packet Len %d", ntohs (ospfh->length));
zlog_debug (" Router ID %s", inet_ntoa (ospfh->router_id)); zlog_debug (" Router ID %s", inet_ntoa (ospfh->router_id));
zlog_debug (" Area ID %s", inet_ntoa (ospfh->area_id)); zlog_debug (" Area ID %s", inet_ntoa (ospfh->area_id));
zlog_debug (" Checksum 0x%x", ntohs (ospfh->checksum)); zlog_debug (" Checksum 0x%x", ntohs (ospfh->checksum));
zlog_debug (" AuType %s", LOOKUP (ospf_auth_type_str, auth_type)); zlog_debug (" AuType %s", lookup_msg(ospf_auth_type_str, auth_type, NULL));
switch (auth_type) switch (auth_type)
{ {
@ -1608,7 +1608,7 @@ show_debugging_ospf_common (struct vty *vty, struct ospf *ospf)
if (IS_DEBUG_OSPF_PACKET (i, SEND) && IS_DEBUG_OSPF_PACKET (i, RECV)) if (IS_DEBUG_OSPF_PACKET (i, SEND) && IS_DEBUG_OSPF_PACKET (i, RECV))
{ {
vty_out (vty, " OSPF packet %s%s debugging is on%s", vty_out (vty, " OSPF packet %s%s debugging is on%s",
LOOKUP (ospf_packet_type_str, i + 1), lookup_msg(ospf_packet_type_str, i + 1, NULL),
IS_DEBUG_OSPF_PACKET (i, DETAIL) ? " detail" : "", IS_DEBUG_OSPF_PACKET (i, DETAIL) ? " detail" : "",
VTY_NEWLINE); VTY_NEWLINE);
} }
@ -1616,12 +1616,12 @@ show_debugging_ospf_common (struct vty *vty, struct ospf *ospf)
{ {
if (IS_DEBUG_OSPF_PACKET (i, SEND)) if (IS_DEBUG_OSPF_PACKET (i, SEND))
vty_out (vty, " OSPF packet %s send%s debugging is on%s", vty_out (vty, " OSPF packet %s send%s debugging is on%s",
LOOKUP (ospf_packet_type_str, i + 1), lookup_msg(ospf_packet_type_str, i + 1, NULL),
IS_DEBUG_OSPF_PACKET (i, DETAIL) ? " detail" : "", IS_DEBUG_OSPF_PACKET (i, DETAIL) ? " detail" : "",
VTY_NEWLINE); VTY_NEWLINE);
if (IS_DEBUG_OSPF_PACKET (i, RECV)) if (IS_DEBUG_OSPF_PACKET (i, RECV))
vty_out (vty, " OSPF packet %s receive%s debugging is on%s", vty_out (vty, " OSPF packet %s receive%s debugging is on%s",
LOOKUP (ospf_packet_type_str, i + 1), lookup_msg(ospf_packet_type_str, i + 1, NULL),
IS_DEBUG_OSPF_PACKET (i, DETAIL) ? " detail" : "", IS_DEBUG_OSPF_PACKET (i, DETAIL) ? " detail" : "",
VTY_NEWLINE); VTY_NEWLINE);
} }

View File

@ -40,8 +40,8 @@ const struct message ospf_ism_state_msg[] =
{ ISM_DROther, "DROther" }, { ISM_DROther, "DROther" },
{ ISM_Backup, "Backup" }, { ISM_Backup, "Backup" },
{ ISM_DR, "DR" }, { ISM_DR, "DR" },
{ 0 }
}; };
const int ospf_ism_state_msg_max = OSPF_ISM_STATE_MAX;
const struct message ospf_nsm_state_msg[] = const struct message ospf_nsm_state_msg[] =
{ {
@ -55,8 +55,8 @@ const struct message ospf_nsm_state_msg[] =
{ NSM_Exchange, "Exchange" }, { NSM_Exchange, "Exchange" },
{ NSM_Loading, "Loading" }, { NSM_Loading, "Loading" },
{ NSM_Full, "Full" }, { NSM_Full, "Full" },
{ 0 }
}; };
const int ospf_nsm_state_msg_max = OSPF_NSM_STATE_MAX;
const struct message ospf_lsa_type_msg[] = const struct message ospf_lsa_type_msg[] =
{ {
@ -72,8 +72,8 @@ const struct message ospf_lsa_type_msg[] =
{ OSPF_OPAQUE_LINK_LSA, "Link-Local Opaque-LSA" }, { OSPF_OPAQUE_LINK_LSA, "Link-Local Opaque-LSA" },
{ OSPF_OPAQUE_AREA_LSA, "Area-Local Opaque-LSA" }, { OSPF_OPAQUE_AREA_LSA, "Area-Local Opaque-LSA" },
{ OSPF_OPAQUE_AS_LSA, "AS-external Opaque-LSA" }, { OSPF_OPAQUE_AS_LSA, "AS-external Opaque-LSA" },
{ 0 }
}; };
const int ospf_lsa_type_msg_max = OSPF_MAX_LSA;
const struct message ospf_link_state_id_type_msg[] = const struct message ospf_link_state_id_type_msg[] =
{ {
@ -89,8 +89,8 @@ const struct message ospf_link_state_id_type_msg[] =
{ OSPF_OPAQUE_LINK_LSA, "(Link-Local Opaque-Type/ID)" }, { OSPF_OPAQUE_LINK_LSA, "(Link-Local Opaque-Type/ID)" },
{ OSPF_OPAQUE_AREA_LSA, "(Area-Local Opaque-Type/ID)" }, { OSPF_OPAQUE_AREA_LSA, "(Area-Local Opaque-Type/ID)" },
{ OSPF_OPAQUE_AS_LSA, "(AS-external Opaque-Type/ID)" }, { OSPF_OPAQUE_AS_LSA, "(AS-external Opaque-Type/ID)" },
{ 0 }
}; };
const int ospf_link_state_id_type_msg_max = OSPF_MAX_LSA;
const struct message ospf_network_type_msg[] = const struct message ospf_network_type_msg[] =
{ {
@ -100,8 +100,8 @@ const struct message ospf_network_type_msg[] =
{ OSPF_IFTYPE_NBMA, "NBMA" }, { OSPF_IFTYPE_NBMA, "NBMA" },
{ OSPF_IFTYPE_POINTOMULTIPOINT, "Point-to-MultiPoint" }, { OSPF_IFTYPE_POINTOMULTIPOINT, "Point-to-MultiPoint" },
{ OSPF_IFTYPE_VIRTUALLINK, "Virtual-Link" }, { OSPF_IFTYPE_VIRTUALLINK, "Virtual-Link" },
{ 0 }
}; };
const int ospf_network_type_msg_max = OSPF_IFTYPE_MAX;
/* AuType */ /* AuType */
const struct message ospf_auth_type_str[] = const struct message ospf_auth_type_str[] =
@ -109,9 +109,8 @@ const struct message ospf_auth_type_str[] =
{ OSPF_AUTH_NULL, "Null" }, { OSPF_AUTH_NULL, "Null" },
{ OSPF_AUTH_SIMPLE, "Simple" }, { OSPF_AUTH_SIMPLE, "Simple" },
{ OSPF_AUTH_CRYPTOGRAPHIC, "Cryptographic" }, { OSPF_AUTH_CRYPTOGRAPHIC, "Cryptographic" },
{ 0 }
}; };
const size_t ospf_auth_type_str_max = sizeof (ospf_auth_type_str) /
sizeof (ospf_auth_type_str[0]);
#define OSPF_OPTION_STR_MAXLEN 24 #define OSPF_OPTION_STR_MAXLEN 24
@ -135,7 +134,7 @@ ospf_options_dump (u_char options)
void void
ospf_lsa_header_dump (struct lsa_header *lsah) ospf_lsa_header_dump (struct lsa_header *lsah)
{ {
const char *lsah_type = LOOKUP (ospf_lsa_type_msg, lsah->type); const char *lsah_type = lookup_msg(ospf_lsa_type_msg, lsah->type, NULL);
zlog_debug (" LSA Header"); zlog_debug (" LSA Header");
zlog_debug (" LS age %d", ntohs (lsah->ls_age)); zlog_debug (" LS age %d", ntohs (lsah->ls_age));

View File

@ -255,7 +255,7 @@ ospf_flood (struct ospf *ospf, struct ospf_neighbor *nbr,
if (IS_DEBUG_OSPF_EVENT) if (IS_DEBUG_OSPF_EVENT)
zlog_debug ("LSA[Flooding]: start, NBR %s (%s), cur(%p), New-LSA[%s]", zlog_debug ("LSA[Flooding]: start, NBR %s (%s), cur(%p), New-LSA[%s]",
inet_ntoa (nbr->router_id), inet_ntoa (nbr->router_id),
LOOKUP (ospf_nsm_state_msg, nbr->state), lookup_msg(ospf_nsm_state_msg, nbr->state, NULL),
(void *)current, (void *)current,
dump_lsa_key (new)); dump_lsa_key (new));
@ -379,7 +379,7 @@ ospf_flood_through_interface (struct ospf_interface *oi,
if (IS_DEBUG_OSPF_EVENT) if (IS_DEBUG_OSPF_EVENT)
zlog_debug ("ospf_flood_through_interface(): considering nbr %s (%s)", zlog_debug ("ospf_flood_through_interface(): considering nbr %s (%s)",
inet_ntoa (onbr->router_id), inet_ntoa (onbr->router_id),
LOOKUP (ospf_nsm_state_msg, onbr->state)); lookup_msg(ospf_nsm_state_msg, onbr->state, NULL));
/* If the neighbor is in a lesser state than Exchange, it /* If the neighbor is in a lesser state than Exchange, it
does not participate in flooding, and the next neighbor does not participate in flooding, and the next neighbor

View File

@ -540,8 +540,8 @@ ism_change_state (struct ospf_interface *oi, int state)
/* Logging change of state. */ /* Logging change of state. */
if (IS_DEBUG_OSPF (ism, ISM_STATUS)) if (IS_DEBUG_OSPF (ism, ISM_STATUS))
zlog_debug("ISM[%s]: State change %s -> %s", IF_NAME(oi), zlog_debug("ISM[%s]: State change %s -> %s", IF_NAME(oi),
LOOKUP(ospf_ism_state_msg, oi->state), lookup_msg(ospf_ism_state_msg, oi->state, NULL),
LOOKUP(ospf_ism_state_msg, state)); lookup_msg(ospf_ism_state_msg, state, NULL));
old_state = oi->state; old_state = oi->state;
oi->state = state; oi->state = state;
@ -606,7 +606,7 @@ ospf_ism_event (struct thread *thread)
if (IS_DEBUG_OSPF (ism, ISM_EVENTS)) if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
zlog_debug("ISM[%s]: %s (%s)", IF_NAME(oi), zlog_debug("ISM[%s]: %s (%s)", IF_NAME(oi),
LOOKUP(ospf_ism_state_msg, oi->state), lookup_msg(ospf_ism_state_msg, oi->state, NULL),
ospf_ism_event_str[event]); ospf_ism_event_str[event]);
/* If state is changed. */ /* If state is changed. */

View File

@ -2759,13 +2759,13 @@ ospf_lsa_install (struct ospf *ospf, struct ospf_interface *oi,
case OSPF_AS_NSSA_LSA: case OSPF_AS_NSSA_LSA:
zlog_debug ("LSA[%s]: Install %s", zlog_debug ("LSA[%s]: Install %s",
dump_lsa_key (new), dump_lsa_key (new),
LOOKUP (ospf_lsa_type_msg, new->data->type)); lookup_msg(ospf_lsa_type_msg, new->data->type, NULL));
break; break;
default: default:
strcpy (area_str, inet_ntoa (new->area->area_id)); strcpy (area_str, inet_ntoa (new->area->area_id));
zlog_debug ("LSA[%s]: Install %s to Area %s", zlog_debug ("LSA[%s]: Install %s to Area %s",
dump_lsa_key (new), dump_lsa_key (new),
LOOKUP (ospf_lsa_type_msg, new->data->type), area_str); lookup_msg(ospf_lsa_type_msg, new->data->type, NULL), area_str);
break; break;
} }
} }

View File

@ -616,8 +616,8 @@ nsm_notice_state_change (struct ospf_neighbor *nbr, int next_state, int event)
if (IS_DEBUG_OSPF (nsm, NSM_STATUS)) if (IS_DEBUG_OSPF (nsm, NSM_STATUS))
zlog_debug ("NSM[%s:%s]: State change %s -> %s (%s)", zlog_debug ("NSM[%s:%s]: State change %s -> %s (%s)",
IF_NAME (nbr->oi), inet_ntoa (nbr->router_id), IF_NAME (nbr->oi), inet_ntoa (nbr->router_id),
LOOKUP (ospf_nsm_state_msg, nbr->state), lookup_msg(ospf_nsm_state_msg, nbr->state, NULL),
LOOKUP (ospf_nsm_state_msg, next_state), lookup_msg(ospf_nsm_state_msg, next_state, NULL),
ospf_nsm_event_str [event]); ospf_nsm_event_str [event]);
/* Optionally notify about adjacency changes */ /* Optionally notify about adjacency changes */
@ -626,8 +626,8 @@ nsm_notice_state_change (struct ospf_neighbor *nbr, int next_state, int event)
(next_state == NSM_Full) || (next_state < nbr->state))) (next_state == NSM_Full) || (next_state < nbr->state)))
zlog_notice("AdjChg: Nbr %s on %s: %s -> %s (%s)", zlog_notice("AdjChg: Nbr %s on %s: %s -> %s (%s)",
inet_ntoa (nbr->router_id), IF_NAME (nbr->oi), inet_ntoa (nbr->router_id), IF_NAME (nbr->oi),
LOOKUP (ospf_nsm_state_msg, nbr->state), lookup_msg(ospf_nsm_state_msg, nbr->state, NULL),
LOOKUP (ospf_nsm_state_msg, next_state), lookup_msg(ospf_nsm_state_msg, next_state, NULL),
ospf_nsm_event_str [event]); ospf_nsm_event_str [event]);
/* Advance in NSM */ /* Advance in NSM */
@ -735,8 +735,8 @@ nsm_change_state (struct ospf_neighbor *nbr, int state)
zlog_info ("nsm_change_state(%s, %s -> %s): " zlog_info ("nsm_change_state(%s, %s -> %s): "
"scheduling new router-LSA origination", "scheduling new router-LSA origination",
inet_ntoa (nbr->router_id), inet_ntoa (nbr->router_id),
LOOKUP(ospf_nsm_state_msg, old_state), lookup_msg(ospf_nsm_state_msg, old_state, NULL),
LOOKUP(ospf_nsm_state_msg, state)); lookup_msg(ospf_nsm_state_msg, state, NULL));
ospf_router_lsa_update_area (oi->area); ospf_router_lsa_update_area (oi->area);
@ -807,7 +807,7 @@ ospf_nsm_event (struct thread *thread)
if (IS_DEBUG_OSPF (nsm, NSM_EVENTS)) if (IS_DEBUG_OSPF (nsm, NSM_EVENTS))
zlog_debug ("NSM[%s:%s]: %s (%s)", IF_NAME (nbr->oi), zlog_debug ("NSM[%s:%s]: %s (%s)", IF_NAME (nbr->oi),
inet_ntoa (nbr->router_id), inet_ntoa (nbr->router_id),
LOOKUP (ospf_nsm_state_msg, nbr->state), lookup_msg(ospf_nsm_state_msg, nbr->state, NULL),
ospf_nsm_event_str [event]); ospf_nsm_event_str [event]);
next_state = NSM [nbr->state][event].next_state; next_state = NSM [nbr->state][event].next_state;
@ -829,9 +829,9 @@ ospf_nsm_event (struct thread *thread)
zlog_warn ("NSM[%s:%s]: %s (%s): " zlog_warn ("NSM[%s:%s]: %s (%s): "
"Warning: action tried to change next_state to %s", "Warning: action tried to change next_state to %s",
IF_NAME (nbr->oi), inet_ntoa (nbr->router_id), IF_NAME (nbr->oi), inet_ntoa (nbr->router_id),
LOOKUP (ospf_nsm_state_msg, nbr->state), lookup_msg(ospf_nsm_state_msg, nbr->state, NULL),
ospf_nsm_event_str [event], ospf_nsm_event_str [event],
LOOKUP (ospf_nsm_state_msg, func_state)); lookup_msg(ospf_nsm_state_msg, func_state, NULL));
} }
} }

View File

@ -78,9 +78,8 @@ const struct message ospf_packet_type_str[] =
{ OSPF_MSG_LS_REQ, "Link State Request" }, { OSPF_MSG_LS_REQ, "Link State Request" },
{ OSPF_MSG_LS_UPD, "Link State Update" }, { OSPF_MSG_LS_UPD, "Link State Update" },
{ OSPF_MSG_LS_ACK, "Link State Acknowledgment" }, { OSPF_MSG_LS_ACK, "Link State Acknowledgment" },
{ 0 }
}; };
const size_t ospf_packet_type_str_max = sizeof (ospf_packet_type_str) /
sizeof (ospf_packet_type_str[0]);
/* Minimum (besides OSPF_HEADER_SIZE) lengths for OSPF packets of /* Minimum (besides OSPF_HEADER_SIZE) lengths for OSPF packets of
particular types, offset is the "type" field of a packet. */ particular types, offset is the "type" field of a packet. */
@ -255,8 +254,8 @@ ospf_packet_add (struct ospf_interface *oi, struct ospf_packet *op)
zlog_err("ospf_packet_add(interface %s in state %d [%s], packet type %s, " zlog_err("ospf_packet_add(interface %s in state %d [%s], packet type %s, "
"destination %s) called with NULL obuf, ignoring " "destination %s) called with NULL obuf, ignoring "
"(please report this bug)!\n", "(please report this bug)!\n",
IF_NAME(oi), oi->state, LOOKUP (ospf_ism_state_msg, oi->state), IF_NAME(oi), oi->state, lookup_msg(ospf_ism_state_msg, oi->state, NULL),
LOOKUP (ospf_packet_type_str, stream_getc_from(op->s, 1)), lookup_msg(ospf_packet_type_str, stream_getc_from(op->s, 1), NULL),
inet_ntoa (op->dst)); inet_ntoa (op->dst));
return; return;
} }
@ -276,8 +275,8 @@ ospf_packet_add_top (struct ospf_interface *oi, struct ospf_packet *op)
zlog_err("ospf_packet_add(interface %s in state %d [%s], packet type %s, " zlog_err("ospf_packet_add(interface %s in state %d [%s], packet type %s, "
"destination %s) called with NULL obuf, ignoring " "destination %s) called with NULL obuf, ignoring "
"(please report this bug)!\n", "(please report this bug)!\n",
IF_NAME(oi), oi->state, LOOKUP (ospf_ism_state_msg, oi->state), IF_NAME(oi), oi->state, lookup_msg(ospf_ism_state_msg, oi->state, NULL),
LOOKUP (ospf_packet_type_str, stream_getc_from(op->s, 1)), lookup_msg(ospf_packet_type_str, stream_getc_from(op->s, 1), NULL),
inet_ntoa (op->dst)); inet_ntoa (op->dst));
return; return;
} }
@ -815,7 +814,8 @@ ospf_write (struct thread *thread)
} }
zlog_debug ("%s sent to [%s] via [%s].", zlog_debug ("%s sent to [%s] via [%s].",
LOOKUP (ospf_packet_type_str, type), inet_ntoa (op->dst), lookup_msg(ospf_packet_type_str, type, NULL),
inet_ntoa (op->dst),
IF_NAME (oi)); IF_NAME (oi));
if (IS_DEBUG_OSPF_PACKET (type - 1, DETAIL)) if (IS_DEBUG_OSPF_PACKET (type - 1, DETAIL))
@ -880,7 +880,7 @@ ospf_hello (struct ip *iph, struct ospf_header *ospfh,
{ {
zlog_debug ("ospf_header[%s/%s]: selforiginated, " zlog_debug ("ospf_header[%s/%s]: selforiginated, "
"dropping.", "dropping.",
LOOKUP (ospf_packet_type_str, ospfh->type), lookup_msg(ospf_packet_type_str, ospfh->type, NULL),
inet_ntoa (iph->ip_src)); inet_ntoa (iph->ip_src));
} }
return; return;
@ -1318,7 +1318,7 @@ ospf_db_desc (struct ip *iph, struct ospf_header *ospfh,
case NSM_TwoWay: case NSM_TwoWay:
zlog_warn ("Packet[DD]: Neighbor %s state is %s, packet discarded.", zlog_warn ("Packet[DD]: Neighbor %s state is %s, packet discarded.",
inet_ntoa(nbr->router_id), inet_ntoa(nbr->router_id),
LOOKUP (ospf_nsm_state_msg, nbr->state)); lookup_msg(ospf_nsm_state_msg, nbr->state, NULL));
break; break;
case NSM_Init: case NSM_Init:
OSPF_NSM_EVENT_EXECUTE (nbr, NSM_TwoWayReceived); OSPF_NSM_EVENT_EXECUTE (nbr, NSM_TwoWayReceived);
@ -1538,7 +1538,7 @@ ospf_ls_req (struct ip *iph, struct ospf_header *ospfh,
zlog_warn ("Link State Request received from %s: " zlog_warn ("Link State Request received from %s: "
"Neighbor state is %s, packet discarded.", "Neighbor state is %s, packet discarded.",
inet_ntoa (ospfh->router_id), inet_ntoa (ospfh->router_id),
LOOKUP (ospf_nsm_state_msg, nbr->state)); lookup_msg(ospf_nsm_state_msg, nbr->state, NULL));
return; return;
} }
@ -1773,7 +1773,7 @@ ospf_ls_upd (struct ospf *ospf, struct ip *iph, struct ospf_header *ospfh,
zlog_debug ("Link State Update: " zlog_debug ("Link State Update: "
"Neighbor[%s] state %s is less than Exchange", "Neighbor[%s] state %s is less than Exchange",
inet_ntoa (ospfh->router_id), inet_ntoa (ospfh->router_id),
LOOKUP(ospf_nsm_state_msg, nbr->state)); lookup_msg(ospf_nsm_state_msg, nbr->state, NULL));
return; return;
} }
@ -2118,7 +2118,7 @@ ospf_ls_ack (struct ip *iph, struct ospf_header *ospfh,
zlog_debug ("Link State Acknowledgment: " zlog_debug ("Link State Acknowledgment: "
"Neighbor[%s] state %s is less than Exchange", "Neighbor[%s] state %s is less than Exchange",
inet_ntoa (ospfh->router_id), inet_ntoa (ospfh->router_id),
LOOKUP(ospf_nsm_state_msg, nbr->state)); lookup_msg(ospf_nsm_state_msg, nbr->state, NULL));
return; return;
} }
@ -2333,7 +2333,7 @@ ospf_check_auth (struct ospf_interface *oi, struct ospf_header *ospfh)
{ {
if (IS_DEBUG_OSPF_PACKET (ospfh->type - 1, RECV)) if (IS_DEBUG_OSPF_PACKET (ospfh->type - 1, RECV))
zlog_warn ("interface %s: auth-type mismatch, local %s, rcvd Null", zlog_warn ("interface %s: auth-type mismatch, local %s, rcvd Null",
IF_NAME (oi), LOOKUP (ospf_auth_type_str, iface_auth_type)); IF_NAME (oi), lookup_msg(ospf_auth_type_str, iface_auth_type, NULL));
return 0; return 0;
} }
if (! ospf_check_sum (ospfh)) if (! ospf_check_sum (ospfh))
@ -2349,7 +2349,7 @@ ospf_check_auth (struct ospf_interface *oi, struct ospf_header *ospfh)
{ {
if (IS_DEBUG_OSPF_PACKET (ospfh->type - 1, RECV)) if (IS_DEBUG_OSPF_PACKET (ospfh->type - 1, RECV))
zlog_warn ("interface %s: auth-type mismatch, local %s, rcvd Simple", zlog_warn ("interface %s: auth-type mismatch, local %s, rcvd Simple",
IF_NAME (oi), LOOKUP (ospf_auth_type_str, iface_auth_type)); IF_NAME (oi), lookup_msg(ospf_auth_type_str, iface_auth_type, NULL));
return 0; return 0;
} }
if (memcmp (OSPF_IF_PARAM (oi, auth_simple), ospfh->u.auth_data, OSPF_AUTH_SIMPLE_SIZE)) if (memcmp (OSPF_IF_PARAM (oi, auth_simple), ospfh->u.auth_data, OSPF_AUTH_SIMPLE_SIZE))
@ -2371,7 +2371,7 @@ ospf_check_auth (struct ospf_interface *oi, struct ospf_header *ospfh)
{ {
if (IS_DEBUG_OSPF_PACKET (ospfh->type - 1, RECV)) if (IS_DEBUG_OSPF_PACKET (ospfh->type - 1, RECV))
zlog_warn ("interface %s: auth-type mismatch, local %s, rcvd Cryptographic", zlog_warn ("interface %s: auth-type mismatch, local %s, rcvd Cryptographic",
IF_NAME (oi), LOOKUP (ospf_auth_type_str, iface_auth_type)); IF_NAME (oi), lookup_msg(ospf_auth_type_str, iface_auth_type, NULL));
return 0; return 0;
} }
if (ospfh->checksum) if (ospfh->checksum)
@ -2480,7 +2480,7 @@ ospf_lsa_examin (struct lsa_header * lsah, const u_int16_t lsalen, const u_char
{ {
if (IS_DEBUG_OSPF_PACKET (0, RECV)) if (IS_DEBUG_OSPF_PACKET (0, RECV))
zlog_debug ("%s: undersized (%u B) %s", zlog_debug ("%s: undersized (%u B) %s",
__func__, lsalen, LOOKUP (ospf_lsa_type_msg, lsah->type)); __func__, lsalen, lookup_msg(ospf_lsa_type_msg, lsah->type, NULL));
return MSG_NG; return MSG_NG;
} }
switch (lsah->type) switch (lsah->type)
@ -2530,7 +2530,7 @@ ospf_lsa_examin (struct lsa_header * lsah, const u_int16_t lsalen, const u_char
} }
if (ret != MSG_OK && IS_DEBUG_OSPF_PACKET (0, RECV)) if (ret != MSG_OK && IS_DEBUG_OSPF_PACKET (0, RECV))
zlog_debug ("%s: alignment error in %s", zlog_debug ("%s: alignment error in %s",
__func__, LOOKUP (ospf_lsa_type_msg, lsah->type)); __func__, lookup_msg(ospf_lsa_type_msg, lsah->type, NULL));
return ret; return ret;
} }
@ -2669,7 +2669,7 @@ ospf_packet_examin (struct ospf_header * oh, const unsigned bytesonwire)
{ {
if (IS_DEBUG_OSPF_PACKET (0, RECV)) if (IS_DEBUG_OSPF_PACKET (0, RECV))
zlog_debug ("%s: undersized (%u B) %s packet", __func__, zlog_debug ("%s: undersized (%u B) %s packet", __func__,
bytesdeclared, LOOKUP (ospf_packet_type_str, oh->type)); bytesdeclared, lookup_msg(ospf_packet_type_str, oh->type, NULL));
return MSG_NG; return MSG_NG;
} }
switch (oh->type) switch (oh->type)
@ -2723,7 +2723,7 @@ ospf_packet_examin (struct ospf_header * oh, const unsigned bytesonwire)
return MSG_NG; return MSG_NG;
} }
if (ret != MSG_OK && IS_DEBUG_OSPF_PACKET (0, RECV)) if (ret != MSG_OK && IS_DEBUG_OSPF_PACKET (0, RECV))
zlog_debug ("%s: malformed %s packet", __func__, LOOKUP (ospf_packet_type_str, oh->type)); zlog_debug ("%s: malformed %s packet", __func__, lookup_msg(ospf_packet_type_str, oh->type, NULL));
return ret; return ret;
} }
@ -2913,7 +2913,7 @@ ospf_read (struct thread *thread)
{ {
zlog_warn ("Dropping packet for AllDRouters from [%s] via [%s] (ISM: %s)", zlog_warn ("Dropping packet for AllDRouters from [%s] via [%s] (ISM: %s)",
inet_ntoa (iph->ip_src), IF_NAME (oi), inet_ntoa (iph->ip_src), IF_NAME (oi),
LOOKUP (ospf_ism_state_msg, oi->state)); lookup_msg(ospf_ism_state_msg, oi->state, NULL));
/* Try to fix multicast membership. */ /* Try to fix multicast membership. */
SET_FLAG(oi->multicast_memberships, MEMBER_DROUTERS); SET_FLAG(oi->multicast_memberships, MEMBER_DROUTERS);
ospf_if_set_multicast(oi); ospf_if_set_multicast(oi);
@ -2941,7 +2941,7 @@ ospf_read (struct thread *thread)
} }
zlog_debug ("%s received from [%s] via [%s]", zlog_debug ("%s received from [%s] via [%s]",
LOOKUP (ospf_packet_type_str, ospfh->type), lookup_msg(ospf_packet_type_str, ospfh->type, NULL),
inet_ntoa (ospfh->router_id), IF_NAME (oi)); inet_ntoa (ospfh->router_id), IF_NAME (oi));
zlog_debug (" src [%s],", inet_ntoa (iph->ip_src)); zlog_debug (" src [%s],", inet_ntoa (iph->ip_src));
zlog_debug (" dst [%s]", inet_ntoa (iph->ip_dst)); zlog_debug (" dst [%s]", inet_ntoa (iph->ip_dst));

View File

@ -2729,7 +2729,7 @@ ospfTrapIfStateChange (struct ospf_interface *oi)
zlog_info("ospfTrapIfStateChange trap sent: %s now %s", zlog_info("ospfTrapIfStateChange trap sent: %s now %s",
inet_ntoa(oi->address->u.prefix4), inet_ntoa(oi->address->u.prefix4),
LOOKUP(ospf_ism_state_msg, oi->state)); lookup_msg(ospf_ism_state_msg, oi->state, NULL));
oid_copy_addr (index, &(oi->address->u.prefix4), IN_ADDR_SIZE); oid_copy_addr (index, &(oi->address->u.prefix4), IN_ADDR_SIZE);
index[IN_ADDR_SIZE] = 0; index[IN_ADDR_SIZE] = 0;

View File

@ -3372,7 +3372,7 @@ show_ip_ospf_interface_sub (struct vty *vty, struct ospf *ospf, struct interface
json_object_string_add(json_interface_sub, "networkType", ospf_network_type_str[oi->type]); json_object_string_add(json_interface_sub, "networkType", ospf_network_type_str[oi->type]);
json_object_int_add(json_interface_sub, "cost", oi->output_cost); json_object_int_add(json_interface_sub, "cost", oi->output_cost);
json_object_int_add(json_interface_sub, "transmitDelayMsecs", 1000 / OSPF_IF_PARAM (oi,transmit_delay)); json_object_int_add(json_interface_sub, "transmitDelayMsecs", 1000 / OSPF_IF_PARAM (oi,transmit_delay));
json_object_string_add(json_interface_sub, "state", LOOKUP (ospf_ism_state_msg, oi->state)); json_object_string_add(json_interface_sub, "state", lookup_msg(ospf_ism_state_msg, oi->state, NULL));
json_object_int_add(json_interface_sub, "priority", PRIORITY (oi)); json_object_int_add(json_interface_sub, "priority", PRIORITY (oi));
} }
else else
@ -3388,7 +3388,7 @@ show_ip_ospf_interface_sub (struct vty *vty, struct ospf *ospf, struct interface
oi->output_cost, VTY_NEWLINE); oi->output_cost, VTY_NEWLINE);
vty_out (vty, " Transmit Delay is %d sec, State %s, Priority %d%s", vty_out (vty, " Transmit Delay is %d sec, State %s, Priority %d%s",
OSPF_IF_PARAM (oi,transmit_delay), LOOKUP (ospf_ism_state_msg, oi->state), OSPF_IF_PARAM (oi,transmit_delay), lookup_msg(ospf_ism_state_msg, oi->state, NULL),
PRIORITY (oi), VTY_NEWLINE); PRIORITY (oi), VTY_NEWLINE);
} }
@ -4123,11 +4123,11 @@ show_ip_ospf_neighbor_detail_sub (struct vty *vty, struct ospf_interface *oi,
if (use_json) if (use_json)
{ {
json_object_int_add(json_sub, "nbrPriority", nbr->priority); json_object_int_add(json_sub, "nbrPriority", nbr->priority);
json_object_string_add(json_sub, "nbrState", LOOKUP (ospf_nsm_state_msg, nbr->state)); json_object_string_add(json_sub, "nbrState", lookup_msg(ospf_nsm_state_msg, nbr->state, NULL));
} }
else else
vty_out (vty, " Neighbor priority is %d, State is %s,", vty_out (vty, " Neighbor priority is %d, State is %s,",
nbr->priority, LOOKUP (ospf_nsm_state_msg, nbr->state)); nbr->priority, lookup_msg(ospf_nsm_state_msg, nbr->state, NULL));
/* Show state changes. */ /* Show state changes. */
if (use_json) if (use_json)
@ -4798,9 +4798,9 @@ show_ip_ospf_database_header (struct vty *vty, struct ospf_lsa *lsa)
vty_out (vty, "%s", VTY_NEWLINE); vty_out (vty, "%s", VTY_NEWLINE);
} }
vty_out (vty, " LS Type: %s%s", vty_out (vty, " LS Type: %s%s",
LOOKUP (ospf_lsa_type_msg, lsa->data->type), VTY_NEWLINE); lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL), VTY_NEWLINE);
vty_out (vty, " Link State ID: %s %s%s", inet_ntoa (lsa->data->id), vty_out (vty, " Link State ID: %s %s%s", inet_ntoa (lsa->data->id),
LOOKUP (ospf_link_state_id_type_msg, lsa->data->type), VTY_NEWLINE); lookup_msg(ospf_link_state_id_type_msg, lsa->data->type, NULL), VTY_NEWLINE);
vty_out (vty, " Advertising Router: %s%s", vty_out (vty, " Advertising Router: %s%s",
inet_ntoa (lsa->data->adv_router), VTY_NEWLINE); inet_ntoa (lsa->data->adv_router), VTY_NEWLINE);
vty_out (vty, " LS Seq Number: %08lx%s", (u_long)ntohl (lsa->data->ls_seqnum), vty_out (vty, " LS Seq Number: %08lx%s", (u_long)ntohl (lsa->data->ls_seqnum),

View File

@ -1267,8 +1267,8 @@ static const struct message ospf_area_type_msg[] =
{ OSPF_AREA_DEFAULT, "Default" }, { OSPF_AREA_DEFAULT, "Default" },
{ OSPF_AREA_STUB, "Stub" }, { OSPF_AREA_STUB, "Stub" },
{ OSPF_AREA_NSSA, "NSSA" }, { OSPF_AREA_NSSA, "NSSA" },
{ 0 }
}; };
static const int ospf_area_type_msg_max = OSPF_AREA_TYPE_MAX;
static void static void
ospf_area_type_set (struct ospf_area *area, int type) ospf_area_type_set (struct ospf_area *area, int type)
@ -1288,7 +1288,7 @@ ospf_area_type_set (struct ospf_area *area, int type)
if (IS_DEBUG_OSPF_EVENT) if (IS_DEBUG_OSPF_EVENT)
zlog_debug ("Area[%s]: Configured as %s", inet_ntoa (area->area_id), zlog_debug ("Area[%s]: Configured as %s", inet_ntoa (area->area_id),
LOOKUP (ospf_area_type_msg, type)); lookup_msg(ospf_area_type_msg, type, NULL));
switch (area->external_routing) switch (area->external_routing)
{ {

View File

@ -58,6 +58,7 @@ const struct message ri_version_msg[] =
{RI_RIP_VERSION_2, "2"}, {RI_RIP_VERSION_2, "2"},
{RI_RIP_VERSION_1_AND_2, "1 2"}, {RI_RIP_VERSION_1_AND_2, "1 2"},
{RI_RIP_VERSION_NONE, "none"}, {RI_RIP_VERSION_NONE, "none"},
{ 0 }
}; };
extern struct zebra_privs_t ripd_privs; extern struct zebra_privs_t ripd_privs;
@ -1905,12 +1906,12 @@ rip_interface_config_write (struct vty *vty)
/* RIP version setting. */ /* RIP version setting. */
if (ri->ri_send != RI_RIP_UNSPEC) if (ri->ri_send != RI_RIP_UNSPEC)
vty_out (vty, " ip rip send version %s%s", vty_out (vty, " ip rip send version %s%s",
lookup (ri_version_msg, ri->ri_send), lookup_msg(ri_version_msg, ri->ri_send, NULL),
VTY_NEWLINE); VTY_NEWLINE);
if (ri->ri_receive != RI_RIP_UNSPEC) if (ri->ri_receive != RI_RIP_UNSPEC)
vty_out (vty, " ip rip receive version %s%s", vty_out (vty, " ip rip receive version %s%s",
lookup (ri_version_msg, ri->ri_receive), lookup_msg(ri_version_msg, ri->ri_receive, NULL),
VTY_NEWLINE); VTY_NEWLINE);
if (ri->v2_broadcast) if (ri->v2_broadcast)

View File

@ -86,7 +86,7 @@ static const struct message rip_msg[] =
{RIP_TRACEOFF, "TRACEOFF"}, {RIP_TRACEOFF, "TRACEOFF"},
{RIP_POLL, "POLL"}, {RIP_POLL, "POLL"},
{RIP_POLL_ENTRY, "POLL ENTRY"}, {RIP_POLL_ENTRY, "POLL ENTRY"},
{0, NULL}, { 0 }
}; };
/* Utility function to set boradcast option to the socket. */ /* Utility function to set boradcast option to the socket. */
@ -701,7 +701,7 @@ rip_packet_dump (struct rip_packet *packet, int size, const char *sndrcv)
/* Set command string. */ /* Set command string. */
if (packet->command > 0 && packet->command < RIP_COMMAND_MAX) if (packet->command > 0 && packet->command < RIP_COMMAND_MAX)
command_str = lookup (rip_msg, packet->command); command_str = lookup_msg (rip_msg, packet->command, NULL);
else else
command_str = "unknown"; command_str = "unknown";
@ -2044,12 +2044,12 @@ rip_read (struct thread *t)
case RIP_TRACEON: case RIP_TRACEON:
case RIP_TRACEOFF: case RIP_TRACEOFF:
zlog_info ("Obsolete command %s received, please sent it to routed", zlog_info ("Obsolete command %s received, please sent it to routed",
lookup (rip_msg, packet->command)); lookup_msg (rip_msg, packet->command, NULL));
rip_peer_bad_packet (&from); rip_peer_bad_packet (&from);
break; break;
case RIP_POLL_ENTRY: case RIP_POLL_ENTRY:
zlog_info ("Obsolete command %s received", zlog_info ("Obsolete command %s received",
lookup (rip_msg, packet->command)); lookup_msg (rip_msg, packet->command, NULL));
rip_peer_bad_packet (&from); rip_peer_bad_packet (&from);
break; break;
default: default:
@ -3586,12 +3586,12 @@ DEFUN (show_ip_rip_status,
vty_out (vty, "%s", VTY_NEWLINE); vty_out (vty, "%s", VTY_NEWLINE);
vty_out (vty, " Default version control: send version %s,", vty_out (vty, " Default version control: send version %s,",
lookup(ri_version_msg,rip->version_send)); lookup_msg(ri_version_msg,rip->version_send, NULL));
if (rip->version_recv == RI_RIP_VERSION_1_AND_2) if (rip->version_recv == RI_RIP_VERSION_1_AND_2)
vty_out (vty, " receive any version %s", VTY_NEWLINE); vty_out (vty, " receive any version %s", VTY_NEWLINE);
else else
vty_out (vty, " receive version %s %s", vty_out (vty, " receive version %s %s",
lookup(ri_version_msg,rip->version_recv), VTY_NEWLINE); lookup_msg(ri_version_msg,rip->version_recv, NULL), VTY_NEWLINE);
vty_out (vty, " Interface Send Recv Key-chain%s", VTY_NEWLINE); vty_out (vty, " Interface Send Recv Key-chain%s", VTY_NEWLINE);
@ -3605,14 +3605,14 @@ DEFUN (show_ip_rip_status,
if (ri->enable_network || ri->enable_interface) if (ri->enable_network || ri->enable_interface)
{ {
if (ri->ri_send == RI_RIP_UNSPEC) if (ri->ri_send == RI_RIP_UNSPEC)
send_version = lookup (ri_version_msg, rip->version_send); send_version = lookup_msg(ri_version_msg, rip->version_send, NULL);
else else
send_version = lookup (ri_version_msg, ri->ri_send); send_version = lookup_msg(ri_version_msg, ri->ri_send, NULL);
if (ri->ri_receive == RI_RIP_UNSPEC) if (ri->ri_receive == RI_RIP_UNSPEC)
receive_version = lookup (ri_version_msg, rip->version_recv); receive_version = lookup_msg(ri_version_msg, rip->version_recv, NULL);
else else
receive_version = lookup (ri_version_msg, ri->ri_receive); receive_version = lookup_msg(ri_version_msg, ri->ri_receive, NULL);
vty_out (vty, " %-17s%-3s %-3s %s%s", ifp->name, vty_out (vty, " %-17s%-3s %-3s %s%s", ifp->name,
send_version, send_version,

View File

@ -83,7 +83,7 @@ static const struct message nlmsg_str[] = {
{RTM_NEWNEIGH, "RTM_NEWNEIGH"}, {RTM_NEWNEIGH, "RTM_NEWNEIGH"},
{RTM_DELNEIGH, "RTM_DELNEIGH"}, {RTM_DELNEIGH, "RTM_DELNEIGH"},
{RTM_GETNEIGH, "RTM_GETNEIGH"}, {RTM_GETNEIGH, "RTM_GETNEIGH"},
{0, NULL} { 0 }
}; };
static const struct message rtproto_str[] = { static const struct message rtproto_str[] = {
@ -104,7 +104,7 @@ static const struct message rtproto_str[] = {
{RTPROT_ISIS, "IS-IS"}, {RTPROT_ISIS, "IS-IS"},
{RTPROT_RIP, "RIP"}, {RTPROT_RIP, "RIP"},
{RTPROT_RIPNG, "RIPNG"}, {RTPROT_RIPNG, "RIPNG"},
{0, NULL} { 0 }
}; };
static const struct message family_str[] = { static const struct message family_str[] = {
@ -113,13 +113,13 @@ static const struct message family_str[] = {
{AF_BRIDGE, "bridge"}, {AF_BRIDGE, "bridge"},
{RTNL_FAMILY_IPMR, "ipv4MR"}, {RTNL_FAMILY_IPMR, "ipv4MR"},
{RTNL_FAMILY_IP6MR, "ipv6MR"}, {RTNL_FAMILY_IP6MR, "ipv6MR"},
{0, NULL}, { 0 }
}; };
static const struct message rttype_str[] = { static const struct message rttype_str[] = {
{RTN_UNICAST, "unicast"}, {RTN_UNICAST, "unicast"},
{RTN_MULTICAST, "multicast"}, {RTN_MULTICAST, "multicast"},
{0, NULL}, { 0 }
}; };
extern struct thread_master *master; extern struct thread_master *master;
@ -425,25 +425,25 @@ rta_nest_end(struct rtattr *rta, struct rtattr *nest)
const char * const char *
nl_msg_type_to_str (uint16_t msg_type) nl_msg_type_to_str (uint16_t msg_type)
{ {
return lookup (nlmsg_str, msg_type); return lookup_msg (nlmsg_str, msg_type, "");
} }
const char * const char *
nl_rtproto_to_str (u_char rtproto) nl_rtproto_to_str (u_char rtproto)
{ {
return lookup (rtproto_str, rtproto); return lookup_msg (rtproto_str, rtproto, "");
} }
const char * const char *
nl_family_to_str (u_char family) nl_family_to_str (u_char family)
{ {
return lookup (family_str, family); return lookup_msg (family_str, family, "");
} }
const char * const char *
nl_rttype_to_str (u_char rttype) nl_rttype_to_str (u_char rttype)
{ {
return lookup (rttype_str, rttype); return lookup_msg (rttype_str, rttype, "");
} }
/* /*

View File

@ -219,7 +219,7 @@ const struct message rtm_type_str[] =
#ifdef RTM_IFANNOUNCE #ifdef RTM_IFANNOUNCE
{RTM_IFANNOUNCE, "RTM_IFANNOUNCE"}, {RTM_IFANNOUNCE, "RTM_IFANNOUNCE"},
#endif /* RTM_IFANNOUNCE */ #endif /* RTM_IFANNOUNCE */
{0, NULL} { 0 }
}; };
static const struct message rtm_flag_str[] = static const struct message rtm_flag_str[] =
@ -277,7 +277,7 @@ static const struct message rtm_flag_str[] =
#ifdef RTF_SETSRC #ifdef RTF_SETSRC
{RTF_SETSRC, "SETSRC"}, {RTF_SETSRC, "SETSRC"},
#endif /* RTF_SETSRC */ #endif /* RTF_SETSRC */
{0, NULL} { 0 }
}; };
/* Kernel routing update socket. */ /* Kernel routing update socket. */
@ -874,7 +874,7 @@ rtm_read (struct rt_msghdr *rtm)
return; return;
if (IS_ZEBRA_DEBUG_KERNEL) if (IS_ZEBRA_DEBUG_KERNEL)
zlog_debug ("%s: got rtm of type %d (%s)", __func__, rtm->rtm_type, zlog_debug ("%s: got rtm of type %d (%s)", __func__, rtm->rtm_type,
lookup (rtm_type_str, rtm->rtm_type)); lookup_msg(rtm_type_str, rtm->rtm_type, NULL));
#ifdef RTF_CLONED /*bsdi, netbsd 1.6*/ #ifdef RTF_CLONED /*bsdi, netbsd 1.6*/
if (flags & RTF_CLONED) if (flags & RTF_CLONED)
@ -939,17 +939,17 @@ rtm_read (struct rt_msghdr *rtm)
{ {
case ZEBRA_RIB_NOTFOUND: case ZEBRA_RIB_NOTFOUND:
zlog_debug ("%s: %s %s: desync: RR isn't yet in RIB, while already in FIB", zlog_debug ("%s: %s %s: desync: RR isn't yet in RIB, while already in FIB",
__func__, lookup (rtm_type_str, rtm->rtm_type), buf); __func__, lookup_msg(rtm_type_str, rtm->rtm_type, NULL), buf);
break; break;
case ZEBRA_RIB_FOUND_CONNECTED: case ZEBRA_RIB_FOUND_CONNECTED:
case ZEBRA_RIB_FOUND_NOGATE: case ZEBRA_RIB_FOUND_NOGATE:
inet_ntop (AF_INET, &gate.sin.sin_addr, gate_buf, INET_ADDRSTRLEN); inet_ntop (AF_INET, &gate.sin.sin_addr, gate_buf, INET_ADDRSTRLEN);
zlog_debug ("%s: %s %s: desync: RR is in RIB, but gate differs (ours is %s)", zlog_debug ("%s: %s %s: desync: RR is in RIB, but gate differs (ours is %s)",
__func__, lookup (rtm_type_str, rtm->rtm_type), buf, gate_buf); __func__, lookup_msg(rtm_type_str, rtm->rtm_type, NULL), buf, gate_buf);
break; break;
case ZEBRA_RIB_FOUND_EXACT: /* RIB RR == FIB RR */ case ZEBRA_RIB_FOUND_EXACT: /* RIB RR == FIB RR */
zlog_debug ("%s: %s %s: done Ok", zlog_debug ("%s: %s %s: done Ok",
__func__, lookup (rtm_type_str, rtm->rtm_type), buf); __func__, lookup_msg(rtm_type_str, rtm->rtm_type, NULL), buf);
rib_lookup_and_dump ((struct prefix_ipv4 *)&p, VRF_DEFAULT); rib_lookup_and_dump ((struct prefix_ipv4 *)&p, VRF_DEFAULT);
return; return;
break; break;
@ -962,18 +962,18 @@ rtm_read (struct rt_msghdr *rtm)
{ {
case ZEBRA_RIB_FOUND_EXACT: case ZEBRA_RIB_FOUND_EXACT:
zlog_debug ("%s: %s %s: desync: RR is still in RIB, while already not in FIB", zlog_debug ("%s: %s %s: desync: RR is still in RIB, while already not in FIB",
__func__, lookup (rtm_type_str, rtm->rtm_type), buf); __func__, lookup_msg(rtm_type_str, rtm->rtm_type, NULL), buf);
rib_lookup_and_dump ((struct prefix_ipv4 *)&p, VRF_DEFAULT); rib_lookup_and_dump ((struct prefix_ipv4 *)&p, VRF_DEFAULT);
break; break;
case ZEBRA_RIB_FOUND_CONNECTED: case ZEBRA_RIB_FOUND_CONNECTED:
case ZEBRA_RIB_FOUND_NOGATE: case ZEBRA_RIB_FOUND_NOGATE:
zlog_debug ("%s: %s %s: desync: RR is still in RIB, plus gate differs", zlog_debug ("%s: %s %s: desync: RR is still in RIB, plus gate differs",
__func__, lookup (rtm_type_str, rtm->rtm_type), buf); __func__, lookup_msg(rtm_type_str, rtm->rtm_type, NULL), buf);
rib_lookup_and_dump ((struct prefix_ipv4 *)&p, VRF_DEFAULT); rib_lookup_and_dump ((struct prefix_ipv4 *)&p, VRF_DEFAULT);
break; break;
case ZEBRA_RIB_NOTFOUND: /* RIB RR == FIB RR */ case ZEBRA_RIB_NOTFOUND: /* RIB RR == FIB RR */
zlog_debug ("%s: %s %s: done Ok", zlog_debug ("%s: %s %s: done Ok",
__func__, lookup (rtm_type_str, rtm->rtm_type), buf); __func__, lookup_msg(rtm_type_str, rtm->rtm_type, NULL), buf);
rib_lookup_and_dump ((struct prefix_ipv4 *)&p, VRF_DEFAULT); rib_lookup_and_dump ((struct prefix_ipv4 *)&p, VRF_DEFAULT);
return; return;
break; break;
@ -981,7 +981,7 @@ rtm_read (struct rt_msghdr *rtm)
break; break;
default: default:
zlog_debug ("%s: %s: warning: loopback RTM of type %s received", zlog_debug ("%s: %s: warning: loopback RTM of type %s received",
__func__, buf, lookup (rtm_type_str, rtm->rtm_type)); __func__, buf, lookup_msg(rtm_type_str, rtm->rtm_type, NULL));
} }
return; return;
} }
@ -1202,7 +1202,7 @@ rtm_write (int message,
static void static void
rtmsg_debug (struct rt_msghdr *rtm) rtmsg_debug (struct rt_msghdr *rtm)
{ {
zlog_debug ("Kernel: Len: %d Type: %s", rtm->rtm_msglen, lookup (rtm_type_str, rtm->rtm_type)); zlog_debug ("Kernel: Len: %d Type: %s", rtm->rtm_msglen, lookup_msg(rtm_type_str, rtm->rtm_type, NULL));
rtm_flag_dump (rtm->rtm_flags); rtm_flag_dump (rtm->rtm_flags);
zlog_debug ("Kernel: message seq %d", rtm->rtm_seq); zlog_debug ("Kernel: message seq %d", rtm->rtm_seq);
zlog_debug ("Kernel: pid %lld, rtm_addrs 0x%x", zlog_debug ("Kernel: pid %lld, rtm_addrs 0x%x",

View File

@ -218,14 +218,14 @@ kernel_rtm_ipv4 (int cmd, struct prefix *p, struct route_entry *re)
default: default:
zlog_err ("%s: %s: rtm_write() unexpectedly returned %d for command %s", zlog_err ("%s: %s: rtm_write() unexpectedly returned %d for command %s",
__func__, prefix2str(p, prefix_buf, sizeof(prefix_buf)), __func__, prefix2str(p, prefix_buf, sizeof(prefix_buf)),
error, lookup (rtm_type_str, cmd)); error, lookup_msg(rtm_type_str, cmd, NULL));
break; break;
} }
} /* if (cmd and flags make sense) */ } /* if (cmd and flags make sense) */
else else
if (IS_ZEBRA_DEBUG_RIB) if (IS_ZEBRA_DEBUG_RIB)
zlog_debug ("%s: odd command %s for flags %d", zlog_debug ("%s: odd command %s for flags %d",
__func__, lookup (rtm_type_str, cmd), nexthop->flags); __func__, lookup_msg(rtm_type_str, cmd, NULL), nexthop->flags);
} /* for (ALL_NEXTHOPS_RO(...))*/ } /* for (ALL_NEXTHOPS_RO(...))*/
/* If there was no useful nexthop, then complain. */ /* If there was no useful nexthop, then complain. */