diff options
| author | Alexey Dobriyan <adobriyan@gmail.com> | 2008-11-04 08:27:15 -0500 |
|---|---|---|
| committer | Patrick McHardy <kaber@trash.net> | 2008-11-04 08:27:15 -0500 |
| commit | 6beceee5aa2cb94c4ae9f0784c7d3135d343f5b5 (patch) | |
| tree | 9f6bd8ee8c966a2ad5eab64a2472c395ef29e2f4 | |
| parent | 511061e2dd1b84bb21bb97c9216a19606c29ac02 (diff) | |
netfilter: netns ebtables: part 2
* return ebt_table from ebt_register_table(), module code will save it into
per-netns data for unregistration
* duplicate ebt_table at the very beginning of registration -- it's added into
list, so one ebt_table wouldn't end up in many lists (and each netns has
different one)
* introduce underscored tables in individial modules, this is temporary to not
break bisection.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Patrick McHardy <kaber@trash.net>
| -rw-r--r-- | include/linux/netfilter_bridge/ebtables.h | 3 | ||||
| -rw-r--r-- | net/bridge/netfilter/ebtable_broute.c | 19 | ||||
| -rw-r--r-- | net/bridge/netfilter/ebtable_filter.c | 17 | ||||
| -rw-r--r-- | net/bridge/netfilter/ebtable_nat.c | 19 | ||||
| -rw-r--r-- | net/bridge/netfilter/ebtables.c | 23 |
5 files changed, 47 insertions, 34 deletions
diff --git a/include/linux/netfilter_bridge/ebtables.h b/include/linux/netfilter_bridge/ebtables.h index 624e7883068c..e40ddb94b1af 100644 --- a/include/linux/netfilter_bridge/ebtables.h +++ b/include/linux/netfilter_bridge/ebtables.h | |||
| @@ -300,7 +300,8 @@ struct ebt_table | |||
| 300 | 300 | ||
| 301 | #define EBT_ALIGN(s) (((s) + (__alignof__(struct ebt_replace)-1)) & \ | 301 | #define EBT_ALIGN(s) (((s) + (__alignof__(struct ebt_replace)-1)) & \ |
| 302 | ~(__alignof__(struct ebt_replace)-1)) | 302 | ~(__alignof__(struct ebt_replace)-1)) |
| 303 | extern int ebt_register_table(struct net *net, struct ebt_table *table); | 303 | extern struct ebt_table *ebt_register_table(struct net *net, |
| 304 | struct ebt_table *table); | ||
| 304 | extern void ebt_unregister_table(struct ebt_table *table); | 305 | extern void ebt_unregister_table(struct ebt_table *table); |
| 305 | extern unsigned int ebt_do_table(unsigned int hook, struct sk_buff *skb, | 306 | extern unsigned int ebt_do_table(unsigned int hook, struct sk_buff *skb, |
| 306 | const struct net_device *in, const struct net_device *out, | 307 | const struct net_device *in, const struct net_device *out, |
diff --git a/net/bridge/netfilter/ebtable_broute.c b/net/bridge/netfilter/ebtable_broute.c index 1731ce8f7479..3277d682dfcf 100644 --- a/net/bridge/netfilter/ebtable_broute.c +++ b/net/bridge/netfilter/ebtable_broute.c | |||
| @@ -41,22 +41,23 @@ static int check(const struct ebt_table_info *info, unsigned int valid_hooks) | |||
| 41 | return 0; | 41 | return 0; |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | static struct ebt_table broute_table = | 44 | static struct ebt_table __broute_table = |
| 45 | { | 45 | { |
| 46 | .name = "broute", | 46 | .name = "broute", |
| 47 | .table = &initial_table, | 47 | .table = &initial_table, |
| 48 | .valid_hooks = 1 << NF_BR_BROUTING, | 48 | .valid_hooks = 1 << NF_BR_BROUTING, |
| 49 | .lock = __RW_LOCK_UNLOCKED(broute_table.lock), | 49 | .lock = __RW_LOCK_UNLOCKED(__broute_table.lock), |
| 50 | .check = check, | 50 | .check = check, |
| 51 | .me = THIS_MODULE, | 51 | .me = THIS_MODULE, |
| 52 | }; | 52 | }; |
| 53 | static struct ebt_table *broute_table; | ||
| 53 | 54 | ||
| 54 | static int ebt_broute(struct sk_buff *skb) | 55 | static int ebt_broute(struct sk_buff *skb) |
| 55 | { | 56 | { |
| 56 | int ret; | 57 | int ret; |
| 57 | 58 | ||
| 58 | ret = ebt_do_table(NF_BR_BROUTING, skb, skb->dev, NULL, | 59 | ret = ebt_do_table(NF_BR_BROUTING, skb, skb->dev, NULL, |
| 59 | &broute_table); | 60 | broute_table); |
| 60 | if (ret == NF_DROP) | 61 | if (ret == NF_DROP) |
| 61 | return 1; /* route it */ | 62 | return 1; /* route it */ |
| 62 | return 0; /* bridge it */ | 63 | return 0; /* bridge it */ |
| @@ -64,21 +65,19 @@ static int ebt_broute(struct sk_buff *skb) | |||
| 64 | 65 | ||
| 65 | static int __init ebtable_broute_init(void) | 66 | static int __init ebtable_broute_init(void) |
| 66 | { | 67 | { |
| 67 | int ret; | 68 | broute_table = ebt_register_table(&init_net, &__broute_table); |
| 68 | 69 | if (IS_ERR(broute_table)) | |
| 69 | ret = ebt_register_table(&init_net, &broute_table); | 70 | return PTR_ERR(broute_table); |
| 70 | if (ret < 0) | ||
| 71 | return ret; | ||
| 72 | /* see br_input.c */ | 71 | /* see br_input.c */ |
| 73 | rcu_assign_pointer(br_should_route_hook, ebt_broute); | 72 | rcu_assign_pointer(br_should_route_hook, ebt_broute); |
| 74 | return ret; | 73 | return 0; |
| 75 | } | 74 | } |
| 76 | 75 | ||
| 77 | static void __exit ebtable_broute_fini(void) | 76 | static void __exit ebtable_broute_fini(void) |
| 78 | { | 77 | { |
| 79 | rcu_assign_pointer(br_should_route_hook, NULL); | 78 | rcu_assign_pointer(br_should_route_hook, NULL); |
| 80 | synchronize_net(); | 79 | synchronize_net(); |
| 81 | ebt_unregister_table(&broute_table); | 80 | ebt_unregister_table(broute_table); |
| 82 | } | 81 | } |
| 83 | 82 | ||
| 84 | module_init(ebtable_broute_init); | 83 | module_init(ebtable_broute_init); |
diff --git a/net/bridge/netfilter/ebtable_filter.c b/net/bridge/netfilter/ebtable_filter.c index af8953c9a57c..596564c7aa58 100644 --- a/net/bridge/netfilter/ebtable_filter.c +++ b/net/bridge/netfilter/ebtable_filter.c | |||
| @@ -50,21 +50,22 @@ static int check(const struct ebt_table_info *info, unsigned int valid_hooks) | |||
| 50 | return 0; | 50 | return 0; |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | static struct ebt_table frame_filter = | 53 | static struct ebt_table __frame_filter = |
| 54 | { | 54 | { |
| 55 | .name = "filter", | 55 | .name = "filter", |
| 56 | .table = &initial_table, | 56 | .table = &initial_table, |
| 57 | .valid_hooks = FILTER_VALID_HOOKS, | 57 | .valid_hooks = FILTER_VALID_HOOKS, |
| 58 | .lock = __RW_LOCK_UNLOCKED(frame_filter.lock), | 58 | .lock = __RW_LOCK_UNLOCKED(__frame_filter.lock), |
| 59 | .check = check, | 59 | .check = check, |
| 60 | .me = THIS_MODULE, | 60 | .me = THIS_MODULE, |
| 61 | }; | 61 | }; |
| 62 | static struct ebt_table *frame_filter; | ||
| 62 | 63 | ||
| 63 | static unsigned int | 64 | static unsigned int |
| 64 | ebt_hook(unsigned int hook, struct sk_buff *skb, const struct net_device *in, | 65 | ebt_hook(unsigned int hook, struct sk_buff *skb, const struct net_device *in, |
| 65 | const struct net_device *out, int (*okfn)(struct sk_buff *)) | 66 | const struct net_device *out, int (*okfn)(struct sk_buff *)) |
| 66 | { | 67 | { |
| 67 | return ebt_do_table(hook, skb, in, out, &frame_filter); | 68 | return ebt_do_table(hook, skb, in, out, frame_filter); |
| 68 | } | 69 | } |
| 69 | 70 | ||
| 70 | static struct nf_hook_ops ebt_ops_filter[] __read_mostly = { | 71 | static struct nf_hook_ops ebt_ops_filter[] __read_mostly = { |
| @@ -95,19 +96,19 @@ static int __init ebtable_filter_init(void) | |||
| 95 | { | 96 | { |
| 96 | int ret; | 97 | int ret; |
| 97 | 98 | ||
| 98 | ret = ebt_register_table(&init_net, &frame_filter); | 99 | frame_filter = ebt_register_table(&init_net, &__frame_filter); |
| 99 | if (ret < 0) | 100 | if (IS_ERR(frame_filter)) |
| 100 | return ret; | 101 | return PTR_ERR(frame_filter); |
| 101 | ret = nf_register_hooks(ebt_ops_filter, ARRAY_SIZE(ebt_ops_filter)); | 102 | ret = nf_register_hooks(ebt_ops_filter, ARRAY_SIZE(ebt_ops_filter)); |
| 102 | if (ret < 0) | 103 | if (ret < 0) |
| 103 | ebt_unregister_table(&frame_filter); | 104 | ebt_unregister_table(frame_filter); |
| 104 | return ret; | 105 | return ret; |
| 105 | } | 106 | } |
| 106 | 107 | ||
| 107 | static void __exit ebtable_filter_fini(void) | 108 | static void __exit ebtable_filter_fini(void) |
| 108 | { | 109 | { |
| 109 | nf_unregister_hooks(ebt_ops_filter, ARRAY_SIZE(ebt_ops_filter)); | 110 | nf_unregister_hooks(ebt_ops_filter, ARRAY_SIZE(ebt_ops_filter)); |
| 110 | ebt_unregister_table(&frame_filter); | 111 | ebt_unregister_table(frame_filter); |
| 111 | } | 112 | } |
| 112 | 113 | ||
| 113 | module_init(ebtable_filter_init); | 114 | module_init(ebtable_filter_init); |
diff --git a/net/bridge/netfilter/ebtable_nat.c b/net/bridge/netfilter/ebtable_nat.c index bafe16029bd7..0d8fc5bcddd1 100644 --- a/net/bridge/netfilter/ebtable_nat.c +++ b/net/bridge/netfilter/ebtable_nat.c | |||
| @@ -50,28 +50,29 @@ static int check(const struct ebt_table_info *info, unsigned int valid_hooks) | |||
| 50 | return 0; | 50 | return 0; |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | static struct ebt_table frame_nat = | 53 | static struct ebt_table __frame_nat = |
| 54 | { | 54 | { |
| 55 | .name = "nat", | 55 | .name = "nat", |
| 56 | .table = &initial_table, | 56 | .table = &initial_table, |
| 57 | .valid_hooks = NAT_VALID_HOOKS, | 57 | .valid_hooks = NAT_VALID_HOOKS, |
| 58 | .lock = __RW_LOCK_UNLOCKED(frame_nat.lock), | 58 | .lock = __RW_LOCK_UNLOCKED(__frame_nat.lock), |
| 59 | .check = check, | 59 | .check = check, |
| 60 | .me = THIS_MODULE, | 60 | .me = THIS_MODULE, |
| 61 | }; | 61 | }; |
| 62 | static struct ebt_table *frame_nat; | ||
| 62 | 63 | ||
| 63 | static unsigned int | 64 | static unsigned int |
| 64 | ebt_nat_dst(unsigned int hook, struct sk_buff *skb, const struct net_device *in | 65 | ebt_nat_dst(unsigned int hook, struct sk_buff *skb, const struct net_device *in |
| 65 | , const struct net_device *out, int (*okfn)(struct sk_buff *)) | 66 | , const struct net_device *out, int (*okfn)(struct sk_buff *)) |
| 66 | { | ||
