From 46c3ce832799c53b90ce914b4b4c09b0589ea136 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 15 May 2017 07:33:48 -0400 Subject: [PATCH 1/9] bgpd: Cleanup some SA Signed-off-by: Donald Sharp --- bgpd/bgp_attr.c | 3 +-- bgpd/bgp_clist.c | 18 +++++++----------- bgpd/bgp_dump.c | 2 +- bgpd/bgp_packet.c | 5 +++-- bgpd/bgp_route.c | 10 +++++++--- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index b97ba61c95..7d5a98fec6 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -1500,8 +1500,7 @@ bgp_attr_as4_path (struct bgp_attr_parser_args *args, struct aspath **as4_path) } /* Set aspath attribute flag. */ - if (as4_path) - attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_AS4_PATH); + attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_AS4_PATH); return BGP_ATTR_PARSE_PROCEED; } diff --git a/bgpd/bgp_clist.c b/bgpd/bgp_clist.c index 3def97c73d..91cd7e3762 100644 --- a/bgpd/bgp_clist.c +++ b/bgpd/bgp_clist.c @@ -1158,16 +1158,13 @@ extcommunity_list_set (struct community_list_handler *ch, } } - if (str) - { - if (style == EXTCOMMUNITY_LIST_STANDARD) - ecom = ecommunity_str2com (str, 0, 1); - else - regex = bgp_regcomp (str); + if (style == EXTCOMMUNITY_LIST_STANDARD) + ecom = ecommunity_str2com (str, 0, 1); + else + regex = bgp_regcomp (str); - if (! ecom && ! regex) - return COMMUNITY_LIST_ERR_MALFORMED_VAL; - } + if (! ecom && ! regex) + return COMMUNITY_LIST_ERR_MALFORMED_VAL; if (ecom) ecom->str = ecommunity_ecom2str (ecom, ECOMMUNITY_FORMAT_DISPLAY, 0); @@ -1180,8 +1177,7 @@ extcommunity_list_set (struct community_list_handler *ch, entry->config = ecommunity_ecom2str (ecom, ECOMMUNITY_FORMAT_COMMUNITY_LIST, 0); else if (regex) entry->config = XSTRDUP (MTYPE_COMMUNITY_LIST_CONFIG, str); - else - entry->config = NULL; + entry->u.ecom = ecom; entry->reg = regex; diff --git a/bgpd/bgp_dump.c b/bgpd/bgp_dump.c index 10ddf1660c..c552ceab5a 100644 --- a/bgpd/bgp_dump.c +++ b/bgpd/bgp_dump.c @@ -626,7 +626,7 @@ bgp_dump_parse_time (const char *str) return 0; total += time * 60; time = 0; - seen_h = 1; + seen_m = 1; } else return 0; diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c index 0800dd74ba..ca211589f7 100644 --- a/bgpd/bgp_packet.c +++ b/bgpd/bgp_packet.c @@ -603,6 +603,8 @@ bgp_notify_send_with_data (struct peer *peer, u_char code, u_char sub_code, struct stream *s; int length; + assert (data); + /* Allocate new stream. */ s = stream_new (BGP_MAX_PACKET_SIZE); @@ -614,8 +616,7 @@ bgp_notify_send_with_data (struct peer *peer, u_char code, u_char sub_code, stream_putc (s, sub_code); /* BGP notify sub_code */ /* If notify data is present. */ - if (data) - stream_write (s, data, datalen); + stream_write (s, data, datalen); /* Set BGP packet length. */ length = bgp_packet_set_size (s); diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 834b9e073e..01032193a5 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -8887,6 +8887,7 @@ bgp_show_community (struct vty *vty, struct bgp *bgp, int argc, int i; char *str; int first = 0; + int ret = 0; b = buffer_new (1024); for (i = 0; i < argc; i++) @@ -8915,9 +8916,12 @@ bgp_show_community (struct vty *vty, struct bgp *bgp, int argc, return CMD_WARNING; } - return bgp_show (vty, bgp, afi, safi, - (exact ? bgp_show_type_community_exact : - bgp_show_type_community), com, 0); + ret = bgp_show (vty, bgp, afi, safi, + (exact ? bgp_show_type_community_exact : + bgp_show_type_community), com, 0); + community_free (com); + + return ret; } static int From 057fad8dfb65167925c01237af31e1a4ecadabb3 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 15 May 2017 18:48:54 -0400 Subject: [PATCH 2/9] eigrpd: Cleanup a bunch SA warnings. 1) Cleanup SA warnings, more to come 2) Cleanup some non debug guarded zlog_info code Signed-off-by: Donald Sharp --- eigrpd/eigrp_dump.c | 11 +++-- eigrpd/eigrp_filter.c | 17 +------- eigrpd/eigrp_hello.c | 15 ++++--- eigrpd/eigrp_interface.c | 4 +- eigrpd/eigrp_packet.c | 14 ++++--- eigrpd/eigrp_query.c | 11 ++--- eigrpd/eigrp_reply.c | 37 ++++++++--------- eigrpd/eigrp_siaquery.c | 13 +++--- eigrpd/eigrp_siareply.c | 13 +++--- eigrpd/eigrp_update.c | 86 +++++++++++++--------------------------- 10 files changed, 95 insertions(+), 126 deletions(-) diff --git a/eigrpd/eigrp_dump.c b/eigrpd/eigrp_dump.c index 21bef48ecb..3de7a53c10 100644 --- a/eigrpd/eigrp_dump.c +++ b/eigrpd/eigrp_dump.c @@ -310,10 +310,15 @@ show_ip_eigrp_topology_header (struct vty *vty, struct eigrp *eigrp) void show_ip_eigrp_prefix_entry (struct vty *vty, struct eigrp_prefix_entry *tn) { + struct list *successors = eigrp_topology_get_successor(tn); + vty_out (vty, "%-3c",(tn->state > 0) ? 'A' : 'P'); - vty_out (vty, "%s/%u, ",inet_ntoa (tn->destination_ipv4->prefix),tn->destination_ipv4->prefixlen); - vty_out (vty, "%u successors, ",eigrp_topology_get_successor(tn)->count); - vty_out (vty, "FD is %u, serno: %lu %s",tn->fdistance, tn->serno, VTY_NEWLINE); + vty_out (vty, "%s/%u, ", + inet_ntoa (tn->destination_ipv4->prefix), tn->destination_ipv4->prefixlen); + vty_out (vty, "%u successors, ", successors->count); + vty_out (vty, "FD is %u, serno: %lu %s", tn->fdistance, tn->serno, VTY_NEWLINE); + + list_delete(successors); } void diff --git a/eigrpd/eigrp_filter.c b/eigrpd/eigrp_filter.c index bfe51ae88d..7d628c8208 100644 --- a/eigrpd/eigrp_filter.c +++ b/eigrpd/eigrp_filter.c @@ -83,7 +83,6 @@ eigrp_distribute_update (struct distribute *dist) if (dist->list[DISTRIBUTE_V4_IN]) { alist = access_list_lookup (AFI_IP, dist->list[DISTRIBUTE_V4_IN]); - zlog_info("name); if (alist) e->list[EIGRP_FILTER_IN] = alist; else @@ -97,7 +96,6 @@ eigrp_distribute_update (struct distribute *dist) /* access list OUT for whole process */ if (dist->list[DISTRIBUTE_V4_OUT]) { - zlog_info("list[DISTRIBUTE_V4_OUT]); alist = access_list_lookup (AFI_IP, dist->list[DISTRIBUTE_V4_OUT]); if (alist) e->list[EIGRP_FILTER_OUT] = alist; @@ -112,7 +110,6 @@ eigrp_distribute_update (struct distribute *dist) /* PREFIX_LIST IN for process */ if (dist->prefix[DISTRIBUTE_V4_IN]) { - zlog_info("prefix[DISTRIBUTE_V4_IN]); plist = prefix_list_lookup (AFI_IP, dist->prefix[DISTRIBUTE_V4_IN]); if (plist) { @@ -126,7 +123,6 @@ eigrp_distribute_update (struct distribute *dist) /* PREFIX_LIST OUT for process */ if (dist->prefix[DISTRIBUTE_V4_OUT]) { - zlog_info("prefix[DISTRIBUTE_V4_OUT]); plist = prefix_list_lookup (AFI_IP, dist->prefix[DISTRIBUTE_V4_OUT]); if (plist) { @@ -192,8 +188,6 @@ eigrp_distribute_update (struct distribute *dist) if (ifp == NULL) return; - zlog_info("info; ei = info->eigrp_interface;*/ struct listnode *node, *nnode; @@ -207,15 +201,9 @@ eigrp_distribute_update (struct distribute *dist) } } - if(ei == NULL) - { - zlog_info("Not Found eigrp interface %s",ifp->name); - } - /* Access-list for interface in */ if (dist->list[DISTRIBUTE_V4_IN]) { - zlog_info("list[DISTRIBUTE_V4_IN]); if (alist){ ei->list[EIGRP_FILTER_IN] = alist; @@ -239,10 +227,7 @@ eigrp_distribute_update (struct distribute *dist) } else - { - ei->list[EIGRP_FILTER_OUT] = NULL; - zlog_info("list[EIGRP_FILTER_OUT] = NULL; /* Prefix-list for interface in */ if (dist->prefix[DISTRIBUTE_V4_IN]) diff --git a/eigrpd/eigrp_hello.c b/eigrpd/eigrp_hello.c index 051836d7e8..624c355eb4 100644 --- a/eigrpd/eigrp_hello.c +++ b/eigrpd/eigrp_hello.c @@ -252,7 +252,8 @@ eigrp_peer_termination_decode (struct eigrp_neighbor *nbr, if(my_ip == received_ip) { zlog_info ("Neighbor %s (%s) is down: Peer Termination received", - inet_ntoa (nbr->src),ifindex2ifname (nbr->ei->ifp->ifindex, VRF_DEFAULT)); + inet_ntoa (nbr->src), + ifindex2ifname (nbr->ei->ifp->ifindex, VRF_DEFAULT)); /* set neighbor to DOWN */ nbr->state = EIGRP_NEIGHBOR_DOWN; /* delete neighbor */ @@ -364,14 +365,15 @@ eigrp_hello_receive (struct eigrp *eigrp, struct ip *iph, struct eigrp_header *e case EIGRP_TLV_SW_VERSION: eigrp_sw_version_decode(nbr, tlv_header); break; - case EIGRP_TLV_NEXT_MCAST_SEQ: - break; + case EIGRP_TLV_NEXT_MCAST_SEQ: + break; case EIGRP_TLV_PEER_TERMINATION: eigrp_peer_termination_decode(nbr, tlv_header); + return; break; case EIGRP_TLV_PEER_MTRLIST: - case EIGRP_TLV_PEER_TIDLIST: - break; + case EIGRP_TLV_PEER_TIDLIST: + break; default: break; } @@ -388,7 +390,8 @@ eigrp_hello_receive (struct eigrp *eigrp, struct ip *iph, struct eigrp_header *e { /* increment statistics. */ ei->hello_in++; - eigrp_nbr_state_update(nbr); + if (nbr) + eigrp_nbr_state_update(nbr); } diff --git a/eigrpd/eigrp_interface.c b/eigrpd/eigrp_interface.c index 1ad5e88c22..5f3de8a921 100644 --- a/eigrpd/eigrp_interface.c +++ b/eigrpd/eigrp_interface.c @@ -304,7 +304,9 @@ eigrp_if_up (struct eigrp_interface *ei) { pe = eigrp_prefix_entry_new (); pe->serno = eigrp->serno; - pe->destination_ipv4 = dest_addr; + pe->destination_ipv4 = prefix_ipv4_new (); + prefix_copy ((struct prefix *)pe->destination_ipv4, + (struct prefix *)&dest_addr); pe->af = AF_INET; pe->nt = EIGRP_TOPOLOGY_TYPE_CONNECTED; diff --git a/eigrpd/eigrp_packet.c b/eigrpd/eigrp_packet.c index 635c1cf66b..6b529302d5 100644 --- a/eigrpd/eigrp_packet.c +++ b/eigrpd/eigrp_packet.c @@ -114,7 +114,10 @@ eigrp_make_md5_digest (struct eigrp_interface *ei, struct stream *s, u_char flag if(keychain) key = key_lookup_for_send(keychain); else - return EIGRP_AUTH_TYPE_NONE; + { + eigrp_authTLV_MD5_free(auth_TLV); + return EIGRP_AUTH_TYPE_NONE; + } memset(&ctx, 0, sizeof(ctx)); MD5Init(&ctx); @@ -235,8 +238,7 @@ eigrp_check_md5_digest (struct stream *s, } /* save neighbor's crypt_seqnum */ - if (nbr) - nbr->crypt_seqnum = authTLV->key_sequence; + nbr->crypt_seqnum = authTLV->key_sequence; return 1; } @@ -628,7 +630,7 @@ eigrp_read (struct thread *thread) struct eigrp_packet *ep; ep = eigrp_fifo_tail(nbr->retrans_queue); - if (ep != NULL) + if (ep) { if (ntohl(eigrph->ack) == ep->sequence_number) { @@ -642,7 +644,7 @@ eigrp_read (struct thread *thread) eigrp_update_send_EOT(nbr); } ep = eigrp_fifo_pop_tail(nbr->retrans_queue); - /*eigrp_packet_free(ep);*/ + eigrp_packet_free(ep); if (nbr->retrans_queue->count > 0) { eigrp_send_packet_reliably(nbr); @@ -650,7 +652,7 @@ eigrp_read (struct thread *thread) } } ep = eigrp_fifo_tail(nbr->multicast_queue); - if (ep != NULL) + if (ep) { if (ntohl(eigrph->ack) == ep->sequence_number) { diff --git a/eigrpd/eigrp_query.c b/eigrpd/eigrp_query.c index 4488054e06..e52d4fa663 100644 --- a/eigrpd/eigrp_query.c +++ b/eigrpd/eigrp_query.c @@ -114,16 +114,17 @@ eigrp_query_receive (struct eigrp *eigrp, struct ip *iph, struct eigrp_header *e type = stream_getw(s); if (type == EIGRP_TLV_IPv4_INT) { + struct prefix_ipv4 dest_addr; + stream_set_getp(s, s->getp - sizeof(u_int16_t)); tlv = eigrp_read_ipv4_tlv(s); - struct prefix_ipv4 *dest_addr; - dest_addr = prefix_ipv4_new(); - dest_addr->prefix = tlv->destination; - dest_addr->prefixlen = tlv->prefix_length; + dest_addr.family = AFI_IP; + dest_addr.prefix = tlv->destination; + dest_addr.prefixlen = tlv->prefix_length; struct eigrp_prefix_entry *dest = - eigrp_topology_table_lookup_ipv4(eigrp->topology_table, dest_addr); + eigrp_topology_table_lookup_ipv4(eigrp->topology_table, &dest_addr); /* If the destination exists (it should, but one never know)*/ if (dest != NULL) diff --git a/eigrpd/eigrp_reply.c b/eigrpd/eigrp_reply.c index 0c5d9dd92e..e5470a48f0 100644 --- a/eigrpd/eigrp_reply.c +++ b/eigrpd/eigrp_reply.c @@ -146,6 +146,8 @@ eigrp_send_reply (struct eigrp_neighbor *nbr, struct eigrp_prefix_entry *pe) { eigrp_send_packet_reliably(nbr); } + + XFREE(MTYPE_EIGRP_PREFIX_ENTRY, pe2); } /*EIGRP REPLY read function*/ @@ -180,16 +182,17 @@ eigrp_reply_receive (struct eigrp *eigrp, struct ip *iph, struct eigrp_header *e type = stream_getw(s); if (type == EIGRP_TLV_IPv4_INT) { + struct prefix_ipv4 dest_addr; + stream_set_getp(s, s->getp - sizeof(u_int16_t)); tlv = eigrp_read_ipv4_tlv(s); - struct prefix_ipv4 *dest_addr; - dest_addr = prefix_ipv4_new(); - dest_addr->prefix = tlv->destination; - dest_addr->prefixlen = tlv->prefix_length; + dest_addr.family = AFI_IP; + dest_addr.prefix = tlv->destination; + dest_addr.prefixlen = tlv->prefix_length; struct eigrp_prefix_entry *dest = - eigrp_topology_table_lookup_ipv4 (eigrp->topology_table, dest_addr); + eigrp_topology_table_lookup_ipv4 (eigrp->topology_table, &dest_addr); /* * Destination must exists */ @@ -212,24 +215,18 @@ eigrp_reply_receive (struct eigrp *eigrp, struct ip *iph, struct eigrp_header *e plist = e->prefix[EIGRP_FILTER_IN]; alist_i = ei->list[EIGRP_FILTER_IN]; plist_i = ei->prefix[EIGRP_FILTER_IN]; - zlog_info("REPLY Receive: Filtering"); - zlog_info("REPLY RECEIVE Prefix: %s", inet_ntoa(dest_addr->prefix)); /* Check if any list fits */ - if ((alist && access_list_apply (alist, - (struct prefix *) dest_addr) == FILTER_DENY)|| - (plist && prefix_list_apply (plist, - (struct prefix *) dest_addr) == PREFIX_DENY)|| - (alist_i && access_list_apply (alist_i, - (struct prefix *) dest_addr) == FILTER_DENY)|| - (plist_i && prefix_list_apply (plist_i, - (struct prefix *) dest_addr) == PREFIX_DENY)) + if ((alist && + access_list_apply (alist, (struct prefix *)&dest_addr) == FILTER_DENY) || + (plist && + prefix_list_apply (plist, (struct prefix *)&dest_addr) == PREFIX_DENY) || + (alist_i && + access_list_apply (alist_i, (struct prefix *)&dest_addr) == FILTER_DENY) || + (plist_i && + prefix_list_apply (plist_i, (struct prefix *)&dest_addr) == PREFIX_DENY)) { - zlog_info("REPLY RECEIVE: Setting metric to max"); tlv->metric.delay = EIGRP_MAX_METRIC; - zlog_info("REPLY RECEIVE Prefix: %s", inet_ntoa(dest_addr->prefix)); - } else { - zlog_info("REPLY RECEIVE: Not setting metric"); - } + } /* * End of filtering */ diff --git a/eigrpd/eigrp_siaquery.c b/eigrpd/eigrp_siaquery.c index b041300764..38033a4fa2 100644 --- a/eigrpd/eigrp_siaquery.c +++ b/eigrpd/eigrp_siaquery.c @@ -81,16 +81,17 @@ eigrp_siaquery_receive (struct eigrp *eigrp, struct ip *iph, struct eigrp_header type = stream_getw(s); if (type == EIGRP_TLV_IPv4_INT) { + struct prefix_ipv4 dest_addr; + stream_set_getp(s, s->getp - sizeof(u_int16_t)); tlv = eigrp_read_ipv4_tlv(s); - struct prefix_ipv4 *dest_addr; - dest_addr = prefix_ipv4_new(); - dest_addr->prefix = tlv->destination; - dest_addr->prefixlen = tlv->prefix_length; + dest_addr.family = AFI_IP; + dest_addr.prefix = tlv->destination; + dest_addr.prefixlen = tlv->prefix_length; struct eigrp_prefix_entry *dest = - eigrp_topology_table_lookup_ipv4(eigrp->topology_table, dest_addr); + eigrp_topology_table_lookup_ipv4(eigrp->topology_table, &dest_addr); /* If the destination exists (it should, but one never know)*/ if (dest != NULL) @@ -162,4 +163,6 @@ eigrp_send_siaquery (struct eigrp_neighbor *nbr, struct eigrp_prefix_entry *pe) eigrp_send_packet_reliably(nbr); } } + else + eigrp_packet_free(ep); } diff --git a/eigrpd/eigrp_siareply.c b/eigrpd/eigrp_siareply.c index 4c4793f864..e99f4ed957 100644 --- a/eigrpd/eigrp_siareply.c +++ b/eigrpd/eigrp_siareply.c @@ -80,16 +80,17 @@ eigrp_siareply_receive (struct eigrp *eigrp, struct ip *iph, struct eigrp_header type = stream_getw(s); if (type == EIGRP_TLV_IPv4_INT) { + struct prefix_ipv4 dest_addr; + stream_set_getp(s, s->getp - sizeof(u_int16_t)); tlv = eigrp_read_ipv4_tlv(s); - struct prefix_ipv4 *dest_addr; - dest_addr = prefix_ipv4_new(); - dest_addr->prefix = tlv->destination; - dest_addr->prefixlen = tlv->prefix_length; + dest_addr.family = AFI_IP; + dest_addr.prefix = tlv->destination; + dest_addr.prefixlen = tlv->prefix_length; struct eigrp_prefix_entry *dest = - eigrp_topology_table_lookup_ipv4(eigrp->topology_table, dest_addr); + eigrp_topology_table_lookup_ipv4(eigrp->topology_table, &dest_addr); /* If the destination exists (it should, but one never know)*/ if (dest != NULL) @@ -161,6 +162,8 @@ eigrp_send_siareply (struct eigrp_neighbor *nbr, struct eigrp_prefix_entry *pe) eigrp_send_packet_reliably(nbr); } } + else + eigrp_packet_free(ep); } diff --git a/eigrpd/eigrp_update.c b/eigrpd/eigrp_update.c index 5c942bd4d5..9bb772decf 100644 --- a/eigrpd/eigrp_update.c +++ b/eigrpd/eigrp_update.c @@ -291,17 +291,18 @@ eigrp_update_receive (struct eigrp *eigrp, struct ip *iph, struct eigrp_header * type = stream_getw(s); if (type == EIGRP_TLV_IPv4_INT) { + struct prefix_ipv4 dest_addr; + stream_set_getp(s, s->getp - sizeof(u_int16_t)); tlv = eigrp_read_ipv4_tlv(s); /*searching if destination exists */ - struct prefix_ipv4 *dest_addr; - dest_addr = prefix_ipv4_new(); - dest_addr->prefix = tlv->destination; - dest_addr->prefixlen = tlv->prefix_length; + dest_addr.family = AFI_IP; + dest_addr.prefix = tlv->destination; + dest_addr.prefixlen = tlv->prefix_length; struct eigrp_prefix_entry *dest = - eigrp_topology_table_lookup_ipv4(eigrp->topology_table, dest_addr); + eigrp_topology_table_lookup_ipv4(eigrp->topology_table, &dest_addr); /*if exists it comes to DUAL*/ if (dest != NULL) @@ -331,7 +332,9 @@ eigrp_update_receive (struct eigrp *eigrp, struct ip *iph, struct eigrp_header * /*Here comes topology information save*/ pe = eigrp_prefix_entry_new(); pe->serno = eigrp->serno; - pe->destination_ipv4 = dest_addr; + pe->destination_ipv4 = prefix_ipv4_new(); + prefix_copy((struct prefix *)pe->destination_ipv4, + (struct prefix *)&dest_addr); pe->af = AF_INET; pe->state = EIGRP_FSM_STATE_PASSIVE; pe->nt = EIGRP_TOPOLOGY_TYPE_REMOTE; @@ -353,93 +356,52 @@ eigrp_update_receive (struct eigrp *eigrp, struct ip *iph, struct eigrp_header * */ alist = ei->list[EIGRP_FILTER_IN]; - if (alist) { - zlog_info ("ALIST PROC IN: %s", alist->name); - } else { - zlog_info("ALIST je prazdny"); - } - /* Check if access-list fits */ - if (alist && access_list_apply (alist, - (struct prefix *) dest_addr) == FILTER_DENY) + if (alist && + access_list_apply (alist, (struct prefix *)&dest_addr) == FILTER_DENY) { /* If yes, set reported metric to Max */ - zlog_info("PROC IN: Nastavujem metriku na MAX"); ne->reported_metric.delay = EIGRP_MAX_METRIC; - zlog_info("PROC IN Prefix: %s", inet_ntoa(dest_addr->prefix)); } else { - zlog_info("PROC IN: NENastavujem metriku "); ne->distance = eigrp_calculate_total_metrics(eigrp, ne); } plist = e->prefix[EIGRP_FILTER_IN]; - if (plist) { - zlog_info ("PLIST PROC IN: %s", plist->name); - } else { - zlog_info("PLIST PROC IN je prazdny"); - } - /* Check if prefix-list fits */ - if (plist && prefix_list_apply (plist, - (struct prefix *) dest_addr) == PREFIX_DENY) + if (plist && + prefix_list_apply (plist, (struct prefix *)&dest_addr) == PREFIX_DENY) { /* If yes, set reported metric to Max */ - zlog_info("PLIST PROC IN: Nastavujem metriku na MAX"); ne->reported_metric.delay = EIGRP_MAX_METRIC; - zlog_info("PLIST PROC IN Prefix: %s", inet_ntoa(dest_addr->prefix)); - } else { - zlog_info("PLIST PROC IN: NENastavujem metriku "); - } + } /*Get access-list from current interface */ - zlog_info("Checking access_list on interface: %s",ei->ifp->name); alist = ei->list[EIGRP_FILTER_IN]; - if (alist) { - zlog_info ("ALIST INT IN: %s", alist->name); - } else { - zlog_info("ALIST INT IN je prazdny"); - } /* Check if access-list fits */ - if (alist && access_list_apply (alist, (struct prefix *) dest_addr) == FILTER_DENY) + if (alist && + access_list_apply (alist, (struct prefix *)&dest_addr) == FILTER_DENY) { /* If yes, set reported metric to Max */ - zlog_info("INT IN: Nastavujem metriku na MAX"); ne->reported_metric.delay = EIGRP_MAX_METRIC; - zlog_info("INT IN Prefix: %s", inet_ntoa(dest_addr->prefix)); - } else { - zlog_info("INT IN: NENastavujem metriku "); - } + } plist = ei->prefix[EIGRP_FILTER_IN]; - if (plist) { - zlog_info ("PLIST INT IN: %s", plist->name); - } else { - zlog_info("PLIST INT IN je prazdny"); - } - /* Check if prefix-list fits */ - if (plist && prefix_list_apply (plist, - (struct prefix *) dest_addr) == PREFIX_DENY) + if (plist && + prefix_list_apply (plist, (struct prefix *)&dest_addr) == PREFIX_DENY) { /* If yes, set reported metric to Max */ - zlog_info("PLIST INT IN: Nastavujem metriku na MAX"); ne->reported_metric.delay = EIGRP_MAX_METRIC; - zlog_info("PLIST INT IN Prefix: %s", inet_ntoa(dest_addr->prefix)); - } else { - zlog_info("PLIST INT IN: NENastavujem metriku "); - } + } /* * End of filtering */ ne->distance = eigrp_calculate_total_metrics(eigrp, ne); - zlog_info("distance); - zlog_info("total_metric.delay); - pe->fdistance = pe->distance = pe->rdistance = ne->distance; ne->prefix = pe; @@ -669,6 +631,7 @@ eigrp_update_send (struct eigrp_interface *ei) struct prefix_list *plist_i; struct eigrp *e; struct prefix_ipv4 *dest_addr; + bool packet_sent = false; u_int16_t length = EIGRP_HEADER_LEN; @@ -740,7 +703,8 @@ eigrp_update_send (struct eigrp_interface *ei) return; } - if((IF_DEF_PARAMS (ei->ifp)->auth_type == EIGRP_AUTH_TYPE_MD5) && (IF_DEF_PARAMS (ei->ifp)->auth_keychain != NULL)) + if((IF_DEF_PARAMS (ei->ifp)->auth_type == EIGRP_AUTH_TYPE_MD5) + && (IF_DEF_PARAMS (ei->ifp)->auth_keychain != NULL)) { eigrp_make_md5_digest(ei,ep->s, EIGRP_AUTH_UPDATE_FLAG); } @@ -762,6 +726,7 @@ eigrp_update_send (struct eigrp_interface *ei) { if (nbr->state == EIGRP_NEIGHBOR_UP) { + packet_sent = true; /*Put packet to retransmission queue*/ eigrp_fifo_push_head(nbr->retrans_queue, ep); @@ -771,6 +736,9 @@ eigrp_update_send (struct eigrp_interface *ei) } } } + + if (!packet_sent) + eigrp_packet_free(ep); } void From 7922fc65ae0bf5ec211064d8610d4122ddbb4e20 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 15 May 2017 19:02:34 -0400 Subject: [PATCH 3/9] lib, zebra: Cleanup vrf api some Segregate the vrf enable/disable functionality from other vrf code. This is to ensure that people are not actually using the functions when they should not be. Also document the why of it properly in the new vrf_int.h header. Signed-off-by: Donald Sharp --- lib/vrf.c | 1 + lib/vrf.h | 2 -- lib/vrf_int.h | 56 ++++++++++++++++++++++++++++++++++++++++++++++ lib/zclient.c | 2 ++ zebra/if_netlink.c | 1 + 5 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 lib/vrf_int.h diff --git a/lib/vrf.c b/lib/vrf.c index ce57bb6e7a..4fde134e44 100644 --- a/lib/vrf.c +++ b/lib/vrf.c @@ -24,6 +24,7 @@ #include "if.h" #include "vrf.h" +#include "vrf_int.h" #include "prefix.h" #include "table.h" #include "log.h" diff --git a/lib/vrf.h b/lib/vrf.h index f8bb07ef48..418d891a35 100644 --- a/lib/vrf.h +++ b/lib/vrf.h @@ -111,8 +111,6 @@ extern void vrf_add_hook (int, int (*)(struct vrf *)); extern struct vrf *vrf_lookup_by_id (vrf_id_t); extern struct vrf *vrf_lookup_by_name (const char *); extern struct vrf *vrf_get (vrf_id_t, const char *); -extern void vrf_delete (struct vrf *); -extern int vrf_enable (struct vrf *); extern vrf_id_t vrf_name_to_id (const char *); #define VRF_GET_ID(V,NAME) \ diff --git a/lib/vrf_int.h b/lib/vrf_int.h new file mode 100644 index 0000000000..f0301b7670 --- /dev/null +++ b/lib/vrf_int.h @@ -0,0 +1,56 @@ +/* + * VRF Internal Header + * Copyright (C) 2017 Cumulus Networks, Inc. + * Donald Sharp + * + * This file is part of FRR. + * + * FRR 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, or (at your option) any + * later version. + * + * FRR 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 FRR; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ +#ifndef __LIB_VRF_PRIVATE_H__ +#define __LIB_VRF_PRIVATE_H__ + +#include "vrf.h" + +/* + * These functions should only be called by: + * zebra/if_netlink.c -> The interface from OS into Zebra + * lib/zclient.c -> The interface from Zebra to each daemon + * + * Why you ask? Well because these are the turn on/off + * functions and the only place we can really turn a + * vrf on properly is in the call up from the os -> zebra + * and the pass through of this informatoin from zebra -> protocols + */ + +/* + * vrf_enable + * + * Given a newly running vrf enable it to be used + * by interested routing protocols + */ +extern int vrf_enable (struct vrf *); + +/* + * vrf_delete + * + * Given a vrf that is being deleted, delete it + * from interested parties + */ +extern void vrf_delete (struct vrf *); + +#endif + diff --git a/lib/zclient.c b/lib/zclient.c index 1d3c93d85d..5d1ca00c92 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -26,6 +26,8 @@ #include "stream.h" #include "buffer.h" #include "network.h" +#include "vrf.h" +#include "vrf_int.h" #include "if.h" #include "log.h" #include "thread.h" diff --git a/zebra/if_netlink.c b/zebra/if_netlink.c index 006fcf16f4..256f4d6567 100644 --- a/zebra/if_netlink.c +++ b/zebra/if_netlink.c @@ -38,6 +38,7 @@ #include "privs.h" #include "nexthop.h" #include "vrf.h" +#include "vrf_int.h" #include "mpls.h" #include "vty.h" From 759927a1b9e1a0a820e05dbb6ce12fb16c8f9b34 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 15 May 2017 19:11:20 -0400 Subject: [PATCH 4/9] *: Remove some unneeded functions vrf_iflist_create -> By the time this is called in enable, the vrf's iflist is already created. Additionally this code should be a properly of the vrf to init/destroy not someone else. vrf_iflist_terminate -> This function should be a property of vrf deletion and does not need to be exposed. Signed-off-by: Donald Sharp --- bgpd/bgpd.c | 19 +------------------ lib/vrf.c | 18 ------------------ lib/vrf.h | 6 ++---- pimd/pim_iface.c | 1 - 4 files changed, 3 insertions(+), 41 deletions(-) diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 2c04f79478..9af48eafb8 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -94,7 +94,6 @@ struct community_list_handler *bgp_clist; unsigned int multipath_num = MULTIPATH_NUM; -static void bgp_if_init (struct bgp *bgp); static void bgp_if_finish (struct bgp *bgp); extern struct zclient *zclient; @@ -3115,10 +3114,7 @@ bgp_get (struct bgp **bgp_val, as_t *as, const char *name, vrf = bgp_vrf_lookup_by_instance_type (bgp); if (vrf) - { - bgp_vrf_link (bgp, vrf); - bgp_if_init (bgp); - } + bgp_vrf_link (bgp, vrf); } /* Register with Zebra, if needed */ @@ -7654,19 +7650,6 @@ bgp_master_init (struct thread_master *master) QOBJ_REG (bm, bgp_master); } -/* - * Initialize interface list for instance, if needed. Invoked upon - * instance create. - */ -static void -bgp_if_init (struct bgp *bgp) -{ - if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW) - return; - - vrf_iflist_create (bgp->vrf_id); -} - /* * Free up connected routes and interfaces for a BGP instance. Invoked upon * instance delete (non-default only) or BGP exit. diff --git a/lib/vrf.c b/lib/vrf.c index 4fde134e44..41b6a05b3a 100644 --- a/lib/vrf.c +++ b/lib/vrf.c @@ -310,24 +310,6 @@ vrf_iflist_get (vrf_id_t vrf_id) return vrf->iflist; } -/* Create the interface list for the specified VRF, if needed. */ -void -vrf_iflist_create (vrf_id_t vrf_id) -{ - struct vrf * vrf = vrf_lookup_by_id (vrf_id); - if (vrf && !vrf->iflist) - if_init (&vrf->iflist); -} - -/* Free the interface list of the specified VRF. */ -void -vrf_iflist_terminate (vrf_id_t vrf_id) -{ - struct vrf * vrf = vrf_lookup_by_id (vrf_id); - if (vrf && vrf->iflist) - if_terminate (&vrf->iflist); -} - /* * VRF bit-map */ diff --git a/lib/vrf.h b/lib/vrf.h index 418d891a35..053be89684 100644 --- a/lib/vrf.h +++ b/lib/vrf.h @@ -108,6 +108,8 @@ extern struct vrf_name_head vrfs_by_name; */ extern void vrf_add_hook (int, int (*)(struct vrf *)); +int (*vrf_callback)(struct vrf *); + extern struct vrf *vrf_lookup_by_id (vrf_id_t); extern struct vrf *vrf_lookup_by_name (const char *); extern struct vrf *vrf_get (vrf_id_t, const char *); @@ -146,10 +148,6 @@ extern void *vrf_info_lookup (vrf_id_t); extern struct list *vrf_iflist (vrf_id_t); /* Get the interface list of the specified VRF. Create one if not find. */ extern struct list *vrf_iflist_get (vrf_id_t); -/* Create the interface list for the specified VRF, if needed. */ -extern void vrf_iflist_create (vrf_id_t vrf_id); -/* Free the interface list of the specified VRF. */ -extern void vrf_iflist_terminate (vrf_id_t vrf_id); /* * VRF bit-map: maintaining flags, one bit per VRF ID diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index 48a59344eb..2cbf63e7d5 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -61,7 +61,6 @@ pim_if_init (void) for (i = 0; i < MAXVIFS; i++) pim_iface_vif_index[i] = 0; - vrf_iflist_create(VRF_DEFAULT); pim_ifchannel_list = list_new(); pim_ifchannel_list->cmp = (int (*)(void *, void *))pim_ifchannel_compare; } From 6df853648784baf44c55d026bd8e4f0976bd1607 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 15 May 2017 19:31:27 -0400 Subject: [PATCH 5/9] *: Consolidate vrf_hooks into vrf_init We only needed to add/change the vrf callbacks when we initialize the vrf subsystem. As such it is not necessary to handle the callbacks in any other way than through the init function. Signed-off-by: Donald Sharp --- bgpd/bgp_main.c | 15 ++++----------- eigrpd/eigrp_main.c | 2 +- isisd/isis_main.c | 2 +- ldpd/ldpd.c | 2 +- lib/vrf.c | 37 +++++++++---------------------------- lib/vrf.h | 26 ++++---------------------- nhrpd/nhrp_main.c | 2 +- ospf6d/ospf6_main.c | 2 +- ospfd/ospf_main.c | 2 +- pimd/pimd.c | 15 ++++----------- ripd/rip_main.c | 2 +- ripngd/ripng_main.c | 2 +- zebra/zebra_vrf.c | 9 ++++----- 13 files changed, 33 insertions(+), 85 deletions(-) diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c index 3b844cf70e..644a091c31 100644 --- a/bgpd/bgp_main.c +++ b/bgpd/bgp_main.c @@ -327,22 +327,15 @@ bgp_vrf_disable (struct vrf *vrf) static void bgp_vrf_init (void) { - vrf_add_hook (VRF_NEW_HOOK, bgp_vrf_new); - vrf_add_hook (VRF_ENABLE_HOOK, bgp_vrf_enable); - vrf_add_hook (VRF_DISABLE_HOOK, bgp_vrf_disable); - vrf_add_hook (VRF_DELETE_HOOK, bgp_vrf_delete); - - vrf_init (); + vrf_init (bgp_vrf_new, + bgp_vrf_enable, + bgp_vrf_disable, + bgp_vrf_delete); } static void bgp_vrf_terminate (void) { - vrf_add_hook (VRF_NEW_HOOK, NULL); - vrf_add_hook (VRF_ENABLE_HOOK, NULL); - vrf_add_hook (VRF_DISABLE_HOOK, NULL); - vrf_add_hook (VRF_DELETE_HOOK, NULL); - vrf_terminate (); } diff --git a/eigrpd/eigrp_main.c b/eigrpd/eigrp_main.c index 6a5e3b1a04..e71464fdbb 100644 --- a/eigrpd/eigrp_main.c +++ b/eigrpd/eigrp_main.c @@ -182,7 +182,7 @@ main (int argc, char **argv, char **envp) eigrp_om->master = frr_init(); master = eigrp_om->master; - vrf_init (); + vrf_init (NULL, NULL, NULL, NULL); /*EIGRPd init*/ eigrp_if_init (); diff --git a/isisd/isis_main.c b/isisd/isis_main.c index 644b652d44..b895f61dce 100644 --- a/isisd/isis_main.c +++ b/isisd/isis_main.c @@ -206,7 +206,7 @@ main (int argc, char **argv, char **envp) * initializations */ access_list_init(); - vrf_init (); + vrf_init (NULL, NULL, NULL, NULL); prefix_list_init(); isis_init (); isis_circuit_init (); diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index a0b021dfd9..710dcd15f4 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -329,7 +329,7 @@ main(int argc, char *argv[]) cmd_init(1); vty_config_lockless(); vty_init(master); - vrf_init(); + vrf_init(NULL, NULL, NULL, NULL); access_list_init(); ldp_vty_init(); ldp_zebra_init(master); diff --git a/lib/vrf.c b/lib/vrf.c index 41b6a05b3a..7d8a118763 100644 --- a/lib/vrf.c +++ b/lib/vrf.c @@ -238,33 +238,6 @@ vrf_disable (struct vrf *vrf) (*vrf_master.vrf_disable_hook) (vrf); } - -/* Add a VRF hook. Please add hooks before calling vrf_init(). */ -void -vrf_add_hook (int type, int (*func)(struct vrf *)) -{ - if (debug_vrf) - zlog_debug ("%s: Add Hook %d to function %p", __PRETTY_FUNCTION__, - type, func); - - switch (type) { - case VRF_NEW_HOOK: - vrf_master.vrf_new_hook = func; - break; - case VRF_DELETE_HOOK: - vrf_master.vrf_delete_hook = func; - break; - case VRF_ENABLE_HOOK: - vrf_master.vrf_enable_hook = func; - break; - case VRF_DISABLE_HOOK: - vrf_master.vrf_disable_hook = func; - break; - default: - break; - } -} - vrf_id_t vrf_name_to_id (const char *name) { @@ -407,13 +380,21 @@ vrf_bitmap_check (vrf_bitmap_t bmap, vrf_id_t vrf_id) /* Initialize VRF module. */ void -vrf_init (void) +vrf_init (int (*create)(struct vrf *), + int (*enable)(struct vrf *), + int (*disable)(struct vrf *), + int (*delete)(struct vrf *)) { struct vrf *default_vrf; if (debug_vrf) zlog_debug ("%s: Initializing VRF subsystem", __PRETTY_FUNCTION__); + vrf_master.vrf_new_hook = create; + vrf_master.vrf_enable_hook = enable; + vrf_master.vrf_disable_hook = disable; + vrf_master.vrf_delete_hook = delete; + /* The default VRF always exists. */ default_vrf = vrf_get (VRF_DEFAULT, VRF_DEFAULT_NAME); if (!default_vrf) diff --git a/lib/vrf.h b/lib/vrf.h index 053be89684..a08258a929 100644 --- a/lib/vrf.h +++ b/lib/vrf.h @@ -57,15 +57,6 @@ enum { #define VRF_CMD_HELP_STR "Specify the VRF\nThe VRF name\n" #define VRF_ALL_CMD_HELP_STR "Specify the VRF\nAll VRFs\n" -/* - * VRF hooks - */ - -#define VRF_NEW_HOOK 0 /* a new VRF is just created */ -#define VRF_DELETE_HOOK 1 /* a VRF is to be deleted */ -#define VRF_ENABLE_HOOK 2 /* a VRF is ready to use */ -#define VRF_DISABLE_HOOK 3 /* a VRF is to be unusable */ - struct vrf { RB_ENTRY(vrf) id_entry, name_entry; @@ -98,18 +89,6 @@ DECLARE_QOBJ_TYPE(vrf) extern struct vrf_id_head vrfs_by_id; extern struct vrf_name_head vrfs_by_name; -/* - * Add a specific hook to VRF module. - * @param1: hook type - * @param2: the callback function - * - param 1: the VRF ID - * - param 2: the address of the user data pointer (the user data - * can be stored in or freed from there) - */ -extern void vrf_add_hook (int, int (*)(struct vrf *)); - -int (*vrf_callback)(struct vrf *); - extern struct vrf *vrf_lookup_by_id (vrf_id_t); extern struct vrf *vrf_lookup_by_name (const char *); extern struct vrf *vrf_get (vrf_id_t, const char *); @@ -166,7 +145,10 @@ extern int vrf_bitmap_check (vrf_bitmap_t, vrf_id_t); * VRF initializer/destructor */ /* Please add hooks before calling vrf_init(). */ -extern void vrf_init (void); +extern void vrf_init (int (*create)(struct vrf *), + int (*enable)(struct vrf *), + int (*disable)(struct vrf *), + int (*delete)(struct vrf *)); extern void vrf_terminate (void); extern void vrf_cmd_init (int (*writefunc)(struct vty *vty)); diff --git a/nhrpd/nhrp_main.c b/nhrpd/nhrp_main.c index a44ce35bb8..7c5d80336c 100644 --- a/nhrpd/nhrp_main.c +++ b/nhrpd/nhrp_main.c @@ -129,7 +129,7 @@ int main(int argc, char **argv) /* Library inits. */ master = frr_init(); nhrp_interface_init(); - vrf_init(); + vrf_init(NULL, NULL, NULL, NULL); resolver_init(); /* Run with elevated capabilities, as for all netlink activity diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c index 54ae4645ad..198a881106 100644 --- a/ospf6d/ospf6_main.c +++ b/ospf6d/ospf6_main.c @@ -222,7 +222,7 @@ main (int argc, char *argv[], char *envp[]) /* thread master */ master = frr_init (); - vrf_init (); + vrf_init (NULL, NULL, NULL, NULL); access_list_init (); prefix_list_init (); diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c index 38718b35d5..a5f430e051 100644 --- a/ospfd/ospf_main.c +++ b/ospfd/ospf_main.c @@ -207,7 +207,7 @@ main (int argc, char **argv) /* Library inits. */ debug_init (); - vrf_init (); + vrf_init (NULL, NULL, NULL, NULL); access_list_init (); prefix_list_init (); diff --git a/pimd/pimd.c b/pimd/pimd.c index fc6663776b..6b75a93914 100644 --- a/pimd/pimd.c +++ b/pimd/pimd.c @@ -141,22 +141,15 @@ pim_vrf_disable (struct vrf *vrf) void pim_vrf_init (void) { - vrf_add_hook (VRF_NEW_HOOK, pim_vrf_new); - vrf_add_hook (VRF_ENABLE_HOOK, pim_vrf_enable); - vrf_add_hook (VRF_DISABLE_HOOK, pim_vrf_disable); - vrf_add_hook (VRF_DELETE_HOOK, pim_vrf_delete); - - vrf_init (); + vrf_init (pim_vrf_new, + pim_vrf_enable, + pim_vrf_disable, + pim_vrf_delete); } static void pim_vrf_terminate (void) { - vrf_add_hook (VRF_NEW_HOOK, NULL); - vrf_add_hook (VRF_ENABLE_HOOK, NULL); - vrf_add_hook (VRF_DISABLE_HOOK, NULL); - vrf_add_hook (VRF_DELETE_HOOK, NULL); - vrf_terminate (); } diff --git a/ripd/rip_main.c b/ripd/rip_main.c index 62ea6dd078..a4509cc064 100644 --- a/ripd/rip_main.c +++ b/ripd/rip_main.c @@ -178,7 +178,7 @@ main (int argc, char **argv) /* Library initialization. */ keychain_init (); - vrf_init (); + vrf_init (NULL, NULL, NULL, NULL); /* RIP related initialization. */ rip_init (); diff --git a/ripngd/ripng_main.c b/ripngd/ripng_main.c index 9d97df5c41..5767b08636 100644 --- a/ripngd/ripng_main.c +++ b/ripngd/ripng_main.c @@ -178,7 +178,7 @@ main (int argc, char **argv) master = frr_init (); /* Library inits. */ - vrf_init (); + vrf_init (NULL, NULL, NULL, NULL); /* RIPngd inits. */ ripng_init (); diff --git a/zebra/zebra_vrf.c b/zebra/zebra_vrf.c index 6b36891056..1e6142038d 100644 --- a/zebra/zebra_vrf.c +++ b/zebra/zebra_vrf.c @@ -536,11 +536,10 @@ vrf_config_write (struct vty *vty) void zebra_vrf_init (void) { - vrf_add_hook (VRF_NEW_HOOK, zebra_vrf_new); - vrf_add_hook (VRF_ENABLE_HOOK, zebra_vrf_enable); - vrf_add_hook (VRF_DISABLE_HOOK, zebra_vrf_disable); - vrf_add_hook (VRF_DELETE_HOOK, zebra_vrf_delete); + vrf_init (zebra_vrf_new, + zebra_vrf_enable, + zebra_vrf_disable, + zebra_vrf_delete); - vrf_init (); vrf_cmd_init (vrf_config_write); } From 97b1a80cbb7ca5582972d700dbed6e011cbd9f83 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 15 May 2017 19:37:16 -0400 Subject: [PATCH 6/9] lib: Add some more documentation to vrf.h Signed-off-by: Donald Sharp --- lib/vrf.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/vrf.h b/lib/vrf.h index a08258a929..14917eec02 100644 --- a/lib/vrf.h +++ b/lib/vrf.h @@ -143,12 +143,31 @@ extern int vrf_bitmap_check (vrf_bitmap_t, vrf_id_t); /* * VRF initializer/destructor + * + * create -> Called back when a new VRF is created. This + * can be either through these 3 options: + * 1) CLI mentions a vrf before OS knows about it + * 2) OS calls zebra and we create the vrf from OS + * callback + * 3) zebra calls individual protocols to notify + * about the new vrf + * + * enable -> Called back when a VRF is actually usable from + * an OS perspective ( 2 and 3 above ) + * + * disable -> Called back when a VRF is being deleted from + * the system ( 2 and 3 ) above + * + * delete -> Called back when a vrf is being deleted from + * the system ( 2 and 3 ) above. */ -/* Please add hooks before calling vrf_init(). */ extern void vrf_init (int (*create)(struct vrf *), int (*enable)(struct vrf *), int (*disable)(struct vrf *), int (*delete)(struct vrf *)); +/* + * Call vrf_terminate when the protocol is being shutdown + */ extern void vrf_terminate (void); extern void vrf_cmd_init (int (*writefunc)(struct vty *vty)); From cc629aef4a1a4bb08123ca72312be5e9b28f27c5 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 15 May 2017 22:00:28 -0400 Subject: [PATCH 7/9] tests: Fix vrf_init to have correct call Signed-off-by: Donald Sharp --- tests/bgpd/test_capability.c | 2 +- tests/bgpd/test_mp_attr.c | 2 +- tests/bgpd/test_mpath.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/bgpd/test_capability.c b/tests/bgpd/test_capability.c index c3de6a16e8..787a398f3c 100644 --- a/tests/bgpd/test_capability.c +++ b/tests/bgpd/test_capability.c @@ -651,7 +651,7 @@ main (void) qobj_init (); master = thread_master_create (); bgp_master_init (master); - vrf_init (); + vrf_init (NULL, NULL, NULL, NULL); bgp_option_set (BGP_OPT_NO_LISTEN); if (fileno (stdout) >= 0) diff --git a/tests/bgpd/test_mp_attr.c b/tests/bgpd/test_mp_attr.c index 6824c11fea..7c1200b32b 100644 --- a/tests/bgpd/test_mp_attr.c +++ b/tests/bgpd/test_mp_attr.c @@ -751,7 +751,7 @@ main (void) qobj_init (); master = thread_master_create (); bgp_master_init (master); - vrf_init (); + vrf_init (NULL, NULL, NULL, NULL); bgp_option_set (BGP_OPT_NO_LISTEN); bgp_attr_init (); diff --git a/tests/bgpd/test_mpath.c b/tests/bgpd/test_mpath.c index a2fd66528c..9e406c397b 100644 --- a/tests/bgpd/test_mpath.c +++ b/tests/bgpd/test_mpath.c @@ -380,7 +380,7 @@ global_test_init (void) master = thread_master_create (); zclient = zclient_new(master); bgp_master_init (master); - vrf_init (); + vrf_init (NULL, NULL, NULL, NULL); bgp_option_set (BGP_OPT_NO_LISTEN); if (fileno (stdout) >= 0) From b84ccd40895bfc9660b1cb36821192d2910ae984 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 15 May 2017 22:29:10 -0400 Subject: [PATCH 8/9] bgpd: Revert incorrect handling of data data is actually allowed to be NULL. So allow pass in. Signed-off-by: Donald Sharp --- bgpd/bgp_packet.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c index ca211589f7..0800dd74ba 100644 --- a/bgpd/bgp_packet.c +++ b/bgpd/bgp_packet.c @@ -603,8 +603,6 @@ bgp_notify_send_with_data (struct peer *peer, u_char code, u_char sub_code, struct stream *s; int length; - assert (data); - /* Allocate new stream. */ s = stream_new (BGP_MAX_PACKET_SIZE); @@ -616,7 +614,8 @@ bgp_notify_send_with_data (struct peer *peer, u_char code, u_char sub_code, stream_putc (s, sub_code); /* BGP notify sub_code */ /* If notify data is present. */ - stream_write (s, data, datalen); + if (data) + stream_write (s, data, datalen); /* Set BGP packet length. */ length = bgp_packet_set_size (s); From 21a15acdde0f428fa2e9926d69a8a484249228d0 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 16 May 2017 07:49:46 -0400 Subject: [PATCH 9/9] lib: Fix missing vrf_int.h from `make distribute` Signed-off-by: Donald Sharp --- lib/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Makefile.am b/lib/Makefile.am index 6e3c6d680d..e3e58fedf6 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -78,6 +78,7 @@ pkginclude_HEADERS = \ libfrr.h \ sha256.h \ frr_pthread.h \ + vrf_int.h \ # end noinst_HEADERS = \