vport: Extract common functions for virtual devices.
authorJesse Gross <jesse@nicira.com>
Tue, 11 May 2010 00:40:22 +0000 (17:40 -0700)
committerJesse Gross <jesse@nicira.com>
Tue, 18 May 2010 19:55:42 +0000 (12:55 -0700)
Pull some generic implementations of vport functions out of the
GRE vport so they can be used by others.

Also move the code to set the MTUs of internal devices to the minimum
of attached devices to the generic vport_set_mtu layer.

datapath/Modules.mk
datapath/linux-2.6/.gitignore
datapath/vport-generic.c [new file with mode: 0644]
datapath/vport-generic.h [new file with mode: 0644]
datapath/vport-gre.c
datapath/vport-internal_dev.c
datapath/vport.c
datapath/vport.h

index ab9ae29..3777743 100644 (file)
@@ -18,6 +18,7 @@ openvswitch_sources = \
        flow.c \
        table.c \
        vport.c \
+       vport-generic.c \
        vport-gre.c \
        vport-internal_dev.c \
        vport-netdev.c
@@ -31,6 +32,7 @@ openvswitch_headers = \
        odp-compat.h \
        table.h \
        vport.h \
+       vport-generic.h \
        vport-internal_dev.h \
        vport-netdev.h
 
index 1755126..d8b4a25 100644 (file)
@@ -27,6 +27,7 @@
 /table.c
 /tmp
 /veth.c
+/vport-generic.c
 /vport-gre.c
 /vport-internal_dev.c
 /vport-netdev.c
diff --git a/datapath/vport-generic.c b/datapath/vport-generic.c
new file mode 100644 (file)
index 0000000..72909d9
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2010 Nicira Networks.
+ * Distributed under the terms of the GNU GPL version 2.
+ *
+ * Significant portions of this file may be copied from parts of the Linux
+ * kernel, by Linus Torvalds and others.
+ */
+
+#include <linux/etherdevice.h>
+
+#include "vport-generic.h"
+
+void
+vport_gen_rand_ether_addr(u8 *addr)
+{
+       random_ether_addr(addr);
+
+       /* Set the OUI to the Nicira one. */
+       addr[0] = 0x00;
+       addr[1] = 0x23;
+       addr[2] = 0x20;
+
+       /* Set the top bit to indicate random address. */
+       addr[3] |= 0x80;
+}
+
+unsigned
+vport_gen_get_dev_flags(const struct vport *vport)
+{
+       return IFF_UP | IFF_RUNNING | IFF_LOWER_UP;
+}
+
+int
+vport_gen_is_running(const struct vport *vport)
+{
+       return 1;
+}
+
+unsigned char
+vport_gen_get_operstate(const struct vport *vport)
+{
+       return IF_OPER_UP;
+}
diff --git a/datapath/vport-generic.h b/datapath/vport-generic.h
new file mode 100644 (file)
index 0000000..8bda5ad
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2010 Nicira Networks.
+ * Distributed under the terms of the GNU GPL version 2.
+ *
+ * Significant portions of this file may be copied from parts of the Linux
+ * kernel, by Linus Torvalds and others.
+ */
+
+#ifndef VPORT_GENERIC_H
+#define VPORT_GENERIC_H 1
+
+#include "vport.h"
+
+void vport_gen_rand_ether_addr(u8 *addr);
+unsigned vport_gen_get_dev_flags(const struct vport *);
+int vport_gen_is_running(const struct vport *);
+unsigned char vport_gen_get_operstate(const struct vport *);
+
+#endif /* vport-generic.h */
index bd6d4a3..dbfc100 100644 (file)
@@ -32,6 +32,7 @@
 #include "openvswitch/gre.h"
 #include "table.h"
 #include "vport.h"
+#include "vport-generic.h"
 
 /* The absolute minimum fragment size.  Note that there are many other
  * definitions of the minimum MTU. */
@@ -1218,7 +1219,7 @@ gre_create(const char *name, const void __user *config)
                goto error_free_vport;
        }
 
-       vport_gen_ether_addr(gre_vport->mutable->eth_addr);
+       vport_gen_rand_ether_addr(gre_vport->mutable->eth_addr);
        gre_vport->mutable->mtu = ETH_DATA_LEN;
 
        err = set_config(NULL, gre_vport->mutable, config);
