Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ tags
*.orig
*~
\#*#
.vscode/
5 changes: 3 additions & 2 deletions configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -1503,13 +1503,14 @@ redistribute_filter(const unsigned char *prefix, unsigned short plen,
}

int
install_filter(const unsigned char *prefix, unsigned short plen,
install_filter(const unsigned char *id,
const unsigned char *prefix, unsigned short plen,
const unsigned char *src_prefix, unsigned short src_plen,
unsigned int ifindex,
struct filter_result *result)
{
int res;
res = do_filter(install_filters, NULL, prefix, plen,
res = do_filter(install_filters, id, prefix, plen,
src_prefix, src_plen, NULL, ifindex, 0, result);
if(res < 0)
res = INFINITY;
Expand Down
3 changes: 2 additions & 1 deletion configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ int redistribute_filter(const unsigned char *prefix, unsigned short plen,
const unsigned char *src_prefix, unsigned short src_plen,
unsigned int ifindex, int proto,
struct filter_result *result);
int install_filter(const unsigned char *prefix, unsigned short plen,
int install_filter(const unsigned char *id,
const unsigned char *prefix, unsigned short plen,
const unsigned char *src_prefix, unsigned short src_plen,
unsigned int ifindex, struct filter_result *result);
int finalise_config(void);
3 changes: 2 additions & 1 deletion kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ int kernel_route(int operation, int table,
const unsigned char *pref_src,
const unsigned char *gate, int ifindex, unsigned int metric,
const unsigned char *newgate, int newifindex,
unsigned int newmetric, int newtable);
unsigned int newmetric, int newtable,
const unsigned char *newpref_src);
int kernel_dump(int operation, struct kernel_filter *filter);
int kernel_callback(struct kernel_filter *filter);
int if_eui64(char *ifname, int ifindex, unsigned char *eui);
Expand Down
9 changes: 5 additions & 4 deletions kernel_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,8 @@ kernel_route(int operation, int table,
const unsigned char *pref_src,
const unsigned char *gate, int ifindex, unsigned int metric,
const unsigned char *newgate, int newifindex,
unsigned int newmetric, int newtable)
unsigned int newmetric, int newtable,
const unsigned char *newpref_src)
{
union { char raw[1024]; struct nlmsghdr nh; } buf;
struct rtmsg *rtm;
Expand Down Expand Up @@ -1011,11 +1012,11 @@ kernel_route(int operation, int table,
kernel_route(ROUTE_FLUSH, table, dest, plen,
src, src_plen, pref_src,
gate, ifindex, metric,
NULL, 0, 0, 0);
NULL, 0, 0, 0, NULL);
rc = kernel_route(ROUTE_ADD, newtable, dest, plen,
src, src_plen, pref_src,
src, src_plen, newpref_src,
newgate, newifindex, newmetric,
NULL, 0, 0, 0);
NULL, 0, 0, 0, NULL);
if(rc < 0) {
if(errno == EEXIST)
rc = 1;
Expand Down
9 changes: 5 additions & 4 deletions kernel_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ kernel_route(int operation, int table,
const unsigned char *pref_src,
const unsigned char *gate, int ifindex, unsigned int metric,
const unsigned char *newgate, int newifindex,
unsigned int newmetric, int newtable)
unsigned int newmetric, int newtable,
const unsigned char *newpref_src)
{
struct {
struct rt_msghdr m_rtm;
Expand All @@ -423,7 +424,7 @@ kernel_route(int operation, int table,

/* Source-specific routes & preferred source IPs
* are not implemented yet for BSD. */
if((!is_default(src, src_plen)) || pref_src) {
if((!is_default(src, src_plen)) || pref_src || newpref_src) {
errno = ENOSYS;
return -1;
}
Expand Down Expand Up @@ -454,11 +455,11 @@ kernel_route(int operation, int table,
kernel_route(ROUTE_FLUSH, table, dest, plen,
src, src_plen, NULL,
gate, ifindex, metric,
NULL, 0, 0, 0);
NULL, 0, 0, 0, NULL);
return kernel_route(ROUTE_ADD, table, dest, plen,
src, src_plen, NULL,
newgate, newifindex, newmetric,
NULL, 0, 0, 0);
NULL, 0, 0, 0, NULL);

}

Expand Down
29 changes: 22 additions & 7 deletions route.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,14 +439,17 @@ move_installed_route(struct babel_route *route, int i)
static int
change_route(int operation, const struct babel_route *route, int metric,
const unsigned char *new_next_hop,
int new_ifindex, int new_metric)
int new_ifindex, int new_metric,
const struct source *newsrc)
{
struct filter_result filter_result;
unsigned char *pref_src = NULL;
unsigned char *newpref_src = NULL;
unsigned int ifindex = route->neigh->ifp->ifindex;
int m, table;

m = install_filter(route->src->prefix, route->src->plen,
m = install_filter(route->src->id,
route->src->prefix, route->src->plen,
route->src->src_prefix, route->src->src_plen,
ifindex, &filter_result);
if(m >= INFINITY && operation == ROUTE_ADD) {
Expand All @@ -455,13 +458,24 @@ change_route(int operation, const struct babel_route *route, int metric,
}

pref_src = filter_result.pref_src;
newpref_src = pref_src;
table = filter_result.table ? filter_result.table : export_table;

if(newsrc) {
m = install_filter(newsrc->id,
newsrc->prefix, newsrc->plen,
newsrc->src_prefix, newsrc->src_plen,
new_ifindex, &filter_result);
if(m < INFINITY && filter_result.pref_src)
newpref_src = filter_result.pref_src;
}

return kernel_route(operation, table, route->src->prefix, route->src->plen,
route->src->src_prefix, route->src->src_plen, pref_src,
route->nexthop, ifindex,
metric, new_next_hop, new_ifindex, new_metric,
operation == ROUTE_MODIFY ? table : 0);
operation == ROUTE_MODIFY ? table : 0,
newpref_src);
}

void
Expand Down Expand Up @@ -490,7 +504,7 @@ install_route(struct babel_route *route)
format_prefix(route->src->prefix, route->src->plen),
format_prefix(route->src->src_prefix, route->src->src_plen));
rc = change_route(ROUTE_ADD, route, metric_to_kernel(route_metric(route)),
NULL, 0, 0);
NULL, 0, 0, NULL);
if(rc < 0 && errno != EEXIST) {
perror("kernel_route(ADD)");
return;
Expand All @@ -516,7 +530,7 @@ uninstall_route(struct babel_route *route)
format_prefix(route->src->prefix, route->src->plen),
format_prefix(route->src->src_prefix, route->src->src_plen));
rc = change_route(ROUTE_FLUSH, route, metric_to_kernel(route_metric(route)),
NULL, 0, 0);
NULL, 0, 0, NULL);
if(rc < 0) {
perror("kernel_route(FLUSH)");
return;
Expand Down Expand Up @@ -550,7 +564,8 @@ switch_routes(struct babel_route *old, struct babel_route *new)
format_prefix(old->src->src_prefix, old->src->src_plen));
rc = change_route(ROUTE_MODIFY, old, metric_to_kernel(route_metric(old)),
new->nexthop, new->neigh->ifp->ifindex,
metric_to_kernel(route_metric(new)));
metric_to_kernel(route_metric(new)),
new->src);
if(rc < 0) {
perror("kernel_route(MODIFY)");
return;
Expand Down Expand Up @@ -580,7 +595,7 @@ change_route_metric(struct babel_route *route,
format_prefix(route->src->src_prefix, route->src->src_plen),
old_metric, new_metric);
rc = change_route(ROUTE_MODIFY, route, old_metric, route->nexthop,
route->neigh->ifp->ifindex, new_metric);
route->neigh->ifp->ifindex, new_metric, NULL);
if(rc < 0) {
perror("kernel_route(MODIFY metric)");
return;
Expand Down