developer | 5d86c14 | 2023-12-06 14:18:27 +0800 | [diff] [blame] | 1 | --- a/drivers/net/ppp/pptp.c |
| 2 | +++ b/drivers/net/ppp/pptp.c |
| 3 | @@ -33,6 +33,7 @@ |
| 4 | #include <net/route.h> |
| 5 | #include <net/gre.h> |
| 6 | #include <net/pptp.h> |
| 7 | +#include <net/netfilter/nf_flow_table.h> |
| 8 | |
| 9 | #include <linux/uaccess.h> |
| 10 | |
| 11 | @@ -40,6 +41,9 @@ |
| 12 | |
| 13 | #define MAX_CALLID 65535 |
| 14 | |
| 15 | +int (*mtk_pptp_seq_next)(u16 call_id, u32 *val) = NULL; |
| 16 | +EXPORT_SYMBOL(mtk_pptp_seq_next); |
| 17 | + |
| 18 | static DECLARE_BITMAP(callid_bitmap, MAX_CALLID + 1); |
| 19 | static struct pppox_sock __rcu **callid_sock; |
| 20 | |
| 21 | @@ -128,6 +132,26 @@ static void del_chan(struct pppox_sock * |
| 22 | spin_unlock(&chan_lock); |
| 23 | } |
| 24 | |
| 25 | +#if IS_ENABLED(CONFIG_NF_FLOW_TABLE) |
| 26 | +static int pptp_flow_offload_check(struct ppp_channel *chan, |
| 27 | + struct flow_offload_hw_path *path) |
| 28 | +{ |
| 29 | + struct sock *sk = (struct sock *)chan->private; |
| 30 | + struct pppox_sock *po = pppox_sk(sk); |
| 31 | + |
| 32 | + if (path->flags & FLOW_OFFLOAD_PATH_TNL) |
| 33 | + return -EEXIST; |
| 34 | + |
| 35 | + if (sk_pppox(po)->sk_state & PPPOX_DEAD) |
| 36 | + return -EINVAL; |
| 37 | + |
| 38 | + path->flags |= FLOW_OFFLOAD_PATH_TNL; |
| 39 | + path->tnl_type = FLOW_OFFLOAD_TNL_PPTP; |
| 40 | + |
| 41 | + return 0; |
| 42 | +} |
| 43 | +#endif /* IS_ENABLED(CONFIG_NF_FLOW_TABLE) */ |
| 44 | + |
| 45 | static int pptp_xmit(struct ppp_channel *chan, struct sk_buff *skb) |
| 46 | { |
| 47 | struct sock *sk = (struct sock *) chan->private; |
| 48 | @@ -140,6 +164,7 @@ static int pptp_xmit(struct ppp_channel |
| 49 | int islcp; |
| 50 | int len; |
| 51 | unsigned char *data; |
| 52 | + u32 seq_sent_hw; |
| 53 | __u32 seq_recv; |
| 54 | |
| 55 | |
| 56 | @@ -204,7 +229,14 @@ static int pptp_xmit(struct ppp_channel |
| 57 | hdr->gre_hd.protocol = GRE_PROTO_PPP; |
| 58 | hdr->call_id = htons(opt->dst_addr.call_id); |
| 59 | |
| 60 | - hdr->seq = htonl(++opt->seq_sent); |
| 61 | + if (mtk_pptp_seq_next && !mtk_pptp_seq_next(opt->dst_addr.call_id, |
| 62 | + &seq_sent_hw)) { |
| 63 | + opt->seq_sent = seq_sent_hw; |
| 64 | + hdr->seq = htonl(opt->seq_sent); |
| 65 | + } else { |
| 66 | + hdr->seq = htonl(++opt->seq_sent); |
| 67 | + } |
| 68 | + |
| 69 | if (opt->ack_sent != seq_recv) { |
| 70 | /* send ack with this message */ |
| 71 | hdr->gre_hd.flags |= GRE_ACK; |
| 72 | @@ -598,6 +630,9 @@ static int pptp_ppp_ioctl(struct ppp_cha |
| 73 | static const struct ppp_channel_ops pptp_chan_ops = { |
| 74 | .start_xmit = pptp_xmit, |
| 75 | .ioctl = pptp_ppp_ioctl, |
| 76 | +#if IS_ENABLED(CONFIG_NF_FLOW_TABLE) |
| 77 | + .flow_offload_check = pptp_flow_offload_check, |
| 78 | +#endif /* IS_ENABLED(CONFIG_NF_FLOW_TABLE) */ |
| 79 | }; |
| 80 | |
| 81 | static struct proto pptp_sk_proto __read_mostly = { |
| 82 | --- a/include/net/pptp.h |
| 83 | +++ b/include/net/pptp.h |
| 84 | @@ -2,6 +2,8 @@ |
| 85 | #ifndef _NET_PPTP_H |
| 86 | #define _NET_PPTP_H |
| 87 | |
| 88 | +#include <net/gre.h> |
| 89 | + |
| 90 | #define PPP_LCP_ECHOREQ 0x09 |
| 91 | #define PPP_LCP_ECHOREP 0x0A |
| 92 | #define SC_RCV_BITS (SC_RCV_B7_1|SC_RCV_B7_0|SC_RCV_ODDP|SC_RCV_EVNP) |
| 93 | @@ -20,5 +22,7 @@ struct pptp_gre_header { |
| 94 | __be32 ack; |
| 95 | } __packed; |
| 96 | |
| 97 | +/* symbol exported from linux kernel driver/net/ppp/pptp.c */ |
| 98 | +extern int (*mtk_pptp_seq_next)(uint16_t call_id, uint32_t *val); |
| 99 | |
| 100 | #endif |