af_key.c (658b219e9379d75fbdc578b9630b598098471258) af_key.c (050f009e16f908932070313c1745d09dc69fd62b)
1/*
2 * net/key/af_key.c An implementation of PF_KEYv2 sockets.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *

--- 641 unchanged lines hidden (view full) ---

650 return XFRM_MODE_TUNNEL;
651 case IPSEC_MODE_BEET:
652 return XFRM_MODE_BEET;
653 default:
654 return -1;
655 }
656}
657
1/*
2 * net/key/af_key.c An implementation of PF_KEYv2 sockets.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *

--- 641 unchanged lines hidden (view full) ---

650 return XFRM_MODE_TUNNEL;
651 case IPSEC_MODE_BEET:
652 return XFRM_MODE_BEET;
653 default:
654 return -1;
655 }
656}
657
658static struct sk_buff * pfkey_xfrm_state2msg(struct xfrm_state *x, int add_keys, int hsc)
658static struct sk_buff *__pfkey_xfrm_state2msg(struct xfrm_state *x,
659 int add_keys, int hsc)
659{
660 struct sk_buff *skb;
661 struct sadb_msg *hdr;
662 struct sadb_sa *sa;
663 struct sadb_lifetime *lifetime;
664 struct sadb_address *addr;
665 struct sadb_key *key;
666 struct sadb_x_sa2 *sa2;

--- 337 unchanged lines hidden (view full) ---

1004 sec_ctx->sadb_x_ctx_len = xfrm_ctx->ctx_len;
1005 memcpy(sec_ctx + 1, xfrm_ctx->ctx_str,
1006 xfrm_ctx->ctx_len);
1007 }
1008
1009 return skb;
1010}
1011
660{
661 struct sk_buff *skb;
662 struct sadb_msg *hdr;
663 struct sadb_sa *sa;
664 struct sadb_lifetime *lifetime;
665 struct sadb_address *addr;
666 struct sadb_key *key;
667 struct sadb_x_sa2 *sa2;

--- 337 unchanged lines hidden (view full) ---

1005 sec_ctx->sadb_x_ctx_len = xfrm_ctx->ctx_len;
1006 memcpy(sec_ctx + 1, xfrm_ctx->ctx_str,
1007 xfrm_ctx->ctx_len);
1008 }
1009
1010 return skb;
1011}
1012
1013
1014static inline struct sk_buff *pfkey_xfrm_state2msg(struct xfrm_state *x)
1015{
1016 struct sk_buff *skb;
1017
1018 spin_lock_bh(&x->lock);
1019 skb = __pfkey_xfrm_state2msg(x, 1, 3);
1020 spin_unlock_bh(&x->lock);
1021
1022 return skb;
1023}
1024
1025static inline struct sk_buff *pfkey_xfrm_state2msg_expire(struct xfrm_state *x,
1026 int hsc)
1027{
1028 return __pfkey_xfrm_state2msg(x, 0, hsc);
1029}
1030
1012static struct xfrm_state * pfkey_msg2xfrm_state(struct sadb_msg *hdr,
1013 void **ext_hdrs)
1014{
1015 struct xfrm_state *x;
1016 struct sadb_lifetime *lifetime;
1017 struct sadb_sa *sa;
1018 struct sadb_key *key;
1019 struct sadb_x_sec_ctx *sec_ctx;

--- 297 unchanged lines hidden (view full) ---

1317
1318 range = ext_hdrs[SADB_EXT_SPIRANGE-1];
1319 if (range) {
1320 min_spi = range->sadb_spirange_min;
1321 max_spi = range->sadb_spirange_max;
1322 }
1323
1324 err = xfrm_alloc_spi(x, min_spi, max_spi);
1031static struct xfrm_state * pfkey_msg2xfrm_state(struct sadb_msg *hdr,
1032 void **ext_hdrs)
1033{
1034 struct xfrm_state *x;
1035 struct sadb_lifetime *lifetime;
1036 struct sadb_sa *sa;
1037 struct sadb_key *key;
1038 struct sadb_x_sec_ctx *sec_ctx;

--- 297 unchanged lines hidden (view full) ---

1336
1337 range = ext_hdrs[SADB_EXT_SPIRANGE-1];
1338 if (range) {
1339 min_spi = range->sadb_spirange_min;
1340 max_spi = range->sadb_spirange_max;
1341 }
1342
1343 err = xfrm_alloc_spi(x, min_spi, max_spi);
1325 resp_skb = err ? ERR_PTR(err) : pfkey_xfrm_state2msg(x, 0, 3);
1344 resp_skb = err ? ERR_PTR(err) : pfkey_xfrm_state2msg(x);
1326
1327 if (IS_ERR(resp_skb)) {
1328 xfrm_state_put(x);
1329 return PTR_ERR(resp_skb);
1330 }
1331
1332 out_hdr = (struct sadb_msg *) resp_skb->data;
1333 out_hdr->sadb_msg_version = hdr->sadb_msg_version;

--- 73 unchanged lines hidden (view full) ---

1407 return 0;
1408}
1409
1410/* ADD/UPD/DEL */
1411static int key_notify_sa(struct xfrm_state *x, struct km_event *c)
1412{
1413 struct sk_buff *skb;
1414 struct sadb_msg *hdr;
1345
1346 if (IS_ERR(resp_skb)) {
1347 xfrm_state_put(x);
1348 return PTR_ERR(resp_skb);
1349 }
1350
1351 out_hdr = (struct sadb_msg *) resp_skb->data;
1352 out_hdr->sadb_msg_version = hdr->sadb_msg_version;

--- 73 unchanged lines hidden (view full) ---

1426 return 0;
1427}
1428
1429/* ADD/UPD/DEL */
1430static int key_notify_sa(struct xfrm_state *x, struct km_event *c)
1431{
1432 struct sk_buff *skb;
1433 struct sadb_msg *hdr;
1415 int hsc = 3;
1416
1434
1417 if (c->event == XFRM_MSG_DELSA)
1418 hsc = 0;
1435 skb = pfkey_xfrm_state2msg(x);
1419
1436
1420 skb = pfkey_xfrm_state2msg(x, 0, hsc);
1421
1422 if (IS_ERR(skb))
1423 return PTR_ERR(skb);
1424
1425 hdr = (struct sadb_msg *) skb->data;
1426 hdr->sadb_msg_version = PF_KEY_V2;
1427 hdr->sadb_msg_type = event2keytype(c->event);
1428 hdr->sadb_msg_satype = pfkey_proto2satype(x->id.proto);
1429 hdr->sadb_msg_errno = 0;

--- 94 unchanged lines hidden (view full) ---

1524 !present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC-1],
1525 ext_hdrs[SADB_EXT_ADDRESS_DST-1]))
1526 return -EINVAL;
1527
1528 x = pfkey_xfrm_state_lookup(hdr, ext_hdrs);
1529 if (x == NULL)
1530 return -ESRCH;
1531
1437 if (IS_ERR(skb))
1438 return PTR_ERR(skb);
1439
1440 hdr = (struct sadb_msg *) skb->data;
1441 hdr->sadb_msg_version = PF_KEY_V2;
1442 hdr->sadb_msg_type = event2keytype(c->event);
1443 hdr->sadb_msg_satype = pfkey_proto2satype(x->id.proto);
1444 hdr->sadb_msg_errno = 0;

