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/pfkeyv2.h>
23 #include <linux/ipsec.h>
24 #include <linux/init.h>
25 #include <linux/security.h>
28 #include <net/netlink.h>
30 #include <asm/uaccess.h>
31 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
32 #include <linux/in6.h>
35 static inline int aead_len(struct xfrm_algo_aead
*alg
)
37 return sizeof(*alg
) + ((alg
->alg_key_len
+ 7) / 8);
40 static int verify_one_alg(struct nlattr
**attrs
, enum xfrm_attr_type_t type
)
42 struct nlattr
*rt
= attrs
[type
];
43 struct xfrm_algo
*algp
;
49 if (nla_len(rt
) < xfrm_alg_len(algp
))
62 algp
->alg_name
[CRYPTO_MAX_ALG_NAME
- 1] = '\0';
66 static int verify_auth_trunc(struct nlattr
**attrs
)
68 struct nlattr
*rt
= attrs
[XFRMA_ALG_AUTH_TRUNC
];
69 struct xfrm_algo_auth
*algp
;
75 if (nla_len(rt
) < xfrm_alg_auth_len(algp
))
78 algp
->alg_name
[CRYPTO_MAX_ALG_NAME
- 1] = '\0';
82 static int verify_aead(struct nlattr
**attrs
)
84 struct nlattr
*rt
= attrs
[XFRMA_ALG_AEAD
];
85 struct xfrm_algo_aead
*algp
;
91 if (nla_len(rt
) < aead_len(algp
))
94 algp
->alg_name
[CRYPTO_MAX_ALG_NAME
- 1] = '\0';
98 static void verify_one_addr(struct nlattr
**attrs
, enum xfrm_attr_type_t type
,
99 xfrm_address_t
**addrp
)
101 struct nlattr
*rt
= attrs
[type
];
104 *addrp
= nla_data(rt
);
107 static inline int verify_sec_ctx_len(struct nlattr
**attrs
)
109 struct nlattr
*rt
= attrs
[XFRMA_SEC_CTX
];
110 struct xfrm_user_sec_ctx
*uctx
;
116 if (uctx
->len
!= (sizeof(struct xfrm_user_sec_ctx
) + uctx
->ctx_len
))
122 static inline int verify_replay(struct xfrm_usersa_info
*p
,
123 struct nlattr
**attrs
)
125 struct nlattr
*rt
= attrs
[XFRMA_REPLAY_ESN_VAL
];
130 if (p
->id
.proto
!= IPPROTO_ESP
)
133 if (p
->replay_window
!= 0)
139 static int verify_newsa_info(struct xfrm_usersa_info
*p
,
140 struct nlattr
**attrs
)
150 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
162 switch (p
->id
.proto
) {
164 if ((!attrs
[XFRMA_ALG_AUTH
] &&
165 !attrs
[XFRMA_ALG_AUTH_TRUNC
]) ||
166 attrs
[XFRMA_ALG_AEAD
] ||
167 attrs
[XFRMA_ALG_CRYPT
] ||
168 attrs
[XFRMA_ALG_COMP
] ||
174 if (attrs
[XFRMA_ALG_COMP
])
176 if (!attrs
[XFRMA_ALG_AUTH
] &&
177 !attrs
[XFRMA_ALG_AUTH_TRUNC
] &&
178 !attrs
[XFRMA_ALG_CRYPT
] &&
179 !attrs
[XFRMA_ALG_AEAD
])
181 if ((attrs
[XFRMA_ALG_AUTH
] ||
182 attrs
[XFRMA_ALG_AUTH_TRUNC
] ||
183 attrs
[XFRMA_ALG_CRYPT
]) &&
184 attrs
[XFRMA_ALG_AEAD
])
186 if (attrs
[XFRMA_TFCPAD
] &&
187 p
->mode
!= XFRM_MODE_TUNNEL
)
192 if (!attrs
[XFRMA_ALG_COMP
] ||
193 attrs
[XFRMA_ALG_AEAD
] ||
194 attrs
[XFRMA_ALG_AUTH
] ||
195 attrs
[XFRMA_ALG_AUTH_TRUNC
] ||
196 attrs
[XFRMA_ALG_CRYPT
] ||
201 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
202 case IPPROTO_DSTOPTS
:
203 case IPPROTO_ROUTING
:
204 if (attrs
[XFRMA_ALG_COMP
] ||
205 attrs
[XFRMA_ALG_AUTH
] ||
206 attrs
[XFRMA_ALG_AUTH_TRUNC
] ||
207 attrs
[XFRMA_ALG_AEAD
] ||
208 attrs
[XFRMA_ALG_CRYPT
] ||
209 attrs
[XFRMA_ENCAP
] ||
210 attrs
[XFRMA_SEC_CTX
] ||
211 attrs
[XFRMA_TFCPAD
] ||
212 !attrs
[XFRMA_COADDR
])
221 if ((err
= verify_aead(attrs
)))
223 if ((err
= verify_auth_trunc(attrs
)))
225 if ((err
= verify_one_alg(attrs
, XFRMA_ALG_AUTH
)))
227 if ((err
= verify_one_alg(attrs
, XFRMA_ALG_CRYPT
)))
229 if ((err
= verify_one_alg(attrs
, XFRMA_ALG_COMP
)))
231 if ((err
= verify_sec_ctx_len(attrs
)))
233 if ((err
= verify_replay(p
, attrs
)))
238 case XFRM_MODE_TRANSPORT
:
239 case XFRM_MODE_TUNNEL
:
240 case XFRM_MODE_ROUTEOPTIMIZATION
:
254 static int attach_one_algo(struct xfrm_algo
**algpp
, u8
*props
,
255 struct xfrm_algo_desc
*(*get_byname
)(const char *, int),
258 struct xfrm_algo
*p
, *ualg
;
259 struct xfrm_algo_desc
*algo
;
264 ualg
= nla_data(rta
);
266 algo
= get_byname(ualg
->alg_name
, 1);
269 *props
= algo
->desc
.sadb_alg_id
;
271 p
= kmemdup(ualg
, xfrm_alg_len(ualg
), GFP_KERNEL
);
275 strcpy(p
->alg_name
, algo
->name
);
280 static int attach_auth(struct xfrm_algo_auth
**algpp
, u8
*props
,
283 struct xfrm_algo
*ualg
;
284 struct xfrm_algo_auth
*p
;
285 struct xfrm_algo_desc
*algo
;
290 ualg
= nla_data(rta
);
292 algo
= xfrm_aalg_get_byname(ualg
->alg_name
, 1);
295 *props
= algo
->desc
.sadb_alg_id
;
297 p
= kmalloc(sizeof(*p
) + (ualg
->alg_key_len
+ 7) / 8, GFP_KERNEL
);
301 strcpy(p
->alg_name
, algo
->name
);
302 p
->alg_key_len
= ualg
->alg_key_len
;
303 p
->alg_trunc_len
= algo
->uinfo
.auth
.icv_truncbits
;
304 memcpy(p
->alg_key
, ualg
->alg_key
, (ualg
->alg_key_len
+ 7) / 8);
310 static int attach_auth_trunc(struct xfrm_algo_auth
**algpp
, u8
*props
,
313 struct xfrm_algo_auth
*p
, *ualg
;
314 struct xfrm_algo_desc
*algo
;
319 ualg
= nla_data(rta
);
321 algo
= xfrm_aalg_get_byname(ualg
->alg_name
, 1);
324 if ((ualg
->alg_trunc_len
/ 8) > MAX_AH_AUTH_LEN
||
325 ualg
->alg_trunc_len
> algo
->uinfo
.auth
.icv_fullbits
)
327 *props
= algo
->desc
.sadb_alg_id
;
329 p
= kmemdup(ualg
, xfrm_alg_auth_len(ualg
), GFP_KERNEL
);
333 strcpy(p
->alg_name
, algo
->name
);
334 if (!p
->alg_trunc_len
)
335 p
->alg_trunc_len
= algo
->uinfo
.auth
.icv_truncbits
;
341 static int attach_aead(struct xfrm_algo_aead
**algpp
, u8
*props
,
344 struct xfrm_algo_aead
*p
, *ualg
;
345 struct xfrm_algo_desc
*algo
;
350 ualg
= nla_data(rta
);
352 algo
= xfrm_aead_get_byname(ualg
->alg_name
, ualg
->alg_icv_len
, 1);
355 *props
= algo
->desc
.sadb_alg_id
;
357 p
= kmemdup(ualg
, aead_len(ualg
), GFP_KERNEL
);
361 strcpy(p
->alg_name
, algo
->name
);
366 static inline int xfrm_replay_verify_len(struct xfrm_replay_state_esn
*replay_esn
,
369 struct xfrm_replay_state_esn
*up
;
371 if (!replay_esn
|| !rp
)
376 if (xfrm_replay_state_esn_len(replay_esn
) !=
377 xfrm_replay_state_esn_len(up
))
383 static int xfrm_alloc_replay_state_esn(struct xfrm_replay_state_esn
**replay_esn
,
384 struct xfrm_replay_state_esn
**preplay_esn
,
387 struct xfrm_replay_state_esn
*p
, *pp
, *up
;
394 p
= kmemdup(up
, xfrm_replay_state_esn_len(up
), GFP_KERNEL
);
398 pp
= kmemdup(up
, xfrm_replay_state_esn_len(up
), GFP_KERNEL
);
410 static inline int xfrm_user_sec_ctx_size(struct xfrm_sec_ctx
*xfrm_ctx
)
415 len
+= sizeof(struct xfrm_user_sec_ctx
);
416 len
+= xfrm_ctx
->ctx_len
;
421 static void copy_from_user_state(struct xfrm_state
*x
, struct xfrm_usersa_info
*p
)
423 memcpy(&x
->id
, &p
->id
, sizeof(x
->id
));
424 memcpy(&x
->sel
, &p
->sel
, sizeof(x
->sel
));
425 memcpy(&x
->lft
, &p
->lft
, sizeof(x
->lft
));
426 x
->props
.mode
= p
->mode
;
427 x
->props
.replay_window
= p
->replay_window
;
428 x
->props
.reqid
= p
->reqid
;
429 x
->props
.family
= p
->family
;
430 memcpy(&x
->props
.saddr
, &p
->saddr
, sizeof(x
->props
.saddr
));
431 x
->props
.flags
= p
->flags
;
433 if (!x
->sel
.family
&& !(p
->flags
& XFRM_STATE_AF_UNSPEC
))
434 x
->sel
.family
= p
->family
;
438 * someday when pfkey also has support, we could have the code
439 * somehow made shareable and move it to xfrm_state.c - JHS
442 static void xfrm_update_ae_params(struct xfrm_state
*x
, struct nlattr
**attrs
)
444 struct nlattr
*rp
= attrs
[XFRMA_REPLAY_VAL
];
445 struct nlattr
*re
= attrs
[XFRMA_REPLAY_ESN_VAL
];
446 struct nlattr
*lt
= attrs
[XFRMA_LTIME_VAL
];
447 struct nlattr
*et
= attrs
[XFRMA_ETIMER_THRESH
];
448 struct nlattr
*rt
= attrs
[XFRMA_REPLAY_THRESH
];
451 struct xfrm_replay_state_esn
*replay_esn
;
452 replay_esn
= nla_data(re
);
453 memcpy(x
->replay_esn
, replay_esn
,
454 xfrm_replay_state_esn_len(replay_esn
));
455 memcpy(x
->preplay_esn
, replay_esn
,
456 xfrm_replay_state_esn_len(replay_esn
));
460 struct xfrm_replay_state
*replay
;
461 replay
= nla_data(rp
);
462 memcpy(&x
->replay
, replay
, sizeof(*replay
));
463 memcpy(&x
->preplay
, replay
, sizeof(*replay
));
467 struct xfrm_lifetime_cur
*ltime
;
468 ltime
= nla_data(lt
);
469 x
->curlft
.bytes
= ltime
->bytes
;
470 x
->curlft
.packets
= ltime
->packets
;
471 x
->curlft
.add_time
= ltime
->add_time
;
472 x
->curlft
.use_time
= ltime
->use_time
;
476 x
->replay_maxage
= nla_get_u32(et
);
479 x
->replay_maxdiff
= nla_get_u32(rt
);
482 static struct xfrm_state
*xfrm_state_construct(struct net
*net
,
483 struct xfrm_usersa_info
*p
,
484 struct nlattr
**attrs
,
487 struct xfrm_state
*x
= xfrm_state_alloc(net
);
493 copy_from_user_state(x
, p
);
495 if ((err
= attach_aead(&x
->aead
, &x
->props
.ealgo
,
496 attrs
[XFRMA_ALG_AEAD
])))
498 if ((err
= attach_auth_trunc(&x
->aalg
, &x
->props
.aalgo
,
499 attrs
[XFRMA_ALG_AUTH_TRUNC
])))
501 if (!x
->props
.aalgo
) {
502 if ((err
= attach_auth(&x
->aalg
, &x
->props
.aalgo
,
503 attrs
[XFRMA_ALG_AUTH
])))
506 if ((err
= attach_one_algo(&x
->ealg
, &x
->props
.ealgo
,
507 xfrm_ealg_get_byname
,
508 attrs
[XFRMA_ALG_CRYPT
])))
510 if ((err
= attach_one_algo(&x
->calg
, &x
->props
.calgo
,
511 xfrm_calg_get_byname
,
512 attrs
[XFRMA_ALG_COMP
])))
515 if (attrs
[XFRMA_ENCAP
]) {
516 x
->encap
= kmemdup(nla_data(attrs
[XFRMA_ENCAP
]),
517 sizeof(*x
->encap
), GFP_KERNEL
);
518 if (x
->encap
== NULL
)
522 if (attrs
[XFRMA_TFCPAD
])
523 x
->tfcpad
= nla_get_u32(attrs
[XFRMA_TFCPAD
]);
525 if (attrs
[XFRMA_COADDR
]) {
526 x
->coaddr
= kmemdup(nla_data(attrs
[XFRMA_COADDR
]),
527 sizeof(*x
->coaddr
), GFP_KERNEL
);
528 if (x
->coaddr
== NULL
)
532 xfrm_mark_get(attrs
, &x
->mark
);
534 err
= __xfrm_init_state(x
, false);
538 if (attrs
[XFRMA_SEC_CTX
] &&
539 security_xfrm_state_alloc(x
, nla_data(attrs
[XFRMA_SEC_CTX
])))
542 if ((err
= xfrm_alloc_replay_state_esn(&x
->replay_esn
, &x
->preplay_esn
,
543 attrs
[XFRMA_REPLAY_ESN_VAL
])))
547 x
->replay_maxdiff
= net
->xfrm
.sysctl_aevent_rseqth
;
548 /* sysctl_xfrm_aevent_etime is in 100ms units */
549 x
->replay_maxage
= (net
->xfrm
.sysctl_aevent_etime
*HZ
)/XFRM_AE_ETH_M
;
551 if ((err
= xfrm_init_replay(x
)))
554 /* override default values from above */
555 xfrm_update_ae_params(x
, attrs
);
560 x
->km
.state
= XFRM_STATE_DEAD
;
567 static int xfrm_add_sa(struct sk_buff
*skb
, struct nlmsghdr
*nlh
,
568 struct nlattr
**attrs
)
570 struct net
*net
= sock_net(skb
->sk
);
571 struct xfrm_usersa_info
*p
= nlmsg_data(nlh
);
572 struct xfrm_state
*x
;
575 uid_t loginuid
= audit_get_loginuid(current
);
576 u32 sessionid
= audit_get_sessionid(current
);
579 err
= verify_newsa_info(p
, attrs
);
583 x
= xfrm_state_construct(net
, p
, attrs
, &err
);
588 if (nlh
->nlmsg_type
== XFRM_MSG_NEWSA
)
589 err
= xfrm_state_add(x
);
591 err
= xfrm_state_update(x
);
593 security_task_getsecid(current
, &sid
);
594 xfrm_audit_state_add(x
, err
? 0 : 1, loginuid
, sessionid
, sid
);
597 x
->km
.state
= XFRM_STATE_DEAD
;
602 c
.seq
= nlh
->nlmsg_seq
;
603 c
.pid
= nlh
->nlmsg_pid
;
604 c
.event
= nlh
->nlmsg_type
;
606 km_state_notify(x
, &c
);
612 static struct xfrm_state
*xfrm_user_state_lookup(struct net
*net
,
613 struct xfrm_usersa_id
*p
,
614 struct nlattr
**attrs
,
617 struct xfrm_state
*x
= NULL
;
620 u32 mark
= xfrm_mark_get(attrs
, &m
);
622 if (xfrm_id_proto_match(p
->proto
, IPSEC_PROTO_ANY
)) {
624 x
= xfrm_state_lookup(net
, mark
, &p
->daddr
, p
->spi
, p
->proto
, p
->family
);
626 xfrm_address_t
*saddr
= NULL
;
628 verify_one_addr(attrs
, XFRMA_SRCADDR
, &saddr
);
635 x
= xfrm_state_lookup_byaddr(net
, mark
,
637 p
->proto
, p
->family
);
646 static int xfrm_del_sa(struct sk_buff
*skb
, struct nlmsghdr
*nlh
,
647 struct nlattr
**attrs
)
649 struct net
*net
= sock_net(skb
->sk
);
650 struct xfrm_state
*x
;
653 struct xfrm_usersa_id
*p
= nlmsg_data(nlh
);
654 uid_t loginuid
= audit_get_loginuid(current
);
655 u32 sessionid
= audit_get_sessionid(current
);
658 x
= xfrm_user_state_lookup(net
, p
, attrs
, &err
);
662 if ((err
= security_xfrm_state_delete(x
)) != 0)
665 if (xfrm_state_kern(x
)) {
670 err
= xfrm_state_delete(x
);
675 c
.seq
= nlh
->nlmsg_seq
;
676 c
.pid
= nlh
->nlmsg_pid
;
677 c
.event
= nlh
->nlmsg_type
;
678 km_state_notify(x
, &c
);
681 security_task_getsecid(current
, &sid
);
682 xfrm_audit_state_delete(x
, err
? 0 : 1, loginuid
, sessionid
, sid
);
687 static void copy_to_user_state(struct xfrm_state
*x
, struct xfrm_usersa_info
*p
)
689 memcpy(&p
->id
, &x
->id
, sizeof(p
->id
));
690 memcpy(&p
->sel
, &x
->sel
, sizeof(p
->sel
));
691 memcpy(&p
->lft
, &x
->lft
, sizeof(p
->lft
));
692 memcpy(&p
->curlft
, &x
->curlft
, sizeof(p
->curlft
));
693 memcpy(&p
->stats
, &x
->stats
, sizeof(p
->stats
));
694 memcpy(&p
->saddr
, &x
->props
.saddr
, sizeof(p
->saddr
));
695 p
->mode
= x
->props
.mode
;
696 p
->replay_window
= x
->props
.replay_window
;
697 p
->reqid
= x
->props
.reqid
;
698 p
->family
= x
->props
.family
;
699 p
->flags
= x
->props
.flags
;
703 struct xfrm_dump_info
{
704 struct sk_buff
*in_skb
;
705 struct sk_buff
*out_skb
;
710 static int copy_sec_ctx(struct xfrm_sec_ctx
*s
, struct sk_buff
*skb
)
712 struct xfrm_user_sec_ctx
*uctx
;
714 int ctx_size
= sizeof(*uctx
) + s
->ctx_len
;
716 attr
= nla_reserve(skb
, XFRMA_SEC_CTX
, ctx_size
);
720 uctx
= nla_data(attr
);
721 uctx
->exttype
= XFRMA_SEC_CTX
;
722 uctx
->len
= ctx_size
;
723 uctx
->ctx_doi
= s
->ctx_doi
;
724 uctx
->ctx_alg
= s
->ctx_alg
;
725 uctx
->ctx_len
= s
->ctx_len
;
726 memcpy(uctx
+ 1, s
->ctx_str
, s
->ctx_len
);
731 static int copy_to_user_auth(struct xfrm_algo_auth
*auth
, struct sk_buff
*skb
)
733 struct xfrm_algo
*algo
;
736 nla
= nla_reserve(skb
, XFRMA_ALG_AUTH
,
737 sizeof(*algo
) + (auth
->alg_key_len
+ 7) / 8);
741 algo
= nla_data(nla
);
742 strcpy(algo
->alg_name
, auth
->alg_name
);
743 memcpy(algo
->alg_key
, auth
->alg_key
, (auth
->alg_key_len
+ 7) / 8);
744 algo
->alg_key_len
= auth
->alg_key_len
;
749 /* Don't change this without updating xfrm_sa_len! */
750 static int copy_to_user_state_extra(struct xfrm_state
*x
,
751 struct xfrm_usersa_info
*p
,
754 copy_to_user_state(x
, p
);
757 NLA_PUT(skb
, XFRMA_COADDR
, sizeof(*x
->coaddr
), x
->coaddr
);
760 NLA_PUT_U64(skb
, XFRMA_LASTUSED
, x
->lastused
);
763 NLA_PUT(skb
, XFRMA_ALG_AEAD
, aead_len(x
->aead
), x
->aead
);
765 if (copy_to_user_auth(x
->aalg
, skb
))
766 goto nla_put_failure
;
768 NLA_PUT(skb
, XFRMA_ALG_AUTH_TRUNC
,
769 xfrm_alg_auth_len(x
->aalg
), x
->aalg
);
772 NLA_PUT(skb
, XFRMA_ALG_CRYPT
, xfrm_alg_len(x
->ealg
), x
->ealg
);
774 NLA_PUT(skb
, XFRMA_ALG_COMP
, sizeof(*(x
->calg
)), x
->calg
);
777 NLA_PUT(skb
, XFRMA_ENCAP
, sizeof(*x
->encap
), x
->encap
);
780 NLA_PUT_U32(skb
, XFRMA_TFCPAD
, x
->tfcpad
);
782 if (xfrm_mark_put(skb
, &x
->mark
))
783 goto nla_put_failure
;
786 NLA_PUT(skb
, XFRMA_REPLAY_ESN_VAL
,
787 xfrm_replay_state_esn_len(x
->replay_esn
), x
->replay_esn
);
789 if (x
->security
&& copy_sec_ctx(x
->security
, skb
) < 0)
790 goto nla_put_failure
;
798 static int dump_one_state(struct xfrm_state
*x
, int count
, void *ptr
)
800 struct xfrm_dump_info
*sp
= ptr
;
801 struct sk_buff
*in_skb
= sp
->in_skb
;
802 struct sk_buff
*skb
= sp
->out_skb
;
803 struct xfrm_usersa_info
*p
;
804 struct nlmsghdr
*nlh
;
807 nlh
= nlmsg_put(skb
, NETLINK_CB(in_skb
).pid
, sp
->nlmsg_seq
,
808 XFRM_MSG_NEWSA
, sizeof(*p
), sp
->nlmsg_flags
);
814 err
= copy_to_user_state_extra(x
, p
, skb
);
816 goto nla_put_failure
;
822 nlmsg_cancel(skb
, nlh
);
826 static int xfrm_dump_sa_done(struct netlink_callback
*cb
)
828 struct xfrm_state_walk
*walk
= (struct xfrm_state_walk
*) &cb
->args
[1];
829 xfrm_state_walk_done(walk
);
833 static int xfrm_dump_sa(struct sk_buff
*skb
, struct netlink_callback
*cb
)
835 struct net
*net
= sock_net(skb
->sk
);
836 struct xfrm_state_walk
*walk
= (struct xfrm_state_walk
*) &cb
->args
[1];
837 struct xfrm_dump_info info
;
839 BUILD_BUG_ON(sizeof(struct xfrm_state_walk
) >
840 sizeof(cb
->args
) - sizeof(cb
->args
[0]));
842 info
.in_skb
= cb
->skb
;
844 info
.nlmsg_seq
= cb
->nlh
->nlmsg_seq
;
845 info
.nlmsg_flags
= NLM_F_MULTI
;
849 xfrm_state_walk_init(walk
, 0);
852 (void) xfrm_state_walk(net
, walk
, dump_one_state
, &info
);
857 static struct sk_buff
*xfrm_state_netlink(struct sk_buff
*in_skb
,
858 struct xfrm_state
*x
, u32 seq
)
860 struct xfrm_dump_info info
;
863 skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
865 return ERR_PTR(-ENOMEM
);
867 info
.in_skb
= in_skb
;
869 info
.nlmsg_seq
= seq
;
870 info
.nlmsg_flags
= 0;
872 if (dump_one_state(x
, 0, &info
)) {
880 static inline size_t xfrm_spdinfo_msgsize(void)
882 return NLMSG_ALIGN(4)
883 + nla_total_size(sizeof(struct xfrmu_spdinfo
))
884 + nla_total_size(sizeof(struct xfrmu_spdhinfo
));
887 static int build_spdinfo(struct sk_buff
*skb
, struct net
*net
,
888 u32 pid
, u32 seq
, u32 flags
)
890 struct xfrmk_spdinfo si
;
891 struct xfrmu_spdinfo spc
;
892 struct xfrmu_spdhinfo sph
;
893 struct nlmsghdr
*nlh
;
896 nlh
= nlmsg_put(skb
, pid
, seq
, XFRM_MSG_NEWSPDINFO
, sizeof(u32
), 0);
897 if (nlh
== NULL
) /* shouldnt really happen ... */
902 xfrm_spd_getinfo(net
, &si
);
903 spc
.incnt
= si
.incnt
;
904 spc
.outcnt
= si
.outcnt
;
905 spc
.fwdcnt
= si
.fwdcnt
;
906 spc
.inscnt
= si
.inscnt
;
907 spc
.outscnt
= si
.outscnt
;
908 spc
.fwdscnt
= si
.fwdscnt
;
909 sph
.spdhcnt
= si
.spdhcnt
;
910 sph
.spdhmcnt
= si
.spdhmcnt
;
912 NLA_PUT(skb
, XFRMA_SPD_INFO
, sizeof(spc
), &spc
);
913 NLA_PUT(skb
, XFRMA_SPD_HINFO
, sizeof(sph
), &sph
);
915 return nlmsg_end(skb
, nlh
);
918 nlmsg_cancel(skb
, nlh
);
922 static int xfrm_get_spdinfo(struct sk_buff
*skb
, struct nlmsghdr
*nlh
,
923 struct nlattr
**attrs
)
925 struct net
*net
= sock_net(skb
->sk
);
926 struct sk_buff
*r_skb
;
927 u32
*flags
= nlmsg_data(nlh
);
928 u32 spid
= NETLINK_CB(skb
).pid
;
929 u32 seq
= nlh
->nlmsg_seq
;
931 r_skb
= nlmsg_new(xfrm_spdinfo_msgsize(), GFP_ATOMIC
);
935 if (build_spdinfo(r_skb
, net
, spid
, seq
, *flags
) < 0)
938 return nlmsg_unicast(net
->xfrm
.nlsk
, r_skb
, spid
);
941 static inline size_t xfrm_sadinfo_msgsize(void)
943 return NLMSG_ALIGN(4)
944 + nla_total_size(sizeof(struct xfrmu_sadhinfo
))
945 + nla_total_size(4); /* XFRMA_SAD_CNT */
948 static int build_sadinfo(struct sk_buff
*skb
, struct net
*net
,
949 u32 pid
, u32 seq
, u32 flags
)
951 struct xfrmk_sadinfo si
;
952 struct xfrmu_sadhinfo sh
;
953 struct nlmsghdr
*nlh
;
956 nlh
= nlmsg_put(skb
, pid
, seq
, XFRM_MSG_NEWSADINFO
, sizeof(u32
), 0);
957 if (nlh
== NULL
) /* shouldnt really happen ... */
962 xfrm_sad_getinfo(net
, &si
);
964 sh
.sadhmcnt
= si
.sadhmcnt
;
965 sh
.sadhcnt
= si
.sadhcnt
;
967 NLA_PUT_U32(skb
, XFRMA_SAD_CNT
, si
.sadcnt
);
968 NLA_PUT(skb
, XFRMA_SAD_HINFO
, sizeof(sh
), &sh
);
970 return nlmsg_end(skb
, nlh
);
973 nlmsg_cancel(skb
, nlh
);
977 static int xfrm_get_sadinfo(struct sk_buff
*skb
, struct nlmsghdr
*nlh
,
978 struct nlattr
**attrs
)
980 struct net
*net
= sock_net(skb
->sk
);
981 struct sk_buff
*r_skb
;
982 u32
*flags
= nlmsg_data(nlh
);
983 u32 spid
= NETLINK_CB(skb
).pid
;
984 u32 seq
= nlh
->nlmsg_seq
;
986 r_skb
= nlmsg_new(xfrm_sadinfo_msgsize(), GFP_ATOMIC
);
990 if (build_sadinfo(r_skb
, net
, spid
, seq
, *flags
) < 0)
993 return nlmsg_unicast(net
->xfrm
.nlsk
, r_skb
, spid
);
996 static int xfrm_get_sa(struct sk_buff
*skb
, struct nlmsghdr
*nlh
,
997 struct nlattr
**attrs
)
999 struct net
*net
= sock_net(skb
->sk
);
1000 struct xfrm_usersa_id
*p
= nlmsg_data(nlh
);
1001 struct xfrm_state
*x
;
1002 struct sk_buff
*resp_skb
;
1005 x
= xfrm_user_state_lookup(net
, p
, attrs
, &err
);
1009 resp_skb
= xfrm_state_netlink(skb
, x
, nlh
->nlmsg_seq
);
1010 if (IS_ERR(resp_skb
)) {
1011 err
= PTR_ERR(resp_skb
);
1013 err
= nlmsg_unicast(net
->xfrm
.nlsk
, resp_skb
, NETLINK_CB(skb
).pid
);
1020 static int verify_userspi_info(struct xfrm_userspi_info
*p
)
1022 switch (p
->info
.id
.proto
) {
1028 /* IPCOMP spi is 16-bits. */
1029 if (p
->max
>= 0x10000)
1037 if (p
->min
> p
->max
)
1043 static int xfrm_alloc_userspi(struct sk_buff
*skb
, struct nlmsghdr
*nlh
,
1044 struct nlattr
**attrs
)
1046 struct net
*net
= sock_net(skb
->sk
);
1047 struct xfrm_state
*x
;
1048 struct xfrm_userspi_info
*p
;
1049 struct sk_buff
*resp_skb
;
1050 xfrm_address_t
*daddr
;
1056 p
= nlmsg_data(nlh
);
1057 err
= verify_userspi_info(p
);
1061 family
= p
->info
.family
;
1062 daddr
= &p
->info
.id
.daddr
;
1066 mark
= xfrm_mark_get(attrs
, &m
);
1068 x
= xfrm_find_acq_byseq(net
, mark
, p
->info
.seq
);
1069 if (x
&& xfrm_addr_cmp(&x
->id
.daddr
, daddr
, family
)) {
1076 x
= xfrm_find_acq(net
, &m
, p
->info
.mode
, p
->info
.reqid
,
1077 p
->info
.id
.proto
, daddr
,
1084 err
= xfrm_alloc_spi(x
, p
->min
, p
->max
);
1088 resp_skb
= xfrm_state_netlink(skb
, x
, nlh
->nlmsg_seq
);
1089 if (IS_ERR(resp_skb
)) {
1090 err
= PTR_ERR(resp_skb
);
1094 err
= nlmsg_unicast(net
->xfrm
.nlsk
, resp_skb
, NETLINK_CB(skb
).pid
);
1102 static int verify_policy_dir(u8 dir
)
1105 case XFRM_POLICY_IN
:
1106 case XFRM_POLICY_OUT
:
1107 case XFRM_POLICY_FWD
:
1117 static int verify_policy_type(u8 type
)
1120 case XFRM_POLICY_TYPE_MAIN
:
1121 #ifdef CONFIG_XFRM_SUB_POLICY
1122 case XFRM_POLICY_TYPE_SUB
:
1133 static int verify_newpolicy_info(struct xfrm_userpolicy_info
*p
)
1136 case XFRM_SHARE_ANY
:
1137 case XFRM_SHARE_SESSION
:
1138 case XFRM_SHARE_USER
:
1139 case XFRM_SHARE_UNIQUE
:
1146 switch (p
->action
) {
1147 case XFRM_POLICY_ALLOW
:
1148 case XFRM_POLICY_BLOCK
:
1155 switch (p
->sel
.family
) {
1160 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
1163 return -EAFNOSUPPORT
;
1170 return verify_policy_dir(p
->dir
);
1173 static int copy_from_user_sec_ctx(struct xfrm_policy
*pol
, struct nlattr
**attrs
)
1175 struct nlattr
*rt
= attrs
[XFRMA_SEC_CTX
];
1176 struct xfrm_user_sec_ctx
*uctx
;
1181 uctx
= nla_data(rt
);
1182 return security_xfrm_policy_alloc(&pol
->security
, uctx
);
1185 static void copy_templates(struct xfrm_policy
*xp
, struct xfrm_user_tmpl
*ut
,
1191 for (i
= 0; i
< nr
; i
++, ut
++) {
1192 struct xfrm_tmpl
*t
= &xp
->xfrm_vec
[i
];
1194 memcpy(&t
->id
, &ut
->id
, sizeof(struct xfrm_id
));
1195 memcpy(&t
->saddr
, &ut
->saddr
,
1196 sizeof(xfrm_address_t
));
1197 t
->reqid
= ut
->reqid
;
1199 t
->share
= ut
->share
;
1200 t
->optional
= ut
->optional
;
1201 t
->aalgos
= ut
->aalgos
;
1202 t
->ealgos
= ut
->ealgos
;
1203 t
->calgos
= ut
->calgos
;
1204 /* If all masks are ~0, then we allow all algorithms. */
1205 t
->allalgs
= !~(t
->aalgos
& t
->ealgos
& t
->calgos
);
1206 t
->encap_family
= ut
->family
;
1210 static int validate_tmpl(int nr
, struct xfrm_user_tmpl
*ut
, u16 family
)
1214 if (nr
> XFRM_MAX_DEPTH
)
1217 for (i
= 0; i
< nr
; i
++) {
1218 /* We never validated the ut->family value, so many
1219 * applications simply leave it at zero. The check was
1220 * never made and ut->family was ignored because all
1221 * templates could be assumed to have the same family as
1222 * the policy itself. Now that we will have ipv4-in-ipv6
1223 * and ipv6-in-ipv4 tunnels, this is no longer true.
1226 ut
[i
].family
= family
;
1228 switch (ut
[i
].family
) {
1231 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
1243 static int copy_from_user_tmpl(struct xfrm_policy
*pol
, struct nlattr
**attrs
)
1245 struct nlattr
*rt
= attrs
[XFRMA_TMPL
];
1250 struct xfrm_user_tmpl
*utmpl
= nla_data(rt
);
1251 int nr
= nla_len(rt
) / sizeof(*utmpl
);
1254 err
= validate_tmpl(nr
, utmpl
, pol
->family
);
1258 copy_templates(pol
, utmpl
, nr
);
1263 static int copy_from_user_policy_type(u8
*tp
, struct nlattr
**attrs
)
1265 struct nlattr
*rt
= attrs
[XFRMA_POLICY_TYPE
];
1266 struct xfrm_userpolicy_type
*upt
;
1267 u8 type
= XFRM_POLICY_TYPE_MAIN
;
1275 err
= verify_policy_type(type
);
1283 static void copy_from_user_policy(struct xfrm_policy
*xp
, struct xfrm_userpolicy_info
*p
)
1285 xp
->priority
= p
->priority
;
1286 xp
->index
= p
->index
;
1287 memcpy(&xp
->selector
, &p
->sel
, sizeof(xp
->selector
));
1288 memcpy(&xp
->lft
, &p
->lft
, sizeof(xp
->lft
));
1289 xp
->action
= p
->action
;
1290 xp
->flags
= p
->flags
;
1291 xp
->family
= p
->sel
.family
;
1292 /* XXX xp->share = p->share; */
1295 static void copy_to_user_policy(struct xfrm_policy
*xp
, struct xfrm_userpolicy_info
*p
, int dir
)
1297 memcpy(&p
->sel
, &xp
->selector
, sizeof(p
->sel
));
1298 memcpy(&p
->lft
, &xp
->lft
, sizeof(p
->lft
));
1299 memcpy(&p
->curlft
, &xp
->curlft
, sizeof(p
->curlft
));
1300 p
->priority
= xp
->priority
;
1301 p
->index
= xp
->index
;
1302 p
->sel
.family
= xp
->family
;
1304 p
->action
= xp
->action
;
1305 p
->flags
= xp
->flags
;
1306 p
->share
= XFRM_SHARE_ANY
; /* XXX xp->share */
1309 static struct xfrm_policy
*xfrm_policy_construct(struct net
*net
, struct xfrm_userpolicy_info
*p
, struct nlattr
**attrs
, int *errp
)
1311 struct xfrm_policy
*xp
= xfrm_policy_alloc(net
, GFP_KERNEL
);
1319 copy_from_user_policy(xp
, p
);
1321 err
= copy_from_user_policy_type(&xp
->type
, attrs
);
1325 if (!(err
= copy_from_user_tmpl(xp
, attrs
)))
1326 err
= copy_from_user_sec_ctx(xp
, attrs
);
1330 xfrm_mark_get(attrs
, &xp
->mark
);
1336 xfrm_policy_destroy(xp
);
1340 static int xfrm_add_policy(struct sk_buff
*skb
, struct nlmsghdr
*nlh
,
1341 struct nlattr
**attrs
)
1343 struct net
*net
= sock_net(skb
->sk
);
1344 struct xfrm_userpolicy_info
*p
= nlmsg_data(nlh
);
1345 struct xfrm_policy
*xp
;
1349 uid_t loginuid
= audit_get_loginuid(current
);
1350 u32 sessionid
= audit_get_sessionid(current
);
1353 err
= verify_newpolicy_info(p
);
1356 err
= verify_sec_ctx_len(attrs
);
1360 xp
= xfrm_policy_construct(net
, p
, attrs
, &err
);
1364 /* shouldnt excl be based on nlh flags??
1365 * Aha! this is anti-netlink really i.e more pfkey derived
1366 * in netlink excl is a flag and you wouldnt need
1367 * a type XFRM_MSG_UPDPOLICY - JHS */
1368 excl
= nlh
->nlmsg_type
== XFRM_MSG_NEWPOLICY
;
1369 err
= xfrm_policy_insert(p
->dir
, xp
, excl
);
1370 security_task_getsecid(current
, &sid
);
1371 xfrm_audit_policy_add(xp
, err
? 0 : 1, loginuid
, sessionid
, sid
);
1374 security_xfrm_policy_free(xp
->security
);
1379 c
.event
= nlh
->nlmsg_type
;
1380 c
.seq
= nlh
->nlmsg_seq
;
1381 c
.pid
= nlh
->nlmsg_pid
;
1382 km_policy_notify(xp
, p
->dir
, &c
);
1389 static int copy_to_user_tmpl(struct xfrm_policy
*xp
, struct sk_buff
*skb
)
1391 struct xfrm_user_tmpl vec
[XFRM_MAX_DEPTH
];
1394 if (xp
->xfrm_nr
== 0)
1397 for (i
= 0; i
< xp
->xfrm_nr
; i
++) {
1398 struct xfrm_user_tmpl
*up
= &vec
[i
];
1399 struct xfrm_tmpl
*kp
= &xp
->xfrm_vec
[i
];
1401 memcpy(&up
->id
, &kp
->id
, sizeof(up
->id
));
1402 up
->family
= kp
->encap_family
;
1403 memcpy(&up
->saddr
, &kp
->saddr
, sizeof(up
->saddr
));
1404 up
->reqid
= kp
->reqid
;
1405 up
->mode
= kp
->mode
;
1406 up
->share
= kp
->share
;
1407 up
->optional
= kp
->optional
;
1408 up
->aalgos
= kp
->aalgos
;
1409 up
->ealgos
= kp
->ealgos
;
1410 up
->calgos
= kp
->calgos
;
1413 return nla_put(skb
, XFRMA_TMPL
,
1414 sizeof(struct xfrm_user_tmpl
) * xp
->xfrm_nr
, vec
);
1417 static inline int copy_to_user_state_sec_ctx(struct xfrm_state
*x
, struct sk_buff
*skb
)
1420 return copy_sec_ctx(x
->security
, skb
);
1425 static inline int copy_to_user_sec_ctx(struct xfrm_policy
*xp
, struct sk_buff
*skb
)
1428 return copy_sec_ctx(xp
->security
, skb
);
1432 static inline size_t userpolicy_type_attrsize(void)
1434 #ifdef CONFIG_XFRM_SUB_POLICY
1435 return nla_total_size(sizeof(struct xfrm_userpolicy_type
));
1441 #ifdef CONFIG_XFRM_SUB_POLICY
1442 static int copy_to_user_policy_type(u8 type
, struct sk_buff
*skb
)
1444 struct xfrm_userpolicy_type upt
= {
1448 return nla_put(skb
, XFRMA_POLICY_TYPE
, sizeof(upt
), &upt
);
1452 static inline int copy_to_user_policy_type(u8 type
, struct sk_buff
*skb
)
1458 static int dump_one_policy(struct xfrm_policy
*xp
, int dir
, int count
, void *ptr
)
1460 struct xfrm_dump_info
*sp
= ptr
;
1461 struct xfrm_userpolicy_info
*p
;
1462 struct sk_buff
*in_skb
= sp
->in_skb
;
1463 struct sk_buff
*skb
= sp
->out_skb
;
1464 struct nlmsghdr
*nlh
;
1466 nlh
= nlmsg_put(skb
, NETLINK_CB(in_skb
).pid
, sp
->nlmsg_seq
,
1467 XFRM_MSG_NEWPOLICY
, sizeof(*p
), sp
->nlmsg_flags
);
1471 p
= nlmsg_data(nlh
);
1472 copy_to_user_policy(xp
, p
, dir
);
1473 if (copy_to_user_tmpl(xp
, skb
) < 0)
1475 if (copy_to_user_sec_ctx(xp
, skb
))
1477 if (copy_to_user_policy_type(xp
->type
, skb
) < 0)
1479 if (xfrm_mark_put(skb
, &xp
->mark
))
1480 goto nla_put_failure
;
1482 nlmsg_end(skb
, nlh
);
1487 nlmsg_cancel(skb
, nlh
);
1491 static int xfrm_dump_policy_done(struct netlink_callback
*cb
)
1493 struct xfrm_policy_walk
*walk
= (struct xfrm_policy_walk
*) &cb
->args
[1];
1495 xfrm_policy_walk_done(walk
);
1499 static int xfrm_dump_policy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1501 struct net
*net
= sock_net(skb
->sk
);
1502 struct xfrm_policy_walk
*walk
= (struct xfrm_policy_walk
*) &cb
->args
[1];
1503 struct xfrm_dump_info info
;
1505 BUILD_BUG_ON(sizeof(struct xfrm_policy_walk
) >
1506 sizeof(cb
->args
) - sizeof(cb
->args
[0]));
1508 info
.in_skb
= cb
->skb
;
1510 info
.nlmsg_seq
= cb
->nlh
->nlmsg_seq
;
1511 info
.nlmsg_flags
= NLM_F_MULTI
;
1515 xfrm_policy_walk_init(walk
, XFRM_POLICY_TYPE_ANY
);
1518 (void) xfrm_policy_walk(net
, walk
, dump_one_policy
, &info
);
1523 static struct sk_buff
*xfrm_policy_netlink(struct sk_buff
*in_skb
,
1524 struct xfrm_policy
*xp
,
1527 struct xfrm_dump_info info
;
1528 struct sk_buff
*skb
;
1530 skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1532 return ERR_PTR(-ENOMEM
);
1534 info
.in_skb
= in_skb
;
1536 info
.nlmsg_seq
= seq
;
1537 info
.nlmsg_flags
= 0;
1539 if (dump_one_policy(xp
, dir
, 0, &info
) < 0) {
1547 static int xfrm_get_policy(struct sk_buff
*skb
, struct nlmsghdr
*nlh
,
1548 struct nlattr
**attrs
)
1550 struct net
*net
= sock_net(skb
->sk
);
1551 struct xfrm_policy
*xp
;
1552 struct xfrm_userpolicy_id
*p
;
1553 u8 type
= XFRM_POLICY_TYPE_MAIN
;
1558 u32 mark
= xfrm_mark_get(attrs
, &m
);
1560 p
= nlmsg_data(nlh
);
1561 delete = nlh
->nlmsg_type
== XFRM_MSG_DELPOLICY
;
1563 err
= copy_from_user_policy_type(&type
, attrs
);
1567 err
= verify_policy_dir(p
->dir
);
1572 xp
= xfrm_policy_byid(net
, mark
, type
, p
->dir
, p
->index
, delete, &err
);
1574 struct nlattr
*rt
= attrs
[XFRMA_SEC_CTX
];
1575 struct xfrm_sec_ctx
*ctx
;
1577 err
= verify_sec_ctx_len(attrs
);
1583 struct xfrm_user_sec_ctx
*uctx
= nla_data(rt
);
1585 err
= security_xfrm_policy_alloc(&ctx
, uctx
);
1589 xp
= xfrm_policy_bysel_ctx(net
, mark
, type
, p
->dir
, &p
->sel
,
1591 security_xfrm_policy_free(ctx
);
1597 struct sk_buff
*resp_skb
;
1599 resp_skb
= xfrm_policy_netlink(skb
, xp
, p
->dir
, nlh
->nlmsg_seq
);
1600 if (IS_ERR(resp_skb
)) {
1601 err
= PTR_ERR(resp_skb
);
1603 err
= nlmsg_unicast(net
->xfrm
.nlsk
, resp_skb
,
1604 NETLINK_CB(skb
).pid
);
1607 uid_t loginuid
= audit_get_loginuid(current
);
1608 u32 sessionid
= audit_get_sessionid(current
);
1611 security_task_getsecid(current
, &sid
);
1612 xfrm_audit_policy_delete(xp
, err
? 0 : 1, loginuid
, sessionid
,
1618 c
.data
.byid
= p
->index
;
1619 c
.event
= nlh
->nlmsg_type
;
1620 c
.seq
= nlh
->nlmsg_seq
;
1621 c
.pid
= nlh
->nlmsg_pid
;
1622 km_policy_notify(xp
, p
->dir
, &c
);
1630 static int xfrm_flush_sa(struct sk_buff
*skb
, struct nlmsghdr
*nlh
,
1631 struct nlattr
**attrs
)
1633 struct net
*net
= sock_net(skb
->sk
);
1635 struct xfrm_usersa_flush
*p
= nlmsg_data(nlh
);
1636 struct xfrm_audit audit_info
;
1639 audit_info
.loginuid
= audit_get_loginuid(current
);
1640 audit_info
.sessionid
= audit_get_sessionid(current
);
1641 security_task_getsecid(current
, &audit_info
.secid
);
1642 err
= xfrm_state_flush(net
, p
->proto
, &audit_info
);
1644 if (err
== -ESRCH
) /* empty table */
1648 c
.data
.proto
= p
->proto
;
1649 c
.event
= nlh
->nlmsg_type
;
1650 c
.seq
= nlh
->nlmsg_seq
;
1651 c
.pid
= nlh
->nlmsg_pid
;
1653 km_state_notify(NULL
, &c
);
1658 static inline size_t xfrm_aevent_msgsize(struct xfrm_state
*x
)
1660 size_t replay_size
= x
->replay_esn
?
1661 xfrm_replay_state_esn_len(x
->replay_esn
) :
1662 sizeof(struct xfrm_replay_state
);
1664 return NLMSG_ALIGN(sizeof(struct xfrm_aevent_id
))
1665 + nla_total_size(replay_size
)
1666 + nla_total_size(sizeof(struct xfrm_lifetime_cur
))
1667 + nla_total_size(sizeof(struct xfrm_mark
))
1668 + nla_total_size(4) /* XFRM_AE_RTHR */
1669 + nla_total_size(4); /* XFRM_AE_ETHR */
1672 static int build_aevent(struct sk_buff
*skb
, struct xfrm_state
*x
, const struct km_event
*c
)
1674 struct xfrm_aevent_id
*id
;
1675 struct nlmsghdr
*nlh
;
1677 nlh
= nlmsg_put(skb
, c
->pid
, c
->seq
, XFRM_MSG_NEWAE
, sizeof(*id
), 0);
1681 id
= nlmsg_data(nlh
);
1682 memcpy(&id
->sa_id
.daddr
, &x
->id
.daddr
,sizeof(x
->id
.daddr
));
1683 id
->sa_id
.spi
= x
->id
.spi
;
1684 id
->sa_id
.family
= x
->props
.family
;
1685 id
->sa_id
.proto
= x
->id
.proto
;
1686 memcpy(&id
->saddr
, &x
->props
.saddr
,sizeof(x
->props
.saddr
));
1687 id
->reqid
= x
->props
.reqid
;
1688 id
->flags
= c
->data
.aevent
;
1691 NLA_PUT(skb
, XFRMA_REPLAY_ESN_VAL
,
1692 xfrm_replay_state_esn_len(x
->replay_esn
),
1695 NLA_PUT(skb
, XFRMA_REPLAY_VAL
, sizeof(x
->replay
), &x
->replay
);
1697 NLA_PUT(skb
, XFRMA_LTIME_VAL
, sizeof(x
->curlft
), &x
->curlft
);
1699 if (id
->flags
& XFRM_AE_RTHR
)
1700 NLA_PUT_U32(skb
, XFRMA_REPLAY_THRESH
, x
->replay_maxdiff
);
1702 if (id
->flags
& XFRM_AE_ETHR
)
1703 NLA_PUT_U32(skb
, XFRMA_ETIMER_THRESH
,
1704 x
->replay_maxage
* 10 / HZ
);
1706 if (xfrm_mark_put(skb
, &x
->mark
))
1707 goto nla_put_failure
;
1709 return nlmsg_end(skb
, nlh
);
1712 nlmsg_cancel(skb
, nlh
);
1716 static int xfrm_get_ae(struct sk_buff
*skb
, struct nlmsghdr
*nlh
,
1717 struct nlattr
**attrs
)
1719 struct net
*net
= sock_net(skb
->sk
);
1720 struct xfrm_state
*x
;
1721 struct sk_buff
*r_skb
;
1726 struct xfrm_aevent_id
*p
= nlmsg_data(nlh
);
1727 struct xfrm_usersa_id
*id
= &p
->sa_id
;
1729 mark
= xfrm_mark_get(attrs
, &m
);
1731 x
= xfrm_state_lookup(net
, mark
, &id
->daddr
, id
->spi
, id
->proto
, id
->family
);
1735 r_skb
= nlmsg_new(xfrm_aevent_msgsize(x
), GFP_ATOMIC
);
1736 if (r_skb
== NULL
) {
1742 * XXX: is this lock really needed - none of the other
1743 * gets lock (the concern is things getting updated
1744 * while we are still reading) - jhs
1746 spin_lock_bh(&x
->lock
);
1747 c
.data
.aevent
= p
->flags
;
1748 c
.seq
= nlh
->nlmsg_seq
;
1749 c
.pid
= nlh
->nlmsg_pid
;
1751 if (build_aevent(r_skb
, x
, &c
) < 0)
1753 err
= nlmsg_unicast(net
->xfrm
.nlsk
, r_skb
, NETLINK_CB(skb
).pid
);
1754 spin_unlock_bh(&x
->lock
);
1759 static int xfrm_new_ae(struct sk_buff
*skb
, struct nlmsghdr
*nlh
,
1760 struct nlattr
**attrs
)
1762 struct net
*net
= sock_net(skb
->sk
);
1763 struct xfrm_state
*x
;
1768 struct xfrm_aevent_id
*p
= nlmsg_data(nlh
);
1769 struct nlattr
*rp
= attrs
[XFRMA_REPLAY_VAL
];
1770 struct nlattr
*re
= attrs
[XFRMA_REPLAY_ESN_VAL
];
1771 struct nlattr
*lt
= attrs
[XFRMA_LTIME_VAL
];
1773 if (!lt
&& !rp
&& !re
)
1776 /* pedantic mode - thou shalt sayeth replaceth */
1777 if (!(nlh
->nlmsg_flags
&NLM_F_REPLACE
))
1780 mark
= xfrm_mark_get(attrs
, &m
);
1782 x
= xfrm_state_lookup(net
, mark
, &p
->sa_id
.daddr
, p
->sa_id
.spi
, p
->sa_id
.proto
, p
->sa_id
.family
);
1786 if (x
->km
.state
!= XFRM_STATE_VALID
)
1789 err
= xfrm_replay_verify_len(x
->replay_esn
, rp
);
1793 spin_lock_bh(&x
->lock
);
1794 xfrm_update_ae_params(x
, attrs
);
1795 spin_unlock_bh(&x
->lock
);
1797 c
.event
= nlh
->nlmsg_type
;
1798 c
.seq
= nlh
->nlmsg_seq
;
1799 c
.pid
= nlh
->nlmsg_pid
;
1800 c
.data
.aevent
= XFRM_AE_CU
;
1801 km_state_notify(x
, &c
);
1808 static int xfrm_flush_policy(struct sk_buff
*skb
, struct nlmsghdr
*nlh
,
1809 struct nlattr
**attrs
)
1811 struct net
*net
= sock_net(skb
->sk
);
1813 u8 type
= XFRM_POLICY_TYPE_MAIN
;
1815 struct xfrm_audit audit_info
;
1817 err
= copy_from_user_policy_type(&type
, attrs
);
1821 audit_info
.loginuid
= audit_get_loginuid(current
);
1822 audit_info
.sessionid
= audit_get_sessionid(current
);
1823 security_task_getsecid(current
, &audit_info
.secid
);
1824 err
= xfrm_policy_flush(net
, type
, &audit_info
);
1826 if (err
== -ESRCH
) /* empty table */
1832 c
.event
= nlh
->nlmsg_type
;
1833 c
.seq
= nlh
->nlmsg_seq
;
1834 c
.pid
= nlh
->nlmsg_pid
;
1836 km_policy_notify(NULL
, 0, &c
);
1840 static int xfrm_add_pol_expire(struct sk_buff
*skb
, struct nlmsghdr
*nlh
,
1841 struct nlattr
**attrs
)
1843 struct net
*net
= sock_net(skb
->sk
);
1844 struct xfrm_policy
*xp
;
1845 struct xfrm_user_polexpire
*up
= nlmsg_data(nlh
);
1846 struct xfrm_userpolicy_info
*p
= &up
->pol
;
1847 u8 type
= XFRM_POLICY_TYPE_MAIN
;
1850 u32 mark
= xfrm_mark_get(attrs
, &m
);
1852 err
= copy_from_user_policy_type(&type
, attrs
);
1856 err
= verify_policy_dir(p
->dir
);
1861 xp
= xfrm_policy_byid(net
, mark
, type
, p
->dir
, p
->index
, 0, &err
);
1863 struct nlattr
*rt
= attrs
[XFRMA_SEC_CTX
];
1864 struct xfrm_sec_ctx
*ctx
;
1866 err
= verify_sec_ctx_len(attrs
);
1872 struct xfrm_user_sec_ctx
*uctx
= nla_data(rt
);
1874 err
= security_xfrm_policy_alloc(&ctx
, uctx
);
1878 xp
= xfrm_policy_bysel_ctx(net
, mark
, type
, p
->dir
,
1879 &p
->sel
, ctx
, 0, &err
);
1880 security_xfrm_policy_free(ctx
);
1885 if (unlikely(xp
->walk
.dead
))
1890 uid_t loginuid
= audit_get_loginuid(current
);
1891 u32 sessionid
= audit_get_sessionid(current
);
1894 security_task_getsecid(current
, &sid
);
1895 xfrm_policy_delete(xp
, p
->dir
);
1896 xfrm_audit_policy_delete(xp
, 1, loginuid
, sessionid
, sid
);
1899 // reset the timers here?
1900 WARN(1, "Dont know what to do with soft policy expire\n");
1902 km_policy_expired(xp
, p
->dir
, up
->hard
, current
->pid
);
1909 static int xfrm_add_sa_expire(struct sk_buff
*skb
, struct nlmsghdr
*nlh
,
1910 struct nlattr
**attrs
)
1912 struct net
*net
= sock_net(skb
->sk
);
1913 struct xfrm_state
*x
;
1915 struct xfrm_user_expire
*ue
= nlmsg_data(nlh
);
1916 struct xfrm_usersa_info
*p
= &ue
->state
;
1918 u32 mark
= xfrm_mark_get(attrs
, &m
);
1920 x
= xfrm_state_lookup(net
, mark
, &p
->id
.daddr
, p
->id
.spi
, p
->id
.proto
, p
->family
);
1926 spin_lock_bh(&x
->lock
);
1928 if (x
->km
.state
!= XFRM_STATE_VALID
)
1930 km_state_expired(x
, ue
->hard
, current
->pid
);
1933 uid_t loginuid
= audit_get_loginuid(current
);
1934 u32 sessionid
= audit_get_sessionid(current
);
1937 security_task_getsecid(current
, &sid
);
1938 __xfrm_state_delete(x
);
1939 xfrm_audit_state_delete(x
, 1, loginuid
, sessionid
, sid
);
1943 spin_unlock_bh(&x
->lock
);
1948 static int xfrm_add_acquire(struct sk_buff
*skb
, struct nlmsghdr
*nlh
,
1949 struct nlattr
**attrs
)
1951 struct net
*net
= sock_net(skb
->sk
);
1952 struct xfrm_policy
*xp
;
1953 struct xfrm_user_tmpl
*ut
;
1955 struct nlattr
*rt
= attrs
[XFRMA_TMPL
];
1956 struct xfrm_mark mark
;
1958 struct xfrm_user_acquire
*ua
= nlmsg_data(nlh
);
1959 struct xfrm_state
*x
= xfrm_state_alloc(net
);
1965 xfrm_mark_get(attrs
, &mark
);
1967 err
= verify_newpolicy_info(&ua
->policy
);
1972 xp
= xfrm_policy_construct(net
, &ua
->policy
, attrs
, &err
);
1976 memcpy(&x
->id
, &ua
->id
, sizeof(ua
->id
));
1977 memcpy(&x
->props
.saddr
, &ua
->saddr
, sizeof(ua
->saddr
));
1978 memcpy(&x
->sel
, &ua
->sel
, sizeof(ua
->sel
));
1979 xp
->mark
.m
= x
->mark
.m
= mark
.m
;
1980 xp
->mark
.v
= x
->mark
.v
= mark
.v
;
1982 /* extract the templates and for each call km_key */
1983 for (i
= 0; i
< xp
->xfrm_nr
; i
++, ut
++) {
1984 struct xfrm_tmpl
*t
= &xp
->xfrm_vec
[i
];
1985 memcpy(&x
->id
, &t
->id
, sizeof(x
->id
));
1986 x
->props
.mode
= t
->mode
;
1987 x
->props
.reqid
= t
->reqid
;
1988 x
->props
.family
= ut
->family
;
1989 t
->aalgos
= ua
->aalgos
;
1990 t
->ealgos
= ua
->ealgos
;
1991 t
->calgos
= ua
->calgos
;
1992 err
= km_query(x
, t
, xp
);
2002 WARN(1, "BAD policy passed\n");
2009 #ifdef CONFIG_XFRM_MIGRATE
2010 static int copy_from_user_migrate(struct xfrm_migrate
*ma
,
2011 struct xfrm_kmaddress
*k
,
2012 struct nlattr
**attrs
, int *num
)
2014 struct nlattr
*rt
= attrs
[XFRMA_MIGRATE
];
2015 struct xfrm_user_migrate
*um
;
2019 struct xfrm_user_kmaddress
*uk
;
2021 uk
= nla_data(attrs
[XFRMA_KMADDRESS
]);
2022 memcpy(&k
->local
, &uk
->local
, sizeof(k
->local
));
2023 memcpy(&k
->remote
, &uk
->remote
, sizeof(k
->remote
));
2024 k
->family
= uk
->family
;
2025 k
->reserved
= uk
->reserved
;
2029 num_migrate
= nla_len(rt
) / sizeof(*um
);
2031 if (num_migrate
<= 0 || num_migrate
> XFRM_MAX_DEPTH
)
2034 for (i
= 0; i
< num_migrate
; i
++, um
++, ma
++) {
2035 memcpy(&ma
->old_daddr
, &um
->old_daddr
, sizeof(ma
->old_daddr
));
2036 memcpy(&ma
->old_saddr
, &um
->old_saddr
, sizeof(ma
->old_saddr
));
2037 memcpy(&ma
->new_daddr
, &um
->new_daddr
, sizeof(ma
->new_daddr
));
2038 memcpy(&ma
->new_saddr
, &um
->new_saddr
, sizeof(ma
->new_saddr
));
2040 ma
->proto
= um
->proto
;
2041 ma
->mode
= um
->mode
;
2042 ma
->reqid
= um
->reqid
;
2044 ma
->old_family
= um
->old_family
;
2045 ma
->new_family
= um
->new_family
;
2052 static int xfrm_do_migrate(struct sk_buff
*skb
, struct nlmsghdr
*nlh
,
2053 struct nlattr
**attrs
)
2055 struct xfrm_userpolicy_id
*pi
= nlmsg_data(nlh
);
2056 struct xfrm_migrate m
[XFRM_MAX_DEPTH
];
2057 struct xfrm_kmaddress km
, *kmp
;
2062 if (attrs
[XFRMA_MIGRATE
] == NULL
)
2065 kmp
= attrs
[XFRMA_KMADDRESS
] ? &km
: NULL
;
2067 err
= copy_from_user_policy_type(&type
, attrs
);
2071 err
= copy_from_user_migrate((struct xfrm_migrate
*)m
, kmp
, attrs
, &n
);
2078 xfrm_migrate(&pi
->sel
, pi
->dir
, type
, m
, n
, kmp
);
2083 static int xfrm_do_migrate(struct sk_buff
*skb
, struct nlmsghdr
*nlh
,
2084 struct nlattr
**attrs
)
2086 return -ENOPROTOOPT
;
2090 #ifdef CONFIG_XFRM_MIGRATE
2091 static int copy_to_user_migrate(const struct xfrm_migrate
*m
, struct sk_buff
*skb
)
2093 struct xfrm_user_migrate um
;
2095 memset(&um
, 0, sizeof(um
));
2096 um
.proto
= m
->proto
;
2098 um
.reqid
= m
->reqid
;
2099 um
.old_family
= m
->old_family
;
2100 memcpy(&um
.old_daddr
, &m
->old_daddr
, sizeof(um
.old_daddr
));
2101 memcpy(&um
.old_saddr
, &m
->old_saddr
, sizeof(um
.old_saddr
));
2102 um
.new_family
= m
->new_family
;
2103 memcpy(&um
.new_daddr
, &m
->new_daddr
, sizeof(um
.new_daddr
));
2104 memcpy(&um
.new_saddr
, &m
->new_saddr
, sizeof(um
.new_saddr
));
2106 return nla_put(skb
, XFRMA_MIGRATE
, sizeof(um
), &um
);
2109 static int copy_to_user_kmaddress(const struct xfrm_kmaddress
*k
, struct sk_buff
*skb
)
2111 struct xfrm_user_kmaddress uk
;
2113 memset(&uk
, 0, sizeof(uk
));
2114 uk
.family
= k
->family
;
2115 uk
.reserved
= k
->reserved
;
2116 memcpy(&uk
.local
, &k
->local
, sizeof(uk
.local
));
2117 memcpy(&uk
.remote
, &k
->remote
, sizeof(uk
.remote
));
2119 return nla_put(skb
, XFRMA_KMADDRESS
, sizeof(uk
), &uk
);
2122 static inline size_t xfrm_migrate_msgsize(int num_migrate
, int with_kma
)
2124 return NLMSG_ALIGN(sizeof(struct xfrm_userpolicy_id
))
2125 + (with_kma
? nla_total_size(sizeof(struct xfrm_kmaddress
)) : 0)
2126 + nla_total_size(sizeof(struct xfrm_user_migrate
) * num_migrate
)
2127 + userpolicy_type_attrsize();
2130 static int build_migrate(struct sk_buff
*skb
, const struct xfrm_migrate
*m
,
2131 int num_migrate
, const struct xfrm_kmaddress
*k
,
2132 const struct xfrm_selector
*sel
, u8 dir
, u8 type
)
2134 const struct xfrm_migrate
*mp
;
2135 struct xfrm_userpolicy_id
*pol_id
;
2136 struct nlmsghdr
*nlh
;
2139 nlh
= nlmsg_put(skb
, 0, 0, XFRM_MSG_MIGRATE
, sizeof(*pol_id
), 0);
2143 pol_id
= nlmsg_data(nlh
);
2144 /* copy data from selector, dir, and type to the pol_id */
2145 memset(pol_id
, 0, sizeof(*pol_id
));
2146 memcpy(&pol_id
->sel
, sel
, sizeof(pol_id
->sel
));
2149 if (k
!= NULL
&& (copy_to_user_kmaddress(k
, skb
) < 0))
2152 if (copy_to_user_policy_type(type
, skb
) < 0)
2155 for (i
= 0, mp
= m
; i
< num_migrate
; i
++, mp
++) {
2156 if (copy_to_user_migrate(mp
, skb
) < 0)
2160 return nlmsg_end(skb
, nlh
);
2162 nlmsg_cancel(skb
, nlh
);
2166 static int xfrm_send_migrate(const struct xfrm_selector
*sel
, u8 dir
, u8 type
,
2167 const struct xfrm_migrate
*m
, int num_migrate
,
2168 const struct xfrm_kmaddress
*k
)
2170 struct net
*net
= &init_net
;
2171 struct sk_buff
*skb
;
2173 skb
= nlmsg_new(xfrm_migrate_msgsize(num_migrate
, !!k
), GFP_ATOMIC
);
2178 if (build_migrate(skb
, m
, num_migrate
, k
, sel
, dir
, type
) < 0)
2181 return nlmsg_multicast(net
->xfrm
.nlsk
, skb
, 0, XFRMNLGRP_MIGRATE
, GFP_ATOMIC
);
2184 static int xfrm_send_migrate(const struct xfrm_selector
*sel
, u8 dir
, u8 type
,
2185 const struct xfrm_migrate
*m
, int num_migrate
,
2186 const struct xfrm_kmaddress
*k
)
2188 return -ENOPROTOOPT
;
2192 #define XMSGSIZE(type) sizeof(struct type)
2194 static const int xfrm_msg_min
[XFRM_NR_MSGTYPES
] = {
2195 [XFRM_MSG_NEWSA
- XFRM_MSG_BASE
] = XMSGSIZE(xfrm_usersa_info
),
2196 [XFRM_MSG_DELSA
- XFRM_MSG_BASE
] = XMSGSIZE(xfrm_usersa_id
),
2197 [XFRM_MSG_GETSA
- XFRM_MSG_BASE
] = XMSGSIZE(xfrm_usersa_id
),
2198 [XFRM_MSG_NEWPOLICY
- XFRM_MSG_BASE
] = XMSGSIZE(xfrm_userpolicy_info
),
2199 [XFRM_MSG_DELPOLICY
- XFRM_MSG_BASE
] = XMSGSIZE(xfrm_userpolicy_id
),
2200 [XFRM_MSG_GETPOLICY
- XFRM_MSG_BASE
] = XMSGSIZE(xfrm_userpolicy_id
),
2201 [XFRM_MSG_ALLOCSPI
- XFRM_MSG_BASE
] = XMSGSIZE(xfrm_userspi_info
),
2202 [XFRM_MSG_ACQUIRE
- XFRM_MSG_BASE
] = XMSGSIZE(xfrm_user_acquire
),
2203 [XFRM_MSG_EXPIRE
- XFRM_MSG_BASE
] = XMSGSIZE(xfrm_user_expire
),
2204 [XFRM_MSG_UPDPOLICY
- XFRM_MSG_BASE
] = XMSGSIZE(xfrm_userpolicy_info
),
2205 [XFRM_MSG_UPDSA
- XFRM_MSG_BASE
] = XMSGSIZE(xfrm_usersa_info
),
2206 [XFRM_MSG_POLEXPIRE
- XFRM_MSG_BASE
] = XMSGSIZE(xfrm_user_polexpire
),
2207 [XFRM_MSG_FLUSHSA
- XFRM_MSG_BASE
] = XMSGSIZE(xfrm_usersa_flush
),
2208 [XFRM_MSG_FLUSHPOLICY
- XFRM_MSG_BASE
] = 0,
2209 [XFRM_MSG_NEWAE
- XFRM_MSG_BASE
] = XMSGSIZE(xfrm_aevent_id
),
2210 [XFRM_MSG_GETAE
- XFRM_MSG_BASE
] = XMSGSIZE(xfrm_aevent_id
),
2211 [XFRM_MSG_REPORT
- XFRM_MSG_BASE
] = XMSGSIZE(xfrm_user_report
),
2212 [XFRM_MSG_MIGRATE
- XFRM_MSG_BASE
] = XMSGSIZE(xfrm_userpolicy_id
),
2213 [XFRM_MSG_GETSADINFO
- XFRM_MSG_BASE
] = sizeof(u32
),
2214 [XFRM_MSG_GETSPDINFO
- XFRM_MSG_BASE
] = sizeof(u32
),
2219 static const struct nla_policy xfrma_policy
[XFRMA_MAX
+1] = {
2220 [XFRMA_SA
] = { .len
= sizeof(struct xfrm_usersa_info
)},
2221 [XFRMA_POLICY
] = { .len
= sizeof(struct xfrm_userpolicy_info
)},
2222 [XFRMA_LASTUSED
] = { .type
= NLA_U64
},
2223 [XFRMA_ALG_AUTH_TRUNC
] = { .len
= sizeof(struct xfrm_algo_auth
)},
2224 [XFRMA_ALG_AEAD
] = { .len
= sizeof(struct xfrm_algo_aead
) },
2225 [XFRMA_ALG_AUTH
] = { .len
= sizeof(struct xfrm_algo
) },
2226 [XFRMA_ALG_CRYPT
] = { .len
= sizeof(struct xfrm_algo
) },
2227 [XFRMA_ALG_COMP
] = { .len
= sizeof(struct xfrm_algo
) },
2228 [XFRMA_ENCAP
] = { .len
= sizeof(struct xfrm_encap_tmpl
) },
2229 [XFRMA_TMPL
] = { .len
= sizeof(struct xfrm_user_tmpl
) },
2230 [XFRMA_SEC_CTX
] = { .len
= sizeof(struct xfrm_sec_ctx
) },
2231 [XFRMA_LTIME_VAL
] = { .len
= sizeof(struct xfrm_lifetime_cur
) },
2232 [XFRMA_REPLAY_VAL
] = { .len
= sizeof(struct xfrm_replay_state
) },
2233 [XFRMA_REPLAY_THRESH
] = { .type
= NLA_U32
},
2234 [XFRMA_ETIMER_THRESH
] = { .type
= NLA_U32
},
2235 [XFRMA_SRCADDR
] = { .len
= sizeof(xfrm_address_t
) },
2236 [XFRMA_COADDR
] = { .len
= sizeof(xfrm_address_t
) },
2237 [XFRMA_POLICY_TYPE
] = { .len
= sizeof(struct xfrm_userpolicy_type
)},
2238 [XFRMA_MIGRATE
] = { .len
= sizeof(struct xfrm_user_migrate
) },
2239 [XFRMA_KMADDRESS
] = { .len
= sizeof(struct xfrm_user_kmaddress
) },
2240 [XFRMA_MARK
] = { .len
= sizeof(struct xfrm_mark
) },
2241 [XFRMA_TFCPAD
] = { .type
= NLA_U32
},
2242 [XFRMA_REPLAY_ESN_VAL
] = { .len
= sizeof(struct xfrm_replay_state_esn
) },
2245 static struct xfrm_link
{
2246 int (*doit
)(struct sk_buff
*, struct nlmsghdr
*, struct nlattr
**);
2247 int (*dump
)(struct sk_buff
*, struct netlink_callback
*);
2248 int (*done
)(struct netlink_callback
*);
2249 } xfrm_dispatch
[XFRM_NR_MSGTYPES
] = {
2250 [XFRM_MSG_NEWSA
- XFRM_MSG_BASE
] = { .doit
= xfrm_add_sa
},
2251 [XFRM_MSG_DELSA
- XFRM_MSG_BASE
] = { .doit
= xfrm_del_sa
},
2252 [XFRM_MSG_GETSA
- XFRM_MSG_BASE
] = { .doit
= xfrm_get_sa
,
2253 .dump
= xfrm_dump_sa
,
2254 .done
= xfrm_dump_sa_done
},
2255 [XFRM_MSG_NEWPOLICY
- XFRM_MSG_BASE
] = { .doit
= xfrm_add_policy
},
2256 [XFRM_MSG_DELPOLICY
- XFRM_MSG_BASE
] = { .doit
= xfrm_get_policy
},
2257 [XFRM_MSG_GETPOLICY
- XFRM_MSG_BASE
] = { .doit
= xfrm_get_policy
,
2258 .dump
= xfrm_dump_policy
,
2259 .done
= xfrm_dump_policy_done
},
2260 [XFRM_MSG_ALLOCSPI
- XFRM_MSG_BASE
] = { .doit
= xfrm_alloc_userspi
},
2261 [XFRM_MSG_ACQUIRE
- XFRM_MSG_BASE
] = { .doit
= xfrm_add_acquire
},
2262 [XFRM_MSG_EXPIRE
- XFRM_MSG_BASE
] = { .doit
= xfrm_add_sa_expire
},
2263 [XFRM_MSG_UPDPOLICY
- XFRM_MSG_BASE
] = { .doit
= xfrm_add_policy
},
2264 [XFRM_MSG_UPDSA
- XFRM_MSG_BASE
] = { .doit
= xfrm_add_sa
},
2265 [XFRM_MSG_POLEXPIRE
- XFRM_MSG_BASE
] = { .doit
= xfrm_add_pol_expire
},
2266 [XFRM_MSG_FLUSHSA
- XFRM_MSG_BASE
] = { .doit
= xfrm_flush_sa
},
2267 [XFRM_MSG_FLUSHPOLICY
- XFRM_MSG_BASE
] = { .doit
= xfrm_flush_policy
},
2268 [XFRM_MSG_NEWAE
- XFRM_MSG_BASE
] = { .doit
= xfrm_new_ae
},
2269 [XFRM_MSG_GETAE
- XFRM_MSG_BASE
] = { .doit
= xfrm_get_ae
},
2270 [XFRM_MSG_MIGRATE
- XFRM_MSG_BASE
] = { .doit
= xfrm_do_migrate
},
2271 [XFRM_MSG_GETSADINFO
- XFRM_MSG_BASE
] = { .doit
= xfrm_get_sadinfo
},
2272 [XFRM_MSG_GETSPDINFO
- XFRM_MSG_BASE
] = { .doit
= xfrm_get_spdinfo
},
2275 static int xfrm_user_rcv_msg(struct sk_buff
*skb
, struct nlmsghdr
*nlh
)
2277 struct net
*net
= sock_net(skb
->sk
);
2278 struct nlattr
*attrs
[XFRMA_MAX
+1];
2279 struct xfrm_link
*link
;
2282 type
= nlh
->nlmsg_type
;
2283 if (type
> XFRM_MSG_MAX
)
2286 type
-= XFRM_MSG_BASE
;
2287 link
= &xfrm_dispatch
[type
];
2289 /* All operations require privileges, even GET */
2290 if (security_netlink_recv(skb
, CAP_NET_ADMIN
))
2293 if ((type
== (XFRM_MSG_GETSA
- XFRM_MSG_BASE
) ||
2294 type
== (XFRM_MSG_GETPOLICY
- XFRM_MSG_BASE
)) &&
2295 (nlh
->nlmsg_flags
& NLM_F_DUMP
)) {
2296 if (link
->dump
== NULL
)
2299 return netlink_dump_start(net
->xfrm
.nlsk
, skb
, nlh
, link
->dump
, link
->done
);
2302 err
= nlmsg_parse(nlh
, xfrm_msg_min
[type
], attrs
, XFRMA_MAX
,
2307 if (link
->doit
== NULL
)
2310 return link
->doit(skb
, nlh
, attrs
);
2313 static void xfrm_netlink_rcv(struct sk_buff
*skb
)
2315 mutex_lock(&xfrm_cfg_mutex
);
2316 netlink_rcv_skb(skb
, &xfrm_user_rcv_msg
);
2317 mutex_unlock(&xfrm_cfg_mutex
);
2320 static inline size_t xfrm_expire_msgsize(void)
2322 return NLMSG_ALIGN(sizeof(struct xfrm_user_expire
))
2323 + nla_total_size(sizeof(struct xfrm_mark
));
2326 static int build_expire(struct sk_buff
*skb
, struct xfrm_state
*x
, const struct km_event
*c
)
2328 struct xfrm_user_expire
*ue
;
2329 struct nlmsghdr
*nlh
;
2331 nlh
= nlmsg_put(skb
, c
->pid
, 0, XFRM_MSG_EXPIRE
, sizeof(*ue
), 0);
2335 ue
= nlmsg_data(nlh
);
2336 copy_to_user_state(x
, &ue
->state
);
2337 ue
->hard
= (c
->data
.hard
!= 0) ? 1 : 0;
2339 if (xfrm_mark_put(skb
, &x
->mark
))
2340 goto nla_put_failure
;
2342 return nlmsg_end(skb
, nlh
);
2348 static int xfrm_exp_state_notify(struct xfrm_state
*x
, const struct km_event
*c
)
2350 struct net
*net
= xs_net(x
);
2351 struct sk_buff
*skb
;
2353 skb
= nlmsg_new(xfrm_expire_msgsize(), GFP_ATOMIC
);
2357 if (build_expire(skb
, x
, c
) < 0) {
2362 return nlmsg_multicast(net
->xfrm
.nlsk
, skb
, 0, XFRMNLGRP_EXPIRE
, GFP_ATOMIC
);
2365 static int xfrm_aevent_state_notify(struct xfrm_state
*x
, const struct km_event
*c
)
2367 struct net
*net
= xs_net(x
);
2368 struct sk_buff
*skb
;
2370 skb
= nlmsg_new(xfrm_aevent_msgsize(x
), GFP_ATOMIC
);
2374 if (build_aevent(skb
, x
, c
) < 0)
2377 return nlmsg_multicast(net
->xfrm
.nlsk
, skb
, 0, XFRMNLGRP_AEVENTS
, GFP_ATOMIC
);
2380 static int xfrm_notify_sa_flush(const struct km_event
*c
)
2382 struct net
*net
= c
->net
;
2383 struct xfrm_usersa_flush
*p
;
2384 struct nlmsghdr
*nlh
;
2385 struct sk_buff
*skb
;
2386 int len
= NLMSG_ALIGN(sizeof(struct xfrm_usersa_flush
));
2388 skb
= nlmsg_new(len
, GFP_ATOMIC
);
2392 nlh
= nlmsg_put(skb
, c
->pid
, c
->seq
, XFRM_MSG_FLUSHSA
, sizeof(*p
), 0);
2398 p
= nlmsg_data(nlh
);
2399 p
->proto
= c
->data
.proto
;
2401 nlmsg_end(skb
, nlh
);
2403 return nlmsg_multicast(net
->xfrm
.nlsk
, skb
, 0, XFRMNLGRP_SA
, GFP_ATOMIC
);
2406 static inline size_t xfrm_sa_len(struct xfrm_state
*x
)
2410 l
+= nla_total_size(aead_len(x
->aead
));
2412 l
+= nla_total_size(sizeof(struct xfrm_algo
) +
2413 (x
->aalg
->alg_key_len
+ 7) / 8);
2414 l
+= nla_total_size(xfrm_alg_auth_len(x
->aalg
));
2417 l
+= nla_total_size(xfrm_alg_len(x
->ealg
));
2419 l
+= nla_total_size(sizeof(*x
->calg
));
2421 l
+= nla_total_size(sizeof(*x
->encap
));
2423 l
+= nla_total_size(sizeof(x
->tfcpad
));
2425 l
+= nla_total_size(xfrm_replay_state_esn_len(x
->replay_esn
));
2427 l
+= nla_total_size(sizeof(struct xfrm_user_sec_ctx
) +
2428 x
->security
->ctx_len
);
2430 l
+= nla_total_size(sizeof(*x
->coaddr
));
2432 /* Must count x->lastused as it may become non-zero behind our back. */
2433 l
+= nla_total_size(sizeof(u64
));
2438 static int xfrm_notify_sa(struct xfrm_state
*x
, const struct km_event
*c
)
2440 struct net
*net
= xs_net(x
);
2441 struct xfrm_usersa_info
*p
;
2442 struct xfrm_usersa_id
*id
;
2443 struct nlmsghdr
*nlh
;
2444 struct sk_buff
*skb
;
2445 int len
= xfrm_sa_len(x
);
2448 headlen
= sizeof(*p
);
2449 if (c
->event
== XFRM_MSG_DELSA
) {
2450 len
+= nla_total_size(headlen
);
2451 headlen
= sizeof(*id
);
2452 len
+= nla_total_size(sizeof(struct xfrm_mark
));
2454 len
+= NLMSG_ALIGN(headlen
);
2456 skb
= nlmsg_new(len
, GFP_ATOMIC
);
2460 nlh
= nlmsg_put(skb
, c
->pid
, c
->seq
, c
->event
, headlen
, 0);
2462 goto nla_put_failure
;
2464 p
= nlmsg_data(nlh
);
2465 if (c
->event
== XFRM_MSG_DELSA
) {
2466 struct nlattr
*attr
;
2468 id
= nlmsg_data(nlh
);
2469 memcpy(&id
->daddr
, &x
->id
.daddr
, sizeof(id
->daddr
));
2470 id
->spi
= x
->id
.spi
;
2471 id
->family
= x
->props
.family
;
2472 id
->proto
= x
->id
.proto
;
2474 attr
= nla_reserve(skb
, XFRMA_SA
, sizeof(*p
));
2476 goto nla_put_failure
;
2481 if (copy_to_user_state_extra(x
, p
, skb
))
2482 goto nla_put_failure
;
2484 nlmsg_end(skb
, nlh
);
2486 return nlmsg_multicast(net
->xfrm
.nlsk
, skb
, 0, XFRMNLGRP_SA
, GFP_ATOMIC
);
2489 /* Somebody screwed up with xfrm_sa_len! */
2495 static int xfrm_send_state_notify(struct xfrm_state
*x
, const struct km_event
*c
)
2499 case XFRM_MSG_EXPIRE
:
2500 return xfrm_exp_state_notify(x
, c
);
2501 case XFRM_MSG_NEWAE
:
2502 return xfrm_aevent_state_notify(x
, c
);
2503 case XFRM_MSG_DELSA
:
2504 case XFRM_MSG_UPDSA
:
2505 case XFRM_MSG_NEWSA
:
2506 return xfrm_notify_sa(x
, c
);
2507 case XFRM_MSG_FLUSHSA
:
2508 return xfrm_notify_sa_flush(c
);
2510 printk(KERN_NOTICE
"xfrm_user: Unknown SA event %d\n",
2519 static inline size_t xfrm_acquire_msgsize(struct xfrm_state
*x
,
2520 struct xfrm_policy
*xp
)
2522 return NLMSG_ALIGN(sizeof(struct xfrm_user_acquire
))
2523 + nla_total_size(sizeof(struct xfrm_user_tmpl
) * xp
->xfrm_nr
)
2524 + nla_total_size(sizeof(struct xfrm_mark
))
2525 + nla_total_size(xfrm_user_sec_ctx_size(x
->security
))
2526 + userpolicy_type_attrsize();
2529 static int build_acquire(struct sk_buff
*skb
, struct xfrm_state
*x
,
2530 struct xfrm_tmpl
*xt
, struct xfrm_policy
*xp
,
2533 struct xfrm_user_acquire
*ua
;
2534 struct nlmsghdr
*nlh
;
2535 __u32 seq
= xfrm_get_acqseq();
2537 nlh
= nlmsg_put(skb
, 0, 0, XFRM_MSG_ACQUIRE
, sizeof(*ua
), 0);
2541 ua
= nlmsg_data(nlh
);
2542 memcpy(&ua
->id
, &x
->id
, sizeof(ua
->id
));
2543 memcpy(&ua
->saddr
, &x
->props
.saddr
, sizeof(ua
->saddr
));
2544 memcpy(&ua
->sel
, &x
->sel
, sizeof(ua
->sel
));
2545 copy_to_user_policy(xp
, &ua
->policy
, dir
);
2546 ua
->aalgos
= xt
->aalgos
;
2547 ua
->ealgos
= xt
->ealgos
;
2548 ua
->calgos
= xt
->calgos
;
2549 ua
->seq
= x
->km
.seq
= seq
;
2551 if (copy_to_user_tmpl(xp
, skb
) < 0)
2553 if (copy_to_user_state_sec_ctx(x
, skb
))
2555 if (copy_to_user_policy_type(xp
->type
, skb
) < 0)
2557 if (xfrm_mark_put(skb
, &xp
->mark
))
2558 goto nla_put_failure
;
2560 return nlmsg_end(skb
, nlh
);
2564 nlmsg_cancel(skb
, nlh
);
2568 static int xfrm_send_acquire(struct xfrm_state
*x
, struct xfrm_tmpl
*xt
,
2569 struct xfrm_policy
*xp
, int dir
)
2571 struct net
*net
= xs_net(x
);
2572 struct sk_buff
*skb
;
2574 skb
= nlmsg_new(xfrm_acquire_msgsize(x
, xp
), GFP_ATOMIC
);
2578 if (build_acquire(skb
, x
, xt
, xp
, dir
) < 0)
2581 return nlmsg_multicast(net
->xfrm
.nlsk
, skb
, 0, XFRMNLGRP_ACQUIRE
, GFP_ATOMIC
);
2584 /* User gives us xfrm_user_policy_info followed by an array of 0
2585 * or more templates.
2587 static struct xfrm_policy
*xfrm_compile_policy(struct sock
*sk
, int opt
,
2588 u8
*data
, int len
, int *dir
)
2590 struct net
*net
= sock_net(sk
);
2591 struct xfrm_userpolicy_info
*p
= (struct xfrm_userpolicy_info
*)data
;
2592 struct xfrm_user_tmpl
*ut
= (struct xfrm_user_tmpl
*) (p
+ 1);
2593 struct xfrm_policy
*xp
;
2596 switch (sk
->sk_family
) {
2598 if (opt
!= IP_XFRM_POLICY
) {
2603 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
2605 if (opt
!= IPV6_XFRM_POLICY
) {
2618 if (len
< sizeof(*p
) ||
2619 verify_newpolicy_info(p
))
2622 nr
= ((len
- sizeof(*p
)) / sizeof(*ut
));
2623 if (validate_tmpl(nr
, ut
, p
->sel
.family
))
2626 if (p
->dir
> XFRM_POLICY_OUT
)
2629 xp
= xfrm_policy_alloc(net
, GFP_ATOMIC
);
2635 copy_from_user_policy(xp
, p
);
2636 xp
->type
= XFRM_POLICY_TYPE_MAIN
;
2637 copy_templates(xp
, ut
, nr
);
2644 static inline size_t xfrm_polexpire_msgsize(struct xfrm_policy
*xp
)
2646 return NLMSG_ALIGN(sizeof(struct xfrm_user_polexpire
))
2647 + nla_total_size(sizeof(struct xfrm_user_tmpl
) * xp
->xfrm_nr
)
2648 + nla_total_size(xfrm_user_sec_ctx_size(xp
->security
))
2649 + nla_total_size(sizeof(struct xfrm_mark
))
2650 + userpolicy_type_attrsize();
2653 static int build_polexpire(struct sk_buff
*skb
, struct xfrm_policy
*xp
,
2654 int dir
, const struct km_event
*c
)
2656 struct xfrm_user_polexpire
*upe
;
2657 struct nlmsghdr
*nlh
;
2658 int hard
= c
->data
.hard
;
2660 nlh
= nlmsg_put(skb
, c
->pid
, 0, XFRM_MSG_POLEXPIRE
, sizeof(*upe
), 0);
2664 upe
= nlmsg_data(nlh
);
2665 copy_to_user_policy(xp
, &upe
->pol
, dir
);
2666 if (copy_to_user_tmpl(xp
, skb
) < 0)
2668 if (copy_to_user_sec_ctx(xp
, skb
))
2670 if (copy_to_user_policy_type(xp
->type
, skb
) < 0)
2672 if (xfrm_mark_put(skb
, &xp
->mark
))
2673 goto nla_put_failure
;
2676 return nlmsg_end(skb
, nlh
);
2680 nlmsg_cancel(skb
, nlh
);
2684 static int xfrm_exp_policy_notify(struct xfrm_policy
*xp
, int dir
, const struct km_event
*c
)
2686 struct net
*net
= xp_net(xp
);
2687 struct sk_buff
*skb
;
2689 skb
= nlmsg_new(xfrm_polexpire_msgsize(xp
), GFP_ATOMIC
);
2693 if (build_polexpire(skb
, xp
, dir
, c
) < 0)
2696 return nlmsg_multicast(net
->xfrm
.nlsk
, skb
, 0, XFRMNLGRP_EXPIRE
, GFP_ATOMIC
);
2699 static int xfrm_notify_policy(struct xfrm_policy
*xp
, int dir
, const struct km_event
*c
)
2701 struct net
*net
= xp_net(xp
);
2702 struct xfrm_userpolicy_info
*p
;
2703 struct xfrm_userpolicy_id
*id
;
2704 struct nlmsghdr
*nlh
;
2705 struct sk_buff
*skb
;
2706 int len
= nla_total_size(sizeof(struct xfrm_user_tmpl
) * xp
->xfrm_nr
);
2709 headlen
= sizeof(*p
);
2710 if (c
->event
== XFRM_MSG_DELPOLICY
) {
2711 len
+= nla_total_size(headlen
);
2712 headlen
= sizeof(*id
);
2714 len
+= userpolicy_type_attrsize();
2715 len
+= nla_total_size(sizeof(struct xfrm_mark
));
2716 len
+= NLMSG_ALIGN(headlen
);
2718 skb
= nlmsg_new(len
, GFP_ATOMIC
);
2722 nlh
= nlmsg_put(skb
, c
->pid
, c
->seq
, c
->event
, headlen
, 0);
2726 p
= nlmsg_data(nlh
);
2727 if (c
->event
== XFRM_MSG_DELPOLICY
) {
2728 struct nlattr
*attr
;
2730 id
= nlmsg_data(nlh
);
2731 memset(id
, 0, sizeof(*id
));
2734 id
->index
= xp
->index
;
2736 memcpy(&id
->sel
, &xp
->selector
, sizeof(id
->sel
));
2738 attr
= nla_reserve(skb
, XFRMA_POLICY
, sizeof(*p
));
2745 copy_to_user_policy(xp
, p
, dir
);
2746 if (copy_to_user_tmpl(xp
, skb
) < 0)
2748 if (copy_to_user_policy_type(xp
->type
, skb
) < 0)
2751 if (xfrm_mark_put(skb
, &xp
->mark
))
2752 goto nla_put_failure
;
2754 nlmsg_end(skb
, nlh
);
2756 return nlmsg_multicast(net
->xfrm
.nlsk
, skb
, 0, XFRMNLGRP_POLICY
, GFP_ATOMIC
);
2764 static int xfrm_notify_policy_flush(const struct km_event
*c
)
2766 struct net
*net
= c
->net
;
2767 struct nlmsghdr
*nlh
;
2768 struct sk_buff
*skb
;
2770 skb
= nlmsg_new(userpolicy_type_attrsize(), GFP_ATOMIC
);
2774 nlh
= nlmsg_put(skb
, c
->pid
, c
->seq
, XFRM_MSG_FLUSHPOLICY
, 0, 0);
2777 if (copy_to_user_policy_type(c
->data
.type
, skb
) < 0)
2780 nlmsg_end(skb
, nlh
);
2782 return nlmsg_multicast(net
->xfrm
.nlsk
, skb
, 0, XFRMNLGRP_POLICY
, GFP_ATOMIC
);
2789 static int xfrm_send_policy_notify(struct xfrm_policy
*xp
, int dir
, const struct km_event
*c
)
2793 case XFRM_MSG_NEWPOLICY
:
2794 case XFRM_MSG_UPDPOLICY
:
2795 case XFRM_MSG_DELPOLICY
:
2796 return xfrm_notify_policy(xp
, dir
, c
);
2797 case XFRM_MSG_FLUSHPOLICY
:
2798 return xfrm_notify_policy_flush(c
);
2799 case XFRM_MSG_POLEXPIRE
:
2800 return xfrm_exp_policy_notify(xp
, dir
, c
);
2802 printk(KERN_NOTICE
"xfrm_user: Unknown Policy event %d\n",
2810 static inline size_t xfrm_report_msgsize(void)
2812 return NLMSG_ALIGN(sizeof(struct xfrm_user_report
));
2815 static int build_report(struct sk_buff
*skb
, u8 proto
,
2816 struct xfrm_selector
*sel
, xfrm_address_t
*addr
)
2818 struct xfrm_user_report
*ur
;
2819 struct nlmsghdr
*nlh
;
2821 nlh
= nlmsg_put(skb
, 0, 0, XFRM_MSG_REPORT
, sizeof(*ur
), 0);
2825 ur
= nlmsg_data(nlh
);
2827 memcpy(&ur
->sel
, sel
, sizeof(ur
->sel
));
2830 NLA_PUT(skb
, XFRMA_COADDR
, sizeof(*addr
), addr
);
2832 return nlmsg_end(skb
, nlh
);
2835 nlmsg_cancel(skb
, nlh
);
2839 static int xfrm_send_report(struct net
*net
, u8 proto
,
2840 struct xfrm_selector
*sel
, xfrm_address_t
*addr
)
2842 struct sk_buff
*skb
;
2844 skb
= nlmsg_new(xfrm_report_msgsize(), GFP_ATOMIC
);
2848 if (build_report(skb
, proto
, sel
, addr
) < 0)
2851 return nlmsg_multicast(net
->xfrm
.nlsk
, skb
, 0, XFRMNLGRP_REPORT
, GFP_ATOMIC
);
2854 static inline size_t xfrm_mapping_msgsize(void)
2856 return NLMSG_ALIGN(sizeof(struct xfrm_user_mapping
));
2859 static int build_mapping(struct sk_buff
*skb
, struct xfrm_state
*x
,
2860 xfrm_address_t
*new_saddr
, __be16 new_sport
)
2862 struct xfrm_user_mapping
*um
;
2863 struct nlmsghdr
*nlh
;
2865 nlh
= nlmsg_put(skb
, 0, 0, XFRM_MSG_MAPPING
, sizeof(*um
), 0);
2869 um
= nlmsg_data(nlh
);
2871 memcpy(&um
->id
.daddr
, &x
->id
.daddr
, sizeof(um
->id
.daddr
));
2872 um
->id
.spi
= x
->id
.spi
;
2873 um
->id
.family
= x
->props
.family
;
2874 um
->id
.proto
= x
->id
.proto
;
2875 memcpy(&um
->new_saddr
, new_saddr
, sizeof(um
->new_saddr
));
2876 memcpy(&um
->old_saddr
, &x
->props
.saddr
, sizeof(um
->old_saddr
));
2877 um
->new_sport
= new_sport
;
2878 um
->old_sport
= x
->encap
->encap_sport
;
2879 um
->reqid
= x
->props
.reqid
;
2881 return nlmsg_end(skb
, nlh
);
2884 static int xfrm_send_mapping(struct xfrm_state
*x
, xfrm_address_t
*ipaddr
,
2887 struct net
*net
= xs_net(x
);
2888 struct sk_buff
*skb
;
2890 if (x
->id
.proto
!= IPPROTO_ESP
)
2896 skb
= nlmsg_new(xfrm_mapping_msgsize(), GFP_ATOMIC
);
2900 if (build_mapping(skb
, x
, ipaddr
, sport
) < 0)
2903 return nlmsg_multicast(net
->xfrm
.nlsk
, skb
, 0, XFRMNLGRP_MAPPING
, GFP_ATOMIC
);
2906 static struct xfrm_mgr netlink_mgr
= {
2908 .notify
= xfrm_send_state_notify
,
2909 .acquire
= xfrm_send_acquire
,
2910 .compile_policy
= xfrm_compile_policy
,
2911 .notify_policy
= xfrm_send_policy_notify
,
2912 .report
= xfrm_send_report
,
2913 .migrate
= xfrm_send_migrate
,
2914 .new_mapping
= xfrm_send_mapping
,
2917 static int __net_init
xfrm_user_net_init(struct net
*net
)
2921 nlsk
= netlink_kernel_create(net
, NETLINK_XFRM
, XFRMNLGRP_MAX
,
2922 xfrm_netlink_rcv
, NULL
, THIS_MODULE
);
2925 net
->xfrm
.nlsk_stash
= nlsk
; /* Don't set to NULL */
2926 rcu_assign_pointer(net
->xfrm
.nlsk
, nlsk
);
2930 static void __net_exit
xfrm_user_net_exit(struct list_head
*net_exit_list
)
2933 list_for_each_entry(net
, net_exit_list
, exit_list
)
2934 rcu_assign_pointer(net
->xfrm
.nlsk
, NULL
);
2936 list_for_each_entry(net
, net_exit_list
, exit_list
)
2937 netlink_kernel_release(net
->xfrm
.nlsk_stash
);
2940 static struct pernet_operations xfrm_user_net_ops
= {
2941 .init
= xfrm_user_net_init
,
2942 .exit_batch
= xfrm_user_net_exit
,
2945 static int __init
xfrm_user_init(void)
2949 printk(KERN_INFO
"Initializing XFRM netlink socket\n");
2951 rv
= register_pernet_subsys(&xfrm_user_net_ops
);
2954 rv
= xfrm_register_km(&netlink_mgr
);
2956 unregister_pernet_subsys(&xfrm_user_net_ops
);
2960 static void __exit
xfrm_user_exit(void)
2962 xfrm_unregister_km(&netlink_mgr
);
2963 unregister_pernet_subsys(&xfrm_user_net_ops
);
2966 module_init(xfrm_user_init
);
2967 module_exit(xfrm_user_exit
);
2968 MODULE_LICENSE("GPL");
2969 MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK
, NETLINK_XFRM
);