Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
| 17 | * it under the terms of the GNU General Public License as published by |
| 18 | * the Free Software Foundation, version 2. |
Yuichi Nakamura | 3232c11 | 2007-08-24 11:55:11 +0900 | [diff] [blame] | 19 | * |
| 20 | * Updated: Yuichi Nakamura <ynakam@hitachisoft.jp> |
| 21 | * Tuned number of hash slots for avtab to reduce memory usage |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | */ |
| 23 | #ifndef _SS_AVTAB_H_ |
| 24 | #define _SS_AVTAB_H_ |
| 25 | |
| 26 | struct avtab_key { |
Stephen Smalley | 782ebb9 | 2005-09-03 15:55:16 -0700 | [diff] [blame] | 27 | u16 source_type; /* source type */ |
| 28 | u16 target_type; /* target type */ |
| 29 | u16 target_class; /* target object class */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #define AVTAB_ALLOWED 1 |
| 31 | #define AVTAB_AUDITALLOW 2 |
| 32 | #define AVTAB_AUDITDENY 4 |
| 33 | #define AVTAB_AV (AVTAB_ALLOWED | AVTAB_AUDITALLOW | AVTAB_AUDITDENY) |
| 34 | #define AVTAB_TRANSITION 16 |
| 35 | #define AVTAB_MEMBER 32 |
| 36 | #define AVTAB_CHANGE 64 |
| 37 | #define AVTAB_TYPE (AVTAB_TRANSITION | AVTAB_MEMBER | AVTAB_CHANGE) |
Stephen Smalley | 782ebb9 | 2005-09-03 15:55:16 -0700 | [diff] [blame] | 38 | #define AVTAB_ENABLED_OLD 0x80000000 /* reserved for used in cond_avtab */ |
| 39 | #define AVTAB_ENABLED 0x8000 /* reserved for used in cond_avtab */ |
| 40 | u16 specified; /* what field is specified */ |
| 41 | }; |
| 42 | |
| 43 | struct avtab_datum { |
| 44 | u32 data; /* access vector or type value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | struct avtab_node { |
| 48 | struct avtab_key key; |
| 49 | struct avtab_datum datum; |
| 50 | struct avtab_node *next; |
| 51 | }; |
| 52 | |
| 53 | struct avtab { |
| 54 | struct avtab_node **htable; |
| 55 | u32 nel; /* number of elements */ |
Yuichi Nakamura | 3232c11 | 2007-08-24 11:55:11 +0900 | [diff] [blame] | 56 | u32 nslot; /* number of hash slots */ |
| 57 | u16 mask; /* mask to compute hash func */ |
| 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | int avtab_init(struct avtab *); |
Yuichi Nakamura | 3232c11 | 2007-08-24 11:55:11 +0900 | [diff] [blame] | 62 | int avtab_alloc(struct avtab *, u32); |
Stephen Smalley | 782ebb9 | 2005-09-03 15:55:16 -0700 | [diff] [blame] | 63 | struct avtab_datum *avtab_search(struct avtab *h, struct avtab_key *k); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | void avtab_destroy(struct avtab *h); |
| 65 | void avtab_hash_eval(struct avtab *h, char *tag); |
| 66 | |
Stephen Smalley | 45e5421 | 2007-11-07 10:08:00 -0500 | [diff] [blame] | 67 | struct policydb; |
| 68 | int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol, |
Stephen Smalley | 782ebb9 | 2005-09-03 15:55:16 -0700 | [diff] [blame] | 69 | int (*insert)(struct avtab *a, struct avtab_key *k, |
| 70 | struct avtab_datum *d, void *p), |
| 71 | void *p); |
| 72 | |
Stephen Smalley | 45e5421 | 2007-11-07 10:08:00 -0500 | [diff] [blame] | 73 | int avtab_read(struct avtab *a, void *fp, struct policydb *pol); |
Eric Paris | cee74f4 | 2010-10-13 17:50:25 -0400 | [diff] [blame] | 74 | int avtab_write_item(struct policydb *p, struct avtab_node *cur, void *fp); |
| 75 | int avtab_write(struct policydb *p, struct avtab *a, void *fp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | struct avtab_node *avtab_insert_nonunique(struct avtab *h, struct avtab_key *key, |
| 78 | struct avtab_datum *datum); |
| 79 | |
Stephen Smalley | 782ebb9 | 2005-09-03 15:55:16 -0700 | [diff] [blame] | 80 | struct avtab_node *avtab_search_node(struct avtab *h, struct avtab_key *key); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
| 82 | struct avtab_node *avtab_search_node_next(struct avtab_node *node, int specified); |
| 83 | |
| 84 | void avtab_cache_init(void); |
| 85 | void avtab_cache_destroy(void); |
| 86 | |
Stephen Smalley | 6c9ff10 | 2010-03-15 10:42:11 -0400 | [diff] [blame] | 87 | #define MAX_AVTAB_HASH_BITS 11 |
Yuichi Nakamura | 3232c11 | 2007-08-24 11:55:11 +0900 | [diff] [blame] | 88 | #define MAX_AVTAB_HASH_BUCKETS (1 << MAX_AVTAB_HASH_BITS) |
| 89 | #define MAX_AVTAB_HASH_MASK (MAX_AVTAB_HASH_BUCKETS-1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
| 91 | #endif /* _SS_AVTAB_H_ */ |
| 92 | |