| 357 | } |
| 358 | |
| 359 | static int |
| 360 | ipsec_get_pcbpolicy(struct inpcb *inp, void *request, size_t *len) |
| 361 | { |
| 362 | struct sadb_x_policy *xpl; |
| 363 | struct secpolicy *sp; |
| 364 | int error, flags; |
| 365 | |
| 366 | xpl = (struct sadb_x_policy *)request; |
| 367 | |
| 368 | INP_RLOCK(inp); |
| 369 | flags = inp->inp_sp->flags; |
| 370 | /* Select direction. */ |
| 371 | switch (xpl->sadb_x_policy_dir) { |
| 372 | case IPSEC_DIR_INBOUND: |
| 373 | sp = inp->inp_sp->sp_in; |
| 374 | flags &= INP_INBOUND_POLICY; |
| 375 | break; |
| 376 | case IPSEC_DIR_OUTBOUND: |
| 377 | sp = inp->inp_sp->sp_out; |
| 378 | flags &= INP_OUTBOUND_POLICY; |
| 379 | break; |
| 380 | default: |
| 381 | INP_RUNLOCK(inp); |
| 382 | ipseclog((LOG_ERR, "%s: invalid direction=%u\n", __func__, |
| 383 | xpl->sadb_x_policy_dir)); |
| 384 | return (EINVAL); |
| 385 | } |
| 386 | |
| 387 | if (flags == 0) { |
| 388 | /* Return ENTRUST policy */ |
| 389 | INP_RUNLOCK(inp); |
| 390 | xpl->sadb_x_policy_exttype = SADB_X_EXT_POLICY; |
| 391 | xpl->sadb_x_policy_type = IPSEC_POLICY_ENTRUST; |
| 392 | xpl->sadb_x_policy_id = 0; |
| 393 | xpl->sadb_x_policy_priority = 0; |
| 394 | xpl->sadb_x_policy_len = PFKEY_UNIT64(sizeof(*xpl)); |
| 395 | *len = sizeof(*xpl); |
| 396 | return (0); |
| 397 | } |
| 398 | |
| 399 | IPSEC_ASSERT(sp != NULL, |
| 400 | ("sp is NULL, but flags is 0x%04x", inp->inp_sp->flags)); |
| 401 | |
| 402 | key_addref(sp); |
| 403 | INP_RUNLOCK(inp); |
| 404 | error = key_sp2msg(sp, request, len); |
| 405 | key_freesp(&sp); |
| 406 | if (error == EINVAL) |
| 407 | return (error); |
| 408 | /* |
| 409 | * We return "success", but user should check *len. |
| 410 | * *len will be set to size of valid data and |
| 411 | * sadb_x_policy_len will contain needed size. |
| 412 | */ |
| 413 | return (0); |
| 414 | } |
| 415 | |
| 416 | /* Handle socket option control request for PCB */ |
no test coverage detected