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. ...@@ -36,8 +36,9 @@ THE SOFTWARE.
#include "route.h" #include "route.h"
#include "source.h" #include "source.h"
#include "neighbour.h" #include "neighbour.h"
#include "rule.h"
#include "disambiguation.h" #include "disambiguation.h"
#include "configuration.h"
#include "rule.h"
struct zone { struct zone {
const unsigned char *dst_prefix; const unsigned char *dst_prefix;
...@@ -214,55 +215,60 @@ is_installed(struct zone *zone) ...@@ -214,55 +215,60 @@ is_installed(struct zone *zone)
} }
static int 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, struct filter_result filter_result;
zone->src_prefix, zone->src_plen); unsigned int ifindex = route->neigh->ifp->ifindex;
return kernel_route(ROUTE_ADD, table, zone->dst_prefix, zone->dst_plen,
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, zone->src_prefix, zone->src_plen,
route->nexthop, route->nexthop, ifindex,
route->neigh->ifp->ifindex, metric, new_next_hop, new_ifindex, new_metric,
metric_to_kernel(route_metric(route)), NULL, 0, 0, 0); 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 static int
del_route(const struct zone *zone, const struct babel_route *route) del_route(const struct zone *zone, const struct babel_route *route)
{ {
int table = find_table(zone->dst_prefix, zone->dst_plen, return change_route(ROUTE_FLUSH, zone, route,
zone->src_prefix, zone->src_plen); metric_to_kernel(route_metric(route)), NULL, 0, 0);
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);
} }
static int static int
chg_route(const struct zone *zone, const struct babel_route *old, chg_route(const struct zone *zone, const struct babel_route *old,
const struct babel_route *new) const struct babel_route *new)
{ {
int table = find_table(zone->dst_prefix, zone->dst_plen, return change_route(ROUTE_MODIFY, zone, old,
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,
metric_to_kernel(route_metric(old)), metric_to_kernel(route_metric(old)),
new->nexthop, new->neigh->ifp->ifindex, new->nexthop, new->neigh->ifp->ifindex,
metric_to_kernel(route_metric(new)), table); metric_to_kernel(route_metric(new)));
} }
static int static int
chg_route_metric(const struct zone *zone, const struct babel_route *route, chg_route_metric(const struct zone *zone, const struct babel_route *route,
int old_metric, int new_metric) int old_metric, int new_metric)
{ {
int table = find_table(zone->dst_prefix, zone->dst_plen, return change_route(ROUTE_MODIFY, zone, route,
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,
old_metric, old_metric,
route->nexthop, route->neigh->ifp->ifindex, route->nexthop, route->neigh->ifp->ifindex,
new_metric, table); new_metric);
} }
int int
......
...@@ -178,14 +178,10 @@ int ...@@ -178,14 +178,10 @@ int
find_table(const unsigned char *dest, unsigned short plen, find_table(const unsigned char *dest, unsigned short plen,
const unsigned char *src, unsigned short src_plen) const unsigned char *src, unsigned short src_plen)
{ {
struct filter_result filter_result = {0};
struct rule *kr = NULL; struct rule *kr = NULL;
int i, found; int i, found;
install_filter(dest, plen, src, src_plen, &filter_result); if(is_default(src, src_plen)) {
if(filter_result.table) {
return filter_result.table;
} else if(is_default(src, src_plen)) {
return export_table; return export_table;
} else if(kernel_disambiguate(v4mapped(dest))) { } else if(kernel_disambiguate(v4mapped(dest))) {
return export_table; 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