extern int
static_add_ipv4 (struct prefix *p, struct in_addr *gate, unsigned int ifindex,
- u_char flags, u_short tag, u_char distance, vrf_id_t vrf_id);
+ u_char flags, u_short tag, u_char distance, struct zebra_vrf *zvrf);
extern int
static_delete_ipv4 (struct prefix *p, struct in_addr *gate, unsigned int ifindex,
- u_short tag, u_char distance, vrf_id_t vrf_id);
+ u_short tag, u_char distance, struct zebra_vrf *zvrf);
extern int
rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p,
extern int
static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
unsigned int ifindex, u_char flags, u_short tag,
- u_char distance, vrf_id_t vrf_id);
+ u_char distance, struct zebra_vrf *zvrf);
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,
unsigned int ifindex, u_short tag, u_char distance,
- vrf_id_t vrf_id);
+ struct zebra_vrf *zvrf);
extern int rib_gc_dest (struct route_node *rn);
extern struct route_table *rib_tables_iter_next (rib_tables_iter_t *iter);
/* Add static route into static route configuration. */
int
static_add_ipv4 (struct prefix *p, struct in_addr *gate, unsigned int ifindex,
- u_char flags, u_short tag, u_char distance, vrf_id_t vrf_id)
+ u_char flags, u_short tag, u_char distance, struct zebra_vrf *zvrf)
{
u_char type = 0;
struct route_node *rn;
struct static_route *pp;
struct static_route *cp;
struct static_route *update = NULL;
- struct zebra_vrf *zvrf = vrf_info_get (vrf_id);
struct route_table *stable = zvrf->stable[AFI_IP][SAFI_UNICAST];
if (! stable)
/* Distance or tag changed. */
if (update)
- static_delete_ipv4 (p, gate, ifindex, update->tag, update->distance, vrf_id);
+ static_delete_ipv4 (p, gate, ifindex, update->tag, update->distance, zvrf);
/* Make new static route structure. */
si = XCALLOC (MTYPE_STATIC_ROUTE, sizeof (struct static_route));
si->distance = distance;
si->flags = flags;
si->tag = tag;
- si->vrf_id = vrf_id;
+ si->vrf_id = zvrf->vrf_id;
si->ifindex = ifindex;
if (gate)
/* Delete static route from static route configuration. */
int
static_delete_ipv4 (struct prefix *p, struct in_addr *gate, unsigned int ifindex,
- u_short tag, u_char distance, vrf_id_t vrf_id)
+ u_short tag, u_char distance, struct zebra_vrf *zvrf)
{
u_char type = 0;
struct route_node *rn;
struct static_route *si;
struct route_table *stable;
- struct zebra_vrf *zvrf = vrf_info_lookup (vrf_id);
/* Lookup table. */
stable = zebra_vrf_static_table (AFI_IP, SAFI_UNICAST, zvrf);
int
static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
unsigned int ifindex, u_char flags, u_short tag,
- u_char distance, vrf_id_t vrf_id)
+ u_char distance, struct zebra_vrf *zvrf)
{
struct route_node *rn;
struct static_route *si;
struct static_route *pp;
struct static_route *cp;
struct static_route *update = NULL;
- struct zebra_vrf *zvrf = vrf_info_get (vrf_id);
struct route_table *stable = zvrf->stable[AFI_IP6][SAFI_UNICAST];
if (! stable)
/* Distance or tag changed. */
if (update)
- static_delete_ipv6 (p, type, gate, ifindex, update->tag, update->distance, vrf_id);
+ static_delete_ipv6 (p, type, gate, ifindex, update->tag, update->distance, zvrf);
/* Make new static route structure. */
si = XCALLOC (MTYPE_STATIC_ROUTE, sizeof (struct static_route));
si->distance = distance;
si->flags = flags;
si->tag = tag;
- si->vrf_id = vrf_id;
+ si->vrf_id = zvrf->vrf_id;
si->ifindex = ifindex;
switch (type)
int
static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
unsigned int ifindex, u_short tag, u_char distance,
- vrf_id_t vrf_id)
+ struct zebra_vrf *zvrf)
{
struct route_node *rn;
struct static_route *si;
struct route_table *stable;
- struct zebra_vrf *zvrf = vrf_info_lookup (vrf_id);
/* Lookup table. */
stable = zebra_vrf_static_table (AFI_IP6, SAFI_UNICAST, zvrf);
extern int allow_delete;
+static struct zebra_vrf *
+zebra_vty_vrf_lookup (const char *vrf_id_str)
+{
+ struct vrf *vrf = NULL;
+
+ if (vrf_id_str)
+ {
+ vrf = vrf_list_lookup_by_name (vrf_id_str); //Pending: create VRF if the given vrf doesnt exist?
+ }
+ else
+ {
+ vrf = vrf_list_lookup_by_name (VRF_DEFAULT_NAME);
+ }
+
+ if (vrf)
+ return (struct zebra_vrf *)vrf->info;
+
+ return NULL;
+}
+
/* General fucntion for static route. */
static int
zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str,
struct in_addr mask;
u_char flag = 0;
u_short tag = 0;
- vrf_id_t vrf_id = VRF_DEFAULT;
+ struct zebra_vrf *zvrf = NULL;
unsigned int ifindex = 0;
ret = str2prefix (dest_str, &p);
tag = atoi(tag_str);
/* VRF id */
- if (vrf_id_str)
- VRF_GET_ID (vrf_id, vrf_id_str); //Pending: create VRF if the given vrf doesnt exist?
+ zvrf = zebra_vty_vrf_lookup (vrf_id_str);
+
+ if (!zvrf)
+ {
+ vty_out (vty, "%% vrf %s is not defined%s", vrf_id_str, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
/* Null0 static route. */
if ((gate_str != NULL) && (strncasecmp (gate_str, "Null0", strlen (gate_str)) == 0))
return CMD_WARNING;
}
if (add_cmd)
- static_add_ipv4 (&p, NULL, ifindex, ZEBRA_FLAG_BLACKHOLE, tag, distance, vrf_id);
+ static_add_ipv4 (&p, NULL, ifindex, ZEBRA_FLAG_BLACKHOLE, tag, distance, zvrf);
else
- static_delete_ipv4 (&p, NULL, ifindex, tag, distance, vrf_id);
+ static_delete_ipv4 (&p, NULL, ifindex, tag, distance, zvrf);
return CMD_SUCCESS;
}
if (gate_str == NULL)
{
if (add_cmd)
- static_add_ipv4 (&p, NULL, ifindex, flag, tag, distance, vrf_id);
+ static_add_ipv4 (&p, NULL, ifindex, flag, tag, distance, zvrf);
else
- static_delete_ipv4 (&p, NULL, ifindex, tag, distance, vrf_id);
+ static_delete_ipv4 (&p, NULL, ifindex, tag, distance, zvrf);
return CMD_SUCCESS;
}
ret = inet_aton (gate_str, &gate);
if (!ret)
{
- struct interface *ifp = if_lookup_by_name_vrf (gate_str, vrf_id);
+ struct interface *ifp = if_lookup_by_name_vrf (gate_str, zvrf->vrf_id);
if (!ifp)
{
vty_out (vty, "%% Unknown interface: %s%s", gate_str, VTY_NEWLINE);
}
if (add_cmd)
- static_add_ipv4 (&p, ifindex ? NULL : &gate, ifindex, flag, tag, distance, vrf_id);
+ static_add_ipv4 (&p, ifindex ? NULL : &gate, ifindex, flag, tag, distance, zvrf);
else
- static_delete_ipv4 (&p, ifindex ? NULL : &gate, ifindex, tag, distance, vrf_id);
+ static_delete_ipv4 (&p, ifindex ? NULL : &gate, ifindex, tag, distance, zvrf);
return CMD_SUCCESS;
}
struct static_route *si;
struct route_table *stable;
struct zebra_vrf *zvrf;
- vrf_iter_t iter;
- int write;
-
- write = 0;
+ int write =0;
+ struct listnode *node;
+ struct vrf *vrfp;
- for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+ for (ALL_LIST_ELEMENTS_RO (vrf_list, node, vrfp))
{
- if ((zvrf = vrf_iter2info (iter)) == NULL ||
+ if ((zvrf = vrfp->info) == NULL ||
(stable = zvrf->stable[AFI_IP][safi]) == NULL)
continue;
vty_out (vty, " %d", si->distance);
if (si->vrf_id != VRF_DEFAULT)
- {
- struct vrf *vrf;
-
- vrf = vrf_lookup(si->vrf_id);
- vty_out (vty, " vrf %s", vrf ? vrf->name : "");
- }
+ vty_out (vty, " vrf %s", vrfp ? vrfp->name : "");
vty_out (vty, "%s", VTY_NEWLINE);
struct in6_addr *gate = NULL;
struct in6_addr gate_addr;
u_char type = 0;
- vrf_id_t vrf_id = VRF_DEFAULT;
u_char flag = 0;
u_short tag = 0;
unsigned int ifindex = 0;
struct interface *ifp = NULL;
+ struct zebra_vrf *zvrf;
ret = str2prefix (dest_str, &p);
if (ret <= 0)
ret = inet_pton (AF_INET6, gate_str, &gate_addr);
/* VRF id */
- if (vrf_id_str)
- VRF_GET_ID (vrf_id, vrf_id_str);
+ zvrf = zebra_vty_vrf_lookup (vrf_id_str);
+
+ if (!zvrf)
+ {
+ vty_out (vty, "%% vrf %s is not defined%s", vrf_id_str, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
if (ifname)
{
}
type = STATIC_IPV6_GATEWAY_IFINDEX;
gate = &gate_addr;
- ifp = if_lookup_by_name_vrf (ifname, vrf_id);
+ ifp = if_lookup_by_name_vrf (ifname, zvrf->vrf_id);
if (!ifp)
{
vty_out (vty, "%% Malformed Interface name %s%s", ifname, VTY_NEWLINE);
else
{
type = STATIC_IFINDEX;
- ifp = if_lookup_by_name_vrf (gate_str, vrf_id);
+ ifp = if_lookup_by_name_vrf (gate_str, zvrf->vrf_id);
if (!ifp)
{
vty_out (vty, "%% Malformed Interface name %s%s", gate_str, VTY_NEWLINE);
}
if (add_cmd)
- static_add_ipv6 (&p, type, gate, ifindex, flag, tag, distance, vrf_id);
+ static_add_ipv6 (&p, type, gate, ifindex, flag, tag, distance, zvrf);
else
- static_delete_ipv6 (&p, type, gate, ifindex, tag, distance, vrf_id);
+ static_delete_ipv6 (&p, type, gate, ifindex, tag, distance, zvrf);
return CMD_SUCCESS;
}