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

Function key_getnewspid

freebsd/netipsec/key.c:2118–2144  ·  view source on GitHub ↗

* get new policy id. * OUT: * 0: failure. * others: success. */

Source from the content-addressed store, hash-verified

2116 * others: success.
2117 */
2118static uint32_t
2119key_getnewspid(void)
2120{
2121 struct secpolicy *sp;
2122 uint32_t newid = 0;
2123 int count = V_key_spi_trycnt; /* XXX */
2124
2125 SPTREE_WLOCK_ASSERT();
2126 while (count--) {
2127 if (V_policy_id == ~0) /* overflowed */
2128 newid = V_policy_id = 1;
2129 else
2130 newid = ++V_policy_id;
2131 LIST_FOREACH(sp, SPHASH_HASH(newid), idhash) {
2132 if (sp->id == newid)
2133 break;
2134 }
2135 if (sp == NULL)
2136 break;
2137 }
2138 if (count == 0 || newid == 0) {
2139 ipseclog((LOG_DEBUG, "%s: failed to allocate policy id.\n",
2140 __func__));
2141 return (0);
2142 }
2143 return (newid);
2144}
2145
2146/*
2147 * SADB_SPDDELETE processing

Callers 2

key_register_ifnetFunction · 0.85
key_spdaddFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected