diff options
Diffstat (limited to 'net/xfrm/xfrm_state.c')
-rw-r--r-- | net/xfrm/xfrm_state.c | 84 |
1 files changed, 48 insertions, 36 deletions
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c index 0a8f09c3144c..508337f97249 100644 --- a/net/xfrm/xfrm_state.c +++ b/net/xfrm/xfrm_state.c | |||
@@ -408,11 +408,10 @@ static void xfrm_state_gc_task(struct work_struct *data) | |||
408 | struct hlist_head gc_list; | 408 | struct hlist_head gc_list; |
409 | 409 | ||
410 | spin_lock_bh(&xfrm_state_gc_lock); | 410 | spin_lock_bh(&xfrm_state_gc_lock); |
411 | gc_list.first = xfrm_state_gc_list.first; | 411 | hlist_move_list(&xfrm_state_gc_list, &gc_list); |
412 | INIT_HLIST_HEAD(&xfrm_state_gc_list); | ||
413 | spin_unlock_bh(&xfrm_state_gc_lock); | 412 | spin_unlock_bh(&xfrm_state_gc_lock); |
414 | 413 | ||
415 | hlist_for_each_entry_safe(x, entry, tmp, &gc_list, bydst) | 414 | hlist_for_each_entry_safe(x, entry, tmp, &gc_list, gclist) |
416 | xfrm_state_gc_destroy(x); | 415 | xfrm_state_gc_destroy(x); |
417 | 416 | ||
418 | wake_up(&km_waitq); | 417 | wake_up(&km_waitq); |
@@ -514,7 +513,7 @@ struct xfrm_state *xfrm_state_alloc(void) | |||
514 | if (x) { | 513 | if (x) { |
515 | atomic_set(&x->refcnt, 1); | 514 | atomic_set(&x->refcnt, 1); |
516 | atomic_set(&x->tunnel_users, 0); | 515 | atomic_set(&x->tunnel_users, 0); |
517 | INIT_LIST_HEAD(&x->all); | 516 | INIT_LIST_HEAD(&x->km.all); |
518 | INIT_HLIST_NODE(&x->bydst); | 517 | INIT_HLIST_NODE(&x->bydst); |
519 | INIT_HLIST_NODE(&x->bysrc); | 518 | INIT_HLIST_NODE(&x->bysrc); |
520 | INIT_HLIST_NODE(&x->byspi); | 519 | INIT_HLIST_NODE(&x->byspi); |
@@ -540,12 +539,8 @@ void __xfrm_state_destroy(struct xfrm_state *x) | |||
540 | { | 539 | { |
541 | WARN_ON(x->km.state != XFRM_STATE_DEAD); | 540 | WARN_ON(x->km.state != XFRM_STATE_DEAD); |
542 | 541 | ||
543 | spin_lock_bh(&xfrm_state_lock); | ||
544 | list_del(&x->all); | ||
545 | spin_unlock_bh(&xfrm_state_lock); | ||
546 | |||
547 | spin_lock_bh(&xfrm_state_gc_lock); | 542 | spin_lock_bh(&xfrm_state_gc_lock); |
548 | hlist_add_head(&x->bydst, &xfrm_state_gc_list); | 543 | hlist_add_head(&x->gclist, &xfrm_state_gc_list); |
549 | spin_unlock_bh(&xfrm_state_gc_lock); | 544 | spin_unlock_bh(&xfrm_state_gc_lock); |
550 | schedule_work(&xfrm_state_gc_work); | 545 | schedule_work(&xfrm_state_gc_work); |
551 | } | 546 | } |
@@ -558,6 +553,7 @@ int __xfrm_state_delete(struct xfrm_state *x) | |||
558 | if (x->km.state != XFRM_STATE_DEAD) { | 553 | if (x->km.state != XFRM_STATE_DEAD) { |
559 | x->km.state = XFRM_STATE_DEAD; | 554 | x->km.state = XFRM_STATE_DEAD; |
560 | spin_lock(&xfrm_state_lock); | 555 | spin_lock(&xfrm_state_lock); |
556 | list_del(&x->km.all); | ||
561 | hlist_del(&x->bydst); | 557 | hlist_del(&x->bydst); |
562 | hlist_del(&x->bysrc); | 558 | hlist_del(&x->bysrc); |
563 | if (x->id.spi) | 559 | if (x->id.spi) |
@@ -858,7 +854,7 @@ xfrm_state_find(xfrm_address_t *daddr, xfrm_address_t *saddr, | |||
858 | 854 | ||
859 | if (km_query(x, tmpl, pol) == 0) { | 855 | if (km_query(x, tmpl, pol) == 0) { |
860 | x->km.state = XFRM_STATE_ACQ; | 856 | x->km.state = XFRM_STATE_ACQ; |
861 | list_add_tail(&x->all, &xfrm_state_all); | 857 | list_add(&x->km.all, &xfrm_state_all); |
862 | hlist_add_head(&x->bydst, xfrm_state_bydst+h); | 858 | hlist_add_head(&x->bydst, xfrm_state_bydst+h); |
863 | h = xfrm_src_hash(daddr, saddr, family); | 859 | h = xfrm_src_hash(daddr, saddr, family); |
864 | hlist_add_head(&x->bysrc, xfrm_state_bysrc+h); | 860 | hlist_add_head(&x->bysrc, xfrm_state_bysrc+h); |
@@ -927,7 +923,7 @@ static void __xfrm_state_insert(struct xfrm_state *x) | |||
927 | 923 | ||
928 | x->genid = ++xfrm_state_genid; | 924 | x->genid = ++xfrm_state_genid; |
929 | 925 | ||
930 | list_add_tail(&x->all, &xfrm_state_all); | 926 | list_add(&x->km.all, &xfrm_state_all); |
931 | 927 | ||
932 | h = xfrm_dst_hash(&x->id.daddr, &x->props.saddr, | 928 | h = xfrm_dst_hash(&x->id.daddr, &x->props.saddr, |
933 | x->props.reqid, x->props.family); | 929 | x->props.reqid, x->props.family); |
@@ -1056,7 +1052,7 @@ static struct xfrm_state *__find_acq_core(unsigned short family, u8 mode, u32 re | |||
1056 | xfrm_state_hold(x); | 1052 | xfrm_state_hold(x); |
1057 | x->timer.expires = jiffies + sysctl_xfrm_acq_expires*HZ; | 1053 | x->timer.expires = jiffies + sysctl_xfrm_acq_expires*HZ; |
1058 | add_timer(&x->timer); | 1054 | add_timer(&x->timer); |
1059 | list_add_tail(&x->all, &xfrm_state_all); | 1055 | list_add(&x->km.all, &xfrm_state_all); |
1060 | hlist_add_head(&x->bydst, xfrm_state_bydst+h); | 1056 | hlist_add_head(&x->bydst, xfrm_state_bydst+h); |
1061 | h = xfrm_src_hash(daddr, saddr, family); | 1057 | h = xfrm_src_hash(daddr, saddr, family); |
1062 | hlist_add_head(&x->bysrc, xfrm_state_bysrc+h); | 1058 | hlist_add_head(&x->bysrc, xfrm_state_bysrc+h); |
@@ -1553,47 +1549,62 @@ int xfrm_state_walk(struct xfrm_state_walk *walk, | |||
1553 | int (*func)(struct xfrm_state *, int, void*), | 1549 | int (*func)(struct xfrm_state *, int, void*), |
1554 | void *data) | 1550 | void *data) |
1555 | { | 1551 | { |
1556 | struct xfrm_state *old, *x, *last = NULL; | 1552 | struct xfrm_state *state; |
1553 | struct xfrm_state_walk *x; | ||
1557 | int err = 0; | 1554 | int err = 0; |
1558 | 1555 | ||
1559 | if (walk->state == NULL && walk->count != 0) | 1556 | if (walk->seq != 0 && list_empty(&walk->all)) |
1560 | return 0; | 1557 | return 0; |
1561 | 1558 | ||
1562 | old = x = walk->state; | ||
1563 | walk->state = NULL; | ||
1564 | spin_lock_bh(&xfrm_state_lock); | 1559 | spin_lock_bh(&xfrm_state_lock); |
1565 | if (x == NULL) | 1560 | if (list_empty(&walk->all)) |
1566 | x = list_first_entry(&xfrm_state_all, struct xfrm_state, all); | 1561 | x = list_first_entry(&xfrm_state_all, struct xfrm_state_walk, all); |
1562 | else | ||
1563 | x = list_entry(&walk->all, struct xfrm_state_walk, all); | ||
1567 | list_for_each_entry_from(x, &xfrm_state_all, all) { | 1564 | list_for_each_entry_from(x, &xfrm_state_all, all) { |
1568 | if (x->km.state == XFRM_STATE_DEAD) | 1565 | if (x->state == XFRM_STATE_DEAD) |
1569 | continue; | 1566 | continue; |
1570 | if (!xfrm_id_proto_match(x->id.proto, walk->proto)) | 1567 | state = container_of(x, struct xfrm_state, km); |
1568 | if (!xfrm_id_proto_match(state->id.proto, walk->proto)) | ||
1571 | continue; | 1569 | continue; |
1572 | if (last) { | 1570 | err = func(state, walk->seq, data); |
1573 | err = func(last, walk->count, data); | 1571 | if (err) { |
1574 | if (err) { | 1572 | list_move_tail(&walk->all, &x->all); |
1575 | xfrm_state_hold(last); | 1573 | goto out; |
1576 | walk->state = last; | ||
1577 | goto out; | ||
1578 | } | ||
1579 | } | 1574 | } |
1580 | last = x; | 1575 | walk->seq++; |
1581 | walk->count++; | ||
1582 | } | 1576 | } |
1583 | if (walk->count == 0) { | 1577 | if (walk->seq == 0) { |
1584 | err = -ENOENT; | 1578 | err = -ENOENT; |
1585 | goto out; | 1579 | goto out; |
1586 | } | 1580 | } |
1587 | if (last) | 1581 | list_del_init(&walk->all); |
1588 | err = func(last, 0, data); | ||
1589 | out: | 1582 | out: |
1590 | spin_unlock_bh(&xfrm_state_lock); | 1583 | spin_unlock_bh(&xfrm_state_lock); |
1591 | if (old != NULL) | ||
1592 | xfrm_state_put(old); | ||
1593 | return err; | 1584 | return err; |
1594 | } | 1585 | } |
1595 | EXPORT_SYMBOL(xfrm_state_walk); | 1586 | EXPORT_SYMBOL(xfrm_state_walk); |
1596 | 1587 | ||
1588 | void xfrm_state_walk_init(struct xfrm_state_walk *walk, u8 proto) | ||
1589 | { | ||
1590 | INIT_LIST_HEAD(&walk->all); | ||
1591 | walk->proto = proto; | ||
1592 | walk->state = XFRM_STATE_DEAD; | ||
1593 | walk->seq = 0; | ||
1594 | } | ||
1595 | EXPORT_SYMBOL(xfrm_state_walk_init); | ||
1596 | |||
1597 | void xfrm_state_walk_done(struct xfrm_state_walk *walk) | ||
1598 | { | ||
1599 | if (list_empty(&walk->all)) | ||
1600 | return; | ||
1601 | |||
1602 | spin_lock_bh(&xfrm_state_lock); | ||
1603 | list_del(&walk->all); | ||
1604 | spin_lock_bh(&xfrm_state_lock); | ||
1605 | } | ||
1606 | EXPORT_SYMBOL(xfrm_state_walk_done); | ||
1607 | |||
1597 | 1608 | ||
1598 | void xfrm_replay_notify(struct xfrm_state *x, int event) | 1609 | void xfrm_replay_notify(struct xfrm_state *x, int event) |
1599 | { | 1610 | { |
@@ -1803,7 +1814,8 @@ EXPORT_SYMBOL(km_policy_expired); | |||
1803 | 1814 | ||
1804 | #ifdef CONFIG_XFRM_MIGRATE | 1815 | #ifdef CONFIG_XFRM_MIGRATE |
1805 | int km_migrate(struct xfrm_selector *sel, u8 dir, u8 type, | 1816 | int km_migrate(struct xfrm_selector *sel, u8 dir, u8 type, |
1806 | struct xfrm_migrate *m, int num_migrate) | 1817 | struct xfrm_migrate *m, int num_migrate, |
1818 | struct xfrm_kmaddress *k) | ||
1807 | { | 1819 | { |
1808 | int err = -EINVAL; | 1820 | int err = -EINVAL; |
1809 | int ret; | 1821 | int ret; |
@@ -1812,7 +1824,7 @@ int km_migrate(struct xfrm_selector *sel, u8 dir, u8 type, | |||
1812 | read_lock(&xfrm_km_lock); | 1824 | read_lock(&xfrm_km_lock); |
1813 | list_for_each_entry(km, &xfrm_km_list, list) { | 1825 | list_for_each_entry(km, &xfrm_km_list, list) { |
1814 | if (km->migrate) { | 1826 | if (km->migrate) { |
1815 | ret = km->migrate(sel, dir, type, m, num_migrate); | 1827 | ret = km->migrate(sel, dir, type, m, num_migrate, k); |
1816 | if (!ret) | 1828 | if (!ret) |
1817 | err = ret; | 1829 | err = ret; |
1818 | } | 1830 | } |