2 * Copyright (c) 2008 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/netlink.h>
14 #include <linux/netfilter.h>
15 #include <linux/netfilter/nf_tables.h>
16 #include <net/netfilter/nf_tables.h>
22 static void nft_template_eval(const struct nft_expr *expr,
23 struct nft_data data[NFT_REG_MAX + 1],
24 const struct nft_pktinfo *pkt)
26 struct nft_template *priv = nft_expr_priv(expr);
30 static const struct nla_policy nft_template_policy[NFTA_TEMPLATE_MAX + 1] = {
31 [NFTA_TEMPLATE_ATTR] = { .type = NLA_U32 },
34 static int nft_template_init(const struct nft_ctx *ctx,
35 const struct nft_expr *expr,
36 const struct nlattr *tb[])
38 struct nft_template *priv = nft_expr_priv(expr);
43 static void nft_template_destroy(const struct nft_ctx *ctx,
44 const struct nft_expr *expr)
46 struct nft_template *priv = nft_expr_priv(expr);
50 static int nft_template_dump(struct sk_buff *skb, const struct nft_expr *expr)
52 const struct nft_template *priv = nft_expr_priv(expr);
54 NLA_PUT_BE32(skb, NFTA_TEMPLATE_ATTR, priv->field);
61 static struct nft_expr_ops template_ops __read_mostly = {
63 .size = NFT_EXPR_SIZE(sizeof(struct nft_template)),
65 .eval = nft_template_eval,
66 .init = nft_template_init,
67 .destroy = nft_template_destroy,
68 .dump = nft_template_dump,
69 .policy = nft_template_policy,
70 .maxattr = NFTA_TEMPLATE_MAX,
73 static int __init nft_template_module_init(void)
75 return nft_register_expr(&template_ops);
78 static void __exit nft_template_module_exit(void)
80 nft_unregister_expr(&template_ops);
83 module_init(nft_template_module_init);
84 module_exit(nft_template_module_exit);
86 MODULE_LICENSE("GPL");
87 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
88 MODULE_ALIAS_NFT_EXPR("template");