Commit a1d768f1 authored by Taehee Yoo's avatar Taehee Yoo Committed by Pablo Neira Ayuso

netfilter: ebtables: add ebt_get_target and ebt_get_target_c

ebt_get_target similar to {ip/ip6/arp}t_get_target.
and ebt_get_target_c similar to {ip/ip6/arp}t_get_target_c.
Signed-off-by: default avatarTaehee Yoo <ap420073@gmail.com>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 4351bef0
...@@ -191,6 +191,12 @@ struct ebt_entry { ...@@ -191,6 +191,12 @@ struct ebt_entry {
unsigned char elems[0] __attribute__ ((aligned (__alignof__(struct ebt_replace)))); unsigned char elems[0] __attribute__ ((aligned (__alignof__(struct ebt_replace))));
}; };
static __inline__ struct ebt_entry_target *
ebt_get_target(struct ebt_entry *e)
{
return (void *)e + e->target_offset;
}
/* {g,s}etsockopt numbers */ /* {g,s}etsockopt numbers */
#define EBT_BASE_CTL 128 #define EBT_BASE_CTL 128
......
...@@ -177,6 +177,12 @@ struct ebt_entry *ebt_next_entry(const struct ebt_entry *entry) ...@@ -177,6 +177,12 @@ struct ebt_entry *ebt_next_entry(const struct ebt_entry *entry)
return (void *)entry + entry->next_offset; return (void *)entry + entry->next_offset;
} }
static inline const struct ebt_entry_target *
ebt_get_target_c(const struct ebt_entry *e)
{
return ebt_get_target((struct ebt_entry *)e);
}
/* Do some firewalling */ /* Do some firewalling */
unsigned int ebt_do_table(struct sk_buff *skb, unsigned int ebt_do_table(struct sk_buff *skb,
const struct nf_hook_state *state, const struct nf_hook_state *state,
...@@ -230,8 +236,7 @@ unsigned int ebt_do_table(struct sk_buff *skb, ...@@ -230,8 +236,7 @@ unsigned int ebt_do_table(struct sk_buff *skb,
*/ */
EBT_WATCHER_ITERATE(point, ebt_do_watcher, skb, &acpar); EBT_WATCHER_ITERATE(point, ebt_do_watcher, skb, &acpar);
t = (struct ebt_entry_target *) t = ebt_get_target_c(point);
(((char *)point) + point->target_offset);
/* standard target */ /* standard target */
if (!t->u.target->target) if (!t->u.target->target)
verdict = ((struct ebt_standard_target *)t)->verdict; verdict = ((struct ebt_standard_target *)t)->verdict;
...@@ -637,7 +642,7 @@ ebt_cleanup_entry(struct ebt_entry *e, struct net *net, unsigned int *cnt) ...@@ -637,7 +642,7 @@ ebt_cleanup_entry(struct ebt_entry *e, struct net *net, unsigned int *cnt)
return 1; return 1;
EBT_WATCHER_ITERATE(e, ebt_cleanup_watcher, net, NULL); EBT_WATCHER_ITERATE(e, ebt_cleanup_watcher, net, NULL);
EBT_MATCH_ITERATE(e, ebt_cleanup_match, net, NULL); EBT_MATCH_ITERATE(e, ebt_cleanup_match, net, NULL);
t = (struct ebt_entry_target *)(((char *)e) + e->target_offset); t = ebt_get_target(e);
par.net = net; par.net = net;
par.target = t->u.target; par.target = t->u.target;
...@@ -716,7 +721,7 @@ ebt_check_entry(struct ebt_entry *e, struct net *net, ...@@ -716,7 +721,7 @@ ebt_check_entry(struct ebt_entry *e, struct net *net,
ret = EBT_WATCHER_ITERATE(e, ebt_check_watcher, &tgpar, &j); ret = EBT_WATCHER_ITERATE(e, ebt_check_watcher, &tgpar, &j);
if (ret != 0) if (ret != 0)
goto cleanup_watchers; goto cleanup_watchers;
t = (struct ebt_entry_target *)(((char *)e) + e->target_offset); t = ebt_get_target(e);
gap = e->next_offset - e->target_offset; gap = e->next_offset - e->target_offset;
target = xt_request_find_target(NFPROTO_BRIDGE, t->u.name, 0); target = xt_request_find_target(NFPROTO_BRIDGE, t->u.name, 0);
...@@ -789,8 +794,7 @@ static int check_chainloops(const struct ebt_entries *chain, struct ebt_cl_stack ...@@ -789,8 +794,7 @@ static int check_chainloops(const struct ebt_entries *chain, struct ebt_cl_stack
if (pos == nentries) if (pos == nentries)
continue; continue;
} }
t = (struct ebt_entry_target *) t = ebt_get_target_c(e);
(((char *)e) + e->target_offset);
if (strcmp(t->u.name, EBT_STANDARD_TARGET)) if (strcmp(t->u.name, EBT_STANDARD_TARGET))
goto letscontinue; goto letscontinue;
if (e->target_offset + sizeof(struct ebt_standard_target) > if (e->target_offset + sizeof(struct ebt_standard_target) >
...@@ -1396,7 +1400,7 @@ static inline int ebt_entry_to_user(struct ebt_entry *e, const char *base, ...@@ -1396,7 +1400,7 @@ static inline int ebt_entry_to_user(struct ebt_entry *e, const char *base,
return -EFAULT; return -EFAULT;
hlp = ubase + (((char *)e + e->target_offset) - base); hlp = ubase + (((char *)e + e->target_offset) - base);
t = (struct ebt_entry_target *)(((char *)e) + e->target_offset); t = ebt_get_target_c(e);
ret = EBT_MATCH_ITERATE(e, ebt_match_to_user, base, ubase); ret = EBT_MATCH_ITERATE(e, ebt_match_to_user, base, ubase);
if (ret != 0) if (ret != 0)
...@@ -1737,7 +1741,7 @@ static int compat_copy_entry_to_user(struct ebt_entry *e, void __user **dstptr, ...@@ -1737,7 +1741,7 @@ static int compat_copy_entry_to_user(struct ebt_entry *e, void __user **dstptr,
return ret; return ret;
target_offset = e->target_offset - (origsize - *size); target_offset = e->target_offset - (origsize - *size);
t = (struct ebt_entry_target *) ((char *) e + e->target_offset); t = ebt_get_target(e);
ret = compat_target_to_user(t, dstptr, size); ret = compat_target_to_user(t, dstptr, size);
if (ret) if (ret)
...@@ -1785,7 +1789,7 @@ static int compat_calc_entry(const struct ebt_entry *e, ...@@ -1785,7 +1789,7 @@ static int compat_calc_entry(const struct ebt_entry *e,
EBT_MATCH_ITERATE(e, compat_calc_match, &off); EBT_MATCH_ITERATE(e, compat_calc_match, &off);
EBT_WATCHER_ITERATE(e, compat_calc_watcher, &off); EBT_WATCHER_ITERATE(e, compat_calc_watcher, &off);
t = (const struct ebt_entry_target *) ((char *) e + e->target_offset); t = ebt_get_target_c(e);
off += xt_compat_target_offset(t->u.target); off += xt_compat_target_offset(t->u.target);
off += ebt_compat_entry_padsize(); off += ebt_compat_entry_padsize();
......
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