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

Function key_allocsp

freebsd/netipsec/key.c:881–949  ·  view source on GitHub ↗

* allocating a SP for OUTBOUND or INBOUND packet. * Must call key_freesp() later. * OUT: NULL: not found * others: found and return the pointer. */

Source from the content-addressed store, hash-verified

879 * others: found and return the pointer.
880 */
881struct secpolicy *
882key_allocsp(struct secpolicyindex *spidx, u_int dir)
883{
884 struct spdcache_entry *entry, *lastentry, *tmpentry;
885 struct secpolicy *sp;
886 uint32_t hashv;
887 int nb_entries;
888
889 if (!SPDCACHE_ACTIVE()) {
890 sp = key_do_allocsp(spidx, dir);
891 goto out;
892 }
893
894 hashv = SPDCACHE_HASHVAL(spidx);
895 SPDCACHE_LOCK(hashv);
896 nb_entries = 0;
897 LIST_FOREACH_SAFE(entry, &V_spdcachehashtbl[hashv], chain, tmpentry) {
898 /* Removed outdated entries */
899 if (entry->sp != NULL &&
900 entry->sp->state == IPSEC_SPSTATE_DEAD) {
901 LIST_REMOVE(entry, chain);
902 spdcache_entry_free(entry);
903 continue;
904 }
905
906 nb_entries++;
907 if (!key_cmpspidx_exactly(&entry->spidx, spidx)) {
908 lastentry = entry;
909 continue;
910 }
911
912 sp = entry->sp;
913 if (entry->sp != NULL)
914 SP_ADDREF(sp);
915
916 /* IPSECSTAT_INC(ips_spdcache_hits); */
917
918 SPDCACHE_UNLOCK(hashv);
919 goto out;
920 }
921
922 /* IPSECSTAT_INC(ips_spdcache_misses); */
923
924 sp = key_do_allocsp(spidx, dir);
925 entry = spdcache_entry_alloc(spidx, sp);
926 if (entry != NULL) {
927 if (nb_entries >= SPDCACHE_MAX_ENTRIES_PER_HASH) {
928 LIST_REMOVE(lastentry, chain);
929 spdcache_entry_free(lastentry);
930 }
931
932 LIST_INSERT_HEAD(&V_spdcachehashtbl[hashv], entry, chain);
933 }
934
935 SPDCACHE_UNLOCK(hashv);
936
937out:
938 if (sp != NULL) { /* found a SPD entry */

Callers 3

ipsec4_getpolicyFunction · 0.85
ipsec6_getpolicyFunction · 0.85
ipsec_hdrsiz_inpcbFunction · 0.85

Calls 7

key_do_allocspFunction · 0.85
spdcache_entry_freeFunction · 0.85
key_cmpspidx_exactlyFunction · 0.85
spdcache_entry_allocFunction · 0.85
kdebug_secpolicyFunction · 0.85
kdebug_secpolicyindexFunction · 0.85
printfFunction · 0.50

Tested by

no test coverage detected