From: Feng Lu Date: Thu, 16 Oct 2014 01:52:36 +0000 (+0800) Subject: *: add VRF ID in the API message header X-Git-Tag: frr-2.0-rc1~1211 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=7076bb2f522ea00266a221ed5d45c71658b668c9;p=matthieu%2Ffrr.git *: add VRF ID in the API message header The API messages are used by zebra to exchange the interfaces, addresses, routes and router-id information with its clients. To distinguish which VRF the information belongs to, a new field "VRF ID" is added in the message header. And hence the message version is increased to 3. * The new field "VRF ID" in the message header: Length (2 bytes) Marker (1 byte) Version (1 byte) VRF ID (2 bytes, newly added) Command (2 bytes) - Client side: - zclient_create_header() adds the VRF ID in the message header. - zclient_read() extracts and validates the VRF ID from the header, and passes the VRF ID to the callback functions registered to the API messages. - All relative functions are appended with a new parameter "vrf_id", including all the callback functions. - "vrf_id" is also added to "struct zapi_ipv4" and "struct zapi_ipv6". Clients need to correctly set the VRF ID when using the API functions zapi_ipv4_route() and zapi_ipv6_route(). - Till now all messages sent from a client have the default VRF ID "0" in the header. - The HELLO message is special, which is used as the heart-beat of a client, and has no relation with VRF. The VRF ID in the HELLO message header will always be 0 and ignored by zebra. - Zebra side: - zserv_create_header() adds the VRF ID in the message header. - zebra_client_read() extracts and validates the VRF ID from the header, and passes the VRF ID to the functions which process the received messages. - All relative functions are appended with a new parameter "vrf_id". * Suppress the messages in a VRF which a client does not care: Some clients may not care about the information in the VRF X, and zebra should not send the messages in the VRF X to those clients. Extra flags are used to indicate which VRF is registered by a client, and a new message ZEBRA_VRF_UNREGISTER is introduced to let a client can unregister a VRF when it does not need any information in that VRF. A client sends any message other than ZEBRA_VRF_UNREGISTER in a VRF will automatically register to that VRF. - lib/vrf: A new utility "VRF bit-map" is provided to manage the flags for VRFs, one bit per VRF ID. - Use vrf_bitmap_init()/vrf_bitmap_free() to initialize/free a bit-map; - Use vrf_bitmap_set()/vrf_bitmap_unset() to set/unset a flag in the given bit-map, corresponding to the given VRF ID; - Use vrf_bitmap_check() to test whether the flag, in the given bit-map and for the given VRF ID, is set. - Client side: - In "struct zclient", the following flags are changed from "u_char" to "vrf_bitmap_t": redist[ZEBRA_ROUTE_MAX] default_information These flags are extended for each VRF, and controlled by the clients themselves (or with the help of zclient_redistribute() and zclient_redistribute_default()). - Zebra side: - In "struct zserv", the following flags are changed from "u_char" to "vrf_bitmap_t": redist[ZEBRA_ROUTE_MAX] redist_default ifinfo ridinfo These flags are extended for each VRF, as the VRF registration flags. They are maintained on receiving a ZEBRA_XXX_ADD or ZEBRA_XXX_DELETE message. When sending an interface/address/route/router-id message in a VRF to a client, if the corresponding VRF registration flag is not set, this message will not be dropped by zebra. - A new function zread_vrf_unregister() is introduced to process the new command ZEBRA_VRF_UNREGISTER. All the VRF registration flags are cleared for the requested VRF. Those clients, who support only the default VRF, will never receive a message in a non-default VRF, thanks to the filter in zebra. * New callback for the event of successful connection to zebra: - zclient_start() is splitted, keeping only the code of connecting to zebra. - Now zclient_init()=>zclient_connect()=>zclient_start() operations are purely dealing with the connection to zbera. - Once zebra is successfully connected, at the end of zclient_start(), a new callback is used to inform the client about connection. - Till now, in the callback of connect-to-zebra event, all clients send messages to zebra to request the router-id/interface/routes information in the default VRF. Of corse in future the client can do anything it wants in this callback. For example, it may send requests for both default VRF and some non-default VRFs. Signed-off-by: Feng Lu Reviewed-by: Alain Ritoux Signed-off-by: Nicolas Dichtel Acked-by: Donald Sharp Conflicts: lib/zclient.h lib/zebra.h zebra/zserv.c zebra/zserv.h Conflicts: bgpd/bgp_nexthop.c bgpd/bgp_nht.c bgpd/bgp_zebra.c isisd/isis_zebra.c lib/zclient.c lib/zclient.h lib/zebra.h nhrpd/nhrp_interface.c nhrpd/nhrp_route.c nhrpd/nhrpd.h ospf6d/ospf6_zebra.c ospf6d/ospf6_zebra.h ospfd/ospf_vty.c ospfd/ospf_zebra.c pimd/pim_zebra.c pimd/pim_zlookup.c ripd/rip_zebra.c ripngd/ripng_zebra.c zebra/redistribute.c zebra/rt_netlink.c zebra/zebra_rnh.c zebra/zebra_rnh.h zebra/zserv.c zebra/zserv.h --- diff --git a/babeld/babel_interface.c b/babeld/babel_interface.c index c7c1527481..8dfaffd878 100644 --- a/babeld/babel_interface.c +++ b/babeld/babel_interface.c @@ -82,7 +82,7 @@ static struct cmd_node babel_interface_node = /* babeld's interface node. */ int -babel_interface_up (int cmd, struct zclient *client, zebra_size_t length) +babel_interface_up (int cmd, struct zclient *client, zebra_size_t length, vrf_id_t vrf_id) { struct stream *s = NULL; struct interface *ifp = NULL; @@ -90,7 +90,7 @@ babel_interface_up (int cmd, struct zclient *client, zebra_size_t length) debugf(BABEL_DEBUG_IF, "receive a 'interface up'"); s = zclient->ibuf; - ifp = zebra_interface_state_read(s); /* it updates iflist */ + ifp = zebra_interface_state_read(s, vrf_id); /* it updates iflist */ if (ifp == NULL) { return 0; @@ -101,7 +101,7 @@ babel_interface_up (int cmd, struct zclient *client, zebra_size_t length) } int -babel_interface_down (int cmd, struct zclient *client, zebra_size_t length) +babel_interface_down (int cmd, struct zclient *client, zebra_size_t length, vrf_id_t vrf_id) { struct stream *s = NULL; struct interface *ifp = NULL; @@ -109,7 +109,7 @@ babel_interface_down (int cmd, struct zclient *client, zebra_size_t length) debugf(BABEL_DEBUG_IF, "receive a 'interface down'"); s = zclient->ibuf; - ifp = zebra_interface_state_read(s); /* it updates iflist */ + ifp = zebra_interface_state_read(s, vrf_id); /* it updates iflist */ if (ifp == NULL) { return 0; @@ -120,14 +120,14 @@ babel_interface_down (int cmd, struct zclient *client, zebra_size_t length) } int -babel_interface_add (int cmd, struct zclient *client, zebra_size_t length) +babel_interface_add (int cmd, struct zclient *client, zebra_size_t length, vrf_id_t vrf_id) { struct interface *ifp = NULL; debugf(BABEL_DEBUG_IF, "receive a 'interface add'"); /* read and add the interface in the iflist. */ - ifp = zebra_interface_add_read (zclient->ibuf); + ifp = zebra_interface_add_read (zclient->ibuf, vrf_id); if (ifp == NULL) { return 0; @@ -138,7 +138,7 @@ babel_interface_add (int cmd, struct zclient *client, zebra_size_t length) } int -babel_interface_delete (int cmd, struct zclient *client, zebra_size_t length) +babel_interface_delete (int cmd, struct zclient *client, zebra_size_t length, vrf_id_t vrf_id) { struct interface *ifp; struct stream *s; @@ -146,7 +146,7 @@ babel_interface_delete (int cmd, struct zclient *client, zebra_size_t length) debugf(BABEL_DEBUG_IF, "receive a 'interface delete'"); s = zclient->ibuf; - ifp = zebra_interface_state_read(s); /* it updates iflist */ + ifp = zebra_interface_state_read(s, vrf_id); /* it updates iflist */ if (ifp == NULL) return 0; @@ -163,7 +163,7 @@ babel_interface_delete (int cmd, struct zclient *client, zebra_size_t length) int babel_interface_address_add (int cmd, struct zclient *client, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { babel_interface_nfo *babel_ifp; struct connected *ifc; @@ -172,7 +172,7 @@ babel_interface_address_add (int cmd, struct zclient *client, debugf(BABEL_DEBUG_IF, "receive a 'interface address add'"); ifc = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, - zclient->ibuf); + zclient->ibuf, vrf_id); if (ifc == NULL) return 0; @@ -200,7 +200,7 @@ babel_interface_address_add (int cmd, struct zclient *client, int babel_interface_address_delete (int cmd, struct zclient *client, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { babel_interface_nfo *babel_ifp; struct connected *ifc; @@ -209,7 +209,7 @@ babel_interface_address_delete (int cmd, struct zclient *client, debugf(BABEL_DEBUG_IF, "receive a 'interface address add'"); ifc = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, - zclient->ibuf); + zclient->ibuf, vrf_id); if (ifc == NULL) return 0; diff --git a/babeld/babel_interface.h b/babeld/babel_interface.h index 94fd8e5d75..e0d53d6ef4 100644 --- a/babeld/babel_interface.h +++ b/babeld/babel_interface.h @@ -133,12 +133,12 @@ struct buffered_update { void babel_if_init(void); /* Callback functions for zebra client */ -int babel_interface_up (int, struct zclient *, zebra_size_t); -int babel_interface_down (int, struct zclient *, zebra_size_t); -int babel_interface_add (int, struct zclient *, zebra_size_t); -int babel_interface_delete (int, struct zclient *, zebra_size_t); -int babel_interface_address_add (int, struct zclient *, zebra_size_t); -int babel_interface_address_delete (int, struct zclient *, zebra_size_t); +int babel_interface_up (int, struct zclient *, zebra_size_t, vrf_id_t); +int babel_interface_down (int, struct zclient *, zebra_size_t, vrf_id_t); +int babel_interface_add (int, struct zclient *, zebra_size_t, vrf_id_t); +int babel_interface_delete (int, struct zclient *, zebra_size_t, vrf_id_t); +int babel_interface_address_add (int, struct zclient *, zebra_size_t, vrf_id_t); +int babel_interface_address_delete (int, struct zclient *, zebra_size_t, vrf_id_t); unsigned jitter(babel_interface_nfo *, int); unsigned update_jitter(babel_interface_nfo *babel_ifp, int urgent); diff --git a/babeld/babel_zebra.c b/babeld/babel_zebra.c index e107cca100..5ae35ec5cd 100644 --- a/babeld/babel_zebra.c +++ b/babeld/babel_zebra.c @@ -80,7 +80,7 @@ struct cmd_node zebra_node = /* Zebra route add and delete treatment (ipv6). */ static int babel_zebra_read_ipv6 (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct stream *s; struct zapi_ipv6 api; @@ -133,7 +133,7 @@ babel_zebra_read_ipv6 (int command, struct zclient *zclient, static int babel_zebra_read_ipv4 (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct stream *s; struct zapi_ipv4 api; @@ -209,7 +209,7 @@ DEFUN (babel_redistribute_type, return CMD_WARNING; } - zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, afi, type, 0); + zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, afi, type, 0, VRF_DEFAULT); return CMD_SUCCESS; } @@ -238,7 +238,7 @@ DEFUN (no_babel_redistribute_type, return CMD_WARNING; } - zclient_redistribute (ZEBRA_REDISTRIBUTE_DELETE, zclient, afi, type, 0); + zclient_redistribute (ZEBRA_REDISTRIBUTE_DELETE, zclient, afi, type, 0, VRF_DEFAULT); /* perhaps should we remove xroutes having the same type... */ return CMD_SUCCESS; } @@ -371,8 +371,8 @@ zebra_config_write (struct vty *vty) vty_out (vty, "no router zebra%s", VTY_NEWLINE); return 1; } - else if (! (zclient->redist[AFI_IP][ZEBRA_ROUTE_BABEL].enabled || - zclient->redist[AFI_IP6][ZEBRA_ROUTE_BABEL].enabled)) + else if (! (vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_BABEL], VRF_DEFAULT) || + vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_BABEL], VRF_DEFAULT))) { vty_out (vty, "router zebra%s", VTY_NEWLINE); vty_out (vty, " no redistribute babel%s", VTY_NEWLINE); diff --git a/babeld/babeld.c b/babeld/babeld.c index fff0f61313..9e0018ad25 100644 --- a/babeld/babeld.c +++ b/babeld/babeld.c @@ -60,6 +60,7 @@ THE SOFTWARE. #include "resend.h" #include "babel_filter.h" #include "babel_zebra.h" +#include "vrf.h" static int babel_init_routing_process(struct thread *thread); @@ -114,7 +115,7 @@ babel_config_write (struct vty *vty) for (afi = AFI_IP; afi < AFI_MAX; afi++) for (i = 0; i < ZEBRA_ROUTE_MAX; i++) if (i != zclient->redist_default && - zclient->redist[afi][i].enabled) + vrf_bitmap_check (zclient->redist[afi][i], VRF_DEFAULT) ) { vty_out (vty, " redistribute %s%s", zebra_route_string (i), VTY_NEWLINE); lines++; diff --git a/bgpd/bgp_bfd.c b/bgpd/bgp_bfd.c index 5505ced926..011ccef941 100644 --- a/bgpd/bgp_bfd.c +++ b/bgpd/bgp_bfd.c @@ -96,13 +96,13 @@ bgp_bfd_peer_sendmsg (struct peer *peer, int command) &peer->su.sin.sin_addr, (peer->su_local) ? &peer->su_local->sin.sin_addr : NULL, (peer->nexthop.ifp) ? peer->nexthop.ifp->name : NULL, - peer->ttl, bgp_bfd_is_peer_multihop(peer), command, 1); + peer->ttl, bgp_bfd_is_peer_multihop(peer), command, 1, VRF_DEFAULT); else if (peer->su.sa.sa_family == AF_INET6) bfd_peer_sendmsg (zclient, bfd_info, AF_INET6, &peer->su.sin6.sin6_addr, (peer->su_local) ? &peer->su_local->sin6.sin6_addr : NULL, (peer->nexthop.ifp) ? peer->nexthop.ifp->name : NULL, - peer->ttl, bgp_bfd_is_peer_multihop(peer), command, 1); + peer->ttl, bgp_bfd_is_peer_multihop(peer), command, 1, VRF_DEFAULT); } /* @@ -171,7 +171,8 @@ bgp_bfd_update_peer (struct peer *peer) * to zebra */ static int -bgp_bfd_dest_replay (int command, struct zclient *client, zebra_size_t length) +bgp_bfd_dest_replay (int command, struct zclient *client, zebra_size_t length, + vrf_id_t vrf_id) { struct listnode *mnode, *node, *nnode; struct bgp *bgp; @@ -224,7 +225,7 @@ bgp_bfd_peer_status_update (struct peer *peer, int status) */ static int bgp_bfd_dest_update (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct interface *ifp; struct prefix dp; diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index 4b3d14af58..dafabe22ca 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -351,7 +351,6 @@ bgp_nexthop_self (struct attr *attr) return 0; } - int bgp_multiaccess_check_v4 (struct in_addr nexthop, struct peer *peer) { diff --git a/bgpd/bgp_nht.c b/bgpd/bgp_nht.c index 70a4309628..1824771e3a 100644 --- a/bgpd/bgp_nht.c +++ b/bgpd/bgp_nht.c @@ -30,6 +30,7 @@ #include "log.h" #include "memory.h" #include "nexthop.h" +#include "vrf.h" #include "bgpd/bgpd.h" #include "bgpd/bgp_table.h" @@ -292,7 +293,7 @@ bgp_delete_connected_nexthop (afi_t afi, struct peer *peer) } void -bgp_parse_nexthop_update (int command) +bgp_parse_nexthop_update (int command, vrf_id_t vrf_id) { struct stream *s; struct bgp_node *rn = NULL; @@ -526,15 +527,18 @@ sendmsg_zebra_rnh (struct bgp_nexthop_cache *bnc, int command) /* Check socket. */ if (!zclient || zclient->sock < 0) { - zlog_debug("%s: Can't send NH register, Zebra client not established", + /* Pending: hiding this error now, because bgp_nht_register_all() is implemented. + which tries it after zclient_connect() + zlog_debug("%s: Can't send NH register, Zebra client not established", __FUNCTION__); + */ return; } p = &(bnc->node->p); s = zclient->obuf; stream_reset (s); - zclient_create_header (s, command); + zclient_create_header (s, command, VRF_DEFAULT); if (CHECK_FLAG(bnc->flags, BGP_NEXTHOP_CONNECTED) || CHECK_FLAG(bnc->flags, BGP_STATIC_ROUTE_EXACT_MATCH)) stream_putc(s, 1); @@ -682,6 +686,40 @@ evaluate_paths (struct bgp_nexthop_cache *bnc) RESET_FLAG(bnc->change_flags); } +void +bgp_nht_register_all (void) +{ + struct bgp_node *rn; + struct bgp_nexthop_cache *bnc; + + for (rn = bgp_table_top (bgp_nexthop_cache_table[AFI_IP]); rn; rn = bgp_route_next (rn)) + if ((bnc = rn->info) != NULL && + !CHECK_FLAG(bnc->flags, BGP_NEXTHOP_REGISTERED)) + { + register_zebra_rnh(bnc, 0); + } + for (rn = bgp_table_top (bgp_nexthop_cache_table[AFI_IP6]); rn; rn = bgp_route_next (rn)) + if ((bnc = rn->info) != NULL && + !CHECK_FLAG(bnc->flags, BGP_NEXTHOP_REGISTERED)) + { + register_zebra_rnh(bnc, 0); + } + + for (rn = bgp_table_top (bgp_import_check_table[AFI_IP]); rn; rn = bgp_route_next (rn)) + if ((bnc = rn->info) != NULL && + !CHECK_FLAG(bnc->flags, BGP_NEXTHOP_REGISTERED)) + { + register_zebra_rnh(bnc, 1); + } + for (rn = bgp_table_top (bgp_import_check_table[AFI_IP6]); rn; rn = bgp_route_next (rn)) + if ((bnc = rn->info) != NULL && + !CHECK_FLAG(bnc->flags, BGP_NEXTHOP_REGISTERED)) + { + register_zebra_rnh(bnc, 1); + } + +} + /** * path_nh_map - make or break path-to-nexthop association. * ARGUMENTS: diff --git a/bgpd/bgp_nht.h b/bgpd/bgp_nht.h index 952268789f..aeb0e407f4 100644 --- a/bgpd/bgp_nht.h +++ b/bgpd/bgp_nht.h @@ -22,10 +22,12 @@ #ifndef _BGP_NHT_H #define _BGP_NHT_H +extern void bgp_nht_register_all (void); + /** * bgp_parse_nexthop_update() - parse a nexthop update message from Zebra. */ -extern void bgp_parse_nexthop_update(int command); +extern void bgp_parse_nexthop_update(int command, vrf_id_t vrf_id); /** * bgp_find_nexthop() - lookup the nexthop cache table for the bnc object diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 501af234a2..410bc8564b 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -92,7 +92,8 @@ do { \ /* Router-id update message from zebra. */ static int -bgp_router_id_update (int command, struct zclient *zclient, zebra_size_t length) +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; @@ -121,17 +122,17 @@ bgp_router_id_update (int command, struct zclient *zclient, zebra_size_t length) /* Nexthop update message from zebra. */ static int bgp_read_nexthop_update (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { - bgp_parse_nexthop_update(command); + bgp_parse_nexthop_update(command, vrf_id); return 0; } static int bgp_read_import_check_update(int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { - bgp_parse_nexthop_update(command); + bgp_parse_nexthop_update(command, vrf_id); return 0; } @@ -212,11 +213,12 @@ bgp_nbr_connected_delete (struct nbr_connected *ifc, int del) /* Inteface addition message from zebra. */ static int -bgp_interface_add (int command, struct zclient *zclient, zebra_size_t length) +bgp_interface_add (int command, struct zclient *zclient, zebra_size_t length, + vrf_id_t vrf_id) { struct interface *ifp; - ifp = zebra_interface_add_read (zclient->ibuf); + ifp = zebra_interface_add_read (zclient->ibuf, vrf_id); if (BGP_DEBUG (zebra, ZEBRA) && ifp) zlog_debug("Zebra rcvd: interface add %s", ifp->name); @@ -226,13 +228,13 @@ bgp_interface_add (int command, struct zclient *zclient, zebra_size_t length) static int bgp_interface_delete (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct stream *s; struct interface *ifp; s = zclient->ibuf; - ifp = zebra_interface_state_read (s); + ifp = zebra_interface_state_read (s, vrf_id); ifp->ifindex = IFINDEX_INTERNAL; if (BGP_DEBUG (zebra, ZEBRA)) @@ -242,7 +244,8 @@ bgp_interface_delete (int command, struct zclient *zclient, } static int -bgp_interface_up (int command, struct zclient *zclient, zebra_size_t length) +bgp_interface_up (int command, struct zclient *zclient, zebra_size_t length, + vrf_id_t vrf_id) { struct stream *s; struct interface *ifp; @@ -251,7 +254,7 @@ bgp_interface_up (int command, struct zclient *zclient, zebra_size_t length) struct listnode *node, *nnode; s = zclient->ibuf; - ifp = zebra_interface_state_read (s); + ifp = zebra_interface_state_read (s, vrf_id); if (! ifp) return 0; @@ -269,7 +272,8 @@ bgp_interface_up (int command, struct zclient *zclient, zebra_size_t length) } static int -bgp_interface_down (int command, struct zclient *zclient, zebra_size_t length) +bgp_interface_down (int command, struct zclient *zclient, zebra_size_t length, + vrf_id_t vrf_id) { struct stream *s; struct interface *ifp; @@ -278,7 +282,7 @@ bgp_interface_down (int command, struct zclient *zclient, zebra_size_t length) struct listnode *node, *nnode; s = zclient->ibuf; - ifp = zebra_interface_state_read (s); + ifp = zebra_interface_state_read (s, vrf_id); if (! ifp) return 0; @@ -318,11 +322,11 @@ bgp_interface_down (int command, struct zclient *zclient, zebra_size_t length) static int bgp_interface_address_add (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct connected *ifc; - ifc = zebra_interface_address_read (command, zclient->ibuf); + ifc = zebra_interface_address_read (command, zclient->ibuf, vrf_id); if (ifc == NULL) return 0; @@ -352,11 +356,11 @@ bgp_interface_address_add (int command, struct zclient *zclient, static int bgp_interface_address_delete (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct connected *ifc; - ifc = zebra_interface_address_read (command, zclient->ibuf); + ifc = zebra_interface_address_read (command, zclient->ibuf, vrf_id); if (ifc == NULL) return 0; @@ -379,11 +383,11 @@ bgp_interface_address_delete (int command, struct zclient *zclient, static int bgp_interface_nbr_address_add (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct nbr_connected *ifc = NULL; - ifc = zebra_interface_nbr_address_read (command, zclient->ibuf); + ifc = zebra_interface_nbr_address_read (command, zclient->ibuf, vrf_id); if (ifc == NULL) return 0; @@ -404,11 +408,11 @@ bgp_interface_nbr_address_add (int command, struct zclient *zclient, static int bgp_interface_nbr_address_delete (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct nbr_connected *ifc = NULL; - ifc = zebra_interface_nbr_address_read (command, zclient->ibuf); + ifc = zebra_interface_nbr_address_read (command, zclient->ibuf, vrf_id); if (ifc == NULL) return 0; @@ -431,7 +435,8 @@ bgp_interface_nbr_address_delete (int command, struct zclient *zclient, /* Zebra route add and delete treatment. */ static int -zebra_read_ipv4 (int command, struct zclient *zclient, zebra_size_t length) +zebra_read_ipv4 (int command, struct zclient *zclient, zebra_size_t length, + vrf_id_t vrf_id) { struct stream *s; struct zapi_ipv4 api; @@ -538,7 +543,8 @@ zebra_read_ipv4 (int command, struct zclient *zclient, zebra_size_t length) #ifdef HAVE_IPV6 /* Zebra route add and delete treatment. */ static int -zebra_read_ipv6 (int command, struct zclient *zclient, zebra_size_t length) +zebra_read_ipv6 (int command, struct zclient *zclient, zebra_size_t length, + vrf_id_t vrf_id) { struct stream *s; struct zapi_ipv6 api; @@ -1026,8 +1032,10 @@ bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp, if (zclient->sock < 0) return; - if ((p->family == AF_INET && !zclient->redist[AFI_IP][ZEBRA_ROUTE_BGP].enabled) - || (p->family == AF_INET6 && !zclient->redist[AFI_IP6][ZEBRA_ROUTE_BGP].enabled)) + if ((p->family == AF_INET && + !vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_BGP], VRF_DEFAULT)) + || (p->family == AF_INET6 && + !vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_BGP], VRF_DEFAULT))) return; if (bgp->main_zebra_update_hold) @@ -1140,6 +1148,7 @@ bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp, valid_nh_count++; } + api.vrf_id = VRF_DEFAULT; api.flags = flags; api.type = ZEBRA_ROUTE_BGP; api.instance = 0; @@ -1322,6 +1331,7 @@ bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp, } /* Make Zebra API structure. */ + api.vrf_id = VRF_DEFAULT; api.flags = flags; api.type = ZEBRA_ROUTE_BGP; api.instance = 0; @@ -1424,8 +1434,10 @@ bgp_zebra_withdraw (struct prefix *p, struct bgp_info *info, safi_t safi) if (zclient->sock < 0) return; - if ((p->family == AF_INET && !zclient->redist[AFI_IP][ZEBRA_ROUTE_BGP].enabled) - || (p->family == AF_INET6 && !zclient->redist[AFI_IP6][ZEBRA_ROUTE_BGP].enabled)) + if ((p->family == AF_INET && + !vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_BGP], VRF_DEFAULT)) + || (p->family == AF_INET6 && + !vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_BGP], VRF_DEFAULT))) return; peer = info->peer; @@ -1447,6 +1459,7 @@ bgp_zebra_withdraw (struct prefix *p, struct bgp_info *info, safi_t safi) { struct zapi_ipv4 api; + api.vrf_id = VRF_DEFAULT; api.flags = flags; api.type = ZEBRA_ROUTE_BGP; @@ -1485,6 +1498,7 @@ bgp_zebra_withdraw (struct prefix *p, struct bgp_info *info, safi_t safi) assert (info->attr->extra); + api.vrf_id = VRF_DEFAULT; api.flags = flags; api.type = ZEBRA_ROUTE_BGP; api.instance = 0; @@ -1580,10 +1594,20 @@ bgp_redistribute_set (afi_t afi, int type, u_short instance) { /* Return if already redistribute flag is set. */ - if (redist_check_instance(&zclient->redist[afi][type], instance)) - return CMD_WARNING; + if (instance) + { + if (redist_check_instance(&zclient->mi_redist[afi][type], instance)) + return CMD_WARNING; - redist_add_instance(&zclient->redist[afi][type], instance); + redist_add_instance(&zclient->mi_redist[afi][type], instance); + } + else + { + if (vrf_bitmap_check (zclient->redist[afi][type], VRF_DEFAULT)) + return CMD_WARNING; + + vrf_bitmap_set (zclient->redist[afi][type], VRF_DEFAULT); + } /* Return if zebra connection is not established. */ if (zclient->sock < 0) @@ -1594,7 +1618,8 @@ bgp_redistribute_set (afi_t afi, int type, u_short instance) zebra_route_string(type), instance); /* Send distribute add message to zebra. */ - zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, afi, type, instance); + zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, afi, type, + instance, VRF_DEFAULT); return CMD_SUCCESS; } @@ -1611,8 +1636,10 @@ bgp_redistribute_resend (struct bgp *bgp, afi_t afi, int type, u_short instance) zebra_route_string(type), instance); /* Send distribute add message to zebra. */ - zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, afi, type, instance); - zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, afi, type, instance); + zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, afi, type, + instance, VRF_DEFAULT); + zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, afi, type, + instance, VRF_DEFAULT); return 0; } @@ -1685,9 +1712,18 @@ bgp_redistribute_unset (struct bgp *bgp, afi_t afi, int type, u_short instance) bgp_redist_del(bgp, afi, type, instance); /* Return if zebra connection is disabled. */ - if (!redist_check_instance(&zclient->redist[afi][type], instance)) - return CMD_WARNING; - redist_del_instance(&zclient->redist[afi][type], instance); + if (instance) + { + if (!redist_check_instance(&zclient->mi_redist[afi][type], instance)) + return CMD_WARNING; + redist_del_instance(&zclient->mi_redist[afi][type], instance); + } + else + { + if (! vrf_bitmap_check (zclient->redist[afi][type], VRF_DEFAULT)) + return CMD_WARNING; + vrf_bitmap_unset (zclient->redist[afi][type], VRF_DEFAULT); + } if (zclient->sock >= 0) { @@ -1695,7 +1731,8 @@ bgp_redistribute_unset (struct bgp *bgp, afi_t afi, int type, u_short instance) if (BGP_DEBUG (zebra, ZEBRA)) zlog_debug("Zebra send: redistribute delete afi %d %s %d", afi, zebra_route_string(type), instance); - zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, afi, type, instance); + zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, afi, type, instance, + VRF_DEFAULT); } /* Withdraw redistributed routes from current BGP's routing table. */ @@ -1710,12 +1747,21 @@ bgp_zclient_reset (void) zclient_reset (zclient); } +static void +bgp_zebra_connected (struct zclient *zclient) +{ + zclient_send_requests (zclient, VRF_DEFAULT); + + bgp_nht_register_all(); +} + void bgp_zebra_init (struct thread_master *master) { /* Set default values. */ zclient = zclient_new (master); zclient_init (zclient, ZEBRA_ROUTE_BGP, 0); + zclient->zebra_connected = bgp_zebra_connected; zclient->router_id_update = bgp_router_id_update; zclient->interface_add = bgp_interface_add; zclient->interface_delete = bgp_interface_delete; diff --git a/isisd/isis_zebra.c b/isisd/isis_zebra.c index a29ad68172..27c2c92d08 100644 --- a/isisd/isis_zebra.c +++ b/isisd/isis_zebra.c @@ -32,6 +32,7 @@ #include "zclient.h" #include "stream.h" #include "linklist.h" +#include "vrf.h" #include "isisd/dict.h" #include "isisd/isis_constants.h" @@ -52,7 +53,7 @@ struct zclient *zclient = NULL; /* Router-id update message from zebra. */ static int isis_router_id_update_zebra (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct isis_area *area; struct listnode *node; @@ -71,11 +72,12 @@ isis_router_id_update_zebra (int command, struct zclient *zclient, } static int -isis_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length) +isis_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length, + vrf_id_t vrf_id) { struct interface *ifp; - ifp = zebra_interface_add_read (zclient->ibuf); + ifp = zebra_interface_add_read (zclient->ibuf, vrf_id); if (isis->debugs & DEBUG_ZEBRA) zlog_debug ("Zebra I/F add: %s index %d flags %ld metric %d mtu %d", @@ -88,13 +90,14 @@ isis_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length) } static int -isis_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length) +isis_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length, + vrf_id_t vrf_id) { struct interface *ifp; struct stream *s; s = zclient->ibuf; - ifp = zebra_interface_state_read (s); + ifp = zebra_interface_state_read (s, vrf_id); if (!ifp) return 0; @@ -120,11 +123,11 @@ isis_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length) static int isis_zebra_if_state_up (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct interface *ifp; - ifp = zebra_interface_state_read (zclient->ibuf); + ifp = zebra_interface_state_read (zclient->ibuf, vrf_id); if (ifp == NULL) return 0; @@ -136,12 +139,12 @@ isis_zebra_if_state_up (int command, struct zclient *zclient, static int isis_zebra_if_state_down (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct interface *ifp; struct isis_circuit *circuit; - ifp = zebra_interface_state_read (zclient->ibuf); + ifp = zebra_interface_state_read (zclient->ibuf, vrf_id); if (ifp == NULL) return 0; @@ -156,14 +159,14 @@ isis_zebra_if_state_down (int command, struct zclient *zclient, static int isis_zebra_if_address_add (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct connected *c; struct prefix *p; char buf[BUFSIZ]; c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, - zclient->ibuf); + zclient->ibuf, vrf_id); if (c == NULL) return 0; @@ -187,7 +190,7 @@ isis_zebra_if_address_add (int command, struct zclient *zclient, static int isis_zebra_if_address_del (int command, struct zclient *client, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct connected *c; struct interface *ifp; @@ -197,7 +200,7 @@ isis_zebra_if_address_del (int command, struct zclient *client, #endif /* EXTREME_DEBUG */ c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE, - zclient->ibuf); + zclient->ibuf, vrf_id); if (c == NULL) return 0; @@ -236,7 +239,7 @@ isis_zebra_route_add_ipv4 (struct prefix *prefix, if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED)) return; - if (zclient->redist[AFI_IP][ZEBRA_ROUTE_ISIS].enabled) + if (vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_ISIS], VRF_DEFAULT)) { message = 0; flags = 0; @@ -249,7 +252,7 @@ isis_zebra_route_add_ipv4 (struct prefix *prefix, stream = zclient->obuf; stream_reset (stream); - zclient_create_header (stream, ZEBRA_IPV4_ROUTE_ADD); + zclient_create_header (stream, ZEBRA_IPV4_ROUTE_ADD, VRF_DEFAULT); /* type */ stream_putc (stream, ZEBRA_ROUTE_ISIS); /* instance */ @@ -303,8 +306,9 @@ isis_zebra_route_del_ipv4 (struct prefix *prefix, struct zapi_ipv4 api; struct prefix_ipv4 prefix4; - if (zclient->redist[AFI_IP][ZEBRA_ROUTE_ISIS].enabled) + if (vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_ISIS], VRF_DEFAULT)) { + api.vrf_id = VRF_DEFAULT; api.type = ZEBRA_ROUTE_ISIS; api.instance = 0; api.flags = 0; @@ -336,6 +340,7 @@ isis_zebra_route_add_ipv6 (struct prefix *prefix, if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED)) return; + api.vrf_id = VRF_DEFAULT; api.type = ZEBRA_ROUTE_ISIS; api.instance = 0; api.flags = 0; @@ -422,6 +427,7 @@ isis_zebra_route_del_ipv6 (struct prefix *prefix, if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED)) return; + api.vrf_id = VRF_DEFAULT; api.type = ZEBRA_ROUTE_ISIS; api.instance = 0; api.flags = 0; @@ -493,8 +499,8 @@ isis_zebra_route_update (struct prefix *prefix, if (zclient->sock < 0) return; - if ((prefix->family == AF_INET && !zclient->redist[AFI_IP][ZEBRA_ROUTE_ISIS].enabled) || - (prefix->family == AF_INET6 && !zclient->redist[AFI_IP6][ZEBRA_ROUTE_ISIS].enabled)) + if ((prefix->family == AF_INET && !vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_ISIS], VRF_DEFAULT)) || + (prefix->family == AF_INET6 && !vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_ISIS], VRF_DEFAULT))) return; if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ACTIVE)) @@ -520,7 +526,7 @@ isis_zebra_route_update (struct prefix *prefix, static int isis_zebra_read_ipv4 (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct stream *stream; struct zapi_ipv4 api; @@ -567,15 +573,17 @@ isis_zebra_read_ipv4 (int command, struct zclient *zclient, #ifdef HAVE_IPV6 static int isis_zebra_read_ipv6 (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { return 0; } #endif #define ISIS_TYPE_IS_REDISTRIBUTED(T) \ -T == ZEBRA_ROUTE_MAX ? zclient->default_information : \ -(zclient->redist[AFI_IP][type].enabled || client->redist[AFI_IP6][type].enabled) +T == ZEBRA_ROUTE_MAX ? \ + vrf_bitmap_check (zclient->default_information, VRF_DEFAULT) : \ + (vrf_bitmap_check (zclient->redist[AFI_IP][type], VRF_DEFAULT) || \ + vrf_bitmap_check (zclient->redist[AFI_IP6][type], VRF_DEFAULT) int isis_distribute_list_update (int routetype) @@ -592,11 +600,18 @@ isis_redistribute_default_set (int routetype, int metric_type, } #endif /* 0 */ +static void +isis_zebra_connected (struct zclient *zclient) +{ + zclient_send_requests (zclient, VRF_DEFAULT); +} + void isis_zebra_init (struct thread_master *master) { - zclient = zclient_new(master); + zclient = zclient_new (master); zclient_init (zclient, ZEBRA_ROUTE_ISIS, 0); + zclient->zebra_connected = isis_zebra_connected; zclient->router_id_update = isis_router_id_update_zebra; zclient->interface_add = isis_zebra_if_add; zclient->interface_delete = isis_zebra_if_del; diff --git a/lib/bfd.c b/lib/bfd.c index 613c71487e..530086b1bd 100644 --- a/lib/bfd.c +++ b/lib/bfd.c @@ -119,7 +119,8 @@ bfd_set_param (struct bfd_info **bfd_info, u_int32_t min_rx, u_int32_t min_tx, void bfd_peer_sendmsg (struct zclient *zclient, struct bfd_info *bfd_info, int family, void *dst_ip, void *src_ip, char *if_name, - int ttl, int multihop, int command, int set_flag) + int ttl, int multihop, int command, int set_flag, + vrf_id_t vrf_id) { struct stream *s; int ret; @@ -135,7 +136,7 @@ bfd_peer_sendmsg (struct zclient *zclient, struct bfd_info *bfd_info, s = zclient->obuf; stream_reset (s); - zclient_create_header (s, command); + zclient_create_header (s, command, vrf_id); stream_putw(s, family); switch (family) diff --git a/lib/bfd.h b/lib/bfd.h index 0b5743b910..3cae1a5219 100644 --- a/lib/bfd.h +++ b/lib/bfd.h @@ -74,7 +74,8 @@ bfd_set_param (struct bfd_info **bfd_info, u_int32_t min_rx, u_int32_t min_tx, extern void bfd_peer_sendmsg (struct zclient *zclient, struct bfd_info *bfd_info, int family, void *dst_ip, void *src_ip, char *if_name, - int ttl, int multihop, int command, int set_flag); + int ttl, int multihop, int command, int set_flag, + vrf_id_t vrf_id); extern const char * bfd_get_command_dbg_str(int command); diff --git a/lib/memtypes.c b/lib/memtypes.c index 828820f309..a249423d7c 100644 --- a/lib/memtypes.c +++ b/lib/memtypes.c @@ -75,6 +75,7 @@ struct memory_list memory_list_lib[] = { MTYPE_BFD_INFO, "BFD info" }, { MTYPE_VRF, "VRF" }, { MTYPE_VRF_NAME, "VRF name" }, + { MTYPE_VRF_BITMAP, "VRF bit-map" }, { -1, NULL }, }; diff --git a/lib/vrf.c b/lib/vrf.c index d11a98264c..683026e5c0 100644 --- a/lib/vrf.c +++ b/lib/vrf.c @@ -336,6 +336,99 @@ vrf_iflist_get (vrf_id_t vrf_id) return vrf->iflist; } +/* + * VRF bit-map + */ + +#define VRF_BITMAP_NUM_OF_GROUPS 8 +#define VRF_BITMAP_NUM_OF_BITS_IN_GROUP \ + (UINT16_MAX / VRF_BITMAP_NUM_OF_GROUPS) +#define VRF_BITMAP_NUM_OF_BYTES_IN_GROUP \ + (VRF_BITMAP_NUM_OF_BITS_IN_GROUP / CHAR_BIT + 1) /* +1 for ensure */ + +#define VRF_BITMAP_GROUP(_id) \ + ((_id) / VRF_BITMAP_NUM_OF_BITS_IN_GROUP) +#define VRF_BITMAP_BIT_OFFSET(_id) \ + ((_id) % VRF_BITMAP_NUM_OF_BITS_IN_GROUP) + +#define VRF_BITMAP_INDEX_IN_GROUP(_bit_offset) \ + ((_bit_offset) / CHAR_BIT) +#define VRF_BITMAP_FLAG(_bit_offset) \ + (((u_char)1) << ((_bit_offset) % CHAR_BIT)) + +struct vrf_bitmap +{ + u_char *groups[VRF_BITMAP_NUM_OF_GROUPS]; +}; + +vrf_bitmap_t +vrf_bitmap_init (void) +{ + return (vrf_bitmap_t) XCALLOC (MTYPE_VRF_BITMAP, sizeof (struct vrf_bitmap)); +} + +void +vrf_bitmap_free (vrf_bitmap_t bmap) +{ + struct vrf_bitmap *bm = (struct vrf_bitmap *) bmap; + int i; + + if (bmap == VRF_BITMAP_NULL) + return; + + for (i = 0; i < VRF_BITMAP_NUM_OF_GROUPS; i++) + if (bm->groups[i]) + XFREE (MTYPE_VRF_BITMAP, bm->groups[i]); + + XFREE (MTYPE_VRF_BITMAP, bm); +} + +void +vrf_bitmap_set (vrf_bitmap_t bmap, vrf_id_t vrf_id) +{ + struct vrf_bitmap *bm = (struct vrf_bitmap *) bmap; + u_char group = VRF_BITMAP_GROUP (vrf_id); + u_char offset = VRF_BITMAP_BIT_OFFSET (vrf_id); + + if (bmap == VRF_BITMAP_NULL) + return; + + if (bm->groups[group] == NULL) + bm->groups[group] = XCALLOC (MTYPE_VRF_BITMAP, + VRF_BITMAP_NUM_OF_BYTES_IN_GROUP); + + SET_FLAG (bm->groups[group][VRF_BITMAP_INDEX_IN_GROUP (offset)], + VRF_BITMAP_FLAG (offset)); +} + +void +vrf_bitmap_unset (vrf_bitmap_t bmap, vrf_id_t vrf_id) +{ + struct vrf_bitmap *bm = (struct vrf_bitmap *) bmap; + u_char group = VRF_BITMAP_GROUP (vrf_id); + u_char offset = VRF_BITMAP_BIT_OFFSET (vrf_id); + + if (bmap == VRF_BITMAP_NULL || bm->groups[group] == NULL) + return; + + UNSET_FLAG (bm->groups[group][VRF_BITMAP_INDEX_IN_GROUP (offset)], + VRF_BITMAP_FLAG (offset)); +} + +int +vrf_bitmap_check (vrf_bitmap_t bmap, vrf_id_t vrf_id) +{ + struct vrf_bitmap *bm = (struct vrf_bitmap *) bmap; + u_char group = VRF_BITMAP_GROUP (vrf_id); + u_char offset = VRF_BITMAP_BIT_OFFSET (vrf_id); + + if (bmap == VRF_BITMAP_NULL || bm->groups[group] == NULL) + return 0; + + return CHECK_FLAG (bm->groups[group][VRF_BITMAP_INDEX_IN_GROUP (offset)], + VRF_BITMAP_FLAG (offset)) ? 1 : 0; +} + /* Initialize VRF module. */ void vrf_init (void) diff --git a/lib/vrf.h b/lib/vrf.h index 653fabf905..8b29b8093e 100644 --- a/lib/vrf.h +++ b/lib/vrf.h @@ -109,6 +109,19 @@ extern struct list *vrf_iflist (vrf_id_t); /* Get the interface list of the specified VRF. Create one if not find. */ extern struct list *vrf_iflist_get (vrf_id_t); +/* + * VRF bit-map: maintaining flags, one bit per VRF ID + */ + +typedef void * vrf_bitmap_t; +#define VRF_BITMAP_NULL NULL + +extern vrf_bitmap_t vrf_bitmap_init (void); +extern void vrf_bitmap_free (vrf_bitmap_t); +extern void vrf_bitmap_set (vrf_bitmap_t, vrf_id_t); +extern void vrf_bitmap_unset (vrf_bitmap_t, vrf_id_t); +extern int vrf_bitmap_check (vrf_bitmap_t, vrf_id_t); + /* * VRF initializer/destructor */ diff --git a/lib/zclient.c b/lib/zclient.c index 623ca1583f..f1486f4ade 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -164,12 +164,12 @@ zclient_stop (struct zclient *zclient) void zclient_reset (struct zclient *zclient) { - int afi; + afi_t afi; zclient_stop (zclient); for (afi = AFI_IP; afi < AFI_MAX; afi++) - redist_del_instance (&zclient->redist[afi][zclient->redist_default], zclient->instance); + redist_del_instance (&zclient->mi_redist[afi][zclient->redist_default], zclient->instance); zclient_init (zclient, zclient->redist_default, zclient->instance); } @@ -322,18 +322,19 @@ zclient_send_message(struct zclient *zclient) } void -zclient_create_header (struct stream *s, uint16_t command) +zclient_create_header (struct stream *s, uint16_t command, vrf_id_t vrf_id) { /* length placeholder, caller can update */ stream_putw (s, ZEBRA_HEADER_SIZE); stream_putc (s, ZEBRA_HEADER_MARKER); stream_putc (s, ZSERV_VERSION); + stream_putw (s, vrf_id); stream_putw (s, command); } /* Send simple Zebra message. */ static int -zebra_message_send (struct zclient *zclient, int command) +zebra_message_send (struct zclient *zclient, int command, vrf_id_t vrf_id) { struct stream *s; @@ -342,7 +343,7 @@ zebra_message_send (struct zclient *zclient, int command) stream_reset (s); /* Send very simple command only Zebra message. */ - zclient_create_header (s, command); + zclient_create_header (s, command, vrf_id); return zclient_send_message(zclient); } @@ -357,7 +358,8 @@ zebra_hello_send (struct zclient *zclient) s = zclient->obuf; stream_reset (s); - zclient_create_header (s, ZEBRA_HELLO); + /* The VRF ID in the HELLO message is always 0. */ + zclient_create_header (s, ZEBRA_HELLO, VRF_DEFAULT); stream_putc (s, zclient->redist_default); stream_putw (s, zclient->instance); stream_putw_at (s, 0, stream_get_endp (s)); @@ -367,12 +369,71 @@ zebra_hello_send (struct zclient *zclient) return 0; } +/* Send requests to zebra daemon for the information in a VRF. */ +void +zclient_send_requests (struct zclient *zclient, vrf_id_t vrf_id) +{ + int i; + afi_t afi; + + /* zclient is disabled. */ + if (! zclient->enable) + return; + + /* If not connected to the zebra yet. */ + if (zclient->sock < 0) + return; + + if (zclient_debug) + zlog_debug ("%s: send messages for VRF %u", __func__, vrf_id); + + /* We need router-id information. */ + zebra_message_send (zclient, ZEBRA_ROUTER_ID_ADD, vrf_id); + + /* We need interface information. */ + zebra_message_send (zclient, ZEBRA_INTERFACE_ADD, vrf_id); + + /* Set unwanted redistribute route. */ + for (afi = AFI_IP; afi < AFI_MAX; afi++) + vrf_bitmap_set (zclient->redist[afi][zclient->redist_default], vrf_id); + + /* Flush all redistribute request. */ + if (vrf_id == VRF_DEFAULT) + for (afi = AFI_IP; afi < AFI_MAX; afi++) + for (i = 0; i < ZEBRA_ROUTE_MAX; i++) + if (zclient->mi_redist[afi][i].enabled) + { + struct listnode *node; + u_short *id; + + for (ALL_LIST_ELEMENTS_RO(zclient->mi_redist[afi][i].instances, node, id)) + if (!(i == zclient->redist_default && *id == zclient->instance)) + zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, afi, i, + *id, VRF_DEFAULT); + } + + /* Flush all redistribute request. */ + for (afi = AFI_IP; afi < AFI_MAX; afi++) + for (i = 0; i < ZEBRA_ROUTE_MAX; i++) + if (i != zclient->redist_default && + vrf_bitmap_check (zclient->redist[afi][i], vrf_id)) + zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, afi, i, 0, vrf_id); + + /* If default information is needed. */ + if (vrf_bitmap_check (zclient->default_information, VRF_DEFAULT)) + zebra_message_send (zclient, ZEBRA_REDISTRIBUTE_DEFAULT_ADD, vrf_id); +} + /* Make connection to zebra daemon. */ int zclient_start (struct zclient *zclient) { - int i; - afi_t afi; + if (zclient_debug) + zlog_info ("zclient_start is called"); + + /* zclient is disabled. */ + if (! zclient->enable) + return 0; /* If already connected to the zebra. */ if (zclient->sock >= 0) @@ -382,40 +443,33 @@ zclient_start (struct zclient *zclient) if (zclient->t_connect) return 0; - /* Flush all redistribute request. */ - for (afi = AFI_IP; afi < AFI_MAX; afi++) - for (i = 0; i < ZEBRA_ROUTE_MAX; i++) - if (zclient->redist[afi][i].enabled) - { - struct listnode *node; - u_short *id; - - for (ALL_LIST_ELEMENTS_RO(zclient->redist[afi][i].instances, node, id)) - if (!(i == zclient->redist_default && *id == zclient->instance)) - zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, afi, i, *id); - } + if (zclient_socket_connect(zclient) < 0) + { + if (zclient_debug) + zlog_debug ("zclient connection fail"); + zclient->fail++; + zclient_event (ZCLIENT_CONNECT, zclient); + return -1; + } - /* If default information is needed. */ - if (zclient->default_information) - zebra_message_send (zclient, ZEBRA_REDISTRIBUTE_DEFAULT_ADD); + if (set_nonblocking(zclient->sock) < 0) + zlog_warn("%s: set_nonblocking(%d) failed", __func__, zclient->sock); - return 0; -} + /* Clear fail count. */ + zclient->fail = 0; + if (zclient_debug) + zlog_debug ("zclient connect success with socket [%d]", zclient->sock); -/* This function is a wrapper function for calling zclient_start from - timer or event thread. */ -static int -zclient_connect (struct thread *t) -{ - struct zclient *zclient; + /* Create read thread. */ + zclient_event (ZCLIENT_READ, zclient); - zclient = THREAD_ARG (t); - zclient->t_connect = NULL; + zebra_hello_send (zclient); - if (zclient_debug) - zlog_debug ("zclient_connect is called"); + /* Inform the successful connection. */ + if (zclient->zebra_connected) + (*zclient->zebra_connected) (zclient); - return zclient_start (zclient); + return 0; } /* Initialize zebra client. Argument redist_default is unwanted @@ -434,7 +488,7 @@ zclient_init (struct zclient *zclient, int redist_default, u_short instance) /* Clear redistribution flags. */ for (afi = AFI_IP; afi < AFI_MAX; afi++) for (i = 0; i < ZEBRA_ROUTE_MAX; i++) - memset(&zclient->redist[afi][i], 0, sizeof(struct redist_proto)); + zclient->redist[afi][i] = vrf_bitmap_init(); /* Set unwanted redistribute route. bgpd does not need BGP route redistribution. */ @@ -442,47 +496,31 @@ zclient_init (struct zclient *zclient, int redist_default, u_short instance) zclient->instance = instance; /* Pending: make afi(s) an arg. */ for (afi = AFI_IP; afi < AFI_MAX; afi++) - redist_add_instance (&zclient->redist[afi][redist_default], instance); + redist_add_instance (&zclient->mi_redist[afi][redist_default], instance); /* Set default-information redistribute to zero. */ - zclient->default_information = 0; + zclient->default_information = vrf_bitmap_init ();; if (zclient_debug) zlog_debug ("zclient_start is called"); - /* zclient is disabled. */ - if (! zclient->enable) - return; + zclient_event (ZCLIENT_SCHEDULE, zclient); +} - if (zclient_socket_connect(zclient) < 0) - { - if (zclient_debug) - zlog_debug ("zclient connection fail"); - zclient->fail++; - zclient_event (ZCLIENT_CONNECT, zclient); - return; - } +/* This function is a wrapper function for calling zclient_start from + timer or event thread. */ +static int +zclient_connect (struct thread *t) +{ + struct zclient *zclient; - if (set_nonblocking(zclient->sock) < 0) - zlog_warn("%s: set_nonblocking(%d) failed", __func__, zclient->sock); + zclient = THREAD_ARG (t); + zclient->t_connect = NULL; - /* Clear fail count. */ - zclient->fail = 0; if (zclient_debug) - zlog_debug ("zclient connect success with socket [%d]", zclient->sock); - - /* Create read thread. */ - zclient_event (ZCLIENT_READ, zclient); - - zebra_hello_send (zclient); - - /* We need router-id information. */ - zebra_message_send (zclient, ZEBRA_ROUTER_ID_ADD); - - /* We need interface information. */ - zebra_message_send (zclient, ZEBRA_INTERFACE_ADD); + zlog_debug ("zclient_connect is called"); - zclient_event (ZCLIENT_SCHEDULE, zclient); + return zclient_start (zclient); } /* @@ -557,8 +595,8 @@ zapi_ipv4_route (u_char cmd, struct zclient *zclient, struct prefix_ipv4 *p, /* Reset stream. */ s = zclient->obuf; stream_reset (s); - - zclient_create_header (s, cmd); + + zclient_create_header (s, cmd, api->vrf_id); /* Put type and nexthop. */ stream_putc (s, api->type); @@ -640,7 +678,7 @@ zapi_ipv4_route_ipv6_nexthop (u_char cmd, struct zclient *zclient, s = zclient->obuf; stream_reset (s); - zclient_create_header (s, cmd); + zclient_create_header (s, cmd, api->vrf_id); /* Put type and nexthop. */ stream_putc (s, api->type); @@ -704,7 +742,7 @@ zapi_ipv6_route (u_char cmd, struct zclient *zclient, struct prefix_ipv6 *p, s = zclient->obuf; stream_reset (s); - zclient_create_header (s, cmd); + zclient_create_header (s, cmd, api->vrf_id); /* Put type and nexthop. */ stream_putc (s, api->type); @@ -765,14 +803,14 @@ zapi_ipv6_route (u_char cmd, struct zclient *zclient, struct prefix_ipv6 *p, */ int zebra_redistribute_send (int command, struct zclient *zclient, afi_t afi, int type, - u_short instance) + u_short instance, vrf_id_t vrf_id) { struct stream *s; s = zclient->obuf; stream_reset(s); - zclient_create_header (s, command); + zclient_create_header (s, command, vrf_id); stream_putc (s, afi); stream_putc (s, type); stream_putw (s, instance); @@ -829,7 +867,7 @@ zebra_router_id_update_read (struct stream *s, struct prefix *rid) */ struct interface * -zebra_interface_add_read (struct stream *s) +zebra_interface_add_read (struct stream *s, vrf_id_t vrf_id) { struct interface *ifp; char ifname_tmp[INTERFACE_NAMSIZ]; @@ -838,7 +876,9 @@ zebra_interface_add_read (struct stream *s) stream_get (ifname_tmp, s, INTERFACE_NAMSIZ); /* Lookup/create interface by name. */ - ifp = if_get_by_name_len (ifname_tmp, strnlen(ifname_tmp, INTERFACE_NAMSIZ)); + ifp = if_get_by_name_len_vrf (ifname_tmp, + strnlen (ifname_tmp, INTERFACE_NAMSIZ), + vrf_id); zebra_interface_if_set_value (s, ifp); @@ -853,7 +893,7 @@ zebra_interface_add_read (struct stream *s) * is sent at the tail of the message. */ struct interface * -zebra_interface_state_read (struct stream *s) +zebra_interface_state_read (struct stream *s, vrf_id_t vrf_id) { struct interface *ifp; char ifname_tmp[INTERFACE_NAMSIZ]; @@ -862,8 +902,9 @@ zebra_interface_state_read (struct stream *s) stream_get (ifname_tmp, s, INTERFACE_NAMSIZ); /* Lookup this by interface index. */ - ifp = if_lookup_by_name_len (ifname_tmp, - strnlen(ifname_tmp, INTERFACE_NAMSIZ)); + ifp = if_lookup_by_name_len_vrf (ifname_tmp, + strnlen (ifname_tmp, INTERFACE_NAMSIZ), + vrf_id); /* If such interface does not exist, indicate an error */ if (! ifp) @@ -943,7 +984,7 @@ memconstant(const void *s, int c, size_t n) struct connected * -zebra_interface_address_read (int type, struct stream *s) +zebra_interface_address_read (int type, struct stream *s, vrf_id_t vrf_id) { unsigned int ifindex; struct interface *ifp; @@ -960,7 +1001,7 @@ zebra_interface_address_read (int type, struct stream *s) ifindex = stream_getl (s); /* Lookup index. */ - ifp = if_lookup_by_index (ifindex); + ifp = if_lookup_by_index_vrf (ifindex, vrf_id); if (ifp == NULL) { zlog_warn ("zebra_interface_address_read(%s): " @@ -1040,7 +1081,7 @@ zebra_interface_address_read (int type, struct stream *s) * +-+-+-+-+-+-+-+-+ */ struct nbr_connected * -zebra_interface_nbr_address_read (int type, struct stream *s) +zebra_interface_nbr_address_read (int type, struct stream *s, vrf_id_t vrf_id) { unsigned int ifindex; struct interface *ifp; @@ -1098,6 +1139,7 @@ zclient_read (struct thread *thread) size_t already; uint16_t length, command; uint8_t marker, version; + vrf_id_t vrf_id; struct zclient *zclient; /* Get socket to zebra. */ @@ -1132,6 +1174,7 @@ zclient_read (struct thread *thread) length = stream_getw (zclient->ibuf); marker = stream_getc (zclient->ibuf); version = stream_getc (zclient->ibuf); + vrf_id = stream_getw (zclient->ibuf); command = stream_getw (zclient->ibuf); if (marker != ZEBRA_HEADER_MARKER || version != ZSERV_VERSION) @@ -1183,97 +1226,97 @@ zclient_read (struct thread *thread) length -= ZEBRA_HEADER_SIZE; if (zclient_debug) - zlog_debug("zclient 0x%p command 0x%x \n", zclient, command); + zlog_debug("zclient 0x%p command 0x%x VRF %u\n", (void *)zclient, command, vrf_id); switch (command) { case ZEBRA_ROUTER_ID_UPDATE: if (zclient->router_id_update) - (*zclient->router_id_update) (command, zclient, length); + (*zclient->router_id_update) (command, zclient, length, vrf_id); break; case ZEBRA_INTERFACE_ADD: if (zclient->interface_add) - (*zclient->interface_add) (command, zclient, length); + (*zclient->interface_add) (command, zclient, length, vrf_id); break; case ZEBRA_INTERFACE_DELETE: if (zclient->interface_delete) - (*zclient->interface_delete) (command, zclient, length); + (*zclient->interface_delete) (command, zclient, length, vrf_id); break; case ZEBRA_INTERFACE_ADDRESS_ADD: if (zclient->interface_address_add) - (*zclient->interface_address_add) (command, zclient, length); + (*zclient->interface_address_add) (command, zclient, length, vrf_id); break; case ZEBRA_INTERFACE_ADDRESS_DELETE: if (zclient->interface_address_delete) - (*zclient->interface_address_delete) (command, zclient, length); + (*zclient->interface_address_delete) (command, zclient, length, vrf_id); break; case ZEBRA_INTERFACE_BFD_DEST_UPDATE: if (zclient->interface_bfd_dest_update) - (*zclient->interface_bfd_dest_update) (command, zclient, length); + (*zclient->interface_bfd_dest_update) (command, zclient, length, vrf_id); break; case ZEBRA_INTERFACE_NBR_ADDRESS_ADD: if (zclient->interface_nbr_address_add) - (*zclient->interface_nbr_address_add) (command, zclient, length); + (*zclient->interface_nbr_address_add) (command, zclient, length, vrf_id); break; case ZEBRA_INTERFACE_NBR_ADDRESS_DELETE: if (zclient->interface_nbr_address_delete) - (*zclient->interface_nbr_address_delete) (command, zclient, length); + (*zclient->interface_nbr_address_delete) (command, zclient, length, vrf_id); break; case ZEBRA_INTERFACE_UP: if (zclient->interface_up) - (*zclient->interface_up) (command, zclient, length); + (*zclient->interface_up) (command, zclient, length, vrf_id); break; case ZEBRA_INTERFACE_DOWN: if (zclient->interface_down) - (*zclient->interface_down) (command, zclient, length); + (*zclient->interface_down) (command, zclient, length, vrf_id); break; case ZEBRA_IPV4_ROUTE_ADD: if (zclient->ipv4_route_add) - (*zclient->ipv4_route_add) (command, zclient, length); + (*zclient->ipv4_route_add) (command, zclient, length, vrf_id); break; case ZEBRA_IPV4_ROUTE_DELETE: if (zclient->ipv4_route_delete) - (*zclient->ipv4_route_delete) (command, zclient, length); + (*zclient->ipv4_route_delete) (command, zclient, length, vrf_id); break; case ZEBRA_IPV6_ROUTE_ADD: if (zclient->ipv6_route_add) - (*zclient->ipv6_route_add) (command, zclient, length); + (*zclient->ipv6_route_add) (command, zclient, length, vrf_id); break; case ZEBRA_IPV6_ROUTE_DELETE: if (zclient->ipv6_route_delete) - (*zclient->ipv6_route_delete) (command, zclient, length); + (*zclient->ipv6_route_delete) (command, zclient, length, vrf_id); break; case ZEBRA_NEXTHOP_UPDATE: if (zclient_debug) zlog_debug("zclient rcvd nexthop update\n"); if (zclient->nexthop_update) - (*zclient->nexthop_update) (command, zclient, length); + (*zclient->nexthop_update) (command, zclient, length, vrf_id); break; case ZEBRA_IMPORT_CHECK_UPDATE: if (zclient_debug) zlog_debug("zclient rcvd import check update\n"); if (zclient->import_check_update) - (*zclient->import_check_update) (command, zclient, length); + (*zclient->import_check_update) (command, zclient, length, vrf_id); break; case ZEBRA_BFD_DEST_REPLAY: if (zclient->bfd_dest_replay) - (*zclient->bfd_dest_replay) (command, zclient, length); + (*zclient->bfd_dest_replay) (command, zclient, length, vrf_id); break; case ZEBRA_REDISTRIBUTE_IPV4_ADD: if (zclient->redistribute_route_ipv4_add) - (*zclient->redistribute_route_ipv4_add) (command, zclient, length); + (*zclient->redistribute_route_ipv4_add) (command, zclient, length, vrf_id); break; case ZEBRA_REDISTRIBUTE_IPV4_DEL: if (zclient->redistribute_route_ipv4_del) - (*zclient->redistribute_route_ipv4_del) (command, zclient, length); + (*zclient->redistribute_route_ipv4_del) (command, zclient, length, vrf_id); break; case ZEBRA_REDISTRIBUTE_IPV6_ADD: if (zclient->redistribute_route_ipv6_add) - (*zclient->redistribute_route_ipv6_add) (command, zclient, length); + (*zclient->redistribute_route_ipv6_add) (command, zclient, length, vrf_id); break; case ZEBRA_REDISTRIBUTE_IPV6_DEL: if (zclient->redistribute_route_ipv6_del) - (*zclient->redistribute_route_ipv6_del) (command, zclient, length); + (*zclient->redistribute_route_ipv6_del) (command, zclient, length, vrf_id); break; default: break; @@ -1292,46 +1335,63 @@ zclient_read (struct thread *thread) void zclient_redistribute (int command, struct zclient *zclient, afi_t afi, int type, - u_short instance) + u_short instance, vrf_id_t vrf_id) { - if (command == ZEBRA_REDISTRIBUTE_ADD) - { - if (redist_check_instance(&zclient->redist[afi][type], instance)) - return; - redist_add_instance(&zclient->redist[afi][type], instance); - } - else - { - if (!redist_check_instance(&zclient->redist[afi][type], instance)) - return; - redist_del_instance(&zclient->redist[afi][type], instance); - } + if (instance) { + if (command == ZEBRA_REDISTRIBUTE_ADD) + { + if (redist_check_instance(&zclient->mi_redist[afi][type], instance)) + return; + redist_add_instance(&zclient->mi_redist[afi][type], instance); + } + else + { + if (!redist_check_instance(&zclient->mi_redist[afi][type], instance)) + return; + redist_del_instance(&zclient->mi_redist[afi][type], instance); + } + + } else { + if (command == ZEBRA_REDISTRIBUTE_ADD) + { + if (vrf_bitmap_check (zclient->redist[afi][type], vrf_id)) + return; + vrf_bitmap_set (zclient->redist[afi][type], vrf_id); + } + else + { + if (!vrf_bitmap_check (zclient->redist[afi][type], vrf_id)) + return; + vrf_bitmap_unset (zclient->redist[afi][type], vrf_id); + } + } if (zclient->sock > 0) - zebra_redistribute_send (command, zclient, afi, type, instance); + zebra_redistribute_send (command, zclient, afi, type, instance, vrf_id); } void -zclient_redistribute_default (int command, struct zclient *zclient) +zclient_redistribute_default (int command, struct zclient *zclient, + vrf_id_t vrf_id) { if (command == ZEBRA_REDISTRIBUTE_DEFAULT_ADD) { - if (zclient->default_information) + if (vrf_bitmap_check (zclient->default_information, vrf_id)) return; - zclient->default_information = 1; + vrf_bitmap_set (zclient->default_information, vrf_id); } else { - if (!zclient->default_information) + if (!vrf_bitmap_check (zclient->default_information, vrf_id)) return; - zclient->default_information = 0; + vrf_bitmap_unset (zclient->default_information, vrf_id); } if (zclient->sock > 0) - zebra_message_send (zclient, command); + zebra_message_send (zclient, command, vrf_id); } static void diff --git a/lib/zclient.h b/lib/zclient.h index 8caf682d81..4d855a426a 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -28,11 +28,14 @@ /* For struct interface and struct connected. */ #include "if.h" +/* For vrf_bitmap_t. */ +#include "vrf.h" + /* For input/output buffer to zebra. */ #define ZEBRA_MAX_PACKET_SIZ 4096 /* Zebra header size. */ -#define ZEBRA_HEADER_SIZE 6 +#define ZEBRA_HEADER_SIZE 8 struct redist_proto { @@ -75,33 +78,35 @@ struct zclient /* Redistribute information. */ u_char redist_default; /* clients protocol */ u_short instance; - struct redist_proto redist[AFI_MAX][ZEBRA_ROUTE_MAX]; + struct redist_proto mi_redist[AFI_MAX][ZEBRA_ROUTE_MAX]; + vrf_bitmap_t redist[AFI_MAX][ZEBRA_ROUTE_MAX]; /* Redistribute defauilt. */ - u_char default_information; + vrf_bitmap_t default_information; /* Pointer to the callback functions. */ - int (*router_id_update) (int, struct zclient *, uint16_t); - int (*interface_add) (int, struct zclient *, uint16_t); - int (*interface_delete) (int, struct zclient *, uint16_t); - int (*interface_up) (int, struct zclient *, uint16_t); - int (*interface_down) (int, struct zclient *, uint16_t); - int (*interface_address_add) (int, struct zclient *, uint16_t); - int (*interface_address_delete) (int, struct zclient *, uint16_t); - int (*interface_bfd_dest_update) (int, struct zclient *, uint16_t); - int (*interface_nbr_address_add) (int, struct zclient *, uint16_t); - int (*interface_nbr_address_delete) (int, struct zclient *, uint16_t); - int (*ipv4_route_add) (int, struct zclient *, uint16_t); - int (*ipv4_route_delete) (int, struct zclient *, uint16_t); - int (*ipv6_route_add) (int, struct zclient *, uint16_t); - int (*ipv6_route_delete) (int, struct zclient *, uint16_t); - int (*nexthop_update) (int, struct zclient *, uint16_t); - int (*import_check_update) (int, struct zclient *, uint16_t); - int (*bfd_dest_replay) (int, struct zclient *, uint16_t); - int (*redistribute_route_ipv4_add) (int, struct zclient *, uint16_t); - int (*redistribute_route_ipv4_del) (int, struct zclient *, uint16_t); - int (*redistribute_route_ipv6_add) (int, struct zclient *, uint16_t); - int (*redistribute_route_ipv6_del) (int, struct zclient *, uint16_t); + void (*zebra_connected) (struct zclient *); + int (*router_id_update) (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); + int (*interface_down) (int, struct zclient *, uint16_t, vrf_id_t); + int (*interface_address_add) (int, struct zclient *, uint16_t, vrf_id_t); + int (*interface_address_delete) (int, struct zclient *, uint16_t, vrf_id_t); + int (*interface_bfd_dest_update) (int, struct zclient *, uint16_t, vrf_id_t); + int (*interface_nbr_address_add) (int, struct zclient *, uint16_t, vrf_id_t); + int (*interface_nbr_address_delete) (int, struct zclient *, uint16_t, vrf_id_t); + int (*ipv4_route_add) (int, struct zclient *, uint16_t, vrf_id_t); + int (*ipv4_route_delete) (int, struct zclient *, uint16_t, vrf_id_t); + int (*ipv6_route_add) (int, struct zclient *, uint16_t, vrf_id_t); + int (*ipv6_route_delete) (int, struct zclient *, uint16_t, vrf_id_t); + int (*nexthop_update) (int, struct zclient *, uint16_t, vrf_id_t); + int (*import_check_update) (int, struct zclient *, uint16_t, vrf_id_t); + int (*bfd_dest_replay) (int, struct zclient *, uint16_t, vrf_id_t); + int (*redistribute_route_ipv4_add) (int, struct zclient *, uint16_t, vrf_id_t); + int (*redistribute_route_ipv4_del) (int, struct zclient *, uint16_t, vrf_id_t); + int (*redistribute_route_ipv6_add) (int, struct zclient *, uint16_t, vrf_id_t); + int (*redistribute_route_ipv6_del) (int, struct zclient *, uint16_t, vrf_id_t); }; /* Zebra API message flag. */ @@ -120,7 +125,8 @@ struct zserv_header * always set to 255 in new zserv. */ uint8_t version; -#define ZSERV_VERSION 2 +#define ZSERV_VERSION 3 + vrf_id_t vrf_id; uint16_t command; }; @@ -147,6 +153,8 @@ struct zapi_ipv4 u_int32_t metric; u_short tag; + + vrf_id_t vrf_id; }; /* Prototypes of zebra client service functions. */ @@ -164,27 +172,30 @@ extern int redist_check_instance (struct redist_proto *, u_short); extern void redist_add_instance (struct redist_proto *, u_short); extern void redist_del_instance (struct redist_proto *, u_short); +extern void zclient_send_requests (struct zclient *, vrf_id_t); + /* Send redistribute command to zebra daemon. Do not update zclient state. */ -extern int zebra_redistribute_send (int command, struct zclient *, afi_t, int type, u_short instance); +extern int zebra_redistribute_send (int command, struct zclient *, afi_t, int type, u_short instance, vrf_id_t vrf_id); /* If state has changed, update state and call zebra_redistribute_send. */ extern void zclient_redistribute (int command, struct zclient *, afi_t, int type, - u_short instance); + u_short instance, vrf_id_t vrf_id); /* If state has changed, update state and send the command to zebra. */ -extern void zclient_redistribute_default (int command, struct zclient *); +extern void zclient_redistribute_default (int command, struct zclient *, + vrf_id_t vrf_id); /* Send the message in zclient->obuf to the zebra daemon (or enqueue it). Returns 0 for success or -1 on an I/O error. */ 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); +extern void zclient_create_header (struct stream *, uint16_t, vrf_id_t); -extern struct interface *zebra_interface_add_read (struct stream *); -extern struct interface *zebra_interface_state_read (struct stream *s); -extern struct connected *zebra_interface_address_read (int, struct stream *); -extern struct nbr_connected *zebra_interface_nbr_address_read (int, struct stream *); +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); +extern struct nbr_connected *zebra_interface_nbr_address_read (int, struct stream *, vrf_id_t); extern void zebra_interface_if_set_value (struct stream *, struct interface *); extern void zebra_router_id_update_read (struct stream *s, struct prefix *rid); extern int zapi_ipv4_route (u_char, struct zclient *, struct prefix_ipv4 *, @@ -215,6 +226,8 @@ struct zapi_ipv6 u_int32_t metric; u_short tag; + + vrf_id_t vrf_id; }; extern int zapi_ipv6_route (u_char cmd, struct zclient *zclient, diff --git a/lib/zebra.h b/lib/zebra.h index a3ac78cbce..47665ea9c4 100644 --- a/lib/zebra.h +++ b/lib/zebra.h @@ -442,7 +442,8 @@ struct in_pktinfo #define ZEBRA_REDISTRIBUTE_IPV4_DEL 39 #define ZEBRA_REDISTRIBUTE_IPV6_ADD 40 #define ZEBRA_REDISTRIBUTE_IPV6_DEL 41 -#define ZEBRA_MESSAGE_MAX 42 +#define ZEBRA_VRF_UNREGISTER 42 +#define ZEBRA_MESSAGE_MAX 43 /* Marker value used in new Zserv, in the byte location corresponding * the command value in the old zserv header. To allow old and new diff --git a/ospf6d/ospf6_bfd.c b/ospf6d/ospf6_bfd.c index 16dedb1031..f2bc52aff2 100644 --- a/ospf6d/ospf6_bfd.c +++ b/ospf6d/ospf6_bfd.c @@ -92,7 +92,7 @@ ospf6_bfd_reg_dereg_nbr (struct ospf6_neighbor *on, int command) bfd_peer_sendmsg (zclient, bfd_info, AF_INET6, &on->linklocal_addr, on->ospf6_if->linklocal_addr, ifp->name, - 0, 0, command, 0); + 0, 0, command, 0, VRF_DEFAULT); if (command == ZEBRA_BFD_DEST_DEREGISTER) bfd_info_free((struct bfd_info **)&on->bfd_info); @@ -145,7 +145,8 @@ ospf6_bfd_reg_dereg_all_nbr (struct ospf6_interface *oi, int command) * to zebra */ static int -ospf6_bfd_nbr_replay (int command, struct zclient *client, zebra_size_t length) +ospf6_bfd_nbr_replay (int command, struct zclient *client, zebra_size_t length, + vrf_id_t vrf_id) { struct listnode *inode, *nnode; struct interface *ifp; @@ -188,7 +189,7 @@ ospf6_bfd_nbr_replay (int command, struct zclient *client, zebra_size_t length) */ static int ospf6_bfd_interface_dest_update (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct interface *ifp; struct ospf6_interface *oi; diff --git a/ospf6d/ospf6_zebra.c b/ospf6d/ospf6_zebra.c index f97a9db723..b3e18bfd3e 100644 --- a/ospf6d/ospf6_zebra.c +++ b/ospf6d/ospf6_zebra.c @@ -49,7 +49,7 @@ struct in_addr router_id_zebra; /* Router-id update message from zebra. */ static int ospf6_router_id_update_zebra (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct prefix router_id; struct ospf6 *o = ospf6; @@ -70,30 +70,34 @@ ospf6_router_id_update_zebra (int command, struct zclient *zclient, void ospf6_zebra_redistribute (int type) { - if (zclient->redist[AFI_IP6][type].enabled) + if (vrf_bitmap_check (zclient->redist[AFI_IP6][type], VRF_DEFAULT)) return; - redist_add_instance(&zclient->redist[AFI_IP6][type], 0); + vrf_bitmap_set (zclient->redist[AFI_IP6][type], VRF_DEFAULT); + if (zclient->sock > 0) - zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP6, type, 0); + zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP6, type, 0, + VRF_DEFAULT); } void ospf6_zebra_no_redistribute (int type) { - if (! zclient->redist[AFI_IP6][type].enabled) + if (!vrf_bitmap_check (zclient->redist[AFI_IP6][type], VRF_DEFAULT)) return; - redist_del_instance(&zclient->redist[AFI_IP6][type], 0); + vrf_bitmap_unset (zclient->redist[AFI_IP6][type], VRF_DEFAULT); if (zclient->sock > 0) - zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, AFI_IP6, type, 0); + zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, AFI_IP6, type, + 0, VRF_DEFAULT); } /* Inteface addition message from zebra. */ static int -ospf6_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length) +ospf6_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length, + vrf_id_t vrf_id) { struct interface *ifp; - ifp = zebra_interface_add_read (zclient->ibuf); + ifp = zebra_interface_add_read (zclient->ibuf, vrf_id); if (IS_OSPF6_DEBUG_ZEBRA (RECV)) zlog_debug ("Zebra Interface add: %s index %d mtu %d", ifp->name, ifp->ifindex, ifp->mtu6); @@ -102,11 +106,12 @@ ospf6_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length) } static int -ospf6_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length) +ospf6_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length, + vrf_id_t vrf_id) { struct interface *ifp; - if (!(ifp = zebra_interface_state_read(zclient->ibuf))) + if (!(ifp = zebra_interface_state_read (zclient->ibuf, vrf_id))) return 0; if (if_is_up (ifp)) @@ -129,11 +134,11 @@ ospf6_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length) static int ospf6_zebra_if_state_update (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct interface *ifp; - ifp = zebra_interface_state_read (zclient->ibuf); + ifp = zebra_interface_state_read (zclient->ibuf, vrf_id); if (ifp == NULL) return 0; @@ -149,12 +154,13 @@ ospf6_zebra_if_state_update (int command, struct zclient *zclient, static int ospf6_zebra_if_address_update_add (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct connected *c; char buf[128]; - c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, zclient->ibuf); + c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, zclient->ibuf, + vrf_id); if (c == NULL) return 0; @@ -174,12 +180,13 @@ ospf6_zebra_if_address_update_add (int command, struct zclient *zclient, static int ospf6_zebra_if_address_update_delete (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct connected *c; char buf[128]; - c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE, zclient->ibuf); + c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE, zclient->ibuf, + vrf_id); if (c == NULL) return 0; @@ -200,7 +207,7 @@ ospf6_zebra_if_address_update_delete (int command, struct zclient *zclient, static int ospf6_zebra_read_ipv6 (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct stream *s; struct zapi_ipv6 api; @@ -292,12 +299,13 @@ DEFUN (show_zebra, vty_out (vty, "Zebra Infomation%s", VNL); vty_out (vty, " enable: %d fail: %d%s", zclient->enable, zclient->fail, VNL); - vty_out (vty, " redistribute default: %d%s", zclient->redist_default, + vty_out (vty, " redistribute default: %d%s", + vrf_bitmap_check (zclient->default_information, VRF_DEFAULT), VNL); vty_out (vty, " redistribute:"); for (i = 0; i < ZEBRA_ROUTE_MAX; i++) { - if (zclient->redist[AFI_IP6][i].enabled) + if (vrf_bitmap_check (zclient->redist[AFI_IP6][i], VRF_DEFAULT)) vty_out (vty, " %s", zebra_route_string(i)); } vty_out (vty, "%s", VNL); @@ -337,7 +345,8 @@ config_write_ospf6_zebra (struct vty *vty) vty_out (vty, "no router zebra%s", VNL); vty_out (vty, "!%s", VNL); } - else if (! zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6].enabled) + else if (! vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], + VRF_DEFAULT)) { vty_out (vty, "router zebra%s", VNL); vty_out (vty, " no redistribute ospf6%s", VNL); @@ -438,6 +447,7 @@ ospf6_zebra_route_update (int type, struct ospf6_route *request) ospf6_route_zebra_copy_nexthops (request, ifindexes, nexthops, nhcount); + api.vrf_id = VRF_DEFAULT; api.type = ZEBRA_ROUTE_OSPF6; api.instance = 0; api.flags = 0; @@ -472,7 +482,8 @@ ospf6_zebra_route_update (int type, struct ospf6_route *request) void ospf6_zebra_route_update_add (struct ospf6_route *request) { - if (! zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6].enabled) + if (! vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], + VRF_DEFAULT)) { ospf6->route_table->hook_add = NULL; ospf6->route_table->hook_remove = NULL; @@ -484,7 +495,8 @@ ospf6_zebra_route_update_add (struct ospf6_route *request) void ospf6_zebra_route_update_remove (struct ospf6_route *request) { - if (! zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6].enabled) + if (! vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], + VRF_DEFAULT)) { ospf6->route_table->hook_add = NULL; ospf6->route_table->hook_remove = NULL; @@ -500,7 +512,8 @@ ospf6_zebra_add_discard (struct ospf6_route *request) char buf[INET6_ADDRSTRLEN]; struct prefix_ipv6 *dest; - if (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6].enabled) + if (vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], + VRF_DEFAULT)) { if (!CHECK_FLAG (request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED)) { @@ -544,7 +557,7 @@ ospf6_zebra_delete_discard (struct ospf6_route *request) char buf[INET6_ADDRSTRLEN]; struct prefix_ipv6 *dest; - if (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6].enabled) + if (vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], VRF_DEFAULT)) { if (CHECK_FLAG (request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED)) { @@ -587,10 +600,10 @@ DEFUN (redistribute_ospf6, { struct ospf6_route *route; - if (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6].enabled) + if (vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], VRF_DEFAULT)) return CMD_SUCCESS; - redist_add_instance(&zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], 0); + vrf_bitmap_set (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], VRF_DEFAULT); if (ospf6 == NULL) return CMD_SUCCESS; @@ -615,10 +628,10 @@ DEFUN (no_redistribute_ospf6, { struct ospf6_route *route; - if (! zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6].enabled) + if (! vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], VRF_DEFAULT)) return CMD_SUCCESS; - redist_del_instance(&zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], 0); + vrf_bitmap_unset (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], VRF_DEFAULT); if (ospf6 == NULL) return CMD_SUCCESS; @@ -634,12 +647,19 @@ DEFUN (no_redistribute_ospf6, return CMD_SUCCESS; } +static void +ospf6_zebra_connected (struct zclient *zclient) +{ + zclient_send_requests (zclient, VRF_DEFAULT); +} + void ospf6_zebra_init (struct thread_master *master) { /* Allocate zebra structure. */ zclient = zclient_new(master); zclient_init (zclient, ZEBRA_ROUTE_OSPF6, 0); + zclient->zebra_connected = ospf6_zebra_connected; zclient->router_id_update = ospf6_router_id_update_zebra; zclient->interface_add = ospf6_zebra_if_add; zclient->interface_delete = ospf6_zebra_if_del; diff --git a/ospf6d/ospf6_zebra.h b/ospf6d/ospf6_zebra.h index 972b44d4a0..5b28c07636 100644 --- a/ospf6d/ospf6_zebra.h +++ b/ospf6d/ospf6_zebra.h @@ -42,7 +42,8 @@ extern void ospf6_zebra_route_update_remove (struct ospf6_route *request); extern void ospf6_zebra_redistribute (int); extern void ospf6_zebra_no_redistribute (int); -#define ospf6_zebra_is_redistribute(type) (zclient->redist[AFI_IP6][type].enabled) +#define ospf6_zebra_is_redistribute(type) \ + vrf_bitmap_check (zclient->redist[AFI_IP6][type], VRF_DEFAULT) extern void ospf6_zebra_init (struct thread_master *); extern void ospf6_zebra_add_discard (struct ospf6_route *request); extern void ospf6_zebra_delete_discard (struct ospf6_route *request); diff --git a/ospfd/ospf_bfd.c b/ospfd/ospf_bfd.c index 46c1844e28..6c0ef37efd 100644 --- a/ospfd/ospf_bfd.c +++ b/ospfd/ospf_bfd.c @@ -83,7 +83,7 @@ ospf_bfd_reg_dereg_nbr (struct ospf_neighbor *nbr, int command) inet_ntoa (nbr->src)); bfd_peer_sendmsg (zclient, bfd_info, AF_INET, - &nbr->src, NULL, ifp->name, 0, 0, command, 0); + &nbr->src, NULL, ifp->name, 0, 0, command, 0, VRF_DEFAULT); } /* @@ -147,7 +147,8 @@ ospf_bfd_reg_dereg_all_nbr (struct interface *ifp, int command) * to zebra */ static int -ospf_bfd_nbr_replay (int command, struct zclient *client, zebra_size_t length) +ospf_bfd_nbr_replay (int command, struct zclient *client, zebra_size_t length, + vrf_id_t vrf_id) { struct listnode *inode, *node, *onode; struct ospf *ospf; @@ -200,7 +201,7 @@ ospf_bfd_nbr_replay (int command, struct zclient *client, zebra_size_t length) */ static int ospf_bfd_interface_dest_update (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct interface *ifp; struct ospf_interface *oi; diff --git a/ospfd/ospf_flood.c b/ospfd/ospf_flood.c index 4e6b7348e5..5a6893a6f8 100644 --- a/ospfd/ospf_flood.c +++ b/ospfd/ospf_flood.c @@ -94,8 +94,11 @@ ospf_external_info_check (struct ospf_lsa *lsa) { int redist_on = 0; - redist_on = is_prefix_default (&p) ? zclient->default_information : - zclient->redist[AFI_IP][type].enabled; + redist_on = is_prefix_default (&p) ? + vrf_bitmap_check (zclient->default_information, VRF_DEFAULT) : + (zclient->mi_redist[AFI_IP][type].enabled || + vrf_bitmap_check (zclient->redist[AFI_IP][type], VRF_DEFAULT)); + //Pending: check for MI above. if (redist_on) { struct list *ext_list; diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c index a95b2e1b67..15585eaea7 100644 --- a/ospfd/ospf_zebra.c +++ b/ospfd/ospf_zebra.c @@ -62,7 +62,7 @@ struct in_addr router_id_zebra; /* Router-id update message from zebra. */ static int ospf_router_id_update_zebra (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct ospf *ospf; struct prefix router_id; @@ -87,11 +87,12 @@ ospf_router_id_update_zebra (int command, struct zclient *zclient, /* Inteface addition message from zebra. */ static int -ospf_interface_add (int command, struct zclient *zclient, zebra_size_t length) +ospf_interface_add (int command, struct zclient *zclient, zebra_size_t length, + vrf_id_t vrf_id) { struct interface *ifp; - ifp = zebra_interface_add_read (zclient->ibuf); + ifp = zebra_interface_add_read (zclient->ibuf, vrf_id); if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE)) zlog_debug ("Zebra: interface add %s index %d flags %llx metric %d mtu %d", @@ -117,7 +118,7 @@ ospf_interface_add (int command, struct zclient *zclient, zebra_size_t length) static int ospf_interface_delete (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct interface *ifp; struct stream *s; @@ -125,7 +126,7 @@ ospf_interface_delete (int command, struct zclient *zclient, s = zclient->ibuf; /* zebra_interface_state_read() updates interface structure in iflist */ - ifp = zebra_interface_state_read (s); + ifp = zebra_interface_state_read (s, vrf_id); if (ifp == NULL) return 0; @@ -152,7 +153,7 @@ ospf_interface_delete (int command, struct zclient *zclient, } static struct interface * -zebra_interface_if_lookup (struct stream *s) +zebra_interface_if_lookup (struct stream *s, vrf_id_t vrf_id) { char ifname_tmp[INTERFACE_NAMSIZ]; @@ -166,13 +167,13 @@ zebra_interface_if_lookup (struct stream *s) static int ospf_interface_state_up (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct interface *ifp; struct ospf_interface *oi; struct route_node *rn; - ifp = zebra_interface_if_lookup (zclient->ibuf); + ifp = zebra_interface_if_lookup (zclient->ibuf, vrf_id); if (ifp == NULL) return 0; @@ -228,13 +229,13 @@ ospf_interface_state_up (int command, struct zclient *zclient, static int ospf_interface_state_down (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct interface *ifp; struct ospf_interface *oi; struct route_node *node; - ifp = zebra_interface_state_read (zclient->ibuf); + ifp = zebra_interface_state_read (zclient->ibuf, vrf_id); if (ifp == NULL) return 0; @@ -254,11 +255,11 @@ ospf_interface_state_down (int command, struct zclient *zclient, static int ospf_interface_address_add (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct connected *c; - c = zebra_interface_address_read (command, zclient->ibuf); + c = zebra_interface_address_read (command, zclient->ibuf, vrf_id); if (c == NULL) return 0; @@ -281,7 +282,7 @@ ospf_interface_address_add (int command, struct zclient *zclient, static int ospf_interface_address_delete (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct connected *c; struct interface *ifp; @@ -289,7 +290,7 @@ ospf_interface_address_delete (int command, struct zclient *zclient, struct route_node *rn; struct prefix p; - c = zebra_interface_address_read (command, zclient->ibuf); + c = zebra_interface_address_read (command, zclient->ibuf, vrf_id); if (c == NULL) return 0; @@ -339,7 +340,10 @@ ospf_zebra_add (struct prefix_ipv4 *p, struct ospf_route *or) struct listnode *node; struct ospf *ospf = ospf_lookup (); - if (redist_check_instance(&zclient->redist[AFI_IP][ZEBRA_ROUTE_OSPF], ospf->instance)) + if ((ospf->instance && + redist_check_instance(&zclient->mi_redist[AFI_IP][ZEBRA_ROUTE_OSPF], ospf->instance)) + || + vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_OSPF], VRF_DEFAULT)) { message = 0; flags = 0; @@ -364,7 +368,7 @@ ospf_zebra_add (struct prefix_ipv4 *p, struct ospf_route *or) stream_reset (s); /* Put command, type, flags, message. */ - zclient_create_header (s, ZEBRA_IPV4_ROUTE_ADD); + zclient_create_header (s, ZEBRA_IPV4_ROUTE_ADD, VRF_DEFAULT); stream_putc (s, ZEBRA_ROUTE_OSPF); stream_putw (s, ospf->instance); stream_putc (s, flags); @@ -484,7 +488,10 @@ ospf_zebra_delete (struct prefix_ipv4 *p, struct ospf_route *or) struct listnode *node; struct ospf *ospf = ospf_lookup (); - if (redist_check_instance(&zclient->redist[AFI_IP][ZEBRA_ROUTE_OSPF], ospf->instance)) + if ((ospf->instance && + redist_check_instance(&zclient->mi_redist[AFI_IP][ZEBRA_ROUTE_OSPF], ospf->instance)) + || + vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_OSPF], VRF_DEFAULT)) { message = 0; flags = 0; @@ -495,7 +502,7 @@ ospf_zebra_delete (struct prefix_ipv4 *p, struct ospf_route *or) stream_reset (s); /* Put command, type, flags, message. */ - zclient_create_header (s, ZEBRA_IPV4_ROUTE_DELETE); + zclient_create_header (s, ZEBRA_IPV4_ROUTE_DELETE, VRF_DEFAULT); stream_putc (s, ZEBRA_ROUTE_OSPF); stream_putw (s, ospf->instance); stream_putc (s, flags); @@ -567,8 +574,12 @@ ospf_zebra_add_discard (struct prefix_ipv4 *p) struct zapi_ipv4 api; struct ospf *ospf = ospf_lookup (); - if (redist_check_instance(&zclient->redist[AFI_IP][ZEBRA_ROUTE_OSPF], ospf->instance)) + if ((ospf->instance && + redist_check_instance(&zclient->mi_redist[AFI_IP][ZEBRA_ROUTE_OSPF], ospf->instance)) + || + vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_OSPF], VRF_DEFAULT)) { + api.vrf_id = VRF_DEFAULT; api.type = ZEBRA_ROUTE_OSPF; api.instance = ospf->instance; api.flags = ZEBRA_FLAG_BLACKHOLE; @@ -593,8 +604,12 @@ ospf_zebra_delete_discard (struct prefix_ipv4 *p) struct zapi_ipv4 api; struct ospf *ospf = ospf_lookup (); - if (redist_check_instance(&zclient->redist[AFI_IP][ZEBRA_ROUTE_OSPF], ospf->instance)) + if ((ospf->instance && + redist_check_instance(&zclient->mi_redist[AFI_IP][ZEBRA_ROUTE_OSPF], ospf->instance)) + || + vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_OSPF], VRF_DEFAULT)) { + api.vrf_id = VRF_DEFAULT; api.type = ZEBRA_ROUTE_OSPF; api.instance = ospf->instance; api.flags = ZEBRA_FLAG_BLACKHOLE; @@ -741,8 +756,9 @@ int ospf_is_type_redistributed (int type, u_short instance) { return (DEFAULT_ROUTE_TYPE (type) ? - zclient->default_information : - redist_check_instance(&zclient->redist[AFI_IP][type], instance)); + vrf_bitmap_check (zclient->default_information, VRF_DEFAULT) : + ((instance && redist_check_instance(&zclient->mi_redist[AFI_IP][type], instance)) + || vrf_bitmap_check (zclient->redist[AFI_IP][type], VRF_DEFAULT))); } int @@ -782,7 +798,8 @@ ospf_redistribute_set (struct ospf *ospf, int type, u_short instance, int mtype, ospf_external_add(type, instance); - zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP, type, instance); + zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP, type, + instance, VRF_DEFAULT); if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) zlog_debug ("Redistribute[%s][%d]: Start Type[%d], Metric[%d]", @@ -803,7 +820,8 @@ ospf_redistribute_unset (struct ospf *ospf, int type, u_short instance) if (!ospf_is_type_redistributed (type, instance)) return CMD_SUCCESS; - zclient_redistribute (ZEBRA_REDISTRIBUTE_DELETE, zclient, AFI_IP, type, instance); + zclient_redistribute (ZEBRA_REDISTRIBUTE_DELETE, zclient, AFI_IP, type, + instance, VRF_DEFAULT); if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) zlog_debug ("Redistribute[%s][%d]: Stop", @@ -850,7 +868,8 @@ ospf_redistribute_default_set (struct ospf *ospf, int originate, return CMD_SUCCESS; } - zclient_redistribute_default (ZEBRA_REDISTRIBUTE_DEFAULT_ADD, zclient); + zclient_redistribute_default (ZEBRA_REDISTRIBUTE_DEFAULT_ADD, zclient, + VRF_DEFAULT); if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) zlog_debug ("Redistribute[DEFAULT]: Start Type[%d], Metric[%d]", @@ -876,7 +895,8 @@ ospf_redistribute_default_unset (struct ospf *ospf) ospf->default_originate = DEFAULT_ORIGINATE_NONE; ospf_redist_del(ospf, DEFAULT_ROUTE, 0); - zclient_redistribute_default (ZEBRA_REDISTRIBUTE_DEFAULT_DELETE, zclient); + zclient_redistribute_default (ZEBRA_REDISTRIBUTE_DEFAULT_DELETE, zclient, + VRF_DEFAULT); if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) zlog_debug ("Redistribute[DEFAULT]: Stop"); @@ -1015,7 +1035,7 @@ ospf_routemap_unset (struct ospf_redist *red) /* Zebra route add and delete treatment. */ static int ospf_zebra_read_ipv4 (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct stream *s; struct zapi_ipv4 api; @@ -1545,12 +1565,19 @@ ospf_distance_apply (struct prefix_ipv4 *p, struct ospf_route *or) return 0; } +static void +ospf_zebra_connected (struct zclient *zclient) +{ + zclient_send_requests (zclient, VRF_DEFAULT); +} + void ospf_zebra_init (struct thread_master *master, u_short instance) { /* Allocate zebra structure. */ zclient = zclient_new(master); zclient_init (zclient, ZEBRA_ROUTE_OSPF, instance); + zclient->zebra_connected = ospf_zebra_connected; zclient->router_id_update = ospf_router_id_update_zebra; zclient->interface_add = ospf_interface_add; zclient->interface_delete = ospf_interface_delete; diff --git a/ripd/rip_interface.c b/ripd/rip_interface.c index b12ce5ee10..c9fc40e815 100644 --- a/ripd/rip_interface.c +++ b/ripd/rip_interface.c @@ -380,7 +380,8 @@ if_check_address (struct in_addr addr) /* Inteface link down message processing. */ int -rip_interface_down (int command, struct zclient *zclient, zebra_size_t length) +rip_interface_down (int command, struct zclient *zclient, zebra_size_t length, + vrf_id_t vrf_id) { struct interface *ifp; struct stream *s; @@ -389,7 +390,7 @@ rip_interface_down (int command, struct zclient *zclient, zebra_size_t length) /* zebra_interface_state_read() updates interface structure in iflist. */ - ifp = zebra_interface_state_read(s); + ifp = zebra_interface_state_read (s, vrf_id); if (ifp == NULL) return 0; @@ -406,13 +407,14 @@ rip_interface_down (int command, struct zclient *zclient, zebra_size_t length) /* Inteface link up message processing */ int -rip_interface_up (int command, struct zclient *zclient, zebra_size_t length) +rip_interface_up (int command, struct zclient *zclient, zebra_size_t length, + vrf_id_t vrf_id) { struct interface *ifp; /* zebra_interface_state_read () updates interface structure in iflist. */ - ifp = zebra_interface_state_read (zclient->ibuf); + ifp = zebra_interface_state_read (zclient->ibuf, vrf_id); if (ifp == NULL) return 0; @@ -436,11 +438,12 @@ rip_interface_up (int command, struct zclient *zclient, zebra_size_t length) /* Inteface addition message from zebra. */ int -rip_interface_add (int command, struct zclient *zclient, zebra_size_t length) +rip_interface_add (int command, struct zclient *zclient, zebra_size_t length, + vrf_id_t vrf_id) { struct interface *ifp; - ifp = zebra_interface_add_read (zclient->ibuf); + ifp = zebra_interface_add_read (zclient->ibuf, vrf_id); if (IS_RIP_DEBUG_ZEBRA) zlog_debug ("interface add %s index %d flags %#llx metric %d mtu %d", @@ -466,7 +469,7 @@ rip_interface_add (int command, struct zclient *zclient, zebra_size_t length) int rip_interface_delete (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct interface *ifp; struct stream *s; @@ -474,7 +477,7 @@ rip_interface_delete (int command, struct zclient *zclient, s = zclient->ibuf; /* zebra_interface_state_read() updates interface structure in iflist */ - ifp = zebra_interface_state_read(s); + ifp = zebra_interface_state_read (s, vrf_id); if (ifp == NULL) return 0; @@ -666,13 +669,13 @@ rip_apply_address_add (struct connected *ifc) int rip_interface_address_add (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct connected *ifc; struct prefix *p; ifc = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, - zclient->ibuf); + zclient->ibuf, vrf_id); if (ifc == NULL) return 0; @@ -722,13 +725,13 @@ rip_apply_address_del (struct connected *ifc) { int rip_interface_address_delete (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct connected *ifc; struct prefix *p; ifc = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE, - zclient->ibuf); + zclient->ibuf, vrf_id); if (ifc) { diff --git a/ripd/rip_interface.h b/ripd/rip_interface.h index 8926cce7b7..d9dfbb7cc3 100644 --- a/ripd/rip_interface.h +++ b/ripd/rip_interface.h @@ -21,11 +21,17 @@ #ifndef _QUAGGA_RIP_INTERFACE_H #define _QUAGGA_RIP_INTERFACE_H -extern int rip_interface_down (int , struct zclient *, zebra_size_t); -extern int rip_interface_up (int , struct zclient *, zebra_size_t); -extern int rip_interface_add (int , struct zclient *, zebra_size_t); -extern int rip_interface_delete (int , struct zclient *, zebra_size_t); -extern int rip_interface_address_add (int , struct zclient *, zebra_size_t); -extern int rip_interface_address_delete (int , struct zclient *, zebra_size_t); +extern int rip_interface_down (int , struct zclient *, zebra_size_t, + vrf_id_t); +extern int rip_interface_up (int , struct zclient *, zebra_size_t, + vrf_id_t); +extern int rip_interface_add (int , struct zclient *, zebra_size_t, + vrf_id_t); +extern int rip_interface_delete (int , struct zclient *, zebra_size_t, + vrf_id_t); +extern int rip_interface_address_add (int , struct zclient *, zebra_size_t, + vrf_id_t); +extern int rip_interface_address_delete (int , struct zclient *, zebra_size_t, + vrf_id_t); #endif /* _QUAGGA_RIP_INTERFACE_H */ diff --git a/ripd/rip_zebra.c b/ripd/rip_zebra.c index a5cc8260db..245cb66c47 100644 --- a/ripd/rip_zebra.c +++ b/ripd/rip_zebra.c @@ -27,6 +27,7 @@ #include "routemap.h" #include "zclient.h" #include "log.h" +#include "vrf.h" #include "ripd/ripd.h" #include "ripd/rip_debug.h" #include "ripd/rip_interface.h" @@ -41,8 +42,9 @@ rip_zebra_ipv4_add (struct prefix_ipv4 *p, struct in_addr *nexthop, { struct zapi_ipv4 api; - if (zclient->redist[AFI_IP][ZEBRA_ROUTE_RIP].enabled) + if (vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_RIP], VRF_DEFAULT)) { + api.vrf_id = VRF_DEFAULT; api.type = ZEBRA_ROUTE_RIP; api.instance = 0; api.flags = 0; @@ -73,7 +75,7 @@ rip_zebra_ipv4_delete (struct prefix_ipv4 *p, struct in_addr *nexthop, { struct zapi_ipv4 api; - if (zclient->redist[AFI_IP][ZEBRA_ROUTE_RIP].enabled) + if (vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_RIP], VRF_DEFAULT)) { api.type = ZEBRA_ROUTE_RIP; api.instance = 0; @@ -95,7 +97,8 @@ rip_zebra_ipv4_delete (struct prefix_ipv4 *p, struct in_addr *nexthop, /* Zebra route add and delete treatment. */ static int -rip_zebra_read_ipv4 (int command, struct zclient *zclient, zebra_size_t length) +rip_zebra_read_ipv4 (int command, struct zclient *zclient, zebra_size_t length, + vrf_id_t vrf_id) { struct stream *s; struct zapi_ipv4 api; @@ -243,10 +246,10 @@ DEFUN (no_router_zebra, static int rip_redistribute_set (int type) { - if (zclient->redist[AFI_IP][type]) + if (vrf_bitmap_check (zclient->redist[AFI_IP][type], VRF_DEFAULT)) return CMD_SUCCESS; - zclient->redist[AFI_IP][type] = 1; + vrf_bitmap_set (zclient->redist[AFI_IP][type], VRF_DEFAULT); if (zclient->sock > 0) zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, API_IP, type); @@ -258,13 +261,13 @@ rip_redistribute_set (int type) static int rip_redistribute_unset (int type) { - if (! zclient->redist[AFI_IP][type].enabled) + if (! vrf_bitmap_check (zclient->redist[AFI_IP][type], VRF_DEFAULT)) return CMD_SUCCESS; - redist_del_instance(&zclient->redist[AFI_IP][type], 0); + vrf_bitmap_unset (zclient->redist[AFI_IP][type], VRF_DEFAULT); if (zclient->sock > 0) - zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, AFI_IP, type, 0); + zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, AFI_IP, type, 0, VRF_DEFAULT); /* Remove the routes from RIP table. */ rip_redistribute_withdraw (type); @@ -275,7 +278,7 @@ rip_redistribute_unset (int type) int rip_redistribute_check (int type) { - return (zclient->redist[AFI_IP][type].enabled); + return vrf_bitmap_check (zclient->redist[AFI_IP][type], VRF_DEFAULT); } void @@ -285,13 +288,14 @@ rip_redistribute_clean (void) for (i = 0; redist_type[i].str; i++) { - if (zclient->redist[AFI_IP][redist_type[i].type].enabled) + if (vrf_bitmap_check (zclient->redist[AFI_IP][redist_type[i].type], VRF_DEFAULT)) { if (zclient->sock > 0) zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, - zclient, AFI_IP, redist_type[i].type, 0); + zclient, AFI_IP, redist_type[i].type, 0, + VRF_DEFAULT); - redist_del_instance(&zclient->redist[AFI_IP][redist_type[i].type], 0); + vrf_bitmap_unset (zclient->redist[AFI_IP][redist_type[i].type], VRF_DEFAULT); /* Remove the routes from RIP table. */ rip_redistribute_withdraw (redist_type[i].type); @@ -305,7 +309,7 @@ DEFUN (rip_redistribute_rip, "Redistribute information from another routing protocol\n" "Routing Information Protocol (RIP)\n") { - redist_add_instance(&zclient->redist[AFI_IP][ZEBRA_ROUTE_RIP], 0); + vrf_bitmap_set (zclient->redist[AFI_IP][ZEBRA_ROUTE_RIP], VRF_DEFAULT); return CMD_SUCCESS; } @@ -316,7 +320,7 @@ DEFUN (no_rip_redistribute_rip, "Redistribute information from another routing protocol\n" "Routing Information Protocol (RIP)\n") { - redist_del_instance(&zclient->redist[AFI_IP][ZEBRA_ROUTE_RIP], 0); + vrf_bitmap_unset (zclient->redist[AFI_IP][ZEBRA_ROUTE_RIP], VRF_DEFAULT); return CMD_SUCCESS; } @@ -334,7 +338,7 @@ DEFUN (rip_redistribute_type, redist_type[i].str_min_len) == 0) { zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, - AFI_IP, redist_type[i].type, 0); + AFI_IP, redist_type[i].type, 0, VRF_DEFAULT); return CMD_SUCCESS; } } @@ -388,7 +392,7 @@ DEFUN (rip_redistribute_type_routemap, { rip_routemap_set (redist_type[i].type, argv[1]); zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP, - redist_type[i].type, 0); + redist_type[i].type, 0, VRF_DEFAULT); return CMD_SUCCESS; } } @@ -447,7 +451,7 @@ DEFUN (rip_redistribute_type_metric, { rip_redistribute_metric_set (redist_type[i].type, metric); zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP, - redist_type[i].type, 0); + redist_type[i].type, 0, VRF_DEFAULT); return CMD_SUCCESS; } } @@ -509,7 +513,7 @@ DEFUN (rip_redistribute_type_metric_routemap, rip_redistribute_metric_set (redist_type[i].type, metric); rip_routemap_set (redist_type[i].type, argv[2]); zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP, - redist_type[i].type, 0); + redist_type[i].type, 0, VRF_DEFAULT); return CMD_SUCCESS; } } @@ -613,7 +617,7 @@ config_write_zebra (struct vty *vty) vty_out (vty, "no router zebra%s", VTY_NEWLINE); return 1; } - else if (! zclient->redist[AFI_IP][ZEBRA_ROUTE_RIP].enabled) + else if (! vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_RIP], VRF_DEFAULT)) { vty_out (vty, "router zebra%s", VTY_NEWLINE); vty_out (vty, " no redistribute rip%s", VTY_NEWLINE); @@ -629,7 +633,7 @@ config_write_rip_redistribute (struct vty *vty, int config_mode) for (i = 0; i < ZEBRA_ROUTE_MAX; i++) if (i != zclient->redist_default && - zclient->redist[AFI_IP][i].enabled) + vrf_bitmap_check (zclient->redist[AFI_IP][i], VRF_DEFAULT)) { if (config_mode) { @@ -669,12 +673,19 @@ static struct cmd_node zebra_node = "%s(config-router)# ", }; +static void +rip_zebra_connected (struct zclient *zclient) +{ + zclient_send_requests (zclient, VRF_DEFAULT); +} + void rip_zclient_init (struct thread_master *master) { /* Set default value to the zebra client structure. */ zclient = zclient_new(master); zclient_init (zclient, ZEBRA_ROUTE_RIP, 0); + zclient->zebra_connected = rip_zebra_connected; zclient->interface_add = rip_interface_add; zclient->interface_delete = rip_interface_delete; zclient->interface_address_add = rip_interface_address_add; diff --git a/ripngd/ripng_interface.c b/ripngd/ripng_interface.c index 3f9f025975..3b3c377c81 100644 --- a/ripngd/ripng_interface.c +++ b/ripngd/ripng_interface.c @@ -215,14 +215,15 @@ ripng_if_down (struct interface *ifp) /* Inteface link up message processing. */ int -ripng_interface_up (int command, struct zclient *zclient, zebra_size_t length) +ripng_interface_up (int command, struct zclient *zclient, zebra_size_t length, + vrf_id_t vrf_id) { struct stream *s; struct interface *ifp; /* zebra_interface_state_read() updates interface structure in iflist. */ s = zclient->ibuf; - ifp = zebra_interface_state_read (s); + ifp = zebra_interface_state_read (s, vrf_id); if (ifp == NULL) return 0; @@ -247,14 +248,14 @@ ripng_interface_up (int command, struct zclient *zclient, zebra_size_t length) /* Inteface link down message processing. */ int ripng_interface_down (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct stream *s; struct interface *ifp; /* zebra_interface_state_read() updates interface structure in iflist. */ s = zclient->ibuf; - ifp = zebra_interface_state_read (s); + ifp = zebra_interface_state_read (s, vrf_id); if (ifp == NULL) return 0; @@ -271,11 +272,12 @@ ripng_interface_down (int command, struct zclient *zclient, /* Inteface addition message from zebra. */ int -ripng_interface_add (int command, struct zclient *zclient, zebra_size_t length) +ripng_interface_add (int command, struct zclient *zclient, zebra_size_t length, + vrf_id_t vrf_id) { struct interface *ifp; - ifp = zebra_interface_add_read (zclient->ibuf); + ifp = zebra_interface_add_read (zclient->ibuf, vrf_id); if (IS_RIPNG_DEBUG_ZEBRA) zlog_debug ("RIPng interface add %s index %d flags %#llx metric %d mtu %d", @@ -296,14 +298,14 @@ ripng_interface_add (int command, struct zclient *zclient, zebra_size_t length) int ripng_interface_delete (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct interface *ifp; struct stream *s; s = zclient->ibuf; /* zebra_interface_state_read() updates interface structure in iflist */ - ifp = zebra_interface_state_read(s); + ifp = zebra_interface_state_read (s, vrf_id); if (ifp == NULL) return 0; @@ -410,13 +412,13 @@ ripng_apply_address_add (struct connected *ifc) { int ripng_interface_address_add (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct connected *c; struct prefix *p; c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, - zclient->ibuf); + zclient->ibuf, vrf_id); if (c == NULL) return 0; @@ -477,14 +479,14 @@ ripng_apply_address_del (struct connected *ifc) { int ripng_interface_address_delete (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct connected *ifc; struct prefix *p; char buf[INET6_ADDRSTRLEN]; ifc = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE, - zclient->ibuf); + zclient->ibuf, vrf_id); if (ifc) { diff --git a/ripngd/ripng_zebra.c b/ripngd/ripng_zebra.c index 278ca76715..e83e36bf26 100644 --- a/ripngd/ripng_zebra.c +++ b/ripngd/ripng_zebra.c @@ -34,22 +34,15 @@ /* All information about zebra. */ struct zclient *zclient = NULL; -/* Callback prototypes for zebra client service. */ -int ripng_interface_up (int, struct zclient *, zebra_size_t); -int ripng_interface_down (int, struct zclient *, zebra_size_t); -int ripng_interface_add (int, struct zclient *, zebra_size_t); -int ripng_interface_delete (int, struct zclient *, zebra_size_t); -int ripng_interface_address_add (int, struct zclient *, zebra_size_t); -int ripng_interface_address_delete (int, struct zclient *, zebra_size_t); - void ripng_zebra_ipv6_add (struct prefix_ipv6 *p, struct in6_addr *nexthop, unsigned int ifindex, u_char metric) { struct zapi_ipv6 api; - if (zclient->redist[AFI_IP6][ZEBRA_ROUTE_RIPNG].enabled) + if (vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_RIPNG], VRF_DEFAULT)) { + api.vrf_id = VRF_DEFAULT; api.type = ZEBRA_ROUTE_RIPNG; api.instance = 0; api.flags = 0; @@ -74,7 +67,7 @@ ripng_zebra_ipv6_delete (struct prefix_ipv6 *p, struct in6_addr *nexthop, { struct zapi_ipv6 api; - if (zclient->redist[AFI_IP6][ZEBRA_ROUTE_RIPNG].enabled) + if (vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_RIPNG], VRF_DEFAULT)) { api.type = ZEBRA_ROUTE_RIPNG; api.instance = 0; @@ -95,7 +88,7 @@ ripng_zebra_ipv6_delete (struct prefix_ipv6 *p, struct in6_addr *nexthop, /* Zebra route add and delete treatment. */ static int ripng_zebra_read_ipv6 (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct stream *s; struct zapi_ipv6 api; @@ -156,13 +149,14 @@ ripng_zclient_reset (void) static int ripng_redistribute_unset (int type) { - if (! zclient->redist[AFI_IP6][type].enabled) + + if (! vrf_bitmap_check (zclient->redist[AFI_IP6][type], VRF_DEFAULT)) return CMD_SUCCESS; - redist_del_instance(&zclient->redist[AFI_IP6][type], 0); + vrf_bitmap_set (zclient->redist[AFI_IP6][type], VRF_DEFAULT); if (zclient->sock > 0) - zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, AFI_IP6, type, 0); + zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, AFI_IP6, type, 0, VRF_DEFAULT); ripng_redistribute_withdraw (type); @@ -172,7 +166,7 @@ ripng_redistribute_unset (int type) int ripng_redistribute_check (int type) { - return (zclient->redist[AFI_IP6][type].enabled); + return vrf_bitmap_check (zclient->redist[AFI_IP6][type], VRF_DEFAULT); } static void @@ -232,13 +226,14 @@ ripng_redistribute_clean () for (i = 0; redist_type[i].str; i++) { - if (zclient->redist[AFI_IP6][redist_type[i].type].enabled) + if (vrf_bitmap_check (zclient->redist[AFI_IP6][redist_type[i].type], VRF_DEFAULT)) { if (zclient->sock > 0) zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, - zclient, AFI_IP6, redist_type[i].type, 0); + zclient, AFI_IP6, redist_type[i].type, 0, + VRF_DEFAULT); - redist_del_instance(&zclient->redist[AFI_IP6][redist_type[i].type], 0); + vrf_bitmap_unset (zclient->redist[AFI_IP6][redist_type[i].type], VRF_DEFAULT); /* Remove the routes from RIPng table. */ ripng_redistribute_withdraw (redist_type[i].type); @@ -276,7 +271,7 @@ DEFUN (ripng_redistribute_ripng, "Redistribute information from another routing protocol\n" "RIPng route\n") { - redist_add_instance(&zclient->redist[AFI_IP6][ZEBRA_ROUTE_RIPNG], 0); + vrf_bitmap_set (zclient->redist[AFI_IP6][ZEBRA_ROUTE_RIPNG], VRF_DEFAULT); return CMD_SUCCESS; } @@ -287,7 +282,7 @@ DEFUN (no_ripng_redistribute_ripng, "Redistribute information from another routing protocol\n" "RIPng route\n") { - redist_del_instance(&zclient->redist[AFI_IP6][ZEBRA_ROUTE_RIPNG], 0); + vrf_bitmap_unset (zclient->redist[AFI_IP6][ZEBRA_ROUTE_RIPNG], VRF_DEFAULT); return CMD_SUCCESS; } @@ -307,7 +302,7 @@ DEFUN (ripng_redistribute_type, return CMD_WARNING; } - zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP6, type, 0); + zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP6, type, 0, VRF_DEFAULT); return CMD_SUCCESS; } @@ -355,7 +350,8 @@ DEFUN (ripng_redistribute_type_metric, } ripng_redistribute_metric_set (type, metric); - zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP6, type, 0); + zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP6, type, 0, + VRF_DEFAULT); return CMD_SUCCESS; } @@ -387,7 +383,8 @@ DEFUN (ripng_redistribute_type_routemap, } ripng_redistribute_routemap_set (type, argv[1]); - zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP6, type, 0); + zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP6, type, 0, + VRF_DEFAULT); return CMD_SUCCESS; } @@ -424,7 +421,7 @@ DEFUN (ripng_redistribute_type_metric_routemap, ripng_redistribute_metric_set (type, metric); ripng_redistribute_routemap_set (type, argv[2]); - zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP6, type, 0); + zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP6, type, 0, VRF_DEFAULT); return CMD_SUCCESS; } @@ -444,7 +441,7 @@ ripng_redistribute_write (struct vty *vty, int config_mode) for (i = 0; i < ZEBRA_ROUTE_MAX; i++) if (i != zclient->redist_default && - zclient->redist[AFI_IP6][i].enabled) + vrf_bitmap_check (zclient->redist[AFI_IP6][i], VRF_DEFAULT)) { if (config_mode) { @@ -484,7 +481,7 @@ zebra_config_write (struct vty *vty) vty_out (vty, "no router zebra%s", VTY_NEWLINE); return 1; } - else if (! zclient->redist[AFI_IP6][ZEBRA_ROUTE_RIPNG].enabled) + else if (! vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_RIPNG], VRF_DEFAULT)) { vty_out (vty, "router zebra%s", VTY_NEWLINE); vty_out (vty, " no redistribute ripng%s", VTY_NEWLINE); @@ -500,6 +497,12 @@ static struct cmd_node zebra_node = "%s(config-router)# ", }; +static void +ripng_zebra_connected (struct zclient *zclient) +{ + zclient_send_requests (zclient, VRF_DEFAULT); +} + /* Initialize zebra structure and it's commands. */ void zebra_init (struct thread_master *master) @@ -508,6 +511,7 @@ zebra_init (struct thread_master *master) zclient = zclient_new(master); zclient_init (zclient, ZEBRA_ROUTE_RIPNG, 0); + zclient->zebra_connected = ripng_zebra_connected; zclient->interface_up = ripng_interface_up; zclient->interface_down = ripng_interface_down; zclient->interface_add = ripng_interface_add; diff --git a/ripngd/ripngd.h b/ripngd/ripngd.h index 884f3ed9bb..9a82d82288 100644 --- a/ripngd/ripngd.h +++ b/ripngd/ripngd.h @@ -409,12 +409,18 @@ extern int ripng_send_packet (caddr_t buf, int bufsize, extern void ripng_packet_dump (struct ripng_packet *packet, int size, const char *sndrcv); -extern int ripng_interface_up (int command, struct zclient *, zebra_size_t); -extern int ripng_interface_down (int command, struct zclient *, zebra_size_t); -extern int ripng_interface_add (int command, struct zclient *, zebra_size_t); -extern int ripng_interface_delete (int command, struct zclient *, zebra_size_t); -extern int ripng_interface_address_add (int command, struct zclient *, zebra_size_t); -extern int ripng_interface_address_delete (int command, struct zclient *, zebra_size_t); +extern int ripng_interface_up (int command, struct zclient *, zebra_size_t, + vrf_id_t); +extern int ripng_interface_down (int command, struct zclient *, zebra_size_t, + vrf_id_t); +extern int ripng_interface_add (int command, struct zclient *, zebra_size_t, + vrf_id_t); +extern int ripng_interface_delete (int command, struct zclient *, zebra_size_t, + vrf_id_t); +extern int ripng_interface_address_add (int command, struct zclient *, zebra_size_t, + vrf_id_t); +extern int ripng_interface_address_delete (int command, struct zclient *, zebra_size_t, + vrf_id_t); extern int ripng_network_write (struct vty *, int); diff --git a/zebra/client_main.c b/zebra/client_main.c index cc69ef761b..06307936e8 100644 --- a/zebra/client_main.c +++ b/zebra/client_main.c @@ -54,6 +54,7 @@ zebra_test_ipv4 (int command, int type, char *prefix, char *gateway, inet_aton (gateway, &gate); gpnt = &gate; + api.vrf_id = VRF_DEFAULT; api.type = type; api.flags = 0; diff --git a/zebra/if_sysctl.c b/zebra/if_sysctl.c index e7b25d1f8f..3e23954dcd 100644 --- a/zebra/if_sysctl.c +++ b/zebra/if_sysctl.c @@ -29,11 +29,8 @@ #include "memory.h" #include "ioctl.h" #include "log.h" -<<<<<<< HEAD -======= #include "interface.h" #include "vrf.h" ->>>>>>> 3c27b5f... zebra, lib/memtypes.c: the netlink sockets work per VRF #include "zebra/rt.h" #include "zebra/kernel_socket.h" diff --git a/zebra/redistribute.c b/zebra/redistribute.c index 01b85700f2..a17b9a8c09 100644 --- a/zebra/redistribute.c +++ b/zebra/redistribute.c @@ -63,7 +63,7 @@ is_zebra_import_table_enabled(afi_t afi, u_int32_t table_id) return 0; } -static int +int is_default (struct prefix *p) { if (p->family == AF_INET) @@ -81,7 +81,7 @@ is_default (struct prefix *p) } static void -zebra_redistribute_default (struct zserv *client) +zebra_redistribute_default (struct zserv *client, vrf_id_t vrf_id) { struct prefix_ipv4 p; struct route_table *table; @@ -97,7 +97,7 @@ zebra_redistribute_default (struct zserv *client) p.family = AF_INET; /* Lookup table. */ - table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT); + table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id); if (table) { rn = route_node_lookup (table, (struct prefix *)&p); @@ -117,7 +117,7 @@ zebra_redistribute_default (struct zserv *client) p6.family = AF_INET6; /* Lookup table. */ - table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT); + table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id); if (table) { rn = route_node_lookup (table, (struct prefix *)&p6); @@ -135,13 +135,13 @@ zebra_redistribute_default (struct zserv *client) /* Redistribute routes. */ static void -zebra_redistribute (struct zserv *client, int type, u_short instance) +zebra_redistribute (struct zserv *client, int type, u_short instance, vrf_id_t vrf_id) { struct rib *newrib; struct route_table *table; struct route_node *rn; - table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT); + table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id); if (table) for (rn = route_top (table); rn; rn = route_next (rn)) RNODE_FOREACH_RIB (rn, newrib) @@ -156,7 +156,7 @@ zebra_redistribute (struct zserv *client, int type, u_short instance) } #ifdef HAVE_IPV6 - table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT); + table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id); if (table) for (rn = route_top (table); rn; rn = route_next (rn)) RNODE_FOREACH_RIB (rn, newrib) @@ -196,9 +196,14 @@ redistribute_update (struct prefix *p, struct rib *rib, struct rib *prev_rib) if (is_default(p) && client->redist_default) send_redistribute = 1; - if (redist_check_instance(&client->redist[afi][rib->type], - rib->instance)) - send_redistribute = 1; + if (rib->instance && redist_check_instance(&client->mi_redist[afi][rib->type], + rib->instance)) + send_redistribute = 1; + else + if ((is_default (p) && + vrf_bitmap_check (client->redist_default, rib->vrf_id)) + || vrf_bitmap_check (client->redist[afi][rib->type], rib->vrf_id)) + send_redistribute = 1; if (send_redistribute) { @@ -220,8 +225,10 @@ redistribute_update (struct prefix *p, struct rib *rib, struct rib *prev_rib) } } else if (prev_rib && - redist_check_instance(&client->redist[afi][prev_rib->type], - rib->instance)) + ((rib->instance && + redist_check_instance(&client->mi_redist[afi][prev_rib->type], + rib->instance)) || + vrf_bitmap_check (client->redist[afi][prev_rib->type], rib->vrf_id))) { switch (afi) { @@ -257,16 +264,20 @@ redistribute_delete (struct prefix *p, struct rib *rib) if (is_default (p)) { if ((p->family == AF_INET) && - (client->redist_default || - redist_check_instance(&client->redist[AFI_IP][rib->type], - rib->instance))) + (vrf_bitmap_check (client->redist_default, rib->vrf_id) || + (rib->instance && + redist_check_instance(&client->mi_redist[AFI_IP][rib->type], + rib->instance)) || + vrf_bitmap_check (client->redist[AFI_IP][rib->type], rib->vrf_id))) zsend_redistribute_route (ZEBRA_REDISTRIBUTE_IPV4_DEL, client, p, rib); #ifdef HAVE_IPV6 if ((p->family == AF_INET6) && - (client->redist_default || - redist_check_instance(&client->redist[AFI_IP6][rib->type], - rib->instance))) + (vrf_bitmap_check (client->redist_default, rib->vrf_id) || + (rib->instance && + redist_check_instance(&client->mi_redist[AFI_IP6][rib->type], + rib->instance)) || + vrf_bitmap_check (client->redist[AFI_IP6][rib->type], rib->vrf_id))) zsend_redistribute_route (ZEBRA_REDISTRIBUTE_IPV6_DEL, client, p, rib); #endif /* HAVE_IPV6 */ @@ -274,14 +285,18 @@ redistribute_delete (struct prefix *p, struct rib *rib) else { if ((p->family == AF_INET) && - redist_check_instance(&client->redist[AFI_IP][rib->type], - rib->instance)) + ((rib->instance && + redist_check_instance(&client->mi_redist[AFI_IP][rib->type], + rib->instance)) || + vrf_bitmap_check (client->redist[AFI_IP][rib->type], rib->vrf_id))) zsend_redistribute_route (ZEBRA_REDISTRIBUTE_IPV4_DEL, client, p, rib); #ifdef HAVE_IPV6 if ((p->family == AF_INET6) && - redist_check_instance(&client->redist[AFI_IP6][rib->type], - rib->instance)) + ((rib->instance && + redist_check_instance(&client->mi_redist[AFI_IP6][rib->type], + rib->instance)) || + vrf_bitmap_check (client->redist[AFI_IP6][rib->type], rib->vrf_id))) zsend_redistribute_route (ZEBRA_REDISTRIBUTE_IPV6_DEL, client, p, rib); #endif /* HAVE_IPV6 */ @@ -290,7 +305,8 @@ redistribute_delete (struct prefix *p, struct rib *rib) } void -zebra_redistribute_add (int command, struct zserv *client, int length) +zebra_redistribute_add (int command, struct zserv *client, int length, + vrf_id_t vrf_id) { afi_t afi; int type; @@ -303,15 +319,22 @@ zebra_redistribute_add (int command, struct zserv *client, int length) if (type == 0 || type >= ZEBRA_ROUTE_MAX) return; - if (!redist_check_instance(&client->redist[afi][type], instance)) + if (instance && !redist_check_instance(&client->mi_redist[afi][type], instance)) { - redist_add_instance(&client->redist[afi][type], instance); - zebra_redistribute (client, type, instance); + redist_add_instance(&client->mi_redist[afi][type], instance); + zebra_redistribute (client, type, instance, vrf_id); } + else + if (! vrf_bitmap_check (client->redist[afi][type], vrf_id)) + { + vrf_bitmap_set (client->redist[afi][type], vrf_id); + zebra_redistribute (client, type, 0, vrf_id); + } } void -zebra_redistribute_delete (int command, struct zserv *client, int length) +zebra_redistribute_delete (int command, struct zserv *client, int length, + vrf_id_t vrf_id) { afi_t afi; int type; @@ -324,25 +347,27 @@ zebra_redistribute_delete (int command, struct zserv *client, int length) if (type == 0 || type >= ZEBRA_ROUTE_MAX) return; - if (redist_check_instance(&client->redist[afi][type], instance)) + if (instance && redist_check_instance(&client->mi_redist[afi][type], instance)) { - redist_del_instance(&client->redist[afi][type], instance); + redist_del_instance(&client->mi_redist[afi][type], instance); //Pending: why no reaction here? } + vrf_bitmap_unset (client->redist[afi][type], vrf_id); } void -zebra_redistribute_default_add (int command, struct zserv *client, int length) +zebra_redistribute_default_add (int command, struct zserv *client, int length, + vrf_id_t vrf_id) { - client->redist_default = 1; - zebra_redistribute_default (client); + vrf_bitmap_set (client->redist_default, vrf_id); + zebra_redistribute_default (client, vrf_id); } void zebra_redistribute_default_delete (int command, struct zserv *client, - int length) + int length, vrf_id_t vrf_id) { - client->redist_default = 0;; + vrf_bitmap_unset (client->redist_default, vrf_id); } /* Interface up information. */ diff --git a/zebra/redistribute.h b/zebra/redistribute.h index 5bd4275155..833aa0e5d4 100644 --- a/zebra/redistribute.h +++ b/zebra/redistribute.h @@ -27,11 +27,13 @@ #include "zserv.h" #include "vty.h" -extern void zebra_redistribute_add (int, struct zserv *, int); -extern void zebra_redistribute_delete (int, struct zserv *, int); +extern void zebra_redistribute_add (int, struct zserv *, int, vrf_id_t); +extern void zebra_redistribute_delete (int, struct zserv *, int, vrf_id_t); -extern void zebra_redistribute_default_add (int, struct zserv *, int); -extern void zebra_redistribute_default_delete (int, struct zserv *, int); +extern void zebra_redistribute_default_add (int, struct zserv *, int, + vrf_id_t); +extern void zebra_redistribute_default_delete (int, struct zserv *, int, + vrf_id_t); extern void redistribute_update (struct prefix *, struct rib *, struct rib *); extern void redistribute_delete (struct prefix *, struct rib *); @@ -57,5 +59,7 @@ extern int is_zebra_import_table_enabled(afi_t, u_int32_t table_id); extern int zebra_import_table_config(struct vty *); +extern int is_default (struct prefix *); + #endif /* _ZEBRA_REDISTRIBUTE_H */ diff --git a/zebra/redistribute_null.c b/zebra/redistribute_null.c index 3fd97a754f..c491c2baa7 100644 --- a/zebra/redistribute_null.c +++ b/zebra/redistribute_null.c @@ -4,18 +4,22 @@ #include "zebra/redistribute.h" -void zebra_redistribute_add (int a, struct zserv *b, int c) +void zebra_redistribute_add (int a, struct zserv *b, int c, + vrf_id_t vrf_id) { return; } #ifdef HAVE_SYS_WEAK_ALIAS_PRAGMA #pragma weak zebra_redistribute_delete = zebra_redistribute_add #pragma weak zebra_redistribute_default_add = zebra_redistribute_add #pragma weak zebra_redistribute_default_delete = zebra_redistribute_add #else -void zebra_redistribute_delete (int a, struct zserv *b, int c) +void zebra_redistribute_delete (int a, struct zserv *b, int c, + vrf_id_t vrf_id) { return; } -void zebra_redistribute_default_add (int a, struct zserv *b, int c) +void zebra_redistribute_default_add (int a, struct zserv *b, int c, + vrf_id_t vrf_id) { return; } -void zebra_redistribute_default_delete (int a, struct zserv *b, int c) +void zebra_redistribute_default_delete (int a, struct zserv *b, int c, + vrf_id_t vrf_id) { return; } #endif diff --git a/zebra/zebra_ptm_redistribute.c b/zebra/zebra_ptm_redistribute.c index 1a81c79857..741eeb8eb3 100644 --- a/zebra/zebra_ptm_redistribute.c +++ b/zebra/zebra_ptm_redistribute.c @@ -44,7 +44,7 @@ zsend_interface_bfd_update (int cmd, struct zserv *client, s = client->obuf; stream_reset (s); - zserv_create_header (s, cmd); + zserv_create_header (s, cmd, (ifp ? ifp->vrf_id : VRF_DEFAULT)); if (ifp) stream_putl (s, ifp->ifindex); else @@ -100,7 +100,7 @@ zsend_bfd_peer_replay (int cmd, struct zserv *client) s = client->obuf; stream_reset (s); - zserv_create_header (s, cmd); + zserv_create_header (s, cmd, VRF_DEFAULT); //Pending: /* Write packet size. */ stream_putw_at (s, 0, stream_get_endp (s)); diff --git a/zebra/zebra_rnh.c b/zebra/zebra_rnh.c index 09d2947c4e..76b038d1b9 100644 --- a/zebra/zebra_rnh.c +++ b/zebra/zebra_rnh.c @@ -62,7 +62,8 @@ static void copy_state(struct rnh *rnh, struct rib *rib, }) static int compare_state(struct rib *r1, struct rib *r2); -static int send_client(struct rnh *rnh, struct zserv *client, rnh_type_t type); +static int send_client(struct rnh *rnh, struct zserv *client, rnh_type_t type, + vrf_id_t vrf_id); static void print_rnh(struct route_node *rn, struct vty *vty); int zebra_rnh_ip_default_route = 0; @@ -182,7 +183,8 @@ zebra_delete_rnh (struct rnh *rnh, rnh_type_t type) } void -zebra_add_rnh_client (struct rnh *rnh, struct zserv *client, rnh_type_t type) +zebra_add_rnh_client (struct rnh *rnh, struct zserv *client, rnh_type_t type, + vrf_id_t vrf_id) { if (IS_ZEBRA_DEBUG_NHT) { @@ -194,6 +196,7 @@ zebra_add_rnh_client (struct rnh *rnh, struct zserv *client, rnh_type_t type) if (!listnode_lookup(rnh->client_list, client)) { listnode_add(rnh->client_list, client); + send_client(rnh, client, type, vrf_id); // Pending: check if its needed } } @@ -393,7 +396,7 @@ zebra_evaluate_rnh (vrf_id_t vrfid, int family, int force, rnh_type_t type, /* state changed, notify clients */ for (ALL_LIST_ELEMENTS_RO(rnh->client_list, node, client)) { - send_client(rnh, client, RNH_IMPORT_CHECK_TYPE); + send_client(rnh, client, RNH_IMPORT_CHECK_TYPE, vrfid); } } @@ -466,7 +469,7 @@ zebra_evaluate_rnh (vrf_id_t vrfid, int family, int force, rnh_type_t type, at_least_one ? "":"(filtered)", bufn, bufp, rib ? "reachable" : "unreachable"); - send_client(rnh, client, RNH_NEXTHOP_TYPE); /* Route-map passed */ + send_client(rnh, client, RNH_NEXTHOP_TYPE, vrfid); /* Route-map passed */ } /* Now evaluate static client */ @@ -568,14 +571,14 @@ zebra_evaluate_rnh (vrf_id_t vrfid, int family, int force, rnh_type_t type, } int -zebra_dispatch_rnh_table (vrf_id_t vrfid, int family, struct zserv *client, +zebra_dispatch_rnh_table (vrf_id_t vrf_id, int family, struct zserv *client, rnh_type_t type) { struct route_table *ntable; struct route_node *nrn; struct rnh *rnh; - ntable = get_rnh_table(vrfid, family, type); + ntable = get_rnh_table(vrf_id, family, type); if (!ntable) { zlog_debug("dispatch_rnh_table: rnh table not found\n"); @@ -596,7 +599,7 @@ zebra_dispatch_rnh_table (vrf_id_t vrfid, int family, struct zserv *client, rnh->state ? "reachable" : "unreachable", zebra_route_string(client->proto)); } - send_client(rnh, client, RNH_NEXTHOP_TYPE); + send_client(rnh, client, RNH_NEXTHOP_TYPE, vrf_id); } return 1; } @@ -714,7 +717,7 @@ compare_state (struct rib *r1, struct rib *r2) } static int -send_client (struct rnh *rnh, struct zserv *client, rnh_type_t type) +send_client (struct rnh *rnh, struct zserv *client, rnh_type_t type, vrf_id_t vrf_id) { struct stream *s; struct rib *rib; @@ -732,7 +735,8 @@ send_client (struct rnh *rnh, struct zserv *client, rnh_type_t type) s = client->obuf; stream_reset (s); - zserv_create_header (s, cmd); + zserv_create_header (s, cmd, vrf_id); + stream_putw(s, rn->p.family); switch (rn->p.family) { diff --git a/zebra/zebra_rnh.h b/zebra/zebra_rnh.h index 6deb878084..8e5ee8b952 100644 --- a/zebra/zebra_rnh.h +++ b/zebra/zebra_rnh.h @@ -57,7 +57,8 @@ extern struct rnh *zebra_add_rnh(struct prefix *p, vrf_id_t vrfid, extern struct rnh *zebra_lookup_rnh(struct prefix *p, vrf_id_t vrfid, rnh_type_t type); extern void zebra_delete_rnh(struct rnh *rnh, rnh_type_t type); -extern void zebra_add_rnh_client(struct rnh *rnh, struct zserv *client, rnh_type_t type); +extern void zebra_add_rnh_client(struct rnh *rnh, struct zserv *client, rnh_type_t type, + vrf_id_t vrfid); extern void zebra_register_rnh_static_nh(struct prefix *, struct route_node *); extern void zebra_deregister_rnh_static_nh(struct prefix *, struct route_node *); extern void zebra_remove_rnh_client(struct rnh *rnh, struct zserv *client, diff --git a/zebra/zserv.c b/zebra/zserv.c index 7a5700210f..f47d4bdb49 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -135,12 +135,13 @@ zebra_server_send_message(struct zserv *client) } void -zserv_create_header (struct stream *s, uint16_t cmd) +zserv_create_header (struct stream *s, uint16_t cmd, vrf_id_t vrf_id) { /* length placeholder, caller can update */ stream_putw (s, ZEBRA_HEADER_SIZE); stream_putc (s, ZEBRA_HEADER_MARKER); stream_putc (s, ZSERV_VERSION); + stream_putw (s, vrf_id); stream_putw (s, cmd); } @@ -187,13 +188,13 @@ zsend_interface_add (struct zserv *client, struct interface *ifp) struct stream *s; /* Check this client need interface information. */ - if (! client->ifinfo) + if (! vrf_bitmap_check (client->ifinfo, ifp->vrf_id)) return 0; s = client->obuf; stream_reset (s); - zserv_create_header (s, ZEBRA_INTERFACE_ADD); + zserv_create_header (s, ZEBRA_INTERFACE_ADD, ifp->vrf_id); zserv_encode_interface (s, ifp); client->ifadd_cnt++; @@ -207,13 +208,13 @@ zsend_interface_delete (struct zserv *client, struct interface *ifp) struct stream *s; /* Check this client need interface information. */ - if (! client->ifinfo) + if (! vrf_bitmap_check (client->ifinfo, ifp->vrf_id)) return 0; s = client->obuf; stream_reset (s); - zserv_create_header (s, ZEBRA_INTERFACE_DELETE); + zserv_create_header (s, ZEBRA_INTERFACE_DELETE, ifp->vrf_id); zserv_encode_interface (s, ifp); client->ifdel_cnt++; @@ -267,13 +268,13 @@ zsend_interface_address (int cmd, struct zserv *client, struct prefix *p; /* Check this client need interface information. */ - if (! client->ifinfo) + if (! vrf_bitmap_check (client->ifinfo, ifp->vrf_id)) return 0; s = client->obuf; stream_reset (s); - zserv_create_header (s, cmd); + zserv_create_header (s, cmd, ifp->vrf_id); stream_putl (s, ifp->ifindex); /* Interface address flag. */ @@ -321,7 +322,7 @@ zsend_interface_nbr_address (int cmd, struct zserv *client, s = client->obuf; stream_reset (s); - zserv_create_header (s, cmd); + zserv_create_header (s, cmd, ifp->vrf_id); stream_putl (s, ifp->ifindex); /* Prefix information. */ @@ -463,13 +464,13 @@ zsend_interface_update (int cmd, struct zserv *client, struct interface *ifp) struct stream *s; /* Check this client need interface information. */ - if (! client->ifinfo) + if (! vrf_bitmap_check (client->ifinfo, ifp->vrf_id)) return 0; s = client->obuf; stream_reset (s); - zserv_create_header (s, cmd); + zserv_create_header (s, cmd, ifp->vrf_id); zserv_encode_interface (s, ifp); if (cmd == ZEBRA_INTERFACE_UP) @@ -502,12 +503,22 @@ zsend_redistribute_route (int cmd, struct zserv *client, struct prefix *p, u_char zapi_flags = 0; struct nexthop dummy_nh; + /* Came from VRF lib patch, is this really needed? callers of this routine + do check for redist.., so may be its not needed. + Check this client need this route. + if (!vrf_bitmap_check (client->redist[family2afi(p->family)][rib->type], + rib->vrf_id) && + !(is_default (p) && + vrf_bitmap_check (client->redist_default, rib->vrf_id))) + return 0; + */ + s = client->obuf; stream_reset (s); memset(&dummy_nh, 0, sizeof(struct nexthop)); - zserv_create_header (s, cmd); - + zserv_create_header (s, cmd, rib->vrf_id); + /* Put type and nexthop. */ stream_putc (s, rib->type); stream_putw (s, rib->instance); @@ -635,7 +646,8 @@ zsend_redistribute_route (int cmd, struct zserv *client, struct prefix *p, #ifdef HAVE_IPV6 static int -zsend_ipv6_nexthop_lookup (struct zserv *client, struct in6_addr *addr) +zsend_ipv6_nexthop_lookup (struct zserv *client, struct in6_addr *addr, + vrf_id_t vrf_id) { struct stream *s; struct rib *rib; @@ -644,14 +656,14 @@ zsend_ipv6_nexthop_lookup (struct zserv *client, struct in6_addr *addr) struct nexthop *nexthop; /* Lookup nexthop. */ - rib = rib_match_ipv6 (addr, VRF_DEFAULT); + rib = rib_match_ipv6 (addr, vrf_id); /* Get output stream. */ s = client->obuf; stream_reset (s); /* Fill in result. */ - zserv_create_header (s, ZEBRA_IPV6_NEXTHOP_LOOKUP); + zserv_create_header (s, ZEBRA_IPV6_NEXTHOP_LOOKUP, vrf_id); stream_put (s, &addr, 16); if (rib) @@ -702,7 +714,8 @@ zsend_ipv6_nexthop_lookup (struct zserv *client, struct in6_addr *addr) #endif /* HAVE_IPV6 */ static int -zsend_ipv4_nexthop_lookup (struct zserv *client, struct in_addr addr) +zsend_ipv4_nexthop_lookup (struct zserv *client, struct in_addr addr, + vrf_id_t vrf_id) { struct stream *s; struct rib *rib; @@ -711,14 +724,14 @@ zsend_ipv4_nexthop_lookup (struct zserv *client, struct in_addr addr) struct nexthop *nexthop; /* Lookup nexthop. */ - rib = rib_match_ipv4 (addr, VRF_DEFAULT); + rib = rib_match_ipv4 (addr, vrf_id); /* Get output stream. */ s = client->obuf; stream_reset (s); /* Fill in result. */ - zserv_create_header (s, ZEBRA_IPV4_NEXTHOP_LOOKUP); + zserv_create_header (s, ZEBRA_IPV4_NEXTHOP_LOOKUP, vrf_id); stream_put_in_addr (s, &addr); if (rib) @@ -773,7 +786,7 @@ zsend_ipv4_nexthop_lookup (struct zserv *client, struct in_addr addr) /* Nexthop register */ static int zserv_rnh_register (struct zserv *client, int sock, u_short length, - rnh_type_t type) + rnh_type_t type, vrf_id_t vrf_id) { struct rnh *rnh; struct stream *s; @@ -828,7 +841,7 @@ zserv_rnh_register (struct zserv *client, int sock, u_short length, UNSET_FLAG(rnh->flags, ZEBRA_NHT_EXACT_MATCH); } - zebra_add_rnh_client(rnh, client, type); + zebra_add_rnh_client(rnh, client, type, vrf_id); /* Anything not AF_INET/INET6 has been filtered out above */ zebra_evaluate_rnh(0, p.family, 1, type, &p); } @@ -884,7 +897,8 @@ zserv_rnh_unregister (struct zserv *client, int sock, u_short length, } static int -zsend_ipv4_import_lookup (struct zserv *client, struct prefix_ipv4 *p) +zsend_ipv4_import_lookup (struct zserv *client, struct prefix_ipv4 *p, + vrf_id_t vrf_id) { struct stream *s; struct rib *rib; @@ -893,14 +907,14 @@ zsend_ipv4_import_lookup (struct zserv *client, struct prefix_ipv4 *p) struct nexthop *nexthop; /* Lookup nexthop. */ - rib = rib_lookup_ipv4 (p, VRF_DEFAULT); + rib = rib_lookup_ipv4 (p, vrf_id); /* Get output stream. */ s = client->obuf; stream_reset (s); /* Fill in result. */ - zserv_create_header (s, ZEBRA_IPV4_IMPORT_LOOKUP); + zserv_create_header (s, ZEBRA_IPV4_IMPORT_LOOKUP, vrf_id); stream_put_in_addr (s, &p->prefix); if (rib) @@ -955,14 +969,14 @@ zsend_router_id_update (struct zserv *client, struct prefix *p, int blen; /* Check this client need interface information. */ - if (!client->ridinfo) + if (! vrf_bitmap_check (client->ridinfo, vrf_id)) return 0; s = client->obuf; stream_reset (s); /* Message type. */ - zserv_create_header (s, ZEBRA_ROUTER_ID_UPDATE); + zserv_create_header (s, ZEBRA_ROUTER_ID_UPDATE, vrf_id); /* Prefix information. */ stream_putc (s, p->family); @@ -979,7 +993,7 @@ zsend_router_id_update (struct zserv *client, struct prefix *p, /* Register zebra server interface information. Send current all interface and address information. */ static int -zread_interface_add (struct zserv *client, u_short length) +zread_interface_add (struct zserv *client, u_short length, vrf_id_t vrf_id) { struct listnode *ifnode, *ifnnode; struct listnode *cnode, *cnnode; @@ -988,9 +1002,9 @@ zread_interface_add (struct zserv *client, u_short length) struct nbr_connected *nc; /* Interface information is needed. */ - client->ifinfo = 1; + vrf_bitmap_set (client->ifinfo, vrf_id); - for (ALL_LIST_ELEMENTS (iflist, ifnode, ifnnode, ifp)) + for (ALL_LIST_ELEMENTS (vrf_iflist (vrf_id), ifnode, ifnnode, ifp)) { /* Skip pseudo interface. */ if (! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) @@ -1019,9 +1033,9 @@ zread_interface_add (struct zserv *client, u_short length) /* Unregister zebra server interface information. */ static int -zread_interface_delete (struct zserv *client, u_short length) +zread_interface_delete (struct zserv *client, u_short length, vrf_id_t vrf_id) { - client->ifinfo = 0; + vrf_bitmap_unset (client->ifinfo, vrf_id); return 0; } @@ -1043,7 +1057,7 @@ zserv_nexthop_num_warn (const char *caller, const struct prefix *p, const u_char * add kernel route. */ static int -zread_ipv4_add (struct zserv *client, u_short length) +zread_ipv4_add (struct zserv *client, u_short length, vrf_id_t vrf_id) { int i; struct rib *rib; @@ -1079,7 +1093,7 @@ zread_ipv4_add (struct zserv *client, u_short length) stream_get (&p.prefix, s, PSIZE (p.prefixlen)); /* VRF ID */ - rib->vrf_id = VRF_DEFAULT; + rib->vrf_id = vrf_id; /* Nexthop parse. */ if (CHECK_FLAG (message, ZAPI_MESSAGE_NEXTHOP)) @@ -1153,7 +1167,7 @@ zread_ipv4_add (struct zserv *client, u_short length) /* Zebra server IPv4 prefix delete function. */ static int -zread_ipv4_delete (struct zserv *client, u_short length) +zread_ipv4_delete (struct zserv *client, u_short length, vrf_id_t vrf_id) { int i; struct stream *s; @@ -1236,14 +1250,15 @@ zread_ipv4_delete (struct zserv *client, u_short length) api.tag = 0; rib_delete_ipv4 (api.type, api.instance, api.flags, &p, nexthop_p, ifindex, - VRF_DEFAULT, client->rtm_table, api.safi); + vrf_id, client->rtm_table, api.safi); client->v4_route_del_cnt++; return 0; } /* Nexthop lookup for IPv4. */ static int -zread_ipv4_nexthop_lookup (struct zserv *client, u_short length) +zread_ipv4_nexthop_lookup (struct zserv *client, u_short length, + vrf_id_t vrf_id) { struct in_addr addr; char buf[BUFSIZ]; @@ -1252,12 +1267,13 @@ zread_ipv4_nexthop_lookup (struct zserv *client, u_short length) if (IS_ZEBRA_DEBUG_PACKET && IS_ZEBRA_DEBUG_RECV) zlog_debug("%s: looking up %s", __func__, inet_ntop (AF_INET, &addr, buf, BUFSIZ)); - return zsend_ipv4_nexthop_lookup (client, addr); + return zsend_ipv4_nexthop_lookup (client, addr, vrf_id); } /* Nexthop lookup for IPv4. */ static int -zread_ipv4_import_lookup (struct zserv *client, u_short length) +zread_ipv4_import_lookup (struct zserv *client, u_short length, + vrf_id_t vrf_id) { struct prefix_ipv4 p; @@ -1265,7 +1281,7 @@ zread_ipv4_import_lookup (struct zserv *client, u_short length) p.prefixlen = stream_getc (client->ibuf); p.prefix.s_addr = stream_get_ipv4 (client->ibuf); - return zsend_ipv4_import_lookup (client, &p); + return zsend_ipv4_import_lookup (client, &p, vrf_id); } #ifdef HAVE_IPV6 @@ -1390,9 +1406,8 @@ zread_ipv4_route_ipv6_nexthop_add (struct zserv *client, u_short length) return 0; } -/* Zebra server IPv6 prefix add function. */ static int -zread_ipv6_add (struct zserv *client, u_short length) +zread_ipv6_add (struct zserv *client, u_short length, vrf_id_t vrf_id) { int i; struct stream *s; @@ -1510,7 +1525,7 @@ zread_ipv6_add (struct zserv *client, u_short length) /* Table */ rib->table=zebrad.rtm_table_default; - rib->vrf_id = VRF_DEFAULT; + rib->vrf_id = vrf_id; ret = rib_add_ipv6_multipath ((struct prefix *)&p, rib, safi, ifindex); /* Stats */ if (ret > 0) @@ -1523,7 +1538,7 @@ zread_ipv6_add (struct zserv *client, u_short length) /* Zebra server IPv6 prefix delete function. */ static int -zread_ipv6_delete (struct zserv *client, u_short length) +zread_ipv6_delete (struct zserv *client, u_short length, vrf_id_t vrf_id) { int i; struct stream *s; @@ -1591,17 +1606,18 @@ zread_ipv6_delete (struct zserv *client, u_short length) if (IN6_IS_ADDR_UNSPECIFIED (&nexthop)) rib_delete_ipv6 (api.type, api.instance, api.flags, &p, NULL, ifindex, - VRF_DEFAULT, client->rtm_table, api.safi); + vrf_id, client->rtm_table, api.safi); else rib_delete_ipv6 (api.type, api.instance, api.flags, &p, &nexthop, ifindex, - VRF_DEFAULT, client->rtm_table, api.safi); + vrf_id, client->rtm_table, api.safi); client->v6_route_del_cnt++; return 0; } static int -zread_ipv6_nexthop_lookup (struct zserv *client, u_short length) +zread_ipv6_nexthop_lookup (struct zserv *client, u_short length, + vrf_id_t vrf_id) { struct in6_addr addr; char buf[BUFSIZ]; @@ -1611,29 +1627,29 @@ zread_ipv6_nexthop_lookup (struct zserv *client, u_short length) zlog_debug("%s: looking up %s", __func__, inet_ntop (AF_INET6, &addr, buf, BUFSIZ)); - return zsend_ipv6_nexthop_lookup (client, &addr); + return zsend_ipv6_nexthop_lookup (client, &addr, vrf_id); } #endif /* HAVE_IPV6 */ /* Register zebra server router-id information. Send current router-id */ static int -zread_router_id_add (struct zserv *client, u_short length) +zread_router_id_add (struct zserv *client, u_short length, vrf_id_t vrf_id) { struct prefix p; /* Router-id information is needed. */ - client->ridinfo = 1; + vrf_bitmap_set (client->ridinfo, vrf_id); - router_id_get (&p, VRF_DEFAULT); + router_id_get (&p, vrf_id); - return zsend_router_id_update (client, &p, VRF_DEFAULT); + return zsend_router_id_update (client, &p, vrf_id); } /* Unregister zebra server router-id information. */ static int -zread_router_id_delete (struct zserv *client, u_short length) +zread_router_id_delete (struct zserv *client, u_short length, vrf_id_t vrf_id) { - client->ridinfo = 0; + vrf_bitmap_unset (client->ridinfo, vrf_id); return 0; } @@ -1662,6 +1678,23 @@ zread_hello (struct zserv *client) } } +/* Unregister all information in a VRF. */ +static int +zread_vrf_unregister (struct zserv *client, u_short length, vrf_id_t vrf_id) +{ + int i; + afi_t afi; + + for (afi = AFI_IP; afi < AFI_MAX; afi++) + for (i = 0; i < ZEBRA_ROUTE_MAX; i++) + vrf_bitmap_unset (client->redist[afi][i], vrf_id); + vrf_bitmap_unset (client->redist_default, vrf_id); + vrf_bitmap_unset (client->ifinfo, vrf_id); + vrf_bitmap_unset (client->ridinfo, vrf_id); + + return 0; +} + /* Close zebra client. */ static void zebra_client_close (struct zserv *client) @@ -1709,6 +1742,8 @@ static void zebra_client_create (int sock) { struct zserv *client; + int i; + afi_t afi; client = XCALLOC (0, sizeof (struct zserv)); @@ -1722,6 +1757,13 @@ zebra_client_create (int sock) client->rtm_table = zebrad.rtm_table_default; client->connect_time = quagga_time(NULL); + /* Initialize flags */ + for (afi = AFI_IP; afi < AFI_MAX; afi++) + for (i = 0; i < ZEBRA_ROUTE_MAX; i++) + client->redist[afi][i] = vrf_bitmap_init (); + client->redist_default = vrf_bitmap_init (); + client->ifinfo = vrf_bitmap_init (); + client->ridinfo = vrf_bitmap_init (); /* Add this client to linked list. */ listnode_add (zebrad.client_list, client); @@ -1739,6 +1781,7 @@ zebra_client_read (struct thread *thread) size_t already; uint16_t length, command; uint8_t marker, version; + vrf_id_t vrf_id; /* Get thread data. Reset reading thread because I'm running. */ sock = THREAD_FD (thread); @@ -1780,6 +1823,7 @@ zebra_client_read (struct thread *thread) length = stream_getw (client->ibuf); marker = stream_getc (client->ibuf); version = stream_getc (client->ibuf); + vrf_id = stream_getw (client->ibuf); command = stream_getw (client->ibuf); if (marker != ZEBRA_HEADER_MARKER || version != ZSERV_VERSION) @@ -1832,8 +1876,8 @@ zebra_client_read (struct thread *thread) zlog_debug ("zebra message comes from socket [%d]", sock); if (IS_ZEBRA_DEBUG_PACKET && IS_ZEBRA_DEBUG_RECV) - zlog_debug ("zebra message received [%s] %d", - zserv_command_string (command), length); + zlog_debug ("zebra message received [%s] %d in VRF %u", + zserv_command_string (command), length, vrf_id); client->last_read_time = quagga_time(NULL); client->last_read_cmd = command; @@ -1841,68 +1885,68 @@ zebra_client_read (struct thread *thread) switch (command) { case ZEBRA_ROUTER_ID_ADD: - zread_router_id_add (client, length); + zread_router_id_add (client, length, vrf_id); break; case ZEBRA_ROUTER_ID_DELETE: - zread_router_id_delete (client, length); + zread_router_id_delete (client, length, vrf_id); break; case ZEBRA_INTERFACE_ADD: - zread_interface_add (client, length); + zread_interface_add (client, length, vrf_id); break; case ZEBRA_INTERFACE_DELETE: - zread_interface_delete (client, length); + zread_interface_delete (client, length, vrf_id); break; case ZEBRA_IPV4_ROUTE_ADD: - zread_ipv4_add (client, length); + zread_ipv4_add (client, length, vrf_id); break; case ZEBRA_IPV4_ROUTE_DELETE: - zread_ipv4_delete (client, length); + zread_ipv4_delete (client, length, vrf_id); break; #ifdef HAVE_IPV6 case ZEBRA_IPV4_ROUTE_IPV6_NEXTHOP_ADD: zread_ipv4_route_ipv6_nexthop_add (client, length); break; case ZEBRA_IPV6_ROUTE_ADD: - zread_ipv6_add (client, length); + zread_ipv6_add (client, length, vrf_id); break; case ZEBRA_IPV6_ROUTE_DELETE: - zread_ipv6_delete (client, length); + zread_ipv6_delete (client, length, vrf_id); break; #endif /* HAVE_IPV6 */ case ZEBRA_REDISTRIBUTE_ADD: - zebra_redistribute_add (command, client, length); + zebra_redistribute_add (command, client, length, vrf_id); break; case ZEBRA_REDISTRIBUTE_DELETE: - zebra_redistribute_delete (command, client, length); + zebra_redistribute_delete (command, client, length, vrf_id); break; case ZEBRA_REDISTRIBUTE_DEFAULT_ADD: - zebra_redistribute_default_add (command, client, length); + zebra_redistribute_default_add (command, client, length, vrf_id); break; case ZEBRA_REDISTRIBUTE_DEFAULT_DELETE: - zebra_redistribute_default_delete (command, client, length); + zebra_redistribute_default_delete (command, client, length, vrf_id); break; case ZEBRA_IPV4_NEXTHOP_LOOKUP: - zread_ipv4_nexthop_lookup (client, length); + zread_ipv4_nexthop_lookup (client, length, vrf_id); break; #ifdef HAVE_IPV6 case ZEBRA_IPV6_NEXTHOP_LOOKUP: - zread_ipv6_nexthop_lookup (client, length); + zread_ipv6_nexthop_lookup (client, length, vrf_id); break; #endif /* HAVE_IPV6 */ case ZEBRA_IPV4_IMPORT_LOOKUP: - zread_ipv4_import_lookup (client, length); + zread_ipv4_import_lookup (client, length, vrf_id); break; case ZEBRA_HELLO: zread_hello (client); break; case ZEBRA_NEXTHOP_REGISTER: - zserv_rnh_register(client, sock, length, RNH_NEXTHOP_TYPE); + zserv_rnh_register(client, sock, length, RNH_NEXTHOP_TYPE, vrf_id); break; case ZEBRA_NEXTHOP_UNREGISTER: zserv_rnh_unregister(client, sock, length, RNH_NEXTHOP_TYPE); break; case ZEBRA_IMPORT_ROUTE_REGISTER: - zserv_rnh_register(client, sock, length, RNH_IMPORT_CHECK_TYPE); + zserv_rnh_register(client, sock, length, RNH_IMPORT_CHECK_TYPE, vrf_id); break; case ZEBRA_IMPORT_ROUTE_UNREGISTER: zserv_rnh_unregister(client, sock, length, RNH_IMPORT_CHECK_TYPE); @@ -1914,6 +1958,9 @@ zebra_client_read (struct thread *thread) case ZEBRA_BFD_DEST_DEREGISTER: zebra_ptm_bfd_dst_deregister(client, sock, length); break; + case ZEBRA_VRF_UNREGISTER: + zread_vrf_unregister (client, length, vrf_id); + break; default: zlog_info ("Zebra received unknown command %d", command); break; diff --git a/zebra/zserv.h b/zebra/zserv.h index f4da43d0b0..8e741a417e 100644 --- a/zebra/zserv.h +++ b/zebra/zserv.h @@ -28,6 +28,7 @@ #include "routemap.h" #include "vty.h" #include "zclient.h" +#include "vrf.h" /* Default port information. */ #define ZEBRA_VTY_PORT 2601 @@ -61,16 +62,17 @@ struct zserv int rtm_table; /* This client's redistribute flag. */ - struct redist_proto redist[AFI_MAX][ZEBRA_ROUTE_MAX]; + struct redist_proto mi_redist[AFI_MAX][ZEBRA_ROUTE_MAX]; + vrf_bitmap_t redist[AFI_MAX][ZEBRA_ROUTE_MAX]; /* Redistribute default route flag. */ - u_char redist_default; + vrf_bitmap_t redist_default; /* Interface information. */ - u_char ifinfo; + vrf_bitmap_t ifinfo; /* Router-id information. */ - u_char ridinfo; + vrf_bitmap_t ridinfo; /* client's protocol */ u_char proto; @@ -157,7 +159,7 @@ extern int zsend_router_id_update (struct zserv *, struct prefix *, extern pid_t pid; -extern void zserv_create_header(struct stream *s, uint16_t cmd); +extern void zserv_create_header(struct stream *s, uint16_t cmd, vrf_id_t vrf_id); extern void zserv_nexthop_num_warn(const char *, const struct prefix *, const u_char); extern int zebra_server_send_message(struct zserv *client);