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
27 #include "zebra/ipforward.h"
30 ** Solaris should define IP_DEV_NAME in <inet/ip.h>, but we'll save
31 ** configure.in changes for another day. We can use the same device
32 ** for both IPv4 and IPv6.
34 /* #include <inet/ip.h> */
36 #define IP_DEV_NAME "/dev/ip"
40 extern struct zebra_privs_t zserv_privs
;
42 /* This is a limited ndd style function that operates one integer
43 ** value only. Errors return -1. ND_SET commands return 0 on
44 ** success. ND_GET commands return the value on success (which could
45 ** be -1 and be confused for an error). The parameter is the string
46 ** name of the parameter being referenced.
50 solaris_nd(const int cmd
, const char* parameter
, const int value
)
52 #define ND_BUFFER_SIZE 1024
54 char nd_buf
[ND_BUFFER_SIZE
];
55 struct strioctl strioctl
;
56 const char* device
= IP_DEV_NAME
;
58 memset(nd_buf
, '\0', ND_BUFFER_SIZE
);
60 ** ND_SET takes a NULL delimited list of strings further terminated
61 ** buy a NULL. ND_GET returns a list in a similar layout, although
62 ** here we only use the first result.
65 snprintf(nd_buf
, ND_BUFFER_SIZE
, "%s%c%d%c", parameter
, '\0', value
,'\0');
66 else if (cmd
== ND_GET
)
67 snprintf(nd_buf
, ND_BUFFER_SIZE
, "%s", parameter
);
69 zlog_err("internal error - inappropriate command given to "
70 "solaris_nd()%s:%d", __FILE__
, __LINE__
);
74 strioctl
.ic_cmd
= cmd
;
75 strioctl
.ic_timout
= 0;
76 strioctl
.ic_len
= ND_BUFFER_SIZE
;
77 strioctl
.ic_dp
= nd_buf
;
79 if ( zserv_privs
.change (ZPRIVS_RAISE
) )
80 zlog_err ("solaris_nd: Can't raise privileges");
81 if ((fd
= open (device
, O_RDWR
)) < 0)
83 zlog_warn("failed to open device %s - %s", device
, safe_strerror(errno
));
84 if ( zserv_privs
.change (ZPRIVS_LOWER
) )
85 zlog_err ("solaris_nd: Can't lower privileges");
88 if (ioctl (fd
, I_STR
, &strioctl
) < 0)
90 int save_errno
= errno
;
91 if ( zserv_privs
.change (ZPRIVS_LOWER
) )
92 zlog_err ("solaris_nd: Can't lower privileges");
94 zlog_warn("ioctl I_STR failed on device %s - %s",
95 device
, safe_strerror(save_errno
));
99 if ( zserv_privs
.change (ZPRIVS_LOWER
) )
100 zlog_err ("solaris_nd: Can't lower privileges");
105 retval
= atoi(nd_buf
);
108 zlog_warn("failed to convert returned value to integer - %s",
109 safe_strerror(errno
));
121 solaris_nd_set(const char* parameter
, const int value
) {
122 return solaris_nd(ND_SET
, parameter
, value
);
125 solaris_nd_get(const char* parameter
) {
126 return solaris_nd(ND_GET
, parameter
, 0);
131 return solaris_nd_get("ip_forwarding");
137 (void) solaris_nd_set("ip_forwarding", 1);
144 (void) solaris_nd_set("ip_forwarding", 0);
147 int ipforward_ipv6(void)
149 return solaris_nd_get("ip6_forwarding");
152 ipforward_ipv6_on (void)
154 (void) solaris_nd_set("ip6_forwarding", 1);
155 return ipforward_ipv6();
158 ipforward_ipv6_off (void)
160 (void) solaris_nd_set("ip6_forwarding", 0);
161 return ipforward_ipv6();