1 /* $NetBSD: uipc_domain.c,v 1.106 2018/12/27 07:56:43 maxv 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.106 2018/12/27 07:56:43 maxv 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 56 #include <netatalk/at.h> 57 #include <net/if_dl.h> 58 #include <netinet/in.h> 59 60 MALLOC_DECLARE(M_SOCKADDR); 61 62 MALLOC_DEFINE(M_SOCKADDR, "sockaddr", "socket endpoints"); 63 64 void pffasttimo(void *); 65 void pfslowtimo(void *); 66 67 struct domainhead domains = STAILQ_HEAD_INITIALIZER(domains); 68 static struct domain *domain_array[AF_MAX]; 69 70 callout_t pffasttimo_ch, pfslowtimo_ch; 71 72 /* 73 * Current time values for fast and slow timeouts. We can use u_int 74 * relatively safely. The fast timer will roll over in 27 years and 75 * the slow timer in 68 years. 76 */ 77 u_int pfslowtimo_now; 78 u_int pffasttimo_now; 79 80 static struct sysctllog *domain_sysctllog; 81 static void sysctl_net_setup(void); 82 83 /* ensure successful linkage even without any domains in link sets */ 84 static struct domain domain_dummy; 85 __link_set_add_rodata(domains,domain_dummy); 86 87 static void 88 domain_init_timers(void) 89 { 90 91 callout_init(&pffasttimo_ch, CALLOUT_MPSAFE); 92 callout_init(&pfslowtimo_ch, CALLOUT_MPSAFE); 93 94 callout_reset(&pffasttimo_ch, 1, pffasttimo, NULL); 95 callout_reset(&pfslowtimo_ch, 1, pfslowtimo, NULL); 96 } 97 98 void 99 domaininit(bool attach) 100 { 101 __link_set_decl(domains, struct domain); 102 struct domain * const * dpp; 103 struct domain *rt_domain = NULL; 104 105 sysctl_net_setup(); 106 107 /* 108 * Add all of the domains. Make sure the PF_ROUTE 109 * domain is added last. 110 */ 111 if (attach) { 112 __link_set_foreach(dpp, domains) { 113 if (*dpp == &domain_dummy) 114 continue; 115 if ((*dpp)->dom_family == PF_ROUTE) 116 rt_domain = *dpp; 117 else 118 domain_attach(*dpp); 119 } 120 if (rt_domain) 121 domain_attach(rt_domain); 122 123 domain_init_timers(); 124 } 125 } 126 127 /* 128 * Must be called only if domaininit has been called with false and 129 * after all domains have been attached. 130 */ 131 void 132 domaininit_post(void) 133 { 134 135 domain_init_timers(); 136 } 137 138 void 139 domain_attach(struct domain *dp) 140 { 141 const struct protosw *pr; 142 143 STAILQ_INSERT_TAIL(&domains, dp, dom_link); 144 if (dp->dom_family < __arraycount(domain_array)) 145 domain_array[dp->dom_family] = dp; 146 147 if (dp->dom_init) 148 (*dp->dom_init)(); 149 150 #ifdef MBUFTRACE 151 if (dp->dom_mowner.mo_name[0] == '\0') { 152 strncpy(dp->dom_mowner.mo_name, dp->dom_name, 153 sizeof(dp->dom_mowner.mo_name)); 154 MOWNER_ATTACH(&dp->dom_mowner); 155 } 156 #endif 157 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) { 158 if (pr->pr_init) 159 (*pr->pr_init)(); 160 } 161 162 if (max_linkhdr < 16) /* XXX */ 163 max_linkhdr = 16; 164 max_hdr = max_linkhdr + max_protohdr; 165 max_datalen = MHLEN - max_hdr; 166 } 167 168 struct domain * 169 pffinddomain(int family) 170 { 171 struct domain *dp; 172 173 if (family < __arraycount(domain_array) && domain_array[family] != NULL) 174 return domain_array[family]; 175 176 DOMAIN_FOREACH(dp) 177 if (dp->dom_family == family) 178 return dp; 179 return NULL; 180 } 181 182 const struct protosw * 183 pffindtype(int family, int type) 184 { 185 struct domain *dp; 186 const struct protosw *pr; 187 188 dp = pffinddomain(family); 189 if (dp == NULL) 190 return NULL; 191 192 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 193 if (pr->pr_type && pr->pr_type == type) 194 return pr; 195 196 return NULL; 197 } 198 199 const struct protosw * 200 pffindproto(int family, int protocol, int type) 201 { 202 struct domain *dp; 203 const struct protosw *pr; 204 const struct protosw *maybe = NULL; 205 206 if (family == 0) 207 return NULL; 208 209 dp = pffinddomain(family); 210 if (dp == NULL) 211 return NULL; 212 213 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) { 214 if ((pr->pr_protocol == protocol) && (pr->pr_type == type)) 215 return pr; 216 217 if (type == SOCK_RAW && pr->pr_type == SOCK_RAW && 218 pr->pr_protocol == 0 && maybe == NULL) 219 maybe = pr; 220 } 221 return maybe; 222 } 223 224 void * 225 sockaddr_addr(struct sockaddr *sa, socklen_t *slenp) 226 { 227 const struct domain *dom; 228 229 if ((dom = pffinddomain(sa->sa_family)) == NULL || 230 dom->dom_sockaddr_addr == NULL) 231 return NULL; 232 233 return (*dom->dom_sockaddr_addr)(sa, slenp); 234 } 235 236 const void * 237 sockaddr_const_addr(const struct sockaddr *sa, socklen_t *slenp) 238 { 239 const struct domain *dom; 240 241 if ((dom = pffinddomain(sa->sa_family)) == NULL || 242 dom->dom_sockaddr_const_addr == NULL) 243 return NULL; 244 245 return (*dom->dom_sockaddr_const_addr)(sa, slenp); 246 } 247 248 const struct sockaddr * 249 sockaddr_any_by_family(sa_family_t family) 250 { 251 const struct domain *dom; 252 253 if ((dom = pffinddomain(family)) == NULL) 254 return NULL; 255 256 return dom->dom_sa_any; 257 } 258 259 const struct sockaddr * 260 sockaddr_any(const struct sockaddr *sa) 261 { 262 return sockaddr_any_by_family(sa->sa_family); 263 } 264 265 const void * 266 sockaddr_anyaddr(const struct sockaddr *sa, socklen_t *slenp) 267 { 268 const struct sockaddr *any; 269 270 if ((any = sockaddr_any(sa)) == NULL) 271 return NULL; 272 273 return sockaddr_const_addr(any, slenp); 274 } 275 276 socklen_t 277 sockaddr_getsize_by_family(sa_family_t af) 278 { 279 switch (af) { 280 case AF_INET: 281 return sizeof(struct sockaddr_in); 282 case AF_INET6: 283 return sizeof(struct sockaddr_in6); 284 case AF_UNIX: 285 return sizeof(struct sockaddr_un); 286 case AF_LINK: 287 return sizeof(struct sockaddr_dl); 288 case AF_APPLETALK: 289 return sizeof(struct sockaddr_at); 290 default: 291 #ifdef DIAGNOSTIC 292 printf("%s: (%s:%u:%u) Unhandled address family=%hhu\n", 293 __func__, curlwp->l_proc->p_comm, 294 curlwp->l_proc->p_pid, curlwp->l_lid, af); 295 #endif 296 return 0; 297 } 298 } 299 300 #ifdef DIAGNOSTIC 301 static void 302 sockaddr_checklen(const struct sockaddr *sa) 303 { 304 // Can't tell how much was allocated, if it was allocated. 305 if (sa->sa_family == AF_LINK) 306 return; 307 308 socklen_t len = sockaddr_getsize_by_family(sa->sa_family); 309 if (len == 0 || len == sa->sa_len) 310 return; 311 312 char buf[512]; 313 sockaddr_format(sa, buf, sizeof(buf)); 314 printf("%s: %p bad len af=%hhu socklen=%hhu len=%u [%s]\n", 315 __func__, sa, sa->sa_family, sa->sa_len, (unsigned)len, buf); 316 } 317 #else 318 #define sockaddr_checklen(sa) ((void)0) 319 #endif 320 321 struct sockaddr * 322 sockaddr_alloc(sa_family_t af, socklen_t socklen, int flags) 323 { 324 struct sockaddr *sa; 325 socklen_t reallen = MAX(socklen, offsetof(struct sockaddr, sa_data[0])); 326 327 if ((sa = malloc(reallen, M_SOCKADDR, flags)) == NULL) 328 return NULL; 329 330 sa->sa_family = af; 331 sa->sa_len = reallen; 332 sockaddr_checklen(sa); 333 return sa; 334 } 335 336 struct sockaddr * 337 sockaddr_copy(struct sockaddr *dst, socklen_t socklen, 338 const struct sockaddr *src) 339 { 340 if (__predict_false(socklen < src->sa_len)) { 341 panic("%s: source too long, %d < %d bytes", __func__, socklen, 342 src->sa_len); 343 } 344 sockaddr_checklen(src); 345 return memcpy(dst, src, src->sa_len); 346 } 347 348 struct sockaddr * 349 sockaddr_externalize(struct sockaddr *dst, socklen_t socklen, 350 const struct sockaddr *src) 351 { 352 struct domain *dom; 353 354 dom = pffinddomain(src->sa_family); 355 356 if (dom != NULL && dom->dom_sockaddr_externalize != NULL) 357 return (*dom->dom_sockaddr_externalize)(dst, socklen, src); 358 359 return sockaddr_copy(dst, socklen, src); 360 } 361 362 int 363 sockaddr_cmp(const struct sockaddr *sa1, const struct sockaddr *sa2) 364 { 365 int len, rc; 366 struct domain *dom; 367 368 if (sa1->sa_family != sa2->sa_family) 369 return sa1->sa_family - sa2->sa_family; 370 371 dom = pffinddomain(sa1->sa_family); 372 373 if (dom != NULL && dom->dom_sockaddr_cmp != NULL) 374 return (*dom->dom_sockaddr_cmp)(sa1, sa2); 375 376 len = MIN(sa1->sa_len, sa2->sa_len); 377 378 if (dom == NULL || dom->dom_sa_cmplen == 0) { 379 if ((rc = memcmp(sa1, sa2, len)) != 0) 380 return rc; 381 return sa1->sa_len - sa2->sa_len; 382 } 383 384 if ((rc = memcmp((const char *)sa1 + dom->dom_sa_cmpofs, 385 (const char *)sa2 + dom->dom_sa_cmpofs, 386 MIN(dom->dom_sa_cmplen, 387 len - MIN(len, dom->dom_sa_cmpofs)))) != 0) 388 return rc; 389 390 return MIN(dom->dom_sa_cmplen + dom->dom_sa_cmpofs, sa1->sa_len) - 391 MIN(dom->dom_sa_cmplen + dom->dom_sa_cmpofs, sa2->sa_len); 392 } 393 394 struct sockaddr * 395 sockaddr_dup(const struct sockaddr *src, int flags) 396 { 397 struct sockaddr *dst; 398 399 if ((dst = sockaddr_alloc(src->sa_family, src->sa_len, flags)) == NULL) 400 return NULL; 401 402 return sockaddr_copy(dst, dst->sa_len, src); 403 } 404 405 void 406 sockaddr_free(struct sockaddr *sa) 407 { 408 free(sa, M_SOCKADDR); 409 } 410 411 static int 412 sun_print(char *buf, size_t len, const void *v) 413 { 414 const struct sockaddr_un *sun = v; 415 return snprintf(buf, len, "%s", sun->sun_path); 416 } 417 418 int 419 sockaddr_format(const struct sockaddr *sa, char *buf, size_t len) 420 { 421 size_t plen = 0; 422 423 if (sa == NULL) 424 return strlcpy(buf, "(null)", len); 425 426 switch (sa->sa_family) { 427 case AF_LOCAL: 428 plen = strlcpy(buf, "unix: ", len); 429 break; 430 case AF_INET: 431 plen = strlcpy(buf, "inet: ", len); 432 break; 433 case AF_INET6: 434 plen = strlcpy(buf, "inet6: ", len); 435 break; 436 case AF_LINK: 437 plen = strlcpy(buf, "link: ", len); 438 break; 439 case AF_APPLETALK: 440 plen = strlcpy(buf, "atalk: ", len); 441 break; 442 default: 443 return snprintf(buf, len, "(unknown socket family %d)", 444 (int)sa->sa_family); 445 } 446 447 buf += plen; 448 if (plen > len) 449 len = 0; 450 else 451 len -= plen; 452 453 switch (sa->sa_family) { 454 case AF_LOCAL: 455 return sun_print(buf, len, sa); 456 case AF_INET: 457 return sin_print(buf, len, sa); 458 case AF_INET6: 459 return sin6_print(buf, len, sa); 460 case AF_LINK: 461 return sdl_print(buf, len, sa); 462 case AF_APPLETALK: 463 return sat_print(buf, len, sa); 464 default: 465 panic("bad family %hhu", sa->sa_family); 466 } 467 } 468 469 /* 470 * sysctl helper to stuff PF_LOCAL pcbs into sysctl structures 471 */ 472 static void 473 sysctl_dounpcb(struct kinfo_pcb *pcb, const struct socket *so) 474 { 475 const bool allowaddr = get_expose_address(curproc); 476 struct unpcb *unp = sotounpcb(so); 477 struct sockaddr_un *un = unp->unp_addr; 478 479 memset(pcb, 0, sizeof(*pcb)); 480 481 pcb->ki_family = so->so_proto->pr_domain->dom_family; 482 pcb->ki_type = so->so_proto->pr_type; 483 pcb->ki_protocol = so->so_proto->pr_protocol; 484 pcb->ki_pflags = unp->unp_flags; 485 486 COND_SET_VALUE(pcb->ki_pcbaddr, PTRTOUINT64(unp), allowaddr); 487 /* pcb->ki_ppcbaddr = unp has no ppcb... */ 488 COND_SET_VALUE(pcb->ki_sockaddr, PTRTOUINT64(so), allowaddr); 489 490 pcb->ki_sostate = so->so_state; 491 /* pcb->ki_prstate = unp has no state... */ 492 493 pcb->ki_rcvq = so->so_rcv.sb_cc; 494 pcb->ki_sndq = so->so_snd.sb_cc; 495 496 un = (struct sockaddr_un *)pcb->ki_spad; 497 /* 498 * local domain sockets may bind without having a local 499 * endpoint. bleah! 500 */ 501 if (unp->unp_addr != NULL) { 502 /* 503 * We've added one to sun_len when allocating to 504 * hold terminating NUL which we want here. See 505 * makeun(). 506 */ 507 memcpy(un, unp->unp_addr, 508 uimin(sizeof(pcb->ki_spad), unp->unp_addr->sun_len + 1)); 509 } 510 else { 511 un->sun_len = offsetof(struct sockaddr_un, sun_path); 512 un->sun_family = pcb->ki_family; 513 } 514 if (unp->unp_conn != NULL) { 515 un = (struct sockaddr_un *)pcb->ki_dpad; 516 if (unp->unp_conn->unp_addr != NULL) { 517 memcpy(un, unp->unp_conn->unp_addr, 518 uimin(sizeof(pcb->ki_dpad), unp->unp_conn->unp_addr->sun_len + 1)); 519 } 520 else { 521 un->sun_len = offsetof(struct sockaddr_un, sun_path); 522 un->sun_family = pcb->ki_family; 523 } 524 } 525 526 pcb->ki_inode = unp->unp_ino; 527 COND_SET_VALUE(pcb->ki_vnode, PTRTOUINT64(unp->unp_vnode), allowaddr); 528 COND_SET_VALUE(pcb->ki_conn, PTRTOUINT64(unp->unp_conn), allowaddr); 529 COND_SET_VALUE(pcb->ki_refs, PTRTOUINT64(unp->unp_refs), allowaddr); 530 COND_SET_VALUE(pcb->ki_nextref, PTRTOUINT64(unp->unp_nextref), 531 allowaddr); 532 } 533 534 static int 535 sysctl_unpcblist(SYSCTLFN_ARGS) 536 { 537 struct file *fp, *np, *dfp; 538 struct socket *so; 539 struct kinfo_pcb pcb; 540 char *dp; 541 size_t len, needed, elem_size, out_size; 542 int error, elem_count, pf, type; 543 544 if (namelen == 1 && name[0] == CTL_QUERY) 545 return sysctl_query(SYSCTLFN_CALL(rnode)); 546 547 if (namelen != 4) 548 return EINVAL; 549 550 if (oldp != NULL) { 551 len = *oldlenp; 552 elem_size = name[2]; 553 elem_count = name[3]; 554 if (elem_size != sizeof(pcb)) 555 return EINVAL; 556 } else { 557 len = 0; 558 elem_size = sizeof(pcb); 559 elem_count = INT_MAX; 560 } 561 error = 0; 562 dp = oldp; 563 out_size = elem_size; 564 needed = 0; 565 566 if (name - oname != 4) 567 return EINVAL; 568 569 pf = oname[1]; 570 type = oname[2]; 571 572 /* 573 * allocate dummy file descriptor to make position in list. 574 */ 575 sysctl_unlock(); 576 if ((dfp = fgetdummy()) == NULL) { 577 sysctl_relock(); 578 return ENOMEM; 579 } 580 581 /* 582 * there's no "list" of local domain sockets, so we have 583 * to walk the file list looking for them. :-/ 584 */ 585 mutex_enter(&filelist_lock); 586 LIST_FOREACH_SAFE(fp, &filehead, f_list, np) { 587 if (fp->f_count == 0 || fp->f_type != DTYPE_SOCKET || 588 fp->f_socket == NULL) 589 continue; 590 so = fp->f_socket; 591 if (so->so_type != type) 592 continue; 593 if (so->so_proto->pr_domain->dom_family != pf) 594 continue; 595 if (kauth_authorize_network(l->l_cred, KAUTH_NETWORK_SOCKET, 596 KAUTH_REQ_NETWORK_SOCKET_CANSEE, so, NULL, NULL) != 0) 597 continue; 598 if (len >= elem_size && elem_count > 0) { 599 mutex_enter(&fp->f_lock); 600 /* 601 * Do not add references, if the count reached 0. 602 * Since the check above has been performed without 603 * locking, it must be rechecked here as a concurrent 604 * closef could have reduced it. 605 */ 606 if (fp->f_count == 0) { 607 mutex_exit(&fp->f_lock); 608 continue; 609 } 610 fp->f_count++; 611 mutex_exit(&fp->f_lock); 612 LIST_INSERT_AFTER(fp, dfp, f_list); 613 mutex_exit(&filelist_lock); 614 sysctl_dounpcb(&pcb, so); 615 error = copyout(&pcb, dp, out_size); 616 closef(fp); 617 mutex_enter(&filelist_lock); 618 np = LIST_NEXT(dfp, f_list); 619 LIST_REMOVE(dfp, f_list); 620 if (error) 621 break; 622 dp += elem_size; 623 len -= elem_size; 624 } 625 needed += elem_size; 626 if (elem_count > 0 && elem_count != INT_MAX) 627 elem_count--; 628 } 629 mutex_exit(&filelist_lock); 630 fputdummy(dfp); 631 *oldlenp = needed; 632 if (oldp == NULL) 633 *oldlenp += PCB_SLOP * sizeof(struct kinfo_pcb); 634 sysctl_relock(); 635 636 return error; 637 } 638 639 static void 640 sysctl_net_setup(void) 641 { 642 643 KASSERT(domain_sysctllog == NULL); 644 sysctl_createv(&domain_sysctllog, 0, NULL, NULL, 645 CTLFLAG_PERMANENT, 646 CTLTYPE_NODE, "local", 647 SYSCTL_DESCR("PF_LOCAL related settings"), 648 NULL, 0, NULL, 0, 649 CTL_NET, PF_LOCAL, CTL_EOL); 650 sysctl_createv(&domain_sysctllog, 0, NULL, NULL, 651 CTLFLAG_PERMANENT, 652 CTLTYPE_NODE, "stream", 653 SYSCTL_DESCR("SOCK_STREAM settings"), 654 NULL, 0, NULL, 0, 655 CTL_NET, PF_LOCAL, SOCK_STREAM, CTL_EOL); 656 sysctl_createv(&domain_sysctllog, 0, NULL, NULL, 657 CTLFLAG_PERMANENT, 658 CTLTYPE_NODE, "seqpacket", 659 SYSCTL_DESCR("SOCK_SEQPACKET settings"), 660 NULL, 0, NULL, 0, 661 CTL_NET, PF_LOCAL, SOCK_SEQPACKET, CTL_EOL); 662 sysctl_createv(&domain_sysctllog, 0, NULL, NULL, 663 CTLFLAG_PERMANENT, 664 CTLTYPE_NODE, "dgram", 665 SYSCTL_DESCR("SOCK_DGRAM settings"), 666 NULL, 0, NULL, 0, 667 CTL_NET, PF_LOCAL, SOCK_DGRAM, CTL_EOL); 668 669 sysctl_createv(&domain_sysctllog, 0, NULL, NULL, 670 CTLFLAG_PERMANENT, 671 CTLTYPE_STRUCT, "pcblist", 672 SYSCTL_DESCR("SOCK_STREAM protocol control block list"), 673 sysctl_unpcblist, 0, NULL, 0, 674 CTL_NET, PF_LOCAL, SOCK_STREAM, CTL_CREATE, CTL_EOL); 675 sysctl_createv(&domain_sysctllog, 0, NULL, NULL, 676 CTLFLAG_PERMANENT, 677 CTLTYPE_STRUCT, "pcblist", 678 SYSCTL_DESCR("SOCK_SEQPACKET protocol control " 679 "block list"), 680 sysctl_unpcblist, 0, NULL, 0, 681 CTL_NET, PF_LOCAL, SOCK_SEQPACKET, CTL_CREATE, CTL_EOL); 682 sysctl_createv(&domain_sysctllog, 0, NULL, NULL, 683 CTLFLAG_PERMANENT, 684 CTLTYPE_STRUCT, "pcblist", 685 SYSCTL_DESCR("SOCK_DGRAM protocol control block list"), 686 sysctl_unpcblist, 0, NULL, 0, 687 CTL_NET, PF_LOCAL, SOCK_DGRAM, CTL_CREATE, CTL_EOL); 688 unp_sysctl_create(&domain_sysctllog); 689 } 690 691 void 692 pfctlinput(int cmd, const struct sockaddr *sa) 693 { 694 struct domain *dp; 695 const struct protosw *pr; 696 697 DOMAIN_FOREACH(dp) { 698 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) { 699 if (pr->pr_ctlinput != NULL) 700 (*pr->pr_ctlinput)(cmd, sa, NULL); 701 } 702 } 703 } 704 705 void 706 pfctlinput2(int cmd, const struct sockaddr *sa, void *ctlparam) 707 { 708 struct domain *dp; 709 const struct protosw *pr; 710 711 if (sa == NULL) 712 return; 713 714 DOMAIN_FOREACH(dp) { 715 /* 716 * the check must be made by xx_ctlinput() anyways, to 717 * make sure we use data item pointed to by ctlparam in 718 * correct way. the following check is made just for safety. 719 */ 720 if (dp->dom_family != sa->sa_family) 721 continue; 722 723 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) { 724 if (pr->pr_ctlinput != NULL) 725 (*pr->pr_ctlinput)(cmd, sa, ctlparam); 726 } 727 } 728 } 729 730 void 731 pfslowtimo(void *arg) 732 { 733 struct domain *dp; 734 const struct protosw *pr; 735 736 pfslowtimo_now++; 737 738 DOMAIN_FOREACH(dp) { 739 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 740 if (pr->pr_slowtimo) 741 (*pr->pr_slowtimo)(); 742 } 743 callout_schedule(&pfslowtimo_ch, hz / PR_SLOWHZ); 744 } 745 746 void 747 pffasttimo(void *arg) 748 { 749 struct domain *dp; 750 const struct protosw *pr; 751 752 pffasttimo_now++; 753 754 DOMAIN_FOREACH(dp) { 755 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 756 if (pr->pr_fasttimo) 757 (*pr->pr_fasttimo)(); 758 } 759 callout_schedule(&pffasttimo_ch, hz / PR_FASTHZ); 760 } 761