2 * Copyright (c) 2008-2009 Patrick McHardy <kaber@trash.net>
3 * Copyright (c) 2013 Eric Leblond <eric@regit.org>
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.
9 * Development of this code funded by Astaro AG (http://www.astaro.com/)
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>
19 #include <net/netfilter/nft_reject.h>
20 #include <linux/icmp.h>
21 #include <linux/icmpv6.h>
23 const struct nla_policy nft_reject_policy
[NFTA_REJECT_MAX
+ 1] = {
24 [NFTA_REJECT_TYPE
] = { .type
= NLA_U32
},
25 [NFTA_REJECT_ICMP_CODE
] = { .type
= NLA_U8
},
27 EXPORT_SYMBOL_GPL(nft_reject_policy
);
29 int nft_reject_init(const struct nft_ctx
*ctx
,
30 const struct nft_expr
*expr
,
31 const struct nlattr
* const tb
[])
33 struct nft_reject
*priv
= nft_expr_priv(expr
);
35 if (tb
[NFTA_REJECT_TYPE
] == NULL
)
38 priv
->type
= ntohl(nla_get_be32(tb
[NFTA_REJECT_TYPE
]));
40 case NFT_REJECT_ICMP_UNREACH
:
41 if (tb
[NFTA_REJECT_ICMP_CODE
] == NULL
)
43 priv
->icmp_code
= nla_get_u8(tb
[NFTA_REJECT_ICMP_CODE
]);
44 case NFT_REJECT_TCP_RST
:
52 EXPORT_SYMBOL_GPL(nft_reject_init
);
54 int nft_reject_dump(struct sk_buff
*skb
, const struct nft_expr
*expr
)
56 const struct nft_reject
*priv
= nft_expr_priv(expr
);
58 if (nla_put_be32(skb
, NFTA_REJECT_TYPE
, htonl(priv
->type
)))
62 case NFT_REJECT_ICMP_UNREACH
:
63 if (nla_put_u8(skb
, NFTA_REJECT_ICMP_CODE
, priv
->icmp_code
))
73 EXPORT_SYMBOL_GPL(nft_reject_dump
);
75 static u8 icmp_code_v4
[NFT_REJECT_ICMPX_MAX
+ 1] = {
76 [NFT_REJECT_ICMPX_NO_ROUTE
] = ICMP_NET_UNREACH
,
77 [NFT_REJECT_ICMPX_PORT_UNREACH
] = ICMP_PORT_UNREACH
,
78 [NFT_REJECT_ICMPX_HOST_UNREACH
] = ICMP_HOST_UNREACH
,
79 [NFT_REJECT_ICMPX_ADMIN_PROHIBITED
] = ICMP_PKT_FILTERED
,
82 int nft_reject_icmp_code(u8 code
)
84 BUG_ON(code
> NFT_REJECT_ICMPX_MAX
);
86 return icmp_code_v4
[code
];
89 EXPORT_SYMBOL_GPL(nft_reject_icmp_code
);
92 static u8 icmp_code_v6
[NFT_REJECT_ICMPX_MAX
+ 1] = {
93 [NFT_REJECT_ICMPX_NO_ROUTE
] = ICMPV6_NOROUTE
,
94 [NFT_REJECT_ICMPX_PORT_UNREACH
] = ICMPV6_PORT_UNREACH
,
95 [NFT_REJECT_ICMPX_HOST_UNREACH
] = ICMPV6_ADDR_UNREACH
,
96 [NFT_REJECT_ICMPX_ADMIN_PROHIBITED
] = ICMPV6_ADM_PROHIBITED
,
99 int nft_reject_icmpv6_code(u8 code
)
101 BUG_ON(code
> NFT_REJECT_ICMPX_MAX
);
103 return icmp_code_v6
[code
];
106 EXPORT_SYMBOL_GPL(nft_reject_icmpv6_code
);
108 MODULE_LICENSE("GPL");
109 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");