diff mbox

[ovs-dev,ovs,V2,06/21] netdev-vport: Add get ifindex implementation

Message ID 1482665989-791-7-git-send-email-paulb@mellanox.com
State Changes Requested
Headers show

Commit Message

Paul Blakey Dec. 25, 2016, 11:39 a.m. UTC
Ifindex is needed for flow offloading using tc, so we
try and get ifindex by the real vport netdev name.

Signed-off-by: Paul Blakey <paulb@mellanox.com>
Reviewed-by: Roi Dayan <roid@mellanox.com>
---
 lib/netdev-vport.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

Comments

Joe Stringer Jan. 5, 2017, 1:32 a.m. UTC | #1
On 25 December 2016 at 03:39, Paul Blakey <paulb@mellanox.com> wrote:
> Ifindex is needed for flow offloading using tc, so we
> try and get ifindex by the real vport netdev name.
>
> Signed-off-by: Paul Blakey <paulb@mellanox.com>
> Reviewed-by: Roi Dayan <roid@mellanox.com>
> ---

As mentioned in my feedback on the cover letter, this is a bit broken because
netdev-vport is also used with userspace datapath and on windows.
diff mbox

Patch

diff --git a/lib/netdev-vport.c b/lib/netdev-vport.c
index 2cde854..04c9d62 100644
--- a/lib/netdev-vport.c
+++ b/lib/netdev-vport.c
@@ -742,6 +742,32 @@  get_stats(const struct netdev *netdev, struct netdev_stats *stats)
     return 0;
 }
 
+static int
+do_get_ifindex(const char *netdev_name)
+{
+    struct ifreq ifr;
+    int error;
+
+    ovs_strzcpy(ifr.ifr_name, netdev_name, sizeof ifr.ifr_name);
+
+    error = af_inet_ioctl(SIOCGIFINDEX, &ifr);
+    if (error) {
+        VLOG_ERR("ioctl(SIOCGIFINDEX) on %s device failed: %s",
+                     netdev_name, ovs_strerror(error));
+        return -error;
+    }
+    return ifr.ifr_ifindex;
+}
+
+static int
+netdev_vport_get_ifindex(const struct netdev *netdev_)
+{
+    char buf[32];
+    const char *name = netdev_vport_get_dpif_port(netdev_, buf, sizeof(buf));
+
+    return do_get_ifindex(name);
+}
+
 
 #define VPORT_FUNCTIONS(GET_CONFIG, SET_CONFIG,             \
                         GET_TUNNEL_CONFIG, GET_STATUS,      \
@@ -771,7 +797,7 @@  get_stats(const struct netdev *netdev, struct netdev_stats *stats)
     netdev_vport_get_etheraddr,                             \
     NULL,                       /* get_mtu */               \
     NULL,                       /* set_mtu */               \
-    NULL,                       /* get_ifindex */           \
+    netdev_vport_get_ifindex,                               \
     NULL,                       /* get_carrier */           \
     NULL,                       /* get_carrier_resets */    \
     NULL,                       /* get_miimon */            \