2 * Copyright (c) 2008-2009 Patrick McHardy <kaber@trash.net>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * Development of this code funded by Astaro AG (http://www.astaro.com/)
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/module.h>
14 #include <linux/netlink.h>
15 #include <linux/netfilter.h>
16 #include <linux/netfilter/nf_tables.h>
17 #include <net/netfilter/nf_tables.h>
21 enum nft_reject_types type:8;
25 static void nft_reject_eval(const struct nft_expr *expr,
26 struct nft_data data[NFT_REG_MAX + 1],
27 const struct nft_pktinfo *pkt)
29 struct nft_reject *priv = nft_expr_priv(expr);
32 case NFT_REJECT_ICMP_UNREACH:
33 icmp_send(pkt->skb, ICMP_DEST_UNREACH, priv->icmp_code, 0);
35 case NFT_REJECT_TCP_RST:
39 data[NFT_REG_VERDICT].verdict = NF_DROP;
42 static const struct nla_policy nft_reject_policy[NFTA_REJECT_MAX + 1] = {
43 [NFTA_REJECT_TYPE] = { .type = NLA_U32 },
44 [NFTA_REJECT_ICMP_CODE] = { .type = NLA_U8 },
47 static int nft_reject_init(const struct nft_ctx *ctx,
48 const struct nft_expr *expr,
49 const struct nlattr * const tb[])
51 struct nft_reject *priv = nft_expr_priv(expr);
53 if (tb[NFTA_REJECT_TYPE] == NULL)
56 priv->type = ntohl(nla_get_be32(tb[NFTA_REJECT_TYPE]));
58 case NFT_REJECT_ICMP_UNREACH:
59 if (tb[NFTA_REJECT_ICMP_CODE] == NULL)
61 priv->icmp_code = nla_get_u8(tb[NFTA_REJECT_ICMP_CODE]);
62 case NFT_REJECT_TCP_RST:
71 static int nft_reject_dump(struct sk_buff *skb, const struct nft_expr *expr)
73 const struct nft_reject *priv = nft_expr_priv(expr);
75 if (nla_put_be32(skb, NFTA_REJECT_TYPE, priv->type))
79 case NFT_REJECT_ICMP_UNREACH:
80 if (nla_put_u8(skb, NFTA_REJECT_ICMP_CODE, priv->icmp_code))
91 static struct nft_expr_type nft_reject_type;
92 static const struct nft_expr_ops nft_reject_ops = {
93 .type = &nft_reject_type,
94 .size = NFT_EXPR_SIZE(sizeof(struct nft_reject)),
95 .eval = nft_reject_eval,
96 .init = nft_reject_init,
97 .dump = nft_reject_dump,
100 static struct nft_expr_type nft_reject_type __read_mostly = {
102 .ops = &nft_reject_ops,
103 .policy = nft_reject_policy,
104 .maxattr = NFTA_REJECT_MAX,
105 .owner = THIS_MODULE,
108 static int __init nft_reject_module_init(void)
110 return nft_register_expr(&nft_reject_type);
113 static void __exit nft_reject_module_exit(void)
115 nft_unregister_expr(&nft_reject_type);
118 module_init(nft_reject_module_init);
119 module_exit(nft_reject_module_exit);
121 MODULE_LICENSE("GPL");
122 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
123 MODULE_ALIAS_NFT_EXPR("reject");