aboutsummaryrefslogtreecommitdiffstats
path: root/net/netlabel
diff options
context:
space:
mode:
authorPaul Moore <paul.moore@hp.com>2008-01-29 08:37:54 -0500
committerJames Morris <jmorris@namei.org>2008-01-29 16:17:17 -0500
commitb64397e0b40e75b619aeef9a1fa21f79f801a3e8 (patch)
treecea93c3a06953ceb0e8876f699ff41be6c54207d /net/netlabel
parentc783f1ce5712530ba404807c55d77ac782eb8a7d (diff)
NetLabel: Cleanup the LSM domain hash functions
The NetLabel/LSM domain hash table search function used an argument to specify if the default entry should be returned if an exact match couldn't be found in the hash table. This is a bit against the kernel's style so make two separate functions to represent the separate behaviors. Signed-off-by: Paul Moore <paul.moore@hp.com> Signed-off-by: James Morris <jmorris@namei.org>
Diffstat (limited to 'net/netlabel')
-rw-r--r--net/netlabel/netlabel_domainhash.c47
1 files changed, 34 insertions, 13 deletions
diff --git a/net/netlabel/netlabel_domainhash.c b/net/netlabel/netlabel_domainhash.c
index b3675bd7db33..1f8f7ace790e 100644
--- a/net/netlabel/netlabel_domainhash.c
+++ b/net/netlabel/netlabel_domainhash.c
@@ -109,17 +109,14 @@ static u32 netlbl_domhsh_hash(const char *key)
109/** 109/**
110 * netlbl_domhsh_search - Search for a domain entry 110 * netlbl_domhsh_search - Search for a domain entry
111 * @domain: the domain 111 * @domain: the domain
112 * @def: return default if no match is found
113 * 112 *
114 * Description: 113 * Description:
115 * Searches the domain hash table and returns a pointer to the hash table 114 * Searches the domain hash table and returns a pointer to the hash table
116 * entry if found, otherwise NULL is returned. If @def is non-zero and a 115 * entry if found, otherwise NULL is returned. The caller is responsibile for
117 * match is not found in the domain hash table the default mapping is returned 116 * the rcu hash table locks (i.e. the caller much call rcu_read_[un]lock()).
118 * if it exists. The caller is responsibile for the rcu hash table locks
119 * (i.e. the caller much call rcu_read_[un]lock()).
120 * 117 *
121 */ 118 */
122static struct netlbl_dom_map *netlbl_domhsh_search(const char *domain, u32 def) 119static struct netlbl_dom_map *netlbl_domhsh_search(const char *domain)
123{ 120{
124 u32 bkt; 121 u32 bkt;
125 struct netlbl_dom_map *iter; 122 struct netlbl_dom_map *iter;
@@ -133,10 +130,31 @@ static struct netlbl_dom_map *netlbl_domhsh_search(const char *domain, u32 def)
133 return iter; 130 return iter;
134 } 131 }
135 132
136 if (def != 0) { 133 return NULL;
137 iter = rcu_dereference(netlbl_domhsh_def); 134}
138 if (iter != NULL && iter->valid) 135
139 return iter; 136/**
137 * netlbl_domhsh_search_def - Search for a domain entry
138 * @domain: the domain
139 * @def: return default if no match is found
140 *
141 * Description:
142 * Searches the domain hash table and returns a pointer to the hash table
143 * entry if an exact match is found, if an exact match is not present in the
144 * hash table then the default entry is returned if valid otherwise NULL is
145 * returned. The caller is responsibile for the rcu hash table locks
146 * (i.e. the caller much call rcu_read_[un]lock()).
147 *
148 */
149static struct netlbl_dom_map *netlbl_domhsh_search_def(const char *domain)
150{
151 struct netlbl_dom_map *entry;
152
153 entry = netlbl_domhsh_search(domain);
154 if (entry == NULL) {
155 entry = rcu_dereference(netlbl_domhsh_def);
156 if (entry != NULL && entry->valid)
157 return entry;
140 } 158 }
141 159
142 return NULL; 160 return NULL;
@@ -224,7 +242,7 @@ int netlbl_domhsh_add(struct netlbl_dom_map *entry,
224 if (entry->domain != NULL) { 242 if (entry->domain != NULL) {
225 bkt = netlbl_domhsh_hash(entry->domain); 243 bkt = netlbl_domhsh_hash(entry->domain);
226 spin_lock(&netlbl_domhsh_lock); 244 spin_lock(&netlbl_domhsh_lock);
227 if (netlbl_domhsh_search(entry->domain, 0) == NULL) 245 if (netlbl_domhsh_search(entry->domain) == NULL)
228 list_add_tail_rcu(&entry->list, 246 list_add_tail_rcu(&entry->list,
229 &rcu_dereference(netlbl_domhsh)->tbl[bkt]); 247 &rcu_dereference(netlbl_domhsh)->tbl[bkt]);
230 else 248 else
@@ -307,7 +325,10 @@ int netlbl_domhsh_remove(const char *domain, struct netlbl_audit *audit_info)
307 struct audit_buffer *audit_buf; 325 struct audit_buffer *audit_buf;
308 326
309 rcu_read_lock(); 327 rcu_read_lock();
310 entry = netlbl_domhsh_search(domain, (domain != NULL ? 0 : 1)); 328 if (domain)
329 entry = netlbl_domhsh_search(domain);
330 else
331 entry = netlbl_domhsh_search_def(domain);
311 if (entry == NULL) 332 if (entry == NULL)
312 goto remove_return; 333 goto remove_return;
313 switch (entry->type) { 334 switch (entry->type) {
@@ -377,7 +398,7 @@ int netlbl_domhsh_remove_default(struct netlbl_audit *audit_info)
377 */ 398 */
378struct netlbl_dom_map *netlbl_domhsh_getentry(const char *domain) 399struct netlbl_dom_map *netlbl_domhsh_getentry(const char *domain)
379{ 400{
380 return netlbl_domhsh_search(domain, 1); 401 return netlbl_domhsh_search_def(domain);
381} 402}
382 403
383/** 404/**