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