From 5e882cab8fc828de286f1ead04ff6d648f05d832 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Tue, 20 Jun 2017 23:56:50 +0000 Subject: [PATCH 1/9] *: 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 --- bgpd/bgp_attr.c | 25 ++++++------ bgpd/bgp_debug.c | 28 ++++++------- bgpd/bgp_debug.h | 1 - bgpd/bgp_fsm.c | 16 ++++---- bgpd/bgp_open.c | 20 +++++----- bgpd/bgp_packet.c | 6 +-- bgpd/bgp_vty.c | 10 ++--- bgpd/bgpd.h | 6 --- bgpd/rfapi/rfapi_import.c | 2 +- lib/grammar_sandbox.c | 7 ++-- lib/log.c | 82 +++++++++++++-------------------------- lib/log.h | 9 +---- nhrpd/nhrp_vty.c | 4 +- ospf6d/ospf6_message.c | 14 +++---- ospfclient/ospfclient.c | 4 +- ospfd/ospf_dump.c | 14 +++---- ospfd/ospf_dump_api.c | 15 ++++--- ospfd/ospf_flood.c | 4 +- ospfd/ospf_ism.c | 6 +-- ospfd/ospf_lsa.c | 4 +- ospfd/ospf_nsm.c | 18 ++++----- ospfd/ospf_packet.c | 42 ++++++++++---------- ospfd/ospf_snmp.c | 2 +- ospfd/ospf_vty.c | 12 +++--- ospfd/ospfd.c | 4 +- ripd/rip_interface.c | 5 ++- ripd/ripd.c | 20 +++++----- zebra/kernel_netlink.c | 16 ++++---- zebra/kernel_socket.c | 22 +++++------ zebra/rt_socket.c | 4 +- 30 files changed, 189 insertions(+), 233 deletions(-) diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index 4d5f7cab5d..0c18eb11b5 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -78,9 +78,9 @@ static const struct message attr_str [] = #if ENABLE_BGP_VNC { BGP_ATTR_VNC, "VNC" }, #endif - { BGP_ATTR_LARGE_COMMUNITIES, "LARGE_COMMUNITY" } + { BGP_ATTR_LARGE_COMMUNITIES, "LARGE_COMMUNITY" }, + { 0 } }; -static const int attr_str_max = array_size(attr_str); static const struct message attr_flag_str[] = { @@ -89,6 +89,7 @@ static const struct message attr_flag_str[] = { BGP_ATTR_FLAG_PARTIAL, "Partial" }, /* bgp_attr_flags_diagnose() relies on this bit being last in this list */ { BGP_ATTR_FLAG_EXTLEN, "Extended Length" }, + { 0 } }; static struct hash *cluster_hash; @@ -1253,7 +1254,7 @@ bgp_attr_flags_diagnose (struct bgp_attr_parser_args *args, ) { 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", attr_flag_str[i].str); seen = 1; @@ -1262,7 +1263,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" " (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); } } @@ -1310,7 +1311,7 @@ bgp_attr_flag_invalid (struct bgp_attr_parser_args *args) && !CHECK_FLAG (BGP_ATTR_FLAG_TRANS, flags)) { 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; } @@ -1323,7 +1324,7 @@ bgp_attr_flag_invalid (struct bgp_attr_parser_args *args) { zlog_err ("%s well-known attribute " "must NOT have the partial flag set (%x)", - LOOKUP (attr_str, attr_code), flags); + lookup_msg(attr_str, attr_code, NULL), flags); return 1; } if (CHECK_FLAG (flags, BGP_ATTR_FLAG_OPTIONAL) @@ -1331,7 +1332,7 @@ bgp_attr_flag_invalid (struct bgp_attr_parser_args *args) { zlog_err ("%s optional + transitive attribute " "must NOT have the partial flag set (%x)", - LOOKUP (attr_str, attr_code), flags); + lookup_msg(attr_str, attr_code, NULL), flags); return 1; } } @@ -2374,7 +2375,7 @@ bgp_attr_check (struct peer *peer, struct attr *attr) if (type) { 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_UPDATE_ERR, BGP_NOTIFY_UPDATE_MISS_ATTR, @@ -2590,7 +2591,7 @@ bgp_attr_parse (struct peer *peer, struct attr *attr, bgp_size_t size, { zlog_warn ("%s: Attribute %s, parse error", peer->host, - LOOKUP (attr_str, type)); + lookup_msg(attr_str, type, NULL)); if (as4_path) aspath_unintern (&as4_path); return ret; @@ -2600,7 +2601,7 @@ bgp_attr_parse (struct peer *peer, struct attr *attr, bgp_size_t size, zlog_warn ("%s: Attribute %s, parse error - treating as withdrawal", peer->host, - LOOKUP (attr_str, type)); + lookup_msg(attr_str, type, NULL)); if (as4_path) aspath_unintern (&as4_path); return ret; @@ -2610,7 +2611,7 @@ bgp_attr_parse (struct peer *peer, struct attr *attr, bgp_size_t size, if (BGP_INPUT_PNT (peer) != attr_endp) { 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_UPDATE_ERR, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR); @@ -2624,7 +2625,7 @@ bgp_attr_parse (struct peer *peer, struct attr *attr, bgp_size_t size, if (BGP_INPUT_PNT (peer) != endp) { 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_UPDATE_ERR, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR); diff --git a/bgpd/bgp_debug.c b/bgpd/bgp_debug.c index fb350d51a1..8b6db50b19 100644 --- a/bgpd/bgp_debug.c +++ b/bgpd/bgp_debug.c @@ -85,8 +85,8 @@ const struct message bgp_status_msg[] = { Established, "Established" }, { Clearing, "Clearing" }, { Deleted, "Deleted" }, + { 0 } }; -const int bgp_status_msg_max = BGP_STATUS_MAX; /* BGP message type string. */ 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_CEASE, "Cease"}, { 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[] = { { BGP_NOTIFY_HEADER_NOT_SYNC, "/Connection Not Synchronized"}, { 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[] = { @@ -131,8 +131,8 @@ static const struct message bgp_notify_open_msg[] = { BGP_NOTIFY_OPEN_AUTH_FAILURE, "/Authentication Failure"}, { BGP_NOTIFY_OPEN_UNACEP_HOLDTIME, "/Unacceptable Hold Time"}, { 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[] = { @@ -148,8 +148,8 @@ static const struct message bgp_notify_update_msg[] = { BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, "/Optional Attribute Error"}, { BGP_NOTIFY_UPDATE_INVAL_NETWORK, "/Invalid Network Field"}, { 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[] = { @@ -162,8 +162,8 @@ static const struct message bgp_notify_cease_msg[] = { BGP_NOTIFY_CEASE_CONFIG_CHANGE, "/Other Configuration Change"}, { BGP_NOTIFY_CEASE_COLLISION_RESOLUTION, "/Connection collision resolution"}, { 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[] = { @@ -171,8 +171,8 @@ static const struct message bgp_notify_capability_msg[] = { BGP_NOTIFY_CAPABILITY_INVALID_ACTION, "/Invalid Action Value" }, { BGP_NOTIFY_CAPABILITY_INVALID_LENGTH, "/Invalid Capability Length"}, { BGP_NOTIFY_CAPABILITY_MALFORMED_CODE, "/Malformed Capability Value"}, + { 0 } }; -static const int bgp_notify_capability_msg_max = BGP_NOTIFY_CAPABILITY_MAX; /* Origin strings. */ const char *bgp_origin_str[] = {"i","e","?"}; @@ -457,7 +457,7 @@ bgp_dump_attr (struct peer *peer, struct attr *attr, char *buf, size_t size) const char * 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 * @@ -467,23 +467,23 @@ bgp_notify_subcode_str (char code, char subcode) switch (code) { case BGP_NOTIFY_HEADER_ERR: - return LOOKUP_DEF (bgp_notify_head_msg, subcode, + return lookup_msg (bgp_notify_head_msg, subcode, "Unrecognized Error Subcode"); case BGP_NOTIFY_OPEN_ERR: - return LOOKUP_DEF (bgp_notify_open_msg, subcode, + return lookup_msg (bgp_notify_open_msg, subcode, "Unrecognized Error Subcode"); case BGP_NOTIFY_UPDATE_ERR: - return LOOKUP_DEF (bgp_notify_update_msg, subcode, + return lookup_msg (bgp_notify_update_msg, subcode, "Unrecognized Error Subcode"); case BGP_NOTIFY_HOLD_ERR: break; case BGP_NOTIFY_FSM_ERR: break; case BGP_NOTIFY_CEASE: - return LOOKUP_DEF (bgp_notify_cease_msg, subcode, + return lookup_msg (bgp_notify_cease_msg, subcode, "Unrecognized Error Subcode"); case BGP_NOTIFY_CAPABILITY_ERR: - return LOOKUP_DEF (bgp_notify_capability_msg, subcode, + return lookup_msg (bgp_notify_capability_msg, subcode, "Unrecognized Error Subcode"); } return ""; diff --git a/bgpd/bgp_debug.h b/bgpd/bgp_debug.h index 0968568225..260f8129fd 100644 --- a/bgpd/bgp_debug.h +++ b/bgpd/bgp_debug.h @@ -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 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_keepalive(struct peer *peer); extern int bgp_debug_update(struct peer *peer, struct prefix *p, diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c index fbca83c750..2b8498e518 100644 --- a/bgpd/bgp_fsm.c +++ b/bgpd/bgp_fsm.c @@ -972,8 +972,8 @@ bgp_fsm_change_status (struct peer *peer, int status) if (bgp_debug_neighbor_events(peer)) zlog_debug ("%s went from %s to %s", peer->host, - LOOKUP (bgp_status_msg, peer->ostatus), - LOOKUP (bgp_status_msg, peer->status)); + lookup_msg(bgp_status_msg, peer->ostatus, NULL), + lookup_msg(bgp_status_msg, peer->status, NULL)); } /* Flush the event queue and ensure the peer is shut down */ @@ -1412,7 +1412,7 @@ static int bgp_fsm_event_error (struct peer *peer) { 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); } @@ -1598,7 +1598,7 @@ bgp_ignore (struct peer *peer) { zlog_err ("%s [FSM] Ignoring event %s in state %s, prior events %s, %s, fd %d", 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_major_event], peer->fd); return 0; @@ -1610,7 +1610,7 @@ bgp_fsm_exeption (struct peer *peer) { zlog_err ("%s [FSM] Unexpected event %s in state %s, prior events %s, %s, fd %d", 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_major_event], peer->fd); return(bgp_stop (peer)); @@ -1836,8 +1836,8 @@ bgp_event_update (struct peer *peer, int event) if (bgp_debug_neighbor_events(peer) && peer->status != next) zlog_debug ("%s [FSM] %s (%s->%s), fd %d", peer->host, bgp_event_str[event], - LOOKUP (bgp_status_msg, peer->status), - LOOKUP (bgp_status_msg, next), peer->fd); + lookup_msg(bgp_status_msg, peer->status, NULL), + lookup_msg(bgp_status_msg, next, NULL), peer->fd); peer->last_event = peer->cur_event; peer->cur_event = event; @@ -1872,7 +1872,7 @@ bgp_event_update (struct peer *peer, int event) zlog_err ("%s [FSM] Failure handling event %s in state %s, " "prior events %s, %s, fd %d", 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_major_event], peer->fd); bgp_stop (peer); diff --git a/bgpd/bgp_open.c b/bgpd/bgp_open.c index 51079f31e0..e808ceab3a 100644 --- a/bgpd/bgp_open.c +++ b/bgpd/bgp_open.c @@ -245,16 +245,16 @@ static const struct message orf_type_str[] = { { ORF_TYPE_PREFIX, "Prefixlist" }, { 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[] = { { ORF_MODE_RECEIVE, "Receive" }, { ORF_MODE_SEND, "Send" }, { ORF_MODE_BOTH, "Both" }, + { 0 } }; -static const int orf_mode_str_max = array_size(orf_mode_str); static int bgp_capability_orf_entry (struct peer *peer, struct capability_header *hdr) @@ -359,8 +359,8 @@ bgp_capability_orf_entry (struct peer *peer, struct capability_header *hdr) if (bgp_debug_neighbor_events(peer)) zlog_debug ("%s OPEN has %s ORF capability" " as %s for afi/safi: %d/%d", - peer->host, LOOKUP (orf_type_str, type), - LOOKUP (orf_mode_str, mode), + peer->host, lookup_msg(orf_type_str, type, NULL), + lookup_msg(orf_mode_str, mode, NULL), pkt_afi, pkt_safi); if (hdr->code == CAPABILITY_CODE_ORF) @@ -709,9 +709,9 @@ bgp_capability_hostname (struct peer *peer, struct capability_header *hdr) { CAPABILITY_CODE_DYNAMIC_OLD, "Dynamic (Old)" }, { CAPABILITY_CODE_REFRESH_OLD, "Route Refresh (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) */ static const size_t cap_minsizes[] = @@ -798,7 +798,7 @@ bgp_capability_parse (struct peer *peer, size_t length, int *mp_capability, if (bgp_debug_neighbor_events(peer)) zlog_debug ("%s OPEN has %s capability (%u), length %u", peer->host, - LOOKUP (capcode_str, caphdr.code), + lookup_msg(capcode_str, caphdr.code, NULL), caphdr.code, caphdr.length); /* Length sanity check, type-specific, for known capabilities */ @@ -822,7 +822,7 @@ bgp_capability_parse (struct peer *peer, size_t length, int *mp_capability, zlog_info ("%s %s Capability length error: got %u," " expected at least %u", peer->host, - LOOKUP (capcode_str, caphdr.code), + lookup_msg(capcode_str, caphdr.code, NULL), caphdr.length, (unsigned) cap_minsizes[caphdr.code]); bgp_notify_send (peer, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_MALFORMED_ATTR); @@ -834,7 +834,7 @@ bgp_capability_parse (struct peer *peer, size_t length, int *mp_capability, zlog_info ("%s %s Capability length error: got %u," " expected a multiple of %u", peer->host, - LOOKUP (capcode_str, caphdr.code), + lookup_msg(capcode_str, caphdr.code, NULL), caphdr.length, (unsigned) cap_modsizes[caphdr.code]); bgp_notify_send (peer, BGP_NOTIFY_OPEN_ERR, @@ -933,7 +933,7 @@ bgp_capability_parse (struct peer *peer, size_t length, int *mp_capability, { if (stream_get_getp(s) > (start + caphdr.length)) 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); stream_set_getp (s, start + caphdr.length); } diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c index 77395bf859..b1fa50974b 100644 --- a/bgpd/bgp_packet.c +++ b/bgpd/bgp_packet.c @@ -1377,7 +1377,7 @@ bgp_update_receive (struct peer *peer, bgp_size_t size) if (peer->status != Established) { 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); return -1; } @@ -1743,7 +1743,7 @@ bgp_route_refresh_receive (struct peer *peer, bgp_size_t size) if (peer->status != Established) { 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); return; } @@ -2072,7 +2072,7 @@ bgp_capability_receive (struct peer *peer, bgp_size_t size) if (peer->status != Established) { 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); return -1; } diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 7e2912440a..a82856db1d 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -6545,7 +6545,7 @@ bgp_show_summary (struct vty *vty, struct bgp *bgp, int afi, int safi, else if (CHECK_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW)) json_object_string_add(json_peer, "state", "Idle (PfxCt)"); 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) json_object_string_add(json_peer, "idType", "interface"); @@ -6597,7 +6597,7 @@ bgp_show_summary (struct vty *vty, struct bgp *bgp, int afi, int safi, else if (CHECK_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW)) vty_out (vty, " Idle (PfxCt)"); 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); } @@ -7576,7 +7576,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"); /* 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) { @@ -7649,7 +7649,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); /* 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) vty_out (vty, ", up for %8s", peer_uptime (p->uptime, timebuf, BGP_UPTIME_LEN, 0, NULL)); @@ -9350,7 +9350,7 @@ bgp_show_one_peer_group (struct vty *vty, struct peer_group *group) else if (CHECK_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW)) peer_status = "Idle (PfxCt)"; else - peer_status = LOOKUP(bgp_status_msg, peer->status); + peer_status = lookup_msg(bgp_status_msg, peer->status, NULL); dynamic = peer_dynamic_neighbor(peer); vty_out (vty, " %s %s %s %s", diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index a72974bc1d..bc7ba0581d 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -988,7 +988,6 @@ struct bgp_nlri #define BGP_NOTIFY_FSM_ERR 5 #define BGP_NOTIFY_CEASE 6 #define BGP_NOTIFY_CAPABILITY_ERR 7 -#define BGP_NOTIFY_MAX 8 #define BGP_NOTIFY_SUBCODE_UNSPECIFIC 0 @@ -996,7 +995,6 @@ struct bgp_nlri #define BGP_NOTIFY_HEADER_NOT_SYNC 1 #define BGP_NOTIFY_HEADER_BAD_MESLEN 2 #define BGP_NOTIFY_HEADER_BAD_MESTYPE 3 -#define BGP_NOTIFY_HEADER_MAX 4 /* BGP_NOTIFY_OPEN_ERR sub codes. */ #define BGP_NOTIFY_OPEN_MALFORMED_ATTR 0 @@ -1007,7 +1005,6 @@ struct bgp_nlri #define BGP_NOTIFY_OPEN_AUTH_FAILURE 5 #define BGP_NOTIFY_OPEN_UNACEP_HOLDTIME 6 #define BGP_NOTIFY_OPEN_UNSUP_CAPBL 7 -#define BGP_NOTIFY_OPEN_MAX 8 /* BGP_NOTIFY_UPDATE_ERR sub codes. */ #define BGP_NOTIFY_UPDATE_MAL_ATTR 1 @@ -1021,7 +1018,6 @@ struct bgp_nlri #define BGP_NOTIFY_UPDATE_OPT_ATTR_ERR 9 #define BGP_NOTIFY_UPDATE_INVAL_NETWORK 10 #define BGP_NOTIFY_UPDATE_MAL_AS_PATH 11 -#define BGP_NOTIFY_UPDATE_MAX 12 /* BGP_NOTIFY_CEASE sub codes (RFC 4486). */ #define BGP_NOTIFY_CEASE_MAX_PREFIX 1 @@ -1032,13 +1028,11 @@ struct bgp_nlri #define BGP_NOTIFY_CEASE_CONFIG_CHANGE 6 #define BGP_NOTIFY_CEASE_COLLISION_RESOLUTION 7 #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). */ #define BGP_NOTIFY_CAPABILITY_INVALID_ACTION 1 #define BGP_NOTIFY_CAPABILITY_INVALID_LENGTH 2 #define BGP_NOTIFY_CAPABILITY_MALFORMED_CODE 3 -#define BGP_NOTIFY_CAPABILITY_MAX 4 /* BGP finite state machine status. */ #define Idle 1 diff --git a/bgpd/rfapi/rfapi_import.c b/bgpd/rfapi/rfapi_import.c index 4a05018d23..b99d102d70 100644 --- a/bgpd/rfapi/rfapi_import.c +++ b/bgpd/rfapi/rfapi_import.c @@ -3244,7 +3244,7 @@ rfapiBgpInfoFilteredImportEncap ( rn = route_node_lookup (rt, p); #if DEBUG_ENCAP_MONITOR - vnc_zlog_debug_verbose ("%s: initial encap lookup (it=%p) rn=%p", + vnc_zlog_debug_verbose ("%s: initial encap lookup(it=%p) rn=%p", __func__, import_table, rn); #endif diff --git a/lib/grammar_sandbox.c b/lib/grammar_sandbox.c index 0da7981fc1..3561d7466a 100644 --- a/lib/grammar_sandbox.c +++ b/lib/grammar_sandbox.c @@ -504,9 +504,8 @@ struct message tokennames[] = { item(JOIN_TKN), item(START_TKN), // first 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. @@ -523,7 +522,7 @@ pretty_print_graph (struct vty *vty, struct graph_node *start, int level, struct cmd_token *tok = start->data; 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) vty_out(vty, ":\"%s\"", tok->text); if (desc) @@ -590,7 +589,7 @@ pretty_print_dot (FILE *ofd, unsigned opts, struct graph_node *start, snprintf(tokennum, sizeof(tokennum), "%d?", tok->type); fprintf(ofd, " n%p [ shape=box, label=<", start); - fprintf(ofd, "%s", LOOKUP_DEF(tokennames, tok->type, tokennum)); + fprintf(ofd, "%s", lookup_msg(tokennames, tok->type, NULL)); if (tok->attr == CMD_ATTR_DEPRECATED) fprintf(ofd, " (d)"); else if (tok->attr == CMD_ATTR_HIDDEN) diff --git a/lib/log.c b/lib/log.c index c7d4ca2d97..52d92de392 100644 --- a/lib/log.c +++ b/lib/log.c @@ -86,8 +86,33 @@ static void write_wrapper (int fd, const void *buf, size_t count) 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 quagga_timestamp(int timestamp_precision, char *buf, size_t buflen) { @@ -847,61 +872,6 @@ zlog_rotate (void) 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. */ const char * safe_strerror(int errnum) diff --git a/lib/log.h b/lib/log.h index cc419cc374..a8464be330 100644 --- a/lib/log.h +++ b/lib/log.h @@ -101,14 +101,7 @@ extern int zlog_reset_file (void); /* Rotate log. */ extern int zlog_rotate (void); -/* For hackey message lookup and check */ -#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); +const char *lookup_msg (const struct message *mz, int kz, const char *nf); /* Safe version of strerror -- never returns NULL. */ extern const char *safe_strerror(int errnum); diff --git a/nhrpd/nhrp_vty.c b/nhrpd/nhrp_vty.c index dc89683277..3341743c69 100644 --- a/nhrpd/nhrp_vty.c +++ b/nhrpd/nhrp_vty.c @@ -46,14 +46,14 @@ static const struct message debug_flags_desc[] = { { NHRP_DEBUG_ROUTE, "route" }, { NHRP_DEBUG_VICI, "vici" }, { NHRP_DEBUG_EVENT, "event" }, - { 0, NULL }, + { 0 } }; static const struct message interface_flags_desc[] = { { NHRP_IFF_SHORTCUT, "shortcut" }, { NHRP_IFF_REDIRECT, "redirect" }, { NHRP_IFF_REG_NO_UNIQUE, "registration no-unique" }, - { 0, NULL }, + { 0 } }; static int nhrp_vty_return(struct vty *vty, int ret) diff --git a/ospf6d/ospf6_message.c b/ospf6d/ospf6_message.c index 578b39a641..69a53fcbd5 100644 --- a/ospf6d/ospf6_message.c +++ b/ospf6d/ospf6_message.c @@ -57,8 +57,8 @@ static const struct message ospf6_message_type_str [] = { OSPF6_MESSAGE_TYPE_LSREQ, "LSReq" }, { OSPF6_MESSAGE_TYPE_LSUPDATE, "LSUpdate" }, { 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 packets of particular types, offset is the "type" field. */ @@ -1211,7 +1211,7 @@ ospf6_packet_examin (struct ospf6_header *oh, const unsigned bytesonwire) { if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) 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; } /* type-specific deeper validation */ @@ -1224,7 +1224,7 @@ ospf6_packet_examin (struct ospf6_header *oh, const unsigned bytesonwire) return MSG_OK; if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) 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; case OSPF6_MESSAGE_TYPE_DBDESC: /* RFC5340 A.3.3, packet header + OSPF6_DB_DESC_MIN_SIZE bytes followed @@ -1243,7 +1243,7 @@ ospf6_packet_examin (struct ospf6_header *oh, const unsigned bytesonwire) return MSG_OK; if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) 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; case OSPF6_MESSAGE_TYPE_LSUPDATE: /* RFC5340 A.3.5, packet header + OSPF6_LS_UPD_MIN_SIZE bytes followed @@ -1273,7 +1273,7 @@ ospf6_packet_examin (struct ospf6_header *oh, const unsigned bytesonwire) return MSG_NG; } 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; } @@ -1581,7 +1581,7 @@ ospf6_receive (struct thread *thread) inet_ntop (AF_INET6, &src, srcname, sizeof (srcname)); inet_ntop (AF_INET6, &dst, dstname, sizeof (dstname)); 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 (" dst: %s", dstname); @@ -1669,7 +1669,7 @@ ospf6_send (struct in6_addr *src, struct in6_addr *dst, else memset (srcname, 0, sizeof (srcname)); 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 (" dst: %s", dstname); diff --git a/ospfclient/ospfclient.c b/ospfclient/ospfclient.c index 43ffa1da8e..c51725adcf 100644 --- a/ospfclient/ospfclient.c +++ b/ospfclient/ospfclient.c @@ -252,7 +252,7 @@ ism_change_callback (struct in_addr ifaddr, struct in_addr area_id, { printf ("ism_change: ifaddr: %s ", inet_ntoa (ifaddr)); 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 @@ -262,7 +262,7 @@ nsm_change_callback (struct in_addr ifaddr, struct in_addr nbraddr, printf ("nsm_change: ifaddr: %s ", inet_ntoa (ifaddr)); printf ("nbraddr: %s\n", inet_ntoa (nbraddr)); 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)); } diff --git a/ospfd/ospf_dump.c b/ospfd/ospf_dump.c index 21b2855499..a33da0a6a3 100644 --- a/ospfd/ospf_dump.c +++ b/ospfd/ospf_dump.c @@ -154,8 +154,8 @@ ospf_nbr_state_message (struct ospf_neighbor *nbr, char *buf, size_t size) memset (buf, 0, size); snprintf (buf, size, "%s/%s", - LOOKUP (ospf_nsm_state_msg, nbr->state), - LOOKUP (ospf_ism_state_msg, state)); + lookup_msg(ospf_nsm_state_msg, nbr->state, NULL), + lookup_msg(ospf_ism_state_msg, state, NULL)); } const char * @@ -560,12 +560,12 @@ ospf_header_dump (struct ospf_header *ospfh) zlog_debug ("Header"); zlog_debug (" Version %d", ospfh->version); 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 (" Router ID %s", inet_ntoa (ospfh->router_id)); zlog_debug (" Area ID %s", inet_ntoa (ospfh->area_id)); 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) { @@ -1609,7 +1609,7 @@ show_debugging_ospf_common (struct vty *vty, struct ospf *ospf) if (IS_DEBUG_OSPF_PACKET (i, SEND) && IS_DEBUG_OSPF_PACKET (i, RECV)) { 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" : "", VTY_NEWLINE); } @@ -1617,12 +1617,12 @@ show_debugging_ospf_common (struct vty *vty, struct ospf *ospf) { if (IS_DEBUG_OSPF_PACKET (i, SEND)) 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" : "", VTY_NEWLINE); if (IS_DEBUG_OSPF_PACKET (i, RECV)) 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" : "", VTY_NEWLINE); } diff --git a/ospfd/ospf_dump_api.c b/ospfd/ospf_dump_api.c index 5ef262ce54..dd11ec4745 100644 --- a/ospfd/ospf_dump_api.c +++ b/ospfd/ospf_dump_api.c @@ -40,8 +40,8 @@ const struct message ospf_ism_state_msg[] = { ISM_DROther, "DROther" }, { ISM_Backup, "Backup" }, { ISM_DR, "DR" }, + { 0 } }; -const int ospf_ism_state_msg_max = OSPF_ISM_STATE_MAX; const struct message ospf_nsm_state_msg[] = { @@ -55,8 +55,8 @@ const struct message ospf_nsm_state_msg[] = { NSM_Exchange, "Exchange" }, { NSM_Loading, "Loading" }, { NSM_Full, "Full" }, + { 0 } }; -const int ospf_nsm_state_msg_max = OSPF_NSM_STATE_MAX; 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_AREA_LSA, "Area-Local 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[] = { @@ -89,8 +89,8 @@ const struct message ospf_link_state_id_type_msg[] = { OSPF_OPAQUE_LINK_LSA, "(Link-Local Opaque-Type/ID)" }, { OSPF_OPAQUE_AREA_LSA, "(Area-Local 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[] = { @@ -100,8 +100,8 @@ const struct message ospf_network_type_msg[] = { OSPF_IFTYPE_NBMA, "NBMA" }, { OSPF_IFTYPE_POINTOMULTIPOINT, "Point-to-MultiPoint" }, { OSPF_IFTYPE_VIRTUALLINK, "Virtual-Link" }, + { 0 } }; -const int ospf_network_type_msg_max = OSPF_IFTYPE_MAX; /* AuType */ const struct message ospf_auth_type_str[] = @@ -109,9 +109,8 @@ const struct message ospf_auth_type_str[] = { OSPF_AUTH_NULL, "Null" }, { OSPF_AUTH_SIMPLE, "Simple" }, { 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 @@ -135,7 +134,7 @@ ospf_options_dump (u_char options) void 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 (" LS age %d", ntohs (lsah->ls_age)); diff --git a/ospfd/ospf_flood.c b/ospfd/ospf_flood.c index 4cc28f7486..dd7874aa2f 100644 --- a/ospfd/ospf_flood.c +++ b/ospfd/ospf_flood.c @@ -256,7 +256,7 @@ ospf_flood (struct ospf *ospf, struct ospf_neighbor *nbr, if (IS_DEBUG_OSPF_EVENT) zlog_debug ("LSA[Flooding]: start, NBR %s (%s), cur(%p), New-LSA[%s]", inet_ntoa (nbr->router_id), - LOOKUP (ospf_nsm_state_msg, nbr->state), + lookup_msg(ospf_nsm_state_msg, nbr->state, NULL), (void *)current, dump_lsa_key (new)); @@ -380,7 +380,7 @@ ospf_flood_through_interface (struct ospf_interface *oi, if (IS_DEBUG_OSPF_EVENT) zlog_debug ("ospf_flood_through_interface(): considering nbr %s (%s)", 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 does not participate in flooding, and the next neighbor diff --git a/ospfd/ospf_ism.c b/ospfd/ospf_ism.c index 717c99c21f..e325578412 100644 --- a/ospfd/ospf_ism.c +++ b/ospfd/ospf_ism.c @@ -541,8 +541,8 @@ ism_change_state (struct ospf_interface *oi, int state) /* Logging change of state. */ if (IS_DEBUG_OSPF (ism, ISM_STATUS)) zlog_debug("ISM[%s]: State change %s -> %s", IF_NAME(oi), - LOOKUP(ospf_ism_state_msg, oi->state), - LOOKUP(ospf_ism_state_msg, state)); + lookup_msg(ospf_ism_state_msg, oi->state, NULL), + lookup_msg(ospf_ism_state_msg, state, NULL)); old_state = oi->state; oi->state = state; @@ -607,7 +607,7 @@ ospf_ism_event (struct thread *thread) if (IS_DEBUG_OSPF (ism, ISM_EVENTS)) 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]); /* If state is changed. */ diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index cf9943893a..722b18f850 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -2760,13 +2760,13 @@ ospf_lsa_install (struct ospf *ospf, struct ospf_interface *oi, case OSPF_AS_NSSA_LSA: zlog_debug ("LSA[%s]: Install %s", dump_lsa_key (new), - LOOKUP (ospf_lsa_type_msg, new->data->type)); + lookup_msg(ospf_lsa_type_msg, new->data->type, NULL)); break; default: strcpy (area_str, inet_ntoa (new->area->area_id)); zlog_debug ("LSA[%s]: Install %s to Area %s", 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; } } diff --git a/ospfd/ospf_nsm.c b/ospfd/ospf_nsm.c index 97f3f6a382..b1f3a838bc 100644 --- a/ospfd/ospf_nsm.c +++ b/ospfd/ospf_nsm.c @@ -617,8 +617,8 @@ nsm_notice_state_change (struct ospf_neighbor *nbr, int next_state, int event) if (IS_DEBUG_OSPF (nsm, NSM_STATUS)) zlog_debug ("NSM[%s:%s]: State change %s -> %s (%s)", IF_NAME (nbr->oi), inet_ntoa (nbr->router_id), - LOOKUP (ospf_nsm_state_msg, nbr->state), - LOOKUP (ospf_nsm_state_msg, next_state), + lookup_msg(ospf_nsm_state_msg, nbr->state, NULL), + lookup_msg(ospf_nsm_state_msg, next_state, NULL), ospf_nsm_event_str [event]); /* Optionally notify about adjacency changes */ @@ -627,8 +627,8 @@ nsm_notice_state_change (struct ospf_neighbor *nbr, int next_state, int event) (next_state == NSM_Full) || (next_state < nbr->state))) zlog_notice("AdjChg: Nbr %s on %s: %s -> %s (%s)", inet_ntoa (nbr->router_id), IF_NAME (nbr->oi), - LOOKUP (ospf_nsm_state_msg, nbr->state), - LOOKUP (ospf_nsm_state_msg, next_state), + lookup_msg(ospf_nsm_state_msg, nbr->state, NULL), + lookup_msg(ospf_nsm_state_msg, next_state, NULL), ospf_nsm_event_str [event]); /* Advance in NSM */ @@ -736,8 +736,8 @@ nsm_change_state (struct ospf_neighbor *nbr, int state) zlog_info ("nsm_change_state(%s, %s -> %s): " "scheduling new router-LSA origination", inet_ntoa (nbr->router_id), - LOOKUP(ospf_nsm_state_msg, old_state), - LOOKUP(ospf_nsm_state_msg, state)); + lookup_msg(ospf_nsm_state_msg, old_state, NULL), + lookup_msg(ospf_nsm_state_msg, state, NULL)); ospf_router_lsa_update_area (oi->area); @@ -808,7 +808,7 @@ ospf_nsm_event (struct thread *thread) if (IS_DEBUG_OSPF (nsm, NSM_EVENTS)) zlog_debug ("NSM[%s:%s]: %s (%s)", 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]); next_state = NSM [nbr->state][event].next_state; @@ -830,9 +830,9 @@ ospf_nsm_event (struct thread *thread) zlog_warn ("NSM[%s:%s]: %s (%s): " "Warning: action tried to change next_state to %s", 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], - LOOKUP (ospf_nsm_state_msg, func_state)); + lookup_msg(ospf_nsm_state_msg, func_state, NULL)); } } diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c index b7721adb3e..230b44c606 100644 --- a/ospfd/ospf_packet.c +++ b/ospfd/ospf_packet.c @@ -79,9 +79,8 @@ const struct message ospf_packet_type_str[] = { OSPF_MSG_LS_REQ, "Link State Request" }, { OSPF_MSG_LS_UPD, "Link State Update" }, { 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 particular types, offset is the "type" field of a packet. */ @@ -256,8 +255,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, " "destination %s) called with NULL obuf, ignoring " "(please report this bug)!\n", - IF_NAME(oi), oi->state, LOOKUP (ospf_ism_state_msg, oi->state), - LOOKUP (ospf_packet_type_str, stream_getc_from(op->s, 1)), + IF_NAME(oi), oi->state, lookup_msg(ospf_ism_state_msg, oi->state, NULL), + lookup_msg(ospf_packet_type_str, stream_getc_from(op->s, 1), NULL), inet_ntoa (op->dst)); return; } @@ -277,8 +276,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, " "destination %s) called with NULL obuf, ignoring " "(please report this bug)!\n", - IF_NAME(oi), oi->state, LOOKUP (ospf_ism_state_msg, oi->state), - LOOKUP (ospf_packet_type_str, stream_getc_from(op->s, 1)), + IF_NAME(oi), oi->state, lookup_msg(ospf_ism_state_msg, oi->state, NULL), + lookup_msg(ospf_packet_type_str, stream_getc_from(op->s, 1), NULL), inet_ntoa (op->dst)); return; } @@ -815,7 +814,8 @@ ospf_write (struct thread *thread) } 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 (IS_DEBUG_OSPF_PACKET (type - 1, DETAIL)) @@ -879,7 +879,7 @@ ospf_hello (struct ip *iph, struct ospf_header *ospfh, { zlog_debug ("ospf_header[%s/%s]: selforiginated, " "dropping.", - LOOKUP (ospf_packet_type_str, ospfh->type), + lookup_msg(ospf_packet_type_str, ospfh->type, NULL), inet_ntoa (iph->ip_src)); } return; @@ -1317,7 +1317,7 @@ ospf_db_desc (struct ip *iph, struct ospf_header *ospfh, case NSM_TwoWay: zlog_warn ("Packet[DD]: Neighbor %s state is %s, packet discarded.", inet_ntoa(nbr->router_id), - LOOKUP (ospf_nsm_state_msg, nbr->state)); + lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); break; case NSM_Init: OSPF_NSM_EVENT_EXECUTE (nbr, NSM_TwoWayReceived); @@ -1537,7 +1537,7 @@ ospf_ls_req (struct ip *iph, struct ospf_header *ospfh, zlog_warn ("Link State Request received from %s: " "Neighbor state is %s, packet discarded.", inet_ntoa (ospfh->router_id), - LOOKUP (ospf_nsm_state_msg, nbr->state)); + lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); return; } @@ -1772,7 +1772,7 @@ ospf_ls_upd (struct ospf *ospf, struct ip *iph, struct ospf_header *ospfh, zlog_debug ("Link State Update: " "Neighbor[%s] state %s is less than Exchange", inet_ntoa (ospfh->router_id), - LOOKUP(ospf_nsm_state_msg, nbr->state)); + lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); return; } @@ -2117,7 +2117,7 @@ ospf_ls_ack (struct ip *iph, struct ospf_header *ospfh, zlog_debug ("Link State Acknowledgment: " "Neighbor[%s] state %s is less than Exchange", inet_ntoa (ospfh->router_id), - LOOKUP(ospf_nsm_state_msg, nbr->state)); + lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); return; } @@ -2332,7 +2332,7 @@ ospf_check_auth (struct ospf_interface *oi, struct ospf_header *ospfh) { if (IS_DEBUG_OSPF_PACKET (ospfh->type - 1, RECV)) 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; } if (! ospf_check_sum (ospfh)) @@ -2348,7 +2348,7 @@ ospf_check_auth (struct ospf_interface *oi, struct ospf_header *ospfh) { if (IS_DEBUG_OSPF_PACKET (ospfh->type - 1, RECV)) 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; } if (memcmp (OSPF_IF_PARAM (oi, auth_simple), ospfh->u.auth_data, OSPF_AUTH_SIMPLE_SIZE)) @@ -2370,7 +2370,7 @@ ospf_check_auth (struct ospf_interface *oi, struct ospf_header *ospfh) { if (IS_DEBUG_OSPF_PACKET (ospfh->type - 1, RECV)) 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; } if (ospfh->checksum) @@ -2479,7 +2479,7 @@ ospf_lsa_examin (struct lsa_header * lsah, const u_int16_t lsalen, const u_char { if (IS_DEBUG_OSPF_PACKET (0, RECV)) 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; } switch (lsah->type) @@ -2529,7 +2529,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)) 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; } @@ -2668,7 +2668,7 @@ ospf_packet_examin (struct ospf_header * oh, const unsigned bytesonwire) { if (IS_DEBUG_OSPF_PACKET (0, RECV)) 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; } switch (oh->type) @@ -2722,7 +2722,7 @@ ospf_packet_examin (struct ospf_header * oh, const unsigned bytesonwire) return MSG_NG; } 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; } @@ -2911,7 +2911,7 @@ ospf_read (struct thread *thread) { zlog_warn ("Dropping packet for AllDRouters from [%s] via [%s] (ISM: %s)", 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. */ SET_FLAG(oi->multicast_memberships, MEMBER_DROUTERS); ospf_if_set_multicast(oi); @@ -2939,7 +2939,7 @@ ospf_read (struct thread *thread) } 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)); zlog_debug (" src [%s],", inet_ntoa (iph->ip_src)); zlog_debug (" dst [%s]", inet_ntoa (iph->ip_dst)); diff --git a/ospfd/ospf_snmp.c b/ospfd/ospf_snmp.c index 32449d5597..1b0654889d 100644 --- a/ospfd/ospf_snmp.c +++ b/ospfd/ospf_snmp.c @@ -2730,7 +2730,7 @@ ospfTrapIfStateChange (struct ospf_interface *oi) zlog_info("ospfTrapIfStateChange trap sent: %s now %s", 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); index[IN_ADDR_SIZE] = 0; diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 7e8c5ce2ce..00b405eee2 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -3374,7 +3374,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_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_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)); } else @@ -3390,7 +3390,7 @@ show_ip_ospf_interface_sub (struct vty *vty, struct ospf *ospf, struct interface oi->output_cost, VTY_NEWLINE); 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); } @@ -4125,11 +4125,11 @@ show_ip_ospf_neighbor_detail_sub (struct vty *vty, struct ospf_interface *oi, if (use_json) { 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 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. */ if (use_json) @@ -4800,9 +4800,9 @@ show_ip_ospf_database_header (struct vty *vty, struct ospf_lsa *lsa) vty_out (vty, "%s", VTY_NEWLINE); } 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), - 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", inet_ntoa (lsa->data->adv_router), VTY_NEWLINE); vty_out (vty, " LS Seq Number: %08lx%s", (u_long)ntohl (lsa->data->ls_seqnum), diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index af68d1d35f..d906c4e3f7 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -1264,8 +1264,8 @@ static const struct message ospf_area_type_msg[] = { OSPF_AREA_DEFAULT, "Default" }, { OSPF_AREA_STUB, "Stub" }, { OSPF_AREA_NSSA, "NSSA" }, + { 0 } }; -static const int ospf_area_type_msg_max = OSPF_AREA_TYPE_MAX; static void ospf_area_type_set (struct ospf_area *area, int type) @@ -1285,7 +1285,7 @@ ospf_area_type_set (struct ospf_area *area, int type) if (IS_DEBUG_OSPF_EVENT) 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) { diff --git a/ripd/rip_interface.c b/ripd/rip_interface.c index a4ee2ba570..ea68872bca 100644 --- a/ripd/rip_interface.c +++ b/ripd/rip_interface.c @@ -59,6 +59,7 @@ const struct message ri_version_msg[] = {RI_RIP_VERSION_2, "2"}, {RI_RIP_VERSION_1_AND_2, "1 2"}, {RI_RIP_VERSION_NONE, "none"}, + { 0 } }; extern struct zebra_privs_t ripd_privs; @@ -1907,12 +1908,12 @@ rip_interface_config_write (struct vty *vty) /* RIP version setting. */ if (ri->ri_send != RI_RIP_UNSPEC) 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); if (ri->ri_receive != RI_RIP_UNSPEC) 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); if (ri->v2_broadcast) diff --git a/ripd/ripd.c b/ripd/ripd.c index 9e8c21da31..6919e7bf95 100644 --- a/ripd/ripd.c +++ b/ripd/ripd.c @@ -87,7 +87,7 @@ static const struct message rip_msg[] = {RIP_TRACEOFF, "TRACEOFF"}, {RIP_POLL, "POLL"}, {RIP_POLL_ENTRY, "POLL ENTRY"}, - {0, NULL}, + { 0 } }; /* Utility function to set boradcast option to the socket. */ @@ -702,7 +702,7 @@ rip_packet_dump (struct rip_packet *packet, int size, const char *sndrcv) /* Set command string. */ 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 command_str = "unknown"; @@ -2045,12 +2045,12 @@ rip_read (struct thread *t) case RIP_TRACEON: case RIP_TRACEOFF: 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); break; case RIP_POLL_ENTRY: zlog_info ("Obsolete command %s received", - lookup (rip_msg, packet->command)); + lookup_msg (rip_msg, packet->command, NULL)); rip_peer_bad_packet (&from); break; default: @@ -3587,12 +3587,12 @@ DEFUN (show_ip_rip_status, vty_out (vty, "%s", VTY_NEWLINE); 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) vty_out (vty, " receive any version %s", VTY_NEWLINE); else 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); @@ -3606,14 +3606,14 @@ DEFUN (show_ip_rip_status, if (ri->enable_network || ri->enable_interface) { 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 - 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) - receive_version = lookup (ri_version_msg, rip->version_recv); + receive_version = lookup_msg(ri_version_msg, rip->version_recv, NULL); 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, send_version, diff --git a/zebra/kernel_netlink.c b/zebra/kernel_netlink.c index 49394bd6f8..9faf925522 100644 --- a/zebra/kernel_netlink.c +++ b/zebra/kernel_netlink.c @@ -84,7 +84,7 @@ static const struct message nlmsg_str[] = { {RTM_NEWNEIGH, "RTM_NEWNEIGH"}, {RTM_DELNEIGH, "RTM_DELNEIGH"}, {RTM_GETNEIGH, "RTM_GETNEIGH"}, - {0, NULL} + { 0 } }; static const struct message rtproto_str[] = { @@ -100,7 +100,7 @@ static const struct message rtproto_str[] = { {RTPROT_BIRD, "BIRD"}, #endif /* RTPROT_BIRD */ {RTPROT_MROUTED, "mroute"}, - {0, NULL} + { 0 } }; static const struct message family_str[] = { @@ -109,13 +109,13 @@ static const struct message family_str[] = { {AF_BRIDGE, "bridge"}, {RTNL_FAMILY_IPMR, "ipv4MR"}, {RTNL_FAMILY_IP6MR, "ipv6MR"}, - {0, NULL}, + { 0 } }; static const struct message rttype_str[] = { {RTN_UNICAST, "unicast"}, {RTN_MULTICAST, "multicast"}, - {0, NULL}, + { 0 } }; extern struct thread_master *master; @@ -420,25 +420,25 @@ rta_nest_end(struct rtattr *rta, struct rtattr *nest) const char * nl_msg_type_to_str (uint16_t msg_type) { - return lookup (nlmsg_str, msg_type); + return lookup_msg (nlmsg_str, msg_type, ""); } const char * nl_rtproto_to_str (u_char rtproto) { - return lookup (rtproto_str, rtproto); + return lookup_msg (rtproto_str, rtproto, ""); } const char * nl_family_to_str (u_char family) { - return lookup (family_str, family); + return lookup_msg (family_str, family, ""); } const char * nl_rttype_to_str (u_char rttype) { - return lookup (rttype_str, rttype); + return lookup_msg (rttype_str, rttype, ""); } /* diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index 7212ed6f26..eeccd1f175 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -220,7 +220,7 @@ const struct message rtm_type_str[] = #ifdef RTM_IFANNOUNCE {RTM_IFANNOUNCE, "RTM_IFANNOUNCE"}, #endif /* RTM_IFANNOUNCE */ - {0, NULL} + { 0 } }; static const struct message rtm_flag_str[] = @@ -278,7 +278,7 @@ static const struct message rtm_flag_str[] = #ifdef RTF_SETSRC {RTF_SETSRC, "SETSRC"}, #endif /* RTF_SETSRC */ - {0, NULL} + { 0 } }; /* Kernel routing update socket. */ @@ -875,7 +875,7 @@ rtm_read (struct rt_msghdr *rtm) return; if (IS_ZEBRA_DEBUG_KERNEL) 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*/ if (flags & RTF_CLONED) @@ -940,17 +940,17 @@ rtm_read (struct rt_msghdr *rtm) { case ZEBRA_RIB_NOTFOUND: 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; case ZEBRA_RIB_FOUND_CONNECTED: case ZEBRA_RIB_FOUND_NOGATE: 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)", - __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; case ZEBRA_RIB_FOUND_EXACT: /* RIB RR == FIB RR */ 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); return; break; @@ -963,18 +963,18 @@ rtm_read (struct rt_msghdr *rtm) { case ZEBRA_RIB_FOUND_EXACT: 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); break; case ZEBRA_RIB_FOUND_CONNECTED: case ZEBRA_RIB_FOUND_NOGATE: 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); break; case ZEBRA_RIB_NOTFOUND: /* RIB RR == FIB RR */ 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); return; break; @@ -982,7 +982,7 @@ rtm_read (struct rt_msghdr *rtm) break; default: 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; } @@ -1203,7 +1203,7 @@ rtm_write (int message, static void 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); zlog_debug ("Kernel: message seq %d", rtm->rtm_seq); zlog_debug ("Kernel: pid %lld, rtm_addrs 0x%x", diff --git a/zebra/rt_socket.c b/zebra/rt_socket.c index de8cc69a8e..647532761f 100644 --- a/zebra/rt_socket.c +++ b/zebra/rt_socket.c @@ -219,14 +219,14 @@ kernel_rtm_ipv4 (int cmd, struct prefix *p, struct rib *rib) default: zlog_err ("%s: %s: rtm_write() unexpectedly returned %d for command %s", __func__, prefix2str(p, prefix_buf, sizeof(prefix_buf)), - error, lookup (rtm_type_str, cmd)); + error, lookup_msg(rtm_type_str, cmd, NULL)); break; } } /* if (cmd and flags make sense) */ else if (IS_ZEBRA_DEBUG_RIB) 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(...))*/ /* If there was no useful nexthop, then complain. */ From 2dd13a26df48840d8d9dbec272f60e002331fc04 Mon Sep 17 00:00:00 2001 From: Ryan Hagelstrom Date: Fri, 30 Jun 2017 14:21:11 -0500 Subject: [PATCH 2/9] docs: Changed the manpage section from 1 to 8 so it conforms with its definition Signed-off-by: Ryan Hagelstrom --- doc/ospfclient.8.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/ospfclient.8.in b/doc/ospfclient.8.in index fb996a541f..a304beffda 100644 --- a/doc/ospfclient.8.in +++ b/doc/ospfclient.8.in @@ -1,5 +1,5 @@ .\" This file was originally generated by help2man 1.36. -.TH OSPFCLIENT "1" "July 2010" +.TH OSPFCLIENT "8" "July 2010" .SH NAME ospfclient \- an example ospf-api client .SH SYNOPSIS From 619500fd7ef0646315f2124716834c35cb482c69 Mon Sep 17 00:00:00 2001 From: Martin Winter Date: Tue, 11 Jul 2017 18:36:41 -0700 Subject: [PATCH 3/9] redhat: Add missing pimd to daemon config file Signed-off-by: Martin Winter --- redhat/daemons | 2 ++ 1 file changed, 2 insertions(+) diff --git a/redhat/daemons b/redhat/daemons index 6c8cf7e345..f5f4cad88b 100644 --- a/redhat/daemons +++ b/redhat/daemons @@ -45,6 +45,7 @@ ripd=no ripngd=no isisd=no ldpd=no +pimd=no nhrpd=no # # Command line options for the daemons @@ -57,5 +58,6 @@ ripd_options=("-A 127.0.0.1") ripngd_options=("-A ::1") isisd_options=("-A 127.0.0.1") ldpd_options=("-A 127.0.0.1") +pimd_options=("-A 127.0.0.1") nhrpd_options=("-A 127.0.0.1") From e3de326d6c2e84a5471db0f7d5915c455afdb8ef Mon Sep 17 00:00:00 2001 From: Martin Winter Date: Tue, 11 Jul 2017 18:37:02 -0700 Subject: [PATCH 4/9] doc: Update Building Doc for RedHat-style Distro's (CentOS / Fedora) Signed-off-by: Martin Winter --- doc/Building_FRR_on_CentOS6.md | 77 +++++++++++++++++--------------- doc/Building_FRR_on_CentOS7.md | 79 +++++++++++++++++---------------- doc/Building_FRR_on_Fedora24.md | 77 ++++++++++++++++---------------- 3 files changed, 121 insertions(+), 112 deletions(-) diff --git a/doc/Building_FRR_on_CentOS6.md b/doc/Building_FRR_on_CentOS6.md index 9f40418fff..8499340122 100644 --- a/doc/Building_FRR_on_CentOS6.md +++ b/doc/Building_FRR_on_CentOS6.md @@ -1,6 +1,10 @@ Building FRR on CentOS 6 from Git Source ======================================== +(As an alternative to this installation, you may prefer to create a FRR +rpm package yourself and install that package instead. See instructions +in redhat/README.rpm_build.md on how to build a rpm package) + Instructions are tested with `CentOS 6.8` on `x86_64` platform CentOS 6 restrictions: @@ -16,13 +20,15 @@ Install required packages Add packages: - sudo yum install git autoconf automake libtool make gawk readline-devel \ - texinfo net-snmp-devel groff pkgconfig json-c-devel pam-devel \ - flex c-ares-devel epel-release rpm-build libcap-devel texi2html + sudo yum install git autoconf automake libtool make gawk \ + readline-devel texinfo net-snmp-devel groff pkgconfig \ + json-c-devel pam-devel flex epel-release perl-XML-LibXML \ + c-ares-devel Install newer version of bison (CentOS 6 package source is too old) from CentOS 7 + sudo yum install rpm-build curl -O http://vault.centos.org/7.0.1406/os/Source/SPackages/bison-2.7-4.el7.src.rpm rpmbuild --rebuild ./bison-2.7-4.el7.src.rpm sudo yum install ./rpmbuild/RPMS/x86_64/bison-2.7-4.el6.x86_64.rpm @@ -48,12 +54,12 @@ Install newer version of autoconf and automake (Package versions are too old) Install `Python 2.7` in parallel to default 2.6 (needed for `make check` to run unittests). -Make sure you've install EPEL (`epel-release` as above). Then install current -`python2.7` and `pytest` +Pick correct EPEL based on CentOS version used. Then install current `pytest` - rpm -ivh https://centos6.iuscommunity.org/ius-release.rpm - yum install python27 python27-devel python27-pip - pip2.7 install pytest + sudo rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm + sudo rpm -ivh https://centos6.iuscommunity.org/ius-release.rpm + sudo yum install python27 python27-pip + sudo pip2.7 install pytest Please note that `CentOS 6` needs to keep python pointing to version 2.6 for `yum` to keep working, so don't create a symlink for python2.7 to python @@ -75,17 +81,18 @@ any packages** (You may prefer different options on configure statement. These are just an example.) -You may want to pay special attention to `/usr/lib64` paths and change -them if you are not building on a x86_64 architecture - git clone https://github.com/frrouting/frr.git frr cd frr + git checkout stable/3.0 ./bootstrap.sh ./configure \ + --bindir=/usr/bin \ + --sbindir=/usr/lib/frr \ --sysconfdir=/etc/frr \ - --libdir=/usr/lib64/frr \ - --libexecdir=/usr/lib64/frr \ + --libdir=/usr/lib/frr \ + --libexecdir=/usr/lib/frr \ --localstatedir=/var/run/frr \ + --with-moduledir=/usr/lib/frr/modules \ --disable-pimd \ --enable-snmp=agentx \ --enable-multipath=64 \ @@ -98,9 +105,11 @@ them if you are not building on a x86_64 architecture --disable-exampledir \ --enable-watchfrr \ --enable-tcp-zebra \ + --disable-ldpd \ --enable-fpm \ + --enable-nhrpd \ --with-pkg-git-version \ - --with-pkg-extra-version=-MyOwnFRRVersion + --with-pkg-extra-version=-MyOwnFRRVersion make make check PYTHON=/usr/bin/python2.7 sudo make install @@ -115,11 +124,21 @@ them if you are not building on a x86_64 architecture sudo touch /etc/frr/isisd.conf sudo touch /etc/frr/ripd.conf sudo touch /etc/frr/ripngd.conf + sudo touch /etc/frr/nhrpd.conf sudo chown -R frr:frr /etc/frr/ sudo touch /etc/frr/vtysh.conf sudo chown frr:frrvt /etc/frr/vtysh.conf sudo chmod 640 /etc/frr/*.conf +### Install daemon config file + sudo install -p -m 644 redhat/daemons /etc/frr/ + sudo chown frr:frr /etc/frr/daemons + +### Edit /etc/frr/daemons as needed to select the required daemons + +Look for the section with `watchfrr_enable=...` and `zebra=...` etc. +Enable the daemons as required by changing the value to `yes` + ### Enable IP & IPv6 forwarding Edit `/etc/sysctl.conf` and set the following values (ignore the other @@ -132,28 +151,16 @@ settings) # Controls source route verification net.ipv4.conf.default.rp_filter = 0 -**Reboot** or use `sysctl` to apply the same config to the running system +Load the modifed sysctl's on the system: + + sudo sysctl -p /etc/sysctl.d/90-routing-sysctl.conf ### Add init.d startup files - sudo cp redhat/bgpd.init /etc/init.d/bgpd - sudo cp redhat/isisd.init /etc/init.d/isisd - sudo cp redhat/ospfd.init /etc/init.d/ospfd - sudo cp redhat/ospf6d.init /etc/init.d/ospf6d - sudo cp redhat/ripngd.init /etc/init.d/ripngd - sudo cp redhat/ripd.init /etc/init.d/ripd - sudo cp redhat/zebra.init /etc/init.d/zebra - sudo chkconfig --add zebra - sudo chkconfig --add ripd - sudo chkconfig --add ripngd - sudo chkconfig --add ospf6d - sudo chkconfig --add ospfd - sudo chkconfig --add bgpd - sudo chkconfig --add isisd + sudo install -p -m 755 redhat/frr.init /etc/init.d/frr + sudo chkconfig --add frr -### Enable required daemons at startup -Only enable zebra and the daemons which are needed for your setup +### Enable frr daemon at startup + sudo chkconfig frr on - sudo chkconfig zebra on - sudo chkconfig ospfd on - sudo chkconfig bgpd on - [...] etc (as needed) +### Start FRR manually (or reboot) + sudo /etc/init.d/frr start diff --git a/doc/Building_FRR_on_CentOS7.md b/doc/Building_FRR_on_CentOS7.md index 0ab5c0ff54..653efc6e60 100644 --- a/doc/Building_FRR_on_CentOS7.md +++ b/doc/Building_FRR_on_CentOS7.md @@ -1,6 +1,10 @@ Building FRR on CentOS 7 from Git Source ======================================== +(As an alternative to this installation, you may prefer to create a FRR +rpm package yourself and install that package instead. See instructions +in redhat/README.rpm_build.md on how to build a rpm package) + CentOS 7 restrictions: ---------------------- @@ -13,13 +17,10 @@ Install required packages Add packages: - sudo yum install git autoconf automake libtool make gawk readline-devel \ - texinfo net-snmp-devel groff pkgconfig json-c-devel pam-devel \ - bison flex pytest c-ares-devel python-devel rpm-build - -To build from git (in difference to building from distribution tar.gz as created by `make dist`), the python development libraries are needed. (Make sure you've installed EPEL libraries as shown above for this to work) - - yum install python34-devel + sudo yum install git autoconf automake libtool make gawk \ + readline-devel texinfo net-snmp-devel groff pkgconfig \ + json-c-devel pam-devel bison flex pytest c-ares-devel \ + perl-XML-LibXML Get FRR, compile it and install it (from Git) --------------------------------------------- @@ -38,17 +39,19 @@ any packages** (You may prefer different options on configure statement. These are just an example.) -You may want to pay special attention to `/usr/lib64` paths and change -them if you are not building on a x86_64 architecture - git clone https://github.com/frrouting/frr.git frr cd frr + git checkout stable/3.0 ./bootstrap.sh ./configure \ + --bindir=/usr/bin \ + --sbindir=/usr/lib/frr \ --sysconfdir=/etc/frr \ - --libdir=/usr/lib64/frr \ - --libexecdir=/usr/lib64/frr \ + --libdir=/usr/lib/frr \ + --libexecdir=/usr/lib/frr \ --localstatedir=/var/run/frr \ + --with-moduledir=/usr/lib/frr/modules \ + --enable-pimd \ --enable-snmp=agentx \ --enable-multipath=64 \ --enable-ospfclient=yes \ @@ -60,9 +63,11 @@ them if you are not building on a x86_64 architecture --disable-exampledir \ --enable-watchfrr \ --enable-tcp-zebra \ + --disable-ldpd \ --enable-fpm \ + --enable-nhrpd \ --with-pkg-git-version \ - --with-pkg-extra-version=-MyOwnFRRVersion + --with-pkg-extra-version=-MyOwnFRRVersion make make check sudo make install @@ -78,11 +83,21 @@ them if you are not building on a x86_64 architecture sudo touch /etc/frr/ripd.conf sudo touch /etc/frr/ripngd.conf sudo touch /etc/frr/pimd.conf + sudo touch /etc/frr/nhrpd.conf sudo chown -R frr:frr /etc/frr/ sudo touch /etc/frr/vtysh.conf sudo chown frr:frrvt /etc/frr/vtysh.conf sudo chmod 640 /etc/frr/*.conf +### Install daemon config file + sudo install -p -m 644 redhat/daemons /etc/frr/ + sudo chown frr:frr /etc/frr/daemons + +### Edit /etc/frr/daemons as needed to select the required daemons + +Look for the section with `watchfrr_enable=...` and `zebra=...` etc. +Enable the daemons as required by changing the value to `yes` + ### Enable IP & IPv6 forwarding Create a new file `/etc/sysctl.d/90-routing-sysctl.conf` with the @@ -94,33 +109,19 @@ following content: net.ipv4.conf.all.forwarding=1 net.ipv6.conf.all.forwarding=1 -**Reboot** or use `sysctl` to apply the same config to the running system +Load the modifed sysctl's on the system: -### Install Service files - sudo install -p -m 644 redhat/zebra.service /usr/lib/systemd/system/zebra.service - sudo install -p -m 644 redhat/isisd.service /usr/lib/systemd/system/isisd.service - sudo install -p -m 644 redhat/ripd.service /usr/lib/systemd/system/ripd.service - sudo install -p -m 644 redhat/ospfd.service /usr/lib/systemd/system/ospfd.service - sudo install -p -m 644 redhat/bgpd.service /usr/lib/systemd/system/bgpd.service - sudo install -p -m 644 redhat/ospf6d.service /usr/lib/systemd/system/ospf6d.service - sudo install -p -m 644 redhat/ripngd.service /usr/lib/systemd/system/ripngd.service - sudo install -p -m 644 redhat/pimd.service /usr/lib/systemd/system/pimd.service - sudo install -p -m 644 redhat/frr.sysconfig /etc/sysconfig/frr - sudo install -p -m 644 redhat/frr.logrotate /etc/logrotate.d/frr + sudo sysctl -p /etc/sysctl.d/90-routing-sysctl.conf + +### Install frr Service and redhat init files + sudo install -p -m 644 redhat/frr.service /usr/lib/systemd/system/frr.service + sudo install -p -m 755 redhat/frr.init /usr/lib/frr/frr ### Register the systemd files - sudo systemctl preset zebra.service - sudo systemctl preset ripd.service - sudo systemctl preset ospfd.service - sudo systemctl preset bgpd.service - sudo systemctl preset ospf6d.service - sudo systemctl preset ripngd.service - sudo systemctl preset pimd.service + sudo systemctl preset frr.service + +### Enable required frr at startup + sudo systemctl enable frr -### Enable required daemons at startup -Only enable zebra and the daemons which are needed for your setup - - sudo systemctl enable zebra - sudo systemctl enable ospfd - sudo systemctl enable bgpd - [...] etc (as needed) +### Reboot or start FRR manually + sudo systemctl start frr diff --git a/doc/Building_FRR_on_Fedora24.md b/doc/Building_FRR_on_Fedora24.md index 1f5f12b9cc..4e2647c62b 100644 --- a/doc/Building_FRR_on_Fedora24.md +++ b/doc/Building_FRR_on_Fedora24.md @@ -1,15 +1,19 @@ Building FRR on Fedora 24 from Git Source ========================================= +(As an alternative to this installation, you may prefer to create a FRR +rpm package yourself and install that package instead. See instructions +in redhat/README.rpm_build.md on how to build a rpm package) + Install required packages ------------------------- Add packages: sudo dnf install git autoconf automake libtool make gawk \ - readline-devel texinfo net-snmp-devel groff pkgconfig \ - json-c-devel pam-devel perl-XML-LibXML c-ares-devel \ - python3-devel + readline-devel texinfo net-snmp-devel groff pkgconfig \ + json-c-devel pam-devel bison flex pytest perl-XML-LibXML \ + c-ares-devel Get FRR, compile it and install it (from Git) --------------------------------------------- @@ -28,17 +32,18 @@ using any packages** (You may prefer different options on configure statement. These are just an example.) -You may want to pay special attention to `/usr/lib64` paths and change -them if you are not building on a x86_64 architecture - git clone https://github.com/frrouting/frr.git frr cd frr + git checkout stable/3.0 ./bootstrap.sh ./configure \ + --bindir=/usr/bin \ + --sbindir=/usr/lib/frr \ --sysconfdir=/etc/frr \ - --libdir=/usr/lib64/frr \ - --libexecdir=/usr/lib64/frr \ + --libdir=/usr/lib/frr \ + --libexecdir=/usr/lib/frr \ --localstatedir=/var/run/frr \ + --with-moduledir=/usr/lib/frr/modules \ --enable-pimd \ --enable-snmp=agentx \ --enable-multipath=64 \ @@ -51,9 +56,11 @@ them if you are not building on a x86_64 architecture --disable-exampledir \ --enable-watchfrr \ --enable-tcp-zebra \ + --enable-ldpd \ --enable-fpm \ + --enable-nhrpd \ --with-pkg-git-version \ - --with-pkg-extra-version=-MyOwnFRRVersion + --with-pkg-extra-version=-MyOwnFRRVersion make make check sudo make install @@ -76,6 +83,15 @@ them if you are not building on a x86_64 architecture sudo chown frr:frrvt /etc/frr/vtysh.conf sudo chmod 640 /etc/frr/*.conf +### Install daemon config file + sudo install -p -m 644 redhat/daemons /etc/frr/ + sudo chown frr:frr /etc/frr/daemons + +### Edit /etc/frr/daemons as needed to select the required daemons + +Look for the section with `watchfrr_enable=...` and `zebra=...` etc. +Enable the daemons as required by changing the value to `yes` + ### Enable IP & IPv6 forwarding (and MPLS) Create a new file `/etc/sysctl.d/90-routing-sysctl.conf` with the @@ -95,41 +111,26 @@ to `net.mpls.conf.eth0.input=1`) net.mpls.conf.eth2.input=1 net.mpls.platform_labels=100000 +Load the modifed sysctl's on the system: + + sudo sysctl -p /etc/sysctl.d/90-routing-sysctl.conf + Create a new file `/etc/modules-load.d/mpls.conf` with the following content: # Load MPLS Kernel Modules mpls-router mpls-iptunnel -**Reboot** or use `sysctl` to apply the same config to the running system +And load the kernel modules on the running system: -### Install Service files - install -p -m 644 redhat/zebra.service /usr/lib/systemd/system/zebra.service - install -p -m 644 redhat/isisd.service /usr/lib/systemd/system/isisd.service - install -p -m 644 redhat/ripd.service /usr/lib/systemd/system/ripd.service - install -p -m 644 redhat/ospfd.service /usr/lib/systemd/system/ospfd.service - install -p -m 644 redhat/bgpd.service /usr/lib/systemd/system/bgpd.service - install -p -m 644 redhat/ospf6d.service /usr/lib/systemd/system/ospf6d.service - install -p -m 644 redhat/ripngd.service /usr/lib/systemd/system/ripngd.service - install -p -m 644 redhat/pimd.service /usr/lib/systemd/system/pimd.service - install -p -m 644 redhat/ldpd.service /usr/lib/systemd/system/ldpd.service - install -p -m 644 redhat/frr.sysconfig /etc/sysconfig/frr - install -p -m 644 redhat/frr.logrotate /etc/logrotate.d/frr + sudo modprobe mpls-router mpls-iptunnel -### Register the systemd files - systemctl preset zebra.service - systemctl preset ripd.service - systemctl preset ospfd.service - systemctl preset bgpd.service - systemctl preset ospf6d.service - systemctl preset ripngd.service - systemctl preset pimd.service - systemctl preset ldpd.service +### Install frr Service and redhat init files + sudo install -p -m 644 redhat/frr.service /usr/lib/systemd/system/frr.service + sudo install -p -m 755 redhat/frr.init /usr/lib/frr/frr + +### Enable required frr at startup + sudo systemctl enable frr -### Enable required daemons at startup -Only enable zebra and the daemons which are needed for your setup - - systemctl enable zebra - systemctl enable ospfd - systemctl enable bgpd - [...] etc (as needed) +### Reboot or start FRR manually + sudo systemctl start frr From 69f93be55a9146ba58e814964a77961cdba13bf9 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Mon, 24 Jul 2017 18:57:20 -0300 Subject: [PATCH 5/9] ldpd: fix bug with dual-stack neighbors We were assuming that a neighbor can be deleted only when all of its adjacencies are dead. This is not the case for dual-stack neighbors. If the transport-preference is IPv4 and all adjacencies are IPv6 (or vice-versa), then it should be deleted and everything cleaned-up accordingly. Bug exposed by the new RB tree implementation on master, but the fix also applies to stable/3.0. Signed-off-by: Renato Westphal --- ldpd/neighbor.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ldpd/neighbor.c b/ldpd/neighbor.c index 9a92a00d32..7cd3a3fd7d 100644 --- a/ldpd/neighbor.c +++ b/ldpd/neighbor.c @@ -287,6 +287,8 @@ nbr_new(struct in_addr id, int af, int ds_tlv, union ldpd_addr *addr, void nbr_del(struct nbr *nbr) { + struct adj *adj; + log_debug("%s: lsr-id %s", __func__, inet_ntoa(nbr->id)); nbr_fsm(nbr, NBR_EVT_CLOSE_SESSION); @@ -312,6 +314,11 @@ nbr_del(struct nbr *nbr) mapping_list_clr(&nbr->release_list); mapping_list_clr(&nbr->abortreq_list); + while ((adj = RB_ROOT(&nbr->adj_tree)) != NULL) { + adj->nbr = NULL; + RB_REMOVE(nbr_adj_head, &nbr->adj_tree, adj); + } + if (nbr->peerid) RB_REMOVE(nbr_pid_head, &nbrs_by_pid, nbr); RB_REMOVE(nbr_id_head, &nbrs_by_id, nbr); From f766e29c4b208e9e674cb2fa6d8b962c659dc2ad Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Fri, 21 Jul 2017 15:09:58 -0300 Subject: [PATCH 6/9] zebra: fetch interface speed on *BSD Fixes #407 for FreeBSD and NetBSD. OpenBSD uses ioctl to fetch interface information on startup and the SIOCGIFMEDIA command is just too cumbersome to use. The best way to fix the problem for OpenBSD is probably to stop treating it differently from the other BSDs for no apparent reason. There should be nothing preventing us to make OpenBSD use the routing socket to fetch interface information on startup (we already do it to detect runtime changes). This is something that should be done in a separate commit after a careful analysis. Signed-off-by: Renato Westphal --- zebra/kernel_socket.c | 1 + 1 file changed, 1 insertion(+) diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index eeccd1f175..70effade27 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -628,6 +628,7 @@ ifm_read (struct if_msghdr *ifm) #ifdef HAVE_NET_RT_IFLIST ifp->stats = ifm->ifm_data; #endif /* HAVE_NET_RT_IFLIST */ + ifp->speed = ifm->ifm_data.ifi_baudrate / 1000000; if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug ("%s: interface %s index %d", From 59f851e91d7f777ccb401aa6620cfa4040569cb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Fingen?= Date: Tue, 1 Aug 2017 11:34:15 +0200 Subject: [PATCH 7/9] ospf6: Fix DEBUG compiling error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit struct ospf6_lsa doesn't have next nor prev, so it was raising a compiling error if DEBUG is set. Signed-off-by: ßingen --- ospf6d/ospf6_lsdb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ospf6d/ospf6_lsdb.c b/ospf6d/ospf6_lsdb.c index 1d4b557cd5..55f3db89d9 100644 --- a/ospf6d/ospf6_lsdb.c +++ b/ospf6d/ospf6_lsdb.c @@ -92,8 +92,7 @@ _lsdb_count_assert (struct ospf6_lsdb *lsdb) lsdb, lsdb->count, num); for (debug = ospf6_lsdb_head (lsdb); debug; debug = ospf6_lsdb_next (debug)) - zlog_debug ("%p %p %s lsdb[%p]", debug->prev, debug->next, debug->name, - debug->lsdb); + zlog_debug ("%s lsdb[%p]", debug->name, debug->lsdb); zlog_debug ("DUMP END"); assert (num == lsdb->count); From c222aa61d685d483ac21245d51a0ed013897517a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Fingen?= Date: Tue, 1 Aug 2017 11:38:19 +0200 Subject: [PATCH 8/9] ospf: Fix segfault if compiled with DEBUG MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If OSPF_LS_REFRESH_TIME is 60, min_delay in ospf_refresher_register_lsa function (ospf_lsa.c) would be negative, so index (which is unsigned) would be out of range, causing a segfault. Signed-off-by: ßingen --- lib/libospf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libospf.h b/lib/libospf.h index a1ff9c24a2..ec6e642f89 100644 --- a/lib/libospf.h +++ b/lib/libospf.h @@ -35,7 +35,7 @@ /* Architectual Constants */ #ifdef DEBUG -#define OSPF_LS_REFRESH_TIME 60 +#define OSPF_LS_REFRESH_TIME 120 #else #define OSPF_LS_REFRESH_TIME 1800 #endif From 650c7ae1646150fd679ae7b34730bb0cdd5fa49b Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Fri, 4 Aug 2017 12:05:38 +0200 Subject: [PATCH 9/9] lib: vty: fix config-write fd leak Since we were only setting vty->wfd in config_write, vty->fd would remain 0 and vty_close() wouldn't close vty->wfd. Clean up the entire fd closing and make it more explicit. We were even trying to write to stdin... [master commit: 10b8a9c] Reported-by: Jorge Boncompte Signed-off-by: David Lamparter --- lib/vty.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/lib/vty.c b/lib/vty.c index e7e0f17e67..ffde21db93 100644 --- a/lib/vty.c +++ b/lib/vty.c @@ -322,6 +322,7 @@ vty_new () { struct vty *new = XCALLOC (MTYPE_VTY, sizeof (struct vty)); + new->fd = new->wfd = -1; new->obuf = buffer_new(0); /* Use default buffer size. */ new->buf = XCALLOC (MTYPE_VTY, VTY_BUFSIZ); new->error_buf = XCALLOC (MTYPE_VTY, VTY_BUFSIZ); @@ -2248,18 +2249,22 @@ vty_close (struct vty *vty) XFREE (MTYPE_VTY_HIST, vty->hist[i]); /* Unset vector. */ - vector_unset (vtyvec, vty->fd); + if (vty->fd != -1) + vector_unset(vtyvec, vty->fd); if (vty->wfd > 0 && vty->type == VTY_FILE) fsync (vty->wfd); - /* Close socket. */ - if (vty->fd > 0) - { - close (vty->fd); - if (vty->wfd > 0 && vty->wfd != vty->fd) - close (vty->wfd); - } + /* Close socket. + * note check is for fd > STDERR_FILENO, not fd != -1. + * We never close stdin/stdout/stderr here, because we may be + * running in foreground mode with logging to stdout. Also, + * additionally, we'd need to replace these fds with /dev/null. */ + if (vty->wfd > STDERR_FILENO && vty->wfd != vty->fd) + close(vty->wfd); + + if (vty->fd > STDERR_FILENO) + close(vty->fd); else was_stdio = true; @@ -2309,13 +2314,14 @@ vty_read_file (FILE *confp) unsigned int line_num = 0; vty = vty_new (); - vty->wfd = dup(STDERR_FILENO); /* vty_close() will close this */ - if (vty->wfd < 0) - { - /* Fine, we couldn't make a new fd. vty_close doesn't close stdout. */ - vty->wfd = STDOUT_FILENO; - } - vty->fd = STDIN_FILENO; + /* vty_close won't close stderr; if some config command prints + * something it'll end up there. (not ideal; it'd be beter if output + * from a file-load went to logging instead. Also note that if this + * function is called after daemonizing, stderr will be /dev/null.) + * + * vty->fd will be -1 from vty_new() + */ + vty->wfd = STDERR_FILENO; vty->type = VTY_FILE; vty->node = CONFIG_NODE; @@ -2323,7 +2329,7 @@ vty_read_file (FILE *confp) ret = config_from_file (vty, confp, &line_num); /* Flush any previous errors before printing messages below */ - buffer_flush_all (vty->obuf, vty->fd); + buffer_flush_all (vty->obuf, vty->wfd); if ( !((ret == CMD_SUCCESS) || (ret == CMD_ERR_NOTHING_TODO)) ) {