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
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 #include "zebra/ipforward.h"
27 #include <netinet6/in6.h>
34 extern struct zebra_privs_t zserv_privs
;
36 /* IPv4 forwarding control MIB. */
51 len
= sizeof ipforwarding
;
52 if (sysctl (mib
, MIB_SIZ
, &ipforwarding
, &len
, 0, 0) < 0)
54 zlog_warn ("Can't get ipforwarding value");
66 len
= sizeof ipforwarding
;
67 if (zserv_privs
.change(ZPRIVS_RAISE
))
68 zlog (NULL
, LOG_ERR
, "Can't raise privileges");
69 if (sysctl (mib
, MIB_SIZ
, NULL
, NULL
, &ipforwarding
, len
) < 0)
71 if (zserv_privs
.change(ZPRIVS_LOWER
))
72 zlog (NULL
, LOG_ERR
, "Can't lower privileges");
73 zlog_warn ("Can't set ipforwarding on");
76 if (zserv_privs
.change(ZPRIVS_LOWER
))
77 zlog (NULL
, LOG_ERR
, "Can't lower privileges");
87 len
= sizeof ipforwarding
;
88 if (zserv_privs
.change(ZPRIVS_RAISE
))
89 zlog (NULL
, LOG_ERR
, "Can't raise privileges");
90 if (sysctl (mib
, MIB_SIZ
, NULL
, NULL
, &ipforwarding
, len
) < 0)
92 if (zserv_privs
.change(ZPRIVS_LOWER
))
93 zlog (NULL
, LOG_ERR
, "Can't lower privileges");
94 zlog_warn ("Can't set ipforwarding on");
97 if (zserv_privs
.change(ZPRIVS_LOWER
))
98 zlog (NULL
, LOG_ERR
, "Can't lower privileges");
104 /* IPv6 forwarding control MIB. */
105 int mib_ipv6
[MIB_SIZ
] =
109 #if defined(KAME) || (defined(__bsdi__) && _BSDI_VERSION >= 199802 ) || defined(NRL)
119 ipforward_ipv6 (void)
122 int ip6forwarding
= 0;
124 len
= sizeof ip6forwarding
;
125 if (zserv_privs
.change(ZPRIVS_RAISE
))
126 zlog (NULL
, LOG_ERR
, "Can't raise privileges");
127 if (sysctl (mib_ipv6
, MIB_SIZ
, &ip6forwarding
, &len
, 0, 0) < 0)
129 if (zserv_privs
.change(ZPRIVS_LOWER
))
130 zlog (NULL
, LOG_ERR
, "Can't lower privileges");
131 zlog_warn ("can't get ip6forwarding value");
134 if (zserv_privs
.change(ZPRIVS_LOWER
))
135 zlog (NULL
, LOG_ERR
, "Can't lower privileges");
136 return ip6forwarding
;
140 ipforward_ipv6_on (void)
143 int ip6forwarding
= 1;
145 len
= sizeof ip6forwarding
;
146 if (zserv_privs
.change(ZPRIVS_RAISE
))
147 zlog (NULL
, LOG_ERR
, "Can't raise privileges");
148 if (sysctl (mib_ipv6
, MIB_SIZ
, NULL
, NULL
, &ip6forwarding
, len
) < 0)
150 if (zserv_privs
.change(ZPRIVS_LOWER
))
151 zlog (NULL
, LOG_ERR
, "Can't lower privileges");
152 zlog_warn ("can't get ip6forwarding value");
155 if (zserv_privs
.change(ZPRIVS_LOWER
))
156 zlog (NULL
, LOG_ERR
, "Can't lower privileges");
157 return ip6forwarding
;
161 ipforward_ipv6_off (void)
164 int ip6forwarding
= 0;
166 len
= sizeof ip6forwarding
;
167 if (zserv_privs
.change(ZPRIVS_RAISE
))
168 zlog (NULL
, LOG_ERR
, "Can't raise privileges");
169 if (sysctl (mib_ipv6
, MIB_SIZ
, NULL
, NULL
, &ip6forwarding
, len
) < 0)
171 if (zserv_privs
.change(ZPRIVS_LOWER
))
172 zlog (NULL
, LOG_ERR
, "Can't lower privileges");
173 zlog_warn ("can't get ip6forwarding value");
176 if (zserv_privs
.change(ZPRIVS_LOWER
))
177 zlog (NULL
, LOG_ERR
, "Can't lower privileges");
178 return ip6forwarding
;
180 #endif /* HAVE_IPV6 */