-/*
- * This file is free software: you may copy, redistribute and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 2 of the License, or (at your
- * option) any later version.
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * This file incorporates work covered by the following copyright and
- * permission notice:
- *
+/*
Copyright (c) 2007, 2008 by Juliusz Chroboczek
Copyright 2011 by Matthieu Boutier and Juliusz Chroboczek
/* Add redistributed route to Babel table. */
int
-babel_ipv4_route_add (struct zapi_ipv4 *api, struct prefix_ipv4 *prefix,
- unsigned int ifindex, struct in_addr *nexthop)
+babel_route_add (struct zapi_route *api)
{
unsigned char uchar_prefix[16];
- inaddr_to_uchar(uchar_prefix, &prefix->prefix);
- debugf(BABEL_DEBUG_ROUTE, "Adding new ipv4 route comming from Zebra.");
- xroute_add_new_route(uchar_prefix, prefix->prefixlen + 96,
- api->metric, ifindex, 0, 1);
- return 0;
-}
-
-/* Remove redistributed route from Babel table. */
-int
-babel_ipv4_route_delete (struct zapi_ipv4 *api, struct prefix_ipv4 *prefix,
- unsigned int ifindex)
-{
- unsigned char uchar_prefix[16];
- struct xroute *xroute = NULL;
-
- inaddr_to_uchar(uchar_prefix, &prefix->prefix);
- xroute = find_xroute(uchar_prefix, prefix->prefixlen + 96);
- if (xroute != NULL) {
- debugf(BABEL_DEBUG_ROUTE, "Removing ipv4 route (from zebra).");
- flush_xroute(xroute);
+ switch (api->prefix.family) {
+ case AF_INET:
+ inaddr_to_uchar(uchar_prefix, &api->prefix.u.prefix4);
+ debugf(BABEL_DEBUG_ROUTE, "Adding new ipv4 route coming from Zebra.");
+ xroute_add_new_route(uchar_prefix, api->prefix.prefixlen + 96,
+ api->metric, api->nexthops[0].ifindex, 0, 1);
+ break;
+ case AF_INET6:
+ in6addr_to_uchar(uchar_prefix, &api->prefix.u.prefix6);
+ debugf(BABEL_DEBUG_ROUTE, "Adding new ipv6 route coming from Zebra.");
+ xroute_add_new_route(uchar_prefix, api->prefix.prefixlen,
+ api->metric, api->nexthops[0].ifindex, 0, 1);
+ break;
}
- return 0;
-}
-
-/* Add redistributed route to Babel table. */
-int
-babel_ipv6_route_add (struct zapi_ipv6 *api, struct prefix_ipv6 *prefix,
- unsigned int ifindex, struct in6_addr *nexthop)
-{
- unsigned char uchar_prefix[16];
- in6addr_to_uchar(uchar_prefix, &prefix->prefix);
- debugf(BABEL_DEBUG_ROUTE, "Adding new route comming from Zebra.");
- xroute_add_new_route(uchar_prefix, prefix->prefixlen, api->metric, ifindex,
- 0, 1);
return 0;
}
/* Remove redistributed route from Babel table. */
int
-babel_ipv6_route_delete (struct zapi_ipv6 *api, struct prefix_ipv6 *prefix,
- unsigned int ifindex)
+babel_route_delete (struct zapi_route *api)
{
unsigned char uchar_prefix[16];
struct xroute *xroute = NULL;
- in6addr_to_uchar(uchar_prefix, &prefix->prefix);
- xroute = find_xroute(uchar_prefix, prefix->prefixlen);
- if (xroute != NULL) {
- debugf(BABEL_DEBUG_ROUTE, "Removing route (from zebra).");
- flush_xroute(xroute);
+ 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;
}
/* Returns an overestimate of the number of xroutes. */
int
-xroutes_estimate()
+xroutes_estimate(void)
{
return numxroutes;
}
-void
-for_all_xroutes(void (*f)(struct xroute*, void*), void *closure)
+struct xroute_stream {
+ int index;
+};
+
+struct
+xroute_stream *
+xroute_stream(void)
{
- int i;
+ struct xroute_stream *stream = malloc(sizeof(struct xroute_stream));
+ if(stream == NULL)
+ return NULL;
- for(i = 0; i < numxroutes; i++)
- (*f)(&xroutes[i], closure);
+ stream->index = 0;
+ return stream;
+}
+
+struct xroute *
+xroute_stream_next(struct xroute_stream *stream)
+{
+ if(stream->index < numxroutes)
+ return &xroutes[stream->index++];
+ else
+ return NULL;
+}
+
+void
+xroute_stream_done(struct xroute_stream *stream)
+{
+ free(stream);
}
/* add an xroute, verifying some conditions; return 0 if there is no changes */
if(rc > 0) {
struct babel_route *route;
route = find_installed_route(prefix, plen);
- if(route) {
- if(allow_duplicates < 0 ||
- metric < allow_duplicates)
- uninstall_route(route);
- }
+ if(route)
+ uninstall_route(route);
if(send_updates)
send_update(NULL, 0, prefix, plen);
return 1;