Commit 150a87a6 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Use named constants for kernel route manipulation.

parent 17ef3ef2
...@@ -545,7 +545,7 @@ kernel_interface_wireless(const char *ifname, int ifindex) ...@@ -545,7 +545,7 @@ kernel_interface_wireless(const char *ifname, int ifindex)
} }
int int
kernel_route(int add, const unsigned char *dest, unsigned short plen, kernel_route(int operation, const unsigned char *dest, unsigned short plen,
const unsigned char *gate, int ifindex, unsigned int metric) const unsigned char *gate, int ifindex, unsigned int metric)
{ {
...@@ -554,8 +554,8 @@ kernel_route(int add, const unsigned char *dest, unsigned short plen, ...@@ -554,8 +554,8 @@ kernel_route(int add, const unsigned char *dest, unsigned short plen,
struct rtattr *rta; struct rtattr *rta;
int len = sizeof(buf.raw); int len = sizeof(buf.raw);
debugf("kernel_route: %s: %s/%d metric %d via %d nexthop %s\n", debugf("kernel_route: %s %s/%d metric %d via %d nexthop %s\n",
add ? "Add" : "Del", operation == ROUTE_ADD ? "add" : "flush",
format_address(dest), plen, metric, ifindex, format_address(dest), plen, metric, ifindex,
format_address(gate)); format_address(gate));
...@@ -566,7 +566,7 @@ kernel_route(int add, const unsigned char *dest, unsigned short plen, ...@@ -566,7 +566,7 @@ kernel_route(int add, const unsigned char *dest, unsigned short plen,
} }
memset(buf.raw, 0, sizeof(buf.raw)); memset(buf.raw, 0, sizeof(buf.raw));
if(add) { if(operation == ROUTE_ADD) {
buf.nh.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL; buf.nh.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL;
buf.nh.nlmsg_type = RTM_NEWROUTE; buf.nh.nlmsg_type = RTM_NEWROUTE;
} else { } else {
......
...@@ -30,11 +30,14 @@ struct kernel_route { ...@@ -30,11 +30,14 @@ struct kernel_route {
unsigned char gw[16]; unsigned char gw[16];
}; };
#define ROUTE_FLUSH 0
#define ROUTE_ADD 1
int kernel_setup(int setup); int kernel_setup(int setup);
int kernel_setup_interface(int setup, const char *ifname, int ifindex); int kernel_setup_interface(int setup, const char *ifname, int ifindex);
int kernel_interface_mtu(const char *ifname, int ifindex); int kernel_interface_mtu(const char *ifname, int ifindex);
int kernel_interface_wireless(const char *ifname, int ifindex); int kernel_interface_wireless(const char *ifname, int ifindex);
int kernel_route(int add, const unsigned char *dest, unsigned short plen, int kernel_route(int operation, const unsigned char *dest, unsigned short plen,
const unsigned char *gate, int ifindex, unsigned int metric); const unsigned char *gate, int ifindex, unsigned int metric);
int kernel_routes(int maxplen, struct kernel_route *routes, int maxroutes); int kernel_routes(int maxplen, struct kernel_route *routes, int maxroutes);
int kernel_callback(void); int kernel_callback(void);
...@@ -177,12 +177,12 @@ install_route(struct route *route) ...@@ -177,12 +177,12 @@ install_route(struct route *route)
if(installed) if(installed)
uninstall_route(installed); uninstall_route(installed);
rc = kernel_route(1, route->dest->address, 128, rc = kernel_route(ROUTE_ADD, route->dest->address, 128,
route->nexthop->address, route->nexthop->address,
route->nexthop->network->ifindex, route->nexthop->network->ifindex,
metric_to_kernel(route->metric)); metric_to_kernel(route->metric));
if(rc < 0) { if(rc < 0) {
perror("kernel_route(1)"); perror("kernel_route(ADD)");
if(errno != EEXIST) if(errno != EEXIST)
return; return;
} }
...@@ -209,12 +209,12 @@ uninstall_route(struct route *route) ...@@ -209,12 +209,12 @@ uninstall_route(struct route *route)
uninstall_xroute(&xroutes[i]); uninstall_xroute(&xroutes[i]);
} }
rc = kernel_route(0, route->dest->address, 128, rc = kernel_route(ROUTE_FLUSH, route->dest->address, 128,
route->nexthop->address, route->nexthop->address,
route->nexthop->network->ifindex, route->nexthop->network->ifindex,
metric_to_kernel(route->metric)); metric_to_kernel(route->metric));
if(rc < 0) if(rc < 0)
perror("kernel_route(0)"); perror("kernel_route(FLUSH)");
route->installed = 0; route->installed = 0;
} }
......
...@@ -116,12 +116,12 @@ install_xroute(struct xroute *xroute) ...@@ -116,12 +116,12 @@ install_xroute(struct xroute *xroute)
if(installed) if(installed)
uninstall_xroute(installed); uninstall_xroute(installed);
rc = kernel_route(1, xroute->prefix, xroute->plen, rc = kernel_route(ROUTE_ADD, xroute->prefix, xroute->plen,
gwroute->nexthop->address, gwroute->nexthop->address,
gwroute->nexthop->network->ifindex, gwroute->nexthop->network->ifindex,
metric_to_kernel(xroute->metric)); metric_to_kernel(xroute->metric));
if(rc < 0) { if(rc < 0) {
perror("kernel_route(1)"); perror("kernel_route(ADD)");
if(errno != EEXIST) if(errno != EEXIST)
return; return;
} }
...@@ -145,12 +145,12 @@ uninstall_xroute(struct xroute *xroute) ...@@ -145,12 +145,12 @@ uninstall_xroute(struct xroute *xroute)
return; return;
} }
rc = kernel_route(0, xroute->prefix, xroute->plen, rc = kernel_route(ROUTE_FLUSH, xroute->prefix, xroute->plen,
gwroute->nexthop->address, gwroute->nexthop->address,
gwroute->nexthop->network->ifindex, gwroute->nexthop->network->ifindex,
metric_to_kernel(xroute->metric)); metric_to_kernel(xroute->metric));
if(rc < 0) if(rc < 0)
perror("kernel_route(0)"); perror("kernel_route(FLUSH)");
xroute->installed = 0; xroute->installed = 0;
} }
......
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