xref: /openbmc/linux/include/net/netlabel.h (revision 6c2e8ac0953fccdd24dc6c4b9e08e8f1cd68cf07)
111a03f78SPaul Moore /*
211a03f78SPaul Moore  * NetLabel System
311a03f78SPaul Moore  *
411a03f78SPaul Moore  * The NetLabel system manages static and dynamic label mappings for network
511a03f78SPaul Moore  * protocols such as CIPSO and RIPSO.
611a03f78SPaul Moore  *
711a03f78SPaul Moore  * Author: Paul Moore <paul.moore@hp.com>
811a03f78SPaul Moore  *
911a03f78SPaul Moore  */
1011a03f78SPaul Moore 
1111a03f78SPaul Moore /*
1263c41688SPaul Moore  * (c) Copyright Hewlett-Packard Development Company, L.P., 2006, 2008
1311a03f78SPaul Moore  *
1411a03f78SPaul Moore  * This program is free software;  you can redistribute it and/or modify
1511a03f78SPaul Moore  * it under the terms of the GNU General Public License as published by
1611a03f78SPaul Moore  * the Free Software Foundation; either version 2 of the License, or
1711a03f78SPaul Moore  * (at your option) any later version.
1811a03f78SPaul Moore  *
1911a03f78SPaul Moore  * This program is distributed in the hope that it will be useful,
2011a03f78SPaul Moore  * but WITHOUT ANY WARRANTY;  without even the implied warranty of
2111a03f78SPaul Moore  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
2211a03f78SPaul Moore  * the GNU General Public License for more details.
2311a03f78SPaul Moore  *
2411a03f78SPaul Moore  * You should have received a copy of the GNU General Public License
2511a03f78SPaul Moore  * along with this program;  if not, write to the Free Software
2611a03f78SPaul Moore  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2711a03f78SPaul Moore  *
2811a03f78SPaul Moore  */
2911a03f78SPaul Moore 
3011a03f78SPaul Moore #ifndef _NETLABEL_H
3111a03f78SPaul Moore #define _NETLABEL_H
3211a03f78SPaul Moore 
3311a03f78SPaul Moore #include <linux/types.h>
347a0e1d60SPaul Moore #include <linux/net.h>
3511a03f78SPaul Moore #include <linux/skbuff.h>
36*6c2e8ac0SPaul Moore #include <linux/in.h>
37*6c2e8ac0SPaul Moore #include <linux/in6.h>
3811a03f78SPaul Moore #include <net/netlink.h>
39ffb733c6Spaul.moore@hp.com #include <asm/atomic.h>
4011a03f78SPaul Moore 
41eda61d32SPaul Moore struct cipso_v4_doi;
42eda61d32SPaul Moore 
4311a03f78SPaul Moore /*
4411a03f78SPaul Moore  * NetLabel - A management interface for maintaining network packet label
4511a03f78SPaul Moore  *            mapping tables for explicit packet labling protocols.
4611a03f78SPaul Moore  *
4711a03f78SPaul Moore  * Network protocols such as CIPSO and RIPSO require a label translation layer
4811a03f78SPaul Moore  * to convert the label on the packet into something meaningful on the host
4911a03f78SPaul Moore  * machine.  In the current Linux implementation these mapping tables live
5011a03f78SPaul Moore  * inside the kernel; NetLabel provides a mechanism for user space applications
5111a03f78SPaul Moore  * to manage these mapping tables.
5211a03f78SPaul Moore  *
5311a03f78SPaul Moore  * NetLabel makes use of the Generic NETLINK mechanism as a transport layer to
5411a03f78SPaul Moore  * send messages between kernel and user space.  The general format of a
5511a03f78SPaul Moore  * NetLabel message is shown below:
5611a03f78SPaul Moore  *
5711a03f78SPaul Moore  *  +-----------------+-------------------+--------- --- -- -
5811a03f78SPaul Moore  *  | struct nlmsghdr | struct genlmsghdr | payload
5911a03f78SPaul Moore  *  +-----------------+-------------------+--------- --- -- -
6011a03f78SPaul Moore  *
6111a03f78SPaul Moore  * The 'nlmsghdr' and 'genlmsghdr' structs should be dealt with like normal.
6211a03f78SPaul Moore  * The payload is dependent on the subsystem specified in the
6311a03f78SPaul Moore  * 'nlmsghdr->nlmsg_type' and should be defined below, supporting functions
6411a03f78SPaul Moore  * should be defined in the corresponding net/netlabel/netlabel_<subsys>.h|c
65fcd48280SPaul Moore  * file.  All of the fields in the NetLabel payload are NETLINK attributes, see
66fcd48280SPaul Moore  * the include/net/netlink.h file for more information on NETLINK attributes.
6711a03f78SPaul Moore  *
6811a03f78SPaul Moore  */
6911a03f78SPaul Moore 
7011a03f78SPaul Moore /*
7111a03f78SPaul Moore  * NetLabel NETLINK protocol
7211a03f78SPaul Moore  */
7311a03f78SPaul Moore 
748cc44579SPaul Moore /* NetLabel NETLINK protocol version
758cc44579SPaul Moore  *  1: initial version
768cc44579SPaul Moore  *  2: added static labels for unlabeled connections
77d91d4079SPaul Moore  *  3: network selectors added to the NetLabel/LSM domain mapping and the
78d91d4079SPaul Moore  *     CIPSO_V4_MAP_LOCAL CIPSO mapping was added
798cc44579SPaul Moore  */
8063c41688SPaul Moore #define NETLBL_PROTO_VERSION            3
8111a03f78SPaul Moore 
8211a03f78SPaul Moore /* NetLabel NETLINK types/families */
8311a03f78SPaul Moore #define NETLBL_NLTYPE_NONE              0
8411a03f78SPaul Moore #define NETLBL_NLTYPE_MGMT              1
8511a03f78SPaul Moore #define NETLBL_NLTYPE_MGMT_NAME         "NLBL_MGMT"
8611a03f78SPaul Moore #define NETLBL_NLTYPE_RIPSO             2
8711a03f78SPaul Moore #define NETLBL_NLTYPE_RIPSO_NAME        "NLBL_RIPSO"
8811a03f78SPaul Moore #define NETLBL_NLTYPE_CIPSOV4           3
8911a03f78SPaul Moore #define NETLBL_NLTYPE_CIPSOV4_NAME      "NLBL_CIPSOv4"
9011a03f78SPaul Moore #define NETLBL_NLTYPE_CIPSOV6           4
9111a03f78SPaul Moore #define NETLBL_NLTYPE_CIPSOV6_NAME      "NLBL_CIPSOv6"
9211a03f78SPaul Moore #define NETLBL_NLTYPE_UNLABELED         5
9311a03f78SPaul Moore #define NETLBL_NLTYPE_UNLABELED_NAME    "NLBL_UNLBL"
9463c41688SPaul Moore #define NETLBL_NLTYPE_ADDRSELECT        6
9563c41688SPaul Moore #define NETLBL_NLTYPE_ADDRSELECT_NAME   "NLBL_ADRSEL"
9611a03f78SPaul Moore 
9711a03f78SPaul Moore /*
9811a03f78SPaul Moore  * NetLabel - Kernel API for accessing the network packet label mappings.
9911a03f78SPaul Moore  *
10011a03f78SPaul Moore  * The following functions are provided for use by other kernel modules,
10111a03f78SPaul Moore  * specifically kernel LSM modules, to provide a consistent, transparent API
10211a03f78SPaul Moore  * for dealing with explicit packet labeling protocols such as CIPSO and
10311a03f78SPaul Moore  * RIPSO.  The functions defined here are implemented in the
10411a03f78SPaul Moore  * net/netlabel/netlabel_kapi.c file.
10511a03f78SPaul Moore  *
10611a03f78SPaul Moore  */
10711a03f78SPaul Moore 
10895d4e6beSPaul Moore /* NetLabel audit information */
10995d4e6beSPaul Moore struct netlbl_audit {
11095d4e6beSPaul Moore 	u32 secid;
11195d4e6beSPaul Moore 	uid_t loginuid;
1122532386fSEric Paris 	u32 sessionid;
11395d4e6beSPaul Moore };
11495d4e6beSPaul Moore 
11516efd454SPaul Moore /*
11616efd454SPaul Moore  * LSM security attributes
11716efd454SPaul Moore  */
11816efd454SPaul Moore 
11916efd454SPaul Moore /**
12016efd454SPaul Moore  * struct netlbl_lsm_cache - NetLabel LSM security attribute cache
12116efd454SPaul Moore  * @refcount: atomic reference counter
12216efd454SPaul Moore  * @free: LSM supplied function to free the cache data
12316efd454SPaul Moore  * @data: LSM supplied cache data
12416efd454SPaul Moore  *
12516efd454SPaul Moore  * Description:
12616efd454SPaul Moore  * This structure is provided for LSMs which wish to make use of the NetLabel
12716efd454SPaul Moore  * caching mechanism to store LSM specific data/attributes in the NetLabel
12816efd454SPaul Moore  * cache.  If the LSM has to perform a lot of translation from the NetLabel
12916efd454SPaul Moore  * security attributes into it's own internal representation then the cache
13016efd454SPaul Moore  * mechanism can provide a way to eliminate some or all of that translation
13116efd454SPaul Moore  * overhead on a cache hit.
13216efd454SPaul Moore  *
13316efd454SPaul Moore  */
13411a03f78SPaul Moore struct netlbl_lsm_cache {
135ffb733c6Spaul.moore@hp.com 	atomic_t refcount;
13611a03f78SPaul Moore 	void (*free) (const void *data);
13711a03f78SPaul Moore 	void *data;
13811a03f78SPaul Moore };
13916efd454SPaul Moore 
14016efd454SPaul Moore /**
14116efd454SPaul Moore  * struct netlbl_lsm_secattr_catmap - NetLabel LSM secattr category bitmap
14216efd454SPaul Moore  * @startbit: the value of the lowest order bit in the bitmap
14316efd454SPaul Moore  * @bitmap: the category bitmap
14416efd454SPaul Moore  * @next: pointer to the next bitmap "node" or NULL
14516efd454SPaul Moore  *
14616efd454SPaul Moore  * Description:
14716efd454SPaul Moore  * This structure is used to represent category bitmaps.  Due to the large
14816efd454SPaul Moore  * number of categories supported by most labeling protocols it is not
14916efd454SPaul Moore  * practical to transfer a full bitmap internally so NetLabel adopts a sparse
15016efd454SPaul Moore  * bitmap structure modeled after SELinux's ebitmap structure.
15116efd454SPaul Moore  * The catmap bitmap field MUST be a power of two in length and large
15202752760SPaul Moore  * enough to hold at least 240 bits.  Special care (i.e. check the code!)
15302752760SPaul Moore  * should be used when changing these values as the LSM implementation
15402752760SPaul Moore  * probably has functions which rely on the sizes of these types to speed
15516efd454SPaul Moore  * processing.
15616efd454SPaul Moore  *
15716efd454SPaul Moore  */
15802752760SPaul Moore #define NETLBL_CATMAP_MAPTYPE           u64
15902752760SPaul Moore #define NETLBL_CATMAP_MAPCNT            4
16002752760SPaul Moore #define NETLBL_CATMAP_MAPSIZE           (sizeof(NETLBL_CATMAP_MAPTYPE) * 8)
16102752760SPaul Moore #define NETLBL_CATMAP_SIZE              (NETLBL_CATMAP_MAPSIZE * \
16202752760SPaul Moore 					 NETLBL_CATMAP_MAPCNT)
16302752760SPaul Moore #define NETLBL_CATMAP_BIT               (NETLBL_CATMAP_MAPTYPE)0x01
16402752760SPaul Moore struct netlbl_lsm_secattr_catmap {
16502752760SPaul Moore 	u32 startbit;
16602752760SPaul Moore 	NETLBL_CATMAP_MAPTYPE bitmap[NETLBL_CATMAP_MAPCNT];
16702752760SPaul Moore 	struct netlbl_lsm_secattr_catmap *next;
16802752760SPaul Moore };
16916efd454SPaul Moore 
17016efd454SPaul Moore /**
17116efd454SPaul Moore  * struct netlbl_lsm_secattr - NetLabel LSM security attributes
17200447872SPaul Moore  * @flags: indicate structure attributes, see NETLBL_SECATTR_*
17316efd454SPaul Moore  * @type: indicate the NLTYPE of the attributes
17416efd454SPaul Moore  * @domain: the NetLabel LSM domain
17516efd454SPaul Moore  * @cache: NetLabel LSM specific cache
17616efd454SPaul Moore  * @attr.mls: MLS sensitivity label
17716efd454SPaul Moore  * @attr.mls.cat: MLS category bitmap
17816efd454SPaul Moore  * @attr.mls.lvl: MLS sensitivity level
17916efd454SPaul Moore  * @attr.secid: LSM specific secid token
18016efd454SPaul Moore  *
18116efd454SPaul Moore  * Description:
18216efd454SPaul Moore  * This structure is used to pass security attributes between NetLabel and the
18316efd454SPaul Moore  * LSM modules.  The flags field is used to specify which fields within the
18416efd454SPaul Moore  * struct are valid and valid values can be created by bitwise OR'ing the
18516efd454SPaul Moore  * NETLBL_SECATTR_* defines.  The domain field is typically set by the LSM to
18616efd454SPaul Moore  * specify domain specific configuration settings and is not usually used by
18716efd454SPaul Moore  * NetLabel itself when returning security attributes to the LSM.
18816efd454SPaul Moore  *
18916efd454SPaul Moore  */
19000447872SPaul Moore struct netlbl_lsm_secattr {
19100447872SPaul Moore 	u32 flags;
19200447872SPaul Moore 	/* bitmap values for 'flags' */
193701a90baSPaul Moore #define NETLBL_SECATTR_NONE             0x00000000
194701a90baSPaul Moore #define NETLBL_SECATTR_DOMAIN           0x00000001
19500447872SPaul Moore #define NETLBL_SECATTR_DOMAIN_CPY       (NETLBL_SECATTR_DOMAIN | \
19600447872SPaul Moore 					 NETLBL_SECATTR_FREE_DOMAIN)
197701a90baSPaul Moore #define NETLBL_SECATTR_CACHE            0x00000002
198701a90baSPaul Moore #define NETLBL_SECATTR_MLS_LVL          0x00000004
199701a90baSPaul Moore #define NETLBL_SECATTR_MLS_CAT          0x00000008
20016efd454SPaul Moore #define NETLBL_SECATTR_SECID            0x00000010
20100447872SPaul Moore 	/* bitmap meta-values for 'flags' */
20200447872SPaul Moore #define NETLBL_SECATTR_FREE_DOMAIN      0x01000000
2039534f71cSPaul Moore #define NETLBL_SECATTR_CACHEABLE        (NETLBL_SECATTR_MLS_LVL | \
20416efd454SPaul Moore 					 NETLBL_SECATTR_MLS_CAT | \
20516efd454SPaul Moore 					 NETLBL_SECATTR_SECID)
20616efd454SPaul Moore 	u32 type;
20711a03f78SPaul Moore 	char *domain;
208ffb733c6Spaul.moore@hp.com 	struct netlbl_lsm_cache *cache;
2098d75899dSPaul Moore 	struct {
21016efd454SPaul Moore 		struct {
21116efd454SPaul Moore 			struct netlbl_lsm_secattr_catmap *cat;
21216efd454SPaul Moore 			u32 lvl;
21316efd454SPaul Moore 		} mls;
21416efd454SPaul Moore 		u32 secid;
21516efd454SPaul Moore 	} attr;
21611a03f78SPaul Moore };
21711a03f78SPaul Moore 
21811a03f78SPaul Moore /*
21923bcdc1aSPaul Moore  * LSM security attribute operations (inline)
22011a03f78SPaul Moore  */
22111a03f78SPaul Moore 
22211a03f78SPaul Moore /**
223ffb733c6Spaul.moore@hp.com  * netlbl_secattr_cache_alloc - Allocate and initialize a secattr cache
224ffb733c6Spaul.moore@hp.com  * @flags: the memory allocation flags
225ffb733c6Spaul.moore@hp.com  *
226ffb733c6Spaul.moore@hp.com  * Description:
227ffb733c6Spaul.moore@hp.com  * Allocate and initialize a netlbl_lsm_cache structure.  Returns a pointer
228ffb733c6Spaul.moore@hp.com  * on success, NULL on failure.
229ffb733c6Spaul.moore@hp.com  *
230ffb733c6Spaul.moore@hp.com  */
231645408d1SAl Viro static inline struct netlbl_lsm_cache *netlbl_secattr_cache_alloc(gfp_t flags)
232ffb733c6Spaul.moore@hp.com {
233ffb733c6Spaul.moore@hp.com 	struct netlbl_lsm_cache *cache;
234ffb733c6Spaul.moore@hp.com 
235ffb733c6Spaul.moore@hp.com 	cache = kzalloc(sizeof(*cache), flags);
236ffb733c6Spaul.moore@hp.com 	if (cache)
237ffb733c6Spaul.moore@hp.com 		atomic_set(&cache->refcount, 1);
238ffb733c6Spaul.moore@hp.com 	return cache;
239ffb733c6Spaul.moore@hp.com }
240ffb733c6Spaul.moore@hp.com 
241ffb733c6Spaul.moore@hp.com /**
242ffb733c6Spaul.moore@hp.com  * netlbl_secattr_cache_free - Frees a netlbl_lsm_cache struct
243ffb733c6Spaul.moore@hp.com  * @cache: the struct to free
244ffb733c6Spaul.moore@hp.com  *
245ffb733c6Spaul.moore@hp.com  * Description:
246ffb733c6Spaul.moore@hp.com  * Frees @secattr including all of the internal buffers.
247ffb733c6Spaul.moore@hp.com  *
248ffb733c6Spaul.moore@hp.com  */
249ffb733c6Spaul.moore@hp.com static inline void netlbl_secattr_cache_free(struct netlbl_lsm_cache *cache)
250ffb733c6Spaul.moore@hp.com {
251ffb733c6Spaul.moore@hp.com 	if (!atomic_dec_and_test(&cache->refcount))
252ffb733c6Spaul.moore@hp.com 		return;
253ffb733c6Spaul.moore@hp.com 
254ffb733c6Spaul.moore@hp.com 	if (cache->free)
255ffb733c6Spaul.moore@hp.com 		cache->free(cache->data);
256ffb733c6Spaul.moore@hp.com 	kfree(cache);
257ffb733c6Spaul.moore@hp.com }
258ffb733c6Spaul.moore@hp.com 
259ffb733c6Spaul.moore@hp.com /**
26002752760SPaul Moore  * netlbl_secattr_catmap_alloc - Allocate a LSM secattr catmap
26102752760SPaul Moore  * @flags: memory allocation flags
26202752760SPaul Moore  *
26302752760SPaul Moore  * Description:
26402752760SPaul Moore  * Allocate memory for a LSM secattr catmap, returns a pointer on success, NULL
26502752760SPaul Moore  * on failure.
26602752760SPaul Moore  *
26702752760SPaul Moore  */
26802752760SPaul Moore static inline struct netlbl_lsm_secattr_catmap *netlbl_secattr_catmap_alloc(
26902752760SPaul Moore 	                                                           gfp_t flags)
27002752760SPaul Moore {
27102752760SPaul Moore 	return kzalloc(sizeof(struct netlbl_lsm_secattr_catmap), flags);
27202752760SPaul Moore }
27302752760SPaul Moore 
27402752760SPaul Moore /**
27502752760SPaul Moore  * netlbl_secattr_catmap_free - Free a LSM secattr catmap
27602752760SPaul Moore  * @catmap: the category bitmap
27702752760SPaul Moore  *
27802752760SPaul Moore  * Description:
27902752760SPaul Moore  * Free a LSM secattr catmap.
28002752760SPaul Moore  *
28102752760SPaul Moore  */
28202752760SPaul Moore static inline void netlbl_secattr_catmap_free(
28302752760SPaul Moore 	                              struct netlbl_lsm_secattr_catmap *catmap)
28402752760SPaul Moore {
28502752760SPaul Moore 	struct netlbl_lsm_secattr_catmap *iter;
28602752760SPaul Moore 
28702752760SPaul Moore 	do {
28802752760SPaul Moore 		iter = catmap;
28902752760SPaul Moore 		catmap = catmap->next;
29002752760SPaul Moore 		kfree(iter);
29102752760SPaul Moore 	} while (catmap);
29202752760SPaul Moore }
29302752760SPaul Moore 
29402752760SPaul Moore /**
29511a03f78SPaul Moore  * netlbl_secattr_init - Initialize a netlbl_lsm_secattr struct
29611a03f78SPaul Moore  * @secattr: the struct to initialize
29711a03f78SPaul Moore  *
29811a03f78SPaul Moore  * Description:
299c6fa82a9SPaul Moore  * Initialize an already allocated netlbl_lsm_secattr struct.
30011a03f78SPaul Moore  *
30111a03f78SPaul Moore  */
302c6fa82a9SPaul Moore static inline void netlbl_secattr_init(struct netlbl_lsm_secattr *secattr)
30311a03f78SPaul Moore {
30416efd454SPaul Moore 	memset(secattr, 0, sizeof(*secattr));
30511a03f78SPaul Moore }
30611a03f78SPaul Moore 
30711a03f78SPaul Moore /**
30811a03f78SPaul Moore  * netlbl_secattr_destroy - Clears a netlbl_lsm_secattr struct
30911a03f78SPaul Moore  * @secattr: the struct to clear
31011a03f78SPaul Moore  *
31111a03f78SPaul Moore  * Description:
31211a03f78SPaul Moore  * Destroys the @secattr struct, including freeing all of the internal buffers.
313ffb733c6Spaul.moore@hp.com  * The struct must be reset with a call to netlbl_secattr_init() before reuse.
31411a03f78SPaul Moore  *
31511a03f78SPaul Moore  */
316ffb733c6Spaul.moore@hp.com static inline void netlbl_secattr_destroy(struct netlbl_lsm_secattr *secattr)
31711a03f78SPaul Moore {
31800447872SPaul Moore 	if (secattr->flags & NETLBL_SECATTR_FREE_DOMAIN)
31911a03f78SPaul Moore 		kfree(secattr->domain);
32016efd454SPaul Moore 	if (secattr->flags & NETLBL_SECATTR_CACHE)
32116efd454SPaul Moore 		netlbl_secattr_cache_free(secattr->cache);
32216efd454SPaul Moore 	if (secattr->flags & NETLBL_SECATTR_MLS_CAT)
32316efd454SPaul Moore 		netlbl_secattr_catmap_free(secattr->attr.mls.cat);
32411a03f78SPaul Moore }
32511a03f78SPaul Moore 
32611a03f78SPaul Moore /**
32711a03f78SPaul Moore  * netlbl_secattr_alloc - Allocate and initialize a netlbl_lsm_secattr struct
32811a03f78SPaul Moore  * @flags: the memory allocation flags
32911a03f78SPaul Moore  *
33011a03f78SPaul Moore  * Description:
33111a03f78SPaul Moore  * Allocate and initialize a netlbl_lsm_secattr struct.  Returns a valid
33211a03f78SPaul Moore  * pointer on success, or NULL on failure.
33311a03f78SPaul Moore  *
33411a03f78SPaul Moore  */
3351f758d93SPaul Moore static inline struct netlbl_lsm_secattr *netlbl_secattr_alloc(gfp_t flags)
33611a03f78SPaul Moore {
33711a03f78SPaul Moore 	return kzalloc(sizeof(struct netlbl_lsm_secattr), flags);
33811a03f78SPaul Moore }
33911a03f78SPaul Moore 
34011a03f78SPaul Moore /**
34111a03f78SPaul Moore  * netlbl_secattr_free - Frees a netlbl_lsm_secattr struct
34211a03f78SPaul Moore  * @secattr: the struct to free
34311a03f78SPaul Moore  *
34411a03f78SPaul Moore  * Description:
345ffb733c6Spaul.moore@hp.com  * Frees @secattr including all of the internal buffers.
34611a03f78SPaul Moore  *
34711a03f78SPaul Moore  */
348ffb733c6Spaul.moore@hp.com static inline void netlbl_secattr_free(struct netlbl_lsm_secattr *secattr)
34911a03f78SPaul Moore {
350ffb733c6Spaul.moore@hp.com 	netlbl_secattr_destroy(secattr);
35111a03f78SPaul Moore 	kfree(secattr);
35211a03f78SPaul Moore }
35311a03f78SPaul Moore 
35402752760SPaul Moore #ifdef CONFIG_NETLABEL
35523bcdc1aSPaul Moore /*
356eda61d32SPaul Moore  * LSM configuration operations
357eda61d32SPaul Moore  */
358*6c2e8ac0SPaul Moore int netlbl_cfg_map_del(const char *domain,
359*6c2e8ac0SPaul Moore 		       u16 family,
360*6c2e8ac0SPaul Moore 		       const void *addr,
361*6c2e8ac0SPaul Moore 		       const void *mask,
362eda61d32SPaul Moore 		       struct netlbl_audit *audit_info);
363*6c2e8ac0SPaul Moore int netlbl_cfg_unlbl_map_add(const char *domain,
364*6c2e8ac0SPaul Moore 			     u16 family,
365*6c2e8ac0SPaul Moore 			     const void *addr,
366*6c2e8ac0SPaul Moore 			     const void *mask,
367*6c2e8ac0SPaul Moore 			     struct netlbl_audit *audit_info);
368*6c2e8ac0SPaul Moore int netlbl_cfg_unlbl_static_add(struct net *net,
369*6c2e8ac0SPaul Moore 				const char *dev_name,
370*6c2e8ac0SPaul Moore 				const void *addr,
371*6c2e8ac0SPaul Moore 				const void *mask,
372*6c2e8ac0SPaul Moore 				u16 family,
373*6c2e8ac0SPaul Moore 				u32 secid,
374*6c2e8ac0SPaul Moore 				struct netlbl_audit *audit_info);
375*6c2e8ac0SPaul Moore int netlbl_cfg_unlbl_static_del(struct net *net,
376*6c2e8ac0SPaul Moore 				const char *dev_name,
377*6c2e8ac0SPaul Moore 				const void *addr,
378*6c2e8ac0SPaul Moore 				const void *mask,
379*6c2e8ac0SPaul Moore 				u16 family,
380*6c2e8ac0SPaul Moore 				struct netlbl_audit *audit_info);
381*6c2e8ac0SPaul Moore int netlbl_cfg_cipsov4_add(struct cipso_v4_doi *doi_def,
382*6c2e8ac0SPaul Moore 			   struct netlbl_audit *audit_info);
383*6c2e8ac0SPaul Moore void netlbl_cfg_cipsov4_del(u32 doi, struct netlbl_audit *audit_info);
384*6c2e8ac0SPaul Moore int netlbl_cfg_cipsov4_map_add(u32 doi,
385eda61d32SPaul Moore 			       const char *domain,
386*6c2e8ac0SPaul Moore 			       const struct in_addr *addr,
387*6c2e8ac0SPaul Moore 			       const struct in_addr *mask,
388eda61d32SPaul Moore 			       struct netlbl_audit *audit_info);
389eda61d32SPaul Moore /*
39023bcdc1aSPaul Moore  * LSM security attribute operations
39123bcdc1aSPaul Moore  */
39202752760SPaul Moore int netlbl_secattr_catmap_walk(struct netlbl_lsm_secattr_catmap *catmap,
39302752760SPaul Moore 			       u32 offset);
39402752760SPaul Moore int netlbl_secattr_catmap_walk_rng(struct netlbl_lsm_secattr_catmap *catmap,
39502752760SPaul Moore 				   u32 offset);
39602752760SPaul Moore int netlbl_secattr_catmap_setbit(struct netlbl_lsm_secattr_catmap *catmap,
39702752760SPaul Moore 				 u32 bit,
39802752760SPaul Moore 				 gfp_t flags);
39902752760SPaul Moore int netlbl_secattr_catmap_setrng(struct netlbl_lsm_secattr_catmap *catmap,
40002752760SPaul Moore 				 u32 start,
40102752760SPaul Moore 				 u32 end,
40202752760SPaul Moore 				 gfp_t flags);
40323bcdc1aSPaul Moore 
40423bcdc1aSPaul Moore /*
40516efd454SPaul Moore  * LSM protocol operations (NetLabel LSM/kernel API)
40623bcdc1aSPaul Moore  */
40723bcdc1aSPaul Moore int netlbl_enabled(void);
40823bcdc1aSPaul Moore int netlbl_sock_setattr(struct sock *sk,
40923bcdc1aSPaul Moore 			const struct netlbl_lsm_secattr *secattr);
410014ab19aSPaul Moore void netlbl_sock_delattr(struct sock *sk);
41123bcdc1aSPaul Moore int netlbl_sock_getattr(struct sock *sk,
41223bcdc1aSPaul Moore 			struct netlbl_lsm_secattr *secattr);
413014ab19aSPaul Moore int netlbl_conn_setattr(struct sock *sk,
414014ab19aSPaul Moore 			struct sockaddr *addr,
415014ab19aSPaul Moore 			const struct netlbl_lsm_secattr *secattr);
416948bf85cSPaul Moore int netlbl_skbuff_setattr(struct sk_buff *skb,
417948bf85cSPaul Moore 			  u16 family,
418948bf85cSPaul Moore 			  const struct netlbl_lsm_secattr *secattr);
41923bcdc1aSPaul Moore int netlbl_skbuff_getattr(const struct sk_buff *skb,
42075e22910SPaul Moore 			  u16 family,
42123bcdc1aSPaul Moore 			  struct netlbl_lsm_secattr *secattr);
422dfaebe98SPaul Moore void netlbl_skbuff_err(struct sk_buff *skb, int error, int gateway);
42323bcdc1aSPaul Moore 
42423bcdc1aSPaul Moore /*
42523bcdc1aSPaul Moore  * LSM label mapping cache operations
42623bcdc1aSPaul Moore  */
42723bcdc1aSPaul Moore void netlbl_cache_invalidate(void);
42823bcdc1aSPaul Moore int netlbl_cache_add(const struct sk_buff *skb,
42923bcdc1aSPaul Moore 		     const struct netlbl_lsm_secattr *secattr);
430*6c2e8ac0SPaul Moore 
431*6c2e8ac0SPaul Moore /*
432*6c2e8ac0SPaul Moore  * Protocol engine operations
433*6c2e8ac0SPaul Moore  */
434*6c2e8ac0SPaul Moore struct audit_buffer *netlbl_audit_start(int type,
435*6c2e8ac0SPaul Moore 					struct netlbl_audit *audit_info);
43602752760SPaul Moore #else
437eda61d32SPaul Moore static inline int netlbl_cfg_map_del(const char *domain,
438*6c2e8ac0SPaul Moore 				     u16 family,
439*6c2e8ac0SPaul Moore 				     const void *addr,
440*6c2e8ac0SPaul Moore 				     const void *mask,
441eda61d32SPaul Moore 				     struct netlbl_audit *audit_info)
442eda61d32SPaul Moore {
443eda61d32SPaul Moore 	return -ENOSYS;
444eda61d32SPaul Moore }
445*6c2e8ac0SPaul Moore static inline int netlbl_cfg_unlbl_map_add(const char *domain,
446*6c2e8ac0SPaul Moore 					   u16 family,
447*6c2e8ac0SPaul Moore 					   void *addr,
448*6c2e8ac0SPaul Moore 					   void *mask,
449eda61d32SPaul Moore 					   struct netlbl_audit *audit_info)
450eda61d32SPaul Moore {
451eda61d32SPaul Moore 	return -ENOSYS;
452eda61d32SPaul Moore }
453*6c2e8ac0SPaul Moore static inline int netlbl_cfg_unlbl_static_add(struct net *net,
454*6c2e8ac0SPaul Moore 					      const char *dev_name,
455*6c2e8ac0SPaul Moore 					      const void *addr,
456*6c2e8ac0SPaul Moore 					      const void *mask,
457*6c2e8ac0SPaul Moore 					      u16 family,
458*6c2e8ac0SPaul Moore 					      u32 secid,
459*6c2e8ac0SPaul Moore 					      struct netlbl_audit *audit_info)
460*6c2e8ac0SPaul Moore {
461*6c2e8ac0SPaul Moore 	return -ENOSYS;
462*6c2e8ac0SPaul Moore }
463*6c2e8ac0SPaul Moore static inline int netlbl_cfg_unlbl_static_del(struct net *net,
464*6c2e8ac0SPaul Moore 					      const char *dev_name,
465*6c2e8ac0SPaul Moore 					      const void *addr,
466*6c2e8ac0SPaul Moore 					      const void *mask,
467*6c2e8ac0SPaul Moore 					      u16 family,
468*6c2e8ac0SPaul Moore 					      struct netlbl_audit *audit_info)
469*6c2e8ac0SPaul Moore {
470*6c2e8ac0SPaul Moore 	return -ENOSYS;
471*6c2e8ac0SPaul Moore }
472*6c2e8ac0SPaul Moore static inline int netlbl_cfg_cipsov4_add(struct cipso_v4_doi *doi_def,
473*6c2e8ac0SPaul Moore 					 struct netlbl_audit *audit_info)
474*6c2e8ac0SPaul Moore {
475*6c2e8ac0SPaul Moore 	return -ENOSYS;
476*6c2e8ac0SPaul Moore }
477*6c2e8ac0SPaul Moore static inline void netlbl_cfg_cipsov4_del(u32 doi,
478*6c2e8ac0SPaul Moore 					  struct netlbl_audit *audit_info)
479*6c2e8ac0SPaul Moore {
480*6c2e8ac0SPaul Moore 	return;
481*6c2e8ac0SPaul Moore }
482*6c2e8ac0SPaul Moore static inline int netlbl_cfg_cipsov4_map_add(u32 doi,
483eda61d32SPaul Moore 					     const char *domain,
484*6c2e8ac0SPaul Moore 					     const struct in_addr *addr,
485*6c2e8ac0SPaul Moore 					     const struct in_addr *mask,
486eda61d32SPaul Moore 					     struct netlbl_audit *audit_info)
487eda61d32SPaul Moore {
488eda61d32SPaul Moore 	return -ENOSYS;
489eda61d32SPaul Moore }
49002752760SPaul Moore static inline int netlbl_secattr_catmap_walk(
49102752760SPaul Moore 	                              struct netlbl_lsm_secattr_catmap *catmap,
49202752760SPaul Moore 				      u32 offset)
49302752760SPaul Moore {
49402752760SPaul Moore 	return -ENOENT;
49502752760SPaul Moore }
49602752760SPaul Moore static inline int netlbl_secattr_catmap_walk_rng(
49702752760SPaul Moore 				      struct netlbl_lsm_secattr_catmap *catmap,
49802752760SPaul Moore 				      u32 offset)
49902752760SPaul Moore {
50002752760SPaul Moore 	return -ENOENT;
50102752760SPaul Moore }
50202752760SPaul Moore static inline int netlbl_secattr_catmap_setbit(
50302752760SPaul Moore 	                              struct netlbl_lsm_secattr_catmap *catmap,
50402752760SPaul Moore 				      u32 bit,
50502752760SPaul Moore 				      gfp_t flags)
50602752760SPaul Moore {
50702752760SPaul Moore 	return 0;
50802752760SPaul Moore }
50902752760SPaul Moore static inline int netlbl_secattr_catmap_setrng(
51002752760SPaul Moore 	                              struct netlbl_lsm_secattr_catmap *catmap,
51102752760SPaul Moore 				      u32 start,
51202752760SPaul Moore 				      u32 end,
51302752760SPaul Moore 				      gfp_t flags)
51402752760SPaul Moore {
51502752760SPaul Moore 	return 0;
51602752760SPaul Moore }
51723bcdc1aSPaul Moore static inline int netlbl_enabled(void)
51823bcdc1aSPaul Moore {
51923bcdc1aSPaul Moore 	return 0;
52023bcdc1aSPaul Moore }
521ba6ff9f2SPaul Moore static inline int netlbl_sock_setattr(struct sock *sk,
52211a03f78SPaul Moore 				     const struct netlbl_lsm_secattr *secattr)
52311a03f78SPaul Moore {
52411a03f78SPaul Moore 	return -ENOSYS;
52511a03f78SPaul Moore }
526014ab19aSPaul Moore static inline void netlbl_sock_delattr(struct sock *sk)
527014ab19aSPaul Moore {
528014ab19aSPaul Moore }
52914a72f53SPaul Moore static inline int netlbl_sock_getattr(struct sock *sk,
53014a72f53SPaul Moore 				      struct netlbl_lsm_secattr *secattr)
53114a72f53SPaul Moore {
53214a72f53SPaul Moore 	return -ENOSYS;
53314a72f53SPaul Moore }
534014ab19aSPaul Moore static inline int netlbl_conn_setattr(struct sock *sk,
535014ab19aSPaul Moore 				      struct sockaddr *addr,
536014ab19aSPaul Moore 				      const struct netlbl_lsm_secattr *secattr)
537014ab19aSPaul Moore {
538014ab19aSPaul Moore 	return -ENOSYS;
539014ab19aSPaul Moore }
540948bf85cSPaul Moore static inline int netlbl_skbuff_setattr(struct sk_buff *skb,
541948bf85cSPaul Moore 				      u16 family,
542948bf85cSPaul Moore 				      const struct netlbl_lsm_secattr *secattr)
543948bf85cSPaul Moore {
544948bf85cSPaul Moore 	return -ENOSYS;
545948bf85cSPaul Moore }
54611a03f78SPaul Moore static inline int netlbl_skbuff_getattr(const struct sk_buff *skb,
54775e22910SPaul Moore 					u16 family,
54811a03f78SPaul Moore 					struct netlbl_lsm_secattr *secattr)
54911a03f78SPaul Moore {
55011a03f78SPaul Moore 	return -ENOSYS;
55111a03f78SPaul Moore }
552dfaebe98SPaul Moore static inline void netlbl_skbuff_err(struct sk_buff *skb,
553dfaebe98SPaul Moore 				     int error,
554dfaebe98SPaul Moore 				     int gateway)
55511a03f78SPaul Moore {
55611a03f78SPaul Moore 	return;
55711a03f78SPaul Moore }
55811a03f78SPaul Moore static inline void netlbl_cache_invalidate(void)
55911a03f78SPaul Moore {
56011a03f78SPaul Moore 	return;
56111a03f78SPaul Moore }
56211a03f78SPaul Moore static inline int netlbl_cache_add(const struct sk_buff *skb,
56311a03f78SPaul Moore 				   const struct netlbl_lsm_secattr *secattr)
56411a03f78SPaul Moore {
56511a03f78SPaul Moore 	return 0;
56611a03f78SPaul Moore }
567*6c2e8ac0SPaul Moore static inline struct audit_buffer *netlbl_audit_start(int type,
568*6c2e8ac0SPaul Moore 						struct netlbl_audit *audit_info)
569*6c2e8ac0SPaul Moore {
570*6c2e8ac0SPaul Moore 	return NULL;
571*6c2e8ac0SPaul Moore }
57211a03f78SPaul Moore #endif /* CONFIG_NETLABEL */
57311a03f78SPaul Moore 
57411a03f78SPaul Moore #endif /* _NETLABEL_H */
575