Commit c6feeaed authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Add support for installing IPv4 routes (netlink-only).

parent c345d632
...@@ -562,7 +562,8 @@ kernel_route(int operation, const unsigned char *dest, unsigned short plen, ...@@ -562,7 +562,8 @@ kernel_route(int operation, const unsigned char *dest, unsigned short plen,
struct rtmsg *rtm; struct rtmsg *rtm;
struct rtattr *rta; struct rtattr *rta;
int len = sizeof(buf.raw); int len = sizeof(buf.raw);
int rc; int rc, ipv4;
if(!nl_setup) { if(!nl_setup) {
fprintf(stderr,"kernel_route: netlink not initialized.\n"); fprintf(stderr,"kernel_route: netlink not initialized.\n");
...@@ -595,11 +596,7 @@ kernel_route(int operation, const unsigned char *dest, unsigned short plen, ...@@ -595,11 +596,7 @@ kernel_route(int operation, const unsigned char *dest, unsigned short plen,
} }
} }
if(v4mapped(gate)) { ipv4 = v4mapped(gate);
/* Not implemented yet. */
errno = ENOSYS;
return -1;
}
if(operation == ROUTE_MODIFY) { if(operation == ROUTE_MODIFY) {
if(newmetric == metric && memcmp(newgate, gate, 16) == 0 && if(newmetric == metric && memcmp(newgate, gate, 16) == 0 &&
...@@ -624,7 +621,7 @@ kernel_route(int operation, const unsigned char *dest, unsigned short plen, ...@@ -624,7 +621,7 @@ kernel_route(int operation, const unsigned char *dest, unsigned short plen,
/* Unreachable default routes cause all sort of weird interactions; /* Unreachable default routes cause all sort of weird interactions;
ignore them. */ ignore them. */
if(metric >= KERNEL_INFINITY && plen == 0) if(metric >= KERNEL_INFINITY && (plen == 0 || (ipv4 && plen == 96)))
return 0; return 0;
memset(buf.raw, 0, sizeof(buf.raw)); memset(buf.raw, 0, sizeof(buf.raw));
...@@ -637,8 +634,8 @@ kernel_route(int operation, const unsigned char *dest, unsigned short plen, ...@@ -637,8 +634,8 @@ kernel_route(int operation, const unsigned char *dest, unsigned short plen,
} }
rtm = NLMSG_DATA(&buf.nh); rtm = NLMSG_DATA(&buf.nh);
rtm->rtm_family = AF_INET6; rtm->rtm_family = ipv4 ? AF_INET : AF_INET6;
rtm->rtm_dst_len = plen; rtm->rtm_dst_len = ipv4 ? plen - 96 : plen;
rtm->rtm_table = RT_TABLE_MAIN; rtm->rtm_table = RT_TABLE_MAIN;
rtm->rtm_scope = RT_SCOPE_UNIVERSE; rtm->rtm_scope = RT_SCOPE_UNIVERSE;
if(metric < KERNEL_INFINITY) if(metric < KERNEL_INFINITY)
...@@ -649,10 +646,17 @@ kernel_route(int operation, const unsigned char *dest, unsigned short plen, ...@@ -649,10 +646,17 @@ kernel_route(int operation, const unsigned char *dest, unsigned short plen,
rta = RTM_RTA(rtm); rta = RTM_RTA(rtm);
rta = RTA_NEXT(rta, len); if(ipv4) {
rta->rta_len = RTA_LENGTH(sizeof(struct in6_addr)); rta = RTA_NEXT(rta, len);
rta->rta_type = RTA_DST; rta->rta_len = RTA_LENGTH(sizeof(struct in_addr));
memcpy(RTA_DATA(rta), dest, sizeof(struct in6_addr)); rta->rta_type = RTA_DST;
memcpy(RTA_DATA(rta), dest + 12, sizeof(struct in_addr));
} else {
rta = RTA_NEXT(rta, len);
rta->rta_len = RTA_LENGTH(sizeof(struct in6_addr));
rta->rta_type = RTA_DST;
memcpy(RTA_DATA(rta), dest, sizeof(struct in6_addr));
}
rta = RTA_NEXT(rta, len); rta = RTA_NEXT(rta, len);
rta->rta_len = RTA_LENGTH(sizeof(int)); rta->rta_len = RTA_LENGTH(sizeof(int));
...@@ -665,10 +669,17 @@ kernel_route(int operation, const unsigned char *dest, unsigned short plen, ...@@ -665,10 +669,17 @@ kernel_route(int operation, const unsigned char *dest, unsigned short plen,
rta->rta_type = RTA_OIF; rta->rta_type = RTA_OIF;
*(int*)RTA_DATA(rta) = ifindex; *(int*)RTA_DATA(rta) = ifindex;
rta = RTA_NEXT(rta, len); if(ipv4) {
rta->rta_len = RTA_LENGTH(sizeof(struct in6_addr)); rta = RTA_NEXT(rta, len);
rta->rta_type = RTA_GATEWAY; rta->rta_len = RTA_LENGTH(sizeof(struct in_addr));
memcpy(RTA_DATA(rta), gate, sizeof(struct in6_addr)); rta->rta_type = RTA_GATEWAY;
memcpy(RTA_DATA(rta), gate + 12, sizeof(struct in_addr));
} else {
rta = RTA_NEXT(rta, len);
rta->rta_len = RTA_LENGTH(sizeof(struct in6_addr));
rta->rta_type = RTA_GATEWAY;
memcpy(RTA_DATA(rta), gate, sizeof(struct in6_addr));
}
} else { } else {
*(int*)RTA_DATA(rta) = -1; *(int*)RTA_DATA(rta) = -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