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"
30 extern struct zebra_privs_t zserv_privs
;
32 /* IPv4 forwarding control MIB. */
47 len
= sizeof ipforwarding
;
48 if (sysctl (mib
, MIB_SIZ
, &ipforwarding
, &len
, 0, 0) < 0)
50 zlog_warn ("Can't get ipforwarding value");
62 len
= sizeof ipforwarding
;
63 if (zserv_privs
.change(ZPRIVS_RAISE
))
64 zlog (NULL
, LOG_ERR
, "Can't raise privileges");
65 if (sysctl (mib
, MIB_SIZ
, NULL
, NULL
, &ipforwarding
, len
) < 0)
67 if (zserv_privs
.change(ZPRIVS_LOWER
))
68 zlog (NULL
, LOG_ERR
, "Can't lower privileges");
69 zlog_warn ("Can't set ipforwarding on");
72 if (zserv_privs
.change(ZPRIVS_LOWER
))
73 zlog (NULL
, LOG_ERR
, "Can't lower privileges");
83 len
= sizeof ipforwarding
;
84 if (zserv_privs
.change(ZPRIVS_RAISE
))
85 zlog (NULL
, LOG_ERR
, "Can't raise privileges");
86 if (sysctl (mib
, MIB_SIZ
, NULL
, NULL
, &ipforwarding
, len
) < 0)
88 if (zserv_privs
.change(ZPRIVS_LOWER
))
89 zlog (NULL
, LOG_ERR
, "Can't lower privileges");
90 zlog_warn ("Can't set ipforwarding on");
93 if (zserv_privs
.change(ZPRIVS_LOWER
))
94 zlog (NULL
, LOG_ERR
, "Can't lower privileges");
98 /* IPv6 forwarding control MIB. */
99 int mib_ipv6
[MIB_SIZ
] =
113 ipforward_ipv6 (void)
116 int ip6forwarding
= 0;
118 len
= sizeof ip6forwarding
;
119 if (zserv_privs
.change(ZPRIVS_RAISE
))
120 zlog (NULL
, LOG_ERR
, "Can't raise privileges");
121 if (sysctl (mib_ipv6
, MIB_SIZ
, &ip6forwarding
, &len
, 0, 0) < 0)
123 if (zserv_privs
.change(ZPRIVS_LOWER
))
124 zlog (NULL
, LOG_ERR
, "Can't lower privileges");
125 zlog_warn ("can't get ip6forwarding value");
128 if (zserv_privs
.change(ZPRIVS_LOWER
))
129 zlog (NULL
, LOG_ERR
, "Can't lower privileges");
130 return ip6forwarding
;
134 ipforward_ipv6_on (void)
137 int ip6forwarding
= 1;
139 len
= sizeof ip6forwarding
;
140 if (zserv_privs
.change(ZPRIVS_RAISE
))
141 zlog (NULL
, LOG_ERR
, "Can't raise privileges");
142 if (sysctl (mib_ipv6
, MIB_SIZ
, NULL
, NULL
, &ip6forwarding
, len
) < 0)
144 if (zserv_privs
.change(ZPRIVS_LOWER
))
145 zlog (NULL
, LOG_ERR
, "Can't lower privileges");
146 zlog_warn ("can't get ip6forwarding value");
149 if (zserv_privs
.change(ZPRIVS_LOWER
))
150 zlog (NULL
, LOG_ERR
, "Can't lower privileges");
151 return ip6forwarding
;
155 ipforward_ipv6_off (void)
158 int ip6forwarding
= 0;
160 len
= sizeof ip6forwarding
;
161 if (zserv_privs
.change(ZPRIVS_RAISE
))
162 zlog (NULL
, LOG_ERR
, "Can't raise privileges");
163 if (sysctl (mib_ipv6
, MIB_SIZ
, NULL
, NULL
, &ip6forwarding
, len
) < 0)
165 if (zserv_privs
.change(ZPRIVS_LOWER
))
166 zlog (NULL
, LOG_ERR
, "Can't lower privileges");
167 zlog_warn ("can't get ip6forwarding value");
170 if (zserv_privs
.change(ZPRIVS_LOWER
))
171 zlog (NULL
, LOG_ERR
, "Can't lower privileges");
172 return ip6forwarding
;