Commit aa87d6fe authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Distinguish changes from additions in local language.

parent fe14685c
...@@ -83,13 +83,13 @@ write_timeout(int fd, const void *buf, int len) ...@@ -83,13 +83,13 @@ write_timeout(int fd, const void *buf, int len)
void void
local_notify_self() local_notify_self()
{ {
char buf[512]; char buf[512];
int rc; int rc;
if(local_socket < 0) if(local_socket < 0)
return; return;
rc = snprintf(buf, 512, "self id %s\n", format_address(myid)); rc = snprintf(buf, 512, "add self id %s\n", format_address(myid));
if(rc < 0 || rc >= 512) if(rc < 0 || rc >= 512)
goto fail; goto fail;
...@@ -104,8 +104,19 @@ local_notify_self() ...@@ -104,8 +104,19 @@ local_notify_self()
return; return;
} }
static char *
local_kind(int kind)
{
switch(kind) {
case LOCAL_FLUSH: return "flush";
case LOCAL_CHANGE: return "change";
case LOCAL_ADD: return "add";
default: return "???";
}
}
void void
local_notify_neighbour(struct neighbour *neigh, int flush) local_notify_neighbour(struct neighbour *neigh, int kind)
{ {
char buf[512]; char buf[512];
int rc; int rc;
...@@ -114,9 +125,9 @@ local_notify_neighbour(struct neighbour *neigh, int flush) ...@@ -114,9 +125,9 @@ local_notify_neighbour(struct neighbour *neigh, int flush)
return; return;
rc = snprintf(buf, 512, rc = snprintf(buf, 512,
"%sneighbour id %s address %s " "%s neighbour id %s address %s "
"if %s reach %04x rxcost %d txcost %d cost %d\n", "if %s reach %04x rxcost %d txcost %d cost %d\n",
flush ? " flush" : "", local_kind(kind),
format_address(neigh->id), format_address(neigh->id),
format_address(neigh->address), format_address(neigh->address),
neigh->network->ifname, neigh->network->ifname,
...@@ -139,7 +150,7 @@ local_notify_neighbour(struct neighbour *neigh, int flush) ...@@ -139,7 +150,7 @@ local_notify_neighbour(struct neighbour *neigh, int flush)
} }
void void
local_notify_xroute(struct xroute *xroute, int flush) local_notify_xroute(struct xroute *xroute, int kind)
{ {
char buf[512]; char buf[512];
int rc; int rc;
...@@ -147,8 +158,8 @@ local_notify_xroute(struct xroute *xroute, int flush) ...@@ -147,8 +158,8 @@ local_notify_xroute(struct xroute *xroute, int flush)
if(local_socket < 0) if(local_socket < 0)
return; return;
rc = snprintf(buf, 512, "%sxroute prefix %s metric %d\n", rc = snprintf(buf, 512, "%s xroute prefix %s metric %d\n",
flush ? "flush " : "", local_kind(kind),
format_prefix(xroute->prefix, xroute->plen), format_prefix(xroute->prefix, xroute->plen),
xroute->metric); xroute->metric);
...@@ -166,7 +177,7 @@ local_notify_xroute(struct xroute *xroute, int flush) ...@@ -166,7 +177,7 @@ local_notify_xroute(struct xroute *xroute, int flush)
} }
void void
local_notify_route(struct route *route, int flush) local_notify_route(struct route *route, int kind)
{ {
char buf[512]; char buf[512];
int rc; int rc;
...@@ -175,9 +186,9 @@ local_notify_route(struct route *route, int flush) ...@@ -175,9 +186,9 @@ local_notify_route(struct route *route, int flush)
return; return;
rc = snprintf(buf, 512, rc = snprintf(buf, 512,
"%sroute prefix %s installed %s " "%s route prefix %s installed %s "
"id %s metric %d refmetric %d via %s if %s neigh %s\n", "id %s metric %d refmetric %d via %s if %s neigh %s\n",
flush ? "flush " : "", local_kind(kind),
format_prefix(route->src->prefix, route->src->plen), format_prefix(route->src->prefix, route->src->plen),
route->installed ? "yes" : "no", route->installed ? "yes" : "no",
format_address(route->src->id), format_address(route->src->id),
...@@ -209,9 +220,9 @@ local_dump() ...@@ -209,9 +220,9 @@ local_dump()
local_notify_self(); local_notify_self();
for(i = 0; i < numneighs; i++) for(i = 0; i < numneighs; i++)
local_notify_neighbour(&neighs[i], 0); local_notify_neighbour(&neighs[i], LOCAL_ADD);
for(i = 0; i < numxroutes; i++) for(i = 0; i < numxroutes; i++)
local_notify_xroute(&xroutes[i], 0); local_notify_xroute(&xroutes[i], LOCAL_ADD);
for(i = 0; i < numroutes; i++) for(i = 0; i < numroutes; i++)
local_notify_route(&routes[i], 0); local_notify_route(&routes[i], LOCAL_ADD);
} }
...@@ -24,9 +24,13 @@ struct neighbour; ...@@ -24,9 +24,13 @@ struct neighbour;
struct route; struct route;
struct xroute; struct xroute;
#define LOCAL_FLUSH 0
#define LOCAL_ADD 1
#define LOCAL_CHANGE 2
int local_read(int s); int local_read(int s);
void local_notify_self(void); void local_notify_self(void);
void local_notify_neighbour(struct neighbour *neigh, int flush); void local_notify_neighbour(struct neighbour *neigh, int kind);
void local_notify_xroute(struct xroute *xroute, int flush); void local_notify_xroute(struct xroute *xroute, int kind);
void local_notify_route(struct route *route, int flush); void local_notify_route(struct route *route, int kind);
void local_dump(void); void local_dump(void);
...@@ -140,8 +140,6 @@ add_neighbour(const unsigned char *id, const unsigned char *address, ...@@ -140,8 +140,6 @@ add_neighbour(const unsigned char *id, const unsigned char *address,
neigh->hello_interval = 0; neigh->hello_interval = 0;
neigh->ihu_interval = 0; neigh->ihu_interval = 0;
neigh->network = net; neigh->network = net;
neigh->next = neighs;
neighs = neigh;
send_hello(net); send_hello(net);
return neigh; return neigh;
} }
...@@ -237,7 +235,7 @@ update_neighbour(struct neighbour *neigh, int hello, int hello_interval) ...@@ -237,7 +235,7 @@ update_neighbour(struct neighbour *neigh, int hello, int hello_interval)
send_unicast_request(neigh, NULL, 0, 0, 0, 0); send_unicast_request(neigh, NULL, 0, 0, 0, 0);
} }
if(rc) if(rc)
local_notify_neighbour(neigh, 0); local_notify_neighbour(neigh, LOCAL_CHANGE);
return rc; return rc;
} }
...@@ -257,7 +255,7 @@ reset_txcost(struct neighbour *neigh) ...@@ -257,7 +255,7 @@ reset_txcost(struct neighbour *neigh)
delay >= neigh->ihu_interval * 10 * 10)) { delay >= neigh->ihu_interval * 10 * 10)) {
neigh->txcost = INFINITY; neigh->txcost = INFINITY;
neigh->ihu_time = now; neigh->ihu_time = now;
local_notify_neighbour(neigh, 0); local_notify_neighbour(neigh, LOCAL_CHANGE);
return 1; return 1;
} }
......
...@@ -87,7 +87,7 @@ flush_route(struct route *route) ...@@ -87,7 +87,7 @@ flush_route(struct route *route)
lost = 1; lost = 1;
} }
local_notify_route(route, 1); local_notify_route(route, LOCAL_FLUSH);
src = route->src; src = route->src;
...@@ -158,7 +158,7 @@ install_route(struct route *route) ...@@ -158,7 +158,7 @@ install_route(struct route *route)
return; return;
} }
route->installed = 1; route->installed = 1;
local_notify_route(route, 0); local_notify_route(route, LOCAL_CHANGE);
} }
void void
...@@ -177,7 +177,7 @@ uninstall_route(struct route *route) ...@@ -177,7 +177,7 @@ uninstall_route(struct route *route)
perror("kernel_route(FLUSH)"); perror("kernel_route(FLUSH)");
route->installed = 0; route->installed = 0;
local_notify_route(route, 0); local_notify_route(route, LOCAL_CHANGE);
} }
/* This is equivalent to uninstall_route followed with install_route, /* This is equivalent to uninstall_route followed with install_route,
...@@ -206,8 +206,8 @@ switch_routes(struct route *old, struct route *new) ...@@ -206,8 +206,8 @@ switch_routes(struct route *old, struct route *new)
old->installed = 0; old->installed = 0;
new->installed = 1; new->installed = 1;
} }
local_notify_route(old, 0); local_notify_route(old, LOCAL_CHANGE);
local_notify_route(new, 0); local_notify_route(new, LOCAL_CHANGE);
} }
void void
...@@ -233,7 +233,7 @@ change_route_metric(struct route *route, int newmetric) ...@@ -233,7 +233,7 @@ change_route_metric(struct route *route, int newmetric)
} }
} }
route->metric = newmetric; route->metric = newmetric;
local_notify_route(route, 0); local_notify_route(route, LOCAL_CHANGE);
} }
int int
...@@ -440,6 +440,7 @@ update_route(const unsigned char *a, const unsigned char *p, unsigned char plen, ...@@ -440,6 +440,7 @@ update_route(const unsigned char *a, const unsigned char *p, unsigned char plen,
route->time = now.tv_sec; route->time = now.tv_sec;
route->installed = 0; route->installed = 0;
numroutes++; numroutes++;
local_notify_route(route, LOCAL_ADD);
consider_route(route); consider_route(route);
} }
return route; return route;
......
...@@ -62,7 +62,7 @@ flush_xroute(struct xroute *xroute) ...@@ -62,7 +62,7 @@ flush_xroute(struct xroute *xroute)
n = xroute - xroutes; n = xroute - xroutes;
assert(n >= 0 && n < numxroutes); assert(n >= 0 && n < numxroutes);
local_notify_xroute(xroute, 1); local_notify_xroute(xroute, LOCAL_FLUSH);
if(n != numxroutes - 1) if(n != numxroutes - 1)
memcpy(xroutes + n, xroutes + numxroutes - 1, sizeof(struct xroute)); memcpy(xroutes + n, xroutes + numxroutes - 1, sizeof(struct xroute));
...@@ -100,7 +100,7 @@ add_xroute(int kind, unsigned char prefix[16], unsigned char plen, ...@@ -100,7 +100,7 @@ add_xroute(int kind, unsigned char prefix[16], unsigned char plen,
if(xroute->metric <= metric) if(xroute->metric <= metric)
return 0; return 0;
xroute->metric = metric; xroute->metric = metric;
local_notify_xroute(xroute, 0); local_notify_xroute(xroute, LOCAL_CHANGE);
return 1; return 1;
} }
...@@ -123,7 +123,7 @@ add_xroute(int kind, unsigned char prefix[16], unsigned char plen, ...@@ -123,7 +123,7 @@ add_xroute(int kind, unsigned char prefix[16], unsigned char plen,
xroutes[numxroutes].ifindex = ifindex; xroutes[numxroutes].ifindex = ifindex;
xroutes[numxroutes].proto = proto; xroutes[numxroutes].proto = proto;
numxroutes++; numxroutes++;
local_notify_xroute(&xroutes[numxroutes - 1], 0); local_notify_xroute(&xroutes[numxroutes - 1], LOCAL_ADD);
return 1; return 1;
} }
......
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