Driver core: Don't leak 'old_class_name' in drivers/base/core.c::device_rename()
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / net / netlabel.h
blob12c214b9eadf8b8d7da0f7c0eb12c08512193049
1 /*
2 * NetLabel System
4 * The NetLabel system manages static and dynamic label mappings for network
5 * protocols such as CIPSO and RIPSO.
7 * Author: Paul Moore <paul.moore@hp.com>
9 */
12 * (c) Copyright Hewlett-Packard Development Company, L.P., 2006
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
22 * the GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #ifndef _NETLABEL_H
31 #define _NETLABEL_H
33 #include <linux/types.h>
34 #include <linux/net.h>
35 #include <linux/skbuff.h>
36 #include <net/netlink.h>
37 #include <asm/atomic.h>
40 * NetLabel - A management interface for maintaining network packet label
41 * mapping tables for explicit packet labling protocols.
43 * Network protocols such as CIPSO and RIPSO require a label translation layer
44 * to convert the label on the packet into something meaningful on the host
45 * machine. In the current Linux implementation these mapping tables live
46 * inside the kernel; NetLabel provides a mechanism for user space applications
47 * to manage these mapping tables.
49 * NetLabel makes use of the Generic NETLINK mechanism as a transport layer to
50 * send messages between kernel and user space. The general format of a
51 * NetLabel message is shown below:
53 * +-----------------+-------------------+--------- --- -- -
54 * | struct nlmsghdr | struct genlmsghdr | payload
55 * +-----------------+-------------------+--------- --- -- -
57 * The 'nlmsghdr' and 'genlmsghdr' structs should be dealt with like normal.
58 * The payload is dependent on the subsystem specified in the
59 * 'nlmsghdr->nlmsg_type' and should be defined below, supporting functions
60 * should be defined in the corresponding net/netlabel/netlabel_<subsys>.h|c
61 * file. All of the fields in the NetLabel payload are NETLINK attributes, see
62 * the include/net/netlink.h file for more information on NETLINK attributes.
67 * NetLabel NETLINK protocol
70 #define NETLBL_PROTO_VERSION 1
72 /* NetLabel NETLINK types/families */
73 #define NETLBL_NLTYPE_NONE 0
74 #define NETLBL_NLTYPE_MGMT 1
75 #define NETLBL_NLTYPE_MGMT_NAME "NLBL_MGMT"
76 #define NETLBL_NLTYPE_RIPSO 2
77 #define NETLBL_NLTYPE_RIPSO_NAME "NLBL_RIPSO"
78 #define NETLBL_NLTYPE_CIPSOV4 3
79 #define NETLBL_NLTYPE_CIPSOV4_NAME "NLBL_CIPSOv4"
80 #define NETLBL_NLTYPE_CIPSOV6 4
81 #define NETLBL_NLTYPE_CIPSOV6_NAME "NLBL_CIPSOv6"
82 #define NETLBL_NLTYPE_UNLABELED 5
83 #define NETLBL_NLTYPE_UNLABELED_NAME "NLBL_UNLBL"
86 * NetLabel - Kernel API for accessing the network packet label mappings.
88 * The following functions are provided for use by other kernel modules,
89 * specifically kernel LSM modules, to provide a consistent, transparent API
90 * for dealing with explicit packet labeling protocols such as CIPSO and
91 * RIPSO. The functions defined here are implemented in the
92 * net/netlabel/netlabel_kapi.c file.
96 /* NetLabel audit information */
97 struct netlbl_audit {
98 u32 secid;
99 uid_t loginuid;
102 /* Domain mapping definition struct */
103 struct netlbl_dom_map;
105 /* Domain mapping operations */
106 int netlbl_domhsh_remove(const char *domain, struct netlbl_audit *audit_info);
108 /* LSM security attributes */
109 struct netlbl_lsm_cache {
110 atomic_t refcount;
111 void (*free) (const void *data);
112 void *data;
114 struct netlbl_lsm_secattr {
115 char *domain;
117 u32 mls_lvl;
118 u32 mls_lvl_vld;
119 unsigned char *mls_cat;
120 size_t mls_cat_len;
122 struct netlbl_lsm_cache *cache;
126 * LSM security attribute operations
131 * netlbl_secattr_cache_alloc - Allocate and initialize a secattr cache
132 * @flags: the memory allocation flags
134 * Description:
135 * Allocate and initialize a netlbl_lsm_cache structure. Returns a pointer
136 * on success, NULL on failure.
139 static inline struct netlbl_lsm_cache *netlbl_secattr_cache_alloc(gfp_t flags)
141 struct netlbl_lsm_cache *cache;
143 cache = kzalloc(sizeof(*cache), flags);
144 if (cache)
145 atomic_set(&cache->refcount, 1);
146 return cache;
150 * netlbl_secattr_cache_free - Frees a netlbl_lsm_cache struct
151 * @cache: the struct to free
153 * Description:
154 * Frees @secattr including all of the internal buffers.
157 static inline void netlbl_secattr_cache_free(struct netlbl_lsm_cache *cache)
159 if (!atomic_dec_and_test(&cache->refcount))
160 return;
162 if (cache->free)
163 cache->free(cache->data);
164 kfree(cache);
168 * netlbl_secattr_init - Initialize a netlbl_lsm_secattr struct
169 * @secattr: the struct to initialize
171 * Description:
172 * Initialize an already allocated netlbl_lsm_secattr struct. Returns zero on
173 * success, negative values on error.
176 static inline int netlbl_secattr_init(struct netlbl_lsm_secattr *secattr)
178 memset(secattr, 0, sizeof(*secattr));
179 return 0;
183 * netlbl_secattr_destroy - Clears a netlbl_lsm_secattr struct
184 * @secattr: the struct to clear
186 * Description:
187 * Destroys the @secattr struct, including freeing all of the internal buffers.
188 * The struct must be reset with a call to netlbl_secattr_init() before reuse.
191 static inline void netlbl_secattr_destroy(struct netlbl_lsm_secattr *secattr)
193 if (secattr->cache)
194 netlbl_secattr_cache_free(secattr->cache);
195 kfree(secattr->domain);
196 kfree(secattr->mls_cat);
200 * netlbl_secattr_alloc - Allocate and initialize a netlbl_lsm_secattr struct
201 * @flags: the memory allocation flags
203 * Description:
204 * Allocate and initialize a netlbl_lsm_secattr struct. Returns a valid
205 * pointer on success, or NULL on failure.
208 static inline struct netlbl_lsm_secattr *netlbl_secattr_alloc(int flags)
210 return kzalloc(sizeof(struct netlbl_lsm_secattr), flags);
214 * netlbl_secattr_free - Frees a netlbl_lsm_secattr struct
215 * @secattr: the struct to free
217 * Description:
218 * Frees @secattr including all of the internal buffers.
221 static inline void netlbl_secattr_free(struct netlbl_lsm_secattr *secattr)
223 netlbl_secattr_destroy(secattr);
224 kfree(secattr);
228 * LSM protocol operations
231 #ifdef CONFIG_NETLABEL
232 int netlbl_socket_setattr(const struct socket *sock,
233 const struct netlbl_lsm_secattr *secattr);
234 int netlbl_sock_getattr(struct sock *sk,
235 struct netlbl_lsm_secattr *secattr);
236 int netlbl_socket_getattr(const struct socket *sock,
237 struct netlbl_lsm_secattr *secattr);
238 int netlbl_skbuff_getattr(const struct sk_buff *skb,
239 struct netlbl_lsm_secattr *secattr);
240 void netlbl_skbuff_err(struct sk_buff *skb, int error);
241 #else
242 static inline int netlbl_socket_setattr(const struct socket *sock,
243 const struct netlbl_lsm_secattr *secattr)
245 return -ENOSYS;
248 static inline int netlbl_sock_getattr(struct sock *sk,
249 struct netlbl_lsm_secattr *secattr)
251 return -ENOSYS;
254 static inline int netlbl_socket_getattr(const struct socket *sock,
255 struct netlbl_lsm_secattr *secattr)
257 return -ENOSYS;
260 static inline int netlbl_skbuff_getattr(const struct sk_buff *skb,
261 struct netlbl_lsm_secattr *secattr)
263 return -ENOSYS;
266 static inline void netlbl_skbuff_err(struct sk_buff *skb, int error)
268 return;
270 #endif /* CONFIG_NETLABEL */
273 * LSM label mapping cache operations
276 #ifdef CONFIG_NETLABEL
277 void netlbl_cache_invalidate(void);
278 int netlbl_cache_add(const struct sk_buff *skb,
279 const struct netlbl_lsm_secattr *secattr);
280 #else
281 static inline void netlbl_cache_invalidate(void)
283 return;
286 static inline int netlbl_cache_add(const struct sk_buff *skb,
287 const struct netlbl_lsm_secattr *secattr)
289 return 0;
291 #endif /* CONFIG_NETLABEL */
293 #endif /* _NETLABEL_H */