Blame view
net/netfilter/xt_connlabel.c
2.46 KB
d2912cb15
|
1 |
// SPDX-License-Identifier: GPL-2.0-only |
c539f0171
|
2 3 |
/* * (C) 2013 Astaro GmbH & Co KG |
c539f0171
|
4 5 6 7 8 |
*/ #include <linux/module.h> #include <linux/skbuff.h> #include <net/netfilter/nf_conntrack.h> |
857ed310c
|
9 |
#include <net/netfilter/nf_conntrack_ecache.h> |
c539f0171
|
10 11 12 13 14 |
#include <net/netfilter/nf_conntrack_labels.h> #include <linux/netfilter/x_tables.h> MODULE_LICENSE("GPL"); MODULE_AUTHOR("Florian Westphal <fw@strlen.de>"); |
1de6f3342
|
15 |
MODULE_DESCRIPTION("Xtables: add/match connection tracking labels"); |
c539f0171
|
16 17 18 19 20 21 22 23 |
MODULE_ALIAS("ipt_connlabel"); MODULE_ALIAS("ip6t_connlabel"); static bool connlabel_mt(const struct sk_buff *skb, struct xt_action_param *par) { const struct xt_connlabel_mtinfo *info = par->matchinfo; enum ip_conntrack_info ctinfo; |
857ed310c
|
24 |
struct nf_conn_labels *labels; |
c539f0171
|
25 26 27 28 |
struct nf_conn *ct; bool invert = info->options & XT_CONNLABEL_OP_INVERT; ct = nf_ct_get(skb, &ctinfo); |
ab8bc7ed8
|
29 |
if (ct == NULL) |
c539f0171
|
30 |
return invert; |
857ed310c
|
31 32 33 34 35 36 37 38 39 40 41 42 43 |
labels = nf_ct_labels_find(ct); if (!labels) return invert; if (test_bit(info->bit, labels->bits)) return !invert; if (info->options & XT_CONNLABEL_OP_SET) { if (!test_and_set_bit(info->bit, labels->bits)) nf_conntrack_event_cache(IPCT_LABEL, ct); return !invert; } |
c539f0171
|
44 |
|
857ed310c
|
45 |
return invert; |
c539f0171
|
46 47 48 49 50 51 52 53 |
} static int connlabel_mt_check(const struct xt_mtchk_param *par) { const int options = XT_CONNLABEL_OP_INVERT | XT_CONNLABEL_OP_SET; struct xt_connlabel_mtinfo *info = par->matchinfo; int ret; |
c539f0171
|
54 55 |
if (info->options & ~options) { |
b26066447
|
56 57 58 |
pr_info_ratelimited("Unknown options in mask %x ", info->options); |
c539f0171
|
59 60 |
return -EINVAL; } |
ecb2421b5
|
61 |
ret = nf_ct_netns_get(par->net, par->family); |
c539f0171
|
62 |
if (ret < 0) { |
b26066447
|
63 64 65 |
pr_info_ratelimited("cannot load conntrack support for proto=%u ", par->family); |
c539f0171
|
66 67 |
return ret; } |
adff6c656
|
68 |
ret = nf_connlabels_get(par->net, info->bit); |
86ca02e77
|
69 |
if (ret < 0) |
ecb2421b5
|
70 |
nf_ct_netns_put(par->net, par->family); |
c539f0171
|
71 72 73 74 75 |
return ret; } static void connlabel_mt_destroy(const struct xt_mtdtor_param *par) { |
86ca02e77
|
76 |
nf_connlabels_put(par->net); |
ecb2421b5
|
77 |
nf_ct_netns_put(par->net, par->family); |
c539f0171
|
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
} static struct xt_match connlabels_mt_reg __read_mostly = { .name = "connlabel", .family = NFPROTO_UNSPEC, .checkentry = connlabel_mt_check, .match = connlabel_mt, .matchsize = sizeof(struct xt_connlabel_mtinfo), .destroy = connlabel_mt_destroy, .me = THIS_MODULE, }; static int __init connlabel_mt_init(void) { return xt_register_match(&connlabels_mt_reg); } static void __exit connlabel_mt_exit(void) { xt_unregister_match(&connlabels_mt_reg); } module_init(connlabel_mt_init); module_exit(connlabel_mt_exit); |