]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* |
2 | * Kernel routing table readup by getmsg(2) | |
3 | * Copyright (C) 1999 Michael Handler | |
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> | |
23 | ||
ddfeb486 DL |
24 | #ifdef SUNOS_5 |
25 | ||
718e3744 | 26 | #include "prefix.h" |
27 | #include "log.h" | |
28 | #include "if.h" | |
78104b9b | 29 | #include "vrf.h" |
82283592 | 30 | #include "vty.h" |
718e3744 | 31 | |
32 | #include "zebra/rib.h" | |
6621ca86 | 33 | #include "zebra/zserv.h" |
718e3744 | 34 | |
a5b38c5b DL |
35 | /* Thank you, Solaris, for polluting application symbol namespace. */ |
36 | #undef hook_register | |
37 | #undef hook_unregister | |
38 | ||
718e3744 | 39 | #include <sys/stream.h> |
40 | #include <sys/tihdr.h> | |
41 | ||
42 | /* Solaris defines these in both <netinet/in.h> and <inet/in.h>, sigh */ | |
43 | #ifdef SUNOS_5 | |
44 | #include <sys/tiuser.h> | |
45 | #ifndef T_CURRENT | |
46 | #define T_CURRENT MI_T_CURRENT | |
47 | #endif /* T_CURRENT */ | |
48 | #ifndef IRE_CACHE | |
49 | #define IRE_CACHE 0x0020 /* Cached Route entry */ | |
50 | #endif /* IRE_CACHE */ | |
51 | #ifndef IRE_HOST_REDIRECT | |
52 | #define IRE_HOST_REDIRECT 0x0200 /* Host route entry from redirects */ | |
53 | #endif /* IRE_HOST_REDIRECT */ | |
54 | #ifndef IRE_CACHETABLE | |
d62a17ae | 55 | #define IRE_CACHETABLE (IRE_CACHE | IRE_BROADCAST | IRE_LOCAL | IRE_LOOPBACK) |
718e3744 | 56 | #endif /* IRE_CACHETABLE */ |
57 | #undef IPOPT_EOL | |
58 | #undef IPOPT_NOP | |
59 | #undef IPOPT_LSRR | |
60 | #undef IPOPT_RR | |
61 | #undef IPOPT_SSRR | |
62 | #endif /* SUNOS_5 */ | |
63 | ||
64 | #include <inet/common.h> | |
65 | #include <inet/ip.h> | |
66 | #include <inet/mib2.h> | |
67 | ||
68 | /* device to read IP routing table from */ | |
69 | #ifndef _PATH_GETMSG_ROUTE | |
70 | #define _PATH_GETMSG_ROUTE "/dev/ip" | |
71 | #endif /* _PATH_GETMSG_ROUTE */ | |
72 | ||
73 | #define RT_BUFSIZ 8192 | |
74 | ||
d62a17ae | 75 | static void handle_route_entry(mib2_ipRouteEntry_t *routeEntry) |
718e3744 | 76 | { |
d62a17ae | 77 | struct prefix prefix; |
78 | struct in_addr tmpaddr, gateway; | |
79 | union g_addr *ggateway; | |
80 | u_char zebra_flags = 0; | |
718e3744 | 81 | |
d62a17ae | 82 | if (routeEntry->ipRouteInfo.re_ire_type & IRE_CACHETABLE) |
83 | return; | |
718e3744 | 84 | |
d62a17ae | 85 | if (routeEntry->ipRouteInfo.re_ire_type & IRE_HOST_REDIRECT) |
86 | zebra_flags |= ZEBRA_FLAG_SELFROUTE; | |
718e3744 | 87 | |
d62a17ae | 88 | prefix.family = AF_INET; |
718e3744 | 89 | |
d62a17ae | 90 | tmpaddr.s_addr = routeEntry->ipRouteDest; |
91 | prefix.u.prefix4 = tmpaddr; | |
718e3744 | 92 | |
d62a17ae | 93 | tmpaddr.s_addr = routeEntry->ipRouteMask; |
94 | prefix.prefixlen = ip_masklen(tmpaddr); | |
718e3744 | 95 | |
d62a17ae | 96 | gateway.s_addr = routeEntry->ipRouteNextHop; |
97 | ggateway = (union g_addr *)&gateway; | |
718e3744 | 98 | |
d62a17ae | 99 | rib_add(AFI_IP, SAFI_UNICAST, VRF_DEFAULT, ZEBRA_ROUTE_KERNEL, 0, |
100 | zebra_flags, &prefix, NULL, ggateway, NULL, 0, 0, 0, 0, 0); | |
718e3744 | 101 | } |
102 | ||
d62a17ae | 103 | void route_read(struct zebra_ns *zns) |
718e3744 | 104 | { |
d62a17ae | 105 | char storage[RT_BUFSIZ]; |
718e3744 | 106 | |
d62a17ae | 107 | struct T_optmgmt_req *TLIreq = (struct T_optmgmt_req *)storage; |
108 | struct T_optmgmt_ack *TLIack = (struct T_optmgmt_ack *)storage; | |
109 | struct T_error_ack *TLIerr = (struct T_error_ack *)storage; | |
718e3744 | 110 | |
d62a17ae | 111 | struct opthdr *MIB2hdr; |
718e3744 | 112 | |
d62a17ae | 113 | mib2_ipRouteEntry_t *routeEntry, *lastRouteEntry; |
718e3744 | 114 | |
d62a17ae | 115 | struct strbuf msgdata; |
116 | int flags, dev, retval, process; | |
718e3744 | 117 | |
d62a17ae | 118 | if ((dev = open(_PATH_GETMSG_ROUTE, O_RDWR)) == -1) { |
119 | zlog_warn("can't open %s: %s", _PATH_GETMSG_ROUTE, | |
120 | safe_strerror(errno)); | |
718e3744 | 121 | return; |
122 | } | |
123 | ||
124 | TLIreq->PRIM_type = T_OPTMGMT_REQ; | |
d62a17ae | 125 | TLIreq->OPT_offset = sizeof(struct T_optmgmt_req); |
126 | TLIreq->OPT_length = sizeof(struct opthdr); | |
718e3744 | 127 | TLIreq->MGMT_flags = T_CURRENT; |
128 | ||
d62a17ae | 129 | MIB2hdr = (struct opthdr *)&TLIreq[1]; |
718e3744 | 130 | |
131 | MIB2hdr->level = MIB2_IP; | |
132 | MIB2hdr->name = 0; | |
133 | MIB2hdr->len = 0; | |
d62a17ae | 134 | |
718e3744 | 135 | msgdata.buf = storage; |
d62a17ae | 136 | msgdata.len = sizeof(struct T_optmgmt_req) + sizeof(struct opthdr); |
718e3744 | 137 | |
138 | flags = 0; | |
139 | ||
d62a17ae | 140 | if (putmsg(dev, &msgdata, NULL, flags) == -1) { |
141 | zlog_warn("putmsg failed: %s", safe_strerror(errno)); | |
718e3744 | 142 | goto exit; |
143 | } | |
144 | ||
d62a17ae | 145 | MIB2hdr = (struct opthdr *)&TLIack[1]; |
146 | msgdata.maxlen = sizeof(storage); | |
718e3744 | 147 | |
148 | while (1) { | |
149 | flags = 0; | |
d62a17ae | 150 | retval = getmsg(dev, &msgdata, NULL, &flags); |
718e3744 | 151 | |
152 | if (retval == -1) { | |
d62a17ae | 153 | zlog_warn("getmsg(ctl) failed: %s", |
154 | safe_strerror(errno)); | |
718e3744 | 155 | goto exit; |
156 | } | |
157 | ||
158 | /* This is normal loop termination */ | |
d62a17ae | 159 | if (retval == 0 |
160 | && (size_t)msgdata.len >= sizeof(struct T_optmgmt_ack) | |
161 | && TLIack->PRIM_type == T_OPTMGMT_ACK | |
162 | && TLIack->MGMT_flags == T_SUCCESS && MIB2hdr->len == 0) | |
718e3744 | 163 | break; |
164 | ||
d62a17ae | 165 | if ((size_t)msgdata.len >= sizeof(struct T_error_ack) |
166 | && TLIerr->PRIM_type == T_ERROR_ACK) { | |
167 | zlog_warn("getmsg(ctl) returned T_ERROR_ACK: %s", | |
168 | safe_strerror((TLIerr->TLI_error == TSYSERR) | |
169 | ? TLIerr->UNIX_error | |
170 | : EPROTO)); | |
718e3744 | 171 | break; |
172 | } | |
173 | ||
174 | /* should dump more debugging info to the log statement, | |
175 | like what GateD does in this instance, but not | |
176 | critical yet. */ | |
d62a17ae | 177 | if (retval != MOREDATA |
178 | || (size_t)msgdata.len < sizeof(struct T_optmgmt_ack) | |
179 | || TLIack->PRIM_type != T_OPTMGMT_ACK | |
180 | || TLIack->MGMT_flags != T_SUCCESS) { | |
718e3744 | 181 | errno = ENOMSG; |
d62a17ae | 182 | zlog_warn("getmsg(ctl) returned bizarreness"); |
718e3744 | 183 | break; |
184 | } | |
185 | ||
186 | /* MIB2_IP_21 is the the pseudo-MIB2 ipRouteTable | |
187 | entry, see <inet/mib2.h>. "This isn't the MIB data | |
188 | you're looking for." */ | |
d62a17ae | 189 | process = (MIB2hdr->level == MIB2_IP |
190 | && MIB2hdr->name == MIB2_IP_21) | |
191 | ? 1 | |
192 | : 0; | |
718e3744 | 193 | |
194 | /* getmsg writes the data buffer out completely, not | |
195 | to the closest smaller multiple. Unless reassembling | |
196 | data structures across buffer boundaries is your idea | |
197 | of a good time, set maxlen to the closest smaller | |
198 | multiple of the size of the datastructure you're | |
199 | retrieving. */ | |
d62a17ae | 200 | msgdata.maxlen = |
201 | sizeof(storage) | |
202 | - (sizeof(storage) % sizeof(mib2_ipRouteEntry_t)); | |
718e3744 | 203 | |
204 | msgdata.len = 0; | |
205 | flags = 0; | |
206 | ||
207 | do { | |
d62a17ae | 208 | retval = getmsg(dev, NULL, &msgdata, &flags); |
718e3744 | 209 | |
210 | if (retval == -1) { | |
d62a17ae | 211 | zlog_warn("getmsg(data) failed: %s", |
212 | safe_strerror(errno)); | |
718e3744 | 213 | goto exit; |
214 | } | |
215 | ||
216 | if (!(retval == 0 || retval == MOREDATA)) { | |
d62a17ae | 217 | zlog_warn("getmsg(data) returned %d", retval); |
718e3744 | 218 | goto exit; |
219 | } | |
220 | ||
221 | if (process) { | |
d62a17ae | 222 | if (msgdata.len % sizeof(mib2_ipRouteEntry_t) |
223 | != 0) { | |
224 | zlog_warn( | |
225 | "getmsg(data) returned " | |
226 | "msgdata.len = %d (%% sizeof (mib2_ipRouteEntry_t) != 0)", | |
227 | msgdata.len); | |
718e3744 | 228 | goto exit; |
229 | } | |
230 | ||
d62a17ae | 231 | routeEntry = (mib2_ipRouteEntry_t *)msgdata.buf; |
232 | lastRouteEntry = | |
233 | (mib2_ipRouteEntry_t *)(msgdata.buf | |
234 | + msgdata.len); | |
718e3744 | 235 | do { |
d62a17ae | 236 | handle_route_entry(routeEntry); |
718e3744 | 237 | } while (++routeEntry < lastRouteEntry); |
238 | } | |
239 | } while (retval == MOREDATA); | |
240 | } | |
241 | ||
242 | exit: | |
d62a17ae | 243 | close(dev); |
718e3744 | 244 | } |
2232a77c | 245 | |
246 | /* Only implemented for netlink method */ | |
d62a17ae | 247 | void macfdb_read(struct zebra_ns *zns) |
2232a77c | 248 | { |
249 | } | |
250 | ||
d62a17ae | 251 | void macfdb_read_for_bridge(struct zebra_ns *zns, struct interface *ifp, |
252 | struct interface *br_if) | |
2232a77c | 253 | { |
254 | } | |
255 | ||
d62a17ae | 256 | void neigh_read(struct zebra_ns *zns) |
2232a77c | 257 | { |
258 | } | |
259 | ||
d62a17ae | 260 | void neigh_read_for_vlan(struct zebra_ns *zns, struct interface *vlan_if) |
2232a77c | 261 | { |
262 | } | |
ddfeb486 DL |
263 | |
264 | #endif /* SUNOS_5 */ |