2 * Fetch ipforward value by reading /proc filesystem.
3 * Copyright (C) 1997 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #include "zebra/ipforward.h"
31 extern struct zebra_privs_t zserv_privs
;
33 static const char proc_net_snmp
[] = "/proc/net/snmp";
35 static void dropline(FILE *fp
)
37 while (getc(fp
) != '\n')
48 fp
= fopen(proc_net_snmp
, "r");
53 /* We don't care about the first line. */
56 /* Get ip_statistics.IpForwarding :
57 1 => ip forwarding enabled
58 2 => ip forwarding off. */
59 if (fgets(buf
, 6, fp
))
60 ret
= sscanf(buf
, "Ip: %d", &ipforwarding
);
64 if (ret
== 1 && ipforwarding
== 1)
70 /* char proc_ipv4_forwarding[] = "/proc/sys/net/ipv4/conf/all/forwarding"; */
71 static const char proc_ipv4_forwarding
[] = "/proc/sys/net/ipv4/ip_forward";
73 int ipforward_on(void)
77 frr_with_privs(&zserv_privs
) {
79 fp
= fopen(proc_ipv4_forwarding
, "w");
94 int ipforward_off(void)
98 frr_with_privs(&zserv_privs
) {
100 fp
= fopen(proc_ipv4_forwarding
, "w");
115 static const char proc_ipv6_forwarding
[] =
116 "/proc/sys/net/ipv6/conf/all/forwarding";
118 int ipforward_ipv6(void)
123 int ipforwarding
= 0;
125 fp
= fopen(proc_ipv6_forwarding
, "r");
130 if (fgets(buf
, 2, fp
))
131 ret
= sscanf(buf
, "%d", &ipforwarding
);
141 int ipforward_ipv6_on(void)
145 frr_with_privs(&zserv_privs
) {
147 fp
= fopen(proc_ipv6_forwarding
, "w");
159 return ipforward_ipv6();
163 int ipforward_ipv6_off(void)
167 frr_with_privs(&zserv_privs
) {
169 fp
= fopen(proc_ipv6_forwarding
, "w");
181 return ipforward_ipv6();
184 #endif /* GNU_LINUX */