From: Jesse Gross Date: Tue, 11 May 2010 00:40:22 +0000 (-0700) Subject: vport: Extract common functions for virtual devices. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b19e8815add8374089c8a90fd276ba65c151416a;p=openvswitch vport: Extract common functions for virtual devices. 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. --- diff --git a/datapath/Modules.mk b/datapath/Modules.mk index ab9ae299..37777436 100644 --- a/datapath/Modules.mk +++ b/datapath/Modules.mk @@ -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 diff --git a/datapath/linux-2.6/.gitignore b/datapath/linux-2.6/.gitignore index 1755126f..d8b4a256 100644 --- a/datapath/linux-2.6/.gitignore +++ b/datapath/linux-2.6/.gitignore @@ -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 index 00000000..72909d9b --- /dev/null +++ b/datapath/vport-generic.c @@ -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 + +#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 index 00000000..8bda5ad3 --- /dev/null +++ b/datapath/vport-generic.h @@ -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 */ diff --git a/datapath/vport-gre.c b/datapath/vport-gre.c index bd6d4a3c..dbfc1001 100644 --- a/datapath/vport-gre.c +++ b/datapath/vport-gre.c @@ -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, }; diff --git a/datapath/vport-internal_dev.c b/datapath/vport-internal_dev.c index 88d3444c..d8e57fef 100644 --- a/datapath/vport-internal_dev.c +++ b/datapath/vport-internal_dev.c @@ -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 * diff --git a/datapath/vport.c b/datapath/vport.c index 691ab84b..f1c78b11 100644 --- a/datapath/vport.c +++ b/datapath/vport.c @@ -17,6 +17,7 @@ #include #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; -} diff --git a/datapath/vport.h b/datapath/vport.h index a26f232a..baa94324 100644 --- a/datapath/vport.h +++ b/datapath/vport.h @@ -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 */