]> git.proxmox.com Git - mirror_frr.git/blame - zebra/ipforward_solaris.c
isisd: implement the 'lsp-too-large' notification
[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"
364fed6b 32#include "zebra/zebra_errors.h"
9bcdb638 33
269c67c5 34/*
35** Solaris should define IP_DEV_NAME in <inet/ip.h>, but we'll save
36** configure.in changes for another day. We can use the same device
37** for both IPv4 and IPv6.
38*/
39/* #include <inet/ip.h> */
40#ifndef IP_DEV_NAME
41#define IP_DEV_NAME "/dev/ip"
42#endif
9bcdb638 43
edd7c245 44
45extern struct zebra_privs_t zserv_privs;
46
9bcdb638 47/* This is a limited ndd style function that operates one integer
269c67c5 48** value only. Errors return -1. ND_SET commands return 0 on
49** success. ND_GET commands return the value on success (which could
50** be -1 and be confused for an error). The parameter is the string
51** name of the parameter being referenced.
52*/
718e3744 53
d62a17ae 54static int solaris_nd(const int cmd, const char *parameter, const int value)
718e3744 55{
269c67c5 56#define ND_BUFFER_SIZE 1024
d62a17ae 57 int fd;
58 char nd_buf[ND_BUFFER_SIZE];
59 struct strioctl strioctl;
60 const char *device = IP_DEV_NAME;
61 int retval;
62 memset(nd_buf, '\0', ND_BUFFER_SIZE);
63 /*
64 ** ND_SET takes a NULL delimited list of strings further terminated
65 ** buy a NULL. ND_GET returns a list in a similar layout, although
66 ** here we only use the first result.
67 */
68 if (cmd == ND_SET)
69 snprintf(nd_buf, ND_BUFFER_SIZE, "%s%c%d%c", parameter, '\0',
70 value, '\0');
71 else if (cmd == ND_GET)
72 snprintf(nd_buf, ND_BUFFER_SIZE, "%s", parameter);
73 else {
450971aa 74 flog_err_sys(EC_LIB_SYSTEM_CALL,
09c866e3
QY
75 "internal error - inappropriate command given to "
76 "solaris_nd()%s:%d",
77 __FILE__, __LINE__);
d62a17ae 78 return -1;
79 }
edd7c245 80
d62a17ae 81 strioctl.ic_cmd = cmd;
82 strioctl.ic_timout = 0;
83 strioctl.ic_len = ND_BUFFER_SIZE;
84 strioctl.ic_dp = nd_buf;
85
01b9e3fd
DL
86 frr_elevate_privs(&zserv_privs) {
87 if ((fd = open(device, O_RDWR)) < 0) {
450971aa 88 flog_err_sys(EC_LIB_SYSTEM_CALL,
9df414fe
QY
89 "failed to open device %s - %s", device,
90 safe_strerror(errno));
01b9e3fd
DL
91 return -1;
92 }
93 if (ioctl(fd, I_STR, &strioctl) < 0) {
94 close(fd);
450971aa 95 flog_err_sys(EC_LIB_SYSTEM_CALL,
9df414fe
QY
96 "ioctl I_STR failed on device %s - %s",
97 device, safe_strerror(errno));
01b9e3fd
DL
98 return -1;
99 }
d62a17ae 100 close(fd);
d62a17ae 101 }
d62a17ae 102
103 if (cmd == ND_GET) {
104 errno = 0;
105 retval = atoi(nd_buf);
106 if (errno) {
9df414fe 107 zlog_debug(
d62a17ae 108 "failed to convert returned value to integer - %s",
109 safe_strerror(errno));
110 retval = -1;
111 }
112 } else {
113 retval = 0;
114 }
115 return retval;
269c67c5 116}
718e3744 117
d62a17ae 118static int solaris_nd_set(const char *parameter, const int value)
119{
120 return solaris_nd(ND_SET, parameter, value);
269c67c5 121}
d62a17ae 122static int solaris_nd_get(const char *parameter)
123{
124 return solaris_nd(ND_GET, parameter, 0);
269c67c5 125}
d62a17ae 126int ipforward(void)
269c67c5 127{
d62a17ae 128 return solaris_nd_get("ip_forwarding");
718e3744 129}
130
d62a17ae 131int ipforward_on(void)
718e3744 132{
d62a17ae 133 (void)solaris_nd_set("ip_forwarding", 1);
134 return ipforward();
718e3744 135}
136
d62a17ae 137int ipforward_off(void)
718e3744 138{
d62a17ae 139 (void)solaris_nd_set("ip_forwarding", 0);
140 return ipforward();
269c67c5 141}
a1ac18c4 142int ipforward_ipv6(void)
269c67c5 143{
d62a17ae 144 return solaris_nd_get("ip6_forwarding");
269c67c5 145}
d62a17ae 146int ipforward_ipv6_on(void)
269c67c5 147{
d62a17ae 148 (void)solaris_nd_set("ip6_forwarding", 1);
149 return ipforward_ipv6();
269c67c5 150}
d62a17ae 151int ipforward_ipv6_off(void)
269c67c5 152{
d62a17ae 153 (void)solaris_nd_set("ip6_forwarding", 0);
154 return ipforward_ipv6();
718e3744 155}
ddfeb486
DL
156
157#endif /* SUNOS_5 */