/*
 *  Elbrus MAC Kernel (elmac) security module
 *
 *	This program is free software; you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License version 2,
 *      as published by the Free Software Foundation.
 */

#ifndef _LINUX_ELMAC_H
#define _LINUX_ELMAC_H

#include <linux/capability.h>

#ifndef PACKED
#define EL_PACKED __attribute__((aligned(1), packed))
#else
#define EL_PACKED PACKED
#endif

/*
 * el_mac label
 */
typedef struct _el_mac_label {
        __u8	level;
        __u64	category;
} EL_PACKED elmac_label_t;

/*
 * el_mac context
 */
typedef struct _el_mac_context {
        __u32		attr;
        elmac_label_t	mac;
} EL_PACKED elmac_context_t;


#define ELMAC_LABEL_LEV(label)		((label).level)
#define ELMAC_LABEL_LCAT(label)		((label).category)
#define ELMAC_CONTEXT_LEV(context)	((context).mac.level)
#define ELMAC_CONTEXT_CAT(context)	((context).mac.category)
#define ELMAC_CONTEXT_ATTR(context)	((context).attr)
#define ELMAC_CONTEXT_ATTR_CHECK(context, a) \
					((context).attr & ELMAC_ATTR_##a)

#define ELMAC_ATTR_IGNORER_CAT 0x00000001
#define ELMAC_ATTR_IGNOREW_CAT 0x00000002
#define ELMAC_ATTR_IGNOREX_CAT 0x00000004
#define ELMAC_ATTR_IGNORER_LVL 0x00000008
#define ELMAC_ATTR_IGNOREW_LVL 0x00000010
#define ELMAC_ATTR_IGNOREX_LVL 0x00000020

#define ELMAC_ATTR_IGNORER	((ELMAC_ATTR_IGNORER_CAT) | \
				(ELMAC_ATTR_IGNORER_LVL))
#define ELMAC_ATTR_IGNOREW	((ELMAC_ATTR_IGNOREW_CAT) | \
				(ELMAC_ATTR_IGNOREW_LVL))
#define ELMAC_ATTR_IGNOREX	((ELMAC_ATTR_IGNOREX_CAT) | \
				(ELMAC_ATTR_IGNOREX_LVL))
#define ELMAC_ATTR_IGNORE	((ELMAC_ATTR_IGNORER) | (ELMAC_ATTR_IGNOREW) | \
				(ELMAC_ATTR_IGNOREX))

#define ELMAC_MAX_LEVEL		255
#define ELMAC_MAX_CATEGORY	((__u64)(-1))

#define ELMAC_LABEL_MAXLEN	sizeof(elmac_label_t)
#define ELMAC_LABEL_STRLEN	(ELMAC_LABEL_MAXLEN + 1)
#define ELMAC_CONTEXT_MAXLEN	sizeof(elmac_context_t)
#define ELMAC_CONTEXT_STRLEN	(ELMAC_CONTEXT_MAXLEN + 1)
/*
 * xattr names
 */
#ifndef	XATTR_SECURITY_PREFIX
#define XATTR_SECURITY_PREFIX	"security."
#endif
#define XATTR_ELMAC_SUFFIX	"ELMAC64"
#define XATTR_ELMAC_IPIN	"ELMAC64IPIN"
#define XATTR_ELMAC_IPOUT	"ELMAC64IPOUT"
#define XATTR_NAME_ELMAC	XATTR_SECURITY_PREFIX XATTR_ELMAC_SUFFIX
#define XATTR_NAME_ELMAC_IPIN	XATTR_SECURITY_PREFIX XATTR_ELMAC_IPIN
#define XATTR_NAME_ELMAC_IPOUT	XATTR_SECURITY_PREFIX XATTR_ELMAC_IPOUT

#define ELMAC_IPSO_OPTION 	"-IPSO"

#endif	/* _LINUX_ELMAC_H */
