2 * NetLabel Unlabeled Support
4 * This file defines functions for dealing with unlabeled packets for the
5 * NetLabel system. The NetLabel system manages static and dynamic label
6 * mappings for network protocols such as CIPSO and RIPSO.
8 * Author: Paul Moore <paul.moore@hp.com>
13 * (c) Copyright Hewlett-Packard Development Company, L.P., 2006
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
23 * the GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include <linux/types.h>
32 #include <linux/rcupdate.h>
33 #include <linux/list.h>
34 #include <linux/spinlock.h>
35 #include <linux/socket.h>
36 #include <linux/string.h>
37 #include <linux/skbuff.h>
39 #include <net/netlink.h>
40 #include <net/genetlink.h>
42 #include <net/netlabel.h>
45 #include "netlabel_user.h"
46 #include "netlabel_domainhash.h"
47 #include "netlabel_unlabeled.h"
49 /* Accept unlabeled packets flag */
50 static atomic_t netlabel_unlabel_accept_flg = ATOMIC_INIT(0);
52 /* NetLabel Generic NETLINK CIPSOv4 family */
53 static struct genl_family netlbl_unlabel_gnl_family = {
54 .id = GENL_ID_GENERATE,
56 .name = NETLBL_NLTYPE_UNLABELED_NAME,
57 .version = NETLBL_PROTO_VERSION,
63 * NetLabel Command Handlers
67 * netlbl_unlabel_accept - Handle an ACCEPT message
68 * @skb: the NETLINK buffer
69 * @info: the Generic NETLINK info block
72 * Process a user generated ACCEPT message and set the accept flag accordingly.
73 * Returns zero on success, negative values on failure.
76 static int netlbl_unlabel_accept(struct sk_buff *skb, struct genl_info *info)
79 struct nlattr *data = netlbl_netlink_payload_data(skb);
82 ret_val = netlbl_netlink_cap_check(skb, CAP_NET_ADMIN);
86 if (netlbl_netlink_payload_len(skb) == NETLBL_LEN_U32) {
87 value = nla_get_u32(data);
88 if (value == 1 || value == 0) {
89 atomic_set(&netlabel_unlabel_accept_flg, value);
90 netlbl_netlink_send_ack(info,
91 netlbl_unlabel_gnl_family.id,
98 netlbl_netlink_send_ack(info,
99 netlbl_unlabel_gnl_family.id,
106 * netlbl_unlabel_list - Handle a LIST message
107 * @skb: the NETLINK buffer
108 * @info: the Generic NETLINK info block
111 * Process a user generated LIST message and respond with the current status.
112 * Returns zero on success, negative values on failure.
115 static int netlbl_unlabel_list(struct sk_buff *skb, struct genl_info *info)
117 int ret_val = -ENOMEM;
118 struct sk_buff *ans_skb;
120 ans_skb = netlbl_netlink_alloc_skb(0,
121 GENL_HDRLEN + NETLBL_LEN_U32,
126 if (netlbl_netlink_hdr_put(ans_skb,
129 netlbl_unlabel_gnl_family.id,
130 NLBL_UNLABEL_C_LIST) == NULL)
133 ret_val = nla_put_u32(ans_skb,
135 atomic_read(&netlabel_unlabel_accept_flg));
139 ret_val = netlbl_netlink_snd(ans_skb, info->snd_pid);
146 netlbl_netlink_send_ack(info,
147 netlbl_unlabel_gnl_family.id,
155 * NetLabel Generic NETLINK Command Definitions
158 static struct genl_ops netlbl_unlabel_genl_c_accept = {
159 .cmd = NLBL_UNLABEL_C_ACCEPT,
161 .doit = netlbl_unlabel_accept,
165 static struct genl_ops netlbl_unlabel_genl_c_list = {
166 .cmd = NLBL_UNLABEL_C_LIST,
168 .doit = netlbl_unlabel_list,
174 * NetLabel Generic NETLINK Protocol Functions
178 * netlbl_unlabel_genl_init - Register the Unlabeled NetLabel component
181 * Register the unlabeled packet NetLabel component with the Generic NETLINK
182 * mechanism. Returns zero on success, negative values on failure.
185 int netlbl_unlabel_genl_init(void)
189 ret_val = genl_register_family(&netlbl_unlabel_gnl_family);
193 ret_val = genl_register_ops(&netlbl_unlabel_gnl_family,
194 &netlbl_unlabel_genl_c_accept);
198 ret_val = genl_register_ops(&netlbl_unlabel_gnl_family,
199 &netlbl_unlabel_genl_c_list);
207 * NetLabel KAPI Hooks
211 * netlbl_unlabel_getattr - Get the security attributes for an unlabled packet
212 * @secattr: the security attributes
215 * Determine the security attributes, if any, for an unlabled packet and return
216 * them in @secattr. Returns zero on success and negative values on failure.
219 int netlbl_unlabel_getattr(struct netlbl_lsm_secattr *secattr)
221 if (atomic_read(&netlabel_unlabel_accept_flg) == 1) {
222 memset(secattr, 0, sizeof(*secattr));
230 * netlbl_unlabel_defconf - Set the default config to allow unlabeled packets
233 * Set the default NetLabel configuration to allow incoming unlabeled packets
234 * and to send unlabeled network traffic by default.
237 int netlbl_unlabel_defconf(void)
240 struct netlbl_dom_map *entry;
242 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
245 entry->type = NETLBL_NLTYPE_UNLABELED;
246 ret_val = netlbl_domhsh_add_default(entry);
250 atomic_set(&netlabel_unlabel_accept_flg, 1);