diff options
author | Jukka Rissanen <jukka.rissanen@linux.intel.com> | 2011-10-21 11:16:54 +0300 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2011-10-21 16:32:51 +0200 |
commit | e94a8c5bd9a7c513b35fbbfc9b2c69120e0ed696 (patch) | |
tree | c8591628878a78546bd62e1f3d00c62ed49b7e1f /src/ipconfig.c | |
parent | 602aec9684a3121adbf39d5b8f4c4105b7f89ec3 (diff) | |
download | connman-e94a8c5bd9a7c513b35fbbfc9b2c69120e0ed696.tar.gz connman-e94a8c5bd9a7c513b35fbbfc9b2c69120e0ed696.tar.bz2 connman-e94a8c5bd9a7c513b35fbbfc9b2c69120e0ed696.zip |
ipconfig: Set/unset IPv4 rp_filter setting
Diffstat (limited to 'src/ipconfig.c')
-rw-r--r-- | src/ipconfig.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/ipconfig.c b/src/ipconfig.c index fd858a15..da61446e 100644 --- a/src/ipconfig.c +++ b/src/ipconfig.c @@ -452,6 +452,60 @@ static void set_ipv6_privacy(gchar *ifname, int value) fclose(f); } +static int get_rp_filter() +{ + FILE *f; + int value = -EINVAL, tmp; + + f = fopen("/proc/sys/net/ipv4/conf/all/rp_filter", "r"); + + if (f != NULL) { + if (fscanf(f, "%d", &tmp) == 1) + value = tmp; + fclose(f); + } + + return value; +} + +static void set_rp_filter(int value) +{ + FILE *f; + + f = fopen("/proc/sys/net/ipv4/conf/all/rp_filter", "r+"); + + if (f == NULL) + return; + + fprintf(f, "%d", value); + + fclose(f); +} + +int __connman_ipconfig_set_rp_filter() +{ + int value; + + value = get_rp_filter(); + + if (value < 0) + return value; + + set_rp_filter(2); + + connman_info("rp_filter set to 2 (loose mode routing), " + "old value was %d", value); + + return value; +} + +void __connman_ipconfig_unset_rp_filter(int old_value) +{ + set_rp_filter(old_value); + + connman_info("rp_filter restored to %d", old_value); +} + static void free_ipdevice(gpointer data) { struct connman_ipdevice *ipdevice = data; |