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*24767Skarels * @(#)uipc_domain.c 6.8 (Berkeley) 09/16/85 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*24767Skarels #if defined(INET) || defined(BBNNET) 309008Sroot ADDDOMAIN(inet); 319008Sroot #endif 3218816Ssklower #ifdef NS 3318816Ssklower ADDDOMAIN(ns); 3418816Ssklower #endif 359008Sroot #ifdef PUP 369008Sroot ADDDOMAIN(pup); 379008Sroot #endif 3810025Ssam #include "imp.h" 3910025Ssam #if NIMP > 0 409008Sroot ADDDOMAIN(imp); 419008Sroot #endif 429161Ssam #endif 439008Sroot 4416993Skarels for (dp = domains; dp; dp = dp->dom_next) { 4516993Skarels if (dp->dom_init) 4616993Skarels (*dp->dom_init)(); 479008Sroot for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 489008Sroot if (pr->pr_init) 499008Sroot (*pr->pr_init)(); 5016993Skarels } 519161Ssam pffasttimo(); 529161Ssam pfslowtimo(); 539008Sroot } 549008Sroot 559008Sroot struct protosw * 569008Sroot pffindtype(family, type) 579008Sroot int family, type; 589008Sroot { 599008Sroot register struct domain *dp; 609008Sroot register struct protosw *pr; 619008Sroot 629008Sroot for (dp = domains; dp; dp = dp->dom_next) 639008Sroot if (dp->dom_family == family) 649008Sroot goto found; 659008Sroot return (0); 669008Sroot found: 679008Sroot for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 6811569Ssam if (pr->pr_type && pr->pr_type == type) 699008Sroot return (pr); 709008Sroot return (0); 719008Sroot } 729008Sroot 739008Sroot struct protosw * 7421766Skarels pffindproto(family, protocol, type) 7521766Skarels int family, protocol, type; 769008Sroot { 779008Sroot register struct domain *dp; 789008Sroot register struct protosw *pr; 7921766Skarels struct protosw *maybe = 0; 809008Sroot 819008Sroot if (family == 0) 829008Sroot return (0); 839008Sroot for (dp = domains; dp; dp = dp->dom_next) 849008Sroot if (dp->dom_family == family) 859008Sroot goto found; 869008Sroot return (0); 879008Sroot found: 8821766Skarels for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) { 8924519Skarels if ((pr->pr_protocol == protocol) && (pr->pr_type == type)) 909008Sroot return (pr); 9124519Skarels 9221766Skarels if (type == SOCK_RAW && pr->pr_type == SOCK_RAW && 9321766Skarels pr->pr_protocol == 0 && maybe == (struct protosw *)0) 9421766Skarels maybe = pr; 9521766Skarels } 9621766Skarels return (maybe); 979008Sroot } 989008Sroot 99*24767Skarels pfctlinput(cmd, sa) 1009008Sroot int cmd; 101*24767Skarels struct sockaddr *sa; 1029008Sroot { 1039008Sroot register struct domain *dp; 1049008Sroot register struct protosw *pr; 1059008Sroot 1069008Sroot for (dp = domains; dp; dp = dp->dom_next) 1079008Sroot for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 1089008Sroot if (pr->pr_ctlinput) 109*24767Skarels (*pr->pr_ctlinput)(cmd, sa); 1109008Sroot } 1119008Sroot 1129008Sroot pfslowtimo() 1139008Sroot { 1149008Sroot register struct domain *dp; 1159008Sroot register struct protosw *pr; 1169008Sroot 1179008Sroot for (dp = domains; dp; dp = dp->dom_next) 1189008Sroot for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 1199008Sroot if (pr->pr_slowtimo) 1209008Sroot (*pr->pr_slowtimo)(); 1219161Ssam timeout(pfslowtimo, (caddr_t)0, hz/2); 1229008Sroot } 1239008Sroot 1249008Sroot pffasttimo() 1259008Sroot { 1269008Sroot register struct domain *dp; 1279008Sroot register struct protosw *pr; 1289008Sroot 1299008Sroot for (dp = domains; dp; dp = dp->dom_next) 1309008Sroot for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 1319008Sroot if (pr->pr_fasttimo) 1329008Sroot (*pr->pr_fasttimo)(); 1339161Ssam timeout(pffasttimo, (caddr_t)0, hz/5); 1349008Sroot } 135