driver/net/tun: Added features for USO.
authorAndrew Melnychenko <andrew@daynix.com>
Wed, 7 Dec 2022 11:35:55 +0000 (13:35 +0200)
committerDavid S. Miller <davem@davemloft.net>
Mon, 12 Dec 2022 09:29:56 +0000 (09:29 +0000)
Added support for USO4 and USO6.
For now, to "enable" USO, it's required to set both USO4 and USO6 simultaneously.
USO enables NETIF_F_GSO_UDP_L4.

Signed-off-by: Andrew Melnychenko <andrew@daynix.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/tap.c
drivers/net/tun.c

index 9e75ed3f08ce5b442f55a11f22ca3cc0567cdfce..a2be1994b389459e5bad3f745fee246521bdabd6 100644 (file)
@@ -957,6 +957,10 @@ static int set_offload(struct tap_queue *q, unsigned long arg)
                        if (arg & TUN_F_TSO6)
                                feature_mask |= NETIF_F_TSO6;
                }
+
+               /* TODO: for now USO4 and USO6 should work simultaneously */
+               if ((arg & (TUN_F_USO4 | TUN_F_USO6)) == (TUN_F_USO4 | TUN_F_USO6))
+                       features |= NETIF_F_GSO_UDP_L4;
        }
 
        /* tun/tap driver inverts the usage for TSO offloads, where
@@ -967,7 +971,8 @@ static int set_offload(struct tap_queue *q, unsigned long arg)
         * When user space turns off TSO, we turn off GSO/LRO so that
         * user-space will not receive TSO frames.
         */
-       if (feature_mask & (NETIF_F_TSO | NETIF_F_TSO6))
+       if (feature_mask & (NETIF_F_TSO | NETIF_F_TSO6) ||
+           (feature_mask & (TUN_F_USO4 | TUN_F_USO6)) == (TUN_F_USO4 | TUN_F_USO6))
                features |= RX_OFFLOADS;
        else
                features &= ~RX_OFFLOADS;
@@ -1091,7 +1096,8 @@ static long tap_ioctl(struct file *file, unsigned int cmd,
        case TUNSETOFFLOAD:
                /* let the user check for future flags */
                if (arg & ~(TUN_F_CSUM | TUN_F_TSO4 | TUN_F_TSO6 |
-                           TUN_F_TSO_ECN | TUN_F_UFO))
+                           TUN_F_TSO_ECN | TUN_F_UFO |
+                           TUN_F_USO4 | TUN_F_USO6))
                        return -EINVAL;
 
                rtnl_lock();
index b4baa2001a639f30f8fb1c7a349e3f7097d81274..a7d17c680f4a013d1efa7f452faee5e18d9ed07c 100644 (file)
@@ -185,7 +185,7 @@ struct tun_struct {
        struct net_device       *dev;
        netdev_features_t       set_features;
 #define TUN_USER_FEATURES (NETIF_F_HW_CSUM|NETIF_F_TSO_ECN|NETIF_F_TSO| \
-                         NETIF_F_TSO6)
+                         NETIF_F_TSO6 | NETIF_F_GSO_UDP_L4)
 
        int                     align;
        int                     vnet_hdr_sz;
@@ -2878,6 +2878,12 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
                }
 
                arg &= ~TUN_F_UFO;
+
+               /* TODO: for now USO4 and USO6 should work simultaneously */
+               if (arg & TUN_F_USO4 && arg & TUN_F_USO6) {
+                       features |= NETIF_F_GSO_UDP_L4;
+                       arg &= ~(TUN_F_USO4 | TUN_F_USO6);
+               }
        }
 
        /* This gives the user a way to test for new features in future by