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 #if !defined(GNU_LINUX) && !defined(SUNOS_5)
26 #include "zebra/ipforward.h"
32 extern struct zebra_privs_t zserv_privs
;
34 /* IPv4 forwarding control MIB. */
35 int mib
[MIB_SIZ
] = {CTL_NET
, PF_INET
, IPPROTO_IP
, IPCTL_FORWARDING
};
42 len
= sizeof ipforwarding
;
43 if (sysctl(mib
, MIB_SIZ
, &ipforwarding
, &len
, 0, 0) < 0) {
44 zlog_warn("Can't get ipforwarding value");
50 int ipforward_on(void)
55 len
= sizeof ipforwarding
;
56 if (zserv_privs
.change(ZPRIVS_RAISE
))
57 zlog_err("Can't raise privileges");
58 if (sysctl(mib
, MIB_SIZ
, NULL
, NULL
, &ipforwarding
, len
) < 0) {
59 if (zserv_privs
.change(ZPRIVS_LOWER
))
60 zlog_err("Can't lower privileges");
61 zlog_warn("Can't set ipforwarding on");
64 if (zserv_privs
.change(ZPRIVS_LOWER
))
65 zlog_err("Can't lower privileges");
69 int ipforward_off(void)
74 len
= sizeof ipforwarding
;
75 if (zserv_privs
.change(ZPRIVS_RAISE
))
76 zlog_err("Can't raise privileges");
77 if (sysctl(mib
, MIB_SIZ
, NULL
, NULL
, &ipforwarding
, len
) < 0) {
78 if (zserv_privs
.change(ZPRIVS_LOWER
))
79 zlog_err("Can't lower privileges");
80 zlog_warn("Can't set ipforwarding on");
83 if (zserv_privs
.change(ZPRIVS_LOWER
))
84 zlog_err("Can't lower privileges");
88 /* IPv6 forwarding control MIB. */
89 int mib_ipv6
[MIB_SIZ
] = {CTL_NET
, PF_INET6
,
90 #if defined(BSD_V6_SYSCTL)
91 IPPROTO_IPV6
, IPV6CTL_FORWARDING
92 #else /* NOT BSD_V6_SYSCTL */
93 IPPROTO_IP
, IP6CTL_FORWARDING
94 #endif /* BSD_V6_SYSCTL */
97 int ipforward_ipv6(void)
100 int ip6forwarding
= 0;
102 len
= sizeof ip6forwarding
;
103 if (zserv_privs
.change(ZPRIVS_RAISE
))
104 zlog_err("Can't raise privileges");
105 if (sysctl(mib_ipv6
, MIB_SIZ
, &ip6forwarding
, &len
, 0, 0) < 0) {
106 if (zserv_privs
.change(ZPRIVS_LOWER
))
107 zlog_err("Can't lower privileges");
108 zlog_warn("can't get ip6forwarding value");
111 if (zserv_privs
.change(ZPRIVS_LOWER
))
112 zlog_err("Can't lower privileges");
113 return ip6forwarding
;
116 int ipforward_ipv6_on(void)
119 int ip6forwarding
= 1;
121 len
= sizeof ip6forwarding
;
122 if (zserv_privs
.change(ZPRIVS_RAISE
))
123 zlog_err("Can't raise privileges");
124 if (sysctl(mib_ipv6
, MIB_SIZ
, NULL
, NULL
, &ip6forwarding
, len
) < 0) {
125 if (zserv_privs
.change(ZPRIVS_LOWER
))
126 zlog_err("Can't lower privileges");
127 zlog_warn("can't get ip6forwarding value");
130 if (zserv_privs
.change(ZPRIVS_LOWER
))
131 zlog_err("Can't lower privileges");
132 return ip6forwarding
;
135 int ipforward_ipv6_off(void)
138 int ip6forwarding
= 0;
140 len
= sizeof ip6forwarding
;
141 if (zserv_privs
.change(ZPRIVS_RAISE
))
142 zlog_err("Can't raise privileges");
143 if (sysctl(mib_ipv6
, MIB_SIZ
, NULL
, NULL
, &ip6forwarding
, len
) < 0) {
144 if (zserv_privs
.change(ZPRIVS_LOWER
))
145 zlog_err("Can't lower privileges");
146 zlog_warn("can't get ip6forwarding value");
149 if (zserv_privs
.change(ZPRIVS_LOWER
))
150 zlog_err("Can't lower privileges");
151 return ip6forwarding
;
154 #endif /* !defined(GNU_LINUX) && !defined(SUNOS_5) */