Offloaded sockets rely on the netdev to transform the transmitted
packets before sending them over the network.
When a packet from an offloaded socket is looped back or
rerouted to a different device we need to detect it and
do the transformation in software

Signed-off-by: Ilya Lesokhin <il...@mellanox.com>
Signed-off-by: Boris Pismenny <bor...@mellanox.com>
---
 include/net/sock.h | 17 +++++++++++++++++
 net/core/dev.c     |  4 ++++
 2 files changed, 21 insertions(+)

diff --git a/include/net/sock.h b/include/net/sock.h
index 9a9047268d37..5397307603ec 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -479,6 +479,9 @@ struct sock {
        void                    (*sk_error_report)(struct sock *sk);
        int                     (*sk_backlog_rcv)(struct sock *sk,
                                                  struct sk_buff *skb);
+       struct sk_buff*         (*sk_offload_check)(struct sock *sk,
+                                                   struct net_device *dev,
+                                                   struct sk_buff *skb);
        void                    (*sk_destruct)(struct sock *sk);
        struct sock_reuseport __rcu     *sk_reuseport_cb;
        struct rcu_head         sk_rcu;
@@ -2324,6 +2327,20 @@ static inline bool sk_fullsock(const struct sock *sk)
        return (1 << sk->sk_state) & ~(TCPF_TIME_WAIT | TCPF_NEW_SYN_RECV);
 }
 
+/* Checks if this SKB belongs to an HW offloaded socket
+ * and whether any SW fallbacks are required based on dev.
+ */
+static inline struct sk_buff *skb_offload_check(struct sk_buff *skb,
+                                               struct net_device *dev)
+{
+       struct sock *sk = skb->sk;
+
+       if (sk && sk_fullsock(sk) && sk->sk_offload_check)
+               skb = sk->sk_offload_check(sk, dev, skb);
+
+       return skb;
+}
+
 /* This helper checks if a socket is a LISTEN or NEW_SYN_RECV
  * SYNACK messages can be attached to either ones (depending on SYNCOOKIE)
  */
diff --git a/net/core/dev.c b/net/core/dev.c
index b0eee49a2489..6a78d9046674 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -3051,6 +3051,10 @@ static struct sk_buff *validate_xmit_skb(struct sk_buff 
*skb, struct net_device
        if (unlikely(!skb))
                goto out_null;
 
+       skb = skb_offload_check(skb, dev);
+       if (!skb)
+               goto out_null;
+
        if (netif_needs_gso(skb, features)) {
                struct sk_buff *segs;
 
-- 
2.15.0.317.g14c63a9

Reply via email to