Commit 46957e84 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Kernel support for blackhole routes.

parent 03d5785b
......@@ -37,6 +37,7 @@ THE SOFTWARE.
static int old_forwarding = -1;
static int old_accept_redirects = -1;
static int ifindex_lo = -1;
static int
read_proc(char *filename)
......@@ -198,7 +199,7 @@ static int route_socket = -1;
int
kernel_route(int add, const unsigned char *dest, unsigned short plen,
const unsigned char *gate, int ifindex, int metric)
const unsigned char *gate, int ifindex, unsigned int metric)
{
struct in6_rtmsg msg;
int rc;
......@@ -209,21 +210,32 @@ kernel_route(int add, const unsigned char *dest, unsigned short plen,
return -1;
}
if(ifindex_lo < 0) {
ifindex_lo = if_nametoindex("lo");
if(ifindex_lo < 0)
return -1;
}
memset(&msg, 0, sizeof(msg));
msg.rtmsg_flags = RTF_UP;
if(plen < 128) {
msg.rtmsg_flags |= RTF_GATEWAY;
} else {
memcpy(&msg.rtmsg_dst, dest, sizeof(struct in6_addr));
msg.rtmsg_dst_len = plen;
msg.rtmsg_metric = metric;
if(plen >= 128)
msg.rtmsg_flags |= RTF_HOST;
if(memcmp(dest, gate, 16) != 0)
if(metric >= KERNEL_INFINITY) {
msg.rtmsg_ifindex = ifindex_lo;
} else {
msg.rtmsg_ifindex = ifindex;
if(plen < 128 || memcmp(dest, gate, 16) != 0)
msg.rtmsg_flags |= RTF_GATEWAY;
}
msg.rtmsg_metric = metric;
memcpy(&msg.rtmsg_dst, dest, sizeof(struct in6_addr));
msg.rtmsg_dst_len = plen;
memcpy(&msg.rtmsg_gateway, gate, sizeof(struct in6_addr));
msg.rtmsg_ifindex = ifindex;
rc = ioctl(route_socket, add ? SIOCADDRT : SIOCDELRT, &msg);
if(rc < 0)
return -1;
......
......@@ -20,9 +20,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#define KERNEL_INFINITY 0xFFFF
int kernel_setup(int setup);
int kernel_setup_interface(int setup, 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_route(int add, const unsigned char *dest, unsigned short plen,
const unsigned char *gate, int ifindex, int metric);
const unsigned char *gate, int ifindex, unsigned int metric);
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