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

Function key_spddelete2

freebsd/netipsec/key.c:2269–2356  ·  view source on GitHub ↗

* SADB_SPDDELETE2 processing * receive * * from the user(?), and set SADB_SASTATE_DEAD, * and send, * * to the ikmpd. * policy(*) including direction of policy. * * m will always be freed. */

Source from the content-addressed store, hash-verified

2267 * m will always be freed.
2268 */
2269static int
2270key_spddelete2(struct socket *so, struct mbuf *m,
2271 const struct sadb_msghdr *mhp)
2272{
2273 struct secpolicy *sp;
2274 uint32_t id;
2275
2276 IPSEC_ASSERT(so != NULL, ("null socket"));
2277 IPSEC_ASSERT(m != NULL, ("null mbuf"));
2278 IPSEC_ASSERT(mhp != NULL, ("null msghdr"));
2279 IPSEC_ASSERT(mhp->msg != NULL, ("null msg"));
2280
2281 if (SADB_CHECKHDR(mhp, SADB_X_EXT_POLICY) ||
2282 SADB_CHECKLEN(mhp, SADB_X_EXT_POLICY)) {
2283 ipseclog((LOG_DEBUG, "%s: invalid message is passed.\n",
2284 __func__));
2285 return key_senderror(so, m, EINVAL);
2286 }
2287
2288 id = ((struct sadb_x_policy *)
2289 mhp->ext[SADB_X_EXT_POLICY])->sadb_x_policy_id;
2290
2291 /* Is there SP in SPD ? */
2292 if ((sp = key_getspbyid(id)) == NULL) {
2293 ipseclog((LOG_DEBUG, "%s: no SP found for id %u.\n",
2294 __func__, id));
2295 return key_senderror(so, m, EINVAL);
2296 }
2297
2298 KEYDBG(KEY_STAMP,
2299 printf("%s: SP(%p)\n", __func__, sp));
2300 KEYDBG(KEY_DATA, kdebug_secpolicy(sp));
2301 key_unlink(sp);
2302 if (sp->state != IPSEC_SPSTATE_DEAD) {
2303 ipseclog((LOG_DEBUG, "%s: failed to delete SP with id %u.\n",
2304 __func__, id));
2305 key_freesp(&sp);
2306 return (key_senderror(so, m, EACCES));
2307 }
2308 key_freesp(&sp);
2309
2310 {
2311 struct mbuf *n, *nn;
2312 struct sadb_msg *newmsg;
2313 int off, len;
2314
2315 /* create new sadb_msg to reply. */
2316 len = PFKEY_ALIGN8(sizeof(struct sadb_msg));
2317
2318 MGETHDR(n, M_NOWAIT, MT_DATA);
2319 if (n && len > MHLEN) {
2320 if (!(MCLGET(n, M_NOWAIT))) {
2321 m_freem(n);
2322 n = NULL;
2323 }
2324 }
2325 if (!n)
2326 return key_senderror(so, m, ENOBUFS);

Callers

nothing calls this directly

Calls 10

key_senderrorFunction · 0.85
key_getspbyidFunction · 0.85
kdebug_secpolicyFunction · 0.85
key_unlinkFunction · 0.85
key_freespFunction · 0.85
m_copydataFunction · 0.85
m_copymFunction · 0.85
key_sendup_mbufFunction · 0.85
printfFunction · 0.50
m_freemFunction · 0.50

Tested by

no test coverage detected