Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implement setting of IPv4 forwarding flag.

  • Loading branch information...
commit 9ff33c577bc07990c57ccb546cc535dd7074792d 1 parent f40cbec
@jech authored
Showing with 34 additions and 7 deletions.
  1. +3 −3 babel.c
  2. +1 −1  kernel.h
  3. +29 −2 kernel_netlink.c
  4. +1 −1  kernel_socket.c
View
6 babel.c
@@ -286,7 +286,7 @@ main(int argc, char **argv)
fprintf(stderr, "Respecting %ld second silent time.\n",
(long int)(reboot_time + silent_time - now.tv_sec));
- rc = kernel_setup(1);
+ rc = kernel_setup(1, do_ipv4);
if(rc < 0) {
fprintf(stderr, "kernel_setup failed.\n");
exit(1);
@@ -571,7 +571,7 @@ main(int argc, char **argv)
kernel_setup_interface(0, nets[i].ifname, nets[i].ifindex);
}
kernel_setup_socket(0);
- kernel_setup(0);
+ kernel_setup(0, do_ipv4);
fd = open(state_file, O_WRONLY | O_TRUNC | O_CREAT, 0644);
if(fd < 0) {
@@ -614,7 +614,7 @@ main(int argc, char **argv)
for(i = 0; i < numnets; i++)
kernel_setup_interface(0, nets[i].ifname, nets[i].ifindex);
kernel_setup_socket(0);
- kernel_setup(0);
+ kernel_setup(0, do_ipv4);
exit(1);
}
View
2  kernel.h
@@ -34,7 +34,7 @@ struct kernel_route {
#define ROUTE_ADD 1
#define ROUTE_MODIFY 2
-int kernel_setup(int setup);
+int kernel_setup(int setup, int ipv4);
int kernel_setup_socket(int setup);
int kernel_setup_interface(int setup, const char *ifname, int ifindex);
int kernel_interface_ipv4(const char *ifname, int ifindex, char *addr_r);
View
31 kernel_netlink.c
@@ -45,6 +45,7 @@ THE SOFTWARE.
#include "util.h"
static int old_forwarding = -1;
+static int old_ipv4_forwarding = -1;
static int old_accept_redirects = -1;
static int old_rp_filter = -1;
@@ -379,7 +380,7 @@ netlink_send_dump(int type, void *data, int len) {
}
int
-kernel_setup(int setup)
+kernel_setup(int setup, int ipv4)
{
int rc;
@@ -403,6 +404,22 @@ kernel_setup(int setup)
return -1;
}
+ if(ipv4) {
+ old_ipv4_forwarding =
+ read_proc("/proc/sys/net/ipv4/conf/all/forwarding");
+ if(old_ipv4_forwarding < 0) {
+ perror("Couldn't read IPv4 forwarding knob.");
+ return -1;
+ }
+
+ rc = write_proc("/proc/sys/net/ipv4/conf/all/forwarding", 1);
+ if(rc < 0) {
+ perror("Couldn't write IPv4 forwarding knob.");
+ return -1;
+ }
+ }
+
+
old_accept_redirects =
read_proc("/proc/sys/net/ipv6/conf/all/accept_redirects");
if(old_accept_redirects < 0) {
@@ -435,10 +452,20 @@ kernel_setup(int setup)
rc = write_proc("/proc/sys/net/ipv6/conf/all/forwarding",
old_forwarding);
if(rc < 0) {
- perror("Couldn't write accept_redirects knob.\n");
+ perror("Couldn't write forwarding knob.\n");
+ return -1;
+ }
+ }
+
+ if(old_ipv4_forwarding >= 0) {
+ rc = write_proc("/proc/sys/net/ipv4/conf/all/forwarding",
+ old_ipv4_forwarding);
+ if(rc < 0) {
+ perror("Couldn't write IPv4 forwarding knob.\n");
return -1;
}
}
+
if(old_accept_redirects >= 0) {
rc = write_proc("/proc/sys/net/ipv6/conf/all/accept_redirects",
old_accept_redirects);
View
2  kernel_socket.c
@@ -136,7 +136,7 @@ plen2mask(int n, struct in6_addr *dest)
}
int
-kernel_setup(int setup)
+kernel_setup(int setup, int ipv4)
{
int rc;
if(setup) {
Please sign in to comment.
Something went wrong with that request. Please try again.