Commit 9ff33c57 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Implement setting of IPv4 forwarding flag.

parent f40cbec0
...@@ -286,7 +286,7 @@ main(int argc, char **argv) ...@@ -286,7 +286,7 @@ main(int argc, char **argv)
fprintf(stderr, "Respecting %ld second silent time.\n", fprintf(stderr, "Respecting %ld second silent time.\n",
(long int)(reboot_time + silent_time - now.tv_sec)); (long int)(reboot_time + silent_time - now.tv_sec));
rc = kernel_setup(1); rc = kernel_setup(1, do_ipv4);
if(rc < 0) { if(rc < 0) {
fprintf(stderr, "kernel_setup failed.\n"); fprintf(stderr, "kernel_setup failed.\n");
exit(1); exit(1);
...@@ -571,7 +571,7 @@ main(int argc, char **argv) ...@@ -571,7 +571,7 @@ main(int argc, char **argv)
kernel_setup_interface(0, nets[i].ifname, nets[i].ifindex); kernel_setup_interface(0, nets[i].ifname, nets[i].ifindex);
} }
kernel_setup_socket(0); kernel_setup_socket(0);
kernel_setup(0); kernel_setup(0, do_ipv4);
fd = open(state_file, O_WRONLY | O_TRUNC | O_CREAT, 0644); fd = open(state_file, O_WRONLY | O_TRUNC | O_CREAT, 0644);
if(fd < 0) { if(fd < 0) {
...@@ -614,7 +614,7 @@ main(int argc, char **argv) ...@@ -614,7 +614,7 @@ main(int argc, char **argv)
for(i = 0; i < numnets; i++) for(i = 0; i < numnets; i++)
kernel_setup_interface(0, nets[i].ifname, nets[i].ifindex); kernel_setup_interface(0, nets[i].ifname, nets[i].ifindex);
kernel_setup_socket(0); kernel_setup_socket(0);
kernel_setup(0); kernel_setup(0, do_ipv4);
exit(1); exit(1);
} }
......
...@@ -34,7 +34,7 @@ struct kernel_route { ...@@ -34,7 +34,7 @@ struct kernel_route {
#define ROUTE_ADD 1 #define ROUTE_ADD 1
#define ROUTE_MODIFY 2 #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_socket(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_ipv4(const char *ifname, int ifindex, char *addr_r); int kernel_interface_ipv4(const char *ifname, int ifindex, char *addr_r);
......
...@@ -45,6 +45,7 @@ THE SOFTWARE. ...@@ -45,6 +45,7 @@ THE SOFTWARE.
#include "util.h" #include "util.h"
static int old_forwarding = -1; static int old_forwarding = -1;
static int old_ipv4_forwarding = -1;
static int old_accept_redirects = -1; static int old_accept_redirects = -1;
static int old_rp_filter = -1; static int old_rp_filter = -1;
...@@ -379,7 +380,7 @@ netlink_send_dump(int type, void *data, int len) { ...@@ -379,7 +380,7 @@ netlink_send_dump(int type, void *data, int len) {
} }
int int
kernel_setup(int setup) kernel_setup(int setup, int ipv4)
{ {
int rc; int rc;
...@@ -403,6 +404,22 @@ kernel_setup(int setup) ...@@ -403,6 +404,22 @@ kernel_setup(int setup)
return -1; 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 = old_accept_redirects =
read_proc("/proc/sys/net/ipv6/conf/all/accept_redirects"); read_proc("/proc/sys/net/ipv6/conf/all/accept_redirects");
if(old_accept_redirects < 0) { if(old_accept_redirects < 0) {
...@@ -435,10 +452,20 @@ kernel_setup(int setup) ...@@ -435,10 +452,20 @@ kernel_setup(int setup)
rc = write_proc("/proc/sys/net/ipv6/conf/all/forwarding", rc = write_proc("/proc/sys/net/ipv6/conf/all/forwarding",
old_forwarding); old_forwarding);
if(rc < 0) { 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; return -1;
} }
} }
if(old_accept_redirects >= 0) { if(old_accept_redirects >= 0) {
rc = write_proc("/proc/sys/net/ipv6/conf/all/accept_redirects", rc = write_proc("/proc/sys/net/ipv6/conf/all/accept_redirects",
old_accept_redirects); old_accept_redirects);
......
...@@ -136,7 +136,7 @@ plen2mask(int n, struct in6_addr *dest) ...@@ -136,7 +136,7 @@ plen2mask(int n, struct in6_addr *dest)
} }
int int
kernel_setup(int setup) kernel_setup(int setup, int ipv4)
{ {
int rc; int rc;
if(setup) { if(setup) {
......
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