* key_attach() * derived from net/rtsock.c:rts_attach() */
| 277 | * derived from net/rtsock.c:rts_attach() |
| 278 | */ |
| 279 | static int |
| 280 | key_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() |
nothing calls this directly
no test coverage detected