]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - security/selinux/ss/avtab.h
selinux: convert avtab hash table to flex_array
[mirror_ubuntu-bionic-kernel.git] / security / selinux / ss / avtab.h
CommitLineData
1da177e4
LT
1/*
2 * An access vector table (avtab) is a hash table
3 * of access vectors and transition types indexed
4 * by a type pair and a class. An access vector
5 * table is used to represent the type enforcement
6 * tables.
7 *
8 * Author : Stephen Smalley, <sds@epoch.ncsc.mil>
9 */
10
11/* Updated: Frank Mayer <mayerf@tresys.com> and Karl MacMillan <kmacmillan@tresys.com>
12 *
13 * Added conditional policy language extensions
14 *
15 * Copyright (C) 2003 Tresys Technology, LLC
16 * This program is free software; you can redistribute it and/or modify
652bb9b0 17 * it under the terms of the GNU General Public License as published by
1da177e4 18 * the Free Software Foundation, version 2.
3232c110
YN
19 *
20 * Updated: Yuichi Nakamura <ynakam@hitachisoft.jp>
21 * Tuned number of hash slots for avtab to reduce memory usage
1da177e4
LT
22 */
23#ifndef _SS_AVTAB_H_
24#define _SS_AVTAB_H_
25
ba39db6e
SS
26#include <linux/flex_array.h>
27
1da177e4 28struct avtab_key {
782ebb99
SS
29 u16 source_type; /* source type */
30 u16 target_type; /* target type */
31 u16 target_class; /* target object class */
652bb9b0
EP
32#define AVTAB_ALLOWED 0x0001
33#define AVTAB_AUDITALLOW 0x0002
34#define AVTAB_AUDITDENY 0x0004
35#define AVTAB_AV (AVTAB_ALLOWED | AVTAB_AUDITALLOW | AVTAB_AUDITDENY)
36#define AVTAB_TRANSITION 0x0010
37#define AVTAB_MEMBER 0x0020
38#define AVTAB_CHANGE 0x0040
39#define AVTAB_TYPE (AVTAB_TRANSITION | AVTAB_MEMBER | AVTAB_CHANGE)
40#define AVTAB_ENABLED_OLD 0x80000000 /* reserved for used in cond_avtab */
41#define AVTAB_ENABLED 0x8000 /* reserved for used in cond_avtab */
782ebb99
SS
42 u16 specified; /* what field is specified */
43};
44
45struct avtab_datum {
46 u32 data; /* access vector or type value */
1da177e4
LT
47};
48
49struct avtab_node {
50 struct avtab_key key;
51 struct avtab_datum datum;
52 struct avtab_node *next;
53};
54
55struct avtab {
ba39db6e 56 struct flex_array *htable;
1da177e4 57 u32 nel; /* number of elements */
3232c110
YN
58 u32 nslot; /* number of hash slots */
59 u16 mask; /* mask to compute hash func */
60
1da177e4
LT
61};
62
63int avtab_init(struct avtab *);
3232c110 64int avtab_alloc(struct avtab *, u32);
782ebb99 65struct avtab_datum *avtab_search(struct avtab *h, struct avtab_key *k);
1da177e4
LT
66void avtab_destroy(struct avtab *h);
67void avtab_hash_eval(struct avtab *h, char *tag);
68
45e5421e
SS
69struct policydb;
70int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol,
782ebb99
SS
71 int (*insert)(struct avtab *a, struct avtab_key *k,
72 struct avtab_datum *d, void *p),
73 void *p);
74
45e5421e 75int avtab_read(struct avtab *a, void *fp, struct policydb *pol);
cee74f47
EP
76int avtab_write_item(struct policydb *p, struct avtab_node *cur, void *fp);
77int avtab_write(struct policydb *p, struct avtab *a, void *fp);
1da177e4
LT
78
79struct avtab_node *avtab_insert_nonunique(struct avtab *h, struct avtab_key *key,
80 struct avtab_datum *datum);
81
782ebb99 82struct avtab_node *avtab_search_node(struct avtab *h, struct avtab_key *key);
1da177e4
LT
83
84struct avtab_node *avtab_search_node_next(struct avtab_node *node, int specified);
85
86void avtab_cache_init(void);
87void avtab_cache_destroy(void);
88
6c9ff101 89#define MAX_AVTAB_HASH_BITS 11
3232c110 90#define MAX_AVTAB_HASH_BUCKETS (1 << MAX_AVTAB_HASH_BITS)
1da177e4
LT
91
92#endif /* _SS_AVTAB_H_ */
93