GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / net / netlabel / netlabel_domainhash.c
blobc05fb696ae9245014bc6b24575d442a69495bf9a
1 /*
2 * NetLabel Domain Hash Table
4 * This file manages the domain hash table that NetLabel uses to determine
5 * which network labeling protocol to use for a given domain. The NetLabel
6 * system manages static and dynamic label mappings for network protocols such
7 * as CIPSO and RIPSO.
9 * Author: Paul Moore <paul.moore@hp.com>
14 * (c) Copyright Hewlett-Packard Development Company, L.P., 2006, 2008
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; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
24 * the GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include <linux/types.h>
33 #include <linux/rculist.h>
34 #include <linux/skbuff.h>
35 #include <linux/spinlock.h>
36 #include <linux/string.h>
37 #include <linux/audit.h>
38 #include <linux/slab.h>
39 #include <net/netlabel.h>
40 #include <net/cipso_ipv4.h>
41 #include <asm/bug.h>
43 #include "netlabel_mgmt.h"
44 #include "netlabel_addrlist.h"
45 #include "netlabel_domainhash.h"
46 #include "netlabel_user.h"
48 struct netlbl_domhsh_tbl {
49 struct list_head *tbl;
50 u32 size;
53 /* Domain hash table */
54 /* updates should be so rare that having one spinlock for the entire hash table
55 * should be okay */
56 static DEFINE_SPINLOCK(netlbl_domhsh_lock);
57 #define netlbl_domhsh_rcu_deref(p) \
58 rcu_dereference_check(p, rcu_read_lock_held() || \
59 lockdep_is_held(&netlbl_domhsh_lock))
60 static struct netlbl_domhsh_tbl *netlbl_domhsh = NULL;
61 static struct netlbl_dom_map *netlbl_domhsh_def = NULL;
64 * Domain Hash Table Helper Functions
67 /**
68 * netlbl_domhsh_free_entry - Frees a domain hash table entry
69 * @entry: the entry's RCU field
71 * Description:
72 * This function is designed to be used as a callback to the call_rcu()
73 * function so that the memory allocated to a hash table entry can be released
74 * safely.
77 static void netlbl_domhsh_free_entry(struct rcu_head *entry)
79 struct netlbl_dom_map *ptr;
80 struct netlbl_af4list *iter4;
81 struct netlbl_af4list *tmp4;
82 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
83 struct netlbl_af6list *iter6;
84 struct netlbl_af6list *tmp6;
85 #endif /* IPv6 */
87 ptr = container_of(entry, struct netlbl_dom_map, rcu);
88 if (ptr->type == NETLBL_NLTYPE_ADDRSELECT) {
89 netlbl_af4list_foreach_safe(iter4, tmp4,
90 &ptr->type_def.addrsel->list4) {
91 netlbl_af4list_remove_entry(iter4);
92 kfree(netlbl_domhsh_addr4_entry(iter4));
94 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
95 netlbl_af6list_foreach_safe(iter6, tmp6,
96 &ptr->type_def.addrsel->list6) {
97 netlbl_af6list_remove_entry(iter6);
98 kfree(netlbl_domhsh_addr6_entry(iter6));
100 #endif /* IPv6 */
102 kfree(ptr->domain);
103 kfree(ptr);
107 * netlbl_domhsh_hash - Hashing function for the domain hash table
108 * @domain: the domain name to hash
110 * Description:
111 * This is the hashing function for the domain hash table, it returns the
112 * correct bucket number for the domain. The caller is responsibile for
113 * ensuring that the hash table is protected with either a RCU read lock or the
114 * hash table lock.
117 static u32 netlbl_domhsh_hash(const char *key)
119 u32 iter;
120 u32 val;
121 u32 len;
123 /* This is taken (with slight modification) from
124 * security/selinux/ss/symtab.c:symhash() */
126 for (iter = 0, val = 0, len = strlen(key); iter < len; iter++)
127 val = (val << 4 | (val >> (8 * sizeof(u32) - 4))) ^ key[iter];
128 return val & (netlbl_domhsh_rcu_deref(netlbl_domhsh)->size - 1);
132 * netlbl_domhsh_search - Search for a domain entry
133 * @domain: the domain
135 * Description:
136 * Searches the domain hash table and returns a pointer to the hash table
137 * entry if found, otherwise NULL is returned. The caller is responsibile for
138 * ensuring that the hash table is protected with either a RCU read lock or the
139 * hash table lock.
142 static struct netlbl_dom_map *netlbl_domhsh_search(const char *domain)
144 u32 bkt;
145 struct list_head *bkt_list;
146 struct netlbl_dom_map *iter;
148 if (domain != NULL) {
149 bkt = netlbl_domhsh_hash(domain);
150 bkt_list = &netlbl_domhsh_rcu_deref(netlbl_domhsh)->tbl[bkt];
151 list_for_each_entry_rcu(iter, bkt_list, list)
152 if (iter->valid && strcmp(iter->domain, domain) == 0)
153 return iter;
156 return NULL;
160 * netlbl_domhsh_search_def - Search for a domain entry
161 * @domain: the domain
162 * @def: return default if no match is found
164 * Description:
165 * Searches the domain hash table and returns a pointer to the hash table
166 * entry if an exact match is found, if an exact match is not present in the
167 * hash table then the default entry is returned if valid otherwise NULL is
168 * returned. The caller is responsibile ensuring that the hash table is
169 * protected with either a RCU read lock or the hash table lock.
172 static struct netlbl_dom_map *netlbl_domhsh_search_def(const char *domain)
174 struct netlbl_dom_map *entry;
176 entry = netlbl_domhsh_search(domain);
177 if (entry == NULL) {
178 entry = netlbl_domhsh_rcu_deref(netlbl_domhsh_def);
179 if (entry != NULL && !entry->valid)
180 entry = NULL;
183 return entry;
187 * netlbl_domhsh_audit_add - Generate an audit entry for an add event
188 * @entry: the entry being added
189 * @addr4: the IPv4 address information
190 * @addr6: the IPv6 address information
191 * @result: the result code
192 * @audit_info: NetLabel audit information
194 * Description:
195 * Generate an audit record for adding a new NetLabel/LSM mapping entry with
196 * the given information. Caller is responsibile for holding the necessary
197 * locks.
200 static void netlbl_domhsh_audit_add(struct netlbl_dom_map *entry,
201 struct netlbl_af4list *addr4,
202 struct netlbl_af6list *addr6,
203 int result,
204 struct netlbl_audit *audit_info)
206 struct audit_buffer *audit_buf;
207 struct cipso_v4_doi *cipsov4 = NULL;
208 u32 type;
210 audit_buf = netlbl_audit_start_common(AUDIT_MAC_MAP_ADD, audit_info);
211 if (audit_buf != NULL) {
212 audit_log_format(audit_buf, " nlbl_domain=%s",
213 entry->domain ? entry->domain : "(default)");
214 if (addr4 != NULL) {
215 struct netlbl_domaddr4_map *map4;
216 map4 = netlbl_domhsh_addr4_entry(addr4);
217 type = map4->type;
218 cipsov4 = map4->type_def.cipsov4;
219 netlbl_af4list_audit_addr(audit_buf, 0, NULL,
220 addr4->addr, addr4->mask);
221 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
222 } else if (addr6 != NULL) {
223 struct netlbl_domaddr6_map *map6;
224 map6 = netlbl_domhsh_addr6_entry(addr6);
225 type = map6->type;
226 netlbl_af6list_audit_addr(audit_buf, 0, NULL,
227 &addr6->addr, &addr6->mask);
228 #endif /* IPv6 */
229 } else {
230 type = entry->type;
231 cipsov4 = entry->type_def.cipsov4;
233 switch (type) {
234 case NETLBL_NLTYPE_UNLABELED:
235 audit_log_format(audit_buf, " nlbl_protocol=unlbl");
236 break;
237 case NETLBL_NLTYPE_CIPSOV4:
238 BUG_ON(cipsov4 == NULL);
239 audit_log_format(audit_buf,
240 " nlbl_protocol=cipsov4 cipso_doi=%u",
241 cipsov4->doi);
242 break;
244 audit_log_format(audit_buf, " res=%u", result == 0 ? 1 : 0);
245 audit_log_end(audit_buf);
250 * Domain Hash Table Functions
254 * netlbl_domhsh_init - Init for the domain hash
255 * @size: the number of bits to use for the hash buckets
257 * Description:
258 * Initializes the domain hash table, should be called only by
259 * netlbl_user_init() during initialization. Returns zero on success, non-zero
260 * values on error.
263 int __init netlbl_domhsh_init(u32 size)
265 u32 iter;
266 struct netlbl_domhsh_tbl *hsh_tbl;
268 if (size == 0)
269 return -EINVAL;
271 hsh_tbl = kmalloc(sizeof(*hsh_tbl), GFP_KERNEL);
272 if (hsh_tbl == NULL)
273 return -ENOMEM;
274 hsh_tbl->size = 1 << size;
275 hsh_tbl->tbl = kcalloc(hsh_tbl->size,
276 sizeof(struct list_head),
277 GFP_KERNEL);
278 if (hsh_tbl->tbl == NULL) {
279 kfree(hsh_tbl);
280 return -ENOMEM;
282 for (iter = 0; iter < hsh_tbl->size; iter++)
283 INIT_LIST_HEAD(&hsh_tbl->tbl[iter]);
285 spin_lock(&netlbl_domhsh_lock);
286 rcu_assign_pointer(netlbl_domhsh, hsh_tbl);
287 spin_unlock(&netlbl_domhsh_lock);
289 return 0;
293 * netlbl_domhsh_add - Adds a entry to the domain hash table
294 * @entry: the entry to add
295 * @audit_info: NetLabel audit information
297 * Description:
298 * Adds a new entry to the domain hash table and handles any updates to the
299 * lower level protocol handler (i.e. CIPSO). Returns zero on success,
300 * negative on failure.
303 int netlbl_domhsh_add(struct netlbl_dom_map *entry,
304 struct netlbl_audit *audit_info)
306 int ret_val = 0;
307 struct netlbl_dom_map *entry_old;
308 struct netlbl_af4list *iter4;
309 struct netlbl_af4list *tmp4;
310 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
311 struct netlbl_af6list *iter6;
312 struct netlbl_af6list *tmp6;
313 #endif /* IPv6 */
315 rcu_read_lock();
316 spin_lock(&netlbl_domhsh_lock);
317 if (entry->domain != NULL)
318 entry_old = netlbl_domhsh_search(entry->domain);
319 else
320 entry_old = netlbl_domhsh_search_def(entry->domain);
321 if (entry_old == NULL) {
322 entry->valid = 1;
324 if (entry->domain != NULL) {
325 u32 bkt = netlbl_domhsh_hash(entry->domain);
326 list_add_tail_rcu(&entry->list,
327 &rcu_dereference(netlbl_domhsh)->tbl[bkt]);
328 } else {
329 INIT_LIST_HEAD(&entry->list);
330 rcu_assign_pointer(netlbl_domhsh_def, entry);
333 if (entry->type == NETLBL_NLTYPE_ADDRSELECT) {
334 netlbl_af4list_foreach_rcu(iter4,
335 &entry->type_def.addrsel->list4)
336 netlbl_domhsh_audit_add(entry, iter4, NULL,
337 ret_val, audit_info);
338 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
339 netlbl_af6list_foreach_rcu(iter6,
340 &entry->type_def.addrsel->list6)
341 netlbl_domhsh_audit_add(entry, NULL, iter6,
342 ret_val, audit_info);
343 #endif /* IPv6 */
344 } else
345 netlbl_domhsh_audit_add(entry, NULL, NULL,
346 ret_val, audit_info);
347 } else if (entry_old->type == NETLBL_NLTYPE_ADDRSELECT &&
348 entry->type == NETLBL_NLTYPE_ADDRSELECT) {
349 struct list_head *old_list4;
350 struct list_head *old_list6;
352 old_list4 = &entry_old->type_def.addrsel->list4;
353 old_list6 = &entry_old->type_def.addrsel->list6;
355 /* we only allow the addition of address selectors if all of
356 * the selectors do not exist in the existing domain map */
357 netlbl_af4list_foreach_rcu(iter4,
358 &entry->type_def.addrsel->list4)
359 if (netlbl_af4list_search_exact(iter4->addr,
360 iter4->mask,
361 old_list4)) {
362 ret_val = -EEXIST;
363 goto add_return;
365 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
366 netlbl_af6list_foreach_rcu(iter6,
367 &entry->type_def.addrsel->list6)
368 if (netlbl_af6list_search_exact(&iter6->addr,
369 &iter6->mask,
370 old_list6)) {
371 ret_val = -EEXIST;
372 goto add_return;
374 #endif /* IPv6 */
376 netlbl_af4list_foreach_safe(iter4, tmp4,
377 &entry->type_def.addrsel->list4) {
378 netlbl_af4list_remove_entry(iter4);
379 iter4->valid = 1;
380 ret_val = netlbl_af4list_add(iter4, old_list4);
381 netlbl_domhsh_audit_add(entry_old, iter4, NULL,
382 ret_val, audit_info);
383 if (ret_val != 0)
384 goto add_return;
386 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
387 netlbl_af6list_foreach_safe(iter6, tmp6,
388 &entry->type_def.addrsel->list6) {
389 netlbl_af6list_remove_entry(iter6);
390 iter6->valid = 1;
391 ret_val = netlbl_af6list_add(iter6, old_list6);
392 netlbl_domhsh_audit_add(entry_old, NULL, iter6,
393 ret_val, audit_info);
394 if (ret_val != 0)
395 goto add_return;
397 #endif /* IPv6 */
398 } else
399 ret_val = -EINVAL;
401 add_return:
402 spin_unlock(&netlbl_domhsh_lock);
403 rcu_read_unlock();
404 return ret_val;
408 * netlbl_domhsh_add_default - Adds the default entry to the domain hash table
409 * @entry: the entry to add
410 * @audit_info: NetLabel audit information
412 * Description:
413 * Adds a new default entry to the domain hash table and handles any updates
414 * to the lower level protocol handler (i.e. CIPSO). Returns zero on success,
415 * negative on failure.
418 int netlbl_domhsh_add_default(struct netlbl_dom_map *entry,
419 struct netlbl_audit *audit_info)
421 return netlbl_domhsh_add(entry, audit_info);
425 * netlbl_domhsh_remove_entry - Removes a given entry from the domain table
426 * @entry: the entry to remove
427 * @audit_info: NetLabel audit information
429 * Description:
430 * Removes an entry from the domain hash table and handles any updates to the
431 * lower level protocol handler (i.e. CIPSO). Caller is responsible for
432 * ensuring that the RCU read lock is held. Returns zero on success, negative
433 * on failure.
436 int netlbl_domhsh_remove_entry(struct netlbl_dom_map *entry,
437 struct netlbl_audit *audit_info)
439 int ret_val = 0;
440 struct audit_buffer *audit_buf;
442 if (entry == NULL)
443 return -ENOENT;
445 spin_lock(&netlbl_domhsh_lock);
446 if (entry->valid) {
447 entry->valid = 0;
448 if (entry != rcu_dereference(netlbl_domhsh_def))
449 list_del_rcu(&entry->list);
450 else
451 rcu_assign_pointer(netlbl_domhsh_def, NULL);
452 } else
453 ret_val = -ENOENT;
454 spin_unlock(&netlbl_domhsh_lock);
456 audit_buf = netlbl_audit_start_common(AUDIT_MAC_MAP_DEL, audit_info);
457 if (audit_buf != NULL) {
458 audit_log_format(audit_buf,
459 " nlbl_domain=%s res=%u",
460 entry->domain ? entry->domain : "(default)",
461 ret_val == 0 ? 1 : 0);
462 audit_log_end(audit_buf);
465 if (ret_val == 0) {
466 struct netlbl_af4list *iter4;
467 struct netlbl_domaddr4_map *map4;
469 switch (entry->type) {
470 case NETLBL_NLTYPE_ADDRSELECT:
471 netlbl_af4list_foreach_rcu(iter4,
472 &entry->type_def.addrsel->list4) {
473 map4 = netlbl_domhsh_addr4_entry(iter4);
474 cipso_v4_doi_putdef(map4->type_def.cipsov4);
476 /* no need to check the IPv6 list since we currently
477 * support only unlabeled protocols for IPv6 */
478 break;
479 case NETLBL_NLTYPE_CIPSOV4:
480 cipso_v4_doi_putdef(entry->type_def.cipsov4);
481 break;
483 call_rcu(&entry->rcu, netlbl_domhsh_free_entry);
486 return ret_val;
490 * netlbl_domhsh_remove_af4 - Removes an address selector entry
491 * @domain: the domain
492 * @addr: IPv4 address
493 * @mask: IPv4 address mask
494 * @audit_info: NetLabel audit information
496 * Description:
497 * Removes an individual address selector from a domain mapping and potentially
498 * the entire mapping if it is empty. Returns zero on success, negative values
499 * on failure.
502 int netlbl_domhsh_remove_af4(const char *domain,
503 const struct in_addr *addr,
504 const struct in_addr *mask,
505 struct netlbl_audit *audit_info)
507 struct netlbl_dom_map *entry_map;
508 struct netlbl_af4list *entry_addr;
509 struct netlbl_af4list *iter4;
510 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
511 struct netlbl_af6list *iter6;
512 #endif /* IPv6 */
513 struct netlbl_domaddr4_map *entry;
515 rcu_read_lock();
517 if (domain)
518 entry_map = netlbl_domhsh_search(domain);
519 else
520 entry_map = netlbl_domhsh_search_def(domain);
521 if (entry_map == NULL || entry_map->type != NETLBL_NLTYPE_ADDRSELECT)
522 goto remove_af4_failure;
524 spin_lock(&netlbl_domhsh_lock);
525 entry_addr = netlbl_af4list_remove(addr->s_addr, mask->s_addr,
526 &entry_map->type_def.addrsel->list4);
527 spin_unlock(&netlbl_domhsh_lock);
529 if (entry_addr == NULL)
530 goto remove_af4_failure;
531 netlbl_af4list_foreach_rcu(iter4, &entry_map->type_def.addrsel->list4)
532 goto remove_af4_single_addr;
533 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
534 netlbl_af6list_foreach_rcu(iter6, &entry_map->type_def.addrsel->list6)
535 goto remove_af4_single_addr;
536 #endif /* IPv6 */
537 /* the domain mapping is empty so remove it from the mapping table */
538 netlbl_domhsh_remove_entry(entry_map, audit_info);
540 remove_af4_single_addr:
541 rcu_read_unlock();
542 /* yick, we can't use call_rcu here because we don't have a rcu head
543 * pointer but hopefully this should be a rare case so the pause
544 * shouldn't be a problem */
545 synchronize_rcu();
546 entry = netlbl_domhsh_addr4_entry(entry_addr);
547 cipso_v4_doi_putdef(entry->type_def.cipsov4);
548 kfree(entry);
549 return 0;
551 remove_af4_failure:
552 rcu_read_unlock();
553 return -ENOENT;
557 * netlbl_domhsh_remove - Removes an entry from the domain hash table
558 * @domain: the domain to remove
559 * @audit_info: NetLabel audit information
561 * Description:
562 * Removes an entry from the domain hash table and handles any updates to the
563 * lower level protocol handler (i.e. CIPSO). Returns zero on success,
564 * negative on failure.
567 int netlbl_domhsh_remove(const char *domain, struct netlbl_audit *audit_info)
569 int ret_val;
570 struct netlbl_dom_map *entry;
572 rcu_read_lock();
573 if (domain)
574 entry = netlbl_domhsh_search(domain);
575 else
576 entry = netlbl_domhsh_search_def(domain);
577 ret_val = netlbl_domhsh_remove_entry(entry, audit_info);
578 rcu_read_unlock();
580 return ret_val;
584 * netlbl_domhsh_remove_default - Removes the default entry from the table
585 * @audit_info: NetLabel audit information
587 * Description:
588 * Removes/resets the default entry for the domain hash table and handles any
589 * updates to the lower level protocol handler (i.e. CIPSO). Returns zero on
590 * success, non-zero on failure.
593 int netlbl_domhsh_remove_default(struct netlbl_audit *audit_info)
595 return netlbl_domhsh_remove(NULL, audit_info);
599 * netlbl_domhsh_getentry - Get an entry from the domain hash table
600 * @domain: the domain name to search for
602 * Description:
603 * Look through the domain hash table searching for an entry to match @domain,
604 * return a pointer to a copy of the entry or NULL. The caller is responsibile
605 * for ensuring that rcu_read_[un]lock() is called.
608 struct netlbl_dom_map *netlbl_domhsh_getentry(const char *domain)
610 return netlbl_domhsh_search_def(domain);
614 * netlbl_domhsh_getentry_af4 - Get an entry from the domain hash table
615 * @domain: the domain name to search for
616 * @addr: the IP address to search for
618 * Description:
619 * Look through the domain hash table searching for an entry to match @domain
620 * and @addr, return a pointer to a copy of the entry or NULL. The caller is
621 * responsible for ensuring that rcu_read_[un]lock() is called.
624 struct netlbl_domaddr4_map *netlbl_domhsh_getentry_af4(const char *domain,
625 __be32 addr)
627 struct netlbl_dom_map *dom_iter;
628 struct netlbl_af4list *addr_iter;
630 dom_iter = netlbl_domhsh_search_def(domain);
631 if (dom_iter == NULL)
632 return NULL;
633 if (dom_iter->type != NETLBL_NLTYPE_ADDRSELECT)
634 return NULL;
636 addr_iter = netlbl_af4list_search(addr,
637 &dom_iter->type_def.addrsel->list4);
638 if (addr_iter == NULL)
639 return NULL;
641 return netlbl_domhsh_addr4_entry(addr_iter);
644 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
646 * netlbl_domhsh_getentry_af6 - Get an entry from the domain hash table
647 * @domain: the domain name to search for
648 * @addr: the IP address to search for
650 * Description:
651 * Look through the domain hash table searching for an entry to match @domain
652 * and @addr, return a pointer to a copy of the entry or NULL. The caller is
653 * responsible for ensuring that rcu_read_[un]lock() is called.
656 struct netlbl_domaddr6_map *netlbl_domhsh_getentry_af6(const char *domain,
657 const struct in6_addr *addr)
659 struct netlbl_dom_map *dom_iter;
660 struct netlbl_af6list *addr_iter;
662 dom_iter = netlbl_domhsh_search_def(domain);
663 if (dom_iter == NULL)
664 return NULL;
665 if (dom_iter->type != NETLBL_NLTYPE_ADDRSELECT)
666 return NULL;
668 addr_iter = netlbl_af6list_search(addr,
669 &dom_iter->type_def.addrsel->list6);
670 if (addr_iter == NULL)
671 return NULL;
673 return netlbl_domhsh_addr6_entry(addr_iter);
675 #endif /* IPv6 */
678 * netlbl_domhsh_walk - Iterate through the domain mapping hash table
679 * @skip_bkt: the number of buckets to skip at the start
680 * @skip_chain: the number of entries to skip in the first iterated bucket
681 * @callback: callback for each entry
682 * @cb_arg: argument for the callback function
684 * Description:
685 * Interate over the domain mapping hash table, skipping the first @skip_bkt
686 * buckets and @skip_chain entries. For each entry in the table call
687 * @callback, if @callback returns a negative value stop 'walking' through the
688 * table and return. Updates the values in @skip_bkt and @skip_chain on
689 * return. Returns zero on success, negative values on failure.
692 int netlbl_domhsh_walk(u32 *skip_bkt,
693 u32 *skip_chain,
694 int (*callback) (struct netlbl_dom_map *entry, void *arg),
695 void *cb_arg)
697 int ret_val = -ENOENT;
698 u32 iter_bkt;
699 struct list_head *iter_list;
700 struct netlbl_dom_map *iter_entry;
701 u32 chain_cnt = 0;
703 rcu_read_lock();
704 for (iter_bkt = *skip_bkt;
705 iter_bkt < rcu_dereference(netlbl_domhsh)->size;
706 iter_bkt++, chain_cnt = 0) {
707 iter_list = &rcu_dereference(netlbl_domhsh)->tbl[iter_bkt];
708 list_for_each_entry_rcu(iter_entry, iter_list, list)
709 if (iter_entry->valid) {
710 if (chain_cnt++ < *skip_chain)
711 continue;
712 ret_val = callback(iter_entry, cb_arg);
713 if (ret_val < 0) {
714 chain_cnt--;
715 goto walk_return;
720 walk_return:
721 rcu_read_unlock();
722 *skip_bkt = iter_bkt;
723 *skip_chain = chain_cnt;
724 return ret_val;