Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * xfrm6_policy.c: based on xfrm4_policy.c |
| 4 | * |
| 5 | * Authors: |
| 6 | * Mitsuru KANDA @USAGI |
Ian Morris | 67ba415 | 2014-08-24 21:53:10 +0100 | [diff] [blame] | 7 | * Kazunori MIYAZAWA @USAGI |
| 8 | * Kunihiro Ishiguro <kunihiro@ipinfusion.com> |
| 9 | * IPv6 support |
| 10 | * YOSHIFUJI Hideaki |
| 11 | * Split up af-specific portion |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 12 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | */ |
| 14 | |
Herbert Xu | 66cdb3c | 2007-11-13 21:37:28 -0800 | [diff] [blame] | 15 | #include <linux/err.h> |
| 16 | #include <linux/kernel.h> |
Herbert Xu | aabc976 | 2005-05-03 16:27:10 -0700 | [diff] [blame] | 17 | #include <linux/netdevice.h> |
| 18 | #include <net/addrconf.h> |
Herbert Xu | 45ff5a3 | 2007-11-13 21:35:32 -0800 | [diff] [blame] | 19 | #include <net/dst.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <net/xfrm.h> |
| 21 | #include <net/ip.h> |
| 22 | #include <net/ipv6.h> |
| 23 | #include <net/ip6_route.h> |
David Ahern | 385add9 | 2015-09-29 20:07:13 -0700 | [diff] [blame] | 24 | #include <net/l3mdev.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
David Ahern | 42a7b32 | 2015-08-10 16:58:11 -0600 | [diff] [blame] | 26 | static struct dst_entry *xfrm6_dst_lookup(struct net *net, int tos, int oif, |
David S. Miller | 5e6b930 | 2011-02-24 00:14:45 -0500 | [diff] [blame] | 27 | const xfrm_address_t *saddr, |
Lorenzo Colitti | 077fbac | 2017-08-11 02:11:33 +0900 | [diff] [blame] | 28 | const xfrm_address_t *daddr, |
| 29 | u32 mark) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | { |
David S. Miller | 7e1dc7b | 2011-03-12 02:42:11 -0500 | [diff] [blame] | 31 | struct flowi6 fl6; |
Herbert Xu | 66cdb3c | 2007-11-13 21:37:28 -0800 | [diff] [blame] | 32 | struct dst_entry *dst; |
| 33 | int err; |
| 34 | |
David S. Miller | 7e1dc7b | 2011-03-12 02:42:11 -0500 | [diff] [blame] | 35 | memset(&fl6, 0, sizeof(fl6)); |
David Ahern | 11d7a0b | 2016-08-14 19:52:56 -0700 | [diff] [blame] | 36 | fl6.flowi6_oif = l3mdev_master_ifindex_by_index(net, oif); |
David Ahern | 4148987 | 2015-10-05 08:32:51 -0600 | [diff] [blame] | 37 | fl6.flowi6_flags = FLOWI_FLAG_SKIP_NH_OIF; |
Lorenzo Colitti | 077fbac | 2017-08-11 02:11:33 +0900 | [diff] [blame] | 38 | fl6.flowi6_mark = mark; |
David S. Miller | 7e1dc7b | 2011-03-12 02:42:11 -0500 | [diff] [blame] | 39 | memcpy(&fl6.daddr, daddr, sizeof(fl6.daddr)); |
Herbert Xu | 66cdb3c | 2007-11-13 21:37:28 -0800 | [diff] [blame] | 40 | if (saddr) |
David S. Miller | 7e1dc7b | 2011-03-12 02:42:11 -0500 | [diff] [blame] | 41 | memcpy(&fl6.saddr, saddr, sizeof(fl6.saddr)); |
Herbert Xu | 66cdb3c | 2007-11-13 21:37:28 -0800 | [diff] [blame] | 42 | |
David S. Miller | 4c9483b | 2011-03-12 16:22:43 -0500 | [diff] [blame] | 43 | dst = ip6_route_output(net, NULL, &fl6); |
Herbert Xu | 66cdb3c | 2007-11-13 21:37:28 -0800 | [diff] [blame] | 44 | |
| 45 | err = dst->error; |
| 46 | if (dst->error) { |
Ville Nuorvala | 4251320 | 2006-10-16 22:10:05 -0700 | [diff] [blame] | 47 | dst_release(dst); |
Herbert Xu | 66cdb3c | 2007-11-13 21:37:28 -0800 | [diff] [blame] | 48 | dst = ERR_PTR(err); |
| 49 | } |
| 50 | |
| 51 | return dst; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | } |
| 53 | |
David Ahern | 42a7b32 | 2015-08-10 16:58:11 -0600 | [diff] [blame] | 54 | static int xfrm6_get_saddr(struct net *net, int oif, |
Lorenzo Colitti | 077fbac | 2017-08-11 02:11:33 +0900 | [diff] [blame] | 55 | xfrm_address_t *saddr, xfrm_address_t *daddr, |
| 56 | u32 mark) |
Patrick McHardy | a1e59ab | 2006-09-19 12:57:34 -0700 | [diff] [blame] | 57 | { |
Herbert Xu | 66cdb3c | 2007-11-13 21:37:28 -0800 | [diff] [blame] | 58 | struct dst_entry *dst; |
Brian Haley | 191cd58 | 2008-08-14 15:33:21 -0700 | [diff] [blame] | 59 | struct net_device *dev; |
Patrick McHardy | a1e59ab | 2006-09-19 12:57:34 -0700 | [diff] [blame] | 60 | |
Lorenzo Colitti | 077fbac | 2017-08-11 02:11:33 +0900 | [diff] [blame] | 61 | dst = xfrm6_dst_lookup(net, 0, oif, NULL, daddr, mark); |
Herbert Xu | 66cdb3c | 2007-11-13 21:37:28 -0800 | [diff] [blame] | 62 | if (IS_ERR(dst)) |
| 63 | return -EHOSTUNREACH; |
| 64 | |
Brian Haley | 191cd58 | 2008-08-14 15:33:21 -0700 | [diff] [blame] | 65 | dev = ip6_dst_idev(dst)->dev; |
Jiri Benc | 15e318b | 2015-03-29 16:59:24 +0200 | [diff] [blame] | 66 | ipv6_dev_get_saddr(dev_net(dev), dev, &daddr->in6, 0, &saddr->in6); |
Herbert Xu | 66cdb3c | 2007-11-13 21:37:28 -0800 | [diff] [blame] | 67 | dst_release(dst); |
| 68 | return 0; |
Patrick McHardy | a1e59ab | 2006-09-19 12:57:34 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Herbert Xu | 87c1e12 | 2010-03-02 02:51:56 +0000 | [diff] [blame] | 71 | static int xfrm6_fill_dst(struct xfrm_dst *xdst, struct net_device *dev, |
David S. Miller | 0c7b3ee | 2011-02-22 17:48:57 -0800 | [diff] [blame] | 72 | const struct flowi *fl) |
Herbert Xu | 25ee328 | 2007-12-11 09:32:34 -0800 | [diff] [blame] | 73 | { |
Ian Morris | 67ba415 | 2014-08-24 21:53:10 +0100 | [diff] [blame] | 74 | struct rt6_info *rt = (struct rt6_info *)xdst->route; |
Herbert Xu | 25ee328 | 2007-12-11 09:32:34 -0800 | [diff] [blame] | 75 | |
| 76 | xdst->u.dst.dev = dev; |
Eric Dumazet | 4177e49 | 2021-12-07 11:32:03 -0800 | [diff] [blame] | 77 | dev_hold_track(dev, &xdst->u.dst.dev_tracker, GFP_ATOMIC); |
Herbert Xu | 25ee328 | 2007-12-11 09:32:34 -0800 | [diff] [blame] | 78 | |
Nicolas Dichtel | bc8e4b9 | 2010-04-21 16:25:30 -0700 | [diff] [blame] | 79 | xdst->u.rt6.rt6i_idev = in6_dev_get(dev); |
Cong Wang | 84c4a9d | 2013-05-09 22:40:00 +0000 | [diff] [blame] | 80 | if (!xdst->u.rt6.rt6i_idev) { |
Eric Dumazet | 4177e49 | 2021-12-07 11:32:03 -0800 | [diff] [blame] | 81 | dev_put_track(dev, &xdst->u.dst.dev_tracker); |
Herbert Xu | 25ee328 | 2007-12-11 09:32:34 -0800 | [diff] [blame] | 82 | return -ENODEV; |
Cong Wang | 84c4a9d | 2013-05-09 22:40:00 +0000 | [diff] [blame] | 83 | } |
Herbert Xu | 25ee328 | 2007-12-11 09:32:34 -0800 | [diff] [blame] | 84 | |
| 85 | /* Sheit... I remember I did this right. Apparently, |
| 86 | * it was magically lost, so this code needs audit */ |
| 87 | xdst->u.rt6.rt6i_flags = rt->rt6i_flags & (RTF_ANYCAST | |
| 88 | RTF_LOCAL); |
Martin KaFai Lau | b197df4 | 2015-05-22 20:56:01 -0700 | [diff] [blame] | 89 | xdst->route_cookie = rt6_get_cookie(rt); |
Herbert Xu | 25ee328 | 2007-12-11 09:32:34 -0800 | [diff] [blame] | 90 | xdst->u.rt6.rt6i_gateway = rt->rt6i_gateway; |
| 91 | xdst->u.rt6.rt6i_dst = rt->rt6i_dst; |
| 92 | xdst->u.rt6.rt6i_src = rt->rt6i_src; |
Xin Long | 510c321 | 2018-02-14 19:06:02 +0800 | [diff] [blame] | 93 | INIT_LIST_HEAD(&xdst->u.rt6.rt6i_uncached); |
| 94 | rt6_uncached_list_add(&xdst->u.rt6); |
| 95 | atomic_inc(&dev_net(dev)->ipv6.rt6_stats->fib_rt_uncache); |
Herbert Xu | 25ee328 | 2007-12-11 09:32:34 -0800 | [diff] [blame] | 96 | |
| 97 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | } |
| 99 | |
David S. Miller | 6700c27 | 2012-07-17 03:29:28 -0700 | [diff] [blame] | 100 | static void xfrm6_update_pmtu(struct dst_entry *dst, struct sock *sk, |
Hangbin Liu | bd085ef | 2019-12-22 10:51:09 +0800 | [diff] [blame] | 101 | struct sk_buff *skb, u32 mtu, |
| 102 | bool confirm_neigh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | { |
| 104 | struct xfrm_dst *xdst = (struct xfrm_dst *)dst; |
| 105 | struct dst_entry *path = xdst->route; |
| 106 | |
Hangbin Liu | bd085ef | 2019-12-22 10:51:09 +0800 | [diff] [blame] | 107 | path->ops->update_pmtu(path, sk, skb, mtu, confirm_neigh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | } |
| 109 | |
David S. Miller | 6700c27 | 2012-07-17 03:29:28 -0700 | [diff] [blame] | 110 | static void xfrm6_redirect(struct dst_entry *dst, struct sock *sk, |
| 111 | struct sk_buff *skb) |
David S. Miller | ec18d9a | 2012-07-12 00:25:15 -0700 | [diff] [blame] | 112 | { |
| 113 | struct xfrm_dst *xdst = (struct xfrm_dst *)dst; |
| 114 | struct dst_entry *path = xdst->route; |
| 115 | |
David S. Miller | 6700c27 | 2012-07-17 03:29:28 -0700 | [diff] [blame] | 116 | path->ops->redirect(path, sk, skb); |
David S. Miller | ec18d9a | 2012-07-12 00:25:15 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Herbert Xu | aabc976 | 2005-05-03 16:27:10 -0700 | [diff] [blame] | 119 | static void xfrm6_dst_destroy(struct dst_entry *dst) |
| 120 | { |
| 121 | struct xfrm_dst *xdst = (struct xfrm_dst *)dst; |
| 122 | |
| 123 | if (likely(xdst->u.rt6.rt6i_idev)) |
| 124 | in6_dev_put(xdst->u.rt6.rt6i_idev); |
David S. Miller | 62fa8a8 | 2011-01-26 20:51:05 -0800 | [diff] [blame] | 125 | dst_destroy_metrics_generic(dst); |
Xin Long | 510c321 | 2018-02-14 19:06:02 +0800 | [diff] [blame] | 126 | if (xdst->u.rt6.rt6i_uncached_list) |
| 127 | rt6_uncached_list_del(&xdst->u.rt6); |
Herbert Xu | aabc976 | 2005-05-03 16:27:10 -0700 | [diff] [blame] | 128 | xfrm_dst_destroy(xdst); |
| 129 | } |
| 130 | |
| 131 | static void xfrm6_dst_ifdown(struct dst_entry *dst, struct net_device *dev, |
| 132 | int unregister) |
| 133 | { |
| 134 | struct xfrm_dst *xdst; |
| 135 | |
| 136 | if (!unregister) |
| 137 | return; |
| 138 | |
| 139 | xdst = (struct xfrm_dst *)dst; |
| 140 | if (xdst->u.rt6.rt6i_idev->dev == dev) { |
Denis V. Lunev | 5a3e55d | 2007-12-07 00:38:10 -0800 | [diff] [blame] | 141 | struct inet6_dev *loopback_idev = |
YOSHIFUJI Hideaki | c346dca | 2008-03-25 21:47:49 +0900 | [diff] [blame] | 142 | in6_dev_get(dev_net(dev)->loopback_dev); |
Herbert Xu | aabc976 | 2005-05-03 16:27:10 -0700 | [diff] [blame] | 143 | |
| 144 | do { |
| 145 | in6_dev_put(xdst->u.rt6.rt6i_idev); |
| 146 | xdst->u.rt6.rt6i_idev = loopback_idev; |
| 147 | in6_dev_hold(loopback_idev); |
David Miller | b92cf4a | 2017-11-28 15:40:22 -0500 | [diff] [blame] | 148 | xdst = (struct xfrm_dst *)xfrm_dst_child(&xdst->u.dst); |
Herbert Xu | aabc976 | 2005-05-03 16:27:10 -0700 | [diff] [blame] | 149 | } while (xdst->u.dst.xfrm); |
| 150 | |
| 151 | __in6_dev_put(loopback_idev); |
| 152 | } |
| 153 | |
| 154 | xfrm_dst_ifdown(dst, dev); |
| 155 | } |
| 156 | |
Dan Streetman | a8a572a | 2015-10-29 09:51:16 -0400 | [diff] [blame] | 157 | static struct dst_ops xfrm6_dst_ops_template = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | .family = AF_INET6, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | .update_pmtu = xfrm6_update_pmtu, |
David S. Miller | ec18d9a | 2012-07-12 00:25:15 -0700 | [diff] [blame] | 160 | .redirect = xfrm6_redirect, |
David S. Miller | 62fa8a8 | 2011-01-26 20:51:05 -0800 | [diff] [blame] | 161 | .cow_metrics = dst_cow_metrics_generic, |
Herbert Xu | aabc976 | 2005-05-03 16:27:10 -0700 | [diff] [blame] | 162 | .destroy = xfrm6_dst_destroy, |
| 163 | .ifdown = xfrm6_dst_ifdown, |
Herbert Xu | 862b82c | 2007-11-13 21:43:11 -0800 | [diff] [blame] | 164 | .local_out = __ip6_local_out, |
Florian Westphal | 3c2a89d | 2017-07-17 13:57:20 +0200 | [diff] [blame] | 165 | .gc_thresh = 32768, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | }; |
| 167 | |
Florian Westphal | 37b1038 | 2017-02-07 15:00:19 +0100 | [diff] [blame] | 168 | static const struct xfrm_policy_afinfo xfrm6_policy_afinfo = { |
Dan Streetman | a8a572a | 2015-10-29 09:51:16 -0400 | [diff] [blame] | 169 | .dst_ops = &xfrm6_dst_ops_template, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | .dst_lookup = xfrm6_dst_lookup, |
Ian Morris | 67ba415 | 2014-08-24 21:53:10 +0100 | [diff] [blame] | 171 | .get_saddr = xfrm6_get_saddr, |
Herbert Xu | 25ee328 | 2007-12-11 09:32:34 -0800 | [diff] [blame] | 172 | .fill_dst = xfrm6_fill_dst, |
David S. Miller | 2774c13 | 2011-03-01 14:59:04 -0800 | [diff] [blame] | 173 | .blackhole_route = ip6_blackhole_route, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | }; |
| 175 | |
Daniel Lezcano | 0013cab | 2007-12-07 00:42:11 -0800 | [diff] [blame] | 176 | static int __init xfrm6_policy_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | { |
Florian Westphal | a2817d8 | 2017-02-07 15:00:17 +0100 | [diff] [blame] | 178 | return xfrm_policy_register_afinfo(&xfrm6_policy_afinfo, AF_INET6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | static void xfrm6_policy_fini(void) |
| 182 | { |
| 183 | xfrm_policy_unregister_afinfo(&xfrm6_policy_afinfo); |
| 184 | } |
| 185 | |
David S. Miller | db71789 | 2009-08-04 20:32:16 -0700 | [diff] [blame] | 186 | #ifdef CONFIG_SYSCTL |
Neil Horman | a44a4a0 | 2009-07-27 08:22:46 +0000 | [diff] [blame] | 187 | static struct ctl_table xfrm6_policy_table[] = { |
| 188 | { |
Neil Horman | a44a4a0 | 2009-07-27 08:22:46 +0000 | [diff] [blame] | 189 | .procname = "xfrm6_gc_thresh", |
Ian Morris | 67ba415 | 2014-08-24 21:53:10 +0100 | [diff] [blame] | 190 | .data = &init_net.xfrm.xfrm6_dst_ops.gc_thresh, |
| 191 | .maxlen = sizeof(int), |
| 192 | .mode = 0644, |
Neil Horman | a44a4a0 | 2009-07-27 08:22:46 +0000 | [diff] [blame] | 193 | .proc_handler = proc_dointvec, |
| 194 | }, |
| 195 | { } |
| 196 | }; |
| 197 | |
Dan Streetman | a8a572a | 2015-10-29 09:51:16 -0400 | [diff] [blame] | 198 | static int __net_init xfrm6_net_sysctl_init(struct net *net) |
Michal Kubecek | 8d06887 | 2013-02-06 10:46:33 +0100 | [diff] [blame] | 199 | { |
| 200 | struct ctl_table *table; |
| 201 | struct ctl_table_header *hdr; |
| 202 | |
| 203 | table = xfrm6_policy_table; |
| 204 | if (!net_eq(net, &init_net)) { |
| 205 | table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL); |
| 206 | if (!table) |
| 207 | goto err_alloc; |
| 208 | |
| 209 | table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh; |
| 210 | } |
| 211 | |
| 212 | hdr = register_net_sysctl(net, "net/ipv6", table); |
| 213 | if (!hdr) |
| 214 | goto err_reg; |
| 215 | |
| 216 | net->ipv6.sysctl.xfrm6_hdr = hdr; |
| 217 | return 0; |
| 218 | |
| 219 | err_reg: |
| 220 | if (!net_eq(net, &init_net)) |
| 221 | kfree(table); |
| 222 | err_alloc: |
| 223 | return -ENOMEM; |
| 224 | } |
| 225 | |
Dan Streetman | a8a572a | 2015-10-29 09:51:16 -0400 | [diff] [blame] | 226 | static void __net_exit xfrm6_net_sysctl_exit(struct net *net) |
Michal Kubecek | 8d06887 | 2013-02-06 10:46:33 +0100 | [diff] [blame] | 227 | { |
| 228 | struct ctl_table *table; |
| 229 | |
Ian Morris | 63159f2 | 2015-03-29 14:00:04 +0100 | [diff] [blame] | 230 | if (!net->ipv6.sysctl.xfrm6_hdr) |
Michal Kubecek | 8d06887 | 2013-02-06 10:46:33 +0100 | [diff] [blame] | 231 | return; |
| 232 | |
| 233 | table = net->ipv6.sysctl.xfrm6_hdr->ctl_table_arg; |
| 234 | unregister_net_sysctl_table(net->ipv6.sysctl.xfrm6_hdr); |
| 235 | if (!net_eq(net, &init_net)) |
| 236 | kfree(table); |
| 237 | } |
Dan Streetman | a8a572a | 2015-10-29 09:51:16 -0400 | [diff] [blame] | 238 | #else /* CONFIG_SYSCTL */ |
Arnd Bergmann | 318d3cc | 2016-06-16 15:59:25 +0200 | [diff] [blame] | 239 | static inline int xfrm6_net_sysctl_init(struct net *net) |
Dan Streetman | a8a572a | 2015-10-29 09:51:16 -0400 | [diff] [blame] | 240 | { |
| 241 | return 0; |
| 242 | } |
| 243 | |
Arnd Bergmann | 318d3cc | 2016-06-16 15:59:25 +0200 | [diff] [blame] | 244 | static inline void xfrm6_net_sysctl_exit(struct net *net) |
Dan Streetman | a8a572a | 2015-10-29 09:51:16 -0400 | [diff] [blame] | 245 | { |
| 246 | } |
| 247 | #endif |
| 248 | |
| 249 | static int __net_init xfrm6_net_init(struct net *net) |
| 250 | { |
| 251 | int ret; |
| 252 | |
| 253 | memcpy(&net->xfrm.xfrm6_dst_ops, &xfrm6_dst_ops_template, |
| 254 | sizeof(xfrm6_dst_ops_template)); |
| 255 | ret = dst_entries_init(&net->xfrm.xfrm6_dst_ops); |
| 256 | if (ret) |
| 257 | return ret; |
| 258 | |
| 259 | ret = xfrm6_net_sysctl_init(net); |
| 260 | if (ret) |
| 261 | dst_entries_destroy(&net->xfrm.xfrm6_dst_ops); |
| 262 | |
| 263 | return ret; |
| 264 | } |
| 265 | |
| 266 | static void __net_exit xfrm6_net_exit(struct net *net) |
| 267 | { |
| 268 | xfrm6_net_sysctl_exit(net); |
| 269 | dst_entries_destroy(&net->xfrm.xfrm6_dst_ops); |
| 270 | } |
Michal Kubecek | 8d06887 | 2013-02-06 10:46:33 +0100 | [diff] [blame] | 271 | |
| 272 | static struct pernet_operations xfrm6_net_ops = { |
| 273 | .init = xfrm6_net_init, |
| 274 | .exit = xfrm6_net_exit, |
| 275 | }; |
Neil Horman | a44a4a0 | 2009-07-27 08:22:46 +0000 | [diff] [blame] | 276 | |
Daniel Lezcano | 0013cab | 2007-12-07 00:42:11 -0800 | [diff] [blame] | 277 | int __init xfrm6_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | { |
Daniel Lezcano | 0013cab | 2007-12-07 00:42:11 -0800 | [diff] [blame] | 279 | int ret; |
| 280 | |
Alexey Dobriyan | d7c7544 | 2010-01-24 22:47:53 -0800 | [diff] [blame] | 281 | ret = xfrm6_policy_init(); |
Dan Streetman | a8a572a | 2015-10-29 09:51:16 -0400 | [diff] [blame] | 282 | if (ret) |
Alexey Dobriyan | d7c7544 | 2010-01-24 22:47:53 -0800 | [diff] [blame] | 283 | goto out; |
Alexey Dobriyan | d7c7544 | 2010-01-24 22:47:53 -0800 | [diff] [blame] | 284 | ret = xfrm6_state_init(); |
| 285 | if (ret) |
| 286 | goto out_policy; |
| 287 | |
Steffen Klassert | 7e14ea1 | 2014-03-14 07:28:07 +0100 | [diff] [blame] | 288 | ret = xfrm6_protocol_init(); |
| 289 | if (ret) |
| 290 | goto out_state; |
| 291 | |
Michal Kubecek | 8d06887 | 2013-02-06 10:46:33 +0100 | [diff] [blame] | 292 | register_pernet_subsys(&xfrm6_net_ops); |
Daniel Lezcano | 0013cab | 2007-12-07 00:42:11 -0800 | [diff] [blame] | 293 | out: |
| 294 | return ret; |
Steffen Klassert | 7e14ea1 | 2014-03-14 07:28:07 +0100 | [diff] [blame] | 295 | out_state: |
| 296 | xfrm6_state_fini(); |
Daniel Lezcano | 0013cab | 2007-12-07 00:42:11 -0800 | [diff] [blame] | 297 | out_policy: |
| 298 | xfrm6_policy_fini(); |
| 299 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | void xfrm6_fini(void) |
| 303 | { |
Michal Kubecek | 8d06887 | 2013-02-06 10:46:33 +0100 | [diff] [blame] | 304 | unregister_pernet_subsys(&xfrm6_net_ops); |
Steffen Klassert | 7e14ea1 | 2014-03-14 07:28:07 +0100 | [diff] [blame] | 305 | xfrm6_protocol_fini(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | xfrm6_policy_fini(); |
| 307 | xfrm6_state_fini(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | } |