]> git.proxmox.com Git - mirror_frr.git/blame - zebra/ipforward_solaris.c
bgpd: remove duplicate log_ref_add()
[mirror_frr.git] / zebra / ipforward_solaris.c
CommitLineData
718e3744 1/*
2 * ipforward value get function for solaris.
3 * Copyright (C) 1997 Kunihiro Ishiguro
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
896014f4
DL
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
718e3744 20 */
21
22#include <zebra.h>
ddfeb486
DL
23
24#ifdef SUNOS_5
25
269c67c5 26#include "log.h"
edd7c245 27#include "prefix.h"
174482ef 28#include "lib_errors.h"
718e3744 29
9bcdb638 30#include "privs.h"
a1ac18c4 31#include "zebra/ipforward.h"
9bcdb638 32
269c67c5 33/*
34** Solaris should define IP_DEV_NAME in <inet/ip.h>, but we'll save
35** configure.in changes for another day. We can use the same device
36** for both IPv4 and IPv6.
37*/
38/* #include <inet/ip.h> */
39#ifndef IP_DEV_NAME
40#define IP_DEV_NAME "/dev/ip"
41#endif
9bcdb638 42
edd7c245 43
44extern struct zebra_privs_t zserv_privs;
45
9bcdb638 46/* This is a limited ndd style function that operates one integer
269c67c5 47** value only. Errors return -1. ND_SET commands return 0 on
48** success. ND_GET commands return the value on success (which could
49** be -1 and be confused for an error). The parameter is the string
50** name of the parameter being referenced.
51*/
718e3744 52
d62a17ae 53static int solaris_nd(const int cmd, const char *parameter, const int value)
718e3744 54{
269c67c5 55#define ND_BUFFER_SIZE 1024
d62a17ae 56 int fd;
57 char nd_buf[ND_BUFFER_SIZE];
58 struct strioctl strioctl;
59 const char *device = IP_DEV_NAME;
60 int retval;
61 memset(nd_buf, '\0', ND_BUFFER_SIZE);
62 /*
63 ** ND_SET takes a NULL delimited list of strings further terminated
64 ** buy a NULL. ND_GET returns a list in a similar layout, although
65 ** here we only use the first result.
66 */
67 if (cmd == ND_SET)
68 snprintf(nd_buf, ND_BUFFER_SIZE, "%s%c%d%c", parameter, '\0',
69 value, '\0');
70 else if (cmd == ND_GET)
71 snprintf(nd_buf, ND_BUFFER_SIZE, "%s", parameter);
72 else {
09c866e3
QY
73 flog_err_sys(LIB_ERR_SYSTEM_CALL,
74 "internal error - inappropriate command given to "
75 "solaris_nd()%s:%d",
76 __FILE__, __LINE__);
d62a17ae 77 return -1;
78 }
edd7c245 79
d62a17ae 80 strioctl.ic_cmd = cmd;
81 strioctl.ic_timout = 0;
82 strioctl.ic_len = ND_BUFFER_SIZE;
83 strioctl.ic_dp = nd_buf;
84
01b9e3fd
DL
85 frr_elevate_privs(&zserv_privs) {
86 if ((fd = open(device, O_RDWR)) < 0) {
9df414fe
QY
87 flog_err_sys(LIB_ERR_SYSTEM_CALL,
88 "failed to open device %s - %s", device,
89 safe_strerror(errno));
01b9e3fd
DL
90 return -1;
91 }
92 if (ioctl(fd, I_STR, &strioctl) < 0) {
93 close(fd);
9df414fe
QY
94 flog_err_sys(LIB_ERR_SYSTEM_CALL,
95 "ioctl I_STR failed on device %s - %s",
96 device, safe_strerror(errno));
01b9e3fd
DL
97 return -1;
98 }
d62a17ae 99 close(fd);
d62a17ae 100 }
d62a17ae 101
102 if (cmd == ND_GET) {
103 errno = 0;
104 retval = atoi(nd_buf);
105 if (errno) {
9df414fe 106 zlog_debug(
d62a17ae 107 "failed to convert returned value to integer - %s",
108 safe_strerror(errno));
109 retval = -1;
110 }
111 } else {
112 retval = 0;
113 }
114 return retval;
269c67c5 115}
718e3744 116
d62a17ae 117static int solaris_nd_set(const char *parameter, const int value)
118{
119 return solaris_nd(ND_SET, parameter, value);
269c67c5 120}
d62a17ae 121static int solaris_nd_get(const char *parameter)
122{
123 return solaris_nd(ND_GET, parameter, 0);
269c67c5 124}
d62a17ae 125int ipforward(void)
269c67c5 126{
d62a17ae 127 return solaris_nd_get("ip_forwarding");
718e3744 128}
129
d62a17ae 130int ipforward_on(void)
718e3744 131{
d62a17ae 132 (void)solaris_nd_set("ip_forwarding", 1);
133 return ipforward();
718e3744 134}
135
d62a17ae 136int ipforward_off(void)
718e3744 137{
d62a17ae 138 (void)solaris_nd_set("ip_forwarding", 0);
139 return ipforward();
269c67c5 140}
a1ac18c4 141int ipforward_ipv6(void)
269c67c5 142{
d62a17ae 143 return solaris_nd_get("ip6_forwarding");
269c67c5 144}
d62a17ae 145int ipforward_ipv6_on(void)
269c67c5 146{
d62a17ae 147 (void)solaris_nd_set("ip6_forwarding", 1);
148 return ipforward_ipv6();
269c67c5 149}
d62a17ae 150int ipforward_ipv6_off(void)
269c67c5 151{
d62a17ae 152 (void)solaris_nd_set("ip6_forwarding", 0);
153 return ipforward_ipv6();
718e3744 154}
ddfeb486
DL
155
156#endif /* SUNOS_5 */