From: Donald Sharp Date: Wed, 27 Apr 2016 20:22:13 +0000 (-0400) Subject: zebra: Stop passing around vrf_id for static_XXX functions X-Git-Tag: frr-2.0-rc1~948 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=b9f1114e3875b7859acf21fe12643473c902a8c6;p=matthieu%2Ffrr.git zebra: Stop passing around vrf_id for static_XXX functions The static zebra functions are passing around the vrf_id At the crunchy edges gather the zvrf from passed in vrf name and pass that around instead. Signed-off-by: Don Slice Signed-off-by: Donald Sharp --- diff --git a/zebra/rib.h b/zebra/rib.h index 555bb46426..f22d7aa420 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -382,11 +382,11 @@ extern void rib_queue_add (struct route_node *rn); 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, @@ -407,7 +407,7 @@ extern struct route_table *rib_table_ipv6; 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, @@ -416,7 +416,7 @@ 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); diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index b41ebaab02..59da68e245 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -3020,7 +3020,7 @@ static_uninstall_route (afi_t afi, safi_t safi, struct prefix *p, struct static_ /* 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; @@ -3028,7 +3028,6 @@ static_add_ipv4 (struct prefix *p, struct in_addr *gate, unsigned int ifindex, 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) @@ -3064,7 +3063,7 @@ static_add_ipv4 (struct prefix *p, struct in_addr *gate, unsigned int ifindex, /* 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)); @@ -3073,7 +3072,7 @@ static_add_ipv4 (struct prefix *p, struct in_addr *gate, unsigned int ifindex, 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) @@ -3115,13 +3114,12 @@ static_add_ipv4 (struct prefix *p, struct in_addr *gate, unsigned int ifindex, /* 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); @@ -3541,14 +3539,13 @@ rib_delete_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, 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) @@ -3584,7 +3581,7 @@ static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, /* 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)); @@ -3593,7 +3590,7 @@ static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, 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) @@ -3636,12 +3633,11 @@ static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, 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); diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 1dcc55a9ff..37e28f2709 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -38,6 +38,26 @@ 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, @@ -52,7 +72,7 @@ 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); @@ -88,8 +108,13 @@ zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str, 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)) @@ -100,9 +125,9 @@ zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str, 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; } @@ -126,9 +151,9 @@ zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str, 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; } @@ -138,7 +163,7 @@ zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str, 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); @@ -148,9 +173,9 @@ zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str, } 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; } @@ -3196,14 +3221,13 @@ static_config_ipv4 (struct vty *vty, safi_t safi, const char *cmd) 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; @@ -3243,12 +3267,7 @@ static_config_ipv4 (struct vty *vty, safi_t safi, const char *cmd) 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); @@ -3355,11 +3374,11 @@ static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str, 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) @@ -3403,8 +3422,13 @@ static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str, 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) { @@ -3417,7 +3441,7 @@ static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str, } 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); @@ -3435,7 +3459,7 @@ static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str, 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); @@ -3446,9 +3470,9 @@ static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str, } 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; }