]> git.proxmox.com Git - mirror_frr.git/blob - zebra/ipforward_sysctl.c
isisd: implement the 'lsp-too-large' notification
[mirror_frr.git] / zebra / ipforward_sysctl.c
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 *
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
19 */
20
21 #include <zebra.h>
22
23 #if !defined(GNU_LINUX) && !defined(SUNOS_5)
24
25 #include "privs.h"
26 #include "zebra/ipforward.h"
27 #include "zebra/zebra_errors.h"
28
29 #include "log.h"
30 #include "lib_errors.h"
31
32 #define MIB_SIZ 4
33
34 extern struct zebra_privs_t zserv_privs;
35
36 /* IPv4 forwarding control MIB. */
37 int mib[MIB_SIZ] = {CTL_NET, PF_INET, IPPROTO_IP, IPCTL_FORWARDING};
38
39 int ipforward(void)
40 {
41 size_t len;
42 int ipforwarding = 0;
43
44 len = sizeof ipforwarding;
45 if (sysctl(mib, MIB_SIZ, &ipforwarding, &len, 0, 0) < 0) {
46 flog_err_sys(EC_LIB_SYSTEM_CALL,
47 "Can't get ipforwarding value");
48 return -1;
49 }
50 return ipforwarding;
51 }
52
53 int ipforward_on(void)
54 {
55 size_t len;
56 int ipforwarding = 1;
57
58 len = sizeof ipforwarding;
59 frr_elevate_privs(&zserv_privs) {
60 if (sysctl(mib, MIB_SIZ, NULL, NULL, &ipforwarding, len) < 0) {
61 flog_err_sys(EC_LIB_SYSTEM_CALL,
62 "Can't set ipforwarding on");
63 return -1;
64 }
65 }
66 return ipforwarding;
67 }
68
69 int ipforward_off(void)
70 {
71 size_t len;
72 int ipforwarding = 0;
73
74 len = sizeof ipforwarding;
75 frr_elevate_privs(&zserv_privs) {
76 if (sysctl(mib, MIB_SIZ, NULL, NULL, &ipforwarding, len) < 0) {
77 flog_err_sys(EC_LIB_SYSTEM_CALL,
78 "Can't set ipforwarding on");
79 return -1;
80 }
81 }
82 return ipforwarding;
83 }
84
85 /* IPv6 forwarding control MIB. */
86 int mib_ipv6[MIB_SIZ] = {CTL_NET, PF_INET6,
87 #if defined(BSD_V6_SYSCTL)
88 IPPROTO_IPV6, IPV6CTL_FORWARDING
89 #else /* NOT BSD_V6_SYSCTL */
90 IPPROTO_IP, IP6CTL_FORWARDING
91 #endif /* BSD_V6_SYSCTL */
92 };
93
94 int ipforward_ipv6(void)
95 {
96 size_t len;
97 int ip6forwarding = 0;
98
99 len = sizeof ip6forwarding;
100 frr_elevate_privs(&zserv_privs) {
101 if (sysctl(mib_ipv6, MIB_SIZ, &ip6forwarding, &len, 0, 0) < 0) {
102 flog_err_sys(EC_LIB_SYSTEM_CALL,
103 "can't get ip6forwarding value");
104 return -1;
105 }
106 }
107 return ip6forwarding;
108 }
109
110 int ipforward_ipv6_on(void)
111 {
112 size_t len;
113 int ip6forwarding = 1;
114
115 len = sizeof ip6forwarding;
116 frr_elevate_privs(&zserv_privs) {
117 if (sysctl(mib_ipv6, MIB_SIZ, NULL, NULL, &ip6forwarding, len)
118 < 0) {
119 flog_err_sys(EC_LIB_SYSTEM_CALL,
120 "can't get ip6forwarding value");
121 return -1;
122 }
123 }
124 return ip6forwarding;
125 }
126
127 int ipforward_ipv6_off(void)
128 {
129 size_t len;
130 int ip6forwarding = 0;
131
132 len = sizeof ip6forwarding;
133 frr_elevate_privs(&zserv_privs) {
134 if (sysctl(mib_ipv6, MIB_SIZ, NULL, NULL, &ip6forwarding, len)
135 < 0) {
136 flog_err_sys(EC_LIB_SYSTEM_CALL,
137 "can't get ip6forwarding value");
138 return -1;
139 }
140 }
141 return ip6forwarding;
142 }
143
144 #endif /* !defined(GNU_LINUX) && !defined(SUNOS_5) */