123416Smckusick /* 223416Smckusick * Copyright (c) 1982 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*25765Skarels * @(#)uipc_domain.c 6.9 (Berkeley) 01/08/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); 29*25765Skarels #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 } 489161Ssam pffasttimo(); 499161Ssam pfslowtimo(); 509008Sroot } 519008Sroot 529008Sroot struct protosw * 539008Sroot pffindtype(family, type) 549008Sroot int family, type; 559008Sroot { 569008Sroot register struct domain *dp; 579008Sroot register struct protosw *pr; 589008Sroot 599008Sroot for (dp = domains; dp; dp = dp->dom_next) 609008Sroot if (dp->dom_family == family) 619008Sroot goto found; 629008Sroot return (0); 639008Sroot found: 649008Sroot for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 6511569Ssam if (pr->pr_type && pr->pr_type == type) 669008Sroot return (pr); 679008Sroot return (0); 689008Sroot } 699008Sroot 709008Sroot struct protosw * 7121766Skarels pffindproto(family, protocol, type) 7221766Skarels int family, protocol, type; 739008Sroot { 749008Sroot register struct domain *dp; 759008Sroot register struct protosw *pr; 7621766Skarels struct protosw *maybe = 0; 779008Sroot 789008Sroot if (family == 0) 799008Sroot return (0); 809008Sroot for (dp = domains; dp; dp = dp->dom_next) 819008Sroot if (dp->dom_family == family) 829008Sroot goto found; 839008Sroot return (0); 849008Sroot found: 8521766Skarels for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) { 8624519Skarels if ((pr->pr_protocol == protocol) && (pr->pr_type == type)) 879008Sroot return (pr); 8824519Skarels 8921766Skarels if (type == SOCK_RAW && pr->pr_type == SOCK_RAW && 9021766Skarels pr->pr_protocol == 0 && maybe == (struct protosw *)0) 9121766Skarels maybe = pr; 9221766Skarels } 9321766Skarels return (maybe); 949008Sroot } 959008Sroot 9624767Skarels pfctlinput(cmd, sa) 979008Sroot int cmd; 9824767Skarels struct sockaddr *sa; 999008Sroot { 1009008Sroot register struct domain *dp; 1019008Sroot register struct protosw *pr; 1029008Sroot 1039008Sroot for (dp = domains; dp; dp = dp->dom_next) 1049008Sroot for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 1059008Sroot if (pr->pr_ctlinput) 10624767Skarels (*pr->pr_ctlinput)(cmd, sa); 1079008Sroot } 1089008Sroot 1099008Sroot pfslowtimo() 1109008Sroot { 1119008Sroot register struct domain *dp; 1129008Sroot register struct protosw *pr; 1139008Sroot 1149008Sroot for (dp = domains; dp; dp = dp->dom_next) 1159008Sroot for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 1169008Sroot if (pr->pr_slowtimo) 1179008Sroot (*pr->pr_slowtimo)(); 1189161Ssam timeout(pfslowtimo, (caddr_t)0, hz/2); 1199008Sroot } 1209008Sroot 1219008Sroot pffasttimo() 1229008Sroot { 1239008Sroot register struct domain *dp; 1249008Sroot register struct protosw *pr; 1259008Sroot 1269008Sroot for (dp = domains; dp; dp = dp->dom_next) 1279008Sroot for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 1289008Sroot if (pr->pr_fasttimo) 1299008Sroot (*pr->pr_fasttimo)(); 1309161Ssam timeout(pffasttimo, (caddr_t)0, hz/5); 1319008Sroot } 132