From 0e6cb7434fbaca97d8991ac8a4ec291b4f74b1fa Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Thu, 28 Jul 2016 17:23:34 +0200 Subject: [PATCH] bgpd: divorce router-id logic from CLI & zebra Logic for determining the router-id was spread out over bgp_zebra.c and bgp_vty.c. Move to bgpd/bgpd.c and have these two call more properly encapsulated functions. Significant work by Christian Franke . Signed-off-by: David Lamparter --- bgpd/bgp_vty.c | 15 ++++----------- bgpd/bgp_zebra.c | 29 +---------------------------- bgpd/bgpd.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- bgpd/bgpd.h | 3 ++- 4 files changed, 49 insertions(+), 42 deletions(-) diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index bef9856a9d..0f27069a95 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -820,11 +820,7 @@ DEFUN (bgp_router_id, return CMD_WARNING; } - if (IPV4_ADDR_SAME (&bgp->router_id_static, &id)) - return CMD_SUCCESS; - - bgp->router_id_static = id; - bgp_router_id_set (bgp, &id); + bgp_router_id_static_set (bgp, id); return CMD_SUCCESS; } @@ -874,8 +870,8 @@ DEFUN (no_bgp_router_id, } } - bgp->router_id_static.s_addr = 0; - bgp_router_id_set (bgp, &bgp->router_id_zebra); + id.s_addr = 0; + bgp_router_id_static_set (bgp, id); return CMD_SUCCESS; } @@ -919,10 +915,7 @@ DEFUN (bgp_router_id_interface, if (p && (p->family == AF_INET)) { - if (IPV4_ADDR_SAME (&bgp->router_id_static, &p->u.prefix4)) - return CMD_SUCCESS; - bgp->router_id_static = p->u.prefix4; - bgp_router_id_set (bgp, &p->u.prefix4); + bgp_router_id_static_set(bgp, p->u.prefix4); return CMD_SUCCESS; } } diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 888a819d06..68f6cede8b 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -109,8 +109,6 @@ bgp_router_id_update (int command, struct zclient *zclient, zebra_size_t length, vrf_id_t vrf_id) { struct prefix router_id; - struct listnode *node, *nnode; - struct bgp *bgp; zebra_router_id_update_read(zclient->ibuf,&router_id); @@ -121,32 +119,7 @@ bgp_router_id_update (int command, struct zclient *zclient, zebra_size_t length, zlog_debug("Rx Router Id update VRF %u Id %s", vrf_id, buf); } - if (vrf_id == VRF_DEFAULT) - { - /* Router-id change for default VRF has to also update all views. */ - for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp)) - { - if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF) - continue; - - bgp->router_id_zebra = router_id.u.prefix4; - - if (!bgp->router_id_static.s_addr) - bgp_router_id_set (bgp, &router_id.u.prefix4); - } - } - else - { - bgp = bgp_lookup_by_vrf_id (vrf_id); - if (bgp) - { - bgp->router_id_zebra = router_id.u.prefix4; - - if (!bgp->router_id_static.s_addr) - bgp_router_id_set (bgp, &router_id.u.prefix4); - } - } - + bgp_router_id_zebra_bump (vrf_id, &router_id); return 0; } diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 9377568ec8..1a5270874c 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -209,8 +209,8 @@ bgp_config_check (struct bgp *bgp, int config) } /* Set BGP router identifier. */ -int -bgp_router_id_set (struct bgp *bgp, struct in_addr *id) +static int +bgp_router_id_set (struct bgp *bgp, const struct in_addr *id) { struct peer *peer; struct listnode *node, *nnode; @@ -235,6 +235,46 @@ bgp_router_id_set (struct bgp *bgp, struct in_addr *id) return 0; } +void +bgp_router_id_zebra_bump (vrf_id_t vrf_id, const struct prefix *router_id) +{ + struct listnode *node, *nnode; + struct bgp *bgp; + + if (vrf_id == VRF_DEFAULT) + { + /* Router-id change for default VRF has to also update all views. */ + for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp)) + { + if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF) + continue; + + bgp->router_id_zebra = router_id->u.prefix4; + if (!bgp->router_id_static.s_addr) + bgp_router_id_set (bgp, &router_id->u.prefix4); + } + } + else + { + bgp = bgp_lookup_by_vrf_id (vrf_id); + if (bgp) + { + bgp->router_id_zebra = router_id->u.prefix4; + + if (!bgp->router_id_static.s_addr) + bgp_router_id_set (bgp, &router_id->u.prefix4); + } + } +} + +int +bgp_router_id_static_set (struct bgp *bgp, struct in_addr id) +{ + bgp->router_id_static = id; + bgp_router_id_set (bgp, id.s_addr ? &id : &bgp->router_id_zebra); + return 0; +} + /* BGP's cluster-id control. */ int bgp_cluster_id_set (struct bgp *bgp, struct in_addr *cluster_id) diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index db857a8867..1603ed2614 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -1208,7 +1208,8 @@ extern int bgp_flag_check (struct bgp *, int); extern void bgp_lock (struct bgp *); extern void bgp_unlock (struct bgp *); -extern int bgp_router_id_set (struct bgp *, struct in_addr *); +extern void bgp_router_id_zebra_bump (vrf_id_t, const struct prefix*); +extern int bgp_router_id_static_set (struct bgp *, struct in_addr); extern int bgp_cluster_id_set (struct bgp *, struct in_addr *); extern int bgp_cluster_id_unset (struct bgp *); -- 2.39.5