[ovs-dev] [PATCH 3/7] add lib/netdev-windows.c

Ankur Sharma ankursharma at vmware.com
Fri Oct 3 23:57:33 UTC 2014


Acked-by: Ankur Sharma <ankursharma at vmware.com>
________________________________
From: Nithin Raju
Sent: Friday, October 3, 2014 4:55 PM
To: Ankur Sharma
Subject: Fwd: [PATCH 3/7] add lib/netdev-windows.c



Begin forwarded message:

From: Nithin Raju <nithin at vmware.com<mailto:nithin at vmware.com>>
Subject: [PATCH 3/7] add lib/netdev-windows.c
Date: September 30, 2014 6:00:03 PM PDT
To: <dev at openvswitch.org<mailto:dev at openvswitch.org>>
Cc: Nithin Raju <nithin at vmware.com<mailto:nithin at vmware.com>>

In this patch, we add a lib/netdev-windows.c which mostly contains stub
code and in subsequent patches, would use the netlink interface to query
netdev information for a vport.

The code implements netdev functionality for "internal" and "system"
types of vports.

Signed-off-by: Nithin Raju <nithin at vmware.com<mailto:nithin at vmware.com>>
---
lib/automake.mk       |    1 +
lib/netdev-provider.h |    9 ++-
lib/netdev-windows.c  |  137 +++++++++++++++++++++++++++++++++++++++++++++++++
lib/netdev.c          |    5 ++
4 files changed, 149 insertions(+), 3 deletions(-)
create mode 100644 lib/netdev-windows.c

diff --git a/lib/automake.mk b/lib/automake.mk
index c44a77f..b1d40b9 100644
--- a/lib/automake.mk
+++ b/lib/automake.mk
@@ -334,6 +334,7 @@ if WIN32
lib_libopenvswitch_la_SOURCES += \
lib/dpif-netlink.c \
lib/dpif-netlink.h \
+ lib/netdev-windows.c \
lib/netlink-notifier.c \
lib/netlink-notifier.h \
lib/netlink-protocol.h \
diff --git a/lib/netdev-provider.h b/lib/netdev-provider.h
index 0e4cda5..af9ea3c 100644
--- a/lib/netdev-provider.h
+++ b/lib/netdev-provider.h
@@ -705,12 +705,15 @@ struct netdev_class {
int netdev_register_provider(const struct netdev_class *);
int netdev_unregister_provider(const char *type);

-extern const struct netdev_class netdev_linux_class;
-extern const struct netdev_class netdev_internal_class;
-extern const struct netdev_class netdev_tap_class;
#if defined(__FreeBSD__) || defined(__NetBSD__)
extern const struct netdev_class netdev_bsd_class;
+#elif defined(_WIN32)
+extern const struct netdev_class netdev_windows_class;
+#else
+extern const struct netdev_class netdev_linux_class;
#endif
+extern const struct netdev_class netdev_internal_class;
+extern const struct netdev_class netdev_tap_class;

#ifdef  __cplusplus
}
diff --git a/lib/netdev-windows.c b/lib/netdev-windows.c
new file mode 100644
index 0000000..33209b1
--- /dev/null
+++ b/lib/netdev-windows.c
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2014 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+#include <config.h>
+#include <errno.h>
+
+#include <net/if.h>
+
+#include "coverage.h"
+#include "fatal-signal.h"
+#include "netdev-provider.h"
+#include "ofpbuf.h"
+#include "poll-loop.h"
+#include "shash.h"
+#include "svec.h"
+#include "vlog.h"
+#include "odp-netlink.h"
+#include "netlink-socket.h"
+#include "netlink.h"
+
+VLOG_DEFINE_THIS_MODULE(netdev_windows);
+static struct vlog_rate_limit error_rl = VLOG_RATE_LIMIT_INIT(9999, 5);
+
+enum {
+    VALID_ETHERADDR         = 1 << 0,
+    VALID_MTU               = 1 << 1,
+    VALID_IFFLAG            = 1 << 5,
+};
+
+/* Caches the information of a netdev. */
+struct netdev_windows {
+    struct netdev up;
+    int32_t dev_type;
+    uint32_t port_no;
+
+    unsigned int change_seq;
+
+    unsigned int cache_valid;
+    int ifindex;
+    uint8_t mac[ETH_ADDR_LEN];
+    uint32_t mtu;
+    unsigned int ifi_flags;
+};
+
+/* Utility structure for netdev commands. */
+struct netdev_windows_netdev_info {
+    /* Generic Netlink header. */
+    uint8_t cmd;
+
+    /* Information that is relevant to ovs. */
+    uint32_t dp_ifindex;
+    uint32_t port_no;
+    uint32_t ovs_type;
+
+    /* General information of a network device. */
+    const char *name;
+    uint8_t mac_address[ETH_ADDR_LEN];
+    uint32_t mtu;
+    uint32_t ifi_flags;
+};
+
+static int
+netdev_windows_init(void)
+{
+    return EINVAL;
+}
+
+static struct netdev *
+netdev_windows_alloc(void)
+{
+    return NULL;
+}
+
+static int
+netdev_windows_system_construct(struct netdev *netdev_)
+{
+    return EINVAL;
+}
+
+static void
+netdev_windows_dealloc(struct netdev *netdev_)
+{
+}
+
+static int
+netdev_windows_get_etheraddr(const struct netdev *netdev_, uint8_t mac[6])
+{
+    return EINVAL;
+}
+
+static int
+netdev_windows_get_mtu(const struct netdev *netdev_, int *mtup)
+{
+    return EINVAL;
+}
+
+
+static int
+netdev_windows_internal_construct(struct netdev *netdev_)
+{
+    return netdev_windows_system_construct(netdev_);
+}
+
+
+#define NETDEV_WINDOWS_CLASS(NAME, CONSTRUCT)                           \
+{                                                                       \
+    .type               = NAME,                                         \
+    .init               = netdev_windows_init,                          \
+    .alloc              = netdev_windows_alloc,                         \
+    .construct          = CONSTRUCT,                                    \
+    .dealloc            = netdev_windows_dealloc,                       \
+    .get_etheraddr      = netdev_windows_get_etheraddr,                 \
+}
+
+const struct netdev_class netdev_windows_class =
+    NETDEV_WINDOWS_CLASS(
+        "system",
+        netdev_windows_system_construct);
+
+const struct netdev_class netdev_internal_class =
+    NETDEV_WINDOWS_CLASS(
+        "internal",
+        netdev_windows_internal_construct);
diff --git a/lib/netdev.c b/lib/netdev.c
index a9ad7d1..670bd62 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -144,6 +144,11 @@ netdev_initialize(void)
        netdev_register_provider(&netdev_tap_class);
        netdev_register_provider(&netdev_bsd_class);
#endif
+#ifdef _WIN32
+        netdev_register_provider(&netdev_windows_class);
+        netdev_register_provider(&netdev_internal_class);
+        netdev_vport_tunnel_register();
+#endif
        netdev_dpdk_register();

        ovsthread_once_done(&once);
--
1.7.4.1


Thanks,
-- Nithin




More information about the dev mailing list