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