Commit 90fc2cbf authored by Killian Lufau's avatar Killian Lufau Committed by Juliusz Chroboczek

Refactor find_table and calls to kernel_route.

This is only a cleanup and not a functional change
parent f8bce04c
......@@ -36,8 +36,9 @@ THE SOFTWARE.
#include "route.h"
#include "source.h"
#include "neighbour.h"
#include "rule.h"
#include "disambiguation.h"
#include "configuration.h"
#include "rule.h"
struct zone {
const unsigned char *dst_prefix;
......@@ -214,55 +215,60 @@ is_installed(struct zone *zone)
}
static int
add_route(const struct zone *zone, const struct babel_route *route)
change_route(int operation, const struct zone *zone,
const struct babel_route *route, int metric,
const unsigned char *new_next_hop,
int new_ifindex, int new_metric)
{
int table = find_table(zone->dst_prefix, zone->dst_plen,
zone->src_prefix, zone->src_plen);
return kernel_route(ROUTE_ADD, table, zone->dst_prefix, zone->dst_plen,
struct filter_result filter_result;
unsigned int ifindex = route->neigh->ifp->ifindex;
install_filter(zone->dst_prefix, zone->dst_plen,
zone->src_prefix, zone->src_plen, &filter_result);
int table = filter_result.table ? filter_result.table :
find_table(zone->dst_prefix, zone->dst_plen,
zone->src_prefix, zone->src_plen);
return kernel_route(operation, table, zone->dst_prefix, zone->dst_plen,
zone->src_prefix, zone->src_plen,
route->nexthop,
route->neigh->ifp->ifindex,
metric_to_kernel(route_metric(route)), NULL, 0, 0, 0);
route->nexthop, ifindex,
metric, new_next_hop, new_ifindex, new_metric,
operation == ROUTE_MODIFY ? table : 0);
}
static int
add_route(const struct zone *zone, const struct babel_route *route)
{
return change_route(ROUTE_ADD, zone, route,
metric_to_kernel(route_metric(route)), NULL, 0, 0);
}
static int
del_route(const struct zone *zone, const struct babel_route *route)
{
int table = find_table(zone->dst_prefix, zone->dst_plen,
zone->src_prefix, zone->src_plen);
return kernel_route(ROUTE_FLUSH, table, zone->dst_prefix, zone->dst_plen,
zone->src_prefix, zone->src_plen,
route->nexthop,
route->neigh->ifp->ifindex,
metric_to_kernel(route_metric(route)), NULL, 0, 0, 0);
return change_route(ROUTE_FLUSH, zone, route,
metric_to_kernel(route_metric(route)), NULL, 0, 0);
}
static int
chg_route(const struct zone *zone, const struct babel_route *old,
const struct babel_route *new)
{
int table = find_table(zone->dst_prefix, zone->dst_plen,
zone->src_prefix, zone->src_plen);
return kernel_route(ROUTE_MODIFY, table, zone->dst_prefix, zone->dst_plen,
zone->src_prefix, zone->src_plen,
old->nexthop, old->neigh->ifp->ifindex,
return change_route(ROUTE_MODIFY, zone, old,
metric_to_kernel(route_metric(old)),
new->nexthop, new->neigh->ifp->ifindex,
metric_to_kernel(route_metric(new)), table);
metric_to_kernel(route_metric(new)));
}
static int
chg_route_metric(const struct zone *zone, const struct babel_route *route,
int old_metric, int new_metric)
{
int table = find_table(zone->dst_prefix, zone->dst_plen,
zone->src_prefix, zone->src_plen);
return kernel_route(ROUTE_MODIFY, table, zone->dst_prefix, zone->dst_plen,
zone->src_prefix, zone->src_plen,
route->nexthop, route->neigh->ifp->ifindex,
return change_route(ROUTE_MODIFY, zone, route,
old_metric,
route->nexthop, route->neigh->ifp->ifindex,
new_metric, table);
new_metric);
}
int
......
......@@ -178,14 +178,10 @@ int
find_table(const unsigned char *dest, unsigned short plen,
const unsigned char *src, unsigned short src_plen)
{
struct filter_result filter_result = {0};
struct rule *kr = NULL;
int i, found;
install_filter(dest, plen, src, src_plen, &filter_result);
if(filter_result.table) {
return filter_result.table;
} else if(is_default(src, src_plen)) {
if(is_default(src, src_plen)) {
return export_table;
} else if(kernel_disambiguate(v4mapped(dest))) {
return export_table;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment