Commit 22eea519 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Add nexthop field to struct route.

parent b2115006
...@@ -192,7 +192,8 @@ parse_packet(const unsigned char *from, struct network *net, ...@@ -192,7 +192,8 @@ parse_packet(const unsigned char *from, struct network *net,
if(plen <= 128) { if(plen <= 128) {
unsigned char prefix[16]; unsigned char prefix[16];
mask_prefix(prefix, address, plen); mask_prefix(prefix, address, plen);
update_route(address, prefix, plen, seqno, metric, neigh); update_route(address, prefix, plen, seqno, metric, neigh,
neigh->address);
} }
} else if(type == 4) { } else if(type == 4) {
unsigned char prefix[16]; unsigned char prefix[16];
...@@ -212,7 +213,8 @@ parse_packet(const unsigned char *from, struct network *net, ...@@ -212,7 +213,8 @@ parse_packet(const unsigned char *from, struct network *net,
if(memcmp(current_source, myid, 16) == 0) if(memcmp(current_source, myid, 16) == 0)
continue; continue;
mask_prefix(prefix, address, plen); mask_prefix(prefix, address, plen);
update_route(current_source, prefix, plen, seqno, metric, neigh); update_route(current_source, prefix, plen, seqno, metric,
neigh, neigh->address);
} else { } else {
debugf("Received unknown packet type %d from %s (%s).\n", debugf("Received unknown packet type %d from %s (%s).\n",
type, format_address(neigh->id), format_address(from)); type, format_address(neigh->id), format_address(from));
......
...@@ -45,11 +45,12 @@ int route_gc_delay = 180; ...@@ -45,11 +45,12 @@ int route_gc_delay = 180;
struct route * struct route *
find_route(const unsigned char *prefix, unsigned char plen, find_route(const unsigned char *prefix, unsigned char plen,
struct neighbour *neigh) struct neighbour *neigh, const unsigned char *nexthop)
{ {
int i; int i;
for(i = 0; i < numroutes; i++) { for(i = 0; i < numroutes; i++) {
if(routes[i].neigh == neigh && if(routes[i].neigh == neigh &&
memcmp(routes[i].nexthop, nexthop, 16) == 0 &&
source_match(routes[i].src, prefix, plen)) source_match(routes[i].src, prefix, plen))
return &routes[i]; return &routes[i];
} }
...@@ -130,7 +131,7 @@ install_route(struct route *route) ...@@ -130,7 +131,7 @@ install_route(struct route *route)
return; return;
rc = kernel_route(ROUTE_ADD, route->src->prefix, route->src->plen, rc = kernel_route(ROUTE_ADD, route->src->prefix, route->src->plen,
route->neigh->address, route->nexthop,
route->neigh->network->ifindex, route->neigh->network->ifindex,
metric_to_kernel(route->metric), NULL, 0, 0); metric_to_kernel(route->metric), NULL, 0, 0);
if(rc < 0) { if(rc < 0) {
...@@ -150,7 +151,7 @@ uninstall_route(struct route *route) ...@@ -150,7 +151,7 @@ uninstall_route(struct route *route)
return; return;
rc = kernel_route(ROUTE_FLUSH, route->src->prefix, route->src->plen, rc = kernel_route(ROUTE_FLUSH, route->src->prefix, route->src->plen,
route->neigh->address, route->nexthop,
route->neigh->network->ifindex, route->neigh->network->ifindex,
metric_to_kernel(route->metric), NULL, 0, 0); metric_to_kernel(route->metric), NULL, 0, 0);
if(rc < 0) if(rc < 0)
...@@ -177,9 +178,9 @@ change_route(struct route *old, struct route *new) ...@@ -177,9 +178,9 @@ change_route(struct route *old, struct route *new)
return; return;
rc = kernel_route(ROUTE_MODIFY, old->src->prefix, old->src->plen, rc = kernel_route(ROUTE_MODIFY, old->src->prefix, old->src->plen,
old->neigh->address, old->neigh->network->ifindex, old->nexthop, old->neigh->network->ifindex,
metric_to_kernel(old->metric), metric_to_kernel(old->metric),
new->neigh->address, new->neigh->network->ifindex, new->nexthop, new->neigh->network->ifindex,
metric_to_kernel(new->metric)); metric_to_kernel(new->metric));
if(rc >= 0) { if(rc >= 0) {
old->installed = 0; old->installed = 0;
...@@ -195,10 +196,10 @@ change_route_metric(struct route *route, int newmetric) ...@@ -195,10 +196,10 @@ change_route_metric(struct route *route, int newmetric)
if(route->installed) { if(route->installed) {
rc = kernel_route(ROUTE_MODIFY, rc = kernel_route(ROUTE_MODIFY,
route->src->prefix, route->src->plen, route->src->prefix, route->src->plen,
route->neigh->address, route->nexthop,
route->neigh->network->ifindex, route->neigh->network->ifindex,
metric_to_kernel(route->metric), metric_to_kernel(route->metric),
route->neigh->address, route->nexthop,
route->neigh->network->ifindex, route->neigh->network->ifindex,
metric_to_kernel(newmetric)); metric_to_kernel(newmetric));
if(rc < 0) { if(rc < 0) {
...@@ -307,7 +308,7 @@ update_neighbour_metric(struct neighbour *neigh) ...@@ -307,7 +308,7 @@ update_neighbour_metric(struct neighbour *neigh)
struct route * struct route *
update_route(const unsigned char *a, const unsigned char *p, unsigned char plen, update_route(const unsigned char *a, const unsigned char *p, unsigned char plen,
unsigned short seqno, unsigned short refmetric, unsigned short seqno, unsigned short refmetric,
struct neighbour *neigh) struct neighbour *neigh, const unsigned char *nexthop)
{ {
struct route *route; struct route *route;
struct source *src; struct source *src;
...@@ -327,7 +328,7 @@ update_route(const unsigned char *a, const unsigned char *p, unsigned char plen, ...@@ -327,7 +328,7 @@ update_route(const unsigned char *a, const unsigned char *p, unsigned char plen,
return NULL; return NULL;
feasible = update_feasible(a, p, plen, seqno, refmetric); feasible = update_feasible(a, p, plen, seqno, refmetric);
route = find_route(p, plen, neigh); route = find_route(p, plen, neigh, nexthop);
metric = MIN((int)refmetric + neighbour_cost(neigh), INFINITY); metric = MIN((int)refmetric + neighbour_cost(neigh), INFINITY);
if(route) { if(route) {
...@@ -385,6 +386,7 @@ update_route(const unsigned char *a, const unsigned char *p, unsigned char plen, ...@@ -385,6 +386,7 @@ update_route(const unsigned char *a, const unsigned char *p, unsigned char plen,
route->seqno = seqno; route->seqno = seqno;
route->metric = metric; route->metric = metric;
route->neigh = neigh; route->neigh = neigh;
memcpy(route->nexthop, nexthop, 16);
route->time = now.tv_sec; route->time = now.tv_sec;
route->origtime = now.tv_sec; route->origtime = now.tv_sec;
route->installed = 0; route->installed = 0;
......
...@@ -26,6 +26,7 @@ struct route { ...@@ -26,6 +26,7 @@ struct route {
unsigned short refmetric; unsigned short refmetric;
unsigned short seqno; unsigned short seqno;
struct neighbour *neigh; struct neighbour *neigh;
unsigned char nexthop[16];
int time; int time;
int origtime; int origtime;
int installed; int installed;
...@@ -38,7 +39,7 @@ extern int route_timeout_delay; ...@@ -38,7 +39,7 @@ extern int route_timeout_delay;
extern int route_gc_delay; extern int route_gc_delay;
struct route *find_route(const unsigned char *prefix, unsigned char plen, struct route *find_route(const unsigned char *prefix, unsigned char plen,
struct neighbour *neigh); struct neighbour *neigh, const unsigned char *nexthop);
struct route *find_installed_route(const unsigned char *prefix, struct route *find_installed_route(const unsigned char *prefix,
unsigned char plen); unsigned char plen);
void flush_route(struct route *route); void flush_route(struct route *route);
...@@ -60,7 +61,8 @@ void update_route_metric(struct route *route); ...@@ -60,7 +61,8 @@ void update_route_metric(struct route *route);
struct route *update_route(const unsigned char *a, struct route *update_route(const unsigned char *a,
const unsigned char *p, unsigned char plen, const unsigned char *p, unsigned char plen,
unsigned short seqno, unsigned short refmetric, unsigned short seqno, unsigned short refmetric,
struct neighbour *neigh); struct neighbour *neigh,
const unsigned char *nexthop);
void consider_route(struct route *route); void consider_route(struct route *route);
void send_triggered_update(struct route *route, void send_triggered_update(struct route *route,
struct source *oldsrc, int oldmetric); struct source *oldsrc, int oldmetric);
......
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