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"
29 #include "lib_errors.h"
33 extern struct zebra_privs_t zserv_privs
;
35 /* IPv4 forwarding control MIB. */
36 int mib
[MIB_SIZ
] = {CTL_NET
, PF_INET
, IPPROTO_IP
, IPCTL_FORWARDING
};
43 len
= sizeof ipforwarding
;
44 if (sysctl(mib
, MIB_SIZ
, &ipforwarding
, &len
, 0, 0) < 0) {
45 zlog_warn("Can't get ipforwarding value");
51 int ipforward_on(void)
56 len
= sizeof ipforwarding
;
57 frr_elevate_privs(&zserv_privs
) {
58 if (sysctl(mib
, MIB_SIZ
, NULL
, NULL
, &ipforwarding
, len
) < 0) {
59 zlog_warn("Can't set ipforwarding on");
66 int ipforward_off(void)
71 len
= sizeof ipforwarding
;
72 frr_elevate_privs(&zserv_privs
) {
73 if (sysctl(mib
, MIB_SIZ
, NULL
, NULL
, &ipforwarding
, len
) < 0) {
74 zlog_warn("Can't set ipforwarding on");
81 /* IPv6 forwarding control MIB. */
82 int mib_ipv6
[MIB_SIZ
] = {CTL_NET
, PF_INET6
,
83 #if defined(BSD_V6_SYSCTL)
84 IPPROTO_IPV6
, IPV6CTL_FORWARDING
85 #else /* NOT BSD_V6_SYSCTL */
86 IPPROTO_IP
, IP6CTL_FORWARDING
87 #endif /* BSD_V6_SYSCTL */
90 int ipforward_ipv6(void)
93 int ip6forwarding
= 0;
95 len
= sizeof ip6forwarding
;
96 frr_elevate_privs(&zserv_privs
) {
97 if (sysctl(mib_ipv6
, MIB_SIZ
, &ip6forwarding
, &len
, 0, 0) < 0) {
98 zlog_warn("can't get ip6forwarding value");
102 return ip6forwarding
;
105 int ipforward_ipv6_on(void)
108 int ip6forwarding
= 1;
110 len
= sizeof ip6forwarding
;
111 frr_elevate_privs(&zserv_privs
) {
112 if (sysctl(mib_ipv6
, MIB_SIZ
, NULL
, NULL
, &ip6forwarding
, len
)
114 zlog_warn("can't get ip6forwarding value");
118 return ip6forwarding
;
121 int ipforward_ipv6_off(void)
124 int ip6forwarding
= 0;
126 len
= sizeof ip6forwarding
;
127 frr_elevate_privs(&zserv_privs
) {
128 if (sysctl(mib_ipv6
, MIB_SIZ
, NULL
, NULL
, &ip6forwarding
, len
)
130 zlog_warn("can't get ip6forwarding value");
134 return ip6forwarding
;
137 #endif /* !defined(GNU_LINUX) && !defined(SUNOS_5) */