1 /* IP forward control by sysctl function.
2 * Copyright (C) 1997, 1999 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "zebra/ipforward.h"
29 extern struct zebra_privs_t zserv_privs
;
31 /* IPv4 forwarding control MIB. */
46 len
= sizeof ipforwarding
;
47 if (sysctl (mib
, MIB_SIZ
, &ipforwarding
, &len
, 0, 0) < 0)
49 zlog_warn ("Can't get ipforwarding value");
61 len
= sizeof ipforwarding
;
62 if (zserv_privs
.change(ZPRIVS_RAISE
))
63 zlog_err("Can't raise privileges");
64 if (sysctl (mib
, MIB_SIZ
, NULL
, NULL
, &ipforwarding
, len
) < 0)
66 if (zserv_privs
.change(ZPRIVS_LOWER
))
67 zlog_err("Can't lower privileges");
68 zlog_warn ("Can't set ipforwarding on");
71 if (zserv_privs
.change(ZPRIVS_LOWER
))
72 zlog_err("Can't lower privileges");
82 len
= sizeof ipforwarding
;
83 if (zserv_privs
.change(ZPRIVS_RAISE
))
84 zlog_err("Can't raise privileges");
85 if (sysctl (mib
, MIB_SIZ
, NULL
, NULL
, &ipforwarding
, len
) < 0)
87 if (zserv_privs
.change(ZPRIVS_LOWER
))
88 zlog_err("Can't lower privileges");
89 zlog_warn ("Can't set ipforwarding on");
92 if (zserv_privs
.change(ZPRIVS_LOWER
))
93 zlog_err("Can't lower privileges");
97 /* IPv6 forwarding control MIB. */
98 int mib_ipv6
[MIB_SIZ
] =
112 ipforward_ipv6 (void)
115 int ip6forwarding
= 0;
117 len
= sizeof ip6forwarding
;
118 if (zserv_privs
.change(ZPRIVS_RAISE
))
119 zlog_err("Can't raise privileges");
120 if (sysctl (mib_ipv6
, MIB_SIZ
, &ip6forwarding
, &len
, 0, 0) < 0)
122 if (zserv_privs
.change(ZPRIVS_LOWER
))
123 zlog_err("Can't lower privileges");
124 zlog_warn ("can't get ip6forwarding value");
127 if (zserv_privs
.change(ZPRIVS_LOWER
))
128 zlog_err("Can't lower privileges");
129 return ip6forwarding
;
133 ipforward_ipv6_on (void)
136 int ip6forwarding
= 1;
138 len
= sizeof ip6forwarding
;
139 if (zserv_privs
.change(ZPRIVS_RAISE
))
140 zlog_err("Can't raise privileges");
141 if (sysctl (mib_ipv6
, MIB_SIZ
, NULL
, NULL
, &ip6forwarding
, len
) < 0)
143 if (zserv_privs
.change(ZPRIVS_LOWER
))
144 zlog_err("Can't lower privileges");
145 zlog_warn ("can't get ip6forwarding value");
148 if (zserv_privs
.change(ZPRIVS_LOWER
))
149 zlog_err("Can't lower privileges");
150 return ip6forwarding
;
154 ipforward_ipv6_off (void)
157 int ip6forwarding
= 0;
159 len
= sizeof ip6forwarding
;
160 if (zserv_privs
.change(ZPRIVS_RAISE
))
161 zlog_err("Can't raise privileges");
162 if (sysctl (mib_ipv6
, MIB_SIZ
, NULL
, NULL
, &ip6forwarding
, len
) < 0)
164 if (zserv_privs
.change(ZPRIVS_LOWER
))
165 zlog_err("Can't lower privileges");
166 zlog_warn ("can't get ip6forwarding value");
169 if (zserv_privs
.change(ZPRIVS_LOWER
))
170 zlog_err("Can't lower privileges");
171 return ip6forwarding
;