Add a new ndo_update_offloads callback to net_device_ops that allows
devices to compute and update their offload features during feature
updates.

This callback enabling master devices to recompute their features
based on current slave device configuration. This is particularly
useful for bonding, bridging, team, and failover devices that need
to aggregate features from their lower devices.

The callback is optional and only implemented by devices that need
dynamic offload feature computation.

Signed-off-by: Hangbin Liu <[email protected]>
---
 include/linux/netdevice.h | 7 +++++++
 net/core/dev.c            | 3 +++
 2 files changed, 10 insertions(+)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index d4e6e00bb90a..1169091ccb9a 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1281,6 +1281,12 @@ struct netdev_net_notifier {
  *     constraints, and returns the resulting flags. Must not modify
  *     the device state.
  *
+ * void (*ndo_update_offloads)(struct net_device *dev);
+ *     Called during feature update to allow device to compute and update
+ *     offload features (like vlan_features, hw_enc_features) based on
+ *     current lower device configuration. Typically used by master
+ *     devices to aggregate features from slave devices.
+ *
  * int (*ndo_set_features)(struct net_device *dev, netdev_features_t features);
  *     Called to update device configuration to new features. Passed
  *     feature set might be less than what was returned by ndo_fix_features()).
@@ -1558,6 +1564,7 @@ struct net_device_ops {
                                                        struct sock *sk);
        netdev_features_t       (*ndo_fix_features)(struct net_device *dev,
                                                    netdev_features_t features);
+       void                    (*ndo_update_offloads)(struct net_device *dev);
        int                     (*ndo_set_features)(struct net_device *dev,
                                                    netdev_features_t features);
        int                     (*ndo_neigh_construct)(struct net_device *dev,
diff --git a/net/core/dev.c b/net/core/dev.c
index 096b3ff13f6b..d05837c0713a 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -10982,6 +10982,9 @@ int __netdev_update_features(struct net_device *dev)
        ASSERT_RTNL();
        netdev_ops_assert_locked(dev);
 
+       if (dev->netdev_ops->ndo_update_offloads)
+               dev->netdev_ops->ndo_update_offloads(dev);
+
        features = netdev_get_wanted_features(dev);
 
        if (dev->netdev_ops->ndo_fix_features)
-- 
2.50.1


Reply via email to