From a165b67e53a835c623c13de4a0df5f4d7bc9db25 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 6 Jul 2009 11:02:57 -0700 Subject: [PATCH] dpif-linux: Don't allow arbitrary internal ports to identify a datapath. The userspace tools were allowing the name of any internal port to be used to identify a datapath. This, however, makes it hard to enumerate all the names by which a datapath can be known, and it was never documented or intentional behavior, so this commit disables it. --- datapath/dp_dev.c | 2 +- lib/dpif-linux.c | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/datapath/dp_dev.c b/datapath/dp_dev.c index 34a102a3b..848a27b28 100644 --- a/datapath/dp_dev.c +++ b/datapath/dp_dev.c @@ -124,7 +124,7 @@ static void dp_getinfo(struct net_device *netdev, struct ethtool_drvinfo *info) { struct dp_dev *dp_dev = dp_dev_priv(netdev); strcpy(info->driver, "openvswitch"); - sprintf(info->bus_info, "%d", dp_dev->dp->dp_idx); + sprintf(info->bus_info, "%d.%d", dp_dev->dp->dp_idx, dp_dev->port_no); } static struct ethtool_ops dp_ethtool_ops = { diff --git a/lib/dpif-linux.c b/lib/dpif-linux.c index 417349d8d..8cc213d5d 100644 --- a/lib/dpif-linux.c +++ b/lib/dpif-linux.c @@ -453,9 +453,10 @@ do_ioctl(const struct dpif *dpif_, int cmd, const void *arg) } static int -lookup_minor(const char *name, int *minor) +lookup_minor(const char *name, int *minorp) { struct ethtool_drvinfo drvinfo; + int minor, port_no; struct ifreq ifr; int error; int sock; @@ -485,14 +486,20 @@ lookup_minor(const char *name, int *minor) goto error_close_sock; } - if (!isdigit(drvinfo.bus_info[0])) { - VLOG_WARN("%s ethtool info does not contain an openvswitch minor", - name); + if (sscanf(drvinfo.bus_info, "%d.%d", &minor, &port_no) != 2) { + VLOG_WARN("%s ethtool bus_info has unexpected format", name); error = EPROTOTYPE; goto error_close_sock; + } else if (port_no != ODPP_LOCAL) { + /* This is an Open vSwitch device but not the local port. We + * intentionally support only using the name of the local port as the + * name of a datapath; otherwise, it would be too difficult to + * enumerate all the names of a datapath. */ + error = EOPNOTSUPP; + goto error_close_sock; } - *minor = atoi(drvinfo.bus_info); + *minorp = minor; close(sock); return 0; -- 2.43.0