mediatek: update to latest kernel patchset from v4.13-rc
[openwrt/openwrt.git] / target / linux / mediatek / patches-4.9 / 0056-net-mediatek-add-hw-nat-support.patch
1 From 043efc0e619e04661be2b1889382db2fdd378145 Mon Sep 17 00:00:00 2001
2 From: John Crispin <john@phrozen.org>
3 Date: Thu, 10 Aug 2017 16:34:36 +0200
4 Subject: [PATCH 56/57] net: mediatek: add hw nat support
5
6 Signed-off-by: John Crispin <john@phrozen.org>
7 ---
8 drivers/net/ethernet/mediatek/Kconfig | 7 +++++++
9 drivers/net/ethernet/mediatek/Makefile | 1 +
10 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 13 +++++++++++++
11 net/netfilter/nf_conntrack_proto_tcp.c | 19 +++++++++++++++++++
12 4 files changed, 40 insertions(+)
13
14 --- a/drivers/net/ethernet/mediatek/Kconfig
15 +++ b/drivers/net/ethernet/mediatek/Kconfig
16 @@ -14,4 +14,11 @@ config NET_MEDIATEK_SOC
17 This driver supports the gigabit ethernet MACs in the
18 MediaTek MT2701/MT7623 chipset family.
19
20 +config NET_MEDIATEK_HNAT
21 + tristate "MediaTek MT7623 hardware NAT support"
22 + depends on NET_MEDIATEK_SOC && NF_CONNTRACK && NF_CONNTRACK_IPV4 && IP_NF_NAT && IP_NF_TARGET_MASQUERADE
23 + ---help---
24 + This driver supports the hardwaer NAT in the
25 + MediaTek MT2701/MT7623 chipset family.
26 +
27 endif #NET_VENDOR_MEDIATEK
28 --- a/drivers/net/ethernet/mediatek/Makefile
29 +++ b/drivers/net/ethernet/mediatek/Makefile
30 @@ -3,3 +3,4 @@
31 #
32
33 obj-$(CONFIG_NET_MEDIATEK_SOC) += mtk_eth_soc.o
34 +obj-$(CONFIG_NET_MEDIATEK_HNAT) += mtk_hnat/
35 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
36 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
37 @@ -23,6 +23,10 @@
38 #include <linux/reset.h>
39 #include <linux/tcp.h>
40
41 +#if defined(CONFIG_NET_MEDIATEK_HNAT) || defined(CONFIG_NET_MEDIATEK_HNAT_MODULE)
42 +#include "mtk_hnat/nf_hnat_mtk.h"
43 +#endif
44 +
45 #include "mtk_eth_soc.h"
46
47 static int mtk_msg_level = -1;
48 @@ -649,6 +653,11 @@ static int mtk_tx_map(struct sk_buff *sk
49 return -ENOMEM;
50
51 /* set the forward port */
52 +#if defined(CONFIG_NET_MEDIATEK_HNAT) || defined(CONFIG_NET_MEDIATEK_HNAT_MODULE)
53 + if (HNAT_SKB_CB2(skb)->magic == 0x78681415)
54 + fport |= 0x4 << TX_DMA_FPORT_SHIFT;
55 + else
56 +#endif
57 fport = (mac->id + 1) << TX_DMA_FPORT_SHIFT;
58 txd4 |= fport;
59
60 @@ -1013,6 +1022,10 @@ static int mtk_poll_rx(struct napi_struc
61 RX_DMA_VID(trxd.rxd3))
62 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
63 RX_DMA_VID(trxd.rxd3));
64 +#if defined(CONFIG_NET_MEDIATEK_HNAT) || defined(CONFIG_NET_MEDIATEK_HNAT_MODULE)
65 + *(u32 *)(skb->head) = trxd.rxd4;
66 + skb_hnat_alg(skb) = 0;
67 +#endif
68 skb_record_rx_queue(skb, 0);
69 napi_gro_receive(napi, skb);
70
71 --- a/net/netfilter/nf_conntrack_proto_tcp.c
72 +++ b/net/netfilter/nf_conntrack_proto_tcp.c
73 @@ -11,6 +11,7 @@
74 #include <linux/types.h>
75 #include <linux/timer.h>
76 #include <linux/module.h>
77 +#include <linux/inetdevice.h>
78 #include <linux/in.h>
79 #include <linux/tcp.h>
80 #include <linux/spinlock.h>
81 @@ -19,6 +20,7 @@
82 #include <net/ip6_checksum.h>
83 #include <asm/unaligned.h>
84
85 +#include <net/ip.h>
86 #include <net/tcp.h>
87
88 #include <linux/netfilter.h>
89 @@ -53,6 +55,11 @@ static int nf_ct_tcp_max_retrans __read_
90 /* FIXME: Examine ipfilter's timeouts and conntrack transitions more
91 closely. They're more complex. --RR */
92
93 +#ifndef IPV4_DEVCONF_DFLT
94 + #define IPV4_DEVCONF_DFLT(net, attr) \
95 + IPV4_DEVCONF((*net->ipv4.devconf_dflt), attr)
96 +#endif
97 +
98 static const char *const tcp_conntrack_names[] = {
99 "NONE",
100 "SYN_SENT",
101 @@ -519,6 +526,18 @@ static bool tcp_in_window(const struct n
102 if (nf_ct_tcp_no_window_check)
103 return true;
104
105 + if (net) {
106 + if ((net->ipv4.devconf_all && net->ipv4.devconf_dflt && net->ipv6.devconf_all) &&
107 + net->ipv6.devconf_dflt) {
108 + if ((IPV4_DEVCONF_DFLT(net, FORWARDING) ||
109 + IPV4_DEVCONF_ALL(net, FORWARDING)) ||
110 + (net->ipv6.devconf_all->forwarding ||
111 + net->ipv6.devconf_dflt->forwarding)) {
112 + return true;
113 + }
114 + }
115 + }
116 +
117 /*
118 * Get the required data from the packet.
119 */