--- 94 unchanged lines hidden (view full) ---

1539 !present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC-1],
1540 ext_hdrs[SADB_EXT_ADDRESS_DST-1]))
1541 return -EINVAL;
1542
1543 x = pfkey_xfrm_state_lookup(hdr, ext_hdrs);
1544 if (x == NULL)
1545 return -ESRCH;
1546
1532 out_skb = pfkey_xfrm_state2msg(x, 1, 3);
1547 out_skb = pfkey_xfrm_state2msg(x);
1533 proto = x->id.proto;
1534 xfrm_state_put(x);
1535 if (IS_ERR(out_skb))
1536 return PTR_ERR(out_skb);
1537
1538 out_hdr = (struct sadb_msg *) out_skb->data;
1539 out_hdr->sadb_msg_version = hdr->sadb_msg_version;
1540 out_hdr->sadb_msg_type = SADB_DUMP;

--- 163 unchanged lines hidden (view full) ---

1704};
1705
1706static int dump_sa(struct xfrm_state *x, int count, void *ptr)
1707{
1708 struct pfkey_dump_data *data = ptr;
1709 struct sk_buff *out_skb;
1710 struct sadb_msg *out_hdr;
1711
1548 proto = x->id.proto;
1549 xfrm_state_put(x);
1550 if (IS_ERR(out_skb))
1551 return PTR_ERR(out_skb);
1552
1553 out_hdr = (struct sadb_msg *) out_skb->data;
1554 out_hdr->sadb_msg_version = hdr->sadb_msg_version;
1555 out_hdr->sadb_msg_type = SADB_DUMP;

--- 163 unchanged lines hidden (view full) ---

1719};
1720
1721static int dump_sa(struct xfrm_state *x, int count, void *ptr)
1722{
1723 struct pfkey_dump_data *data = ptr;
1724 struct sk_buff *out_skb;
1725 struct sadb_msg *out_hdr;
1726
1712 out_skb = pfkey_xfrm_state2msg(x, 1, 3);
1727 out_skb = pfkey_xfrm_state2msg(x);
1713 if (IS_ERR(out_skb))
1714 return PTR_ERR(out_skb);
1715
1716 out_hdr = (struct sadb_msg *) out_skb->data;
1717 out_hdr->sadb_msg_version = data->hdr->sadb_msg_version;
1718 out_hdr->sadb_msg_type = SADB_DUMP;
1719 out_hdr->sadb_msg_satype = pfkey_proto2satype(x->id.proto);
1720 out_hdr->sadb_msg_errno = 0;

--- 1184 unchanged lines hidden (view full) ---

2905 int hsc;
2906
2907 hard = c->data.hard;
2908 if (hard)
2909 hsc = 2;
2910 else
2911 hsc = 1;
2912
1728 if (IS_ERR(out_skb))
1729 return PTR_ERR(out_skb);
1730
1731 out_hdr = (struct sadb_msg *) out_skb->data;
1732 out_hdr->sadb_msg_version = data->hdr->sadb_msg_version;
1733 out_hdr->sadb_msg_type = SADB_DUMP;
1734 out_hdr->sadb_msg_satype = pfkey_proto2satype(x->id.proto);
1735 out_hdr->sadb_msg_errno = 0;

--- 1184 unchanged lines hidden (view full) ---

2920 int hsc;
2921
2922 hard = c->data.hard;
2923 if (hard)
2924 hsc = 2;
2925 else
2926 hsc = 1;
2927
2913 out_skb = pfkey_xfrm_state2msg(x, 0, hsc);
2928 out_skb = pfkey_xfrm_state2msg_expire(x, hsc);
2914 if (IS_ERR(out_skb))
2915 return PTR_ERR(out_skb);
2916
2917 out_hdr = (struct sadb_msg *) out_skb->data;
2918 out_hdr->sadb_msg_version = PF_KEY_V2;
2919 out_hdr->sadb_msg_type = SADB_EXPIRE;
2920 out_hdr->sadb_msg_satype = pfkey_proto2satype(x->id.proto);
2921 out_hdr->sadb_msg_errno = 0;

--- 896 unchanged lines hidden ---
2929 if (IS_ERR(out_skb))
2930 return PTR_ERR(out_skb);
2931
2932 out_hdr = (struct sadb_msg *) out_skb->data;
2933 out_hdr->sadb_msg_version = PF_KEY_V2;
2934 out_hdr->sadb_msg_type = SADB_EXPIRE;
2935 out_hdr->sadb_msg_satype = pfkey_proto2satype(x->id.proto);
2936 out_hdr->sadb_msg_errno = 0;

--- 896 unchanged lines hidden ---