summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bgpd/bgp_main.c83
-rw-r--r--bgpd/bgp_zebra.c62
-rw-r--r--lib/zclient.c18
-rw-r--r--lib/zclient.h4
4 files changed, 90 insertions, 77 deletions
diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c
index 7626077c95..b45c35e650 100644
--- a/bgpd/bgp_main.c
+++ b/bgpd/bgp_main.c
@@ -290,6 +290,87 @@ bgp_exit (int status)
exit (status);
}
+static int
+bgp_vrf_new (vrf_id_t vrf_id, const char *name, void **info)
+{
+ if (BGP_DEBUG (zebra, ZEBRA))
+ zlog_debug ("VRF Created: %s(%d)", name, vrf_id);
+
+ return 0;
+}
+
+static int
+bgp_vrf_delete (vrf_id_t vrf_id, const char *name, void **info)
+{
+ if (BGP_DEBUG (zebra, ZEBRA))
+ zlog_debug ("VRF Deletion: %s(%d)", name, vrf_id);
+
+ return 0;
+}
+
+static int
+bgp_vrf_enable (vrf_id_t vrf_id, const char *name, void **info)
+{
+ struct vrf *vrf;
+ struct bgp *bgp;
+
+ vrf = vrf_lookup (vrf_id);
+ if (!vrf) // unexpected
+ return -1;
+
+ if (BGP_DEBUG (zebra, ZEBRA))
+ zlog_debug("VRF enable add %s id %d", name, vrf_id);
+
+ bgp = bgp_lookup_by_name(name);
+ if (bgp)
+ {
+ /* We have instance configured, link to VRF and make it "up". */
+ bgp_vrf_link (bgp, vrf);
+ bgp_instance_up (bgp);
+ }
+
+ return 0;
+}
+
+static int
+bgp_vrf_disable (vrf_id_t vrf_id, const char *name, void **info)
+{
+ struct vrf *vrf;
+ struct bgp *bgp;
+
+ if (vrf_id == VRF_DEFAULT)
+ return 0;
+
+ vrf = vrf_lookup (vrf_id);
+ if (!vrf) // unexpected
+ return -1;
+
+ if (BGP_DEBUG (zebra, ZEBRA))
+ zlog_debug("VRF disable %s id %d", name, vrf_id);
+
+ bgp = bgp_lookup_by_name(name);
+ if (bgp)
+ {
+ /* We have instance configured, unlink from VRF and make it "down". */
+ bgp_vrf_unlink (bgp, vrf);
+ bgp_instance_down (bgp);
+ }
+
+ /* Note: This is a callback, the VRF will be deleted by the caller. */
+ return 0;
+}
+
+static void
+bgp_vrf_init (void)
+{
+ vrf_add_hook (VRF_NEW_HOOK, bgp_vrf_new);
+ vrf_add_hook (VRF_ENABLE_HOOK, bgp_vrf_enable);
+ vrf_add_hook (VRF_DISABLE_HOOK, bgp_vrf_disable);
+ vrf_add_hook (VRF_DELETE_HOOK, bgp_vrf_delete);
+
+ vrf_init ();
+}
+
/* Main routine of bgpd. Treatment of argument and start bgp finite
state machine is handled at here. */
int
@@ -400,7 +481,7 @@ main (int argc, char **argv)
cmd_init (1);
vty_init (bm->master);
memory_init ();
- vrf_init ();
+ bgp_vrf_init ();
/* BGP related initialization. */
bgp_init ();
diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c
index d8427307ce..94a0a566b5 100644
--- a/bgpd/bgp_zebra.c
+++ b/bgpd/bgp_zebra.c
@@ -234,64 +234,6 @@ bgp_nbr_connected_delete (struct bgp *bgp, struct nbr_connected *ifc, int del)
}
}
-/* VRF learnt from Zebra. */
-static int
-bgp_vrf_add (int command, struct zclient *zclient, zebra_size_t length,
- vrf_id_t vrf_id)
-{
- struct vrf *vrf;
- struct bgp *bgp;
-
- vrf = zebra_vrf_add_read (zclient->ibuf, vrf_id);
- if (!vrf) // unexpected
- return -1;
-
- if (BGP_DEBUG (zebra, ZEBRA))
- zlog_debug("Rx VRF add %s id %d", vrf->name, vrf_id);
-
- bgp = bgp_lookup_by_name(vrf->name);
- if (bgp)
- {
- /* We have instance configured, link to VRF and make it "up". */
- bgp_vrf_link (bgp, vrf);
- bgp_instance_up (bgp);
- }
-
- return 0;
-}
-
-/* VRF deleted by Zebra. */
-static int
-bgp_vrf_delete (int command, struct zclient *zclient, zebra_size_t length,
- vrf_id_t vrf_id)
-{
- struct vrf *vrf;
- struct bgp *bgp;
-
- /* Default VRF cannot be deleted. */
- assert (vrf_id != VRF_DEFAULT);
-
- vrf = zebra_vrf_state_read (zclient->ibuf, vrf_id);
- if (!vrf) // unexpected
- return -1;
-
- if (BGP_DEBUG (zebra, ZEBRA))
- zlog_debug("Rx VRF del %s id %d", vrf->name, vrf_id);
-
- bgp = bgp_lookup_by_name(vrf->name);
- if (bgp)
- {
- /* We have instance configured, unlink from VRF and make it "down". */
- bgp_vrf_unlink (bgp, vrf);
- bgp_instance_down (bgp);
- }
-
- /* Note: This is a callback, the VRF will be deleted by the caller. */
- return 0;
-}
-
-
-
/* Inteface addition message from zebra. */
static int
bgp_interface_add (int command, struct zclient *zclient, zebra_size_t length,
@@ -2049,8 +1991,6 @@ bgp_zebra_init (struct thread_master *master)
zclient_init (zclient, ZEBRA_ROUTE_BGP, 0);
zclient->zebra_connected = bgp_zebra_connected;
zclient->router_id_update = bgp_router_id_update;
- zclient->vrf_add = bgp_vrf_add;
- zclient->vrf_delete = bgp_vrf_delete;
zclient->interface_add = bgp_interface_add;
zclient->interface_delete = bgp_interface_delete;
zclient->interface_address_add = bgp_interface_address_add;
@@ -2064,12 +2004,10 @@ bgp_zebra_init (struct thread_master *master)
zclient->redistribute_route_ipv4_del = zebra_read_ipv4;
zclient->interface_up = bgp_interface_up;
zclient->interface_down = bgp_interface_down;
-#ifdef HAVE_IPV6
zclient->ipv6_route_add = zebra_read_ipv6;
zclient->ipv6_route_delete = zebra_read_ipv6;
zclient->redistribute_route_ipv6_add = zebra_read_ipv6;
zclient->redistribute_route_ipv6_del = zebra_read_ipv6;
-#endif /* HAVE_IPV6 */
zclient->nexthop_update = bgp_read_nexthop_update;
zclient->import_check_update = bgp_read_import_check_update;
diff --git a/lib/zclient.c b/lib/zclient.c
index c971bff6e2..1aa1251bf5 100644
--- a/lib/zclient.c
+++ b/lib/zclient.c
@@ -919,8 +919,8 @@ zebra_router_id_update_read (struct stream *s, struct prefix *rid)
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
-struct vrf *
-zebra_vrf_add_read (struct stream *s, vrf_id_t vrf_id)
+static void
+zclient_vrf_add (struct stream *s, vrf_id_t vrf_id)
{
struct vrf *vrf;
char vrfname_tmp[VRF_NAMSIZ];
@@ -931,18 +931,18 @@ zebra_vrf_add_read (struct stream *s, vrf_id_t vrf_id)
/* Lookup/create vrf by vrf_id. */
vrf = vrf_get (vrf_id, vrfname_tmp);
- return vrf;
+ vrf_enable (vrf);
}
-struct vrf *
-zebra_vrf_state_read (struct stream *s, vrf_id_t vrf_id)
+static void
+zclient_vrf_delete (struct stream *s, vrf_id_t vrf_id)
{
struct vrf *vrf;
/* Lookup vrf by vrf_id. */
vrf = vrf_lookup (vrf_id);
- return vrf;
+ vrf_delete (vrf);
}
struct interface *
@@ -1341,12 +1341,10 @@ zclient_read (struct thread *thread)
(*zclient->router_id_update) (command, zclient, length, vrf_id);
break;
case ZEBRA_VRF_ADD:
- if (zclient->vrf_add)
- (*zclient->vrf_add) (command, zclient, length, vrf_id);
+ zclient_vrf_add (zclient->ibuf, vrf_id);
break;
case ZEBRA_VRF_DELETE:
- if (zclient->vrf_delete)
- (*zclient->vrf_delete) (command, zclient, length, vrf_id);
+ zclient_vrf_delete (zclient->ibuf, vrf_id);
break;
case ZEBRA_INTERFACE_ADD:
if (zclient->interface_add)
diff --git a/lib/zclient.h b/lib/zclient.h
index 49f73b3e9b..d411965217 100644
--- a/lib/zclient.h
+++ b/lib/zclient.h
@@ -87,8 +87,6 @@ struct zclient
/* Pointer to the callback functions. */
void (*zebra_connected) (struct zclient *);
int (*router_id_update) (int, struct zclient *, uint16_t, vrf_id_t);
- int (*vrf_add) (int, struct zclient *, uint16_t, vrf_id_t);
- int (*vrf_delete) (int, struct zclient *, uint16_t, vrf_id_t);
int (*interface_add) (int, struct zclient *, uint16_t, vrf_id_t);
int (*interface_delete) (int, struct zclient *, uint16_t, vrf_id_t);
int (*interface_up) (int, struct zclient *, uint16_t, vrf_id_t);
@@ -195,8 +193,6 @@ extern int zclient_send_message(struct zclient *);
/* create header for command, length to be filled in by user later */
extern void zclient_create_header (struct stream *, uint16_t, vrf_id_t);
-extern struct vrf *zebra_vrf_add_read (struct stream *, vrf_id_t);
-extern struct vrf *zebra_vrf_state_read (struct stream *s, vrf_id_t);
extern struct interface *zebra_interface_add_read (struct stream *, vrf_id_t);
extern struct interface *zebra_interface_state_read (struct stream *s, vrf_id_t);
extern struct connected *zebra_interface_address_read (int, struct stream *, vrf_id_t);