return 0;
}
-int
-prefix2str (const struct prefix *p, char *str, int size)
+const char *
+prefix2str (union prefix46constptr pu, char *str, int size)
{
+ const struct prefix *p = pu.p;
char buf[BUFSIZ];
inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ);
snprintf (str, size, "%s/%d", buf, p->prefixlen);
- return 0;
+ return str;
}
struct prefix *
extern const char *prefix_family_str (const struct prefix *);
extern int prefix_blen (const struct prefix *);
extern int str2prefix (const char *, struct prefix *);
-extern int prefix2str (const struct prefix *, char *, int);
+extern const char *prefix2str (union prefix46constptr, char *, int);
extern int prefix_match (const struct prefix *, const struct prefix *);
extern int prefix_same (const struct prefix *, const struct prefix *);
extern int prefix_cmp (const struct prefix *, const struct prefix *);
return;
rib_add_ipv4 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, NULL, ifp->ifindex,
- RT_TABLE_MAIN, ifp->metric, 0, SAFI_UNICAST);
+ ifp->vrf_id, RT_TABLE_MAIN, ifp->metric, 0, SAFI_UNICAST);
rib_add_ipv4 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, NULL, ifp->ifindex,
- RT_TABLE_MAIN, ifp->metric, 0, SAFI_MULTICAST);
+ ifp->vrf_id, RT_TABLE_MAIN, ifp->metric, 0, SAFI_MULTICAST);
if (IS_ZEBRA_DEBUG_RIB)
zlog_debug ("%s: calling rib_update", __func__);
- rib_update ();
+ rib_update (ifp->vrf_id);
}
/* Add connected IPv4 route to the interface. */
return;
/* Same logic as for connected_up_ipv4(): push the changes into the head. */
- rib_delete_ipv4 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, 0, SAFI_UNICAST);
+ rib_delete_ipv4 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, ifp->vrf_id, 0,
+ SAFI_UNICAST);
- rib_delete_ipv4 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, 0, SAFI_MULTICAST);
+ rib_delete_ipv4 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, ifp->vrf_id, 0,
+ SAFI_MULTICAST);
if (IS_ZEBRA_DEBUG_RIB)
zlog_debug ("%s: calling rib_update_static", __func__);
- rib_update_static ();
+ rib_update_static (ifp->vrf_id);
}
void
if (IS_ZEBRA_DEBUG_RIB)
zlog_debug ("%s: calling rib_update_static", __func__);
- rib_update_static();
+ rib_update_static(ifp->vrf_id);
}
#ifdef HAVE_IPV6
return;
#endif
- rib_add_ipv6 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, RT_TABLE_MAIN,
- ifp->metric, 0, SAFI_UNICAST);
+ rib_add_ipv6 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, ifp->vrf_id,
+ RT_TABLE_MAIN, ifp->metric, 0, SAFI_UNICAST);
if (IS_ZEBRA_DEBUG_RIB)
zlog_debug ("%s: calling rib_update", __func__);
- rib_update ();
+ rib_update (ifp->vrf_id);
}
/* Add connected IPv6 route to the interface. */
if (IN6_IS_ADDR_UNSPECIFIED (&p.prefix))
return;
- rib_delete_ipv6 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, 0, SAFI_UNICAST);
+ rib_delete_ipv6 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex,
+ ifp->vrf_id, 0, SAFI_UNICAST);
if (IS_ZEBRA_DEBUG_RIB)
zlog_debug ("%s: calling rib_update_static", __func__);
- rib_update_static ();
+ rib_update_static (ifp->vrf_id);
}
void
if (IS_ZEBRA_DEBUG_RIB)
zlog_debug ("%s: calling rib_update_static", __func__);
- rib_update_static();
+ rib_update_static(ifp->vrf_id);
}
#endif /* HAVE_IPV6 */
ifp->name);
/* Examine all static routes. */
- rib_update ();
+ rib_update (ifp->vrf_id);
}
/* Interface goes down. We have to manage different behavior of based
zlog_debug ("%s: calling rib_update_static on interface %s down", __func__,
ifp->name);
- rib_update_static ();
+ rib_update_static (ifp->vrf_id);
if_nbr_ipv6ll_to_ipv4ll_neigh_del_all (ifp);
#include "table.h"
#include "rib.h"
#include "privs.h"
+#include "vrf.h"
#include "zebra/interface.h"
#include "zebra/zserv.h"
int ret;
if (! IS_ZEBRA_DEBUG_RIB)
return;
- ret = rib_lookup_ipv4_route (&p, &gate);
- inet_ntop (AF_INET, &p.prefix, buf, INET_ADDRSTRLEN);
+ ret = rib_lookup_ipv4_route (&p, &gate, VRF_DEFAULT);
+ prefix2str (&p, buf, sizeof(buf));
switch (rtm->rtm_type)
{
case RTM_ADD:
*/
if (rtm->rtm_type == RTM_CHANGE)
rib_delete_ipv4 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p,
- NULL, 0, 0, SAFI_UNICAST);
+ NULL, 0, VRF_DEFAULT, SAFI_UNICAST);
if (rtm->rtm_type == RTM_GET
|| rtm->rtm_type == RTM_ADD
|| rtm->rtm_type == RTM_CHANGE)
rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags,
- &p, &gate.sin.sin_addr, NULL, 0, 0, 0, 0, SAFI_UNICAST);
+ &p, &gate.sin.sin_addr, NULL, 0, VRF_DEFAULT, 0, 0, SAFI_UNICAST);
else
rib_delete_ipv4 (ZEBRA_ROUTE_KERNEL, 0 zebra_flags,
- &p, &gate.sin.sin_addr, 0, 0, SAFI_UNICAST);
+ &p, &gate.sin.sin_addr, 0, VRF_DEFAULT, SAFI_UNICAST);
}
#ifdef HAVE_IPV6
if (dest.sa.sa_family == AF_INET6)
*/
if (rtm->rtm_type == RTM_CHANGE)
rib_delete_ipv6 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p,
- NULL, 0, 0, SAFI_UNICAST);
+ NULL, 0, VRF_DEFAULT, SAFI_UNICAST);
if (rtm->rtm_type == RTM_GET
|| rtm->rtm_type == RTM_ADD
|| rtm->rtm_type == RTM_CHANGE)
rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags,
- &p, &gate.sin6.sin6_addr, ifindex, 0, 0, 0, SAFI_UNICAST);
+ &p, &gate.sin6.sin6_addr, ifindex, VRF_DEFAULT, 0, 0, SAFI_UNICAST);
else
rib_delete_ipv6 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags,
- &p, &gate.sin6.sin6_addr, ifindex, 0, SAFI_UNICAST);
+ &p, &gate.sin6.sin6_addr, ifindex, VRF_DEFAULT, SAFI_UNICAST);
}
#endif /* HAVE_IPV6 */
}
/* Source protocol instance */
u_short instance;
+ /* VRF identifier. */
+ vrf_id_t vrf_id;
+
/* Which routing table */
uint32_t table;
#define rib_dump(prefix ,rib) _rib_dump(__func__, prefix, rib)
extern void _rib_dump (const char *,
union prefix46constptr, const struct rib *);
-extern int rib_lookup_ipv4_route (struct prefix_ipv4 *, union sockunion *);
+extern int rib_lookup_ipv4_route (struct prefix_ipv4 *, union sockunion *,
+ vrf_id_t);
#define ZEBRA_RIB_LOOKUP_ERROR -1
#define ZEBRA_RIB_FOUND_EXACT 0
#define ZEBRA_RIB_FOUND_NOGATE 1
* also implicitly withdraw equal prefix of same type. */
extern int rib_add_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p,
struct in_addr *gate, struct in_addr *src,
- unsigned int ifindex, u_int32_t vrf_id,
+ unsigned int ifindex, vrf_id_t vrf_id, u_int32_t table_id,
u_int32_t, u_char, safi_t);
extern int rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *, safi_t);
extern int rib_delete_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p,
struct in_addr *gate, unsigned int ifindex,
- u_int32_t, safi_t safi);
+ vrf_id_t, u_int32_t, safi_t safi);
-extern struct rib *rib_match_ipv4 (struct in_addr);
+extern struct rib *rib_match_ipv4 (struct in_addr, vrf_id_t);
-extern struct rib *rib_lookup_ipv4 (struct prefix_ipv4 *);
+extern struct rib *rib_lookup_ipv4 (struct prefix_ipv4 *, vrf_id_t);
-extern void rib_update (void);
-extern void rib_update_static (void);
+extern void rib_update (vrf_id_t);
+extern void rib_update_static (vrf_id_t);
extern void rib_weed_tables (void);
extern void rib_sweep_route (void);
extern void rib_close (void);
extern int
static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
- u_char flags, u_short tag, u_char distance, u_int32_t vrf_id);
+ u_char flags, u_short tag, u_char distance, vrf_id_t vrf_id);
extern int
static_delete_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
- u_short tag, u_char distance, u_int32_t vrf_id);
+ u_short tag, u_char distance, vrf_id_t vrf_id);
#ifdef HAVE_IPV6
extern int
rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p,
- struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id,
- u_int32_t metric, u_char distance, safi_t safi);
+ struct in6_addr *gate, unsigned int ifindex, vrf_id_t vrf_id,
+ u_int32_t table_id, u_int32_t metric, u_char distance, safi_t safi);
extern int
rib_delete_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p,
- struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id, safi_t safi);
+ struct in6_addr *gate, unsigned int ifindex, vrf_id_t vrf_id,
+ u_int32_t table_id, safi_t safi);
-extern struct rib *rib_lookup_ipv6 (struct in6_addr *);
+extern struct rib *rib_lookup_ipv6 (struct in6_addr *, vrf_id_t);
-extern struct rib *rib_match_ipv6 (struct in6_addr *);
+extern struct rib *rib_match_ipv6 (struct in6_addr *, vrf_id_t);
extern struct route_table *rib_table_ipv6;
extern int
static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
const char *ifname, u_char flags, u_short tag,
- u_char distance, u_int32_t vrf_id);
+ u_char distance, vrf_id_t vrf_id);
extern int
rib_add_ipv6_multipath (struct prefix *, struct rib *, safi_t,
extern int
static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
const char *ifname, u_short tag, u_char distance,
- u_int32_t vrf_id);
+ vrf_id_t vrf_id);
#endif /* HAVE_IPV6 */
#include "thread.h"
#include "privs.h"
#include "nexthop.h"
+#include "vrf.h"
#include "zebra/zserv.h"
#include "zebra/rt.h"
if (!tb[RTA_MULTIPATH])
rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, flags, &p, gate, src, index,
- table, metric, 0, SAFI_UNICAST);
+ VRF_DEFAULT, table, metric, 0, SAFI_UNICAST);
else
{
/* This is a multipath route */
rib->distance = 0;
rib->flags = flags;
rib->metric = metric;
+ rib->vrf_id = VRF_DEFAULT;
rib->table = table;
rib->nexthop_num = 0;
rib->uptime = time (NULL);
memcpy (&p.prefix, dest, 16);
p.prefixlen = rtm->rtm_dst_len;
- rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, flags, &p, gate, index, table,
- metric, 0, SAFI_UNICAST);
+ rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, flags, &p, gate, index, VRF_DEFAULT,
+ table, metric, 0, SAFI_UNICAST);
}
#endif /* HAVE_IPV6 */
if (h->nlmsg_type == RTM_NEWROUTE)
{
if (!tb[RTA_MULTIPATH])
- rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, 0, &p, gate, src, index, table,
- metric, 0, SAFI_UNICAST);
+ rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, 0, &p, gate, src, index, VRF_DEFAULT,
+ table, metric, 0, SAFI_UNICAST);
else
{
/* This is a multipath route */
rib->distance = 0;
rib->flags = 0;
rib->metric = metric;
+ rib->vrf_id = VRF_DEFAULT;
rib->table = table;
rib->nexthop_num = 0;
rib->uptime = time (NULL);
}
else
rib_delete_ipv4 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, gate, index,
- table, SAFI_UNICAST);
+ VRF_DEFAULT, table, SAFI_UNICAST);
}
#ifdef HAVE_IPV6
}
if (h->nlmsg_type == RTM_NEWROUTE)
- rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, 0, &p, gate, index, table, metric, 0, SAFI_UNICAST);
+ rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, 0, &p, gate, index, VRF_DEFAULT,
+ table, metric, 0, SAFI_UNICAST);
else
rib_delete_ipv6 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, gate, index,
- table, SAFI_UNICAST);
+ VRF_DEFAULT, table, SAFI_UNICAST);
}
#endif /* HAVE_IPV6 */
#include "prefix.h"
#include "log.h"
#include "if.h"
+#include "vrf.h"
#include "zebra/rib.h"
#include "zebra/zserv.h"
gateway.s_addr = routeEntry->ipRouteNextHop;
rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &prefix,
- &gateway, NULL, 0, 0, 0, 0, SAFI_UNICAST);
+ &gateway, NULL, 0, VRF_DEFAULT, 0, 0, 0, SAFI_UNICAST);
}
void
p.prefix = nexthop->gate.ipv4;
/* Lookup table. */
- table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
+ table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, rib->vrf_id);
if (! table)
return 0;
p.prefix = nexthop->gate.ipv6;
/* Lookup table. */
- table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
+ table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, rib->vrf_id);
if (! table)
return 0;
#endif /* HAVE_IPV6 */
struct rib *
-rib_match_ipv4 (struct in_addr addr)
+rib_match_ipv4 (struct in_addr addr, vrf_id_t vrf_id)
{
struct prefix_ipv4 p;
struct route_table *table;
int recursing;
/* Lookup table. */
- table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
+ table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
if (! table)
return 0;
}
struct rib *
-rib_lookup_ipv4 (struct prefix_ipv4 *p)
+rib_lookup_ipv4 (struct prefix_ipv4 *p, vrf_id_t vrf_id)
{
struct route_table *table;
struct route_node *rn;
int recursing;
/* Lookup table. */
- table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
+ table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
if (! table)
return 0;
* 3: no matches found
*/
int
-rib_lookup_ipv4_route (struct prefix_ipv4 *p, union sockunion * qgate)
+rib_lookup_ipv4_route (struct prefix_ipv4 *p, union sockunion * qgate,
+ vrf_id_t vrf_id)
{
struct route_table *table;
struct route_node *rn;
int nexthops_active;
/* Lookup table. */
- table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
+ table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
if (! table)
return ZEBRA_RIB_LOOKUP_ERROR;
#ifdef HAVE_IPV6
struct rib *
-rib_match_ipv6 (struct in6_addr *addr)
+rib_match_ipv6 (struct in6_addr *addr, vrf_id_t vrf_id)
{
struct prefix_ipv6 p;
struct route_table *table;
int recursing;
/* Lookup table. */
- table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
+ table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
if (! table)
return 0;
switch (nexthop->type)
{
case NEXTHOP_TYPE_IFINDEX:
- ifp = if_lookup_by_index (nexthop->ifindex);
+ ifp = if_lookup_by_index_vrf (nexthop->ifindex, rib->vrf_id);
if (ifp && if_is_operative(ifp))
SET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
else
case NEXTHOP_TYPE_IPV6_IFNAME:
family = AFI_IP6;
case NEXTHOP_TYPE_IFNAME:
- ifp = if_lookup_by_name (nexthop->ifname);
+ ifp = if_lookup_by_name_vrf (nexthop->ifname, rib->vrf_id);
if (ifp && if_is_operative(ifp))
{
if (set)
family = AFI_IP6;
if (IN6_IS_ADDR_LINKLOCAL (&nexthop->gate.ipv6))
{
- ifp = if_lookup_by_index (nexthop->ifindex);
+ ifp = if_lookup_by_index_vrf (nexthop->ifindex, rib->vrf_id);
if (ifp && if_is_operative(ifp))
SET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
else
int
rib_add_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p,
struct in_addr *gate, struct in_addr *src,
- unsigned int ifindex, u_int32_t table_id,
+ unsigned int ifindex, vrf_id_t vrf_id, u_int32_t table_id,
u_int32_t metric, u_char distance, safi_t safi)
{
struct rib *rib;
/* Lookup table. */
if ((table_id == RT_TABLE_MAIN) || (table_id == zebrad.rtm_table_default))
{
- table = zebra_vrf_table (AFI_IP, safi, VRF_DEFAULT);
+ table = zebra_vrf_table (AFI_IP, safi, vrf_id);
}
else
{
- table = zebra_vrf_other_route_table (AFI_IP, table_id, VRF_DEFAULT);
+ table = zebra_vrf_other_route_table (AFI_IP, table_id, vrf_id);
}
if (! table)
return 0;
rib->flags = flags;
rib->metric = metric;
rib->table = table_id;
+ rib->vrf_id = vrf_id;
rib->nexthop_num = 0;
rib->uptime = time (NULL);
struct nexthop *nexthop, *tnexthop;
int recursing;
- inet_ntop (p->family, &p->u.prefix, straddr, INET6_ADDRSTRLEN);
- zlog_debug ("%s: dumping RIB entry %p for %s/%d", func, rib, straddr, p->prefixlen);
+ zlog_debug ("%s: dumping RIB entry %p for %s vrf %u", func, rib,
+ prefix2str(pp, straddr, sizeof(straddr)), rib->vrf_id);
zlog_debug
(
"%s: refcnt == %lu, uptime == %lu, type == %u, instance == %d, table == %d",
/* Lookup table. */
if ((rib->table == zebrad.rtm_table_default) || (rib->table == RT_TABLE_MAIN))
{
- table = zebra_vrf_table (AFI_IP, safi, VRF_DEFAULT);
+ table = zebra_vrf_table (AFI_IP, safi, rib->vrf_id);
}
else
{
- table = zebra_vrf_other_route_table (AFI_IP, rib->table, VRF_DEFAULT);
+ table = zebra_vrf_other_route_table (AFI_IP, rib->table, rib->vrf_id);
}
if (! table)
return 0;
/* XXX factor with rib_delete_ipv6 */
int
rib_delete_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p,
- struct in_addr *gate, unsigned int ifindex,
+ struct in_addr *gate, unsigned int ifindex, vrf_id_t vrf_id,
u_int32_t table_id, safi_t safi)
{
struct route_table *table;
/* Lookup table. */
if ((table_id == RT_TABLE_MAIN) || (table_id == zebrad.rtm_table_default))
{
- table = zebra_vrf_table (AFI_IP, safi, VRF_DEFAULT);
+ table = zebra_vrf_table (AFI_IP, safi, vrf_id);
}
else
{
- table = zebra_vrf_other_route_table(AFI_IP, table_id, VRF_DEFAULT);
+ table = zebra_vrf_other_route_table(AFI_IP, table_id, vrf_id);
}
if (! table)
return 0;
if (IS_ZEBRA_DEBUG_KERNEL)
{
if (gate)
- zlog_debug ("rib_delete_ipv4(): route delete %s/%d via %s ifindex %d",
- inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN),
- p->prefixlen,
+ zlog_debug ("rib_delete_ipv4(): route delete %s vrf %u via %s ifindex %d",
+ prefix2str (p, buf1, sizeof(buf1)), vrf_id,
inet_ntoa (*gate),
ifindex);
else
- zlog_debug ("rib_delete_ipv4(): route delete %s/%d ifindex %d",
- inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN),
- p->prefixlen,
+ zlog_debug ("rib_delete_ipv4(): route delete %s vrf %u ifindex %d",
+ prefix2str (p, buf1, sizeof(buf1)), vrf_id,
ifindex);
}
if (IS_ZEBRA_DEBUG_KERNEL)
{
if (gate)
- zlog_debug ("route %s/%d via %s ifindex %d doesn't exist in rib",
- inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN),
- p->prefixlen,
+ zlog_debug ("route %s vrf %u via %s ifindex %d doesn't exist in rib",
+ prefix2str (p, buf1, sizeof(buf1)), vrf_id,
inet_ntop (AF_INET, gate, buf2, INET_ADDRSTRLEN),
ifindex);
else
- zlog_debug ("route %s/%d ifindex %d doesn't exist in rib",
- inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN),
- p->prefixlen,
+ zlog_debug ("route %s vrf %u ifindex %d doesn't exist in rib",
+ prefix2str (p, buf1, sizeof(buf1)), vrf_id,
ifindex);
}
return ZEBRA_ERR_RTNOEXIST;
if (IS_ZEBRA_DEBUG_KERNEL)
{
if (gate)
- zlog_debug ("route %s/%d via %s ifindex %d type %d doesn't exist in rib",
- inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN),
- p->prefixlen,
+ zlog_debug ("route %s vrf %u via %s ifindex %d type %d "
+ "doesn't exist in rib",
+ prefix2str (p, buf1, sizeof(buf1)), vrf_id,
inet_ntop (AF_INET, gate, buf2, INET_ADDRSTRLEN),
ifindex,
type);
else
- zlog_debug ("route %s/%d ifindex %d type %d doesn't exist in rib",
- inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN),
- p->prefixlen,
+ zlog_debug ("route %s vrf %u ifindex %d type %d doesn't exist in rib",
+ prefix2str (p, buf1, sizeof(buf1)), vrf_id,
ifindex,
type);
}
rib->instance = 0;
rib->distance = si->distance;
rib->metric = 0;
+ rib->vrf_id = VRF_DEFAULT;
rib->table = zebrad.rtm_table_default;
rib->nexthop_num = 0;
rib->tag = si->tag;
/* Add static route into static route configuration. */
int
static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
- u_char flags, u_short tag, u_char distance, u_int32_t vrf_id)
+ u_char flags, u_short tag, u_char distance, vrf_id_t vrf_id)
{
u_char type = 0;
struct route_node *rn;
struct static_ipv4 *pp;
struct static_ipv4 *cp;
struct static_ipv4 *update = NULL;
- struct route_table *stable;
+ struct zebra_vrf *zvrf = vrf_info_get (vrf_id);
+ struct route_table *stable = zvrf->stable[AFI_IP][SAFI_UNICAST];
- /* Lookup table. */
- stable = zebra_vrf_static_table (AFI_IP, SAFI_UNICAST, vrf_id);
if (! stable)
return -1;
/* Delete static route from static route configuration. */
int
static_delete_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
- u_short tag, u_char distance, u_int32_t vrf_id)
+ u_short tag, u_char distance, vrf_id_t vrf_id)
{
u_char type = 0;
struct route_node *rn;
int
rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p,
- struct in6_addr *gate, unsigned int ifindex, u_int32_t table_id,
- u_int32_t metric, u_char distance, safi_t safi)
+ struct in6_addr *gate, unsigned int ifindex, vrf_id_t vrf_id,
+ u_int32_t table_id, u_int32_t metric, u_char distance, safi_t safi)
{
struct rib *rib;
struct rib *same = NULL;
/* Lookup table. */
if ((table_id == RT_TABLE_MAIN) || (table_id == zebrad.rtm_table_default))
{
- table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
+ table = zebra_vrf_table (AFI_IP6, safi, vrf_id);
}
else
{
- table = zebra_vrf_other_route_table(AFI_IP6, table_id, VRF_DEFAULT);
+ table = zebra_vrf_other_route_table(AFI_IP6, table_id, vrf_id);
}
if (! table)
return 0;
rib->flags = flags;
rib->metric = metric;
rib->table = table_id;
+ rib->vrf_id = vrf_id;
rib->nexthop_num = 0;
rib->uptime = time (NULL);
/* XXX factor with rib_delete_ipv6 */
int
rib_delete_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p,
- struct in6_addr *gate, unsigned int ifindex, u_int32_t table_id, safi_t safi)
+ struct in6_addr *gate, unsigned int ifindex, vrf_id_t vrf_id,
+ u_int32_t table_id, safi_t safi)
{
struct route_table *table;
struct route_node *rn;
/* Lookup table. */
if ((table_id == RT_TABLE_MAIN) || (table_id == zebrad.rtm_table_default))
{
- table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
+ table = zebra_vrf_table (AFI_IP6, safi, vrf_id);
}
else
{
if (IS_ZEBRA_DEBUG_KERNEL)
{
if (gate)
- zlog_debug ("route %s/%d via %s ifindex %d doesn't exist in rib",
- inet_ntop (AF_INET6, &p->prefix, buf1, INET6_ADDRSTRLEN),
- p->prefixlen,
+ zlog_debug ("route %s vrf %u via %s ifindex %d doesn't exist in rib",
+ prefix2str (p, buf1, sizeof(buf1)), vrf_id,
inet_ntop (AF_INET6, gate, buf2, INET6_ADDRSTRLEN),
ifindex);
else
- zlog_debug ("route %s/%d ifindex %d doesn't exist in rib",
- inet_ntop (AF_INET6, &p->prefix, buf1, INET6_ADDRSTRLEN),
- p->prefixlen,
+ zlog_debug ("route %s vrf %u ifindex %d doesn't exist in rib",
+ prefix2str (p, buf1, sizeof(buf1)), vrf_id,
ifindex);
}
return ZEBRA_ERR_RTNOEXIST;
if (IS_ZEBRA_DEBUG_KERNEL)
{
if (gate)
- zlog_debug ("route %s/%d via %s ifindex %d type %d doesn't exist in rib",
- inet_ntop (AF_INET6, &p->prefix, buf1, INET6_ADDRSTRLEN),
- p->prefixlen,
+ zlog_debug ("route %s vrf %u via %s ifindex %d type %d "
+ "doesn't exist in rib",
+ prefix2str (p, buf1, sizeof(buf1)), vrf_id,
inet_ntop (AF_INET6, gate, buf2, INET6_ADDRSTRLEN),
ifindex,
type);
else
- zlog_debug ("route %s/%d ifindex %d type %d doesn't exist in rib",
- inet_ntop (AF_INET6, &p->prefix, buf1, INET6_ADDRSTRLEN),
- p->prefixlen,
+ zlog_debug ("route %s vrf %u ifindex %d type %d doesn't exist in rib",
+ prefix2str (p, buf1, sizeof(buf1)), vrf_id,
ifindex,
type);
}
rib->instance = 0;
rib->distance = si->distance;
rib->metric = 0;
+ rib->vrf_id = VRF_DEFAULT;
rib->table = zebrad.rtm_table_default;
rib->nexthop_num = 0;
rib->tag = si->tag;
int
static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
const char *ifname, u_char flags, u_short tag,
- u_char distance, u_int32_t vrf_id)
+ u_char distance, vrf_id_t vrf_id)
{
struct route_node *rn;
struct static_ipv6 *si;
struct static_ipv6 *pp;
struct static_ipv6 *cp;
- struct route_table *stable;
+ struct zebra_vrf *zvrf = vrf_info_get (vrf_id);
+ struct route_table *stable = zvrf->stable[AFI_IP6][SAFI_UNICAST];
- /* Lookup table. */
- stable = zebra_vrf_static_table (AFI_IP6, SAFI_UNICAST, vrf_id);
if (! stable)
return -1;
int
static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
const char *ifname, u_short tag, u_char distance,
- u_int32_t vrf_id)
+ vrf_id_t vrf_id)
{
struct route_node *rn;
struct static_ipv6 *si;
/* RIB update function. */
void
-rib_update_static (void)
+rib_update_static (vrf_id_t vrf_id)
{
struct route_node *rn;
struct route_table *table;
struct rib *rib, *next;
- 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_SAFE (rn, rib, next)
break;
}
- 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_SAFE (rn, rib, next)
/* RIB update function. */
void
-rib_update (void)
+rib_update (vrf_id_t vrf_id)
{
struct route_node *rn;
struct route_table *table;
- 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))
if (rnode_to_ribs (rn))
rib_queue_add (&zebrad, rn);
- 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))
if (rnode_to_ribs (rn))
void
rib_weed_tables (void)
{
- rib_weed_table (zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT));
- rib_weed_table (zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT));
+ vrf_iter_t iter;
+ struct zebra_vrf *zvrf;
+
+ for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+ if ((zvrf = vrf_iter2info (iter)) != NULL)
+ {
+ rib_weed_table (zvrf->table[AFI_IP][SAFI_UNICAST]);
+ rib_weed_table (zvrf->table[AFI_IP6][SAFI_UNICAST]);
+ }
}
/* Delete self installed routes after zebra is relaunched. */
void
rib_sweep_route (void)
{
- rib_sweep_table (zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT));
- rib_sweep_table (zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT));
+ vrf_iter_t iter;
+ struct zebra_vrf *zvrf;
+
+ for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+ if ((zvrf = vrf_iter2info (iter)) != NULL)
+ {
+ rib_sweep_table (zvrf->table[AFI_IP][SAFI_UNICAST]);
+ rib_sweep_table (zvrf->table[AFI_IP6][SAFI_UNICAST]);
+ }
}
/* Remove specific by protocol routes from 'table'. */
unsigned long
rib_score_proto (u_char proto, u_short instance)
{
- return rib_score_proto_table (proto, instance, zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT))
- +rib_score_proto_table (proto, instance, zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT));
+ vrf_iter_t iter;
+ struct zebra_vrf *zvrf;
+ unsigned long cnt = 0;
+
+ for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+ if ((zvrf = vrf_iter2info (iter)) != NULL)
+ cnt += rib_score_proto_table (proto, instance, zvrf->table[AFI_IP][SAFI_UNICAST])
+ +rib_score_proto_table (proto, instance, zvrf->table[AFI_IP6][SAFI_UNICAST]);
+
+ return cnt;
}
/* Close RIB and clean up kernel routes. */
void
rib_close (void)
{
- struct listnode *node, *nnode;
+ vrf_iter_t iter;
+ struct zebra_vrf *zvrf;
+ struct listnode *node;
struct interface *ifp;
- rib_close_table (zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT));
- rib_close_table (zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT));
-
- for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp))
- if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(ifp);
+ for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+ {
+ if ((zvrf = vrf_iter2info (iter)) != NULL)
+ {
+ rib_close_table (zvrf->table[AFI_IP][SAFI_UNICAST]);
+ rib_close_table (zvrf->table[AFI_IP6][SAFI_UNICAST]);
+ }
+ for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist (iter), node, ifp))
+ if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(ifp);
+ }
}
/* Routing information base initialize. */
case NEXTHOP_TYPE_IPV4_IFINDEX:
vty_out (vty, " %s", inet_ntoa (nexthop->gate.ipv4));
if (nexthop->ifindex)
- vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex));
+ vty_out (vty, ", via %s",
+ ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
break;
#ifdef HAVE_IPV6
case NEXTHOP_TYPE_IPV6:
if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
vty_out (vty, ", %s", nexthop->ifname);
else if (nexthop->ifindex)
- vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex));
+ vty_out (vty, ", via %s",
+ ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
break;
#endif /* HAVE_IPV6 */
case NEXTHOP_TYPE_IFINDEX:
vty_out (vty, " directly connected, %s",
- ifindex2ifname (nexthop->ifindex));
+ ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
break;
case NEXTHOP_TYPE_IFNAME:
vty_out (vty, " directly connected, %s", nexthop->ifname);
case NEXTHOP_TYPE_IPV4_IFINDEX:
vty_out (vty, " via %s", inet_ntoa (nexthop->gate.ipv4));
if (nexthop->ifindex)
- vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex));
+ vty_out (vty, ", %s",
+ ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
break;
#ifdef HAVE_IPV6
case NEXTHOP_TYPE_IPV6:
if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
vty_out (vty, ", %s", nexthop->ifname);
else if (nexthop->ifindex)
- vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex));
+ vty_out (vty, ", %s",
+ ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
break;
#endif /* HAVE_IPV6 */
case NEXTHOP_TYPE_IFINDEX:
vty_out (vty, " is directly connected, %s",
- ifindex2ifname (nexthop->ifindex));
+ ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
break;
case NEXTHOP_TYPE_IFNAME:
vty_out (vty, " is directly connected, %s", nexthop->ifname);
#include "network.h"
#include "buffer.h"
#include "nexthop.h"
+#include "vrf.h"
#include "zebra/zserv.h"
#include "zebra/router-id.h"
struct nexthop *nexthop;
/* Lookup nexthop. */
- rib = rib_match_ipv6 (addr);
+ rib = rib_match_ipv6 (addr, VRF_DEFAULT);
/* Get output stream. */
s = client->obuf;
struct nexthop *nexthop;
/* Lookup nexthop. */
- rib = rib_match_ipv4 (addr);
+ rib = rib_match_ipv4 (addr, VRF_DEFAULT);
/* Get output stream. */
s = client->obuf;
struct nexthop *nexthop;
/* Lookup nexthop. */
- rib = rib_lookup_ipv4 (p);
+ rib = rib_lookup_ipv4 (p, VRF_DEFAULT);
/* Get output stream. */
s = client->obuf;
p.prefixlen = stream_getc (s);
stream_get (&p.prefix, s, PSIZE (p.prefixlen));
+ /* VRF ID */
+ rib->vrf_id = VRF_DEFAULT;
+
/* Nexthop parse. */
if (CHECK_FLAG (message, ZAPI_MESSAGE_NEXTHOP))
{
api.tag = 0;
rib_delete_ipv4 (api.type, api.instance, api.flags, &p, nexthop_p, ifindex,
- client->rtm_table, api.safi);
+ VRF_DEFAULT, client->rtm_table, api.safi);
client->v4_route_del_cnt++;
return 0;
}
/* Table */
rib->table=zebrad.rtm_table_default;
+ rib->vrf_id = VRF_DEFAULT;
ret = rib_add_ipv6_multipath ((struct prefix *)&p, rib, safi, ifindex);
/* Stats */
if (ret > 0)
api.tag = 0;
if (IN6_IS_ADDR_UNSPECIFIED (&nexthop))
- rib_delete_ipv6 (api.type, api.instance, api.flags, &p, NULL, ifindex, client->rtm_table, api.safi);
+ rib_delete_ipv6 (api.type, api.instance, api.flags, &p, NULL, ifindex,
+ VRF_DEFAULT, client->rtm_table, api.safi);
else
- rib_delete_ipv6 (api.type, api.instance, api.flags, &p, &nexthop, ifindex, client->rtm_table, api.safi);
+ rib_delete_ipv6 (api.type, api.instance, api.flags, &p, &nexthop, ifindex,
+ VRF_DEFAULT, client->rtm_table, api.safi);
client->v6_route_del_cnt++;
return 0;