1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Fetch ipforward value by reading /proc filesystem.
4 * Copyright (C) 1997 Kunihiro Ishiguro
14 #include "zebra/ipforward.h"
16 extern struct zebra_privs_t zserv_privs
;
18 static const char proc_net_snmp
[] = "/proc/net/snmp";
20 static void dropline(FILE *fp
)
22 while (getc(fp
) != '\n')
33 fp
= fopen(proc_net_snmp
, "r");
38 /* We don't care about the first line. */
41 /* Get ip_statistics.IpForwarding :
42 1 => ip forwarding enabled
43 2 => ip forwarding off. */
44 if (fgets(buf
, 6, fp
))
45 ret
= sscanf(buf
, "Ip: %d", &ipforwarding
);
49 if (ret
== 1 && ipforwarding
== 1)
55 /* char proc_ipv4_forwarding[] = "/proc/sys/net/ipv4/conf/all/forwarding"; */
56 static const char proc_ipv4_forwarding
[] = "/proc/sys/net/ipv4/ip_forward";
58 int ipforward_on(void)
62 frr_with_privs(&zserv_privs
) {
64 fp
= fopen(proc_ipv4_forwarding
, "w");
79 int ipforward_off(void)
83 frr_with_privs(&zserv_privs
) {
85 fp
= fopen(proc_ipv4_forwarding
, "w");
100 static const char proc_ipv6_forwarding
[] =
101 "/proc/sys/net/ipv6/conf/all/forwarding";
103 int ipforward_ipv6(void)
108 int ipforwarding
= 0;
110 fp
= fopen(proc_ipv6_forwarding
, "r");
115 if (fgets(buf
, 2, fp
))
116 ret
= sscanf(buf
, "%d", &ipforwarding
);
126 int ipforward_ipv6_on(void)
130 frr_with_privs(&zserv_privs
) {
132 fp
= fopen(proc_ipv6_forwarding
, "w");
144 return ipforward_ipv6();
148 int ipforward_ipv6_off(void)
152 frr_with_privs(&zserv_privs
) {
154 fp
= fopen(proc_ipv6_forwarding
, "w");
166 return ipforward_ipv6();
169 #endif /* GNU_LINUX */