blob: 828eb8655762977b68576b56ae8b4a9afbc4b34b [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* 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 *
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
19 * 02111-1307, USA.
20 */
21
22#include <zebra.h>
23
24#ifdef NRL
25#include <netinet6/in6.h>
26#endif /* NRL */
27
28#include "log.h"
29
30#define MIB_SIZ 4
31
32/* IPv4 forwarding control MIB. */
33int mib[MIB_SIZ] =
34{
35 CTL_NET,
36 PF_INET,
37 IPPROTO_IP,
38 IPCTL_FORWARDING
39};
40
41int
42ipforward ()
43{
44 int len;
45 int ipforwarding = 0;
46
47 len = sizeof ipforwarding;
48 if (sysctl (mib, MIB_SIZ, &ipforwarding, &len, 0, 0) < 0)
49 {
50 zlog_warn ("Can't get ipforwarding value");
51 return -1;
52 }
53 return ipforwarding;
54}
55
56int
57ipforward_on ()
58{
59 int len;
60 int ipforwarding = 1;
61
62 len = sizeof ipforwarding;
63 if (sysctl (mib, MIB_SIZ, NULL, NULL, &ipforwarding, len) < 0)
64 {
65 zlog_warn ("Can't set ipforwarding on");
66 return -1;
67 }
68 return ipforwarding;
69}
70
71int
72ipforward_off ()
73{
74 int len;
75 int ipforwarding = 0;
76
77 len = sizeof ipforwarding;
78 if (sysctl (mib, MIB_SIZ, NULL, NULL, &ipforwarding, len) < 0)
79 {
80 zlog_warn ("Can't set ipforwarding on");
81 return -1;
82 }
83 return ipforwarding;
84}
85
86#ifdef HAVE_IPV6
87
88/* IPv6 forwarding control MIB. */
89int mib_ipv6[MIB_SIZ] =
90{
91 CTL_NET,
92 PF_INET6,
93#if defined(KAME) || (defined(__bsdi__) && _BSDI_VERSION >= 199802 ) || defined(NRL)
94 IPPROTO_IPV6,
95 IPV6CTL_FORWARDING
96#else /* NOT KAME */
97 IPPROTO_IP,
98 IP6CTL_FORWARDING
99#endif /* KAME */
100};
101
102int
103ipforward_ipv6 ()
104{
105 int len;
106 int ip6forwarding = 0;
107
108 len = sizeof ip6forwarding;
109 if (sysctl (mib_ipv6, MIB_SIZ, &ip6forwarding, &len, 0, 0) < 0)
110 {
111 zlog_warn ("can't get ip6forwarding value");
112 return -1;
113 }
114 return ip6forwarding;
115}
116
117int
118ipforward_ipv6_on ()
119{
120 int len;
121 int ip6forwarding = 1;
122
123 len = sizeof ip6forwarding;
124 if (sysctl (mib_ipv6, MIB_SIZ, NULL, NULL, &ip6forwarding, len) < 0)
125 {
126 zlog_warn ("can't get ip6forwarding value");
127 return -1;
128 }
129 return ip6forwarding;
130}
131
132int
133ipforward_ipv6_off ()
134{
135 int len;
136 int ip6forwarding = 0;
137
138 len = sizeof ip6forwarding;
139 if (sysctl (mib_ipv6, MIB_SIZ, NULL, NULL, &ip6forwarding, len) < 0)
140 {
141 zlog_warn ("can't get ip6forwarding value");
142 return -1;
143 }
144 return ip6forwarding;
145}
146#endif /* HAVE_IPV6 */