blob: 3b3b304ccd8bc89ae1dc8ab7ac0dfa34e3075c55 [file] [log] [blame]
Paul Moored15c3452006-08-03 16:48:37 -07001/*
2 * NetLabel Domain Hash Table
3 *
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.
8 *
Paul Moore82c21bf2011-08-01 11:10:33 +00009 * Author: Paul Moore <paul@paul-moore.com>
Paul Moored15c3452006-08-03 16:48:37 -070010 *
11 */
12
13/*
Paul Moore63c41682008-10-10 10:16:32 -040014 * (c) Copyright Hewlett-Packard Development Company, L.P., 2006, 2008
Paul Moored15c3452006-08-03 16:48:37 -070015 *
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.
20 *
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.
25 *
26 * You should have received a copy of the GNU General Public License
Jeff Kirsherd484ff12013-12-06 09:13:41 -080027 * along with this program; if not, see <http://www.gnu.org/licenses/>.
Paul Moored15c3452006-08-03 16:48:37 -070028 *
29 */
30
31#include <linux/types.h>
Franck Bui-Huu82524742008-05-12 21:21:05 +020032#include <linux/rculist.h>
Paul Moored15c3452006-08-03 16:48:37 -070033#include <linux/skbuff.h>
34#include <linux/spinlock.h>
35#include <linux/string.h>
Paul Moore32f50cd2006-09-28 14:51:47 -070036#include <linux/audit.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090037#include <linux/slab.h>
Paul Moored15c3452006-08-03 16:48:37 -070038#include <net/netlabel.h>
39#include <net/cipso_ipv4.h>
40#include <asm/bug.h>
41
42#include "netlabel_mgmt.h"
Paul Moore63c41682008-10-10 10:16:32 -040043#include "netlabel_addrlist.h"
Paul Moored15c3452006-08-03 16:48:37 -070044#include "netlabel_domainhash.h"
Paul Moore32f50cd2006-09-28 14:51:47 -070045#include "netlabel_user.h"
Paul Moored15c3452006-08-03 16:48:37 -070046
47struct netlbl_domhsh_tbl {
48 struct list_head *tbl;
49 u32 size;
50};
51
52/* Domain hash table */
Paul Mooreb914f3a2010-04-01 10:43:57 +000053/* updates should be so rare that having one spinlock for the entire hash table
54 * should be okay */
Adrian Bunk8ce11e62006-08-07 21:50:48 -070055static DEFINE_SPINLOCK(netlbl_domhsh_lock);
Paul Mooreb914f3a2010-04-01 10:43:57 +000056#define netlbl_domhsh_rcu_deref(p) \
Michal Hockod8bf4ca2011-07-08 14:39:41 +020057 rcu_dereference_check(p, lockdep_is_held(&netlbl_domhsh_lock))
Huw Davies96a8f7f2016-06-27 15:02:45 -040058static struct netlbl_domhsh_tbl __rcu *netlbl_domhsh;
Huw Davies8f18e672016-06-27 15:02:46 -040059static struct netlbl_dom_map __rcu *netlbl_domhsh_def_ipv4;
60static struct netlbl_dom_map __rcu *netlbl_domhsh_def_ipv6;
Paul Moored15c3452006-08-03 16:48:37 -070061
62/*
63 * Domain Hash Table Helper Functions
64 */
65
66/**
67 * netlbl_domhsh_free_entry - Frees a domain hash table entry
68 * @entry: the entry's RCU field
69 *
70 * Description:
71 * This function is designed to be used as a callback to the call_rcu()
72 * function so that the memory allocated to a hash table entry can be released
73 * safely.
74 *
75 */
76static void netlbl_domhsh_free_entry(struct rcu_head *entry)
77{
78 struct netlbl_dom_map *ptr;
Paul Moore63c41682008-10-10 10:16:32 -040079 struct netlbl_af4list *iter4;
80 struct netlbl_af4list *tmp4;
Eric Dumazetdfd56b82011-12-10 09:48:31 +000081#if IS_ENABLED(CONFIG_IPV6)
Paul Moore63c41682008-10-10 10:16:32 -040082 struct netlbl_af6list *iter6;
83 struct netlbl_af6list *tmp6;
84#endif /* IPv6 */
Paul Moored15c3452006-08-03 16:48:37 -070085
86 ptr = container_of(entry, struct netlbl_dom_map, rcu);
Paul Moore6a8b7f02013-08-02 14:45:08 -040087 if (ptr->def.type == NETLBL_NLTYPE_ADDRSELECT) {
Paul Moore63c41682008-10-10 10:16:32 -040088 netlbl_af4list_foreach_safe(iter4, tmp4,
Paul Moore6a8b7f02013-08-02 14:45:08 -040089 &ptr->def.addrsel->list4) {
Paul Moore63c41682008-10-10 10:16:32 -040090 netlbl_af4list_remove_entry(iter4);
91 kfree(netlbl_domhsh_addr4_entry(iter4));
92 }
Eric Dumazetdfd56b82011-12-10 09:48:31 +000093#if IS_ENABLED(CONFIG_IPV6)
Paul Moore63c41682008-10-10 10:16:32 -040094 netlbl_af6list_foreach_safe(iter6, tmp6,
Paul Moore6a8b7f02013-08-02 14:45:08 -040095 &ptr->def.addrsel->list6) {
Paul Moore63c41682008-10-10 10:16:32 -040096 netlbl_af6list_remove_entry(iter6);
97 kfree(netlbl_domhsh_addr6_entry(iter6));
98 }
99#endif /* IPv6 */
100 }
Paul Moored15c3452006-08-03 16:48:37 -0700101 kfree(ptr->domain);
102 kfree(ptr);
103}
104
105/**
106 * netlbl_domhsh_hash - Hashing function for the domain hash table
107 * @domain: the domain name to hash
108 *
109 * Description:
110 * This is the hashing function for the domain hash table, it returns the
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300111 * correct bucket number for the domain. The caller is responsible for
Paul Mooreb914f3a2010-04-01 10:43:57 +0000112 * ensuring that the hash table is protected with either a RCU read lock or the
113 * hash table lock.
Paul Moored15c3452006-08-03 16:48:37 -0700114 *
115 */
116static u32 netlbl_domhsh_hash(const char *key)
117{
118 u32 iter;
119 u32 val;
120 u32 len;
121
122 /* This is taken (with slight modification) from
123 * security/selinux/ss/symtab.c:symhash() */
124
125 for (iter = 0, val = 0, len = strlen(key); iter < len; iter++)
126 val = (val << 4 | (val >> (8 * sizeof(u32) - 4))) ^ key[iter];
Paul Mooreb914f3a2010-04-01 10:43:57 +0000127 return val & (netlbl_domhsh_rcu_deref(netlbl_domhsh)->size - 1);
Paul Moored15c3452006-08-03 16:48:37 -0700128}
129
Huw Davies8f18e672016-06-27 15:02:46 -0400130static bool netlbl_family_match(u16 f1, u16 f2)
131{
132 return (f1 == f2) || (f1 == AF_UNSPEC) || (f2 == AF_UNSPEC);
133}
134
Paul Moored15c3452006-08-03 16:48:37 -0700135/**
136 * netlbl_domhsh_search - Search for a domain entry
137 * @domain: the domain
Huw Davies8f18e672016-06-27 15:02:46 -0400138 * @family: the address family
Paul Moored15c3452006-08-03 16:48:37 -0700139 *
140 * Description:
141 * Searches the domain hash table and returns a pointer to the hash table
Huw Davies8f18e672016-06-27 15:02:46 -0400142 * entry if found, otherwise NULL is returned. @family may be %AF_UNSPEC
143 * which matches any address family entries. The caller is responsible for
Paul Mooreb914f3a2010-04-01 10:43:57 +0000144 * ensuring that the hash table is protected with either a RCU read lock or the
145 * hash table lock.
Paul Moored15c3452006-08-03 16:48:37 -0700146 *
147 */
Huw Davies8f18e672016-06-27 15:02:46 -0400148static struct netlbl_dom_map *netlbl_domhsh_search(const char *domain,
149 u16 family)
Paul Moored15c3452006-08-03 16:48:37 -0700150{
151 u32 bkt;
Paul Moore56196702008-10-10 10:16:29 -0400152 struct list_head *bkt_list;
Paul Moored15c3452006-08-03 16:48:37 -0700153 struct netlbl_dom_map *iter;
154
155 if (domain != NULL) {
156 bkt = netlbl_domhsh_hash(domain);
Paul Mooreb914f3a2010-04-01 10:43:57 +0000157 bkt_list = &netlbl_domhsh_rcu_deref(netlbl_domhsh)->tbl[bkt];
Paul Moore56196702008-10-10 10:16:29 -0400158 list_for_each_entry_rcu(iter, bkt_list, list)
Huw Davies8f18e672016-06-27 15:02:46 -0400159 if (iter->valid &&
160 netlbl_family_match(iter->family, family) &&
161 strcmp(iter->domain, domain) == 0)
Paul Moored15c3452006-08-03 16:48:37 -0700162 return iter;
163 }
164
Paul Mooreb64397e2008-01-29 08:37:54 -0500165 return NULL;
166}
167
168/**
169 * netlbl_domhsh_search_def - Search for a domain entry
170 * @domain: the domain
Huw Davies8f18e672016-06-27 15:02:46 -0400171 * @family: the address family
Paul Mooreb64397e2008-01-29 08:37:54 -0500172 *
173 * Description:
174 * Searches the domain hash table and returns a pointer to the hash table
175 * entry if an exact match is found, if an exact match is not present in the
176 * hash table then the default entry is returned if valid otherwise NULL is
Huw Davies8f18e672016-06-27 15:02:46 -0400177 * returned. @family may be %AF_UNSPEC which matches any address family
178 * entries. The caller is responsible ensuring that the hash table is
Paul Mooreb914f3a2010-04-01 10:43:57 +0000179 * protected with either a RCU read lock or the hash table lock.
Paul Mooreb64397e2008-01-29 08:37:54 -0500180 *
181 */
Huw Davies8f18e672016-06-27 15:02:46 -0400182static struct netlbl_dom_map *netlbl_domhsh_search_def(const char *domain,
183 u16 family)
Paul Mooreb64397e2008-01-29 08:37:54 -0500184{
185 struct netlbl_dom_map *entry;
186
Huw Davies8f18e672016-06-27 15:02:46 -0400187 entry = netlbl_domhsh_search(domain, family);
188 if (entry != NULL)
189 return entry;
190 if (family == AF_INET || family == AF_UNSPEC) {
191 entry = netlbl_domhsh_rcu_deref(netlbl_domhsh_def_ipv4);
192 if (entry != NULL && entry->valid)
193 return entry;
194 }
195 if (family == AF_INET6 || family == AF_UNSPEC) {
196 entry = netlbl_domhsh_rcu_deref(netlbl_domhsh_def_ipv6);
197 if (entry != NULL && entry->valid)
198 return entry;
Paul Moored15c3452006-08-03 16:48:37 -0700199 }
200
Huw Davies8f18e672016-06-27 15:02:46 -0400201 return NULL;
Paul Moored15c3452006-08-03 16:48:37 -0700202}
203
Paul Moore63c41682008-10-10 10:16:32 -0400204/**
205 * netlbl_domhsh_audit_add - Generate an audit entry for an add event
206 * @entry: the entry being added
207 * @addr4: the IPv4 address information
208 * @addr6: the IPv6 address information
209 * @result: the result code
210 * @audit_info: NetLabel audit information
211 *
212 * Description:
213 * Generate an audit record for adding a new NetLabel/LSM mapping entry with
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300214 * the given information. Caller is responsible for holding the necessary
Paul Moore63c41682008-10-10 10:16:32 -0400215 * locks.
216 *
217 */
218static void netlbl_domhsh_audit_add(struct netlbl_dom_map *entry,
219 struct netlbl_af4list *addr4,
220 struct netlbl_af6list *addr6,
221 int result,
222 struct netlbl_audit *audit_info)
223{
224 struct audit_buffer *audit_buf;
225 struct cipso_v4_doi *cipsov4 = NULL;
226 u32 type;
227
228 audit_buf = netlbl_audit_start_common(AUDIT_MAC_MAP_ADD, audit_info);
229 if (audit_buf != NULL) {
230 audit_log_format(audit_buf, " nlbl_domain=%s",
231 entry->domain ? entry->domain : "(default)");
232 if (addr4 != NULL) {
233 struct netlbl_domaddr4_map *map4;
234 map4 = netlbl_domhsh_addr4_entry(addr4);
Paul Moore6a8b7f02013-08-02 14:45:08 -0400235 type = map4->def.type;
236 cipsov4 = map4->def.cipso;
Paul Moore63c41682008-10-10 10:16:32 -0400237 netlbl_af4list_audit_addr(audit_buf, 0, NULL,
238 addr4->addr, addr4->mask);
Eric Dumazetdfd56b82011-12-10 09:48:31 +0000239#if IS_ENABLED(CONFIG_IPV6)
Paul Moore63c41682008-10-10 10:16:32 -0400240 } else if (addr6 != NULL) {
241 struct netlbl_domaddr6_map *map6;
242 map6 = netlbl_domhsh_addr6_entry(addr6);
Paul Moore6a8b7f02013-08-02 14:45:08 -0400243 type = map6->def.type;
Paul Moore63c41682008-10-10 10:16:32 -0400244 netlbl_af6list_audit_addr(audit_buf, 0, NULL,
245 &addr6->addr, &addr6->mask);
246#endif /* IPv6 */
247 } else {
Paul Moore6a8b7f02013-08-02 14:45:08 -0400248 type = entry->def.type;
249 cipsov4 = entry->def.cipso;
Paul Moore63c41682008-10-10 10:16:32 -0400250 }
251 switch (type) {
252 case NETLBL_NLTYPE_UNLABELED:
253 audit_log_format(audit_buf, " nlbl_protocol=unlbl");
254 break;
255 case NETLBL_NLTYPE_CIPSOV4:
256 BUG_ON(cipsov4 == NULL);
257 audit_log_format(audit_buf,
258 " nlbl_protocol=cipsov4 cipso_doi=%u",
259 cipsov4->doi);
260 break;
261 }
262 audit_log_format(audit_buf, " res=%u", result == 0 ? 1 : 0);
263 audit_log_end(audit_buf);
264 }
265}
266
Paul Moore6b21e1b2013-05-17 09:08:50 +0000267/**
268 * netlbl_domhsh_validate - Validate a new domain mapping entry
269 * @entry: the entry to validate
270 *
271 * This function validates the new domain mapping entry to ensure that it is
272 * a valid entry. Returns zero on success, negative values on failure.
273 *
274 */
275static int netlbl_domhsh_validate(const struct netlbl_dom_map *entry)
276{
277 struct netlbl_af4list *iter4;
278 struct netlbl_domaddr4_map *map4;
279#if IS_ENABLED(CONFIG_IPV6)
280 struct netlbl_af6list *iter6;
281 struct netlbl_domaddr6_map *map6;
282#endif /* IPv6 */
283
284 if (entry == NULL)
285 return -EINVAL;
286
Huw Davies8f18e672016-06-27 15:02:46 -0400287 if (entry->family != AF_INET && entry->family != AF_INET6 &&
288 (entry->family != AF_UNSPEC ||
289 entry->def.type != NETLBL_NLTYPE_UNLABELED))
290 return -EINVAL;
291
Paul Moore6a8b7f02013-08-02 14:45:08 -0400292 switch (entry->def.type) {
Paul Moore6b21e1b2013-05-17 09:08:50 +0000293 case NETLBL_NLTYPE_UNLABELED:
Paul Moore6a8b7f02013-08-02 14:45:08 -0400294 if (entry->def.cipso != NULL || entry->def.addrsel != NULL)
Paul Moore6b21e1b2013-05-17 09:08:50 +0000295 return -EINVAL;
296 break;
297 case NETLBL_NLTYPE_CIPSOV4:
Huw Davies8f18e672016-06-27 15:02:46 -0400298 if (entry->family != AF_INET ||
299 entry->def.cipso == NULL)
Paul Moore6b21e1b2013-05-17 09:08:50 +0000300 return -EINVAL;
301 break;
302 case NETLBL_NLTYPE_ADDRSELECT:
Paul Moore6a8b7f02013-08-02 14:45:08 -0400303 netlbl_af4list_foreach(iter4, &entry->def.addrsel->list4) {
Paul Moore6b21e1b2013-05-17 09:08:50 +0000304 map4 = netlbl_domhsh_addr4_entry(iter4);
Paul Moore6a8b7f02013-08-02 14:45:08 -0400305 switch (map4->def.type) {
Paul Moore6b21e1b2013-05-17 09:08:50 +0000306 case NETLBL_NLTYPE_UNLABELED:
Paul Moore6a8b7f02013-08-02 14:45:08 -0400307 if (map4->def.cipso != NULL)
Paul Moore6b21e1b2013-05-17 09:08:50 +0000308 return -EINVAL;
309 break;
310 case NETLBL_NLTYPE_CIPSOV4:
Paul Moore6a8b7f02013-08-02 14:45:08 -0400311 if (map4->def.cipso == NULL)
Paul Moore6b21e1b2013-05-17 09:08:50 +0000312 return -EINVAL;
313 break;
314 default:
315 return -EINVAL;
316 }
317 }
318#if IS_ENABLED(CONFIG_IPV6)
Paul Moore6a8b7f02013-08-02 14:45:08 -0400319 netlbl_af6list_foreach(iter6, &entry->def.addrsel->list6) {
Paul Moore6b21e1b2013-05-17 09:08:50 +0000320 map6 = netlbl_domhsh_addr6_entry(iter6);
Paul Moore6a8b7f02013-08-02 14:45:08 -0400321 switch (map6->def.type) {
Paul Moore6b21e1b2013-05-17 09:08:50 +0000322 case NETLBL_NLTYPE_UNLABELED:
323 break;
324 default:
325 return -EINVAL;
326 }
327 }
328#endif /* IPv6 */
329 break;
330 default:
331 return -EINVAL;
332 }
333
334 return 0;
335}
336
Paul Moored15c3452006-08-03 16:48:37 -0700337/*
338 * Domain Hash Table Functions
339 */
340
341/**
342 * netlbl_domhsh_init - Init for the domain hash
343 * @size: the number of bits to use for the hash buckets
344 *
345 * Description:
346 * Initializes the domain hash table, should be called only by
347 * netlbl_user_init() during initialization. Returns zero on success, non-zero
348 * values on error.
349 *
350 */
Pavel Emelyanov05705e42008-02-17 22:33:57 -0800351int __init netlbl_domhsh_init(u32 size)
Paul Moored15c3452006-08-03 16:48:37 -0700352{
353 u32 iter;
354 struct netlbl_domhsh_tbl *hsh_tbl;
355
356 if (size == 0)
357 return -EINVAL;
358
359 hsh_tbl = kmalloc(sizeof(*hsh_tbl), GFP_KERNEL);
360 if (hsh_tbl == NULL)
361 return -ENOMEM;
362 hsh_tbl->size = 1 << size;
363 hsh_tbl->tbl = kcalloc(hsh_tbl->size,
364 sizeof(struct list_head),
365 GFP_KERNEL);
366 if (hsh_tbl->tbl == NULL) {
367 kfree(hsh_tbl);
368 return -ENOMEM;
369 }
370 for (iter = 0; iter < hsh_tbl->size; iter++)
371 INIT_LIST_HEAD(&hsh_tbl->tbl[iter]);
372
Paul Moored15c3452006-08-03 16:48:37 -0700373 spin_lock(&netlbl_domhsh_lock);
Eric Dumazetcf778b02012-01-12 04:41:32 +0000374 rcu_assign_pointer(netlbl_domhsh, hsh_tbl);
Paul Moored15c3452006-08-03 16:48:37 -0700375 spin_unlock(&netlbl_domhsh_lock);
Paul Moored15c3452006-08-03 16:48:37 -0700376
377 return 0;
378}
379
380/**
381 * netlbl_domhsh_add - Adds a entry to the domain hash table
382 * @entry: the entry to add
Paul Moore95d4e6b2006-09-29 17:05:05 -0700383 * @audit_info: NetLabel audit information
Paul Moored15c3452006-08-03 16:48:37 -0700384 *
385 * Description:
386 * Adds a new entry to the domain hash table and handles any updates to the
Huw Davies8f18e672016-06-27 15:02:46 -0400387 * lower level protocol handler (i.e. CIPSO). @entry->family may be set to
388 * %AF_UNSPEC which will add an entry that matches all address families. This
389 * is only useful for the unlabelled type and will only succeed if there is no
390 * existing entry for any address family with the same domain. Returns zero
391 * on success, negative on failure.
Paul Moored15c3452006-08-03 16:48:37 -0700392 *
393 */
Paul Moore95d4e6b2006-09-29 17:05:05 -0700394int netlbl_domhsh_add(struct netlbl_dom_map *entry,
395 struct netlbl_audit *audit_info)
Paul Moored15c3452006-08-03 16:48:37 -0700396{
Paul Moore63c41682008-10-10 10:16:32 -0400397 int ret_val = 0;
Huw Davies8f18e672016-06-27 15:02:46 -0400398 struct netlbl_dom_map *entry_old, *entry_b;
Paul Moore63c41682008-10-10 10:16:32 -0400399 struct netlbl_af4list *iter4;
400 struct netlbl_af4list *tmp4;
Eric Dumazetdfd56b82011-12-10 09:48:31 +0000401#if IS_ENABLED(CONFIG_IPV6)
Paul Moore63c41682008-10-10 10:16:32 -0400402 struct netlbl_af6list *iter6;
403 struct netlbl_af6list *tmp6;
404#endif /* IPv6 */
Paul Moored15c3452006-08-03 16:48:37 -0700405
Paul Moore6b21e1b2013-05-17 09:08:50 +0000406 ret_val = netlbl_domhsh_validate(entry);
407 if (ret_val != 0)
408 return ret_val;
409
Paul Mooreb914f3a2010-04-01 10:43:57 +0000410 /* XXX - we can remove this RCU read lock as the spinlock protects the
411 * entire function, but before we do we need to fixup the
412 * netlbl_af[4,6]list RCU functions to do "the right thing" with
413 * respect to rcu_dereference() when only a spinlock is held. */
Paul Moored15c3452006-08-03 16:48:37 -0700414 rcu_read_lock();
Paul Moore1c3fad92008-01-29 08:37:57 -0500415 spin_lock(&netlbl_domhsh_lock);
Paul Moore63c41682008-10-10 10:16:32 -0400416 if (entry->domain != NULL)
Huw Davies8f18e672016-06-27 15:02:46 -0400417 entry_old = netlbl_domhsh_search(entry->domain, entry->family);
Paul Moore63c41682008-10-10 10:16:32 -0400418 else
Huw Davies8f18e672016-06-27 15:02:46 -0400419 entry_old = netlbl_domhsh_search_def(entry->domain,
420 entry->family);
Paul Moore63c41682008-10-10 10:16:32 -0400421 if (entry_old == NULL) {
422 entry->valid = 1;
Paul Moore63c41682008-10-10 10:16:32 -0400423
424 if (entry->domain != NULL) {
425 u32 bkt = netlbl_domhsh_hash(entry->domain);
Paul Moored15c3452006-08-03 16:48:37 -0700426 list_add_tail_rcu(&entry->list,
Paul Moore3482fd92007-08-07 17:53:10 -0700427 &rcu_dereference(netlbl_domhsh)->tbl[bkt]);
Paul Moore63c41682008-10-10 10:16:32 -0400428 } else {
429 INIT_LIST_HEAD(&entry->list);
Huw Davies8f18e672016-06-27 15:02:46 -0400430 switch (entry->family) {
431 case AF_INET:
432 rcu_assign_pointer(netlbl_domhsh_def_ipv4,
433 entry);
434 break;
435 case AF_INET6:
436 rcu_assign_pointer(netlbl_domhsh_def_ipv6,
437 entry);
438 break;
439 case AF_UNSPEC:
440 if (entry->def.type !=
441 NETLBL_NLTYPE_UNLABELED) {
442 ret_val = -EINVAL;
443 goto add_return;
444 }
445 entry_b = kzalloc(sizeof(*entry_b), GFP_ATOMIC);
446 if (entry_b == NULL) {
447 ret_val = -ENOMEM;
448 goto add_return;
449 }
450 entry_b->family = AF_INET6;
451 entry_b->def.type = NETLBL_NLTYPE_UNLABELED;
452 entry_b->valid = 1;
453 entry->family = AF_INET;
454 rcu_assign_pointer(netlbl_domhsh_def_ipv4,
455 entry);
456 rcu_assign_pointer(netlbl_domhsh_def_ipv6,
457 entry_b);
458 break;
459 default:
460 /* Already checked in
461 * netlbl_domhsh_validate(). */
462 ret_val = -EINVAL;
463 goto add_return;
464 }
Paul Moorede646882006-11-17 17:38:55 -0500465 }
Paul Moored15c3452006-08-03 16:48:37 -0700466
Paul Moore6a8b7f02013-08-02 14:45:08 -0400467 if (entry->def.type == NETLBL_NLTYPE_ADDRSELECT) {
Paul Moore63c41682008-10-10 10:16:32 -0400468 netlbl_af4list_foreach_rcu(iter4,
Paul Moore6a8b7f02013-08-02 14:45:08 -0400469 &entry->def.addrsel->list4)
Paul Moore63c41682008-10-10 10:16:32 -0400470 netlbl_domhsh_audit_add(entry, iter4, NULL,
471 ret_val, audit_info);
Eric Dumazetdfd56b82011-12-10 09:48:31 +0000472#if IS_ENABLED(CONFIG_IPV6)
Paul Moore63c41682008-10-10 10:16:32 -0400473 netlbl_af6list_foreach_rcu(iter6,
Paul Moore6a8b7f02013-08-02 14:45:08 -0400474 &entry->def.addrsel->list6)
Paul Moore63c41682008-10-10 10:16:32 -0400475 netlbl_domhsh_audit_add(entry, NULL, iter6,
476 ret_val, audit_info);
477#endif /* IPv6 */
478 } else
479 netlbl_domhsh_audit_add(entry, NULL, NULL,
480 ret_val, audit_info);
Paul Moore6a8b7f02013-08-02 14:45:08 -0400481 } else if (entry_old->def.type == NETLBL_NLTYPE_ADDRSELECT &&
482 entry->def.type == NETLBL_NLTYPE_ADDRSELECT) {
Paul Moore63c41682008-10-10 10:16:32 -0400483 struct list_head *old_list4;
484 struct list_head *old_list6;
485
Paul Moore6a8b7f02013-08-02 14:45:08 -0400486 old_list4 = &entry_old->def.addrsel->list4;
487 old_list6 = &entry_old->def.addrsel->list6;
Paul Moore63c41682008-10-10 10:16:32 -0400488
489 /* we only allow the addition of address selectors if all of
490 * the selectors do not exist in the existing domain map */
Paul Moore6a8b7f02013-08-02 14:45:08 -0400491 netlbl_af4list_foreach_rcu(iter4, &entry->def.addrsel->list4)
Paul Moore63c41682008-10-10 10:16:32 -0400492 if (netlbl_af4list_search_exact(iter4->addr,
493 iter4->mask,
494 old_list4)) {
495 ret_val = -EEXIST;
496 goto add_return;
497 }
Eric Dumazetdfd56b82011-12-10 09:48:31 +0000498#if IS_ENABLED(CONFIG_IPV6)
Paul Moore6a8b7f02013-08-02 14:45:08 -0400499 netlbl_af6list_foreach_rcu(iter6, &entry->def.addrsel->list6)
Paul Moore63c41682008-10-10 10:16:32 -0400500 if (netlbl_af6list_search_exact(&iter6->addr,
501 &iter6->mask,
502 old_list6)) {
503 ret_val = -EEXIST;
504 goto add_return;
505 }
506#endif /* IPv6 */
507
508 netlbl_af4list_foreach_safe(iter4, tmp4,
Paul Moore6a8b7f02013-08-02 14:45:08 -0400509 &entry->def.addrsel->list4) {
Paul Moore63c41682008-10-10 10:16:32 -0400510 netlbl_af4list_remove_entry(iter4);
511 iter4->valid = 1;
512 ret_val = netlbl_af4list_add(iter4, old_list4);
513 netlbl_domhsh_audit_add(entry_old, iter4, NULL,
514 ret_val, audit_info);
515 if (ret_val != 0)
516 goto add_return;
517 }
Eric Dumazetdfd56b82011-12-10 09:48:31 +0000518#if IS_ENABLED(CONFIG_IPV6)
Paul Moore63c41682008-10-10 10:16:32 -0400519 netlbl_af6list_foreach_safe(iter6, tmp6,
Paul Moore6a8b7f02013-08-02 14:45:08 -0400520 &entry->def.addrsel->list6) {
Paul Moore63c41682008-10-10 10:16:32 -0400521 netlbl_af6list_remove_entry(iter6);
522 iter6->valid = 1;
523 ret_val = netlbl_af6list_add(iter6, old_list6);
524 netlbl_domhsh_audit_add(entry_old, NULL, iter6,
525 ret_val, audit_info);
526 if (ret_val != 0)
527 goto add_return;
528 }
529#endif /* IPv6 */
530 } else
531 ret_val = -EINVAL;
532
533add_return:
534 spin_unlock(&netlbl_domhsh_lock);
535 rcu_read_unlock();
Paul Moored15c3452006-08-03 16:48:37 -0700536 return ret_val;
537}
538
539/**
540 * netlbl_domhsh_add_default - Adds the default entry to the domain hash table
541 * @entry: the entry to add
Paul Moore95d4e6b2006-09-29 17:05:05 -0700542 * @audit_info: NetLabel audit information
Paul Moored15c3452006-08-03 16:48:37 -0700543 *
544 * Description:
545 * Adds a new default entry to the domain hash table and handles any updates
546 * to the lower level protocol handler (i.e. CIPSO). Returns zero on success,
547 * negative on failure.
548 *
549 */
Paul Moore95d4e6b2006-09-29 17:05:05 -0700550int netlbl_domhsh_add_default(struct netlbl_dom_map *entry,
551 struct netlbl_audit *audit_info)
Paul Moored15c3452006-08-03 16:48:37 -0700552{
Paul Moore95d4e6b2006-09-29 17:05:05 -0700553 return netlbl_domhsh_add(entry, audit_info);
Paul Moored15c3452006-08-03 16:48:37 -0700554}
555
556/**
Paul Mooreb1edeb12008-10-10 10:16:31 -0400557 * netlbl_domhsh_remove_entry - Removes a given entry from the domain table
558 * @entry: the entry to remove
559 * @audit_info: NetLabel audit information
560 *
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). Caller is responsible for
564 * ensuring that the RCU read lock is held. Returns zero on success, negative
565 * on failure.
566 *
567 */
568int netlbl_domhsh_remove_entry(struct netlbl_dom_map *entry,
569 struct netlbl_audit *audit_info)
570{
571 int ret_val = 0;
572 struct audit_buffer *audit_buf;
573
574 if (entry == NULL)
575 return -ENOENT;
576
577 spin_lock(&netlbl_domhsh_lock);
578 if (entry->valid) {
579 entry->valid = 0;
Huw Davies8f18e672016-06-27 15:02:46 -0400580 if (entry == rcu_dereference(netlbl_domhsh_def_ipv4))
581 RCU_INIT_POINTER(netlbl_domhsh_def_ipv4, NULL);
582 else if (entry == rcu_dereference(netlbl_domhsh_def_ipv6))
583 RCU_INIT_POINTER(netlbl_domhsh_def_ipv6, NULL);
Paul Mooreb1edeb12008-10-10 10:16:31 -0400584 else
Huw Davies8f18e672016-06-27 15:02:46 -0400585 list_del_rcu(&entry->list);
Paul Mooreb1edeb12008-10-10 10:16:31 -0400586 } else
587 ret_val = -ENOENT;
588 spin_unlock(&netlbl_domhsh_lock);
589
590 audit_buf = netlbl_audit_start_common(AUDIT_MAC_MAP_DEL, audit_info);
591 if (audit_buf != NULL) {
592 audit_log_format(audit_buf,
593 " nlbl_domain=%s res=%u",
594 entry->domain ? entry->domain : "(default)",
595 ret_val == 0 ? 1 : 0);
596 audit_log_end(audit_buf);
597 }
598
599 if (ret_val == 0) {
Paul Moore63c41682008-10-10 10:16:32 -0400600 struct netlbl_af4list *iter4;
601 struct netlbl_domaddr4_map *map4;
602
Paul Moore6a8b7f02013-08-02 14:45:08 -0400603 switch (entry->def.type) {
Paul Moore63c41682008-10-10 10:16:32 -0400604 case NETLBL_NLTYPE_ADDRSELECT:
605 netlbl_af4list_foreach_rcu(iter4,
Paul Moore6a8b7f02013-08-02 14:45:08 -0400606 &entry->def.addrsel->list4) {
Paul Moore63c41682008-10-10 10:16:32 -0400607 map4 = netlbl_domhsh_addr4_entry(iter4);
Paul Moore6a8b7f02013-08-02 14:45:08 -0400608 cipso_v4_doi_putdef(map4->def.cipso);
Paul Moore63c41682008-10-10 10:16:32 -0400609 }
610 /* no need to check the IPv6 list since we currently
611 * support only unlabeled protocols for IPv6 */
612 break;
Paul Mooreb1edeb12008-10-10 10:16:31 -0400613 case NETLBL_NLTYPE_CIPSOV4:
Paul Moore6a8b7f02013-08-02 14:45:08 -0400614 cipso_v4_doi_putdef(entry->def.cipso);
Paul Mooreb1edeb12008-10-10 10:16:31 -0400615 break;
616 }
617 call_rcu(&entry->rcu, netlbl_domhsh_free_entry);
618 }
619
620 return ret_val;
621}
622
623/**
Paul Moore6c2e8ac2008-12-31 12:54:11 -0500624 * netlbl_domhsh_remove_af4 - Removes an address selector entry
625 * @domain: the domain
626 * @addr: IPv4 address
627 * @mask: IPv4 address mask
628 * @audit_info: NetLabel audit information
629 *
630 * Description:
631 * Removes an individual address selector from a domain mapping and potentially
632 * the entire mapping if it is empty. Returns zero on success, negative values
633 * on failure.
634 *
635 */
636int netlbl_domhsh_remove_af4(const char *domain,
637 const struct in_addr *addr,
638 const struct in_addr *mask,
639 struct netlbl_audit *audit_info)
640{
641 struct netlbl_dom_map *entry_map;
642 struct netlbl_af4list *entry_addr;
643 struct netlbl_af4list *iter4;
Eric Dumazetdfd56b82011-12-10 09:48:31 +0000644#if IS_ENABLED(CONFIG_IPV6)
Paul Moore6c2e8ac2008-12-31 12:54:11 -0500645 struct netlbl_af6list *iter6;
646#endif /* IPv6 */
647 struct netlbl_domaddr4_map *entry;
648
649 rcu_read_lock();
650
651 if (domain)
Huw Davies8f18e672016-06-27 15:02:46 -0400652 entry_map = netlbl_domhsh_search(domain, AF_INET);
Paul Moore6c2e8ac2008-12-31 12:54:11 -0500653 else
Huw Davies8f18e672016-06-27 15:02:46 -0400654 entry_map = netlbl_domhsh_search_def(domain, AF_INET);
Paul Moore6a8b7f02013-08-02 14:45:08 -0400655 if (entry_map == NULL ||
656 entry_map->def.type != NETLBL_NLTYPE_ADDRSELECT)
Paul Moore6c2e8ac2008-12-31 12:54:11 -0500657 goto remove_af4_failure;
658
659 spin_lock(&netlbl_domhsh_lock);
660 entry_addr = netlbl_af4list_remove(addr->s_addr, mask->s_addr,
Paul Moore6a8b7f02013-08-02 14:45:08 -0400661 &entry_map->def.addrsel->list4);
Paul Moore6c2e8ac2008-12-31 12:54:11 -0500662 spin_unlock(&netlbl_domhsh_lock);
663
664 if (entry_addr == NULL)
665 goto remove_af4_failure;
Paul Moore6a8b7f02013-08-02 14:45:08 -0400666 netlbl_af4list_foreach_rcu(iter4, &entry_map->def.addrsel->list4)
Paul Moore6c2e8ac2008-12-31 12:54:11 -0500667 goto remove_af4_single_addr;
Eric Dumazetdfd56b82011-12-10 09:48:31 +0000668#if IS_ENABLED(CONFIG_IPV6)
Paul Moore6a8b7f02013-08-02 14:45:08 -0400669 netlbl_af6list_foreach_rcu(iter6, &entry_map->def.addrsel->list6)
Paul Moore6c2e8ac2008-12-31 12:54:11 -0500670 goto remove_af4_single_addr;
671#endif /* IPv6 */
672 /* the domain mapping is empty so remove it from the mapping table */
673 netlbl_domhsh_remove_entry(entry_map, audit_info);
674
675remove_af4_single_addr:
676 rcu_read_unlock();
677 /* yick, we can't use call_rcu here because we don't have a rcu head
678 * pointer but hopefully this should be a rare case so the pause
679 * shouldn't be a problem */
680 synchronize_rcu();
681 entry = netlbl_domhsh_addr4_entry(entry_addr);
Paul Moore6a8b7f02013-08-02 14:45:08 -0400682 cipso_v4_doi_putdef(entry->def.cipso);
Paul Moore6c2e8ac2008-12-31 12:54:11 -0500683 kfree(entry);
684 return 0;
685
686remove_af4_failure:
687 rcu_read_unlock();
688 return -ENOENT;
689}
690
691/**
Paul Moored15c3452006-08-03 16:48:37 -0700692 * netlbl_domhsh_remove - Removes an entry from the domain hash table
693 * @domain: the domain to remove
Huw Davies8f18e672016-06-27 15:02:46 -0400694 * @family: address family
Paul Moore95d4e6b2006-09-29 17:05:05 -0700695 * @audit_info: NetLabel audit information
Paul Moored15c3452006-08-03 16:48:37 -0700696 *
697 * Description:
698 * Removes an entry from the domain hash table and handles any updates to the
Huw Davies8f18e672016-06-27 15:02:46 -0400699 * lower level protocol handler (i.e. CIPSO). @family may be %AF_UNSPEC which
700 * removes all address family entries. Returns zero on success, negative on
701 * failure.
Paul Moored15c3452006-08-03 16:48:37 -0700702 *
703 */
Huw Davies8f18e672016-06-27 15:02:46 -0400704int netlbl_domhsh_remove(const char *domain, u16 family,
705 struct netlbl_audit *audit_info)
Paul Moored15c3452006-08-03 16:48:37 -0700706{
Huw Davies8f18e672016-06-27 15:02:46 -0400707 int ret_val = -EINVAL;
Paul Moored15c3452006-08-03 16:48:37 -0700708 struct netlbl_dom_map *entry;
709
710 rcu_read_lock();
Huw Davies8f18e672016-06-27 15:02:46 -0400711
712 if (family == AF_INET || family == AF_UNSPEC) {
713 if (domain)
714 entry = netlbl_domhsh_search(domain, AF_INET);
715 else
716 entry = netlbl_domhsh_search_def(domain, AF_INET);
717 ret_val = netlbl_domhsh_remove_entry(entry, audit_info);
718 if (ret_val && ret_val != -ENOENT)
719 goto done;
720 }
721 if (family == AF_INET6 || family == AF_UNSPEC) {
722 int ret_val2;
723
724 if (domain)
725 entry = netlbl_domhsh_search(domain, AF_INET6);
726 else
727 entry = netlbl_domhsh_search_def(domain, AF_INET6);
728 ret_val2 = netlbl_domhsh_remove_entry(entry, audit_info);
729 if (ret_val2 != -ENOENT)
730 ret_val = ret_val2;
731 }
732done:
Paul Moored15c3452006-08-03 16:48:37 -0700733 rcu_read_unlock();
Paul Mooreb1edeb12008-10-10 10:16:31 -0400734
Paul Moored15c3452006-08-03 16:48:37 -0700735 return ret_val;
736}
737
738/**
739 * netlbl_domhsh_remove_default - Removes the default entry from the table
Huw Davies8f18e672016-06-27 15:02:46 -0400740 * @family: address family
Paul Moore95d4e6b2006-09-29 17:05:05 -0700741 * @audit_info: NetLabel audit information
Paul Moored15c3452006-08-03 16:48:37 -0700742 *
743 * Description:
Huw Davies8f18e672016-06-27 15:02:46 -0400744 * Removes/resets the default entry corresponding to @family from the domain
745 * hash table and handles any updates to the lower level protocol handler
746 * (i.e. CIPSO). @family may be %AF_UNSPEC which removes all address family
747 * entries. Returns zero on success, negative on failure.
Paul Moored15c3452006-08-03 16:48:37 -0700748 *
749 */
Huw Davies8f18e672016-06-27 15:02:46 -0400750int netlbl_domhsh_remove_default(u16 family, struct netlbl_audit *audit_info)
Paul Moored15c3452006-08-03 16:48:37 -0700751{
Huw Davies8f18e672016-06-27 15:02:46 -0400752 return netlbl_domhsh_remove(NULL, family, audit_info);
Paul Moored15c3452006-08-03 16:48:37 -0700753}
754
755/**
756 * netlbl_domhsh_getentry - Get an entry from the domain hash table
757 * @domain: the domain name to search for
Huw Davies8f18e672016-06-27 15:02:46 -0400758 * @family: address family
Paul Moored15c3452006-08-03 16:48:37 -0700759 *
760 * Description:
761 * Look through the domain hash table searching for an entry to match @domain,
Huw Davies8f18e672016-06-27 15:02:46 -0400762 * with address family @family, return a pointer to a copy of the entry or
763 * NULL. The caller is responsible for ensuring that rcu_read_[un]lock() is
764 * called.
Paul Moored15c3452006-08-03 16:48:37 -0700765 *
766 */
Huw Davies8f18e672016-06-27 15:02:46 -0400767struct netlbl_dom_map *netlbl_domhsh_getentry(const char *domain, u16 family)
Paul Moored15c3452006-08-03 16:48:37 -0700768{
Huw Davies8f18e672016-06-27 15:02:46 -0400769 if (family == AF_UNSPEC)
770 return NULL;
771 return netlbl_domhsh_search_def(domain, family);
Paul Moored15c3452006-08-03 16:48:37 -0700772}
773
774/**
Paul Moore63c41682008-10-10 10:16:32 -0400775 * netlbl_domhsh_getentry_af4 - Get an entry from the domain hash table
776 * @domain: the domain name to search for
777 * @addr: the IP address to search for
778 *
779 * Description:
780 * Look through the domain hash table searching for an entry to match @domain
781 * and @addr, return a pointer to a copy of the entry or NULL. The caller is
782 * responsible for ensuring that rcu_read_[un]lock() is called.
783 *
784 */
Paul Moore6a8b7f02013-08-02 14:45:08 -0400785struct netlbl_dommap_def *netlbl_domhsh_getentry_af4(const char *domain,
786 __be32 addr)
Paul Moore63c41682008-10-10 10:16:32 -0400787{
788 struct netlbl_dom_map *dom_iter;
789 struct netlbl_af4list *addr_iter;
790
Huw Davies8f18e672016-06-27 15:02:46 -0400791 dom_iter = netlbl_domhsh_search_def(domain, AF_INET);
Paul Moore63c41682008-10-10 10:16:32 -0400792 if (dom_iter == NULL)
793 return NULL;
Paul Moore63c41682008-10-10 10:16:32 -0400794
Paul Moore6a8b7f02013-08-02 14:45:08 -0400795 if (dom_iter->def.type != NETLBL_NLTYPE_ADDRSELECT)
796 return &dom_iter->def;
797 addr_iter = netlbl_af4list_search(addr, &dom_iter->def.addrsel->list4);
Paul Moore63c41682008-10-10 10:16:32 -0400798 if (addr_iter == NULL)
799 return NULL;
Paul Moore6a8b7f02013-08-02 14:45:08 -0400800 return &(netlbl_domhsh_addr4_entry(addr_iter)->def);
Paul Moore63c41682008-10-10 10:16:32 -0400801}
802
Eric Dumazetdfd56b82011-12-10 09:48:31 +0000803#if IS_ENABLED(CONFIG_IPV6)
Paul Moore63c41682008-10-10 10:16:32 -0400804/**
805 * netlbl_domhsh_getentry_af6 - Get an entry from the domain hash table
806 * @domain: the domain name to search for
807 * @addr: the IP address to search for
808 *
809 * Description:
810 * Look through the domain hash table searching for an entry to match @domain
811 * and @addr, return a pointer to a copy of the entry or NULL. The caller is
812 * responsible for ensuring that rcu_read_[un]lock() is called.
813 *
814 */
Paul Moore6a8b7f02013-08-02 14:45:08 -0400815struct netlbl_dommap_def *netlbl_domhsh_getentry_af6(const char *domain,
Paul Moore63c41682008-10-10 10:16:32 -0400816 const struct in6_addr *addr)
817{
818 struct netlbl_dom_map *dom_iter;
819 struct netlbl_af6list *addr_iter;
820
Huw Davies8f18e672016-06-27 15:02:46 -0400821 dom_iter = netlbl_domhsh_search_def(domain, AF_INET6);
Paul Moore63c41682008-10-10 10:16:32 -0400822 if (dom_iter == NULL)
823 return NULL;
Paul Moore63c41682008-10-10 10:16:32 -0400824
Paul Moore6a8b7f02013-08-02 14:45:08 -0400825 if (dom_iter->def.type != NETLBL_NLTYPE_ADDRSELECT)
826 return &dom_iter->def;
827 addr_iter = netlbl_af6list_search(addr, &dom_iter->def.addrsel->list6);
Paul Moore63c41682008-10-10 10:16:32 -0400828 if (addr_iter == NULL)
829 return NULL;
Paul Moore6a8b7f02013-08-02 14:45:08 -0400830 return &(netlbl_domhsh_addr6_entry(addr_iter)->def);
Paul Moore63c41682008-10-10 10:16:32 -0400831}
832#endif /* IPv6 */
833
834/**
Paul Moorefcd48282006-09-25 15:56:09 -0700835 * netlbl_domhsh_walk - Iterate through the domain mapping hash table
836 * @skip_bkt: the number of buckets to skip at the start
837 * @skip_chain: the number of entries to skip in the first iterated bucket
838 * @callback: callback for each entry
839 * @cb_arg: argument for the callback function
Paul Moored15c3452006-08-03 16:48:37 -0700840 *
841 * Description:
Paul Moorefcd48282006-09-25 15:56:09 -0700842 * Interate over the domain mapping hash table, skipping the first @skip_bkt
843 * buckets and @skip_chain entries. For each entry in the table call
844 * @callback, if @callback returns a negative value stop 'walking' through the
845 * table and return. Updates the values in @skip_bkt and @skip_chain on
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200846 * return. Returns zero on success, negative values on failure.
Paul Moored15c3452006-08-03 16:48:37 -0700847 *
848 */
Paul Moorefcd48282006-09-25 15:56:09 -0700849int netlbl_domhsh_walk(u32 *skip_bkt,
850 u32 *skip_chain,
851 int (*callback) (struct netlbl_dom_map *entry, void *arg),
852 void *cb_arg)
Paul Moored15c3452006-08-03 16:48:37 -0700853{
Paul Moorefcd48282006-09-25 15:56:09 -0700854 int ret_val = -ENOENT;
855 u32 iter_bkt;
Paul Moore56196702008-10-10 10:16:29 -0400856 struct list_head *iter_list;
Paul Moorefcd48282006-09-25 15:56:09 -0700857 struct netlbl_dom_map *iter_entry;
858 u32 chain_cnt = 0;
Paul Moored15c3452006-08-03 16:48:37 -0700859
Paul Moored15c3452006-08-03 16:48:37 -0700860 rcu_read_lock();
Paul Moorefcd48282006-09-25 15:56:09 -0700861 for (iter_bkt = *skip_bkt;
862 iter_bkt < rcu_dereference(netlbl_domhsh)->size;
863 iter_bkt++, chain_cnt = 0) {
Paul Moore56196702008-10-10 10:16:29 -0400864 iter_list = &rcu_dereference(netlbl_domhsh)->tbl[iter_bkt];
865 list_for_each_entry_rcu(iter_entry, iter_list, list)
Paul Moorefcd48282006-09-25 15:56:09 -0700866 if (iter_entry->valid) {
867 if (chain_cnt++ < *skip_chain)
868 continue;
869 ret_val = callback(iter_entry, cb_arg);
870 if (ret_val < 0) {
871 chain_cnt--;
872 goto walk_return;
873 }
Paul Moored15c3452006-08-03 16:48:37 -0700874 }
Paul Moorefcd48282006-09-25 15:56:09 -0700875 }
Paul Moored15c3452006-08-03 16:48:37 -0700876
Paul Moorefcd48282006-09-25 15:56:09 -0700877walk_return:
Paul Moored15c3452006-08-03 16:48:37 -0700878 rcu_read_unlock();
Paul Moorefcd48282006-09-25 15:56:09 -0700879 *skip_bkt = iter_bkt;
880 *skip_chain = chain_cnt;
881 return ret_val;
Paul Moored15c3452006-08-03 16:48:37 -0700882}