SiS190/191 half-duplex initialization fix
[deliverable/linux.git] / net / xfrm / xfrm_state.c
CommitLineData
1da177e4
LT
1/*
2 * xfrm_state.c
3 *
4 * Changes:
5 * Mitsuru KANDA @USAGI
6 * Kazunori MIYAZAWA @USAGI
7 * Kunihiro Ishiguro <kunihiro@ipinfusion.com>
8 * IPv6 support
9 * YOSHIFUJI Hideaki @USAGI
10 * Split up af-specific functions
11 * Derek Atkins <derek@ihtfp.com>
12 * Add UDP Encapsulation
df71837d 13 *
1da177e4
LT
14 */
15
16#include <linux/workqueue.h>
17#include <net/xfrm.h>
18#include <linux/pfkeyv2.h>
19#include <linux/ipsec.h>
20#include <linux/module.h>
f034b5d4 21#include <linux/cache.h>
68277acc 22#include <linux/audit.h>
b5890d8b 23#include <asm/uaccess.h>
9e0d57fd
YP
24#include <linux/ktime.h>
25#include <linux/interrupt.h>
26#include <linux/kernel.h>
1da177e4 27
44e36b42
DM
28#include "xfrm_hash.h"
29
1da177e4
LT
30/* Each xfrm_state may be linked to two tables:
31
32 1. Hash table by (spi,daddr,ah/esp) to find SA by SPI. (input,ctl)
a624c108 33 2. Hash table by (daddr,family,reqid) to find what SAs exist for given
1da177e4
LT
34 destination/tunnel endpoint. (output)
35 */
36
37static DEFINE_SPINLOCK(xfrm_state_lock);
38
f034b5d4 39static unsigned int xfrm_state_hashmax __read_mostly = 1 * 1024 * 1024;
9d4a706d 40static unsigned int xfrm_state_genid;
f034b5d4 41
17c2a42a
HX
42static struct xfrm_state_afinfo *xfrm_state_get_afinfo(unsigned int family);
43static void xfrm_state_put_afinfo(struct xfrm_state_afinfo *afinfo);
44
afeb14b4
PM
45#ifdef CONFIG_AUDITSYSCALL
46static void xfrm_audit_state_replay(struct xfrm_state *x,
47 struct sk_buff *skb, __be32 net_seq);
48#else
49#define xfrm_audit_state_replay(x, s, sq) do { ; } while (0)
50#endif /* CONFIG_AUDITSYSCALL */
51
64d0cd00
AD
52static inline unsigned int xfrm_dst_hash(struct net *net,
53 xfrm_address_t *daddr,
c1969f29
DM
54 xfrm_address_t *saddr,
55 u32 reqid,
a624c108 56 unsigned short family)
f034b5d4 57{
64d0cd00 58 return __xfrm_dst_hash(daddr, saddr, reqid, family, net->xfrm.state_hmask);
f034b5d4
DM
59}
60
64d0cd00
AD
61static inline unsigned int xfrm_src_hash(struct net *net,
62 xfrm_address_t *daddr,
667bbcb6 63 xfrm_address_t *saddr,
44e36b42 64 unsigned short family)
f034b5d4 65{
64d0cd00 66 return __xfrm_src_hash(daddr, saddr, family, net->xfrm.state_hmask);
f034b5d4
DM
67}
68
f034b5d4 69static inline unsigned int
64d0cd00 70xfrm_spi_hash(struct net *net, xfrm_address_t *daddr, __be32 spi, u8 proto, unsigned short family)
f034b5d4 71{
64d0cd00 72 return __xfrm_spi_hash(daddr, spi, proto, family, net->xfrm.state_hmask);
f034b5d4
DM
73}
74
f034b5d4
DM
75static void xfrm_hash_transfer(struct hlist_head *list,
76 struct hlist_head *ndsttable,
77 struct hlist_head *nsrctable,
78 struct hlist_head *nspitable,
79 unsigned int nhashmask)
80{
81 struct hlist_node *entry, *tmp;
82 struct xfrm_state *x;
83
84 hlist_for_each_entry_safe(x, entry, tmp, list, bydst) {
85 unsigned int h;
86
c1969f29
DM
87 h = __xfrm_dst_hash(&x->id.daddr, &x->props.saddr,
88 x->props.reqid, x->props.family,
89 nhashmask);
f034b5d4
DM
90 hlist_add_head(&x->bydst, ndsttable+h);
91
667bbcb6
MN
92 h = __xfrm_src_hash(&x->id.daddr, &x->props.saddr,
93 x->props.family,
f034b5d4
DM
94 nhashmask);
95 hlist_add_head(&x->bysrc, nsrctable+h);
96
7b4dc360
MN
97 if (x->id.spi) {
98 h = __xfrm_spi_hash(&x->id.daddr, x->id.spi,
99 x->id.proto, x->props.family,
100 nhashmask);
101 hlist_add_head(&x->byspi, nspitable+h);
102 }
f034b5d4
DM
103 }
104}
105
63082733 106static unsigned long xfrm_hash_new_size(unsigned int state_hmask)
f034b5d4 107{
63082733 108 return ((state_hmask + 1) << 1) * sizeof(struct hlist_head);
f034b5d4
DM
109}
110
111static DEFINE_MUTEX(hash_resize_mutex);
112
63082733 113static void xfrm_hash_resize(struct work_struct *work)
f034b5d4 114{
63082733 115 struct net *net = container_of(work, struct net, xfrm.state_hash_work);
f034b5d4
DM
116 struct hlist_head *ndst, *nsrc, *nspi, *odst, *osrc, *ospi;
117 unsigned long nsize, osize;
118 unsigned int nhashmask, ohashmask;
119 int i;
120
121 mutex_lock(&hash_resize_mutex);
122
63082733 123 nsize = xfrm_hash_new_size(net->xfrm.state_hmask);
44e36b42 124 ndst = xfrm_hash_alloc(nsize);
f034b5d4
DM
125 if (!ndst)
126 goto out_unlock;
44e36b42 127 nsrc = xfrm_hash_alloc(nsize);
f034b5d4 128 if (!nsrc) {
44e36b42 129 xfrm_hash_free(ndst, nsize);
f034b5d4
DM
130 goto out_unlock;
131 }
44e36b42 132 nspi = xfrm_hash_alloc(nsize);
f034b5d4 133 if (!nspi) {
44e36b42
DM
134 xfrm_hash_free(ndst, nsize);
135 xfrm_hash_free(nsrc, nsize);
f034b5d4
DM
136 goto out_unlock;
137 }
138
139 spin_lock_bh(&xfrm_state_lock);
140
141 nhashmask = (nsize / sizeof(struct hlist_head)) - 1U;
63082733
AD
142 for (i = net->xfrm.state_hmask; i >= 0; i--)
143 xfrm_hash_transfer(net->xfrm.state_bydst+i, ndst, nsrc, nspi,
f034b5d4
DM
144 nhashmask);
145
63082733
AD
146 odst = net->xfrm.state_bydst;
147 osrc = net->xfrm.state_bysrc;
148 ospi = net->xfrm.state_byspi;
149 ohashmask = net->xfrm.state_hmask;
f034b5d4 150
63082733
AD
151 net->xfrm.state_bydst = ndst;
152 net->xfrm.state_bysrc = nsrc;
153 net->xfrm.state_byspi = nspi;
154 net->xfrm.state_hmask = nhashmask;
f034b5d4
DM
155
156 spin_unlock_bh(&xfrm_state_lock);
157
158 osize = (ohashmask + 1) * sizeof(struct hlist_head);
44e36b42
DM
159 xfrm_hash_free(odst, osize);
160 xfrm_hash_free(osrc, osize);
161 xfrm_hash_free(ospi, osize);
f034b5d4
DM
162
163out_unlock:
164 mutex_unlock(&hash_resize_mutex);
165}
166
1da177e4
LT
167static DEFINE_RWLOCK(xfrm_state_afinfo_lock);
168static struct xfrm_state_afinfo *xfrm_state_afinfo[NPROTO];
169
1da177e4
LT
170static DEFINE_SPINLOCK(xfrm_state_gc_lock);
171
53bc6b4d 172int __xfrm_state_delete(struct xfrm_state *x);
1da177e4 173
980ebd25 174int km_query(struct xfrm_state *x, struct xfrm_tmpl *t, struct xfrm_policy *pol);
53bc6b4d 175void km_state_expired(struct xfrm_state *x, int hard, u32 pid);
1da177e4 176
aa5d62cc
HX
177static struct xfrm_state_afinfo *xfrm_state_lock_afinfo(unsigned int family)
178{
179 struct xfrm_state_afinfo *afinfo;
180 if (unlikely(family >= NPROTO))
181 return NULL;
182 write_lock_bh(&xfrm_state_afinfo_lock);
183 afinfo = xfrm_state_afinfo[family];
184 if (unlikely(!afinfo))
185 write_unlock_bh(&xfrm_state_afinfo_lock);
186 return afinfo;
187}
188
189static void xfrm_state_unlock_afinfo(struct xfrm_state_afinfo *afinfo)
9a429c49 190 __releases(xfrm_state_afinfo_lock)
aa5d62cc
HX
191{
192 write_unlock_bh(&xfrm_state_afinfo_lock);
193}
194
533cb5b0 195int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
aa5d62cc
HX
196{
197 struct xfrm_state_afinfo *afinfo = xfrm_state_lock_afinfo(family);
533cb5b0 198 const struct xfrm_type **typemap;
aa5d62cc
HX
199 int err = 0;
200
201 if (unlikely(afinfo == NULL))
202 return -EAFNOSUPPORT;
203 typemap = afinfo->type_map;
204
205 if (likely(typemap[type->proto] == NULL))
206 typemap[type->proto] = type;
207 else
208 err = -EEXIST;
209 xfrm_state_unlock_afinfo(afinfo);
210 return err;
211}
212EXPORT_SYMBOL(xfrm_register_type);
213
533cb5b0 214int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
aa5d62cc
HX
215{
216 struct xfrm_state_afinfo *afinfo = xfrm_state_lock_afinfo(family);
533cb5b0 217 const struct xfrm_type **typemap;
aa5d62cc
HX
218 int err = 0;
219
220 if (unlikely(afinfo == NULL))
221 return -EAFNOSUPPORT;
222 typemap = afinfo->type_map;
223
224 if (unlikely(typemap[type->proto] != type))
225 err = -ENOENT;
226 else
227 typemap[type->proto] = NULL;
228 xfrm_state_unlock_afinfo(afinfo);
229 return err;
230}
231EXPORT_SYMBOL(xfrm_unregister_type);
232
533cb5b0 233static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
aa5d62cc
HX
234{
235 struct xfrm_state_afinfo *afinfo;
533cb5b0
ED
236 const struct xfrm_type **typemap;
237 const struct xfrm_type *type;
aa5d62cc
HX
238 int modload_attempted = 0;
239
240retry:
241 afinfo = xfrm_state_get_afinfo(family);
242 if (unlikely(afinfo == NULL))
243 return NULL;
244 typemap = afinfo->type_map;
245
246 type = typemap[proto];
247 if (unlikely(type && !try_module_get(type->owner)))
248 type = NULL;
249 if (!type && !modload_attempted) {
250 xfrm_state_put_afinfo(afinfo);
251 request_module("xfrm-type-%d-%d", family, proto);
252 modload_attempted = 1;
253 goto retry;
254 }
255
256 xfrm_state_put_afinfo(afinfo);
257 return type;
258}
259
533cb5b0 260static void xfrm_put_type(const struct xfrm_type *type)
aa5d62cc
HX
261{
262 module_put(type->owner);
263}
264
265int xfrm_register_mode(struct xfrm_mode *mode, int family)
266{
267 struct xfrm_state_afinfo *afinfo;
268 struct xfrm_mode **modemap;
269 int err;
270
271 if (unlikely(mode->encap >= XFRM_MODE_MAX))
272 return -EINVAL;
273
274 afinfo = xfrm_state_lock_afinfo(family);
275 if (unlikely(afinfo == NULL))
276 return -EAFNOSUPPORT;
277
278 err = -EEXIST;
279 modemap = afinfo->mode_map;
17c2a42a
HX
280 if (modemap[mode->encap])
281 goto out;
aa5d62cc 282
17c2a42a
HX
283 err = -ENOENT;
284 if (!try_module_get(afinfo->owner))
285 goto out;
286
287 mode->afinfo = afinfo;
288 modemap[mode->encap] = mode;
289 err = 0;
290
291out:
aa5d62cc
HX
292 xfrm_state_unlock_afinfo(afinfo);
293 return err;
294}
295EXPORT_SYMBOL(xfrm_register_mode);
296
297int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
298{
299 struct xfrm_state_afinfo *afinfo;
300 struct xfrm_mode **modemap;
301 int err;
302
303 if (unlikely(mode->encap >= XFRM_MODE_MAX))
304 return -EINVAL;
305
306 afinfo = xfrm_state_lock_afinfo(family);
307 if (unlikely(afinfo == NULL))
308 return -EAFNOSUPPORT;
309
310 err = -ENOENT;
311 modemap = afinfo->mode_map;
312 if (likely(modemap[mode->encap] == mode)) {
313 modemap[mode->encap] = NULL;
17c2a42a 314 module_put(mode->afinfo->owner);
aa5d62cc
HX
315 err = 0;
316 }
317
318 xfrm_state_unlock_afinfo(afinfo);
319 return err;
320}
321EXPORT_SYMBOL(xfrm_unregister_mode);
322
323static struct xfrm_mode *xfrm_get_mode(unsigned int encap, int family)
324{
325 struct xfrm_state_afinfo *afinfo;
326 struct xfrm_mode *mode;
327 int modload_attempted = 0;
328
329 if (unlikely(encap >= XFRM_MODE_MAX))
330 return NULL;
331
332retry:
333 afinfo = xfrm_state_get_afinfo(family);
334 if (unlikely(afinfo == NULL))
335 return NULL;
336
337 mode = afinfo->mode_map[encap];
338 if (unlikely(mode && !try_module_get(mode->owner)))
339 mode = NULL;
340 if (!mode && !modload_attempted) {
341 xfrm_state_put_afinfo(afinfo);
342 request_module("xfrm-mode-%d-%d", family, encap);
343 modload_attempted = 1;
344 goto retry;
345 }
346
347 xfrm_state_put_afinfo(afinfo);
348 return mode;
349}
350
351static void xfrm_put_mode(struct xfrm_mode *mode)
352{
353 module_put(mode->owner);
354}
355
1da177e4
LT
356static void xfrm_state_gc_destroy(struct xfrm_state *x)
357{
9e0d57fd 358 tasklet_hrtimer_cancel(&x->mtimer);
a47f0ce0 359 del_timer_sync(&x->rtimer);
a51482bd
JJ
360 kfree(x->aalg);
361 kfree(x->ealg);
362 kfree(x->calg);
363 kfree(x->encap);
060f02a3 364 kfree(x->coaddr);
13996378
HX
365 if (x->inner_mode)
366 xfrm_put_mode(x->inner_mode);
df9dcb45
KM
367 if (x->inner_mode_iaf)
368 xfrm_put_mode(x->inner_mode_iaf);
13996378
HX
369 if (x->outer_mode)
370 xfrm_put_mode(x->outer_mode);
1da177e4
LT
371 if (x->type) {
372 x->type->destructor(x);
373 xfrm_put_type(x->type);
374 }
df71837d 375 security_xfrm_state_free(x);
1da177e4
LT
376 kfree(x);
377}
378
c7837144 379static void xfrm_state_gc_task(struct work_struct *work)
1da177e4 380{
c7837144 381 struct net *net = container_of(work, struct net, xfrm.state_gc_work);
12a169e7
HX
382 struct xfrm_state *x;
383 struct hlist_node *entry, *tmp;
384 struct hlist_head gc_list;
1da177e4 385
1da177e4 386 spin_lock_bh(&xfrm_state_gc_lock);
c7837144 387 hlist_move_list(&net->xfrm.state_gc_list, &gc_list);
1da177e4
LT
388 spin_unlock_bh(&xfrm_state_gc_lock);
389
12a169e7 390 hlist_for_each_entry_safe(x, entry, tmp, &gc_list, gclist)
1da177e4 391 xfrm_state_gc_destroy(x);
8f126e37 392
50a30657 393 wake_up(&net->xfrm.km_waitq);
1da177e4
LT
394}
395
396static inline unsigned long make_jiffies(long secs)
397{
398 if (secs >= (MAX_SCHEDULE_TIMEOUT-1)/HZ)
399 return MAX_SCHEDULE_TIMEOUT-1;
400 else
a716c119 401 return secs*HZ;
1da177e4
LT
402}
403
9e0d57fd 404static enum hrtimer_restart xfrm_timer_handler(struct hrtimer * me)
1da177e4 405{
9e0d57fd
YP
406 struct tasklet_hrtimer *thr = container_of(me, struct tasklet_hrtimer, timer);
407 struct xfrm_state *x = container_of(thr, struct xfrm_state, mtimer);
98806f75 408 struct net *net = xs_net(x);
9d729f72 409 unsigned long now = get_seconds();
1da177e4
LT
410 long next = LONG_MAX;
411 int warn = 0;
161a09e7 412 int err = 0;
1da177e4
LT
413
414 spin_lock(&x->lock);
415 if (x->km.state == XFRM_STATE_DEAD)
416 goto out;
417 if (x->km.state == XFRM_STATE_EXPIRED)
418 goto expired;
419 if (x->lft.hard_add_expires_seconds) {
420 long tmo = x->lft.hard_add_expires_seconds +
421 x->curlft.add_time - now;
422 if (tmo <= 0)
423 goto expired;
424 if (tmo < next)
425 next = tmo;
426 }
427 if (x->lft.hard_use_expires_seconds) {
428 long tmo = x->lft.hard_use_expires_seconds +
429 (x->curlft.use_time ? : now) - now;
430 if (tmo <= 0)
431 goto expired;
432 if (tmo < next)
433 next = tmo;
434 }
435 if (x->km.dying)
436 goto resched;
437 if (x->lft.soft_add_expires_seconds) {
438 long tmo = x->lft.soft_add_expires_seconds +
439 x->curlft.add_time - now;
440 if (tmo <= 0)
441 warn = 1;
442 else if (tmo < next)
443 next = tmo;
444 }
445 if (x->lft.soft_use_expires_seconds) {
446 long tmo = x->lft.soft_use_expires_seconds +
447 (x->curlft.use_time ? : now) - now;
448 if (tmo <= 0)
449 warn = 1;
450 else if (tmo < next)
451 next = tmo;
452 }
453
4666faab 454 x->km.dying = warn;
1da177e4 455 if (warn)
53bc6b4d 456 km_state_expired(x, 0, 0);
1da177e4 457resched:
9e0d57fd
YP
458 if (next != LONG_MAX){
459 tasklet_hrtimer_start(&x->mtimer, ktime_set(next, 0), HRTIMER_MODE_REL);
460 }
a47f0ce0 461
1da177e4
LT
462 goto out;
463
464expired:
465 if (x->km.state == XFRM_STATE_ACQ && x->id.spi == 0) {
466 x->km.state = XFRM_STATE_EXPIRED;
98806f75 467 wake_up(&net->xfrm.km_waitq);
1da177e4
LT
468 next = 2;
469 goto resched;
470 }
161a09e7
JL
471
472 err = __xfrm_state_delete(x);
473 if (!err && x->id.spi)
53bc6b4d 474 km_state_expired(x, 1, 0);
1da177e4 475
ab5f5e8b 476 xfrm_audit_state_delete(x, err ? 0 : 1,
2532386f
EP
477 audit_get_loginuid(current),
478 audit_get_sessionid(current), 0);
161a09e7 479
1da177e4
LT
480out:
481 spin_unlock(&x->lock);
9e0d57fd 482 return HRTIMER_NORESTART;
1da177e4
LT
483}
484
0ac84752
DM
485static void xfrm_replay_timer_handler(unsigned long data);
486
673c09be 487struct xfrm_state *xfrm_state_alloc(struct net *net)
1da177e4
LT
488{
489 struct xfrm_state *x;
490
0da974f4 491 x = kzalloc(sizeof(struct xfrm_state), GFP_ATOMIC);
1da177e4
LT
492
493 if (x) {
673c09be 494 write_pnet(&x->xs_net, net);
1da177e4
LT
495 atomic_set(&x->refcnt, 1);
496 atomic_set(&x->tunnel_users, 0);
12a169e7 497 INIT_LIST_HEAD(&x->km.all);
8f126e37
DM
498 INIT_HLIST_NODE(&x->bydst);
499 INIT_HLIST_NODE(&x->bysrc);
500 INIT_HLIST_NODE(&x->byspi);
9e0d57fd 501 tasklet_hrtimer_init(&x->mtimer, xfrm_timer_handler, CLOCK_REALTIME, HRTIMER_MODE_ABS);
b24b8a24
PE
502 setup_timer(&x->rtimer, xfrm_replay_timer_handler,
503 (unsigned long)x);
9d729f72 504 x->curlft.add_time = get_seconds();
1da177e4
LT
505 x->lft.soft_byte_limit = XFRM_INF;
506 x->lft.soft_packet_limit = XFRM_INF;
507 x->lft.hard_byte_limit = XFRM_INF;
508 x->lft.hard_packet_limit = XFRM_INF;
f8cd5488
JHS
509 x->replay_maxage = 0;
510 x->replay_maxdiff = 0;
df9dcb45
KM
511 x->inner_mode = NULL;
512 x->inner_mode_iaf = NULL;
1da177e4
LT
513 spin_lock_init(&x->lock);
514 }
515 return x;
516}
517EXPORT_SYMBOL(xfrm_state_alloc);
518
519void __xfrm_state_destroy(struct xfrm_state *x)
520{
98806f75
AD
521 struct net *net = xs_net(x);
522
547b792c 523 WARN_ON(x->km.state != XFRM_STATE_DEAD);
1da177e4
LT
524
525 spin_lock_bh(&xfrm_state_gc_lock);
98806f75 526 hlist_add_head(&x->gclist, &net->xfrm.state_gc_list);
1da177e4 527 spin_unlock_bh(&xfrm_state_gc_lock);
98806f75 528 schedule_work(&net->xfrm.state_gc_work);
1da177e4
LT
529}
530EXPORT_SYMBOL(__xfrm_state_destroy);
531
53bc6b4d 532int __xfrm_state_delete(struct xfrm_state *x)
1da177e4 533{
98806f75 534 struct net *net = xs_net(x);
26b15dad
JHS
535 int err = -ESRCH;
536
1da177e4
LT
537 if (x->km.state != XFRM_STATE_DEAD) {
538 x->km.state = XFRM_STATE_DEAD;
539 spin_lock(&xfrm_state_lock);
12a169e7 540 list_del(&x->km.all);
8f126e37 541 hlist_del(&x->bydst);
8f126e37 542 hlist_del(&x->bysrc);
a47f0ce0 543 if (x->id.spi)
8f126e37 544 hlist_del(&x->byspi);
98806f75 545 net->xfrm.state_num--;
1da177e4 546 spin_unlock(&xfrm_state_lock);
1da177e4 547
1da177e4
LT
548 /* All xfrm_state objects are created by xfrm_state_alloc.
549 * The xfrm_state_alloc call gives a reference, and that
550 * is what we are dropping here.
551 */
5dba4797 552 xfrm_state_put(x);
26b15dad 553 err = 0;
1da177e4 554 }
26b15dad
JHS
555
556 return err;
1da177e4 557}
53bc6b4d 558EXPORT_SYMBOL(__xfrm_state_delete);
1da177e4 559
26b15dad 560int xfrm_state_delete(struct xfrm_state *x)
1da177e4 561{
26b15dad
JHS
562 int err;
563
1da177e4 564 spin_lock_bh(&x->lock);
26b15dad 565 err = __xfrm_state_delete(x);
1da177e4 566 spin_unlock_bh(&x->lock);
26b15dad
JHS
567
568 return err;
1da177e4
LT
569}
570EXPORT_SYMBOL(xfrm_state_delete);
571
4aa2e62c
JL
572#ifdef CONFIG_SECURITY_NETWORK_XFRM
573static inline int
0e602451 574xfrm_state_flush_secctx_check(struct net *net, u8 proto, struct xfrm_audit *audit_info)
1da177e4 575{
4aa2e62c
JL
576 int i, err = 0;
577
0e602451 578 for (i = 0; i <= net->xfrm.state_hmask; i++) {
4aa2e62c
JL
579 struct hlist_node *entry;
580 struct xfrm_state *x;
581
0e602451 582 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+i, bydst) {
4aa2e62c
JL
583 if (xfrm_id_proto_match(x->id.proto, proto) &&
584 (err = security_xfrm_state_delete(x)) != 0) {
ab5f5e8b
JL
585 xfrm_audit_state_delete(x, 0,
586 audit_info->loginuid,
2532386f 587 audit_info->sessionid,
ab5f5e8b 588 audit_info->secid);
4aa2e62c
JL
589 return err;
590 }
591 }
592 }
593
594 return err;
595}
596#else
597static inline int
0e602451 598xfrm_state_flush_secctx_check(struct net *net, u8 proto, struct xfrm_audit *audit_info)
4aa2e62c
JL
599{
600 return 0;
601}
602#endif
603
0e602451 604int xfrm_state_flush(struct net *net, u8 proto, struct xfrm_audit *audit_info)
4aa2e62c 605{
19f4c713 606 int i, err = 0, cnt = 0;
1da177e4
LT
607
608 spin_lock_bh(&xfrm_state_lock);
0e602451 609 err = xfrm_state_flush_secctx_check(net, proto, audit_info);
4aa2e62c
JL
610 if (err)
611 goto out;
612
19f4c713 613 err = -ESRCH;
0e602451 614 for (i = 0; i <= net->xfrm.state_hmask; i++) {
8f126e37
DM
615 struct hlist_node *entry;
616 struct xfrm_state *x;
1da177e4 617restart:
0e602451 618 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+i, bydst) {
1da177e4 619 if (!xfrm_state_kern(x) &&
5794708f 620 xfrm_id_proto_match(x->id.proto, proto)) {
1da177e4
LT
621 xfrm_state_hold(x);
622 spin_unlock_bh(&xfrm_state_lock);
623
161a09e7 624 err = xfrm_state_delete(x);
ab5f5e8b
JL
625 xfrm_audit_state_delete(x, err ? 0 : 1,
626 audit_info->loginuid,
2532386f 627 audit_info->sessionid,
ab5f5e8b 628 audit_info->secid);
1da177e4 629 xfrm_state_put(x);
19f4c713 630 if (!err)
631 cnt++;
1da177e4
LT
632
633 spin_lock_bh(&xfrm_state_lock);
634 goto restart;
635 }
636 }
637 }
19f4c713 638 if (cnt)
639 err = 0;
4aa2e62c
JL
640
641out:
1da177e4 642 spin_unlock_bh(&xfrm_state_lock);
0e602451 643 wake_up(&net->xfrm.km_waitq);
4aa2e62c 644 return err;
1da177e4
LT
645}
646EXPORT_SYMBOL(xfrm_state_flush);
647
e071041b 648void xfrm_sad_getinfo(struct net *net, struct xfrmk_sadinfo *si)
28d8909b
JHS
649{
650 spin_lock_bh(&xfrm_state_lock);
e071041b
AD
651 si->sadcnt = net->xfrm.state_num;
652 si->sadhcnt = net->xfrm.state_hmask;
28d8909b
JHS
653 si->sadhmcnt = xfrm_state_hashmax;
654 spin_unlock_bh(&xfrm_state_lock);
655}
656EXPORT_SYMBOL(xfrm_sad_getinfo);
657
1da177e4
LT
658static int
659xfrm_init_tempsel(struct xfrm_state *x, struct flowi *fl,
660 struct xfrm_tmpl *tmpl,
661 xfrm_address_t *daddr, xfrm_address_t *saddr,
662 unsigned short family)
663{
664 struct xfrm_state_afinfo *afinfo = xfrm_state_get_afinfo(family);
665 if (!afinfo)
666 return -1;
667 afinfo->init_tempsel(x, fl, tmpl, daddr, saddr);
668 xfrm_state_put_afinfo(afinfo);
669 return 0;
670}
671
221df1ed 672static struct xfrm_state *__xfrm_state_lookup(struct net *net, xfrm_address_t *daddr, __be32 spi, u8 proto, unsigned short family)
edcd5821 673{
221df1ed 674 unsigned int h = xfrm_spi_hash(net, daddr, spi, proto, family);
edcd5821 675 struct xfrm_state *x;
8f126e37 676 struct hlist_node *entry;
edcd5821 677
221df1ed 678 hlist_for_each_entry(x, entry, net->xfrm.state_byspi+h, byspi) {
edcd5821
DM
679 if (x->props.family != family ||
680 x->id.spi != spi ||
1802571b
WY
681 x->id.proto != proto ||
682 xfrm_addr_cmp(&x->id.daddr, daddr, family))
edcd5821
DM
683 continue;
684
edcd5821
DM
685 xfrm_state_hold(x);
686 return x;
687 }
688
689 return NULL;
690}
691
221df1ed 692static struct xfrm_state *__xfrm_state_lookup_byaddr(struct net *net, xfrm_address_t *daddr, xfrm_address_t *saddr, u8 proto, unsigned short family)
edcd5821 693{
221df1ed 694 unsigned int h = xfrm_src_hash(net, daddr, saddr, family);
edcd5821 695 struct xfrm_state *x;
8f126e37 696 struct hlist_node *entry;
edcd5821 697
221df1ed 698 hlist_for_each_entry(x, entry, net->xfrm.state_bysrc+h, bysrc) {
edcd5821 699 if (x->props.family != family ||
1802571b
WY
700 x->id.proto != proto ||
701 xfrm_addr_cmp(&x->id.daddr, daddr, family) ||
702 xfrm_addr_cmp(&x->props.saddr, saddr, family))
edcd5821
DM
703 continue;
704
edcd5821
DM
705 xfrm_state_hold(x);
706 return x;
707 }
708
709 return NULL;
710}
711
712static inline struct xfrm_state *
713__xfrm_state_locate(struct xfrm_state *x, int use_spi, int family)
714{
221df1ed
AD
715 struct net *net = xs_net(x);
716
edcd5821 717 if (use_spi)
221df1ed 718 return __xfrm_state_lookup(net, &x->id.daddr, x->id.spi,
edcd5821
DM
719 x->id.proto, family);
720 else
221df1ed 721 return __xfrm_state_lookup_byaddr(net, &x->id.daddr,
edcd5821
DM
722 &x->props.saddr,
723 x->id.proto, family);
724}
725
98806f75 726static void xfrm_hash_grow_check(struct net *net, int have_hash_collision)
2fab22f2
PM
727{
728 if (have_hash_collision &&
98806f75
AD
729 (net->xfrm.state_hmask + 1) < xfrm_state_hashmax &&
730 net->xfrm.state_num > net->xfrm.state_hmask)
731 schedule_work(&net->xfrm.state_hash_work);
2fab22f2
PM
732}
733
08ec9af1
DM
734static void xfrm_state_look_at(struct xfrm_policy *pol, struct xfrm_state *x,
735 struct flowi *fl, unsigned short family,
736 xfrm_address_t *daddr, xfrm_address_t *saddr,
737 struct xfrm_state **best, int *acq_in_progress,
738 int *error)
739{
740 /* Resolution logic:
741 * 1. There is a valid state with matching selector. Done.
742 * 2. Valid state with inappropriate selector. Skip.
743 *
744 * Entering area of "sysdeps".
745 *
746 * 3. If state is not valid, selector is temporary, it selects
747 * only session which triggered previous resolution. Key
748 * manager will do something to install a state with proper
749 * selector.
750 */
751 if (x->km.state == XFRM_STATE_VALID) {
752 if ((x->sel.family &&
753 !xfrm_selector_match(&x->sel, fl, x->sel.family)) ||
754 !security_xfrm_state_pol_flow_match(x, pol, fl))
755 return;
756
757 if (!*best ||
758 (*best)->km.dying > x->km.dying ||
759 ((*best)->km.dying == x->km.dying &&
760 (*best)->curlft.add_time < x->curlft.add_time))
761 *best = x;
762 } else if (x->km.state == XFRM_STATE_ACQ) {
763 *acq_in_progress = 1;
764 } else if (x->km.state == XFRM_STATE_ERROR ||
765 x->km.state == XFRM_STATE_EXPIRED) {
766 if (xfrm_selector_match(&x->sel, fl, x->sel.family) &&
767 security_xfrm_state_pol_flow_match(x, pol, fl))
768 *error = -ESRCH;
769 }
770}
771
1da177e4 772struct xfrm_state *
a716c119 773xfrm_state_find(xfrm_address_t *daddr, xfrm_address_t *saddr,
1da177e4
LT
774 struct flowi *fl, struct xfrm_tmpl *tmpl,
775 struct xfrm_policy *pol, int *err,
776 unsigned short family)
777{
08ec9af1 778 static xfrm_address_t saddr_wildcard = { };
5447c5e4 779 struct net *net = xp_net(pol);
6a783c90 780 unsigned int h, h_wildcard;
8f126e37 781 struct hlist_node *entry;
37b08e34 782 struct xfrm_state *x, *x0, *to_put;
1da177e4
LT
783 int acquire_in_progress = 0;
784 int error = 0;
785 struct xfrm_state *best = NULL;
a716c119 786
37b08e34
DM
787 to_put = NULL;
788
1da177e4 789 spin_lock_bh(&xfrm_state_lock);
5447c5e4
AD
790 h = xfrm_dst_hash(net, daddr, saddr, tmpl->reqid, family);
791 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+h, bydst) {
1da177e4
LT
792 if (x->props.family == family &&
793 x->props.reqid == tmpl->reqid &&
fbd9a5b4 794 !(x->props.flags & XFRM_STATE_WILDRECV) &&
1da177e4
LT
795 xfrm_state_addr_check(x, daddr, saddr, family) &&
796 tmpl->mode == x->props.mode &&
797 tmpl->id.proto == x->id.proto &&
08ec9af1
DM
798 (tmpl->id.spi == x->id.spi || !tmpl->id.spi))
799 xfrm_state_look_at(pol, x, fl, family, daddr, saddr,
800 &best, &acquire_in_progress, &error);
801 }
802 if (best)
803 goto found;
804
6a783c90
ND
805 h_wildcard = xfrm_dst_hash(net, daddr, &saddr_wildcard, tmpl->reqid, family);
806 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+h_wildcard, bydst) {
08ec9af1
DM
807 if (x->props.family == family &&
808 x->props.reqid == tmpl->reqid &&
809 !(x->props.flags & XFRM_STATE_WILDRECV) &&
810 xfrm_state_addr_check(x, daddr, saddr, family) &&
811 tmpl->mode == x->props.mode &&
812 tmpl->id.proto == x->id.proto &&
813 (tmpl->id.spi == x->id.spi || !tmpl->id.spi))
814 xfrm_state_look_at(pol, x, fl, family, daddr, saddr,
815 &best, &acquire_in_progress, &error);
1da177e4
LT
816 }
817
08ec9af1 818found:
1da177e4
LT
819 x = best;
820 if (!x && !error && !acquire_in_progress) {
5c5d281a 821 if (tmpl->id.spi &&
5447c5e4 822 (x0 = __xfrm_state_lookup(net, daddr, tmpl->id.spi,
edcd5821 823 tmpl->id.proto, family)) != NULL) {
37b08e34 824 to_put = x0;
1da177e4
LT
825 error = -EEXIST;
826 goto out;
827 }
5447c5e4 828 x = xfrm_state_alloc(net);
1da177e4
LT
829 if (x == NULL) {
830 error = -ENOMEM;
831 goto out;
832 }
833 /* Initialize temporary selector matching only
834 * to current session. */
835 xfrm_init_tempsel(x, fl, tmpl, daddr, saddr, family);
836
e0d1caa7
VY
837 error = security_xfrm_state_alloc_acquire(x, pol->security, fl->secid);
838 if (error) {
839 x->km.state = XFRM_STATE_DEAD;
37b08e34 840 to_put = x;
e0d1caa7
VY
841 x = NULL;
842 goto out;
843 }
844
1da177e4
LT
845 if (km_query(x, tmpl, pol) == 0) {
846 x->km.state = XFRM_STATE_ACQ;
5447c5e4
AD
847 list_add(&x->km.all, &net->xfrm.state_all);
848 hlist_add_head(&x->bydst, net->xfrm.state_bydst+h);
849 h = xfrm_src_hash(net, daddr, saddr, family);
850 hlist_add_head(&x->bysrc, net->xfrm.state_bysrc+h);
1da177e4 851 if (x->id.spi) {
5447c5e4
AD
852 h = xfrm_spi_hash(net, &x->id.daddr, x->id.spi, x->id.proto, family);
853 hlist_add_head(&x->byspi, net->xfrm.state_byspi+h);
1da177e4 854 }
b27aeadb 855 x->lft.hard_add_expires_seconds = net->xfrm.sysctl_acq_expires;
9e0d57fd 856 tasklet_hrtimer_start(&x->mtimer, ktime_set(net->xfrm.sysctl_acq_expires, 0), HRTIMER_MODE_REL);
5447c5e4
AD
857 net->xfrm.state_num++;
858 xfrm_hash_grow_check(net, x->bydst.next != NULL);
1da177e4
LT
859 } else {
860 x->km.state = XFRM_STATE_DEAD;
37b08e34 861 to_put = x;
1da177e4
LT
862 x = NULL;
863 error = -ESRCH;
864 }
865 }
866out:
867 if (x)
868 xfrm_state_hold(x);
869 else
870 *err = acquire_in_progress ? -EAGAIN : error;
871 spin_unlock_bh(&xfrm_state_lock);
37b08e34
DM
872 if (to_put)
873 xfrm_state_put(to_put);
1da177e4
LT
874 return x;
875}
876
628529b6 877struct xfrm_state *
5447c5e4
AD
878xfrm_stateonly_find(struct net *net,
879 xfrm_address_t *daddr, xfrm_address_t *saddr,
628529b6
JHS
880 unsigned short family, u8 mode, u8 proto, u32 reqid)
881{
4bda4f25 882 unsigned int h;
628529b6
JHS
883 struct xfrm_state *rx = NULL, *x = NULL;
884 struct hlist_node *entry;
885
886 spin_lock(&xfrm_state_lock);
5447c5e4
AD
887 h = xfrm_dst_hash(net, daddr, saddr, reqid, family);
888 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+h, bydst) {
628529b6
JHS
889 if (x->props.family == family &&
890 x->props.reqid == reqid &&
891 !(x->props.flags & XFRM_STATE_WILDRECV) &&
892 xfrm_state_addr_check(x, daddr, saddr, family) &&
893 mode == x->props.mode &&
894 proto == x->id.proto &&
895 x->km.state == XFRM_STATE_VALID) {
896 rx = x;
897 break;
898 }
899 }
900
901 if (rx)
902 xfrm_state_hold(rx);
903 spin_unlock(&xfrm_state_lock);
904
905
906 return rx;
907}
908EXPORT_SYMBOL(xfrm_stateonly_find);
909
1da177e4
LT
910static void __xfrm_state_insert(struct xfrm_state *x)
911{
98806f75 912 struct net *net = xs_net(x);
a624c108 913 unsigned int h;
1da177e4 914
9d4a706d
DM
915 x->genid = ++xfrm_state_genid;
916
98806f75 917 list_add(&x->km.all, &net->xfrm.state_all);
4c563f76 918
98806f75 919 h = xfrm_dst_hash(net, &x->id.daddr, &x->props.saddr,
c1969f29 920 x->props.reqid, x->props.family);
98806f75 921 hlist_add_head(&x->bydst, net->xfrm.state_bydst+h);
1da177e4 922
98806f75
AD
923 h = xfrm_src_hash(net, &x->id.daddr, &x->props.saddr, x->props.family);
924 hlist_add_head(&x->bysrc, net->xfrm.state_bysrc+h);
1da177e4 925
7b4dc360 926 if (x->id.spi) {
98806f75 927 h = xfrm_spi_hash(net, &x->id.daddr, x->id.spi, x->id.proto,
6c44e6b7
MN
928 x->props.family);
929
98806f75 930 hlist_add_head(&x->byspi, net->xfrm.state_byspi+h);
6c44e6b7
MN
931 }
932
9e0d57fd 933 tasklet_hrtimer_start(&x->mtimer, ktime_set(1, 0), HRTIMER_MODE_REL);
a47f0ce0
DM
934 if (x->replay_maxage)
935 mod_timer(&x->rtimer, jiffies + x->replay_maxage);
f8cd5488 936
98806f75 937 wake_up(&net->xfrm.km_waitq);
f034b5d4 938
98806f75 939 net->xfrm.state_num++;
f034b5d4 940
98806f75 941 xfrm_hash_grow_check(net, x->bydst.next != NULL);
1da177e4
LT
942}
943
c7f5ea3a
DM
944/* xfrm_state_lock is held */
945static void __xfrm_state_bump_genids(struct xfrm_state *xnew)
946{
98806f75 947 struct net *net = xs_net(xnew);
c7f5ea3a
DM
948 unsigned short family = xnew->props.family;
949 u32 reqid = xnew->props.reqid;
950 struct xfrm_state *x;
951 struct hlist_node *entry;
952 unsigned int h;
953
98806f75
AD
954 h = xfrm_dst_hash(net, &xnew->id.daddr, &xnew->props.saddr, reqid, family);
955 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+h, bydst) {
c7f5ea3a
DM
956 if (x->props.family == family &&
957 x->props.reqid == reqid &&
c1969f29
DM
958 !xfrm_addr_cmp(&x->id.daddr, &xnew->id.daddr, family) &&
959 !xfrm_addr_cmp(&x->props.saddr, &xnew->props.saddr, family))
c7f5ea3a
DM
960 x->genid = xfrm_state_genid;
961 }
962}
963
1da177e4
LT
964void xfrm_state_insert(struct xfrm_state *x)
965{
966 spin_lock_bh(&xfrm_state_lock);
c7f5ea3a 967 __xfrm_state_bump_genids(x);
1da177e4
LT
968 __xfrm_state_insert(x);
969 spin_unlock_bh(&xfrm_state_lock);
970}
971EXPORT_SYMBOL(xfrm_state_insert);
972
2770834c 973/* xfrm_state_lock is held */
5447c5e4 974static struct xfrm_state *__find_acq_core(struct net *net, unsigned short family, u8 mode, u32 reqid, u8 proto, xfrm_address_t *daddr, xfrm_address_t *saddr, int create)
2770834c 975{
5447c5e4 976 unsigned int h = xfrm_dst_hash(net, daddr, saddr, reqid, family);
8f126e37 977 struct hlist_node *entry;
2770834c
DM
978 struct xfrm_state *x;
979
5447c5e4 980 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+h, bydst) {
2770834c
DM
981 if (x->props.reqid != reqid ||
982 x->props.mode != mode ||
983 x->props.family != family ||
984 x->km.state != XFRM_STATE_ACQ ||
75e252d9 985 x->id.spi != 0 ||
1802571b
WY
986 x->id.proto != proto ||
987 xfrm_addr_cmp(&x->id.daddr, daddr, family) ||
988 xfrm_addr_cmp(&x->props.saddr, saddr, family))
2770834c
DM
989 continue;
990
2770834c
DM
991 xfrm_state_hold(x);
992 return x;
993 }
994
995 if (!create)
996 return NULL;
997
5447c5e4 998 x = xfrm_state_alloc(net);
2770834c
DM
999 if (likely(x)) {
1000 switch (family) {
1001 case AF_INET:
1002 x->sel.daddr.a4 = daddr->a4;
1003 x->sel.saddr.a4 = saddr->a4;
1004 x->sel.prefixlen_d = 32;
1005 x->sel.prefixlen_s = 32;
1006 x->props.saddr.a4 = saddr->a4;
1007 x->id.daddr.a4 = daddr->a4;
1008 break;
1009
1010 case AF_INET6:
1011 ipv6_addr_copy((struct in6_addr *)x->sel.daddr.a6,
1012 (struct in6_addr *)daddr);
1013 ipv6_addr_copy((struct in6_addr *)x->sel.saddr.a6,
1014 (struct in6_addr *)saddr);
1015 x->sel.prefixlen_d = 128;
1016 x->sel.prefixlen_s = 128;
1017 ipv6_addr_copy((struct in6_addr *)x->props.saddr.a6,
1018 (struct in6_addr *)saddr);
1019 ipv6_addr_copy((struct in6_addr *)x->id.daddr.a6,
1020 (struct in6_addr *)daddr);
1021 break;
3ff50b79 1022 }
2770834c
DM
1023
1024 x->km.state = XFRM_STATE_ACQ;
1025 x->id.proto = proto;
1026 x->props.family = family;
1027 x->props.mode = mode;
1028 x->props.reqid = reqid;
b27aeadb 1029 x->lft.hard_add_expires_seconds = net->xfrm.sysctl_acq_expires;
2770834c 1030 xfrm_state_hold(x);
9e0d57fd 1031 tasklet_hrtimer_start(&x->mtimer, ktime_set(net->xfrm.sysctl_acq_expires, 0), HRTIMER_MODE_REL);
5447c5e4
AD
1032 list_add(&x->km.all, &net->xfrm.state_all);
1033 hlist_add_head(&x->bydst, net->xfrm.state_bydst+h);
1034 h = xfrm_src_hash(net, daddr, saddr, family);
1035 hlist_add_head(&x->bysrc, net->xfrm.state_bysrc+h);
918049f0 1036
5447c5e4 1037 net->xfrm.state_num++;
918049f0 1038
5447c5e4 1039 xfrm_hash_grow_check(net, x->bydst.next != NULL);
2770834c
DM
1040 }
1041
1042 return x;
1043}
1044
5447c5e4 1045static struct xfrm_state *__xfrm_find_acq_byseq(struct net *net, u32 seq);
1da177e4
LT
1046
1047int xfrm_state_add(struct xfrm_state *x)
1048{
5447c5e4 1049 struct net *net = xs_net(x);
37b08e34 1050 struct xfrm_state *x1, *to_put;
1da177e4
LT
1051 int family;
1052 int err;
eb2971b6 1053 int use_spi = xfrm_id_proto_match(x->id.proto, IPSEC_PROTO_ANY);
1da177e4
LT
1054
1055 family = x->props.family;
1da177e4 1056
37b08e34
DM
1057 to_put = NULL;
1058
1da177e4
LT
1059 spin_lock_bh(&xfrm_state_lock);
1060
edcd5821 1061 x1 = __xfrm_state_locate(x, use_spi, family);
1da177e4 1062 if (x1) {
37b08e34 1063 to_put = x1;
1da177e4
LT
1064 x1 = NULL;
1065 err = -EEXIST;
1066 goto out;
1067 }
1068
eb2971b6 1069 if (use_spi && x->km.seq) {
5447c5e4 1070 x1 = __xfrm_find_acq_byseq(net, x->km.seq);
75e252d9
JL
1071 if (x1 && ((x1->id.proto != x->id.proto) ||
1072 xfrm_addr_cmp(&x1->id.daddr, &x->id.daddr, family))) {
37b08e34 1073 to_put = x1;
1da177e4
LT
1074 x1 = NULL;
1075 }
1076 }
1077
eb2971b6 1078 if (use_spi && !x1)
5447c5e4 1079 x1 = __find_acq_core(net, family, x->props.mode, x->props.reqid,
2770834c
DM
1080 x->id.proto,
1081 &x->id.daddr, &x->props.saddr, 0);
1da177e4 1082
c7f5ea3a 1083 __xfrm_state_bump_genids(x);
1da177e4
LT
1084 __xfrm_state_insert(x);
1085 err = 0;
1086
1087out:
1088 spin_unlock_bh(&xfrm_state_lock);
1da177e4
LT
1089
1090 if (x1) {
1091 xfrm_state_delete(x1);
1092 xfrm_state_put(x1);
1093 }
1094
37b08e34
DM
1095 if (to_put)
1096 xfrm_state_put(to_put);
1097
1da177e4
LT
1098 return err;
1099}
1100EXPORT_SYMBOL(xfrm_state_add);
1101
80c9abaa 1102#ifdef CONFIG_XFRM_MIGRATE
6666351d 1103static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, int *errp)
80c9abaa 1104{
98806f75 1105 struct net *net = xs_net(orig);
80c9abaa 1106 int err = -ENOMEM;
98806f75 1107 struct xfrm_state *x = xfrm_state_alloc(net);
80c9abaa 1108 if (!x)
553f9118 1109 goto out;
80c9abaa
SS
1110
1111 memcpy(&x->id, &orig->id, sizeof(x->id));
1112 memcpy(&x->sel, &orig->sel, sizeof(x->sel));
1113 memcpy(&x->lft, &orig->lft, sizeof(x->lft));
1114 x->props.mode = orig->props.mode;
1115 x->props.replay_window = orig->props.replay_window;
1116 x->props.reqid = orig->props.reqid;
1117 x->props.family = orig->props.family;
1118 x->props.saddr = orig->props.saddr;
1119
1120 if (orig->aalg) {
4447bb33 1121 x->aalg = xfrm_algo_auth_clone(orig->aalg);
80c9abaa
SS
1122 if (!x->aalg)
1123 goto error;
1124 }
1125 x->props.aalgo = orig->props.aalgo;
1126
1127 if (orig->ealg) {
1128 x->ealg = xfrm_algo_clone(orig->ealg);
1129 if (!x->ealg)
1130 goto error;
1131 }
1132 x->props.ealgo = orig->props.ealgo;
1133
1134 if (orig->calg) {
1135 x->calg = xfrm_algo_clone(orig->calg);
1136 if (!x->calg)
1137 goto error;
1138 }
1139 x->props.calgo = orig->props.calgo;
1140
a716c119 1141 if (orig->encap) {
80c9abaa
SS
1142 x->encap = kmemdup(orig->encap, sizeof(*x->encap), GFP_KERNEL);
1143 if (!x->encap)
1144 goto error;
1145 }
1146
1147 if (orig->coaddr) {
1148 x->coaddr = kmemdup(orig->coaddr, sizeof(*x->coaddr),
1149 GFP_KERNEL);
1150 if (!x->coaddr)
1151 goto error;
1152 }
1153
1154 err = xfrm_init_state(x);
1155 if (err)
1156 goto error;
1157
1158 x->props.flags = orig->props.flags;
1159
1160 x->curlft.add_time = orig->curlft.add_time;
1161 x->km.state = orig->km.state;
1162 x->km.seq = orig->km.seq;
1163
1164 return x;
1165
1166 error:
553f9118
HX
1167 xfrm_state_put(x);
1168out:
80c9abaa
SS
1169 if (errp)
1170 *errp = err;
80c9abaa
SS
1171 return NULL;
1172}
80c9abaa
SS
1173
1174/* xfrm_state_lock is held */
1175struct xfrm_state * xfrm_migrate_state_find(struct xfrm_migrate *m)
1176{
1177 unsigned int h;
1178 struct xfrm_state *x;
1179 struct hlist_node *entry;
1180
1181 if (m->reqid) {
64d0cd00 1182 h = xfrm_dst_hash(&init_net, &m->old_daddr, &m->old_saddr,
80c9abaa 1183 m->reqid, m->old_family);
73d189dc 1184 hlist_for_each_entry(x, entry, init_net.xfrm.state_bydst+h, bydst) {
80c9abaa
SS
1185 if (x->props.mode != m->mode ||
1186 x->id.proto != m->proto)
1187 continue;
1188 if (m->reqid && x->props.reqid != m->reqid)
1189 continue;
1190 if (xfrm_addr_cmp(&x->id.daddr, &m->old_daddr,
1191 m->old_family) ||
1192 xfrm_addr_cmp(&x->props.saddr, &m->old_saddr,
1193 m->old_family))
1194 continue;
1195 xfrm_state_hold(x);
1196 return x;
1197 }
1198 } else {
64d0cd00 1199 h = xfrm_src_hash(&init_net, &m->old_daddr, &m->old_saddr,
80c9abaa 1200 m->old_family);
d320bbb3 1201 hlist_for_each_entry(x, entry, init_net.xfrm.state_bysrc+h, bysrc) {
80c9abaa
SS
1202 if (x->props.mode != m->mode ||
1203 x->id.proto != m->proto)
1204 continue;
1205 if (xfrm_addr_cmp(&x->id.daddr, &m->old_daddr,
1206 m->old_family) ||
1207 xfrm_addr_cmp(&x->props.saddr, &m->old_saddr,
1208 m->old_family))
1209 continue;
1210 xfrm_state_hold(x);
1211 return x;
1212 }
1213 }
1214
a716c119 1215 return NULL;
80c9abaa
SS
1216}
1217EXPORT_SYMBOL(xfrm_migrate_state_find);
1218
1219struct xfrm_state * xfrm_state_migrate(struct xfrm_state *x,
1220 struct xfrm_migrate *m)
1221{
1222 struct xfrm_state *xc;
1223 int err;
1224
1225 xc = xfrm_state_clone(x, &err);
1226 if (!xc)
1227 return NULL;
1228
1229 memcpy(&xc->id.daddr, &m->new_daddr, sizeof(xc->id.daddr));
1230 memcpy(&xc->props.saddr, &m->new_saddr, sizeof(xc->props.saddr));
1231
1232 /* add state */
1233 if (!xfrm_addr_cmp(&x->id.daddr, &m->new_daddr, m->new_family)) {
1234 /* a care is needed when the destination address of the
1235 state is to be updated as it is a part of triplet */
1236 xfrm_state_insert(xc);
1237 } else {
1238 if ((err = xfrm_state_add(xc)) < 0)
1239 goto error;
1240 }
1241
1242 return xc;
1243error:
1244 kfree(xc);
1245 return NULL;
1246}
1247EXPORT_SYMBOL(xfrm_state_migrate);
1248#endif
1249
1da177e4
LT
1250int xfrm_state_update(struct xfrm_state *x)
1251{
37b08e34 1252 struct xfrm_state *x1, *to_put;
1da177e4 1253 int err;
eb2971b6 1254 int use_spi = xfrm_id_proto_match(x->id.proto, IPSEC_PROTO_ANY);
1da177e4 1255
37b08e34
DM
1256 to_put = NULL;
1257
1da177e4 1258 spin_lock_bh(&xfrm_state_lock);
edcd5821 1259 x1 = __xfrm_state_locate(x, use_spi, x->props.family);
1da177e4
LT
1260
1261 err = -ESRCH;
1262 if (!x1)
1263 goto out;
1264
1265 if (xfrm_state_kern(x1)) {
37b08e34 1266 to_put = x1;
1da177e4
LT
1267 err = -EEXIST;
1268 goto out;
1269 }
1270
1271 if (x1->km.state == XFRM_STATE_ACQ) {
1272 __xfrm_state_insert(x);
1273 x = NULL;
1274 }
1275 err = 0;
1276
1277out:
1278 spin_unlock_bh(&xfrm_state_lock);
1da177e4 1279
37b08e34
DM
1280 if (to_put)
1281 xfrm_state_put(to_put);
1282
1da177e4
LT
1283 if (err)
1284 return err;
1285
1286 if (!x) {
1287 xfrm_state_delete(x1);
1288 xfrm_state_put(x1);
1289 return 0;
1290 }
1291
1292 err = -EINVAL;
1293 spin_lock_bh(&x1->lock);
1294 if (likely(x1->km.state == XFRM_STATE_VALID)) {
1295 if (x->encap && x1->encap)
1296 memcpy(x1->encap, x->encap, sizeof(*x1->encap));
060f02a3
NT
1297 if (x->coaddr && x1->coaddr) {
1298 memcpy(x1->coaddr, x->coaddr, sizeof(*x1->coaddr));
1299 }
1300 if (!use_spi && memcmp(&x1->sel, &x->sel, sizeof(x1->sel)))
1301 memcpy(&x1->sel, &x->sel, sizeof(x1->sel));
1da177e4
LT
1302 memcpy(&x1->lft, &x->lft, sizeof(x1->lft));
1303 x1->km.dying = 0;
1304
9e0d57fd 1305 tasklet_hrtimer_start(&x1->mtimer, ktime_set(1, 0), HRTIMER_MODE_REL);
1da177e4
LT
1306 if (x1->curlft.use_time)
1307 xfrm_state_check_expire(x1);
1308
1309 err = 0;
1310 }
1311 spin_unlock_bh(&x1->lock);
1312
1313 xfrm_state_put(x1);
1314
1315 return err;
1316}
1317EXPORT_SYMBOL(xfrm_state_update);
1318
1319int xfrm_state_check_expire(struct xfrm_state *x)
1320{
1321 if (!x->curlft.use_time)
9d729f72 1322 x->curlft.use_time = get_seconds();
1da177e4
LT
1323
1324 if (x->km.state != XFRM_STATE_VALID)
1325 return -EINVAL;
1326
1327 if (x->curlft.bytes >= x->lft.hard_byte_limit ||
1328 x->curlft.packets >= x->lft.hard_packet_limit) {
4666faab 1329 x->km.state = XFRM_STATE_EXPIRED;
9e0d57fd 1330 tasklet_hrtimer_start(&x->mtimer, ktime_set(0,0), HRTIMER_MODE_REL);
1da177e4
LT
1331 return -EINVAL;
1332 }
1333
1334 if (!x->km.dying &&
1335 (x->curlft.bytes >= x->lft.soft_byte_limit ||
4666faab
HX
1336 x->curlft.packets >= x->lft.soft_packet_limit)) {
1337 x->km.dying = 1;
53bc6b4d 1338 km_state_expired(x, 0, 0);
4666faab 1339 }
1da177e4
LT
1340 return 0;
1341}
1342EXPORT_SYMBOL(xfrm_state_check_expire);
1343
1da177e4 1344struct xfrm_state *
221df1ed 1345xfrm_state_lookup(struct net *net, xfrm_address_t *daddr, __be32 spi, u8 proto,
1da177e4
LT
1346 unsigned short family)
1347{
1348 struct xfrm_state *x;
1da177e4
LT
1349
1350 spin_lock_bh(&xfrm_state_lock);
221df1ed 1351 x = __xfrm_state_lookup(net, daddr, spi, proto, family);
1da177e4 1352 spin_unlock_bh(&xfrm_state_lock);
1da177e4
LT
1353 return x;
1354}
1355EXPORT_SYMBOL(xfrm_state_lookup);
1356
1357struct xfrm_state *
221df1ed
AD
1358xfrm_state_lookup_byaddr(struct net *net,
1359 xfrm_address_t *daddr, xfrm_address_t *saddr,
eb2971b6
MN
1360 u8 proto, unsigned short family)
1361{
1362 struct xfrm_state *x;
eb2971b6
MN
1363
1364 spin_lock_bh(&xfrm_state_lock);
221df1ed 1365 x = __xfrm_state_lookup_byaddr(net, daddr, saddr, proto, family);
eb2971b6 1366 spin_unlock_bh(&xfrm_state_lock);
eb2971b6
MN
1367 return x;
1368}
1369EXPORT_SYMBOL(xfrm_state_lookup_byaddr);
1370
1371struct xfrm_state *
5447c5e4 1372xfrm_find_acq(struct net *net, u8 mode, u32 reqid, u8 proto,
a716c119 1373 xfrm_address_t *daddr, xfrm_address_t *saddr,
1da177e4
LT
1374 int create, unsigned short family)
1375{
1376 struct xfrm_state *x;
1da177e4
LT
1377
1378 spin_lock_bh(&xfrm_state_lock);
5447c5e4 1379 x = __find_acq_core(net, family, mode, reqid, proto, daddr, saddr, create);
1da177e4 1380 spin_unlock_bh(&xfrm_state_lock);
2770834c 1381
1da177e4
LT
1382 return x;
1383}
1384EXPORT_SYMBOL(xfrm_find_acq);
1385
41a49cc3
MN
1386#ifdef CONFIG_XFRM_SUB_POLICY
1387int
1388xfrm_tmpl_sort(struct xfrm_tmpl **dst, struct xfrm_tmpl **src, int n,
1389 unsigned short family)
1390{
1391 int err = 0;
1392 struct xfrm_state_afinfo *afinfo = xfrm_state_get_afinfo(family);
1393 if (!afinfo)
1394 return -EAFNOSUPPORT;
1395
1396 spin_lock_bh(&xfrm_state_lock);
1397 if (afinfo->tmpl_sort)
1398 err = afinfo->tmpl_sort(dst, src, n);
1399 spin_unlock_bh(&xfrm_state_lock);
1400 xfrm_state_put_afinfo(afinfo);
1401 return err;
1402}
1403EXPORT_SYMBOL(xfrm_tmpl_sort);
1404
1405int
1406xfrm_state_sort(struct xfrm_state **dst, struct xfrm_state **src, int n,
1407 unsigned short family)
1408{
1409 int err = 0;
1410 struct xfrm_state_afinfo *afinfo = xfrm_state_get_afinfo(family);
1411 if (!afinfo)
1412 return -EAFNOSUPPORT;
1413
1414 spin_lock_bh(&xfrm_state_lock);
1415 if (afinfo->state_sort)
1416 err = afinfo->state_sort(dst, src, n);
1417 spin_unlock_bh(&xfrm_state_lock);
1418 xfrm_state_put_afinfo(afinfo);
1419 return err;
1420}
1421EXPORT_SYMBOL(xfrm_state_sort);
1422#endif
1423
1da177e4
LT
1424/* Silly enough, but I'm lazy to build resolution list */
1425
5447c5e4 1426static struct xfrm_state *__xfrm_find_acq_byseq(struct net *net, u32 seq)
1da177e4
LT
1427{
1428 int i;
1da177e4 1429
5447c5e4 1430 for (i = 0; i <= net->xfrm.state_hmask; i++) {
8f126e37
DM
1431 struct hlist_node *entry;
1432 struct xfrm_state *x;
1433
5447c5e4 1434 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+i, bydst) {
8f126e37
DM
1435 if (x->km.seq == seq &&
1436 x->km.state == XFRM_STATE_ACQ) {
1da177e4
LT
1437 xfrm_state_hold(x);
1438 return x;
1439 }
1440 }
1441 }
1442 return NULL;
1443}
1444
5447c5e4 1445struct xfrm_state *xfrm_find_acq_byseq(struct net *net, u32 seq)
1da177e4
LT
1446{
1447 struct xfrm_state *x;
1448
1449 spin_lock_bh(&xfrm_state_lock);
5447c5e4 1450 x = __xfrm_find_acq_byseq(net, seq);
1da177e4
LT
1451 spin_unlock_bh(&xfrm_state_lock);
1452 return x;
1453}
1454EXPORT_SYMBOL(xfrm_find_acq_byseq);
1455
1456u32 xfrm_get_acqseq(void)
1457{
1458 u32 res;
6836b9bd 1459 static atomic_t acqseq;
1460
1461 do {
1462 res = atomic_inc_return(&acqseq);
1463 } while (!res);
1da177e4 1464
1da177e4
LT
1465 return res;
1466}
1467EXPORT_SYMBOL(xfrm_get_acqseq);
1468
658b219e 1469int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high)
1da177e4 1470{
221df1ed 1471 struct net *net = xs_net(x);
f034b5d4 1472 unsigned int h;
1da177e4 1473 struct xfrm_state *x0;
658b219e
HX
1474 int err = -ENOENT;
1475 __be32 minspi = htonl(low);
1476 __be32 maxspi = htonl(high);
1da177e4 1477
658b219e
HX
1478 spin_lock_bh(&x->lock);
1479 if (x->km.state == XFRM_STATE_DEAD)
1480 goto unlock;
1481
1482 err = 0;
1da177e4 1483 if (x->id.spi)
658b219e
HX
1484 goto unlock;
1485
1486 err = -ENOENT;
1da177e4
LT
1487
1488 if (minspi == maxspi) {
221df1ed 1489 x0 = xfrm_state_lookup(net, &x->id.daddr, minspi, x->id.proto, x->props.family);
1da177e4
LT
1490 if (x0) {
1491 xfrm_state_put(x0);
658b219e 1492 goto unlock;
1da177e4
LT
1493 }
1494 x->id.spi = minspi;
1495 } else {
1496 u32 spi = 0;
26977b4e
AV
1497 for (h=0; h<high-low+1; h++) {
1498 spi = low + net_random()%(high-low+1);
221df1ed 1499 x0 = xfrm_state_lookup(net, &x->id.daddr, htonl(spi), x->id.proto, x->props.family);
1da177e4
LT
1500 if (x0 == NULL) {
1501 x->id.spi = htonl(spi);
1502 break;
1503 }
1504 xfrm_state_put(x0);
1505 }
1506 }
1507 if (x->id.spi) {
1508 spin_lock_bh(&xfrm_state_lock);
12604d8a
AD
1509 h = xfrm_spi_hash(net, &x->id.daddr, x->id.spi, x->id.proto, x->props.family);
1510 hlist_add_head(&x->byspi, net->xfrm.state_byspi+h);
1da177e4 1511 spin_unlock_bh(&xfrm_state_lock);
658b219e
HX
1512
1513 err = 0;
1da177e4 1514 }
658b219e
HX
1515
1516unlock:
1517 spin_unlock_bh(&x->lock);
1518
1519 return err;
1da177e4
LT
1520}
1521EXPORT_SYMBOL(xfrm_alloc_spi);
1522
284fa7da 1523int xfrm_state_walk(struct net *net, struct xfrm_state_walk *walk,
4c563f76 1524 int (*func)(struct xfrm_state *, int, void*),
1da177e4
LT
1525 void *data)
1526{
12a169e7
HX
1527 struct xfrm_state *state;
1528 struct xfrm_state_walk *x;
1da177e4
LT
1529 int err = 0;
1530
12a169e7 1531 if (walk->seq != 0 && list_empty(&walk->all))
4c563f76
TT
1532 return 0;
1533
1da177e4 1534 spin_lock_bh(&xfrm_state_lock);
12a169e7 1535 if (list_empty(&walk->all))
284fa7da 1536 x = list_first_entry(&net->xfrm.state_all, struct xfrm_state_walk, all);
12a169e7
HX
1537 else
1538 x = list_entry(&walk->all, struct xfrm_state_walk, all);
284fa7da 1539 list_for_each_entry_from(x, &net->xfrm.state_all, all) {
12a169e7 1540 if (x->state == XFRM_STATE_DEAD)
4c563f76 1541 continue;
12a169e7
HX
1542 state = container_of(x, struct xfrm_state, km);
1543 if (!xfrm_id_proto_match(state->id.proto, walk->proto))
4c563f76 1544 continue;
12a169e7
HX
1545 err = func(state, walk->seq, data);
1546 if (err) {
1547 list_move_tail(&walk->all, &x->all);
1548 goto out;
1da177e4 1549 }
12a169e7 1550 walk->seq++;
1da177e4 1551 }
12a169e7 1552 if (walk->seq == 0) {
1da177e4
LT
1553 err = -ENOENT;
1554 goto out;
1555 }
12a169e7 1556 list_del_init(&walk->all);
1da177e4
LT
1557out:
1558 spin_unlock_bh(&xfrm_state_lock);
1559 return err;
1560}
1561EXPORT_SYMBOL(xfrm_state_walk);
1562
5c182458
HX
1563void xfrm_state_walk_init(struct xfrm_state_walk *walk, u8 proto)
1564{
12a169e7 1565 INIT_LIST_HEAD(&walk->all);
5c182458 1566 walk->proto = proto;
12a169e7
HX
1567 walk->state = XFRM_STATE_DEAD;
1568 walk->seq = 0;
5c182458
HX
1569}
1570EXPORT_SYMBOL(xfrm_state_walk_init);
1571
abb81c4f
HX
1572void xfrm_state_walk_done(struct xfrm_state_walk *walk)
1573{
12a169e7 1574 if (list_empty(&walk->all))
5c182458 1575 return;
5c182458 1576
12a169e7
HX
1577 spin_lock_bh(&xfrm_state_lock);
1578 list_del(&walk->all);
7d0b591c 1579 spin_unlock_bh(&xfrm_state_lock);
abb81c4f
HX
1580}
1581EXPORT_SYMBOL(xfrm_state_walk_done);
1582
f8cd5488
JHS
1583
1584void xfrm_replay_notify(struct xfrm_state *x, int event)
1585{
1586 struct km_event c;
1587 /* we send notify messages in case
1588 * 1. we updated on of the sequence numbers, and the seqno difference
1589 * is at least x->replay_maxdiff, in this case we also update the
1590 * timeout of our timer function
1591 * 2. if x->replay_maxage has elapsed since last update,
1592 * and there were changes
1593 *
1594 * The state structure must be locked!
1595 */
1596
1597 switch (event) {
1598 case XFRM_REPLAY_UPDATE:
1599 if (x->replay_maxdiff &&
1600 (x->replay.seq - x->preplay.seq < x->replay_maxdiff) &&
2717096a
JHS
1601 (x->replay.oseq - x->preplay.oseq < x->replay_maxdiff)) {
1602 if (x->xflags & XFRM_TIME_DEFER)
1603 event = XFRM_REPLAY_TIMEOUT;
1604 else
1605 return;
1606 }
f8cd5488
JHS
1607
1608 break;
1609
1610 case XFRM_REPLAY_TIMEOUT:
1611 if ((x->replay.seq == x->preplay.seq) &&
1612 (x->replay.bitmap == x->preplay.bitmap) &&
2717096a
JHS
1613 (x->replay.oseq == x->preplay.oseq)) {
1614 x->xflags |= XFRM_TIME_DEFER;
f8cd5488 1615 return;
2717096a 1616 }
f8cd5488
JHS
1617
1618 break;
1619 }
1620
1621 memcpy(&x->preplay, &x->replay, sizeof(struct xfrm_replay_state));
1622 c.event = XFRM_MSG_NEWAE;
1623 c.data.aevent = event;
1624 km_state_notify(x, &c);
1625
f8cd5488 1626 if (x->replay_maxage &&
a47f0ce0 1627 !mod_timer(&x->rtimer, jiffies + x->replay_maxage))
2717096a 1628 x->xflags &= ~XFRM_TIME_DEFER;
f8cd5488
JHS
1629}
1630
1631static void xfrm_replay_timer_handler(unsigned long data)
1632{
1633 struct xfrm_state *x = (struct xfrm_state*)data;
1634
1635 spin_lock(&x->lock);
1636
2717096a 1637 if (x->km.state == XFRM_STATE_VALID) {
a6483b79 1638 if (xfrm_aevent_is_on(xs_net(x)))
2717096a
JHS
1639 xfrm_replay_notify(x, XFRM_REPLAY_TIMEOUT);
1640 else
1641 x->xflags |= XFRM_TIME_DEFER;
1642 }
f8cd5488
JHS
1643
1644 spin_unlock(&x->lock);
1645}
1646
afeb14b4
PM
1647int xfrm_replay_check(struct xfrm_state *x,
1648 struct sk_buff *skb, __be32 net_seq)
1da177e4
LT
1649{
1650 u32 diff;
a252cc23 1651 u32 seq = ntohl(net_seq);
1da177e4
LT
1652
1653 if (unlikely(seq == 0))
afeb14b4 1654 goto err;
1da177e4
LT
1655
1656 if (likely(seq > x->replay.seq))
1657 return 0;
1658
1659 diff = x->replay.seq - seq;
4c4d51a7
HX
1660 if (diff >= min_t(unsigned int, x->props.replay_window,
1661 sizeof(x->replay.bitmap) * 8)) {
1da177e4 1662 x->stats.replay_window++;
afeb14b4 1663 goto err;
1da177e4
LT
1664 }
1665
1666 if (x->replay.bitmap & (1U << diff)) {
1667 x->stats.replay++;
afeb14b4 1668 goto err;
1da177e4
LT
1669 }
1670 return 0;
afeb14b4
PM
1671
1672err:
1673 xfrm_audit_state_replay(x, skb, net_seq);
1674 return -EINVAL;
1da177e4 1675}
1da177e4 1676
61f4627b 1677void xfrm_replay_advance(struct xfrm_state *x, __be32 net_seq)
1da177e4
LT
1678{
1679 u32 diff;
61f4627b 1680 u32 seq = ntohl(net_seq);
1da177e4
LT
1681
1682 if (seq > x->replay.seq) {
1683 diff = seq - x->replay.seq;
1684 if (diff < x->props.replay_window)
1685 x->replay.bitmap = ((x->replay.bitmap) << diff) | 1;
1686 else
1687 x->replay.bitmap = 1;
1688 x->replay.seq = seq;
1689 } else {
1690 diff = x->replay.seq - seq;
1691 x->replay.bitmap |= (1U << diff);
1692 }
f8cd5488 1693
a6483b79 1694 if (xfrm_aevent_is_on(xs_net(x)))
f8cd5488 1695 xfrm_replay_notify(x, XFRM_REPLAY_UPDATE);
1da177e4 1696}
1da177e4 1697
df01812e 1698static LIST_HEAD(xfrm_km_list);
1da177e4
LT
1699static DEFINE_RWLOCK(xfrm_km_lock);
1700
26b15dad 1701void km_policy_notify(struct xfrm_policy *xp, int dir, struct km_event *c)
1da177e4
LT
1702{
1703 struct xfrm_mgr *km;
1704
26b15dad
JHS
1705 read_lock(&xfrm_km_lock);
1706 list_for_each_entry(km, &xfrm_km_list, list)
1707 if (km->notify_policy)
1708 km->notify_policy(xp, dir, c);
1709 read_unlock(&xfrm_km_lock);
1710}
1da177e4 1711
26b15dad
JHS
1712void km_state_notify(struct xfrm_state *x, struct km_event *c)
1713{
1714 struct xfrm_mgr *km;
1da177e4
LT
1715 read_lock(&xfrm_km_lock);
1716 list_for_each_entry(km, &xfrm_km_list, list)
26b15dad
JHS
1717 if (km->notify)
1718 km->notify(x, c);
1da177e4 1719 read_unlock(&xfrm_km_lock);
26b15dad
JHS
1720}
1721
1722EXPORT_SYMBOL(km_policy_notify);
1723EXPORT_SYMBOL(km_state_notify);
1724
53bc6b4d 1725void km_state_expired(struct xfrm_state *x, int hard, u32 pid)
26b15dad 1726{
98806f75 1727 struct net *net = xs_net(x);
26b15dad
JHS
1728 struct km_event c;
1729
bf08867f 1730 c.data.hard = hard;
53bc6b4d 1731 c.pid = pid;
f60f6b8f 1732 c.event = XFRM_MSG_EXPIRE;
26b15dad 1733 km_state_notify(x, &c);
1da177e4
LT
1734
1735 if (hard)
98806f75 1736 wake_up(&net->xfrm.km_waitq);
1da177e4
LT
1737}
1738
53bc6b4d 1739EXPORT_SYMBOL(km_state_expired);
26b15dad
JHS
1740/*
1741 * We send to all registered managers regardless of failure
1742 * We are happy with one success
1743*/
980ebd25 1744int km_query(struct xfrm_state *x, struct xfrm_tmpl *t, struct xfrm_policy *pol)
1da177e4 1745{
26b15dad 1746 int err = -EINVAL, acqret;
1da177e4
LT
1747 struct xfrm_mgr *km;
1748
1749 read_lock(&xfrm_km_lock);
1750 list_for_each_entry(km, &xfrm_km_list, list) {
26b15dad
JHS
1751 acqret = km->acquire(x, t, pol, XFRM_POLICY_OUT);
1752 if (!acqret)
1753 err = acqret;
1da177e4
LT
1754 }
1755 read_unlock(&xfrm_km_lock);
1756 return err;
1757}
980ebd25 1758EXPORT_SYMBOL(km_query);
1da177e4 1759
5d36b180 1760int km_new_mapping(struct xfrm_state *x, xfrm_address_t *ipaddr, __be16 sport)
1da177e4
LT
1761{
1762 int err = -EINVAL;
1763 struct xfrm_mgr *km;
1764
1765 read_lock(&xfrm_km_lock);
1766 list_for_each_entry(km, &xfrm_km_list, list) {
1767 if (km->new_mapping)
1768 err = km->new_mapping(x, ipaddr, sport);
1769 if (!err)
1770 break;
1771 }
1772 read_unlock(&xfrm_km_lock);
1773 return err;
1774}
1775EXPORT_SYMBOL(km_new_mapping);
1776
6c5c8ca7 1777void km_policy_expired(struct xfrm_policy *pol, int dir, int hard, u32 pid)
1da177e4 1778{
98806f75 1779 struct net *net = xp_net(pol);
26b15dad 1780 struct km_event c;
1da177e4 1781
bf08867f 1782 c.data.hard = hard;
6c5c8ca7 1783 c.pid = pid;
f60f6b8f 1784 c.event = XFRM_MSG_POLEXPIRE;
26b15dad 1785 km_policy_notify(pol, dir, &c);
1da177e4
LT
1786
1787 if (hard)
98806f75 1788 wake_up(&net->xfrm.km_waitq);
1da177e4 1789}
a70fcb0b 1790EXPORT_SYMBOL(km_policy_expired);
1da177e4 1791
2d60abc2 1792#ifdef CONFIG_XFRM_MIGRATE
80c9abaa 1793int km_migrate(struct xfrm_selector *sel, u8 dir, u8 type,
13c1d189
AE
1794 struct xfrm_migrate *m, int num_migrate,
1795 struct xfrm_kmaddress *k)
80c9abaa
SS
1796{
1797 int err = -EINVAL;
1798 int ret;
1799 struct xfrm_mgr *km;
1800
1801 read_lock(&xfrm_km_lock);
1802 list_for_each_entry(km, &xfrm_km_list, list) {
1803 if (km->migrate) {
13c1d189 1804 ret = km->migrate(sel, dir, type, m, num_migrate, k);
80c9abaa
SS
1805 if (!ret)
1806 err = ret;
1807 }
1808 }
1809 read_unlock(&xfrm_km_lock);
1810 return err;
1811}
1812EXPORT_SYMBOL(km_migrate);
2d60abc2 1813#endif
80c9abaa 1814
db983c11 1815int km_report(struct net *net, u8 proto, struct xfrm_selector *sel, xfrm_address_t *addr)
97a64b45
MN
1816{
1817 int err = -EINVAL;
1818 int ret;
1819 struct xfrm_mgr *km;
1820
1821 read_lock(&xfrm_km_lock);
1822 list_for_each_entry(km, &xfrm_km_list, list) {
1823 if (km->report) {
db983c11 1824 ret = km->report(net, proto, sel, addr);
97a64b45
MN
1825 if (!ret)
1826 err = ret;
1827 }
1828 }
1829 read_unlock(&xfrm_km_lock);
1830 return err;
1831}
1832EXPORT_SYMBOL(km_report);
1833
1da177e4
LT
1834int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen)
1835{
1836 int err;
1837 u8 *data;
1838 struct xfrm_mgr *km;
1839 struct xfrm_policy *pol = NULL;
1840
1841 if (optlen <= 0 || optlen > PAGE_SIZE)
1842 return -EMSGSIZE;
1843
1844 data = kmalloc(optlen, GFP_KERNEL);
1845 if (!data)
1846 return -ENOMEM;
1847
1848 err = -EFAULT;
1849 if (copy_from_user(data, optval, optlen))
1850 goto out;
1851
1852 err = -EINVAL;
1853 read_lock(&xfrm_km_lock);
1854 list_for_each_entry(km, &xfrm_km_list, list) {
cb969f07 1855 pol = km->compile_policy(sk, optname, data,
1da177e4
LT
1856 optlen, &err);
1857 if (err >= 0)
1858 break;
1859 }
1860 read_unlock(&xfrm_km_lock);
1861
1862 if (err >= 0) {
1863 xfrm_sk_policy_insert(sk, err, pol);
1864 xfrm_pol_put(pol);
1865 err = 0;
1866 }
1867
1868out:
1869 kfree(data);
1870 return err;
1871}
1872EXPORT_SYMBOL(xfrm_user_policy);
1873
1874int xfrm_register_km(struct xfrm_mgr *km)
1875{
1876 write_lock_bh(&xfrm_km_lock);
1877 list_add_tail(&km->list, &xfrm_km_list);
1878 write_unlock_bh(&xfrm_km_lock);
1879 return 0;
1880}
1881EXPORT_SYMBOL(xfrm_register_km);
1882
1883int xfrm_unregister_km(struct xfrm_mgr *km)
1884{
1885 write_lock_bh(&xfrm_km_lock);
1886 list_del(&km->list);
1887 write_unlock_bh(&xfrm_km_lock);
1888 return 0;
1889}
1890EXPORT_SYMBOL(xfrm_unregister_km);
1891
1892int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo)
1893{
1894 int err = 0;
1895 if (unlikely(afinfo == NULL))
1896 return -EINVAL;
1897 if (unlikely(afinfo->family >= NPROTO))
1898 return -EAFNOSUPPORT;
f3111502 1899 write_lock_bh(&xfrm_state_afinfo_lock);
1da177e4
LT
1900 if (unlikely(xfrm_state_afinfo[afinfo->family] != NULL))
1901 err = -ENOBUFS;
edcd5821 1902 else
1da177e4 1903 xfrm_state_afinfo[afinfo->family] = afinfo;
f3111502 1904 write_unlock_bh(&xfrm_state_afinfo_lock);
1da177e4
LT
1905 return err;
1906}
1907EXPORT_SYMBOL(xfrm_state_register_afinfo);
1908
1909int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo)
1910{
1911 int err = 0;
1912 if (unlikely(afinfo == NULL))
1913 return -EINVAL;
1914 if (unlikely(afinfo->family >= NPROTO))
1915 return -EAFNOSUPPORT;
f3111502 1916 write_lock_bh(&xfrm_state_afinfo_lock);
1da177e4
LT
1917 if (likely(xfrm_state_afinfo[afinfo->family] != NULL)) {
1918 if (unlikely(xfrm_state_afinfo[afinfo->family] != afinfo))
1919 err = -EINVAL;
edcd5821 1920 else
1da177e4 1921 xfrm_state_afinfo[afinfo->family] = NULL;
1da177e4 1922 }
f3111502 1923 write_unlock_bh(&xfrm_state_afinfo_lock);
1da177e4
LT
1924 return err;
1925}
1926EXPORT_SYMBOL(xfrm_state_unregister_afinfo);
1927
17c2a42a 1928static struct xfrm_state_afinfo *xfrm_state_get_afinfo(unsigned int family)
1da177e4
LT
1929{
1930 struct xfrm_state_afinfo *afinfo;
1931 if (unlikely(family >= NPROTO))
1932 return NULL;
1933 read_lock(&xfrm_state_afinfo_lock);
1934 afinfo = xfrm_state_afinfo[family];
546be240
HX
1935 if (unlikely(!afinfo))
1936 read_unlock(&xfrm_state_afinfo_lock);
1da177e4
LT
1937 return afinfo;
1938}
1939
17c2a42a 1940static void xfrm_state_put_afinfo(struct xfrm_state_afinfo *afinfo)
9a429c49 1941 __releases(xfrm_state_afinfo_lock)
1da177e4 1942{
546be240 1943 read_unlock(&xfrm_state_afinfo_lock);
1da177e4
LT
1944}
1945
1946/* Temporarily located here until net/xfrm/xfrm_tunnel.c is created */
1947void xfrm_state_delete_tunnel(struct xfrm_state *x)
1948{
1949 if (x->tunnel) {
1950 struct xfrm_state *t = x->tunnel;
1951
1952 if (atomic_read(&t->tunnel_users) == 2)
1953 xfrm_state_delete(t);
1954 atomic_dec(&t->tunnel_users);
1955 xfrm_state_put(t);
1956 x->tunnel = NULL;
1957 }
1958}
1959EXPORT_SYMBOL(xfrm_state_delete_tunnel);
1960
1961int xfrm_state_mtu(struct xfrm_state *x, int mtu)
1962{
c5c25238 1963 int res;
1da177e4 1964
c5c25238
PM
1965 spin_lock_bh(&x->lock);
1966 if (x->km.state == XFRM_STATE_VALID &&
1967 x->type && x->type->get_mtu)
1968 res = x->type->get_mtu(x, mtu);
1969 else
28121617 1970 res = mtu - x->props.header_len;
c5c25238 1971 spin_unlock_bh(&x->lock);
1da177e4
LT
1972 return res;
1973}
1974
72cb6962
HX
1975int xfrm_init_state(struct xfrm_state *x)
1976{
d094cd83 1977 struct xfrm_state_afinfo *afinfo;
df9dcb45 1978 struct xfrm_mode *inner_mode;
d094cd83 1979 int family = x->props.family;
72cb6962
HX
1980 int err;
1981
d094cd83
HX
1982 err = -EAFNOSUPPORT;
1983 afinfo = xfrm_state_get_afinfo(family);
1984 if (!afinfo)
1985 goto error;
1986
1987 err = 0;
1988 if (afinfo->init_flags)
1989 err = afinfo->init_flags(x);
1990
1991 xfrm_state_put_afinfo(afinfo);
1992
1993 if (err)
1994 goto error;
1995
1996 err = -EPROTONOSUPPORT;
13996378 1997
df9dcb45
KM
1998 if (x->sel.family != AF_UNSPEC) {
1999 inner_mode = xfrm_get_mode(x->props.mode, x->sel.family);
2000 if (inner_mode == NULL)
2001 goto error;
2002
2003 if (!(inner_mode->flags & XFRM_MODE_FLAG_TUNNEL) &&
2004 family != x->sel.family) {
2005 xfrm_put_mode(inner_mode);
2006 goto error;
2007 }
2008
2009 x->inner_mode = inner_mode;
2010 } else {
2011 struct xfrm_mode *inner_mode_iaf;
d81d2285 2012 int iafamily = AF_INET;
df9dcb45 2013
d81d2285 2014 inner_mode = xfrm_get_mode(x->props.mode, x->props.family);
df9dcb45
KM
2015 if (inner_mode == NULL)
2016 goto error;
2017
2018 if (!(inner_mode->flags & XFRM_MODE_FLAG_TUNNEL)) {
2019 xfrm_put_mode(inner_mode);
2020 goto error;
2021 }
d81d2285 2022 x->inner_mode = inner_mode;
df9dcb45 2023
d81d2285
MW
2024 if (x->props.family == AF_INET)
2025 iafamily = AF_INET6;
df9dcb45 2026
d81d2285
MW
2027 inner_mode_iaf = xfrm_get_mode(x->props.mode, iafamily);
2028 if (inner_mode_iaf) {
2029 if (inner_mode_iaf->flags & XFRM_MODE_FLAG_TUNNEL)
2030 x->inner_mode_iaf = inner_mode_iaf;
2031 else
2032 xfrm_put_mode(inner_mode_iaf);
df9dcb45
KM
2033 }
2034 }
13996378 2035
d094cd83 2036 x->type = xfrm_get_type(x->id.proto, family);
72cb6962
HX
2037 if (x->type == NULL)
2038 goto error;
2039
2040 err = x->type->init_state(x);
2041 if (err)
2042 goto error;
2043
13996378
HX
2044 x->outer_mode = xfrm_get_mode(x->props.mode, family);
2045 if (x->outer_mode == NULL)
b59f45d0
HX
2046 goto error;
2047
72cb6962
HX
2048 x->km.state = XFRM_STATE_VALID;
2049
2050error:
2051 return err;
2052}
2053
2054EXPORT_SYMBOL(xfrm_init_state);
a716c119 2055
d62ddc21 2056int __net_init xfrm_state_init(struct net *net)
1da177e4 2057{
f034b5d4
DM
2058 unsigned int sz;
2059
9d4139c7
AD
2060 INIT_LIST_HEAD(&net->xfrm.state_all);
2061
f034b5d4
DM
2062 sz = sizeof(struct hlist_head) * 8;
2063
73d189dc
AD
2064 net->xfrm.state_bydst = xfrm_hash_alloc(sz);
2065 if (!net->xfrm.state_bydst)
2066 goto out_bydst;
d320bbb3
AD
2067 net->xfrm.state_bysrc = xfrm_hash_alloc(sz);
2068 if (!net->xfrm.state_bysrc)
2069 goto out_bysrc;
b754a4fd
AD
2070 net->xfrm.state_byspi = xfrm_hash_alloc(sz);
2071 if (!net->xfrm.state_byspi)
2072 goto out_byspi;
529983ec 2073 net->xfrm.state_hmask = ((sz / sizeof(struct hlist_head)) - 1);
1da177e4 2074
0bf7c5b0 2075 net->xfrm.state_num = 0;
63082733 2076 INIT_WORK(&net->xfrm.state_hash_work, xfrm_hash_resize);
b8a0ae20 2077 INIT_HLIST_HEAD(&net->xfrm.state_gc_list);
c7837144 2078 INIT_WORK(&net->xfrm.state_gc_work, xfrm_state_gc_task);
50a30657 2079 init_waitqueue_head(&net->xfrm.km_waitq);
d62ddc21 2080 return 0;
73d189dc 2081
b754a4fd
AD
2082out_byspi:
2083 xfrm_hash_free(net->xfrm.state_bysrc, sz);
d320bbb3
AD
2084out_bysrc:
2085 xfrm_hash_free(net->xfrm.state_bydst, sz);
73d189dc
AD
2086out_bydst:
2087 return -ENOMEM;
d62ddc21
AD
2088}
2089
2090void xfrm_state_fini(struct net *net)
2091{
7c2776ee 2092 struct xfrm_audit audit_info;
73d189dc
AD
2093 unsigned int sz;
2094
7c2776ee
AD
2095 flush_work(&net->xfrm.state_hash_work);
2096 audit_info.loginuid = -1;
2097 audit_info.sessionid = -1;
2098 audit_info.secid = 0;
2099 xfrm_state_flush(net, IPSEC_PROTO_ANY, &audit_info);
2100 flush_work(&net->xfrm.state_gc_work);
2101
9d4139c7 2102 WARN_ON(!list_empty(&net->xfrm.state_all));
73d189dc 2103
529983ec 2104 sz = (net->xfrm.state_hmask + 1) * sizeof(struct hlist_head);
b754a4fd
AD
2105 WARN_ON(!hlist_empty(net->xfrm.state_byspi));
2106 xfrm_hash_free(net->xfrm.state_byspi, sz);
d320bbb3
AD
2107 WARN_ON(!hlist_empty(net->xfrm.state_bysrc));
2108 xfrm_hash_free(net->xfrm.state_bysrc, sz);
73d189dc
AD
2109 WARN_ON(!hlist_empty(net->xfrm.state_bydst));
2110 xfrm_hash_free(net->xfrm.state_bydst, sz);
1da177e4
LT
2111}
2112
ab5f5e8b 2113#ifdef CONFIG_AUDITSYSCALL
cf35f43e
IJ
2114static void xfrm_audit_helper_sainfo(struct xfrm_state *x,
2115 struct audit_buffer *audit_buf)
ab5f5e8b 2116{
68277acc
PM
2117 struct xfrm_sec_ctx *ctx = x->security;
2118 u32 spi = ntohl(x->id.spi);
2119
2120 if (ctx)
ab5f5e8b 2121 audit_log_format(audit_buf, " sec_alg=%u sec_doi=%u sec_obj=%s",
68277acc 2122 ctx->ctx_alg, ctx->ctx_doi, ctx->ctx_str);
ab5f5e8b
JL
2123
2124 switch(x->props.family) {
2125 case AF_INET:
21454aaa
HH
2126 audit_log_format(audit_buf, " src=%pI4 dst=%pI4",
2127 &x->props.saddr.a4, &x->id.daddr.a4);
ab5f5e8b
JL
2128 break;
2129 case AF_INET6:
5b095d98 2130 audit_log_format(audit_buf, " src=%pI6 dst=%pI6",
fdb46ee7 2131 x->props.saddr.a6, x->id.daddr.a6);
ab5f5e8b
JL
2132 break;
2133 }
68277acc
PM
2134
2135 audit_log_format(audit_buf, " spi=%u(0x%x)", spi, spi);
ab5f5e8b
JL
2136}
2137
cf35f43e
IJ
2138static void xfrm_audit_helper_pktinfo(struct sk_buff *skb, u16 family,
2139 struct audit_buffer *audit_buf)
afeb14b4
PM
2140{
2141 struct iphdr *iph4;
2142 struct ipv6hdr *iph6;
2143
2144 switch (family) {
2145 case AF_INET:
2146 iph4 = ip_hdr(skb);
21454aaa
HH
2147 audit_log_format(audit_buf, " src=%pI4 dst=%pI4",
2148 &iph4->saddr, &iph4->daddr);
afeb14b4
PM
2149 break;
2150 case AF_INET6:
2151 iph6 = ipv6_hdr(skb);
2152 audit_log_format(audit_buf,
5b095d98 2153 " src=%pI6 dst=%pI6 flowlbl=0x%x%02x%02x",
fdb46ee7 2154 &iph6->saddr,&iph6->daddr,
afeb14b4
PM
2155 iph6->flow_lbl[0] & 0x0f,
2156 iph6->flow_lbl[1],
2157 iph6->flow_lbl[2]);
2158 break;
2159 }
2160}
2161
68277acc 2162void xfrm_audit_state_add(struct xfrm_state *x, int result,
2532386f 2163 uid_t auid, u32 sessionid, u32 secid)
ab5f5e8b
JL
2164{
2165 struct audit_buffer *audit_buf;
ab5f5e8b 2166
afeb14b4 2167 audit_buf = xfrm_audit_start("SAD-add");
ab5f5e8b
JL
2168 if (audit_buf == NULL)
2169 return;
2532386f 2170 xfrm_audit_helper_usrinfo(auid, sessionid, secid, audit_buf);
afeb14b4
PM
2171 xfrm_audit_helper_sainfo(x, audit_buf);
2172 audit_log_format(audit_buf, " res=%u", result);
ab5f5e8b
JL
2173 audit_log_end(audit_buf);
2174}
2175EXPORT_SYMBOL_GPL(xfrm_audit_state_add);
2176
68277acc 2177void xfrm_audit_state_delete(struct xfrm_state *x, int result,
2532386f 2178 uid_t auid, u32 sessionid, u32 secid)
ab5f5e8b
JL
2179{
2180 struct audit_buffer *audit_buf;
ab5f5e8b 2181
afeb14b4 2182 audit_buf = xfrm_audit_start("SAD-delete");
ab5f5e8b
JL
2183 if (audit_buf == NULL)
2184 return;
2532386f 2185 xfrm_audit_helper_usrinfo(auid, sessionid, secid, audit_buf);
afeb14b4
PM
2186 xfrm_audit_helper_sainfo(x, audit_buf);
2187 audit_log_format(audit_buf, " res=%u", result);
ab5f5e8b
JL
2188 audit_log_end(audit_buf);
2189}
2190EXPORT_SYMBOL_GPL(xfrm_audit_state_delete);
afeb14b4
PM
2191
2192void xfrm_audit_state_replay_overflow(struct xfrm_state *x,
2193 struct sk_buff *skb)
2194{
2195 struct audit_buffer *audit_buf;
2196 u32 spi;
2197
2198 audit_buf = xfrm_audit_start("SA-replay-overflow");
2199 if (audit_buf == NULL)
2200 return;
2201 xfrm_audit_helper_pktinfo(skb, x->props.family, audit_buf);
2202 /* don't record the sequence number because it's inherent in this kind
2203 * of audit message */
2204 spi = ntohl(x->id.spi);
2205 audit_log_format(audit_buf, " spi=%u(0x%x)", spi, spi);
2206 audit_log_end(audit_buf);
2207}
2208EXPORT_SYMBOL_GPL(xfrm_audit_state_replay_overflow);
2209
2210static void xfrm_audit_state_replay(struct xfrm_state *x,
2211 struct sk_buff *skb, __be32 net_seq)
2212{
2213 struct audit_buffer *audit_buf;
2214 u32 spi;
2215
2216 audit_buf = xfrm_audit_start("SA-replayed-pkt");
2217 if (audit_buf == NULL)
2218 return;
2219 xfrm_audit_helper_pktinfo(skb, x->props.family, audit_buf);
2220 spi = ntohl(x->id.spi);
2221 audit_log_format(audit_buf, " spi=%u(0x%x) seqno=%u",
2222 spi, spi, ntohl(net_seq));
2223 audit_log_end(audit_buf);
2224}
2225
2226void xfrm_audit_state_notfound_simple(struct sk_buff *skb, u16 family)
2227{
2228 struct audit_buffer *audit_buf;
2229
2230 audit_buf = xfrm_audit_start("SA-notfound");
2231 if (audit_buf == NULL)
2232 return;
2233 xfrm_audit_helper_pktinfo(skb, family, audit_buf);
2234 audit_log_end(audit_buf);
2235}
2236EXPORT_SYMBOL_GPL(xfrm_audit_state_notfound_simple);
2237
2238void xfrm_audit_state_notfound(struct sk_buff *skb, u16 family,
2239 __be32 net_spi, __be32 net_seq)
2240{
2241 struct audit_buffer *audit_buf;
2242 u32 spi;
2243
2244 audit_buf = xfrm_audit_start("SA-notfound");
2245 if (audit_buf == NULL)
2246 return;
2247 xfrm_audit_helper_pktinfo(skb, family, audit_buf);
2248 spi = ntohl(net_spi);
2249 audit_log_format(audit_buf, " spi=%u(0x%x) seqno=%u",
2250 spi, spi, ntohl(net_seq));
2251 audit_log_end(audit_buf);
2252}
2253EXPORT_SYMBOL_GPL(xfrm_audit_state_notfound);
2254
2255void xfrm_audit_state_icvfail(struct xfrm_state *x,
2256 struct sk_buff *skb, u8 proto)
2257{
2258 struct audit_buffer *audit_buf;
2259 __be32 net_spi;
2260 __be32 net_seq;
2261
2262 audit_buf = xfrm_audit_start("SA-icv-failure");
2263 if (audit_buf == NULL)
2264 return;
2265 xfrm_audit_helper_pktinfo(skb, x->props.family, audit_buf);
2266 if (xfrm_parse_spi(skb, proto, &net_spi, &net_seq) == 0) {
2267 u32 spi = ntohl(net_spi);
2268 audit_log_format(audit_buf, " spi=%u(0x%x) seqno=%u",
2269 spi, spi, ntohl(net_seq));
2270 }
2271 audit_log_end(audit_buf);
2272}
2273EXPORT_SYMBOL_GPL(xfrm_audit_state_icvfail);
ab5f5e8b 2274#endif /* CONFIG_AUDITSYSCALL */
This page took 0.97051 seconds and 5 git commands to generate.