summaryrefslogtreecommitdiffstats
path: root/drivers/net/macvtap.c
diff options
context:
space:
mode:
authorVlad Yasevich <vyasevic@redhat.com>2013-06-25 16:04:21 -0400
committerDavid S. Miller <davem@davemloft.net>2013-06-25 19:44:56 -0400
commit2be5c76794b0e570aa87b012df5ac864ce668a74 (patch)
treece0bb01b91bad831e290626308b886e9d0d884d2 /drivers/net/macvtap.c
parentac4e4af1e59e16a018527ffa58d9d3f30bb96ca9 (diff)
macvtap: Let TUNSETOFFLOAD actually controll offload features.
When the user issues TUNSETOFFLOAD ioctl, macvtap does not do anything other then to verify arguments. This patch adds functionality to allow users to actually control offload features. NETIF_F_GSO and NETIF_F_GRO are always on, but the rest of the features can be controlled. Signed-off-by: Vlad Yasevich <vyasevic@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/macvtap.c')
-rw-r--r--drivers/net/macvtap.c65
1 files changed, 64 insertions, 1 deletions
diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
index d7856a8f589a..7eab01975ed1 100644
--- a/drivers/net/macvtap.c
+++ b/drivers/net/macvtap.c
@@ -65,6 +65,9 @@ static struct cdev macvtap_cdev;
65 65
66static const struct proto_ops macvtap_socket_ops; 66static const struct proto_ops macvtap_socket_ops;
67 67
68#define TUN_OFFLOADS (NETIF_F_HW_CSUM | NETIF_F_TSO_ECN | NETIF_F_TSO | \
69 NETIF_F_TSO6 | NETIF_F_UFO)
70#define RX_OFFLOADS (NETIF_F_GRO | NETIF_F_LRO)
68/* 71/*
69 * RCU usage: 72 * RCU usage:
70 * The macvtap_queue and the macvlan_dev are loosely coupled, the 73 * The macvtap_queue and the macvlan_dev are loosely coupled, the
@@ -349,6 +352,11 @@ static int macvtap_newlink(struct net *src_net,
349 struct macvlan_dev *vlan = netdev_priv(dev); 352 struct macvlan_dev *vlan = netdev_priv(dev);
350 INIT_LIST_HEAD(&vlan->queue_list); 353 INIT_LIST_HEAD(&vlan->queue_list);
351 354
355 /* Since macvlan supports all offloads by default, make
356 * tap support all offloads also.
357 */
358 vlan->tap_features = TUN_OFFLOADS;
359
352 /* Don't put anything that may fail after macvlan_common_newlink 360 /* Don't put anything that may fail after macvlan_common_newlink
353 * because we can't undo what it does. 361 * because we can't undo what it does.
354 */ 362 */
@@ -958,6 +966,58 @@ static int macvtap_ioctl_set_queue(struct file *file, unsigned int flags)
958 return ret; 966 return ret;
959} 967}
960 968
969static int set_offload(struct macvtap_queue *q, unsigned long arg)
970{
971 struct macvlan_dev *vlan;
972 netdev_features_t features;
973 netdev_features_t feature_mask = 0;
974
975 vlan = rtnl_dereference(q->vlan);
976 if (!vlan)
977 return -ENOLINK;
978
979 features = vlan->dev->features;
980
981 if (arg & TUN_F_CSUM) {
982 feature_mask = NETIF_F_HW_CSUM;
983
984 if (arg & (TUN_F_TSO4 | TUN_F_TSO6)) {
985 if (arg & TUN_F_TSO_ECN)
986 feature_mask |= NETIF_F_TSO_ECN;
987 if (arg & TUN_F_TSO4)
988 feature_mask |= NETIF_F_TSO;
989 if (arg & TUN_F_TSO6)
990 feature_mask |= NETIF_F_TSO6;
991 }
992
993 if (arg & TUN_F_UFO)
994 feature_mask |= NETIF_F_UFO;
995 }
996
997 /* tun/tap driver inverts the usage for TSO offloads, where
998 * setting the TSO bit means that the userspace wants to
999 * accept TSO frames and turning it off means that user space
1000 * does not support TSO.
1001 * For macvtap, we have to invert it to mean the same thing.
1002 * When user space turns off TSO, we turn off GSO/LRO so that
1003 * user-space will not receive TSO frames.
1004 */
1005 if (feature_mask & (NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_UFO))
1006 features |= RX_OFFLOADS;
1007 else
1008 features &= ~RX_OFFLOADS;
1009
1010 /* tap_features are the same as features on tun/tap and
1011 * reflect user expectations.
1012 */
1013 vlan->tap_features = vlan->dev->features &
1014 (feature_mask | ~TUN_OFFLOADS);
1015 vlan->set_features = features;
1016 netdev_update_features(vlan->dev);
1017
1018 return 0;
1019}
1020
961/* 1021/*
962 * provide compatibility with generic tun/tap interface 1022 * provide compatibility with generic tun/tap interface
963 */ 1023 */
@@ -1050,7 +1110,10 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
1050 got enabled for forwarded frames */ 1110 got enabled for forwarded frames */
1051 if (!(q->flags & IFF_VNET_HDR)) 1111 if (!(q->flags & IFF_VNET_HDR))
1052 return -EINVAL; 1112 return -EINVAL;
1053 return 0; 1113 rtnl_lock();
1114 ret = set_offload(q, arg);
1115 rtnl_unlock();
1116 return ret;
1054 1117
1055 default: 1118 default:
1056 return -EINVAL; 1119 return -EINVAL;