]> git.proxmox.com Git - mirror_frr.git/blame - zebra/ipforward_sysctl.c
*: add indent control files
[mirror_frr.git] / zebra / ipforward_sysctl.c
CommitLineData
718e3744 1/* IP forward control by sysctl function.
2 * Copyright (C) 1997, 1999 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
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
9 * later version.
10 *
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.
15 *
896014f4
DL
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
718e3744 19 */
20
21#include <zebra.h>
edd7c245 22#include "privs.h"
a1ac18c4 23#include "zebra/ipforward.h"
718e3744 24
718e3744 25#include "log.h"
26
27#define MIB_SIZ 4
28
edd7c245 29extern struct zebra_privs_t zserv_privs;
30
718e3744 31/* IPv4 forwarding control MIB. */
32int mib[MIB_SIZ] =
33{
34 CTL_NET,
35 PF_INET,
36 IPPROTO_IP,
37 IPCTL_FORWARDING
38};
39
40int
a1ac18c4 41ipforward (void)
718e3744 42{
a5ea687e 43 size_t len;
718e3744 44 int ipforwarding = 0;
45
46 len = sizeof ipforwarding;
47 if (sysctl (mib, MIB_SIZ, &ipforwarding, &len, 0, 0) < 0)
48 {
49 zlog_warn ("Can't get ipforwarding value");
50 return -1;
51 }
52 return ipforwarding;
53}
54
55int
a1ac18c4 56ipforward_on (void)
718e3744 57{
a5ea687e 58 size_t len;
718e3744 59 int ipforwarding = 1;
60
61 len = sizeof ipforwarding;
edd7c245 62 if (zserv_privs.change(ZPRIVS_RAISE))
4525281a 63 zlog_err("Can't raise privileges");
edd7c245 64 if (sysctl (mib, MIB_SIZ, NULL, NULL, &ipforwarding, len) < 0)
718e3744 65 {
edd7c245 66 if (zserv_privs.change(ZPRIVS_LOWER))
4525281a 67 zlog_err("Can't lower privileges");
718e3744 68 zlog_warn ("Can't set ipforwarding on");
69 return -1;
70 }
edd7c245 71 if (zserv_privs.change(ZPRIVS_LOWER))
4525281a 72 zlog_err("Can't lower privileges");
718e3744 73 return ipforwarding;
74}
75
76int
a1ac18c4 77ipforward_off (void)
718e3744 78{
a5ea687e 79 size_t len;
718e3744 80 int ipforwarding = 0;
81
82 len = sizeof ipforwarding;
edd7c245 83 if (zserv_privs.change(ZPRIVS_RAISE))
4525281a 84 zlog_err("Can't raise privileges");
edd7c245 85 if (sysctl (mib, MIB_SIZ, NULL, NULL, &ipforwarding, len) < 0)
718e3744 86 {
edd7c245 87 if (zserv_privs.change(ZPRIVS_LOWER))
4525281a 88 zlog_err("Can't lower privileges");
718e3744 89 zlog_warn ("Can't set ipforwarding on");
90 return -1;
91 }
edd7c245 92 if (zserv_privs.change(ZPRIVS_LOWER))
4525281a 93 zlog_err("Can't lower privileges");
718e3744 94 return ipforwarding;
95}
96
718e3744 97/* IPv6 forwarding control MIB. */
98int mib_ipv6[MIB_SIZ] =
99{
100 CTL_NET,
101 PF_INET6,
1cbb5dfc 102#if defined(KAME)
718e3744 103 IPPROTO_IPV6,
104 IPV6CTL_FORWARDING
105#else /* NOT KAME */
106 IPPROTO_IP,
107 IP6CTL_FORWARDING
108#endif /* KAME */
109};
110
111int
a1ac18c4 112ipforward_ipv6 (void)
718e3744 113{
a5ea687e 114 size_t len;
718e3744 115 int ip6forwarding = 0;
116
117 len = sizeof ip6forwarding;
edd7c245 118 if (zserv_privs.change(ZPRIVS_RAISE))
4525281a 119 zlog_err("Can't raise privileges");
edd7c245 120 if (sysctl (mib_ipv6, MIB_SIZ, &ip6forwarding, &len, 0, 0) < 0)
718e3744 121 {
edd7c245 122 if (zserv_privs.change(ZPRIVS_LOWER))
4525281a 123 zlog_err("Can't lower privileges");
718e3744 124 zlog_warn ("can't get ip6forwarding value");
125 return -1;
126 }
edd7c245 127 if (zserv_privs.change(ZPRIVS_LOWER))
4525281a 128 zlog_err("Can't lower privileges");
718e3744 129 return ip6forwarding;
130}
131
132int
a1ac18c4 133ipforward_ipv6_on (void)
718e3744 134{
a5ea687e 135 size_t len;
718e3744 136 int ip6forwarding = 1;
137
138 len = sizeof ip6forwarding;
edd7c245 139 if (zserv_privs.change(ZPRIVS_RAISE))
4525281a 140 zlog_err("Can't raise privileges");
edd7c245 141 if (sysctl (mib_ipv6, MIB_SIZ, NULL, NULL, &ip6forwarding, len) < 0)
718e3744 142 {
edd7c245 143 if (zserv_privs.change(ZPRIVS_LOWER))
4525281a 144 zlog_err("Can't lower privileges");
718e3744 145 zlog_warn ("can't get ip6forwarding value");
146 return -1;
147 }
edd7c245 148 if (zserv_privs.change(ZPRIVS_LOWER))
4525281a 149 zlog_err("Can't lower privileges");
718e3744 150 return ip6forwarding;
151}
152
153int
a1ac18c4 154ipforward_ipv6_off (void)
718e3744 155{
a5ea687e 156 size_t len;
718e3744 157 int ip6forwarding = 0;
158
159 len = sizeof ip6forwarding;
edd7c245 160 if (zserv_privs.change(ZPRIVS_RAISE))
4525281a 161 zlog_err("Can't raise privileges");
edd7c245 162 if (sysctl (mib_ipv6, MIB_SIZ, NULL, NULL, &ip6forwarding, len) < 0)
718e3744 163 {
edd7c245 164 if (zserv_privs.change(ZPRIVS_LOWER))
4525281a 165 zlog_err("Can't lower privileges");
718e3744 166 zlog_warn ("can't get ip6forwarding value");
167 return -1;
168 }
edd7c245 169 if (zserv_privs.change(ZPRIVS_LOWER))
4525281a 170 zlog_err("Can't lower privileges");
718e3744 171 return ip6forwarding;
172}