123416Smckusick /* 2*29123Smckusick * Copyright (c) 1982, 1986 Regents of the University of California. 323416Smckusick * All rights reserved. The Berkeley software License Agreement 423416Smckusick * specifies the terms and conditions for redistribution. 523416Smckusick * 6*29123Smckusick * @(#)uipc_domain.c 7.1 (Berkeley) 06/05/86 723416Smckusick */ 87425Sroot 917102Sbloom #include "param.h" 1017102Sbloom #include "socket.h" 1117102Sbloom #include "protosw.h" 1217102Sbloom #include "domain.h" 1317102Sbloom #include "time.h" 1417102Sbloom #include "kernel.h" 157425Sroot 169008Sroot #define ADDDOMAIN(x) { \ 179008Sroot extern struct domain x/**/domain; \ 189008Sroot x/**/domain.dom_next = domains; \ 199008Sroot domains = &x/**/domain; \ 209008Sroot } 219008Sroot 229008Sroot domaininit() 237500Sroot { 249161Ssam register struct domain *dp; 259161Ssam register struct protosw *pr; 267500Sroot 279161Ssam #ifndef lint 289008Sroot ADDDOMAIN(unix); 2925765Skarels #ifdef INET 309008Sroot ADDDOMAIN(inet); 319008Sroot #endif 3218816Ssklower #ifdef NS 3318816Ssklower ADDDOMAIN(ns); 3418816Ssklower #endif 3510025Ssam #include "imp.h" 3610025Ssam #if NIMP > 0 379008Sroot ADDDOMAIN(imp); 389008Sroot #endif 399161Ssam #endif 409008Sroot 4116993Skarels for (dp = domains; dp; dp = dp->dom_next) { 4216993Skarels if (dp->dom_init) 4316993Skarels (*dp->dom_init)(); 449008Sroot for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 459008Sroot if (pr->pr_init) 469008Sroot (*pr->pr_init)(); 4716993Skarels } 4828884Skarels null_init(); 499161Ssam pffasttimo(); 509161Ssam pfslowtimo(); 519008Sroot } 529008Sroot 539008Sroot struct protosw * 549008Sroot pffindtype(family, type) 559008Sroot int family, type; 569008Sroot { 579008Sroot register struct domain *dp; 589008Sroot register struct protosw *pr; 599008Sroot 609008Sroot for (dp = domains; dp; dp = dp->dom_next) 619008Sroot if (dp->dom_family == family) 629008Sroot goto found; 639008Sroot return (0); 649008Sroot found: 659008Sroot for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 6611569Ssam if (pr->pr_type && pr->pr_type == type) 679008Sroot return (pr); 689008Sroot return (0); 699008Sroot } 709008Sroot 719008Sroot struct protosw * 7221766Skarels pffindproto(family, protocol, type) 7321766Skarels int family, protocol, type; 749008Sroot { 759008Sroot register struct domain *dp; 769008Sroot register struct protosw *pr; 7721766Skarels struct protosw *maybe = 0; 789008Sroot 799008Sroot if (family == 0) 809008Sroot return (0); 819008Sroot for (dp = domains; dp; dp = dp->dom_next) 829008Sroot if (dp->dom_family == family) 839008Sroot goto found; 849008Sroot return (0); 859008Sroot found: 8621766Skarels for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) { 8724519Skarels if ((pr->pr_protocol == protocol) && (pr->pr_type == type)) 889008Sroot return (pr); 8924519Skarels 9021766Skarels if (type == SOCK_RAW && pr->pr_type == SOCK_RAW && 9121766Skarels pr->pr_protocol == 0 && maybe == (struct protosw *)0) 9221766Skarels maybe = pr; 9321766Skarels } 9421766Skarels return (maybe); 959008Sroot } 969008Sroot 9724767Skarels pfctlinput(cmd, sa) 989008Sroot int cmd; 9924767Skarels struct sockaddr *sa; 1009008Sroot { 1019008Sroot register struct domain *dp; 1029008Sroot register struct protosw *pr; 1039008Sroot 1049008Sroot for (dp = domains; dp; dp = dp->dom_next) 1059008Sroot for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 1069008Sroot if (pr->pr_ctlinput) 10724767Skarels (*pr->pr_ctlinput)(cmd, sa); 1089008Sroot } 1099008Sroot 1109008Sroot pfslowtimo() 1119008Sroot { 1129008Sroot register struct domain *dp; 1139008Sroot register struct protosw *pr; 1149008Sroot 1159008Sroot for (dp = domains; dp; dp = dp->dom_next) 1169008Sroot for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 1179008Sroot if (pr->pr_slowtimo) 1189008Sroot (*pr->pr_slowtimo)(); 1199161Ssam timeout(pfslowtimo, (caddr_t)0, hz/2); 1209008Sroot } 1219008Sroot 1229008Sroot pffasttimo() 1239008Sroot { 1249008Sroot register struct domain *dp; 1259008Sroot register struct protosw *pr; 1269008Sroot 1279008Sroot for (dp = domains; dp; dp = dp->dom_next) 1289008Sroot for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 1299008Sroot if (pr->pr_fasttimo) 1309008Sroot (*pr->pr_fasttimo)(); 1319161Ssam timeout(pffasttimo, (caddr_t)0, hz/5); 1329008Sroot } 133