]> git.proxmox.com Git - mirror_frr.git/blame - zebra/ipforward_solaris.c
*: make consistent & update GPLv2 file headers
[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>
269c67c5 23#include "log.h"
edd7c245 24#include "prefix.h"
718e3744 25
9bcdb638 26#include "privs.h"
a1ac18c4 27#include "zebra/ipforward.h"
9bcdb638 28
269c67c5 29/*
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.
33*/
34/* #include <inet/ip.h> */
35#ifndef IP_DEV_NAME
36#define IP_DEV_NAME "/dev/ip"
37#endif
9bcdb638 38
edd7c245 39
40extern struct zebra_privs_t zserv_privs;
41
9bcdb638 42/* This is a limited ndd style function that operates one integer
269c67c5 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.
47*/
718e3744 48
269c67c5 49static int
50solaris_nd(const int cmd, const char* parameter, const int value)
718e3744 51{
269c67c5 52#define ND_BUFFER_SIZE 1024
53 int fd;
54 char nd_buf[ND_BUFFER_SIZE];
55 struct strioctl strioctl;
56 const char* device = IP_DEV_NAME;
57 int retval;
58 memset(nd_buf, '\0', ND_BUFFER_SIZE);
59 /*
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.
63 */
66e9488c 64 if (cmd == ND_SET)
269c67c5 65 snprintf(nd_buf, ND_BUFFER_SIZE, "%s%c%d%c", parameter, '\0', value,'\0');
66e9488c 66 else if (cmd == ND_GET)
269c67c5 67 snprintf(nd_buf, ND_BUFFER_SIZE, "%s", parameter);
66e9488c 68 else {
69 zlog_err("internal error - inappropriate command given to "
70 "solaris_nd()%s:%d", __FILE__, __LINE__);
718e3744 71 return -1;
72 }
edd7c245 73
269c67c5 74 strioctl.ic_cmd = cmd;
75 strioctl.ic_timout = 0;
76 strioctl.ic_len = ND_BUFFER_SIZE;
77 strioctl.ic_dp = nd_buf;
edd7c245 78
79 if ( zserv_privs.change (ZPRIVS_RAISE) )
80 zlog_err ("solaris_nd: Can't raise privileges");
81 if ((fd = open (device, O_RDWR)) < 0)
82 {
6099b3b5 83 zlog_warn("failed to open device %s - %s", device, safe_strerror(errno));
edd7c245 84 if ( zserv_privs.change (ZPRIVS_LOWER) )
85 zlog_err ("solaris_nd: Can't lower privileges");
86 return -1;
87 }
88 if (ioctl (fd, I_STR, &strioctl) < 0)
89 {
4460e7a4 90 int save_errno = errno;
edd7c245 91 if ( zserv_privs.change (ZPRIVS_LOWER) )
92 zlog_err ("solaris_nd: Can't lower privileges");
93 close (fd);
4460e7a4 94 zlog_warn("ioctl I_STR failed on device %s - %s",
95 device, safe_strerror(save_errno));
edd7c245 96 return -1;
97 }
269c67c5 98 close(fd);
edd7c245 99 if ( zserv_privs.change (ZPRIVS_LOWER) )
100 zlog_err ("solaris_nd: Can't lower privileges");
101
102 if (cmd == ND_GET)
103 {
104 errno = 0;
105 retval = atoi(nd_buf);
106 if (errno)
107 {
108 zlog_warn("failed to convert returned value to integer - %s",
6099b3b5 109 safe_strerror(errno));
edd7c245 110 retval = -1;
111 }
112 }
113 else
114 {
115 retval = 0;
269c67c5 116 }
269c67c5 117 return retval;
118}
718e3744 119
269c67c5 120static int
121solaris_nd_set(const char* parameter, const int value) {
122 return solaris_nd(ND_SET, parameter, value);
123}
124static int
125solaris_nd_get(const char* parameter) {
126 return solaris_nd(ND_GET, parameter, 0);
127}
128int
a1ac18c4 129ipforward(void)
269c67c5 130{
131 return solaris_nd_get("ip_forwarding");
718e3744 132}
133
134int
a1ac18c4 135ipforward_on (void)
718e3744 136{
269c67c5 137 (void) solaris_nd_set("ip_forwarding", 1);
138 return ipforward();
718e3744 139}
140
141int
a1ac18c4 142ipforward_off (void)
718e3744 143{
269c67c5 144 (void) solaris_nd_set("ip_forwarding", 0);
145 return ipforward();
146}
a1ac18c4 147int ipforward_ipv6(void)
269c67c5 148{
66e9488c 149 return solaris_nd_get("ip6_forwarding");
269c67c5 150}
151int
a1ac18c4 152ipforward_ipv6_on (void)
269c67c5 153{
154 (void) solaris_nd_set("ip6_forwarding", 1);
155 return ipforward_ipv6();
156}
157int
a1ac18c4 158ipforward_ipv6_off (void)
269c67c5 159{
160 (void) solaris_nd_set("ip6_forwarding", 0);
161 return ipforward_ipv6();
718e3744 162}