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/list.h>
14 #include <linux/rbtree.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>
21 enum nft_meta_keys key;
24 static void nft_meta_eval(const struct nft_expr *expr,
25 struct nft_data *nfres,
26 struct nft_data *data,
27 const struct nft_pktinfo *pkt)
29 const struct nft_meta *meta = nft_expr_priv(expr);
30 struct sk_buff *skb = pkt->skb;
31 u32 val = data->data[0];
37 case NFT_META_PRIORITY:
40 case NFT_META_NFTRACE:
43 #ifdef CONFIG_NETWORK_SECMARK
44 case NFT_META_SECMARK:
53 static const struct nla_policy nft_meta_policy[NFTA_META_MAX + 1] = {
54 [NFTA_META_KEY] = { .type = NLA_U32 },
57 static int nft_meta_init(const struct nft_expr *expr, struct nlattr *tb[])
59 struct nft_meta *meta = nft_expr_priv(expr);
61 if (tb[NFTA_META_KEY] == NULL)
64 meta->key = ntohl(nla_get_be32(tb[NFTA_META_KEY]));
67 case NFT_META_PRIORITY:
68 case NFT_META_NFTRACE:
69 #ifdef CONFIG_NETWORK_SECMARK
70 case NFT_META_SECMARK:
80 static int nft_meta_dump(struct sk_buff *skb, const struct nft_expr *expr)
82 struct nft_meta *meta = nft_expr_priv(expr);
84 NLA_PUT_BE32(skb, NFTA_META_KEY, htonl(meta->key));
91 static struct nft_expr_ops meta_target __read_mostly = {
93 .size = NFT_EXPR_SIZE(sizeof(struct nft_meta)),
95 .eval = nft_meta_eval,
96 .init = nft_meta_init,
97 .dump = nft_meta_dump,
98 .policy = nft_meta_policy,
99 .maxattr = NFTA_META_MAX,
102 static int __init nft_meta_target_init(void)
104 return nft_register_expr(&meta_target);
107 static void __exit nft_meta_target_exit(void)
109 nft_unregister_expr(&meta_target);
112 module_init(nft_meta_target_init);
113 module_exit(nft_meta_target_exit);
115 MODULE_LICENSE("GPL");
116 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
117 MODULE_ALIAS_NFT_EXPR("meta");