diff options
343 files changed, 8802 insertions, 4316 deletions
diff --git a/.gitignore b/.gitignore index 226dca09d0..8c61aeb9c5 100644 --- a/.gitignore +++ b/.gitignore @@ -56,6 +56,12 @@ *.pb.cc *_clippy.c +### gcov outputs + +*.gcno +*.gcov +*.gcda + ### dist *.tar.?z @@ -96,3 +102,4 @@ compile_commands.json .dirstamp refix .vscode +.kitchen diff --git a/babeld/babeld.c b/babeld/babeld.c index 83a2a3137c..a7a3481998 100644 --- a/babeld/babeld.c +++ b/babeld/babeld.c @@ -138,7 +138,7 @@ babel_create_routing_process (void) assert (babel_routing_process == NULL); /* Allocaste Babel instance. */ - babel_routing_process = XCALLOC (MTYPE_BABEL, sizeof (struct babel)); + babel_routing_process = XCALLOC(MTYPE_BABEL, sizeof(struct babel)); /* Initialize timeouts */ gettime(&babel_now); diff --git a/babeld/util.h b/babeld/util.h index 00a025ff93..9310040571 100644 --- a/babeld/util.h +++ b/babeld/util.h @@ -122,7 +122,7 @@ void uchar_to_inaddr(struct in_addr *dest, const unsigned char *src); void in6addr_to_uchar(unsigned char *dest, const struct in6_addr *src); void uchar_to_in6addr(struct in6_addr *dest, const unsigned char *src); int daemonise(void); -const unsigned char v4prefix[16]; +extern const unsigned char v4prefix[16]; /* If debugging is disabled, we want to avoid calling format_address for every omitted debugging message. So debug is a macro. But diff --git a/bfdd/bfdd_nb_config.c b/bfdd/bfdd_nb_config.c index 50f953115c..48dcce3ddf 100644 --- a/bfdd/bfdd_nb_config.c +++ b/bfdd/bfdd_nb_config.c @@ -383,7 +383,7 @@ int bfdd_bfd_sessions_single_hop_administrative_down_modify( bs = nb_running_get_entry(dnode, NULL, true); - if (shutdown == false) { + if (!shutdown) { if (!BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN)) return NB_OK; @@ -447,7 +447,7 @@ int bfdd_bfd_sessions_single_hop_echo_mode_modify(enum nb_event event, bs = nb_running_get_entry(dnode, NULL, true); - if (echo == false) { + if (!echo) { if (!BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO)) return NB_OK; diff --git a/bfdd/bfdd_vty.c b/bfdd/bfdd_vty.c index e6307f78a4..2a98b0fb02 100644 --- a/bfdd/bfdd_vty.c +++ b/bfdd/bfdd_vty.c @@ -474,7 +474,7 @@ static void _display_peer_brief(struct vty *vty, struct bfd_session *bs) } } -static void _display_peer_brief_iter(struct hash_backet *hb, void *arg) +static void _display_peer_brief_iter(struct hash_bucket *hb, void *arg) { struct bfd_vrf_tuple *bvt = arg; struct vty *vty; @@ -500,7 +500,7 @@ static void _display_peers_brief(struct vty *vty, const char *vrfname, bool use_ bvt.vrfname = vrfname; - if (use_json == false) { + if (!use_json) { bvt.vty = vty; vty_out(vty, "Session count: %lu\n", bfd_get_session_count()); diff --git a/bgpd/bgp_aspath.c b/bgpd/bgp_aspath.c index a781e70d2f..44962f5af3 100644 --- a/bgpd/bgp_aspath.c +++ b/bgpd/bgp_aspath.c @@ -41,9 +41,9 @@ #define AS_HEADER_SIZE 2 /* Now FOUR octets are used for AS value. */ -#define AS_VALUE_SIZE sizeof (as_t) +#define AS_VALUE_SIZE sizeof(as_t) /* This is the old one */ -#define AS16_VALUE_SIZE sizeof (as16_t) +#define AS16_VALUE_SIZE sizeof(as16_t) /* Maximum protocol segment length value */ #define AS_SEGMENT_MAX 255 @@ -132,8 +132,7 @@ static void assegment_free(struct assegment *seg) if (!seg) return; - if (seg->as) - assegment_data_free(seg->as); + assegment_data_free(seg->as); memset(seg, 0xfe, sizeof(struct assegment)); XFREE(MTYPE_AS_SEG, seg); @@ -429,6 +428,22 @@ bool aspath_check_as_sets(struct aspath *aspath) return false; } +/* Check if aspath has BGP_AS_ZERO */ +bool aspath_check_as_zero(struct aspath *aspath) +{ + struct assegment *seg = aspath->segments; + unsigned int i; + + while (seg) { + for (i = 0; i < seg->length; i++) + if (seg->as[i] == BGP_AS_ZERO) + return true; + seg = seg->next; + } + + return false; +} + /* Estimate size aspath /might/ take if encoded into an * ASPATH attribute. * @@ -477,7 +492,7 @@ as_t aspath_leftmost(struct aspath *aspath) } /* Return 1 if there are any 4-byte ASes in the path */ -unsigned int aspath_has_as4(struct aspath *aspath) +bool aspath_has_as4(struct aspath *aspath) { struct assegment *seg = aspath->segments; unsigned int i; @@ -485,10 +500,10 @@ unsigned int aspath_has_as4(struct aspath *aspath) while (seg) { for (i = 0; i < seg->length; i++) if (seg->as[i] > BGP_AS_MAX) - return 1; + return true; seg = seg->next; } - return 0; + return false; } /* Convert aspath structure to string expression. */ @@ -768,7 +783,7 @@ static int assegments_parse(struct stream *s, size_t length, * on more, than 8 bits (otherwise it's a warning, bug * #564). */ - || ((sizeof segh.length > 1) + || ((sizeof(segh.length) > 1) && (0x10 + segh.length > 0x10 + AS_SEGMENT_MAX))) { if (head) assegment_free_all(head); @@ -793,7 +808,7 @@ static int assegments_parse(struct stream *s, size_t length, if (head) prev->next = seg; else /* it's the first segment */ - head = prev = seg; + head = seg; for (i = 0; i < segh.length; i++) seg->as[i] = @@ -1114,16 +1129,16 @@ struct aspath *aspath_aggregate(struct aspath *as1, struct aspath *as2) /* When a BGP router receives an UPDATE with an MP_REACH_NLRI attribute, check the leftmost AS number in the AS_PATH attribute is or not the peer's AS number. */ -int aspath_firstas_check(struct aspath *aspath, as_t asno) +bool aspath_firstas_check(struct aspath *aspath, as_t asno) { if ((aspath == NULL) || (aspath->segments == NULL)) - return 0; + return false; if (aspath->segments && (aspath->segments->type == AS_SEQUENCE) && (aspath->segments->as[0] == asno)) - return 1; + return true; - return 0; + return false; } unsigned int aspath_get_first_as(struct aspath *aspath) @@ -1179,12 +1194,12 @@ int aspath_loop_check(struct aspath *aspath, as_t asno) } /* When all of AS path is private AS return 1. */ -int aspath_private_as_check(struct aspath *aspath) +bool aspath_private_as_check(struct aspath *aspath) { struct assegment *seg; if (!(aspath && aspath->segments)) - return 0; + return false; seg = aspath->segments; @@ -1193,20 +1208,20 @@ int aspath_private_as_check(struct aspath *aspath) for (i = 0; i < seg->length; i++) { if (!BGP_AS_IS_PRIVATE(seg->as[i])) - return 0; + return false; } seg = seg->next; } - return 1; + return true; } /* Return True if the entire ASPATH consist of the specified ASN */ -int aspath_single_asn_check(struct aspath *aspath, as_t asn) +bool aspath_single_asn_check(struct aspath *aspath, as_t asn) { struct assegment *seg; if (!(aspath && aspath->segments)) - return 0; + return false; seg = aspath->segments; @@ -1215,11 +1230,11 @@ int aspath_single_asn_check(struct aspath *aspath, as_t asn) for (i = 0; i < seg->length; i++) { if (seg->as[i] != asn) - return 0; + return false; } seg = seg->next; } - return 1; + return true; } /* Replace all instances of the target ASN with our own ASN */ @@ -1338,37 +1353,37 @@ struct aspath *aspath_remove_private_asns(struct aspath *aspath, as_t peer_asn) /* AS path confed check. If aspath contains confed set or sequence then return * 1. */ -int aspath_confed_check(struct aspath *aspath) +bool aspath_confed_check(struct aspath *aspath) { struct assegment *seg; if (!(aspath && aspath->segments)) - return 0; + return false; seg = aspath->segments; while (seg) { if (seg->type == AS_CONFED_SET || seg->type == AS_CONFED_SEQUENCE) - return 1; + return true; seg = seg->next; } - return 0; + return false; } /* Leftmost AS path segment confed check. If leftmost AS segment is of type AS_CONFED_SEQUENCE or AS_CONFED_SET then return 1. */ -int aspath_left_confed_check(struct aspath *aspath) +bool aspath_left_confed_check(struct aspath *aspath) { if (!(aspath && aspath->segments)) - return 0; + return false; if ((aspath->segments->type == AS_CONFED_SEQUENCE) || (aspath->segments->type == AS_CONFED_SET)) - return 1; + return true; - return 0; + return false; } /* Merge as1 to as2. as2 should be uninterned aspath. */ @@ -1605,13 +1620,13 @@ struct aspath *aspath_add_seq(struct aspath *aspath, as_t asno) /* Compare leftmost AS value for MED check. If as1's leftmost AS and as2's leftmost AS is same return 1. */ -int aspath_cmp_left(const struct aspath *aspath1, const struct aspath *aspath2) +bool aspath_cmp_left(const struct aspath *aspath1, const struct aspath *aspath2) { const struct assegment *seg1; const struct assegment *seg2; if (!(aspath1 && aspath2)) - return 0; + return false; seg1 = aspath1->segments; seg2 = aspath2->segments; @@ -1619,7 +1634,7 @@ int aspath_cmp_left(const struct aspath *aspath1, const struct aspath *aspath2) /* If both paths are originated in this AS then we do want to compare * MED */ if (!seg1 && !seg2) - return 1; + return true; /* find first non-confed segments for each */ while (seg1 && ((seg1->type == AS_CONFED_SEQUENCE) @@ -1633,12 +1648,12 @@ int aspath_cmp_left(const struct aspath *aspath1, const struct aspath *aspath2) /* Check as1's */ if (!(seg1 && seg2 && (seg1->type == AS_SEQUENCE) && (seg2->type == AS_SEQUENCE))) - return 0; + return false; if (seg1->as[0] == seg2->as[0]) - return 1; + return true; - return 0; + return false; } /* Truncate an aspath after a number of hops, and put the hops remaining @@ -2127,7 +2142,7 @@ static void *bgp_aggr_aspath_hash_alloc(void *p) return aspath; } -static void bgp_aggr_aspath_prepare(struct hash_backet *hb, void *arg) +static void bgp_aggr_aspath_prepare(struct hash_bucket *hb, void *arg) { struct aspath *hb_aspath = hb->data; struct aspath **aggr_aspath = arg; diff --git a/bgpd/bgp_aspath.h b/bgpd/bgp_aspath.h index a4427714ba..9df352fcd6 100644 --- a/bgpd/bgp_aspath.h +++ b/bgpd/bgp_aspath.h @@ -39,6 +39,7 @@ #define BGP_PRIVATE_AS4_MAX 4294967294U /* we leave BGP_AS_MAX as the 16bit AS MAX number. */ +#define BGP_AS_ZERO 0 #define BGP_AS_MAX 65535U #define BGP_AS4_MAX 4294967295U /* Transition 16Bit AS as defined by IANA */ @@ -87,7 +88,7 @@ extern struct aspath *aspath_add_seq_n(struct aspath *, as_t, unsigned); extern struct aspath *aspath_add_seq(struct aspath *, as_t); extern struct aspath *aspath_add_confed_seq(struct aspath *, as_t); extern bool aspath_cmp(const void *as1, const void *as2); -extern int aspath_cmp_left(const struct aspath *, const struct aspath *); +extern bool aspath_cmp_left(const struct aspath *, const struct aspath *); extern bool aspath_cmp_left_confed(const struct aspath *as1, const struct aspath *as2xs); extern struct aspath *aspath_delete_confed_seq(struct aspath *); @@ -106,8 +107,8 @@ extern unsigned int aspath_key_make(const void *); extern unsigned int aspath_get_first_as(struct aspath *); extern unsigned int aspath_get_last_as(struct aspath *); extern int aspath_loop_check(struct aspath *, as_t); -extern int aspath_private_as_check(struct aspath *); -extern int aspath_single_asn_check(struct aspath *, as_t asn); +extern bool aspath_private_as_check(struct aspath *); +extern bool aspath_single_asn_check(struct aspath *, as_t asn); extern struct aspath *aspath_replace_specific_asn(struct aspath *aspath, as_t target_asn, as_t our_asn); @@ -115,12 +116,13 @@ extern struct aspath *aspath_replace_private_asns(struct aspath *aspath, as_t asn, as_t peer_asn); extern struct aspath *aspath_remove_private_asns(struct aspath *aspath, as_t peer_asn); -extern int aspath_firstas_check(struct aspath *, as_t); -extern int aspath_confed_check(struct aspath *); -extern int aspath_left_confed_check(struct aspath *); +extern bool aspath_firstas_check(struct aspath *, as_t); +extern bool aspath_confed_check(struct aspath *); +extern bool aspath_left_confed_check(struct aspath *); extern unsigned long aspath_count(void); extern unsigned int aspath_count_hops(const struct aspath *); extern bool aspath_check_as_sets(struct aspath *aspath); +extern bool aspath_check_as_zero(struct aspath *aspath); extern unsigned int aspath_count_confeds(struct aspath *); extern unsigned int aspath_size(struct aspath *); extern as_t aspath_highest(struct aspath *); @@ -128,7 +130,7 @@ extern as_t aspath_leftmost(struct aspath *); extern size_t aspath_put(struct stream *, struct aspath *, int); extern struct aspath *aspath_reconcile_as4(struct aspath *, struct aspath *); -extern unsigned int aspath_has_as4(struct aspath *); +extern bool aspath_has_as4(struct aspath *); /* For SNMP BGP4PATHATTRASPATHSEGMENT, might be useful for debug */ extern uint8_t *aspath_snmp_pathseg(struct aspath *, size_t *); diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index f00bb2b3cd..7c15fd3711 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -47,7 +47,7 @@ #include "bgpd/bgp_lcommunity.h" #include "bgpd/bgp_updgrp.h" #include "bgpd/bgp_encap_types.h" -#if ENABLE_BGP_VNC +#ifdef ENABLE_BGP_VNC #include "bgpd/rfapi/bgp_rfapi_cfg.h" #include "bgp_encap_types.h" #include "bgp_vnc_types.h" @@ -79,7 +79,7 @@ static const struct message attr_str[] = { {BGP_ATTR_AS_PATHLIMIT, "AS_PATHLIMIT"}, {BGP_ATTR_PMSI_TUNNEL, "PMSI_TUNNEL_ATTRIBUTE"}, {BGP_ATTR_ENCAP, "ENCAP"}, -#if ENABLE_BGP_VNC_ATTR +#ifdef ENABLE_BGP_VNC_ATTR {BGP_ATTR_VNC, "VNC"}, #endif {BGP_ATTR_LARGE_COMMUNITIES, "LARGE_COMMUNITY"}, @@ -199,7 +199,7 @@ static void cluster_finish(void) } static struct hash *encap_hash = NULL; -#if ENABLE_BGP_VNC +#ifdef ENABLE_BGP_VNC static struct hash *vnc_hash = NULL; #endif static struct hash *srv6_l3vpn_hash; @@ -247,7 +247,7 @@ void bgp_attr_flush_encap(struct attr *attr) encap_free(attr->encap_subtlvs); attr->encap_subtlvs = NULL; } -#if ENABLE_BGP_VNC +#ifdef ENABLE_BGP_VNC if (attr->vnc_subtlvs) { encap_free(attr->vnc_subtlvs); attr->vnc_subtlvs = NULL; @@ -309,7 +309,7 @@ static void *encap_hash_alloc(void *p) typedef enum { ENCAP_SUBTLV_TYPE, -#if ENABLE_BGP_VNC +#ifdef ENABLE_BGP_VNC VNC_SUBTLV_TYPE #endif } encap_subtlv_type; @@ -319,7 +319,7 @@ encap_intern(struct bgp_attr_encap_subtlv *encap, encap_subtlv_type type) { struct bgp_attr_encap_subtlv *find; struct hash *hash = encap_hash; -#if ENABLE_BGP_VNC +#ifdef ENABLE_BGP_VNC if (type == VNC_SUBTLV_TYPE) hash = vnc_hash; #endif @@ -341,7 +341,7 @@ static void encap_unintern(struct bgp_attr_encap_subtlv **encapp, if (encap->refcnt == 0) { struct hash *hash = encap_hash; -#if ENABLE_BGP_VNC +#ifdef ENABLE_BGP_VNC if (type == VNC_SUBTLV_TYPE) hash = vnc_hash; #endif @@ -368,7 +368,7 @@ static void encap_init(void) { encap_hash = hash_create(encap_hash_key_make, encap_hash_cmp, "BGP Encap Hash"); -#if ENABLE_BGP_VNC +#ifdef ENABLE_BGP_VNC vnc_hash = hash_create(encap_hash_key_make, encap_hash_cmp, "BGP VNC Hash"); #endif @@ -379,7 +379,7 @@ static void encap_finish(void) hash_clean(encap_hash, (void (*)(void *))encap_free); hash_free(encap_hash); encap_hash = NULL; -#if ENABLE_BGP_VNC +#ifdef ENABLE_BGP_VNC hash_clean(vnc_hash, (void (*)(void *))encap_free); hash_free(vnc_hash); vnc_hash = NULL; @@ -660,7 +660,7 @@ unsigned int attrhash_key_make(const void *p) MIX(transit_hash_key_make(attr->transit)); if (attr->encap_subtlvs) MIX(encap_hash_key_make(attr->encap_subtlvs)); -#if ENABLE_BGP_VNC +#ifdef ENABLE_BGP_VNC if (attr->vnc_subtlvs) MIX(encap_hash_key_make(attr->vnc_subtlvs)); #endif @@ -698,7 +698,7 @@ bool attrhash_cmp(const void *p1, const void *p2) && attr1->rmap_table_id == attr2->rmap_table_id && (attr1->encap_tunneltype == attr2->encap_tunneltype) && encap_same(attr1->encap_subtlvs, attr2->encap_subtlvs) -#if ENABLE_BGP_VNC +#ifdef ENABLE_BGP_VNC && encap_same(attr1->vnc_subtlvs, attr2->vnc_subtlvs) #endif && IPV6_ADDR_SAME(&attr1->mp_nexthop_global, @@ -780,7 +780,7 @@ static void *bgp_attr_hash_alloc(void *p) if (val->encap_subtlvs) { val->encap_subtlvs = NULL; } -#if ENABLE_BGP_VNC +#ifdef ENABLE_BGP_VNC if (val->vnc_subtlvs) { val->vnc_subtlvs = NULL; } @@ -856,7 +856,7 @@ struct attr *bgp_attr_intern(struct attr *attr) else attr->srv6_vpn->refcnt++; } -#if ENABLE_BGP_VNC +#ifdef ENABLE_BGP_VNC if (attr->vnc_subtlvs) { if (!attr->vnc_subtlvs->refcnt) attr->vnc_subtlvs = encap_intern(attr->vnc_subtlvs, @@ -1041,7 +1041,7 @@ void bgp_attr_unintern_sub(struct attr *attr) if (attr->encap_subtlvs) encap_unintern(&attr->encap_subtlvs, ENCAP_SUBTLV_TYPE); -#if ENABLE_BGP_VNC +#ifdef ENABLE_BGP_VNC if (attr->vnc_subtlvs) encap_unintern(&attr->vnc_subtlvs, VNC_SUBTLV_TYPE); #endif @@ -1125,7 +1125,7 @@ void bgp_attr_flush(struct attr *attr) encap_free(attr->encap_subtlvs); attr->encap_subtlvs = NULL; } -#if ENABLE_BGP_VNC +#ifdef ENABLE_BGP_VNC if (attr->vnc_subtlvs && !attr->vnc_subtlvs->refcnt) { encap_free(attr->vnc_subtlvs); attr->vnc_subtlvs = NULL; @@ -1398,6 +1398,15 @@ static int bgp_attr_aspath(struct bgp_attr_parser_args *args) 0); } + /* Codification of AS 0 Processing */ + if (aspath_check_as_zero(attr->aspath)) { + flog_err(EC_BGP_ATTR_MAL_AS_PATH, + "Malformed AS path, contains BGP_AS_ZERO(0) from %s", + peer->host); + return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_MAL_AS_PATH, + 0); + } + /* Set aspath attribute flag. */ attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_AS_PATH); @@ -1469,6 +1478,15 @@ static int bgp_attr_as4_path(struct bgp_attr_parser_args *args, 0); } + /* Codification of AS 0 Processing */ + if (aspath_check_as_zero(*as4_path)) { + flog_err(EC_BGP_ATTR_MAL_AS_PATH, + "Malformed AS4 path, contains BGP_AS_ZERO(0) from %s", + peer->host); + return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_MAL_AS_PATH, + 0); + } + /* Set aspath attribute flag. */ attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_AS4_PATH); @@ -1615,6 +1633,7 @@ static int bgp_attr_aggregator(struct bgp_attr_parser_args *args) struct peer *const peer = args->peer; struct attr *const attr = args->attr; const bgp_size_t length = args->length; + as_t aggregator_as; int wantedlen = 6; @@ -1632,9 +1651,19 @@ static int bgp_attr_aggregator(struct bgp_attr_parser_args *args) } if (CHECK_FLAG(peer->cap, PEER_CAP_AS4_RCV)) - attr->aggregator_as = stream_getl(peer->curr); + aggregator_as = stream_getl(peer->curr); else - attr->aggregator_as = stream_getw(peer->curr); + aggregator_as = stream_getw(peer->curr); + + /* Codification of AS 0 Processing */ + if (aggregator_as == BGP_AS_ZERO) { + flog_err(EC_BGP_ATTR_LEN, + "AGGREGATOR attribute is BGP_AS_ZERO(0)"); + return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_MAL_AS_PATH, + args->total); + } + + attr->aggregator_as = aggregator_as; attr->aggregator_addr.s_addr = stream_get_ipv4(peer->curr); /* Set atomic aggregate flag. */ @@ -1652,6 +1681,7 @@ bgp_attr_as4_aggregator(struct bgp_attr_parser_args *args, struct peer *const peer = args->peer; struct attr *const attr = args->attr; const bgp_size_t length = args->length; + as_t aggregator_as; if (length != 8) { flog_err(EC_BGP_ATTR_LEN, "New Aggregator length is not 8 [%d]", @@ -1660,7 +1690,16 @@ bgp_attr_as4_aggregator(struct bgp_attr_parser_args *args, 0); } - *as4_aggregator_as = stream_getl(peer->curr); + /* Codification of AS 0 Processing */ + aggregator_as = stream_getl(peer->curr); + if (aggregator_as == BGP_AS_ZERO) { + flog_err(EC_BGP_ATTR_LEN, + "AS4_AGGREGATOR attribute is BGP_AS_ZERO(0)"); + return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_MAL_AS_PATH, + 0); + } + + *as4_aggregator_as = aggregator_as; as4_aggregator_addr->s_addr = stream_get_ipv4(peer->curr); attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_AS4_AGGREGATOR); @@ -2265,7 +2304,7 @@ static int bgp_attr_encap(uint8_t type, struct peer *peer, /* IN */ subtype = stream_getc(BGP_INPUT(peer)); sublength = stream_getc(BGP_INPUT(peer)); length -= 2; -#if ENABLE_BGP_VNC +#ifdef ENABLE_BGP_VNC } else { subtype = stream_getw(BGP_INPUT(peer)); sublength = stream_getw(BGP_INPUT(peer)); @@ -2304,7 +2343,7 @@ static int bgp_attr_encap(uint8_t type, struct peer *peer, /* IN */ } else { attr->encap_subtlvs = tlv; } -#if ENABLE_BGP_VNC +#ifdef ENABLE_BGP_VNC } else { struct bgp_attr_encap_subtlv *stlv_last; for (stlv_last = attr->vnc_subtlvs; @@ -2506,9 +2545,14 @@ static bgp_attr_parse_ret_t bgp_attr_psid_sub(uint8_t type, uint16_t length, } /* Configure from Info */ - attr->srv6_vpn = XMALLOC(MTYPE_BGP_SRV6_VPN, + if (attr->srv6_vpn) { + flog_err(EC_BGP_ATTRIBUTE_REPEATED, + "Prefix SID SRv6 VPN field repeated"); + return bgp_attr_malformed( + args, BGP_NOTIFY_UPDATE_MAL_ATTR, args->total); + } + attr->srv6_vpn = XCALLOC(MTYPE_BGP_SRV6_VPN, sizeof(struct bgp_attr_srv6_vpn)); - attr->srv6_vpn->refcnt = 0; attr->srv6_vpn->sid_flags = sid_flags; sid_copy(&attr->srv6_vpn->sid, &ipv6_sid); } @@ -2543,7 +2587,13 @@ static bgp_attr_parse_ret_t bgp_attr_psid_sub(uint8_t type, uint16_t length, } /* Configure from Info */ - attr->srv6_l3vpn = XMALLOC(MTYPE_BGP_SRV6_L3VPN, + if (attr->srv6_l3vpn) { + flog_err(EC_BGP_ATTRIBUTE_REPEATED, + "Prefix SID SRv6 L3VPN field repeated"); + return bgp_attr_malformed( + args, BGP_NOTIFY_UPDATE_MAL_ATTR, args->total); + } + attr->srv6_l3vpn = XCALLOC(MTYPE_BGP_SRV6_L3VPN, sizeof(struct bgp_attr_srv6_l3vpn)); attr->srv6_l3vpn->sid_flags = sid_flags; attr->srv6_l3vpn->endpoint_behavior = endpoint_behavior; @@ -3008,7 +3058,7 @@ bgp_attr_parse_ret_t bgp_attr_parse(struct peer *peer, struct attr *attr, case BGP_ATTR_EXT_COMMUNITIES: ret = bgp_attr_ext_communities(&attr_args); break; -#if ENABLE_BGP_VNC_ATTR +#ifdef ENABLE_BGP_VNC_ATTR case BGP_ATTR_VNC: #endif case BGP_ATTR_ENCAP: @@ -3160,7 +3210,7 @@ done: if (attr->encap_subtlvs) attr->encap_subtlvs = encap_intern(attr->encap_subtlvs, ENCAP_SUBTLV_TYPE); -#if ENABLE_BGP_VNC +#ifdef ENABLE_BGP_VNC if (attr->vnc_subtlvs) attr->vnc_subtlvs = encap_intern(attr->vnc_subtlvs, VNC_SUBTLV_TYPE); @@ -3179,7 +3229,7 @@ done: assert(attr->transit->refcnt > 0); if (attr->encap_subtlvs) assert(attr->encap_subtlvs->refcnt > 0); -#if ENABLE_BGP_VNC +#ifdef ENABLE_BGP_VNC if (attr->vnc_subtlvs) assert(attr->vnc_subtlvs->refcnt > 0); #endif @@ -3429,7 +3479,7 @@ static void bgp_packet_mpattr_tea(struct bgp *bgp, struct peer *peer, attrhdrlen = 1 + 1; /* subTLV T + L */ break; -#if ENABLE_BGP_VNC_ATTR +#ifdef ENABLE_BGP_VNC_ATTR case BGP_ATTR_VNC: attrname = "VNC"; subtlvs = attr->vnc_subtlvs; @@ -3480,7 +3530,7 @@ static void bgp_packet_mpattr_tea(struct bgp *bgp, struct peer *peer, if (attrtype == BGP_ATTR_ENCAP) { stream_putc(s, st->type); stream_putc(s, st->length); -#if ENABLE_BGP_VNC +#ifdef ENABLE_BGP_VNC } else { stream_putw(s, st->type); stream_putw(s, st->length); @@ -3965,7 +4015,7 @@ bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer, /* Tunnel Encap attribute */ bgp_packet_mpattr_tea(bgp, peer, s, attr, BGP_ATTR_ENCAP); -#if ENABLE_BGP_VNC_ATTR +#ifdef ENABLE_BGP_VNC_ATTR /* VNC attribute */ bgp_packet_mpattr_tea(bgp, peer, s, attr, BGP_ATTR_VNC); #endif diff --git a/bgpd/bgp_attr_evpn.h b/bgpd/bgp_attr_evpn.h index a8a35e8174..25654ba709 100644 --- a/bgpd/bgp_attr_evpn.h +++ b/bgpd/bgp_attr_evpn.h @@ -34,7 +34,6 @@ #define MAX_ET 0xffffffff -unsigned long eth_tag_id; struct attr; /* EVPN ESI */ diff --git a/bgpd/bgp_bfd.c b/bgpd/bgp_bfd.c index 80ef43f0d3..1f650aaeb7 100644 --- a/bgpd/bgp_bfd.c +++ b/bgpd/bgp_bfd.c @@ -329,19 +329,22 @@ static int bgp_bfd_dest_update(ZAPI_CALLBACK_ARGS) &remote_cbit, vrf_id); if (BGP_DEBUG(zebra, ZEBRA)) { + struct vrf *vrf; char buf[2][PREFIX2STR_BUFFER]; + + vrf = vrf_lookup_by_id(vrf_id); prefix2str(&dp, buf[0], sizeof(buf[0])); if (ifp) { zlog_debug( - "Zebra: vrf %u interface %s bfd destination %s %s %s", - vrf_id, ifp->name, buf[0], - bfd_get_status_str(status), + "Zebra: vrf %s(%u) interface %s bfd destination %s %s %s", + VRF_LOGNAME(vrf), vrf_id, ifp->name, + buf[0], bfd_get_status_str(status), remote_cbit ? "(cbit on)" : ""); } else { prefix2str(&sp, buf[1], sizeof(buf[1])); zlog_debug( - "Zebra: vrf %u source %s bfd destination %s %s %s", - vrf_id, buf[1], buf[0], + "Zebra: vrf %s(%u) source %s bfd destination %s %s %s", + VRF_LOGNAME(vrf), vrf_id, buf[1], buf[0], bfd_get_status_str(status), remote_cbit ? "(cbit on)" : ""); } diff --git a/bgpd/bgp_clist.c b/bgpd/bgp_clist.c index 7ca48a5bea..5c461dbe77 100644 --- a/bgpd/bgp_clist.c +++ b/bgpd/bgp_clist.c @@ -44,7 +44,7 @@ static int64_t bgp_clist_new_seq_get(struct community_list *list) int64_t newseq; struct community_entry *entry; - maxseq = newseq = 0; + maxseq = 0; for (entry = list->head; entry; entry = entry->next) { if (maxseq < entry->seq) @@ -654,7 +654,7 @@ community_regexp_delete (struct community *com, regex_t * reg) i = 0; while (i < com->size) { - memcpy (&comval, com_nthval (com, i), sizeof (uint32_t)); + memcpy (&comval, com_nthval (com, i), sizeof(uint32_t)); comval = ntohl (comval); switch (comval) { diff --git a/bgpd/bgp_community.c b/bgpd/bgp_community.c index 496d7ed2b1..c145c47d02 100644 --- a/bgpd/bgp_community.c +++ b/bgpd/bgp_community.c @@ -907,7 +907,7 @@ static void *bgp_aggr_communty_hash_alloc(void *p) return community; } -static void bgp_aggr_community_prepare(struct hash_backet *hb, void *arg) +static void bgp_aggr_community_prepare(struct hash_bucket *hb, void *arg) { struct community *hb_community = hb->data; struct community **aggr_community = arg; diff --git a/bgpd/bgp_damp.c b/bgpd/bgp_damp.c index b0fee079d1..792f3cea70 100644 --- a/bgpd/bgp_damp.c +++ b/bgpd/bgp_damp.c @@ -501,7 +501,7 @@ static const char *bgp_get_reuse_time(unsigned int penalty, char *buf, bool use_json, json_object *json) { time_t reuse_time = 0; - struct tm *tm = NULL; + struct tm tm; int time_store = 0; if (penalty > damp[afi][safi].reuse_limit) { @@ -513,7 +513,7 @@ static const char *bgp_get_reuse_time(unsigned int penalty, char *buf, if (reuse_time > damp[afi][safi].max_suppress_time) reuse_time = damp[afi][safi].max_suppress_time; - tm = gmtime(&reuse_time); + gmtime_r(&reuse_time, &tm); } else reuse_time = 0; @@ -525,39 +525,39 @@ static const char *bgp_get_reuse_time(unsigned int penalty, char *buf, snprintf(buf, len, "00:00:00"); } else if (reuse_time < ONE_DAY_SECOND) { if (use_json) { - time_store = (3600000 * tm->tm_hour) - + (60000 * tm->tm_min) - + (1000 * tm->tm_sec); + time_store = (3600000 * tm.tm_hour) + + (60000 * tm.tm_min) + + (1000 * tm.tm_sec); json_object_int_add(json, "reuseTimerMsecs", time_store); } else - snprintf(buf, len, "%02d:%02d:%02d", tm->tm_hour, - tm->tm_min, tm->tm_sec); + snprintf(buf, len, "%02d:%02d:%02d", tm.tm_hour, + tm.tm_min, tm.tm_sec); } else if (reuse_time < ONE_WEEK_SECOND) { if (use_json) { - time_store = (86400000 * tm->tm_yday) - + (3600000 * tm->tm_hour) - + (60000 * tm->tm_min) - + (1000 * tm->tm_sec); + time_store = (86400000 * tm.tm_yday) + + (3600000 * tm.tm_hour) + + (60000 * tm.tm_min) + + (1000 * tm.tm_sec); json_object_int_add(json, "reuseTimerMsecs", time_store); } else - snprintf(buf, len, "%dd%02dh%02dm", tm->tm_yday, - tm->tm_hour, tm->tm_min); + snprintf(buf, len, "%dd%02dh%02dm", tm.tm_yday, + tm.tm_hour, tm.tm_min); } else { if (use_json) { time_store = - (604800000 * tm->tm_yday / 7) + (604800000 * tm.tm_yday / 7) + (86400000 - * (tm->tm_yday - ((tm->tm_yday / 7) * 7))) - + (3600000 * tm->tm_hour) + (60000 * tm->tm_min) - + (1000 * tm->tm_sec); + * (tm.tm_yday - ((tm.tm_yday / 7) * 7))) + + (3600000 * tm.tm_hour) + (60000 * tm.tm_min) + + (1000 * tm.tm_sec); json_object_int_add(json, "reuseTimerMsecs", time_store); } else - snprintf(buf, len, "%02dw%dd%02dh", tm->tm_yday / 7, - tm->tm_yday - ((tm->tm_yday / 7) * 7), - tm->tm_hour); + snprintf(buf, len, "%02dw%dd%02dh", tm.tm_yday / 7, + tm.tm_yday - ((tm.tm_yday / 7) * 7), + tm.tm_hour); } return buf; diff --git a/bgpd/bgp_debug.c b/bgpd/bgp_debug.c index c69bc52e47..2e21c7222c 100644 --- a/bgpd/bgp_debug.c +++ b/bgpd/bgp_debug.c @@ -170,6 +170,16 @@ static const struct message bgp_notify_capability_msg[] = { {BGP_NOTIFY_CAPABILITY_MALFORMED_CODE, "/Malformed Capability Value"}, {0}}; +static const struct message bgp_notify_fsm_msg[] = { + {BGP_NOTIFY_FSM_ERR_SUBCODE_UNSPECIFIC, "/Unspecific"}, + {BGP_NOTIFY_FSM_ERR_SUBCODE_OPENSENT, + "/Receive Unexpected Message in OpenSent State"}, + {BGP_NOTIFY_FSM_ERR_SUBCODE_OPENCONFIRM, + "/Receive Unexpected Message in OpenConfirm State"}, + {BGP_NOTIFY_FSM_ERR_SUBCODE_ESTABLISHED, + "/Receive Unexpected Message in Established State"}, + {0}}; + /* Origin strings. */ const char *const bgp_origin_str[] = {"i", "e", "?"}; const char *const bgp_origin_long_str[] = {"IGP", "EGP", "incomplete"}; @@ -209,13 +219,8 @@ static void bgp_debug_list_free(struct list *list) if (list) for (ALL_LIST_ELEMENTS(list, node, nnode, filter)) { listnode_delete(list, filter); - - if (filter->p) - prefix_free(&filter->p); - - if (filter->host) - XFREE(MTYPE_BGP_DEBUG_STR, filter->host); - + prefix_free(&filter->p); + XFREE(MTYPE_BGP_DEBUG_STR, filter->host); XFREE(MTYPE_BGP_DEBUG_FILTER, filter); } } @@ -476,7 +481,8 @@ const char *bgp_notify_subcode_str(char code, char subcode) case BGP_NOTIFY_HOLD_ERR: break; case BGP_NOTIFY_FSM_ERR: - break; + return lookup_msg(bgp_notify_fsm_msg, subcode, + "Unrecognized Error Subcode"); case BGP_NOTIFY_CEASE: return lookup_msg(bgp_notify_cease_msg, subcode, "Unrecognized Error Subcode"); diff --git a/bgpd/bgp_dump.c b/bgpd/bgp_dump.c index 298f9d0212..c448b9894a 100644 --- a/bgpd/bgp_dump.c +++ b/bgpd/bgp_dump.c @@ -106,19 +106,19 @@ static FILE *bgp_dump_open_file(struct bgp_dump *bgp_dump) { int ret; time_t clock; - struct tm *tm; + struct tm tm; char fullpath[MAXPATHLEN]; char realpath[MAXPATHLEN]; mode_t oldumask; time(&clock); - tm = localtime(&clock); + localtime_r(&clock, &tm); if (bgp_dump->filename[0] != DIRECTORY_SEP) { sprintf(fullpath, "%s/%s", vty_get_cwd(), bgp_dump->filename); - ret = strftime(realpath, MAXPATHLEN, fullpath, tm); + ret = strftime(realpath, MAXPATHLEN, fullpath, &tm); } else - ret = strftime(realpath, MAXPATHLEN, bgp_dump->filename, tm); + ret = strftime(realpath, MAXPATHLEN, bgp_dump->filename, &tm); if (ret == 0) { flog_warn(EC_BGP_DUMP, "bgp_dump_open_file: strftime error"); @@ -147,7 +147,7 @@ static int bgp_dump_interval_add(struct bgp_dump *bgp_dump, int interval) { int secs_into_day; time_t t; - struct tm *tm; + struct tm tm; if (interval > 0) { /* Periodic dump every interval seconds */ @@ -158,9 +158,9 @@ static int bgp_dump_interval_add(struct bgp_dump *bgp_dump, int interval) * midnight */ (void)time(&t); - tm = localtime(&t); - secs_into_day = tm->tm_sec + 60 * tm->tm_min - + 60 * 60 * tm->tm_hour; + localtime_r(&t, &tm); + secs_into_day = tm.tm_sec + 60 * tm.tm_min + + 60 * 60 * tm.tm_hour; interval = interval - secs_into_day % interval; /* always > 0 */ } diff --git a/bgpd/bgp_ecommunity.c b/bgpd/bgp_ecommunity.c index 4c55a0764d..2711cf7a69 100644 --- a/bgpd/bgp_ecommunity.c +++ b/bgpd/bgp_ecommunity.c @@ -1026,7 +1026,7 @@ static void *bgp_aggr_ecommunty_hash_alloc(void *p) return ecommunity; } -static void bgp_aggr_ecommunity_prepare(struct hash_backet *hb, void *arg) +static void bgp_aggr_ecommunity_prepare(struct hash_bucket *hb, void *arg) { struct ecommunity *hb_ecommunity = hb->data; struct ecommunity **aggr_ecommunity = arg; diff --git a/bgpd/bgp_errors.c b/bgpd/bgp_errors.c index d9aba87e35..8a33ce6789 100644 --- a/bgpd/bgp_errors.c +++ b/bgpd/bgp_errors.c @@ -457,6 +457,12 @@ static struct log_ref ferr_bgp_err[] = { .suggestion = "Gather data and open a Issue so that this developmental escape can be fixed, the peer should have been reset", }, { + .code = EC_BGP_ROUTER_ID_SAME, + .title = "BGP has detected a duplicate router id during collision resolution", + .description = "As part of normal collision detection for opening a connection to a peer, BGP has detected that the remote peer's router-id is the same as ours", + .suggestion = "Change one of the two router-id's", + }, + { .code = END_FERR, } }; diff --git a/bgpd/bgp_errors.h b/bgpd/bgp_errors.h index 35c5cc3998..49c58ae6b0 100644 --- a/bgpd/bgp_errors.h +++ b/bgpd/bgp_errors.h @@ -98,6 +98,7 @@ enum bgp_log_refs { EC_BGP_CAPABILITY_UNKNOWN, EC_BGP_INVALID_NEXTHOP_LENGTH, EC_BGP_DOPPELGANGER_CONFIG, + EC_BGP_ROUTER_ID_SAME, }; extern void bgp_error_init(void); diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c index 206680c403..664d62fd11 100644 --- a/bgpd/bgp_evpn.c +++ b/bgpd/bgp_evpn.c @@ -600,8 +600,9 @@ static int bgp_zebra_send_remote_macip(struct bgp *bgp, struct bgpevpn *vpn, /* Don't try to register if Zebra doesn't know of this instance. */ if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp)) { if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("%s: No zebra instance to talk to, not installing remote macip", - __PRETTY_FUNCTION__); + zlog_debug( + "%s: No zebra instance to talk to, not installing remote macip", + __func__); return 0; } s = zclient->obuf; @@ -662,8 +663,9 @@ static int bgp_zebra_send_remote_vtep(struct bgp *bgp, struct bgpevpn *vpn, /* Don't try to register if Zebra doesn't know of this instance. */ if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp)) { if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("%s: No zebra instance to talk to, not installing remote vtep", - __PRETTY_FUNCTION__); + zlog_debug( + "%s: No zebra instance to talk to, not installing remote vtep", + __func__); return 0; } diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c index b483d39bba..0051b8d606 100644 --- a/bgpd/bgp_fsm.c +++ b/bgpd/bgp_fsm.c @@ -885,6 +885,27 @@ void bgp_maxmed_update(struct bgp *bgp) } } +int bgp_fsm_error_subcode(int status) +{ + int fsm_err_subcode = BGP_NOTIFY_FSM_ERR_SUBCODE_UNSPECIFIC; + + switch (status) { + case OpenSent: + fsm_err_subcode = BGP_NOTIFY_FSM_ERR_SUBCODE_OPENSENT; + break; + case OpenConfirm: + fsm_err_subcode = BGP_NOTIFY_FSM_ERR_SUBCODE_OPENCONFIRM; + break; + case Established: + fsm_err_subcode = BGP_NOTIFY_FSM_ERR_SUBCODE_ESTABLISHED; + break; + default: + break; + } + + return fsm_err_subcode; +} + /* The maxmed onstartup timer expiry callback. */ static int bgp_maxmed_onstartup_timer(struct thread *thread) { @@ -1128,6 +1149,10 @@ int bgp_stop(struct peer *peer) peer->nsf_af_count = 0; + /* deregister peer */ + if (peer->last_reset == PEER_DOWN_UPDATE_SOURCE_CHANGE) + bgp_bfd_deregister_peer(peer); + if (peer_dynamic_neighbor(peer) && !(CHECK_FLAG(peer->flags, PEER_FLAG_DELETE))) { if (bgp_debug_neighbor_events(peer)) @@ -1450,10 +1475,9 @@ static int bgp_connect_success(struct peer *peer) if (bgp_getsockname(peer) < 0) { flog_err_sys(EC_LIB_SOCKET, "%s: bgp_getsockname(): failed for peer %s, fd %d", - __FUNCTION__, peer->host, peer->fd); - bgp_notify_send( - peer, BGP_NOTIFY_FSM_ERR, - BGP_NOTIFY_SUBCODE_UNSPECIFIC); /* internal error */ + __func__, peer->host, peer->fd); + bgp_notify_send(peer, BGP_NOTIFY_FSM_ERR, + bgp_fsm_error_subcode(peer->status)); bgp_writes_on(peer); return -1; } @@ -1653,7 +1677,8 @@ static int bgp_fsm_event_error(struct peer *peer) flog_err(EC_BGP_FSM, "%s [FSM] unexpected packet received in state %s", 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, + bgp_fsm_error_subcode(peer->status)); } /* Hold timer expire. This is error of BGP connection. So cut the @@ -1931,6 +1956,7 @@ static int bgp_establish(struct peer *peer) hash_release(peer->bgp->peerhash, peer); hash_get(peer->bgp->peerhash, peer, hash_alloc_intern); + bgp_bfd_deregister_peer(peer); bgp_bfd_register_peer(peer); return ret; } @@ -2512,7 +2538,7 @@ int bgp_neighbor_graceful_restart(struct peer *peer, int peer_gr_cmd) peer->peer_gr_present_state = peer_new_state; if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART)) zlog_debug( - "[BGP_GR] Succesfully change the state of the peer to : %s : !", + "[BGP_GR] Successfully change the state of the peer to : %s : !", print_peer_gr_mode(peer_new_state)); return BGP_GR_SUCCESS; diff --git a/bgpd/bgp_fsm.h b/bgpd/bgp_fsm.h index 6feabbf570..4b8db161d7 100644 --- a/bgpd/bgp_fsm.h +++ b/bgpd/bgp_fsm.h @@ -121,6 +121,7 @@ extern void bgp_update_delay_end(struct bgp *); extern void bgp_maxmed_update(struct bgp *); extern int bgp_maxmed_onstartup_configured(struct bgp *); extern int bgp_maxmed_onstartup_active(struct bgp *); +extern int bgp_fsm_error_subcode(int status); /** * Start the route advertisement timer (that honors MRAI) for all the diff --git a/bgpd/bgp_lcommunity.c b/bgpd/bgp_lcommunity.c index f889693001..7a4435f6f2 100644 --- a/bgpd/bgp_lcommunity.c +++ b/bgpd/bgp_lcommunity.c @@ -550,7 +550,7 @@ static void *bgp_aggr_lcommunty_hash_alloc(void *p) return lcommunity; } -static void bgp_aggr_lcommunity_prepare(struct hash_backet *hb, void *arg) +static void bgp_aggr_lcommunity_prepare(struct hash_bucket *hb, void *arg) { struct lcommunity *hb_lcommunity = hb->data; struct lcommunity **aggr_lcommunity = arg; diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index 86c04b71f0..8758d0ca78 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -1532,7 +1532,10 @@ void vpn_handle_router_id_update(struct bgp *bgp, bool withdraw, ecom = bgp->vpn_policy[afi].rtlist[edir]; for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi]. export_vrf, node, vname)) { - bgp_import = bgp_lookup_by_name(vname); + if (strcmp(vname, VRF_DEFAULT_NAME) == 0) + bgp_import = bgp_get_default(); + else + bgp_import = bgp_lookup_by_name(vname); if (!bgp_import) continue; @@ -1572,7 +1575,10 @@ void vpn_handle_router_id_update(struct bgp *bgp, bool withdraw, ecom = bgp->vpn_policy[afi].rtlist[edir]; for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi]. export_vrf, node, vname)) { - bgp_import = bgp_lookup_by_name(vname); + if (strcmp(vname, VRF_DEFAULT_NAME) == 0) + bgp_import = bgp_get_default(); + else + bgp_import = bgp_lookup_by_name(vname); if (!bgp_import) continue; if (bgp_import->vpn_policy[afi].rtlist[idir]) diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c index 8759a88444..037aeec288 100644 --- a/bgpd/bgp_network.c +++ b/bgpd/bgp_network.c @@ -57,8 +57,26 @@ struct bgp_listener { union sockunion su; struct thread *thread; struct bgp *bgp; + char *name; }; +void bgp_dump_listener_info(struct vty *vty) +{ + struct listnode *node; + struct bgp_listener *listener; + + vty_out(vty, "Name fd Address\n"); + vty_out(vty, "---------------------------\n"); + for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) { + char buf[SU_ADDRSTRLEN]; + + vty_out(vty, "%-16s %d %s\n", + listener->name ? listener->name : VRF_DEFAULT_NAME, + listener->fd, + sockunion2str(&listener->su, buf, sizeof(buf))); + } +} + /* * Set MD5 key for the socket, for the given IPv4 peer address. * If the password is NULL or zero-length, the option will be disabled. @@ -762,6 +780,7 @@ static int bgp_listener(int sock, struct sockaddr *sa, socklen_t salen, listener = XCALLOC(MTYPE_BGP_LISTENER, sizeof(*listener)); listener->fd = sock; + listener->name = XSTRDUP(MTYPE_BGP_LISTENER, bgp->name); /* this socket needs a change of ns. record bgp back pointer */ if (bgp->vrf_id != VRF_DEFAULT && vrf_is_backend_netns()) @@ -871,6 +890,7 @@ void bgp_close_vrf_socket(struct bgp *bgp) thread_cancel(listener->thread); close(listener->fd); listnode_delete(bm->listen_sockets, listener); + XFREE(MTYPE_BGP_LISTENER, listener->name); XFREE(MTYPE_BGP_LISTENER, listener); } } @@ -892,6 +912,7 @@ void bgp_close(void) thread_cancel(listener->thread); close(listener->fd); listnode_delete(bm->listen_sockets, listener); + XFREE(MTYPE_BGP_LISTENER, listener->name); XFREE(MTYPE_BGP_LISTENER, listener); } } diff --git a/bgpd/bgp_network.h b/bgpd/bgp_network.h index 59b18f9376..018efbc08e 100644 --- a/bgpd/bgp_network.h +++ b/bgpd/bgp_network.h @@ -23,6 +23,7 @@ #define BGP_SOCKET_SNDBUF_SIZE 65536 +extern void bgp_dump_listener_info(struct vty *vty); extern int bgp_socket(struct bgp *bgp, unsigned short port, const char *address); extern void bgp_close_vrf_socket(struct bgp *bgp); diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index 7116c80941..ab0c3a3f11 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -180,7 +180,7 @@ void bgp_tip_del(struct bgp *bgp, struct in_addr *tip) /* BGP own address structure */ struct bgp_addr { - struct prefix *p; + struct prefix p; struct list *ifp_name_list; }; @@ -192,17 +192,10 @@ static void show_address_entry(struct hash_bucket *bucket, void *args) struct listnode *node; char str[INET6_ADDRSTRLEN] = {0}; - if (addr->p->family == AF_INET) { - vty_out(vty, "addr: %s, count: %d : ", inet_ntop(AF_INET, - &(addr->p->u.prefix4), - str, INET_ADDRSTRLEN), - addr->ifp_name_list->count); - } else if (addr->p->family == AF_INET6) { - vty_out(vty, "addr: %s, count: %d : ", inet_ntop(AF_INET6, - &(addr->p->u.prefix6), - str, INET6_ADDRSTRLEN), - addr->ifp_name_list->count); - } + vty_out(vty, "addr: %s, count: %d : ", + inet_ntop(addr->p.family, &(addr->p.u.prefix), + str, INET6_ADDRSTRLEN), + addr->ifp_name_list->count); for (ALL_LIST_ELEMENTS_RO(addr->ifp_name_list, node, name)) { vty_out(vty, " %s,", name); @@ -231,8 +224,7 @@ static void *bgp_address_hash_alloc(void *p) struct bgp_addr *addr = NULL; addr = XMALLOC(MTYPE_BGP_ADDR, sizeof(struct bgp_addr)); - addr->p = prefix_new(); - prefix_copy(addr->p, copy_addr->p); + prefix_copy(&addr->p, ©_addr->p); addr->ifp_name_list = list_new(); addr->ifp_name_list->del = bgp_address_hash_string_del; @@ -244,7 +236,6 @@ static void bgp_address_hash_free(void *data) { struct bgp_addr *addr = data; - prefix_free(&addr->p); list_delete(&addr->ifp_name_list); XFREE(MTYPE_BGP_ADDR, addr); } @@ -253,7 +244,7 @@ static unsigned int bgp_address_hash_key_make(const void *p) { const struct bgp_addr *addr = p; - return prefix_hash_key((const void *)(addr->p)); + return prefix_hash_key(&addr->p); } static bool bgp_address_hash_cmp(const void *p1, const void *p2) @@ -261,7 +252,7 @@ static bool bgp_address_hash_cmp(const void *p1, const void *p2) const struct bgp_addr *addr1 = p1; const struct bgp_addr *addr2 = p2; - return prefix_same(addr1->p, addr2->p); + return prefix_same(&addr1->p, &addr2->p); } void bgp_address_init(struct bgp *bgp) @@ -288,12 +279,12 @@ static void bgp_address_add(struct bgp *bgp, struct connected *ifc, struct listnode *node; char *name; - tmp.p = p; + tmp.p = *p; - if (tmp.p->family == AF_INET) - tmp.p->prefixlen = IPV4_MAX_BITLEN; - else if (tmp.p->family == AF_INET6) - tmp.p->prefixlen = IPV6_MAX_BITLEN; + if (tmp.p.family == AF_INET) + tmp.p.prefixlen = IPV4_MAX_BITLEN; + else if (tmp.p.family == AF_INET6) + tmp.p.prefixlen = IPV6_MAX_BITLEN; addr = hash_get(bgp->address_hash, &tmp, bgp_address_hash_alloc); @@ -315,12 +306,12 @@ static void bgp_address_del(struct bgp *bgp, struct connected *ifc, struct listnode *node; char *name; - tmp.p = p; + tmp.p = *p; - if (tmp.p->family == AF_INET) - tmp.p->prefixlen = IPV4_MAX_BITLEN; - else if (tmp.p->family == AF_INET6) - tmp.p->prefixlen = IPV6_MAX_BITLEN; + if (tmp.p.family == AF_INET) + tmp.p.prefixlen = IPV4_MAX_BITLEN; + else if (tmp.p.family == AF_INET6) + tmp.p.prefixlen = IPV6_MAX_BITLEN; addr = hash_lookup(bgp->address_hash, &tmp); /* may have been deleted earlier by bgp_interface_down() */ @@ -482,75 +473,67 @@ static void bgp_connected_cleanup(struct route_table *table, int bgp_nexthop_self(struct bgp *bgp, afi_t afi, uint8_t type, uint8_t sub_type, struct attr *attr, struct bgp_node *rn) { - struct prefix p = {0}; - afi_t new_afi = afi; - struct bgp_addr tmp_addr = {0}, *addr = NULL; + uint8_t new_afi = afi == AFI_IP ? AF_INET : AF_INET6; + struct bgp_addr tmp_addr = {{0}}, *addr = NULL; struct tip_addr tmp_tip, *tip = NULL; - bool is_bgp_static_route = ((type == ZEBRA_ROUTE_BGP) - && (sub_type == BGP_ROUTE_STATIC)) + bool is_bgp_static_route = + ((type == ZEBRA_ROUTE_BGP) && (sub_type == BGP_ROUTE_STATIC)) ? true : false; if (!is_bgp_static_route) - new_afi = BGP_ATTR_NEXTHOP_AFI_IP6(attr) ? AFI_IP6 : AFI_IP; + new_afi = BGP_ATTR_NEXTHOP_AFI_IP6(attr) ? AF_INET6 : AF_INET; + tmp_addr.p.family = new_afi; switch (new_afi) { - case AFI_IP: - p.family = AF_INET; + case AF_INET: if (is_bgp_static_route) { - p.u.prefix4 = rn->p.u.prefix4; - p.prefixlen = rn->p.prefixlen; + tmp_addr.p.u.prefix4 = rn->p.u.prefix4; + tmp_addr.p.prefixlen = rn->p.prefixlen; } else { /* Here we need to find out which nexthop to be used*/ - if (attr->flag & - ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP)) { - - p.u.prefix4 = attr->nexthop; - p.prefixlen = IPV4_MAX_BITLEN; - - } else if ((attr->mp_nexthop_len) && - ((attr->mp_nexthop_len == - BGP_ATTR_NHLEN_IPV4) || - (attr->mp_nexthop_len == - BGP_ATTR_NHLEN_VPNV4))) { - p.u.prefix4 = + if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP)) { + tmp_addr.p.u.prefix4 = attr->nexthop; + tmp_addr.p.prefixlen = IPV4_MAX_BITLEN; + } else if ((attr->mp_nexthop_len) + && ((attr->mp_nexthop_len + == BGP_ATTR_NHLEN_IPV4) + || (attr->mp_nexthop_len + == BGP_ATTR_NHLEN_VPNV4))) { + tmp_addr.p.u.prefix4 = attr->mp_nexthop_global_in; - p.prefixlen = IPV4_MAX_BITLEN; + tmp_addr.p.prefixlen = IPV4_MAX_BITLEN; } else return 0; } break; - case AFI_IP6: - p.family = AF_INET6; - + case AF_INET6: if (is_bgp_static_route) { - p.u.prefix6 = rn->p.u.prefix6; - p.prefixlen = rn->p.prefixlen; + tmp_addr.p.u.prefix6 = rn->p.u.prefix6; + tmp_addr.p.prefixlen = rn->p.prefixlen; } else { - p.u.prefix6 = attr->mp_nexthop_global; - p.prefixlen = IPV6_MAX_BITLEN; + tmp_addr.p.u.prefix6 = attr->mp_nexthop_global; + tmp_addr.p.prefixlen = IPV6_MAX_BITLEN; } break; default: break; } - tmp_addr.p = &p; addr = hash_lookup(bgp->address_hash, &tmp_addr); if (addr) return 1; - if (new_afi == AFI_IP) { + if (new_afi == AF_INET) { memset(&tmp_tip, 0, sizeof(struct tip_addr)); tmp_tip.addr = attr->nexthop; if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP)) { tmp_tip.addr = attr->nexthop; } else if ((attr->mp_nexthop_len) && - ((attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV4) - || (attr->mp_nexthop_len == - BGP_ATTR_NHLEN_VPNV4))) { + ((attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV4) + || (attr->mp_nexthop_len == BGP_ATTR_NHLEN_VPNV4))) { tmp_tip.addr = attr->mp_nexthop_global_in; } diff --git a/bgpd/bgp_nht.c b/bgpd/bgp_nht.c index 55b44de6fb..dfa9ac9398 100644 --- a/bgpd/bgp_nht.c +++ b/bgpd/bgp_nht.c @@ -153,7 +153,7 @@ int bgp_find_or_add_nexthop(struct bgp *bgp_route, struct bgp *bgp_nexthop, if (BGP_DEBUG(nht, NHT)) { zlog_debug( "%s: Attempting to register with unknown AFI %d (not %d or %d)", - __FUNCTION__, afi, AFI_IP, AFI_IP6); + __func__, afi, AFI_IP, AFI_IP6); } return 0; } @@ -338,7 +338,7 @@ void bgp_parse_nexthop_update(int command, vrf_id_t vrf_id) if (!zapi_nexthop_update_decode(zclient->ibuf, &nhr)) { if (BGP_DEBUG(nht, NHT)) zlog_debug("%s[%s]: Failure to decode nexthop update", - __PRETTY_FUNCTION__, bgp->name_pretty); + __func__, bgp->name_pretty); return; } @@ -563,7 +563,7 @@ static int make_prefix(int afi, struct bgp_path_info *pi, struct prefix *p) if (BGP_DEBUG(nht, NHT)) { zlog_debug( "%s: Attempting to make prefix with unknown AFI %d (not %d or %d)", - __FUNCTION__, afi, AFI_IP, AFI_IP6); + __func__, afi, AFI_IP, AFI_IP6); } break; } @@ -591,15 +591,17 @@ static void sendmsg_zebra_rnh(struct bgp_nexthop_cache *bnc, int command) /* Don't try to register if Zebra doesn't know of this instance. */ if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bnc->bgp)) { if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("%s: No zebra instance to talk to, not installing NHT entry", - __PRETTY_FUNCTION__); + zlog_debug( + "%s: No zebra instance to talk to, not installing NHT entry", + __func__); return; } if (!bgp_zebra_num_connects()) { if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("%s: We have not connected yet, cannot send nexthops", - __PRETTY_FUNCTION__); + zlog_debug( + "%s: We have not connected yet, cannot send nexthops", + __func__); } p = &(bnc->node->p); if ((command == ZEBRA_NEXTHOP_REGISTER @@ -801,9 +803,10 @@ static void evaluate_paths(struct bgp_nexthop_cache *bnc) if (!CHECK_FLAG(bnc->flags, BGP_NEXTHOP_PEER_NOTIFIED)) { if (BGP_DEBUG(nht, NHT)) - zlog_debug("%s: Updating peer (%s(%s)) status with NHT", - __FUNCTION__, peer->host, - peer->bgp->name_pretty); + zlog_debug( + "%s: Updating peer (%s(%s)) status with NHT", + __func__, peer->host, + peer->bgp->name_pretty); bgp_fsm_event_update(peer, valid_nexthops); SET_FLAG(bnc->flags, BGP_NEXTHOP_PEER_NOTIFIED); } @@ -882,7 +885,7 @@ void bgp_nht_register_enhe_capability_interfaces(struct peer *peer) if (!sockunion2hostprefix(&peer->su, &p)) { if (BGP_DEBUG(nht, NHT)) zlog_debug("%s: Unable to convert prefix to sockunion", - __PRETTY_FUNCTION__); + __func__); return; } diff --git a/bgpd/bgp_open.c b/bgpd/bgp_open.c index 906083f755..81bb45aa76 100644 --- a/bgpd/bgp_open.c +++ b/bgpd/bgp_open.c @@ -696,7 +696,7 @@ static int bgp_capability_hostname(struct peer *peer, flog_warn( EC_BGP_CAPABILITY_INVALID_DATA, "%s: Received malformed hostname capability from peer %s", - __FUNCTION__, peer->host); + __func__, peer->host); return -1; } @@ -720,7 +720,7 @@ static int bgp_capability_hostname(struct peer *peer, flog_warn( EC_BGP_CAPABILITY_INVALID_DATA, "%s: Received invalid domain name len (hostname capability) from peer %s", - __FUNCTION__, peer->host); + __func__, peer->host); return -1; } @@ -729,7 +729,7 @@ static int bgp_capability_hostname(struct peer *peer, flog_warn( EC_BGP_CAPABILITY_INVALID_DATA, "%s: Received runt domain name (hostname capability) from peer %s", - __FUNCTION__, peer->host); + __func__, peer->host); return -1; } diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c index c72f7226e2..9649de464e 100644 --- a/bgpd/bgp_packet.c +++ b/bgpd/bgp_packet.c @@ -1007,6 +1007,11 @@ static int bgp_collision_detect(struct peer *new, struct in_addr remote_id) return -1; } else { + if (ntohl(peer->local_id.s_addr) == + ntohl(remote_id.s_addr)) + flog_err(EC_BGP_ROUTER_ID_SAME, "Peer's router-id %s is the same as ours", + inet_ntoa(remote_id)); + /* 3. Otherwise, the local system closes newly created BGP connection (the one associated with the @@ -1137,6 +1142,15 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) return BGP_Stop; } + /* Codification of AS 0 Processing */ + if (remote_as == BGP_AS_ZERO) { + flog_err(EC_BGP_PKT_OPEN, "%s bad OPEN, got AS set to 0", + peer->host); + bgp_notify_send(peer, BGP_NOTIFY_OPEN_ERR, + BGP_NOTIFY_OPEN_BAD_PEER_AS); + return BGP_Stop; + } + if (remote_as == BGP_AS_TRANS) { /* Take the AS4 from the capability. We must have received the * capability now! Otherwise we have a asn16 peer who uses @@ -1298,8 +1312,7 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) /* Open option part parse. */ if (optlen != 0) { - if ((ret = bgp_open_option_parse(peer, optlen, &mp_capability)) - < 0) + if (bgp_open_option_parse(peer, optlen, &mp_capability) < 0) return BGP_Stop; } else { if (bgp_debug_neighbor_events(peer)) @@ -1341,10 +1354,10 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) return BGP_Stop; /* Get sockname. */ - if ((ret = bgp_getsockname(peer)) < 0) { + if (bgp_getsockname(peer) < 0) { flog_err_sys(EC_LIB_SOCKET, "%s: bgp_getsockname() failed for peer: %s", - __FUNCTION__, peer->host); + __func__, peer->host); return BGP_Stop; } @@ -1443,7 +1456,7 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size) peer->host, lookup_msg(bgp_status_msg, peer->status, NULL)); bgp_notify_send(peer, BGP_NOTIFY_FSM_ERR, - BGP_NOTIFY_SUBCODE_UNSPECIFIC); + bgp_fsm_error_subcode(peer->status)); return BGP_Stop; } @@ -1855,7 +1868,7 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size) peer->host, lookup_msg(bgp_status_msg, peer->status, NULL)); bgp_notify_send(peer, BGP_NOTIFY_FSM_ERR, - BGP_NOTIFY_SUBCODE_UNSPECIFIC); + bgp_fsm_error_subcode(peer->status)); return BGP_Stop; } @@ -1967,38 +1980,29 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size) } else p_pnt = p_end; - if ((ok = (p_pnt < p_end))) - orfp.ge = - *p_pnt++; /* value - checked in - prefix_bgp_orf_set() - */ - if ((ok = (p_pnt < p_end))) - orfp.le = - *p_pnt++; /* value - checked in - prefix_bgp_orf_set() - */ + /* val checked in prefix_bgp_orf_set */ + if (p_pnt < p_end) + orfp.ge = *p_pnt++; + + /* val checked in prefix_bgp_orf_set */ + if (p_pnt < p_end) + orfp.le = *p_pnt++; + if ((ok = (p_pnt < p_end))) orfp.p.prefixlen = *p_pnt++; - orfp.p.family = afi2family( - afi); /* afi checked already */ - - psize = PSIZE( - orfp.p.prefixlen); /* 0 if not - ok */ - if (psize - > prefix_blen( - &orfp.p)) /* valid for - family ? */ - { + + /* afi checked already */ + orfp.p.family = afi2family(afi); + + /* 0 if not ok */ + psize = PSIZE(orfp.p.prefixlen); + /* valid for family ? */ + if (psize > prefix_blen(&orfp.p)) { ok = 0; psize = prefix_blen(&orfp.p); } - if (psize - > (p_end - p_pnt)) /* valid for - packet ? */ - { + /* valid for packet ? */ + if (psize > (p_end - p_pnt)) { ok = 0; psize = p_end - p_pnt; } @@ -2256,7 +2260,7 @@ int bgp_capability_receive(struct peer *peer, bgp_size_t size) peer->host, lookup_msg(bgp_status_msg, peer->status, NULL)); bgp_notify_send(peer, BGP_NOTIFY_FSM_ERR, - BGP_NOTIFY_SUBCODE_UNSPECIFIC); + bgp_fsm_error_subcode(peer->status)); return BGP_Stop; } diff --git a/bgpd/bgp_pbr.c b/bgpd/bgp_pbr.c index eea20d7210..172ec8b42e 100644 --- a/bgpd/bgp_pbr.c +++ b/bgpd/bgp_pbr.c @@ -1403,11 +1403,16 @@ void bgp_pbr_print_policy_route(struct bgp_pbr_entry_main *api) ptr += sprintf(ptr, "@redirect ip nh %s", local_buff); break; - case ACTION_REDIRECT: + case ACTION_REDIRECT: { + struct vrf *vrf; + + vrf = vrf_lookup_by_id(api->actions[i].u.redirect_vrf); INCREMENT_DISPLAY(ptr, nb_items); - ptr += sprintf(ptr, "@redirect vrf %u", + ptr += sprintf(ptr, "@redirect vrf %s(%u)", + VRF_LOGNAME(vrf), api->actions[i].u.redirect_vrf); break; + } case ACTION_MARKING: INCREMENT_DISPLAY(ptr, nb_items); ptr += sprintf(ptr, "@set dscp %u", diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 3ae858945e..ad089d9d25 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -69,6 +69,7 @@ #include "bgpd/bgp_label.h" #include "bgpd/bgp_addpath.h" #include "bgpd/bgp_mac.h" +#include "bgpd/bgp_network.h" #if ENABLE_BGP_VNC #include "bgpd/rfapi/rfapi_backend.h" @@ -122,8 +123,6 @@ struct bgp_node *bgp_afi_node_get(struct bgp_table *table, afi_t afi, struct bgp_node *prn = NULL; assert(table); - if (!table) - return NULL; if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP) || (safi == SAFI_EVPN)) { @@ -299,7 +298,7 @@ static int bgp_node_set_defer_flag(struct bgp_node *rn, bool delete) { struct peer *peer; struct bgp_path_info *old_pi, *nextpi; - bool set_flag = 0; + bool set_flag = false; struct bgp *bgp = NULL; struct bgp_table *table = NULL; afi_t afi = 0; @@ -339,7 +338,7 @@ static int bgp_node_set_defer_flag(struct bgp_node *rn, bool delete) */ if (CHECK_FLAG(old_pi->flags, BGP_PATH_STALE) && (old_pi->sub_type == BGP_ROUTE_NORMAL)) { - set_flag = 1; + set_flag = true; } else { /* If the peer is graceful restart capable and peer is * restarting mode, set the flag BGP_NODE_SELECT_DEFER @@ -349,7 +348,7 @@ static int bgp_node_set_defer_flag(struct bgp_node *rn, bool delete) && BGP_PEER_RESTARTING_MODE(peer) && (old_pi && old_pi->sub_type == BGP_ROUTE_NORMAL)) { - set_flag = 1; + set_flag = true; } } if (set_flag) @@ -1946,6 +1945,10 @@ int subgroup_announce_check(struct bgp_node *rn, struct bgp_path_info *pi, if (aspath_check_as_sets(attr->aspath)) return 0; + /* Codification of AS 0 Processing */ + if (aspath_check_as_zero(attr->aspath)) + return 0; + if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) { if (peer->sort == BGP_PEER_IBGP || peer->sort == BGP_PEER_CONFED) { @@ -2487,7 +2490,7 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_node *rn, */ if (CHECK_FLAG(rn->flags, BGP_NODE_SELECT_DEFER)) { if (BGP_DEBUG(update, UPDATE_OUT)) - zlog_debug("SELECT_DEFER falg set for route %p", rn); + zlog_debug("SELECT_DEFER flag set for route %p", rn); return; } @@ -2926,8 +2929,7 @@ static int bgp_maximum_prefix_restart_timer(struct thread *thread) peer->host); if ((peer_clear(peer, NULL) < 0) && bgp_debug_neighbor_events(peer)) - zlog_debug("%s: %s peer_clear failed", - __PRETTY_FUNCTION__, peer->host); + zlog_debug("%s: %s peer_clear failed", __func__, peer->host); return 0; } @@ -3732,7 +3734,7 @@ int bgp_update(struct peer *peer, struct prefix *p, uint32_t addpath_id, ->nexthop, buf1, INET6_ADDRSTRLEN); zlog_debug("%s(%s): NH unresolved", - __FUNCTION__, buf1); + __func__, buf1); } bgp_path_info_unset_flag(rn, pi, BGP_PATH_VALID); @@ -3880,8 +3882,8 @@ int bgp_update(struct peer *peer, struct prefix *p, uint32_t addpath_id, inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN); - zlog_debug("%s(%s): NH unresolved", - __FUNCTION__, buf1); + zlog_debug("%s(%s): NH unresolved", __func__, + buf1); } bgp_path_info_unset_flag(rn, new, BGP_PATH_VALID); } @@ -4909,8 +4911,6 @@ void bgp_static_update(struct bgp *bgp, struct prefix *p, #endif assert(bgp_static); - if (!bgp_static) - return; rn = bgp_afi_node_get(bgp->rib[afi][safi], afi, safi, p, NULL); @@ -5040,7 +5040,7 @@ void bgp_static_update(struct bgp *bgp, struct prefix *p, INET6_ADDRSTRLEN); zlog_debug( "%s(%s): Route not in table, not advertising", - __FUNCTION__, buf1); + __func__, buf1); } bgp_path_info_unset_flag( rn, pi, BGP_PATH_VALID); @@ -5089,7 +5089,7 @@ void bgp_static_update(struct bgp *bgp, struct prefix *p, INET6_ADDRSTRLEN); zlog_debug( "%s(%s): Route not in table, not advertising", - __FUNCTION__, buf1); + __func__, buf1); } bgp_path_info_unset_flag(rn, new, BGP_PATH_VALID); } @@ -6270,6 +6270,9 @@ void bgp_aggregate_route(struct bgp *bgp, struct prefix *p, else if (aggregate->egp_origin_count > 0) origin = BGP_ORIGIN_EGP; + if (aggregate->origin != BGP_ORIGIN_UNSPECIFIED) + origin = aggregate->origin; + if (aggregate->as_set) { if (aggregate->aspath) /* Retrieve aggregate route's as-path. @@ -6434,6 +6437,9 @@ static void bgp_add_route_to_aggregate(struct bgp *bgp, struct prefix *aggr_p, else if (aggregate->egp_origin_count > 0) origin = BGP_ORIGIN_EGP; + if (aggregate->origin != BGP_ORIGIN_UNSPECIFIED) + origin = aggregate->origin; + if (aggregate->as_set) { /* Compute aggregate route's as-path. */ @@ -6565,6 +6571,9 @@ static void bgp_remove_route_from_aggregate(struct bgp *bgp, afi_t afi, else if (aggregate->egp_origin_count > 0) origin = BGP_ORIGIN_EGP; + if (aggregate->origin != BGP_ORIGIN_UNSPECIFIED) + origin = aggregate->origin; + if (aggregate->as_set) { /* Retrieve aggregate route's as-path. */ @@ -6660,6 +6669,19 @@ void bgp_aggregate_decrement(struct bgp *bgp, struct prefix *p, #define AGGREGATE_AS_SET 1 #define AGGREGATE_AS_UNSET 0 +static const char *bgp_origin2str(uint8_t origin) +{ + switch (origin) { + case BGP_ORIGIN_IGP: + return "igp"; + case BGP_ORIGIN_EGP: + return "egp"; + case BGP_ORIGIN_INCOMPLETE: + return "incomplete"; + } + return "n/a"; +} + static int bgp_aggregate_unset(struct vty *vty, const char *prefix_str, afi_t afi, safi_t safi) { @@ -6753,8 +6775,9 @@ static int bgp_aggregate_unset(struct vty *vty, const char *prefix_str, } static int bgp_aggregate_set(struct vty *vty, const char *prefix_str, afi_t afi, - safi_t safi, const char *rmap, uint8_t summary_only, - uint8_t as_set) + safi_t safi, const char *rmap, + uint8_t summary_only, uint8_t as_set, + uint8_t origin) { VTY_DECLVAR_CONTEXT(bgp, bgp); int ret; @@ -6818,6 +6841,12 @@ static int bgp_aggregate_set(struct vty *vty, const char *prefix_str, afi_t afi, aggregate->as_set = as_set_new; aggregate->safi = safi; + /* Override ORIGIN attribute if defined. + * E.g.: Cisco and Juniper set ORIGIN for aggregated address + * to IGP which is not what rfc4271 says. + * This enables the same behavior, optionally. + */ + aggregate->origin = origin; if (rmap) { XFREE(MTYPE_ROUTE_MAP_NAME, aggregate->rmap.name); @@ -6837,7 +6866,7 @@ static int bgp_aggregate_set(struct vty *vty, const char *prefix_str, afi_t afi, DEFUN (aggregate_address, aggregate_address_cmd, - "aggregate-address A.B.C.D/M [<as-set [summary-only]|summary-only [as-set]>] [route-map WORD]", + "aggregate-address A.B.C.D/M [<as-set [summary-only]|summary-only [as-set]>] [route-map WORD] [origin <egp|igp|incomplete>]", "Configure BGP aggregate entries\n" "Aggregate prefix\n" "Generate AS set path information\n" @@ -6845,12 +6874,17 @@ DEFUN (aggregate_address, "Filter more specific routes from updates\n" "Generate AS set path information\n" "Apply route map to aggregate network\n" - "Name of route map\n") + "Name of route map\n" + "BGP origin code\n" + "Remote EGP\n" + "Local IGP\n" + "Unknown heritage\n") { int idx = 0; argv_find(argv, argc, "A.B.C.D/M", &idx); char *prefix = argv[idx]->arg; char *rmap = NULL; + uint8_t origin = BGP_ORIGIN_UNSPECIFIED; int as_set = argv_find(argv, argc, "as-set", &idx) ? AGGREGATE_AS_SET : AGGREGATE_AS_UNSET; idx = 0; @@ -6863,13 +6897,23 @@ DEFUN (aggregate_address, if (idx) rmap = argv[idx]->arg; - return bgp_aggregate_set(vty, prefix, AFI_IP, bgp_node_safi(vty), - rmap, summary_only, as_set); + idx = 0; + if (argv_find(argv, argc, "origin", &idx)) { + if (strncmp(argv[idx + 1]->arg, "igp", 2) == 0) + origin = BGP_ORIGIN_IGP; + if (strncmp(argv[idx + 1]->arg, "egp", 1) == 0) + origin = BGP_ORIGIN_EGP; + if (strncmp(argv[idx + 1]->arg, "incomplete", 2) == 0) + origin = BGP_ORIGIN_INCOMPLETE; + } + + return bgp_aggregate_set(vty, prefix, AFI_IP, bgp_node_safi(vty), rmap, + summary_only, as_set, origin); } DEFUN (aggregate_address_mask, aggregate_address_mask_cmd, - "aggregate-address A.B.C.D A.B.C.D [<as-set [summary-only]|summary-only [as-set]>] [route-map WORD]", + "aggregate-address A.B.C.D A.B.C.D [<as-set [summary-only]|summary-only [as-set]>] [route-map WORD] [origin <egp|igp|incomplete>]", "Configure BGP aggregate entries\n" "Aggregate address\n" "Aggregate mask\n" @@ -6878,7 +6922,11 @@ DEFUN (aggregate_address_mask, "Filter more specific routes from updates\n" "Generate AS set path information\n" "Apply route map to aggregate network\n" - "Name of route map\n") + "Name of route map\n" + "BGP origin code\n" + "Remote EGP\n" + "Local IGP\n" + "Unknown heritage\n") { int idx = 0; argv_find(argv, argc, "A.B.C.D", &idx); @@ -6886,6 +6934,7 @@ DEFUN (aggregate_address_mask, char *mask = argv[idx + 1]->arg; bool rmap_found; char *rmap = NULL; + uint8_t origin = BGP_ORIGIN_UNSPECIFIED; int as_set = argv_find(argv, argc, "as-set", &idx) ? AGGREGATE_AS_SET : AGGREGATE_AS_UNSET; idx = 0; @@ -6905,13 +6954,23 @@ DEFUN (aggregate_address_mask, return CMD_WARNING_CONFIG_FAILED; } + idx = 0; + if (argv_find(argv, argc, "origin", &idx)) { + if (strncmp(argv[idx + 1]->arg, "igp", 2) == 0) + origin = BGP_ORIGIN_IGP; + if (strncmp(argv[idx + 1]->arg, "egp", 1) == 0) + origin = BGP_ORIGIN_EGP; + if (strncmp(argv[idx + 1]->arg, "incomplete", 2) == 0) + origin = BGP_ORIGIN_INCOMPLETE; + } + return bgp_aggregate_set(vty, prefix_str, AFI_IP, bgp_node_safi(vty), - rmap, summary_only, as_set); + rmap, summary_only, as_set, origin); } DEFUN (no_aggregate_address, no_aggregate_address_cmd, - "no aggregate-address A.B.C.D/M [<as-set [summary-only]|summary-only [as-set]>] [route-map WORD]", + "no aggregate-address A.B.C.D/M [<as-set [summary-only]|summary-only [as-set]>] [route-map WORD] [origin <egp|igp|incomplete>]", NO_STR "Configure BGP aggregate entries\n" "Aggregate prefix\n" @@ -6920,7 +6979,11 @@ DEFUN (no_aggregate_address, "Filter more specific routes from updates\n" "Generate AS set path information\n" "Apply route map to aggregate network\n" - "Name of route map\n") + "Name of route map\n" + "BGP origin code\n" + "Remote EGP\n" + "Local IGP\n" + "Unknown heritage\n") { int idx = 0; argv_find(argv, argc, "A.B.C.D/M", &idx); @@ -6930,7 +6993,7 @@ DEFUN (no_aggregate_address, DEFUN (no_aggregate_address_mask, no_aggregate_address_mask_cmd, - "no aggregate-address A.B.C.D A.B.C.D [<as-set [summary-only]|summary-only [as-set]>] [route-map WORD]", + "no aggregate-address A.B.C.D A.B.C.D [<as-set [summary-only]|summary-only [as-set]>] [route-map WORD] [origin <egp|igp|incomplete>]", NO_STR "Configure BGP aggregate entries\n" "Aggregate address\n" @@ -6940,7 +7003,11 @@ DEFUN (no_aggregate_address_mask, "Filter more specific routes from updates\n" "Generate AS set path information\n" "Apply route map to aggregate network\n" - "Name of route map\n") + "Name of route map\n" + "BGP origin code\n" + "Remote EGP\n" + "Local IGP\n" + "Unknown heritage\n") { int idx = 0; argv_find(argv, argc, "A.B.C.D", &idx); @@ -6960,7 +7027,7 @@ DEFUN (no_aggregate_address_mask, DEFUN (ipv6_aggregate_address, ipv6_aggregate_address_cmd, - "aggregate-address X:X::X:X/M [<as-set [summary-only]|summary-only [as-set]>] [route-map WORD]", + "aggregate-address X:X::X:X/M [<as-set [summary-only]|summary-only [as-set]>] [route-map WORD] [origin <egp|igp|incomplete>]", "Configure BGP aggregate entries\n" "Aggregate prefix\n" "Generate AS set path information\n" @@ -6968,13 +7035,18 @@ DEFUN (ipv6_aggregate_address, "Filter more specific routes from updates\n" "Generate AS set path information\n" "Apply route map to aggregate network\n" - "Name of route map\n") + "Name of route map\n" + "BGP origin code\n" + "Remote EGP\n" + "Local IGP\n" + "Unknown heritage\n") { int idx = 0; argv_find(argv, argc, "X:X::X:X/M", &idx); char *prefix = argv[idx]->arg; char *rmap = NULL; bool rmap_found; + uint8_t origin = BGP_ORIGIN_UNSPECIFIED; int as_set = argv_find(argv, argc, "as-set", &idx) ? AGGREGATE_AS_SET : AGGREGATE_AS_UNSET; @@ -6987,13 +7059,23 @@ DEFUN (ipv6_aggregate_address, if (rmap_found) rmap = argv[idx]->arg; + idx = 0; + if (argv_find(argv, argc, "origin", &idx)) { + if (strncmp(argv[idx + 1]->arg, "igp", 2) == 0) + origin = BGP_ORIGIN_IGP; + if (strncmp(argv[idx + 1]->arg, "egp", 1) == 0) + origin = BGP_ORIGIN_EGP; + if (strncmp(argv[idx + 1]->arg, "incomplete", 2) == 0) + origin = BGP_ORIGIN_INCOMPLETE; + } + return bgp_aggregate_set(vty, prefix, AFI_IP6, SAFI_UNICAST, rmap, - sum_only, as_set); + sum_only, as_set, origin); } DEFUN (no_ipv6_aggregate_address, no_ipv6_aggregate_address_cmd, - "no aggregate-address X:X::X:X/M [<as-set [summary-only]|summary-only [as-set]>] [route-map WORD]", + "no aggregate-address X:X::X:X/M [<as-set [summary-only]|summary-only [as-set]>] [route-map WORD] [origin <egp|igp|incomplete>]", NO_STR "Configure BGP aggregate entries\n" "Aggregate prefix\n" @@ -7002,7 +7084,11 @@ DEFUN (no_ipv6_aggregate_address, "Filter more specific routes from updates\n" "Generate AS set path information\n" "Apply route map to aggregate network\n" - "Name of route map\n") + "Name of route map\n" + "BGP origin code\n" + "Remote EGP\n" + "Local IGP\n" + "Unknown heritage\n") { int idx = 0; argv_find(argv, argc, "X:X::X:X/M", &idx); @@ -8867,8 +8953,13 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, } else { if (nexthop_vrfid == VRF_UNKNOWN) vty_out(vty, " vrf ?"); - else - vty_out(vty, " vrf %u", nexthop_vrfid); + else { + struct vrf *vrf; + + vrf = vrf_lookup_by_id(nexthop_vrfid); + vty_out(vty, " vrf %s(%u)", + VRF_LOGNAME(vrf), nexthop_vrfid); + } } } @@ -10336,32 +10427,20 @@ DEFUN (show_ip_bgp_large_community_list, "Exact match of the large-communities\n" JSON_STR) { - char *vrf = NULL; afi_t afi = AFI_IP6; safi_t safi = SAFI_UNICAST; int idx = 0; bool exact_match = 0; - - if (argv_find(argv, argc, "ip", &idx)) - afi = AFI_IP; - if (argv_find(argv, argc, "view", &idx) - || argv_find(argv, argc, "vrf", &idx)) - vrf = argv[++idx]->arg; - if (argv_find(argv, argc, "ipv4", &idx) - || argv_find(argv, argc, "ipv6", &idx)) { - afi = strmatch(argv[idx]->text, "ipv6") ? AFI_IP6 : AFI_IP; - if (argv_find(argv, argc, "unicast", &idx) - || argv_find(argv, argc, "multicast", &idx)) - safi = bgp_vty_safi_from_str(argv[idx]->text); - } - + struct bgp *bgp = NULL; bool uj = use_json(argc, argv); - struct bgp *bgp = bgp_lookup_by_name(vrf); - if (bgp == NULL) { - vty_out(vty, "Can't find BGP instance %s\n", vrf); - return CMD_WARNING; - } + if (uj) + argc--; + + bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi, + &bgp, uj); + if (!idx) + return CMD_WARNING; argv_find(argv, argc, "large-community-list", &idx); @@ -10387,32 +10466,20 @@ DEFUN (show_ip_bgp_large_community, "Exact match of the large-communities\n" JSON_STR) { - char *vrf = NULL; afi_t afi = AFI_IP6; safi_t safi = SAFI_UNICAST; int idx = 0; bool exact_match = 0; - - if (argv_find(argv, argc, "ip", &idx)) - afi = AFI_IP; - if (argv_find(argv, argc, "view", &idx) - || argv_find(argv, argc, "vrf", &idx)) - vrf = argv[++idx]->arg; - if (argv_find(argv, argc, "ipv4", &idx) - || argv_find(argv, argc, "ipv6", &idx)) { - afi = strmatch(argv[idx]->text, "ipv6") ? AFI_IP6 : AFI_IP; - if (argv_find(argv, argc, "unicast", &idx) - || argv_find(argv, argc, "multicast", &idx)) - safi = bgp_vty_safi_from_str(argv[idx]->text); - } - + struct bgp *bgp = NULL; bool uj = use_json(argc, argv); - struct bgp *bgp = bgp_lookup_by_name(vrf); - if (bgp == NULL) { - vty_out(vty, "Can't find BGP instance %s\n", vrf); - return CMD_WARNING; - } + if (uj) + argc--; + + bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi, + &bgp, uj); + if (!idx) + return CMD_WARNING; if (argv_find(argv, argc, "AA:BB:CC", &idx)) { if (argv_find(argv, argc, "exact-match", &idx)) @@ -12704,6 +12771,18 @@ static void show_bgp_peerhash_entry(struct hash_bucket *bucket, void *arg) sockunion2str(&peer->su, buf, sizeof(buf))); } +DEFUN (show_bgp_listeners, + show_bgp_listeners_cmd, + "show bgp listeners", + SHOW_STR + BGP_STR + "Display Listen Sockets and who created them\n") +{ + bgp_dump_listener_info(vty); + + return CMD_SUCCESS; +} + DEFUN (show_bgp_peerhash, show_bgp_peerhash_cmd, "show bgp peerhash", @@ -12916,6 +12995,10 @@ void bgp_config_write_network(struct vty *vty, struct bgp *bgp, afi_t afi, if (bgp_aggregate->rmap.name) vty_out(vty, " route-map %s", bgp_aggregate->rmap.name); + if (bgp_aggregate->origin != BGP_ORIGIN_UNSPECIFIED) + vty_out(vty, " origin %s", + bgp_origin2str(bgp_aggregate->origin)); + vty_out(vty, "\n"); } } @@ -13089,6 +13172,7 @@ void bgp_route_init(void) /* show bgp ipv4 flowspec detailed */ install_element(VIEW_NODE, &show_ip_bgp_flowspec_routes_detailed_cmd); + install_element(VIEW_NODE, &show_bgp_listeners_cmd); install_element(VIEW_NODE, &show_bgp_peerhash_cmd); } diff --git a/bgpd/bgp_route.h b/bgpd/bgp_route.h index 8f31cd38dc..0ad656d133 100644 --- a/bgpd/bgp_route.h +++ b/bgpd/bgp_route.h @@ -338,6 +338,9 @@ struct bgp_aggregate { /* Count of routes of origin type egp under this aggregate. */ unsigned long egp_origin_count; + /* Optional modify flag to override ORIGIN */ + uint8_t origin; + /* Hash containing the communities of all the * routes under this aggregate. */ diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index 5e6c782400..52b5402737 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -4400,10 +4400,10 @@ DEFUN (no_set_distance, DEFUN (set_local_pref, set_local_pref_cmd, - "set local-preference (0-4294967295)", + "set local-preference WORD", SET_STR "BGP local preference path attribute\n" - "Preference value\n") + "Preference value (0-4294967295)\n") { int idx_number = 2; return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), @@ -4413,11 +4413,11 @@ DEFUN (set_local_pref, DEFUN (no_set_local_pref, no_set_local_pref_cmd, - "no set local-preference [(0-4294967295)]", + "no set local-preference [WORD]", NO_STR SET_STR "BGP local preference path attribute\n" - "Preference value\n") + "Preference value (0-4294967295)\n") { int idx_localpref = 3; if (argc <= idx_localpref) diff --git a/bgpd/bgp_rpki.c b/bgpd/bgp_rpki.c index 2ca0c7b96d..ee1c49666b 100644 --- a/bgpd/bgp_rpki.c +++ b/bgpd/bgp_rpki.c @@ -94,6 +94,7 @@ enum return_values { SUCCESS = 0, ERROR = -1 }; struct rpki_for_each_record_arg { struct vty *vty; unsigned int *prefix_amount; + as_t as; }; static int start(void); @@ -273,6 +274,17 @@ static void print_record(const struct pfx_record *record, struct vty *vty) record->max_len, record->asn); } +static void print_record_by_asn(const struct pfx_record *record, void *data) +{ + struct rpki_for_each_record_arg *arg = data; + struct vty *vty = arg->vty; + + if (record->asn == arg->as) { + (*arg->prefix_amount)++; + print_record(record, vty); + } +} + static void print_record_cb(const struct pfx_record *record, void *data) { struct rpki_for_each_record_arg *arg = data; @@ -621,6 +633,36 @@ static struct rtr_mgr_group *get_connected_group(void) return rtr_mgr_get_first_group(rtr_config); } +static void print_prefix_table_by_asn(struct vty *vty, as_t as) +{ + unsigned int number_of_ipv4_prefixes = 0; + unsigned int number_of_ipv6_prefixes = 0; + struct rtr_mgr_group *group = get_connected_group(); + struct rpki_for_each_record_arg arg; + + arg.vty = vty; + arg.as = as; + + if (!group) { + vty_out(vty, "Cannot find a connected group.\n"); + return; + } + + struct pfx_table *pfx_table = group->sockets[0]->pfx_table; + + vty_out(vty, "RPKI/RTR prefix table\n"); + vty_out(vty, "%-40s %s %s\n", "Prefix", "Prefix Length", "Origin-AS"); + + arg.prefix_amount = &number_of_ipv4_prefixes; + pfx_table_for_each_ipv4_record(pfx_table, print_record_by_asn, &arg); + + arg.prefix_amount = &number_of_ipv6_prefixes; + pfx_table_for_each_ipv6_record(pfx_table, print_record_by_asn, &arg); + + vty_out(vty, "Number of IPv4 Prefixes: %u\n", number_of_ipv4_prefixes); + vty_out(vty, "Number of IPv6 Prefixes: %u\n", number_of_ipv6_prefixes); +} + static void print_prefix_table(struct vty *vty) { struct rpki_for_each_record_arg arg; @@ -1190,6 +1232,21 @@ DEFUN (show_rpki_prefix_table, return CMD_SUCCESS; } +DEFPY(show_rpki_as_number, show_rpki_as_number_cmd, + "show rpki as-number (1-4294967295)$by_asn", + SHOW_STR RPKI_OUTPUT_STRING + "Lookup by ASN in prefix table\n" + "AS Number\n") +{ + if (!is_synchronized()) { + vty_out(vty, "No Connection to RPKI cache server.\n"); + return CMD_WARNING; + } + + print_prefix_table_by_asn(vty, by_asn); + return CMD_SUCCESS; +} + DEFPY (show_rpki_prefix, show_rpki_prefix_cmd, "show rpki prefix <A.B.C.D/M|X:X::X:X/M> [(1-4294967295)$asn]", @@ -1523,6 +1580,7 @@ static void install_cli_commands(void) install_element(VIEW_NODE, &show_rpki_cache_connection_cmd); install_element(VIEW_NODE, &show_rpki_cache_server_cmd); install_element(VIEW_NODE, &show_rpki_prefix_cmd); + install_element(VIEW_NODE, &show_rpki_as_number_cmd); /* Install debug commands */ install_element(CONFIG_NODE, &debug_rpki_cmd); diff --git a/bgpd/bgp_snmp.c b/bgpd/bgp_snmp.c index 70e4a3fa00..d507161052 100644 --- a/bgpd/bgp_snmp.c +++ b/bgpd/bgp_snmp.c @@ -869,7 +869,7 @@ static int bgpTrapEstablished(struct peer *peer) smux_trap(bgp_variables, array_size(bgp_variables), bgp_trap_oid, array_size(bgp_trap_oid), bgp_oid, - sizeof bgp_oid / sizeof(oid), index, IN_ADDR_SIZE, + sizeof(bgp_oid) / sizeof(oid), index, IN_ADDR_SIZE, bgpTrapList, array_size(bgpTrapList), BGPESTABLISHED); return 0; } @@ -888,7 +888,7 @@ static int bgpTrapBackwardTransition(struct peer *peer) smux_trap(bgp_variables, array_size(bgp_variables), bgp_trap_oid, array_size(bgp_trap_oid), bgp_oid, - sizeof bgp_oid / sizeof(oid), index, IN_ADDR_SIZE, + sizeof(bgp_oid) / sizeof(oid), index, IN_ADDR_SIZE, bgpTrapList, array_size(bgpTrapList), BGPBACKWARDTRANSITION); return 0; } diff --git a/bgpd/bgp_updgrp_packet.c b/bgpd/bgp_updgrp_packet.c index 89199d05cb..4dc9dfa39a 100644 --- a/bgpd/bgp_updgrp_packet.c +++ b/bgpd/bgp_updgrp_packet.c @@ -330,8 +330,6 @@ void bpacket_queue_remove_peer(struct peer_af *paf) q = PAF_PKTQ(paf); assert(q); - if (!q) - return; LIST_REMOVE(paf, pkt_train); paf->next_pkt_to_send = NULL; diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index f18f9ccf4b..8c751e4f19 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -753,7 +753,7 @@ static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi, } static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi, - struct listnode *nnode, enum bgp_clear_type stype) + struct listnode **nnode, enum bgp_clear_type stype) { int ret = 0; @@ -767,7 +767,7 @@ static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi, continue; if (stype == BGP_CLEAR_SOFT_NONE) - ret = peer_clear(peer, &nnode); + ret = peer_clear(peer, nnode); else ret = peer_clear_soft(peer, tmp_afi, tmp_safi, stype); @@ -782,7 +782,7 @@ static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi, continue; if (stype == BGP_CLEAR_SOFT_NONE) - ret = peer_clear(peer, &nnode); + ret = peer_clear(peer, nnode); else ret = peer_clear_soft(peer, afi, tmp_safi, stype); @@ -793,7 +793,7 @@ static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi, return 1; if (stype == BGP_CLEAR_SOFT_NONE) - ret = peer_clear(peer, &nnode); + ret = peer_clear(peer, nnode); else ret = peer_clear_soft(peer, afi, safi, stype); } @@ -826,7 +826,7 @@ static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART)) gr_router_detected = true; - ret = bgp_peer_clear(peer, afi, safi, nnode, + ret = bgp_peer_clear(peer, afi, safi, &nnode, stype); if (ret < 0) @@ -901,7 +901,7 @@ static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, } for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) { - ret = bgp_peer_clear(peer, afi, safi, nnode, stype); + ret = bgp_peer_clear(peer, afi, safi, &nnode, stype); if (ret < 0) bgp_clear_vty_error(vty, peer, afi, safi, ret); @@ -928,7 +928,7 @@ static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART)) gr_router_detected = true; - ret = bgp_peer_clear(peer, afi, safi, nnode, stype); + ret = bgp_peer_clear(peer, afi, safi, &nnode, stype); if (ret < 0) bgp_clear_vty_error(vty, peer, afi, safi, ret); @@ -965,7 +965,7 @@ static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART)) gr_router_detected = true; - ret = bgp_peer_clear(peer, afi, safi, nnode, stype); + ret = bgp_peer_clear(peer, afi, safi, &nnode, stype); if (ret < 0) bgp_clear_vty_error(vty, peer, afi, safi, ret); @@ -7304,7 +7304,7 @@ ALIAS (af_label_vpn_export, DEFPY (af_nexthop_vpn_export, af_nexthop_vpn_export_cmd, - "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str", + "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]", NO_STR "Specify next hop to use for VRF advertised prefixes\n" "Between current address-family and vpn\n" @@ -7315,14 +7315,14 @@ DEFPY (af_nexthop_vpn_export, VTY_DECLVAR_CONTEXT(bgp, bgp); afi_t afi; struct prefix p; - int idx = 0; - int yes = 1; - if (argv_find(argv, argc, "no", &idx)) - yes = 0; + if (!no) { + if (!nexthop_su) { + vty_out(vty, "%% Nexthop required\n"); + return CMD_WARNING_CONFIG_FAILED; + } - if (yes) { - if (!sockunion2hostprefix(nexthop_str, &p)) + if (!sockunion2hostprefix(nexthop_su, &p)) return CMD_WARNING_CONFIG_FAILED; } @@ -7336,7 +7336,7 @@ DEFPY (af_nexthop_vpn_export, vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi, bgp_get_default(), bgp); - if (yes) { + if (!no) { bgp->vpn_policy[afi].tovpn_nexthop = p; SET_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_NEXTHOP_SET); @@ -7352,14 +7352,6 @@ DEFPY (af_nexthop_vpn_export, return CMD_SUCCESS; } -ALIAS (af_nexthop_vpn_export, - af_no_nexthop_vpn_export_cmd, - "no nexthop vpn export", - NO_STR - "Specify next hop to use for VRF advertised prefixes\n" - "Between current address-family and vpn\n" - "For routes leaked from current address-family to vpn\n") - static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir) { if (!strcmp(dstr, "import")) { @@ -9440,19 +9432,19 @@ static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty, bool use_json, json_object *json) { - bool rbit_status = 0; + bool rbit_status = false; if (!use_json) - vty_out(vty, "\n R bit : "); + vty_out(vty, "\n R bit: "); if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) && (p->status == Established)) { if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV)) - rbit_status = 1; + rbit_status = true; else - rbit_status = 0; + rbit_status = false; } if (rbit_status) { @@ -9476,7 +9468,7 @@ static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty, const char *mode = "NotApplicable"; if (!use_json) - vty_out(vty, "\n Remote GR Mode : "); + vty_out(vty, "\n Remote GR Mode: "); if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) && (peer->status == Established)) { @@ -9512,7 +9504,7 @@ static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty, const char *mode = "Invalid"; if (!use_json) - vty_out(vty, " Local GR Mode : "); + vty_out(vty, " Local GR Mode: "); if (bgp_peer_gr_mode_get(p) == PEER_HELPER) mode = "Helper"; @@ -9570,10 +9562,10 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi( eor_flag = false; if (!use_json) { - vty_out(vty, " %s :\n", + vty_out(vty, " %s:\n", get_afi_safi_str(afi, safi, false)); - vty_out(vty, " F bit : "); + vty_out(vty, " F bit: "); } if (peer->nsf[afi][safi] @@ -9594,27 +9586,7 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi( } if (!use_json) - vty_out(vty, " End-of-RIB Received : "); - - if (CHECK_FLAG(peer->af_sflags[afi][safi], - PEER_STATUS_EOR_RECEIVED)) { - if (use_json) - json_object_boolean_true_add( - json_endofrib_status, - "endOfRibRecv"); - else - vty_out(vty, "Yes\n"); - } else { - if (use_json) - json_object_boolean_false_add( - json_endofrib_status, - "endOfRibRecv"); - else - vty_out(vty, "No\n"); - } - - if (!use_json) - vty_out(vty, " End-of-RIB Send : "); + vty_out(vty, " End-of-RIB sent: "); if (CHECK_FLAG(peer->af_sflags[afi][safi], PEER_STATUS_EOR_SEND)) { @@ -9627,7 +9599,7 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi( } else { vty_out(vty, "Yes\n"); vty_out(vty, - " EoRSentAfterUpdate : "); + " End-of-RIB sent after update: "); PRINT_EOR(eor_flag); } @@ -9642,11 +9614,31 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi( } else { vty_out(vty, "No\n"); vty_out(vty, - " EoRSentAfterUpdate : "); + " End-of-RIB sent after update: "); vty_out(vty, "No\n"); } } + if (!use_json) + vty_out(vty, " End-of-RIB received: "); + + if (CHECK_FLAG(peer->af_sflags[afi][safi], + PEER_STATUS_EOR_RECEIVED)) { + if (use_json) + json_object_boolean_true_add( + json_endofrib_status, + "endOfRibRecv"); + else + vty_out(vty, "Yes\n"); + } else { + if (use_json) + json_object_boolean_false_add( + json_endofrib_status, + "endOfRibRecv"); + else + vty_out(vty, "No\n"); + } + if (use_json) { json_object_int_add(json_timer, "stalePathTimer", @@ -9686,46 +9678,36 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi( .t_select_deferral)); } } else { - vty_out(vty, " Timers:\n"); - - vty_out(vty, "%*s", 6, ""); + vty_out(vty, " Timers:\n"); vty_out(vty, - "Configured Stale Path Time(sec)%*s: %u\n", - 8, "", peer->bgp->stalepath_time); + " Configured Stale Path Time(sec): %u\n", + peer->bgp->stalepath_time); - if (peer->t_gr_stale != NULL) { - vty_out(vty, "%*s", 6, ""); + if (peer->t_gr_stale != NULL) vty_out(vty, - "Stale Path Remaining(sec)%*s: %ld\n", - 14, "", + " Stale Path Remaining(sec): %ld\n", thread_timer_remain_second( peer->t_gr_stale)); - } /* Display Configured Selection * Deferral only when when * Gr mode is enabled. */ if (CHECK_FLAG(peer->flags, - PEER_FLAG_GRACEFUL_RESTART)) { - vty_out(vty, "%*s", 6, ""); + PEER_FLAG_GRACEFUL_RESTART)) vty_out(vty, - "Configured Selection Deferral Time(sec): %u\n", + " Configured Selection Deferral Time(sec): %u\n", peer->bgp->select_defer_time); - } if (peer->bgp->gr_info[afi][safi] .t_select_deferral - != NULL) { - - vty_out(vty, "%*s", 6, ""); + != NULL) vty_out(vty, - "Selection Deferral Time Remaining(sec) : %ld\n", + " Selection Deferral Time Remaining(sec): %ld\n", thread_timer_remain_second( peer->bgp ->gr_info[afi] [safi] .t_select_deferral)); - } } if (use_json) { json_object_object_add(json_afi_safi, @@ -9765,19 +9747,17 @@ static void bgp_show_neighbor_graceful_restart_time(struct vty *vty, json_object_object_add(json, "timers", json_timer); } else { - vty_out(vty, " Timers :\n"); - vty_out(vty, " Configured Restart Time(sec) : %u\n", + vty_out(vty, " Timers:\n"); + vty_out(vty, " Configured Restart Time(sec): %u\n", p->bgp->restart_time); - vty_out(vty, " Received Restart Time(sec) : %u\n", + vty_out(vty, " Received Restart Time(sec): %u\n", p->v_gr_restart); if (p->t_gr_restart != NULL) - vty_out(vty, - " Restart Time Remaining(sec) : %ld\n", + vty_out(vty, " Restart Time Remaining(sec): %ld\n", thread_timer_remain_second(p->t_gr_restart)); if (p->t_gr_restart != NULL) { - vty_out(vty, - " Restart Time Remaining(sec) : %ld\n", + vty_out(vty, " Restart Time Remaining(sec): %ld\n", thread_timer_remain_second(p->t_gr_restart)); } } @@ -10669,28 +10649,31 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, /* read timer */ time_t uptime; - struct tm *tm; + struct tm tm; uptime = bgp_clock(); uptime -= p->readtime; - tm = gmtime(&uptime); + gmtime_r(&uptime, &tm); + json_object_int_add(json_neigh, "bgpTimerLastRead", - (tm->tm_sec * 1000) + (tm->tm_min * 60000) - + (tm->tm_hour * 3600000)); + (tm.tm_sec * 1000) + (tm.tm_min * 60000) + + (tm.tm_hour * 3600000)); uptime = bgp_clock(); uptime -= p->last_write; - tm = gmtime(&uptime); + gmtime_r(&uptime, &tm); + json_object_int_add(json_neigh, "bgpTimerLastWrite", - (tm->tm_sec * 1000) + (tm->tm_min * 60000) - + (tm->tm_hour * 3600000)); + (tm.tm_sec * 1000) + (tm.tm_min * 60000) + + (tm.tm_hour * 3600000)); uptime = bgp_clock(); uptime -= p->update_time; - tm = gmtime(&uptime); + gmtime_r(&uptime, &tm); + json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs", - (tm->tm_sec * 1000) + (tm->tm_min * 60000) - + (tm->tm_hour * 3600000)); + (tm.tm_sec * 1000) + (tm.tm_min * 60000) + + (tm.tm_hour * 3600000)); /* Configured timer values. */ json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs", @@ -11518,12 +11501,12 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, vty_out(vty, "\n"); - /* Gracefull Restart */ + /* Graceful Restart */ if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) { vty_out(vty, - " Graceful Restart Capabilty:"); + " Graceful Restart Capability:"); if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)) vty_out(vty, " advertised"); @@ -11644,7 +11627,7 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, json_object_object_add( json_neigh, "gracefulRestartInfo", json_grace); } else { - vty_out(vty, " Graceful restart informations:\n"); + vty_out(vty, " Graceful restart information:\n"); if ((p->status == Established) && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) { @@ -11853,15 +11836,16 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, } else { if (use_json) { time_t uptime; - struct tm *tm; + struct tm tm; uptime = bgp_clock(); uptime -= p->resettime; - tm = gmtime(&uptime); + gmtime_r(&uptime, &tm); + json_object_int_add(json_neigh, "lastResetTimerMsecs", - (tm->tm_sec * 1000) - + (tm->tm_min * 60000) - + (tm->tm_hour * 3600000)); + (tm.tm_sec * 1000) + + (tm.tm_min * 60000) + + (tm.tm_hour * 3600000)); bgp_show_peer_reset(NULL, p, json_neigh, true); } else { vty_out(vty, " Last reset %s, ", @@ -16621,8 +16605,6 @@ void bgp_vty_init(void) install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd); install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd); install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd); - install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd); - install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd); install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd); install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd); install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd); diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index bb718c355f..f3ab608492 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -72,8 +72,9 @@ static inline int bgp_install_info_to_zebra(struct bgp *bgp) return 0; if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp)) { - zlog_debug("%s: No zebra instance to talk to, not installing information", - __PRETTY_FUNCTION__); + zlog_debug( + "%s: No zebra instance to talk to, not installing information", + __func__); return 0; } @@ -1918,8 +1919,9 @@ int bgp_zebra_advertise_subnet(struct bgp *bgp, int advertise, vni_t vni) /* Don't try to register if Zebra doesn't know of this instance. */ if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp)) { if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("%s: No zebra instance to talk to, cannot advertise subnet", - __PRETTY_FUNCTION__); + zlog_debug( + "%s: No zebra instance to talk to, cannot advertise subnet", + __func__); return 0; } @@ -1968,8 +1970,9 @@ int bgp_zebra_advertise_gw_macip(struct bgp *bgp, int advertise, vni_t vni) /* Don't try to register if Zebra doesn't know of this instance. */ if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp)) { if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("%s: No zebra instance to talk to, not installing gw_macip", - __PRETTY_FUNCTION__); + zlog_debug( + "%s: No zebra instance to talk to, not installing gw_macip", + __func__); return 0; } @@ -1996,8 +1999,9 @@ int bgp_zebra_vxlan_flood_control(struct bgp *bgp, /* Don't try to register if Zebra doesn't know of this instance. */ if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp)) { if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("%s: No zebra instance to talk to, not installing all vni", - __PRETTY_FUNCTION__); + zlog_debug( + "%s: No zebra instance to talk to, not installing all vni", + __func__); return 0; } @@ -2092,7 +2096,7 @@ static int rule_notify_owner(ZAPI_CALLBACK_ARGS) if (!bgp_pbr && note != ZAPI_RULE_REMOVED) { if (BGP_DEBUG(zebra, ZEBRA)) zlog_debug("%s: Fail to look BGP rule (%u)", - __PRETTY_FUNCTION__, unique); + __func__, unique); return 0; } } @@ -2100,8 +2104,7 @@ static int rule_notify_owner(ZAPI_CALLBACK_ARGS) switch (note) { case ZAPI_RULE_FAIL_INSTALL: if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("%s: Received RULE_FAIL_INSTALL", - __PRETTY_FUNCTION__); + zlog_debug("%s: Received RULE_FAIL_INSTALL", __func__); if (bgp_pbra) { bgp_pbra->installed = false; bgp_pbra->install_in_progress = false; @@ -2128,14 +2131,12 @@ static int rule_notify_owner(ZAPI_CALLBACK_ARGS) bgp_pbr); } if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("%s: Received RULE_INSTALLED", - __PRETTY_FUNCTION__); + zlog_debug("%s: Received RULE_INSTALLED", __func__); break; case ZAPI_RULE_FAIL_REMOVE: case ZAPI_RULE_REMOVED: if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("%s: Received RULE REMOVED", - __PRETTY_FUNCTION__); + zlog_debug("%s: Received RULE REMOVED", __func__); break; } @@ -2157,15 +2158,14 @@ static int ipset_notify_owner(ZAPI_CALLBACK_ARGS) if (!bgp_pbim) { if (BGP_DEBUG(zebra, ZEBRA)) zlog_debug("%s: Fail to look BGP match ( %u, ID %u)", - __PRETTY_FUNCTION__, note, unique); + __func__, note, unique); return 0; } switch (note) { case ZAPI_IPSET_FAIL_INSTALL: if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("%s: Received IPSET_FAIL_INSTALL", - __PRETTY_FUNCTION__); + zlog_debug("%s: Received IPSET_FAIL_INSTALL", __func__); bgp_pbim->installed = false; bgp_pbim->install_in_progress = false; break; @@ -2173,14 +2173,12 @@ static int ipset_notify_owner(ZAPI_CALLBACK_ARGS) bgp_pbim->installed = true; bgp_pbim->install_in_progress = false; if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("%s: Received IPSET_INSTALLED", - __PRETTY_FUNCTION__); + zlog_debug("%s: Received IPSET_INSTALLED", __func__); break; case ZAPI_IPSET_FAIL_REMOVE: case ZAPI_IPSET_REMOVED: if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("%s: Received IPSET REMOVED", - __PRETTY_FUNCTION__); + zlog_debug("%s: Received IPSET REMOVED", __func__); break; } @@ -2205,8 +2203,9 @@ static int ipset_entry_notify_owner(ZAPI_CALLBACK_ARGS) unique); if (!bgp_pbime) { if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("%s: Fail to look BGP match entry (%u, ID %u)", - __PRETTY_FUNCTION__, note, unique); + zlog_debug( + "%s: Fail to look BGP match entry (%u, ID %u)", + __func__, note, unique); return 0; } @@ -2214,7 +2213,7 @@ static int ipset_entry_notify_owner(ZAPI_CALLBACK_ARGS) case ZAPI_IPSET_ENTRY_FAIL_INSTALL: if (BGP_DEBUG(zebra, ZEBRA)) zlog_debug("%s: Received IPSET_ENTRY_FAIL_INSTALL", - __PRETTY_FUNCTION__); + __func__); bgp_pbime->installed = false; bgp_pbime->install_in_progress = false; break; @@ -2227,7 +2226,7 @@ static int ipset_entry_notify_owner(ZAPI_CALLBACK_ARGS) bgp_pbime->install_in_progress = false; if (BGP_DEBUG(zebra, ZEBRA)) zlog_debug("%s: Received IPSET_ENTRY_INSTALLED", - __PRETTY_FUNCTION__); + __func__); /* link bgp_path_info to bpme */ path = (struct bgp_path_info *)bgp_pbime->path; extra = bgp_path_info_extra_get(path); @@ -2238,7 +2237,7 @@ static int ipset_entry_notify_owner(ZAPI_CALLBACK_ARGS) case ZAPI_IPSET_ENTRY_REMOVED: if (BGP_DEBUG(zebra, ZEBRA)) zlog_debug("%s: Received IPSET_ENTRY_REMOVED", - __PRETTY_FUNCTION__); + __func__); break; } return 0; @@ -2259,14 +2258,14 @@ static int iptable_notify_owner(ZAPI_CALLBACK_ARGS) if (!bgpm) { if (BGP_DEBUG(zebra, ZEBRA)) zlog_debug("%s: Fail to look BGP iptable (%u %u)", - __PRETTY_FUNCTION__, note, unique); + __func__, note, unique); return 0; } switch (note) { case ZAPI_IPTABLE_FAIL_INSTALL: if (BGP_DEBUG(zebra, ZEBRA)) zlog_debug("%s: Received IPTABLE_FAIL_INSTALL", - __PRETTY_FUNCTION__); + __func__); bgpm->installed_in_iptable = false; bgpm->install_iptable_in_progress = false; break; @@ -2274,15 +2273,13 @@ static int iptable_notify_owner(ZAPI_CALLBACK_ARGS) bgpm->installed_in_iptable = true; bgpm->install_iptable_in_progress = false; if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("%s: Received IPTABLE_INSTALLED", - __PRETTY_FUNCTION__); + zlog_debug("%s: Received IPTABLE_INSTALLED", __func__); bgpm->action->refcnt++; break; case ZAPI_IPTABLE_FAIL_REMOVE: case ZAPI_IPTABLE_REMOVED: if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("%s: Received IPTABLE REMOVED", - __PRETTY_FUNCTION__); + zlog_debug("%s: Received IPTABLE REMOVED", __func__); break; } return 0; @@ -2786,12 +2783,10 @@ void bgp_send_pbr_rule_action(struct bgp_pbr_action *pbra, return; if (BGP_DEBUG(zebra, ZEBRA)) { if (pbr) - zlog_debug("%s: table %d (ip rule) %d", - __PRETTY_FUNCTION__, + zlog_debug("%s: table %d (ip rule) %d", __func__, pbra->table_id, install); else - zlog_debug("%s: table %d fwmark %d %d", - __PRETTY_FUNCTION__, + zlog_debug("%s: table %d fwmark %d %d", __func__, pbra->table_id, pbra->fwmark, install); } s = zclient->obuf; @@ -2820,10 +2815,9 @@ void bgp_send_pbr_ipset_match(struct bgp_pbr_match *pbrim, bool install) if (pbrim->install_in_progress) return; if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("%s: name %s type %d %d, ID %u", - __PRETTY_FUNCTION__, - pbrim->ipset_name, pbrim->type, - install, pbrim->unique); + zlog_debug("%s: name %s type %d %d, ID %u", __func__, + pbrim->ipset_name, pbrim->type, install, + pbrim->unique); s = zclient->obuf; stream_reset(s); @@ -2849,9 +2843,9 @@ void bgp_send_pbr_ipset_entry_match(struct bgp_pbr_match_entry *pbrime, if (pbrime->install_in_progress) return; if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("%s: name %s %d %d, ID %u", __PRETTY_FUNCTION__, - pbrime->backpointer->ipset_name, - pbrime->unique, install, pbrime->unique); + zlog_debug("%s: name %s %d %d, ID %u", __func__, + pbrime->backpointer->ipset_name, pbrime->unique, + install, pbrime->unique); s = zclient->obuf; stream_reset(s); @@ -2916,9 +2910,8 @@ void bgp_send_pbr_iptable(struct bgp_pbr_action *pba, if (pbm->install_iptable_in_progress) return; if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("%s: name %s type %d mark %d %d, ID %u", - __PRETTY_FUNCTION__, pbm->ipset_name, - pbm->type, pba->fwmark, install, + zlog_debug("%s: name %s type %d mark %d %d, ID %u", __func__, + pbm->ipset_name, pbm->type, pba->fwmark, install, pbm->unique2); s = zclient->obuf; stream_reset(s); diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 5cbf46fe0e..267d67e46e 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -284,8 +284,11 @@ void bgp_router_id_zebra_bump(vrf_id_t vrf_id, const struct prefix *router_id) */ if (bgp->established_peers == 0) { if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("RID change : vrf %u, RTR ID %s", - bgp->vrf_id, inet_ntoa(*addr)); + zlog_debug( + "RID change : vrf %s(%u), RTR ID %s", + bgp->name_pretty, + bgp->vrf_id, + inet_ntoa(*addr)); bgp_router_id_set(bgp, addr, false); } } @@ -304,8 +307,11 @@ void bgp_router_id_zebra_bump(vrf_id_t vrf_id, const struct prefix *router_id) */ if (bgp->established_peers == 0) { if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("RID change : vrf %u, RTR ID %s", - bgp->vrf_id, inet_ntoa(*addr)); + zlog_debug( + "RID change : vrf %s(%u), RTR ID %s", + bgp->name_pretty, + bgp->vrf_id, + inet_ntoa(*addr)); bgp_router_id_set(bgp, addr, false); } } @@ -1194,8 +1200,6 @@ struct peer *peer_new(struct bgp *bgp) /* bgp argument is absolutely required */ assert(bgp); - if (!bgp) - return NULL; /* Allocate new peer. */ peer = XCALLOC(MTYPE_BGP_PEER, sizeof(struct peer)); @@ -2098,8 +2102,8 @@ static int non_peergroup_deactivate_af(struct peer *peer, afi_t afi, if (peer_af_delete(peer, afi, safi) != 0) { flog_err(EC_BGP_PEER_DELETE, - "couldn't delete af structure for peer %s", - peer->host); + "couldn't delete af structure for peer %s(%s, %s)", + peer->host, afi2str(afi), safi2str(safi)); return 1; } @@ -2148,9 +2152,10 @@ int peer_deactivate(struct peer *peer, afi_t afi, safi_t safi) group = peer->group; if (peer_af_delete(peer, afi, safi) != 0) { - flog_err(EC_BGP_PEER_DELETE, - "couldn't delete af structure for peer %s", - peer->host); + flog_err( + EC_BGP_PEER_DELETE, + "couldn't delete af structure for peer %s(%s, %s)", + peer->host, afi2str(afi), safi2str(safi)); } for (ALL_LIST_ELEMENTS(group->peer, node, nnode, tmp_peer)) { @@ -3142,7 +3147,7 @@ int bgp_handle_socket(struct bgp *bgp, struct vrf *vrf, vrf_id_t old_vrf_id, /* * suppress vrf socket */ - if (create == false) { + if (!create) { bgp_close_vrf_socket(bgp); return 0; } @@ -3222,7 +3227,7 @@ int bgp_get(struct bgp **bgp_val, as_t *as, const char *name, if (IS_BGP_INST_KNOWN_TO_ZEBRA(bgp)) { if (BGP_DEBUG(zebra, ZEBRA)) zlog_debug("%s: Registering BGP instance %s to zebra", - __PRETTY_FUNCTION__, name); + __func__, name); bgp_zebra_instance_register(bgp); } @@ -3394,8 +3399,9 @@ int bgp_delete(struct bgp *bgp) /* Deregister from Zebra, if needed */ if (IS_BGP_INST_KNOWN_TO_ZEBRA(bgp)) { if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("%s: deregistering this bgp %s instance from zebra", - __PRETTY_FUNCTION__, bgp->name); + zlog_debug( + "%s: deregistering this bgp %s instance from zebra", + __func__, bgp->name); bgp_zebra_instance_deregister(bgp); } @@ -4026,7 +4032,7 @@ static int peer_flag_modify(struct peer *peer, uint32_t flag, int set) struct peer_flag_action action; memset(&action, 0, sizeof(struct peer_flag_action)); - size = sizeof peer_flag_action_list / sizeof(struct peer_flag_action); + size = sizeof(peer_flag_action_list) / sizeof(struct peer_flag_action); invert = CHECK_FLAG(peer->flags_invert, flag); found = peer_flag_action_set(peer_flag_action_list, size, &action, @@ -4065,6 +4071,9 @@ static int peer_flag_modify(struct peer *peer, uint32_t flag, int set) /* Update flag override state accordingly. */ COND_FLAG(peer->flags_override, flag, set != invert); + if (set && flag == PEER_FLAG_CAPABILITY_ENHE) + bgp_nht_register_enhe_capability_interfaces(peer); + /* Execute flag action on peer. */ if (action.type == peer_change_reset) peer_flag_modify_action(peer, flag); @@ -4073,9 +4082,6 @@ static int peer_flag_modify(struct peer *peer, uint32_t flag, int set) return 0; } - if (set && flag == PEER_FLAG_CAPABILITY_ENHE) - bgp_nht_register_enhe_capability_interfaces(peer); - /* * Update peer-group members, unless they are explicitely overriding * peer-group configuration. @@ -4132,7 +4138,7 @@ static int peer_af_flag_modify(struct peer *peer, afi_t afi, safi_t safi, bgp_peer_sort_t ptype; memset(&action, 0, sizeof(struct peer_flag_action)); - size = sizeof peer_af_flag_action_list + size = sizeof(peer_af_flag_action_list) / sizeof(struct peer_flag_action); invert = CHECK_FLAG(peer->af_flags_invert[afi][safi], flag); @@ -6842,7 +6848,7 @@ char *peer_uptime(time_t uptime2, char *buf, size_t len, bool use_json, json_object *json) { time_t uptime1, epoch_tbuf; - struct tm *tm; + struct tm tm; /* If there is no connection has been done before print `never'. */ if (uptime2 == 0) { @@ -6857,21 +6863,21 @@ char *peer_uptime(time_t uptime2, char *buf, size_t len, bool use_json, /* Get current time. */ uptime1 = bgp_clock(); uptime1 -= uptime2; - tm = gmtime(&uptime1); + gmtime_r(&uptime1, &tm); if (uptime1 < ONE_DAY_SECOND) - snprintf(buf, len, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, - tm->tm_sec); + snprintf(buf, len, "%02d:%02d:%02d", tm.tm_hour, tm.tm_min, + tm.tm_sec); else if (uptime1 < ONE_WEEK_SECOND) - snprintf(buf, len, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour, - tm->tm_min); + snprintf(buf, len, "%dd%02dh%02dm", tm.tm_yday, tm.tm_hour, + tm.tm_min); else if (uptime1 < ONE_YEAR_SECOND) - snprintf(buf, len, "%02dw%dd%02dh", tm->tm_yday / 7, - tm->tm_yday - ((tm->tm_yday / 7) * 7), tm->tm_hour); + snprintf(buf, len, "%02dw%dd%02dh", tm.tm_yday / 7, + tm.tm_yday - ((tm.tm_yday / 7) * 7), tm.tm_hour); else - snprintf(buf, len, "%02dy%02dw%dd", tm->tm_year - 70, - tm->tm_yday / 7, - tm->tm_yday - ((tm->tm_yday / 7) * 7)); + snprintf(buf, len, "%02dy%02dw%dd", tm.tm_year - 70, + tm.tm_yday / 7, + tm.tm_yday - ((tm.tm_yday / 7) * 7)); if (use_json) { epoch_tbuf = time(NULL) - uptime1; diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index 40bf9bcd23..769ac32653 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -555,7 +555,7 @@ struct bgp { struct bgp_addpath_bgp_data tx_addpath; -#if ENABLE_BGP_VNC +#ifdef ENABLE_BGP_VNC struct rfapi_cfg *rfapi_cfg; struct rfapi *rfapi; #endif @@ -1281,9 +1281,7 @@ struct peer { * - This does *not* contain the filter values, rather it contains * whether the filter in filter (struct bgp_filter) is peer-specific. */ - uint8_t filter_override[AFI_MAX][SAFI_MAX][(FILTER_MAX > RMAP_MAX) - ? FILTER_MAX - : RMAP_MAX]; + uint8_t filter_override[AFI_MAX][SAFI_MAX][FILTER_MAX]; #define PEER_FT_DISTRIBUTE_LIST (1 << 0) /* distribute-list */ #define PEER_FT_FILTER_LIST (1 << 1) /* filter-list */ #define PEER_FT_PREFIX_LIST (1 << 2) /* prefix-list */ @@ -1482,7 +1480,7 @@ struct bgp_nlri { #define BGP_ATTR_ENCAP 23 #define BGP_ATTR_LARGE_COMMUNITIES 32 #define BGP_ATTR_PREFIX_SID 40 -#if ENABLE_BGP_VNC_ATTR +#ifdef ENABLE_BGP_VNC_ATTR #define BGP_ATTR_VNC 255 #endif @@ -1490,6 +1488,7 @@ struct bgp_nlri { #define BGP_ORIGIN_IGP 0 #define BGP_ORIGIN_EGP 1 #define BGP_ORIGIN_INCOMPLETE 2 +#define BGP_ORIGIN_UNSPECIFIED 255 /* BGP notify message codes. */ #define BGP_NOTIFY_HEADER_ERR 1 @@ -1500,6 +1499,12 @@ struct bgp_nlri { #define BGP_NOTIFY_CEASE 6 #define BGP_NOTIFY_CAPABILITY_ERR 7 +/* Subcodes for BGP Finite State Machine Error */ +#define BGP_NOTIFY_FSM_ERR_SUBCODE_UNSPECIFIC 0 +#define BGP_NOTIFY_FSM_ERR_SUBCODE_OPENSENT 1 +#define BGP_NOTIFY_FSM_ERR_SUBCODE_OPENCONFIRM 2 +#define BGP_NOTIFY_FSM_ERR_SUBCODE_ESTABLISHED 3 + #define BGP_NOTIFY_SUBCODE_UNSPECIFIC 0 /* BGP_NOTIFY_HEADER_ERR sub codes. */ diff --git a/bgpd/rfapi/bgp_rfapi_cfg.c b/bgpd/rfapi/bgp_rfapi_cfg.c index cad33404fa..acfab53d2b 100644 --- a/bgpd/rfapi/bgp_rfapi_cfg.c +++ b/bgpd/rfapi/bgp_rfapi_cfg.c @@ -47,7 +47,7 @@ #include "bgpd/rfapi/vnc_import_bgp.h" #include "bgpd/rfapi/vnc_debug.h" -#if ENABLE_BGP_VNC +#ifdef ENABLE_BGP_VNC #undef BGP_VNC_DEBUG_MATCH_GROUP @@ -168,7 +168,7 @@ struct rfapi_nve_group_cfg *bgp_rfapi_cfg_match_group(struct rfapi_cfg *hc, agg_unlock_node(rn_un); } -#if BGP_VNC_DEBUG_MATCH_GROUP +#ifdef BGP_VNC_DEBUG_MATCH_GROUP { char buf[PREFIX_STRLEN]; diff --git a/bgpd/rfapi/rfapi.c b/bgpd/rfapi/rfapi.c index 4701d2e1fa..d87292f652 100644 --- a/bgpd/rfapi/rfapi.c +++ b/bgpd/rfapi/rfapi.c @@ -2150,7 +2150,7 @@ int rfapi_close(void *handle) vnc_zlog_debug_verbose("%s: rfd=%p", __func__, rfd); -#if RFAPI_WHO_IS_CALLING_ME +#ifdef RFAPI_WHO_IS_CALLING_ME #ifdef HAVE_GLIBC_BACKTRACE #define RFAPI_DEBUG_BACKTRACE_NENTRIES 5 { diff --git a/bgpd/rfapi/rfapi_import.c b/bgpd/rfapi/rfapi_import.c index 8fbc4d9d15..2f274015fc 100644 --- a/bgpd/rfapi/rfapi_import.c +++ b/bgpd/rfapi/rfapi_import.c @@ -200,7 +200,7 @@ void rfapiCheckRouteCount(void) } } -#if DEBUG_ROUTE_COUNTERS +#ifdef DEBUG_ROUTE_COUNTERS #define VNC_ITRCCK do {rfapiCheckRouteCount();} while (0) #else #define VNC_ITRCCK @@ -458,7 +458,7 @@ int rfapiGetUnAddrOfVpnBi(struct bgp_path_info *bpi, struct prefix *p) default: if (p) p->family = 0; -#if DEBUG_ENCAP_MONITOR +#ifdef DEBUG_ENCAP_MONITOR vnc_zlog_debug_verbose( "%s: bpi->extra->vnc.import.un_family is 0, no UN addr", __func__); @@ -609,7 +609,7 @@ rfapiMonitorMoveShorter(struct agg_node *original_vpn_node, int lockoffset) RFAPI_CHECK_REFCOUNT(original_vpn_node, SAFI_MPLS_VPN, lockoffset); -#if DEBUG_MONITOR_MOVE_SHORTER +#ifdef DEBUG_MONITOR_MOVE_SHORTER { char buf[PREFIX_STRLEN]; @@ -628,7 +628,7 @@ rfapiMonitorMoveShorter(struct agg_node *original_vpn_node, int lockoffset) struct prefix pfx; if (!rfapiGetUnAddrOfVpnBi(bpi, &pfx)) { -#if DEBUG_MONITOR_MOVE_SHORTER +#ifdef DEBUG_MONITOR_MOVE_SHORTER vnc_zlog_debug_verbose( "%s: have valid UN at original node, no change", __func__); @@ -744,7 +744,7 @@ rfapiMonitorMoveShorter(struct agg_node *original_vpn_node, int lockoffset) agg_unlock_node(original_vpn_node); } -#if DEBUG_MONITOR_MOVE_SHORTER +#ifdef DEBUG_MONITOR_MOVE_SHORTER { char buf[PREFIX_STRLEN]; @@ -953,7 +953,7 @@ void rfapiImportTableRefDelByIt(struct bgp *bgp, } } -#if RFAPI_REQUIRE_ENCAP_BEEC +#ifdef RFAPI_REQUIRE_ENCAP_BEEC /* * Look for magic BGP Encapsulation Extended Community value * Format in RFC 5512 Sect. 4.5 @@ -1267,7 +1267,7 @@ rfapiRouteInfo2NextHopEntry(struct rfapi_ip_prefix *rprefix, struct rfapi_next_hop_entry *new; int have_vnc_tunnel_un = 0; -#if DEBUG_ENCAP_MONITOR +#ifdef DEBUG_ENCAP_MONITOR vnc_zlog_debug_verbose("%s: entry, bpi %p, rn %p", __func__, bpi, rn); #endif @@ -1401,7 +1401,7 @@ rfapiRouteInfo2NextHopEntry(struct rfapi_ip_prefix *rprefix, new->un_options = rfapi_encap_tlv_to_un_option(bpi->attr); -#if DEBUG_ENCAP_MONITOR +#ifdef DEBUG_ENCAP_MONITOR vnc_zlog_debug_verbose("%s: line %d: have_vnc_tunnel_un=%d", __func__, __LINE__, have_vnc_tunnel_un); #endif @@ -1448,7 +1448,7 @@ int rfapiHasNonRemovedRoutes(struct agg_node *rn) return 0; } -#if DEBUG_IT_NODES +#ifdef DEBUG_IT_NODES /* * DEBUG FUNCTION */ @@ -1517,7 +1517,7 @@ static int rfapiNhlAddNodeRoutes( struct prefix *newpfx; if (removed && !CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED)) { -#if DEBUG_RETURNED_NHL +#ifdef DEBUG_RETURNED_NHL vnc_zlog_debug_verbose( "%s: want holddown, this route not holddown, skip", __func__); @@ -1549,7 +1549,7 @@ static int rfapiNhlAddNodeRoutes( rfapiNexthop2Prefix(bpi->attr, &pfx_vn); } if (!skiplist_search(seen_nexthops, &pfx_vn, NULL)) { -#if DEBUG_RETURNED_NHL +#ifdef DEBUG_RETURNED_NHL char buf[PREFIX_STRLEN]; prefix2str(&pfx_vn, buf, sizeof(buf)); @@ -1561,7 +1561,7 @@ static int rfapiNhlAddNodeRoutes( } if (rfapiGetUnAddrOfVpnBi(bpi, &pfx_un)) { -#if DEBUG_ENCAP_MONITOR +#ifdef DEBUG_ENCAP_MONITOR vnc_zlog_debug_verbose( "%s: failed to get UN address of this VPN bpi", __func__); @@ -1715,7 +1715,7 @@ struct rfapi_next_hop_entry *rfapiRouteNode2NextHopList( int count = 0; struct agg_node *rib_rn; -#if DEBUG_RETURNED_NHL +#ifdef DEBUG_RETURNED_NHL { char buf[PREFIX_STRLEN]; @@ -1746,7 +1746,7 @@ struct rfapi_next_hop_entry *rfapiRouteNode2NextHopList( pfx_target_original); vnc_zlog_debug_verbose("%s: %d nexthops, answer=%p", __func__, count, answer); -#if DEBUG_RETURNED_NHL +#ifdef DEBUG_RETURNED_NHL rfapiPrintNhl(NULL, answer); #endif if (rib_rn) @@ -1806,7 +1806,7 @@ struct rfapi_next_hop_entry *rfapiRouteNode2NextHopList( vnc_zlog_debug_verbose("%s: %d nexthops, answer=%p", __func__, count, answer); -#if DEBUG_RETURNED_NHL +#ifdef DEBUG_RETURNED_NHL rfapiPrintNhl(NULL, answer); #endif return answer; @@ -1868,7 +1868,7 @@ struct rfapi_next_hop_entry *rfapiEthRouteNode2NextHopList( count = rfapiNhlAddNodeRoutes(rn, rprefix, lifetime, 0, &answer, &last, NULL, rib_rn, pfx_target_original); -#if DEBUG_ENCAP_MONITOR +#ifdef DEBUG_ENCAP_MONITOR vnc_zlog_debug_verbose("%s: node %p: %d non-holddown routes", __func__, rn, count); #endif @@ -1884,7 +1884,7 @@ struct rfapi_next_hop_entry *rfapiEthRouteNode2NextHopList( if (rib_rn) agg_unlock_node(rib_rn); -#if DEBUG_RETURNED_NHL +#ifdef DEBUG_RETURNED_NHL rfapiPrintNhl(NULL, answer); #endif @@ -2164,7 +2164,7 @@ static struct bgp_path_info *rfapiItBiIndexSearch( if (!sl) return NULL; -#if DEBUG_BI_SEARCH +#ifdef DEBUG_BI_SEARCH { char buf[RD_ADDRSTRLEN]; char buf_aux_pfx[PREFIX_STRLEN]; @@ -2185,13 +2185,13 @@ static struct bgp_path_info *rfapiItBiIndexSearch( /* threshold is a WAG */ if (sl->count < 3) { -#if DEBUG_BI_SEARCH +#ifdef DEBUG_BI_SEARCH vnc_zlog_debug_verbose("%s: short list algorithm", __func__); #endif /* if short list, linear search might be faster */ for (bpi_result = rn->info; bpi_result; bpi_result = bpi_result->next) { -#if DEBUG_BI_SEARCH +#ifdef DEBUG_BI_SEARCH { char buf[RD_ADDRSTRLEN]; @@ -2208,7 +2208,7 @@ static struct bgp_path_info *rfapiItBiIndexSearch( ->vnc.import.rd, (struct prefix *)prd)) { -#if DEBUG_BI_SEARCH +#ifdef DEBUG_BI_SEARCH vnc_zlog_debug_verbose( "%s: peer and RD same, doing aux_prefix check", __func__); @@ -2219,7 +2219,7 @@ static struct bgp_path_info *rfapiItBiIndexSearch( &bpi_result->extra->vnc.import .aux_prefix)) { -#if DEBUG_BI_SEARCH +#ifdef DEBUG_BI_SEARCH vnc_zlog_debug_verbose("%s: match", __func__); #endif @@ -2244,13 +2244,13 @@ static struct bgp_path_info *rfapiItBiIndexSearch( rc = skiplist_search(sl, (void *)&bpi_fake, (void *)&bpi_result); if (rc) { -#if DEBUG_BI_SEARCH +#ifdef DEBUG_BI_SEARCH vnc_zlog_debug_verbose("%s: no match", __func__); #endif return NULL; } -#if DEBUG_BI_SEARCH +#ifdef DEBUG_BI_SEARCH vnc_zlog_debug_verbose("%s: matched bpi=%p", __func__, bpi_result); #endif @@ -2958,7 +2958,7 @@ static void rfapiBgpInfoFilteredImportEncap( __func__); return; } -#if RFAPI_REQUIRE_ENCAP_BEEC +#ifdef RFAPI_REQUIRE_ENCAP_BEEC if (!rfapiEcommunitiesMatchBeec(attr->ecommunity)) { vnc_zlog_debug_verbose( "%s: it=%p: no match for BGP Encapsulation ecommunity", @@ -3007,7 +3007,7 @@ static void rfapiBgpInfoFilteredImportEncap( */ rn = agg_node_lookup(rt, p); -#if DEBUG_ENCAP_MONITOR +#ifdef DEBUG_ENCAP_MONITOR vnc_zlog_debug_verbose("%s: initial encap lookup(it=%p) rn=%p", __func__, import_table, rn); #endif @@ -3241,7 +3241,7 @@ static void rfapiBgpInfoFilteredImportEncap( /* * iterate over the set of monitors at this ENCAP node. */ -#if DEBUG_ENCAP_MONITOR +#ifdef DEBUG_ENCAP_MONITOR vnc_zlog_debug_verbose("%s: examining monitors at rn=%p", __func__, rn); #endif @@ -3997,7 +3997,7 @@ void rfapiProcessWithdraw(struct peer *peer, void *rfd, struct prefix *p, rc == 0; rc = skiplist_next(h->import_mac, NULL, (void **)&it, &cursor)) { -#if DEBUG_L2_EXTRA +#ifdef DEBUG_L2_EXTRA vnc_zlog_debug_verbose( "%s: calling rfapiBgpInfoFilteredImportVPN(it=%p, afi=AFI_L2VPN)", __func__, it); @@ -4408,7 +4408,7 @@ static void rfapiDeleteRemotePrefixesIt( { afi_t afi; -#if DEBUG_L2_EXTRA +#ifdef DEBUG_L2_EXTRA { char buf_pfx[PREFIX_STRLEN]; @@ -4487,7 +4487,7 @@ static void rfapiDeleteRemotePrefixesIt( if (vn) { if (!qpt_valid || !prefix_match(vn, &qpt)) { -#if DEBUG_L2_EXTRA +#ifdef DEBUG_L2_EXTRA vnc_zlog_debug_verbose( "%s: continue at vn && !qpt_valid || !prefix_match(vn, &qpt)", __func__); @@ -4502,7 +4502,7 @@ static void rfapiDeleteRemotePrefixesIt( if (un) { if (!qct_valid || !prefix_match(un, &qct)) { -#if DEBUG_L2_EXTRA +#ifdef DEBUG_L2_EXTRA vnc_zlog_debug_verbose( "%s: continue at un && !qct_valid || !prefix_match(un, &qct)", __func__); diff --git a/bgpd/rfapi/rfapi_rib.c b/bgpd/rfapi/rfapi_rib.c index 39d4b3ee29..3d4bdef75a 100644 --- a/bgpd/rfapi/rfapi_rib.c +++ b/bgpd/rfapi/rfapi_rib.c @@ -479,7 +479,7 @@ void rfapiRibClear(struct rfapi_descriptor *rfd) bgp = rfd->bgp; else bgp = bgp_get_default(); -#if DEBUG_L2_EXTRA +#ifdef DEBUG_L2_EXTRA vnc_zlog_debug_verbose("%s: rfd=%p", __func__, rfd); #endif @@ -1487,7 +1487,7 @@ static void rib_do_callback_onepass(struct rfapi_descriptor *rfd, afi_t afi) struct rfapi_next_hop_entry *tail = NULL; struct agg_node *rn; -#if DEBUG_L2_EXTRA +#ifdef DEBUG_L2_EXTRA vnc_zlog_debug_verbose("%s: rfd=%p, afi=%d", __func__, rfd, afi); #endif @@ -1812,7 +1812,7 @@ int rfapiRibFTDFilterRecentPrefix( if (it_rn->p.family == AF_ETHERNET) return 0; -#if DEBUG_FTD_FILTER_RECENT +#ifdef DEBUG_FTD_FILTER_RECENT { char buf_pfx[PREFIX_STRLEN]; @@ -1825,7 +1825,7 @@ int rfapiRibFTDFilterRecentPrefix( * prefix covers target address, so allow prefix */ if (prefix_match(&it_rn->p, pfx_target_original)) { -#if DEBUG_FTD_FILTER_RECENT +#ifdef DEBUG_FTD_FILTER_RECENT vnc_zlog_debug_verbose("%s: prefix covers target, allowed", __func__); #endif @@ -1840,7 +1840,7 @@ int rfapiRibFTDFilterRecentPrefix( if (trn->lock > 1) agg_unlock_node(trn); -#if DEBUG_FTD_FILTER_RECENT +#ifdef DEBUG_FTD_FILTER_RECENT vnc_zlog_debug_verbose("%s: last sent time %lu, last allowed time %lu", __func__, prefix_time, rfd->ftd_last_allowed_time); @@ -2184,6 +2184,7 @@ void rfapiRibPendingDeleteRoute(struct bgp *bgp, struct rfapi_import_table *it, rfapiRibUpdatePendingNode( bgp, m->rfd, it, it_node, m->rfd->response_lifetime); + agg_unlock_node(rn); } } @@ -2310,7 +2311,7 @@ static int print_rib_sl(int (*fp)(void *, const char *, ...), struct vty *vty, *p = 0; rfapiFormatSeconds(ri->lifetime, str_lifetime, BUFSIZ); -#if RFAPI_REGISTRATIONS_REPORT_AGE +#ifdef RFAPI_REGISTRATIONS_REPORT_AGE rfapiFormatAge(ri->last_sent_time, str_age, BUFSIZ); #else { @@ -2450,12 +2451,12 @@ void rfapiRibShowResponses(void *stream, struct prefix *pfx_match, " %-20s %-15s %-15s %4s %-8s %-8s\n", "Prefix", "Registered VN", "Registered UN", "Cost", "Lifetime", -#if RFAPI_REGISTRATIONS_REPORT_AGE +#ifdef RFAPI_REGISTRATIONS_REPORT_AGE "Age" #else "Remaining" #endif - ); + ); } if (!printednve) { char str_vn[BUFSIZ]; diff --git a/bgpd/rfapi/rfapi_vty.c b/bgpd/rfapi/rfapi_vty.c index 77fcf909c8..58fdc7c130 100644 --- a/bgpd/rfapi/rfapi_vty.c +++ b/bgpd/rfapi/rfapi_vty.c @@ -1123,7 +1123,7 @@ static int rfapiPrintRemoteRegBi(struct bgp *bgp, void *stream, (struct thread *)bpi->extra->vnc.import.timer; remaining = thread_timer_remain_second(t); -#if RFAPI_REGISTRATIONS_REPORT_AGE +#ifdef RFAPI_REGISTRATIONS_REPORT_AGE /* * Calculate when the timer started. Doing so here saves * us a timestamp field in "struct bgp_path_info". @@ -1311,7 +1311,7 @@ static int rfapiShowRemoteRegistrationsIt(struct bgp *bgp, void *stream, } fp(out, "%s", HVTYNL); if (show_expiring) { -#if RFAPI_REGISTRATIONS_REPORT_AGE +#ifdef RFAPI_REGISTRATIONS_REPORT_AGE agetype = "Age"; #else agetype = "Remaining"; diff --git a/bgpd/rfapi/vnc_export_bgp.c b/bgpd/rfapi/vnc_export_bgp.c index 352f5e8328..3d34d696b5 100644 --- a/bgpd/rfapi/vnc_export_bgp.c +++ b/bgpd/rfapi/vnc_export_bgp.c @@ -1189,7 +1189,7 @@ static void vnc_direct_add_rn_group_rd(struct bgp *bgp, } if (rfg->label > MPLS_LABEL_MAX) { vnc_zlog_debug_verbose( - "%s: VRF \"%s\" is missing defaul label configuration.\n", + "%s: VRF \"%s\" is missing default label configuration.\n", __func__, rfg->name); return; } diff --git a/configure.ac b/configure.ac index 901cac2318..0d56b60e72 100755 --- a/configure.ac +++ b/configure.ac @@ -122,7 +122,7 @@ AC_ARG_ENABLE([pkgsrcrcdir], pkgsrcrcdir="$enableval",) dnl XXX add --pkgsrcrcdir to autoconf standard directory list somehow AC_SUBST([pkgsrcrcdir]) -AM_CONDITIONAL([PKGSRC], [test "x$pkgsrcrcdir" != "x"]) +AM_CONDITIONAL([PKGSRC], [test "$pkgsrcrcdir" != ""]) AC_ARG_WITH([moduledir], [AS_HELP_STRING([--with-moduledir=DIR], [module directory (${libdir}/frr/modules)])], [ moduledir="$withval" @@ -197,7 +197,7 @@ AC_DEFUN([AC_C_FLAG], [{ CFLAGS="$ac_c_flag_save" AC_LANG_POP([C]) ]) - if test "${cachename}" = yes; then + if test "$cachename" = "yes"; then m4_if([$3], [], [CFLAGS="$CFLAGS $1"], [$3]) else : @@ -242,8 +242,8 @@ CC="${CC% -std=c99}" AC_C_FLAG([-std=gnu11], [CC="$ac_cc"], [CC="$CC -std=gnu11"]) dnl if the user has specified any CFLAGS, override our settings -if test "x${enable_gcov}" = "xyes"; then - if test "z$orig_cflags" = "z"; then +if test "$enable_gcov" = "yes"; then + if test "$orig_cflags" = ""; then AC_C_FLAG([-coverage]) AC_C_FLAG([-O0]) fi @@ -251,7 +251,7 @@ if test "x${enable_gcov}" = "xyes"; then LDFLAGS="${LDFLAGS} -lgcov" fi -if test "x${enable_clang_coverage}" = "xyes"; then +if test "$enable_clang_coverage" = "yes"; then AC_C_FLAG([-fprofile-instr-generate], [ AC_MSG_ERROR([$CC does not support -fprofile-instr-generate.]) ]) @@ -260,13 +260,13 @@ if test "x${enable_clang_coverage}" = "xyes"; then ]) fi -if test "x${enable_dev_build}" = "xyes"; then +if test "$enable_dev_build" = "yes"; then AC_DEFINE([DEV_BUILD], [1], [Build for development]) - if test "z$orig_cflags" = "z"; then + if test "$orig_cflags" = ""; then AC_C_FLAG([-g3]) AC_C_FLAG([-O0]) fi - if test "x${enable_lua}" = "xyes"; then + if test "$enable_lua" = "yes"; then AX_PROG_LUA([5.3]) AX_LUA_HEADERS AX_LUA_LIBS([ @@ -275,15 +275,15 @@ if test "x${enable_dev_build}" = "xyes"; then ]) fi else - if test "x${enable_lua}" = "xyes"; then + if test "$enable_lua" = "yes"; then AC_MSG_ERROR([Lua is not meant to be built/used outside of development at this time]) fi - if test "z$orig_cflags" = "z"; then + if test "$orig_cflags" = ""; then AC_C_FLAG([-g]) AC_C_FLAG([-O2]) fi fi -AM_CONDITIONAL([DEV_BUILD], [test "x$enable_dev_build" = "xyes"]) +AM_CONDITIONAL([DEV_BUILD], [test "$enable_dev_build" = "yes"]) dnl always want these CFLAGS AC_C_FLAG([-fno-omit-frame-pointer]) @@ -295,7 +295,7 @@ AC_C_FLAG([-Wmissing-declarations]) AC_C_FLAG([-Wpointer-arith]) AC_C_FLAG([-Wbad-function-cast]) AC_C_FLAG([-Wwrite-strings]) -if test x"${enable_gcc_ultra_verbose}" = x"yes" ; then +if test "$enable_gcc_ultra_verbose" = "yes" ; then AC_C_FLAG([-Wcast-qual]) AC_C_FLAG([-Wstrict-prototypes]) AC_C_FLAG([-Wmissing-noreturn]) @@ -318,7 +318,7 @@ dnl for some reason the string consts get 'promoted' to char *, dnl triggering a const to non-const conversion warning. AC_C_FLAG([-diag-disable 3179]) -if test x"${enable_werror}" = x"yes" ; then +if test "$enable_werror" = "yes" ; then WERROR="-Werror" fi AC_SUBST([WERROR]) @@ -369,7 +369,7 @@ AX_PTHREAD([ AC_SEARCH_LIBS([pthread_condattr_setclock], [], [frr_cv_pthread_condattr_setclock=yes], [frr_cv_pthread_condattr_setclock=no]) -if test "$frr_cv_pthread_condattr_setclock" = yes; then +if test "$frr_cv_pthread_condattr_setclock" = "yes"; then AC_DEFINE([HAVE_PTHREAD_CONDATTR_SETCLOCK], [1], [Have pthread.h pthread_condattr_setclock]) fi @@ -400,7 +400,7 @@ if test "$enable_shared" != "yes"; then AC_MSG_ERROR([FRR cannot be built with --disable-shared. If you want statically linked daemons, use --enable-shared --enable-static --enable-static-bin]) fi AC_SUBST([AC_LDFLAGS]) -AM_CONDITIONAL([STATIC_BIN], [test "x$enable_static_bin" = "xyes"]) +AM_CONDITIONAL([STATIC_BIN], [test "$enable_static_bin" = "yes"]) dnl $AR and $RANLIB are set by LT_INIT above AC_MSG_CHECKING([whether $AR supports D option]) @@ -451,7 +451,7 @@ AC_ARG_WITH([pkg-extra-version], ], []) AC_ARG_WITH([pkg-git-version], AS_HELP_STRING([--with-pkg-git-version], [add git information to MOTD and build version string]), - [ test "x$withval" != "xno" && with_pkg_git_version="yes" ]) + [ test "$withval" != "no" && with_pkg_git_version="yes" ]) AC_ARG_WITH([clippy], AS_HELP_STRING([--with-clippy=PATH], [use external clippy helper program])) AC_ARG_WITH([vtysh_pager], @@ -602,23 +602,23 @@ AC_ARG_WITH([crypto], AS_HELP_STRING([--with-crypto=<internal|openssl>], [choose between different implementations of cryptographic functions(default value is --with-crypto=internal)])) #if openssl, else use the internal -AS_IF([test x"${with_crypto}" = x"openssl"], [ +AS_IF([test "$with_crypto" = "openssl"], [ AC_CHECK_LIB([crypto], [EVP_DigestInit], [LIBS="$LIBS -lcrypto"], [], []) -if test $ac_cv_lib_crypto_EVP_DigestInit = no; then +if test "$ac_cv_lib_crypto_EVP_DigestInit" = "no"; then AC_MSG_ERROR([build with openssl has been specified but openssl library was not found on your system]) else AC_DEFINE([CRYPTO_OPENSSL], [1], [Compile with openssl support]) fi -], [test x"${with_crypto}" = x"internal" || test x"${with_crypto}" = x"" ], [AC_DEFINE([CRYPTO_INTERNAL], [1], [Compile with internal cryptographic implementation]) +], [test "$with_crypto" = "internal" || test "$with_crypto" = "" ], [AC_DEFINE([CRYPTO_INTERNAL], [1], [Compile with internal cryptographic implementation]) ], [AC_MSG_ERROR([Unknown value for --with-crypto])] ) -AS_IF([test "${enable_clippy_only}" != "yes"], [ +AS_IF([test "$enable_clippy_only" != "yes"], [ AC_CHECK_HEADERS([json-c/json.h]) AC_CHECK_LIB([json-c], [json_object_get], [LIBS="$LIBS -ljson-c"], [], [-lm]) -if test "$ac_cv_lib_json_c_json_object_get" = no; then +if test "$ac_cv_lib_json_c_json_object_get" = "no"; then AC_CHECK_LIB([json], [json_object_get], [LIBS="$LIBS -ljson"]) - if test "$ac_cv_lib_json_json_object_get" = no; then + if test "$ac_cv_lib_json_json_object_get" = "no"; then AC_MSG_ERROR([libjson is needed to compile]) fi fi @@ -630,8 +630,8 @@ AC_ARG_ENABLE([dev_build], AC_ARG_ENABLE([lua], AS_HELP_STRING([--enable-lua], [Build Lua scripting])) -if test x"${enable_time_check}" != x"no" ; then - if test x"${enable_time_check}" = x"yes" -o x"${enable_time_check}" = x ; then +if test "$enable_time_check" != "no" ; then + if test "$enable_time_check" = "yes" -o "$enable_time_check" = "" ; then AC_DEFINE([CONSUMED_TIME_CHECK], [5000000], [Consumed Time Check]) else AC_DEFINE_UNQUOTED([CONSUMED_TIME_CHECK], [$enable_time_check], [Consumed Time Check]) @@ -650,7 +650,7 @@ case "${enable_systemd}" in "no") ;; "yes") AC_CHECK_LIB([systemd], [sd_notify], [LIBS="$LIBS -lsystemd"]) - if test $ac_cv_lib_systemd_sd_notify = no; then + if test "$ac_cv_lib_systemd_sd_notify" = "no"; then AC_MSG_ERROR([enable systemd has been specified but systemd development env not found on your system]) else AC_DEFINE([HAVE_SYSTEMD], [1], [Compile systemd support in]) @@ -659,11 +659,11 @@ case "${enable_systemd}" in "*") ;; esac -if test "${enable_rr_semantics}" != "no" ; then +if test "$enable_rr_semantics" != "no" ; then AC_DEFINE([HAVE_V6_RR_SEMANTICS], [1], [Compile in v6 Route Replacement Semantics]) fi -if test "${enable_datacenter}" = "yes" ; then +if test "$enable_datacenter" = "yes" ; then AC_DEFINE([HAVE_DATACENTER], [1], [Compile extensions for a DataCenter]) AC_MSG_WARN([The --enable-datacenter compile time option is deprecated. Please modify the init script to pass -F datacenter to the daemons instead.]) DFLT_NAME="datacenter" @@ -671,22 +671,22 @@ else DFLT_NAME="traditional" fi -if test "${enable_fuzzing}" = "yes" ; then +if test "$enable_fuzzing" = "yes" ; then AC_DEFINE([HANDLE_ZAPI_FUZZING], [1], [Compile extensions to use with a fuzzer]) fi -if test "${enable_netlink_fuzzing}" = "yes" ; then +if test "$enable_netlink_fuzzing" = "yes" ; then AC_DEFINE([HANDLE_NETLINK_FUZZING], [1], [Compile extensions to use with a fuzzer for netlink]) fi -if test "${enable_cumulus}" = "yes" ; then +if test "$enable_cumulus" = "yes" ; then AC_DEFINE([HAVE_CUMULUS], [1], [Compile Special Cumulus Code in]) fi AC_SUBST([DFLT_NAME]) AC_DEFINE_UNQUOTED([DFLT_NAME], ["$DFLT_NAME"], [Name of the configuration default set]) -if test "${enable_shell_access}" = "yes"; then +if test "$enable_shell_access" = "yes"; then AC_DEFINE([HAVE_SHELL_ACCESS], [1], [Allow user to use ssh/telnet/bash, be aware this is considered insecure]) fi @@ -702,15 +702,15 @@ AS_IF([test "$host" = "$build"], [ FRR_PYTHON_MODULES([pytest]) -if test "${enable_doc}" != "no"; then +if test "$enable_doc" != "no"; then FRR_PYTHON_MODULES([sphinx], , [ - if test "${enable_doc}" = "yes"; then + if test "$enable_doc" = "yes"; then AC_MSG_ERROR([Documentation was explicitly requested with --enable-doc but sphinx is not available for $PYTHON. Please disable docs or install sphinx.]) fi ]) fi -AM_CONDITIONAL([DOC], [test "${enable_doc}" != "no" -a "$frr_py_mod_sphinx" != "false"]) -AM_CONDITIONAL([DOC_HTML], [test "${enable_doc_html}" = "yes"]) +AM_CONDITIONAL([DOC], [test "$enable_doc" != "no" -a "$frr_py_mod_sphinx" != "false"]) +AM_CONDITIONAL([DOC_HTML], [test "$enable_doc_html" = "yes"]) FRR_PYTHON_MOD_EXEC([sphinx], [--version], [ PYSPHINX="-m sphinx" @@ -731,35 +731,35 @@ fi # AC_MSG_CHECKING([if zebra should be configurable to send Route Advertisements]) -if test "${enable_rtadv}" != "no"; then +if test "$enable_rtadv" != "no"; then AC_MSG_RESULT([yes]) AC_DEFINE([HAVE_RTADV], [1], [Enable IPv6 Routing Advertisement support]) else AC_MSG_RESULT([no]) fi -if test x"${enable_user}" = x"no"; then +if test "$enable_user" = "no"; then enable_user="" else - if test x"${enable_user}" = x"yes" || test x"${enable_user}" = x""; then + if test "$enable_user" = "yes" || test "$enable_user" = ""; then enable_user="frr" fi AC_DEFINE_UNQUOTED([FRR_USER], ["${enable_user}"], [frr User]) fi -if test x"${enable_group}" = x"no"; then +if test "$enable_group" = "no"; then enable_group="" else - if test x"${enable_group}" = x"yes" || test x"${enable_group}" = x""; then + if test "$enable_group" = "yes" || test "$enable_group" = ""; then enable_group="frr" fi AC_DEFINE_UNQUOTED([FRR_GROUP], ["${enable_group}"], [frr Group]) fi -if test x"${enable_vty_group}" = x"yes" ; then +if test "$enable_vty_group" = "yes" ; then AC_MSG_ERROR([--enable-vty-group requires a group as argument, not yes]) -elif test x"${enable_vty_group}" != x""; then - if test x"${enable_vty_group}" != x"no"; then +elif test "$enable_vty_group" != ""; then + if test "$enable_vty_group" != "no"; then AC_DEFINE_UNQUOTED([VTY_GROUP], ["${enable_vty_group}"], [VTY Sockets Group]) fi fi @@ -784,7 +784,7 @@ case "${enable_multipath}" in ;; "") ;; - *) + *) AC_MSG_FAILURE([Please specify digit to enable multipath ARG]) ;; esac @@ -796,12 +796,12 @@ AC_DEFINE_UNQUOTED([VTYSH_PAGER], ["$VTYSH_PAGER"], [What pager to use]) dnl -------------------- dnl Enable code coverage dnl -------------------- -AM_CONDITIONAL([HAVE_GCOV], [test '!' "$enable_gcov" = no]) +AM_CONDITIONAL([HAVE_GCOV], [test "$enable_gcov" != "no"]) dnl ------------------------------------ dnl Alpine only accepts numeric versions dnl ------------------------------------ -if test "x${enable_numeric_version}" != "x" ; then +if test "$enable_numeric_version" != "" ; then VERSION="`echo ${VERSION} | tr -c -d '[[.0-9]]'`" PACKAGE_VERSION="`echo ${PACKAGE_VERSION} | tr -c -d '[[.0-9]]'`" fi @@ -810,7 +810,7 @@ dnl ----------------------------------- dnl Add extra version string to package dnl name, string and version fields. dnl ----------------------------------- -if test "x${EXTRAVERSION}" != "x" ; then +if test "$EXTRAVERSION" != "" ; then VERSION="${VERSION}${EXTRAVERSION}" PACKAGE_VERSION="${PACKAGE_VERSION}${EXTRAVERSION}" AC_SUBST(PACKAGE_EXTRAVERSION, ["${EXTRAVERSION}"]) @@ -818,17 +818,17 @@ if test "x${EXTRAVERSION}" != "x" ; then fi AC_SUBST([EXTRAVERSION]) -if test "x$with_pkg_git_version" = "xyes"; then +if test "$with_pkg_git_version" = "yes"; then if test -d "${srcdir}/.git"; then AC_DEFINE([GIT_VERSION], [1], [include git version info]) else with_pkg_git_version="no" AC_MSG_WARN([--with-pkg-git-version given, but this is not a git checkout]) fi fi -AM_CONDITIONAL([GIT_VERSION], [test "x$with_pkg_git_version" = "xyes"]) +AM_CONDITIONAL([GIT_VERSION], [test "$with_pkg_git_version" = "yes"]) AC_CHECK_TOOL([OBJCOPY], [objcopy], [:]) -if test "x${OBJCOPY}" != "x:"; then +if test "$OBJCOPY" != ":"; then AC_CACHE_CHECK([for .interp value to use], [frr_cv_interp], [ frr_cv_interp="" AC_LINK_IFELSE([AC_LANG_SOURCE([[int main() { return 0; }]])], [ @@ -1026,7 +1026,7 @@ AC_CHECK_HEADERS([net/if_var.h], [], [], [FRR_INCLUDES]) m4_define([FRR_INCLUDES], FRR_INCLUDES -[#if HAVE_NET_IF_VAR_H +[#ifdef HAVE_NET_IF_VAR_H # include <net/if_var.h> #endif ])dnl @@ -1061,22 +1061,22 @@ FRR_INCLUDES [ #include <sys/un.h> #include <netinet/in_systm.h> -#if HAVE_NETINET_IN_VAR_H +#ifdef HAVE_NETINET_IN_VAR_H # include <netinet/in_var.h> #endif -#if HAVE_NET_IF_DL_H +#ifdef HAVE_NET_IF_DL_H # include <net/if_dl.h> #endif -#if HAVE_NET_NETOPT_H +#ifdef HAVE_NET_NETOPT_H # include <net/netopt.h> #endif #include <net/route.h> -#if HAVE_INET_ND_H +#ifdef HAVE_INET_ND_H # include <inet/nd.h> #endif #include <arpa/inet.h> /* Required for IDRP */ -#if HAVE_NETINET_IP_ICMP_H +#ifdef HAVE_NETINET_IP_ICMP_H # include <netinet/ip_icmp.h> #endif ])dnl @@ -1123,7 +1123,7 @@ case "$host_os" in AC_DEFINE([KAME], [1], [KAME IPv6]) AC_DEFINE([BSD_V6_SYSCTL], [1], [BSD v6 sysctl to turn on and off forwarding]) - if test "x${enable_pimd}" != "xno"; then + if test "$enable_pimd" != "no"; then case "$host_os" in openbsd6.0) ;; @@ -1141,7 +1141,7 @@ case "$host_os" in AC_DEFINE([BSD_V6_SYSCTL], [1], [BSD v6 sysctl to turn on and off forwarding]) ;; esac -AM_CONDITIONAL([SOLARIS], [test "${SOLARIS}" = "solaris"]) +AM_CONDITIONAL([SOLARIS], [test "$SOLARIS" = "solaris"]) AM_CONDITIONAL([LINUX], [${is_linux}]) AC_SYS_LARGEFILE @@ -1149,7 +1149,7 @@ AC_SYS_LARGEFILE dnl ------------------------ dnl Integrated REALMS option dnl ------------------------ -if test "${enable_realms}" = "yes"; then +if test "$enable_realms" = "yes"; then case "$host_os" in linux*) AC_DEFINE([SUPPORT_REALMS], [1], [Realms support]) @@ -1175,7 +1175,7 @@ AC_CHECK_FUNCS([ \ dnl ########################################################################## dnl LARGE if block spans a lot of "configure"! -if test "${enable_clippy_only}" != "yes"; then +if test "$enable_clippy_only" != "yes"; then dnl ########################################################################## # @@ -1243,15 +1243,15 @@ case "${enable_vtysh}" in LIBS="$prev_libs" AC_CHECK_HEADER([readline/history.h]) - if test $ac_cv_header_readline_history_h = no;then + if test "$ac_cv_header_readline_history_h" = "no"; then AC_MSG_ERROR([readline is too old to have readline/history.h, please update to the latest readline library.]) fi AC_CHECK_LIB([readline], [rl_completion_matches], [true], [], [$LIBREADLINE]) - if test $ac_cv_lib_readline_rl_completion_matches = no; then + if test "$ac_cv_lib_readline_rl_completion_matches" = "no"; then AC_DEFINE([rl_completion_matches], [completion_matches], [Old readline]) fi AC_CHECK_LIB([readline], [append_history], [frr_cv_append_history=yes], [frr_cv_append_history=no], [$LIBREADLINE]) - if test "$frr_cv_append_history" = yes; then + if test "$frr_cv_append_history" = "yes"; then AC_DEFINE([HAVE_APPEND_HISTORY], [1], [Have history.h append_history]) fi ;; @@ -1366,10 +1366,10 @@ case "$host_os" in ISIS_METHOD_MACRO="ISIS_METHOD_DLPI" ;; *) - if test $ac_cv_header_net_bpf_h = no; then - if test $ac_cv_header_sys_dlpi_h = no; then + if test "$ac_cv_header_net_bpf_h" = "no"; then + if test "$ac_cv_header_sys_dlpi_h" = "no"; then AC_MSG_RESULT([none]) - if test "${enable_isisd}" = yes -o "${enable_fabricd}" = yes; then + if test "$enable_isisd" = "yes" -o "$enable_fabricd" = "yes"; then AC_MSG_FAILURE([IS-IS support requested but no packet backend found]) fi AC_MSG_WARN([*** IS-IS support will not be built ***]) @@ -1401,7 +1401,7 @@ AC_CHECK_HEADERS([linux/mroute.h], [], [],[ m4_define([FRR_INCLUDES], FRR_INCLUDES -[#if HAVE_LINUX_MROUTE_H +[#ifdef HAVE_LINUX_MROUTE_H # include <linux/mroute.h> #endif ])dnl @@ -1415,7 +1415,7 @@ AC_CHECK_HEADERS([netinet/ip_mroute.h], [], [],[ m4_define([FRR_INCLUDES], FRR_INCLUDES -[#if HAVE_NETINET_IP_MROUTE_H +[#ifdef HAVE_NETINET_IP_MROUTE_H # include <netinet/ip_mroute.h> #endif ])dnl @@ -1473,7 +1473,7 @@ AC_CHECK_HEADER([netinet/tcp.h], AC_CHECK_DECLS([TCP_MD5SIG], [], [], MD5_INCLUDES)], [], FRR_INCLUDES) -if test $ac_cv_have_decl_TCP_MD5SIG = no; then +if test "$ac_cv_have_decl_TCP_MD5SIG" = "no"; then AC_CHECK_HEADER([linux/tcp.h], [m4_define([MD5_INCLUDES], FRR_INCLUDES @@ -1490,7 +1490,7 @@ AC_CHECK_LIB([resolv], [res_init]) dnl --------------------------- dnl check system has PCRE regexp dnl --------------------------- -if test "x$enable_pcreposix" = "xyes"; then +if test "$enable_pcreposix" = "yes"; then AC_CHECK_LIB([pcreposix], [regexec], [], [ AC_MSG_ERROR([--enable-pcreposix given but unable to find libpcreposix]) ]) @@ -1498,7 +1498,7 @@ fi AC_SUBST([HAVE_LIBPCREPOSIX]) dnl ########################################################################## -dnl test "${enable_clippy_only}" != "yes" +dnl test "$enable_clippy_only" != "yes" fi dnl END OF LARGE if block dnl ########################################################################## @@ -1528,17 +1528,17 @@ AC_CHECK_HEADERS([netinet6/in6.h netinet/in6_var.h \ m4_define([FRR_INCLUDES],dnl FRR_INCLUDES -[#if HAVE_NETINET6_IN6_H +[#ifdef HAVE_NETINET6_IN6_H #include <netinet6/in6.h> #endif -#if HAVE_NETINET_IN6_VAR_H +#ifdef HAVE_NETINET_IN6_VAR_H #include <netinet/in6_var.h> #endif #include <netinet/icmp6.h> -#if HAVE_NETINET6_IN6_VAR_H +#ifdef HAVE_NETINET6_IN6_VAR_H # include <netinet6/in6_var.h> #endif -#if HAVE_NETINET6_ND6_H +#ifdef HAVE_NETINET6_ND6_H # include <netinet6/nd6.h> #endif ])dnl @@ -1547,7 +1547,7 @@ dnl -------------------- dnl Daemon disable check dnl -------------------- -AS_IF([test "${enable_ldpd}" != "no"], [ +AS_IF([test "$enable_ldpd" != "no"], [ AC_DEFINE([HAVE_LDPD], [1], [ldpd]) ]) @@ -1569,7 +1569,7 @@ else esac fi -if test "$ac_cv_lib_json_c_json_object_get" = no -a "x$BFDD" = "xbfdd"; then +if test "$ac_cv_lib_json_c_json_object_get" = "no" -a "$BFDD" = "bfdd"; then AC_MSG_ERROR(["you must use json-c library to use bfdd"]) fi @@ -1580,7 +1580,7 @@ case "$host_os" in no) ;; yes) - if test "${enable_clippy_only}" != "yes"; then + if test "$enable_clippy_only" != "yes"; then if test "$c_ares_found" != "true" ; then AC_MSG_ERROR([nhrpd requires libcares. Please install c-ares and its -dev headers.]) fi @@ -1595,34 +1595,34 @@ case "$host_os" in esac ;; *) - if test "${enable_nhrpd}" = "yes"; then + if test "$enable_nhrpd" = "yes"; then AC_MSG_ERROR([nhrpd requires kernel APIs that are only present on Linux.]) fi ;; esac -if test "${enable_watchfrr}" = "no";then +if test "$enable_watchfrr" = "no";then WATCHFRR="" else WATCHFRR="watchfrr" fi OSPFCLIENT="" -if test "${enable_ospfapi}" != "no";then +if test "$enable_ospfapi" != "no";then AC_DEFINE([SUPPORT_OSPF_API], [1], [OSPFAPI]) - if test "${enable_ospfclient}" != "no";then + if test "$enable_ospfclient" != "no";then OSPFCLIENT="ospfclient" fi fi -if test "${enable_bgp_announce}" = "no";then +if test "$enable_bgp_announce" = "no";then AC_DEFINE([DISABLE_BGP_ANNOUNCE], [1], [Disable BGP installation to zebra]) else AC_DEFINE([DISABLE_BGP_ANNOUNCE], [0], [Disable BGP installation to zebra]) fi -if test "${enable_bgp_vnc}" != "no";then +if test "$enable_bgp_vnc" != "no";then AC_DEFINE([ENABLE_BGP_VNC], [1], [Enable BGP VNC support]) fi @@ -1645,15 +1645,15 @@ esac dnl ########################################################################## dnl LARGE if block -if test "${enable_clippy_only}" != "yes"; then +if test "$enable_clippy_only" != "yes"; then dnl ########################################################################## dnl ------------------ dnl check Net-SNMP library dnl ------------------ -if test "${enable_snmp}" != "" -a "${enable_snmp}" != "no"; then +if test "$enable_snmp" != "" -a "$enable_snmp" != "no"; then AC_PATH_TOOL([NETSNMP_CONFIG], [net-snmp-config], [no]) - if test x"$NETSNMP_CONFIG" = x"no"; then + if test "$NETSNMP_CONFIG" = "no"; then AC_MSG_ERROR([--enable-snmp given but unable to find net-snmp-config]) fi SNMP_LIBS="`${NETSNMP_CONFIG} --agent-libs`" @@ -1726,7 +1726,7 @@ dnl confd dnl --------------- if test "$enable_confd" != "" -a "$enable_confd" != "no"; then AC_CHECK_PROG([CONFD], [confd], [confd], [/bin/false], "${enable_confd}/bin") - if test "x$CONFD" = "x/bin/false"; then + if test "$CONFD" = "/bin/false"; then AC_MSG_ERROR([confd was not found on your system.])] fi CONFD_CFLAGS="-I${enable_confd}/include -L${enable_confd}/lib" @@ -1769,12 +1769,12 @@ fi dnl ------ dnl ZeroMQ dnl ------ -if test "x$enable_zeromq" != "xno"; then +if test "$enable_zeromq" != "no"; then PKG_CHECK_MODULES([ZEROMQ], [libzmq >= 4.0.0], [ AC_DEFINE([HAVE_ZEROMQ], [1], [Enable ZeroMQ support]) ZEROMQ=true ], [ - if test "x$enable_zeromq" = "xyes"; then + if test "$enable_zeromq" = "yes"; then AC_MSG_ERROR([configuration specifies --enable-zeromq but libzmq was not found]) fi ]) @@ -1783,7 +1783,7 @@ fi dnl ------------------------------------ dnl Enable RPKI and add librtr to libs dnl ------------------------------------ -if test "${enable_rpki}" = "yes"; then +if test "$enable_rpki" = "yes"; then PKG_CHECK_MODULES([RTRLIB], [rtrlib >= 0.5.0], [RPKI=true], [RPKI=false @@ -1827,7 +1827,7 @@ AC_CACHE_CHECK([for dlinfo(RTLD_DI_ORIGIN)], [frr_cv_rtld_di_origin], [ frr_cv_rtld_di_origin=no ]) ]) -if test "$frr_cv_rtld_di_origin" = yes; then +if test "$frr_cv_rtld_di_origin" = "yes"; then AC_DEFINE([HAVE_DLINFO_ORIGIN], [1], [Have dlinfo RTLD_DI_ORIGIN]) fi @@ -1847,12 +1847,12 @@ AC_CACHE_CHECK([for dlinfo(RTLD_DI_LINKMAP)], [frr_cv_rtld_di_linkmap], [ frr_cv_rtld_di_linkmap=no ]) ]) -if test "$frr_cv_rtld_di_linkmap" = yes; then +if test "$frr_cv_rtld_di_linkmap" = "yes"; then AC_DEFINE([HAVE_DLINFO_LINKMAP], [1], [Have dlinfo RTLD_DI_LINKMAP]) fi dnl ########################################################################## -dnl test "${enable_clippy_only}" != "yes" +dnl test "$enable_clippy_only" != "yes" fi dnl END OF LARGE if block dnl ########################################################################## @@ -2052,7 +2052,7 @@ fi dnl ------------------- dnl capabilities checks dnl ------------------- -if test "${enable_capabilities}" != "no"; then +if test "$enable_capabilities" != "no"; then AC_MSG_CHECKING([whether prctl PR_SET_KEEPCAPS is available]) AC_TRY_COMPILE([#include <sys/prctl.h>], [prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);], [AC_MSG_RESULT([yes]) @@ -2060,11 +2060,11 @@ if test "${enable_capabilities}" != "no"; then frr_ac_keepcaps="yes"], AC_MSG_RESULT([no]) ) - if test x"${frr_ac_keepcaps}" = x"yes"; then + if test "$frr_ac_keepcaps" = "yes"; then AC_CHECK_HEADERS([sys/capability.h]) fi - if test x"${ac_cv_header_sys_capability_h}" = x"yes"; then - AC_CHECK_LIB([cap], [cap_init], + if test "$ac_cv_header_sys_capability_h" = "yes"; then + AC_CHECK_LIB([cap], [cap_init], [AC_DEFINE([HAVE_LCAPS], [1], [Capabilities]) LIBCAP="-lcap" frr_ac_lcaps="yes"] @@ -2081,14 +2081,14 @@ if test "${enable_capabilities}" != "no"; then ] ) fi - if test x"${frr_ac_scaps}" = x"yes" \ - -o x"${frr_ac_lcaps}" = x"yes"; then + if test "$frr_ac_scaps" = "yes" \ + -o "$frr_ac_lcaps" = "yes"; then AC_DEFINE([HAVE_CAPABILITIES], [1], [capabilities]) fi case "$host_os" in linux*) - if test "${enable_clippy_only}" != "yes"; then + if test "$enable_clippy_only" != "yes"; then if test "$frr_ac_lcaps" != "yes"; then AC_MSG_ERROR([libcap and/or its headers were not found. Running FRR without libcap support built in causes a huge performance penalty.]) fi @@ -2106,8 +2106,8 @@ AC_SUBST([LIBCAP]) dnl --------------------------- dnl check for glibc 'backtrace' -dnl --------------------------- -if test x"${enable_backtrace}" != x"no" ; then +dnl --------------------------- +if test "$enable_backtrace" != "no" ; then backtrace_ok=no PKG_CHECK_MODULES([UNWIND], [libunwind], [ AC_DEFINE([HAVE_LIBUNWIND], [1], [libunwind]) @@ -2134,7 +2134,7 @@ if test x"${enable_backtrace}" != x"no" ; then ]) ;; esac - if test "$backtrace_ok" = no; then + if test "$backtrace_ok" = "no"; then AC_CHECK_HEADER([execinfo.h], [ AC_SEARCH_LIBS([backtrace], [execinfo], [ AC_DEFINE([HAVE_GLIBC_BACKTRACE], [1], [Glibc backtrace]) @@ -2144,7 +2144,7 @@ if test x"${enable_backtrace}" != x"no" ; then fi fi - if test x"${enable_backtrace}" = x"yes" -a x"${backtrace_ok}" = x"no"; then + if test "$enable_backtrace" = "yes" -a "$backtrace_ok" = "no"; then dnl user explicitly requested backtrace but we failed to find support AC_MSG_FAILURE([failed to find backtrace or libunwind support]) fi @@ -2178,7 +2178,7 @@ struct mallinfo ac_x; ac_x = mallinfo (); frr_cv_mallinfo=no ]) ]) -if test "$frr_cv_mallinfo" = yes; then +if test "$frr_cv_mallinfo" = "yes"; then AC_DEFINE([HAVE_MALLINFO], [1], [mallinfo]) fi @@ -2221,7 +2221,7 @@ dnl configure date dnl ---------- dev_version=`echo $VERSION | grep dev` #don't expire deprecated code in non 'dev' branch -if test "${dev_version}" = ""; then +if test "$dev_version" = ""; then CONFDATE=0 else CONFDATE=`date '+%Y%m%d'` @@ -2232,12 +2232,12 @@ dnl ------------------------------ dnl set paths for state directory dnl ------------------------------ AC_MSG_CHECKING([directory to use for state file]) -if test "${prefix}" = "NONE"; then +if test "$prefix" = "NONE"; then frr_statedir_prefix=""; else frr_statedir_prefix=${prefix} fi -if test "${localstatedir}" = '${prefix}/var'; then +if test "$localstatedir" = '${prefix}/var'; then for FRR_STATE_DIR in ${frr_statedir_prefix}/var/run dnl ${frr_statedir_prefix}/var/adm dnl ${frr_statedir_prefix}/etc dnl @@ -2252,7 +2252,7 @@ if test "${localstatedir}" = '${prefix}/var'; then else frr_statedir=${localstatedir} fi -if test $frr_statedir = "/dev/null"; then +if test "$frr_statedir" = "/dev/null"; then AC_MSG_ERROR([STATE DIRECTORY NOT FOUND! FIX OR SPECIFY --localstatedir!]) fi AC_MSG_RESULT([${frr_statedir}]) @@ -2265,8 +2265,8 @@ AC_DEFINE_UNQUOTED([DAEMON_VTY_DIR], ["$frr_statedir%s%s"], [daemon vty director AC_DEFINE_UNQUOTED([DAEMON_DB_DIR], ["$frr_statedir"], [daemon database directory]) dnl autoconf does this, but it does it too late... -test "x$prefix" = xNONE && prefix=$ac_default_prefix -test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' +test "$prefix" = "NONE" && prefix=$ac_default_prefix +test "$exec_prefix" = "NONE" && exec_prefix='${prefix}' dnl get the full path, recursing through variables... vtysh_bin="$bindir/vtysh" @@ -2298,44 +2298,44 @@ AC_DEFINE_UNQUOTED([YANG_MODELS_PATH], ["$CFG_YANGMODELS"], [path to YANG data m AC_DEFINE_UNQUOTED([WATCHFRR_SH_PATH], ["${CFG_SBIN%/}/watchfrr.sh"], [path to watchfrr.sh]) dnl various features -AM_CONDITIONAL([SUPPORT_REALMS], [test "${enable_realms}" = "yes"]) -AM_CONDITIONAL([ENABLE_BGP_VNC], [test x${enable_bgp_vnc} != xno]) +AM_CONDITIONAL([SUPPORT_REALMS], [test "$enable_realms" = "yes"]) +AM_CONDITIONAL([ENABLE_BGP_VNC], [test "$enable_bgp_vnc" != "no"]) AM_CONDITIONAL([BGP_BMP], [$bgpd_bmp]) dnl northbound AM_CONDITIONAL([SQLITE3], [$SQLITE3]) -AM_CONDITIONAL([CONFD], [test "x$enable_confd" != "x"]) -AM_CONDITIONAL([SYSREPO], [test "x$enable_sysrepo" = "xyes"]) -AM_CONDITIONAL([GRPC], [test "x$enable_grpc" = "xyes"]) -AM_CONDITIONAL([ZEROMQ], [test "x$ZEROMQ" = "xtrue"]) +AM_CONDITIONAL([CONFD], [test "$enable_confd" != ""]) +AM_CONDITIONAL([SYSREPO], [test "$enable_sysrepo" = "yes"]) +AM_CONDITIONAL([GRPC], [test "$enable_grpc" = "yes"]) +AM_CONDITIONAL([ZEROMQ], [test "$ZEROMQ" = "true"]) dnl plugins -AM_CONDITIONAL([RPKI], [test "x$RPKI" = "xtrue"]) -AM_CONDITIONAL([SNMP], [test "x$SNMP_METHOD" = "xagentx"]) +AM_CONDITIONAL([RPKI], [test "$RPKI" = "true"]) +AM_CONDITIONAL([SNMP], [test "$SNMP_METHOD" = "agentx"]) AM_CONDITIONAL([IRDP], [$IRDP]) -AM_CONDITIONAL([FPM], [test "x$enable_fpm" = "xyes"]) -AM_CONDITIONAL([HAVE_PROTOBUF], [test "x$enable_protobuf" = "xyes"]) +AM_CONDITIONAL([FPM], [test "$enable_fpm" = "yes"]) +AM_CONDITIONAL([HAVE_PROTOBUF], [test "$enable_protobuf" = "yes"]) AM_CONDITIONAL([HAVE_PROTOBUF3], [$PROTO3]) dnl daemons -AM_CONDITIONAL([VTYSH], [test "x$VTYSH" = "xvtysh"]) -AM_CONDITIONAL([ZEBRA], [test "${enable_zebra}" != "no"]) -AM_CONDITIONAL([BGPD], [test "x${enable_bgpd}" != "no"]) -AM_CONDITIONAL([RIPD], [test "${enable_ripd}" != "no"]) -AM_CONDITIONAL([OSPFD], [test "${enable_ospfd}" != "no"]) -AM_CONDITIONAL([LDPD], [test "${enable_ldpd}" != "no"]) -AM_CONDITIONAL([BFDD], [test "x$BFDD" = "xbfdd"]) -AM_CONDITIONAL([NHRPD], [test "x$NHRPD" = "xnhrpd"]) -AM_CONDITIONAL([EIGRPD], [test "${enable_eigrpd}" != "no"]) -AM_CONDITIONAL([WATCHFRR], [test "x$WATCHFRR" = "xwatchfrr"]) -AM_CONDITIONAL([OSPFCLIENT], [test "x$OSPFCLIENT" = "xospfclient"]) -AM_CONDITIONAL([RIPNGD], [test "${enable_ripngd}" != "no"]) -AM_CONDITIONAL([BABELD], [test "${enable_babeld}" != "no"]) -AM_CONDITIONAL([OSPF6D], [test "${enable_ospf6d}" != "no"]) -AM_CONDITIONAL([ISISD], [test "${enable_isisd}" != "no"]) -AM_CONDITIONAL([PIMD], [test "${enable_pimd}" != "no"]) -AM_CONDITIONAL([PBRD], [test "${enable_pbrd}" != "no"]) -AM_CONDITIONAL([SHARPD], [test "${enable_sharpd}" = "yes"]) -AM_CONDITIONAL([STATICD], [test "${enable_staticd}" != "no"]) -AM_CONDITIONAL([FABRICD], [test "${enable_fabricd}" != "no"]) -AM_CONDITIONAL([VRRPD], [test "${enable_vrrpd}" != "no"]) +AM_CONDITIONAL([VTYSH], [test "$VTYSH" = "vtysh"]) +AM_CONDITIONAL([ZEBRA], [test "$enable_zebra" != "no"]) +AM_CONDITIONAL([BGPD], [test "$enable_bgpd" != "no"]) +AM_CONDITIONAL([RIPD], [test "$enable_ripd" != "no"]) +AM_CONDITIONAL([OSPFD], [test "$enable_ospfd" != "no"]) +AM_CONDITIONAL([LDPD], [test "$enable_ldpd" != "no"]) +AM_CONDITIONAL([BFDD], [test "$BFDD" = "bfdd"]) +AM_CONDITIONAL([NHRPD], [test "$NHRPD" = "nhrpd"]) +AM_CONDITIONAL([EIGRPD], [test "$enable_eigrpd" != "no"]) +AM_CONDITIONAL([WATCHFRR], [test "$WATCHFRR" = "watchfrr"]) +AM_CONDITIONAL([OSPFCLIENT], [test "$OSPFCLIENT" = "ospfclient"]) +AM_CONDITIONAL([RIPNGD], [test "$enable_ripngd" != "no"]) +AM_CONDITIONAL([BABELD], [test "$enable_babeld" != "no"]) +AM_CONDITIONAL([OSPF6D], [test "$enable_ospf6d" != "no"]) +AM_CONDITIONAL([ISISD], [test "$enable_isisd" != "no"]) +AM_CONDITIONAL([PIMD], [test "$enable_pimd" != "no"]) +AM_CONDITIONAL([PBRD], [test "$enable_pbrd" != "no"]) +AM_CONDITIONAL([SHARPD], [test "$enable_sharpd" = "yes"]) +AM_CONDITIONAL([STATICD], [test "$enable_staticd" != "no"]) +AM_CONDITIONAL([FABRICD], [test "$enable_fabricd" != "no"]) +AM_CONDITIONAL([VRRPD], [test "$enable_vrrpd" != "no"]) AC_CONFIG_FILES([Makefile],[sed -e 's/^#AUTODERP# //' -i Makefile]) @@ -2363,7 +2363,7 @@ AC_CONFIG_COMMANDS([lib/route_types.h], [ ${PERL} "${ac_abs_top_srcdir}/lib/route_types.pl" \ < "${ac_abs_top_srcdir}/lib/route_types.txt" \ > "${dst}.tmp" - test -f "${dst}" \ + test -f "$dst" \ && diff "${dst}.tmp" "${dst}" >/dev/null 2>/dev/null \ && rm "${dst}.tmp" \ || mv "${dst}.tmp" "${dst}" @@ -2371,13 +2371,13 @@ AC_CONFIG_COMMANDS([lib/route_types.h], [ PERL="$PERL" ]) -AS_IF([test "x$with_pkg_git_version" = "xyes"], [ +AS_IF([test "$with_pkg_git_version" = "yes"], [ AC_CONFIG_COMMANDS([lib/gitversion.h], [ dst="${ac_abs_top_builddir}/lib/gitversion.h" ${PERL} "${ac_abs_top_srcdir}/lib/gitversion.pl" \ "${ac_abs_top_srcdir}" \ > "${dst}.tmp" - test -f "${dst}" \ + test -f "$dst" \ && diff "${dst}.tmp" "${dst}" >/dev/null 2>/dev/null \ && rm "${dst}.tmp" \ || mv "${dst}.tmp" "${dst}" @@ -2414,9 +2414,9 @@ zebra protobuf enabled : ${enable_protobuf:-no} The above user and group must have read/write access to the state file directory and to the config files in the config file directory." -if test "${enable_doc}" != "no" -a "$frr_py_mod_sphinx" = false; then +if test "$enable_doc" != "no" -a "$frr_py_mod_sphinx" = "false"; then AC_MSG_WARN([sphinx is missing but required to build documentation]) fi -if test "$frr_py_mod_pytest" = false; then +if test "$frr_py_mod_pytest" = "false"; then AC_MSG_WARN([pytest is missing, unit tests cannot be performed]) fi diff --git a/doc/developer/cli.rst b/doc/developer/cli.rst index cf35b03f0c..edabe61d92 100644 --- a/doc/developer/cli.rst +++ b/doc/developer/cli.rst @@ -101,7 +101,7 @@ Definition Grammar FRR uses its own grammar for defining CLI commands. The grammar draws from syntax commonly seen in \*nix manpages and should be fairly intuitive. The parser is implemented in Bison and the lexer in Flex. These may be found in -``lib/command_lex.l`` and ``lib/command_parse.y``, respectively. +``lib/command_parse.y`` and ``lib/command_lex.l``, respectively. **ProTip**: if you define a new command and find that the parser is throwing syntax or other errors, the parser is the last place you want @@ -371,11 +371,11 @@ Type rules +----------------------------+--------------------------------+--------------------------+ | ``A.B.C.D + X:X::X:X`` | ``const union sockunion *`` | ``NULL`` | +----------------------------+--------------------------------+--------------------------+ -| ``A.B.C.D/M`` | ``const struct prefix_ipv4 *`` | ``NULL`` | +| ``A.B.C.D/M`` | ``const struct prefix_ipv4 *`` | ``all-zeroes struct`` | +----------------------------+--------------------------------+--------------------------+ -| ``X:X::X:X/M`` | ``const struct prefix_ipv6 *`` | ``NULL`` | +| ``X:X::X:X/M`` | ``const struct prefix_ipv6 *`` | ``all-zeroes struct`` | +----------------------------+--------------------------------+--------------------------+ -| ``A.B.C.D/M + X:X::X:X/M`` | ``const struct prefix *`` | ``NULL`` | +| ``A.B.C.D/M + X:X::X:X/M`` | ``const struct prefix *`` | ``all-zeroes struct`` | +----------------------------+--------------------------------+--------------------------+ | ``(0-9)`` | ``long`` | ``0`` | +----------------------------+--------------------------------+--------------------------+ @@ -395,8 +395,10 @@ Note the following details: ``word`` tokens (e.g. constant words). This is useful if some parts of a command are optional. The type will be ``const char *``. - ``[no]`` will be passed as ``const char *no``. -- Pointers will be ``NULL`` when the argument is optional and the user did not - use it. +- Most pointers will be ``NULL`` when the argument is optional and the + user did not supply it. As noted in the table above, some prefix + struct type arguments are passed as pointers to all-zeroes structs, + not as ``NULL`` pointers. - If a parameter is not a pointer, but is optional and the user didn't use it, the default value will be passed. Check the ``_str`` argument if you need to determine whether the parameter was omitted. diff --git a/doc/developer/library.rst b/doc/developer/library.rst index a904a4e778..3d5c6a2a15 100644 --- a/doc/developer/library.rst +++ b/doc/developer/library.rst @@ -15,5 +15,6 @@ Library Facilities (libfrr) hooks cli modules + lua diff --git a/doc/developer/lists.rst b/doc/developer/lists.rst index 5f020060ce..853c65ddf3 100644 --- a/doc/developer/lists.rst +++ b/doc/developer/lists.rst @@ -1,3 +1,5 @@ +.. _lists: + List implementations ==================== diff --git a/doc/developer/locking.rst b/doc/developer/locking.rst index aee05aae06..d698789f9f 100644 --- a/doc/developer/locking.rst +++ b/doc/developer/locking.rst @@ -1,3 +1,5 @@ +.. _locking: + Locking ======= diff --git a/doc/developer/logging.rst b/doc/developer/logging.rst index e393fe6fba..db577c9216 100644 --- a/doc/developer/logging.rst +++ b/doc/developer/logging.rst @@ -1,3 +1,5 @@ +.. _logging: + Developer's Guide to Logging ============================ diff --git a/doc/developer/lua.rst b/doc/developer/lua.rst new file mode 100644 index 0000000000..23eb35fc58 --- /dev/null +++ b/doc/developer/lua.rst @@ -0,0 +1,65 @@ +.. _lua: + +Lua +=== + +Lua is currently experimental within FRR and has very limited +support. If you would like to compile FRR with Lua you must +follow these steps: + +1. Installation of Relevant Libraries + + .. code-block:: shell + + apt-get install lua5.3 liblua5-3 liblua5.3-dev + + These are the Debian libraries that are needed. There should + be equivalent RPM's that can be found + +2. Compilation + + Configure needs these options + + .. code-block:: shell + + ./configure --enable-dev-build --enable-lua <all other interesting options> + + Typically you just include the two new enable lines to build with it. + +3. Using Lua + + * Copy tools/lua.scr into /etc/frr + + * Create a route-map match command + + .. code-block:: console + + ! + router bgp 55 + neighbor 10.50.11.116 remote-as external + address-family ipv4 unicast + neighbor 10.50.11.116 route-map TEST in + exit-address-family + ! + route-map TEST permit 10 + match command mooey + ! + + * In the lua.scr file make sure that you have a function named 'mooey' + + .. code-block:: console + + function mooey () + zlog_debug(string.format("afi: %d: %s %d ifdx: %d aspath: %s localpref: %d", + prefix.family, prefix.route, nexthop.metric, + nexthop.ifindex, nexthop.aspath, nexthop.localpref)) + + nexthop.metric = 33 + nexthop.localpref = 13 + return 3 + end + +4. General Comments + + Please be aware that this is extremely experimental and needs a ton of work + to get this up into a state that is usable. diff --git a/doc/developer/modules.rst b/doc/developer/modules.rst index 763d8b1b8d..02330ddfe4 100644 --- a/doc/developer/modules.rst +++ b/doc/developer/modules.rst @@ -1,3 +1,5 @@ +.. _modules: + Modules ======= diff --git a/doc/developer/static-linking.rst b/doc/developer/static-linking.rst index bc33207b38..1e45c48dc3 100644 --- a/doc/developer/static-linking.rst +++ b/doc/developer/static-linking.rst @@ -10,7 +10,7 @@ likely to be present on a given platform - libfrr and libyang. The resultant binaries should still be fairly portable. For example, here is the DSO dependency list for `bgpd` after using these steps: -.. code-block:: +.. code-block:: shell $ ldd bgpd linux-vdso.so.1 (0x00007ffe3a989000) @@ -56,7 +56,7 @@ usable for our purposes. So download ``libpcre`` from `SourceForge <https://sourceforge.net/projects/pcre/>`_, and build it like this: -.. code-block:: +.. code-block:: shell ./configure --with-pic make diff --git a/doc/developer/subdir.am b/doc/developer/subdir.am index 791f7679a6..538a290c34 100644 --- a/doc/developer/subdir.am +++ b/doc/developer/subdir.am @@ -34,6 +34,7 @@ dev_RSTFILES = \ doc/developer/lists.rst \ doc/developer/locking.rst \ doc/developer/logging.rst \ + doc/developer/lua.rst \ doc/developer/memtypes.rst \ doc/developer/modules.rst \ doc/developer/next-hop-tracking.rst \ diff --git a/doc/manpages/conf.py b/doc/manpages/conf.py index 9121d38fe0..8b9bb021a3 100644 --- a/doc/manpages/conf.py +++ b/doc/manpages/conf.py @@ -192,7 +192,7 @@ html_theme = 'default' # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = [] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied diff --git a/doc/user/bgp.rst b/doc/user/bgp.rst index bacb69b815..85ccc277a8 100644 --- a/doc/user/bgp.rst +++ b/doc/user/bgp.rst @@ -924,6 +924,11 @@ Route Aggregation-IPv4 Address Family Apply a route-map for an aggregated prefix. +.. index:: aggregate-address A.B.C.D/M origin <egp|igp|incomplete> +.. clicmd:: aggregate-address A.B.C.D/M origin <egp|igp|incomplete> + + Override ORIGIN for an aggregated prefix. + .. index:: aggregate-address A.B.C.D/M as-set .. clicmd:: aggregate-address A.B.C.D/M as-set @@ -971,6 +976,11 @@ Route Aggregation-IPv6 Address Family Apply a route-map for an aggregated prefix. +.. index:: aggregate-address X:X::X:X/M origin <egp|igp|incomplete> +.. clicmd:: aggregate-address X:X::X:X/M origin <egp|igp|incomplete> + + Override ORIGIN for an aggregated prefix. + .. index:: aggregate-address X:X::X:X/M as-set .. clicmd:: aggregate-address X:X::X:X/M as-set @@ -1205,6 +1215,14 @@ Configuring Peers keyword `all` is specified the modification is done also for routes learned via iBGP. +.. index:: neighbor PEER attribute-unchanged [{as-path|next-hop|med}] +.. clicmd:: neighbor PEER attribute-unchanged [{as-path|next-hop|med}] + + This command specifies attributes to be left unchanged for advertisements + sent to a peer. Use this to leave the next-hop unchanged in ipv6 + configurations, as the route-map directive to leave the next-hop unchanged + is only available for ipv4. + .. index:: [no] neighbor PEER update-source <IFNAME|ADDRESS> .. clicmd:: [no] neighbor PEER update-source <IFNAME|ADDRESS> @@ -2394,6 +2412,12 @@ Debugging Show all enabled debugs. +.. index:: show bgp listeners +.. clicmd:: show bgp listeners + + Display Listen sockets and the vrf that created them. Useful for debugging of when + listen is not working and this is considered a developer debug statement. + .. index:: [no] debug bgp neighbor-events .. clicmd:: [no] debug bgp neighbor-events diff --git a/doc/user/overview.rst b/doc/user/overview.rst index 262c0117df..e31799c1ef 100644 --- a/doc/user/overview.rst +++ b/doc/user/overview.rst @@ -292,16 +292,22 @@ BGP :t:`BGP/MPLS IP Virtual Private Networks (VPNs). Y. Rekhter. Feb 2006.` - :rfc:`4659` :t:`BGP-MPLS IP Virtual Private Network (VPN) Extension for IPv6 VPN. J. De Clercq, D. Ooms, M. Carugi, F. Le Faucheur. September 2006.` +- :rfc:`4893` + :t:`BGP Support for Four-octet AS Number Space. Q. Vohra, E. Chen May 2007.` - :rfc:`5004` :t:`Avoid BGP Best Path Transitions from One External to Another. E. Chen & S. Sangli. September 2007 (Partial support).` - :rfc:`5082` :t:`The Generalized TTL Security Mechanism (GTSM). V. Gill, J. Heasley, D. Meyer, P. Savola, C. Pingnataro. October 2007.` - :rfc:`5575` :t:`Dissemination of Flow Specification Rules. P. Marques, N. Sheth, R. Raszuk, B. Greene, J. Mauch, D. McPherson. August 2009` +- :rfc:`6608` + :t:`Subcodes for BGP Finite State Machine Error. J. Dong, M. Chen, Huawei Technologies, A. Suryanarayana, Cisco Systems. May 2012.` - :rfc:`6810` :t:`The Resource Public Key Infrastructure (RPKI) to Router Protocol. R. Bush, R. Austein. January 2013.` - :rfc:`6811` :t:`BGP Prefix Origin Validation. P. Mohapatra, J. Scudder, D. Ward, R. Bush, R. Austein. January 2013.` +- :rfc:`7607` + :t:`Codification of AS 0 Processing. W. Kumari, R. Bush, H. Schiller, K. Patel. August 2015.` - :rfc:`7611` :t:`BGP ACCEPT_OWN Community Attribute. J. Uttaro, P. Mohapatra, D. Smith, R. Raszuk, J. Scudder. August 2015.` - :rfc:`7999` @@ -445,4 +451,4 @@ For information on reporting bugs, please see :ref:`bug-reports`. .. _frr: |package-url| .. _github: https://github.com/frrouting/frr/ .. _github issues: https://github.com/frrouting/frr/issues -.. _slack: https://frrouting.slack.com/ +.. _slack: https://frrouting.org/#participate diff --git a/doc/user/pim.rst b/doc/user/pim.rst index 6bda692607..36c8b44aa4 100644 --- a/doc/user/pim.rst +++ b/doc/user/pim.rst @@ -174,6 +174,13 @@ PIM interface commands allow you to configure an interface as either a Receiver or a interface that you would like to form pim neighbors on. If the interface is in a vrf, enter the interface command with the vrf keyword at the end. +.. index:: ip pim active-active +.. clicmd:: ip pim active-active + + Turn on pim active-active configuration for a Vxlan interface. This + command will not do anything if you do not have the underlying ability + of a mlag implementation. + .. index:: ip pim bfd .. clicmd:: ip pim bfd @@ -392,6 +399,11 @@ cause great confusion. Display information about interfaces PIM is using. +.. index:: show ip pim mlag [vrf NAME] interface [detail|WORD] [json] +.. clicmd:: show ip pim mlag [vrf NAME|all] interface [detail|WORD] [json] + + Display mlag interface information. + .. index:: show ip pim [vrf NAME] join [A.B.C.D [A.B.C.D]] [json] .. clicmd:: show ip pim join @@ -404,6 +416,11 @@ cause great confusion. Display information about PIM interface local-membership. +.. index:: show ip pim mlag summary [json] +.. clicmd:: show ip pim mlag summary [json] + + Display mlag information state that PIM is keeping track of. + .. index:: show ip pim neighbor .. clicmd:: show ip pim neighbor @@ -461,6 +478,18 @@ cause great confusion. Display upstream information for S,G's and the RPF data associated with them. +.. index:: show ip pim [vrf NAME] mlag upstream [A.B.C.D [A.B.C.D]] [json] +.. clicmd:: show ip pim mlag upstream + + Display upstream entries that are synced across MLAG switches. + Allow the user to specify sub Source and Groups address filters. + +.. index:: show ip pim mlag summary +.. clicmd:: show ip pim mlag summary + + Display PIM MLAG (multi-chassis link aggregation) session status and + control message statistics. + .. index:: show ip pim bsr .. clicmd:: show ip pim bsr diff --git a/doc/user/routemap.rst b/doc/user/routemap.rst index 435639c291..472e2c53ff 100644 --- a/doc/user/routemap.rst +++ b/doc/user/routemap.rst @@ -273,6 +273,16 @@ Route Map Set Command Set the BGP local preference to `local_pref`. +.. index:: set local-preference +LOCAL_PREF +.. clicmd:: set local-preference +LOCAL_PREF + + Add the BGP local preference to an existing `local_pref`. + +.. index:: set local-preference -LOCAL_PREF +.. clicmd:: set local-preference -LOCAL_PREF + + Subtract the BGP local preference from an existing `local_pref`. + .. index:: [no] set distance DISTANCE .. clicmd:: [no] set distance DISTANCE @@ -346,6 +356,27 @@ Route Map Exit Action Command Proceed processing the route-map at the first entry whose order is >= N +.. _route-map-optimization-command: + +Route Map Optimization Command +============================== + +.. index:: route-map optimization +.. clicmd:: route-map optimization + + Enable route-map processing optimization. The optimization is + enabled by default. + Instead of sequentially passing through all the route-map indexes + until a match is found, the search for the best-match index will be + based on a look-up in a prefix-tree. A per-route-map prefix-tree + will be constructed for this purpose. The prefix-tree will compose + of all the prefixes in all the prefix-lists that are included in the + match rule of all the sequences of a route-map. + +.. index:: no route-map optimization +.. clicmd:: no route-map optimization + + Disable the route-map processing optimization. Route Map Examples ================== diff --git a/doc/user/rpki.rst b/doc/user/rpki.rst index dfac10b4f2..f8ec98c964 100644 --- a/doc/user/rpki.rst +++ b/doc/user/rpki.rst @@ -200,6 +200,18 @@ Debugging Displaying RPKI --------------- +.. index:: show rpki prefix <A.B.C.D/M|X:X::X:X/M> [(1-4294967295)] +.. clicmd:: show rpki prefix <A.B.C.D/M|X:X::X:X/M> [(1-4294967295)] + + Display validated prefixes received from the cache servers filtered + by the specified prefix. + +.. index:: show rpki as-number ASN +.. clicmd:: show rpki as-number ASN + + Display validated prefixes received from the cache servers filtered + by ASN. + .. index:: show rpki prefix-table .. clicmd:: show rpki prefix-table diff --git a/doc/user/vrrp.rst b/doc/user/vrrp.rst index 435580131b..33582ee446 100644 --- a/doc/user/vrrp.rst +++ b/doc/user/vrrp.rst @@ -140,7 +140,7 @@ macvlan device. If you are using ``iproute2``, the equivalent configuration is: ip link set dev vrrp4-2-1 up ip link add vrrp6-2-1 link eth0 addrgenmode random type macvlan mode bridge - ip link set dev vrrp4-2-1 address 00:00:5e:00:02:05 + ip link set dev vrrp6-2-1 address 00:00:5e:00:02:05 ip addr add 2001:db8::370:7334/64 dev vrrp6-2-1 ip link set dev vrrp6-2-1 up diff --git a/eigrpd/eigrp_packet.c b/eigrpd/eigrp_packet.c index 6367ef58ab..6090a1ef13 100644 --- a/eigrpd/eigrp_packet.c +++ b/eigrpd/eigrp_packet.c @@ -351,13 +351,13 @@ int eigrp_write(struct thread *thread) ep = eigrp_fifo_next(ei->obuf); if (!ep) { flog_err(EC_LIB_DEVELOPMENT, - "%s: Interface %s no packet on queue?", - __PRETTY_FUNCTION__, ei->ifp->name); + "%s: Interface %s no packet on queue?", __func__, + ei->ifp->name); goto out; } if (ep->length < EIGRP_HEADER_LEN) { flog_err(EC_EIGRP_PACKET, "%s: Packet just has a header?", - __PRETTY_FUNCTION__); + __func__); eigrp_header_dump((struct eigrp_header *)ep->s->data); eigrp_packet_delete(ei); goto out; @@ -749,7 +749,7 @@ static struct stream *eigrp_recv_packet(struct eigrp *eigrp, ip_len = iph->ip_len; -#if !defined(GNU_LINUX) && (OpenBSD < 200311) && (__FreeBSD_version < 1000000) +#if defined(__FreeBSD__) && (__FreeBSD_version < 1000000) /* * Kernel network code touches incoming IP header parameters, * before protocol specific processing. @@ -1205,7 +1205,7 @@ uint16_t eigrp_add_internalTLV_to_stream(struct stream *s, break; default: flog_err(EC_LIB_DEVELOPMENT, "%s: Unexpected prefix length: %d", - __PRETTY_FUNCTION__, pe->destination->prefixlen); + __func__, pe->destination->prefixlen); return 0; } stream_putl(s, 0x00000000); diff --git a/eigrpd/eigrp_reply.c b/eigrpd/eigrp_reply.c index ccf0496736..79405efbbf 100644 --- a/eigrpd/eigrp_reply.c +++ b/eigrpd/eigrp_reply.c @@ -173,7 +173,7 @@ void eigrp_reply_receive(struct eigrp *eigrp, struct ip *iph, flog_err( EC_EIGRP_PACKET, "%s: Received prefix %s which we do not know about", - __PRETTY_FUNCTION__, + __func__, prefix2str(&dest_addr, buf, sizeof(buf))); eigrp_IPv4_InternalTLV_free(tlv); continue; diff --git a/eigrpd/eigrp_routemap.c b/eigrpd/eigrp_routemap.c index 99cc34d3d0..e15f777954 100644 --- a/eigrpd/eigrp_routemap.c +++ b/eigrpd/eigrp_routemap.c @@ -295,7 +295,7 @@ static void *route_match_metric_compile(const char *arg) { // uint32_t *metric; // - // metric = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (uint32_t)); + // metric = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof(uint32_t)); // *metric = atoi (arg); // // if(*metric > 0) @@ -574,7 +574,7 @@ static void *route_match_tag_compile(const char *arg) { // unsigned short *tag; // - // tag = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (unsigned short)); + // tag = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof(unsigned short)); // *tag = atoi (arg); // // return tag; @@ -667,7 +667,7 @@ static void *route_set_metric_compile(const char *arg) // return NULL;*/ // // mod = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, - // sizeof (struct rip_metric_modifier)); + // sizeof(struct rip_metric_modifier)); // mod->type = type; // mod->metric = metric; @@ -718,7 +718,7 @@ static void *route_set_ip_nexthop_compile(const char *arg) // int ret; // struct in_addr *address; // - // address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct + // address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof(struct // in_addr)); // // ret = inet_aton (arg, address); @@ -775,7 +775,7 @@ static void *route_set_tag_compile(const char *arg) { // unsigned short *tag; // - // tag = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (unsigned short)); + // tag = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof(unsigned short)); // *tag = atoi (arg); // // return tag; diff --git a/eigrpd/eigrp_topology.c b/eigrpd/eigrp_topology.c index 56dbe3d85e..7676af15f2 100644 --- a/eigrpd/eigrp_topology.c +++ b/eigrpd/eigrp_topology.c @@ -138,7 +138,7 @@ void eigrp_prefix_entry_add(struct route_table *topology, zlog_debug( "%s: %s Should we have found this entry in the topo table?", - __PRETTY_FUNCTION__, + __func__, prefix2str(pe->destination, buf, sizeof(buf))); } route_unlock_node(rn); @@ -402,7 +402,7 @@ eigrp_topology_update_distance(struct eigrp_fsm_action_message *msg) break; default: flog_err(EC_LIB_DEVELOPMENT, "%s: Please implement handler", - __PRETTY_FUNCTION__); + __func__); break; } distance_done: @@ -175,7 +175,7 @@ static inline size_t fpm_msg_align(size_t len) * The (rounded up) size of the FPM message header. This ensures that * the message payload always starts at an aligned address. */ -#define FPM_MSG_HDR_LEN (sizeof (fpm_msg_hdr_t)) +#define FPM_MSG_HDR_LEN (sizeof(fpm_msg_hdr_t)) #ifndef COMPILE_ASSERT #define COMPILE_ASSERT(x) extern int __dummy[2 * !!(x) - 1] diff --git a/isisd/isis_circuit.c b/isisd/isis_circuit.c index 8343f7d85f..e4152a8712 100644 --- a/isisd/isis_circuit.c +++ b/isisd/isis_circuit.c @@ -1386,7 +1386,6 @@ int isis_if_delete_hook(struct interface *ifp) if (ifp && ifp->info) { circuit = ifp->info; isis_csm_state_change(IF_DOWN_FROM_Z, circuit, circuit->area); - isis_csm_state_change(ISIS_DISABLE, circuit, circuit->area); } return 0; diff --git a/isisd/isis_misc.c b/isisd/isis_misc.c index a7f491e87d..96b76da92d 100644 --- a/isisd/isis_misc.c +++ b/isisd/isis_misc.c @@ -562,19 +562,12 @@ void vty_multiline(struct vty *vty, const char *prefix, const char *format, ...) void vty_out_timestr(struct vty *vty, time_t uptime) { - struct tm *tm; time_t difftime = time(NULL); + char buf[MONOTIME_STRLEN]; + difftime -= uptime; - tm = gmtime(&difftime); - - if (difftime < ONE_DAY_SECOND) - vty_out(vty, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, - tm->tm_sec); - else if (difftime < ONE_WEEK_SECOND) - vty_out(vty, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour, - tm->tm_min); - else - vty_out(vty, "%02dw%dd%02dh", tm->tm_yday / 7, - tm->tm_yday - ((tm->tm_yday / 7) * 7), tm->tm_hour); - vty_out(vty, " ago"); + + frrtime_to_interval(difftime, buf, sizeof(buf)); + + vty_out(vty, "%s ago", buf); } diff --git a/isisd/isis_pdu.c b/isisd/isis_pdu.c index cc22aa5ffd..9153512623 100644 --- a/isisd/isis_pdu.c +++ b/isisd/isis_pdu.c @@ -1652,7 +1652,7 @@ int isis_handle_pdu(struct isis_circuit *circuit, uint8_t *ssnpa) if (length != expected_length) { flog_err(EC_ISIS_PACKET, - "Exepected fixed header length = %" PRIu8 + "Expected fixed header length = %" PRIu8 " but got %" PRIu8, expected_length, length); return ISIS_ERROR; diff --git a/isisd/isis_tlvs.c b/isisd/isis_tlvs.c index df6280e5c3..5b0b709206 100644 --- a/isisd/isis_tlvs.c +++ b/isisd/isis_tlvs.c @@ -2266,7 +2266,7 @@ static int unpack_tlv_spine_leaf(enum isis_tlv_context context, sbuf_push(log, indent, "Unpacking Spine Leaf Extension TLV...\n"); if (tlv_len < 2) { - sbuf_push(log, indent, "WARNING: Unexepected TLV size\n"); + sbuf_push(log, indent, "WARNING: Unexpected TLV size\n"); stream_forward_getp(s, tlv_len); return 0; } @@ -2382,7 +2382,7 @@ static int unpack_tlv_threeway_adj(enum isis_tlv_context context, sbuf_push(log, indent, "Unpacking P2P Three-Way Adjacency TLV...\n"); if (tlv_len != 5 && tlv_len != 15) { - sbuf_push(log, indent, "WARNING: Unexepected TLV size\n"); + sbuf_push(log, indent, "WARNING: Unexpected TLV size\n"); stream_forward_getp(s, tlv_len); return 0; } diff --git a/isisd/isis_vty_fabricd.c b/isisd/isis_vty_fabricd.c index 24e5c51947..09b8d28258 100644 --- a/isisd/isis_vty_fabricd.c +++ b/isisd/isis_vty_fabricd.c @@ -115,6 +115,7 @@ DEFUN (no_triggered_csnp, static void lsp_print_flooding(struct vty *vty, struct isis_lsp *lsp) { char lspid[255]; + char buf[MONOTIME_STRLEN]; lspid_print(lsp->hdr.lsp_id, lspid, true, true); vty_out(vty, "Flooding information for %s\n", lspid); @@ -129,19 +130,10 @@ static void lsp_print_flooding(struct vty *vty, struct isis_lsp *lsp) lsp->flooding_interface : "(null)"); time_t uptime = time(NULL) - lsp->flooding_time; - struct tm *tm = gmtime(&uptime); - - if (uptime < ONE_DAY_SECOND) - vty_out(vty, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, - tm->tm_sec); - else if (uptime < ONE_WEEK_SECOND) - vty_out(vty, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour, - tm->tm_min); - else - vty_out(vty, "%02dw%dd%02dh", tm->tm_yday / 7, - tm->tm_yday - ((tm->tm_yday / 7) * 7), - tm->tm_hour); - vty_out(vty, " ago)\n"); + + frrtime_to_interval(uptime, buf, sizeof(buf)); + + vty_out(vty, "%s ago)\n", buf); if (lsp->flooding_circuit_scoped) { vty_out(vty, " Received as circuit-scoped LSP, so not " diff --git a/ldpd/address.c b/ldpd/address.c index 9c1564a31f..74a3f5a309 100644 --- a/ldpd/address.c +++ b/ldpd/address.c @@ -67,7 +67,7 @@ send_address(struct nbr *nbr, int af, struct if_addr_head *addr_list, fatalx("send_address: unknown af"); } - while ((if_addr = LIST_FIRST(addr_list)) != NULL) { + while (LIST_FIRST(addr_list) != NULL) { /* * Send as many addresses as possible - respect the session's * negotiated maximum pdu length. diff --git a/ldpd/hello.c b/ldpd/hello.c index d17e80008e..a8d6e58cda 100644 --- a/ldpd/hello.c +++ b/ldpd/hello.c @@ -169,7 +169,7 @@ recv_hello(struct in_addr lsr_id, struct ldp_msg *msg, int af, int tlvs_rcvd; int ds_tlv; union ldpd_addr trans_addr; - uint32_t scope_id = 0; + ifindex_t scope_id = 0; uint32_t conf_seqnum; uint16_t trans_pref; int r; diff --git a/ldpd/interface.c b/ldpd/interface.c index 8b45703d22..c7d6dea518 100644 --- a/ldpd/interface.c +++ b/ldpd/interface.c @@ -109,7 +109,7 @@ ldpe_if_exit(struct iface *iface) } struct iface * -if_lookup(struct ldpd_conf *xconf, unsigned short ifindex) +if_lookup(struct ldpd_conf *xconf, ifindex_t ifindex) { struct iface *iface; diff --git a/ldpd/lde.c b/ldpd/lde.c index 006d27f6ab..5f94031320 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -71,9 +71,6 @@ struct nbr_tree lde_nbrs = RB_INITIALIZER(&lde_nbrs); static struct imsgev *iev_ldpe; static struct imsgev *iev_main, *iev_main_sync; -/* Master of threads. */ -struct thread_master *master; - /* lde privileges */ static zebra_capabilities_t _caps_p [] = { diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index dcbcf8ce50..78b1c3e544 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -86,6 +86,8 @@ static struct imsgev *iev_lde, *iev_lde_sync; static pid_t ldpe_pid; static pid_t lde_pid; +enum ldpd_process ldpd_process; + #define LDP_DEFAULT_CONFIG "ldpd.conf" #define LDP_VTY_PORT 2612 @@ -858,7 +860,6 @@ ldp_acl_request(struct imsgev *iev, char *acl_name, int af, union ldpd_addr *addr, uint8_t prefixlen) { struct imsg imsg; - ssize_t n; struct acl_check acl_check; if (acl_name[0] == '\0') @@ -876,9 +877,9 @@ ldp_acl_request(struct imsgev *iev, char *acl_name, int af, imsg_flush(&iev->ibuf); /* receive (blocking) and parse result */ - if ((n = imsg_read(&iev->ibuf)) == -1) + if (imsg_read(&iev->ibuf) == -1) fatal("imsg_read error"); - if ((n = imsg_get(&iev->ibuf, &imsg)) == -1) + if (imsg_get(&iev->ibuf, &imsg) == -1) fatal("imsg_get"); if (imsg.hdr.type != IMSG_ACL_CHECK || imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(int)) @@ -1408,7 +1409,7 @@ merge_ifaces(struct ldpd_conf *conf, struct ldpd_conf *xconf) RB_FOREACH_SAFE(iface, iface_head, &conf->iface_tree, itmp) { /* find deleted interfaces */ - if ((xi = if_lookup_name(xconf, iface->name)) == NULL) { + if (if_lookup_name(xconf, iface->name) == NULL) { switch (ldpd_process) { case PROC_LDP_ENGINE: ldpe_if_exit(iface); @@ -1469,7 +1470,7 @@ merge_tnbrs(struct ldpd_conf *conf, struct ldpd_conf *xconf) continue; /* find deleted tnbrs */ - if ((xt = tnbr_find(xconf, tnbr->af, &tnbr->addr)) == NULL) { + if (tnbr_find(xconf, tnbr->af, &tnbr->addr) == NULL) { switch (ldpd_process) { case PROC_LDP_ENGINE: tnbr->flags &= ~F_TNBR_CONFIGURED; @@ -1515,33 +1516,35 @@ merge_nbrps(struct ldpd_conf *conf, struct ldpd_conf *xconf) RB_FOREACH_SAFE(nbrp, nbrp_head, &conf->nbrp_tree, ntmp) { /* find deleted nbrps */ - if ((xn = nbr_params_find(xconf, nbrp->lsr_id)) == NULL) { - switch (ldpd_process) { - case PROC_LDP_ENGINE: - nbr = nbr_find_ldpid(nbrp->lsr_id.s_addr); - if (nbr) { - session_shutdown(nbr, S_SHUTDOWN, 0, 0); + if (nbr_params_find(xconf, nbrp->lsr_id) != NULL) + continue; + + switch (ldpd_process) { + case PROC_LDP_ENGINE: + nbr = nbr_find_ldpid(nbrp->lsr_id.s_addr); + if (nbr) { + session_shutdown(nbr, S_SHUTDOWN, 0, 0); #ifdef __OpenBSD__ - pfkey_remove(nbr); + pfkey_remove(nbr); #else - sock_set_md5sig( - (ldp_af_global_get(&global, - nbr->af))->ldp_session_socket, - nbr->af, &nbr->raddr, NULL); + sock_set_md5sig( + (ldp_af_global_get(&global, nbr->af)) + ->ldp_session_socket, + nbr->af, &nbr->raddr, NULL); #endif - nbr->auth.method = AUTH_NONE; - if (nbr_session_active_role(nbr)) - nbr_establish_connection(nbr); - } - break; - case PROC_LDE_ENGINE: - case PROC_MAIN: - break; + nbr->auth.method = AUTH_NONE; + if (nbr_session_active_role(nbr)) + nbr_establish_connection(nbr); } - RB_REMOVE(nbrp_head, &conf->nbrp_tree, nbrp); - free(nbrp); + break; + case PROC_LDE_ENGINE: + case PROC_MAIN: + break; } + RB_REMOVE(nbrp_head, &conf->nbrp_tree, nbrp); + free(nbrp); } + RB_FOREACH_SAFE(xn, nbrp_head, &xconf->nbrp_tree, ntmp) { /* find new nbrps */ if ((nbrp = nbr_params_find(conf, xn->lsr_id)) == NULL) { @@ -1624,7 +1627,7 @@ merge_l2vpns(struct ldpd_conf *conf, struct ldpd_conf *xconf) RB_FOREACH_SAFE(l2vpn, l2vpn_head, &conf->l2vpn_tree, ltmp) { /* find deleted l2vpns */ - if ((xl = l2vpn_find(xconf, l2vpn->name)) == NULL) { + if (l2vpn_find(xconf, l2vpn->name) == NULL) { switch (ldpd_process) { case PROC_LDE_ENGINE: l2vpn_exit(l2vpn); @@ -1680,14 +1683,14 @@ merge_l2vpn(struct ldpd_conf *xconf, struct l2vpn *l2vpn, struct l2vpn *xl) /* merge intefaces */ RB_FOREACH_SAFE(lif, l2vpn_if_head, &l2vpn->if_tree, ftmp) { /* find deleted interfaces */ - if ((xf = l2vpn_if_find(xl, lif->ifname)) == NULL) { + if (l2vpn_if_find(xl, lif->ifname) == NULL) { RB_REMOVE(l2vpn_if_head, &l2vpn->if_tree, lif); free(lif); } } RB_FOREACH_SAFE(xf, l2vpn_if_head, &xl->if_tree, ftmp) { /* find new interfaces */ - if ((lif = l2vpn_if_find(l2vpn, xf->ifname)) == NULL) { + if (l2vpn_if_find(l2vpn, xf->ifname) == NULL) { COPY(lif, xf); RB_INSERT(l2vpn_if_head, &l2vpn->if_tree, lif); lif->l2vpn = l2vpn; @@ -1706,7 +1709,7 @@ merge_l2vpn(struct ldpd_conf *xconf, struct l2vpn *l2vpn, struct l2vpn *xl) /* merge active pseudowires */ RB_FOREACH_SAFE(pw, l2vpn_pw_head, &l2vpn->pw_tree, ptmp) { /* find deleted active pseudowires */ - if ((xp = l2vpn_pw_find_active(xl, pw->ifname)) == NULL) { + if (l2vpn_pw_find_active(xl, pw->ifname) == NULL) { switch (ldpd_process) { case PROC_LDE_ENGINE: l2vpn_pw_exit(pw); @@ -1807,7 +1810,7 @@ merge_l2vpn(struct ldpd_conf *xconf, struct l2vpn *l2vpn, struct l2vpn *xl) /* merge inactive pseudowires */ RB_FOREACH_SAFE(pw, l2vpn_pw_head, &l2vpn->pw_inactive_tree, ptmp) { /* find deleted inactive pseudowires */ - if ((xp = l2vpn_pw_find_inactive(xl, pw->ifname)) == NULL) { + if (l2vpn_pw_find_inactive(xl, pw->ifname) == NULL) { RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw); free(pw); } diff --git a/ldpd/ldpd.h b/ldpd/ldpd.h index bd7562e5ad..006780f032 100644 --- a/ldpd/ldpd.h +++ b/ldpd/ldpd.h @@ -306,7 +306,7 @@ struct iface_af { struct iface { RB_ENTRY(iface) entry; char name[IF_NAMESIZE]; - unsigned int ifindex; + ifindex_t ifindex; struct if_addr_head addr_list; struct in6_addr linklocal; enum iface_type type; @@ -391,7 +391,7 @@ struct l2vpn_if { RB_ENTRY(l2vpn_if) entry; struct l2vpn *l2vpn; char ifname[IF_NAMESIZE]; - unsigned int ifindex; + ifindex_t ifindex; int operative; uint8_t mac[ETH_ALEN]; QOBJ_FIELDS @@ -408,7 +408,7 @@ struct l2vpn_pw { union ldpd_addr addr; uint32_t pwid; char ifname[IF_NAMESIZE]; - unsigned int ifindex; + ifindex_t ifindex; bool enabled; uint32_t remote_group; uint16_t remote_mtu; @@ -433,7 +433,7 @@ struct l2vpn { int pw_type; int mtu; char br_ifname[IF_NAMESIZE]; - unsigned int br_ifindex; + ifindex_t br_ifindex; struct l2vpn_if_head if_tree; struct l2vpn_pw_head pw_tree; struct l2vpn_pw_head pw_inactive_tree; @@ -446,7 +446,7 @@ DECLARE_QOBJ_TYPE(l2vpn) #define L2VPN_TYPE_VPLS 2 /* ldp_conf */ -enum ldpd_process { +extern enum ldpd_process { PROC_MAIN, PROC_LDP_ENGINE, PROC_LDE_ENGINE @@ -542,7 +542,7 @@ struct kroute { union ldpd_addr nexthop; uint32_t local_label; uint32_t remote_label; - unsigned short ifindex; + ifindex_t ifindex; uint8_t route_type; uint8_t route_instance; uint16_t flags; @@ -550,7 +550,7 @@ struct kroute { struct kaddr { char ifname[IF_NAMESIZE]; - unsigned short ifindex; + ifindex_t ifindex; int af; union ldpd_addr addr; uint8_t prefixlen; @@ -559,7 +559,7 @@ struct kaddr { struct kif { char ifname[IF_NAMESIZE]; - unsigned short ifindex; + ifindex_t ifindex; int flags; int operative; uint8_t mac[ETH_ALEN]; @@ -577,7 +577,7 @@ struct acl_check { struct ctl_iface { int af; char name[IF_NAMESIZE]; - unsigned int ifindex; + ifindex_t ifindex; int state; enum iface_type type; uint16_t hello_holdtime; @@ -760,7 +760,7 @@ int sock_set_bindany(int, int); int sock_set_md5sig(int, int, union ldpd_addr *, const char *); int sock_set_ipv4_tos(int, int); int sock_set_ipv4_pktinfo(int, int); -int sock_set_ipv4_recvdstaddr(int, int); +int sock_set_ipv4_recvdstaddr(int fd, ifindex_t ifindex); int sock_set_ipv4_recvif(int, int); int sock_set_ipv4_minttl(int, int); int sock_set_ipv4_ucast_ttl(int fd, int); @@ -783,7 +783,8 @@ struct fec; const char *log_sockaddr(void *); const char *log_in6addr(const struct in6_addr *); -const char *log_in6addr_scope(const struct in6_addr *, unsigned int); +const char *log_in6addr_scope(const struct in6_addr *addr, + ifindex_t ifidx); const char *log_addr(int, const union ldpd_addr *); char *log_label(uint32_t); const char *log_time(time_t); diff --git a/ldpd/ldpe.c b/ldpd/ldpe.c index c16d92f28b..b34a1ecdd7 100644 --- a/ldpd/ldpe.c +++ b/ldpd/ldpe.c @@ -41,7 +41,7 @@ static int ldpe_dispatch_pfkey(struct thread *); #endif static void ldpe_setup_sockets(int, int, int, int); static void ldpe_close_sockets(int); -static void ldpe_iface_af_ctl(struct ctl_conn *, int, unsigned int); +static void ldpe_iface_af_ctl(struct ctl_conn *c, int af, ifindex_t ifidx); struct ldpd_conf *leconf; #ifdef __OpenBSD__ @@ -54,9 +54,6 @@ static struct imsgev *iev_lde; static struct thread *pfkey_ev; #endif -/* Master of threads. */ -struct thread_master *master; - /* ldpe privileges */ static zebra_capabilities_t _caps_p [] = { @@ -97,6 +94,8 @@ static struct quagga_signal_t ldpe_signals[] = }, }; +char *pkt_ptr; /* packet buffer */ + /* label distribution protocol engine */ void ldpe(void) @@ -828,7 +827,7 @@ ldpe_stop_init_backoff(int af) } static void -ldpe_iface_af_ctl(struct ctl_conn *c, int af, unsigned int idx) +ldpe_iface_af_ctl(struct ctl_conn *c, int af, ifindex_t idx) { struct iface *iface; struct iface_af *ia; @@ -848,7 +847,7 @@ ldpe_iface_af_ctl(struct ctl_conn *c, int af, unsigned int idx) } void -ldpe_iface_ctl(struct ctl_conn *c, unsigned int idx) +ldpe_iface_ctl(struct ctl_conn *c, ifindex_t idx) { ldpe_iface_af_ctl(c, AF_INET, idx); ldpe_iface_af_ctl(c, AF_INET6, idx); diff --git a/ldpd/ldpe.h b/ldpd/ldpe.h index ccff1e803d..11650069b7 100644 --- a/ldpd/ldpe.h +++ b/ldpd/ldpe.h @@ -92,7 +92,7 @@ struct nbr { struct in_addr id; /* lsr id */ union ldpd_addr laddr; /* local address */ union ldpd_addr raddr; /* remote address */ - uint32_t raddr_scope; /* remote address scope (v6) */ + ifindex_t raddr_scope; /* remote address scope (v6) */ time_t uptime; int fd; int state; @@ -208,7 +208,7 @@ void ldpe_reset_ds_nbrs(void); void ldpe_remove_dynamic_tnbrs(int); void ldpe_stop_init_backoff(int); struct ctl_conn; -void ldpe_iface_ctl(struct ctl_conn *, unsigned int); +void ldpe_iface_ctl(struct ctl_conn *c, ifindex_t ifidx); void ldpe_adj_ctl(struct ctl_conn *); void ldpe_adj_detail_ctl(struct ctl_conn *); void ldpe_nbr_ctl(struct ctl_conn *); @@ -219,7 +219,7 @@ void mapping_list_clr(struct mapping_head *); struct iface *if_new(const char *); void ldpe_if_init(struct iface *); void ldpe_if_exit(struct iface *); -struct iface *if_lookup(struct ldpd_conf *, unsigned short); +struct iface *if_lookup(struct ldpd_conf *c, ifindex_t ifidx); struct iface *if_lookup_name(struct ldpd_conf *, const char *); void if_update_info(struct iface *, struct kif *); struct iface_af *iface_af_get(struct iface *, int); @@ -291,7 +291,7 @@ struct tcp_conn *tcp_new(int, struct nbr *); void pending_conn_del(struct pending_conn *); struct pending_conn *pending_conn_find(int, union ldpd_addr *); -char *pkt_ptr; /* packet buffer */ +extern char *pkt_ptr; /* packet buffer */ /* pfkey.c */ #ifdef __OpenBSD__ diff --git a/ldpd/logmsg.c b/ldpd/logmsg.c index a9b066a3da..2c9fbf0dae 100644 --- a/ldpd/logmsg.c +++ b/ldpd/logmsg.c @@ -59,7 +59,7 @@ log_in6addr(const struct in6_addr *addr) } const char * -log_in6addr_scope(const struct in6_addr *addr, unsigned int ifindex) +log_in6addr_scope(const struct in6_addr *addr, ifindex_t ifindex) { struct sockaddr_in6 sa_in6; diff --git a/ldpd/socket.c b/ldpd/socket.c index 8706d03c6f..4909ea7ad8 100644 --- a/ldpd/socket.c +++ b/ldpd/socket.c @@ -209,7 +209,7 @@ sock_set_nonblock(int fd) flags |= O_NONBLOCK; - if ((flags = fcntl(fd, F_SETFL, flags)) == -1) + if (fcntl(fd, F_SETFL, flags) == -1) fatal("fcntl F_SETFL"); } @@ -223,7 +223,7 @@ sock_set_cloexec(int fd) flags |= FD_CLOEXEC; - if ((flags = fcntl(fd, F_SETFD, flags)) == -1) + if (fcntl(fd, F_SETFD, flags) == -1) fatal("fcntl F_SETFD"); } @@ -329,7 +329,7 @@ sock_set_ipv4_tos(int fd, int tos) } int -sock_set_ipv4_recvif(int fd, int enable) +sock_set_ipv4_recvif(int fd, ifindex_t enable) { return (setsockopt_ifindex(AF_INET, fd, enable)); } diff --git a/lib/agentx.c b/lib/agentx.c index b479b5ea4c..d1b801fe8c 100644 --- a/lib/agentx.c +++ b/lib/agentx.c @@ -264,7 +264,7 @@ int smux_trap(struct variable *vp, size_t vp_len, const oid *ename, uint8_t sptrap) { oid objid_snmptrap[] = {1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0}; - size_t objid_snmptrap_len = sizeof objid_snmptrap / sizeof(oid); + size_t objid_snmptrap_len = sizeof(objid_snmptrap) / sizeof(oid); oid notification_oid[MAX_OID_LEN]; size_t notification_oid_len; unsigned int i; @@ -136,7 +136,7 @@ void bfd_peer_sendmsg(struct zclient *zclient, struct bfd_info *bfd_info, if (bfd_debug) zlog_debug( "%s: Suppressing BFD peer reg/dereg messages", - __FUNCTION__); + __func__); return; } @@ -146,7 +146,7 @@ void bfd_peer_sendmsg(struct zclient *zclient, struct bfd_info *bfd_info, zlog_debug( "%s: Can't send BFD peer register, Zebra client not " "established", - __FUNCTION__); + __func__); return; } @@ -328,7 +328,7 @@ static void bfd_last_update(time_t last_update, char *buf, size_t len) { time_t curr; time_t diff; - struct tm *tm; + struct tm tm; struct timeval tv; /* If no BFD satatus update has ever been received, print `never'. */ @@ -341,10 +341,10 @@ static void bfd_last_update(time_t last_update, char *buf, size_t len) monotime(&tv); curr = tv.tv_sec; diff = curr - last_update; - tm = gmtime(&diff); + gmtime_r(&diff, &tm); - snprintf(buf, len, "%d:%02d:%02d:%02d", tm->tm_yday, tm->tm_hour, - tm->tm_min, tm->tm_sec); + snprintf(buf, len, "%d:%02d:%02d:%02d", tm.tm_yday, tm.tm_hour, + tm.tm_min, tm.tm_sec); } /* @@ -454,7 +454,7 @@ void bfd_client_sendmsg(struct zclient *zclient, int command, zlog_debug( "%s: Can't send BFD client register, Zebra client not " "established", - __FUNCTION__); + __func__); return; } diff --git a/lib/buffer.c b/lib/buffer.c index 766b9791a5..ff49bc83df 100644 --- a/lib/buffer.c +++ b/lib/buffer.c @@ -288,7 +288,7 @@ buffer_status_t buffer_flush_window(struct buffer *b, int fd, int width, /* Previously print out is performed. */ if (erase_flag) { iov[iov_index].iov_base = erase; - iov[iov_index].iov_len = sizeof erase; + iov[iov_index].iov_len = sizeof(erase); iov_index++; } @@ -341,7 +341,7 @@ buffer_status_t buffer_flush_window(struct buffer *b, int fd, int width, /* In case of `more' display need. */ if (b->tail && (b->tail->sp < b->tail->cp) && !no_more_flag) { iov[iov_index].iov_base = more; - iov[iov_index].iov_len = sizeof more; + iov[iov_index].iov_len = sizeof(more); iov_index++; } diff --git a/lib/filter.c b/lib/filter.c index 80f8cf0bd0..3226fb2f5e 100644 --- a/lib/filter.c +++ b/lib/filter.c @@ -412,7 +412,7 @@ static int64_t filter_new_seq_get(struct access_list *access) int64_t newseq; struct filter *filter; - maxseq = newseq = 0; + maxseq = 0; for (filter = access->head; filter; filter = filter->next) { if (maxseq < filter->seq) diff --git a/lib/frr_zmq.c b/lib/frr_zmq.c index 7781beae5e..565936a410 100644 --- a/lib/frr_zmq.c +++ b/lib/frr_zmq.c @@ -177,7 +177,7 @@ int funcname_frrzmq_thread_add_read(struct thread_master *master, else { cb = XCALLOC(MTYPE_ZEROMQ_CB, sizeof(struct frrzmq_cb)); - cb->write.cancelled = 1; + cb->write.cancelled = true; *cbp = cb; } @@ -187,7 +187,7 @@ int funcname_frrzmq_thread_add_read(struct thread_master *master, cb->read.cb_msg = msgfunc; cb->read.cb_part = partfunc; cb->read.cb_error = errfunc; - cb->read.cancelled = 0; + cb->read.cancelled = false; if (events & ZMQ_POLLIN) { if (cb->read.thread) { @@ -285,7 +285,7 @@ int funcname_frrzmq_thread_add_write(struct thread_master *master, else { cb = XCALLOC(MTYPE_ZEROMQ_CB, sizeof(struct frrzmq_cb)); - cb->read.cancelled = 1; + cb->read.cancelled = true; *cbp = cb; } @@ -295,7 +295,7 @@ int funcname_frrzmq_thread_add_write(struct thread_master *master, cb->write.cb_msg = msgfunc; cb->write.cb_part = NULL; cb->write.cb_error = errfunc; - cb->write.cancelled = 0; + cb->write.cancelled = false; if (events & ZMQ_POLLOUT) { if (cb->write.thread) { @@ -316,7 +316,7 @@ void frrzmq_thread_cancel(struct frrzmq_cb **cb, struct cb_core *core) { if (!cb || !*cb) return; - core->cancelled = 1; + core->cancelled = true; if (core->thread) { thread_cancel(core->thread); core->thread = NULL; diff --git a/lib/getopt.h b/lib/getopt.h index 138870d199..63e12e947e 100644 --- a/lib/getopt.h +++ b/lib/getopt.h @@ -111,7 +111,7 @@ struct option { #if defined(__STDC__) && __STDC__ -#if REALLY_NEED_PLAIN_GETOPT +#ifdef REALLY_NEED_PLAIN_GETOPT /* * getopt is defined in POSIX.2. Assume that if the system defines diff --git a/lib/hash.h b/lib/hash.h index 7b3372d433..e7ba3187f5 100644 --- a/lib/hash.h +++ b/lib/hash.h @@ -36,11 +36,6 @@ extern "C" { #define HASHWALK_CONTINUE 0 #define HASHWALK_ABORT -1 -#if CONFDATE > 20200225 -CPP_NOTICE("hash.h: time to remove hash_backet #define") -#endif -#define hash_backet hash_bucket - struct hash_bucket { /* * if this bucket is the head of the linked listed, len denotes the @@ -745,12 +745,16 @@ static void if_dump(const struct interface *ifp) struct listnode *node; struct connected *c __attribute__((unused)); - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, c)) + for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, c)) { + struct vrf *vrf = vrf_lookup_by_id(ifp->vrf_id); + zlog_info( - "Interface %s vrf %u index %d metric %d mtu %d " + "Interface %s vrf %s(%u) index %d metric %d mtu %d " "mtu6 %d %s", - ifp->name, ifp->vrf_id, ifp->ifindex, ifp->metric, - ifp->mtu, ifp->mtu6, if_flag_dump(ifp->flags)); + ifp->name, VRF_LOGNAME(vrf), ifp->vrf_id, ifp->ifindex, + ifp->metric, ifp->mtu, ifp->mtu6, + if_flag_dump(ifp->flags)); + } } /* Interface printing for all interface. */ @@ -811,27 +815,25 @@ DEFUN (show_address, "address\n" VRF_CMD_HELP_STR) { - int idx_vrf = 3; - struct listnode *node; - struct interface *ifp; - struct connected *ifc; - struct prefix *p; - vrf_id_t vrf_id = VRF_DEFAULT; + int idx_vrf = 3; + struct listnode *node; + struct interface *ifp; + struct connected *ifc; + struct prefix *p; + vrf_id_t vrf_id = VRF_DEFAULT; - if (argc > 2) - VRF_GET_ID (vrf_id, argv[idx_vrf]->arg); + if (argc > 2) + VRF_GET_ID (vrf_id, argv[idx_vrf]->arg); - FOR_ALL_INTERFACES (vrf, ifp) - { - for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc)) - { - p = ifc->address; + FOR_ALL_INTERFACES (vrf, ifp) { + for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc)) { + p = ifc->address; - if (p->family == AF_INET) - vty_out (vty, "%s/%d\n", inet_ntoa (p->u.prefix4), p->prefixlen); + if (p->family == AF_INET) + vty_out (vty, "%s/%d\n", inet_ntoa (p->u.prefix4), p->prefixlen); + } } - } - return CMD_SUCCESS; + return CMD_SUCCESS; } DEFUN (show_address_vrf_all, @@ -841,31 +843,30 @@ DEFUN (show_address_vrf_all, "address\n" VRF_ALL_CMD_HELP_STR) { - struct vrf *vrf; - struct listnode *node; - struct interface *ifp; - struct connected *ifc; - struct prefix *p; + struct vrf *vrf; + struct listnode *node; + struct interface *ifp; + struct connected *ifc; + struct prefix *p; - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) - { - if (RB_EMPTY (if_name_head, &vrf->ifaces_by_name)) - continue; + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) + { + if (RB_EMPTY (if_name_head, &vrf->ifaces_by_name)) + continue; - vty_out (vty, "\nVRF %u\n\n", vrf->vrf_id); + vty_out (vty, "\nVRF %s(%u)\n\n", + VRF_LOGNAME(vrf), vrf->vrf_id); - FOR_ALL_INTERFACES (vrf, ifp) - { - for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc)) - { - p = ifc->address; + FOR_ALL_INTERFACES (vrf, ifp) { + for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc)) { + p = ifc->address; - if (p->family == AF_INET) - vty_out (vty, "%s/%d\n", inet_ntoa (p->u.prefix4), p->prefixlen); - } - } - } - return CMD_SUCCESS; + if (p->family == AF_INET) + vty_out (vty, "%s/%d\n", inet_ntoa (p->u.prefix4), p->prefixlen); + } + } + } + return CMD_SUCCESS; } #endif @@ -886,11 +887,8 @@ void connected_free(struct connected **connected) { struct connected *ptr = *connected; - if (ptr->address) - prefix_free(&ptr->address); - - if (ptr->destination) - prefix_free(&ptr->destination); + prefix_free(&ptr->address); + prefix_free(&ptr->destination); XFREE(MTYPE_CONNECTED_LABEL, ptr->label); @@ -927,14 +925,16 @@ connected_log(struct connected *connected, char *str) { struct prefix *p; struct interface *ifp; + struct vrf *vrf; char logbuf[BUFSIZ]; char buf[BUFSIZ]; ifp = connected->ifp; p = connected->address; - snprintf(logbuf, BUFSIZ, "%s interface %s vrf %u %s %s/%d ", str, - ifp->name, ifp->vrf_id, prefix_family_str(p), + vrf = vrf_lookup_by_id(ifp->vrf_id); + snprintf(logbuf, BUFSIZ, "%s interface %s vrf %s(%u) %s %s/%d ", str, + ifp->name, VRF_LOGNAME(vrf), ifp->vrf_id, prefix_family_str(p), inet_ntop(p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen); p = connected->destination; diff --git a/lib/ipaddr.h b/lib/ipaddr.h index 6bd614044c..c6372f1abb 100644 --- a/lib/ipaddr.h +++ b/lib/ipaddr.h @@ -119,10 +119,13 @@ static inline void ipv4_mapped_ipv6_to_ipv4(struct in6_addr *in6, memcpy(in, (char *)in6 + 12, sizeof(struct in_addr)); } +/* + * Check if a struct ipaddr has nonzero value + */ static inline bool ipaddr_isset(struct ipaddr *ip) { static struct ipaddr a = {}; - return (0 == memcmp(&a, ip, sizeof(struct ipaddr))); + return (0 != memcmp(&a, ip, sizeof(struct ipaddr))); } #ifdef __cplusplus diff --git a/lib/keychain.c b/lib/keychain.c index fc9f0f9cfa..ea512a2699 100644 --- a/lib/keychain.c +++ b/lib/keychain.c @@ -967,12 +967,12 @@ static struct cmd_node keychain_key_node = {KEYCHAIN_KEY_NODE, static int keychain_strftime(char *buf, int bufsiz, time_t *time) { - struct tm *tm; + struct tm tm; size_t len; - tm = localtime(time); + localtime_r(time, &tm); - len = strftime(buf, bufsiz, "%T %b %d %Y", tm); + len = strftime(buf, bufsiz, "%T %b %d %Y", &tm); return len; } diff --git a/lib/libfrr.c b/lib/libfrr.c index 4fb43edff2..3622890e46 100644 --- a/lib/libfrr.c +++ b/lib/libfrr.c @@ -383,7 +383,7 @@ static int frr_opt(int opt) exit(0); break; case 'd': - di->daemon_mode = 1; + di->daemon_mode = true; break; case 'M': oc = XMALLOC(MTYPE_TMP, sizeof(*oc)); @@ -467,12 +467,12 @@ static int frr_opt(int opt) case 'C': if (di->flags & FRR_NO_CFG_PID_DRY) return 1; - di->dryrun = 1; + di->dryrun = true; break; case 't': if (di->flags & FRR_NO_CFG_PID_DRY) return 1; - di->terminal = 1; + di->terminal = true; break; case 'z': di->zpathspace = true; @@ -220,11 +220,11 @@ size_t quagga_timestamp(int timestamp_precision, char *buf, size_t buflen) /* first, we update the cache if the time has changed */ if (cache.last != clock.tv_sec) { - struct tm *tm; + struct tm tm; cache.last = clock.tv_sec; - tm = localtime(&cache.last); + localtime_r(&cache.last, &tm); cache.len = strftime(cache.buf, sizeof(cache.buf), - "%Y/%m/%d %H:%M:%S", tm); + "%Y/%m/%d %H:%M:%S", &tm); } /* note: it's not worth caching the subsecond part, because chances are that back-to-back calls are not sufficiently close @@ -1092,6 +1092,11 @@ static const struct zebra_desc_table command_types[] = { DESC_ENTRY(ZEBRA_VXLAN_SG_ADD), DESC_ENTRY(ZEBRA_VXLAN_SG_DEL), DESC_ENTRY(ZEBRA_VXLAN_SG_REPLAY), + DESC_ENTRY(ZEBRA_MLAG_PROCESS_UP), + DESC_ENTRY(ZEBRA_MLAG_PROCESS_DOWN), + DESC_ENTRY(ZEBRA_MLAG_CLIENT_REGISTER), + DESC_ENTRY(ZEBRA_MLAG_CLIENT_UNREGISTER), + DESC_ENTRY(ZEBRA_MLAG_FORWARD_MSG), DESC_ENTRY(ZEBRA_ERROR), DESC_ENTRY(ZEBRA_CLIENT_CAPABILITIES)}; #undef DESC_ENTRY @@ -412,8 +412,8 @@ void hmac_md5(unsigned char *text, int text_len, unsigned char *key, */ /* start out by storing key in pads */ - bzero(k_ipad, sizeof k_ipad); - bzero(k_opad, sizeof k_opad); + bzero(k_ipad, sizeof(k_ipad)); + bzero(k_opad, sizeof(k_opad)); bcopy(key, k_ipad, key_len); bcopy(key, k_opad, key_len); diff --git a/lib/mlag.c b/lib/mlag.c index 1daf290725..733dd41ea8 100644 --- a/lib/mlag.c +++ b/lib/mlag.c @@ -81,22 +81,33 @@ char *mlag_lib_msgid_to_str(enum mlag_msg_type msg_type, char *buf, size_t size) } -int mlag_lib_decode_mlag_hdr(struct stream *s, struct mlag_msg *msg) +int mlag_lib_decode_mlag_hdr(struct stream *s, struct mlag_msg *msg, + size_t *length) { - if (s == NULL || msg == NULL) +#define LIB_MLAG_HDR_LENGTH 8 + *length = stream_get_endp(s); + + if (s == NULL || msg == NULL || *length < LIB_MLAG_HDR_LENGTH) return -1; + *length -= LIB_MLAG_HDR_LENGTH; + STREAM_GETL(s, msg->msg_type); STREAM_GETW(s, msg->data_len); STREAM_GETW(s, msg->msg_cnt); + return 0; stream_failure: return -1; } -int mlag_lib_decode_mroute_add(struct stream *s, struct mlag_mroute_add *msg) +#define MLAG_MROUTE_ADD_LENGTH \ + (VRF_NAMSIZ + INTERFACE_NAMSIZ + 4 + 4 + 4 + 4 + 1 + 1 + 4) + +int mlag_lib_decode_mroute_add(struct stream *s, struct mlag_mroute_add *msg, + size_t *length) { - if (s == NULL || msg == NULL) + if (s == NULL || msg == NULL || *length < MLAG_MROUTE_ADD_LENGTH) return -1; STREAM_GET(msg->vrf_name, s, VRF_NAMSIZ); @@ -108,14 +119,18 @@ int mlag_lib_decode_mroute_add(struct stream *s, struct mlag_mroute_add *msg) STREAM_GETC(s, msg->am_i_dual_active); STREAM_GETL(s, msg->vrf_id); STREAM_GET(msg->intf_name, s, INTERFACE_NAMSIZ); + return 0; stream_failure: return -1; } -int mlag_lib_decode_mroute_del(struct stream *s, struct mlag_mroute_del *msg) +#define MLAG_MROUTE_DEL_LENGTH (VRF_NAMSIZ + INTERFACE_NAMSIZ + 4 + 4 + 4 + 4) + +int mlag_lib_decode_mroute_del(struct stream *s, struct mlag_mroute_del *msg, + size_t *length) { - if (s == NULL || msg == NULL) + if (s == NULL || msg == NULL || *length < MLAG_MROUTE_DEL_LENGTH) return -1; STREAM_GET(msg->vrf_name, s, VRF_NAMSIZ); @@ -124,6 +139,7 @@ int mlag_lib_decode_mroute_del(struct stream *s, struct mlag_mroute_del *msg) STREAM_GETL(s, msg->owner_id); STREAM_GETL(s, msg->vrf_id); STREAM_GET(msg->intf_name, s, INTERFACE_NAMSIZ); + return 0; stream_failure: return -1; diff --git a/lib/mlag.h b/lib/mlag.h index c531fb5b68..37bb3aa6db 100644 --- a/lib/mlag.h +++ b/lib/mlag.h @@ -125,11 +125,14 @@ struct mlag_msg { extern char *mlag_role2str(enum mlag_role role, char *buf, size_t size); extern char *mlag_lib_msgid_to_str(enum mlag_msg_type msg_type, char *buf, size_t size); -extern int mlag_lib_decode_mlag_hdr(struct stream *s, struct mlag_msg *msg); +extern int mlag_lib_decode_mlag_hdr(struct stream *s, struct mlag_msg *msg, + size_t *length); extern int mlag_lib_decode_mroute_add(struct stream *s, - struct mlag_mroute_add *msg); + struct mlag_mroute_add *msg, + size_t *length); extern int mlag_lib_decode_mroute_del(struct stream *s, - struct mlag_mroute_del *msg); + struct mlag_mroute_del *msg, + size_t *length); extern int mlag_lib_decode_mlag_status(struct stream *s, struct mlag_status *msg); extern int mlag_lib_decode_vxlan_update(struct stream *s, diff --git a/lib/module.c b/lib/module.c index 098c550684..14d5cfd44f 100644 --- a/lib/module.c +++ b/lib/module.c @@ -58,7 +58,7 @@ static const char *execname = NULL; void frrmod_init(struct frrmod_runtime *modinfo) { - modinfo->finished_loading = 1; + modinfo->finished_loading = true; *frrmod_last = modinfo; frrmod_last = &modinfo->next; @@ -134,7 +134,7 @@ struct frrmod_runtime *frrmod_load(const char *spec, const char *dir, char *err, goto out_fail; } - rtinfo->finished_loading = 1; + rtinfo->finished_loading = true; *frrmod_last = rtinfo; frrmod_last = &rtinfo->next; diff --git a/lib/monotime.h b/lib/monotime.h index e246f177de..dda763784f 100644 --- a/lib/monotime.h +++ b/lib/monotime.h @@ -112,6 +112,26 @@ static inline char *time_to_string(time_t ts, char *buf) return ctime_r(&tbuf, buf); } +/* Convert interval to human-friendly string, used in cli output e.g. */ +static inline const char *frrtime_to_interval(time_t t, char *buf, + size_t buflen) +{ + struct tm tm; + + gmtime_r(&t, &tm); + + if (t < ONE_DAY_SECOND) + snprintf(buf, buflen, "%02d:%02d:%02d", tm.tm_hour, tm.tm_min, + tm.tm_sec); + else if (t < ONE_WEEK_SECOND) + snprintf(buf, buflen, "%dd%02dh%02dm", tm.tm_yday, tm.tm_hour, + tm.tm_min); + else + snprintf(buf, buflen, "%02dw%dd%02dh", tm.tm_yday / 7, + tm.tm_yday - ((tm.tm_yday / 7) * 7), tm.tm_hour); + return buf; +} + #ifdef __cplusplus } #endif diff --git a/lib/nexthop_group.c b/lib/nexthop_group.c index 3005a51c71..d660428bcd 100644 --- a/lib/nexthop_group.c +++ b/lib/nexthop_group.c @@ -216,7 +216,8 @@ struct nexthop_group *nexthop_group_new(void) return XCALLOC(MTYPE_NEXTHOP_GROUP, sizeof(struct nexthop_group)); } -void nexthop_group_copy(struct nexthop_group *to, struct nexthop_group *from) +void nexthop_group_copy(struct nexthop_group *to, + const struct nexthop_group *from) { /* Copy everything, including recursive info */ copy_nexthops(&to->nexthop, from->nexthop, NULL); diff --git a/lib/nexthop_group.h b/lib/nexthop_group.h index 73b020283a..f99a53f694 100644 --- a/lib/nexthop_group.h +++ b/lib/nexthop_group.h @@ -43,7 +43,7 @@ struct nexthop_group *nexthop_group_new(void); void nexthop_group_delete(struct nexthop_group **nhg); void nexthop_group_copy(struct nexthop_group *to, - struct nexthop_group *from); + const struct nexthop_group *from); /* * Copy a list of nexthops in 'nh' to an nhg, enforcing canonical sort order diff --git a/lib/northbound.c b/lib/northbound.c index 206a88d980..cebedcff09 100644 --- a/lib/northbound.c +++ b/lib/northbound.c @@ -996,7 +996,7 @@ static int nb_transaction_process(enum nb_event event, * Only try to release resources that were allocated * successfully. */ - if (event == NB_EV_ABORT && change->prepare_ok == false) + if (event == NB_EV_ABORT && !change->prepare_ok) break; /* Call the appropriate callback. */ diff --git a/lib/plist.c b/lib/plist.c index 662221beec..40131aebed 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -303,6 +303,8 @@ static void prefix_list_delete(struct prefix_list *plist) /* If prefix-list contain prefix_list_entry free all of it. */ for (pentry = plist->head; pentry; pentry = next) { + route_map_notify_pentry_dependencies(plist->name, pentry, + RMAP_EVENT_PLIST_DELETED); next = pentry->next; prefix_list_trie_del(plist, pentry); prefix_list_entry_free(pentry); @@ -385,7 +387,7 @@ static int64_t prefix_new_seq_get(struct prefix_list *plist) int64_t newseq; struct prefix_list_entry *pentry; - maxseq = newseq = 0; + maxseq = 0; for (pentry = plist->head; pentry; pentry = pentry->next) { if (maxseq < pentry->seq) @@ -518,6 +520,8 @@ static void prefix_list_entry_delete(struct prefix_list *plist, else plist->tail = pentry->prev; + route_map_notify_pentry_dependencies(plist->name, pentry, + RMAP_EVENT_PLIST_DELETED); prefix_list_entry_free(pentry); plist->count--; @@ -631,6 +635,9 @@ static void prefix_list_entry_add(struct prefix_list *plist, /* Increment count. */ plist->count++; + route_map_notify_pentry_dependencies(plist->name, pentry, + RMAP_EVENT_PLIST_ADDED); + /* Run hook function. */ if (plist->master->add_hook) (*plist->master->add_hook)(plist); @@ -2032,7 +2039,7 @@ static void prefix_list_reset_afi(afi_t afi, int orf) assert(master->str.head == NULL); assert(master->str.tail == NULL); - master->seqnum = 1; + master->seqnum = true; master->recent = NULL; } diff --git a/lib/prefix.c b/lib/prefix.c index 2b7727fd0a..80fe0f54a9 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -1082,7 +1082,7 @@ struct prefix *prefix_new(void) { struct prefix *p; - p = XCALLOC(MTYPE_PREFIX, sizeof *p); + p = XCALLOC(MTYPE_PREFIX, sizeof(*p)); return p; } diff --git a/lib/printf/printf-pos.c b/lib/printf/printf-pos.c index 20a58eacdc..cc03f7ef9a 100644 --- a/lib/printf/printf-pos.c +++ b/lib/printf/printf-pos.c @@ -686,7 +686,7 @@ build_arg_table(struct typetable *types, va_list ap, union arg **argtable) if (types->tablemax >= STATIC_ARG_TBL_SIZE) { *argtable = (union arg *) - malloc (sizeof (union arg) * (types->tablemax + 1)); + malloc (sizeof(union arg) * (types->tablemax + 1)); if (*argtable == NULL) return; } diff --git a/lib/ptm_lib.c b/lib/ptm_lib.c index 54f027deeb..b66ae221cf 100644 --- a/lib/ptm_lib.c +++ b/lib/ptm_lib.c @@ -143,7 +143,7 @@ int ptm_lib_append_msg(ptm_lib_handle_t *hdl, void *ctxt, const char *key, csv_record_t *mh_rec, *rec; if (!p_ctxt) { - ERRLOG("%s: no context \n", __FUNCTION__); + ERRLOG("%s: no context \n", __func__); return -1; } @@ -154,7 +154,7 @@ int ptm_lib_append_msg(ptm_lib_handle_t *hdl, void *ctxt, const char *key, /* append to the hdr record */ rec = csv_append_record(csv, rec, 1, key); if (!rec) { - ERRLOG("%s: Could not append key \n", __FUNCTION__); + ERRLOG("%s: Could not append key \n", __func__); return -1; } @@ -162,7 +162,7 @@ int ptm_lib_append_msg(ptm_lib_handle_t *hdl, void *ctxt, const char *key, /* append to the data record */ rec = csv_append_record(csv, rec, 1, val); if (!rec) { - ERRLOG("%s: Could not append val \n", __FUNCTION__); + ERRLOG("%s: Could not append val \n", __func__); return -1; } @@ -186,7 +186,7 @@ int ptm_lib_init_msg(ptm_lib_handle_t *hdl, int cmd_id, int type, void *in_ctxt, csv = csv_init(NULL, NULL, PTMLIB_MSG_SZ); if (!csv) { - ERRLOG("%s: Could not allocate csv \n", __FUNCTION__); + ERRLOG("%s: Could not allocate csv \n", __func__); return -1; } @@ -194,7 +194,7 @@ int ptm_lib_init_msg(ptm_lib_handle_t *hdl, int cmd_id, int type, void *in_ctxt, cmd_id, hdl->client_name); if (!rec) { - ERRLOG("%s: Could not allocate record \n", __FUNCTION__); + ERRLOG("%s: Could not allocate record \n", __func__); csv_clean(csv); csv_free(csv); return -1; @@ -202,7 +202,7 @@ int ptm_lib_init_msg(ptm_lib_handle_t *hdl, int cmd_id, int type, void *in_ctxt, p_ctxt = calloc(1, sizeof(*p_ctxt)); if (!p_ctxt) { - ERRLOG("%s: Could not allocate context \n", __FUNCTION__); + ERRLOG("%s: Could not allocate context \n", __func__); csv_clean(csv); csv_free(csv); return -1; @@ -234,7 +234,7 @@ int ptm_lib_cleanup_msg(ptm_lib_handle_t *hdl, void *ctxt) csv_t *csv; if (!p_ctxt) { - ERRLOG("%s: no context \n", __FUNCTION__); + ERRLOG("%s: no context \n", __func__); return -1; } @@ -254,7 +254,7 @@ int ptm_lib_complete_msg(ptm_lib_handle_t *hdl, void *ctxt, char *buf, int *len) csv_record_t *rec; if (!p_ctxt) { - ERRLOG("%s: no context \n", __FUNCTION__); + ERRLOG("%s: no context \n", __func__); return -1; } @@ -268,7 +268,7 @@ int ptm_lib_complete_msg(ptm_lib_handle_t *hdl, void *ctxt, char *buf, int *len) /* parse csv contents into string */ if (buf && len) { if (csv_serialize(csv, buf, *len)) { - ERRLOG("%s: cannot serialize\n", __FUNCTION__); + ERRLOG("%s: cannot serialize\n", __func__); return -1; } *len = csvlen(csv); @@ -425,8 +425,7 @@ int ptm_lib_process_msg(ptm_lib_handle_t *hdl, int fd, char *inbuf, int inlen, csv_decode(csv, inbuf); p_ctxt = calloc(1, sizeof(*p_ctxt)); if (!p_ctxt) { - ERRLOG("%s: Could not allocate context \n", - __FUNCTION__); + ERRLOG("%s: Could not allocate context \n", __func__); csv_clean(csv); csv_free(csv); return -1; diff --git a/lib/routemap.c b/lib/routemap.c index 0d5621d90e..e2baa36f24 100644 --- a/lib/routemap.c +++ b/lib/routemap.c @@ -31,6 +31,7 @@ #include "hash.h" #include "libfrr.h" #include "lib_errors.h" +#include "table.h" DEFINE_MTYPE_STATIC(LIB, ROUTE_MAP, "Route map") DEFINE_MTYPE(LIB, ROUTE_MAP_NAME, "Route map name") @@ -44,12 +45,52 @@ DEFINE_MTYPE_STATIC(LIB, ROUTE_MAP_DEP_DATA, "Route map dependency data") DEFINE_QOBJ_TYPE(route_map_index) DEFINE_QOBJ_TYPE(route_map) +#define IPv4_PREFIX_LIST "ip address prefix-list" +#define IPv6_PREFIX_LIST "ipv6 address prefix-list" +#define IPv4_MATCH_RULE "ip " +#define IPv6_MATCH_RULE "ipv6 " + +#define IS_RULE_IPv4_PREFIX_LIST(S) \ + (strncmp(S, IPv4_PREFIX_LIST, strlen(IPv4_PREFIX_LIST)) == 0) +#define IS_RULE_IPv6_PREFIX_LIST(S) \ + (strncmp(S, IPv6_PREFIX_LIST, strlen(IPv6_PREFIX_LIST)) == 0) + +#define IS_IPv4_RULE(S) \ + (strncmp(S, IPv4_MATCH_RULE, strlen(IPv4_MATCH_RULE)) == 0) +#define IS_IPv6_RULE(S) \ + (strncmp(S, IPv6_MATCH_RULE, strlen(IPv6_MATCH_RULE)) == 0) +struct route_map_pentry_dep { + struct prefix_list_entry *pentry; + const char *plist_name; + route_map_event_t event; +}; + /* Vector for route match rules. */ static vector route_match_vec; /* Vector for route set rules. */ static vector route_set_vec; +static void route_map_pfx_tbl_update(route_map_event_t event, + struct route_map_index *index, afi_t afi, + const char *plist_name); +static void route_map_pfx_table_add_default(afi_t afi, + struct route_map_index *index); +static void route_map_pfx_table_del_default(afi_t afi, + struct route_map_index *index); +static void route_map_add_plist_entries(afi_t afi, + struct route_map_index *index, + const char *plist_name, + struct prefix_list_entry *entry); +static void route_map_del_plist_entries(afi_t afi, + struct route_map_index *index, + const char *plist_name, + struct prefix_list_entry *entry); +static bool route_map_is_ip_rule_present(struct route_map_index *index); +static bool route_map_is_ipv6_rule_present(struct route_map_index *index); + +static struct hash *route_map_get_dep_hash(route_map_event_t event); + struct route_map_match_set_hooks rmap_match_set_hook; /* match interface */ @@ -566,6 +607,12 @@ static struct route_map *route_map_add(const char *name) route_map_notify_dependencies(name, RMAP_EVENT_CALL_ADDED); } + if (!map->ipv4_prefix_table) + map->ipv4_prefix_table = route_table_init(); + + if (!map->ipv6_prefix_table) + map->ipv6_prefix_table = route_table_init(); + if (rmap_debug) zlog_debug("Add route-map %s", name); return map; @@ -786,8 +833,9 @@ static void vty_show_route_map_entry(struct vty *vty, struct route_map *map) struct route_map_index *index; struct route_map_rule *rule; - vty_out(vty, "route-map: %s Invoked: %" PRIu64 "\n", - map->name, map->applied - map->applied_clear); + vty_out(vty, "route-map: %s Invoked: %" PRIu64 " Optimization: %s\n", + map->name, map->applied - map->applied_clear, + map->optimization_disabled ? "disabled" : "enabled"); for (index = map->head; index; index = index->next) { vty_out(vty, " %s, sequence %d Invoked %" PRIu64 "\n", @@ -914,6 +962,7 @@ static struct route_map_index *route_map_index_new(void) /* Free route map index. */ void route_map_index_delete(struct route_map_index *index, int notify) { + struct routemap_hook_context *rhc; struct route_map_rule *rule; QOBJ_UNREG(index); @@ -923,12 +972,21 @@ void route_map_index_delete(struct route_map_index *index, int notify) index->map->name, index->pref); /* Free route map northbound hook contexts. */ - while (!TAILQ_EMPTY(&index->rhclist)) - routemap_hook_context_free(TAILQ_FIRST(&index->rhclist)); + while ((rhc = TAILQ_FIRST(&index->rhclist)) != NULL) + routemap_hook_context_free(rhc); /* Free route match. */ - while ((rule = index->match_list.head) != NULL) + while ((rule = index->match_list.head) != NULL) { + if (IS_RULE_IPv4_PREFIX_LIST(rule->cmd->str)) + route_map_pfx_tbl_update(RMAP_EVENT_PLIST_DELETED, + index, AFI_IP, rule->rule_str); + else if (IS_RULE_IPv6_PREFIX_LIST(rule->cmd->str)) + route_map_pfx_tbl_update(RMAP_EVENT_PLIST_DELETED, + index, AFI_IP6, + rule->rule_str); + route_map_rule_delete(&index->match_list, rule); + } /* Free route set. */ while ((rule = index->set_list.head) != NULL) @@ -948,6 +1006,8 @@ void route_map_index_delete(struct route_map_index *index, int notify) /* Free 'char *nextrm' if not NULL */ XFREE(MTYPE_ROUTE_MAP_NAME, index->nextrm); + route_map_pfx_tbl_update(RMAP_EVENT_INDEX_DELETED, index, 0, NULL); + /* Execute event hook. */ if (route_map_master.event_hook && notify) { (*route_map_master.event_hook)(index->map->name); @@ -1007,6 +1067,8 @@ route_map_index_add(struct route_map *map, enum route_map_type type, int pref) point->prev = index; } + route_map_pfx_tbl_update(RMAP_EVENT_INDEX_ADDED, index, 0, NULL); + /* Execute event hook. */ if (route_map_master.event_hook) { (*route_map_master.event_hook)(map->name); @@ -1254,6 +1316,19 @@ enum rmap_compile_rets route_map_add_match(struct route_map_index *index, return RMAP_COMPILE_SUCCESS; } + /* If IPv4 or IPv6 prefix-list match criteria + * has been delete to the route-map index, update + * the route-map's prefix table. + */ + if (IS_RULE_IPv4_PREFIX_LIST(match_name)) + route_map_pfx_tbl_update( + RMAP_EVENT_PLIST_DELETED, index, AFI_IP, + rule->rule_str); + else if (IS_RULE_IPv6_PREFIX_LIST(match_name)) + route_map_pfx_tbl_update( + RMAP_EVENT_PLIST_DELETED, index, + AFI_IP6, rule->rule_str); + /* Remove the dependency of the route-map on the rule * that is being replaced. */ @@ -1282,6 +1357,38 @@ enum rmap_compile_rets route_map_add_match(struct route_map_index *index, /* Add new route match rule to linked list. */ route_map_rule_add(&index->match_list, rule); + /* If IPv4 or IPv6 prefix-list match criteria + * has been added to the route-map index, update + * the route-map's prefix table. + */ + if (IS_RULE_IPv4_PREFIX_LIST(match_name)) { + route_map_pfx_tbl_update(RMAP_EVENT_PLIST_ADDED, index, AFI_IP, + match_arg); + } else if (IS_RULE_IPv6_PREFIX_LIST(match_name)) { + route_map_pfx_tbl_update(RMAP_EVENT_PLIST_ADDED, index, AFI_IP6, + match_arg); + } else { + /* If IPv4 match criteria has been added to the route-map + * index, check for IPv6 prefix-list match rule presence and + * remove this index from the trie node created for each of the + * prefix-entry within the prefix-list. If no IPv6 prefix-list + * match rule is present, remove this index from the IPv6 + * default route's trie node. + */ + if (IS_IPv4_RULE(match_name)) + route_map_del_plist_entries(AFI_IP6, index, NULL, NULL); + + /* If IPv6 match criteria has been added to the route-map + * index, check for IPv4 prefix-list match rule presence and + * remove this index from the trie node created for each of the + * prefix-entry within the prefix-list. If no IPv4 prefix-list + * match rule is present, remove this index from the IPv4 + * default route's trie node. + */ + else if (IS_IPv6_RULE(match_name)) + route_map_del_plist_entries(AFI_IP, index, NULL, NULL); + } + /* Execute event hook. */ if (route_map_master.event_hook) { (*route_map_master.event_hook)(index->map->name); @@ -1329,6 +1436,45 @@ enum rmap_compile_rets route_map_delete_match(struct route_map_index *index, index->map->name); route_map_rule_delete(&index->match_list, rule); + + /* If IPv4 or IPv6 prefix-list match criteria + * has been delete to the route-map index, update + * the route-map's prefix table. + */ + if (IS_RULE_IPv4_PREFIX_LIST(match_name)) { + route_map_pfx_tbl_update( + RMAP_EVENT_PLIST_DELETED, index, AFI_IP, + match_arg); + } else if (IS_RULE_IPv6_PREFIX_LIST(match_name)) { + route_map_pfx_tbl_update( + RMAP_EVENT_PLIST_DELETED, index, + AFI_IP6, match_arg); + } else { + /* If no more IPv4 match rules are present in + * this index, check for IPv6 prefix-list match + * rule presence and add this index to trie node + * created for each of the prefix-entry within + * the prefix-list. If no IPv6 prefix-list match + * rule is present, add this index to the IPv6 + * default route's trie node. + */ + if (!route_map_is_ip_rule_present(index)) + route_map_add_plist_entries( + AFI_IP6, index, NULL, NULL); + + /* If no more IPv6 match rules are present in + * this index, check for IPv4 prefix-list match + * rule presence and add this index to trie node + * created for each of the prefix-entry within + * the prefix-list. If no IPv6 prefix-list match + * rule is present, add this index to the IPv4 + * default route's trie node. + */ + if (!route_map_is_ipv6_rule_present(index)) + route_map_add_plist_entries( + AFI_IP, index, NULL, NULL); + } + return RMAP_COMPILE_SUCCESS; } /* Can't find matched rule. */ @@ -1494,6 +1640,705 @@ route_map_apply_match(struct route_map_rule_list *match_list, return ret; } +static struct list *route_map_get_index_list(struct route_node **rn, + const struct prefix *prefix, + struct route_table *table) +{ + struct route_node *tmp_rn = NULL; + + if (!(*rn)) { + *rn = route_node_match(table, prefix); + + if (!(*rn)) + return NULL; + + if ((*rn)->info) + return (struct list *)((*rn)->info); + + /* If rn->info is NULL, get the parent. + * Store the rn in tmp_rn and unlock it later. + */ + tmp_rn = *rn; + } + + do { + *rn = (*rn)->parent; + if (tmp_rn) + route_unlock_node(tmp_rn); + + if (!(*rn)) + break; + + if ((*rn)->info) { + route_lock_node(*rn); + return (struct list *)((*rn)->info); + } + } while (!(*rn)->info); + + return NULL; +} + +/* + * This function returns the route-map index that best matches the prefix. + */ +static struct route_map_index * +route_map_get_index(struct route_map *map, const struct prefix *prefix, + route_map_object_t type, void *object, uint8_t *match_ret) +{ + int ret = 0; + struct list *candidate_rmap_list = NULL; + struct route_node *rn = NULL; + struct listnode *ln = NULL, *nn = NULL; + struct route_map_index *index = NULL, *best_index = NULL; + struct route_map_index *head_index = NULL; + struct route_table *table = NULL; + unsigned char family = prefix->family; + + if (family == AF_INET) + table = map->ipv4_prefix_table; + else + table = map->ipv6_prefix_table; + + if (!table) + return NULL; + + do { + candidate_rmap_list = + route_map_get_index_list(&rn, prefix, table); + if (!rn) + break; + + /* If the index at the head of the list is of seq higher + * than that in best_index, ignore the list and get the + * parent node's list. + */ + head_index = (struct route_map_index *)(listgetdata( + listhead(candidate_rmap_list))); + if (best_index && head_index + && (best_index->pref < head_index->pref)) { + route_unlock_node(rn); + continue; + } + + for (ALL_LIST_ELEMENTS(candidate_rmap_list, ln, nn, index)) { + /* If the index is of seq higher than that in + * best_index, ignore the list and get the parent + * node's list. + */ + if (best_index && (best_index->pref < index->pref)) + break; + + ret = route_map_apply_match(&index->match_list, prefix, + type, object); + + if (ret == RMAP_MATCH) { + *match_ret = ret; + best_index = index; + break; + } else if (ret == RMAP_NOOP) { + /* + * If match_ret is denymatch, even if we see + * more noops, we retain this return value and + * return this eventually if there are no + * matches. + */ + if (*match_ret != RMAP_NOMATCH) + *match_ret = ret; + } else { + /* + * ret is RMAP_NOMATCH. + */ + *match_ret = ret; + } + } + + route_unlock_node(rn); + + } while (rn); + + return best_index; +} + +static int route_map_candidate_list_cmp(struct route_map_index *idx1, + struct route_map_index *idx2) +{ + if (!idx1) + return -1; + if (!idx2) + return 1; + + return (idx1->pref - idx2->pref); +} + +/* + * This function adds the route-map index into the default route's + * route-node in the route-map's IPv4/IPv6 prefix-table. + */ +static void route_map_pfx_table_add_default(afi_t afi, + struct route_map_index *index) +{ + struct route_node *rn = NULL; + struct list *rmap_candidate_list = NULL; + struct prefix p; + bool updated_rn = false; + struct route_table *table = NULL; + + memset(&p, 0, sizeof(p)); + p.family = afi2family(afi); + p.prefixlen = 0; + + if (p.family == AF_INET) { + table = index->map->ipv4_prefix_table; + if (!table) + index->map->ipv4_prefix_table = route_table_init(); + + table = index->map->ipv4_prefix_table; + } else { + table = index->map->ipv6_prefix_table; + if (!table) + index->map->ipv6_prefix_table = route_table_init(); + + table = index->map->ipv6_prefix_table; + } + + /* Add default route to table */ + rn = route_node_get(table, &p); + + if (!rn) + return; + + if (!rn->info) { + rmap_candidate_list = list_new(); + rmap_candidate_list->cmp = + (int (*)(void *, void *))route_map_candidate_list_cmp; + rn->info = rmap_candidate_list; + } else { + rmap_candidate_list = (struct list *)rn->info; + updated_rn = true; + } + + listnode_add_sort_nodup(rmap_candidate_list, index); + if (updated_rn) + route_unlock_node(rn); +} + +/* + * This function removes the route-map index from the default route's + * route-node in the route-map's IPv4/IPv6 prefix-table. + */ +static void route_map_pfx_table_del_default(afi_t afi, + struct route_map_index *index) +{ + struct route_node *rn = NULL; + struct list *rmap_candidate_list = NULL; + struct prefix p; + struct route_table *table = NULL; + + memset(&p, 0, sizeof(p)); + p.family = afi2family(afi); + p.prefixlen = 0; + + if (p.family == AF_INET) + table = index->map->ipv4_prefix_table; + else + table = index->map->ipv6_prefix_table; + + /* Remove RMAP index from default route in table */ + rn = route_node_lookup(table, &p); + if (!rn || !rn->info) + return; + + rmap_candidate_list = (struct list *)rn->info; + + listnode_delete(rmap_candidate_list, index); + + if (listcount(rmap_candidate_list) == 0) { + list_delete(&rmap_candidate_list); + rn->info = NULL; + route_unlock_node(rn); + } + route_unlock_node(rn); +} + +/* + * This function adds the route-map index to the route-node for + * the prefix-entry in the route-map's IPv4/IPv6 prefix-table. + */ +static void route_map_pfx_table_add(struct route_table *table, + struct route_map_index *index, + struct prefix_list_entry *pentry) +{ + struct route_node *rn = NULL; + struct list *rmap_candidate_list = NULL; + bool updated_rn = false; + + rn = route_node_get(table, &pentry->prefix); + if (!rn) + return; + + if (!rn->info) { + rmap_candidate_list = list_new(); + rmap_candidate_list->cmp = + (int (*)(void *, void *))route_map_candidate_list_cmp; + rn->info = rmap_candidate_list; + } else { + rmap_candidate_list = (struct list *)rn->info; + updated_rn = true; + } + + listnode_add_sort_nodup(rmap_candidate_list, index); + if (updated_rn) + route_unlock_node(rn); +} + +/* + * This function removes the route-map index from the route-node for + * the prefix-entry in the route-map's IPv4/IPv6 prefix-table. + */ +static void route_map_pfx_table_del(struct route_table *table, + struct route_map_index *index, + struct prefix_list_entry *pentry) +{ + struct route_node *rn = NULL; + struct list *rmap_candidate_list = NULL; + + rn = route_node_lookup(table, &pentry->prefix); + if (!rn || !rn->info) + return; + + rmap_candidate_list = (struct list *)rn->info; + + listnode_delete(rmap_candidate_list, index); + + if (listcount(rmap_candidate_list) == 0) { + list_delete(&rmap_candidate_list); + rn->info = NULL; + route_unlock_node(rn); + } + route_unlock_node(rn); +} + +/* This function checks for the presence of an IPv4 match rule + * in the given route-map index. + */ +static bool route_map_is_ip_rule_present(struct route_map_index *index) +{ + struct route_map_rule_list *match_list = NULL; + struct route_map_rule *rule = NULL; + + match_list = &index->match_list; + for (rule = match_list->head; rule; rule = rule->next) + if (IS_IPv4_RULE(rule->cmd->str)) + return true; + + return false; +} + +/* This function checks for the presence of an IPv6 match rule + * in the given route-map index. + */ +static bool route_map_is_ipv6_rule_present(struct route_map_index *index) +{ + struct route_map_rule_list *match_list = NULL; + struct route_map_rule *rule = NULL; + + match_list = &index->match_list; + for (rule = match_list->head; rule; rule = rule->next) + if (IS_IPv6_RULE(rule->cmd->str)) + return true; + + return false; +} + +/* This function does the following: + * 1) If plist_name is not present, search for a IPv4 or IPv6 prefix-list + * match clause (based on the afi passed to this foo) and get the + * prefix-list name. + * 2) Look up the prefix-list using the name. + * 3) If the prefix-list is not found then, add the index to the IPv4/IPv6 + * default-route's node in the trie (based on the afi passed to this foo). + * 4) If the prefix-list is found then, remove the index from the IPv4/IPv6 + * default-route's node in the trie (based on the afi passed to this foo). + * 5) If a prefix-entry is passed then, create a route-node for this entry and + * add this index to the route-node. + * 6) If prefix-entry is not passed then, for every prefix-entry in the + * prefix-list, create a route-node for this entry and + * add this index to the route-node. + */ +static void route_map_add_plist_entries(afi_t afi, + struct route_map_index *index, + const char *plist_name, + struct prefix_list_entry *entry) +{ + struct route_map_rule_list *match_list = NULL; + struct route_map_rule *match = NULL; + struct prefix_list *plist = NULL; + struct prefix_list_entry *pentry = NULL; + bool plist_rule_is_present = false; + + if (!plist_name) { + match_list = &index->match_list; + + for (match = match_list->head; match; match = match->next) { + if (afi == AFI_IP) { + if (IS_RULE_IPv4_PREFIX_LIST(match->cmd->str)) { + plist_rule_is_present = true; + break; + } + } else { + if (IS_RULE_IPv6_PREFIX_LIST(match->cmd->str)) { + plist_rule_is_present = true; + break; + } + } + } + + if (plist_rule_is_present) + plist = prefix_list_lookup(afi, match->rule_str); + } else { + plist = prefix_list_lookup(afi, plist_name); + } + + if (!plist) { + route_map_pfx_table_add_default(afi, index); + return; + } + + route_map_pfx_table_del_default(afi, index); + + if (entry) { + if (afi == AFI_IP) { + route_map_pfx_table_add(index->map->ipv4_prefix_table, + index, entry); + } else { + route_map_pfx_table_add(index->map->ipv6_prefix_table, + index, entry); + } + } else { + for (pentry = plist->head; pentry; pentry = pentry->next) { + if (afi == AFI_IP) { + route_map_pfx_table_add( + index->map->ipv4_prefix_table, index, + pentry); + } else { + route_map_pfx_table_add( + index->map->ipv6_prefix_table, index, + pentry); + } + } + } +} + +/* This function does the following: + * 1) If plist_name is not present, search for a IPv4 or IPv6 prefix-list + * match clause (based on the afi passed to this foo) and get the + * prefix-list name. + * 2) Look up the prefix-list using the name. + * 3) If the prefix-list is not found then, delete the index from the IPv4/IPv6 + * default-route's node in the trie (based on the afi passed to this foo). + * 4) If a prefix-entry is passed then, remove this index from the route-node + * for the prefix in this prefix-entry. + * 5) If prefix-entry is not passed then, for every prefix-entry in the + * prefix-list, remove this index from the route-node + * for the prefix in this prefix-entry. + */ +static void route_map_del_plist_entries(afi_t afi, + struct route_map_index *index, + const char *plist_name, + struct prefix_list_entry *entry) +{ + struct route_map_rule_list *match_list = NULL; + struct route_map_rule *match = NULL; + struct prefix_list *plist = NULL; + struct prefix_list_entry *pentry = NULL; + bool plist_rule_is_present = false; + + if (!plist_name) { + match_list = &index->match_list; + + for (match = match_list->head; match; match = match->next) { + if (afi == AFI_IP) { + if (IS_RULE_IPv4_PREFIX_LIST(match->cmd->str)) { + plist_rule_is_present = true; + break; + } + } else { + if (IS_RULE_IPv6_PREFIX_LIST(match->cmd->str)) { + plist_rule_is_present = true; + break; + } + } + } + + if (plist_rule_is_present) + plist = prefix_list_lookup(afi, match->rule_str); + } else { + plist = prefix_list_lookup(afi, plist_name); + } + + if (!plist) { + route_map_pfx_table_del_default(afi, index); + return; + } + + if (entry) { + if (afi == AFI_IP) { + route_map_pfx_table_del(index->map->ipv4_prefix_table, + index, entry); + } else { + route_map_pfx_table_del(index->map->ipv6_prefix_table, + index, entry); + } + } else { + for (pentry = plist->head; pentry; pentry = pentry->next) { + if (afi == AFI_IP) { + route_map_pfx_table_del( + index->map->ipv4_prefix_table, index, + pentry); + } else { + route_map_pfx_table_del( + index->map->ipv6_prefix_table, index, + pentry); + } + } + } +} + +/* + * This function handles the cases where a prefix-list is added/removed + * as a match command from a particular route-map index. + * It updates the prefix-table of the route-map accordingly. + */ +static void route_map_trie_update(afi_t afi, route_map_event_t event, + struct route_map_index *index, + const char *plist_name) +{ + if (event == RMAP_EVENT_PLIST_ADDED) { + if (afi == AFI_IP) { + if (!route_map_is_ipv6_rule_present(index)) { + route_map_pfx_table_del_default(AFI_IP6, index); + route_map_add_plist_entries(afi, index, + plist_name, NULL); + } else { + route_map_del_plist_entries(AFI_IP6, index, + NULL, NULL); + } + } else { + if (!route_map_is_ip_rule_present(index)) { + route_map_pfx_table_del_default(AFI_IP, index); + route_map_add_plist_entries(afi, index, + plist_name, NULL); + } else { + route_map_del_plist_entries(AFI_IP, index, NULL, + NULL); + } + } + } else if (event == RMAP_EVENT_PLIST_DELETED) { + if (afi == AFI_IP) { + route_map_del_plist_entries(afi, index, plist_name, + NULL); + + if (!route_map_is_ipv6_rule_present(index)) + route_map_pfx_table_add_default(afi, index); + + if (!route_map_is_ip_rule_present(index)) + route_map_add_plist_entries(AFI_IP6, index, + NULL, NULL); + } else { + route_map_del_plist_entries(afi, index, plist_name, + NULL); + + if (!route_map_is_ip_rule_present(index)) + route_map_pfx_table_add_default(afi, index); + + if (!route_map_is_ipv6_rule_present(index)) + route_map_add_plist_entries(AFI_IP, index, NULL, + NULL); + } + } +} + +/* + * This function handles the cases where a route-map index and + * prefix-list is added/removed. + * It updates the prefix-table of the route-map accordingly. + */ +static void route_map_pfx_tbl_update(route_map_event_t event, + struct route_map_index *index, afi_t afi, + const char *plist_name) +{ + struct route_map *rmap = NULL; + + if (!index) + return; + + if (event == RMAP_EVENT_INDEX_ADDED) { + route_map_pfx_table_add_default(AFI_IP, index); + route_map_pfx_table_add_default(AFI_IP6, index); + return; + } + + if (event == RMAP_EVENT_INDEX_DELETED) { + route_map_pfx_table_del_default(AFI_IP, index); + route_map_pfx_table_del_default(AFI_IP6, index); + + if ((index->map->head == NULL) && (index->map->tail == NULL)) { + rmap = index->map; + + if (rmap->ipv4_prefix_table) { + route_table_finish(rmap->ipv4_prefix_table); + rmap->ipv4_prefix_table = NULL; + } + + if (rmap->ipv6_prefix_table) { + route_table_finish(rmap->ipv6_prefix_table); + rmap->ipv6_prefix_table = NULL; + } + } + return; + } + + /* Handle prefix-list match rule addition/deletion. + */ + route_map_trie_update(afi, event, index, plist_name); +} + +/* + * This function handles the cases where a new prefix-entry is added to + * a prefix-list or, an existing prefix-entry is removed from the prefix-list. + * It updates the prefix-table of the route-map accordingly. + */ +static void route_map_pentry_update(route_map_event_t event, + const char *plist_name, + struct route_map_index *index, + struct prefix_list_entry *pentry) +{ + struct prefix_list *plist = NULL; + afi_t afi; + unsigned char family = pentry->prefix.family; + + if (family == AF_INET) { + afi = AFI_IP; + plist = prefix_list_lookup(AFI_IP, plist_name); + } else { + afi = AFI_IP6; + plist = prefix_list_lookup(AFI_IP6, plist_name); + } + + if (event == RMAP_EVENT_PLIST_ADDED) { + if (plist->count == 1) { + if (afi == AFI_IP) { + if (!route_map_is_ipv6_rule_present(index)) + route_map_add_plist_entries( + afi, index, plist_name, pentry); + } else { + if (!route_map_is_ip_rule_present(index)) + route_map_add_plist_entries( + afi, index, plist_name, pentry); + } + } else { + route_map_add_plist_entries(afi, index, plist_name, + pentry); + } + } else if (event == RMAP_EVENT_PLIST_DELETED) { + route_map_del_plist_entries(afi, index, plist_name, pentry); + + if (plist->count == 1) { + if (afi == AFI_IP) { + if (!route_map_is_ipv6_rule_present(index)) + route_map_pfx_table_add_default(afi, + index); + } else { + if (!route_map_is_ip_rule_present(index)) + route_map_pfx_table_add_default(afi, + index); + } + } + } +} + +static void route_map_pentry_process_dependency(struct hash_bucket *backet, + void *data) +{ + char *rmap_name = NULL; + struct route_map *rmap = NULL; + struct route_map_index *index = NULL; + struct route_map_rule_list *match_list = NULL; + struct route_map_rule *match = NULL; + struct route_map_dep_data *dep_data = NULL; + struct route_map_pentry_dep *pentry_dep = + (struct route_map_pentry_dep *)data; + unsigned char family = pentry_dep->pentry->prefix.family; + + dep_data = (struct route_map_dep_data *)backet->data; + if (!dep_data) + return; + + rmap_name = dep_data->rname; + rmap = route_map_lookup_by_name(rmap_name); + if (!rmap || !rmap->head) + return; + + for (index = rmap->head; index; index = index->next) { + match_list = &index->match_list; + + if (!match_list) + continue; + + for (match = match_list->head; match; match = match->next) { + if (strcmp(match->rule_str, pentry_dep->plist_name) + == 0) { + if (IS_RULE_IPv4_PREFIX_LIST(match->cmd->str) + && family == AF_INET) { + route_map_pentry_update( + pentry_dep->event, + pentry_dep->plist_name, index, + pentry_dep->pentry); + } else if (IS_RULE_IPv6_PREFIX_LIST( + match->cmd->str) + && family == AF_INET6) { + route_map_pentry_update( + pentry_dep->event, + pentry_dep->plist_name, index, + pentry_dep->pentry); + } + } + } + } +} + +void route_map_notify_pentry_dependencies(const char *affected_name, + struct prefix_list_entry *pentry, + route_map_event_t event) +{ + struct route_map_dep *dep = NULL; + struct hash *upd8_hash = NULL; + struct route_map_pentry_dep pentry_dep; + + if (!affected_name || !pentry) + return; + + upd8_hash = route_map_get_dep_hash(event); + if (!upd8_hash) + return; + + dep = (struct route_map_dep *)hash_get(upd8_hash, (void *)affected_name, + NULL); + if (dep) { + if (!dep->this_hash) + dep->this_hash = upd8_hash; + + memset(&pentry_dep, 0, sizeof(struct route_map_pentry_dep)); + pentry_dep.pentry = pentry; + pentry_dep.plist_name = affected_name; + pentry_dep.event = event; + + hash_iterate(dep->dep_rmap_hash, + route_map_pentry_process_dependency, + (void *)&pentry_dep); + } +} + /* Apply route map's each index to the object. The matrix for a route-map looks like this: @@ -1547,9 +2392,10 @@ route_map_result_t route_map_apply(struct route_map *map, static int recursion = 0; enum route_map_cmd_result_t match_ret = RMAP_NOMATCH; route_map_result_t ret = RMAP_PERMITMATCH; - struct route_map_index *index; - struct route_map_rule *set; + struct route_map_index *index = NULL; + struct route_map_rule *set = NULL; char buf[PREFIX_STRLEN]; + bool skip_match_clause = false; if (recursion > RMAP_RECURSION_LIMIT) { flog_warn( @@ -1566,18 +2412,55 @@ route_map_result_t route_map_apply(struct route_map *map, } map->applied++; - for (index = map->head; index; index = index->next) { - /* Apply this index. */ - index->applied++; - match_ret = route_map_apply_match(&index->match_list, prefix, - type, object); - - if (rmap_debug) { - zlog_debug("Route-map: %s, sequence: %d, prefix: %s, result: %s", - map->name, index->pref, - prefix2str(prefix, buf, sizeof(buf)), - route_map_cmd_result_str(match_ret)); + + if ((!map->optimization_disabled) + && (map->ipv4_prefix_table || map->ipv6_prefix_table)) { + index = route_map_get_index(map, prefix, type, object, + (uint8_t *)&match_ret); + if (index) { + if (rmap_debug) + zlog_debug( + "Best match route-map: %s, sequence: %d for pfx: %s, result: %s", + map->name, index->pref, + prefix2str(prefix, buf, sizeof(buf)), + route_map_cmd_result_str(match_ret)); + } else { + if (rmap_debug) + zlog_debug( + "No best match sequence for pfx: %s in route-map: %s, result: %s", + prefix2str(prefix, buf, sizeof(buf)), + map->name, + route_map_cmd_result_str(match_ret)); + /* + * No index matches this prefix. Return deny unless, + * match_ret = RMAP_NOOP. + */ + if (match_ret == RMAP_NOOP) + ret = RMAP_PERMITMATCH; + else + ret = RMAP_DENYMATCH; + goto route_map_apply_end; } + skip_match_clause = true; + } else { + index = map->head; + } + + for (; index; index = index->next) { + if (!skip_match_clause) { + /* Apply this index. */ + match_ret = route_map_apply_match(&index->match_list, + prefix, type, object); + if (rmap_debug) { + zlog_debug( + "Route-map: %s, sequence: %d, prefix: %s, result: %s", + map->name, index->pref, + prefix2str(prefix, buf, sizeof(buf)), + route_map_cmd_result_str(match_ret)); + } + } else + skip_match_clause = false; + /* Now we apply the matrix from above */ if (match_ret == RMAP_NOOP) @@ -1801,8 +2684,7 @@ static void route_map_print_dependency(struct hash_bucket *bucket, void *data) char *rmap_name = dep_data->rname; char *dep_name = data; - zlog_debug("%s: Dependency for %s: %s", __FUNCTION__, dep_name, - rmap_name); + zlog_debug("%s: Dependency for %s: %s", __func__, dep_name, rmap_name); } static int route_map_dep_update(struct hash *dephash, const char *dep_name, @@ -2025,8 +2907,30 @@ void route_map_notify_dependencies(const char *affected_name, XFREE(MTYPE_ROUTE_MAP_NAME, name); } - /* VTY related functions. */ +DEFUN(no_routemap_optimization, no_routemap_optimization_cmd, + "no route-map optimization", + NO_STR + "route-map\n" + "optimization\n") +{ + VTY_DECLVAR_CONTEXT(route_map_index, index); + + index->map->optimization_disabled = true; + return CMD_SUCCESS; +} + +DEFUN(routemap_optimization, routemap_optimization_cmd, + "route-map optimization", + "route-map\n" + "optimization\n") +{ + VTY_DECLVAR_CONTEXT(route_map_index, index); + + index->map->optimization_disabled = false; + return CMD_SUCCESS; +} + static void clear_route_map_helper(struct route_map *map) { struct route_map_index *index; @@ -2201,6 +3105,121 @@ void route_map_counter_decrement(struct route_map *map) } } +DEFUN_HIDDEN(show_route_map_pfx_tbl, show_route_map_pfx_tbl_cmd, + "show route-map WORD prefix-table", + SHOW_STR + "route-map\n" + "route-map name\n" + "internal prefix-table\n") +{ + const char *rmap_name = argv[2]->arg; + struct route_map *rmap = NULL; + struct route_table *rm_pfx_tbl4 = NULL; + struct route_table *rm_pfx_tbl6 = NULL; + struct route_node *rn = NULL, *prn = NULL; + struct list *rmap_index_list = NULL; + struct listnode *ln = NULL, *nln = NULL; + struct route_map_index *index = NULL; + struct prefix *p = NULL, *pp = NULL; + char buf[SU_ADDRSTRLEN], pbuf[SU_ADDRSTRLEN]; + uint8_t len = 54; + + vty_out(vty, "%s:\n", frr_protonameinst); + rmap = route_map_lookup_by_name(rmap_name); + if (rmap) { + rm_pfx_tbl4 = rmap->ipv4_prefix_table; + if (rm_pfx_tbl4) { + vty_out(vty, "\n%s%43s%s\n", "IPv4 Prefix", "", + "Route-map Index List"); + vty_out(vty, "%s%39s%s\n", "_______________", "", + "____________________"); + for (rn = route_top(rm_pfx_tbl4); rn; + rn = route_next(rn)) { + p = &rn->p; + + vty_out(vty, " %s/%d (%d)\n", + inet_ntop(p->family, &p->u.prefix, buf, + SU_ADDRSTRLEN), + p->prefixlen, rn->lock); + + vty_out(vty, "(P) "); + prn = rn->parent; + if (prn) { + pp = &prn->p; + vty_out(vty, "%s/%d\n", + inet_ntop(pp->family, + &pp->u.prefix, pbuf, + SU_ADDRSTRLEN), + pp->prefixlen); + } + + vty_out(vty, "\n"); + rmap_index_list = (struct list *)rn->info; + if (!rmap_index_list + || !listcount(rmap_index_list)) + vty_out(vty, "%*s%s\n", len, "", "-"); + else + for (ALL_LIST_ELEMENTS(rmap_index_list, + ln, nln, + index)) { + vty_out(vty, "%*s%s seq %d\n", + len, "", + index->map->name, + index->pref); + } + vty_out(vty, "\n"); + } + } + + rm_pfx_tbl6 = rmap->ipv6_prefix_table; + if (rm_pfx_tbl6) { + vty_out(vty, "\n%s%43s%s\n", "IPv6 Prefix", "", + "Route-map Index List"); + vty_out(vty, "%s%39s%s\n", "_______________", "", + "____________________"); + for (rn = route_top(rm_pfx_tbl6); rn; + rn = route_next(rn)) { + p = &rn->p; + + vty_out(vty, " %s/%d (%d)\n", + inet_ntop(p->family, &p->u.prefix, buf, + SU_ADDRSTRLEN), + p->prefixlen, rn->lock); + + vty_out(vty, "(P) "); + prn = rn->parent; + if (prn) { + pp = &prn->p; + vty_out(vty, "%s/%d\n", + inet_ntop(pp->family, + &pp->u.prefix, pbuf, + SU_ADDRSTRLEN), + pp->prefixlen); + } + + vty_out(vty, "\n"); + rmap_index_list = (struct list *)rn->info; + if (!rmap_index_list + || !listcount(rmap_index_list)) + vty_out(vty, "%*s%s\n", len, "", "-"); + else + for (ALL_LIST_ELEMENTS(rmap_index_list, + ln, nln, + index)) { + vty_out(vty, "%*s%s seq %d\n", + len, "", + index->map->name, + index->pref); + } + vty_out(vty, "\n"); + } + } + } + + vty_out(vty, "\n"); + return CMD_SUCCESS; +} + /* Initialization of route map vector. */ void route_map_init(void) { @@ -2237,4 +3256,9 @@ void route_map_init(void) install_element(ENABLE_NODE, &debug_rmap_cmd); install_element(ENABLE_NODE, &no_debug_rmap_cmd); + + install_element(RMAP_NODE, &routemap_optimization_cmd); + install_element(RMAP_NODE, &no_routemap_optimization_cmd); + + install_element(ENABLE_NODE, &show_route_map_pfx_tbl_cmd); } diff --git a/lib/routemap.h b/lib/routemap.h index 05c958967c..e8cab64b47 100644 --- a/lib/routemap.h +++ b/lib/routemap.h @@ -25,6 +25,8 @@ #include "memory.h" #include "qobj.h" #include "vty.h" +#include "lib/plist.h" +#include "lib/plist_int.h" #ifdef __cplusplus extern "C" { @@ -220,6 +222,7 @@ struct route_map { /* Maintain update info */ bool to_be_processed; /* True if modification isn't acted on yet */ bool deleted; /* If 1, then this node will be deleted */ + bool optimization_disabled; /* How many times have we applied this route-map */ uint64_t applied; @@ -228,6 +231,12 @@ struct route_map { /* Counter to track active usage of this route-map */ uint16_t use_count; + /* Tables to maintain IPv4 and IPv6 prefixes from + * the prefix-list match clause. + */ + struct route_table *ipv4_prefix_table; + struct route_table *ipv6_prefix_table; + QOBJ_FIELDS }; DECLARE_QOBJ_TYPE(route_map) @@ -310,7 +319,10 @@ extern void route_map_upd8_dependency(route_map_event_t type, const char *arg, const char *rmap_name); extern void route_map_notify_dependencies(const char *affected_name, route_map_event_t event); - +extern void +route_map_notify_pentry_dependencies(const char *affected_name, + struct prefix_list_entry *pentry, + route_map_event_t event); extern int generic_match_add(struct vty *vty, struct route_map_index *index, const char *command, const char *arg, route_map_event_t type); diff --git a/lib/routemap_cli.c b/lib/routemap_cli.c index 7023710564..5b03b5266f 100644 --- a/lib/routemap_cli.c +++ b/lib/routemap_cli.c @@ -1064,7 +1064,6 @@ void route_map_cli_init(void) install_element(CONFIG_NODE, &no_route_map_all_cmd); /* Install the on-match stuff */ - install_element(RMAP_NODE, &route_map_cmd); install_element(RMAP_NODE, &rmap_onmatch_next_cmd); install_element(RMAP_NODE, &no_rmap_onmatch_next_cmd); install_element(RMAP_NODE, &rmap_onmatch_goto_cmd); diff --git a/lib/routemap_northbound.c b/lib/routemap_northbound.c index 68b112b09a..69cebbd2a1 100644 --- a/lib/routemap_northbound.c +++ b/lib/routemap_northbound.c @@ -221,8 +221,7 @@ static int lib_route_map_entry_description_modify(enum nb_event event, break; case NB_EV_APPLY: rmi = nb_running_get_entry(dnode, NULL, true); - if (rmi->description != NULL) - XFREE(MTYPE_TMP, rmi->description); + XFREE(MTYPE_TMP, rmi->description); rmi->description = resource->ptr; break; } @@ -243,9 +242,7 @@ static int lib_route_map_entry_description_destroy(enum nb_event event, break; case NB_EV_APPLY: rmi = nb_running_get_entry(dnode, NULL, true); - if (rmi->description != NULL) - XFREE(MTYPE_TMP, rmi->description); - rmi->description = NULL; + XFREE(MTYPE_TMP, rmi->description); break; } diff --git a/lib/seqlock.c b/lib/seqlock.c index c05ec19db4..77673146ea 100644 --- a/lib/seqlock.c +++ b/lib/seqlock.c @@ -165,7 +165,7 @@ bool seqlock_timedwait(struct seqlock *sqlo, seqlock_val_t val, /* * ABS_REALTIME - used on NetBSD, Solaris and OSX */ -#if TIME_ABS_REALTIME +#ifdef TIME_ABS_REALTIME #define time_arg1 &abs_rt #define time_arg2 NULL #define time_prep @@ -187,7 +187,7 @@ bool seqlock_timedwait(struct seqlock *sqlo, seqlock_val_t val, /* * RELATIVE - used on OpenBSD (might get a patch to get absolute monotime) */ -#elif TIME_RELATIVE +#elif defined(TIME_RELATIVE) struct timespec reltime; #define time_arg1 abs_monotime_limit @@ -254,7 +254,7 @@ bool seqlock_check(struct seqlock *sqlo, seqlock_val_t val) cur = atomic_load_explicit(&sqlo->pos, memory_order_relaxed); if (!(cur & SEQLOCK_HELD)) - return 1; + return true; cur = SEQLOCK_VAL(cur) - val - 1; assert(cur < 0x40000000 || cur > 0xc0000000); return cur < 0x80000000; diff --git a/lib/skiplist.c b/lib/skiplist.c index 6efa2c362d..d955c6eb9e 100644 --- a/lib/skiplist.c +++ b/lib/skiplist.c @@ -211,12 +211,12 @@ int skiplist_insert(register struct skiplist *l, register void *key, q = newNodeOfLevel(k); q->key = key; q->value = value; -#if SKIPLIST_0TIMER_DEBUG +#ifdef SKIPLIST_0TIMER_DEBUG q->flags = SKIPLIST_NODE_FLAG_INSERTED; /* debug */ #endif ++(l->stats->forward[k]); -#if SKIPLIST_DEBUG +#ifdef SKIPLIST_DEBUG zlog_debug("%s: incremented stats @%p:%d, now %ld", __func__, l, k, l->stats->forward[k] - (struct skiplistnode *)NULL); #endif @@ -281,7 +281,7 @@ int skiplist_delete(register struct skiplist *l, register void *key, /* * found node to delete */ -#if SKIPLIST_0TIMER_DEBUG +#ifdef SKIPLIST_0TIMER_DEBUG q->flags &= ~SKIPLIST_NODE_FLAG_INSERTED; #endif /* @@ -300,7 +300,7 @@ int skiplist_delete(register struct skiplist *l, register void *key, p->forward[k] = q->forward[k]; } --(l->stats->forward[k - 1]); -#if SKIPLIST_DEBUG +#ifdef SKIPLIST_DEBUG zlog_debug("%s: decremented stats @%p:%d, now %ld", __func__, l, k - 1, l->stats->forward[k - 1] @@ -378,7 +378,7 @@ int skiplist_next_value(register struct skiplist *l, /* in */ void **valuePointer, /* in/out */ void **cursor) /* in/out */ { - register int k, m; + register int k; register struct skiplistnode *p, *q; CHECKLAST(l); @@ -389,7 +389,7 @@ int skiplist_next_value(register struct skiplist *l, /* in */ if (!cursor || !*cursor) { p = l->header; - k = m = l->level; + k = l->level; /* * Find matching key @@ -549,7 +549,7 @@ int skiplist_delete_first(register struct skiplist *l) } } -#if SKIPLIST_0TIMER_DEBUG +#ifdef SKIPLIST_0TIMER_DEBUG q->flags &= ~SKIPLIST_NODE_FLAG_INSERTED; #endif /* @@ -561,7 +561,7 @@ int skiplist_delete_first(register struct skiplist *l) } --(l->stats->forward[nodelevel]); -#if SKIPLIST_DEBUG +#ifdef SKIPLIST_DEBUG zlog_debug("%s: decremented stats @%p:%d, now %ld", __func__, l, nodelevel, l->stats->forward[nodelevel] - (struct skiplistnode *)NULL); diff --git a/lib/sockopt.c b/lib/sockopt.c index d6c88c0aff..45d9008796 100644 --- a/lib/sockopt.c +++ b/lib/sockopt.c @@ -90,12 +90,11 @@ int getsockopt_so_recvbuf(const int sock) static void *getsockopt_cmsg_data(struct msghdr *msgh, int level, int type) { struct cmsghdr *cmsg; - void *ptr = NULL; for (cmsg = CMSG_FIRSTHDR(msgh); cmsg != NULL; cmsg = CMSG_NXTHDR(msgh, cmsg)) if (cmsg->cmsg_level == level && cmsg->cmsg_type == type) - return (ptr = CMSG_DATA(cmsg)); + return CMSG_DATA(cmsg); return NULL; } @@ -684,7 +683,7 @@ int sockopt_tcp_signature_ext(int sock, union sockunion *su, uint16_t prefixlen, #endif /* GNU_LINUX */ if ((ret = setsockopt(sock, IPPROTO_TCP, optname, &md5sig, - sizeof md5sig)) + sizeof(md5sig))) < 0) { /* ENOENT is harmless. It is returned when we clear a password for which diff --git a/lib/sockopt.h b/lib/sockopt.h index 59d8a65964..4081e6a45b 100644 --- a/lib/sockopt.h +++ b/lib/sockopt.h @@ -39,7 +39,7 @@ extern int setsockopt_ipv6_hoplimit(int, int); extern int setsockopt_ipv6_multicast_loop(int, int); extern int setsockopt_ipv6_tclass(int, int); -#define SOPT_SIZE_CMSG_PKTINFO_IPV6() (sizeof (struct in6_pktinfo)); +#define SOPT_SIZE_CMSG_PKTINFO_IPV6() (sizeof(struct in6_pktinfo)); /* * Size defines for control messages used to get ifindex. We define @@ -49,7 +49,7 @@ extern int setsockopt_ipv6_tclass(int, int); */ #if defined(IP_PKTINFO) /* Linux in_pktinfo. */ -#define SOPT_SIZE_CMSG_PKTINFO_IPV4() (CMSG_SPACE(sizeof (struct in_pktinfo))) +#define SOPT_SIZE_CMSG_PKTINFO_IPV4() (CMSG_SPACE(sizeof(struct in_pktinfo))) /* XXX This should perhaps be defined even if IP_PKTINFO is not. */ #define SOPT_SIZE_CMSG_PKTINFO(af) \ ((af == AF_INET) ? SOPT_SIZE_CMSG_PKTINFO_IPV4() \ @@ -60,9 +60,9 @@ extern int setsockopt_ipv6_tclass(int, int); /* BSD/Solaris */ #if defined(SUNOS_5) -#define SOPT_SIZE_CMSG_RECVIF_IPV4() (sizeof (uint_t)) +#define SOPT_SIZE_CMSG_RECVIF_IPV4() (sizeof(uint_t)) #else -#define SOPT_SIZE_CMSG_RECVIF_IPV4() (sizeof (struct sockaddr_dl)) +#define SOPT_SIZE_CMSG_RECVIF_IPV4() (sizeof(struct sockaddr_dl)) #endif /* SUNOS_5 */ #endif /* IP_RECVIF */ @@ -72,7 +72,7 @@ extern int setsockopt_ipv6_tclass(int, int); #elif defined(SOPT_SIZE_CMSG_RECVIF_IPV4) #define SOPT_SIZE_CMSG_IFINDEX_IPV4() SOPT_SIZE_CMSG_RECVIF_IPV4() #else /* Nothing available */ -#define SOPT_SIZE_CMSG_IFINDEX_IPV4() (sizeof (char *)) +#define SOPT_SIZE_CMSG_IFINDEX_IPV4() (sizeof(char *)) #endif /* SOPT_SIZE_CMSG_IFINDEX_IPV4 */ #define SOPT_SIZE_CMSG_IFINDEX(af) \ diff --git a/lib/sockunion.c b/lib/sockunion.c index e9c418fdf2..63d8a8c69b 100644 --- a/lib/sockunion.c +++ b/lib/sockunion.c @@ -214,7 +214,7 @@ enum connect_result sockunion_connect(int fd, const union sockunion *peersu, if (errno != EINPROGRESS) { char str[SU_ADDRSTRLEN]; zlog_info("can't connect to %s fd %d : %s", - sockunion_log(&su, str, sizeof str), fd, + sockunion_log(&su, str, sizeof(str)), fd, safe_strerror(errno)); return connect_error; } @@ -518,8 +518,8 @@ union sockunion *sockunion_getsockname(int fd) } name; union sockunion *su; - memset(&name, 0, sizeof name); - len = sizeof name; + memset(&name, 0, sizeof(name)); + len = sizeof(name); ret = getsockname(fd, (struct sockaddr *)&name, &len); if (ret < 0) { @@ -556,8 +556,8 @@ union sockunion *sockunion_getpeername(int fd) } name; union sockunion *su; - memset(&name, 0, sizeof name); - len = sizeof name; + memset(&name, 0, sizeof(name)); + len = sizeof(name); ret = getpeername(fd, (struct sockaddr *)&name, &len); if (ret < 0) { flog_err(EC_LIB_SOCKET, "Can't get remote address and port: %s", diff --git a/lib/stream.h b/lib/stream.h index c0d25e0579..36c65afa3c 100644 --- a/lib/stream.h +++ b/lib/stream.h @@ -110,7 +110,7 @@ struct stream { size_t getp; /* next get position */ size_t endp; /* last valid data position */ size_t size; /* size of data segment */ - unsigned char data[0]; /* data pointer */ + unsigned char data[]; /* data pointer */ }; /* First in first out queue structure. */ diff --git a/lib/systemd.c b/lib/systemd.c index 81b0400ab9..c5cc3aa447 100644 --- a/lib/systemd.c +++ b/lib/systemd.c @@ -114,8 +114,10 @@ void systemd_send_started(struct thread_master *m, int the_process) systemd_master = m; systemd_send_information("READY=1"); - if (wsecs != 0) + if (wsecs != 0) { + systemd_send_information("WATCHDOG=1"); thread_add_timer(m, systemd_send_watchdog, m, wsecs, NULL); + } } void systemd_send_status(const char *status) diff --git a/lib/thread.c b/lib/thread.c index 651d26dfb2..2217a60f0a 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -171,7 +171,7 @@ static void cpu_record_print(struct vty *vty, uint8_t filter) struct thread_master *m; struct listnode *ln; - memset(&tmp, 0, sizeof tmp); + memset(&tmp, 0, sizeof(tmp)); tmp.funcname = "TOTAL"; tmp.types = filter; @@ -493,8 +493,7 @@ void vrf_init(int (*create)(struct vrf *), int (*enable)(struct vrf *), /* initialise NS, in case VRF backend if NETNS */ ns_init(); if (debug_vrf) - zlog_debug("%s: Initializing VRF subsystem", - __PRETTY_FUNCTION__); + zlog_debug("%s: Initializing VRF subsystem", __func__); vrf_master.vrf_new_hook = create; vrf_master.vrf_enable_hook = enable; @@ -535,8 +534,7 @@ void vrf_terminate(void) struct vrf *vrf; if (debug_vrf) - zlog_debug("%s: Shutting down vrf subsystem", - __PRETTY_FUNCTION__); + zlog_debug("%s: Shutting down vrf subsystem", __func__); while (!RB_EMPTY(vrf_id_head, &vrfs_by_id)) { vrf = RB_ROOT(vrf_id_head, &vrfs_by_id); @@ -114,6 +114,8 @@ extern struct vrf *vrf_get(vrf_id_t, const char *); extern const char *vrf_id_to_name(vrf_id_t vrf_id); extern vrf_id_t vrf_name_to_id(const char *); +#define VRF_LOGNAME(V) V ? V->name : "Unknown" + #define VRF_GET_ID(V, NAME, USE_JSON) \ do { \ struct vrf *_vrf; \ diff --git a/lib/wheel.c b/lib/wheel.c index 8e479c931b..f5e5cc52c3 100644 --- a/lib/wheel.c +++ b/lib/wheel.c @@ -47,8 +47,8 @@ static int wheel_timer_thread_helper(struct thread *t) curr_slot = wheel->curr_slot % wheel->slots; if (debug_timer_wheel) - zlog_debug("%s: Wheel Slot: %lld(%lld) count: %d", - __PRETTY_FUNCTION__, wheel->curr_slot, curr_slot, + zlog_debug("%s: Wheel Slot: %lld(%lld) count: %d", __func__, + wheel->curr_slot, curr_slot, listcount(wheel->wheel_slot_lists[curr_slot])); for (ALL_LIST_ELEMENTS(wheel->wheel_slot_lists[curr_slot], node, @@ -146,8 +146,8 @@ int wheel_add_item(struct timer_wheel *wheel, void *item) slot = (*wheel->slot_key)(item); if (debug_timer_wheel) - zlog_debug("%s: Inserting %p: %lld %lld", __PRETTY_FUNCTION__, - item, slot, slot % wheel->slots); + zlog_debug("%s: Inserting %p: %lld %lld", __func__, item, slot, + slot % wheel->slots); listnode_add(wheel->wheel_slot_lists[slot % wheel->slots], item); return 0; @@ -160,8 +160,8 @@ int wheel_remove_item(struct timer_wheel *wheel, void *item) slot = (*wheel->slot_key)(item); if (debug_timer_wheel) - zlog_debug("%s: Removing %p: %lld %lld", __PRETTY_FUNCTION__, - item, slot, slot % wheel->slots); + zlog_debug("%s: Removing %p: %lld %lld", __func__, item, slot, + slot % wheel->slots); listnode_delete(wheel->wheel_slot_lists[slot % wheel->slots], item); return 0; diff --git a/lib/zclient.c b/lib/zclient.c index b0d2ea43a2..eac6c7081d 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -236,9 +236,8 @@ int zclient_socket_connect(struct zclient *zclient) ret = connect(sock, (struct sockaddr *)&zclient_addr, zclient_addr_len); if (ret < 0) { if (zclient_debug) - zlog_debug("%s connect failure: %d(%s)", - __PRETTY_FUNCTION__, errno, - safe_strerror(errno)); + zlog_debug("%s connect failure: %d(%s)", __func__, + errno, safe_strerror(errno)); close(sock); return -1; } @@ -958,7 +957,7 @@ int zapi_route_encode(uint8_t cmd, struct stream *s, struct zapi_route *api) if (api->type >= ZEBRA_ROUTE_MAX) { flog_err(EC_LIB_ZAPI_ENCODE, "%s: Specified route type (%u) is not a legal value\n", - __PRETTY_FUNCTION__, api->type); + __func__, api->type); return -1; } stream_putc(s, api->type); @@ -970,7 +969,7 @@ int zapi_route_encode(uint8_t cmd, struct stream *s, struct zapi_route *api) if (api->safi < SAFI_UNICAST || api->safi >= SAFI_MAX) { flog_err(EC_LIB_ZAPI_ENCODE, "%s: Specified route SAFI (%u) is not a legal value\n", - __PRETTY_FUNCTION__, api->safi); + __func__, api->safi); return -1; } stream_putc(s, api->safi); @@ -1122,7 +1121,7 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api) if (api->type >= ZEBRA_ROUTE_MAX) { flog_err(EC_LIB_ZAPI_ENCODE, "%s: Specified route type: %d is not a legal value\n", - __PRETTY_FUNCTION__, api->type); + __func__, api->type); return -1; } @@ -1133,7 +1132,7 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api) if (api->safi < SAFI_UNICAST || api->safi >= SAFI_MAX) { flog_err(EC_LIB_ZAPI_ENCODE, "%s: Specified route SAFI (%u) is not a legal value\n", - __PRETTY_FUNCTION__, api->safi); + __func__, api->safi); return -1; } @@ -1146,7 +1145,7 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api) flog_err( EC_LIB_ZAPI_ENCODE, "%s: V4 prefixlen is %d which should not be more than 32", - __PRETTY_FUNCTION__, api->prefix.prefixlen); + __func__, api->prefix.prefixlen); return -1; } break; @@ -1155,14 +1154,14 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api) flog_err( EC_LIB_ZAPI_ENCODE, "%s: v6 prefixlen is %d which should not be more than 128", - __PRETTY_FUNCTION__, api->prefix.prefixlen); + __func__, api->prefix.prefixlen); return -1; } break; default: flog_err(EC_LIB_ZAPI_ENCODE, - "%s: Specified family %d is not v4 or v6", - __PRETTY_FUNCTION__, api->prefix.family); + "%s: Specified family %d is not v4 or v6", __func__, + api->prefix.family); return -1; } STREAM_GET(&api->prefix.u.prefix, s, PSIZE(api->prefix.prefixlen)); @@ -1174,7 +1173,7 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api) flog_err( EC_LIB_ZAPI_ENCODE, "%s: SRC Prefix prefixlen received: %d is too large", - __PRETTY_FUNCTION__, api->src_prefix.prefixlen); + __func__, api->src_prefix.prefixlen); return -1; } STREAM_GET(&api->src_prefix.prefix, s, @@ -1185,7 +1184,7 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api) flog_err( EC_LIB_ZAPI_ENCODE, "%s: SRC prefix specified in some manner that makes no sense", - __PRETTY_FUNCTION__); + __func__); return -1; } } @@ -1309,8 +1308,7 @@ bool zapi_rule_notify_decode(struct stream *s, uint32_t *seqno, STREAM_GETL(s, ifi); if (zclient_debug) - zlog_debug("%s: %u %u %u %u", __PRETTY_FUNCTION__, seq, prio, - uni, ifi); + zlog_debug("%s: %u %u %u %u", __func__, seq, prio, uni, ifi); *seqno = seq; *priority = prio; *unique = uni; @@ -1332,7 +1330,7 @@ bool zapi_ipset_notify_decode(struct stream *s, uint32_t *unique, STREAM_GETL(s, uni); if (zclient_debug) - zlog_debug("%s: %u", __PRETTY_FUNCTION__, uni); + zlog_debug("%s: %u", __func__, uni); *unique = uni; return true; @@ -1354,7 +1352,7 @@ bool zapi_ipset_entry_notify_decode(struct stream *s, uint32_t *unique, STREAM_GET(ipset_name, s, ZEBRA_IPSET_NAME_SIZE); if (zclient_debug) - zlog_debug("%s: %u", __PRETTY_FUNCTION__, uni); + zlog_debug("%s: %u", __func__, uni); *unique = uni; return true; @@ -1374,7 +1372,7 @@ bool zapi_iptable_notify_decode(struct stream *s, STREAM_GETL(s, uni); if (zclient_debug) - zlog_debug("%s: %u", __PRETTY_FUNCTION__, uni); + zlog_debug("%s: %u", __func__, uni); *unique = uni; return true; @@ -1978,7 +1976,7 @@ struct connected *zebra_interface_address_read(int type, struct stream *s, "warning: interface %s address %s with peer flag set, but no peer address!", ifp->name, prefix2str(ifc->address, buf, - sizeof buf)); + sizeof(buf))); UNSET_FLAG(ifc->flags, ZEBRA_IFA_PEER); } } @@ -2664,8 +2662,7 @@ int zapi_labels_decode(struct stream *s, struct zapi_labels *zl) if (zl->route.prefix.prefixlen > IPV4_MAX_BITLEN) { zlog_debug( "%s: Specified prefix length %d is greater than a v4 address can support", - __PRETTY_FUNCTION__, - zl->route.prefix.prefixlen); + __func__, zl->route.prefix.prefixlen); return -1; } STREAM_GET(&zl->route.prefix.u.prefix4.s_addr, s, @@ -2675,8 +2672,7 @@ int zapi_labels_decode(struct stream *s, struct zapi_labels *zl) if (zl->route.prefix.prefixlen > IPV6_MAX_BITLEN) { zlog_debug( "%s: Specified prefix length %d is greater than a v6 address can support", - __PRETTY_FUNCTION__, - zl->route.prefix.prefixlen); + __func__, zl->route.prefix.prefixlen); return -1; } STREAM_GET(&zl->route.prefix.u.prefix6, s, psize); @@ -2684,7 +2680,7 @@ int zapi_labels_decode(struct stream *s, struct zapi_labels *zl) default: flog_err(EC_LIB_ZAPI_ENCODE, "%s: Specified family %u is not v4 or v6", - __PRETTY_FUNCTION__, zl->route.prefix.family); + __func__, zl->route.prefix.family); return -1; } diff --git a/m4/ax_python.m4 b/m4/ax_python.m4 index 69809184ee..d293da5257 100644 --- a/m4/ax_python.m4 +++ b/m4/ax_python.m4 @@ -3,7 +3,7 @@ dnl 2019 David Lamparter for NetDEF, Inc. dnl SPDX-License-Identifier: GPL-2.0-or-later dnl the _ at the beginning will be cut off (to support the empty version string) -m4_define_default([_FRR_PY_VERS], [_3 _ _2 _3.7 _3.6 _3.5 _3.4 _3.3 _3.2 _2.7]) +m4_define_default([_FRR_PY_VERS], [_3 _ _2 _3.8 _3.7 _3.6 _3.5 _3.4 _3.3 _3.2 _2.7]) dnl check basic interpreter properties (py2/py3) dnl doubles as simple check whether the interpreter actually works diff --git a/nhrpd/netlink_arp.c b/nhrpd/netlink_arp.c index 6666c6e96b..cf338a0876 100644 --- a/nhrpd/netlink_arp.c +++ b/nhrpd/netlink_arp.c @@ -65,11 +65,12 @@ static void netlink_neigh_msg(struct nlmsghdr *msg, struct zbuf *zb) struct nhrp_cache *c; struct interface *ifp; struct zbuf payload; - union sockunion addr; + union sockunion addr, lladdr; size_t len; - char buf[SU_ADDRSTRLEN]; + char buf[4][SU_ADDRSTRLEN]; int state; + memset(&lladdr, 0, sizeof(lladdr)); ndm = znl_pull(zb, sizeof(*ndm)); if (!ndm) return; @@ -82,6 +83,10 @@ static void netlink_neigh_msg(struct nlmsghdr *msg, struct zbuf *zb) sockunion_set(&addr, ndm->ndm_family, zbuf_pulln(&payload, len), len); break; + case NDA_LLADDR: + sockunion_set(&lladdr, ndm->ndm_family, + zbuf_pulln(&payload, len), len); + break; } } @@ -93,20 +98,34 @@ static void netlink_neigh_msg(struct nlmsghdr *msg, struct zbuf *zb) if (!c) return; - if (msg->nlmsg_type == RTM_GETNEIGH) { - debugf(NHRP_DEBUG_KERNEL, "Netlink: who-has %s dev %s", - sockunion2str(&addr, buf, sizeof buf), ifp->name); + debugf(NHRP_DEBUG_KERNEL, + "Netlink: %s %s dev %s lladdr %s nud 0x%x cache used %u type %u", + (msg->nlmsg_type == RTM_GETNEIGH) + ? "who-has" + : (msg->nlmsg_type == RTM_NEWNEIGH) ? "new-neigh" + : "del-neigh", + sockunion2str(&addr, buf[0], sizeof(buf[0])), ifp->name, + sockunion2str(&lladdr, buf[1], sizeof(buf[1])), ndm->ndm_state, + c->used, c->cur.type); + if (msg->nlmsg_type == RTM_GETNEIGH) { if (c->cur.type >= NHRP_CACHE_CACHED) { nhrp_cache_set_used(c, 1); - netlink_update_binding(ifp, &addr, - &c->cur.peer->vc->remote.nbma); + debugf(NHRP_DEBUG_KERNEL, + "Netlink: update binding for %s dev %s from c %s peer.vc.nbma %s to lladdr %s", + sockunion2str(&addr, buf[0], sizeof(buf[0])), + ifp->name, + sockunion2str(&c->cur.remote_nbma_natoa, buf[1], + sizeof(buf[1])), + sockunion2str(&c->cur.peer->vc->remote.nbma, + buf[2], sizeof(buf[2])), + sockunion2str(&lladdr, buf[3], sizeof(buf[3]))); + /* In case of shortcuts, nbma is given by lladdr, not + * vc->remote.nbma. + */ + netlink_update_binding(ifp, &addr, &lladdr); } } else { - debugf(NHRP_DEBUG_KERNEL, "Netlink: update %s dev %s nud %x", - sockunion2str(&addr, buf, sizeof buf), ifp->name, - ndm->ndm_state); - state = (msg->nlmsg_type == RTM_NEWNEIGH) ? ndm->ndm_state : NUD_FAILED; nhrp_cache_set_used(c, state == NUD_REACHABLE); diff --git a/nhrpd/nhrp_cache.c b/nhrpd/nhrp_cache.c index cc18b36f6a..42f6a88f95 100644 --- a/nhrpd/nhrp_cache.c +++ b/nhrpd/nhrp_cache.c @@ -119,12 +119,43 @@ static void nhrp_cache_update_route(struct nhrp_cache *c) { struct prefix pfx; struct nhrp_peer *p = c->cur.peer; + char buf[3][SU_ADDRSTRLEN]; + struct nhrp_interface *nifp; sockunion2hostprefix(&c->remote_addr, &pfx); if (p && nhrp_peer_check(p, 1)) { - netlink_update_binding(p->ifp, &c->remote_addr, - &p->vc->remote.nbma); + if (sockunion_family(&c->cur.remote_nbma_natoa) != AF_UNSPEC) { + /* remote_nbma_natoa is already set. Therefore, binding + * should be updated to this value and not vc's remote + * nbma. + */ + debugf(NHRP_DEBUG_COMMON, + "cache (remote_nbma_natoa set): Update binding for %s dev %s from (deleted) peer.vc.nbma %s to %s", + sockunion2str(&c->remote_addr, buf[0], + sizeof(buf[0])), + p->ifp->name, + sockunion2str(&p->vc->remote.nbma, buf[1], + sizeof(buf[1])), + sockunion2str(&c->cur.remote_nbma_natoa, buf[2], + sizeof(buf[2]))); + + netlink_update_binding(p->ifp, &c->remote_addr, + &c->cur.remote_nbma_natoa); + } else { + /* update binding to peer->vc->remote->nbma */ + debugf(NHRP_DEBUG_COMMON, + "cache (remote_nbma_natoa unspec): Update binding for %s dev %s from (deleted) to peer.vc.nbma %s", + sockunion2str(&c->remote_addr, buf[0], + sizeof(buf[0])), + p->ifp->name, + sockunion2str(&p->vc->remote.nbma, buf[1], + sizeof(buf[1]))); + + netlink_update_binding(p->ifp, &c->remote_addr, + &p->vc->remote.nbma); + } + nhrp_route_announce(1, c->cur.type, &pfx, c->ifp, NULL, c->cur.mtu); if (c->cur.type >= NHRP_CACHE_DYNAMIC) { @@ -139,6 +170,17 @@ static void nhrp_cache_update_route(struct nhrp_cache *c) c->route_installed = 1; } } else { + /* debug the reason for peer check fail */ + if (p) { + nifp = p->ifp->info; + debugf(NHRP_DEBUG_COMMON, + "cache (peer check failed: online?%d requested?%d ipsec?%d)", + p->online, p->requested, + nifp->ipsec_profile ? 1 : 0); + } else + debugf(NHRP_DEBUG_COMMON, + "cache (peer check failed: no p)"); + if (c->nhrp_route_installed) { nhrp_route_update_nhrp(&pfx, NULL); c->nhrp_route_installed = 0; @@ -207,10 +249,10 @@ static void nhrp_cache_update_timers(struct nhrp_cache *c) static void nhrp_cache_authorize_binding(struct nhrp_reqid *r, void *arg) { struct nhrp_cache *c = container_of(r, struct nhrp_cache, eventid); - char buf[SU_ADDRSTRLEN]; + char buf[3][SU_ADDRSTRLEN]; debugf(NHRP_DEBUG_COMMON, "cache: %s %s: %s", c->ifp->name, - sockunion2str(&c->remote_addr, buf, sizeof buf), + sockunion2str(&c->remote_addr, buf[0], sizeof(buf[0])), (const char *)arg); nhrp_reqid_free(&nhrp_event_reqid, r); @@ -230,6 +272,26 @@ static void nhrp_cache_authorize_binding(struct nhrp_reqid *r, void *arg) if (c->cur.peer) nhrp_peer_notify_add(c->cur.peer, &c->peer_notifier, nhrp_cache_peer_notifier); + + if (sockunion_family(&c->cur.remote_nbma_natoa) != AF_UNSPEC) { + debugf(NHRP_DEBUG_COMMON, + "cache: update binding for %s dev %s from (deleted) peer.vc.nbma %s to %s", + sockunion2str(&c->remote_addr, buf[0], + sizeof(buf[0])), + c->ifp->name, + (c->cur.peer ? sockunion2str( + &c->cur.peer->vc->remote.nbma, buf[1], + sizeof(buf[1])) + : "(no peer)"), + sockunion2str(&c->cur.remote_nbma_natoa, buf[2], + sizeof(buf[2]))); + + if (c->cur.peer) + netlink_update_binding( + c->cur.peer->ifp, &c->remote_addr, + &c->cur.remote_nbma_natoa); + } + nhrp_cache_update_route(c); notifier_call(&c->notifier_list, NOTIFY_CACHE_BINDING_CHANGE); } else { @@ -273,6 +335,8 @@ int nhrp_cache_update_binding(struct nhrp_cache *c, enum nhrp_cache_type type, int holding_time, struct nhrp_peer *p, uint32_t mtu, union sockunion *nbma_oa) { + char buf[2][SU_ADDRSTRLEN]; + if (c->cur.type > type || c->new.type > type) { nhrp_peer_unref(p); return 0; @@ -293,17 +357,31 @@ int nhrp_cache_update_binding(struct nhrp_cache *c, enum nhrp_cache_type type, break; } + sockunion2str(&c->cur.remote_nbma_natoa, buf[0], sizeof(buf[0])); + if (nbma_oa) + sockunion2str(nbma_oa, buf[1], sizeof(buf[1])); + nhrp_cache_reset_new(c); if (c->cur.type == type && c->cur.peer == p && c->cur.mtu == mtu) { + debugf(NHRP_DEBUG_COMMON, + "cache: same type %u, updating expiry and changing nbma addr from %s to %s", + type, buf[0], nbma_oa ? buf[1] : "(NULL)"); if (holding_time > 0) c->cur.expires = monotime(NULL) + holding_time; + if (nbma_oa) c->cur.remote_nbma_natoa = *nbma_oa; else memset(&c->cur.remote_nbma_natoa, 0, - sizeof c->cur.remote_nbma_natoa); + sizeof(c->cur.remote_nbma_natoa)); + nhrp_peer_unref(p); } else { + debugf(NHRP_DEBUG_COMMON, + "cache: new type %u/%u, or peer %s, or mtu %u/%u, nbma %s --> %s (map %d)", + c->cur.type, type, (c->cur.peer == p) ? "same" : "diff", + c->cur.mtu, mtu, buf[0], nbma_oa ? buf[1] : "(NULL)", + c->map); c->new.type = type; c->new.peer = p; c->new.mtu = mtu; diff --git a/nhrpd/nhrp_event.c b/nhrpd/nhrp_event.c index 9301c2d515..40efeb5795 100644 --- a/nhrpd/nhrp_event.c +++ b/nhrpd/nhrp_event.c @@ -200,7 +200,7 @@ static int evmgr_reconnect(struct thread *t) fd = sock_open_unix(nhrp_event_socket_path); if (fd < 0) { zlog_warn("%s: failure connecting nhrp-event socket: %s", - __PRETTY_FUNCTION__, strerror(errno)); + __func__, strerror(errno)); zbufq_reset(&evmgr->obuf); thread_add_timer(master, evmgr_reconnect, evmgr, 10, &evmgr->t_reconnect); diff --git a/nhrpd/nhrp_interface.c b/nhrpd/nhrp_interface.c index 7cf8dfbde4..1e576fc5ac 100644 --- a/nhrpd/nhrp_interface.c +++ b/nhrpd/nhrp_interface.c @@ -112,7 +112,7 @@ static void nhrp_interface_interface_notifier(struct notifier_block *n, NOTIFY_INTERFACE_NBMA_CHANGED); debugf(NHRP_DEBUG_IF, "%s: NBMA change: address %s", nifp->ifp->name, - sockunion2str(&nifp->nbma, buf, sizeof buf)); + sockunion2str(&nifp->nbma, buf, sizeof(buf))); break; } } @@ -221,7 +221,7 @@ static void nhrp_interface_update_address(struct interface *ifp, afi_t afi, if (best && if_ad->configured && best->address->prefixlen != 8 * prefix_blen(best->address)) { zlog_notice("%s: %s is not a host prefix", ifp->name, - prefix2str(best->address, buf, sizeof buf)); + prefix2str(best->address, buf, sizeof(buf))); best = NULL; } @@ -243,7 +243,7 @@ static void nhrp_interface_update_address(struct interface *ifp, afi_t afi, debugf(NHRP_DEBUG_KERNEL, "%s: IPv%d address changed to %s", ifp->name, afi == AFI_IP ? 4 : 6, - best ? prefix2str(best->address, buf, sizeof buf) : "(none)"); + best ? prefix2str(best->address, buf, sizeof(buf)) : "(none)"); if_ad->addr = addr; if (if_ad->configured && sockunion_family(&if_ad->addr) != AF_UNSPEC) { @@ -342,7 +342,7 @@ int nhrp_interface_address_add(ZAPI_CALLBACK_ARGS) return 0; debugf(NHRP_DEBUG_IF, "if-addr-add: %s: %s", ifc->ifp->name, - prefix2str(ifc->address, buf, sizeof buf)); + prefix2str(ifc->address, buf, sizeof(buf))); nhrp_interface_update_address( ifc->ifp, family2afi(PREFIX_FAMILY(ifc->address)), 0); @@ -360,7 +360,7 @@ int nhrp_interface_address_delete(ZAPI_CALLBACK_ARGS) return 0; debugf(NHRP_DEBUG_IF, "if-addr-del: %s: %s", ifc->ifp->name, - prefix2str(ifc->address, buf, sizeof buf)); + prefix2str(ifc->address, buf, sizeof(buf))); nhrp_interface_update_address( ifc->ifp, family2afi(PREFIX_FAMILY(ifc->address)), 0); diff --git a/nhrpd/nhrp_nhs.c b/nhrpd/nhrp_nhs.c index bec6c014a0..8509cedcee 100644 --- a/nhrpd/nhrp_nhs.c +++ b/nhrpd/nhrp_nhs.c @@ -136,7 +136,7 @@ static void nhrp_reg_peer_notify(struct notifier_block *n, unsigned long cmd) case NOTIFY_PEER_MTU_CHANGED: debugf(NHRP_DEBUG_COMMON, "NHS: Flush timer for %s", sockunion2str(&r->peer->vc->remote.nbma, buf, - sizeof buf)); + sizeof(buf))); THREAD_TIMER_OFF(r->t_register); thread_add_timer_msec(master, nhrp_reg_send_req, r, 10, &r->t_register); @@ -162,7 +162,7 @@ static int nhrp_reg_send_req(struct thread *t) if (!nhrp_peer_check(r->peer, 2)) { debugf(NHRP_DEBUG_COMMON, "NHS: Waiting link for %s", sockunion2str(&r->peer->vc->remote.nbma, buf1, - sizeof buf1)); + sizeof(buf1))); thread_add_timer(master, nhrp_reg_send_req, r, 120, &r->t_register); return 0; diff --git a/nhrpd/nhrp_peer.c b/nhrpd/nhrp_peer.c index c5e985cdac..2dc019ce65 100644 --- a/nhrpd/nhrp_peer.c +++ b/nhrpd/nhrp_peer.c @@ -305,8 +305,8 @@ void nhrp_peer_send(struct nhrp_peer *p, struct zbuf *zb) return; debugf(NHRP_DEBUG_KERNEL, "PACKET: Send %s -> %s", - sockunion2str(&p->vc->local.nbma, buf[0], sizeof buf[0]), - sockunion2str(&p->vc->remote.nbma, buf[1], sizeof buf[1])); + sockunion2str(&p->vc->local.nbma, buf[0], sizeof(buf[0])), + sockunion2str(&p->vc->remote.nbma, buf[1], sizeof(buf[1]))); os_sendmsg(zb->head, zbuf_used(zb), p->ifp->ifindex, sockunion_get_addr(&p->vc->remote.nbma), @@ -314,23 +314,29 @@ void nhrp_peer_send(struct nhrp_peer *p, struct zbuf *zb) zbuf_reset(zb); } -static void nhrp_handle_resolution_req(struct nhrp_packet_parser *p) +static void nhrp_handle_resolution_req(struct nhrp_packet_parser *pp) { + struct interface *ifp = pp->ifp; struct zbuf *zb, payload; struct nhrp_packet_header *hdr; struct nhrp_cie_header *cie; struct nhrp_extension_header *ext; - struct nhrp_interface *nifp; + struct nhrp_cache *c; + union sockunion cie_nbma, cie_proto, *proto_addr, *nbma_addr; + int holdtime, prefix_len, hostprefix_len; + struct nhrp_interface *nifp = ifp->info; struct nhrp_peer *peer; + size_t paylen; + char buf[SU_ADDRSTRLEN]; - if (!(p->if_ad->flags & NHRP_IFF_SHORTCUT)) { + if (!(pp->if_ad->flags & NHRP_IFF_SHORTCUT)) { debugf(NHRP_DEBUG_COMMON, "Shortcuts disabled"); /* FIXME: Send error indication? */ return; } - if (p->if_ad->network_id && p->route_type == NHRP_ROUTE_OFF_NBMA - && p->route_prefix.prefixlen < 8) { + if (pp->if_ad->network_id && pp->route_type == NHRP_ROUTE_OFF_NBMA + && pp->route_prefix.prefixlen < 8) { debugf(NHRP_DEBUG_COMMON, "Shortcut to more generic than /8 dropped"); return; @@ -338,45 +344,101 @@ static void nhrp_handle_resolution_req(struct nhrp_packet_parser *p) debugf(NHRP_DEBUG_COMMON, "Parsing and replying to Resolution Req"); - if (nhrp_route_address(p->ifp, &p->src_proto, NULL, &peer) + if (nhrp_route_address(ifp, &pp->src_proto, NULL, &peer) != NHRP_ROUTE_NBMA_NEXTHOP) return; -#if 0 - /* FIXME: Update requestors binding if CIE specifies holding time */ - nhrp_cache_update_binding( - NHRP_CACHE_CACHED, &p->src_proto, - nhrp_peer_get(p->ifp, &p->src_nbma), - htons(cie->holding_time)); -#endif + /* Copy payload CIE */ + hostprefix_len = 8 * sockunion_get_addrlen(&pp->if_ad->addr); + paylen = zbuf_used(&pp->payload); + debugf(NHRP_DEBUG_COMMON, "shortcut res_rep: paylen %zu", paylen); + + while ((cie = nhrp_cie_pull(&pp->payload, pp->hdr, &cie_nbma, + &cie_proto)) + != NULL) { + prefix_len = cie->prefix_length; + debugf(NHRP_DEBUG_COMMON, + "shortcut res_rep: parsing CIE with prefixlen=%u", + prefix_len); + if (prefix_len == 0 || prefix_len >= hostprefix_len) + prefix_len = hostprefix_len; + + if (prefix_len != hostprefix_len + && !(pp->hdr->flags + & htons(NHRP_FLAG_REGISTRATION_UNIQUE))) { + cie->code = NHRP_CODE_BINDING_NON_UNIQUE; + continue; + } + + /* We currently support only unique prefix registrations */ + if (prefix_len != hostprefix_len) { + cie->code = NHRP_CODE_ADMINISTRATIVELY_PROHIBITED; + continue; + } + + proto_addr = (sockunion_family(&cie_proto) == AF_UNSPEC) + ? &pp->src_proto + : &cie_proto; + nbma_addr = (sockunion_family(&cie_nbma) == AF_UNSPEC) + ? &pp->src_nbma + : &cie_nbma; + + holdtime = htons(cie->holding_time); + debugf(NHRP_DEBUG_COMMON, + "shortcut res_rep: holdtime is %u (if 0, using %u)", + holdtime, pp->if_ad->holdtime); + if (!holdtime) + holdtime = pp->if_ad->holdtime; + + c = nhrp_cache_get(ifp, proto_addr, 1); + if (!c) { + debugf(NHRP_DEBUG_COMMON, + "shortcut res_rep: no cache found"); + cie->code = NHRP_CODE_INSUFFICIENT_RESOURCES; + continue; + } + if (nbma_addr) + sockunion2str(nbma_addr, buf, sizeof(buf)); + + debugf(NHRP_DEBUG_COMMON, + "shortcut res_rep: updating binding for nmba addr %s", + nbma_addr ? buf : "(NULL)"); + if (!nhrp_cache_update_binding(c, NHRP_CACHE_DYNAMIC, holdtime, + nhrp_peer_ref(pp->peer), + htons(cie->mtu), nbma_addr)) { + cie->code = NHRP_CODE_ADMINISTRATIVELY_PROHIBITED; + continue; + } - nifp = peer->ifp->info; + cie->code = NHRP_CODE_SUCCESS; + } /* Create reply */ zb = zbuf_alloc(1500); - hdr = nhrp_packet_push(zb, NHRP_PACKET_RESOLUTION_REPLY, &p->src_nbma, - &p->src_proto, &p->dst_proto); + hdr = nhrp_packet_push(zb, NHRP_PACKET_RESOLUTION_REPLY, &pp->src_nbma, + &pp->src_proto, &pp->dst_proto); /* Copied information from request */ - hdr->flags = - p->hdr->flags & htons(NHRP_FLAG_RESOLUTION_SOURCE_IS_ROUTER - | NHRP_FLAG_RESOLUTION_SOURCE_STABLE); + hdr->flags = pp->hdr->flags + & htons(NHRP_FLAG_RESOLUTION_SOURCE_IS_ROUTER + | NHRP_FLAG_RESOLUTION_SOURCE_STABLE); hdr->flags |= htons(NHRP_FLAG_RESOLUTION_DESTINATION_STABLE | NHRP_FLAG_RESOLUTION_AUTHORATIVE); - hdr->u.request_id = p->hdr->u.request_id; + hdr->u.request_id = pp->hdr->u.request_id; - /* CIE payload */ + /* CIE payload for the reply packet */ cie = nhrp_cie_push(zb, NHRP_CODE_SUCCESS, &nifp->nbma, - &p->if_ad->addr); - cie->holding_time = htons(p->if_ad->holdtime); - cie->mtu = htons(p->if_ad->mtu); - if (p->if_ad->network_id && p->route_type == NHRP_ROUTE_OFF_NBMA) - cie->prefix_length = p->route_prefix.prefixlen; + &pp->if_ad->addr); + cie->holding_time = htons(pp->if_ad->holdtime); + cie->mtu = htons(pp->if_ad->mtu); + if (pp->if_ad->network_id && pp->route_type == NHRP_ROUTE_OFF_NBMA) + cie->prefix_length = pp->route_prefix.prefixlen; else - cie->prefix_length = 8 * sockunion_get_addrlen(&p->if_ad->addr); + cie->prefix_length = + 8 * sockunion_get_addrlen(&pp->if_ad->addr); /* Handle extensions */ - while ((ext = nhrp_ext_pull(&p->extensions, &payload)) != NULL) { + while ((ext = nhrp_ext_pull(&pp->extensions, &payload)) != NULL) { switch (htons(ext->type) & ~NHRP_EXTENSION_FLAG_COMPULSORY) { case NHRP_EXTENSION_NAT_ADDRESS: if (sockunion_family(&nifp->nat_nbma) == AF_UNSPEC) @@ -386,13 +448,13 @@ static void nhrp_handle_resolution_req(struct nhrp_packet_parser *p) if (!ext) goto err; cie = nhrp_cie_push(zb, NHRP_CODE_SUCCESS, - &nifp->nat_nbma, &p->if_ad->addr); + &nifp->nat_nbma, &pp->if_ad->addr); if (!cie) goto err; nhrp_ext_complete(zb, ext); break; default: - if (nhrp_ext_reply(zb, hdr, p->ifp, ext, &payload) < 0) + if (nhrp_ext_reply(zb, hdr, ifp, ext, &payload) < 0) goto err; break; } @@ -584,15 +646,15 @@ void nhrp_peer_send_indication(struct interface *ifp, uint16_t protocol_type, debugf(NHRP_DEBUG_COMMON, "Send Traffic Indication to %s about packet to %s ignored", sockunion2str(&p->vc->remote.nbma, buf[0], - sizeof buf[0]), - sockunion2str(&dst, buf[1], sizeof buf[1])); + sizeof(buf[0])), + sockunion2str(&dst, buf[1], sizeof(buf[1]))); return; } debugf(NHRP_DEBUG_COMMON, "Send Traffic Indication to %s (online=%d) about packet to %s", - sockunion2str(&p->vc->remote.nbma, buf[0], sizeof buf[0]), - p->online, sockunion2str(&dst, buf[1], sizeof buf[1])); + sockunion2str(&p->vc->remote.nbma, buf[0], sizeof(buf[0])), + p->online, sockunion2str(&dst, buf[1], sizeof(buf[1]))); /* Create reply */ zb = zbuf_alloc(1500); @@ -622,8 +684,8 @@ static void nhrp_handle_error_ind(struct nhrp_packet_parser *pp) debugf(NHRP_DEBUG_COMMON, "Error Indication from %s about packet to %s ignored", - sockunion2str(&pp->src_proto, buf[0], sizeof buf[0]), - sockunion2str(&dst_proto, buf[1], sizeof buf[1])); + sockunion2str(&pp->src_proto, buf[0], sizeof(buf[0])), + sockunion2str(&dst_proto, buf[1], sizeof(buf[1]))); reqid = nhrp_reqid_lookup(&nhrp_packet_reqid, htonl(hdr->u.request_id)); if (reqid) @@ -641,8 +703,8 @@ static void nhrp_handle_traffic_ind(struct nhrp_packet_parser *p) debugf(NHRP_DEBUG_COMMON, "Traffic Indication from %s about packet to %s: %s", - sockunion2str(&p->src_proto, buf[0], sizeof buf[0]), - sockunion2str(&dst, buf[1], sizeof buf[1]), + sockunion2str(&p->src_proto, buf[0], sizeof(buf[0])), + sockunion2str(&dst, buf[1], sizeof(buf[1])), (p->if_ad->flags & NHRP_IFF_SHORTCUT) ? "trying shortcut" : "ignored"); @@ -657,7 +719,7 @@ enum packet_type_t { PACKET_INDICATION, }; -static const struct { +static struct { enum packet_type_t type; const char *name; void (*handler)(struct nhrp_packet_parser *); @@ -755,10 +817,9 @@ static void nhrp_peer_forward(struct nhrp_peer *p, if ((type == NHRP_EXTENSION_REVERSE_TRANSIT_NHS) == (packet_types[hdr->type].type == PACKET_REPLY)) { /* Check NHS list for forwarding loop */ - while ((cie = nhrp_cie_pull(&extpl, pp->hdr, - &cie_nbma, - &cie_protocol)) - != NULL) { + while (nhrp_cie_pull(&extpl, pp->hdr, + &cie_nbma, + &cie_protocol) != NULL) { if (sockunion_same(&p->vc->remote.nbma, &cie_nbma)) goto err; @@ -810,8 +871,8 @@ static void nhrp_packet_debug(struct zbuf *zb, const char *dir) zbuf_init(&zhdr, zb->buf, zb->tail - zb->buf, zb->tail - zb->buf); hdr = nhrp_packet_pull(&zhdr, &src_nbma, &src_proto, &dst_proto); - sockunion2str(&src_proto, buf[0], sizeof buf[0]); - sockunion2str(&dst_proto, buf[1], sizeof buf[1]); + sockunion2str(&src_proto, buf[0], sizeof(buf[0])); + sockunion2str(&dst_proto, buf[1], sizeof(buf[1])); reply = packet_types[hdr->type].type == PACKET_REPLY; debugf(NHRP_DEBUG_COMMON, "%s %s(%d) %s -> %s", dir, @@ -853,8 +914,8 @@ void nhrp_peer_recv(struct nhrp_peer *p, struct zbuf *zb) afi_t nbma_afi, proto_afi; debugf(NHRP_DEBUG_KERNEL, "PACKET: Recv %s -> %s", - sockunion2str(&vc->remote.nbma, buf[0], sizeof buf[0]), - sockunion2str(&vc->local.nbma, buf[1], sizeof buf[1])); + sockunion2str(&vc->remote.nbma, buf[0], sizeof(buf[0])), + sockunion2str(&vc->local.nbma, buf[1], sizeof(buf[1]))); if (!p->online) { info = "peer not online"; @@ -886,7 +947,7 @@ void nhrp_peer_recv(struct nhrp_peer *p, struct zbuf *zb) || htons(hdr->packet_size) > realsize) { zlog_info( "From %s: error: packet type %d, version %d, AFI %d, proto %x, size %d (real size %d)", - sockunion2str(&vc->remote.nbma, buf[0], sizeof buf[0]), + sockunion2str(&vc->remote.nbma, buf[0], sizeof(buf[0])), (int)hdr->type, (int)hdr->version, (int)nbma_afi, (int)htons(hdr->protocol_type), (int)htons(hdr->packet_size), (int)realsize); @@ -898,11 +959,15 @@ void nhrp_peer_recv(struct nhrp_peer *p, struct zbuf *zb) if (extoff) { assert(zb->head > zb->buf); uint32_t header_offset = zb->head - zb->buf; - if ((extoff >= realsize) || (extoff < (header_offset))) { - info = "extoff larger than packet, or smaller than header"; + if (extoff >= realsize) { + info = "extoff larger than packet"; + goto drop; + } + if (extoff < header_offset) { + info = "extoff smaller than header offset"; goto drop; } - paylen = extoff - (zb->head - zb->buf); + paylen = extoff - header_offset; } else { paylen = zbuf_used(zb); } @@ -963,7 +1028,7 @@ drop: if (info) { zlog_info( "From %s: error: %s", - sockunion2str(&vc->remote.nbma, buf[0], sizeof buf[0]), + sockunion2str(&vc->remote.nbma, buf[0], sizeof(buf[0])), info); } if (peer) diff --git a/nhrpd/nhrp_route.c b/nhrpd/nhrp_route.c index a23ac34745..f242c2e367 100644 --- a/nhrpd/nhrp_route.c +++ b/nhrpd/nhrp_route.c @@ -220,8 +220,8 @@ int nhrp_route_read(ZAPI_CALLBACK_ARGS) added = (cmd == ZEBRA_REDISTRIBUTE_ROUTE_ADD); debugf(NHRP_DEBUG_ROUTE, "if-route-%s: %s via %s dev %s", added ? "add" : "del", - prefix2str(&api.prefix, buf[0], sizeof buf[0]), - sockunion2str(&nexthop_addr, buf[1], sizeof buf[1]), + prefix2str(&api.prefix, buf[0], sizeof(buf[0])), + sockunion2str(&nexthop_addr, buf[1], sizeof(buf[1])), ifp ? ifp->name : "(none)"); nhrp_route_update_zebra(&api.prefix, &nexthop_addr, ifp); @@ -248,7 +248,7 @@ int nhrp_route_get_nexthop(const union sockunion *addr, struct prefix *p, ri = rn->info; if (ri->nhrp_ifp) { debugf(NHRP_DEBUG_ROUTE, "lookup %s: nhrp_if=%s", - prefix2str(&lookup, buf, sizeof buf), + prefix2str(&lookup, buf, sizeof(buf)), ri->nhrp_ifp->name); if (via) @@ -257,7 +257,7 @@ int nhrp_route_get_nexthop(const union sockunion *addr, struct prefix *p, *ifp = ri->nhrp_ifp; } else { debugf(NHRP_DEBUG_ROUTE, "lookup %s: zebra route dev %s", - prefix2str(&lookup, buf, sizeof buf), + prefix2str(&lookup, buf, sizeof(buf)), ri->ifp ? ri->ifp->name : "(none)"); if (via) diff --git a/nhrpd/nhrp_shortcut.c b/nhrpd/nhrp_shortcut.c index b3fdecf0ec..1c2b2b28f2 100644 --- a/nhrpd/nhrp_shortcut.c +++ b/nhrpd/nhrp_shortcut.c @@ -32,7 +32,7 @@ static void nhrp_shortcut_check_use(struct nhrp_shortcut *s) if (s->expiring && s->cache && s->cache->used) { debugf(NHRP_DEBUG_ROUTE, "Shortcut %s used and expiring", - prefix2str(s->p, buf, sizeof buf)); + prefix2str(s->p, buf, sizeof(buf))); nhrp_shortcut_send_resolution_req(s); } } @@ -53,14 +53,21 @@ static int nhrp_shortcut_do_expire(struct thread *t) static void nhrp_shortcut_cache_notify(struct notifier_block *n, unsigned long cmd) { + char buf[PREFIX_STRLEN]; + struct nhrp_shortcut *s = container_of(n, struct nhrp_shortcut, cache_notifier); switch (cmd) { case NOTIFY_CACHE_UP: if (!s->route_installed) { - nhrp_route_announce(1, s->type, s->p, NULL, - &s->cache->remote_addr, 0); + debugf(NHRP_DEBUG_ROUTE, + "Shortcut: route install %s nh (unspec) dev %s", + prefix2str(s->p, buf, sizeof(buf)), + s->cache->ifp->name); + + nhrp_route_announce(1, s->type, s->p, s->cache->ifp, + NULL, 0); s->route_installed = 1; } break; @@ -84,6 +91,8 @@ static void nhrp_shortcut_update_binding(struct nhrp_shortcut *s, enum nhrp_cache_type type, struct nhrp_cache *c, int holding_time) { + char buf[2][PREFIX_STRLEN]; + s->type = type; if (c != s->cache) { if (s->cache) { @@ -98,13 +107,29 @@ static void nhrp_shortcut_update_binding(struct nhrp_shortcut *s, /* Force renewal of Zebra announce on prefix * change */ s->route_installed = 0; + debugf(NHRP_DEBUG_ROUTE, + "Shortcut: forcing renewal of zebra announce on prefix change peer %s ht %u cur nbma %s dev %s", + sockunion2str(&s->cache->remote_addr, + buf[0], sizeof(buf[0])), + holding_time, + sockunion2str( + &s->cache->cur.remote_nbma_natoa, + buf[1], sizeof(buf[1])), + s->cache->ifp->name); nhrp_shortcut_cache_notify(&s->cache_notifier, NOTIFY_CACHE_UP); } } - if (!s->cache || !s->cache->route_installed) + if (!s->cache || !s->cache->route_installed) { + debugf(NHRP_DEBUG_ROUTE, + "Shortcut: notify cache down because cache?%s or ri?%s", + s->cache ? "yes" : "no", + s->cache ? (s->cache->route_installed ? "yes" + : "no") + : "n/a"); nhrp_shortcut_cache_notify(&s->cache_notifier, NOTIFY_CACHE_DOWN); + } } if (s->type == NHRP_CACHE_NEGATIVE && !s->route_installed) { nhrp_route_announce(1, s->type, s->p, NULL, NULL, 0); @@ -133,7 +158,7 @@ static void nhrp_shortcut_delete(struct nhrp_shortcut *s) nhrp_reqid_free(&nhrp_packet_reqid, &s->reqid); debugf(NHRP_DEBUG_ROUTE, "Shortcut %s purged", - prefix2str(s->p, buf, sizeof buf)); + prefix2str(s->p, buf, sizeof(buf))); nhrp_shortcut_update_binding(s, NHRP_CACHE_INVALID, NULL, 0); @@ -141,6 +166,7 @@ static void nhrp_shortcut_delete(struct nhrp_shortcut *s) rn = route_node_lookup(shortcut_rib[afi], s->p); if (rn) { XFREE(MTYPE_NHRP_SHORTCUT, rn->info); + rn->info = NULL; route_unlock_node(rn); route_unlock_node(rn); } @@ -172,7 +198,7 @@ static struct nhrp_shortcut *nhrp_shortcut_get(struct prefix *p) s->p = &rn->p; debugf(NHRP_DEBUG_ROUTE, "Shortcut %s created", - prefix2str(s->p, buf, sizeof buf)); + prefix2str(s->p, buf, sizeof(buf))); } else { s = rn->info; route_unlock_node(rn); @@ -190,11 +216,10 @@ static void nhrp_shortcut_recv_resolution_rep(struct nhrp_reqid *reqid, struct nhrp_extension_header *ext; struct nhrp_cie_header *cie; struct nhrp_cache *c = NULL; - union sockunion *proto, cie_proto, *nbma, *nbma_natoa, cie_nbma, - nat_nbma; + union sockunion *proto, cie_proto, *nbma, cie_nbma, nat_nbma; struct prefix prefix, route_prefix; struct zbuf extpl; - char bufp[PREFIX_STRLEN], buf[3][SU_ADDRSTRLEN]; + char bufp[PREFIX_STRLEN], buf[4][SU_ADDRSTRLEN]; int holding_time = pp->if_ad->holdtime; nhrp_reqid_free(&nhrp_packet_reqid, &s->reqid); @@ -217,7 +242,7 @@ static void nhrp_shortcut_recv_resolution_rep(struct nhrp_reqid *reqid, } /* Parse extensions */ - memset(&nat_nbma, 0, sizeof nat_nbma); + memset(&nat_nbma, 0, sizeof(nat_nbma)); while ((ext = nhrp_ext_pull(&pp->extensions, &extpl)) != NULL) { switch (htons(ext->type) & ~NHRP_EXTENSION_FLAG_COMPULSORY) { case NHRP_EXTENSION_NAT_ADDRESS: @@ -231,8 +256,8 @@ static void nhrp_shortcut_recv_resolution_rep(struct nhrp_reqid *reqid, if (!sockunion_same(&cie_proto, &pp->dst_proto)) { debugf(NHRP_DEBUG_COMMON, "Shortcut: Warning dst_proto altered from %s to %s", - sockunion2str(&cie_proto, buf[0], sizeof buf[0]), - sockunion2str(&pp->dst_proto, buf[1], sizeof buf[1])); + sockunion2str(&cie_proto, buf[0], sizeof(buf[0])), + sockunion2str(&pp->dst_proto, buf[1], sizeof(buf[1]))); } /* One or more CIEs should be given as reply, we support only one */ @@ -262,39 +287,55 @@ static void nhrp_shortcut_recv_resolution_rep(struct nhrp_reqid *reqid, } debugf(NHRP_DEBUG_COMMON, - "Shortcut: %s is at proto %s cie-nbma %s nat-nbma %s cie-holdtime %d", - prefix2str(&prefix, bufp, sizeof bufp), - sockunion2str(proto, buf[0], sizeof buf[0]), - sockunion2str(&cie_nbma, buf[1], sizeof buf[1]), - sockunion2str(&nat_nbma, buf[2], sizeof buf[2]), + "Shortcut: %s is at proto %s dst_proto %s cie-nbma %s nat-nbma %s cie-holdtime %d", + prefix2str(&prefix, bufp, sizeof(bufp)), + sockunion2str(proto, buf[0], sizeof(buf[0])), + sockunion2str(&pp->dst_proto, buf[1], sizeof(buf[1])), + sockunion2str(&cie_nbma, buf[2], sizeof(buf[2])), + sockunion2str(&nat_nbma, buf[3], sizeof(buf[3])), htons(cie->holding_time)); /* Update cache entry for the protocol to nbma binding */ - if (sockunion_family(&nat_nbma) != AF_UNSPEC) { + if (sockunion_family(&nat_nbma) != AF_UNSPEC) nbma = &nat_nbma; - nbma_natoa = &cie_nbma; - } else { + else nbma = &cie_nbma; - nbma_natoa = NULL; - } + if (sockunion_family(nbma)) { c = nhrp_cache_get(pp->ifp, proto, 1); if (c) { - nhrp_cache_update_binding(c, NHRP_CACHE_CACHED, + debugf(NHRP_DEBUG_COMMON, + "Shortcut: cache found, update binding"); + nhrp_cache_update_binding(c, NHRP_CACHE_DYNAMIC, holding_time, nhrp_peer_get(pp->ifp, nbma), - htons(cie->mtu), nbma_natoa); + htons(cie->mtu), nbma); + } else { + debugf(NHRP_DEBUG_COMMON, + "Shortcut: no cache for nbma %s", buf[2]); } } /* Update shortcut entry for subnet to protocol gw binding */ - if (c && !sockunion_same(proto, &pp->dst_proto)) { + if (c) { ps = nhrp_shortcut_get(&prefix); if (ps) { ps->addr = s->addr; - nhrp_shortcut_update_binding(ps, NHRP_CACHE_CACHED, c, + debugf(NHRP_DEBUG_COMMON, + "Shortcut: calling update_binding"); + nhrp_shortcut_update_binding(ps, NHRP_CACHE_DYNAMIC, c, holding_time); + } else { + debugf(NHRP_DEBUG_COMMON, + "Shortcut: proto diff but no ps"); } + } else { + debugf(NHRP_DEBUG_COMMON, + "NO Shortcut because c NULL?%s or same proto?%s", + c ? "no" : "yes", + proto && pp && sockunion_same(proto, &pp->dst_proto) + ? "yes" + : "no"); } debugf(NHRP_DEBUG_COMMON, "Shortcut: Resolution reply handled"); @@ -306,7 +347,9 @@ static void nhrp_shortcut_send_resolution_req(struct nhrp_shortcut *s) struct nhrp_packet_header *hdr; struct interface *ifp; struct nhrp_interface *nifp; + struct nhrp_afi_data *if_ad; struct nhrp_peer *peer; + struct nhrp_cie_header *cie; if (nhrp_route_address(NULL, &s->addr, NULL, &peer) != NHRP_ROUTE_NBMA_NEXTHOP) @@ -336,7 +379,15 @@ static void nhrp_shortcut_send_resolution_req(struct nhrp_shortcut *s) * - MTU: MTU of the source station * - Holding Time: Max time to cache the source information * */ - /* FIXME: Send holding time, and MTU */ + /* FIXME: push CIE for each local protocol address */ + cie = nhrp_cie_push(zb, NHRP_CODE_SUCCESS, NULL, NULL); + cie->prefix_length = 0xff; + if_ad = &nifp->afi[family2afi(sockunion_family(&s->addr))]; + cie->holding_time = htons(if_ad->holdtime); + cie->mtu = htons(if_ad->mtu); + debugf(NHRP_DEBUG_COMMON, + "Shortcut res_req: set cie ht to %u and mtu to %u. shortcut ht is %u", + ntohs(cie->holding_time), ntohs(cie->mtu), s->holding_time); nhrp_ext_request(zb, hdr, ifp); diff --git a/nhrpd/nhrp_vc.c b/nhrpd/nhrp_vc.c index 605aa34ff9..6567b231a9 100644 --- a/nhrpd/nhrp_vc.c +++ b/nhrpd/nhrp_vc.c @@ -142,8 +142,8 @@ int nhrp_vc_ipsec_updown(uint32_t child_id, struct nhrp_vc *vc) sa->vc->abort_migration = 0; debugf(NHRP_DEBUG_COMMON, "IPsec NBMA change of %s to %s", sockunion2str(&sa->vc->remote.nbma, buf[0], - sizeof buf[0]), - sockunion2str(&vc->remote.nbma, buf[1], sizeof buf[1])); + sizeof(buf[0])), + sockunion2str(&vc->remote.nbma, buf[1], sizeof(buf[1]))); nhrp_vc_update(sa->vc, NOTIFY_VC_IPSEC_UPDATE_NBMA); abort_migration = sa->vc->abort_migration; } diff --git a/nhrpd/nhrp_vty.c b/nhrpd/nhrp_vty.c index 8438f3cb4a..f6d18fb77f 100644 --- a/nhrpd/nhrp_vty.c +++ b/nhrpd/nhrp_vty.c @@ -613,9 +613,9 @@ static void show_ip_nhrp_cache(struct nhrp_cache *c, void *pctx) vty_out(ctx->vty, "%-8s %-8s %-24s %-24s %c%c%c %s\n", c->ifp->name, nhrp_cache_type_str[c->cur.type], - sockunion2str(&c->remote_addr, buf[0], sizeof buf[0]), + sockunion2str(&c->remote_addr, buf[0], sizeof(buf[0])), c->cur.peer ? sockunion2str(&c->cur.peer->vc->remote.nbma, - buf[1], sizeof buf[1]) + buf[1], sizeof(buf[1])) : "-", c->used ? 'U' : ' ', c->t_timeout ? 'T' : ' ', c->t_auth ? 'A' : ' ', @@ -637,10 +637,10 @@ static void show_ip_nhrp_nhs(struct nhrp_nhs *n, struct nhrp_registration *reg, vty_out(vty, "%-8s %-24s %-16s %-16s\n", n->ifp->name, n->nbma_fqdn, (reg && reg->peer) ? sockunion2str(®->peer->vc->remote.nbma, - buf[0], sizeof buf[0]) + buf[0], sizeof(buf[0])) : "-", sockunion2str(reg ? ®->proto_addr : &n->proto_addr, buf[1], - sizeof buf[1])); + sizeof(buf[1]))); } static void show_ip_nhrp_shortcut(struct nhrp_shortcut *s, void *pctx) @@ -658,8 +658,8 @@ static void show_ip_nhrp_shortcut(struct nhrp_shortcut *s, void *pctx) c = s->cache; vty_out(ctx->vty, "%-8s %-24s %-24s %s\n", nhrp_cache_type_str[s->type], - prefix2str(s->p, buf1, sizeof buf1), - c ? sockunion2str(&c->remote_addr, buf2, sizeof buf2) : "", + prefix2str(s->p, buf1, sizeof(buf1)), + c ? sockunion2str(&c->remote_addr, buf2, sizeof(buf2)) : "", (c && c->cur.peer) ? c->cur.peer->vc->remote.id : ""); } @@ -678,19 +678,19 @@ static void show_ip_opennhrp_cache(struct nhrp_cache *c, void *pctx) nhrp_cache_type_str[c->cur.type], (c->cur.peer && c->cur.peer->online) ? " up" : "", c->used ? " used" : "", - sockunion2str(&c->remote_addr, buf, sizeof buf), + sockunion2str(&c->remote_addr, buf, sizeof(buf)), 8 * family2addrsize(sockunion_family(&c->remote_addr))); if (c->cur.peer) { vty_out(ctx->vty, "NBMA-Address: %s\n", sockunion2str(&c->cur.peer->vc->remote.nbma, buf, - sizeof buf)); + sizeof(buf))); } if (sockunion_family(&c->cur.remote_nbma_natoa) != AF_UNSPEC) { vty_out(ctx->vty, "NBMA-NAT-OA-Address: %s\n", sockunion2str(&c->cur.remote_nbma_natoa, buf, - sizeof buf)); + sizeof(buf))); } vty_out(ctx->vty, "\n\n"); @@ -741,8 +741,8 @@ static void show_dmvpn_entry(struct nhrp_vc *vc, void *ctx) char buf[2][SU_ADDRSTRLEN]; vty_out(vty, "%-24s %-24s %c %-4d %-24s\n", - sockunion2str(&vc->local.nbma, buf[0], sizeof buf[0]), - sockunion2str(&vc->remote.nbma, buf[1], sizeof buf[1]), + sockunion2str(&vc->local.nbma, buf[0], sizeof(buf[0])), + sockunion2str(&vc->remote.nbma, buf[1], sizeof(buf[1])), notifier_active(&vc->notifier_list) ? 'n' : ' ', vc->ipsec, vc->remote.id); } @@ -824,11 +824,11 @@ static void interface_config_write_nhrp_map(struct nhrp_cache *c, void *data) return; vty_out(vty, " %s nhrp map %s %s\n", ctx->aficmd, - sockunion2str(&c->remote_addr, buf[0], sizeof buf[0]), + sockunion2str(&c->remote_addr, buf[0], sizeof(buf[0])), c->cur.type == NHRP_CACHE_LOCAL ? "local" : sockunion2str(&c->cur.peer->vc->remote.nbma, buf[1], - sizeof buf[1])); + sizeof(buf[1]))); } static int interface_config_write(struct vty *vty) @@ -904,7 +904,7 @@ static int interface_config_write(struct vty *vty) ? "dynamic" : sockunion2str( &nhs->proto_addr, buf, - sizeof buf), + sizeof(buf)), nhs->nbma_fqdn); } } diff --git a/nhrpd/vici.c b/nhrpd/vici.c index d6105b71d4..2dc05a4aa7 100644 --- a/nhrpd/vici.c +++ b/nhrpd/vici.c @@ -303,7 +303,7 @@ static void vici_recv_sa(struct vici_conn *vici, struct zbuf *msg, int event) if (ctx.kill_ikesa && ctx.ike_uniqueid) { debugf(NHRP_DEBUG_COMMON, "VICI: Deleting IKE_SA %u", ctx.ike_uniqueid); - snprintf(buf, sizeof buf, "%u", ctx.ike_uniqueid); + snprintf(buf, sizeof(buf), "%u", ctx.ike_uniqueid); vici_submit_request(vici, "terminate", VICI_KEY_VALUE, "ike-id", strlen(buf), buf, VICI_END); } @@ -481,8 +481,8 @@ static int vici_reconnect(struct thread *t) fd = sock_open_unix("/var/run/charon.vici"); if (fd < 0) { debugf(NHRP_DEBUG_VICI, - "%s: failure connecting VICI socket: %s", - __PRETTY_FUNCTION__, strerror(errno)); + "%s: failure connecting VICI socket: %s", __func__, + strerror(errno)); thread_add_timer(master, vici_reconnect, vici, 2, &vici->t_reconnect); return 0; @@ -527,8 +527,8 @@ void vici_request_vc(const char *profile, union sockunion *src, struct vici_conn *vici = &vici_connection; char buf[2][SU_ADDRSTRLEN]; - sockunion2str(src, buf[0], sizeof buf[0]); - sockunion2str(dst, buf[1], sizeof buf[1]); + sockunion2str(src, buf[0], sizeof(buf[0])); + sockunion2str(dst, buf[1], sizeof(buf[1])); vici_submit_request(vici, "initiate", VICI_KEY_VALUE, "child", strlen(profile), profile, VICI_KEY_VALUE, "timeout", diff --git a/ospf6d/ospf6_abr.c b/ospf6d/ospf6_abr.c index ff82bb1798..ead186b6fc 100644 --- a/ospf6d/ospf6_abr.c +++ b/ospf6d/ospf6_abr.c @@ -232,8 +232,8 @@ int ospf6_abr_originate_summary_to_area(struct ospf6_route *route, &route->prefix)), buf, sizeof(buf)); zlog_debug( - "%s: route %s with cost %u is not best, ignore." - , __PRETTY_FUNCTION__, buf, + "%s: route %s with cost %u is not best, ignore.", + __func__, buf, route->path.cost); } return 0; @@ -246,9 +246,10 @@ int ospf6_abr_originate_summary_to_area(struct ospf6_route *route, if (is_debug) { prefix2str(&route->prefix, buf, sizeof(buf)); - zlog_debug("%s: intra-prefix route %s with cost %u is not best, ignore." - , __PRETTY_FUNCTION__, buf, - route->path.cost); + zlog_debug( + "%s: intra-prefix route %s with cost %u is not best, ignore.", + __func__, buf, + route->path.cost); } return 0; } @@ -762,11 +763,13 @@ void ospf6_abr_old_path_update(struct ospf6_route *old_route, } if (IS_OSPF6_DEBUG_ABR || IS_OSPF6_DEBUG_EXAMIN(INTER_PREFIX)) - zlog_debug("%s: paths %u nh %u", __PRETTY_FUNCTION__, - old_route->paths ? - listcount(old_route->paths) : 0, - old_route->nh_list ? - listcount(old_route->nh_list) : 0); + zlog_debug("%s: paths %u nh %u", __func__, + old_route->paths + ? listcount(old_route->paths) + : 0, + old_route->nh_list + ? listcount(old_route->nh_list) + : 0); if (table->hook_add) (*table->hook_add)(old_route); @@ -822,9 +825,10 @@ void ospf6_abr_old_route_remove(struct ospf6_lsa *lsa, prefix2str(&old->prefix, buf, sizeof(buf)); zlog_debug("%s: old %s updated nh %u", - __PRETTY_FUNCTION__, buf, - old->nh_list ? - listcount(old->nh_list) : 0); + __func__, buf, + old->nh_list ? listcount( + old->nh_list) + : 0); } if (table->hook_add) @@ -878,8 +882,8 @@ void ospf6_abr_examin_summary(struct ospf6_lsa *lsa, struct ospf6_area *oa) if (lsa->header->type == htons(OSPF6_LSTYPE_INTER_PREFIX)) { if (IS_OSPF6_DEBUG_EXAMIN(INTER_PREFIX)) { is_debug++; - zlog_debug("%s: Examin %s in area %s", - __PRETTY_FUNCTION__, lsa->name, oa->name); + zlog_debug("%s: Examin %s in area %s", __func__, + lsa->name, oa->name); } prefix_lsa = @@ -898,8 +902,8 @@ void ospf6_abr_examin_summary(struct ospf6_lsa *lsa, struct ospf6_area *oa) } else if (lsa->header->type == htons(OSPF6_LSTYPE_INTER_ROUTER)) { if (IS_OSPF6_DEBUG_EXAMIN(INTER_ROUTER)) { is_debug++; - zlog_debug("%s: Examin %s in area %s", - __PRETTY_FUNCTION__, lsa->name, oa->name); + zlog_debug("%s: Examin %s in area %s", __func__, + lsa->name, oa->name); } router_lsa = @@ -946,9 +950,10 @@ void ospf6_abr_examin_summary(struct ospf6_lsa *lsa, struct ospf6_area *oa) old = route; if (is_debug) - zlog_debug("%s: old entry found in paths, adv_router %s", - __PRETTY_FUNCTION__, - adv_router); + zlog_debug( + "%s: old entry found in paths, adv_router %s", + __func__, + adv_router); break; } @@ -973,8 +978,8 @@ void ospf6_abr_examin_summary(struct ospf6_lsa *lsa, struct ospf6_area *oa) } if (OSPF6_LSA_IS_MAXAGE(lsa)) { if (is_debug) - zlog_debug("%s: LSA %s is MaxAge, ignore", - __PRETTY_FUNCTION__, lsa->name); + zlog_debug("%s: LSA %s is MaxAge, ignore", __func__, + lsa->name); if (old) ospf6_abr_old_route_remove(lsa, old, table); return; @@ -1053,21 +1058,21 @@ void ospf6_abr_examin_summary(struct ospf6_lsa *lsa, struct ospf6_area *oa) || CHECK_FLAG(abr_entry->flag, OSPF6_ROUTE_REMOVE) || !CHECK_FLAG(abr_entry->path.router_bits, OSPF6_ROUTER_BIT_B)) { if (is_debug) - zlog_debug("%s: ABR router entry does not exist, ignore", - __PRETTY_FUNCTION__); + zlog_debug( + "%s: ABR router entry does not exist, ignore", + __func__); if (old) { if (old->type == OSPF6_DEST_TYPE_ROUTER && oa->intra_brouter_calc) { if (is_debug) zlog_debug( - "%s: intra_brouter_calc is on, skip brouter remove: %s (%p)", - __PRETTY_FUNCTION__, buf, - (void *)old); + "%s: intra_brouter_calc is on, skip brouter remove: %s (%p)", + __func__, buf, (void *)old); } else { if (is_debug) - zlog_debug("%s: remove old entry: %s %p ", - __PRETTY_FUNCTION__, buf, - (void *)old); + zlog_debug( + "%s: remove old entry: %s %p ", + __func__, buf, (void *)old); ospf6_route_remove(old, table); } } @@ -1142,11 +1147,10 @@ void ospf6_abr_examin_summary(struct ospf6_lsa *lsa, struct ospf6_area *oa) if ((ospf6_route_cmp(route, old_route) != 0)) { if (is_debug) { prefix2str(&prefix, buf, sizeof(buf)); - zlog_debug("%s: old %p %s cost %u new route cost %u are not same", - __PRETTY_FUNCTION__, - (void *)old_route, buf, - old_route->path.cost, - route->path.cost); + zlog_debug( + "%s: old %p %s cost %u new route cost %u are not same", + __func__, (void *)old_route, buf, + old_route->path.cost, route->path.cost); } /* Check new route's adv. router is same in one of @@ -1185,14 +1189,15 @@ void ospf6_abr_examin_summary(struct ospf6_lsa *lsa, struct ospf6_area *oa) inet_ntop(AF_INET, &ecmp_path->origin.adv_router, adv_router, sizeof(adv_router)); - zlog_debug("%s: route %s cost %u another path %s added with nh %u, effective paths %u nh %u", - __PRETTY_FUNCTION__, buf, - old_route->path.cost, - adv_router, - listcount(ecmp_path->nh_list), - old_route->paths ? - listcount(old_route->paths) : 0, - listcount(old_route->nh_list)); + zlog_debug( + "%s: route %s cost %u another path %s added with nh %u, effective paths %u nh %u", + __func__, buf, old_route->path.cost, + adv_router, + listcount(ecmp_path->nh_list), + old_route->paths + ? listcount(old_route->paths) + : 0, + listcount(old_route->nh_list)); } } else { /* adv. router exists in the list, update the nhs */ @@ -1201,10 +1206,11 @@ void ospf6_abr_examin_summary(struct ospf6_lsa *lsa, struct ospf6_area *oa) } if (is_debug) - zlog_debug("%s: Update route: %s %p old cost %u new cost %u nh %u", - __PRETTY_FUNCTION__, buf, (void *)old_route, - old_route->path.cost, route->path.cost, - listcount(route->nh_list)); + zlog_debug( + "%s: Update route: %s %p old cost %u new cost %u nh %u", + __func__, buf, (void *)old_route, + old_route->path.cost, route->path.cost, + listcount(route->nh_list)); /* For Inter-Prefix route: Update RIB/FIB, * For Inter-Router trigger summary update @@ -1221,9 +1227,10 @@ void ospf6_abr_examin_summary(struct ospf6_lsa *lsa, struct ospf6_area *oa) if (is_debug) { inet_ntop(AF_INET, &route->path.origin.adv_router, adv_router, sizeof(adv_router)); - zlog_debug("%s: Install route: %s cost %u nh %u adv_router %s ", - __PRETTY_FUNCTION__, buf, route->path.cost, - listcount(route->nh_list), adv_router); + zlog_debug( + "%s: Install route: %s cost %u nh %u adv_router %s ", + __func__, buf, route->path.cost, + listcount(route->nh_list), adv_router); } path = ospf6_path_dup(&route->path); diff --git a/ospf6d/ospf6_area.c b/ospf6d/ospf6_area.c index e4c4d4ad9c..9fe077b544 100644 --- a/ospf6d/ospf6_area.c +++ b/ospf6d/ospf6_area.c @@ -61,8 +61,7 @@ static void ospf6_area_lsdb_hook_add(struct ospf6_lsa *lsa) case OSPF6_LSTYPE_ROUTER: case OSPF6_LSTYPE_NETWORK: if (IS_OSPF6_DEBUG_EXAMIN_TYPE(lsa->header->type)) { - zlog_debug("%s Examin LSA %s", __PRETTY_FUNCTION__, - lsa->name); + zlog_debug("%s Examin LSA %s", __func__, lsa->name); zlog_debug(" Schedule SPF Calculation for %s", OSPF6_AREA(lsa->lsdb->data)->name); } diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c index 0f9a20df87..805e411c7b 100644 --- a/ospf6d/ospf6_asbr.c +++ b/ospf6d/ospf6_asbr.c @@ -166,7 +166,7 @@ int ospf6_orig_as_external_lsa(struct thread *thread) if (IS_OSPF6_DEBUG_ASBR) zlog_debug( "%s: Send update of AS-External LSA %s seq 0x%x", - __PRETTY_FUNCTION__, lsa->name, + __func__, lsa->name, ntohl(lsa->header->seqnum)); ospf6_flood_interface(NULL, lsa, oi); @@ -245,7 +245,7 @@ void ospf6_asbr_update_route_ecmp_path(struct ospf6_route *old, sizeof(buf)); zlog_debug( "%s: route %s cost old %u new %u is not same, replace route", - __PRETTY_FUNCTION__, buf, o_path->cost, + __func__, buf, o_path->cost, route->path.cost); } @@ -309,7 +309,7 @@ void ospf6_asbr_update_route_ecmp_path(struct ospf6_route *old, sizeof(buf)); zlog_debug( "%s: route %s old cost %u new cost %u, delete old entry.", - __PRETTY_FUNCTION__, buf, + __func__, buf, old_route->path.cost, route->path.cost); } @@ -340,8 +340,7 @@ void ospf6_asbr_update_route_ecmp_path(struct ospf6_route *old, sizeof(buf)); zlog_debug( "%s: old route %s path cost %u e2 %u", - __PRETTY_FUNCTION__, buf, - old_route->path.cost, + __func__, buf, old_route->path.cost, old_route->path.u.cost_e2); } route_found = true; @@ -378,13 +377,11 @@ void ospf6_asbr_update_route_ecmp_path(struct ospf6_route *old, sizeof(buf)); zlog_debug( "%s: route %s another path added with nh %u, effective paths %u nh %u", - __PRETTY_FUNCTION__, buf, + __func__, buf, listcount(ecmp_path->nh_list), - old_route->paths - ? listcount( - old_route - ->paths) - : 0, + old_route->paths ? listcount( + old_route->paths) + : 0, listcount(old_route->nh_list)); } } else { @@ -410,9 +407,9 @@ void ospf6_asbr_update_route_ecmp_path(struct ospf6_route *old, AS_EXTERNAL)) { prefix2str(&old_route->prefix, buf, sizeof(buf)); - zlog_debug("%s: ls_prfix %s asbr_entry not found.", - __PRETTY_FUNCTION__, - buf); + zlog_debug( + "%s: ls_prfix %s asbr_entry not found.", + __func__, buf); } continue; } @@ -422,12 +419,15 @@ void ospf6_asbr_update_route_ecmp_path(struct ospf6_route *old, if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) { prefix2str(&route->prefix, buf, sizeof(buf)); - zlog_debug("%s: route %s with effective paths %u nh %u", - __PRETTY_FUNCTION__, buf, - old_route->paths ? - listcount(old_route->paths) : 0, - old_route->nh_list ? - listcount(old_route->nh_list) : 0); + zlog_debug( + "%s: route %s with effective paths %u nh %u", + __func__, buf, + old_route->paths + ? listcount(old_route->paths) + : 0, + old_route->nh_list + ? listcount(old_route->nh_list) + : 0); } /* Update RIB/FIB */ @@ -532,7 +532,7 @@ void ospf6_asbr_lsa_add(struct ospf6_lsa *lsa) if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) { prefix2str(&route->prefix, buf, sizeof(buf)); zlog_debug("%s: AS-External %u route add %s cost %u(%u) nh %u", - __PRETTY_FUNCTION__, + __func__, (route->path.type == OSPF6_PATH_TYPE_EXTERNAL1) ? 1 : 2, buf, route->path.cost, route->path.u.cost_e2, @@ -621,9 +621,8 @@ void ospf6_asbr_lsa_remove(struct ospf6_lsa *lsa, prefix2str(&prefix, buf, sizeof(buf)); zlog_debug( "%s: Current route %s cost %u e2 %u, route to del cost %u e2 %u", - __PRETTY_FUNCTION__, buf, route->path.cost, - route->path.u.cost_e2, route_to_del->path.cost, - route_to_del->path.u.cost_e2); + __func__, buf, route->path.cost, route->path.u.cost_e2, + route_to_del->path.cost, route_to_del->path.u.cost_e2); } for (ospf6_route_lock(route); @@ -670,8 +669,8 @@ void ospf6_asbr_lsa_remove(struct ospf6_lsa *lsa, sizeof(buf)); zlog_debug( "%s: route %s to delete is not same, cost %u del cost %u. skip", - __PRETTY_FUNCTION__, - buf, route->path.cost, + __func__, buf, + route->path.cost, route_to_del->path .cost); } @@ -682,8 +681,7 @@ void ospf6_asbr_lsa_remove(struct ospf6_lsa *lsa, prefix2str(&prefix, buf, sizeof(buf)); zlog_debug( "%s: route %s path found with cost %u nh %u to remove.", - __PRETTY_FUNCTION__, buf, - route->path.cost, + __func__, buf, route->path.cost, listcount(o_path->nh_list)); } @@ -726,14 +724,15 @@ void ospf6_asbr_lsa_remove(struct ospf6_lsa *lsa, sizeof(buf)); zlog_debug( "%s: AS-External %u route %s update paths %u nh %u", - __PRETTY_FUNCTION__, + __func__, (route->path.type == OSPF6_PATH_TYPE_EXTERNAL1) ? 1 : 2, buf, listcount(route->paths), - route->nh_list ? - listcount(route->nh_list) : 0); + route->nh_list ? listcount( + route->nh_list) + : 0); } if (listcount(route->paths)) { @@ -785,8 +784,7 @@ void ospf6_asbr_lsa_remove(struct ospf6_lsa *lsa, prefix2str(&prefix, buf, sizeof(buf)); zlog_debug( "%s: route %s to delete is not same, cost %u del cost %u. skip", - __PRETTY_FUNCTION__, buf, - route->path.cost, + __func__, buf, route->path.cost, route_to_del->path.cost); } continue; @@ -802,7 +800,7 @@ void ospf6_asbr_lsa_remove(struct ospf6_lsa *lsa, prefix2str(&route->prefix, buf, sizeof(buf)); zlog_debug( "%s: AS-External %u route remove %s cost %u(%u) nh %u", - __PRETTY_FUNCTION__, + __func__, route->path.type == OSPF6_PATH_TYPE_EXTERNAL1 ? 1 : 2, @@ -892,8 +890,7 @@ static int ospf6_asbr_routemap_update_timer(struct thread *thread) if (ospf6->rmap[arg_type].map) { if (IS_OSPF6_DEBUG_ASBR) zlog_debug("%s: route-map %s update, reset redist %s", - __PRETTY_FUNCTION__, - ospf6->rmap[arg_type].name, + __func__, ospf6->rmap[arg_type].name, ZROUTE_NAME(arg_type)); ospf6_zebra_no_redistribute(arg_type); @@ -917,8 +914,8 @@ void ospf6_asbr_distribute_list_update(int type) args[1] = (void *)((ptrdiff_t)type); if (IS_OSPF6_DEBUG_ASBR) - zlog_debug("%s: trigger redistribute %s reset thread", - __PRETTY_FUNCTION__, ZROUTE_NAME(type)); + zlog_debug("%s: trigger redistribute %s reset thread", __func__, + ZROUTE_NAME(type)); ospf6->t_distribute_update = NULL; thread_add_timer_msec(master, ospf6_asbr_routemap_update_timer, @@ -943,7 +940,7 @@ static void ospf6_asbr_routemap_update(const char *mapname) if (IS_OSPF6_DEBUG_ASBR) zlog_debug( "%s: route-map %s update, reset redist %s", - __PRETTY_FUNCTION__, mapname, + __func__, mapname, ZROUTE_NAME(type)); route_map_counter_increment( diff --git a/ospf6d/ospf6_flood.c b/ospf6d/ospf6_flood.c index 15dbd0716a..85d02c186b 100644 --- a/ospf6d/ospf6_flood.c +++ b/ospf6d/ospf6_flood.c @@ -258,8 +258,8 @@ void ospf6_install_lsa(struct ospf6_lsa *lsa) if (IS_OSPF6_DEBUG_LSA_TYPE(lsa->header->type) || IS_OSPF6_DEBUG_EXAMIN_TYPE(lsa->header->type)) zlog_debug("%s Install LSA: %s age %d seqnum %x in LSDB.", - __PRETTY_FUNCTION__, lsa->name, - ntohs(lsa->header->age), ntohl(lsa->header->seqnum)); + __func__, lsa->name, ntohs(lsa->header->age), + ntohl(lsa->header->seqnum)); /* actually install */ lsa->installed = now; @@ -373,7 +373,7 @@ void ospf6_flood_interface(struct ospf6_neighbor *from, struct ospf6_lsa *lsa, if (is_debug) zlog_debug( "%s: Send LSA %s (age %d) update now", - __PRETTY_FUNCTION__, lsa->name, + __func__, lsa->name, ntohs(lsa->header->age)); ospf6_lsupdate_send_neighbor_now(on, lsa); continue; @@ -1004,7 +1004,7 @@ void ospf6_receive_lsa(struct ospf6_neighbor *from, if (is_debug) zlog_debug( "%s: Current copy of LSA %s is MAXAGE, but new has recent Age.", - old->name, __PRETTY_FUNCTION__); + old->name, __func__); ospf6_lsa_purge(old); if (new->header->adv_router diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c index 61879b2cbb..9c239b75ff 100644 --- a/ospf6d/ospf6_intra.c +++ b/ospf6d/ospf6_intra.c @@ -1022,8 +1022,9 @@ int ospf6_intra_prefix_lsa_originate_stub(struct thread *thread) */ if (oa->intra_prefix_originate) { if (IS_OSPF6_DEBUG_ORIGINATE(INTRA_PREFIX)) - zlog_debug("%s: Re-originate intra prefix LSA, Current full nbrs %u", - __PRETTY_FUNCTION__, oa->full_nbrs); + zlog_debug( + "%s: Re-originate intra prefix LSA, Current full nbrs %u", + __func__, oa->full_nbrs); if (old) ospf6_lsa_purge_multi_ls_id(oa, old); oa->intra_prefix_originate = 0; @@ -1401,9 +1402,10 @@ void ospf6_intra_prefix_route_ecmp_path(struct ospf6_area *oa, if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX)) { prefix2str(&old_route->prefix, buf, sizeof(buf)); - zlog_debug("%s: route %s cost old %u new %u is not same, replace route", - __PRETTY_FUNCTION__, buf, - o_path->cost, route->path.cost); + zlog_debug( + "%s: route %s cost old %u new %u is not same, replace route", + __func__, buf, o_path->cost, + route->path.cost); } /* Remove selected current path's nh from @@ -1458,10 +1460,11 @@ void ospf6_intra_prefix_route_ecmp_path(struct ospf6_area *oa, if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX)) { prefix2str(&old_route->prefix, buf, sizeof(buf)); - zlog_debug("%s: route %s old cost %u new cost %u, delete old entry.", - __PRETTY_FUNCTION__, buf, - old_route->path.cost, - route->path.cost); + zlog_debug( + "%s: route %s old cost %u new cost %u, delete old entry.", + __func__, buf, + old_route->path.cost, + route->path.cost); } if (oa->route_table->hook_remove) ospf6_route_remove(old_route, @@ -1516,13 +1519,13 @@ void ospf6_intra_prefix_route_ecmp_path(struct ospf6_area *oa, sizeof(buf)); zlog_debug( "%s: route %s %p another path added with nh %u, effective paths %u nh %u", - __PRETTY_FUNCTION__, buf, + __func__, buf, (void *)old_route, listcount(ecmp_path->nh_list), - old_route->paths ? - listcount(old_route->paths) : 0, + old_route->paths ? listcount( + old_route->paths) + : 0, listcount(old_route->nh_list)); - } } else { list_delete_all_node(o_path->nh_list); @@ -1540,9 +1543,9 @@ void ospf6_intra_prefix_route_ecmp_path(struct ospf6_area *oa, oa->spf_table); if (ls_entry == NULL) { if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX)) - zlog_debug("%s: ls_prfix %s ls_entry not found.", - __PRETTY_FUNCTION__, - buf); + zlog_debug( + "%s: ls_prfix %s ls_entry not found.", + __func__, buf); continue; } lsa = ospf6_lsdb_lookup(o_path->origin.type, @@ -1559,9 +1562,9 @@ void ospf6_intra_prefix_route_ecmp_path(struct ospf6_area *oa, o_path->origin.id, &adv_prefix); prefix2str(&adv_prefix, buf, sizeof(buf)); - zlog_debug("%s: adv_router %s lsa not found", - __PRETTY_FUNCTION__, - buf); + zlog_debug( + "%s: adv_router %s lsa not found", + __func__, buf); } continue; } @@ -1587,12 +1590,13 @@ void ospf6_intra_prefix_route_ecmp_path(struct ospf6_area *oa, if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX)) { prefix2str(&route->prefix, buf, sizeof(buf)); - zlog_debug("%s: route %s %p with final effective paths %u nh%u", - __PRETTY_FUNCTION__, buf, - (void *)old_route, - old_route->paths ? - listcount(old_route->paths) : 0, - listcount(old_route->nh_list)); + zlog_debug( + "%s: route %s %p with final effective paths %u nh%u", + __func__, buf, (void *)old_route, + old_route->paths + ? listcount(old_route->paths) + : 0, + listcount(old_route->nh_list)); } /* used in intra_route_calculation() to add to @@ -1636,7 +1640,7 @@ void ospf6_intra_prefix_lsa_add(struct ospf6_lsa *lsa) return; if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX)) - zlog_debug("%s: LSA %s found", __PRETTY_FUNCTION__, lsa->name); + zlog_debug("%s: LSA %s found", __func__, lsa->name); oa = OSPF6_AREA(lsa->lsdb->data); @@ -1732,21 +1736,22 @@ void ospf6_intra_prefix_lsa_add(struct ospf6_lsa *lsa) if (old) { if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX)) { prefix2str(&route->prefix, buf, sizeof(buf)); - zlog_debug("%s Update route: %s old cost %u new cost %u paths %u nh %u", - __PRETTY_FUNCTION__, buf, - old->path.cost, route->path.cost, - listcount(route->paths), - listcount(route->nh_list)); + zlog_debug( + "%s Update route: %s old cost %u new cost %u paths %u nh %u", + __func__, buf, old->path.cost, + route->path.cost, + listcount(route->paths), + listcount(route->nh_list)); } ospf6_intra_prefix_route_ecmp_path(oa, old, route); } else { if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX)) { prefix2str(&route->prefix, buf, sizeof(buf)); - zlog_debug("%s route %s add with cost %u paths %u nh %u", - __PRETTY_FUNCTION__, buf, - route->path.cost, - listcount(route->paths), - listcount(route->nh_list)); + zlog_debug( + "%s route %s add with cost %u paths %u nh %u", + __func__, buf, route->path.cost, + listcount(route->paths), + listcount(route->nh_list)); } ospf6_route_add(route, oa->route_table); } @@ -1783,7 +1788,7 @@ static void ospf6_intra_prefix_lsa_remove_update_route(struct ospf6_lsa *lsa, prefix2str(&route->prefix, buf, sizeof(buf)); zlog_debug( "%s: route %s path found with cost %u nh %u to remove.", - __PRETTY_FUNCTION__, buf, o_path->cost, + __func__, buf, o_path->cost, listcount(o_path->nh_list)); } @@ -1819,11 +1824,10 @@ static void ospf6_intra_prefix_lsa_remove_update_route(struct ospf6_lsa *lsa, if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX)) { prefix2str(&route->prefix, buf, sizeof(buf)); - zlog_debug("%s: route %s update paths %u nh %u", - __PRETTY_FUNCTION__, buf, - route->paths ? listcount(route->paths) : 0, - route->nh_list ? listcount(route->nh_list) - : 0); + zlog_debug( + "%s: route %s update paths %u nh %u", __func__, + buf, route->paths ? listcount(route->paths) : 0, + route->nh_list ? listcount(route->nh_list) : 0); } /* Update Global Route table and @@ -1859,8 +1863,7 @@ void ospf6_intra_prefix_lsa_remove(struct ospf6_lsa *lsa) char buf[PREFIX2STR_BUFFER]; if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX)) - zlog_debug("%s: %s disappearing", __PRETTY_FUNCTION__, - lsa->name); + zlog_debug("%s: %s disappearing", __func__, lsa->name); oa = OSPF6_AREA(lsa->lsdb->data); @@ -1917,12 +1920,12 @@ void ospf6_intra_prefix_lsa_remove(struct ospf6_lsa *lsa) if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX)) { prefix2str(&route->prefix, buf, sizeof(buf)); - zlog_debug("%s: route remove %s with path type %u cost %u paths %u nh %u", - __PRETTY_FUNCTION__, buf, - route->path.type, - route->path.cost, - listcount(route->paths), - listcount(route->nh_list)); + zlog_debug( + "%s: route remove %s with path type %u cost %u paths %u nh %u", + __func__, buf, route->path.type, + route->path.cost, + listcount(route->paths), + listcount(route->nh_list)); } ospf6_route_remove(route, oa->route_table); } @@ -2054,8 +2057,8 @@ void ospf6_intra_brouter_calculation(struct ospf6_area *oa) if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ID(oa->area_id) || IS_OSPF6_DEBUG_ROUTE(MEMORY)) - zlog_info("%s: border-router calculation for area %s", - __PRETTY_FUNCTION__, oa->name); + zlog_info("%s: border-router calculation for area %s", __func__, + oa->name); hook_add = oa->ospf6->brouter_table->hook_add; hook_remove = oa->ospf6->brouter_table->hook_remove; @@ -2161,10 +2164,11 @@ void ospf6_intra_brouter_calculation(struct ospf6_area *oa) if (ospf6_route_lookup(&adv_prefix, oa->spf_table)) { if (IS_OSPF6_DEBUG_BROUTER) { - zlog_debug("%s: keep inter brouter %s as adv router 0x%x found in spf", - __PRETTY_FUNCTION__, - brouter_name, - brouter->path.origin.adv_router); + zlog_debug( + "%s: keep inter brouter %s as adv router 0x%x found in spf", + __func__, brouter_name, + brouter->path.origin + .adv_router); ospf6_brouter_debug_print(brouter); } UNSET_FLAG(brouter->flag, OSPF6_ROUTE_REMOVE); @@ -2183,9 +2187,9 @@ void ospf6_intra_brouter_calculation(struct ospf6_area *oa) brouter_id) || IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ID( oa->area_id)) - zlog_info("%s: brouter %s disappears via area %s", - __PRETTY_FUNCTION__, brouter_name, - oa->name); + zlog_info( + "%s: brouter %s disappears via area %s", + __func__, brouter_name, oa->name); /* This is used to protect nbrouter from removed from * the table. For an example, ospf6_abr_examin_summary, * removes brouters which are marked for remove. @@ -2201,8 +2205,7 @@ void ospf6_intra_brouter_calculation(struct ospf6_area *oa) || IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ID( oa->area_id)) zlog_info("%s: brouter %s appears via area %s", - __PRETTY_FUNCTION__, brouter_name, - oa->name); + __func__, brouter_name, oa->name); /* newly added */ if (hook_add) @@ -2229,7 +2232,7 @@ void ospf6_intra_brouter_calculation(struct ospf6_area *oa) if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ID(oa->area_id) || IS_OSPF6_DEBUG_ROUTE(MEMORY)) zlog_info("%s: border-router calculation for area %s: done", - __PRETTY_FUNCTION__, oa->name); + __func__, oa->name); } static const struct ospf6_lsa_handler router_handler = { diff --git a/ospf6d/ospf6_message.c b/ospf6d/ospf6_message.c index d75fc39bbb..21f9b0722c 100644 --- a/ospf6d/ospf6_message.c +++ b/ospf6d/ospf6_message.c @@ -2186,9 +2186,8 @@ int ospf6_lsupdate_send_neighbor_now(struct ospf6_neighbor *on, if (IS_OSPF6_DEBUG_FLOODING || IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_LSUPDATE, SEND)) - zlog_debug("%s: Send lsupdate with lsa %s (age %u)", - __PRETTY_FUNCTION__, lsa->name, - ntohs(lsa->header->age)); + zlog_debug("%s: Send lsupdate with lsa %s (age %u)", __func__, + lsa->name, ntohs(lsa->header->age)); ospf6_send_lsupdate(on, NULL, oh); @@ -2244,8 +2243,7 @@ int ospf6_lsupdate_send_interface(struct thread *thread) if (IS_OSPF6_DEBUG_MESSAGE( OSPF6_MESSAGE_TYPE_LSUPDATE, SEND)) zlog_debug("%s: LSUpdate length %d", - __PRETTY_FUNCTION__, - ntohs(oh->length)); + __func__, ntohs(oh->length)); memset(sendbuf, 0, iobuflen); oh = (struct ospf6_header *)sendbuf; diff --git a/ospf6d/ospf6_proto.h b/ospf6d/ospf6_proto.h index c9e7b549db..3876a98c50 100644 --- a/ospf6d/ospf6_proto.h +++ b/ospf6d/ospf6_proto.h @@ -71,7 +71,7 @@ struct ospf6_prefix { #define OSPF6_PREFIX_OPTION_P (1 << 3) /* Propagate (NSSA) */ /* caddr_t OSPF6_PREFIX_BODY (struct ospf6_prefix *); */ -#define OSPF6_PREFIX_BODY(x) ((caddr_t)(x) + sizeof (struct ospf6_prefix)) +#define OSPF6_PREFIX_BODY(x) ((caddr_t)(x) + sizeof(struct ospf6_prefix)) /* size_t OSPF6_PREFIX_SPACE (int prefixlength); */ #define OSPF6_PREFIX_SPACE(x) ((((x) + 31) / 32) * 4) diff --git a/ospf6d/ospf6_snmp.c b/ospf6d/ospf6_snmp.c index 27f5ef8edd..9a1141f631 100644 --- a/ospf6d/ospf6_snmp.c +++ b/ospf6d/ospf6_snmp.c @@ -1356,7 +1356,7 @@ static int ospf6TrapNbrStateChange(struct ospf6_neighbor *on, int next_state, smux_trap(ospfv3_variables, array_size(ospfv3_variables), ospfv3_trap_oid, array_size(ospfv3_trap_oid), ospfv3_oid, - sizeof ospfv3_oid / sizeof(oid), index, 3, ospf6NbrTrapList, + sizeof(ospfv3_oid) / sizeof(oid), index, 3, ospf6NbrTrapList, array_size(ospf6NbrTrapList), NBRSTATECHANGE); return 0; } @@ -1378,7 +1378,7 @@ static int ospf6TrapIfStateChange(struct ospf6_interface *oi, int next_state, smux_trap(ospfv3_variables, array_size(ospfv3_variables), ospfv3_trap_oid, array_size(ospfv3_trap_oid), ospfv3_oid, - sizeof ospfv3_oid / sizeof(oid), index, 2, ospf6IfTrapList, + sizeof(ospfv3_oid) / sizeof(oid), index, 2, ospf6IfTrapList, array_size(ospf6IfTrapList), IFSTATECHANGE); return 0; } diff --git a/ospf6d/ospf6_spf.c b/ospf6d/ospf6_spf.c index 966ef44825..b0fe890d33 100644 --- a/ospf6d/ospf6_spf.c +++ b/ospf6d/ospf6_spf.c @@ -351,7 +351,7 @@ static int ospf6_spf_install(struct ospf6_vertex *v, if (IS_OSPF6_DEBUG_SPF(PROCESS)) { zlog_debug( "%s: V lsa %s id %u, route id %u are different", - __PRETTY_FUNCTION__, v->lsa->name, + __func__, v->lsa->name, ntohl(v->lsa->header->id), ntohl(route->path.origin.id)); } @@ -995,15 +995,15 @@ struct ospf6_lsa *ospf6_create_single_router_lsa(struct ospf6_area *area, rtr_lsa = ospf6_lsdb_next(end, rtr_lsa); } if (IS_OSPF6_DEBUG_SPF(PROCESS)) - zlog_debug("%s: adv_router %s num_lsa %u to convert.", - __PRETTY_FUNCTION__, ifbuf, num_lsa); + zlog_debug("%s: adv_router %s num_lsa %u to convert.", __func__, + ifbuf, num_lsa); if (num_lsa == 1) return lsa; if (num_lsa == 0) { if (IS_OSPF6_DEBUG_SPF(PROCESS)) zlog_debug("%s: adv_router %s not found in LSDB.", - __PRETTY_FUNCTION__, ifbuf); + __func__, ifbuf); return NULL; } @@ -1052,7 +1052,7 @@ struct ospf6_lsa *ospf6_create_single_router_lsa(struct ospf6_area *area, inet_ntop(AF_INET, &interface_id, ifbuf, sizeof(ifbuf)); zlog_debug( "%s: Next Router LSA %s to aggreat with len %u interface_id %s", - __PRETTY_FUNCTION__, rtr_lsa->name, + __func__, rtr_lsa->name, ntohs(lsa_header->length), ifbuf); } @@ -1074,9 +1074,9 @@ struct ospf6_lsa *ospf6_create_single_router_lsa(struct ospf6_area *area, if (IS_OSPF6_DEBUG_SPF(PROCESS)) zlog_debug("%s: LSA %s id %u type 0%x len %u num_lsa %u", - __PRETTY_FUNCTION__, lsa->name, - ntohl(lsa->header->id), ntohs(lsa->header->type), - ntohs(lsa->header->length), num_lsa); + __func__, lsa->name, ntohl(lsa->header->id), + ntohs(lsa->header->type), ntohs(lsa->header->length), + num_lsa); return lsa; } @@ -1089,7 +1089,7 @@ void ospf6_remove_temp_router_lsa(struct ospf6_area *area) if (IS_OSPF6_DEBUG_SPF(PROCESS)) zlog_debug( "%s Remove LSA %s lsa->lock %u lsdb count %u", - __PRETTY_FUNCTION__, lsa->name, lsa->lock, + __func__, lsa->name, lsa->lock, area->temp_router_lsa_lsdb->count); ospf6_lsdb_remove(lsa, area->temp_router_lsa_lsdb); } diff --git a/ospf6d/ospf6_top.c b/ospf6d/ospf6_top.c index 95537eb86e..96eee51929 100644 --- a/ospf6d/ospf6_top.c +++ b/ospf6d/ospf6_top.c @@ -111,7 +111,7 @@ static void ospf6_top_brouter_hook_add(struct ospf6_route *route) inet_ntop(AF_INET, &brouter_id, brouter_name, sizeof(brouter_name)); zlog_debug("%s: brouter %s add with adv router %x nh count %u", - __PRETTY_FUNCTION__, brouter_name, + __func__, brouter_name, route->path.origin.adv_router, listcount(route->nh_list)); } @@ -131,7 +131,7 @@ static void ospf6_top_brouter_hook_remove(struct ospf6_route *route) inet_ntop(AF_INET, &brouter_id, brouter_name, sizeof(brouter_name)); zlog_debug("%s: brouter %p %s del with adv router %x nh %u", - __PRETTY_FUNCTION__, (void *)route, brouter_name, + __func__, (void *)route, brouter_name, route->path.origin.adv_router, listcount(route->nh_list)); } diff --git a/ospf6d/ospf6_zebra.c b/ospf6d/ospf6_zebra.c index 6832737ada..f8df37094f 100644 --- a/ospf6d/ospf6_zebra.c +++ b/ospf6d/ospf6_zebra.c @@ -64,10 +64,9 @@ static int ospf6_router_id_update_zebra(ZAPI_CALLBACK_ARGS) if (IS_OSPF6_DEBUG_ZEBRA(RECV)) { char buf[INET_ADDRSTRLEN]; - zlog_debug("%s: zebra router-id %s update", - __PRETTY_FUNCTION__, - inet_ntop(AF_INET, &router_id.u.prefix4, - buf, INET_ADDRSTRLEN)); + zlog_debug("%s: zebra router-id %s update", __func__, + inet_ntop(AF_INET, &router_id.u.prefix4, buf, + INET_ADDRSTRLEN)); } ospf6_router_id_update(); @@ -257,7 +256,7 @@ static void ospf6_zebra_route_update(int type, struct ospf6_route *request) && ospf6_route_is_same(request, request->next)) { if (IS_OSPF6_DEBUG_ZEBRA(SEND)) zlog_debug( - " Best-path removal resulted Sencondary addition"); + " Best-path removal resulted Secondary addition"); type = ADD; request = request->next; } diff --git a/ospfd/ospf_abr.c b/ospfd/ospf_abr.c index b4690cfa42..a8dfcbb36b 100644 --- a/ospfd/ospf_abr.c +++ b/ospfd/ospf_abr.c @@ -670,8 +670,7 @@ static int ospf_abr_translate_nssa(struct ospf_area *area, struct ospf_lsa *lsa) * originate translated LSA */ - if ((new = ospf_translated_nssa_originate(area->ospf, lsa)) - == NULL) { + if (ospf_translated_nssa_originate(area->ospf, lsa) == NULL) { if (IS_DEBUG_OSPF_NSSA) zlog_debug( "ospf_abr_translate_nssa(): Could not translate " diff --git a/ospfd/ospf_dump.c b/ospfd/ospf_dump.c index dffcb930e4..a712ecde95 100644 --- a/ospfd/ospf_dump.c +++ b/ospfd/ospf_dump.c @@ -158,12 +158,12 @@ const char *ospf_timeval_dump(struct timeval *t, char *buf, size_t size) #define HOUR_IN_SECONDS (60*MINUTE_IN_SECONDS) #define DAY_IN_SECONDS (24*HOUR_IN_SECONDS) #define WEEK_IN_SECONDS (7*DAY_IN_SECONDS) - unsigned long w, d, h, m, s, ms, us; + unsigned long w, d, h, m, ms, us; if (!t) return "inactive"; - w = d = h = m = s = ms = us = 0; + w = d = h = m = ms = 0; memset(buf, 0, size); us = t->tv_usec; @@ -386,7 +386,7 @@ static void ospf_packet_db_desc_dump(struct stream *s, uint16_t length) zlog_debug(" Options %d (%s)", dd->options, ospf_options_dump(dd->options)); zlog_debug(" Flags %d (%s)", dd->flags, - ospf_dd_flags_dump(dd->flags, dd_flags, sizeof dd_flags)); + ospf_dd_flags_dump(dd->flags, dd_flags, sizeof(dd_flags))); zlog_debug(" Sequence Number 0x%08lx", (unsigned long)ntohl(dd->dd_seqnum)); diff --git a/ospfd/ospf_flood.c b/ospfd/ospf_flood.c index c29b464cab..818e7e72bc 100644 --- a/ospfd/ospf_flood.c +++ b/ospfd/ospf_flood.c @@ -948,7 +948,7 @@ void ospf_lsa_flush_area(struct ospf_lsa *lsa, struct ospf_area *area) retransmissions */ lsa->data->ls_age = htons(OSPF_LSA_MAXAGE); if (IS_DEBUG_OSPF_EVENT) - zlog_debug("%s: MAXAGE set to LSA %s", __PRETTY_FUNCTION__, + zlog_debug("%s: MAXAGE set to LSA %s", __func__, inet_ntoa(lsa->data->id)); monotime(&lsa->tv_recv); lsa->tv_orig = lsa->tv_recv; diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c index f2efaf322f..1622b2fd25 100644 --- a/ospfd/ospf_interface.c +++ b/ospfd/ospf_interface.c @@ -272,8 +272,8 @@ struct ospf_interface *ospf_if_new(struct ospf *ospf, struct interface *ifp, if (IS_DEBUG_OSPF_EVENT) zlog_debug("%s: ospf interface %s vrf %s id %u created", - __PRETTY_FUNCTION__, ifp->name, - ospf_get_name(ospf), ospf->vrf_id); + __func__, ifp->name, ospf_get_name(ospf), + ospf->vrf_id); return oi; } @@ -349,7 +349,7 @@ void ospf_if_free(struct ospf_interface *oi) if (IS_DEBUG_OSPF_EVENT) zlog_debug("%s: ospf interface %s vrf %s id %u deleted", - __PRETTY_FUNCTION__, oi->ifp->name, + __func__, oi->ifp->name, ospf_vrf_id_to_name(oi->ifp->vrf_id), oi->ifp->vrf_id); diff --git a/ospfd/ospf_ism.c b/ospfd/ospf_ism.c index f4e89da45d..86712c6198 100644 --- a/ospfd/ospf_ism.c +++ b/ospfd/ospf_ism.c @@ -183,17 +183,22 @@ static void ospf_dr_change(struct ospf *ospf, struct route_table *nbrs) struct route_node *rn; struct ospf_neighbor *nbr; - for (rn = route_top(nbrs); rn; rn = route_next(rn)) - if ((nbr = rn->info) != NULL) - /* Ignore 0.0.0.0 node*/ - if (nbr->router_id.s_addr != INADDR_ANY) - /* Is neighbor upper 2-Way? */ - if (nbr->state >= NSM_TwoWay) - /* Ignore myself. */ - if (!IPV4_ADDR_SAME(&nbr->router_id, - &ospf->router_id)) - OSPF_NSM_EVENT_SCHEDULE( - nbr, NSM_AdjOK); + for (rn = route_top(nbrs); rn; rn = route_next(rn)) { + nbr = rn->info; + + if (!nbr) + continue; + + /* + * Ignore 0.0.0.0 node + * Is neighbor 2-Way? + * Ignore myself + */ + if (nbr->router_id.s_addr != INADDR_ANY + && nbr->state >= NSM_TwoWay + && !IPV4_ADDR_SAME(&nbr->router_id, &ospf->router_id)) + OSPF_NSM_EVENT_SCHEDULE(nbr, NSM_AdjOK); + } } static int ospf_dr_election(struct ospf_interface *oi) diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index 35bbe06cd1..55ec638522 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -434,7 +434,7 @@ static char link_info_set(struct stream **s, struct in_addr id, /* we futz the size here for simplicity, really we need * to account * for just: - * IP Header - (sizeof (struct ip)) + * IP Header - (sizeof(struct ip)) * OSPF Header - OSPF_HEADER_SIZE * LSA Header - OSPF_LSA_HEADER_SIZE * MD5 auth data, if MD5 is configured - @@ -2858,7 +2858,7 @@ void ospf_lsa_maxage_delete(struct ospf *ospf, struct ospf_lsa *lsa) } else { if (IS_DEBUG_OSPF_EVENT) zlog_debug("%s: lsa %s is not found in maxage db.", - __PRETTY_FUNCTION__, dump_lsa_key(lsa)); + __func__, dump_lsa_key(lsa)); } } diff --git a/ospfd/ospf_nsm.c b/ospfd/ospf_nsm.c index 0fc2cd60f9..9cd83c245c 100644 --- a/ospfd/ospf_nsm.c +++ b/ospfd/ospf_nsm.c @@ -684,7 +684,7 @@ static void nsm_change_state(struct ospf_neighbor *nbr, int state) zlog_info( "%s:[%s:%s], %s -> %s): " "scheduling new router-LSA origination", - __PRETTY_FUNCTION__, inet_ntoa(nbr->router_id), + __func__, inet_ntoa(nbr->router_id), ospf_get_name(oi->ospf), lookup_msg(ospf_nsm_state_msg, old_state, NULL), lookup_msg(ospf_nsm_state_msg, state, NULL)); @@ -731,7 +731,7 @@ static void nsm_change_state(struct ospf_neighbor *nbr, int state) OSPF_DD_FLAG_I | OSPF_DD_FLAG_M | OSPF_DD_FLAG_MS; if (CHECK_FLAG(oi->ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) zlog_info( - "%s: Intializing [DD]: %s with seqnum:%x , flags:%x", + "%s: Initializing [DD]: %s with seqnum:%x , flags:%x", (oi->ospf->name) ? oi->ospf->name : VRF_DEFAULT_NAME, inet_ntoa(nbr->router_id), nbr->dd_seqnum, diff --git a/ospfd/ospf_opaque.c b/ospfd/ospf_opaque.c index a989b8468c..b042a06372 100644 --- a/ospfd/ospf_opaque.c +++ b/ospfd/ospf_opaque.c @@ -1557,8 +1557,8 @@ struct ospf_lsa *ospf_opaque_lsa_install(struct ospf_lsa *lsa, int rt_recalc) ospf_lsa_unlock(&oipi->lsa); oipi->lsa = ospf_lsa_lock(lsa); } - /* Register the new lsa entry and get its control info. */ - else if ((oipi = register_opaque_lsa(lsa)) == NULL) { + /* Register the new lsa entry */ + else if (register_opaque_lsa(lsa) == NULL) { flog_warn(EC_OSPF_LSA, "ospf_opaque_lsa_install: register_opaque_lsa() ?"); goto out; diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c index 213db15fa5..d87f02627b 100644 --- a/ospfd/ospf_packet.c +++ b/ospfd/ospf_packet.c @@ -725,7 +725,7 @@ static int ospf_write(struct thread *thread) * but.. */ if (sizeof(struct ip) > (unsigned int)(iph.ip_hl << OSPF_WRITE_IPHL_SHIFT)) - iph.ip_hl++; /* we presume sizeof struct ip cant + iph.ip_hl++; /* we presume sizeof(struct ip) cant overflow ip_hl.. */ iph.ip_v = IPVERSION; @@ -2376,9 +2376,9 @@ static struct stream *ospf_recv_packet(struct ospf *ospf, int fd, } if (IS_DEBUG_OSPF_PACKET(0, RECV)) - zlog_debug("%s: fd %d(%s) on interface %d(%s)", - __PRETTY_FUNCTION__, fd, ospf_get_name(ospf), - ifindex, *ifp ? (*ifp)->name : "Unknown"); + zlog_debug("%s: fd %d(%s) on interface %d(%s)", __func__, fd, + ospf_get_name(ospf), ifindex, + *ifp ? (*ifp)->name : "Unknown"); return ibuf; } @@ -2984,8 +2984,7 @@ static enum ospf_read_return_enum ospf_read_helper(struct ospf *ospf) if (IS_DEBUG_OSPF_PACKET(0, RECV)) zlog_debug( "%s: Unable to determine incoming interface from: %s(%s)", - __PRETTY_FUNCTION__, - inet_ntoa(iph->ip_src), + __func__, inet_ntoa(iph->ip_src), ospf_get_name(ospf)); return OSPF_READ_CONTINUE; } @@ -3251,7 +3250,7 @@ static int ospf_make_auth(struct ospf_interface *oi, struct ospf_header *ospfh) switch (ospf_auth_type(oi)) { case OSPF_AUTH_NULL: - /* memset (ospfh->u.auth_data, 0, sizeof (ospfh->u.auth_data)); + /* memset (ospfh->u.auth_data, 0, sizeof(ospfh->u.auth_data)); */ break; case OSPF_AUTH_SIMPLE: @@ -3274,7 +3273,7 @@ static int ospf_make_auth(struct ospf_interface *oi, struct ospf_header *ospfh) /* note: the seq is done in ospf_make_md5_digest() */ break; default: - /* memset (ospfh->u.auth_data, 0, sizeof (ospfh->u.auth_data)); + /* memset (ospfh->u.auth_data, 0, sizeof(ospfh->u.auth_data)); */ break; } @@ -3689,7 +3688,7 @@ static void ospf_hello_send_sub(struct ospf_interface *oi, in_addr_t addr) if (oi->ospf->vrf_id) zlog_debug( "%s: Hello Tx interface %s ospf vrf %s id %u", - __PRETTY_FUNCTION__, oi->ifp->name, + __func__, oi->ifp->name, ospf_vrf_id_to_name(oi->ospf->vrf_id), oi->ospf->vrf_id); } diff --git a/ospfd/ospf_snmp.c b/ospfd/ospf_snmp.c index 7bd586fd31..550e5ee9ee 100644 --- a/ospfd/ospf_snmp.c +++ b/ospfd/ospf_snmp.c @@ -2455,7 +2455,7 @@ static void ospfTrapNbrStateChange(struct ospf_neighbor *on) ospf_nbr_state_message(on, msgbuf, sizeof(msgbuf)); if (IS_DEBUG_OSPF_EVENT) - zlog_info("%s: trap sent: %s now %s", __PRETTY_FUNCTION__, + zlog_info("%s: trap sent: %s now %s", __func__, inet_ntoa(on->address.u.prefix4), msgbuf); oid_copy_addr(index, &(on->address.u.prefix4), IN_ADDR_SIZE); @@ -2463,7 +2463,7 @@ static void ospfTrapNbrStateChange(struct ospf_neighbor *on) smux_trap(ospf_variables, array_size(ospf_variables), ospf_trap_oid, array_size(ospf_trap_oid), ospf_oid, - sizeof ospf_oid / sizeof(oid), index, IN_ADDR_SIZE + 1, + sizeof(ospf_oid) / sizeof(oid), index, IN_ADDR_SIZE + 1, ospfNbrTrapList, array_size(ospfNbrTrapList), NBRSTATECHANGE); } @@ -2478,7 +2478,7 @@ static void ospfTrapVirtNbrStateChange(struct ospf_neighbor *on) smux_trap(ospf_variables, array_size(ospf_variables), ospf_trap_oid, array_size(ospf_trap_oid), ospf_oid, - sizeof ospf_oid / sizeof(oid), index, IN_ADDR_SIZE + 1, + sizeof(ospf_oid) / sizeof(oid), index, IN_ADDR_SIZE + 1, ospfVirtNbrTrapList, array_size(ospfVirtNbrTrapList), VIRTNBRSTATECHANGE); } @@ -2508,7 +2508,7 @@ static void ospfTrapIfStateChange(struct ospf_interface *oi) oid index[sizeof(oid) * (IN_ADDR_SIZE + 1)]; if (IS_DEBUG_OSPF_EVENT) - zlog_info("%s: trap sent: %s now %s", __PRETTY_FUNCTION__, + zlog_info("%s: trap sent: %s now %s", __func__, inet_ntoa(oi->address->u.prefix4), lookup_msg(ospf_ism_state_msg, oi->state, NULL)); @@ -2517,7 +2517,7 @@ static void ospfTrapIfStateChange(struct ospf_interface *oi) smux_trap(ospf_variables, array_size(ospf_variables), ospf_trap_oid, array_size(ospf_trap_oid), ospf_oid, - sizeof ospf_oid / sizeof(oid), index, IN_ADDR_SIZE + 1, + sizeof(ospf_oid) / sizeof(oid), index, IN_ADDR_SIZE + 1, ospfIfTrapList, array_size(ospfIfTrapList), IFSTATECHANGE); } @@ -2532,7 +2532,7 @@ static void ospfTrapVirtIfStateChange(struct ospf_interface *oi) smux_trap(ospf_variables, array_size(ospf_variables), ospf_trap_oid, array_size(ospf_trap_oid), ospf_oid, - sizeof ospf_oid / sizeof(oid), index, IN_ADDR_SIZE + 1, + sizeof(ospf_oid) / sizeof(oid), index, IN_ADDR_SIZE + 1, ospfVirtIfTrapList, array_size(ospfVirtIfTrapList), VIRTIFSTATECHANGE); } diff --git a/ospfd/ospf_spf.c b/ospfd/ospf_spf.c index 620691a98d..8b605b3bac 100644 --- a/ospfd/ospf_spf.c +++ b/ospfd/ospf_spf.c @@ -1345,7 +1345,7 @@ static int ospf_spf_calculate_timer(struct thread *thread) if (IS_DEBUG_OSPF_EVENT) zlog_debug( "%s: ospf install new route, vrf %s id %u new_table count %lu", - __PRETTY_FUNCTION__, ospf_vrf_id_to_name(ospf->vrf_id), + __func__, ospf_vrf_id_to_name(ospf->vrf_id), ospf->vrf_id, new_table->count); /* Update routing table. */ monotime(&start_time); diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index fb4082e509..75f556e39f 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -93,7 +93,7 @@ static int str2metric(const char *str, int *metric) return 0; *metric = strtol(str, NULL, 10); - if (*metric < 0 && *metric > 16777214) { + if (*metric < 0 || *metric > 16777214) { /* vty_out (vty, "OSPF metric value is invalid\n"); */ return 0; } @@ -619,8 +619,7 @@ DEFUN (ospf_network_area, if (IS_DEBUG_OSPF_EVENT) zlog_debug( "%s ospf vrf %s num of %u ip osp area x config", - __PRETTY_FUNCTION__, - ospf->name ? ospf->name : "NIL", + __func__, ospf->name ? ospf->name : "NIL", ospf->if_ospf_cli_count); return CMD_WARNING_CONFIG_FAILED; } diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c index 64013435f6..385a7ece7b 100644 --- a/ospfd/ospf_zebra.c +++ b/ospfd/ospf_zebra.c @@ -87,8 +87,8 @@ static int ospf_router_id_update_zebra(ZAPI_CALLBACK_ARGS) prefix2str(&router_id, buf, sizeof(buf)); zlog_debug( "%s: ospf instance not found for vrf %s id %u router_id %s", - __PRETTY_FUNCTION__, - ospf_vrf_id_to_name(vrf_id), vrf_id, buf); + __func__, ospf_vrf_id_to_name(vrf_id), vrf_id, + buf); } } return 0; @@ -197,7 +197,7 @@ static int ospf_interface_vrf_update(ZAPI_CALLBACK_ARGS) if (IS_DEBUG_OSPF_EVENT) zlog_debug( "%s: Rx Interface %s VRF change vrf_id %u New vrf %s id %u", - __PRETTY_FUNCTION__, ifp->name, vrf_id, + __func__, ifp->name, vrf_id, ospf_vrf_id_to_name(new_vrf_id), new_vrf_id); /*if_update(ifp, ifp->name, strlen(ifp->name), new_vrf_id);*/ @@ -957,8 +957,8 @@ static int ospf_distribute_list_update_timer(struct thread *thread) if (IS_DEBUG_OSPF_EVENT) { zlog_debug( "%s: ospf distribute-list update arg_type %d vrf %s id %d", - __PRETTY_FUNCTION__, arg_type, - ospf_vrf_id_to_name(ospf->vrf_id), ospf->vrf_id); + __func__, arg_type, ospf_vrf_id_to_name(ospf->vrf_id), + ospf->vrf_id); } /* foreach all external info. */ @@ -1002,7 +1002,6 @@ static int ospf_distribute_list_update_timer(struct thread *thread) void ospf_distribute_list_update(struct ospf *ospf, int type, unsigned short instance) { - struct route_table *rt; struct ospf_external *ext; void **args = XCALLOC(MTYPE_OSPF_DIST_ARGS, sizeof(void *) * 2); @@ -1011,7 +1010,7 @@ void ospf_distribute_list_update(struct ospf *ospf, int type, /* External info does not exist. */ ext = ospf_external_lookup(ospf, type, instance); - if (!ext || !(rt = EXTERNAL_INFO(ext))) { + if (!ext || !EXTERNAL_INFO(ext)) { XFREE(MTYPE_OSPF_DIST_ARGS, args); return; } @@ -1321,8 +1320,7 @@ void ospf_zebra_vrf_register(struct ospf *ospf) if (ospf->vrf_id != VRF_UNKNOWN) { if (IS_DEBUG_OSPF_EVENT) - zlog_debug("%s: Register VRF %s id %u", - __PRETTY_FUNCTION__, + zlog_debug("%s: Register VRF %s id %u", __func__, ospf_vrf_id_to_name(ospf->vrf_id), ospf->vrf_id); zclient_send_reg_requests(zclient, ospf->vrf_id); @@ -1337,8 +1335,7 @@ void ospf_zebra_vrf_deregister(struct ospf *ospf) if (ospf->vrf_id != VRF_DEFAULT && ospf->vrf_id != VRF_UNKNOWN) { if (IS_DEBUG_OSPF_EVENT) zlog_debug("%s: De-Register VRF %s id %u to Zebra.", - __PRETTY_FUNCTION__, - ospf_vrf_id_to_name(ospf->vrf_id), + __func__, ospf_vrf_id_to_name(ospf->vrf_id), ospf->vrf_id); /* Deregister for router-id, interfaces, * redistributed routes. */ diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index 2a3f1329a0..f3fe9e17b2 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -220,7 +220,7 @@ static struct ospf *ospf_new(unsigned short instance, const char *name) if (IS_DEBUG_OSPF_EVENT) zlog_debug( "%s: Create new ospf instance with vrf_name %s vrf_id %u", - __PRETTY_FUNCTION__, name, new->vrf_id); + __func__, name, new->vrf_id); } else { new->vrf_id = VRF_DEFAULT; vrf = vrf_lookup_by_id(VRF_DEFAULT); @@ -1308,7 +1308,7 @@ void ospf_if_update(struct ospf *ospf, struct interface *ifp) if (IS_DEBUG_OSPF_EVENT) zlog_debug( "%s: interface %s ifp->vrf_id %u ospf vrf %s vrf_id %u router_id %s", - __PRETTY_FUNCTION__, ifp->name, ifp->vrf_id, + __func__, ifp->name, ifp->vrf_id, ospf_vrf_id_to_name(ospf->vrf_id), ospf->vrf_id, inet_ntoa(ospf->router_id)); @@ -2019,8 +2019,8 @@ void ospf_vrf_unlink(struct ospf *ospf, struct vrf *vrf) static int ospf_vrf_new(struct vrf *vrf) { if (IS_DEBUG_OSPF_EVENT) - zlog_debug("%s: VRF Created: %s(%u)", __PRETTY_FUNCTION__, - vrf->name, vrf->vrf_id); + zlog_debug("%s: VRF Created: %s(%u)", __func__, vrf->name, + vrf->vrf_id); return 0; } @@ -2029,8 +2029,8 @@ static int ospf_vrf_new(struct vrf *vrf) static int ospf_vrf_delete(struct vrf *vrf) { if (IS_DEBUG_OSPF_EVENT) - zlog_debug("%s: VRF Deletion: %s(%u)", __PRETTY_FUNCTION__, - vrf->name, vrf->vrf_id); + zlog_debug("%s: VRF Deletion: %s(%u)", __func__, vrf->name, + vrf->vrf_id); return 0; } @@ -2060,8 +2060,8 @@ static int ospf_vrf_enable(struct vrf *vrf) int ret = 0; if (IS_DEBUG_OSPF_EVENT) - zlog_debug("%s: VRF %s id %u enabled", __PRETTY_FUNCTION__, - vrf->name, vrf->vrf_id); + zlog_debug("%s: VRF %s id %u enabled", __func__, vrf->name, + vrf->vrf_id); ospf = ospf_lookup_by_name(vrf->name); if (ospf) { @@ -2075,8 +2075,7 @@ static int ospf_vrf_enable(struct vrf *vrf) if (IS_DEBUG_OSPF_EVENT) zlog_debug( "%s: ospf linked to vrf %s vrf_id %u (old id %u)", - __PRETTY_FUNCTION__, vrf->name, ospf->vrf_id, - old_vrf_id); + __func__, vrf->name, ospf->vrf_id, old_vrf_id); if (old_vrf_id != ospf->vrf_id) { frr_with_privs(&ospfd_privs) { @@ -2113,8 +2112,8 @@ static int ospf_vrf_disable(struct vrf *vrf) return 0; if (IS_DEBUG_OSPF_EVENT) - zlog_debug("%s: VRF %s id %d disabled.", __PRETTY_FUNCTION__, - vrf->name, vrf->vrf_id); + zlog_debug("%s: VRF %s id %d disabled.", __func__, vrf->name, + vrf->vrf_id); ospf = ospf_lookup_by_name(vrf->name); if (ospf) { @@ -2126,8 +2125,8 @@ static int ospf_vrf_disable(struct vrf *vrf) ospf_vrf_unlink(ospf, vrf); ospf->oi_running = 0; if (IS_DEBUG_OSPF_EVENT) - zlog_debug("%s: ospf old_vrf_id %d unlinked", - __PRETTY_FUNCTION__, old_vrf_id); + zlog_debug("%s: ospf old_vrf_id %d unlinked", __func__, + old_vrf_id); thread_cancel(ospf->t_read); close(ospf->fd); ospf->fd = -1; diff --git a/pbrd/pbr_map.c b/pbrd/pbr_map.c index 37b6be6949..e45e629649 100644 --- a/pbrd/pbr_map.c +++ b/pbrd/pbr_map.c @@ -202,7 +202,7 @@ void pbr_map_reason_string(unsigned int reason, char *buf, int size) void pbr_map_final_interface_deletion(struct pbr_map *pbrm, struct pbr_map_interface *pmi) { - if (pmi->delete == true && !pbr_map_interface_is_installed(pbrm, pmi)) { + if (pmi->delete && !pbr_map_interface_is_installed(pbrm, pmi)) { listnode_delete(pbrm->incoming, pmi); pmi->pbrm = NULL; @@ -327,8 +327,7 @@ void pbr_map_vrf_update(const struct pbr_vrf *pbr_vrf) enabled ? "enabled" : "disabled"); RB_FOREACH (pbrm, pbr_map_entry_head, &pbr_maps) { - DEBUGD(&pbr_dbg_map, "%s: Looking at %s", __PRETTY_FUNCTION__, - pbrm->name); + DEBUGD(&pbr_dbg_map, "%s: Looking at %s", __func__, pbrm->name); for (ALL_LIST_ELEMENTS_RO(pbrm->seqnumbers, node, pbrms)) pbrms_vrf_update(pbrms, pbr_vrf); } @@ -417,8 +416,7 @@ struct pbr_map_sequence *pbrms_lookup_unique(uint32_t unique, ifindex_t ifindex, for (ALL_LIST_ELEMENTS_RO(pbrm->seqnumbers, snode, pbrms)) { DEBUGD(&pbr_dbg_map, "%s: Comparing %u to %u", - __PRETTY_FUNCTION__, pbrms->unique, - unique); + __func__, pbrms->unique, unique); if (pbrms->unique == unique) return pbrms; } @@ -595,8 +593,8 @@ bool pbr_map_check_valid(const char *name) pbrm = pbrm_find(name); if (!pbrm) { DEBUGD(&pbr_dbg_map, - "%s: Specified PBR-MAP(%s) does not exist?", - __PRETTY_FUNCTION__, name); + "%s: Specified PBR-MAP(%s) does not exist?", __func__, + name); return false; } @@ -611,8 +609,7 @@ void pbr_map_schedule_policy_from_nhg(const char *nh_group) struct listnode *node; RB_FOREACH (pbrm, pbr_map_entry_head, &pbr_maps) { - DEBUGD(&pbr_dbg_map, "%s: Looking at %s", __PRETTY_FUNCTION__, - pbrm->name); + DEBUGD(&pbr_dbg_map, "%s: Looking at %s", __func__, pbrm->name); for (ALL_LIST_ELEMENTS_RO(pbrm->seqnumbers, node, pbrms)) { DEBUGD(&pbr_dbg_map, "\tNH Grp name: %s", pbrms->nhgrp_name ? @@ -643,16 +640,15 @@ void pbr_map_policy_install(const char *name) struct listnode *node, *inode; struct pbr_map_interface *pmi; - DEBUGD(&pbr_dbg_map, "%s: for %s", __PRETTY_FUNCTION__, name); + DEBUGD(&pbr_dbg_map, "%s: for %s", __func__, name); pbrm = pbrm_find(name); if (!pbrm) return; for (ALL_LIST_ELEMENTS_RO(pbrm->seqnumbers, node, pbrms)) { DEBUGD(&pbr_dbg_map, - "%s: Looking at what to install %s(%u) %d %d", - __PRETTY_FUNCTION__, name, pbrms->seqno, pbrm->valid, - pbrms->nhs_installed); + "%s: Looking at what to install %s(%u) %d %d", __func__, + name, pbrms->seqno, pbrm->valid, pbrms->nhs_installed); if (pbrm->valid && pbrms->nhs_installed && pbrm->incoming->count) { @@ -726,8 +722,8 @@ void pbr_map_check(struct pbr_map_sequence *pbrms) bool install; pbrm = pbrms->parent; - DEBUGD(&pbr_dbg_map, "%s: for %s(%u)", __PRETTY_FUNCTION__, - pbrm->name, pbrms->seqno); + DEBUGD(&pbr_dbg_map, "%s: for %s(%u)", __func__, pbrm->name, + pbrms->seqno); if (pbr_map_check_valid(pbrm->name)) DEBUGD(&pbr_dbg_map, "We are totally valid %s", pbrm->name); @@ -735,16 +731,13 @@ void pbr_map_check(struct pbr_map_sequence *pbrms) if (pbrms->reason == PBR_MAP_VALID_SEQUENCE_NUMBER) { install = true; DEBUGD(&pbr_dbg_map, "%s: Installing %s(%u) reason: %" PRIu64, - __PRETTY_FUNCTION__, pbrm->name, pbrms->seqno, - pbrms->reason); + __func__, pbrm->name, pbrms->seqno, pbrms->reason); DEBUGD(&pbr_dbg_map, "\tSending PBR_MAP_POLICY_INSTALL event"); } else { install = false; - DEBUGD(&pbr_dbg_map, - "%s: Removing %s(%u) reason: %" PRIu64, - __PRETTY_FUNCTION__, pbrm->name, - pbrms->seqno, pbrms->reason); + DEBUGD(&pbr_dbg_map, "%s: Removing %s(%u) reason: %" PRIu64, + __func__, pbrm->name, pbrms->seqno, pbrms->reason); } if (install) diff --git a/pbrd/pbr_nht.c b/pbrd/pbr_nht.c index 5ab714e617..ecd375333c 100644 --- a/pbrd/pbr_nht.c +++ b/pbrd/pbr_nht.c @@ -97,8 +97,7 @@ static void *pbr_nh_alloc(void *p) /* Decremented again in pbr_nh_delete */ ++nhrc->refcount; - DEBUGD(&pbr_dbg_nht, "%s: Sending nexthop to Zebra", - __PRETTY_FUNCTION__); + DEBUGD(&pbr_dbg_nht, "%s: Sending nexthop to Zebra", __func__); pbr_send_rnh(new->nexthop, true); @@ -116,7 +115,7 @@ static void pbr_nh_delete(struct pbr_nexthop_cache **pnhc) --nhrc->refcount; if (!nhrc || nhrc->refcount == 0) { DEBUGD(&pbr_dbg_nht, "%s: Removing nexthop from Zebra", - __PRETTY_FUNCTION__); + __func__); pbr_send_rnh((*pnhc)->nexthop, false); } if (nhrc && nhrc->refcount == 0) { @@ -197,8 +196,8 @@ static void *pbr_nhgc_alloc(void *p) strlcpy(new->name, pnhgc->name, sizeof(pnhgc->name)); new->table_id = pbr_nht_get_next_tableid(false); - DEBUGD(&pbr_dbg_nht, "%s: NHT: %s assigned Table ID: %u", - __PRETTY_FUNCTION__, new->name, new->table_id); + DEBUGD(&pbr_dbg_nht, "%s: NHT: %s assigned Table ID: %u", __func__, + new->name, new->table_id); new->nhh = hash_create_size(8, pbr_nh_hash_key, pbr_nh_hash_equal, "PBR NH Cache Hash"); @@ -215,7 +214,7 @@ void pbr_nhgroup_add_cb(const char *name) if (!nhgc) { DEBUGD(&pbr_dbg_nht, "%s: Could not find nhgc with name: %s\n", - __PRETTY_FUNCTION__, name); + __func__, name); return; } @@ -224,8 +223,7 @@ void pbr_nhgroup_add_cb(const char *name) if (!pnhgc) return; - DEBUGD(&pbr_dbg_nht, "%s: Added nexthop-group %s", __PRETTY_FUNCTION__, - name); + DEBUGD(&pbr_dbg_nht, "%s: Added nexthop-group %s", __func__, name); pbr_map_check_nh_group_change(name); } @@ -242,7 +240,7 @@ void pbr_nhgroup_add_nexthop_cb(const struct nexthop_group_cmd *nhgc, if (!pbr_nht_get_next_tableid(true)) { zlog_warn( "%s: Exhausted all table identifiers; cannot create nexthop-group cache for nexthop-group '%s'", - __PRETTY_FUNCTION__, nhgc->name); + __func__, nhgc->name); return; } @@ -261,7 +259,7 @@ void pbr_nhgroup_add_nexthop_cb(const struct nexthop_group_cmd *nhgc, if (DEBUG_MODE_CHECK(&pbr_dbg_nht, DEBUG_MODE_ALL)) { nexthop2str(nhop, debugstr, sizeof(debugstr)); DEBUGD(&pbr_dbg_nht, "%s: Added %s to nexthop-group %s", - __PRETTY_FUNCTION__, debugstr, nhgc->name); + __func__, debugstr, nhgc->name); } pbr_nht_install_nexthop_group(pnhgc, nhgc->nhg); @@ -302,7 +300,7 @@ void pbr_nhgroup_del_nexthop_cb(const struct nexthop_group_cmd *nhgc, if (DEBUG_MODE_CHECK(&pbr_dbg_nht, DEBUG_MODE_ALL)) { nexthop2str(nhop, debugstr, sizeof(debugstr)); DEBUGD(&pbr_dbg_nht, "%s: Removed %s from nexthop-group %s", - __PRETTY_FUNCTION__, debugstr, nhgc->name); + __func__, debugstr, nhgc->name); } if (pnhgc->nhh->count) @@ -315,8 +313,7 @@ void pbr_nhgroup_del_nexthop_cb(const struct nexthop_group_cmd *nhgc, void pbr_nhgroup_delete_cb(const char *name) { - DEBUGD(&pbr_dbg_nht, "%s: Removed nexthop-group %s", - __PRETTY_FUNCTION__, name); + DEBUGD(&pbr_dbg_nht, "%s: Removed nexthop-group %s", __func__, name); /* delete group from all pbrms's */ pbr_nht_delete_group(name); @@ -339,8 +336,8 @@ static void pbr_nht_find_nhg_from_table_install(struct hash_bucket *b, uint32_t *table_id = (uint32_t *)data; if (pnhgc->table_id == *table_id) { - DEBUGD(&pbr_dbg_nht, "%s: Table ID (%u) matches %s", - __PRETTY_FUNCTION__, *table_id, pnhgc->name); + DEBUGD(&pbr_dbg_nht, "%s: Table ID (%u) matches %s", __func__, + *table_id, pnhgc->name); /* * If the table has been re-handled by zebra @@ -434,13 +431,13 @@ static afi_t pbr_nht_which_afi(struct nexthop_group nhg, if (!bh && v6 && v4) DEBUGD(&pbr_dbg_nht, - "%s: Saw both V6 and V4 nexthops...using %s", - __PRETTY_FUNCTION__, afi2str(install_afi)); + "%s: Saw both V6 and V4 nexthops...using %s", __func__, + afi2str(install_afi)); if (bh && (v6 || v4)) DEBUGD(&pbr_dbg_nht, "%s: Saw blackhole nexthop(s) with %s%s%s nexthop(s), using AFI_MAX.", - __PRETTY_FUNCTION__, v4 ? "v4" : "", - (v4 && v6) ? " and " : "", v6 ? "v6" : ""); + __func__, v4 ? "v4" : "", (v4 && v6) ? " and " : "", + v6 ? "v6" : ""); return install_afi; } @@ -488,7 +485,7 @@ void pbr_nht_change_group(const char *name) if (!pnhgc) { DEBUGD(&pbr_dbg_nht, "%s: Could not find nexthop-group cache w/ name '%s'", - __PRETTY_FUNCTION__, name); + __func__, name); return; } @@ -527,7 +524,7 @@ void pbr_nht_add_individual_nexthop(struct pbr_map_sequence *pbrms) if (!pbr_nht_get_next_tableid(true)) { zlog_warn( "%s: Exhausted all table identifiers; cannot create nexthop-group cache for nexthop-group '%s'", - __PRETTY_FUNCTION__, find.name); + __func__, find.name); return; } @@ -582,7 +579,7 @@ struct pbr_nexthop_group_cache *pbr_nht_add_group(const char *name) if (!pbr_nht_get_next_tableid(true)) { zlog_warn( "%s: Exhausted all table identifiers; cannot create nexthop-group cache for nexthop-group '%s'", - __PRETTY_FUNCTION__, name); + __func__, name); return NULL; } @@ -590,14 +587,13 @@ struct pbr_nexthop_group_cache *pbr_nht_add_group(const char *name) if (!nhgc) { DEBUGD(&pbr_dbg_nht, "%s: Could not find nhgc with name: %s\n", - __PRETTY_FUNCTION__, name); + __func__, name); return NULL; } snprintf(lookup.name, sizeof(lookup.name), "%s", name); pnhgc = hash_get(pbr_nhg_hash, &lookup, pbr_nhgc_alloc); - DEBUGD(&pbr_dbg_nht, "%s: Retrieved NHGC @ %p", __PRETTY_FUNCTION__, - pnhgc); + DEBUGD(&pbr_dbg_nht, "%s: Retrieved NHGC @ %p", __func__, pnhgc); for (ALL_NEXTHOPS(nhgc->nhg, nhop)) { struct pbr_nexthop_cache lookupc; @@ -641,7 +637,7 @@ void pbr_nht_delete_group(const char *name) bool pbr_nht_nexthop_valid(struct nexthop_group *nhg) { - DEBUGD(&pbr_dbg_nht, "%s: %p", __PRETTY_FUNCTION__, nhg); + DEBUGD(&pbr_dbg_nht, "%s: %p", __func__, nhg); return true; } @@ -650,13 +646,13 @@ bool pbr_nht_nexthop_group_valid(const char *name) struct pbr_nexthop_group_cache *pnhgc; struct pbr_nexthop_group_cache lookup; - DEBUGD(&pbr_dbg_nht, "%s: %s", __PRETTY_FUNCTION__, name); + DEBUGD(&pbr_dbg_nht, "%s: %s", __func__, name); snprintf(lookup.name, sizeof(lookup.name), "%s", name); pnhgc = hash_get(pbr_nhg_hash, &lookup, NULL); if (!pnhgc) return false; - DEBUGD(&pbr_dbg_nht, "%s: \t%d %d", __PRETTY_FUNCTION__, pnhgc->valid, + DEBUGD(&pbr_dbg_nht, "%s: \t%d %d", __func__, pnhgc->valid, pnhgc->installed); if (pnhgc->valid && pnhgc->installed) return true; @@ -853,7 +849,7 @@ void pbr_nht_nexthop_update(struct zapi_route *nhr) } static void -pbr_nht_individual_nexthop_interface_update_lookup(struct hash_backet *b, +pbr_nht_individual_nexthop_interface_update_lookup(struct hash_bucket *b, void *data) { struct pbr_nexthop_cache *pnhc = b->data; @@ -871,7 +867,7 @@ pbr_nht_individual_nexthop_interface_update_lookup(struct hash_backet *b, pnhi->valid += 1; } -static void pbr_nht_nexthop_interface_update_lookup(struct hash_backet *b, +static void pbr_nht_nexthop_interface_update_lookup(struct hash_bucket *b, void *data) { struct pbr_nexthop_group_cache *pnhgc = b->data; @@ -982,7 +978,7 @@ uint32_t pbr_nht_get_table(const char *name) if (!pnhgc) { DEBUGD(&pbr_dbg_nht, "%s: Could not find nexthop-group cache w/ name '%s'", - __PRETTY_FUNCTION__, name); + __func__, name); return 5000; } diff --git a/pbrd/pbr_vty.c b/pbrd/pbr_vty.c index c1922d8728..e395b7831d 100644 --- a/pbrd/pbr_vty.c +++ b/pbrd/pbr_vty.c @@ -88,8 +88,7 @@ DEFUN_NOSH(no_pbr_map, no_pbr_map_cmd, "no pbr-map PBRMAP [seq (1-700)]", DEFPY(pbr_set_table_range, pbr_set_table_range_cmd, - "[no] pbr table range (10000-4294966272)$lb (10000-4294966272)$ub", - NO_STR + "pbr table range (10000-4294966272)$lb (10000-4294966272)$ub", PBR_STR "Set table ID range\n" "Set table ID range\n" @@ -113,6 +112,19 @@ DEFPY(pbr_set_table_range, return ret; } +DEFPY(no_pbr_set_table_range, no_pbr_set_table_range_cmd, + "no pbr table range [(10000-4294966272)$lb (10000-4294966272)$ub]", + NO_STR + PBR_STR + "Set table ID range\n" + "Set table ID range\n" + "Lower bound for table ID range\n" + "Upper bound for table ID range\n") +{ + pbr_nht_set_tableid_range(PBR_NHT_DEFAULT_LOW_TABLEID, + PBR_NHT_DEFAULT_HIGH_TABLEID); + return CMD_SUCCESS; +} DEFPY(pbr_map_match_src, pbr_map_match_src_cmd, "[no] match src-ip <A.B.C.D/M|X:X::X:X/M>$prefix", @@ -854,6 +866,7 @@ void pbr_vty_init(void) install_element(CONFIG_NODE, &pbr_map_cmd); install_element(CONFIG_NODE, &no_pbr_map_cmd); install_element(CONFIG_NODE, &pbr_set_table_range_cmd); + install_element(CONFIG_NODE, &no_pbr_set_table_range_cmd); install_element(INTERFACE_NODE, &pbr_policy_cmd); install_element(PBRMAP_NODE, &pbr_map_match_src_cmd); install_element(PBRMAP_NODE, &pbr_map_match_dst_cmd); diff --git a/pbrd/pbr_zebra.c b/pbrd/pbr_zebra.c index ec0327d74f..c2d93a405e 100644 --- a/pbrd/pbr_zebra.c +++ b/pbrd/pbr_zebra.c @@ -62,8 +62,7 @@ struct pbr_interface *pbr_if_new(struct interface *ifp) /* Inteface addition message from zebra. */ int pbr_ifp_create(struct interface *ifp) { - DEBUGD(&pbr_dbg_zebra, - "%s: %s", __PRETTY_FUNCTION__, ifp->name); + DEBUGD(&pbr_dbg_zebra, "%s: %s", __func__, ifp->name); if (!ifp->info) pbr_if_new(ifp); @@ -78,8 +77,7 @@ int pbr_ifp_create(struct interface *ifp) int pbr_ifp_destroy(struct interface *ifp) { - DEBUGD(&pbr_dbg_zebra, - "%s: %s", __PRETTY_FUNCTION__, ifp->name); + DEBUGD(&pbr_dbg_zebra, "%s: %s", __func__, ifp->name); pbr_map_policy_interface_update(ifp, false); @@ -93,8 +91,7 @@ static int interface_address_add(ZAPI_CALLBACK_ARGS) c = zebra_interface_address_read(cmd, zclient->ibuf, vrf_id); - DEBUGD(&pbr_dbg_zebra, - "%s: %s added %s", __PRETTY_FUNCTION__, + DEBUGD(&pbr_dbg_zebra, "%s: %s added %s", __func__, c ? c->ifp->name : "Unknown", c ? prefix2str(c->address, buf, sizeof(buf)) : "Unknown"); @@ -111,8 +108,7 @@ static int interface_address_delete(ZAPI_CALLBACK_ARGS) if (!c) return 0; - DEBUGD(&pbr_dbg_zebra, - "%s: %s deleted %s", __PRETTY_FUNCTION__, c->ifp->name, + DEBUGD(&pbr_dbg_zebra, "%s: %s deleted %s", __func__, c->ifp->name, prefix2str(c->address, buf, sizeof(buf))); connected_free(&c); @@ -121,8 +117,7 @@ static int interface_address_delete(ZAPI_CALLBACK_ARGS) int pbr_ifp_up(struct interface *ifp) { - DEBUGD(&pbr_dbg_zebra, - "%s: %s is up", __PRETTY_FUNCTION__, ifp->name); + DEBUGD(&pbr_dbg_zebra, "%s: %s is up", __func__, ifp->name); pbr_nht_nexthop_interface_update(ifp); @@ -131,8 +126,7 @@ int pbr_ifp_up(struct interface *ifp) int pbr_ifp_down(struct interface *ifp) { - DEBUGD(&pbr_dbg_zebra, - "%s: %s is down", __PRETTY_FUNCTION__, ifp->name); + DEBUGD(&pbr_dbg_zebra, "%s: %s is down", __func__, ifp->name); pbr_nht_nexthop_interface_update(ifp); @@ -177,30 +171,30 @@ static int route_notify_owner(ZAPI_CALLBACK_ARGS) switch (note) { case ZAPI_ROUTE_FAIL_INSTALL: DEBUGD(&pbr_dbg_zebra, - "%s: [%s] Route install failure for table: %u", - __PRETTY_FUNCTION__, buf, table_id); + "%s: [%s] Route install failure for table: %u", __func__, + buf, table_id); break; case ZAPI_ROUTE_BETTER_ADMIN_WON: DEBUGD(&pbr_dbg_zebra, "%s: [%s] Route better admin distance won for table: %u", - __PRETTY_FUNCTION__, buf, table_id); + __func__, buf, table_id); break; case ZAPI_ROUTE_INSTALLED: DEBUGD(&pbr_dbg_zebra, "%s: [%s] Route installed succeeded for table: %u", - __PRETTY_FUNCTION__, buf, table_id); + __func__, buf, table_id); pbr_nht_route_installed_for_table(table_id); break; case ZAPI_ROUTE_REMOVED: DEBUGD(&pbr_dbg_zebra, "%s: [%s] Route Removed succeeded for table: %u", - __PRETTY_FUNCTION__, buf, table_id); + __func__, buf, table_id); pbr_nht_route_removed_for_table(table_id); break; case ZAPI_ROUTE_REMOVE_FAIL: DEBUGD(&pbr_dbg_zebra, - "%s: [%s] Route remove fail for table: %u", - __PRETTY_FUNCTION__, buf, table_id); + "%s: [%s] Route remove fail for table: %u", __func__, + buf, table_id); break; } @@ -224,8 +218,8 @@ static int rule_notify_owner(ZAPI_CALLBACK_ARGS) pbrms = pbrms_lookup_unique(unique, ifi, &pmi); if (!pbrms) { DEBUGD(&pbr_dbg_zebra, - "%s: Failure to lookup pbrms based upon %u", - __PRETTY_FUNCTION__, unique); + "%s: Failure to lookup pbrms based upon %u", __func__, + unique); return 0; } @@ -256,8 +250,7 @@ static int rule_notify_owner(ZAPI_CALLBACK_ARGS) static void zebra_connected(struct zclient *zclient) { - DEBUGD(&pbr_dbg_zebra, "%s: Registering for fun and profit", - __PRETTY_FUNCTION__); + DEBUGD(&pbr_dbg_zebra, "%s: Registering for fun and profit", __func__); zclient_send_reg_requests(zclient, VRF_DEFAULT); } @@ -318,8 +311,7 @@ void route_add(struct pbr_nexthop_group_cache *pnhgc, struct nexthop_group nhg, { struct zapi_route api; - DEBUGD(&pbr_dbg_zebra, "%s for Table: %d", __PRETTY_FUNCTION__, - pnhgc->table_id); + DEBUGD(&pbr_dbg_zebra, "%s for Table: %d", __func__, pnhgc->table_id); memset(&api, 0, sizeof(api)); @@ -347,12 +339,11 @@ void route_add(struct pbr_nexthop_group_cache *pnhgc, struct nexthop_group nhg, case AFI_L2VPN: DEBUGD(&pbr_dbg_zebra, "%s: Asked to install unsupported route type: L2VPN", - __PRETTY_FUNCTION__); + __func__); break; case AFI_UNSPEC: DEBUGD(&pbr_dbg_zebra, - "%s: Asked to install unspecified route type", - __PRETTY_FUNCTION__); + "%s: Asked to install unspecified route type", __func__); break; } } @@ -365,8 +356,7 @@ void route_delete(struct pbr_nexthop_group_cache *pnhgc, afi_t afi) { struct zapi_route api; - DEBUGD(&pbr_dbg_zebra, "%s for Table: %d", __PRETTY_FUNCTION__, - pnhgc->table_id); + DEBUGD(&pbr_dbg_zebra, "%s for Table: %d", __func__, pnhgc->table_id); memset(&api, 0, sizeof(api)); api.vrf_id = VRF_DEFAULT; @@ -394,12 +384,11 @@ void route_delete(struct pbr_nexthop_group_cache *pnhgc, afi_t afi) case AFI_L2VPN: DEBUGD(&pbr_dbg_zebra, "%s: Asked to delete unsupported route type: L2VPN", - __PRETTY_FUNCTION__); + __func__); break; case AFI_UNSPEC: DEBUGD(&pbr_dbg_zebra, - "%s: Asked to delete unspecified route type", - __PRETTY_FUNCTION__); + "%s: Asked to delete unspecified route type", __func__); break; } } @@ -418,16 +407,15 @@ static int pbr_zebra_nexthop_update(ZAPI_CALLBACK_ARGS) if (DEBUG_MODE_CHECK(&pbr_dbg_zebra, DEBUG_MODE_ALL)) { DEBUGD(&pbr_dbg_zebra, "%s: Received Nexthop update: %s", - __PRETTY_FUNCTION__, - prefix2str(&nhr.prefix, buf, sizeof(buf))); + __func__, prefix2str(&nhr.prefix, buf, sizeof(buf))); - DEBUGD(&pbr_dbg_zebra, "%s: (\tNexthops(%u)", - __PRETTY_FUNCTION__, nhr.nexthop_num); + DEBUGD(&pbr_dbg_zebra, "%s: (\tNexthops(%u)", __func__, + nhr.nexthop_num); for (i = 0; i < nhr.nexthop_num; i++) { DEBUGD(&pbr_dbg_zebra, "%s: \tType: %d: vrf: %d, ifindex: %d gate: %s", - __PRETTY_FUNCTION__, nhr.nexthops[i].type, + __func__, nhr.nexthops[i].type, nhr.nexthops[i].vrf_id, nhr.nexthops[i].ifindex, inet_ntoa(nhr.nexthops[i].gate.ipv4)); } @@ -490,8 +478,7 @@ void pbr_send_rnh(struct nexthop *nhop, bool reg) if (zclient_send_rnh(zclient, command, &p, false, nhop->vrf_id) < 0) { - zlog_warn("%s: Failure to send nexthop to zebra", - __PRETTY_FUNCTION__); + zlog_warn("%s: Failure to send nexthop to zebra", __func__); } } @@ -569,8 +556,8 @@ void pbr_send_pbr_map(struct pbr_map_sequence *pbrms, is_installed &= pbrms->installed; - DEBUGD(&pbr_dbg_zebra, "%s: for %s %d(%" PRIu64 ")", - __PRETTY_FUNCTION__, pbrm->name, install, is_installed); + DEBUGD(&pbr_dbg_zebra, "%s: for %s %d(%" PRIu64 ")", __func__, + pbrm->name, install, is_installed); /* * If we are installed and asked to do so again @@ -595,9 +582,9 @@ void pbr_send_pbr_map(struct pbr_map_sequence *pbrms, */ stream_putl(s, 1); - DEBUGD(&pbr_dbg_zebra, "%s: \t%s %s %d %s %u", - __PRETTY_FUNCTION__, install ? "Installing" : "Deleting", - pbrm->name, install, pmi->ifp->name, pmi->delete); + DEBUGD(&pbr_dbg_zebra, "%s: \t%s %s %d %s %u", __func__, + install ? "Installing" : "Deleting", pbrm->name, install, + pmi->ifp->name, pmi->delete); pbr_encode_pbr_map_sequence(s, pbrms, pmi->ifp); diff --git a/pimd/pim_assert.c b/pimd/pim_assert.c index 53ab22754c..957f904714 100644 --- a/pimd/pim_assert.c +++ b/pimd/pim_assert.c @@ -56,7 +56,7 @@ void pim_ifassert_winner_set(struct pim_ifchannel *ch, if (ch->ifassert_state != new_state) { zlog_debug( "%s: (S,G)=%s assert state changed from %s to %s on interface %s", - __PRETTY_FUNCTION__, ch->sg_str, + __func__, ch->sg_str, pim_ifchannel_ifassert_name(ch->ifassert_state), pim_ifchannel_ifassert_name(new_state), ch->interface->name); @@ -71,8 +71,8 @@ void pim_ifassert_winner_set(struct pim_ifchannel *ch, sizeof(winner_str)); zlog_debug( "%s: (S,G)=%s assert winner changed from %s to %s on interface %s", - __PRETTY_FUNCTION__, ch->sg_str, was_str, - winner_str, ch->interface->name); + __func__, ch->sg_str, was_str, winner_str, + ch->interface->name); } } /* PIM_DEBUG_PIM_EVENTS */ @@ -130,7 +130,7 @@ static void if_could_assert_do_a1(const char *caller, struct pim_ifchannel *ch) if (assert_action_a1(ch)) { zlog_warn( "%s: %s: (S,G)=%s assert_action_a1 failure on interface %s", - __PRETTY_FUNCTION__, caller, ch->sg_str, + __func__, caller, ch->sg_str, ch->interface->name); /* log warning only */ } @@ -153,12 +153,12 @@ static int dispatch_assert(struct interface *ifp, struct in_addr source_addr, case PIM_IFASSERT_NOINFO: if (recv_metric.rpt_bit_flag) { /* RPT bit set */ - if_could_assert_do_a1(__PRETTY_FUNCTION__, ch); + if_could_assert_do_a1(__func__, ch); } else { /* RPT bit clear */ if (inferior_assert(&ch->ifassert_my_metric, &recv_metric)) { - if_could_assert_do_a1(__PRETTY_FUNCTION__, ch); + if_could_assert_do_a1(__func__, ch); } else if (acceptable_assert(&ch->ifassert_my_metric, &recv_metric)) { if (PIM_IF_FLAG_TEST_ASSERT_TRACKING_DESIRED( @@ -205,8 +205,7 @@ static int dispatch_assert(struct interface *ifp, struct in_addr source_addr, default: { zlog_warn( "%s: (S,G)=%s invalid assert state %d on interface %s", - __PRETTY_FUNCTION__, ch->sg_str, ch->ifassert_state, - ifp->name); + __func__, ch->sg_str, ch->ifassert_state, ifp->name); } return -2; } @@ -225,7 +224,7 @@ int pim_assert_recv(struct interface *ifp, struct pim_neighbor *neigh, int curr_size; struct pim_interface *pim_ifp = NULL; - on_trace(__PRETTY_FUNCTION__, ifp, src_addr); + on_trace(__func__, ifp, src_addr); curr = buf; curr_size = buf_size; @@ -239,7 +238,7 @@ int pim_assert_recv(struct interface *ifp, struct pim_neighbor *neigh, char src_str[INET_ADDRSTRLEN]; pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str)); zlog_warn("%s: pim_parse_addr_group() failure: from %s on %s", - __PRETTY_FUNCTION__, src_str, ifp->name); + __func__, src_str, ifp->name); return -1; } curr += offset; @@ -253,7 +252,7 @@ int pim_assert_recv(struct interface *ifp, struct pim_neighbor *neigh, char src_str[INET_ADDRSTRLEN]; pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str)); zlog_warn("%s: pim_parse_addr_ucast() failure: from %s on %s", - __PRETTY_FUNCTION__, src_str, ifp->name); + __func__, src_str, ifp->name); return -2; } curr += offset; @@ -264,7 +263,7 @@ int pim_assert_recv(struct interface *ifp, struct pim_neighbor *neigh, pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str)); zlog_warn( "%s: preference/metric size is less than 8 bytes: size=%d from %s on interface %s", - __PRETTY_FUNCTION__, curr_size, src_str, ifp->name); + __func__, curr_size, src_str, ifp->name); return -3; } @@ -297,9 +296,8 @@ int pim_assert_recv(struct interface *ifp, struct pim_neighbor *neigh, pim_inet4_dump("<grp?>", sg.grp, group_str, sizeof(group_str)); zlog_debug( "%s: from %s on %s: (S,G)=(%s,%s) pref=%u metric=%u rpt_bit=%u", - __PRETTY_FUNCTION__, neigh_str, ifp->name, source_str, - group_str, msg_metric.metric_preference, - msg_metric.route_metric, + __func__, neigh_str, ifp->name, source_str, group_str, + msg_metric.metric_preference, msg_metric.route_metric, PIM_FORCE_BOOLEAN(msg_metric.rpt_bit_flag)); } @@ -380,7 +378,7 @@ int pim_assert_build_msg(uint8_t *pim_msg, int buf_size, struct interface *ifp, sizeof(group_str)); zlog_warn( "%s: failure encoding group address %s: space left=%d", - __PRETTY_FUNCTION__, group_str, remain); + __func__, group_str, remain); return -1; } @@ -394,7 +392,7 @@ int pim_assert_build_msg(uint8_t *pim_msg, int buf_size, struct interface *ifp, sizeof(source_str)); zlog_warn( "%s: failure encoding source address %s: space left=%d", - __PRETTY_FUNCTION__, source_str, remain); + __func__, source_str, remain); return -2; } @@ -429,7 +427,7 @@ static int pim_assert_do(struct pim_ifchannel *ch, if (!ifp) { if (PIM_DEBUG_PIM_TRACE) zlog_debug("%s: channel%s has no associated interface!", - __PRETTY_FUNCTION__, ch->sg_str); + __func__, ch->sg_str); return -1; } pim_ifp = ifp->info; @@ -437,7 +435,7 @@ static int pim_assert_do(struct pim_ifchannel *ch, if (PIM_DEBUG_PIM_TRACE) zlog_debug( "%s: channel %s pim not enabled on interface: %s", - __PRETTY_FUNCTION__, ch->sg_str, ifp->name); + __func__, ch->sg_str, ifp->name); return -1; } @@ -448,7 +446,7 @@ static int pim_assert_do(struct pim_ifchannel *ch, if (pim_msg_size < 1) { zlog_warn( "%s: failure building PIM assert message: msg_size=%d", - __PRETTY_FUNCTION__, pim_msg_size); + __func__, pim_msg_size); return -2; } @@ -465,7 +463,7 @@ static int pim_assert_do(struct pim_ifchannel *ch, if (PIM_DEBUG_PIM_TRACE) { zlog_debug("%s: to %s: (S,G)=%s pref=%u metric=%u rpt_bit=%u", - __PRETTY_FUNCTION__, ifp->name, ch->sg_str, + __func__, ifp->name, ch->sg_str, metric.metric_preference, metric.route_metric, PIM_FORCE_BOOLEAN(metric.rpt_bit_flag)); } @@ -475,7 +473,7 @@ static int pim_assert_do(struct pim_ifchannel *ch, qpim_all_pim_routers_addr, pim_msg, pim_msg_size, ifp->name)) { zlog_warn("%s: could not send PIM message on interface %s", - __PRETTY_FUNCTION__, ifp->name); + __func__, ifp->name); return -3; } @@ -516,7 +514,7 @@ static int on_assert_timer(struct thread *t) if (PIM_DEBUG_PIM_TRACE) { zlog_debug("%s: (S,G)=%s timer expired on interface %s", - __PRETTY_FUNCTION__, ch->sg_str, ifp->name); + __func__, ch->sg_str, ifp->name); } ch->t_ifassert_timer = NULL; @@ -532,8 +530,8 @@ static int on_assert_timer(struct thread *t) if (PIM_DEBUG_PIM_EVENTS) zlog_warn( "%s: (S,G)=%s invalid assert state %d on interface %s", - __PRETTY_FUNCTION__, ch->sg_str, - ch->ifassert_state, ifp->name); + __func__, ch->sg_str, ch->ifassert_state, + ifp->name); } } @@ -546,8 +544,7 @@ static void assert_timer_off(struct pim_ifchannel *ch) if (ch->t_ifassert_timer) { zlog_debug( "%s: (S,G)=%s cancelling timer on interface %s", - __PRETTY_FUNCTION__, ch->sg_str, - ch->interface->name); + __func__, ch->sg_str, ch->interface->name); } } THREAD_OFF(ch->t_ifassert_timer); @@ -559,8 +556,7 @@ static void pim_assert_timer_set(struct pim_ifchannel *ch, int interval) if (PIM_DEBUG_PIM_TRACE) { zlog_debug("%s: (S,G)=%s starting %u sec timer on interface %s", - __PRETTY_FUNCTION__, ch->sg_str, interval, - ch->interface->name); + __func__, ch->sg_str, interval, ch->interface->name); } thread_add_timer(router->master, on_assert_timer, ch, interval, @@ -591,7 +587,7 @@ int assert_action_a1(struct pim_ifchannel *ch) pim_ifp = ifp->info; if (!pim_ifp) { zlog_warn("%s: (S,G)=%s multicast not enabled on interface %s", - __PRETTY_FUNCTION__, ch->sg_str, ifp->name); + __func__, ch->sg_str, ifp->name); return -1; /* must return since pim_ifp is used below */ } @@ -604,7 +600,7 @@ int assert_action_a1(struct pim_ifchannel *ch) if (assert_action_a3(ch)) { zlog_warn( "%s: (S,G)=%s assert_action_a3 failure on interface %s", - __PRETTY_FUNCTION__, ch->sg_str, ifp->name); + __func__, ch->sg_str, ifp->name); /* warning only */ } @@ -612,7 +608,7 @@ int assert_action_a1(struct pim_ifchannel *ch) if (PIM_DEBUG_PIM_EVENTS) zlog_warn( "%s: channel%s not in expected PIM_IFASSERT_I_AM_WINNER state", - __PRETTY_FUNCTION__, ch->sg_str); + __func__, ch->sg_str); } return 0; @@ -639,7 +635,7 @@ static void assert_action_a2(struct pim_ifchannel *ch, if (PIM_DEBUG_PIM_EVENTS) zlog_warn( "%s: channel%s not in expected PIM_IFASSERT_I_AM_LOSER state", - __PRETTY_FUNCTION__, ch->sg_str); + __func__, ch->sg_str); } } @@ -657,7 +653,7 @@ static int assert_action_a3(struct pim_ifchannel *ch) if (PIM_DEBUG_PIM_EVENTS) zlog_warn( "%s: channel%s expected to be in PIM_IFASSERT_I_AM_WINNER state", - __PRETTY_FUNCTION__, ch->sg_str); + __func__, ch->sg_str); return -1; } @@ -665,7 +661,7 @@ static int assert_action_a3(struct pim_ifchannel *ch) if (pim_assert_send(ch)) { zlog_warn("%s: (S,G)=%s failure sending assert on interface %s", - __PRETTY_FUNCTION__, ch->sg_str, ch->interface->name); + __func__, ch->sg_str, ch->interface->name); return -1; } @@ -686,7 +682,7 @@ void assert_action_a4(struct pim_ifchannel *ch) { if (pim_assert_cancel(ch)) { zlog_warn("%s: failure sending AssertCancel%s on interface %s", - __PRETTY_FUNCTION__, ch->sg_str, ch->interface->name); + __func__, ch->sg_str, ch->interface->name); /* log warning only */ } @@ -696,7 +692,7 @@ void assert_action_a4(struct pim_ifchannel *ch) if (PIM_DEBUG_PIM_EVENTS) zlog_warn( "%s: channel%s not in PIM_IFASSERT_NOINFO state as expected", - __PRETTY_FUNCTION__, ch->sg_str); + __func__, ch->sg_str); } } @@ -715,7 +711,7 @@ void assert_action_a5(struct pim_ifchannel *ch) if (PIM_DEBUG_PIM_EVENTS) zlog_warn( "%s: channel%s not in PIM_IFSSERT_NOINFO state as expected", - __PRETTY_FUNCTION__, ch->sg_str); + __func__, ch->sg_str); } } @@ -747,6 +743,6 @@ static void assert_action_a6(struct pim_ifchannel *ch, if (PIM_DEBUG_PIM_EVENTS) zlog_warn( "%s: channel%s not in PIM_IFASSERT_I_AM_LOSER state as expected", - __PRETTY_FUNCTION__, ch->sg_str); + __func__, ch->sg_str); } } diff --git a/pimd/pim_bfd.c b/pimd/pim_bfd.c index 01a7980858..84f6733eaf 100644 --- a/pimd/pim_bfd.c +++ b/pimd/pim_bfd.c @@ -125,7 +125,7 @@ static void pim_bfd_reg_dereg_nbr(struct pim_neighbor *nbr, int command) char str[INET_ADDRSTRLEN]; pim_inet4_dump("<bfd_nbr?>", nbr->source_addr, str, sizeof(str)); - zlog_debug("%s Nbr %s %s with BFD", __PRETTY_FUNCTION__, str, + zlog_debug("%s Nbr %s %s with BFD", __func__, str, bfd_get_command_dbg_str(command)); } @@ -199,8 +199,8 @@ void pim_bfd_if_param_set(struct interface *ifp, uint32_t min_rx, if (pim_ifp->bfd_info) { if (PIM_DEBUG_PIM_TRACE) - zlog_debug("%s: interface %s has bfd_info", - __PRETTY_FUNCTION__, ifp->name); + zlog_debug("%s: interface %s has bfd_info", __func__, + ifp->name); } if (command) pim_bfd_reg_dereg_all_nbr(ifp, command); @@ -240,16 +240,15 @@ static int pim_bfd_interface_dest_update(ZAPI_CALLBACK_ARGS) if (!pim_ifp->bfd_info) { if (PIM_DEBUG_PIM_TRACE) zlog_debug("%s: pim interface %s BFD is disabled ", - __PRETTY_FUNCTION__, ifp->name); + __func__, ifp->name); return 0; } if (PIM_DEBUG_PIM_TRACE) { char buf[PREFIX2STR_BUFFER]; prefix2str(&p, buf, sizeof(buf)); - zlog_debug("%s: interface %s bfd destination %s %s", - __PRETTY_FUNCTION__, ifp->name, buf, - bfd_get_status_str(status)); + zlog_debug("%s: interface %s bfd destination %s %s", __func__, + ifp->name, buf, bfd_get_status_str(status)); } for (ALL_LIST_ELEMENTS(pim_ifp->pim_neighbor_list, neigh_node, @@ -265,7 +264,7 @@ static int pim_bfd_interface_dest_update(ZAPI_CALLBACK_ARGS) pim_inet4_dump("<nht_nbr?>", neigh->source_addr, str, sizeof(str)); zlog_debug("%s: bfd status is same for nbr %s", - __PRETTY_FUNCTION__, str); + __func__, str); } continue; } @@ -275,8 +274,7 @@ static int pim_bfd_interface_dest_update(ZAPI_CALLBACK_ARGS) bfd_info->last_update = tv.tv_sec; if (PIM_DEBUG_PIM_TRACE) { - zlog_debug("%s: status %s old_status %s", - __PRETTY_FUNCTION__, + zlog_debug("%s: status %s old_status %s", __func__, bfd_get_status_str(status), bfd_get_status_str(old_status)); } @@ -328,8 +326,7 @@ static int pim_bfd_nbr_replay(ZAPI_CALLBACK_ARGS) sizeof(str)); zlog_debug( "%s: Replaying Pim Neigh %s to BFD vrf_id %u", - __PRETTY_FUNCTION__, str, - vrf->vrf_id); + __func__, str, vrf->vrf_id); } pim_bfd_reg_dereg_nbr(neigh, ZEBRA_BFD_DEST_UPDATE); diff --git a/pimd/pim_bsm.c b/pimd/pim_bsm.c index e14b7e058d..bcf11aedbd 100644 --- a/pimd/pim_bsm.c +++ b/pimd/pim_bsm.c @@ -145,8 +145,7 @@ static struct bsgrp_node *pim_bsm_new_bsgrp_node(struct route_table *rt, rn = route_node_get(rt, grp); if (!rn) { - zlog_warn("%s: route node creation failed", - __PRETTY_FUNCTION__); + zlog_warn("%s: route node creation failed", __func__); return NULL; } bsgrp = XCALLOC(MTYPE_PIM_BSGRP_NODE, sizeof(struct bsgrp_node)); @@ -180,7 +179,7 @@ static int pim_on_bs_timer(struct thread *t) if (PIM_DEBUG_BSM) zlog_debug("%s: Bootstrap Timer expired for scope: %d", - __PRETTY_FUNCTION__, scope->sz_id); + __func__, scope->sz_id); /* Remove next hop tracking for the bsr */ nht_p.family = AF_INET; @@ -189,7 +188,7 @@ static int pim_on_bs_timer(struct thread *t) if (PIM_DEBUG_BSM) { prefix2str(&nht_p, buf, sizeof(buf)); zlog_debug("%s: Deregister BSR addr %s with Zebra NHT", - __PRETTY_FUNCTION__, buf); + __func__, buf); } pim_delete_tracked_nexthop(scope->pim, &nht_p, NULL, NULL, is_bsr_tracking); @@ -209,8 +208,7 @@ static int pim_on_bs_timer(struct thread *t) bsgrp_node = (struct bsgrp_node *)rn->info; if (!bsgrp_node) { if (PIM_DEBUG_BSM) - zlog_debug("%s: bsgrp_node is null", - __PRETTY_FUNCTION__); + zlog_debug("%s: bsgrp_node is null", __func__); continue; } /* Give grace time for rp to continue for another hold time */ @@ -231,8 +229,8 @@ static int pim_on_bs_timer(struct thread *t) static void pim_bs_timer_stop(struct bsm_scope *scope) { if (PIM_DEBUG_BSM) - zlog_debug("%s : BS timer being stopped of sz: %d", - __PRETTY_FUNCTION__, scope->sz_id); + zlog_debug("%s : BS timer being stopped of sz: %d", __func__, + scope->sz_id); THREAD_OFF(scope->bs_timer); } @@ -240,14 +238,14 @@ static void pim_bs_timer_start(struct bsm_scope *scope, int bs_timeout) { if (!scope) { if (PIM_DEBUG_BSM) - zlog_debug("%s : Invalid scope(NULL).", - __PRETTY_FUNCTION__); + zlog_debug("%s : Invalid scope(NULL).", __func__); return; } THREAD_OFF(scope->bs_timer); if (PIM_DEBUG_BSM) - zlog_debug("%s : starting bs timer for scope %d with timeout %d secs", - __PRETTY_FUNCTION__, scope->sz_id, bs_timeout); + zlog_debug( + "%s : starting bs timer for scope %d with timeout %d secs", + __func__, scope->sz_id, bs_timeout); thread_add_timer(router->master, pim_on_bs_timer, scope, bs_timeout, &scope->bs_timer); } @@ -337,7 +335,7 @@ static int pim_on_g2rp_timer(struct thread *t) rn = route_node_lookup(pim->rp_table, &bsgrp_node->group); if (!rn) { - zlog_warn("%s: Route node doesn't exist", __PRETTY_FUNCTION__); + zlog_warn("%s: Route node doesn't exist", __func__); return 0; } @@ -376,8 +374,7 @@ static void pim_g2rp_timer_start(struct bsm_rpinfo *bsrp, int hold_time) { if (!bsrp) { if (PIM_DEBUG_BSM) - zlog_debug("%s : Invalid brsp(NULL).", - __PRETTY_FUNCTION__); + zlog_debug("%s : Invalid brsp(NULL).", __func__); return; } THREAD_OFF(bsrp->g2rp_timer); @@ -386,8 +383,7 @@ static void pim_g2rp_timer_start(struct bsm_rpinfo *bsrp, int hold_time) zlog_debug( "%s : starting g2rp timer for grp: %s - rp: %s with timeout %d secs(Actual Hold time : %d secs)", - __PRETTY_FUNCTION__, - prefix2str(&bsrp->bsgrp_node->group, buf, 48), + __func__, prefix2str(&bsrp->bsgrp_node->group, buf, 48), inet_ntoa(bsrp->rp_address), hold_time, bsrp->rp_holdtime); } @@ -411,7 +407,7 @@ static void pim_g2rp_timer_stop(struct bsm_rpinfo *bsrp) char buf[48]; zlog_debug("%s : stopping g2rp timer for grp: %s - rp: %s", - __PRETTY_FUNCTION__, + __func__, prefix2str(&bsrp->bsgrp_node->group, buf, 48), inet_ntoa(bsrp->rp_address)); } @@ -466,8 +462,7 @@ static void pim_instate_pend_list(struct bsgrp_node *bsgrp_node) if (!rn || (prefix_same(&rp_all->group, &bsgrp_node->group) && pim_rpf_addr_is_inaddr_none(&rp_all->rp))) { if (PIM_DEBUG_BSM) - zlog_debug("%s: Route node doesn't exist", - __PRETTY_FUNCTION__); + zlog_debug("%s: Route node doesn't exist", __func__); if (pend) pim_rp_new(pim, pend->rp_address, bsgrp_node->group, NULL, RP_SRC_BSR); @@ -507,7 +502,7 @@ static void pim_instate_pend_list(struct bsgrp_node *bsgrp_node) if (PIM_DEBUG_BSM) { zlog_debug( "%s: Both bsrp and partial list are empty", - __PRETTY_FUNCTION__); + __func__); } pim_free_bsgrp_node(bsgrp_node->scope->bsrp_table, &bsgrp_node->group); @@ -523,7 +518,7 @@ static void pim_instate_pend_list(struct bsgrp_node *bsgrp_node) &bsgrp_node->group); if (PIM_DEBUG_BSM) { zlog_debug("%s:Pend List is null,del grp node", - __PRETTY_FUNCTION__); + __func__); } pim_free_bsgrp_data(bsgrp_node); return; @@ -540,7 +535,7 @@ static void pim_instate_pend_list(struct bsgrp_node *bsgrp_node) if (PIM_DEBUG_BSM) zlog_debug( "%s: Partial list is empty, static rp exists", - __PRETTY_FUNCTION__); + __func__); pim_free_bsgrp_node(bsgrp_node->scope->bsrp_table, &bsgrp_node->group); pim_free_bsgrp_data(bsgrp_node); @@ -587,8 +582,8 @@ static bool pim_bsr_rpf_check(struct pim_instance *pim, struct in_addr bsr, char bsr_str[INET_ADDRSTRLEN]; pim_inet4_dump("<bsr?>", bsr, bsr_str, sizeof(bsr_str)); - zlog_debug("%s : No route to BSR address %s", - __PRETTY_FUNCTION__, bsr_str); + zlog_debug("%s : No route to BSR address %s", __func__, + bsr_str); } return false; } @@ -634,7 +629,7 @@ static void pim_bsm_update(struct pim_instance *pim, struct in_addr bsr, prefix2str(&nht_p, buf, sizeof(buf)); zlog_debug( "%s: Deregister BSR addr %s with Zebra NHT", - __PRETTY_FUNCTION__, buf); + __func__, buf); } pim_delete_tracked_nexthop(pim, &nht_p, NULL, NULL, is_bsr_tracking); @@ -645,7 +640,7 @@ static void pim_bsm_update(struct pim_instance *pim, struct in_addr bsr, prefix2str(&nht_p, buf, sizeof(buf)); zlog_debug( "%s: NHT Register BSR addr %s with Zebra NHT", - __PRETTY_FUNCTION__, buf); + __func__, buf); } memset(&pnc, 0, sizeof(struct pim_nexthop_cache)); @@ -670,21 +665,21 @@ static bool pim_bsm_send_intf(uint8_t *buf, int len, struct interface *ifp, if (!pim_ifp) { if (PIM_DEBUG_BSM) zlog_debug("%s: Pim interface not available for %s", - __PRETTY_FUNCTION__, ifp->name); + __func__, ifp->name); return false; } if (pim_ifp->pim_sock_fd == -1) { if (PIM_DEBUG_BSM) zlog_debug("%s: Pim sock not available for %s", - __PRETTY_FUNCTION__, ifp->name); + __func__, ifp->name); return false; } if (pim_msg_send(pim_ifp->pim_sock_fd, pim_ifp->primary_address, dst_addr, buf, len, ifp->name)) { zlog_warn("%s: Could not send BSM message on interface: %s", - __PRETTY_FUNCTION__, ifp->name); + __func__, ifp->name); return false; } @@ -715,11 +710,11 @@ static bool pim_bsm_frag_send(uint8_t *buf, uint32_t len, struct interface *ifp, if (pim_mtu < (PIM_MIN_BSM_LEN)) { zlog_warn( "%s: mtu(pim mtu: %d) size less than minimum bootstrap len", - __PRETTY_FUNCTION__, pim_mtu); + __func__, pim_mtu); if (PIM_DEBUG_BSM) zlog_debug( "%s: mtu (pim mtu:%d) less than minimum bootstrap len", - __PRETTY_FUNCTION__, pim_mtu); + __func__, pim_mtu); return false; } @@ -886,8 +881,7 @@ static void pim_bsm_fwd_whole_sz(struct pim_instance *pim, uint8_t *buf, dst_addr, no_fwd); if (PIM_DEBUG_BSM) zlog_debug("%s: pim_bsm_frag_send returned %s", - __PRETTY_FUNCTION__, - ret ? "TRUE" : "FALSE"); + __func__, ret ? "TRUE" : "FALSE"); } else { pim_msg_build_header(buf, len, PIM_MSG_TYPE_BOOTSTRAP, no_fwd); @@ -895,7 +889,7 @@ static void pim_bsm_fwd_whole_sz(struct pim_instance *pim, uint8_t *buf, if (PIM_DEBUG_BSM) zlog_debug( "%s: pim_bsm_send_intf returned false", - __PRETTY_FUNCTION__); + __func__); } } } @@ -916,8 +910,8 @@ bool pim_bsm_new_nbr_fwd(struct pim_neighbor *neigh, struct interface *ifp) if (PIM_DEBUG_BSM) { pim_inet4_dump("<src?>", neigh->source_addr, neigh_src_str, sizeof(neigh_src_str)); - zlog_debug("%s: New neighbor %s seen on %s", - __PRETTY_FUNCTION__, neigh_src_str, ifp->name); + zlog_debug("%s: New neighbor %s seen on %s", __func__, + neigh_src_str, ifp->name); } pim_ifp = ifp->info; @@ -927,13 +921,13 @@ bool pim_bsm_new_nbr_fwd(struct pim_neighbor *neigh, struct interface *ifp) if (PIM_DEBUG_BSM) zlog_debug( "%s: It is not DR, so don't forward BSM packet", - __PRETTY_FUNCTION__); + __func__); } if (!pim_ifp->bsm_enable) { if (PIM_DEBUG_BSM) - zlog_debug("%s: BSM proc not enabled on %s", - __PRETTY_FUNCTION__, ifp->name); + zlog_debug("%s: BSM proc not enabled on %s", __func__, + ifp->name); return ret; } @@ -942,20 +936,20 @@ bool pim_bsm_new_nbr_fwd(struct pim_neighbor *neigh, struct interface *ifp) if (!scope->bsm_list->count) { if (PIM_DEBUG_BSM) zlog_debug("%s: BSM list for the scope is empty", - __PRETTY_FUNCTION__); + __func__); return ret; } if (!pim_ifp->ucast_bsm_accept) { dst_addr = qpim_all_pim_routers_addr; if (PIM_DEBUG_BSM) - zlog_debug("%s: Sending BSM mcast to %s", - __PRETTY_FUNCTION__, neigh_src_str); + zlog_debug("%s: Sending BSM mcast to %s", __func__, + neigh_src_str); } else { dst_addr = neigh->source_addr; if (PIM_DEBUG_BSM) - zlog_debug("%s: Sending BSM ucast to %s", - __PRETTY_FUNCTION__, neigh_src_str); + zlog_debug("%s: Sending BSM ucast to %s", __func__, + neigh_src_str); } pim_mtu = ifp->mtu - MAX_IP_HDR_LEN; pim_hello_require(ifp); @@ -968,7 +962,7 @@ bool pim_bsm_new_nbr_fwd(struct pim_neighbor *neigh, struct interface *ifp) if (PIM_DEBUG_BSM) zlog_debug( "%s: pim_bsm_frag_send failed", - __PRETTY_FUNCTION__); + __func__); } } else { /* Pim header needs to be constructed */ @@ -980,7 +974,7 @@ bool pim_bsm_new_nbr_fwd(struct pim_neighbor *neigh, struct interface *ifp) if (PIM_DEBUG_BSM) zlog_debug( "%s: pim_bsm_frag_send failed", - __PRETTY_FUNCTION__); + __func__); } } } @@ -997,7 +991,7 @@ struct bsgrp_node *pim_bsm_get_bsgrp_node(struct bsm_scope *scope, if (!rn) { if (PIM_DEBUG_BSM) zlog_debug("%s: Route node doesn't exist for the group", - __PRETTY_FUNCTION__); + __func__); return NULL; } bsgrp = rn->info; @@ -1063,12 +1057,12 @@ static bool pim_install_bsm_grp_rp(struct pim_instance *pim, if (PIM_DEBUG_BSM) zlog_debug( "%s, bs_rpinfo node added to the partial bs_rplist.\r\n", - __PRETTY_FUNCTION__); + __func__); return true; } if (PIM_DEBUG_BSM) - zlog_debug("%s: list node not added\n", __PRETTY_FUNCTION__); + zlog_debug("%s: list node not added\n", __func__); XFREE(MTYPE_PIM_BSRP_NODE, bsm_rpinfo); return false; @@ -1087,7 +1081,7 @@ static void pim_update_pending_rp_cnt(struct bsm_scope *sz, if (PIM_DEBUG_BSM) zlog_debug( "%s,Received a new BSM ,so clear the pending bs_rpinfo list.\r\n", - __PRETTY_FUNCTION__); + __func__); list_delete_all_node(bsgrp->partial_bsrp_list); bsgrp->pend_rp_cnt = total_rp_count; } @@ -1114,7 +1108,7 @@ static bool pim_bsm_parse_install_g2rp(struct bsm_scope *scope, uint8_t *buf, if (PIM_DEBUG_BSM) zlog_debug( "%s: buflen received %d is less than the internal data structure of the packet would suggest", - __PRETTY_FUNCTION__, buflen); + __func__, buflen); return false; } /* Extract Group tlv from BSM */ @@ -1127,7 +1121,7 @@ static bool pim_bsm_parse_install_g2rp(struct bsm_scope *scope, uint8_t *buf, sizeof(grp_str)); zlog_debug( "%s, Group %s Rpcount:%d Fragment-Rp-count:%d\r\n", - __PRETTY_FUNCTION__, grp_str, grpinfo.rp_count, + __func__, grp_str, grpinfo.rp_count, grpinfo.frag_rp_count); } @@ -1142,7 +1136,7 @@ static bool pim_bsm_parse_install_g2rp(struct bsm_scope *scope, uint8_t *buf, grp_str, sizeof(grp_str)); zlog_debug( "%s, Rp count is zero for group: %s\r\n", - __PRETTY_FUNCTION__, grp_str); + __func__, grp_str); } return false; } @@ -1150,8 +1144,9 @@ static bool pim_bsm_parse_install_g2rp(struct bsm_scope *scope, uint8_t *buf, group.family = AF_INET; if (grpinfo.group.mask > IPV4_MAX_BITLEN) { if (PIM_DEBUG_BSM) - zlog_debug("%s, v4 prefix length specified: %d is too long", - __PRETTY_FUNCTION__, grpinfo.group.mask); + zlog_debug( + "%s, v4 prefix length specified: %d is too long", + __func__, grpinfo.group.mask); return false; } group.prefixlen = grpinfo.group.mask; @@ -1164,7 +1159,7 @@ static bool pim_bsm_parse_install_g2rp(struct bsm_scope *scope, uint8_t *buf, if (PIM_DEBUG_BSM) zlog_debug( "%s, Create new BSM Group node.\r\n", - __PRETTY_FUNCTION__); + __func__); /* create a new node to be added to the tree. */ bsgrp = pim_bsm_new_bsgrp_node(scope->bsrp_table, @@ -1173,7 +1168,7 @@ static bool pim_bsm_parse_install_g2rp(struct bsm_scope *scope, uint8_t *buf, if (!bsgrp) { zlog_debug( "%s, Failed to get the BSM group node.\r\n", - __PRETTY_FUNCTION__); + __func__); continue; } @@ -1191,7 +1186,7 @@ static bool pim_bsm_parse_install_g2rp(struct bsm_scope *scope, uint8_t *buf, if (PIM_DEBUG_BSM) zlog_debug( "%s, buflen received: %u is less than the internal data structure of the packet would suggest", - __PRETTY_FUNCTION__, buflen); + __func__, buflen); return false; } @@ -1208,8 +1203,8 @@ static bool pim_bsm_parse_install_g2rp(struct bsm_scope *scope, uint8_t *buf, rp_str, sizeof(rp_str)); zlog_debug( "%s, Rp address - %s; pri:%d hold:%d\r\n", - __PRETTY_FUNCTION__, rp_str, - rpinfo.rp_pri, rpinfo.rp_holdtime); + __func__, rp_str, rpinfo.rp_pri, + rpinfo.rp_holdtime); } /* Call Install api to update grp-rp mappings */ @@ -1223,7 +1218,7 @@ static bool pim_bsm_parse_install_g2rp(struct bsm_scope *scope, uint8_t *buf, if (PIM_DEBUG_BSM) zlog_debug( "%s, Recvd all the rps for this group, so bsrp list with penidng rp list.", - __PRETTY_FUNCTION__); + __func__); /* replace the bsrp_list with pending list */ pim_instate_pend_list(bsgrp); } @@ -1249,7 +1244,7 @@ int pim_bsm_process(struct interface *ifp, struct ip *ip_hdr, uint8_t *buf, if (!pim_ifp) { if (PIM_DEBUG_BSM) zlog_debug("%s: multicast not enabled on interface %s", - __PRETTY_FUNCTION__, ifp->name); + __func__, ifp->name); return -1; } @@ -1259,8 +1254,8 @@ int pim_bsm_process(struct interface *ifp, struct ip *ip_hdr, uint8_t *buf, /* Drop if bsm processing is disabled on interface */ if (!pim_ifp->bsm_enable) { - zlog_warn("%s: BSM not enabled on interface %s", - __PRETTY_FUNCTION__, ifp->name); + zlog_warn("%s: BSM not enabled on interface %s", __func__, + ifp->name); pim_ifp->pim_ifstat_bsm_cfg_miss++; pim->bsm_dropped++; return -1; @@ -1268,8 +1263,9 @@ int pim_bsm_process(struct interface *ifp, struct ip *ip_hdr, uint8_t *buf, if (buf_size < (PIM_MSG_HEADER_LEN + sizeof(struct bsm_hdr))) { if (PIM_DEBUG_BSM) - zlog_debug("%s: received buffer length of %d which is too small to properly decode", - __PRETTY_FUNCTION__, buf_size); + zlog_debug( + "%s: received buffer length of %d which is too small to properly decode", + __func__, buf_size); return -1; } @@ -1291,7 +1287,7 @@ int pim_bsm_process(struct interface *ifp, struct ip *ip_hdr, uint8_t *buf, if (PIM_DEBUG_BSM) zlog_debug( "%s : Administratively scoped range BSM received", - __PRETTY_FUNCTION__); + __func__); pim_ifp->pim_ifstat_bsm_invalid_sz++; pim->bsm_dropped++; return -1; @@ -1302,7 +1298,7 @@ int pim_bsm_process(struct interface *ifp, struct ip *ip_hdr, uint8_t *buf, if (!is_preferred_bsr(pim, bshdr->bsr_addr.addr, bshdr->bsr_prio)) { if (PIM_DEBUG_BSM) zlog_debug("%s : Received a non-preferred BSM", - __PRETTY_FUNCTION__); + __func__); pim->bsm_dropped++; return -1; } @@ -1316,7 +1312,7 @@ int pim_bsm_process(struct interface *ifp, struct ip *ip_hdr, uint8_t *buf, if (PIM_DEBUG_BSM) zlog_debug( "%s : nofwd_bsm received on %s when accpt_nofwd_bsm false", - __PRETTY_FUNCTION__, bsr_str); + __func__, bsr_str); pim->bsm_dropped++; pim_ifp->pim_ifstat_ucast_bsm_cfg_miss++; return -1; @@ -1331,7 +1327,7 @@ int pim_bsm_process(struct interface *ifp, struct ip *ip_hdr, uint8_t *buf, if (PIM_DEBUG_BSM) zlog_debug( "%s : RPF check fail for BSR address %s", - __PRETTY_FUNCTION__, bsr_str); + __func__, bsr_str); pim->bsm_dropped++; return -1; } @@ -1345,7 +1341,7 @@ int pim_bsm_process(struct interface *ifp, struct ip *ip_hdr, uint8_t *buf, if (PIM_DEBUG_BSM) zlog_debug( "%s : Unicast BSM not enabled on interface %s", - __PRETTY_FUNCTION__, ifp->name); + __func__, ifp->name); pim_ifp->pim_ifstat_ucast_bsm_cfg_miss++; pim->bsm_dropped++; return -1; @@ -1354,15 +1350,14 @@ int pim_bsm_process(struct interface *ifp, struct ip *ip_hdr, uint8_t *buf, } else { if (PIM_DEBUG_BSM) zlog_debug("%s : Invalid destination address", - __PRETTY_FUNCTION__); + __func__); pim->bsm_dropped++; return -1; } if (empty_bsm) { if (PIM_DEBUG_BSM) - zlog_debug("%s : Empty Pref BSM received", - __PRETTY_FUNCTION__); + zlog_debug("%s : Empty Pref BSM received", __func__); } /* Parse Update bsm rp table and install/uninstall rp if required */ if (!pim_bsm_parse_install_g2rp( @@ -1371,8 +1366,7 @@ int pim_bsm_process(struct interface *ifp, struct ip *ip_hdr, uint8_t *buf, (buf_size - PIM_BSM_HDR_LEN - PIM_MSG_HEADER_LEN), frag_tag)) { if (PIM_DEBUG_BSM) { - zlog_debug("%s, Parsing BSM failed.\r\n", - __PRETTY_FUNCTION__); + zlog_debug("%s, Parsing BSM failed.\r\n", __func__); } pim->bsm_dropped++; return -1; @@ -1385,7 +1379,7 @@ int pim_bsm_process(struct interface *ifp, struct ip *ip_hdr, uint8_t *buf, if (pim_ifp->pim->global_scope.bsm_frag_tag != frag_tag) { if (PIM_DEBUG_BSM) { zlog_debug("%s: Current frag tag: %d Frag teg rcvd: %d", - __PRETTY_FUNCTION__, + __func__, pim_ifp->pim->global_scope.bsm_frag_tag, frag_tag); } diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 6508fb4453..7e24d924a4 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -166,7 +166,7 @@ static void pim_if_membership_refresh(struct interface *ifp) sg.src = src->source_addr; sg.grp = grp->group_addr; pim_ifchannel_local_membership_add(ifp, - &sg); + &sg, false /*is_vxlan*/); } } /* scan group sources */ @@ -909,7 +909,7 @@ static void igmp_show_interface_join(struct pim_instance *pim, struct vty *vty) static void pim_show_interfaces_single(struct pim_instance *pim, struct vty *vty, const char *ifname, - bool uj) + bool mlag, bool uj) { struct in_addr ifaddr; struct interface *ifp; @@ -952,6 +952,9 @@ static void pim_show_interfaces_single(struct pim_instance *pim, if (!pim_ifp) continue; + if (mlag == true && pim_ifp->activeactive == false) + continue; + if (strcmp(ifname, "detail") && strcmp(ifname, ifp->name)) continue; @@ -1380,7 +1383,7 @@ static void igmp_show_statistics(struct pim_instance *pim, struct vty *vty, } static void pim_show_interfaces(struct pim_instance *pim, struct vty *vty, - bool uj) + bool mlag, bool uj) { struct interface *ifp; struct pim_interface *pim_ifp; @@ -1400,6 +1403,9 @@ static void pim_show_interfaces(struct pim_instance *pim, struct vty *vty, if (!pim_ifp) continue; + if (mlag == true && pim_ifp->activeactive == false) + continue; + pim_nbrs = pim_ifp->pim_neighbor_list->count; pim_ifchannels = pim_if_ifchannel_count(pim_ifp); fhr = 0; @@ -3726,8 +3732,6 @@ static void pim_show_bsr(struct pim_instance *pim, char bsr_str[PREFIX_STRLEN]; json_object *json = NULL; - vty_out(vty, "PIMv2 Bootstrap information\n"); - if (pim->global_scope.current_bsr.s_addr == INADDR_ANY) { strlcpy(bsr_str, "0.0.0.0", sizeof(bsr_str)); pim_time_uptime(uptime, sizeof(uptime), @@ -3773,6 +3777,7 @@ static void pim_show_bsr(struct pim_instance *pim, } else { + vty_out(vty, "PIMv2 Bootstrap information\n"); vty_out(vty, "Current preferred BSR address: %s\n", bsr_str); vty_out(vty, "Priority Fragment-Tag State UpTime\n"); @@ -3927,7 +3932,7 @@ static void clear_mroute(struct pim_instance *pim) /* clean up all upstreams*/ while ((up = rb_pim_upstream_first(&pim->upstream_head))) { - pim_upstream_del(pim, up, __PRETTY_FUNCTION__); + pim_upstream_del(pim, up, __func__); } } @@ -4295,6 +4300,113 @@ DEFUN (show_ip_igmp_statistics, return CMD_SUCCESS; } +DEFUN (show_ip_pim_mlag_summary, + show_ip_pim_mlag_summary_cmd, + "show ip pim mlag summary [json]", + SHOW_STR + IP_STR + PIM_STR + "MLAG\n" + "status and stats\n" + JSON_STR) +{ + bool uj = use_json(argc, argv); + char role_buf[MLAG_ROLE_STRSIZE]; + char addr_buf[INET_ADDRSTRLEN]; + + if (uj) { + json_object *json = NULL; + json_object *json_stat = NULL; + + json = json_object_new_object(); + if (router->mlag_flags & PIM_MLAGF_LOCAL_CONN_UP) + json_object_boolean_true_add(json, "mlagConnUp"); + if (router->mlag_flags & PIM_MLAGF_PEER_CONN_UP) + json_object_boolean_true_add(json, "mlagPeerConnUp"); + if (router->mlag_flags & PIM_MLAGF_PEER_ZEBRA_UP) + json_object_boolean_true_add(json, "mlagPeerZebraUp"); + json_object_string_add(json, "mlagRole", + mlag_role2str(router->mlag_role, + role_buf, sizeof(role_buf))); + inet_ntop(AF_INET, &router->local_vtep_ip, + addr_buf, INET_ADDRSTRLEN); + json_object_string_add(json, "localVtepIp", addr_buf); + inet_ntop(AF_INET, &router->anycast_vtep_ip, + addr_buf, INET_ADDRSTRLEN); + json_object_string_add(json, "anycastVtepIp", addr_buf); + json_object_string_add(json, "peerlinkRif", + router->peerlink_rif); + + json_stat = json_object_new_object(); + json_object_int_add(json_stat, "mlagConnFlaps", + router->mlag_stats.mlagd_session_downs); + json_object_int_add(json_stat, "mlagPeerConnFlaps", + router->mlag_stats.peer_session_downs); + json_object_int_add(json_stat, "mlagPeerZebraFlaps", + router->mlag_stats.peer_zebra_downs); + json_object_int_add(json_stat, "mrouteAddRx", + router->mlag_stats.msg.mroute_add_rx); + json_object_int_add(json_stat, "mrouteAddTx", + router->mlag_stats.msg.mroute_add_tx); + json_object_int_add(json_stat, "mrouteDelRx", + router->mlag_stats.msg.mroute_del_rx); + json_object_int_add(json_stat, "mrouteDelTx", + router->mlag_stats.msg.mroute_del_tx); + json_object_int_add(json_stat, "mlagStatusUpdates", + router->mlag_stats.msg.mlag_status_updates); + json_object_int_add(json_stat, "peerZebraStatusUpdates", + router->mlag_stats.msg.peer_zebra_status_updates); + json_object_int_add(json_stat, "pimStatusUpdates", + router->mlag_stats.msg.pim_status_updates); + json_object_int_add(json_stat, "vxlanUpdates", + router->mlag_stats.msg.vxlan_updates); + json_object_object_add(json, "connStats", json_stat); + + vty_out(vty, "%s\n", json_object_to_json_string_ext( + json, JSON_C_TO_STRING_PRETTY)); + json_object_free(json); + return CMD_SUCCESS; + } + + vty_out(vty, "MLAG daemon connection: %s\n", + (router->mlag_flags & PIM_MLAGF_LOCAL_CONN_UP) + ? "up" : "down"); + vty_out(vty, "MLAG peer state: %s\n", + (router->mlag_flags & PIM_MLAGF_PEER_CONN_UP) + ? "up" : "down"); + vty_out(vty, "Zebra peer state: %s\n", + (router->mlag_flags & PIM_MLAGF_PEER_ZEBRA_UP) + ? "up" : "down"); + vty_out(vty, "MLAG role: %s\n", + mlag_role2str(router->mlag_role, role_buf, sizeof(role_buf))); + inet_ntop(AF_INET, &router->local_vtep_ip, + addr_buf, INET_ADDRSTRLEN); + vty_out(vty, "Local VTEP IP: %s\n", addr_buf); + inet_ntop(AF_INET, &router->anycast_vtep_ip, + addr_buf, INET_ADDRSTRLEN); + vty_out(vty, "Anycast VTEP IP: %s\n", addr_buf); + vty_out(vty, "Peerlink: %s\n", router->peerlink_rif); + vty_out(vty, "Session flaps: mlagd: %d mlag-peer: %d zebra-peer: %d\n", + router->mlag_stats.mlagd_session_downs, + router->mlag_stats.peer_session_downs, + router->mlag_stats.peer_zebra_downs); + vty_out(vty, "Message Statistics:\n"); + vty_out(vty, " mroute adds: rx: %d, tx: %d\n", + router->mlag_stats.msg.mroute_add_rx, + router->mlag_stats.msg.mroute_add_tx); + vty_out(vty, " mroute dels: rx: %d, tx: %d\n", + router->mlag_stats.msg.mroute_del_rx, + router->mlag_stats.msg.mroute_del_tx); + vty_out(vty, " peer zebra status updates: %d\n", + router->mlag_stats.msg.peer_zebra_status_updates); + vty_out(vty, " PIM status updates: %d\n", + router->mlag_stats.msg.pim_status_updates); + vty_out(vty, " VxLAN updates: %d\n", + router->mlag_stats.msg.vxlan_updates); + + return CMD_SUCCESS; +} + DEFUN (show_ip_pim_assert, show_ip_pim_assert_cmd, "show ip pim [vrf NAME] assert", @@ -4377,10 +4489,11 @@ DEFUN (show_ip_pim_assert_winner_metric, DEFUN (show_ip_pim_interface, show_ip_pim_interface_cmd, - "show ip pim [vrf NAME] interface [detail|WORD] [json]", + "show ip pim [mlag] [vrf NAME] interface [detail|WORD] [json]", SHOW_STR IP_STR PIM_STR + "MLAG\n" VRF_CMD_HELP_STR "PIM interface information\n" "Detailed output\n" @@ -4390,36 +4503,47 @@ DEFUN (show_ip_pim_interface, int idx = 2; struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); bool uj = use_json(argc, argv); + bool mlag = false; if (!vrf) return CMD_WARNING; + if (argv_find(argv, argc, "mlag", &idx)) + mlag = true; + if (argv_find(argv, argc, "WORD", &idx) || argv_find(argv, argc, "detail", &idx)) - pim_show_interfaces_single(vrf->info, vty, argv[idx]->arg, uj); + pim_show_interfaces_single(vrf->info, vty, argv[idx]->arg, mlag, + uj); else - pim_show_interfaces(vrf->info, vty, uj); + pim_show_interfaces(vrf->info, vty, mlag, uj); return CMD_SUCCESS; } DEFUN (show_ip_pim_interface_vrf_all, show_ip_pim_interface_vrf_all_cmd, - "show ip pim vrf all interface [detail|WORD] [json]", + "show ip pim [mlag] vrf all interface [detail|WORD] [json]", SHOW_STR IP_STR PIM_STR + "MLAG\n" VRF_CMD_HELP_STR "PIM interface information\n" "Detailed output\n" "interface name\n" JSON_STR) { - int idx = 6; + int idx = 2; bool uj = use_json(argc, argv); struct vrf *vrf; bool first = true; + bool mlag = false; + + if (argv_find(argv, argc, "mlag", &idx)) + mlag = true; + idx = 6; if (uj) vty_out(vty, "{ "); RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { @@ -4433,9 +4557,9 @@ DEFUN (show_ip_pim_interface_vrf_all, if (argv_find(argv, argc, "WORD", &idx) || argv_find(argv, argc, "detail", &idx)) pim_show_interfaces_single(vrf->info, vty, - argv[idx]->arg, uj); + argv[idx]->arg, mlag, uj); else - pim_show_interfaces(vrf->info, vty, uj); + pim_show_interfaces(vrf->info, vty, mlag, uj); } if (uj) vty_out(vty, "}\n"); @@ -4625,6 +4749,272 @@ DEFUN (show_ip_pim_local_membership, return CMD_SUCCESS; } +static void pim_show_mlag_up_entry_detail(struct vrf *vrf, + struct vty *vty, struct pim_upstream *up, + char *src_str, char *grp_str, json_object *json) +{ + if (json) { + json_object *json_row = NULL; + json_object *own_list = NULL; + json_object *json_group = NULL; + + + json_object_object_get_ex(json, grp_str, &json_group); + if (!json_group) { + json_group = json_object_new_object(); + json_object_object_add(json, grp_str, + json_group); + } + + json_row = json_object_new_object(); + json_object_string_add(json_row, "source", src_str); + json_object_string_add(json_row, "group", grp_str); + + own_list = json_object_new_array(); + if (pim_up_mlag_is_local(up)) + json_object_array_add(own_list, + json_object_new_string("local")); + if (up->flags & (PIM_UPSTREAM_FLAG_MASK_MLAG_PEER)) + json_object_array_add(own_list, + json_object_new_string("peer")); + if (up->flags & (PIM_UPSTREAM_FLAG_MASK_MLAG_INTERFACE)) + json_object_array_add( + own_list, json_object_new_string("Interface")); + json_object_object_add(json_row, "owners", own_list); + + json_object_int_add(json_row, "localCost", + pim_up_mlag_local_cost(up)); + json_object_int_add(json_row, "peerCost", + pim_up_mlag_peer_cost(up)); + if (PIM_UPSTREAM_FLAG_TEST_MLAG_NON_DF(up->flags)) + json_object_boolean_false_add(json_row, "df"); + else + json_object_boolean_true_add(json_row, "df"); + json_object_object_add(json_group, src_str, json_row); + } else { + char own_str[6]; + + own_str[0] = '\0'; + if (pim_up_mlag_is_local(up)) + strlcat(own_str, "L", sizeof(own_str)); + if (up->flags & (PIM_UPSTREAM_FLAG_MASK_MLAG_PEER)) + strlcat(own_str, "P", sizeof(own_str)); + if (up->flags & (PIM_UPSTREAM_FLAG_MASK_MLAG_INTERFACE)) + strlcat(own_str, "I", sizeof(own_str)); + /* XXX - fixup, print paragraph output */ + vty_out(vty, + "%-15s %-15s %-6s %-11u %-10d %2s\n", + src_str, grp_str, own_str, + pim_up_mlag_local_cost(up), + pim_up_mlag_peer_cost(up), + PIM_UPSTREAM_FLAG_TEST_MLAG_NON_DF(up->flags) + ? "n" : "y"); + } +} + +static void pim_show_mlag_up_detail(struct vrf *vrf, + struct vty *vty, const char *src_or_group, + const char *group, bool uj) +{ + char src_str[INET_ADDRSTRLEN]; + char grp_str[INET_ADDRSTRLEN]; + struct pim_upstream *up; + struct pim_instance *pim = vrf->info; + json_object *json = NULL; + + if (uj) + json = json_object_new_object(); + else + vty_out(vty, + "Source Group Owner Local-cost Peer-cost DF\n"); + + frr_each (rb_pim_upstream, &pim->upstream_head, up) { + if (!(up->flags & PIM_UPSTREAM_FLAG_MASK_MLAG_PEER) + && !(up->flags & PIM_UPSTREAM_FLAG_MASK_MLAG_INTERFACE) + && !pim_up_mlag_is_local(up)) + continue; + + pim_inet4_dump("<src?>", up->sg.src, src_str, sizeof(src_str)); + pim_inet4_dump("<grp?>", up->sg.grp, grp_str, sizeof(grp_str)); + /* XXX: strcmps are clearly inefficient. we should do uint comps + * here instead. + */ + if (group) { + if (strcmp(src_str, src_or_group) || + strcmp(grp_str, group)) + continue; + } else { + if (strcmp(src_str, src_or_group) && + strcmp(grp_str, src_or_group)) + continue; + } + pim_show_mlag_up_entry_detail(vrf, vty, up, + src_str, grp_str, json); + } + + if (uj) { + vty_out(vty, "%s\n", json_object_to_json_string_ext( + json, JSON_C_TO_STRING_PRETTY)); + json_object_free(json); + } +} + +static void pim_show_mlag_up_vrf(struct vrf *vrf, struct vty *vty, bool uj) +{ + json_object *json = NULL; + json_object *json_row; + struct pim_upstream *up; + char src_str[INET_ADDRSTRLEN]; + char grp_str[INET_ADDRSTRLEN]; + struct pim_instance *pim = vrf->info; + json_object *json_group = NULL; + + if (uj) { + json = json_object_new_object(); + } else { + vty_out(vty, + "Source Group Owner Local-cost Peer-cost DF\n"); + } + + frr_each (rb_pim_upstream, &pim->upstream_head, up) { + if (!(up->flags & PIM_UPSTREAM_FLAG_MASK_MLAG_PEER) + && !(up->flags & PIM_UPSTREAM_FLAG_MASK_MLAG_INTERFACE) + && !pim_up_mlag_is_local(up)) + continue; + pim_inet4_dump("<src?>", up->sg.src, src_str, sizeof(src_str)); + pim_inet4_dump("<grp?>", up->sg.grp, grp_str, sizeof(grp_str)); + if (uj) { + json_object *own_list = NULL; + + json_object_object_get_ex(json, grp_str, &json_group); + if (!json_group) { + json_group = json_object_new_object(); + json_object_object_add(json, grp_str, + json_group); + } + + json_row = json_object_new_object(); + json_object_string_add(json_row, "vrf", vrf->name); + json_object_string_add(json_row, "source", src_str); + json_object_string_add(json_row, "group", grp_str); + + own_list = json_object_new_array(); + if (pim_up_mlag_is_local(up)) { + + json_object_array_add(own_list, + json_object_new_string("local")); + } + if (up->flags & (PIM_UPSTREAM_FLAG_MASK_MLAG_PEER)) { + json_object_array_add(own_list, + json_object_new_string("peer")); + } + json_object_object_add(json_row, "owners", own_list); + + json_object_int_add(json_row, "localCost", + pim_up_mlag_local_cost(up)); + json_object_int_add(json_row, "peerCost", + pim_up_mlag_peer_cost(up)); + if (PIM_UPSTREAM_FLAG_TEST_MLAG_NON_DF(up->flags)) + json_object_boolean_false_add(json_row, "df"); + else + json_object_boolean_true_add(json_row, "df"); + json_object_object_add(json_group, src_str, json_row); + } else { + char own_str[6]; + + own_str[0] = '\0'; + if (pim_up_mlag_is_local(up)) + strlcat(own_str, "L", sizeof(own_str)); + if (up->flags & (PIM_UPSTREAM_FLAG_MASK_MLAG_PEER)) + strlcat(own_str, "P", sizeof(own_str)); + if (up->flags & (PIM_UPSTREAM_FLAG_MASK_MLAG_INTERFACE)) + strlcat(own_str, "I", sizeof(own_str)); + vty_out(vty, + "%-15s %-15s %-6s %-11u %-10u %2s\n", + src_str, grp_str, own_str, + pim_up_mlag_local_cost(up), + pim_up_mlag_peer_cost(up), + PIM_UPSTREAM_FLAG_TEST_MLAG_NON_DF(up->flags) + ? "n" : "y"); + } + } + if (uj) { + vty_out(vty, "%s\n", json_object_to_json_string_ext( + json, JSON_C_TO_STRING_PRETTY)); + json_object_free(json); + } +} + +static void pim_show_mlag_help_string(struct vty *vty, bool uj) +{ + if (!uj) { + vty_out(vty, "Owner codes:\n"); + vty_out(vty, + "L: EVPN-MLAG Entry, I:PIM-MLAG Entry, " + "P: Peer Entry\n"); + } +} + + +DEFUN(show_ip_pim_mlag_up, show_ip_pim_mlag_up_cmd, + "show ip pim [vrf NAME] mlag upstream [A.B.C.D [A.B.C.D]] [json]", + SHOW_STR + IP_STR + PIM_STR + VRF_CMD_HELP_STR + "MLAG\n" + "upstream\n" + "Unicast or Multicast address\n" + "Multicast address\n" JSON_STR) +{ + const char *src_or_group = NULL; + const char *group = NULL; + int idx = 2; + struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); + bool uj = use_json(argc, argv); + + if (!vrf || !vrf->info) { + vty_out(vty, "%s: VRF or Info missing\n", __func__); + return CMD_WARNING; + } + + if (uj) + argc--; + + if (argv_find(argv, argc, "A.B.C.D", &idx)) { + src_or_group = argv[idx]->arg; + if (idx + 1 < argc) + group = argv[idx + 1]->arg; + } + + pim_show_mlag_help_string(vty, uj); + + if (src_or_group) + pim_show_mlag_up_detail(vrf, vty, src_or_group, group, uj); + else + pim_show_mlag_up_vrf(vrf, vty, uj); + + return CMD_SUCCESS; +} + + +DEFUN(show_ip_pim_mlag_up_vrf_all, show_ip_pim_mlag_up_vrf_all_cmd, + "show ip pim vrf all mlag upstream [json]", + SHOW_STR IP_STR PIM_STR VRF_CMD_HELP_STR + "MLAG\n" + "upstream\n" JSON_STR) +{ + struct vrf *vrf; + bool uj = use_json(argc, argv); + + pim_show_mlag_help_string(vty, uj); + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { + pim_show_mlag_up_vrf(vrf, vty, uj); + } + + return CMD_SUCCESS; +} + DEFUN (show_ip_pim_neighbor, show_ip_pim_neighbor_cmd, "show ip pim [vrf NAME] neighbor [detail|WORD] [json]", @@ -5294,7 +5684,7 @@ static void pim_cmd_show_ip_multicast_helper(struct pim_instance *pim, pim = vrf->info; vty_out(vty, "Router MLAG Role: %s\n", - mlag_role2str(router->role, mlag_role, sizeof(mlag_role))); + mlag_role2str(router->mlag_role, mlag_role, sizeof(mlag_role))); vty_out(vty, "Mroute socket descriptor:"); vty_out(vty, " %d(%s)\n", pim->mroute_socket, vrf->name); @@ -5399,12 +5789,18 @@ static void show_mroute(struct pim_instance *pim, struct vty *vty, int oif_vif_index; struct interface *ifp_in; char proto[100]; + char state_str[PIM_REG_STATE_STR_LEN]; + char mroute_uptime[10]; if (uj) { json = json_object_new_object(); } else { + vty_out(vty, "IP Multicast Routing Table\n"); + vty_out(vty, "Flags: S- Sparse, C - Connected, P - Pruned\n"); + vty_out(vty, + " R - RP-bit set, F - Register flag, T - SPT-bit set\n"); vty_out(vty, - "Source Group Proto Input Output TTL Uptime\n"); + "\nSource Group Flags Proto Input Output TTL Uptime\n"); } now = pim_time_monotonic_sec(); @@ -5427,6 +5823,23 @@ static void show_mroute(struct pim_instance *pim, struct vty *vty, sizeof(grp_str)); pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, src_str, sizeof(src_str)); + + strlcpy(state_str, "S", sizeof(state_str)); + /* When a non DR receives a igmp join, it creates a (*,G) + * channel_oil without any upstream creation */ + if (c_oil->up) { + if (PIM_UPSTREAM_FLAG_TEST_SRC_IGMP(c_oil->up->flags)) + strlcat(state_str, "C", sizeof(state_str)); + if (pim_upstream_is_sg_rpt(c_oil->up)) + strlcat(state_str, "R", sizeof(state_str)); + if (PIM_UPSTREAM_FLAG_TEST_FHR(c_oil->up->flags)) + strlcat(state_str, "F", sizeof(state_str)); + if (c_oil->up->sptbit == PIM_UPSTREAM_SPTBIT_TRUE) + strlcat(state_str, "T", sizeof(state_str)); + } + if (pim_channel_oil_empty(c_oil)) + strlcat(state_str, "P", sizeof(state_str)); + ifp_in = pim_if_find_by_vif_index(pim, c_oil->oil.mfcc_parent); if (ifp_in) @@ -5434,6 +5847,10 @@ static void show_mroute(struct pim_instance *pim, struct vty *vty, else strlcpy(in_ifname, "<iif?>", sizeof(in_ifname)); + + pim_time_uptime(mroute_uptime, sizeof(mroute_uptime), + now - c_oil->mroute_creation); + if (uj) { /* Find the group, create it if it doesn't exist */ @@ -5446,7 +5863,8 @@ static void show_mroute(struct pim_instance *pim, struct vty *vty, } /* Find the source nested under the group, create it if - * it doesn't exist */ + * it doesn't exist + */ json_object_object_get_ex(json_group, src_str, &json_source); @@ -5467,13 +5885,14 @@ static void show_mroute(struct pim_instance *pim, struct vty *vty, json_object_int_add(json_source, "OilInheritedRescan", c_oil->oil_inherited_rescan); json_object_string_add(json_source, "iif", in_ifname); + json_object_string_add(json_source, "upTime", + mroute_uptime); json_oil = NULL; } for (oif_vif_index = 0; oif_vif_index < MAXVIFS; ++oif_vif_index) { struct interface *ifp_out; - char mroute_uptime[10]; int ttl; ttl = c_oil->oil.mfcc_ttls[oif_vif_index]; @@ -5491,9 +5910,6 @@ static void show_mroute(struct pim_instance *pim, struct vty *vty, continue; ifp_out = pim_if_find_by_vif_index(pim, oif_vif_index); - pim_time_uptime( - mroute_uptime, sizeof(mroute_uptime), - now - c_oil->mroute_creation); found_oif = 1; if (ifp_out) @@ -5571,23 +5987,27 @@ static void show_mroute(struct pim_instance *pim, struct vty *vty, } vty_out(vty, - "%-15s %-15s %-6s %-16s %-16s %-3d %8s\n", - src_str, grp_str, proto, in_ifname, - out_ifname, ttl, mroute_uptime); + "%-15s %-15s %-15s %-6s %-16s %-16s %-3d %8s\n", + src_str, grp_str, state_str, proto, + in_ifname, out_ifname, ttl, + mroute_uptime); if (first) { src_str[0] = '\0'; grp_str[0] = '\0'; in_ifname[0] = '\0'; + state_str[0] = '\0'; + mroute_uptime[0] = '\0'; first = 0; } } } if (!uj && !found_oif) { - vty_out(vty, "%-15s %-15s %-6s %-16s %-16s %-3d %8s\n", - src_str, grp_str, "none", in_ifname, "none", 0, - "--:--:--"); + vty_out(vty, + "%-15s %-15s %-15s %-6s %-16s %-16s %-3d %8s\n", + src_str, grp_str, state_str, "none", in_ifname, + "none", 0, "--:--:--"); } } @@ -7042,7 +7462,7 @@ static void igmp_sock_query_interval_reconfig(struct igmp_sock *igmp) pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str)); zlog_debug("%s: Querier %s on %s reconfig query_interval=%d", - __PRETTY_FUNCTION__, ifaddr_str, ifp->name, + __func__, ifaddr_str, ifp->name, pim_ifp->igmp_default_query_interval); } @@ -7056,6 +7476,9 @@ static void igmp_sock_query_interval_reconfig(struct igmp_sock *igmp) static void igmp_sock_query_reschedule(struct igmp_sock *igmp) { + if (igmp->mtrace_only) + return; + if (igmp->t_igmp_query_timer) { /* other querier present */ zassert(igmp->t_igmp_query_timer); @@ -7659,13 +8082,13 @@ DEFPY_HIDDEN (pim_test_sg_keepalive, return CMD_SUCCESS; } -DEFPY_HIDDEN (interface_ip_pim_activeactive, - interface_ip_pim_activeactive_cmd, - "[no$no] ip pim active-active", - NO_STR - IP_STR - PIM_STR - "Mark interface as Active-Active for MLAG operations, Hidden because not finished yet\n") +DEFPY (interface_ip_pim_activeactive, + interface_ip_pim_activeactive_cmd, + "[no$no] ip pim active-active", + NO_STR + IP_STR + PIM_STR + "Mark interface as Active-Active for MLAG operations, Hidden because not finished yet\n") { VTY_DECLVAR_CONTEXT(interface, ifp); struct pim_interface *pim_ifp; @@ -7675,6 +8098,11 @@ DEFPY_HIDDEN (interface_ip_pim_activeactive, return CMD_WARNING_CONFIG_FAILED; } + + if (PIM_DEBUG_MLAG) + zlog_debug("%sConfiguring PIM active-active on Interface: %s", + no ? "Un-":" ", ifp->name); + pim_ifp = ifp->info; if (no) pim_if_unconfigure_mlag_dualactive(pim_ifp); @@ -10024,7 +10452,7 @@ static void pim_show_vxlan_sg_entry(struct pim_vxlan_sg *vxlan_sg, } } -static void pim_show_vxlan_sg_hash_entry(struct hash_backet *backet, void *arg) +static void pim_show_vxlan_sg_hash_entry(struct hash_bucket *backet, void *arg) { pim_show_vxlan_sg_entry((struct pim_vxlan_sg *)backet->data, (struct pim_sg_cache_walk_data *)arg); @@ -10259,7 +10687,7 @@ DEFUN_HIDDEN (no_ip_pim_mlag, addr.s_addr = 0; pim_vxlan_mlag_update(true/*mlag_enable*/, - false/*peer_state*/, PIM_VXLAN_MLAG_ROLE_SECONDARY, + false/*peer_state*/, MLAG_ROLE_NONE, NULL/*peerlink*/, &addr); return CMD_SUCCESS; @@ -10299,9 +10727,9 @@ DEFUN_HIDDEN (ip_pim_mlag, idx += 2; if (!strcmp(argv[idx]->arg, "primary")) { - role = PIM_VXLAN_MLAG_ROLE_PRIMARY; + role = MLAG_ROLE_PRIMARY; } else if (!strcmp(argv[idx]->arg, "secondary")) { - role = PIM_VXLAN_MLAG_ROLE_SECONDARY; + role = MLAG_ROLE_SECONDARY; } else { vty_out(vty, "unknown MLAG role %s\n", argv[idx]->arg); return CMD_WARNING; @@ -10471,6 +10899,9 @@ void pim_cmd_init(void) install_element(VIEW_NODE, &show_ip_pim_join_vrf_all_cmd); install_element(VIEW_NODE, &show_ip_pim_jp_agg_cmd); install_element(VIEW_NODE, &show_ip_pim_local_membership_cmd); + install_element(VIEW_NODE, &show_ip_pim_mlag_summary_cmd); + install_element(VIEW_NODE, &show_ip_pim_mlag_up_cmd); + install_element(VIEW_NODE, &show_ip_pim_mlag_up_vrf_all_cmd); install_element(VIEW_NODE, &show_ip_pim_neighbor_cmd); install_element(VIEW_NODE, &show_ip_pim_neighbor_vrf_all_cmd); install_element(VIEW_NODE, &show_ip_pim_rpf_cmd); @@ -10595,6 +11026,8 @@ void pim_cmd_init(void) install_element(CONFIG_NODE, &no_debug_ssmpingd_cmd); install_element(CONFIG_NODE, &debug_pim_zebra_cmd); install_element(CONFIG_NODE, &no_debug_pim_zebra_cmd); + install_element(CONFIG_NODE, &debug_pim_mlag_cmd); + install_element(CONFIG_NODE, &no_debug_pim_mlag_cmd); install_element(CONFIG_NODE, &debug_pim_vxlan_cmd); install_element(CONFIG_NODE, &no_debug_pim_vxlan_cmd); install_element(CONFIG_NODE, &debug_msdp_cmd); diff --git a/pimd/pim_hello.c b/pimd/pim_hello.c index 34c5eb43bc..ecdb3a34a7 100644 --- a/pimd/pim_hello.c +++ b/pimd/pim_hello.c @@ -154,7 +154,7 @@ int pim_hello_recv(struct interface *ifp, struct in_addr src_addr, struct list *hello_option_addr_list = 0; if (PIM_DEBUG_PIM_HELLO) - on_trace(__PRETTY_FUNCTION__, ifp, src_addr); + on_trace(__func__, ifp, src_addr); pim_ifp = ifp->info; zassert(pim_ifp); @@ -180,8 +180,8 @@ int pim_hello_recv(struct interface *ifp, struct in_addr src_addr, sizeof(src_str)); zlog_debug( "%s: short PIM hello TLV size=%d < min=%d from %s on interface %s", - __PRETTY_FUNCTION__, remain, - PIM_TLV_MIN_SIZE, src_str, ifp->name); + __func__, remain, PIM_TLV_MIN_SIZE, + src_str, ifp->name); } FREE_ADDR_LIST_THEN_RETURN(-1); } @@ -198,9 +198,9 @@ int pim_hello_recv(struct interface *ifp, struct in_addr src_addr, sizeof(src_str)); zlog_debug( "%s: long PIM hello TLV type=%d length=%d > left=%td from %s on interface %s", - __PRETTY_FUNCTION__, option_type, - option_len, tlv_pastend - tlv_curr, - src_str, ifp->name); + __func__, option_type, option_len, + tlv_pastend - tlv_curr, src_str, + ifp->name); } FREE_ADDR_LIST_THEN_RETURN(-2); } @@ -211,8 +211,8 @@ int pim_hello_recv(struct interface *ifp, struct in_addr src_addr, sizeof(src_str)); zlog_debug( "%s: parse left_size=%d: PIM hello TLV type=%d length=%d from %s on %s", - __PRETTY_FUNCTION__, remain, option_type, - option_len, src_str, ifp->name); + __func__, remain, option_type, option_len, + src_str, ifp->name); } switch (option_type) { @@ -264,8 +264,8 @@ int pim_hello_recv(struct interface *ifp, struct in_addr src_addr, sizeof(src_str)); zlog_debug( "%s: ignoring PIM hello dense-mode state refresh TLV option type=%d length=%d from %s on interface %s", - __PRETTY_FUNCTION__, option_type, - option_len, src_str, ifp->name); + __func__, option_type, option_len, + src_str, ifp->name); } break; default: @@ -275,8 +275,8 @@ int pim_hello_recv(struct interface *ifp, struct in_addr src_addr, sizeof(src_str)); zlog_debug( "%s: ignoring unknown PIM hello TLV type=%d length=%d from %s on interface %s", - __PRETTY_FUNCTION__, option_type, - option_len, src_str, ifp->name); + __func__, option_type, option_len, + src_str, ifp->name); } } @@ -288,44 +288,38 @@ int pim_hello_recv(struct interface *ifp, struct in_addr src_addr, */ if (PIM_DEBUG_PIM_HELLO) { - tlv_trace_uint16(__PRETTY_FUNCTION__, "holdtime", ifp->name, - src_addr, + tlv_trace_uint16(__func__, "holdtime", ifp->name, src_addr, PIM_OPTION_IS_SET(hello_options, PIM_OPTION_MASK_HOLDTIME), hello_option_holdtime); tlv_trace_uint16( - __PRETTY_FUNCTION__, "propagation_delay", ifp->name, - src_addr, + __func__, "propagation_delay", ifp->name, src_addr, PIM_OPTION_IS_SET(hello_options, PIM_OPTION_MASK_LAN_PRUNE_DELAY), hello_option_propagation_delay); tlv_trace_uint16( - __PRETTY_FUNCTION__, "override_interval", ifp->name, - src_addr, + __func__, "override_interval", ifp->name, src_addr, PIM_OPTION_IS_SET(hello_options, PIM_OPTION_MASK_LAN_PRUNE_DELAY), hello_option_override_interval); tlv_trace_bool( - __PRETTY_FUNCTION__, "can_disable_join_suppression", - ifp->name, src_addr, + __func__, "can_disable_join_suppression", ifp->name, + src_addr, PIM_OPTION_IS_SET(hello_options, PIM_OPTION_MASK_LAN_PRUNE_DELAY), PIM_OPTION_IS_SET( hello_options, PIM_OPTION_MASK_CAN_DISABLE_JOIN_SUPPRESSION)); - tlv_trace_uint32(__PRETTY_FUNCTION__, "dr_priority", ifp->name, - src_addr, + tlv_trace_uint32(__func__, "dr_priority", ifp->name, src_addr, PIM_OPTION_IS_SET(hello_options, PIM_OPTION_MASK_DR_PRIORITY), hello_option_dr_priority); tlv_trace_uint32_hex( - __PRETTY_FUNCTION__, "generation_id", ifp->name, - src_addr, + __func__, "generation_id", ifp->name, src_addr, PIM_OPTION_IS_SET(hello_options, PIM_OPTION_MASK_GENERATION_ID), hello_option_generation_id); - tlv_trace_list(__PRETTY_FUNCTION__, "address_list", ifp->name, - src_addr, + tlv_trace_list(__func__, "address_list", ifp->name, src_addr, PIM_OPTION_IS_SET(hello_options, PIM_OPTION_MASK_ADDRESS_LIST), hello_option_addr_list); @@ -338,7 +332,7 @@ int pim_hello_recv(struct interface *ifp, struct in_addr src_addr, sizeof(src_str)); zlog_debug( "%s: PIM hello missing holdtime from %s on interface %s", - __PRETTY_FUNCTION__, src_str, ifp->name); + __func__, src_str, ifp->name); } } @@ -363,16 +357,16 @@ int pim_hello_recv(struct interface *ifp, struct in_addr src_addr, sizeof(src_str)); zlog_warn( "%s: failure creating PIM neighbor %s on interface %s", - __PRETTY_FUNCTION__, src_str, - ifp->name); + __func__, src_str, ifp->name); } FREE_ADDR_LIST_THEN_RETURN(-8); } /* Forward BSM if required */ if (!pim_bsm_new_nbr_fwd(neigh, ifp)) { if (PIM_DEBUG_PIM_HELLO) - zlog_debug("%s: forwarding bsm to new nbr failed", - __PRETTY_FUNCTION__); + zlog_debug( + "%s: forwarding bsm to new nbr failed", + __func__); } /* actual addr list has been saved under neighbor */ @@ -396,8 +390,7 @@ int pim_hello_recv(struct interface *ifp, struct in_addr src_addr, sizeof(src_str)); zlog_debug( "%s: GenId mismatch new=%08x old=%08x: replacing neighbor %s on %s", - __PRETTY_FUNCTION__, - hello_option_generation_id, + __func__, hello_option_generation_id, neigh->generation_id, src_str, ifp->name); } @@ -422,16 +415,16 @@ int pim_hello_recv(struct interface *ifp, struct in_addr src_addr, sizeof(src_str)); zlog_debug( "%s: failure re-creating PIM neighbor %s on interface %s", - __PRETTY_FUNCTION__, src_str, - ifp->name); + __func__, src_str, ifp->name); } FREE_ADDR_LIST_THEN_RETURN(-9); } /* Forward BSM if required */ if (!pim_bsm_new_nbr_fwd(neigh, ifp)) { if (PIM_DEBUG_PIM_HELLO) - zlog_debug("%s: forwarding bsm to new nbr failed", - __PRETTY_FUNCTION__); + zlog_debug( + "%s: forwarding bsm to new nbr failed", + __func__); } /* actual addr list is saved under neighbor */ return 0; @@ -473,7 +466,7 @@ int pim_hello_build_tlv(struct interface *ifp, uint8_t *tlv_buf, if (PIM_DEBUG_PIM_HELLO) { zlog_debug( "%s: could not set PIM hello Holdtime option for interface %s", - __PRETTY_FUNCTION__, ifp->name); + __func__, ifp->name); } return -1; } @@ -486,7 +479,7 @@ int pim_hello_build_tlv(struct interface *ifp, uint8_t *tlv_buf, if (PIM_DEBUG_PIM_HELLO) { zlog_debug( "%s: could not set PIM LAN Prune Delay option for interface %s", - __PRETTY_FUNCTION__, ifp->name); + __func__, ifp->name); } return -1; } @@ -502,7 +495,7 @@ int pim_hello_build_tlv(struct interface *ifp, uint8_t *tlv_buf, if (PIM_DEBUG_PIM_HELLO) { zlog_debug( "%s: could not set PIM hello DR Priority option for interface %s", - __PRETTY_FUNCTION__, ifp->name); + __func__, ifp->name); } return -2; } @@ -515,7 +508,7 @@ int pim_hello_build_tlv(struct interface *ifp, uint8_t *tlv_buf, if (PIM_DEBUG_PIM_HELLO) { zlog_debug( "%s: could not set PIM hello Generation ID option for interface %s", - __PRETTY_FUNCTION__, ifp->name); + __func__, ifp->name); } return -3; } @@ -528,7 +521,7 @@ int pim_hello_build_tlv(struct interface *ifp, uint8_t *tlv_buf, if (PIM_DEBUG_PIM_HELLO) { zlog_debug( "%s: could not set PIM hello v4 Secondary Address List option for interface %s", - __PRETTY_FUNCTION__, ifp->name); + __func__, ifp->name); } return -4; } @@ -539,7 +532,7 @@ int pim_hello_build_tlv(struct interface *ifp, uint8_t *tlv_buf, if (PIM_DEBUG_PIM_HELLO) { zlog_debug( "%s: could not sent PIM hello v6 secondary Address List option for interface %s", - __PRETTY_FUNCTION__, ifp->name); + __func__, ifp->name); } return -4; } diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index c615540149..cb31878e01 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -314,9 +314,9 @@ static int detect_primary_address_change(struct interface *ifp, sizeof(new_prim_str)); pim_inet4_dump("<old?>", pim_ifp->primary_address, old_prim_str, sizeof(old_prim_str)); - zlog_debug("%s: old=%s new=%s on interface %s: %s", - __PRETTY_FUNCTION__, old_prim_str, new_prim_str, - ifp->name, changed ? "changed" : "unchanged"); + zlog_debug("%s: old=%s new=%s on interface %s: %s", __func__, + old_prim_str, new_prim_str, ifp->name, + changed ? "changed" : "unchanged"); } if (changed) { @@ -487,8 +487,7 @@ int pim_update_source_set(struct interface *ifp, struct in_addr source) } pim_ifp->update_source = source; - detect_address_change(ifp, 0 /* force_prim_as_any */, - __PRETTY_FUNCTION__); + detect_address_change(ifp, 0 /* force_prim_as_any */, __func__); return PIM_SUCCESS; } @@ -498,6 +497,7 @@ void pim_if_addr_add(struct connected *ifc) struct pim_interface *pim_ifp; struct interface *ifp; struct in_addr ifaddr; + bool vxlan_term; zassert(ifc); @@ -514,7 +514,7 @@ void pim_if_addr_add(struct connected *ifc) char buf[BUFSIZ]; prefix2str(ifc->address, buf, BUFSIZ); zlog_debug("%s: %s ifindex=%d connected IP address %s %s", - __PRETTY_FUNCTION__, ifp->name, ifp->ifindex, buf, + __func__, ifp->name, ifp->ifindex, buf, CHECK_FLAG(ifc->flags, ZEBRA_IFA_SECONDARY) ? "secondary" : "primary"); @@ -522,7 +522,7 @@ void pim_if_addr_add(struct connected *ifc) ifaddr = ifc->address->u.prefix4; - detect_address_change(ifp, 0, __PRETTY_FUNCTION__); + detect_address_change(ifp, 0, __func__); // if (ifc->address->family != AF_INET) // return; @@ -570,8 +570,8 @@ void pim_if_addr_add(struct connected *ifc) source_str, sizeof(source_str)); zlog_warn( "%s: igmp_join_sock() failure for IGMP group %s source %s on interface %s", - __PRETTY_FUNCTION__, group_str, - source_str, ifp->name); + __func__, group_str, source_str, + ifp->name); /* warning only */ } else ij->sock_fd = join_fd; @@ -635,7 +635,8 @@ void pim_if_addr_add(struct connected *ifc) address assigned, then try to create a vif_index. */ if (pim_ifp->mroute_vif_index < 0) { - pim_if_add_vif(ifp, false, false /*vxlan_term*/); + vxlan_term = pim_vxlan_is_term_dev_cfg(pim_ifp->pim, ifp); + pim_if_add_vif(ifp, false, vxlan_term); } pim_ifchannel_scan_forward_start(ifp); } @@ -710,13 +711,13 @@ void pim_if_addr_del(struct connected *ifc, int force_prim_as_any) char buf[BUFSIZ]; prefix2str(ifc->address, buf, BUFSIZ); zlog_debug("%s: %s ifindex=%d disconnected IP address %s %s", - __PRETTY_FUNCTION__, ifp->name, ifp->ifindex, buf, + __func__, ifp->name, ifp->ifindex, buf, CHECK_FLAG(ifc->flags, ZEBRA_IFA_SECONDARY) ? "secondary" : "primary"); } - detect_address_change(ifp, force_prim_as_any, __PRETTY_FUNCTION__); + detect_address_change(ifp, force_prim_as_any, __func__); pim_if_addr_del_igmp(ifc); pim_if_addr_del_pim(ifc); @@ -730,6 +731,7 @@ void pim_if_addr_add_all(struct interface *ifp) int v4_addrs = 0; int v6_addrs = 0; struct pim_interface *pim_ifp = ifp->info; + bool vxlan_term; /* PIM/IGMP enabled ? */ @@ -768,7 +770,8 @@ void pim_if_addr_add_all(struct interface *ifp) * address assigned, then try to create a vif_index. */ if (pim_ifp->mroute_vif_index < 0) { - pim_if_add_vif(ifp, false, false /*vxlan_term*/); + vxlan_term = pim_vxlan_is_term_dev_cfg(pim_ifp->pim, ifp); + pim_if_add_vif(ifp, false, vxlan_term); } pim_ifchannel_scan_forward_start(ifp); @@ -873,7 +876,7 @@ struct in_addr pim_find_primary_addr(struct interface *ifp) if (PIM_INADDR_IS_ANY(p->u.prefix4)) { zlog_warn( "%s: null IPv4 address connected to interface %s", - __PRETTY_FUNCTION__, ifp->name); + __func__, ifp->name); continue; } @@ -943,14 +946,14 @@ int pim_if_add_vif(struct interface *ifp, bool ispimreg, bool is_vxlan_term) if (pim_ifp->mroute_vif_index > 0) { zlog_warn("%s: vif_index=%d > 0 on interface %s ifindex=%d", - __PRETTY_FUNCTION__, pim_ifp->mroute_vif_index, - ifp->name, ifp->ifindex); + __func__, pim_ifp->mroute_vif_index, ifp->name, + ifp->ifindex); return -1; } if (ifp->ifindex < 0) { - zlog_warn("%s: ifindex=%d < 1 on interface %s", - __PRETTY_FUNCTION__, ifp->ifindex, ifp->name); + zlog_warn("%s: ifindex=%d < 1 on interface %s", __func__, + ifp->ifindex, ifp->name); return -2; } @@ -958,7 +961,7 @@ int pim_if_add_vif(struct interface *ifp, bool ispimreg, bool is_vxlan_term) if (!ispimreg && !is_vxlan_term && PIM_INADDR_IS_ANY(ifaddr)) { zlog_warn( "%s: could not get address for interface %s ifindex=%d", - __PRETTY_FUNCTION__, ifp->name, ifp->ifindex); + __func__, ifp->name, ifp->ifindex); return -4; } @@ -967,7 +970,7 @@ int pim_if_add_vif(struct interface *ifp, bool ispimreg, bool is_vxlan_term) if (pim_ifp->mroute_vif_index >= MAXVIFS) { zlog_warn( "%s: Attempting to configure more than MAXVIFS=%d on pim enabled interface %s", - __PRETTY_FUNCTION__, MAXVIFS, ifp->name); + __func__, MAXVIFS, ifp->name); return -3; } @@ -997,8 +1000,8 @@ int pim_if_del_vif(struct interface *ifp) if (pim_ifp->mroute_vif_index < 1) { zlog_warn("%s: vif_index=%d < 1 on interface %s ifindex=%d", - __PRETTY_FUNCTION__, pim_ifp->mroute_vif_index, - ifp->name, ifp->ifindex); + __func__, pim_ifp->mroute_vif_index, ifp->name, + ifp->ifindex); return -1; } @@ -1125,8 +1128,8 @@ struct pim_neighbor *pim_if_find_neighbor(struct interface *ifp, pim_ifp = ifp->info; if (!pim_ifp) { - zlog_warn("%s: multicast not enabled on interface %s", - __PRETTY_FUNCTION__, ifp->name); + zlog_warn("%s: multicast not enabled on interface %s", __func__, + ifp->name); return 0; } @@ -1151,7 +1154,7 @@ struct pim_neighbor *pim_if_find_neighbor(struct interface *ifp, pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); zlog_debug( "%s: neighbor not found for address %s on interface %s", - __PRETTY_FUNCTION__, addr_str, ifp->name); + __func__, addr_str, ifp->name); } return NULL; @@ -1219,8 +1222,8 @@ static int igmp_join_sock(const char *ifname, ifindex_t ifindex, sizeof(source_str)); zlog_warn( "%s: setsockopt(fd=%d) failure for IGMP group %s source %s ifindex %d on interface %s: errno=%d: %s", - __PRETTY_FUNCTION__, join_fd, group_str, source_str, - ifindex, ifname, errno, safe_strerror(errno)); + __func__, join_fd, group_str, source_str, ifindex, + ifname, errno, safe_strerror(errno)); close(join_fd); return -2; @@ -1252,7 +1255,7 @@ static struct igmp_join *igmp_join_new(struct interface *ifp, sizeof(source_str)); zlog_warn( "%s: igmp_join_sock() failure for IGMP group %s source %s on interface %s", - __PRETTY_FUNCTION__, group_str, source_str, ifp->name); + __func__, group_str, source_str, ifp->name); return 0; } @@ -1304,7 +1307,7 @@ ferr_r pim_if_igmp_join_add(struct interface *ifp, struct in_addr group_addr, sizeof(source_str)); zlog_debug( "%s: issued static igmp join for channel (S,G)=(%s,%s) on interface %s", - __PRETTY_FUNCTION__, source_str, group_str, ifp->name); + __func__, source_str, group_str, ifp->name); } return ferr_ok(); @@ -1319,14 +1322,14 @@ int pim_if_igmp_join_del(struct interface *ifp, struct in_addr group_addr, pim_ifp = ifp->info; if (!pim_ifp) { - zlog_warn("%s: multicast not enabled on interface %s", - __PRETTY_FUNCTION__, ifp->name); + zlog_warn("%s: multicast not enabled on interface %s", __func__, + ifp->name); return -1; } if (!pim_ifp->igmp_join_list) { - zlog_warn("%s: no IGMP join on interface %s", - __PRETTY_FUNCTION__, ifp->name); + zlog_warn("%s: no IGMP join on interface %s", __func__, + ifp->name); return -2; } @@ -1340,7 +1343,7 @@ int pim_if_igmp_join_del(struct interface *ifp, struct in_addr group_addr, sizeof(source_str)); zlog_warn( "%s: could not find IGMP group %s source %s on interface %s", - __PRETTY_FUNCTION__, group_str, source_str, ifp->name); + __func__, group_str, source_str, ifp->name); return -3; } @@ -1353,8 +1356,8 @@ int pim_if_igmp_join_del(struct interface *ifp, struct in_addr group_addr, sizeof(source_str)); zlog_warn( "%s: failure closing sock_fd=%d for IGMP group %s source %s on interface %s: errno=%d: %s", - __PRETTY_FUNCTION__, ij->sock_fd, group_str, source_str, - ifp->name, errno, safe_strerror(errno)); + __func__, ij->sock_fd, group_str, source_str, ifp->name, + errno, safe_strerror(errno)); /* warning only */ } listnode_delete(pim_ifp->igmp_join_list, ij); @@ -1376,8 +1379,8 @@ static void pim_if_igmp_join_del_all(struct interface *ifp) pim_ifp = ifp->info; if (!pim_ifp) { - zlog_warn("%s: multicast not enabled on interface %s", - __PRETTY_FUNCTION__, ifp->name); + zlog_warn("%s: multicast not enabled on interface %s", __func__, + ifp->name); return; } @@ -1542,8 +1545,8 @@ int pim_ifp_create(struct interface *ifp) if (PIM_DEBUG_ZEBRA) { zlog_debug( "%s: %s index %d(%u) flags %ld metric %d mtu %d operative %d", - __PRETTY_FUNCTION__, ifp->name, ifp->ifindex, - ifp->vrf_id, (long)ifp->flags, ifp->metric, ifp->mtu, + __func__, ifp->name, ifp->ifindex, ifp->vrf_id, + (long)ifp->flags, ifp->metric, ifp->mtu, if_is_operative(ifp)); } @@ -1595,8 +1598,8 @@ int pim_ifp_up(struct interface *ifp) if (PIM_DEBUG_ZEBRA) { zlog_debug( "%s: %s index %d(%u) flags %ld metric %d mtu %d operative %d", - __PRETTY_FUNCTION__, ifp->name, ifp->ifindex, - ifp->vrf_id, (long)ifp->flags, ifp->metric, ifp->mtu, + __func__, ifp->name, ifp->ifindex, ifp->vrf_id, + (long)ifp->flags, ifp->metric, ifp->mtu, if_is_operative(ifp)); } @@ -1632,7 +1635,7 @@ int pim_ifp_up(struct interface *ifp) if (!master) { zlog_debug( "%s: Unable to find Master interface for %s", - __PRETTY_FUNCTION__, vrf->name); + __func__, vrf->name); return 0; } pim_zebra_interface_set_master(master, ifp); @@ -1647,8 +1650,8 @@ int pim_ifp_down(struct interface *ifp) if (PIM_DEBUG_ZEBRA) { zlog_debug( "%s: %s index %d(%u) flags %ld metric %d mtu %d operative %d", - __PRETTY_FUNCTION__, ifp->name, ifp->ifindex, - ifp->vrf_id, (long)ifp->flags, ifp->metric, ifp->mtu, + __func__, ifp->name, ifp->ifindex, ifp->vrf_id, + (long)ifp->flags, ifp->metric, ifp->mtu, if_is_operative(ifp)); } @@ -1683,8 +1686,8 @@ int pim_ifp_destroy(struct interface *ifp) if (PIM_DEBUG_ZEBRA) { zlog_debug( "%s: %s index %d(%u) flags %ld metric %d mtu %d operative %d", - __PRETTY_FUNCTION__, ifp->name, ifp->ifindex, - ifp->vrf_id, (long)ifp->flags, ifp->metric, ifp->mtu, + __func__, ifp->name, ifp->ifindex, ifp->vrf_id, + (long)ifp->flags, ifp->metric, ifp->mtu, if_is_operative(ifp)); } diff --git a/pimd/pim_iface.h b/pimd/pim_iface.h index 1b76b52305..570bf5eac3 100644 --- a/pimd/pim_iface.h +++ b/pimd/pim_iface.h @@ -55,6 +55,7 @@ #define PIM_IF_DONT_PIM_CAN_DISABLE_JOIN_SUPRESSION(options) ((options) &= ~PIM_IF_MASK_PIM_CAN_DISABLE_JOIN_SUPRESSION) #define PIM_I_am_DR(pim_ifp) (pim_ifp)->pim_dr_addr.s_addr == (pim_ifp)->primary_address.s_addr +#define PIM_I_am_DualActive(pim_ifp) (pim_ifp)->activeactive == true struct pim_iface_upstream_switch { struct in_addr address; diff --git a/pimd/pim_ifchannel.c b/pimd/pim_ifchannel.c index 22d6e6298e..44d4ee7192 100644 --- a/pimd/pim_ifchannel.c +++ b/pimd/pim_ifchannel.c @@ -43,6 +43,7 @@ #include "pim_upstream.h" #include "pim_ssm.h" #include "pim_rp.h" +#include "pim_mlag.h" RB_GENERATE(pim_ifchannel_rb, pim_ifchannel, pim_ifp_rb, pim_ifchannel_compare); @@ -127,9 +128,29 @@ static void pim_ifchannel_find_new_children(struct pim_ifchannel *ch) void pim_ifchannel_delete(struct pim_ifchannel *ch) { struct pim_interface *pim_ifp; + struct pim_upstream *up; pim_ifp = ch->interface->info; + if (PIM_DEBUG_PIM_TRACE) + zlog_debug("%s: ifchannel entry %s(%s) del start", __func__, + ch->sg_str, ch->interface->name); + + if (PIM_I_am_DualActive(pim_ifp)) { + if (PIM_DEBUG_MLAG) + zlog_debug( + "%s: if-chnanel-%s is deleted from a Dual " + "active Interface", + __func__, ch->sg_str); + /* Post Delete only if it is the last Dual-active Interface */ + if (ch->upstream->dualactive_ifchannel_count == 1) { + pim_mlag_up_local_del(pim_ifp->pim, ch->upstream); + PIM_UPSTREAM_FLAG_UNSET_MLAG_INTERFACE( + ch->upstream->flags); + } + ch->upstream->dualactive_ifchannel_count--; + } + if (ch->upstream->channel_oil) { uint32_t mask = PIM_OIF_FLAG_PROTO_PIM; if (ch->upstream->flags & PIM_UPSTREAM_FLAG_MASK_SRC_IGMP) @@ -181,22 +202,22 @@ void pim_ifchannel_delete(struct pim_ifchannel *ch) listnode_delete(ch->upstream->ifchannels, ch); - pim_upstream_update_join_desired(pim_ifp->pim, ch->upstream); + up = ch->upstream; /* upstream is common across ifchannels, check if upstream's ifchannel list is empty before deleting upstream_del ref count will take care of it. */ if (ch->upstream->ref_count > 0) - pim_upstream_del(pim_ifp->pim, ch->upstream, - __PRETTY_FUNCTION__); + up = pim_upstream_del(pim_ifp->pim, ch->upstream, __func__); else { if (PIM_DEBUG_PIM_TRACE) - zlog_debug("%s: Avoiding deletion of upstream with ref_count %d " - "from ifchannel(%s): %s", __PRETTY_FUNCTION__, - ch->upstream->ref_count, ch->interface->name, - ch->sg_str); + zlog_debug( + "%s: Avoiding deletion of upstream with ref_count %d " + "from ifchannel(%s): %s", + __func__, ch->upstream->ref_count, + ch->interface->name, ch->sg_str); } ch->upstream = NULL; @@ -213,10 +234,13 @@ void pim_ifchannel_delete(struct pim_ifchannel *ch) RB_REMOVE(pim_ifchannel_rb, &pim_ifp->ifchannel_rb, ch); if (PIM_DEBUG_PIM_TRACE) - zlog_debug("%s: ifchannel entry %s is deleted ", - __PRETTY_FUNCTION__, ch->sg_str); + zlog_debug("%s: ifchannel entry %s(%s) is deleted ", __func__, + ch->sg_str, ch->interface->name); XFREE(MTYPE_PIM_IFCHANNEL, ch); + + if (up) + pim_upstream_update_join_desired(pim_ifp->pim, up); } void pim_ifchannel_delete_all(struct interface *ifp) @@ -231,8 +255,7 @@ void pim_ifchannel_delete_all(struct interface *ifp) while (!RB_EMPTY(pim_ifchannel_rb, &pim_ifp->ifchannel_rb)) { ch = RB_ROOT(pim_ifchannel_rb, &pim_ifp->ifchannel_rb); - pim_ifchannel_ifjoin_switch(__PRETTY_FUNCTION__, - ch, PIM_IFJOIN_NOINFO); + pim_ifchannel_ifjoin_switch(__func__, ch, PIM_IFJOIN_NOINFO); pim_ifchannel_delete(ch); } } @@ -264,7 +287,7 @@ void pim_ifchannel_ifjoin_switch(const char *caller, struct pim_ifchannel *ch, if (PIM_DEBUG_PIM_EVENTS) { zlog_debug( "%s calledby %s: non-transition on state %d (%s)", - __PRETTY_FUNCTION__, caller, new_state, + __func__, caller, new_state, pim_ifchannel_ifjoin_name(new_state, 0)); } return; @@ -287,8 +310,7 @@ void pim_ifchannel_ifjoin_switch(const char *caller, struct pim_ifchannel *ch, if (PIM_DEBUG_PIM_TRACE) zlog_debug( "%s %s: Prune(S,G)=%s from %s", - __FILE__, - __PRETTY_FUNCTION__, + __FILE__, __func__, child->sg_str, up->sg_str); if (!c_oil) @@ -314,8 +336,7 @@ void pim_ifchannel_ifjoin_switch(const char *caller, struct pim_ifchannel *ch, if (PIM_DEBUG_PIM_TRACE) zlog_debug( "%s %s: Join(S,G)=%s from %s", - __FILE__, - __PRETTY_FUNCTION__, + __FILE__, __func__, child->sg_str, up->sg_str); @@ -438,7 +459,7 @@ struct pim_ifchannel *pim_ifchannel_find(struct interface *ifp, if (!pim_ifp) { zlog_warn("%s: (S,G)=%s: multicast not enabled on interface %s", - __PRETTY_FUNCTION__, pim_str_sg_dump(sg), ifp->name); + __func__, pim_str_sg_dump(sg), ifp->name); return NULL; } @@ -459,7 +480,7 @@ static void ifmembership_set(struct pim_ifchannel *ch, if (PIM_DEBUG_PIM_EVENTS) { zlog_debug("%s: (S,G)=%s membership now is %s on interface %s", - __PRETTY_FUNCTION__, ch->sg_str, + __func__, ch->sg_str, membership == PIM_IFMEMBERSHIP_INCLUDE ? "INCLUDE" : "NOINFO", ch->interface->name); @@ -564,8 +585,7 @@ struct pim_ifchannel *pim_ifchannel_add(struct interface *ifp, RB_INSERT(pim_ifchannel_rb, &pim_ifp->ifchannel_rb, ch); - up = pim_upstream_add(pim_ifp->pim, sg, NULL, up_flags, - __PRETTY_FUNCTION__, ch); + up = pim_upstream_add(pim_ifp->pim, sg, NULL, up_flags, __func__, ch); ch->upstream = up; @@ -590,9 +610,27 @@ struct pim_ifchannel *pim_ifchannel_add(struct interface *ifp, else PIM_IF_FLAG_UNSET_ASSERT_TRACKING_DESIRED(ch->flags); + /* + * advertise MLAG Data to MLAG peer + */ + if (PIM_I_am_DualActive(pim_ifp)) { + up->dualactive_ifchannel_count++; + /* Sync once for upstream */ + if (up->dualactive_ifchannel_count == 1) { + PIM_UPSTREAM_FLAG_SET_MLAG_INTERFACE(up->flags); + pim_mlag_up_local_add(pim_ifp->pim, up); + } + if (PIM_DEBUG_MLAG) + zlog_debug( + "%s: New Dual active if-chnanel is added to upstream:%s " + "count:%d, flags:0x%x", + __func__, up->sg_str, + up->dualactive_ifchannel_count, up->flags); + } + if (PIM_DEBUG_PIM_TRACE) - zlog_debug("%s: ifchannel %s is created ", __PRETTY_FUNCTION__, - ch->sg_str); + zlog_debug("%s: ifchannel %s(%s) is created ", __func__, + ch->sg_str, ch->interface->name); return ch; } @@ -600,7 +638,7 @@ struct pim_ifchannel *pim_ifchannel_add(struct interface *ifp, static void ifjoin_to_noinfo(struct pim_ifchannel *ch, bool ch_del) { pim_forward_stop(ch, !ch_del); - pim_ifchannel_ifjoin_switch(__PRETTY_FUNCTION__, ch, PIM_IFJOIN_NOINFO); + pim_ifchannel_ifjoin_switch(__func__, ch, PIM_IFJOIN_NOINFO); if (ch_del) delete_on_noinfo(ch); } @@ -612,7 +650,7 @@ static int on_ifjoin_expiry_timer(struct thread *t) ch = THREAD_ARG(t); if (PIM_DEBUG_PIM_TRACE) - zlog_debug("%s: ifchannel %s expiry timer", __PRETTY_FUNCTION__, + zlog_debug("%s: ifchannel %s expiry timer", __func__, ch->sg_str); ifjoin_to_noinfo(ch, true); @@ -633,7 +671,7 @@ static int on_ifjoin_prune_pending_timer(struct thread *t) if (PIM_DEBUG_PIM_TRACE) zlog_debug( "%s: IFCHANNEL%s %s Prune Pending Timer Popped", - __PRETTY_FUNCTION__, pim_str_sg_dump(&ch->sg), + __func__, pim_str_sg_dump(&ch->sg), pim_ifchannel_ifjoin_name(ch->ifjoin_state, ch->flags)); if (ch->ifjoin_state == PIM_IFJOIN_PRUNE_PENDING) { @@ -695,8 +733,8 @@ static void check_recv_upstream(int is_join, struct interface *recv_ifp, if (pim_rpf_addr_is_inaddr_any(&up->rpf)) { /* RPF'(S,G) not found */ - zlog_warn("%s %s: RPF'%s not found", __FILE__, - __PRETTY_FUNCTION__, up->sg_str); + zlog_warn("%s %s: RPF'%s not found", __FILE__, __func__, + up->sg_str); return; } @@ -709,8 +747,8 @@ static void check_recv_upstream(int is_join, struct interface *recv_ifp, sizeof(rpf_str)); zlog_warn( "%s %s: (S,G)=%s upstream=%s not directed to RPF'(S,G)=%s on interface %s", - __FILE__, __PRETTY_FUNCTION__, up->sg_str, up_str, - rpf_str, recv_ifp->name); + __FILE__, __func__, up->sg_str, up_str, rpf_str, + recv_ifp->name); return; } /* upstream directed to RPF'(S,G) */ @@ -761,7 +799,7 @@ static int nonlocal_upstream(int is_join, struct interface *recv_ifp, char up_str[INET_ADDRSTRLEN]; pim_inet4_dump("<upstream?>", upstream, up_str, sizeof(up_str)); zlog_warn("%s: recv %s (S,G)=%s to non-local upstream=%s on %s", - __PRETTY_FUNCTION__, is_join ? "join" : "prune", + __func__, is_join ? "join" : "prune", pim_str_sg_dump(sg), up_str, recv_ifp->name); } @@ -778,8 +816,7 @@ static int nonlocal_upstream(int is_join, struct interface *recv_ifp, static void pim_ifchannel_ifjoin_handler(struct pim_ifchannel *ch, struct pim_interface *pim_ifp) { - pim_ifchannel_ifjoin_switch(__PRETTY_FUNCTION__, ch, - PIM_IFJOIN_JOIN); + pim_ifchannel_ifjoin_switch(__func__, ch, PIM_IFJOIN_JOIN); PIM_IF_FLAG_UNSET_S_G_RPT(ch->flags); /* check if the interface qualifies as an immediate * OIF @@ -833,8 +870,7 @@ void pim_ifchannel_join_add(struct interface *ifp, struct in_addr neigh_addr, pim_inet4_dump("<neigh?>", neigh_addr, neigh_str, sizeof(neigh_str)); zlog_warn("%s: Assert Loser recv Join%s from %s on %s", - __PRETTY_FUNCTION__, ch->sg_str, neigh_str, - ifp->name); + __func__, ch->sg_str, neigh_str, ifp->name); assert_action_a5(ch); } @@ -844,8 +880,7 @@ void pim_ifchannel_join_add(struct interface *ifp, struct in_addr neigh_addr, switch (ch->ifjoin_state) { case PIM_IFJOIN_NOINFO: - pim_ifchannel_ifjoin_switch(__PRETTY_FUNCTION__, ch, - PIM_IFJOIN_JOIN); + pim_ifchannel_ifjoin_switch(__func__, ch, PIM_IFJOIN_JOIN); if (pim_macro_chisin_oiflist(ch)) { pim_upstream_inherited_olist(pim_ifp->pim, ch->upstream); @@ -854,13 +889,14 @@ void pim_ifchannel_join_add(struct interface *ifp, struct in_addr neigh_addr, /* * If we are going to be a LHR, we need to note it */ - if (ch->upstream->parent && (ch->upstream->parent->flags - & PIM_UPSTREAM_FLAG_MASK_SRC_IGMP) + if (ch->upstream->parent && + (PIM_UPSTREAM_FLAG_TEST_CAN_BE_LHR( + ch->upstream->parent->flags)) && !(ch->upstream->flags & PIM_UPSTREAM_FLAG_MASK_SRC_LHR)) { pim_upstream_ref(ch->upstream, PIM_UPSTREAM_FLAG_MASK_SRC_LHR, - __PRETTY_FUNCTION__); + __func__); pim_upstream_keep_alive_timer_start( ch->upstream, pim_ifp->pim->keep_alive_time); } @@ -902,7 +938,7 @@ void pim_ifchannel_join_add(struct interface *ifp, struct in_addr neigh_addr, break; case PIM_IFJOIN_PRUNE: if (source_flags & PIM_ENCODE_RPT_BIT) - pim_ifchannel_ifjoin_switch(__PRETTY_FUNCTION__, ch, + pim_ifchannel_ifjoin_switch(__func__, ch, PIM_IFJOIN_NOINFO); else pim_ifchannel_ifjoin_handler(ch, pim_ifp); @@ -911,7 +947,7 @@ void pim_ifchannel_join_add(struct interface *ifp, struct in_addr neigh_addr, THREAD_OFF(ch->t_ifjoin_prune_pending_timer); if (source_flags & PIM_ENCODE_RPT_BIT) { THREAD_OFF(ch->t_ifjoin_expiry_timer); - pim_ifchannel_ifjoin_switch(__PRETTY_FUNCTION__, ch, + pim_ifchannel_ifjoin_switch(__func__, ch, PIM_IFJOIN_NOINFO); } else { pim_ifchannel_ifjoin_handler(ch, pim_ifp); @@ -947,8 +983,8 @@ void pim_ifchannel_prune(struct interface *ifp, struct in_addr upstream, if (PIM_DEBUG_PIM_TRACE) zlog_debug( "%s: Received prune with no relevant ifchannel %s%s state: %d", - __PRETTY_FUNCTION__, ifp->name, - pim_str_sg_dump(sg), source_flags); + __func__, ifp->name, pim_str_sg_dump(sg), + source_flags); return; } @@ -994,7 +1030,7 @@ void pim_ifchannel_prune(struct interface *ifp, struct in_addr upstream, case PIM_IFJOIN_JOIN: THREAD_OFF(ch->t_ifjoin_expiry_timer); - pim_ifchannel_ifjoin_switch(__PRETTY_FUNCTION__, ch, + pim_ifchannel_ifjoin_switch(__func__, ch, PIM_IFJOIN_PRUNE_PENDING); if (listcount(pim_ifp->pim_neighbor_list) > 1) @@ -1042,27 +1078,27 @@ void pim_ifchannel_prune(struct interface *ifp, struct in_addr upstream, } int pim_ifchannel_local_membership_add(struct interface *ifp, - struct prefix_sg *sg) + struct prefix_sg *sg, bool is_vxlan) { struct pim_ifchannel *ch, *starch; struct pim_interface *pim_ifp; struct pim_instance *pim; + int up_flags; /* PIM enabled on interface? */ pim_ifp = ifp->info; if (!pim_ifp) { if (PIM_DEBUG_EVENTS) zlog_debug("%s:%s Expected pim interface setup for %s", - __PRETTY_FUNCTION__, - pim_str_sg_dump(sg), ifp->name); + __func__, pim_str_sg_dump(sg), ifp->name); return 0; } if (!PIM_IF_TEST_PIM(pim_ifp->options)) { if (PIM_DEBUG_EVENTS) - zlog_debug("%s:%s PIM is not configured on this interface %s", - __PRETTY_FUNCTION__, - pim_str_sg_dump(sg), ifp->name); + zlog_debug( + "%s:%s PIM is not configured on this interface %s", + __func__, pim_str_sg_dump(sg), ifp->name); return 0; } @@ -1074,13 +1110,17 @@ int pim_ifchannel_local_membership_add(struct interface *ifp, if (PIM_DEBUG_PIM_EVENTS) zlog_debug( "%s: local membership (S,G)=%s ignored as group is SSM", - __PRETTY_FUNCTION__, - pim_str_sg_dump(sg)); + __func__, pim_str_sg_dump(sg)); return 1; } } - ch = pim_ifchannel_add(ifp, sg, 0, PIM_UPSTREAM_FLAG_MASK_SRC_IGMP); + /* vxlan term mroutes use ipmr-lo as local member to + * pull down multicast vxlan tunnel traffic + */ + up_flags = is_vxlan ? PIM_UPSTREAM_FLAG_MASK_SRC_VXLAN_TERM : + PIM_UPSTREAM_FLAG_MASK_SRC_IGMP; + ch = pim_ifchannel_add(ifp, sg, 0, up_flags); ifmembership_set(ch, PIM_IFMEMBERSHIP_INCLUDE); @@ -1094,9 +1134,8 @@ int pim_ifchannel_local_membership_add(struct interface *ifp, for (ALL_LIST_ELEMENTS_RO(up->sources, up_node, child)) { if (PIM_DEBUG_EVENTS) zlog_debug("%s %s: IGMP (S,G)=%s(%s) from %s", - __FILE__, __PRETTY_FUNCTION__, - child->sg_str, ifp->name, - up->sg_str); + __FILE__, __func__, child->sg_str, + ifp->name, up->sg_str); ch = pim_ifchannel_find(ifp, &child->sg); if (pim_upstream_evaluate_join_desired_interface( @@ -1168,9 +1207,8 @@ void pim_ifchannel_local_membership_del(struct interface *ifp, if (PIM_DEBUG_EVENTS) zlog_debug("%s %s: Prune(S,G)=%s(%s) from %s", - __FILE__, __PRETTY_FUNCTION__, - up->sg_str, ifp->name, - child->sg_str); + __FILE__, __func__, up->sg_str, + ifp->name, child->sg_str); ch = pim_ifchannel_find(ifp, &child->sg); /* @@ -1210,9 +1248,8 @@ void pim_ifchannel_update_could_assert(struct pim_ifchannel *ch) pim_inet4_dump("<src?>", ch->sg.src, src_str, sizeof(src_str)); pim_inet4_dump("<grp?>", ch->sg.grp, grp_str, sizeof(grp_str)); zlog_debug("%s: CouldAssert(%s,%s,%s) changed from %d to %d", - __PRETTY_FUNCTION__, src_str, grp_str, - ch->interface->name, old_couldassert, - new_couldassert); + __func__, src_str, grp_str, ch->interface->name, + old_couldassert, new_couldassert); } if (new_couldassert) { @@ -1259,8 +1296,7 @@ void pim_ifchannel_update_my_assert_metric(struct pim_ifchannel *ch) new_addr_str, sizeof(new_addr_str)); zlog_debug( "%s: my_assert_metric(%s,%s,%s) changed from %u,%u,%u,%s to %u,%u,%u,%s", - __PRETTY_FUNCTION__, src_str, grp_str, - ch->interface->name, + __func__, src_str, grp_str, ch->interface->name, ch->ifassert_my_metric.rpt_bit_flag, ch->ifassert_my_metric.metric_preference, ch->ifassert_my_metric.route_metric, old_addr_str, @@ -1294,8 +1330,8 @@ void pim_ifchannel_update_assert_tracking_desired(struct pim_ifchannel *ch) pim_inet4_dump("<grp?>", ch->sg.grp, grp_str, sizeof(grp_str)); zlog_debug( "%s: AssertTrackingDesired(%s,%s,%s) changed from %d to %d", - __PRETTY_FUNCTION__, src_str, grp_str, - ch->interface->name, old_atd, new_atd); + __func__, src_str, grp_str, ch->interface->name, + old_atd, new_atd); } if (new_atd) { @@ -1364,7 +1400,7 @@ void pim_ifchannel_set_star_g_join_state(struct pim_ifchannel *ch, int eom, if (PIM_DEBUG_PIM_TRACE) zlog_debug( - "%s: %s %s eom: %d join %u", __PRETTY_FUNCTION__, + "%s: %s %s eom: %d join %u", __func__, pim_ifchannel_ifjoin_name(ch->ifjoin_state, ch->flags), ch->sg_str, eom, join); if (!ch->sources) diff --git a/pimd/pim_ifchannel.h b/pimd/pim_ifchannel.h index b36c3236b0..3d5cbd8ecf 100644 --- a/pimd/pim_ifchannel.h +++ b/pimd/pim_ifchannel.h @@ -130,7 +130,7 @@ void pim_ifchannel_prune(struct interface *ifp, struct in_addr upstream, struct prefix_sg *sg, uint8_t source_flags, uint16_t holdtime); int pim_ifchannel_local_membership_add(struct interface *ifp, - struct prefix_sg *sg); + struct prefix_sg *sg, bool is_vxlan); void pim_ifchannel_local_membership_del(struct interface *ifp, struct prefix_sg *sg); diff --git a/pimd/pim_igmp.c b/pimd/pim_igmp.c index 39ef706f79..8d39d7e800 100644 --- a/pimd/pim_igmp.c +++ b/pimd/pim_igmp.c @@ -64,9 +64,8 @@ static int igmp_sock_open(struct in_addr ifaddr, struct interface *ifp, } else { zlog_warn( "%s %s: IGMP socket fd=%d interface %s: could not solve %s to group address: errno=%d: %s", - __FILE__, __PRETTY_FUNCTION__, fd, - inet_ntoa(ifaddr), PIM_ALL_ROUTERS, errno, - safe_strerror(errno)); + __FILE__, __func__, fd, inet_ntoa(ifaddr), + PIM_ALL_ROUTERS, errno, safe_strerror(errno)); } } @@ -81,7 +80,7 @@ static int igmp_sock_open(struct in_addr ifaddr, struct interface *ifp, } else { zlog_warn( "%s %s: IGMP socket fd=%d interface %s: could not solve %s to group address: errno=%d: %s", - __FILE__, __PRETTY_FUNCTION__, fd, inet_ntoa(ifaddr), + __FILE__, __func__, fd, inet_ntoa(ifaddr), PIM_ALL_SYSTEMS, errno, safe_strerror(errno)); } @@ -92,7 +91,7 @@ static int igmp_sock_open(struct in_addr ifaddr, struct interface *ifp, } else { zlog_warn( "%s %s: IGMP socket fd=%d interface %s: could not solve %s to group address: errno=%d: %s", - __FILE__, __PRETTY_FUNCTION__, fd, inet_ntoa(ifaddr), + __FILE__, __func__, fd, inet_ntoa(ifaddr), PIM_ALL_IGMP_ROUTERS, errno, safe_strerror(errno)); } @@ -119,8 +118,8 @@ static void igmp_sock_dump(array_t *igmp_sock_array) struct igmp_sock *igmp = array_get(igmp_sock_array, i); zlog_debug("%s %s: [%d/%d] igmp_addr=%s fd=%d", __FILE__, - __PRETTY_FUNCTION__, i, size, - inet_ntoa(igmp->ifaddr), igmp->fd); + __func__, i, size, inet_ntoa(igmp->ifaddr), + igmp->fd); } } #endif @@ -166,8 +165,7 @@ static int pim_igmp_other_querier_expire(struct thread *t) char ifaddr_str[INET_ADDRSTRLEN]; pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str)); - zlog_debug("%s: Querier %s resuming", __PRETTY_FUNCTION__, - ifaddr_str); + zlog_debug("%s: Querier %s resuming", __func__, ifaddr_str); } /* @@ -419,7 +417,7 @@ static int igmp_v1_recv_report(struct igmp_sock *igmp, struct in_addr from, struct igmp_group *group; struct in_addr group_addr; - on_trace(__PRETTY_FUNCTION__, igmp->interface, from); + on_trace(__func__, igmp->interface, from); if (igmp->mtrace_only) return 0; @@ -435,8 +433,7 @@ static int igmp_v1_recv_report(struct igmp_sock *igmp, struct in_addr from, igmp->rx_stats.report_v1++; if (PIM_DEBUG_IGMP_TRACE) { - zlog_warn("%s %s: FIXME WRITEME", __FILE__, - __PRETTY_FUNCTION__); + zlog_warn("%s %s: FIXME WRITEME", __FILE__, __func__); } memcpy(&group_addr, igmp_msg + 4, sizeof(struct in_addr)); @@ -1014,9 +1011,8 @@ static int igmp_group_timer(struct thread *t) char group_str[INET_ADDRSTRLEN]; pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str)); - zlog_debug("%s: Timer for group %s on interface %s", - __PRETTY_FUNCTION__, group_str, - group->group_igmp_sock->interface->name); + zlog_debug("%s: Timer for group %s on interface %s", __func__, + group_str, group->group_igmp_sock->interface->name); } zassert(group->group_filtermode_isexcl); @@ -1108,7 +1104,7 @@ struct igmp_group *igmp_add_group_by_addr(struct igmp_sock *igmp, if (!pim_is_group_224_4(group_addr)) { zlog_warn("%s: Group Specified is not part of 224.0.0.0/4", - __PRETTY_FUNCTION__); + __func__); return NULL; } @@ -1116,7 +1112,7 @@ struct igmp_group *igmp_add_group_by_addr(struct igmp_sock *igmp, if (PIM_DEBUG_IGMP_TRACE) zlog_debug( "%s: Group specified %s is part of 224.0.0.0/24", - __PRETTY_FUNCTION__, inet_ntoa(group_addr)); + __func__, inet_ntoa(group_addr)); return NULL; } /* diff --git a/pimd/pim_igmp_mtrace.c b/pimd/pim_igmp_mtrace.c index 309b8c1495..1cecd976cd 100644 --- a/pimd/pim_igmp_mtrace.c +++ b/pimd/pim_igmp_mtrace.c @@ -132,8 +132,8 @@ static bool mtrace_fwd_info(struct pim_instance *pim, if (!up->rpf.source_nexthop.interface) { if (PIM_DEBUG_TRACE) - zlog_debug("%s: up %s RPF is not present", - __PRETTY_FUNCTION__, up->sg_str); + zlog_debug("%s: up %s RPF is not present", __func__, + up->sg_str); return false; } diff --git a/pimd/pim_igmpv2.c b/pimd/pim_igmpv2.c index 19c3768813..af598d040d 100644 --- a/pimd/pim_igmpv2.c +++ b/pimd/pim_igmpv2.c @@ -109,7 +109,7 @@ int igmp_v2_recv_report(struct igmp_sock *igmp, struct in_addr from, struct in_addr group_addr; char group_str[INET_ADDRSTRLEN]; - on_trace(__PRETTY_FUNCTION__, igmp->interface, from); + on_trace(__func__, igmp->interface, from); if (igmp->mtrace_only) return 0; @@ -158,7 +158,7 @@ int igmp_v2_recv_leave(struct igmp_sock *igmp, struct in_addr from, struct in_addr group_addr; char group_str[INET_ADDRSTRLEN]; - on_trace(__PRETTY_FUNCTION__, igmp->interface, from); + on_trace(__func__, igmp->interface, from); if (igmp->mtrace_only) return 0; diff --git a/pimd/pim_igmpv3.c b/pimd/pim_igmpv3.c index 2d58340c8c..ffd872ce03 100644 --- a/pimd/pim_igmpv3.c +++ b/pimd/pim_igmpv3.c @@ -126,7 +126,7 @@ static int igmp_source_timer(struct thread *t) sizeof(source_str)); zlog_debug( "%s: Source timer expired for group %s source %s on %s", - __PRETTY_FUNCTION__, group_str, source_str, + __func__, group_str, source_str, group->group_igmp_sock->interface->name); } @@ -332,8 +332,7 @@ void igmp_source_free(struct igmp_source *source) static void source_channel_oil_detach(struct igmp_source *source) { if (source->source_channel_oil) { - pim_channel_oil_del(source->source_channel_oil, - __PRETTY_FUNCTION__); + pim_channel_oil_del(source->source_channel_oil, __func__); source->source_channel_oil = NULL; } } @@ -378,7 +377,7 @@ void igmp_source_delete(struct igmp_source *source) sizeof(source_str)); zlog_warn( "%s: forwarding=ON(!) IGMP source %s for group %s from socket %d interface %s", - __PRETTY_FUNCTION__, source_str, group_str, + __func__, source_str, group_str, group->group_igmp_sock->fd, group->group_igmp_sock->interface->name); /* warning only */ @@ -545,8 +544,8 @@ void igmpv3_report_isin(struct igmp_sock *igmp, struct in_addr from, struct in_addr group_addr, int num_sources, struct in_addr *sources) { - on_trace(__PRETTY_FUNCTION__, igmp->interface, from, group_addr, - num_sources, sources); + on_trace(__func__, igmp->interface, from, group_addr, num_sources, + sources); allow(igmp, from, group_addr, num_sources, sources); } @@ -654,8 +653,7 @@ void igmpv3_report_isex(struct igmp_sock *igmp, struct in_addr from, struct interface *ifp = igmp->interface; struct igmp_group *group; - on_trace(__PRETTY_FUNCTION__, ifp, from, group_addr, num_sources, - sources); + on_trace(__func__, ifp, from, group_addr, num_sources, sources); if (pim_is_group_filtered(ifp->info, &group_addr)) return; @@ -774,8 +772,7 @@ void igmpv3_report_toin(struct igmp_sock *igmp, struct in_addr from, struct interface *ifp = igmp->interface; struct igmp_group *group; - on_trace(__PRETTY_FUNCTION__, ifp, from, group_addr, num_sources, - sources); + on_trace(__func__, ifp, from, group_addr, num_sources, sources); /* * If the requested filter mode is INCLUDE *and* the requested source @@ -937,8 +934,7 @@ void igmpv3_report_toex(struct igmp_sock *igmp, struct in_addr from, struct interface *ifp = igmp->interface; struct igmp_group *group; - on_trace(__PRETTY_FUNCTION__, ifp, from, group_addr, num_sources, - sources); + on_trace(__func__, ifp, from, group_addr, num_sources, sources); /* non-existant group is created as INCLUDE {empty} */ group = igmp_add_group_by_addr(igmp, group_addr); @@ -964,8 +960,8 @@ void igmpv3_report_allow(struct igmp_sock *igmp, struct in_addr from, struct in_addr group_addr, int num_sources, struct in_addr *sources) { - on_trace(__PRETTY_FUNCTION__, igmp->interface, from, group_addr, - num_sources, sources); + on_trace(__func__, igmp->interface, from, group_addr, num_sources, + sources); allow(igmp, from, group_addr, num_sources, sources); } @@ -1137,7 +1133,7 @@ static int group_retransmit_sources(struct igmp_group *group, group_str, sizeof(group_str)); zlog_warn( "%s: group %s on %s: s_flag=1 unable to fit %d sources into buf_size=%zu (max_sources=%d)", - __PRETTY_FUNCTION__, group_str, + __func__, group_str, igmp->interface->name, num_sources_tosend1, sizeof(query_buf1), query_buf1_max_sources); @@ -1181,9 +1177,9 @@ static int group_retransmit_sources(struct igmp_group *group, sizeof(group_str)); zlog_warn( "%s: group %s on %s: s_flag=0 unable to fit %d sources into buf_size=%zu (max_sources=%d)", - __PRETTY_FUNCTION__, group_str, - igmp->interface->name, num_sources_tosend2, - sizeof(query_buf2), query_buf2_max_sources); + __func__, group_str, igmp->interface->name, + num_sources_tosend2, sizeof(query_buf2), + query_buf2_max_sources); } else { /* RFC3376: 4.1.12. IP Destination Addresses for Queries @@ -1469,8 +1465,7 @@ void igmpv3_report_block(struct igmp_sock *igmp, struct in_addr from, struct interface *ifp = igmp->interface; struct igmp_group *group; - on_trace(__PRETTY_FUNCTION__, ifp, from, group_addr, num_sources, - sources); + on_trace(__func__, ifp, from, group_addr, num_sources, sources); /* non-existant group is created as INCLUDE {empty} */ group = igmp_add_group_by_addr(igmp, group_addr); @@ -1524,7 +1519,7 @@ void igmp_group_timer_lower_to_lmqt(struct igmp_group *group) sizeof(group_str)); zlog_debug( "%s: group %s on %s: LMQC=%d LMQI=%d dsec LMQT=%d msec", - __PRETTY_FUNCTION__, group_str, ifname, lmqc, lmqi_dsec, + __func__, group_str, ifname, lmqc, lmqi_dsec, lmqt_msec); } @@ -1564,8 +1559,8 @@ void igmp_source_timer_lower_to_lmqt(struct igmp_source *source) sizeof(source_str)); zlog_debug( "%s: group %s source %s on %s: LMQC=%d LMQI=%d dsec LMQT=%d msec", - __PRETTY_FUNCTION__, group_str, source_str, ifname, - lmqc, lmqi_dsec, lmqt_msec); + __func__, group_str, source_str, ifname, lmqc, + lmqi_dsec, lmqt_msec); } igmp_source_timer_on(group, source, lmqt_msec); @@ -1593,8 +1588,7 @@ void igmp_v3_send_query(struct igmp_group *group, int fd, const char *ifname, flog_err( EC_LIB_DEVELOPMENT, "%s %s: unable to send: msg_size=%zd larger than query_buf_size=%d", - __FILE__, __PRETTY_FUNCTION__, msg_size, - query_buf_size); + __FILE__, __func__, msg_size, query_buf_size); return; } @@ -1691,7 +1685,7 @@ void igmp_v3_send_query(struct igmp_group *group, int fd, const char *ifname, sizeof(group_str)); zlog_warn( "%s: to %s on %s: group=%s sources=%d: s_flag is clear for general query!", - __PRETTY_FUNCTION__, dst_str, ifname, group_str, + __func__, dst_str, ifname, group_str, num_sources); } } diff --git a/pimd/pim_instance.c b/pimd/pim_instance.c index 955ad14b01..347b0fc284 100644 --- a/pimd/pim_instance.c +++ b/pimd/pim_instance.c @@ -101,7 +101,7 @@ static struct pim_instance *pim_instance_init(struct vrf *vrf) hash_name); if (PIM_DEBUG_ZEBRA) - zlog_debug("%s: NHT rpf hash init ", __PRETTY_FUNCTION__); + zlog_debug("%s: NHT rpf hash init ", __func__); pim->ssm_info = pim_ssm_init(); @@ -165,7 +165,7 @@ static int pim_vrf_enable(struct vrf *vrf) { struct pim_instance *pim = (struct pim_instance *)vrf->info; - zlog_debug("%s: for %s", __PRETTY_FUNCTION__, vrf->name); + zlog_debug("%s: for %s", __func__, vrf->name); pim_mroute_socket_enable(pim); diff --git a/pimd/pim_instance.h b/pimd/pim_instance.h index da0c75decb..7b1fd2e172 100644 --- a/pimd/pim_instance.h +++ b/pimd/pim_instance.h @@ -48,6 +48,46 @@ enum pim_spt_switchover { PIM_SPT_INFINITY, }; +/* stats for updates rxed from the MLAG component during the life of a + * session + */ +struct pim_mlag_msg_stats { + uint32_t mroute_add_rx; + uint32_t mroute_add_tx; + uint32_t mroute_del_rx; + uint32_t mroute_del_tx; + uint32_t mlag_status_updates; + uint32_t pim_status_updates; + uint32_t vxlan_updates; + uint32_t peer_zebra_status_updates; +}; + +struct pim_mlag_stats { + /* message stats are reset when the connection to mlagd flaps */ + struct pim_mlag_msg_stats msg; + uint32_t mlagd_session_downs; + uint32_t peer_session_downs; + uint32_t peer_zebra_downs; +}; + +enum pim_mlag_flags { + PIM_MLAGF_NONE = 0, + /* connection to the local MLAG daemon is up */ + PIM_MLAGF_LOCAL_CONN_UP = (1 << 0), + /* connection to the MLAG daemon on the peer switch is up. note + * that there is no direct connection between FRR and the peer MLAG + * daemon. this is just a peer-session status provided by the local + * MLAG daemon. + */ + PIM_MLAGF_PEER_CONN_UP = (1 << 1), + /* status update rxed from the local daemon */ + PIM_MLAGF_STATUS_RXED = (1 << 2), + /* initial dump of data done post peerlink flap */ + PIM_MLAGF_PEER_REPLAY_DONE = (1 << 3), + /* zebra is up on the peer */ + PIM_MLAGF_PEER_ZEBRA_UP = (1 << 4) +}; + struct pim_router { struct thread_master *master; @@ -65,7 +105,7 @@ struct pim_router { */ vrf_id_t vrf_id; - enum mlag_role role; + enum mlag_role mlag_role; uint32_t pim_mlag_intf_cnt; /* if true we have registered with MLAG */ bool mlag_process_register; @@ -77,6 +117,12 @@ struct pim_router { struct stream_fifo *mlag_fifo; struct stream *mlag_stream; struct thread *zpthread_mlag_write; + struct in_addr anycast_vtep_ip; + struct in_addr local_vtep_ip; + struct pim_mlag_stats mlag_stats; + enum pim_mlag_flags mlag_flags; + char peerlink_rif[INTERFACE_NAMSIZ]; + struct interface *peerlink_rif_p; }; /* Per VRF PIM DB */ diff --git a/pimd/pim_join.c b/pimd/pim_join.c index fbb547c80e..62bd2360c3 100644 --- a/pimd/pim_join.c +++ b/pimd/pim_join.c @@ -64,7 +64,7 @@ static void recv_join(struct interface *ifp, struct pim_neighbor *neigh, sizeof(neigh_str)); zlog_debug( "%s: join (S,G)=%s rpt=%d wc=%d upstream=%s holdtime=%d from %s on %s", - __PRETTY_FUNCTION__, pim_str_sg_dump(sg), + __func__, pim_str_sg_dump(sg), !!(source_flags & PIM_RPT_BIT_MASK), !!(source_flags & PIM_WILDCARD_BIT_MASK), up_str, holdtime, neigh_str, ifp->name); @@ -84,8 +84,8 @@ static void recv_join(struct interface *ifp, struct pim_neighbor *neigh, struct pim_rpf *rp = RP(pim_ifp->pim, sg->grp); if (!rp) { - zlog_warn("%s: Lookup of RP failed for %pSG4", - __PRETTY_FUNCTION__, sg); + zlog_warn("%s: Lookup of RP failed for %pSG4", __func__, + sg); return; } /* @@ -99,8 +99,9 @@ static void recv_join(struct interface *ifp, struct pim_neighbor *neigh, sizeof(received_rp)); pim_inet4_dump("<local?>", rp->rpf_addr.u.prefix4, local_rp, sizeof(local_rp)); - zlog_warn("%s: Specified RP(%s) in join is different than our configured RP(%s)", - __PRETTY_FUNCTION__, received_rp, local_rp); + zlog_warn( + "%s: Specified RP(%s) in join is different than our configured RP(%s)", + __func__, received_rp, local_rp); return; } @@ -126,7 +127,7 @@ static void recv_prune(struct interface *ifp, struct pim_neighbor *neigh, sizeof(neigh_str)); zlog_debug( "%s: prune (S,G)=%s rpt=%d wc=%d upstream=%s holdtime=%d from %s on %s", - __PRETTY_FUNCTION__, pim_str_sg_dump(sg), + __func__, pim_str_sg_dump(sg), source_flags & PIM_RPT_BIT_MASK, source_flags & PIM_WILDCARD_BIT_MASK, up_str, holdtime, neigh_str, ifp->name); @@ -143,8 +144,9 @@ static void recv_prune(struct interface *ifp, struct pim_neighbor *neigh, if (!rp) { if (PIM_DEBUG_PIM_TRACE) - zlog_debug("%s: RP for %pSG4 completely failed lookup", - __PRETTY_FUNCTION__, sg); + zlog_debug( + "%s: RP for %pSG4 completely failed lookup", + __func__, sg); return; } // Ignoring Prune *,G's at the moment. @@ -184,7 +186,7 @@ int pim_joinprune_recv(struct interface *ifp, struct pim_neighbor *neigh, char src_str[INET_ADDRSTRLEN]; pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str)); zlog_warn("%s: pim_parse_addr_ucast() failure: from %s on %s", - __PRETTY_FUNCTION__, src_str, ifp->name); + __func__, src_str, ifp->name); return -1; } buf += addr_offset; @@ -195,9 +197,9 @@ int pim_joinprune_recv(struct interface *ifp, struct pim_neighbor *neigh, if (msg_upstream_addr.family != AF_INET) { char src_str[INET_ADDRSTRLEN]; pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str)); - zlog_warn("%s: ignoring join/prune directed to unexpected addr family=%d from %s on %s", - __PRETTY_FUNCTION__, msg_upstream_addr.family, - src_str, ifp->name); + zlog_warn( + "%s: ignoring join/prune directed to unexpected addr family=%d from %s on %s", + __func__, msg_upstream_addr.family, src_str, ifp->name); return -2; } @@ -207,7 +209,7 @@ int pim_joinprune_recv(struct interface *ifp, struct pim_neighbor *neigh, pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str)); zlog_warn( "%s: short join/prune message buffer for group list: size=%d minimum=%d from %s on %s", - __PRETTY_FUNCTION__, remain, 4, src_str, ifp->name); + __func__, remain, 4, src_str, ifp->name); return -4; } @@ -226,8 +228,8 @@ int pim_joinprune_recv(struct interface *ifp, struct pim_neighbor *neigh, upstream_str, sizeof(upstream_str)); zlog_debug( "%s: join/prune upstream=%s groups=%d holdtime=%d from %s on %s", - __PRETTY_FUNCTION__, upstream_str, msg_num_groups, - msg_holdtime, src_str, ifp->name); + __func__, upstream_str, msg_num_groups, msg_holdtime, + src_str, ifp->name); } /* Scan groups */ @@ -254,8 +256,7 @@ int pim_joinprune_recv(struct interface *ifp, struct pim_neighbor *neigh, sizeof(src_str)); zlog_warn( "%s: short join/prune buffer for source list: size=%d minimum=%d from %s on %s", - __PRETTY_FUNCTION__, remain, 4, src_str, - ifp->name); + __func__, remain, 4, src_str, ifp->name); return -6; } @@ -276,7 +277,7 @@ int pim_joinprune_recv(struct interface *ifp, struct pim_neighbor *neigh, sizeof(group_str)); zlog_debug( "%s: join/prune upstream=%s group=%s/32 join_src=%d prune_src=%d from %s on %s", - __PRETTY_FUNCTION__, upstream_str, group_str, + __func__, upstream_str, group_str, msg_num_joined_sources, msg_num_pruned_sources, src_str, ifp->name); } @@ -345,8 +346,7 @@ int pim_joinprune_recv(struct interface *ifp, struct pim_neighbor *neigh, if (PIM_DEBUG_PIM_TRACE) zlog_debug( "%s: SGRpt flag is set, del inherit oif from up %s", - __PRETTY_FUNCTION__, - up->sg_str); + __func__, up->sg_str); pim_channel_del_inherited_oif( up->channel_oil, starg_ch->interface, @@ -445,17 +445,15 @@ int pim_joinprune_send(struct pim_rpf *rpf, struct list *groups) if (rpf->source_nexthop.interface) pim_ifp = rpf->source_nexthop.interface->info; else { - zlog_warn("%s: RPF interface is not present", - __PRETTY_FUNCTION__); + zlog_warn("%s: RPF interface is not present", __func__); return -1; } - on_trace(__PRETTY_FUNCTION__, rpf->source_nexthop.interface, - rpf->rpf_addr.u.prefix4); + on_trace(__func__, rpf->source_nexthop.interface, + rpf->rpf_addr.u.prefix4); if (!pim_ifp) { - zlog_warn("%s: multicast not enabled on interface %s", - __PRETTY_FUNCTION__, + zlog_warn("%s: multicast not enabled on interface %s", __func__, rpf->source_nexthop.interface->name); return -1; } @@ -466,7 +464,7 @@ int pim_joinprune_send(struct pim_rpf *rpf, struct list *groups) pim_inet4_dump("<dst?>", rpf->rpf_addr.u.prefix4, dst_str, sizeof(dst_str)); zlog_debug("%s: upstream=%s is myself on interface %s", - __PRETTY_FUNCTION__, dst_str, + __func__, dst_str, rpf->source_nexthop.interface->name); } return 0; @@ -515,7 +513,7 @@ int pim_joinprune_send(struct pim_rpf *rpf, struct list *groups) sizeof(grp_str)); zlog_debug( "%s: sending (G)=%s to upstream=%s on interface %s", - __PRETTY_FUNCTION__, grp_str, dst_str, + __func__, grp_str, dst_str, rpf->source_nexthop.interface->name); } @@ -530,7 +528,7 @@ int pim_joinprune_send(struct pim_rpf *rpf, struct list *groups) rpf->source_nexthop.interface->name)) { zlog_warn( "%s: could not send PIM message on interface %s", - __PRETTY_FUNCTION__, + __func__, rpf->source_nexthop.interface->name); } @@ -571,8 +569,7 @@ int pim_joinprune_send(struct pim_rpf *rpf, struct list *groups) if (PIM_DEBUG_PIM_TRACE) zlog_debug( "%s: interface %s num_joins %u num_prunes %u", - __PRETTY_FUNCTION__, - rpf->source_nexthop.interface->name, + __func__, rpf->source_nexthop.interface->name, ntohs(grp->joins), ntohs(grp->prunes)); grp = (struct pim_jp_groups *)curr_ptr; @@ -587,7 +584,7 @@ int pim_joinprune_send(struct pim_rpf *rpf, struct list *groups) rpf->source_nexthop.interface->name)) { zlog_warn( "%s: could not send PIM message on interface %s", - __PRETTY_FUNCTION__, + __func__, rpf->source_nexthop.interface->name); } @@ -606,8 +603,7 @@ int pim_joinprune_send(struct pim_rpf *rpf, struct list *groups) rpf->source_nexthop.interface->name)) { zlog_warn( "%s: could not send PIM message on interface %s", - __PRETTY_FUNCTION__, - rpf->source_nexthop.interface->name); + __func__, rpf->source_nexthop.interface->name); } } return 0; diff --git a/pimd/pim_jp_agg.c b/pimd/pim_jp_agg.c index 2662c9eae6..5279a00855 100644 --- a/pimd/pim_jp_agg.c +++ b/pimd/pim_jp_agg.c @@ -239,8 +239,8 @@ void pim_jp_agg_upstream_verification(struct pim_upstream *up, bool ignore) if (!up->rpf.source_nexthop.interface) { if (PIM_DEBUG_PIM_TRACE) - zlog_debug("%s: up %s RPF is not present", - __PRETTY_FUNCTION__, up->sg_str); + zlog_debug("%s: up %s RPF is not present", __func__, + up->sg_str); return; } diff --git a/pimd/pim_macro.c b/pimd/pim_macro.c index 6691cc00d6..c6961d30c2 100644 --- a/pimd/pim_macro.c +++ b/pimd/pim_macro.c @@ -113,8 +113,7 @@ int pim_macro_ch_lost_assert(const struct pim_ifchannel *ch) ifp = ch->interface; if (!ifp) { - zlog_warn("%s: (S,G)=%s: null interface", __PRETTY_FUNCTION__, - ch->sg_str); + zlog_warn("%s: (S,G)=%s: null interface", __func__, ch->sg_str); return 0; /* false */ } @@ -125,7 +124,7 @@ int pim_macro_ch_lost_assert(const struct pim_ifchannel *ch) pim_ifp = ifp->info; if (!pim_ifp) { zlog_warn("%s: (S,G)=%s: multicast not enabled on interface %s", - __PRETTY_FUNCTION__, ch->sg_str, ifp->name); + __func__, ch->sg_str, ifp->name); return 0; /* false */ } @@ -158,10 +157,11 @@ int pim_macro_ch_lost_assert(const struct pim_ifchannel *ch) int pim_macro_chisin_pim_include(const struct pim_ifchannel *ch) { struct pim_interface *pim_ifp = ch->interface->info; + bool mlag_active = false; if (!pim_ifp) { zlog_warn("%s: (S,G)=%s: multicast not enabled on interface %s", - __PRETTY_FUNCTION__, ch->sg_str, ch->interface->name); + __func__, ch->sg_str, ch->interface->name); return 0; /* false */ } @@ -173,9 +173,21 @@ int pim_macro_chisin_pim_include(const struct pim_ifchannel *ch) if (ch->ifassert_winner.s_addr == pim_ifp->primary_address.s_addr) return 1; /* true */ + /* + * When we have a activeactive interface we need to signal + * that this interface is interesting to the upstream + * decision to JOIN *if* we are syncing over the interface + */ + if (pim_ifp->activeactive) { + struct pim_upstream *up = ch->upstream; + + if (PIM_UPSTREAM_FLAG_TEST_MLAG_INTERFACE(up->flags)) + mlag_active = true; + } + return ( /* I_am_DR( I ) ? */ - PIM_I_am_DR(pim_ifp) && + (PIM_I_am_DR(pim_ifp) || mlag_active) && /* lost_assert(S,G,I) == false ? */ (!pim_macro_ch_lost_assert(ch))); } @@ -221,8 +233,7 @@ int pim_macro_ch_could_assert_eval(const struct pim_ifchannel *ch) ifp = ch->interface; if (!ifp) { - zlog_warn("%s: (S,G)=%s: null interface", __PRETTY_FUNCTION__, - ch->sg_str); + zlog_warn("%s: (S,G)=%s: null interface", __func__, ch->sg_str); return 0; /* false */ } @@ -379,15 +390,14 @@ int pim_macro_assert_tracking_desired_eval(const struct pim_ifchannel *ch) ifp = ch->interface; if (!ifp) { - zlog_warn("%s: (S,G)=%s: null interface", __PRETTY_FUNCTION__, - ch->sg_str); + zlog_warn("%s: (S,G)=%s: null interface", __func__, ch->sg_str); return 0; /* false */ } pim_ifp = ifp->info; if (!pim_ifp) { zlog_warn("%s: (S,G)=%s: multicast not enabled on interface %s", - __PRETTY_FUNCTION__, ch->sg_str, ch->interface->name); + __func__, ch->sg_str, ch->interface->name); return 0; /* false */ } diff --git a/pimd/pim_mlag.c b/pimd/pim_mlag.c index f60c18204b..304e6ac6bc 100644 --- a/pimd/pim_mlag.c +++ b/pimd/pim_mlag.c @@ -25,14 +25,540 @@ #include "pimd.h" #include "pim_mlag.h" +#include "pim_upstream.h" +#include "pim_vxlan.h" extern struct zclient *zclient; +#define PIM_MLAG_METADATA_LEN 4 + +/*********************ACtual Data processing *****************************/ +/* TBD: There can be duplicate updates to FIB***/ +#define PIM_MLAG_ADD_OIF_TO_OIL(ch, ch_oil) \ + do { \ + if (PIM_DEBUG_MLAG) \ + zlog_debug( \ + "%s: add Dual-active Interface to %s " \ + "to oil:%s", \ + __func__, ch->interface->name, ch->sg_str); \ + pim_channel_add_oif(ch_oil, ch->interface, \ + PIM_OIF_FLAG_PROTO_IGMP, __func__); \ + } while (0) + +#define PIM_MLAG_DEL_OIF_TO_OIL(ch, ch_oil) \ + do { \ + if (PIM_DEBUG_MLAG) \ + zlog_debug( \ + "%s: del Dual-active Interface to %s " \ + "to oil:%s", \ + __func__, ch->interface->name, ch->sg_str); \ + pim_channel_del_oif(ch_oil, ch->interface, \ + PIM_OIF_FLAG_PROTO_IGMP, __func__); \ + } while (0) + + +static void pim_mlag_calculate_df_for_ifchannels(struct pim_upstream *up, + bool is_df) +{ + struct listnode *chnode; + struct listnode *chnextnode; + struct pim_ifchannel *ch; + struct pim_interface *pim_ifp = NULL; + struct channel_oil *ch_oil = NULL; + + ch_oil = (up) ? up->channel_oil : NULL; + + if (!ch_oil) + return; + + if (PIM_DEBUG_MLAG) + zlog_debug("%s: Calculating DF for Dual active if-channel%s", + __func__, up->sg_str); + + for (ALL_LIST_ELEMENTS(up->ifchannels, chnode, chnextnode, ch)) { + pim_ifp = (ch->interface) ? ch->interface->info : NULL; + if (!pim_ifp || !PIM_I_am_DualActive(pim_ifp)) + continue; + + if (is_df) + PIM_MLAG_ADD_OIF_TO_OIL(ch, ch_oil); + else + PIM_MLAG_DEL_OIF_TO_OIL(ch, ch_oil); + } +} + +static void pim_mlag_inherit_mlag_flags(struct pim_upstream *up, bool is_df) +{ + struct listnode *listnode; + struct pim_upstream *child; + + for (ALL_LIST_ELEMENTS_RO(up->sources, listnode, child)) { + PIM_UPSTREAM_FLAG_SET_MLAG_PEER(child->flags); + if (is_df) + PIM_UPSTREAM_FLAG_UNSET_MLAG_NON_DF(child->flags); + else + PIM_UPSTREAM_FLAG_SET_MLAG_NON_DF(child->flags); + pim_mlag_calculate_df_for_ifchannels(child, is_df); + } +} + +/******************************* pim upstream sync **************************/ +/* Update DF role for the upstream entry and return true on role change */ +bool pim_mlag_up_df_role_update(struct pim_instance *pim, + struct pim_upstream *up, bool is_df, const char *reason) +{ + struct channel_oil *c_oil = up->channel_oil; + bool old_is_df = !PIM_UPSTREAM_FLAG_TEST_MLAG_NON_DF(up->flags); + struct pim_interface *vxlan_ifp; + + if (is_df == old_is_df) { + if (PIM_DEBUG_MLAG) + zlog_debug( + "%s: Ignoring Role update for %s, since no change", + __func__, up->sg_str); + return false; + } + + if (PIM_DEBUG_MLAG) + zlog_debug("local MLAG mroute %s role changed to %s based on %s", + up->sg_str, is_df ? "df" : "non-df", reason); + + if (is_df) + PIM_UPSTREAM_FLAG_UNSET_MLAG_NON_DF(up->flags); + else + PIM_UPSTREAM_FLAG_SET_MLAG_NON_DF(up->flags); + + + /* + * This Upstream entry synced to peer Because of Dual-active + * Interface configuration + */ + if (PIM_UPSTREAM_FLAG_TEST_MLAG_INTERFACE(up->flags)) { + pim_mlag_calculate_df_for_ifchannels(up, is_df); + pim_mlag_inherit_mlag_flags(up, is_df); + } + + /* If the DF role has changed check if ipmr-lo needs to be + * muted/un-muted. Active-Active devices and vxlan termination + * devices (ipmr-lo) are suppressed on the non-DF. + * This may leave the mroute with the empty OIL in which case the + * the forwarding entry's sole purpose is to just blackhole the flow + * headed to the switch. + */ + if (c_oil) { + vxlan_ifp = pim_vxlan_get_term_ifp(pim); + if (vxlan_ifp) + pim_channel_update_oif_mute(c_oil, vxlan_ifp); + } + + /* If DF role changed on a (*,G) termination mroute update the + * associated DF role on the inherited (S,G) entries + */ + if ((up->sg.src.s_addr == INADDR_ANY) && + PIM_UPSTREAM_FLAG_TEST_MLAG_VXLAN(up->flags)) + pim_vxlan_inherit_mlag_flags(pim, up, true /* inherit */); + + return true; +} + +/* Run per-upstream entry DF election and return true on role change */ +static bool pim_mlag_up_df_role_elect(struct pim_instance *pim, + struct pim_upstream *up) +{ + bool is_df; + uint32_t peer_cost; + uint32_t local_cost; + bool rv; + + if (!pim_up_mlag_is_local(up) + && !PIM_UPSTREAM_FLAG_TEST_MLAG_INTERFACE(up->flags)) + return false; + + /* We are yet to rx a status update from the local MLAG daemon so + * we will assume DF status. + */ + if (!(router->mlag_flags & PIM_MLAGF_STATUS_RXED)) + return pim_mlag_up_df_role_update(pim, up, + true /*is_df*/, "mlagd-down"); + + /* If not connected to peer assume DF role on the MLAG primary + * switch (and non-DF on the secondary switch. + */ + if (!(router->mlag_flags & PIM_MLAGF_PEER_CONN_UP)) { + is_df = (router->mlag_role == MLAG_ROLE_PRIMARY) ? true : false; + return pim_mlag_up_df_role_update(pim, up, + is_df, "peer-down"); + } + + /* If MLAG peer session is up but zebra is down on the peer + * assume DF role. + */ + if (!(router->mlag_flags & PIM_MLAGF_PEER_ZEBRA_UP)) + return pim_mlag_up_df_role_update(pim, up, + true /*is_df*/, "zebra-down"); + + /* If we are connected to peer switch but don't have a mroute + * from it we have to assume non-DF role to avoid duplicates. + * Note: When the peer connection comes up we wait for initial + * replay to complete before moving "strays" i.e. local-mlag-mroutes + * without a peer reference to non-df role. + */ + if (!PIM_UPSTREAM_FLAG_TEST_MLAG_PEER(up->flags)) + return pim_mlag_up_df_role_update(pim, up, + false /*is_df*/, "no-peer-mroute"); + + /* switch with the lowest RPF cost wins. if both switches have the same + * cost MLAG role is used as a tie breaker (MLAG primary wins). + */ + peer_cost = up->mlag.peer_mrib_metric; + local_cost = pim_up_mlag_local_cost(up); + if (local_cost == peer_cost) { + is_df = (router->mlag_role == MLAG_ROLE_PRIMARY) ? true : false; + rv = pim_mlag_up_df_role_update(pim, up, is_df, "equal-cost"); + } else { + is_df = (local_cost < peer_cost) ? true : false; + rv = pim_mlag_up_df_role_update(pim, up, is_df, "cost"); + } + + return rv; +} + +/* Handle upstream entry add from the peer MLAG switch - + * - if a local entry doesn't exist one is created with reference + * _MLAG_PEER + * - if a local entry exists and has a MLAG OIF DF election is run. + * the non-DF switch stop forwarding traffic to MLAG devices. + */ +static void pim_mlag_up_peer_add(struct mlag_mroute_add *msg) +{ + struct pim_upstream *up; + struct pim_instance *pim; + int flags = 0; + struct prefix_sg sg; + struct vrf *vrf; + char sg_str[PIM_SG_LEN]; + + memset(&sg, 0, sizeof(struct prefix_sg)); + sg.src.s_addr = htonl(msg->source_ip); + sg.grp.s_addr = htonl(msg->group_ip); + if (PIM_DEBUG_MLAG) + pim_str_sg_set(&sg, sg_str); + + if (PIM_DEBUG_MLAG) + zlog_debug("peer MLAG mroute add %s:%s cost %d", + msg->vrf_name, sg_str, msg->cost_to_rp); + + /* XXX - this is not correct. we MUST cache updates to avoid losing + * an entry because of race conditions with the peer switch. + */ + vrf = vrf_lookup_by_name(msg->vrf_name); + if (!vrf) { + if (PIM_DEBUG_MLAG) + zlog_debug("peer MLAG mroute add failed %s:%s; no vrf", + msg->vrf_name, sg_str); + return; + } + pim = vrf->info; + + up = pim_upstream_find(pim, &sg); + if (up) { + /* upstream already exists; create peer reference if it + * doesn't already exist. + */ + if (!PIM_UPSTREAM_FLAG_TEST_MLAG_PEER(up->flags)) + pim_upstream_ref(up, PIM_UPSTREAM_FLAG_MASK_MLAG_PEER, + __func__); + } else { + PIM_UPSTREAM_FLAG_SET_MLAG_PEER(flags); + up = pim_upstream_add(pim, &sg, NULL /*iif*/, flags, __func__, + NULL /*if_ch*/); + + if (!up) { + if (PIM_DEBUG_MLAG) + zlog_debug("peer MLAG mroute add failed %s:%s", + vrf->name, sg_str); + return; + } + } + up->mlag.peer_mrib_metric = msg->cost_to_rp; + pim_mlag_up_df_role_elect(pim, up); +} + +/* Handle upstream entry del from the peer MLAG switch - + * - peer reference is removed. this can result in the upstream + * being deleted altogether. + * - if a local entry continues to exisy and has a MLAG OIF DF election + * is re-run (at the end of which the local entry will be the DF). + */ +static struct pim_upstream *pim_mlag_up_peer_deref(struct pim_instance *pim, + struct pim_upstream *up) +{ + if (!PIM_UPSTREAM_FLAG_TEST_MLAG_PEER(up->flags)) + return up; + + PIM_UPSTREAM_FLAG_UNSET_MLAG_PEER(up->flags); + up = pim_upstream_del(pim, up, __func__); + if (up) + pim_mlag_up_df_role_elect(pim, up); + + return up; +} + +static void pim_mlag_up_peer_del(struct mlag_mroute_del *msg) +{ + struct pim_upstream *up; + struct pim_instance *pim; + struct prefix_sg sg; + struct vrf *vrf; + char sg_str[PIM_SG_LEN]; + + memset(&sg, 0, sizeof(struct prefix_sg)); + sg.src.s_addr = htonl(msg->source_ip); + sg.grp.s_addr = htonl(msg->group_ip); + if (PIM_DEBUG_MLAG) + pim_str_sg_set(&sg, sg_str); + + if (PIM_DEBUG_MLAG) + zlog_debug("peer MLAG mroute del %s:%s", msg->vrf_name, + sg_str); + + vrf = vrf_lookup_by_name(msg->vrf_name); + if (!vrf) { + if (PIM_DEBUG_MLAG) + zlog_debug("peer MLAG mroute del skipped %s:%s; no vrf", + msg->vrf_name, sg_str); + return; + } + pim = vrf->info; + + up = pim_upstream_find(pim, &sg); + if (!up) { + if (PIM_DEBUG_MLAG) + zlog_debug("peer MLAG mroute del skipped %s:%s; no up", + vrf->name, sg_str); + return; + } + + (void)pim_mlag_up_peer_deref(pim, up); +} + +/* When we lose connection to the local MLAG daemon we can drop all peer + * references. + */ +static void pim_mlag_up_peer_del_all(void) +{ + struct list *temp = list_new(); + struct pim_upstream *up; + struct vrf *vrf; + struct pim_instance *pim; + + /* + * So why these gyrations? + * pim->upstream_head has the list of *,G and S,G + * that are in the system. The problem of course + * is that it is an ordered list: + * (*,G1) -> (S1,G1) -> (S2,G2) -> (S3, G2) -> (*,G2) -> (S1,G2) + * And the *,G1 has pointers to S1,G1 and S2,G1 + * if we delete *,G1 then we have a situation where + * S1,G1 and S2,G2 can be deleted as well. Then a + * simple ALL_LIST_ELEMENTS will have the next listnode + * pointer become invalid and we crash. + * So let's grab the list of MLAG_PEER upstreams + * add a refcount put on another list and delete safely + */ + RB_FOREACH(vrf, vrf_name_head, &vrfs_by_name) { + pim = vrf->info; + frr_each (rb_pim_upstream, &pim->upstream_head, up) { + if (!PIM_UPSTREAM_FLAG_TEST_MLAG_PEER(up->flags)) + continue; + listnode_add(temp, up); + /* + * Add a reference since we are adding to this + * list for deletion + */ + up->ref_count++; + } + + while (temp->count) { + up = listnode_head(temp); + listnode_delete(temp, up); + + up = pim_mlag_up_peer_deref(pim, up); + /* + * This is the deletion of the reference added + * above + */ + if (up) + pim_upstream_del(pim, up, __func__); + } + } + + list_delete(&temp); +} + +/* Send upstream entry to the local MLAG daemon (which will subsequently + * send it to the peer MLAG switch). + */ +static void pim_mlag_up_local_add_send(struct pim_instance *pim, + struct pim_upstream *up) +{ + struct stream *s = NULL; + struct vrf *vrf = pim->vrf; + + if (!(router->mlag_flags & PIM_MLAGF_LOCAL_CONN_UP)) + return; + + s = stream_new(sizeof(struct mlag_mroute_add) + PIM_MLAG_METADATA_LEN); + if (!s) + return; + + if (PIM_DEBUG_MLAG) + zlog_debug("local MLAG mroute add %s:%s", + vrf->name, up->sg_str); + + ++router->mlag_stats.msg.mroute_add_tx; + + stream_putl(s, MLAG_MROUTE_ADD); + stream_put(s, vrf->name, VRF_NAMSIZ); + stream_putl(s, ntohl(up->sg.src.s_addr)); + stream_putl(s, ntohl(up->sg.grp.s_addr)); + + stream_putl(s, pim_up_mlag_local_cost(up)); + /* XXX - who is addding*/ + stream_putl(s, MLAG_OWNER_VXLAN); + /* XXX - am_i_DR field should be removed */ + stream_putc(s, false); + stream_putc(s, !(PIM_UPSTREAM_FLAG_TEST_MLAG_NON_DF(up->flags))); + stream_putl(s, vrf->vrf_id); + /* XXX - this field is a No-op for VXLAN*/ + stream_put(s, NULL, INTERFACE_NAMSIZ); + + stream_fifo_push_safe(router->mlag_fifo, s); + pim_mlag_signal_zpthread(); +} + +static void pim_mlag_up_local_del_send(struct pim_instance *pim, + struct pim_upstream *up) +{ + struct stream *s = NULL; + struct vrf *vrf = pim->vrf; + + if (!(router->mlag_flags & PIM_MLAGF_LOCAL_CONN_UP)) + return; + + s = stream_new(sizeof(struct mlag_mroute_del) + PIM_MLAG_METADATA_LEN); + if (!s) + return; + + if (PIM_DEBUG_MLAG) + zlog_debug("local MLAG mroute del %s:%s", + vrf->name, up->sg_str); + + ++router->mlag_stats.msg.mroute_del_tx; + + stream_putl(s, MLAG_MROUTE_DEL); + stream_put(s, vrf->name, VRF_NAMSIZ); + stream_putl(s, ntohl(up->sg.src.s_addr)); + stream_putl(s, ntohl(up->sg.grp.s_addr)); + /* XXX - who is adding */ + stream_putl(s, MLAG_OWNER_VXLAN); + stream_putl(s, vrf->vrf_id); + /* XXX - this field is a No-op for VXLAN */ + stream_put(s, NULL, INTERFACE_NAMSIZ); + + /* XXX - is this the the most optimal way to do things */ + stream_fifo_push_safe(router->mlag_fifo, s); + pim_mlag_signal_zpthread(); +} + + +/* Called when a local upstream entry is created or if it's cost changes */ +void pim_mlag_up_local_add(struct pim_instance *pim, + struct pim_upstream *up) +{ + pim_mlag_up_df_role_elect(pim, up); + /* XXX - need to add some dup checks here */ + pim_mlag_up_local_add_send(pim, up); +} + +/* Called when local MLAG reference is removed from an upstream entry */ +void pim_mlag_up_local_del(struct pim_instance *pim, + struct pim_upstream *up) +{ + pim_mlag_up_df_role_elect(pim, up); + pim_mlag_up_local_del_send(pim, up); +} + +/* When connection to local MLAG daemon is established all the local + * MLAG upstream entries are replayed to it. + */ +static void pim_mlag_up_local_replay(void) +{ + struct pim_upstream *up; + struct vrf *vrf; + struct pim_instance *pim; + + RB_FOREACH(vrf, vrf_name_head, &vrfs_by_name) { + pim = vrf->info; + frr_each (rb_pim_upstream, &pim->upstream_head, up) { + if (pim_up_mlag_is_local(up) + || PIM_UPSTREAM_FLAG_TEST_MLAG_INTERFACE(up->flags)) + pim_mlag_up_local_add_send(pim, up); + } + } +} + +/* on local/peer mlag connection and role changes the DF status needs + * to be re-evaluated + */ +static void pim_mlag_up_local_reeval(bool mlagd_send, const char *reason_code) +{ + struct pim_upstream *up; + struct vrf *vrf; + struct pim_instance *pim; + + if (PIM_DEBUG_MLAG) + zlog_debug("%s re-run DF election because of %s", + __func__, reason_code); + RB_FOREACH(vrf, vrf_name_head, &vrfs_by_name) { + pim = vrf->info; + frr_each (rb_pim_upstream, &pim->upstream_head, up) { + if (!pim_up_mlag_is_local(up) + && !PIM_UPSTREAM_FLAG_TEST_MLAG_INTERFACE( + up->flags)) + continue; + /* if role changes re-send to peer */ + if (pim_mlag_up_df_role_elect(pim, up) && + mlagd_send) + pim_mlag_up_local_add_send(pim, up); + } + } +} + +/*****************PIM Actions for MLAG state changes**********************/ + +/* notify the anycast VTEP component about state changes */ +static inline void pim_mlag_vxlan_state_update(void) +{ + bool enable = !!(router->mlag_flags & PIM_MLAGF_STATUS_RXED); + bool peer_state = !!(router->mlag_flags & PIM_MLAGF_PEER_CONN_UP); + + pim_vxlan_mlag_update(enable, peer_state, router->mlag_role, + router->peerlink_rif_p, &router->local_vtep_ip); + +} + +/**************End of PIM Actions for MLAG State changes******************/ + /********************API to process PIM MLAG Data ************************/ static void pim_mlag_process_mlagd_state_change(struct mlag_status msg) { + bool role_chg = false; + bool state_chg = false; + bool notify_vxlan = false; + struct interface *peerlink_rif_p; char buf[MLAG_ROLE_STRSIZE]; if (PIM_DEBUG_MLAG) @@ -41,6 +567,84 @@ static void pim_mlag_process_mlagd_state_change(struct mlag_status msg) mlag_role2str(msg.my_role, buf, sizeof(buf)), (msg.peer_state == MLAG_STATE_RUNNING ? "RUNNING" : "DOWN")); + + if (!(router->mlag_flags & PIM_MLAGF_LOCAL_CONN_UP)) { + if (PIM_DEBUG_MLAG) + zlog_debug("%s: msg ignored mlagd process state down", + __func__); + return; + } + ++router->mlag_stats.msg.mlag_status_updates; + + /* evaluate the changes first */ + if (router->mlag_role != msg.my_role) { + role_chg = true; + notify_vxlan = true; + router->mlag_role = msg.my_role; + } + + strcpy(router->peerlink_rif, msg.peerlink_rif); + /* XXX - handle the case where we may rx the interface name from the + * MLAG daemon before we get the interface from zebra. + */ + peerlink_rif_p = if_lookup_by_name(router->peerlink_rif, VRF_DEFAULT); + if (router->peerlink_rif_p != peerlink_rif_p) { + router->peerlink_rif_p = peerlink_rif_p; + notify_vxlan = true; + } + + if (msg.peer_state == MLAG_STATE_RUNNING) { + if (!(router->mlag_flags & PIM_MLAGF_PEER_CONN_UP)) { + state_chg = true; + notify_vxlan = true; + router->mlag_flags |= PIM_MLAGF_PEER_CONN_UP; + } + router->connected_to_mlag = true; + } else { + if (router->mlag_flags & PIM_MLAGF_PEER_CONN_UP) { + ++router->mlag_stats.peer_session_downs; + state_chg = true; + notify_vxlan = true; + router->mlag_flags &= ~PIM_MLAGF_PEER_CONN_UP; + } + router->connected_to_mlag = false; + } + + /* apply the changes */ + /* when connection to mlagd comes up we hold send mroutes till we have + * rxed the status and had a chance to re-valuate DF state + */ + if (!(router->mlag_flags & PIM_MLAGF_STATUS_RXED)) { + router->mlag_flags |= PIM_MLAGF_STATUS_RXED; + pim_mlag_vxlan_state_update(); + /* on session up re-eval DF status */ + pim_mlag_up_local_reeval(false /*mlagd_send*/, "mlagd_up"); + /* replay all the upstream entries to the local MLAG daemon */ + pim_mlag_up_local_replay(); + return; + } + + if (notify_vxlan) + pim_mlag_vxlan_state_update(); + + if (state_chg) { + if (!(router->mlag_flags & PIM_MLAGF_PEER_CONN_UP)) + /* when a connection goes down the primary takes over + * DF role for all entries + */ + pim_mlag_up_local_reeval(true /*mlagd_send*/, + "peer_down"); + else + /* XXX - when session comes up we need to wait for + * PEER_REPLAY_DONE before running re-election on + * local-mlag entries that are missing peer reference + */ + pim_mlag_up_local_reeval(true /*mlagd_send*/, + "peer_up"); + } else if (role_chg) { + /* MLAG role changed without a state change */ + pim_mlag_up_local_reeval(true /*mlagd_send*/, "role_chg"); + } } static void pim_mlag_process_peer_frr_state_change(struct mlag_frr_status msg) @@ -49,45 +653,125 @@ static void pim_mlag_process_peer_frr_state_change(struct mlag_frr_status msg) zlog_debug( "%s: msg dump: peer_frr_state: %s", __func__, (msg.frr_state == MLAG_FRR_STATE_UP ? "UP" : "DOWN")); + + if (!(router->mlag_flags & PIM_MLAGF_LOCAL_CONN_UP)) { + if (PIM_DEBUG_MLAG) + zlog_debug("%s: msg ignored mlagd process state down", + __func__); + return; + } + ++router->mlag_stats.msg.peer_zebra_status_updates; + + /* evaluate the changes first */ + if (msg.frr_state == MLAG_FRR_STATE_UP) { + if (!(router->mlag_flags & PIM_MLAGF_PEER_ZEBRA_UP)) { + router->mlag_flags |= PIM_MLAGF_PEER_ZEBRA_UP; + /* XXX - when peer zebra comes up we need to wait for + * for some time to let the peer setup MDTs before + * before relinquishing DF status + */ + pim_mlag_up_local_reeval(true /*mlagd_send*/, + "zebra_up"); + } + } else { + if (router->mlag_flags & PIM_MLAGF_PEER_ZEBRA_UP) { + ++router->mlag_stats.peer_zebra_downs; + router->mlag_flags &= ~PIM_MLAGF_PEER_ZEBRA_UP; + /* when a peer zebra goes down we assume DF role */ + pim_mlag_up_local_reeval(true /*mlagd_send*/, + "zebra_down"); + } + } } static void pim_mlag_process_vxlan_update(struct mlag_vxlan *msg) { + char addr_buf1[INET_ADDRSTRLEN]; + char addr_buf2[INET_ADDRSTRLEN]; + uint32_t local_ip; + + if (!(router->mlag_flags & PIM_MLAGF_LOCAL_CONN_UP)) { + if (PIM_DEBUG_MLAG) + zlog_debug("%s: msg ignored mlagd process state down", + __func__); + return; + } + + ++router->mlag_stats.msg.vxlan_updates; + router->anycast_vtep_ip.s_addr = htonl(msg->anycast_ip); + local_ip = htonl(msg->local_ip); + if (router->local_vtep_ip.s_addr != local_ip) { + router->local_vtep_ip.s_addr = local_ip; + pim_mlag_vxlan_state_update(); + } + + if (PIM_DEBUG_MLAG) { + inet_ntop(AF_INET, &router->local_vtep_ip, + addr_buf1, INET_ADDRSTRLEN); + inet_ntop(AF_INET, &router->anycast_vtep_ip, + addr_buf2, INET_ADDRSTRLEN); + + zlog_debug("%s: msg dump: local-ip:%s, anycast-ip:%s", + __func__, addr_buf1, addr_buf2); + } } static void pim_mlag_process_mroute_add(struct mlag_mroute_add msg) { if (PIM_DEBUG_MLAG) { zlog_debug( - "%s: msg dump: vrf_name: %s, s.ip: 0x%x, g.ip: 0x%x cost: %u", - __func__, msg.vrf_name, msg.source_ip, msg.group_ip, - msg.cost_to_rp); + "%s: msg dump: vrf_name: %s, s.ip: 0x%x, g.ip: 0x%x cost: %u", + __func__, msg.vrf_name, msg.source_ip, + msg.group_ip, msg.cost_to_rp); zlog_debug( - "owner_id: %d, DR: %d, Dual active: %d, vrf_id: 0x%x intf_name: %s", - msg.owner_id, msg.am_i_dr, msg.am_i_dual_active, - msg.vrf_id, msg.intf_name); + "owner_id: %d, DR: %d, Dual active: %d, vrf_id: 0x%x intf_name: %s", + msg.owner_id, msg.am_i_dr, msg.am_i_dual_active, + msg.vrf_id, msg.intf_name); + } + + if (!(router->mlag_flags & PIM_MLAGF_LOCAL_CONN_UP)) { + if (PIM_DEBUG_MLAG) + zlog_debug("%s: msg ignored mlagd process state down", + __func__); + return; } + + ++router->mlag_stats.msg.mroute_add_rx; + + pim_mlag_up_peer_add(&msg); } static void pim_mlag_process_mroute_del(struct mlag_mroute_del msg) { if (PIM_DEBUG_MLAG) { zlog_debug( - "%s: msg dump: vrf_name: %s, s.ip: 0x%x, g.ip: 0x%x ", - __func__, msg.vrf_name, msg.source_ip, msg.group_ip); + "%s: msg dump: vrf_name: %s, s.ip: 0x%x, g.ip: 0x%x ", + __func__, msg.vrf_name, msg.source_ip, + msg.group_ip); zlog_debug("owner_id: %d, vrf_id: 0x%x intf_name: %s", - msg.owner_id, msg.vrf_id, msg.intf_name); + msg.owner_id, msg.vrf_id, msg.intf_name); + } + + if (!(router->mlag_flags & PIM_MLAGF_LOCAL_CONN_UP)) { + if (PIM_DEBUG_MLAG) + zlog_debug("%s: msg ignored mlagd process state down", + __func__); + return; } -} + ++router->mlag_stats.msg.mroute_del_rx; + + pim_mlag_up_peer_del(&msg); +} int pim_zebra_mlag_handle_msg(struct stream *s, int len) { struct mlag_msg mlag_msg; char buf[ZLOG_FILTER_LENGTH_MAX]; int rc = 0; + size_t length; - rc = mlag_lib_decode_mlag_hdr(s, &mlag_msg); + rc = mlag_lib_decode_mlag_hdr(s, &mlag_msg, &length); if (rc) return (rc); @@ -126,7 +810,7 @@ int pim_zebra_mlag_handle_msg(struct stream *s, int len) case MLAG_MROUTE_ADD: { struct mlag_mroute_add msg; - rc = mlag_lib_decode_mroute_add(s, &msg); + rc = mlag_lib_decode_mroute_add(s, &msg, &length); if (rc) return (rc); pim_mlag_process_mroute_add(msg); @@ -134,7 +818,7 @@ int pim_zebra_mlag_handle_msg(struct stream *s, int len) case MLAG_MROUTE_DEL: { struct mlag_mroute_del msg; - rc = mlag_lib_decode_mroute_del(s, &msg); + rc = mlag_lib_decode_mroute_del(s, &msg, &length); if (rc) return (rc); pim_mlag_process_mroute_del(msg); @@ -144,8 +828,7 @@ int pim_zebra_mlag_handle_msg(struct stream *s, int len) int i; for (i = 0; i < mlag_msg.msg_cnt; i++) { - - rc = mlag_lib_decode_mroute_add(s, &msg); + rc = mlag_lib_decode_mroute_add(s, &msg, &length); if (rc) return (rc); pim_mlag_process_mroute_add(msg); @@ -156,8 +839,7 @@ int pim_zebra_mlag_handle_msg(struct stream *s, int len) int i; for (i = 0; i < mlag_msg.msg_cnt; i++) { - - rc = mlag_lib_decode_mroute_del(s, &msg); + rc = mlag_lib_decode_mroute_del(s, &msg, &length); if (rc) return (rc); pim_mlag_process_mroute_del(msg); @@ -176,14 +858,49 @@ int pim_zebra_mlag_process_up(void) if (PIM_DEBUG_MLAG) zlog_debug("%s: Received Process-Up from Mlag", __func__); + /* + * Incase of local MLAG restart, PIM needs to replay all the data + * since MLAG is empty. + */ + router->connected_to_mlag = true; + router->mlag_flags |= PIM_MLAGF_LOCAL_CONN_UP; return 0; } +static void pim_mlag_param_reset(void) +{ + /* reset the cached params and stats */ + router->mlag_flags &= ~(PIM_MLAGF_STATUS_RXED | + PIM_MLAGF_LOCAL_CONN_UP | + PIM_MLAGF_PEER_CONN_UP | + PIM_MLAGF_PEER_ZEBRA_UP); + router->local_vtep_ip.s_addr = INADDR_ANY; + router->anycast_vtep_ip.s_addr = INADDR_ANY; + router->mlag_role = MLAG_ROLE_NONE; + memset(&router->mlag_stats.msg, 0, sizeof(router->mlag_stats.msg)); + router->peerlink_rif[0] = '\0'; +} + int pim_zebra_mlag_process_down(void) { if (PIM_DEBUG_MLAG) zlog_debug("%s: Received Process-Down from Mlag", __func__); + /* Local CLAG is down, reset peer data and forward the traffic if + * we are DR + */ + if (router->mlag_flags & PIM_MLAGF_PEER_CONN_UP) + ++router->mlag_stats.peer_session_downs; + if (router->mlag_flags & PIM_MLAGF_PEER_ZEBRA_UP) + ++router->mlag_stats.peer_zebra_downs; + router->connected_to_mlag = false; + pim_mlag_param_reset(); + /* on mlagd session down re-eval DF status */ + pim_mlag_up_local_reeval(false /*mlagd_send*/, "mlagd_down"); + /* flush all peer references */ + pim_mlag_up_peer_del_all(); + /* notify the vxlan component */ + pim_mlag_vxlan_state_update(); return 0; } @@ -239,7 +956,7 @@ static int pim_mlag_deregister_handler(struct thread *thread) void pim_mlag_deregister(void) { /* if somebody still interested in the MLAG channel skip de-reg */ - if (router->pim_mlag_intf_cnt) + if (router->pim_mlag_intf_cnt || pim_vxlan_do_mlag_reg()) return; /* not registered; nothing do */ @@ -257,10 +974,6 @@ void pim_if_configure_mlag_dualactive(struct pim_interface *pim_ifp) if (!pim_ifp || !pim_ifp->pim || pim_ifp->activeactive == true) return; - if (PIM_DEBUG_MLAG) - zlog_debug("%s: Configuring active-active on Interface: %s", - __func__, "NULL"); - pim_ifp->activeactive = true; if (pim_ifp->pim) pim_ifp->pim->inst_mlag_intf_cnt++; @@ -286,10 +999,6 @@ void pim_if_unconfigure_mlag_dualactive(struct pim_interface *pim_ifp) if (!pim_ifp || !pim_ifp->pim || pim_ifp->activeactive == false) return; - if (PIM_DEBUG_MLAG) - zlog_debug("%s: UnConfiguring active-active on Interface: %s", - __func__, "NULL"); - pim_ifp->activeactive = false; pim_ifp->pim->inst_mlag_intf_cnt--; @@ -306,6 +1015,7 @@ void pim_if_unconfigure_mlag_dualactive(struct pim_interface *pim_ifp) * De-register to Zebra */ pim_mlag_deregister(); + pim_mlag_param_reset(); } } @@ -339,6 +1049,7 @@ void pim_instance_mlag_terminate(struct pim_instance *pim) void pim_mlag_init(void) { + pim_mlag_param_reset(); router->pim_mlag_intf_cnt = 0; router->connected_to_mlag = false; router->mlag_fifo = stream_fifo_new(); diff --git a/pimd/pim_mlag.h b/pimd/pim_mlag.h index e86fdae78f..eb316695f7 100644 --- a/pimd/pim_mlag.h +++ b/pimd/pim_mlag.h @@ -32,9 +32,22 @@ extern void pim_instance_mlag_init(struct pim_instance *pim); extern void pim_instance_mlag_terminate(struct pim_instance *pim); extern void pim_if_configure_mlag_dualactive(struct pim_interface *pim_ifp); extern void pim_if_unconfigure_mlag_dualactive(struct pim_interface *pim_ifp); -extern void pim_mlag_register(void); -extern void pim_mlag_deregister(void); extern int pim_zebra_mlag_process_up(void); extern int pim_zebra_mlag_process_down(void); extern int pim_zebra_mlag_handle_msg(struct stream *msg, int len); + +/* pm_zpthread.c */ +extern int pim_mlag_signal_zpthread(void); +extern void pim_zpthread_init(void); +extern void pim_zpthread_terminate(void); + +extern void pim_mlag_register(void); +extern void pim_mlag_deregister(void); +extern void pim_mlag_up_local_add(struct pim_instance *pim, + struct pim_upstream *upstream); +extern void pim_mlag_up_local_del(struct pim_instance *pim, + struct pim_upstream *upstream); +extern bool pim_mlag_up_df_role_update(struct pim_instance *pim, + struct pim_upstream *up, bool is_df, + const char *reason); #endif diff --git a/pimd/pim_mroute.c b/pimd/pim_mroute.c index 3459abbc19..5ce7863611 100644 --- a/pimd/pim_mroute.c +++ b/pimd/pim_mroute.c @@ -65,10 +65,9 @@ static int pim_mroute_set(struct pim_instance *pim, int enable) &data, data_len); if (err) { zlog_warn( - "%s %s: failure: setsockopt(fd=%d,IPPROTO_IP, MRT_TABLE=%d): errno=%d: %s", - __FILE__, __PRETTY_FUNCTION__, - pim->mroute_socket, data, errno, - safe_strerror(errno)); + "%s %s: failure: setsockopt(fd=%d,IPPROTO_IP, MRT_TABLE=%d): errno=%d: %s", + __FILE__, __func__, pim->mroute_socket, + data, errno, safe_strerror(errno)); return -1; } @@ -86,11 +85,10 @@ static int pim_mroute_set(struct pim_instance *pim, int enable) opt, &data, data_len); if (err) { zlog_warn( - "%s %s: failure: setsockopt(fd=%d,IPPROTO_IP,%s=%d): errno=%d: %s", - __FILE__, __PRETTY_FUNCTION__, - pim->mroute_socket, - enable ? "MRT_INIT" : "MRT_DONE", data, errno, - safe_strerror(errno)); + "%s %s: failure: setsockopt(fd=%d,IPPROTO_IP,%s=%d): errno=%d: %s", + __FILE__, __func__, pim->mroute_socket, + enable ? "MRT_INIT" : "MRT_DONE", data, errno, + safe_strerror(errno)); return -1; } } @@ -168,7 +166,7 @@ static int pim_mroute_msg_nocache(int fd, struct interface *ifp, if (PIM_DEBUG_MROUTE_DETAIL) zlog_debug( "%s: Interface is not configured correctly to handle incoming packet: Could be !pim_ifp, !SM, !RP", - __PRETTY_FUNCTION__); + __func__); return 0; } @@ -181,7 +179,7 @@ static int pim_mroute_msg_nocache(int fd, struct interface *ifp, if (PIM_DEBUG_MROUTE_DETAIL) zlog_debug( "%s: Received incoming packet that doesn't originate on our seg", - __PRETTY_FUNCTION__); + __func__); return 0; } @@ -191,8 +189,9 @@ static int pim_mroute_msg_nocache(int fd, struct interface *ifp, if (!(PIM_I_am_DR(pim_ifp))) { if (PIM_DEBUG_MROUTE_DETAIL) - zlog_debug("%s: Interface is not the DR blackholing incoming traffic for %s", - __PRETTY_FUNCTION__, pim_str_sg_dump(&sg)); + zlog_debug( + "%s: Interface is not the DR blackholing incoming traffic for %s", + __func__, pim_str_sg_dump(&sg)); /* * We are not the DR, but we are still receiving packets @@ -205,15 +204,14 @@ static int pim_mroute_msg_nocache(int fd, struct interface *ifp, * this for future reference. */ up = pim_upstream_find_or_add( - &sg, ifp, PIM_UPSTREAM_FLAG_MASK_SRC_NOCACHE, - __PRETTY_FUNCTION__); - pim_upstream_mroute_add(up->channel_oil, __PRETTY_FUNCTION__); + &sg, ifp, PIM_UPSTREAM_FLAG_MASK_SRC_NOCACHE, __func__); + pim_upstream_mroute_add(up->channel_oil, __func__); return 0; } up = pim_upstream_find_or_add(&sg, ifp, PIM_UPSTREAM_FLAG_MASK_FHR, - __PRETTY_FUNCTION__); + __func__); /* * I moved this debug till after the actual add because @@ -221,7 +219,7 @@ static int pim_mroute_msg_nocache(int fd, struct interface *ifp, */ if (PIM_DEBUG_MROUTE) { zlog_debug("%s: Adding a Route %s for WHOLEPKT consumption", - __PRETTY_FUNCTION__, up->sg_str); + __func__, up->sg_str); } PIM_UPSTREAM_FLAG_SET_SRC_STREAM(up->flags); @@ -262,16 +260,15 @@ static int pim_mroute_msg_wholepkt(int fd, struct interface *ifp, up = pim_upstream_find(pim_ifp->pim, &star); - if (up && PIM_UPSTREAM_FLAG_TEST_SRC_IGMP(up->flags)) { + if (up && PIM_UPSTREAM_FLAG_TEST_CAN_BE_LHR(up->flags)) { up = pim_upstream_add(pim_ifp->pim, &sg, ifp, PIM_UPSTREAM_FLAG_MASK_SRC_LHR, - __PRETTY_FUNCTION__, NULL); + __func__, NULL); if (!up) { if (PIM_DEBUG_MROUTE) zlog_debug( "%s: Unable to create upstream information for %s", - __PRETTY_FUNCTION__, - pim_str_sg_dump(&sg)); + __func__, pim_str_sg_dump(&sg)); return 0; } pim_upstream_keep_alive_timer_start( @@ -281,21 +278,21 @@ static int pim_mroute_msg_wholepkt(int fd, struct interface *ifp, if (PIM_DEBUG_MROUTE) zlog_debug("%s: Creating %s upstream on LHR", - __PRETTY_FUNCTION__, up->sg_str); + __func__, up->sg_str); return 0; } if (PIM_DEBUG_MROUTE_DETAIL) { zlog_debug( "%s: Unable to find upstream channel WHOLEPKT%s", - __PRETTY_FUNCTION__, pim_str_sg_dump(&sg)); + __func__, pim_str_sg_dump(&sg)); } return 0; } if (!up->rpf.source_nexthop.interface) { if (PIM_DEBUG_PIM_TRACE) - zlog_debug("%s: up %s RPF is not present", - __PRETTY_FUNCTION__, up->sg_str); + zlog_debug("%s: up %s RPF is not present", __func__, + up->sg_str); return 0; } @@ -306,8 +303,7 @@ static int pim_mroute_msg_wholepkt(int fd, struct interface *ifp, if ((pim_rpf_addr_is_inaddr_none(rpg)) || (!pim_ifp) || (!(PIM_I_am_DR(pim_ifp)))) { if (PIM_DEBUG_MROUTE) { - zlog_debug("%s: Failed Check send packet", - __PRETTY_FUNCTION__); + zlog_debug("%s: Failed Check send packet", __func__); } return 0; } @@ -365,8 +361,7 @@ static int pim_mroute_msg_wrongvif(int fd, struct interface *ifp, if (PIM_DEBUG_MROUTE) zlog_debug( "%s: WRONGVIF (S,G)=%s could not find input interface for input_vif_index=%d", - __PRETTY_FUNCTION__, pim_str_sg_dump(&sg), - msg->im_vif); + __func__, pim_str_sg_dump(&sg), msg->im_vif); return -1; } @@ -375,8 +370,7 @@ static int pim_mroute_msg_wrongvif(int fd, struct interface *ifp, if (PIM_DEBUG_MROUTE) zlog_debug( "%s: WRONGVIF (S,G)=%s multicast not enabled on interface %s", - __PRETTY_FUNCTION__, pim_str_sg_dump(&sg), - ifp->name); + __func__, pim_str_sg_dump(&sg), ifp->name); return -2; } @@ -386,8 +380,7 @@ static int pim_mroute_msg_wrongvif(int fd, struct interface *ifp, if (PIM_DEBUG_MROUTE) zlog_debug( "%s: WRONGVIF (S,G)=%s could not find channel on interface %s", - __PRETTY_FUNCTION__, pim_str_sg_dump(&sg), - ifp->name); + __func__, pim_str_sg_dump(&sg), ifp->name); star_g.src.s_addr = INADDR_ANY; ch = pim_ifchannel_find(ifp, &star_g); @@ -395,8 +388,8 @@ static int pim_mroute_msg_wrongvif(int fd, struct interface *ifp, if (PIM_DEBUG_MROUTE) zlog_debug( "%s: WRONGVIF (*,G)=%s could not find channel on interface %s", - __PRETTY_FUNCTION__, - pim_str_sg_dump(&star_g), ifp->name); + __func__, pim_str_sg_dump(&star_g), + ifp->name); return -3; } } @@ -419,7 +412,7 @@ static int pim_mroute_msg_wrongvif(int fd, struct interface *ifp, if (PIM_DEBUG_MROUTE) { zlog_debug( "%s: WRONGVIF (S,G)=%s channel is not on Assert NoInfo state for interface %s", - __PRETTY_FUNCTION__, ch->sg_str, ifp->name); + __func__, ch->sg_str, ifp->name); } return -4; } @@ -428,7 +421,7 @@ static int pim_mroute_msg_wrongvif(int fd, struct interface *ifp, if (PIM_DEBUG_MROUTE) { zlog_debug( "%s: WRONGVIF (S,G)=%s interface %s is not downstream for channel", - __PRETTY_FUNCTION__, ch->sg_str, ifp->name); + __func__, ch->sg_str, ifp->name); } return -5; } @@ -437,7 +430,7 @@ static int pim_mroute_msg_wrongvif(int fd, struct interface *ifp, if (PIM_DEBUG_MROUTE) { zlog_debug( "%s: WRONGVIF (S,G)=%s assert_action_a1 failure on interface %s", - __PRETTY_FUNCTION__, ch->sg_str, ifp->name); + __func__, ch->sg_str, ifp->name); } return -6; } @@ -450,6 +443,7 @@ static int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, { const struct ip *ip_hdr = (const struct ip *)buf; struct pim_interface *pim_ifp; + struct pim_instance *pim; struct pim_ifchannel *ch; struct pim_upstream *up; struct prefix_sg star_g; @@ -472,16 +466,18 @@ static int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, star_g = sg; star_g.src.s_addr = INADDR_ANY; -#if 0 - ch = pim_ifchannel_find(ifp, &star_g); - if (ch) - { - if (PIM_DEBUG_MROUTE) - zlog_debug ("WRVIFWHOLE (*,G)=%s found ifchannel on interface %s", - pim_str_sg_dump (&star_g), ifp->name); - return -1; - } -#endif + + pim = pim_ifp->pim; + /* + * If the incoming interface is the pimreg, then + * we know the callback is associated with a pim register + * packet and there is nothing to do here as that + * normal pim processing will see the packet and allow + * us to do the right thing. + */ + if (ifp == pim->regiface) { + return 0; + } up = pim_upstream_find(pim_ifp->pim, &sg); if (up) { @@ -509,8 +505,17 @@ static int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, * the pimreg period, so I believe we can ignore this packet */ if (!PIM_UPSTREAM_FLAG_TEST_FHR(up->flags)) { - // No if channel, but upstream we are at the RP. - if (pim_nexthop_lookup(pim_ifp->pim, &source, + /* + * No if channel, but upstream we are at the RP. + * + * This could be a anycast RP too and we may + * not have received a register packet from + * the source here at all. So gracefully + * bow out of doing a nexthop lookup and + * setting the SPTBIT to true + */ + if (up->upstream_register.s_addr != INADDR_ANY && + pim_nexthop_lookup(pim_ifp->pim, &source, up->upstream_register, 0)) { pim_register_stop_send(source.interface, &sg, pim_ifp->primary_address, @@ -521,7 +526,7 @@ static int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, pim_upstream_inherited_olist(pim_ifp->pim, up); if (!up->channel_oil->installed) pim_upstream_mroute_add(up->channel_oil, - __PRETTY_FUNCTION__); + __func__); } else { if (I_am_RP(pim_ifp->pim, up->sg.grp)) { if (pim_nexthop_lookup(pim_ifp->pim, &source, @@ -544,8 +549,8 @@ static int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, pim_ifp = ifp->info; if (pim_if_connected_to_source(ifp, sg.src)) { up = pim_upstream_add(pim_ifp->pim, &sg, ifp, - PIM_UPSTREAM_FLAG_MASK_FHR, - __PRETTY_FUNCTION__, NULL); + PIM_UPSTREAM_FLAG_MASK_FHR, __func__, + NULL); if (!up) { if (PIM_DEBUG_MROUTE) zlog_debug( @@ -567,10 +572,9 @@ static int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, } else { up = pim_upstream_add(pim_ifp->pim, &sg, ifp, PIM_UPSTREAM_FLAG_MASK_SRC_NOCACHE, - __PRETTY_FUNCTION__, NULL); + __func__, NULL); if (!up->channel_oil->installed) - pim_upstream_mroute_add(up->channel_oil, - __PRETTY_FUNCTION__); + pim_upstream_mroute_add(up->channel_oil, __func__); } return 0; @@ -621,8 +625,8 @@ static int pim_mroute_msg(struct pim_instance *pim, const char *buf, zlog_debug( "%s(%s): igmp kernel upcall on %s(%p) for %s -> %s", - __PRETTY_FUNCTION__, pim->vrf->name, ifp->name, - igmp, ip_src_str, ip_dst_str); + __func__, pim->vrf->name, ifp->name, igmp, + ip_src_str, ip_dst_str); } if (igmp) pim_igmp_packet(igmp, (char *)buf, buf_size); @@ -635,8 +639,8 @@ static int pim_mroute_msg(struct pim_instance *pim, const char *buf, sizeof(grp_str)); zlog_debug( "%s: no kernel upcall proto=%d src: %s dst: %s msg_size=%d", - __PRETTY_FUNCTION__, ip_hdr->ip_p, src_str, - grp_str, buf_size); + __func__, ip_hdr->ip_p, src_str, grp_str, + buf_size); } } else { @@ -653,8 +657,7 @@ static int pim_mroute_msg(struct pim_instance *pim, const char *buf, sizeof(grp_str)); zlog_debug( "%s: pim kernel upcall %s type=%d ip_p=%d from fd=%d for (S,G)=(%s,%s) on %s vifi=%d size=%d", - __PRETTY_FUNCTION__, - igmpmsgtype2str[msg->im_msgtype], + __func__, igmpmsgtype2str[msg->im_msgtype], msg->im_msgtype, ip_hdr->ip_p, pim->mroute_socket, src_str, grp_str, ifp->name, msg->im_vif, buf_size); @@ -706,9 +709,10 @@ static int mroute_read(struct thread *t) if (errno == EWOULDBLOCK || errno == EAGAIN) break; - zlog_warn("%s: failure reading rd=%d: fd=%d: errno=%d: %s", - __PRETTY_FUNCTION__, rd, pim->mroute_socket, - errno, safe_strerror(errno)); + zlog_warn( + "%s: failure reading rd=%d: fd=%d: errno=%d: %s", + __func__, rd, pim->mroute_socket, errno, + safe_strerror(errno)); goto done; } @@ -815,7 +819,7 @@ int pim_mroute_add_vif(struct interface *ifp, struct in_addr ifaddr, int err; if (PIM_DEBUG_MROUTE) - zlog_debug("%s: Add Vif %d (%s[%s])", __PRETTY_FUNCTION__, + zlog_debug("%s: Add Vif %d (%s[%s])", __func__, pim_ifp->mroute_vif_index, ifp->name, pim_ifp->pim->vrf->name); @@ -827,7 +831,7 @@ int pim_mroute_add_vif(struct interface *ifp, struct in_addr ifaddr, if (ifaddr.s_addr == INADDR_ANY) { zlog_warn( "%s: unnumbered interfaces are not supported on this platform", - __PRETTY_FUNCTION__); + __func__); return -1; } memcpy(&vc.vifc_lcl_addr, &ifaddr, sizeof(vc.vifc_lcl_addr)); @@ -853,9 +857,8 @@ int pim_mroute_add_vif(struct interface *ifp, struct in_addr ifaddr, zlog_warn( "%s: failure: setsockopt(fd=%d,IPPROTO_IP,MRT_ADD_VIF,vif_index=%d,ifaddr=%s,flag=%d): errno=%d: %s", - __PRETTY_FUNCTION__, pim_ifp->pim->mroute_socket, - ifp->ifindex, ifaddr_str, flags, errno, - safe_strerror(errno)); + __func__, pim_ifp->pim->mroute_socket, ifp->ifindex, + ifaddr_str, flags, errno, safe_strerror(errno)); return -2; } @@ -869,7 +872,7 @@ int pim_mroute_del_vif(struct interface *ifp) int err; if (PIM_DEBUG_MROUTE) - zlog_debug("%s: Del Vif %d (%s[%s])", __PRETTY_FUNCTION__, + zlog_debug("%s: Del Vif %d (%s[%s])", __func__, pim_ifp->mroute_vif_index, ifp->name, pim_ifp->pim->vrf->name); @@ -881,9 +884,8 @@ int pim_mroute_del_vif(struct interface *ifp) if (err) { zlog_warn( "%s %s: failure: setsockopt(fd=%d,IPPROTO_IP,MRT_DEL_VIF,vif_index=%d): errno=%d: %s", - __FILE__, __PRETTY_FUNCTION__, - pim_ifp->pim->mroute_socket, pim_ifp->mroute_vif_index, - errno, safe_strerror(errno)); + __FILE__, __func__, pim_ifp->pim->mroute_socket, + pim_ifp->mroute_vif_index, errno, safe_strerror(errno)); return -2; } @@ -1003,20 +1005,22 @@ static int pim_mroute_add(struct channel_oil *c_oil, const char *name) if (err) { zlog_warn( "%s %s: failure: setsockopt(fd=%d,IPPROTO_IP,MRT_ADD_MFC): errno=%d: %s", - __FILE__, __PRETTY_FUNCTION__, pim->mroute_socket, - errno, safe_strerror(errno)); + __FILE__, __func__, pim->mroute_socket, errno, + safe_strerror(errno)); return -2; } if (PIM_DEBUG_MROUTE) { char buf[1000]; - zlog_debug("%s(%s), vrf %s Added Route: %s", - __PRETTY_FUNCTION__, name, pim->vrf->name, + zlog_debug("%s(%s), vrf %s Added Route: %s", __func__, name, + pim->vrf->name, pim_channel_oil_dump(c_oil, buf, sizeof(buf))); } - c_oil->installed = 1; - c_oil->mroute_creation = pim_time_monotonic_sec(); + if (!c_oil->installed) { + c_oil->installed = 1; + c_oil->mroute_creation = pim_time_monotonic_sec(); + } return 0; } @@ -1170,8 +1174,7 @@ int pim_mroute_del(struct channel_oil *c_oil, const char *name) char buf[1000]; zlog_debug( "%s %s: vifi %d for route is %s not installed, do not need to send del req. ", - __FILE__, __PRETTY_FUNCTION__, - c_oil->oil.mfcc_parent, + __FILE__, __func__, c_oil->oil.mfcc_parent, pim_channel_oil_dump(c_oil, buf, sizeof(buf))); } return -2; @@ -1183,16 +1186,15 @@ int pim_mroute_del(struct channel_oil *c_oil, const char *name) if (PIM_DEBUG_MROUTE) zlog_warn( "%s %s: failure: setsockopt(fd=%d,IPPROTO_IP,MRT_DEL_MFC): errno=%d: %s", - __FILE__, __PRETTY_FUNCTION__, - pim->mroute_socket, errno, + __FILE__, __func__, pim->mroute_socket, errno, safe_strerror(errno)); return -2; } if (PIM_DEBUG_MROUTE) { char buf[1000]; - zlog_debug("%s(%s), vrf %s Deleted Route: %s", - __PRETTY_FUNCTION__, name, pim->vrf->name, + zlog_debug("%s(%s), vrf %s Deleted Route: %s", __func__, name, + pim->vrf->name, pim_channel_oil_dump(c_oil, buf, sizeof(buf))); } diff --git a/pimd/pim_msdp.c b/pimd/pim_msdp.c index 27af9473bb..63d34e859c 100644 --- a/pimd/pim_msdp.c +++ b/pimd/pim_msdp.c @@ -126,7 +126,7 @@ static void pim_msdp_sa_upstream_del(struct pim_msdp_sa *sa) if (PIM_UPSTREAM_FLAG_TEST_SRC_MSDP(up->flags)) { PIM_UPSTREAM_FLAG_UNSET_SRC_MSDP(up->flags); sa->flags |= PIM_MSDP_SAF_UP_DEL_IN_PROG; - up = pim_upstream_del(sa->pim, up, __PRETTY_FUNCTION__); + up = pim_upstream_del(sa->pim, up, __func__); /* re-eval joinDesired; clearing peer-msdp-sa flag can * cause JD to change */ @@ -210,8 +210,7 @@ static void pim_msdp_sa_upstream_update(struct pim_msdp_sa *sa, /* RFC3618: "RP triggers a (S, G) join event towards the data source * as if a JP message was rxed addressed to the RP itself." */ up = pim_upstream_add(sa->pim, &sa->sg, NULL /* iif */, - PIM_UPSTREAM_FLAG_MASK_SRC_MSDP, - __PRETTY_FUNCTION__, NULL); + PIM_UPSTREAM_FLAG_MASK_SRC_MSDP, __func__, NULL); sa->up = up; if (up) { diff --git a/pimd/pim_msdp_socket.c b/pimd/pim_msdp_socket.c index 22eb8bc7b4..7620cd5792 100644 --- a/pimd/pim_msdp_socket.c +++ b/pimd/pim_msdp_socket.c @@ -162,14 +162,14 @@ int pim_msdp_sock_listen(struct pim_instance *pim) if (!ifp) { flog_err(EC_LIB_INTERFACE, "%s: Unable to lookup vrf interface: %s", - __PRETTY_FUNCTION__, pim->vrf->name); + __func__, pim->vrf->name); close(sock); return -1; } if (pim_socket_bind(sock, ifp)) { flog_err_sys(EC_LIB_SOCKET, "%s: Unable to bind to socket: %s", - __PRETTY_FUNCTION__, safe_strerror(errno)); + __func__, safe_strerror(errno)); close(sock); return -1; } @@ -243,13 +243,13 @@ int pim_msdp_sock_connect(struct pim_msdp_peer *mp) if (!ifp) { flog_err(EC_LIB_INTERFACE, "%s: Unable to lookup vrf interface: %s", - __PRETTY_FUNCTION__, mp->pim->vrf->name); + __func__, mp->pim->vrf->name); return -1; } if (pim_socket_bind(mp->fd, ifp)) { flog_err_sys(EC_LIB_SOCKET, "%s: Unable to bind to socket: %s", - __PRETTY_FUNCTION__, safe_strerror(errno)); + __func__, safe_strerror(errno)); close(mp->fd); mp->fd = -1; return -1; diff --git a/pimd/pim_msg.c b/pimd/pim_msg.c index fba76d84dd..65b6405c81 100644 --- a/pimd/pim_msg.c +++ b/pimd/pim_msg.c @@ -123,7 +123,7 @@ size_t pim_msg_get_jp_group_size(struct list *sources) if (PIM_DEBUG_PIM_PACKETS) zlog_debug( "%s: Considering (%s) children for (S,G,rpt) prune", - __PRETTY_FUNCTION__, up->sg_str); + __func__, up->sg_str); for (ALL_LIST_ELEMENTS_RO(up->sources, up_node, child)) { if (!PIM_UPSTREAM_FLAG_TEST_USE_RPT(child->flags)) { @@ -144,13 +144,12 @@ size_t pim_msg_get_jp_group_size(struct list *sources) if (PIM_DEBUG_PIM_PACKETS) zlog_debug( "%s: SPT Bit and RPF'(%s) != RPF'(S,G): Add Prune (%s,rpt) to compound message", - __PRETTY_FUNCTION__, - up->sg_str, + __func__, up->sg_str, child->sg_str); } else if (PIM_DEBUG_PIM_PACKETS) zlog_debug( "%s: SPT Bit and RPF'(%s) == RPF'(S,G): Not adding Prune for (%s,rpt)", - __PRETTY_FUNCTION__, up->sg_str, + __func__, up->sg_str, child->sg_str); } else if (pim_upstream_empty_inherited_olist(child)) { /* S is supposed to be forwarded along the RPT @@ -163,14 +162,12 @@ size_t pim_msg_get_jp_group_size(struct list *sources) child->flags); if (PIM_DEBUG_PIM_PACKETS) zlog_debug( - "%s: inherited_olist(%s,rpt) is NULL, Add Prune to compound message", - __PRETTY_FUNCTION__, - child->sg_str); + "%s: inherited_olist(%s,rpt) is NULL, Add Prune to compound message", + __func__, child->sg_str); } else if (PIM_DEBUG_PIM_PACKETS) zlog_debug( - "%s: Do not add Prune %s to compound message %s", - __PRETTY_FUNCTION__, child->sg_str, - up->sg_str); + "%s: Do not add Prune %s to compound message %s", + __func__, child->sg_str, up->sg_str); } } return size; diff --git a/pimd/pim_neighbor.c b/pimd/pim_neighbor.c index 3f2aaf2bbe..ca7ca11402 100644 --- a/pimd/pim_neighbor.c +++ b/pimd/pim_neighbor.c @@ -53,8 +53,7 @@ static void dr_election_by_addr(struct interface *ifp) pim_ifp->pim_dr_addr = pim_ifp->primary_address; if (PIM_DEBUG_PIM_TRACE) { - zlog_debug("%s: on interface %s", __PRETTY_FUNCTION__, - ifp->name); + zlog_debug("%s: on interface %s", __func__, ifp->name); } for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, node, neigh)) { @@ -79,14 +78,14 @@ static void dr_election_by_pri(struct interface *ifp) dr_pri = pim_ifp->pim_dr_priority; if (PIM_DEBUG_PIM_TRACE) { - zlog_debug("%s: dr pri %u on interface %s", __PRETTY_FUNCTION__, - dr_pri, ifp->name); + zlog_debug("%s: dr pri %u on interface %s", __func__, dr_pri, + ifp->name); } for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, node, neigh)) { if (PIM_DEBUG_PIM_TRACE) { zlog_info("%s: neigh pri %u addr %x if dr addr %x", - __PRETTY_FUNCTION__, neigh->dr_priority, + __func__, neigh->dr_priority, ntohl(neigh->source_addr.s_addr), ntohl(pim_ifp->pim_dr_addr.s_addr)); } @@ -133,8 +132,7 @@ int pim_if_dr_election(struct interface *ifp) pim_inet4_dump("<new_dr?>", pim_ifp->pim_dr_addr, dr_new_str, sizeof(dr_new_str)); zlog_debug("%s: DR was %s now is %s on interface %s", - __PRETTY_FUNCTION__, dr_old_str, dr_new_str, - ifp->name); + __func__, dr_old_str, dr_new_str, ifp->name); } pim_ifp->pim_dr_election_last = @@ -251,7 +249,7 @@ void pim_neighbor_timer_reset(struct pim_neighbor *neigh, uint16_t holdtime) pim_inet4_dump("<src?>", neigh->source_addr, src_str, sizeof(src_str)); zlog_debug("%s: starting %u sec timer for neighbor %s on %s", - __PRETTY_FUNCTION__, neigh->holdtime, src_str, + __func__, neigh->holdtime, src_str, neigh->interface->name); } @@ -269,7 +267,7 @@ static int on_neighbor_jp_timer(struct thread *t) pim_inet4_dump("<src?>", neigh->source_addr, src_str, sizeof(src_str)); zlog_debug("%s:Sending JP Agg to %s on %s with %d groups", - __PRETTY_FUNCTION__, src_str, neigh->interface->name, + __func__, src_str, neigh->interface->name, neigh->upstream_jp_agg->count); } @@ -338,7 +336,7 @@ pim_neighbor_new(struct interface *ifp, struct in_addr source_addr, if (PIM_DEBUG_PIM_EVENTS) { zlog_debug("%s: creating PIM neighbor %s on interface %s", - __PRETTY_FUNCTION__, src_str, ifp->name); + __func__, src_str, ifp->name); } zlog_info("PIM NEIGHBOR UP: neighbor %s on interface %s", src_str, @@ -390,7 +388,7 @@ static void delete_prefix_list(struct pim_neighbor *neigh) sizeof(addr_str)); zlog_debug( "%s: DUMP_PREFIX_LIST neigh=%x prefix_list=%x prefix=%x addr=%s [%d/%d]", - __PRETTY_FUNCTION__, (unsigned)neigh, + __func__, (unsigned)neigh, (unsigned)neigh->prefix_list, (unsigned)p, addr_str, i, list_size); ++i; @@ -502,7 +500,7 @@ pim_neighbor_add(struct interface *ifp, struct in_addr source_addr, if (PIM_DEBUG_PIM_TRACE_DETAIL) { char str[INET_ADDRSTRLEN]; pim_inet4_dump("<nht_nbr?>", source_addr, str, sizeof(str)); - zlog_debug("%s: neighbor %s added ", __PRETTY_FUNCTION__, str); + zlog_debug("%s: neighbor %s added ", __func__, str); } /* RFC 4601: 4.3.2. DR Election @@ -657,7 +655,7 @@ void pim_neighbor_delete(struct interface *ifp, struct pim_neighbor *neigh, if (PIM_DEBUG_PIM_TRACE) { zlog_debug("%s: deleting PIM neighbor %s on interface %s", - __PRETTY_FUNCTION__, src_str, ifp->name); + __func__, src_str, ifp->name); } // De-Register PIM Neighbor with BFD @@ -793,7 +791,7 @@ void pim_neighbor_update(struct pim_neighbor *neigh, #ifdef DUMP_PREFIX_LIST zlog_debug( "%s: DUMP_PREFIX_LIST old_prefix_list=%x old_size=%d new_prefix_list=%x new_size=%d", - __PRETTY_FUNCTION__, (unsigned)neigh->prefix_list, + __func__, (unsigned)neigh->prefix_list, neigh->prefix_list ? (int)listcount(neigh->prefix_list) : -1, (unsigned)addr_list, addr_list ? (int)listcount(addr_list) : -1); @@ -804,7 +802,7 @@ void pim_neighbor_update(struct pim_neighbor *neigh, flog_err( EC_LIB_DEVELOPMENT, "%s: internal error: trying to replace same prefix list=%p", - __PRETTY_FUNCTION__, (void *)addr_list); + __func__, (void *)addr_list); } } else { /* Delete existing secondary address list */ diff --git a/pimd/pim_nht.c b/pimd/pim_nht.c index 5cb9492ec3..60b7c73d43 100644 --- a/pimd/pim_nht.c +++ b/pimd/pim_nht.c @@ -61,7 +61,7 @@ void pim_sendmsg_zebra_rnh(struct pim_instance *pim, struct zclient *zclient, prefix2str(p, buf, sizeof(buf)); zlog_debug( "%s: NHT %sregistered addr %s(%s) with Zebra ret:%d ", - __PRETTY_FUNCTION__, + __func__, (command == ZEBRA_NEXTHOP_REGISTER) ? " " : "de", buf, pim->vrf->name, ret); } @@ -145,7 +145,7 @@ int pim_find_or_track_nexthop(struct pim_instance *pim, struct prefix *addr, prefix2str(addr, buf, sizeof(buf)); zlog_debug( "%s: NHT cache and zebra notification added for %s(%s)", - __PRETTY_FUNCTION__, buf, pim->vrf->name); + __func__, buf, pim->vrf->name); } } @@ -217,10 +217,10 @@ void pim_delete_tracked_nexthop(struct pim_instance *pim, struct prefix *addr, if (PIM_DEBUG_PIM_NHT) { char buf[PREFIX_STRLEN]; - prefix2str(addr, buf, sizeof buf); + prefix2str(addr, buf, sizeof(buf)); zlog_debug( "%s: NHT %s(%s) rp_list count:%d upstream count:%ld", - __PRETTY_FUNCTION__, buf, pim->vrf->name, + __func__, buf, pim->vrf->name, pnc->rp_list->count, pnc->upstream_hash->count); } @@ -255,7 +255,7 @@ bool pim_nexthop_match(struct pim_instance *pim, struct in_addr addr, int num_ifindex; if (addr.s_addr == INADDR_NONE) - return 0; + return false; memset(nexthop_tab, 0, sizeof(struct pim_zlookup_nexthop) * MULTIPATH_NUM); @@ -267,8 +267,8 @@ bool pim_nexthop_match(struct pim_instance *pim, struct in_addr addr, pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); zlog_warn( "%s %s: could not find nexthop ifindex for address %s", - __FILE__, __PRETTY_FUNCTION__, addr_str); - return 0; + __FILE__, __func__, addr_str); + return false; } while (i < num_ifindex) { @@ -283,8 +283,8 @@ bool pim_nexthop_match(struct pim_instance *pim, struct in_addr addr, sizeof(addr_str)); zlog_debug( "%s %s: could not find interface for ifindex %d (address %s)", - __FILE__, __PRETTY_FUNCTION__, - first_ifindex, addr_str); + __FILE__, __func__, first_ifindex, + addr_str); } i++; continue; @@ -298,8 +298,8 @@ bool pim_nexthop_match(struct pim_instance *pim, struct in_addr addr, sizeof(addr_str)); zlog_debug( "%s: multicast not enabled on input interface %s (ifindex=%d, RPF for source %s)", - __PRETTY_FUNCTION__, ifp->name, - first_ifindex, addr_str); + __func__, ifp->name, first_ifindex, + addr_str); } i++; continue; @@ -319,12 +319,12 @@ bool pim_nexthop_match(struct pim_instance *pim, struct in_addr addr, if (nexthop_tab[i].nexthop_addr.u.prefix4.s_addr == ip_src.s_addr) - return 1; + return true; i++; } - return 0; + return false; } /* Given a source address and a neighbor address, check if the neighbor is one @@ -348,7 +348,7 @@ bool pim_nexthop_match_nht_cache(struct pim_instance *pim, struct in_addr addr, pnc = pim_nexthop_cache_find(pim, &rpf); if (!pnc || !pnc->nexthop_num) - return 0; + return false; for (nh_node = pnc->nexthop; nh_node; nh_node = nh_node->next) { first_ifindex = nh_node->ifindex; @@ -361,9 +361,8 @@ bool pim_nexthop_match_nht_cache(struct pim_instance *pim, struct in_addr addr, sizeof(addr_str)); zlog_debug( "%s %s: could not find interface for ifindex %d (address %s(%s))", - __FILE__, __PRETTY_FUNCTION__, - first_ifindex, addr_str, - pim->vrf->name); + __FILE__, __func__, first_ifindex, + addr_str, pim->vrf->name); } nh_iter++; continue; @@ -376,9 +375,8 @@ bool pim_nexthop_match_nht_cache(struct pim_instance *pim, struct in_addr addr, sizeof(addr_str)); zlog_debug( "%s: multicast not enabled on input interface %s(%s) (ifindex=%d, RPF for source %s)", - __PRETTY_FUNCTION__, ifp->name, - pim->vrf->name, first_ifindex, - addr_str); + __func__, ifp->name, pim->vrf->name, + first_ifindex, addr_str); } nh_iter++; continue; @@ -390,7 +388,7 @@ bool pim_nexthop_match_nht_cache(struct pim_instance *pim, struct in_addr addr, if (PIM_DEBUG_PIM_NHT) zlog_debug( "%s: pim nbr not found on input interface %s(%s)", - __PRETTY_FUNCTION__, ifp->name, + __func__, ifp->name, pim->vrf->name); nh_iter++; continue; @@ -398,10 +396,10 @@ bool pim_nexthop_match_nht_cache(struct pim_instance *pim, struct in_addr addr, } if (nh_node->gate.ipv4.s_addr == ip_src.s_addr) - return 1; + return true; } - return 0; + return false; } void pim_rp_nexthop_del(struct rp_info *rp_info) @@ -460,12 +458,15 @@ static int pim_update_upstream_nh_helper(struct hash_bucket *bucket, void *arg) if (PIM_DEBUG_PIM_NHT) { - zlog_debug("%s: NHT upstream %s(%s) old ifp %s new ifp %s", - __PRETTY_FUNCTION__, up->sg_str, pim->vrf->name, - old.source_nexthop.interface - ? old.source_nexthop.interface->name : "Unknown", - up->rpf.source_nexthop.interface - ? up->rpf.source_nexthop.interface->name : "Unknown"); + zlog_debug( + "%s: NHT upstream %s(%s) old ifp %s new ifp %s", + __func__, up->sg_str, pim->vrf->name, + old.source_nexthop.interface ? old.source_nexthop + .interface->name + : "Unknown", + up->rpf.source_nexthop.interface ? up->rpf.source_nexthop + .interface->name + : "Unknown"); } return HASHWALK_CONTINUE; @@ -559,8 +560,15 @@ static int pim_ecmp_nexthop_search(struct pim_instance *pim, if (PIM_DEBUG_PIM_NHT) zlog_debug( "%s: current nexthop does not have nbr ", - __PRETTY_FUNCTION__); + __func__); } else { + /* update metric even if the upstream + * neighbor stays unchanged + */ + nexthop->mrib_metric_preference = + pnc->distance; + nexthop->mrib_route_metric = + pnc->metric; if (PIM_DEBUG_PIM_NHT) { char src_str[INET_ADDRSTRLEN]; pim_inet4_dump("<addr?>", @@ -574,9 +582,8 @@ static int pim_ecmp_nexthop_search(struct pim_instance *pim, sizeof(grp_str)); zlog_debug( "%s: (%s,%s)(%s) current nexthop %s is valid, skipping new path selection", - __PRETTY_FUNCTION__, - src_str, grp_str, - pim->vrf->name, + __func__, src_str, + grp_str, pim->vrf->name, nexthop->interface->name); } return 1; @@ -626,9 +633,8 @@ static int pim_ecmp_nexthop_search(struct pim_instance *pim, addr_str, sizeof(addr_str)); zlog_debug( "%s %s: could not find interface for ifindex %d (address %s(%s))", - __FILE__, __PRETTY_FUNCTION__, - first_ifindex, addr_str, - pim->vrf->name); + __FILE__, __func__, first_ifindex, + addr_str, pim->vrf->name); } if (nh_iter == mod_val) mod_val++; // Select nexthpath @@ -642,9 +648,8 @@ static int pim_ecmp_nexthop_search(struct pim_instance *pim, addr_str, sizeof(addr_str)); zlog_debug( "%s: multicast not enabled on input interface %s(%s) (ifindex=%d, RPF for source %s)", - __PRETTY_FUNCTION__, ifp->name, - pim->vrf->name, first_ifindex, - addr_str); + __func__, ifp->name, pim->vrf->name, + first_ifindex, addr_str); } if (nh_iter == mod_val) mod_val++; // Select nexthpath @@ -659,7 +664,7 @@ static int pim_ecmp_nexthop_search(struct pim_instance *pim, if (PIM_DEBUG_PIM_NHT) zlog_debug( "%s: pim nbr not found on input interface %s(%s)", - __PRETTY_FUNCTION__, ifp->name, + __func__, ifp->name, pim->vrf->name); if (nh_iter == mod_val) mod_val++; // Select nexthpath @@ -694,9 +699,9 @@ static int pim_ecmp_nexthop_search(struct pim_instance *pim, buf, sizeof(buf)); zlog_debug( "%s: (%s,%s)(%s) selected nhop interface %s addr %s mod_val %u iter %d ecmp %d", - __PRETTY_FUNCTION__, buf2, buf3, - pim->vrf->name, ifp->name, buf, mod_val, - nh_iter, pim->ecmp_enable); + __func__, buf2, buf3, pim->vrf->name, + ifp->name, buf, mod_val, nh_iter, + pim->ecmp_enable); } } nh_iter++; @@ -733,7 +738,7 @@ int pim_parse_nexthop_update(ZAPI_CALLBACK_ARGS) if (PIM_DEBUG_PIM_NHT) zlog_debug( "%s: Decode of nexthop update from zebra failed", - __PRETTY_FUNCTION__); + __func__); return 0; } @@ -746,7 +751,7 @@ int pim_parse_nexthop_update(ZAPI_CALLBACK_ARGS) prefix2str(&rpf.rpf_addr, buf, sizeof(buf)); zlog_debug( "%s: Skipping NHT update, addr %s is not in local cached DB.", - __PRETTY_FUNCTION__, buf); + __func__, buf); } return 0; } @@ -803,8 +808,7 @@ int pim_parse_nexthop_update(ZAPI_CALLBACK_ARGS) char buf[NEXTHOP_STRLEN]; zlog_debug( "%s: could not find interface for ifindex %d(%s) (addr %s)", - __PRETTY_FUNCTION__, - nexthop->ifindex, + __func__, nexthop->ifindex, pim->vrf->name, nexthop2str(nexthop, buf, sizeof(buf))); @@ -819,8 +823,7 @@ int pim_parse_nexthop_update(ZAPI_CALLBACK_ARGS) prefix2str(&nhr.prefix, p_str, sizeof(p_str)); zlog_debug( "%s: NHT addr %s(%s) %d-nhop via %s(%s) type %d distance:%u metric:%u ", - __PRETTY_FUNCTION__, p_str, - pim->vrf->name, i + 1, + __func__, p_str, pim->vrf->name, i + 1, inet_ntoa(nexthop->gate.ipv4), ifp->name, nexthop->type, nhr.distance, nhr.metric); @@ -840,7 +843,7 @@ int pim_parse_nexthop_update(ZAPI_CALLBACK_ARGS) zlog_debug( "%s: multicast not enabled on input interface %s(%s) (ifindex=%d, addr %s)", - __PRETTY_FUNCTION__, ifp->name, + __func__, ifp->name, pim->vrf->name, nexthop->ifindex, nexthop2str(nexthop, buf, @@ -879,9 +882,9 @@ int pim_parse_nexthop_update(ZAPI_CALLBACK_ARGS) prefix2str(&nhr.prefix, buf, sizeof(buf)); zlog_debug( "%s: NHT Update for %s(%s) num_nh %d num_pim_nh %d vrf:%u up %ld rp %d", - __PRETTY_FUNCTION__, buf, pim->vrf->name, - nhr.nexthop_num, pnc->nexthop_num, vrf_id, - pnc->upstream_hash->count, listcount(pnc->rp_list)); + __func__, buf, pim->vrf->name, nhr.nexthop_num, + pnc->nexthop_num, vrf_id, pnc->upstream_hash->count, + listcount(pnc->rp_list)); } pim_rpf_set_refresh_time(pim); @@ -915,7 +918,7 @@ int pim_ecmp_nexthop_lookup(struct pim_instance *pim, pim_inet4_dump("<addr?>", src->u.prefix4, addr_str, sizeof(addr_str)); zlog_debug("%s: Looking up: %s(%s), last lookup time: %lld", - __PRETTY_FUNCTION__, addr_str, pim->vrf->name, + __func__, addr_str, pim->vrf->name, nexthop->last_lookup_time); } @@ -940,7 +943,7 @@ int pim_ecmp_nexthop_lookup(struct pim_instance *pim, if (PIM_DEBUG_PIM_NHT) zlog_warn( "%s: could not find nexthop ifindex for address %s(%s)", - __PRETTY_FUNCTION__, addr_str, pim->vrf->name); + __func__, addr_str, pim->vrf->name); return 0; } @@ -977,8 +980,8 @@ int pim_ecmp_nexthop_lookup(struct pim_instance *pim, hash_val = pim_compute_ecmp_hash(src, grp); mod_val = hash_val % consider; if (PIM_DEBUG_PIM_NHT_DETAIL) - zlog_debug("%s: hash_val %u mod_val %u", - __PRETTY_FUNCTION__, hash_val, mod_val); + zlog_debug("%s: hash_val %u mod_val %u", __func__, + hash_val, mod_val); } i = 0; @@ -990,9 +993,8 @@ int pim_ecmp_nexthop_lookup(struct pim_instance *pim, if (PIM_DEBUG_PIM_NHT) zlog_debug( "%s %s: could not find interface for ifindex %d (address %s(%s))", - __FILE__, __PRETTY_FUNCTION__, - first_ifindex, addr_str, - pim->vrf->name); + __FILE__, __func__, first_ifindex, + addr_str, pim->vrf->name); if (i == mod_val) mod_val++; i++; @@ -1003,9 +1005,8 @@ int pim_ecmp_nexthop_lookup(struct pim_instance *pim, if (PIM_DEBUG_PIM_NHT) zlog_debug( "%s: multicast not enabled on input interface %s(%s) (ifindex=%d, RPF for source %s)", - __PRETTY_FUNCTION__, ifp->name, - pim->vrf->name, first_ifindex, - addr_str); + __func__, ifp->name, pim->vrf->name, + first_ifindex, addr_str); if (i == mod_val) mod_val++; i++; @@ -1024,7 +1025,7 @@ int pim_ecmp_nexthop_lookup(struct pim_instance *pim, if (PIM_DEBUG_PIM_NHT) zlog_debug( "%s: NBR not found on input interface %s(%s) (RPF for source %s)", - __PRETTY_FUNCTION__, ifp->name, + __func__, ifp->name, pim->vrf->name, addr_str); continue; } @@ -1039,8 +1040,8 @@ int pim_ecmp_nexthop_lookup(struct pim_instance *pim, nexthop_str, sizeof(nexthop_str)); zlog_debug( "%s: found nhop %s for addr %s interface %s(%s) metric %d dist %d", - __PRETTY_FUNCTION__, nexthop_str, - addr_str, ifp->name, pim->vrf->name, + __func__, nexthop_str, addr_str, + ifp->name, pim->vrf->name, nexthop_tab[i].route_metric, nexthop_tab[i].protocol_distance); } @@ -1079,11 +1080,11 @@ int pim_ecmp_fib_lookup_if_vif_index(struct pim_instance *pim, sizeof(addr_str)); memset(&nhop, 0, sizeof(nhop)); - if (!pim_ecmp_nexthop_lookup(pim, &nhop, src, grp, 0)) { + if (!pim_ecmp_nexthop_lookup(pim, &nhop, src, grp, 1)) { if (PIM_DEBUG_PIM_NHT) zlog_debug( "%s: could not find nexthop ifindex for address %s(%s)", - __PRETTY_FUNCTION__, addr_str, pim->vrf->name); + __func__, addr_str, pim->vrf->name); return -1; } @@ -1091,8 +1092,7 @@ int pim_ecmp_fib_lookup_if_vif_index(struct pim_instance *pim, if (PIM_DEBUG_PIM_NHT) zlog_debug( "%s: found nexthop ifindex=%d (interface %s(%s)) for address %s", - __PRETTY_FUNCTION__, ifindex, - ifindex2ifname(ifindex, pim->vrf_id), + __func__, ifindex, ifindex2ifname(ifindex, pim->vrf_id), pim->vrf->name, addr_str); vif_index = pim_if_find_vifindex_by_ifindex(pim, ifindex); @@ -1101,8 +1101,7 @@ int pim_ecmp_fib_lookup_if_vif_index(struct pim_instance *pim, if (PIM_DEBUG_PIM_NHT) { zlog_debug( "%s: low vif_index=%d(%s) < 1 nexthop for address %s", - __PRETTY_FUNCTION__, vif_index, pim->vrf->name, - addr_str); + __func__, vif_index, pim->vrf->name, addr_str); } return -2; } diff --git a/pimd/pim_oil.c b/pimd/pim_oil.c index 598988f88f..21febcc969 100644 --- a/pimd/pim_oil.c +++ b/pimd/pim_oil.c @@ -33,9 +33,6 @@ #include "pim_time.h" #include "pim_vxlan.h" -// struct list *pim_channel_oil_list = NULL; -// struct hash *pim_channel_oil_hash = NULL; - static void pim_channel_update_mute(struct channel_oil *c_oil); char *pim_channel_oil_dump(struct channel_oil *c_oil, char *buf, size_t size) @@ -149,8 +146,7 @@ struct channel_oil *pim_channel_oil_add(struct pim_instance *pim, if (PIM_DEBUG_MROUTE) zlog_debug( "%s(%s): Existing oil for %pSG4 Ref Count: %d (Post Increment)", - __PRETTY_FUNCTION__, name, sg, - c_oil->oil_ref_count); + __func__, name, sg, c_oil->oil_ref_count); return c_oil; } @@ -175,7 +171,7 @@ struct channel_oil *pim_channel_oil_add(struct pim_instance *pim, } struct channel_oil *pim_channel_oil_del(struct channel_oil *c_oil, - const char *name) + const char *name) { if (PIM_DEBUG_MROUTE) { struct prefix_sg sg = {.src = c_oil->oil.mfcc_mcastgrp, @@ -183,7 +179,7 @@ struct channel_oil *pim_channel_oil_del(struct channel_oil *c_oil, zlog_debug( "%s(%s): Del oil for %pSG4, Ref Count: %d (Predecrement)", - __PRETTY_FUNCTION__, name, &sg, c_oil->oil_ref_count); + __func__, name, &sg, c_oil->oil_ref_count); } --c_oil->oil_ref_count; @@ -244,7 +240,7 @@ int pim_channel_del_oif(struct channel_oil *channel_oil, struct interface *oif, sizeof(source_str)); zlog_debug( "%s %s: no existing protocol mask %u(%u) for requested OIF %s (vif_index=%d, min_ttl=%d) for channel (S,G)=(%s,%s)", - __FILE__, __PRETTY_FUNCTION__, proto_mask, + __FILE__, __func__, proto_mask, channel_oil ->oif_flags[pim_ifp->mroute_vif_index], oif->name, pim_ifp->mroute_vif_index, @@ -270,7 +266,7 @@ int pim_channel_del_oif(struct channel_oil *channel_oil, struct interface *oif, sizeof(source_str)); zlog_debug( "%s %s: other protocol masks remain for requested OIF %s (vif_index=%d, min_ttl=%d) for channel (S,G)=(%s,%s)", - __FILE__, __PRETTY_FUNCTION__, oif->name, + __FILE__, __func__, oif->name, pim_ifp->mroute_vif_index, channel_oil->oil .mfcc_ttls[pim_ifp->mroute_vif_index], @@ -283,7 +279,7 @@ int pim_channel_del_oif(struct channel_oil *channel_oil, struct interface *oif, /* clear mute; will be re-evaluated when the OIF becomes valid again */ channel_oil->oif_flags[pim_ifp->mroute_vif_index] &= ~PIM_OIF_FLAG_MUTE; - if (pim_upstream_mroute_add(channel_oil, __PRETTY_FUNCTION__)) { + if (pim_upstream_mroute_add(channel_oil, __func__)) { if (PIM_DEBUG_MROUTE) { char group_str[INET_ADDRSTRLEN]; char source_str[INET_ADDRSTRLEN]; @@ -295,7 +291,7 @@ int pim_channel_del_oif(struct channel_oil *channel_oil, struct interface *oif, sizeof(source_str)); zlog_debug( "%s %s: could not remove output interface %s (vif_index=%d) for channel (S,G)=(%s,%s)", - __FILE__, __PRETTY_FUNCTION__, oif->name, + __FILE__, __func__, oif->name, pim_ifp->mroute_vif_index, source_str, group_str); } @@ -313,8 +309,8 @@ int pim_channel_del_oif(struct channel_oil *channel_oil, struct interface *oif, source_str, sizeof(source_str)); zlog_debug( "%s(%s): (S,G)=(%s,%s): proto_mask=%u IIF:%d OIF=%s vif_index=%d", - __PRETTY_FUNCTION__, caller, source_str, group_str, - proto_mask, channel_oil->oil.mfcc_parent, oif->name, + __func__, caller, source_str, group_str, proto_mask, + channel_oil->oil.mfcc_parent, oif->name, pim_ifp->mroute_vif_index); } @@ -405,7 +401,7 @@ void pim_channel_update_oif_mute(struct channel_oil *c_oil, c_oil->oif_flags[pim_ifp->mroute_vif_index] &= ~PIM_OIF_FLAG_MUTE; - pim_upstream_mroute_add(c_oil, __PRETTY_FUNCTION__); + pim_upstream_mroute_add(c_oil, __func__); } /* pim_upstream has been set or cleared on the c_oil. re-eval mute state @@ -455,8 +451,8 @@ int pim_channel_add_oif(struct channel_oil *channel_oil, struct interface *oif, sizeof(source_str)); zlog_debug( "%s %s: existing protocol mask %u requested OIF %s (vif_index=%d, min_ttl=%d) for channel (S,G)=(%s,%s)", - __FILE__, __PRETTY_FUNCTION__, proto_mask, - oif->name, pim_ifp->mroute_vif_index, + __FILE__, __func__, proto_mask, oif->name, + pim_ifp->mroute_vif_index, channel_oil->oil .mfcc_ttls[pim_ifp->mroute_vif_index], source_str, group_str); @@ -489,15 +485,31 @@ int pim_channel_add_oif(struct channel_oil *channel_oil, struct interface *oif, source_str, sizeof(source_str)); zlog_warn( "%s %s: new protocol mask %u requested nonexistent OIF %s (vif_index=%d, min_ttl=%d) for channel (S,G)=(%s,%s)", - __FILE__, __PRETTY_FUNCTION__, - proto_mask, oif->name, - pim_ifp->mroute_vif_index, + __FILE__, __func__, proto_mask, + oif->name, pim_ifp->mroute_vif_index, channel_oil->oil.mfcc_ttls [pim_ifp->mroute_vif_index], source_str, group_str); } } + if (PIM_DEBUG_MROUTE) { + char group_str[INET_ADDRSTRLEN]; + char source_str[INET_ADDRSTRLEN]; + pim_inet4_dump("<group?>", + channel_oil->oil.mfcc_mcastgrp, + group_str, sizeof(group_str)); + pim_inet4_dump("<source?>", + channel_oil->oil.mfcc_origin, source_str, + sizeof(source_str)); + zlog_debug( + "%s(%s): (S,G)=(%s,%s): proto_mask=%u OIF=%s vif_index=%d added to 0x%x", + __func__, caller, source_str, group_str, + proto_mask, oif->name, + pim_ifp->mroute_vif_index, + channel_oil + ->oif_flags[pim_ifp->mroute_vif_index]); + } return 0; } @@ -515,7 +527,7 @@ int pim_channel_add_oif(struct channel_oil *channel_oil, struct interface *oif, sizeof(source_str)); zlog_debug( "%s %s: interface %s (vif_index=%d) is existing output for channel (S,G)=(%s,%s)", - __FILE__, __PRETTY_FUNCTION__, oif->name, + __FILE__, __func__, oif->name, pim_ifp->mroute_vif_index, source_str, group_str); } @@ -541,7 +553,7 @@ int pim_channel_add_oif(struct channel_oil *channel_oil, struct interface *oif, * valid to get installed in kernel. */ if (channel_oil->oil.mfcc_parent != MAXVIFS) { - if (pim_upstream_mroute_add(channel_oil, __PRETTY_FUNCTION__)) { + if (pim_upstream_mroute_add(channel_oil, __func__)) { if (PIM_DEBUG_MROUTE) { char group_str[INET_ADDRSTRLEN]; char source_str[INET_ADDRSTRLEN]; @@ -552,10 +564,10 @@ int pim_channel_add_oif(struct channel_oil *channel_oil, struct interface *oif, channel_oil->oil.mfcc_origin, source_str, sizeof(source_str)); zlog_debug( - "%s %s: could not add output interface %s (vif_index=%d) for channel (S,G)=(%s,%s)", - __FILE__, __PRETTY_FUNCTION__, oif->name, - pim_ifp->mroute_vif_index, source_str, - group_str); + "%s %s: could not add output interface %s (vif_index=%d) for channel (S,G)=(%s,%s)", + __FILE__, __func__, oif->name, + pim_ifp->mroute_vif_index, source_str, + group_str); } channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index] @@ -578,8 +590,8 @@ int pim_channel_add_oif(struct channel_oil *channel_oil, struct interface *oif, source_str, sizeof(source_str)); zlog_debug( "%s(%s): (S,G)=(%s,%s): proto_mask=%u OIF=%s vif_index=%d: DONE", - __PRETTY_FUNCTION__, caller, source_str, group_str, - proto_mask, oif->name, pim_ifp->mroute_vif_index); + __func__, caller, source_str, group_str, proto_mask, + oif->name, pim_ifp->mroute_vif_index); } return 0; diff --git a/pimd/pim_oil.h b/pimd/pim_oil.h index 788ddaa16c..8a808afa73 100644 --- a/pimd/pim_oil.h +++ b/pimd/pim_oil.h @@ -130,7 +130,7 @@ void pim_channel_oil_change_iif(struct pim_instance *pim, struct channel_oil *c_oil, int input_vif_index, const char *name); struct channel_oil *pim_channel_oil_del(struct channel_oil *c_oil, - const char *name); + const char *name); int pim_channel_add_oif(struct channel_oil *c_oil, struct interface *oif, uint32_t proto_mask, const char *caller); @@ -146,6 +146,6 @@ void pim_channel_update_oif_mute(struct channel_oil *c_oil, void pim_channel_oil_upstream_deref(struct channel_oil *c_oil); void pim_channel_del_inherited_oif(struct channel_oil *c_oil, - struct interface *oif, const char *caller); + struct interface *oif, const char *caller); #endif /* PIM_OIL_H */ diff --git a/pimd/pim_pim.c b/pimd/pim_pim.c index b367aa21f4..8d7a921cf4 100644 --- a/pimd/pim_pim.c +++ b/pimd/pim_pim.c @@ -119,7 +119,7 @@ void pim_sock_delete(struct interface *ifp, const char *delete_message) if (!ifp->info) { flog_err(EC_PIM_CONFIG, "%s: %s: but PIM not enabled on interface %s (!)", - __PRETTY_FUNCTION__, delete_message, ifp->name); + __func__, delete_message, ifp->name); return; } @@ -233,7 +233,7 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len) ifp->name, ip_hdr->ip_ttl, header->ver, pim_msg_len, checksum); if (PIM_DEBUG_PIM_PACKETDUMP_RECV) { - pim_pkt_dump(__PRETTY_FUNCTION__, pim_msg, pim_msg_len); + pim_pkt_dump(__func__, pim_msg, pim_msg_len); } } @@ -258,8 +258,8 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len) if (PIM_DEBUG_PIM_PACKETS) zlog_debug( "%s %s: non-hello PIM message type=%d from non-neighbor %s on %s", - __FILE__, __PRETTY_FUNCTION__, - header->type, src_str, ifp->name); + __FILE__, __func__, header->type, + src_str, ifp->name); return -1; } pim_neighbor_timer_reset(neigh, neigh->holdtime); @@ -273,8 +273,8 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len) if (PIM_DEBUG_PIM_PACKETS) zlog_debug( "%s %s: non-hello PIM message type=%d from non-neighbor %s on %s", - __FILE__, __PRETTY_FUNCTION__, - header->type, src_str, ifp->name); + __FILE__, __func__, header->type, + src_str, ifp->name); return -1; } pim_neighbor_timer_reset(neigh, neigh->holdtime); @@ -347,15 +347,15 @@ static int pim_sock_read(struct thread *t) if (PIM_DEBUG_PIM_PACKETS) zlog_debug( "%s: Received incoming pim packet on interface(%s:%d) not yet configured for pim", - __PRETTY_FUNCTION__, - ifp ? ifp->name : "Unknown", ifindex); + __func__, ifp ? ifp->name : "Unknown", + ifindex); goto done; } int fail = pim_pim_packet(ifp, buf, len); if (fail) { if (PIM_DEBUG_PIM_PACKETS) zlog_debug("%s: pim_pim_packet() return=%d", - __PRETTY_FUNCTION__, fail); + __func__, fail); goto done; } @@ -519,8 +519,8 @@ static int pim_msg_send_frame(int fd, char *buf, size_t len, sizeof(dst_str)); zlog_warn( "%s: sendto() failure to %s: fd=%d msg_size=%zd: errno=%d: %s", - __PRETTY_FUNCTION__, dst_str, fd, len, - errno, safe_strerror(errno)); + __func__, dst_str, fd, len, errno, + safe_strerror(errno)); } return -1; } @@ -588,9 +588,8 @@ int pim_msg_send(int fd, struct in_addr src, struct in_addr dst, if (PIM_DEBUG_PIM_PACKETS) { char dst_str[INET_ADDRSTRLEN]; pim_inet4_dump("<dst?>", dst, dst_str, sizeof(dst_str)); - zlog_debug("%s: to %s on %s: msg_size=%d checksum=%x", - __PRETTY_FUNCTION__, dst_str, ifname, pim_msg_size, - header->checksum); + zlog_debug("%s: to %s on %s: msg_size=%d checksum=%x", __func__, + dst_str, ifname, pim_msg_size, header->checksum); } memset(&to, 0, sizeof(to)); @@ -599,7 +598,7 @@ int pim_msg_send(int fd, struct in_addr src, struct in_addr dst, tolen = sizeof(to); if (PIM_DEBUG_PIM_PACKETDUMP_SEND) { - pim_pkt_dump(__PRETTY_FUNCTION__, pim_msg, pim_msg_size); + pim_pkt_dump(__func__, pim_msg, pim_msg_size); } pim_msg_send_frame(fd, (char *)buffer, sendlen, (struct sockaddr *)&to, @@ -622,7 +621,7 @@ static int hello_send(struct interface *ifp, uint16_t holdtime) sizeof(dst_str)); zlog_debug( "%s: to %s on %s: holdt=%u prop_d=%u overr_i=%u dis_join_supp=%d dr_prio=%u gen_id=%08x addrs=%d", - __PRETTY_FUNCTION__, dst_str, ifp->name, holdtime, + __func__, dst_str, ifp->name, holdtime, pim_ifp->pim_propagation_delay_msec, pim_ifp->pim_override_interval_msec, PIM_IF_TEST_PIM_CAN_DISABLE_JOIN_SUPRESSION( @@ -655,7 +654,7 @@ static int hello_send(struct interface *ifp, uint16_t holdtime) if (PIM_DEBUG_PIM_HELLO) { zlog_debug( "%s: could not send PIM message on interface %s", - __PRETTY_FUNCTION__, ifp->name); + __func__, ifp->name); } return -2; } diff --git a/pimd/pim_register.c b/pimd/pim_register.c index aa9faf6923..19baecb9c2 100644 --- a/pimd/pim_register.c +++ b/pimd/pim_register.c @@ -99,7 +99,7 @@ void pim_register_stop_send(struct interface *ifp, struct prefix_sg *sg, pinfo = (struct pim_interface *)ifp->info; if (!pinfo) { if (PIM_DEBUG_PIM_TRACE) - zlog_debug("%s: No pinfo!", __PRETTY_FUNCTION__); + zlog_debug("%s: No pinfo!", __func__); return; } if (pim_msg_send(pinfo->pim_sock_fd, src, originator, buffer, @@ -107,7 +107,7 @@ void pim_register_stop_send(struct interface *ifp, struct prefix_sg *sg, if (PIM_DEBUG_PIM_TRACE) { zlog_debug( "%s: could not send PIM register stop message on interface %s", - __PRETTY_FUNCTION__, ifp->name); + __func__, ifp->name); } } ++pinfo->pim_ifstat_reg_stop_send; @@ -122,6 +122,8 @@ int pim_register_stop_recv(struct interface *ifp, uint8_t *buf, int buf_size) struct prefix_sg sg; int l; + ++pim_ifp->pim_ifstat_reg_stop_recv; + memset(&sg, 0, sizeof(struct prefix_sg)); l = pim_parse_addr_group(&sg, buf, buf_size); buf += l; @@ -177,7 +179,7 @@ void pim_register_send(const uint8_t *buf, int buf_size, struct in_addr src, if (!ifp) { if (PIM_DEBUG_PIM_REG) zlog_debug("%s: No interface to transmit register on", - __PRETTY_FUNCTION__); + __func__); return; } pinfo = (struct pim_interface *)ifp->info; @@ -185,7 +187,7 @@ void pim_register_send(const uint8_t *buf, int buf_size, struct in_addr src, if (PIM_DEBUG_PIM_REG) zlog_debug( "%s: Interface: %s not configured for pim to trasmit on!\n", - __PRETTY_FUNCTION__, ifp->name); + __func__, ifp->name); return; } @@ -194,8 +196,8 @@ void pim_register_send(const uint8_t *buf, int buf_size, struct in_addr src, strlcpy(rp_str, inet_ntoa(rpg->rpf_addr.u.prefix4), sizeof(rp_str)); zlog_debug("%s: Sending %s %sRegister Packet to %s on %s", - __PRETTY_FUNCTION__, up->sg_str, - null_register ? "NULL " : "", rp_str, ifp->name); + __func__, up->sg_str, null_register ? "NULL " : "", + rp_str, ifp->name); } memset(buffer, 0, 10000); @@ -215,7 +217,7 @@ void pim_register_send(const uint8_t *buf, int buf_size, struct in_addr src, if (PIM_DEBUG_PIM_TRACE) { zlog_debug( "%s: could not send PIM register message on interface %s", - __PRETTY_FUNCTION__, ifp->name); + __func__, ifp->name); } return; } @@ -233,7 +235,7 @@ void pim_null_register_send(struct pim_upstream *up) if (PIM_DEBUG_PIM_TRACE) zlog_debug( "%s: Cannot send null-register for %s no valid iif", - __PRETTY_FUNCTION__, up->sg_str); + __func__, up->sg_str); return; } @@ -242,7 +244,7 @@ void pim_null_register_send(struct pim_upstream *up) if (PIM_DEBUG_PIM_TRACE) zlog_debug( "%s: Cannot send null-register for %s no RPF to the RP", - __PRETTY_FUNCTION__, up->sg_str); + __func__, up->sg_str); return; } @@ -261,7 +263,7 @@ void pim_null_register_send(struct pim_upstream *up) if (PIM_DEBUG_PIM_TRACE) zlog_debug( "%s: Cannot send null-register for %s vxlan-aa PIP unavailable", - __PRETTY_FUNCTION__, up->sg_str); + __func__, up->sg_str); return; } } @@ -417,8 +419,8 @@ int pim_register_recv(struct interface *ifp, struct in_addr dest_addr, if (!upstream) { upstream = pim_upstream_add( pim_ifp->pim, &sg, ifp, - PIM_UPSTREAM_FLAG_MASK_SRC_STREAM, - __PRETTY_FUNCTION__, NULL); + PIM_UPSTREAM_FLAG_MASK_SRC_STREAM, __func__, + NULL); if (!upstream) { zlog_warn("Failure to create upstream state"); return 1; diff --git a/pimd/pim_rp.c b/pimd/pim_rp.c index 2db39bac4b..355aa07048 100644 --- a/pimd/pim_rp.c +++ b/pimd/pim_rp.c @@ -240,7 +240,7 @@ struct rp_info *pim_rp_find_match_group(struct pim_instance *pim, flog_err( EC_LIB_DEVELOPMENT, "%s: BUG We should have found default group information\n", - __PRETTY_FUNCTION__); + __func__); return best; } @@ -248,13 +248,14 @@ struct rp_info *pim_rp_find_match_group(struct pim_instance *pim, if (PIM_DEBUG_PIM_TRACE) { char buf[PREFIX_STRLEN]; - route_unlock_node(rn); zlog_debug("Lookedup: %p for rp_info: %p(%s) Lock: %d", rn, rp_info, prefix2str(&rp_info->group, buf, sizeof(buf)), rn->lock); } + route_unlock_node(rn); + if (!best) return rp_info; @@ -351,8 +352,7 @@ void pim_upstream_update(struct pim_instance *pim, struct pim_upstream *up) if (PIM_DEBUG_PIM_TRACE) zlog_debug("%s: pim upstream update for old upstream %s", - __PRETTY_FUNCTION__, - inet_ntoa(old_upstream_addr)); + __func__, inet_ntoa(old_upstream_addr)); if (old_upstream_addr.s_addr == new_upstream_addr.s_addr) return; @@ -371,8 +371,9 @@ void pim_upstream_update(struct pim_instance *pim, struct pim_upstream *up) char buf[PREFIX2STR_BUFFER]; prefix2str(&nht_p, buf, sizeof(buf)); - zlog_debug("%s: Deregister upstream %s addr %s with Zebra NHT", - __PRETTY_FUNCTION__, up->sg_str, buf); + zlog_debug( + "%s: Deregister upstream %s addr %s with Zebra NHT", + __func__, up->sg_str, buf); } pim_delete_tracked_nexthop(pim, &nht_p, up, NULL, false); } @@ -384,7 +385,7 @@ void pim_upstream_update(struct pim_instance *pim, struct pim_upstream *up) rpf_result = pim_rpf_update(pim, up, &old_rpf, __func__); if (rpf_result == PIM_RPF_FAILURE) - pim_mroute_del(up->channel_oil, __PRETTY_FUNCTION__); + pim_mroute_del(up->channel_oil, __func__); /* update kernel multicast forwarding cache (MFC) */ if (up->rpf.source_nexthop.interface && up->channel_oil) @@ -550,7 +551,7 @@ int pim_rp_new(struct pim_instance *pim, struct in_addr rp_addr, prefix2str(&rp_all->group, buf1, sizeof(buf1)); zlog_debug( "%s: NHT Register rp_all addr %s grp %s ", - __PRETTY_FUNCTION__, buf, buf1); + __func__, buf, buf1); } frr_each (rb_pim_upstream, &pim->upstream_head, up) { @@ -676,7 +677,7 @@ int pim_rp_new(struct pim_instance *pim, struct in_addr rp_addr, prefix2str(&nht_p, buf, sizeof(buf)); prefix2str(&rp_info->group, buf1, sizeof(buf1)); zlog_debug("%s: NHT Register RP addr %s grp %s with Zebra ", - __PRETTY_FUNCTION__, buf, buf1); + __func__, buf, buf1); } pim_find_or_track_nexthop(pim, &nht_p, NULL, rp_info, false, NULL); if (!pim_ecmp_nexthop_lookup(pim, &rp_info->rp.source_nexthop, &nht_p, @@ -744,8 +745,8 @@ int pim_rp_del(struct pim_instance *pim, struct in_addr rp_addr, } if (PIM_DEBUG_PIM_TRACE) - zlog_debug("%s: Delete RP %s for the group %s", - __PRETTY_FUNCTION__, rp_str, grp_str); + zlog_debug("%s: Delete RP %s for the group %s", __func__, + rp_str, grp_str); /* While static RP is getting deleted, we need to check if dynamic RP * present for the same group in BSM RP table, then install the dynamic @@ -764,9 +765,9 @@ int pim_rp_del(struct pim_instance *pim, struct in_addr rp_addr, sizeof(bsrp_str))) sprintf(bsrp_str, "<bsrp?>"); - zlog_debug("%s: BSM RP %s found for the group %s", - __PRETTY_FUNCTION__, - bsrp_str, grp_str); + zlog_debug( + "%s: BSM RP %s found for the group %s", + __func__, bsrp_str, grp_str); } return pim_rp_change(pim, bsrp->rp_address, group, RP_SRC_BSR); @@ -775,7 +776,7 @@ int pim_rp_del(struct pim_instance *pim, struct in_addr rp_addr, if (PIM_DEBUG_PIM_TRACE) zlog_debug( "%s: BSM RP not found for the group %s", - __PRETTY_FUNCTION__, grp_str); + __func__, grp_str); } } @@ -786,8 +787,8 @@ int pim_rp_del(struct pim_instance *pim, struct in_addr rp_addr, if (PIM_DEBUG_PIM_NHT_RP) { char buf[PREFIX2STR_BUFFER]; prefix2str(&nht_p, buf, sizeof(buf)); - zlog_debug("%s: Deregister RP addr %s with Zebra ", - __PRETTY_FUNCTION__, buf); + zlog_debug("%s: Deregister RP addr %s with Zebra ", __func__, + buf); } pim_delete_tracked_nexthop(pim, &nht_p, NULL, rp_info, false); @@ -836,7 +837,7 @@ int pim_rp_del(struct pim_instance *pim, struct in_addr rp_addr, zlog_debug( "%s:Found for Freeing: %p for rp_info: %p(%s) Lock: %d", - __PRETTY_FUNCTION__, rn, rp_info, + __func__, rn, rp_info, prefix2str(&rp_info->group, buf, sizeof(buf)), rn->lock); @@ -924,7 +925,7 @@ int pim_rp_change(struct pim_instance *pim, struct in_addr new_rp_addr, prefix2str(&nht_p, buf, sizeof(buf)); zlog_debug("%s: Deregister RP addr %s with Zebra ", - __PRETTY_FUNCTION__, buf); + __func__, buf); } pim_delete_tracked_nexthop(pim, &nht_p, NULL, rp_info, false); } @@ -962,7 +963,7 @@ int pim_rp_change(struct pim_instance *pim, struct in_addr new_rp_addr, prefix2str(&nht_p, buf, sizeof(buf)); prefix2str(&rp_info->group, buf1, sizeof(buf1)); zlog_debug("%s: NHT Register RP addr %s grp %s with Zebra ", - __PRETTY_FUNCTION__, buf, buf1); + __func__, buf, buf1); } pim_find_or_track_nexthop(pim, &nht_p, NULL, rp_info, false, NULL); @@ -1146,7 +1147,7 @@ struct pim_rpf *pim_rp_g(struct pim_instance *pim, struct in_addr group) prefix2str(&rp_info->group, buf1, sizeof(buf1)); zlog_debug( "%s: NHT Register RP addr %s grp %s with Zebra", - __PRETTY_FUNCTION__, buf, buf1); + __func__, buf, buf1); } pim_find_or_track_nexthop(pim, &nht_p, NULL, rp_info, false, NULL); @@ -1185,7 +1186,7 @@ int pim_rp_set_upstream_addr(struct pim_instance *pim, struct in_addr *up, && (source.s_addr == INADDR_ANY))) { if (PIM_DEBUG_PIM_NHT_RP) zlog_debug("%s: Received a (*,G) with no RP configured", - __PRETTY_FUNCTION__); + __func__); up->s_addr = INADDR_ANY; return 0; } @@ -1394,8 +1395,7 @@ void pim_resolve_rp_nh(struct pim_instance *pim, struct pim_neighbor *nbr) sizeof(str)); zlog_debug( "%s: addr %s new nexthop addr %s interface %s", - __PRETTY_FUNCTION__, str, str1, - ifp1->name); + __func__, str, str1, ifp1->name); } } } diff --git a/pimd/pim_rpf.c b/pimd/pim_rpf.c index 24519adb1e..010ec7d745 100644 --- a/pimd/pim_rpf.c +++ b/pimd/pim_rpf.c @@ -36,6 +36,7 @@ #include "pim_time.h" #include "pim_nht.h" #include "pim_oil.h" +#include "pim_mlag.h" static struct in_addr pim_rpf_find_rpf_addr(struct pim_upstream *up); @@ -44,7 +45,7 @@ void pim_rpf_set_refresh_time(struct pim_instance *pim) pim->last_route_change_time = pim_time_monotonic_usec(); if (PIM_DEBUG_PIM_TRACE) zlog_debug("%s: vrf(%s) New last route change time: %" PRId64, - __PRETTY_FUNCTION__, pim->vrf->name, + __func__, pim->vrf->name, pim->last_route_change_time); } @@ -77,9 +78,9 @@ bool pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop, pim_addr_dump("<nexthop?>", &nexthop->mrib_nexthop_addr, nexthop_str, sizeof(nexthop_str)); zlog_debug( - "%s: Using last lookup for %s at %lld, %" PRId64 " addr %s", - __PRETTY_FUNCTION__, addr_str, - nexthop->last_lookup_time, + "%s: Using last lookup for %s at %lld, %" PRId64 + " addr %s", + __func__, addr_str, nexthop->last_lookup_time, pim->last_route_change_time, nexthop_str); } pim->nexthop_lookups_avoided++; @@ -91,8 +92,7 @@ bool pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop, sizeof(addr_str)); zlog_debug( "%s: Looking up: %s, last lookup time: %lld, %" PRId64, - __PRETTY_FUNCTION__, addr_str, - nexthop->last_lookup_time, + __func__, addr_str, nexthop->last_lookup_time, pim->last_route_change_time); } } @@ -106,7 +106,7 @@ bool pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop, pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); zlog_warn( "%s %s: could not find nexthop ifindex for address %s", - __FILE__, __PRETTY_FUNCTION__, addr_str); + __FILE__, __func__, addr_str); return false; } @@ -121,8 +121,8 @@ bool pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop, sizeof(addr_str)); zlog_debug( "%s %s: could not find interface for ifindex %d (address %s)", - __FILE__, __PRETTY_FUNCTION__, - first_ifindex, addr_str); + __FILE__, __func__, first_ifindex, + addr_str); } i++; continue; @@ -135,8 +135,8 @@ bool pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop, sizeof(addr_str)); zlog_debug( "%s: multicast not enabled on input interface %s (ifindex=%d, RPF for source %s)", - __PRETTY_FUNCTION__, ifp->name, - first_ifindex, addr_str); + __func__, ifp->name, first_ifindex, + addr_str); } i++; } else if (neighbor_needed @@ -165,8 +165,8 @@ bool pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop, sizeof(addr_str)); zlog_debug( "%s %s: found nexthop %s for address %s: interface %s ifindex=%d metric=%d pref=%d", - __FILE__, __PRETTY_FUNCTION__, nexthop_str, - addr_str, ifp->name, first_ifindex, + __FILE__, __func__, nexthop_str, addr_str, + ifp->name, first_ifindex, nexthop_tab[i].route_metric, nexthop_tab[i].protocol_distance); } @@ -194,6 +194,32 @@ static int nexthop_mismatch(const struct pim_nexthop *nh1, || (nh1->mrib_route_metric != nh2->mrib_route_metric); } +static void pim_rpf_cost_change(struct pim_instance *pim, + struct pim_upstream *up, uint32_t old_cost) +{ + struct pim_rpf *rpf = &up->rpf; + uint32_t new_cost; + + new_cost = pim_up_mlag_local_cost(up); + if (PIM_DEBUG_MLAG) + zlog_debug( + "%s: Cost_to_rp of upstream-%s changed to:%u, from:%u", + __func__, up->sg_str, new_cost, old_cost); + + if (old_cost == new_cost) + return; + + /* Cost changed, it might Impact MLAG DF election, update */ + if (PIM_DEBUG_MLAG) + zlog_debug( + "%s: Cost_to_rp of upstream-%s changed to:%u", + __func__, up->sg_str, + rpf->source_nexthop.mrib_route_metric); + + if (pim_up_mlag_is_local(up)) + pim_mlag_up_local_add(pim, up); +} + enum pim_rpf_result pim_rpf_update(struct pim_instance *pim, struct pim_upstream *up, struct pim_rpf *old, const char *caller) @@ -203,6 +229,7 @@ enum pim_rpf_result pim_rpf_update(struct pim_instance *pim, struct prefix nht_p; struct prefix src, grp; bool neigh_needed = true; + uint32_t saved_mrib_route_metric; if (PIM_UPSTREAM_FLAG_TEST_STATIC_IIF(up->flags)) return PIM_RPF_OK; @@ -215,6 +242,7 @@ enum pim_rpf_result pim_rpf_update(struct pim_instance *pim, saved.source_nexthop = rpf->source_nexthop; saved.rpf_addr = rpf->rpf_addr; + saved_mrib_route_metric = pim_up_mlag_local_cost(up); if (old) { old->source_nexthop = saved.source_nexthop; old->rpf_addr = saved.rpf_addr; @@ -236,8 +264,12 @@ enum pim_rpf_result pim_rpf_update(struct pim_instance *pim, neigh_needed = false; pim_find_or_track_nexthop(pim, &nht_p, up, NULL, false, NULL); if (!pim_ecmp_nexthop_lookup(pim, &rpf->source_nexthop, &src, &grp, - neigh_needed)) + neigh_needed)) { + /* Route is Deleted in Zebra, reset the stored NH data */ + pim_upstream_rpf_clear(pim, up); + pim_rpf_cost_change(pim, up, saved_mrib_route_metric); return PIM_RPF_FAILURE; + } rpf->rpf_addr.family = AF_INET; rpf->rpf_addr.u.prefix4 = pim_rpf_find_rpf_addr(up); @@ -290,10 +322,18 @@ enum pim_rpf_result pim_rpf_update(struct pim_instance *pim, if (saved.rpf_addr.u.prefix4.s_addr != rpf->rpf_addr.u.prefix4.s_addr || saved.source_nexthop .interface != rpf->source_nexthop.interface) { - + pim_rpf_cost_change(pim, up, saved_mrib_route_metric); return PIM_RPF_CHANGED; } + if (PIM_DEBUG_MLAG) + zlog_debug( + "%s(%s): Cost_to_rp of upstream-%s changed to:%u", + __func__, caller, up->sg_str, + rpf->source_nexthop.mrib_route_metric); + + pim_rpf_cost_change(pim, up, saved_mrib_route_metric); + return PIM_RPF_OK; } @@ -342,7 +382,7 @@ static struct in_addr pim_rpf_find_rpf_addr(struct pim_upstream *up) if (!up->rpf.source_nexthop.interface) { zlog_warn("%s: missing RPF interface for upstream (S,G)=%s", - __PRETTY_FUNCTION__, up->sg_str); + __func__, up->sg_str); rpf_addr.s_addr = PIM_NET_INADDR_ANY; return rpf_addr; @@ -374,7 +414,7 @@ int pim_rpf_addr_is_inaddr_none(struct pim_rpf *rpf) case AF_INET: return rpf->rpf_addr.u.prefix4.s_addr == INADDR_NONE; case AF_INET6: - zlog_warn("%s: v6 Unimplmeneted", __PRETTY_FUNCTION__); + zlog_warn("%s: v6 Unimplmeneted", __func__); return 1; default: return 0; @@ -389,7 +429,7 @@ int pim_rpf_addr_is_inaddr_any(struct pim_rpf *rpf) case AF_INET: return rpf->rpf_addr.u.prefix4.s_addr == INADDR_ANY; case AF_INET6: - zlog_warn("%s: v6 Unimplmented", __PRETTY_FUNCTION__); + zlog_warn("%s: v6 Unimplmented", __func__); return 1; default: return 0; diff --git a/pimd/pim_sock.c b/pimd/pim_sock.c index 7f03e18389..ae5781f0cc 100644 --- a/pimd/pim_sock.c +++ b/pimd/pim_sock.c @@ -69,8 +69,7 @@ void pim_socket_ip_hdr(int fd) if (setsockopt(fd, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on))) zlog_err("%s: Could not turn on IP_HDRINCL option: %s", - __PRETTY_FUNCTION__, safe_strerror(errno)); - + __func__, safe_strerror(errno)); } } @@ -153,7 +152,7 @@ int pim_socket_mcast(int protocol, struct in_addr ifaddr, struct interface *ifp, flog_err( EC_LIB_DEVELOPMENT, "%s %s: Missing IP_PKTINFO and IP_RECVDSTADDR: unable to get dst addr from recvmsg()", - __FILE__, __PRETTY_FUNCTION__); + __FILE__, __func__); close(fd); return PIM_SOCK_ERR_DSTADDR; #endif @@ -231,8 +230,8 @@ int pim_socket_mcast(int protocol, struct in_addr ifaddr, struct interface *ifp, } if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(rcvbuf))) - zlog_warn("%s: Failure to set buffer size to %d", - __PRETTY_FUNCTION__, rcvbuf); + zlog_warn("%s: Failure to set buffer size to %d", __func__, + rcvbuf); { long flags; diff --git a/pimd/pim_ssm.c b/pimd/pim_ssm.c index 6a70a73b45..8d3e04f5da 100644 --- a/pimd/pim_ssm.c +++ b/pimd/pim_ssm.c @@ -75,7 +75,7 @@ static int pim_is_grp_standard_ssm(struct prefix *group) if (!str2prefix(PIM_SSM_STANDARD_RANGE, &group_ssm)) flog_err(EC_LIB_DEVELOPMENT, "%s: Failure to Read Group Address: %s", - __PRETTY_FUNCTION__, PIM_SSM_STANDARD_RANGE); + __func__, PIM_SSM_STANDARD_RANGE); first = 0; } diff --git a/pimd/pim_ssmpingd.c b/pimd/pim_ssmpingd.c index 17bc375c12..f4d3547b3f 100644 --- a/pimd/pim_ssmpingd.c +++ b/pimd/pim_ssmpingd.c @@ -85,7 +85,7 @@ static int ssmpingd_socket(struct in_addr addr, int port, int mttl) if (fd < 0) { flog_err_sys(EC_LIB_SOCKET, "%s: could not create socket: errno=%d: %s", - __PRETTY_FUNCTION__, errno, safe_strerror(errno)); + __func__, errno, safe_strerror(errno)); return -1; } @@ -98,8 +98,8 @@ static int ssmpingd_socket(struct in_addr addr, int port, int mttl) pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); zlog_warn( "%s: bind(fd=%d,addr=%s,port=%d,len=%zu) failure: errno=%d: %s", - __PRETTY_FUNCTION__, fd, addr_str, port, - sizeof(sockaddr), errno, safe_strerror(errno)); + __func__, fd, addr_str, port, sizeof(sockaddr), errno, + safe_strerror(errno)); close(fd); return -1; } @@ -112,8 +112,7 @@ static int ssmpingd_socket(struct in_addr addr, int port, int mttl) if (setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &opt, sizeof(opt))) { zlog_warn( "%s: could not set IP_PKTINFO on socket fd=%d: errno=%d: %s", - __PRETTY_FUNCTION__, fd, errno, - safe_strerror(errno)); + __func__, fd, errno, safe_strerror(errno)); } #elif defined(HAVE_IP_RECVDSTADDR) /* BSD IP_RECVDSTADDR */ @@ -122,14 +121,13 @@ static int ssmpingd_socket(struct in_addr addr, int port, int mttl) sizeof(opt))) { zlog_warn( "%s: could not set IP_RECVDSTADDR on socket fd=%d: errno=%d: %s", - __PRETTY_FUNCTION__, fd, errno, - safe_strerror(errno)); + __func__, fd, errno, safe_strerror(errno)); } #else flog_err( EC_LIB_DEVELOPMENT, "%s %s: missing IP_PKTINFO and IP_RECVDSTADDR: unable to get dst addr from recvmsg()", - __FILE__, __PRETTY_FUNCTION__); + __FILE__, __func__); close(fd); return -1; #endif @@ -141,8 +139,7 @@ static int ssmpingd_socket(struct in_addr addr, int port, int mttl) sizeof(reuse))) { zlog_warn( "%s: could not set Reuse Address Option on socket fd=%d: errno=%d: %s", - __PRETTY_FUNCTION__, fd, errno, - safe_strerror(errno)); + __func__, fd, errno, safe_strerror(errno)); close(fd); return -1; } @@ -152,8 +149,7 @@ static int ssmpingd_socket(struct in_addr addr, int port, int mttl) sizeof(mttl))) { zlog_warn( "%s: could not set multicast TTL=%d on socket fd=%d: errno=%d: %s", - __PRETTY_FUNCTION__, mttl, fd, errno, - safe_strerror(errno)); + __func__, mttl, fd, errno, safe_strerror(errno)); close(fd); return -1; } @@ -161,7 +157,7 @@ static int ssmpingd_socket(struct in_addr addr, int port, int mttl) if (setsockopt_ipv4_multicast_loop(fd, 0)) { zlog_warn( "%s: could not disable Multicast Loopback Option on socket fd=%d: errno=%d: %s", - __PRETTY_FUNCTION__, fd, errno, safe_strerror(errno)); + __func__, fd, errno, safe_strerror(errno)); close(fd); return PIM_SOCK_ERR_LOOP; } @@ -170,7 +166,7 @@ static int ssmpingd_socket(struct in_addr addr, int port, int mttl) sizeof(addr))) { zlog_warn( "%s: could not set Outgoing Interface Option on socket fd=%d: errno=%d: %s", - __PRETTY_FUNCTION__, fd, errno, safe_strerror(errno)); + __func__, fd, errno, safe_strerror(errno)); close(fd); return -1; } @@ -182,8 +178,7 @@ static int ssmpingd_socket(struct in_addr addr, int port, int mttl) if (flags < 0) { zlog_warn( "%s: could not get fcntl(F_GETFL,O_NONBLOCK) on socket fd=%d: errno=%d: %s", - __PRETTY_FUNCTION__, fd, errno, - safe_strerror(errno)); + __func__, fd, errno, safe_strerror(errno)); close(fd); return -1; } @@ -191,8 +186,7 @@ static int ssmpingd_socket(struct in_addr addr, int port, int mttl) if (fcntl(fd, F_SETFL, flags | O_NONBLOCK)) { zlog_warn( "%s: could not set fcntl(F_SETFL,O_NONBLOCK) on socket fd=%d: errno=%d: %s", - __PRETTY_FUNCTION__, fd, errno, - safe_strerror(errno)); + __func__, fd, errno, safe_strerror(errno)); close(fd); return -1; } @@ -213,7 +207,7 @@ static void ssmpingd_delete(struct ssmpingd_sock *ss) sizeof(source_str)); zlog_warn( "%s: failure closing ssmpingd sock_fd=%d for source %s: errno=%d: %s", - __PRETTY_FUNCTION__, ss->sock_fd, source_str, errno, + __func__, ss->sock_fd, source_str, errno, safe_strerror(errno)); /* warning only */ } @@ -236,12 +230,12 @@ static void ssmpingd_sendto(struct ssmpingd_sock *ss, const uint8_t *buf, if (sent < 0) { zlog_warn( "%s: sendto() failure to %s,%d: fd=%d len=%d: errno=%d: %s", - __PRETTY_FUNCTION__, to_str, ntohs(to.sin_port), + __func__, to_str, ntohs(to.sin_port), ss->sock_fd, len, errno, safe_strerror(errno)); } else { zlog_warn( "%s: sendto() partial to %s,%d: fd=%d len=%d: sent=%d", - __PRETTY_FUNCTION__, to_str, ntohs(to.sin_port), + __func__, to_str, ntohs(to.sin_port), ss->sock_fd, len, sent); } } @@ -268,7 +262,7 @@ static int ssmpingd_read_msg(struct ssmpingd_sock *ss) sizeof(source_str)); zlog_warn( "%s: failure receiving ssmping for source %s on fd=%d: errno=%d: %s", - __PRETTY_FUNCTION__, source_str, ss->sock_fd, errno, + __func__, source_str, ss->sock_fd, errno, safe_strerror(errno)); return -1; } @@ -286,8 +280,8 @@ static int ssmpingd_read_msg(struct ssmpingd_sock *ss) pim_inet4_dump("<to?>", to.sin_addr, to_str, sizeof(to_str)); zlog_warn( "%s: bad ssmping type=%d from %s,%d to %s,%d on interface %s ifindex=%d fd=%d src=%s", - __PRETTY_FUNCTION__, buf[0], from_str, - ntohs(from.sin_port), to_str, ntohs(to.sin_port), + __func__, buf[0], from_str, ntohs(from.sin_port), + to_str, ntohs(to.sin_port), ifp ? ifp->name : "<iface?>", ifindex, ss->sock_fd, source_str); return 0; @@ -304,10 +298,9 @@ static int ssmpingd_read_msg(struct ssmpingd_sock *ss) pim_inet4_dump("<to?>", to.sin_addr, to_str, sizeof(to_str)); zlog_debug( "%s: recv ssmping from %s,%d to %s,%d on interface %s ifindex=%d fd=%d src=%s", - __PRETTY_FUNCTION__, from_str, ntohs(from.sin_port), - to_str, ntohs(to.sin_port), - ifp ? ifp->name : "<iface?>", ifindex, ss->sock_fd, - source_str); + __func__, from_str, ntohs(from.sin_port), to_str, + ntohs(to.sin_port), ifp ? ifp->name : "<iface?>", + ifindex, ss->sock_fd, source_str); } buf[0] = PIM_SSMPINGD_REPLY; @@ -361,7 +354,7 @@ static struct ssmpingd_sock *ssmpingd_new(struct pim_instance *pim, pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str)); zlog_warn("%s: ssmpingd_socket() failure for source %s", - __PRETTY_FUNCTION__, source_str); + __func__, source_str); return 0; } @@ -395,8 +388,8 @@ int pim_ssmpingd_start(struct pim_instance *pim, struct in_addr source_addr) char source_str[INET_ADDRSTRLEN]; pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str)); - zlog_info("%s: starting ssmpingd for source %s", - __PRETTY_FUNCTION__, source_str); + zlog_info("%s: starting ssmpingd for source %s", __func__, + source_str); } ss = ssmpingd_new(pim, source_addr); @@ -404,8 +397,8 @@ int pim_ssmpingd_start(struct pim_instance *pim, struct in_addr source_addr) char source_str[INET_ADDRSTRLEN]; pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str)); - zlog_warn("%s: ssmpingd_new() failure for source %s", - __PRETTY_FUNCTION__, source_str); + zlog_warn("%s: ssmpingd_new() failure for source %s", __func__, + source_str); return -1; } @@ -421,8 +414,8 @@ int pim_ssmpingd_stop(struct pim_instance *pim, struct in_addr source_addr) char source_str[INET_ADDRSTRLEN]; pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str)); - zlog_warn("%s: could not find ssmpingd for source %s", - __PRETTY_FUNCTION__, source_str); + zlog_warn("%s: could not find ssmpingd for source %s", __func__, + source_str); return -1; } @@ -430,8 +423,8 @@ int pim_ssmpingd_stop(struct pim_instance *pim, struct in_addr source_addr) char source_str[INET_ADDRSTRLEN]; pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str)); - zlog_info("%s: stopping ssmpingd for source %s", - __PRETTY_FUNCTION__, source_str); + zlog_info("%s: stopping ssmpingd for source %s", __func__, + source_str); } ssmpingd_delete(ss); diff --git a/pimd/pim_static.c b/pimd/pim_static.c index 7b121c9136..91c9b5b933 100644 --- a/pimd/pim_static.c +++ b/pimd/pim_static.c @@ -79,7 +79,7 @@ int pim_static_add(struct pim_instance *pim, struct interface *iif, if (!iif_index || !oif_index || iif_index == -1 || oif_index == -1) { zlog_warn( "%s %s: Unable to add static route: Invalid interface index(iif=%d,oif=%d)", - __FILE__, __PRETTY_FUNCTION__, iif_index, oif_index); + __FILE__, __func__, iif_index, oif_index); return -2; } @@ -88,7 +88,7 @@ int pim_static_add(struct pim_instance *pim, struct interface *iif, /* looped MFC entry */ zlog_warn( "%s %s: Unable to add static route: Looped MFC entry(iif=%d,oif=%d)", - __FILE__, __PRETTY_FUNCTION__, iif_index, oif_index); + __FILE__, __func__, iif_index, oif_index); return -4; } #endif @@ -109,9 +109,8 @@ int pim_static_add(struct pim_instance *pim, struct interface *iif, sizeof(sifaddr_str)); zlog_warn( "%s %s: Unable to add static route: Route already exists (iif=%d,oif=%d,group=%s,source=%s)", - __FILE__, __PRETTY_FUNCTION__, - iif_index, oif_index, gifaddr_str, - sifaddr_str); + __FILE__, __func__, iif_index, + oif_index, gifaddr_str, sifaddr_str); return -3; } @@ -138,9 +137,8 @@ int pim_static_add(struct pim_instance *pim, struct interface *iif, } else { /* input interface changed */ s_route->iif = iif_index; - pim_static_mroute_iif_update(&s_route->c_oil, - iif_index, - __PRETTY_FUNCTION__); + pim_static_mroute_iif_update( + &s_route->c_oil, iif_index, __func__); #ifdef PIM_ENFORCE_LOOPFREE_MFC /* check to make sure the new input was not an @@ -179,7 +177,7 @@ int pim_static_add(struct pim_instance *pim, struct interface *iif, s_route->c_oil.pim = pim; - if (pim_static_mroute_add(&s_route->c_oil, __PRETTY_FUNCTION__)) { + if (pim_static_mroute_add(&s_route->c_oil, __func__)) { char gifaddr_str[INET_ADDRSTRLEN]; char sifaddr_str[INET_ADDRSTRLEN]; pim_inet4_dump("<ifaddr?>", group, gifaddr_str, @@ -188,8 +186,8 @@ int pim_static_add(struct pim_instance *pim, struct interface *iif, sizeof(sifaddr_str)); zlog_warn( "%s %s: Unable to add static route(iif=%d,oif=%d,group=%s,source=%s)", - __FILE__, __PRETTY_FUNCTION__, iif_index, oif_index, - gifaddr_str, sifaddr_str); + __FILE__, __func__, iif_index, oif_index, gifaddr_str, + sifaddr_str); /* Need to put s_route back to the way it was */ if (original_s_route) { @@ -223,7 +221,7 @@ int pim_static_add(struct pim_instance *pim, struct interface *iif, sizeof(sifaddr_str)); zlog_debug( "%s: Static route added(iif=%d,oif=%d,group=%s,source=%s)", - __PRETTY_FUNCTION__, iif_index, oif_index, gifaddr_str, + __func__, iif_index, oif_index, gifaddr_str, sifaddr_str); } @@ -245,7 +243,7 @@ int pim_static_del(struct pim_instance *pim, struct interface *iif, if (!iif_index || !oif_index) { zlog_warn( "%s %s: Unable to remove static route: Invalid interface index(iif=%d,oif=%d)", - __FILE__, __PRETTY_FUNCTION__, iif_index, oif_index); + __FILE__, __func__, iif_index, oif_index); return -2; } @@ -262,10 +260,9 @@ int pim_static_del(struct pim_instance *pim, struct interface *iif, * route, otherwise set the route with the new outputs */ if (s_route->c_oil.oil_ref_count <= 0 - ? pim_mroute_del(&s_route->c_oil, - __PRETTY_FUNCTION__) + ? pim_mroute_del(&s_route->c_oil, __func__) : pim_static_mroute_add(&s_route->c_oil, - __PRETTY_FUNCTION__)) { + __func__)) { char gifaddr_str[INET_ADDRSTRLEN]; char sifaddr_str[INET_ADDRSTRLEN]; pim_inet4_dump("<ifaddr?>", group, gifaddr_str, @@ -274,9 +271,8 @@ int pim_static_del(struct pim_instance *pim, struct interface *iif, sizeof(sifaddr_str)); zlog_warn( "%s %s: Unable to remove static route(iif=%d,oif=%d,group=%s,source=%s)", - __FILE__, __PRETTY_FUNCTION__, - iif_index, oif_index, gifaddr_str, - sifaddr_str); + __FILE__, __func__, iif_index, + oif_index, gifaddr_str, sifaddr_str); s_route->oif_ttls[oif_index] = 1; s_route->c_oil.oil.mfcc_ttls[oif_index] = 1; @@ -301,8 +297,8 @@ int pim_static_del(struct pim_instance *pim, struct interface *iif, sizeof(sifaddr_str)); zlog_debug( "%s: Static route removed(iif=%d,oif=%d,group=%s,source=%s)", - __PRETTY_FUNCTION__, iif_index, - oif_index, gifaddr_str, sifaddr_str); + __func__, iif_index, oif_index, + gifaddr_str, sifaddr_str); } break; @@ -318,8 +314,8 @@ int pim_static_del(struct pim_instance *pim, struct interface *iif, sizeof(sifaddr_str)); zlog_warn( "%s %s: Unable to remove static route: Route does not exist(iif=%d,oif=%d,group=%s,source=%s)", - __FILE__, __PRETTY_FUNCTION__, iif_index, oif_index, - gifaddr_str, sifaddr_str); + __FILE__, __func__, iif_index, oif_index, gifaddr_str, + sifaddr_str); return -3; } diff --git a/pimd/pim_time.c b/pimd/pim_time.c index f12f767537..9878fcf6b4 100644 --- a/pimd/pim_time.c +++ b/pimd/pim_time.c @@ -37,7 +37,7 @@ static int gettime_monotonic(struct timeval *tv) if (result) { flog_err_sys(EC_LIB_SYSTEM_CALL, "%s: gettimeofday() failure: errno=%d: %s", - __PRETTY_FUNCTION__, errno, safe_strerror(errno)); + __func__, errno, safe_strerror(errno)); } return result; @@ -54,7 +54,7 @@ int64_t pim_time_monotonic_sec(void) if (gettime_monotonic(&now_tv)) { flog_err_sys(EC_LIB_SYSTEM_CALL, "%s: gettime_monotonic() failure: errno=%d: %s", - __PRETTY_FUNCTION__, errno, safe_strerror(errno)); + __func__, errno, safe_strerror(errno)); return -1; } @@ -73,7 +73,7 @@ int64_t pim_time_monotonic_dsec(void) if (gettime_monotonic(&now_tv)) { flog_err_sys(EC_LIB_SYSTEM_CALL, "%s: gettime_monotonic() failure: errno=%d: %s", - __PRETTY_FUNCTION__, errno, safe_strerror(errno)); + __func__, errno, safe_strerror(errno)); return -1; } @@ -91,7 +91,7 @@ int64_t pim_time_monotonic_usec(void) if (gettime_monotonic(&now_tv)) { flog_err_sys(EC_LIB_SYSTEM_CALL, "%s: gettime_monotonic() failure: errno=%d: %s", - __PRETTY_FUNCTION__, errno, safe_strerror(errno)); + __func__, errno, safe_strerror(errno)); return -1; } diff --git a/pimd/pim_tlv.c b/pimd/pim_tlv.c index 5faa499276..5a751ac929 100644 --- a/pimd/pim_tlv.c +++ b/pimd/pim_tlv.c @@ -143,7 +143,7 @@ int pim_encode_addr_ucast(uint8_t *buf, struct prefix *p) } } -#define group_ipv4_encoding_len (4 + sizeof (struct in_addr)) +#define group_ipv4_encoding_len (4 + sizeof(struct in_addr)) /* * Encoded-Group addresses take the following format: @@ -257,7 +257,7 @@ uint8_t *pim_tlv_append_addrlist_ucast(uint8_t *buf, const uint8_t *buf_pastend, if (PIM_DEBUG_PIM_TRACE_DETAIL) { zlog_debug( "%s: number of encoded secondary unicast IPv4 addresses: %zu", - __PRETTY_FUNCTION__, option_len / uel); + __func__, option_len / uel); } if (option_len < 1) { @@ -340,15 +340,15 @@ int pim_tlv_parse_holdtime(const char *ifname, struct in_addr src_addr, { const char *label = "holdtime"; - if (check_tlv_length(__PRETTY_FUNCTION__, label, ifname, src_addr, + if (check_tlv_length(__func__, label, ifname, src_addr, sizeof(uint16_t), option_len)) { return -1; } - check_tlv_redefinition_uint16( - __PRETTY_FUNCTION__, label, ifname, src_addr, *hello_options, - PIM_OPTION_MASK_HOLDTIME, PIM_TLV_GET_HOLDTIME(tlv_curr), - *hello_option_holdtime); + check_tlv_redefinition_uint16(__func__, label, ifname, src_addr, + *hello_options, PIM_OPTION_MASK_HOLDTIME, + PIM_TLV_GET_HOLDTIME(tlv_curr), + *hello_option_holdtime); PIM_OPTION_SET(*hello_options, PIM_OPTION_MASK_HOLDTIME); @@ -363,13 +363,13 @@ int pim_tlv_parse_lan_prune_delay(const char *ifname, struct in_addr src_addr, uint16_t *hello_option_override_interval, uint16_t option_len, const uint8_t *tlv_curr) { - if (check_tlv_length(__PRETTY_FUNCTION__, "lan_prune_delay", ifname, - src_addr, sizeof(uint32_t), option_len)) { + if (check_tlv_length(__func__, "lan_prune_delay", ifname, src_addr, + sizeof(uint32_t), option_len)) { return -1; } - check_tlv_redefinition_uint16(__PRETTY_FUNCTION__, "propagation_delay", - ifname, src_addr, *hello_options, + check_tlv_redefinition_uint16(__func__, "propagation_delay", ifname, + src_addr, *hello_options, PIM_OPTION_MASK_LAN_PRUNE_DELAY, PIM_TLV_GET_PROPAGATION_DELAY(tlv_curr), *hello_option_propagation_delay); @@ -400,13 +400,13 @@ int pim_tlv_parse_dr_priority(const char *ifname, struct in_addr src_addr, { const char *label = "dr_priority"; - if (check_tlv_length(__PRETTY_FUNCTION__, label, ifname, src_addr, + if (check_tlv_length(__func__, label, ifname, src_addr, sizeof(uint32_t), option_len)) { return -1; } check_tlv_redefinition_uint32( - __PRETTY_FUNCTION__, label, ifname, src_addr, *hello_options, + __func__, label, ifname, src_addr, *hello_options, PIM_OPTION_MASK_DR_PRIORITY, PIM_TLV_GET_DR_PRIORITY(tlv_curr), *hello_option_dr_priority); @@ -424,13 +424,13 @@ int pim_tlv_parse_generation_id(const char *ifname, struct in_addr src_addr, { const char *label = "generation_id"; - if (check_tlv_length(__PRETTY_FUNCTION__, label, ifname, src_addr, + if (check_tlv_length(__func__, label, ifname, src_addr, sizeof(uint32_t), option_len)) { return -1; } - check_tlv_redefinition_uint32_hex(__PRETTY_FUNCTION__, label, ifname, - src_addr, *hello_options, + check_tlv_redefinition_uint32_hex(__func__, label, ifname, src_addr, + *hello_options, PIM_OPTION_MASK_GENERATION_ID, PIM_TLV_GET_GENERATION_ID(tlv_curr), *hello_option_generation_id); @@ -453,7 +453,7 @@ int pim_parse_addr_ucast(struct prefix *p, const uint8_t *buf, int buf_size) if (buf_size < ucast_encoding_min_len) { zlog_warn( "%s: unicast address encoding overflow: left=%d needed=%d", - __PRETTY_FUNCTION__, buf_size, ucast_encoding_min_len); + __func__, buf_size, ucast_encoding_min_len); return -1; } @@ -465,7 +465,7 @@ int pim_parse_addr_ucast(struct prefix *p, const uint8_t *buf, int buf_size) if (type) { zlog_warn("%s: unknown unicast address encoding type=%d", - __PRETTY_FUNCTION__, type); + __func__, type); return -2; } @@ -474,7 +474,7 @@ int pim_parse_addr_ucast(struct prefix *p, const uint8_t *buf, int buf_size) if ((addr + sizeof(struct in_addr)) > pastend) { zlog_warn( "%s: IPv4 unicast address overflow: left=%zd needed=%zu", - __PRETTY_FUNCTION__, pastend - addr, + __func__, pastend - addr, sizeof(struct in_addr)); return -3; } @@ -490,7 +490,7 @@ int pim_parse_addr_ucast(struct prefix *p, const uint8_t *buf, int buf_size) if ((addr + sizeof(struct in6_addr)) > pastend) { zlog_warn( "%s: IPv6 unicast address overflow: left=%zd needed %zu", - __PRETTY_FUNCTION__, pastend - addr, + __func__, pastend - addr, sizeof(struct in6_addr)); return -3; } @@ -503,7 +503,7 @@ int pim_parse_addr_ucast(struct prefix *p, const uint8_t *buf, int buf_size) break; default: { zlog_warn("%s: unknown unicast address encoding family=%d from", - __PRETTY_FUNCTION__, family); + __func__, family); return -4; } } @@ -524,7 +524,7 @@ int pim_parse_addr_group(struct prefix_sg *sg, const uint8_t *buf, int buf_size) if (buf_size < grp_encoding_min_len) { zlog_warn( "%s: group address encoding overflow: left=%d needed=%d", - __PRETTY_FUNCTION__, buf_size, grp_encoding_min_len); + __func__, buf_size, grp_encoding_min_len); return -1; } @@ -542,14 +542,14 @@ int pim_parse_addr_group(struct prefix_sg *sg, const uint8_t *buf, int buf_size) if (type) { zlog_warn( "%s: unknown group address encoding type=%d from", - __PRETTY_FUNCTION__, type); + __func__, type); return -2; } if ((addr + sizeof(struct in_addr)) > pastend) { zlog_warn( "%s: IPv4 group address overflow: left=%zd needed=%zu from", - __PRETTY_FUNCTION__, pastend - addr, + __func__, pastend - addr, sizeof(struct in_addr)); return -3; } @@ -562,7 +562,7 @@ int pim_parse_addr_group(struct prefix_sg *sg, const uint8_t *buf, int buf_size) default: { zlog_warn( "%s: unknown group address encoding family=%d mask_len=%d from", - __PRETTY_FUNCTION__, family, mask_len); + __func__, family, mask_len); return -4; } } @@ -584,7 +584,7 @@ int pim_parse_addr_source(struct prefix_sg *sg, uint8_t *flags, if (buf_size < src_encoding_min_len) { zlog_warn( "%s: source address encoding overflow: left=%d needed=%d", - __PRETTY_FUNCTION__, buf_size, src_encoding_min_len); + __func__, buf_size, src_encoding_min_len); return -1; } @@ -599,8 +599,7 @@ int pim_parse_addr_source(struct prefix_sg *sg, uint8_t *flags, if (type) { zlog_warn( "%s: unknown source address encoding type=%d: %02x%02x%02x%02x", - __PRETTY_FUNCTION__, type, buf[0], buf[1], buf[2], - buf[3]); + __func__, type, buf[0], buf[1], buf[2], buf[3]); return -2; } @@ -609,7 +608,7 @@ int pim_parse_addr_source(struct prefix_sg *sg, uint8_t *flags, if ((addr + sizeof(struct in_addr)) > pastend) { zlog_warn( "%s: IPv4 source address overflow: left=%zd needed=%zu", - __PRETTY_FUNCTION__, pastend - addr, + __func__, pastend - addr, sizeof(struct in_addr)); return -3; } @@ -630,7 +629,7 @@ int pim_parse_addr_source(struct prefix_sg *sg, uint8_t *flags, */ if (mask_len != 32) { zlog_warn("%s: IPv4 bad source address mask: %d", - __PRETTY_FUNCTION__, mask_len); + __func__, mask_len); return -4; } @@ -640,8 +639,7 @@ int pim_parse_addr_source(struct prefix_sg *sg, uint8_t *flags, default: { zlog_warn( "%s: unknown source address encoding family=%d: %02x%02x%02x%02x", - __PRETTY_FUNCTION__, family, buf[0], buf[1], buf[2], - buf[3]); + __func__, family, buf[0], buf[1], buf[2], buf[3]); return -5; } } @@ -686,7 +684,7 @@ int pim_tlv_parse_addr_list(const char *ifname, struct in_addr src_addr, sizeof(src_str)); zlog_warn( "%s: pim_parse_addr_ucast() failure: from %s on %s", - __PRETTY_FUNCTION__, src_str, ifname); + __func__, src_str, ifname); FREE_ADDR_LIST(*hello_option_addr_list); return -1; } @@ -706,10 +704,10 @@ int pim_tlv_parse_addr_list(const char *ifname, struct in_addr src_addr, sizeof(src_str)); zlog_debug( "%s: PIM hello TLV option: list_old_size=%d IPv4 address %s from %s on %s", - __PRETTY_FUNCTION__, + __func__, *hello_option_addr_list ? ((int)listcount( - *hello_option_addr_list)) + *hello_option_addr_list)) : -1, addr_str, src_str, ifname); } break; @@ -721,10 +719,10 @@ int pim_tlv_parse_addr_list(const char *ifname, struct in_addr src_addr, sizeof(src_str)); zlog_debug( "%s: PIM hello TLV option: list_old_size=%d UNKNOWN address family from %s on %s", - __PRETTY_FUNCTION__, + __func__, *hello_option_addr_list ? ((int)listcount( - *hello_option_addr_list)) + *hello_option_addr_list)) : -1, src_str, ifname); } @@ -742,7 +740,7 @@ int pim_tlv_parse_addr_list(const char *ifname, struct in_addr src_addr, sizeof(src_str)); zlog_warn( "%s: ignoring primary address in secondary list from %s on %s", - __PRETTY_FUNCTION__, src_str, ifname); + __func__, src_str, ifname); continue; } } diff --git a/pimd/pim_upstream.c b/pimd/pim_upstream.c index c899e403c8..efa58c1b1f 100644 --- a/pimd/pim_upstream.c +++ b/pimd/pim_upstream.c @@ -52,10 +52,12 @@ #include "pim_nht.h" #include "pim_ssm.h" #include "pim_vxlan.h" +#include "pim_mlag.h" static void join_timer_stop(struct pim_upstream *up); static void pim_upstream_update_assert_tracking_desired(struct pim_upstream *up); +static bool pim_upstream_sg_running_proc(struct pim_upstream *up); /* * A (*,G) or a (*,*) is going away @@ -75,8 +77,7 @@ static void pim_upstream_remove_children(struct pim_instance *pim, listnode_delete(up->sources, child); if (PIM_UPSTREAM_FLAG_TEST_SRC_LHR(child->flags)) { PIM_UPSTREAM_FLAG_UNSET_SRC_LHR(child->flags); - child = pim_upstream_del(pim, child, - __PRETTY_FUNCTION__); + child = pim_upstream_del(pim, child, __func__); } if (child) { child->parent = NULL; @@ -141,6 +142,18 @@ static struct pim_upstream *pim_upstream_find_parent(struct pim_instance *pim, if (up) listnode_add(up->sources, child); + /* + * In case parent is MLAG entry copy the data to child + */ + if (up && PIM_UPSTREAM_FLAG_TEST_MLAG_INTERFACE(up->flags)) { + PIM_UPSTREAM_FLAG_SET_MLAG_INTERFACE(child->flags); + if (PIM_UPSTREAM_FLAG_TEST_MLAG_NON_DF(up->flags)) + PIM_UPSTREAM_FLAG_SET_MLAG_NON_DF(child->flags); + else + PIM_UPSTREAM_FLAG_UNSET_MLAG_NON_DF( + child->flags); + } + return up; } @@ -178,7 +191,7 @@ struct pim_upstream *pim_upstream_del(struct pim_instance *pim, if (PIM_DEBUG_PIM_TRACE) zlog_debug( "%s(%s): Delete %s[%s] ref count: %d , flags: %d c_oil ref count %d (Pre decrement)", - __PRETTY_FUNCTION__, name, up->sg_str, pim->vrf->name, + __func__, name, up->sg_str, pim->vrf->name, up->ref_count, up->flags, up->channel_oil->oil_ref_count); @@ -193,6 +206,9 @@ struct pim_upstream *pim_upstream_del(struct pim_instance *pim, zlog_debug("pim_upstream free vrf:%s %s flags 0x%x", pim->vrf->name, up->sg_str, up->flags); + if (pim_up_mlag_is_local(up)) + pim_mlag_up_local_del(pim, up); + THREAD_OFF(up->t_ka_timer); THREAD_OFF(up->t_rs_timer); THREAD_OFF(up->t_msdp_reg_timer); @@ -218,7 +234,7 @@ struct pim_upstream *pim_upstream_del(struct pim_instance *pim, notify_msdp = true; } - pim_mroute_del(up->channel_oil, __PRETTY_FUNCTION__); + pim_mroute_del(up->channel_oil, __func__); upstream_channel_oil_detach(up); for (ALL_LIST_ELEMENTS(up->ifchannels, node, nnode, ch)) @@ -253,8 +269,9 @@ struct pim_upstream *pim_upstream_del(struct pim_instance *pim, if (PIM_DEBUG_PIM_TRACE) { char buf[PREFIX2STR_BUFFER]; prefix2str(&nht_p, buf, sizeof(buf)); - zlog_debug("%s: Deregister upstream %s addr %s with Zebra NHT", - __PRETTY_FUNCTION__, up->sg_str, buf); + zlog_debug( + "%s: Deregister upstream %s addr %s with Zebra NHT", + __func__, up->sg_str, buf); } pim_delete_tracked_nexthop(pim, &nht_p, up, NULL, false); } @@ -268,8 +285,8 @@ void pim_upstream_send_join(struct pim_upstream *up) { if (!up->rpf.source_nexthop.interface) { if (PIM_DEBUG_PIM_TRACE) - zlog_debug("%s: up %s RPF is not present", - __PRETTY_FUNCTION__, up->sg_str); + zlog_debug("%s: up %s RPF is not present", __func__, + up->sg_str); return; } @@ -277,13 +294,13 @@ void pim_upstream_send_join(struct pim_upstream *up) char rpf_str[PREFIX_STRLEN]; pim_addr_dump("<rpf?>", &up->rpf.rpf_addr, rpf_str, sizeof(rpf_str)); - zlog_debug("%s: RPF'%s=%s(%s) for Interface %s", - __PRETTY_FUNCTION__, up->sg_str, rpf_str, + zlog_debug("%s: RPF'%s=%s(%s) for Interface %s", __func__, + up->sg_str, rpf_str, pim_upstream_state2str(up->join_state), up->rpf.source_nexthop.interface->name); if (pim_rpf_addr_is_inaddr_any(&up->rpf)) { zlog_debug("%s: can't send join upstream: RPF'%s=%s", - __PRETTY_FUNCTION__, up->sg_str, rpf_str); + __func__, up->sg_str, rpf_str); /* warning only */ } } @@ -300,8 +317,8 @@ static int on_join_timer(struct thread *t) if (!up->rpf.source_nexthop.interface) { if (PIM_DEBUG_PIM_TRACE) - zlog_debug("%s: up %s RPF is not present", - __PRETTY_FUNCTION__, up->sg_str); + zlog_debug("%s: up %s RPF is not present", __func__, + up->sg_str); return 0; } @@ -351,8 +368,7 @@ void join_timer_start(struct pim_upstream *up) if (PIM_DEBUG_PIM_EVENTS) { zlog_debug( "%s: starting %d sec timer for upstream (S,G)=%s", - __PRETTY_FUNCTION__, router->t_periodic, - up->sg_str); + __func__, router->t_periodic, up->sg_str); } } @@ -385,7 +401,7 @@ static void pim_upstream_join_timer_restart_msec(struct pim_upstream *up, { if (PIM_DEBUG_PIM_EVENTS) { zlog_debug("%s: restarting %d msec timer for upstream (S,G)=%s", - __PRETTY_FUNCTION__, interval_msec, up->sg_str); + __func__, interval_msec, up->sg_str); } THREAD_OFF(up->t_join_timer); @@ -401,8 +417,8 @@ void pim_upstream_join_suppress(struct pim_upstream *up, if (!up->rpf.source_nexthop.interface) { if (PIM_DEBUG_PIM_TRACE) - zlog_debug("%s: up %s RPF is not present", - __PRETTY_FUNCTION__, up->sg_str); + zlog_debug("%s: up %s RPF is not present", __func__, + up->sg_str); return; } @@ -417,7 +433,7 @@ void pim_upstream_join_suppress(struct pim_upstream *up, pim_inet4_dump("<rpf?>", rpf_addr, rpf_str, sizeof(rpf_str)); zlog_debug( "%s %s: detected Join%s to RPF'(S,G)=%s: join_timer=%ld msec t_joinsuppress=%ld msec", - __FILE__, __PRETTY_FUNCTION__, up->sg_str, rpf_str, + __FILE__, __func__, up->sg_str, rpf_str, join_timer_remain_msec, t_joinsuppress_msec); } @@ -425,7 +441,7 @@ void pim_upstream_join_suppress(struct pim_upstream *up, if (PIM_DEBUG_PIM_TRACE) { zlog_debug( "%s %s: suppressing Join(S,G)=%s for %ld msec", - __FILE__, __PRETTY_FUNCTION__, up->sg_str, + __FILE__, __func__, up->sg_str, t_joinsuppress_msec); } @@ -441,8 +457,8 @@ void pim_upstream_join_timer_decrease_to_t_override(const char *debug_label, if (!up->rpf.source_nexthop.interface) { if (PIM_DEBUG_PIM_TRACE) - zlog_debug("%s: up %s RPF is not present", - __PRETTY_FUNCTION__, up->sg_str); + zlog_debug("%s: up %s RPF is not present", __func__, + up->sg_str); return; } @@ -514,8 +530,8 @@ static int pim_upstream_could_register(struct pim_upstream *up) pim_ifp = up->rpf.source_nexthop.interface->info; else { if (PIM_DEBUG_PIM_TRACE) - zlog_debug("%s: up %s RPF is not present", - __PRETTY_FUNCTION__, up->sg_str); + zlog_debug("%s: up %s RPF is not present", __func__, + up->sg_str); } if (pim_ifp && PIM_I_am_DR(pim_ifp) @@ -651,21 +667,21 @@ void pim_upstream_switch(struct pim_instance *pim, struct pim_upstream *up, if (up->upstream_addr.s_addr == INADDR_ANY) { if (PIM_DEBUG_PIM_EVENTS) - zlog_debug("%s: RPF not configured for %s", - __PRETTY_FUNCTION__, up->sg_str); + zlog_debug("%s: RPF not configured for %s", __func__, + up->sg_str); return; } if (!up->rpf.source_nexthop.interface) { if (PIM_DEBUG_PIM_EVENTS) - zlog_debug("%s: RP not reachable for %s", - __PRETTY_FUNCTION__, up->sg_str); + zlog_debug("%s: RP not reachable for %s", __func__, + up->sg_str); return; } if (PIM_DEBUG_PIM_EVENTS) { zlog_debug("%s: PIM_UPSTREAM_%s: (S,G) old: %s new: %s", - __PRETTY_FUNCTION__, up->sg_str, + __func__, up->sg_str, pim_upstream_state2str(up->join_state), pim_upstream_state2str(new_state)); } @@ -812,7 +828,7 @@ static struct pim_upstream *pim_upstream_new(struct pim_instance *pim, sg->grp)) { if (PIM_DEBUG_PIM_TRACE) zlog_debug("%s: Received a (*,G) with no RP configured", - __PRETTY_FUNCTION__); + __func__); } up->parent = pim_upstream_find_parent(pim, up); @@ -833,8 +849,7 @@ static struct pim_upstream *pim_upstream_new(struct pim_instance *pim, up->join_state = PIM_UPSTREAM_NOTJOINED; up->reg_state = PIM_REG_NOINFO; up->state_transition = pim_time_monotonic_sec(); - up->channel_oil = - pim_channel_oil_add(pim, &up->sg, __PRETTY_FUNCTION__); + up->channel_oil = pim_channel_oil_add(pim, &up->sg, __func__); up->sptbit = PIM_UPSTREAM_SPTBIT_FALSE; up->rpf.source_nexthop.interface = NULL; @@ -851,9 +866,23 @@ static struct pim_upstream *pim_upstream_new(struct pim_instance *pim, up->ifchannels = list_new(); up->ifchannels->cmp = (int (*)(void *, void *))pim_ifchannel_compare; - if (up->sg.src.s_addr != INADDR_ANY) + if (up->sg.src.s_addr != INADDR_ANY) { wheel_add_item(pim->upstream_sg_wheel, up); + /* Inherit the DF role from the parent (*, G) entry for + * VxLAN BUM groups + */ + if (up->parent + && PIM_UPSTREAM_FLAG_TEST_MLAG_VXLAN(up->parent->flags) + && PIM_UPSTREAM_FLAG_TEST_MLAG_NON_DF(up->parent->flags)) { + PIM_UPSTREAM_FLAG_SET_MLAG_NON_DF(up->flags); + if (PIM_DEBUG_VXLAN) + zlog_debug( + "upstream %s inherited mlag non-df flag from parent", + up->sg_str); + } + } + if (PIM_UPSTREAM_FLAG_TEST_STATIC_IIF(up->flags) || PIM_UPSTREAM_FLAG_TEST_SRC_NOCACHE(up->flags)) { pim_upstream_fill_static_iif(up, incoming); @@ -874,7 +903,7 @@ static struct pim_upstream *pim_upstream_new(struct pim_instance *pim, if (PIM_DEBUG_PIM_TRACE) zlog_debug( "%s: Attempting to create upstream(%s), Unable to RPF for source", - __PRETTY_FUNCTION__, up->sg_str); + __func__, up->sg_str); } if (up->rpf.source_nexthop.interface) { @@ -883,16 +912,49 @@ static struct pim_upstream *pim_upstream_new(struct pim_instance *pim, } } + /* send the entry to the MLAG peer */ + /* XXX - duplicate send is possible here if pim_rpf_update + * successfully resolved the nexthop + */ + if (pim_up_mlag_is_local(up) + || PIM_UPSTREAM_FLAG_TEST_MLAG_INTERFACE(up->flags)) + pim_mlag_up_local_add(pim, up); + if (PIM_DEBUG_PIM_TRACE) { zlog_debug( "%s: Created Upstream %s upstream_addr %s ref count %d increment", - __PRETTY_FUNCTION__, up->sg_str, - inet_ntoa(up->upstream_addr), up->ref_count); + __func__, up->sg_str, inet_ntoa(up->upstream_addr), + up->ref_count); } return up; } +uint32_t pim_up_mlag_local_cost(struct pim_upstream *up) +{ + if (!(pim_up_mlag_is_local(up)) + && !(up->flags & PIM_UPSTREAM_FLAG_MASK_MLAG_INTERFACE)) + return router->infinite_assert_metric.route_metric; + + if ((up->rpf.source_nexthop.interface == + up->pim->vxlan.peerlink_rif) && + (up->rpf.source_nexthop.mrib_route_metric < + (router->infinite_assert_metric.route_metric - + PIM_UPSTREAM_MLAG_PEERLINK_PLUS_METRIC))) + return up->rpf.source_nexthop.mrib_route_metric + + PIM_UPSTREAM_MLAG_PEERLINK_PLUS_METRIC; + + return up->rpf.source_nexthop.mrib_route_metric; +} + +uint32_t pim_up_mlag_peer_cost(struct pim_upstream *up) +{ + if (!(up->flags & PIM_UPSTREAM_FLAG_MASK_MLAG_PEER)) + return router->infinite_assert_metric.route_metric; + + return up->mlag.peer_mrib_metric; +} + struct pim_upstream *pim_upstream_find(struct pim_instance *pim, struct prefix_sg *sg) { @@ -916,6 +978,15 @@ struct pim_upstream *pim_upstream_find_or_add(struct prefix_sg *sg, void pim_upstream_ref(struct pim_upstream *up, int flags, const char *name) { + /* if a local MLAG reference is being created we need to send the mroute + * to the peer + */ + if (!PIM_UPSTREAM_FLAG_TEST_MLAG_VXLAN(up->flags) && + PIM_UPSTREAM_FLAG_TEST_MLAG_VXLAN(flags)) { + PIM_UPSTREAM_FLAG_SET_MLAG_VXLAN(up->flags); + pim_mlag_up_local_add(up->pim, up); + } + /* when we go from non-FHR to FHR we need to re-eval traffic * forwarding path */ @@ -938,8 +1009,7 @@ void pim_upstream_ref(struct pim_upstream *up, int flags, const char *name) ++up->ref_count; if (PIM_DEBUG_PIM_TRACE) zlog_debug("%s(%s): upstream %s ref count %d increment", - __PRETTY_FUNCTION__, name, up->sg_str, - up->ref_count); + __func__, name, up->sg_str, up->ref_count); } struct pim_upstream *pim_upstream_add(struct pim_instance *pim, @@ -964,14 +1034,13 @@ struct pim_upstream *pim_upstream_add(struct pim_instance *pim, char buf[PREFIX2STR_BUFFER]; prefix2str(&up->rpf.rpf_addr, buf, sizeof(buf)); zlog_debug("%s(%s): %s, iif %s (%s) found: %d: ref_count: %d", - __PRETTY_FUNCTION__, name, + __func__, name, up->sg_str, buf, up->rpf.source_nexthop.interface ? up->rpf.source_nexthop.interface->name : "Unknown" , found, up->ref_count); } else - zlog_debug("%s(%s): (%s) failure to create", - __PRETTY_FUNCTION__, name, - pim_str_sg_dump(sg)); + zlog_debug("%s(%s): (%s) failure to create", __func__, + name, pim_str_sg_dump(sg)); } return up; @@ -1094,7 +1163,7 @@ static inline bool pim_upstream_is_msdp_peer_sa(struct pim_upstream *up) * AND inherited_olist(S,G) != NULL ) ) * } */ -int pim_upstream_evaluate_join_desired(struct pim_instance *pim, +bool pim_upstream_evaluate_join_desired(struct pim_instance *pim, struct pim_upstream *up) { bool empty_imm_oil; @@ -1175,8 +1244,7 @@ void pim_upstream_rpf_genid_changed(struct pim_instance *pim, sizeof(rpf_addr_str)); zlog_debug( "%s: matching neigh=%s against upstream (S,G)=%s[%s] joined=%d rpf_addr=%s", - __PRETTY_FUNCTION__, neigh_str, up->sg_str, - pim->vrf->name, + __func__, neigh_str, up->sg_str, pim->vrf->name, up->join_state == PIM_UPSTREAM_JOINED, rpf_addr_str); } @@ -1352,13 +1420,13 @@ struct pim_upstream *pim_upstream_keep_alive_timer_proc( PIM_UPSTREAM_FLAG_UNSET_SRC_STREAM(up->flags); /* Return if upstream entry got deleted.*/ - if (!pim_upstream_del(pim, up, __PRETTY_FUNCTION__)) + if (!pim_upstream_del(pim, up, __func__)) return NULL; } if (PIM_UPSTREAM_FLAG_TEST_SRC_NOCACHE(up->flags)) { PIM_UPSTREAM_FLAG_UNSET_SRC_NOCACHE(up->flags); - if (!pim_upstream_del(pim, up, __PRETTY_FUNCTION__)) + if (!pim_upstream_del(pim, up, __func__)) return NULL; } @@ -1370,7 +1438,7 @@ struct pim_upstream *pim_upstream_keep_alive_timer_proc( struct pim_upstream *parent = up->parent; PIM_UPSTREAM_FLAG_UNSET_SRC_LHR(up->flags); - up = pim_upstream_del(pim, up, __PRETTY_FUNCTION__); + up = pim_upstream_del(pim, up, __func__); if (parent) { pim_jp_agg_single_upstream_send(&parent->rpf, parent, @@ -1386,6 +1454,11 @@ static int pim_upstream_keep_alive_timer(struct thread *t) up = THREAD_ARG(t); + /* pull the stats and re-check */ + if (pim_upstream_sg_running_proc(up)) + /* kat was restarted because of new activity */ + return 0; + pim_upstream_keep_alive_timer_proc(up); return 0; } @@ -1502,7 +1575,7 @@ void pim_upstream_set_sptbit(struct pim_upstream *up, if (PIM_DEBUG_PIM_TRACE) zlog_debug( "%s: Incoming Interface: %s is different than RPF_interface(S) %s", - __PRETTY_FUNCTION__, incoming->name, + __func__, incoming->name, up->rpf.source_nexthop.interface->name); return; } @@ -1510,8 +1583,8 @@ void pim_upstream_set_sptbit(struct pim_upstream *up, // AND JoinDesired(S,G) == true if (!pim_upstream_evaluate_join_desired(up->channel_oil->pim, up)) { if (PIM_DEBUG_PIM_TRACE) - zlog_debug("%s: %s Join is not Desired", - __PRETTY_FUNCTION__, up->sg_str); + zlog_debug("%s: %s Join is not Desired", __func__, + up->sg_str); return; } @@ -1520,7 +1593,7 @@ void pim_upstream_set_sptbit(struct pim_upstream *up, up->sg.src)) { if (PIM_DEBUG_PIM_TRACE) zlog_debug("%s: %s is directly connected to the source", - __PRETTY_FUNCTION__, up->sg_str); + __func__, up->sg_str); up->sptbit = PIM_UPSTREAM_SPTBIT_TRUE; return; } @@ -1534,7 +1607,7 @@ void pim_upstream_set_sptbit(struct pim_upstream *up, if (PIM_DEBUG_PIM_TRACE) zlog_debug( "%s: %s RPF_interface(S) != RPF_interface(RP(G))", - __PRETTY_FUNCTION__, up->sg_str); + __func__, up->sg_str); up->sptbit = PIM_UPSTREAM_SPTBIT_TRUE; pim_jp_agg_single_upstream_send(&starup->rpf, starup, true); @@ -1546,7 +1619,7 @@ void pim_upstream_set_sptbit(struct pim_upstream *up, && pim_upstream_empty_inherited_olist(up)) { if (PIM_DEBUG_PIM_TRACE) zlog_debug("%s: %s OR inherited_olist(S,G,rpt) == NULL", - __PRETTY_FUNCTION__, up->sg_str); + __func__, up->sg_str); up->sptbit = PIM_UPSTREAM_SPTBIT_TRUE; return; } @@ -1556,7 +1629,7 @@ void pim_upstream_set_sptbit(struct pim_upstream *up, if (up->parent && pim_rpf_is_same(&up->rpf, &up->parent->rpf)) { if (PIM_DEBUG_PIM_TRACE) zlog_debug("%s: %s RPF'(S,G) is the same as RPF'(*,G)", - __PRETTY_FUNCTION__, up->sg_str); + __func__, up->sg_str); up->sptbit = PIM_UPSTREAM_SPTBIT_TRUE; return; } @@ -1608,8 +1681,9 @@ static int pim_upstream_register_stop_timer(struct thread *t) if (PIM_DEBUG_PIM_TRACE) { char state_str[PIM_REG_STATE_STR_LEN]; zlog_debug("%s: (S,G)=%s[%s] upstream register stop timer %s", - __PRETTY_FUNCTION__, up->sg_str, pim->vrf->name, - pim_reg_state2str(up->reg_state, state_str, sizeof(state_str))); + __func__, up->sg_str, pim->vrf->name, + pim_reg_state2str(up->reg_state, state_str, + sizeof(state_str))); } switch (up->reg_state) { @@ -1626,7 +1700,7 @@ static int pim_upstream_register_stop_timer(struct thread *t) if (!up->rpf.source_nexthop.interface) { if (PIM_DEBUG_PIM_TRACE) zlog_debug("%s: up %s RPF is not present", - __PRETTY_FUNCTION__, up->sg_str); + __func__, up->sg_str); return 0; } @@ -1635,7 +1709,7 @@ static int pim_upstream_register_stop_timer(struct thread *t) if (PIM_DEBUG_PIM_TRACE) zlog_debug( "%s: Interface: %s is not configured for pim", - __PRETTY_FUNCTION__, + __func__, up->rpf.source_nexthop.interface->name); return 0; } @@ -1648,7 +1722,7 @@ static int pim_upstream_register_stop_timer(struct thread *t) if (PIM_DEBUG_PIM_TRACE) zlog_debug( "%s: Stop sending the register, because I am the RP and we haven't seen a packet in a while", - __PRETTY_FUNCTION__); + __func__); return 0; } pim_null_register_send(up); @@ -1678,7 +1752,7 @@ void pim_upstream_start_register_stop_timer(struct pim_upstream *up, if (PIM_DEBUG_PIM_TRACE) { zlog_debug( "%s: (S,G)=%s Starting upstream register stop timer %d", - __PRETTY_FUNCTION__, up->sg_str, time); + __func__, up->sg_str, time); } thread_add_timer(router->master, pim_upstream_register_stop_timer, up, time, &up->t_rs_timer); @@ -1694,10 +1768,11 @@ int pim_upstream_inherited_olist_decide(struct pim_instance *pim, if (!up->rpf.source_nexthop.interface) if (PIM_DEBUG_PIM_TRACE) - zlog_debug("%s: up %s RPF is not present", - __PRETTY_FUNCTION__, up->sg_str); + zlog_debug("%s: up %s RPF is not present", __func__, + up->sg_str); FOR_ALL_INTERFACES (pim->vrf, ifp) { + struct pim_interface *pim_ifp; if (!ifp->info) continue; @@ -1711,6 +1786,12 @@ int pim_upstream_inherited_olist_decide(struct pim_instance *pim, if (!ch && !starch) continue; + pim_ifp = ifp->info; + if (PIM_I_am_DualActive(pim_ifp) + && PIM_UPSTREAM_FLAG_TEST_MLAG_INTERFACE(up->flags) + && (PIM_UPSTREAM_FLAG_TEST_MLAG_NON_DF(up->flags) + || !PIM_UPSTREAM_FLAG_TEST_MLAG_PEER(up->flags))) + continue; if (pim_upstream_evaluate_join_desired_interface(up, ch, starch)) { int flag = PIM_OIF_FLAG_PROTO_PIM; @@ -1786,8 +1867,8 @@ void pim_upstream_find_new_rpf(struct pim_instance *pim) if (up->upstream_addr.s_addr == INADDR_ANY) { if (PIM_DEBUG_PIM_TRACE) zlog_debug( - "%s: RP not configured for Upstream %s", - __PRETTY_FUNCTION__, up->sg_str); + "%s: RP not configured for Upstream %s", + __func__, up->sg_str); continue; } @@ -1795,7 +1876,7 @@ void pim_upstream_find_new_rpf(struct pim_instance *pim) if (PIM_DEBUG_PIM_TRACE) zlog_debug( "%s: Upstream %s without a path to send join, checking", - __PRETTY_FUNCTION__, up->sg_str); + __func__, up->sg_str); old.source_nexthop.interface = up->rpf.source_nexthop.interface; rpf_result = pim_rpf_update(pim, up, &old, __func__); @@ -1823,7 +1904,7 @@ void pim_upstream_terminate(struct pim_instance *pim) struct pim_upstream *up; while ((up = rb_pim_upstream_first(&pim->upstream_head))) { - pim_upstream_del(pim, up, __PRETTY_FUNCTION__); + pim_upstream_del(pim, up, __func__); } rb_pim_upstream_fini(&pim->upstream_head); @@ -1890,41 +1971,14 @@ static bool pim_upstream_kat_start_ok(struct pim_upstream *up) return false; } -/* - * Code to check and see if we've received packets on a S,G mroute - * and if so to set the SPT bit appropriately - */ -static void pim_upstream_sg_running(void *arg) +static bool pim_upstream_sg_running_proc(struct pim_upstream *up) { - struct pim_upstream *up = (struct pim_upstream *)arg; - struct pim_instance *pim = up->channel_oil->pim; + bool rv = false; + struct pim_instance *pim = up->pim; - // No packet can have arrived here if this is the case - if (!up->channel_oil->installed) { - if (PIM_DEBUG_PIM_TRACE) - zlog_debug("%s: %s%s is not installed in mroute", - __PRETTY_FUNCTION__, up->sg_str, - pim->vrf->name); - return; - } + if (!up->channel_oil->installed) + return rv; - /* - * This is a bit of a hack - * We've noted that we should rescan but - * we've missed the window for doing so in - * pim_zebra.c for some reason. I am - * only doing this at this point in time - * to get us up and working for the moment - */ - if (up->channel_oil->oil_inherited_rescan) { - if (PIM_DEBUG_PIM_TRACE) - zlog_debug( - "%s: Handling unscanned inherited_olist for %s[%s]", - __PRETTY_FUNCTION__, up->sg_str, - pim->vrf->name); - pim_upstream_inherited_olist_decide(pim, up); - up->channel_oil->oil_inherited_rescan = 0; - } pim_mroute_update_counters(up->channel_oil); // Have we seen packets? @@ -1933,12 +1987,12 @@ static void pim_upstream_sg_running(void *arg) if (PIM_DEBUG_PIM_TRACE) { zlog_debug( "%s[%s]: %s old packet count is equal or lastused is greater than 30, (%ld,%ld,%lld)", - __PRETTY_FUNCTION__, up->sg_str, pim->vrf->name, + __func__, up->sg_str, pim->vrf->name, up->channel_oil->cc.oldpktcnt, up->channel_oil->cc.pktcnt, up->channel_oil->cc.lastused / 100); } - return; + return rv; } if (pim_upstream_kat_start_ok(up)) { @@ -1951,19 +2005,60 @@ static void pim_upstream_sg_running(void *arg) up->sg_str, pim->vrf->name); pim_upstream_ref(up, PIM_UPSTREAM_FLAG_MASK_SRC_STREAM, - __PRETTY_FUNCTION__); + __func__); PIM_UPSTREAM_FLAG_SET_SRC_STREAM(up->flags); pim_upstream_fhr_kat_start(up); } pim_upstream_keep_alive_timer_start(up, pim->keep_alive_time); - } else if (PIM_UPSTREAM_FLAG_TEST_SRC_LHR(up->flags)) + rv = true; + } else if (PIM_UPSTREAM_FLAG_TEST_SRC_LHR(up->flags)) { pim_upstream_keep_alive_timer_start(up, pim->keep_alive_time); + rv = true; + } if ((up->sptbit != PIM_UPSTREAM_SPTBIT_TRUE) && (up->rpf.source_nexthop.interface)) { pim_upstream_set_sptbit(up, up->rpf.source_nexthop.interface); } - return; + + return rv; +} + +/* + * Code to check and see if we've received packets on a S,G mroute + * and if so to set the SPT bit appropriately + */ +static void pim_upstream_sg_running(void *arg) +{ + struct pim_upstream *up = (struct pim_upstream *)arg; + struct pim_instance *pim = up->channel_oil->pim; + + // No packet can have arrived here if this is the case + if (!up->channel_oil->installed) { + if (PIM_DEBUG_TRACE) + zlog_debug("%s: %s%s is not installed in mroute", + __func__, up->sg_str, pim->vrf->name); + return; + } + + /* + * This is a bit of a hack + * We've noted that we should rescan but + * we've missed the window for doing so in + * pim_zebra.c for some reason. I am + * only doing this at this point in time + * to get us up and working for the moment + */ + if (up->channel_oil->oil_inherited_rescan) { + if (PIM_DEBUG_TRACE) + zlog_debug( + "%s: Handling unscanned inherited_olist for %s[%s]", + __func__, up->sg_str, pim->vrf->name); + pim_upstream_inherited_olist_decide(pim, up); + up->channel_oil->oil_inherited_rescan = 0; + } + + pim_upstream_sg_running_proc(up); } void pim_upstream_add_lhr_star_pimreg(struct pim_instance *pim) @@ -1974,7 +2069,7 @@ void pim_upstream_add_lhr_star_pimreg(struct pim_instance *pim) if (up->sg.src.s_addr != INADDR_ANY) continue; - if (!PIM_UPSTREAM_FLAG_TEST_SRC_IGMP(up->flags)) + if (!PIM_UPSTREAM_FLAG_TEST_CAN_BE_LHR(up->flags)) continue; pim_channel_add_oif(up->channel_oil, pim->regiface, @@ -2021,7 +2116,7 @@ void pim_upstream_remove_lhr_star_pimreg(struct pim_instance *pim, if (up->sg.src.s_addr != INADDR_ANY) continue; - if (!PIM_UPSTREAM_FLAG_TEST_SRC_IGMP(up->flags)) + if (!PIM_UPSTREAM_FLAG_TEST_CAN_BE_LHR(up->flags)) continue; if (!nlist) { diff --git a/pimd/pim_upstream.h b/pimd/pim_upstream.h index 1eb2052bb3..ca693ee73f 100644 --- a/pimd/pim_upstream.h +++ b/pimd/pim_upstream.h @@ -74,6 +74,8 @@ * blackholing the traffic pulled down to the LHR. */ #define PIM_UPSTREAM_FLAG_MASK_MLAG_NON_DF (1 << 17) +/* MLAG mroute rxed from the peer MLAG switch */ +#define PIM_UPSTREAM_FLAG_MASK_MLAG_PEER (1 << 18) /* * We are creating a non-joined upstream data structure * for this S,G as that we want to have a channel oil @@ -86,6 +88,12 @@ * This flag is only relevant for (S,G) entries. */ #define PIM_UPSTREAM_FLAG_MASK_USE_RPT (1 << 20) +/* PIM Syncs upstream entries to peer Nodes via MLAG in 2 cases. + * one is to support plain PIM Redundancy and another one is to support + * PIM REdundancy. + */ +#define PIM_UPSTREAM_FLAG_MASK_MLAG_INTERFACE (1 << 21) + #define PIM_UPSTREAM_FLAG_ALL 0xFFFFFFFF @@ -108,8 +116,11 @@ #define PIM_UPSTREAM_FLAG_TEST_SRC_VXLAN(flags) ((flags) & (PIM_UPSTREAM_FLAG_MASK_SRC_VXLAN_ORIG | PIM_UPSTREAM_FLAG_MASK_SRC_VXLAN_TERM)) #define PIM_UPSTREAM_FLAG_TEST_MLAG_VXLAN(flags) ((flags) & PIM_UPSTREAM_FLAG_MASK_MLAG_VXLAN) #define PIM_UPSTREAM_FLAG_TEST_MLAG_NON_DF(flags) ((flags) & PIM_UPSTREAM_FLAG_MASK_MLAG_NON_DF) +#define PIM_UPSTREAM_FLAG_TEST_MLAG_PEER(flags) ((flags) & PIM_UPSTREAM_FLAG_MASK_MLAG_PEER) #define PIM_UPSTREAM_FLAG_TEST_SRC_NOCACHE(flags) ((flags) &PIM_UPSTREAM_FLAG_MASK_SRC_NOCACHE) #define PIM_UPSTREAM_FLAG_TEST_USE_RPT(flags) ((flags) & PIM_UPSTREAM_FLAG_MASK_USE_RPT) +#define PIM_UPSTREAM_FLAG_TEST_CAN_BE_LHR(flags) ((flags) & (PIM_UPSTREAM_FLAG_MASK_SRC_IGMP | PIM_UPSTREAM_FLAG_MASK_SRC_VXLAN_TERM)) +#define PIM_UPSTREAM_FLAG_TEST_MLAG_INTERFACE(flags) ((flags)&PIM_UPSTREAM_FLAG_MASK_MLAG_INTERFACE) #define PIM_UPSTREAM_FLAG_SET_DR_JOIN_DESIRED(flags) ((flags) |= PIM_UPSTREAM_FLAG_MASK_DR_JOIN_DESIRED) #define PIM_UPSTREAM_FLAG_SET_DR_JOIN_DESIRED_UPDATED(flags) ((flags) |= PIM_UPSTREAM_FLAG_MASK_DR_JOIN_DESIRED_UPDATED) @@ -129,7 +140,9 @@ #define PIM_UPSTREAM_FLAG_SET_SRC_VXLAN_TERM(flags) ((flags) |= PIM_UPSTREAM_FLAG_MASK_SRC_VXLAN_TERM) #define PIM_UPSTREAM_FLAG_SET_MLAG_VXLAN(flags) ((flags) |= PIM_UPSTREAM_FLAG_MASK_MLAG_VXLAN) #define PIM_UPSTREAM_FLAG_SET_MLAG_NON_DF(flags) ((flags) |= PIM_UPSTREAM_FLAG_MASK_MLAG_NON_DF) +#define PIM_UPSTREAM_FLAG_SET_MLAG_PEER(flags) ((flags) |= PIM_UPSTREAM_FLAG_MASK_MLAG_PEER) #define PIM_UPSTREAM_FLAG_SET_USE_RPT(flags) ((flags) |= PIM_UPSTREAM_FLAG_MASK_USE_RPT) +#define PIM_UPSTREAM_FLAG_SET_MLAG_INTERFACE(flags) ((flags) |= PIM_UPSTREAM_FLAG_MASK_MLAG_INTERFACE) #define PIM_UPSTREAM_FLAG_UNSET_DR_JOIN_DESIRED(flags) ((flags) &= ~PIM_UPSTREAM_FLAG_MASK_DR_JOIN_DESIRED) #define PIM_UPSTREAM_FLAG_UNSET_DR_JOIN_DESIRED_UPDATED(flags) ((flags) &= ~PIM_UPSTREAM_FLAG_MASK_DR_JOIN_DESIRED_UPDATED) @@ -149,8 +162,16 @@ #define PIM_UPSTREAM_FLAG_UNSET_SRC_VXLAN_TERM(flags) ((flags) &= ~PIM_UPSTREAM_FLAG_MASK_SRC_VXLAN_TERM) #define PIM_UPSTREAM_FLAG_UNSET_MLAG_VXLAN(flags) ((flags) &= ~PIM_UPSTREAM_FLAG_MASK_MLAG_VXLAN) #define PIM_UPSTREAM_FLAG_UNSET_MLAG_NON_DF(flags) ((flags) &= ~PIM_UPSTREAM_FLAG_MASK_MLAG_NON_DF) +#define PIM_UPSTREAM_FLAG_UNSET_MLAG_PEER(flags) ((flags) &= ~PIM_UPSTREAM_FLAG_MASK_MLAG_PEER) #define PIM_UPSTREAM_FLAG_UNSET_SRC_NOCACHE(flags) ((flags) &= ~PIM_UPSTREAM_FLAG_MASK_SRC_NOCACHE) #define PIM_UPSTREAM_FLAG_UNSET_USE_RPT(flags) ((flags) &= ~PIM_UPSTREAM_FLAG_MASK_USE_RPT) +#define PIM_UPSTREAM_FLAG_UNSET_MLAG_INTERFACE(flags) ((flags) &= ~PIM_UPSTREAM_FLAG_MASK_MLAG_INTERFACE) + +/* The RPF cost is incremented by 10 if the RPF interface is the peerlink-rif. + * This is used to force the MLAG switch with the lowest cost to the RPF + * to become the MLAG DF. + */ +#define PIM_UPSTREAM_MLAG_PEERLINK_PLUS_METRIC 10 enum pim_upstream_state { PIM_UPSTREAM_NOTJOINED, @@ -169,6 +190,13 @@ enum pim_upstream_sptbit { PIM_UPSTREAM_SPTBIT_TRUE }; +struct pim_up_mlag { + /* MRIB.metric(S) from the peer switch. This is used for DF election + * and switch with the lowest cost wins. + */ + uint32_t peer_mrib_metric; +}; + PREDECL_RBTREE_UNIQ(rb_pim_upstream); /* Upstream (S,G) channel in Joined state @@ -209,6 +237,8 @@ struct pim_upstream { struct channel_oil *channel_oil; struct list *sources; struct list *ifchannels; + /* Counter for Dual active ifchannels*/ + uint32_t dualactive_ifchannel_count; enum pim_upstream_state join_state; enum pim_reg_state reg_state; @@ -218,6 +248,8 @@ struct pim_upstream { struct pim_rpf rpf; + struct pim_up_mlag mlag; + struct thread *t_join_timer; /* @@ -249,6 +281,14 @@ static inline bool pim_upstream_is_kat_running(struct pim_upstream *up) return (up->t_ka_timer != NULL); } +static inline bool pim_up_mlag_is_local(struct pim_upstream *up) +{ + /* XXX: extend this to also return true if the channel-oil has + * any AA devices + */ + return (up->flags & PIM_UPSTREAM_FLAG_MASK_MLAG_VXLAN); +} + struct pim_upstream *pim_upstream_find(struct pim_instance *pim, struct prefix_sg *sg); struct pim_upstream *pim_upstream_find_or_add(struct prefix_sg *sg, @@ -259,13 +299,14 @@ struct pim_upstream *pim_upstream_add(struct pim_instance *pim, struct interface *ifp, int flags, const char *name, struct pim_ifchannel *ch); -void pim_upstream_ref(struct pim_upstream *up, int flags, const char *name); +void pim_upstream_ref(struct pim_upstream *up, + int flags, const char *name); struct pim_upstream *pim_upstream_del(struct pim_instance *pim, struct pim_upstream *up, const char *name); -int pim_upstream_evaluate_join_desired(struct pim_instance *pim, - struct pim_upstream *up); +bool pim_upstream_evaluate_join_desired(struct pim_instance *pim, + struct pim_upstream *up); int pim_upstream_evaluate_join_desired_interface(struct pim_upstream *up, struct pim_ifchannel *ch, struct pim_ifchannel *starch); @@ -350,5 +391,7 @@ void pim_upstream_fill_static_iif(struct pim_upstream *up, struct interface *incoming); void pim_upstream_update_use_rpt(struct pim_upstream *up, bool update_mroute); +uint32_t pim_up_mlag_local_cost(struct pim_upstream *up); +uint32_t pim_up_mlag_peer_cost(struct pim_upstream *up); void pim_upstream_reeval_use_rpt(struct pim_instance *pim); #endif /* PIM_UPSTREAM_H */ diff --git a/pimd/pim_vty.c b/pimd/pim_vty.c index c48ec373f8..8a87dfbb55 100644 --- a/pimd/pim_vty.c +++ b/pimd/pim_vty.c @@ -117,6 +117,11 @@ int pim_debug_config_write(struct vty *vty) ++writes; } + if (PIM_DEBUG_MLAG) { + vty_out(vty, "debug pim mlag\n"); + ++writes; + } + if (PIM_DEBUG_BSM) { vty_out(vty, "debug pim bsm\n"); ++writes; @@ -242,8 +247,6 @@ int pim_global_config_write_worker(struct pim_instance *pim, struct vty *vty) } } - pim_vxlan_config_write(vty, spaces, &writes); - return writes; } diff --git a/pimd/pim_vxlan.c b/pimd/pim_vxlan.c index fc34f3f600..569b04d278 100644 --- a/pimd/pim_vxlan.c +++ b/pimd/pim_vxlan.c @@ -38,6 +38,7 @@ #include "pim_nht.h" #include "pim_zebra.h" #include "pim_vxlan.h" +#include "pim_mlag.h" /* pim-vxlan global info */ struct pim_vxlan vxlan_info, *pim_vxlan_p = &vxlan_info; @@ -84,8 +85,16 @@ static void pim_vxlan_do_reg_work(void) if (PIM_DEBUG_VXLAN) zlog_debug("vxlan SG %s periodic NULL register", vxlan_sg->sg_str); - pim_null_register_send(vxlan_sg->up); - ++work_cnt; + + /* + * If we are on the work queue *and* the rpf + * has been lost on the vxlan_sg->up let's + * make sure that we don't send it. + */ + if (vxlan_sg->up->rpf.source_nexthop.interface) { + pim_null_register_send(vxlan_sg->up); + ++work_cnt; + } } if (work_cnt > vxlan_info.max_work_cnt) { @@ -216,6 +225,7 @@ static void pim_vxlan_orig_mr_up_del(struct pim_vxlan_sg *vxlan_sg) vxlan_sg->sg_str); vxlan_sg->up = NULL; + if (up->flags & PIM_UPSTREAM_FLAG_MASK_SRC_VXLAN_ORIG) { /* clear out all the vxlan properties */ up->flags &= ~(PIM_UPSTREAM_FLAG_MASK_SRC_VXLAN_ORIG | @@ -238,8 +248,7 @@ static void pim_vxlan_orig_mr_up_del(struct pim_vxlan_sg *vxlan_sg) * origination mroutes active sources but just in * case */ - up = pim_upstream_del(vxlan_sg->pim, up, - __PRETTY_FUNCTION__); + up = pim_upstream_del(vxlan_sg->pim, up, __func__); } /* if there are other references register the source * for nht @@ -284,6 +293,7 @@ static void pim_vxlan_orig_mr_up_iif_update(struct pim_vxlan_sg *vxlan_sg) static void pim_vxlan_orig_mr_up_add(struct pim_vxlan_sg *vxlan_sg) { struct pim_upstream *up; + struct pim_interface *term_ifp; int flags = 0; struct prefix nht_p; struct pim_instance *pim = vxlan_sg->pim; @@ -343,8 +353,13 @@ static void pim_vxlan_orig_mr_up_add(struct pim_vxlan_sg *vxlan_sg) } /* We are acting FHR; clear out use_rpt setting if any */ pim_upstream_update_use_rpt(up, false /*update_mroute*/); - pim_upstream_ref(up, flags, __PRETTY_FUNCTION__); + pim_upstream_ref(up, flags, __func__); vxlan_sg->up = up; + term_ifp = pim_vxlan_get_term_ifp(pim); + /* mute termination device on origination mroutes */ + if (term_ifp) + pim_channel_update_oif_mute(up->channel_oil, + term_ifp); pim_vxlan_orig_mr_up_iif_update(vxlan_sg); /* mute pimreg on origination mroutes */ if (pim->regiface) @@ -352,8 +367,7 @@ static void pim_vxlan_orig_mr_up_add(struct pim_vxlan_sg *vxlan_sg) pim->regiface->info); } else { up = pim_upstream_add(vxlan_sg->pim, &vxlan_sg->sg, - vxlan_sg->iif, flags, - __PRETTY_FUNCTION__, NULL); + vxlan_sg->iif, flags, __func__, NULL); vxlan_sg->up = up; } @@ -474,15 +488,16 @@ static void pim_vxlan_orig_mr_del(struct pim_vxlan_sg *vxlan_sg) pim_vxlan_orig_mr_up_del(vxlan_sg); } -static void pim_vxlan_orig_mr_iif_update(struct hash_backet *backet, void *arg) +static void pim_vxlan_orig_mr_iif_update(struct hash_bucket *backet, void *arg) { - struct interface *ifp = (struct interface *)arg; + struct interface *ifp; struct pim_vxlan_sg *vxlan_sg = (struct pim_vxlan_sg *)backet->data; struct interface *old_iif = vxlan_sg->iif; if (!pim_vxlan_is_orig_mroute(vxlan_sg)) return; + ifp = pim_vxlan_orig_mr_iif_get(vxlan_sg->pim); if (PIM_DEBUG_VXLAN) zlog_debug("vxlan SG %s iif changed from %s to %s", vxlan_sg->sg_str, @@ -529,8 +544,15 @@ static void pim_vxlan_term_mr_oif_add(struct pim_vxlan_sg *vxlan_sg) vxlan_sg->sg_str, vxlan_sg->term_oif->name); if (pim_ifchannel_local_membership_add(vxlan_sg->term_oif, - &vxlan_sg->sg)) { + &vxlan_sg->sg, true /*is_vxlan */)) { vxlan_sg->flags |= PIM_VXLAN_SGF_OIF_INSTALLED; + /* update the inherited OIL */ + /* XXX - I don't see the inherited OIL updated when a local + * member is added. And that probably needs to be fixed. Till + * that happens we do a force update on the inherited OIL + * here. + */ + pim_upstream_inherited_olist(vxlan_sg->pim, vxlan_sg->up); } else { zlog_warn("vxlan SG %s term-oif %s add failed", vxlan_sg->sg_str, vxlan_sg->term_oif->name); @@ -548,6 +570,43 @@ static void pim_vxlan_term_mr_oif_del(struct pim_vxlan_sg *vxlan_sg) vxlan_sg->flags &= ~PIM_VXLAN_SGF_OIF_INSTALLED; pim_ifchannel_local_membership_del(vxlan_sg->term_oif, &vxlan_sg->sg); + /* update the inherited OIL */ + /* XXX - I don't see the inherited OIL updated when a local member + * is deleted. And that probably needs to be fixed. Till that happens + * we do a force update on the inherited OIL here. + */ + pim_upstream_inherited_olist(vxlan_sg->pim, vxlan_sg->up); +} + +static void pim_vxlan_update_sg_entry_mlag(struct pim_instance *pim, + struct pim_upstream *up, bool inherit) +{ + bool is_df = true; + + if (inherit && up->parent && + PIM_UPSTREAM_FLAG_TEST_MLAG_VXLAN(up->parent->flags) && + PIM_UPSTREAM_FLAG_TEST_MLAG_NON_DF(up->parent->flags)) + is_df = false; + + pim_mlag_up_df_role_update(pim, up, is_df, "inherit_xg_df"); +} + +/* We run MLAG DF election only on mroutes that have the termination + * device ipmr-lo in the immediate OIL. This is only (*, G) entries at the + * moment. For (S, G) entries that (with ipmr-lo in the inherited OIL) we + * inherit the DF role from the (*, G) entry. + */ +void pim_vxlan_inherit_mlag_flags(struct pim_instance *pim, + struct pim_upstream *up, bool inherit) +{ + struct listnode *listnode; + struct pim_upstream *child; + + for (ALL_LIST_ELEMENTS_RO(up->sources, listnode, + child)) { + pim_vxlan_update_sg_entry_mlag(pim, + child, true /* inherit */); + } } static void pim_vxlan_term_mr_up_add(struct pim_vxlan_sg *vxlan_sg) @@ -568,15 +627,18 @@ static void pim_vxlan_term_mr_up_add(struct pim_vxlan_sg *vxlan_sg) /* enable MLAG designated-forwarder election on termination mroutes */ PIM_UPSTREAM_FLAG_SET_MLAG_VXLAN(flags); - up = pim_upstream_add(vxlan_sg->pim, &vxlan_sg->sg, - NULL /* iif */, flags, - __PRETTY_FUNCTION__, NULL); + up = pim_upstream_add(vxlan_sg->pim, &vxlan_sg->sg, NULL /* iif */, + flags, __func__, NULL); vxlan_sg->up = up; if (!up) { zlog_warn("vxlan SG %s term mroute-up add failed", vxlan_sg->sg_str); + return; } + + /* update existing SG entries with the parent's MLAG flag */ + pim_vxlan_inherit_mlag_flags(vxlan_sg->pim, up, true /*enable*/); } static void pim_vxlan_term_mr_up_del(struct pim_vxlan_sg *vxlan_sg) @@ -591,12 +653,14 @@ static void pim_vxlan_term_mr_up_del(struct pim_vxlan_sg *vxlan_sg) vxlan_sg->sg_str); vxlan_sg->up = NULL; if (up->flags & PIM_UPSTREAM_FLAG_MASK_SRC_VXLAN_TERM) { + /* update SG entries that are inheriting from this XG entry */ + pim_vxlan_inherit_mlag_flags(vxlan_sg->pim, up, + false /*enable*/); /* clear out all the vxlan related flags */ up->flags &= ~(PIM_UPSTREAM_FLAG_MASK_SRC_VXLAN_TERM | PIM_UPSTREAM_FLAG_MASK_MLAG_VXLAN); - - pim_upstream_del(vxlan_sg->pim, up, - __PRETTY_FUNCTION__); + pim_mlag_up_local_del(vxlan_sg->pim, up); + pim_upstream_del(vxlan_sg->pim, up, __func__); } } @@ -660,6 +724,14 @@ static struct pim_vxlan_sg *pim_vxlan_sg_new(struct pim_instance *pim, vxlan_sg = hash_get(pim->vxlan.sg_hash, vxlan_sg, hash_alloc_intern); + /* we register with the MLAG daemon in the first VxLAN SG and never + * de-register during that life of the pimd + */ + if (pim->vxlan.sg_hash->count == 1) { + vxlan_mlag.flags |= PIM_VXLAN_MLAGF_DO_REG; + pim_mlag_register(); + } + return vxlan_sg; } @@ -691,14 +763,8 @@ struct pim_vxlan_sg *pim_vxlan_sg_add(struct pim_instance *pim, return vxlan_sg; } -void pim_vxlan_sg_del(struct pim_instance *pim, struct prefix_sg *sg) +static void pim_vxlan_sg_del_item(struct pim_vxlan_sg *vxlan_sg) { - struct pim_vxlan_sg *vxlan_sg; - - vxlan_sg = pim_vxlan_sg_find(pim, sg); - if (!vxlan_sg) - return; - vxlan_sg->flags |= PIM_VXLAN_SGF_DEL_IN_PROG; pim_vxlan_del_work(vxlan_sg); @@ -708,21 +774,37 @@ void pim_vxlan_sg_del(struct pim_instance *pim, struct prefix_sg *sg) else pim_vxlan_term_mr_del(vxlan_sg); - hash_release(vxlan_sg->pim->vxlan.sg_hash, vxlan_sg); - if (PIM_DEBUG_VXLAN) zlog_debug("vxlan SG %s free", vxlan_sg->sg_str); XFREE(MTYPE_PIM_VXLAN_SG, vxlan_sg); } +void pim_vxlan_sg_del(struct pim_instance *pim, struct prefix_sg *sg) +{ + struct pim_vxlan_sg *vxlan_sg; + + vxlan_sg = pim_vxlan_sg_find(pim, sg); + if (!vxlan_sg) + return; + + pim_vxlan_sg_del_item(vxlan_sg); + hash_release(pim->vxlan.sg_hash, vxlan_sg); +} + /******************************* MLAG handling *******************************/ +bool pim_vxlan_do_mlag_reg(void) +{ + return (vxlan_mlag.flags & PIM_VXLAN_MLAGF_DO_REG); +} + /* The peerlink sub-interface is added as an OIF to the origination-mroute. * This is done to send a copy of the multicast-vxlan encapsulated traffic * to the MLAG peer which may mroute it over the underlay if there are any * interested receivers. */ -static void pim_vxlan_sg_peerlink_update(struct hash_backet *backet, void *arg) +static void pim_vxlan_sg_peerlink_oif_update(struct hash_bucket *backet, + void *arg) { struct interface *new_oif = (struct interface *)arg; struct pim_vxlan_sg *vxlan_sg = (struct pim_vxlan_sg *)backet->data; @@ -761,8 +843,6 @@ void pim_vxlan_mlag_update(bool enable, bool peer_state, uint32_t role, struct in_addr *reg_addr) { struct pim_instance *pim; - struct interface *old_oif; - struct interface *new_oif; char addr_buf[INET_ADDRSTRLEN]; struct pim_interface *pim_ifp = NULL; @@ -782,8 +862,6 @@ void pim_vxlan_mlag_update(bool enable, bool peer_state, uint32_t role, */ pim = pim_get_pim_instance(VRF_DEFAULT); - old_oif = pim_vxlan_orig_mr_oif_get(pim); - if (enable) vxlan_mlag.flags |= PIM_VXLAN_MLAGF_ENABLED; else @@ -804,35 +882,9 @@ void pim_vxlan_mlag_update(bool enable, bool peer_state, uint32_t role, pim_vxlan_set_peerlink_rif(pim, peerlink_rif); else pim_vxlan_set_peerlink_rif(pim, NULL); - - new_oif = pim_vxlan_orig_mr_oif_get(pim); - if (old_oif != new_oif) - hash_iterate(pim->vxlan.sg_hash, pim_vxlan_sg_peerlink_update, - new_oif); } /****************************** misc callbacks *******************************/ -void pim_vxlan_config_write(struct vty *vty, char *spaces, int *writes) -{ - char addr_buf[INET_ADDRSTRLEN]; - - if ((vxlan_mlag.flags & PIM_VXLAN_MLAGF_ENABLED) && - vxlan_mlag.peerlink_rif) { - - inet_ntop(AF_INET, &vxlan_mlag.reg_addr, - addr_buf, sizeof(addr_buf)); - vty_out(vty, - "%sip pim mlag %s role %s state %s addr %s\n", - spaces, - vxlan_mlag.peerlink_rif->name, - (vxlan_mlag.role == PIM_VXLAN_MLAG_ROLE_PRIMARY) ? - "primary":"secondary", - vxlan_mlag.peer_state ? "up" : "down", - addr_buf); - *writes += 1; - } -} - static void pim_vxlan_set_default_iif(struct pim_instance *pim, struct interface *ifp) { @@ -844,9 +896,8 @@ static void pim_vxlan_set_default_iif(struct pim_instance *pim, old_iif = pim->vxlan.default_iif; if (PIM_DEBUG_VXLAN) zlog_debug("%s: vxlan default iif changed from %s to %s", - __PRETTY_FUNCTION__, - old_iif ? old_iif->name : "-", - ifp ? ifp->name : "-"); + __func__, old_iif ? old_iif->name : "-", + ifp ? ifp->name : "-"); old_iif = pim_vxlan_orig_mr_iif_get(pim); pim->vxlan.default_iif = ifp; @@ -855,22 +906,80 @@ static void pim_vxlan_set_default_iif(struct pim_instance *pim, return; if (PIM_DEBUG_VXLAN) - zlog_debug("%s: vxlan orig iif changed from %s to %s", - __PRETTY_FUNCTION__, old_iif ? old_iif->name : "-", - ifp ? ifp->name : "-"); + zlog_debug("%s: vxlan orig iif changed from %s to %s", __func__, + old_iif ? old_iif->name : "-", + ifp ? ifp->name : "-"); /* add/del upstream entries for the existing vxlan SG when the * interface becomes available */ if (pim->vxlan.sg_hash) hash_iterate(pim->vxlan.sg_hash, - pim_vxlan_orig_mr_iif_update, ifp); + pim_vxlan_orig_mr_iif_update, NULL); +} + +static void pim_vxlan_up_cost_update(struct pim_instance *pim, + struct pim_upstream *up, + struct interface *old_peerlink_rif) +{ + if (!PIM_UPSTREAM_FLAG_TEST_MLAG_VXLAN(up->flags)) + return; + + if (up->rpf.source_nexthop.interface && + ((up->rpf.source_nexthop.interface == + pim->vxlan.peerlink_rif) || + (up->rpf.source_nexthop.interface == + old_peerlink_rif))) { + if (PIM_DEBUG_VXLAN) + zlog_debug("RPF cost adjust for %s on peerlink-rif (old: %s, new: %s) change", + up->sg_str, + old_peerlink_rif ? + old_peerlink_rif->name : "-", + pim->vxlan.peerlink_rif ? + pim->vxlan.peerlink_rif->name : "-"); + pim_mlag_up_local_add(pim, up); + } +} + +static void pim_vxlan_term_mr_cost_update(struct hash_bucket *backet, void *arg) +{ + struct interface *old_peerlink_rif = (struct interface *)arg; + struct pim_vxlan_sg *vxlan_sg = (struct pim_vxlan_sg *)backet->data; + struct pim_upstream *up; + struct listnode *listnode; + struct pim_upstream *child; + + if (pim_vxlan_is_orig_mroute(vxlan_sg)) + return; + + /* Lookup all XG and SG entries with RPF-interface peerlink_rif */ + up = vxlan_sg->up; + if (!up) + return; + + pim_vxlan_up_cost_update(vxlan_sg->pim, up, + old_peerlink_rif); + + for (ALL_LIST_ELEMENTS_RO(up->sources, listnode, + child)) + pim_vxlan_up_cost_update(vxlan_sg->pim, child, + old_peerlink_rif); +} + +static void pim_vxlan_sg_peerlink_rif_update(struct hash_bucket *backet, + void *arg) +{ + pim_vxlan_orig_mr_iif_update(backet, NULL); + pim_vxlan_term_mr_cost_update(backet, arg); } static void pim_vxlan_set_peerlink_rif(struct pim_instance *pim, struct interface *ifp) { struct interface *old_iif; + struct interface *new_iif; + struct interface *old_oif; + struct interface *new_oif; if (pim->vxlan.peerlink_rif == ifp) return; @@ -878,26 +987,79 @@ static void pim_vxlan_set_peerlink_rif(struct pim_instance *pim, old_iif = pim->vxlan.peerlink_rif; if (PIM_DEBUG_VXLAN) zlog_debug("%s: vxlan peerlink_rif changed from %s to %s", - __PRETTY_FUNCTION__, old_iif ? old_iif->name : "-", - ifp ? ifp->name : "-"); + __func__, old_iif ? old_iif->name : "-", + ifp ? ifp->name : "-"); old_iif = pim_vxlan_orig_mr_iif_get(pim); + old_oif = pim_vxlan_orig_mr_oif_get(pim); pim->vxlan.peerlink_rif = ifp; - ifp = pim_vxlan_orig_mr_iif_get(pim); - if (old_iif == ifp) + + new_iif = pim_vxlan_orig_mr_iif_get(pim); + if (old_iif != new_iif) { + if (PIM_DEBUG_VXLAN) + zlog_debug("%s: vxlan orig iif changed from %s to %s", + __func__, old_iif ? old_iif->name : "-", + new_iif ? new_iif->name : "-"); + + /* add/del upstream entries for the existing vxlan SG when the + * interface becomes available + */ + if (pim->vxlan.sg_hash) + hash_iterate(pim->vxlan.sg_hash, + pim_vxlan_sg_peerlink_rif_update, + old_iif); + } + + new_oif = pim_vxlan_orig_mr_oif_get(pim); + if (old_oif != new_oif) { + if (PIM_DEBUG_VXLAN) + zlog_debug("%s: vxlan orig oif changed from %s to %s", + __func__, old_oif ? old_oif->name : "-", + new_oif ? new_oif->name : "-"); + if (pim->vxlan.sg_hash) + hash_iterate(pim->vxlan.sg_hash, + pim_vxlan_sg_peerlink_oif_update, + new_oif); + } +} + +static void pim_vxlan_term_mr_oif_update(struct hash_bucket *backet, void *arg) +{ + struct interface *ifp = (struct interface *)arg; + struct pim_vxlan_sg *vxlan_sg = (struct pim_vxlan_sg *)backet->data; + + if (pim_vxlan_is_orig_mroute(vxlan_sg)) + return; + + if (vxlan_sg->term_oif == ifp) return; if (PIM_DEBUG_VXLAN) - zlog_debug("%s: vxlan orig iif changed from %s to %s", - __PRETTY_FUNCTION__, old_iif ? old_iif->name : "-", + zlog_debug("vxlan SG %s term oif changed from %s to %s", + vxlan_sg->sg_str, + vxlan_sg->term_oif ? vxlan_sg->term_oif->name : "-", ifp ? ifp->name : "-"); - /* add/del upstream entries for the existing vxlan SG when the - * interface becomes available - */ + pim_vxlan_term_mr_del(vxlan_sg); + vxlan_sg->term_oif = ifp; + pim_vxlan_term_mr_add(vxlan_sg); +} + +static void pim_vxlan_term_oif_update(struct pim_instance *pim, + struct interface *ifp) +{ + if (pim->vxlan.term_if == ifp) + return; + + if (PIM_DEBUG_VXLAN) + zlog_debug("vxlan term oif changed from %s to %s", + pim->vxlan.term_if ? pim->vxlan.term_if->name : "-", + ifp ? ifp->name : "-"); + + pim->vxlan.term_if = ifp; if (pim->vxlan.sg_hash) hash_iterate(pim->vxlan.sg_hash, - pim_vxlan_orig_mr_iif_update, ifp); + pim_vxlan_term_mr_oif_update, ifp); } void pim_vxlan_add_vif(struct interface *ifp) @@ -914,6 +1076,9 @@ void pim_vxlan_add_vif(struct interface *ifp) if (vxlan_mlag.flags & PIM_VXLAN_MLAGF_ENABLED && (ifp == vxlan_mlag.peerlink_rif)) pim_vxlan_set_peerlink_rif(pim, ifp); + + if (pim->vxlan.term_if_cfg == ifp) + pim_vxlan_term_oif_update(pim, ifp); } void pim_vxlan_del_vif(struct interface *ifp) @@ -929,76 +1094,56 @@ void pim_vxlan_del_vif(struct interface *ifp) if (pim->vxlan.peerlink_rif == ifp) pim_vxlan_set_peerlink_rif(pim, NULL); -} - -static void pim_vxlan_term_mr_oif_update(struct hash_backet *backet, void *arg) -{ - struct interface *ifp = (struct interface *)arg; - struct pim_vxlan_sg *vxlan_sg = (struct pim_vxlan_sg *)backet->data; - if (pim_vxlan_is_orig_mroute(vxlan_sg)) - return; - - if (vxlan_sg->term_oif == ifp) - return; - - if (PIM_DEBUG_VXLAN) - zlog_debug("vxlan SG %s term oif changed from %s to %s", - vxlan_sg->sg_str, - vxlan_sg->term_oif ? vxlan_sg->term_oif->name : "-", - ifp ? ifp->name : "-"); - - pim_vxlan_term_mr_del(vxlan_sg); - vxlan_sg->term_oif = ifp; - pim_vxlan_term_mr_add(vxlan_sg); + if (pim->vxlan.term_if == ifp) + pim_vxlan_term_oif_update(pim, NULL); } +/* enable pim implicitly on the termination device add */ void pim_vxlan_add_term_dev(struct pim_instance *pim, struct interface *ifp) { struct pim_interface *pim_ifp; - if (pim->vxlan.term_if == ifp) + if (pim->vxlan.term_if_cfg == ifp) return; if (PIM_DEBUG_VXLAN) - zlog_debug("vxlan term oif changed from %s to %s", - pim->vxlan.term_if ? pim->vxlan.term_if->name : "-", - ifp->name); + zlog_debug("vxlan term oif cfg changed from %s to %s", + pim->vxlan.term_if_cfg ? + pim->vxlan.term_if_cfg->name : "-", + ifp->name); + + pim->vxlan.term_if_cfg = ifp; /* enable pim on the term ifp */ pim_ifp = (struct pim_interface *)ifp->info; if (pim_ifp) { PIM_IF_DO_PIM(pim_ifp->options); + /* ifp is already oper up; activate it as a term dev */ + if (pim_ifp->mroute_vif_index >= 0) + pim_vxlan_term_oif_update(pim, ifp); } else { - pim_ifp = pim_if_new(ifp, false /*igmp*/, true /*pim*/, - false /*pimreg*/, true /*vxlan_term*/); - /* ensure that pimreg existss before using the newly created + /* ensure that pimreg exists before using the newly created * vxlan termination device */ pim_if_create_pimreg(pim); + (void)pim_if_new(ifp, false /*igmp*/, true /*pim*/, + false /*pimreg*/, true /*vxlan_term*/); } - - pim->vxlan.term_if = ifp; - - if (pim->vxlan.sg_hash) - hash_iterate(pim_ifp->pim->vxlan.sg_hash, - pim_vxlan_term_mr_oif_update, ifp); } +/* disable pim implicitly, if needed, on the termination device deletion */ void pim_vxlan_del_term_dev(struct pim_instance *pim) { - struct interface *ifp = pim->vxlan.term_if; + struct interface *ifp = pim->vxlan.term_if_cfg; struct pim_interface *pim_ifp; if (PIM_DEBUG_VXLAN) - zlog_debug("vxlan term oif changed from %s to -", ifp->name); + zlog_debug("vxlan term oif cfg changed from %s to -", + ifp->name); - pim->vxlan.term_if = NULL; - - if (pim->vxlan.sg_hash) - hash_iterate(pim->vxlan.sg_hash, - pim_vxlan_term_mr_oif_update, NULL); + pim->vxlan.term_if_cfg = NULL; pim_ifp = (struct pim_interface *)ifp->info; if (pim_ifp) { @@ -1006,7 +1151,6 @@ void pim_vxlan_del_term_dev(struct pim_instance *pim) if (!PIM_IF_TEST_IGMP(pim_ifp->options)) pim_if_delete(ifp); } - } void pim_vxlan_init(struct pim_instance *pim) @@ -1022,8 +1166,14 @@ void pim_vxlan_init(struct pim_instance *pim) void pim_vxlan_exit(struct pim_instance *pim) { if (pim->vxlan.sg_hash) { - hash_clean(pim->vxlan.sg_hash, NULL); + hash_clean(pim->vxlan.sg_hash, + (void (*)(void *))pim_vxlan_sg_del_item); hash_free(pim->vxlan.sg_hash); pim->vxlan.sg_hash = NULL; } } + +void pim_vxlan_terminate(void) +{ + pim_vxlan_work_timer_setup(false); +} diff --git a/pimd/pim_vxlan.h b/pimd/pim_vxlan.h index c6507a474c..18f1b74175 100644 --- a/pimd/pim_vxlan.h +++ b/pimd/pim_vxlan.h @@ -66,17 +66,14 @@ struct pim_vxlan_sg { enum pim_vxlan_mlag_flags { PIM_VXLAN_MLAGF_NONE = 0, - PIM_VXLAN_MLAGF_ENABLED = (1 << 0) -}; - -enum pim_vxlan_mlag_role { - PIM_VXLAN_MLAG_ROLE_SECONDARY = 0, - PIM_VXLAN_MLAG_ROLE_PRIMARY + PIM_VXLAN_MLAGF_ENABLED = (1 << 0), + PIM_VXLAN_MLAGF_DO_REG = (1 << 1) }; struct pim_vxlan_mlag { enum pim_vxlan_mlag_flags flags; - enum pim_vxlan_mlag_role role; + /* XXX - remove this variable from here */ + int role; bool peer_state; /* routed interface setup on top of MLAG peerlink */ struct interface *peerlink_rif; @@ -122,6 +119,12 @@ static inline bool pim_vxlan_is_local_sip(struct pim_upstream *up) if_is_loopback_or_vrf(up->rpf.source_nexthop.interface); } +static inline bool pim_vxlan_is_term_dev_cfg(struct pim_instance *pim, + struct interface *ifp) +{ + return pim->vxlan.term_if_cfg == ifp; +} + extern struct pim_vxlan *pim_vxlan_p; extern struct pim_vxlan_sg *pim_vxlan_sg_find(struct pim_instance *pim, struct prefix_sg *sg); @@ -141,6 +144,10 @@ extern bool pim_vxlan_get_register_src(struct pim_instance *pim, extern void pim_vxlan_mlag_update(bool enable, bool peer_state, uint32_t role, struct interface *peerlink_rif, struct in_addr *reg_addr); -extern void pim_vxlan_config_write(struct vty *vty, char *spaces, int *writes); +extern bool pim_vxlan_do_mlag_reg(void); +extern void pim_vxlan_inherit_mlag_flags(struct pim_instance *pim, + struct pim_upstream *up, bool inherit); +/* Shutdown of PIM stop the thread */ +extern void pim_vxlan_terminate(void); #endif /* PIM_VXLAN_H */ diff --git a/pimd/pim_vxlan_instance.h b/pimd/pim_vxlan_instance.h index 3f99483fbe..5b35bcbeaa 100644 --- a/pimd/pim_vxlan_instance.h +++ b/pimd/pim_vxlan_instance.h @@ -36,6 +36,7 @@ struct pim_vxlan_instance { /* device used by the dataplane to terminate multicast encapsulated * vxlan traffic */ + struct interface *term_if_cfg; struct interface *term_if; }; diff --git a/pimd/pim_zebra.c b/pimd/pim_zebra.c index 06507b1f4c..e791500ede 100644 --- a/pimd/pim_zebra.c +++ b/pimd/pim_zebra.c @@ -75,9 +75,8 @@ static int pim_zebra_interface_vrf_update(ZAPI_CALLBACK_ARGS) return 0; if (PIM_DEBUG_ZEBRA) - zlog_debug("%s: %s updating from %u to %u", - __PRETTY_FUNCTION__, - ifp->name, vrf_id, new_vrf_id); + zlog_debug("%s: %s updating from %u to %u", __func__, ifp->name, + vrf_id, new_vrf_id); if_update_to_new_vrf(ifp, new_vrf_id); @@ -90,8 +89,8 @@ static void dump_if_address(struct interface *ifp) struct connected *ifc; struct listnode *node; - zlog_debug("%s %s: interface %s addresses:", __FILE__, - __PRETTY_FUNCTION__, ifp->name); + zlog_debug("%s %s: interface %s addresses:", __FILE__, __func__, + ifp->name); for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) { struct prefix *p = ifc->address; @@ -100,8 +99,7 @@ static void dump_if_address(struct interface *ifp) continue; zlog_debug("%s %s: interface %s address %s %s", __FILE__, - __PRETTY_FUNCTION__, ifp->name, - inet_ntoa(p->u.prefix4), + __func__, ifp->name, inet_ntoa(p->u.prefix4), CHECK_FLAG(ifc->flags, ZEBRA_IFA_SECONDARY) ? "secondary" : "primary"); @@ -135,8 +133,7 @@ static int pim_zebra_if_address_add(ZAPI_CALLBACK_ARGS) char buf[BUFSIZ]; prefix2str(p, buf, BUFSIZ); zlog_debug("%s: %s(%u) connected IP address %s flags %u %s", - __PRETTY_FUNCTION__, c->ifp->name, vrf_id, buf, - c->flags, + __func__, c->ifp->name, vrf_id, buf, c->flags, CHECK_FLAG(c->flags, ZEBRA_IFA_SECONDARY) ? "secondary" : "primary"); @@ -161,7 +158,7 @@ static int pim_zebra_if_address_add(ZAPI_CALLBACK_ARGS) zlog_warn( "%s: %s : forcing secondary flag on %s", - __PRETTY_FUNCTION__, c->ifp->name, buf); + __func__, c->ifp->name, buf); } SET_FLAG(c->flags, ZEBRA_IFA_SECONDARY); } @@ -218,8 +215,7 @@ static int pim_zebra_if_address_del(ZAPI_CALLBACK_ARGS) prefix2str(p, buf, BUFSIZ); zlog_debug( "%s: %s(%u) disconnected IP address %s flags %u %s", - __PRETTY_FUNCTION__, c->ifp->name, vrf_id, buf, - c->flags, + __func__, c->ifp->name, vrf_id, buf, c->flags, CHECK_FLAG(c->flags, ZEBRA_IFA_SECONDARY) ? "secondary" : "primary"); @@ -291,7 +287,7 @@ void pim_zebra_upstream_rpf_changed(struct pim_instance *pim, */ if (!up->channel_oil->installed) pim_upstream_mroute_add(up->channel_oil, - __PRETTY_FUNCTION__); + __func__); /* * RFC 4601: 4.5.7. Sending (S,G) @@ -329,8 +325,7 @@ void pim_zebra_upstream_rpf_changed(struct pim_instance *pim, pim_jp_agg_switch_interface(old, &up->rpf, up); if (!up->channel_oil->installed) - pim_upstream_mroute_add(up->channel_oil, - __PRETTY_FUNCTION__); + pim_upstream_mroute_add(up->channel_oil, __func__); } /* FIXME can join_desired actually be changed by pim_rpf_update() @@ -430,7 +425,7 @@ void sched_rpf_cache_refresh(struct pim_instance *pim) /* Start refresh timer */ if (PIM_DEBUG_ZEBRA) { - zlog_debug("%s: triggering %ld msec timer", __PRETTY_FUNCTION__, + zlog_debug("%s: triggering %ld msec timer", __func__, router->rpf_cache_refresh_delay_msec); } @@ -452,7 +447,7 @@ static void pim_zebra_connected(struct zclient *zclient) static void pim_zebra_capabilities(struct zclient_capabilities *cap) { - router->role = cap->role; + router->mlag_role = cap->role; } void pim_zebra_init(void) @@ -475,8 +470,7 @@ void pim_zebra_init(void) zclient_init(zclient, ZEBRA_ROUTE_PIM, 0, &pimd_privs); if (PIM_DEBUG_PIM_TRACE) { - zlog_notice("%s: zclient socket initialized", - __PRETTY_FUNCTION__); + zlog_notice("%s: zclient socket initialized", __func__); } zclient_lookup_new(); @@ -493,8 +487,7 @@ void igmp_anysource_forward_start(struct pim_instance *pim, source = source_new(group, src_addr); if (!source) { - zlog_warn("%s: Failure to create * source", - __PRETTY_FUNCTION__); + zlog_warn("%s: Failure to create * source", __func__); return; } @@ -547,7 +540,8 @@ static void igmp_source_forward_reevaluate_one(struct pim_instance *pim, "local membership add for %s as G is now ASM", pim_str_sg_dump(&sg)); pim_ifchannel_local_membership_add( - group->group_igmp_sock->interface, &sg); + group->group_igmp_sock->interface, &sg, + false /*is_vxlan*/); } } } @@ -603,8 +597,8 @@ void igmp_source_forward_start(struct pim_instance *pim, if (PIM_DEBUG_IGMP_TRACE) { zlog_debug( - "%s: (S,G)=%s igmp_sock=%d oif=%s fwd=%d", - __PRETTY_FUNCTION__, pim_str_sg_dump(&sg), + "%s: (S,G)=%s igmp_sock=%d oif=%s fwd=%d", __func__, + pim_str_sg_dump(&sg), source->source_group->group_igmp_sock->fd, source->source_group->group_igmp_sock->interface->name, IGMP_SOURCE_TEST_FORWARDING(source->source_flags)); @@ -620,11 +614,10 @@ void igmp_source_forward_start(struct pim_instance *pim, pim_oif = group->group_igmp_sock->interface->info; if (!pim_oif) { if (PIM_DEBUG_IGMP_TRACE) { - zlog_debug( - "%s: multicast not enabled on oif=%s ?", - __PRETTY_FUNCTION__, + zlog_debug("%s: multicast not enabled on oif=%s ?", + __func__, source->source_group->group_igmp_sock - ->interface->name); + ->interface->name); } return; } @@ -638,8 +631,8 @@ void igmp_source_forward_start(struct pim_instance *pim, if (!pim_rp_set_upstream_addr(pim, &vif_source, source->source_addr, sg.grp)) { /*Create a dummy channel oil */ - source->source_channel_oil = pim_channel_oil_add( - pim, &sg, __PRETTY_FUNCTION__); + source->source_channel_oil = + pim_channel_oil_add(pim, &sg, __func__); } else { @@ -671,10 +664,10 @@ void igmp_source_forward_start(struct pim_instance *pim, pim_inet4_dump("<source?>", vif_source, buf2, sizeof(buf2)); - zlog_debug("%s: NHT %s vif_source %s vif_index:%d ", - __PRETTY_FUNCTION__, - pim_str_sg_dump(&sg), - buf2, input_iface_vif_index); + zlog_debug( + "%s: NHT %s vif_source %s vif_index:%d ", + __func__, pim_str_sg_dump(&sg), buf2, + input_iface_vif_index); } if (input_iface_vif_index < 1) { @@ -684,14 +677,11 @@ void igmp_source_forward_start(struct pim_instance *pim, source->source_addr, source_str, sizeof(source_str)); zlog_debug( - "%s %s: could not find input interface for source %s", - __FILE__, __PRETTY_FUNCTION__, - source_str); + "%s %s: could not find input interface for source %s", + __FILE__, __func__, source_str); } source->source_channel_oil = - pim_channel_oil_add( - pim, &sg, - __PRETTY_FUNCTION__); + pim_channel_oil_add(pim, &sg, __func__); } else { @@ -709,30 +699,28 @@ void igmp_source_forward_start(struct pim_instance *pim, */ if (PIM_DEBUG_IGMP_TRACE) { zlog_debug( - "%s: ignoring request for looped MFC entry (S,G)=%s: igmp_sock=%d oif=%s vif_index=%d", - __PRETTY_FUNCTION__, - pim_str_sg_dump(&sg), - source->source_group - ->group_igmp_sock->fd, - source->source_group - ->group_igmp_sock - ->interface->name, - input_iface_vif_index); + "%s: ignoring request for looped MFC entry (S,G)=%s: igmp_sock=%d oif=%s vif_index=%d", + __func__, + pim_str_sg_dump(&sg), + source->source_group + ->group_igmp_sock + ->fd, + source->source_group + ->group_igmp_sock + ->interface->name, + input_iface_vif_index); } return; } source->source_channel_oil = - pim_channel_oil_add( - pim, &sg, - __PRETTY_FUNCTION__); + pim_channel_oil_add(pim, &sg, __func__); if (!source->source_channel_oil) { if (PIM_DEBUG_IGMP_TRACE) { zlog_debug( - "%s %s: could not create OIL for channel (S,G)=%s", - __FILE__, - __PRETTY_FUNCTION__, - pim_str_sg_dump(&sg)); + "%s %s: could not create OIL for channel (S,G)=%s", + __FILE__, __func__, + pim_str_sg_dump(&sg)); } return; } @@ -753,10 +741,10 @@ void igmp_source_forward_start(struct pim_instance *pim, } } else { if (PIM_DEBUG_IGMP_TRACE) - zlog_debug("%s: %s was received on %s interface but we are not DR for that interface", - __PRETTY_FUNCTION__, - pim_str_sg_dump(&sg), - group->group_igmp_sock->interface->name); + zlog_debug( + "%s: %s was received on %s interface but we are not DR for that interface", + __func__, pim_str_sg_dump(&sg), + group->group_igmp_sock->interface->name); return; } @@ -765,10 +753,11 @@ void igmp_source_forward_start(struct pim_instance *pim, per-interface (S,G) state. */ if (!pim_ifchannel_local_membership_add( - group->group_igmp_sock->interface, &sg)) { + group->group_igmp_sock->interface, &sg, + false /*is_vxlan*/)) { if (PIM_DEBUG_MROUTE) zlog_warn("%s: Failure to add local membership for %s", - __PRETTY_FUNCTION__, pim_str_sg_dump(&sg)); + __func__, pim_str_sg_dump(&sg)); pim_channel_del_oif(source->source_channel_oil, group->group_igmp_sock->interface, @@ -795,8 +784,8 @@ void igmp_source_forward_stop(struct igmp_source *source) if (PIM_DEBUG_IGMP_TRACE) { zlog_debug( - "%s: (S,G)=%s igmp_sock=%d oif=%s fwd=%d", - __PRETTY_FUNCTION__, pim_str_sg_dump(&sg), + "%s: (S,G)=%s igmp_sock=%d oif=%s fwd=%d", __func__, + pim_str_sg_dump(&sg), source->source_group->group_igmp_sock->fd, source->source_group->group_igmp_sock->interface->name, IGMP_SOURCE_TEST_FORWARDING(source->source_flags)); @@ -859,7 +848,7 @@ void pim_forward_start(struct pim_ifchannel *ch) sizeof(group_str)); pim_inet4_dump("<upstream?>", up->upstream_addr, upstream_str, sizeof(upstream_str)); - zlog_debug("%s: (S,G)=(%s,%s) oif=%s (%s)", __PRETTY_FUNCTION__, + zlog_debug("%s: (S,G)=(%s,%s) oif=%s (%s)", __func__, source_str, group_str, ch->interface->name, inet_ntoa(up->upstream_addr)); } @@ -877,7 +866,7 @@ void pim_forward_stop(struct pim_ifchannel *ch, bool install_it) if (PIM_DEBUG_PIM_TRACE) { zlog_debug("%s: (S,G)=%s oif=%s install_it: %d installed: %d", - __PRETTY_FUNCTION__, ch->sg_str, ch->interface->name, + __func__, ch->sg_str, ch->interface->name, install_it, up->channel_oil->installed); } @@ -893,7 +882,7 @@ void pim_forward_stop(struct pim_ifchannel *ch, bool install_it) PIM_OIF_FLAG_PROTO_PIM, __func__); if (install_it && !up->channel_oil->installed) - pim_upstream_mroute_add(up->channel_oil, __PRETTY_FUNCTION__); + pim_upstream_mroute_add(up->channel_oil, __func__); } void pim_zebra_zclient_update(struct vty *vty) diff --git a/pimd/pim_zlookup.c b/pimd/pim_zlookup.c index 0454c0d69e..fc486f4998 100644 --- a/pimd/pim_zlookup.c +++ b/pimd/pim_zlookup.c @@ -56,7 +56,7 @@ static int zclient_lookup_connect(struct thread *t) if (zclient_socket_connect(zlookup) < 0) { ++zlookup->fail; zlog_warn("%s: failure connecting zclient socket: failures=%d", - __PRETTY_FUNCTION__, zlookup->fail); + __func__, zlookup->fail); } else { zlookup->fail = 0; /* reset counter on connection */ } @@ -79,7 +79,7 @@ static void zclient_lookup_sched(struct zclient *zlookup, int delay) &zlookup->t_connect); zlog_notice("%s: zclient lookup connection scheduled for %d seconds", - __PRETTY_FUNCTION__, delay); + __func__, delay); } /* Schedule connection for now. */ @@ -89,7 +89,7 @@ static void zclient_lookup_sched_now(struct zclient *zlookup) &zlookup->t_connect); zlog_notice("%s: zclient lookup immediate connection scheduled", - __PRETTY_FUNCTION__); + __func__); } /* Schedule reconnection, if needed. */ @@ -128,7 +128,7 @@ void zclient_lookup_new(void) zlookup = zclient_new(router->master, &zclient_options_default); if (!zlookup) { flog_err(EC_LIB_ZAPI_SOCKET, "%s: zclient_new() failure", - __PRETTY_FUNCTION__); + __func__); return; } @@ -138,8 +138,7 @@ void zclient_lookup_new(void) zclient_lookup_sched_now(zlookup); - zlog_notice("%s: zclient lookup socket initialized", - __PRETTY_FUNCTION__); + zlog_notice("%s: zclient lookup socket initialized", __func__); } static int zclient_read_nexthop(struct pim_instance *pim, @@ -163,7 +162,7 @@ static int zclient_read_nexthop(struct pim_instance *pim, if (PIM_DEBUG_PIM_NHT_DETAIL) { char addr_str[INET_ADDRSTRLEN]; pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); - zlog_debug("%s: addr=%s(%s)", __PRETTY_FUNCTION__, addr_str, + zlog_debug("%s: addr=%s(%s)", __func__, addr_str, pim->vrf->name); } @@ -175,8 +174,7 @@ static int zclient_read_nexthop(struct pim_instance *pim, &version, &vrf_id, &command); if (err < 0) { flog_err(EC_LIB_ZAPI_MISSMATCH, - "%s: zclient_read_header() failed", - __PRETTY_FUNCTION__); + "%s: zclient_read_header() failed", __func__); zclient_lookup_failed(zlookup); return -1; } @@ -198,8 +196,7 @@ static int zclient_read_nexthop(struct pim_instance *pim, pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); pim_inet4_dump("<raddr?>", raddr, raddr_str, sizeof(raddr_str)); zlog_warn("%s: address mismatch: addr=%s(%s) raddr=%s", - __PRETTY_FUNCTION__, addr_str, pim->vrf->name, - raddr_str); + __func__, addr_str, pim->vrf->name, raddr_str); /* warning only */ } @@ -228,8 +225,8 @@ static int zclient_read_nexthop(struct pim_instance *pim, sizeof(addr_str)); zlog_warn( "%s: found too many nexthop ifindexes (%d > %d) for address %s(%s)", - __PRETTY_FUNCTION__, (num_ifindex + 1), - tab_size, addr_str, pim->vrf->name); + __func__, (num_ifindex + 1), tab_size, addr_str, + pim->vrf->name); return num_ifindex; } nexthop_tab[num_ifindex].protocol_distance = distance; @@ -304,8 +301,8 @@ static int zclient_read_nexthop(struct pim_instance *pim, sizeof(addr_str)); zlog_warn( "%s: found non-ifindex nexthop type=%d for address %s(%s)", - __PRETTY_FUNCTION__, nexthop_type, - addr_str, pim->vrf->name); + __func__, nexthop_type, addr_str, + pim->vrf->name); } break; } @@ -324,7 +321,7 @@ static int zclient_lookup_nexthop_once(struct pim_instance *pim, if (PIM_DEBUG_PIM_NHT_DETAIL) { char addr_str[INET_ADDRSTRLEN]; pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); - zlog_debug("%s: addr=%s(%s)", __PRETTY_FUNCTION__, addr_str, + zlog_debug("%s: addr=%s(%s)", __func__, addr_str, pim->vrf->name); } @@ -332,7 +329,7 @@ static int zclient_lookup_nexthop_once(struct pim_instance *pim, if (zlookup->sock < 0) { flog_err(EC_LIB_ZAPI_SOCKET, "%s: zclient lookup socket is not connected", - __PRETTY_FUNCTION__); + __func__); zclient_lookup_failed(zlookup); return -1; } @@ -340,7 +337,7 @@ static int zclient_lookup_nexthop_once(struct pim_instance *pim, if (pim->vrf->vrf_id == VRF_UNKNOWN) { zlog_notice( "%s: VRF: %s does not fully exist yet, delaying lookup", - __PRETTY_FUNCTION__, pim->vrf->name); + __func__, pim->vrf->name); return -1; } @@ -356,14 +353,14 @@ static int zclient_lookup_nexthop_once(struct pim_instance *pim, flog_err( EC_LIB_SOCKET, "%s: writen() failure: %d writing to zclient lookup socket", - __PRETTY_FUNCTION__, errno); + __func__, errno); zclient_lookup_failed(zlookup); return -2; } if (ret == 0) { flog_err_sys(EC_LIB_SOCKET, "%s: connection closed on zclient lookup socket", - __PRETTY_FUNCTION__); + __func__); zclient_lookup_failed(zlookup); return -3; } @@ -410,8 +407,8 @@ int zclient_lookup_nexthop(struct pim_instance *pim, sizeof(addr_str)); zlog_debug( "%s: lookup=%d/%d: could not find nexthop ifindex for address %s(%s)", - __PRETTY_FUNCTION__, lookup, max_lookup, - addr_str, pim->vrf->name); + __func__, lookup, max_lookup, addr_str, + pim->vrf->name); } return -1; } @@ -448,9 +445,9 @@ int zclient_lookup_nexthop(struct pim_instance *pim, sizeof(addr_str)); zlog_debug( "%s: lookup=%d/%d: found non-recursive ifindex=%d for address %s(%s) dist=%d met=%d", - __PRETTY_FUNCTION__, lookup, - max_lookup, first_ifindex, - addr_str, pim->vrf->name, + __func__, lookup, max_lookup, + first_ifindex, addr_str, + pim->vrf->name, nexthop_tab[0] .protocol_distance, nexthop_tab[0].route_metric); @@ -477,8 +474,8 @@ int zclient_lookup_nexthop(struct pim_instance *pim, sizeof(nexthop_str)); zlog_debug( "%s: lookup=%d/%d: zebra returned recursive nexthop %s for address %s(%s) dist=%d met=%d", - __PRETTY_FUNCTION__, lookup, max_lookup, - nexthop_str, addr_str, pim->vrf->name, + __func__, lookup, max_lookup, nexthop_str, + addr_str, pim->vrf->name, nexthop_tab[0].protocol_distance, nexthop_tab[0].route_metric); } @@ -493,8 +490,7 @@ int zclient_lookup_nexthop(struct pim_instance *pim, pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); zlog_warn( "%s: lookup=%d/%d: failure searching recursive nexthop ifindex for address %s(%s)", - __PRETTY_FUNCTION__, lookup, max_lookup, addr_str, - pim->vrf->name); + __func__, lookup, max_lookup, addr_str, pim->vrf->name); } return -2; @@ -548,7 +544,7 @@ int pim_zlookup_sg_statistics(struct channel_oil *c_oil) flog_err( EC_LIB_SOCKET, "%s: writen() failure: %d writing to zclient lookup socket", - __PRETTY_FUNCTION__, errno); + __func__, errno); return -1; } @@ -566,8 +562,7 @@ int pim_zlookup_sg_statistics(struct channel_oil *c_oil) &version, &vrf_id, &command); if (err < 0) { flog_err(EC_LIB_ZAPI_MISSMATCH, - "%s: zclient_read_header() failed", - __PRETTY_FUNCTION__); + "%s: zclient_read_header() failed", __func__); zclient_lookup_failed(zlookup); return -1; } @@ -585,7 +580,7 @@ int pim_zlookup_sg_statistics(struct channel_oil *c_oil) flog_err( EC_LIB_ZAPI_MISSMATCH, "%s: Received wrong %s(%s) information requested", - __PRETTY_FUNCTION__, pim_str_sg_dump(&more), + __func__, pim_str_sg_dump(&more), c_oil->pim->vrf->name); } zclient_lookup_failed(zlookup); diff --git a/pimd/pim_zpthread.c b/pimd/pim_zpthread.c new file mode 100644 index 0000000000..518b024749 --- /dev/null +++ b/pimd/pim_zpthread.c @@ -0,0 +1,225 @@ +/* + * PIM for Quagga + * Copyright (C) 2008 Everton da Silva Marques + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; see the file COPYING; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <zebra.h> +#include <lib/log.h> +#include <lib/lib_errors.h> + +#include "pimd.h" +#include "pim_mlag.h" +#include "pim_zebra.h" + +extern struct zclient *zclient; + +#define PIM_MLAG_POST_LIMIT 100 + +int32_t mlag_bulk_cnt; + +static void pim_mlag_zebra_fill_header(enum mlag_msg_type msg_type) +{ + uint32_t fill_msg_type = msg_type; + uint16_t data_len; + uint16_t msg_cnt = 1; + + if (msg_type == MLAG_MSG_NONE) + return; + + switch (msg_type) { + case MLAG_REGISTER: + case MLAG_DEREGISTER: + data_len = sizeof(struct mlag_msg); + break; + case MLAG_MROUTE_ADD: + data_len = sizeof(struct mlag_mroute_add); + fill_msg_type = MLAG_MROUTE_ADD_BULK; + break; + case MLAG_MROUTE_DEL: + data_len = sizeof(struct mlag_mroute_del); + fill_msg_type = MLAG_MROUTE_DEL_BULK; + break; + default: + data_len = 0; + break; + } + + stream_reset(router->mlag_stream); + /* ADD Hedaer */ + stream_putl(router->mlag_stream, fill_msg_type); + /* + * In case of Bulk actual size & msg_cnt will be updated + * just before writing onto zebra + */ + stream_putw(router->mlag_stream, data_len); + stream_putw(router->mlag_stream, msg_cnt); + + if (PIM_DEBUG_MLAG) + zlog_debug(":%s: msg_type: %d/%d len %d", + __func__, msg_type, fill_msg_type, data_len); +} + +static void pim_mlag_zebra_flush_buffer(void) +{ + uint32_t msg_type; + + /* Stream had bulk messages update the Hedaer */ + if (mlag_bulk_cnt > 1) { + /* + * No need to reset the pointer, below api reads from data[0] + */ + STREAM_GETL(router->mlag_stream, msg_type); + if (msg_type == MLAG_MROUTE_ADD_BULK) { + stream_putw_at( + router->mlag_stream, 4, + (mlag_bulk_cnt * sizeof(struct mlag_mroute_add))); + stream_putw_at(router->mlag_stream, 6, mlag_bulk_cnt); + } else if (msg_type == MLAG_MROUTE_DEL_BULK) { + stream_putw_at( + router->mlag_stream, 4, + (mlag_bulk_cnt * sizeof(struct mlag_mroute_del))); + stream_putw_at(router->mlag_stream, 6, mlag_bulk_cnt); + } else { + flog_err(EC_LIB_ZAPI_ENCODE, + "unknown bulk message type %d bulk_count %d", + msg_type, mlag_bulk_cnt); + stream_reset(router->mlag_stream); + mlag_bulk_cnt = 0; + return; + } + } + + zclient_send_mlag_data(zclient, router->mlag_stream); +stream_failure: + stream_reset(router->mlag_stream); + mlag_bulk_cnt = 0; +} + +/* + * Only ROUTE add & Delete will be bulked. + * Buffer will be flushed, when + * 1) there were no messages in the queue + * 2) Curr_msg_type != prev_msg_type + */ + +static void pim_mlag_zebra_check_for_buffer_flush(uint32_t curr_msg_type, + uint32_t prev_msg_type) +{ + /* First Message, keep bulking */ + if (prev_msg_type == MLAG_MSG_NONE) { + mlag_bulk_cnt = 1; + return; + } + + /*msg type is route add & delete, keep bulking */ + if (curr_msg_type == prev_msg_type + && (curr_msg_type == MLAG_MROUTE_ADD + || curr_msg_type == MLAG_MROUTE_DEL)) { + mlag_bulk_cnt++; + return; + } + + pim_mlag_zebra_flush_buffer(); +} + +/* + * Thsi thread reads the clients data from the Gloabl queue and encodes with + * protobuf and pass on to the MLAG socket. + */ +static int pim_mlag_zthread_handler(struct thread *event) +{ + struct stream *read_s; + uint32_t wr_count = 0; + uint32_t prev_msg_type = MLAG_MSG_NONE; + uint32_t curr_msg_type = MLAG_MSG_NONE; + + router->zpthread_mlag_write = NULL; + wr_count = stream_fifo_count_safe(router->mlag_fifo); + + if (PIM_DEBUG_MLAG) + zlog_debug(":%s: Processing MLAG write, %d messages in queue", + __func__, wr_count); + + if (wr_count == 0) + return 0; + + for (wr_count = 0; wr_count < PIM_MLAG_POST_LIMIT; wr_count++) { + /* FIFO is empty,wait for teh message to be add */ + if (stream_fifo_count_safe(router->mlag_fifo) == 0) + break; + + read_s = stream_fifo_pop_safe(router->mlag_fifo); + if (!read_s) { + zlog_debug(":%s: Got a NULL Messages, some thing wrong", + __func__); + break; + } + STREAM_GETL(read_s, curr_msg_type); + /* + * Check for Buffer Overflow, + * MLAG Can't process more than 'PIM_MLAG_BUF_LIMIT' bytes + */ + if (router->mlag_stream->endp + read_s->endp + ZEBRA_HEADER_SIZE + > MLAG_BUF_LIMIT) + pim_mlag_zebra_flush_buffer(); + + pim_mlag_zebra_check_for_buffer_flush(curr_msg_type, + prev_msg_type); + + /* + * First message to Buffer, fill the Header + */ + if (router->mlag_stream->endp == 0) + pim_mlag_zebra_fill_header(curr_msg_type); + + /* + * add the data now + */ + stream_put(router->mlag_stream, read_s->data + read_s->getp, + read_s->endp - read_s->getp); + + stream_free(read_s); + prev_msg_type = curr_msg_type; + } + +stream_failure: + /* + * we are here , because + * 1. Queue might be empty + * 2. we crossed the max Q Read limit + * In any acse flush the buffer towards zebra + */ + pim_mlag_zebra_flush_buffer(); + + if (wr_count >= PIM_MLAG_POST_LIMIT) + pim_mlag_signal_zpthread(); + + return 0; +} + + +int pim_mlag_signal_zpthread(void) +{ + if (router->master) { + if (PIM_DEBUG_MLAG) + zlog_debug(":%s: Scheduling PIM MLAG write Thread", + __func__); + thread_add_event(router->master, pim_mlag_zthread_handler, NULL, + 0, &router->zpthread_mlag_write); + } + return (0); +} diff --git a/pimd/pimd.c b/pimd/pimd.c index 889a83a136..5ccbac32f2 100644 --- a/pimd/pimd.c +++ b/pimd/pimd.c @@ -39,6 +39,7 @@ #include "pim_static.h" #include "pim_rp.h" #include "pim_ssm.h" +#include "pim_vxlan.h" #include "pim_zlookup.h" #include "pim_zebra.h" @@ -50,6 +51,7 @@ const char *const PIM_ALL_IGMP_ROUTERS = MCAST_ALL_IGMP_ROUTERS; DEFINE_MTYPE_STATIC(PIMD, ROUTER, "PIM Router information"); struct pim_router *router = NULL; +struct in_addr qpim_all_pim_routers_addr; void pim_prefix_list_update(struct prefix_list *plist) { @@ -101,6 +103,8 @@ void pim_router_init(void) router->packet_process = PIM_DEFAULT_PACKET_PROCESS; router->register_probe_time = PIM_REGISTER_PROBE_TIME_DEFAULT; router->vrf_id = VRF_DEFAULT; + router->pim_mlag_intf_cnt = 0; + router->connected_to_mlag = false; } void pim_router_terminate(void) @@ -114,8 +118,8 @@ void pim_init(void) flog_err( EC_LIB_SOCKET, "%s %s: could not solve %s to group address: errno=%d: %s", - __FILE__, __PRETTY_FUNCTION__, PIM_ALL_PIM_ROUTERS, - errno, safe_strerror(errno)); + __FILE__, __func__, PIM_ALL_PIM_ROUTERS, errno, + safe_strerror(errno)); zassert(0); return; } @@ -132,6 +136,7 @@ void pim_terminate(void) prefix_list_delete_hook(NULL); prefix_list_reset(); + pim_vxlan_terminate(); pim_vrf_terminate(); zclient = pim_zebra_zclient_get(); diff --git a/pimd/pimd.h b/pimd/pimd.h index 70d2766220..88e692b50d 100644 --- a/pimd/pimd.h +++ b/pimd/pimd.h @@ -131,14 +131,14 @@ #define PIM_UPDATE_SOURCE_DUP -10 #define PIM_GROUP_BAD_ADDR_MASK_COMBO -11 -const char *const PIM_ALL_SYSTEMS; -const char *const PIM_ALL_ROUTERS; -const char *const PIM_ALL_PIM_ROUTERS; -const char *const PIM_ALL_IGMP_ROUTERS; +extern const char *const PIM_ALL_SYSTEMS; +extern const char *const PIM_ALL_ROUTERS; +extern const char *const PIM_ALL_PIM_ROUTERS; +extern const char *const PIM_ALL_IGMP_ROUTERS; extern struct pim_router *router; extern struct zebra_privs_t pimd_privs; -struct in_addr qpim_all_pim_routers_addr; +extern struct in_addr qpim_all_pim_routers_addr; extern uint8_t qpim_ecmp_enable; extern uint8_t qpim_ecmp_rebalance_enable; diff --git a/pimd/subdir.am b/pimd/subdir.am index b5d135d032..0e30590079 100644 --- a/pimd/subdir.am +++ b/pimd/subdir.am @@ -34,6 +34,7 @@ pimd_libpim_a_SOURCES = \ pimd/pim_jp_agg.c \ pimd/pim_macro.c \ pimd/pim_memory.c \ + pimd/pim_mlag.c \ pimd/pim_mroute.c \ pimd/pim_msdp.c \ pimd/pim_msdp_packet.c \ @@ -62,7 +63,7 @@ pimd_libpim_a_SOURCES = \ pimd/pim_zebra.c \ pimd/pim_zlookup.c \ pimd/pim_vxlan.c \ - pimd/pim_mlag.c \ + pimd/pim_zpthread.c \ pimd/pimd.c \ # end @@ -88,6 +89,7 @@ noinst_HEADERS += \ pimd/pim_jp_agg.h \ pimd/pim_macro.h \ pimd/pim_memory.h \ + pimd/pim_mlag.h \ pimd/pim_mroute.h \ pimd/pim_msdp.h \ pimd/pim_msdp_packet.h \ @@ -115,7 +117,6 @@ noinst_HEADERS += \ pimd/pim_zebra.h \ pimd/pim_zlookup.h \ pimd/pim_vxlan.h \ - pimd/pim_mlag.h \ pimd/pim_vxlan_instance.h \ pimd/pimd.h \ pimd/mtracebis_netlink.h \ diff --git a/ripd/rip_interface.c b/ripd/rip_interface.c index d07cc894a5..c05d776eb1 100644 --- a/ripd/rip_interface.c +++ b/ripd/rip_interface.c @@ -216,7 +216,7 @@ rip_request_neighbor (struct in_addr addr) { struct sockaddr_in to; - memset (&to, 0, sizeof (struct sockaddr_in)); + memset (&to, 0, sizeof(struct sockaddr_in)); to.sin_port = htons (RIP_PORT_DEFAULT); to.sin_addr = addr; @@ -351,11 +351,14 @@ static int rip_ifp_down(struct interface *ifp) rip_interface_sync(ifp); rip_if_down(ifp); - if (IS_RIP_DEBUG_ZEBRA) + if (IS_RIP_DEBUG_ZEBRA) { + struct vrf *vrf = vrf_lookup_by_id(ifp->vrf_id); + zlog_debug( - "interface %s vrf %u index %d flags %llx metric %d mtu %d is down", - ifp->name, ifp->vrf_id, ifp->ifindex, + "interface %s vrf %s(%u) index %d flags %llx metric %d mtu %d is down", + ifp->name, VRF_LOGNAME(vrf), ifp->vrf_id, ifp->ifindex, (unsigned long long)ifp->flags, ifp->metric, ifp->mtu); + } return 0; } @@ -363,11 +366,14 @@ static int rip_ifp_down(struct interface *ifp) /* Inteface link up message processing */ static int rip_ifp_up(struct interface *ifp) { - if (IS_RIP_DEBUG_ZEBRA) + if (IS_RIP_DEBUG_ZEBRA) { + struct vrf *vrf = vrf_lookup_by_id(ifp->vrf_id); + zlog_debug( - "interface %s vrf %u index %d flags %#llx metric %d mtu %d is up", - ifp->name, ifp->vrf_id, ifp->ifindex, + "interface %s vrf %s(%u) index %d flags %#llx metric %d mtu %d is up", + ifp->name, VRF_LOGNAME(vrf), ifp->vrf_id, ifp->ifindex, (unsigned long long)ifp->flags, ifp->metric, ifp->mtu); + } rip_interface_sync(ifp); @@ -388,11 +394,13 @@ static int rip_ifp_create(struct interface *ifp) { rip_interface_sync(ifp); - if (IS_RIP_DEBUG_ZEBRA) + if (IS_RIP_DEBUG_ZEBRA) { + struct vrf *vrf = vrf_lookup_by_id(ifp->vrf_id); zlog_debug( - "interface add %s vrf %u index %d flags %#llx metric %d mtu %d", - ifp->name, ifp->vrf_id, ifp->ifindex, + "interface add %s vrf %s(%u) index %d flags %#llx metric %d mtu %d", + ifp->name, VRF_LOGNAME(vrf), ifp->vrf_id, ifp->ifindex, (unsigned long long)ifp->flags, ifp->metric, ifp->mtu); + } /* Check if this interface is RIP enabled or not.*/ rip_enable_apply(ifp); @@ -413,14 +421,16 @@ static int rip_ifp_create(struct interface *ifp) static int rip_ifp_destroy(struct interface *ifp) { + struct vrf *vrf = vrf_lookup_by_id(ifp->vrf_id); + rip_interface_sync(ifp); if (if_is_up(ifp)) { rip_if_down(ifp); } zlog_info( - "interface delete %s vrf %u index %d flags %#llx metric %d mtu %d", - ifp->name, ifp->vrf_id, ifp->ifindex, + "interface delete %s vrf %s(%u) index %d flags %#llx metric %d mtu %d", + ifp->name, VRF_LOGNAME(vrf), ifp->vrf_id, ifp->ifindex, (unsigned long long)ifp->flags, ifp->metric, ifp->mtu); return 0; @@ -437,9 +447,14 @@ int rip_interface_vrf_update(ZAPI_CALLBACK_ARGS) if (!ifp) return 0; - if (IS_RIP_DEBUG_ZEBRA) - zlog_debug("interface %s VRF change vrf_id %u new vrf id %u", - ifp->name, vrf_id, new_vrf_id); + if (IS_RIP_DEBUG_ZEBRA) { + struct vrf *vrf = vrf_lookup_by_id(vrf_id); + struct vrf *nvrf = vrf_lookup_by_id(new_vrf_id); + + zlog_debug("interface %s VRF change vrf %s(%u) new vrf %s(%u)", + ifp->name, VRF_LOGNAME(vrf), vrf_id, + VRF_LOGNAME(nvrf), new_vrf_id); + } if_update_to_new_vrf(ifp, new_vrf_id); rip_interface_sync(ifp); diff --git a/ripd/rip_peer.c b/ripd/rip_peer.c index 4ad7309c41..77c73ab398 100644 --- a/ripd/rip_peer.c +++ b/ripd/rip_peer.c @@ -131,7 +131,6 @@ void rip_peer_bad_packet(struct rip *rip, struct sockaddr_in *from) static char *rip_peer_uptime(struct rip_peer *peer, char *buf, size_t len) { time_t uptime; - struct tm *tm; /* If there is no connection has been done before print `never'. */ if (peer->uptime == 0) { @@ -142,17 +141,9 @@ static char *rip_peer_uptime(struct rip_peer *peer, char *buf, size_t len) /* Get current time. */ uptime = time(NULL); uptime -= peer->uptime; - tm = gmtime(&uptime); - - if (uptime < ONE_DAY_SECOND) - snprintf(buf, len, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, - tm->tm_sec); - else if (uptime < ONE_WEEK_SECOND) - snprintf(buf, len, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour, - tm->tm_min); - else - snprintf(buf, len, "%02dw%dd%02dh", tm->tm_yday / 7, - tm->tm_yday - ((tm->tm_yday / 7) * 7), tm->tm_hour); + + frrtime_to_interval(uptime, buf, len); + return buf; } diff --git a/ripd/rip_routemap.c b/ripd/rip_routemap.c index 102b64df6b..77c2db8ceb 100644 --- a/ripd/rip_routemap.c +++ b/ripd/rip_routemap.c @@ -468,7 +468,7 @@ static void *route_set_metric_compile(const char *arg) if (metric > RIP_METRIC_INFINITY) { zlog_info( "%s: Metric specified: %ld is greater than RIP_METRIC_INFINITY, using INFINITY instead", - __PRETTY_FUNCTION__, metric); + __func__, metric); mod->metric = RIP_METRIC_INFINITY; } else mod->metric = metric; diff --git a/ripd/rip_snmp.c b/ripd/rip_snmp.c index 39e07f3c2e..be222c7a5f 100644 --- a/ripd/rip_snmp.c +++ b/ripd/rip_snmp.c @@ -553,7 +553,7 @@ static uint8_t *rip2PeerTable(struct variable *v, oid name[], size_t *length, * - don't support this variable, at all * Currently, we do the latter... */ - *val_len = sizeof (time_t); + *val_len = sizeof(time_t); uptime = peer->uptime; /* now - snmp_agent_startup - peer->uptime */ return (uint8_t *) &uptime; #else diff --git a/ripd/ripd.c b/ripd/ripd.c index 5ccefac178..f092da847d 100644 --- a/ripd/ripd.c +++ b/ripd/ripd.c @@ -104,7 +104,7 @@ static int sockopt_broadcast(int sock) int on = 1; ret = setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (char *)&on, - sizeof on); + sizeof(on)); if (ret < 0) { zlog_warn("can't set sockopt SO_BROADCAST to socket %d", sock); return -1; @@ -3020,20 +3020,20 @@ void rip_ecmp_disable(struct rip *rip) static void rip_vty_out_uptime(struct vty *vty, struct rip_info *rinfo) { time_t clock; - struct tm *tm; + struct tm tm; #define TIME_BUF 25 char timebuf[TIME_BUF]; struct thread *thread; if ((thread = rinfo->t_timeout) != NULL) { clock = thread_timer_remain_second(thread); - tm = gmtime(&clock); - strftime(timebuf, TIME_BUF, "%M:%S", tm); + gmtime_r(&clock, &tm); + strftime(timebuf, TIME_BUF, "%M:%S", &tm); vty_out(vty, "%5s", timebuf); } else if ((thread = rinfo->t_garbage_collect) != NULL) { clock = thread_timer_remain_second(thread); - tm = gmtime(&clock); - strftime(timebuf, TIME_BUF, "%M:%S", tm); + gmtime_r(&clock, &tm); + strftime(timebuf, TIME_BUF, "%M:%S", &tm); vty_out(vty, "%5s", timebuf); } } diff --git a/ripngd/ripng_interface.c b/ripngd/ripng_interface.c index 250c7803f7..6a30c07d99 100644 --- a/ripngd/ripng_interface.c +++ b/ripngd/ripng_interface.c @@ -198,11 +198,14 @@ static int ripng_if_down(struct interface *ifp) /* Inteface link up message processing. */ static int ripng_ifp_up(struct interface *ifp) { - if (IS_RIPNG_DEBUG_ZEBRA) + if (IS_RIPNG_DEBUG_ZEBRA) { + struct vrf *vrf = vrf_lookup_by_id(ifp->vrf_id); + zlog_debug( - "interface up %s vrf %u index %d flags %llx metric %d mtu %d", - ifp->name, ifp->vrf_id, ifp->ifindex, + "interface up %s vrf %s(%u) index %d flags %llx metric %d mtu %d", + ifp->name, VRF_LOGNAME(vrf), ifp->vrf_id, ifp->ifindex, (unsigned long long)ifp->flags, ifp->metric, ifp->mtu6); + } ripng_interface_sync(ifp); @@ -224,11 +227,14 @@ static int ripng_ifp_down(struct interface *ifp) ripng_interface_sync(ifp); ripng_if_down(ifp); - if (IS_RIPNG_DEBUG_ZEBRA) + if (IS_RIPNG_DEBUG_ZEBRA) { + struct vrf *vrf = vrf_lookup_by_id(ifp->vrf_id); + zlog_debug( - "interface down %s vrf %u index %d flags %#llx metric %d mtu %d", - ifp->name, ifp->vrf_id, ifp->ifindex, + "interface down %s vrf %s(%u) index %d flags %#llx metric %d mtu %d", + ifp->name, VRF_LOGNAME(vrf), ifp->vrf_id, ifp->ifindex, (unsigned long long)ifp->flags, ifp->metric, ifp->mtu6); + } return 0; } @@ -238,11 +244,14 @@ static int ripng_ifp_create(struct interface *ifp) { ripng_interface_sync(ifp); - if (IS_RIPNG_DEBUG_ZEBRA) + if (IS_RIPNG_DEBUG_ZEBRA) { + struct vrf *vrf = vrf_lookup_by_id(ifp->vrf_id); + zlog_debug( - "RIPng interface add %s vrf %u index %d flags %#llx metric %d mtu %d", - ifp->name, ifp->vrf_id, ifp->ifindex, + "RIPng interface add %s vrf %s(%u) index %d flags %#llx metric %d mtu %d", + ifp->name, VRF_LOGNAME(vrf), ifp->vrf_id, ifp->ifindex, (unsigned long long)ifp->flags, ifp->metric, ifp->mtu6); + } /* Check is this interface is RIP enabled or not.*/ ripng_enable_apply(ifp); @@ -258,14 +267,16 @@ static int ripng_ifp_create(struct interface *ifp) static int ripng_ifp_destroy(struct interface *ifp) { + struct vrf *vrf = vrf_lookup_by_id(ifp->vrf_id); + ripng_interface_sync(ifp); if (if_is_up(ifp)) { ripng_if_down(ifp); } zlog_info( - "interface delete %s vrf %u index %d flags %#llx metric %d mtu %d", - ifp->name, ifp->vrf_id, ifp->ifindex, + "interface delete %s vrf %s(%u) index %d flags %#llx metric %d mtu %d", + ifp->name, VRF_LOGNAME(vrf), ifp->vrf_id, ifp->ifindex, (unsigned long long)ifp->flags, ifp->metric, ifp->mtu6); return 0; @@ -282,9 +293,14 @@ int ripng_interface_vrf_update(ZAPI_CALLBACK_ARGS) if (!ifp) return 0; - if (IS_RIPNG_DEBUG_ZEBRA) - zlog_debug("interface %s VRF change vrf_id %u new vrf id %u", - ifp->name, vrf_id, new_vrf_id); + if (IS_RIPNG_DEBUG_ZEBRA) { + struct vrf *vrf = vrf_lookup_by_id(ifp->vrf_id); + struct vrf *nvrf = vrf_lookup_by_id(new_vrf_id); + + zlog_debug("interface %s VRF change vrf %s(%u) new vrf %s(%u)", + ifp->name, VRF_LOGNAME(vrf), vrf_id, + VRF_LOGNAME(nvrf), new_vrf_id); + } if_update_to_new_vrf(ifp, new_vrf_id); ripng_interface_sync(ifp); diff --git a/ripngd/ripng_peer.c b/ripngd/ripng_peer.c index 109524e212..e6ff58dd0c 100644 --- a/ripngd/ripng_peer.c +++ b/ripngd/ripng_peer.c @@ -141,7 +141,6 @@ void ripng_peer_bad_packet(struct ripng *ripng, struct sockaddr_in6 *from) static char *ripng_peer_uptime(struct ripng_peer *peer, char *buf, size_t len) { time_t uptime; - struct tm *tm; /* If there is no connection has been done before print `never'. */ if (peer->uptime == 0) { @@ -152,17 +151,9 @@ static char *ripng_peer_uptime(struct ripng_peer *peer, char *buf, size_t len) /* Get current time. */ uptime = time(NULL); uptime -= peer->uptime; - tm = gmtime(&uptime); - - if (uptime < ONE_DAY_SECOND) - snprintf(buf, len, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, - tm->tm_sec); - else if (uptime < ONE_WEEK_SECOND) - snprintf(buf, len, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour, - tm->tm_min); - else - snprintf(buf, len, "%02dw%dd%02dh", tm->tm_yday / 7, - tm->tm_yday - ((tm->tm_yday / 7) * 7), tm->tm_hour); + + frrtime_to_interval(uptime, buf, len); + return buf; } diff --git a/ripngd/ripng_routemap.c b/ripngd/ripng_routemap.c index 6123591429..b5f80d2ab0 100644 --- a/ripngd/ripng_routemap.c +++ b/ripngd/ripng_routemap.c @@ -237,9 +237,9 @@ static void *route_set_metric_compile(const char *arg) return mod; if (metric > RIPNG_METRIC_INFINITY) { - zlog_info("%s: Metric specified: %ld is being converted into METRIC_INFINITY", - __PRETTY_FUNCTION__, - metric); + zlog_info( + "%s: Metric specified: %ld is being converted into METRIC_INFINITY", + __func__, metric); mod->metric = RIPNG_METRIC_INFINITY; } else mod->metric = metric; diff --git a/ripngd/ripngd.c b/ripngd/ripngd.c index f8d7dc968b..bb33abdb2c 100644 --- a/ripngd/ripngd.c +++ b/ripngd/ripngd.c @@ -271,7 +271,7 @@ static int ripng_recv_packet(int sock, uint8_t *buf, int bufsize, msg.msg_iov = &iov; msg.msg_iovlen = 1; msg.msg_control = (void *)adata; - msg.msg_controllen = sizeof adata; + msg.msg_controllen = sizeof(adata); iov.iov_base = buf; iov.iov_len = bufsize; @@ -1455,7 +1455,7 @@ static int ripng_update(struct thread *t) if (ri->passive) continue; -#if RIPNG_ADVANCED +#ifdef RIPNG_ADVANCED if (ri->ri_send == RIPNG_SEND_OFF) { if (IS_RIPNG_DEBUG_EVENT) zlog_debug( @@ -1991,20 +1991,20 @@ void ripng_event(struct ripng *ripng, enum ripng_event event, int sock) static void ripng_vty_out_uptime(struct vty *vty, struct ripng_info *rinfo) { time_t clock; - struct tm *tm; + struct tm tm; #define TIME_BUF 25 char timebuf[TIME_BUF]; struct thread *thread; if ((thread = rinfo->t_timeout) != NULL) { clock = thread_timer_remain_second(thread); - tm = gmtime(&clock); - strftime(timebuf, TIME_BUF, "%M:%S", tm); + gmtime_r(&clock, &tm); + strftime(timebuf, TIME_BUF, "%M:%S", &tm); vty_out(vty, "%5s", timebuf); } else if ((thread = rinfo->t_garbage_collect) != NULL) { clock = thread_timer_remain_second(thread); - tm = gmtime(&clock); - strftime(timebuf, TIME_BUF, "%M:%S", tm); + gmtime_r(&clock, &tm); + strftime(timebuf, TIME_BUF, "%M:%S", &tm); vty_out(vty, "%5s", timebuf); } } diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c index 3cd80bde49..882e73f873 100644 --- a/sharpd/sharp_zebra.c +++ b/sharpd/sharp_zebra.c @@ -338,8 +338,7 @@ void sharp_zebra_nexthop_watch(struct prefix *p, vrf_id_t vrf_id, bool import, } if (zclient_send_rnh(zclient, command, p, connected, vrf_id) < 0) - zlog_warn("%s: Failure to send nexthop to zebra", - __PRETTY_FUNCTION__); + zlog_warn("%s: Failure to send nexthop to zebra", __func__); } static int sharp_debug_nexthops(struct zapi_route *api) @@ -387,7 +386,7 @@ static int sharp_nexthop_update(ZAPI_CALLBACK_ARGS) struct zapi_route nhr; if (!zapi_nexthop_update_decode(zclient->ibuf, &nhr)) { - zlog_warn("%s: Decode of update failed", __PRETTY_FUNCTION__); + zlog_warn("%s: Decode of update failed", __func__); return 0; } @@ -408,8 +407,7 @@ static int sharp_redistribute_route(ZAPI_CALLBACK_ARGS) struct zapi_route api; if (zapi_route_decode(zclient->ibuf, &api) < 0) - zlog_warn("%s: Decode of redistribute failed: %d", - __PRETTY_FUNCTION__, + zlog_warn("%s: Decode of redistribute failed: %d", __func__, ZEBRA_REDISTRIBUTE_ROUTE_ADD); zlog_debug("%s: %pFX (%s)", zserv_command_string(cmd), diff --git a/staticd/static_debug.h b/staticd/static_debug.h index 6e58118ed0..8932e2d429 100644 --- a/staticd/static_debug.h +++ b/staticd/static_debug.h @@ -29,7 +29,7 @@ #include "lib/debug.h" /* staticd debugging records */ -struct debug static_dbg_events; +extern struct debug static_dbg_events; /* * Initialize staticd debugging. diff --git a/staticd/static_main.c b/staticd/static_main.c index 43cb7db51d..3aa8a8db3e 100644 --- a/staticd/static_main.c +++ b/staticd/static_main.c @@ -73,6 +73,8 @@ static void sigint(void) { zlog_notice("Terminating on signal"); + static_vrf_terminate(); + exit(0); } diff --git a/staticd/static_vrf.c b/staticd/static_vrf.c index abb64aad3f..6c065932a1 100644 --- a/staticd/static_vrf.c +++ b/staticd/static_vrf.c @@ -111,6 +111,7 @@ static int static_vrf_delete(struct vrf *vrf) svrf->stable[afi][safi] = NULL; } } + XFREE(MTYPE_TMP, svrf); return 0; } @@ -204,3 +205,8 @@ void static_vrf_init(void) vrf_cmd_init(static_vrf_config_write, &static_privs); } + +void static_vrf_terminate(void) +{ + vrf_terminate(); +} diff --git a/staticd/static_vrf.h b/staticd/static_vrf.h index 28fcdd0d36..6951e56712 100644 --- a/staticd/static_vrf.h +++ b/staticd/static_vrf.h @@ -35,4 +35,5 @@ void static_vrf_init(void); struct route_table *static_vrf_static_table(afi_t afi, safi_t safi, struct static_vrf *svrf); +extern void static_vrf_terminate(void); #endif diff --git a/staticd/static_vty.c b/staticd/static_vty.c index 6390fd811f..40bcf2b5d3 100644 --- a/staticd/static_vty.c +++ b/staticd/static_vty.c @@ -287,8 +287,8 @@ static int static_route_leak( if (vty) vty_out(vty, "%% Malformed address\n"); else - zlog_warn("%s: Malformed address: %s", - __PRETTY_FUNCTION__, dest_str); + zlog_warn("%s: Malformed address: %s", __func__, + dest_str); return CMD_WARNING_CONFIG_FAILED; } @@ -302,8 +302,7 @@ static int static_route_leak( vty_out(vty, "%% Malformed address\n"); else zlog_warn("%s: Malformed address: %s", - __PRETTY_FUNCTION__, - mask_str); + __func__, mask_str); return CMD_WARNING_CONFIG_FAILED; } p.prefixlen = ip_masklen(mask); @@ -320,7 +319,7 @@ static int static_route_leak( else zlog_warn( "%s: Malformed source address: %s", - __PRETTY_FUNCTION__, src_str); + __func__, src_str); return CMD_WARNING_CONFIG_FAILED; } src_p = (struct prefix_ipv6 *)&src; @@ -351,10 +350,9 @@ static int static_route_leak( "%% Table %s overlaps vrf table %u\n", table_str, svrf->vrf->data.l.table_id); else - zlog_warn( - "%s: Table %s overlaps vrf table %u", - __PRETTY_FUNCTION__, - table_str, svrf->vrf->data.l.table_id); + zlog_warn("%s: Table %s overlaps vrf table %u", + __func__, table_str, + svrf->vrf->data.l.table_id); return CMD_WARNING_CONFIG_FAILED; } } @@ -379,7 +377,7 @@ static int static_route_leak( else zlog_warn( "%s: MPLS not turned on in kernel ignoring static route to %s", - __PRETTY_FUNCTION__, dest_str); + __func__, dest_str); return CMD_WARNING_CONFIG_FAILED; } int rc = mpls_str2label(label_str, &snh_label.num_labels, @@ -392,7 +390,7 @@ static int static_route_leak( else zlog_warn( "%s: Malformed labels specified for route %s", - __PRETTY_FUNCTION__, dest_str); + __func__, dest_str); break; case -2: if (vty) @@ -403,7 +401,7 @@ static int static_route_leak( else zlog_warn( "%s: Cannot use reserved labels (%d-%d) for %s", - __PRETTY_FUNCTION__, + __func__, MPLS_LABEL_RESERVED_MIN, MPLS_LABEL_RESERVED_MAX, dest_str); @@ -416,8 +414,8 @@ static int static_route_leak( else zlog_warn( "%s: Too many labels, Enter %d or fewer for %s", - __PRETTY_FUNCTION__, - MPLS_MAX_LABELS, dest_str); + __func__, MPLS_MAX_LABELS, + dest_str); break; } return CMD_WARNING_CONFIG_FAILED; @@ -439,7 +437,7 @@ static int static_route_leak( else zlog_warn( "%s: %s: Nexthop interface name can not be from reserved keywords (Null0, reject, blackhole)", - __PRETTY_FUNCTION__, dest_str); + __func__, dest_str); return CMD_WARNING_CONFIG_FAILED; } } @@ -462,8 +460,7 @@ static int static_route_leak( flag_str); else zlog_warn("%s: Malformed flag %s for %s", - __PRETTY_FUNCTION__, flag_str, - dest_str); + __func__, flag_str, dest_str); return CMD_WARNING_CONFIG_FAILED; } } @@ -477,8 +474,7 @@ static int static_route_leak( else zlog_warn( "%s: Malformed nexthop address %s for %s", - __PRETTY_FUNCTION__, gate_str, - dest_str); + __func__, gate_str, dest_str); return CMD_WARNING_CONFIG_FAILED; } gatep = &gate; @@ -595,7 +591,7 @@ void static_config_install_delayed_routes(struct static_vrf *svrf) if (installed != CMD_SUCCESS) zlog_debug( "%s: Attempt to install %s as a route and it was rejected", - __PRETTY_FUNCTION__, shr->dest_str); + __func__, shr->dest_str); listnode_delete(static_list, shr); static_list_delete(shr); } diff --git a/staticd/static_zebra.c b/staticd/static_zebra.c index 42646d15bc..5cadf34365 100644 --- a/staticd/static_zebra.c +++ b/staticd/static_zebra.c @@ -122,12 +122,13 @@ static int route_notify_owner(ZAPI_CALLBACK_ARGS) case ZAPI_ROUTE_FAIL_INSTALL: static_nht_mark_state(&p, vrf_id, STATIC_NOT_INSTALLED); zlog_warn("%s: Route %s failed to install for table: %u", - __PRETTY_FUNCTION__, buf, table_id); + __func__, buf, table_id); break; case ZAPI_ROUTE_BETTER_ADMIN_WON: static_nht_mark_state(&p, vrf_id, STATIC_NOT_INSTALLED); - zlog_warn("%s: Route %s over-ridden by better route for table: %u", - __PRETTY_FUNCTION__, buf, table_id); + zlog_warn( + "%s: Route %s over-ridden by better route for table: %u", + __func__, buf, table_id); break; case ZAPI_ROUTE_INSTALLED: static_nht_mark_state(&p, vrf_id, STATIC_INSTALLED); @@ -138,7 +139,7 @@ static int route_notify_owner(ZAPI_CALLBACK_ARGS) case ZAPI_ROUTE_REMOVE_FAIL: static_nht_mark_state(&p, vrf_id, STATIC_INSTALLED); zlog_warn("%s: Route %s failure to remove for table: %u", - __PRETTY_FUNCTION__, buf, table_id); + __func__, buf, table_id); break; } @@ -335,8 +336,7 @@ void static_zebra_nht_register(struct route_node *rn, } if (zclient_send_rnh(zclient, cmd, &p, false, si->nh_vrf_id) < 0) - zlog_warn("%s: Failure to send nexthop to zebra", - __PRETTY_FUNCTION__); + zlog_warn("%s: Failure to send nexthop to zebra", __func__); } extern void static_zebra_route_add(struct route_node *rn, diff --git a/tests/bgpd/test_aspath.c b/tests/bgpd/test_aspath.c index 9feec7156a..b94355e8b8 100644 --- a/tests/bgpd/test_aspath.c +++ b/tests/bgpd/test_aspath.c @@ -474,6 +474,20 @@ static struct test_segment { 14, {NULL, NULL, 0, 0, 0, 0, 0, 0}, }, + { + /* 28 */ + "BGP_AS_ZERO", + "seq(8466,3,52737,0,4096)", + {0x2, 0x5, + 0x21, 0x12, + 0x00, 0x03, + 0xce, 0x01, + 0x00, 0x00, + 0x10, 0x00}, + 12, + {"8466 3 52737 0 4096", "8466 3 52737 0 4096", 5, 0, + NOT_ALL_PRIVATE, 4096, 4, 8466}, + }, {NULL, NULL, {0}, 0, {NULL, 0, 0}}}; #define COMMON_ATTRS \ @@ -678,6 +692,21 @@ static struct aspath_tests { COMMON_ATTR_SIZE + 3, &test_segments[0], }, + /* 13 */ + { + "4b AS4_PATH: BGP_AS_ZERO", + &test_segments[28], + "8466 3 52737 0 4096", + AS4_DATA, + -1, + PEER_CAP_AS4_RCV | PEER_CAP_AS4_ADV, + { + COMMON_ATTRS, + BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_OPTIONAL, + BGP_ATTR_AS4_PATH, 22, + }, + COMMON_ATTR_SIZE + 3, + }, {NULL, NULL, NULL, 0, 0, 0, {0}, 0}, }; diff --git a/tests/bgpd/test_aspath.py b/tests/bgpd/test_aspath.py index 15ae514c87..5fa1f11629 100644 --- a/tests/bgpd/test_aspath.py +++ b/tests/bgpd/test_aspath.py @@ -52,6 +52,7 @@ TestAspath.parsertest("redundantset2") TestAspath.parsertest("zero-size overflow") TestAspath.parsertest("zero-size overflow + valid segment") TestAspath.parsertest("invalid segment type") +TestAspath.parsertest("BGP_AS_ZERO") for i in range(10): TestAspath.okfail("prepend test %d" % i) @@ -77,3 +78,4 @@ TestAspath.attrtest("4b AS_PATH: too long2") TestAspath.attrtest("4b AS_PATH: bad flags") TestAspath.attrtest("4b AS4_PATH w/o AS_PATH") TestAspath.attrtest("4b AS4_PATH: confed") +TestAspath.attrtest("4b AS4_PATH: BGP_AS_ZERO") diff --git a/tests/bgpd/test_mpath.c b/tests/bgpd/test_mpath.c index 3f63c0499a..2258df9491 100644 --- a/tests/bgpd/test_mpath.c +++ b/tests/bgpd/test_mpath.c @@ -52,8 +52,8 @@ #define EXPECT_TRUE(expr, res) \ if (!(expr)) { \ - printf("Test failure in %s line %u: %s\n", __FUNCTION__, \ - __LINE__, #expr); \ + printf("Test failure in %s line %u: %s\n", __func__, __LINE__, \ + #expr); \ (res) = TEST_FAILED; \ } @@ -75,7 +75,7 @@ struct testcase_t__ { /* need these to link in libbgp */ struct thread_master *master = NULL; -struct zclient *zclient; +extern struct zclient *zclient; struct zebra_privs_t bgpd_privs = { .user = NULL, .group = NULL, diff --git a/tests/isisd/test_fuzz_isis_tlv_tests.h.gz b/tests/isisd/test_fuzz_isis_tlv_tests.h.gz Binary files differindex 46e45e5ee0..4f59d1d7c0 100644 --- a/tests/isisd/test_fuzz_isis_tlv_tests.h.gz +++ b/tests/isisd/test_fuzz_isis_tlv_tests.h.gz diff --git a/tests/topotests/bgp-basic-functionality-topo1/test_bgp_basic_functionality.py b/tests/topotests/bgp-basic-functionality-topo1/test_bgp_basic_functionality.py index e99111d90b..43639a81d1 100755 --- a/tests/topotests/bgp-basic-functionality-topo1/test_bgp_basic_functionality.py +++ b/tests/topotests/bgp-basic-functionality-topo1/test_bgp_basic_functionality.py @@ -79,6 +79,9 @@ try: except IOError: assert False, "Could not read file {}".format(jsonFile) +#Global Variable +KEEPALIVETIMER = 2 +HOLDDOWNTIMER = 6 class CreateTopo(Topo): """ @@ -292,8 +295,8 @@ def test_bgp_timers_functionality(request): "r2": { "dest_link":{ "r1": { - "keepalivetimer": 60, - "holddowntimer": 180, + "keepalivetimer": KEEPALIVETIMER, + "holddowntimer": HOLDDOWNTIMER } } } @@ -319,8 +322,6 @@ def test_bgp_timers_functionality(request): write_test_footer(tc_name) - - def test_static_routes(request): """ Test to create and verify static routes. """ diff --git a/tests/topotests/bgp-route-map/test_route_map_topo1.py b/tests/topotests/bgp-route-map/test_route_map_topo1.py index 86ec6c82d2..22dd3a6380 100755 --- a/tests/topotests/bgp-route-map/test_route_map_topo1.py +++ b/tests/topotests/bgp-route-map/test_route_map_topo1.py @@ -71,7 +71,7 @@ from time import sleep # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers @@ -102,7 +102,7 @@ ADDR_TYPES = check_address_types() # Reading the data from JSON File for topology and configuration creation jsonFile = "{}/bgp_route_map_topo1.json".format(CWD) try: - with open(jsonFile, 'r') as topoJson: + with open(jsonFile, "r") as topoJson: topo = json.load(topoJson) except IOError: assert False, "Could not read file {}".format(jsonFile) @@ -442,11 +442,12 @@ def test_route_map_inbound_outbound_same_neighbor_p0(request): } } - result = verify_rib(tgen, adt, dut, input_dict_2, protocol=protocol) + result = verify_rib(tgen, adt, dut, input_dict_2, protocol=protocol, + expected=False) assert result is not True, "Testcase {} : Failed \n" - "Expected behavior: routes are not present in rib \n" - "Error: {}".format( + "routes are not present in rib \n Error: {}".format( tc_name, result) + logger.info("Expected behaviour: {}".format(result)) # Verifying RIB routes dut = "r4" @@ -461,11 +462,12 @@ def test_route_map_inbound_outbound_same_neighbor_p0(request): ] } } - result = verify_rib(tgen, adt, dut, input_dict, protocol=protocol) + result = verify_rib(tgen, adt, dut, input_dict, protocol=protocol, + expected=False) assert result is not True, "Testcase {} : Failed \n " - "Expected behavior: routes are not present in rib \n " - "Error: {}".format( + "routes are not present in rib \n Error: {}".format( tc_name, result) + logger.info("Expected behaviour: {}".format(result)) write_test_footer(tc_name) @@ -649,10 +651,14 @@ def test_route_map_with_action_values_combination_of_prefix_action_p0( } } - result = verify_rib(tgen, adt, dut, input_dict_2, protocol=protocol) + #tgen.mininet_cli() + result = verify_rib(tgen, adt, dut, input_dict_2, protocol=protocol, + expected=False) if "deny" in [prefix_action, rmap_action]: - assert result is not True, "Testcase {} : Failed \n Error: {}".\ + assert result is not True, "Testcase {} : Failed \n " + "Routes are still present \n Error: {}".\ format(tc_name, result) + logger.info("Expected behaviour: {}".format(result)) else: assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) diff --git a/tests/topotests/bgp-route-map/test_route_map_topo2.py b/tests/topotests/bgp-route-map/test_route_map_topo2.py index 7009fc97ce..f2398c33ff 100755 --- a/tests/topotests/bgp-route-map/test_route_map_topo2.py +++ b/tests/topotests/bgp-route-map/test_route_map_topo2.py @@ -32,17 +32,17 @@ TC_61: TC_50_1: Test modify/remove prefix-lists referenced by a route-map for match statement. -TC_50_1: +TC_50_2: Remove prefix-list referencec by route-map match cluase and verifying it reflecting as intended TC_51: Add and remove community-list referencec by route-map match cluase and verifying it reflecting as intended TC_45: - Test multiple match statements as part of a route-map's single + Test multiple match statements as part of a route-map"s single sequence number. (Logical OR-ed of multiple match statements) TC_44: - Test multiple match statements as part of a route-map's single + Test multiple match statements as part of a route-map"s single sequence number. (Logical AND of multiple match statements) TC_41: Test add/remove route-maps to specific neighbor and see if @@ -57,7 +57,7 @@ TC_48: Create route map setting local preference and weight to eBGP peeer and metric to ibgp peer and verifying it should not get advertised TC_43: - Test multiple set statements as part of a route-map's + Test multiple set statements as part of a route-map"s single sequence number. TC_54: Verify route-maps continue clause functionality. @@ -112,7 +112,7 @@ from time import sleep # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers @@ -127,7 +127,8 @@ from lib.common_config import ( verify_rib, delete_route_maps, create_bgp_community_lists, interface_status, create_route_maps, create_prefix_lists, verify_route_maps, check_address_types, verify_bgp_community, - shutdown_bringup_interface, verify_prefix_lists, reset_config_on_routers) + shutdown_bringup_interface, verify_prefix_lists, reset_config_on_routers, + verify_create_community_list) from lib.topolog import logger from lib.bgp import ( verify_bgp_convergence, create_router_bgp, @@ -138,7 +139,7 @@ from lib.topojson import build_topo_from_json, build_config_from_json jsonFile = "{}/bgp_route_map_topo2.json".format(CWD) try: - with open(jsonFile, 'r') as topoJson: + with open(jsonFile, "r") as topoJson: topo = json.load(topoJson) except IOError: assert False, "Could not read file {}".format(jsonFile) @@ -198,14 +199,14 @@ def setup_module(mod): global bgp_convergence global ADDR_TYPES - # Don't run this test if we have any failure. + # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) # Api call verify whether BGP is converged bgp_convergence = verify_bgp_convergence(tgen, topo) - assert bgp_convergence is True, ('setup_module :Failed \n Error:' - ' {}'.format(bgp_convergence)) + assert bgp_convergence is True, ("setup_module :Failed \n Error:" + " {}".format(bgp_convergence)) logger.info("Running setup_module() done") @@ -241,7 +242,7 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -250,20 +251,20 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit', + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit", }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit', + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 10, + "network": "any", + "action": "permit", }] } } @@ -271,7 +272,7 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) for addr_type in ADDR_TYPES: # Create route map @@ -280,7 +281,7 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_" + addr_type @@ -294,7 +295,7 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): ], "rmap_match_pf_2_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_" + addr_type @@ -309,12 +310,12 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -326,7 +327,7 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -337,7 +338,7 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): "route_maps": [{ "name": "rmap_match_pf_2_ipv4", - "direction": 'out' + "direction": "out" }] } } @@ -354,7 +355,7 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -365,7 +366,7 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): "route_maps": [{ "name": "rmap_match_pf_2_ipv6", - "direction": 'out' + "direction": "out" }] } } @@ -379,23 +380,23 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] # dual stack changes for addr_type in ADDR_TYPES: result4 = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result4 is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result4 is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result4) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -405,21 +406,21 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result4 = verify_bgp_attributes(tgen, addr_type, dut, routes[ addr_type],rmap_name, input_dict_3) - assert result4 is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result4 is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result4) # Verifying RIB routes - dut = 'r4' - protocol = 'bgp' + dut = "r4" + protocol = "bgp" # dual stack changes for addr_type in ADDR_TYPES: result4 = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result4 is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result4 is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result4) # Verifying BGP set attributes - dut = 'r4' + dut = "r4" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -429,7 +430,7 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): rmap_name = "rmap_match_pf_2_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -448,7 +449,7 @@ def test_modify_set_match_clauses_in_rmap_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -458,37 +459,37 @@ def test_modify_set_match_clauses_in_rmap_p0(): # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit', + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit", }], - 'pf_list_2_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit' + "pf_list_2_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit" }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit', + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 10, + "network": "any", + "action": "permit", }], - 'pf_list_2_ipv6': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit' + "pf_list_2_ipv6": [{ + "seqid": 10, + "network": "any", + "action": "permit" }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map @@ -498,7 +499,7 @@ def test_modify_set_match_clauses_in_rmap_p0(): "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -510,7 +511,7 @@ def test_modify_set_match_clauses_in_rmap_p0(): }], "rmap_match_pf_2_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -524,12 +525,12 @@ def test_modify_set_match_clauses_in_rmap_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -541,7 +542,7 @@ def test_modify_set_match_clauses_in_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -552,7 +553,7 @@ def test_modify_set_match_clauses_in_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_2_ipv4", - "direction": 'out' + "direction": "out" }] } } @@ -569,7 +570,7 @@ def test_modify_set_match_clauses_in_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -580,7 +581,7 @@ def test_modify_set_match_clauses_in_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_2_ipv6", - "direction": 'out' + "direction": "out" }] } } @@ -593,21 +594,21 @@ def test_modify_set_match_clauses_in_rmap_p0(): } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -617,21 +618,21 @@ def test_modify_set_match_clauses_in_rmap_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result4 = verify_bgp_attributes(tgen, addr_type, dut, routes[ addr_type],rmap_name, input_dict_3) - assert result4 is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result4 is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result4) # Verifying RIB routes - dut = 'r4' - protocol = 'bgp' + dut = "r4" + protocol = "bgp" # dual stack changes for addr_type in ADDR_TYPES: result4 = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result4 is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result4 is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result4) # Verifying BGP set attributes - dut = 'r4' + dut = "r4" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -640,7 +641,7 @@ def test_modify_set_match_clauses_in_rmap_p0(): rmap_name = "rmap_match_pf_2_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[ addr_type],rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Modify set/match clause of in-used route map @@ -650,7 +651,7 @@ def test_modify_set_match_clauses_in_rmap_p0(): "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -662,7 +663,7 @@ def test_modify_set_match_clauses_in_rmap_p0(): }], "rmap_match_pf_2_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -676,20 +677,20 @@ def test_modify_set_match_clauses_in_rmap_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -698,20 +699,20 @@ def test_modify_set_match_clauses_in_rmap_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r4' - protocol = 'bgp' + dut = "r4" + protocol = "bgp" for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r4' + dut = "r4" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -720,7 +721,7 @@ def test_modify_set_match_clauses_in_rmap_p0(): rmap_name = "rmap_match_pf_2_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -739,7 +740,7 @@ def test_delete_route_maps_p1(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -763,22 +764,22 @@ def test_delete_route_maps_p1(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Delete route maps for addr_type in ADDR_TYPES: input_dict = { - 'r3': { - 'route_maps': ['rmap_match_tag_1_{}'.format(addr_type)] + "r3": { + "route_maps": ["rmap_match_tag_1_{}".format(addr_type)] } } result = delete_route_maps(tgen, input_dict) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_route_maps(tgen, input_dict) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -797,7 +798,7 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -806,27 +807,27 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit', + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit", }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'permit', + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "permit", }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map @@ -836,7 +837,7 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -849,7 +850,7 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): }], "rmap_match_pf_2_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -863,12 +864,12 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -880,7 +881,7 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -891,7 +892,7 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_2_ipv4", - "direction": 'out' + "direction": "out" }] } } @@ -908,7 +909,7 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -919,7 +920,7 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_2_ipv6", - "direction": 'out' + "direction": "out" }] } } @@ -933,21 +934,21 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -956,20 +957,20 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r4' - protocol = 'bgp' + dut = "r4" + protocol = "bgp" for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r4' + dut = "r4" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -979,55 +980,55 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): rmap_name = "rmap_match_pf_2_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Modify ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'deny' + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "deny" }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'deny' + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "deny" }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) sleep(5) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) - assert result is not True, 'Testcase {} : Failed \n' - 'Expected behaviour: routes are not present \n ' - 'Error: {}'.format( + protocol=protocol, expected=False) + assert result is not True, "Testcase {} : Failed \n" + "routes are not present \n Error: {}".format( tc_name, result) + logger.info("Expected behaviour: {}".format(result)) # Verifying RIB routes - dut = 'r4' - protocol = 'bgp' + dut = "r4" + protocol = "bgp" for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) - assert result is not True, 'Testcase {} : Failed \n' - 'Expected behaviour: routes are not present \n ' - 'Error: {}'.format( + protocol=protocol, expected=False) + assert result is not True, "Testcase {} : Failed \n" + "Expected behaviour: routes are not present \n " + "Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -1038,7 +1039,7 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): def test_remove_prefix_list_referenced_by_rmap_p0(): """ - TC_50_1: + TC_50_2: Remove prefix-list referencec by route-map match cluase and verifying it reflecting as intended """ @@ -1046,7 +1047,7 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -1055,27 +1056,27 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit' + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit" }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'permit' + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "permit" }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map @@ -1085,7 +1086,7 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -1097,7 +1098,7 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): }], "rmap_match_pf_2_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -1111,13 +1112,13 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map for addr_type in ADDR_TYPES: input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -1129,7 +1130,7 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -1140,7 +1141,7 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_2_ipv4", - "direction": 'out' + "direction": "out" }] } } @@ -1157,7 +1158,7 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -1168,7 +1169,7 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_2_ipv6", - "direction": 'out' + "direction": "out" }] } } @@ -1181,21 +1182,21 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -1204,20 +1205,20 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r4' - protocol = 'bgp' + dut = "r4" + protocol = "bgp" for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r4' + dut = "r4" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -1226,67 +1227,67 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): rmap_name = "rmap_match_pf_2_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Remove/Delete prefix list input_dict_3 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit', - 'delete': True + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit", + "delete": True }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'permit', - 'delete': True + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "permit", + "delete": True }] } } } } result = create_prefix_lists(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_prefix_lists(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Api call to clear bgp, so config changes would be reflected - dut = 'r3' + dut = "r3" result = clear_bgp_and_verify(tgen, topo, dut) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) - assert result is not True, 'Testcase {} : Failed \n' - 'Expected behaviour: routes are not present \n ' - 'Error: {}'.format( + protocol=protocol, expected=False) + assert result is not True, "Testcase {} : Failed \n" + "routes are not present \n Error: {}".format( tc_name, result) + logger.info("Expected behaviour: {}".format(result)) # Verifying RIB routes - dut = 'r4' - protocol = 'bgp' + dut = "r4" + protocol = "bgp" for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) - assert result is not True, 'Testcase {} : Failed \n' - 'Expected behaviour: routes are not present \n ' - 'Error: {}'.format( - tc_name, result) + protocol=protocol, expected=False) + assert result is not True, "Testcase {} : Failed \n" + "routes are not present \n Error: {}".\ + format(tc_name, result) + logger.info("Expected behaviour: {}".format(result)) write_test_footer(tc_name) @@ -1304,7 +1305,7 @@ def test_add_and_remove_community_list_referenced_by_rmap_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -1329,12 +1330,12 @@ def test_add_and_remove_community_list_referenced_by_rmap_p0(): } } result = create_route_maps(tgen, input_dict_5) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_6 = { - 'r1': { + "r1": { "bgp": { "address_family": { "ipv4": { @@ -1345,7 +1346,7 @@ def test_add_and_remove_community_list_referenced_by_rmap_p0(): "r1": { "route_maps": [{ "name": "rm_r1_out_ipv4", - "direction": 'out' + "direction": "out" }] } } @@ -1361,7 +1362,7 @@ def test_add_and_remove_community_list_referenced_by_rmap_p0(): "r1": { "route_maps": [{ "name": "rm_r1_out_ipv6", - "direction": 'out' + "direction": "out" }] } } @@ -1375,7 +1376,7 @@ def test_add_and_remove_community_list_referenced_by_rmap_p0(): } result = create_router_bgp(tgen, topo, input_dict_6) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) for addr_type in ADDR_TYPES: @@ -1394,9 +1395,14 @@ def test_add_and_remove_community_list_referenced_by_rmap_p0(): } } result = create_bgp_community_lists(tgen, input_dict_1) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) + # Verify BGP large community is created + result = verify_create_community_list(tgen, input_dict_1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result) + for addr_type in ADDR_TYPES: # Create route map input_dict_2 = { @@ -1415,12 +1421,12 @@ def test_add_and_remove_community_list_referenced_by_rmap_p0(): } } result = create_route_maps(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_3 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -1431,7 +1437,7 @@ def test_add_and_remove_community_list_referenced_by_rmap_p0(): "r3": { "route_maps": [{ "name": "rm_r3_in_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -1447,7 +1453,7 @@ def test_add_and_remove_community_list_referenced_by_rmap_p0(): "r3": { "route_maps": [{ "name": "rm_r3_in_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -1461,33 +1467,33 @@ def test_add_and_remove_community_list_referenced_by_rmap_p0(): } result = create_router_bgp(tgen, topo, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) sleep(5) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verify large-community-list - dut = 'r3' + dut = "r3" networks = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] } input_dict_4 = { - 'largeCommunity': '1:1:1 1:2:3 2:1:1 2:2:2' + "largeCommunity": "1:1:1 1:2:3 2:1:1 2:2:2" } for addr_type in ADDR_TYPES: result = verify_bgp_community(tgen, addr_type, dut, networks[ addr_type],input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -1498,14 +1504,14 @@ def test_add_and_remove_community_list_referenced_by_rmap_p0(): def test_multiple_match_statement_in_route_map_logical_ORed_p0(): """ TC_45: - Test multiple match statements as part of a route-map's single + Test multiple match statements as part of a route-map"s single sequence number. (Logical OR-ed of multiple match statements) """ tgen = get_topogen() global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -1514,20 +1520,20 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): # Api call to advertise networks input_dict_nw1 = { - 'r1': { + "r1": { "bgp": { "address_family": { "ipv4": { "unicast": { "advertise_networks": [ - {"network": '10.0.30.1/32'} + {"network": "10.0.30.1/32"} ] } }, "ipv6": { "unicast": { "advertise_networks": [ - {"network": '1::1/128'} + {"network": "1::1/128"} ] } } @@ -1537,25 +1543,25 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): } result = create_router_bgp(tgen, topo, input_dict_nw1) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Api call to advertise networks input_dict_nw2 = { - 'r1': { + "r1": { "bgp": { "address_family": { "ipv4": { "unicast": { "advertise_networks": [ - {"network": '20.0.30.1/32'} + {"network": "20.0.30.1/32"} ] } }, "ipv6": { "unicast": { "advertise_networks": [ - {"network": '2::1/128'} + {"network": "2::1/128"} ] } } @@ -1565,57 +1571,57 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): } result = create_router_bgp(tgen, topo, input_dict_nw2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit' + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit" }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'permit' + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "permit" }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_2_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit' + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_2_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit" }] }, - 'ipv6': { - 'pf_list_2_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'permit' + "ipv6": { + "pf_list_2_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "permit" }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) input_dict_3_addr_type ={} @@ -1626,7 +1632,7 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -1641,7 +1647,7 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): } input_dict_3_addr_type[addr_type] = input_dict_3 result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map @@ -1651,7 +1657,7 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -1666,12 +1672,12 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): } input_dict_3_addr_type[addr_type] = input_dict_3 result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_6 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -1683,7 +1689,7 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -1700,7 +1706,7 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -1714,21 +1720,21 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): } result = create_router_bgp(tgen, topo, input_dict_6) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" routes = { "ipv4": ["10.0.30.1/32"], "ipv6": ["1::1/128"] @@ -1737,7 +1743,7 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3_addr_type[addr_type]) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes @@ -1748,7 +1754,7 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): for addr_type in ADDR_TYPES: result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -1757,17 +1763,17 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): # tgen.mininet_cli() -def test_multiple_match_statement_in_route_map_logical_ANDed(): +def test_multiple_match_statement_in_route_map_logical_ANDed_p1(): """ TC_44: - Test multiple match statements as part of a route-map's single + Test multiple match statements as part of a route-map"s single sequence number. (Logical AND of multiple match statements) """ tgen = get_topogen() global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -1790,13 +1796,13 @@ def test_multiple_match_statement_in_route_map_logical_ANDed(): } } result = create_route_maps(tgen, input_dict_5) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map for addr_type in ADDR_TYPES: input_dict_6 = { - 'r1': { + "r1": { "bgp": { "address_family": { addr_type: { @@ -1808,7 +1814,7 @@ def test_multiple_match_statement_in_route_map_logical_ANDed(): "route_maps": [{ "name": "rm_r1_out_{}".format(addr_type), - "direction": 'out' + "direction": "out" }] } } @@ -1821,25 +1827,25 @@ def test_multiple_match_statement_in_route_map_logical_ANDed(): } } result = create_router_bgp(tgen, topo, input_dict_6) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit' + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit" }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'permit' + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "permit" }] } } @@ -1847,7 +1853,7 @@ def test_multiple_match_statement_in_route_map_logical_ANDed(): } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) for addr_type in ADDR_TYPES: @@ -1866,9 +1872,14 @@ def test_multiple_match_statement_in_route_map_logical_ANDed(): } } result = create_bgp_community_lists(tgen, input_dict_1) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) + # Verify BGP large community is created + result = verify_create_community_list(tgen, input_dict_1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result) + # Create route map for addr_type in ADDR_TYPES: input_dict_3 = { @@ -1876,7 +1887,7 @@ def test_multiple_match_statement_in_route_map_logical_ANDed(): "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -1890,7 +1901,7 @@ def test_multiple_match_statement_in_route_map_logical_ANDed(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) for addr_type in ADDR_TYPES: @@ -1900,7 +1911,7 @@ def test_multiple_match_statement_in_route_map_logical_ANDed(): "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type : { "large_community_list": {"id": "rmap_lcomm_"+ @@ -1915,12 +1926,12 @@ def test_multiple_match_statement_in_route_map_logical_ANDed(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map for addr_type in ADDR_TYPES: input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { addr_type: { @@ -1932,7 +1943,7 @@ def test_multiple_match_statement_in_route_map_logical_ANDed(): "route_maps": [{ "name": "rmap_match_pf_1_{}".format(addr_type), - "direction": 'in' + "direction": "in" }] } } @@ -1945,20 +1956,20 @@ def test_multiple_match_statement_in_route_map_logical_ANDed(): } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # sleep(10) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -1967,7 +1978,7 @@ def test_multiple_match_statement_in_route_map_logical_ANDed(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -1986,7 +1997,7 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -1995,27 +2006,27 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'deny' + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "deny" }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'deny' + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "deny" }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map @@ -2025,7 +2036,7 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -2039,12 +2050,12 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -2056,7 +2067,7 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -2073,7 +2084,7 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -2087,24 +2098,24 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) - assert result is not True, 'Testcase {} : \n' - 'Expected Behavior: Routes are not present in RIB \n' - ' Error: {}'.format( + protocol=protocol, expected=False) + assert result is not True, "Testcase {} : Failed \n Error" + "Routes are still present: {}".format( tc_name, result) + logger.info("Expected behaviour: {}".format(result)) # Remove applied rmap from neighbor input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -2116,7 +2127,7 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in', + "direction": "in", "delete": True }] } @@ -2134,7 +2145,7 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv6", - "direction": 'in', + "direction": "in", "delete": True }] } @@ -2149,16 +2160,16 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -2177,7 +2188,7 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -2186,27 +2197,27 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit' + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit" }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'permit' + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "permit" }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map @@ -2216,7 +2227,7 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -2231,12 +2242,12 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -2248,7 +2259,7 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -2265,7 +2276,7 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -2279,20 +2290,20 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -2301,26 +2312,26 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # clear bgp, so config changes would be reflected - dut = 'r3' + dut = "r3" result = clear_bgp_and_verify(tgen, topo, dut) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -2329,7 +2340,7 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Flap interface to see if route-map properties are intact @@ -2348,19 +2359,19 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): # Verify BGP convergence once interface is up result = verify_bgp_convergence(tgen, topo) assert result is True, ( - 'setup_module :Failed \n Error:' ' {}'.format(result)) + "setup_module :Failed \n Error:" " {}".format(result)) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -2369,7 +2380,7 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -2388,7 +2399,7 @@ def test_rmap_without_match_and_set_clause_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -2402,22 +2413,22 @@ def test_rmap_without_match_and_set_clause_p0(): "route_maps": { "rmap_no_match_set_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5' + "seq_id": "5" }], "rmap_no_match_set_2_{}".format(addr_type): [{ "action": "deny", - 'seq_id': '5' + "seq_id": "5" }] } } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -2429,7 +2440,7 @@ def test_rmap_without_match_and_set_clause_p0(): "route_maps": [{ "name": "rmap_no_match_set_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -2440,7 +2451,7 @@ def test_rmap_without_match_and_set_clause_p0(): "route_maps": [{ "name": "rmap_no_match_set_2_ipv4", - "direction": 'out' + "direction": "out" }] } } @@ -2457,7 +2468,7 @@ def test_rmap_without_match_and_set_clause_p0(): "route_maps": [{ "name": "rmap_no_match_set_1_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -2468,7 +2479,7 @@ def test_rmap_without_match_and_set_clause_p0(): "route_maps": [{ "name": "rmap_no_match_set_2_ipv6", - "direction": 'out' + "direction": "out" }] } } @@ -2482,30 +2493,30 @@ def test_rmap_without_match_and_set_clause_p0(): } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r4' - protocol = 'bgp' + dut = "r4" + protocol = "bgp" for addr_type in ADDR_TYPES: - result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is not True, 'Testcase {} : Failed \n' - 'Expected behaviour: routes are not present \n ' - 'Error: {}'.format( + result = verify_rib(tgen, addr_type, dut, input_dict, + protocol=protocol, expected=False) + assert result is not True, "Testcase {} : Failed \n" + "routes are not present \n Error: {}".format( tc_name, result) + logger.info("Expected behaviour: {}".format(result)) write_test_footer(tc_name) - # Uncomment next line for debugging # tgen.mininet_cli() @@ -2520,7 +2531,7 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -2529,27 +2540,27 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit' + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit" }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'permit' + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "permit" }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map @@ -2597,12 +2608,12 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): } input_dict_3_addr_type[addr_type] = input_dict_3 result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -2614,7 +2625,7 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -2625,7 +2636,7 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): "route_maps": [{ "name": "rmap_match_pf_2_ipv4", - "direction": 'out' + "direction": "out" }] } } @@ -2636,7 +2647,7 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): "route_maps": [{ "name": "rmap_match_pf_3_ipv4", - "direction": 'out' + "direction": "out" }] } } @@ -2653,7 +2664,7 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -2664,7 +2675,7 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): "route_maps": [{ "name": "rmap_match_pf_2_ipv6", - "direction": 'out' + "direction": "out" }] } } @@ -2675,7 +2686,7 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): "route_maps": [{ "name": "rmap_match_pf_3_ipv6", - "direction": 'out' + "direction": "out" }] } } @@ -2689,21 +2700,21 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -2713,20 +2724,20 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[ addr_type],rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r4' - protocol = 'bgp' + dut = "r4" + protocol = "bgp" for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r4' + dut = "r4" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -2736,22 +2747,23 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): rmap_name = "rmap_match_pf_2_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], - rmap_name, input_dict_3_addr_type[addr_type]) - assert result is not True, 'Testcase {} : Failed \n' - 'Expected behaviour: Attributes are not set \n' - 'Error: {}'.format( + rmap_name, input_dict_3_addr_type[addr_type], + expected=False) + assert result is not True, "Testcase {} : Failed \n" + "Attributes are not set \n Error: {}".format( tc_name, result) + logger.info("Expected behaviour: {}".format(result)) # Verifying RIB routes - dut = 'r5' - protocol = 'bgp' + dut = "r5" + protocol = "bgp" for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r5' + dut = "r5" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -2761,12 +2773,11 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): for addr_type in ADDR_TYPES: rmap_name = "rmap_match_pf_3_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], - rmap_name, input_dict_3_addr_type[addr_type]) - assert result is not True, 'Testcase {} : Failed \n' - 'Expected behaviour: Attributes are not set \n' - 'Error: {}'.format( + rmap_name, input_dict_3_addr_type[addr_type], + expected=False) + assert result is not True, "Testcase {} : Failed \n" + "Attributes are not set \n Error: {}".format( tc_name, result) - logger.info("Expected behaviour: {}".format(result)) write_test_footer(tc_name) @@ -2778,14 +2789,14 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): def test_multiple_set_on_single_sequence_in_rmap_p0(): """ TC_43: - Test multiple set statements as part of a route-map's + Test multiple set statements as part of a route-map"s single sequence number. """ tgen = get_topogen() global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -2794,27 +2805,27 @@ def test_multiple_set_on_single_sequence_in_rmap_p0(): # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit' + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit" }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'permit' + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "permit" }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map @@ -2839,12 +2850,12 @@ def test_multiple_set_on_single_sequence_in_rmap_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -2856,7 +2867,7 @@ def test_multiple_set_on_single_sequence_in_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -2873,7 +2884,7 @@ def test_multiple_set_on_single_sequence_in_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -2886,20 +2897,20 @@ def test_multiple_set_on_single_sequence_in_rmap_p0(): } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -2910,7 +2921,7 @@ def test_multiple_set_on_single_sequence_in_rmap_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -2928,7 +2939,7 @@ def test_route_maps_with_continue_clause_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -2937,27 +2948,27 @@ def test_route_maps_with_continue_clause_p0(): # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit' + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit" }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'permit' + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "permit" }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map @@ -2967,7 +2978,7 @@ def test_route_maps_with_continue_clause_p0(): "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '10', + "seq_id": "10", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -2980,7 +2991,7 @@ def test_route_maps_with_continue_clause_p0(): }, { "action": "permit", - 'seq_id': '20', + "seq_id": "20", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -2992,7 +3003,7 @@ def test_route_maps_with_continue_clause_p0(): }, { "action": "permit", - 'seq_id': '30', + "seq_id": "30", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -3007,12 +3018,12 @@ def test_route_maps_with_continue_clause_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -3024,7 +3035,7 @@ def test_route_maps_with_continue_clause_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -3041,7 +3052,7 @@ def test_route_maps_with_continue_clause_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -3054,21 +3065,21 @@ def test_route_maps_with_continue_clause_p0(): } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" rmap_name = "rmap_match_pf_1" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], @@ -3082,7 +3093,7 @@ def test_route_maps_with_continue_clause_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[ addr_type],rmap_name, input_dict_3, seq_id[addr_type]) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -3100,7 +3111,7 @@ def test_route_maps_with_goto_clause_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -3109,27 +3120,27 @@ def test_route_maps_with_goto_clause_p0(): # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit' + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit" }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'permit' + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "permit" }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map @@ -3139,7 +3150,7 @@ def test_route_maps_with_goto_clause_p0(): "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '10', + "seq_id": "10", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -3149,7 +3160,7 @@ def test_route_maps_with_goto_clause_p0(): }, { "action": "permit", - 'seq_id': '20', + "seq_id": "20", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -3161,7 +3172,7 @@ def test_route_maps_with_goto_clause_p0(): }, { "action": "permit", - 'seq_id': '30', + "seq_id": "30", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -3176,12 +3187,13 @@ def test_route_maps_with_goto_clause_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + # tgen.mininet_cli() + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -3193,7 +3205,7 @@ def test_route_maps_with_goto_clause_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -3210,7 +3222,7 @@ def test_route_maps_with_goto_clause_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -3223,20 +3235,20 @@ def test_route_maps_with_goto_clause_p0(): } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" rmap_name = "rmap_match_pf_1" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], @@ -3250,7 +3262,7 @@ def test_route_maps_with_goto_clause_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[ addr_type],rmap_name, input_dict_3, seq_id[addr_type]) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -3268,7 +3280,7 @@ def test_route_maps_with_call_clause_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -3277,27 +3289,27 @@ def test_route_maps_with_call_clause_p0(): # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit' + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit" }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'permit' + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "permit" }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map @@ -3332,12 +3344,12 @@ def test_route_maps_with_call_clause_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -3349,7 +3361,7 @@ def test_route_maps_with_call_clause_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -3366,7 +3378,7 @@ def test_route_maps_with_call_clause_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -3379,20 +3391,20 @@ def test_route_maps_with_call_clause_p0(): } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -3402,7 +3414,7 @@ def test_route_maps_with_call_clause_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) rmap_name = "rmap_match_pf_2" @@ -3410,7 +3422,7 @@ def test_route_maps_with_call_clause_p0(): rmap_name = "rmap_match_pf_2_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -3429,7 +3441,7 @@ def test_create_rmap_match_prefix_list_to_deny_in_and_outbound_prefixes_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -3438,27 +3450,27 @@ def test_create_rmap_match_prefix_list_to_deny_in_and_outbound_prefixes_p0(): # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit' + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit" }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'permit' + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "permit" }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map @@ -3492,12 +3504,12 @@ def test_create_rmap_match_prefix_list_to_deny_in_and_outbound_prefixes_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -3509,7 +3521,7 @@ def test_create_rmap_match_prefix_list_to_deny_in_and_outbound_prefixes_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -3520,7 +3532,7 @@ def test_create_rmap_match_prefix_list_to_deny_in_and_outbound_prefixes_p0(): "route_maps": [{ "name": "rmap_match_pf_2_ipv6", - "direction": 'out' + "direction": "out" }] } } @@ -3537,7 +3549,7 @@ def test_create_rmap_match_prefix_list_to_deny_in_and_outbound_prefixes_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -3548,7 +3560,7 @@ def test_create_rmap_match_prefix_list_to_deny_in_and_outbound_prefixes_p0(): "route_maps": [{ "name": "rmap_match_pf_2_ipv6", - "direction": 'out' + "direction": "out" }] } } @@ -3561,31 +3573,31 @@ def test_create_rmap_match_prefix_list_to_deny_in_and_outbound_prefixes_p0(): } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) - assert result is not True, 'Testcase {} : Failed \n' - 'Expected behaviour: routes are not present \n ' - 'Error: {}'.format( - tc_name, result) + protocol=protocol, expected=False) + assert result is not True, "Testcase {} : Failed \n" + "routes are not present \n Error: {}".\ + format(tc_name, result) + logger.info("Expected behaviour: {}".format(result)) # Verifying RIB routes - dut = 'r4' - protocol = 'bgp' + dut = "r4" + protocol = "bgp" for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) - assert result is not True, 'Testcase {} : Failed \n' - 'Expected behaviour: routes are not present \n ' - 'Error: {}'.format( - tc_name, result) + protocol=protocol, expected=False) + assert result is not True, "Testcase {} : Failed \n" + "routes are not present \n Error: {}".\ + format(tc_name, result) + logger.info("Expected behaviour: {}".format(result)) write_test_footer(tc_name) @@ -3603,7 +3615,7 @@ def test_create_rmap_to_match_tag_permit_inbound_prefixes_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -3675,12 +3687,12 @@ def test_create_rmap_to_match_tag_permit_inbound_prefixes_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r1': { + "r1": { "bgp": { "address_family": { "ipv4": { @@ -3692,7 +3704,7 @@ def test_create_rmap_to_match_tag_permit_inbound_prefixes_p0(): "route_maps": [{ "name": "rmap_match_tag_1_ipv4", - "direction": 'out' + "direction": "out" }] } } @@ -3709,7 +3721,7 @@ def test_create_rmap_to_match_tag_permit_inbound_prefixes_p0(): "route_maps": [{ "name": "rmap_match_tag_1_ipv6", - "direction": 'out' + "direction": "out" }] } } @@ -3722,12 +3734,12 @@ def test_create_rmap_to_match_tag_permit_inbound_prefixes_p0(): } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" for addr_type in ADDR_TYPES: input_dict = { @@ -3743,7 +3755,7 @@ def test_create_rmap_to_match_tag_permit_inbound_prefixes_p0(): } result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -3762,7 +3774,7 @@ def test_create_rmap_to_match_tag_deny_outbound_prefixes_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -3834,12 +3846,12 @@ def test_create_rmap_to_match_tag_deny_outbound_prefixes_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r1': { + "r1": { "bgp": { "address_family": { "ipv4": { @@ -3851,7 +3863,7 @@ def test_create_rmap_to_match_tag_deny_outbound_prefixes_p0(): "route_maps": [{ "name": "rmap_match_tag_1_ipv4", - "direction": 'out' + "direction": "out" }] } } @@ -3868,7 +3880,7 @@ def test_create_rmap_to_match_tag_deny_outbound_prefixes_p0(): "route_maps": [{ "name": "rmap_match_tag_1_ipv6", - "direction": 'out' + "direction": "out" }] } } @@ -3881,12 +3893,12 @@ def test_create_rmap_to_match_tag_deny_outbound_prefixes_p0(): } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" for addr_type in ADDR_TYPES: input_dict = { @@ -3901,16 +3913,17 @@ def test_create_rmap_to_match_tag_deny_outbound_prefixes_p0(): } } result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) - assert result is not True, 'Testcase {} : Failed \n' - 'Expected behavior: routes are denied \n Error: {}'.format( + protocol=protocol, expected=False) + assert result is not True, "Testcase {} : Failed \n" + "routes are denied \n Error: {}".format( tc_name, result) + logger.info("Expected behaviour: {}".format(result)) write_test_footer(tc_name) # Uncomment next line for debugging # tgen.mininet_cli() -if __name__ == '__main__': +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_aggregate-address_origin/__init__.py b/tests/topotests/bgp_aggregate-address_origin/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/topotests/bgp_aggregate-address_origin/__init__.py diff --git a/tests/topotests/bgp_aggregate-address_origin/r1/bgpd.conf b/tests/topotests/bgp_aggregate-address_origin/r1/bgpd.conf new file mode 100644 index 0000000000..528d02af36 --- /dev/null +++ b/tests/topotests/bgp_aggregate-address_origin/r1/bgpd.conf @@ -0,0 +1,7 @@ +router bgp 65000 + neighbor 192.168.255.2 remote-as 65001 + address-family ipv4 unicast + redistribute connected + aggregate-address 172.16.255.0/24 origin igp + exit-address-family +! diff --git a/tests/topotests/bgp_aggregate-address_origin/r1/zebra.conf b/tests/topotests/bgp_aggregate-address_origin/r1/zebra.conf new file mode 100644 index 0000000000..0a283c06d5 --- /dev/null +++ b/tests/topotests/bgp_aggregate-address_origin/r1/zebra.conf @@ -0,0 +1,9 @@ +! +interface lo + ip address 172.16.255.254/32 +! +interface r1-eth0 + ip address 192.168.255.1/24 +! +ip forwarding +! diff --git a/tests/topotests/bgp_aggregate-address_origin/r2/bgpd.conf b/tests/topotests/bgp_aggregate-address_origin/r2/bgpd.conf new file mode 100644 index 0000000000..73d4d0aeea --- /dev/null +++ b/tests/topotests/bgp_aggregate-address_origin/r2/bgpd.conf @@ -0,0 +1,4 @@ +router bgp 65001 + neighbor 192.168.255.1 remote-as 65000 + exit-address-family +! diff --git a/tests/topotests/bgp_aggregate-address_origin/r2/zebra.conf b/tests/topotests/bgp_aggregate-address_origin/r2/zebra.conf new file mode 100644 index 0000000000..606c17bec9 --- /dev/null +++ b/tests/topotests/bgp_aggregate-address_origin/r2/zebra.conf @@ -0,0 +1,6 @@ +! +interface r2-eth0 + ip address 192.168.255.2/24 +! +ip forwarding +! diff --git a/tests/topotests/bgp_aggregate-address_origin/test_bgp_aggregate-address_origin.py b/tests/topotests/bgp_aggregate-address_origin/test_bgp_aggregate-address_origin.py new file mode 100644 index 0000000000..be29d143dd --- /dev/null +++ b/tests/topotests/bgp_aggregate-address_origin/test_bgp_aggregate-address_origin.py @@ -0,0 +1,128 @@ +#!/usr/bin/env python + +# +# bgp_aggregate-address_origin.py +# Part of NetDEF Topology Tests +# +# Copyright (c) 2020 by +# Donatas Abraitis <donatas.abraitis@gmail.com> +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose with or without fee is hereby granted, provided +# that the above copyright notice and this permission notice appear +# in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY +# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS +# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +# OF THIS SOFTWARE. +# + +""" +bgp_aggregate-address_origin.py: + +Test if works the following commands: +router bgp 65031 + address-family ipv4 unicast + aggregate-address 192.168.255.0/24 origin igp +""" + +import os +import sys +import json +import time +import pytest +import functools + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, '../')) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topolog import logger +from mininet.topo import Topo + +class TemplateTopo(Topo): + def build(self, *_args, **_opts): + tgen = get_topogen(self) + + for routern in range(1, 3): + tgen.add_router('r{}'.format(routern)) + + switch = tgen.add_switch('s1') + switch.add_link(tgen.gears['r1']) + switch.add_link(tgen.gears['r2']) + +def setup_module(mod): + tgen = Topogen(TemplateTopo, mod.__name__) + tgen.start_topology() + + router_list = tgen.routers() + + for i, (rname, router) in enumerate(router_list.iteritems(), 1): + router.load_config( + TopoRouter.RD_ZEBRA, + os.path.join(CWD, '{}/zebra.conf'.format(rname)) + ) + router.load_config( + TopoRouter.RD_BGP, + os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + ) + + tgen.start_router() + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + +def test_bgp_aggregate_address_origin(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router = tgen.gears['r2'] + + def _bgp_converge(router): + output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json")) + expected = { + '192.168.255.1': { + 'bgpState': 'Established', + 'addressFamilyInfo': { + 'ipv4Unicast': { + 'acceptedPrefixCounter': 3 + } + } + } + } + return topotest.json_cmp(output, expected) + + def _bgp_aggregate_address_has_metric(router): + output = json.loads(router.vtysh_cmd("show ip bgp 172.16.255.0/24 json")) + expected = { + 'paths': [ + { + 'origin': 'IGP' + } + ] + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_converge, router) + success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) + + assert result is None, 'Failed to see bgp convergence in "{}"'.format(router) + + test_func = functools.partial(_bgp_aggregate_address_has_metric, router) + success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) + + assert result is None, 'Failed to see applied ORIGIN (igp) for aggregated prefix in "{}"'.format(router) + +if __name__ == '__main__': + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py b/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py index 7607fe986b..c851567dda 100755 --- a/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py +++ b/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py @@ -151,8 +151,7 @@ def setup_module(module): net['r%s' % i].startRouter() # Starting PE Hosts and init ExaBGP on each of them - print('*** Starting BGP on all 8 Peers in 10s') - sleep(10) + print('*** Starting BGP on all 8 Peers') for i in range(1, 9): net['peer%s' % i].cmd('cp %s/exabgp.env /etc/exabgp/exabgp.env' % thisDir) net['peer%s' % i].cmd('cp %s/peer%s/* /etc/exabgp/' % (thisDir, i)) @@ -191,7 +190,6 @@ def test_router_running(): print("\n\n** Check if FRR/Quagga is running on each Router node") print("******************************************\n") - sleep(5) # Starting Routers for i in range(1, 2): @@ -215,7 +213,7 @@ def test_bgp_converge(): # Wait for BGP to converge (All Neighbors in either Full or TwoWay State) print("\n\n** Verify for BGP to converge") print("******************************************\n") - timeout = 60 + timeout = 125 while timeout > 0: print("Timeout in %s: " % timeout), sys.stdout.flush() @@ -240,9 +238,9 @@ def test_bgp_converge(): bgpStatus = net['r%s' % i].cmd('vtysh -c "show ip bgp view %s summary"' % view) assert False, "BGP did not converge:\n%s" % bgpStatus - # Wait for an extra 30s to announce all routes - print('Waiting 30s for routes to be announced'); - sleep(30) + # Wait for an extra 5s to announce all routes + print('Waiting 5s for routes to be announced'); + sleep(5) print("BGP converged.") diff --git a/tests/topotests/bgp_set_local-preference_add_subtract/__init__.py b/tests/topotests/bgp_set_local-preference_add_subtract/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/topotests/bgp_set_local-preference_add_subtract/__init__.py diff --git a/tests/topotests/bgp_set_local-preference_add_subtract/r1/bgpd.conf b/tests/topotests/bgp_set_local-preference_add_subtract/r1/bgpd.conf new file mode 100644 index 0000000000..1a9c5325ad --- /dev/null +++ b/tests/topotests/bgp_set_local-preference_add_subtract/r1/bgpd.conf @@ -0,0 +1,5 @@ +router bgp 65000 + neighbor 192.168.255.2 remote-as 65000 + neighbor 192.168.255.3 remote-as 65000 + exit-address-family +! diff --git a/tests/topotests/bgp_set_local-preference_add_subtract/r1/zebra.conf b/tests/topotests/bgp_set_local-preference_add_subtract/r1/zebra.conf new file mode 100644 index 0000000000..6e9b0b4a7e --- /dev/null +++ b/tests/topotests/bgp_set_local-preference_add_subtract/r1/zebra.conf @@ -0,0 +1,6 @@ +! +interface r1-eth0 + ip address 192.168.255.1/24 +! +ip forwarding +! diff --git a/tests/topotests/bgp_set_local-preference_add_subtract/r2/bgpd.conf b/tests/topotests/bgp_set_local-preference_add_subtract/r2/bgpd.conf new file mode 100644 index 0000000000..89e1256667 --- /dev/null +++ b/tests/topotests/bgp_set_local-preference_add_subtract/r2/bgpd.conf @@ -0,0 +1,9 @@ +router bgp 65000 + neighbor 192.168.255.1 remote-as 65000 + address-family ipv4 + redistribute connected + neighbor 192.168.255.1 route-map r1-out out + exit-address-family +! +route-map r1-out permit 10 + set local-preference +50 diff --git a/tests/topotests/bgp_set_local-preference_add_subtract/r2/zebra.conf b/tests/topotests/bgp_set_local-preference_add_subtract/r2/zebra.conf new file mode 100644 index 0000000000..93e3590448 --- /dev/null +++ b/tests/topotests/bgp_set_local-preference_add_subtract/r2/zebra.conf @@ -0,0 +1,9 @@ +! +interface lo + ip address 172.16.255.254/32 +! +interface r2-eth0 + ip address 192.168.255.2/24 +! +ip forwarding +! diff --git a/tests/topotests/bgp_set_local-preference_add_subtract/r3/bgpd.conf b/tests/topotests/bgp_set_local-preference_add_subtract/r3/bgpd.conf new file mode 100644 index 0000000000..fabd4605f3 --- /dev/null +++ b/tests/topotests/bgp_set_local-preference_add_subtract/r3/bgpd.conf @@ -0,0 +1,9 @@ +router bgp 65000 + neighbor 192.168.255.1 remote-as 65000 + address-family ipv4 + redistribute connected + neighbor 192.168.255.1 route-map r1-out out + exit-address-family +! +route-map r1-out permit 10 + set local-preference -50 diff --git a/tests/topotests/bgp_set_local-preference_add_subtract/r3/zebra.conf b/tests/topotests/bgp_set_local-preference_add_subtract/r3/zebra.conf new file mode 100644 index 0000000000..b5e060c3d6 --- /dev/null +++ b/tests/topotests/bgp_set_local-preference_add_subtract/r3/zebra.conf @@ -0,0 +1,9 @@ +! +interface lo + ip address 172.16.255.254/32 +! +interface r3-eth0 + ip address 192.168.255.3/24 +! +ip forwarding +! diff --git a/tests/topotests/bgp_set_local-preference_add_subtract/test_bgp_set_local-preference_add_subtract.py b/tests/topotests/bgp_set_local-preference_add_subtract/test_bgp_set_local-preference_add_subtract.py new file mode 100644 index 0000000000..09e195e22d --- /dev/null +++ b/tests/topotests/bgp_set_local-preference_add_subtract/test_bgp_set_local-preference_add_subtract.py @@ -0,0 +1,147 @@ +#!/usr/bin/env python + +# +# bgp_set_local-preference_add_subtract.py +# Part of NetDEF Topology Tests +# +# Copyright (c) 2020 by +# Donatas Abraitis <donatas.abraitis@gmail.com> +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose with or without fee is hereby granted, provided +# that the above copyright notice and this permission notice appear +# in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY +# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS +# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +# OF THIS SOFTWARE. +# + +""" +bgp_set_local-preference_add_subtract.py: +Test if we can add/subtract the value to/from an existing +LOCAL_PREF in route-maps. +""" + +import os +import sys +import json +import time +import pytest +import functools + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, '../')) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topolog import logger +from mininet.topo import Topo + +class TemplateTopo(Topo): + def build(self, *_args, **_opts): + tgen = get_topogen(self) + + for routern in range(1, 4): + tgen.add_router('r{}'.format(routern)) + + switch = tgen.add_switch('s1') + switch.add_link(tgen.gears['r1']) + switch.add_link(tgen.gears['r2']) + switch.add_link(tgen.gears['r3']) + +def setup_module(mod): + tgen = Topogen(TemplateTopo, mod.__name__) + tgen.start_topology() + + router_list = tgen.routers() + + for i, (rname, router) in enumerate(router_list.iteritems(), 1): + router.load_config( + TopoRouter.RD_ZEBRA, + os.path.join(CWD, '{}/zebra.conf'.format(rname)) + ) + router.load_config( + TopoRouter.RD_BGP, + os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + ) + + tgen.start_router() + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + +def test_bgp_set_local_preference(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router = tgen.gears['r1'] + + def _bgp_converge(router): + output = json.loads(router.vtysh_cmd("show ip bgp neighbor json")) + expected = { + '192.168.255.2': { + 'bgpState': 'Established', + 'addressFamilyInfo': { + 'ipv4Unicast': { + 'acceptedPrefixCounter': 2 + } + } + }, + '192.168.255.3': { + 'bgpState': 'Established', + 'addressFamilyInfo': { + 'ipv4Unicast': { + 'acceptedPrefixCounter': 2 + } + } + } + } + return topotest.json_cmp(output, expected) + + def _bgp_check_local_preference(router): + output = json.loads(router.vtysh_cmd("show ip bgp 172.16.255.254/32 json")) + expected = { + 'paths': [ + { + 'localpref': 50, + 'nexthops': [ + { + 'ip': '192.168.255.3' + } + ] + }, + { + 'localpref': 150, + 'nexthops': [ + { + 'ip': '192.168.255.2' + } + ] + } + ] + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_converge, router) + success, result = topotest.run_and_expect(test_func, None, count=15, wait=0.5) + + assert result is None, 'Failed to see BGP convergence in "{}"'.format(router) + + test_func = functools.partial(_bgp_check_local_preference, router) + success, result = topotest.run_and_expect(test_func, None, count=15, wait=0.5) + + assert result is None, 'Failed to see applied BGP local-preference in "{}"'.format(router) + +if __name__ == '__main__': + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/evpn-pim-1/host1/bgpd.conf b/tests/topotests/evpn-pim-1/host1/bgpd.conf new file mode 100644 index 0000000000..cdf4cb4feb --- /dev/null +++ b/tests/topotests/evpn-pim-1/host1/bgpd.conf @@ -0,0 +1 @@ +! diff --git a/tests/topotests/evpn-pim-1/host1/pimd.conf b/tests/topotests/evpn-pim-1/host1/pimd.conf new file mode 100644 index 0000000000..63a44c1333 --- /dev/null +++ b/tests/topotests/evpn-pim-1/host1/pimd.conf @@ -0,0 +1,4 @@ +int lo +! + + diff --git a/tests/topotests/evpn-pim-1/host1/zebra.conf b/tests/topotests/evpn-pim-1/host1/zebra.conf new file mode 100644 index 0000000000..45ad031017 --- /dev/null +++ b/tests/topotests/evpn-pim-1/host1/zebra.conf @@ -0,0 +1,5 @@ +int host1-eth0 + ip addr 192.168.3.4/24 + +int lo + ip addr 192.168.100.4/32 diff --git a/tests/topotests/evpn-pim-1/host2/bgpd.conf b/tests/topotests/evpn-pim-1/host2/bgpd.conf new file mode 100644 index 0000000000..cdf4cb4feb --- /dev/null +++ b/tests/topotests/evpn-pim-1/host2/bgpd.conf @@ -0,0 +1 @@ +! diff --git a/tests/topotests/evpn-pim-1/host2/pimd.conf b/tests/topotests/evpn-pim-1/host2/pimd.conf new file mode 100644 index 0000000000..63a44c1333 --- /dev/null +++ b/tests/topotests/evpn-pim-1/host2/pimd.conf @@ -0,0 +1,4 @@ +int lo +! + + diff --git a/tests/topotests/evpn-pim-1/host2/zebra.conf b/tests/topotests/evpn-pim-1/host2/zebra.conf new file mode 100644 index 0000000000..bfae53017f --- /dev/null +++ b/tests/topotests/evpn-pim-1/host2/zebra.conf @@ -0,0 +1,5 @@ +int host-eth0 + ip addr 192.168.4.5/24 + +int lo + ip addr 192.168.100.5/32 diff --git a/tests/topotests/evpn-pim-1/leaf1/bgpd.conf b/tests/topotests/evpn-pim-1/leaf1/bgpd.conf new file mode 100644 index 0000000000..33d34db677 --- /dev/null +++ b/tests/topotests/evpn-pim-1/leaf1/bgpd.conf @@ -0,0 +1,9 @@ + +router bgp 65002 + neighbor 192.168.1.1 remote-as external + redistribute connected + address-family l2vpn evpn + neighbor 192.168.1.1 activate + advertise-all-vni + ! +!
\ No newline at end of file diff --git a/tests/topotests/evpn-pim-1/leaf1/pimd.conf b/tests/topotests/evpn-pim-1/leaf1/pimd.conf new file mode 100644 index 0000000000..293e252086 --- /dev/null +++ b/tests/topotests/evpn-pim-1/leaf1/pimd.conf @@ -0,0 +1,15 @@ +debug pim events +debug pim nht +debug pim zebra +ip pim rp 192.168.100.1 +! +int lo + ip pim +! +int leaf1-eth0 + ip pim +! +int leaf1-eth1 + ip pim + ip igmp + diff --git a/tests/topotests/evpn-pim-1/leaf1/zebra.conf b/tests/topotests/evpn-pim-1/leaf1/zebra.conf new file mode 100644 index 0000000000..581cc6e7be --- /dev/null +++ b/tests/topotests/evpn-pim-1/leaf1/zebra.conf @@ -0,0 +1,6 @@ +int leaf1-eth0 + ip addr 192.168.1.2/24 +int leaf1-eth1 + ip addr 192.168.3.2/24 +int lo + ip addr 192.168.100.2/32 diff --git a/tests/topotests/evpn-pim-1/leaf2/bgpd.conf b/tests/topotests/evpn-pim-1/leaf2/bgpd.conf new file mode 100644 index 0000000000..3dd9f237be --- /dev/null +++ b/tests/topotests/evpn-pim-1/leaf2/bgpd.conf @@ -0,0 +1,9 @@ + +router bgp 65003 + neighbor 192.168.2.1 remote-as external + redistribute connected + address-family l2vpn evpn + neighbor 192.168.2.1 activate + advertise-all-vni + ! +!
\ No newline at end of file diff --git a/tests/topotests/evpn-pim-1/leaf2/pimd.conf b/tests/topotests/evpn-pim-1/leaf2/pimd.conf new file mode 100644 index 0000000000..08d5a19a2a --- /dev/null +++ b/tests/topotests/evpn-pim-1/leaf2/pimd.conf @@ -0,0 +1,13 @@ +ip pim rp 192.168.100.1 +! +int lo + ip pim +! +int leaf2-eth0 + ip pim +! +int leaf2-eth1 + ip pim + ip igmp +! + diff --git a/tests/topotests/evpn-pim-1/leaf2/zebra.conf b/tests/topotests/evpn-pim-1/leaf2/zebra.conf new file mode 100644 index 0000000000..1bcf8e1ded --- /dev/null +++ b/tests/topotests/evpn-pim-1/leaf2/zebra.conf @@ -0,0 +1,6 @@ +int leaf2-eth0 + ip addr 192.168.2.3/24 +int leaf2-eth1 + ip addr 192.168.4.3/24 +int lo + ip addr 192.168.100.3/32 diff --git a/tests/topotests/evpn-pim-1/spine/bgp.summ.json b/tests/topotests/evpn-pim-1/spine/bgp.summ.json new file mode 100644 index 0000000000..faf40c8d43 --- /dev/null +++ b/tests/topotests/evpn-pim-1/spine/bgp.summ.json @@ -0,0 +1,44 @@ +{ + "routerId":"192.168.100.1", + "as":65001, + "vrfId":0, + "vrfName":"default", + "tableVersion":7, + "peerCount":2, + "peers":{ + "192.168.1.2":{ + "remoteAs":65002, + "version":4, + "tableVersion":0, + "outq":0, + "inq":0, + "prefixReceivedCount":3, + "pfxRcd":3, + "pfxSnt":7, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv4" + }, + "192.168.2.3":{ + "remoteAs":65003, + "version":4, + "tableVersion":0, + "outq":0, + "inq":0, + "prefixReceivedCount":3, + "pfxRcd":3, + "pfxSnt":7, + "state":"Established", + "connectionsEstablished":1, + "connectionsDropped":0, + "idType":"ipv4" + } + }, + "failedPeers":0, + "totalPeers":2, + "dynamicPeers":0, + "bestPath":{ + "multiPathRelax":"false" + } +} diff --git a/tests/topotests/evpn-pim-1/spine/bgpd.conf b/tests/topotests/evpn-pim-1/spine/bgpd.conf new file mode 100644 index 0000000000..9a845043e9 --- /dev/null +++ b/tests/topotests/evpn-pim-1/spine/bgpd.conf @@ -0,0 +1,10 @@ + +router bgp 65001 + neighbor 192.168.1.2 remote-as external + neighbor 192.168.2.3 remote-as external + redistribute connected + address-family l2vpn evpn + neighbor 192.168.1.2 activate + neighbor 192.168.2.3 activate + exit-address-family +! diff --git a/tests/topotests/evpn-pim-1/spine/join-info.json b/tests/topotests/evpn-pim-1/spine/join-info.json new file mode 100644 index 0000000000..3d135fb964 --- /dev/null +++ b/tests/topotests/evpn-pim-1/spine/join-info.json @@ -0,0 +1,34 @@ +{ + "spine-eth0":{ + "name":"spine-eth0", + "state":"up", + "address":"192.168.1.1", + "flagMulticast":true, + "flagBroadcast":true, + "lanDelayEnabled":true, + "239.1.1.1":{ + "*":{ + "source":"*", + "group":"239.1.1.1", + "prune":"--:--", + "channelJoinName":"JOIN" + } + } + }, + "spine-eth1":{ + "name":"spine-eth1", + "state":"up", + "address":"192.168.2.1", + "flagMulticast":true, + "flagBroadcast":true, + "lanDelayEnabled":true, + "239.1.1.1":{ + "*":{ + "source":"*", + "group":"239.1.1.1", + "prune":"--:--", + "channelJoinName":"JOIN" + } + } + } +} diff --git a/tests/topotests/evpn-pim-1/spine/pimd.conf b/tests/topotests/evpn-pim-1/spine/pimd.conf new file mode 100644 index 0000000000..56adda5cc4 --- /dev/null +++ b/tests/topotests/evpn-pim-1/spine/pimd.conf @@ -0,0 +1,13 @@ +ip pim rp 192.168.100.1 +! +int lo + ip pim +! +int spine-eth0 + ip pim +! +int spine-eth1 + ip pim +! + + diff --git a/tests/topotests/evpn-pim-1/spine/zebra.conf b/tests/topotests/evpn-pim-1/spine/zebra.conf new file mode 100644 index 0000000000..2cb719486e --- /dev/null +++ b/tests/topotests/evpn-pim-1/spine/zebra.conf @@ -0,0 +1,8 @@ +int spine-eth0 + ip addr 192.168.1.1/24 +! +int spine-eth1 + ip addr 192.168.2.1/24 +! +int lo + ip addr 192.168.100.1/32 diff --git a/tests/topotests/evpn-pim-1/test_evpn_pim_topo1.py b/tests/topotests/evpn-pim-1/test_evpn_pim_topo1.py new file mode 100755 index 0000000000..dafe2e03ac --- /dev/null +++ b/tests/topotests/evpn-pim-1/test_evpn_pim_topo1.py @@ -0,0 +1,215 @@ +#!/usr/bin/env python + +# +# test_evpn-pim_topo1.py +# +# Copyright (c) 2017 by +# Cumulus Networks, Inc. +# Donald Sharp +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose with or without fee is hereby granted, provided +# that the above copyright notice and this permission notice appear +# in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY +# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS +# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +# OF THIS SOFTWARE. +# + +""" +test_evpn_pim_topo1.py: Testing evpn-pim + +""" + +import os +import re +import sys +import pytest +import json +from functools import partial + +# Save the Current Working Directory to find configuration files. +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, '../')) + +# pylint: disable=C0413 +# Import topogen and topotest helpers +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topolog import logger + +# Required to instantiate the topology builder class. +from mininet.topo import Topo + +##################################################### +## +## Network Topology Definition +## +##################################################### + +class NetworkTopo(Topo): + "evpn-pim Topology 1" + + def build(self, **_opts): + "Build function" + + tgen = get_topogen(self) + + tgen.add_router('spine') + tgen.add_router('leaf1') + tgen.add_router('leaf2') + tgen.add_router('host1') + tgen.add_router('host2') + + # On main router + # First switch is for a dummy interface (for local network) + # spine-eth0 is connected to leaf1-eth0 + switch = tgen.add_switch('sw1') + switch.add_link(tgen.gears['spine']) + switch.add_link(tgen.gears['leaf1']) + + # spine-eth1 is connected to leaf2-eth0 + switch = tgen.add_switch('sw2') + switch.add_link(tgen.gears['spine']) + switch.add_link(tgen.gears['leaf2']) + + # leaf1-eth1 is connected to host1-eth0 + switch = tgen.add_switch('sw3') + switch.add_link(tgen.gears['leaf1']) + switch.add_link(tgen.gears['host1']) + + # leaf2-eth1 is connected to host2-eth0 + switch = tgen.add_switch('sw4') + switch.add_link(tgen.gears['leaf2']) + switch.add_link(tgen.gears['host2']) + + + +##################################################### +## +## Tests starting +## +##################################################### + +def setup_module(module): + "Setup topology" + tgen = Topogen(NetworkTopo, module.__name__) + tgen.start_topology() + + leaf1 = tgen.gears['leaf1'] + leaf2 = tgen.gears['leaf2'] + + leaf1.run('brctl addbr brleaf1') + leaf2.run('brctl addbr brleaf2') + leaf1.run('ip link set dev brleaf1 up') + leaf2.run('ip link set dev brleaf2 up') + leaf1.run('ip link add vxlan0 type vxlan id 42 group 239.1.1.1 dev leaf1-eth1 dstport 4789') + leaf2.run('ip link add vxlan0 type vxlan id 42 group 239.1.1.1 dev leaf2-eth1 dstport 4789') + leaf1.run('brctl addif brleaf1 vxlan0') + leaf2.run('brctl addif brleaf2 vxlan0') + leaf1.run('ip link set up dev vxlan0') + leaf2.run('ip link set up dev vxlan0') + #tgen.mininet_cli() + # This is a sample of configuration loading. + router_list = tgen.routers() + for rname, router in router_list.iteritems(): + router.load_config( + TopoRouter.RD_ZEBRA, + os.path.join(CWD, '{}/zebra.conf'.format(rname)) + ) + router.load_config( + TopoRouter.RD_BGP, + os.path.join(CWD, '{}/bgpd.conf'.format(rname)) + ) + router.load_config( + TopoRouter.RD_PIM, + os.path.join(CWD, '{}/pimd.conf'.format(rname)) + ) + tgen.start_router() + #tgen.mininet_cli() + +def teardown_module(_mod): + "Teardown the pytest environment" + tgen = get_topogen() + + # This function tears down the whole topology. + tgen.stop_topology() + + +def test_converge_protocols(): + "Wait for protocol convergence" + + tgen = get_topogen() + # Don't run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + spine = tgen.gears['spine'] + json_file = '{}/{}/bgp.summ.json'.format(CWD, spine.name) + expected = json.loads(open(json_file).read()) + + test_func = partial(topotest.router_json_cmp, + spine, 'show bgp ipv4 uni summ json', expected) + _, result = topotest.run_and_expect(test_func, None, count=125, wait=1) + assertmsg = '"{}" JSON output mismatches'.format(spine.name) + assert result is None, assertmsg + #tgen.mininet_cli() + +def test_multicast_groups_on_rp(): + "Ensure the multicast groups show up on the spine" + # This test implicitly tests the auto mcast groups + # of the created vlans and then the auto-joins that + # pim will do to the RP( spine ) + + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + spine = tgen.gears['spine'] + json_file = '{}/{}/join-info.json'.format(CWD, spine.name) + expected = json.loads(open(json_file).read()) + + test_func = partial(topotest.router_json_cmp, + spine, 'show ip pim join json', expected) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assertmsg = '"{}" JSON output mismatches'.format(spine.name) + assert result is None, assertmsg + #tgen.mininet_cli() + +def test_shutdown_check_stderr(): + if os.environ.get('TOPOTESTS_CHECK_STDERR') is None: + pytest.skip('Skipping test for Stderr output and memory leaks') + + tgen = get_topogen() + # Don't run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + logger.info("Verifying unexpected STDERR output from daemons") + + router_list = tgen.routers().values() + for router in router_list: + router.stop() + + log = tgen.net[router.name].getStdErr('pimd') + if log: + logger.error('PIMd StdErr Log:' + log) + log = tgen.net[router.name].getStdErr('bgpd') + if log: + logger.error('BGPd StdErr Log:' + log) + log = tgen.net[router.name].getStdErr('zebra') + if log: + logger.error('Zebra StdErr Log:' + log) + + +if __name__ == '__main__': + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) + diff --git a/tests/topotests/lib/bgp.py b/tests/topotests/lib/bgp.py index a8354f4c77..997b72d691 100644 --- a/tests/topotests/lib/bgp.py +++ b/tests/topotests/lib/bgp.py @@ -382,8 +382,8 @@ def __create_bgp_neighbor(topo, input_dict, router, addr_type, add_neigh=True): disable_connected = peer.setdefault("disable_connected_check", False) - keep_alive = peer.setdefault("keep_alive", 60) - hold_down = peer.setdefault("hold_down", 180) + keep_alive = peer.setdefault("keepalivetimer", 60) + hold_down = peer.setdefault("holddowntimer", 180) password = peer.setdefault("password", None) max_hop_limit = peer.setdefault("ebgp_multihop", 1) @@ -1293,16 +1293,13 @@ def verify_bgp_attributes(tgen, addr_type, dut, static_routes, rmap_name, for static_route in static_routes: cmd = "show bgp {} {} json".format(addr_type, static_route) show_bgp_json = run_frr_cmd(rnode, cmd, isjson=True) - print("show_bgp_json $$$$$", show_bgp_json) dict_to_test = [] tmp_list = [] for rmap_router in input_dict.keys(): for rmap, values in input_dict[rmap_router][ "route_maps"].items(): - print("rmap == rmap_name $$$$1", rmap, rmap_name) if rmap == rmap_name: - print("rmap == rmap_name $$$$", rmap, rmap_name) dict_to_test = values for rmap_dict in values: if seq_id is not None: @@ -1318,7 +1315,6 @@ def verify_bgp_attributes(tgen, addr_type, dut, static_routes, rmap_name, if tmp_list: dict_to_test = tmp_list - print("dict_to_test $$$$", dict_to_test) for rmap_dict in dict_to_test: if "set" in rmap_dict: for criteria in rmap_dict["set"].keys(): diff --git a/tests/topotests/rip-topo1/r1/rip_status.ref b/tests/topotests/rip-topo1/r1/rip_status.ref index 30c840e508..d75fbe85bb 100644 --- a/tests/topotests/rip-topo1/r1/rip_status.ref +++ b/tests/topotests/rip-topo1/r1/rip_status.ref @@ -1,6 +1,6 @@ Routing Protocol is "rip" - Sending updates every 30 seconds with +/-50%, next due in XX seconds - Timeout after 180 seconds, garbage collect after 120 seconds + Sending updates every 5 seconds with +/-50%, next due in XX seconds + Timeout after 180 seconds, garbage collect after 5 seconds Outgoing update filter list for all interface is not set Incoming update filter list for all interface is not set Default redistribution metric is 1 diff --git a/tests/topotests/rip-topo1/r1/ripd.conf b/tests/topotests/rip-topo1/r1/ripd.conf index 70e70d3590..935ec312e5 100644 --- a/tests/topotests/rip-topo1/r1/ripd.conf +++ b/tests/topotests/rip-topo1/r1/ripd.conf @@ -1,6 +1,7 @@ log file ripd.log ! router rip + timers basic 5 180 5 version 2 network 193.1.1.0/26 ! diff --git a/tests/topotests/rip-topo1/r2/rip_status.ref b/tests/topotests/rip-topo1/r2/rip_status.ref index b539d321d5..da1abd041a 100644 --- a/tests/topotests/rip-topo1/r2/rip_status.ref +++ b/tests/topotests/rip-topo1/r2/rip_status.ref @@ -1,6 +1,6 @@ Routing Protocol is "rip" - Sending updates every 30 seconds with +/-50%, next due in XX seconds - Timeout after 180 seconds, garbage collect after 120 seconds + Sending updates every 5 seconds with +/-50%, next due in XX seconds + Timeout after 180 seconds, garbage collect after 5 seconds Outgoing update filter list for all interface is not set Incoming update filter list for all interface is not set Default redistribution metric is 1 diff --git a/tests/topotests/rip-topo1/r2/ripd.conf b/tests/topotests/rip-topo1/r2/ripd.conf index 179a1ebd0f..2e94cfa262 100644 --- a/tests/topotests/rip-topo1/r2/ripd.conf +++ b/tests/topotests/rip-topo1/r2/ripd.conf @@ -3,6 +3,7 @@ log file ripd.log ! router rip version 2 + timers basic 5 180 5 network 193.1.1.0/26 network 193.1.2.0/24 ! diff --git a/tests/topotests/rip-topo1/r3/rip_status.ref b/tests/topotests/rip-topo1/r3/rip_status.ref index 0e3a4be944..040d3c32a1 100644 --- a/tests/topotests/rip-topo1/r3/rip_status.ref +++ b/tests/topotests/rip-topo1/r3/rip_status.ref @@ -1,6 +1,6 @@ Routing Protocol is "rip" - Sending updates every 30 seconds with +/-50%, next due in XX seconds - Timeout after 180 seconds, garbage collect after 120 seconds + Sending updates every 5 seconds with +/-50%, next due in XX seconds + Timeout after 180 seconds, garbage collect after 5 seconds Outgoing update filter list for all interface is not set Incoming update filter list for all interface is not set Default redistribution metric is 1 diff --git a/tests/topotests/rip-topo1/r3/ripd.conf b/tests/topotests/rip-topo1/r3/ripd.conf index 363b91b33a..e27e67503f 100644 --- a/tests/topotests/rip-topo1/r3/ripd.conf +++ b/tests/topotests/rip-topo1/r3/ripd.conf @@ -3,6 +3,7 @@ log file ripd.log ! router rip version 2 + timers basic 5 180 5 redistribute connected redistribute static network 193.1.2.0/24 diff --git a/tests/topotests/rip-topo1/test_rip_topo1.py b/tests/topotests/rip-topo1/test_rip_topo1.py index 7aaaacacfb..8f3c25e910 100755 --- a/tests/topotests/rip-topo1/test_rip_topo1.py +++ b/tests/topotests/rip-topo1/test_rip_topo1.py @@ -144,7 +144,6 @@ def test_router_running(): print("\n\n** Check if FRR/Quagga is running on each Router node") print("******************************************\n") - sleep(5) # Make sure that all daemons are running for i in range(1, 4): @@ -168,8 +167,8 @@ def test_converge_protocols(): print("\n\n** Waiting for protocols convergence") print("******************************************\n") - # Not really implemented yet - just sleep 60 secs for now - sleep(60) + # Not really implemented yet - just sleep 11 secs for now + sleep(11) # Make sure that all daemons are still running for i in range(1, 4): diff --git a/tests/topotests/ripng-topo1/r1/ripng_status.ref b/tests/topotests/ripng-topo1/r1/ripng_status.ref index 48816c1a9b..e6197f179b 100644 --- a/tests/topotests/ripng-topo1/r1/ripng_status.ref +++ b/tests/topotests/ripng-topo1/r1/ripng_status.ref @@ -1,6 +1,6 @@ Routing Protocol is "RIPng" - Sending updates every 30 seconds with +/-50%, next due in XX seconds - Timeout after 180 seconds, garbage collect after 120 seconds + Sending updates every 5 seconds with +/-50%, next due in XX seconds + Timeout after 180 seconds, garbage collect after 5 seconds Outgoing update filter list for all interface is not set Incoming update filter list for all interface is not set Default redistribution metric is 1 diff --git a/tests/topotests/ripng-topo1/r1/ripngd.conf b/tests/topotests/ripng-topo1/r1/ripngd.conf index 5eb78eafe2..dd54c43557 100644 --- a/tests/topotests/ripng-topo1/r1/ripngd.conf +++ b/tests/topotests/ripng-topo1/r1/ripngd.conf @@ -5,6 +5,7 @@ debug ripng packet debug ripng zebra ! router ripng + timers basic 5 180 5 network fc00:5::/64 ! line vty diff --git a/tests/topotests/ripng-topo1/r2/ripng_status.ref b/tests/topotests/ripng-topo1/r2/ripng_status.ref index fddcf63e5b..640df9a4a0 100644 --- a/tests/topotests/ripng-topo1/r2/ripng_status.ref +++ b/tests/topotests/ripng-topo1/r2/ripng_status.ref @@ -1,6 +1,6 @@ Routing Protocol is "RIPng" - Sending updates every 30 seconds with +/-50%, next due in XX seconds - Timeout after 180 seconds, garbage collect after 120 seconds + Sending updates every 5 seconds with +/-50%, next due in XX seconds + Timeout after 180 seconds, garbage collect after 5 seconds Outgoing update filter list for all interface is not set Incoming update filter list for all interface is not set Default redistribution metric is 1 diff --git a/tests/topotests/ripng-topo1/r2/ripngd.conf b/tests/topotests/ripng-topo1/r2/ripngd.conf index a25a3cd490..ef2c42195d 100644 --- a/tests/topotests/ripng-topo1/r2/ripngd.conf +++ b/tests/topotests/ripng-topo1/r2/ripngd.conf @@ -5,6 +5,7 @@ debug ripng packet debug ripng zebra ! router ripng + timers basic 5 180 5 network fc00:5::/64 network fc00:6::/62 ! diff --git a/tests/topotests/ripng-topo1/r3/ripng_status.ref b/tests/topotests/ripng-topo1/r3/ripng_status.ref index 1a8dabbf5f..f4bfff0c59 100644 --- a/tests/topotests/ripng-topo1/r3/ripng_status.ref +++ b/tests/topotests/ripng-topo1/r3/ripng_status.ref @@ -1,6 +1,6 @@ Routing Protocol is "RIPng" - Sending updates every 30 seconds with +/-50%, next due in XX seconds - Timeout after 180 seconds, garbage collect after 120 seconds + Sending updates every 5 seconds with +/-50%, next due in XX seconds + Timeout after 180 seconds, garbage collect after 5 seconds Outgoing update filter list for all interface is not set Incoming update filter list for all interface is not set Default redistribution metric is 1 diff --git a/tests/topotests/ripng-topo1/r3/ripngd.conf b/tests/topotests/ripng-topo1/r3/ripngd.conf index dfa5700adb..506eaac442 100644 --- a/tests/topotests/ripng-topo1/r3/ripngd.conf +++ b/tests/topotests/ripng-topo1/r3/ripngd.conf @@ -5,6 +5,7 @@ debug ripng packet debug ripng zebra ! router ripng + timers basic 5 180 5 network fc00:6::/62 redistribute connected redistribute static diff --git a/tests/topotests/ripng-topo1/test_ripng_topo1.py b/tests/topotests/ripng-topo1/test_ripng_topo1.py index 145b1a7efe..32b137240c 100755 --- a/tests/topotests/ripng-topo1/test_ripng_topo1.py +++ b/tests/topotests/ripng-topo1/test_ripng_topo1.py @@ -145,7 +145,6 @@ def test_router_running(): print("\n\n** Check if FRR/Quagga is running on each Router node") print("******************************************\n") - sleep(5) # Starting Routers for i in range(1, 4): @@ -169,8 +168,8 @@ def test_converge_protocols(): print("\n\n** Waiting for protocols convergence") print("******************************************\n") - # Not really implemented yet - just sleep 60 secs for now - sleep(60) + # Not really implemented yet - just sleep 11 secs for now + sleep(11) # Make sure that all daemons are running for i in range(1, 4): diff --git a/tools/coccinelle/__func__.cocci b/tools/coccinelle/__func__.cocci new file mode 100644 index 0000000000..fb68494d43 --- /dev/null +++ b/tools/coccinelle/__func__.cocci @@ -0,0 +1,10 @@ +@@ +@@ + +( +- __PRETTY_FUNCTION__ ++ __func__ +| +- __FUNCTION__ ++ __func__ +) diff --git a/tools/coccinelle/bool_assignment.cocci b/tools/coccinelle/bool_assignment.cocci new file mode 100644 index 0000000000..e6146ea310 --- /dev/null +++ b/tools/coccinelle/bool_assignment.cocci @@ -0,0 +1,13 @@ +@@ +bool b; +@@ + +( + b = +- 0 ++ false +| + b = +- 1 ++ true +) diff --git a/tools/coccinelle/bool_expression.cocci b/tools/coccinelle/bool_expression.cocci new file mode 100644 index 0000000000..c0c329cb59 --- /dev/null +++ b/tools/coccinelle/bool_expression.cocci @@ -0,0 +1,29 @@ +@@ +bool t; +@@ + +( +- t == true ++ t +| +- true == t ++ t +| +- t != true ++ !t +| +- true != t ++ !t +| +- t == false ++ !t +| +- false == t ++ !t +| +- t != false ++ t +| +- false != t ++ t +) diff --git a/tools/coccinelle/bool_function.cocci b/tools/coccinelle/bool_function.cocci new file mode 100644 index 0000000000..0328ecfbbe --- /dev/null +++ b/tools/coccinelle/bool_function.cocci @@ -0,0 +1,21 @@ +@@ +identifier fn; +typedef bool; +symbol false; +symbol true; +@@ + +bool fn ( ... ) +{ +<... +return +( +- 0 ++ false +| +- 1 ++ true +) + ; +...> +} diff --git a/tools/coccinelle/bool_function_type.cocci b/tools/coccinelle/bool_function_type.cocci new file mode 100644 index 0000000000..71bf4f53b8 --- /dev/null +++ b/tools/coccinelle/bool_function_type.cocci @@ -0,0 +1,19 @@ +@@ +identifier fn; +typedef bool; +symbol false; +symbol true; +@@ + +- int ++ bool +fn (...) +{ +?... +return +( + true +| + false +); +} diff --git a/scripts/coccinelle/replace_bgp_flag_functions.cocci b/tools/coccinelle/replace_bgp_flag_functions.cocci index 3064fc0267..3064fc0267 100644 --- a/scripts/coccinelle/replace_bgp_flag_functions.cocci +++ b/tools/coccinelle/replace_bgp_flag_functions.cocci diff --git a/scripts/coccinelle/return_without_parenthesis.cocci b/tools/coccinelle/return_without_parenthesis.cocci index 7097e87ddc..7097e87ddc 100644 --- a/scripts/coccinelle/return_without_parenthesis.cocci +++ b/tools/coccinelle/return_without_parenthesis.cocci diff --git a/scripts/coccinelle/s_addr_0_to_INADDR_ANY.cocci b/tools/coccinelle/s_addr_0_to_INADDR_ANY.cocci index bd7f4af4f2..bd7f4af4f2 100644 --- a/scripts/coccinelle/s_addr_0_to_INADDR_ANY.cocci +++ b/tools/coccinelle/s_addr_0_to_INADDR_ANY.cocci diff --git a/scripts/coccinelle/shorthand_operator.cocci b/tools/coccinelle/shorthand_operator.cocci index f7019d4040..f7019d4040 100644 --- a/scripts/coccinelle/shorthand_operator.cocci +++ b/tools/coccinelle/shorthand_operator.cocci diff --git a/tools/coccinelle/test_after_assert.cocci b/tools/coccinelle/test_after_assert.cocci new file mode 100644 index 0000000000..30596a89c2 --- /dev/null +++ b/tools/coccinelle/test_after_assert.cocci @@ -0,0 +1,7 @@ +@@ +identifier i; +@@ + +assert(i); +- if (!i) +- return ...; diff --git a/scripts/coccinelle/void_no_return.cocci b/tools/coccinelle/void_no_return.cocci index 7da9e73933..7da9e73933 100644 --- a/scripts/coccinelle/void_no_return.cocci +++ b/tools/coccinelle/void_no_return.cocci diff --git a/vrrpd/vrrp.c b/vrrpd/vrrp.c index 03a08dd86b..3ef9fd90aa 100644 --- a/vrrpd/vrrp.c +++ b/vrrpd/vrrp.c @@ -185,6 +185,11 @@ static bool vrrp_ifp_has_vrrp_mac(struct interface *ifp) * is used to look up any existing instances that match the interface. It does * not matter whether the instance is already bound to the interface or not. * + * Note that the interface linkages must be correct for this to work. In other + * words, the macvlan must have a valid VRRP MAC, and its link_ifindex must be + * be equal to the ifindex of another interface in the interface RB trees (its + * parent). If these conditions aren't satisfied we won't find the VR. + * * mvl_ifp * Interface pointer to use to lookup. Should be a macvlan device. * @@ -953,7 +958,7 @@ static int vrrp_recv_advertisement(struct vrrp_router *r, struct ipaddr *src, thread_add_timer_msec( master, vrrp_master_down_timer_expire, r, r->skew_time * CS2MS, &r->t_master_down_timer); - } else if (r->vr->preempt_mode == false + } else if (!r->vr->preempt_mode || pkt->hdr.priority >= r->priority) { if (r->vr->version == 3) { r->master_adver_interval = @@ -965,7 +970,7 @@ static int vrrp_recv_advertisement(struct vrrp_router *r, struct ipaddr *src, vrrp_master_down_timer_expire, r, r->master_down_interval * CS2MS, &r->t_master_down_timer); - } else if (r->vr->preempt_mode == true + } else if (r->vr->preempt_mode && pkt->hdr.priority < r->priority) { /* Discard advertisement */ DEBUGD(&vrrp_dbg_proto, @@ -1646,7 +1651,7 @@ static int vrrp_shutdown(struct vrrp_router *r) r->vr->vrid, family2str(r->family), vrrp_event_names[VRRP_EVENT_SHUTDOWN], vrrp_state_names[VRRP_STATE_INITIALIZE]); - break; + return 0; } /* Cancel all timers */ @@ -1834,7 +1839,7 @@ static int vrrp_autoconfig_if_add(struct interface *ifp) created = true; } - if (!vr || vr->autoconf == false) + if (!vr || !vr->autoconf) return 0; if (!created) { @@ -2214,18 +2219,57 @@ void vrrp_if_del(struct interface *ifp) { struct listnode *ln; struct vrrp_vrouter *vr; - struct list *vrs = vrrp_lookup_by_if_any(ifp); vrrp_if_down(ifp); + /* + * You think we'd be able use vrrp_lookup_by_if_any to find interfaces? + * Nah. FRR's interface management is insane. There are no ordering + * guarantees about what interfaces are deleted when. Maybe this is a + * macvlan and its parent was already deleted, in which case its + * ifindex is now IFINDEX_INTERNAL, so ifp->link_ifindex - while still + * valid - doesn't match any interface on the system, meaning we can't + * use any of the vrrp_lookup* functions since they rely on finding the + * base interface of what they're given by following link_ifindex. + * + * Since we need to actually NULL out pointers in this function to + * avoid a UAF - since the caller will (might) free ifp after we return + * - we need to look up based on pointers. + */ + struct list *vrs = hash_to_list(vrrp_vrouters_hash); + for (ALL_LIST_ELEMENTS_RO(vrs, ln, vr)) { - if ((vr->v4->mvl_ifp == ifp || vr->ifp == ifp) - && vr->v4->fsm.state != VRRP_STATE_INITIALIZE) { + if (ifp == vr->ifp) { vrrp_event(vr->v4, VRRP_EVENT_SHUTDOWN); + vrrp_event(vr->v6, VRRP_EVENT_SHUTDOWN); + /* + * Stands to reason if the base was deleted, so were + * (or will be) its children + */ vr->v4->mvl_ifp = NULL; - } else if ((vr->v6->mvl_ifp == ifp || vr->ifp == ifp) - && vr->v6->fsm.state != VRRP_STATE_INITIALIZE) { + vr->v6->mvl_ifp = NULL; + /* + * We shouldn't need to lose the reference if it's the + * primary interface, because that was configured + * explicitly in our config, and thus will be kept as a + * stub; to avoid stupid bugs, double check that + */ + assert(ifp->configured); + } else if (ifp == vr->v4->mvl_ifp) { + vrrp_event(vr->v4, VRRP_EVENT_SHUTDOWN); + /* + * If this is a macvlan, then it wasn't explicitly + * configured and will be deleted when we return from + * this function, so we need to lose the reference + */ + vr->v4->mvl_ifp = NULL; + } else if (ifp == vr->v6->mvl_ifp) { vrrp_event(vr->v6, VRRP_EVENT_SHUTDOWN); + /* + * If this is a macvlan, then it wasn't explicitly + * configured and will be deleted when we return from + * this function, so we need to lose the reference + */ vr->v6->mvl_ifp = NULL; } } @@ -2347,11 +2391,11 @@ static bool vrrp_hash_cmp(const void *arg1, const void *arg2) const struct vrrp_vrouter *vr2 = arg2; if (vr1->ifp != vr2->ifp) - return 0; + return false; if (vr1->vrid != vr2->vrid) - return 0; + return false; - return 1; + return true; } void vrrp_init(void) diff --git a/vrrpd/vrrp_debug.h b/vrrpd/vrrp_debug.h index 20f9930955..459d4d01aa 100644 --- a/vrrpd/vrrp_debug.h +++ b/vrrpd/vrrp_debug.h @@ -25,13 +25,13 @@ #include "lib/debug.h" /* VRRP debugging records */ -struct debug vrrp_dbg_arp; -struct debug vrrp_dbg_auto; -struct debug vrrp_dbg_ndisc; -struct debug vrrp_dbg_pkt; -struct debug vrrp_dbg_proto; -struct debug vrrp_dbg_sock; -struct debug vrrp_dbg_zebra; +extern struct debug vrrp_dbg_arp; +extern struct debug vrrp_dbg_auto; +extern struct debug vrrp_dbg_ndisc; +extern struct debug vrrp_dbg_pkt; +extern struct debug vrrp_dbg_proto; +extern struct debug vrrp_dbg_sock; +extern struct debug vrrp_dbg_zebra; /* * Initialize VRRP debugging. diff --git a/vrrpd/vrrp_zebra.c b/vrrpd/vrrp_zebra.c index 000672a080..a578921df6 100644 --- a/vrrpd/vrrp_zebra.c +++ b/vrrpd/vrrp_zebra.c @@ -204,5 +204,5 @@ void vrrp_zebra_init(void) zclient_init(zclient, ZEBRA_ROUTE_VRRP, 0, &vrrp_privs); - zlog_notice("%s: zclient socket initialized", __PRETTY_FUNCTION__); + zlog_notice("%s: zclient socket initialized", __func__); } diff --git a/vtysh/extract.pl.in b/vtysh/extract.pl.in index b7ac0abe02..c4f293fd3b 100755 --- a/vtysh/extract.pl.in +++ b/vtysh/extract.pl.in @@ -43,7 +43,9 @@ sub scan_file { open (FH, "@CPP@ -DHAVE_CONFIG_H -DVTYSH_EXTRACT_PL -Ivtysh/@top_builddir@ -Ivtysh/@top_srcdir@ -Ivtysh/@top_srcdir@/lib -Ivtysh/@top_builddir@/lib -Ivtysh/@top_srcdir@/bgpd -Ivtysh/@top_srcdir@/bgpd/rfapi @LUA_INCLUDE@ @CPPFLAGS@ $cppadd $file |"); local $/; undef $/; $line = <FH>; - close (FH); + if (!close (FH)) { + printf "File: $file failed to compile, when extracting cli from it please inspect\n" + } # ?: makes a group non-capturing @defun = ($line =~ /((?:DEFUN|DEFUN_HIDDEN|ALIAS|ALIAS_HIDDEN)\s*\(.+?\));?\s?\s?\n/sg); diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 92d52ff650..310acdf37f 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -3670,7 +3670,7 @@ char *vtysh_prompt(void) { static char buf[512]; - snprintf(buf, sizeof buf, cmd_prompt(vty->node), cmd_hostname_get()); + snprintf(buf, sizeof(buf), cmd_prompt(vty->node), cmd_hostname_get()); return buf; } diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c index 5951274257..25d1bf7db0 100644 --- a/vtysh/vtysh_main.c +++ b/vtysh/vtysh_main.c @@ -229,14 +229,15 @@ static char *vtysh_rl_gets(void) static void log_it(const char *line) { time_t t = time(NULL); - struct tm *tmp = localtime(&t); + struct tm tmp; const char *user = getenv("USER"); char tod[64]; + localtime_r(&t, &tmp); if (!user) user = "boot"; - strftime(tod, sizeof tod, "%Y%m%d-%H:%M.%S", tmp); + strftime(tod, sizeof(tod), "%Y%m%d-%H:%M.%S", &tmp); fprintf(logfile, "%s:%s %s\n", tod, user, line); } diff --git a/zebra/connected.c b/zebra/connected.c index 0ee41afa8f..5c713aa970 100644 --- a/zebra/connected.c +++ b/zebra/connected.c @@ -210,9 +210,10 @@ void connected_up(struct interface *ifp, struct connected *ifc) zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id); if (!zvrf) { - flog_err(EC_ZEBRA_VRF_NOT_FOUND, - "%s: Received Up for interface but no associated zvrf: %d", - __PRETTY_FUNCTION__, ifp->vrf_id); + flog_err( + EC_ZEBRA_VRF_NOT_FOUND, + "%s: Received Up for interface but no associated zvrf: %d", + __func__, ifp->vrf_id); return; } if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL)) @@ -355,9 +356,10 @@ void connected_down(struct interface *ifp, struct connected *ifc) zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id); if (!zvrf) { - flog_err(EC_ZEBRA_VRF_NOT_FOUND, - "%s: Received Up for interface but no associated zvrf: %d", - __PRETTY_FUNCTION__, ifp->vrf_id); + flog_err( + EC_ZEBRA_VRF_NOT_FOUND, + "%s: Received Up for interface but no associated zvrf: %d", + __func__, ifp->vrf_id); return; } diff --git a/zebra/debug.c b/zebra/debug.c index 16b1d0057b..68f6b69305 100644 --- a/zebra/debug.c +++ b/zebra/debug.c @@ -544,6 +544,10 @@ static int config_write_debug(struct vty *vty) vty_out(vty, "debug zebra vxlan\n"); write++; } + if (IS_ZEBRA_DEBUG_MLAG) { + vty_out(vty, "debug zebra mlag\n"); + write++; + } if (IS_ZEBRA_DEBUG_PW) { vty_out(vty, "debug zebra pseudowires\n"); write++; @@ -633,4 +637,5 @@ void zebra_debug_init(void) install_element(CONFIG_NODE, &no_debug_zebra_rib_cmd); install_element(CONFIG_NODE, &no_debug_zebra_fpm_cmd); install_element(CONFIG_NODE, &no_debug_zebra_dplane_cmd); + install_element(CONFIG_NODE, &debug_zebra_mlag_cmd); } diff --git a/zebra/if_netlink.c b/zebra/if_netlink.c index 4731d1ed15..65a0add57e 100644 --- a/zebra/if_netlink.c +++ b/zebra/if_netlink.c @@ -286,7 +286,7 @@ static void netlink_vrf_change(struct nlmsghdr *h, struct rtattr *tb, ifi = NLMSG_DATA(h); - memset(linkinfo, 0, sizeof linkinfo); + memset(linkinfo, 0, sizeof(linkinfo)); parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb); if (!linkinfo[IFLA_INFO_DATA]) { @@ -297,7 +297,7 @@ static void netlink_vrf_change(struct nlmsghdr *h, struct rtattr *tb, return; } - memset(attr, 0, sizeof attr); + memset(attr, 0, sizeof(attr)); parse_rtattr_nested(attr, IFLA_VRF_MAX, linkinfo[IFLA_INFO_DATA]); if (!attr[IFLA_VRF_TABLE]) { if (IS_ZEBRA_DEBUG_KERNEL) @@ -433,7 +433,7 @@ static int netlink_extract_bridge_info(struct rtattr *link_data, struct rtattr *attr[IFLA_BR_MAX + 1]; memset(bridge_info, 0, sizeof(*bridge_info)); - memset(attr, 0, sizeof attr); + memset(attr, 0, sizeof(attr)); parse_rtattr_nested(attr, IFLA_BR_MAX, link_data); if (attr[IFLA_BR_VLAN_FILTERING]) bridge_info->vlan_aware = @@ -448,7 +448,7 @@ static int netlink_extract_vlan_info(struct rtattr *link_data, vlanid_t vid_in_msg; memset(vlan_info, 0, sizeof(*vlan_info)); - memset(attr, 0, sizeof attr); + memset(attr, 0, sizeof(attr)); parse_rtattr_nested(attr, IFLA_VLAN_MAX, link_data); if (!attr[IFLA_VLAN_ID]) { if (IS_ZEBRA_DEBUG_KERNEL) @@ -469,7 +469,7 @@ static int netlink_extract_vxlan_info(struct rtattr *link_data, struct in_addr vtep_ip_in_msg; memset(vxl_info, 0, sizeof(*vxl_info)); - memset(attr, 0, sizeof attr); + memset(attr, 0, sizeof(attr)); parse_rtattr_nested(attr, IFLA_VXLAN_MAX, link_data); if (!attr[IFLA_VXLAN_ID]) { if (IS_ZEBRA_DEBUG_KERNEL) @@ -543,7 +543,7 @@ static int netlink_bridge_interface(struct nlmsghdr *h, int len, ns_id_t ns_id, /* Fetch name and ifindex */ ifi = NLMSG_DATA(h); - memset(tb, 0, sizeof tb); + memset(tb, 0, sizeof(tb)); netlink_parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len); if (tb[IFLA_IFNAME] == NULL) @@ -567,7 +567,7 @@ static int netlink_bridge_interface(struct nlmsghdr *h, int len, ns_id_t ns_id, /* There is a 1-to-1 mapping of VLAN to VxLAN - hence * only 1 access VLAN is accepted. */ - memset(aftb, 0, sizeof aftb); + memset(aftb, 0, sizeof(aftb)); parse_rtattr_nested(aftb, IFLA_BRIDGE_MAX, tb[IFLA_AF_SPEC]); if (!aftb[IFLA_BRIDGE_VLAN_INFO]) return 0; @@ -616,10 +616,10 @@ static int netlink_interface(struct nlmsghdr *h, ns_id_t ns_id, int startup) len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifinfomsg)); if (len < 0) { - zlog_err("%s: Message received from netlink is of a broken size: %d %zu", - __PRETTY_FUNCTION__, - h->nlmsg_len, - (size_t)NLMSG_LENGTH(sizeof(struct ifinfomsg))); + zlog_err( + "%s: Message received from netlink is of a broken size: %d %zu", + __func__, h->nlmsg_len, + (size_t)NLMSG_LENGTH(sizeof(struct ifinfomsg))); return -1; } @@ -628,8 +628,8 @@ static int netlink_interface(struct nlmsghdr *h, ns_id_t ns_id, int startup) return netlink_bridge_interface(h, len, ns_id, startup); /* Looking up interface name. */ - memset(tb, 0, sizeof tb); - memset(linkinfo, 0, sizeof linkinfo); + memset(tb, 0, sizeof(tb)); + memset(linkinfo, 0, sizeof(linkinfo)); netlink_parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len); /* check for wireless messages to ignore */ @@ -858,7 +858,7 @@ int kernel_interface_set_master(struct interface *master, char buf[NL_PKT_BUF_SIZE]; } req; - memset(&req, 0, sizeof req); + memset(&req, 0, sizeof(req)); req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)); req.n.nlmsg_flags = NLM_F_REQUEST; @@ -867,8 +867,8 @@ int kernel_interface_set_master(struct interface *master, req.ifa.ifi_index = slave->ifindex; - addattr_l(&req.n, sizeof req, IFLA_MASTER, &master->ifindex, 4); - addattr_l(&req.n, sizeof req, IFLA_LINK, &slave->ifindex, 4); + addattr_l(&req.n, sizeof(req), IFLA_MASTER, &master->ifindex, 4); + addattr_l(&req.n, sizeof(req), IFLA_LINK, &slave->ifindex, 4); return netlink_talk(netlink_talk_filter, &req.n, &zns->netlink_cmd, zns, 0); @@ -975,14 +975,14 @@ int netlink_interface_addr(struct nlmsghdr *h, ns_id_t ns_id, int startup) len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifaddrmsg)); if (len < 0) { - zlog_err("%s: Message received from netlink is of a broken size: %d %zu", - __PRETTY_FUNCTION__, - h->nlmsg_len, - (size_t)NLMSG_LENGTH(sizeof(struct ifaddrmsg))); + zlog_err( + "%s: Message received from netlink is of a broken size: %d %zu", + __func__, h->nlmsg_len, + (size_t)NLMSG_LENGTH(sizeof(struct ifaddrmsg))); return -1; } - memset(tb, 0, sizeof tb); + memset(tb, 0, sizeof(tb)); netlink_parse_rtattr(tb, IFA_MAX, IFA_RTA(ifa), len); ifp = if_lookup_by_index_per_ns(zns, ifa->ifa_index); @@ -1176,9 +1176,10 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifinfomsg)); if (len < 0) { - zlog_err("%s: Message received from netlink is of a broken size %d %zu", - __PRETTY_FUNCTION__, h->nlmsg_len, - (size_t)NLMSG_LENGTH(sizeof(struct ifinfomsg))); + zlog_err( + "%s: Message received from netlink is of a broken size %d %zu", + __func__, h->nlmsg_len, + (size_t)NLMSG_LENGTH(sizeof(struct ifinfomsg))); return -1; } @@ -1187,8 +1188,8 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) return netlink_bridge_interface(h, len, ns_id, startup); /* Looking up interface name. */ - memset(tb, 0, sizeof tb); - memset(linkinfo, 0, sizeof linkinfo); + memset(tb, 0, sizeof(tb)); + memset(linkinfo, 0, sizeof(linkinfo)); netlink_parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len); /* check for wireless messages to ignore */ diff --git a/zebra/interface.c b/zebra/interface.c index 7e7397a3bb..59cbfc6854 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -84,9 +84,8 @@ static int if_zebra_speed_update(struct thread *thread) return 1; if (new_speed != ifp->speed) { - zlog_info("%s: %s old speed: %u new speed: %u", - __PRETTY_FUNCTION__, ifp->name, ifp->speed, - new_speed); + zlog_info("%s: %s old speed: %u new speed: %u", __func__, + ifp->name, ifp->speed, new_speed); ifp->speed = new_speed; if_add_update(ifp); changed = true; @@ -617,11 +616,14 @@ void if_add_update(struct interface *ifp) SET_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE); if (if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON) { - if (IS_ZEBRA_DEBUG_KERNEL) + if (IS_ZEBRA_DEBUG_KERNEL) { zlog_debug( - "interface %s vrf %u index %d is shutdown. " + "interface %s vrf %s(%u) index %d is shutdown. " "Won't wake it up.", - ifp->name, ifp->vrf_id, ifp->ifindex); + ifp->name, VRF_LOGNAME(zvrf->vrf), + ifp->vrf_id, ifp->ifindex); + } + return; } @@ -629,13 +631,15 @@ void if_add_update(struct interface *ifp) if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( - "interface %s vrf %u index %d becomes active.", - ifp->name, ifp->vrf_id, ifp->ifindex); + "interface %s vrf %s(%u) index %d becomes active.", + ifp->name, VRF_LOGNAME(zvrf->vrf), ifp->vrf_id, + ifp->ifindex); } else { if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug("interface %s vrf %u index %d is added.", - ifp->name, ifp->vrf_id, ifp->ifindex); + zlog_debug("interface %s vrf %s(%u) index %d is added.", + ifp->name, VRF_LOGNAME(zvrf->vrf), + ifp->vrf_id, ifp->ifindex); } } @@ -774,10 +778,12 @@ void if_delete_update(struct interface *ifp) struct zebra_if *zif; if (if_is_up(ifp)) { + struct vrf *vrf = vrf_lookup_by_id(ifp->vrf_id); + flog_err( EC_LIB_INTERFACE, - "interface %s vrf %u index %d is still up while being deleted.", - ifp->name, ifp->vrf_id, ifp->ifindex); + "interface %s vrf %s(%u) index %d is still up while being deleted.", + ifp->name, VRF_LOGNAME(vrf), ifp->vrf_id, ifp->ifindex); return; } @@ -787,9 +793,13 @@ void if_delete_update(struct interface *ifp) /* Mark interface as inactive */ UNSET_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE); - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug("interface %s vrf %u index %d is now inactive.", - ifp->name, ifp->vrf_id, ifp->ifindex); + if (IS_ZEBRA_DEBUG_KERNEL) { + struct vrf *vrf = vrf_lookup_by_id(ifp->vrf_id); + + zlog_debug("interface %s vrf %s(%u) index %d is now inactive.", + ifp->name, VRF_LOGNAME(vrf), ifp->vrf_id, + ifp->ifindex); + } /* Delete connected routes from the kernel. */ if_delete_connected(ifp); @@ -1863,7 +1873,8 @@ DEFUN (show_interface_desc_vrf_all, RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) if (!RB_EMPTY(if_name_head, &vrf->ifaces_by_name)) { - vty_out(vty, "\n\tVRF %u\n\n", vrf->vrf_id); + vty_out(vty, "\n\tVRF %s(%u)\n\n", VRF_LOGNAME(vrf), + vrf->vrf_id); if_show_description(vty, vrf->vrf_id); } diff --git a/zebra/ipforward_proc.c b/zebra/ipforward_proc.c index 226f722937..4bd160ddbc 100644 --- a/zebra/ipforward_proc.c +++ b/zebra/ipforward_proc.c @@ -34,9 +34,7 @@ static const char proc_net_snmp[] = "/proc/net/snmp"; static void dropline(FILE *fp) { - int c; - - while ((c = getc(fp)) != '\n') + while (getc(fp) != '\n') ; } diff --git a/zebra/ipforward_sysctl.c b/zebra/ipforward_sysctl.c index ac8f537075..48ab95d1ba 100644 --- a/zebra/ipforward_sysctl.c +++ b/zebra/ipforward_sysctl.c @@ -41,7 +41,7 @@ int ipforward(void) size_t len; int ipforwarding = 0; - len = sizeof ipforwarding; + len = sizeof(ipforwarding); if (sysctl(mib, MIB_SIZ, &ipforwarding, &len, 0, 0) < 0) { flog_err_sys(EC_LIB_SYSTEM_CALL, "Can't get ipforwarding value"); @@ -55,7 +55,7 @@ int ipforward_on(void) size_t len; int ipforwarding = 1; - len = sizeof ipforwarding; + len = sizeof(ipforwarding); frr_with_privs(&zserv_privs) { if (sysctl(mib, MIB_SIZ, NULL, NULL, &ipforwarding, len) < 0) { flog_err_sys(EC_LIB_SYSTEM_CALL, @@ -71,7 +71,7 @@ int ipforward_off(void) size_t len; int ipforwarding = 0; - len = sizeof ipforwarding; + len = sizeof(ipforwarding); frr_with_privs(&zserv_privs) { if (sysctl(mib, MIB_SIZ, NULL, NULL, &ipforwarding, len) < 0) { flog_err_sys(EC_LIB_SYSTEM_CALL, @@ -96,7 +96,7 @@ int ipforward_ipv6(void) size_t len; int ip6forwarding = 0; - len = sizeof ip6forwarding; + len = sizeof(ip6forwarding); frr_with_privs(&zserv_privs) { if (sysctl(mib_ipv6, MIB_SIZ, &ip6forwarding, &len, 0, 0) < 0) { flog_err_sys(EC_LIB_SYSTEM_CALL, @@ -112,7 +112,7 @@ int ipforward_ipv6_on(void) size_t len; int ip6forwarding = 1; - len = sizeof ip6forwarding; + len = sizeof(ip6forwarding); frr_with_privs(&zserv_privs) { if (sysctl(mib_ipv6, MIB_SIZ, NULL, NULL, &ip6forwarding, len) < 0) { @@ -129,7 +129,7 @@ int ipforward_ipv6_off(void) size_t len; int ip6forwarding = 0; - len = sizeof ip6forwarding; + len = sizeof(ip6forwarding); frr_with_privs(&zserv_privs) { if (sysctl(mib_ipv6, MIB_SIZ, NULL, NULL, &ip6forwarding, len) < 0) { diff --git a/zebra/irdp_main.c b/zebra/irdp_main.c index 0de618625d..a1e6e8248e 100644 --- a/zebra/irdp_main.c +++ b/zebra/irdp_main.c @@ -190,7 +190,7 @@ static void irdp_send(struct interface *ifp, struct prefix *p, struct stream *s) if (irdp->flags & IF_DEBUG_MESSAGES) zlog_debug("IRDP: TX Advert on %s %s Holdtime=%d Preference=%d", - ifp->name, prefix2str(p, buf, sizeof buf), + ifp->name, prefix2str(p, buf, sizeof(buf)), irdp->flags & IF_SHUTDOWN ? 0 : irdp->Lifetime, get_pref(irdp, p)); diff --git a/zebra/irdp_packet.c b/zebra/irdp_packet.c index f6fe6bbf1e..502a2f277c 100644 --- a/zebra/irdp_packet.c +++ b/zebra/irdp_packet.c @@ -78,6 +78,7 @@ static void parse_irdp_packet(char *p, int len, struct interface *ifp) int ip_hlen, iplen, datalen; struct zebra_if *zi; struct irdp_interface *irdp; + uint16_t saved_chksum; zi = ifp->info; if (!zi) @@ -121,8 +122,10 @@ static void parse_irdp_packet(char *p, int len, struct interface *ifp) icmp = (struct icmphdr *)(p + ip_hlen); + saved_chksum = icmp->checksum; + icmp->checksum = 0; /* check icmp checksum */ - if (in_cksum(icmp, datalen) != icmp->checksum) { + if (in_cksum(icmp, datalen) != saved_chksum) { flog_warn( EC_ZEBRA_IRDP_BAD_CHECKSUM, "IRDP: RX ICMP packet from %s. Bad checksum, silently ignored", @@ -193,7 +196,7 @@ static int irdp_recvmsg(int sock, uint8_t *buf, int size, int *ifindex) msg.msg_iov = &iov; msg.msg_iovlen = 1; msg.msg_control = (void *)adata; - msg.msg_controllen = sizeof adata; + msg.msg_controllen = sizeof(adata); iov.iov_base = buf; iov.iov_len = size; @@ -315,15 +318,20 @@ void send_packet(struct interface *ifp, struct stream *s, uint32_t dst, if (setsockopt(irdp_sock, IPPROTO_IP, IP_HDRINCL, (char *)&on, sizeof(on)) < 0) - zlog_debug("sendto %s", safe_strerror(errno)); + flog_err(EC_LIB_SOCKET, + "IRDP: Cannot set IP_HDRINCLU %s(%d) on %s", + safe_strerror(errno), errno, ifp->name); if (dst == INADDR_BROADCAST) { - on = 1; - if (setsockopt(irdp_sock, SOL_SOCKET, SO_BROADCAST, (char *)&on, - sizeof(on)) + uint32_t bon = 1; + + if (setsockopt(irdp_sock, SOL_SOCKET, SO_BROADCAST, &bon, + sizeof(bon)) < 0) - zlog_debug("sendto %s", safe_strerror(errno)); + flog_err(EC_LIB_SOCKET, + "IRDP: Cannot set SO_BROADCAST %s(%d) on %s", + safe_strerror(errno), errno, ifp->name); } if (dst != INADDR_BROADCAST) @@ -354,8 +362,8 @@ void send_packet(struct interface *ifp, struct stream *s, uint32_t dst, sockopt_iphdrincl_swab_htosys(ip); - if (sendmsg(irdp_sock, msg, 0) < 0) { - zlog_debug("sendto %s", safe_strerror(errno)); - } - /* printf("TX on %s idx %d\n", ifp->name, ifp->ifindex); */ + if (sendmsg(irdp_sock, msg, 0) < 0) + flog_err(EC_LIB_SOCKET, + "IRDP: sendmsg send failure %s(%d) on %s", + safe_strerror(errno), errno, ifp->name); } diff --git a/zebra/kernel_netlink.c b/zebra/kernel_netlink.c index 90d3aeb482..97b0238362 100644 --- a/zebra/kernel_netlink.c +++ b/zebra/kernel_netlink.c @@ -231,12 +231,12 @@ static int netlink_socket(struct nlsock *nl, unsigned long groups, return -1; } - memset(&snl, 0, sizeof snl); + memset(&snl, 0, sizeof(snl)); snl.nl_family = AF_NETLINK; snl.nl_groups = groups; /* Bind the socket to the netlink structure for anything. */ - ret = bind(sock, (struct sockaddr *)&snl, sizeof snl); + ret = bind(sock, (struct sockaddr *)&snl, sizeof(snl)); } if (ret < 0) { @@ -247,9 +247,9 @@ static int netlink_socket(struct nlsock *nl, unsigned long groups, } /* multiple netlink sockets will have different nl_pid */ - namelen = sizeof snl; + namelen = sizeof(snl); ret = getsockname(sock, (struct sockaddr *)&snl, (socklen_t *)&namelen); - if (ret < 0 || namelen != sizeof snl) { + if (ret < 0 || namelen != sizeof(snl)) { flog_err_sys(EC_LIB_SOCKET, "Can't get %s socket name: %s", nl->name, safe_strerror(errno)); close(sock); @@ -697,8 +697,7 @@ static void netlink_parse_extended_ack(struct nlmsghdr *h) * but noticing it for later. */ err_nlh = &err->msg; - zlog_debug("%s: Received %s extended Ack", - __PRETTY_FUNCTION__, + zlog_debug("%s: Received %s extended Ack", __func__, nl_msg_type_to_str(err_nlh->nlmsg_type)); } } @@ -739,10 +738,10 @@ int netlink_parse_info(int (*filter)(struct nlmsghdr *, ns_id_t, int), while (1) { char buf[NL_RCV_PKT_BUF_SIZE]; - struct iovec iov = {.iov_base = buf, .iov_len = sizeof buf}; + struct iovec iov = {.iov_base = buf, .iov_len = sizeof(buf)}; struct sockaddr_nl snl; struct msghdr msg = {.msg_name = (void *)&snl, - .msg_namelen = sizeof snl, + .msg_namelen = sizeof(snl), .msg_iov = &iov, .msg_iovlen = 1}; struct nlmsghdr *h; @@ -784,7 +783,7 @@ int netlink_parse_info(int (*filter)(struct nlmsghdr *, ns_id_t, int), return -1; } - if (msg.msg_namelen != sizeof snl) { + if (msg.msg_namelen != sizeof(snl)) { flog_err(EC_ZEBRA_NETLINK_LENGTH_ERROR, "%s sender address length error: length %d", nl->name, msg.msg_namelen); @@ -844,7 +843,7 @@ int netlink_parse_info(int (*filter)(struct nlmsghdr *, ns_id_t, int), if (IS_ZEBRA_DEBUG_KERNEL) { zlog_debug( "%s: %s ACK: type=%s(%u), seq=%u, pid=%u", - __FUNCTION__, nl->name, + __func__, nl->name, nl_msg_type_to_str( err->msg.nlmsg_type), err->msg.nlmsg_type, @@ -990,14 +989,14 @@ int netlink_talk_info(int (*filter)(struct nlmsghdr *, ns_id_t, int startup), int save_errno = 0; const struct nlsock *nl; - memset(&snl, 0, sizeof snl); - memset(&iov, 0, sizeof iov); - memset(&msg, 0, sizeof msg); + memset(&snl, 0, sizeof(snl)); + memset(&iov, 0, sizeof(iov)); + memset(&msg, 0, sizeof(msg)); iov.iov_base = n; iov.iov_len = n->nlmsg_len; msg.msg_name = (void *)&snl; - msg.msg_namelen = sizeof snl; + msg.msg_namelen = sizeof(snl); msg.msg_iov = &iov; msg.msg_iovlen = 1; @@ -1078,13 +1077,13 @@ int netlink_request(struct nlsock *nl, struct nlmsghdr *n) n->nlmsg_pid = nl->snl.nl_pid; n->nlmsg_seq = ++nl->seq; - memset(&snl, 0, sizeof snl); + memset(&snl, 0, sizeof(snl)); snl.nl_family = AF_NETLINK; /* Raise capabilities and send message, then lower capabilities. */ frr_with_privs(&zserv_privs) { ret = sendto(nl->sock, (void *)n, n->nlmsg_len, 0, - (struct sockaddr *)&snl, sizeof snl); + (struct sockaddr *)&snl, sizeof(snl)); } if (ret < 0) { diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index 7cdd6ef84e..5ab5210664 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -1371,7 +1371,7 @@ static int kernel_read(struct thread *thread) /* Fetch routing socket. */ sock = THREAD_FD(thread); - nbytes = read(sock, &buf, sizeof buf); + nbytes = read(sock, &buf, sizeof(buf)); if (nbytes <= 0) { if (nbytes < 0 && errno != EWOULDBLOCK && errno != EAGAIN) diff --git a/zebra/redistribute.c b/zebra/redistribute.c index b891fb121f..d1148061b9 100644 --- a/zebra/redistribute.c +++ b/zebra/redistribute.c @@ -75,6 +75,10 @@ static void zebra_redistribute_default(struct zserv *client, vrf_id_t vrf_id) struct route_entry *newre; for (afi = AFI_IP; afi <= AFI_IP6; afi++) { + + if (!vrf_bitmap_check(client->redist_default[afi], vrf_id)) + continue; + /* Lookup table. */ table = zebra_vrf_table(afi, SAFI_UNICAST, vrf_id); if (!table) @@ -339,20 +343,20 @@ void zebra_redistribute_add(ZAPI_HANDLER_ARGS) if (IS_ZEBRA_DEBUG_EVENT) zlog_debug( - "%s: client proto %s afi=%d, wants %s, vrf %u, instance=%d", + "%s: client proto %s afi=%d, wants %s, vrf %s(%u), instance=%d", __func__, zebra_route_string(client->proto), afi, - zebra_route_string(type), zvrf_id(zvrf), instance); + zebra_route_string(type), VRF_LOGNAME(zvrf->vrf), + zvrf_id(zvrf), instance); if (afi == 0 || afi >= AFI_MAX) { flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF, - "%s: Specified afi %d does not exist", - __PRETTY_FUNCTION__, afi); + "%s: Specified afi %d does not exist", __func__, afi); return; } if (type == 0 || type >= ZEBRA_ROUTE_MAX) { zlog_debug("%s: Specified Route Type %d does not exist", - __PRETTY_FUNCTION__, type); + __func__, type); return; } @@ -368,8 +372,10 @@ void zebra_redistribute_add(ZAPI_HANDLER_ARGS) if (!vrf_bitmap_check(client->redist[afi][type], zvrf_id(zvrf))) { if (IS_ZEBRA_DEBUG_EVENT) - zlog_debug("%s: setting vrf %u redist bitmap", - __func__, zvrf_id(zvrf)); + zlog_debug( + "%s: setting vrf %s(%u) redist bitmap", + __func__, VRF_LOGNAME(zvrf->vrf), + zvrf_id(zvrf)); vrf_bitmap_set(client->redist[afi][type], zvrf_id(zvrf)); zebra_redistribute(client, type, 0, zvrf_id(zvrf), afi); @@ -392,14 +398,13 @@ void zebra_redistribute_delete(ZAPI_HANDLER_ARGS) if (afi == 0 || afi >= AFI_MAX) { flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF, - "%s: Specified afi %d does not exist", - __PRETTY_FUNCTION__, afi); + "%s: Specified afi %d does not exist", __func__, afi); return; } if (type == 0 || type >= ZEBRA_ROUTE_MAX) { zlog_debug("%s: Specified Route Type %d does not exist", - __PRETTY_FUNCTION__, type); + __func__, type); return; } @@ -426,8 +431,7 @@ void zebra_redistribute_default_add(ZAPI_HANDLER_ARGS) if (afi == 0 || afi >= AFI_MAX) { flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF, - "%s: Specified afi %u does not exist", - __PRETTY_FUNCTION__, afi); + "%s: Specified afi %u does not exist", __func__, afi); return; } @@ -446,8 +450,7 @@ void zebra_redistribute_default_delete(ZAPI_HANDLER_ARGS) if (afi == 0 || afi >= AFI_MAX) { flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF, - "%s: Specified afi %u does not exist", - __PRETTY_FUNCTION__, afi); + "%s: Specified afi %u does not exist", __func__, afi); return; } @@ -645,7 +648,7 @@ int zebra_add_import_table_entry(struct zebra_vrf *zvrf, struct route_node *rn, if (rmap_name) ret = zebra_import_table_route_map_check( afi, re->type, re->instance, &rn->p, - re->nhe->nhg->nexthop, + re->nhe->nhg.nexthop, zvrf->vrf->vrf_id, re->tag, rmap_name); if (ret != RMAP_PERMITMATCH) { @@ -682,7 +685,7 @@ int zebra_add_import_table_entry(struct zebra_vrf *zvrf, struct route_node *rn, newre->instance = re->table; ng = nexthop_group_new(); - copy_nexthops(&ng->nexthop, re->nhe->nhg->nexthop, NULL); + copy_nexthops(&ng->nexthop, re->nhe->nhg.nexthop, NULL); rib_add_multipath(afi, SAFI_UNICAST, &p, NULL, newre, ng); @@ -699,7 +702,7 @@ int zebra_del_import_table_entry(struct zebra_vrf *zvrf, struct route_node *rn, prefix_copy(&p, &rn->p); rib_delete(afi, SAFI_UNICAST, zvrf->vrf->vrf_id, ZEBRA_ROUTE_TABLE, - re->table, re->flags, &p, NULL, re->nhe->nhg->nexthop, + re->table, re->flags, &p, NULL, re->nhe->nhg.nexthop, re->nhe_id, zvrf->table_id, re->metric, re->distance, false); diff --git a/zebra/rib.h b/zebra/rib.h index 927675e3d9..931c97638e 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -515,7 +515,7 @@ static inline struct nexthop_group *rib_active_nhg(struct route_entry *re) if (re->fib_ng.nexthop) return &(re->fib_ng); else - return re->nhe->nhg; + return &(re->nhe->nhg); } extern void zebra_vty_init(void); diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index 1d63db32e8..e40bf45f59 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -142,7 +142,7 @@ static uint16_t neigh_state_to_netlink(uint16_t dplane_state) } -static inline int is_selfroute(int proto) +static inline bool is_selfroute(int proto) { if ((proto == RTPROT_BGP) || (proto == RTPROT_OSPF) || (proto == RTPROT_ZSTATIC) || (proto == RTPROT_ZEBRA) @@ -151,10 +151,10 @@ static inline int is_selfroute(int proto) || (proto == RTPROT_LDP) || (proto == RTPROT_BABEL) || (proto == RTPROT_RIP) || (proto == RTPROT_SHARP) || (proto == RTPROT_PBR) || (proto == RTPROT_OPENFABRIC)) { - return 1; + return true; } - return 0; + return false; } static inline int zebra2proto(int proto) @@ -213,7 +213,7 @@ static inline int zebra2proto(int proto) */ zlog_debug( "%s: Please add this protocol(%d) to proper rt_netlink.c handling", - __PRETTY_FUNCTION__, proto); + __func__, proto); proto = RTPROT_ZEBRA; break; } @@ -280,7 +280,7 @@ static inline int proto2zebra(int proto, int family, bool is_nexthop) */ zlog_debug( "%s: Please add this protocol(%d) to proper rt_netlink.c handling", - __PRETTY_FUNCTION__, proto); + __func__, proto); proto = ZEBRA_ROUTE_KERNEL; break; } @@ -439,7 +439,7 @@ static uint8_t parse_multipath_nexthops_unicast(ns_id_t ns_id, flog_warn( EC_ZEBRA_UNKNOWN_INTERFACE, "%s: Unknown interface %u specified, defaulting to VRF_DEFAULT", - __PRETTY_FUNCTION__, index); + __func__, index); nh_vrf_id = VRF_DEFAULT; } } else @@ -513,6 +513,7 @@ static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id, struct prefix p; struct prefix_ipv6 src_p = {}; vrf_id_t vrf_id; + bool selfroute; char anyaddr[16] = {0}; @@ -557,13 +558,14 @@ static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id, len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct rtmsg)); if (len < 0) { - zlog_err("%s: Message received from netlink is of a broken size %d %zu", - __PRETTY_FUNCTION__, h->nlmsg_len, - (size_t)NLMSG_LENGTH(sizeof(struct rtmsg))); + zlog_err( + "%s: Message received from netlink is of a broken size %d %zu", + __func__, h->nlmsg_len, + (size_t)NLMSG_LENGTH(sizeof(struct rtmsg))); return -1; } - memset(tb, 0, sizeof tb); + memset(tb, 0, sizeof(tb)); netlink_parse_rtattr(tb, RTA_MAX, RTM_RTA(rtm), len); if (rtm->rtm_flags & RTM_F_CLONED) @@ -573,8 +575,9 @@ static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id, if (rtm->rtm_protocol == RTPROT_KERNEL) return 0; - if (!startup && is_selfroute(rtm->rtm_protocol) - && h->nlmsg_type == RTM_NEWROUTE) { + selfroute = is_selfroute(rtm->rtm_protocol); + + if (!startup && selfroute && h->nlmsg_type == RTM_NEWROUTE) { if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug("Route type: %d Received that we think we have originated, ignoring", rtm->rtm_protocol); @@ -601,7 +604,7 @@ static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id, } /* Route which inserted by Zebra. */ - if (is_selfroute(rtm->rtm_protocol)) { + if (selfroute) { flags |= ZEBRA_FLAG_SELFROUTE; proto = proto2zebra(rtm->rtm_protocol, rtm->rtm_family, false); } @@ -638,7 +641,7 @@ static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id, if (tb[RTA_METRICS]) { struct rtattr *mxrta[RTAX_MAX + 1]; - memset(mxrta, 0, sizeof mxrta); + memset(mxrta, 0, sizeof(mxrta)); netlink_parse_rtattr(mxrta, RTAX_MAX, RTA_DATA(tb[RTA_METRICS]), RTA_PAYLOAD(tb[RTA_METRICS])); @@ -848,7 +851,7 @@ static int netlink_route_change_read_multicast(struct nlmsghdr *h, len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct rtmsg)); - memset(tb, 0, sizeof tb); + memset(tb, 0, sizeof(tb)); netlink_parse_rtattr(tb, RTA_MAX, RTM_RTA(rtm), len); if (tb[RTA_TABLE]) @@ -951,10 +954,10 @@ int netlink_route_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct rtmsg)); if (len < 0) { - zlog_err("%s: Message received from netlink is of a broken size: %d %zu", - __PRETTY_FUNCTION__, - h->nlmsg_len, - (size_t)NLMSG_LENGTH(sizeof(struct rtmsg))); + zlog_err( + "%s: Message received from netlink is of a broken size: %d %zu", + __func__, h->nlmsg_len, + (size_t)NLMSG_LENGTH(sizeof(struct rtmsg))); return -1; } @@ -2296,7 +2299,7 @@ static struct nexthop netlink_nexthop_process_nh(struct rtattr **tb, flog_warn( EC_ZEBRA_UNKNOWN_INTERFACE, "%s: Unknown nexthop interface %u received, defaulting to VRF_DEFAULT", - __PRETTY_FUNCTION__, nh.ifindex); + __func__, nh.ifindex); nh.vrf_id = VRF_DEFAULT; } @@ -2386,7 +2389,7 @@ int netlink_nexthop_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) if (len < 0) { zlog_warn( "%s: Message received from netlink is of a broken size %d %zu", - __PRETTY_FUNCTION__, h->nlmsg_len, + __func__, h->nlmsg_len, (size_t)NLMSG_LENGTH(sizeof(struct nhmsg))); return -1; } @@ -2587,7 +2590,7 @@ static int netlink_macfdb_change(struct nlmsghdr *h, int len, ns_id_t ns_id) struct interface *br_if; struct ethaddr mac; vlanid_t vid = 0; - struct prefix vtep_ip; + struct in_addr vtep_ip; int vid_present = 0, dst_present = 0; char buf[ETHER_ADDR_STRLEN]; char vid_buf[20]; @@ -2600,66 +2603,25 @@ static int netlink_macfdb_change(struct nlmsghdr *h, int len, ns_id_t ns_id) if (!is_evpn_enabled()) return 0; - /* The interface should exist. */ - ifp = if_lookup_by_index_per_ns(zebra_ns_lookup(ns_id), - ndm->ndm_ifindex); - if (!ifp || !ifp->info) { - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug("\t%s without associated interface: %u", - __PRETTY_FUNCTION__, ndm->ndm_ifindex); - return 0; - } - - /* The interface should be something we're interested in. */ - if (!IS_ZEBRA_IF_BRIDGE_SLAVE(ifp)) { - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug("\t%s Not interested in %s, not a slave", - __PRETTY_FUNCTION__, ifp->name); - return 0; - } - - /* Drop "permanent" entries. */ - if (ndm->ndm_state & NUD_PERMANENT) { - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug("\t%s Entry is PERMANENT, dropping", - __PRETTY_FUNCTION__); - return 0; - } - - zif = (struct zebra_if *)ifp->info; - if ((br_if = zif->brslave_info.br_if) == NULL) { - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug( - "%s family %s IF %s(%u) brIF %u - no bridge master", - nl_msg_type_to_str(h->nlmsg_type), - nl_family_to_str(ndm->ndm_family), ifp->name, - ndm->ndm_ifindex, - zif->brslave_info.bridge_ifindex); - return 0; - } - - /* Parse attributes and extract fields of interest. */ + /* Parse attributes and extract fields of interest. Do basic + * validation of the fields. + */ memset(tb, 0, sizeof tb); netlink_parse_rtattr(tb, NDA_MAX, NDA_RTA(ndm), len); if (!tb[NDA_LLADDR]) { if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug("%s family %s IF %s(%u) brIF %u - no LLADDR", + zlog_debug("%s AF_BRIDGE IF %u - no LLADDR", nl_msg_type_to_str(h->nlmsg_type), - nl_family_to_str(ndm->ndm_family), ifp->name, - ndm->ndm_ifindex, - zif->brslave_info.bridge_ifindex); + ndm->ndm_ifindex); return 0; } if (RTA_PAYLOAD(tb[NDA_LLADDR]) != ETH_ALEN) { if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( - "%s family %s IF %s(%u) brIF %u - LLADDR is not MAC, len %lu", - nl_msg_type_to_str(h->nlmsg_type), - nl_family_to_str(ndm->ndm_family), ifp->name, - ndm->ndm_ifindex, - zif->brslave_info.bridge_ifindex, + "%s AF_BRIDGE IF %u - LLADDR is not MAC, len %lu", + nl_msg_type_to_str(h->nlmsg_type), ndm->ndm_ifindex, (unsigned long)RTA_PAYLOAD(tb[NDA_LLADDR])); return 0; } @@ -2675,24 +2637,42 @@ static int netlink_macfdb_change(struct nlmsghdr *h, int len, ns_id_t ns_id) if (tb[NDA_DST]) { /* TODO: Only IPv4 supported now. */ dst_present = 1; - vtep_ip.family = AF_INET; - vtep_ip.prefixlen = IPV4_MAX_BITLEN; - memcpy(&(vtep_ip.u.prefix4.s_addr), RTA_DATA(tb[NDA_DST]), + memcpy(&vtep_ip.s_addr, RTA_DATA(tb[NDA_DST]), IPV4_MAX_BYTELEN); - sprintf(dst_buf, " dst %s", inet_ntoa(vtep_ip.u.prefix4)); + sprintf(dst_buf, " dst %s", inet_ntoa(vtep_ip)); } - sticky = !!(ndm->ndm_state & NUD_NOARP); - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug("Rx %s family %s IF %s(%u)%s %sMAC %s%s", + zlog_debug("Rx %s AF_BRIDGE IF %u%s st 0x%x fl 0x%x MAC %s%s", nl_msg_type_to_str(h->nlmsg_type), - nl_family_to_str(ndm->ndm_family), ifp->name, ndm->ndm_ifindex, vid_present ? vid_buf : "", - sticky ? "sticky " : "", + ndm->ndm_state, ndm->ndm_flags, prefix_mac2str(&mac, buf, sizeof(buf)), dst_present ? dst_buf : ""); + /* The interface should exist. */ + ifp = if_lookup_by_index_per_ns(zebra_ns_lookup(ns_id), + ndm->ndm_ifindex); + if (!ifp || !ifp->info) + return 0; + + /* The interface should be something we're interested in. */ + if (!IS_ZEBRA_IF_BRIDGE_SLAVE(ifp)) + return 0; + + zif = (struct zebra_if *)ifp->info; + if ((br_if = zif->brslave_info.br_if) == NULL) { + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug( + "%s AF_BRIDGE IF %s(%u) brIF %u - no bridge master", + nl_msg_type_to_str(h->nlmsg_type), ifp->name, + ndm->ndm_ifindex, + zif->brslave_info.bridge_ifindex); + return 0; + } + + sticky = !!(ndm->ndm_state & NUD_NOARP); + if (filter_vlan && vid != filter_vlan) { if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug("\tFiltered due to filter vlan: %d", @@ -2706,6 +2686,13 @@ static int netlink_macfdb_change(struct nlmsghdr *h, int len, ns_id_t ns_id) * so perform an implicit delete of any local entry (if it exists). */ if (h->nlmsg_type == RTM_NEWNEIGH) { + /* Drop "permanent" entries. */ + if (ndm->ndm_state & NUD_PERMANENT) { + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug("\tDropping entry because of NUD_PERMANENT"); + return 0; + } + if (IS_ZEBRA_IF_VXLAN(ifp)) return zebra_vxlan_check_del_local_mac(ifp, br_if, &mac, vid); @@ -2715,16 +2702,20 @@ static int netlink_macfdb_change(struct nlmsghdr *h, int len, ns_id_t ns_id) } /* This is a delete notification. + * Ignore the notification with IP dest as it may just signify that the + * MAC has moved from remote to local. The exception is the special + * all-zeros MAC that represents the BUM flooding entry; we may have + * to readd it. Otherwise, * 1. For a MAC over VxLan, check if it needs to be refreshed(readded) * 2. For a MAC over "local" interface, delete the mac * Note: We will get notifications from both bridge driver and VxLAN * driver. - * Ignore the notification from VxLan driver as it is also generated - * when mac moves from remote to local. */ if (dst_present) { - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug("\tNo Destination Present"); + u_char zero_mac[6] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; + + if (!memcmp(zero_mac, mac.octet, ETH_ALEN)) + return zebra_vxlan_check_readd_vtep(ifp, vtep_ip); return 0; } @@ -2871,8 +2862,7 @@ static int netlink_request_specific_mac_in_bridge(struct zebra_ns *zns, addattr32(&req.n, sizeof(req), NDA_MASTER, br_if->ifindex); if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug("%s: Tx family %s IF %s(%u) MAC %s vid %u", - __PRETTY_FUNCTION__, + zlog_debug("%s: Tx family %s IF %s(%u) MAC %s vid %u", __func__, nl_family_to_str(req.ndm.ndm_family), br_if->name, br_if->ifindex, prefix_mac2str(mac, buf, sizeof(buf)), vid); @@ -3050,7 +3040,7 @@ static int netlink_ipneigh_change(struct nlmsghdr *h, int len, ns_id_t ns_id) zif = (struct zebra_if *)ifp->info; /* Parse attributes and extract fields of interest. */ - memset(tb, 0, sizeof tb); + memset(tb, 0, sizeof(tb)); netlink_parse_rtattr(tb, NDA_MAX, NDA_RTA(ndm), len); if (!tb[NDA_DST]) { @@ -3285,6 +3275,15 @@ static int netlink_request_specific_neigh_in_vlan(struct zebra_ns *zns, addattr_l(&req.n, sizeof(req), NDA_DST, &ip->ip.addr, ipa_len); + if (IS_ZEBRA_DEBUG_KERNEL) { + char buf[INET6_ADDRSTRLEN]; + + zlog_debug("%s: Tx %s family %s IF %u IP %s flags 0x%x", + __func__, nl_msg_type_to_str(type), + nl_family_to_str(req.ndm.ndm_family), ifindex, + ipaddr2str(ip, buf, sizeof(buf)), req.n.nlmsg_flags); + } + return netlink_request(&zns->netlink_cmd, &req.n); } @@ -3303,10 +3302,8 @@ int netlink_neigh_read_specific_ip(struct ipaddr *ip, if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug("%s: neigh request IF %s(%u) IP %s vrf_id %u", - __PRETTY_FUNCTION__, vlan_if->name, - vlan_if->ifindex, - ipaddr2str(ip, buf, sizeof(buf)), - vlan_if->vrf_id); + __func__, vlan_if->name, vlan_if->ifindex, + ipaddr2str(ip, buf, sizeof(buf)), vlan_if->vrf_id); ret = netlink_request_specific_neigh_in_vlan(zns, RTM_GETNEIGH, ip, vlan_if->ifindex); @@ -3330,9 +3327,10 @@ int netlink_neigh_change(struct nlmsghdr *h, ns_id_t ns_id) /* Length validity. */ len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ndmsg)); if (len < 0) { - zlog_err("%s: Message received from netlink is of a broken size %d %zu", - __PRETTY_FUNCTION__, h->nlmsg_len, - (size_t)NLMSG_LENGTH(sizeof(struct ndmsg))); + zlog_err( + "%s: Message received from netlink is of a broken size %d %zu", + __func__, h->nlmsg_len, + (size_t)NLMSG_LENGTH(sizeof(struct ndmsg))); return -1; } diff --git a/zebra/rtadv.c b/zebra/rtadv.c index e36af00b4e..60ac471b5a 100644 --- a/zebra/rtadv.c +++ b/zebra/rtadv.c @@ -130,7 +130,7 @@ static int rtadv_recv_packet(struct zebra_vrf *zvrf, int sock, uint8_t *buf, msg.msg_iov = &iov; msg.msg_iovlen = 1; msg.msg_control = (void *)adata; - msg.msg_controllen = sizeof adata; + msg.msg_controllen = sizeof(adata); iov.iov_base = buf; iov.iov_len = buflen; @@ -1118,18 +1118,31 @@ void rtadv_stop_ra(struct interface *ifp) } /* - * send router lifetime value of zero in RAs on all interfaces since we're + * Send router lifetime value of zero in RAs on all interfaces since we're * ceasing to advertise globally and want to let all of our neighbors know * RFC 4861 secion 6.2.5 + * + * Delete all ipv6 global prefixes added to the router advertisement prefix + * lists prior to ceasing. */ void rtadv_stop_ra_all(void) { struct vrf *vrf; struct interface *ifp; + struct listnode *node, *nnode; + struct zebra_if *zif; + struct rtadv_prefix *rprefix; RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) - FOR_ALL_INTERFACES (vrf, ifp) + FOR_ALL_INTERFACES (vrf, ifp) { + zif = ifp->info; + + for (ALL_LIST_ELEMENTS(zif->rtadv.AdvPrefixList, + node, nnode, rprefix)) + rtadv_prefix_reset(zif, rprefix); + rtadv_stop_ra(ifp); + } } void zebra_interface_radv_disable(ZAPI_HANDLER_ARGS) @@ -2425,7 +2438,7 @@ static int if_join_all_router(int sock, struct interface *ifp) mreq.ipv6mr_interface = ifp->ifindex; ret = setsockopt(sock, IPPROTO_IPV6, IPV6_JOIN_GROUP, (char *)&mreq, - sizeof mreq); + sizeof(mreq)); if (ret < 0) flog_err_sys(EC_LIB_SOCKET, "%s(%u): Failed to join group, socket %u error %s", @@ -2451,7 +2464,7 @@ static int if_leave_all_router(int sock, struct interface *ifp) mreq.ipv6mr_interface = ifp->ifindex; ret = setsockopt(sock, IPPROTO_IPV6, IPV6_LEAVE_GROUP, (char *)&mreq, - sizeof mreq); + sizeof(mreq)); if (ret < 0) flog_err_sys( EC_LIB_SOCKET, @@ -2479,4 +2492,25 @@ void rtadv_cmd_init(void) { /* Empty.*/; } + +void rtadv_add_prefix(struct zebra_if *zif, const struct prefix_ipv6 *p) +{ + /* Empty.*/; +} + +void rtadv_delete_prefix(struct zebra_if *zif, const struct prefix *p) +{ + /* Empty.*/; +} + +void rtadv_stop_ra(struct interface *ifp) +{ + /* Empty.*/; +} + +void rtadv_stop_ra_all(void) +{ + /* Empty.*/; +} + #endif /* HAVE_RTADV */ diff --git a/zebra/rtread_getmsg.c b/zebra/rtread_getmsg.c index 3ba5d6ee73..28529cc138 100644 --- a/zebra/rtread_getmsg.c +++ b/zebra/rtread_getmsg.c @@ -231,7 +231,7 @@ void route_read(struct zebra_ns *zns) != 0) { zlog_debug( "getmsg(data) returned " - "msgdata.len = %d (%% sizeof (mib2_ipRouteEntry_t) != 0)", + "msgdata.len = %d (%% sizeof(mib2_ipRouteEntry_t) != 0)", msgdata.len); goto exit; } diff --git a/zebra/rule_netlink.c b/zebra/rule_netlink.c index 2fdb215128..c9699c7d95 100644 --- a/zebra/rule_netlink.c +++ b/zebra/rule_netlink.c @@ -201,9 +201,10 @@ int netlink_rule_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct fib_rule_hdr)); if (len < 0) { - zlog_err("%s: Message received from netlink is of a broken size: %d %zu", - __PRETTY_FUNCTION__, h->nlmsg_len, - (size_t)NLMSG_LENGTH(sizeof(struct fib_rule_hdr))); + zlog_err( + "%s: Message received from netlink is of a broken size: %d %zu", + __func__, h->nlmsg_len, + (size_t)NLMSG_LENGTH(sizeof(struct fib_rule_hdr))); return -1; } diff --git a/zebra/rule_socket.c b/zebra/rule_socket.c index c5660abf3a..e2c650b4ad 100644 --- a/zebra/rule_socket.c +++ b/zebra/rule_socket.c @@ -46,14 +46,14 @@ enum zebra_dplane_result kernel_add_pbr_rule(struct zebra_pbr_rule *rule) { flog_err(EC_LIB_UNAVAILABLE, "%s not Implemented for this platform", - __PRETTY_FUNCTION__); + __func__); return ZEBRA_DPLANE_REQUEST_FAILURE; } enum zebra_dplane_result kernel_del_pbr_rule(struct zebra_pbr_rule *rule) { flog_err(EC_LIB_UNAVAILABLE, "%s not Implemented for this platform", - __PRETTY_FUNCTION__); + __func__); return ZEBRA_DPLANE_REQUEST_FAILURE; } diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c index 42b4791d48..f1c181438e 100644 --- a/zebra/zapi_msg.c +++ b/zebra/zapi_msg.c @@ -580,7 +580,7 @@ int zsend_redistribute_route(int cmd, struct zserv *client, memcpy(&api.src_prefix, src_p, sizeof(api.src_prefix)); } - for (nexthop = re->nhe->nhg->nexthop; + for (nexthop = re->nhe->nhg.nexthop; nexthop; nexthop = nexthop->next) { if (!CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE)) continue; @@ -689,7 +689,7 @@ static int zsend_ipv4_nexthop_lookup_mrib(struct zserv *client, * nexthop we are looking up. Therefore, we will just iterate * over the top chain of nexthops. */ - for (nexthop = re->nhe->nhg->nexthop; nexthop; + for (nexthop = re->nhe->nhg.nexthop; nexthop; nexthop = nexthop->next) if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE)) num += zserv_encode_nexthop(s, nexthop); @@ -790,8 +790,7 @@ void zsend_rule_notify_owner(struct zebra_pbr_rule *rule, struct stream *s; if (IS_ZEBRA_DEBUG_PACKET) - zlog_debug("%s: Notifying %u", __PRETTY_FUNCTION__, - rule->rule.unique); + zlog_debug("%s: Notifying %u", __func__, rule->rule.unique); for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client)) { if (rule->sock == client->sock) @@ -823,8 +822,7 @@ void zsend_ipset_notify_owner(struct zebra_pbr_ipset *ipset, struct stream *s; if (IS_ZEBRA_DEBUG_PACKET) - zlog_debug("%s: Notifying %u", __PRETTY_FUNCTION__, - ipset->unique); + zlog_debug("%s: Notifying %u", __func__, ipset->unique); for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client)) { if (ipset->sock == client->sock) @@ -853,8 +851,7 @@ void zsend_ipset_entry_notify_owner(struct zebra_pbr_ipset_entry *ipset, struct stream *s; if (IS_ZEBRA_DEBUG_PACKET) - zlog_debug("%s: Notifying %u", __PRETTY_FUNCTION__, - ipset->unique); + zlog_debug("%s: Notifying %u", __func__, ipset->unique); for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client)) { if (ipset->sock == client->sock) @@ -883,8 +880,7 @@ void zsend_iptable_notify_owner(struct zebra_pbr_iptable *iptable, struct stream *s; if (IS_ZEBRA_DEBUG_PACKET) - zlog_debug("%s: Notifying %u", __PRETTY_FUNCTION__, - iptable->unique); + zlog_debug("%s: Notifying %u", __func__, iptable->unique); for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client)) { if (iptable->sock == client->sock) @@ -1086,7 +1082,7 @@ static void zread_rnh_register(ZAPI_HANDLER_ARGS) if (p.prefixlen > IPV4_MAX_BITLEN) { zlog_debug( "%s: Specified prefix hdr->length %d is too large for a v4 address", - __PRETTY_FUNCTION__, p.prefixlen); + __func__, p.prefixlen); return; } STREAM_GET(&p.u.prefix4.s_addr, s, IPV4_MAX_BYTELEN); @@ -1096,7 +1092,7 @@ static void zread_rnh_register(ZAPI_HANDLER_ARGS) if (p.prefixlen > IPV6_MAX_BITLEN) { zlog_debug( "%s: Specified prefix hdr->length %d is to large for a v6 address", - __PRETTY_FUNCTION__, p.prefixlen); + __func__, p.prefixlen); return; } STREAM_GET(&p.u.prefix6, s, IPV6_MAX_BYTELEN); @@ -1177,7 +1173,7 @@ static void zread_rnh_unregister(ZAPI_HANDLER_ARGS) if (p.prefixlen > IPV4_MAX_BITLEN) { zlog_debug( "%s: Specified prefix hdr->length %d is to large for a v4 address", - __PRETTY_FUNCTION__, p.prefixlen); + __func__, p.prefixlen); return; } STREAM_GET(&p.u.prefix4.s_addr, s, IPV4_MAX_BYTELEN); @@ -1187,7 +1183,7 @@ static void zread_rnh_unregister(ZAPI_HANDLER_ARGS) if (p.prefixlen > IPV6_MAX_BITLEN) { zlog_debug( "%s: Specified prefix hdr->length %d is to large for a v6 address", - __PRETTY_FUNCTION__, p.prefixlen); + __func__, p.prefixlen); return; } STREAM_GET(&p.u.prefix6, s, IPV6_MAX_BYTELEN); @@ -1255,7 +1251,7 @@ static void zread_fec_register(ZAPI_HANDLER_ARGS) && p.prefixlen > IPV6_MAX_BITLEN)) { zlog_debug( "%s: Specified prefix hdr->length: %d is to long for %d", - __PRETTY_FUNCTION__, p.prefixlen, p.family); + __func__, p.prefixlen, p.family); return; } l += 5; @@ -1321,7 +1317,7 @@ static void zread_fec_unregister(ZAPI_HANDLER_ARGS) && p.prefixlen > IPV6_MAX_BITLEN)) { zlog_debug( "%s: Received prefix hdr->length %d which is greater than %d can support", - __PRETTY_FUNCTION__, p.prefixlen, p.family); + __func__, p.prefixlen, p.family); return; } l += 5; @@ -1426,7 +1422,7 @@ static void zread_route_add(ZAPI_HANDLER_ARGS) if (zapi_route_decode(s, &api) < 0) { if (IS_ZEBRA_DEBUG_RECV) zlog_debug("%s: Unable to decode zapi_route sent", - __PRETTY_FUNCTION__); + __func__); return; } @@ -1563,7 +1559,7 @@ static void zread_route_add(ZAPI_HANDLER_ARGS) flog_warn( EC_ZEBRA_NEXTHOP_CREATION_FAILED, "%s: Nexthops Specified: %d but we failed to properly create one", - __PRETTY_FUNCTION__, api.nexthop_num); + __func__, api.nexthop_num); nexthop_group_delete(&ng); XFREE(MTYPE_RE, re); return; @@ -1612,7 +1608,7 @@ static void zread_route_add(ZAPI_HANDLER_ARGS) if (afi != AFI_IP6 && CHECK_FLAG(api.message, ZAPI_MESSAGE_SRCPFX)) { flog_warn(EC_ZEBRA_RX_SRCDEST_WRONG_AFI, "%s: Received SRC Prefix but afi is not v6", - __PRETTY_FUNCTION__); + __func__); nexthop_group_delete(&ng); XFREE(MTYPE_RE, re); return; @@ -1663,7 +1659,7 @@ static void zread_route_del(ZAPI_HANDLER_ARGS) if (afi != AFI_IP6 && CHECK_FLAG(api.message, ZAPI_MESSAGE_SRCPFX)) { flog_warn(EC_ZEBRA_RX_SRCDEST_WRONG_AFI, "%s: Received a src prefix while afi is not v6", - __PRETTY_FUNCTION__); + __func__); return; } if (CHECK_FLAG(api.message, ZAPI_MESSAGE_SRCPFX)) @@ -1773,10 +1769,11 @@ static void zread_hello(ZAPI_HANDLER_ARGS) client->proto = proto; client->instance = instance; + + /* Graceful restart processing for client connect */ + zebra_gr_client_reconnect(client); } - /* Graceful restart processing for client connect */ - zebra_gr_client_reconnect(client); zsend_capabilities(client, zvrf); zebra_vrf_update_all(client); stream_failure: @@ -1815,7 +1812,7 @@ static void zread_mpls_labels_add(ZAPI_HANDLER_ARGS) if (zapi_labels_decode(s, &zl) < 0) { if (IS_ZEBRA_DEBUG_RECV) zlog_debug("%s: Unable to decode zapi_labels sent", - __PRETTY_FUNCTION__); + __func__); return; } @@ -1826,7 +1823,9 @@ static void zread_mpls_labels_add(ZAPI_HANDLER_ARGS) struct zapi_nexthop *znh; znh = &zl.nexthops[i]; - mpls_lsp_install(zvrf, zl.type, zl.local_label, 1, znh->labels, + + mpls_lsp_install(zvrf, zl.type, zl.local_label, + znh->label_num, znh->labels, znh->type, &znh->gate, znh->ifindex); if (CHECK_FLAG(zl.message, ZAPI_LABELS_FTN)) @@ -1857,7 +1856,7 @@ static void zread_mpls_labels_delete(ZAPI_HANDLER_ARGS) if (zapi_labels_decode(s, &zl) < 0) { if (IS_ZEBRA_DEBUG_RECV) zlog_debug("%s: Unable to decode zapi_labels sent", - __PRETTY_FUNCTION__); + __func__); return; } @@ -1912,7 +1911,7 @@ static void zread_mpls_labels_replace(ZAPI_HANDLER_ARGS) if (zapi_labels_decode(s, &zl) < 0) { if (IS_ZEBRA_DEBUG_RECV) zlog_debug("%s: Unable to decode zapi_labels sent", - __PRETTY_FUNCTION__); + __func__); return; } @@ -1929,7 +1928,7 @@ static void zread_mpls_labels_replace(ZAPI_HANDLER_ARGS) znh = &zl.nexthops[i]; mpls_lsp_install(zvrf, zl.type, zl.local_label, - 1, znh->labels, znh->type, + znh->label_num, znh->labels, znh->type, &znh->gate, znh->ifindex); if (CHECK_FLAG(zl.message, ZAPI_LABELS_FTN)) { @@ -1948,6 +1947,7 @@ static void zread_table_manager_connect(struct zserv *client, struct stream *s; uint8_t proto; uint16_t instance; + struct vrf *vrf = vrf_lookup_by_id(vrf_id); s = msg; @@ -1963,8 +1963,9 @@ static void zread_table_manager_connect(struct zserv *client, zsend_table_manager_connect_response(client, vrf_id, 1); return; } - zlog_notice("client %d with vrf %u instance %u connected as %s", - client->sock, vrf_id, instance, zebra_route_string(proto)); + zlog_notice("client %d with vrf %s(%u) instance %u connected as %s", + client->sock, VRF_LOGNAME(vrf), vrf_id, instance, + zebra_route_string(proto)); client->proto = proto; client->instance = instance; @@ -2410,17 +2411,18 @@ static inline void zread_rule(ZAPI_HANDLER_ARGS) || zpr.rule.filter.src_ip.family == AF_INET6)) { zlog_warn( "Unsupported PBR source IP family: %s (%" PRIu8 - ")\n", + ")", family2str(zpr.rule.filter.src_ip.family), zpr.rule.filter.src_ip.family); return; } if (!(zpr.rule.filter.dst_ip.family == AF_INET || zpr.rule.filter.dst_ip.family == AF_INET6)) { - zlog_warn("Unsupported PBR IP family: %s (%" PRIu8 - ")\n", - family2str(zpr.rule.filter.dst_ip.family), - zpr.rule.filter.dst_ip.family); + zlog_warn( + "Unsupported PBR destination IP family: %s (%" PRIu8 + ")", + family2str(zpr.rule.filter.dst_ip.family), + zpr.rule.filter.dst_ip.family); return; } @@ -2510,6 +2512,23 @@ static inline void zread_ipset_entry(ZAPI_HANDLER_ARGS) if (zpi.proto != 0) zpi.filter_bm |= PBR_FILTER_PROTO; + if (!(zpi.dst.family == AF_INET + || zpi.dst.family == AF_INET6)) { + zlog_warn( + "Unsupported PBR destination IP family: %s (%" PRIu8 + ")", + family2str(zpi.dst.family), zpi.dst.family); + goto stream_failure; + } + if (!(zpi.src.family == AF_INET + || zpi.src.family == AF_INET6)) { + zlog_warn( + "Unsupported PBR source IP family: %s (%" PRIu8 + ")", + family2str(zpi.src.family), zpi.src.family); + goto stream_failure; + } + /* calculate backpointer */ zpi.backpointer = zebra_pbr_lookup_ipset_pername(ipset.ipset_name); diff --git a/zebra/zebra_dplane.c b/zebra/zebra_dplane.c index 17b148178f..459d2bc620 100644 --- a/zebra/zebra_dplane.c +++ b/zebra/zebra_dplane.c @@ -1513,9 +1513,9 @@ static int dplane_ctx_route_init(struct zebra_dplane_ctx *ctx, /* Copy nexthops; recursive info is included too */ copy_nexthops(&(ctx->u.rinfo.zd_ng.nexthop), - re->nhe->nhg->nexthop, NULL); + re->nhe->nhg.nexthop, NULL); - /* Ensure that the dplane's nexthops flags are clear. */ + /* Ensure that the dplane nexthops' flags are clear. */ for (ALL_NEXTHOPS(ctx->u.rinfo.zd_ng, nexthop)) UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB); @@ -1596,9 +1596,9 @@ static int dplane_ctx_nexthop_init(struct zebra_dplane_ctx *ctx, ctx->u.rinfo.nhe.vrf_id = nhe->vrf_id; ctx->u.rinfo.nhe.type = nhe->type; - nexthop_group_copy(&(ctx->u.rinfo.nhe.ng), nhe->nhg); + nexthop_group_copy(&(ctx->u.rinfo.nhe.ng), &(nhe->nhg)); - /* If its a group, convert it to a grp array of ids */ + /* If this is a group, convert it to a grp array of ids */ if (!zebra_nhg_depends_is_empty(nhe) && !CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_RECURSIVE)) ctx->u.rinfo.nhe.nh_grp_count = zebra_nhg_nhe2grp( @@ -1753,7 +1753,7 @@ static int dplane_ctx_pw_init(struct zebra_dplane_ctx *ctx, if (re) copy_nexthops(&(ctx->u.pw.nhg.nexthop), - re->nhe->nhg->nexthop, NULL); + re->nhe->nhg.nexthop, NULL); route_unlock_node(rn); } @@ -1849,7 +1849,7 @@ dplane_route_update_internal(struct route_node *rn, * We'll need these to do per-nexthop deletes. */ copy_nexthops(&(ctx->u.rinfo.zd_old_ng.nexthop), - old_re->nhe->nhg->nexthop, NULL); + old_re->nhe->nhg.nexthop, NULL); #endif /* !HAVE_NETLINK */ } @@ -3331,7 +3331,7 @@ skip_one: return 0; } -#if DPLANE_TEST_PROVIDER +#ifdef DPLANE_TEST_PROVIDER /* * Test dataplane provider plugin @@ -3415,7 +3415,7 @@ static void dplane_provider_init(void) zlog_err("Unable to register kernel dplane provider: %d", ret); -#if DPLANE_TEST_PROVIDER +#ifdef DPLANE_TEST_PROVIDER /* Optional test provider ... */ ret = dplane_provider_register("Test", DPLANE_PRIO_PRE_KERNEL, diff --git a/zebra/zebra_fpm.c b/zebra/zebra_fpm.c index fa48c03c71..0190ee2b8d 100644 --- a/zebra/zebra_fpm.c +++ b/zebra/zebra_fpm.c @@ -70,7 +70,7 @@ DEFINE_MTYPE_STATIC(ZEBRA, FPM_MAC_INFO, "FPM_MAC_INFO"); #define ZFPM_STATS_IVL_SECS 10 #define FPM_MAX_MAC_MSG_LEN 512 -static void zfpm_iterate_rmac_table(struct hash_backet *backet, void *args); +static void zfpm_iterate_rmac_table(struct hash_bucket *backet, void *args); /* * Structure that holds state for iterating over all route_node @@ -1647,7 +1647,7 @@ static int zfpm_trigger_rmac_update(zebra_mac_t *rmac, zebra_l3vni_t *zl3vni, * Iterate over all the RMAC entries for the given L3VNI * and enqueue the RMAC for FPM processing. */ -static void zfpm_trigger_rmac_update_wrapper(struct hash_backet *backet, +static void zfpm_trigger_rmac_update_wrapper(struct hash_bucket *backet, void *args) { zebra_mac_t *zrmac = (zebra_mac_t *)backet->data; @@ -1661,7 +1661,7 @@ static void zfpm_trigger_rmac_update_wrapper(struct hash_backet *backet, * This function iterates over all the L3VNIs to trigger * FPM updates for RMACs currently available. */ -static void zfpm_iterate_rmac_table(struct hash_backet *backet, void *args) +static void zfpm_iterate_rmac_table(struct hash_bucket *backet, void *args) { zebra_l3vni_t *zl3vni = (zebra_l3vni_t *)backet->data; diff --git a/zebra/zebra_fpm_dt.c b/zebra/zebra_fpm_dt.c index 389781d4f7..81437e72f5 100644 --- a/zebra/zebra_fpm_dt.c +++ b/zebra/zebra_fpm_dt.c @@ -90,7 +90,7 @@ static int zfpm_dt_find_route(rib_dest_t **dest_p, struct route_entry **re_p) if (!re) continue; - if (nexthop_group_active_nexthop_num(re->nhe->nhg) == 0) + if (nexthop_group_active_nexthop_num(&(re->nhe->nhg)) == 0) continue; *dest_p = dest; diff --git a/zebra/zebra_fpm_netlink.c b/zebra/zebra_fpm_netlink.c index be29b75aea..0d6428026a 100644 --- a/zebra/zebra_fpm_netlink.c +++ b/zebra/zebra_fpm_netlink.c @@ -300,8 +300,7 @@ static int netlink_route_info_fill(netlink_route_info_t *ri, int cmd, return 1; if (!re) { - zfpm_debug("%s: Expected non-NULL re pointer", - __PRETTY_FUNCTION__); + zfpm_debug("%s: Expected non-NULL re pointer", __func__); return 0; } @@ -309,7 +308,7 @@ static int netlink_route_info_fill(netlink_route_info_t *ri, int cmd, ri->rtm_type = RTN_UNICAST; ri->metric = &re->metric; - for (ALL_NEXTHOPS_PTR(re->nhe->nhg, nexthop)) { + for (ALL_NEXTHOPS(re->nhe->nhg, nexthop)) { if (ri->num_nhs >= zrouter.multipath_num) break; @@ -570,7 +569,7 @@ int zfpm_netlink_encode_route(int cmd, rib_dest_t *dest, struct route_entry *re, if (!netlink_route_info_fill(ri, cmd, dest, re)) return 0; - zfpm_log_route_info(ri, __FUNCTION__); + zfpm_log_route_info(ri, __func__); return netlink_route_info_encode(ri, in_buf, in_buf_len); } diff --git a/zebra/zebra_fpm_protobuf.c b/zebra/zebra_fpm_protobuf.c index d50981debf..ade4b636d6 100644 --- a/zebra/zebra_fpm_protobuf.c +++ b/zebra/zebra_fpm_protobuf.c @@ -173,7 +173,7 @@ static Fpm__AddRoute *create_add_route_message(qpb_allocator_t *allocator, * Figure out the set of nexthops to be added to the message. */ num_nhs = 0; - for (ALL_NEXTHOPS_PTR(re->nhe->nhg, nexthop)) { + for (ALL_NEXTHOPS(re->nhe->nhg, nexthop)) { if (num_nhs >= zrouter.multipath_num) break; diff --git a/zebra/zebra_gr.c b/zebra/zebra_gr.c index e8c7304f44..19a280c0ca 100644 --- a/zebra/zebra_gr.c +++ b/zebra/zebra_gr.c @@ -127,8 +127,7 @@ static void zebra_gr_client_info_delte(struct zserv *client, THREAD_OFF(info->t_stale_removal); - if (info->current_prefix) - XFREE(MTYPE_TMP, info->current_prefix); + XFREE(MTYPE_TMP, info->current_prefix); LOG_GR("%s: Instance info is being deleted for client %s", __func__, zebra_route_string(client->proto)); @@ -265,30 +264,31 @@ void zebra_gr_client_reconnect(struct zserv *client) } /* Copy the timers */ - if (old_client) { - client->gr_instance_count = old_client->gr_instance_count; - client->restart_time = old_client->restart_time; - - LOG_GR("%s : old client %s, gr_instance_count %d", __func__, - zebra_route_string(old_client->proto), - old_client->gr_instance_count); - - if (TAILQ_FIRST(&old_client->gr_info_queue)) { - TAILQ_CONCAT(&client->gr_info_queue, - &old_client->gr_info_queue, gr_info); - TAILQ_INIT(&old_client->gr_info_queue); - } + if (!old_client) + return; - TAILQ_FOREACH (info, &client->gr_info_queue, gr_info) { - info->stale_client_ptr = client; - info->stale_client = false; - } + client->gr_instance_count = old_client->gr_instance_count; + client->restart_time = old_client->restart_time; + + LOG_GR("%s : old client %s, gr_instance_count %d", __func__, + zebra_route_string(old_client->proto), + old_client->gr_instance_count); + + if (TAILQ_FIRST(&old_client->gr_info_queue)) { + TAILQ_CONCAT(&client->gr_info_queue, &old_client->gr_info_queue, + gr_info); + TAILQ_INIT(&old_client->gr_info_queue); + } - /* Delete the stale client */ - listnode_delete(zrouter.stale_client_list, old_client); - /* Delete old client */ - XFREE(MTYPE_TMP, old_client); + TAILQ_FOREACH (info, &client->gr_info_queue, gr_info) { + info->stale_client_ptr = client; + info->stale_client = false; } + + /* Delete the stale client */ + listnode_delete(zrouter.stale_client_list, old_client); + /* Delete old client */ + XFREE(MTYPE_TMP, old_client); } /* @@ -425,6 +425,12 @@ void zread_client_capabilities(ZAPI_HANDLER_ARGS) return; } + /* GR only for dynamic clients */ + if (client->proto <= ZEBRA_ROUTE_CONNECT) { + LOG_GR("%s: GR capabilities for client %s not supported", + __func__, zebra_route_string(client->proto)); + return; + } /* Call the capabilities handler */ zebra_client_capabilities_handler(client, &api); } @@ -468,9 +474,7 @@ static int32_t zebra_gr_route_stale_delete_timer_expiry(struct thread *thread) LOG_GR("%s: Client %s all starle routes processed", __func__, zebra_route_string(client->proto)); - if (info->current_prefix != NULL) - XFREE(MTYPE_TMP, info->current_prefix); - info->current_prefix = NULL; + XFREE(MTYPE_TMP, info->current_prefix); info->current_afi = 0; zebra_gr_delete_stale_client(info); } @@ -516,7 +520,6 @@ static int32_t zebra_gr_delete_stale_route(struct client_gr_info *info, struct route_entry *next; struct route_table *table; int32_t n = 0; - struct prefix *p; afi_t afi, curr_afi; uint8_t proto; uint16_t instance; @@ -541,25 +544,21 @@ static int32_t zebra_gr_delete_stale_route(struct client_gr_info *info, /* Process routes for all AFI */ for (afi = curr_afi; afi < AFI_MAX; afi++) { table = zvrf->table[afi][SAFI_UNICAST]; - p = info->current_prefix; if (table) { /* * If the current prefix is NULL then get the first * route entry in the table */ - if (p == NULL) { + if (info->current_prefix == NULL) { rn = route_top(table); if (rn == NULL) continue; - p = XCALLOC(MTYPE_TMP, sizeof(struct prefix)); - if (p == NULL) - return -1; curr = rn; - prefix_copy(p, &rn->p); } else /* Get the next route entry */ - curr = route_table_get_next(table, p); + curr = route_table_get_next( + table, info->current_prefix); for (rn = curr; rn; rn = srcdest_route_next(rn)) { RNODE_FOREACH_RE_SAFE (rn, re, next) { @@ -583,9 +582,13 @@ static int32_t zebra_gr_delete_stale_route(struct client_gr_info *info, */ if ((n >= ZEBRA_MAX_STALE_ROUTE_COUNT) && (info->delete == false)) { - prefix_copy(p, &rn->p); info->current_afi = afi; - info->current_prefix = p; + info->current_prefix = XCALLOC( + MTYPE_TMP, + sizeof(struct prefix)); + prefix_copy( + info->current_prefix, + &rn->p); return n; } } @@ -595,11 +598,7 @@ static int32_t zebra_gr_delete_stale_route(struct client_gr_info *info, * Reset the current prefix to indicate processing completion * of the current AFI */ - if (info->current_prefix) { - XFREE(MTYPE_TMP, info->current_prefix); - info->current_prefix = NULL; - } - continue; + XFREE(MTYPE_TMP, info->current_prefix); } return 0; } diff --git a/zebra/zebra_mlag.c b/zebra/zebra_mlag.c index fc7804a409..8ba7998f50 100644 --- a/zebra/zebra_mlag.c +++ b/zebra/zebra_mlag.c @@ -322,7 +322,7 @@ static int zebra_mlag_post_data_from_main_thread(struct thread *thread) STREAM_GETL(s, msg_type); if (IS_ZEBRA_DEBUG_MLAG) zlog_debug( - "%s: Posting MLAG data for msg_type:0x%x to interested cleints", + "%s: Posting MLAG data for msg_type:0x%x to interested clients", __func__, msg_type); msg_len = s->endp - ZEBRA_MLAG_METADATA_LEN; @@ -364,7 +364,7 @@ stream_failure: /* * Start the MLAG Thread, this will be used to write client data on to - * MLAG Process and to read the data from MLAG and post to cleints. + * MLAG Process and to read the data from MLAG and post to clients. * when all clients are un-registered, this Thread will be * suspended. */ @@ -605,7 +605,7 @@ int32_t zebra_mlag_test_mlag_internal(const char *none, const char *primary, zsend_capabilities_all_clients(); if (zrouter.mlag_info.role != MLAG_ROLE_NONE) { if (zrouter.mlag_info.clients_interested_cnt == 0 - && test_mlag_in_progress == false) { + && !test_mlag_in_progress) { if (zrouter.mlag_info.zebra_pth_mlag == NULL) zebra_mlag_spawn_pthread(); zrouter.mlag_info.clients_interested_cnt++; @@ -613,7 +613,7 @@ int32_t zebra_mlag_test_mlag_internal(const char *none, const char *primary, hook_call(zebra_mlag_private_open_channel); } } else { - if (test_mlag_in_progress == true) { + if (test_mlag_in_progress) { test_mlag_in_progress = false; zrouter.mlag_info.clients_interested_cnt--; hook_call(zebra_mlag_private_close_channel); @@ -667,14 +667,17 @@ int zebra_mlag_protobuf_encode_client_data(struct stream *s, uint32_t *msg_type) int n_len = 0; int rc = 0; char buf[ZLOG_FILTER_LENGTH_MAX]; + size_t length; if (IS_ZEBRA_DEBUG_MLAG) zlog_debug("%s: Entering..", __func__); - rc = mlag_lib_decode_mlag_hdr(s, &mlag_msg); + rc = mlag_lib_decode_mlag_hdr(s, &mlag_msg, &length); if (rc) return rc; + memset(tmp_buf, 0, ZEBRA_MLAG_BUF_LIMIT); + if (IS_ZEBRA_DEBUG_MLAG) zlog_debug("%s: Mlag ProtoBuf encoding of message:%s, len:%d", __func__, @@ -688,9 +691,10 @@ int zebra_mlag_protobuf_encode_client_data(struct stream *s, uint32_t *msg_type) ZebraMlagMrouteAdd pay_load = ZEBRA_MLAG_MROUTE_ADD__INIT; uint32_t vrf_name_len = 0; - rc = mlag_lib_decode_mroute_add(s, &msg); + rc = mlag_lib_decode_mroute_add(s, &msg, &length); if (rc) return rc; + vrf_name_len = strlen(msg.vrf_name) + 1; pay_load.vrf_name = XMALLOC(MTYPE_MLAG_PBUF, vrf_name_len); strlcpy(pay_load.vrf_name, msg.vrf_name, vrf_name_len); @@ -720,7 +724,7 @@ int zebra_mlag_protobuf_encode_client_data(struct stream *s, uint32_t *msg_type) ZebraMlagMrouteDel pay_load = ZEBRA_MLAG_MROUTE_DEL__INIT; uint32_t vrf_name_len = 0; - rc = mlag_lib_decode_mroute_del(s, &msg); + rc = mlag_lib_decode_mroute_del(s, &msg, &length); if (rc) return rc; vrf_name_len = strlen(msg.vrf_name) + 1; @@ -749,18 +753,18 @@ int zebra_mlag_protobuf_encode_client_data(struct stream *s, uint32_t *msg_type) ZebraMlagMrouteAddBulk Bulk_msg = ZEBRA_MLAG_MROUTE_ADD_BULK__INIT; ZebraMlagMrouteAdd **pay_load = NULL; - int i; bool cleanup = false; + uint32_t i, actual; Bulk_msg.n_mroute_add = mlag_msg.msg_cnt; pay_load = XMALLOC(MTYPE_MLAG_PBUF, sizeof(ZebraMlagMrouteAdd *) * mlag_msg.msg_cnt); - for (i = 0; i < mlag_msg.msg_cnt; i++) { + for (i = 0, actual = 0; i < mlag_msg.msg_cnt; i++, actual++) { uint32_t vrf_name_len = 0; - rc = mlag_lib_decode_mroute_add(s, &msg); + rc = mlag_lib_decode_mroute_add(s, &msg, &length); if (rc) { cleanup = true; break; @@ -790,13 +794,21 @@ int zebra_mlag_protobuf_encode_client_data(struct stream *s, uint32_t *msg_type) vrf_name_len); } } - if (cleanup == false) { + if (!cleanup) { Bulk_msg.mroute_add = pay_load; len = zebra_mlag_mroute_add_bulk__pack(&Bulk_msg, tmp_buf); } - for (i = 0; i < mlag_msg.msg_cnt; i++) { + for (i = 0; i < actual; i++) { + /* + * The mlag_lib_decode_mroute_add can + * fail to properly decode and cause nothing + * to be allocated. Prevent a crash + */ + if (!pay_load[i]) + continue; + XFREE(MTYPE_MLAG_PBUF, pay_load[i]->vrf_name); if (pay_load[i]->owner_id == MLAG_OWNER_INTERFACE && pay_load[i]->intf_name) @@ -804,7 +816,7 @@ int zebra_mlag_protobuf_encode_client_data(struct stream *s, uint32_t *msg_type) XFREE(MTYPE_MLAG_PBUF, pay_load[i]); } XFREE(MTYPE_MLAG_PBUF, pay_load); - if (cleanup == true) + if (cleanup) return -1; } break; case MLAG_MROUTE_DEL_BULK: { @@ -812,18 +824,18 @@ int zebra_mlag_protobuf_encode_client_data(struct stream *s, uint32_t *msg_type) ZebraMlagMrouteDelBulk Bulk_msg = ZEBRA_MLAG_MROUTE_DEL_BULK__INIT; ZebraMlagMrouteDel **pay_load = NULL; - int i; bool cleanup = false; + uint32_t i, actual; Bulk_msg.n_mroute_del = mlag_msg.msg_cnt; pay_load = XMALLOC(MTYPE_MLAG_PBUF, sizeof(ZebraMlagMrouteDel *) * mlag_msg.msg_cnt); - for (i = 0; i < mlag_msg.msg_cnt; i++) { + for (i = 0, actual = 0; i < mlag_msg.msg_cnt; i++, actual++) { uint32_t vrf_name_len = 0; - rc = mlag_lib_decode_mroute_del(s, &msg); + rc = mlag_lib_decode_mroute_del(s, &msg, &length); if (rc) { cleanup = true; break; @@ -858,7 +870,15 @@ int zebra_mlag_protobuf_encode_client_data(struct stream *s, uint32_t *msg_type) tmp_buf); } - for (i = 0; i < mlag_msg.msg_cnt; i++) { + for (i = 0; i < actual; i++) { + /* + * The mlag_lib_decode_mroute_add can + * fail to properly decode and cause nothing + * to be allocated. Prevent a crash + */ + if (!pay_load[i]) + continue; + XFREE(MTYPE_MLAG_PBUF, pay_load[i]->vrf_name); if (pay_load[i]->owner_id == MLAG_OWNER_INTERFACE && pay_load[i]->intf_name) @@ -915,6 +935,15 @@ int zebra_mlag_protobuf_encode_client_data(struct stream *s, uint32_t *msg_type) return len; } +static void zebra_fill_protobuf_msg(struct stream *s, char *name, int len) +{ + int str_len = strlen(name) + 1; + + stream_put(s, name, str_len); + /* Fill the rest with Null Character for aligning */ + stream_put(s, NULL, len - str_len); +} + int zebra_mlag_protobuf_decode_message(struct stream *s, uint8_t *data, uint32_t len) { @@ -966,7 +995,8 @@ int zebra_mlag_protobuf_decode_message(struct stream *s, uint8_t *data, /* No Batching */ stream_putw(s, MLAG_MSG_NO_BATCH); /* Actual Data */ - stream_put(s, msg->peerlink, INTERFACE_NAMSIZ); + zebra_fill_protobuf_msg(s, msg->peerlink, + INTERFACE_NAMSIZ); stream_putl(s, msg->my_role); stream_putl(s, msg->peer_state); zebra_mlag_status_update__free_unpacked(msg, NULL); @@ -1003,7 +1033,7 @@ int zebra_mlag_protobuf_decode_message(struct stream *s, uint8_t *data, /* No Batching */ stream_putw(s, MLAG_MSG_NO_BATCH); /* Actual Data */ - stream_put(s, msg->vrf_name, VRF_NAMSIZ); + zebra_fill_protobuf_msg(s, msg->vrf_name, VRF_NAMSIZ); stream_putl(s, msg->source_ip); stream_putl(s, msg->group_ip); @@ -1013,7 +1043,8 @@ int zebra_mlag_protobuf_decode_message(struct stream *s, uint8_t *data, stream_putc(s, msg->am_i_dual_active); stream_putl(s, msg->vrf_id); if (msg->owner_id == MLAG_OWNER_INTERFACE) - stream_put(s, msg->intf_name, INTERFACE_NAMSIZ); + zebra_fill_protobuf_msg(s, msg->intf_name, + INTERFACE_NAMSIZ); else stream_put(s, NULL, INTERFACE_NAMSIZ); zebra_mlag_mroute_add__free_unpacked(msg, NULL); @@ -1032,15 +1063,15 @@ int zebra_mlag_protobuf_decode_message(struct stream *s, uint8_t *data, /* No Batching */ stream_putw(s, MLAG_MSG_NO_BATCH); /* Actual Data */ - stream_put(s, msg->vrf_name, VRF_NAMSIZ); + zebra_fill_protobuf_msg(s, msg->vrf_name, VRF_NAMSIZ); stream_putl(s, msg->source_ip); stream_putl(s, msg->group_ip); - stream_putl(s, msg->group_ip); stream_putl(s, msg->owner_id); stream_putl(s, msg->vrf_id); if (msg->owner_id == MLAG_OWNER_INTERFACE) - stream_put(s, msg->intf_name, INTERFACE_NAMSIZ); + zebra_fill_protobuf_msg(s, msg->intf_name, + INTERFACE_NAMSIZ); else stream_put(s, NULL, INTERFACE_NAMSIZ); zebra_mlag_mroute_del__free_unpacked(msg, NULL); @@ -1067,7 +1098,8 @@ int zebra_mlag_protobuf_decode_message(struct stream *s, uint8_t *data, msg = Bulk_msg->mroute_add[i]; - stream_put(s, msg->vrf_name, VRF_NAMSIZ); + zebra_fill_protobuf_msg(s, msg->vrf_name, + VRF_NAMSIZ); stream_putl(s, msg->source_ip); stream_putl(s, msg->group_ip); stream_putl(s, msg->cost_to_rp); @@ -1076,8 +1108,9 @@ int zebra_mlag_protobuf_decode_message(struct stream *s, uint8_t *data, stream_putc(s, msg->am_i_dual_active); stream_putl(s, msg->vrf_id); if (msg->owner_id == MLAG_OWNER_INTERFACE) - stream_put(s, msg->intf_name, - INTERFACE_NAMSIZ); + zebra_fill_protobuf_msg( + s, msg->intf_name, + INTERFACE_NAMSIZ); else stream_put(s, NULL, INTERFACE_NAMSIZ); } @@ -1106,14 +1139,16 @@ int zebra_mlag_protobuf_decode_message(struct stream *s, uint8_t *data, msg = Bulk_msg->mroute_del[i]; - stream_put(s, msg->vrf_name, VRF_NAMSIZ); + zebra_fill_protobuf_msg(s, msg->vrf_name, + VRF_NAMSIZ); stream_putl(s, msg->source_ip); stream_putl(s, msg->group_ip); stream_putl(s, msg->owner_id); stream_putl(s, msg->vrf_id); if (msg->owner_id == MLAG_OWNER_INTERFACE) - stream_put(s, msg->intf_name, - INTERFACE_NAMSIZ); + zebra_fill_protobuf_msg( + s, msg->intf_name, + INTERFACE_NAMSIZ); else stream_put(s, NULL, INTERFACE_NAMSIZ); } diff --git a/zebra/zebra_mlag.h b/zebra/zebra_mlag.h index c35fa15561..d44a400666 100644 --- a/zebra/zebra_mlag.h +++ b/zebra/zebra_mlag.h @@ -46,6 +46,7 @@ extern uint32_t mlag_rd_buf_offset; static inline void zebra_mlag_reset_read_buffer(void) { + memset(mlag_wr_buffer, 0, ZEBRA_MLAG_BUF_LIMIT); mlag_rd_buf_offset = 0; } diff --git a/zebra/zebra_mlag_private.c b/zebra/zebra_mlag_private.c index 3024407ada..0f0285ed31 100644 --- a/zebra/zebra_mlag_private.c +++ b/zebra/zebra_mlag_private.c @@ -78,6 +78,8 @@ static int zebra_mlag_read(struct thread *thread) uint32_t h_msglen; uint32_t tot_len, curr_len = mlag_rd_buf_offset; + zrouter.mlag_info.t_read = NULL; + /* * Received message in sock_stream looks like below * | len-1 (4 Bytes) | payload-1 (len-1) | @@ -157,8 +159,6 @@ static int zebra_mlag_read(struct thread *thread) static int zebra_mlag_connect(struct thread *thread) { struct sockaddr_un svr = {0}; - struct ucred ucred; - socklen_t len = 0; /* Reset the Timer-running flag */ zrouter.mlag_info.timer_running = false; @@ -182,11 +182,8 @@ static int zebra_mlag_connect(struct thread *thread) &zrouter.mlag_info.t_read); return 0; } - len = sizeof(struct ucred); - ucred.pid = getpid(); set_nonblocking(mlag_socket); - setsockopt(mlag_socket, SOL_SOCKET, SO_PEERCRED, &ucred, len); if (IS_ZEBRA_DEBUG_MLAG) zlog_debug("%s: Connection with MLAG is established ", diff --git a/zebra/zebra_mpls.c b/zebra/zebra_mpls.c index c167e6a8ad..d373fdf370 100644 --- a/zebra/zebra_mpls.c +++ b/zebra/zebra_mpls.c @@ -93,6 +93,8 @@ static void lsp_processq_del(struct work_queue *wq, void *data); static void lsp_processq_complete(struct work_queue *wq); static int lsp_processq_add(zebra_lsp_t *lsp); static void *lsp_alloc(void *p); +/* Free lsp; sets caller's pointer to NULL */ +static void lsp_free(struct hash *lsp_table, zebra_lsp_t **plsp); static char *nhlfe2str(zebra_nhlfe_t *nhlfe, char *buf, int size); static int nhlfe_nhop_match(zebra_nhlfe_t *nhlfe, enum nexthop_types_t gtype, @@ -186,7 +188,7 @@ static int lsp_install(struct zebra_vrf *zvrf, mpls_label_t label, * the label advertised by the recursive nexthop (plus we don't have the * logic yet to push multiple labels). */ - for (nexthop = re->nhe->nhg->nexthop; + for (nexthop = re->nhe->nhg.nexthop; nexthop; nexthop = nexthop->next) { /* Skip inactive and recursive entries. */ if (!CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE)) @@ -250,14 +252,8 @@ static int lsp_install(struct zebra_vrf *zvrf, mpls_label_t label, if (lsp_processq_add(lsp)) return -1; } else if (!lsp->nhlfe_list - && !CHECK_FLAG(lsp->flags, LSP_FLAG_SCHEDULED)) { - if (IS_ZEBRA_DEBUG_MPLS) - zlog_debug("Free LSP in-label %u flags 0x%x", - lsp->ile.in_label, lsp->flags); - - lsp = hash_release(lsp_table, &lsp->ile); - XFREE(MTYPE_LSP, lsp); - } + && !CHECK_FLAG(lsp->flags, LSP_FLAG_SCHEDULED)) + lsp_free(lsp_table, &lsp); return 0; } @@ -313,14 +309,8 @@ static int lsp_uninstall(struct zebra_vrf *zvrf, mpls_label_t label) if (lsp_processq_add(lsp)) return -1; } else if (!lsp->nhlfe_list - && !CHECK_FLAG(lsp->flags, LSP_FLAG_SCHEDULED)) { - if (IS_ZEBRA_DEBUG_MPLS) - zlog_debug("Del LSP in-label %u flags 0x%x", - lsp->ile.in_label, lsp->flags); - - lsp = hash_release(lsp_table, &lsp->ile); - XFREE(MTYPE_LSP, lsp); - } + && !CHECK_FLAG(lsp->flags, LSP_FLAG_SCHEDULED)) + lsp_free(lsp_table, &lsp); return 0; } @@ -638,7 +628,7 @@ static int nhlfe_nexthop_active_ipv4(zebra_nhlfe_t *nhlfe, || !CHECK_FLAG(match->flags, ZEBRA_FLAG_SELECTED)) continue; - for (match_nh = match->nhe->nhg->nexthop; match_nh; + for (match_nh = match->nhe->nhg.nexthop; match_nh; match_nh = match_nh->next) { if (match->type == ZEBRA_ROUTE_CONNECT || nexthop->ifindex == match_nh->ifindex) { @@ -689,10 +679,10 @@ static int nhlfe_nexthop_active_ipv6(zebra_nhlfe_t *nhlfe, break; } - if (!match || !match->nhe->nhg->nexthop) + if (!match || !match->nhe->nhg.nexthop) return 0; - nexthop->ifindex = match->nhe->nhg->nexthop->ifindex; + nexthop->ifindex = match->nhe->nhg.nexthop->ifindex; return 1; } @@ -1047,14 +1037,8 @@ static void lsp_processq_del(struct work_queue *wq, void *data) nhlfe_del(nhlfe); } - if (!lsp->nhlfe_list) { - if (IS_ZEBRA_DEBUG_MPLS) - zlog_debug("Free LSP in-label %u flags 0x%x", - lsp->ile.in_label, lsp->flags); - - lsp = hash_release(lsp_table, &lsp->ile); - XFREE(MTYPE_LSP, lsp); - } + if (!lsp->nhlfe_list) + lsp_free(lsp_table, &lsp); } /* @@ -1104,6 +1088,37 @@ static void *lsp_alloc(void *p) } /* + * Dtor for an LSP: remove from ile hash, release any internal allocations, + * free LSP object. + */ +static void lsp_free(struct hash *lsp_table, zebra_lsp_t **plsp) +{ + zebra_lsp_t *lsp; + zebra_nhlfe_t *nhlfe, *nhlfe_next; + + if (plsp == NULL || *plsp == NULL) + return; + + lsp = *plsp; + + if (IS_ZEBRA_DEBUG_MPLS) + zlog_debug("Free LSP in-label %u flags 0x%x", + lsp->ile.in_label, lsp->flags); + + /* Free nhlfes, if any. */ + for (nhlfe = lsp->nhlfe_list; nhlfe; nhlfe = nhlfe_next) { + nhlfe_next = nhlfe->next; + + nhlfe_del(nhlfe); + } + + hash_release(lsp_table, &lsp->ile); + XFREE(MTYPE_LSP, lsp); + + *plsp = NULL; +} + +/* * Create printable string for NHLFE entry. */ static char *nhlfe2str(zebra_nhlfe_t *nhlfe, char *buf, int size) @@ -1334,14 +1349,8 @@ static int mpls_lsp_uninstall_all(struct hash *lsp_table, zebra_lsp_t *lsp, if (lsp_processq_add(lsp)) return -1; } else if (!lsp->nhlfe_list - && !CHECK_FLAG(lsp->flags, LSP_FLAG_SCHEDULED)) { - if (IS_ZEBRA_DEBUG_MPLS) - zlog_debug("Free LSP in-label %u flags 0x%x", - lsp->ile.in_label, lsp->flags); - - lsp = hash_release(lsp_table, &lsp->ile); - XFREE(MTYPE_LSP, lsp); - } + && !CHECK_FLAG(lsp->flags, LSP_FLAG_SCHEDULED)) + lsp_free(lsp_table, &lsp); return 0; } @@ -2631,7 +2640,7 @@ int mpls_ftn_update(int add, struct zebra_vrf *zvrf, enum lsp_types_t type, * We can't just change the values here since we are hashing * on labels. We need to create a whole new group */ - nexthop_group_copy(&new_grp, re->nhe->nhg); + nexthop_group_copy(&new_grp, &(re->nhe->nhg)); found = false; for (nexthop = new_grp.nexthop; nexthop; nexthop = nexthop->next) { @@ -2712,7 +2721,7 @@ int mpls_ftn_uninstall(struct zebra_vrf *zvrf, enum lsp_types_t type, if (re == NULL) return -1; - nexthop_group_copy(&new_grp, re->nhe->nhg); + nexthop_group_copy(&new_grp, &(re->nhe->nhg)); for (nexthop = new_grp.nexthop; nexthop; nexthop = nexthop->next) nexthop_del_labels(nexthop); @@ -2872,14 +2881,9 @@ int mpls_lsp_uninstall(struct zebra_vrf *zvrf, enum lsp_types_t type, /* Free LSP entry if no other NHLFEs and not scheduled. */ if (!lsp->nhlfe_list - && !CHECK_FLAG(lsp->flags, LSP_FLAG_SCHEDULED)) { - if (IS_ZEBRA_DEBUG_MPLS) - zlog_debug("Free LSP in-label %u flags 0x%x", - lsp->ile.in_label, lsp->flags); + && !CHECK_FLAG(lsp->flags, LSP_FLAG_SCHEDULED)) + lsp_free(lsp_table, &lsp); - lsp = hash_release(lsp_table, &lsp->ile); - XFREE(MTYPE_LSP, lsp); - } } return 0; } @@ -2949,7 +2953,7 @@ static void mpls_ftn_uninstall_all(struct zebra_vrf *zvrf, RNODE_FOREACH_RE (rn, re) { struct nexthop_group new_grp = {}; - nexthop_group_copy(&new_grp, re->nhe->nhg); + nexthop_group_copy(&new_grp, &(re->nhe->nhg)); for (nexthop = new_grp.nexthop; nexthop; nexthop = nexthop->next) { diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c index bb95e72382..f0d43756b5 100644 --- a/zebra/zebra_nhg.c +++ b/zebra/zebra_nhg.c @@ -315,20 +315,20 @@ zebra_nhg_connect_depends(struct nhg_hash_entry *nhe, } /* Add the ifp now if its not a group or recursive and has ifindex */ - if (zebra_nhg_depends_is_empty(nhe) && nhe->nhg->nexthop - && nhe->nhg->nexthop->ifindex) { + if (zebra_nhg_depends_is_empty(nhe) && nhe->nhg.nexthop + && nhe->nhg.nexthop->ifindex) { struct interface *ifp = NULL; - ifp = if_lookup_by_index(nhe->nhg->nexthop->ifindex, - nhe->nhg->nexthop->vrf_id); + ifp = if_lookup_by_index(nhe->nhg.nexthop->ifindex, + nhe->nhg.nexthop->vrf_id); if (ifp) zebra_nhg_set_if(nhe, ifp); else flog_err( EC_ZEBRA_IF_LOOKUP_FAILED, "Zebra failed to lookup an interface with ifindex=%d in vrf=%u for NHE id=%u", - nhe->nhg->nexthop->ifindex, - nhe->nhg->nexthop->vrf_id, nhe->id); + nhe->nhg.nexthop->ifindex, + nhe->nhg.nexthop->vrf_id, nhe->id); } } @@ -350,8 +350,7 @@ static struct nhg_hash_entry *zebra_nhg_copy(const struct nhg_hash_entry *copy, nhe->id = id; - nhe->nhg = nexthop_group_new(); - nexthop_group_copy(nhe->nhg, copy->nhg); + nexthop_group_copy(&(nhe->nhg), &(copy->nhg)); nhe->vrf_id = copy->vrf_id; nhe->afi = copy->afi; @@ -371,7 +370,7 @@ static void *zebra_nhg_hash_alloc(void *arg) nhe = zebra_nhg_copy(copy, copy->id); /* Mark duplicate nexthops in a group at creation time. */ - nexthop_group_mark_duplicates(nhe->nhg); + nexthop_group_mark_duplicates(&(nhe->nhg)); zebra_nhg_connect_depends(nhe, copy->nhg_depends); zebra_nhg_insert_id(nhe); @@ -385,7 +384,8 @@ uint32_t zebra_nhg_hash_key(const void *arg) uint32_t key = 0x5a351234; - key = jhash_3words(nhe->vrf_id, nhe->afi, nexthop_group_hash(nhe->nhg), + key = jhash_3words(nhe->vrf_id, nhe->afi, + nexthop_group_hash(&(nhe->nhg)), key); return key; @@ -416,7 +416,7 @@ bool zebra_nhg_hash_equal(const void *arg1, const void *arg2) return false; /* Nexthops should be sorted */ - for (nexthop1 = nhe1->nhg->nexthop, nexthop2 = nhe2->nhg->nexthop; + for (nexthop1 = nhe1->nhg.nexthop, nexthop2 = nhe2->nhg.nexthop; nexthop1 || nexthop2; nexthop1 = nexthop1->next, nexthop2 = nexthop2->next) { if (nexthop1 && !nexthop2) @@ -498,7 +498,7 @@ static int zebra_nhg_process_grp(struct nexthop_group *nhg, * in the kernel. */ - copy_nexthops(&nhg->nexthop, depend->nhg->nexthop, NULL); + copy_nexthops(&nhg->nexthop, depend->nhg.nexthop, NULL); } return 0; @@ -536,14 +536,14 @@ static bool zebra_nhg_find(struct nhg_hash_entry **nhe, uint32_t id, lookup.id = id ? id : ++id_counter; lookup.type = type ? type : ZEBRA_ROUTE_NHG; - lookup.nhg = nhg; + lookup.nhg = *nhg; lookup.vrf_id = vrf_id; - if (lookup.nhg->nexthop->next) { + if (lookup.nhg.nexthop->next) { /* Groups can have all vrfs and AF's in them */ lookup.afi = AFI_UNSPEC; } else { - switch (lookup.nhg->nexthop->type) { + switch (lookup.nhg.nexthop->type) { case (NEXTHOP_TYPE_IFINDEX): case (NEXTHOP_TYPE_BLACKHOLE): /* @@ -687,9 +687,9 @@ static struct nh_grp *nhg_ctx_get_grp(struct nhg_ctx *ctx) return ctx->u.grp; } -static struct nhg_ctx *nhg_ctx_new() +static struct nhg_ctx *nhg_ctx_new(void) { - struct nhg_ctx *new = NULL; + struct nhg_ctx *new; new = XCALLOC(MTYPE_NHG_CTX, sizeof(struct nhg_ctx)); @@ -1193,12 +1193,6 @@ zebra_nhg_rib_find(uint32_t id, struct nexthop_group *nhg, afi_t rt_afi) assert(nhg->nexthop); vrf_id = !vrf_is_backend_netns() ? VRF_DEFAULT : nhg->nexthop->vrf_id; - if (!(nhg && nhg->nexthop)) { - flog_err(EC_ZEBRA_TABLE_LOOKUP_FAILED, - "No nexthop passed to %s", __func__); - return NULL; - } - zebra_nhg_find(&nhe, id, nhg, NULL, vrf_id, rt_afi, 0); return nhe; @@ -1206,7 +1200,8 @@ zebra_nhg_rib_find(uint32_t id, struct nexthop_group *nhg, afi_t rt_afi) static void zebra_nhg_free_members(struct nhg_hash_entry *nhe) { - nexthop_group_delete(&nhe->nhg); + nexthops_free(nhe->nhg.nexthop); + /* Decrement to remove connection ref */ nhg_connected_tree_decrement_ref(&nhe->nhg_depends); nhg_connected_tree_free(&nhe->nhg_depends); @@ -1417,7 +1412,7 @@ static int nexthop_active(afi_t afi, struct route_entry *re, if (IS_ZEBRA_DEBUG_RIB_DETAILED) zlog_debug( "\t%s: Onlink and interface: %u[%u] does not exist", - __PRETTY_FUNCTION__, nexthop->ifindex, + __func__, nexthop->ifindex, nexthop->vrf_id); return 0; } @@ -1428,14 +1423,14 @@ static int nexthop_active(afi_t afi, struct route_entry *re, if (IS_ZEBRA_DEBUG_RIB_DETAILED) zlog_debug( "\t%s: Onlink and interface %s is not operative", - __PRETTY_FUNCTION__, ifp->name); + __func__, ifp->name); return 0; } if (!if_is_operative(ifp)) { if (IS_ZEBRA_DEBUG_RIB_DETAILED) zlog_debug( "\t%s: Interface %s is not unnumbered", - __PRETTY_FUNCTION__, ifp->name); + __func__, ifp->name); return 0; } } @@ -1447,7 +1442,7 @@ static int nexthop_active(afi_t afi, struct route_entry *re, if (IS_ZEBRA_DEBUG_RIB_DETAILED) zlog_debug( "\t:%s: Attempting to install a max prefixlength route through itself", - __PRETTY_FUNCTION__); + __func__); return 0; } @@ -1474,8 +1469,7 @@ static int nexthop_active(afi_t afi, struct route_entry *re, zvrf = zebra_vrf_lookup_by_id(nexthop->vrf_id); if (!table || !zvrf) { if (IS_ZEBRA_DEBUG_RIB_DETAILED) - zlog_debug("\t%s: Table not found", - __PRETTY_FUNCTION__); + zlog_debug("\t%s: Table not found", __func__); return 0; } @@ -1494,7 +1488,7 @@ static int nexthop_active(afi_t afi, struct route_entry *re, if (IS_ZEBRA_DEBUG_RIB_DETAILED) zlog_debug( "\t%s: Matched against ourself and prefix length is not max bit length", - __PRETTY_FUNCTION__); + __func__); return 0; } @@ -1507,7 +1501,7 @@ static int nexthop_active(afi_t afi, struct route_entry *re, if (IS_ZEBRA_DEBUG_RIB_DETAILED) zlog_debug( "\t:%s: Resolved against default route", - __PRETTY_FUNCTION__); + __func__); return 0; } @@ -1533,7 +1527,7 @@ static int nexthop_active(afi_t afi, struct route_entry *re, if (match->type == ZEBRA_ROUTE_CONNECT) { /* Directly point connected route. */ - newhop = match->nhe->nhg->nexthop; + newhop = match->nhe->nhg.nexthop; if (newhop) { if (nexthop->type == NEXTHOP_TYPE_IPV4 || nexthop->type == NEXTHOP_TYPE_IPV6) @@ -1542,7 +1536,7 @@ static int nexthop_active(afi_t afi, struct route_entry *re, return 1; } else if (CHECK_FLAG(re->flags, ZEBRA_FLAG_ALLOW_RECURSION)) { resolved = 0; - for (ALL_NEXTHOPS_PTR(match->nhe->nhg, newhop)) { + for (ALL_NEXTHOPS(match->nhe->nhg, newhop)) { if (!CHECK_FLAG(match->status, ROUTE_ENTRY_INSTALLED)) continue; @@ -1559,11 +1553,11 @@ static int nexthop_active(afi_t afi, struct route_entry *re, if (!resolved && IS_ZEBRA_DEBUG_RIB_DETAILED) zlog_debug("\t%s: Recursion failed to find", - __PRETTY_FUNCTION__); + __func__); return resolved; } else if (re->type == ZEBRA_ROUTE_STATIC) { resolved = 0; - for (ALL_NEXTHOPS_PTR(match->nhe->nhg, newhop)) { + for (ALL_NEXTHOPS(match->nhe->nhg, newhop)) { if (!CHECK_FLAG(match->status, ROUTE_ENTRY_INSTALLED)) continue; @@ -1581,14 +1575,13 @@ static int nexthop_active(afi_t afi, struct route_entry *re, if (!resolved && IS_ZEBRA_DEBUG_RIB_DETAILED) zlog_debug( "\t%s: Static route unable to resolve", - __PRETTY_FUNCTION__); + __func__); return resolved; } else { if (IS_ZEBRA_DEBUG_RIB_DETAILED) { zlog_debug( "\t%s: Route Type %s has not turned on recursion", - __PRETTY_FUNCTION__, - zebra_route_string(re->type)); + __func__, zebra_route_string(re->type)); if (re->type == ZEBRA_ROUTE_BGP && !CHECK_FLAG(re->flags, ZEBRA_FLAG_IBGP)) zlog_debug( @@ -1598,8 +1591,7 @@ static int nexthop_active(afi_t afi, struct route_entry *re, } } if (IS_ZEBRA_DEBUG_RIB_DETAILED) - zlog_debug("\t%s: Nexthop did not lookup in table", - __PRETTY_FUNCTION__); + zlog_debug("\t%s: Nexthop did not lookup in table", __func__); return 0; } @@ -1636,7 +1628,16 @@ static unsigned nexthop_active_check(struct route_node *rn, switch (nexthop->type) { case NEXTHOP_TYPE_IFINDEX: ifp = if_lookup_by_index(nexthop->ifindex, nexthop->vrf_id); - if (ifp && if_is_operative(ifp)) + /* + * If the interface exists and its operative or its a kernel + * route and interface is up, its active. We trust kernel routes + * to be good. + */ + if (ifp + && (if_is_operative(ifp) + || (if_is_up(ifp) + && (re->type == ZEBRA_ROUTE_KERNEL + || re->type == ZEBRA_ROUTE_SYSTEM)))) SET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE); else UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE); @@ -1683,7 +1684,7 @@ static unsigned nexthop_active_check(struct route_node *rn, if (!CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE)) { if (IS_ZEBRA_DEBUG_RIB_DETAILED) zlog_debug("\t%s: Unable to find a active nexthop", - __PRETTY_FUNCTION__); + __func__); return 0; } @@ -1712,7 +1713,7 @@ static unsigned nexthop_active_check(struct route_node *rn, zvrf = zebra_vrf_lookup_by_id(nexthop->vrf_id); if (!zvrf) { if (IS_ZEBRA_DEBUG_RIB_DETAILED) - zlog_debug("\t%s: zvrf is NULL", __PRETTY_FUNCTION__); + zlog_debug("\t%s: zvrf is NULL", __func__); return CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE); } @@ -1754,7 +1755,7 @@ int nexthop_active_update(struct route_node *rn, struct route_entry *re) UNSET_FLAG(re->status, ROUTE_ENTRY_CHANGED); /* Copy over the nexthops in current state */ - nexthop_group_copy(&new_grp, re->nhe->nhg); + nexthop_group_copy(&new_grp, &(re->nhe->nhg)); for (nexthop = new_grp.nexthop; nexthop; nexthop = nexthop->next) { @@ -1866,7 +1867,7 @@ uint8_t zebra_nhg_nhe2grp(struct nh_grp *grp, struct nhg_hash_entry *nhe, if (!duplicate) { grp[i].id = depend->id; /* We aren't using weights for anything right now */ - grp[i].weight = depend->nhg->nexthop->weight; + grp[i].weight = depend->nhg.nexthop->weight; i++; } diff --git a/zebra/zebra_nhg.h b/zebra/zebra_nhg.h index 4d001944b7..dc3a47c020 100644 --- a/zebra/zebra_nhg.h +++ b/zebra/zebra_nhg.h @@ -40,16 +40,15 @@ struct nh_grp { PREDECL_RBTREE_UNIQ(nhg_connected_tree); /* - * Hashtables contiaining entries found in `zebra_router`. + * Hashtables containing nhg entries is in `zebra_router`. */ - struct nhg_hash_entry { uint32_t id; afi_t afi; vrf_id_t vrf_id; int type; - struct nexthop_group *nhg; + struct nexthop_group nhg; /* If this is not a group, it * will be a single nexthop diff --git a/zebra/zebra_pbr.c b/zebra/zebra_pbr.c index ff3907451b..6728567e6e 100644 --- a/zebra/zebra_pbr.c +++ b/zebra/zebra_pbr.c @@ -458,7 +458,7 @@ void zebra_pbr_del_rule(struct zebra_pbr_rule *rule) XFREE(MTYPE_TMP, lookup); } else zlog_debug("%s: Rule being deleted we know nothing about", - __PRETTY_FUNCTION__); + __func__); } static void zebra_pbr_cleanup_rules(struct hash_bucket *b, void *data) @@ -572,7 +572,7 @@ void zebra_pbr_destroy_ipset(struct zebra_pbr_ipset *ipset) } else zlog_debug( "%s: IPSet Entry being deleted we know nothing about", - __PRETTY_FUNCTION__); + __func__); } struct pbr_ipset_name_lookup { @@ -651,7 +651,7 @@ void zebra_pbr_del_ipset_entry(struct zebra_pbr_ipset_entry *ipset) XFREE(MTYPE_TMP, lookup); } else zlog_debug("%s: IPSet being deleted we know nothing about", - __PRETTY_FUNCTION__); + __func__); } static void *pbr_iptable_alloc_intern(void *arg) @@ -710,7 +710,7 @@ void zebra_pbr_del_iptable(struct zebra_pbr_iptable *iptable) XFREE(MTYPE_TMP, lookup); } else zlog_debug("%s: IPTable being deleted we know nothing about", - __PRETTY_FUNCTION__); + __func__); } /* diff --git a/zebra/zebra_ptm.c b/zebra/zebra_ptm.c index 681b4d1ab8..669cb2466f 100644 --- a/zebra/zebra_ptm.c +++ b/zebra/zebra_ptm.c @@ -390,7 +390,7 @@ static int zebra_ptm_socket_init(void) if (set_nonblocking(sock) < 0) { if (IS_ZEBRA_DEBUG_EVENT) zlog_debug("%s: Unable to set socket non blocking[%s]", - __PRETTY_FUNCTION__, safe_strerror(errno)); + __func__, safe_strerror(errno)); close(sock); return -1; } @@ -441,15 +441,17 @@ static void if_bfd_session_update(struct interface *ifp, struct prefix *dp, dp->prefixlen, ifp->name, bfd_get_status_str(status)); } else { + struct vrf *vrf = vrf_lookup_by_id(vrf_id); + zlog_debug( "MESSAGE: ZEBRA_INTERFACE_BFD_DEST_UPDATE %s/%d " - "with src %s/%d and vrf %u %s event", + "with src %s/%d and vrf %s(%u) %s event", inet_ntop(dp->family, &dp->u.prefix, buf[0], INET6_ADDRSTRLEN), dp->prefixlen, inet_ntop(sp->family, &sp->u.prefix, buf[1], INET6_ADDRSTRLEN), - sp->prefixlen, vrf_id, + sp->prefixlen, VRF_LOGNAME(vrf), vrf_id, bfd_get_status_str(status)); } } diff --git a/zebra/zebra_pw.c b/zebra/zebra_pw.c index 618a232408..610a052c31 100644 --- a/zebra/zebra_pw.c +++ b/zebra/zebra_pw.c @@ -259,7 +259,7 @@ static int zebra_pw_check_reachability(struct zebra_pw *pw) * Need to ensure that there's a label binding for all nexthops. * Otherwise, ECMP for this route could render the pseudowire unusable. */ - for (ALL_NEXTHOPS_PTR(re->nhe->nhg, nexthop)) { + for (ALL_NEXTHOPS(re->nhe->nhg, nexthop)) { if (!nexthop->nh_label) { if (IS_ZEBRA_DEBUG_PW) zlog_debug("%s: unlabeled route for %s", diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 57bd986872..29d59b515f 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -198,8 +198,8 @@ int zebra_check_addr(const struct prefix *p) */ void route_entry_copy_nexthops(struct route_entry *re, struct nexthop *nh) { - assert(!re->nhe->nhg->nexthop); - copy_nexthops(&re->nhe->nhg->nexthop, nh, NULL); + assert(!re->nhe->nhg.nexthop); + copy_nexthops(&re->nhe->nhg.nexthop, nh, NULL); } static void route_entry_attach_ref(struct route_entry *re, @@ -217,12 +217,14 @@ int route_entry_update_nhe(struct route_entry *re, struct nhg_hash_entry *new) int ret = 0; if (new == NULL) { - re->nhe->nhg = NULL; + if (re->nhe) + zebra_nhg_decrement_ref(re->nhe); + re->nhe = NULL; goto done; } if (re->nhe_id != new->id) { - old = zebra_nhg_lookup_id(re->nhe_id); + old = re->nhe; route_entry_attach_ref(re, new); @@ -404,7 +406,7 @@ int zebra_rib_labeled_unicast(struct route_entry *re) if (re->type != ZEBRA_ROUTE_BGP) return 0; - for (ALL_NEXTHOPS_PTR(re->nhe->nhg, nexthop)) + for (ALL_NEXTHOPS(re->nhe->nhg, nexthop)) if (!nexthop->nh_label || !nexthop->nh_label->num_labels) return 0; @@ -428,7 +430,7 @@ void rib_install_kernel(struct route_node *rn, struct route_entry *re, srcdest_rnode_prefixes(rn, &p, &src_p); if (info->safi != SAFI_UNICAST) { - for (ALL_NEXTHOPS_PTR(re->nhe->nhg, nexthop)) + for (ALL_NEXTHOPS(re->nhe->nhg, nexthop)) SET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB); return; } @@ -437,7 +439,7 @@ void rib_install_kernel(struct route_node *rn, struct route_entry *re, /* * Install the resolved nexthop object first. */ - zebra_nhg_install_kernel(zebra_nhg_lookup_id(re->nhe_id)); + zebra_nhg_install_kernel(re->nhe); /* * If this is a replace to a new RE let the originator of the RE @@ -506,7 +508,7 @@ void rib_uninstall_kernel(struct route_node *rn, struct route_entry *re) if (info->safi != SAFI_UNICAST) { UNSET_FLAG(re->status, ROUTE_ENTRY_INSTALLED); - for (ALL_NEXTHOPS_PTR(re->nhe->nhg, nexthop)) + for (ALL_NEXTHOPS(re->nhe->nhg, nexthop)) UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB); return; } @@ -566,7 +568,7 @@ static void rib_uninstall(struct route_node *rn, struct route_entry *re) re->fib_ng.nexthop = NULL; } - for (ALL_NEXTHOPS_PTR(re->nhe->nhg, nexthop)) + for (ALL_NEXTHOPS(re->nhe->nhg, nexthop)) UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB); } @@ -630,10 +632,11 @@ void zebra_rib_evaluate_rn_nexthops(struct route_node *rn, uint32_t seq) if (IS_ZEBRA_DEBUG_NHT_DETAILED) { char buf[PREFIX_STRLEN]; - zlog_debug("%s: %s Being examined for Nexthop Tracking Count: %zd", - __PRETTY_FUNCTION__, - srcdest_rnode2str(rn, buf, sizeof(buf)), - dest ? rnh_list_count(&dest->nht) : 0); + zlog_debug( + "%s: %s Being examined for Nexthop Tracking Count: %zd", + __func__, + srcdest_rnode2str(rn, buf, sizeof(buf)), + dest ? rnh_list_count(&dest->nht) : 0); } if (!dest) { rn = rn->parent; @@ -742,7 +745,7 @@ static void rib_process_add_fib(struct zebra_vrf *zvrf, struct route_node *rn, /* Update real nexthop. This may actually determine if nexthop is active * or not. */ - if (!nexthop_group_active_nexthop_num(new->nhe->nhg)) { + if (!nexthop_group_active_nexthop_num(&(new->nhe->nhg))) { UNSET_FLAG(new->status, ROUTE_ENTRY_CHANGED); return; } @@ -811,7 +814,7 @@ static void rib_process_update_fib(struct zebra_vrf *zvrf, /* Update the nexthop; we could determine here that nexthop is * inactive. */ - if (nexthop_group_active_nexthop_num(new->nhe->nhg)) + if (nexthop_group_active_nexthop_num(&(new->nhe->nhg))) nh_active = 1; /* If nexthop is active, install the selected route, if @@ -929,7 +932,7 @@ static struct route_entry *rib_choose_best(struct route_entry *current, /* both are connected. are either loop or vrf? */ struct nexthop *nexthop = NULL; - for (ALL_NEXTHOPS_PTR(alternate->nhe->nhg, nexthop)) { + for (ALL_NEXTHOPS(alternate->nhe->nhg, nexthop)) { struct interface *ifp = if_lookup_by_index( nexthop->ifindex, alternate->vrf_id); @@ -937,7 +940,7 @@ static struct route_entry *rib_choose_best(struct route_entry *current, return alternate; } - for (ALL_NEXTHOPS_PTR(current->nhe->nhg, nexthop)) { + for (ALL_NEXTHOPS(current->nhe->nhg, nexthop)) { struct interface *ifp = if_lookup_by_index( nexthop->ifindex, current->vrf_id); @@ -1269,7 +1272,7 @@ static void zebra_rib_fixup_system(struct route_node *rn) SET_FLAG(re->status, ROUTE_ENTRY_INSTALLED); UNSET_FLAG(re->status, ROUTE_ENTRY_QUEUED); - for (ALL_NEXTHOPS_PTR(re->nhe->nhg, nhop)) { + for (ALL_NEXTHOPS(re->nhe->nhg, nhop)) { if (CHECK_FLAG(nhop->flags, NEXTHOP_FLAG_RECURSIVE)) continue; @@ -1386,7 +1389,7 @@ static bool rib_update_re_from_ctx(struct route_entry *re, || !CHECK_FLAG(ctx_nexthop->flags, NEXTHOP_FLAG_ACTIVE)) ctx_nexthop = nexthop_next_active_resolved(ctx_nexthop); - for (ALL_NEXTHOPS_PTR(re->nhe->nhg, nexthop)) { + for (ALL_NEXTHOPS(re->nhe->nhg, nexthop)) { if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE)) continue; @@ -2354,8 +2357,8 @@ void rib_unlink(struct route_node *rn, struct route_entry *re) nhe = zebra_nhg_lookup_id(re->nhe_id); if (nhe) zebra_nhg_decrement_ref(nhe); - } else if (re->nhe->nhg) - nexthop_group_delete(&re->nhe->nhg); + } else if (re->nhe->nhg.nexthop) + nexthops_free(re->nhe->nhg.nexthop); nexthops_free(re->fib_ng.nexthop); @@ -2408,13 +2411,14 @@ void _route_entry_dump(const char *func, union prefixconstptr pp, char srcaddr[PREFIX_STRLEN]; char nhname[PREFIX_STRLEN]; struct nexthop *nexthop; + struct vrf *vrf = vrf_lookup_by_id(re->vrf_id); - zlog_debug("%s: dumping RE entry %p for %s%s%s vrf %u", func, + zlog_debug("%s: dumping RE entry %p for %s%s%s vrf %s(%u)", func, (const void *)re, prefix2str(pp, straddr, sizeof(straddr)), is_srcdst ? " from " : "", is_srcdst ? prefix2str(src_pp, srcaddr, sizeof(srcaddr)) : "", - re->vrf_id); + VRF_LOGNAME(vrf), re->vrf_id); zlog_debug("%s: uptime == %lu, type == %u, instance == %d, table == %d", straddr, (unsigned long)re->uptime, re->type, re->instance, re->table); @@ -2422,10 +2426,10 @@ void _route_entry_dump(const char *func, union prefixconstptr pp, "%s: metric == %u, mtu == %u, distance == %u, flags == %u, status == %u", straddr, re->metric, re->mtu, re->distance, re->flags, re->status); zlog_debug("%s: nexthop_num == %u, nexthop_active_num == %u", straddr, - nexthop_group_nexthop_num(re->nhe->nhg), - nexthop_group_active_nexthop_num(re->nhe->nhg)); + nexthop_group_nexthop_num(&(re->nhe->nhg)), + nexthop_group_active_nexthop_num(&(re->nhe->nhg))); - for (ALL_NEXTHOPS_PTR(re->nhe->nhg, nexthop)) { + for (ALL_NEXTHOPS(re->nhe->nhg, nexthop)) { struct interface *ifp; struct vrf *vrf = vrf_lookup_by_id(nexthop->vrf_id); @@ -2783,7 +2787,7 @@ void rib_delete(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, if (re->type == ZEBRA_ROUTE_KERNEL && re->metric != metric) continue; if (re->type == ZEBRA_ROUTE_CONNECT && - (rtnh = re->nhe->nhg->nexthop) + (rtnh = re->nhe->nhg.nexthop) && rtnh->type == NEXTHOP_TYPE_IFINDEX && nh) { if (rtnh->ifindex != nh->ifindex) continue; @@ -2801,7 +2805,7 @@ void rib_delete(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, same = re; break; } - for (ALL_NEXTHOPS_PTR(re->nhe->nhg, rtnh)) { + for (ALL_NEXTHOPS(re->nhe->nhg, rtnh)) { /* * No guarantee all kernel send nh with labels * on delete. @@ -2843,7 +2847,7 @@ void rib_delete(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, if (allow_delete) { UNSET_FLAG(fib->status, ROUTE_ENTRY_INSTALLED); /* Unset flags. */ - for (rtnh = fib->nhe->nhg->nexthop; rtnh; + for (rtnh = fib->nhe->nhg.nexthop; rtnh; rtnh = rtnh->next) UNSET_FLAG(rtnh->flags, NEXTHOP_FLAG_FIB); @@ -2899,7 +2903,7 @@ void rib_delete(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, if (CHECK_FLAG(flags, ZEBRA_FLAG_EVPN_ROUTE)) { struct nexthop *tmp_nh; - for (ALL_NEXTHOPS_PTR(re->nhe->nhg, tmp_nh)) { + for (ALL_NEXTHOPS(re->nhe->nhg, tmp_nh)) { struct ipaddr vtep_ip; memset(&vtep_ip, 0, sizeof(struct ipaddr)); @@ -3169,7 +3173,7 @@ void rib_update(rib_update_event_t event) &t_rib_update_threads[event])) rib_update_ctx_fini(&ctx); /* Already scheduled */ else if (IS_ZEBRA_DEBUG_EVENT) - zlog_debug("%s: Schedued VRF (ALL), event %s", __func__, + zlog_debug("%s: Scheduled VRF (ALL), event %s", __func__, rib_update_event2str(event)); } @@ -3223,7 +3227,7 @@ void rib_sweep_table(struct route_table *table) * this decision needs to be revisited */ SET_FLAG(re->status, ROUTE_ENTRY_INSTALLED); - for (ALL_NEXTHOPS_PTR(re->nhe->nhg, nexthop)) + for (ALL_NEXTHOPS(re->nhe->nhg, nexthop)) SET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB); rib_uninstall_kernel(rn, re); diff --git a/zebra/zebra_rnh.c b/zebra/zebra_rnh.c index 2d9c83becb..6cfc68eb74 100644 --- a/zebra/zebra_rnh.c +++ b/zebra/zebra_rnh.c @@ -54,7 +54,7 @@ DEFINE_MTYPE_STATIC(ZEBRA, RNH, "Nexthop tracking object") static void free_state(vrf_id_t vrf_id, struct route_entry *re, struct route_node *rn); -static void copy_state(struct rnh *rnh, struct route_entry *re, +static void copy_state(struct rnh *rnh, const struct route_entry *re, struct route_node *rn); static int compare_state(struct route_entry *r1, struct route_entry *r2); static int send_client(struct rnh *rnh, struct zserv *client, rnh_type_t type, @@ -111,8 +111,8 @@ static void zebra_rnh_remove_from_routing_table(struct rnh *rnh) char buf[PREFIX_STRLEN]; char buf1[PREFIX_STRLEN]; - zlog_debug("%s: %u:%s removed from tracking on %s", - __PRETTY_FUNCTION__, rnh->vrf_id, + zlog_debug("%s: %u:%s removed from tracking on %s", __func__, + rnh->vrf_id, prefix2str(&rnh->node->p, buf, sizeof(buf)), srcdest_rnode2str(rn, buf1, sizeof(buf))); } @@ -137,8 +137,8 @@ static void zebra_rnh_store_in_routing_table(struct rnh *rnh) char buf[PREFIX_STRLEN]; char buf1[PREFIX_STRLEN]; - zlog_debug("%s: %u:%s added for tracking on %s", - __PRETTY_FUNCTION__, rnh->vrf_id, + zlog_debug("%s: %u:%s added for tracking on %s", __func__, + rnh->vrf_id, prefix2str(&rnh->node->p, buf, sizeof(buf)), srcdest_rnode2str(rn, buf1, sizeof(buf))); } @@ -384,7 +384,7 @@ static void zebra_rnh_clear_nexthop_rnh_filters(struct route_entry *re) struct nexthop *nexthop; if (re) { - for (nexthop = re->nhe->nhg->nexthop; nexthop; + for (nexthop = re->nhe->nhg.nexthop; nexthop; nexthop = nexthop->next) { UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_RNH_FILTERED); } @@ -403,7 +403,7 @@ static int zebra_rnh_apply_nht_rmap(afi_t afi, struct zebra_vrf *zvrf, route_map_result_t ret; if (prn && re) { - for (nexthop = re->nhe->nhg->nexthop; nexthop; + for (nexthop = re->nhe->nhg.nexthop; nexthop; nexthop = nexthop->next) { ret = zebra_nht_route_map_check( afi, proto, &prn->p, zvrf, re, nexthop); @@ -452,8 +452,8 @@ zebra_rnh_resolve_import_entry(struct zebra_vrf *zvrf, afi_t afi, char buf[PREFIX_STRLEN]; char buf1[PREFIX_STRLEN]; - zlog_debug("%s: %u:%s Resolved Import Entry to %s", - __PRETTY_FUNCTION__, rnh->vrf_id, + zlog_debug("%s: %u:%s Resolved Import Entry to %s", __func__, + rnh->vrf_id, prefix2str(&rnh->node->p, buf, sizeof(buf)), srcdest_rnode2str(rn, buf1, sizeof(buf))); } @@ -643,8 +643,8 @@ zebra_rnh_resolve_nexthop_entry(struct zebra_vrf *zvrf, afi_t afi, char buf[PREFIX_STRLEN]; char buf1[PREFIX_STRLEN]; - zlog_debug("%s: %u:%s Possible Match to %s", - __PRETTY_FUNCTION__, rnh->vrf_id, + zlog_debug("%s: %u:%s Possible Match to %s", __func__, + rnh->vrf_id, prefix2str(&rnh->node->p, buf, sizeof(buf)), srcdest_rnode2str(rn, buf1, sizeof(buf))); } @@ -669,7 +669,8 @@ zebra_rnh_resolve_nexthop_entry(struct zebra_vrf *zvrf, afi_t afi, zebra_route_string(re->type)); continue; } - if (!CHECK_FLAG(re->flags, ZEBRA_FLAG_SELECTED)) { + if (!CHECK_FLAG(re->flags, ZEBRA_FLAG_SELECTED) && + !CHECK_FLAG(re->flags, ZEBRA_FLAG_FIB_OVERRIDE)) { if (IS_ZEBRA_DEBUG_NHT_DETAILED) zlog_debug( "\tRoute Entry %s !selected", @@ -688,7 +689,7 @@ zebra_rnh_resolve_nexthop_entry(struct zebra_vrf *zvrf, afi_t afi, /* Just being SELECTED isn't quite enough - must * have an installed nexthop to be useful. */ - for (ALL_NEXTHOPS_PTR(re->nhe->nhg, nexthop)) { + for (ALL_NEXTHOPS(re->nhe->nhg, nexthop)) { if (rnh_nexthop_valid(re, nexthop)) break; } @@ -707,7 +708,7 @@ zebra_rnh_resolve_nexthop_entry(struct zebra_vrf *zvrf, afi_t afi, break; if (re->type == ZEBRA_ROUTE_NHRP) { - for (nexthop = re->nhe->nhg->nexthop; + for (nexthop = re->nhe->nhg.nexthop; nexthop; nexthop = nexthop->next) if (nexthop->type @@ -945,7 +946,7 @@ static void free_state(vrf_id_t vrf_id, struct route_entry *re, XFREE(MTYPE_RE, re); } -static void copy_state(struct rnh *rnh, struct route_entry *re, +static void copy_state(struct rnh *rnh, const struct route_entry *re, struct route_node *rn) { struct route_entry *state; @@ -966,9 +967,8 @@ static void copy_state(struct rnh *rnh, struct route_entry *re, state->status = re->status; state->nhe = zebra_nhg_alloc(); - state->nhe->nhg = nexthop_group_new(); - nexthop_group_copy(state->nhe->nhg, re->nhe->nhg); + nexthop_group_copy(&(state->nhe->nhg), &(re->nhe->nhg)); rnh->state = state; } @@ -986,12 +986,12 @@ static int compare_state(struct route_entry *r1, struct route_entry *r2) if (r1->metric != r2->metric) return 1; - if (nexthop_group_nexthop_num(r1->nhe->nhg) - != nexthop_group_nexthop_num(r2->nhe->nhg)) + if (nexthop_group_nexthop_num(&(r1->nhe->nhg)) + != nexthop_group_nexthop_num(&(r2->nhe->nhg))) return 1; - if (nexthop_group_hash(r1->nhe->nhg) != - nexthop_group_hash(r2->nhe->nhg)) + if (nexthop_group_hash(&(r1->nhe->nhg)) != + nexthop_group_hash(&(r2->nhe->nhg))) return 1; return 0; @@ -1043,7 +1043,7 @@ static int send_client(struct rnh *rnh, struct zserv *client, rnh_type_t type, num = 0; nump = stream_get_endp(s); stream_putc(s, 0); - for (ALL_NEXTHOPS_PTR(re->nhe->nhg, nh)) + for (ALL_NEXTHOPS(re->nhe->nhg, nh)) if (rnh_nexthop_valid(re, nh)) { zapi_nexthop_from_nexthop(&znh, nh); zapi_nexthop_encode(s, &znh, 0 /* flags */); @@ -1114,7 +1114,7 @@ static void print_rnh(struct route_node *rn, struct vty *vty) if (rnh->state) { vty_out(vty, " resolved via %s\n", zebra_route_string(rnh->state->type)); - for (nexthop = rnh->state->nhe->nhg->nexthop; nexthop; + for (nexthop = rnh->state->nhe->nhg.nexthop; nexthop; nexthop = nexthop->next) print_nh(nexthop, vty); } else diff --git a/zebra/zebra_snmp.c b/zebra/zebra_snmp.c index 70bb6a14ca..5de45c0294 100644 --- a/zebra/zebra_snmp.c +++ b/zebra/zebra_snmp.c @@ -285,8 +285,8 @@ static void check_replace(struct route_node *np2, struct route_entry *re2, return; } - if (in_addr_cmp((uint8_t *)&(*re)->nhe->nhg->nexthop->gate.ipv4, - (uint8_t *)&re2->nhe->nhg->nexthop->gate.ipv4) + if (in_addr_cmp((uint8_t *)&(*re)->nhe->nhg.nexthop->gate.ipv4, + (uint8_t *)&re2->nhe->nhg.nexthop->gate.ipv4) <= 0) return; @@ -372,7 +372,7 @@ static void get_fwtable_route_node(struct variable *v, oid objid[], (uint8_t *)&dest)) { RNODE_FOREACH_RE (*np, *re) { if (!in_addr_cmp((uint8_t *)&(*re)->nhe - ->nhg->nexthop + ->nhg.nexthop ->gate.ipv4, (uint8_t *)&nexthop)) if (proto @@ -407,7 +407,7 @@ static void get_fwtable_route_node(struct variable *v, oid objid[], || ((policy == policy2) && (proto == proto2) && (in_addr_cmp( (uint8_t *)&re2->nhe - ->nhg->nexthop->gate.ipv4, + ->nhg.nexthop->gate.ipv4, (uint8_t *)&nexthop) >= 0))) check_replace(np2, re2, np, re); @@ -432,7 +432,7 @@ static void get_fwtable_route_node(struct variable *v, oid objid[], { struct nexthop *nexthop; - nexthop = (*re)->nhe->nhg->nexthop; + nexthop = (*re)->nhe->nhg.nexthop; if (nexthop) { pnt = (uint8_t *)&nexthop->gate.ipv4; for (i = 0; i < 4; i++) @@ -462,7 +462,7 @@ static uint8_t *ipFwTable(struct variable *v, oid objid[], size_t *objid_len, if (!np) return NULL; - nexthop = re->nhe->nhg->nexthop; + nexthop = re->nhe->nhg.nexthop; if (!nexthop) return NULL; diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 86ec2ffef3..ccc6e9e46b 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -62,7 +62,7 @@ static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi, route_tag_t tag, const struct prefix *longer_prefix_p, bool supernets_only, int type, - unsigned short ospf_instance_id); + unsigned short ospf_instance_id, uint32_t tableid); static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, int mcast, bool use_fib, bool show_ng); static void vty_show_ip_route_summary(struct vty *vty, @@ -131,7 +131,7 @@ DEFUN (show_ip_rpf, { bool uj = use_json(argc, argv); return do_show_ip_route(vty, VRF_DEFAULT_NAME, AFI_IP, SAFI_MULTICAST, - false, uj, 0, NULL, false, 0, 0); + false, uj, 0, NULL, false, 0, 0, 0); } DEFUN (show_ip_rpf_addr, @@ -241,30 +241,18 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, vty_out(vty, "\n"); time_t uptime; - struct tm *tm; uptime = monotime(NULL); uptime -= re->uptime; - tm = gmtime(&uptime); - vty_out(vty, " Last update "); + frrtime_to_interval(uptime, buf, sizeof(buf)); - if (uptime < ONE_DAY_SECOND) - vty_out(vty, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, - tm->tm_sec); - else if (uptime < ONE_WEEK_SECOND) - vty_out(vty, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour, - tm->tm_min); - else - vty_out(vty, "%02dw%dd%02dh", tm->tm_yday / 7, - tm->tm_yday - ((tm->tm_yday / 7) * 7), - tm->tm_hour); - vty_out(vty, " ago\n"); + vty_out(vty, " Last update %s ago\n", buf); if (show_ng) vty_out(vty, " Nexthop Group ID: %u\n", re->nhe_id); - for (ALL_NEXTHOPS_PTR(re->nhe->nhg, nexthop)) { + for (ALL_NEXTHOPS(re->nhe->nhg, nexthop)) { char addrstr[32]; vty_out(vty, " %c%s", @@ -286,7 +274,7 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, case NEXTHOP_TYPE_IPV6_IFINDEX: vty_out(vty, " %s", inet_ntop(AF_INET6, &nexthop->gate.ipv6, - buf, sizeof buf)); + buf, sizeof(buf))); if (nexthop->ifindex) vty_out(vty, ", via %s", ifindex2ifname( @@ -348,7 +336,7 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, if (nexthop->src.ipv4.s_addr) { if (inet_ntop(AF_INET, &nexthop->src.ipv4, - addrstr, sizeof addrstr)) + addrstr, sizeof(addrstr))) vty_out(vty, ", src %s", addrstr); } @@ -359,7 +347,7 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, &in6addr_any)) { if (inet_ntop(AF_INET6, &nexthop->src.ipv6, - addrstr, sizeof addrstr)) + addrstr, sizeof(addrstr))) vty_out(vty, ", src %s", addrstr); } @@ -378,7 +366,7 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, mpls_label2str( nexthop->nh_label->num_labels, nexthop->nh_label->label, buf, - sizeof buf, 1)); + sizeof(buf), 1)); } if (nexthop->weight) @@ -402,14 +390,15 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, json_object *json_route = NULL; json_object *json_labels = NULL; time_t uptime; - struct tm *tm; struct vrf *vrf = NULL; rib_dest_t *dest = rib_dest_from_rnode(rn); struct nexthop_group *nhg; + char up_str[MONOTIME_STRLEN]; uptime = monotime(NULL); uptime -= re->uptime; - tm = gmtime(&uptime); + + frrtime_to_interval(uptime, up_str, sizeof(up_str)); /* If showing fib information, use the fib view of the * nexthops. @@ -417,14 +406,14 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, if (is_fib) nhg = rib_active_nhg(re); else - nhg = re->nhe->nhg; + nhg = &(re->nhe->nhg); if (json) { json_route = json_object_new_object(); json_nexthops = json_object_new_array(); json_object_string_add(json_route, "prefix", - srcdest_rnode2str(rn, buf, sizeof buf)); + srcdest_rnode2str(rn, buf, sizeof(buf))); json_object_string_add(json_route, "protocol", zebra_route_string(re->type)); @@ -470,22 +459,12 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, json_object_int_add(json_route, "internalFlags", re->flags); json_object_int_add(json_route, "internalNextHopNum", - nexthop_group_nexthop_num(re->nhe->nhg)); + nexthop_group_nexthop_num(&(re->nhe->nhg))); json_object_int_add(json_route, "internalNextHopActiveNum", nexthop_group_active_nexthop_num( - re->nhe->nhg)); - if (uptime < ONE_DAY_SECOND) - sprintf(buf, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, - tm->tm_sec); - else if (uptime < ONE_WEEK_SECOND) - sprintf(buf, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour, - tm->tm_min); - else - sprintf(buf, "%02dw%dd%02dh", tm->tm_yday / 7, - tm->tm_yday - ((tm->tm_yday / 7) * 7), - tm->tm_hour); + &(re->nhe->nhg))); - json_object_string_add(json_route, "uptime", buf); + json_object_string_add(json_route, "uptime", up_str); for (ALL_NEXTHOPS_PTR(nhg, nexthop)) { json_nexthop = json_object_new_object(); @@ -526,7 +505,7 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, json_object_string_add( json_nexthop, "ip", inet_ntop(AF_INET6, &nexthop->gate.ipv6, - buf, sizeof buf)); + buf, sizeof(buf))); json_object_string_add(json_nexthop, "afi", "ipv6"); @@ -606,7 +585,7 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, if (nexthop->src.ipv4.s_addr) { if (inet_ntop(AF_INET, &nexthop->src.ipv4, buf, - sizeof buf)) + sizeof(buf))) json_object_string_add( json_nexthop, "source", buf); @@ -618,7 +597,7 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, &in6addr_any)) { if (inet_ntop(AF_INET6, &nexthop->src.ipv6, buf, - sizeof buf)) + sizeof(buf))) json_object_string_add( json_nexthop, "source", buf); @@ -667,7 +646,7 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, ? '>' : ' ', re_status_output_char(re, nexthop), - srcdest_rnode2str(rn, buf, sizeof buf)); + srcdest_rnode2str(rn, buf, sizeof(buf))); /* Distance and metric display. */ if (((re->type == ZEBRA_ROUTE_CONNECT) && @@ -694,7 +673,7 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, case NEXTHOP_TYPE_IPV6_IFINDEX: vty_out(vty, " via %s", inet_ntop(AF_INET6, &nexthop->gate.ipv6, buf, - sizeof buf)); + sizeof(buf))); if (nexthop->ifindex) vty_out(vty, ", %s", ifindex2ifname(nexthop->ifindex, @@ -750,7 +729,7 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, case NEXTHOP_TYPE_IPV4_IFINDEX: if (nexthop->src.ipv4.s_addr) { if (inet_ntop(AF_INET, &nexthop->src.ipv4, buf, - sizeof buf)) + sizeof(buf))) vty_out(vty, ", src %s", buf); } break; @@ -758,7 +737,7 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, case NEXTHOP_TYPE_IPV6_IFINDEX: if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any)) { if (inet_ntop(AF_INET6, &nexthop->src.ipv6, buf, - sizeof buf)) + sizeof(buf))) vty_out(vty, ", src %s", buf); } break; @@ -771,20 +750,10 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, vty_out(vty, ", label %s", mpls_label2str(nexthop->nh_label->num_labels, nexthop->nh_label->label, buf, - sizeof buf, 1)); + sizeof(buf), 1)); } - if (uptime < ONE_DAY_SECOND) - vty_out(vty, ", %02d:%02d:%02d", tm->tm_hour, - tm->tm_min, tm->tm_sec); - else if (uptime < ONE_WEEK_SECOND) - vty_out(vty, ", %dd%02dh%02dm", tm->tm_yday, - tm->tm_hour, tm->tm_min); - else - vty_out(vty, ", %02dw%dd%02dh", tm->tm_yday / 7, - tm->tm_yday - ((tm->tm_yday / 7) * 7), - tm->tm_hour); - vty_out(vty, "\n"); + vty_out(vty, ", %s\n", up_str); } } @@ -915,12 +884,40 @@ static void do_show_route_helper(struct vty *vty, struct zebra_vrf *zvrf, } } +static void do_show_ip_route_all(struct vty *vty, struct zebra_vrf *zvrf, + afi_t afi, bool use_fib, bool use_json, + route_tag_t tag, + const struct prefix *longer_prefix_p, + bool supernets_only, int type, + unsigned short ospf_instance_id) +{ + struct zebra_router_table *zrt; + rib_table_info_t *info; + + RB_FOREACH (zrt, zebra_router_table_head, + &zrouter.tables) { + info = route_table_get_info(zrt->table); + + if (zvrf != info->zvrf) + continue; + if (zrt->afi != afi || + zrt->safi != SAFI_UNICAST) + continue; + + do_show_ip_route(vty, zvrf_name(zvrf), afi, + SAFI_UNICAST, use_fib, use_json, + tag, longer_prefix_p, + supernets_only, type, + ospf_instance_id, zrt->tableid); + } +} + static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi, safi_t safi, bool use_fib, bool use_json, route_tag_t tag, const struct prefix *longer_prefix_p, bool supernets_only, int type, - unsigned short ospf_instance_id) + unsigned short ospf_instance_id, uint32_t tableid) { struct route_table *table; struct zebra_vrf *zvrf = NULL; @@ -941,7 +938,10 @@ static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi, return CMD_SUCCESS; } - table = zebra_vrf_table(afi, safi, zvrf_id(zvrf)); + if (tableid) + table = zebra_router_find_table(zvrf, tableid, afi, SAFI_UNICAST); + else + table = zebra_vrf_table(afi, safi, zvrf_id(zvrf)); if (!table) { if (use_json) vty_out(vty, "{}\n"); @@ -950,98 +950,11 @@ static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi, do_show_route_helper(vty, zvrf, table, afi, use_fib, tag, longer_prefix_p, supernets_only, type, - ospf_instance_id, use_json, 0); - - return CMD_SUCCESS; -} - -DEFPY (show_route_table, - show_route_table_cmd, - "show <ip$ipv4|ipv6$ipv6> route table (1-4294967295)$table [json$json]", - SHOW_STR - IP_STR - IP6_STR - "IP routing table\n" - "Table to display\n" - "The table number to display, if available\n" - JSON_STR) -{ - afi_t afi = ipv4 ? AFI_IP : AFI_IP6; - struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); - struct route_table *t; - - t = zebra_router_find_table(zvrf, table, afi, SAFI_UNICAST); - if (t) - do_show_route_helper(vty, zvrf, t, afi, false, 0, false, false, - 0, 0, !!json, table); - - return CMD_SUCCESS; -} - -DEFPY (show_route_table_vrf, - show_route_table_vrf_cmd, - "show <ip$ipv4|ipv6$ipv6> route table (1-4294967295)$table vrf NAME$vrf_name [json$json]", - SHOW_STR - IP_STR - IP6_STR - "IP routing table\n" - "Table to display\n" - "The table number to display, if available\n" - VRF_CMD_HELP_STR - JSON_STR) -{ - afi_t afi = ipv4 ? AFI_IP : AFI_IP6; - struct zebra_vrf *zvrf; - struct route_table *t; - vrf_id_t vrf_id = VRF_DEFAULT; - - if (vrf_name) - VRF_GET_ID(vrf_id, vrf_name, !!json); - zvrf = zebra_vrf_lookup_by_id(vrf_id); - - t = zebra_router_find_table(zvrf, table, afi, SAFI_UNICAST); - if (t) - do_show_route_helper(vty, zvrf, t, afi, false, 0, false, false, - 0, 0, !!json, table); + ospf_instance_id, use_json, tableid); return CMD_SUCCESS; } -DEFPY (show_route_all_table_vrf, - show_route_all_table_vrf_cmd, - "show <ip$ipv4|ipv6$ipv6> route [vrf <NAME$vrf_name|all$vrf_all>] tables [json$json]", - SHOW_STR - IP_STR - IP6_STR - "IP routing table\n" - "Display all tables\n" - VRF_FULL_CMD_HELP_STR - JSON_STR) -{ - afi_t afi = ipv4 ? AFI_IP : AFI_IP6; - struct zebra_vrf *zvrf = NULL; - vrf_id_t vrf_id = VRF_UNKNOWN; - struct zebra_router_table *zrt; - - if (vrf_name) { - VRF_GET_ID(vrf_id, vrf_name, !!json); - zvrf = zebra_vrf_lookup_by_id(vrf_id); - } - - RB_FOREACH (zrt, zebra_router_table_head, &zrouter.tables) { - rib_table_info_t *info = route_table_get_info(zrt->table); - - if (zvrf && zvrf != info->zvrf) - continue; - if (zrt->afi != afi || zrt->safi != SAFI_UNICAST) - continue; - - do_show_route_helper(vty, info->zvrf, zrt->table, afi, false, 0, - false, false, 0, 0, !!json, zrt->tableid); - } - return CMD_SUCCESS; -} - DEFPY (show_ip_nht, show_ip_nht_cmd, "show <ip$ipv4|ipv6$ipv6> <nht|import-check>$type [<A.B.C.D|X:X::X:X>$addr|vrf NAME$vrf_name [<A.B.C.D|X:X::X:X>$addr]|vrf all$vrf_all]", @@ -1149,7 +1062,7 @@ static void show_nexthop_group_out(struct vty *vty, struct nhg_hash_entry *nhe) vty_out(vty, "\n"); } - for (ALL_NEXTHOPS_PTR(nhe->nhg, nexthop)) { + for (ALL_NEXTHOPS(nhe->nhg, nexthop)) { if (!CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE)) vty_out(vty, " "); else @@ -1512,7 +1425,8 @@ DEFPY (show_route, show_route_cmd, "show\ <\ - ip$ipv4 <fib$fib|route> [vrf <NAME$vrf_name|all$vrf_all>]\ + ip$ipv4 <fib$fib|route> [table <(1-4294967295)$table|all$table_all>]\ + [vrf <NAME$vrf_name|all$vrf_all>]\ [{\ tag (1-4294967295)\ |A.B.C.D/M$prefix longer-prefixes\ @@ -1522,7 +1436,8 @@ DEFPY (show_route, " FRR_IP_REDIST_STR_ZEBRA "$type_str\ |ospf$type_str (1-65535)$ospf_instance_id\ >]\ - |ipv6$ipv6 <fib$fib|route> [vrf <NAME$vrf_name|all$vrf_all>]\ + |ipv6$ipv6 <fib$fib|route> [table <(1-4294967295)$table|all$table_all>]\ + [vrf <NAME$vrf_name|all$vrf_all>]\ [{\ tag (1-4294967295)\ |X:X::X:X/M$prefix longer-prefixes\ @@ -1534,6 +1449,9 @@ DEFPY (show_route, IP_STR "IP forwarding table\n" "IP routing table\n" + "Table to display\n" + "The table number to display\n" + "All tables\n" VRF_FULL_CMD_HELP_STR "Show only routes with tag\n" "Tag value\n" @@ -1546,6 +1464,9 @@ DEFPY (show_route, IPV6_STR "IP forwarding table\n" "IP routing table\n" + "Table to display\n" + "The table number to display\n" + "All tables\n" VRF_FULL_CMD_HELP_STR "Show only routes with tag\n" "Tag value\n" @@ -1557,7 +1478,19 @@ DEFPY (show_route, afi_t afi = ipv4 ? AFI_IP : AFI_IP6; struct vrf *vrf; int type = 0; + struct zebra_vrf *zvrf; + if (!vrf_is_backend_netns()) { + if ((vrf_all || vrf_name) && (table || table_all)) { + if (!!json) + vty_out(vty, "{}\n"); + else { + vty_out(vty, "Linux vrf backend already points to table id\n"); + vty_out(vty, "Either remove table parameter or vrf parameter\n"); + } + return CMD_SUCCESS; + } + } if (type_str) { type = proto_redistnum(afi, type_str); if (type < 0) { @@ -1568,17 +1501,22 @@ DEFPY (show_route, if (vrf_all) { RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - struct zebra_vrf *zvrf; - struct route_table *table; - if ((zvrf = vrf->info) == NULL - || (table = zvrf->table[afi][SAFI_UNICAST]) == NULL) + || (zvrf->table[afi][SAFI_UNICAST] == NULL)) continue; - do_show_ip_route( - vty, zvrf_name(zvrf), afi, SAFI_UNICAST, !!fib, - !!json, tag, prefix_str ? prefix : NULL, - !!supernets_only, type, ospf_instance_id); + if (table_all) + do_show_ip_route_all(vty, zvrf, afi, + !!fib, !!json, + tag, prefix_str ? prefix : NULL, + !!supernets_only, type, + ospf_instance_id); + else + do_show_ip_route(vty, zvrf_name(zvrf), afi, + SAFI_UNICAST, !!fib, !!json, tag, + prefix_str ? prefix : NULL, + !!supernets_only, type, + ospf_instance_id, table); } } else { vrf_id_t vrf_id = VRF_DEFAULT; @@ -1586,9 +1524,21 @@ DEFPY (show_route, if (vrf_name) VRF_GET_ID(vrf_id, vrf_name, !!json); vrf = vrf_lookup_by_id(vrf_id); - do_show_ip_route(vty, vrf->name, afi, SAFI_UNICAST, !!fib, - !!json, tag, prefix_str ? prefix : NULL, - !!supernets_only, type, ospf_instance_id); + if (vrf) + zvrf = vrf->info; + if (!vrf || !zvrf) + return CMD_SUCCESS; + + if (table_all) + do_show_ip_route_all(vty, zvrf, afi, + !!fib, !!json, + tag, prefix_str ? prefix : NULL, + !!supernets_only, type, + ospf_instance_id); + else + do_show_ip_route(vty, vrf->name, afi, SAFI_UNICAST, !!fib, + !!json, tag, prefix_str ? prefix : NULL, + !!supernets_only, type, ospf_instance_id, table); } return CMD_SUCCESS; @@ -1970,7 +1920,7 @@ static void vty_show_ip_route_summary_prefix(struct vty *vty, fib_cnt[ZEBRA_ROUTE_TOTAL]++; fib_cnt[re->type]++; } - for (nexthop = re->nhe->nhg->nexthop; (!cnt && nexthop); + for (nexthop = re->nhe->nhg.nexthop; (!cnt && nexthop); nexthop = nexthop->next) { cnt++; rib_cnt[ZEBRA_ROUTE_TOTAL]++; @@ -3539,10 +3489,6 @@ void zebra_vty_init(void) install_element(VIEW_NODE, &show_vrf_cmd); install_element(VIEW_NODE, &show_vrf_vni_cmd); install_element(VIEW_NODE, &show_route_cmd); - install_element(VIEW_NODE, &show_route_table_cmd); - if (vrf_is_backend_netns()) - install_element(VIEW_NODE, &show_route_table_vrf_cmd); - install_element(VIEW_NODE, &show_route_all_table_vrf_cmd); install_element(VIEW_NODE, &show_route_detail_cmd); install_element(VIEW_NODE, &show_route_summary_cmd); install_element(VIEW_NODE, &show_ip_nht_cmd); diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c index 4b56581ca9..61865e5baf 100644 --- a/zebra/zebra_vxlan.c +++ b/zebra/zebra_vxlan.c @@ -101,8 +101,6 @@ static void *zvni_neigh_alloc(void *p); static zebra_neigh_t *zvni_neigh_add(zebra_vni_t *zvni, struct ipaddr *ip, struct ethaddr *mac); static int zvni_neigh_del(zebra_vni_t *zvni, zebra_neigh_t *n); -static void zvni_neigh_del_from_vtep(zebra_vni_t *zvni, int uninstall, - struct in_addr *r_vtep_ip); static void zvni_neigh_del_all(zebra_vni_t *zvni, int uninstall, int upd_client, uint32_t flags); static zebra_neigh_t *zvni_neigh_lookup(zebra_vni_t *zvni, struct ipaddr *ip); @@ -156,8 +154,6 @@ static bool mac_cmp(const void *p1, const void *p2); static void *zvni_mac_alloc(void *p); static zebra_mac_t *zvni_mac_add(zebra_vni_t *zvni, struct ethaddr *macaddr); static int zvni_mac_del(zebra_vni_t *zvni, zebra_mac_t *mac); -static void zvni_mac_del_from_vtep(zebra_vni_t *zvni, int uninstall, - struct in_addr *r_vtep_ip); static void zvni_mac_del_all(zebra_vni_t *zvni, int uninstall, int upd_client, uint32_t flags); static zebra_mac_t *zvni_mac_lookup(zebra_vni_t *zvni, struct ethaddr *macaddr); @@ -225,7 +221,7 @@ static void zebra_vxlan_sg_deref(struct in_addr local_vtep_ip, struct in_addr mcast_grp); static void zebra_vxlan_sg_ref(struct in_addr local_vtep_ip, struct in_addr mcast_grp); -static void zebra_vxlan_sg_cleanup(struct hash_backet *backet, void *arg); +static void zebra_vxlan_sg_cleanup(struct hash_bucket *bucket, void *arg); static void zvni_send_mac_to_client(zebra_vni_t *zvn); static void zvni_send_neigh_to_client(zebra_vni_t *zvni); @@ -258,8 +254,8 @@ static int host_rb_entry_compare(const struct host_rb_entry *hle1, return memcmp(&hle1->p.u.prefix6, &hle2->p.u.prefix6, IPV6_MAX_BYTELEN); } else { - zlog_debug("%s: Unexpected family type: %d", - __PRETTY_FUNCTION__, hle1->p.family); + zlog_debug("%s: Unexpected family type: %d", __func__, + hle1->p.family); return 0; } } @@ -447,12 +443,11 @@ static void zebra_vxlan_dup_addr_detect_for_mac(struct zebra_vrf *zvrf, if (CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE)) { if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "%s: duplicate addr MAC %s flags 0x%x skip update to client, learn count %u recover time %u", - __PRETTY_FUNCTION__, - prefix_mac2str(&mac->macaddr, buf, - sizeof(buf)), - mac->flags, mac->dad_count, - zvrf->dad_freeze_time); + "%s: duplicate addr MAC %s flags 0x%x skip update to client, learn count %u recover time %u", + __func__, + prefix_mac2str(&mac->macaddr, buf, sizeof(buf)), + mac->flags, mac->dad_count, + zvrf->dad_freeze_time); /* For duplicate MAC do not update * client but update neigh due to @@ -483,11 +478,10 @@ static void zebra_vxlan_dup_addr_detect_for_mac(struct zebra_vrf *zvrf, if (reset_params) { if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "%s: duplicate addr MAC %s flags 0x%x detection time passed, reset learn count %u" - , __PRETTY_FUNCTION__, - prefix_mac2str(&mac->macaddr, buf, - sizeof(buf)), - mac->flags, mac->dad_count); + "%s: duplicate addr MAC %s flags 0x%x detection time passed, reset learn count %u", + __func__, + prefix_mac2str(&mac->macaddr, buf, sizeof(buf)), + mac->flags, mac->dad_count); mac->dad_count = 0; /* Start dup. addr detection (DAD) start time, @@ -551,8 +545,8 @@ static void zebra_vxlan_dup_addr_detect_for_mac(struct zebra_vrf *zvrf, if (zvrf->dad_freeze && zvrf->dad_freeze_time) { if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "%s: duplicate addr MAC %s flags 0x%x auto recovery time %u start" - , __PRETTY_FUNCTION__, + "%s: duplicate addr MAC %s flags 0x%x auto recovery time %u start", + __func__, prefix_mac2str(&mac->macaddr, buf, sizeof(buf)), mac->flags, zvrf->dad_freeze_time); @@ -594,8 +588,8 @@ static void zebra_vxlan_dup_addr_detect_for_neigh(struct zebra_vrf *zvrf, if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE)) { if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "%s: duplicate addr MAC %s IP %s flags 0x%x skip installing, learn count %u recover time %u", - __PRETTY_FUNCTION__, + "%s: duplicate addr MAC %s IP %s flags 0x%x skip installing, learn count %u recover time %u", + __func__, prefix_mac2str(&nbr->emac, buf, sizeof(buf)), ipaddr2str(&nbr->ip, buf1, sizeof(buf1)), nbr->flags, nbr->dad_count, @@ -635,7 +629,7 @@ static void zebra_vxlan_dup_addr_detect_for_neigh(struct zebra_vrf *zvrf, if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( "%s: duplicate addr MAC %s IP %s flags 0x%x detection time passed, reset learn count %u", - __PRETTY_FUNCTION__, + __func__, prefix_mac2str(&nbr->emac, buf, sizeof(buf)), ipaddr2str(&nbr->ip, buf1, sizeof(buf1)), nbr->flags, nbr->dad_count); @@ -685,10 +679,12 @@ static void zebra_vxlan_dup_addr_detect_for_neigh(struct zebra_vrf *zvrf, if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( "%s: duplicate addr MAC %s IP %s flags 0x%x auto recovery time %u start", - __PRETTY_FUNCTION__, - prefix_mac2str(&nbr->emac, buf, sizeof(buf)), - ipaddr2str(&nbr->ip, buf1, sizeof(buf1)), - nbr->flags, zvrf->dad_freeze_time); + __func__, + prefix_mac2str(&nbr->emac, buf, + sizeof(buf)), + ipaddr2str(&nbr->ip, buf1, + sizeof(buf1)), + nbr->flags, zvrf->dad_freeze_time); thread_add_timer(zrouter.master, zebra_vxlan_dad_ip_auto_recovery_exp, @@ -2302,26 +2298,6 @@ static void zvni_neigh_del_hash_entry(struct hash_bucket *bucket, void *arg) } /* - * Delete all neighbor entries from specific VTEP for a particular VNI. - */ -static void zvni_neigh_del_from_vtep(zebra_vni_t *zvni, int uninstall, - struct in_addr *r_vtep_ip) -{ - struct neigh_walk_ctx wctx; - - if (!zvni->neigh_table) - return; - - memset(&wctx, 0, sizeof(struct neigh_walk_ctx)); - wctx.zvni = zvni; - wctx.uninstall = uninstall; - wctx.flags = DEL_REMOTE_NEIGH_FROM_VTEP; - wctx.r_vtep_ip = *r_vtep_ip; - - hash_iterate(zvni->neigh_table, zvni_neigh_del_hash_entry, &wctx); -} - -/* * Delete all neighbor entries for this VNI. */ static void zvni_neigh_del_all(zebra_vni_t *zvni, int uninstall, int upd_client, @@ -3450,11 +3426,10 @@ static bool zvni_check_mac_del_from_db(struct mac_walk_ctx *wctx, if (IS_ZEBRA_DEBUG_VXLAN) { char buf[ETHER_ADDR_STRLEN]; - zlog_debug("%s: Del MAC %s flags 0x%x", - __PRETTY_FUNCTION__, - prefix_mac2str(&mac->macaddr, - buf, sizeof(buf)), - mac->flags); + zlog_debug( + "%s: Del MAC %s flags 0x%x", __func__, + prefix_mac2str(&mac->macaddr, buf, sizeof(buf)), + mac->flags); } wctx->uninstall = 0; @@ -3487,26 +3462,6 @@ static void zvni_mac_del_hash_entry(struct hash_bucket *bucket, void *arg) } /* - * Delete all MAC entries from specific VTEP for a particular VNI. - */ -static void zvni_mac_del_from_vtep(zebra_vni_t *zvni, int uninstall, - struct in_addr *r_vtep_ip) -{ - struct mac_walk_ctx wctx; - - if (!zvni->mac_table) - return; - - memset(&wctx, 0, sizeof(struct mac_walk_ctx)); - wctx.zvni = zvni; - wctx.uninstall = uninstall; - wctx.flags = DEL_REMOTE_MAC_FROM_VTEP; - wctx.r_vtep_ip = *r_vtep_ip; - - hash_iterate(zvni->mac_table, zvni_mac_del_hash_entry, &wctx); -} - -/* * Delete all MAC entries for this VNI. */ static void zvni_mac_del_all(zebra_vni_t *zvni, int uninstall, int upd_client, @@ -5875,14 +5830,11 @@ static void process_remote_macip_del(vni_t vni, zns = zebra_ns_lookup(NS_DEFAULT); vxl = &zif->l2info.vxl; - /* The remote VTEP specified is normally expected to exist, but - * it is possible that the peer may delete the VTEP before deleting - * any MACs referring to the VTEP, in which case the handler (see - * remote_vtep_del) would have already deleted the MACs. + /* It is possible remote vtep del request is processed prior to + * remote macip route delete. remote_vtep_del does not clean up + * the macip route delete. Explicite withdraw of the macip route + * is expected to recieve. This handler removes the remote route. */ - if (!zvni_vtep_find(zvni, &vtep_ip)) - return; - mac = zvni_mac_lookup(zvni, macaddr); if (ipa_len) n = zvni_neigh_lookup(zvni, ipaddr); @@ -5928,7 +5880,7 @@ static void process_remote_macip_del(vni_t vni, if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( "%s: IP %s (flags 0x%x intf %s) is remote and duplicate, read kernel for local entry", - __PRETTY_FUNCTION__, + __func__, ipaddr2str(ipaddr, buf1, sizeof(buf1)), n->flags, vlan_if ? vlan_if->name : "Unknown"); @@ -5958,11 +5910,12 @@ static void process_remote_macip_del(vni_t vni, CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE) && CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) { if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("%s: MAC %s (flags 0x%x) is remote and duplicate, read kernel for local entry", - __PRETTY_FUNCTION__, - prefix_mac2str(macaddr, buf, - sizeof(buf)), - mac->flags); + zlog_debug( + "%s: MAC %s (flags 0x%x) is remote and duplicate, read kernel for local entry", + __func__, + prefix_mac2str(macaddr, buf, + sizeof(buf)), + mac->flags); macfdb_read_specific_mac(zns, zif->brslave_info.br_if, macaddr, vxl->access_vlan); } @@ -7028,8 +6981,7 @@ int zebra_vxlan_clear_dup_detect_vni_ip(struct vty *vty, if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug("%s: clear neigh %s in dup state, flags 0x%x seq %u", - __PRETTY_FUNCTION__, buf, nbr->flags, - nbr->loc_seq); + __func__, buf, nbr->flags, nbr->loc_seq); UNSET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE); nbr->dad_count = 0; @@ -7122,10 +7074,8 @@ static void zvni_clear_dup_neigh_hash(struct hash_bucket *bucket, void *ctxt) if (IS_ZEBRA_DEBUG_VXLAN) { ipaddr2str(&nbr->ip, buf, sizeof(buf)); - zlog_debug( - "%s: clear neigh %s dup state, flags 0x%x seq %u", - __PRETTY_FUNCTION__, buf, - nbr->flags, nbr->loc_seq); + zlog_debug("%s: clear neigh %s dup state, flags 0x%x seq %u", + __func__, buf, nbr->flags, nbr->loc_seq); } UNSET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE); @@ -7560,9 +7510,10 @@ int zebra_vxlan_handle_kernel_neigh_del(struct interface *ifp, zvni = zvni_from_svi(ifp, link_if); if (!zvni) { if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("%s: Del neighbor %s VNI is not present for interface %s", - __PRETTY_FUNCTION__, - ipaddr2str(ip, buf, sizeof(buf)), ifp->name); + zlog_debug( + "%s: Del neighbor %s VNI is not present for interface %s", + __func__, ipaddr2str(ip, buf, sizeof(buf)), + ifp->name); return 0; } @@ -7605,8 +7556,8 @@ int zebra_vxlan_handle_kernel_neigh_del(struct interface *ifp, zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id); if (!zvrf) { - zlog_debug("%s: VNI %u vrf lookup failed.", - __PRETTY_FUNCTION__, zvni->vni); + zlog_debug("%s: VNI %u vrf lookup failed.", __func__, + zvni->vni); return -1; } @@ -7837,6 +7788,52 @@ stream_failure: } /* + * Handle remote vtep delete by kernel; re-add the vtep if we have it + */ +int zebra_vxlan_check_readd_vtep(struct interface *ifp, + struct in_addr vtep_ip) +{ + struct zebra_if *zif; + struct zebra_vrf *zvrf = NULL; + struct zebra_l2info_vxlan *vxl; + vni_t vni; + zebra_vni_t *zvni = NULL; + zebra_vtep_t *zvtep = NULL; + + zif = ifp->info; + assert(zif); + vxl = &zif->l2info.vxl; + vni = vxl->vni; + + /* If EVPN is not enabled, nothing to do. */ + if (!is_evpn_enabled()) + return 0; + + /* Locate VRF corresponding to interface. */ + zvrf = vrf_info_lookup(ifp->vrf_id); + if (!zvrf) + return -1; + + /* Locate hash entry; it is expected to exist. */ + zvni = zvni_lookup(vni); + if (!zvni) + return 0; + + /* If the remote vtep entry doesn't exists nothing to do */ + zvtep = zvni_vtep_find(zvni, &vtep_ip); + if (!zvtep) + return 0; + + if (IS_ZEBRA_DEBUG_VXLAN) + zlog_debug( + "Del MAC for remote VTEP %s intf %s(%u) VNI %u - readd", + inet_ntoa(vtep_ip), ifp->name, ifp->ifindex, vni); + + zvni_vtep_install(zvni, zvtep); + return 0; +} + +/* * Handle notification of MAC add/update over VxLAN. If the kernel is notifying * us, this must involve a multihoming scenario. Treat this as implicit delete * of any prior local MAC. @@ -8220,7 +8217,7 @@ void zebra_vxlan_remote_vtep_del(ZAPI_HANDLER_ARGS) if (!is_evpn_enabled()) { zlog_debug( "%s: EVPN is not enabled yet we have received a vtep del command", - __PRETTY_FUNCTION__); + __func__); return; } @@ -8284,8 +8281,6 @@ void zebra_vxlan_remote_vtep_del(ZAPI_HANDLER_ARGS) if (!zvtep) continue; - zvni_neigh_del_from_vtep(zvni, 1, &vtep_ip); - zvni_mac_del_from_vtep(zvni, 1, &vtep_ip); zvni_vtep_uninstall(zvni, &vtep_ip); zvni_vtep_del(zvni, zvtep); } @@ -8312,7 +8307,7 @@ void zebra_vxlan_remote_vtep_add(ZAPI_HANDLER_ARGS) if (!is_evpn_enabled()) { zlog_debug( "%s: EVPN not enabled yet we received a vtep_add zapi call", - __PRETTY_FUNCTION__); + __func__); return; } @@ -9227,12 +9222,12 @@ int zebra_vxlan_process_vrf_vni_cmd(struct zebra_vrf *zvrf, vni_t vni, zl3vni->mac_vlan_if = zl3vni_map_to_mac_vlan_if(zl3vni); if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("%s: l3vni %u svi_if %s mac_vlan_if %s", - __PRETTY_FUNCTION__, vni, - zl3vni->svi_if ? - zl3vni->svi_if->name : "NIL", - zl3vni->mac_vlan_if ? - zl3vni->mac_vlan_if->name : "NIL"); + zlog_debug( + "%s: l3vni %u svi_if %s mac_vlan_if %s", + __func__, vni, + zl3vni->svi_if ? zl3vni->svi_if->name : "NIL", + zl3vni->mac_vlan_if ? zl3vni->mac_vlan_if->name + : "NIL"); /* formulate l2vni list */ hash_iterate(zvrf_evpn->vni_table, zvni_add_to_l3vni_list, @@ -9785,12 +9780,12 @@ static int zebra_vxlan_dad_ip_auto_recovery_exp(struct thread *t) return 0; if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("%s: duplicate addr MAC %s IP %s flags 0x%x learn count %u vni %u auto recovery expired", - __PRETTY_FUNCTION__, - prefix_mac2str(&nbr->emac, buf2, sizeof(buf2)), - ipaddr2str(&nbr->ip, buf1, sizeof(buf1)), - nbr->flags, - nbr->dad_count, zvni->vni); + zlog_debug( + "%s: duplicate addr MAC %s IP %s flags 0x%x learn count %u vni %u auto recovery expired", + __func__, + prefix_mac2str(&nbr->emac, buf2, sizeof(buf2)), + ipaddr2str(&nbr->ip, buf1, sizeof(buf1)), nbr->flags, + nbr->dad_count, zvni->vni); UNSET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE); nbr->dad_count = 0; @@ -9836,12 +9831,11 @@ static int zebra_vxlan_dad_mac_auto_recovery_exp(struct thread *t) return 0; if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("%s: duplicate addr mac %s flags 0x%x learn count %u host count %u auto recovery expired", - __PRETTY_FUNCTION__, - prefix_mac2str(&mac->macaddr, buf, sizeof(buf)), - mac->flags, - mac->dad_count, - listcount(mac->neigh_list)); + zlog_debug( + "%s: duplicate addr mac %s flags 0x%x learn count %u host count %u auto recovery expired", + __func__, + prefix_mac2str(&mac->macaddr, buf, sizeof(buf)), + mac->flags, mac->dad_count, listcount(mac->neigh_list)); /* Remove all IPs as duplicate associcated with this MAC */ for (ALL_LIST_ELEMENTS_RO(mac->neigh_list, node, nbr)) { @@ -10102,14 +10096,14 @@ static void zebra_vxlan_sg_ref(struct in_addr local_vtep_ip, zebra_vxlan_sg_do_ref(zvrf, local_vtep_ip, mcast_grp); } -static void zebra_vxlan_sg_cleanup(struct hash_backet *backet, void *arg) +static void zebra_vxlan_sg_cleanup(struct hash_bucket *backet, void *arg) { zebra_vxlan_sg_t *vxlan_sg = (zebra_vxlan_sg_t *)backet->data; zebra_vxlan_sg_del(vxlan_sg); } -static void zebra_vxlan_sg_replay_send(struct hash_backet *backet, void *arg) +static void zebra_vxlan_sg_replay_send(struct hash_bucket *backet, void *arg) { zebra_vxlan_sg_t *vxlan_sg = (zebra_vxlan_sg_t *)backet->data; diff --git a/zebra/zebra_vxlan.h b/zebra/zebra_vxlan.h index b551ba8dff..6ca93f6cb6 100644 --- a/zebra/zebra_vxlan.h +++ b/zebra/zebra_vxlan.h @@ -183,6 +183,8 @@ extern int zebra_vxlan_check_readd_remote_mac(struct interface *ifp, extern int zebra_vxlan_check_del_local_mac(struct interface *ifp, struct interface *br_if, struct ethaddr *mac, vlanid_t vid); +extern int zebra_vxlan_check_readd_vtep(struct interface *ifp, + struct in_addr vtep_ip); extern int zebra_vxlan_if_up(struct interface *ifp); extern int zebra_vxlan_if_down(struct interface *ifp); extern int zebra_vxlan_if_add(struct interface *ifp); diff --git a/zebra/zserv.c b/zebra/zserv.c index 2a5352a1da..7f806d82c3 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -568,7 +568,7 @@ static void zserv_client_free(struct zserv *client) close(client->sock); - if (!client->gr_instance_count) { + if (DYNAMIC_CLIENT_GR_DISABLED(client)) { nroutes = rib_score_proto(client->proto, client->instance); zlog_notice( @@ -610,7 +610,7 @@ static void zserv_client_free(struct zserv *client) * If any instance are graceful restart enabled, * client is not deleted */ - if (!client->gr_instance_count) { + if (DYNAMIC_CLIENT_GR_DISABLED(client)) { if (IS_ZEBRA_DEBUG_EVENT) zlog_debug("%s: Deleting client %s", __func__, zebra_route_string(client->proto)); @@ -858,7 +858,6 @@ void zserv_event(struct zserv *client, enum zserv_event event) #define ZEBRA_TIME_BUF 32 static char *zserv_time_buf(time_t *time1, char *buf, int buflen) { - struct tm *tm; time_t now; assert(buf != NULL); @@ -872,17 +871,9 @@ static char *zserv_time_buf(time_t *time1, char *buf, int buflen) now = monotime(NULL); now -= *time1; - tm = gmtime(&now); - - if (now < ONE_DAY_SECOND) - snprintf(buf, buflen, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, - tm->tm_sec); - else if (now < ONE_WEEK_SECOND) - snprintf(buf, buflen, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour, - tm->tm_min); - else - snprintf(buf, buflen, "%02dw%dd%02dh", tm->tm_yday / 7, - tm->tm_yday - ((tm->tm_yday / 7) * 7), tm->tm_hour); + + frrtime_to_interval(now, buf, buflen); + return buf; } @@ -1001,8 +992,6 @@ static void zebra_show_stale_client_detail(struct vty *vty, struct zserv *client) { char buf[PREFIX2STR_BUFFER]; - struct tm *tm; - struct timeval tv; time_t uptime; struct client_gr_info *info = NULL; struct zserv *s = NULL; @@ -1028,25 +1017,13 @@ static void zebra_show_stale_client_detail(struct vty *vty, if (ZEBRA_CLIENT_GR_ENABLED(info->capabilities)) { if (info->stale_client_ptr) { s = (struct zserv *)(info->stale_client_ptr); - uptime = monotime(&tv); + uptime = monotime(NULL); uptime -= s->restart_time; - tm = gmtime(&uptime); - vty_out(vty, "Last restart time : "); - if (uptime < ONE_DAY_SECOND) - vty_out(vty, "%02d:%02d:%02d", - tm->tm_hour, tm->tm_min, - tm->tm_sec); - else if (uptime < ONE_WEEK_SECOND) - vty_out(vty, "%dd%02dh%02dm", - tm->tm_yday, tm->tm_hour, - tm->tm_min); - else - vty_out(vty, "%02dw%dd%02dh", - tm->tm_yday / 7, - tm->tm_yday - ((tm->tm_yday / 7) - * 7), - tm->tm_hour); - vty_out(vty, " ago\n"); + + frrtime_to_interval(uptime, buf, sizeof(buf)); + + vty_out(vty, "Last restart time : %s ago\n", + buf); vty_out(vty, "Stalepath removal time: %d sec\n", info->stale_removal_time); diff --git a/zebra/zserv.h b/zebra/zserv.h index 77ea19202f..6a075cc9a7 100644 --- a/zebra/zserv.h +++ b/zebra/zserv.h @@ -229,6 +229,10 @@ struct zserv { DECLARE_HOOK(zserv_client_connect, (struct zserv *client), (client)); DECLARE_KOOH(zserv_client_close, (struct zserv *client), (client)); +#define DYNAMIC_CLIENT_GR_DISABLED(_client) \ + ((_client->proto <= ZEBRA_ROUTE_CONNECT) \ + || !(_client->gr_instance_count)) + /* * Initialize Zebra API server. * |
