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

Function key_register_ifnet

freebsd/netipsec/key.c:1263–1305  ·  view source on GitHub ↗

* Insert a bunch of VTI secpolicies into the SPDB. * We keep VTI policies in the separate list due to following reasons: * 1) they should be immutable to user's or some deamon's attempts to * delete. The only way delete such policies - destroy or unconfigure * corresponding virtual inteface. * 2) such policies have traffic selector that matches all traffic per * address family. * S

Source from the content-addressed store, hash-verified

1261 * policies order.
1262 */
1263int
1264key_register_ifnet(struct secpolicy **spp, u_int count)
1265{
1266 struct mbuf *m;
1267 u_int i;
1268
1269 SPTREE_WLOCK();
1270 /*
1271 * First of try to acquire id for each SP.
1272 */
1273 for (i = 0; i < count; i++) {
1274 IPSEC_ASSERT(spp[i]->spidx.dir == IPSEC_DIR_INBOUND ||
1275 spp[i]->spidx.dir == IPSEC_DIR_OUTBOUND,
1276 ("invalid direction %u", spp[i]->spidx.dir));
1277
1278 if ((spp[i]->id = key_getnewspid()) == 0) {
1279 SPTREE_WUNLOCK();
1280 return (EAGAIN);
1281 }
1282 }
1283 for (i = 0; i < count; i++) {
1284 TAILQ_INSERT_TAIL(&V_sptree_ifnet[spp[i]->spidx.dir],
1285 spp[i], chain);
1286 /*
1287 * NOTE: despite the fact that we keep VTI SP in the
1288 * separate list, SPHASH contains policies from both
1289 * sources. Thus SADB_X_SPDGET will correctly return
1290 * SP by id, because it uses SPHASH for lookups.
1291 */
1292 LIST_INSERT_HEAD(SPHASH_HASH(spp[i]->id), spp[i], idhash);
1293 spp[i]->state = IPSEC_SPSTATE_IFNET;
1294 }
1295 SPTREE_WUNLOCK();
1296 /*
1297 * Notify user processes about new SP.
1298 */
1299 for (i = 0; i < count; i++) {
1300 m = key_setdumpsp(spp[i], SADB_X_SPDADD, 0, 0);
1301 if (m != NULL)
1302 key_sendup_mbuf(NULL, m, KEY_SENDUP_ALL);
1303 }
1304 return (0);
1305}
1306
1307void
1308key_unregister_ifnet(struct secpolicy **spp, u_int count)

Callers 1

ipsec_set_tunnelFunction · 0.85

Calls 3

key_getnewspidFunction · 0.85
key_setdumpspFunction · 0.85
key_sendup_mbufFunction · 0.85

Tested by

no test coverage detected