2 * Module for modifying the secmark field of the skb, for use by
5 * Based on the nfmark match by:
6 * (C) 1999-2001 Marc Boucher <marc@mbsi.ca>
8 * (C) 2006 Red Hat, Inc., James Morris <jmorris@redhat.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/module.h>
16 #include <linux/skbuff.h>
17 #include <linux/selinux.h>
18 #include <linux/netfilter/x_tables.h>
19 #include <linux/netfilter/xt_SECMARK.h>
21 MODULE_LICENSE("GPL");
22 MODULE_AUTHOR("James Morris <jmorris@redhat.com>");
23 MODULE_DESCRIPTION("ip[6]tables SECMARK modification module");
24 MODULE_ALIAS("ipt_SECMARK");
25 MODULE_ALIAS("ip6t_SECMARK");
27 #define PFX "SECMARK: "
31 static unsigned int target(struct sk_buff
**pskb
, const struct net_device
*in
,
32 const struct net_device
*out
, unsigned int hooknum
,
33 const struct xt_target
*target
,
34 const void *targinfo
, void *userinfo
)
37 const struct xt_secmark_target_info
*info
= targinfo
;
39 BUG_ON(info
->mode
!= mode
);
42 case SECMARK_MODE_SEL
:
43 secmark
= info
->u
.sel
.selsid
;
50 if ((*pskb
)->secmark
!= secmark
)
51 (*pskb
)->secmark
= secmark
;
56 static int checkentry_selinux(struct xt_secmark_target_info
*info
)
59 struct xt_secmark_target_selinux_info
*sel
= &info
->u
.sel
;
61 err
= selinux_string_to_sid(sel
->selctx
, &sel
->selsid
);
64 printk(KERN_INFO PFX
"invalid SELinux context \'%s\'\n",
70 printk(KERN_INFO PFX
"unable to map SELinux context \'%s\'\n",
75 err
= selinux_relabel_packet_permission(sel
->selsid
);
77 printk(KERN_INFO PFX
"unable to obtain relabeling permission\n");
84 static int checkentry(const char *tablename
, const void *entry
,
85 const struct xt_target
*target
, void *targinfo
,
86 unsigned int targinfosize
, unsigned int hook_mask
)
88 struct xt_secmark_target_info
*info
= targinfo
;
90 if (mode
&& mode
!= info
->mode
) {
91 printk(KERN_INFO PFX
"mode already set to %hu cannot mix with "
92 "rules for mode %hu\n", mode
, info
->mode
);
97 case SECMARK_MODE_SEL
:
98 if (!checkentry_selinux(info
))
103 printk(KERN_INFO PFX
"invalid mode: %hu\n", info
->mode
);
112 static struct xt_target ipt_secmark_reg
= {
115 .targetsize
= sizeof(struct xt_secmark_target_info
),
117 .checkentry
= checkentry
,
123 static struct xt_target ip6t_secmark_reg
= {
126 .targetsize
= sizeof(struct xt_secmark_target_info
),
128 .checkentry
= checkentry
,
134 static int __init
xt_secmark_init(void)
138 err
= xt_register_target(&ipt_secmark_reg
);
142 err
= xt_register_target(&ip6t_secmark_reg
);
144 xt_unregister_target(&ipt_secmark_reg
);
149 static void __exit
xt_secmark_fini(void)
151 xt_unregister_target(&ip6t_secmark_reg
);
152 xt_unregister_target(&ipt_secmark_reg
);
155 module_init(xt_secmark_init
);
156 module_exit(xt_secmark_fini
);