@@ -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;
Use netdev_feature_xxx helpers to replace the logical operation for netdev features. Signed-off-by: Jian Shen <shenjian15@huawei.com> --- drivers/net/tun.c | 48 ++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-)