blob: b86c1b9e7bfea77511815baa38784da33247d8c2 [file] [log] [blame]
developerfd40db22021-04-29 10:08:25 +08001/* This program is free software; you can redistribute it and/or modify
2 * it under the terms of the GNU General Public License as published by
3 * the Free Software Foundation; version 2 of the License
4 *
5 * This program is distributed in the hope that it will be useful,
6 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8 * GNU General Public License for more details.
9 *
10 * Copyright (C) 2014-2016 Sean Wang <sean.wang@mediatek.com>
11 * Copyright (C) 2016-2017 John Crispin <blogic@openwrt.org>
12 */
13
14#include <linux/netfilter_bridge.h>
15#include <linux/netfilter_ipv6.h>
16
17#include <net/arp.h>
18#include <net/neighbour.h>
19#include <net/netfilter/nf_conntrack_helper.h>
20#include <net/netfilter/nf_flow_table.h>
21#include <net/ipv6.h>
22#include <net/ip6_route.h>
23#include <net/ip.h>
24#include <net/tcp.h>
25#include <net/udp.h>
developer30a47682021-11-02 17:06:14 +080026#include <net/netfilter/nf_conntrack.h>
27#include <net/netfilter/nf_conntrack_acct.h>
developerfd40db22021-04-29 10:08:25 +080028
29#include "nf_hnat_mtk.h"
30#include "hnat.h"
31
32#include "../mtk_eth_soc.h"
developer8051e042022-04-08 13:26:36 +080033#include "../mtk_eth_reset.h"
developerfd40db22021-04-29 10:08:25 +080034
35#define do_ge2ext_fast(dev, skb) \
developerd35bbcc2022-09-28 22:46:01 +080036 ((IS_LAN_GRP(dev) || IS_WAN(dev) || IS_PPD(dev)) && \
developerfd40db22021-04-29 10:08:25 +080037 skb_hnat_is_hashed(skb) && \
38 skb_hnat_reason(skb) == HIT_BIND_FORCE_TO_CPU)
39#define do_ext2ge_fast_learn(dev, skb) \
40 (IS_PPD(dev) && \
41 (skb_hnat_sport(skb) == NR_PDMA_PORT || \
42 skb_hnat_sport(skb) == NR_QDMA_PORT) && \
43 ((get_dev_from_index(skb->vlan_tci & VLAN_VID_MASK)) || \
44 get_wandev_from_index(skb->vlan_tci & VLAN_VID_MASK)))
45#define do_mape_w2l_fast(dev, skb) \
46 (mape_toggle && IS_WAN(dev) && (!is_from_mape(skb)))
47
48static struct ipv6hdr mape_l2w_v6h;
49static struct ipv6hdr mape_w2l_v6h;
50static inline uint8_t get_wifi_hook_if_index_from_dev(const struct net_device *dev)
51{
52 int i;
53
54 for (i = 1; i < MAX_IF_NUM; i++) {
55 if (hnat_priv->wifi_hook_if[i] == dev)
56 return i;
57 }
58
59 return 0;
60}
61
62static inline int get_ext_device_number(void)
63{
64 int i, number = 0;
65
66 for (i = 0; i < MAX_EXT_DEVS && hnat_priv->ext_if[i]; i++)
67 number += 1;
68 return number;
69}
70
71static inline int find_extif_from_devname(const char *name)
72{
73 int i;
74 struct extdev_entry *ext_entry;
75
76 for (i = 0; i < MAX_EXT_DEVS && hnat_priv->ext_if[i]; i++) {
77 ext_entry = hnat_priv->ext_if[i];
78 if (!strcmp(name, ext_entry->name))
79 return 1;
80 }
81 return 0;
82}
83
84static inline int get_index_from_dev(const struct net_device *dev)
85{
86 int i;
87 struct extdev_entry *ext_entry;
88
89 for (i = 0; i < MAX_EXT_DEVS && hnat_priv->ext_if[i]; i++) {
90 ext_entry = hnat_priv->ext_if[i];
91 if (dev == ext_entry->dev)
92 return ext_entry->dev->ifindex;
93 }
94 return 0;
95}
96
97static inline struct net_device *get_dev_from_index(int index)
98{
99 int i;
100 struct extdev_entry *ext_entry;
101 struct net_device *dev = 0;
102
103 for (i = 0; i < MAX_EXT_DEVS && hnat_priv->ext_if[i]; i++) {
104 ext_entry = hnat_priv->ext_if[i];
105 if (ext_entry->dev && index == ext_entry->dev->ifindex) {
106 dev = ext_entry->dev;
107 break;
108 }
109 }
110 return dev;
111}
112
113static inline struct net_device *get_wandev_from_index(int index)
114{
developer8c9c0d02021-06-18 16:15:37 +0800115 if (!hnat_priv->g_wandev)
116 hnat_priv->g_wandev = dev_get_by_name(&init_net, hnat_priv->wan);
developerfd40db22021-04-29 10:08:25 +0800117
developer8c9c0d02021-06-18 16:15:37 +0800118 if (hnat_priv->g_wandev && hnat_priv->g_wandev->ifindex == index)
119 return hnat_priv->g_wandev;
developerfd40db22021-04-29 10:08:25 +0800120 return NULL;
121}
122
123static inline int extif_set_dev(struct net_device *dev)
124{
125 int i;
126 struct extdev_entry *ext_entry;
127
128 for (i = 0; i < MAX_EXT_DEVS && hnat_priv->ext_if[i]; i++) {
129 ext_entry = hnat_priv->ext_if[i];
130 if (!strcmp(dev->name, ext_entry->name) && !ext_entry->dev) {
131 dev_hold(dev);
132 ext_entry->dev = dev;
133 pr_info("%s(%s)\n", __func__, dev->name);
134
135 return ext_entry->dev->ifindex;
136 }
137 }
138
139 return -1;
140}
141
142static inline int extif_put_dev(struct net_device *dev)
143{
144 int i;
145 struct extdev_entry *ext_entry;
146
147 for (i = 0; i < MAX_EXT_DEVS && hnat_priv->ext_if[i]; i++) {
148 ext_entry = hnat_priv->ext_if[i];
149 if (ext_entry->dev == dev) {
150 ext_entry->dev = NULL;
151 dev_put(dev);
152 pr_info("%s(%s)\n", __func__, dev->name);
153
developerbc53e5f2021-05-21 10:07:17 +0800154 return 0;
developerfd40db22021-04-29 10:08:25 +0800155 }
156 }
157
158 return -1;
159}
160
161int ext_if_add(struct extdev_entry *ext_entry)
162{
163 int len = get_ext_device_number();
164
developer4c32b7a2021-11-13 16:46:43 +0800165 if (len < MAX_EXT_DEVS)
166 hnat_priv->ext_if[len++] = ext_entry;
167
developerfd40db22021-04-29 10:08:25 +0800168 return len;
169}
170
171int ext_if_del(struct extdev_entry *ext_entry)
172{
173 int i, j;
174
175 for (i = 0; i < MAX_EXT_DEVS; i++) {
176 if (hnat_priv->ext_if[i] == ext_entry) {
177 for (j = i; hnat_priv->ext_if[j] && j < MAX_EXT_DEVS - 1; j++)
178 hnat_priv->ext_if[j] = hnat_priv->ext_if[j + 1];
179 hnat_priv->ext_if[j] = NULL;
180 break;
181 }
182 }
183
184 return i;
185}
186
187void foe_clear_all_bind_entries(struct net_device *dev)
188{
developer471f6562021-05-10 20:48:34 +0800189 int i, hash_index;
developerfd40db22021-04-29 10:08:25 +0800190 struct foe_entry *entry;
191
developerd35bbcc2022-09-28 22:46:01 +0800192 if (!IS_LAN_GRP(dev) && !IS_WAN(dev) &&
developerfd40db22021-04-29 10:08:25 +0800193 !find_extif_from_devname(dev->name) &&
194 !dev->netdev_ops->ndo_flow_offload_check)
195 return;
196
developer471f6562021-05-10 20:48:34 +0800197 for (i = 0; i < CFG_PPE_NUM; i++) {
198 cr_set_field(hnat_priv->ppe_base[i] + PPE_TB_CFG,
199 SMA, SMA_ONLY_FWD_CPU);
200
201 for (hash_index = 0; hash_index < hnat_priv->foe_etry_num; hash_index++) {
202 entry = hnat_priv->foe_table_cpu[i] + hash_index;
203 if (entry->bfib1.state == BIND) {
204 entry->ipv4_hnapt.udib1.state = INVALID;
205 entry->ipv4_hnapt.udib1.time_stamp =
206 readl((hnat_priv->fe_base + 0x0010)) & 0xFF;
207 }
developerfd40db22021-04-29 10:08:25 +0800208 }
209 }
210
211 /* clear HWNAT cache */
212 hnat_cache_ebl(1);
213
214 mod_timer(&hnat_priv->hnat_sma_build_entry_timer, jiffies + 3 * HZ);
215}
216
217static void gmac_ppe_fwd_enable(struct net_device *dev)
218{
219 if (IS_LAN(dev) || IS_GMAC1_MODE)
developerd35bbcc2022-09-28 22:46:01 +0800220 set_gmac_ppe_fwd(NR_GMAC1_PORT, 1);
developerfd40db22021-04-29 10:08:25 +0800221 else if (IS_WAN(dev))
developerd35bbcc2022-09-28 22:46:01 +0800222 set_gmac_ppe_fwd(NR_GMAC2_PORT, 1);
223 else if (IS_LAN2(dev))
224 set_gmac_ppe_fwd(NR_GMAC3_PORT, 1);
developerfd40db22021-04-29 10:08:25 +0800225}
226
227int nf_hnat_netdevice_event(struct notifier_block *unused, unsigned long event,
228 void *ptr)
229{
230 struct net_device *dev;
231
232 dev = netdev_notifier_info_to_dev(ptr);
233
234 switch (event) {
235 case NETDEV_UP:
236 gmac_ppe_fwd_enable(dev);
237
238 extif_set_dev(dev);
239
240 break;
241 case NETDEV_GOING_DOWN:
242 if (!get_wifi_hook_if_index_from_dev(dev))
243 extif_put_dev(dev);
244
245 foe_clear_all_bind_entries(dev);
246
247 break;
developer8c9c0d02021-06-18 16:15:37 +0800248 case NETDEV_UNREGISTER:
developer1901f412022-01-04 17:22:00 +0800249 if (hnat_priv->g_ppdev == dev) {
developer8c9c0d02021-06-18 16:15:37 +0800250 hnat_priv->g_ppdev = NULL;
251 dev_put(dev);
252 }
developer1901f412022-01-04 17:22:00 +0800253 if (hnat_priv->g_wandev == dev) {
developer8c9c0d02021-06-18 16:15:37 +0800254 hnat_priv->g_wandev = NULL;
255 dev_put(dev);
256 }
257
258 break;
259 case NETDEV_REGISTER:
260 if (IS_PPD(dev) && !hnat_priv->g_ppdev)
261 hnat_priv->g_ppdev = dev_get_by_name(&init_net, hnat_priv->ppd);
262 if (IS_WAN(dev) && !hnat_priv->g_wandev)
263 hnat_priv->g_wandev = dev_get_by_name(&init_net, hnat_priv->wan);
264
265 break;
developer8051e042022-04-08 13:26:36 +0800266 case MTK_FE_RESET_NAT_DONE:
267 pr_info("[%s] HNAT driver starts to do warm init !\n", __func__);
268 hnat_warm_init();
269 break;
developerfd40db22021-04-29 10:08:25 +0800270 default:
271 break;
272 }
273
274 return NOTIFY_DONE;
275}
276
277void foe_clear_entry(struct neighbour *neigh)
278{
279 u32 *daddr = (u32 *)neigh->primary_key;
280 unsigned char h_dest[ETH_ALEN];
281 struct foe_entry *entry;
developer471f6562021-05-10 20:48:34 +0800282 int i, hash_index;
developerfd40db22021-04-29 10:08:25 +0800283 u32 dip;
284
285 dip = (u32)(*daddr);
286
developer471f6562021-05-10 20:48:34 +0800287 for (i = 0; i < CFG_PPE_NUM; i++) {
developer8051e042022-04-08 13:26:36 +0800288 if (!hnat_priv->foe_table_cpu[i])
289 continue;
290
developer471f6562021-05-10 20:48:34 +0800291 for (hash_index = 0; hash_index < hnat_priv->foe_etry_num; hash_index++) {
292 entry = hnat_priv->foe_table_cpu[i] + hash_index;
293 if (entry->bfib1.state == BIND &&
294 entry->ipv4_hnapt.new_dip == ntohl(dip)) {
295 *((u32 *)h_dest) = swab32(entry->ipv4_hnapt.dmac_hi);
296 *((u16 *)&h_dest[4]) =
297 swab16(entry->ipv4_hnapt.dmac_lo);
298 if (strncmp(h_dest, neigh->ha, ETH_ALEN) != 0) {
299 pr_info("%s: state=%d\n", __func__,
300 neigh->nud_state);
301 cr_set_field(hnat_priv->ppe_base[i] + PPE_TB_CFG,
302 SMA, SMA_ONLY_FWD_CPU);
developerfd40db22021-04-29 10:08:25 +0800303
developer471f6562021-05-10 20:48:34 +0800304 entry->ipv4_hnapt.udib1.state = INVALID;
305 entry->ipv4_hnapt.udib1.time_stamp =
306 readl((hnat_priv->fe_base + 0x0010)) & 0xFF;
developerfd40db22021-04-29 10:08:25 +0800307
developer471f6562021-05-10 20:48:34 +0800308 /* clear HWNAT cache */
309 hnat_cache_ebl(1);
developerfd40db22021-04-29 10:08:25 +0800310
developer471f6562021-05-10 20:48:34 +0800311 mod_timer(&hnat_priv->hnat_sma_build_entry_timer,
312 jiffies + 3 * HZ);
developerfd40db22021-04-29 10:08:25 +0800313
developer471f6562021-05-10 20:48:34 +0800314 pr_info("Delete old entry: dip =%pI4\n", &dip);
315 pr_info("Old mac= %pM\n", h_dest);
316 pr_info("New mac= %pM\n", neigh->ha);
317 }
developerfd40db22021-04-29 10:08:25 +0800318 }
319 }
320 }
321}
322
323int nf_hnat_netevent_handler(struct notifier_block *unused, unsigned long event,
324 void *ptr)
325{
326 struct net_device *dev = NULL;
327 struct neighbour *neigh = NULL;
328
329 switch (event) {
330 case NETEVENT_NEIGH_UPDATE:
331 neigh = ptr;
332 dev = neigh->dev;
333 if (dev)
334 foe_clear_entry(neigh);
335 break;
336 }
337
338 return NOTIFY_DONE;
339}
340
341unsigned int mape_add_ipv6_hdr(struct sk_buff *skb, struct ipv6hdr mape_ip6h)
342{
343 struct ethhdr *eth = NULL;
344 struct ipv6hdr *ip6h = NULL;
345 struct iphdr *iph = NULL;
346
347 if (skb_headroom(skb) < IPV6_HDR_LEN || skb_shared(skb) ||
348 (skb_cloned(skb) && !skb_clone_writable(skb, 0))) {
349 return -1;
350 }
351
352 /* point to L3 */
353 memcpy(skb->data - IPV6_HDR_LEN - ETH_HLEN, skb_push(skb, ETH_HLEN), ETH_HLEN);
354 memcpy(skb_push(skb, IPV6_HDR_LEN - ETH_HLEN), &mape_ip6h, IPV6_HDR_LEN);
355
356 eth = (struct ethhdr *)(skb->data - ETH_HLEN);
357 eth->h_proto = htons(ETH_P_IPV6);
358 skb->protocol = htons(ETH_P_IPV6);
359
360 iph = (struct iphdr *)(skb->data + IPV6_HDR_LEN);
361 ip6h = (struct ipv6hdr *)(skb->data);
362 ip6h->payload_len = iph->tot_len; /* maybe different with ipv4 */
363
364 skb_set_network_header(skb, 0);
365 skb_set_transport_header(skb, iph->ihl * 4 + IPV6_HDR_LEN);
366 return 0;
367}
368
369static void fix_skb_packet_type(struct sk_buff *skb, struct net_device *dev,
370 struct ethhdr *eth)
371{
372 skb->pkt_type = PACKET_HOST;
373 if (unlikely(is_multicast_ether_addr(eth->h_dest))) {
374 if (ether_addr_equal_64bits(eth->h_dest, dev->broadcast))
375 skb->pkt_type = PACKET_BROADCAST;
376 else
377 skb->pkt_type = PACKET_MULTICAST;
378 }
379}
380
381unsigned int do_hnat_ext_to_ge(struct sk_buff *skb, const struct net_device *in,
382 const char *func)
383{
384 if (hnat_priv->g_ppdev && hnat_priv->g_ppdev->flags & IFF_UP) {
385 u16 vlan_id = 0;
386 skb_set_network_header(skb, 0);
387 skb_push(skb, ETH_HLEN);
388 set_to_ppe(skb);
389
390 vlan_id = skb_vlan_tag_get_id(skb);
391 if (vlan_id) {
392 skb = vlan_insert_tag(skb, skb->vlan_proto, skb->vlan_tci);
393 if (!skb)
394 return -1;
395 }
396
397 /*set where we come from*/
398 skb->vlan_proto = htons(ETH_P_8021Q);
399 skb->vlan_tci =
400 (VLAN_CFI_MASK | (in->ifindex & VLAN_VID_MASK));
401 trace_printk(
402 "%s: vlan_prot=0x%x, vlan_tci=%x, in->name=%s, skb->dev->name=%s\n",
403 __func__, ntohs(skb->vlan_proto), skb->vlan_tci,
404 in->name, hnat_priv->g_ppdev->name);
405 skb->dev = hnat_priv->g_ppdev;
406 dev_queue_xmit(skb);
407 trace_printk("%s: called from %s successfully\n", __func__, func);
408 return 0;
409 }
410
411 trace_printk("%s: called from %s fail\n", __func__, func);
412 return -1;
413}
414
415unsigned int do_hnat_ext_to_ge2(struct sk_buff *skb, const char *func)
416{
417 struct ethhdr *eth = eth_hdr(skb);
418 struct net_device *dev;
419 struct foe_entry *entry;
420
421 trace_printk("%s: vlan_prot=0x%x, vlan_tci=%x\n", __func__,
422 ntohs(skb->vlan_proto), skb->vlan_tci);
423
424 dev = get_dev_from_index(skb->vlan_tci & VLAN_VID_MASK);
425
426 if (dev) {
427 /*set where we to go*/
428 skb->dev = dev;
429 skb->vlan_proto = 0;
430 skb->vlan_tci = 0;
431
432 if (ntohs(eth->h_proto) == ETH_P_8021Q) {
433 skb = skb_vlan_untag(skb);
434 if (unlikely(!skb))
435 return -1;
436 }
437
438 if (IS_BOND_MODE &&
developerd35bbcc2022-09-28 22:46:01 +0800439 (((hnat_priv->data->version == MTK_HNAT_V4 ||
440 hnat_priv->data->version == MTK_HNAT_V5) &&
developerfd40db22021-04-29 10:08:25 +0800441 (skb_hnat_entry(skb) != 0x7fff)) ||
developerd35bbcc2022-09-28 22:46:01 +0800442 ((hnat_priv->data->version != MTK_HNAT_V4 &&
443 hnat_priv->data->version != MTK_HNAT_V5) &&
developerfd40db22021-04-29 10:08:25 +0800444 (skb_hnat_entry(skb) != 0x3fff))))
445 skb_set_hash(skb, skb_hnat_entry(skb) >> 1, PKT_HASH_TYPE_L4);
446
447 set_from_extge(skb);
448 fix_skb_packet_type(skb, skb->dev, eth);
449 netif_rx(skb);
450 trace_printk("%s: called from %s successfully\n", __func__,
451 func);
452 return 0;
453 } else {
454 /* MapE WAN --> LAN/WLAN PingPong. */
455 dev = get_wandev_from_index(skb->vlan_tci & VLAN_VID_MASK);
456 if (mape_toggle && dev) {
457 if (!mape_add_ipv6_hdr(skb, mape_w2l_v6h)) {
458 skb_set_mac_header(skb, -ETH_HLEN);
459 skb->dev = dev;
460 set_from_mape(skb);
461 skb->vlan_proto = 0;
462 skb->vlan_tci = 0;
463 fix_skb_packet_type(skb, skb->dev, eth_hdr(skb));
developer471f6562021-05-10 20:48:34 +0800464 entry = &hnat_priv->foe_table_cpu[skb_hnat_ppe(skb)][skb_hnat_entry(skb)];
developerfd40db22021-04-29 10:08:25 +0800465 entry->bfib1.pkt_type = IPV4_HNAPT;
466 netif_rx(skb);
467 return 0;
468 }
469 }
470 trace_printk("%s: called from %s fail\n", __func__, func);
471 return -1;
472 }
473}
474
475unsigned int do_hnat_ge_to_ext(struct sk_buff *skb, const char *func)
476{
477 /*set where we to go*/
478 u8 index;
479 struct foe_entry *entry;
480 struct net_device *dev;
481
developer471f6562021-05-10 20:48:34 +0800482 entry = &hnat_priv->foe_table_cpu[skb_hnat_ppe(skb)][skb_hnat_entry(skb)];
developerfd40db22021-04-29 10:08:25 +0800483
484 if (IS_IPV4_GRP(entry))
485 index = entry->ipv4_hnapt.act_dp;
486 else
487 index = entry->ipv6_5t_route.act_dp;
488
489 skb->dev = get_dev_from_index(index);
490
developer34028fb2022-01-11 13:51:29 +0800491 if (IS_HQOS_MODE && eth_hdr(skb)->h_proto == HQOS_MAGIC_TAG) {
developerfd40db22021-04-29 10:08:25 +0800492 skb = skb_unshare(skb, GFP_ATOMIC);
493 if (!skb)
494 return NF_ACCEPT;
495
496 if (unlikely(!pskb_may_pull(skb, VLAN_HLEN)))
497 return NF_ACCEPT;
498
499 skb_pull_rcsum(skb, VLAN_HLEN);
500
501 memmove(skb->data - ETH_HLEN, skb->data - ETH_HLEN - VLAN_HLEN,
502 2 * ETH_ALEN);
503 }
developerfd40db22021-04-29 10:08:25 +0800504
505 if (skb->dev) {
506 skb_set_network_header(skb, 0);
507 skb_push(skb, ETH_HLEN);
508 dev_queue_xmit(skb);
509 trace_printk("%s: called from %s successfully\n", __func__,
510 func);
511 return 0;
512 } else {
513 if (mape_toggle) {
514 /* Add ipv6 header mape for lan/wlan -->wan */
515 dev = get_wandev_from_index(index);
516 if (dev) {
517 if (!mape_add_ipv6_hdr(skb, mape_l2w_v6h)) {
518 skb_set_network_header(skb, 0);
519 skb_push(skb, ETH_HLEN);
520 skb_set_mac_header(skb, 0);
521 skb->dev = dev;
522 dev_queue_xmit(skb);
523 return 0;
524 }
525 trace_printk("%s: called from %s fail[MapE]\n", __func__,
526 func);
527 return -1;
528 }
529 }
530 }
531 /*if external devices is down, invalidate related ppe entry*/
532 if (entry_hnat_is_bound(entry)) {
533 entry->bfib1.state = INVALID;
534 if (IS_IPV4_GRP(entry))
535 entry->ipv4_hnapt.act_dp = 0;
536 else
537 entry->ipv6_5t_route.act_dp = 0;
538
539 /* clear HWNAT cache */
540 hnat_cache_ebl(1);
541 }
542 trace_printk("%s: called from %s fail, index=%x\n", __func__,
543 func, index);
544 return -1;
545}
546
547static void pre_routing_print(struct sk_buff *skb, const struct net_device *in,
548 const struct net_device *out, const char *func)
549{
550 trace_printk(
551 "[%s]: %s(iif=0x%x CB2=0x%x)-->%s (ppe_hash=0x%x) sport=0x%x reason=0x%x alg=0x%x from %s\n",
552 __func__, in->name, skb_hnat_iface(skb),
553 HNAT_SKB_CB2(skb)->magic, out->name, skb_hnat_entry(skb),
554 skb_hnat_sport(skb), skb_hnat_reason(skb), skb_hnat_alg(skb),
555 func);
556}
557
558static void post_routing_print(struct sk_buff *skb, const struct net_device *in,
559 const struct net_device *out, const char *func)
560{
561 trace_printk(
562 "[%s]: %s(iif=0x%x, CB2=0x%x)-->%s (ppe_hash=0x%x) sport=0x%x reason=0x%x alg=0x%x from %s\n",
563 __func__, in->name, skb_hnat_iface(skb),
564 HNAT_SKB_CB2(skb)->magic, out->name, skb_hnat_entry(skb),
565 skb_hnat_sport(skb), skb_hnat_reason(skb), skb_hnat_alg(skb),
566 func);
567}
568
569static inline void hnat_set_iif(const struct nf_hook_state *state,
570 struct sk_buff *skb, int val)
571{
developer40017972021-06-29 14:27:35 +0800572 if (IS_WHNAT(state->in) && FROM_WED(skb)) {
developere567ad32021-05-25 17:16:17 +0800573 return;
574 } else if (IS_LAN(state->in)) {
developerfd40db22021-04-29 10:08:25 +0800575 skb_hnat_iface(skb) = FOE_MAGIC_GE_LAN;
developerd35bbcc2022-09-28 22:46:01 +0800576 } else if (IS_LAN2(state->in)) {
577 skb_hnat_iface(skb) = FOE_MAGIC_GE_LAN2;
developerfd40db22021-04-29 10:08:25 +0800578 } else if (IS_PPD(state->in)) {
579 skb_hnat_iface(skb) = FOE_MAGIC_GE_PPD;
580 } else if (IS_EXT(state->in)) {
581 skb_hnat_iface(skb) = FOE_MAGIC_EXT;
582 } else if (IS_WAN(state->in)) {
583 skb_hnat_iface(skb) = FOE_MAGIC_GE_WAN;
developerfd40db22021-04-29 10:08:25 +0800584 } else if (!IS_BR(state->in)) {
developer99506e52021-06-30 22:03:02 +0800585 if (state->in->netdev_ops->ndo_flow_offload_check) {
586 skb_hnat_iface(skb) = FOE_MAGIC_GE_VIRTUAL;
587 } else {
588 skb_hnat_iface(skb) = FOE_INVALID;
developerfd40db22021-04-29 10:08:25 +0800589
developer99506e52021-06-30 22:03:02 +0800590 if (is_magic_tag_valid(skb) &&
591 IS_SPACE_AVAILABLE_HEAD(skb))
592 memset(skb_hnat_info(skb), 0, FOE_INFO_LEN);
593 }
developerfd40db22021-04-29 10:08:25 +0800594 }
595}
596
597static inline void hnat_set_alg(const struct nf_hook_state *state,
598 struct sk_buff *skb, int val)
599{
600 skb_hnat_alg(skb) = val;
601}
602
603static inline void hnat_set_head_frags(const struct nf_hook_state *state,
604 struct sk_buff *head_skb, int val,
605 void (*fn)(const struct nf_hook_state *state,
606 struct sk_buff *skb, int val))
607{
608 struct sk_buff *segs = skb_shinfo(head_skb)->frag_list;
609
610 fn(state, head_skb, val);
611 while (segs) {
612 fn(state, segs, val);
613 segs = segs->next;
614 }
615}
616
developer25fc8c02022-05-06 16:24:02 +0800617static void ppe_fill_flow_lbl(struct foe_entry *entry, struct ipv6hdr *ip6h)
618{
619 entry->ipv4_dslite.flow_lbl[0] = ip6h->flow_lbl[2];
620 entry->ipv4_dslite.flow_lbl[1] = ip6h->flow_lbl[1];
621 entry->ipv4_dslite.flow_lbl[2] = ip6h->flow_lbl[0];
622}
623
developerfd40db22021-04-29 10:08:25 +0800624unsigned int do_hnat_mape_w2l_fast(struct sk_buff *skb, const struct net_device *in,
625 const char *func)
626{
627 struct ipv6hdr *ip6h = ipv6_hdr(skb);
628 struct iphdr _iphdr;
629 struct iphdr *iph;
630 struct ethhdr *eth;
631
632 /* WAN -> LAN/WLAN MapE. */
633 if (mape_toggle && (ip6h->nexthdr == NEXTHDR_IPIP)) {
634 iph = skb_header_pointer(skb, IPV6_HDR_LEN, sizeof(_iphdr), &_iphdr);
developer4c32b7a2021-11-13 16:46:43 +0800635 if (unlikely(!iph))
636 return -1;
637
developerfd40db22021-04-29 10:08:25 +0800638 switch (iph->protocol) {
639 case IPPROTO_UDP:
640 case IPPROTO_TCP:
641 break;
642 default:
643 return -1;
644 }
645 mape_w2l_v6h = *ip6h;
646
647 /* Remove ipv6 header. */
648 memcpy(skb->data + IPV6_HDR_LEN - ETH_HLEN,
649 skb->data - ETH_HLEN, ETH_HLEN);
650 skb_pull(skb, IPV6_HDR_LEN - ETH_HLEN);
651 skb_set_mac_header(skb, 0);
652 skb_set_network_header(skb, ETH_HLEN);
653 skb_set_transport_header(skb, ETH_HLEN + sizeof(_iphdr));
654
655 eth = eth_hdr(skb);
656 eth->h_proto = htons(ETH_P_IP);
657 set_to_ppe(skb);
658
659 skb->vlan_proto = htons(ETH_P_8021Q);
660 skb->vlan_tci =
661 (VLAN_CFI_MASK | (in->ifindex & VLAN_VID_MASK));
662
663 if (!hnat_priv->g_ppdev)
664 hnat_priv->g_ppdev = dev_get_by_name(&init_net, hnat_priv->ppd);
665
666 skb->dev = hnat_priv->g_ppdev;
667 skb->protocol = htons(ETH_P_IP);
668
669 dev_queue_xmit(skb);
670
671 return 0;
672 }
673 return -1;
674}
675
developer25fc8c02022-05-06 16:24:02 +0800676
developer25fc8c02022-05-06 16:24:02 +0800677
developerfd40db22021-04-29 10:08:25 +0800678static unsigned int is_ppe_support_type(struct sk_buff *skb)
679{
680 struct ethhdr *eth = NULL;
681 struct iphdr *iph = NULL;
682 struct ipv6hdr *ip6h = NULL;
683 struct iphdr _iphdr;
684
685 eth = eth_hdr(skb);
developerfd2d7422021-06-09 17:09:39 +0800686 if (!is_magic_tag_valid(skb) || !IS_SPACE_AVAILABLE_HEAD(skb) ||
developerb254f762022-01-20 20:06:25 +0800687 is_broadcast_ether_addr(eth->h_dest))
developerfd40db22021-04-29 10:08:25 +0800688 return 0;
689
690 switch (ntohs(skb->protocol)) {
691 case ETH_P_IP:
692 iph = ip_hdr(skb);
693
694 /* do not accelerate non tcp/udp traffic */
695 if ((iph->protocol == IPPROTO_TCP) ||
696 (iph->protocol == IPPROTO_UDP) ||
697 (iph->protocol == IPPROTO_IPV6)) {
698 return 1;
699 }
700
701 break;
702 case ETH_P_IPV6:
703 ip6h = ipv6_hdr(skb);
704
705 if ((ip6h->nexthdr == NEXTHDR_TCP) ||
706 (ip6h->nexthdr == NEXTHDR_UDP)) {
707 return 1;
708 } else if (ip6h->nexthdr == NEXTHDR_IPIP) {
709 iph = skb_header_pointer(skb, IPV6_HDR_LEN,
710 sizeof(_iphdr), &_iphdr);
developer4c32b7a2021-11-13 16:46:43 +0800711 if (unlikely(!iph))
712 return 0;
developerfd40db22021-04-29 10:08:25 +0800713
714 if ((iph->protocol == IPPROTO_TCP) ||
715 (iph->protocol == IPPROTO_UDP)) {
716 return 1;
717 }
718
719 }
720
721 break;
722 case ETH_P_8021Q:
723 return 1;
724 }
725
726 return 0;
727}
728
729static unsigned int
730mtk_hnat_ipv6_nf_pre_routing(void *priv, struct sk_buff *skb,
731 const struct nf_hook_state *state)
732{
733 if (!is_ppe_support_type(skb)) {
734 hnat_set_head_frags(state, skb, 1, hnat_set_alg);
735 return NF_ACCEPT;
736 }
737
738 hnat_set_head_frags(state, skb, -1, hnat_set_iif);
739
740 pre_routing_print(skb, state->in, state->out, __func__);
741
developerfd40db22021-04-29 10:08:25 +0800742 /* packets from external devices -> xxx ,step 1 , learning stage & bound stage*/
743 if (do_ext2ge_fast_try(state->in, skb)) {
744 if (!do_hnat_ext_to_ge(skb, state->in, __func__))
745 return NF_STOLEN;
746 if (!skb)
747 goto drop;
748 return NF_ACCEPT;
749 }
750
751 /* packets form ge -> external device
752 * For standalone wan interface
753 */
754 if (do_ge2ext_fast(state->in, skb)) {
755 if (!do_hnat_ge_to_ext(skb, __func__))
756 return NF_STOLEN;
757 goto drop;
758 }
759
developerf4c370a2022-10-08 17:01:19 +0800760
761#if !(defined(CONFIG_MEDIATEK_NETSYS_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3))
developerfd40db22021-04-29 10:08:25 +0800762 /* MapE need remove ipv6 header and pingpong. */
763 if (do_mape_w2l_fast(state->in, skb)) {
764 if (!do_hnat_mape_w2l_fast(skb, state->in, __func__))
765 return NF_STOLEN;
766 else
767 return NF_ACCEPT;
768 }
769
770 if (is_from_mape(skb))
771 clr_from_extge(skb);
developerf4c370a2022-10-08 17:01:19 +0800772#endif
developerfd40db22021-04-29 10:08:25 +0800773 return NF_ACCEPT;
774drop:
775 printk_ratelimited(KERN_WARNING
776 "%s:drop (in_dev=%s, iif=0x%x, CB2=0x%x, ppe_hash=0x%x, sport=0x%x, reason=0x%x, alg=0x%x)\n",
777 __func__, state->in->name, skb_hnat_iface(skb),
778 HNAT_SKB_CB2(skb)->magic, skb_hnat_entry(skb),
779 skb_hnat_sport(skb), skb_hnat_reason(skb),
780 skb_hnat_alg(skb));
781
782 return NF_DROP;
783}
784
785static unsigned int
786mtk_hnat_ipv4_nf_pre_routing(void *priv, struct sk_buff *skb,
787 const struct nf_hook_state *state)
788{
789 if (!is_ppe_support_type(skb)) {
790 hnat_set_head_frags(state, skb, 1, hnat_set_alg);
791 return NF_ACCEPT;
792 }
793
794 hnat_set_head_frags(state, skb, -1, hnat_set_iif);
795
796 pre_routing_print(skb, state->in, state->out, __func__);
797
developerfd40db22021-04-29 10:08:25 +0800798 /* packets from external devices -> xxx ,step 1 , learning stage & bound stage*/
799 if (do_ext2ge_fast_try(state->in, skb)) {
800 if (!do_hnat_ext_to_ge(skb, state->in, __func__))
801 return NF_STOLEN;
802 if (!skb)
803 goto drop;
804 return NF_ACCEPT;
805 }
806
807 /* packets form ge -> external device
808 * For standalone wan interface
809 */
810 if (do_ge2ext_fast(state->in, skb)) {
811 if (!do_hnat_ge_to_ext(skb, __func__))
812 return NF_STOLEN;
813 goto drop;
814 }
815
816 return NF_ACCEPT;
817drop:
818 printk_ratelimited(KERN_WARNING
819 "%s:drop (in_dev=%s, iif=0x%x, CB2=0x%x, ppe_hash=0x%x, sport=0x%x, reason=0x%x, alg=0x%x)\n",
820 __func__, state->in->name, skb_hnat_iface(skb),
821 HNAT_SKB_CB2(skb)->magic, skb_hnat_entry(skb),
822 skb_hnat_sport(skb), skb_hnat_reason(skb),
823 skb_hnat_alg(skb));
824
825 return NF_DROP;
826}
827
828static unsigned int
829mtk_hnat_br_nf_local_in(void *priv, struct sk_buff *skb,
830 const struct nf_hook_state *state)
831{
developerfd40db22021-04-29 10:08:25 +0800832 struct vlan_ethhdr *veth;
833
developer34028fb2022-01-11 13:51:29 +0800834 if (IS_HQOS_MODE && hnat_priv->data->whnat) {
developerfd40db22021-04-29 10:08:25 +0800835 veth = (struct vlan_ethhdr *)skb_mac_header(skb);
836
837 if (eth_hdr(skb)->h_proto == HQOS_MAGIC_TAG) {
838 skb_hnat_entry(skb) = ntohs(veth->h_vlan_TCI) & 0x3fff;
839 skb_hnat_reason(skb) = HIT_BIND_FORCE_TO_CPU;
840 }
841 }
developerfd40db22021-04-29 10:08:25 +0800842
843 if (!HAS_HQOS_MAGIC_TAG(skb) && !is_ppe_support_type(skb)) {
844 hnat_set_head_frags(state, skb, 1, hnat_set_alg);
845 return NF_ACCEPT;
846 }
847
848 hnat_set_head_frags(state, skb, -1, hnat_set_iif);
849
850 pre_routing_print(skb, state->in, state->out, __func__);
851
852 if (unlikely(debug_level >= 7)) {
853 hnat_cpu_reason_cnt(skb);
854 if (skb_hnat_reason(skb) == dbg_cpu_reason)
855 foe_dump_pkt(skb);
856 }
857
developerfd40db22021-04-29 10:08:25 +0800858 /* packets from external devices -> xxx ,step 1 , learning stage & bound stage*/
859 if ((skb_hnat_iface(skb) == FOE_MAGIC_EXT) && !is_from_extge(skb) &&
860 !is_multicast_ether_addr(eth_hdr(skb)->h_dest)) {
861 if (!hnat_priv->g_ppdev)
862 hnat_priv->g_ppdev = dev_get_by_name(&init_net, hnat_priv->ppd);
863
864 if (!do_hnat_ext_to_ge(skb, state->in, __func__))
865 return NF_STOLEN;
866 if (!skb)
867 goto drop;
868 return NF_ACCEPT;
869 }
870
871 if (hnat_priv->data->whnat) {
872 if (skb_hnat_iface(skb) == FOE_MAGIC_EXT)
873 clr_from_extge(skb);
874
875 /* packets from external devices -> xxx ,step 2, learning stage */
developeraf07fad2021-11-19 17:53:42 +0800876 if (do_ext2ge_fast_learn(state->in, skb) && (!qos_toggle ||
877 (qos_toggle && eth_hdr(skb)->h_proto != HQOS_MAGIC_TAG))) {
developerfd40db22021-04-29 10:08:25 +0800878 if (!do_hnat_ext_to_ge2(skb, __func__))
879 return NF_STOLEN;
880 goto drop;
881 }
882
883 /* packets form ge -> external device */
884 if (do_ge2ext_fast(state->in, skb)) {
885 if (!do_hnat_ge_to_ext(skb, __func__))
886 return NF_STOLEN;
887 goto drop;
888 }
889 }
890
developerf4c370a2022-10-08 17:01:19 +0800891#if !(defined(CONFIG_MEDIATEK_NETSYS_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3))
developerfd40db22021-04-29 10:08:25 +0800892 /* MapE need remove ipv6 header and pingpong. (bridge mode) */
893 if (do_mape_w2l_fast(state->in, skb)) {
894 if (!do_hnat_mape_w2l_fast(skb, state->in, __func__))
895 return NF_STOLEN;
896 else
897 return NF_ACCEPT;
898 }
developerf4c370a2022-10-08 17:01:19 +0800899#endif
developerfd40db22021-04-29 10:08:25 +0800900 return NF_ACCEPT;
901drop:
902 printk_ratelimited(KERN_WARNING
903 "%s:drop (in_dev=%s, iif=0x%x, CB2=0x%x, ppe_hash=0x%x, sport=0x%x, reason=0x%x, alg=0x%x)\n",
904 __func__, state->in->name, skb_hnat_iface(skb),
905 HNAT_SKB_CB2(skb)->magic, skb_hnat_entry(skb),
906 skb_hnat_sport(skb), skb_hnat_reason(skb),
907 skb_hnat_alg(skb));
908
909 return NF_DROP;
910}
911
912static unsigned int hnat_ipv6_get_nexthop(struct sk_buff *skb,
913 const struct net_device *out,
914 struct flow_offload_hw_path *hw_path)
915{
916 const struct in6_addr *ipv6_nexthop;
917 struct neighbour *neigh = NULL;
918 struct dst_entry *dst = skb_dst(skb);
919 struct ethhdr *eth;
920
921 if (hw_path->flags & FLOW_OFFLOAD_PATH_PPPOE) {
922 memcpy(eth_hdr(skb)->h_source, hw_path->eth_src, ETH_ALEN);
923 memcpy(eth_hdr(skb)->h_dest, hw_path->eth_dest, ETH_ALEN);
924 return 0;
925 }
926
927 rcu_read_lock_bh();
928 ipv6_nexthop =
929 rt6_nexthop((struct rt6_info *)dst, &ipv6_hdr(skb)->daddr);
930 neigh = __ipv6_neigh_lookup_noref(dst->dev, ipv6_nexthop);
931 if (unlikely(!neigh)) {
932 dev_notice(hnat_priv->dev, "%s:No neigh (daddr=%pI6)\n", __func__,
933 &ipv6_hdr(skb)->daddr);
934 rcu_read_unlock_bh();
935 return -1;
936 }
937
938 /* why do we get all zero ethernet address ? */
939 if (!is_valid_ether_addr(neigh->ha)) {
940 rcu_read_unlock_bh();
941 return -1;
942 }
943
944 if (ipv6_hdr(skb)->nexthdr == NEXTHDR_IPIP) {
945 /*copy ether type for DS-Lite and MapE */
946 eth = (struct ethhdr *)(skb->data - ETH_HLEN);
947 eth->h_proto = skb->protocol;
948 } else {
949 eth = eth_hdr(skb);
950 }
951
952 ether_addr_copy(eth->h_dest, neigh->ha);
953 ether_addr_copy(eth->h_source, out->dev_addr);
954
955 rcu_read_unlock_bh();
956
957 return 0;
958}
959
960static unsigned int hnat_ipv4_get_nexthop(struct sk_buff *skb,
961 const struct net_device *out,
962 struct flow_offload_hw_path *hw_path)
963{
964 u32 nexthop;
965 struct neighbour *neigh;
966 struct dst_entry *dst = skb_dst(skb);
967 struct rtable *rt = (struct rtable *)dst;
968 struct net_device *dev = (__force struct net_device *)out;
969
970 if (hw_path->flags & FLOW_OFFLOAD_PATH_PPPOE) {
971 memcpy(eth_hdr(skb)->h_source, hw_path->eth_src, ETH_ALEN);
972 memcpy(eth_hdr(skb)->h_dest, hw_path->eth_dest, ETH_ALEN);
973 return 0;
974 }
975
976 rcu_read_lock_bh();
977 nexthop = (__force u32)rt_nexthop(rt, ip_hdr(skb)->daddr);
978 neigh = __ipv4_neigh_lookup_noref(dev, nexthop);
979 if (unlikely(!neigh)) {
980 dev_notice(hnat_priv->dev, "%s:No neigh (daddr=%pI4)\n", __func__,
981 &ip_hdr(skb)->daddr);
982 rcu_read_unlock_bh();
983 return -1;
984 }
985
986 /* why do we get all zero ethernet address ? */
987 if (!is_valid_ether_addr(neigh->ha)) {
988 rcu_read_unlock_bh();
989 return -1;
990 }
991
992 memcpy(eth_hdr(skb)->h_dest, neigh->ha, ETH_ALEN);
993 memcpy(eth_hdr(skb)->h_source, out->dev_addr, ETH_ALEN);
994
995 rcu_read_unlock_bh();
996
997 return 0;
998}
999
1000static u16 ppe_get_chkbase(struct iphdr *iph)
1001{
1002 u16 org_chksum = ntohs(iph->check);
1003 u16 org_tot_len = ntohs(iph->tot_len);
1004 u16 org_id = ntohs(iph->id);
1005 u16 chksum_tmp, tot_len_tmp, id_tmp;
1006 u32 tmp = 0;
1007 u16 chksum_base = 0;
1008
1009 chksum_tmp = ~(org_chksum);
1010 tot_len_tmp = ~(org_tot_len);
1011 id_tmp = ~(org_id);
1012 tmp = chksum_tmp + tot_len_tmp + id_tmp;
1013 tmp = ((tmp >> 16) & 0x7) + (tmp & 0xFFFF);
1014 tmp = ((tmp >> 16) & 0x7) + (tmp & 0xFFFF);
1015 chksum_base = tmp & 0xFFFF;
1016
1017 return chksum_base;
1018}
1019
1020struct foe_entry ppe_fill_L2_info(struct ethhdr *eth, struct foe_entry entry,
1021 struct flow_offload_hw_path *hw_path)
1022{
1023 switch (entry.bfib1.pkt_type) {
1024 case IPV4_HNAPT:
1025 case IPV4_HNAT:
1026 entry.ipv4_hnapt.dmac_hi = swab32(*((u32 *)eth->h_dest));
1027 entry.ipv4_hnapt.dmac_lo = swab16(*((u16 *)&eth->h_dest[4]));
1028 entry.ipv4_hnapt.smac_hi = swab32(*((u32 *)eth->h_source));
1029 entry.ipv4_hnapt.smac_lo = swab16(*((u16 *)&eth->h_source[4]));
1030 entry.ipv4_hnapt.pppoe_id = hw_path->pppoe_sid;
1031 break;
1032 case IPV4_DSLITE:
1033 case IPV4_MAP_E:
1034 case IPV6_6RD:
1035 case IPV6_5T_ROUTE:
1036 case IPV6_3T_ROUTE:
1037 entry.ipv6_5t_route.dmac_hi = swab32(*((u32 *)eth->h_dest));
1038 entry.ipv6_5t_route.dmac_lo = swab16(*((u16 *)&eth->h_dest[4]));
1039 entry.ipv6_5t_route.smac_hi = swab32(*((u32 *)eth->h_source));
1040 entry.ipv6_5t_route.smac_lo =
1041 swab16(*((u16 *)&eth->h_source[4]));
1042 entry.ipv6_5t_route.pppoe_id = hw_path->pppoe_sid;
1043 break;
1044 }
1045 return entry;
1046}
1047
1048struct foe_entry ppe_fill_info_blk(struct ethhdr *eth, struct foe_entry entry,
1049 struct flow_offload_hw_path *hw_path)
1050{
1051 entry.bfib1.psn = (hw_path->flags & FLOW_OFFLOAD_PATH_PPPOE) ? 1 : 0;
1052 entry.bfib1.vlan_layer += (hw_path->flags & FLOW_OFFLOAD_PATH_VLAN) ? 1 : 0;
1053 entry.bfib1.vpm = (entry.bfib1.vlan_layer) ? 1 : 0;
developerfd40db22021-04-29 10:08:25 +08001054 entry.bfib1.cah = 1;
developerd35bbcc2022-09-28 22:46:01 +08001055 entry.bfib1.time_stamp = (hnat_priv->data->version == MTK_HNAT_V4 ||
1056 hnat_priv->data->version == MTK_HNAT_V5) ?
developerfd40db22021-04-29 10:08:25 +08001057 readl(hnat_priv->fe_base + 0x0010) & (0xFF) :
1058 readl(hnat_priv->fe_base + 0x0010) & (0x7FFF);
1059
1060 switch (entry.bfib1.pkt_type) {
1061 case IPV4_HNAPT:
1062 case IPV4_HNAT:
developer8116b0a2021-08-23 18:07:20 +08001063 if (hnat_priv->data->mcast &&
1064 is_multicast_ether_addr(&eth->h_dest[0])) {
developerfd40db22021-04-29 10:08:25 +08001065 entry.ipv4_hnapt.iblk2.mcast = 1;
1066 if (hnat_priv->data->version == MTK_HNAT_V3) {
1067 entry.bfib1.sta = 1;
1068 entry.ipv4_hnapt.m_timestamp = foe_timestamp(hnat_priv);
1069 }
1070 } else {
1071 entry.ipv4_hnapt.iblk2.mcast = 0;
1072 }
1073
1074 entry.ipv4_hnapt.iblk2.port_ag =
developerd35bbcc2022-09-28 22:46:01 +08001075 (hnat_priv->data->version == MTK_HNAT_V4 ||
1076 hnat_priv->data->version == MTK_HNAT_V5) ? 0xf : 0x3f;
developerfd40db22021-04-29 10:08:25 +08001077 break;
1078 case IPV4_DSLITE:
1079 case IPV4_MAP_E:
1080 case IPV6_6RD:
1081 case IPV6_5T_ROUTE:
1082 case IPV6_3T_ROUTE:
developer8116b0a2021-08-23 18:07:20 +08001083 if (hnat_priv->data->mcast &&
1084 is_multicast_ether_addr(&eth->h_dest[0])) {
developerfd40db22021-04-29 10:08:25 +08001085 entry.ipv6_5t_route.iblk2.mcast = 1;
1086 if (hnat_priv->data->version == MTK_HNAT_V3) {
1087 entry.bfib1.sta = 1;
1088 entry.ipv4_hnapt.m_timestamp = foe_timestamp(hnat_priv);
1089 }
1090 } else {
1091 entry.ipv6_5t_route.iblk2.mcast = 0;
1092 }
1093
1094 entry.ipv6_5t_route.iblk2.port_ag =
developerd35bbcc2022-09-28 22:46:01 +08001095 (hnat_priv->data->version == MTK_HNAT_V4 ||
1096 hnat_priv->data->version == MTK_HNAT_V5) ? 0xf : 0x3f;
developerfd40db22021-04-29 10:08:25 +08001097 break;
1098 }
1099 return entry;
1100}
1101
developerfd40db22021-04-29 10:08:25 +08001102static unsigned int skb_to_hnat_info(struct sk_buff *skb,
1103 const struct net_device *dev,
1104 struct foe_entry *foe,
1105 struct flow_offload_hw_path *hw_path)
1106{
1107 struct foe_entry entry = { 0 };
1108 int whnat = IS_WHNAT(dev);
1109 struct ethhdr *eth;
1110 struct iphdr *iph;
1111 struct ipv6hdr *ip6h;
1112 struct tcpudphdr _ports;
1113 const struct tcpudphdr *pptr;
1114 u32 gmac = NR_DISCARD;
1115 int udp = 0;
1116 u32 qid = 0;
developeraf07fad2021-11-19 17:53:42 +08001117 u32 port_id = 0;
developerfd40db22021-04-29 10:08:25 +08001118 int mape = 0;
1119
1120 if (ipv6_hdr(skb)->nexthdr == NEXTHDR_IPIP)
1121 /* point to ethernet header for DS-Lite and MapE */
1122 eth = (struct ethhdr *)(skb->data - ETH_HLEN);
1123 else
1124 eth = eth_hdr(skb);
developer8116b0a2021-08-23 18:07:20 +08001125
1126 /*do not bind multicast if PPE mcast not enable*/
1127 if (!hnat_priv->data->mcast && is_multicast_ether_addr(eth->h_dest))
1128 return 0;
developerfd40db22021-04-29 10:08:25 +08001129
1130 entry.bfib1.pkt_type = foe->udib1.pkt_type; /* Get packte type state*/
developerf94d8862022-03-29 10:11:17 +08001131 entry.bfib1.state = foe->udib1.state;
1132
developerd35bbcc2022-09-28 22:46:01 +08001133#if defined(CONFIG_MEDIATEK_NETSYS_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developerfd40db22021-04-29 10:08:25 +08001134 entry.bfib1.sp = foe->udib1.sp;
1135#endif
1136
1137 switch (ntohs(eth->h_proto)) {
1138 case ETH_P_IP:
1139 iph = ip_hdr(skb);
1140 switch (iph->protocol) {
1141 case IPPROTO_UDP:
1142 udp = 1;
1143 /* fallthrough */
1144 case IPPROTO_TCP:
1145 entry.ipv4_hnapt.etype = htons(ETH_P_IP);
1146
1147 /* DS-Lite WAN->LAN */
1148 if (entry.ipv4_hnapt.bfib1.pkt_type == IPV4_DSLITE ||
1149 entry.ipv4_hnapt.bfib1.pkt_type == IPV4_MAP_E) {
1150 entry.ipv4_dslite.sip = foe->ipv4_dslite.sip;
1151 entry.ipv4_dslite.dip = foe->ipv4_dslite.dip;
1152 entry.ipv4_dslite.sport =
1153 foe->ipv4_dslite.sport;
1154 entry.ipv4_dslite.dport =
1155 foe->ipv4_dslite.dport;
1156
developerd35bbcc2022-09-28 22:46:01 +08001157#if defined(CONFIG_MEDIATEK_NETSYS_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developerfd40db22021-04-29 10:08:25 +08001158 if (entry.bfib1.pkt_type == IPV4_MAP_E) {
1159 pptr = skb_header_pointer(skb,
1160 iph->ihl * 4,
1161 sizeof(_ports),
1162 &_ports);
developer4c32b7a2021-11-13 16:46:43 +08001163 if (unlikely(!pptr))
1164 return -1;
developerfd40db22021-04-29 10:08:25 +08001165
developerd35bbcc2022-09-28 22:46:01 +08001166 entry.ipv4_mape.new_sip =
developerfd40db22021-04-29 10:08:25 +08001167 ntohl(iph->saddr);
developerd35bbcc2022-09-28 22:46:01 +08001168 entry.ipv4_mape.new_dip =
developerfd40db22021-04-29 10:08:25 +08001169 ntohl(iph->daddr);
developerd35bbcc2022-09-28 22:46:01 +08001170 entry.ipv4_mape.new_sport =
developerfd40db22021-04-29 10:08:25 +08001171 ntohs(pptr->src);
developerd35bbcc2022-09-28 22:46:01 +08001172 entry.ipv4_mape.new_dport =
developerfd40db22021-04-29 10:08:25 +08001173 ntohs(pptr->dst);
1174 }
1175#endif
1176
1177 entry.ipv4_dslite.tunnel_sipv6_0 =
1178 foe->ipv4_dslite.tunnel_sipv6_0;
1179 entry.ipv4_dslite.tunnel_sipv6_1 =
1180 foe->ipv4_dslite.tunnel_sipv6_1;
1181 entry.ipv4_dslite.tunnel_sipv6_2 =
1182 foe->ipv4_dslite.tunnel_sipv6_2;
1183 entry.ipv4_dslite.tunnel_sipv6_3 =
1184 foe->ipv4_dslite.tunnel_sipv6_3;
1185
1186 entry.ipv4_dslite.tunnel_dipv6_0 =
1187 foe->ipv4_dslite.tunnel_dipv6_0;
1188 entry.ipv4_dslite.tunnel_dipv6_1 =
1189 foe->ipv4_dslite.tunnel_dipv6_1;
1190 entry.ipv4_dslite.tunnel_dipv6_2 =
1191 foe->ipv4_dslite.tunnel_dipv6_2;
1192 entry.ipv4_dslite.tunnel_dipv6_3 =
1193 foe->ipv4_dslite.tunnel_dipv6_3;
1194
1195 entry.ipv4_dslite.bfib1.rmt = 1;
1196 entry.ipv4_dslite.iblk2.dscp = iph->tos;
1197 entry.ipv4_dslite.vlan1 = hw_path->vlan_id;
1198 if (hnat_priv->data->per_flow_accounting)
1199 entry.ipv4_dslite.iblk2.mibf = 1;
1200
1201 } else {
1202 entry.ipv4_hnapt.iblk2.dscp = iph->tos;
1203 if (hnat_priv->data->per_flow_accounting)
1204 entry.ipv4_hnapt.iblk2.mibf = 1;
1205
1206 entry.ipv4_hnapt.vlan1 = hw_path->vlan_id;
1207
developerd35bbcc2022-09-28 22:46:01 +08001208 if (skb->vlan_tci && FROM_GE_WAN(skb) &&
1209 IS_LAN_GRP(dev)) {
developerfd40db22021-04-29 10:08:25 +08001210 entry.bfib1.vlan_layer += 1;
1211
1212 if (entry.ipv4_hnapt.vlan1)
1213 entry.ipv4_hnapt.vlan2 = (skb->vlan_tci & VLAN_VID_MASK);
1214 else
1215 entry.ipv4_hnapt.vlan1 = (skb->vlan_tci & VLAN_VID_MASK);
1216 }
1217
1218 entry.ipv4_hnapt.sip = foe->ipv4_hnapt.sip;
1219 entry.ipv4_hnapt.dip = foe->ipv4_hnapt.dip;
1220 entry.ipv4_hnapt.sport = foe->ipv4_hnapt.sport;
1221 entry.ipv4_hnapt.dport = foe->ipv4_hnapt.dport;
1222
1223 entry.ipv4_hnapt.new_sip = ntohl(iph->saddr);
1224 entry.ipv4_hnapt.new_dip = ntohl(iph->daddr);
1225 }
1226
1227 entry.ipv4_hnapt.bfib1.udp = udp;
1228 if (IS_IPV4_HNAPT(foe)) {
1229 pptr = skb_header_pointer(skb, iph->ihl * 4,
1230 sizeof(_ports),
1231 &_ports);
developer4c32b7a2021-11-13 16:46:43 +08001232 if (unlikely(!pptr))
1233 return -1;
1234
developerfd40db22021-04-29 10:08:25 +08001235 entry.ipv4_hnapt.new_sport = ntohs(pptr->src);
1236 entry.ipv4_hnapt.new_dport = ntohs(pptr->dst);
1237 }
1238
1239 break;
1240
1241 default:
1242 return -1;
1243 }
1244 trace_printk(
1245 "[%s]skb->head=%p, skb->data=%p,ip_hdr=%p, skb->len=%d, skb->data_len=%d\n",
1246 __func__, skb->head, skb->data, iph, skb->len,
1247 skb->data_len);
1248 break;
1249
1250 case ETH_P_IPV6:
1251 ip6h = ipv6_hdr(skb);
1252 switch (ip6h->nexthdr) {
1253 case NEXTHDR_UDP:
1254 udp = 1;
1255 /* fallthrough */
1256 case NEXTHDR_TCP: /* IPv6-5T or IPv6-3T */
1257 entry.ipv6_5t_route.etype = htons(ETH_P_IPV6);
1258
1259 entry.ipv6_5t_route.vlan1 = hw_path->vlan_id;
1260
developerd35bbcc2022-09-28 22:46:01 +08001261 if (skb->vlan_tci && FROM_GE_WAN(skb) &&
1262 IS_LAN_GRP(dev)) {
developerfd40db22021-04-29 10:08:25 +08001263 entry.bfib1.vlan_layer += 1;
1264
1265 if (entry.ipv6_5t_route.vlan1)
1266 entry.ipv6_5t_route.vlan2 = (skb->vlan_tci & VLAN_VID_MASK);
1267 else
1268 entry.ipv6_5t_route.vlan1 = (skb->vlan_tci & VLAN_VID_MASK);
1269 }
1270
1271 if (hnat_priv->data->per_flow_accounting)
1272 entry.ipv6_5t_route.iblk2.mibf = 1;
1273 entry.ipv6_5t_route.bfib1.udp = udp;
1274
1275 if (IS_IPV6_6RD(foe)) {
1276 entry.ipv6_5t_route.bfib1.rmt = 1;
1277 entry.ipv6_6rd.tunnel_sipv4 =
1278 foe->ipv6_6rd.tunnel_sipv4;
1279 entry.ipv6_6rd.tunnel_dipv4 =
1280 foe->ipv6_6rd.tunnel_dipv4;
1281 }
1282
1283 entry.ipv6_3t_route.ipv6_sip0 =
1284 foe->ipv6_3t_route.ipv6_sip0;
1285 entry.ipv6_3t_route.ipv6_sip1 =
1286 foe->ipv6_3t_route.ipv6_sip1;
1287 entry.ipv6_3t_route.ipv6_sip2 =
1288 foe->ipv6_3t_route.ipv6_sip2;
1289 entry.ipv6_3t_route.ipv6_sip3 =
1290 foe->ipv6_3t_route.ipv6_sip3;
1291
1292 entry.ipv6_3t_route.ipv6_dip0 =
1293 foe->ipv6_3t_route.ipv6_dip0;
1294 entry.ipv6_3t_route.ipv6_dip1 =
1295 foe->ipv6_3t_route.ipv6_dip1;
1296 entry.ipv6_3t_route.ipv6_dip2 =
1297 foe->ipv6_3t_route.ipv6_dip2;
1298 entry.ipv6_3t_route.ipv6_dip3 =
1299 foe->ipv6_3t_route.ipv6_dip3;
1300
developer729f0272021-06-09 17:28:38 +08001301 if (IS_IPV6_3T_ROUTE(foe)) {
1302 entry.ipv6_3t_route.prot =
1303 foe->ipv6_3t_route.prot;
1304 entry.ipv6_3t_route.hph =
1305 foe->ipv6_3t_route.hph;
1306 }
1307
developerfd40db22021-04-29 10:08:25 +08001308 if (IS_IPV6_5T_ROUTE(foe) || IS_IPV6_6RD(foe)) {
1309 entry.ipv6_5t_route.sport =
1310 foe->ipv6_5t_route.sport;
1311 entry.ipv6_5t_route.dport =
1312 foe->ipv6_5t_route.dport;
1313 }
1314 entry.ipv6_5t_route.iblk2.dscp =
1315 (ip6h->priority << 4 |
1316 (ip6h->flow_lbl[0] >> 4));
1317 break;
1318
1319 case NEXTHDR_IPIP:
1320 if ((!mape_toggle &&
1321 entry.bfib1.pkt_type == IPV4_DSLITE) ||
1322 (mape_toggle &&
1323 entry.bfib1.pkt_type == IPV4_MAP_E)) {
1324 /* DS-Lite LAN->WAN */
1325 entry.ipv4_dslite.bfib1.udp =
1326 foe->ipv4_dslite.bfib1.udp;
1327 entry.ipv4_dslite.sip = foe->ipv4_dslite.sip;
1328 entry.ipv4_dslite.dip = foe->ipv4_dslite.dip;
1329 entry.ipv4_dslite.sport =
1330 foe->ipv4_dslite.sport;
1331 entry.ipv4_dslite.dport =
1332 foe->ipv4_dslite.dport;
1333
1334 entry.ipv4_dslite.tunnel_sipv6_0 =
1335 ntohl(ip6h->saddr.s6_addr32[0]);
1336 entry.ipv4_dslite.tunnel_sipv6_1 =
1337 ntohl(ip6h->saddr.s6_addr32[1]);
1338 entry.ipv4_dslite.tunnel_sipv6_2 =
1339 ntohl(ip6h->saddr.s6_addr32[2]);
1340 entry.ipv4_dslite.tunnel_sipv6_3 =
1341 ntohl(ip6h->saddr.s6_addr32[3]);
1342
1343 entry.ipv4_dslite.tunnel_dipv6_0 =
1344 ntohl(ip6h->daddr.s6_addr32[0]);
1345 entry.ipv4_dslite.tunnel_dipv6_1 =
1346 ntohl(ip6h->daddr.s6_addr32[1]);
1347 entry.ipv4_dslite.tunnel_dipv6_2 =
1348 ntohl(ip6h->daddr.s6_addr32[2]);
1349 entry.ipv4_dslite.tunnel_dipv6_3 =
1350 ntohl(ip6h->daddr.s6_addr32[3]);
1351
1352 ppe_fill_flow_lbl(&entry, ip6h);
1353
1354 entry.ipv4_dslite.priority = ip6h->priority;
1355 entry.ipv4_dslite.hop_limit = ip6h->hop_limit;
1356 entry.ipv4_dslite.vlan1 = hw_path->vlan_id;
1357 if (hnat_priv->data->per_flow_accounting)
1358 entry.ipv4_dslite.iblk2.mibf = 1;
developer25fc8c02022-05-06 16:24:02 +08001359 /* Map-E LAN->WAN record inner IPv4 header info. */
1360#if defined(CONFIG_MEDIATEK_NETSYS_V2)
1361 if (mape_toggle) {
1362 entry.ipv4_dslite.iblk2.dscp = foe->ipv4_dslite.iblk2.dscp;
developerd35bbcc2022-09-28 22:46:01 +08001363 entry.ipv4_mape.new_sip = foe->ipv4_mape.new_sip;
1364 entry.ipv4_mape.new_dip = foe->ipv4_mape.new_dip;
1365 entry.ipv4_mape.new_sport = foe->ipv4_mape.new_sport;
1366 entry.ipv4_mape.new_dport = foe->ipv4_mape.new_dport;
developer25fc8c02022-05-06 16:24:02 +08001367 }
1368#endif
developerfd40db22021-04-29 10:08:25 +08001369 } else if (mape_toggle &&
1370 entry.bfib1.pkt_type == IPV4_HNAPT) {
1371 /* MapE LAN -> WAN */
1372 mape = 1;
1373 entry.ipv4_hnapt.iblk2.dscp =
1374 foe->ipv4_hnapt.iblk2.dscp;
1375 if (hnat_priv->data->per_flow_accounting)
1376 entry.ipv4_hnapt.iblk2.mibf = 1;
1377
developerbb816412021-06-11 15:43:44 +08001378 if (IS_GMAC1_MODE)
1379 entry.ipv4_hnapt.vlan1 = 1;
1380 else
1381 entry.ipv4_hnapt.vlan1 = hw_path->vlan_id;
developerfd40db22021-04-29 10:08:25 +08001382
1383 entry.ipv4_hnapt.sip = foe->ipv4_hnapt.sip;
1384 entry.ipv4_hnapt.dip = foe->ipv4_hnapt.dip;
1385 entry.ipv4_hnapt.sport = foe->ipv4_hnapt.sport;
1386 entry.ipv4_hnapt.dport = foe->ipv4_hnapt.dport;
1387
1388 entry.ipv4_hnapt.new_sip =
1389 foe->ipv4_hnapt.new_sip;
1390 entry.ipv4_hnapt.new_dip =
1391 foe->ipv4_hnapt.new_dip;
1392 entry.ipv4_hnapt.etype = htons(ETH_P_IP);
1393
developer34028fb2022-01-11 13:51:29 +08001394 if (IS_HQOS_MODE) {
developeraf07fad2021-11-19 17:53:42 +08001395 entry.ipv4_hnapt.iblk2.qid =
developerd35bbcc2022-09-28 22:46:01 +08001396 (hnat_priv->data->version == MTK_HNAT_V4 ||
1397 hnat_priv->data->version == MTK_HNAT_V5) ?
developeraf07fad2021-11-19 17:53:42 +08001398 skb->mark & 0x7f : skb->mark & 0xf;
developerd35bbcc2022-09-28 22:46:01 +08001399#if defined(CONFIG_MEDIATEK_NETSYS_V3)
1400 entry.ipv4_hnapt.tport_id = 1;
1401#else
developeraf07fad2021-11-19 17:53:42 +08001402 entry.ipv4_hnapt.iblk2.fqos = 1;
developerd35bbcc2022-09-28 22:46:01 +08001403#endif
developeraf07fad2021-11-19 17:53:42 +08001404 }
developerfd40db22021-04-29 10:08:25 +08001405
1406 entry.ipv4_hnapt.bfib1.udp =
1407 foe->ipv4_hnapt.bfib1.udp;
1408
1409 entry.ipv4_hnapt.new_sport =
1410 foe->ipv4_hnapt.new_sport;
1411 entry.ipv4_hnapt.new_dport =
1412 foe->ipv4_hnapt.new_dport;
1413 mape_l2w_v6h = *ip6h;
1414 }
1415 break;
1416
1417 default:
1418 return -1;
1419 }
1420
1421 trace_printk(
1422 "[%s]skb->head=%p, skb->data=%p,ipv6_hdr=%p, skb->len=%d, skb->data_len=%d\n",
1423 __func__, skb->head, skb->data, ip6h, skb->len,
1424 skb->data_len);
1425 break;
1426
1427 default:
developerfd40db22021-04-29 10:08:25 +08001428 iph = ip_hdr(skb);
1429 switch (entry.bfib1.pkt_type) {
1430 case IPV6_6RD: /* 6RD LAN->WAN */
1431 entry.ipv6_6rd.ipv6_sip0 = foe->ipv6_6rd.ipv6_sip0;
1432 entry.ipv6_6rd.ipv6_sip1 = foe->ipv6_6rd.ipv6_sip1;
1433 entry.ipv6_6rd.ipv6_sip2 = foe->ipv6_6rd.ipv6_sip2;
1434 entry.ipv6_6rd.ipv6_sip3 = foe->ipv6_6rd.ipv6_sip3;
1435
1436 entry.ipv6_6rd.ipv6_dip0 = foe->ipv6_6rd.ipv6_dip0;
1437 entry.ipv6_6rd.ipv6_dip1 = foe->ipv6_6rd.ipv6_dip1;
1438 entry.ipv6_6rd.ipv6_dip2 = foe->ipv6_6rd.ipv6_dip2;
1439 entry.ipv6_6rd.ipv6_dip3 = foe->ipv6_6rd.ipv6_dip3;
1440
1441 entry.ipv6_6rd.sport = foe->ipv6_6rd.sport;
1442 entry.ipv6_6rd.dport = foe->ipv6_6rd.dport;
1443 entry.ipv6_6rd.tunnel_sipv4 = ntohl(iph->saddr);
1444 entry.ipv6_6rd.tunnel_dipv4 = ntohl(iph->daddr);
1445 entry.ipv6_6rd.hdr_chksum = ppe_get_chkbase(iph);
1446 entry.ipv6_6rd.flag = (ntohs(iph->frag_off) >> 13);
1447 entry.ipv6_6rd.ttl = iph->ttl;
1448 entry.ipv6_6rd.dscp = iph->tos;
1449 entry.ipv6_6rd.per_flow_6rd_id = 1;
1450 entry.ipv6_6rd.vlan1 = hw_path->vlan_id;
1451 if (hnat_priv->data->per_flow_accounting)
1452 entry.ipv6_6rd.iblk2.mibf = 1;
1453 break;
1454
1455 default:
1456 return -1;
1457 }
1458 }
1459
1460 /* Fill Layer2 Info.*/
1461 entry = ppe_fill_L2_info(eth, entry, hw_path);
1462
1463 /* Fill Info Blk*/
1464 entry = ppe_fill_info_blk(eth, entry, hw_path);
1465
1466 if (IS_LAN(dev)) {
1467 if (IS_DSA_LAN(dev))
developeraf07fad2021-11-19 17:53:42 +08001468 port_id = hnat_dsa_fill_stag(dev, &entry, hw_path,
1469 ntohs(eth->h_proto),
1470 mape);
developerfd40db22021-04-29 10:08:25 +08001471
1472 if (IS_BOND_MODE)
1473 gmac = ((skb_hnat_entry(skb) >> 1) % hnat_priv->gmac_num) ?
1474 NR_GMAC2_PORT : NR_GMAC1_PORT;
1475 else
1476 gmac = NR_GMAC1_PORT;
developerd35bbcc2022-09-28 22:46:01 +08001477 } else if (IS_LAN2(dev)) {
1478 gmac = NR_GMAC3_PORT;
developerfd40db22021-04-29 10:08:25 +08001479 } else if (IS_WAN(dev)) {
1480 if (IS_DSA_WAN(dev))
developeraf07fad2021-11-19 17:53:42 +08001481 port_id = hnat_dsa_fill_stag(dev,&entry, hw_path,
1482 ntohs(eth->h_proto),
1483 mape);
developerfd40db22021-04-29 10:08:25 +08001484 if (mape_toggle && mape == 1) {
1485 gmac = NR_PDMA_PORT;
1486 /* Set act_dp = wan_dev */
1487 entry.ipv4_hnapt.act_dp = dev->ifindex;
1488 } else {
1489 gmac = (IS_GMAC1_MODE) ? NR_GMAC1_PORT : NR_GMAC2_PORT;
1490 }
developerd35bbcc2022-09-28 22:46:01 +08001491 } else if (IS_EXT(dev) && (FROM_GE_PPD(skb) || FROM_GE_LAN_GRP(skb) ||
developer99506e52021-06-30 22:03:02 +08001492 FROM_GE_WAN(skb) || FROM_GE_VIRTUAL(skb) || FROM_WED(skb))) {
developerfd40db22021-04-29 10:08:25 +08001493 if (!hnat_priv->data->whnat && IS_GMAC1_MODE) {
1494 entry.bfib1.vpm = 1;
1495 entry.bfib1.vlan_layer = 1;
1496
1497 if (FROM_GE_LAN(skb))
1498 entry.ipv4_hnapt.vlan1 = 1;
1499 else if (FROM_GE_WAN(skb) || FROM_GE_VIRTUAL(skb))
1500 entry.ipv4_hnapt.vlan1 = 2;
1501 }
1502
1503 trace_printk("learn of lan or wan(iif=%x) --> %s(ext)\n",
1504 skb_hnat_iface(skb), dev->name);
1505 /* To CPU then stolen by pre-routing hant hook of LAN/WAN
1506 * Current setting is PDMA RX.
1507 */
1508 gmac = NR_PDMA_PORT;
1509 if (IS_IPV4_GRP(foe))
1510 entry.ipv4_hnapt.act_dp = dev->ifindex;
1511 else
1512 entry.ipv6_5t_route.act_dp = dev->ifindex;
1513 } else {
1514 printk_ratelimited(KERN_WARNING
1515 "Unknown case of dp, iif=%x --> %s\n",
1516 skb_hnat_iface(skb), dev->name);
1517
1518 return 0;
1519 }
1520
developerafff5662022-06-29 10:09:56 +08001521 if (IS_HQOS_MODE || skb->mark >= MAX_PPPQ_PORT_NUM)
developeraf07fad2021-11-19 17:53:42 +08001522 qid = skb->mark & (MTK_QDMA_TX_MASK);
developerdac6ac72022-08-18 15:32:19 +08001523 else if (IS_PPPQ_MODE && (IS_DSA_1G_LAN(dev) || IS_DSA_WAN(dev) ||
1524 (FROM_WED(skb) && IS_DSA_LAN(dev))))
developeraf07fad2021-11-19 17:53:42 +08001525 qid = port_id & MTK_QDMA_TX_MASK;
1526 else
1527 qid = 0;
developerfd40db22021-04-29 10:08:25 +08001528
1529 if (IS_IPV4_GRP(foe)) {
1530 entry.ipv4_hnapt.iblk2.dp = gmac;
1531 entry.ipv4_hnapt.iblk2.port_mg =
1532 (hnat_priv->data->version == MTK_HNAT_V1) ? 0x3f : 0;
developer24948202021-11-24 17:38:27 +08001533
developeraf07fad2021-11-19 17:53:42 +08001534 if (qos_toggle) {
developerd35bbcc2022-09-28 22:46:01 +08001535 if (hnat_priv->data->version == MTK_HNAT_V4 ||
1536 hnat_priv->data->version == MTK_HNAT_V5) {
developeraf07fad2021-11-19 17:53:42 +08001537 entry.ipv4_hnapt.iblk2.qid = qid & 0x7f;
1538 } else {
1539 /* qid[5:0]= port_mg[1:0]+ qid[3:0] */
1540 entry.ipv4_hnapt.iblk2.qid = qid & 0xf;
1541 if (hnat_priv->data->version != MTK_HNAT_V1)
1542 entry.ipv4_hnapt.iblk2.port_mg |=
1543 ((qid >> 4) & 0x3);
developerfd40db22021-04-29 10:08:25 +08001544
developerd35bbcc2022-09-28 22:46:01 +08001545 if (((IS_EXT(dev) && (FROM_GE_LAN_GRP(skb) ||
developeraf07fad2021-11-19 17:53:42 +08001546 FROM_GE_WAN(skb) || FROM_GE_VIRTUAL(skb))) ||
1547 ((mape_toggle && mape == 1) && !FROM_EXT(skb))) &&
1548 (!whnat)) {
1549 entry.ipv4_hnapt.etype = htons(HQOS_MAGIC_TAG);
1550 entry.ipv4_hnapt.vlan1 = skb_hnat_entry(skb);
1551 entry.bfib1.vlan_layer = 1;
1552 }
developerfd40db22021-04-29 10:08:25 +08001553 }
developerfd40db22021-04-29 10:08:25 +08001554
developer34028fb2022-01-11 13:51:29 +08001555 if (FROM_EXT(skb) || skb_hnat_sport(skb) == NR_QDMA_PORT ||
1556 (IS_PPPQ_MODE && !IS_DSA_LAN(dev) && !IS_DSA_WAN(dev)))
developeraf07fad2021-11-19 17:53:42 +08001557 entry.ipv4_hnapt.iblk2.fqos = 0;
1558 else
developerd35bbcc2022-09-28 22:46:01 +08001559#if defined(CONFIG_MEDIATEK_NETSYS_V3)
1560 entry.ipv4_hnapt.tport_id = 1;
1561#else
developer399ec072022-06-24 16:07:41 +08001562 entry.ipv4_hnapt.iblk2.fqos =
1563 (!IS_PPPQ_MODE || (IS_PPPQ_MODE &&
developerdac6ac72022-08-18 15:32:19 +08001564 (IS_DSA_1G_LAN(dev) || IS_DSA_WAN(dev) ||
1565 (FROM_WED(skb) && IS_DSA_LAN(dev)))));
developerd35bbcc2022-09-28 22:46:01 +08001566#endif
developeraf07fad2021-11-19 17:53:42 +08001567 } else {
developerfd40db22021-04-29 10:08:25 +08001568 entry.ipv4_hnapt.iblk2.fqos = 0;
developeraf07fad2021-11-19 17:53:42 +08001569 }
developerfd40db22021-04-29 10:08:25 +08001570 } else {
1571 entry.ipv6_5t_route.iblk2.dp = gmac;
1572 entry.ipv6_5t_route.iblk2.port_mg =
1573 (hnat_priv->data->version == MTK_HNAT_V1) ? 0x3f : 0;
developer24948202021-11-24 17:38:27 +08001574
developeraf07fad2021-11-19 17:53:42 +08001575 if (qos_toggle) {
developerd35bbcc2022-09-28 22:46:01 +08001576 if (hnat_priv->data->version == MTK_HNAT_V4 ||
1577 hnat_priv->data->version == MTK_HNAT_V5) {
developeraf07fad2021-11-19 17:53:42 +08001578 entry.ipv6_5t_route.iblk2.qid = qid & 0x7f;
1579 } else {
1580 /* qid[5:0]= port_mg[1:0]+ qid[3:0] */
1581 entry.ipv6_5t_route.iblk2.qid = qid & 0xf;
1582 if (hnat_priv->data->version != MTK_HNAT_V1)
1583 entry.ipv6_5t_route.iblk2.port_mg |=
1584 ((qid >> 4) & 0x3);
developerfd40db22021-04-29 10:08:25 +08001585
developerd35bbcc2022-09-28 22:46:01 +08001586 if (IS_EXT(dev) && (FROM_GE_LAN_GRP(skb) ||
developeraf07fad2021-11-19 17:53:42 +08001587 FROM_GE_WAN(skb) || FROM_GE_VIRTUAL(skb)) &&
1588 (!whnat)) {
1589 entry.ipv6_5t_route.etype = htons(HQOS_MAGIC_TAG);
1590 entry.ipv6_5t_route.vlan1 = skb_hnat_entry(skb);
1591 entry.bfib1.vlan_layer = 1;
1592 }
developerfd40db22021-04-29 10:08:25 +08001593 }
developerfd40db22021-04-29 10:08:25 +08001594
developer34028fb2022-01-11 13:51:29 +08001595 if (FROM_EXT(skb) ||
1596 (IS_PPPQ_MODE && !IS_DSA_LAN(dev) && !IS_DSA_WAN(dev)))
developeraf07fad2021-11-19 17:53:42 +08001597 entry.ipv6_5t_route.iblk2.fqos = 0;
1598 else
developerd35bbcc2022-09-28 22:46:01 +08001599#if defined(CONFIG_MEDIATEK_NETSYS_V3)
1600 entry.ipv6_5t_route.tport_id = 1;
1601#else
developer399ec072022-06-24 16:07:41 +08001602 entry.ipv6_5t_route.iblk2.fqos =
1603 (!IS_PPPQ_MODE || (IS_PPPQ_MODE &&
developerdac6ac72022-08-18 15:32:19 +08001604 (IS_DSA_1G_LAN(dev) || IS_DSA_WAN(dev) ||
1605 (FROM_WED(skb) && IS_DSA_LAN(dev)))));
developerd35bbcc2022-09-28 22:46:01 +08001606#endif
developeraf07fad2021-11-19 17:53:42 +08001607 } else {
developerfd40db22021-04-29 10:08:25 +08001608 entry.ipv6_5t_route.iblk2.fqos = 0;
developeraf07fad2021-11-19 17:53:42 +08001609 }
developerfd40db22021-04-29 10:08:25 +08001610 }
1611
developer60e60962021-06-15 21:05:07 +08001612 /* The INFO2.port_mg and 2nd VLAN ID fields of PPE entry are redefined
1613 * by Wi-Fi whnat engine. These data and INFO2.dp will be updated and
1614 * the entry is set to BIND state in mtk_sw_nat_hook_tx().
1615 */
developer7b36dca2022-05-19 18:29:10 +08001616 if (!whnat) {
1617 entry.bfib1.ttl = 1;
developer60e60962021-06-15 21:05:07 +08001618 entry.bfib1.state = BIND;
developer7b36dca2022-05-19 18:29:10 +08001619 }
developer60e60962021-06-15 21:05:07 +08001620
developerbc552cc2022-03-15 16:19:27 +08001621 wmb();
developerfd40db22021-04-29 10:08:25 +08001622 memcpy(foe, &entry, sizeof(entry));
1623 /*reset statistic for this entry*/
1624 if (hnat_priv->data->per_flow_accounting)
developer471f6562021-05-10 20:48:34 +08001625 memset(&hnat_priv->acct[skb_hnat_ppe(skb)][skb_hnat_entry(skb)],
1626 0, sizeof(struct mib_entry));
developerfd40db22021-04-29 10:08:25 +08001627
developerfdfe1572021-09-13 16:56:33 +08001628 skb_hnat_filled(skb) = HNAT_INFO_FILLED;
developerfd40db22021-04-29 10:08:25 +08001629
1630 return 0;
1631}
1632
1633int mtk_sw_nat_hook_tx(struct sk_buff *skb, int gmac_no)
1634{
1635 struct foe_entry *entry;
1636 struct ethhdr *eth;
developerbc552cc2022-03-15 16:19:27 +08001637 struct hnat_bind_info_blk bfib1_tx;
developerfd40db22021-04-29 10:08:25 +08001638
developerfdfe1572021-09-13 16:56:33 +08001639 if (skb_hnat_alg(skb) || !is_hnat_info_filled(skb) ||
1640 !is_magic_tag_valid(skb) || !IS_SPACE_AVAILABLE_HEAD(skb))
developerfd40db22021-04-29 10:08:25 +08001641 return NF_ACCEPT;
1642
1643 trace_printk(
1644 "[%s]entry=%x reason=%x gmac_no=%x wdmaid=%x rxid=%x wcid=%x bssid=%x\n",
1645 __func__, skb_hnat_entry(skb), skb_hnat_reason(skb), gmac_no,
1646 skb_hnat_wdma_id(skb), skb_hnat_bss_id(skb),
1647 skb_hnat_wc_id(skb), skb_hnat_rx_id(skb));
1648
developer99506e52021-06-30 22:03:02 +08001649 if ((gmac_no != NR_WDMA0_PORT) && (gmac_no != NR_WDMA1_PORT) &&
1650 (gmac_no != NR_WHNAT_WDMA_PORT))
1651 return NF_ACCEPT;
1652
developerfd40db22021-04-29 10:08:25 +08001653 if (!skb_hnat_is_hashed(skb))
1654 return NF_ACCEPT;
1655
developer955a6f62021-07-26 10:54:39 +08001656 if (skb_hnat_entry(skb) >= hnat_priv->foe_etry_num ||
1657 skb_hnat_ppe(skb) >= CFG_PPE_NUM)
1658 return NF_ACCEPT;
1659
developer471f6562021-05-10 20:48:34 +08001660 entry = &hnat_priv->foe_table_cpu[skb_hnat_ppe(skb)][skb_hnat_entry(skb)];
developerfd40db22021-04-29 10:08:25 +08001661 if (entry_hnat_is_bound(entry))
1662 return NF_ACCEPT;
1663
1664 if (skb_hnat_reason(skb) != HIT_UNBIND_RATE_REACH)
1665 return NF_ACCEPT;
1666
1667 eth = eth_hdr(skb);
developerbc552cc2022-03-15 16:19:27 +08001668 memcpy(&bfib1_tx, &entry->bfib1, sizeof(entry->bfib1));
developer8116b0a2021-08-23 18:07:20 +08001669
1670 /*not bind multicast if PPE mcast not enable*/
developerfdfe1572021-09-13 16:56:33 +08001671 if (!hnat_priv->data->mcast) {
1672 if (is_multicast_ether_addr(eth->h_dest))
1673 return NF_ACCEPT;
1674
1675 if (IS_IPV4_GRP(entry))
1676 entry->ipv4_hnapt.iblk2.mcast = 0;
1677 else
1678 entry->ipv6_5t_route.iblk2.mcast = 0;
1679 }
developerfd40db22021-04-29 10:08:25 +08001680
1681 /* Some mt_wifi virtual interfaces, such as apcli,
1682 * will change the smac for specail purpose.
1683 */
developerbc552cc2022-03-15 16:19:27 +08001684 switch (bfib1_tx.pkt_type) {
developerfd40db22021-04-29 10:08:25 +08001685 case IPV4_HNAPT:
1686 case IPV4_HNAT:
1687 entry->ipv4_hnapt.smac_hi = swab32(*((u32 *)eth->h_source));
1688 entry->ipv4_hnapt.smac_lo = swab16(*((u16 *)&eth->h_source[4]));
1689 break;
1690 case IPV4_DSLITE:
1691 case IPV4_MAP_E:
1692 case IPV6_6RD:
1693 case IPV6_5T_ROUTE:
1694 case IPV6_3T_ROUTE:
1695 entry->ipv6_5t_route.smac_hi = swab32(*((u32 *)eth->h_source));
1696 entry->ipv6_5t_route.smac_lo = swab16(*((u16 *)&eth->h_source[4]));
1697 break;
1698 }
1699
developer0ff76882021-10-26 10:54:13 +08001700 if (skb->vlan_tci) {
developerbc552cc2022-03-15 16:19:27 +08001701 bfib1_tx.vlan_layer = 1;
1702 bfib1_tx.vpm = 1;
developer0ff76882021-10-26 10:54:13 +08001703 if (IS_IPV4_GRP(entry)) {
1704 entry->ipv4_hnapt.etype = htons(ETH_P_8021Q);
developer00a07372022-03-11 16:04:34 +08001705 entry->ipv4_hnapt.vlan1 = skb->vlan_tci;
developer0ff76882021-10-26 10:54:13 +08001706 } else if (IS_IPV6_GRP(entry)) {
1707 entry->ipv6_5t_route.etype = htons(ETH_P_8021Q);
developer00a07372022-03-11 16:04:34 +08001708 entry->ipv6_5t_route.vlan1 = skb->vlan_tci;
developer0ff76882021-10-26 10:54:13 +08001709 }
1710 } else {
developerbc552cc2022-03-15 16:19:27 +08001711 bfib1_tx.vpm = 0;
1712 bfib1_tx.vlan_layer = 0;
developer0ff76882021-10-26 10:54:13 +08001713 }
developer60e60962021-06-15 21:05:07 +08001714
developerfd40db22021-04-29 10:08:25 +08001715 /* MT7622 wifi hw_nat not support QoS */
1716 if (IS_IPV4_GRP(entry)) {
1717 entry->ipv4_hnapt.iblk2.fqos = 0;
developere567ad32021-05-25 17:16:17 +08001718 if ((hnat_priv->data->version == MTK_HNAT_V2 &&
1719 gmac_no == NR_WHNAT_WDMA_PORT) ||
developerd35bbcc2022-09-28 22:46:01 +08001720 ((hnat_priv->data->version == MTK_HNAT_V4 ||
1721 hnat_priv->data->version == MTK_HNAT_V5) &&
developere567ad32021-05-25 17:16:17 +08001722 (gmac_no == NR_WDMA0_PORT || gmac_no == NR_WDMA1_PORT))) {
developerfd40db22021-04-29 10:08:25 +08001723 entry->ipv4_hnapt.winfo.bssid = skb_hnat_bss_id(skb);
1724 entry->ipv4_hnapt.winfo.wcid = skb_hnat_wc_id(skb);
developerd35bbcc2022-09-28 22:46:01 +08001725#if defined(CONFIG_MEDIATEK_NETSYS_V3)
1726 entry->ipv4_hnapt.tport_id = (IS_HQOS_MODE) ? 1 : 0;
1727 entry->ipv4_hnapt.iblk2.rxid = skb_hnat_rx_id(skb);
1728 entry->ipv4_hnapt.iblk2.winfoi = 1;
1729 entry->ipv4_hnapt.winfo_pao.usr_info =
1730 skb_hnat_usr_info(skb);
1731 entry->ipv4_hnapt.winfo_pao.tid = skb_hnat_tid(skb);
1732 entry->ipv4_hnapt.winfo_pao.is_fixedrate =
1733 skb_hnat_is_fixedrate(skb);
1734 entry->ipv4_hnapt.winfo_pao.is_prior =
1735 skb_hnat_is_prior(skb);
1736 entry->ipv4_hnapt.winfo_pao.is_sp = skb_hnat_is_sp(skb);
1737 entry->ipv4_hnapt.winfo_pao.hf = skb_hnat_hf(skb);
1738 entry->ipv4_hnapt.winfo_pao.amsdu = skb_hnat_amsdu(skb);
1739#elif defined(CONFIG_MEDIATEK_NETSYS_V2)
developerfd40db22021-04-29 10:08:25 +08001740 entry->ipv4_hnapt.iblk2.rxid = skb_hnat_rx_id(skb);
1741 entry->ipv4_hnapt.iblk2.winfoi = 1;
1742#else
1743 entry->ipv4_hnapt.winfo.rxid = skb_hnat_rx_id(skb);
1744 entry->ipv4_hnapt.iblk2w.winfoi = 1;
1745 entry->ipv4_hnapt.iblk2w.wdmaid = skb_hnat_wdma_id(skb);
1746#endif
1747 } else {
1748 if (IS_GMAC1_MODE && !hnat_dsa_is_enable(hnat_priv)) {
developerbc552cc2022-03-15 16:19:27 +08001749 bfib1_tx.vpm = 1;
1750 bfib1_tx.vlan_layer = 1;
developerfd40db22021-04-29 10:08:25 +08001751
developerd35bbcc2022-09-28 22:46:01 +08001752 if (FROM_GE_LAN_GRP(skb))
developerfd40db22021-04-29 10:08:25 +08001753 entry->ipv4_hnapt.vlan1 = 1;
1754 else if (FROM_GE_WAN(skb) || FROM_GE_VIRTUAL(skb))
1755 entry->ipv4_hnapt.vlan1 = 2;
1756 }
1757
developer34028fb2022-01-11 13:51:29 +08001758 if (IS_HQOS_MODE &&
developerd35bbcc2022-09-28 22:46:01 +08001759 (FROM_GE_LAN_GRP(skb) || FROM_GE_WAN(skb) || FROM_GE_VIRTUAL(skb))) {
developerbc552cc2022-03-15 16:19:27 +08001760 bfib1_tx.vpm = 0;
1761 bfib1_tx.vlan_layer = 1;
developerfd40db22021-04-29 10:08:25 +08001762 entry->ipv4_hnapt.etype = htons(HQOS_MAGIC_TAG);
1763 entry->ipv4_hnapt.vlan1 = skb_hnat_entry(skb);
1764 entry->ipv4_hnapt.iblk2.fqos = 1;
1765 }
developerfd40db22021-04-29 10:08:25 +08001766 }
1767 entry->ipv4_hnapt.iblk2.dp = gmac_no;
1768 } else {
1769 entry->ipv6_5t_route.iblk2.fqos = 0;
developere567ad32021-05-25 17:16:17 +08001770 if ((hnat_priv->data->version == MTK_HNAT_V2 &&
1771 gmac_no == NR_WHNAT_WDMA_PORT) ||
developerd35bbcc2022-09-28 22:46:01 +08001772 ((hnat_priv->data->version == MTK_HNAT_V4 ||
1773 hnat_priv->data->version == MTK_HNAT_V5) &&
developere567ad32021-05-25 17:16:17 +08001774 (gmac_no == NR_WDMA0_PORT || gmac_no == NR_WDMA1_PORT))) {
developerfd40db22021-04-29 10:08:25 +08001775 entry->ipv6_5t_route.winfo.bssid = skb_hnat_bss_id(skb);
1776 entry->ipv6_5t_route.winfo.wcid = skb_hnat_wc_id(skb);
developerd35bbcc2022-09-28 22:46:01 +08001777#if defined(CONFIG_MEDIATEK_NETSYS_V3)
1778 entry->ipv6_5t_route.tport_id = (IS_HQOS_MODE) ? 1 : 0;
developerfd40db22021-04-29 10:08:25 +08001779 entry->ipv6_5t_route.iblk2.rxid = skb_hnat_rx_id(skb);
1780 entry->ipv6_5t_route.iblk2.winfoi = 1;
developerd35bbcc2022-09-28 22:46:01 +08001781 entry->ipv6_5t_route.winfo_pao.usr_info =
1782 skb_hnat_usr_info(skb);
1783 entry->ipv6_5t_route.winfo_pao.tid =
1784 skb_hnat_tid(skb);
1785 entry->ipv6_5t_route.winfo_pao.is_fixedrate =
1786 skb_hnat_is_fixedrate(skb);
1787 entry->ipv6_5t_route.winfo_pao.is_prior =
1788 skb_hnat_is_prior(skb);
1789 entry->ipv6_5t_route.winfo_pao.is_sp =
1790 skb_hnat_is_sp(skb);
1791 entry->ipv6_5t_route.winfo_pao.hf =
1792 skb_hnat_hf(skb);
1793 entry->ipv6_5t_route.winfo_pao.amsdu =
1794 skb_hnat_amsdu(skb);
1795#elif defined(CONFIG_MEDIATEK_NETSYS_V2)
1796 entry->ipv6_5t_route.iblk2.rxid = skb_hnat_rx_id(skb);
1797 entry->ipv6_5t_route.iblk2.winfoi = 1;
developerfd40db22021-04-29 10:08:25 +08001798#else
1799 entry->ipv6_5t_route.winfo.rxid = skb_hnat_rx_id(skb);
1800 entry->ipv6_5t_route.iblk2w.winfoi = 1;
1801 entry->ipv6_5t_route.iblk2w.wdmaid = skb_hnat_wdma_id(skb);
1802#endif
1803 } else {
1804 if (IS_GMAC1_MODE && !hnat_dsa_is_enable(hnat_priv)) {
developerbc552cc2022-03-15 16:19:27 +08001805 bfib1_tx.vpm = 1;
1806 bfib1_tx.vlan_layer = 1;
developerfd40db22021-04-29 10:08:25 +08001807
developerd35bbcc2022-09-28 22:46:01 +08001808 if (FROM_GE_LAN_GRP(skb))
developerfd40db22021-04-29 10:08:25 +08001809 entry->ipv6_5t_route.vlan1 = 1;
1810 else if (FROM_GE_WAN(skb) || FROM_GE_VIRTUAL(skb))
1811 entry->ipv6_5t_route.vlan1 = 2;
1812 }
1813
developer34028fb2022-01-11 13:51:29 +08001814 if (IS_HQOS_MODE &&
developerd35bbcc2022-09-28 22:46:01 +08001815 (FROM_GE_LAN_GRP(skb) || FROM_GE_WAN(skb) || FROM_GE_VIRTUAL(skb))) {
developerbc552cc2022-03-15 16:19:27 +08001816 bfib1_tx.vpm = 0;
1817 bfib1_tx.vlan_layer = 1;
developerfd40db22021-04-29 10:08:25 +08001818 entry->ipv6_5t_route.etype = htons(HQOS_MAGIC_TAG);
1819 entry->ipv6_5t_route.vlan1 = skb_hnat_entry(skb);
1820 entry->ipv6_5t_route.iblk2.fqos = 1;
1821 }
developerfd40db22021-04-29 10:08:25 +08001822 }
1823 entry->ipv6_5t_route.iblk2.dp = gmac_no;
1824 }
1825
developer7b36dca2022-05-19 18:29:10 +08001826 bfib1_tx.ttl = 1;
developerbc552cc2022-03-15 16:19:27 +08001827 bfib1_tx.state = BIND;
1828 wmb();
1829 memcpy(&entry->bfib1, &bfib1_tx, sizeof(bfib1_tx));
developerfd40db22021-04-29 10:08:25 +08001830
1831 return NF_ACCEPT;
1832}
1833
1834int mtk_sw_nat_hook_rx(struct sk_buff *skb)
1835{
developer99506e52021-06-30 22:03:02 +08001836 if (!IS_SPACE_AVAILABLE_HEAD(skb) || !FROM_WED(skb)) {
1837 skb_hnat_magic_tag(skb) = 0;
developerfd40db22021-04-29 10:08:25 +08001838 return NF_ACCEPT;
developer99506e52021-06-30 22:03:02 +08001839 }
developerfd40db22021-04-29 10:08:25 +08001840
1841 skb_hnat_alg(skb) = 0;
developerfdfe1572021-09-13 16:56:33 +08001842 skb_hnat_filled(skb) = 0;
developerfd40db22021-04-29 10:08:25 +08001843 skb_hnat_magic_tag(skb) = HNAT_MAGIC_TAG;
1844
1845 if (skb_hnat_iface(skb) == FOE_MAGIC_WED0)
1846 skb_hnat_sport(skb) = NR_WDMA0_PORT;
1847 else if (skb_hnat_iface(skb) == FOE_MAGIC_WED1)
1848 skb_hnat_sport(skb) = NR_WDMA1_PORT;
1849
1850 return NF_ACCEPT;
1851}
1852
1853void mtk_ppe_dev_register_hook(struct net_device *dev)
1854{
1855 int i, number = 0;
1856 struct extdev_entry *ext_entry;
1857
developerfd40db22021-04-29 10:08:25 +08001858 for (i = 1; i < MAX_IF_NUM; i++) {
1859 if (hnat_priv->wifi_hook_if[i] == dev) {
1860 pr_info("%s : %s has been registered in wifi_hook_if table[%d]\n",
1861 __func__, dev->name, i);
1862 return;
1863 }
1864 if (!hnat_priv->wifi_hook_if[i]) {
1865 if (find_extif_from_devname(dev->name)) {
1866 extif_set_dev(dev);
1867 goto add_wifi_hook_if;
1868 }
1869
1870 number = get_ext_device_number();
1871 if (number >= MAX_EXT_DEVS) {
1872 pr_info("%s : extdev array is full. %s is not registered\n",
1873 __func__, dev->name);
1874 return;
1875 }
1876
1877 ext_entry = kzalloc(sizeof(*ext_entry), GFP_KERNEL);
1878 if (!ext_entry)
1879 return;
1880
developer4c32b7a2021-11-13 16:46:43 +08001881 strncpy(ext_entry->name, dev->name, IFNAMSIZ - 1);
developerfd40db22021-04-29 10:08:25 +08001882 dev_hold(dev);
1883 ext_entry->dev = dev;
1884 ext_if_add(ext_entry);
1885
1886add_wifi_hook_if:
1887 dev_hold(dev);
1888 hnat_priv->wifi_hook_if[i] = dev;
1889
1890 break;
1891 }
1892 }
1893 pr_info("%s : ineterface %s register (%d)\n", __func__, dev->name, i);
1894}
1895
1896void mtk_ppe_dev_unregister_hook(struct net_device *dev)
1897{
1898 int i;
1899
1900 for (i = 1; i < MAX_IF_NUM; i++) {
1901 if (hnat_priv->wifi_hook_if[i] == dev) {
1902 hnat_priv->wifi_hook_if[i] = NULL;
1903 dev_put(dev);
1904
1905 break;
1906 }
1907 }
1908
1909 extif_put_dev(dev);
1910 pr_info("%s : ineterface %s set null (%d)\n", __func__, dev->name, i);
1911}
1912
1913static unsigned int mtk_hnat_accel_type(struct sk_buff *skb)
1914{
1915 struct dst_entry *dst;
1916 struct nf_conn *ct;
1917 enum ip_conntrack_info ctinfo;
1918 const struct nf_conn_help *help;
1919
1920 /* Do not accelerate 1st round of xfrm flow, and 2nd round of xfrm flow
1921 * is from local_out which is also filtered in sanity check.
1922 */
1923 dst = skb_dst(skb);
1924 if (dst && dst_xfrm(dst))
1925 return 0;
1926
1927 ct = nf_ct_get(skb, &ctinfo);
1928 if (!ct)
1929 return 1;
1930
1931 /* rcu_read_lock()ed by nf_hook_slow */
1932 help = nfct_help(ct);
1933 if (help && rcu_dereference(help->helper))
1934 return 0;
1935
1936 return 1;
1937}
1938
developer6f4a0c72021-10-19 10:04:22 +08001939static void mtk_hnat_dscp_update(struct sk_buff *skb, struct foe_entry *entry)
1940{
1941 struct iphdr *iph;
1942 struct ethhdr *eth;
1943 struct ipv6hdr *ip6h;
1944 bool flag = false;
1945
1946 eth = eth_hdr(skb);
1947 switch (ntohs(eth->h_proto)) {
1948 case ETH_P_IP:
1949 iph = ip_hdr(skb);
developer001e7be2021-12-09 15:00:27 +08001950 if (IS_IPV4_GRP(entry) && entry->ipv4_hnapt.iblk2.dscp != iph->tos)
developer6f4a0c72021-10-19 10:04:22 +08001951 flag = true;
1952 break;
1953 case ETH_P_IPV6:
1954 ip6h = ipv6_hdr(skb);
developer001e7be2021-12-09 15:00:27 +08001955 if ((IS_IPV6_3T_ROUTE(entry) || IS_IPV6_5T_ROUTE(entry)) &&
1956 (entry->ipv6_5t_route.iblk2.dscp !=
1957 (ip6h->priority << 4 | (ip6h->flow_lbl[0] >> 4))))
developer6f4a0c72021-10-19 10:04:22 +08001958 flag = true;
1959 break;
1960 default:
1961 return;
1962 }
1963
1964 if (flag) {
developer1080dd82022-03-07 19:31:04 +08001965 if (debug_level >= 2)
1966 pr_info("Delete entry idx=%d.\n", skb_hnat_entry(skb));
developer6f4a0c72021-10-19 10:04:22 +08001967 memset(entry, 0, sizeof(struct foe_entry));
1968 hnat_cache_ebl(1);
1969 }
1970}
1971
developer30a47682021-11-02 17:06:14 +08001972static void mtk_hnat_nf_update(struct sk_buff *skb)
1973{
1974 struct nf_conn *ct;
1975 struct nf_conn_acct *acct;
1976 struct nf_conn_counter *counter;
1977 enum ip_conntrack_info ctinfo;
1978 struct hnat_accounting diff;
1979
1980 ct = nf_ct_get(skb, &ctinfo);
1981 if (ct) {
1982 if (!hnat_get_count(hnat_priv, skb_hnat_ppe(skb), skb_hnat_entry(skb), &diff))
1983 return;
1984
1985 acct = nf_conn_acct_find(ct);
1986 if (acct) {
1987 counter = acct->counter;
1988 atomic64_add(diff.packets, &counter[CTINFO2DIR(ctinfo)].packets);
1989 atomic64_add(diff.bytes, &counter[CTINFO2DIR(ctinfo)].bytes);
1990 }
1991 }
1992}
1993
developerfd40db22021-04-29 10:08:25 +08001994static unsigned int mtk_hnat_nf_post_routing(
1995 struct sk_buff *skb, const struct net_device *out,
1996 unsigned int (*fn)(struct sk_buff *, const struct net_device *,
1997 struct flow_offload_hw_path *),
1998 const char *func)
1999{
2000 struct foe_entry *entry;
2001 struct flow_offload_hw_path hw_path = { .dev = (struct net_device*)out,
developere5763512021-05-21 01:04:58 +08002002 .virt_dev = (struct net_device*)out };
developerfd40db22021-04-29 10:08:25 +08002003 const struct net_device *arp_dev = out;
2004
2005 if (skb_hnat_alg(skb) || unlikely(!is_magic_tag_valid(skb) ||
2006 !IS_SPACE_AVAILABLE_HEAD(skb)))
2007 return 0;
2008
2009 if (unlikely(!skb_hnat_is_hashed(skb)))
2010 return 0;
2011
2012 if (out->netdev_ops->ndo_flow_offload_check) {
developere5763512021-05-21 01:04:58 +08002013 out->netdev_ops->ndo_flow_offload_check(&hw_path);
developerfd40db22021-04-29 10:08:25 +08002014 out = (IS_GMAC1_MODE) ? hw_path.virt_dev : hw_path.dev;
2015 }
2016
developerd35bbcc2022-09-28 22:46:01 +08002017 if (!IS_LAN_GRP(out) && !IS_WAN(out) && !IS_EXT(out))
developerfd40db22021-04-29 10:08:25 +08002018 return 0;
2019
2020 trace_printk("[%s] case hit, %x-->%s, reason=%x\n", __func__,
2021 skb_hnat_iface(skb), out->name, skb_hnat_reason(skb));
2022
developer471f6562021-05-10 20:48:34 +08002023 entry = &hnat_priv->foe_table_cpu[skb_hnat_ppe(skb)][skb_hnat_entry(skb)];
developerfd40db22021-04-29 10:08:25 +08002024
2025 switch (skb_hnat_reason(skb)) {
2026 case HIT_UNBIND_RATE_REACH:
2027 if (entry_hnat_is_bound(entry))
2028 break;
2029
2030 if (fn && !mtk_hnat_accel_type(skb))
2031 break;
2032
2033 if (fn && fn(skb, arp_dev, &hw_path))
2034 break;
2035
2036 skb_to_hnat_info(skb, out, entry, &hw_path);
2037 break;
2038 case HIT_BIND_KEEPALIVE_DUP_OLD_HDR:
developer30a47682021-11-02 17:06:14 +08002039 /* update hnat count to nf_conntrack by keepalive */
2040 if (hnat_priv->data->per_flow_accounting && hnat_priv->nf_stat_en)
2041 mtk_hnat_nf_update(skb);
2042
developerfd40db22021-04-29 10:08:25 +08002043 if (fn && !mtk_hnat_accel_type(skb))
2044 break;
2045
developer6f4a0c72021-10-19 10:04:22 +08002046 /* update dscp for qos */
2047 mtk_hnat_dscp_update(skb, entry);
2048
developerfd40db22021-04-29 10:08:25 +08002049 /* update mcast timestamp*/
2050 if (hnat_priv->data->version == MTK_HNAT_V3 &&
2051 hnat_priv->data->mcast && entry->bfib1.sta == 1)
2052 entry->ipv4_hnapt.m_timestamp = foe_timestamp(hnat_priv);
2053
2054 if (entry_hnat_is_bound(entry)) {
2055 memset(skb_hnat_info(skb), 0, FOE_INFO_LEN);
2056
2057 return -1;
2058 }
2059 break;
2060 case HIT_BIND_MULTICAST_TO_CPU:
2061 case HIT_BIND_MULTICAST_TO_GMAC_CPU:
2062 /*do not forward to gdma again,if ppe already done it*/
developerd35bbcc2022-09-28 22:46:01 +08002063 if (IS_LAN_GRP(out) || IS_WAN(out))
developerfd40db22021-04-29 10:08:25 +08002064 return -1;
2065 break;
2066 }
2067
2068 return 0;
2069}
2070
2071static unsigned int
2072mtk_hnat_ipv6_nf_local_out(void *priv, struct sk_buff *skb,
2073 const struct nf_hook_state *state)
2074{
2075 struct foe_entry *entry;
2076 struct ipv6hdr *ip6h;
2077 struct iphdr _iphdr;
2078 const struct iphdr *iph;
2079 struct tcpudphdr _ports;
2080 const struct tcpudphdr *pptr;
2081 int udp = 0;
2082
2083 if (unlikely(!skb_hnat_is_hashed(skb)))
2084 return NF_ACCEPT;
2085
developer471f6562021-05-10 20:48:34 +08002086 entry = &hnat_priv->foe_table_cpu[skb_hnat_ppe(skb)][skb_hnat_entry(skb)];
developerfd40db22021-04-29 10:08:25 +08002087 if (skb_hnat_reason(skb) == HIT_UNBIND_RATE_REACH) {
2088 ip6h = ipv6_hdr(skb);
2089 if (ip6h->nexthdr == NEXTHDR_IPIP) {
2090 /* Map-E LAN->WAN: need to record orig info before fn. */
2091 if (mape_toggle) {
2092 iph = skb_header_pointer(skb, IPV6_HDR_LEN,
2093 sizeof(_iphdr), &_iphdr);
developer4c32b7a2021-11-13 16:46:43 +08002094 if (unlikely(!iph))
2095 return NF_ACCEPT;
2096
developerfd40db22021-04-29 10:08:25 +08002097 switch (iph->protocol) {
2098 case IPPROTO_UDP:
2099 udp = 1;
2100 case IPPROTO_TCP:
2101 break;
2102
2103 default:
2104 return NF_ACCEPT;
2105 }
2106
2107 pptr = skb_header_pointer(skb, IPV6_HDR_LEN + iph->ihl * 4,
2108 sizeof(_ports), &_ports);
developer4c32b7a2021-11-13 16:46:43 +08002109 if (unlikely(!pptr))
2110 return NF_ACCEPT;
2111
developerfd40db22021-04-29 10:08:25 +08002112 entry->bfib1.udp = udp;
2113
developer25fc8c02022-05-06 16:24:02 +08002114 /* Map-E LAN->WAN record inner IPv4 header info. */
developerd35bbcc2022-09-28 22:46:01 +08002115#if defined(CONFIG_MEDIATEK_NETSYS_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developerfd40db22021-04-29 10:08:25 +08002116 entry->bfib1.pkt_type = IPV4_MAP_E;
2117 entry->ipv4_dslite.iblk2.dscp = iph->tos;
developerd35bbcc2022-09-28 22:46:01 +08002118 entry->ipv4_mape.new_sip = ntohl(iph->saddr);
2119 entry->ipv4_mape.new_dip = ntohl(iph->daddr);
2120 entry->ipv4_mape.new_sport = ntohs(pptr->src);
2121 entry->ipv4_mape.new_dport = ntohs(pptr->dst);
developerfd40db22021-04-29 10:08:25 +08002122#else
2123 entry->ipv4_hnapt.iblk2.dscp = iph->tos;
2124 entry->ipv4_hnapt.new_sip = ntohl(iph->saddr);
2125 entry->ipv4_hnapt.new_dip = ntohl(iph->daddr);
2126 entry->ipv4_hnapt.new_sport = ntohs(pptr->src);
2127 entry->ipv4_hnapt.new_dport = ntohs(pptr->dst);
2128#endif
2129 } else {
2130 entry->bfib1.pkt_type = IPV4_DSLITE;
2131 }
2132 }
2133 }
2134 return NF_ACCEPT;
2135}
2136
2137static unsigned int
2138mtk_hnat_ipv6_nf_post_routing(void *priv, struct sk_buff *skb,
2139 const struct nf_hook_state *state)
2140{
2141 post_routing_print(skb, state->in, state->out, __func__);
2142
2143 if (!mtk_hnat_nf_post_routing(skb, state->out, hnat_ipv6_get_nexthop,
2144 __func__))
2145 return NF_ACCEPT;
2146
2147 trace_printk(
2148 "%s:drop (iif=0x%x, out_dev=%s, CB2=0x%x, ppe_hash=0x%x, sport=0x%x, reason=0x%x, alg=0x%x)\n",
2149 __func__, skb_hnat_iface(skb), state->out->name, HNAT_SKB_CB2(skb)->magic,
2150 skb_hnat_entry(skb), skb_hnat_sport(skb), skb_hnat_reason(skb),
2151 skb_hnat_alg(skb));
2152
2153 return NF_DROP;
2154}
2155
2156static unsigned int
2157mtk_hnat_ipv4_nf_post_routing(void *priv, struct sk_buff *skb,
2158 const struct nf_hook_state *state)
2159{
2160 post_routing_print(skb, state->in, state->out, __func__);
2161
2162 if (!mtk_hnat_nf_post_routing(skb, state->out, hnat_ipv4_get_nexthop,
2163 __func__))
2164 return NF_ACCEPT;
2165
2166 trace_printk(
2167 "%s:drop (iif=0x%x, out_dev=%s, CB2=0x%x, ppe_hash=0x%x, sport=0x%x, reason=0x%x, alg=0x%x)\n",
2168 __func__, skb_hnat_iface(skb), state->out->name, HNAT_SKB_CB2(skb)->magic,
2169 skb_hnat_entry(skb), skb_hnat_sport(skb), skb_hnat_reason(skb),
2170 skb_hnat_alg(skb));
2171
2172 return NF_DROP;
2173}
2174
2175static unsigned int
2176mtk_pong_hqos_handler(void *priv, struct sk_buff *skb,
2177 const struct nf_hook_state *state)
2178{
developerfd40db22021-04-29 10:08:25 +08002179 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb);
2180
developer34028fb2022-01-11 13:51:29 +08002181 if (IS_HQOS_MODE && eth_hdr(skb)->h_proto == HQOS_MAGIC_TAG) {
developerfd40db22021-04-29 10:08:25 +08002182 skb_hnat_entry(skb) = ntohs(veth->h_vlan_TCI) & 0x3fff;
2183 skb_hnat_reason(skb) = HIT_BIND_FORCE_TO_CPU;
2184 }
developerfd40db22021-04-29 10:08:25 +08002185
2186 if (skb_hnat_iface(skb) == FOE_MAGIC_EXT)
2187 clr_from_extge(skb);
2188
2189 /* packets from external devices -> xxx ,step 2, learning stage */
developeraf07fad2021-11-19 17:53:42 +08002190 if (do_ext2ge_fast_learn(state->in, skb) && (!qos_toggle ||
2191 (qos_toggle && eth_hdr(skb)->h_proto != HQOS_MAGIC_TAG))) {
developerfd40db22021-04-29 10:08:25 +08002192 if (!do_hnat_ext_to_ge2(skb, __func__))
2193 return NF_STOLEN;
2194 goto drop;
2195 }
2196
2197 /* packets form ge -> external device */
2198 if (do_ge2ext_fast(state->in, skb)) {
2199 if (!do_hnat_ge_to_ext(skb, __func__))
2200 return NF_STOLEN;
2201 goto drop;
2202 }
2203
2204 return NF_ACCEPT;
2205drop:
2206 printk_ratelimited(KERN_WARNING
2207 "%s:drop (in_dev=%s, iif=0x%x, CB2=0x%x, ppe_hash=0x%x, sport=0x%x, reason=0x%x, alg=0x%x)\n",
2208 __func__, state->in->name, skb_hnat_iface(skb),
2209 HNAT_SKB_CB2(skb)->magic, skb_hnat_entry(skb),
2210 skb_hnat_sport(skb), skb_hnat_reason(skb),
2211 skb_hnat_alg(skb));
2212
2213 return NF_DROP;
2214}
2215
2216static unsigned int
2217mtk_hnat_br_nf_local_out(void *priv, struct sk_buff *skb,
2218 const struct nf_hook_state *state)
2219{
2220 post_routing_print(skb, state->in, state->out, __func__);
2221
2222 if (!mtk_hnat_nf_post_routing(skb, state->out, 0, __func__))
2223 return NF_ACCEPT;
2224
2225 trace_printk(
2226 "%s:drop (iif=0x%x, out_dev=%s, CB2=0x%x, ppe_hash=0x%x, sport=0x%x, reason=0x%x, alg=0x%x)\n",
2227 __func__, skb_hnat_iface(skb), state->out->name, HNAT_SKB_CB2(skb)->magic,
2228 skb_hnat_entry(skb), skb_hnat_sport(skb), skb_hnat_reason(skb),
2229 skb_hnat_alg(skb));
2230
2231 return NF_DROP;
2232}
2233
2234static unsigned int
2235mtk_hnat_ipv4_nf_local_out(void *priv, struct sk_buff *skb,
2236 const struct nf_hook_state *state)
2237{
2238 struct sk_buff *new_skb;
2239 struct foe_entry *entry;
2240 struct iphdr *iph;
2241
2242 if (!skb_hnat_is_hashed(skb))
2243 return NF_ACCEPT;
2244
developer471f6562021-05-10 20:48:34 +08002245 entry = &hnat_priv->foe_table_cpu[skb_hnat_ppe(skb)][skb_hnat_entry(skb)];
developerfd40db22021-04-29 10:08:25 +08002246
2247 if (unlikely(skb_headroom(skb) < FOE_INFO_LEN)) {
2248 new_skb = skb_realloc_headroom(skb, FOE_INFO_LEN);
2249 if (!new_skb) {
2250 dev_info(hnat_priv->dev, "%s:drop\n", __func__);
2251 return NF_DROP;
2252 }
2253 dev_kfree_skb(skb);
2254 skb = new_skb;
2255 }
2256
2257 /* Make the flow from local not be bound. */
2258 iph = ip_hdr(skb);
2259 if (iph->protocol == IPPROTO_IPV6) {
2260 entry->udib1.pkt_type = IPV6_6RD;
2261 hnat_set_head_frags(state, skb, 0, hnat_set_alg);
2262 } else {
2263 hnat_set_head_frags(state, skb, 1, hnat_set_alg);
2264 }
2265
2266 return NF_ACCEPT;
2267}
2268
2269static unsigned int mtk_hnat_br_nf_forward(void *priv,
2270 struct sk_buff *skb,
2271 const struct nf_hook_state *state)
2272{
developer99506e52021-06-30 22:03:02 +08002273 if ((hnat_priv->data->version == MTK_HNAT_V2) &&
2274 unlikely(IS_EXT(state->in) && IS_EXT(state->out)))
developerfd40db22021-04-29 10:08:25 +08002275 hnat_set_head_frags(state, skb, 1, hnat_set_alg);
2276
2277 return NF_ACCEPT;
2278}
2279
2280static struct nf_hook_ops mtk_hnat_nf_ops[] __read_mostly = {
2281 {
2282 .hook = mtk_hnat_ipv4_nf_pre_routing,
2283 .pf = NFPROTO_IPV4,
2284 .hooknum = NF_INET_PRE_ROUTING,
2285 .priority = NF_IP_PRI_FIRST + 1,
2286 },
2287 {
2288 .hook = mtk_hnat_ipv6_nf_pre_routing,
2289 .pf = NFPROTO_IPV6,
2290 .hooknum = NF_INET_PRE_ROUTING,
2291 .priority = NF_IP_PRI_FIRST + 1,
2292 },
2293 {
2294 .hook = mtk_hnat_ipv6_nf_post_routing,
2295 .pf = NFPROTO_IPV6,
2296 .hooknum = NF_INET_POST_ROUTING,
2297 .priority = NF_IP_PRI_LAST,
2298 },
2299 {
2300 .hook = mtk_hnat_ipv6_nf_local_out,
2301 .pf = NFPROTO_IPV6,
2302 .hooknum = NF_INET_LOCAL_OUT,
2303 .priority = NF_IP_PRI_LAST,
2304 },
2305 {
2306 .hook = mtk_hnat_ipv4_nf_post_routing,
2307 .pf = NFPROTO_IPV4,
2308 .hooknum = NF_INET_POST_ROUTING,
2309 .priority = NF_IP_PRI_LAST,
2310 },
2311 {
2312 .hook = mtk_hnat_ipv4_nf_local_out,
2313 .pf = NFPROTO_IPV4,
2314 .hooknum = NF_INET_LOCAL_OUT,
2315 .priority = NF_IP_PRI_LAST,
2316 },
2317 {
2318 .hook = mtk_hnat_br_nf_local_in,
2319 .pf = NFPROTO_BRIDGE,
2320 .hooknum = NF_BR_LOCAL_IN,
2321 .priority = NF_BR_PRI_FIRST,
2322 },
2323 {
2324 .hook = mtk_hnat_br_nf_local_out,
2325 .pf = NFPROTO_BRIDGE,
2326 .hooknum = NF_BR_LOCAL_OUT,
2327 .priority = NF_BR_PRI_LAST - 1,
2328 },
2329 {
2330 .hook = mtk_pong_hqos_handler,
2331 .pf = NFPROTO_BRIDGE,
2332 .hooknum = NF_BR_PRE_ROUTING,
developer2b85f652021-08-19 16:09:50 +08002333 .priority = NF_BR_PRI_FIRST + 1,
developerfd40db22021-04-29 10:08:25 +08002334 },
2335};
2336
2337int hnat_register_nf_hooks(void)
2338{
2339 return nf_register_net_hooks(&init_net, mtk_hnat_nf_ops, ARRAY_SIZE(mtk_hnat_nf_ops));
2340}
2341
2342void hnat_unregister_nf_hooks(void)
2343{
2344 nf_unregister_net_hooks(&init_net, mtk_hnat_nf_ops, ARRAY_SIZE(mtk_hnat_nf_ops));
2345}
2346
2347int whnat_adjust_nf_hooks(void)
2348{
2349 struct nf_hook_ops *hook = mtk_hnat_nf_ops;
2350 unsigned int n = ARRAY_SIZE(mtk_hnat_nf_ops);
2351
developerfd40db22021-04-29 10:08:25 +08002352 while (n-- > 0) {
2353 if (hook[n].hook == mtk_hnat_br_nf_local_in) {
2354 hook[n].hooknum = NF_BR_PRE_ROUTING;
developer2b85f652021-08-19 16:09:50 +08002355 hook[n].priority = NF_BR_PRI_FIRST + 1;
developerfd40db22021-04-29 10:08:25 +08002356 } else if (hook[n].hook == mtk_hnat_br_nf_local_out) {
2357 hook[n].hooknum = NF_BR_POST_ROUTING;
2358 } else if (hook[n].hook == mtk_pong_hqos_handler) {
2359 hook[n].hook = mtk_hnat_br_nf_forward;
2360 hook[n].hooknum = NF_BR_FORWARD;
2361 hook[n].priority = NF_BR_PRI_LAST - 1;
2362 }
2363 }
2364
2365 return 0;
2366}
2367
developerfd40db22021-04-29 10:08:25 +08002368int mtk_hqos_ptype_cb(struct sk_buff *skb, struct net_device *dev,
2369 struct packet_type *pt, struct net_device *unused)
2370{
2371 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb);
2372
2373 skb_hnat_entry(skb) = ntohs(veth->h_vlan_TCI) & 0x3fff;
2374 skb_hnat_reason(skb) = HIT_BIND_FORCE_TO_CPU;
2375
2376 do_hnat_ge_to_ext(skb, __func__);
2377
2378 return 0;
2379}
developerfd40db22021-04-29 10:08:25 +08002380