]> git.proxmox.com Git - mirror_frr.git/blame - zebra/ipforward_solaris.c
2003-06-04 Paul Jakma <paul@dishone.st>
[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 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
21 */
22
23#include <zebra.h>
269c67c5 24#include "log.h"
718e3744 25
269c67c5 26/*
27** Solaris should define IP_DEV_NAME in <inet/ip.h>, but we'll save
28** configure.in changes for another day. We can use the same device
29** for both IPv4 and IPv6.
30*/
31/* #include <inet/ip.h> */
32#ifndef IP_DEV_NAME
33#define IP_DEV_NAME "/dev/ip"
34#endif
35/*
36** This is a limited ndd style function that operates one integer
37** value only. Errors return -1. ND_SET commands return 0 on
38** success. ND_GET commands return the value on success (which could
39** be -1 and be confused for an error). The parameter is the string
40** name of the parameter being referenced.
41*/
718e3744 42
269c67c5 43static int
44solaris_nd(const int cmd, const char* parameter, const int value)
718e3744 45{
269c67c5 46#define ND_BUFFER_SIZE 1024
47 int fd;
48 char nd_buf[ND_BUFFER_SIZE];
49 struct strioctl strioctl;
50 const char* device = IP_DEV_NAME;
51 int retval;
52 memset(nd_buf, '\0', ND_BUFFER_SIZE);
53 /*
54 ** ND_SET takes a NULL delimited list of strings further terminated
55 ** buy a NULL. ND_GET returns a list in a similar layout, although
56 ** here we only use the first result.
57 */
58 if (cmd == ND_SET) {
59 snprintf(nd_buf, ND_BUFFER_SIZE, "%s%c%d%c", parameter, '\0', value,'\0');
60 } else if (cmd == ND_GET) {
61 snprintf(nd_buf, ND_BUFFER_SIZE, "%s", parameter);
62 } else {
63 zlog_err("internal error - inappropriate command given to solaris_nd()%s:%d", __FILE__, __LINE__);
718e3744 64 return -1;
65 }
269c67c5 66 strioctl.ic_cmd = cmd;
67 strioctl.ic_timout = 0;
68 strioctl.ic_len = ND_BUFFER_SIZE;
69 strioctl.ic_dp = nd_buf;
70 if ((fd = open (device, O_RDWR)) < 0) {
71 zlog_warn("failed to open device %s - %s", device, strerror(errno));
72 return -1;
73 }
74 if (ioctl (fd, I_STR, &strioctl) < 0) {
75 close (fd);
76 zlog_warn("ioctl I_STR failed on device %s - %s", device,strerror(errno));
718e3744 77 return -1;
78 }
269c67c5 79 close(fd);
80 if (cmd == ND_GET) {
81 errno = 0;
82 retval = atoi(nd_buf);
83 if (errno) {
84 zlog_warn("failed to convert returned value to integer - %s",strerror(errno));
85 retval = -1;
86 }
87 } else {
88 retval = 0;
89 }
90 return retval;
91}
718e3744 92
269c67c5 93static int
94solaris_nd_set(const char* parameter, const int value) {
95 return solaris_nd(ND_SET, parameter, value);
96}
97static int
98solaris_nd_get(const char* parameter) {
99 return solaris_nd(ND_GET, parameter, 0);
100}
101int
102ipforward()
103{
104 return solaris_nd_get("ip_forwarding");
718e3744 105}
106
107int
108ipforward_on ()
109{
269c67c5 110 (void) solaris_nd_set("ip_forwarding", 1);
111 return ipforward();
718e3744 112}
113
114int
115ipforward_off ()
116{
269c67c5 117 (void) solaris_nd_set("ip_forwarding", 0);
118 return ipforward();
119}
120#ifdef HAVE_IPV6
121int ipforward_ipv6()
122{
123 return solaris_nd_get("ip6_fowarding");
124}
125int
126ipforward_ipv6_on ()
127{
128 (void) solaris_nd_set("ip6_forwarding", 1);
129 return ipforward_ipv6();
130}
131int
132ipforward_ipv6_off ()
133{
134 (void) solaris_nd_set("ip6_forwarding", 0);
135 return ipforward_ipv6();
718e3744 136}
269c67c5 137#endif /* HAVE_IPV6 */