mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-09 05:13:07 +00:00
zebra: Refactor v4 and v6 static_add into 1 function
Refactor the static_add_ipv[4|6] functions into 1 function call. They are basically doing the exact same thing no need for separate code paths. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
This commit is contained in:
parent
c7cfcb75e9
commit
3a3d00f1bd
@ -310,37 +310,42 @@ static_uninstall_route (afi_t afi, safi_t safi, struct prefix *p, struct static_
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
static_add_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, ifindex_t ifindex,
|
static_add_route (afi_t afi, safi_t safi, u_char type, struct prefix *p,
|
||||||
|
union g_addr *gate, ifindex_t ifindex,
|
||||||
const char *ifname, u_char flags, u_short tag,
|
const char *ifname, u_char flags, u_short tag,
|
||||||
u_char distance, struct zebra_vrf *zvrf)
|
u_char distance, struct zebra_vrf *zvrf)
|
||||||
{
|
{
|
||||||
u_char type = 0;
|
|
||||||
struct route_node *rn;
|
struct route_node *rn;
|
||||||
struct static_route *si;
|
struct static_route *si;
|
||||||
struct static_route *pp;
|
struct static_route *pp;
|
||||||
struct static_route *cp;
|
struct static_route *cp;
|
||||||
struct static_route *update = NULL;
|
struct static_route *update = NULL;
|
||||||
struct route_table *stable = zvrf->stable[AFI_IP][safi];
|
struct route_table *stable = zvrf->stable[afi][safi];
|
||||||
|
|
||||||
if (! stable)
|
if (! stable)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (!gate &&
|
||||||
|
(type == STATIC_IPV4_GATEWAY ||
|
||||||
|
type == STATIC_IPV6_GATEWAY ||
|
||||||
|
type == STATIC_IPV6_GATEWAY_IFINDEX))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (!ifindex &&
|
||||||
|
(type == STATIC_IFINDEX ||
|
||||||
|
type == STATIC_IPV6_GATEWAY_IFINDEX))
|
||||||
|
return -1;
|
||||||
|
|
||||||
/* Lookup static route prefix. */
|
/* Lookup static route prefix. */
|
||||||
rn = route_node_get (stable, p);
|
rn = route_node_get (stable, p);
|
||||||
|
|
||||||
/* Make flags. */
|
|
||||||
if (gate)
|
|
||||||
type = STATIC_IPV4_GATEWAY;
|
|
||||||
else if (ifindex)
|
|
||||||
type = STATIC_IFINDEX;
|
|
||||||
else
|
|
||||||
type = STATIC_IPV4_BLACKHOLE;
|
|
||||||
|
|
||||||
/* Do nothing if there is a same static route. */
|
/* Do nothing if there is a same static route. */
|
||||||
for (si = rn->info; si; si = si->next)
|
for (si = rn->info; si; si = si->next)
|
||||||
{
|
{
|
||||||
if (type == si->type
|
if (type == si->type
|
||||||
&& (! gate || IPV4_ADDR_SAME (gate, &si->addr.ipv4))
|
&& (! gate ||
|
||||||
|
((afi == AFI_IP && IPV4_ADDR_SAME (gate, &si->addr.ipv4)) ||
|
||||||
|
(afi == AFI_IP6 && IPV6_ADDR_SAME (gate, &si->addr.ipv6))))
|
||||||
&& (! ifindex || ifindex == si->ifindex))
|
&& (! ifindex || ifindex == si->ifindex))
|
||||||
{
|
{
|
||||||
if ((distance == si->distance) && (tag == si->tag))
|
if ((distance == si->distance) && (tag == si->tag))
|
||||||
@ -355,7 +360,7 @@ static_add_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, ifindex_t
|
|||||||
|
|
||||||
/* Distance or tag changed. */
|
/* Distance or tag changed. */
|
||||||
if (update)
|
if (update)
|
||||||
static_delete_route (AFI_IP, safi, type, p, (union g_addr *)gate,
|
static_delete_route (afi, safi, type, p, gate,
|
||||||
ifindex, update->tag, update->distance, zvrf);
|
ifindex, update->tag, update->distance, zvrf);
|
||||||
|
|
||||||
/* Make new static route structure. */
|
/* Make new static route structure. */
|
||||||
@ -370,8 +375,20 @@ static_add_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, ifindex_t
|
|||||||
if (si->ifindex)
|
if (si->ifindex)
|
||||||
strcpy(si->ifname, ifname);
|
strcpy(si->ifname, ifname);
|
||||||
|
|
||||||
if (gate)
|
switch (type)
|
||||||
si->addr.ipv4 = *gate;
|
{
|
||||||
|
case STATIC_IPV4_GATEWAY:
|
||||||
|
si->addr.ipv4 = gate->ipv4;
|
||||||
|
break;
|
||||||
|
case STATIC_IPV6_GATEWAY:
|
||||||
|
si->addr.ipv6 = gate->ipv6;
|
||||||
|
break;
|
||||||
|
case STATIC_IPV6_GATEWAY_IFINDEX:
|
||||||
|
si->addr.ipv6 = gate->ipv6;
|
||||||
|
break;
|
||||||
|
case STATIC_IFINDEX:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* Add new static route information to the tree with sort by
|
/* Add new static route information to the tree with sort by
|
||||||
distance value and gateway address. */
|
distance value and gateway address. */
|
||||||
@ -401,7 +418,7 @@ static_add_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, ifindex_t
|
|||||||
si->next = cp;
|
si->next = cp;
|
||||||
|
|
||||||
/* Install into rib. */
|
/* Install into rib. */
|
||||||
static_install_route (AFI_IP, safi, p, si);
|
static_install_route (afi, safi, p, si);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -461,101 +478,3 @@ static_delete_route (afi_t afi, safi_t safi, u_char type, struct prefix *p,
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add static route into static route configuration. */
|
|
||||||
int
|
|
||||||
static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
|
|
||||||
ifindex_t ifindex, const char *ifname, u_char flags,
|
|
||||||
u_short tag, 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 route_table *stable = zvrf->stable[AFI_IP6][SAFI_UNICAST];
|
|
||||||
|
|
||||||
if (! stable)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (!gate &&
|
|
||||||
(type == STATIC_IPV6_GATEWAY || type == STATIC_IPV6_GATEWAY_IFINDEX))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (!ifindex &&
|
|
||||||
(type == STATIC_IPV6_GATEWAY_IFINDEX || type == STATIC_IFINDEX))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
/* Lookup static route prefix. */
|
|
||||||
rn = route_node_get (stable, p);
|
|
||||||
|
|
||||||
/* Do nothing if there is a same static route. */
|
|
||||||
for (si = rn->info; si; si = si->next)
|
|
||||||
{
|
|
||||||
if (type == si->type
|
|
||||||
&& (! gate || IPV6_ADDR_SAME (gate, &si->addr.ipv6))
|
|
||||||
&& (! ifindex || ifindex == si->ifindex))
|
|
||||||
{
|
|
||||||
if ((distance == si->distance) && (tag == si->tag))
|
|
||||||
{
|
|
||||||
route_unlock_node (rn);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
update = si;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Distance or tag changed. */
|
|
||||||
if (update)
|
|
||||||
static_delete_route (AFI_IP6, SAFI_UNICAST, type, p,
|
|
||||||
(union g_addr *)gate, ifindex,
|
|
||||||
update->tag, update->distance, zvrf);
|
|
||||||
|
|
||||||
/* Make new static route structure. */
|
|
||||||
si = XCALLOC (MTYPE_STATIC_ROUTE, sizeof (struct static_route));
|
|
||||||
|
|
||||||
si->type = type;
|
|
||||||
si->distance = distance;
|
|
||||||
si->flags = flags;
|
|
||||||
si->tag = tag;
|
|
||||||
si->vrf_id = zvrf->vrf_id;
|
|
||||||
si->ifindex = ifindex;
|
|
||||||
if (si->ifindex)
|
|
||||||
strcpy (si->ifname, ifname);
|
|
||||||
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case STATIC_IPV6_GATEWAY:
|
|
||||||
si->addr.ipv6 = *gate;
|
|
||||||
break;
|
|
||||||
case STATIC_IPV6_GATEWAY_IFINDEX:
|
|
||||||
si->addr.ipv6 = *gate;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Add new static route information to the tree with sort by
|
|
||||||
distance value and gateway address. */
|
|
||||||
for (pp = NULL, cp = rn->info; cp; pp = cp, cp = cp->next)
|
|
||||||
{
|
|
||||||
if (si->distance < cp->distance)
|
|
||||||
break;
|
|
||||||
if (si->distance > cp->distance)
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make linked list. */
|
|
||||||
if (pp)
|
|
||||||
pp->next = si;
|
|
||||||
else
|
|
||||||
rn->info = si;
|
|
||||||
if (cp)
|
|
||||||
cp->prev = si;
|
|
||||||
si->prev = pp;
|
|
||||||
si->next = cp;
|
|
||||||
|
|
||||||
/* Install into rib. */
|
|
||||||
static_install_route (AFI_IP6, SAFI_UNICAST, p, si);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
@ -74,7 +74,8 @@ extern void
|
|||||||
static_uninstall_route (afi_t afi, safi_t safi, struct prefix *p, struct static_route *si);
|
static_uninstall_route (afi_t afi, safi_t safi, struct prefix *p, struct static_route *si);
|
||||||
|
|
||||||
extern int
|
extern int
|
||||||
static_add_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, ifindex_t ifindex,
|
static_add_route (afi_t, safi_t safi, u_char type, struct prefix *p,
|
||||||
|
union g_addr *gate, ifindex_t ifindex,
|
||||||
const char *ifname, u_char flags, u_short tag,
|
const char *ifname, u_char flags, u_short tag,
|
||||||
u_char distance, struct zebra_vrf *zvrf);
|
u_char distance, struct zebra_vrf *zvrf);
|
||||||
|
|
||||||
@ -84,9 +85,5 @@ static_delete_route (afi_t, safi_t safi, u_char type, struct prefix *p,
|
|||||||
u_short tag, u_char distance,
|
u_short tag, u_char distance,
|
||||||
struct zebra_vrf *zvrf);
|
struct zebra_vrf *zvrf);
|
||||||
|
|
||||||
extern int
|
|
||||||
static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
|
|
||||||
ifindex_t ifindex, const char *ifname, u_char flags,
|
|
||||||
u_short tag, u_char distance, struct zebra_vrf *zvrf);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -118,7 +118,7 @@ zebra_static_ipv4 (struct vty *vty, safi_t safi, int add_cmd,
|
|||||||
return CMD_WARNING;
|
return CMD_WARNING;
|
||||||
}
|
}
|
||||||
if (add_cmd)
|
if (add_cmd)
|
||||||
static_add_ipv4 (safi, &p, NULL, ifindex, ifname, ZEBRA_FLAG_BLACKHOLE, tag, distance, zvrf);
|
static_add_route (AFI_IP, safi, type, &p, NULL, ifindex, ifname, ZEBRA_FLAG_BLACKHOLE, tag, distance, zvrf);
|
||||||
else
|
else
|
||||||
static_delete_route (AFI_IP, safi, type, &p, NULL, ifindex, tag, distance, zvrf);
|
static_delete_route (AFI_IP, safi, type, &p, NULL, ifindex, tag, distance, zvrf);
|
||||||
return CMD_SUCCESS;
|
return CMD_SUCCESS;
|
||||||
@ -143,9 +143,8 @@ zebra_static_ipv4 (struct vty *vty, safi_t safi, int add_cmd,
|
|||||||
|
|
||||||
if (gate_str == NULL)
|
if (gate_str == NULL)
|
||||||
{
|
{
|
||||||
type = STATIC_IFINDEX;
|
|
||||||
if (add_cmd)
|
if (add_cmd)
|
||||||
static_add_ipv4 (safi, &p, NULL, ifindex, ifname, flag, tag, distance, zvrf);
|
static_add_route (AFI_IP, safi, type, &p, NULL, ifindex, ifname, flag, tag, distance, zvrf);
|
||||||
else
|
else
|
||||||
static_delete_route (AFI_IP, safi, type, &p, NULL, ifindex, tag, distance, zvrf);
|
static_delete_route (AFI_IP, safi, type, &p, NULL, ifindex, tag, distance, zvrf);
|
||||||
|
|
||||||
@ -172,7 +171,7 @@ zebra_static_ipv4 (struct vty *vty, safi_t safi, int add_cmd,
|
|||||||
type = STATIC_IPV4_GATEWAY;
|
type = STATIC_IPV4_GATEWAY;
|
||||||
|
|
||||||
if (add_cmd)
|
if (add_cmd)
|
||||||
static_add_ipv4 (safi, &p, ifindex ? NULL : &gate, ifindex, ifname, flag, tag, distance, zvrf);
|
static_add_route (AFI_IP, safi, type, &p, ifindex ? NULL : (union g_addr *)&gate, ifindex, ifname, flag, tag, distance, zvrf);
|
||||||
else
|
else
|
||||||
static_delete_route (AFI_IP, safi, type, &p, ifindex ? NULL : (union g_addr *)&gate, ifindex, tag, distance, zvrf);
|
static_delete_route (AFI_IP, safi, type, &p, ifindex ? NULL : (union g_addr *)&gate, ifindex, tag, distance, zvrf);
|
||||||
|
|
||||||
@ -3738,7 +3737,7 @@ static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (add_cmd)
|
if (add_cmd)
|
||||||
static_add_ipv6 (&p, type, gate, ifindex, ifname, flag, tag, distance, zvrf);
|
static_add_route (AFI_IP6, SAFI_UNICAST, type, &p, (union g_addr *)gate, ifindex, ifname, flag, tag, distance, zvrf);
|
||||||
else
|
else
|
||||||
static_delete_route (AFI_IP6, SAFI_UNICAST, type, &p, (union g_addr *)gate, ifindex, tag, distance, zvrf);
|
static_delete_route (AFI_IP6, SAFI_UNICAST, type, &p, (union g_addr *)gate, ifindex, tag, distance, zvrf);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user