diff options
author | Reyk Floeter <reyk@cvs.openbsd.org> | 2016-10-12 19:07:43 +0000 |
---|---|---|
committer | Reyk Floeter <reyk@cvs.openbsd.org> | 2016-10-12 19:07:43 +0000 |
commit | 2c8b4a5d06668df9dd4ca308364599ed7bd90ce6 (patch) | |
tree | 1957e11b32cbb7f59e980e7bed52f779522b2dc9 /usr.sbin/switchd/ofcconn.c | |
parent | 9a8144695bfe9da05620d6691336173b6178623c (diff) |
Start reworking the "device" support in switchd: Once connected, a
device is just an fd that is connected to a switch, either via TCP or
via /dev/switch. Change the switchctl from "device add" to "connect"
etc. This change is an intermediate step towards other changes,
including the configuration grammar, so a few things will be left
undocumented for now.
switchctl(8) examples,
switchctl connect /dev/switch0
switchctl connect /dev/switch0 forward-to 10.1.1.1
switchctl connect 127.0.0.1
switchctl connect 127.0.0.1 forward-to 10.1.1.1
switchctl disconnect /dev/switch0
Discussed with rzalamena@
Diffstat (limited to 'usr.sbin/switchd/ofcconn.c')
-rw-r--r-- | usr.sbin/switchd/ofcconn.c | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/usr.sbin/switchd/ofcconn.c b/usr.sbin/switchd/ofcconn.c index a26159b47dd..059f2f4fdd9 100644 --- a/usr.sbin/switchd/ofcconn.c +++ b/usr.sbin/switchd/ofcconn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ofcconn.c,v 1.11 2016/09/30 12:48:27 reyk Exp $ */ +/* $OpenBSD: ofcconn.c,v 1.12 2016/10/12 19:07:42 reyk Exp $ */ /* * Copyright (c) 2016 YASUOKA Masahiko <yasuoka@openbsd.org> @@ -20,6 +20,7 @@ #include <sys/queue.h> #include <sys/uio.h> #include <sys/socket.h> +#include <sys/un.h> #include <net/ofp.h> @@ -78,7 +79,7 @@ void ofsw_on_io(int, short, void *); int ofsw_write(struct ofsw *, struct ofcconn *); int ofsw_ofc_write_ready(struct ofsw *); void ofsw_reset_event_handlers(struct ofsw *); -int ofsw_new_ofcconn(struct ofsw *, struct switch_controller *); +int ofsw_new_ofcconn(struct ofsw *, struct switch_address *); int ofcconn_connect(struct ofcconn *); void ofcconn_on_sockio(int, short, void *); void ofcconn_connect_again(struct ofcconn *); @@ -126,30 +127,33 @@ int ofcconn_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg) { struct ofsw *os; - struct switch_device *sdv; - struct switch_controller *swc; + struct switch_client swc; + struct sockaddr_un *un; switch (imsg->hdr.type) { - case IMSG_CTL_DEVICE_CONNECT: - if (IMSG_DATA_SIZE(imsg) < sizeof(*sdv)) { - log_warnx("%s: IMSG_CTL_DEVICE_CONNECT: " + case IMSG_CTL_CONNECT: + if (IMSG_DATA_SIZE(imsg) < sizeof(swc)) { + log_warnx("%s: IMSG_CTL_CONNECT: " "invalid message size", __func__); return (0); } - sdv = imsg->data; - swc = &sdv->sdv_swc; - if ((os = ofsw_create(sdv->sdv_device, imsg->fd)) != NULL) - ofsw_new_ofcconn(os, swc); + memcpy(&swc, imsg->data, sizeof(swc)); + un = (struct sockaddr_un *)&swc.swc_addr.swa_addr; + + if ((os = ofsw_create(un->sun_path, imsg->fd)) != NULL) + ofsw_new_ofcconn(os, &swc.swc_target); return (0); - case IMSG_CTL_DEVICE_DISCONNECT: - if (IMSG_DATA_SIZE(imsg) < sizeof(*sdv)) { + case IMSG_CTL_DISCONNECT: + if (IMSG_DATA_SIZE(imsg) < sizeof(swc)) { log_warnx("%s: IMSG_CTL_DEVICE_DISCONNECT: " "invalid message size", __func__); return (0); } - sdv = imsg->data; + memcpy(&swc, imsg->data, sizeof(swc)); + un = (struct sockaddr_un *)&swc.swc_addr.swa_addr; + TAILQ_FOREACH(os, &ofsw_list, os_next) { - if (!strcmp(os->os_name, sdv->sdv_device)) + if (!strcmp(os->os_name, un->sun_path)) break; } if (os) { @@ -375,7 +379,7 @@ ofsw_reset_event_handlers(struct ofsw *os) } int -ofsw_new_ofcconn(struct ofsw *os, struct switch_controller *swc) +ofsw_new_ofcconn(struct ofsw *os, struct switch_address *swa) { struct ofcconn *oc = NULL; char buf[128]; @@ -386,7 +390,7 @@ ofsw_new_ofcconn(struct ofsw *os, struct switch_controller *swc) } if (asprintf(&oc->oc_name, "tcp:%s", - print_host(&swc->swc_addr, buf, sizeof(buf))) == -1) { + print_host(&swa->swa_addr, buf, sizeof(buf))) == -1) { log_warn("%s: strdup failed", __func__); goto fail; } @@ -396,7 +400,7 @@ ofsw_new_ofcconn(struct ofsw *os, struct switch_controller *swc) } oc->oc_sw = os; oc->oc_sock = -1; - memcpy(&oc->oc_peer, &swc->swc_addr, sizeof(oc->oc_peer)); + memcpy(&oc->oc_peer, &swa->swa_addr, sizeof(oc->oc_peer)); if (ntohs(((struct sockaddr_in *)&oc->oc_peer)->sin_port) == 0) ((struct sockaddr_in *)&oc->oc_peer)->sin_port = @@ -444,7 +448,7 @@ ofcconn_connect(struct ofcconn *oc) ofcconn_on_sockio, oc); event_add(&oc->oc_evsock, NULL); - tv.tv_sec = SWITCHD_OFCCONN_TIMEOUT; + tv.tv_sec = SWITCHD_CONNECT_TIMEOUT; tv.tv_usec = 0; event_add(&oc->oc_evtimer, &tv); |