[Devel] [PATCH 2/5] veth: add ability to enable vz-specific features

Andrew Vagin avagin at openvz.org
Thu May 28 04:06:57 PDT 2015


For example, vzethdev filters packages accoding with mac addresses.

Signed-off-by: Andrew Vagin <avagin at openvz.org>
---
 drivers/net/veth.c        |   24 ++++++++++++++++++++++++
 include/uapi/linux/veth.h |    2 ++
 2 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index 04d8d7e..7f64043 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -244,6 +244,29 @@ static void veth_dev_free(struct net_device *dev)
 	free_netdev(dev);
 }
 
+static int vzethdev_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
+{
+	if (!capable(CAP_NET_ADMIN))
+		return -EPERM;
+
+	switch (cmd) {
+	case SIOCSVENET:
+	{
+		struct veth_priv *priv = netdev_priv(dev);
+		struct net_device *rcv;
+
+		rcu_read_lock();
+		rcv = rcu_dereference(priv->peer);
+		if (rcv)
+			rcv->features |= NETIF_F_VENET;
+		dev->features |= NETIF_F_VENET;
+		rcu_read_unlock();
+
+		return 0;
+	}
+	return -ENOTTY;
+}
+
 static const struct net_device_ops veth_netdev_ops = {
 	.ndo_init            = veth_dev_init,
 	.ndo_open            = veth_open,
@@ -252,6 +275,7 @@ static const struct net_device_ops veth_netdev_ops = {
 	.ndo_change_mtu      = veth_change_mtu,
 	.ndo_get_stats64     = veth_get_stats64,
 	.ndo_set_mac_address = eth_mac_addr,
+	.ndo_do_ioctl        = vzethdev_net_ioctl,
 };
 
 #define VETH_FEATURES (NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_ALL_TSO |    \
diff --git a/include/uapi/linux/veth.h b/include/uapi/linux/veth.h
index 6f893ae..27e7795 100644
--- a/include/uapi/linux/veth.h
+++ b/include/uapi/linux/veth.h
@@ -18,4 +18,6 @@ enum {
 #define VETH_INFO_MAX	(__VETH_INFO_MAX - 1)
 };
 
+#define SIOCSVENET	(SIOCDEVPRIVATE + 0xf)
+
 #endif
-- 
1.7.1




More information about the Devel mailing list