Home | History | Annotate | Line # | Download | only in kern
uipc_domain.c revision 1.88
      1 /*	$NetBSD: uipc_domain.c,v 1.88 2013/01/31 14:30:47 joerg Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1982, 1986, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. Neither the name of the University nor the names of its contributors
     16  *    may be used to endorse or promote products derived from this software
     17  *    without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  * SUCH DAMAGE.
     30  *
     31  *	@(#)uipc_domain.c	8.3 (Berkeley) 2/14/95
     32  */
     33 
     34 #include <sys/cdefs.h>
     35 __KERNEL_RCSID(0, "$NetBSD: uipc_domain.c,v 1.88 2013/01/31 14:30:47 joerg Exp $");
     36 
     37 #include <sys/param.h>
     38 #include <sys/socket.h>
     39 #include <sys/socketvar.h>
     40 #include <sys/protosw.h>
     41 #include <sys/domain.h>
     42 #include <sys/mbuf.h>
     43 #include <sys/time.h>
     44 #include <sys/kernel.h>
     45 #include <sys/systm.h>
     46 #include <sys/callout.h>
     47 #include <sys/queue.h>
     48 #include <sys/proc.h>
     49 #include <sys/sysctl.h>
     50 #include <sys/un.h>
     51 #include <sys/unpcb.h>
     52 #include <sys/file.h>
     53 #include <sys/filedesc.h>
     54 #include <sys/kauth.h>
     55 #include <netinet/in.h>
     56 
     57 MALLOC_DECLARE(M_SOCKADDR);
     58 
     59 MALLOC_DEFINE(M_SOCKADDR, "sockaddr", "socket endpoints");
     60 
     61 void	pffasttimo(void *);
     62 void	pfslowtimo(void *);
     63 
     64 struct domainhead domains = STAILQ_HEAD_INITIALIZER(domains);
     65 static struct domain *domain_array[AF_MAX];
     66 
     67 callout_t pffasttimo_ch, pfslowtimo_ch;
     68 
     69 /*
     70  * Current time values for fast and slow timeouts.  We can use u_int
     71  * relatively safely.  The fast timer will roll over in 27 years and
     72  * the slow timer in 68 years.
     73  */
     74 u_int	pfslowtimo_now;
     75 u_int	pffasttimo_now;
     76 
     77 static struct sysctllog *domain_sysctllog;
     78 static void sysctl_net_setup(void);
     79 
     80 void
     81 domaininit(bool addroute)
     82 {
     83 	__link_set_decl(domains, struct domain);
     84 	struct domain * const * dpp;
     85 	struct domain *rt_domain = NULL;
     86 
     87 	sysctl_net_setup();
     88 
     89 	/*
     90 	 * Add all of the domains.  Make sure the PF_ROUTE
     91 	 * domain is added last.
     92 	 */
     93 	__link_set_foreach(dpp, domains) {
     94 		if ((*dpp)->dom_family == PF_ROUTE)
     95 			rt_domain = *dpp;
     96 		else
     97 			domain_attach(*dpp);
     98 	}
     99 	if (rt_domain && addroute)
    100 		domain_attach(rt_domain);
    101 
    102 	callout_init(&pffasttimo_ch, CALLOUT_MPSAFE);
    103 	callout_init(&pfslowtimo_ch, CALLOUT_MPSAFE);
    104 
    105 	callout_reset(&pffasttimo_ch, 1, pffasttimo, NULL);
    106 	callout_reset(&pfslowtimo_ch, 1, pfslowtimo, NULL);
    107 }
    108 
    109 void
    110 domain_attach(struct domain *dp)
    111 {
    112 	const struct protosw *pr;
    113 
    114 	STAILQ_INSERT_TAIL(&domains, dp, dom_link);
    115 	if (dp->dom_family < __arraycount(domain_array))
    116 		domain_array[dp->dom_family] = dp;
    117 
    118 	if (dp->dom_init)
    119 		(*dp->dom_init)();
    120 
    121 #ifdef MBUFTRACE
    122 	if (dp->dom_mowner.mo_name[0] == '\0') {
    123 		strncpy(dp->dom_mowner.mo_name, dp->dom_name,
    124 		    sizeof(dp->dom_mowner.mo_name));
    125 		MOWNER_ATTACH(&dp->dom_mowner);
    126 	}
    127 #endif
    128 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
    129 		if (pr->pr_init)
    130 			(*pr->pr_init)();
    131 	}
    132 
    133 	if (max_linkhdr < 16)		/* XXX */
    134 		max_linkhdr = 16;
    135 	max_hdr = max_linkhdr + max_protohdr;
    136 	max_datalen = MHLEN - max_hdr;
    137 }
    138 
    139 struct domain *
    140 pffinddomain(int family)
    141 {
    142 	struct domain *dp;
    143 
    144 	if (family < __arraycount(domain_array) && domain_array[family] != NULL)
    145 		return domain_array[family];
    146 
    147 	DOMAIN_FOREACH(dp)
    148 		if (dp->dom_family == family)
    149 			return dp;
    150 	return NULL;
    151 }
    152 
    153 const struct protosw *
    154 pffindtype(int family, int type)
    155 {
    156 	struct domain *dp;
    157 	const struct protosw *pr;
    158 
    159 	dp = pffinddomain(family);
    160 	if (dp == NULL)
    161 		return NULL;
    162 
    163 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
    164 		if (pr->pr_type && pr->pr_type == type)
    165 			return pr;
    166 
    167 	return NULL;
    168 }
    169 
    170 const struct protosw *
    171 pffindproto(int family, int protocol, int type)
    172 {
    173 	struct domain *dp;
    174 	const struct protosw *pr;
    175 	const struct protosw *maybe = NULL;
    176 
    177 	if (family == 0)
    178 		return NULL;
    179 
    180 	dp = pffinddomain(family);
    181 	if (dp == NULL)
    182 		return NULL;
    183 
    184 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
    185 		if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
    186 			return pr;
    187 
    188 		if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
    189 		    pr->pr_protocol == 0 && maybe == NULL)
    190 			maybe = pr;
    191 	}
    192 	return maybe;
    193 }
    194 
    195 void *
    196 sockaddr_addr(struct sockaddr *sa, socklen_t *slenp)
    197 {
    198 	const struct domain *dom;
    199 
    200 	if ((dom = pffinddomain(sa->sa_family)) == NULL ||
    201 	    dom->dom_sockaddr_addr == NULL)
    202 		return NULL;
    203 
    204 	return (*dom->dom_sockaddr_addr)(sa, slenp);
    205 }
    206 
    207 const void *
    208 sockaddr_const_addr(const struct sockaddr *sa, socklen_t *slenp)
    209 {
    210 	const struct domain *dom;
    211 
    212 	if ((dom = pffinddomain(sa->sa_family)) == NULL ||
    213 	    dom->dom_sockaddr_const_addr == NULL)
    214 		return NULL;
    215 
    216 	return (*dom->dom_sockaddr_const_addr)(sa, slenp);
    217 }
    218 
    219 const struct sockaddr *
    220 sockaddr_any_by_family(int family)
    221 {
    222 	const struct domain *dom;
    223 
    224 	if ((dom = pffinddomain(family)) == NULL)
    225 		return NULL;
    226 
    227 	return dom->dom_sa_any;
    228 }
    229 
    230 const struct sockaddr *
    231 sockaddr_any(const struct sockaddr *sa)
    232 {
    233 	return sockaddr_any_by_family(sa->sa_family);
    234 }
    235 
    236 const void *
    237 sockaddr_anyaddr(const struct sockaddr *sa, socklen_t *slenp)
    238 {
    239 	const struct sockaddr *any;
    240 
    241 	if ((any = sockaddr_any(sa)) == NULL)
    242 		return NULL;
    243 
    244 	return sockaddr_const_addr(any, slenp);
    245 }
    246 
    247 struct sockaddr *
    248 sockaddr_alloc(sa_family_t af, socklen_t socklen, int flags)
    249 {
    250 	struct sockaddr *sa;
    251 	socklen_t reallen = MAX(socklen, offsetof(struct sockaddr, sa_data[0]));
    252 
    253 	if ((sa = malloc(reallen, M_SOCKADDR, flags)) == NULL)
    254 		return NULL;
    255 
    256 	sa->sa_family = af;
    257 	sa->sa_len = reallen;
    258 	return sa;
    259 }
    260 
    261 struct sockaddr *
    262 sockaddr_copy(struct sockaddr *dst, socklen_t socklen,
    263     const struct sockaddr *src)
    264 {
    265 	if (__predict_false(socklen < src->sa_len)) {
    266 		panic("%s: source too long, %d < %d bytes", __func__, socklen,
    267 		    src->sa_len);
    268 	}
    269 	return memcpy(dst, src, src->sa_len);
    270 }
    271 
    272 struct sockaddr *
    273 sockaddr_externalize(struct sockaddr *dst, socklen_t socklen,
    274     const struct sockaddr *src)
    275 {
    276 	struct domain *dom;
    277 
    278 	dom = pffinddomain(src->sa_family);
    279 
    280 	if (dom != NULL && dom->dom_sockaddr_externalize != NULL)
    281 		return (*dom->dom_sockaddr_externalize)(dst, socklen, src);
    282 
    283 	return sockaddr_copy(dst, socklen, src);
    284 }
    285 
    286 int
    287 sockaddr_cmp(const struct sockaddr *sa1, const struct sockaddr *sa2)
    288 {
    289 	int len, rc;
    290 	struct domain *dom;
    291 
    292 	if (sa1->sa_family != sa2->sa_family)
    293 		return sa1->sa_family - sa2->sa_family;
    294 
    295 	dom = pffinddomain(sa1->sa_family);
    296 
    297 	if (dom != NULL && dom->dom_sockaddr_cmp != NULL)
    298 		return (*dom->dom_sockaddr_cmp)(sa1, sa2);
    299 
    300 	len = MIN(sa1->sa_len, sa2->sa_len);
    301 
    302 	if (dom == NULL || dom->dom_sa_cmplen == 0) {
    303 		if ((rc = memcmp(sa1, sa2, len)) != 0)
    304 			return rc;
    305 		return sa1->sa_len - sa2->sa_len;
    306 	}
    307 
    308 	if ((rc = memcmp((const char *)sa1 + dom->dom_sa_cmpofs,
    309 		         (const char *)sa2 + dom->dom_sa_cmpofs,
    310 			 MIN(dom->dom_sa_cmplen,
    311 			     len - MIN(len, dom->dom_sa_cmpofs)))) != 0)
    312 		return rc;
    313 
    314 	return MIN(dom->dom_sa_cmplen + dom->dom_sa_cmpofs, sa1->sa_len) -
    315 	       MIN(dom->dom_sa_cmplen + dom->dom_sa_cmpofs, sa2->sa_len);
    316 }
    317 
    318 struct sockaddr *
    319 sockaddr_dup(const struct sockaddr *src, int flags)
    320 {
    321 	struct sockaddr *dst;
    322 
    323 	if ((dst = sockaddr_alloc(src->sa_family, src->sa_len, flags)) == NULL)
    324 		return NULL;
    325 
    326 	return sockaddr_copy(dst, dst->sa_len, src);
    327 }
    328 
    329 void
    330 sockaddr_free(struct sockaddr *sa)
    331 {
    332 	free(sa, M_SOCKADDR);
    333 }
    334 
    335 void
    336 sockaddr_format(const struct sockaddr *sa, char *buf, size_t len)
    337 {
    338 	const struct sockaddr_un *sun = (const struct sockaddr_un *)sa;
    339 	const struct sockaddr_in *sin = (const struct sockaddr_in *)sa;
    340 	const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)sa;
    341 	const uint8_t *data;
    342 	size_t data_len;
    343 
    344 	if (sa == NULL) {
    345 		strlcpy(buf, "(null)", len);
    346 		return;
    347 	}
    348 
    349 	switch (sa->sa_family) {
    350 	default:
    351 		snprintf(buf, len, "(unknown socket family %d)",
    352 		    (int)sa->sa_family);
    353 		return;
    354 	case AF_LOCAL:
    355 		strlcpy(buf, "unix:", len);
    356 		strlcat(buf, sun->sun_path, len);
    357 		return;
    358 	case AF_INET:
    359 		strlcpy(buf, "inet:", len);
    360 		if (len < 6)
    361 			return;
    362 		buf += 5;
    363 		len -= 5;
    364 		data = (const uint8_t *)&sin->sin_addr;
    365 		data_len = sizeof(sin->sin_addr);
    366 		break;
    367 	case AF_INET6:
    368 		strlcpy(buf, "inet6:", len);
    369 		if (len < 7)
    370 			return;
    371 		buf += 6;
    372 		len -= 6;
    373 		data = (const uint8_t *)&sin6->sin6_addr;
    374 		data_len = sizeof(sin6->sin6_addr);
    375 		break;
    376 	}
    377 	for (;;) {
    378 		if (--len == 0)
    379 			break;
    380 
    381 		uint8_t hi = *data >> 4;
    382 		uint8_t lo = *data & 15;
    383 		--data_len;
    384 		++data;
    385 		*buf++ = hi + (hi >= 10 ? 'a' - 10 : '0');
    386 		if (--len == 0)
    387 			break;
    388 		*buf++ = lo + (lo >= 10 ? 'a' - 10 : '0');
    389 		if (data_len == 0)
    390 			break;
    391 	}
    392 	*buf = 0;
    393 }
    394 
    395 /*
    396  * sysctl helper to stuff PF_LOCAL pcbs into sysctl structures
    397  */
    398 static void
    399 sysctl_dounpcb(struct kinfo_pcb *pcb, const struct socket *so)
    400 {
    401 	struct unpcb *unp = sotounpcb(so);
    402 	struct sockaddr_un *un = unp->unp_addr;
    403 
    404 	memset(pcb, 0, sizeof(*pcb));
    405 
    406 	pcb->ki_family = so->so_proto->pr_domain->dom_family;
    407 	pcb->ki_type = so->so_proto->pr_type;
    408 	pcb->ki_protocol = so->so_proto->pr_protocol;
    409 	pcb->ki_pflags = unp->unp_flags;
    410 
    411 	pcb->ki_pcbaddr = PTRTOUINT64(unp);
    412 	/* pcb->ki_ppcbaddr = unp has no ppcb... */
    413 	pcb->ki_sockaddr = PTRTOUINT64(so);
    414 
    415 	pcb->ki_sostate = so->so_state;
    416 	/* pcb->ki_prstate = unp has no state... */
    417 
    418 	pcb->ki_rcvq = so->so_rcv.sb_cc;
    419 	pcb->ki_sndq = so->so_snd.sb_cc;
    420 
    421 	un = (struct sockaddr_un *)&pcb->ki_src;
    422 	/*
    423 	 * local domain sockets may bind without having a local
    424 	 * endpoint.  bleah!
    425 	 */
    426 	if (unp->unp_addr != NULL) {
    427 		un->sun_len = unp->unp_addr->sun_len;
    428 		un->sun_family = unp->unp_addr->sun_family;
    429 		strlcpy(un->sun_path, unp->unp_addr->sun_path,
    430 		    sizeof(pcb->ki_s));
    431 	}
    432 	else {
    433 		un->sun_len = offsetof(struct sockaddr_un, sun_path);
    434 		un->sun_family = pcb->ki_family;
    435 	}
    436 	if (unp->unp_conn != NULL) {
    437 		un = (struct sockaddr_un *)&pcb->ki_dst;
    438 		if (unp->unp_conn->unp_addr != NULL) {
    439 			un->sun_len = unp->unp_conn->unp_addr->sun_len;
    440 			un->sun_family = unp->unp_conn->unp_addr->sun_family;
    441 			un->sun_family = unp->unp_conn->unp_addr->sun_family;
    442 			strlcpy(un->sun_path, unp->unp_conn->unp_addr->sun_path,
    443 				sizeof(pcb->ki_d));
    444 		}
    445 		else {
    446 			un->sun_len = offsetof(struct sockaddr_un, sun_path);
    447 			un->sun_family = pcb->ki_family;
    448 		}
    449 	}
    450 
    451 	pcb->ki_inode = unp->unp_ino;
    452 	pcb->ki_vnode = PTRTOUINT64(unp->unp_vnode);
    453 	pcb->ki_conn = PTRTOUINT64(unp->unp_conn);
    454 	pcb->ki_refs = PTRTOUINT64(unp->unp_refs);
    455 	pcb->ki_nextref = PTRTOUINT64(unp->unp_nextref);
    456 }
    457 
    458 static int
    459 sysctl_unpcblist(SYSCTLFN_ARGS)
    460 {
    461 	struct file *fp, *dfp, *np;
    462 	struct socket *so;
    463 	struct kinfo_pcb pcb;
    464 	char *dp;
    465 	u_int op, arg;
    466 	size_t len, needed, elem_size, out_size;
    467 	int error, elem_count, pf, type, pf2;
    468 
    469 	if (namelen == 1 && name[0] == CTL_QUERY)
    470 		return sysctl_query(SYSCTLFN_CALL(rnode));
    471 
    472 	if (namelen != 4)
    473 		return EINVAL;
    474 
    475 	if (oldp != NULL) {
    476 		len = *oldlenp;
    477 		elem_size = name[2];
    478 		elem_count = name[3];
    479 		if (elem_size != sizeof(pcb))
    480 			return EINVAL;
    481 	} else {
    482 		len = 0;
    483 		elem_size = sizeof(pcb);
    484 		elem_count = INT_MAX;
    485 	}
    486 	error = 0;
    487 	dp = oldp;
    488 	op = name[0];
    489 	arg = name[1];
    490 	out_size = elem_size;
    491 	needed = 0;
    492 
    493 	if (name - oname != 4)
    494 		return EINVAL;
    495 
    496 	pf = oname[1];
    497 	type = oname[2];
    498 	pf2 = (oldp == NULL) ? 0 : pf;
    499 
    500 	/*
    501 	 * allocate dummy file descriptor to make position in list.
    502 	 */
    503 	sysctl_unlock();
    504 	if ((dfp = fgetdummy()) == NULL) {
    505 	 	sysctl_relock();
    506 		return ENOMEM;
    507 	}
    508 
    509 	/*
    510 	 * there's no "list" of local domain sockets, so we have
    511 	 * to walk the file list looking for them.  :-/
    512 	 */
    513 	mutex_enter(&filelist_lock);
    514 	LIST_FOREACH(fp, &filehead, f_list) {
    515 	    	np = LIST_NEXT(fp, f_list);
    516 		if (fp->f_count == 0 || fp->f_type != DTYPE_SOCKET ||
    517 		    fp->f_data == NULL)
    518 			continue;
    519 		so = (struct socket *)fp->f_data;
    520 		if (so->so_type != type)
    521 			continue;
    522 		if (so->so_proto->pr_domain->dom_family != pf)
    523 			continue;
    524 		if (kauth_authorize_network(l->l_cred, KAUTH_NETWORK_SOCKET,
    525 		    KAUTH_REQ_NETWORK_SOCKET_CANSEE, so, NULL, NULL) != 0)
    526 			continue;
    527 		if (len >= elem_size && elem_count > 0) {
    528 			mutex_enter(&fp->f_lock);
    529 			fp->f_count++;
    530 			mutex_exit(&fp->f_lock);
    531 			LIST_INSERT_AFTER(fp, dfp, f_list);
    532 			mutex_exit(&filelist_lock);
    533 			sysctl_dounpcb(&pcb, so);
    534 			error = copyout(&pcb, dp, out_size);
    535 			closef(fp);
    536 			mutex_enter(&filelist_lock);
    537 			np = LIST_NEXT(dfp, f_list);
    538 			LIST_REMOVE(dfp, f_list);
    539 			if (error)
    540 				break;
    541 			dp += elem_size;
    542 			len -= elem_size;
    543 		}
    544 		needed += elem_size;
    545 		if (elem_count > 0 && elem_count != INT_MAX)
    546 			elem_count--;
    547 	}
    548 	mutex_exit(&filelist_lock);
    549 	fputdummy(dfp);
    550  	*oldlenp = needed;
    551 	if (oldp == NULL)
    552 		*oldlenp += PCB_SLOP * sizeof(struct kinfo_pcb);
    553  	sysctl_relock();
    554 
    555 	return error;
    556 }
    557 
    558 static void
    559 sysctl_net_setup(void)
    560 {
    561 
    562 	KASSERT(domain_sysctllog == NULL);
    563 	sysctl_createv(&domain_sysctllog, 0, NULL, NULL,
    564 		       CTLFLAG_PERMANENT,
    565 		       CTLTYPE_NODE, "net", NULL,
    566 		       NULL, 0, NULL, 0,
    567 		       CTL_NET, CTL_EOL);
    568 	sysctl_createv(&domain_sysctllog, 0, NULL, NULL,
    569 		       CTLFLAG_PERMANENT,
    570 		       CTLTYPE_NODE, "local",
    571 		       SYSCTL_DESCR("PF_LOCAL related settings"),
    572 		       NULL, 0, NULL, 0,
    573 		       CTL_NET, PF_LOCAL, CTL_EOL);
    574 	sysctl_createv(&domain_sysctllog, 0, NULL, NULL,
    575 		       CTLFLAG_PERMANENT,
    576 		       CTLTYPE_NODE, "stream",
    577 		       SYSCTL_DESCR("SOCK_STREAM settings"),
    578 		       NULL, 0, NULL, 0,
    579 		       CTL_NET, PF_LOCAL, SOCK_STREAM, CTL_EOL);
    580 	sysctl_createv(&domain_sysctllog, 0, NULL, NULL,
    581 		       CTLFLAG_PERMANENT,
    582 		       CTLTYPE_NODE, "seqpacket",
    583 		       SYSCTL_DESCR("SOCK_SEQPACKET settings"),
    584 		       NULL, 0, NULL, 0,
    585 		       CTL_NET, PF_LOCAL, SOCK_SEQPACKET, CTL_EOL);
    586 	sysctl_createv(&domain_sysctllog, 0, NULL, NULL,
    587 		       CTLFLAG_PERMANENT,
    588 		       CTLTYPE_NODE, "dgram",
    589 		       SYSCTL_DESCR("SOCK_DGRAM settings"),
    590 		       NULL, 0, NULL, 0,
    591 		       CTL_NET, PF_LOCAL, SOCK_DGRAM, CTL_EOL);
    592 
    593 	sysctl_createv(&domain_sysctllog, 0, NULL, NULL,
    594 		       CTLFLAG_PERMANENT,
    595 		       CTLTYPE_STRUCT, "pcblist",
    596 		       SYSCTL_DESCR("SOCK_STREAM protocol control block list"),
    597 		       sysctl_unpcblist, 0, NULL, 0,
    598 		       CTL_NET, PF_LOCAL, SOCK_STREAM, CTL_CREATE, CTL_EOL);
    599 	sysctl_createv(&domain_sysctllog, 0, NULL, NULL,
    600 		       CTLFLAG_PERMANENT,
    601 		       CTLTYPE_STRUCT, "pcblist",
    602 		       SYSCTL_DESCR("SOCK_SEQPACKET protocol control "
    603 				    "block list"),
    604 		       sysctl_unpcblist, 0, NULL, 0,
    605 		       CTL_NET, PF_LOCAL, SOCK_SEQPACKET, CTL_CREATE, CTL_EOL);
    606 	sysctl_createv(&domain_sysctllog, 0, NULL, NULL,
    607 		       CTLFLAG_PERMANENT,
    608 		       CTLTYPE_STRUCT, "pcblist",
    609 		       SYSCTL_DESCR("SOCK_DGRAM protocol control block list"),
    610 		       sysctl_unpcblist, 0, NULL, 0,
    611 		       CTL_NET, PF_LOCAL, SOCK_DGRAM, CTL_CREATE, CTL_EOL);
    612 }
    613 
    614 void
    615 pfctlinput(int cmd, const struct sockaddr *sa)
    616 {
    617 	struct domain *dp;
    618 	const struct protosw *pr;
    619 
    620 	DOMAIN_FOREACH(dp) {
    621 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
    622 			if (pr->pr_ctlinput != NULL)
    623 				(*pr->pr_ctlinput)(cmd, sa, NULL);
    624 		}
    625 	}
    626 }
    627 
    628 void
    629 pfctlinput2(int cmd, const struct sockaddr *sa, void *ctlparam)
    630 {
    631 	struct domain *dp;
    632 	const struct protosw *pr;
    633 
    634 	if (sa == NULL)
    635 		return;
    636 
    637 	DOMAIN_FOREACH(dp) {
    638 		/*
    639 		 * the check must be made by xx_ctlinput() anyways, to
    640 		 * make sure we use data item pointed to by ctlparam in
    641 		 * correct way.  the following check is made just for safety.
    642 		 */
    643 		if (dp->dom_family != sa->sa_family)
    644 			continue;
    645 
    646 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
    647 			if (pr->pr_ctlinput != NULL)
    648 				(*pr->pr_ctlinput)(cmd, sa, ctlparam);
    649 		}
    650 	}
    651 }
    652 
    653 void
    654 pfslowtimo(void *arg)
    655 {
    656 	struct domain *dp;
    657 	const struct protosw *pr;
    658 
    659 	pfslowtimo_now++;
    660 
    661 	DOMAIN_FOREACH(dp) {
    662 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
    663 			if (pr->pr_slowtimo)
    664 				(*pr->pr_slowtimo)();
    665 	}
    666 	callout_schedule(&pfslowtimo_ch, hz / PR_SLOWHZ);
    667 }
    668 
    669 void
    670 pffasttimo(void *arg)
    671 {
    672 	struct domain *dp;
    673 	const struct protosw *pr;
    674 
    675 	pffasttimo_now++;
    676 
    677 	DOMAIN_FOREACH(dp) {
    678 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
    679 			if (pr->pr_fasttimo)
    680 				(*pr->pr_fasttimo)();
    681 	}
    682 	callout_schedule(&pffasttimo_ch, hz / PR_FASTHZ);
    683 }
    684