These two functions are essentially the same.
Refactor.
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
void
connected_down_ipv4 (struct interface *ifp, struct connected *ifc)
{
- struct prefix_ipv4 p;
+ struct prefix p;
if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL))
return;
PREFIX_COPY_IPV4(&p, CONNECTED_PREFIX(ifc));
/* Apply mask to the network. */
- apply_mask_ipv4 (&p);
+ apply_mask (&p);
/* In case of connected address is 0.0.0.0/0 we treat it tunnel
address. */
- if (prefix_ipv4_any (&p))
+ if (prefix_ipv4_any ((struct prefix_ipv4 *)&p))
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, ifp->vrf_id, 0,
- SAFI_UNICAST);
+ rib_delete (AFI_IP, SAFI_UNICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT,
+ 0, 0, &p, NULL, ifp->ifindex, 0);
- rib_delete_ipv4 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, ifp->vrf_id, 0,
- SAFI_MULTICAST);
+ rib_delete (AFI_IP, SAFI_MULTICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT,
+ 0, 0, &p, NULL, ifp->ifindex, 0);
if (IS_ZEBRA_DEBUG_RIB_DETAILED)
zlog_debug ("%u: IF %s IPv4 address down, scheduling RIB processing",
void
connected_down_ipv6 (struct interface *ifp, struct connected *ifc)
{
- struct prefix_ipv6 p;
+ struct prefix p;
if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL))
return;
PREFIX_COPY_IPV6(&p, CONNECTED_PREFIX(ifc));
- apply_mask_ipv6 (&p);
+ apply_mask (&p);
- if (IN6_IS_ADDR_UNSPECIFIED (&p.prefix))
+ if (IN6_IS_ADDR_UNSPECIFIED (&p.u.prefix6))
return;
- rib_delete_ipv6 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex,
- ifp->vrf_id, 0, SAFI_UNICAST);
+ rib_delete (AFI_IP6, SAFI_UNICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT,
+ 0, 0, &p, NULL, ifp->ifindex, 0);
if (IS_ZEBRA_DEBUG_RIB_DETAILED)
zlog_debug ("%u: IF %s IPv6 address down, scheduling RIB processing",
if (dest.sa.sa_family == AF_INET)
{
- struct prefix_ipv4 p;
+ struct prefix p;
p.family = AF_INET;
- p.prefix = dest.sin.sin_addr;
+ p.u.prefix4 = dest.sin.sin_addr;
if (flags & RTF_HOST)
p.prefixlen = IPV4_MAX_PREFIXLEN;
else
* to specify the route really
*/
if (rtm->rtm_type == RTM_CHANGE)
- rib_delete_ipv4 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p,
- NULL, 0, VRF_DEFAULT, 0, SAFI_UNICAST);
+ rib_delete (AFI_IP, SAFI_UNICAST, VRF_DEFAULT, ZEBRA_ROUTE_KERNEL,
+ 0, zebra_flags, &p, NULL, 0, 0);
+ union g_addr ggate = { .ipv4 = gate.sin.sin_addr };
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, VRF_DEFAULT,
+ (struct prefix_ipv4 *)&p, &gate.sin.sin_addr, NULL, 0, VRF_DEFAULT,
0, 0, 0, 0, SAFI_UNICAST);
else
- rib_delete_ipv4 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags,
- &p, &gate.sin.sin_addr, 0, VRF_DEFAULT, 0, SAFI_UNICAST);
+ rib_delete (AFI_IP, SAFI_UNICAST, VRF_DEFAULT, ZEBRA_ROUTE_KERNEL,
+ 0, zebra_flags, &p, &&ggate, 0, 0);
}
-#ifdef HAVE_IPV6
if (dest.sa.sa_family == AF_INET6)
{
/* One day we might have a debug section here like one in the
*/
if (rtm->rtm_type != RTM_GET && rtm->rtm_pid == pid)
return;
- struct prefix_ipv6 p;
+ struct prefix p;
ifindex_t ifindex = 0;
p.family = AF_INET6;
- p.prefix = dest.sin6.sin6_addr;
+ p.u.prefix6 = dest.sin6.sin6_addr;
if (flags & RTF_HOST)
p.prefixlen = IPV6_MAX_PREFIXLEN;
else
* to specify the route really
*/
if (rtm->rtm_type == RTM_CHANGE)
- rib_delete_ipv6 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p,
- NULL, 0, VRF_DEFAULT, 0, SAFI_UNICAST);
-
+ rib_delete (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT, ZEBRA_ROUTE_KERNEL,
+ 0, zebra_flags, &p, NULL, 0, 0);
+
+ union g_addr ggate = { .ipv6 = gate.sin6.sin6_addr };
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, VRF_DEFAULT,
+ (struct prefix_ipv6 *)&p, &gate.sin6.sin6_addr,
+ ifindex, VRF_DEFAULT,
0, 0, 0, 0, SAFI_UNICAST);
else
- rib_delete_ipv6 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags,
- &p, &gate.sin6.sin6_addr, ifindex, VRF_DEFAULT, 0, SAFI_UNICAST);
+ rib_delete (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT, ZEBRA_ROUTE_KERNEL,
+ 0, zebra_flags, &p, &ggate, ifindex, 0);
}
-#endif /* HAVE_IPV6 */
}
/* Interface function for the kernel routing table updates. Support
int
zebra_del_import_table_entry (struct route_node *rn, struct rib *rib)
{
- struct prefix_ipv4 p4;
+ struct prefix p;
if (rn->p.family == AF_INET)
{
- p4.family = AF_INET;
- p4.prefixlen = rn->p.prefixlen;
- p4.prefix = rn->p.u.prefix4;
+ p.family = AF_INET;
+ p.prefixlen = rn->p.prefixlen;
+ p.u.prefix4 = rn->p.u.prefix4;
- rib_delete_ipv4(ZEBRA_ROUTE_TABLE, rib->table, rib->flags, &p4, NULL,
- 0, rib->vrf_id, zebrad.rtm_table_default, SAFI_UNICAST);
+ rib_delete (AFI_IP, SAFI_UNICAST, rib->vrf_id, ZEBRA_ROUTE_TABLE,
+ rib->table, rib->flags, &p, NULL,
+ 0, zebrad.rtm_table_default);
}
/* DD: Add IPv6 code */
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, ifindex_t ifindex,
- vrf_id_t, u_int32_t, safi_t safi);
+extern int rib_delete (afi_t afi, safi_t safi, vrf_id_t vrf_id, int type,
+ u_short instance, int flags, struct prefix *p,
+ union g_addr *gate, ifindex_t ifindex,
+ u_int32_t table_id);
extern struct rib *rib_match (afi_t afi, safi_t safi, vrf_id_t, union g_addr *,
struct route_node **rn_out);
u_int32_t table_id, u_int32_t metric, u_int32_t mtu,
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, ifindex_t ifindex, vrf_id_t vrf_id,
- u_int32_t table_id, safi_t safi);
-
extern struct rib *rib_lookup_ipv6 (struct in6_addr *, vrf_id_t);
extern struct route_table *rib_table_ipv6;
struct rtmsg *rtm;
struct rtattr *tb[RTA_MAX + 1];
u_char zebra_flags = 0;
-
+ struct prefix p;
+
char anyaddr[16] = { 0 };
int index;
if (rtm->rtm_family == AF_INET)
{
- struct prefix_ipv4 p;
p.family = AF_INET;
- memcpy (&p.prefix, dest, 4);
+ memcpy (&p.u.prefix4, dest, 4);
p.prefixlen = rtm->rtm_dst_len;
if (IS_ZEBRA_DEBUG_KERNEL)
if (h->nlmsg_type == RTM_NEWROUTE)
{
if (!tb[RTA_MULTIPATH])
- rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, 0, &p, gate, src, index, vrf_id,
+ rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, 0, (struct prefix_ipv4 *)&p, gate, src, index, vrf_id,
table, metric, mtu, 0, SAFI_UNICAST);
else
{
if (rib->nexthop_num == 0)
XFREE (MTYPE_RIB, rib);
else
- rib_add_ipv4_multipath (&p, rib, SAFI_UNICAST);
+ rib_add_ipv4_multipath ((struct prefix_ipv4 *)&p, rib, SAFI_UNICAST);
}
}
else
- rib_delete_ipv4 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, gate, index,
- vrf_id, table, SAFI_UNICAST);
+ rib_delete (AFI_IP, SAFI_UNICAST, vrf_id, ZEBRA_ROUTE_KERNEL, 0, zebra_flags,
+ &p, gate, index, table);
}
-#ifdef HAVE_IPV6
if (rtm->rtm_family == AF_INET6)
{
- struct prefix_ipv6 p;
+ struct prefix p;
p.family = AF_INET6;
- memcpy (&p.prefix, dest, 16);
+ memcpy (&p.u.prefix6, dest, 16);
p.prefixlen = rtm->rtm_dst_len;
if (IS_ZEBRA_DEBUG_KERNEL)
}
if (h->nlmsg_type == RTM_NEWROUTE)
- rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, 0, &p, gate, index, vrf_id,
+ rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, 0, (struct prefix_ipv6 *)&p, gate, index, vrf_id,
table, metric, mtu, 0, SAFI_UNICAST);
else
- rib_delete_ipv6 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, gate, index,
- vrf_id, table, SAFI_UNICAST);
+ rib_delete (AFI_IP6, SAFI_UNICAST, vrf_id, ZEBRA_ROUTE_KERNEL,
+ 0, zebra_flags, &p, gate, index, table);
}
-#endif /* HAVE_IPV6 */
return 0;
}
return ret;
}
-/* 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, ifindex_t ifindex, vrf_id_t vrf_id,
- u_int32_t table_id, safi_t safi)
+rib_delete (afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, u_short instance,
+ int flags, struct prefix *p, union g_addr *gate, ifindex_t ifindex,
+ u_int32_t table_id)
{
struct route_table *table;
struct route_node *rn;
char buf2[INET6_ADDRSTRLEN];
/* Lookup table. */
- table = zebra_vrf_table_with_table_id (AFI_IP, safi, vrf_id, table_id);
+ table = zebra_vrf_table_with_table_id (afi, safi, vrf_id, table_id);
if (! table)
return 0;
/* Apply mask. */
- apply_mask_ipv4 (p);
+ apply_mask (p);
/* Lookup route node. */
- rn = route_node_lookup (table, (struct prefix *) p);
+ rn = route_node_lookup (table, p);
if (! rn)
{
if (IS_ZEBRA_DEBUG_RIB)
break;
}
for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
- if (IPV4_ADDR_SAME (&nexthop->gate.ipv4, gate))
+ if (IPV4_ADDR_SAME (&nexthop->gate.ipv4, gate) ||
+ IPV6_ADDR_SAME (&nexthop->gate.ipv6, gate))
{
same = rib;
break;
{
if (IS_ZEBRA_DEBUG_RIB)
{
- zlog_debug ("%u:%s/%d: rn %p, rib %p (type %d) was deleted "
+ zlog_debug ("%u:%s: rn %p, rib %p (type %d) was deleted "
"from kernel, adding",
- vrf_id, inet_ntop (p->family, &p->prefix, buf1, INET6_ADDRSTRLEN),
- p->prefixlen, rn, fib, fib->type);
+ vrf_id, prefix2str(p, buf1, INET6_ADDRSTRLEN),
+ rn, fib, fib->type);
}
if (allow_delete)
{
zlog_debug ("%u:%s: via %s ifindex %d type %d "
"doesn't exist in rib",
vrf_id, prefix2str (p, buf1, sizeof(buf1)),
- inet_ntop (AF_INET, gate, buf2, INET_ADDRSTRLEN),
+ inet_ntop (family2afi(afi), gate, buf2, INET_ADDRSTRLEN),
ifindex,
type);
else
return ret;
}
-/* 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, ifindex_t ifindex, vrf_id_t vrf_id,
- u_int32_t table_id, safi_t safi)
-{
- struct route_table *table;
- struct route_node *rn;
- struct rib *rib;
- struct rib *fib = NULL;
- struct rib *same = NULL;
- struct nexthop *nexthop, *tnexthop;
- int recursing;
- char buf1[PREFIX_STRLEN];
- char buf2[INET6_ADDRSTRLEN];
-
- /* Apply mask. */
- apply_mask_ipv6 (p);
-
- /* Lookup table. */
- table = zebra_vrf_table_with_table_id (AFI_IP6, safi, vrf_id, table_id);
- if (! table)
- return 0;
-
- /* Lookup route node. */
- rn = route_node_lookup (table, (struct prefix *) p);
- if (! rn)
- {
- if (IS_ZEBRA_DEBUG_RIB)
- zlog_debug ("%u:%s: doesn't exist in rib",
- vrf_id, prefix2str (p, buf1, sizeof(buf1)));
- return ZEBRA_ERR_RTNOEXIST;
- }
-
- /* Lookup same type route. */
- RNODE_FOREACH_RIB (rn, rib)
- {
- if (CHECK_FLAG(rib->status, RIB_ENTRY_REMOVED))
- continue;
-
- if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
- fib = rib;
-
- if (rib->type != type)
- continue;
- if (rib->instance != instance)
- continue;
- if (rib->type == ZEBRA_ROUTE_CONNECT && (nexthop = rib->nexthop) &&
- nexthop->type == NEXTHOP_TYPE_IFINDEX)
- {
- if (nexthop->ifindex != ifindex)
- continue;
- if (rib->refcnt)
- {
- rib->refcnt--;
- route_unlock_node (rn);
- route_unlock_node (rn);
- return 0;
- }
- same = rib;
- break;
- }
- /* Make sure that the route found has the same gateway. */
- else
- {
- if (gate == NULL)
- {
- same = rib;
- break;
- }
- for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
- if (IPV6_ADDR_SAME (&nexthop->gate.ipv6, gate))
- {
- same = rib;
- break;
- }
- if (same)
- break;
- }
- }
-
- /* If same type of route can't be found and this message is from
- kernel. */
- if (! same)
- {
- if (fib && type == ZEBRA_ROUTE_KERNEL &&
- CHECK_FLAG(flags, ZEBRA_FLAG_SELFROUTE))
- {
- if (IS_ZEBRA_DEBUG_RIB)
- zlog_debug ("%u:%s/%d: rn %p, rib %p (type %d) was deleted "
- "from kernel, adding",
- vrf_id, inet_ntop (p->family, &p->prefix, buf1, INET6_ADDRSTRLEN),
- p->prefixlen, rn, fib, fib->type);
- if (allow_delete)
- {
- /* Unset flags. */
- for (nexthop = fib->nexthop; nexthop; nexthop = nexthop->next)
- UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB);
-
- UNSET_FLAG (fib->flags, ZEBRA_FLAG_SELECTED);
- }
- else
- {
- /* This means someone else, other than Zebra, has deleted a Zebra
- * route from the kernel. We will add it back */
- rib_install_kernel(rn, fib, 0);
- }
- }
- else
- {
- if (IS_ZEBRA_DEBUG_KERNEL)
- {
- if (gate)
- zlog_debug ("%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 ("%s: vrf %u ifindex %d type %d doesn't exist in rib",
- prefix2str (p, buf1, sizeof(buf1)), vrf_id,
- ifindex,
- type);
- }
- route_unlock_node (rn);
- return ZEBRA_ERR_RTNOEXIST;
- }
- }
-
- if (same)
- rib_delnode (rn, same);
-
- route_unlock_node (rn);
- return 0;
-}
-
/* Schedule routes of a particular table (address-family) based on event. */
static void
rib_update_table (struct route_table *table, rib_update_event_t event)
int i;
struct stream *s;
struct zapi_ipv4 api;
- struct in_addr nexthop, *nexthop_p;
+ struct in_addr nexthop;
+ union g_addr *nexthop_p;
unsigned long ifindex;
- struct prefix_ipv4 p;
+ struct prefix p;
u_char nexthop_num;
u_char nexthop_type;
u_int32_t table_id;
memset (&p, 0, sizeof (struct prefix_ipv4));
p.family = AF_INET;
p.prefixlen = stream_getc (s);
- stream_get (&p.prefix, s, PSIZE (p.prefixlen));
+ stream_get (&p.u.prefix4, s, PSIZE (p.prefixlen));
/* Nexthop, ifindex, distance, metric. */
if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
break;
case ZEBRA_NEXTHOP_IPV4:
nexthop.s_addr = stream_get_ipv4 (s);
- nexthop_p = &nexthop;
+ nexthop_p = (union g_addr *)&nexthop;
break;
case ZEBRA_NEXTHOP_IPV4_IFINDEX:
nexthop.s_addr = stream_get_ipv4 (s);
- nexthop_p = &nexthop;
+ nexthop_p = (union g_addr *)&nexthop;
ifindex = stream_getl (s);
break;
case ZEBRA_NEXTHOP_IPV6:
table_id = zvrf->table_id;
- rib_delete_ipv4 (api.type, api.instance, api.flags, &p, nexthop_p, ifindex,
- zvrf->vrf_id, table_id, api.safi);
+ rib_delete (AFI_IP, api.safi, zvrf->vrf_id, api.type, api.instance,
+ api.flags, &p, nexthop_p, ifindex, table_id);
client->v4_route_del_cnt++;
return 0;
}
struct stream *s;
struct zapi_ipv6 api;
struct in6_addr nexthop;
+ union g_addr *pnexthop;
unsigned long ifindex;
- struct prefix_ipv6 p;
+ struct prefix p;
s = client->ibuf;
ifindex = 0;
memset (&p, 0, sizeof (struct prefix_ipv6));
p.family = AF_INET6;
p.prefixlen = stream_getc (s);
- stream_get (&p.prefix, s, PSIZE (p.prefixlen));
+ stream_get (&p.u.prefix6, s, PSIZE (p.prefixlen));
/* Nexthop, ifindex, distance, metric. */
if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
{
case ZEBRA_NEXTHOP_IPV6:
stream_get (&nexthop, s, 16);
+ pnexthop = (union g_addr *)&nexthop;
break;
case ZEBRA_NEXTHOP_IFINDEX:
ifindex = stream_getl (s);
api.tag = 0;
if (IN6_IS_ADDR_UNSPECIFIED (&nexthop))
- rib_delete_ipv6 (api.type, api.instance, api.flags, &p, NULL, ifindex,
- zvrf->vrf_id, client->rtm_table, api.safi);
+ rib_delete (AFI_IP6, api.safi, zvrf->vrf_id, api.type, api.instance,
+ api.flags, &p, NULL, ifindex, client->rtm_table);
else
- rib_delete_ipv6 (api.type, api.instance, api.flags, &p, &nexthop, ifindex,
- zvrf->vrf_id, client->rtm_table, api.safi);
+ rib_delete (AFI_IP6, api.safi, zvrf->vrf_id, api.type, api.instance,
+ api.flags, &p, pnexthop, ifindex, client->rtm_table);
client->v6_route_del_cnt++;
return 0;