lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210929155334.12454-32-shenjian15@huawei.com>
Date:   Wed, 29 Sep 2021 23:51:18 +0800
From:   Jian Shen <shenjian15@...wei.com>
To:     <davem@...emloft.net>, <kuba@...nel.org>, <andrew@...n.ch>,
        <hkallweit1@...il.com>
CC:     <netdev@...r.kernel.org>, <linuxarm@...neuler.org>
Subject: [RFCv2 net-next 031/167] net: tun: use netdev feature helpers

Use netdev_feature_xxx helpers to replace the logical operation
for netdev features.

Signed-off-by: Jian Shen <shenjian15@...wei.com>
---
 drivers/net/tun.c | 48 ++++++++++++++++++++++++++++++-----------------
 1 file changed, 31 insertions(+), 17 deletions(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index d89a9874eb37..9e9cbafc870b 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1083,9 +1083,11 @@ static void tun_net_fix_features(struct net_device *dev,
 				 netdev_features_t *features)
 {
 	struct tun_struct *tun = netdev_priv(dev);
+	netdev_features_t tmp;
 
-	*features = (*features & tun->set_features) |
-			(*features & ~TUN_USER_FEATURES);
+	netdev_feature_and(&tmp, *features, tun->set_features);
+	netdev_feature_clear_bits(TUN_USER_FEATURES, features);
+	netdev_feature_or(features, *features, tmp);
 }
 
 static void tun_set_headroom(struct net_device *dev, int new_hr)
@@ -2727,13 +2729,18 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
 		tun_net_init(dev);
 		tun_flow_init(tun);
 
-		dev->hw_features = NETIF_F_SG | NETIF_F_FRAGLIST |
-				   TUN_USER_FEATURES | NETIF_F_HW_VLAN_CTAG_TX |
-				   NETIF_F_HW_VLAN_STAG_TX;
-		dev->features = dev->hw_features | NETIF_F_LLTX;
-		dev->vlan_features = dev->features &
-				     ~(NETIF_F_HW_VLAN_CTAG_TX |
-				       NETIF_F_HW_VLAN_STAG_TX);
+		netdev_feature_zero(&dev->hw_features);
+		netdev_feature_set_bits(NETIF_F_SG | NETIF_F_FRAGLIST |
+					TUN_USER_FEATURES |
+					NETIF_F_HW_VLAN_CTAG_TX |
+					NETIF_F_HW_VLAN_STAG_TX,
+					&dev->hw_features);
+		netdev_feature_copy(&dev->features, dev->hw_features);
+		netdev_feature_set_bit(NETIF_F_LLTX_BIT, &dev->features);
+		netdev_feature_copy(&dev->vlan_features, dev->features);
+		netdev_feature_clear_bits(NETIF_F_HW_VLAN_CTAG_TX |
+					  NETIF_F_HW_VLAN_STAG_TX,
+					  &dev->vlan_features);
 
 		tun->flags = (tun->flags & ~TUN_FEATURES) |
 			      (ifr->ifr_flags & TUN_FEATURES);
@@ -2795,21 +2802,26 @@ static void tun_get_iff(struct tun_struct *tun, struct ifreq *ifr)
  * privs required. */
 static int set_offload(struct tun_struct *tun, unsigned long arg)
 {
-	netdev_features_t features = 0;
+	netdev_features_t features;
+
+	netdev_feature_zero(&features);
 
 	if (arg & TUN_F_CSUM) {
-		features |= NETIF_F_HW_CSUM;
+		netdev_feature_set_bit(NETIF_F_HW_CSUM_BIT, &features);
 		arg &= ~TUN_F_CSUM;
 
 		if (arg & (TUN_F_TSO4|TUN_F_TSO6)) {
 			if (arg & TUN_F_TSO_ECN) {
-				features |= NETIF_F_TSO_ECN;
+				netdev_feature_set_bit(NETIF_F_TSO_ECN_BIT,
+						       &features);
 				arg &= ~TUN_F_TSO_ECN;
 			}
 			if (arg & TUN_F_TSO4)
-				features |= NETIF_F_TSO;
+				netdev_feature_set_bit(NETIF_F_TSO_BIT,
+						       &features);
 			if (arg & TUN_F_TSO6)
-				features |= NETIF_F_TSO6;
+				netdev_feature_set_bit(NETIF_F_TSO6_BIT,
+						       &features);
 			arg &= ~(TUN_F_TSO4|TUN_F_TSO6);
 		}
 
@@ -2821,9 +2833,11 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
 	if (arg)
 		return -EINVAL;
 
-	tun->set_features = features;
-	tun->dev->wanted_features &= ~TUN_USER_FEATURES;
-	tun->dev->wanted_features |= features;
+	netdev_feature_copy(&tun->set_features, features);
+	netdev_feature_clear_bits(TUN_USER_FEATURES,
+				  &tun->dev->wanted_features);
+	netdev_feature_or(&tun->dev->wanted_features,
+			  tun->dev->wanted_features, features);
 	netdev_update_features(tun->dev);
 
 	return 0;
-- 
2.33.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