blob: e94185fb29bd1f585910dd407d635e91a2b41d5f [file] [log] [blame]
developer24f74432023-06-07 14:14:08 +08001--- a/include/net/netfilter/nf_flow_table.h
2+++ b/include/net/netfilter/nf_flow_table.h
3@@ -96,6 +96,7 @@ struct flow_offload {
4 #define FLOW_OFFLOAD_PATH_DSA BIT(3)
5 #define FLOW_OFFLOAD_PATH_DSLITE BIT(4)
6 #define FLOW_OFFLOAD_PATH_6RD BIT(5)
7+#define FLOW_OFFLOAD_PATH_TNL BIT(6)
8
9 struct flow_offload_hw_path {
10 struct net_device *dev;
11--- a/net/l2tp/l2tp_ppp.c
12+++ b/net/l2tp/l2tp_ppp.c
13@@ -89,6 +89,7 @@
14 #include <linux/nsproxy.h>
15 #include <net/net_namespace.h>
16 #include <net/netns/generic.h>
17+#include <net/netfilter/nf_flow_table.h>
18 #include <net/ip.h>
19 #include <net/udp.h>
20 #include <net/inet_common.h>
21@@ -124,9 +125,14 @@ struct pppol2tp_session {
22 };
23
24 static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb);
25+static int l2tp_ppp_flow_offload_check(struct ppp_channel *chan,
26+ struct flow_offload_hw_path *path);
27
28 static const struct ppp_channel_ops pppol2tp_chan_ops = {
29 .start_xmit = pppol2tp_xmit,
30+#if IS_ENABLED(CONFIG_NF_FLOW_TABLE)
31+ .flow_offload_check = l2tp_ppp_flow_offload_check,
32+#endif /* IS_ENABLED(CONFIG_NF_FLOW_TABLE) */
33 };
34
35 static const struct proto_ops pppol2tp_ops;
36@@ -335,6 +341,26 @@ error:
37 return error;
38 }
39
40+#if IS_ENABLED(CONFIG_NF_FLOW_TABLE)
41+static int l2tp_ppp_flow_offload_check(struct ppp_channel *chan,
42+ struct flow_offload_hw_path *path)
43+{
44+ struct sock *sk = (struct sock *)chan->private;
45+ struct l2tp_session *session;
46+
47+ if (path->flags & FLOW_OFFLOAD_PATH_TNL)
48+ return -EEXIST;
49+
50+ session = pppol2tp_sock_to_session(sk);
51+ if (!session)
52+ return -EINVAL;
53+
54+ path->flags |= FLOW_OFFLOAD_PATH_TNL;
55+
56+ return 0;
57+}
58+#endif /* IS_ENABLED(CONFIG_NF_FLOW_TABLE) */
59+
60 /* Transmit function called by generic PPP driver. Sends PPP frame
61 * over PPPoL2TP socket.
62 *