]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: wangxun: restrict feature flags for tunnel packets
authorJiawen Wu <jiawenwu@trustnetic.com>
Mon, 21 Apr 2025 02:29:56 +0000 (10:29 +0800)
committerJakub Kicinski <kuba@kernel.org>
Wed, 23 Apr 2025 02:53:35 +0000 (19:53 -0700)
Implement ndo_features_check to restrict Tx checksum offload flags, since
there are some inner layer length and protocols unsupported.

Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
Reviewed-by: Michal Kubiak <michal.kubiak@intel.com>
Link: https://patch.msgid.link/20250421022956.508018-3-jiawenwu@trustnetic.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/wangxun/libwx/wx_lib.c
drivers/net/ethernet/wangxun/libwx/wx_lib.h
drivers/net/ethernet/wangxun/ngbe/ngbe_main.c
drivers/net/ethernet/wangxun/txgbe/txgbe_main.c

index 18422b940dbed6077da7c4850cdba0b6be4509bf..2a808afeb414214702dfd8c296471e88d5953087 100644 (file)
@@ -3000,6 +3000,33 @@ netdev_features_t wx_fix_features(struct net_device *netdev,
 }
 EXPORT_SYMBOL(wx_fix_features);
 
+#define WX_MAX_TUNNEL_HDR_LEN  80
+netdev_features_t wx_features_check(struct sk_buff *skb,
+                                   struct net_device *netdev,
+                                   netdev_features_t features)
+{
+       struct wx *wx = netdev_priv(netdev);
+
+       if (!skb->encapsulation)
+               return features;
+
+       if (wx->mac.type == wx_mac_em)
+               return features & ~NETIF_F_CSUM_MASK;
+
+       if (unlikely(skb_inner_mac_header(skb) - skb_transport_header(skb) >
+                    WX_MAX_TUNNEL_HDR_LEN))
+               return features & ~NETIF_F_CSUM_MASK;
+
+       if (skb->inner_protocol_type == ENCAP_TYPE_ETHER &&
+           skb->inner_protocol != htons(ETH_P_IP) &&
+           skb->inner_protocol != htons(ETH_P_IPV6) &&
+           skb->inner_protocol != htons(ETH_P_TEB))
+               return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
+
+       return features;
+}
+EXPORT_SYMBOL(wx_features_check);
+
 void wx_set_ring(struct wx *wx, u32 new_tx_count,
                 u32 new_rx_count, struct wx_ring *temp_ring)
 {
index fdeb0c315b75553824fd7dde3dd479cfe2c8dacd..919f499993089221eeddd7892b572239aefb9316 100644 (file)
@@ -33,6 +33,9 @@ void wx_get_stats64(struct net_device *netdev,
 int wx_set_features(struct net_device *netdev, netdev_features_t features);
 netdev_features_t wx_fix_features(struct net_device *netdev,
                                  netdev_features_t features);
+netdev_features_t wx_features_check(struct sk_buff *skb,
+                                   struct net_device *netdev,
+                                   netdev_features_t features);
 void wx_set_ring(struct wx *wx, u32 new_tx_count,
                 u32 new_rx_count, struct wx_ring *temp_ring);
 
index 9c18203c8ce1eeb4261377c5f1de621d635e7d47..b5022c49dc5ee0a9d7b719986c63adebc39d939e 100644 (file)
@@ -587,6 +587,7 @@ static const struct net_device_ops ngbe_netdev_ops = {
        .ndo_set_rx_mode        = wx_set_rx_mode,
        .ndo_set_features       = wx_set_features,
        .ndo_fix_features       = wx_fix_features,
+       .ndo_features_check     = wx_features_check,
        .ndo_validate_addr      = eth_validate_addr,
        .ndo_set_mac_address    = wx_set_mac,
        .ndo_get_stats64        = wx_get_stats64,
index dcfccc6d963a55d748ffc496340bb1e08d32bc41..f57d84628e071abff8a52368c5e73af3f0a40110 100644 (file)
@@ -579,6 +579,7 @@ static const struct net_device_ops txgbe_netdev_ops = {
        .ndo_set_rx_mode        = wx_set_rx_mode,
        .ndo_set_features       = wx_set_features,
        .ndo_fix_features       = wx_fix_features,
+       .ndo_features_check     = wx_features_check,
        .ndo_validate_addr      = eth_validate_addr,
        .ndo_set_mac_address    = wx_set_mac,
        .ndo_get_stats64        = wx_get_stats64,