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

Function sctp6_getcred

freebsd/netinet6/sctp6_usrreq.c:396–458  ·  view source on GitHub ↗

* this routine can probably be collasped into the one in sctp_userreq.c * since they do the same thing and now we lookup with a sockaddr */

Source from the content-addressed store, hash-verified

394 * since they do the same thing and now we lookup with a sockaddr
395 */
396static int
397sctp6_getcred(SYSCTL_HANDLER_ARGS)
398{
399 struct xucred xuc;
400 struct sockaddr_in6 addrs[2];
401 struct sctp_inpcb *inp;
402 struct sctp_nets *net;
403 struct sctp_tcb *stcb;
404 int error;
405 uint32_t vrf_id;
406
407 vrf_id = SCTP_DEFAULT_VRFID;
408
409 error = priv_check(req->td, PRIV_NETINET_GETCRED);
410 if (error)
411 return (error);
412
413 if (req->newlen != sizeof(addrs)) {
414 SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
415 return (EINVAL);
416 }
417 if (req->oldlen != sizeof(struct ucred)) {
418 SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
419 return (EINVAL);
420 }
421 error = SYSCTL_IN(req, addrs, sizeof(addrs));
422 if (error)
423 return (error);
424
425 stcb = sctp_findassociation_addr_sa(sin6tosa(&addrs[1]),
426 sin6tosa(&addrs[0]),
427 &inp, &net, 1, vrf_id);
428 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
429 if ((inp != NULL) && (stcb == NULL)) {
430 /* reduce ref-count */
431 SCTP_INP_WLOCK(inp);
432 SCTP_INP_DECR_REF(inp);
433 goto cred_can_cont;
434 }
435 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, ENOENT);
436 error = ENOENT;
437 goto out;
438 }
439 SCTP_TCB_UNLOCK(stcb);
440 /*
441 * We use the write lock here, only since in the error leg we need
442 * it. If we used RLOCK, then we would have to
443 * wlock/decr/unlock/rlock. Which in theory could create a hole.
444 * Better to use higher wlock.
445 */
446 SCTP_INP_WLOCK(inp);
447cred_can_cont:
448 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
449 if (error) {
450 SCTP_INP_WUNLOCK(inp);
451 goto out;
452 }
453 cru2x(inp->sctp_socket->so_cred, &xuc);

Callers

nothing calls this directly

Calls 4

priv_checkFunction · 0.50
cr_canseesocketFunction · 0.50
cru2xFunction · 0.50

Tested by

no test coverage detected