* get new policy id. * OUT: * 0: failure. * others: success. */
| 2116 | * others: success. |
| 2117 | */ |
| 2118 | static uint32_t |
| 2119 | key_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 |
no outgoing calls
no test coverage detected