Commit 8cc848fa authored by Patrick McHardy's avatar Patrick McHardy

Merge branch 'master' of git://dev.medozas.de/linux

parents a17c8598 45185364
...@@ -142,6 +142,12 @@ static inline int ebt_basic_match(struct ebt_entry *e, struct ethhdr *h, ...@@ -142,6 +142,12 @@ static inline int ebt_basic_match(struct ebt_entry *e, struct ethhdr *h,
return 0; return 0;
} }
static inline __pure
struct ebt_entry *ebt_next_entry(const struct ebt_entry *entry)
{
return (void *)entry + entry->next_offset;
}
/* Do some firewalling */ /* Do some firewalling */
unsigned int ebt_do_table (unsigned int hook, struct sk_buff *skb, unsigned int ebt_do_table (unsigned int hook, struct sk_buff *skb,
const struct net_device *in, const struct net_device *out, const struct net_device *in, const struct net_device *out,
...@@ -249,8 +255,7 @@ unsigned int ebt_do_table (unsigned int hook, struct sk_buff *skb, ...@@ -249,8 +255,7 @@ unsigned int ebt_do_table (unsigned int hook, struct sk_buff *skb,
/* jump to a udc */ /* jump to a udc */
cs[sp].n = i + 1; cs[sp].n = i + 1;
cs[sp].chaininfo = chaininfo; cs[sp].chaininfo = chaininfo;
cs[sp].e = (struct ebt_entry *) cs[sp].e = ebt_next_entry(point);
(((char *)point) + point->next_offset);
i = 0; i = 0;
chaininfo = (struct ebt_entries *) (base + verdict); chaininfo = (struct ebt_entries *) (base + verdict);
#ifdef CONFIG_NETFILTER_DEBUG #ifdef CONFIG_NETFILTER_DEBUG
...@@ -266,8 +271,7 @@ unsigned int ebt_do_table (unsigned int hook, struct sk_buff *skb, ...@@ -266,8 +271,7 @@ unsigned int ebt_do_table (unsigned int hook, struct sk_buff *skb,
sp++; sp++;
continue; continue;
letscontinue: letscontinue:
point = (struct ebt_entry *) point = ebt_next_entry(point);
(((char *)point) + point->next_offset);
i++; i++;
} }
...@@ -787,7 +791,7 @@ static int check_chainloops(struct ebt_entries *chain, struct ebt_cl_stack *cl_s ...@@ -787,7 +791,7 @@ static int check_chainloops(struct ebt_entries *chain, struct ebt_cl_stack *cl_s
/* this can't be 0, so the loop test is correct */ /* this can't be 0, so the loop test is correct */
cl_s[i].cs.n = pos + 1; cl_s[i].cs.n = pos + 1;
pos = 0; pos = 0;
cl_s[i].cs.e = ((void *)e + e->next_offset); cl_s[i].cs.e = ebt_next_entry(e);
e = (struct ebt_entry *)(hlp2->data); e = (struct ebt_entry *)(hlp2->data);
nentries = hlp2->nentries; nentries = hlp2->nentries;
cl_s[i].from = chain_nr; cl_s[i].from = chain_nr;
...@@ -797,7 +801,7 @@ static int check_chainloops(struct ebt_entries *chain, struct ebt_cl_stack *cl_s ...@@ -797,7 +801,7 @@ static int check_chainloops(struct ebt_entries *chain, struct ebt_cl_stack *cl_s
continue; continue;
} }
letscontinue: letscontinue:
e = (void *)e + e->next_offset; e = ebt_next_entry(e);
pos++; pos++;
} }
return 0; return 0;
......
...@@ -231,6 +231,12 @@ static inline struct arpt_entry *get_entry(void *base, unsigned int offset) ...@@ -231,6 +231,12 @@ static inline struct arpt_entry *get_entry(void *base, unsigned int offset)
return (struct arpt_entry *)(base + offset); return (struct arpt_entry *)(base + offset);
} }
static inline __pure
struct arpt_entry *arpt_next_entry(const struct arpt_entry *entry)
{
return (void *)entry + entry->next_offset;
}
unsigned int arpt_do_table(struct sk_buff *skb, unsigned int arpt_do_table(struct sk_buff *skb,
unsigned int hook, unsigned int hook,
const struct net_device *in, const struct net_device *in,
...@@ -267,67 +273,64 @@ unsigned int arpt_do_table(struct sk_buff *skb, ...@@ -267,67 +273,64 @@ unsigned int arpt_do_table(struct sk_buff *skb,
arp = arp_hdr(skb); arp = arp_hdr(skb);
do { do {
if (arp_packet_match(arp, skb->dev, indev, outdev, &e->arp)) { struct arpt_entry_target *t;
struct arpt_entry_target *t; int hdr_len;
int hdr_len;
hdr_len = sizeof(*arp) + (2 * sizeof(struct in_addr)) +
(2 * skb->dev->addr_len);
ADD_COUNTER(e->counters, hdr_len, 1); if (!arp_packet_match(arp, skb->dev, indev, outdev, &e->arp)) {
e = arpt_next_entry(e);
continue;
}
t = arpt_get_target(e); hdr_len = sizeof(*arp) + (2 * sizeof(struct in_addr)) +
(2 * skb->dev->addr_len);
ADD_COUNTER(e->counters, hdr_len, 1);
/* Standard target? */ t = arpt_get_target(e);
if (!t->u.kernel.target->target) {
int v;
v = ((struct arpt_standard_target *)t)->verdict; /* Standard target? */
if (v < 0) { if (!t->u.kernel.target->target) {
/* Pop from stack? */ int v;
if (v != ARPT_RETURN) {
verdict = (unsigned)(-v) - 1;
break;
}
e = back;
back = get_entry(table_base,
back->comefrom);
continue;
}
if (table_base + v
!= (void *)e + e->next_offset) {
/* Save old back ptr in next entry */
struct arpt_entry *next
= (void *)e + e->next_offset;
next->comefrom =
(void *)back - table_base;
/* set back pointer to next entry */
back = next;
}
e = get_entry(table_base, v); v = ((struct arpt_standard_target *)t)->verdict;
} else { if (v < 0) {
/* Targets which reenter must return /* Pop from stack? */
* abs. verdicts if (v != ARPT_RETURN) {
*/ verdict = (unsigned)(-v) - 1;
tgpar.target = t->u.kernel.target;
tgpar.targinfo = t->data;
verdict = t->u.kernel.target->target(skb,
&tgpar);
/* Target might have changed stuff. */
arp = arp_hdr(skb);
if (verdict == ARPT_CONTINUE)
e = (void *)e + e->next_offset;
else
/* Verdict */
break; break;
}
e = back;
back = get_entry(table_base, back->comefrom);
continue;
} }
} else { if (table_base + v
e = (void *)e + e->next_offset; != arpt_next_entry(e)) {
/* Save old back ptr in next entry */
struct arpt_entry *next = arpt_next_entry(e);
next->comefrom = (void *)back - table_base;
/* set back pointer to next entry */
back = next;
}
e = get_entry(table_base, v);
continue;
} }
/* Targets which reenter must return
* abs. verdicts
*/
tgpar.target = t->u.kernel.target;
tgpar.targinfo = t->data;
verdict = t->u.kernel.target->target(skb, &tgpar);
/* Target might have changed stuff. */
arp = arp_hdr(skb);
if (verdict == ARPT_CONTINUE)
e = arpt_next_entry(e);
else
/* Verdict */
break;
} while (!hotdrop); } while (!hotdrop);
xt_info_rdunlock_bh(); xt_info_rdunlock_bh();
......
...@@ -596,7 +596,7 @@ static int __init ip_queue_init(void) ...@@ -596,7 +596,7 @@ static int __init ip_queue_init(void)
#ifdef CONFIG_SYSCTL #ifdef CONFIG_SYSCTL
ipq_sysctl_header = register_sysctl_paths(net_ipv4_ctl_path, ipq_table); ipq_sysctl_header = register_sysctl_paths(net_ipv4_ctl_path, ipq_table);
#endif #endif
status = nf_register_queue_handler(PF_INET, &nfqh); status = nf_register_queue_handler(NFPROTO_IPV4, &nfqh);
if (status < 0) { if (status < 0) {
printk(KERN_ERR "ip_queue: failed to register queue handler\n"); printk(KERN_ERR "ip_queue: failed to register queue handler\n");
goto cleanup_sysctl; goto cleanup_sysctl;
......
...@@ -238,8 +238,8 @@ static struct nf_loginfo trace_loginfo = { ...@@ -238,8 +238,8 @@ static struct nf_loginfo trace_loginfo = {
/* Mildly perf critical (only if packet tracing is on) */ /* Mildly perf critical (only if packet tracing is on) */
static inline int static inline int
get_chainname_rulenum(struct ipt_entry *s, struct ipt_entry *e, get_chainname_rulenum(struct ipt_entry *s, struct ipt_entry *e,
char *hookname, char **chainname, const char *hookname, const char **chainname,
char **comment, unsigned int *rulenum) const char **comment, unsigned int *rulenum)
{ {
struct ipt_standard_target *t = (void *)ipt_get_target(s); struct ipt_standard_target *t = (void *)ipt_get_target(s);
...@@ -257,8 +257,8 @@ get_chainname_rulenum(struct ipt_entry *s, struct ipt_entry *e, ...@@ -257,8 +257,8 @@ get_chainname_rulenum(struct ipt_entry *s, struct ipt_entry *e,
&& unconditional(&s->ip)) { && unconditional(&s->ip)) {
/* Tail of chains: STANDARD target (return/policy) */ /* Tail of chains: STANDARD target (return/policy) */
*comment = *chainname == hookname *comment = *chainname == hookname
? (char *)comments[NF_IP_TRACE_COMMENT_POLICY] ? comments[NF_IP_TRACE_COMMENT_POLICY]
: (char *)comments[NF_IP_TRACE_COMMENT_RETURN]; : comments[NF_IP_TRACE_COMMENT_RETURN];
} }
return 1; return 1;
} else } else
...@@ -277,14 +277,14 @@ static void trace_packet(struct sk_buff *skb, ...@@ -277,14 +277,14 @@ static void trace_packet(struct sk_buff *skb,
{ {
void *table_base; void *table_base;
const struct ipt_entry *root; const struct ipt_entry *root;
char *hookname, *chainname, *comment; const char *hookname, *chainname, *comment;
unsigned int rulenum = 0; unsigned int rulenum = 0;
table_base = (void *)private->entries[smp_processor_id()]; table_base = private->entries[smp_processor_id()];
root = get_entry(table_base, private->hook_entry[hook]); root = get_entry(table_base, private->hook_entry[hook]);
hookname = chainname = (char *)hooknames[hook]; hookname = chainname = hooknames[hook];
comment = (char *)comments[NF_IP_TRACE_COMMENT_RULE]; comment = comments[NF_IP_TRACE_COMMENT_RULE];
IPT_ENTRY_ITERATE(root, IPT_ENTRY_ITERATE(root,
private->size - private->hook_entry[hook], private->size - private->hook_entry[hook],
...@@ -297,6 +297,12 @@ static void trace_packet(struct sk_buff *skb, ...@@ -297,6 +297,12 @@ static void trace_packet(struct sk_buff *skb,
} }
#endif #endif
static inline __pure
struct ipt_entry *ipt_next_entry(const struct ipt_entry *entry)
{
return (void *)entry + entry->next_offset;
}
/* Returns one of the generic firewall policies, like NF_ACCEPT. */ /* Returns one of the generic firewall policies, like NF_ACCEPT. */
unsigned int unsigned int
ipt_do_table(struct sk_buff *skb, ipt_do_table(struct sk_buff *skb,
...@@ -305,6 +311,8 @@ ipt_do_table(struct sk_buff *skb, ...@@ -305,6 +311,8 @@ ipt_do_table(struct sk_buff *skb,
const struct net_device *out, const struct net_device *out,
struct xt_table *table) struct xt_table *table)
{ {
#define tb_comefrom ((struct ipt_entry *)table_base)->comefrom
static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long)))); static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long))));
const struct iphdr *ip; const struct iphdr *ip;
u_int16_t datalen; u_int16_t datalen;
...@@ -348,92 +356,84 @@ ipt_do_table(struct sk_buff *skb, ...@@ -348,92 +356,84 @@ ipt_do_table(struct sk_buff *skb,
back = get_entry(table_base, private->underflow[hook]); back = get_entry(table_base, private->underflow[hook]);
do { do {
struct ipt_entry_target *t;
IP_NF_ASSERT(e); IP_NF_ASSERT(e);
IP_NF_ASSERT(back); IP_NF_ASSERT(back);
if (ip_packet_match(ip, indev, outdev, if (!ip_packet_match(ip, indev, outdev,
&e->ip, mtpar.fragoff)) { &e->ip, mtpar.fragoff) ||
struct ipt_entry_target *t; IPT_MATCH_ITERATE(e, do_match, skb, &mtpar) != 0) {
e = ipt_next_entry(e);
if (IPT_MATCH_ITERATE(e, do_match, skb, &mtpar) != 0) continue;
goto no_match; }
ADD_COUNTER(e->counters, ntohs(ip->tot_len), 1); ADD_COUNTER(e->counters, ntohs(ip->tot_len), 1);
t = ipt_get_target(e); t = ipt_get_target(e);
IP_NF_ASSERT(t->u.kernel.target); IP_NF_ASSERT(t->u.kernel.target);
#if defined(CONFIG_NETFILTER_XT_TARGET_TRACE) || \ #if defined(CONFIG_NETFILTER_XT_TARGET_TRACE) || \
defined(CONFIG_NETFILTER_XT_TARGET_TRACE_MODULE) defined(CONFIG_NETFILTER_XT_TARGET_TRACE_MODULE)
/* The packet is traced: log it */ /* The packet is traced: log it */
if (unlikely(skb->nf_trace)) if (unlikely(skb->nf_trace))
trace_packet(skb, hook, in, out, trace_packet(skb, hook, in, out,
table->name, private, e); table->name, private, e);
#endif #endif
/* Standard target? */ /* Standard target? */
if (!t->u.kernel.target->target) { if (!t->u.kernel.target->target) {
int v; int v;
v = ((struct ipt_standard_target *)t)->verdict; v = ((struct ipt_standard_target *)t)->verdict;
if (v < 0) { if (v < 0) {
/* Pop from stack? */ /* Pop from stack? */
if (v != IPT_RETURN) { if (v != IPT_RETURN) {
verdict = (unsigned)(-v) - 1; verdict = (unsigned)(-v) - 1;
break; break;
}
e = back;
back = get_entry(table_base,
back->comefrom);
continue;
}
if (table_base + v != (void *)e + e->next_offset
&& !(e->ip.flags & IPT_F_GOTO)) {
/* Save old back ptr in next entry */
struct ipt_entry *next
= (void *)e + e->next_offset;
next->comefrom
= (void *)back - table_base;
/* set back pointer to next entry */
back = next;
} }
e = back;
back = get_entry(table_base, back->comefrom);
continue;
}
if (table_base + v != ipt_next_entry(e)
&& !(e->ip.flags & IPT_F_GOTO)) {
/* Save old back ptr in next entry */
struct ipt_entry *next = ipt_next_entry(e);
next->comefrom = (void *)back - table_base;
/* set back pointer to next entry */
back = next;
}
e = get_entry(table_base, v);
continue;
}
/* Targets which reenter must return
abs. verdicts */
tgpar.target = t->u.kernel.target;
tgpar.targinfo = t->data;
e = get_entry(table_base, v);
} else {
/* Targets which reenter must return
abs. verdicts */
tgpar.target = t->u.kernel.target;
tgpar.targinfo = t->data;
#ifdef CONFIG_NETFILTER_DEBUG #ifdef CONFIG_NETFILTER_DEBUG
((struct ipt_entry *)table_base)->comefrom tb_comefrom = 0xeeeeeeec;
= 0xeeeeeeec;
#endif #endif
verdict = t->u.kernel.target->target(skb, verdict = t->u.kernel.target->target(skb, &tgpar);
&tgpar);
#ifdef CONFIG_NETFILTER_DEBUG #ifdef CONFIG_NETFILTER_DEBUG
if (((struct ipt_entry *)table_base)->comefrom if (comefrom != 0xeeeeeeec && verdict == IPT_CONTINUE) {
!= 0xeeeeeeec printk("Target %s reentered!\n",
&& verdict == IPT_CONTINUE) { t->u.kernel.target->name);
printk("Target %s reentered!\n", verdict = NF_DROP;
t->u.kernel.target->name); }
verdict = NF_DROP; tb_comefrom = 0x57acc001;
}
((struct ipt_entry *)table_base)->comefrom
= 0x57acc001;
#endif #endif
/* Target might have changed stuff. */ /* Target might have changed stuff. */
ip = ip_hdr(skb); ip = ip_hdr(skb);
datalen = skb->len - ip->ihl * 4; datalen = skb->len - ip->ihl * 4;
if (verdict == IPT_CONTINUE)
e = (void *)e + e->next_offset;
else
/* Verdict */
break;
}
} else {
no_match: if (verdict == IPT_CONTINUE)
e = (void *)e + e->next_offset; e = ipt_next_entry(e);
} else
/* Verdict */
break;
} while (!hotdrop); } while (!hotdrop);
xt_info_rdunlock_bh(); xt_info_rdunlock_bh();
...@@ -444,6 +444,8 @@ ipt_do_table(struct sk_buff *skb, ...@@ -444,6 +444,8 @@ ipt_do_table(struct sk_buff *skb,
return NF_DROP; return NF_DROP;
else return verdict; else return verdict;
#endif #endif
#undef tb_comefrom
} }
/* Figures out from what hook each rule can be called: returns 0 if /* Figures out from what hook each rule can be called: returns 0 if
...@@ -2158,7 +2160,7 @@ static bool icmp_checkentry(const struct xt_mtchk_param *par) ...@@ -2158,7 +2160,7 @@ static bool icmp_checkentry(const struct xt_mtchk_param *par)
static struct xt_target ipt_standard_target __read_mostly = { static struct xt_target ipt_standard_target __read_mostly = {
.name = IPT_STANDARD_TARGET, .name = IPT_STANDARD_TARGET,
.targetsize = sizeof(int), .targetsize = sizeof(int),
.family = AF_INET, .family = NFPROTO_IPV4,
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
.compatsize = sizeof(compat_int_t), .compatsize = sizeof(compat_int_t),
.compat_from_user = compat_standard_from_user, .compat_from_user = compat_standard_from_user,
...@@ -2170,7 +2172,7 @@ static struct xt_target ipt_error_target __read_mostly = { ...@@ -2170,7 +2172,7 @@ static struct xt_target ipt_error_target __read_mostly = {
.name = IPT_ERROR_TARGET, .name = IPT_ERROR_TARGET,
.target = ipt_error, .target = ipt_error,
.targetsize = IPT_FUNCTION_MAXNAMELEN, .targetsize = IPT_FUNCTION_MAXNAMELEN,
.family = AF_INET, .family = NFPROTO_IPV4,
}; };
static struct nf_sockopt_ops ipt_sockopts = { static struct nf_sockopt_ops ipt_sockopts = {
...@@ -2196,17 +2198,17 @@ static struct xt_match icmp_matchstruct __read_mostly = { ...@@ -2196,17 +2198,17 @@ static struct xt_match icmp_matchstruct __read_mostly = {
.matchsize = sizeof(struct ipt_icmp), .matchsize = sizeof(struct ipt_icmp),
.checkentry = icmp_checkentry, .checkentry = icmp_checkentry,
.proto = IPPROTO_ICMP, .proto = IPPROTO_ICMP,
.family = AF_INET, .family = NFPROTO_IPV4,
}; };
static int __net_init ip_tables_net_init(struct net *net) static int __net_init ip_tables_net_init(struct net *net)
{ {
return xt_proto_init(net, AF_INET); return xt_proto_init(net, NFPROTO_IPV4);
} }
static void __net_exit ip_tables_net_exit(struct net *net) static void __net_exit ip_tables_net_exit(struct net *net)
{ {
xt_proto_fini(net, AF_INET); xt_proto_fini(net, NFPROTO_IPV4);
} }
static struct pernet_operations ip_tables_net_ops = { static struct pernet_operations ip_tables_net_ops = {
......
...@@ -598,7 +598,7 @@ static int __init ip6_queue_init(void) ...@@ -598,7 +598,7 @@ static int __init ip6_queue_init(void)
#ifdef CONFIG_SYSCTL #ifdef CONFIG_SYSCTL
ipq_sysctl_header = register_sysctl_paths(net_ipv6_ctl_path, ipq_table); ipq_sysctl_header = register_sysctl_paths(net_ipv6_ctl_path, ipq_table);
#endif #endif
status = nf_register_queue_handler(PF_INET6, &nfqh); status = nf_register_queue_handler(NFPROTO_IPV6, &nfqh);
if (status < 0) { if (status < 0) {
printk(KERN_ERR "ip6_queue: failed to register queue handler\n"); printk(KERN_ERR "ip6_queue: failed to register queue handler\n");
goto cleanup_sysctl; goto cleanup_sysctl;
......
...@@ -270,8 +270,8 @@ static struct nf_loginfo trace_loginfo = { ...@@ -270,8 +270,8 @@ static struct nf_loginfo trace_loginfo = {
/* Mildly perf critical (only if packet tracing is on) */ /* Mildly perf critical (only if packet tracing is on) */
static inline int static inline int
get_chainname_rulenum(struct ip6t_entry *s, struct ip6t_entry *e, get_chainname_rulenum(struct ip6t_entry *s, struct ip6t_entry *e,
char *hookname, char **chainname, const char *hookname, const char **chainname,
char **comment, unsigned int *rulenum) const char **comment, unsigned int *rulenum)
{ {
struct ip6t_standard_target *t = (void *)ip6t_get_target(s); struct ip6t_standard_target *t = (void *)ip6t_get_target(s);
...@@ -289,8 +289,8 @@ get_chainname_rulenum(struct ip6t_entry *s, struct ip6t_entry *e, ...@@ -289,8 +289,8 @@ get_chainname_rulenum(struct ip6t_entry *s, struct ip6t_entry *e,
&& unconditional(&s->ipv6)) { && unconditional(&s->ipv6)) {
/* Tail of chains: STANDARD target (return/policy) */ /* Tail of chains: STANDARD target (return/policy) */
*comment = *chainname == hookname *comment = *chainname == hookname
? (char *)comments[NF_IP6_TRACE_COMMENT_POLICY] ? comments[NF_IP6_TRACE_COMMENT_POLICY]
: (char *)comments[NF_IP6_TRACE_COMMENT_RETURN]; : comments[NF_IP6_TRACE_COMMENT_RETURN];
} }
return 1; return 1;
} else } else
...@@ -309,14 +309,14 @@ static void trace_packet(struct sk_buff *skb, ...@@ -309,14 +309,14 @@ static void trace_packet(struct sk_buff *skb,
{ {
void *table_base; void *table_base;
const struct ip6t_entry *root; const struct ip6t_entry *root;
char *hookname, *chainname, *comment; const char *hookname, *chainname, *comment;
unsigned int rulenum = 0; unsigned int rulenum = 0;
table_base = (void *)private->entries[smp_processor_id()]; table_base = private->entries[smp_processor_id()];
root = get_entry(table_base, private->hook_entry[hook]); root = get_entry(table_base, private->hook_entry[hook]);
hookname = chainname = (char *)hooknames[hook]; hookname = chainname = hooknames[hook];
comment = (char *)comments[NF_IP6_TRACE_COMMENT_RULE]; comment = comments[NF_IP6_TRACE_COMMENT_RULE];
IP6T_ENTRY_ITERATE(root, IP6T_ENTRY_ITERATE(root,
private->size - private->hook_entry[hook], private->size - private->hook_entry[hook],
...@@ -329,6 +329,12 @@ static void trace_packet(struct sk_buff *skb, ...@@ -329,6 +329,12 @@ static void trace_packet(struct sk_buff *skb,
} }
#endif #endif
static inline __pure struct ip6t_entry *
ip6t_next_entry(const struct ip6t_entry *entry)
{
return (void *)entry + entry->next_offset;
}
/* Returns one of the generic firewall policies, like NF_ACCEPT. */ /* Returns one of the generic firewall policies, like NF_ACCEPT. */
unsigned int unsigned int
ip6t_do_table(struct sk_buff *skb, ip6t_do_table(struct sk_buff *skb,
...@@ -337,6 +343,8 @@ ip6t_do_table(struct sk_buff *skb, ...@@ -337,6 +343,8 @@ ip6t_do_table(struct sk_buff *skb,
const struct net_device *out, const struct net_device *out,
struct xt_table *table) struct xt_table *table)
{ {
#define tb_comefrom ((struct ip6t_entry *)table_base)->comefrom
static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long)))); static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long))));
bool hotdrop = false; bool hotdrop = false;
/* Initializing verdict to NF_DROP keeps gcc happy. */ /* Initializing verdict to NF_DROP keeps gcc happy. */
...@@ -375,96 +383,86 @@ ip6t_do_table(struct sk_buff *skb, ...@@ -375,96 +383,86 @@ ip6t_do_table(struct sk_buff *skb,
back = get_entry(table_base, private->underflow[hook]); back = get_entry(table_base, private->underflow[hook]);
do { do {
struct ip6t_entry_target *t;
IP_NF_ASSERT(e); IP_NF_ASSERT(e);
IP_NF_ASSERT(back); IP_NF_ASSERT(back);
if (ip6_packet_match(skb, indev, outdev, &e->ipv6, if (!ip6_packet_match(skb, indev, outdev, &e->ipv6,
&mtpar.thoff, &mtpar.fragoff, &hotdrop)) { &mtpar.thoff, &mtpar.fragoff, &hotdrop) ||
struct ip6t_entry_target *t; IP6T_MATCH_ITERATE(e, do_match, skb, &mtpar) != 0) {
e = ip6t_next_entry(e);
if (IP6T_MATCH_ITERATE(e, do_match, skb, &mtpar) != 0) continue;
goto no_match; }
ADD_COUNTER(e->counters, ADD_COUNTER(e->counters,
ntohs(ipv6_hdr(skb)->payload_len) + ntohs(ipv6_hdr(skb)->payload_len) +
sizeof(struct ipv6hdr), 1); sizeof(struct ipv6hdr), 1);
t = ip6t_get_target(e); t = ip6t_get_target(e);
IP_NF_ASSERT(t->u.kernel.target); IP_NF_ASSERT(t->u.kernel.target);
#if defined(CONFIG_NETFILTER_XT_TARGET_TRACE) || \ #if defined(CONFIG_NETFILTER_XT_TARGET_TRACE) || \
defined(CONFIG_NETFILTER_XT_TARGET_TRACE_MODULE) defined(CONFIG_NETFILTER_XT_TARGET_TRACE_MODULE)
/* The packet is traced: log it */ /* The packet is traced: log it */
if (unlikely(skb->nf_trace)) if (unlikely(skb->nf_trace))
trace_packet(skb, hook, in, out, trace_packet(skb, hook, in, out,
table->name, private, e); table->name, private, e);
#endif #endif
/* Standard target? */ /* Standard target? */
if (!t->u.kernel.target->target) { if (!t->u.kernel.target->target) {
int v; int v;
v = ((struct ip6t_standard_target *)t)->verdict; v = ((struct ip6t_standard_target *)t)->verdict;
if (v < 0) { if (v < 0) {
/* Pop from stack? */ /* Pop from stack? */
if (v != IP6T_RETURN) { if (v != IP6T_RETURN) {
verdict = (unsigned)(-v) - 1; verdict = (unsigned)(-v) - 1;
break; break;
}
e = back;
back = get_entry(table_base,
back->comefrom);
continue;
}
if (table_base + v != (void *)e + e->next_offset
&& !(e->ipv6.flags & IP6T_F_GOTO)) {
/* Save old back ptr in next entry */
struct ip6t_entry *next
= (void *)e + e->next_offset;
next->comefrom
= (void *)back - table_base;
/* set back pointer to next entry */
back = next;
} }
e = back;
back = get_entry(table_base, back->comefrom);
continue;
}
if (table_base + v != ip6t_next_entry(e)
&& !(e->ipv6.flags & IP6T_F_GOTO)) {
/* Save old back ptr in next entry */
struct ip6t_entry *next = ip6t_next_entry(e);
next->comefrom = (void *)back - table_base;
/* set back pointer to next entry */
back = next;
}
e = get_entry(table_base, v); e = get_entry(table_base, v);
} else { continue;
/* Targets which reenter must return }
abs. verdicts */
tgpar.target = t->u.kernel.target;
tgpar.targinfo = t->data;
#ifdef CONFIG_NETFILTER_DEBUG /* Targets which reenter must return
((struct ip6t_entry *)table_base)->comefrom abs. verdicts */
= 0xeeeeeeec; tgpar.target = t->u.kernel.target;
#endif tgpar.targinfo = t->data;
verdict = t->u.kernel.target->target(skb,
&tgpar);
#ifdef CONFIG_NETFILTER_DEBUG #ifdef CONFIG_NETFILTER_DEBUG
if (((struct ip6t_entry *)table_base)->comefrom tb_comefrom = 0xeeeeeeec;
!= 0xeeeeeeec
&& verdict == IP6T_CONTINUE) {
printk("Target %s reentered!\n",
t->u.kernel.target->name);
verdict = NF_DROP;
}
((struct ip6t_entry *)table_base)->comefrom
= 0x57acc001;
#endif #endif
if (verdict == IP6T_CONTINUE) verdict = t->u.kernel.target->target(skb, &tgpar);
e = (void *)e + e->next_offset;
else
/* Verdict */
break;
}
} else {
no_match: #ifdef CONFIG_NETFILTER_DEBUG
e = (void *)e + e->next_offset; if (tb_comefrom != 0xeeeeeeec && verdict == IP6T_CONTINUE) {
printk("Target %s reentered!\n",
t->u.kernel.target->name);
verdict = NF_DROP;
} }
tb_comefrom = 0x57acc001;
#endif
if (verdict == IP6T_CONTINUE)
e = ip6t_next_entry(e);
else
/* Verdict */
break;
} while (!hotdrop); } while (!hotdrop);
#ifdef CONFIG_NETFILTER_DEBUG #ifdef CONFIG_NETFILTER_DEBUG
((struct ip6t_entry *)table_base)->comefrom = NETFILTER_LINK_POISON; tb_comefrom = NETFILTER_LINK_POISON;
#endif #endif
xt_info_rdunlock_bh(); xt_info_rdunlock_bh();
...@@ -475,6 +473,8 @@ ip6t_do_table(struct sk_buff *skb, ...@@ -475,6 +473,8 @@ ip6t_do_table(struct sk_buff *skb,
return NF_DROP; return NF_DROP;
else return verdict; else return verdict;
#endif #endif
#undef tb_comefrom
} }
/* Figures out from what hook each rule can be called: returns 0 if /* Figures out from what hook each rule can be called: returns 0 if
...@@ -2191,7 +2191,7 @@ static bool icmp6_checkentry(const struct xt_mtchk_param *par) ...@@ -2191,7 +2191,7 @@ static bool icmp6_checkentry(const struct xt_mtchk_param *par)
static struct xt_target ip6t_standard_target __read_mostly = { static struct xt_target ip6t_standard_target __read_mostly = {
.name = IP6T_STANDARD_TARGET, .name = IP6T_STANDARD_TARGET,
.targetsize = sizeof(int), .targetsize = sizeof(int),
.family = AF_INET6, .family = NFPROTO_IPV6,
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
.compatsize = sizeof(compat_int_t), .compatsize = sizeof(compat_int_t),
.compat_from_user = compat_standard_from_user, .compat_from_user = compat_standard_from_user,
...@@ -2203,7 +2203,7 @@ static struct xt_target ip6t_error_target __read_mostly = { ...@@ -2203,7 +2203,7 @@ static struct xt_target ip6t_error_target __read_mostly = {
.name = IP6T_ERROR_TARGET, .name = IP6T_ERROR_TARGET,
.target = ip6t_error, .target = ip6t_error,
.targetsize = IP6T_FUNCTION_MAXNAMELEN, .targetsize = IP6T_FUNCTION_MAXNAMELEN,
.family = AF_INET6, .family = NFPROTO_IPV6,
}; };
static struct nf_sockopt_ops ip6t_sockopts = { static struct nf_sockopt_ops ip6t_sockopts = {
...@@ -2229,17 +2229,17 @@ static struct xt_match icmp6_matchstruct __read_mostly = { ...@@ -2229,17 +2229,17 @@ static struct xt_match icmp6_matchstruct __read_mostly = {
.matchsize = sizeof(struct ip6t_icmp), .matchsize = sizeof(struct ip6t_icmp),
.checkentry = icmp6_checkentry, .checkentry = icmp6_checkentry,
.proto = IPPROTO_ICMPV6, .proto = IPPROTO_ICMPV6,
.family = AF_INET6, .family = NFPROTO_IPV6,
}; };
static int __net_init ip6_tables_net_init(struct net *net) static int __net_init ip6_tables_net_init(struct net *net)
{ {
return xt_proto_init(net, AF_INET6); return xt_proto_init(net, NFPROTO_IPV6);
} }
static void __net_exit ip6_tables_net_exit(struct net *net) static void __net_exit ip6_tables_net_exit(struct net *net)
{ {
xt_proto_fini(net, AF_INET6); xt_proto_fini(net, NFPROTO_IPV6);
} }
static struct pernet_operations ip6_tables_net_ops = { static struct pernet_operations ip6_tables_net_ops = {
......
...@@ -204,10 +204,10 @@ int nf_queue(struct sk_buff *skb, ...@@ -204,10 +204,10 @@ int nf_queue(struct sk_buff *skb,
queuenum); queuenum);
switch (pf) { switch (pf) {
case AF_INET: case NFPROTO_IPV4:
skb->protocol = htons(ETH_P_IP); skb->protocol = htons(ETH_P_IP);
break; break;
case AF_INET6: case NFPROTO_IPV6:
skb->protocol = htons(ETH_P_IPV6); skb->protocol = htons(ETH_P_IPV6);
break; break;
} }
......
...@@ -329,6 +329,32 @@ int xt_find_revision(u8 af, const char *name, u8 revision, int target, ...@@ -329,6 +329,32 @@ int xt_find_revision(u8 af, const char *name, u8 revision, int target,
} }
EXPORT_SYMBOL_GPL(xt_find_revision); EXPORT_SYMBOL_GPL(xt_find_revision);
static char *textify_hooks(char *buf, size_t size, unsigned int mask)
{
static const char *const names[] = {
"PREROUTING", "INPUT", "FORWARD",
"OUTPUT", "POSTROUTING", "BROUTING",
};
unsigned int i;
char *p = buf;
bool np = false;
int res;
*p = '\0';
for (i = 0; i < ARRAY_SIZE(names); ++i) {
if (!(mask & (1 << i)))
continue;
res = snprintf(p, size, "%s%s", np ? "/" : "", names[i]);
if (res > 0) {
size -= res;
p += res;
}
np = true;
}
return buf;
}
int xt_check_match(struct xt_mtchk_param *par, int xt_check_match(struct xt_mtchk_param *par,
unsigned int size, u_int8_t proto, bool inv_proto) unsigned int size, u_int8_t proto, bool inv_proto)
{ {
...@@ -351,9 +377,13 @@ int xt_check_match(struct xt_mtchk_param *par, ...@@ -351,9 +377,13 @@ int xt_check_match(struct xt_mtchk_param *par,
return -EINVAL; return -EINVAL;
} }
if (par->match->hooks && (par->hook_mask & ~par->match->hooks) != 0) { if (par->match->hooks && (par->hook_mask & ~par->match->hooks) != 0) {
printk("%s_tables: %s match: bad hook_mask %#x/%#x\n", char used[64], allow[64];
printk("%s_tables: %s match: used from hooks %s, but only "
"valid from %s\n",
xt_prefix[par->family], par->match->name, xt_prefix[par->family], par->match->name,
par->hook_mask, par->match->hooks); textify_hooks(used, sizeof(used), par->hook_mask),
textify_hooks(allow, sizeof(allow), par->match->hooks));
return -EINVAL; return -EINVAL;
} }
if (par->match->proto && (par->match->proto != proto || inv_proto)) { if (par->match->proto && (par->match->proto != proto || inv_proto)) {
...@@ -497,9 +527,13 @@ int xt_check_target(struct xt_tgchk_param *par, ...@@ -497,9 +527,13 @@ int xt_check_target(struct xt_tgchk_param *par,
return -EINVAL; return -EINVAL;
} }
if (par->target->hooks && (par->hook_mask & ~par->target->hooks) != 0) { if (par->target->hooks && (par->hook_mask & ~par->target->hooks) != 0) {
printk("%s_tables: %s target: bad hook_mask %#x/%#x\n", char used[64], allow[64];
printk("%s_tables: %s target: used from hooks %s, but only "
"usable from %s\n",
xt_prefix[par->family], par->target->name, xt_prefix[par->family], par->target->name,
par->hook_mask, par->target->hooks); textify_hooks(used, sizeof(used), par->hook_mask),
textify_hooks(allow, sizeof(allow), par->target->hooks));
return -EINVAL; return -EINVAL;
} }
if (par->target->proto && (par->target->proto != proto || inv_proto)) { if (par->target->proto && (par->target->proto != proto || inv_proto)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment