MCPcopy Create free account
hub / github.com/F-Stack/f-stack / key_spdacquire

Function key_spdacquire

freebsd/netipsec/key.c:2424–2470  ·  view source on GitHub ↗

* SADB_X_SPDACQUIRE processing. * Acquire policy and SA(s) for a *OUTBOUND* packet. * send * * to KMD, and expect to receive * with SADB_X_SPDACQUIRE if error occurred, * or * * with SADB_X_SPDUPDATE from KMD by PF_KEY. * policy(*) is without policy requests. * * 0 : succeed * others: error number */

Source from the content-addressed store, hash-verified

2422 * others: error number
2423 */
2424int
2425key_spdacquire(struct secpolicy *sp)
2426{
2427 struct mbuf *result = NULL, *m;
2428 struct secspacq *newspacq;
2429
2430 IPSEC_ASSERT(sp != NULL, ("null secpolicy"));
2431 IPSEC_ASSERT(sp->req == NULL, ("policy exists"));
2432 IPSEC_ASSERT(sp->policy == IPSEC_POLICY_IPSEC,
2433 ("policy not IPSEC %u", sp->policy));
2434
2435 /* Get an entry to check whether sent message or not. */
2436 newspacq = key_getspacq(&sp->spidx);
2437 if (newspacq != NULL) {
2438 if (V_key_blockacq_count < newspacq->count) {
2439 /* reset counter and do send message. */
2440 newspacq->count = 0;
2441 } else {
2442 /* increment counter and do nothing. */
2443 newspacq->count++;
2444 SPACQ_UNLOCK();
2445 return (0);
2446 }
2447 SPACQ_UNLOCK();
2448 } else {
2449 /* make new entry for blocking to send SADB_ACQUIRE. */
2450 newspacq = key_newspacq(&sp->spidx);
2451 if (newspacq == NULL)
2452 return ENOBUFS;
2453 }
2454
2455 /* create new sadb_msg to reply. */
2456 m = key_setsadbmsg(SADB_X_SPDACQUIRE, 0, 0, 0, 0, 0);
2457 if (!m)
2458 return ENOBUFS;
2459
2460 result = m;
2461
2462 result->m_pkthdr.len = 0;
2463 for (m = result; m; m = m->m_next)
2464 result->m_pkthdr.len += m->m_len;
2465
2466 mtod(result, struct sadb_msg *)->sadb_msg_len =
2467 PFKEY_UNIT64(result->m_pkthdr.len);
2468
2469 return key_sendup_mbuf(NULL, m, KEY_SENDUP_REGISTERED);
2470}
2471
2472/*
2473 * SADB_SPDFLUSH processing

Callers

nothing calls this directly

Calls 4

key_getspacqFunction · 0.85
key_newspacqFunction · 0.85
key_setsadbmsgFunction · 0.85
key_sendup_mbufFunction · 0.85

Tested by

no test coverage detected