+static int get_ipv6_privacy(gchar *ifname)
+{
+ gchar *path;
+ FILE *f;
+ int value;
+
+ if (!ifname)
+ return 0;
+
+ path = g_strdup_printf("/proc/sys/net/ipv6/conf/%s/use_tempaddr",
+ ifname);
+
+ if (!path)
+ return 0;
+
+ f = fopen(path, "r");
+
+ g_free(path);
+
+ if (!f)
+ return 0;
+
+ if (fscanf(f, "%d", &value) <= 0)
+ value = 0;
+
+ fclose(f);
+
+ return value;
+}
+
+/* Enable the IPv6 privacy extension for stateless address autoconfiguration.
+ * The privacy extension is described in RFC 3041 and RFC 4941
+ */
+static void set_ipv6_privacy(gchar *ifname, int value)
+{
+ gchar *path;
+ FILE *f;
+
+ if (!ifname)
+ return;
+
+ path = g_strdup_printf("/proc/sys/net/ipv6/conf/%s/use_tempaddr",
+ ifname);
+
+ if (!path)
+ return;
+
+ if (value < 0)
+ value = 0;
+
+ f = fopen(path, "r+");
+
+ g_free(path);
+
+ if (!f)
+ return;
+
+ fprintf(f, "%d", value);
+ fclose(f);
+}
+
+static int get_rp_filter(void)
+{
+ FILE *f;
+ int value = -EINVAL, tmp;
+
+ f = fopen("/proc/sys/net/ipv4/conf/all/rp_filter", "r");
+
+ if (f) {
+ 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)
+ 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);
+}
+
+bool __connman_ipconfig_ipv6_privacy_enabled(struct connman_ipconfig *ipconfig)
+{
+ if (!ipconfig)
+ return false;
+
+ return ipconfig->ipv6_privacy_config == 0 ? FALSE : TRUE;
+}
+
+bool __connman_ipconfig_ipv6_is_enabled(struct connman_ipconfig *ipconfig)
+{
+ struct connman_ipdevice *ipdevice;
+ char *ifname;
+ bool ret;
+
+ if (!ipconfig)
+ return false;
+
+ ipdevice = g_hash_table_lookup(ipdevice_hash,
+ GINT_TO_POINTER(ipconfig->index));
+ if (!ipdevice)
+ return false;
+
+ ifname = connman_inet_ifname(ipconfig->index);
+ ret = get_ipv6_state(ifname);
+ g_free(ifname);
+
+ return ret;
+}
+