[Description]

Fix Coverity scan warning.

[Release-log]
N/A

Change-Id: Iafa443df041c656079bb17dc4706159fcc9cdce6
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/6838293
This commit is contained in:
developer 2022-11-28 10:33:36 +08:00 committed by hanwckf
parent cec6012a69
commit 5ad03d0865
4 changed files with 176 additions and 90 deletions

View File

@ -403,7 +403,7 @@ static int hnat_start(u32 ppe_id)
{ {
u32 foe_table_sz; u32 foe_table_sz;
u32 foe_mib_tb_sz; u32 foe_mib_tb_sz;
u32 etry_num_cfg; int etry_num_cfg;
if (ppe_id >= CFG_PPE_NUM) if (ppe_id >= CFG_PPE_NUM)
return -EINVAL; return -EINVAL;

View File

@ -41,6 +41,7 @@ static const char * const packet_type[] = {
static uint8_t *show_cpu_reason(struct sk_buff *skb) static uint8_t *show_cpu_reason(struct sk_buff *skb)
{ {
static u8 buf[32]; static u8 buf[32];
int ret;
switch (skb_hnat_reason(skb)) { switch (skb_hnat_reason(skb)) {
case TTL_0: case TTL_0:
@ -89,8 +90,12 @@ static uint8_t *show_cpu_reason(struct sk_buff *skb)
return "Pre bind\n"; return "Pre bind\n";
} }
sprintf(buf, "CPU Reason Error - %X\n", skb_hnat_entry(skb)); ret = snprintf(buf, sizeof(buf), "CPU Reason Error - %X\n",
return buf; skb_hnat_entry(skb));
if (ret == strlen(buf))
return buf;
else
return "CPU Reason Error\n";
} }
uint32_t foe_dump_pkt(struct sk_buff *skb) uint32_t foe_dump_pkt(struct sk_buff *skb)
@ -742,7 +747,8 @@ int read_mib(struct mtk_hnat *h, u32 ppe_id,
*packets = cnt_r2 + ((u64)cnt_r3 << 32); *packets = cnt_r2 + ((u64)cnt_r3 << 32);
} else { } else {
*bytes = cnt_r0 + ((u64)(cnt_r1 & 0xffff) << 32); *bytes = cnt_r0 + ((u64)(cnt_r1 & 0xffff) << 32);
*packets = ((cnt_r1 & 0xffff0000) >> 16) + ((cnt_r2 & 0xffffff) << 16); *packets = ((cnt_r1 & 0xffff0000) >> 16) +
((u64)(cnt_r2 & 0xffffff) << 16);
} }
return 0; return 0;
@ -758,6 +764,9 @@ struct hnat_accounting *hnat_get_count(struct mtk_hnat *h, u32 ppe_id,
if (ppe_id >= CFG_PPE_NUM) if (ppe_id >= CFG_PPE_NUM)
return NULL; return NULL;
if (index >= hnat_priv->foe_etry_num)
return NULL;
if (!hnat_priv->data->per_flow_accounting) if (!hnat_priv->data->per_flow_accounting)
return NULL; return NULL;
@ -766,7 +775,7 @@ struct hnat_accounting *hnat_get_count(struct mtk_hnat *h, u32 ppe_id,
h->acct[ppe_id][index].bytes += bytes; h->acct[ppe_id][index].bytes += bytes;
h->acct[ppe_id][index].packets += packets; h->acct[ppe_id][index].packets += packets;
if (diff) { if (diff) {
diff->bytes = bytes; diff->bytes = bytes;
diff->packets = packets; diff->packets = packets;
@ -1850,6 +1859,15 @@ static ssize_t hnat_queue_write(struct file *file, const char __user *buf,
line[length] = '\0'; line[length] = '\0';
#if defined(CONFIG_MEDIATEK_NETSYS_V3)
if (max_rate > 100000000 || max_rate < 0 ||
min_rate > 100000000 || min_rate < 0)
#else
if (max_rate > 10000000 || max_rate < 0 ||
min_rate > 10000000 || min_rate < 0)
#endif
return -EINVAL;
while (max_rate > 127) { while (max_rate > 127) {
max_rate /= 10; max_rate /= 10;
max_exp++; max_exp++;
@ -2139,7 +2157,7 @@ static void hnat_qos_pppq_enable(void)
static ssize_t hnat_qos_toggle_write(struct file *file, const char __user *buffer, static ssize_t hnat_qos_toggle_write(struct file *file, const char __user *buffer,
size_t count, loff_t *data) size_t count, loff_t *data)
{ {
char buf[8]; char buf[8] = {0};
int len = count; int len = count;
if ((len > 8) || copy_from_user(buf, buffer, len)) if ((len > 8) || copy_from_user(buf, buffer, len))
@ -2293,25 +2311,26 @@ static ssize_t hnat_static_entry_write(struct file *file,
buf[len] = '\0'; buf[len] = '\0';
#if defined(CONFIG_MEDIATEK_NETSYS_V3) #if defined(CONFIG_MEDIATEK_NETSYS_V3)
sscanf(buf, "%d %x %x %x %hx %hx %x %x %x %hx %hx %s %s %x %x %x", if (sscanf(buf, "%d %x %x %x %hx %hx %x %x %x %hx %hx %s %s %x %x %x",
&hash, &hash,
&entry.ipv4_hnapt.info_blk1, &entry.ipv4_hnapt.info_blk1,
&entry.ipv4_hnapt.sip, &entry.ipv4_hnapt.sip,
&entry.ipv4_hnapt.dip, &entry.ipv4_hnapt.dip,
&entry.ipv4_hnapt.sport, &entry.ipv4_hnapt.sport,
&entry.ipv4_hnapt.dport, &entry.ipv4_hnapt.dport,
&entry.ipv4_hnapt.info_blk2, &entry.ipv4_hnapt.info_blk2,
&entry.ipv4_hnapt.new_sip, &entry.ipv4_hnapt.new_sip,
&entry.ipv4_hnapt.new_dip, &entry.ipv4_hnapt.new_dip,
&entry.ipv4_hnapt.new_sport, &entry.ipv4_hnapt.new_sport,
&entry.ipv4_hnapt.new_dport, &entry.ipv4_hnapt.new_dport,
dmac_str, smac_str, &tport_id, &tops_entry, &cdrt_id); dmac_str, smac_str, &tport_id, &tops_entry, &cdrt_id) != 16)
return -EFAULT;
entry.ipv4_hnapt.tport_id = tport_id; entry.ipv4_hnapt.tport_id = tport_id;
entry.ipv4_hnapt.tops_entry = tops_entry; entry.ipv4_hnapt.tops_entry = tops_entry;
entry.ipv4_hnapt.cdrt_id = cdrt_id; entry.ipv4_hnapt.cdrt_id = cdrt_id;
if ((hash > 8192) || (hash < -1) || (hash % 4 != 0) || if ((hash >= hnat_priv->foe_etry_num) || (hash < -1) ||
(tport_id > 16) || (tport_id < 0) || (tport_id > 16) || (tport_id < 0) ||
(tops_entry > 64) || (tops_entry < 0) || (tops_entry > 64) || (tops_entry < 0) ||
(cdrt_id > 255) || (cdrt_id < 0) || (cdrt_id > 255) || (cdrt_id < 0) ||
@ -2324,24 +2343,25 @@ static ssize_t hnat_static_entry_write(struct file *file,
(entry.ipv4_hnapt.new_dport > 65535) || (entry.ipv4_hnapt.new_dport > 65535) ||
(entry.ipv4_hnapt.new_dport < 0)) { (entry.ipv4_hnapt.new_dport < 0)) {
hnat_static_entry_help(); hnat_static_entry_help();
return -EINVAL; return -EFAULT;
} }
#else #else
sscanf(buf, "%d %x %x %x %hx %hx %x %x %x %hx %hx %s %s", if (sscanf(buf, "%d %x %x %x %hx %hx %x %x %x %hx %hx %s %s",
&hash, &hash,
&entry.ipv4_hnapt.info_blk1, &entry.ipv4_hnapt.info_blk1,
&entry.ipv4_hnapt.sip, &entry.ipv4_hnapt.sip,
&entry.ipv4_hnapt.dip, &entry.ipv4_hnapt.dip,
&entry.ipv4_hnapt.sport, &entry.ipv4_hnapt.sport,
&entry.ipv4_hnapt.dport, &entry.ipv4_hnapt.dport,
&entry.ipv4_hnapt.info_blk2, &entry.ipv4_hnapt.info_blk2,
&entry.ipv4_hnapt.new_sip, &entry.ipv4_hnapt.new_sip,
&entry.ipv4_hnapt.new_dip, &entry.ipv4_hnapt.new_dip,
&entry.ipv4_hnapt.new_sport, &entry.ipv4_hnapt.new_sport,
&entry.ipv4_hnapt.new_dport, &entry.ipv4_hnapt.new_dport,
dmac_str, smac_str); dmac_str, smac_str) != 13)
return -EFAULT;
if ((hash > 8192) || (hash < -1) || (hash % 4 != 0) || if ((hash >= hnat_priv->foe_etry_num) || (hash < -1) ||
(entry.ipv4_hnapt.sport > 65535) || (entry.ipv4_hnapt.sport > 65535) ||
(entry.ipv4_hnapt.sport < 0) || (entry.ipv4_hnapt.sport < 0) ||
(entry.ipv4_hnapt.dport > 65535) || (entry.ipv4_hnapt.dport > 65535) ||
@ -2351,7 +2371,7 @@ static ssize_t hnat_static_entry_write(struct file *file,
(entry.ipv4_hnapt.new_dport > 65535) || (entry.ipv4_hnapt.new_dport > 65535) ||
(entry.ipv4_hnapt.new_dport < 0)) { (entry.ipv4_hnapt.new_dport < 0)) {
hnat_static_entry_help(); hnat_static_entry_help();
return -EINVAL; return -EFAULT;
} }
#endif #endif
@ -2507,7 +2527,11 @@ int hnat_init_debugfs(struct mtk_hnat *h)
h->regset[i]->nregs = ARRAY_SIZE(hnat_regs); h->regset[i]->nregs = ARRAY_SIZE(hnat_regs);
h->regset[i]->base = h->ppe_base[i]; h->regset[i]->base = h->ppe_base[i];
snprintf(name, sizeof(name), "regdump%ld", i); ret = snprintf(name, sizeof(name), "regdump%ld", i);
if (ret != strlen(name)) {
ret = -ENOMEM;
goto err1;
}
file = debugfs_create_regset32(name, 0444, file = debugfs_create_regset32(name, 0444,
root, h->regset[i]); root, h->regset[i]);
if (!file) { if (!file) {
@ -2544,13 +2568,21 @@ int hnat_init_debugfs(struct mtk_hnat *h)
&hnat_static_fops); &hnat_static_fops);
for (i = 0; i < hnat_priv->data->num_of_sch; i++) { for (i = 0; i < hnat_priv->data->num_of_sch; i++) {
snprintf(name, sizeof(name), "qdma_sch%ld", i); ret = snprintf(name, sizeof(name), "qdma_sch%ld", i);
if (ret != strlen(name)) {
ret = -ENOMEM;
goto err1;
}
debugfs_create_file(name, 0444, root, (void *)i, debugfs_create_file(name, 0444, root, (void *)i,
&hnat_sched_fops); &hnat_sched_fops);
} }
for (i = 0; i < MTK_QDMA_TX_NUM; i++) { for (i = 0; i < MTK_QDMA_TX_NUM; i++) {
snprintf(name, sizeof(name), "qdma_txq%ld", i); ret = snprintf(name, sizeof(name), "qdma_txq%ld", i);
if (ret != strlen(name)) {
ret = -ENOMEM;
goto err1;
}
debugfs_create_file(name, 0444, root, (void *)i, debugfs_create_file(name, 0444, root, (void *)i,
&hnat_queue_fops); &hnat_queue_fops);
} }

View File

@ -297,11 +297,11 @@ int hnat_mcast_enable(u32 ppe_id)
INIT_WORK(&pmcast->work, hnat_mcast_nlmsg_handler); INIT_WORK(&pmcast->work, hnat_mcast_nlmsg_handler);
pmcast->queue = create_singlethread_workqueue("ppe_mcast"); pmcast->queue = create_singlethread_workqueue("ppe_mcast");
if (!pmcast->queue) if (!pmcast->queue)
goto err; goto err1;
pmcast->msock = hnat_mcast_netlink_open(&init_net); pmcast->msock = hnat_mcast_netlink_open(&init_net);
if (!pmcast->msock) if (!pmcast->msock)
goto err; goto err2;
hnat_priv->pmcast = pmcast; hnat_priv->pmcast = pmcast;
@ -325,11 +325,10 @@ int hnat_mcast_enable(u32 ppe_id)
cr_set_field(hnat_priv->ppe_base[ppe_id] + PPE_MCAST_PPSE, MC_P3_PPSE, 5); cr_set_field(hnat_priv->ppe_base[ppe_id] + PPE_MCAST_PPSE, MC_P3_PPSE, 5);
return 0; return 0;
err: err2:
if (pmcast->queue) if (pmcast->queue)
destroy_workqueue(pmcast->queue); destroy_workqueue(pmcast->queue);
if (pmcast->msock) err1:
sock_release(pmcast->msock);
kfree(pmcast); kfree(pmcast);
return -1; return -1;

View File

@ -421,6 +421,10 @@ unsigned int do_hnat_ext_to_ge2(struct sk_buff *skb, const char *func)
trace_printk("%s: vlan_prot=0x%x, vlan_tci=%x\n", __func__, trace_printk("%s: vlan_prot=0x%x, vlan_tci=%x\n", __func__,
ntohs(skb->vlan_proto), skb->vlan_tci); ntohs(skb->vlan_proto), skb->vlan_tci);
if (skb_hnat_entry(skb) >= hnat_priv->foe_etry_num ||
skb_hnat_ppe(skb) >= CFG_PPE_NUM)
return -1;
dev = get_dev_from_index(skb->vlan_tci & VLAN_VID_MASK); dev = get_dev_from_index(skb->vlan_tci & VLAN_VID_MASK);
if (dev) { if (dev) {
@ -479,6 +483,10 @@ unsigned int do_hnat_ge_to_ext(struct sk_buff *skb, const char *func)
struct foe_entry *entry; struct foe_entry *entry;
struct net_device *dev; struct net_device *dev;
if (skb_hnat_entry(skb) >= hnat_priv->foe_etry_num ||
skb_hnat_ppe(skb) >= CFG_PPE_NUM)
return -1;
entry = &hnat_priv->foe_table_cpu[skb_hnat_ppe(skb)][skb_hnat_entry(skb)]; entry = &hnat_priv->foe_table_cpu[skb_hnat_ppe(skb)][skb_hnat_entry(skb)];
if (IS_IPV4_GRP(entry)) if (IS_IPV4_GRP(entry))
@ -730,6 +738,9 @@ static unsigned int
mtk_hnat_ipv6_nf_pre_routing(void *priv, struct sk_buff *skb, mtk_hnat_ipv6_nf_pre_routing(void *priv, struct sk_buff *skb,
const struct nf_hook_state *state) const struct nf_hook_state *state)
{ {
if (!skb)
goto drop;
if (!is_ppe_support_type(skb)) { if (!is_ppe_support_type(skb)) {
hnat_set_head_frags(state, skb, 1, hnat_set_alg); hnat_set_head_frags(state, skb, 1, hnat_set_alg);
return NF_ACCEPT; return NF_ACCEPT;
@ -743,8 +754,6 @@ mtk_hnat_ipv6_nf_pre_routing(void *priv, struct sk_buff *skb,
if (do_ext2ge_fast_try(state->in, skb)) { if (do_ext2ge_fast_try(state->in, skb)) {
if (!do_hnat_ext_to_ge(skb, state->in, __func__)) if (!do_hnat_ext_to_ge(skb, state->in, __func__))
return NF_STOLEN; return NF_STOLEN;
if (!skb)
goto drop;
return NF_ACCEPT; return NF_ACCEPT;
} }
@ -772,12 +781,14 @@ mtk_hnat_ipv6_nf_pre_routing(void *priv, struct sk_buff *skb,
#endif #endif
return NF_ACCEPT; return NF_ACCEPT;
drop: drop:
printk_ratelimited(KERN_WARNING if (skb)
"%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", printk_ratelimited(KERN_WARNING
__func__, state->in->name, skb_hnat_iface(skb), "%s:drop (in_dev=%s, iif=0x%x, CB2=0x%x, ppe_hash=0x%x,\n"
HNAT_SKB_CB2(skb)->magic, skb_hnat_entry(skb), "sport=0x%x, reason=0x%x, alg=0x%x)\n",
skb_hnat_sport(skb), skb_hnat_reason(skb), __func__, state->in->name, skb_hnat_iface(skb),
skb_hnat_alg(skb)); HNAT_SKB_CB2(skb)->magic, skb_hnat_entry(skb),
skb_hnat_sport(skb), skb_hnat_reason(skb),
skb_hnat_alg(skb));
return NF_DROP; return NF_DROP;
} }
@ -786,6 +797,9 @@ static unsigned int
mtk_hnat_ipv4_nf_pre_routing(void *priv, struct sk_buff *skb, mtk_hnat_ipv4_nf_pre_routing(void *priv, struct sk_buff *skb,
const struct nf_hook_state *state) const struct nf_hook_state *state)
{ {
if (!skb)
goto drop;
if (!is_ppe_support_type(skb)) { if (!is_ppe_support_type(skb)) {
hnat_set_head_frags(state, skb, 1, hnat_set_alg); hnat_set_head_frags(state, skb, 1, hnat_set_alg);
return NF_ACCEPT; return NF_ACCEPT;
@ -799,8 +813,6 @@ mtk_hnat_ipv4_nf_pre_routing(void *priv, struct sk_buff *skb,
if (do_ext2ge_fast_try(state->in, skb)) { if (do_ext2ge_fast_try(state->in, skb)) {
if (!do_hnat_ext_to_ge(skb, state->in, __func__)) if (!do_hnat_ext_to_ge(skb, state->in, __func__))
return NF_STOLEN; return NF_STOLEN;
if (!skb)
goto drop;
return NF_ACCEPT; return NF_ACCEPT;
} }
@ -815,12 +827,14 @@ mtk_hnat_ipv4_nf_pre_routing(void *priv, struct sk_buff *skb,
return NF_ACCEPT; return NF_ACCEPT;
drop: drop:
printk_ratelimited(KERN_WARNING if (skb)
"%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", printk_ratelimited(KERN_WARNING
__func__, state->in->name, skb_hnat_iface(skb), "%s:drop (in_dev=%s, iif=0x%x, CB2=0x%x, ppe_hash=0x%x,\n"
HNAT_SKB_CB2(skb)->magic, skb_hnat_entry(skb), "sport=0x%x, reason=0x%x, alg=0x%x)\n",
skb_hnat_sport(skb), skb_hnat_reason(skb), __func__, state->in->name, skb_hnat_iface(skb),
skb_hnat_alg(skb)); HNAT_SKB_CB2(skb)->magic, skb_hnat_entry(skb),
skb_hnat_sport(skb), skb_hnat_reason(skb),
skb_hnat_alg(skb));
return NF_DROP; return NF_DROP;
} }
@ -831,6 +845,9 @@ mtk_hnat_br_nf_local_in(void *priv, struct sk_buff *skb,
{ {
struct vlan_ethhdr *veth; struct vlan_ethhdr *veth;
if (!skb)
goto drop;
if (IS_HQOS_MODE && hnat_priv->data->whnat) { if (IS_HQOS_MODE && hnat_priv->data->whnat) {
veth = (struct vlan_ethhdr *)skb_mac_header(skb); veth = (struct vlan_ethhdr *)skb_mac_header(skb);
@ -863,8 +880,6 @@ mtk_hnat_br_nf_local_in(void *priv, struct sk_buff *skb,
if (!do_hnat_ext_to_ge(skb, state->in, __func__)) if (!do_hnat_ext_to_ge(skb, state->in, __func__))
return NF_STOLEN; return NF_STOLEN;
if (!skb)
goto drop;
return NF_ACCEPT; return NF_ACCEPT;
} }
@ -899,12 +914,14 @@ mtk_hnat_br_nf_local_in(void *priv, struct sk_buff *skb,
#endif #endif
return NF_ACCEPT; return NF_ACCEPT;
drop: drop:
printk_ratelimited(KERN_WARNING if (skb)
"%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", printk_ratelimited(KERN_WARNING
__func__, state->in->name, skb_hnat_iface(skb), "%s:drop (in_dev=%s, iif=0x%x, CB2=0x%x, ppe_hash=0x%x,\n"
HNAT_SKB_CB2(skb)->magic, skb_hnat_entry(skb), "sport=0x%x, reason=0x%x, alg=0x%x)\n",
skb_hnat_sport(skb), skb_hnat_reason(skb), __func__, state->in->name, skb_hnat_iface(skb),
skb_hnat_alg(skb)); HNAT_SKB_CB2(skb)->magic, skb_hnat_entry(skb),
skb_hnat_sport(skb), skb_hnat_reason(skb),
skb_hnat_alg(skb));
return NF_DROP; return NF_DROP;
} }
@ -1621,7 +1638,9 @@ static unsigned int skb_to_hnat_info(struct sk_buff *skb,
wmb(); wmb();
memcpy(foe, &entry, sizeof(entry)); memcpy(foe, &entry, sizeof(entry));
/*reset statistic for this entry*/ /*reset statistic for this entry*/
if (hnat_priv->data->per_flow_accounting) if (hnat_priv->data->per_flow_accounting &&
skb_hnat_entry(skb) < hnat_priv->foe_etry_num &&
skb_hnat_ppe(skb) < CFG_PPE_NUM)
memset(&hnat_priv->acct[skb_hnat_ppe(skb)][skb_hnat_entry(skb)], memset(&hnat_priv->acct[skb_hnat_ppe(skb)][skb_hnat_entry(skb)],
0, sizeof(struct mib_entry)); 0, sizeof(struct mib_entry));
@ -2020,6 +2039,10 @@ static unsigned int mtk_hnat_nf_post_routing(
trace_printk("[%s] case hit, %x-->%s, reason=%x\n", __func__, trace_printk("[%s] case hit, %x-->%s, reason=%x\n", __func__,
skb_hnat_iface(skb), out->name, skb_hnat_reason(skb)); skb_hnat_iface(skb), out->name, skb_hnat_reason(skb));
if (skb_hnat_entry(skb) >= hnat_priv->foe_etry_num ||
skb_hnat_ppe(skb) >= CFG_PPE_NUM)
return -1;
entry = &hnat_priv->foe_table_cpu[skb_hnat_ppe(skb)][skb_hnat_entry(skb)]; entry = &hnat_priv->foe_table_cpu[skb_hnat_ppe(skb)][skb_hnat_entry(skb)];
switch (skb_hnat_reason(skb)) { switch (skb_hnat_reason(skb)) {
@ -2083,6 +2106,10 @@ mtk_hnat_ipv6_nf_local_out(void *priv, struct sk_buff *skb,
if (unlikely(!skb_hnat_is_hashed(skb))) if (unlikely(!skb_hnat_is_hashed(skb)))
return NF_ACCEPT; return NF_ACCEPT;
if (skb_hnat_entry(skb) >= hnat_priv->foe_etry_num ||
skb_hnat_ppe(skb) >= CFG_PPE_NUM)
return NF_ACCEPT;
entry = &hnat_priv->foe_table_cpu[skb_hnat_ppe(skb)][skb_hnat_entry(skb)]; entry = &hnat_priv->foe_table_cpu[skb_hnat_ppe(skb)][skb_hnat_entry(skb)];
if (skb_hnat_reason(skb) == HIT_UNBIND_RATE_REACH) { if (skb_hnat_reason(skb) == HIT_UNBIND_RATE_REACH) {
ip6h = ipv6_hdr(skb); ip6h = ipv6_hdr(skb);
@ -2138,17 +2165,24 @@ static unsigned int
mtk_hnat_ipv6_nf_post_routing(void *priv, struct sk_buff *skb, mtk_hnat_ipv6_nf_post_routing(void *priv, struct sk_buff *skb,
const struct nf_hook_state *state) const struct nf_hook_state *state)
{ {
if (!skb)
goto drop;
post_routing_print(skb, state->in, state->out, __func__); post_routing_print(skb, state->in, state->out, __func__);
if (!mtk_hnat_nf_post_routing(skb, state->out, hnat_ipv6_get_nexthop, if (!mtk_hnat_nf_post_routing(skb, state->out, hnat_ipv6_get_nexthop,
__func__)) __func__))
return NF_ACCEPT; return NF_ACCEPT;
trace_printk( drop:
"%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", if (skb)
__func__, skb_hnat_iface(skb), state->out->name, HNAT_SKB_CB2(skb)->magic, trace_printk(
skb_hnat_entry(skb), skb_hnat_sport(skb), skb_hnat_reason(skb), "%s:drop (iif=0x%x, out_dev=%s, CB2=0x%x, ppe_hash=0x%x,\n"
skb_hnat_alg(skb)); "sport=0x%x, reason=0x%x, alg=0x%x)\n",
__func__, skb_hnat_iface(skb), state->out->name,
HNAT_SKB_CB2(skb)->magic, skb_hnat_entry(skb),
skb_hnat_sport(skb), skb_hnat_reason(skb),
skb_hnat_alg(skb));
return NF_DROP; return NF_DROP;
} }
@ -2157,17 +2191,24 @@ static unsigned int
mtk_hnat_ipv4_nf_post_routing(void *priv, struct sk_buff *skb, mtk_hnat_ipv4_nf_post_routing(void *priv, struct sk_buff *skb,
const struct nf_hook_state *state) const struct nf_hook_state *state)
{ {
if (!skb)
goto drop;
post_routing_print(skb, state->in, state->out, __func__); post_routing_print(skb, state->in, state->out, __func__);
if (!mtk_hnat_nf_post_routing(skb, state->out, hnat_ipv4_get_nexthop, if (!mtk_hnat_nf_post_routing(skb, state->out, hnat_ipv4_get_nexthop,
__func__)) __func__))
return NF_ACCEPT; return NF_ACCEPT;
trace_printk( drop:
"%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", if (skb)
__func__, skb_hnat_iface(skb), state->out->name, HNAT_SKB_CB2(skb)->magic, trace_printk(
skb_hnat_entry(skb), skb_hnat_sport(skb), skb_hnat_reason(skb), "%s:drop (iif=0x%x, out_dev=%s, CB2=0x%x, ppe_hash=0x%x,\n"
skb_hnat_alg(skb)); "sport=0x%x, reason=0x%x, alg=0x%x)\n",
__func__, skb_hnat_iface(skb), state->out->name,
HNAT_SKB_CB2(skb)->magic, skb_hnat_entry(skb),
skb_hnat_sport(skb), skb_hnat_reason(skb),
skb_hnat_alg(skb));
return NF_DROP; return NF_DROP;
} }
@ -2202,13 +2243,16 @@ mtk_pong_hqos_handler(void *priv, struct sk_buff *skb,
} }
return NF_ACCEPT; return NF_ACCEPT;
drop: drop:
printk_ratelimited(KERN_WARNING if (skb)
"%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", printk_ratelimited(KERN_WARNING
__func__, state->in->name, skb_hnat_iface(skb), "%s:drop (in_dev=%s, iif=0x%x, CB2=0x%x, ppe_hash=0x%x,\n"
HNAT_SKB_CB2(skb)->magic, skb_hnat_entry(skb), "sport=0x%x, reason=0x%x, alg=0x%x)\n",
skb_hnat_sport(skb), skb_hnat_reason(skb), __func__, state->in->name, skb_hnat_iface(skb),
skb_hnat_alg(skb)); HNAT_SKB_CB2(skb)->magic, skb_hnat_entry(skb),
skb_hnat_sport(skb), skb_hnat_reason(skb),
skb_hnat_alg(skb));
return NF_DROP; return NF_DROP;
} }
@ -2217,16 +2261,23 @@ static unsigned int
mtk_hnat_br_nf_local_out(void *priv, struct sk_buff *skb, mtk_hnat_br_nf_local_out(void *priv, struct sk_buff *skb,
const struct nf_hook_state *state) const struct nf_hook_state *state)
{ {
if (!skb)
goto drop;
post_routing_print(skb, state->in, state->out, __func__); post_routing_print(skb, state->in, state->out, __func__);
if (!mtk_hnat_nf_post_routing(skb, state->out, 0, __func__)) if (!mtk_hnat_nf_post_routing(skb, state->out, 0, __func__))
return NF_ACCEPT; return NF_ACCEPT;
trace_printk( drop:
"%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", if (skb)
__func__, skb_hnat_iface(skb), state->out->name, HNAT_SKB_CB2(skb)->magic, trace_printk(
skb_hnat_entry(skb), skb_hnat_sport(skb), skb_hnat_reason(skb), "%s:drop (iif=0x%x, out_dev=%s, CB2=0x%x, ppe_hash=0x%x,\n"
skb_hnat_alg(skb)); "sport=0x%x, reason=0x%x, alg=0x%x)\n",
__func__, skb_hnat_iface(skb), state->out->name,
HNAT_SKB_CB2(skb)->magic, skb_hnat_entry(skb),
skb_hnat_sport(skb), skb_hnat_reason(skb),
skb_hnat_alg(skb));
return NF_DROP; return NF_DROP;
} }
@ -2242,6 +2293,10 @@ mtk_hnat_ipv4_nf_local_out(void *priv, struct sk_buff *skb,
if (!skb_hnat_is_hashed(skb)) if (!skb_hnat_is_hashed(skb))
return NF_ACCEPT; return NF_ACCEPT;
if (skb_hnat_entry(skb) >= hnat_priv->foe_etry_num ||
skb_hnat_ppe(skb) >= CFG_PPE_NUM)
return NF_ACCEPT;
entry = &hnat_priv->foe_table_cpu[skb_hnat_ppe(skb)][skb_hnat_entry(skb)]; entry = &hnat_priv->foe_table_cpu[skb_hnat_ppe(skb)][skb_hnat_entry(skb)];
if (unlikely(skb_headroom(skb) < FOE_INFO_LEN)) { if (unlikely(skb_headroom(skb) < FOE_INFO_LEN)) {