--- zzzz-none-000/linux-2.6.32.60/net/ipv4/netfilter/ip_tables.c 2012-10-07 21:41:24.000000000 +0000 +++ ur8-7270-606/linux-2.6.32.60/net/ipv4/netfilter/ip_tables.c 2011-07-20 07:23:51.000000000 +0000 @@ -60,6 +60,13 @@ #define IP_NF_ASSERT(x) #endif +#ifdef CONFIG_ATHRS_HW_ACL + +athr_nf_acl_ops_t *athr_acl_sw_ops; +EXPORT_SYMBOL(athr_acl_sw_ops); + +#endif + #if 0 /* All the better to debug you with... */ #define static @@ -88,6 +95,9 @@ #define FWINV(bool, invflg) ((bool) ^ !!(ipinfo->invflags & (invflg))) + if (ipinfo->flags & IPT_F_NO_DEF_MATCH) + return true; + if (FWINV((ip->saddr&ipinfo->smsk.s_addr) != ipinfo->src.s_addr, IPT_INV_SRCIP) || FWINV((ip->daddr&ipinfo->dmsk.s_addr) != ipinfo->dst.s_addr, @@ -138,13 +148,35 @@ return false; } +#undef FWINV return true; } static bool -ip_checkentry(const struct ipt_ip *ip) +ip_checkentry(struct ipt_ip *ip) { - if (ip->flags & ~IPT_F_MASK) { +#define FWINV(bool, invflg) ((bool) || (ip->invflags & (invflg))) + + if (FWINV(ip->smsk.s_addr, IPT_INV_SRCIP) || + FWINV(ip->dmsk.s_addr, IPT_INV_DSTIP)) + goto has_match_rules; + + if (FWINV(!!((const unsigned long *)ip->iniface_mask)[0], + IPT_INV_VIA_IN) || + FWINV(!!((const unsigned long *)ip->outiface_mask)[0], + IPT_INV_VIA_OUT)) + goto has_match_rules; + + if (FWINV(ip->proto, IPT_INV_PROTO)) + goto has_match_rules; + + if (FWINV(ip->flags&IPT_F_FRAG, IPT_INV_FRAG)) + goto has_match_rules; + + ip->flags |= IPT_F_NO_DEF_MATCH; + +has_match_rules: + if (ip->flags & ~(IPT_F_MASK|IPT_F_NO_DEF_MATCH)) { duprintf("Unknown flag bits set: %08X\n", ip->flags & ~IPT_F_MASK); return false; @@ -154,6 +186,8 @@ ip->invflags & ~IPT_INV_MASK); return false; } + +#undef FWINV return true; } @@ -196,7 +230,6 @@ static const struct ipt_ip uncond; return memcmp(ip, &uncond, sizeof(uncond)) == 0; -#undef FWINV } #if defined(CONFIG_NETFILTER_XT_TARGET_TRACE) || \ @@ -322,7 +355,42 @@ struct xt_target_param tgpar; /* Initialization */ +#ifdef CONFIG_ATHRS_HW_NAT + if ((skb->ath_hw_nat_fw_flags == 2 || + skb->ath_hw_nat_fw_flags == 3) && + (0 == strncmp(table->name,"nat",3))) { + return NF_ACCEPT; + } +#endif +#ifdef CONFIG_ATHRS_HW_ACL + if (skb->ath_hw_nat_fw_flags == 3 && + (0 == strncmp(table->name,"filter",6))) { + return NF_ACCEPT; + } +#endif + ip = ip_hdr(skb); + + IP_NF_ASSERT(table->valid_hooks & (1 << hook)); + xt_info_rdlock_bh(); + private = table->private; + table_base = private->entries[smp_processor_id()]; + e = get_entry(table_base, private->hook_entry[hook]); + + if (e->target_offset <= sizeof(struct ipt_entry) && + (e->ip.flags & IPT_F_NO_DEF_MATCH)) { + struct ipt_entry_target *t = ipt_get_target(e); + if (!t->u.kernel.target->target) { + int v = ((struct ipt_standard_target *)t)->verdict; + if ((v < 0) && (v != IPT_RETURN)) { + ADD_COUNTER(e->counters, ntohs(ip->tot_len), 1); + xt_info_rdunlock_bh(); + return (unsigned)(-v) - 1; + } + } + } + + /* Initialization */ indev = in ? in->name : nulldevname; outdev = out ? out->name : nulldevname; /* We handle fragments by dealing with the first fragment as @@ -339,13 +407,6 @@ mtpar.family = tgpar.family = NFPROTO_IPV4; mtpar.hooknum = tgpar.hooknum = hook; - IP_NF_ASSERT(table->valid_hooks & (1 << hook)); - xt_info_rdlock_bh(); - private = table->private; - table_base = private->entries[smp_processor_id()]; - - e = get_entry(table_base, private->hook_entry[hook]); - /* For return from builtin chain */ back = get_entry(table_base, private->underflow[hook]); @@ -809,6 +870,9 @@ { unsigned int i; int ret; +#ifdef CONFIG_ATHRS_HW_ACL + void (*athr_parse_iptables)(void *, unsigned int, char *); +#endif newinfo->size = size; newinfo->number = number; @@ -874,6 +938,14 @@ memcpy(newinfo->entries[i], entry0, newinfo->size); } +#ifdef CONFIG_ATHRS_HW_ACL + if (athr_acl_sw_ops) { + athr_parse_iptables = rcu_dereference(athr_acl_sw_ops->nf_parse_tables); + if (athr_parse_iptables) + athr_parse_iptables(entry0, newinfo->size, (char *)name); + } +#endif + return ret; } @@ -992,6 +1064,7 @@ unsigned int i; const struct ipt_entry_match *m; const struct ipt_entry_target *t; + u8 flags; e = (struct ipt_entry *)(loc_cpu_entry + off); if (copy_to_user(userptr + off @@ -1001,6 +1074,14 @@ ret = -EFAULT; goto free_counters; } + + flags = e->ip.flags & ~IPT_F_NO_DEF_MATCH; + if (copy_to_user(userptr + off + + offsetof(struct ipt_entry, ip.flags), + &flags, sizeof(flags)) != 0) { + ret = -EFAULT; + goto free_counters; + } for (i = sizeof(struct ipt_entry); i < e->target_offset;