]>
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) { | |
450971aa | 46 | flog_err_sys(EC_LIB_SYSTEM_CALL, "Can't get ipforwarding value"); |
d62a17ae | 47 | return -1; |
48 | } | |
49 | return ipforwarding; | |
718e3744 | 50 | } |
51 | ||
d62a17ae | 52 | int ipforward_on(void) |
718e3744 | 53 | { |
d62a17ae | 54 | size_t len; |
55 | int ipforwarding = 1; | |
56 | ||
57 | len = sizeof ipforwarding; | |
01b9e3fd DL |
58 | frr_elevate_privs(&zserv_privs) { |
59 | if (sysctl(mib, MIB_SIZ, NULL, NULL, &ipforwarding, len) < 0) { | |
450971aa | 60 | flog_err_sys(EC_LIB_SYSTEM_CALL, |
9df414fe | 61 | "Can't set ipforwarding on"); |
01b9e3fd DL |
62 | return -1; |
63 | } | |
d62a17ae | 64 | } |
d62a17ae | 65 | return ipforwarding; |
718e3744 | 66 | } |
67 | ||
d62a17ae | 68 | int ipforward_off(void) |
718e3744 | 69 | { |
d62a17ae | 70 | size_t len; |
71 | int ipforwarding = 0; | |
72 | ||
73 | len = sizeof ipforwarding; | |
01b9e3fd DL |
74 | frr_elevate_privs(&zserv_privs) { |
75 | if (sysctl(mib, MIB_SIZ, NULL, NULL, &ipforwarding, len) < 0) { | |
450971aa | 76 | flog_err_sys(EC_LIB_SYSTEM_CALL, |
9df414fe | 77 | "Can't set ipforwarding on"); |
01b9e3fd DL |
78 | return -1; |
79 | } | |
d62a17ae | 80 | } |
d62a17ae | 81 | return ipforwarding; |
718e3744 | 82 | } |
83 | ||
718e3744 | 84 | /* IPv6 forwarding control MIB. */ |
d62a17ae | 85 | int mib_ipv6[MIB_SIZ] = {CTL_NET, PF_INET6, |
d616d639 | 86 | #if defined(BSD_V6_SYSCTL) |
d62a17ae | 87 | IPPROTO_IPV6, IPV6CTL_FORWARDING |
d616d639 | 88 | #else /* NOT BSD_V6_SYSCTL */ |
d62a17ae | 89 | IPPROTO_IP, IP6CTL_FORWARDING |
d616d639 | 90 | #endif /* BSD_V6_SYSCTL */ |
d62a17ae | 91 | }; |
718e3744 | 92 | |
d62a17ae | 93 | int ipforward_ipv6(void) |
718e3744 | 94 | { |
d62a17ae | 95 | size_t len; |
96 | int ip6forwarding = 0; | |
97 | ||
98 | len = sizeof ip6forwarding; | |
01b9e3fd DL |
99 | frr_elevate_privs(&zserv_privs) { |
100 | if (sysctl(mib_ipv6, MIB_SIZ, &ip6forwarding, &len, 0, 0) < 0) { | |
450971aa | 101 | flog_err_sys(EC_LIB_SYSTEM_CALL, |
9df414fe | 102 | "can't get ip6forwarding value"); |
01b9e3fd DL |
103 | return -1; |
104 | } | |
d62a17ae | 105 | } |
d62a17ae | 106 | return ip6forwarding; |
718e3744 | 107 | } |
108 | ||
d62a17ae | 109 | int ipforward_ipv6_on(void) |
718e3744 | 110 | { |
d62a17ae | 111 | size_t len; |
112 | int ip6forwarding = 1; | |
113 | ||
114 | len = sizeof ip6forwarding; | |
01b9e3fd | 115 | frr_elevate_privs(&zserv_privs) { |
633fc9b1 DL |
116 | if (sysctl(mib_ipv6, MIB_SIZ, NULL, NULL, &ip6forwarding, len) |
117 | < 0) { | |
450971aa | 118 | flog_err_sys(EC_LIB_SYSTEM_CALL, |
9df414fe | 119 | "can't get ip6forwarding value"); |
01b9e3fd DL |
120 | return -1; |
121 | } | |
d62a17ae | 122 | } |
d62a17ae | 123 | return ip6forwarding; |
718e3744 | 124 | } |
125 | ||
d62a17ae | 126 | int ipforward_ipv6_off(void) |
718e3744 | 127 | { |
d62a17ae | 128 | size_t len; |
129 | int ip6forwarding = 0; | |
130 | ||
131 | len = sizeof ip6forwarding; | |
01b9e3fd | 132 | frr_elevate_privs(&zserv_privs) { |
633fc9b1 DL |
133 | if (sysctl(mib_ipv6, MIB_SIZ, NULL, NULL, &ip6forwarding, len) |
134 | < 0) { | |
450971aa | 135 | flog_err_sys(EC_LIB_SYSTEM_CALL, |
9df414fe | 136 | "can't get ip6forwarding value"); |
01b9e3fd DL |
137 | return -1; |
138 | } | |
d62a17ae | 139 | } |
d62a17ae | 140 | return ip6forwarding; |
718e3744 | 141 | } |
ddfeb486 DL |
142 | |
143 | #endif /* !defined(GNU_LINUX) && !defined(SUNOS_5) */ |