MCPcopy Index your code
hub / github.com/F-Stack/f-stack / socreate

Function socreate

freebsd/kern/uipc_socket.c:505–570  ·  view source on GitHub ↗

* socreate returns a socket with a ref count of 1. The socket should be * closed with soclose(). */

Source from the content-addressed store, hash-verified

503 * closed with soclose().
504 */
505int
506socreate(int dom, struct socket **aso, int type, int proto,
507 struct ucred *cred, struct thread *td)
508{
509 struct protosw *prp;
510 struct socket *so;
511 int error;
512
513 if (proto)
514 prp = pffindproto(dom, proto, type);
515 else
516 prp = pffindtype(dom, type);
517
518 if (prp == NULL) {
519 /* No support for domain. */
520 if (pffinddomain(dom) == NULL)
521 return (EAFNOSUPPORT);
522 /* No support for socket type. */
523 if (proto == 0 && type != 0)
524 return (EPROTOTYPE);
525 return (EPROTONOSUPPORT);
526 }
527 if (prp->pr_usrreqs->pru_attach == NULL ||
528 prp->pr_usrreqs->pru_attach == pru_attach_notsupp)
529 return (EPROTONOSUPPORT);
530
531 if (prison_check_af(cred, prp->pr_domain->dom_family) != 0)
532 return (EPROTONOSUPPORT);
533
534 if (prp->pr_type != type)
535 return (EPROTOTYPE);
536 so = soalloc(CRED_TO_VNET(cred));
537 if (so == NULL)
538 return (ENOBUFS);
539
540 so->so_type = type;
541 so->so_cred = crhold(cred);
542 if ((prp->pr_domain->dom_family == PF_INET) ||
543 (prp->pr_domain->dom_family == PF_INET6) ||
544 (prp->pr_domain->dom_family == PF_ROUTE))
545 so->so_fibnum = td->td_proc->p_fibnum;
546 else
547 so->so_fibnum = 0;
548 so->so_proto = prp;
549#ifdef MAC
550 mac_socket_create(cred, so);
551#endif
552 knlist_init(&so->so_rdsel.si_note, so, so_rdknl_lock, so_rdknl_unlock,
553 so_rdknl_assert_lock);
554 knlist_init(&so->so_wrsel.si_note, so, so_wrknl_lock, so_wrknl_unlock,
555 so_wrknl_assert_lock);
556 /*
557 * Auto-sizing of socket buffers is managed by the protocols and
558 * the appropriate flags must be set in the pru_attach function.
559 */
560 CURVNET_SET(so->so_vnet);
561 error = (*prp->pr_usrreqs->pru_attach)(so, proto, td);
562 CURVNET_RESTORE();

Callers 14

sctp_over_udp_startFunction · 0.85
in_gre_setup_socketFunction · 0.85
in6_gre_setup_socketFunction · 0.85
kern_socketFunction · 0.85
kern_socketpairFunction · 0.85
vxlan_socket_initFunction · 0.85
ng_ksocket_newhookFunction · 0.85
lo_set_defaultaddrFunction · 0.85
ff_veth_setaddrFunction · 0.85
ff_veth_setvaddrFunction · 0.85

Calls 9

pffindprotoFunction · 0.85
pffindtypeFunction · 0.85
pffinddomainFunction · 0.85
soallocFunction · 0.85
mac_socket_createFunction · 0.85
knlist_initFunction · 0.85
sodeallocFunction · 0.85
prison_check_afFunction · 0.70
crholdFunction · 0.70

Tested by

no test coverage detected