summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--babeld/net.c2
-rw-r--r--bfdd/bfd.c158
-rw-r--r--bfdd/bfd.h14
-rw-r--r--bfdd/bfd_packet.c141
-rw-r--r--bfdd/bfdd.c4
-rw-r--r--bfdd/bfdd_nb_config.c32
-rw-r--r--bfdd/bfdd_nb_state.c2
-rw-r--r--bfdd/bfdd_vty.c12
-rw-r--r--bfdd/config.c91
-rw-r--r--bfdd/control.c46
-rw-r--r--bfdd/event.c20
-rw-r--r--bfdd/ptm_adapter.c42
-rw-r--r--bgpd/bgp_attr.c5
-rw-r--r--bgpd/bgp_community.c25
-rw-r--r--bgpd/bgp_community.h4
-rw-r--r--bgpd/bgp_ecommunity.c2
-rw-r--r--bgpd/bgp_evpn.c4
-rw-r--r--bgpd/bgp_evpn_vty.c5
-rw-r--r--bgpd/bgp_lcommunity.c2
-rw-r--r--bgpd/bgp_nexthop.c3
-rw-r--r--bgpd/bgp_route.c120
-rw-r--r--bgpd/bgp_routemap.c4
-rw-r--r--bgpd/bgp_snmp.c2
-rw-r--r--bgpd/bgp_vty.c37
-rw-r--r--bgpd/bgpd.c3
-rw-r--r--bgpd/rfapi/rfapi_import.c2
-rw-r--r--bgpd/rfapi/rfapi_monitor.c5
-rw-r--r--bgpd/rfapi/rfapi_rib.c4
-rw-r--r--bgpd/rfapi/rfapi_vty.c2
-rwxr-xr-xconfigure.ac2
-rw-r--r--eigrpd/eigrp_network.c2
-rw-r--r--isisd/isis_cli.c18
-rw-r--r--ldpd/socket.c2
-rw-r--r--lib/command_match.c2
-rw-r--r--lib/md5.c4
-rw-r--r--lib/skiplist.c4
-rw-r--r--lib/table.c2
-rw-r--r--lib/vrf.c2
-rw-r--r--lib/zclient.c2
-rw-r--r--nhrpd/zbuf.h8
-rw-r--r--ospf6d/ospf6_asbr.c4
-rw-r--r--ospf6d/ospf6_lsa.c4
-rw-r--r--ospf6d/ospf6_spf.c6
-rw-r--r--ospf6d/ospf6_zebra.c4
-rw-r--r--ospfd/ospf_abr.c6
-rw-r--r--ospfd/ospf_ext.c4
-rw-r--r--ospfd/ospf_lsa.c9
-rw-r--r--ospfd/ospf_opaque.c2
-rw-r--r--ospfd/ospf_ri.c2
-rw-r--r--ospfd/ospf_sr.c8
-rw-r--r--ospfd/ospf_te.c2
-rw-r--r--ospfd/ospf_zebra.c4
-rw-r--r--ospfd/ospfd.c2
-rw-r--r--pimd/pim_bfd.c10
-rw-r--r--pimd/pim_hello.c2
-rw-r--r--pimd/pim_iface.c5
-rw-r--r--pimd/pim_sock.c5
-rw-r--r--pimd/pim_tlv.c21
-rw-r--r--tests/lib/test_srcdest_table.c3
-rw-r--r--tests/subdir.am2
-rw-r--r--tests/topotests/all-protocol-startup/r1/ipv4_routes.ref3
-rw-r--r--tests/topotests/all-protocol-startup/r1/zebra.conf11
-rwxr-xr-xtests/topotests/bgp-basic-functionality-topo1/test_bgp_basic_functionality.py71
-rwxr-xr-xtests/topotests/bgp-ecmp-topo2/test_ebgp_ecmp_topo2.py21
-rwxr-xr-xtests/topotests/bgp-ecmp-topo2/test_ibgp_ecmp_topo2.py12
-rw-r--r--tests/topotests/bgp_as_allow_in/bgp_as_allow_in.json266
-rwxr-xr-xtests/topotests/bgp_as_allow_in/test_bgp_as_allow_in.py975
-rw-r--r--tests/topotests/bgp_communities_topo1/bgp_communities.json175
-rw-r--r--tests/topotests/bgp_communities_topo1/test_bgp_communities.py635
-rw-r--r--tests/topotests/lib/bgp.py527
-rw-r--r--tests/topotests/rip-topo1/r1/rip_status.ref6
-rw-r--r--tests/topotests/rip-topo1/r1/ripd.conf3
-rw-r--r--tests/topotests/rip-topo1/r1/show_ip_rip.ref2
-rw-r--r--tests/topotests/rip-topo1/r1/zebra.conf7
-rw-r--r--tests/topotests/rip-topo1/r2/rip_status.ref1
-rw-r--r--tests/topotests/rip-topo1/r2/show_ip_rip.ref2
-rw-r--r--tests/topotests/rip-topo1/r2/show_ip_route.ref2
-rw-r--r--tests/topotests/rip-topo1/r3/show_ip_rip.ref2
-rw-r--r--tests/topotests/rip-topo1/r3/show_ip_route.ref2
-rwxr-xr-xtests/topotests/rip-topo1/test_rip_topo1.py6
-rw-r--r--tests/topotests/ripng-topo1/r1/ripng_status.ref4
-rw-r--r--tests/topotests/ripng-topo1/r1/ripngd.conf3
-rw-r--r--tests/topotests/ripng-topo1/r1/show_ipv6_ripng.ref4
-rw-r--r--tests/topotests/ripng-topo1/r1/zebra.conf6
-rw-r--r--tests/topotests/ripng-topo1/r2/show_ipv6_ripng.ref4
-rw-r--r--tests/topotests/ripng-topo1/r2/show_ipv6_route.ref2
-rw-r--r--tests/topotests/ripng-topo1/r3/show_ipv6_ripng.ref4
-rw-r--r--tests/topotests/ripng-topo1/r3/show_ipv6_route.ref2
-rwxr-xr-xtests/topotests/ripng-topo1/test_ripng_topo1.py5
-rw-r--r--tools/coccinelle/same_type_casting.cocci7
-rw-r--r--tools/start-stop-daemon.c6
-rw-r--r--vrrpd/vrrp_ndisc.c3
-rw-r--r--yang/embedmodel.py9
-rw-r--r--yang/frr-eigrpd.yang2
-rw-r--r--yang/frr-ripd.yang6
-rw-r--r--yang/frr-ripngd.yang2
-rw-r--r--zebra/redistribute.c110
-rw-r--r--zebra/rt_netlink.c222
-rw-r--r--zebra/zebra_fpm_protobuf.c2
-rw-r--r--zebra/zebra_netns_id.c2
-rw-r--r--zebra/zebra_rib.c2
-rw-r--r--zebra/zebra_vxlan.c10
102 files changed, 3403 insertions, 689 deletions
diff --git a/babeld/net.c b/babeld/net.c
index d1f6a44142..40716a701d 100644
--- a/babeld/net.c
+++ b/babeld/net.c
@@ -144,7 +144,7 @@ babel_send(int s,
iovec[1].iov_base = buf2;
iovec[1].iov_len = buflen2;
memset(&msg, 0, sizeof(msg));
- msg.msg_name = (struct sockaddr*)sin;
+ msg.msg_name = sin;
msg.msg_namelen = slen;
msg.msg_iov = iovec;
msg.msg_iovlen = 2;
diff --git a/bfdd/bfd.c b/bfdd/bfd.c
index 222bf32c94..e1c662941b 100644
--- a/bfdd/bfd.c
+++ b/bfdd/bfd.c
@@ -131,7 +131,7 @@ int bfd_session_enable(struct bfd_session *bs)
if (bs->key.vrfname[0]) {
vrf = vrf_lookup_by_name(bs->key.vrfname);
if (vrf == NULL) {
- log_error(
+ zlog_err(
"session-enable: specified VRF doesn't exists.");
return 0;
}
@@ -143,15 +143,15 @@ int bfd_session_enable(struct bfd_session *bs)
else
ifp = if_lookup_by_name_all_vrf(bs->key.ifname);
if (ifp == NULL) {
- log_error(
- "session-enable: specified interface doesn't exists.");
+ zlog_err(
+ "session-enable: specified interface doesn't exists.");
return 0;
}
if (bs->key.ifname[0] && !vrf) {
vrf = vrf_lookup_by_id(ifp->vrf_id);
if (vrf == NULL) {
- log_error(
- "session-enable: specified VRF doesn't exists.");
+ zlog_err(
+ "session-enable: specified VRF doesn't exists.");
return 0;
}
}
@@ -164,12 +164,12 @@ int bfd_session_enable(struct bfd_session *bs)
assert(bs->vrf);
if (bs->key.ifname[0]
- && BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH) == 0)
+ && CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH) == 0)
bs->ifp = ifp;
/* Sanity check: don't leak open sockets. */
if (bs->sock != -1) {
- log_debug("session-enable: previous socket open");
+ zlog_debug("session-enable: previous socket open");
close(bs->sock);
bs->sock = -1;
}
@@ -179,7 +179,7 @@ int bfd_session_enable(struct bfd_session *bs)
* could use the destination port (3784) for the source
* port we wouldn't need a socket per session.
*/
- if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_IPV6) == 0) {
+ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_IPV6) == 0) {
psock = bp_peer_socket(bs);
if (psock == -1)
return 0;
@@ -287,7 +287,7 @@ void ptm_bfd_echo_stop(struct bfd_session *bfd)
{
bfd->echo_xmt_TO = 0;
bfd->echo_detect_TO = 0;
- BFD_UNSET_FLAG(bfd->flags, BFD_SESS_FLAG_ECHO_ACTIVE);
+ UNSET_FLAG(bfd->flags, BFD_SESS_FLAG_ECHO_ACTIVE);
bfd_echo_xmttimer_delete(bfd);
bfd_echo_recvtimer_delete(bfd);
@@ -318,9 +318,9 @@ void ptm_bfd_sess_up(struct bfd_session *bfd)
if (old_state != bfd->ses_state) {
bfd->stats.session_up++;
- log_info("state-change: [%s] %s -> %s", bs_to_string(bfd),
- state_list[old_state].str,
- state_list[bfd->ses_state].str);
+ zlog_debug("state-change: [%s] %s -> %s", bs_to_string(bfd),
+ state_list[old_state].str,
+ state_list[bfd->ses_state].str);
}
}
@@ -352,15 +352,15 @@ void ptm_bfd_sess_dn(struct bfd_session *bfd, uint8_t diag)
control_notify(bfd, PTM_BFD_DOWN);
/* Stop echo packet transmission if they are active */
- if (BFD_CHECK_FLAG(bfd->flags, BFD_SESS_FLAG_ECHO_ACTIVE))
+ if (CHECK_FLAG(bfd->flags, BFD_SESS_FLAG_ECHO_ACTIVE))
ptm_bfd_echo_stop(bfd);
if (old_state != bfd->ses_state) {
bfd->stats.session_down++;
- log_info("state-change: [%s] %s -> %s reason:%s",
- bs_to_string(bfd), state_list[old_state].str,
- state_list[bfd->ses_state].str,
- get_diag_str(bfd->local_diag));
+ zlog_debug("state-change: [%s] %s -> %s reason:%s",
+ bs_to_string(bfd), state_list[old_state].str,
+ state_list[bfd->ses_state].str,
+ get_diag_str(bfd->local_diag));
}
}
@@ -548,19 +548,19 @@ static void _bfd_session_update(struct bfd_session *bs,
{
if (bpc->bpc_echo) {
/* Check if echo mode is already active. */
- if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO))
+ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO))
goto skip_echo;
- BFD_SET_FLAG(bs->flags, BFD_SESS_FLAG_ECHO);
+ SET_FLAG(bs->flags, BFD_SESS_FLAG_ECHO);
/* Activate/update echo receive timeout timer. */
bs_echo_timer_handler(bs);
} else {
/* Check if echo mode is already disabled. */
- if (!BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO))
+ if (!CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO))
goto skip_echo;
- BFD_UNSET_FLAG(bs->flags, BFD_SESS_FLAG_ECHO);
+ UNSET_FLAG(bs->flags, BFD_SESS_FLAG_ECHO);
ptm_bfd_echo_stop(bs);
}
@@ -582,10 +582,10 @@ skip_echo:
if (bpc->bpc_shutdown) {
/* Check if already shutdown. */
- if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN))
+ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN))
return;
- BFD_SET_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN);
+ SET_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN);
/* Disable all events. */
bfd_recvtimer_delete(bs);
@@ -602,10 +602,10 @@ skip_echo:
ptm_bfd_snd(bs, 0);
} else {
/* Check if already working. */
- if (!BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN))
+ if (!CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN))
return;
- BFD_UNSET_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN);
+ UNSET_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN);
/* Change and notify state change. */
bs->ses_state = PTM_BFD_DOWN;
@@ -616,15 +616,15 @@ skip_echo:
bfd_xmttimer_update(bs, bs->xmt_TO);
}
if (bpc->bpc_cbit) {
- if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_CBIT))
+ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_CBIT))
return;
- BFD_SET_FLAG(bs->flags, BFD_SESS_FLAG_CBIT);
+ SET_FLAG(bs->flags, BFD_SESS_FLAG_CBIT);
} else {
- if (!BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_CBIT))
+ if (!CHECK_FLAG(bs->flags, BFD_SESS_FLAG_CBIT))
return;
- BFD_UNSET_FLAG(bs->flags, BFD_SESS_FLAG_CBIT);
+ UNSET_FLAG(bs->flags, BFD_SESS_FLAG_CBIT);
}
}
@@ -682,7 +682,7 @@ struct bfd_session *ptm_bfd_sess_new(struct bfd_peer_cfg *bpc)
/* Get BFD session storage with its defaults. */
bfd = bfd_session_new();
if (bfd == NULL) {
- log_error("session-new: allocation failed");
+ zlog_err("session-new: allocation failed");
return NULL;
}
@@ -703,7 +703,7 @@ struct bfd_session *ptm_bfd_sess_new(struct bfd_peer_cfg *bpc)
/* Copy remaining data. */
if (bpc->bpc_ipv4 == false)
- BFD_SET_FLAG(bfd->flags, BFD_SESS_FLAG_IPV6);
+ SET_FLAG(bfd->flags, BFD_SESS_FLAG_IPV6);
bfd->key.family = (bpc->bpc_ipv4) ? AF_INET : AF_INET6;
switch (bfd->key.family) {
@@ -727,7 +727,7 @@ struct bfd_session *ptm_bfd_sess_new(struct bfd_peer_cfg *bpc)
}
if (bpc->bpc_mhop)
- BFD_SET_FLAG(bfd->flags, BFD_SESS_FLAG_MH);
+ SET_FLAG(bfd->flags, BFD_SESS_FLAG_MH);
bfd->key.mhop = bpc->bpc_mhop;
@@ -758,7 +758,7 @@ struct bfd_session *bs_registrate(struct bfd_session *bfd)
if (bfd->key.ifname[0] || bfd->key.vrfname[0] || bfd->sock == -1)
bs_observer_add(bfd);
- log_info("session-new: %s", bs_to_string(bfd));
+ zlog_debug("session-new: %s", bs_to_string(bfd));
control_notify_config(BCM_NOTIFY_CONFIG_ADD, bfd);
@@ -776,13 +776,13 @@ int ptm_bfd_sess_del(struct bfd_peer_cfg *bpc)
/* This pointer is being referenced, don't let it be deleted. */
if (bs->refcount > 0) {
- log_error("session-delete: refcount failure: %" PRIu64
- " references",
- bs->refcount);
+ zlog_err("session-delete: refcount failure: %" PRIu64
+ " references",
+ bs->refcount);
return -1;
}
- log_info("session-delete: %s", bs_to_string(bs));
+ zlog_debug("session-delete: %s", bs_to_string(bs));
control_notify_config(BCM_NOTIFY_CONFIG_DELETE, bs);
@@ -849,7 +849,8 @@ static void bs_down_handler(struct bfd_session *bs, int nstate)
break;
default:
- log_debug("state-change: unhandled neighbor state: %d", nstate);
+ zlog_debug("state-change: unhandled neighbor state: %d",
+ nstate);
break;
}
}
@@ -876,7 +877,8 @@ static void bs_init_handler(struct bfd_session *bs, int nstate)
break;
default:
- log_debug("state-change: unhandled neighbor state: %d", nstate);
+ zlog_debug("state-change: unhandled neighbor state: %d",
+ nstate);
break;
}
}
@@ -901,16 +903,16 @@ static void bs_neighbour_admin_down_handler(struct bfd_session *bfd,
control_notify(bfd, PTM_BFD_ADM_DOWN);
/* Stop echo packet transmission if they are active */
- if (BFD_CHECK_FLAG(bfd->flags, BFD_SESS_FLAG_ECHO_ACTIVE))
+ if (CHECK_FLAG(bfd->flags, BFD_SESS_FLAG_ECHO_ACTIVE))
ptm_bfd_echo_stop(bfd);
if (old_state != bfd->ses_state) {
bfd->stats.session_down++;
- log_info("state-change: [%s] %s -> %s reason:%s",
- bs_to_string(bfd), state_list[old_state].str,
- state_list[bfd->ses_state].str,
- get_diag_str(bfd->local_diag));
+ zlog_debug("state-change: [%s] %s -> %s reason:%s",
+ bs_to_string(bfd), state_list[old_state].str,
+ state_list[bfd->ses_state].str,
+ get_diag_str(bfd->local_diag));
}
}
@@ -932,7 +934,8 @@ static void bs_up_handler(struct bfd_session *bs, int nstate)
break;
default:
- log_debug("state-change: unhandled neighbor state: %d", nstate);
+ zlog_debug("state-change: unhandled neighbor state: %d",
+ nstate);
break;
}
}
@@ -954,8 +957,8 @@ void bs_state_handler(struct bfd_session *bs, int nstate)
break;
default:
- log_debug("state-change: [%s] is in invalid state: %d",
- bs_to_string(bs), nstate);
+ zlog_debug("state-change: [%s] is in invalid state: %d",
+ bs_to_string(bs), nstate);
break;
}
}
@@ -976,14 +979,14 @@ void bs_echo_timer_handler(struct bfd_session *bs)
* Section 3).
* - Check that we are already at the up state.
*/
- if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO) == 0
- || BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH)
+ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO) == 0
+ || CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH)
|| bs->ses_state != PTM_BFD_UP)
return;
/* Remote peer asked to stop echo. */
if (bs->remote_timers.required_min_echo == 0) {
- if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO_ACTIVE))
+ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO_ACTIVE))
ptm_bfd_echo_stop(bs);
return;
@@ -1002,7 +1005,7 @@ void bs_echo_timer_handler(struct bfd_session *bs)
else
bs->echo_xmt_TO = bs->timers.required_min_echo;
- if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO_ACTIVE) == 0
+ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO_ACTIVE) == 0
|| old_timer != bs->echo_xmt_TO)
ptm_bfd_echo_start(bs);
}
@@ -1032,20 +1035,19 @@ void bs_final_handler(struct bfd_session *bs)
}
/*
- * Calculate detection time based on new timers.
+ * Calculate transmission time based on new timers.
*
* Transmission calculation:
- * We must respect the RequiredMinRxInterval from the remote
- * system: if our desired transmission timer is more than the
- * minimum receive rate, then we must lower it to at least the
- * minimum receive interval.
+ * Unless specified by exceptions at the end of Section 6.8.7, the
+ * transmission time will be determined by the system with the
+ * slowest rate.
*
- * RFC 5880, Section 6.8.3.
+ * RFC 5880, Section 6.8.7.
*/
if (bs->timers.desired_min_tx > bs->remote_timers.required_min_rx)
- bs->xmt_TO = bs->remote_timers.required_min_rx;
- else
bs->xmt_TO = bs->timers.desired_min_tx;
+ else
+ bs->xmt_TO = bs->remote_timers.required_min_rx;
/* Apply new transmission timer immediately. */
ptm_bfd_start_xmt_timer(bs, false);
@@ -1241,7 +1243,7 @@ const char *bs_to_string(const struct bfd_session *bs)
static char buf[256];
char addr_buf[INET6_ADDRSTRLEN];
int pos;
- bool is_mhop = BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH);
+ bool is_mhop = CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH);
pos = snprintf(buf, sizeof(buf), "mhop:%s", is_mhop ? "yes" : "no");
pos += snprintf(buf + pos, sizeof(buf) - pos, " peer:%s",
@@ -1435,8 +1437,8 @@ struct bfd_session *bfd_key_lookup(struct bfd_key key)
inet_ntop(bs.key.family, &key.local, addr_buf,
sizeof(addr_buf));
- log_debug(" peer %s found, but loc-addr %s ignored",
- peer_buf, addr_buf);
+ zlog_debug(" peer %s found, but loc-addr %s ignored",
+ peer_buf, addr_buf);
return bsp;
}
}
@@ -1447,8 +1449,8 @@ struct bfd_session *bfd_key_lookup(struct bfd_key key)
memset(bs.key.ifname, 0, sizeof(bs.key.ifname));
bsp = hash_lookup(bfd_key_hash, &bs);
if (bsp) {
- log_debug(" peer %s found, but ifp %s ignored",
- peer_buf, key.ifname);
+ zlog_debug(" peer %s found, but ifp %s ignored",
+ peer_buf, key.ifname);
return bsp;
}
}
@@ -1462,10 +1464,10 @@ struct bfd_session *bfd_key_lookup(struct bfd_key key)
inet_ntop(bs.key.family, &bs.key.local, addr_buf,
sizeof(addr_buf));
- log_debug(" peer %s found, but ifp %s"
- " and loc-addr %s ignored",
- peer_buf, key.ifname,
- addr_buf);
+ zlog_debug(
+ " peer %s found, but ifp %s"
+ " and loc-addr %s ignored",
+ peer_buf, key.ifname, addr_buf);
return bsp;
}
}
@@ -1483,8 +1485,10 @@ struct bfd_session *bfd_key_lookup(struct bfd_key key)
/* change key */
if (ctx.result) {
bsp = ctx.result;
- log_debug(" peer %s found, but ifp"
- " and/or loc-addr params ignored", peer_buf);
+ zlog_debug(
+ " peer %s found, but ifp"
+ " and/or loc-addr params ignored",
+ peer_buf);
}
return bsp;
}
@@ -1644,11 +1648,11 @@ static void _bfd_session_remove_manual(struct hash_bucket *hb,
struct bfd_session *bs = hb->data;
/* Delete only manually configured sessions. */
- if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG) == 0)
+ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG) == 0)
return;
bs->refcount--;
- BFD_UNSET_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG);
+ UNSET_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG);
/* Don't delete sessions still in use. */
if (bs->refcount != 0)
@@ -1672,13 +1676,13 @@ void bfd_sessions_remove_manual(void)
*/
static int bfd_vrf_new(struct vrf *vrf)
{
- log_debug("VRF Created: %s(%u)", vrf->name, vrf->vrf_id);
+ zlog_debug("VRF Created: %s(%u)", vrf->name, vrf->vrf_id);
return 0;
}
static int bfd_vrf_delete(struct vrf *vrf)
{
- log_debug("VRF Deletion: %s(%u)", vrf->name, vrf->vrf_id);
+ zlog_debug("VRF Deletion: %s(%u)", vrf->name, vrf->vrf_id);
return 0;
}
@@ -1686,7 +1690,7 @@ static int bfd_vrf_update(struct vrf *vrf)
{
if (!vrf_is_enabled(vrf))
return 0;
- log_debug("VRF update: %s(%u)", vrf->name, vrf->vrf_id);
+ zlog_debug("VRF update: %s(%u)", vrf->name, vrf->vrf_id);
/* a different name is given; update bfd list */
bfdd_sessions_enable_vrf(vrf);
return 0;
@@ -1703,7 +1707,7 @@ static int bfd_vrf_enable(struct vrf *vrf)
vrf->info = (void *)bvrf;
} else
bvrf = vrf->info;
- log_debug("VRF enable add %s id %u", vrf->name, vrf->vrf_id);
+ zlog_debug("VRF enable add %s id %u", vrf->name, vrf->vrf_id);
if (vrf->vrf_id == VRF_DEFAULT ||
vrf_get_backend() == VRF_BACKEND_NETNS) {
if (!bvrf->bg_shop)
@@ -1759,7 +1763,7 @@ static int bfd_vrf_disable(struct vrf *vrf)
bfdd_zclient_unregister(vrf->vrf_id);
}
- log_debug("VRF disable %s id %d", vrf->name, vrf->vrf_id);
+ zlog_debug("VRF disable %s id %d", vrf->name, vrf->vrf_id);
/* Disable read/write poll triggering. */
THREAD_OFF(bvrf->bg_ev[0]);
diff --git a/bfdd/bfd.h b/bfdd/bfd.h
index 2ae74d7880..a786bb71bc 100644
--- a/bfdd/bfd.h
+++ b/bfdd/bfd.h
@@ -172,10 +172,6 @@ enum bfd_session_flags {
BFD_SESS_FLAG_CBIT = 1 << 9, /* CBIT is set */
};
-#define BFD_SET_FLAG(field, flag) (field |= flag)
-#define BFD_UNSET_FLAG(field, flag) (field &= ~flag)
-#define BFD_CHECK_FLAG(field, flag) (field & flag)
-
/* BFD session hash keys */
struct bfd_key {
uint16_t family;
@@ -429,15 +425,9 @@ void pl_free(struct peer_label *pl);
/*
* logging - alias to zebra log
*/
-
-#define log_debug zlog_debug
-#define log_info zlog_info
-#define log_warning zlog_warn
-#define log_error zlog_err
-
-#define log_fatal(msg, ...) \
+#define zlog_fatal(msg, ...) \
do { \
- zlog_err(msg, ## __VA_ARGS__); \
+ zlog_err(msg, ##__VA_ARGS__); \
assert(!msg); \
abort(); \
} while (0)
diff --git a/bfdd/bfd_packet.c b/bfdd/bfd_packet.c
index 12e508c601..79971fb3e2 100644
--- a/bfdd/bfd_packet.c
+++ b/bfdd/bfd_packet.c
@@ -76,7 +76,7 @@ int _ptm_bfd_send(struct bfd_session *bs, uint16_t *port, const void *data,
ssize_t rv;
int sd = -1;
- if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_IPV6)) {
+ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_IPV6)) {
memset(&sin6, 0, sizeof(sin6));
sin6.sin6_family = AF_INET6;
memcpy(&sin6.sin6_addr, &bs->key.peer, sizeof(sin6.sin6_addr));
@@ -85,7 +85,7 @@ int _ptm_bfd_send(struct bfd_session *bs, uint16_t *port, const void *data,
sin6.sin6_port =
(port) ? *port
- : (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH))
+ : (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH))
? htons(BFD_DEF_MHOP_DEST_PORT)
: htons(BFD_DEFDESTPORT);
@@ -98,7 +98,7 @@ int _ptm_bfd_send(struct bfd_session *bs, uint16_t *port, const void *data,
memcpy(&sin.sin_addr, &bs->key.peer, sizeof(sin.sin_addr));
sin.sin_port =
(port) ? *port
- : (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH))
+ : (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH))
? htons(BFD_DEF_MHOP_DEST_PORT)
: htons(BFD_DEFDESTPORT);
@@ -112,11 +112,11 @@ int _ptm_bfd_send(struct bfd_session *bs, uint16_t *port, const void *data,
#endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
rv = sendto(sd, data, datalen, 0, sa, slen);
if (rv <= 0) {
- log_debug("packet-send: send failure: %s", strerror(errno));
+ zlog_debug("packet-send: send failure: %s", strerror(errno));
return -1;
}
if (rv < (ssize_t)datalen)
- log_debug("packet-send: send partial: %s", strerror(errno));
+ zlog_debug("packet-send: send partial: %s", strerror(errno));
return 0;
}
@@ -133,15 +133,15 @@ void ptm_bfd_echo_snd(struct bfd_session *bfd)
if (!bvrf)
return;
- if (!BFD_CHECK_FLAG(bfd->flags, BFD_SESS_FLAG_ECHO_ACTIVE))
- BFD_SET_FLAG(bfd->flags, BFD_SESS_FLAG_ECHO_ACTIVE);
+ if (!CHECK_FLAG(bfd->flags, BFD_SESS_FLAG_ECHO_ACTIVE))
+ SET_FLAG(bfd->flags, BFD_SESS_FLAG_ECHO_ACTIVE);
memset(&bep, 0, sizeof(bep));
bep.ver = BFD_ECHO_VERSION;
bep.len = BFD_ECHO_PKT_LEN;
bep.my_discr = htonl(bfd->discrs.my_discr);
- if (BFD_CHECK_FLAG(bfd->flags, BFD_SESS_FLAG_IPV6)) {
+ if (CHECK_FLAG(bfd->flags, BFD_SESS_FLAG_IPV6)) {
sd = bvrf->bg_echov6;
memset(&sin6, 0, sizeof(sin6));
sin6.sin6_family = AF_INET6;
@@ -190,13 +190,14 @@ static int ptm_bfd_process_echo_pkt(struct bfd_vrf_global *bvrf, int s)
/* Your discriminator not zero - use it to find session */
bfd = bfd_id_lookup(my_discr);
if (bfd == NULL) {
- log_debug("echo-packet: no matching session (id:%u)", my_discr);
+ zlog_debug("echo-packet: no matching session (id:%u)",
+ my_discr);
return -1;
}
- if (!BFD_CHECK_FLAG(bfd->flags, BFD_SESS_FLAG_ECHO_ACTIVE)) {
- log_debug("echo-packet: echo disabled [%s] (id:%u)",
- bs_to_string(bfd), my_discr);
+ if (!CHECK_FLAG(bfd->flags, BFD_SESS_FLAG_ECHO_ACTIVE)) {
+ zlog_debug("echo-packet: echo disabled [%s] (id:%u)",
+ bs_to_string(bfd), my_discr);
return -1;
}
@@ -214,7 +215,7 @@ static int ptm_bfd_process_echo_pkt(struct bfd_vrf_global *bvrf, int s)
void ptm_bfd_snd(struct bfd_session *bfd, int fbit)
{
- struct bfd_pkt cp;
+ struct bfd_pkt cp = {};
/* Set fields according to section 6.5.7 */
cp.diag = bfd->local_diag;
@@ -222,7 +223,7 @@ void ptm_bfd_snd(struct bfd_session *bfd, int fbit)
cp.flags = 0;
BFD_SETSTATE(cp.flags, bfd->ses_state);
- if (BFD_CHECK_FLAG(bfd->flags, BFD_SESS_FLAG_CBIT))
+ if (CHECK_FLAG(bfd->flags, BFD_SESS_FLAG_CBIT))
BFD_SETCBIT(cp.flags, BFD_CBIT);
BFD_SETDEMANDBIT(cp.flags, BFD_DEF_DEMAND);
@@ -291,8 +292,7 @@ ssize_t bfd_recv_ipv4(int sd, uint8_t *msgbuf, size_t msgbuflen, uint8_t *ttl,
mlen = recvmsg(sd, &msghdr, MSG_DONTWAIT);
if (mlen == -1) {
if (errno != EAGAIN)
- log_error("ipv4-recv: recv failed: %s",
- strerror(errno));
+ zlog_err("ipv4-recv: recv failed: %s", strerror(errno));
return -1;
}
@@ -313,7 +313,8 @@ ssize_t bfd_recv_ipv4(int sd, uint8_t *msgbuf, size_t msgbuflen, uint8_t *ttl,
memcpy(&ttlval, CMSG_DATA(cm), sizeof(ttlval));
if (ttlval > 255) {
- log_debug("ipv4-recv: invalid TTL: %u", ttlval);
+ zlog_debug("ipv4-recv: invalid TTL: %u",
+ ttlval);
return -1;
}
*ttl = ttlval;
@@ -402,8 +403,7 @@ ssize_t bfd_recv_ipv6(int sd, uint8_t *msgbuf, size_t msgbuflen, uint8_t *ttl,
mlen = recvmsg(sd, &msghdr6, MSG_DONTWAIT);
if (mlen == -1) {
if (errno != EAGAIN)
- log_error("ipv6-recv: recv failed: %s",
- strerror(errno));
+ zlog_err("ipv6-recv: recv failed: %s", strerror(errno));
return -1;
}
@@ -420,7 +420,8 @@ ssize_t bfd_recv_ipv6(int sd, uint8_t *msgbuf, size_t msgbuflen, uint8_t *ttl,
if (cm->cmsg_type == IPV6_HOPLIMIT) {
memcpy(&ttlval, CMSG_DATA(cm), sizeof(ttlval));
if (ttlval > 255) {
- log_debug("ipv6-recv: invalid TTL: %u", ttlval);
+ zlog_debug("ipv6-recv: invalid TTL: %u",
+ ttlval);
return -1;
}
@@ -511,8 +512,8 @@ static void cp_debug(bool mhop, struct sockaddr_any *peer,
vsnprintf(buf, sizeof(buf), fmt, vl);
va_end(vl);
- log_debug("control-packet: %s [mhop:%s%s%s%s%s]", buf,
- mhop ? "yes" : "no", peerstr, localstr, portstr, vrfstr);
+ zlog_debug("control-packet: %s [mhop:%s%s%s%s%s]", buf,
+ mhop ? "yes" : "no", peerstr, localstr, portstr, vrfstr);
}
int bfd_recv_cb(struct thread *t)
@@ -796,11 +797,12 @@ int bp_udp_send(int sd, uint8_t ttl, uint8_t *data, size_t datalen,
/* Send echo back. */
wlen = sendmsg(sd, &msg, 0);
if (wlen <= 0) {
- log_debug("udp-send: loopback failure: (%d) %s", errno, strerror(errno));
+ zlog_debug("udp-send: loopback failure: (%d) %s", errno,
+ strerror(errno));
return -1;
} else if (wlen < (ssize_t)datalen) {
- log_debug("udp-send: partial send: %zd expected %zu", wlen,
- datalen);
+ zlog_debug("udp-send: partial send: %zd expected %zu", wlen,
+ datalen);
return -1;
}
@@ -821,8 +823,8 @@ int bp_set_ttl(int sd, uint8_t value)
int ttl = value;
if (setsockopt(sd, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl)) == -1) {
- log_warning("set-ttl: setsockopt(IP_TTL, %d): %s", value,
- strerror(errno));
+ zlog_warn("set-ttl: setsockopt(IP_TTL, %d): %s", value,
+ strerror(errno));
return -1;
}
@@ -834,8 +836,8 @@ int bp_set_tos(int sd, uint8_t value)
int tos = value;
if (setsockopt(sd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) == -1) {
- log_warning("set-tos: setsockopt(IP_TOS, %d): %s", value,
- strerror(errno));
+ zlog_warn("set-tos: setsockopt(IP_TOS, %d): %s", value,
+ strerror(errno));
return -1;
}
@@ -847,12 +849,12 @@ static void bp_set_ipopts(int sd)
int rcvttl = BFD_RCV_TTL_VAL;
if (bp_set_ttl(sd, BFD_TTL_VAL) != 0)
- log_fatal("set-ipopts: TTL configuration failed");
+ zlog_fatal("set-ipopts: TTL configuration failed");
if (setsockopt(sd, IPPROTO_IP, IP_RECVTTL, &rcvttl, sizeof(rcvttl))
== -1)
- log_fatal("set-ipopts: setsockopt(IP_RECVTTL, %d): %s", rcvttl,
- strerror(errno));
+ zlog_fatal("set-ipopts: setsockopt(IP_RECVTTL, %d): %s", rcvttl,
+ strerror(errno));
#ifdef BFD_LINUX
int pktinfo = BFD_PKT_INFO_VAL;
@@ -860,21 +862,21 @@ static void bp_set_ipopts(int sd)
/* Figure out address and interface to do the peer matching. */
if (setsockopt(sd, IPPROTO_IP, IP_PKTINFO, &pktinfo, sizeof(pktinfo))
== -1)
- log_fatal("set-ipopts: setsockopt(IP_PKTINFO, %d): %s", pktinfo,
- strerror(errno));
+ zlog_fatal("set-ipopts: setsockopt(IP_PKTINFO, %d): %s",
+ pktinfo, strerror(errno));
#endif /* BFD_LINUX */
#ifdef BFD_BSD
int yes = 1;
/* Find out our address for peer matching. */
if (setsockopt(sd, IPPROTO_IP, IP_RECVDSTADDR, &yes, sizeof(yes)) == -1)
- log_fatal("set-ipopts: setsockopt(IP_RECVDSTADDR, %d): %s", yes,
- strerror(errno));
+ zlog_fatal("set-ipopts: setsockopt(IP_RECVDSTADDR, %d): %s",
+ yes, strerror(errno));
/* Find out interface where the packet came in. */
if (setsockopt_ifindex(AF_INET, sd, yes) == -1)
- log_fatal("set-ipopts: setsockopt_ipv4_ifindex(%d): %s", yes,
- strerror(errno));
+ zlog_fatal("set-ipopts: setsockopt_ipv4_ifindex(%d): %s", yes,
+ strerror(errno));
#endif /* BFD_BSD */
}
@@ -887,7 +889,7 @@ static void bp_bind_ip(int sd, uint16_t port)
sin.sin_addr.s_addr = htonl(INADDR_ANY);
sin.sin_port = htons(port);
if (bind(sd, (struct sockaddr *)&sin, sizeof(sin)) == -1)
- log_fatal("bind-ip: bind: %s", strerror(errno));
+ zlog_fatal("bind-ip: bind: %s", strerror(errno));
}
int bp_udp_shop(const struct vrf *vrf)
@@ -899,7 +901,7 @@ int bp_udp_shop(const struct vrf *vrf)
vrf->name);
}
if (sd == -1)
- log_fatal("udp-shop: socket: %s", strerror(errno));
+ zlog_fatal("udp-shop: socket: %s", strerror(errno));
bp_set_ipopts(sd);
bp_bind_ip(sd, BFD_DEFDESTPORT);
@@ -915,7 +917,7 @@ int bp_udp_mhop(const struct vrf *vrf)
vrf->name);
}
if (sd == -1)
- log_fatal("udp-mhop: socket: %s", strerror(errno));
+ zlog_fatal("udp-mhop: socket: %s", strerror(errno));
bp_set_ipopts(sd);
bp_bind_ip(sd, BFD_DEF_MHOP_DEST_PORT);
@@ -932,7 +934,7 @@ int bp_peer_socket(const struct bfd_session *bs)
if (bs->key.ifname[0])
device_to_bind = (const char *)bs->key.ifname;
- else if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH)
+ else if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH)
&& bs->key.vrfname[0])
device_to_bind = (const char *)bs->key.vrfname;
@@ -941,8 +943,8 @@ int bp_peer_socket(const struct bfd_session *bs)
bs->vrf->vrf_id, device_to_bind);
}
if (sd == -1) {
- log_error("ipv4-new: failed to create socket: %s",
- strerror(errno));
+ zlog_err("ipv4-new: failed to create socket: %s",
+ strerror(errno));
return -1;
}
@@ -965,15 +967,15 @@ int bp_peer_socket(const struct bfd_session *bs)
sin.sin_len = sizeof(sin);
#endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
memcpy(&sin.sin_addr, &bs->key.local, sizeof(sin.sin_addr));
- if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH) == 0)
+ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH) == 0)
sin.sin_addr.s_addr = INADDR_ANY;
pcount = 0;
do {
if ((++pcount) > (BFD_SRCPORTMAX - BFD_SRCPORTINIT)) {
/* Searched all ports, none available */
- log_error("ipv4-new: failed to bind port: %s",
- strerror(errno));
+ zlog_err("ipv4-new: failed to bind port: %s",
+ strerror(errno));
close(sd);
return -1;
}
@@ -999,7 +1001,7 @@ int bp_peer_socketv6(const struct bfd_session *bs)
if (bs->key.ifname[0])
device_to_bind = (const char *)bs->key.ifname;
- else if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH)
+ else if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH)
&& bs->key.vrfname[0])
device_to_bind = (const char *)bs->key.vrfname;
@@ -1008,8 +1010,8 @@ int bp_peer_socketv6(const struct bfd_session *bs)
bs->vrf->vrf_id, device_to_bind);
}
if (sd == -1) {
- log_error("ipv6-new: failed to create socket: %s",
- strerror(errno));
+ zlog_err("ipv6-new: failed to create socket: %s",
+ strerror(errno));
return -1;
}
@@ -1039,8 +1041,8 @@ int bp_peer_socketv6(const struct bfd_session *bs)
do {
if ((++pcount) > (BFD_SRCPORTMAX - BFD_SRCPORTINIT)) {
/* Searched all ports, none available */
- log_error("ipv6-new: failed to bind port: %s",
- strerror(errno));
+ zlog_err("ipv6-new: failed to bind port: %s",
+ strerror(errno));
close(sd);
return -1;
}
@@ -1058,8 +1060,8 @@ int bp_set_ttlv6(int sd, uint8_t value)
if (setsockopt(sd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof(ttl))
== -1) {
- log_warning("set-ttlv6: setsockopt(IPV6_UNICAST_HOPS, %d): %s",
- value, strerror(errno));
+ zlog_warn("set-ttlv6: setsockopt(IPV6_UNICAST_HOPS, %d): %s",
+ value, strerror(errno));
return -1;
}
@@ -1072,8 +1074,8 @@ int bp_set_tosv6(int sd, uint8_t value)
if (setsockopt(sd, IPPROTO_IPV6, IPV6_TCLASS, &tos, sizeof(tos))
== -1) {
- log_warning("set-tosv6: setsockopt(IPV6_TCLASS, %d): %s", value,
- strerror(errno));
+ zlog_warn("set-tosv6: setsockopt(IPV6_TCLASS, %d): %s", value,
+ strerror(errno));
return -1;
}
@@ -1086,22 +1088,23 @@ static void bp_set_ipv6opts(int sd)
int ipv6_only = BFD_IPV6_ONLY_VAL;
if (bp_set_ttlv6(sd, BFD_TTL_VAL) == -1)
- log_fatal("set-ipv6opts: setsockopt(IPV6_UNICAST_HOPS, %d): %s",
- BFD_TTL_VAL, strerror(errno));
+ zlog_fatal(
+ "set-ipv6opts: setsockopt(IPV6_UNICAST_HOPS, %d): %s",
+ BFD_TTL_VAL, strerror(errno));
if (setsockopt_ipv6_hoplimit(sd, BFD_RCV_TTL_VAL) == -1)
- log_fatal("set-ipv6opts: setsockopt(IPV6_HOPLIMIT, %d): %s",
- BFD_RCV_TTL_VAL, strerror(errno));
+ zlog_fatal("set-ipv6opts: setsockopt(IPV6_HOPLIMIT, %d): %s",
+ BFD_RCV_TTL_VAL, strerror(errno));
if (setsockopt_ipv6_pktinfo(sd, ipv6_pktinfo) == -1)
- log_fatal("set-ipv6opts: setsockopt(IPV6_PKTINFO, %d): %s",
- ipv6_pktinfo, strerror(errno));
+ zlog_fatal("set-ipv6opts: setsockopt(IPV6_PKTINFO, %d): %s",
+ ipv6_pktinfo, strerror(errno));
if (setsockopt(sd, IPPROTO_IPV6, IPV6_V6ONLY, &ipv6_only,
sizeof(ipv6_only))
== -1)
- log_fatal("set-ipv6opts: setsockopt(IPV6_V6ONLY, %d): %s",
- ipv6_only, strerror(errno));
+ zlog_fatal("set-ipv6opts: setsockopt(IPV6_V6ONLY, %d): %s",
+ ipv6_only, strerror(errno));
}
static void bp_bind_ipv6(int sd, uint16_t port)
@@ -1116,7 +1119,7 @@ static void bp_bind_ipv6(int sd, uint16_t port)
sin6.sin6_len = sizeof(sin6);
#endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
if (bind(sd, (struct sockaddr *)&sin6, sizeof(sin6)) == -1)
- log_fatal("bind-ipv6: bind: %s", strerror(errno));
+ zlog_fatal("bind-ipv6: bind: %s", strerror(errno));
}
int bp_udp6_shop(const struct vrf *vrf)
@@ -1128,7 +1131,7 @@ int bp_udp6_shop(const struct vrf *vrf)
vrf->name);
}
if (sd == -1)
- log_fatal("udp6-shop: socket: %s", strerror(errno));
+ zlog_fatal("udp6-shop: socket: %s", strerror(errno));
bp_set_ipv6opts(sd);
bp_bind_ipv6(sd, BFD_DEFDESTPORT);
@@ -1145,7 +1148,7 @@ int bp_udp6_mhop(const struct vrf *vrf)
vrf->name);
}
if (sd == -1)
- log_fatal("udp6-mhop: socket: %s", strerror(errno));
+ zlog_fatal("udp6-mhop: socket: %s", strerror(errno));
bp_set_ipv6opts(sd);
bp_bind_ipv6(sd, BFD_DEF_MHOP_DEST_PORT);
@@ -1161,7 +1164,7 @@ int bp_echo_socket(const struct vrf *vrf)
s = vrf_socket(AF_INET, SOCK_DGRAM, 0, vrf->vrf_id, vrf->name);
}
if (s == -1)
- log_fatal("echo-socket: socket: %s", strerror(errno));
+ zlog_fatal("echo-socket: socket: %s", strerror(errno));
bp_set_ipopts(s);
bp_bind_ip(s, BFD_DEF_ECHO_PORT);
@@ -1177,7 +1180,7 @@ int bp_echov6_socket(const struct vrf *vrf)
s = vrf_socket(AF_INET6, SOCK_DGRAM, 0, vrf->vrf_id, vrf->name);
}
if (s == -1)
- log_fatal("echov6-socket: socket: %s", strerror(errno));
+ zlog_fatal("echov6-socket: socket: %s", strerror(errno));
bp_set_ipv6opts(s);
bp_bind_ipv6(s, BFD_DEF_ECHO_PORT);
diff --git a/bfdd/bfdd.c b/bfdd/bfdd.c
index 69f268ab01..bed6ccd142 100644
--- a/bfdd/bfdd.c
+++ b/bfdd/bfdd.c
@@ -49,8 +49,8 @@ void socket_close(int *s)
return;
if (close(*s) != 0)
- log_error("%s: close(%d): (%d) %s", __func__, *s, errno,
- strerror(errno));
+ zlog_err("%s: close(%d): (%d) %s", __func__, *s, errno,
+ strerror(errno));
*s = -1;
}
diff --git a/bfdd/bfdd_nb_config.c b/bfdd/bfdd_nb_config.c
index 48dcce3ddf..c1123c4c33 100644
--- a/bfdd/bfdd_nb_config.c
+++ b/bfdd/bfdd_nb_config.c
@@ -99,7 +99,7 @@ static int bfd_session_create(enum nb_event event, const struct lyd_node *dnode,
/* This session was already configured by another daemon. */
if (bs != NULL) {
/* Now it is configured also by CLI. */
- BFD_SET_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG);
+ SET_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG);
bs->refcount++;
resource->ptr = bs;
@@ -115,11 +115,11 @@ static int bfd_session_create(enum nb_event event, const struct lyd_node *dnode,
/* Set configuration flags. */
bs->refcount = 1;
- BFD_SET_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG);
+ SET_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG);
if (mhop)
- BFD_SET_FLAG(bs->flags, BFD_SESS_FLAG_MH);
+ SET_FLAG(bs->flags, BFD_SESS_FLAG_MH);
if (bs->key.family == AF_INET6)
- BFD_SET_FLAG(bs->flags, BFD_SESS_FLAG_IPV6);
+ SET_FLAG(bs->flags, BFD_SESS_FLAG_IPV6);
resource->ptr = bs;
break;
@@ -164,10 +164,10 @@ static int bfd_session_destroy(enum nb_event event,
case NB_EV_APPLY:
bs = nb_running_unset_entry(dnode);
/* CLI is not using this session anymore. */
- if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG) == 0)
+ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG) == 0)
break;
- BFD_UNSET_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG);
+ UNSET_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG);
bs->refcount--;
/* There are still daemons using it. */
if (bs->refcount > 0)
@@ -384,10 +384,10 @@ int bfdd_bfd_sessions_single_hop_administrative_down_modify(
bs = nb_running_get_entry(dnode, NULL, true);
if (!shutdown) {
- if (!BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN))
+ if (!CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN))
return NB_OK;
- BFD_UNSET_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN);
+ UNSET_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN);
/* Change and notify state change. */
bs->ses_state = PTM_BFD_DOWN;
@@ -396,15 +396,15 @@ int bfdd_bfd_sessions_single_hop_administrative_down_modify(
/* Enable all timers. */
bfd_recvtimer_update(bs);
bfd_xmttimer_update(bs, bs->xmt_TO);
- if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO)) {
+ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO)) {
bfd_echo_recvtimer_update(bs);
bfd_echo_xmttimer_update(bs, bs->echo_xmt_TO);
}
} else {
- if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN))
+ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN))
return NB_OK;
- BFD_SET_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN);
+ SET_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN);
/* Disable all events. */
bfd_recvtimer_delete(bs);
@@ -448,18 +448,18 @@ int bfdd_bfd_sessions_single_hop_echo_mode_modify(enum nb_event event,
bs = nb_running_get_entry(dnode, NULL, true);
if (!echo) {
- if (!BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO))
+ if (!CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO))
return NB_OK;
- BFD_UNSET_FLAG(bs->flags, BFD_SESS_FLAG_ECHO);
+ UNSET_FLAG(bs->flags, BFD_SESS_FLAG_ECHO);
ptm_bfd_echo_stop(bs);
} else {
- if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO))
+ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO))
return NB_OK;
- BFD_SET_FLAG(bs->flags, BFD_SESS_FLAG_ECHO);
+ SET_FLAG(bs->flags, BFD_SESS_FLAG_ECHO);
/* Apply setting immediately. */
- if (!BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN))
+ if (!CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN))
bs_echo_timer_handler(bs);
}
diff --git a/bfdd/bfdd_nb_state.c b/bfdd/bfdd_nb_state.c
index dfca3d1417..2a44d46c41 100644
--- a/bfdd/bfdd_nb_state.c
+++ b/bfdd/bfdd_nb_state.c
@@ -211,7 +211,7 @@ struct yang_data *bfdd_bfd_sessions_single_hop_stats_detection_mode_get_elem(
*
* TODO: support demand mode.
*/
- if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO))
+ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO))
detection_mode = 1;
else
detection_mode = 2;
diff --git a/bfdd/bfdd_vty.c b/bfdd/bfdd_vty.c
index 2a98b0fb02..74ffd6d625 100644
--- a/bfdd/bfdd_vty.c
+++ b/bfdd/bfdd_vty.c
@@ -84,7 +84,7 @@ static void _display_peer_header(struct vty *vty, struct bfd_session *bs)
inet_ntop(bs->key.family, &bs->key.peer, addr_buf,
sizeof(addr_buf)));
- if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH))
+ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH))
vty_out(vty, " multihop");
if (memcmp(&bs->key.local, &zero_addr, sizeof(bs->key.local)))
@@ -143,7 +143,7 @@ static void _display_peer(struct vty *vty, struct bfd_session *bs)
vty_out(vty, "\t\tDiagnostics: %s\n", diag2str(bs->local_diag));
vty_out(vty, "\t\tRemote diagnostics: %s\n", diag2str(bs->remote_diag));
vty_out(vty, "\t\tPeer Type: %s\n",
- BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG) ? "configured" : "dynamic");
+ CHECK_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG) ? "configured" : "dynamic");
vty_out(vty, "\t\tLocal timers:\n");
vty_out(vty, "\t\t\tDetect-multiplier: %" PRIu32 "\n",
@@ -235,7 +235,7 @@ static struct json_object *__display_peer_json(struct bfd_session *bs)
bs->timers.required_min_rx / 1000);
json_object_int_add(jo, "transmit-interval",
bs->timers.desired_min_tx / 1000);
- if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO))
+ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO))
json_object_int_add(jo, "echo-interval",
bs->timers.required_min_echo / 1000);
else
@@ -305,7 +305,7 @@ static void _display_peer_json_iter(struct hash_bucket *hb, void *arg)
jon = __display_peer_json(bs);
if (jon == NULL) {
- log_warning("%s: not enough memory", __func__);
+ zlog_warn("%s: not enough memory", __func__);
return;
}
@@ -415,7 +415,7 @@ static void _display_peer_counter_json_iter(struct hash_bucket *hb, void *arg)
jon = __display_peer_counters_json(bs);
if (jon == NULL) {
- log_warning("%s: not enough memory", __func__);
+ zlog_warn("%s: not enough memory", __func__);
return;
}
@@ -457,7 +457,7 @@ static void _display_peer_brief(struct vty *vty, struct bfd_session *bs)
{
char addr_buf[INET6_ADDRSTRLEN];
- if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH)) {
+ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH)) {
vty_out(vty, "%-10u", bs->discrs.my_discr);
inet_ntop(bs->key.family, &bs->key.local, addr_buf, sizeof(addr_buf));
vty_out(vty, " %-40s", addr_buf);
diff --git a/bfdd/config.c b/bfdd/config.c
index 4ae7bfdc08..b71670f012 100644
--- a/bfdd/config.c
+++ b/bfdd/config.c
@@ -92,8 +92,8 @@ static int parse_config_json(struct json_object *jo, bpc_handle h, void *arg)
error += parse_list(jo_val, PLT_LABEL, h, arg);
} else {
sval = json_object_get_string(jo_val);
- log_warning("%s:%d invalid configuration: %s", __func__,
- __LINE__, sval);
+ zlog_warn("%s:%d invalid configuration: %s", __func__,
+ __LINE__, sval);
error++;
}
}
@@ -139,15 +139,15 @@ static int parse_list(struct json_object *jo, enum peer_list_type plt,
switch (plt) {
case PLT_IPV4:
- log_debug("ipv4 peers %d:", allen);
+ zlog_debug("ipv4 peers %d:", allen);
bpc.bpc_ipv4 = true;
break;
case PLT_IPV6:
- log_debug("ipv6 peers %d:", allen);
+ zlog_debug("ipv6 peers %d:", allen);
bpc.bpc_ipv4 = false;
break;
case PLT_LABEL:
- log_debug("label peers %d:", allen);
+ zlog_debug("label peers %d:", allen);
if (parse_peer_label_config(jo_val, &bpc) != 0) {
error++;
continue;
@@ -156,8 +156,8 @@ static int parse_list(struct json_object *jo, enum peer_list_type plt,
default:
error++;
- log_error("%s:%d: unsupported peer type", __func__,
- __LINE__);
+ zlog_err("%s:%d: unsupported peer type", __func__,
+ __LINE__);
break;
}
@@ -178,7 +178,7 @@ static int parse_peer_config(struct json_object *jo, struct bfd_peer_cfg *bpc)
int family_type = (bpc->bpc_ipv4) ? AF_INET : AF_INET6;
int error = 0;
- log_debug(" peer: %s", bpc->bpc_ipv4 ? "ipv4" : "ipv6");
+ zlog_debug(" peer: %s", bpc->bpc_ipv4 ? "ipv4" : "ipv6");
JSON_FOREACH (jo, joi, join) {
key = json_object_iter_peek_name(&joi);
@@ -186,41 +186,41 @@ static int parse_peer_config(struct json_object *jo, struct bfd_peer_cfg *bpc)
if (strcmp(key, "multihop") == 0) {
bpc->bpc_mhop = json_object_get_boolean(jo_val);
- log_debug(" multihop: %s",
- bpc->bpc_mhop ? "true" : "false");
+ zlog_debug(" multihop: %s",
+ bpc->bpc_mhop ? "true" : "false");
} else if (strcmp(key, "peer-address") == 0) {
sval = json_object_get_string(jo_val);
if (strtosa(sval, &bpc->bpc_peer) != 0
|| bpc->bpc_peer.sa_sin.sin_family != family_type) {
- log_info(
+ zlog_debug(
"%s:%d failed to parse peer-address '%s'",
__func__, __LINE__, sval);
error++;
}
- log_debug(" peer-address: %s", sval);
+ zlog_debug(" peer-address: %s", sval);
} else if (strcmp(key, "local-address") == 0) {
sval = json_object_get_string(jo_val);
if (strtosa(sval, &bpc->bpc_local) != 0
|| bpc->bpc_local.sa_sin.sin_family
!= family_type) {
- log_info(
+ zlog_debug(
"%s:%d failed to parse local-address '%s'",
__func__, __LINE__, sval);
error++;
}
- log_debug(" local-address: %s", sval);
+ zlog_debug(" local-address: %s", sval);
} else if (strcmp(key, "local-interface") == 0) {
bpc->bpc_has_localif = true;
sval = json_object_get_string(jo_val);
if (strlcpy(bpc->bpc_localif, sval,
sizeof(bpc->bpc_localif))
> sizeof(bpc->bpc_localif)) {
- log_debug(
+ zlog_debug(
" local-interface: %s (truncated)",
sval);
error++;
} else {
- log_debug(" local-interface: %s", sval);
+ zlog_debug(" local-interface: %s", sval);
}
} else if (strcmp(key, "vrf-name") == 0) {
bpc->bpc_has_vrfname = true;
@@ -228,67 +228,68 @@ static int parse_peer_config(struct json_object *jo, struct bfd_peer_cfg *bpc)
if (strlcpy(bpc->bpc_vrfname, sval,
sizeof(bpc->bpc_vrfname))
> sizeof(bpc->bpc_vrfname)) {
- log_debug(" vrf-name: %s (truncated)",
- sval);
+ zlog_debug(" vrf-name: %s (truncated)",
+ sval);
error++;
} else {
- log_debug(" vrf-name: %s", sval);
+ zlog_debug(" vrf-name: %s", sval);
}
} else if (strcmp(key, "detect-multiplier") == 0) {
bpc->bpc_detectmultiplier =
json_object_get_int64(jo_val);
bpc->bpc_has_detectmultiplier = true;
- log_debug(" detect-multiplier: %u",
- bpc->bpc_detectmultiplier);
+ zlog_debug(" detect-multiplier: %u",
+ bpc->bpc_detectmultiplier);
} else if (strcmp(key, "receive-interval") == 0) {
bpc->bpc_recvinterval = json_object_get_int64(jo_val);
bpc->bpc_has_recvinterval = true;
- log_debug(" receive-interval: %" PRIu64,
- bpc->bpc_recvinterval);
+ zlog_debug(" receive-interval: %" PRIu64,
+ bpc->bpc_recvinterval);
} else if (strcmp(key, "transmit-interval") == 0) {
bpc->bpc_txinterval = json_object_get_int64(jo_val);
bpc->bpc_has_txinterval = true;
- log_debug(" transmit-interval: %" PRIu64,
- bpc->bpc_txinterval);
+ zlog_debug(" transmit-interval: %" PRIu64,
+ bpc->bpc_txinterval);
} else if (strcmp(key, "echo-interval") == 0) {
bpc->bpc_echointerval = json_object_get_int64(jo_val);
bpc->bpc_has_echointerval = true;
- log_debug(" echo-interval: %" PRIu64,
- bpc->bpc_echointerval);
+ zlog_debug(" echo-interval: %" PRIu64,
+ bpc->bpc_echointerval);
} else if (strcmp(key, "create-only") == 0) {
bpc->bpc_createonly = json_object_get_boolean(jo_val);
- log_debug(" create-only: %s",
- bpc->bpc_createonly ? "true" : "false");
+ zlog_debug(" create-only: %s",
+ bpc->bpc_createonly ? "true" : "false");
} else if (strcmp(key, "shutdown") == 0) {
bpc->bpc_shutdown = json_object_get_boolean(jo_val);
- log_debug(" shutdown: %s",
- bpc->bpc_shutdown ? "true" : "false");
+ zlog_debug(" shutdown: %s",
+ bpc->bpc_shutdown ? "true" : "false");
} else if (strcmp(key, "echo-mode") == 0) {
bpc->bpc_echo = json_object_get_boolean(jo_val);
- log_debug(" echo-mode: %s",
- bpc->bpc_echo ? "true" : "false");
+ zlog_debug(" echo-mode: %s",
+ bpc->bpc_echo ? "true" : "false");
} else if (strcmp(key, "label") == 0) {
bpc->bpc_has_label = true;
sval = json_object_get_string(jo_val);
if (strlcpy(bpc->bpc_label, sval,
sizeof(bpc->bpc_label))
> sizeof(bpc->bpc_label)) {
- log_debug(" label: %s (truncated)",
- sval);
+ zlog_debug(" label: %s (truncated)",
+ sval);
error++;
} else {
- log_debug(" label: %s", sval);
+ zlog_debug(" label: %s", sval);
}
} else {
sval = json_object_get_string(jo_val);
- log_warning("%s:%d invalid configuration: '%s: %s'",
- __func__, __LINE__, key, sval);
+ zlog_warn("%s:%d invalid configuration: '%s: %s'",
+ __func__, __LINE__, key, sval);
error++;
}
}
if (bpc->bpc_peer.sa_sin.sin_family == 0) {
- log_debug("%s:%d no peer address provided", __func__, __LINE__);
+ zlog_debug("%s:%d no peer address provided", __func__,
+ __LINE__);
error++;
}
@@ -312,7 +313,7 @@ static int parse_peer_label_config(struct json_object *jo,
if (pl == NULL)
return 1;
- log_debug(" peer-label: %s", sval);
+ zlog_debug(" peer-label: %s", sval);
/* Translate the label into BFD address keys. */
bs_to_bpc(pl->pl_bs, bpc);
@@ -474,12 +475,12 @@ char *config_notify_config(const char *op, struct bfd_session *bs)
json_object_int_add(resp, "remote-echo-interval",
bs->remote_timers.required_min_echo / 1000);
- if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO))
+ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO))
json_object_boolean_true_add(resp, "echo-mode");
else
json_object_boolean_false_add(resp, "echo-mode");
- if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN))
+ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN))
json_object_boolean_true_add(resp, "shutdown");
else
json_object_boolean_false_add(resp, "shutdown");
@@ -511,12 +512,12 @@ static int json_object_add_peer(struct json_object *jo, struct bfd_session *bs)
char addr_buf[INET6_ADDRSTRLEN];
/* Add peer 'key' information. */
- if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_IPV6))
+ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_IPV6))
json_object_boolean_true_add(jo, "ipv6");
else
json_object_boolean_false_add(jo, "ipv6");
- if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH)) {
+ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH)) {
json_object_boolean_true_add(jo, "multihop");
json_object_string_add(jo, "peer-address",
inet_ntop(bs->key.family, &bs->key.peer,
@@ -573,7 +574,7 @@ struct peer_label *pl_new(const char *label, struct bfd_session *bs)
if (strlcpy(pl->pl_label, label, sizeof(pl->pl_label))
> sizeof(pl->pl_label))
- log_warning("%s:%d: label was truncated", __func__, __LINE__);
+ zlog_warn("%s:%d: label was truncated", __func__, __LINE__);
pl->pl_bs = bs;
bs->pl = pl;
diff --git a/bfdd/control.c b/bfdd/control.c
index ae6f5a3e79..4adc54a64a 100644
--- a/bfdd/control.c
+++ b/bfdd/control.c
@@ -86,13 +86,13 @@ static int sock_set_nonblock(int fd)
flags = fcntl(fd, F_GETFL, 0);
if (flags == -1) {
- log_warning("%s: fcntl F_GETFL: %s", __func__, strerror(errno));
+ zlog_warn("%s: fcntl F_GETFL: %s", __func__, strerror(errno));
return -1;
}
flags |= O_NONBLOCK;
if (fcntl(fd, F_SETFL, flags) == -1) {
- log_warning("%s: fcntl F_SETFL: %s", __func__, strerror(errno));
+ zlog_warn("%s: fcntl F_SETFL: %s", __func__, strerror(errno));
return -1;
}
@@ -116,20 +116,20 @@ int control_init(const char *path)
sd = socket(AF_UNIX, SOCK_STREAM, PF_UNSPEC);
if (sd == -1) {
- log_error("%s: socket: %s", __func__, strerror(errno));
+ zlog_err("%s: socket: %s", __func__, strerror(errno));
return -1;
}
umval = umask(0);
if (bind(sd, (struct sockaddr *)&sun_, sizeof(sun_)) == -1) {
- log_error("%s: bind: %s", __func__, strerror(errno));
+ zlog_err("%s: bind: %s", __func__, strerror(errno));
close(sd);
return -1;
}
umask(umval);
if (listen(sd, SOMAXCONN) == -1) {
- log_error("%s: listen: %s", __func__, strerror(errno));
+ zlog_err("%s: listen: %s", __func__, strerror(errno));
close(sd);
return -1;
}
@@ -164,7 +164,7 @@ int control_accept(struct thread *t)
csock = accept(sd, NULL, 0);
if (csock == -1) {
- log_warning("%s: accept: %s", __func__, strerror(errno));
+ zlog_warn("%s: accept: %s", __func__, strerror(errno));
return 0;
}
@@ -440,7 +440,7 @@ static int control_read(struct thread *t)
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
goto schedule_next_read;
- log_warning("%s: read: %s", __func__, strerror(errno));
+ zlog_warn("%s: read: %s", __func__, strerror(errno));
control_free(bcs);
return 0;
}
@@ -448,15 +448,15 @@ static int control_read(struct thread *t)
/* Validate header fields. */
plen = ntohl(bcm.bcm_length);
if (plen < 2) {
- log_debug("%s: client closed due small message length: %d",
- __func__, bcm.bcm_length);
+ zlog_debug("%s: client closed due small message length: %d",
+ __func__, bcm.bcm_length);
control_free(bcs);
return 0;
}
if (bcm.bcm_ver != BMV_VERSION_1) {
- log_debug("%s: client closed due bad version: %d", __func__,
- bcm.bcm_ver);
+ zlog_debug("%s: client closed due bad version: %d", __func__,
+ bcm.bcm_ver);
control_free(bcs);
return 0;
}
@@ -470,8 +470,8 @@ static int control_read(struct thread *t)
bcb->bcb_buf = XMALLOC(MTYPE_BFDD_NOTIFICATION,
sizeof(bcm) + bcb->bcb_left + 1);
if (bcb->bcb_buf == NULL) {
- log_warning("%s: not enough memory for message size: %zu",
- __func__, bcb->bcb_left);
+ zlog_warn("%s: not enough memory for message size: %zu",
+ __func__, bcb->bcb_left);
control_free(bcs);
return 0;
}
@@ -492,7 +492,7 @@ skip_header:
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
goto schedule_next_read;
- log_warning("%s: read: %s", __func__, strerror(errno));
+ zlog_warn("%s: read: %s", __func__, strerror(errno));
control_free(bcs);
return 0;
}
@@ -521,8 +521,8 @@ skip_header:
break;
default:
- log_debug("%s: unhandled message type: %d", __func__,
- bcb->bcb_bcm->bcm_type);
+ zlog_debug("%s: unhandled message type: %d", __func__,
+ bcb->bcb_bcm->bcm_type);
control_response(bcs, bcb->bcb_bcm->bcm_id, BCM_RESPONSE_ERROR,
"invalid message type");
break;
@@ -559,7 +559,7 @@ static int control_write(struct thread *t)
return 0;
}
- log_warning("%s: write: %s", __func__, strerror(errno));
+ zlog_warn("%s: write: %s", __func__, strerror(errno));
control_free(bcs);
return 0;
}
@@ -723,8 +723,8 @@ static void control_response(struct bfd_control_socket *bcs, uint16_t id,
/* Generate JSON response. */
jsonstr = config_response(status, error);
if (jsonstr == NULL) {
- log_warning("%s: config_response: failed to get JSON str",
- __func__);
+ zlog_warn("%s: config_response: failed to get JSON str",
+ __func__);
return;
}
@@ -753,8 +753,8 @@ static void _control_notify(struct bfd_control_socket *bcs,
/* Generate JSON response. */
jsonstr = config_notify(bs);
if (jsonstr == NULL) {
- log_warning("%s: config_notify: failed to get JSON str",
- __func__);
+ zlog_warn("%s: config_notify: failed to get JSON str",
+ __func__);
return;
}
@@ -816,8 +816,8 @@ static void _control_notify_config(struct bfd_control_socket *bcs,
/* Generate JSON response. */
jsonstr = config_notify_config(op, bs);
if (jsonstr == NULL) {
- log_warning("%s: config_notify_config: failed to get JSON str",
- __func__);
+ zlog_warn("%s: config_notify_config: failed to get JSON str",
+ __func__);
return;
}
diff --git a/bfdd/event.c b/bfdd/event.c
index 5ba54c2b0b..686f39cc0a 100644
--- a/bfdd/event.c
+++ b/bfdd/event.c
@@ -43,13 +43,14 @@ void bfd_recvtimer_update(struct bfd_session *bs)
bfd_recvtimer_delete(bs);
/* Don't add event if peer is deactivated. */
- if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) ||
+ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) ||
bs->sock == -1)
return;
tv_normalize(&tv);
#ifdef BFD_EVENT_DEBUG
- log_debug("%s: sec = %ld, usec = %ld", __func__, tv.tv_sec, tv.tv_usec);
+ zlog_debug("%s: sec = %ld, usec = %ld", __func__, tv.tv_sec,
+ tv.tv_usec);
#endif /* BFD_EVENT_DEBUG */
thread_add_timer_tv(master, bfd_recvtimer_cb, bs, &tv,
@@ -64,13 +65,14 @@ void bfd_echo_recvtimer_update(struct bfd_session *bs)
bfd_echo_recvtimer_delete(bs);
/* Don't add event if peer is deactivated. */
- if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) ||
+ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) ||
bs->sock == -1)
return;
tv_normalize(&tv);
#ifdef BFD_EVENT_DEBUG
- log_debug("%s: sec = %ld, usec = %ld", __func__, tv.tv_sec, tv.tv_usec);
+ zlog_debug("%s: sec = %ld, usec = %ld", __func__, tv.tv_sec,
+ tv.tv_usec);
#endif /* BFD_EVENT_DEBUG */
thread_add_timer_tv(master, bfd_echo_recvtimer_cb, bs, &tv,
@@ -85,13 +87,14 @@ void bfd_xmttimer_update(struct bfd_session *bs, uint64_t jitter)
bfd_xmttimer_delete(bs);
/* Don't add event if peer is deactivated. */
- if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) ||
+ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) ||
bs->sock == -1)
return;
tv_normalize(&tv);
#ifdef BFD_EVENT_DEBUG
- log_debug("%s: sec = %ld, usec = %ld", __func__, tv.tv_sec, tv.tv_usec);
+ zlog_debug("%s: sec = %ld, usec = %ld", __func__, tv.tv_sec,
+ tv.tv_usec);
#endif /* BFD_EVENT_DEBUG */
thread_add_timer_tv(master, bfd_xmt_cb, bs, &tv, &bs->xmttimer_ev);
@@ -105,13 +108,14 @@ void bfd_echo_xmttimer_update(struct bfd_session *bs, uint64_t jitter)
bfd_echo_xmttimer_delete(bs);
/* Don't add event if peer is deactivated. */
- if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) ||
+ if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) ||
bs->sock == -1)
return;
tv_normalize(&tv);
#ifdef BFD_EVENT_DEBUG
- log_debug("%s: sec = %ld, usec = %ld", __func__, tv.tv_sec, tv.tv_usec);
+ zlog_debug("%s: sec = %ld, usec = %ld", __func__, tv.tv_sec,
+ tv.tv_usec);
#endif /* BFD_EVENT_DEBUG */
thread_add_timer_tv(master, bfd_echo_xmt_cb, bs, &tv,
diff --git a/bfdd/ptm_adapter.c b/bfdd/ptm_adapter.c
index dcca70b796..eae2158acb 100644
--- a/bfdd/ptm_adapter.c
+++ b/bfdd/ptm_adapter.c
@@ -120,9 +120,9 @@ static void debug_printbpc(const char *func, unsigned int line,
sprintf(cbit_str, "CB %x", bpc->bpc_cbit);
- log_debug("%s:%d: %s %s%s%s%s%s%s %s", func, line,
- bpc->bpc_mhop ? "multi-hop" : "single-hop", addr[0], addr[1],
- addr[2], timers[0], timers[1], timers[2], cbit_str);
+ zlog_debug("%s:%d: %s %s%s%s%s%s%s %s", func, line,
+ bpc->bpc_mhop ? "multi-hop" : "single-hop", addr[0], addr[1],
+ addr[2], timers[0], timers[1], timers[2], cbit_str);
}
#define DEBUG_PRINTBPC(bpc) debug_printbpc(__FILE__, __LINE__, (bpc))
@@ -260,7 +260,7 @@ static void _ptm_msg_read_address(struct stream *msg, struct sockaddr_any *sa)
return;
default:
- log_warning("ptm-read-address: invalid family: %d", family);
+ zlog_warn("ptm-read-address: invalid family: %d", family);
break;
}
@@ -316,7 +316,7 @@ static int _ptm_msg_read(struct stream *msg, int command, vrf_id_t vrf_id,
*pc = pc_new(pid);
if (*pc == NULL) {
- log_debug("ptm-read: failed to allocate memory");
+ zlog_debug("ptm-read: failed to allocate memory");
return -1;
}
@@ -358,7 +358,7 @@ static int _ptm_msg_read(struct stream *msg, int command, vrf_id_t vrf_id,
*/
STREAM_GETC(msg, ifnamelen);
if (ifnamelen >= sizeof(bpc->bpc_localif)) {
- log_error("ptm-read: interface name is too big");
+ zlog_err("ptm-read: interface name is too big");
return -1;
}
@@ -376,7 +376,8 @@ static int _ptm_msg_read(struct stream *msg, int command, vrf_id_t vrf_id,
bpc->bpc_has_vrfname = true;
strlcpy(bpc->bpc_vrfname, vrf->name, sizeof(bpc->bpc_vrfname));
} else {
- log_error("ptm-read: vrf id %u could not be identified", vrf_id);
+ zlog_err("ptm-read: vrf id %u could not be identified",
+ vrf_id);
return -1;
}
} else {
@@ -390,7 +391,7 @@ static int _ptm_msg_read(struct stream *msg, int command, vrf_id_t vrf_id,
if (bpc->bpc_local.sa_sin.sin_family != 0
&& (bpc->bpc_local.sa_sin.sin_family
!= bpc->bpc_peer.sa_sin.sin_family)) {
- log_warning("ptm-read: peer family doesn't match local type");
+ zlog_warn("ptm-read: peer family doesn't match local type");
return -1;
}
@@ -418,20 +419,21 @@ static void bfdd_dest_register(struct stream *msg, vrf_id_t vrf_id)
if (bs == NULL) {
bs = ptm_bfd_sess_new(&bpc);
if (bs == NULL) {
- log_debug("ptm-add-dest: failed to create BFD session");
+ zlog_debug(
+ "ptm-add-dest: failed to create BFD session");
return;
}
} else {
/* Don't try to change echo/shutdown state. */
- bpc.bpc_echo = BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO);
+ bpc.bpc_echo = CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO);
bpc.bpc_shutdown =
- BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN);
+ CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN);
}
/* Create client peer notification register. */
pcn = pcn_new(pc, bs);
if (pcn == NULL) {
- log_error("ptm-add-dest: failed to registrate notifications");
+ zlog_err("ptm-add-dest: failed to registrate notifications");
return;
}
@@ -454,7 +456,7 @@ static void bfdd_dest_deregister(struct stream *msg, vrf_id_t vrf_id)
/* Find or start new BFD session. */
bs = bs_peer_find(&bpc);
if (bs == NULL) {
- log_debug("ptm-del-dest: failed to find BFD session");
+ zlog_debug("ptm-del-dest: failed to find BFD session");
return;
}
@@ -462,7 +464,7 @@ static void bfdd_dest_deregister(struct stream *msg, vrf_id_t vrf_id)
pcn = pcn_lookup(pc, bs);
pcn_free(pcn);
if (bs->refcount ||
- BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG))
+ CHECK_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG))
return;
bs->ses_state = PTM_BFD_ADM_DOWN;
@@ -485,14 +487,14 @@ static void bfdd_client_register(struct stream *msg)
pc = pc_new(pid);
if (pc == NULL) {
- log_error("ptm-add-client: failed to register client: %u", pid);
+ zlog_err("ptm-add-client: failed to register client: %u", pid);
return;
}
return;
stream_failure:
- log_error("ptm-add-client: failed to register client");
+ zlog_err("ptm-add-client: failed to register client");
}
/*
@@ -509,7 +511,7 @@ static void bfdd_client_deregister(struct stream *msg)
pc = pc_lookup(pid);
if (pc == NULL) {
- log_debug("ptm-del-client: failed to find client: %u", pid);
+ zlog_debug("ptm-del-client: failed to find client: %u", pid);
return;
}
@@ -518,7 +520,7 @@ static void bfdd_client_deregister(struct stream *msg)
return;
stream_failure:
- log_error("ptm-del-client: failed to deregister client");
+ zlog_err("ptm-del-client: failed to deregister client");
}
static int bfdd_replay(ZAPI_CALLBACK_ARGS)
@@ -544,14 +546,14 @@ static int bfdd_replay(ZAPI_CALLBACK_ARGS)
break;
default:
- log_debug("ptm-replay: invalid message type %u", rcmd);
+ zlog_debug("ptm-replay: invalid message type %u", rcmd);
return -1;
}
return 0;
stream_failure:
- log_error("ptm-replay: failed to find command");
+ zlog_err("ptm-replay: failed to find command");
return -1;
}
diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c
index 123be42e2a..b7e2f45195 100644
--- a/bgpd/bgp_attr.c
+++ b/bgpd/bgp_attr.c
@@ -2178,8 +2178,7 @@ bgp_attr_large_community(struct bgp_attr_parser_args *args)
args->total);
}
- attr->lcommunity =
- lcommunity_parse((uint8_t *)stream_pnt(peer->curr), length);
+ attr->lcommunity = lcommunity_parse(stream_pnt(peer->curr), length);
/* XXX: fix ecommunity_parse to use stream API */
stream_forward_getp(peer->curr, length);
@@ -2209,7 +2208,7 @@ bgp_attr_ext_communities(struct bgp_attr_parser_args *args)
}
attr->ecommunity =
- ecommunity_parse((uint8_t *)stream_pnt(peer->curr), length);
+ ecommunity_parse(stream_pnt(peer->curr), length);
/* XXX: fix ecommunity_parse to use stream API */
stream_forward_getp(peer->curr, length);
diff --git a/bgpd/bgp_community.c b/bgpd/bgp_community.c
index 195c0f394c..30de84c878 100644
--- a/bgpd/bgp_community.c
+++ b/bgpd/bgp_community.c
@@ -146,7 +146,7 @@ uint32_t community_val_get(struct community *com, int i)
uint32_t val;
p = (uint8_t *)com->val;
- p += (i * 4);
+ p += (i * COMMUNITY_SIZE);
memcpy(&val, p, sizeof(uint32_t));
@@ -514,11 +514,11 @@ struct community *community_parse(uint32_t *pnt, unsigned short length)
struct community *new;
/* If length is malformed return NULL. */
- if (length % 4)
+ if (length % COMMUNITY_SIZE)
return NULL;
/* Make temporary community for hash look up. */
- tmp.size = length / 4;
+ tmp.size = length / COMMUNITY_SIZE;
tmp.val = pnt;
new = community_uniq_sort(&tmp);
@@ -533,8 +533,9 @@ struct community *community_dup(struct community *com)
new = XCALLOC(MTYPE_COMMUNITY, sizeof(struct community));
new->size = com->size;
if (new->size) {
- new->val = XMALLOC(MTYPE_COMMUNITY_VAL, com->size * 4);
- memcpy(new->val, com->val, com->size * 4);
+ new->val = XMALLOC(MTYPE_COMMUNITY_VAL,
+ com->size * COMMUNITY_SIZE);
+ memcpy(new->val, com->val, com->size * COMMUNITY_SIZE);
} else
new->val = NULL;
return new;
@@ -558,7 +559,7 @@ char *community_str(struct community *com, bool make_json)
hash package.*/
unsigned int community_hash_make(const struct community *com)
{
- uint32_t *pnt = (uint32_t *)com->val;
+ uint32_t *pnt = com->val;
return jhash2(pnt, com->size, 0x43ea96c1);
}
@@ -600,7 +601,8 @@ bool community_cmp(const struct community *com1, const struct community *com2)
return false;
if (com1->size == com2->size)
- if (memcmp(com1->val, com2->val, com1->size * 4) == 0)
+ if (memcmp(com1->val, com2->val, com1->size * COMMUNITY_SIZE)
+ == 0)
return true;
return false;
}
@@ -610,13 +612,14 @@ struct community *community_merge(struct community *com1,
struct community *com2)
{
if (com1->val)
- com1->val = XREALLOC(MTYPE_COMMUNITY_VAL, com1->val,
- (com1->size + com2->size) * 4);
+ com1->val =
+ XREALLOC(MTYPE_COMMUNITY_VAL, com1->val,
+ (com1->size + com2->size) * COMMUNITY_SIZE);
else
com1->val = XMALLOC(MTYPE_COMMUNITY_VAL,
- (com1->size + com2->size) * 4);
+ (com1->size + com2->size) * COMMUNITY_SIZE);
- memcpy(com1->val + com1->size, com2->val, com2->size * 4);
+ memcpy(com1->val + com1->size, com2->val, com2->size * COMMUNITY_SIZE);
com1->size += com2->size;
return com1;
diff --git a/bgpd/bgp_community.h b/bgpd/bgp_community.h
index 31a061370d..b99f38ab64 100644
--- a/bgpd/bgp_community.h
+++ b/bgpd/bgp_community.h
@@ -61,8 +61,10 @@ struct community {
#define COMMUNITY_LOCAL_AS 0xFFFFFF03
#define COMMUNITY_NO_PEER 0xFFFFFF04
+#define COMMUNITY_SIZE 4
+
/* Macros of community attribute. */
-#define com_length(X) ((X)->size * 4)
+#define com_length(X) ((X)->size * COMMUNITY_SIZE)
#define com_lastval(X) ((X)->val + (X)->size - 1)
#define com_nthval(X,n) ((X)->val + (n))
diff --git a/bgpd/bgp_ecommunity.c b/bgpd/bgp_ecommunity.c
index 5bb4248a57..fe09aab956 100644
--- a/bgpd/bgp_ecommunity.c
+++ b/bgpd/bgp_ecommunity.c
@@ -823,7 +823,7 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
if (sub_type == ECOMMUNITY_REDIRECT_VRF) {
char buf[16] = {};
ecommunity_rt_soo_str(
- buf, sizeof(buf), (uint8_t *)pnt,
+ buf, sizeof(buf), pnt,
type & ~ECOMMUNITY_ENCODE_TRANS_EXP,
ECOMMUNITY_ROUTE_TARGET,
ECOMMUNITY_FORMAT_DISPLAY);
diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c
index 9d895fa27c..fadccc5026 100644
--- a/bgpd/bgp_evpn.c
+++ b/bgpd/bgp_evpn.c
@@ -901,8 +901,8 @@ static void add_mac_mobility_to_attr(uint32_t seq_num, struct attr *attr)
if (type == ECOMMUNITY_ENCODE_EVPN
&& sub_type
== ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY) {
- ecom_val_ptr = (uint8_t *)(attr->ecommunity->val
- + (i * 8));
+ ecom_val_ptr =
+ (attr->ecommunity->val + (i * 8));
break;
}
}
diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c
index fddb00b6e2..769872f2e3 100644
--- a/bgpd/bgp_evpn_vty.c
+++ b/bgpd/bgp_evpn_vty.c
@@ -2515,8 +2515,7 @@ static void evpn_show_route_rd_macip(struct vty *vty, struct bgp *bgp,
return;
}
- bgp_evpn_route2str((struct prefix_evpn *)&p, prefix_str,
- sizeof(prefix_str));
+ bgp_evpn_route2str(&p, prefix_str, sizeof(prefix_str));
/* Prefix and num paths displayed once per prefix. */
route_vty_out_detail_header(vty, bgp, rn, prd, afi, safi, json);
@@ -2574,7 +2573,7 @@ static void evpn_show_route_rd(struct vty *vty, struct bgp *bgp,
safi = SAFI_EVPN;
prefix_cnt = path_cnt = 0;
- prefix_rd2str((struct prefix_rd *)prd, rd_str, sizeof(rd_str));
+ prefix_rd2str(prd, rd_str, sizeof(rd_str));
rd_rn = bgp_node_lookup(bgp->rib[afi][safi], (struct prefix *)prd);
if (!rd_rn)
diff --git a/bgpd/bgp_lcommunity.c b/bgpd/bgp_lcommunity.c
index ec7d07fe73..f47ae91663 100644
--- a/bgpd/bgp_lcommunity.c
+++ b/bgpd/bgp_lcommunity.c
@@ -46,6 +46,8 @@ void lcommunity_free(struct lcommunity **lcom)
{
XFREE(MTYPE_LCOMMUNITY_VAL, (*lcom)->val);
XFREE(MTYPE_LCOMMUNITY_STR, (*lcom)->str);
+ if ((*lcom)->json)
+ json_object_free((*lcom)->json);
XFREE(MTYPE_LCOMMUNITY, *lcom);
}
diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c
index c77238aa33..bfce61c2af 100644
--- a/bgpd/bgp_nexthop.c
+++ b/bgpd/bgp_nexthop.c
@@ -436,8 +436,7 @@ void bgp_connected_delete(struct bgp *bgp, struct connected *ifc)
bgp_address_del(bgp, ifc, addr);
- rn = bgp_node_lookup(bgp->connected_table[AFI_IP6],
- (struct prefix *)&p);
+ rn = bgp_node_lookup(bgp->connected_table[AFI_IP6], &p);
}
if (!rn)
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c
index ccd202dfbb..007f53907f 100644
--- a/bgpd/bgp_route.c
+++ b/bgpd/bgp_route.c
@@ -2444,6 +2444,54 @@ struct bgp_process_queue {
unsigned int queued;
};
+static void bgp_process_evpn_route_injection(struct bgp *bgp, afi_t afi,
+ safi_t safi, struct bgp_node *rn,
+ struct bgp_path_info *new_select,
+ struct bgp_path_info *old_select)
+{
+ const struct prefix *p = bgp_node_get_prefix(rn);
+
+ if ((afi != AFI_IP && afi != AFI_IP6) || (safi != SAFI_UNICAST))
+ return;
+
+ if (advertise_type5_routes(bgp, afi) && new_select
+ && is_route_injectable_into_evpn(new_select)) {
+
+ /* apply the route-map */
+ if (bgp->adv_cmd_rmap[afi][safi].map) {
+ route_map_result_t ret;
+ struct bgp_path_info rmap_path;
+ struct bgp_path_info_extra rmap_path_extra;
+ struct attr dummy_attr;
+
+ dummy_attr = *new_select->attr;
+
+ /* Fill temp path_info */
+ prep_for_rmap_apply(&rmap_path, &rmap_path_extra, rn,
+ new_select, new_select->peer,
+ &dummy_attr);
+
+ RESET_FLAG(dummy_attr.rmap_change_flags);
+
+ ret = route_map_apply(bgp->adv_cmd_rmap[afi][safi].map,
+ p, RMAP_BGP, &rmap_path);
+
+ if (ret == RMAP_DENYMATCH) {
+ bgp_attr_flush(&dummy_attr);
+ bgp_evpn_withdraw_type5_route(bgp, p, afi,
+ safi);
+ } else
+ bgp_evpn_advertise_type5_route(
+ bgp, p, &dummy_attr, afi, safi);
+ } else {
+ bgp_evpn_advertise_type5_route(bgp, p, new_select->attr,
+ afi, safi);
+ }
+ } else if (advertise_type5_routes(bgp, afi) && old_select
+ && is_route_injectable_into_evpn(old_select))
+ bgp_evpn_withdraw_type5_route(bgp, p, afi, safi);
+}
+
/*
* old_select = The old best path
* new_select = the new best path
@@ -2607,6 +2655,12 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_node *rn,
UNSET_FLAG(rn->flags, BGP_NODE_LABEL_CHANGED);
}
+ /* advertise/withdraw type-5 routes */
+ if (CHECK_FLAG(old_select->flags, BGP_PATH_LINK_BW_CHG)
+ || CHECK_FLAG(old_select->flags, BGP_PATH_MULTIPATH_CHG))
+ bgp_process_evpn_route_injection(
+ bgp, afi, safi, rn, old_select, old_select);
+
UNSET_FLAG(old_select->flags, BGP_PATH_MULTIPATH_CHG);
UNSET_FLAG(old_select->flags, BGP_PATH_LINK_BW_CHG);
bgp_zebra_clear_route_change_flags(rn);
@@ -2696,53 +2750,8 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_node *rn,
}
}
- /* advertise/withdraw type-5 routes */
- if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) {
- const struct prefix *p = bgp_node_get_prefix(rn);
-
- if (advertise_type5_routes(bgp, afi) &&
- new_select &&
- is_route_injectable_into_evpn(new_select)) {
-
- /* apply the route-map */
- if (bgp->adv_cmd_rmap[afi][safi].map) {
- route_map_result_t ret;
- struct bgp_path_info rmap_path;
- struct bgp_path_info_extra rmap_path_extra;
- struct attr dummy_attr;
-
- dummy_attr = *new_select->attr;
-
- /* Fill temp path_info */
- prep_for_rmap_apply(
- &rmap_path, &rmap_path_extra,
- rn, new_select, new_select->peer,
- &dummy_attr);
-
- RESET_FLAG(dummy_attr.rmap_change_flags);
-
- ret = route_map_apply(
- bgp->adv_cmd_rmap[afi][safi].map,
- p, RMAP_BGP, &rmap_path);
- if (ret == RMAP_DENYMATCH) {
- bgp_attr_flush(&dummy_attr);
- bgp_evpn_withdraw_type5_route(
- bgp, p, afi, safi);
- } else
- bgp_evpn_advertise_type5_route(
- bgp, p, &dummy_attr,
- afi, safi);
- } else {
- bgp_evpn_advertise_type5_route(bgp, p,
- new_select->attr,
- afi, safi);
-
- }
- } else if (advertise_type5_routes(bgp, afi) &&
- old_select &&
- is_route_injectable_into_evpn(old_select))
- bgp_evpn_withdraw_type5_route(bgp, p, afi, safi);
- }
+ bgp_process_evpn_route_injection(bgp, afi, safi, rn, new_select,
+ old_select);
/* Clear any route change flags. */
bgp_zebra_clear_route_change_flags(rn);
@@ -8298,7 +8307,7 @@ void route_vty_out_overlay(struct vty *vty, const struct prefix *p,
mac = ecom_mac2str((char *)routermac->val);
if (mac) {
if (!json_path) {
- vty_out(vty, "/%s", (char *)mac);
+ vty_out(vty, "/%s", mac);
} else {
json_object_string_add(json_overlay, "rmac",
mac);
@@ -11594,8 +11603,8 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi,
struct bgp_table *table;
struct bgp_adj_in *ain;
struct bgp_adj_out *adj;
- unsigned long output_count;
- unsigned long filtered_count;
+ unsigned long output_count = 0;
+ unsigned long filtered_count = 0;
struct bgp_node *rn;
int header1 = 1;
struct bgp *bgp;
@@ -11885,6 +11894,12 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi,
vty_out(vty, "%s\n", json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
+
+ if (!output_count && !filtered_count) {
+ json_object_free(json_scode);
+ json_object_free(json_ocode);
+ }
+
json_object_free(json);
} else if (output_count > 0) {
if (filtered_count > 0)
@@ -12268,7 +12283,7 @@ static int bgp_distance_set(struct vty *vty, const char *distance_str,
distance = atoi(distance_str);
/* Get BGP distance node. */
- rn = bgp_node_get(bgp_distance_table[afi][safi], (struct prefix *)&p);
+ rn = bgp_node_get(bgp_distance_table[afi][safi], &p);
bdistance = bgp_node_get_bgp_distance_info(rn);
if (bdistance)
bgp_unlock_node(rn);
@@ -12309,8 +12324,7 @@ static int bgp_distance_unset(struct vty *vty, const char *distance_str,
return CMD_WARNING_CONFIG_FAILED;
}
- rn = bgp_node_lookup(bgp_distance_table[afi][safi],
- (struct prefix *)&p);
+ rn = bgp_node_lookup(bgp_distance_table[afi][safi], &p);
if (!rn) {
vty_out(vty, "Can't find specified prefix\n");
return CMD_WARNING_CONFIG_FAILED;
diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c
index 758141c9f2..f30fcc195f 100644
--- a/bgpd/bgp_routemap.c
+++ b/bgpd/bgp_routemap.c
@@ -2569,7 +2569,7 @@ route_set_ecommunity_lb(void *rule, const struct prefix *prefix,
/* Build link bandwidth extended community */
as = (peer->bgp->as > BGP_AS_MAX) ? BGP_AS_TRANS : peer->bgp->as;
if (rels->lb_type == RMAP_ECOMM_LB_SET_VALUE) {
- bw_bytes = ((uint64_t)(rels->bw * 1000 * 1000))/8;
+ bw_bytes = ((uint64_t)rels->bw * 1000 * 1000) / 8;
} else if (rels->lb_type == RMAP_ECOMM_LB_SET_CUMUL) {
/* process this only for the best path. */
if (!CHECK_FLAG(path->flags, BGP_PATH_SELECTED))
@@ -2585,7 +2585,7 @@ route_set_ecommunity_lb(void *rule, const struct prefix *prefix,
if (!CHECK_FLAG(path->flags, BGP_PATH_SELECTED))
return RMAP_OKAY;
- bw_bytes = ((uint64_t)(peer->bgp->lb_ref_bw * 1000 * 1000))/8;
+ bw_bytes = ((uint64_t)peer->bgp->lb_ref_bw * 1000 * 1000) / 8;
mpath_count = bgp_path_info_mpath_count(path) + 1;
bw_bytes *= mpath_count;
}
diff --git a/bgpd/bgp_snmp.c b/bgpd/bgp_snmp.c
index 28eea46a5a..e7aa02863c 100644
--- a/bgpd/bgp_snmp.c
+++ b/bgpd/bgp_snmp.c
@@ -330,7 +330,7 @@ static uint8_t *bgpVersion(struct variable *v, oid name[], size_t *length,
/* Return octet string length 1. */
*var_len = 1;
- return (uint8_t *)&version;
+ return &version;
}
static uint8_t *bgpLocalAs(struct variable *v, oid name[], size_t *length,
diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c
index bfa3ee92a0..8f06fdf86c 100644
--- a/bgpd/bgp_vty.c
+++ b/bgpd/bgp_vty.c
@@ -12192,14 +12192,20 @@ static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
enum show_type type,
union sockunion *su,
const char *conf_if, afi_t afi,
- bool use_json, json_object *json)
+ bool use_json)
{
struct listnode *node, *nnode;
struct peer *peer;
int find = 0;
safi_t safi = SAFI_UNICAST;
+ json_object *json = NULL;
json_object *json_neighbor = NULL;
+ if (use_json) {
+ json = json_object_new_object();
+ json_neighbor = json_object_new_object();
+ }
+
for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
@@ -12208,16 +12214,15 @@ static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
if ((peer->afc[afi][safi]) == 0)
continue;
- if (use_json)
- json_neighbor = json_object_new_object();
-
if (type == show_all) {
bgp_show_peer_gr_status(vty, peer, use_json,
json_neighbor);
- if (use_json)
+ if (use_json) {
json_object_object_add(json, peer->host,
json_neighbor);
+ json_neighbor = NULL;
+ }
} else if (type == show_peer) {
if (conf_if) {
@@ -12243,8 +12248,10 @@ static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
json_neighbor);
}
- if (find)
+ if (find) {
+ json_neighbor = NULL;
break;
+ }
}
if (type == show_peer && !find) {
@@ -12257,6 +12264,10 @@ static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
vty_out(vty, "%s\n",
json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
+
+ if (json_neighbor)
+ json_object_free(json_neighbor);
+ json_object_free(json);
} else {
vty_out(vty, "\n");
}
@@ -12378,7 +12389,6 @@ static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
int ret;
struct bgp *bgp;
union sockunion su;
- json_object *json = NULL;
bgp = bgp_get_default();
@@ -12389,20 +12399,17 @@ static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
NULL);
- json = json_object_new_object();
if (ip_str) {
ret = str2sockunion(ip_str, &su);
if (ret < 0)
- bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL,
- ip_str, afi,
- use_json, json);
- else
bgp_show_neighbor_graceful_restart(
- vty, bgp, type, &su, NULL, afi, use_json, json);
+ vty, bgp, type, NULL, ip_str, afi, use_json);
+ else
+ bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
+ NULL, afi, use_json);
} else
bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
- afi, use_json, json);
- json_object_free(json);
+ afi, use_json);
}
static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index 7560cc4da5..dedd0ed3b1 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -6173,8 +6173,7 @@ static void peer_aslist_update(const char *aslist_name)
static void peer_aslist_add(char *aslist_name)
{
peer_aslist_update(aslist_name);
- route_map_notify_dependencies((char *)aslist_name,
- RMAP_EVENT_ASLIST_ADDED);
+ route_map_notify_dependencies(aslist_name, RMAP_EVENT_ASLIST_ADDED);
}
static void peer_aslist_del(const char *aslist_name)
diff --git a/bgpd/rfapi/rfapi_import.c b/bgpd/rfapi/rfapi_import.c
index d261a3ee88..41e6a64a64 100644
--- a/bgpd/rfapi/rfapi_import.c
+++ b/bgpd/rfapi/rfapi_import.c
@@ -2239,7 +2239,7 @@ static struct bgp_path_info *rfapiItBiIndexSearch(
bpi_fake.peer = peer;
bpi_fake.extra = &bpi_extra;
- bpi_fake.extra->vnc.import.rd = *(struct prefix_rd *)prd;
+ bpi_fake.extra->vnc.import.rd = *prd;
if (aux_prefix) {
bpi_fake.extra->vnc.import.aux_prefix = *aux_prefix;
} else {
diff --git a/bgpd/rfapi/rfapi_monitor.c b/bgpd/rfapi/rfapi_monitor.c
index 0b8dfc3554..cd26892b84 100644
--- a/bgpd/rfapi/rfapi_monitor.c
+++ b/bgpd/rfapi/rfapi_monitor.c
@@ -870,10 +870,9 @@ void rfapiMonitorItNodeChanged(
if ((sl = RFAPI_MONITOR_ETH(rn))) {
for (cursor = NULL,
- rc = skiplist_next(sl, NULL, (void **)&m,
- (void **)&cursor);
+ rc = skiplist_next(sl, NULL, (void **)&m, &cursor);
!rc; rc = skiplist_next(sl, NULL, (void **)&m,
- (void **)&cursor)) {
+ &cursor)) {
if (skiplist_search(nves_seen, m->rfd, NULL)) {
/*
diff --git a/bgpd/rfapi/rfapi_rib.c b/bgpd/rfapi/rfapi_rib.c
index 04a538dc63..95b8582b95 100644
--- a/bgpd/rfapi/rfapi_rib.c
+++ b/bgpd/rfapi/rfapi_rib.c
@@ -268,8 +268,8 @@ static void rfapi_info_free(struct rfapi_info *goner)
if (goner->timer) {
struct rfapi_rib_tcb *tcb;
- tcb = ((struct thread *)goner->timer)->arg;
- thread_cancel((struct thread *)goner->timer);
+ tcb = goner->timer->arg;
+ thread_cancel(goner->timer);
XFREE(MTYPE_RFAPI_RECENT_DELETE, tcb);
goner->timer = NULL;
}
diff --git a/bgpd/rfapi/rfapi_vty.c b/bgpd/rfapi/rfapi_vty.c
index 5a84d14bd9..89f6852e2b 100644
--- a/bgpd/rfapi/rfapi_vty.c
+++ b/bgpd/rfapi/rfapi_vty.c
@@ -3428,7 +3428,7 @@ static void clear_vnc_nve_closer(struct rfapi_local_reg_delete_arg *cda)
&cursor)) {
if (pValue->rfd) {
- ((struct rfapi_descriptor *)pValue->rfd)->flags |=
+ pValue->rfd->flags |=
RFAPI_HD_FLAG_CLOSING_ADMINISTRATIVELY;
rfapi_close(pValue->rfd);
}
diff --git a/configure.ac b/configure.ac
index 628e0c8afc..35261aced4 100755
--- a/configure.ac
+++ b/configure.ac
@@ -860,7 +860,7 @@ fi
AC_SUBST([EXTRAVERSION])
if test "$with_pkg_git_version" = "yes"; then
- if test -d "${srcdir}/.git"; then
+ if test -e "${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])
diff --git a/eigrpd/eigrp_network.c b/eigrpd/eigrp_network.c
index 39008a01c4..072ff29705 100644
--- a/eigrpd/eigrp_network.c
+++ b/eigrpd/eigrp_network.c
@@ -218,7 +218,7 @@ int eigrp_network_set(struct eigrp *eigrp, struct prefix *p)
struct route_node *rn;
struct interface *ifp;
- rn = route_node_get(eigrp->networks, (struct prefix *)p);
+ rn = route_node_get(eigrp->networks, p);
if (rn->info) {
/* There is already same network statement. */
route_unlock_node(rn);
diff --git a/isisd/isis_cli.c b/isisd/isis_cli.c
index 156335e544..c12c7fa936 100644
--- a/isisd/isis_cli.c
+++ b/isisd/isis_cli.c
@@ -402,21 +402,7 @@ DEFPY(no_is_type, no_is_type_cmd,
"Act as both a station router and an area router\n"
"Act as an area router only\n")
{
- const char *value = NULL;
- struct isis_area *area;
-
- area = nb_running_get_entry(NULL, VTY_CURR_XPATH, false);
-
- /*
- * Put the is-type back to defaults:
- * - level-1-2 on first area
- * - level-1 for the rest
- */
- if (area && listgetdata(listhead(isis->area_list)) == area)
- value = "level-1-2";
- else
- value = NULL;
- nb_cli_enqueue_change(vty, "./is-type", NB_OP_MODIFY, value);
+ nb_cli_enqueue_change(vty, "./is-type", NB_OP_MODIFY, NULL);
return nb_cli_apply_changes(vty, NULL);
}
@@ -527,7 +513,7 @@ DEFPY(no_metric_style, no_metric_style_cmd,
"Send and accept both styles of TLVs during transition\n"
"Use new style of TLVs to carry wider metric\n")
{
- nb_cli_enqueue_change(vty, "./metric-style", NB_OP_MODIFY, "narrow");
+ nb_cli_enqueue_change(vty, "./metric-style", NB_OP_MODIFY, NULL);
return nb_cli_apply_changes(vty, NULL);
}
diff --git a/ldpd/socket.c b/ldpd/socket.c
index 4909ea7ad8..e865707d44 100644
--- a/ldpd/socket.c
+++ b/ldpd/socket.c
@@ -320,7 +320,7 @@ sock_set_md5sig(int fd, int af, union ldpd_addr *addr, const char *password)
int
sock_set_ipv4_tos(int fd, int tos)
{
- if (setsockopt(fd, IPPROTO_IP, IP_TOS, (int *)&tos, sizeof(tos)) < 0) {
+ if (setsockopt(fd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0) {
log_warn("%s: error setting IP_TOS to 0x%x", __func__, tos);
return (-1);
}
diff --git a/lib/command_match.c b/lib/command_match.c
index 0195aebc17..801b05f157 100644
--- a/lib/command_match.c
+++ b/lib/command_match.c
@@ -88,7 +88,7 @@ enum matcher_rv command_match(struct graph *cmdgraph, vector vline,
// prepend a dummy token to match that pesky start node
vector vvline = vector_init(vline->alloced + 1);
- vector_set_index(vvline, 0, (void *)XSTRDUP(MTYPE_TMP, "dummy"));
+ vector_set_index(vvline, 0, XSTRDUP(MTYPE_TMP, "dummy"));
memcpy(vvline->index + 1, vline->index,
sizeof(void *) * vline->alloced);
vvline->active = vline->active + 1;
diff --git a/lib/md5.c b/lib/md5.c
index 9c003a3af6..5c93c7bc1f 100644
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -429,7 +429,7 @@ void hmac_md5(unsigned char *text, int text_len, unsigned char *key,
* pass */
MD5Update(&context, k_ipad, 64); /* start with inner pad */
MD5Update(&context, text, text_len); /* then text of datagram */
- MD5Final((uint8_t *)digest, &context); /* finish up 1st pass */
+ MD5Final(digest, &context); /* finish up 1st pass */
/*
* perform outer MD5
*/
@@ -438,5 +438,5 @@ void hmac_md5(unsigned char *text, int text_len, unsigned char *key,
MD5Update(&context, k_opad, 64); /* start with outer pad */
MD5Update(&context, digest, 16); /* then results of 1st
* hash */
- MD5Final((uint8_t *)digest, &context); /* finish up 2nd pass */
+ MD5Final(digest, &context); /* finish up 2nd pass */
}
diff --git a/lib/skiplist.c b/lib/skiplist.c
index fa25770efa..790bd71c38 100644
--- a/lib/skiplist.c
+++ b/lib/skiplist.c
@@ -624,7 +624,7 @@ void skiplist_test(struct vty *vty)
zlog_debug("%s: (%d:%d)", __func__, i, k);
}
// keys[k] = (void *)random();
- keys[k] = (void *)scramble(k);
+ keys[k] = scramble(k);
if (skiplist_insert(l, keys[k], keys[k]))
zlog_debug("error in insert #%d,#%d", i, k);
}
@@ -649,7 +649,7 @@ void skiplist_test(struct vty *vty)
zlog_debug("<%d:%d>", i, k);
if (skiplist_delete(l, keys[k], keys[k]))
zlog_debug("error in delete");
- keys[k] = (void *)scramble(k ^ 0xf0f0f0f0);
+ keys[k] = scramble(k ^ 0xf0f0f0f0);
if (skiplist_insert(l, keys[k], keys[k]))
zlog_debug("error in insert #%d,#%d", i, k);
}
diff --git a/lib/table.c b/lib/table.c
index 1a89a95f4f..86347cbacd 100644
--- a/lib/table.c
+++ b/lib/table.c
@@ -160,7 +160,7 @@ static void route_common(const struct prefix *n, const struct prefix *p,
np = (const uint8_t *)&n->u.prefix;
pp = (const uint8_t *)&p->u.prefix;
- newp = (uint8_t *)&new->u.prefix;
+ newp = &new->u.prefix;
for (i = 0; i < p->prefixlen / 8; i++) {
if (np[i] == pp[i])
diff --git a/lib/vrf.c b/lib/vrf.c
index 370a1b235a..31ea2d6c4c 100644
--- a/lib/vrf.c
+++ b/lib/vrf.c
@@ -116,7 +116,7 @@ static void vrf_update_vrf_id(ns_id_t ns_id, void *opaqueptr)
vrf->vrf_id = vrf_id;
RB_INSERT(vrf_id_head, &vrfs_by_id, vrf);
if (old_vrf_id == VRF_UNKNOWN)
- vrf_enable((struct vrf *)vrf);
+ vrf_enable(vrf);
}
int vrf_switch_to_netns(vrf_id_t vrf_id)
diff --git a/lib/zclient.c b/lib/zclient.c
index d380267a70..d8c6e002d5 100644
--- a/lib/zclient.c
+++ b/lib/zclient.c
@@ -990,7 +990,7 @@ int zapi_route_encode(uint8_t cmd, struct stream *s, struct zapi_route *api)
stream_putc(s, api->prefix.family);
psize = PSIZE(api->prefix.prefixlen);
stream_putc(s, api->prefix.prefixlen);
- stream_write(s, (uint8_t *)&api->prefix.u.prefix, psize);
+ stream_write(s, &api->prefix.u.prefix, psize);
if (CHECK_FLAG(api->message, ZAPI_MESSAGE_SRCPFX)) {
psize = PSIZE(api->src_prefix.prefixlen);
diff --git a/nhrpd/zbuf.h b/nhrpd/zbuf.h
index d03f4ca3a2..e6f7101d63 100644
--- a/nhrpd/zbuf.h
+++ b/nhrpd/zbuf.h
@@ -86,9 +86,9 @@ static inline void *__zbuf_pull(struct zbuf *zb, size_t size, int error)
}
#define zbuf_pull(zb, type) ((type *)__zbuf_pull(zb, sizeof(type), 1))
-#define zbuf_pulln(zb, sz) ((void *)__zbuf_pull(zb, sz, 1))
+#define zbuf_pulln(zb, sz) (__zbuf_pull(zb, sz, 1))
#define zbuf_may_pull(zb, type) ((type *)__zbuf_pull(zb, sizeof(type), 0))
-#define zbuf_may_pulln(zb, sz) ((void *)__zbuf_pull(zb, sz, 0))
+#define zbuf_may_pulln(zb, sz) (__zbuf_pull(zb, sz, 0))
void *zbuf_may_pull_until(struct zbuf *zb, const char *sep, struct zbuf *msg);
@@ -149,9 +149,9 @@ static inline void *__zbuf_push(struct zbuf *zb, size_t size, int error)
}
#define zbuf_push(zb, type) ((type *)__zbuf_push(zb, sizeof(type), 1))
-#define zbuf_pushn(zb, sz) ((void *)__zbuf_push(zb, sz, 1))
+#define zbuf_pushn(zb, sz) (__zbuf_push(zb, sz, 1))
#define zbuf_may_push(zb, type) ((type *)__zbuf_may_push(zb, sizeof(type), 0))
-#define zbuf_may_pushn(zb, sz) ((void *)__zbuf_push(zb, sz, 0))
+#define zbuf_may_pushn(zb, sz) (__zbuf_push(zb, sz, 0))
static inline void zbuf_put(struct zbuf *zb, const void *src, size_t len)
{
diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c
index e059bfbc55..6e71a21bd5 100644
--- a/ospf6d/ospf6_asbr.c
+++ b/ospf6d/ospf6_asbr.c
@@ -918,8 +918,8 @@ void ospf6_asbr_distribute_list_update(int type)
ZROUTE_NAME(type));
ospf6->t_distribute_update = NULL;
- thread_add_timer_msec(master, ospf6_asbr_routemap_update_timer,
- (void **)args, OSPF_MIN_LS_INTERVAL,
+ thread_add_timer_msec(master, ospf6_asbr_routemap_update_timer, args,
+ OSPF_MIN_LS_INTERVAL,
&ospf6->t_distribute_update);
}
diff --git a/ospf6d/ospf6_lsa.c b/ospf6d/ospf6_lsa.c
index c63ea47f29..bcfd975879 100644
--- a/ospf6d/ospf6_lsa.c
+++ b/ospf6d/ospf6_lsa.c
@@ -527,7 +527,7 @@ struct ospf6_lsa *ospf6_lsa_create(struct ospf6_lsa_header *header)
/* allocate memory */
lsa = XCALLOC(MTYPE_OSPF6_LSA, sizeof(struct ospf6_lsa));
- lsa->header = (struct ospf6_lsa_header *)new_header;
+ lsa->header = new_header;
/* dump string */
ospf6_lsa_printbuf(lsa, lsa->name, sizeof(lsa->name));
@@ -554,7 +554,7 @@ struct ospf6_lsa *ospf6_lsa_create_headeronly(struct ospf6_lsa_header *header)
/* allocate memory */
lsa = XCALLOC(MTYPE_OSPF6_LSA, sizeof(struct ospf6_lsa));
- lsa->header = (struct ospf6_lsa_header *)new_header;
+ lsa->header = new_header;
SET_FLAG(lsa->flag, OSPF6_LSA_HEADERONLY);
/* dump string */
diff --git a/ospf6d/ospf6_spf.c b/ospf6d/ospf6_spf.c
index b0fe890d33..80bff5795f 100644
--- a/ospf6d/ospf6_spf.c
+++ b/ospf6d/ospf6_spf.c
@@ -989,7 +989,7 @@ struct ospf6_lsa *ospf6_create_single_router_lsa(struct ospf6_area *area,
rtr_lsa = ospf6_lsdb_next(end, rtr_lsa);
continue;
}
- lsa_header = (struct ospf6_lsa_header *)rtr_lsa->header;
+ lsa_header = rtr_lsa->header;
total_lsa_length += (ntohs(lsa_header->length) - lsa_length);
num_lsa++;
rtr_lsa = ospf6_lsdb_next(end, rtr_lsa);
@@ -1027,7 +1027,7 @@ struct ospf6_lsa *ospf6_create_single_router_lsa(struct ospf6_area *area,
assert(rtr_lsa);
if (!OSPF6_LSA_IS_MAXAGE(rtr_lsa)) {
/* Append first Link State ID LSA */
- lsa_header = (struct ospf6_lsa_header *)rtr_lsa->header;
+ lsa_header = rtr_lsa->header;
memcpy(new_header, lsa_header, ntohs(lsa_header->length));
/* Assign new lsa length as aggregated length. */
((struct ospf6_lsa_header *)new_header)->length =
@@ -1057,7 +1057,7 @@ struct ospf6_lsa *ospf6_create_single_router_lsa(struct ospf6_area *area,
}
/* Append Next Link State ID LSA */
- lsa_header = (struct ospf6_lsa_header *)rtr_lsa->header;
+ lsa_header = rtr_lsa->header;
memcpy(new_header, (OSPF6_LSA_HEADER_END(rtr_lsa->header) + 4),
(ntohs(lsa_header->length) - lsa_length));
new_header += (ntohs(lsa_header->length) - lsa_length);
diff --git a/ospf6d/ospf6_zebra.c b/ospf6d/ospf6_zebra.c
index f8df37094f..2773a666a3 100644
--- a/ospf6d/ospf6_zebra.c
+++ b/ospf6d/ospf6_zebra.c
@@ -171,8 +171,8 @@ static int ospf6_zebra_read_route(ZAPI_CALLBACK_ARGS)
if (IS_OSPF6_DEBUG_ZEBRA(RECV)) {
char prefixstr[PREFIX2STR_BUFFER], nexthopstr[128];
- prefix2str((struct prefix *)&api.prefix, prefixstr,
- sizeof(prefixstr));
+
+ prefix2str(&api.prefix, prefixstr, sizeof(prefixstr));
inet_ntop(AF_INET6, nexthop, nexthopstr, sizeof(nexthopstr));
zlog_debug(
diff --git a/ospfd/ospf_abr.c b/ospfd/ospf_abr.c
index a8dfcbb36b..eb3323997f 100644
--- a/ospfd/ospf_abr.c
+++ b/ospfd/ospf_abr.c
@@ -708,8 +708,7 @@ void ospf_abr_announce_network_to_area(struct prefix_ipv4 *p, uint32_t cost,
else
full_cost = cost;
- old = ospf_lsa_lookup_by_prefix(area->lsdb, OSPF_SUMMARY_LSA,
- (struct prefix_ipv4 *)p,
+ old = ospf_lsa_lookup_by_prefix(area->lsdb, OSPF_SUMMARY_LSA, p,
area->ospf->router_id);
if (old) {
if (IS_DEBUG_OSPF_EVENT)
@@ -761,8 +760,7 @@ void ospf_abr_announce_network_to_area(struct prefix_ipv4 *p, uint32_t cost,
zlog_debug(
"ospf_abr_announce_network_to_area(): "
"creating new summary");
- lsa = ospf_summary_lsa_originate((struct prefix_ipv4 *)p,
- full_cost, area);
+ lsa = ospf_summary_lsa_originate(p, full_cost, area);
/* This will flood through area. */
if (!lsa) {
diff --git a/ospfd/ospf_ext.c b/ospfd/ospf_ext.c
index df64fca883..47883d5f39 100644
--- a/ospfd/ospf_ext.c
+++ b/ospfd/ospf_ext.c
@@ -1684,7 +1684,7 @@ static uint16_t show_vty_link_info(struct vty *vty, struct tlv_header *ext)
/* Extended Link TLVs */
static void ospf_ext_link_show_info(struct vty *vty, struct ospf_lsa *lsa)
{
- struct lsa_header *lsah = (struct lsa_header *)lsa->data;
+ struct lsa_header *lsah = lsa->data;
struct tlv_header *tlvh;
uint16_t length = 0, sum = 0;
@@ -1758,7 +1758,7 @@ static uint16_t show_vty_pref_info(struct vty *vty, struct tlv_header *ext)
/* Extended Prefix TLVs */
static void ospf_ext_pref_show_info(struct vty *vty, struct ospf_lsa *lsa)
{
- struct lsa_header *lsah = (struct lsa_header *)lsa->data;
+ struct lsa_header *lsah = lsa->data;
struct tlv_header *tlvh;
uint16_t length = 0, sum = 0;
diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c
index d50f390e30..088f7f31c7 100644
--- a/ospfd/ospf_lsa.c
+++ b/ospfd/ospf_lsa.c
@@ -123,7 +123,7 @@ int get_age(struct ospf_lsa *lsa)
one-based. */
uint16_t ospf_lsa_checksum(struct lsa_header *lsa)
{
- uint8_t *buffer = (uint8_t *)&lsa->options;
+ uint8_t *buffer = &lsa->options;
int options_offset = buffer - (uint8_t *)&lsa->ls_age; /* should be 2 */
/* Skip the AGE field */
@@ -138,7 +138,7 @@ uint16_t ospf_lsa_checksum(struct lsa_header *lsa)
int ospf_lsa_checksum_valid(struct lsa_header *lsa)
{
- uint8_t *buffer = (uint8_t *)&lsa->options;
+ uint8_t *buffer = &lsa->options;
int options_offset = buffer - (uint8_t *)&lsa->ls_age; /* should be 2 */
/* Skip the AGE field */
@@ -2845,8 +2845,7 @@ void ospf_lsa_maxage_delete(struct ospf *ospf, struct ospf_lsa *lsa)
lsa_prefix.prefixlen = sizeof(lsa_prefix.u.ptr) * CHAR_BIT;
lsa_prefix.u.ptr = (uintptr_t)lsa;
- if ((rn = route_node_lookup(ospf->maxage_lsa,
- (struct prefix *)&lsa_prefix))) {
+ if ((rn = route_node_lookup(ospf->maxage_lsa, &lsa_prefix))) {
if (rn->info == lsa) {
UNSET_FLAG(lsa->flags, OSPF_LSA_IN_MAXAGE);
ospf_lsa_unlock(&lsa); /* maxage_lsa */
@@ -2888,7 +2887,7 @@ void ospf_lsa_maxage(struct ospf *ospf, struct ospf_lsa *lsa)
lsa_prefix.prefixlen = sizeof(lsa_prefix.u.ptr) * CHAR_BIT;
lsa_prefix.u.ptr = (uintptr_t)lsa;
- rn = route_node_get(ospf->maxage_lsa, (struct prefix *)&lsa_prefix);
+ rn = route_node_get(ospf->maxage_lsa, &lsa_prefix);
if (rn->info != NULL) {
if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
zlog_debug(
diff --git a/ospfd/ospf_opaque.c b/ospfd/ospf_opaque.c
index b042a06372..35fa5da74b 100644
--- a/ospfd/ospf_opaque.c
+++ b/ospfd/ospf_opaque.c
@@ -1161,7 +1161,7 @@ void ospf_opaque_config_write_debug(struct vty *vty)
void show_opaque_info_detail(struct vty *vty, struct ospf_lsa *lsa)
{
- struct lsa_header *lsah = (struct lsa_header *)lsa->data;
+ struct lsa_header *lsah = lsa->data;
uint32_t lsid = ntohl(lsah->id.s_addr);
uint8_t opaque_type = GET_OPAQUE_TYPE(lsid);
uint32_t opaque_id = GET_OPAQUE_ID(lsid);
diff --git a/ospfd/ospf_ri.c b/ospfd/ospf_ri.c
index fbe513cea0..c3d53ad5ed 100644
--- a/ospfd/ospf_ri.c
+++ b/ospfd/ospf_ri.c
@@ -1438,7 +1438,7 @@ static uint16_t show_vty_sr_msd(struct vty *vty, struct tlv_header *tlvh)
static void ospf_router_info_show_info(struct vty *vty, struct ospf_lsa *lsa)
{
- struct lsa_header *lsah = (struct lsa_header *)lsa->data;
+ struct lsa_header *lsah = lsa->data;
struct tlv_header *tlvh;
uint16_t length = 0, sum = 0;
diff --git a/ospfd/ospf_sr.c b/ospfd/ospf_sr.c
index b5a54a0bc4..7a786ba7ab 100644
--- a/ospfd/ospf_sr.c
+++ b/ospfd/ospf_sr.c
@@ -1035,7 +1035,7 @@ void ospf_sr_ri_lsa_update(struct ospf_lsa *lsa)
{
struct sr_node *srn;
struct tlv_header *tlvh;
- struct lsa_header *lsah = (struct lsa_header *)lsa->data;
+ struct lsa_header *lsah = lsa->data;
struct ri_sr_tlv_sid_label_range *ri_srgb;
struct ri_sr_tlv_sr_algorithm *algo;
struct sr_srgb srgb;
@@ -1156,7 +1156,7 @@ void ospf_sr_ri_lsa_update(struct ospf_lsa *lsa)
void ospf_sr_ri_lsa_delete(struct ospf_lsa *lsa)
{
struct sr_node *srn;
- struct lsa_header *lsah = (struct lsa_header *)lsa->data;
+ struct lsa_header *lsah = lsa->data;
if (IS_DEBUG_OSPF_SR)
zlog_debug("SR (%s): Remove SR node %s from lsa_id 4.0.0.%u",
@@ -1198,7 +1198,7 @@ void ospf_sr_ext_link_lsa_update(struct ospf_lsa *lsa)
{
struct sr_node *srn;
struct tlv_header *tlvh;
- struct lsa_header *lsah = (struct lsa_header *)lsa->data;
+ struct lsa_header *lsah = lsa->data;
struct sr_link *srl;
uint16_t length, sum;
@@ -1308,7 +1308,7 @@ void ospf_sr_ext_prefix_lsa_update(struct ospf_lsa *lsa)
{
struct sr_node *srn;
struct tlv_header *tlvh;
- struct lsa_header *lsah = (struct lsa_header *)lsa->data;
+ struct lsa_header *lsah = lsa->data;
struct sr_prefix *srp;
uint16_t length, sum;
diff --git a/ospfd/ospf_te.c b/ospfd/ospf_te.c
index a2084e3214..1009c7577e 100644
--- a/ospfd/ospf_te.c
+++ b/ospfd/ospf_te.c
@@ -2119,7 +2119,7 @@ static uint16_t ospf_mpls_te_show_link_subtlv(struct vty *vty,
static void ospf_mpls_te_show_info(struct vty *vty, struct ospf_lsa *lsa)
{
- struct lsa_header *lsah = (struct lsa_header *)lsa->data;
+ struct lsa_header *lsah = lsa->data;
struct tlv_header *tlvh, *next;
uint16_t sum, total;
uint16_t (*subfunc)(struct vty * vty, struct tlv_header * tlvh,
diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c
index 385a7ece7b..c7e6bd9cbf 100644
--- a/ospfd/ospf_zebra.c
+++ b/ospfd/ospf_zebra.c
@@ -1023,8 +1023,8 @@ void ospf_distribute_list_update(struct ospf *ospf, int type,
/* Set timer. */
ospf->t_distribute_update = NULL;
- thread_add_timer_msec(master, ospf_distribute_list_update_timer,
- (void **)args, ospf->min_ls_interval,
+ thread_add_timer_msec(master, ospf_distribute_list_update_timer, args,
+ ospf->min_ls_interval,
&ospf->t_distribute_update);
}
diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c
index f3fe9e17b2..e9f622d217 100644
--- a/ospfd/ospfd.c
+++ b/ospfd/ospfd.c
@@ -1787,7 +1787,7 @@ static void ospf_nbr_nbma_add(struct ospf_nbr_nbma *nbr_nbma,
p.prefixlen = IPV4_MAX_BITLEN;
p.u.prefix4 = nbr_nbma->addr;
- rn = route_node_get(oi->nbrs, (struct prefix *)&p);
+ rn = route_node_get(oi->nbrs, &p);
if (rn->info) {
nbr = rn->info;
nbr->nbr_nbma = nbr_nbma;
diff --git a/pimd/pim_bfd.c b/pimd/pim_bfd.c
index 84f6733eaf..0df8ea6922 100644
--- a/pimd/pim_bfd.c
+++ b/pimd/pim_bfd.c
@@ -47,7 +47,7 @@ void pim_bfd_write_config(struct vty *vty, struct interface *ifp)
if (!pim_ifp)
return;
- bfd_info = (struct bfd_info *)pim_ifp->bfd_info;
+ bfd_info = pim_ifp->bfd_info;
if (!bfd_info)
return;
@@ -92,7 +92,7 @@ void pim_bfd_info_nbr_create(struct pim_interface *pim_ifp,
if (!neigh->bfd_info)
return;
- nbr_bfd_info = (struct bfd_info *)neigh->bfd_info;
+ nbr_bfd_info = neigh->bfd_info;
nbr_bfd_info->detect_mult = pim_ifp->bfd_info->detect_mult;
nbr_bfd_info->desired_min_tx = pim_ifp->bfd_info->desired_min_tx;
nbr_bfd_info->required_min_rx = pim_ifp->bfd_info->required_min_rx;
@@ -118,7 +118,7 @@ static void pim_bfd_reg_dereg_nbr(struct pim_neighbor *nbr, int command)
if (!nbr)
return;
pim_ifp = nbr->interface->info;
- bfd_info = (struct bfd_info *)pim_ifp->bfd_info;
+ bfd_info = pim_ifp->bfd_info;
if (!bfd_info)
return;
if (PIM_DEBUG_PIM_TRACE) {
@@ -194,8 +194,8 @@ void pim_bfd_if_param_set(struct interface *ifp, uint32_t min_rx,
if (!pim_ifp)
return;
- bfd_set_param((struct bfd_info **)&(pim_ifp->bfd_info), min_rx, min_tx,
- detect_mult, defaults, &command);
+ bfd_set_param(&(pim_ifp->bfd_info), min_rx, min_tx, detect_mult,
+ defaults, &command);
if (pim_ifp->bfd_info) {
if (PIM_DEBUG_PIM_TRACE)
diff --git a/pimd/pim_hello.c b/pimd/pim_hello.c
index ecdb3a34a7..e50504ec10 100644
--- a/pimd/pim_hello.c
+++ b/pimd/pim_hello.c
@@ -484,7 +484,7 @@ int pim_hello_build_tlv(struct interface *ifp, uint8_t *tlv_buf,
return -1;
}
if (can_disable_join_suppression) {
- *((uint8_t *)(curr) + 4) |= 0x80; /* enable T bit */
+ *(curr + 4) |= 0x80; /* enable T bit */
}
curr = tmp;
diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c
index 07c4172f22..95b81d5dcb 100644
--- a/pimd/pim_iface.c
+++ b/pimd/pim_iface.c
@@ -900,15 +900,16 @@ struct in_addr pim_find_primary_addr(struct interface *ifp)
* So let's grab the loopbacks v4 address
* and use that as the primary address
*/
- if (!v4_addrs && v6_addrs && !if_is_loopback(ifp)) {
+ if (!v4_addrs && v6_addrs) {
struct interface *lo_ifp;
+
// DBS - Come back and check here
if (ifp->vrf_id == VRF_DEFAULT)
lo_ifp = if_lookup_by_name("lo", vrf->vrf_id);
else
lo_ifp = if_lookup_by_name(vrf->name, vrf->vrf_id);
- if (lo_ifp)
+ if (lo_ifp && (lo_ifp != ifp))
return pim_find_primary_addr(lo_ifp);
}
diff --git a/pimd/pim_sock.c b/pimd/pim_sock.c
index ae5781f0cc..f0a71c96ce 100644
--- a/pimd/pim_sock.c
+++ b/pimd/pim_sock.c
@@ -375,8 +375,7 @@ int pim_socket_recvfromto(int fd, uint8_t *buf, size_t len,
struct in_pktinfo *i =
(struct in_pktinfo *)CMSG_DATA(cmsg);
if (to)
- ((struct sockaddr_in *)to)->sin_addr =
- i->ipi_addr;
+ to->sin_addr = i->ipi_addr;
if (tolen)
*tolen = sizeof(struct sockaddr_in);
if (ifindex)
@@ -391,7 +390,7 @@ int pim_socket_recvfromto(int fd, uint8_t *buf, size_t len,
&& (cmsg->cmsg_type == IP_RECVDSTADDR)) {
struct in_addr *i = (struct in_addr *)CMSG_DATA(cmsg);
if (to)
- ((struct sockaddr_in *)to)->sin_addr = *i;
+ to->sin_addr = *i;
if (tolen)
*tolen = sizeof(struct sockaddr_in);
diff --git a/pimd/pim_tlv.c b/pimd/pim_tlv.c
index 881a3e332a..633bb207bd 100644
--- a/pimd/pim_tlv.c
+++ b/pimd/pim_tlv.c
@@ -121,20 +121,19 @@ int pim_encode_addr_ucast(uint8_t *buf, struct prefix *p)
{
switch (p->family) {
case AF_INET:
- *(uint8_t *)buf =
- PIM_MSG_ADDRESS_FAMILY_IPV4; /* notice: AF_INET !=
- PIM_MSG_ADDRESS_FAMILY_IPV4
- */
+ *buf = PIM_MSG_ADDRESS_FAMILY_IPV4; /* notice: AF_INET !=
+ PIM_MSG_ADDRESS_FAMILY_IPV4
+ */
++buf;
- *(uint8_t *)buf = 0; /* ucast IPv4 native encoding type (RFC
+ *buf = 0; /* ucast IPv4 native encoding type (RFC
4601: 4.9.1) */
++buf;
memcpy(buf, &p->u.prefix4, sizeof(struct in_addr));
return ucast_ipv4_encoding_len;
case AF_INET6:
- *(uint8_t *)buf = PIM_MSG_ADDRESS_FAMILY_IPV6;
+ *buf = PIM_MSG_ADDRESS_FAMILY_IPV6;
++buf;
- *(uint8_t *)buf = 0;
+ *buf = 0;
++buf;
memcpy(buf, &p->u.prefix6, sizeof(struct in6_addr));
return ucast_ipv6_encoding_len;
@@ -198,13 +197,13 @@ int pim_encode_addr_group(uint8_t *buf, afi_t afi, int bidir, int scope,
switch (afi) {
case AFI_IP:
- *(uint8_t *)buf = PIM_MSG_ADDRESS_FAMILY_IPV4;
+ *buf = PIM_MSG_ADDRESS_FAMILY_IPV4;
++buf;
- *(uint8_t *)buf = 0;
+ *buf = 0;
++buf;
- *(uint8_t *)buf = flags;
+ *buf = flags;
++buf;
- *(uint8_t *)buf = 32;
+ *buf = 32;
++buf;
memcpy(buf, &group, sizeof(struct in_addr));
return group_ipv4_encoding_len;
diff --git a/tests/lib/test_srcdest_table.c b/tests/lib/test_srcdest_table.c
index 935ee500a3..9d395bee89 100644
--- a/tests/lib/test_srcdest_table.c
+++ b/tests/lib/test_srcdest_table.c
@@ -391,8 +391,7 @@ static void test_state_del_one_route(struct test_state *test, struct prng *prng)
}
assert(rn);
- srcdest_rnode_prefixes(rn, (const struct prefix **)&dst_p,
- (const struct prefix **)&src_p);
+ srcdest_rnode_prefixes(rn, &dst_p, &src_p);
memcpy(&dst6_p, dst_p, sizeof(dst6_p));
if (src_p)
memcpy(&src6_p, src_p, sizeof(src6_p));
diff --git a/tests/subdir.am b/tests/subdir.am
index bce08c4034..5efdcbbd4c 100644
--- a/tests/subdir.am
+++ b/tests/subdir.am
@@ -90,6 +90,7 @@ check_PROGRAMS += \
endif
tests/lib/cli/test_commands_defun.c: vtysh/vtysh_cmd.c
+ mkdir -p tests/lib/cli
sed \
-e 's%"vtysh/vtysh\.h"%"tests/helpers/c/tests.h"%' \
-e 's/vtysh_init_cmd/test_init_cmd/' \
@@ -99,6 +100,7 @@ tests/lib/cli/test_commands_defun.c: vtysh/vtysh_cmd.c
CLEANFILES += tests/lib/cli/test_commands_defun.c
tests/isisd/test_fuzz_isis_tlv_tests.h: $(top_srcdir)/tests/isisd/test_fuzz_isis_tlv_tests.h.gz
+ mkdir -p tests/isisd
gzip -d < $(top_srcdir)/tests/isisd/test_fuzz_isis_tlv_tests.h.gz > "$@"
CLEANFILES += tests/isisd/test_fuzz_isis_tlv_tests.h
diff --git a/tests/topotests/all-protocol-startup/r1/ipv4_routes.ref b/tests/topotests/all-protocol-startup/r1/ipv4_routes.ref
index e13912f109..993b4df6a2 100644
--- a/tests/topotests/all-protocol-startup/r1/ipv4_routes.ref
+++ b/tests/topotests/all-protocol-startup/r1/ipv4_routes.ref
@@ -18,6 +18,9 @@ S>* 4.5.6.12/32 [1/0] is directly connected, r1-eth0, weight 1, XX:XX:XX
S>* 4.5.6.13/32 [1/0] unreachable (blackhole), weight 1, XX:XX:XX
S>* 4.5.6.14/32 [1/0] unreachable (blackhole), weight 1, XX:XX:XX
S 4.5.6.15/32 [255/0] via 192.168.0.2, r1-eth0, weight 1, XX:XX:XX
+S 4.5.6.16/32 [10/0] via 192.168.0.4, r1-eth0, weight 1, XX:XX:XX
+S>* 4.5.6.16/32 [5/0] via 192.168.0.2, r1-eth0, weight 1, XX:XX:XX
+S>* 4.5.6.17/32 [1/0] via 192.168.0.2, r1-eth0, weight 1, XX:XX:XX
S>* 4.5.6.7/32 [1/0] unreachable (blackhole), weight 1, XX:XX:XX
S>* 4.5.6.8/32 [1/0] unreachable (blackhole), weight 1, XX:XX:XX
S>* 4.5.6.9/32 [1/0] unreachable (ICMP unreachable), weight 1, XX:XX:XX
diff --git a/tests/topotests/all-protocol-startup/r1/zebra.conf b/tests/topotests/all-protocol-startup/r1/zebra.conf
index fbf827604f..f283590ddf 100644
--- a/tests/topotests/all-protocol-startup/r1/zebra.conf
+++ b/tests/topotests/all-protocol-startup/r1/zebra.conf
@@ -26,11 +26,20 @@ ipv6 route 4:5::6:12/128 r1-eth0
# by zebra but not installed.
ip route 4.5.6.15/32 192.168.0.2 255
ipv6 route 4:5::6:15/128 fc00:0:0:0::2 255
-
# Routes to put into a nexthop-group
ip route 1.1.1.1/32 r1-eth0
ip route 1.1.1.2/32 r1-eth1
+# Create a route that has overlapping distance
+# so we have backups
+ip route 4.5.6.16/32 192.168.0.2 5
+ip route 4.5.6.16/32 192.168.0.4 10
+
+# Create routes that have different tags
+# and how we handle it
+ip route 4.5.6.17/32 192.168.0.2 tag 9000
+ip route 4.5.6.17/32 192.168.0.2 tag 10000
+
!
interface r1-eth0
description to sw0 - no routing protocol
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 7a74b62980..3441d68731 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
@@ -233,6 +233,77 @@ def test_bgp_config_with_4byte_as_number(request):
write_test_footer(tc_name)
+def test_BGP_config_with_invalid_ASN_p2(request):
+ """
+ Configure BGP with invalid ASN(ex - 0, reserved ASN) and verify test case
+ ended up with error
+ """
+
+ tgen = get_topogen()
+ global BGP_CONVERGENCE
+
+ if BGP_CONVERGENCE != True:
+ pytest.skip("skipped because of BGP Convergence failure")
+
+ # test case name
+ tc_name = request.node.name
+ write_test_header(tc_name)
+
+ # Api call to modify AS number
+ input_dict = {
+ "r1": {"bgp": {"local_as": 0,}},
+ "r2": {"bgp": {"local_as": 0,}},
+ "r3": {"bgp": {"local_as": 0,}},
+ "r4": {"bgp": {"local_as": 64000,}},
+ }
+ result = modify_as_number(tgen, topo, input_dict)
+ try:
+ assert result is True
+ except AssertionError:
+ logger.info("Expected behaviour: {}".format(result))
+ logger.info("BGP config is not created because of invalid ASNs")
+
+ write_test_footer(tc_name)
+
+
+def test_BGP_config_with_2byteAS_and_4byteAS_number_p1(request):
+ """
+ Configure BGP with 4 byte and 2 byte ASN and verify BGP is converged
+ """
+
+ tgen = get_topogen()
+ global BGP_CONVERGENCE
+
+ if BGP_CONVERGENCE != True:
+ pytest.skip("skipped because of BGP Convergence failure")
+
+ # test case name
+ tc_name = request.node.name
+ write_test_header(tc_name)
+
+ # Api call to modify AS number
+ input_dict = {
+ "r1": {"bgp": {"local_as": 131079}},
+ "r2": {"bgp": {"local_as": 131079}},
+ "r3": {"bgp": {"local_as": 131079}},
+ "r4": {"bgp": {"local_as": 111}},
+ }
+ result = modify_as_number(tgen, topo, input_dict)
+ if result != True:
+ assert False, "Testcase " + tc_name + " :Failed \n Error: {}".format(result)
+
+ result = verify_as_numbers(tgen, topo, input_dict)
+ if result != True:
+ assert False, "Testcase " + tc_name + " :Failed \n Error: {}".format(result)
+
+ # Api call verify whether BGP is converged
+ result = verify_bgp_convergence(tgen, topo)
+ if result != True:
+ assert False, "Testcase " + tc_name + " :Failed \n Error: {}".format(result)
+
+ write_test_footer(tc_name)
+
+
def test_bgp_timers_functionality(request):
"""
Test to modify bgp timers and verify timers functionality.
diff --git a/tests/topotests/bgp-ecmp-topo2/test_ebgp_ecmp_topo2.py b/tests/topotests/bgp-ecmp-topo2/test_ebgp_ecmp_topo2.py
index bad421768c..fd3e7fd7d3 100755
--- a/tests/topotests/bgp-ecmp-topo2/test_ebgp_ecmp_topo2.py
+++ b/tests/topotests/bgp-ecmp-topo2/test_ebgp_ecmp_topo2.py
@@ -305,7 +305,8 @@ def test_modify_ecmp_max_paths(request, ecmp_num, test_type):
write_test_footer(tc_name)
-def test_ecmp_after_clear_bgp(request):
+@pytest.mark.parametrize("test_type", ["redist_static", "advertise_nw"])
+def test_ecmp_after_clear_bgp(request, test_type):
""" Verify BGP table and RIB in DUT after clear BGP routes and neighbors"""
tc_name = request.node.name
@@ -318,7 +319,7 @@ def test_ecmp_after_clear_bgp(request):
dut = "r3"
protocol = "bgp"
- static_or_nw(tgen, topo, tc_name, "redist_static", "r2")
+ static_or_nw(tgen, topo, tc_name, test_type, "r2")
for addr_type in ADDR_TYPES:
input_dict_1 = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}}
@@ -466,14 +467,10 @@ def test_ecmp_remove_redistribute_static(request):
write_test_footer(tc_name)
-def test_ecmp_shut_bgp_neighbor(request):
- """
- Disable/Shut selected paths nexthops and verify other next are installed in
- the RIB of DUT. Enable interfaces and verify RIB count.
-
- Shut BGP neigbors one by one and verify BGP and routing table updated
- accordingly in DUT
- """
+@pytest.mark.parametrize("test_type", ["redist_static", "advertise_nw"])
+def test_ecmp_shut_bgp_neighbor(request, test_type):
+ """ Shut BGP neigbors one by one and verify BGP and routing table updated
+ accordingly in DUT """
tc_name = request.node.name
write_test_header(tc_name)
@@ -485,7 +482,7 @@ def test_ecmp_shut_bgp_neighbor(request):
protocol = "bgp"
reset_config_on_routers(tgen)
- static_or_nw(tgen, topo, tc_name, "redist_static", "r2")
+ static_or_nw(tgen, topo, tc_name, test_type, "r2")
for addr_type in ADDR_TYPES:
input_dict = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}}
@@ -534,7 +531,7 @@ def test_ecmp_shut_bgp_neighbor(request):
result = interface_status(tgen, topo, input_dict_1)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
- static_or_nw(tgen, topo, tc_name, "redist_static", "r2")
+ static_or_nw(tgen, topo, tc_name, test_type, "r2")
for addr_type in ADDR_TYPES:
input_dict = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}}
diff --git a/tests/topotests/bgp-ecmp-topo2/test_ibgp_ecmp_topo2.py b/tests/topotests/bgp-ecmp-topo2/test_ibgp_ecmp_topo2.py
index 9271a780bf..94ffc71ef6 100755
--- a/tests/topotests/bgp-ecmp-topo2/test_ibgp_ecmp_topo2.py
+++ b/tests/topotests/bgp-ecmp-topo2/test_ibgp_ecmp_topo2.py
@@ -306,7 +306,8 @@ def test_modify_ecmp_max_paths(request, ecmp_num, test_type):
write_test_footer(tc_name)
-def test_ecmp_after_clear_bgp(request):
+@pytest.mark.parametrize("test_type", ["redist_static", "advertise_nw"])
+def test_ecmp_after_clear_bgp(request, test_type):
""" Verify BGP table and RIB in DUT after clear BGP routes and neighbors"""
tc_name = request.node.name
@@ -319,7 +320,7 @@ def test_ecmp_after_clear_bgp(request):
dut = "r3"
protocol = "bgp"
- static_or_nw(tgen, topo, tc_name, "redist_static", "r2")
+ static_or_nw(tgen, topo, tc_name, test_type, "r2")
for addr_type in ADDR_TYPES:
input_dict_1 = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}}
@@ -467,7 +468,8 @@ def test_ecmp_remove_redistribute_static(request):
write_test_footer(tc_name)
-def test_ecmp_shut_bgp_neighbor(request):
+@pytest.mark.parametrize("test_type", ["redist_static", "advertise_nw"])
+def test_ecmp_shut_bgp_neighbor(request, test_type):
""" Shut BGP neigbors one by one and verify BGP and routing table updated
accordingly in DUT """
@@ -481,7 +483,7 @@ def test_ecmp_shut_bgp_neighbor(request):
protocol = "bgp"
reset_config_on_routers(tgen)
- static_or_nw(tgen, topo, tc_name, "redist_static", "r2")
+ static_or_nw(tgen, topo, tc_name, test_type, "r2")
for addr_type in ADDR_TYPES:
input_dict = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}}
@@ -530,7 +532,7 @@ def test_ecmp_shut_bgp_neighbor(request):
result = interface_status(tgen, topo, input_dict_1)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
- static_or_nw(tgen, topo, tc_name, "redist_static", "r2")
+ static_or_nw(tgen, topo, tc_name, test_type, "r2")
for addr_type in ADDR_TYPES:
input_dict = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}}
diff --git a/tests/topotests/bgp_as_allow_in/bgp_as_allow_in.json b/tests/topotests/bgp_as_allow_in/bgp_as_allow_in.json
new file mode 100644
index 0000000000..943876cdac
--- /dev/null
+++ b/tests/topotests/bgp_as_allow_in/bgp_as_allow_in.json
@@ -0,0 +1,266 @@
+{
+ "address_types": [
+ "ipv4",
+ "ipv6"
+ ],
+ "ipv4base": "10.0.0.0",
+ "ipv4mask": 30,
+ "ipv6base": "fd00::",
+ "ipv6mask": 64,
+ "link_ip_start": {
+ "ipv4": "10.0.0.0",
+ "v4mask": 30,
+ "ipv6": "fd00::",
+ "v6mask": 64
+ },
+ "lo_prefix": {
+ "ipv4": "1.0.",
+ "v4mask": 32,
+ "ipv6": "2001:db8:f::",
+ "v6mask": 128
+ },
+ "routers": {
+ "r1": {
+ "links": {
+ "lo": {
+ "ipv4": "auto",
+ "ipv6": "auto",
+ "type": "loopback"
+ },
+ "r2": {
+ "ipv4": "auto",
+ "ipv6": "auto"
+ }
+ },
+ "bgp": {
+ "local_as": "200",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "r1": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "r1": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "r2": {
+ "links": {
+ "lo": {
+ "ipv4": "auto",
+ "ipv6": "auto",
+ "type": "loopback"
+ },
+ "r1": {
+ "ipv4": "auto",
+ "ipv6": "auto"
+ },
+ "r3": {
+ "ipv4": "auto",
+ "ipv6": "auto"
+ }
+ },
+ "bgp": {
+ "local_as": "100",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r1": {
+ "dest_link": {
+ "r2": {}
+ }
+ },
+ "r3": {
+ "dest_link": {
+ "r2": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r1": {
+ "dest_link": {
+ "r2": {}
+ }
+ },
+ "r3": {
+ "dest_link": {
+ "r2": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "r3": {
+ "links": {
+ "lo": {
+ "ipv4": "auto",
+ "ipv6": "auto",
+ "type": "loopback"
+ },
+ "r2": {
+ "ipv4": "auto",
+ "ipv6": "auto"
+ },
+ "r4": {
+ "ipv4": "auto",
+ "ipv6": "auto"
+ },
+ "r5": {
+ "ipv4": "auto",
+ "ipv6": "auto"
+ }
+ },
+ "bgp": {
+ "local_as": "200",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r5": {
+ "dest_link": {
+ "r3": {}
+ }
+ },
+ "r2": {
+ "dest_link": {
+ "r3": {}
+ }
+ },
+ "r4": {
+ "dest_link": {
+ "r3": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r5": {
+ "dest_link": {
+ "r3": {}
+ }
+ },
+ "r2": {
+ "dest_link": {
+ "r3": {}
+ }
+ },
+ "r4": {
+ "dest_link": {
+ "r3": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "r4": {
+ "links": {
+ "lo": {
+ "ipv4": "auto",
+ "ipv6": "auto",
+ "type": "loopback"
+ },
+ "r3": {
+ "ipv4": "auto",
+ "ipv6": "auto"
+ }
+ },
+ "bgp": {
+ "local_as": "200",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r3": {
+ "dest_link": {
+ "r4": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r3": {
+ "dest_link": {
+ "r4": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "r5": {
+ "links": {
+ "lo": {
+ "ipv4": "auto",
+ "ipv6": "auto",
+ "type": "loopback"
+ },
+ "r3": {
+ "ipv4": "auto",
+ "ipv6": "auto"
+ }
+ },
+ "bgp": {
+ "local_as": "500",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r3": {
+ "dest_link": {
+ "r5": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r3": {
+ "dest_link": {
+ "r5": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/topotests/bgp_as_allow_in/test_bgp_as_allow_in.py b/tests/topotests/bgp_as_allow_in/test_bgp_as_allow_in.py
new file mode 100755
index 0000000000..89b15c46d3
--- /dev/null
+++ b/tests/topotests/bgp_as_allow_in/test_bgp_as_allow_in.py
@@ -0,0 +1,975 @@
+#!/usr/bin/python
+
+#
+# Copyright (c) 2020 by VMware, Inc. ("VMware")
+# Used Copyright (c) 2018 by Network Device Education Foundation,
+# Inc. ("NetDEF") in this file.
+#
+# 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 VMWARE DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE 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.
+#
+
+"""
+Following tests are covered to test bgp allowas-in functionality:
+
+- Verify that routes coming from same AS are accepted only when
+ '"allowas-in" is configuerd.
+- Verify that "allowas-in" feature works per address-family/VRF
+ 'basis and doesn't impact the other AFIs.
+- Verify that the if number of occurrences of AS number in path is
+ 'more than the configured allowas-in value then we do not accept
+ 'the route.
+- Verify that when we advertise a network, learned from the same AS
+ 'via allowas-in command, to an iBGP neighbor we see multiple
+ 'occurrences.
+- Verify that when we advertise a network, learned from the same AS
+ 'via allowas-in command, to an eBGP neighbor we see multiple
+ 'occurrences of our own AS based on configured value+1.
+"""
+
+import os
+import sys
+import time
+import json
+import pytest
+
+# 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, "../lib/"))
+
+# pylint: disable=C0413
+# Import topogen and topotest helpers
+from mininet.topo import Topo
+from lib.topogen import Topogen, get_topogen
+
+# Import topoJson from lib, to create topology and initial configuration
+from lib.common_config import (
+ start_topology,
+ write_test_header,
+ write_test_footer,
+ reset_config_on_routers,
+ verify_rib,
+ create_static_routes,
+ create_route_maps,
+ check_address_types,
+ step,
+)
+from lib.topolog import logger
+from lib.bgp import (
+ verify_bgp_convergence,
+ create_router_bgp,
+ clear_bgp_and_verify,
+ verify_bgp_rib,
+)
+from lib.topojson import build_topo_from_json, build_config_from_json
+
+# Reading the data from JSON File for topology creation
+jsonFile = "{}/bgp_as_allow_in.json".format(CWD)
+try:
+ with open(jsonFile, "r") as topoJson:
+ topo = json.load(topoJson)
+except IOError:
+ assert False, "Could not read file {}".format(jsonFile)
+
+# Global variables
+BGP_CONVERGENCE = False
+ADDR_TYPES = check_address_types()
+NETWORK = {"ipv4": "2.2.2.2/32", "ipv6": "22:22::2/128"}
+NEXT_HOP_IP = {"ipv4": "Null0", "ipv6": "Null0"}
+
+
+class BGPALLOWASIN(Topo):
+ """
+ Test BGPALLOWASIN - topology 1
+
+ * `Topo`: Topology object
+ """
+
+ def build(self, *_args, **_opts):
+ """Build function"""
+ tgen = get_topogen(self)
+
+ # Building topology from json file
+ build_topo_from_json(tgen, topo)
+
+
+def setup_module(mod):
+ """
+ Sets up the pytest environment
+
+ * `mod`: module name
+ """
+
+ testsuite_run_time = time.asctime(time.localtime(time.time()))
+ logger.info("Testsuite start time: {}".format(testsuite_run_time))
+ logger.info("=" * 40)
+
+ logger.info("Running setup_module to create topology")
+
+ # This function initiates the topology build with Topogen...
+ tgen = Topogen(BGPALLOWASIN, mod.__name__)
+ # ... and here it calls Mininet initialization functions.
+
+ # Starting topology, create tmp files which are loaded to routers
+ # to start deamons and then start routers
+ start_topology(tgen)
+
+ # Creating configuration from JSON
+ build_config_from_json(tgen, topo)
+
+ # Checking BGP convergence
+ global BGP_CONVERGENCE
+ global ADDR_TYPES
+
+ # 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
+ )
+
+ logger.info("Running setup_module() done")
+
+
+def teardown_module(mod):
+ """
+ Teardown the pytest environment
+
+ * `mod`: module name
+ """
+
+ logger.info("Running teardown_module to delete topology")
+
+ tgen = get_topogen()
+
+ # Stop toplogy and Remove tmp files
+ tgen.stop_topology()
+
+ logger.info(
+ "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
+ )
+ logger.info("=" * 40)
+
+
+#####################################################
+#
+# Tests starting
+#
+#####################################################
+
+
+def test_bgp_allowas_in_p0(request):
+ """
+ Verify that routes coming from same AS are accepted only when
+ "allowas-in" is configuerd.
+
+ """
+
+ tc_name = request.node.name
+ write_test_header(tc_name)
+ tgen = get_topogen()
+ reset_config_on_routers(tgen)
+
+ # Don't run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step("Advertise prefix 2.2.2.2/32 from Router-1(AS-200).")
+ step("Advertise an ipv6 prefix 22:22::2/128 from Router-1(AS-200).")
+ # configure static routes
+ dut = "r3"
+ protocol = "bgp"
+
+ for addr_type in ADDR_TYPES:
+ # Enable static routes
+ input_dict_4 = {
+ "r1": {
+ "static_routes": [
+ {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]}
+ ]
+ }
+ }
+
+ logger.info("Configure static routes")
+ result = create_static_routes(tgen, input_dict_4)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("configure redistribute static in Router BGP in R1")
+
+ input_dict_2 = {
+ "r1": {
+ "bgp": {
+ "address_family": {
+ addr_type: {
+ "unicast": {"redistribute": [{"redist_type": "static"}]}
+ }
+ }
+ }
+ }
+ }
+ result = create_router_bgp(tgen, topo, input_dict_2)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+ step(
+ 'Check BGP table of router R3 using "sh bgp ipv4" and "sh bgp '
+ 'ipv6" command.'
+ )
+ step(
+ "We should not see prefix advertised from R1 in R3's BGP "
+ "table without allowas-in."
+ )
+ logger.info("Verifying %s routes on r3, route should not be present", addr_type)
+ result = verify_rib(
+ tgen,
+ addr_type,
+ dut,
+ input_dict_4,
+ next_hop=NEXT_HOP_IP[addr_type],
+ protocol=protocol,
+ expected=False,
+ )
+ assert result is not True, "Testcase {} : Failed \n"
+ "Expected behavior: routes should not present in rib \n"
+ "Error: {}".format(tc_name, result)
+
+ step("Configure allowas-in on R3 for R2.")
+ step("We should see the prefix advertised from R1 in R3's BGP table.")
+ # Api call to enable allowas-in in bgp process.
+ input_dict_1 = {
+ "r3": {
+ "bgp": {
+ "address_family": {
+ addr_type: {
+ "unicast": {
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "r3": {
+ "allowas-in": {"number_occurences": 1}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ result = create_router_bgp(tgen, topo, input_dict_1)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+ result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ write_test_footer(tc_name)
+
+
+def test_bgp_allowas_in_per_addr_family_p0(request):
+ """
+ Verify that "allowas-in" feature works per address-family/VRF
+ basis and doesn't impact the other AFIs.
+
+ """
+
+ # This test is applicable only for dual stack.
+ if "ipv4" not in ADDR_TYPES or "ipv6" not in ADDR_TYPES:
+ pytest.skip("NOT APPLICABLE")
+
+ tc_name = request.node.name
+ write_test_header(tc_name)
+ tgen = get_topogen()
+ reset_config_on_routers(tgen)
+
+ # Don't run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step("Advertise prefix 2.2.2.2/32 from Router-1(AS-200).")
+ step("Advertise an ipv6 prefix 22:22::2/128 from Router-1(AS-200).")
+ # configure static routes routes
+ dut = "r3"
+ protocol = "bgp"
+
+ for addr_type in ADDR_TYPES:
+ # Enable static routes
+ input_dict_4 = {
+ "r1": {
+ "static_routes": [
+ {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]}
+ ]
+ }
+ }
+
+ logger.info("Configure static routes")
+ result = create_static_routes(tgen, input_dict_4)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("configure redistribute static in Router BGP in R1")
+
+ input_dict_2 = {
+ "r1": {
+ "bgp": {
+ "address_family": {
+ addr_type: {
+ "unicast": {"redistribute": [{"redist_type": "static"}]}
+ }
+ }
+ }
+ }
+ }
+ result = create_router_bgp(tgen, topo, input_dict_2)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("Configure allowas-in on R3 for R2 under IPv4 addr-family only")
+ # Api call to enable allowas-in in bgp process.
+ input_dict_1 = {
+ "r3": {
+ "bgp": {
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "r3": {"allowas-in": {"number_occurences": 1}}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ result = create_router_bgp(tgen, topo, input_dict_1)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
+
+ static_route_ipv4 = {
+ "r1": {
+ "static_routes": [
+ {"network": NETWORK["ipv4"], "next_hop": NEXT_HOP_IP["ipv4"]}
+ ]
+ }
+ }
+
+ static_route_ipv6 = {
+ "r1": {
+ "static_routes": [
+ {"network": NETWORK["ipv6"], "next_hop": NEXT_HOP_IP["ipv6"]}
+ ]
+ }
+ }
+ step("We should see R1 advertised prefix only in IPv4 AFI " "not in IPv6 AFI.")
+ result = verify_rib(tgen, "ipv4", dut, static_route_ipv4, protocol=protocol)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
+ result = verify_rib(
+ tgen, "ipv6", dut, static_route_ipv6, protocol=protocol, expected=False
+ )
+ assert result is not True, "Testcase {} : Failed \n"
+ "Expected behavior: routes are should not be present in ipv6 rib\n"
+ " Error: {}".format(tc_name, result)
+
+ step("Repeat the same test for IPv6 AFI.")
+ step("Configure allowas-in on R3 for R2 under IPv6 addr-family only")
+ # Api call to enable allowas-in in bgp process.
+ input_dict_1 = {
+ "r3": {
+ "bgp": {
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "r3": {
+ "allowas-in": {
+ "number_occurences": 2,
+ "delete": True,
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "r3": {"allowas-in": {"number_occurences": 2}}
+ }
+ }
+ }
+ }
+ },
+ }
+ }
+ }
+ }
+ result = create_router_bgp(tgen, topo, input_dict_1)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
+ step("We should see R1 advertised prefix only in IPv6 AFI " "not in IPv4 AFI.")
+ result = verify_rib(
+ tgen, "ipv4", dut, static_route_ipv4, protocol=protocol, expected=False
+ )
+ assert result is not True, "Testcase {} : Failed \n"
+ "Expected behavior: routes should not be present in ipv4 rib\n"
+ " Error: {}".format(tc_name, result)
+ result = verify_rib(tgen, "ipv6", dut, static_route_ipv6, protocol=protocol)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
+
+ write_test_footer(tc_name)
+
+
+def test_bgp_allowas_in_no_of_occurrences_p0(request):
+ """
+ Verify that the if number of occurrences of AS number in path is
+ more than the configured allowas-in value then we do not accept
+ the route.
+
+ """
+
+ tc_name = request.node.name
+ write_test_header(tc_name)
+ tgen = get_topogen()
+ reset_config_on_routers(tgen)
+
+ # Don't run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ dut = "r3"
+ protocol = "bgp"
+
+ for addr_type in ADDR_TYPES:
+ # Enable static routes
+ static_routes = {
+ "r1": {
+ "static_routes": [
+ {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]}
+ ]
+ }
+ }
+
+ logger.info("Configure static routes")
+ result = create_static_routes(tgen, static_routes)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("configure redistribute static in Router BGP in R1")
+
+ input_dict_2 = {
+ "r1": {
+ "bgp": {
+ "address_family": {
+ addr_type: {
+ "unicast": {"redistribute": [{"redist_type": "static"}]}
+ }
+ }
+ }
+ }
+ }
+ result = create_router_bgp(tgen, topo, input_dict_2)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("Configure a route-map on R1 to prepend AS 4 times.")
+ for addr_type in ADDR_TYPES:
+ input_dict_4 = {
+ "r1": {
+ "route_maps": {
+ "ASP_{}".format(addr_type): [
+ {
+ "action": "permit",
+ "set": {
+ "path": {
+ "as_num": "200 200 200 200",
+ "as_action": "prepend",
+ }
+ },
+ }
+ ]
+ }
+ }
+ }
+ result = create_route_maps(tgen, input_dict_4)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("configure route map in out direction on R1")
+ # Configure neighbor for route map
+ input_dict_7 = {
+ "r1": {
+ "bgp": {
+ "address_family": {
+ addr_type: {
+ "unicast": {
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "r1": {
+ "route_maps": [
+ {
+ "name": "ASP_{}".format(
+ addr_type
+ ),
+ "direction": "out",
+ }
+ ]
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ result = create_router_bgp(tgen, topo, input_dict_7)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ for addr_type in ADDR_TYPES:
+ step('Configure "allowas-in 4" on R3 for R2.')
+ # Api call to enable allowas-in in bgp process.
+ input_dict_1 = {
+ "r3": {
+ "bgp": {
+ "address_family": {
+ addr_type: {
+ "unicast": {
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "r3": {
+ "allowas-in": {"number_occurences": 4}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ result = create_router_bgp(tgen, topo, input_dict_1)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+ result = verify_rib(
+ tgen, addr_type, dut, static_routes, protocol=protocol, expected=False
+ )
+ assert result is not True, "Testcase {} : Failed \n "
+ "Expected behavior: routes are should not be present in rib\n"
+ "Error: {}".format(tc_name, result)
+
+ for addr_type in ADDR_TYPES:
+ step('Configure "allowas-in 5" on R3 for R2.')
+ input_dict_1 = {
+ "r3": {
+ "bgp": {
+ "address_family": {
+ addr_type: {
+ "unicast": {
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "r3": {
+ "allowas-in": {"number_occurences": 5}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ result = create_router_bgp(tgen, topo, input_dict_1)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+ static_routes = {
+ "r1": {
+ "static_routes": [
+ {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]}
+ ]
+ }
+ }
+ result = verify_rib(tgen, addr_type, dut, static_routes, protocol=protocol)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ write_test_footer(tc_name)
+
+
+def test_bgp_allowas_in_sameastoibgp_p1(request):
+ """
+ Verify that when we advertise a network, learned from the same AS
+ via allowas-in command, to an iBGP neighbor we see multiple
+ occurrences.
+
+ """
+
+ tc_name = request.node.name
+ write_test_header(tc_name)
+ tgen = get_topogen()
+ reset_config_on_routers(tgen)
+
+ # Don't run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ dut = "r3"
+ protocol = "bgp"
+
+ for addr_type in ADDR_TYPES:
+ # Enable static routes
+ static_routes = {
+ "r1": {
+ "static_routes": [
+ {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]}
+ ]
+ }
+ }
+
+ logger.info("Configure static routes")
+ result = create_static_routes(tgen, static_routes)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("configure redistribute static in Router BGP in R1")
+
+ input_dict_2 = {
+ "r1": {
+ "bgp": {
+ "address_family": {
+ addr_type: {
+ "unicast": {"redistribute": [{"redist_type": "static"}]}
+ }
+ }
+ }
+ }
+ }
+ result = create_router_bgp(tgen, topo, input_dict_2)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("Configure a route-map on R2 to prepend AS 2 times.")
+ for addr_type in ADDR_TYPES:
+ input_dict_4 = {
+ "r2": {
+ "route_maps": {
+ "ASP_{}".format(addr_type): [
+ {
+ "action": "permit",
+ "set": {
+ "path": {"as_num": "200 200", "as_action": "prepend"}
+ },
+ }
+ ]
+ }
+ }
+ }
+ result = create_route_maps(tgen, input_dict_4)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("configure route map in out direction on R2")
+ # Configure neighbor for route map
+ input_dict_7 = {
+ "r2": {
+ "bgp": {
+ "address_family": {
+ addr_type: {
+ "unicast": {
+ "neighbor": {
+ "r3": {
+ "dest_link": {
+ "r2": {
+ "route_maps": [
+ {
+ "name": "ASP_{}".format(
+ addr_type
+ ),
+ "direction": "out",
+ }
+ ]
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ result = create_router_bgp(tgen, topo, input_dict_7)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step('Configure "allowas-in 3" on R3 for R1.')
+ input_dict_1 = {
+ "r3": {
+ "bgp": {
+ "address_family": {
+ addr_type: {
+ "unicast": {
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "r3": {
+ "allowas-in": {"number_occurences": 3}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ result = create_router_bgp(tgen, topo, input_dict_1)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ input_dict_1 = {
+ "r4": {
+ "bgp": {
+ "address_family": {
+ addr_type: {
+ "unicast": {
+ "neighbor": {
+ "r3": {
+ "dest_link": {
+ "r4": {
+ "allowas-in": {"number_occurences": 3}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ result = create_router_bgp(tgen, topo, input_dict_1)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ static_routes = {
+ "r1": {
+ "static_routes": [
+ {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]}
+ ]
+ }
+ }
+ dut = "r4"
+ path = "100 200 200 200"
+ result = verify_bgp_rib(tgen, addr_type, dut, static_routes, aspath=path)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ write_test_footer(tc_name)
+
+
+def test_bgp_allowas_in_sameastoebgp_p1(request):
+ """
+ Verify that when we advertise a network, learned from the same AS
+ via allowas-in command, to an eBGP neighbor we see multiple
+ occurrences of our own AS based on configured value+1.
+
+ """
+
+ tc_name = request.node.name
+ write_test_header(tc_name)
+ tgen = get_topogen()
+ reset_config_on_routers(tgen)
+
+ # Don't run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ dut = "r3"
+ protocol = "bgp"
+
+ for addr_type in ADDR_TYPES:
+ # Enable static routes
+ static_routes = {
+ "r1": {
+ "static_routes": [
+ {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]}
+ ]
+ }
+ }
+
+ logger.info("Configure static routes")
+ result = create_static_routes(tgen, static_routes)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("configure redistribute static in Router BGP in R1")
+
+ input_dict_2 = {
+ "r1": {
+ "bgp": {
+ "address_family": {
+ addr_type: {
+ "unicast": {"redistribute": [{"redist_type": "static"}]}
+ }
+ }
+ }
+ }
+ }
+ result = create_router_bgp(tgen, topo, input_dict_2)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("Configure a route-map on R2 to prepend AS 2 times.")
+ for addr_type in ADDR_TYPES:
+ input_dict_4 = {
+ "r2": {
+ "route_maps": {
+ "ASP_{}".format(addr_type): [
+ {
+ "action": "permit",
+ "set": {
+ "path": {"as_num": "200 200", "as_action": "prepend"}
+ },
+ }
+ ]
+ }
+ }
+ }
+ result = create_route_maps(tgen, input_dict_4)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("configure route map in out direction on R2")
+ # Configure neighbor for route map
+ input_dict_7 = {
+ "r2": {
+ "bgp": {
+ "address_family": {
+ addr_type: {
+ "unicast": {
+ "neighbor": {
+ "r3": {
+ "dest_link": {
+ "r2": {
+ "route_maps": [
+ {
+ "name": "ASP_{}".format(
+ addr_type
+ ),
+ "direction": "out",
+ }
+ ]
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ result = create_router_bgp(tgen, topo, input_dict_7)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ for addr_type in ADDR_TYPES:
+ step('Configure "allowas-in 3" on R3 for R1.')
+ input_dict_1 = {
+ "r3": {
+ "bgp": {
+ "address_family": {
+ addr_type: {
+ "unicast": {
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "r3": {
+ "allowas-in": {"number_occurences": 3}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ result = create_router_bgp(tgen, topo, input_dict_1)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+ static_routes = {
+ "r1": {
+ "static_routes": [
+ {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]}
+ ]
+ }
+ }
+ dut = "r5"
+ path = "200 100 200 200 200"
+ result = verify_bgp_rib(tgen, addr_type, dut, static_routes, aspath=path)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+ write_test_footer(tc_name)
+
+
+if __name__ == "__main__":
+ args = ["-s"] + sys.argv[1:]
+ sys.exit(pytest.main(args))
diff --git a/tests/topotests/bgp_communities_topo1/bgp_communities.json b/tests/topotests/bgp_communities_topo1/bgp_communities.json
new file mode 100644
index 0000000000..da6aec239f
--- /dev/null
+++ b/tests/topotests/bgp_communities_topo1/bgp_communities.json
@@ -0,0 +1,175 @@
+{
+ "address_types": [
+ "ipv4",
+ "ipv6"
+ ],
+ "ipv4base": "10.0.0.0",
+ "ipv4mask": 30,
+ "ipv6base": "fd00::",
+ "ipv6mask": 64,
+ "link_ip_start": {
+ "ipv4": "10.0.0.0",
+ "v4mask": 30,
+ "ipv6": "fd00::",
+ "v6mask": 64
+ },
+ "lo_prefix": {
+ "ipv4": "1.0.",
+ "v4mask": 32,
+ "ipv6": "2001:db8:f::",
+ "v6mask": 128
+ },
+ "routers": {
+ "r1": {
+ "links": {
+ "lo": {
+ "ipv4": "auto",
+ "ipv6": "auto",
+ "type": "loopback"
+ },
+ "r2": {
+ "ipv4": "auto",
+ "ipv6": "auto"
+ },
+ "r0": {
+ "ipv4": "auto",
+ "ipv6": "auto"
+ }
+ },
+ "bgp": {
+ "local_as": "100",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "r1": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "r1": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "r2": {
+ "links": {
+ "lo": {
+ "ipv4": "auto",
+ "ipv6": "auto",
+ "type": "loopback"
+ },
+ "r1": {
+ "ipv4": "auto",
+ "ipv6": "auto"
+ },
+ "r3": {
+ "ipv4": "auto",
+ "ipv6": "auto"
+ }
+ },
+ "bgp": {
+ "local_as": "200",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r1": {
+ "dest_link": {
+ "r2": {}
+ }
+ },
+ "r3": {
+ "dest_link": {
+ "r2": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r1": {
+ "dest_link": {
+ "r2": {}
+ }
+ },
+ "r3": {
+ "dest_link": {
+ "r2": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "r3": {
+ "links": {
+ "lo": {
+ "ipv4": "auto",
+ "ipv6": "auto",
+ "type": "loopback"
+ },
+ "r2": {
+ "ipv4": "auto",
+ "ipv6": "auto"
+ }
+ },
+ "bgp": {
+ "local_as": "300",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "r3": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "r3": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "r0": {
+ "links": {
+ "lo": {
+ "ipv4": "auto",
+ "ipv6": "auto",
+ "type": "loopback"
+ },
+ "r1": {
+ "ipv4": "auto",
+ "ipv6": "auto"
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/topotests/bgp_communities_topo1/test_bgp_communities.py b/tests/topotests/bgp_communities_topo1/test_bgp_communities.py
new file mode 100644
index 0000000000..7d960d6916
--- /dev/null
+++ b/tests/topotests/bgp_communities_topo1/test_bgp_communities.py
@@ -0,0 +1,635 @@
+#!/usr/bin/python
+
+#
+# Copyright (c) 2020 by VMware, Inc. ("VMware")
+# Used Copyright (c) 2018 by Network Device Education Foundation,
+# Inc. ("NetDEF") in this file.
+#
+# 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 VMWARE DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE 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.
+#
+
+"""
+Following tests are covered to test bgp community functionality:
+- Verify routes are not advertised when NO-ADVERTISE Community is applied
+
+"""
+
+import os
+import sys
+import time
+import json
+import pytest
+
+# 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 mininet.topo import Topo
+from lib.topogen import Topogen, get_topogen
+
+# Import topoJson from lib, to create topology and initial configuration
+from lib.common_config import (
+ start_topology,
+ write_test_header,
+ write_test_footer,
+ reset_config_on_routers,
+ verify_rib,
+ create_static_routes,
+ check_address_types,
+ step,
+ create_route_maps,
+ create_prefix_lists,
+ create_route_maps,
+)
+from lib.topolog import logger
+from lib.bgp import (
+ verify_bgp_convergence,
+ create_router_bgp,
+ clear_bgp_and_verify,
+ verify_bgp_rib,
+)
+from lib.topojson import build_topo_from_json, build_config_from_json
+from copy import deepcopy
+
+# Reading the data from JSON File for topology creation
+jsonFile = "{}/bgp_communities.json".format(CWD)
+try:
+ with open(jsonFile, "r") as topoJson:
+ topo = json.load(topoJson)
+except IOError:
+ assert False, "Could not read file {}".format(jsonFile)
+
+# Global variables
+BGP_CONVERGENCE = False
+ADDR_TYPES = check_address_types()
+NETWORK = {"ipv4": "2.2.2.2/32", "ipv6": "22:22::2/128"}
+NEXT_HOP_IP = {}
+
+
+class BGPCOMMUNITIES(Topo):
+ """
+ Test BGPCOMMUNITIES - topology 1
+
+ * `Topo`: Topology object
+ """
+
+ def build(self, *_args, **_opts):
+ """Build function"""
+ tgen = get_topogen(self)
+
+ # Building topology from json file
+ build_topo_from_json(tgen, topo)
+
+
+def setup_module(mod):
+ """
+ Sets up the pytest environment
+
+ * `mod`: module name
+ """
+
+ testsuite_run_time = time.asctime(time.localtime(time.time()))
+ logger.info("Testsuite start time: {}".format(testsuite_run_time))
+ logger.info("=" * 40)
+
+ logger.info("Running setup_module to create topology")
+
+ # This function initiates the topology build with Topogen...
+ tgen = Topogen(BGPCOMMUNITIES, mod.__name__)
+ # ... and here it calls Mininet initialization functions.
+
+ # Starting topology, create tmp files which are loaded to routers
+ # to start deamons and then start routers
+ start_topology(tgen)
+
+ # Creating configuration from JSON
+ build_config_from_json(tgen, topo)
+
+ # Checking BGP convergence
+ global BGP_CONVERGENCE
+ global ADDR_TYPES
+
+ # 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
+ )
+
+ logger.info("Running setup_module() done")
+
+
+def teardown_module(mod):
+ """
+ Teardown the pytest environment
+
+ * `mod`: module name
+ """
+
+ logger.info("Running teardown_module to delete topology")
+
+ tgen = get_topogen()
+
+ # Stop toplogy and Remove tmp files
+ tgen.stop_topology()
+
+ logger.info(
+ "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
+ )
+ logger.info("=" * 40)
+
+
+#####################################################
+#
+# Tests starting
+#
+#####################################################
+
+
+def test_bgp_no_advertise_community_p0(request):
+ """
+ Verify routes are not advertised when NO-ADVERTISE Community is applied
+
+ """
+
+ tc_name = request.node.name
+ write_test_header(tc_name)
+ tgen = get_topogen()
+ reset_config_on_routers(tgen)
+
+ # Don't run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ NEXT_HOP_IP = {
+ "ipv4": topo["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0],
+ "ipv6": topo["routers"]["r0"]["links"]["r1"]["ipv6"].split("/")[0],
+ }
+
+ # configure static routes
+ dut = "r3"
+ protocol = "bgp"
+
+ for addr_type in ADDR_TYPES:
+ # Enable static routes
+ input_dict = {
+ "r1": {
+ "static_routes": [
+ {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]}
+ ]
+ }
+ }
+
+ logger.info("Configure static routes")
+ result = create_static_routes(tgen, input_dict)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("configure redistribute static and connected in Router BGP " "in R1")
+
+ input_dict_2 = {
+ "r1": {
+ "bgp": {
+ "address_family": {
+ addr_type: {
+ "unicast": {
+ "redistribute": [
+ {"redist_type": "static"},
+ {"redist_type": "connected"},
+ ]
+ }
+ }
+ }
+ }
+ }
+ }
+ result = create_router_bgp(tgen, topo, input_dict_2)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "BGP neighbors are up, static and connected route advertised from"
+ " R1 are present on R2 BGP table and RIB using show ip bgp and "
+ " show ip route"
+ )
+ step(
+ "Static and connected route advertised from R1 are present on R3"
+ " BGP table and RIB using show ip bgp and show ip route"
+ )
+
+ dut = "r3"
+ protocol = "bgp"
+ result = verify_bgp_rib(tgen, addr_type, dut, input_dict)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("Configure prefix list P1 on R2 to permit route coming from R1")
+ # Create ip prefix list
+ input_dict_2 = {
+ "r2": {
+ "prefix_lists": {
+ addr_type: {
+ "pf_list_1_{}".format(addr_type): [
+ {"seqid": 10, "network": "any", "action": "permit"}
+ ]
+ }
+ }
+ }
+ }
+ result = create_prefix_lists(tgen, input_dict_2)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ # Create route map
+ input_dict_3 = {
+ "r2": {
+ "route_maps": {
+ "rmap_match_pf_1_{}".format(addr_type): [
+ {
+ "action": "permit",
+ "seq_id": "5",
+ "match": {
+ addr_type: {"prefix_lists": "pf_list_1_" + addr_type}
+ },
+ "set": {"community": {"num": "no-advertise"}},
+ }
+ ]
+ }
+ }
+ }
+ result = create_route_maps(tgen, input_dict_3)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+ step(
+ "Apply route-map RM1 on R2, R2 to R3 BGP neighbor with no"
+ " advertise community"
+ )
+ # Configure neighbor for route map
+ input_dict_4 = {
+ "r2": {
+ "bgp": {
+ "address_family": {
+ addr_type: {
+ "unicast": {
+ "neighbor": {
+ "r1": {
+ "dest_link": {
+ "r2": {
+ "route_maps": [
+ {
+ "name": "rmap_match_pf_1_"
+ + addr_type,
+ "direction": "in",
+ }
+ ]
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ result = create_router_bgp(tgen, topo, input_dict_4)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "After advertising no advertise community to BGP neighbor "
+ "static and connected router got removed from R3 verify using "
+ "show ip bgp & show ip route"
+ )
+
+ result = verify_bgp_rib(tgen, addr_type, dut, input_dict, expected=False)
+ assert result is not True, "Testcase {} : Failed \n "
+ " Routes still present in R3 router. Error: {}".format(tc_name, result)
+
+ result = verify_rib(
+ tgen, addr_type, dut, input_dict, protocol=protocol, expected=False
+ )
+ assert result is not True, "Testcase {} : Failed \n "
+ " Routes still present in R3 router. Error: {}".format(tc_name, result)
+
+ step("Remove and Add no advertise community")
+ # Configure neighbor for route map
+ input_dict_4 = {
+ "r2": {
+ "bgp": {
+ "address_family": {
+ addr_type: {
+ "unicast": {
+ "neighbor": {
+ "r1": {
+ "dest_link": {
+ "r2": {
+ "route_maps": [
+ {
+ "name": "rmap_match_pf_1_"
+ + addr_type,
+ "direction": "in",
+ "delete": True,
+ }
+ ]
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ result = create_router_bgp(tgen, topo, input_dict_4)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "After removing no advertise community from BGP neighbor "
+ "static and connected router got advertised to R3 and "
+ "removing route-map, verify route using show ip bgp"
+ " and show ip route"
+ )
+
+ result = verify_bgp_rib(tgen, addr_type, dut, input_dict)
+ assert result is True, "Testcase {} : Failed \n "
+ " Routes still present in R3 router. Error: {}".format(tc_name, result)
+
+ result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
+ assert result is True, "Testcase {} : Failed \n "
+ " Routes still present in R3 router. Error: {}".format(tc_name, result)
+
+ step("Repeat above steps when IBGP nbr configured between R1, R2 & R2, R3")
+ topo1 = deepcopy(topo)
+
+ topo1["routers"]["r1"]["bgp"]["local_as"] = "100"
+ topo1["routers"]["r2"]["bgp"]["local_as"] = "100"
+ topo1["routers"]["r3"]["bgp"]["local_as"] = "100"
+
+ for rtr in ["r1", "r2", "r3"]:
+ if "bgp" in topo1["routers"][rtr].keys():
+ delete_bgp = {rtr: {"bgp": {"delete": True}}}
+ result = create_router_bgp(tgen, topo1, delete_bgp)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+ config_bgp = {
+ rtr: {"bgp": {"local_as": topo1["routers"][rtr]["bgp"]["local_as"]}}
+ }
+ result = create_router_bgp(tgen, topo1, config_bgp)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ build_config_from_json(tgen, topo1, save_bkup=False)
+
+ step("verify bgp convergence before starting test case")
+
+ bgp_convergence = verify_bgp_convergence(tgen, topo1)
+ assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, bgp_convergence
+ )
+
+ # configure static routes
+ dut = "r3"
+ protocol = "bgp"
+
+ for addr_type in ADDR_TYPES:
+ # Enable static routes
+ input_dict = {
+ "r1": {
+ "static_routes": [
+ {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]}
+ ]
+ }
+ }
+
+ logger.info("Configure static routes")
+ result = create_static_routes(tgen, input_dict)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("configure redistribute static and connected in Router " "BGP in R1")
+
+ input_dict_2 = {
+ "r1": {
+ "bgp": {
+ "address_family": {
+ addr_type: {
+ "unicast": {
+ "redistribute": [
+ {"redist_type": "static"},
+ {"redist_type": "connected"},
+ ]
+ }
+ }
+ }
+ }
+ }
+ }
+ result = create_router_bgp(tgen, topo, input_dict_2)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "BGP neighbors are up, static and connected route advertised from"
+ " R1 are present on R2 BGP table and RIB using show ip bgp and "
+ " show ip route"
+ )
+ step(
+ "Static and connected route advertised from R1 are present on R3"
+ " BGP table and RIB using show ip bgp and show ip route"
+ )
+
+ dut = "r2"
+ protocol = "bgp"
+ result = verify_bgp_rib(tgen, addr_type, dut, input_dict)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("Configure prefix list P1 on R2 to permit route coming from R1")
+ # Create ip prefix list
+ input_dict_2 = {
+ "r2": {
+ "prefix_lists": {
+ addr_type: {
+ "pf_list_1_{}".format(addr_type): [
+ {"seqid": 10, "network": "any", "action": "permit"}
+ ]
+ }
+ }
+ }
+ }
+ result = create_prefix_lists(tgen, input_dict_2)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ # Create route map
+ input_dict_3 = {
+ "r2": {
+ "route_maps": {
+ "rmap_match_pf_1_{}".format(addr_type): [
+ {
+ "action": "permit",
+ "seq_id": "5",
+ "match": {
+ addr_type: {"prefix_lists": "pf_list_1_" + addr_type}
+ },
+ "set": {"community": {"num": "no-advertise"}},
+ }
+ ]
+ }
+ }
+ }
+ result = create_route_maps(tgen, input_dict_3)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+ step(
+ "Apply route-map RM1 on R2, R2 to R3 BGP neighbor with no"
+ " advertise community"
+ )
+
+ # Configure neighbor for route map
+ input_dict_4 = {
+ "r2": {
+ "bgp": {
+ "address_family": {
+ addr_type: {
+ "unicast": {
+ "neighbor": {
+ "r1": {
+ "dest_link": {
+ "r2": {
+ "route_maps": [
+ {
+ "name": "rmap_match_pf_1_"
+ + addr_type,
+ "direction": "in",
+ }
+ ]
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ result = create_router_bgp(tgen, topo, input_dict_4)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "After advertising no advertise community to BGP neighbor "
+ "static and connected router got removed from R3 verify using "
+ "show ip bgp & show ip route"
+ )
+
+ result = verify_bgp_rib(tgen, addr_type, dut, input_dict)
+ assert result is True, "Testcase {} : Failed \n "
+ " Routes still present in R3 router. Error: {}".format(tc_name, result)
+
+ result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
+ assert result is True, "Testcase {} : Failed \n "
+ " Routes still present in R3 router. Error: {}".format(tc_name, result)
+
+ step("Remove and Add no advertise community")
+ # Configure neighbor for route map
+ input_dict_4 = {
+ "r2": {
+ "bgp": {
+ "address_family": {
+ addr_type: {
+ "unicast": {
+ "neighbor": {
+ "r1": {
+ "dest_link": {
+ "r2": {
+ "route_maps": [
+ {
+ "name": "rmap_match_pf_1_"
+ + addr_type,
+ "direction": "in",
+ "delete": True,
+ }
+ ]
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ result = create_router_bgp(tgen, topo, input_dict_4)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "After removing no advertise community from BGP neighbor "
+ "static and connected router got advertised to R3 and "
+ "removing route verify using show ip bgp and "
+ " show ip route"
+ )
+
+ result = verify_bgp_rib(tgen, addr_type, dut, input_dict)
+ assert result is True, "Testcase {} : Failed \n "
+ " Routes still present in R3 router. Error: {}".format(tc_name, result)
+
+ result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
+ assert result is True, "Testcase {} : Failed \n "
+ " Routes still present in R3 router. Error: {}".format(tc_name, result)
+
+ write_test_footer(tc_name)
+
+
+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 d183fb9f60..b2cd2d284d 100644
--- a/tests/topotests/lib/bgp.py
+++ b/tests/topotests/lib/bgp.py
@@ -33,6 +33,7 @@ from lib.common_config import (
load_config_to_router,
check_address_types,
generate_ips,
+ validate_ip_address,
find_interface_with_greater_ip,
run_frr_cmd,
retry,
@@ -82,6 +83,9 @@ def create_router_bgp(tgen, topo, input_dict=None, build=False):
"holddowntimer": 180,
"dest_link": {
"r4": {
+ "allowas-in": {
+ "number_occurences":2
+ },
"prefix_lists": [
{
"name": "pf_list_1",
@@ -469,6 +473,7 @@ def __create_bgp_unicast_address_family(
prefix_lists = peer.setdefault("prefix_lists", {})
route_maps = peer.setdefault("route_maps", {})
no_send_community = peer.setdefault("no_send_community", None)
+ allowas_in = peer.setdefault("allowas-in", None)
# next-hop-self
if next_hop_self:
@@ -483,6 +488,13 @@ def __create_bgp_unicast_address_family(
"no {} send-community {}".format(neigh_cxt, no_send_community)
)
+ if "allowas_in" in peer:
+ allow_as_in = peer["allowas_in"]
+ config_data.append("{} allowas-in {}".format(neigh_cxt, allow_as_in))
+
+ if "no_allowas_in" in peer:
+ allow_as_in = peer["no_allowas_in"]
+ config_data.append("no {} allowas-in {}".format(neigh_cxt, allow_as_in))
if prefix_lists:
for prefix_list in prefix_lists:
name = prefix_list.setdefault("name", {})
@@ -517,6 +529,17 @@ def __create_bgp_unicast_address_family(
cmd = "no {}".format(cmd)
config_data.append(cmd)
+ if allowas_in:
+ number_occurences = allowas_in.setdefault("number_occurences", {})
+ del_action = allowas_in.setdefault("delete", False)
+
+ cmd = "{} allowas-in {}".format(neigh_cxt, number_occurences)
+
+ if del_action:
+ cmd = "no {}".format(cmd)
+
+ config_data.append(cmd)
+
return config_data
@@ -616,6 +639,9 @@ def verify_bgp_convergence(tgen, topo):
logger.debug("Entering lib API: verify_bgp_convergence()")
for router, rnode in tgen.routers().iteritems():
+ if "bgp" not in topo["routers"][router]:
+ continue
+
logger.info("Verifying BGP Convergence on router %s", router)
show_bgp_json = run_frr_cmd(rnode, "show bgp summary json", isjson=True)
# Verifying output dictionary show_bgp_json is empty or not
@@ -929,7 +955,6 @@ def clear_bgp_and_verify(tgen, topo, router):
)
return errormsg
- logger.info(peer_uptime_before_clear_bgp)
# Clearing BGP
logger.info("Clearing BGP neighborship for router %s..", router)
for addr_type in bgp_addr_type.keys():
@@ -1008,7 +1033,7 @@ def clear_bgp_and_verify(tgen, topo, router):
" router {}".format(router)
)
return errormsg
- logger.info(peer_uptime_after_clear_bgp)
+
# Comparing peerUptimeEstablishedEpoch dictionaries
if peer_uptime_before_clear_bgp != peer_uptime_after_clear_bgp:
logger.info("BGP neighborship is reset after clear BGP on router %s", router)
@@ -1679,3 +1704,501 @@ def verify_best_path_as_per_admin_distance(
logger.info("Exiting lib API: verify_best_path_as_per_admin_distance()")
return True
+
+
+@retry(attempts=5, wait=2, return_is_str=True, initial_wait=2)
+def verify_bgp_rib(tgen, addr_type, dut, input_dict, next_hop=None, aspath=None):
+ """
+ This API is to verify whether bgp rib has any
+ matching route for a nexthop.
+
+ Parameters
+ ----------
+ * `tgen`: topogen object
+ * `dut`: input dut router name
+ * `addr_type` : ip type ipv4/ipv6
+ * `input_dict` : input dict, has details of static routes
+ * `next_hop`[optional]: next_hop which needs to be verified,
+ default = static
+ * 'aspath'[optional]: aspath which needs to be verified
+
+ Usage
+ -----
+ dut = 'r1'
+ next_hop = "192.168.1.10"
+ input_dict = topo['routers']
+ aspath = "100 200 300"
+ result = verify_bgp_rib(tgen, addr_type, dut, tgen, input_dict,
+ next_hop, aspath)
+
+ Returns
+ -------
+ errormsg(str) or True
+ """
+
+ logger.debug("Entering lib API: verify_bgp_rib()")
+
+ router_list = tgen.routers()
+ additional_nexthops_in_required_nhs = []
+ list1 = []
+ list2 = []
+ for routerInput in input_dict.keys():
+ for router, rnode in router_list.iteritems():
+ if router != dut:
+ continue
+
+ # Verifying RIB routes
+ command = "show bgp"
+
+ # Static routes
+ sleep(2)
+ logger.info("Checking router {} BGP RIB:".format(dut))
+
+ if "static_routes" in input_dict[routerInput]:
+ static_routes = input_dict[routerInput]["static_routes"]
+
+ for static_route in static_routes:
+ found_routes = []
+ missing_routes = []
+ st_found = False
+ nh_found = False
+ vrf = static_route.setdefault("vrf", None)
+ if vrf:
+ cmd = "{} vrf {} {}".format(command, vrf, addr_type)
+
+ else:
+ cmd = "{} {}".format(command, addr_type)
+
+ cmd = "{} json".format(cmd)
+
+ rib_routes_json = run_frr_cmd(rnode, cmd, isjson=True)
+
+ # Verifying output dictionary rib_routes_json is not empty
+ if bool(rib_routes_json) == False:
+ errormsg = "No route found in rib of router {}..".format(router)
+ return errormsg
+
+ network = static_route["network"]
+
+ if "no_of_ip" in static_route:
+ no_of_ip = static_route["no_of_ip"]
+ else:
+ no_of_ip = 1
+
+ # Generating IPs for verification
+ ip_list = generate_ips(network, no_of_ip)
+
+ for st_rt in ip_list:
+ st_rt = str(ipaddr.IPNetwork(unicode(st_rt)))
+
+ _addr_type = validate_ip_address(st_rt)
+ if _addr_type != addr_type:
+ continue
+
+ if st_rt in rib_routes_json["routes"]:
+ st_found = True
+ found_routes.append(st_rt)
+
+ if next_hop:
+ if not isinstance(next_hop, list):
+ next_hop = [next_hop]
+ list1 = next_hop
+ found_hops = [
+ rib_r["ip"]
+ for rib_r in rib_routes_json["routes"][st_rt][0][
+ "nexthops"
+ ]
+ ]
+ list2 = found_hops
+ missing_list_of_nexthops = set(list2).difference(list1)
+ additional_nexthops_in_required_nhs = set(
+ list1
+ ).difference(list2)
+
+ if list2:
+ if additional_nexthops_in_required_nhs:
+ logger.info(
+ "Missing nexthop %s for route"
+ " %s in RIB of router %s\n",
+ additional_nexthops_in_required_nhs,
+ st_rt,
+ dut,
+ )
+ errormsg = (
+ "Nexthop {} is Missing for "
+ "route {} in RIB of router {}\n".format(
+ additional_nexthops_in_required_nhs,
+ st_rt,
+ dut,
+ )
+ )
+ return errormsg
+ else:
+ nh_found = True
+ if aspath:
+ found_paths = rib_routes_json["routes"][st_rt][0][
+ "path"
+ ]
+ if aspath == found_paths:
+ aspath_found = True
+ logger.info(
+ "Found AS path {} for route"
+ " {} in RIB of router "
+ "{}\n".format(aspath, st_rt, dut)
+ )
+ else:
+ errormsg = (
+ "AS Path {} is missing for route"
+ "for route {} in RIB of router {}\n".format(
+ aspath, st_rt, dut
+ )
+ )
+ return errormsg
+
+ else:
+ missing_routes.append(st_rt)
+
+ if nh_found:
+ logger.info(
+ "Found next_hop {} for all bgp"
+ " routes in RIB of"
+ " router {}\n".format(next_hop, router)
+ )
+
+ if len(missing_routes) > 0:
+ errormsg = (
+ "Missing route in RIB of router {}, "
+ "routes: {}\n".format(dut, missing_routes)
+ )
+ return errormsg
+
+ if found_routes:
+ logger.info(
+ "Verified routes in router {} BGP RIB, "
+ "found routes are: {} \n".format(dut, found_routes)
+ )
+ continue
+
+ if "bgp" not in input_dict[routerInput]:
+ continue
+
+ # Advertise networks
+ bgp_data_list = input_dict[routerInput]["bgp"]
+
+ if type(bgp_data_list) is not list:
+ bgp_data_list = [bgp_data_list]
+
+ for bgp_data in bgp_data_list:
+ vrf_id = bgp_data.setdefault("vrf", None)
+ if vrf_id:
+ cmd = "{} vrf {} {}".format(command, vrf_id, addr_type)
+ else:
+ cmd = "{} {}".format(command, addr_type)
+
+ cmd = "{} json".format(cmd)
+
+ rib_routes_json = run_frr_cmd(rnode, cmd, isjson=True)
+
+ # Verifying output dictionary rib_routes_json is not empty
+ if bool(rib_routes_json) == False:
+ errormsg = "No route found in rib of router {}..".format(router)
+ return errormsg
+
+ bgp_net_advertise = bgp_data["address_family"][addr_type]["unicast"]
+ advertise_network = bgp_net_advertise.setdefault(
+ "advertise_networks", []
+ )
+
+ for advertise_network_dict in advertise_network:
+ found_routes = []
+ missing_routes = []
+ found = False
+
+ network = advertise_network_dict["network"]
+
+ if "no_of_network" in advertise_network_dict:
+ no_of_network = advertise_network_dict["no_of_network"]
+ else:
+ no_of_network = 1
+
+ # Generating IPs for verification
+ ip_list = generate_ips(network, no_of_network)
+
+ for st_rt in ip_list:
+ st_rt = str(ipaddr.IPNetwork(unicode(st_rt)))
+
+ _addr_type = validate_ip_address(st_rt)
+ if _addr_type != addr_type:
+ continue
+
+ if st_rt in rib_routes_json["routes"]:
+ found = True
+ found_routes.append(st_rt)
+ else:
+ found = False
+ missing_routes.append(st_rt)
+
+ if len(missing_routes) > 0:
+ errormsg = (
+ "Missing route in BGP RIB of router {},"
+ " are: {}\n".format(dut, missing_routes)
+ )
+ return errormsg
+
+ if found_routes:
+ logger.info(
+ "Verified routes in router {} BGP RIB, found "
+ "routes are: {}\n".format(dut, found_routes)
+ )
+
+ logger.debug("Exiting lib API: verify_bgp_rib()")
+ return True
+
+
+@retry(attempts=5, wait=2, return_is_str=True, initial_wait=2)
+def verify_bgp_rib(tgen, addr_type, dut, input_dict, next_hop=None, aspath=None):
+ """
+ This API is to verify whether bgp rib has any
+ matching route for a nexthop.
+
+ Parameters
+ ----------
+ * `tgen`: topogen object
+ * `dut`: input dut router name
+ * `addr_type` : ip type ipv4/ipv6
+ * `input_dict` : input dict, has details of static routes
+ * `next_hop`[optional]: next_hop which needs to be verified,
+ default = static
+ * 'aspath'[optional]: aspath which needs to be verified
+
+ Usage
+ -----
+ dut = 'r1'
+ next_hop = "192.168.1.10"
+ input_dict = topo['routers']
+ aspath = "100 200 300"
+ result = verify_bgp_rib(tgen, addr_type, dut, tgen, input_dict,
+ next_hop, aspath)
+
+ Returns
+ -------
+ errormsg(str) or True
+ """
+
+ logger.debug("Entering lib API: verify_bgp_rib()")
+
+ router_list = tgen.routers()
+ additional_nexthops_in_required_nhs = []
+ list1 = []
+ list2 = []
+ for routerInput in input_dict.keys():
+ for router, rnode in router_list.iteritems():
+ if router != dut:
+ continue
+
+ # Verifying RIB routes
+ command = "show bgp"
+
+ # Static routes
+ sleep(2)
+ logger.info("Checking router {} BGP RIB:".format(dut))
+
+ if "static_routes" in input_dict[routerInput]:
+ static_routes = input_dict[routerInput]["static_routes"]
+
+ for static_route in static_routes:
+ found_routes = []
+ missing_routes = []
+ st_found = False
+ nh_found = False
+ vrf = static_route.setdefault("vrf", None)
+ if vrf:
+ cmd = "{} vrf {} {}".format(command, vrf, addr_type)
+
+ else:
+ cmd = "{} {}".format(command, addr_type)
+
+ cmd = "{} json".format(cmd)
+
+ rib_routes_json = run_frr_cmd(rnode, cmd, isjson=True)
+
+ # Verifying output dictionary rib_routes_json is not empty
+ if bool(rib_routes_json) == False:
+ errormsg = "No route found in rib of router {}..".format(router)
+ return errormsg
+
+ network = static_route["network"]
+
+ if "no_of_ip" in static_route:
+ no_of_ip = static_route["no_of_ip"]
+ else:
+ no_of_ip = 1
+
+ # Generating IPs for verification
+ ip_list = generate_ips(network, no_of_ip)
+
+ for st_rt in ip_list:
+ st_rt = str(ipaddr.IPNetwork(unicode(st_rt)))
+
+ _addr_type = validate_ip_address(st_rt)
+ if _addr_type != addr_type:
+ continue
+
+ if st_rt in rib_routes_json["routes"]:
+ st_found = True
+ found_routes.append(st_rt)
+
+ if next_hop:
+ if not isinstance(next_hop, list):
+ next_hop = [next_hop]
+ list1 = next_hop
+ found_hops = [
+ rib_r["ip"]
+ for rib_r in rib_routes_json["routes"][st_rt][0][
+ "nexthops"
+ ]
+ ]
+ list2 = found_hops
+ missing_list_of_nexthops = set(list2).difference(list1)
+ additional_nexthops_in_required_nhs = set(
+ list1
+ ).difference(list2)
+
+ if list2:
+ if additional_nexthops_in_required_nhs:
+ logger.info(
+ "Missing nexthop %s for route"
+ " %s in RIB of router %s\n",
+ additional_nexthops_in_required_nhs,
+ st_rt,
+ dut,
+ )
+ errormsg = (
+ "Nexthop {} is Missing for "
+ "route {} in RIB of router {}\n".format(
+ additional_nexthops_in_required_nhs,
+ st_rt,
+ dut,
+ )
+ )
+ return errormsg
+ else:
+ nh_found = True
+ if aspath:
+ found_paths = rib_routes_json["routes"][st_rt][0][
+ "path"
+ ]
+ if aspath == found_paths:
+ aspath_found = True
+ logger.info(
+ "Found AS path {} for route"
+ " {} in RIB of router "
+ "{}\n".format(aspath, st_rt, dut)
+ )
+ else:
+ errormsg = (
+ "AS Path {} is missing for route"
+ "for route {} in RIB of router {}\n".format(
+ aspath, st_rt, dut
+ )
+ )
+ return errormsg
+
+ else:
+ missing_routes.append(st_rt)
+
+ if nh_found:
+ logger.info(
+ "Found next_hop {} for all bgp"
+ " routes in RIB of"
+ " router {}\n".format(next_hop, router)
+ )
+
+ if len(missing_routes) > 0:
+ errormsg = (
+ "Missing route in RIB of router {}, "
+ "routes: {}\n".format(dut, missing_routes)
+ )
+ return errormsg
+
+ if found_routes:
+ logger.info(
+ "Verified routes in router {} BGP RIB, "
+ "found routes are: {} \n".format(dut, found_routes)
+ )
+ continue
+
+ if "bgp" not in input_dict[routerInput]:
+ continue
+
+ # Advertise networks
+ bgp_data_list = input_dict[routerInput]["bgp"]
+
+ if type(bgp_data_list) is not list:
+ bgp_data_list = [bgp_data_list]
+
+ for bgp_data in bgp_data_list:
+ vrf_id = bgp_data.setdefault("vrf", None)
+ if vrf_id:
+ cmd = "{} vrf {} {}".format(command, vrf_id, addr_type)
+ else:
+ cmd = "{} {}".format(command, addr_type)
+
+ cmd = "{} json".format(cmd)
+
+ rib_routes_json = run_frr_cmd(rnode, cmd, isjson=True)
+
+ # Verifying output dictionary rib_routes_json is not empty
+ if bool(rib_routes_json) == False:
+ errormsg = "No route found in rib of router {}..".format(router)
+ return errormsg
+
+ bgp_net_advertise = bgp_data["address_family"][addr_type]["unicast"]
+ advertise_network = bgp_net_advertise.setdefault(
+ "advertise_networks", []
+ )
+
+ for advertise_network_dict in advertise_network:
+ found_routes = []
+ missing_routes = []
+ found = False
+
+ network = advertise_network_dict["network"]
+
+ if "no_of_network" in advertise_network_dict:
+ no_of_network = advertise_network_dict["no_of_network"]
+ else:
+ no_of_network = 1
+
+ # Generating IPs for verification
+ ip_list = generate_ips(network, no_of_network)
+
+ for st_rt in ip_list:
+ st_rt = str(ipaddr.IPNetwork(unicode(st_rt)))
+
+ _addr_type = validate_ip_address(st_rt)
+ if _addr_type != addr_type:
+ continue
+
+ if st_rt in rib_routes_json["routes"]:
+ found = True
+ found_routes.append(st_rt)
+ else:
+ found = False
+ missing_routes.append(st_rt)
+
+ if len(missing_routes) > 0:
+ errormsg = (
+ "Missing route in BGP RIB of router {},"
+ " are: {}\n".format(dut, missing_routes)
+ )
+ return errormsg
+
+ if found_routes:
+ logger.info(
+ "Verified routes in router {} BGP RIB, found "
+ "routes are: {}\n".format(dut, found_routes)
+ )
+
+ logger.debug("Exiting lib API: verify_bgp_rib()")
+ return True
diff --git a/tests/topotests/rip-topo1/r1/rip_status.ref b/tests/topotests/rip-topo1/r1/rip_status.ref
index d75fbe85bb..31ad46ab2e 100644
--- a/tests/topotests/rip-topo1/r1/rip_status.ref
+++ b/tests/topotests/rip-topo1/r1/rip_status.ref
@@ -8,8 +8,14 @@ Routing Protocol is "rip"
Default version control: send version 2, receive version 2
Interface Send Recv Key-chain
r1-eth1 2 2
+ r1-eth2 2 2
+ r1-eth3 2 2
Routing for Networks:
193.1.1.0/26
+ r1-eth2
+ r1-eth3
+ Passive Interface(s):
+ r1-eth3
Routing Information Sources:
Gateway BadPackets BadRoutes Distance Last Update
193.1.1.2 0 0 120 XX:XX:XX
diff --git a/tests/topotests/rip-topo1/r1/ripd.conf b/tests/topotests/rip-topo1/r1/ripd.conf
index 935ec312e5..54f1774214 100644
--- a/tests/topotests/rip-topo1/r1/ripd.conf
+++ b/tests/topotests/rip-topo1/r1/ripd.conf
@@ -4,6 +4,9 @@ router rip
timers basic 5 180 5
version 2
network 193.1.1.0/26
+ network r1-eth2
+ network r1-eth3
+ passive-interface r1-eth3
!
line vty
!
diff --git a/tests/topotests/rip-topo1/r1/show_ip_rip.ref b/tests/topotests/rip-topo1/r1/show_ip_rip.ref
index 561560f230..a0b77c886e 100644
--- a/tests/topotests/rip-topo1/r1/show_ip_rip.ref
+++ b/tests/topotests/rip-topo1/r1/show_ip_rip.ref
@@ -6,5 +6,7 @@ Sub-codes:
Network Next Hop Metric From Tag Time
R(n) 192.168.2.0/24 193.1.1.2 3 193.1.1.2 0 XX:XX
R(n) 192.168.3.0/24 193.1.1.2 3 193.1.1.2 0 XX:XX
+C(i) 192.168.98.0/24 0.0.0.0 1 self 0
+C(i) 192.168.99.0/24 0.0.0.0 1 self 0
C(i) 193.1.1.0/26 0.0.0.0 1 self 0
R(n) 193.1.2.0/24 193.1.1.2 2 193.1.1.2 0 XX:XX
diff --git a/tests/topotests/rip-topo1/r1/zebra.conf b/tests/topotests/rip-topo1/r1/zebra.conf
index 8537f6dd80..7c8f2c502b 100644
--- a/tests/topotests/rip-topo1/r1/zebra.conf
+++ b/tests/topotests/rip-topo1/r1/zebra.conf
@@ -5,6 +5,13 @@ hostname r1
interface r1-eth0
ip address 192.168.1.1/24
!
+interface r1-eth2
+ ip address 192.168.99.1/24
+!
+interface r1-eth3
+ ip address 192.168.98.1/24
+!
+
interface r1-eth1
description to sw2 - RIPv2 interface
ip address 193.1.1.1/26
diff --git a/tests/topotests/rip-topo1/r2/rip_status.ref b/tests/topotests/rip-topo1/r2/rip_status.ref
index da1abd041a..99841a62b0 100644
--- a/tests/topotests/rip-topo1/r2/rip_status.ref
+++ b/tests/topotests/rip-topo1/r2/rip_status.ref
@@ -14,5 +14,6 @@ Routing Protocol is "rip"
193.1.2.0/24
Routing Information Sources:
Gateway BadPackets BadRoutes Distance Last Update
+ 193.1.1.1 0 0 120 XX:XX:XX
193.1.2.2 0 0 120 XX:XX:XX
Distance: (default is 120)
diff --git a/tests/topotests/rip-topo1/r2/show_ip_rip.ref b/tests/topotests/rip-topo1/r2/show_ip_rip.ref
index 58ab052160..b61fb45eac 100644
--- a/tests/topotests/rip-topo1/r2/show_ip_rip.ref
+++ b/tests/topotests/rip-topo1/r2/show_ip_rip.ref
@@ -6,5 +6,7 @@ Sub-codes:
Network Next Hop Metric From Tag Time
R(n) 192.168.2.0/24 193.1.2.2 2 193.1.2.2 0 XX:XX
R(n) 192.168.3.0/24 193.1.2.2 2 193.1.2.2 0 XX:XX
+R(n) 192.168.98.0/24 193.1.1.1 2 193.1.1.1 0 XX:XX
+R(n) 192.168.99.0/24 193.1.1.1 2 193.1.1.1 0 XX:XX
C(i) 193.1.1.0/26 0.0.0.0 1 self 0
C(i) 193.1.2.0/24 0.0.0.0 1 self 0
diff --git a/tests/topotests/rip-topo1/r2/show_ip_route.ref b/tests/topotests/rip-topo1/r2/show_ip_route.ref
index 22afbee385..80f51a92c7 100644
--- a/tests/topotests/rip-topo1/r2/show_ip_route.ref
+++ b/tests/topotests/rip-topo1/r2/show_ip_route.ref
@@ -1,2 +1,4 @@
R>* 192.168.2.0/24 [120/2] via 193.1.2.2, r2-eth1, weight 1
R>* 192.168.3.0/24 [120/2] via 193.1.2.2, r2-eth1, weight 1
+R>* 192.168.98.0/24 [120/2] via 193.1.1.1, r2-eth0, weight 1
+R>* 192.168.99.0/24 [120/2] via 193.1.1.1, r2-eth0, weight 1
diff --git a/tests/topotests/rip-topo1/r3/show_ip_rip.ref b/tests/topotests/rip-topo1/r3/show_ip_rip.ref
index cf672712a8..1df299b5e6 100644
--- a/tests/topotests/rip-topo1/r3/show_ip_rip.ref
+++ b/tests/topotests/rip-topo1/r3/show_ip_rip.ref
@@ -6,5 +6,7 @@ Sub-codes:
Network Next Hop Metric From Tag Time
S(r) 192.168.2.0/24 192.168.3.10 1 self 0
C(r) 192.168.3.0/24 0.0.0.0 1 self 0
+R(n) 192.168.98.0/24 193.1.2.1 3 193.1.2.1 0 XX:XX
+R(n) 192.168.99.0/24 193.1.2.1 3 193.1.2.1 0 XX:XX
R(n) 193.1.1.0/26 193.1.2.1 2 193.1.2.1 0 XX:XX
C(i) 193.1.2.0/24 0.0.0.0 1 self 0
diff --git a/tests/topotests/rip-topo1/r3/show_ip_route.ref b/tests/topotests/rip-topo1/r3/show_ip_route.ref
index 995b6d7da9..2b739f0489 100644
--- a/tests/topotests/rip-topo1/r3/show_ip_route.ref
+++ b/tests/topotests/rip-topo1/r3/show_ip_route.ref
@@ -1 +1,3 @@
+R>* 192.168.98.0/24 [120/3] via 193.1.2.1, r3-eth1, weight 1
+R>* 192.168.99.0/24 [120/3] via 193.1.2.1, r3-eth1, weight 1
R>* 193.1.1.0/26 [120/2] via 193.1.2.1, r3-eth1, weight 1
diff --git a/tests/topotests/rip-topo1/test_rip_topo1.py b/tests/topotests/rip-topo1/test_rip_topo1.py
index 132d38c2e5..3098812a24 100755
--- a/tests/topotests/rip-topo1/test_rip_topo1.py
+++ b/tests/topotests/rip-topo1/test_rip_topo1.py
@@ -91,6 +91,12 @@ class NetworkTopo(Topo):
switch[4] = self.addSwitch("sw4", cls=topotest.LegacySwitch)
self.addLink(switch[4], router[3], intfName2="r3-eth0")
+ switch[5] = self.addSwitch("sw5", cls=topotest.LegacySwitch)
+ self.addLink(switch[5], router[1], intfName2="r1-eth2")
+
+ switch[6] = self.addSwitch("sw6", cls=topotest.LegacySwitch)
+ self.addLink(switch[6], router[1], intfName2="r1-eth3")
+
#####################################################
##
diff --git a/tests/topotests/ripng-topo1/r1/ripng_status.ref b/tests/topotests/ripng-topo1/r1/ripng_status.ref
index e6197f179b..b02cc69d0e 100644
--- a/tests/topotests/ripng-topo1/r1/ripng_status.ref
+++ b/tests/topotests/ripng-topo1/r1/ripng_status.ref
@@ -8,8 +8,12 @@ Routing Protocol is "RIPng"
Default version control: send version 1, receive version 1
Interface Send Recv
r1-eth1 1 1
+ r1-eth2 1 1
+ r1-eth3 1 1
Routing for Networks:
fc00:5::/64
+ r1-eth2
+ r1-eth3
Routing Information Sources:
Gateway BadPackets BadRoutes Distance Last Update
fe80::XXXX:XXXX:XXXX:XXXX
diff --git a/tests/topotests/ripng-topo1/r1/ripngd.conf b/tests/topotests/ripng-topo1/r1/ripngd.conf
index dd54c43557..07ed7296d9 100644
--- a/tests/topotests/ripng-topo1/r1/ripngd.conf
+++ b/tests/topotests/ripng-topo1/r1/ripngd.conf
@@ -7,6 +7,9 @@ debug ripng zebra
router ripng
timers basic 5 180 5
network fc00:5::/64
+ network r1-eth2
+ network r1-eth3
+ passive-interface r1-eth3
!
line vty
!
diff --git a/tests/topotests/ripng-topo1/r1/show_ipv6_ripng.ref b/tests/topotests/ripng-topo1/r1/show_ipv6_ripng.ref
index 18d026a8fd..30d0f31e18 100644
--- a/tests/topotests/ripng-topo1/r1/show_ipv6_ripng.ref
+++ b/tests/topotests/ripng-topo1/r1/show_ipv6_ripng.ref
@@ -12,3 +12,7 @@ R(n) fc00:7::/64
fe80::XXXX:XXXX:XXXX:XXXX r1-eth1 3 0 XX:XX
R(n) fc00:7:1111::/64
fe80::XXXX:XXXX:XXXX:XXXX r1-eth1 3 0 XX:XX
+C(i) fc00:98:0:1::/64
+ :: self 1 0
+C(i) fc00:99:0:1::/64
+ :: self 1 0
diff --git a/tests/topotests/ripng-topo1/r1/zebra.conf b/tests/topotests/ripng-topo1/r1/zebra.conf
index 1a10343044..11c1cdc5b9 100644
--- a/tests/topotests/ripng-topo1/r1/zebra.conf
+++ b/tests/topotests/ripng-topo1/r1/zebra.conf
@@ -10,6 +10,12 @@ interface r1-eth1
ipv6 address fc00:5::1/64
no link-detect
!
+interface r1-eth2
+ ipv6 address fc00:99:0:1::1/64
+!
+interface r1-eth3
+ ipv6 address fc00:98:0:1::1/64
+!
ip forwarding
ipv6 forwarding
!
diff --git a/tests/topotests/ripng-topo1/r2/show_ipv6_ripng.ref b/tests/topotests/ripng-topo1/r2/show_ipv6_ripng.ref
index 765efd07a2..fe5bcc8b31 100644
--- a/tests/topotests/ripng-topo1/r2/show_ipv6_ripng.ref
+++ b/tests/topotests/ripng-topo1/r2/show_ipv6_ripng.ref
@@ -12,3 +12,7 @@ R(n) fc00:7::/64
fe80::XXXX:XXXX:XXXX:XXXX r2-eth1 2 0 XX:XX
R(n) fc00:7:1111::/64
fe80::XXXX:XXXX:XXXX:XXXX r2-eth1 2 0 XX:XX
+R(n) fc00:98:0:1::/64
+ fe80::XXXX:XXXX:XXXX:XXXX r2-eth0 2 0 XX:XX
+R(n) fc00:99:0:1::/64
+ fe80::XXXX:XXXX:XXXX:XXXX r2-eth0 2 0 XX:XX
diff --git a/tests/topotests/ripng-topo1/r2/show_ipv6_route.ref b/tests/topotests/ripng-topo1/r2/show_ipv6_route.ref
index 8c98b7a67b..72e1f926a2 100644
--- a/tests/topotests/ripng-topo1/r2/show_ipv6_route.ref
+++ b/tests/topotests/ripng-topo1/r2/show_ipv6_route.ref
@@ -1,2 +1,4 @@
R>* fc00:7::/64 [120/2] via fe80::XXXX:XXXX:XXXX:XXXX, r2-eth1, weight 1
R>* fc00:7:1111::/64 [120/2] via fe80::XXXX:XXXX:XXXX:XXXX, r2-eth1, weight 1
+R>* fc00:98:0:1::/64 [120/2] via fe80::XXXX:XXXX:XXXX:XXXX, r2-eth0, weight 1
+R>* fc00:99:0:1::/64 [120/2] via fe80::XXXX:XXXX:XXXX:XXXX, r2-eth0, weight 1
diff --git a/tests/topotests/ripng-topo1/r3/show_ipv6_ripng.ref b/tests/topotests/ripng-topo1/r3/show_ipv6_ripng.ref
index 81e76b97a6..909ad663ba 100644
--- a/tests/topotests/ripng-topo1/r3/show_ipv6_ripng.ref
+++ b/tests/topotests/ripng-topo1/r3/show_ipv6_ripng.ref
@@ -12,3 +12,7 @@ C(r) fc00:7::/64
:: self 1 0
S(r) fc00:7:1111::/64
:: self 1 0
+R(n) fc00:98:0:1::/64
+ fe80::XXXX:XXXX:XXXX:XXXX r3-eth1 3 0 XX:XX
+R(n) fc00:99:0:1::/64
+ fe80::XXXX:XXXX:XXXX:XXXX r3-eth1 3 0 XX:XX
diff --git a/tests/topotests/ripng-topo1/r3/show_ipv6_route.ref b/tests/topotests/ripng-topo1/r3/show_ipv6_route.ref
index 2e9de88db5..25a7440111 100644
--- a/tests/topotests/ripng-topo1/r3/show_ipv6_route.ref
+++ b/tests/topotests/ripng-topo1/r3/show_ipv6_route.ref
@@ -1 +1,3 @@
R>* fc00:5::/64 [120/2] via fe80::XXXX:XXXX:XXXX:XXXX, r3-eth1, weight 1
+R>* fc00:98:0:1::/64 [120/3] via fe80::XXXX:XXXX:XXXX:XXXX, r3-eth1, weight 1
+R>* fc00:99:0:1::/64 [120/3] via fe80::XXXX:XXXX:XXXX:XXXX, r3-eth1, weight 1
diff --git a/tests/topotests/ripng-topo1/test_ripng_topo1.py b/tests/topotests/ripng-topo1/test_ripng_topo1.py
index 51f7fb6fb1..23e689235c 100755
--- a/tests/topotests/ripng-topo1/test_ripng_topo1.py
+++ b/tests/topotests/ripng-topo1/test_ripng_topo1.py
@@ -92,6 +92,11 @@ class NetworkTopo(Topo):
switch[4] = self.addSwitch("sw4", cls=topotest.LegacySwitch)
self.addLink(switch[4], router[3], intfName2="r3-eth0")
+ switch[5] = self.addSwitch("sw5", cls=topotest.LegacySwitch)
+ self.addLink(switch[5], router[1], intfName2="r1-eth2")
+ switch[6] = self.addSwitch("sw6", cls=topotest.LegacySwitch)
+ self.addLink(switch[6], router[1], intfName2="r1-eth3")
+
#####################################################
##
diff --git a/tools/coccinelle/same_type_casting.cocci b/tools/coccinelle/same_type_casting.cocci
new file mode 100644
index 0000000000..58fd7569af
--- /dev/null
+++ b/tools/coccinelle/same_type_casting.cocci
@@ -0,0 +1,7 @@
+@@
+type T;
+T *ptr;
+@@
+
+- (T *)ptr
++ ptr
diff --git a/tools/start-stop-daemon.c b/tools/start-stop-daemon.c
index c75306a959..13118a2769 100644
--- a/tools/start-stop-daemon.c
+++ b/tools/start-stop-daemon.c
@@ -235,7 +235,7 @@ static const char *next_dirname(const char *s)
{
const char *cur;
- cur = (const char *)s;
+ cur = s;
if (*cur != '\0') {
for (; *cur != '/'; ++cur)
@@ -255,7 +255,7 @@ static void add_namespace(const char *path)
const char *nsdirname, *nsname, *cur;
struct namespace *namespace;
- cur = (const char *)path;
+ cur = path;
nsdirname = nsname = "";
while ((cur = next_dirname(cur))[0] != '\0') {
@@ -273,7 +273,7 @@ static void add_namespace(const char *path)
badusage("invalid namepspace path");
namespace = xmalloc(sizeof(*namespace));
- namespace->path = (const char *)path;
+ namespace->path = path;
namespace->nstype = nstype;
LIST_INSERT_HEAD(&namespace_head, namespace, list);
}
diff --git a/vrrpd/vrrp_ndisc.c b/vrrpd/vrrp_ndisc.c
index dc546b09a2..b989e66f60 100644
--- a/vrrpd/vrrp_ndisc.c
+++ b/vrrpd/vrrp_ndisc.c
@@ -83,8 +83,7 @@ static int vrrp_ndisc_una_build(struct interface *ifp, struct ipaddr *ip,
struct nd_opt_hdr *nd_opt_h =
(struct nd_opt_hdr *)((char *)ndh
+ sizeof(struct nd_neighbor_advert));
- char *nd_opt_lladdr =
- (char *)((char *)nd_opt_h + sizeof(struct nd_opt_hdr));
+ char *nd_opt_lladdr = ((char *)nd_opt_h + sizeof(struct nd_opt_hdr));
char *lladdr = (char *)ifp->hw_addr;
/*
diff --git a/yang/embedmodel.py b/yang/embedmodel.py
index 52671f99a8..624a11da9d 100644
--- a/yang/embedmodel.py
+++ b/yang/embedmodel.py
@@ -3,11 +3,18 @@
# YANG module to C wrapper
# written 2018 by David Lamparter, placed in Public Domain.
-import sys, string, re
+import sys
+import os
+import string
+import re
inname = sys.argv[1]
outname = sys.argv[2]
+outdir = os.path.dirname(os.path.abspath(outname))
+if not os.path.isdir(outdir):
+ os.makedirs(outdir)
+
# these are regexes to avoid a compile-time/host dependency on yang-tools
# or python-yang. Cross-compiling FRR is already somewhat involved, no need
# to make it even harder.
diff --git a/yang/frr-eigrpd.yang b/yang/frr-eigrpd.yang
index e02f888b0e..092b714045 100644
--- a/yang/frr-eigrpd.yang
+++ b/yang/frr-eigrpd.yang
@@ -191,7 +191,7 @@ module frr-eigrpd {
leaf-list neighbor {
description "Specific EIGRP neighbor";
- type inet:ipv4-prefix;
+ type inet:ipv4-address;
}
list redistribute {
diff --git a/yang/frr-ripd.yang b/yang/frr-ripd.yang
index 7318eb18d7..12c72b39b5 100644
--- a/yang/frr-ripd.yang
+++ b/yang/frr-ripd.yang
@@ -118,7 +118,7 @@ module frr-ripd {
"Enable RIP on the specified IP network.";
}
leaf-list interface {
- type frr-interface:interface-ref;
+ type string;
description
"Enable RIP on the specified interface.";
}
@@ -179,14 +179,14 @@ module frr-ripd {
}
leaf-list passive-interface {
when "../passive-default = 'false'";
- type frr-interface:interface-ref;
+ type string;
description
"A list of interfaces where the sending of RIP packets
is disabled.";
}
leaf-list non-passive-interface {
when "../passive-default = 'true'";
- type frr-interface:interface-ref;
+ type string;
description
"A list of interfaces where the sending of RIP packets
is enabled.";
diff --git a/yang/frr-ripngd.yang b/yang/frr-ripngd.yang
index 732f32ea50..c58962f5cd 100644
--- a/yang/frr-ripngd.yang
+++ b/yang/frr-ripngd.yang
@@ -76,7 +76,7 @@ module frr-ripngd {
"Enable RIPng on the specified IPv6 network.";
}
leaf-list interface {
- type frr-interface:interface-ref;
+ type string;
description
"Enable RIPng on the specified interface.";
}
diff --git a/zebra/redistribute.c b/zebra/redistribute.c
index 115a69f2c8..4d6346151a 100644
--- a/zebra/redistribute.c
+++ b/zebra/redistribute.c
@@ -150,6 +150,43 @@ static void zebra_redistribute(struct zserv *client, int type,
}
}
+/*
+ * Function to check if prefix is candidate for
+ * redistribute.
+ */
+static bool zebra_redistribute_check(const struct route_entry *re,
+ struct zserv *client,
+ const struct prefix *p, int afi)
+{
+ /* Process only if there is valid re */
+ if (!re)
+ return false;
+
+ /* If default route and redistributed */
+ if (is_default_prefix(p)
+ && vrf_bitmap_check(client->redist_default[afi], re->vrf_id))
+ return true;
+
+ /* If redistribute in enabled for zebra route all */
+ if (vrf_bitmap_check(client->redist[afi][ZEBRA_ROUTE_ALL], re->vrf_id))
+ return true;
+
+ /*
+ * If multi-instance then check for route
+ * redistribution for given instance.
+ */
+ if (re->instance
+ && redist_check_instance(&client->mi_redist[afi][re->type],
+ re->instance))
+ return true;
+
+ /* If redistribution is enabled for give route type. */
+ if (vrf_bitmap_check(client->redist[afi][re->type], re->vrf_id))
+ return true;
+
+ return false;
+}
+
/* Either advertise a route for redistribution to registered clients or */
/* withdraw redistribution if add cannot be done for client */
void redistribute_update(const struct prefix *p, const struct prefix *src_p,
@@ -158,7 +195,6 @@ void redistribute_update(const struct prefix *p, const struct prefix *src_p,
{
struct listnode *node, *nnode;
struct zserv *client;
- int send_redistribute;
int afi;
char buf[PREFIX_STRLEN];
@@ -185,25 +221,7 @@ void redistribute_update(const struct prefix *p, const struct prefix *src_p,
for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
- send_redistribute = 0;
-
- if (is_default_prefix(p)
- && vrf_bitmap_check(client->redist_default[afi],
- re->vrf_id))
- send_redistribute = 1;
- else if (vrf_bitmap_check(client->redist[afi][ZEBRA_ROUTE_ALL],
- re->vrf_id))
- send_redistribute = 1;
- else if (re->instance
- && redist_check_instance(
- &client->mi_redist[afi][re->type],
- re->instance))
- send_redistribute = 1;
- else if (vrf_bitmap_check(client->redist[afi][re->type],
- re->vrf_id))
- send_redistribute = 1;
-
- if (send_redistribute) {
+ if (zebra_redistribute_check(re, client, p, afi)) {
if (IS_ZEBRA_DEBUG_RIB) {
zlog_debug(
"%s: client %s %s(%u), type=%d, distance=%d, metric=%d",
@@ -215,18 +233,9 @@ void redistribute_update(const struct prefix *p, const struct prefix *src_p,
}
zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD,
client, p, src_p, re);
- } else if (prev_re
- && ((re->instance
- && redist_check_instance(
- &client->mi_redist[afi]
- [prev_re->type],
- re->instance))
- || vrf_bitmap_check(
- client->redist[afi][prev_re->type],
- re->vrf_id))) {
+ } else if (zebra_redistribute_check(prev_re, client, p, afi))
zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_DEL,
client, p, src_p, prev_re);
- }
}
}
@@ -294,46 +303,21 @@ void redistribute_delete(const struct prefix *p, const struct prefix *src_p,
/* Do not send unsolicited messages to synchronous clients. */
if (client->synchronous)
continue;
-
- if (new_re) {
- /* Skip this client if it will receive an update for the
- * 'new' re
- */
- if (is_default_prefix(p)
- && vrf_bitmap_check(client->redist_default[afi],
- new_re->vrf_id))
- continue;
- else if (vrf_bitmap_check(
- client->redist[afi][ZEBRA_ROUTE_ALL],
- new_re->vrf_id))
- continue;
- else if (new_re->instance
- && redist_check_instance(
- &client->mi_redist[afi][new_re->type],
- new_re->instance))
- continue;
- else if (vrf_bitmap_check(
- client->redist[afi][new_re->type],
- new_re->vrf_id))
- continue;
- }
+ /*
+ * Skip this client if it will receive an update for the
+ * 'new' re
+ */
+ if (zebra_redistribute_check(new_re, client, p, afi))
+ continue;
/* Send a delete for the 'old' re to any subscribed client. */
- if (old_re
- && (vrf_bitmap_check(client->redist[afi][ZEBRA_ROUTE_ALL],
- old_re->vrf_id)
- || (old_re->instance
- && redist_check_instance(
- &client->mi_redist[afi][old_re->type],
- old_re->instance))
- || vrf_bitmap_check(client->redist[afi][old_re->type],
- old_re->vrf_id))) {
+ if (zebra_redistribute_check(old_re, client, p, afi))
zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_DEL,
client, p, src_p, old_re);
- }
}
}
+
void zebra_redistribute_add(ZAPI_HANDLER_ARGS)
{
afi_t afi = 0;
diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c
index 84c9bd098e..f29a7fa305 100644
--- a/zebra/rt_netlink.c
+++ b/zebra/rt_netlink.c
@@ -2509,12 +2509,28 @@ int kernel_neigh_update(int add, int ifindex, uint32_t addr, char *lla,
addr, lla, llalen, ns_id);
}
-/*
- * Add remote VTEP to the flood list for this VxLAN interface (VNI). This
- * is done by adding an FDB entry with a MAC of 00:00:00:00:00:00.
+/**
+ * netlink_update_neigh_ctx_internal() - Common helper api for evpn
+ * neighbor updates using dataplane context object.
+ * @ctx: Dataplane context
+ * @cmd: Netlink command (RTM_NEWNEIGH or RTM_DELNEIGH)
+ * @mac: A neighbor cache link layer address
+ * @ip: A neighbor cache n/w layer destination address
+ * @replace_obj: Whether NEW request should replace existing object or
+ * add to the end of the list
+ * @family: AF_* netlink family
+ * @type: RTN_* route type
+ * @flags: NTF_* flags
+ * @state: NUD_* states
+ *
+ * Return: Result status
*/
-static int netlink_vxlan_flood_update_ctx(const struct zebra_dplane_ctx *ctx,
- int cmd)
+static int netlink_update_neigh_ctx_internal(const struct zebra_dplane_ctx *ctx,
+ int cmd, const struct ethaddr *mac,
+ const struct ipaddr *ip,
+ bool replace_obj, uint8_t family,
+ uint8_t type, uint8_t flags,
+ uint16_t state)
{
uint8_t protocol = RTPROT_ZEBRA;
struct {
@@ -2522,34 +2538,62 @@ static int netlink_vxlan_flood_update_ctx(const struct zebra_dplane_ctx *ctx,
struct ndmsg ndm;
char buf[256];
} req;
- uint8_t dst_mac[6] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
- const struct ipaddr *addr;
+ int ipa_len;
+ enum dplane_op_e op;
memset(&req, 0, sizeof(req));
+ op = dplane_ctx_get_op(ctx);
+
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
req.n.nlmsg_flags = NLM_F_REQUEST;
if (cmd == RTM_NEWNEIGH)
- req.n.nlmsg_flags |= (NLM_F_CREATE | NLM_F_APPEND);
+ req.n.nlmsg_flags |=
+ NLM_F_CREATE
+ | (replace_obj ? NLM_F_REPLACE : NLM_F_APPEND);
req.n.nlmsg_type = cmd;
- req.ndm.ndm_family = PF_BRIDGE;
- req.ndm.ndm_state = NUD_NOARP | NUD_PERMANENT;
- req.ndm.ndm_flags |= NTF_SELF; /* Handle by "self", not "master" */
-
+ req.ndm.ndm_family = family;
+ req.ndm.ndm_type = type;
+ req.ndm.ndm_state = state;
+ req.ndm.ndm_flags = flags;
+ req.ndm.ndm_ifindex = dplane_ctx_get_ifindex(ctx);
addattr_l(&req.n, sizeof(req),
NDA_PROTOCOL, &protocol, sizeof(protocol));
- addattr_l(&req.n, sizeof(req), NDA_LLADDR, &dst_mac, 6);
- req.ndm.ndm_ifindex = dplane_ctx_get_ifindex(ctx);
+ if (mac)
+ addattr_l(&req.n, sizeof(req), NDA_LLADDR, mac, 6);
- addr = dplane_ctx_neigh_get_ipaddr(ctx);
+ ipa_len = IS_IPADDR_V4(ip) ? IPV4_MAX_BYTELEN : IPV6_MAX_BYTELEN;
+ addattr_l(&req.n, sizeof(req), NDA_DST, &ip->ip.addr, ipa_len);
+
+ if (op == DPLANE_OP_MAC_INSTALL || op == DPLANE_OP_MAC_DELETE) {
+ vlanid_t vid = dplane_ctx_mac_get_vlan(ctx);
+
+ if (vid > 0)
+ addattr16(&req.n, sizeof(req), NDA_VLAN, vid);
- addattr_l(&req.n, sizeof(req), NDA_DST, &(addr->ipaddr_v4), 4);
+ addattr32(&req.n, sizeof(req), NDA_MASTER,
+ dplane_ctx_mac_get_br_ifindex(ctx));
+ }
return netlink_talk_info(netlink_talk_filter, &req.n,
dplane_ctx_get_ns(ctx), 0);
}
+/*
+ * Add remote VTEP to the flood list for this VxLAN interface (VNI). This
+ * is done by adding an FDB entry with a MAC of 00:00:00:00:00:00.
+ */
+static int netlink_vxlan_flood_update_ctx(const struct zebra_dplane_ctx *ctx,
+ int cmd)
+{
+ struct ethaddr dst_mac = {.octet = {0}};
+
+ return netlink_update_neigh_ctx_internal(
+ ctx, cmd, &dst_mac, dplane_ctx_neigh_get_ipaddr(ctx), false,
+ PF_BRIDGE, 0, NTF_SELF, (NUD_NOARP | NUD_PERMANENT));
+}
+
#ifndef NDA_RTA
#define NDA_RTA(r) \
((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct ndmsg))))
@@ -2871,92 +2915,50 @@ int netlink_macfdb_read_specific_mac(struct zebra_ns *zns,
/*
* Netlink-specific handler for MAC updates using dataplane context object.
*/
-static enum zebra_dplane_result
-netlink_macfdb_update_ctx(struct zebra_dplane_ctx *ctx)
+static int netlink_macfdb_update_ctx(struct zebra_dplane_ctx *ctx, int cmd)
{
- uint8_t protocol = RTPROT_ZEBRA;
- struct {
- struct nlmsghdr n;
- struct ndmsg ndm;
- char buf[256];
- } req;
- int ret;
- int dst_alen;
- int vid_present = 0;
- int cmd;
- struct in_addr vtep_ip;
+ struct ipaddr vtep_ip;
vlanid_t vid;
+ uint8_t flags;
+ uint16_t state;
- if (dplane_ctx_get_op(ctx) == DPLANE_OP_MAC_INSTALL)
- cmd = RTM_NEWNEIGH;
- else
- cmd = RTM_DELNEIGH;
-
- memset(&req, 0, sizeof(req));
-
- req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
- req.n.nlmsg_flags = NLM_F_REQUEST;
- if (cmd == RTM_NEWNEIGH)
- req.n.nlmsg_flags |= (NLM_F_CREATE | NLM_F_REPLACE);
- req.n.nlmsg_type = cmd;
- req.ndm.ndm_family = AF_BRIDGE;
- req.ndm.ndm_flags |= NTF_SELF | NTF_MASTER;
- req.ndm.ndm_state = NUD_REACHABLE;
+ flags = (NTF_SELF | NTF_MASTER);
+ state = NUD_REACHABLE;
if (dplane_ctx_mac_is_sticky(ctx))
- req.ndm.ndm_state |= NUD_NOARP;
+ state |= NUD_NOARP;
else
- req.ndm.ndm_flags |= NTF_EXT_LEARNED;
-
- addattr_l(&req.n, sizeof(req),
- NDA_PROTOCOL, &protocol, sizeof(protocol));
- addattr_l(&req.n, sizeof(req), NDA_LLADDR,
- dplane_ctx_mac_get_addr(ctx), 6);
- req.ndm.ndm_ifindex = dplane_ctx_get_ifindex(ctx);
-
- dst_alen = 4; // TODO: hardcoded
- vtep_ip = *(dplane_ctx_mac_get_vtep_ip(ctx));
- addattr_l(&req.n, sizeof(req), NDA_DST, &vtep_ip, dst_alen);
-
- vid = dplane_ctx_mac_get_vlan(ctx);
+ flags |= NTF_EXT_LEARNED;
- if (vid > 0) {
- addattr16(&req.n, sizeof(req), NDA_VLAN, vid);
- vid_present = 1;
- }
- addattr32(&req.n, sizeof(req), NDA_MASTER,
- dplane_ctx_mac_get_br_ifindex(ctx));
+ vtep_ip.ipaddr_v4 = *(dplane_ctx_mac_get_vtep_ip(ctx));
+ SET_IPADDR_V4(&vtep_ip);
if (IS_ZEBRA_DEBUG_KERNEL) {
char ipbuf[PREFIX_STRLEN];
char buf[ETHER_ADDR_STRLEN];
- char dst_buf[PREFIX_STRLEN + 10];
char vid_buf[20];
- if (vid_present)
+ vid = dplane_ctx_mac_get_vlan(ctx);
+ if (vid > 0)
snprintf(vid_buf, sizeof(vid_buf), " VLAN %u", vid);
else
vid_buf[0] = '\0';
- inet_ntop(AF_INET, &vtep_ip, ipbuf, sizeof(ipbuf));
- snprintf(dst_buf, sizeof(dst_buf), " dst %s", ipbuf);
- prefix_mac2str(dplane_ctx_mac_get_addr(ctx), buf, sizeof(buf));
+ const struct ethaddr *mac = dplane_ctx_mac_get_addr(ctx);
- zlog_debug("Tx %s family %s IF %s(%u)%s %sMAC %s%s",
- nl_msg_type_to_str(cmd),
- nl_family_to_str(req.ndm.ndm_family),
+ zlog_debug("Tx %s family %s IF %s(%u)%s %sMAC %s dst %s",
+ nl_msg_type_to_str(cmd), nl_family_to_str(AF_BRIDGE),
dplane_ctx_get_ifname(ctx),
dplane_ctx_get_ifindex(ctx), vid_buf,
dplane_ctx_mac_is_sticky(ctx) ? "sticky " : "",
- buf, dst_buf);
+ prefix_mac2str(mac, buf, sizeof(buf)),
+ ipaddr2str(&vtep_ip, ipbuf, sizeof(ipbuf)));
}
- ret = netlink_talk_info(netlink_talk_filter, &req.n,
- dplane_ctx_get_ns(ctx), 0);
- if (ret == 0)
- return ZEBRA_DPLANE_REQUEST_SUCCESS;
- else
- return ZEBRA_DPLANE_REQUEST_FAILURE;
+ return netlink_update_neigh_ctx_internal(
+ ctx, cmd, dplane_ctx_mac_get_addr(ctx),
+ dplane_ctx_neigh_get_ipaddr(ctx), true, AF_BRIDGE, 0, flags,
+ state);
}
/*
@@ -3336,21 +3338,11 @@ int netlink_neigh_change(struct nlmsghdr *h, ns_id_t ns_id)
static int netlink_neigh_update_ctx(const struct zebra_dplane_ctx *ctx,
int cmd)
{
- uint8_t protocol = RTPROT_ZEBRA;
- struct {
- struct nlmsghdr n;
- struct ndmsg ndm;
- char buf[256];
- } req;
- int ipa_len;
- char buf[INET6_ADDRSTRLEN];
- char buf2[ETHER_ADDR_STRLEN];
const struct ipaddr *ip;
const struct ethaddr *mac;
uint8_t flags;
uint16_t state;
-
- memset(&req, 0, sizeof(req));
+ uint8_t family;
ip = dplane_ctx_neigh_get_ipaddr(ctx);
mac = dplane_ctx_neigh_get_mac(ctx);
@@ -3360,37 +3352,23 @@ static int netlink_neigh_update_ctx(const struct zebra_dplane_ctx *ctx,
flags = neigh_flags_to_netlink(dplane_ctx_neigh_get_flags(ctx));
state = neigh_state_to_netlink(dplane_ctx_neigh_get_state(ctx));
- req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
- req.n.nlmsg_flags = NLM_F_REQUEST;
- if (cmd == RTM_NEWNEIGH)
- req.n.nlmsg_flags |= (NLM_F_CREATE | NLM_F_REPLACE);
- req.n.nlmsg_type = cmd; // RTM_NEWNEIGH or RTM_DELNEIGH
- req.ndm.ndm_family = IS_IPADDR_V4(ip) ? AF_INET : AF_INET6;
- req.ndm.ndm_state = state;
- req.ndm.ndm_ifindex = dplane_ctx_get_ifindex(ctx);
- req.ndm.ndm_type = RTN_UNICAST;
- req.ndm.ndm_flags = flags;
+ family = IS_IPADDR_V4(ip) ? AF_INET : AF_INET6;
- addattr_l(&req.n, sizeof(req),
- NDA_PROTOCOL, &protocol, sizeof(protocol));
- ipa_len = IS_IPADDR_V4(ip) ? IPV4_MAX_BYTELEN : IPV6_MAX_BYTELEN;
- addattr_l(&req.n, sizeof(req), NDA_DST, &ip->ip.addr, ipa_len);
- if (mac)
- addattr_l(&req.n, sizeof(req), NDA_LLADDR, mac, 6);
+ if (IS_ZEBRA_DEBUG_KERNEL) {
+ char buf[INET6_ADDRSTRLEN];
+ char buf2[ETHER_ADDR_STRLEN];
- if (IS_ZEBRA_DEBUG_KERNEL)
- zlog_debug("Tx %s family %s IF %s(%u) Neigh %s MAC %s flags 0x%x state 0x%x",
- nl_msg_type_to_str(cmd),
- nl_family_to_str(req.ndm.ndm_family),
- dplane_ctx_get_ifname(ctx),
- dplane_ctx_get_ifindex(ctx),
- ipaddr2str(ip, buf, sizeof(buf)),
- mac ? prefix_mac2str(mac, buf2, sizeof(buf2))
- : "null",
- flags, state);
+ zlog_debug(
+ "Tx %s family %s IF %s(%u) Neigh %s MAC %s flags 0x%x state 0x%x",
+ nl_msg_type_to_str(cmd), nl_family_to_str(family),
+ dplane_ctx_get_ifname(ctx), dplane_ctx_get_ifindex(ctx),
+ ipaddr2str(ip, buf, sizeof(buf)),
+ mac ? prefix_mac2str(mac, buf2, sizeof(buf2)) : "null",
+ flags, state);
+ }
- return netlink_talk_info(netlink_talk_filter, &req.n,
- dplane_ctx_get_ns(ctx), 0);
+ return netlink_update_neigh_ctx_internal(
+ ctx, cmd, mac, ip, true, family, RTN_UNICAST, flags, state);
}
/*
@@ -3398,7 +3376,13 @@ static int netlink_neigh_update_ctx(const struct zebra_dplane_ctx *ctx,
*/
enum zebra_dplane_result kernel_mac_update_ctx(struct zebra_dplane_ctx *ctx)
{
- return netlink_macfdb_update_ctx(ctx);
+ int cmd = dplane_ctx_get_op(ctx) == DPLANE_OP_MAC_INSTALL
+ ? RTM_NEWNEIGH
+ : RTM_DELNEIGH;
+ int ret = netlink_macfdb_update_ctx(ctx, cmd);
+
+ return (ret == 0 ? ZEBRA_DPLANE_REQUEST_SUCCESS
+ : ZEBRA_DPLANE_REQUEST_FAILURE);
}
enum zebra_dplane_result kernel_neigh_update_ctx(struct zebra_dplane_ctx *ctx)
diff --git a/zebra/zebra_fpm_protobuf.c b/zebra/zebra_fpm_protobuf.c
index ade4b636d6..4b31cc0281 100644
--- a/zebra/zebra_fpm_protobuf.c
+++ b/zebra/zebra_fpm_protobuf.c
@@ -294,7 +294,7 @@ int zfpm_protobuf_encode_route(rib_dest_t *dest, struct route_entry *re,
return 0;
}
- len = fpm__message__pack(msg, (uint8_t *)in_buf);
+ len = fpm__message__pack(msg, in_buf);
assert(len <= in_buf_len);
QPB_RESET_STACK_ALLOCATOR(allocator);
diff --git a/zebra/zebra_netns_id.c b/zebra/zebra_netns_id.c
index ea4b07a87d..77a9a7c368 100644
--- a/zebra/zebra_netns_id.c
+++ b/zebra/zebra_netns_id.c
@@ -143,7 +143,7 @@ static ns_id_t extract_nsid(struct nlmsghdr *nlh, char *buf)
void *tail = (void *)((char *)nlh + NETLINK_ALIGN(nlh->nlmsg_len));
struct nlattr *attr;
- for (attr = (struct nlattr *)((char *)buf + offset);
+ for (attr = (struct nlattr *)(buf + offset);
NETLINK_NLATTR_LEN(tail, attr) >= sizeof(struct nlattr)
&& attr->nla_len >= sizeof(struct nlattr)
&& attr->nla_len <= NETLINK_NLATTR_LEN(tail, attr);
diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c
index 58967de778..80116fca18 100644
--- a/zebra/zebra_rib.c
+++ b/zebra/zebra_rib.c
@@ -261,7 +261,7 @@ struct route_entry *rib_match(afi_t afi, safi_t safi, vrf_id_t vrf_id,
p.prefixlen = IPV6_MAX_PREFIXLEN;
}
- rn = route_node_match(table, (struct prefix *)&p);
+ rn = route_node_match(table, &p);
while (rn) {
rib_dest_t *dest;
diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c
index 2342641270..24050d8038 100644
--- a/zebra/zebra_vxlan.c
+++ b/zebra/zebra_vxlan.c
@@ -1515,8 +1515,8 @@ static void zvni_print_mac_hash_all_vni(struct hash_bucket *bucket, void *ctxt)
struct mac_walk_ctx *wctx = ctxt;
char vni_str[VNI_STR_LEN];
- vty = (struct vty *)wctx->vty;
- json = (struct json_object *)wctx->json;
+ vty = wctx->vty;
+ json = wctx->json;
zvni = (zebra_vni_t *)bucket->data;
wctx->zvni = zvni;
@@ -1586,8 +1586,8 @@ static void zvni_print_mac_hash_all_vni_detail(struct hash_bucket *bucket,
struct mac_walk_ctx *wctx = ctxt;
char vni_str[VNI_STR_LEN];
- vty = (struct vty *)wctx->vty;
- json = (struct json_object *)wctx->json;
+ vty = wctx->vty;
+ json = wctx->json;
zvni = (zebra_vni_t *)bucket->data;
if (!zvni) {
@@ -3691,7 +3691,7 @@ static struct interface *zvni_map_to_svi(vlanid_t vid, struct interface *br_if)
if (!zif || zif->zif_type != ZEBRA_IF_VLAN
|| zif->link != br_if)
continue;
- vl = (struct zebra_l2info_vlan *)&zif->l2info.vl;
+ vl = &zif->l2info.vl;
if (vl->vid == vid) {
found = 1;