protosw: repair protocol selection logic in socket(2)

Pointy hat to:	glebius
Fixes:		61f7427f02
This commit is contained in:
Gleb Smirnoff 2022-08-30 21:19:46 -07:00
parent 1f3d8c09be
commit 24af7808fa
3 changed files with 6 additions and 6 deletions

View File

@ -290,7 +290,7 @@ pffinddomain(int family)
}
struct protosw *
pffindtype(int family, int type)
pffindproto(int family, int type, int proto)
{
struct domain *dp;
struct protosw *pr;
@ -300,7 +300,9 @@ pffindtype(int family, int type)
return (NULL);
for (int i = 0; i < dp->dom_nprotosw; i++)
if ((pr = dp->dom_protosw[i]) != NULL && pr->pr_type == type)
if ((pr = dp->dom_protosw[i]) != NULL && pr->pr_type == type &&
(pr->pr_protocol == 0 || proto == 0 ||
pr->pr_protocol == proto))
return (pr);
return (NULL);

View File

@ -520,7 +520,7 @@ socreate(int dom, struct socket **aso, int type, int proto,
td->td_proc->p_comm);
}
prp = pffindtype(dom, type);
prp = pffindproto(dom, type, proto);
if (prp == NULL) {
/* No support for domain. */
if (pffinddomain(dom) == NULL)
@ -530,8 +530,6 @@ socreate(int dom, struct socket **aso, int type, int proto,
return (EPROTOTYPE);
return (EPROTONOSUPPORT);
}
if (prp->pr_protocol != 0 && proto != 0 && prp->pr_protocol != proto)
return (EPROTONOSUPPORT);
MPASS(prp->pr_attach);

View File

@ -236,7 +236,7 @@ char *prcorequests[] = {
#ifdef _KERNEL
struct domain *pffinddomain(int family);
struct protosw *pffindtype(int family, int type);
struct protosw *pffindproto(int family, int type, int proto);
int protosw_register(struct domain *, struct protosw *);
int protosw_unregister(struct protosw *);