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 #include "zebra/ipforward.h"
30 extern struct zebra_privs_t zserv_privs
;
32 char proc_net_snmp
[] = "/proc/net/snmp";
39 while ((c
= getc (fp
)) != '\n')
51 fp
= fopen (proc_net_snmp
, "r");
56 /* We don't care about the first line. */
59 /* Get ip_statistics.IpForwarding :
60 1 => ip forwarding enabled
61 2 => ip forwarding off. */
62 pnt
= fgets (buf
, 6, fp
);
63 sscanf (buf
, "Ip: %d", &ipforwarding
);
67 if (ipforwarding
== 1)
73 /* char proc_ipv4_forwarding[] = "/proc/sys/net/ipv4/conf/all/forwarding"; */
74 char proc_ipv4_forwarding
[] = "/proc/sys/net/ipv4/ip_forward";
81 if ( zserv_privs
.change(ZPRIVS_RAISE
) )
82 zlog_err ("Can't raise privileges, %s", safe_strerror (errno
) );
84 fp
= fopen (proc_ipv4_forwarding
, "w");
87 if ( zserv_privs
.change(ZPRIVS_LOWER
) )
88 zlog_err ("Can't lower privileges, %s", safe_strerror (errno
));
96 if ( zserv_privs
.change(ZPRIVS_LOWER
) )
97 zlog_err ("Can't lower privileges, %s", safe_strerror (errno
));
107 if ( zserv_privs
.change(ZPRIVS_RAISE
) )
108 zlog_err ("Can't raise privileges, %s", safe_strerror (errno
));
110 fp
= fopen (proc_ipv4_forwarding
, "w");
113 if ( zserv_privs
.change(ZPRIVS_LOWER
) )
114 zlog_err ("Can't lower privileges, %s", safe_strerror (errno
));
122 if ( zserv_privs
.change(ZPRIVS_LOWER
) )
123 zlog_err ("Can't lower privileges, %s", safe_strerror (errno
));
129 char proc_ipv6_forwarding
[] = "/proc/sys/net/ipv6/conf/all/forwarding";
132 ipforward_ipv6 (void)
136 int ipforwarding
= 0;
138 fp
= fopen (proc_ipv6_forwarding
, "r");
144 sscanf (buf
, "%d", &ipforwarding
);
151 ipforward_ipv6_on (void)
155 if ( zserv_privs
.change(ZPRIVS_RAISE
) )
156 zlog_err ("Can't raise privileges, %s", safe_strerror (errno
));
158 fp
= fopen (proc_ipv6_forwarding
, "w");
161 if ( zserv_privs
.change(ZPRIVS_LOWER
) )
162 zlog_err ("Can't lower privileges, %s", safe_strerror (errno
));
170 if ( zserv_privs
.change(ZPRIVS_LOWER
) )
171 zlog_err ("Can't lower privileges, %s", safe_strerror (errno
));
173 return ipforward_ipv6 ();
177 ipforward_ipv6_off (void)
181 if ( zserv_privs
.change(ZPRIVS_RAISE
) )
182 zlog_err ("Can't raise privileges, %s", safe_strerror (errno
));
184 fp
= fopen (proc_ipv6_forwarding
, "w");
187 if ( zserv_privs
.change(ZPRIVS_LOWER
) )
188 zlog_err ("Can't lower privileges, %s", safe_strerror (errno
));
196 if ( zserv_privs
.change(ZPRIVS_LOWER
) )
197 zlog_err ("Can't lower privileges, %s", safe_strerror (errno
));
199 return ipforward_ipv6 ();
201 #endif /* HAVE_IPV6 */