diff options
Diffstat (limited to 'net/xfrm/xfrm_user.c')
-rw-r--r-- | net/xfrm/xfrm_user.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c index e230ba5328d..d6e6527fd8d 100644 --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c | |||
@@ -1232,6 +1232,58 @@ static int xfrm_flush_policy(struct sk_buff *skb, struct nlmsghdr *nlh, void **x | |||
1232 | return 0; | 1232 | return 0; |
1233 | } | 1233 | } |
1234 | 1234 | ||
1235 | static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh, void **xfrma) | ||
1236 | { | ||
1237 | struct xfrm_policy *xp; | ||
1238 | struct xfrm_user_tmpl *ut; | ||
1239 | int i; | ||
1240 | struct rtattr *rt = xfrma[XFRMA_TMPL-1]; | ||
1241 | |||
1242 | struct xfrm_user_acquire *ua = NLMSG_DATA(nlh); | ||
1243 | struct xfrm_state *x = xfrm_state_alloc(); | ||
1244 | int err = -ENOMEM; | ||
1245 | |||
1246 | if (!x) | ||
1247 | return err; | ||
1248 | |||
1249 | err = verify_newpolicy_info(&ua->policy); | ||
1250 | if (err) { | ||
1251 | printk("BAD policy passed\n"); | ||
1252 | kfree(x); | ||
1253 | return err; | ||
1254 | } | ||
1255 | |||
1256 | /* build an XP */ | ||
1257 | xp = xfrm_policy_construct(&ua->policy, (struct rtattr **) xfrma, &err); if (!xp) { | ||
1258 | kfree(x); | ||
1259 | return err; | ||
1260 | } | ||
1261 | |||
1262 | memcpy(&x->id, &ua->id, sizeof(ua->id)); | ||
1263 | memcpy(&x->props.saddr, &ua->saddr, sizeof(ua->saddr)); | ||
1264 | memcpy(&x->sel, &ua->sel, sizeof(ua->sel)); | ||
1265 | |||
1266 | ut = RTA_DATA(rt); | ||
1267 | /* extract the templates and for each call km_key */ | ||
1268 | for (i = 0; i < xp->xfrm_nr; i++, ut++) { | ||
1269 | struct xfrm_tmpl *t = &xp->xfrm_vec[i]; | ||
1270 | memcpy(&x->id, &t->id, sizeof(x->id)); | ||
1271 | x->props.mode = t->mode; | ||
1272 | x->props.reqid = t->reqid; | ||
1273 | x->props.family = ut->family; | ||
1274 | t->aalgos = ua->aalgos; | ||
1275 | t->ealgos = ua->ealgos; | ||
1276 | t->calgos = ua->calgos; | ||
1277 | err = km_query(x, t, xp); | ||
1278 | |||
1279 | } | ||
1280 | |||
1281 | kfree(x); | ||
1282 | kfree(xp); | ||
1283 | |||
1284 | return 0; | ||
1285 | } | ||
1286 | |||
1235 | 1287 | ||
1236 | #define XMSGSIZE(type) NLMSG_LENGTH(sizeof(struct type)) | 1288 | #define XMSGSIZE(type) NLMSG_LENGTH(sizeof(struct type)) |
1237 | 1289 | ||
@@ -1243,6 +1295,7 @@ static const int xfrm_msg_min[XFRM_NR_MSGTYPES] = { | |||
1243 | [XFRM_MSG_DELPOLICY - XFRM_MSG_BASE] = XMSGSIZE(xfrm_userpolicy_id), | 1295 | [XFRM_MSG_DELPOLICY - XFRM_MSG_BASE] = XMSGSIZE(xfrm_userpolicy_id), |
1244 | [XFRM_MSG_GETPOLICY - XFRM_MSG_BASE] = XMSGSIZE(xfrm_userpolicy_id), | 1296 | [XFRM_MSG_GETPOLICY - XFRM_MSG_BASE] = XMSGSIZE(xfrm_userpolicy_id), |
1245 | [XFRM_MSG_ALLOCSPI - XFRM_MSG_BASE] = XMSGSIZE(xfrm_userspi_info), | 1297 | [XFRM_MSG_ALLOCSPI - XFRM_MSG_BASE] = XMSGSIZE(xfrm_userspi_info), |
1298 | [XFRM_MSG_ACQUIRE - XFRM_MSG_BASE] = XMSGSIZE(xfrm_user_acquire), | ||
1246 | [XFRM_MSG_UPDPOLICY - XFRM_MSG_BASE] = XMSGSIZE(xfrm_userpolicy_info), | 1299 | [XFRM_MSG_UPDPOLICY - XFRM_MSG_BASE] = XMSGSIZE(xfrm_userpolicy_info), |
1247 | [XFRM_MSG_UPDSA - XFRM_MSG_BASE] = XMSGSIZE(xfrm_usersa_info), | 1300 | [XFRM_MSG_UPDSA - XFRM_MSG_BASE] = XMSGSIZE(xfrm_usersa_info), |
1248 | [XFRM_MSG_FLUSHSA - XFRM_MSG_BASE] = XMSGSIZE(xfrm_usersa_flush), | 1301 | [XFRM_MSG_FLUSHSA - XFRM_MSG_BASE] = XMSGSIZE(xfrm_usersa_flush), |
@@ -1266,6 +1319,7 @@ static struct xfrm_link { | |||
1266 | [XFRM_MSG_GETPOLICY - XFRM_MSG_BASE] = { .doit = xfrm_get_policy, | 1319 | [XFRM_MSG_GETPOLICY - XFRM_MSG_BASE] = { .doit = xfrm_get_policy, |
1267 | .dump = xfrm_dump_policy }, | 1320 | .dump = xfrm_dump_policy }, |
1268 | [XFRM_MSG_ALLOCSPI - XFRM_MSG_BASE] = { .doit = xfrm_alloc_userspi }, | 1321 | [XFRM_MSG_ALLOCSPI - XFRM_MSG_BASE] = { .doit = xfrm_alloc_userspi }, |
1322 | [XFRM_MSG_ACQUIRE - XFRM_MSG_BASE] = { .doit = xfrm_add_acquire }, | ||
1269 | [XFRM_MSG_UPDPOLICY - XFRM_MSG_BASE] = { .doit = xfrm_add_policy }, | 1323 | [XFRM_MSG_UPDPOLICY - XFRM_MSG_BASE] = { .doit = xfrm_add_policy }, |
1270 | [XFRM_MSG_UPDSA - XFRM_MSG_BASE] = { .doit = xfrm_add_sa }, | 1324 | [XFRM_MSG_UPDSA - XFRM_MSG_BASE] = { .doit = xfrm_add_sa }, |
1271 | [XFRM_MSG_FLUSHSA - XFRM_MSG_BASE] = { .doit = xfrm_flush_sa }, | 1325 | [XFRM_MSG_FLUSHSA - XFRM_MSG_BASE] = { .doit = xfrm_flush_sa }, |