xref: /openbmc/linux/include/net/netlabel.h (revision dfaebe9825ff34983778f287101bc5f3bce00640)
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 /*
1211a03f78SPaul Moore  * (c) Copyright Hewlett-Packard Development Company, L.P., 2006
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>
3611a03f78SPaul Moore #include <net/netlink.h>
37ffb733c6Spaul.moore@hp.com #include <asm/atomic.h>
3811a03f78SPaul Moore 
39eda61d32SPaul Moore struct cipso_v4_doi;
40eda61d32SPaul Moore 
4111a03f78SPaul Moore /*
4211a03f78SPaul Moore  * NetLabel - A management interface for maintaining network packet label
4311a03f78SPaul Moore  *            mapping tables for explicit packet labling protocols.
4411a03f78SPaul Moore  *
4511a03f78SPaul Moore  * Network protocols such as CIPSO and RIPSO require a label translation layer
4611a03f78SPaul Moore  * to convert the label on the packet into something meaningful on the host
4711a03f78SPaul Moore  * machine.  In the current Linux implementation these mapping tables live
4811a03f78SPaul Moore  * inside the kernel; NetLabel provides a mechanism for user space applications
4911a03f78SPaul Moore  * to manage these mapping tables.
5011a03f78SPaul Moore  *
5111a03f78SPaul Moore  * NetLabel makes use of the Generic NETLINK mechanism as a transport layer to
5211a03f78SPaul Moore  * send messages between kernel and user space.  The general format of a
5311a03f78SPaul Moore  * NetLabel message is shown below:
5411a03f78SPaul Moore  *
5511a03f78SPaul Moore  *  +-----------------+-------------------+--------- --- -- -
5611a03f78SPaul Moore  *  | struct nlmsghdr | struct genlmsghdr | payload
5711a03f78SPaul Moore  *  +-----------------+-------------------+--------- --- -- -
5811a03f78SPaul Moore  *
5911a03f78SPaul Moore  * The 'nlmsghdr' and 'genlmsghdr' structs should be dealt with like normal.
6011a03f78SPaul Moore  * The payload is dependent on the subsystem specified in the
6111a03f78SPaul Moore  * 'nlmsghdr->nlmsg_type' and should be defined below, supporting functions
6211a03f78SPaul Moore  * should be defined in the corresponding net/netlabel/netlabel_<subsys>.h|c
63fcd48280SPaul Moore  * file.  All of the fields in the NetLabel payload are NETLINK attributes, see
64fcd48280SPaul Moore  * the include/net/netlink.h file for more information on NETLINK attributes.
6511a03f78SPaul Moore  *
6611a03f78SPaul Moore  */
6711a03f78SPaul Moore 
6811a03f78SPaul Moore /*
6911a03f78SPaul Moore  * NetLabel NETLINK protocol
7011a03f78SPaul Moore  */
7111a03f78SPaul Moore 
728cc44579SPaul Moore /* NetLabel NETLINK protocol version
738cc44579SPaul Moore  *  1: initial version
748cc44579SPaul Moore  *  2: added static labels for unlabeled connections
758cc44579SPaul Moore  */
768cc44579SPaul Moore #define NETLBL_PROTO_VERSION            2
7711a03f78SPaul Moore 
7811a03f78SPaul Moore /* NetLabel NETLINK types/families */
7911a03f78SPaul Moore #define NETLBL_NLTYPE_NONE              0
8011a03f78SPaul Moore #define NETLBL_NLTYPE_MGMT              1
8111a03f78SPaul Moore #define NETLBL_NLTYPE_MGMT_NAME         "NLBL_MGMT"
8211a03f78SPaul Moore #define NETLBL_NLTYPE_RIPSO             2
8311a03f78SPaul Moore #define NETLBL_NLTYPE_RIPSO_NAME        "NLBL_RIPSO"
8411a03f78SPaul Moore #define NETLBL_NLTYPE_CIPSOV4           3
8511a03f78SPaul Moore #define NETLBL_NLTYPE_CIPSOV4_NAME      "NLBL_CIPSOv4"
8611a03f78SPaul Moore #define NETLBL_NLTYPE_CIPSOV6           4
8711a03f78SPaul Moore #define NETLBL_NLTYPE_CIPSOV6_NAME      "NLBL_CIPSOv6"
8811a03f78SPaul Moore #define NETLBL_NLTYPE_UNLABELED         5
8911a03f78SPaul Moore #define NETLBL_NLTYPE_UNLABELED_NAME    "NLBL_UNLBL"
9011a03f78SPaul Moore 
9111a03f78SPaul Moore /*
9211a03f78SPaul Moore  * NetLabel - Kernel API for accessing the network packet label mappings.
9311a03f78SPaul Moore  *
9411a03f78SPaul Moore  * The following functions are provided for use by other kernel modules,
9511a03f78SPaul Moore  * specifically kernel LSM modules, to provide a consistent, transparent API
9611a03f78SPaul Moore  * for dealing with explicit packet labeling protocols such as CIPSO and
9711a03f78SPaul Moore  * RIPSO.  The functions defined here are implemented in the
9811a03f78SPaul Moore  * net/netlabel/netlabel_kapi.c file.
9911a03f78SPaul Moore  *
10011a03f78SPaul Moore  */
10111a03f78SPaul Moore 
10295d4e6beSPaul Moore /* NetLabel audit information */
10395d4e6beSPaul Moore struct netlbl_audit {
10495d4e6beSPaul Moore 	u32 secid;
10595d4e6beSPaul Moore 	uid_t loginuid;
1062532386fSEric Paris 	u32 sessionid;
10795d4e6beSPaul Moore };
10895d4e6beSPaul Moore 
10916efd454SPaul Moore /*
11016efd454SPaul Moore  * LSM security attributes
11116efd454SPaul Moore  */
11216efd454SPaul Moore 
11316efd454SPaul Moore /**
11416efd454SPaul Moore  * struct netlbl_lsm_cache - NetLabel LSM security attribute cache
11516efd454SPaul Moore  * @refcount: atomic reference counter
11616efd454SPaul Moore  * @free: LSM supplied function to free the cache data
11716efd454SPaul Moore  * @data: LSM supplied cache data
11816efd454SPaul Moore  *
11916efd454SPaul Moore  * Description:
12016efd454SPaul Moore  * This structure is provided for LSMs which wish to make use of the NetLabel
12116efd454SPaul Moore  * caching mechanism to store LSM specific data/attributes in the NetLabel
12216efd454SPaul Moore  * cache.  If the LSM has to perform a lot of translation from the NetLabel
12316efd454SPaul Moore  * security attributes into it's own internal representation then the cache
12416efd454SPaul Moore  * mechanism can provide a way to eliminate some or all of that translation
12516efd454SPaul Moore  * overhead on a cache hit.
12616efd454SPaul Moore  *
12716efd454SPaul Moore  */
12811a03f78SPaul Moore struct netlbl_lsm_cache {
129ffb733c6Spaul.moore@hp.com 	atomic_t refcount;
13011a03f78SPaul Moore 	void (*free) (const void *data);
13111a03f78SPaul Moore 	void *data;
13211a03f78SPaul Moore };
13316efd454SPaul Moore 
13416efd454SPaul Moore /**
13516efd454SPaul Moore  * struct netlbl_lsm_secattr_catmap - NetLabel LSM secattr category bitmap
13616efd454SPaul Moore  * @startbit: the value of the lowest order bit in the bitmap
13716efd454SPaul Moore  * @bitmap: the category bitmap
13816efd454SPaul Moore  * @next: pointer to the next bitmap "node" or NULL
13916efd454SPaul Moore  *
14016efd454SPaul Moore  * Description:
14116efd454SPaul Moore  * This structure is used to represent category bitmaps.  Due to the large
14216efd454SPaul Moore  * number of categories supported by most labeling protocols it is not
14316efd454SPaul Moore  * practical to transfer a full bitmap internally so NetLabel adopts a sparse
14416efd454SPaul Moore  * bitmap structure modeled after SELinux's ebitmap structure.
14516efd454SPaul Moore  * The catmap bitmap field MUST be a power of two in length and large
14602752760SPaul Moore  * enough to hold at least 240 bits.  Special care (i.e. check the code!)
14702752760SPaul Moore  * should be used when changing these values as the LSM implementation
14802752760SPaul Moore  * probably has functions which rely on the sizes of these types to speed
14916efd454SPaul Moore  * processing.
15016efd454SPaul Moore  *
15116efd454SPaul Moore  */
15202752760SPaul Moore #define NETLBL_CATMAP_MAPTYPE           u64
15302752760SPaul Moore #define NETLBL_CATMAP_MAPCNT            4
15402752760SPaul Moore #define NETLBL_CATMAP_MAPSIZE           (sizeof(NETLBL_CATMAP_MAPTYPE) * 8)
15502752760SPaul Moore #define NETLBL_CATMAP_SIZE              (NETLBL_CATMAP_MAPSIZE * \
15602752760SPaul Moore 					 NETLBL_CATMAP_MAPCNT)
15702752760SPaul Moore #define NETLBL_CATMAP_BIT               (NETLBL_CATMAP_MAPTYPE)0x01
15802752760SPaul Moore struct netlbl_lsm_secattr_catmap {
15902752760SPaul Moore 	u32 startbit;
16002752760SPaul Moore 	NETLBL_CATMAP_MAPTYPE bitmap[NETLBL_CATMAP_MAPCNT];
16102752760SPaul Moore 	struct netlbl_lsm_secattr_catmap *next;
16202752760SPaul Moore };
16316efd454SPaul Moore 
16416efd454SPaul Moore /**
16516efd454SPaul Moore  * struct netlbl_lsm_secattr - NetLabel LSM security attributes
16600447872SPaul Moore  * @flags: indicate structure attributes, see NETLBL_SECATTR_*
16716efd454SPaul Moore  * @type: indicate the NLTYPE of the attributes
16816efd454SPaul Moore  * @domain: the NetLabel LSM domain
16916efd454SPaul Moore  * @cache: NetLabel LSM specific cache
17016efd454SPaul Moore  * @attr.mls: MLS sensitivity label
17116efd454SPaul Moore  * @attr.mls.cat: MLS category bitmap
17216efd454SPaul Moore  * @attr.mls.lvl: MLS sensitivity level
17316efd454SPaul Moore  * @attr.secid: LSM specific secid token
17416efd454SPaul Moore  *
17516efd454SPaul Moore  * Description:
17616efd454SPaul Moore  * This structure is used to pass security attributes between NetLabel and the
17716efd454SPaul Moore  * LSM modules.  The flags field is used to specify which fields within the
17816efd454SPaul Moore  * struct are valid and valid values can be created by bitwise OR'ing the
17916efd454SPaul Moore  * NETLBL_SECATTR_* defines.  The domain field is typically set by the LSM to
18016efd454SPaul Moore  * specify domain specific configuration settings and is not usually used by
18116efd454SPaul Moore  * NetLabel itself when returning security attributes to the LSM.
18216efd454SPaul Moore  *
18316efd454SPaul Moore  */
18400447872SPaul Moore struct netlbl_lsm_secattr {
18500447872SPaul Moore 	u32 flags;
18600447872SPaul Moore 	/* bitmap values for 'flags' */
187701a90baSPaul Moore #define NETLBL_SECATTR_NONE             0x00000000
188701a90baSPaul Moore #define NETLBL_SECATTR_DOMAIN           0x00000001
18900447872SPaul Moore #define NETLBL_SECATTR_DOMAIN_CPY       (NETLBL_SECATTR_DOMAIN | \
19000447872SPaul Moore 					 NETLBL_SECATTR_FREE_DOMAIN)
191701a90baSPaul Moore #define NETLBL_SECATTR_CACHE            0x00000002
192701a90baSPaul Moore #define NETLBL_SECATTR_MLS_LVL          0x00000004
193701a90baSPaul Moore #define NETLBL_SECATTR_MLS_CAT          0x00000008
19416efd454SPaul Moore #define NETLBL_SECATTR_SECID            0x00000010
19500447872SPaul Moore 	/* bitmap meta-values for 'flags' */
19600447872SPaul Moore #define NETLBL_SECATTR_FREE_DOMAIN      0x01000000
1979534f71cSPaul Moore #define NETLBL_SECATTR_CACHEABLE        (NETLBL_SECATTR_MLS_LVL | \
19816efd454SPaul Moore 					 NETLBL_SECATTR_MLS_CAT | \
19916efd454SPaul Moore 					 NETLBL_SECATTR_SECID)
20016efd454SPaul Moore 	u32 type;
20111a03f78SPaul Moore 	char *domain;
202ffb733c6Spaul.moore@hp.com 	struct netlbl_lsm_cache *cache;
20316efd454SPaul Moore 	union {
20416efd454SPaul Moore 		struct {
20516efd454SPaul Moore 			struct netlbl_lsm_secattr_catmap *cat;
20616efd454SPaul Moore 			u32 lvl;
20716efd454SPaul Moore 		} mls;
20816efd454SPaul Moore 		u32 secid;
20916efd454SPaul Moore 	} attr;
21011a03f78SPaul Moore };
21111a03f78SPaul Moore 
21211a03f78SPaul Moore /*
21323bcdc1aSPaul Moore  * LSM security attribute operations (inline)
21411a03f78SPaul Moore  */
21511a03f78SPaul Moore 
21611a03f78SPaul Moore /**
217ffb733c6Spaul.moore@hp.com  * netlbl_secattr_cache_alloc - Allocate and initialize a secattr cache
218ffb733c6Spaul.moore@hp.com  * @flags: the memory allocation flags
219ffb733c6Spaul.moore@hp.com  *
220ffb733c6Spaul.moore@hp.com  * Description:
221ffb733c6Spaul.moore@hp.com  * Allocate and initialize a netlbl_lsm_cache structure.  Returns a pointer
222ffb733c6Spaul.moore@hp.com  * on success, NULL on failure.
223ffb733c6Spaul.moore@hp.com  *
224ffb733c6Spaul.moore@hp.com  */
225645408d1SAl Viro static inline struct netlbl_lsm_cache *netlbl_secattr_cache_alloc(gfp_t flags)
226ffb733c6Spaul.moore@hp.com {
227ffb733c6Spaul.moore@hp.com 	struct netlbl_lsm_cache *cache;
228ffb733c6Spaul.moore@hp.com 
229ffb733c6Spaul.moore@hp.com 	cache = kzalloc(sizeof(*cache), flags);
230ffb733c6Spaul.moore@hp.com 	if (cache)
231ffb733c6Spaul.moore@hp.com 		atomic_set(&cache->refcount, 1);
232ffb733c6Spaul.moore@hp.com 	return cache;
233ffb733c6Spaul.moore@hp.com }
234ffb733c6Spaul.moore@hp.com 
235ffb733c6Spaul.moore@hp.com /**
236ffb733c6Spaul.moore@hp.com  * netlbl_secattr_cache_free - Frees a netlbl_lsm_cache struct
237ffb733c6Spaul.moore@hp.com  * @cache: the struct to free
238ffb733c6Spaul.moore@hp.com  *
239ffb733c6Spaul.moore@hp.com  * Description:
240ffb733c6Spaul.moore@hp.com  * Frees @secattr including all of the internal buffers.
241ffb733c6Spaul.moore@hp.com  *
242ffb733c6Spaul.moore@hp.com  */
243ffb733c6Spaul.moore@hp.com static inline void netlbl_secattr_cache_free(struct netlbl_lsm_cache *cache)
244ffb733c6Spaul.moore@hp.com {
245ffb733c6Spaul.moore@hp.com 	if (!atomic_dec_and_test(&cache->refcount))
246ffb733c6Spaul.moore@hp.com 		return;
247ffb733c6Spaul.moore@hp.com 
248ffb733c6Spaul.moore@hp.com 	if (cache->free)
249ffb733c6Spaul.moore@hp.com 		cache->free(cache->data);
250ffb733c6Spaul.moore@hp.com 	kfree(cache);
251ffb733c6Spaul.moore@hp.com }
252ffb733c6Spaul.moore@hp.com 
253ffb733c6Spaul.moore@hp.com /**
25402752760SPaul Moore  * netlbl_secattr_catmap_alloc - Allocate a LSM secattr catmap
25502752760SPaul Moore  * @flags: memory allocation flags
25602752760SPaul Moore  *
25702752760SPaul Moore  * Description:
25802752760SPaul Moore  * Allocate memory for a LSM secattr catmap, returns a pointer on success, NULL
25902752760SPaul Moore  * on failure.
26002752760SPaul Moore  *
26102752760SPaul Moore  */
26202752760SPaul Moore static inline struct netlbl_lsm_secattr_catmap *netlbl_secattr_catmap_alloc(
26302752760SPaul Moore 	                                                           gfp_t flags)
26402752760SPaul Moore {
26502752760SPaul Moore 	return kzalloc(sizeof(struct netlbl_lsm_secattr_catmap), flags);
26602752760SPaul Moore }
26702752760SPaul Moore 
26802752760SPaul Moore /**
26902752760SPaul Moore  * netlbl_secattr_catmap_free - Free a LSM secattr catmap
27002752760SPaul Moore  * @catmap: the category bitmap
27102752760SPaul Moore  *
27202752760SPaul Moore  * Description:
27302752760SPaul Moore  * Free a LSM secattr catmap.
27402752760SPaul Moore  *
27502752760SPaul Moore  */
27602752760SPaul Moore static inline void netlbl_secattr_catmap_free(
27702752760SPaul Moore 	                              struct netlbl_lsm_secattr_catmap *catmap)
27802752760SPaul Moore {
27902752760SPaul Moore 	struct netlbl_lsm_secattr_catmap *iter;
28002752760SPaul Moore 
28102752760SPaul Moore 	do {
28202752760SPaul Moore 		iter = catmap;
28302752760SPaul Moore 		catmap = catmap->next;
28402752760SPaul Moore 		kfree(iter);
28502752760SPaul Moore 	} while (catmap);
28602752760SPaul Moore }
28702752760SPaul Moore 
28802752760SPaul Moore /**
28911a03f78SPaul Moore  * netlbl_secattr_init - Initialize a netlbl_lsm_secattr struct
29011a03f78SPaul Moore  * @secattr: the struct to initialize
29111a03f78SPaul Moore  *
29211a03f78SPaul Moore  * Description:
293c6fa82a9SPaul Moore  * Initialize an already allocated netlbl_lsm_secattr struct.
29411a03f78SPaul Moore  *
29511a03f78SPaul Moore  */
296c6fa82a9SPaul Moore static inline void netlbl_secattr_init(struct netlbl_lsm_secattr *secattr)
29711a03f78SPaul Moore {
29816efd454SPaul Moore 	memset(secattr, 0, sizeof(*secattr));
29911a03f78SPaul Moore }
30011a03f78SPaul Moore 
30111a03f78SPaul Moore /**
30211a03f78SPaul Moore  * netlbl_secattr_destroy - Clears a netlbl_lsm_secattr struct
30311a03f78SPaul Moore  * @secattr: the struct to clear
30411a03f78SPaul Moore  *
30511a03f78SPaul Moore  * Description:
30611a03f78SPaul Moore  * Destroys the @secattr struct, including freeing all of the internal buffers.
307ffb733c6Spaul.moore@hp.com  * The struct must be reset with a call to netlbl_secattr_init() before reuse.
30811a03f78SPaul Moore  *
30911a03f78SPaul Moore  */
310ffb733c6Spaul.moore@hp.com static inline void netlbl_secattr_destroy(struct netlbl_lsm_secattr *secattr)
31111a03f78SPaul Moore {
31200447872SPaul Moore 	if (secattr->flags & NETLBL_SECATTR_FREE_DOMAIN)
31311a03f78SPaul Moore 		kfree(secattr->domain);
31416efd454SPaul Moore 	if (secattr->flags & NETLBL_SECATTR_CACHE)
31516efd454SPaul Moore 		netlbl_secattr_cache_free(secattr->cache);
31616efd454SPaul Moore 	if (secattr->flags & NETLBL_SECATTR_MLS_CAT)
31716efd454SPaul Moore 		netlbl_secattr_catmap_free(secattr->attr.mls.cat);
31811a03f78SPaul Moore }
31911a03f78SPaul Moore 
32011a03f78SPaul Moore /**
32111a03f78SPaul Moore  * netlbl_secattr_alloc - Allocate and initialize a netlbl_lsm_secattr struct
32211a03f78SPaul Moore  * @flags: the memory allocation flags
32311a03f78SPaul Moore  *
32411a03f78SPaul Moore  * Description:
32511a03f78SPaul Moore  * Allocate and initialize a netlbl_lsm_secattr struct.  Returns a valid
32611a03f78SPaul Moore  * pointer on success, or NULL on failure.
32711a03f78SPaul Moore  *
32811a03f78SPaul Moore  */
3291f758d93SPaul Moore static inline struct netlbl_lsm_secattr *netlbl_secattr_alloc(gfp_t flags)
33011a03f78SPaul Moore {
33111a03f78SPaul Moore 	return kzalloc(sizeof(struct netlbl_lsm_secattr), flags);
33211a03f78SPaul Moore }
33311a03f78SPaul Moore 
33411a03f78SPaul Moore /**
33511a03f78SPaul Moore  * netlbl_secattr_free - Frees a netlbl_lsm_secattr struct
33611a03f78SPaul Moore  * @secattr: the struct to free
33711a03f78SPaul Moore  *
33811a03f78SPaul Moore  * Description:
339ffb733c6Spaul.moore@hp.com  * Frees @secattr including all of the internal buffers.
34011a03f78SPaul Moore  *
34111a03f78SPaul Moore  */
342ffb733c6Spaul.moore@hp.com static inline void netlbl_secattr_free(struct netlbl_lsm_secattr *secattr)
34311a03f78SPaul Moore {
344ffb733c6Spaul.moore@hp.com 	netlbl_secattr_destroy(secattr);
34511a03f78SPaul Moore 	kfree(secattr);
34611a03f78SPaul Moore }
34711a03f78SPaul Moore 
34802752760SPaul Moore #ifdef CONFIG_NETLABEL
34923bcdc1aSPaul Moore /*
350eda61d32SPaul Moore  * LSM configuration operations
351eda61d32SPaul Moore  */
352eda61d32SPaul Moore int netlbl_cfg_map_del(const char *domain, struct netlbl_audit *audit_info);
353eda61d32SPaul Moore int netlbl_cfg_unlbl_add_map(const char *domain,
354eda61d32SPaul Moore 			     struct netlbl_audit *audit_info);
355eda61d32SPaul Moore int netlbl_cfg_cipsov4_add_map(struct cipso_v4_doi *doi_def,
356eda61d32SPaul Moore 			       const char *domain,
357eda61d32SPaul Moore 			       struct netlbl_audit *audit_info);
358eda61d32SPaul Moore 
359eda61d32SPaul Moore /*
36023bcdc1aSPaul Moore  * LSM security attribute operations
36123bcdc1aSPaul Moore  */
36202752760SPaul Moore int netlbl_secattr_catmap_walk(struct netlbl_lsm_secattr_catmap *catmap,
36302752760SPaul Moore 			       u32 offset);
36402752760SPaul Moore int netlbl_secattr_catmap_walk_rng(struct netlbl_lsm_secattr_catmap *catmap,
36502752760SPaul Moore 				   u32 offset);
36602752760SPaul Moore int netlbl_secattr_catmap_setbit(struct netlbl_lsm_secattr_catmap *catmap,
36702752760SPaul Moore 				 u32 bit,
36802752760SPaul Moore 				 gfp_t flags);
36902752760SPaul Moore int netlbl_secattr_catmap_setrng(struct netlbl_lsm_secattr_catmap *catmap,
37002752760SPaul Moore 				 u32 start,
37102752760SPaul Moore 				 u32 end,
37202752760SPaul Moore 				 gfp_t flags);
37323bcdc1aSPaul Moore 
37423bcdc1aSPaul Moore /*
37516efd454SPaul Moore  * LSM protocol operations (NetLabel LSM/kernel API)
37623bcdc1aSPaul Moore  */
37723bcdc1aSPaul Moore int netlbl_enabled(void);
37823bcdc1aSPaul Moore int netlbl_sock_setattr(struct sock *sk,
37923bcdc1aSPaul Moore 			const struct netlbl_lsm_secattr *secattr);
38023bcdc1aSPaul Moore int netlbl_sock_getattr(struct sock *sk,
38123bcdc1aSPaul Moore 			struct netlbl_lsm_secattr *secattr);
38223bcdc1aSPaul Moore int netlbl_skbuff_getattr(const struct sk_buff *skb,
38375e22910SPaul Moore 			  u16 family,
38423bcdc1aSPaul Moore 			  struct netlbl_lsm_secattr *secattr);
385*dfaebe98SPaul Moore void netlbl_skbuff_err(struct sk_buff *skb, int error, int gateway);
38623bcdc1aSPaul Moore 
38723bcdc1aSPaul Moore /*
38823bcdc1aSPaul Moore  * LSM label mapping cache operations
38923bcdc1aSPaul Moore  */
39023bcdc1aSPaul Moore void netlbl_cache_invalidate(void);
39123bcdc1aSPaul Moore int netlbl_cache_add(const struct sk_buff *skb,
39223bcdc1aSPaul Moore 		     const struct netlbl_lsm_secattr *secattr);
39302752760SPaul Moore #else
394eda61d32SPaul Moore static inline int netlbl_cfg_map_del(const char *domain,
395eda61d32SPaul Moore 				     struct netlbl_audit *audit_info)
396eda61d32SPaul Moore {
397eda61d32SPaul Moore 	return -ENOSYS;
398eda61d32SPaul Moore }
399eda61d32SPaul Moore static inline int netlbl_cfg_unlbl_add_map(const char *domain,
400eda61d32SPaul Moore 					   struct netlbl_audit *audit_info)
401eda61d32SPaul Moore {
402eda61d32SPaul Moore 	return -ENOSYS;
403eda61d32SPaul Moore }
404eda61d32SPaul Moore static inline int netlbl_cfg_cipsov4_add_map(struct cipso_v4_doi *doi_def,
405eda61d32SPaul Moore 					     const char *domain,
406eda61d32SPaul Moore 					     struct netlbl_audit *audit_info)
407eda61d32SPaul Moore {
408eda61d32SPaul Moore 	return -ENOSYS;
409eda61d32SPaul Moore }
41002752760SPaul Moore static inline int netlbl_secattr_catmap_walk(
41102752760SPaul Moore 	                              struct netlbl_lsm_secattr_catmap *catmap,
41202752760SPaul Moore 				      u32 offset)
41302752760SPaul Moore {
41402752760SPaul Moore 	return -ENOENT;
41502752760SPaul Moore }
41602752760SPaul Moore static inline int netlbl_secattr_catmap_walk_rng(
41702752760SPaul Moore 				      struct netlbl_lsm_secattr_catmap *catmap,
41802752760SPaul Moore 				      u32 offset)
41902752760SPaul Moore {
42002752760SPaul Moore 	return -ENOENT;
42102752760SPaul Moore }
42202752760SPaul Moore static inline int netlbl_secattr_catmap_setbit(
42302752760SPaul Moore 	                              struct netlbl_lsm_secattr_catmap *catmap,
42402752760SPaul Moore 				      u32 bit,
42502752760SPaul Moore 				      gfp_t flags)
42602752760SPaul Moore {
42702752760SPaul Moore 	return 0;
42802752760SPaul Moore }
42902752760SPaul Moore static inline int netlbl_secattr_catmap_setrng(
43002752760SPaul Moore 	                              struct netlbl_lsm_secattr_catmap *catmap,
43102752760SPaul Moore 				      u32 start,
43202752760SPaul Moore 				      u32 end,
43302752760SPaul Moore 				      gfp_t flags)
43402752760SPaul Moore {
43502752760SPaul Moore 	return 0;
43602752760SPaul Moore }
43723bcdc1aSPaul Moore static inline int netlbl_enabled(void)
43823bcdc1aSPaul Moore {
43923bcdc1aSPaul Moore 	return 0;
44023bcdc1aSPaul Moore }
441ba6ff9f2SPaul Moore static inline int netlbl_sock_setattr(struct sock *sk,
44211a03f78SPaul Moore 				     const struct netlbl_lsm_secattr *secattr)
44311a03f78SPaul Moore {
44411a03f78SPaul Moore 	return -ENOSYS;
44511a03f78SPaul Moore }
44614a72f53SPaul Moore static inline int netlbl_sock_getattr(struct sock *sk,
44714a72f53SPaul Moore 				      struct netlbl_lsm_secattr *secattr)
44814a72f53SPaul Moore {
44914a72f53SPaul Moore 	return -ENOSYS;
45014a72f53SPaul Moore }
45111a03f78SPaul Moore static inline int netlbl_skbuff_getattr(const struct sk_buff *skb,
45275e22910SPaul Moore 					u16 family,
45311a03f78SPaul Moore 					struct netlbl_lsm_secattr *secattr)
45411a03f78SPaul Moore {
45511a03f78SPaul Moore 	return -ENOSYS;
45611a03f78SPaul Moore }
457*dfaebe98SPaul Moore static inline void netlbl_skbuff_err(struct sk_buff *skb,
458*dfaebe98SPaul Moore 				     int error,
459*dfaebe98SPaul Moore 				     int gateway)
46011a03f78SPaul Moore {
46111a03f78SPaul Moore 	return;
46211a03f78SPaul Moore }
46311a03f78SPaul Moore static inline void netlbl_cache_invalidate(void)
46411a03f78SPaul Moore {
46511a03f78SPaul Moore 	return;
46611a03f78SPaul Moore }
46711a03f78SPaul Moore static inline int netlbl_cache_add(const struct sk_buff *skb,
46811a03f78SPaul Moore 				   const struct netlbl_lsm_secattr *secattr)
46911a03f78SPaul Moore {
47011a03f78SPaul Moore 	return 0;
47111a03f78SPaul Moore }
47211a03f78SPaul Moore #endif /* CONFIG_NETLABEL */
47311a03f78SPaul Moore 
47411a03f78SPaul Moore #endif /* _NETLABEL_H */
475