Patrick McHardy | 9651851 | 2013-10-14 11:00:02 +0200 | [diff] [blame] | 1 | /* |
Patrick McHardy | ef1f7df | 2013-10-10 11:41:20 +0200 | [diff] [blame] | 2 | * Copyright (c) 2008-2009 Patrick McHardy <kaber@trash.net> |
Eric Leblond | bee11dc | 2013-12-29 12:28:14 +0100 | [diff] [blame] | 3 | * Copyright (c) 2013 Eric Leblond <eric@regit.org> |
Patrick McHardy | 9651851 | 2013-10-14 11:00:02 +0200 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * Development of this code funded by Astaro AG (http://www.astaro.com/) |
| 10 | */ |
| 11 | |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/netlink.h> |
| 16 | #include <linux/netfilter.h> |
| 17 | #include <linux/netfilter/nf_tables.h> |
| 18 | #include <net/netfilter/nf_tables.h> |
Patrick McHardy | cc4723c | 2014-02-05 15:03:38 +0000 | [diff] [blame] | 19 | #include <net/netfilter/nft_reject.h> |
Eric Leblond | bee11dc | 2013-12-29 12:28:14 +0100 | [diff] [blame] | 20 | |
Patrick McHardy | cc4723c | 2014-02-05 15:03:38 +0000 | [diff] [blame] | 21 | const struct nla_policy nft_reject_policy[NFTA_REJECT_MAX + 1] = { |
Patrick McHardy | 9651851 | 2013-10-14 11:00:02 +0200 | [diff] [blame] | 22 | [NFTA_REJECT_TYPE] = { .type = NLA_U32 }, |
| 23 | [NFTA_REJECT_ICMP_CODE] = { .type = NLA_U8 }, |
| 24 | }; |
Patrick McHardy | cc4723c | 2014-02-05 15:03:38 +0000 | [diff] [blame] | 25 | EXPORT_SYMBOL_GPL(nft_reject_policy); |
Patrick McHardy | 9651851 | 2013-10-14 11:00:02 +0200 | [diff] [blame] | 26 | |
Patrick McHardy | cc4723c | 2014-02-05 15:03:38 +0000 | [diff] [blame] | 27 | int nft_reject_init(const struct nft_ctx *ctx, |
| 28 | const struct nft_expr *expr, |
| 29 | const struct nlattr * const tb[]) |
Patrick McHardy | 9651851 | 2013-10-14 11:00:02 +0200 | [diff] [blame] | 30 | { |
| 31 | struct nft_reject *priv = nft_expr_priv(expr); |
| 32 | |
| 33 | if (tb[NFTA_REJECT_TYPE] == NULL) |
| 34 | return -EINVAL; |
| 35 | |
| 36 | priv->type = ntohl(nla_get_be32(tb[NFTA_REJECT_TYPE])); |
| 37 | switch (priv->type) { |
| 38 | case NFT_REJECT_ICMP_UNREACH: |
| 39 | if (tb[NFTA_REJECT_ICMP_CODE] == NULL) |
| 40 | return -EINVAL; |
| 41 | priv->icmp_code = nla_get_u8(tb[NFTA_REJECT_ICMP_CODE]); |
| 42 | case NFT_REJECT_TCP_RST: |
| 43 | break; |
| 44 | default: |
| 45 | return -EINVAL; |
| 46 | } |
| 47 | |
| 48 | return 0; |
| 49 | } |
Patrick McHardy | cc4723c | 2014-02-05 15:03:38 +0000 | [diff] [blame] | 50 | EXPORT_SYMBOL_GPL(nft_reject_init); |
Patrick McHardy | 9651851 | 2013-10-14 11:00:02 +0200 | [diff] [blame] | 51 | |
Patrick McHardy | cc4723c | 2014-02-05 15:03:38 +0000 | [diff] [blame] | 52 | int nft_reject_dump(struct sk_buff *skb, const struct nft_expr *expr) |
Patrick McHardy | 9651851 | 2013-10-14 11:00:02 +0200 | [diff] [blame] | 53 | { |
| 54 | const struct nft_reject *priv = nft_expr_priv(expr); |
| 55 | |
Eric Leblond | bee11dc | 2013-12-29 12:28:14 +0100 | [diff] [blame] | 56 | if (nla_put_be32(skb, NFTA_REJECT_TYPE, htonl(priv->type))) |
Patrick McHardy | 9651851 | 2013-10-14 11:00:02 +0200 | [diff] [blame] | 57 | goto nla_put_failure; |
| 58 | |
| 59 | switch (priv->type) { |
| 60 | case NFT_REJECT_ICMP_UNREACH: |
| 61 | if (nla_put_u8(skb, NFTA_REJECT_ICMP_CODE, priv->icmp_code)) |
| 62 | goto nla_put_failure; |
| 63 | break; |
| 64 | } |
| 65 | |
| 66 | return 0; |
| 67 | |
| 68 | nla_put_failure: |
| 69 | return -1; |
| 70 | } |
Patrick McHardy | cc4723c | 2014-02-05 15:03:38 +0000 | [diff] [blame] | 71 | EXPORT_SYMBOL_GPL(nft_reject_dump); |
Patrick McHardy | 9651851 | 2013-10-14 11:00:02 +0200 | [diff] [blame] | 72 | |
| 73 | MODULE_LICENSE("GPL"); |
| 74 | MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>"); |