@@ -1321,7 +1322,6 @@ gre_set_mtu(struct vport *vport, int mtu)
 {
        struct gre_vport *gre_vport = gre_vport_priv(vport);
        struct mutable_config *mutable;
-       struct dp_port *dp_port;
 
        mutable = kmemdup(gre_vport->mutable, sizeof(struct mutable_config), GFP_KERNEL);
        if (!mutable)
@@ -1330,10 +1330,6 @@ gre_set_mtu(struct vport *vport, int mtu)
        mutable->mtu = mtu;
        assign_config_rcu(vport, mutable);
 
-       dp_port = vport_get_dp_port(vport);
-       if (dp_port)
-               set_internal_devs_mtu(dp_port->dp);
-
        return 0;
 }
 
@@ -1368,24 +1364,6 @@ gre_get_addr(const struct vport *vport)
        return rcu_dereference(gre_vport->mutable)->eth_addr;
 }
 
-static unsigned
-gre_get_dev_flags(const struct vport *vport)
-{
-       return IFF_UP | IFF_RUNNING | IFF_LOWER_UP;
-}
-
-static int
-gre_is_running(const struct vport *vport)
-{
-       return 1;
-}
-
-static unsigned char
-gre_get_operstate(const struct vport *vport)
-{
-       return IF_OPER_UP;
-}
-
 static int
 gre_get_mtu(const struct vport *vport)
 {
@@ -1405,9 +1383,9 @@ struct vport_ops gre_vport_ops = {
        .set_addr       = gre_set_addr,
        .get_name       = gre_get_name,
        .get_addr       = gre_get_addr,
-       .get_dev_flags  = gre_get_dev_flags,
-       .is_running     = gre_is_running,
-       .get_operstate  = gre_get_operstate,
+       .get_dev_flags  = vport_gen_get_dev_flags,
+       .is_running     = vport_gen_is_running,
+       .get_operstate  = vport_gen_get_operstate,
        .get_mtu        = gre_get_mtu,
        .send           = gre_send,
 };
index 88d3444..d8e57fe 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "datapath.h"
 #include "openvswitch/internal_dev.h"
+#include "vport-generic.h"
 #include "vport-internal_dev.h"
 #include "vport-netdev.h"
 
@@ -233,7 +234,7 @@ do_setup(struct net_device *netdev)
        netdev->features = NETIF_F_LLTX | NETIF_F_SG | NETIF_F_HIGHDMA
                                | NETIF_F_HW_CSUM | NETIF_F_TSO;
 
-       vport_gen_ether_addr(netdev->dev_addr);
+       vport_gen_rand_ether_addr(netdev->dev_addr);
 }
 
 static struct vport *
index 691ab84..f1c78b1 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/compat.h>
 
 #include "vport.h"
+#include "vport-internal_dev.h"
 
 extern struct vport_ops netdev_vport_ops;
 extern struct vport_ops internal_vport_ops;
@@ -882,9 +883,20 @@ vport_set_mtu(struct vport *vport, int mtu)
        if (mtu < 68)
                return -EINVAL;
 
-       if (vport->ops->set_mtu)
-               return vport->ops->set_mtu(vport, mtu);
-       else
+       if (vport->ops->set_mtu) {
+               int ret;
+
+               ret = vport->ops->set_mtu(vport, mtu);
+
+               if (!ret && !is_internal_vport(vport)) {
+                       struct dp_port *dp_port = vport_get_dp_port(vport);
+
+                       if (dp_port)
+                               set_internal_devs_mtu(dp_port->dp);
+               }
+
+               return ret;
+       } else
                return -EOPNOTSUPP;
 }
 
@@ -1216,25 +1228,3 @@ vport_record_error(struct vport *vport, enum vport_err_type err_type)
                spin_unlock_bh(&vport->err_stats.lock);
        }
 }
-
-/**
- *     vport_gen_ether_addr - generate an Ethernet address
- *
- * @addr: location to store generated address
- *
- * Generates a random Ethernet address for use when creating a device that
- * has no natural address.
- */
-void
-vport_gen_ether_addr(u8 *addr)
-{
-       random_ether_addr(addr);
-
-       /* Set the OUI to the Nicira one. */
-       addr[0] = 0x00;
-       addr[1] = 0x23;
-       addr[2] = 0x20;
-
-       /* Set the top bit to indicate random address. */
-       addr[3] |= 0x80;
-}
index a26f232..baa9432 100644 (file)
@@ -236,6 +236,5 @@ vport_from_priv(const void *priv)
 
 void vport_receive(struct vport *, struct sk_buff *);
 void vport_record_error(struct vport *, enum vport_err_type err_type);
-void vport_gen_ether_addr(u8 *addr);
 
 #endif /* vport.h */