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;
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;
}
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;
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;
}
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;
}
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;
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;
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;
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;
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;
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;
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);
/* 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;
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;
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;
}
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;
}
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);
#include "resend.h"
#include "babel_filter.h"
#include "babel_zebra.h"
+#include "vrf.h"
static int babel_init_routing_process(struct thread *thread);
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++;
&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);
}
/*
* 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;
*/
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;
return 0;
}
-
int
bgp_multiaccess_check_v4 (struct in_addr nexthop, struct peer *peer)
{
#include "log.h"
#include "memory.h"
#include "nexthop.h"
+#include "vrf.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_table.h"
}
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;
/* 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);
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:
#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
/* 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;
/* 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;
}
/* 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);
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))
}
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;
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;
}
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;
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;
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;
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;
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;
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;
/* 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;
#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;
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)
valid_nh_count++;
}
+ api.vrf_id = VRF_DEFAULT;
api.flags = flags;
api.type = ZEBRA_ROUTE_BGP;
api.instance = 0;
}
/* Make Zebra API structure. */
+ api.vrf_id = VRF_DEFAULT;
api.flags = flags;
api.type = ZEBRA_ROUTE_BGP;
api.instance = 0;
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;
{
struct zapi_ipv4 api;
+ api.vrf_id = VRF_DEFAULT;
api.flags = flags;
api.type = ZEBRA_ROUTE_BGP;
assert (info->attr->extra);
+ api.vrf_id = VRF_DEFAULT;
api.flags = flags;
api.type = ZEBRA_ROUTE_BGP;
api.instance = 0;
{
/* 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)
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;
}
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;
}
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)
{
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. */
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;
#include "zclient.h"
#include "stream.h"
#include "linklist.h"
+#include "vrf.h"
#include "isisd/dict.h"
#include "isisd/isis_constants.h"
/* 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;
}
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",
}
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;
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;
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;
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;
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;
#endif /* EXTREME_DEBUG */
c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE,
- zclient->ibuf);
+ zclient->ibuf, vrf_id);
if (c == NULL)
return 0;
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;
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 */
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;
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;
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;
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))
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;
#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)
}
#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;
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;
s = zclient->obuf;
stream_reset (s);
- zclient_create_header (s, command);
+ zclient_create_header (s, command, vrf_id);
stream_putw(s, family);
switch (family)
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);
{ MTYPE_BFD_INFO, "BFD info" },
{ MTYPE_VRF, "VRF" },
{ MTYPE_VRF_NAME, "VRF name" },
+ { MTYPE_VRF_BITMAP, "VRF bit-map" },
{ -1, NULL },
};
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)
/* 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
*/
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);
}
}
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;
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);
}
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));
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)
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
/* 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. */
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);
}
/*
/* 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);
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);
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);
*/
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);
*/
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];
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);
* 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];
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)
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;
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): "
* +-+-+-+-+-+-+-+-+
*/
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;
size_t already;
uint16_t length, command;
uint8_t marker, version;
+ vrf_id_t vrf_id;
struct zclient *zclient;
/* Get socket to zebra. */
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)
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;
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
/* 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
{
/* 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. */
* 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;
};
u_int32_t metric;
u_short tag;
+
+ vrf_id_t vrf_id;
};
/* Prototypes of zebra client service functions. */
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 *,
u_int32_t metric;
u_short tag;
+
+ vrf_id_t vrf_id;
};
extern int zapi_ipv6_route (u_char cmd, struct zclient *zclient,
#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
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);
* 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;
*/
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;
/* 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;
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);
}
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))
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;
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;
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;
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;
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);
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);
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;
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;
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;
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))
{
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))
{
{
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;
{
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;
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;
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);
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);
}
/*
* 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;
*/
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;
{
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;
/* 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;
/* 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",
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;
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;
}
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];
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;
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;
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;
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;
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;
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;
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);
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;
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);
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;
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;
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
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]",
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",
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]",
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");
/* 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;
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;
/* 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;
/* 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;
/* 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;
/* 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",
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;
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;
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;
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)
{
#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 */
#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"
{
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;
{
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;
/* 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;
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);
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);
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
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);
"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;
}
"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;
}
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;
}
}
{
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;
}
}
{
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;
}
}
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;
}
}
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);
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)
{
"%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;
/* 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;
/* 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;
/* 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",
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;
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;
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)
{
/* 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;
{
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;
/* 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;
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);
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
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);
"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;
}
"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;
}
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;
}
}
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;
}
}
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;
}
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;
}
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)
{
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);
"%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)
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;
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);
inet_aton (gateway, &gate);
gpnt = &gate;
+ api.vrf_id = VRF_DEFAULT;
api.type = type;
api.flags = 0;
#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"
return 0;
}
-static int
+int
is_default (struct prefix *p)
{
if (p->family == AF_INET)
}
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;
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);
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);
/* 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)
}
#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)
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)
{
}
}
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)
{
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 */
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 */
}
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;
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;
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. */
#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 *);
extern int zebra_import_table_config(struct vty *);
+extern int is_default (struct prefix *);
+
#endif /* _ZEBRA_REDISTRIBUTE_H */
#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
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
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));
})
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;
}
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)
{
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
}
}
/* 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);
}
}
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 */
}
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");
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;
}
}
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;
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)
{
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,
}
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);
}
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++;
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++;
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. */
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. */
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)
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);
#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;
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)
#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;
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)
/* 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;
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);
}
}
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;
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)
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);
/* 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;
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))
/* 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;
}
* 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;
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))
/* 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;
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];
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;
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
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;
/* 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)
/* 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;
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];
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;
}
}
}
+/* 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)
zebra_client_create (int sock)
{
struct zserv *client;
+ int i;
+ afi_t afi;
client = XCALLOC (0, sizeof (struct zserv));
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);
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);
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)
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;
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);
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;
#include "routemap.h"
#include "vty.h"
#include "zclient.h"
+#include "vrf.h"
/* Default port information. */
#define ZEBRA_VTY_PORT 2601
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;
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);