1 /* xfrm_user.c: User interface to configure xfrm engine.
3 * Copyright (C) 2002 David S. Miller (davem@redhat.com)
7 * Kazunori MIYAZAWA @USAGI
8 * Kunihiro Ishiguro <kunihiro@ipinfusion.com>
13 #include <linux/crypto.h>
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/types.h>
17 #include <linux/slab.h>
18 #include <linux/socket.h>
19 #include <linux/string.h>
20 #include <linux/net.h>
21 #include <linux/skbuff.h>
22 #include <linux/rtnetlink.h>
23 #include <linux/pfkeyv2.h>
24 #include <linux/ipsec.h>
25 #include <linux/init.h>
26 #include <linux/security.h>
29 #include <net/netlink.h>
30 #include <asm/uaccess.h>
31 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
32 #include <linux/in6.h>
34 #include <linux/audit.h>
36 static int verify_one_alg(struct rtattr **xfrma, enum xfrm_attr_type_t type)
38 struct rtattr *rt = xfrma[type - 1];
39 struct xfrm_algo *algp;
45 len = (rt->rta_len - sizeof(*rt)) - sizeof(*algp);
51 len -= (algp->alg_key_len + 7U) / 8;
57 if (!algp->alg_key_len &&
58 strcmp(algp->alg_name, "digest_null") != 0)
63 if (!algp->alg_key_len &&
64 strcmp(algp->alg_name, "cipher_null") != 0)
69 /* Zero length keys are legal. */
76 algp->alg_name[CRYPTO_MAX_ALG_NAME - 1] = '\0';
80 static int verify_encap_tmpl(struct rtattr **xfrma)
82 struct rtattr *rt = xfrma[XFRMA_ENCAP - 1];
83 struct xfrm_encap_tmpl *encap;
88 if ((rt->rta_len - sizeof(*rt)) < sizeof(*encap))
94 static int verify_one_addr(struct rtattr **xfrma, enum xfrm_attr_type_t type,
95 xfrm_address_t **addrp)
97 struct rtattr *rt = xfrma[type - 1];
102 if ((rt->rta_len - sizeof(*rt)) < sizeof(**addrp))
106 *addrp = RTA_DATA(rt);
111 static inline int verify_sec_ctx_len(struct rtattr **xfrma)
113 struct rtattr *rt = xfrma[XFRMA_SEC_CTX - 1];
114 struct xfrm_user_sec_ctx *uctx;
120 if (rt->rta_len < sizeof(*uctx))
125 len += sizeof(struct xfrm_user_sec_ctx);
126 len += uctx->ctx_len;
128 if (uctx->len != len)
135 static int verify_newsa_info(struct xfrm_usersa_info *p,
136 struct rtattr **xfrma)
146 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
158 switch (p->id.proto) {
160 if (!xfrma[XFRMA_ALG_AUTH-1] ||
161 xfrma[XFRMA_ALG_CRYPT-1] ||
162 xfrma[XFRMA_ALG_COMP-1])
167 if ((!xfrma[XFRMA_ALG_AUTH-1] &&
168 !xfrma[XFRMA_ALG_CRYPT-1]) ||
169 xfrma[XFRMA_ALG_COMP-1])
174 if (!xfrma[XFRMA_ALG_COMP-1] ||
175 xfrma[XFRMA_ALG_AUTH-1] ||
176 xfrma[XFRMA_ALG_CRYPT-1])
180 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
181 case IPPROTO_DSTOPTS:
182 case IPPROTO_ROUTING:
183 if (xfrma[XFRMA_ALG_COMP-1] ||
184 xfrma[XFRMA_ALG_AUTH-1] ||
185 xfrma[XFRMA_ALG_CRYPT-1] ||
186 xfrma[XFRMA_ENCAP-1] ||
187 xfrma[XFRMA_SEC_CTX-1] ||
188 !xfrma[XFRMA_COADDR-1])
197 if ((err = verify_one_alg(xfrma, XFRMA_ALG_AUTH)))
199 if ((err = verify_one_alg(xfrma, XFRMA_ALG_CRYPT)))
201 if ((err = verify_one_alg(xfrma, XFRMA_ALG_COMP)))
203 if ((err = verify_encap_tmpl(xfrma)))
205 if ((err = verify_sec_ctx_len(xfrma)))
207 if ((err = verify_one_addr(xfrma, XFRMA_COADDR, NULL)))
212 case XFRM_MODE_TRANSPORT:
213 case XFRM_MODE_TUNNEL:
214 case XFRM_MODE_ROUTEOPTIMIZATION:
228 static int attach_one_algo(struct xfrm_algo **algpp, u8 *props,
229 struct xfrm_algo_desc *(*get_byname)(char *, int),
230 struct rtattr *u_arg)
232 struct rtattr *rta = u_arg;
233 struct xfrm_algo *p, *ualg;
234 struct xfrm_algo_desc *algo;
240 ualg = RTA_DATA(rta);
242 algo = get_byname(ualg->alg_name, 1);
245 *props = algo->desc.sadb_alg_id;
247 len = sizeof(*ualg) + (ualg->alg_key_len + 7U) / 8;
248 p = kmemdup(ualg, len, GFP_KERNEL);
252 strcpy(p->alg_name, algo->name);
257 static int attach_encap_tmpl(struct xfrm_encap_tmpl **encapp, struct rtattr *u_arg)
259 struct rtattr *rta = u_arg;
260 struct xfrm_encap_tmpl *p, *uencap;
265 uencap = RTA_DATA(rta);
266 p = kmemdup(uencap, sizeof(*p), GFP_KERNEL);
275 static inline int xfrm_user_sec_ctx_size(struct xfrm_sec_ctx *xfrm_ctx)
280 len += sizeof(struct xfrm_user_sec_ctx);
281 len += xfrm_ctx->ctx_len;
286 static int attach_sec_ctx(struct xfrm_state *x, struct rtattr *u_arg)
288 struct xfrm_user_sec_ctx *uctx;
293 uctx = RTA_DATA(u_arg);
294 return security_xfrm_state_alloc(x, uctx);
297 static int attach_one_addr(xfrm_address_t **addrpp, struct rtattr *u_arg)
299 struct rtattr *rta = u_arg;
300 xfrm_address_t *p, *uaddrp;
305 uaddrp = RTA_DATA(rta);
306 p = kmemdup(uaddrp, sizeof(*p), GFP_KERNEL);
314 static void copy_from_user_state(struct xfrm_state *x, struct xfrm_usersa_info *p)
316 memcpy(&x->id, &p->id, sizeof(x->id));
317 memcpy(&x->sel, &p->sel, sizeof(x->sel));
318 memcpy(&x->lft, &p->lft, sizeof(x->lft));
319 x->props.mode = p->mode;
320 x->props.replay_window = p->replay_window;
321 x->props.reqid = p->reqid;
322 x->props.family = p->family;
323 memcpy(&x->props.saddr, &p->saddr, sizeof(x->props.saddr));
324 x->props.flags = p->flags;
328 * someday when pfkey also has support, we could have the code
329 * somehow made shareable and move it to xfrm_state.c - JHS
332 static int xfrm_update_ae_params(struct xfrm_state *x, struct rtattr **xfrma)
335 struct rtattr *rp = xfrma[XFRMA_REPLAY_VAL-1];
336 struct rtattr *lt = xfrma[XFRMA_LTIME_VAL-1];
337 struct rtattr *et = xfrma[XFRMA_ETIMER_THRESH-1];
338 struct rtattr *rt = xfrma[XFRMA_REPLAY_THRESH-1];
341 struct xfrm_replay_state *replay;
342 if (RTA_PAYLOAD(rp) < sizeof(*replay))
344 replay = RTA_DATA(rp);
345 memcpy(&x->replay, replay, sizeof(*replay));
346 memcpy(&x->preplay, replay, sizeof(*replay));
350 struct xfrm_lifetime_cur *ltime;
351 if (RTA_PAYLOAD(lt) < sizeof(*ltime))
353 ltime = RTA_DATA(lt);
354 x->curlft.bytes = ltime->bytes;
355 x->curlft.packets = ltime->packets;
356 x->curlft.add_time = ltime->add_time;
357 x->curlft.use_time = ltime->use_time;
361 if (RTA_PAYLOAD(et) < sizeof(u32))
363 x->replay_maxage = *(u32*)RTA_DATA(et);
367 if (RTA_PAYLOAD(rt) < sizeof(u32))
369 x->replay_maxdiff = *(u32*)RTA_DATA(rt);
377 static struct xfrm_state *xfrm_state_construct(struct xfrm_usersa_info *p,
378 struct rtattr **xfrma,
381 struct xfrm_state *x = xfrm_state_alloc();
387 copy_from_user_state(x, p);
389 if ((err = attach_one_algo(&x->aalg, &x->props.aalgo,
390 xfrm_aalg_get_byname,
391 xfrma[XFRMA_ALG_AUTH-1])))
393 if ((err = attach_one_algo(&x->ealg, &x->props.ealgo,
394 xfrm_ealg_get_byname,
395 xfrma[XFRMA_ALG_CRYPT-1])))
397 if ((err = attach_one_algo(&x->calg, &x->props.calgo,
398 xfrm_calg_get_byname,
399 xfrma[XFRMA_ALG_COMP-1])))
401 if ((err = attach_encap_tmpl(&x->encap, xfrma[XFRMA_ENCAP-1])))
403 if ((err = attach_one_addr(&x->coaddr, xfrma[XFRMA_COADDR-1])))
405 err = xfrm_init_state(x);
409 if ((err = attach_sec_ctx(x, xfrma[XFRMA_SEC_CTX-1])))
413 x->replay_maxdiff = sysctl_xfrm_aevent_rseqth;
414 /* sysctl_xfrm_aevent_etime is in 100ms units */
415 x->replay_maxage = (sysctl_xfrm_aevent_etime*HZ)/XFRM_AE_ETH_M;
416 x->preplay.bitmap = 0;
417 x->preplay.seq = x->replay.seq+x->replay_maxdiff;
418 x->preplay.oseq = x->replay.oseq +x->replay_maxdiff;
420 /* override default values from above */
422 err = xfrm_update_ae_params(x, (struct rtattr **)xfrma);
429 x->km.state = XFRM_STATE_DEAD;
436 static int xfrm_add_sa(struct sk_buff *skb, struct nlmsghdr *nlh,
437 struct rtattr **xfrma)
439 struct xfrm_usersa_info *p = NLMSG_DATA(nlh);
440 struct xfrm_state *x;
444 err = verify_newsa_info(p, xfrma);
448 x = xfrm_state_construct(p, xfrma, &err);
453 if (nlh->nlmsg_type == XFRM_MSG_NEWSA)
454 err = xfrm_state_add(x);
456 err = xfrm_state_update(x);
458 xfrm_audit_log(NETLINK_CB(skb).loginuid, NETLINK_CB(skb).sid,
459 AUDIT_MAC_IPSEC_ADDSA, err ? 0 : 1, NULL, x);
462 x->km.state = XFRM_STATE_DEAD;
467 c.seq = nlh->nlmsg_seq;
468 c.pid = nlh->nlmsg_pid;
469 c.event = nlh->nlmsg_type;
471 km_state_notify(x, &c);
477 static struct xfrm_state *xfrm_user_state_lookup(struct xfrm_usersa_id *p,
478 struct rtattr **xfrma,
481 struct xfrm_state *x = NULL;
484 if (xfrm_id_proto_match(p->proto, IPSEC_PROTO_ANY)) {
486 x = xfrm_state_lookup(&p->daddr, p->spi, p->proto, p->family);
488 xfrm_address_t *saddr = NULL;
490 err = verify_one_addr(xfrma, XFRMA_SRCADDR, &saddr);
500 x = xfrm_state_lookup_byaddr(&p->daddr, saddr, p->proto,
510 static int xfrm_del_sa(struct sk_buff *skb, struct nlmsghdr *nlh,
511 struct rtattr **xfrma)
513 struct xfrm_state *x;
516 struct xfrm_usersa_id *p = NLMSG_DATA(nlh);
518 x = xfrm_user_state_lookup(p, xfrma, &err);
522 if ((err = security_xfrm_state_delete(x)) != 0)
525 if (xfrm_state_kern(x)) {
530 err = xfrm_state_delete(x);
535 c.seq = nlh->nlmsg_seq;
536 c.pid = nlh->nlmsg_pid;
537 c.event = nlh->nlmsg_type;
538 km_state_notify(x, &c);
541 xfrm_audit_log(NETLINK_CB(skb).loginuid, NETLINK_CB(skb).sid,
542 AUDIT_MAC_IPSEC_DELSA, err ? 0 : 1, NULL, x);
547 static void copy_to_user_state(struct xfrm_state *x, struct xfrm_usersa_info *p)
549 memcpy(&p->id, &x->id, sizeof(p->id));
550 memcpy(&p->sel, &x->sel, sizeof(p->sel));
551 memcpy(&p->lft, &x->lft, sizeof(p->lft));
552 memcpy(&p->curlft, &x->curlft, sizeof(p->curlft));
553 memcpy(&p->stats, &x->stats, sizeof(p->stats));
554 memcpy(&p->saddr, &x->props.saddr, sizeof(p->saddr));
555 p->mode = x->props.mode;
556 p->replay_window = x->props.replay_window;
557 p->reqid = x->props.reqid;
558 p->family = x->props.family;
559 p->flags = x->props.flags;
563 struct xfrm_dump_info {
564 struct sk_buff *in_skb;
565 struct sk_buff *out_skb;
572 static int dump_one_state(struct xfrm_state *x, int count, void *ptr)
574 struct xfrm_dump_info *sp = ptr;
575 struct sk_buff *in_skb = sp->in_skb;
576 struct sk_buff *skb = sp->out_skb;
577 struct xfrm_usersa_info *p;
578 struct nlmsghdr *nlh;
579 unsigned char *b = skb_tail_pointer(skb);
581 if (sp->this_idx < sp->start_idx)
584 nlh = NLMSG_PUT(skb, NETLINK_CB(in_skb).pid,
586 XFRM_MSG_NEWSA, sizeof(*p));
587 nlh->nlmsg_flags = sp->nlmsg_flags;
590 copy_to_user_state(x, p);
593 RTA_PUT(skb, XFRMA_ALG_AUTH,
594 sizeof(*(x->aalg))+(x->aalg->alg_key_len+7)/8, x->aalg);
596 RTA_PUT(skb, XFRMA_ALG_CRYPT,
597 sizeof(*(x->ealg))+(x->ealg->alg_key_len+7)/8, x->ealg);
599 RTA_PUT(skb, XFRMA_ALG_COMP, sizeof(*(x->calg)), x->calg);
602 RTA_PUT(skb, XFRMA_ENCAP, sizeof(*x->encap), x->encap);
605 int ctx_size = sizeof(struct xfrm_sec_ctx) +
606 x->security->ctx_len;
607 struct rtattr *rt = __RTA_PUT(skb, XFRMA_SEC_CTX, ctx_size);
608 struct xfrm_user_sec_ctx *uctx = RTA_DATA(rt);
610 uctx->exttype = XFRMA_SEC_CTX;
611 uctx->len = ctx_size;
612 uctx->ctx_doi = x->security->ctx_doi;
613 uctx->ctx_alg = x->security->ctx_alg;
614 uctx->ctx_len = x->security->ctx_len;
615 memcpy(uctx + 1, x->security->ctx_str, x->security->ctx_len);
619 RTA_PUT(skb, XFRMA_COADDR, sizeof(*x->coaddr), x->coaddr);
622 RTA_PUT(skb, XFRMA_LASTUSED, sizeof(x->lastused), &x->lastused);
624 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
635 static int xfrm_dump_sa(struct sk_buff *skb, struct netlink_callback *cb)
637 struct xfrm_dump_info info;
639 info.in_skb = cb->skb;
641 info.nlmsg_seq = cb->nlh->nlmsg_seq;
642 info.nlmsg_flags = NLM_F_MULTI;
644 info.start_idx = cb->args[0];
645 (void) xfrm_state_walk(0, dump_one_state, &info);
646 cb->args[0] = info.this_idx;
651 static struct sk_buff *xfrm_state_netlink(struct sk_buff *in_skb,
652 struct xfrm_state *x, u32 seq)
654 struct xfrm_dump_info info;
657 skb = alloc_skb(NLMSG_GOODSIZE, GFP_ATOMIC);
659 return ERR_PTR(-ENOMEM);
661 info.in_skb = in_skb;
663 info.nlmsg_seq = seq;
664 info.nlmsg_flags = 0;
665 info.this_idx = info.start_idx = 0;
667 if (dump_one_state(x, 0, &info)) {
675 static int build_sadinfo(struct sk_buff *skb, u32 pid, u32 seq, u32 flags)
677 struct xfrm_sadinfo si;
678 struct nlmsghdr *nlh;
681 nlh = nlmsg_put(skb, pid, seq, XFRM_MSG_NEWSADINFO, sizeof(u32), 0);
682 if (nlh == NULL) /* shouldnt really happen ... */
687 xfrm_sad_getinfo(&si);
689 if (flags & XFRM_SAD_HMASK)
690 NLA_PUT_U32(skb, XFRMA_SADHMASK, si.sadhcnt);
691 if (flags & XFRM_SAD_HMAX)
692 NLA_PUT_U32(skb, XFRMA_SADHMAX, si.sadhmcnt);
693 if (flags & XFRM_SAD_CNT)
694 NLA_PUT_U32(skb, XFRMA_SADCNT, si.sadcnt);
696 return nlmsg_end(skb, nlh);
699 nlmsg_cancel(skb, nlh);
703 static int xfrm_get_sadinfo(struct sk_buff *skb, struct nlmsghdr *nlh,
704 struct rtattr **xfrma)
706 struct sk_buff *r_skb;
707 u32 *flags = NLMSG_DATA(nlh);
708 u32 spid = NETLINK_CB(skb).pid;
709 u32 seq = nlh->nlmsg_seq;
710 int len = NLMSG_LENGTH(sizeof(u32));
712 if (*flags & XFRM_SAD_HMASK)
713 len += RTA_SPACE(sizeof(u32));
714 if (*flags & XFRM_SAD_HMAX)
715 len += RTA_SPACE(sizeof(u32));
716 if (*flags & XFRM_SAD_CNT)
717 len += RTA_SPACE(sizeof(u32));
719 r_skb = alloc_skb(len, GFP_ATOMIC);
724 if (build_sadinfo(r_skb, spid, seq, *flags) < 0)
727 return nlmsg_unicast(xfrm_nl, r_skb, spid);
730 static int xfrm_get_sa(struct sk_buff *skb, struct nlmsghdr *nlh,
731 struct rtattr **xfrma)
733 struct xfrm_usersa_id *p = NLMSG_DATA(nlh);
734 struct xfrm_state *x;
735 struct sk_buff *resp_skb;
738 x = xfrm_user_state_lookup(p, xfrma, &err);
742 resp_skb = xfrm_state_netlink(skb, x, nlh->nlmsg_seq);
743 if (IS_ERR(resp_skb)) {
744 err = PTR_ERR(resp_skb);
746 err = netlink_unicast(xfrm_nl, resp_skb,
747 NETLINK_CB(skb).pid, MSG_DONTWAIT);
754 static int verify_userspi_info(struct xfrm_userspi_info *p)
756 switch (p->info.id.proto) {
762 /* IPCOMP spi is 16-bits. */
763 if (p->max >= 0x10000)
777 static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh,
778 struct rtattr **xfrma)
780 struct xfrm_state *x;
781 struct xfrm_userspi_info *p;
782 struct sk_buff *resp_skb;
783 xfrm_address_t *daddr;
788 err = verify_userspi_info(p);
792 family = p->info.family;
793 daddr = &p->info.id.daddr;
797 x = xfrm_find_acq_byseq(p->info.seq);
798 if (x && xfrm_addr_cmp(&x->id.daddr, daddr, family)) {
805 x = xfrm_find_acq(p->info.mode, p->info.reqid,
806 p->info.id.proto, daddr,
813 resp_skb = ERR_PTR(-ENOENT);
815 spin_lock_bh(&x->lock);
816 if (x->km.state != XFRM_STATE_DEAD) {
817 xfrm_alloc_spi(x, htonl(p->min), htonl(p->max));
819 resp_skb = xfrm_state_netlink(skb, x, nlh->nlmsg_seq);
821 spin_unlock_bh(&x->lock);
823 if (IS_ERR(resp_skb)) {
824 err = PTR_ERR(resp_skb);
828 err = netlink_unicast(xfrm_nl, resp_skb,
829 NETLINK_CB(skb).pid, MSG_DONTWAIT);
837 static int verify_policy_dir(u8 dir)
841 case XFRM_POLICY_OUT:
842 case XFRM_POLICY_FWD:
852 static int verify_policy_type(u8 type)
855 case XFRM_POLICY_TYPE_MAIN:
856 #ifdef CONFIG_XFRM_SUB_POLICY
857 case XFRM_POLICY_TYPE_SUB:
868 static int verify_newpolicy_info(struct xfrm_userpolicy_info *p)
872 case XFRM_SHARE_SESSION:
873 case XFRM_SHARE_USER:
874 case XFRM_SHARE_UNIQUE:
882 case XFRM_POLICY_ALLOW:
883 case XFRM_POLICY_BLOCK:
890 switch (p->sel.family) {
895 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
898 return -EAFNOSUPPORT;
905 return verify_policy_dir(p->dir);
908 static int copy_from_user_sec_ctx(struct xfrm_policy *pol, struct rtattr **xfrma)
910 struct rtattr *rt = xfrma[XFRMA_SEC_CTX-1];
911 struct xfrm_user_sec_ctx *uctx;
917 return security_xfrm_policy_alloc(pol, uctx);
920 static void copy_templates(struct xfrm_policy *xp, struct xfrm_user_tmpl *ut,
926 for (i = 0; i < nr; i++, ut++) {
927 struct xfrm_tmpl *t = &xp->xfrm_vec[i];
929 memcpy(&t->id, &ut->id, sizeof(struct xfrm_id));
930 memcpy(&t->saddr, &ut->saddr,
931 sizeof(xfrm_address_t));
932 t->reqid = ut->reqid;
934 t->share = ut->share;
935 t->optional = ut->optional;
936 t->aalgos = ut->aalgos;
937 t->ealgos = ut->ealgos;
938 t->calgos = ut->calgos;
939 t->encap_family = ut->family;
943 static int validate_tmpl(int nr, struct xfrm_user_tmpl *ut, u16 family)
947 if (nr > XFRM_MAX_DEPTH)
950 for (i = 0; i < nr; i++) {
951 /* We never validated the ut->family value, so many
952 * applications simply leave it at zero. The check was
953 * never made and ut->family was ignored because all
954 * templates could be assumed to have the same family as
955 * the policy itself. Now that we will have ipv4-in-ipv6
956 * and ipv6-in-ipv4 tunnels, this is no longer true.
959 ut[i].family = family;
961 switch (ut[i].family) {
964 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
976 static int copy_from_user_tmpl(struct xfrm_policy *pol, struct rtattr **xfrma)
978 struct rtattr *rt = xfrma[XFRMA_TMPL-1];
983 struct xfrm_user_tmpl *utmpl = RTA_DATA(rt);
984 int nr = (rt->rta_len - sizeof(*rt)) / sizeof(*utmpl);
987 err = validate_tmpl(nr, utmpl, pol->family);
991 copy_templates(pol, RTA_DATA(rt), nr);
996 static int copy_from_user_policy_type(u8 *tp, struct rtattr **xfrma)
998 struct rtattr *rt = xfrma[XFRMA_POLICY_TYPE-1];
999 struct xfrm_userpolicy_type *upt;
1000 u8 type = XFRM_POLICY_TYPE_MAIN;
1004 if (rt->rta_len < sizeof(*upt))
1011 err = verify_policy_type(type);
1019 static void copy_from_user_policy(struct xfrm_policy *xp, struct xfrm_userpolicy_info *p)
1021 xp->priority = p->priority;
1022 xp->index = p->index;
1023 memcpy(&xp->selector, &p->sel, sizeof(xp->selector));
1024 memcpy(&xp->lft, &p->lft, sizeof(xp->lft));
1025 xp->action = p->action;
1026 xp->flags = p->flags;
1027 xp->family = p->sel.family;
1028 /* XXX xp->share = p->share; */
1031 static void copy_to_user_policy(struct xfrm_policy *xp, struct xfrm_userpolicy_info *p, int dir)
1033 memcpy(&p->sel, &xp->selector, sizeof(p->sel));
1034 memcpy(&p->lft, &xp->lft, sizeof(p->lft));
1035 memcpy(&p->curlft, &xp->curlft, sizeof(p->curlft));
1036 p->priority = xp->priority;
1037 p->index = xp->index;
1038 p->sel.family = xp->family;
1040 p->action = xp->action;
1041 p->flags = xp->flags;
1042 p->share = XFRM_SHARE_ANY; /* XXX xp->share */
1045 static struct xfrm_policy *xfrm_policy_construct(struct xfrm_userpolicy_info *p, struct rtattr **xfrma, int *errp)
1047 struct xfrm_policy *xp = xfrm_policy_alloc(GFP_KERNEL);
1055 copy_from_user_policy(xp, p);
1057 err = copy_from_user_policy_type(&xp->type, xfrma);
1061 if (!(err = copy_from_user_tmpl(xp, xfrma)))
1062 err = copy_from_user_sec_ctx(xp, xfrma);
1073 static int xfrm_add_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
1074 struct rtattr **xfrma)
1076 struct xfrm_userpolicy_info *p = NLMSG_DATA(nlh);
1077 struct xfrm_policy *xp;
1082 err = verify_newpolicy_info(p);
1085 err = verify_sec_ctx_len(xfrma);
1089 xp = xfrm_policy_construct(p, xfrma, &err);
1093 /* shouldnt excl be based on nlh flags??
1094 * Aha! this is anti-netlink really i.e more pfkey derived
1095 * in netlink excl is a flag and you wouldnt need
1096 * a type XFRM_MSG_UPDPOLICY - JHS */
1097 excl = nlh->nlmsg_type == XFRM_MSG_NEWPOLICY;
1098 err = xfrm_policy_insert(p->dir, xp, excl);
1099 xfrm_audit_log(NETLINK_CB(skb).loginuid, NETLINK_CB(skb).sid,
1100 AUDIT_MAC_IPSEC_DELSPD, err ? 0 : 1, xp, NULL);
1103 security_xfrm_policy_free(xp);
1108 c.event = nlh->nlmsg_type;
1109 c.seq = nlh->nlmsg_seq;
1110 c.pid = nlh->nlmsg_pid;
1111 km_policy_notify(xp, p->dir, &c);
1118 static int copy_to_user_tmpl(struct xfrm_policy *xp, struct sk_buff *skb)
1120 struct xfrm_user_tmpl vec[XFRM_MAX_DEPTH];
1123 if (xp->xfrm_nr == 0)
1126 for (i = 0; i < xp->xfrm_nr; i++) {
1127 struct xfrm_user_tmpl *up = &vec[i];
1128 struct xfrm_tmpl *kp = &xp->xfrm_vec[i];
1130 memcpy(&up->id, &kp->id, sizeof(up->id));
1131 up->family = kp->encap_family;
1132 memcpy(&up->saddr, &kp->saddr, sizeof(up->saddr));
1133 up->reqid = kp->reqid;
1134 up->mode = kp->mode;
1135 up->share = kp->share;
1136 up->optional = kp->optional;
1137 up->aalgos = kp->aalgos;
1138 up->ealgos = kp->ealgos;
1139 up->calgos = kp->calgos;
1141 RTA_PUT(skb, XFRMA_TMPL,
1142 (sizeof(struct xfrm_user_tmpl) * xp->xfrm_nr),
1151 static int copy_sec_ctx(struct xfrm_sec_ctx *s, struct sk_buff *skb)
1153 int ctx_size = sizeof(struct xfrm_sec_ctx) + s->ctx_len;
1154 struct rtattr *rt = __RTA_PUT(skb, XFRMA_SEC_CTX, ctx_size);
1155 struct xfrm_user_sec_ctx *uctx = RTA_DATA(rt);
1157 uctx->exttype = XFRMA_SEC_CTX;
1158 uctx->len = ctx_size;
1159 uctx->ctx_doi = s->ctx_doi;
1160 uctx->ctx_alg = s->ctx_alg;
1161 uctx->ctx_len = s->ctx_len;
1162 memcpy(uctx + 1, s->ctx_str, s->ctx_len);
1169 static inline int copy_to_user_state_sec_ctx(struct xfrm_state *x, struct sk_buff *skb)
1172 return copy_sec_ctx(x->security, skb);
1177 static inline int copy_to_user_sec_ctx(struct xfrm_policy *xp, struct sk_buff *skb)
1180 return copy_sec_ctx(xp->security, skb);
1185 #ifdef CONFIG_XFRM_SUB_POLICY
1186 static int copy_to_user_policy_type(u8 type, struct sk_buff *skb)
1188 struct xfrm_userpolicy_type upt;
1190 memset(&upt, 0, sizeof(upt));
1193 RTA_PUT(skb, XFRMA_POLICY_TYPE, sizeof(upt), &upt);
1202 static inline int copy_to_user_policy_type(u8 type, struct sk_buff *skb)
1208 static int dump_one_policy(struct xfrm_policy *xp, int dir, int count, void *ptr)
1210 struct xfrm_dump_info *sp = ptr;
1211 struct xfrm_userpolicy_info *p;
1212 struct sk_buff *in_skb = sp->in_skb;
1213 struct sk_buff *skb = sp->out_skb;
1214 struct nlmsghdr *nlh;
1215 unsigned char *b = skb_tail_pointer(skb);
1217 if (sp->this_idx < sp->start_idx)
1220 nlh = NLMSG_PUT(skb, NETLINK_CB(in_skb).pid,
1222 XFRM_MSG_NEWPOLICY, sizeof(*p));
1223 p = NLMSG_DATA(nlh);
1224 nlh->nlmsg_flags = sp->nlmsg_flags;
1226 copy_to_user_policy(xp, p, dir);
1227 if (copy_to_user_tmpl(xp, skb) < 0)
1229 if (copy_to_user_sec_ctx(xp, skb))
1231 if (copy_to_user_policy_type(xp->type, skb) < 0)
1234 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
1244 static int xfrm_dump_policy(struct sk_buff *skb, struct netlink_callback *cb)
1246 struct xfrm_dump_info info;
1248 info.in_skb = cb->skb;
1250 info.nlmsg_seq = cb->nlh->nlmsg_seq;
1251 info.nlmsg_flags = NLM_F_MULTI;
1253 info.start_idx = cb->args[0];
1254 (void) xfrm_policy_walk(XFRM_POLICY_TYPE_MAIN, dump_one_policy, &info);
1255 #ifdef CONFIG_XFRM_SUB_POLICY
1256 (void) xfrm_policy_walk(XFRM_POLICY_TYPE_SUB, dump_one_policy, &info);
1258 cb->args[0] = info.this_idx;
1263 static struct sk_buff *xfrm_policy_netlink(struct sk_buff *in_skb,
1264 struct xfrm_policy *xp,
1267 struct xfrm_dump_info info;
1268 struct sk_buff *skb;
1270 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
1272 return ERR_PTR(-ENOMEM);
1274 info.in_skb = in_skb;
1276 info.nlmsg_seq = seq;
1277 info.nlmsg_flags = 0;
1278 info.this_idx = info.start_idx = 0;
1280 if (dump_one_policy(xp, dir, 0, &info) < 0) {
1288 static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
1289 struct rtattr **xfrma)
1291 struct xfrm_policy *xp;
1292 struct xfrm_userpolicy_id *p;
1293 u8 type = XFRM_POLICY_TYPE_MAIN;
1298 p = NLMSG_DATA(nlh);
1299 delete = nlh->nlmsg_type == XFRM_MSG_DELPOLICY;
1301 err = copy_from_user_policy_type(&type, xfrma);
1305 err = verify_policy_dir(p->dir);
1310 xp = xfrm_policy_byid(type, p->dir, p->index, delete, &err);
1312 struct rtattr *rt = xfrma[XFRMA_SEC_CTX-1];
1313 struct xfrm_policy tmp;
1315 err = verify_sec_ctx_len(xfrma);
1319 memset(&tmp, 0, sizeof(struct xfrm_policy));
1321 struct xfrm_user_sec_ctx *uctx = RTA_DATA(rt);
1323 if ((err = security_xfrm_policy_alloc(&tmp, uctx)))
1326 xp = xfrm_policy_bysel_ctx(type, p->dir, &p->sel, tmp.security,
1328 security_xfrm_policy_free(&tmp);
1334 struct sk_buff *resp_skb;
1336 resp_skb = xfrm_policy_netlink(skb, xp, p->dir, nlh->nlmsg_seq);
1337 if (IS_ERR(resp_skb)) {
1338 err = PTR_ERR(resp_skb);
1340 err = netlink_unicast(xfrm_nl, resp_skb,
1341 NETLINK_CB(skb).pid,
1345 xfrm_audit_log(NETLINK_CB(skb).loginuid, NETLINK_CB(skb).sid,
1346 AUDIT_MAC_IPSEC_DELSPD, err ? 0 : 1, xp, NULL);
1351 c.data.byid = p->index;
1352 c.event = nlh->nlmsg_type;
1353 c.seq = nlh->nlmsg_seq;
1354 c.pid = nlh->nlmsg_pid;
1355 km_policy_notify(xp, p->dir, &c);
1363 static int xfrm_flush_sa(struct sk_buff *skb, struct nlmsghdr *nlh,
1364 struct rtattr **xfrma)
1367 struct xfrm_usersa_flush *p = NLMSG_DATA(nlh);
1368 struct xfrm_audit audit_info;
1370 audit_info.loginuid = NETLINK_CB(skb).loginuid;
1371 audit_info.secid = NETLINK_CB(skb).sid;
1372 xfrm_state_flush(p->proto, &audit_info);
1373 c.data.proto = p->proto;
1374 c.event = nlh->nlmsg_type;
1375 c.seq = nlh->nlmsg_seq;
1376 c.pid = nlh->nlmsg_pid;
1377 km_state_notify(NULL, &c);
1383 static int build_aevent(struct sk_buff *skb, struct xfrm_state *x, struct km_event *c)
1385 struct xfrm_aevent_id *id;
1386 struct nlmsghdr *nlh;
1387 struct xfrm_lifetime_cur ltime;
1388 unsigned char *b = skb_tail_pointer(skb);
1390 nlh = NLMSG_PUT(skb, c->pid, c->seq, XFRM_MSG_NEWAE, sizeof(*id));
1391 id = NLMSG_DATA(nlh);
1392 nlh->nlmsg_flags = 0;
1394 memcpy(&id->sa_id.daddr, &x->id.daddr,sizeof(x->id.daddr));
1395 id->sa_id.spi = x->id.spi;
1396 id->sa_id.family = x->props.family;
1397 id->sa_id.proto = x->id.proto;
1398 memcpy(&id->saddr, &x->props.saddr,sizeof(x->props.saddr));
1399 id->reqid = x->props.reqid;
1400 id->flags = c->data.aevent;
1402 RTA_PUT(skb, XFRMA_REPLAY_VAL, sizeof(x->replay), &x->replay);
1404 ltime.bytes = x->curlft.bytes;
1405 ltime.packets = x->curlft.packets;
1406 ltime.add_time = x->curlft.add_time;
1407 ltime.use_time = x->curlft.use_time;
1409 RTA_PUT(skb, XFRMA_LTIME_VAL, sizeof(struct xfrm_lifetime_cur), <ime);
1411 if (id->flags&XFRM_AE_RTHR) {
1412 RTA_PUT(skb,XFRMA_REPLAY_THRESH,sizeof(u32),&x->replay_maxdiff);
1415 if (id->flags&XFRM_AE_ETHR) {
1416 u32 etimer = x->replay_maxage*10/HZ;
1417 RTA_PUT(skb,XFRMA_ETIMER_THRESH,sizeof(u32),&etimer);
1420 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
1429 static int xfrm_get_ae(struct sk_buff *skb, struct nlmsghdr *nlh,
1430 struct rtattr **xfrma)
1432 struct xfrm_state *x;
1433 struct sk_buff *r_skb;
1436 struct xfrm_aevent_id *p = NLMSG_DATA(nlh);
1437 int len = NLMSG_LENGTH(sizeof(struct xfrm_aevent_id));
1438 struct xfrm_usersa_id *id = &p->sa_id;
1440 len += RTA_SPACE(sizeof(struct xfrm_replay_state));
1441 len += RTA_SPACE(sizeof(struct xfrm_lifetime_cur));
1443 if (p->flags&XFRM_AE_RTHR)
1444 len+=RTA_SPACE(sizeof(u32));
1446 if (p->flags&XFRM_AE_ETHR)
1447 len+=RTA_SPACE(sizeof(u32));
1449 r_skb = alloc_skb(len, GFP_ATOMIC);
1453 x = xfrm_state_lookup(&id->daddr, id->spi, id->proto, id->family);
1460 * XXX: is this lock really needed - none of the other
1461 * gets lock (the concern is things getting updated
1462 * while we are still reading) - jhs
1464 spin_lock_bh(&x->lock);
1465 c.data.aevent = p->flags;
1466 c.seq = nlh->nlmsg_seq;
1467 c.pid = nlh->nlmsg_pid;
1469 if (build_aevent(r_skb, x, &c) < 0)
1471 err = netlink_unicast(xfrm_nl, r_skb,
1472 NETLINK_CB(skb).pid, MSG_DONTWAIT);
1473 spin_unlock_bh(&x->lock);
1478 static int xfrm_new_ae(struct sk_buff *skb, struct nlmsghdr *nlh,
1479 struct rtattr **xfrma)
1481 struct xfrm_state *x;
1484 struct xfrm_aevent_id *p = NLMSG_DATA(nlh);
1485 struct rtattr *rp = xfrma[XFRMA_REPLAY_VAL-1];
1486 struct rtattr *lt = xfrma[XFRMA_LTIME_VAL-1];
1491 /* pedantic mode - thou shalt sayeth replaceth */
1492 if (!(nlh->nlmsg_flags&NLM_F_REPLACE))
1495 x = xfrm_state_lookup(&p->sa_id.daddr, p->sa_id.spi, p->sa_id.proto, p->sa_id.family);
1499 if (x->km.state != XFRM_STATE_VALID)
1502 spin_lock_bh(&x->lock);
1503 err = xfrm_update_ae_params(x, xfrma);
1504 spin_unlock_bh(&x->lock);
1508 c.event = nlh->nlmsg_type;
1509 c.seq = nlh->nlmsg_seq;
1510 c.pid = nlh->nlmsg_pid;
1511 c.data.aevent = XFRM_AE_CU;
1512 km_state_notify(x, &c);
1519 static int xfrm_flush_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
1520 struct rtattr **xfrma)
1523 u8 type = XFRM_POLICY_TYPE_MAIN;
1525 struct xfrm_audit audit_info;
1527 err = copy_from_user_policy_type(&type, xfrma);
1531 audit_info.loginuid = NETLINK_CB(skb).loginuid;
1532 audit_info.secid = NETLINK_CB(skb).sid;
1533 xfrm_policy_flush(type, &audit_info);
1535 c.event = nlh->nlmsg_type;
1536 c.seq = nlh->nlmsg_seq;
1537 c.pid = nlh->nlmsg_pid;
1538 km_policy_notify(NULL, 0, &c);
1542 static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh,
1543 struct rtattr **xfrma)
1545 struct xfrm_policy *xp;
1546 struct xfrm_user_polexpire *up = NLMSG_DATA(nlh);
1547 struct xfrm_userpolicy_info *p = &up->pol;
1548 u8 type = XFRM_POLICY_TYPE_MAIN;
1551 err = copy_from_user_policy_type(&type, xfrma);
1556 xp = xfrm_policy_byid(type, p->dir, p->index, 0, &err);
1558 struct rtattr *rt = xfrma[XFRMA_SEC_CTX-1];
1559 struct xfrm_policy tmp;
1561 err = verify_sec_ctx_len(xfrma);
1565 memset(&tmp, 0, sizeof(struct xfrm_policy));
1567 struct xfrm_user_sec_ctx *uctx = RTA_DATA(rt);
1569 if ((err = security_xfrm_policy_alloc(&tmp, uctx)))
1572 xp = xfrm_policy_bysel_ctx(type, p->dir, &p->sel, tmp.security,
1574 security_xfrm_policy_free(&tmp);
1579 read_lock(&xp->lock);
1581 read_unlock(&xp->lock);
1585 read_unlock(&xp->lock);
1588 xfrm_policy_delete(xp, p->dir);
1589 xfrm_audit_log(NETLINK_CB(skb).loginuid, NETLINK_CB(skb).sid,
1590 AUDIT_MAC_IPSEC_DELSPD, 1, xp, NULL);
1593 // reset the timers here?
1594 printk("Dont know what to do with soft policy expire\n");
1596 km_policy_expired(xp, p->dir, up->hard, current->pid);
1603 static int xfrm_add_sa_expire(struct sk_buff *skb, struct nlmsghdr *nlh,
1604 struct rtattr **xfrma)
1606 struct xfrm_state *x;
1608 struct xfrm_user_expire *ue = NLMSG_DATA(nlh);
1609 struct xfrm_usersa_info *p = &ue->state;
1611 x = xfrm_state_lookup(&p->id.daddr, p->id.spi, p->id.proto, p->family);
1617 spin_lock_bh(&x->lock);
1619 if (x->km.state != XFRM_STATE_VALID)
1621 km_state_expired(x, ue->hard, current->pid);
1624 __xfrm_state_delete(x);
1625 xfrm_audit_log(NETLINK_CB(skb).loginuid, NETLINK_CB(skb).sid,
1626 AUDIT_MAC_IPSEC_DELSA, 1, NULL, x);
1630 spin_unlock_bh(&x->lock);
1635 static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh,
1636 struct rtattr **xfrma)
1638 struct xfrm_policy *xp;
1639 struct xfrm_user_tmpl *ut;
1641 struct rtattr *rt = xfrma[XFRMA_TMPL-1];
1643 struct xfrm_user_acquire *ua = NLMSG_DATA(nlh);
1644 struct xfrm_state *x = xfrm_state_alloc();
1650 err = verify_newpolicy_info(&ua->policy);
1652 printk("BAD policy passed\n");
1658 xp = xfrm_policy_construct(&ua->policy, (struct rtattr **) xfrma, &err);
1664 memcpy(&x->id, &ua->id, sizeof(ua->id));
1665 memcpy(&x->props.saddr, &ua->saddr, sizeof(ua->saddr));
1666 memcpy(&x->sel, &ua->sel, sizeof(ua->sel));
1669 /* extract the templates and for each call km_key */
1670 for (i = 0; i < xp->xfrm_nr; i++, ut++) {
1671 struct xfrm_tmpl *t = &xp->xfrm_vec[i];
1672 memcpy(&x->id, &t->id, sizeof(x->id));
1673 x->props.mode = t->mode;
1674 x->props.reqid = t->reqid;
1675 x->props.family = ut->family;
1676 t->aalgos = ua->aalgos;
1677 t->ealgos = ua->ealgos;
1678 t->calgos = ua->calgos;
1679 err = km_query(x, t, xp);
1689 #ifdef CONFIG_XFRM_MIGRATE
1690 static int verify_user_migrate(struct rtattr **xfrma)
1692 struct rtattr *rt = xfrma[XFRMA_MIGRATE-1];
1693 struct xfrm_user_migrate *um;
1698 if ((rt->rta_len - sizeof(*rt)) < sizeof(*um))
1704 static int copy_from_user_migrate(struct xfrm_migrate *ma,
1705 struct rtattr **xfrma, int *num)
1707 struct rtattr *rt = xfrma[XFRMA_MIGRATE-1];
1708 struct xfrm_user_migrate *um;
1712 num_migrate = (rt->rta_len - sizeof(*rt)) / sizeof(*um);
1714 if (num_migrate <= 0 || num_migrate > XFRM_MAX_DEPTH)
1717 for (i = 0; i < num_migrate; i++, um++, ma++) {
1718 memcpy(&ma->old_daddr, &um->old_daddr, sizeof(ma->old_daddr));
1719 memcpy(&ma->old_saddr, &um->old_saddr, sizeof(ma->old_saddr));
1720 memcpy(&ma->new_daddr, &um->new_daddr, sizeof(ma->new_daddr));
1721 memcpy(&ma->new_saddr, &um->new_saddr, sizeof(ma->new_saddr));
1723 ma->proto = um->proto;
1724 ma->mode = um->mode;
1725 ma->reqid = um->reqid;
1727 ma->old_family = um->old_family;
1728 ma->new_family = um->new_family;
1735 static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh,
1736 struct rtattr **xfrma)
1738 struct xfrm_userpolicy_id *pi = NLMSG_DATA(nlh);
1739 struct xfrm_migrate m[XFRM_MAX_DEPTH];
1744 err = verify_user_migrate((struct rtattr **)xfrma);
1748 err = copy_from_user_policy_type(&type, (struct rtattr **)xfrma);
1752 err = copy_from_user_migrate((struct xfrm_migrate *)m,
1753 (struct rtattr **)xfrma, &n);
1760 xfrm_migrate(&pi->sel, pi->dir, type, m, n);
1765 static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh,
1766 struct rtattr **xfrma)
1768 return -ENOPROTOOPT;
1772 #ifdef CONFIG_XFRM_MIGRATE
1773 static int copy_to_user_migrate(struct xfrm_migrate *m, struct sk_buff *skb)
1775 struct xfrm_user_migrate um;
1777 memset(&um, 0, sizeof(um));
1778 um.proto = m->proto;
1780 um.reqid = m->reqid;
1781 um.old_family = m->old_family;
1782 memcpy(&um.old_daddr, &m->old_daddr, sizeof(um.old_daddr));
1783 memcpy(&um.old_saddr, &m->old_saddr, sizeof(um.old_saddr));
1784 um.new_family = m->new_family;
1785 memcpy(&um.new_daddr, &m->new_daddr, sizeof(um.new_daddr));
1786 memcpy(&um.new_saddr, &m->new_saddr, sizeof(um.new_saddr));
1788 RTA_PUT(skb, XFRMA_MIGRATE, sizeof(um), &um);
1795 static int build_migrate(struct sk_buff *skb, struct xfrm_migrate *m,
1796 int num_migrate, struct xfrm_selector *sel,
1799 struct xfrm_migrate *mp;
1800 struct xfrm_userpolicy_id *pol_id;
1801 struct nlmsghdr *nlh;
1802 unsigned char *b = skb_tail_pointer(skb);
1805 nlh = NLMSG_PUT(skb, 0, 0, XFRM_MSG_MIGRATE, sizeof(*pol_id));
1806 pol_id = NLMSG_DATA(nlh);
1807 nlh->nlmsg_flags = 0;
1809 /* copy data from selector, dir, and type to the pol_id */
1810 memset(pol_id, 0, sizeof(*pol_id));
1811 memcpy(&pol_id->sel, sel, sizeof(pol_id->sel));
1814 if (copy_to_user_policy_type(type, skb) < 0)
1817 for (i = 0, mp = m ; i < num_migrate; i++, mp++) {
1818 if (copy_to_user_migrate(mp, skb) < 0)
1822 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
1829 static int xfrm_send_migrate(struct xfrm_selector *sel, u8 dir, u8 type,
1830 struct xfrm_migrate *m, int num_migrate)
1832 struct sk_buff *skb;
1835 len = RTA_SPACE(sizeof(struct xfrm_user_migrate) * num_migrate);
1836 len += NLMSG_SPACE(sizeof(struct xfrm_userpolicy_id));
1837 #ifdef CONFIG_XFRM_SUB_POLICY
1838 len += RTA_SPACE(sizeof(struct xfrm_userpolicy_type));
1840 skb = alloc_skb(len, GFP_ATOMIC);
1845 if (build_migrate(skb, m, num_migrate, sel, dir, type) < 0)
1848 NETLINK_CB(skb).dst_group = XFRMNLGRP_MIGRATE;
1849 return netlink_broadcast(xfrm_nl, skb, 0, XFRMNLGRP_MIGRATE,
1853 static int xfrm_send_migrate(struct xfrm_selector *sel, u8 dir, u8 type,
1854 struct xfrm_migrate *m, int num_migrate)
1856 return -ENOPROTOOPT;
1860 #define XMSGSIZE(type) NLMSG_LENGTH(sizeof(struct type))
1862 static const int xfrm_msg_min[XFRM_NR_MSGTYPES] = {
1863 [XFRM_MSG_NEWSA - XFRM_MSG_BASE] = XMSGSIZE(xfrm_usersa_info),
1864 [XFRM_MSG_DELSA - XFRM_MSG_BASE] = XMSGSIZE(xfrm_usersa_id),
1865 [XFRM_MSG_GETSA - XFRM_MSG_BASE] = XMSGSIZE(xfrm_usersa_id),
1866 [XFRM_MSG_NEWPOLICY - XFRM_MSG_BASE] = XMSGSIZE(xfrm_userpolicy_info),
1867 [XFRM_MSG_DELPOLICY - XFRM_MSG_BASE] = XMSGSIZE(xfrm_userpolicy_id),
1868 [XFRM_MSG_GETPOLICY - XFRM_MSG_BASE] = XMSGSIZE(xfrm_userpolicy_id),
1869 [XFRM_MSG_ALLOCSPI - XFRM_MSG_BASE] = XMSGSIZE(xfrm_userspi_info),
1870 [XFRM_MSG_ACQUIRE - XFRM_MSG_BASE] = XMSGSIZE(xfrm_user_acquire),
1871 [XFRM_MSG_EXPIRE - XFRM_MSG_BASE] = XMSGSIZE(xfrm_user_expire),
1872 [XFRM_MSG_UPDPOLICY - XFRM_MSG_BASE] = XMSGSIZE(xfrm_userpolicy_info),
1873 [XFRM_MSG_UPDSA - XFRM_MSG_BASE] = XMSGSIZE(xfrm_usersa_info),
1874 [XFRM_MSG_POLEXPIRE - XFRM_MSG_BASE] = XMSGSIZE(xfrm_user_polexpire),
1875 [XFRM_MSG_FLUSHSA - XFRM_MSG_BASE] = XMSGSIZE(xfrm_usersa_flush),
1876 [XFRM_MSG_FLUSHPOLICY - XFRM_MSG_BASE] = NLMSG_LENGTH(0),
1877 [XFRM_MSG_NEWAE - XFRM_MSG_BASE] = XMSGSIZE(xfrm_aevent_id),
1878 [XFRM_MSG_GETAE - XFRM_MSG_BASE] = XMSGSIZE(xfrm_aevent_id),
1879 [XFRM_MSG_REPORT - XFRM_MSG_BASE] = XMSGSIZE(xfrm_user_report),
1880 [XFRM_MSG_MIGRATE - XFRM_MSG_BASE] = XMSGSIZE(xfrm_userpolicy_id),
1881 [XFRM_MSG_GETSADINFO - XFRM_MSG_BASE] = NLMSG_LENGTH(sizeof(u32)),
1886 static struct xfrm_link {
1887 int (*doit)(struct sk_buff *, struct nlmsghdr *, struct rtattr **);
1888 int (*dump)(struct sk_buff *, struct netlink_callback *);
1889 } xfrm_dispatch[XFRM_NR_MSGTYPES] = {
1890 [XFRM_MSG_NEWSA - XFRM_MSG_BASE] = { .doit = xfrm_add_sa },
1891 [XFRM_MSG_DELSA - XFRM_MSG_BASE] = { .doit = xfrm_del_sa },
1892 [XFRM_MSG_GETSA - XFRM_MSG_BASE] = { .doit = xfrm_get_sa,
1893 .dump = xfrm_dump_sa },
1894 [XFRM_MSG_NEWPOLICY - XFRM_MSG_BASE] = { .doit = xfrm_add_policy },
1895 [XFRM_MSG_DELPOLICY - XFRM_MSG_BASE] = { .doit = xfrm_get_policy },
1896 [XFRM_MSG_GETPOLICY - XFRM_MSG_BASE] = { .doit = xfrm_get_policy,
1897 .dump = xfrm_dump_policy },
1898 [XFRM_MSG_ALLOCSPI - XFRM_MSG_BASE] = { .doit = xfrm_alloc_userspi },
1899 [XFRM_MSG_ACQUIRE - XFRM_MSG_BASE] = { .doit = xfrm_add_acquire },
1900 [XFRM_MSG_EXPIRE - XFRM_MSG_BASE] = { .doit = xfrm_add_sa_expire },
1901 [XFRM_MSG_UPDPOLICY - XFRM_MSG_BASE] = { .doit = xfrm_add_policy },
1902 [XFRM_MSG_UPDSA - XFRM_MSG_BASE] = { .doit = xfrm_add_sa },
1903 [XFRM_MSG_POLEXPIRE - XFRM_MSG_BASE] = { .doit = xfrm_add_pol_expire},
1904 [XFRM_MSG_FLUSHSA - XFRM_MSG_BASE] = { .doit = xfrm_flush_sa },
1905 [XFRM_MSG_FLUSHPOLICY - XFRM_MSG_BASE] = { .doit = xfrm_flush_policy },
1906 [XFRM_MSG_NEWAE - XFRM_MSG_BASE] = { .doit = xfrm_new_ae },
1907 [XFRM_MSG_GETAE - XFRM_MSG_BASE] = { .doit = xfrm_get_ae },
1908 [XFRM_MSG_MIGRATE - XFRM_MSG_BASE] = { .doit = xfrm_do_migrate },
1909 [XFRM_MSG_GETSADINFO - XFRM_MSG_BASE] = { .doit = xfrm_get_sadinfo },
1912 static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
1914 struct rtattr *xfrma[XFRMA_MAX];
1915 struct xfrm_link *link;
1918 type = nlh->nlmsg_type;
1919 if (type > XFRM_MSG_MAX)
1922 type -= XFRM_MSG_BASE;
1923 link = &xfrm_dispatch[type];
1925 /* All operations require privileges, even GET */
1926 if (security_netlink_recv(skb, CAP_NET_ADMIN))
1929 if ((type == (XFRM_MSG_GETSA - XFRM_MSG_BASE) ||
1930 type == (XFRM_MSG_GETPOLICY - XFRM_MSG_BASE)) &&
1931 (nlh->nlmsg_flags & NLM_F_DUMP)) {
1932 if (link->dump == NULL)
1935 return netlink_dump_start(xfrm_nl, skb, nlh, link->dump, NULL);
1938 memset(xfrma, 0, sizeof(xfrma));
1940 if (nlh->nlmsg_len < (min_len = xfrm_msg_min[type]))
1943 if (nlh->nlmsg_len > min_len) {
1944 int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len);
1945 struct rtattr *attr = (void *) nlh + NLMSG_ALIGN(min_len);
1947 while (RTA_OK(attr, attrlen)) {
1948 unsigned short flavor = attr->rta_type;
1950 if (flavor > XFRMA_MAX)
1952 xfrma[flavor - 1] = attr;
1954 attr = RTA_NEXT(attr, attrlen);
1958 if (link->doit == NULL)
1961 return link->doit(skb, nlh, xfrma);
1964 static void xfrm_netlink_rcv(struct sock *sk, int len)
1966 unsigned int qlen = 0;
1969 mutex_lock(&xfrm_cfg_mutex);
1970 netlink_run_queue(sk, &qlen, &xfrm_user_rcv_msg);
1971 mutex_unlock(&xfrm_cfg_mutex);
1976 static int build_expire(struct sk_buff *skb, struct xfrm_state *x, struct km_event *c)
1978 struct xfrm_user_expire *ue;
1979 struct nlmsghdr *nlh;
1980 unsigned char *b = skb_tail_pointer(skb);
1982 nlh = NLMSG_PUT(skb, c->pid, 0, XFRM_MSG_EXPIRE,
1984 ue = NLMSG_DATA(nlh);
1985 nlh->nlmsg_flags = 0;
1987 copy_to_user_state(x, &ue->state);
1988 ue->hard = (c->data.hard != 0) ? 1 : 0;
1990 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
1998 static int xfrm_exp_state_notify(struct xfrm_state *x, struct km_event *c)
2000 struct sk_buff *skb;
2001 int len = NLMSG_LENGTH(sizeof(struct xfrm_user_expire));
2003 skb = alloc_skb(len, GFP_ATOMIC);
2007 if (build_expire(skb, x, c) < 0)
2010 NETLINK_CB(skb).dst_group = XFRMNLGRP_EXPIRE;
2011 return netlink_broadcast(xfrm_nl, skb, 0, XFRMNLGRP_EXPIRE, GFP_ATOMIC);
2014 static int xfrm_aevent_state_notify(struct xfrm_state *x, struct km_event *c)
2016 struct sk_buff *skb;
2017 int len = NLMSG_LENGTH(sizeof(struct xfrm_aevent_id));
2019 len += RTA_SPACE(sizeof(struct xfrm_replay_state));
2020 len += RTA_SPACE(sizeof(struct xfrm_lifetime_cur));
2021 skb = alloc_skb(len, GFP_ATOMIC);
2025 if (build_aevent(skb, x, c) < 0)
2028 NETLINK_CB(skb).dst_group = XFRMNLGRP_AEVENTS;
2029 return netlink_broadcast(xfrm_nl, skb, 0, XFRMNLGRP_AEVENTS, GFP_ATOMIC);
2032 static int xfrm_notify_sa_flush(struct km_event *c)
2034 struct xfrm_usersa_flush *p;
2035 struct nlmsghdr *nlh;
2036 struct sk_buff *skb;
2038 int len = NLMSG_LENGTH(sizeof(struct xfrm_usersa_flush));
2040 skb = alloc_skb(len, GFP_ATOMIC);
2045 nlh = NLMSG_PUT(skb, c->pid, c->seq,
2046 XFRM_MSG_FLUSHSA, sizeof(*p));
2047 nlh->nlmsg_flags = 0;
2049 p = NLMSG_DATA(nlh);
2050 p->proto = c->data.proto;
2052 nlh->nlmsg_len = skb->tail - b;
2054 NETLINK_CB(skb).dst_group = XFRMNLGRP_SA;
2055 return netlink_broadcast(xfrm_nl, skb, 0, XFRMNLGRP_SA, GFP_ATOMIC);
2062 static inline int xfrm_sa_len(struct xfrm_state *x)
2066 l += RTA_SPACE(sizeof(*x->aalg) + (x->aalg->alg_key_len+7)/8);
2068 l += RTA_SPACE(sizeof(*x->ealg) + (x->ealg->alg_key_len+7)/8);
2070 l += RTA_SPACE(sizeof(*x->calg));
2072 l += RTA_SPACE(sizeof(*x->encap));
2077 static int xfrm_notify_sa(struct xfrm_state *x, struct km_event *c)
2079 struct xfrm_usersa_info *p;
2080 struct xfrm_usersa_id *id;
2081 struct nlmsghdr *nlh;
2082 struct sk_buff *skb;
2084 int len = xfrm_sa_len(x);
2087 headlen = sizeof(*p);
2088 if (c->event == XFRM_MSG_DELSA) {
2089 len += RTA_SPACE(headlen);
2090 headlen = sizeof(*id);
2092 len += NLMSG_SPACE(headlen);
2094 skb = alloc_skb(len, GFP_ATOMIC);
2099 nlh = NLMSG_PUT(skb, c->pid, c->seq, c->event, headlen);
2100 nlh->nlmsg_flags = 0;
2102 p = NLMSG_DATA(nlh);
2103 if (c->event == XFRM_MSG_DELSA) {
2104 id = NLMSG_DATA(nlh);
2105 memcpy(&id->daddr, &x->id.daddr, sizeof(id->daddr));
2106 id->spi = x->id.spi;
2107 id->family = x->props.family;
2108 id->proto = x->id.proto;
2110 p = RTA_DATA(__RTA_PUT(skb, XFRMA_SA, sizeof(*p)));
2113 copy_to_user_state(x, p);
2116 RTA_PUT(skb, XFRMA_ALG_AUTH,
2117 sizeof(*(x->aalg))+(x->aalg->alg_key_len+7)/8, x->aalg);
2119 RTA_PUT(skb, XFRMA_ALG_CRYPT,
2120 sizeof(*(x->ealg))+(x->ealg->alg_key_len+7)/8, x->ealg);
2122 RTA_PUT(skb, XFRMA_ALG_COMP, sizeof(*(x->calg)), x->calg);
2125 RTA_PUT(skb, XFRMA_ENCAP, sizeof(*x->encap), x->encap);
2127 nlh->nlmsg_len = skb->tail - b;
2129 NETLINK_CB(skb).dst_group = XFRMNLGRP_SA;
2130 return netlink_broadcast(xfrm_nl, skb, 0, XFRMNLGRP_SA, GFP_ATOMIC);
2138 static int xfrm_send_state_notify(struct xfrm_state *x, struct km_event *c)
2142 case XFRM_MSG_EXPIRE:
2143 return xfrm_exp_state_notify(x, c);
2144 case XFRM_MSG_NEWAE:
2145 return xfrm_aevent_state_notify(x, c);
2146 case XFRM_MSG_DELSA:
2147 case XFRM_MSG_UPDSA:
2148 case XFRM_MSG_NEWSA:
2149 return xfrm_notify_sa(x, c);
2150 case XFRM_MSG_FLUSHSA:
2151 return xfrm_notify_sa_flush(c);
2153 printk("xfrm_user: Unknown SA event %d\n", c->event);
2161 static int build_acquire(struct sk_buff *skb, struct xfrm_state *x,
2162 struct xfrm_tmpl *xt, struct xfrm_policy *xp,
2165 struct xfrm_user_acquire *ua;
2166 struct nlmsghdr *nlh;
2167 unsigned char *b = skb_tail_pointer(skb);
2168 __u32 seq = xfrm_get_acqseq();
2170 nlh = NLMSG_PUT(skb, 0, 0, XFRM_MSG_ACQUIRE,
2172 ua = NLMSG_DATA(nlh);
2173 nlh->nlmsg_flags = 0;
2175 memcpy(&ua->id, &x->id, sizeof(ua->id));
2176 memcpy(&ua->saddr, &x->props.saddr, sizeof(ua->saddr));
2177 memcpy(&ua->sel, &x->sel, sizeof(ua->sel));
2178 copy_to_user_policy(xp, &ua->policy, dir);
2179 ua->aalgos = xt->aalgos;
2180 ua->ealgos = xt->ealgos;
2181 ua->calgos = xt->calgos;
2182 ua->seq = x->km.seq = seq;
2184 if (copy_to_user_tmpl(xp, skb) < 0)
2186 if (copy_to_user_state_sec_ctx(x, skb))
2188 if (copy_to_user_policy_type(xp->type, skb) < 0)
2191 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
2199 static int xfrm_send_acquire(struct xfrm_state *x, struct xfrm_tmpl *xt,
2200 struct xfrm_policy *xp, int dir)
2202 struct sk_buff *skb;
2205 len = RTA_SPACE(sizeof(struct xfrm_user_tmpl) * xp->xfrm_nr);
2206 len += NLMSG_SPACE(sizeof(struct xfrm_user_acquire));
2207 len += RTA_SPACE(xfrm_user_sec_ctx_size(x->security));
2208 #ifdef CONFIG_XFRM_SUB_POLICY
2209 len += RTA_SPACE(sizeof(struct xfrm_userpolicy_type));
2211 skb = alloc_skb(len, GFP_ATOMIC);
2215 if (build_acquire(skb, x, xt, xp, dir) < 0)
2218 NETLINK_CB(skb).dst_group = XFRMNLGRP_ACQUIRE;
2219 return netlink_broadcast(xfrm_nl, skb, 0, XFRMNLGRP_ACQUIRE, GFP_ATOMIC);
2222 /* User gives us xfrm_user_policy_info followed by an array of 0
2223 * or more templates.
2225 static struct xfrm_policy *xfrm_compile_policy(struct sock *sk, int opt,
2226 u8 *data, int len, int *dir)
2228 struct xfrm_userpolicy_info *p = (struct xfrm_userpolicy_info *)data;
2229 struct xfrm_user_tmpl *ut = (struct xfrm_user_tmpl *) (p + 1);
2230 struct xfrm_policy *xp;
2233 switch (sk->sk_family) {
2235 if (opt != IP_XFRM_POLICY) {
2240 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
2242 if (opt != IPV6_XFRM_POLICY) {
2255 if (len < sizeof(*p) ||
2256 verify_newpolicy_info(p))
2259 nr = ((len - sizeof(*p)) / sizeof(*ut));
2260 if (validate_tmpl(nr, ut, p->sel.family))
2263 if (p->dir > XFRM_POLICY_OUT)
2266 xp = xfrm_policy_alloc(GFP_KERNEL);
2272 copy_from_user_policy(xp, p);
2273 xp->type = XFRM_POLICY_TYPE_MAIN;
2274 copy_templates(xp, ut, nr);
2281 static int build_polexpire(struct sk_buff *skb, struct xfrm_policy *xp,
2282 int dir, struct km_event *c)
2284 struct xfrm_user_polexpire *upe;
2285 struct nlmsghdr *nlh;
2286 int hard = c->data.hard;
2287 unsigned char *b = skb_tail_pointer(skb);
2289 nlh = NLMSG_PUT(skb, c->pid, 0, XFRM_MSG_POLEXPIRE, sizeof(*upe));
2290 upe = NLMSG_DATA(nlh);
2291 nlh->nlmsg_flags = 0;
2293 copy_to_user_policy(xp, &upe->pol, dir);
2294 if (copy_to_user_tmpl(xp, skb) < 0)
2296 if (copy_to_user_sec_ctx(xp, skb))
2298 if (copy_to_user_policy_type(xp->type, skb) < 0)
2302 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
2310 static int xfrm_exp_policy_notify(struct xfrm_policy *xp, int dir, struct km_event *c)
2312 struct sk_buff *skb;
2315 len = RTA_SPACE(sizeof(struct xfrm_user_tmpl) * xp->xfrm_nr);
2316 len += NLMSG_SPACE(sizeof(struct xfrm_user_polexpire));
2317 len += RTA_SPACE(xfrm_user_sec_ctx_size(xp->security));
2318 #ifdef CONFIG_XFRM_SUB_POLICY
2319 len += RTA_SPACE(sizeof(struct xfrm_userpolicy_type));
2321 skb = alloc_skb(len, GFP_ATOMIC);
2325 if (build_polexpire(skb, xp, dir, c) < 0)
2328 NETLINK_CB(skb).dst_group = XFRMNLGRP_EXPIRE;
2329 return netlink_broadcast(xfrm_nl, skb, 0, XFRMNLGRP_EXPIRE, GFP_ATOMIC);
2332 static int xfrm_notify_policy(struct xfrm_policy *xp, int dir, struct km_event *c)
2334 struct xfrm_userpolicy_info *p;
2335 struct xfrm_userpolicy_id *id;
2336 struct nlmsghdr *nlh;
2337 struct sk_buff *skb;
2339 int len = RTA_SPACE(sizeof(struct xfrm_user_tmpl) * xp->xfrm_nr);
2342 headlen = sizeof(*p);
2343 if (c->event == XFRM_MSG_DELPOLICY) {
2344 len += RTA_SPACE(headlen);
2345 headlen = sizeof(*id);
2347 #ifdef CONFIG_XFRM_SUB_POLICY
2348 len += RTA_SPACE(sizeof(struct xfrm_userpolicy_type));
2350 len += NLMSG_SPACE(headlen);
2352 skb = alloc_skb(len, GFP_ATOMIC);
2357 nlh = NLMSG_PUT(skb, c->pid, c->seq, c->event, headlen);
2359 p = NLMSG_DATA(nlh);
2360 if (c->event == XFRM_MSG_DELPOLICY) {
2361 id = NLMSG_DATA(nlh);
2362 memset(id, 0, sizeof(*id));
2365 id->index = xp->index;
2367 memcpy(&id->sel, &xp->selector, sizeof(id->sel));
2369 p = RTA_DATA(__RTA_PUT(skb, XFRMA_POLICY, sizeof(*p)));
2372 nlh->nlmsg_flags = 0;
2374 copy_to_user_policy(xp, p, dir);
2375 if (copy_to_user_tmpl(xp, skb) < 0)
2377 if (copy_to_user_policy_type(xp->type, skb) < 0)
2380 nlh->nlmsg_len = skb->tail - b;
2382 NETLINK_CB(skb).dst_group = XFRMNLGRP_POLICY;
2383 return netlink_broadcast(xfrm_nl, skb, 0, XFRMNLGRP_POLICY, GFP_ATOMIC);
2391 static int xfrm_notify_policy_flush(struct km_event *c)
2393 struct nlmsghdr *nlh;
2394 struct sk_buff *skb;
2397 #ifdef CONFIG_XFRM_SUB_POLICY
2398 len += RTA_SPACE(sizeof(struct xfrm_userpolicy_type));
2400 len += NLMSG_LENGTH(0);
2402 skb = alloc_skb(len, GFP_ATOMIC);
2408 nlh = NLMSG_PUT(skb, c->pid, c->seq, XFRM_MSG_FLUSHPOLICY, 0);
2409 nlh->nlmsg_flags = 0;
2410 if (copy_to_user_policy_type(c->data.type, skb) < 0)
2413 nlh->nlmsg_len = skb->tail - b;
2415 NETLINK_CB(skb).dst_group = XFRMNLGRP_POLICY;
2416 return netlink_broadcast(xfrm_nl, skb, 0, XFRMNLGRP_POLICY, GFP_ATOMIC);
2423 static int xfrm_send_policy_notify(struct xfrm_policy *xp, int dir, struct km_event *c)
2427 case XFRM_MSG_NEWPOLICY:
2428 case XFRM_MSG_UPDPOLICY:
2429 case XFRM_MSG_DELPOLICY:
2430 return xfrm_notify_policy(xp, dir, c);
2431 case XFRM_MSG_FLUSHPOLICY:
2432 return xfrm_notify_policy_flush(c);
2433 case XFRM_MSG_POLEXPIRE:
2434 return xfrm_exp_policy_notify(xp, dir, c);
2436 printk("xfrm_user: Unknown Policy event %d\n", c->event);
2443 static int build_report(struct sk_buff *skb, u8 proto,
2444 struct xfrm_selector *sel, xfrm_address_t *addr)
2446 struct xfrm_user_report *ur;
2447 struct nlmsghdr *nlh;
2448 unsigned char *b = skb_tail_pointer(skb);
2450 nlh = NLMSG_PUT(skb, 0, 0, XFRM_MSG_REPORT, sizeof(*ur));
2451 ur = NLMSG_DATA(nlh);
2452 nlh->nlmsg_flags = 0;
2455 memcpy(&ur->sel, sel, sizeof(ur->sel));
2458 RTA_PUT(skb, XFRMA_COADDR, sizeof(*addr), addr);
2460 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
2469 static int xfrm_send_report(u8 proto, struct xfrm_selector *sel,
2470 xfrm_address_t *addr)
2472 struct sk_buff *skb;
2475 len = NLMSG_ALIGN(NLMSG_LENGTH(sizeof(struct xfrm_user_report)));
2476 skb = alloc_skb(len, GFP_ATOMIC);
2480 if (build_report(skb, proto, sel, addr) < 0)
2483 NETLINK_CB(skb).dst_group = XFRMNLGRP_REPORT;
2484 return netlink_broadcast(xfrm_nl, skb, 0, XFRMNLGRP_REPORT, GFP_ATOMIC);
2487 static struct xfrm_mgr netlink_mgr = {
2489 .notify = xfrm_send_state_notify,
2490 .acquire = xfrm_send_acquire,
2491 .compile_policy = xfrm_compile_policy,
2492 .notify_policy = xfrm_send_policy_notify,
2493 .report = xfrm_send_report,
2494 .migrate = xfrm_send_migrate,
2497 static int __init xfrm_user_init(void)
2501 printk(KERN_INFO "Initializing XFRM netlink socket\n");
2503 nlsk = netlink_kernel_create(NETLINK_XFRM, XFRMNLGRP_MAX,
2504 xfrm_netlink_rcv, NULL, THIS_MODULE);
2507 rcu_assign_pointer(xfrm_nl, nlsk);
2509 xfrm_register_km(&netlink_mgr);
2514 static void __exit xfrm_user_exit(void)
2516 struct sock *nlsk = xfrm_nl;
2518 xfrm_unregister_km(&netlink_mgr);
2519 rcu_assign_pointer(xfrm_nl, NULL);
2521 sock_release(nlsk->sk_socket);
2524 module_init(xfrm_user_init);
2525 module_exit(xfrm_user_exit);
2526 MODULE_LICENSE("GPL");
2527 MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_XFRM);