Commit b64397e0 authored by Paul Moore's avatar Paul Moore Committed by James Morris

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: default avatarPaul Moore <paul.moore@hp.com>
Signed-off-by: default avatarJames Morris <jmorris@namei.org>
parent c783f1ce
...@@ -109,17 +109,14 @@ static u32 netlbl_domhsh_hash(const char *key) ...@@ -109,17 +109,14 @@ static u32 netlbl_domhsh_hash(const char *key)
/** /**
* netlbl_domhsh_search - Search for a domain entry * netlbl_domhsh_search - Search for a domain entry
* @domain: the domain * @domain: the domain
* @def: return default if no match is found
* *
* Description: * Description:
* Searches the domain hash table and returns a pointer to the hash table * Searches the domain hash table and returns a pointer to the hash table
* entry if found, otherwise NULL is returned. If @def is non-zero and a * entry if found, otherwise NULL is returned. The caller is responsibile for
* match is not found in the domain hash table the default mapping is returned * the rcu hash table locks (i.e. the caller much call rcu_read_[un]lock()).
* if it exists. The caller is responsibile for the rcu hash table locks
* (i.e. the caller much call rcu_read_[un]lock()).
* *
*/ */
static struct netlbl_dom_map *netlbl_domhsh_search(const char *domain, u32 def) static struct netlbl_dom_map *netlbl_domhsh_search(const char *domain)
{ {
u32 bkt; u32 bkt;
struct netlbl_dom_map *iter; struct netlbl_dom_map *iter;
...@@ -133,10 +130,31 @@ static struct netlbl_dom_map *netlbl_domhsh_search(const char *domain, u32 def) ...@@ -133,10 +130,31 @@ static struct netlbl_dom_map *netlbl_domhsh_search(const char *domain, u32 def)
return iter; return iter;
} }
if (def != 0) { return NULL;
iter = rcu_dereference(netlbl_domhsh_def); }
if (iter != NULL && iter->valid)
return iter; /**
* netlbl_domhsh_search_def - Search for a domain entry
* @domain: the domain
* @def: return default if no match is found
*
* Description:
* Searches the domain hash table and returns a pointer to the hash table
* entry if an exact match is found, if an exact match is not present in the
* hash table then the default entry is returned if valid otherwise NULL is
* returned. The caller is responsibile for the rcu hash table locks
* (i.e. the caller much call rcu_read_[un]lock()).
*
*/
static struct netlbl_dom_map *netlbl_domhsh_search_def(const char *domain)
{
struct netlbl_dom_map *entry;
entry = netlbl_domhsh_search(domain);
if (entry == NULL) {
entry = rcu_dereference(netlbl_domhsh_def);
if (entry != NULL && entry->valid)
return entry;
} }
return NULL; return NULL;
...@@ -224,7 +242,7 @@ int netlbl_domhsh_add(struct netlbl_dom_map *entry, ...@@ -224,7 +242,7 @@ int netlbl_domhsh_add(struct netlbl_dom_map *entry,
if (entry->domain != NULL) { if (entry->domain != NULL) {
bkt = netlbl_domhsh_hash(entry->domain); bkt = netlbl_domhsh_hash(entry->domain);
spin_lock(&netlbl_domhsh_lock); spin_lock(&netlbl_domhsh_lock);
if (netlbl_domhsh_search(entry->domain, 0) == NULL) if (netlbl_domhsh_search(entry->domain) == NULL)
list_add_tail_rcu(&entry->list, list_add_tail_rcu(&entry->list,
&rcu_dereference(netlbl_domhsh)->tbl[bkt]); &rcu_dereference(netlbl_domhsh)->tbl[bkt]);
else else
...@@ -307,7 +325,10 @@ int netlbl_domhsh_remove(const char *domain, struct netlbl_audit *audit_info) ...@@ -307,7 +325,10 @@ int netlbl_domhsh_remove(const char *domain, struct netlbl_audit *audit_info)
struct audit_buffer *audit_buf; struct audit_buffer *audit_buf;
rcu_read_lock(); rcu_read_lock();
entry = netlbl_domhsh_search(domain, (domain != NULL ? 0 : 1)); if (domain)
entry = netlbl_domhsh_search(domain);
else
entry = netlbl_domhsh_search_def(domain);
if (entry == NULL) if (entry == NULL)
goto remove_return; goto remove_return;
switch (entry->type) { switch (entry->type) {
...@@ -377,7 +398,7 @@ int netlbl_domhsh_remove_default(struct netlbl_audit *audit_info) ...@@ -377,7 +398,7 @@ int netlbl_domhsh_remove_default(struct netlbl_audit *audit_info)
*/ */
struct netlbl_dom_map *netlbl_domhsh_getentry(const char *domain) struct netlbl_dom_map *netlbl_domhsh_getentry(const char *domain)
{ {
return netlbl_domhsh_search(domain, 1); return netlbl_domhsh_search_def(domain);
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment