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
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 extern struct zebra_privs_t zserv_privs
;
30 char proc_net_snmp
[] = "/proc/net/snmp";
37 while ((c
= getc (fp
)) != '\n')
49 fp
= fopen (proc_net_snmp
, "r");
54 /* We don't care about the first line. */
57 /* Get ip_statistics.IpForwarding :
58 1 => ip forwarding enabled
59 2 => ip forwarding off. */
60 pnt
= fgets (buf
, 6, fp
);
61 sscanf (buf
, "Ip: %d", &ipforwarding
);
65 if (ipforwarding
== 1)
71 /* char proc_ipv4_forwarding[] = "/proc/sys/net/ipv4/conf/all/forwarding"; */
72 char proc_ipv4_forwarding
[] = "/proc/sys/net/ipv4/ip_forward";
79 if ( zserv_privs
.change(ZPRIVS_RAISE
) )
80 zlog_err ("Can't raise privileges, %s", safe_strerror (errno
) );
82 fp
= fopen (proc_ipv4_forwarding
, "w");
85 if ( zserv_privs
.change(ZPRIVS_LOWER
) )
86 zlog_err ("Can't lower privileges, %s", safe_strerror (errno
));
94 if ( zserv_privs
.change(ZPRIVS_LOWER
) )
95 zlog_err ("Can't lower privileges, %s", safe_strerror (errno
));
105 if ( zserv_privs
.change(ZPRIVS_RAISE
) )
106 zlog_err ("Can't raise privileges, %s", safe_strerror (errno
));
108 fp
= fopen (proc_ipv4_forwarding
, "w");
111 if ( zserv_privs
.change(ZPRIVS_LOWER
) )
112 zlog_err ("Can't lower privileges, %s", safe_strerror (errno
));
120 if ( zserv_privs
.change(ZPRIVS_LOWER
) )
121 zlog_err ("Can't lower privileges, %s", safe_strerror (errno
));
127 char proc_ipv6_forwarding
[] = "/proc/sys/net/ipv6/conf/all/forwarding";
134 int ipforwarding
= 0;
136 fp
= fopen (proc_ipv6_forwarding
, "r");
142 sscanf (buf
, "%d", &ipforwarding
);
153 if ( zserv_privs
.change(ZPRIVS_RAISE
) )
154 zlog_err ("Can't raise privileges, %s", safe_strerror (errno
));
156 fp
= fopen (proc_ipv6_forwarding
, "w");
159 if ( zserv_privs
.change(ZPRIVS_LOWER
) )
160 zlog_err ("Can't lower privileges, %s", safe_strerror (errno
));
168 if ( zserv_privs
.change(ZPRIVS_LOWER
) )
169 zlog_err ("Can't lower privileges, %s", safe_strerror (errno
));
171 return ipforward_ipv6 ();
175 ipforward_ipv6_off ()
179 if ( zserv_privs
.change(ZPRIVS_RAISE
) )
180 zlog_err ("Can't raise privileges, %s", safe_strerror (errno
));
182 fp
= fopen (proc_ipv6_forwarding
, "w");
185 if ( zserv_privs
.change(ZPRIVS_LOWER
) )
186 zlog_err ("Can't lower privileges, %s", safe_strerror (errno
));
194 if ( zserv_privs
.change(ZPRIVS_LOWER
) )
195 zlog_err ("Can't lower privileges, %s", safe_strerror (errno
));
197 return ipforward_ipv6 ();
199 #endif /* HAVE_IPV6 */