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