diff options
37 files changed, 1211 insertions, 613 deletions
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_route.c b/bgpd/bgp_route.c index b90abd8741..1d8be6496d 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -3239,7 +3239,7 @@ static bool bgp_update_martian_nexthop(struct bgp *bgp, afi_t afi, safi_t safi, uint8_t type, uint8_t stype, struct attr *attr, struct bgp_node *rn) { - bool ret = 0; + bool ret = false; /* Only validated for unicast and multicast currently. */ /* Also valid for EVPN where the nexthop is an IP address. */ @@ -10284,7 +10284,7 @@ static int bgp_show_route_in_table(struct vty *vty, struct bgp *bgp, } } else if (safi == SAFI_EVPN) { struct bgp_node *longest_pfx; - bool is_exact_pfxlen_match = FALSE; + bool is_exact_pfxlen_match = false; for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) { const struct prefix *rn_p = bgp_node_get_prefix(rn); @@ -10296,7 +10296,7 @@ static int bgp_show_route_in_table(struct vty *vty, struct bgp *bgp, continue; longest_pfx = NULL; - is_exact_pfxlen_match = FALSE; + is_exact_pfxlen_match = false; /* * Search through all the prefixes for a match. The * pfx's are enumerated in ascending order of pfxlens. @@ -10318,7 +10318,7 @@ static int bgp_show_route_in_table(struct vty *vty, struct bgp *bgp, bgp_evpn_get_type5_prefixlen( rm_p); if (type5_pfxlen == match.prefixlen) { - is_exact_pfxlen_match = TRUE; + is_exact_pfxlen_match = true; bgp_unlock_node(rm); break; } diff --git a/doc/user/bgp.rst b/doc/user/bgp.rst index 85ccc277a8..91ba37991b 100644 --- a/doc/user/bgp.rst +++ b/doc/user/bgp.rst @@ -1997,6 +1997,18 @@ BGP Extended Communities in Route Map This command set Site of Origin value. +.. index:: set extcommunity bandwidth <(1-25600) | cumulative | num-multipaths> [non-transitive] +.. clicmd:: set extcommunity bandwidth <(1-25600) | cumulative | num-multipaths> [non-transitive] + + This command sets the BGP link-bandwidth extended community for the prefix + (best path) for which it is applied. The link-bandwidth can be specified as + an ``explicit value`` (specified in Mbps), or the router can be told to use + the ``cumulative bandwidth`` of all multipaths for the prefix or to compute + it based on the ``number of multipaths``. The link bandwidth extended + community is encoded as ``transitive`` unless the set command explicitly + configures it as ``non-transitive``. + +.. seealso:: :ref:`wecmp_linkbw` Note that the extended expanded community is only used for `match` rule, not for `set` actions. @@ -3152,6 +3164,8 @@ Example of how to set up a 6-Bone connection. .. include:: rpki.rst +.. include:: wecmp_linkbw.rst + .. include:: flowspec.rst .. [#med-transitivity-rant] For some set of objects to have an order, there *must* be some binary ordering relation that is defined for *every* combination of those objects, and that relation *must* be transitive. I.e.:, if the relation operator is <, and if a < b and b < c then that relation must carry over and it *must* be that a < c for the objects to have an order. The ordering relation may allow for equality, i.e. a < b and b < a may both be true and imply that a and b are equal in the order and not distinguished by it, in which case the set has a partial order. Otherwise, if there is an order, all the objects have a distinct place in the order and the set has a total order) diff --git a/doc/user/conf.py b/doc/user/conf.py index 5582847431..d8a188b152 100644 --- a/doc/user/conf.py +++ b/doc/user/conf.py @@ -132,7 +132,8 @@ language = None # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = ['_build', 'rpki.rst', 'routeserver.rst', - 'ospf_fundamentals.rst', 'flowspec.rst', 'snmptrap.rst'] + 'ospf_fundamentals.rst', 'flowspec.rst', 'snmptrap.rst', + 'wecmp_linkbw.rst'] # The reST default role (used for this markup: `text`) to use for all # documents. diff --git a/doc/user/pim.rst b/doc/user/pim.rst index f480c6bdc4..f0ec2d26ff 100644 --- a/doc/user/pim.rst +++ b/doc/user/pim.rst @@ -166,6 +166,11 @@ Certain signals have special meanings to *pimd*. urib-only Lookup in the Unicast Rib only. +.. index:: no ip msdp mesh-group [WORD] +.. clicmd:: no ip msdp mesh-group [WORD] + + Delete multicast source discovery protocol mesh-group + .. index:: ip igmp generate-query-once [version (2-3)] .. clicmd:: ip igmp generate-query-once [version (2-3)] diff --git a/doc/user/subdir.am b/doc/user/subdir.am index ce519fbfbf..0b64232f3d 100644 --- a/doc/user/subdir.am +++ b/doc/user/subdir.am @@ -44,6 +44,7 @@ user_RSTFILES = \ doc/user/bfd.rst \ doc/user/flowspec.rst \ doc/user/watchfrr.rst \ + doc/user/wecmp_linkbw.rst \ # end EXTRA_DIST += \ diff --git a/doc/user/wecmp_linkbw.rst b/doc/user/wecmp_linkbw.rst new file mode 100644 index 0000000000..0d2fe9d756 --- /dev/null +++ b/doc/user/wecmp_linkbw.rst @@ -0,0 +1,298 @@ +.. _wecmp_linkbw: + +Weighted ECMP using BGP link bandwidth +====================================== + +.. _features-of-wecmp-linkbw: + +Overview +-------- + +In normal equal cost multipath (ECMP), the route to a destination has +multiple next hops and traffic is expected to be equally distributed +across these next hops. In practice, flow-based hashing is used so that +all traffic associated with a particular flow uses the same next hop, +and by extension, the same path across the network. + +Weigted ECMP using BGP link bandwidth introduces support for network-wide +unequal cost multipathing (UCMP) to an IP destination. The unequal cost +load balancing is implemented by the forwarding plane based on the weights +associated with the next hops of the IP prefix. These weights are computed +based on the bandwidths of the corresponding multipaths which are encoded +in the ``BGP link bandwidth extended community`` as specified in +[Draft-IETF-idr-link-bandwidth]_. Exchange of an appropriate BGP link +bandwidth value for a prefix across the network results in network-wide +unequal cost multipathing. + +One of the primary use cases of this capability is in the data center when +a service (represented by its anycast IP) has an unequal set of resources +across the regions (e.g., PODs) of the data center and the network itself +provides the load balancing function instead of an external load balancer. +Refer to [Draft-IETF-mohanty-bess-ebgp-dmz]_ and :rfc:`7938` for details +on this use case. This use case is applicable in a pure L3 network as +well as in a EVPN network. + +The traditional use case for BGP link bandwidth to load balance traffic +to the exit routers in the AS based on the bandwidth of their external +eBGP peering links is also supported. + + +Design Principles +----------------- + +Next hop weight computation and usage +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +As described, in UCMP, there is a weight associated with each next hop of an +IP prefix, and traffic is expected to be distributed across the next hops in +proportion to their weight. The weight of a next hop is a simple factoring +of the bandwidth of the corresponding path against the total bandwidth of +all multipaths, mapped to the range 1 to 100. What happens if not all the +paths in the multipath set have link bandwidth associated with them? In such +a case, in adherence to [Draft-IETF-idr-link-bandwidth]_, the behavior +reverts to standard ECMP among all the multipaths, with the link bandwidth +being effectively ignored. + +Note that there is no change to either the BGP best path selection algorithm +or to the multipath computation algorithm; the mapping of link bandwidth to +weight happens at the time of installation of the route in the RIB. + +If data forwarding is implemented by means of the Linux kernel, the next hop’s +weight is used in the hash calculation. The kernel uses the Hash threshold +algorithm and use of the next hop weight is built into it; next hops need +not be expanded to achieve UCMP. UCMP for IPv4 is available in older Linux +kernels too, while UCMP for IPv6 is available from the 4.16 kernel onwards. + +If data forwarding is realized in hardware, common implementations expand +the next hops (i.e., they are repeated) in the ECMP container in proportion +to their weight. For example, if the weights associated with 3 next hops for +a particular route are 50, 25 and 25 and the ECMP container has a size of 16 +next hops, the first next hop will be repeated 8 times and the other 2 next +hops repeated 4 times each. Other implementations are also possible. + +Unequal cost multipath across a network +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +For the use cases listed above, it is not sufficient to support UCMP on just +one router (e.g., egress router), or individually, on multiple routers; UCMP +must be deployed across the entire network. This is achieved by employing the +BGP link-bandwidth extended community. + +At the router which originates the BGP link bandwidth, there has to be user +configuration to trigger it, which is described below. Receiving routers +would use the received link bandwidth from their downstream routers to +determine the next hop weight as described in the earlier section. Further, +if the received link bandwidth is a transitive attribute, it would be +propagated to eBGP peers, with the additional change that if the next hop +is set to oneself, the cumulative link bandwidth of all downstream paths +is propagated to other routers. In this manner, the entire network will +know how to distribute traffic to an anycast service across the network. + +The BGP link-bandwidth extended community is encoded in bytes-per-second. +In the use case where UCMP must be based on the number of paths, a reference +bandwidth of 1 Mbps is used. So, for example, if there are 4 equal cost paths +to an anycast IP, the encoded bandwidth in the extended community will be +500,000. The actual value itself doesn’t matter as long as all routers +originating the link-bandwidth are doing it in the same way. + + +Configuration Guide +------------------- + +The configuration for weighted ECMP using BGP link bandwidth requires +one essential step - using a route-map to inject the link bandwidth +extended community. An additional option is provided to control the +processing of received link bandwidth. + +Injecting link bandwidth into the network +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +At the "entry point" router that is injecting the prefix to which weighted +load balancing must be performed, a route-map must be configured to +attach the link bandwidth extended community. + +For the use case of providing weighted load balancing for an anycast service, +this configuration will typically need to be applied at the TOR or Leaf +router that is connected to servers which provide the anycast service and +the bandwidth would be based on the number of multipaths for the destination. + +For the use case of load balancing to the exit router, the exit router should +be configured with the route map specifying the a bandwidth value that +corresponds to the bandwidth of the link connecting to its eBGP peer in the +adjoining AS. In addition, the link bandwidth extended community must be +explicitly configured to be non-transitive. + +The complete syntax of the route-map set command can be found at +:ref:`bgp-extended-communities-in-route-map` + +This route-map is supported only at two attachment points: +(a) the outbound route-map attached to a peer or peer-group, per address-family +(b) the EVPN advertise route-map used to inject IPv4 or IPv6 unicast routes +into EVPN as type-5 routes. + +Since the link bandwidth origination is done by using a route-map, it can +be constrained to certain prefixes (e.g., only for anycast services) or it +can be generated for all prefixes. Further, when the route-map is used in +the neighbor context, the link bandwidth usage can be constrained to certain +peers only. + +A sample configuration is shown below and illustrates link bandwidth +advertisement towards the "SPINE" peer-group for anycast IPs in the +range 192.168.x.x + +.. code-block:: frr + + ip prefix-list anycast_ip seq 10 permit 192.168.0.0/16 le 32 + route-map anycast_ip permit 10 + match ip address prefix-list anycast_ip + set extcommunity bandwidth num-multipaths + route-map anycast_ip permit 20 + ! + router bgp 65001 + neighbor SPINE peer-group + neighbor SPINE remote-as external + neighbor 172.16.35.1 peer-group SPINE + neighbor 172.16.36.1 peer-group SPINE + ! + address-family ipv4 unicast + network 110.0.0.1/32 + network 192.168.44.1/32 + neighbor SPINE route-map anycast_ip out + exit-address-family + ! + + +Controlling link bandwidth processing on the receiver +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +There is no configuration necessary to process received link bandwidth and +translate it into the weight associated with the corresponding next hop; +that happens by default. If some of the multipaths do not have the link +bandwidth extended community, the default behavior is to revert to normal +ECMP as recommended in [Draft-IETF-idr-link-bandwidth]_. + +The operator can change these behaviors with the following configuration: + +.. index:: bgp bestpath bandwidth <ignore | skip-missing | default-weight-for-missing> +.. clicmd:: bgp bestpath bandwidth <ignore | skip-missing | default-weight-for-missing> + +The different options imply behavior as follows: + +- ignore: Ignore link bandwidth completely for route installation + (i.e., do regular ECMP, not weighted) +- skip-missing: Skip paths without link bandwidth and do UCMP among + the others (if at least some paths have link-bandwidth) +- default-weight-for-missing: Assign a low default weight (value 1) + to paths not having link bandwidth + +This configuration is per BGP instance similar to other BGP route-selection +controls; it operates on both IPv4-unicast and IPv6-unicast routes in that +instance. In an EVPN network, this configuration (if required) should be +implemented in the tenant VRF and is again applicable for IPv4-unicast and +IPv6-unicast, including the ones sourced from EVPN type-5 routes. + +A sample snippet of FRR configuration on a receiver to skip paths without +link bandwidth and do weighted ECMP among the other paths (if some of them +have link bandwidth) is as shown below. + +.. code-block:: frr + + router bgp 65021 + bgp bestpath as-path multipath-relax + bgp bestpath bandwidth skip-missing + neighbor LEAF peer-group + neighbor LEAF remote-as external + neighbor 172.16.35.2 peer-group LEAF + neighbor 172.16.36.2 peer-group LEAF + ! + address-family ipv4 unicast + network 130.0.0.1/32 + exit-address-family + ! + + +Stopping the propagation of the link bandwidth outside a domain +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The link bandwidth extended community will get automatically propagated +with the prefix to EBGP peers, if it is encoded as a transitive attribute +by the originator. If this propagation has to be stopped outside of a +particular domain (e.g., stopped from being propagated to routers outside +of the data center core network), the mechanism available is to disable +the advertisement of all BGP extended communities on the specific peering/s. +In other words, the propagation cannot be blocked just for the link bandwidth +extended community. The configuration to disable all extended communities +can be applied to a peer or peer-group (per address-family). + +Of course, the other common way to stop the propagation of the link bandwidth +outside the domain is to block the prefixes themselves from being advertised +and possibly, announce only an aggregate route. This would be quite common +in a EVPN network. + +BGP link bandwidth and UCMP monitoring & troubleshooting +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Existing operational commands to display the BGP routing table for a specific +prefix will show the link bandwidth extended community also, if present. + +An example of an IPv4-unicast route received with the link bandwidth +attribute from two peers is shown below: + +.. code-block:: frr + + CLI# show bgp ipv4 unicast 192.168.10.1/32 + BGP routing table entry for 192.168.10.1/32 + Paths: (2 available, best #2, table default) + Advertised to non peer-group peers: + l1(swp1) l2(swp2) l3(swp3) l4(swp4) + 65002 + fe80::202:ff:fe00:1b from l2(swp2) (110.0.0.2) + (fe80::202:ff:fe00:1b) (used) + Origin IGP, metric 0, valid, external, multipath, bestpath-from-AS 65002 + Extended Community: LB:65002:125000000 (1000.000 Mbps) + Last update: Thu Feb 20 18:34:16 2020 + + 65001 + fe80::202:ff:fe00:15 from l1(swp1) (110.0.0.1) + (fe80::202:ff:fe00:15) (used) + Origin IGP, metric 0, valid, external, multipath, bestpath-from-AS 65001, best (Older Path) + Extended Community: LB:65001:62500000 (500.000 Mbps) + Last update: Thu Feb 20 18:22:34 2020 + +The weights associated with the next hops of a route can be seen by querying +the RIB for a specific route. + +For example, the next hop weights corresponding to the link bandwidths in the +above example is illustrated below: + +.. code-block:: frr + + spine1# show ip route 192.168.10.1/32 + Routing entry for 192.168.10.1/32 + Known via "bgp", distance 20, metric 0, best + Last update 00:00:32 ago + * fe80::202:ff:fe00:1b, via swp2, weight 66 + * fe80::202:ff:fe00:15, via swp1, weight 33 + +For troubleshooting, existing debug logs ``debug bgp updates``, +``debug bgp bestpath <prefix>``, ``debug bgp zebra`` and +``debug zebra kernel`` can be used. + +A debug log snippet when ``debug bgp zebra`` is enabled and a route is +installed by BGP in the RIB with next hop weights is shown below: + +.. code-block:: frr + + 2020-02-29T06:26:19.927754+00:00 leaf1 bgpd[5459]: bgp_zebra_announce: p=192.168.150.1/32, bgp_is_valid_label: 0 + 2020-02-29T06:26:19.928096+00:00 leaf1 bgpd[5459]: Tx route add VRF 33 192.168.150.1/32 metric 0 tag 0 count 2 + 2020-02-29T06:26:19.928289+00:00 leaf1 bgpd[5459]: nhop [1]: 110.0.0.6 if 35 VRF 33 wt 50 RMAC 0a:11:2f:7d:35:20 + 2020-02-29T06:26:19.928479+00:00 leaf1 bgpd[5459]: nhop [2]: 110.0.0.5 if 35 VRF 33 wt 50 RMAC 32:1e:32:a3:6c:bf + 2020-02-29T06:26:19.928668+00:00 leaf1 bgpd[5459]: bgp_zebra_announce: 192.168.150.1/32: announcing to zebra (recursion NOT set) + + +References +---------- + +.. [Draft-IETF-idr-link-bandwidth] <https://tools.ietf.org/html/draft-ietf-idr-link-bandwidth> +.. [Draft-IETF-mohanty-bess-ebgp-dmz] <https://tools.ietf.org/html/draft-mohanty-bess-ebgp-dmz> + 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/lib/defaults.c b/lib/defaults.c index 71ccc73cc6..7466aad5b1 100644 --- a/lib/defaults.c +++ b/lib/defaults.c @@ -100,10 +100,10 @@ static bool frr_match_version(const char *name, const char *vspec, const char *version, bool check) { int cmp; - static struct spec { + static const struct spec { const char *str; - bool dir, eq; - } *s, specs[] = { + int dir, eq; + } specs[] = { {"<=", -1, 1}, {">=", 1, 1}, {"==", 0, 1}, @@ -112,6 +112,7 @@ static bool frr_match_version(const char *name, const char *vspec, {"=", 0, 1}, {NULL, 0, 0}, }; + const struct spec *s; if (!vspec) /* NULL = all versions */ @@ -582,23 +582,39 @@ struct interface *if_get_by_ifindex(ifindex_t ifindex, vrf_id_t vrf_id) return NULL; } -void if_set_index(struct interface *ifp, ifindex_t ifindex) +int if_set_index(struct interface *ifp, ifindex_t ifindex) { struct vrf *vrf; + if (ifp->ifindex == ifindex) + return 0; + vrf = vrf_get(ifp->vrf_id, NULL); assert(vrf); - if (ifp->ifindex == ifindex) - return; + /* + * If there is already an interface with this ifindex, we will collide + * on insertion, so don't even try. + */ + if (if_lookup_by_ifindex(ifindex, ifp->vrf_id)) + return -1; if (ifp->ifindex != IFINDEX_INTERNAL) IFINDEX_RB_REMOVE(vrf, ifp); ifp->ifindex = ifindex; - if (ifp->ifindex != IFINDEX_INTERNAL) - IFINDEX_RB_INSERT(vrf, ifp) + if (ifp->ifindex != IFINDEX_INTERNAL) { + /* + * This should never happen, since we checked if there was + * already an interface with the desired ifindex at the top of + * the function. Nevertheless. + */ + if (IFINDEX_RB_INSERT(vrf, ifp)) + return -1; + } + + return 0; } void if_set_name(struct interface *ifp, const char *name) @@ -1249,8 +1265,6 @@ struct if_link_params *if_link_params_get(struct interface *ifp) struct if_link_params *iflp = XCALLOC(MTYPE_IF_LINK_PARAMS, sizeof(struct if_link_params)); - if (iflp == NULL) - return NULL; /* Set TE metric equal to standard metric */ iflp->te_metric = ifp->metric; @@ -1278,8 +1292,6 @@ struct if_link_params *if_link_params_get(struct interface *ifp) void if_link_params_free(struct interface *ifp) { - if (ifp->link_params == NULL) - return; XFREE(MTYPE_IF_LINK_PARAMS, ifp->link_params); } @@ -308,33 +308,58 @@ RB_HEAD(if_index_head, interface); RB_PROTOTYPE(if_index_head, interface, index_entry, if_cmp_index_func) DECLARE_QOBJ_TYPE(interface) -#define IFNAME_RB_INSERT(vrf, ifp) \ - if (RB_INSERT(if_name_head, &vrf->ifaces_by_name, (ifp))) \ - flog_err(EC_LIB_INTERFACE, \ - "%s(%s): corruption detected -- interface with this " \ - "name exists already in VRF %u!", \ - __func__, (ifp)->name, (ifp)->vrf_id); - -#define IFNAME_RB_REMOVE(vrf, ifp) \ - if (RB_REMOVE(if_name_head, &vrf->ifaces_by_name, (ifp)) == NULL) \ - flog_err(EC_LIB_INTERFACE, \ - "%s(%s): corruption detected -- interface with this " \ - "name doesn't exist in VRF %u!", \ - __func__, (ifp)->name, (ifp)->vrf_id); - -#define IFINDEX_RB_INSERT(vrf, ifp) \ - if (RB_INSERT(if_index_head, &vrf->ifaces_by_index, (ifp))) \ - flog_err(EC_LIB_INTERFACE, \ - "%s(%u): corruption detected -- interface with this " \ - "ifindex exists already in VRF %u!", \ - __func__, (ifp)->ifindex, (ifp)->vrf_id); - -#define IFINDEX_RB_REMOVE(vrf, ifp) \ - if (RB_REMOVE(if_index_head, &vrf->ifaces_by_index, (ifp)) == NULL) \ - flog_err(EC_LIB_INTERFACE, \ - "%s(%u): corruption detected -- interface with this " \ - "ifindex doesn't exist in VRF %u!", \ - __func__, (ifp)->ifindex, (ifp)->vrf_id); +#define IFNAME_RB_INSERT(vrf, ifp) \ + ({ \ + struct interface *_iz = \ + RB_INSERT(if_name_head, &vrf->ifaces_by_name, (ifp)); \ + if (_iz) \ + flog_err( \ + EC_LIB_INTERFACE, \ + "%s(%s): corruption detected -- interface with this " \ + "name exists already in VRF %u!", \ + __func__, (ifp)->name, (ifp)->vrf_id); \ + _iz; \ + }) + +#define IFNAME_RB_REMOVE(vrf, ifp) \ + ({ \ + struct interface *_iz = \ + RB_REMOVE(if_name_head, &vrf->ifaces_by_name, (ifp)); \ + if (_iz == NULL) \ + flog_err( \ + EC_LIB_INTERFACE, \ + "%s(%s): corruption detected -- interface with this " \ + "name doesn't exist in VRF %u!", \ + __func__, (ifp)->name, (ifp)->vrf_id); \ + _iz; \ + }) + + +#define IFINDEX_RB_INSERT(vrf, ifp) \ + ({ \ + struct interface *_iz = RB_INSERT( \ + if_index_head, &vrf->ifaces_by_index, (ifp)); \ + if (_iz) \ + flog_err( \ + EC_LIB_INTERFACE, \ + "%s(%u): corruption detected -- interface with this " \ + "ifindex exists already in VRF %u!", \ + __func__, (ifp)->ifindex, (ifp)->vrf_id); \ + _iz; \ + }) + +#define IFINDEX_RB_REMOVE(vrf, ifp) \ + ({ \ + struct interface *_iz = RB_REMOVE( \ + if_index_head, &vrf->ifaces_by_index, (ifp)); \ + if (_iz == NULL) \ + flog_err( \ + EC_LIB_INTERFACE, \ + "%s(%u): corruption detected -- interface with this " \ + "ifindex doesn't exist in VRF %u!", \ + __func__, (ifp)->ifindex, (ifp)->vrf_id); \ + _iz; \ + }) #define FOR_ALL_INTERFACES(vrf, ifp) \ if (vrf) \ @@ -502,7 +527,7 @@ extern struct interface *if_get_by_name(const char *ifname, vrf_id_t vrf_id); extern struct interface *if_get_by_ifindex(ifindex_t ifindex, vrf_id_t vrf_id); /* Sets the index and adds to index list */ -extern void if_set_index(struct interface *ifp, ifindex_t ifindex); +extern int if_set_index(struct interface *ifp, ifindex_t ifindex); /* Sets the name and adds to name list */ extern void if_set_name(struct interface *ifp, const char *name); diff --git a/lib/stream.c b/lib/stream.c index f046572f41..683a130e44 100644 --- a/lib/stream.c +++ b/lib/stream.c @@ -543,6 +543,27 @@ uint64_t stream_getq(struct stream *s) return q; } +bool stream_getq2(struct stream *s, uint64_t *q) +{ + STREAM_VERIFY_SANE(s); + + if (STREAM_READABLE(s) < sizeof(uint64_t)) { + STREAM_BOUND_WARN2(s, "get uint64"); + return false; + } + + *q = ((uint64_t)s->data[s->getp++]) << 56; + *q |= ((uint64_t)s->data[s->getp++]) << 48; + *q |= ((uint64_t)s->data[s->getp++]) << 40; + *q |= ((uint64_t)s->data[s->getp++]) << 32; + *q |= ((uint64_t)s->data[s->getp++]) << 24; + *q |= ((uint64_t)s->data[s->getp++]) << 16; + *q |= ((uint64_t)s->data[s->getp++]) << 8; + *q |= ((uint64_t)s->data[s->getp++]); + + return true; +} + /* Get next long word from the stream. */ uint32_t stream_get_ipv4(struct stream *s) { diff --git a/lib/stream.h b/lib/stream.h index 6fcf9a53cf..5c7d94fab8 100644 --- a/lib/stream.h +++ b/lib/stream.h @@ -215,6 +215,7 @@ extern bool stream_getl2(struct stream *s, uint32_t *l); extern uint32_t stream_getl_from(struct stream *, size_t); extern uint64_t stream_getq(struct stream *); extern uint64_t stream_getq_from(struct stream *, size_t); +bool stream_getq2(struct stream *s, uint64_t *q); extern uint32_t stream_get_ipv4(struct stream *); /* IEEE-754 floats */ @@ -402,6 +403,25 @@ static inline const uint8_t *ptr_get_be32(const uint8_t *ptr, uint32_t *out) (P) = _pval; \ } while (0) +#define STREAM_GETF(S, P) \ + do { \ + union { \ + float r; \ + uint32_t d; \ + } _pval; \ + if (stream_getl2((S), &_pval.d)) \ + goto stream_failure; \ + (P) = _pval.r; \ + } while (0) + +#define STREAM_GETQ(S, P) \ + do { \ + uint64_t _pval; \ + if (!stream_getq2((S), &_pval)) \ + goto stream_failure; \ + (P) = _pval; \ + } while (0) + #define STREAM_GET(P, STR, SIZE) \ do { \ if (!stream_get2((P), (STR), (SIZE))) \ @@ -324,10 +324,7 @@ const char *vrf_id_to_name(vrf_id_t vrf_id) struct vrf *vrf; vrf = vrf_lookup_by_id(vrf_id); - if (vrf) - return vrf->name; - - return "n/a"; + return VRF_LOGNAME(vrf); } vrf_id_t vrf_name_to_id(const char *name) @@ -593,10 +590,22 @@ int vrf_get_backend(void) return vrf_backend; } -void vrf_configure_backend(int vrf_backend_netns) +int vrf_configure_backend(enum vrf_backend_type backend) { - vrf_backend = vrf_backend_netns; + /* Work around issue in old gcc */ + switch (backend) { + case VRF_BACKEND_UNKNOWN: + case VRF_BACKEND_NETNS: + case VRF_BACKEND_VRF_LITE: + break; + default: + return -1; + } + + vrf_backend = backend; vrf_backend_configured = 1; + + return 0; } int vrf_handler_create(struct vty *vty, const char *vrfname, @@ -101,9 +101,12 @@ RB_PROTOTYPE(vrf_name_head, vrf, name_entry, vrf_name_compare) DECLARE_QOBJ_TYPE(vrf) /* Allow VRF with netns as backend */ -#define VRF_BACKEND_VRF_LITE 0 -#define VRF_BACKEND_NETNS 1 -#define VRF_BACKEND_UNKNOWN 2 +enum vrf_backend_type { + VRF_BACKEND_VRF_LITE, + VRF_BACKEND_NETNS, + VRF_BACKEND_UNKNOWN, + VRF_BACKEND_MAX, +}; extern struct vrf_id_head vrfs_by_id; extern struct vrf_name_head vrfs_by_name; @@ -292,10 +295,10 @@ extern void vrf_install_commands(void); * VRF utilities */ -/* API for configuring VRF backend - * should be called from zebra only +/* + * API for configuring VRF backend */ -extern void vrf_configure_backend(int vrf_backend_netns); +extern int vrf_configure_backend(enum vrf_backend_type backend); extern int vrf_get_backend(void); extern int vrf_is_backend_netns(void); diff --git a/lib/zclient.c b/lib/zclient.c index d8c6e002d5..5402e9c3c5 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -1635,33 +1635,34 @@ int zebra_redistribute_default_send(int command, struct zclient *zclient, } /* Get prefix in ZServ format; family should be filled in on prefix */ -static void zclient_stream_get_prefix(struct stream *s, struct prefix *p) +static int zclient_stream_get_prefix(struct stream *s, struct prefix *p) { size_t plen = prefix_blen(p); uint8_t c; p->prefixlen = 0; if (plen == 0) - return; + return -1; - stream_get(&p->u.prefix, s, plen); + STREAM_GET(&p->u.prefix, s, plen); STREAM_GETC(s, c); p->prefixlen = MIN(plen * 8, c); + return 0; stream_failure: - return; + return -1; } /* Router-id update from zebra daemon. */ -void zebra_router_id_update_read(struct stream *s, struct prefix *rid) +int zebra_router_id_update_read(struct stream *s, struct prefix *rid) { /* Fetch interface address. */ STREAM_GETC(s, rid->family); - zclient_stream_get_prefix(s, rid); + return zclient_stream_get_prefix(s, rid); stream_failure: - return; + return -1; } /* Interface addition from zebra daemon. */ @@ -1710,24 +1711,36 @@ stream_failure: * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ -static void zclient_vrf_add(struct zclient *zclient, vrf_id_t vrf_id) +static int zclient_vrf_add(struct zclient *zclient, vrf_id_t vrf_id) { struct vrf *vrf; - char vrfname_tmp[VRF_NAMSIZ]; + char vrfname_tmp[VRF_NAMSIZ + 1] = {}; struct vrf_data data; - stream_get(&data, zclient->ibuf, sizeof(struct vrf_data)); + STREAM_GET(&data, zclient->ibuf, sizeof(struct vrf_data)); /* Read interface name. */ - stream_get(vrfname_tmp, zclient->ibuf, VRF_NAMSIZ); + STREAM_GET(vrfname_tmp, zclient->ibuf, VRF_NAMSIZ); - /* Lookup/create vrf by vrf_id. */ + if (strlen(vrfname_tmp) == 0) + goto stream_failure; + + /* Lookup/create vrf by name, then vrf_id. */ vrf = vrf_get(vrf_id, vrfname_tmp); + + /* If there's already a VRF with this name, don't create vrf */ + if (!vrf) + return 0; + vrf->data.l.table_id = data.l.table_id; memcpy(vrf->data.l.netns_name, data.l.netns_name, NS_NAMSIZ); /* overwrite default vrf */ if (vrf_id == VRF_DEFAULT) vrf_set_default_name(vrfname_tmp, false); vrf_enable(vrf); + + return 0; +stream_failure: + return -1; } static void zclient_vrf_delete(struct zclient *zclient, vrf_id_t vrf_id) @@ -1748,21 +1761,32 @@ static void zclient_vrf_delete(struct zclient *zclient, vrf_id_t vrf_id) vrf_delete(vrf); } -static void zclient_interface_add(struct zclient *zclient, vrf_id_t vrf_id) +static int zclient_interface_add(struct zclient *zclient, vrf_id_t vrf_id) { struct interface *ifp; - char ifname_tmp[INTERFACE_NAMSIZ]; + char ifname_tmp[INTERFACE_NAMSIZ + 1] = {}; struct stream *s = zclient->ibuf; /* Read interface name. */ - stream_get(ifname_tmp, s, INTERFACE_NAMSIZ); + STREAM_GET(ifname_tmp, s, INTERFACE_NAMSIZ); /* Lookup/create interface by name. */ + if (!vrf_get(vrf_id, NULL)) { + zlog_debug( + "Rx'd interface add from Zebra, but VRF %u does not exist", + vrf_id); + return -1; + } + ifp = if_get_by_name(ifname_tmp, vrf_id); zebra_interface_if_set_value(s, ifp); if_new_via_zapi(ifp); + + return 0; +stream_failure: + return -1; } /* @@ -1774,10 +1798,10 @@ static void zclient_interface_add(struct zclient *zclient, vrf_id_t vrf_id) struct interface *zebra_interface_state_read(struct stream *s, vrf_id_t vrf_id) { struct interface *ifp; - char ifname_tmp[INTERFACE_NAMSIZ]; + char ifname_tmp[INTERFACE_NAMSIZ + 1] = {}; /* Read interface name. */ - stream_get(ifname_tmp, s, INTERFACE_NAMSIZ); + STREAM_GET(ifname_tmp, s, INTERFACE_NAMSIZ); /* Lookup this by interface index. */ ifp = if_lookup_by_name(ifname_tmp, vrf_id); @@ -1791,6 +1815,8 @@ struct interface *zebra_interface_state_read(struct stream *s, vrf_id_t vrf_id) zebra_interface_if_set_value(s, ifp); return ifp; +stream_failure: + return NULL; } static void zclient_interface_delete(struct zclient *zclient, vrf_id_t vrf_id) @@ -1844,21 +1870,23 @@ static void zclient_handle_error(ZAPI_CALLBACK_ARGS) (*zclient->handle_error)(error); } -static void link_params_set_value(struct stream *s, struct if_link_params *iflp) +static int link_params_set_value(struct stream *s, struct if_link_params *iflp) { if (iflp == NULL) - return; + return -1; - iflp->lp_status = stream_getl(s); - iflp->te_metric = stream_getl(s); - iflp->max_bw = stream_getf(s); - iflp->max_rsv_bw = stream_getf(s); - uint32_t bwclassnum = stream_getl(s); + uint32_t bwclassnum; + + STREAM_GETL(s, iflp->lp_status); + STREAM_GETL(s, iflp->te_metric); + STREAM_GETF(s, iflp->max_bw); + STREAM_GETF(s, iflp->max_rsv_bw); + STREAM_GETL(s, bwclassnum); { unsigned int i; for (i = 0; i < bwclassnum && i < MAX_CLASS_TYPE; i++) - iflp->unrsv_bw[i] = stream_getf(s); + STREAM_GETF(s, iflp->unrsv_bw[i]); if (i < bwclassnum) flog_err( EC_LIB_ZAPI_MISSMATCH, @@ -1866,19 +1894,23 @@ static void link_params_set_value(struct stream *s, struct if_link_params *iflp) " - outdated library?", __func__, bwclassnum, MAX_CLASS_TYPE); } - iflp->admin_grp = stream_getl(s); - iflp->rmt_as = stream_getl(s); + STREAM_GETL(s, iflp->admin_grp); + STREAM_GETL(s, iflp->rmt_as); iflp->rmt_ip.s_addr = stream_get_ipv4(s); - iflp->av_delay = stream_getl(s); - iflp->min_delay = stream_getl(s); - iflp->max_delay = stream_getl(s); - iflp->delay_var = stream_getl(s); + STREAM_GETL(s, iflp->av_delay); + STREAM_GETL(s, iflp->min_delay); + STREAM_GETL(s, iflp->max_delay); + STREAM_GETL(s, iflp->delay_var); + + STREAM_GETF(s, iflp->pkt_loss); + STREAM_GETF(s, iflp->res_bw); + STREAM_GETF(s, iflp->ava_bw); + STREAM_GETF(s, iflp->use_bw); - iflp->pkt_loss = stream_getf(s); - iflp->res_bw = stream_getf(s); - iflp->ava_bw = stream_getf(s); - iflp->use_bw = stream_getf(s); + return 0; +stream_failure: + return -1; } struct interface *zebra_interface_link_params_read(struct stream *s, @@ -1887,9 +1919,7 @@ struct interface *zebra_interface_link_params_read(struct stream *s, struct if_link_params *iflp; ifindex_t ifindex; - assert(s); - - ifindex = stream_getl(s); + STREAM_GETL(s, ifindex); struct interface *ifp = if_lookup_by_index(ifindex, vrf_id); @@ -1903,36 +1933,41 @@ struct interface *zebra_interface_link_params_read(struct stream *s, if ((iflp = if_link_params_get(ifp)) == NULL) return NULL; - link_params_set_value(s, iflp); + if (link_params_set_value(s, iflp) != 0) + goto stream_failure; return ifp; + +stream_failure: + return NULL; } static void zebra_interface_if_set_value(struct stream *s, struct interface *ifp) { uint8_t link_params_status = 0; - ifindex_t old_ifindex; + ifindex_t old_ifindex, new_ifindex; old_ifindex = ifp->ifindex; /* Read interface's index. */ - if_set_index(ifp, stream_getl(s)); - ifp->status = stream_getc(s); + STREAM_GETL(s, new_ifindex); + if_set_index(ifp, new_ifindex); + STREAM_GETC(s, ifp->status); /* Read interface's value. */ - ifp->flags = stream_getq(s); - ifp->ptm_enable = stream_getc(s); - ifp->ptm_status = stream_getc(s); - ifp->metric = stream_getl(s); - ifp->speed = stream_getl(s); - ifp->mtu = stream_getl(s); - ifp->mtu6 = stream_getl(s); - ifp->bandwidth = stream_getl(s); - ifp->link_ifindex = stream_getl(s); - ifp->ll_type = stream_getl(s); - ifp->hw_addr_len = stream_getl(s); + STREAM_GETQ(s, ifp->flags); + STREAM_GETC(s, ifp->ptm_enable); + STREAM_GETC(s, ifp->ptm_status); + STREAM_GETL(s, ifp->metric); + STREAM_GETL(s, ifp->speed); + STREAM_GETL(s, ifp->mtu); + STREAM_GETL(s, ifp->mtu6); + STREAM_GETL(s, ifp->bandwidth); + STREAM_GETL(s, ifp->link_ifindex); + STREAM_GETL(s, ifp->ll_type); + STREAM_GETL(s, ifp->hw_addr_len); if (ifp->hw_addr_len) - stream_get(ifp->hw_addr, s, + STREAM_GET(ifp->hw_addr, s, MIN(ifp->hw_addr_len, INTERFACE_HWADDR_MAX)); /* Read Traffic Engineering status */ @@ -1944,6 +1979,11 @@ static void zebra_interface_if_set_value(struct stream *s, } nexthop_group_interface_state_change(ifp, old_ifindex); + + return; +stream_failure: + zlog_err("Could not parse interface values; aborting"); + assert(!"Failed to parse interface values"); } size_t zebra_interface_link_params_write(struct stream *s, @@ -2042,7 +2082,7 @@ struct connected *zebra_interface_address_read(int type, struct stream *s, memset(&d, 0, sizeof(d)); /* Get interface index. */ - ifindex = stream_getl(s); + STREAM_GETL(s, ifindex); /* Lookup index. */ ifp = if_lookup_by_index(ifindex, vrf_id); @@ -2055,16 +2095,18 @@ struct connected *zebra_interface_address_read(int type, struct stream *s, } /* Fetch flag. */ - ifc_flags = stream_getc(s); + STREAM_GETC(s, ifc_flags); /* Fetch interface address. */ - d.family = p.family = stream_getc(s); + STREAM_GETC(s, d.family); + p.family = d.family; plen = prefix_blen(&d); - zclient_stream_get_prefix(s, &p); + if (zclient_stream_get_prefix(s, &p) != 0) + goto stream_failure; /* Fetch destination address. */ - stream_get(&d.u.prefix, s, plen); + STREAM_GET(&d.u.prefix, s, plen); /* N.B. NULL destination pointers are encoded as all zeroes */ dp = memconstant(&d.u.prefix, 0, plen) ? NULL : &d; @@ -2100,6 +2142,9 @@ struct connected *zebra_interface_address_read(int type, struct stream *s, } return ifc; + +stream_failure: + return NULL; } /* @@ -2135,7 +2180,7 @@ zebra_interface_nbr_address_read(int type, struct stream *s, vrf_id_t vrf_id) struct nbr_connected *ifc; /* Get interface index. */ - ifindex = stream_getl(s); + STREAM_GETL(s, ifindex); /* Lookup index. */ ifp = if_lookup_by_index(ifindex, vrf_id); @@ -2148,9 +2193,9 @@ zebra_interface_nbr_address_read(int type, struct stream *s, vrf_id_t vrf_id) return NULL; } - p.family = stream_getc(s); - stream_get(&p.u.prefix, s, prefix_blen(&p)); - p.prefixlen = stream_getc(s); + STREAM_GETC(s, p.family); + STREAM_GET(&p.u.prefix, s, prefix_blen(&p)); + STREAM_GETC(s, p.prefixlen); if (type == ZEBRA_INTERFACE_NBR_ADDRESS_ADD) { /* Currently only supporting P2P links, so any new RA source @@ -2174,18 +2219,21 @@ zebra_interface_nbr_address_read(int type, struct stream *s, vrf_id_t vrf_id) } return ifc; + +stream_failure: + return NULL; } struct interface *zebra_interface_vrf_update_read(struct stream *s, vrf_id_t vrf_id, vrf_id_t *new_vrf_id) { - char ifname[INTERFACE_NAMSIZ]; + char ifname[INTERFACE_NAMSIZ + 1] = {}; struct interface *ifp; vrf_id_t new_id; /* Read interface name. */ - stream_get(ifname, s, INTERFACE_NAMSIZ); + STREAM_GET(ifname, s, INTERFACE_NAMSIZ); /* Lookup interface. */ ifp = if_lookup_by_name(ifname, vrf_id); @@ -2197,10 +2245,13 @@ struct interface *zebra_interface_vrf_update_read(struct stream *s, } /* Fetch new VRF Id. */ - new_id = stream_getl(s); + STREAM_GETL(s, new_id); *new_vrf_id = new_id; return ifp; + +stream_failure: + return NULL; } /* filter unwanted messages until the expected one arrives */ @@ -2309,8 +2360,11 @@ int lm_label_manager_connect(struct zclient *zclient, int async) s = zclient->ibuf; /* read instance and proto */ - uint8_t proto = stream_getc(s); - uint16_t instance = stream_getw(s); + uint8_t proto; + uint16_t instance; + + STREAM_GETC(s, proto); + STREAM_GETW(s, instance); /* sanity */ if (proto != zclient->redist_default) @@ -2325,11 +2379,14 @@ int lm_label_manager_connect(struct zclient *zclient, int async) instance, zclient->instance); /* result code */ - result = stream_getc(s); + STREAM_GETC(s, result); if (zclient_debug) zlog_debug("LM connect-response received, result %u", result); return (int)result; + +stream_failure: + return -1; } /* @@ -2437,8 +2494,11 @@ int lm_get_label_chunk(struct zclient *zclient, uint8_t keep, uint32_t base, s = zclient->ibuf; /* read proto and instance */ - uint8_t proto = stream_getc(s); - uint16_t instance = stream_getw(s); + uint8_t proto; + uint8_t instance; + + STREAM_GETC(s, proto); + STREAM_GETW(s, instance); /* sanities */ if (proto != zclient->redist_default) @@ -2460,10 +2520,10 @@ int lm_get_label_chunk(struct zclient *zclient, uint8_t keep, uint32_t base, } /* keep */ - response_keep = stream_getc(s); + STREAM_GETC(s, response_keep); /* start and end labels */ - *start = stream_getl(s); - *end = stream_getl(s); + STREAM_GETL(s, *start); + STREAM_GETL(s, *end); /* not owning this response */ if (keep != response_keep) { @@ -2485,6 +2545,9 @@ int lm_get_label_chunk(struct zclient *zclient, uint8_t keep, uint32_t base, response_keep); return 0; + +stream_failure: + return -1; } /** @@ -2874,7 +2937,7 @@ int zebra_send_pw(struct zclient *zclient, int command, struct zapi_pw *pw) /* * Receive PW status update from Zebra and send it to LDE process. */ -void zebra_read_pw_status_update(ZAPI_CALLBACK_ARGS, struct zapi_pw_status *pw) +int zebra_read_pw_status_update(ZAPI_CALLBACK_ARGS, struct zapi_pw_status *pw) { struct stream *s; @@ -2883,8 +2946,12 @@ void zebra_read_pw_status_update(ZAPI_CALLBACK_ARGS, struct zapi_pw_status *pw) /* Get data. */ stream_get(pw->ifname, s, IF_NAMESIZE); - pw->ifindex = stream_getl(s); - pw->status = stream_getl(s); + STREAM_GETL(s, pw->ifindex); + STREAM_GETL(s, pw->status); + + return 0; +stream_failure: + return -1; } static void zclient_capability_decode(ZAPI_CALLBACK_ARGS) @@ -2895,7 +2962,14 @@ static void zclient_capability_decode(ZAPI_CALLBACK_ARGS) uint8_t mpls_enabled; STREAM_GETL(s, vrf_backend); - vrf_configure_backend(vrf_backend); + + if (vrf_backend < 0 || vrf_configure_backend(vrf_backend)) { + flog_err(EC_LIB_ZAPI_ENCODE, + "%s: Garbage VRF backend type: %d\n", __func__, + vrf_backend); + goto stream_failure; + } + memset(&cap, 0, sizeof(cap)); STREAM_GETC(s, mpls_enabled); diff --git a/lib/zclient.h b/lib/zclient.h index e747809f16..214226cf5f 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -723,7 +723,7 @@ zebra_interface_nbr_address_read(int, struct stream *, vrf_id_t); extern struct interface *zebra_interface_vrf_update_read(struct stream *s, vrf_id_t vrf_id, vrf_id_t *new_vrf_id); -extern void zebra_router_id_update_read(struct stream *s, struct prefix *rid); +extern int zebra_router_id_update_read(struct stream *s, struct prefix *rid); extern struct interface *zebra_interface_link_params_read(struct stream *s, vrf_id_t vrf_id); @@ -752,7 +752,8 @@ extern int zapi_labels_decode(struct stream *s, struct zapi_labels *zl); extern int zebra_send_pw(struct zclient *zclient, int command, struct zapi_pw *pw); -extern void zebra_read_pw_status_update(ZAPI_CALLBACK_ARGS, struct zapi_pw_status *pw); +extern int zebra_read_pw_status_update(ZAPI_CALLBACK_ARGS, + struct zapi_pw_status *pw); extern int zclient_route_send(uint8_t, struct zclient *, struct zapi_route *); extern int zclient_send_rnh(struct zclient *zclient, int command, diff --git a/ospf6d/ospf6_abr.c b/ospf6d/ospf6_abr.c index 9721446112..1f6cc9d527 100644 --- a/ospf6d/ospf6_abr.c +++ b/ospf6d/ospf6_abr.c @@ -1200,9 +1200,23 @@ void ospf6_abr_examin_summary(struct ospf6_lsa *lsa, struct ospf6_area *oa) listcount(old_route->nh_list)); } } else { - /* adv. router exists in the list, update the nhs */ - list_delete_all_node(o_path->nh_list); - ospf6_copy_nexthops(o_path->nh_list, route->nh_list); + struct ospf6_route *tmp_route = ospf6_route_create(); + + ospf6_copy_nexthops(tmp_route->nh_list, + o_path->nh_list); + + if (ospf6_route_cmp_nexthops(tmp_route, route) != 0) { + /* adv. router exists in the list, update nhs */ + list_delete_all_node(o_path->nh_list); + ospf6_copy_nexthops(o_path->nh_list, + route->nh_list); + ospf6_route_delete(tmp_route); + } else { + /* adv. router has no change in nhs */ + old_entry_updated = false; + ospf6_route_delete(tmp_route); + continue; + } } if (is_debug) diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c index aa50aeacbc..34e5e2a11e 100644 --- a/ospfd/ospf_packet.c +++ b/ospfd/ospf_packet.c @@ -2038,10 +2038,10 @@ static void ospf_ls_upd(struct ospf *ospf, struct ip *iph, SET_FLAG(lsa->flags, OSPF_LSA_SELF); - ospf_opaque_self_originated_lsa_received(nbr, - lsa); ospf_ls_ack_send(nbr, lsa); + ospf_opaque_self_originated_lsa_received(nbr, + lsa); continue; } } diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index e94d15effd..d6c500cdb0 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -9712,11 +9712,25 @@ DEFUN (no_ip_msdp_mesh_group_source, "mesh group local address\n") { PIM_DECLVAR_CONTEXT(vrf, pim); - if (argc == 7) - return ip_no_msdp_mesh_group_cmd_worker(pim, vty, argv[6]->arg); + + return ip_no_msdp_mesh_group_source_cmd_worker(pim, vty, argv[4]->arg); +} + +DEFUN (no_ip_msdp_mesh_group, + no_ip_msdp_mesh_group_cmd, + "no ip msdp mesh-group [WORD]", + NO_STR + IP_STR + CFG_MSDP_STR + "Delete MSDP mesh-group\n" + "mesh group name") +{ + PIM_DECLVAR_CONTEXT(vrf, pim); + + if (argc == 5) + return ip_no_msdp_mesh_group_cmd_worker(pim, vty, argv[4]->arg); else - return ip_no_msdp_mesh_group_source_cmd_worker(pim, vty, - argv[4]->arg); + return ip_no_msdp_mesh_group_cmd_worker(pim, vty, NULL); } static void print_empty_json_obj(struct vty *vty) @@ -11104,6 +11118,8 @@ void pim_cmd_init(void) install_element(VRF_NODE, &ip_msdp_mesh_group_source_cmd); install_element(CONFIG_NODE, &no_ip_msdp_mesh_group_source_cmd); install_element(VRF_NODE, &no_ip_msdp_mesh_group_source_cmd); + install_element(CONFIG_NODE, &no_ip_msdp_mesh_group_cmd); + install_element(VRF_NODE, &no_ip_msdp_mesh_group_cmd); install_element(VIEW_NODE, &show_ip_msdp_peer_detail_cmd); install_element(VIEW_NODE, &show_ip_msdp_peer_detail_vrf_all_cmd); install_element(VIEW_NODE, &show_ip_msdp_sa_detail_cmd); diff --git a/pimd/pim_msdp.c b/pimd/pim_msdp.c index 63d34e859c..52c989e644 100644 --- a/pimd/pim_msdp.c +++ b/pimd/pim_msdp.c @@ -1286,7 +1286,9 @@ enum pim_msdp_err pim_msdp_mg_del(struct pim_instance *pim, struct pim_msdp_mg *mg = pim->msdp.mg; struct pim_msdp_mg_mbr *mbr; - if (!mg || strcmp(mg->mesh_group_name, mesh_group_name)) { + if (!mg + || (mesh_group_name + && strcmp(mg->mesh_group_name, mesh_group_name))) { return PIM_MSDP_ERR_NO_MG; } diff --git a/pimd/pim_upstream.c b/pimd/pim_upstream.c index 872883dfde..982fb7e5a5 100644 --- a/pimd/pim_upstream.c +++ b/pimd/pim_upstream.c @@ -462,10 +462,26 @@ void pim_upstream_join_timer_decrease_to_t_override(const char *debug_label, return; } - join_timer_remain_msec = pim_time_timer_remain_msec(up->t_join_timer); t_override_msec = pim_if_t_override_msec(up->rpf.source_nexthop.interface); + if (up->t_join_timer) { + join_timer_remain_msec = + pim_time_timer_remain_msec(up->t_join_timer); + } else { + /* upstream join tracked with neighbor jp timer */ + struct pim_neighbor *nbr; + + nbr = pim_neighbor_find(up->rpf.source_nexthop.interface, + up->rpf.rpf_addr.u.prefix4); + if (nbr) + join_timer_remain_msec = + pim_time_timer_remain_msec(nbr->jp_timer); + else + /* Manipulate such that override takes place */ + join_timer_remain_msec = t_override_msec + 1; + } + if (PIM_DEBUG_PIM_TRACE) { char rpf_str[INET_ADDRSTRLEN]; pim_inet4_dump("<rpf?>", up->rpf.rpf_addr.u.prefix4, rpf_str, diff --git a/sharpd/sharp_vty.c b/sharpd/sharp_vty.c index 8a787c8e83..e2ea773055 100644 --- a/sharpd/sharp_vty.c +++ b/sharpd/sharp_vty.c @@ -397,7 +397,7 @@ DEFPY(sharp_lsp_prefix_v4, sharp_lsp_prefix_v4_cmd, "sharp lsp (0-100000)$inlabel\ nexthop-group NHGNAME$nhgname\ [prefix A.B.C.D/M$pfx\ - " FRR_IP_REDIST_STR_SHARPD "$type_str [instance (0-255)$instance]]", + " FRR_IP_REDIST_STR_ZEBRA "$type_str [instance (0-255)$instance]]", "Sharp Routing Protocol\n" "Add an LSP\n" "The ingress label to use\n" @@ -405,7 +405,7 @@ DEFPY(sharp_lsp_prefix_v4, sharp_lsp_prefix_v4_cmd, "The nexthop-group name\n" "Label a prefix\n" "The v4 prefix to label\n" - FRR_IP_REDIST_HELP_STR_SHARPD + FRR_IP_REDIST_HELP_STR_ZEBRA "Instance to use\n" "Instance\n") { 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/zebra/rt_netlink.c b/zebra/rt_netlink.c index f29a7fa305..b6224b3da9 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -718,14 +718,15 @@ static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id, if (IS_ZEBRA_DEBUG_KERNEL) { char buf[PREFIX_STRLEN]; char buf2[PREFIX_STRLEN]; - zlog_debug("%s %s%s%s vrf %u(%u) metric: %d Admin Distance: %d", - nl_msg_type_to_str(h->nlmsg_type), - prefix2str(&p, buf, sizeof(buf)), - src_p.prefixlen ? " from " : "", - src_p.prefixlen - ? prefix2str(&src_p, buf2, sizeof(buf2)) - : "", - vrf_id, table, metric, distance); + zlog_debug( + "%s %s%s%s vrf %s(%u) table_id: %u metric: %d Admin Distance: %d", + nl_msg_type_to_str(h->nlmsg_type), + prefix2str(&p, buf, sizeof(buf)), + src_p.prefixlen ? " from " : "", + src_p.prefixlen ? prefix2str(&src_p, buf2, sizeof(buf2)) + : "", + vrf_id_to_name(vrf_id), vrf_id, table, metric, + distance); } afi_t afi = AFI_IP; @@ -911,9 +912,8 @@ static int netlink_route_change_read_multicast(struct nlmsghdr *h, ifp = if_lookup_by_index(iif, vrf); zlog_debug( "MCAST VRF: %s(%d) %s (%s,%s) IIF: %s(%d) OIF: %s jiffies: %lld", - (zvrf ? zvrf->vrf->name : "Unknown"), vrf, - nl_msg_type_to_str(h->nlmsg_type), sbuf, gbuf, - ifp ? ifp->name : "Unknown", iif, oif_list, + zvrf_name(zvrf), vrf, nl_msg_type_to_str(h->nlmsg_type), + sbuf, gbuf, ifp ? ifp->name : "Unknown", iif, oif_list, m->lastused); } return 0; @@ -1122,9 +1122,12 @@ static void _netlink_route_build_singlepath(const struct prefix *p, mpls_lse_t out_lse[MPLS_MAX_LABELS]; char label_buf[256]; int num_labels = 0; + struct vrf *vrf; assert(nexthop); + vrf = vrf_lookup_by_id(nexthop->vrf_id); + /* * label_buf is *only* currently used within debugging. * As such when we assign it we are guarding it inside @@ -1177,9 +1180,10 @@ static void _netlink_route_build_singlepath(const struct prefix *p, if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( - " 5549: _netlink_route_build_singlepath() (%s): %pFX nexthop via %s %s if %u(%u)", + " 5549: _netlink_route_build_singlepath() (%s): %pFX nexthop via %s %s if %u vrf %s(%u)", routedesc, p, ipv4_ll_buf, label_buf, - nexthop->ifindex, nexthop->vrf_id); + nexthop->ifindex, VRF_LOGNAME(vrf), + nexthop->vrf_id); return; } @@ -1202,9 +1206,10 @@ static void _netlink_route_build_singlepath(const struct prefix *p, if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( - "netlink_route_multipath() (%s): %pFX nexthop via %s %s if %u(%u)", + "netlink_route_multipath() (%s): %pFX nexthop via %s %s if %u vrf %s(%u)", routedesc, p, inet_ntoa(nexthop->gate.ipv4), - label_buf, nexthop->ifindex, nexthop->vrf_id); + label_buf, nexthop->ifindex, VRF_LOGNAME(vrf), + nexthop->vrf_id); } if (nexthop->type == NEXTHOP_TYPE_IPV6 @@ -1224,9 +1229,10 @@ static void _netlink_route_build_singlepath(const struct prefix *p, if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( - "netlink_route_multipath() (%s): %pFX nexthop via %s %s if %u(%u)", + "netlink_route_multipath() (%s): %pFX nexthop via %s %s if %u vrf %s(%u)", routedesc, p, inet6_ntoa(nexthop->gate.ipv6), - label_buf, nexthop->ifindex, nexthop->vrf_id); + label_buf, nexthop->ifindex, VRF_LOGNAME(vrf), + nexthop->vrf_id); } /* @@ -1249,9 +1255,9 @@ static void _netlink_route_build_singlepath(const struct prefix *p, if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( - "netlink_route_multipath() (%s): %pFX nexthop via if %u(%u)", + "netlink_route_multipath() (%s): %pFX nexthop via if %u vrf %s(%u)", routedesc, p, nexthop->ifindex, - nexthop->vrf_id); + VRF_LOGNAME(vrf), nexthop->vrf_id); } } @@ -1280,6 +1286,7 @@ _netlink_route_build_multipath(const struct prefix *p, const char *routedesc, mpls_lse_t out_lse[MPLS_MAX_LABELS]; char label_buf[256]; int num_labels = 0; + struct vrf *vrf; rtnh->rtnh_len = sizeof(*rtnh); rtnh->rtnh_flags = 0; @@ -1288,6 +1295,8 @@ _netlink_route_build_multipath(const struct prefix *p, const char *routedesc, assert(nexthop); + vrf = vrf_lookup_by_id(nexthop->vrf_id); + /* * label_buf is *only* currently used within debugging. * As such when we assign it we are guarding it inside @@ -1347,9 +1356,10 @@ _netlink_route_build_multipath(const struct prefix *p, const char *routedesc, if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( - " 5549: netlink_route_build_multipath() (%s): %pFX nexthop via %s %s if %u", + " 5549: netlink_route_build_multipath() (%s): %pFX nexthop via %s %s if %u vrf %s(%u)", routedesc, p, ipv4_ll_buf, label_buf, - nexthop->ifindex); + nexthop->ifindex, VRF_LOGNAME(vrf), + nexthop->vrf_id); return; } @@ -1365,9 +1375,10 @@ _netlink_route_build_multipath(const struct prefix *p, const char *routedesc, if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( - "netlink_route_multipath() (%s): %pFX nexthop via %s %s if %u", + "netlink_route_multipath() (%s): %pFX nexthop via %s %s if %u vrf %s(%u)", routedesc, p, inet_ntoa(nexthop->gate.ipv4), - label_buf, nexthop->ifindex); + label_buf, nexthop->ifindex, VRF_LOGNAME(vrf), + nexthop->vrf_id); } if (nexthop->type == NEXTHOP_TYPE_IPV6 || nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX) { @@ -1382,9 +1393,10 @@ _netlink_route_build_multipath(const struct prefix *p, const char *routedesc, if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( - "netlink_route_multipath() (%s): %pFX nexthop via %s %s if %u", + "netlink_route_multipath() (%s): %pFX nexthop via %s %s if %u vrf %s(%u)", routedesc, p, inet6_ntoa(nexthop->gate.ipv6), - label_buf, nexthop->ifindex); + label_buf, nexthop->ifindex, VRF_LOGNAME(vrf), + nexthop->vrf_id); } /* @@ -1404,8 +1416,9 @@ _netlink_route_build_multipath(const struct prefix *p, const char *routedesc, if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( - "netlink_route_multipath() (%s): %pFX nexthop via if %u", - routedesc, p, nexthop->ifindex); + "netlink_route_multipath() (%s): %pFX nexthop via if %u vrf %s(%u)", + routedesc, p, nexthop->ifindex, + VRF_LOGNAME(vrf), nexthop->vrf_id); } if (nexthop->weight) @@ -1461,9 +1474,9 @@ static void _netlink_route_debug(int cmd, const struct prefix *p, if (IS_ZEBRA_DEBUG_KERNEL) { char buf[PREFIX_STRLEN]; zlog_debug( - "netlink_route_multipath(): %s %s vrf %u(%u)", + "netlink_route_multipath(): %s %s vrf %s(%u) table_id: %u", nl_msg_type_to_str(cmd), - prefix2str(p, buf, sizeof(buf)), + prefix2str(p, buf, sizeof(buf)), vrf_id_to_name(vrfid), vrfid, tableid); } } @@ -2077,10 +2090,10 @@ static int netlink_nexthop(int cmd, struct zebra_dplane_ctx *ctx) nexthop_done: if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug("%s: ID (%u): %pNHv (%u) %s ", - __func__, id, nh, nh->vrf_id, - label_buf); - + zlog_debug("%s: ID (%u): %pNHv vrf %s(%u) %s ", + __func__, id, nh, + vrf_id_to_name(nh->vrf_id), + nh->vrf_id, label_buf); } req.nhm.nh_protocol = zebra2proto(dplane_ctx_get_nhe_type(ctx)); @@ -2881,10 +2894,12 @@ static int netlink_request_specific_mac_in_bridge(struct zebra_ns *zns, addattr32(&req.n, sizeof(req), NDA_MASTER, br_if->ifindex); if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug("%s: Tx family %s IF %s(%u) MAC %s vid %u", __func__, - nl_family_to_str(req.ndm.ndm_family), br_if->name, - br_if->ifindex, - prefix_mac2str(mac, buf, sizeof(buf)), vid); + zlog_debug( + "%s: Tx family %s IF %s(%u) vrf %s(%u) MAC %s vid %u", + __func__, nl_family_to_str(req.ndm.ndm_family), + br_if->name, br_if->ifindex, + vrf_id_to_name(br_if->vrf_id), br_if->vrf_id, + prefix_mac2str(mac, buf, sizeof(buf)), vid); return netlink_request(&zns->netlink_cmd, &req.n); } @@ -3000,6 +3015,7 @@ static int netlink_ipneigh_change(struct nlmsghdr *h, int len, ns_id_t ns_id) struct interface *link_if; struct ethaddr mac; struct ipaddr ip; + struct vrf *vrf; char buf[ETHER_ADDR_STRLEN]; char buf2[INET6_ADDRSTRLEN]; int mac_present = 0; @@ -3014,6 +3030,7 @@ static int netlink_ipneigh_change(struct nlmsghdr *h, int len, ns_id_t ns_id) if (!ifp || !ifp->info) return 0; + vrf = vrf_lookup_by_id(ifp->vrf_id); zif = (struct zebra_if *)ifp->info; /* Parse attributes and extract fields of interest. */ @@ -3021,10 +3038,10 @@ static int netlink_ipneigh_change(struct nlmsghdr *h, int len, ns_id_t ns_id) netlink_parse_rtattr(tb, NDA_MAX, NDA_RTA(ndm), len); if (!tb[NDA_DST]) { - zlog_debug("%s family %s IF %s(%u) - no DST", + zlog_debug("%s family %s IF %s(%u) vrf %s(%u) - no DST", nl_msg_type_to_str(h->nlmsg_type), nl_family_to_str(ndm->ndm_family), ifp->name, - ndm->ndm_ifindex); + ndm->ndm_ifindex, VRF_LOGNAME(vrf), ifp->vrf_id); return 0; } @@ -3076,12 +3093,13 @@ static int netlink_ipneigh_change(struct nlmsghdr *h, int len, ns_id_t ns_id) if (RTA_PAYLOAD(tb[NDA_LLADDR]) != ETH_ALEN) { if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( - "%s family %s IF %s(%u) - LLADDR is not MAC, len %lu", + "%s family %s IF %s(%u) vrf %s(%u) - LLADDR is not MAC, len %lu", nl_msg_type_to_str( h->nlmsg_type), nl_family_to_str( ndm->ndm_family), ifp->name, ndm->ndm_ifindex, + VRF_LOGNAME(vrf), ifp->vrf_id, (unsigned long)RTA_PAYLOAD( tb[NDA_LLADDR])); return 0; @@ -3096,10 +3114,10 @@ static int netlink_ipneigh_change(struct nlmsghdr *h, int len, ns_id_t ns_id) if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( - "Rx %s family %s IF %s(%u) IP %s MAC %s state 0x%x flags 0x%x", + "Rx %s family %s IF %s(%u) vrf %s(%u) IP %s MAC %s state 0x%x flags 0x%x", nl_msg_type_to_str(h->nlmsg_type), nl_family_to_str(ndm->ndm_family), ifp->name, - ndm->ndm_ifindex, + ndm->ndm_ifindex, VRF_LOGNAME(vrf), ifp->vrf_id, ipaddr2str(&ip, buf2, sizeof(buf2)), mac_present ? prefix_mac2str(&mac, buf, sizeof(buf)) @@ -3121,10 +3139,10 @@ static int netlink_ipneigh_change(struct nlmsghdr *h, int len, ns_id_t ns_id) } if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug("Rx %s family %s IF %s(%u) IP %s", + zlog_debug("Rx %s family %s IF %s(%u) vrf %s(%u) IP %s", nl_msg_type_to_str(h->nlmsg_type), nl_family_to_str(ndm->ndm_family), ifp->name, - ndm->ndm_ifindex, + ndm->ndm_ifindex, VRF_LOGNAME(vrf), ifp->vrf_id, ipaddr2str(&ip, buf2, sizeof(buf2))); /* Process the delete - it may result in re-adding the neighbor if it is @@ -3278,9 +3296,10 @@ int netlink_neigh_read_specific_ip(struct ipaddr *ip, zebra_dplane_info_from_zns(&dp_info, zns, true /*is_cmd*/); if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug("%s: neigh request IF %s(%u) IP %s vrf_id %u", + zlog_debug("%s: neigh request IF %s(%u) IP %s vrf %s(%u)", __func__, vlan_if->name, vlan_if->ifindex, - ipaddr2str(ip, buf, sizeof(buf)), vlan_if->vrf_id); + ipaddr2str(ip, buf, sizeof(buf)), + vrf_id_to_name(vlan_if->vrf_id), vlan_if->vrf_id); ret = netlink_request_specific_neigh_in_vlan(zns, RTM_GETNEIGH, ip, vlan_if->ifindex); diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 80116fca18..2dbe907751 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -348,8 +348,8 @@ struct route_entry *rib_match_ipv4_multicast(vrf_id_t vrf_id, char buf[BUFSIZ]; inet_ntop(AF_INET, &addr, buf, BUFSIZ); - zlog_debug("%s: %s: vrf: %u found %s, using %s", - __func__, buf, vrf_id, + zlog_debug("%s: %s: vrf: %s(%u) found %s, using %s", __func__, + buf, vrf_id_to_name(vrf_id), vrf_id, mre ? (ure ? "MRIB+URIB" : "MRIB") : ure ? "URIB" : "nothing", re == ure ? "URIB" : re == mre ? "MRIB" : "none"); @@ -659,13 +659,14 @@ void zebra_rib_evaluate_rn_nexthops(struct route_node *rn, uint32_t seq) char buf1[PREFIX_STRLEN]; char buf2[PREFIX_STRLEN]; - zlog_debug("%u:%s has Nexthop(%s) Type: %s depending on it, evaluating %u:%u", - zvrf->vrf->vrf_id, - srcdest_rnode2str(rn, buf1, - sizeof(buf1)), - prefix2str(p, buf2, sizeof(buf2)), - rnh_type2str(rnh->type), - seq, rnh->seqno); + zlog_debug( + "%s(%u):%s has Nexthop(%s) Type: %s depending on it, evaluating %u:%u", + zvrf_name(zvrf), zvrf_id(zvrf), + srcdest_rnode2str(rn, buf1, + sizeof(buf1)), + prefix2str(p, buf2, sizeof(buf2)), + rnh_type2str(rnh->type), seq, + rnh->seqno); } /* @@ -753,8 +754,8 @@ static void rib_process_add_fib(struct zebra_vrf *zvrf, struct route_node *rn, if (IS_ZEBRA_DEBUG_RIB) { char buf[SRCDEST2STR_BUFFER]; srcdest_rnode2str(rn, buf, sizeof(buf)); - zlog_debug("%u:%s: Adding route rn %p, re %p (%s)", - zvrf_id(zvrf), buf, rn, new, + zlog_debug("%s(%u):%s: Adding route rn %p, re %p (%s)", + zvrf_name(zvrf), zvrf_id(zvrf), buf, rn, new, zebra_route_string(new->type)); } @@ -776,8 +777,8 @@ static void rib_process_del_fib(struct zebra_vrf *zvrf, struct route_node *rn, if (IS_ZEBRA_DEBUG_RIB) { char buf[SRCDEST2STR_BUFFER]; srcdest_rnode2str(rn, buf, sizeof(buf)); - zlog_debug("%u:%s: Deleting route rn %p, re %p (%s)", - zvrf_id(zvrf), buf, rn, old, + zlog_debug("%s(%u):%s: Deleting route rn %p, re %p (%s)", + zvrf_name(zvrf), zvrf_id(zvrf), buf, rn, old, zebra_route_string(old->type)); } @@ -829,15 +830,17 @@ static void rib_process_update_fib(struct zebra_vrf *zvrf, srcdest_rnode2str(rn, buf, sizeof(buf)); if (new != old) zlog_debug( - "%u:%s: Updating route rn %p, re %p (%s) old %p (%s)", - zvrf_id(zvrf), buf, rn, new, + "%s(%u):%s: Updating route rn %p, re %p (%s) old %p (%s)", + zvrf_name(zvrf), zvrf_id(zvrf), + buf, rn, new, zebra_route_string(new->type), old, zebra_route_string(old->type)); else zlog_debug( - "%u:%s: Updating route rn %p, re %p (%s)", - zvrf_id(zvrf), buf, rn, new, + "%s(%u):%s: Updating route rn %p, re %p (%s)", + zvrf_name(zvrf), zvrf_id(zvrf), + buf, rn, new, zebra_route_string(new->type)); } @@ -867,15 +870,17 @@ static void rib_process_update_fib(struct zebra_vrf *zvrf, srcdest_rnode2str(rn, buf, sizeof(buf)); if (new != old) zlog_debug( - "%u:%s: Deleting route rn %p, re %p (%s) old %p (%s) - nexthop inactive", - zvrf_id(zvrf), buf, rn, new, + "%s(%u):%s: Deleting route rn %p, re %p (%s) old %p (%s) - nexthop inactive", + zvrf_name(zvrf), zvrf_id(zvrf), + buf, rn, new, zebra_route_string(new->type), old, zebra_route_string(old->type)); else zlog_debug( - "%u:%s: Deleting route rn %p, re %p (%s) - nexthop inactive", - zvrf_id(zvrf), buf, rn, new, + "%s(%u):%s: Deleting route rn %p, re %p (%s) - nexthop inactive", + zvrf_name(zvrf), zvrf_id(zvrf), + buf, rn, new, zebra_route_string(new->type)); } @@ -990,6 +995,7 @@ static void rib_process(struct route_node *rn) char buf[SRCDEST2STR_BUFFER]; rib_dest_t *dest; struct zebra_vrf *zvrf = NULL; + struct vrf *vrf; const struct prefix *p, *src_p; srcdest_rnode_prefixes(rn, &p, &src_p); @@ -1003,11 +1009,14 @@ static void rib_process(struct route_node *rn) vrf_id = zvrf_id(zvrf); } + vrf = vrf_lookup_by_id(vrf_id); + if (IS_ZEBRA_DEBUG_RIB) srcdest_rnode2str(rn, buf, sizeof(buf)); if (IS_ZEBRA_DEBUG_RIB_DETAILED) - zlog_debug("%u:%s: Processing rn %p", vrf_id, buf, rn); + zlog_debug("%s(%u):%s: Processing rn %p", VRF_LOGNAME(vrf), + vrf_id, buf, rn); /* * we can have rn's that have a NULL info pointer @@ -1021,10 +1030,10 @@ static void rib_process(struct route_node *rn) RNODE_FOREACH_RE_SAFE (rn, re, next) { if (IS_ZEBRA_DEBUG_RIB_DETAILED) zlog_debug( - "%u:%s: Examine re %p (%s) status %x flags %x dist %d metric %d", - vrf_id, buf, re, zebra_route_string(re->type), - re->status, re->flags, re->distance, - re->metric); + "%s(%u):%s: Examine re %p (%s) status %x flags %x dist %d metric %d", + VRF_LOGNAME(vrf), vrf_id, buf, re, + zebra_route_string(re->type), re->status, + re->flags, re->distance, re->metric); /* Currently selected re. */ if (CHECK_FLAG(re->flags, ZEBRA_FLAG_SELECTED)) { @@ -1065,9 +1074,11 @@ static void rib_process(struct route_node *rn) if (re != old_selected) { if (IS_ZEBRA_DEBUG_RIB) zlog_debug( - "%s: %u:%s: imported via import-table but denied " + "%s: %s(%u):%s: imported via import-table but denied " "by the ip protocol table route-map", - __func__, vrf_id, buf); + __func__, + VRF_LOGNAME(vrf), + vrf_id, buf); rib_unlink(rn, re); } else SET_FLAG(re->status, @@ -1118,9 +1129,9 @@ static void rib_process(struct route_node *rn) if (IS_ZEBRA_DEBUG_RIB_DETAILED) { zlog_debug( - "%u:%s: After processing: old_selected %p new_selected %p old_fib %p new_fib %p", - vrf_id, buf, (void *)old_selected, (void *)new_selected, - (void *)old_fib, (void *)new_fib); + "%s(%u):%s: After processing: old_selected %p new_selected %p old_fib %p new_fib %p", + VRF_LOGNAME(vrf), vrf_id, buf, (void *)old_selected, + (void *)new_selected, (void *)old_fib, (void *)new_fib); } /* Buffer ROUTE_ENTRY_CHANGED here, because it will get cleared if @@ -1191,8 +1202,8 @@ static void zebra_rib_evaluate_mpls(struct route_node *rn) if (CHECK_FLAG(dest->flags, RIB_DEST_UPDATE_LSPS)) { if (IS_ZEBRA_DEBUG_MPLS) zlog_debug( - "%u: Scheduling all LSPs upon RIB completion", - zvrf_id(zvrf)); + "%s(%u): Scheduling all LSPs upon RIB completion", + zvrf_name(zvrf), zvrf_id(zvrf)); zebra_mpls_lsp_schedule(zvrf); mpls_unmark_lsps_for_processing(rn); } @@ -1299,6 +1310,9 @@ static bool rib_update_re_from_ctx(struct route_entry *re, bool is_selected = false; /* Is 're' currently the selected re? */ bool changed_p = false; /* Change to nexthops? */ rib_dest_t *dest; + struct vrf *vrf; + + vrf = vrf_lookup_by_id(re->vrf_id); /* Note well: only capturing the prefix string if debug is enabled here; * unconditional log messages will have to generate the string. @@ -1311,8 +1325,9 @@ static bool rib_update_re_from_ctx(struct route_entry *re, is_selected = (re == dest->selected_fib); if (IS_ZEBRA_DEBUG_RIB_DETAILED) - zlog_debug("update_from_ctx: %u:%s: %sSELECTED", - re->vrf_id, dest_str, (is_selected ? "" : "NOT ")); + zlog_debug("update_from_ctx: %s(%u):%s: %sSELECTED", + VRF_LOGNAME(vrf), re->vrf_id, dest_str, + (is_selected ? "" : "NOT ")); /* Update zebra's nexthop FIB flag for each nexthop that was installed. * If the installed set differs from the set requested by the rib/owner, @@ -1325,11 +1340,10 @@ static bool rib_update_re_from_ctx(struct route_entry *re, * Let's assume the nexthops are ordered here to save time. */ if (nexthop_group_equal(&re->fib_ng, dplane_ctx_get_ng(ctx)) == false) { - if (IS_ZEBRA_DEBUG_RIB_DETAILED) { + if (IS_ZEBRA_DEBUG_RIB_DETAILED) zlog_debug( - "%u:%s update_from_ctx: notif nh and fib nh mismatch", - re->vrf_id, dest_str); - } + "%s(%u):%s update_from_ctx: notif nh and fib nh mismatch", + VRF_LOGNAME(vrf), re->vrf_id, dest_str); matched = false; } else @@ -1338,8 +1352,9 @@ static bool rib_update_re_from_ctx(struct route_entry *re, /* If the new FIB set matches the existing FIB set, we're done. */ if (matched) { if (IS_ZEBRA_DEBUG_RIB) - zlog_debug("%u:%s update_from_ctx(): existing fib nhg, no change", - re->vrf_id, dest_str); + zlog_debug( + "%s(%u):%s update_from_ctx(): existing fib nhg, no change", + VRF_LOGNAME(vrf), re->vrf_id, dest_str); goto done; } else if (re->fib_ng.nexthop) { @@ -1347,8 +1362,9 @@ static bool rib_update_re_from_ctx(struct route_entry *re, * Free stale fib list and move on to check the rib nhg. */ if (IS_ZEBRA_DEBUG_RIB) - zlog_debug("%u:%s update_from_ctx(): replacing fib nhg", - re->vrf_id, dest_str); + zlog_debug( + "%s(%u):%s update_from_ctx(): replacing fib nhg", + VRF_LOGNAME(vrf), re->vrf_id, dest_str); nexthops_free(re->fib_ng.nexthop); re->fib_ng.nexthop = NULL; @@ -1356,8 +1372,8 @@ static bool rib_update_re_from_ctx(struct route_entry *re, changed_p = true; } else { if (IS_ZEBRA_DEBUG_RIB) - zlog_debug("%u:%s update_from_ctx(): no fib nhg", - re->vrf_id, dest_str); + zlog_debug("%s(%u):%s update_from_ctx(): no fib nhg", + VRF_LOGNAME(vrf), re->vrf_id, dest_str); } /* @@ -1437,9 +1453,10 @@ static bool rib_update_re_from_ctx(struct route_entry *re, /* If all nexthops were processed, we're done */ if (matched) { if (IS_ZEBRA_DEBUG_RIB) - zlog_debug("%u:%s update_from_ctx(): rib nhg matched, changed '%s'", - re->vrf_id, dest_str, - (changed_p ? "true" : "false")); + zlog_debug( + "%s(%u):%s update_from_ctx(): rib nhg matched, changed '%s'", + VRF_LOGNAME(vrf), re->vrf_id, dest_str, + (changed_p ? "true" : "false")); goto done; } @@ -1449,9 +1466,10 @@ no_nexthops: * create a fib-specific nexthop-group */ if (IS_ZEBRA_DEBUG_RIB) - zlog_debug("%u:%s update_from_ctx(): changed %s, adding new fib nhg", - re->vrf_id, dest_str, - (changed_p ? "true" : "false")); + zlog_debug( + "%s(%u):%s update_from_ctx(): changed %s, adding new fib nhg", + VRF_LOGNAME(vrf), re->vrf_id, dest_str, + (changed_p ? "true" : "false")); ctxnhg = dplane_ctx_get_ng(ctx); @@ -1489,10 +1507,12 @@ rib_find_rn_from_ctx(const struct zebra_dplane_ctx *ctx) dplane_ctx_get_vrf(ctx), dplane_ctx_get_table(ctx)); if (table == NULL) { if (IS_ZEBRA_DEBUG_DPLANE) { - zlog_debug("Failed to find route for ctx: no table for afi %d, safi %d, vrf %u", - dplane_ctx_get_afi(ctx), - dplane_ctx_get_safi(ctx), - dplane_ctx_get_vrf(ctx)); + zlog_debug( + "Failed to find route for ctx: no table for afi %d, safi %d, vrf %s(%u)", + dplane_ctx_get_afi(ctx), + dplane_ctx_get_safi(ctx), + vrf_id_to_name(dplane_ctx_get_vrf(ctx)), + dplane_ctx_get_vrf(ctx)); } goto done; } @@ -1515,6 +1535,7 @@ done: static void rib_process_result(struct zebra_dplane_ctx *ctx) { struct zebra_vrf *zvrf = NULL; + struct vrf *vrf; struct route_node *rn = NULL; struct route_entry *re = NULL, *old_re = NULL, *rib; bool is_update = false; @@ -1526,6 +1547,7 @@ static void rib_process_result(struct zebra_dplane_ctx *ctx) bool fib_changed = false; zvrf = vrf_info_lookup(dplane_ctx_get_vrf(ctx)); + vrf = vrf_lookup_by_id(dplane_ctx_get_vrf(ctx)); dest_pfx = dplane_ctx_get_dest(ctx); /* Note well: only capturing the prefix string if debug is enabled here; @@ -1538,8 +1560,10 @@ static void rib_process_result(struct zebra_dplane_ctx *ctx) rn = rib_find_rn_from_ctx(ctx); if (rn == NULL) { if (IS_ZEBRA_DEBUG_DPLANE) { - zlog_debug("Failed to process dplane results: no route for %u:%s", - dplane_ctx_get_vrf(ctx), dest_str); + zlog_debug( + "Failed to process dplane results: no route for %s(%u):%s", + VRF_LOGNAME(vrf), dplane_ctx_get_vrf(ctx), + dest_str); } goto done; } @@ -1550,9 +1574,10 @@ static void rib_process_result(struct zebra_dplane_ctx *ctx) status = dplane_ctx_get_status(ctx); if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) - zlog_debug("%u:%s Processing dplane ctx %p, op %s result %s", - dplane_ctx_get_vrf(ctx), dest_str, ctx, - dplane_op2str(op), dplane_res2str(status)); + zlog_debug( + "%s(%u):%s Processing dplane ctx %p, op %s result %s", + VRF_LOGNAME(vrf), dplane_ctx_get_vrf(ctx), dest_str, + ctx, dplane_op2str(op), dplane_res2str(status)); /* * Update is a bit of a special case, where we may have both old and new @@ -1590,9 +1615,10 @@ static void rib_process_result(struct zebra_dplane_ctx *ctx) if (re) { if (re->dplane_sequence != seq) { if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) - zlog_debug("%u:%s Stale dplane result for re %p", - dplane_ctx_get_vrf(ctx), - dest_str, re); + zlog_debug( + "%s(%u):%s Stale dplane result for re %p", + VRF_LOGNAME(vrf), + dplane_ctx_get_vrf(ctx), dest_str, re); } else UNSET_FLAG(re->status, ROUTE_ENTRY_QUEUED); } @@ -1600,9 +1626,11 @@ static void rib_process_result(struct zebra_dplane_ctx *ctx) if (old_re) { if (old_re->dplane_sequence != dplane_ctx_get_old_seq(ctx)) { if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) - zlog_debug("%u:%s Stale dplane result for old_re %p", - dplane_ctx_get_vrf(ctx), - dest_str, old_re); + zlog_debug( + "%s(%u):%s Stale dplane result for old_re %p", + VRF_LOGNAME(vrf), + dplane_ctx_get_vrf(ctx), dest_str, + old_re); } else UNSET_FLAG(old_re->status, ROUTE_ENTRY_QUEUED); } @@ -1639,10 +1667,11 @@ static void rib_process_result(struct zebra_dplane_ctx *ctx) if (!fib_changed) { if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) - zlog_debug("%u:%s no fib change for re", - dplane_ctx_get_vrf( - ctx), - dest_str); + zlog_debug( + "%s(%u):%s no fib change for re", + VRF_LOGNAME(vrf), + dplane_ctx_get_vrf(ctx), + dest_str); } /* Redistribute */ @@ -1677,10 +1706,10 @@ static void rib_process_result(struct zebra_dplane_ctx *ctx) zsend_route_notify_owner(re, dest_pfx, ZAPI_ROUTE_FAIL_INSTALL); - zlog_warn("%u:%s: Route install failed", - dplane_ctx_get_vrf(ctx), - prefix2str(dest_pfx, - dest_str, sizeof(dest_str))); + zlog_warn("%s(%u):%s: Route install failed", + VRF_LOGNAME(vrf), dplane_ctx_get_vrf(ctx), + prefix2str(dest_pfx, dest_str, + sizeof(dest_str))); } break; case DPLANE_OP_ROUTE_DELETE: @@ -1706,10 +1735,10 @@ static void rib_process_result(struct zebra_dplane_ctx *ctx) zsend_route_notify_owner_ctx(ctx, ZAPI_ROUTE_REMOVE_FAIL); - zlog_warn("%u:%s: Route Deletion failure", - dplane_ctx_get_vrf(ctx), - prefix2str(dest_pfx, - dest_str, sizeof(dest_str))); + zlog_warn("%s(%u):%s: Route Deletion failure", + VRF_LOGNAME(vrf), dplane_ctx_get_vrf(ctx), + prefix2str(dest_pfx, dest_str, + sizeof(dest_str))); } /* @@ -1747,6 +1776,7 @@ static void rib_process_dplane_notify(struct zebra_dplane_ctx *ctx) { struct route_node *rn = NULL; struct route_entry *re = NULL; + struct vrf *vrf; struct nexthop *nexthop; char dest_str[PREFIX_STRLEN] = ""; const struct prefix *dest_pfx, *src_pfx; @@ -1755,6 +1785,7 @@ static void rib_process_dplane_notify(struct zebra_dplane_ctx *ctx) bool debug_p = IS_ZEBRA_DEBUG_DPLANE | IS_ZEBRA_DEBUG_RIB; int start_count, end_count; dest_pfx = dplane_ctx_get_dest(ctx); + vrf = vrf_lookup_by_id(dplane_ctx_get_vrf(ctx)); /* Note well: only capturing the prefix string if debug is enabled here; * unconditional log messages will have to generate the string. @@ -1766,8 +1797,10 @@ static void rib_process_dplane_notify(struct zebra_dplane_ctx *ctx) rn = rib_find_rn_from_ctx(ctx); if (rn == NULL) { if (debug_p) { - zlog_debug("Failed to process dplane notification: no routes for %u:%s", - dplane_ctx_get_vrf(ctx), dest_str); + zlog_debug( + "Failed to process dplane notification: no routes for %s(%u):%s", + VRF_LOGNAME(vrf), dplane_ctx_get_vrf(ctx), + dest_str); } goto done; } @@ -1776,8 +1809,9 @@ static void rib_process_dplane_notify(struct zebra_dplane_ctx *ctx) srcdest_rnode_prefixes(rn, &dest_pfx, &src_pfx); if (debug_p) - zlog_debug("%u:%s Processing dplane notif ctx %p", - dplane_ctx_get_vrf(ctx), dest_str, ctx); + zlog_debug("%s(%u):%s Processing dplane notif ctx %p", + VRF_LOGNAME(vrf), dplane_ctx_get_vrf(ctx), dest_str, + ctx); /* * Take a pass through the routes, look for matches with the context @@ -1791,10 +1825,11 @@ static void rib_process_dplane_notify(struct zebra_dplane_ctx *ctx) /* No match? Nothing we can do */ if (re == NULL) { if (debug_p) - zlog_debug("%u:%s Unable to process dplane notification: no entry for type %s", - dplane_ctx_get_vrf(ctx), dest_str, - zebra_route_string( - dplane_ctx_get_type(ctx))); + zlog_debug( + "%s(%u):%s Unable to process dplane notification: no entry for type %s", + VRF_LOGNAME(vrf), dplane_ctx_get_vrf(ctx), + dest_str, + zebra_route_string(dplane_ctx_get_type(ctx))); goto done; } @@ -1824,17 +1859,21 @@ static void rib_process_dplane_notify(struct zebra_dplane_ctx *ctx) if (CHECK_FLAG(re->status, ROUTE_ENTRY_INSTALLED)) UNSET_FLAG(re->status, ROUTE_ENTRY_INSTALLED); if (debug_p) - zlog_debug("%u:%s dplane notif, uninstalled type %s route", - dplane_ctx_get_vrf(ctx), dest_str, - zebra_route_string( - dplane_ctx_get_type(ctx))); + zlog_debug( + "%s(%u):%s dplane notif, uninstalled type %s route", + VRF_LOGNAME(vrf), + dplane_ctx_get_vrf(ctx), dest_str, + zebra_route_string( + dplane_ctx_get_type(ctx))); } else { /* At least report on the event. */ if (debug_p) - zlog_debug("%u:%s dplane notif, but type %s not selected_fib", - dplane_ctx_get_vrf(ctx), dest_str, - zebra_route_string( - dplane_ctx_get_type(ctx))); + zlog_debug( + "%s(%u):%s dplane notif, but type %s not selected_fib", + VRF_LOGNAME(vrf), + dplane_ctx_get_vrf(ctx), dest_str, + zebra_route_string( + dplane_ctx_get_type(ctx))); } goto done; } @@ -1859,8 +1898,10 @@ static void rib_process_dplane_notify(struct zebra_dplane_ctx *ctx) if (!fib_changed) { if (debug_p) - zlog_debug("%u:%s dplane notification: rib_update returns FALSE", - dplane_ctx_get_vrf(ctx), dest_str); + zlog_debug( + "%s(%u):%s dplane notification: rib_update returns FALSE", + VRF_LOGNAME(vrf), dplane_ctx_get_vrf(ctx), + dest_str); } /* @@ -1879,8 +1920,10 @@ static void rib_process_dplane_notify(struct zebra_dplane_ctx *ctx) */ if (start_count > 0 && end_count > 0) { if (debug_p) - zlog_debug("%u:%s applied nexthop changes from dplane notification", - dplane_ctx_get_vrf(ctx), dest_str); + zlog_debug( + "%s(%u):%s applied nexthop changes from dplane notification", + VRF_LOGNAME(vrf), dplane_ctx_get_vrf(ctx), + dest_str); /* Changed nexthops - update kernel/others */ dplane_route_notif_update(rn, re, @@ -1888,8 +1931,10 @@ static void rib_process_dplane_notify(struct zebra_dplane_ctx *ctx) } else if (start_count == 0 && end_count > 0) { if (debug_p) - zlog_debug("%u:%s installed transition from dplane notification", - dplane_ctx_get_vrf(ctx), dest_str); + zlog_debug( + "%s(%u):%s installed transition from dplane notification", + VRF_LOGNAME(vrf), dplane_ctx_get_vrf(ctx), + dest_str); /* We expect this to be the selected route, so we want * to tell others about this transition. @@ -1904,8 +1949,10 @@ static void rib_process_dplane_notify(struct zebra_dplane_ctx *ctx) } else if (start_count > 0 && end_count == 0) { if (debug_p) - zlog_debug("%u:%s un-installed transition from dplane notification", - dplane_ctx_get_vrf(ctx), dest_str); + zlog_debug( + "%s(%u):%s un-installed transition from dplane notification", + VRF_LOGNAME(vrf), dplane_ctx_get_vrf(ctx), + dest_str); /* Transition from _something_ installed to _nothing_ * installed. @@ -1970,8 +2017,8 @@ static void process_subq_route(struct listnode *lnode, uint8_t qindex) char buf[SRCDEST2STR_BUFFER]; srcdest_rnode2str(rnode, buf, sizeof(buf)); - zlog_debug("%u:%s: rn %p dequeued from sub-queue %u", - zvrf ? zvrf_id(zvrf) : 0, buf, rnode, qindex); + zlog_debug("%s(%u):%s: rn %p dequeued from sub-queue %u", + zvrf_name(zvrf), zvrf_id(zvrf), buf, rnode, qindex); } if (rnode->info) @@ -2383,9 +2430,9 @@ void rib_delnode(struct route_node *rn, struct route_entry *re) if (IS_ZEBRA_DEBUG_RIB) { char buf[SRCDEST2STR_BUFFER]; srcdest_rnode2str(rn, buf, sizeof(buf)); - zlog_debug("%u:%s: Freeing route rn %p, re %p (%s)", - re->vrf_id, buf, rn, re, - zebra_route_string(re->type)); + zlog_debug("%s(%u):%s: Freeing route rn %p, re %p (%s)", + vrf_id_to_name(re->vrf_id), re->vrf_id, buf, + rn, re, zebra_route_string(re->type)); } rib_unlink(rn, re); @@ -2515,14 +2562,17 @@ void rib_lookup_and_dump(struct prefix_ipv4 *p, vrf_id_t vrf_id) struct route_table *table; struct route_node *rn; struct route_entry *re; + struct vrf *vrf; char prefix_buf[INET_ADDRSTRLEN]; + vrf = vrf_lookup_by_id(vrf_id); + /* Lookup table. */ table = zebra_vrf_table(AFI_IP, SAFI_UNICAST, vrf_id); if (!table) { flog_err(EC_ZEBRA_TABLE_LOOKUP_FAILED, - "%s:%u zebra_vrf_table() returned NULL", __func__, - vrf_id); + "%s:%s(%u) zebra_vrf_table() returned NULL", __func__, + VRF_LOGNAME(vrf), vrf_id); return; } @@ -2531,7 +2581,8 @@ void rib_lookup_and_dump(struct prefix_ipv4 *p, vrf_id_t vrf_id) /* No route for this prefix. */ if (!rn) { - zlog_debug("%s:%u lookup failed for %s", __func__, vrf_id, + zlog_debug("%s:%s(%u) lookup failed for %s", __func__, + VRF_LOGNAME(vrf), vrf_id, prefix2str((struct prefix *)p, prefix_buf, sizeof(prefix_buf))); return; @@ -2542,9 +2593,8 @@ void rib_lookup_and_dump(struct prefix_ipv4 *p, vrf_id_t vrf_id) /* let's go */ RNODE_FOREACH_RE (rn, re) { - zlog_debug("%s:%u rn %p, re %p: %s, %s", - __func__, vrf_id, - (void *)rn, (void *)re, + zlog_debug("%s:%s(%u) rn %p, re %p: %s, %s", __func__, + VRF_LOGNAME(vrf), vrf_id, (void *)rn, (void *)re, (CHECK_FLAG(re->status, ROUTE_ENTRY_REMOVED) ? "removed" : "NOT removed"), @@ -2567,9 +2617,11 @@ void rib_lookup_and_pushup(struct prefix_ipv4 *p, vrf_id_t vrf_id) rib_dest_t *dest; if (NULL == (table = zebra_vrf_table(AFI_IP, SAFI_UNICAST, vrf_id))) { + struct vrf *vrf = vrf_lookup_by_id(vrf_id); + flog_err(EC_ZEBRA_TABLE_LOOKUP_FAILED, - "%s:%u zebra_vrf_table() returned NULL", __func__, - vrf_id); + "%s:%s(%u) zebra_vrf_table() returned NULL", __func__, + VRF_LOGNAME(vrf), vrf_id); return; } @@ -2592,10 +2644,13 @@ void rib_lookup_and_pushup(struct prefix_ipv4 *p, vrf_id_t vrf_id) if (dest->selected_fib) { if (IS_ZEBRA_DEBUG_RIB) { char buf[PREFIX_STRLEN]; + struct vrf *vrf = + vrf_lookup_by_id(dest->selected_fib->vrf_id); - zlog_debug("%u:%s: freeing way for connected prefix", - dest->selected_fib->vrf_id, - prefix2str(&rn->p, buf, sizeof(buf))); + zlog_debug( + "%s(%u):%s: freeing way for connected prefix", + VRF_LOGNAME(vrf), dest->selected_fib->vrf_id, + prefix2str(&rn->p, buf, sizeof(buf))); route_entry_dump(&rn->p, NULL, dest->selected_fib); } rib_uninstall(rn, dest->selected_fib); @@ -3091,8 +3146,7 @@ void rib_update_table(struct route_table *table, rib_update_event_t event) table->info ? afi2str( ((rib_table_info_t *)table->info)->afi) : "Unknown", - vrf ? vrf->name : "Unknown", - zvrf ? zvrf->table_id : 0, + VRF_LOGNAME(vrf), zvrf ? zvrf->table_id : 0, rib_update_event2str(event)); } diff --git a/zebra/zebra_vrf.h b/zebra/zebra_vrf.h index 5448e17073..268ee12a65 100644 --- a/zebra/zebra_vrf.h +++ b/zebra/zebra_vrf.h @@ -193,7 +193,7 @@ struct zebra_vrf { static inline vrf_id_t zvrf_id(struct zebra_vrf *zvrf) { if (!zvrf || !zvrf->vrf) - return VRF_UNKNOWN; + return VRF_DEFAULT; return zvrf->vrf->vrf_id; } @@ -206,6 +206,8 @@ static inline const char *zvrf_ns_name(struct zebra_vrf *zvrf) static inline const char *zvrf_name(struct zebra_vrf *zvrf) { + if (!zvrf || !zvrf->vrf) + return "Unknown"; return zvrf->vrf->name; } |
