* SADB_SPDEXPIRE processing * send * * to KMD by PF_KEY. * * OUT: 0 : succeed * others : error number */
| 2725 | * others : error number |
| 2726 | */ |
| 2727 | static int |
| 2728 | key_spdexpire(struct secpolicy *sp) |
| 2729 | { |
| 2730 | struct sadb_lifetime *lt; |
| 2731 | struct mbuf *result = NULL, *m; |
| 2732 | int len, error = -1; |
| 2733 | |
| 2734 | IPSEC_ASSERT(sp != NULL, ("null secpolicy")); |
| 2735 | |
| 2736 | KEYDBG(KEY_STAMP, |
| 2737 | printf("%s: SP(%p)\n", __func__, sp)); |
| 2738 | KEYDBG(KEY_DATA, kdebug_secpolicy(sp)); |
| 2739 | |
| 2740 | /* set msg header */ |
| 2741 | m = key_setsadbmsg(SADB_X_SPDEXPIRE, 0, 0, 0, 0, 0); |
| 2742 | if (!m) { |
| 2743 | error = ENOBUFS; |
| 2744 | goto fail; |
| 2745 | } |
| 2746 | result = m; |
| 2747 | |
| 2748 | /* create lifetime extension (current and hard) */ |
| 2749 | len = PFKEY_ALIGN8(sizeof(*lt)) * 2; |
| 2750 | m = m_get2(len, M_NOWAIT, MT_DATA, 0); |
| 2751 | if (m == NULL) { |
| 2752 | error = ENOBUFS; |
| 2753 | goto fail; |
| 2754 | } |
| 2755 | m_align(m, len); |
| 2756 | m->m_len = len; |
| 2757 | bzero(mtod(m, caddr_t), len); |
| 2758 | lt = mtod(m, struct sadb_lifetime *); |
| 2759 | lt->sadb_lifetime_len = PFKEY_UNIT64(sizeof(struct sadb_lifetime)); |
| 2760 | lt->sadb_lifetime_exttype = SADB_EXT_LIFETIME_CURRENT; |
| 2761 | lt->sadb_lifetime_allocations = 0; |
| 2762 | lt->sadb_lifetime_bytes = 0; |
| 2763 | lt->sadb_lifetime_addtime = sp->created; |
| 2764 | lt->sadb_lifetime_usetime = sp->lastused; |
| 2765 | lt = (struct sadb_lifetime *)(mtod(m, caddr_t) + len / 2); |
| 2766 | lt->sadb_lifetime_len = PFKEY_UNIT64(sizeof(struct sadb_lifetime)); |
| 2767 | lt->sadb_lifetime_exttype = SADB_EXT_LIFETIME_HARD; |
| 2768 | lt->sadb_lifetime_allocations = 0; |
| 2769 | lt->sadb_lifetime_bytes = 0; |
| 2770 | lt->sadb_lifetime_addtime = sp->lifetime; |
| 2771 | lt->sadb_lifetime_usetime = sp->validtime; |
| 2772 | m_cat(result, m); |
| 2773 | |
| 2774 | /* set sadb_address for source */ |
| 2775 | m = key_setsadbaddr(SADB_EXT_ADDRESS_SRC, |
| 2776 | &sp->spidx.src.sa, |
| 2777 | sp->spidx.prefs, sp->spidx.ul_proto); |
| 2778 | if (!m) { |
| 2779 | error = ENOBUFS; |
| 2780 | goto fail; |
| 2781 | } |
| 2782 | m_cat(result, m); |
| 2783 | |
| 2784 | /* set sadb_address for destination */ |
no test coverage detected