From 6021c6c059b29cbe5498af527442154d5c721a9d Mon Sep 17 00:00:00 2001 From: Chirag Shah Date: Thu, 2 Nov 2017 07:54:45 -0700 Subject: [PATCH] ospfd: VRF aware Router-ID update Ensure zebra received router-id isolated per vrf instance. Store zebra received router-id within ospf instance. Ticket:CM-18657 Reviewed By: Testing Done: Validated follwoing sequence - Create vrf1111 - Create ospf vrf1111 with no router-id - Assign ip to vrf111 - ospf is assigned zebra assigned router-id which is vrf ip. - upon remvoing vrf ip, the router-id retained as same until ospfd restarted. Signed-off-by: Chirag Shah --- ospfd/ospf_vty.c | 9 ++++----- ospfd/ospf_zebra.c | 14 +++++++------- ospfd/ospfd.c | 6 +++--- ospfd/ospfd.h | 1 + 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index cfbe7a459a..a49143873e 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -244,7 +244,6 @@ DEFUN (no_router_ospf, else return CMD_WARNING; } - zlog_debug("%s: no router ospf ", __PRETTY_FUNCTION__); ospf_finish(ospf); return CMD_SUCCESS; @@ -4151,12 +4150,12 @@ static void show_ip_ospf_neighbor_sub(struct vty *vty, if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0) - strncpy(neigh_str, "neighbor", - INET_ADDRSTRLEN); + strlcpy(neigh_str, "neighbor", + sizeof(neigh_str)); else - strncpy(neigh_str, + strlcpy(neigh_str, inet_ntoa(nbr->router_id), - INET_ADDRSTRLEN); + sizeof(neigh_str)); json_object_object_get_ex(json, neigh_str, &json_neigh_array); diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c index 76fa6fa6dd..d7fe0edcbf 100644 --- a/ospfd/ospf_zebra.c +++ b/ospfd/ospf_zebra.c @@ -63,7 +63,6 @@ struct zclient *zclient = NULL; /* For registering threads. */ extern struct thread_master *master; -struct in_addr router_id_zebra; /* Router-id update message from zebra. */ static int ospf_router_id_update_zebra(int command, struct zclient *zclient, @@ -80,13 +79,12 @@ static int ospf_router_id_update_zebra(int command, struct zclient *zclient, buf, ospf_vrf_id_to_name(vrf_id), vrf_id); } - router_id_zebra = router_id.u.prefix4; - ospf = ospf_lookup_by_vrf_id(vrf_id); - if (ospf != NULL) + if (ospf != NULL) { + ospf->router_id_zebra = router_id.u.prefix4; ospf_router_id_update(ospf); - else { + } else { if (IS_DEBUG_OSPF_EVENT) { char buf[PREFIX2STR_BUFFER]; @@ -1434,12 +1432,14 @@ void ospf_zebra_vrf_register(struct ospf *ospf) if (!zclient || zclient->sock < 0 || !ospf) return; - if (ospf->vrf_id != VRF_DEFAULT && ospf->vrf_id != VRF_UNKNOWN) { + if (ospf->vrf_id != VRF_UNKNOWN) { if (IS_DEBUG_OSPF_EVENT) zlog_debug("%s: Register VRF %s id %u", __PRETTY_FUNCTION__, ospf_vrf_id_to_name(ospf->vrf_id), ospf->vrf_id); + /* Deregister for router-id, interfaces, + * redistributed routes. */ zclient_send_reg_requests(zclient, ospf->vrf_id); } } @@ -1451,7 +1451,7 @@ void ospf_zebra_vrf_deregister(struct ospf *ospf) if (ospf->vrf_id != VRF_DEFAULT && ospf->vrf_id != VRF_UNKNOWN) { if (IS_DEBUG_OSPF_EVENT) - zlog_debug("%s: De-Register VRF %s id %u", + zlog_debug("%s: De-Register VRF %s id %u to Zebra.", __PRETTY_FUNCTION__, ospf_vrf_id_to_name(ospf->vrf_id), ospf->vrf_id); diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index 3771f94630..b0646495a5 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -66,7 +66,6 @@ static struct ospf_master ospf_master; struct ospf_master *om; extern struct zclient *zclient; -extern struct in_addr router_id_zebra; static void ospf_remove_vls_through_area(struct ospf *, struct ospf_area *); @@ -117,12 +116,12 @@ void ospf_router_id_update(struct ospf *ospf) else if (ospf->router_id.s_addr != 0) router_id = ospf->router_id; else - router_id = router_id_zebra; + router_id = ospf->router_id_zebra; if (IS_DEBUG_OSPF_EVENT) zlog_debug("Router-ID[OLD:%s]: Update to %s", inet_ntoa(ospf->router_id), - inet_ntoa(router_id_old)); + inet_ntoa(router_id)); if (!IPV4_ADDR_SAME(&router_id_old, &router_id)) { @@ -2056,6 +2055,7 @@ static int ospf_vrf_enable(struct vrf *vrf) } ospf->oi_running = 1; + ospf_zebra_vrf_register(ospf); ospf_router_id_update(ospf); } } diff --git a/ospfd/ospfd.h b/ospfd/ospfd.h index 4c5bb756f6..df318cf2c0 100644 --- a/ospfd/ospfd.h +++ b/ospfd/ospfd.h @@ -134,6 +134,7 @@ struct ospf { /* OSPF Router ID. */ struct in_addr router_id; /* Configured automatically. */ struct in_addr router_id_static; /* Configured manually. */ + struct in_addr router_id_zebra; vrf_id_t vrf_id; /* VRF Id */ char *name; /* VRF name */ -- 2.39.5