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

Function key_attach

freebsd/netipsec/keysock.c:279–316  ·  view source on GitHub ↗

* key_attach() * derived from net/rtsock.c:rts_attach() */

Source from the content-addressed store, hash-verified

277 * derived from net/rtsock.c:rts_attach()
278 */
279static int
280key_attach(struct socket *so, int proto, struct thread *td)
281{
282 struct keycb *kp;
283 int error;
284
285 KASSERT(so->so_pcb == NULL, ("key_attach: so_pcb != NULL"));
286
287 if (td != NULL) {
288 error = priv_check(td, PRIV_NET_RAW);
289 if (error)
290 return error;
291 }
292
293 /* XXX */
294 kp = malloc(sizeof *kp, M_PCB, M_WAITOK | M_ZERO);
295 if (kp == NULL)
296 return ENOBUFS;
297
298 so->so_pcb = (caddr_t)kp;
299 error = raw_attach(so, proto);
300 kp = (struct keycb *)sotorawcb(so);
301 if (error) {
302 free(kp, M_PCB);
303 so->so_pcb = (caddr_t) 0;
304 return error;
305 }
306
307 kp->kp_promisc = kp->kp_registered = 0;
308
309 if (kp->kp_raw.rcb_proto.sp_protocol == PF_KEY) /* XXX: AF_KEY */
310 V_key_cb.key_count++;
311 V_key_cb.any_count++;
312 soisconnected(so);
313 so->so_options |= SO_USELOOPBACK;
314
315 return 0;
316}
317
318/*
319 * key_bind()

Callers

nothing calls this directly

Calls 5

mallocFunction · 0.85
raw_attachFunction · 0.85
soisconnectedFunction · 0.85
priv_checkFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected