Print this page
Restore SVP_R_ROUTE_REQ, and all that goes with it.
Interpret sl3a_uport == 0 in SVP_R_VL3_ACK to indicate the VL3 IP is a next-hop router.
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/lib/varpd/svp/common/libvarpd_svp.c
+++ new/usr/src/lib/varpd/svp/common/libvarpd_svp.c
1 1 /*
2 2 * This file and its contents are supplied under the terms of the
3 3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 4 * You may only use this file in accordance with the terms of version
5 5 * 1.0 of the CDDL.
6 6 *
7 7 * A full copy of the text of the CDDL should have accompanied this
8 8 * source. A copy of the CDDL is also available via the Internet at
9 9 * http://www.illumos.org/license/CDDL.
10 10 */
11 11
12 12 /*
13 13 * Copyright 2018, Joyent, Inc.
14 14 */
15 15
16 16 /*
17 17 * This plugin implements the SDC VXLAN Protocol (SVP).
18 18 *
19 19 * This plugin is designed to work with a broader distributed system that
20 20 * mainains a database of mappings and provides a means of looking up data and
21 21 * provides a stream of updates. While it is named after VXLAN, there isn't
22 22 * anything specific to VXLAN baked into the protocol at this time, other than
23 23 * that it requires both an IP address and a port; however, if there's a good
24 24 * reason to support others here, we can modify that.
25 25 *
26 26 * -----------
27 27 * Terminology
28 28 * -----------
29 29 *
30 30 * Throughout this module we refer to a few different kinds of addresses:
31 31 *
32 32 * VL3
33 33 *
34 34 * A VL3 address, or virtual layer 3, refers to the layer three addreses
35 35 * that are used by entities on an overlay network. As far as we're
36 36 * concerned that means that this is the IP address of an interface on an
37 37 * overlay network.
38 38 *
39 39 * VL2
40 40 *
41 41 * A VL2 address, or a virtual layer 2, referes to the link-layer addresses
42 42 * that are used by entities on an overlay network. As far as we're
43 43 * concerned that means that this is the MAC addresses of an interface on
44 44 * an overlay network.
45 45 *
46 46 * UL3
47 47 *
48 48 * A UL3, or underlay layer 3, refers to the layer three (IP) address on
49 49 * the underlay network.
50 50 *
51 51 * The svp plugin provides lookups from VL3->VL2, eg. the equivalent of an ARP
52 52 * or NDP query, and then also provides VL2->UL3 lookups.
53 53 *
54 54 * -------------------
55 55 * Protocol Operations
56 56 * -------------------
57 57 *
58 58 * The svp protocol is defined in lib/varpd/svp/common/libvarpd_svp_prot.h. It
59 59 * defines the basic TCP protocol that we use to communicate to hosts. At this
60 60 * time, it is not quite 100% implemented in both this plug-in and our primary
61 61 * server, sdc-portolan (see https://github.com/joyent/sdc-portolan).
62 62 *
63 63 * At this time, we don't quite support everything that we need to. Including
64 64 * the SVP_R_BULK_REQ and SVP_R_SHOOTDOWN.
65 65 *
66 66 * ---------------------------------
67 67 * General Design and Considerations
68 68 * ---------------------------------
69 69 *
70 70 * Every instance of the svp plugin requires the hostname and port of a server
71 71 * to contact. Though, we have co-opted the port 1296 (the year of the oldest
72 72 * extant portolan) as our default port.
73 73 *
74 74 * Each of the different instance of the plugins has a corresponding remote
75 75 * backend. The remote backend represents the tuple of the [ host, port ].
76 76 * Different instances that share the same host and port tuple will use the same
77 77 * backend.
78 78 *
79 79 * The backend is actually in charge of performing lookups, resolving and
80 80 * updating the set of remote hosts based on the DNS resolution we've been
81 81 * provided, and taking care of things like shootdowns.
82 82 *
83 83 * The whole plugin itself maintains an event loop and a number of threads to
84 84 * service that event loop. On top of that event loop, we have a simple timer
85 85 * backend that ticks at one second intervals and performs various callbacks,
86 86 * such as idle query timers, DNS resolution, connection backoff, etc. Each of
87 87 * the remote hosts that we obtain is wrapped up in an svp_conn_t, which manages
88 88 * the connection state, reconnecting, etc.
89 89 *
90 90 * All in all, the general way that this all looks like is:
91 91 *
92 92 * +----------------------------+
93 93 * | Plugin Instance |
94 94 * | svp_t |
95 95 * | |
96 96 * | varpd_provider_handle_t * -+-> varpd handle
97 97 * | uint64_t ----+-> varpd ID
98 98 * | char * ----+-> remote host
99 99 * | uint16_t ----+-> remote port
100 100 * | svp_remote_t * ---+------+-> remote backend
101 101 * +---------------------+------+
102 102 * |
103 103 * v
104 104 * +----------------------+ +----------------+
105 105 * | Remote backend |------------------>| Remove Backend |---> ...
106 106 * | svp_remote_t | | svp_remote_t |
107 107 * | | +----------------+
108 108 * | svp_remote_state_t --+-> state flags
109 109 * | svp_degrade_state_t -+-> degraded reason
110 110 * | struct addrinfo * --+-> resolved hosts
111 111 * | uint_t ---+-> active hosts
112 112 * | uint_t ---+-> DNS generation
113 113 * | uint_t ---+-> Reference count
114 114 * | uint_t ---+-> active conns
115 115 * | uint_t ---+-> degraded conns
116 116 * | list_t ---+---+-> connection list
117 117 * +------------------+---+
118 118 * |
119 119 * +------------------------------+-----------------+
120 120 * | | |
121 121 * v v v
122 122 * +-------------------+ +----------------
123 123 * | SVP Connection | | SVP connection | ...
124 124 * | svp_conn_t | | svp_conn_t |
125 125 * | | +----------------+
126 126 * | svp_event_t ----+-> event loop handle
127 127 * | svp_timer_t ----+-> backoff timer
128 128 * | svp_timer_t ----+-> query timer
129 129 * | int ----+-> socket fd
130 130 * | uint_t ----+-> generation
131 131 * | uint_t ----+-> current backoff
132 132 * | svp_conn_flags_t -+-> connection flags
133 133 * | svp_conn_state_t -+-> connection state
134 134 * | svp_conn_error_t -+-> connection error
135 135 * | int ---+-> last errrno
136 136 * | hrtime_t ---+-> activity timestamp
137 137 * | svp_conn_out_t ---+-> outgoing data state
138 138 * | svp_conn_in_t ---+-> incoming data state
139 139 * | list_t ---+--+-> active queries
140 140 * +----------------+--+
141 141 * |
142 142 * +----------------------------------+-----------------+
143 143 * | | |
144 144 * v v v
145 145 * +--------------------+ +-------------+
146 146 * | SVP Query | | SVP Query | ...
147 147 * | svp_query_t | | svp_query_t |
148 148 * | | +-------------+
149 149 * | svp_query_f ---+-> callback function
150 150 * | void * ---+-> callback arg
151 151 * | svp_query_state_t -+-> state flags
152 152 * | svp_req_t ---+-> svp prot. header
153 153 * | svp_query_data_t --+-> read data
154 154 * | svp_query_data_t --+-> write data
155 155 * | svp_status_t ---+-> request status
156 156 * +--------------------+
157 157 *
158 158 * The svp_t is the instance that we assoicate with varpd. The instance itself
159 159 * maintains properties and then when it's started associates with an
160 160 * svp_remote_t, which is the remote backend. The remote backend itself,
161 161 * maintains the DNS state and spins up and downs connections based on the
162 162 * results from DNS. By default, we query DNS every 30 seconds. For more on the
163 163 * connection life cycle, see the next section.
164 164 *
165 165 * By default, each connection maintains its own back off timer and list of
166 166 * queries it's servicing. Only one request is generally outstanding at a time
167 167 * and requests are round robined across the various connections.
168 168 *
169 169 * The query itself represents the svp request that's going on and keep track of
170 170 * its state and is a place for data that's read and written to as part of the
171 171 * request.
172 172 *
173 173 * Connections maintain a query timer such that if we have not received data on
174 174 * a socket for a certain amount of time, we kill that socket and begin a
175 175 * reconnection cycle with backoff.
176 176 *
177 177 * ------------------------
178 178 * Connection State Machine
179 179 * ------------------------
180 180 *
181 181 * We have a connection pool that's built upon DNS records. DNS describes the
182 182 * membership of the set of remote peers that make up our pool and we maintain
183 183 * one connection to each of them. In addition, we maintain an exponential
184 184 * backoff for each peer and will attempt to reconect immediately before backing
185 185 * off. The following are the valid states that a connection can be in:
186 186 *
187 187 * SVP_CS_ERROR An OS error has occurred on this connection,
188 188 * such as failure to create a socket or associate
189 189 * the socket with an event port. We also
190 190 * transition all connections to this state before
191 191 * we destroy them.
192 192 *
193 193 * SVP_CS_INITIAL This is the initial state of a connection, all
194 194 * that should exist is an unbound socket.
195 195 *
196 196 * SVP_CS_CONNECTING A call to connect has been made and we are
197 197 * polling for it to complete.
198 198 *
199 199 * SVP_CS_BACKOFF A connect attempt has failed and we are
200 200 * currently backing off, waiting to try again.
201 201 *
202 202 * SVP_CS_ACTIVE We have successfully connected to the remote
203 203 * system.
204 204 *
205 205 * SVP_CS_WINDDOWN This connection is going to valhalla. In other
206 206 * words, a previously active connection is no
207 207 * longer valid in DNS, so we should curb our use
208 208 * of it, and reap it as soon as we have other
209 209 * active connections.
210 210 *
211 211 * The following diagram attempts to describe our state transition scheme, and
212 212 * when we transition from one state to the next.
213 213 *
214 214 * |
215 215 * * New remote IP from DNS resolution,
216 216 * | not currently active in the system.
217 217 * |
218 218 * v Socket Error,
219 219 * +----------------+ still in DNS
220 220 * +----------------<---| SVP_CS_INITIAL |<----------------------*-----+
221 221 * | +----------------+ |
222 222 * | System | |
223 223 * | Connection . . . . . success * Successful |
224 224 * | failed . | connect() |
225 225 * | +----*---------+ | +-----------*--+ |
226 226 * | | | | | | |
227 227 * | V ^ v ^ V ^
228 228 * | +----------------+ +-------------------+ +---------------+
229 229 * +<-| SVP_CS_BACKOFF | | SVP_CS_CONNECTING | | SVP_CS_ACTIVE |
230 230 * | +----------------+ +-------------------+ +---------------+
231 231 * | V ^ V V V
232 232 * | Backoff wait * | | | * Removed
233 233 * v interval +--------------+ +-----------------<-----+ | from DNS
234 234 * | finished | |
235 235 * | V |
236 236 * | | V
237 237 * | | +-----------------+
238 238 * +----------------+----------<-----+-------<----| SVP_CS_WINDDOWN |
239 239 * | +-----------------+
240 240 * * . . . Fatal system, not
241 241 * | socket error or
242 242 * V quiesced after
243 243 * +--------------+ removal from DNS
244 244 * | SVP_CS_ERROR |
245 245 * +--------------+
246 246 * |
247 247 * * . . . Removed from DNS
248 248 * v
249 249 * +------------+
250 250 * | Connection |
251 251 * | Destroyed |
252 252 * +------------+
253 253 *
254 254 * --------------------------
255 255 * Connection Event Injection
256 256 * --------------------------
257 257 *
258 258 * For each connection that exists in the system, we have a timer in place that
259 259 * is in charge of performing timeout activity. It fires once every thirty
260 260 * seconds or so for a given connection and checks to ensure that we have had
261 261 * activity for the most recent query on the connection. If not, it terminates
262 262 * the connection. This is important as if we have sent all our data and are
263 263 * waiting for the remote end to reply, without enabling something like TCP
264 264 * keep-alive, we will not be notified that anything that has happened to the
265 265 * remote connection, for example a panic. In addition, this also protects
266 266 * against a server that is up, but a portolan that is not making forward
267 267 * progress.
268 268 *
269 269 * When a timeout occurs, we first try to disassociate any active events, which
270 270 * by definition must exist. Once that's done, we inject a port source user
271 271 * event. Now, there is a small gotcha. Let's assume for a moment that we have a
272 272 * pathological portolan. That means that it knows to inject activity right at
273 273 * the time out window. That means, that the event may be disassociated before
274 274 * we could get to it. If that's the case, we must _not_ inject the user event
275 275 * and instead, we'll let the pending event take care of it. We know that the
276 276 * pending event hasn't hit the main part of the loop yet, otherwise, it would
277 277 * have released the lock protecting our state and associated the event.
278 278 *
279 279 * ------------
280 280 * Notes on DNS
281 281 * ------------
282 282 *
283 283 * Unfortunately, doing host name resolution in a way that allows us to leverage
284 284 * the system's resolvers and the system's caching, require us to make blocking
285 285 * calls in libc via getaddrinfo(3SOCKET). If we can't reach a given server,
286 286 * that will tie up a thread for quite some time. To work around that fact,
287 287 * we're going to create a fixed number of threads and we'll use them to service
288 288 * our DNS requests. While this isn't ideal, until we have a sane means of
289 289 * integrating a DNS resolution into an event loop with say portfs, it's not
290 290 * going to be a fun day no matter what we do.
291 291 *
292 292 * ------
293 293 * Timers
294 294 * ------
295 295 *
296 296 * We maintain a single timer based on CLOCK_REALTIME. It's designed to fire
297 297 * every second. While we'd rather use CLOCK_HIGHRES just to alleviate ourselves
298 298 * from timer drift; however, as zones may not actually have CLOCK_HIGHRES
299 299 * access, we don't want them to end up in there. The timer itself is just a
300 300 * simple avl tree sorted by expiration time, which is stored as a tick in the
301 301 * future, a tick is just one second.
302 302 *
303 303 * ----------
304 304 * Shootdowns
305 305 * ----------
306 306 *
307 307 * As part of the protocol, we need to be able to handle shootdowns that inform
308 308 * us some of the information in the system is out of date. This information
309 309 * needs to be processed promptly; however, the information is hopefully going
310 310 * to be relatively infrequent relative to the normal flow of information.
311 311 *
312 312 * The shoot down information needs to be done on a per-backend basis. The
313 313 * general design is that we'll have a single query for this which can fire on a
314 314 * 5-10s period, we randmoize the latter part to give us a bit more load
315 315 * spreading. If we complete because there's no work to do, then we wait the
316 316 * normal period. If we complete, but there's still work to do, we'll go again
317 317 * after a second.
318 318 *
319 319 * A shootdown has a few different parts. We first receive a list of items to
320 320 * shootdown. After performing all of those, we need to acknowledge them. When
321 321 * that's been done successfully, we can move onto the next part. From a
322 322 * protocol perspective, we make a SVP_R_LOG_REQ, we get a reply, and then after
323 323 * processing them, send an SVP_R_LOG_RM. Only once that's been acked do we
324 324 * continue.
325 325 *
326 326 * However, one of the challenges that we have is that these invalidations are
327 327 * just that, an invalidation. For a virtual layer two request, that's fine,
328 328 * because the kernel supports that. However, for virtual layer three
329 329 * invalidations, we have a bit more work to do. These protocols, ARP and NDP,
330 330 * don't really support a notion of just an invalidation, instead you have to
331 331 * inject the new data in a gratuitous fashion.
332 332 *
333 333 * To that end, what we instead do is when we receive a VL3 invalidation, we
334 334 * turn that info a VL3 request. We hold the general request as outstanding
335 335 * until we receive all of the callbacks for the VL3 invalidations, at which
336 336 * point we go through and do the log removal request.
337 337 */
338 338
339 339 #include <umem.h>
340 340 #include <errno.h>
341 341 #include <stdlib.h>
342 342 #include <sys/types.h>
343 343 #include <sys/socket.h>
344 344 #include <netinet/in.h>
345 345 #include <arpa/inet.h>
346 346 #include <libnvpair.h>
347 347 #include <strings.h>
348 348 #include <string.h>
349 349 #include <assert.h>
350 350 #include <unistd.h>
351 351
352 352 #include <libvarpd_provider.h>
353 353 #include "libvarpd_svp.h"
|
↓ open down ↓ |
353 lines elided |
↑ open up ↑ |
354 354
355 355 bunyan_logger_t *svp_bunyan;
356 356 static int svp_defport = 1296;
357 357 static int svp_defuport = 1339;
358 358 static umem_cache_t *svp_lookup_cache;
359 359
360 360 typedef enum svp_lookup_type {
361 361 SVP_L_UNKNOWN = 0x0,
362 362 SVP_L_VL2 = 0x1,
363 363 SVP_L_VL3 = 0x2,
364 - SVP_L_RVL3 = 0x3
364 + SVP_L_ROUTE = 0x3
365 365 } svp_lookup_type_t;
366 366
367 367 typedef struct svp_lookup {
368 368 int svl_type;
369 369 union {
370 370 struct svl_lookup_vl2 {
371 371 varpd_query_handle_t *svl_handle;
372 372 overlay_target_point_t *svl_point;
373 373 } svl_vl2;
374 374 struct svl_lookup_vl3 {
375 375 varpd_arp_handle_t *svl_vah;
376 376 uint8_t *svl_out;
377 377 } svl_vl3;
378 - struct svl_lookup_rvl3 {
378 + struct svl_lookup_route {
379 379 varpd_query_handle_t *svl_handle;
380 380 overlay_target_point_t *svl_point;
381 381 overlay_target_route_t *svl_route;
382 - } svl_rvl3;
382 + } svl_route;
383 383 } svl_u;
384 384 svp_query_t svl_query;
385 385 } svp_lookup_t;
386 386
387 387 static const char *varpd_svp_props[] = {
388 388 "svp/host",
389 389 "svp/port",
390 390 "svp/underlay_ip",
391 391 "svp/underlay_port",
392 392 "svp/dcid",
393 - "svp/router_mac"
393 + "svp/router_oui"
394 394 };
395 395
396 396 static const uint8_t svp_bcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
397 397
398 398 int
399 399 svp_comparator(const void *l, const void *r)
400 400 {
401 401 const svp_t *ls = l;
402 402 const svp_t *rs = r;
403 403
404 404 if (ls->svp_vid > rs->svp_vid)
405 405 return (1);
406 406 if (ls->svp_vid < rs->svp_vid)
407 407 return (-1);
408 408 return (0);
409 409 }
410 410
411 411 static void
412 412 svp_vl2_lookup_cb(svp_t *svp, svp_status_t status, const struct in6_addr *uip,
413 413 const uint16_t uport, void *arg)
414 414 {
415 415 svp_lookup_t *svl = arg;
416 416 overlay_target_point_t *otp;
417 417
418 418 assert(svp != NULL);
419 419 assert(arg != NULL);
420 420
421 421 if (status != SVP_S_OK) {
422 422 libvarpd_plugin_query_reply(svl->svl_u.svl_vl2.svl_handle,
423 423 VARPD_LOOKUP_DROP);
424 424 umem_cache_free(svp_lookup_cache, svl);
425 425 return;
426 426 }
427 427
428 428 otp = svl->svl_u.svl_vl2.svl_point;
429 429 bcopy(uip, &otp->otp_ip, sizeof (struct in6_addr));
|
↓ open down ↓ |
26 lines elided |
↑ open up ↑ |
430 430 otp->otp_port = uport;
431 431 libvarpd_plugin_query_reply(svl->svl_u.svl_vl2.svl_handle,
432 432 VARPD_LOOKUP_OK);
433 433 umem_cache_free(svp_lookup_cache, svl);
434 434 }
435 435
436 436 static void
437 437 svp_vl3_lookup_cb(svp_t *svp, svp_status_t status, const uint8_t *vl2mac,
438 438 const struct in6_addr *uip, const uint16_t uport, void *arg)
439 439 {
440 - overlay_target_point_t point;
440 + /* Initialize address-holders to 0 for comparisons-to-zeroes later. */
441 + overlay_target_point_t point = { 0 };
441 442 svp_lookup_t *svl = arg;
443 + uint8_t nexthop_mac[6] = { 0, 0, 0, 0, 0, 0 };
442 444
443 445 assert(svp != NULL);
444 446 assert(svl != NULL);
445 447
446 448 if (status != SVP_S_OK) {
447 449 libvarpd_plugin_arp_reply(svl->svl_u.svl_vl3.svl_vah,
448 450 VARPD_LOOKUP_DROP);
449 451 umem_cache_free(svp_lookup_cache, svl);
450 452 return;
451 453 }
452 454
453 455 /* Inject the L2 mapping before the L3 */
454 - bcopy(uip, &point.otp_ip, sizeof (struct in6_addr));
455 - point.otp_port = uport;
456 - libvarpd_inject_varp(svp->svp_hdl, vl2mac, &point);
456 + if (uport != 0 &&
457 + bcmp(uip, &point.otp_ip, sizeof (struct in6_addr)) != 0) {
458 + /* Normal L3 lookup result... */
459 + bcopy(uip, &point.otp_ip, sizeof (struct in6_addr));
460 + point.otp_port = uport;
461 + libvarpd_inject_varp(svp->svp_hdl, vl2mac, &point);
462 + } else {
463 + /*
464 + * Oh my, we have a next-hop router IP.
465 + * Set the MAC to the ouid+vid concatenated
466 + * special-router-MAC. Overlay down below will know
467 + * that uport == 0 means the MAC is a special one.
468 + */
469 + if (bcmp(svp->svp_router_oui, nexthop_mac, ETHERADDRL) == 0) {
470 + /*
471 + * We don't have a router_oui, so we can't support
472 + * special-router-MAC. Drop it.
473 + */
474 + libvarpd_plugin_arp_reply(svl->svl_u.svl_vl3.svl_vah,
475 + VARPD_LOOKUP_DROP);
476 + umem_cache_free(svp_lookup_cache, svl);
477 + return;
478 + }
479 + bcopy(svp->svp_router_oui, nexthop_mac, 3);
480 + nexthop_mac[3] = (svp->svp_vid >> 16) & 0xff;
481 + nexthop_mac[4] = (svp->svp_vid >> 8) & 0xff;
482 + nexthop_mac[5] = svp->svp_vid & 0xff;
483 + vl2mac = nexthop_mac;
484 + }
457 485
458 486 bcopy(vl2mac, svl->svl_u.svl_vl3.svl_out, ETHERADDRL);
459 487 libvarpd_plugin_arp_reply(svl->svl_u.svl_vl3.svl_vah,
460 488 VARPD_LOOKUP_OK);
461 489 umem_cache_free(svp_lookup_cache, svl);
462 490 }
463 491
464 492 static void
465 493 svp_vl2_invalidate_cb(svp_t *svp, const uint8_t *vl2mac)
466 494 {
467 495 libvarpd_inject_varp(svp->svp_hdl, vl2mac, NULL);
468 496 }
469 497
470 498 static void
471 499 svp_vl3_inject_cb(svp_t *svp, const uint16_t vlan, const struct in6_addr *vl3ip,
472 500 const uint8_t *vl2mac, const uint8_t *targmac)
473 501 {
474 502 struct in_addr v4;
475 503
476 504 /*
477 505 * At the moment we don't support any IPv6 related log entries, this
478 506 * will change soon as we develop a bit more of the IPv6 related
479 507 * infrastructure so we can properly test the injection.
480 508 */
481 509 if (IN6_IS_ADDR_V4MAPPED(vl3ip) == 0) {
482 510 return;
483 511 } else {
484 512 IN6_V4MAPPED_TO_INADDR(vl3ip, &v4);
485 513 if (targmac == NULL)
486 514 targmac = svp_bcast;
|
↓ open down ↓ |
20 lines elided |
↑ open up ↑ |
487 515 libvarpd_inject_arp(svp->svp_hdl, vlan, vl2mac, &v4, targmac);
488 516 }
489 517 }
490 518
491 519 /* ARGSUSED */
492 520 static void
493 521 svp_shootdown_cb(svp_t *svp, const uint8_t *vl2mac, const struct in6_addr *uip,
494 522 const uint16_t uport)
495 523 {
496 524 /*
497 - * We should probably do a conditional invlaidation here.
525 + * We should probably do a conditional invalidation here.
498 526 */
499 527 libvarpd_inject_varp(svp->svp_hdl, vl2mac, NULL);
500 528 }
501 529
502 530 static void
503 -svp_rvl3_lookup_cb(svp_t *svp, svp_status_t status, /* XXX KEBE SAYS MORE */
531 +svp_route_lookup_cb(svp_t *svp, svp_status_t status, uint32_t dcid,
532 + uint32_t vnetid, uint16_t vlan, uint8_t *srcmac, uint8_t *dstmac,
533 + uint16_t ul3_port, uint8_t *ul3_addr, uint8_t srcpfx, uint8_t dstpfx,
504 534 void *arg)
505 535 {
506 536 svp_lookup_t *svl = arg;
507 537 overlay_target_point_t *otp;
508 538 overlay_target_route_t *otr;
509 539
510 540 if (status != SVP_S_OK) {
511 - libvarpd_plugin_query_reply(svl->svl_u.svl_rvl3.svl_handle,
541 + libvarpd_plugin_query_reply(svl->svl_u.svl_route.svl_handle,
512 542 VARPD_LOOKUP_DROP);
513 543 umem_cache_free(svp_lookup_cache, svl);
514 544 return;
515 545 }
516 546
517 - otp = svl->svl_u.svl_rvl3.svl_point;
518 - otr = svl->svl_u.svl_rvl3.svl_route;
519 - /* XXX KEBE SAYS FILL ME IN! */
547 + otp = svl->svl_u.svl_route.svl_point;
548 + bcopy(dstmac, otp->otp_mac, ETHERADDRL);
549 + bcopy(ul3_addr, &otp->otp_ip, sizeof (struct in6_addr));
550 + otp->otp_port = ul3_port;
520 551
521 - libvarpd_plugin_query_reply(svl->svl_u.svl_rvl3.svl_handle,
552 + otr = svl->svl_u.svl_route.svl_route;
553 + otr->otr_vnet = vnetid;
554 + otr->otr_vlan = vlan;
555 + bcopy(srcmac, otr->otr_srcmac, ETHERADDRL);
556 + otr->otr_dcid = dcid;
557 + otr->otr_src_prefixlen = srcpfx;
558 + otr->otr_dst_prefixlen = dstpfx;
559 +
560 + libvarpd_plugin_query_reply(svl->svl_u.svl_route.svl_handle,
522 561 VARPD_LOOKUP_OK);
523 562 umem_cache_free(svp_lookup_cache, svl);
524 563 }
525 564
526 565 static svp_cb_t svp_defops = {
527 566 svp_vl2_lookup_cb,
528 567 svp_vl3_lookup_cb,
529 568 svp_vl2_invalidate_cb,
530 569 svp_vl3_inject_cb,
531 570 svp_shootdown_cb,
532 - svp_rvl3_lookup_cb,
571 + svp_route_lookup_cb,
533 572 };
534 573
535 574 static boolean_t
536 575 varpd_svp_valid_dest(overlay_plugin_dest_t dest)
537 576 {
538 577 if (dest != (OVERLAY_PLUGIN_D_IP | OVERLAY_PLUGIN_D_PORT))
539 578 return (B_FALSE);
540 579
541 580 return (B_TRUE);
542 581 }
543 582
544 583 static int
545 584 varpd_svp_create(varpd_provider_handle_t *hdl, void **outp,
546 585 overlay_plugin_dest_t dest)
547 586 {
548 587 int ret;
549 588 svp_t *svp;
550 589
551 590 if (varpd_svp_valid_dest(dest) == B_FALSE)
552 591 return (ENOTSUP);
553 592
554 593 svp = umem_zalloc(sizeof (svp_t), UMEM_DEFAULT);
555 594 if (svp == NULL)
556 595 return (ENOMEM);
557 596
558 597 if ((ret = mutex_init(&svp->svp_lock, USYNC_THREAD | LOCK_ERRORCHECK,
559 598 NULL)) != 0) {
560 599 umem_free(svp, sizeof (svp_t));
561 600 return (ret);
562 601 }
563 602
564 603 svp->svp_port = svp_defport;
565 604 svp->svp_uport = svp_defuport;
566 605 svp->svp_cb = svp_defops;
567 606 svp->svp_hdl = hdl;
568 607 svp->svp_vid = libvarpd_plugin_vnetid(svp->svp_hdl);
569 608 *outp = svp;
570 609 return (0);
571 610 }
572 611
573 612 static int
574 613 varpd_svp_start(void *arg)
575 614 {
576 615 int ret;
577 616 svp_remote_t *srp;
578 617 svp_t *svp = arg;
579 618
580 619 mutex_enter(&svp->svp_lock);
581 620 if (svp->svp_host == NULL || svp->svp_port == 0 ||
582 621 svp->svp_huip == B_FALSE || svp->svp_uport == 0) {
583 622 mutex_exit(&svp->svp_lock);
584 623 return (EAGAIN);
585 624 }
586 625 mutex_exit(&svp->svp_lock);
587 626
588 627 if ((ret = svp_remote_find(svp->svp_host, svp->svp_port, &svp->svp_uip,
589 628 &srp)) != 0)
590 629 return (ret);
591 630
592 631 if ((ret = svp_remote_attach(srp, svp)) != 0) {
593 632 svp_remote_release(srp);
594 633 return (ret);
595 634 }
596 635
597 636 return (0);
598 637 }
599 638
600 639 static void
601 640 varpd_svp_stop(void *arg)
602 641 {
603 642 svp_t *svp = arg;
604 643
605 644 svp_remote_detach(svp);
606 645 }
607 646
608 647 static void
609 648 varpd_svp_destroy(void *arg)
610 649 {
611 650 svp_t *svp = arg;
612 651
613 652 if (svp->svp_host != NULL)
614 653 umem_free(svp->svp_host, strlen(svp->svp_host) + 1);
615 654
616 655 if (mutex_destroy(&svp->svp_lock) != 0)
617 656 libvarpd_panic("failed to destroy svp_t`svp_lock");
618 657
619 658 umem_free(svp, sizeof (svp_t));
620 659 }
621 660
622 661 static void
623 662 varpd_svp_lookup_l3(svp_t *svp, varpd_query_handle_t *vqh,
624 663 const overlay_targ_lookup_t *otl, overlay_target_point_t *otp,
625 664 overlay_target_route_t *otr)
626 665 {
627 666 svp_lookup_t *slp;
628 667 uint32_t type;
629 668 const struct in6_addr *src = &otl->otl_addru.otlu_l3.otl3_srcip,
|
↓ open down ↓ |
87 lines elided |
↑ open up ↑ |
630 669 *dst = &otl->otl_addru.otlu_l3.otl3_dstip;
631 670
632 671 /*
633 672 * otl is an L3 request, so we have src/dst IPs for the inner packet.
634 673 * We also have the vlan.
635 674 *
636 675 * Assume kernel's overlay module is caching well, so we are directly
637 676 * going to query (i.e. no caching up here of actual destinations).
638 677 *
639 678 * Our existing remote sever (svp_remote), but with the new message
640 - * SVP_R_REMOTE_VL3_REQ. Our naming of these functions already has
641 - * "remote" in it, but we'll use "rvl3" instead of "vl3".
679 + * SVP_R_ROUTE_REQ.
642 680 */
643 681
644 682 /* XXX KEBE SAYS DO SOME otl verification too... */
645 683 if (IN6_IS_ADDR_V4MAPPED(src)) {
646 684 if (!IN6_IS_ADDR_V4MAPPED(dst)) {
647 685 libvarpd_plugin_query_reply(vqh, VARPD_LOOKUP_DROP);
648 686 return;
649 687 }
650 688 type = SVP_VL3_IP;
651 689 } else {
652 690 if (IN6_IS_ADDR_V4MAPPED(dst)) {
653 691 libvarpd_plugin_query_reply(vqh, VARPD_LOOKUP_DROP);
654 692 return;
|
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
655 693 }
656 694 type = SVP_VL3_IPV6;
657 695 }
658 696
659 697 slp = umem_cache_alloc(svp_lookup_cache, UMEM_DEFAULT);
660 698 if (slp == NULL) {
661 699 libvarpd_plugin_query_reply(vqh, VARPD_LOOKUP_DROP);
662 700 return;
663 701 }
664 702
665 - slp->svl_type = SVP_L_RVL3;
666 - slp->svl_u.svl_rvl3.svl_handle = vqh;
667 - slp->svl_u.svl_rvl3.svl_point = otp;
668 - slp->svl_u.svl_rvl3.svl_route = otr;
703 + slp->svl_type = SVP_L_ROUTE;
704 + slp->svl_u.svl_route.svl_handle = vqh;
705 + slp->svl_u.svl_route.svl_point = otp;
706 + slp->svl_u.svl_route.svl_route = otr;
669 707
670 - /* XXX KEBE SAYS FILL IN ARGS PROPERLY... */
671 - svp_remote_rvl3_lookup(svp, &slp->svl_query, src, dst, type,
708 + svp_remote_route_lookup(svp, &slp->svl_query, src, dst,
672 709 otl->otl_vnetid, (uint16_t)otl->otl_vlan, slp);
673 710 }
674 711
675 712 static void
676 713 varpd_svp_lookup(void *arg, varpd_query_handle_t *vqh,
677 714 const overlay_targ_lookup_t *otl, overlay_target_point_t *otp,
678 715 overlay_target_route_t *otr)
679 716 {
680 717 svp_lookup_t *slp;
681 718 svp_t *svp = arg;
682 719
683 720 /*
684 721 * Shuffle off L3 lookups to their own codepath.
685 722 */
686 723 if (otl->otl_l3req) {
687 724 varpd_svp_lookup_l3(svp, vqh, otl, otp, otr);
688 725 return;
689 726 }
690 727 /*
691 728 * At this point, the traditional overlay_target_point_t is all that
692 729 * needs filling in. Zero-out the otr for safety.
693 730 */
694 731 bzero(otr, sizeof (*otr));
695 732
696 733
697 734 /*
698 735 * Check if this is something that we need to proxy, eg. arp or ndp.
699 736 */
700 737 if (otl->otl_addru.otlu_l2.otl2_sap == ETHERTYPE_ARP) {
701 738 libvarpd_plugin_proxy_arp(svp->svp_hdl, vqh, otl);
702 739 return;
703 740 }
704 741
705 742 if (otl->otl_addru.otlu_l2.otl2_dstaddr[0] == 0x33 &&
706 743 otl->otl_addru.otlu_l2.otl2_dstaddr[1] == 0x33) {
707 744 if (otl->otl_addru.otlu_l2.otl2_sap == ETHERTYPE_IPV6) {
708 745 libvarpd_plugin_proxy_ndp(svp->svp_hdl, vqh, otl);
709 746 } else {
710 747 libvarpd_plugin_query_reply(vqh, VARPD_LOOKUP_DROP);
711 748 }
712 749 return;
713 750 }
714 751
715 752 /*
716 753 * Watch out for various multicast and broadcast addresses. We've
717 754 * already taken care of the IPv6 range above. Now we just need to
718 755 * handle broadcast and if the multicast bit is set, lowest bit of the
719 756 * first octet of the MAC, then we drop it now.
720 757 */
721 758 if (bcmp(otl->otl_addru.otlu_l2.otl2_dstaddr, svp_bcast,
722 759 ETHERADDRL) == 0 ||
723 760 (otl->otl_addru.otlu_l2.otl2_dstaddr[0] & 0x01) == 0x01) {
724 761 libvarpd_plugin_query_reply(vqh, VARPD_LOOKUP_DROP);
725 762 return;
726 763 }
727 764
728 765 /*
729 766 * If we have a failure to allocate memory for this, that's not good.
730 767 * However, telling the kernel to just drop this packet is much better
731 768 * than the alternative at this moment. At least we'll try again and we
732 769 * may have something more available to us in a little bit.
733 770 */
734 771 slp = umem_cache_alloc(svp_lookup_cache, UMEM_DEFAULT);
735 772 if (slp == NULL) {
736 773 libvarpd_plugin_query_reply(vqh, VARPD_LOOKUP_DROP);
737 774 return;
738 775 }
739 776
740 777 slp->svl_type = SVP_L_VL2;
741 778 slp->svl_u.svl_vl2.svl_handle = vqh;
742 779 slp->svl_u.svl_vl2.svl_point = otp;
743 780
744 781 svp_remote_vl2_lookup(svp, &slp->svl_query,
745 782 otl->otl_addru.otlu_l2.otl2_dstaddr, slp);
746 783 }
747 784
748 785 /* ARGSUSED */
749 786 static int
750 787 varpd_svp_nprops(void *arg, uint_t *nprops)
751 788 {
752 789 *nprops = sizeof (varpd_svp_props) / sizeof (char *);
753 790 return (0);
754 791 }
755 792
756 793 /* ARGSUSED */
757 794 static int
758 795 varpd_svp_propinfo(void *arg, uint_t propid, varpd_prop_handle_t *vph)
759 796 {
760 797 switch (propid) {
761 798 case 0:
762 799 /* svp/host */
763 800 libvarpd_prop_set_name(vph, varpd_svp_props[0]);
764 801 libvarpd_prop_set_prot(vph, OVERLAY_PROP_PERM_RRW);
765 802 libvarpd_prop_set_type(vph, OVERLAY_PROP_T_STRING);
766 803 libvarpd_prop_set_nodefault(vph);
767 804 break;
768 805 case 1:
769 806 /* svp/port */
770 807 libvarpd_prop_set_name(vph, varpd_svp_props[1]);
771 808 libvarpd_prop_set_prot(vph, OVERLAY_PROP_PERM_RRW);
772 809 libvarpd_prop_set_type(vph, OVERLAY_PROP_T_UINT);
773 810 (void) libvarpd_prop_set_default(vph, &svp_defport,
774 811 sizeof (svp_defport));
775 812 libvarpd_prop_set_range_uint32(vph, 1, UINT16_MAX);
776 813 break;
777 814 case 2:
778 815 /* svp/underlay_ip */
779 816 libvarpd_prop_set_name(vph, varpd_svp_props[2]);
780 817 libvarpd_prop_set_prot(vph, OVERLAY_PROP_PERM_RRW);
781 818 libvarpd_prop_set_type(vph, OVERLAY_PROP_T_IP);
782 819 libvarpd_prop_set_nodefault(vph);
783 820 break;
784 821 case 3:
785 822 /* svp/underlay_port */
786 823 libvarpd_prop_set_name(vph, varpd_svp_props[3]);
787 824 libvarpd_prop_set_prot(vph, OVERLAY_PROP_PERM_RRW);
788 825 libvarpd_prop_set_type(vph, OVERLAY_PROP_T_UINT);
789 826 (void) libvarpd_prop_set_default(vph, &svp_defuport,
790 827 sizeof (svp_defuport));
791 828 libvarpd_prop_set_range_uint32(vph, 1, UINT16_MAX);
792 829 break;
|
↓ open down ↓ |
111 lines elided |
↑ open up ↑ |
793 830 case 4:
794 831 /* svp/dcid */
795 832 libvarpd_prop_set_name(vph, varpd_svp_props[4]);
796 833 libvarpd_prop_set_prot(vph, OVERLAY_PROP_PERM_RRW);
797 834 libvarpd_prop_set_type(vph, OVERLAY_PROP_T_UINT);
798 835 libvarpd_prop_set_nodefault(vph);
799 836 /* XXX KEBE ASKS should I just set high to UINT32_MAX? */
800 837 libvarpd_prop_set_range_uint32(vph, 1, UINT32_MAX - 1);
801 838 break;
802 839 case 5:
803 - /* svp/router_mac */
840 + /* svp/router_oui */
804 841 libvarpd_prop_set_name(vph, varpd_svp_props[5]);
805 842 libvarpd_prop_set_prot(vph, OVERLAY_PROP_PERM_RRW);
806 843 libvarpd_prop_set_type(vph, OVERLAY_PROP_T_ETHER);
807 844 libvarpd_prop_set_nodefault(vph);
808 845 break;
809 846 default:
810 847 return (EINVAL);
811 848 }
812 849 return (0);
813 850 }
814 851
815 852 static int
816 853 varpd_svp_getprop(void *arg, const char *pname, void *buf, uint32_t *sizep)
817 854 {
818 855 svp_t *svp = arg;
819 856
820 857 /* svp/host */
821 858 if (strcmp(pname, varpd_svp_props[0]) == 0) {
822 859 size_t len;
823 860
824 861 mutex_enter(&svp->svp_lock);
825 862 if (svp->svp_host == NULL) {
826 863 *sizep = 0;
827 864 } else {
828 865 len = strlen(svp->svp_host) + 1;
829 866 if (*sizep < len) {
830 867 mutex_exit(&svp->svp_lock);
831 868 return (EOVERFLOW);
832 869 }
833 870 *sizep = len;
834 871 (void) strlcpy(buf, svp->svp_host, *sizep);
835 872 }
836 873 mutex_exit(&svp->svp_lock);
837 874 return (0);
838 875 }
839 876
840 877 /* svp/port */
841 878 if (strcmp(pname, varpd_svp_props[1]) == 0) {
842 879 uint64_t val;
843 880
844 881 if (*sizep < sizeof (uint64_t))
845 882 return (EOVERFLOW);
846 883
847 884 mutex_enter(&svp->svp_lock);
848 885 if (svp->svp_port == 0) {
849 886 *sizep = 0;
850 887 } else {
851 888 val = svp->svp_port;
852 889 bcopy(&val, buf, sizeof (uint64_t));
853 890 *sizep = sizeof (uint64_t);
854 891 }
855 892 mutex_exit(&svp->svp_lock);
856 893 return (0);
857 894 }
858 895
859 896 /* svp/underlay_ip */
860 897 if (strcmp(pname, varpd_svp_props[2]) == 0) {
861 898 if (*sizep < sizeof (struct in6_addr))
862 899 return (EOVERFLOW);
863 900 mutex_enter(&svp->svp_lock);
864 901 if (svp->svp_huip == B_FALSE) {
865 902 *sizep = 0;
866 903 } else {
867 904 bcopy(&svp->svp_uip, buf, sizeof (struct in6_addr));
868 905 *sizep = sizeof (struct in6_addr);
869 906 }
870 907 mutex_exit(&svp->svp_lock);
871 908 return (0);
872 909 }
873 910
874 911 /* svp/underlay_port */
875 912 if (strcmp(pname, varpd_svp_props[3]) == 0) {
876 913 uint64_t val;
877 914
878 915 if (*sizep < sizeof (uint64_t))
879 916 return (EOVERFLOW);
880 917
881 918 mutex_enter(&svp->svp_lock);
882 919 if (svp->svp_uport == 0) {
883 920 *sizep = 0;
884 921 } else {
885 922 val = svp->svp_uport;
886 923 bcopy(&val, buf, sizeof (uint64_t));
887 924 *sizep = sizeof (uint64_t);
888 925 }
889 926
890 927 mutex_exit(&svp->svp_lock);
891 928 return (0);
892 929 }
893 930
894 931 /* svp/dcid */
895 932 if (strcmp(pname, varpd_svp_props[4]) == 0) {
896 933 uint64_t val;
897 934
898 935 if (*sizep < sizeof (uint64_t))
899 936 return (EOVERFLOW);
900 937
901 938 mutex_enter(&svp->svp_lock);
902 939 if (svp->svp_uport == 0) {
903 940 *sizep = 0;
|
↓ open down ↓ |
90 lines elided |
↑ open up ↑ |
904 941 } else {
905 942 val = svp->svp_dcid;
906 943 bcopy(&val, buf, sizeof (uint64_t));
907 944 *sizep = sizeof (uint64_t);
908 945 }
909 946
910 947 mutex_exit(&svp->svp_lock);
911 948 return (0);
912 949 }
913 950
914 - /* svp/router_mac */
951 + /* svp/router_oui */
915 952 if (strcmp(pname, varpd_svp_props[5]) == 0) {
916 953 if (*sizep < ETHERADDRL)
917 954 return (EOVERFLOW);
918 955 mutex_enter(&svp->svp_lock);
919 956
920 - if (ether_is_zero(&svp->svp_router_mac)) {
957 + if (ether_is_zero(&svp->svp_router_oui)) {
921 958 *sizep = 0;
922 959 } else {
923 - bcopy(&svp->svp_router_mac, buf, ETHERADDRL);
960 + bcopy(&svp->svp_router_oui, buf, ETHERADDRL);
924 961 *sizep = ETHERADDRL;
925 962 }
926 963
927 964 mutex_exit(&svp->svp_lock);
928 965 return (0);
929 966 }
930 967 return (EINVAL);
931 968 }
932 969
933 970 static int
934 971 varpd_svp_setprop(void *arg, const char *pname, const void *buf,
935 972 const uint32_t size)
936 973 {
937 974 svp_t *svp = arg;
938 975
939 976 /* svp/host */
940 977 if (strcmp(pname, varpd_svp_props[0]) == 0) {
941 978 char *dup;
942 979 dup = umem_alloc(size, UMEM_DEFAULT);
943 980 (void) strlcpy(dup, buf, size);
944 981 if (dup == NULL)
945 982 return (ENOMEM);
946 983 mutex_enter(&svp->svp_lock);
947 984 if (svp->svp_host != NULL)
948 985 umem_free(svp->svp_host, strlen(svp->svp_host) + 1);
949 986 svp->svp_host = dup;
950 987 mutex_exit(&svp->svp_lock);
951 988 return (0);
952 989 }
953 990
954 991 /* svp/port */
955 992 if (strcmp(pname, varpd_svp_props[1]) == 0) {
956 993 const uint64_t *valp = buf;
957 994 if (size < sizeof (uint64_t))
958 995 return (EOVERFLOW);
959 996
960 997 if (*valp == 0 || *valp > UINT16_MAX)
961 998 return (EINVAL);
962 999
963 1000 mutex_enter(&svp->svp_lock);
964 1001 svp->svp_port = (uint16_t)*valp;
965 1002 mutex_exit(&svp->svp_lock);
966 1003 return (0);
967 1004 }
968 1005
969 1006 /* svp/underlay_ip */
970 1007 if (strcmp(pname, varpd_svp_props[2]) == 0) {
971 1008 const struct in6_addr *ipv6 = buf;
972 1009
973 1010 if (size < sizeof (struct in6_addr))
974 1011 return (EOVERFLOW);
975 1012
976 1013 if (IN6_IS_ADDR_V4COMPAT(ipv6))
977 1014 return (EINVAL);
978 1015
979 1016 if (IN6_IS_ADDR_MULTICAST(ipv6))
980 1017 return (EINVAL);
981 1018
982 1019 if (IN6_IS_ADDR_6TO4(ipv6))
983 1020 return (EINVAL);
984 1021
985 1022 if (IN6_IS_ADDR_V4MAPPED(ipv6)) {
986 1023 ipaddr_t v4;
987 1024 IN6_V4MAPPED_TO_IPADDR(ipv6, v4);
988 1025 if (IN_MULTICAST(v4))
989 1026 return (EINVAL);
990 1027 }
991 1028
992 1029 mutex_enter(&svp->svp_lock);
993 1030 bcopy(buf, &svp->svp_uip, sizeof (struct in6_addr));
994 1031 svp->svp_huip = B_TRUE;
995 1032 mutex_exit(&svp->svp_lock);
996 1033 return (0);
997 1034 }
998 1035
999 1036 /* svp/underlay_port */
1000 1037 if (strcmp(pname, varpd_svp_props[3]) == 0) {
1001 1038 const uint64_t *valp = buf;
1002 1039 if (size < sizeof (uint64_t))
1003 1040 return (EOVERFLOW);
1004 1041
1005 1042 if (*valp == 0 || *valp > UINT16_MAX)
1006 1043 return (EINVAL);
1007 1044
1008 1045 mutex_enter(&svp->svp_lock);
1009 1046 svp->svp_uport = (uint16_t)*valp;
1010 1047 mutex_exit(&svp->svp_lock);
1011 1048
1012 1049 return (0);
1013 1050 }
1014 1051
1015 1052 /* svp/dcid */
1016 1053 if (strcmp(pname, varpd_svp_props[4]) == 0) {
1017 1054 const uint64_t *valp = buf;
1018 1055 if (size < sizeof (uint64_t))
1019 1056 return (EOVERFLOW);
1020 1057
1021 1058 /* XXX KEBE ASKS, use UINT32_MAX instead? */
|
↓ open down ↓ |
88 lines elided |
↑ open up ↑ |
1022 1059 if (*valp == 0 || *valp > UINT32_MAX - 1)
1023 1060 return (EINVAL);
1024 1061
1025 1062 mutex_enter(&svp->svp_lock);
1026 1063 svp->svp_dcid = (uint32_t)*valp;
1027 1064 mutex_exit(&svp->svp_lock);
1028 1065
1029 1066 return (0);
1030 1067 }
1031 1068
1032 - /* svp/router_mac */
1069 + /* svp/router_oui */
1033 1070 if (strcmp(pname, varpd_svp_props[5]) == 0) {
1034 1071 if (size < ETHERADDRL)
1035 1072 return (EOVERFLOW);
1036 1073 mutex_enter(&svp->svp_lock);
1037 - bcopy(buf, &svp->svp_router_mac, ETHERADDRL);
1074 + bcopy(buf, &svp->svp_router_oui, ETHERADDRL);
1075 + /* Zero-out the low three bytes. */
1076 + svp->svp_router_oui[3] = 0;
1077 + svp->svp_router_oui[4] = 0;
1078 + svp->svp_router_oui[5] = 0;
1038 1079 mutex_exit(&svp->svp_lock);
1039 1080 return (0);
1040 1081 }
1041 1082
1042 1083 return (EINVAL);
1043 1084 }
1044 1085
1045 1086 static int
1046 1087 varpd_svp_save(void *arg, nvlist_t *nvp)
1047 1088 {
1048 1089 int ret;
1049 1090 svp_t *svp = arg;
1050 1091
1051 1092 mutex_enter(&svp->svp_lock);
1052 1093 /* svp/host */
1053 1094 if (svp->svp_host != NULL) {
1054 1095 if ((ret = nvlist_add_string(nvp, varpd_svp_props[0],
1055 1096 svp->svp_host)) != 0) {
1056 1097 mutex_exit(&svp->svp_lock);
1057 1098 return (ret);
1058 1099 }
1059 1100 }
1060 1101
1061 1102 /* svp/port */
1062 1103 if (svp->svp_port != 0) {
1063 1104 if ((ret = nvlist_add_uint16(nvp, varpd_svp_props[1],
1064 1105 svp->svp_port)) != 0) {
1065 1106 mutex_exit(&svp->svp_lock);
1066 1107 return (ret);
1067 1108 }
1068 1109 }
1069 1110
1070 1111 /* svp/underlay_ip */
1071 1112 if (svp->svp_huip == B_TRUE) {
1072 1113 char buf[INET6_ADDRSTRLEN];
1073 1114
1074 1115 if (inet_ntop(AF_INET6, &svp->svp_uip, buf, sizeof (buf)) ==
1075 1116 NULL)
1076 1117 libvarpd_panic("unexpected inet_ntop failure: %d",
1077 1118 errno);
1078 1119
1079 1120 if ((ret = nvlist_add_string(nvp, varpd_svp_props[2],
1080 1121 buf)) != 0) {
1081 1122 mutex_exit(&svp->svp_lock);
1082 1123 return (ret);
1083 1124 }
1084 1125 }
1085 1126
1086 1127 /* svp/underlay_port */
1087 1128 if (svp->svp_uport != 0) {
1088 1129 if ((ret = nvlist_add_uint16(nvp, varpd_svp_props[3],
1089 1130 svp->svp_uport)) != 0) {
1090 1131 mutex_exit(&svp->svp_lock);
1091 1132 return (ret);
1092 1133 }
1093 1134 }
|
↓ open down ↓ |
46 lines elided |
↑ open up ↑ |
1094 1135
1095 1136 /* svp/dcid */
1096 1137 if (svp->svp_dcid != 0) {
1097 1138 if ((ret = nvlist_add_uint32(nvp, varpd_svp_props[4],
1098 1139 svp->svp_dcid)) != 0) {
1099 1140 mutex_exit(&svp->svp_lock);
1100 1141 return (ret);
1101 1142 }
1102 1143 }
1103 1144
1104 - /* svp/router_mac */
1105 - if (!ether_is_zero(&svp->svp_router_mac)) {
1145 + /* svp/router_oui */
1146 + if (!ether_is_zero(&svp->svp_router_oui)) {
1106 1147 char buf[ETHERADDRSTRL];
1107 1148
1108 1149 /* XXX KEBE SAYS See underlay_ip... */
1109 - if (ether_ntoa_r(&svp->svp_router_mac, buf) == NULL) {
1150 + if (ether_ntoa_r((struct ether_addr *)&svp->svp_router_oui,
1151 + buf) == NULL) {
1110 1152 libvarpd_panic("unexpected ether_ntoa_r failure: %d",
1111 1153 errno);
1112 1154 }
1113 1155
1114 1156 if ((ret = nvlist_add_string(nvp, varpd_svp_props[5],
1115 1157 buf)) != 0) {
1116 1158 mutex_exit(&svp->svp_lock);
1117 1159 return (ret);
1118 1160 }
1119 1161 }
1120 1162
1121 1163 mutex_exit(&svp->svp_lock);
1122 1164 return (0);
1123 1165 }
1124 1166
1125 1167 static int
1126 1168 varpd_svp_restore(nvlist_t *nvp, varpd_provider_handle_t *hdl,
1127 1169 overlay_plugin_dest_t dest, void **outp)
1128 1170 {
1129 1171 int ret;
1130 1172 svp_t *svp;
1131 1173 char *ipstr, *hstr, *etherstr;
1132 1174
1133 1175 if (varpd_svp_valid_dest(dest) == B_FALSE)
1134 1176 return (ENOTSUP);
1135 1177
1136 1178 if ((ret = varpd_svp_create(hdl, (void **)&svp, dest)) != 0)
1137 1179 return (ret);
1138 1180
1139 1181 /* svp/host */
1140 1182 if ((ret = nvlist_lookup_string(nvp, varpd_svp_props[0],
1141 1183 &hstr)) != 0) {
1142 1184 if (ret != ENOENT) {
1143 1185 varpd_svp_destroy(svp);
1144 1186 return (ret);
1145 1187 }
1146 1188 svp->svp_host = NULL;
1147 1189 } else {
1148 1190 size_t blen = strlen(hstr) + 1;
1149 1191 svp->svp_host = umem_alloc(blen, UMEM_DEFAULT);
1150 1192 (void) strlcpy(svp->svp_host, hstr, blen);
1151 1193 }
1152 1194
1153 1195 /* svp/port */
1154 1196 if ((ret = nvlist_lookup_uint16(nvp, varpd_svp_props[1],
1155 1197 &svp->svp_port)) != 0) {
1156 1198 if (ret != ENOENT) {
1157 1199 varpd_svp_destroy(svp);
1158 1200 return (ret);
1159 1201 }
1160 1202 svp->svp_port = 0;
1161 1203 }
1162 1204
1163 1205 /* svp/underlay_ip */
1164 1206 if ((ret = nvlist_lookup_string(nvp, varpd_svp_props[2],
1165 1207 &ipstr)) != 0) {
1166 1208 if (ret != ENOENT) {
1167 1209 varpd_svp_destroy(svp);
1168 1210 return (ret);
1169 1211 }
1170 1212 svp->svp_huip = B_FALSE;
1171 1213 } else {
1172 1214 ret = inet_pton(AF_INET6, ipstr, &svp->svp_uip);
1173 1215 if (ret == -1) {
1174 1216 assert(errno == EAFNOSUPPORT);
1175 1217 libvarpd_panic("unexpected inet_pton failure: %d",
1176 1218 errno);
1177 1219 }
1178 1220
1179 1221 if (ret == 0) {
1180 1222 varpd_svp_destroy(svp);
1181 1223 return (EINVAL);
1182 1224 }
1183 1225 svp->svp_huip = B_TRUE;
1184 1226 }
1185 1227
1186 1228 /* svp/underlay_port */
1187 1229 if ((ret = nvlist_lookup_uint16(nvp, varpd_svp_props[3],
1188 1230 &svp->svp_uport)) != 0) {
1189 1231 if (ret != ENOENT) {
1190 1232 varpd_svp_destroy(svp);
1191 1233 return (ret);
1192 1234 }
1193 1235 svp->svp_uport = 0;
1194 1236 }
1195 1237
|
↓ open down ↓ |
76 lines elided |
↑ open up ↑ |
1196 1238 /* svp/dcid */
1197 1239 if ((ret = nvlist_lookup_uint32(nvp, varpd_svp_props[4],
1198 1240 &svp->svp_dcid)) != 0) {
1199 1241 if (ret != ENOENT) {
1200 1242 varpd_svp_destroy(svp);
1201 1243 return (ret);
1202 1244 }
1203 1245 svp->svp_dcid = 0;
1204 1246 }
1205 1247
1206 - /* svp/router_mac */
1248 + /* svp/router_oui */
1207 1249 if ((ret = nvlist_lookup_string(nvp, varpd_svp_props[5],
1208 1250 ðerstr)) != 0) {
1209 1251 if (ret != ENOENT) {
1210 1252 varpd_svp_destroy(svp);
1211 1253 return (ret);
1212 1254 }
1213 - bzero(&svp->svp_router_mac, ETHERADDRL);
1214 - } else if (ether_aton_r(etherstr, &svp->svp_router_mac) == NULL) {
1255 + bzero(&svp->svp_router_oui, ETHERADDRL);
1256 + } else if (ether_aton_r(etherstr,
1257 + (struct ether_addr *)&svp->svp_router_oui) == NULL) {
1215 1258 libvarpd_panic("unexpected ether_aton_r failure: %d", errno);
1216 1259 }
1217 1260
1218 1261 svp->svp_hdl = hdl;
1219 1262 *outp = svp;
1220 1263 return (0);
1221 1264 }
1222 1265
1223 1266 static void
1224 1267 varpd_svp_arp(void *arg, varpd_arp_handle_t *vah, int type,
1225 1268 const struct sockaddr *sock, uint8_t *out)
1226 1269 {
1227 1270 svp_t *svp = arg;
1228 1271 svp_lookup_t *svl;
1229 1272
1230 1273 if (type != VARPD_QTYPE_ETHERNET) {
1231 1274 libvarpd_plugin_arp_reply(vah, VARPD_LOOKUP_DROP);
1232 1275 return;
1233 1276 }
1234 1277
1235 1278 svl = umem_cache_alloc(svp_lookup_cache, UMEM_DEFAULT);
1236 1279 if (svl == NULL) {
1237 1280 libvarpd_plugin_arp_reply(vah, VARPD_LOOKUP_DROP);
1238 1281 return;
1239 1282 }
1240 1283
1241 1284 svl->svl_type = SVP_L_VL3;
1242 1285 svl->svl_u.svl_vl3.svl_vah = vah;
1243 1286 svl->svl_u.svl_vl3.svl_out = out;
1244 1287 svp_remote_vl3_lookup(svp, &svl->svl_query, sock, svl);
1245 1288 }
1246 1289
1247 1290 static const varpd_plugin_ops_t varpd_svp_ops = {
1248 1291 0,
1249 1292 varpd_svp_create,
1250 1293 varpd_svp_start,
1251 1294 varpd_svp_stop,
1252 1295 varpd_svp_destroy,
1253 1296 NULL,
1254 1297 varpd_svp_lookup,
1255 1298 varpd_svp_nprops,
1256 1299 varpd_svp_propinfo,
1257 1300 varpd_svp_getprop,
1258 1301 varpd_svp_setprop,
1259 1302 varpd_svp_save,
1260 1303 varpd_svp_restore,
1261 1304 varpd_svp_arp,
1262 1305 NULL
1263 1306 };
1264 1307
1265 1308 static int
1266 1309 svp_bunyan_init(void)
1267 1310 {
1268 1311 int ret;
1269 1312
1270 1313 if ((ret = bunyan_init("svp", &svp_bunyan)) != 0)
1271 1314 return (ret);
1272 1315 ret = bunyan_stream_add(svp_bunyan, "stderr", BUNYAN_L_INFO,
1273 1316 bunyan_stream_fd, (void *)STDERR_FILENO);
1274 1317 if (ret != 0)
1275 1318 bunyan_fini(svp_bunyan);
1276 1319 return (ret);
1277 1320 }
1278 1321
1279 1322 static void
1280 1323 svp_bunyan_fini(void)
1281 1324 {
1282 1325 if (svp_bunyan != NULL)
1283 1326 bunyan_fini(svp_bunyan);
1284 1327 }
1285 1328
1286 1329 #pragma init(varpd_svp_init)
1287 1330 static void
1288 1331 varpd_svp_init(void)
1289 1332 {
1290 1333 int err;
1291 1334 varpd_plugin_register_t *vpr;
1292 1335
1293 1336 if (svp_bunyan_init() != 0)
1294 1337 return;
1295 1338
1296 1339 if ((err = svp_host_init()) != 0) {
1297 1340 (void) bunyan_error(svp_bunyan, "failed to init host subsystem",
1298 1341 BUNYAN_T_INT32, "error", err,
1299 1342 BUNYAN_T_END);
1300 1343 svp_bunyan_fini();
1301 1344 return;
1302 1345 }
1303 1346
1304 1347 svp_lookup_cache = umem_cache_create("svp_lookup",
1305 1348 sizeof (svp_lookup_t), 0, NULL, NULL, NULL, NULL, NULL, 0);
1306 1349 if (svp_lookup_cache == NULL) {
1307 1350 (void) bunyan_error(svp_bunyan,
1308 1351 "failed to create svp_lookup cache",
1309 1352 BUNYAN_T_INT32, "error", errno,
1310 1353 BUNYAN_T_END);
1311 1354 svp_bunyan_fini();
1312 1355 return;
1313 1356 }
1314 1357
1315 1358 if ((err = svp_event_init()) != 0) {
1316 1359 (void) bunyan_error(svp_bunyan,
1317 1360 "failed to init event subsystem",
1318 1361 BUNYAN_T_INT32, "error", err,
1319 1362 BUNYAN_T_END);
1320 1363 svp_bunyan_fini();
1321 1364 umem_cache_destroy(svp_lookup_cache);
1322 1365 return;
1323 1366 }
1324 1367
1325 1368 if ((err = svp_timer_init()) != 0) {
1326 1369 (void) bunyan_error(svp_bunyan,
1327 1370 "failed to init timer subsystem",
1328 1371 BUNYAN_T_INT32, "error", err,
1329 1372 BUNYAN_T_END);
1330 1373 svp_event_fini();
1331 1374 umem_cache_destroy(svp_lookup_cache);
1332 1375 svp_bunyan_fini();
1333 1376 return;
1334 1377 }
1335 1378
1336 1379 if ((err = svp_remote_init()) != 0) {
1337 1380 (void) bunyan_error(svp_bunyan,
1338 1381 "failed to init remote subsystem",
1339 1382 BUNYAN_T_INT32, "error", err,
1340 1383 BUNYAN_T_END);
1341 1384 svp_event_fini();
1342 1385 umem_cache_destroy(svp_lookup_cache);
1343 1386 svp_bunyan_fini();
1344 1387 return;
1345 1388 }
1346 1389
1347 1390 vpr = libvarpd_plugin_alloc(VARPD_CURRENT_VERSION, &err);
1348 1391 if (vpr == NULL) {
1349 1392 (void) bunyan_error(svp_bunyan,
1350 1393 "failed to alloc varpd plugin",
1351 1394 BUNYAN_T_INT32, "error", err,
1352 1395 BUNYAN_T_END);
1353 1396 svp_remote_fini();
1354 1397 svp_event_fini();
1355 1398 umem_cache_destroy(svp_lookup_cache);
1356 1399 svp_bunyan_fini();
1357 1400 return;
1358 1401 }
1359 1402
1360 1403 vpr->vpr_mode = OVERLAY_TARGET_DYNAMIC;
1361 1404 vpr->vpr_name = "svp";
1362 1405 vpr->vpr_ops = &varpd_svp_ops;
1363 1406
1364 1407 if ((err = libvarpd_plugin_register(vpr)) != 0) {
1365 1408 (void) bunyan_error(svp_bunyan,
1366 1409 "failed to register varpd plugin",
1367 1410 BUNYAN_T_INT32, "error", err,
1368 1411 BUNYAN_T_END);
1369 1412 svp_remote_fini();
1370 1413 svp_event_fini();
1371 1414 umem_cache_destroy(svp_lookup_cache);
1372 1415 svp_bunyan_fini();
1373 1416
1374 1417 }
1375 1418 libvarpd_plugin_free(vpr);
1376 1419 }
|
↓ open down ↓ |
152 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX