From: Ben Pfaff Date: Wed, 18 Mar 2009 17:03:14 +0000 (-0700) Subject: dpctl: Allow datapath names to be given in place of switch names. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e4e3f59bf4eec797cb85e739870bfbcbe06d734c;p=openvswitch dpctl: Allow datapath names to be given in place of switch names. It is convenient to be able to type, e.g., "dpctl show xenbr0" instead of "dpctl show unix:/var/run/xenbr0.mgmt", so this allows this form. --- diff --git a/utilities/dpctl.8.in b/utilities/dpctl.8.in index d72fcf91..6cd548ce 100644 --- a/utilities/dpctl.8.in +++ b/utilities/dpctl.8.in @@ -144,7 +144,15 @@ The specified TCP \fIport\fR (default: 6633) on the given remote .TP \fBunix:\fIfile\fR -The Unix domain server socket named \fIfile\fR. +The Unix domain server socket named \fIfile\fR. + +.IP "\fIfile\fR" +This is short for \fBunix:\fIfile\fR, as long as \fIfile\fR does not +contain a colon. + +.IP \fIdp\fR +This is short for \fBunix:@RUNDIR@/\fIdp\fB.mgmt\fR, as long as +\fIdp\fR does not contain a colon. .RE .TP diff --git a/utilities/dpctl.c b/utilities/dpctl.c index e3cbace1..c2311104 100644 --- a/utilities/dpctl.c +++ b/utilities/dpctl.c @@ -43,10 +43,12 @@ #include #include #include +#include #include #include "command-line.h" #include "compiler.h" +#include "dirs.h" #include "dpif.h" #include "dynamic-string.h" #include "netdev.h" @@ -597,7 +599,48 @@ do_dp_dump_groups(const struct settings *s UNUSED, static void open_vconn(const char *name, struct vconn **vconnp) { - run(vconn_open_block(name, OFP_VERSION, vconnp), "connecting to %s", name); + struct dpif dpif; + struct stat s; + + if (strstr(name, ":")) { + run(vconn_open_block(name, OFP_VERSION, vconnp), + "connecting to %s", name); + } else if (!stat(name, &s) && S_ISSOCK(s.st_mode)) { + char *vconn_name = xasprintf("unix:%s", name); + VLOG_INFO("connecting to %s", vconn_name); + run(vconn_open_block(vconn_name, OFP_VERSION, vconnp), + "connecting to %s", vconn_name); + free(vconn_name); + } else if (!dpif_open(name, &dpif)) { + char dpif_name[IF_NAMESIZE + 1]; + char *socket_name; + char *vconn_name; + + run(dpif_get_name(&dpif, dpif_name, sizeof dpif_name), + "obtaining name of %s", dpif_name); + dpif_close(&dpif); + if (strcmp(dpif_name, name)) { + VLOG_INFO("datapath %s is named %s", name, dpif_name); + } + + socket_name = xasprintf("%s/%s.mgmt", ofp_rundir, dpif_name); + if (stat(socket_name, &s)) { + ofp_fatal(errno, "cannot connect to %s: stat failed on %s", + name, socket_name); + } else if (!S_ISSOCK(s.st_mode)) { + ofp_fatal(0, "cannot connect to %s: %s is not a socket", + name, socket_name); + } + + vconn_name = xasprintf("unix:%s", socket_name); + VLOG_INFO("connecting to %s", vconn_name); + run(vconn_open_block(vconn_name, OFP_VERSION, vconnp), + "connecting to %s", vconn_name); + free(socket_name); + free(vconn_name); + } else { + ofp_fatal(0, "%s is not a valid connection method", name); + } } static void *