2 * ipforward value get function for solaris.
3 * Copyright (C) 1997 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
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
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.
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
28 #include "lib_errors.h"
31 #include "zebra/ipforward.h"
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.
38 /* #include <inet/ip.h> */
40 #define IP_DEV_NAME "/dev/ip"
44 extern struct zebra_privs_t zserv_privs
;
46 /* This is a limited ndd style function that operates one integer
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.
53 static int solaris_nd(const int cmd
, const char *parameter
, const int value
)
55 #define ND_BUFFER_SIZE 1024
57 char nd_buf
[ND_BUFFER_SIZE
];
58 struct strioctl strioctl
;
59 const char *device
= IP_DEV_NAME
;
61 memset(nd_buf
, '\0', ND_BUFFER_SIZE
);
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.
68 snprintf(nd_buf
, ND_BUFFER_SIZE
, "%s%c%d%c", parameter
, '\0',
70 else if (cmd
== ND_GET
)
71 snprintf(nd_buf
, ND_BUFFER_SIZE
, "%s", parameter
);
73 flog_err_sys(LIB_ERR_SYSTEM_CALL
,
74 "internal error - inappropriate command given to "
80 strioctl
.ic_cmd
= cmd
;
81 strioctl
.ic_timout
= 0;
82 strioctl
.ic_len
= ND_BUFFER_SIZE
;
83 strioctl
.ic_dp
= nd_buf
;
85 frr_elevate_privs(&zserv_privs
) {
86 if ((fd
= open(device
, O_RDWR
)) < 0) {
87 zlog_warn("failed to open device %s - %s", device
,
88 safe_strerror(errno
));
91 if (ioctl(fd
, I_STR
, &strioctl
) < 0) {
93 zlog_warn("ioctl I_STR failed on device %s - %s",
95 safe_strerror(errno
));
103 retval
= atoi(nd_buf
);
106 "failed to convert returned value to integer - %s",
107 safe_strerror(errno
));
116 static int solaris_nd_set(const char *parameter
, const int value
)
118 return solaris_nd(ND_SET
, parameter
, value
);
120 static int solaris_nd_get(const char *parameter
)
122 return solaris_nd(ND_GET
, parameter
, 0);
126 return solaris_nd_get("ip_forwarding");
129 int ipforward_on(void)
131 (void)solaris_nd_set("ip_forwarding", 1);
135 int ipforward_off(void)
137 (void)solaris_nd_set("ip_forwarding", 0);
140 int ipforward_ipv6(void)
142 return solaris_nd_get("ip6_forwarding");
144 int ipforward_ipv6_on(void)
146 (void)solaris_nd_set("ip6_forwarding", 1);
147 return ipforward_ipv6();
149 int ipforward_ipv6_off(void)
151 (void)solaris_nd_set("ip6_forwarding", 0);
152 return ipforward_ipv6();