/* Remove redistributed route from Babel table. */ int babel_route_delete (struct zapi_route *api) { unsigned char uchar_prefix[16]; struct xroute *xroute = NULL; switch (api->prefix.family) { case AF_INET: inaddr_to_uchar(uchar_prefix, &api->prefix.u.prefix4); xroute = find_xroute(uchar_prefix, api->prefix.prefixlen + 96); if (xroute != NULL) { debugf(BABEL_DEBUG_ROUTE, "Removing ipv4 route (from zebra)."); flush_xroute(xroute); } break; case AF_INET6: in6addr_to_uchar(uchar_prefix, &api->prefix.u.prefix6); xroute = find_xroute(uchar_prefix, api->prefix.prefixlen); if (xroute != NULL) { debugf(BABEL_DEBUG_ROUTE, "Removing ipv6 route (from zebra)."); flush_xroute(xroute); } break; } return 0; }
static int add_xroute(unsigned char prefix[16], unsigned char plen, unsigned short metric, unsigned int ifindex, int proto) { struct xroute *xroute = find_xroute(prefix, plen); if(xroute) { if(xroute->metric <= metric) return 0; xroute->metric = metric; return 1; } if(numxroutes >= maxxroutes) { struct xroute *new_xroutes; int n = maxxroutes < 1 ? 8 : 2 * maxxroutes; new_xroutes = xroutes == NULL ? malloc(n * sizeof(struct xroute)) : realloc(xroutes, n * sizeof(struct xroute)); if(new_xroutes == NULL) return -1; maxxroutes = n; xroutes = new_xroutes; } memcpy(xroutes[numxroutes].prefix, prefix, 16); xroutes[numxroutes].plen = plen; xroutes[numxroutes].metric = metric; xroutes[numxroutes].ifindex = ifindex; xroutes[numxroutes].proto = proto; numxroutes++; return 1; }
int add_xroute(unsigned char prefix[16], unsigned char plen, unsigned char src_prefix[16], unsigned char src_plen, unsigned short metric, unsigned int ifindex, int proto) { struct xroute *xroute = find_xroute(prefix, plen, src_prefix, src_plen); if(xroute) { if(xroute->metric <= metric) return 0; xroute->metric = metric; local_notify_xroute(xroute, LOCAL_CHANGE); return 1; } if(numxroutes >= maxxroutes) { struct xroute *new_xroutes; int n = maxxroutes < 1 ? 8 : 2 * maxxroutes; new_xroutes = xroutes == NULL ? malloc(n * sizeof(struct xroute)) : realloc(xroutes, n * sizeof(struct xroute)); if(new_xroutes == NULL) return -1; maxxroutes = n; xroutes = new_xroutes; } memcpy(xroutes[numxroutes].prefix, prefix, 16); xroutes[numxroutes].plen = plen; memcpy(xroutes[numxroutes].src_prefix, src_prefix, 16); xroutes[numxroutes].src_plen = src_plen; xroutes[numxroutes].metric = metric; xroutes[numxroutes].ifindex = ifindex; xroutes[numxroutes].proto = proto; numxroutes++; local_notify_xroute(&xroutes[numxroutes - 1], LOCAL_ADD); return 1; }