1 --- a/include/uapi/linux/netfilter_ipv4/ip_tables.h
2 +++ b/include/uapi/linux/netfilter_ipv4/ip_tables.h
3 @@ -87,6 +87,7 @@ struct ipt_ip {
4 #define IPT_F_FRAG 0x01 /* Set if rule is a fragment rule */
5 #define IPT_F_GOTO 0x02 /* Set if jump is a goto */
6 #define IPT_F_MASK 0x03 /* All possible flag bits mask. */
7 +#define IPT_F_NO_DEF_MATCH 0x80 /* Internal: no default match rules present */
9 /* Values for "inv" field in struct ipt_ip. */
10 #define IPT_INV_VIA_IN 0x01 /* Invert the sense of IN IFACE. */
11 --- a/net/ipv4/netfilter/ip_tables.c
12 +++ b/net/ipv4/netfilter/ip_tables.c
13 @@ -81,6 +81,9 @@ ip_packet_match(const struct iphdr *ip,
15 #define FWINV(bool, invflg) ((bool) ^ !!(ipinfo->invflags & (invflg)))
17 + if (ipinfo->flags & IPT_F_NO_DEF_MATCH)
20 if (FWINV((ip->saddr&ipinfo->smsk.s_addr) != ipinfo->src.s_addr,
22 FWINV((ip->daddr&ipinfo->dmsk.s_addr) != ipinfo->dst.s_addr,
23 @@ -134,6 +137,29 @@ ip_packet_match(const struct iphdr *ip,
28 +ip_checkdefault(struct ipt_ip *ip)
30 + static const char iface_mask[IFNAMSIZ] = {};
32 + if (ip->invflags || ip->flags & IPT_F_FRAG)
35 + if (memcmp(ip->iniface_mask, iface_mask, IFNAMSIZ) != 0)
38 + if (memcmp(ip->outiface_mask, iface_mask, IFNAMSIZ) != 0)
41 + if (ip->smsk.s_addr || ip->dmsk.s_addr)
47 + ip->flags |= IPT_F_NO_DEF_MATCH;
51 ip_checkentry(const struct ipt_ip *ip)
53 @@ -560,7 +586,7 @@ static void cleanup_match(struct xt_entr
57 -check_entry(const struct ipt_entry *e, const char *name)
58 +check_entry(struct ipt_entry *e, const char *name)
60 const struct xt_entry_target *t;
62 @@ -569,6 +595,8 @@ check_entry(const struct ipt_entry *e, c
66 + ip_checkdefault(&e->ip);
68 if (e->target_offset + sizeof(struct xt_entry_target) >
71 @@ -930,6 +958,7 @@ copy_entries_to_user(unsigned int total_
72 const struct xt_table_info *private = table->private;
74 const void *loc_cpu_entry;
77 counters = alloc_counters(table);
79 @@ -960,6 +989,14 @@ copy_entries_to_user(unsigned int total_
84 + flags = e->ip.flags & IPT_F_MASK;
85 + if (copy_to_user(userptr + off
86 + + offsetof(struct ipt_entry, ip.flags),
87 + &flags, sizeof(flags)) != 0) {
92 for (i = sizeof(struct ipt_entry);