Initialize net_device_ops ndo_bpf callback with ieee80211_xdp routine
in order to load a bpf program into low level driver XDP rx hook

Signed-off-by: Lorenzo Bianconi <lorenzo.bianc...@redhat.com>
---
 include/net/mac80211.h    |  2 ++
 net/mac80211/driver-ops.h | 11 +++++++++++
 net/mac80211/iface.c      | 14 ++++++++++++++
 3 files changed, 27 insertions(+)

diff --git a/include/net/mac80211.h b/include/net/mac80211.h
index 71985e95d2d9..a91f1733ce43 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -3623,6 +3623,7 @@ enum ieee80211_reconfig_type {
  *     skb is always a real frame, head may or may not be an A-MSDU.
  * @get_ftm_responder_stats: Retrieve FTM responder statistics, if available.
  *     Statistics should be cumulative, currently no way to reset is provided.
+ * @xdp: main XDP handler
  */
 struct ieee80211_ops {
        void (*tx)(struct ieee80211_hw *hw,
@@ -3911,6 +3912,7 @@ struct ieee80211_ops {
        int (*get_ftm_responder_stats)(struct ieee80211_hw *hw,
                                       struct ieee80211_vif *vif,
                                       struct cfg80211_ftm_responder_stats 
*ftm_stats);
+       int (*xdp)(struct ieee80211_hw *hw, struct netdev_bpf *xdp);
 };
 
 /**
diff --git a/net/mac80211/driver-ops.h b/net/mac80211/driver-ops.h
index 0b1747a2313d..48cad0ae0593 100644
--- a/net/mac80211/driver-ops.h
+++ b/net/mac80211/driver-ops.h
@@ -1278,4 +1278,15 @@ static inline void drv_del_nan_func(struct 
ieee80211_local *local,
        trace_drv_return_void(local);
 }
 
+static inline int drv_xdp(struct ieee80211_local *local,
+                         struct netdev_bpf *xdp)
+{
+       might_sleep();
+
+       if (!local->ops->xdp)
+               return -EOPNOTSUPP;
+
+       return local->ops->xdp(&local->hw, xdp);
+}
+
 #endif /* __MAC80211_DRIVER_OPS */
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index 5836ddeac9e3..e21971f7c652 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -1163,6 +1163,19 @@ ieee80211_get_stats64(struct net_device *dev, struct 
rtnl_link_stats64 *stats)
        }
 }
 
+static int ieee80211_xdp(struct net_device *dev, struct netdev_bpf *xdp)
+{
+       struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+
+       switch (xdp->command) {
+       case XDP_QUERY_PROG:
+       case XDP_SETUP_PROG:
+               return drv_xdp(sdata->local, xdp);
+       default:
+               return -EINVAL;
+       }
+}
+
 static const struct net_device_ops ieee80211_dataif_ops = {
        .ndo_open               = ieee80211_open,
        .ndo_stop               = ieee80211_stop,
@@ -1172,6 +1185,7 @@ static const struct net_device_ops ieee80211_dataif_ops = 
{
        .ndo_set_mac_address    = ieee80211_change_mac,
        .ndo_select_queue       = ieee80211_netdev_select_queue,
        .ndo_get_stats64        = ieee80211_get_stats64,
+       .ndo_bpf                = ieee80211_xdp,
 };
 
 static u16 ieee80211_monitor_select_queue(struct net_device *dev,
-- 
2.19.1

Reply via email to