summaryrefslogtreecommitdiff
path: root/usr.sbin/switchctl
diff options
context:
space:
mode:
authorakoshibe <akoshibe@cvs.openbsd.org>2018-10-21 21:10:25 +0000
committerakoshibe <akoshibe@cvs.openbsd.org>2018-10-21 21:10:25 +0000
commitdb2cb1c7379a5f10c1521bc8d2eaf6406587bd62 (patch)
tree3aaf829f7c9c892035208798159f5f6af34493f5 /usr.sbin/switchctl
parent0841ff09cd03445bb3d29b045deca06bf6a8750e (diff)
Add the ability to query a switch(4) instance via its control device. Also
explicitly set the OpenFlow version during the handshake prior to a query. Since switchctl(8) behaves like a controller in this case, a switch can't be connected to switchd(8) while it is being queried in this way. OK claudio@, tb@ and mestre@ for pledge changes
Diffstat (limited to 'usr.sbin/switchctl')
-rw-r--r--usr.sbin/switchctl/ofpclient.c20
-rw-r--r--usr.sbin/switchctl/parser.c10
-rw-r--r--usr.sbin/switchctl/switchctl.88
-rw-r--r--usr.sbin/switchctl/switchctl.c8
4 files changed, 37 insertions, 9 deletions
diff --git a/usr.sbin/switchctl/ofpclient.c b/usr.sbin/switchctl/ofpclient.c
index f60e3317431..b349a0ba842 100644
--- a/usr.sbin/switchctl/ofpclient.c
+++ b/usr.sbin/switchctl/ofpclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ofpclient.c,v 1.6 2017/01/09 16:42:14 reyk Exp $ */
+/* $OpenBSD: ofpclient.c,v 1.7 2018/10/21 21:10:24 akoshibe Exp $ */
/*
* Copyright (c) 2016 Reyk Floeter <reyk@openbsd.org>
@@ -57,6 +57,7 @@ ofpclient(struct parse_result *res, struct passwd *pw)
struct switch_connection con;
struct switchd sc;
int s, timeout;
+ struct sockaddr_un *un;
memset(&sc, 0, sizeof(sc));
sc.sc_tap = -1;
@@ -93,6 +94,17 @@ ofpclient(struct parse_result *res, struct passwd *pw)
con.con_fd = s;
break;
+ case SWITCH_CONN_LOCAL:
+ un = (struct sockaddr_un *)&res->uri.swa_addr;
+
+ if (strncmp(un->sun_path, "/dev/switch",
+ strlen("/dev/switch")) != 0)
+ fatalx("device path not supported");
+
+ if ((s = open(un->sun_path, O_RDWR | O_NONBLOCK)) == -1)
+ fatalx("failed to open %s", un->sun_path);
+ con.con_fd = s;
+ break;
default:
fatalx("connect type not supported");
}
@@ -206,6 +218,12 @@ ofpclient_read(struct switch_connection *con, int timeout)
&con->con_peer, &con->con_local, oh, ibuf, oh->oh_version) != 0)
fatal("ofp_validate");
+ if (con->con_state == OFP_STATE_CLOSED) {
+ con->con_version = oh->oh_version;
+ ofp_recv_hello(con->con_sc, con, oh, ibuf);
+ con->con_state = OFP_STATE_ESTABLISHED;
+ }
+
ibuf_free(ibuf);
}
diff --git a/usr.sbin/switchctl/parser.c b/usr.sbin/switchctl/parser.c
index 02870e560bd..01657a938ca 100644
--- a/usr.sbin/switchctl/parser.c
+++ b/usr.sbin/switchctl/parser.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.c,v 1.9 2018/10/15 11:30:37 florian Exp $ */
+/* $OpenBSD: parser.c,v 1.10 2018/10/21 21:10:24 akoshibe Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@@ -444,7 +444,13 @@ match_token(char *word, const struct token table[], int level)
res.uri.swa_type = SWITCH_CONN_TCP;
else if (strncmp(word, "tls:", len) == 0)
res.uri.swa_type = SWITCH_CONN_TLS;
- else {
+ else if (strncmp(word, "/dev", len) == 0) {
+ res.uri.swa_type = SWITCH_CONN_LOCAL;
+ parse_addr(word, &res.uri.swa_addr);
+ match++;
+ t = &table[i];
+ break;
+ } else {
/* set the default */
res.uri.swa_type = SWITCH_CONN_TCP;
len = 0;
diff --git a/usr.sbin/switchctl/switchctl.8 b/usr.sbin/switchctl/switchctl.8
index bc6c6c7da31..9874e7a6fde 100644
--- a/usr.sbin/switchctl/switchctl.8
+++ b/usr.sbin/switchctl/switchctl.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: switchctl.8,v 1.5 2016/11/15 09:30:03 jmc Exp $
+.\" $OpenBSD: switchctl.8,v 1.6 2018/10/21 21:10:24 akoshibe Exp $
.\"
.\" Copyright (c) 2007-2015 Reyk Floeter <reyk@openbsd.org>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: November 15 2016 $
+.Dd $Mdocdate: October 21 2018 $
.Dt SWITCHCTL 8
.Os
.Sh NAME
@@ -69,7 +69,9 @@ Close the client connection to a remote switch or a
.Xr switch 4
control device.
.It Cm dump Ar address request
-Request information from a remote switch.
+Request information from a remote switch or a
+.Xr switch 4
+control device.
.Nm
will send an OpenFlow request to the remote switch that is specified by
.Ar address .
diff --git a/usr.sbin/switchctl/switchctl.c b/usr.sbin/switchctl/switchctl.c
index 2d57e47300c..6b828a22901 100644
--- a/usr.sbin/switchctl/switchctl.c
+++ b/usr.sbin/switchctl/switchctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: switchctl.c,v 1.7 2017/01/31 05:53:08 jsg Exp $ */
+/* $OpenBSD: switchctl.c,v 1.8 2018/10/21 21:10:24 akoshibe Exp $ */
/*
* Copyright (c) 2007-2015 Reyk Floeter <reyk@openbsd.org>
@@ -122,11 +122,13 @@ main(int argc, char *argv[])
/*
* pledge in switchctl:
* stdio - for malloc and basic I/O including events.
- * dns - for parsehostport() in the device spec.
+ * rpath - for reading from the /dev/switch device.
+ * wpath - for accessing the /dev/switch device.
* inet - for handling tcp connections with OpenFlow peers.
* unix - for opening the control socket.
+ * dns - for parsehostport() in the device spec.
*/
- if (pledge("stdio dns inet unix", NULL) == -1)
+ if (pledge("stdio rpath wpath inet unix dns", NULL) == -1)
err(1, "pledge");
log_init(quiet ? 0 : 2, LOG_USER);