diff options
| author | Arturo Borrero <arturo.borrero.glez@gmail.com> | 2014-10-03 08:13:36 -0400 |
|---|---|---|
| committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2014-10-03 08:24:35 -0400 |
| commit | 8da4cc1b10c1aeba090d1d862b17174e4dbd50a4 (patch) | |
| tree | 6c5c1a76fd427ae17e4fe9578765ff95b67d7e8e | |
| parent | 07dcc686fa8f6667dec4696804cdb43a90267b9a (diff) | |
netfilter: nft_masq: register/unregister notifiers on module init/exit
We have to register the notifiers in the masquerade expression from
the the module _init and _exit path.
This fixes crashes when removing the masquerade rule with no
ipt_MASQUERADE support in place (which was masking the problem).
Fixes: 9ba1f72 ("netfilter: nf_tables: add new nft_masq expression")
Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
| -rw-r--r-- | net/ipv4/netfilter/nft_masq_ipv4.c | 34 | ||||
| -rw-r--r-- | net/ipv6/netfilter/nft_masq_ipv6.c | 34 |
2 files changed, 22 insertions, 46 deletions
diff --git a/net/ipv4/netfilter/nft_masq_ipv4.c b/net/ipv4/netfilter/nft_masq_ipv4.c index 6ea1d207b6a5..1c636d6b5b50 100644 --- a/net/ipv4/netfilter/nft_masq_ipv4.c +++ b/net/ipv4/netfilter/nft_masq_ipv4.c | |||
| @@ -32,33 +32,12 @@ static void nft_masq_ipv4_eval(const struct nft_expr *expr, | |||
| 32 | data[NFT_REG_VERDICT].verdict = verdict; | 32 | data[NFT_REG_VERDICT].verdict = verdict; |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | static int nft_masq_ipv4_init(const struct nft_ctx *ctx, | ||
| 36 | const struct nft_expr *expr, | ||
| 37 | const struct nlattr * const tb[]) | ||
| 38 | { | ||
| 39 | int err; | ||
| 40 | |||
| 41 | err = nft_masq_init(ctx, expr, tb); | ||
| 42 | if (err < 0) | ||
| 43 | return err; | ||
| 44 | |||
| 45 | nf_nat_masquerade_ipv4_register_notifier(); | ||
| 46 | return 0; | ||
| 47 | } | ||
| 48 | |||
| 49 | static void nft_masq_ipv4_destroy(const struct nft_ctx *ctx, | ||
| 50 | const struct nft_expr *expr) | ||
| 51 | { | ||
| 52 | nf_nat_masquerade_ipv4_unregister_notifier(); | ||
| 53 | } | ||
| 54 | |||
| 55 | static struct nft_expr_type nft_masq_ipv4_type; | 35 | static struct nft_expr_type nft_masq_ipv4_type; |
| 56 | static const struct nft_expr_ops nft_masq_ipv4_ops = { | 36 | static const struct nft_expr_ops nft_masq_ipv4_ops = { |
| 57 | .type = &nft_masq_ipv4_type, | 37 | .type = &nft_masq_ipv4_type, |
| 58 | .size = NFT_EXPR_SIZE(sizeof(struct nft_masq)), | 38 | .size = NFT_EXPR_SIZE(sizeof(struct nft_masq)), |
| 59 | .eval = nft_masq_ipv4_eval, | 39 | .eval = nft_masq_ipv4_eval, |
| 60 | .init = nft_masq_ipv4_init, | 40 | .init = nft_masq_init, |
| 61 | .destroy = nft_masq_ipv4_destroy, | ||
| 62 | .dump = nft_masq_dump, | 41 | .dump = nft_masq_dump, |
| 63 | }; | 42 | }; |
| 64 | 43 | ||
| @@ -73,12 +52,21 @@ static struct nft_expr_type nft_masq_ipv4_type __read_mostly = { | |||
| 73 | 52 | ||
| 74 | static int __init nft_masq_ipv4_module_init(void) | 53 | static int __init nft_masq_ipv4_module_init(void) |
| 75 | { | 54 | { |
| 76 | return nft_register_expr(&nft_masq_ipv4_type); | 55 | int ret; |
| 56 | |||
| 57 | ret = nft_register_expr(&nft_masq_ipv4_type); | ||
| 58 | if (ret < 0) | ||
| 59 | return ret; | ||
| 60 | |||
| 61 | nf_nat_masquerade_ipv4_register_notifier(); | ||
| 62 | |||
| 63 | return ret; | ||
| 77 | } | 64 | } |
| 78 | 65 | ||
| 79 | static void __exit nft_masq_ipv4_module_exit(void) | 66 | static void __exit nft_masq_ipv4_module_exit(void) |
| 80 | { | 67 | { |
| 81 | nft_unregister_expr(&nft_masq_ipv4_type); | 68 | nft_unregister_expr(&nft_masq_ipv4_type); |
| 69 | nf_nat_masquerade_ipv4_unregister_notifier(); | ||
| 82 | } | 70 | } |
| 83 | 71 | ||
| 84 | module_init(nft_masq_ipv4_module_init); | 72 | module_init(nft_masq_ipv4_module_init); |
diff --git a/net/ipv6/netfilter/nft_masq_ipv6.c b/net/ipv6/netfilter/nft_masq_ipv6.c index 4e51334ef6b7..556262f40761 100644 --- a/net/ipv6/netfilter/nft_masq_ipv6.c +++ b/net/ipv6/netfilter/nft_masq_ipv6.c | |||
| @@ -32,33 +32,12 @@ static void nft_masq_ipv6_eval(const struct nft_expr *expr, | |||
| 32 | data[NFT_REG_VERDICT].verdict = verdict; | 32 | data[NFT_REG_VERDICT].verdict = verdict; |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | static int nft_masq_ipv6_init(const struct nft_ctx *ctx, | ||
| 36 | const struct nft_expr *expr, | ||
| 37 | const struct nlattr * const tb[]) | ||
| 38 | { | ||
| 39 | int err; | ||
| 40 | |||
| 41 | err = nft_masq_init(ctx, expr, tb); | ||
| 42 | if (err < 0) | ||
| 43 | return err; | ||
| 44 | |||
| 45 | nf_nat_masquerade_ipv6_register_notifier(); | ||
| 46 | return 0; | ||
| 47 | } | ||
| 48 | |||
| 49 | static void nft_masq_ipv6_destroy(const struct nft_ctx *ctx, | ||
| 50 | const struct nft_expr *expr) | ||
| 51 | { | ||
| 52 | nf_nat_masquerade_ipv6_unregister_notifier(); | ||
| 53 | } | ||
| 54 | |||
| 55 | static struct nft_expr_type nft_masq_ipv6_type; | 35 | static struct nft_expr_type nft_masq_ipv6_type; |
| 56 | static const struct nft_expr_ops nft_masq_ipv6_ops = { | 36 | static const struct nft_expr_ops nft_masq_ipv6_ops = { |
| 57 | .type = &nft_masq_ipv6_type, | 37 | .type = &nft_masq_ipv6_type, |
| 58 | .size = NFT_EXPR_SIZE(sizeof(struct nft_masq)), | 38 | .size = NFT_EXPR_SIZE(sizeof(struct nft_masq)), |
| 59 | .eval = nft_masq_ipv6_eval, | 39 | .eval = nft_masq_ipv6_eval, |
| 60 | .init = nft_masq_ipv6_init, | 40 | .init = nft_masq_init, |
| 61 | .destroy = nft_masq_ipv6_destroy, | ||
| 62 | .dump = nft_masq_dump, | 41 | .dump = nft_masq_dump, |
| 63 | }; | 42 | }; |
| 64 | 43 | ||
| @@ -73,12 +52,21 @@ static struct nft_expr_type nft_masq_ipv6_type __read_mostly = { | |||
| 73 | 52 | ||
| 74 | static int __init nft_masq_ipv6_module_init(void) | 53 | static int __init nft_masq_ipv6_module_init(void) |
| 75 | { | 54 | { |
| 76 | return nft_register_expr(&nft_masq_ipv6_type); | 55 | int ret; |
| 56 | |||
| 57 | ret = nft_register_expr(&nft_masq_ipv6_type); | ||
| 58 | if (ret < 0) | ||
| 59 | return ret; | ||
| 60 | |||
| 61 | nf_nat_masquerade_ipv6_register_notifier(); | ||
| 62 | |||
| 63 | return ret; | ||
| 77 | } | 64 | } |
| 78 | 65 | ||
| 79 | static void __exit nft_masq_ipv6_module_exit(void) | 66 | static void __exit nft_masq_ipv6_module_exit(void) |
| 80 | { | 67 | { |
| 81 | nft_unregister_expr(&nft_masq_ipv6_type); | 68 | nft_unregister_expr(&nft_masq_ipv6_type); |
| 69 | nf_nat_masquerade_ipv6_unregister_notifier(); | ||
| 82 | } | 70 | } |
| 83 | 71 | ||
| 84 | module_init(nft_masq_ipv6_module_init); | 72 | module_init(nft_masq_ipv6_module_init); |
