123416Smckusick /* 229123Smckusick * Copyright (c) 1982, 1986 Regents of the University of California. 3*33187Sbostic * All rights reserved. 423416Smckusick * 5*33187Sbostic * Redistribution and use in source and binary forms are permitted 6*33187Sbostic * provided that this notice is preserved and that due credit is given 7*33187Sbostic * to the University of California at Berkeley. The name of the University 8*33187Sbostic * may not be used to endorse or promote products derived from this 9*33187Sbostic * software without specific prior written permission. This software 10*33187Sbostic * is provided ``as is'' without express or implied warranty. 11*33187Sbostic * 12*33187Sbostic * @(#)uipc_domain.c 7.2 (Berkeley) 12/30/87 1323416Smckusick */ 147425Sroot 1517102Sbloom #include "param.h" 1617102Sbloom #include "socket.h" 1717102Sbloom #include "protosw.h" 1817102Sbloom #include "domain.h" 1917102Sbloom #include "time.h" 2017102Sbloom #include "kernel.h" 217425Sroot 229008Sroot #define ADDDOMAIN(x) { \ 239008Sroot extern struct domain x/**/domain; \ 249008Sroot x/**/domain.dom_next = domains; \ 259008Sroot domains = &x/**/domain; \ 269008Sroot } 279008Sroot 289008Sroot domaininit() 297500Sroot { 309161Ssam register struct domain *dp; 319161Ssam register struct protosw *pr; 327500Sroot 339161Ssam #ifndef lint 349008Sroot ADDDOMAIN(unix); 3525765Skarels #ifdef INET 369008Sroot ADDDOMAIN(inet); 379008Sroot #endif 3818816Ssklower #ifdef NS 3918816Ssklower ADDDOMAIN(ns); 4018816Ssklower #endif 4110025Ssam #include "imp.h" 4210025Ssam #if NIMP > 0 439008Sroot ADDDOMAIN(imp); 449008Sroot #endif 459161Ssam #endif 469008Sroot 4716993Skarels for (dp = domains; dp; dp = dp->dom_next) { 4816993Skarels if (dp->dom_init) 4916993Skarels (*dp->dom_init)(); 509008Sroot for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 519008Sroot if (pr->pr_init) 529008Sroot (*pr->pr_init)(); 5316993Skarels } 5428884Skarels null_init(); 559161Ssam pffasttimo(); 569161Ssam pfslowtimo(); 579008Sroot } 589008Sroot 599008Sroot struct protosw * 609008Sroot pffindtype(family, type) 619008Sroot int family, type; 629008Sroot { 639008Sroot register struct domain *dp; 649008Sroot register struct protosw *pr; 659008Sroot 669008Sroot for (dp = domains; dp; dp = dp->dom_next) 679008Sroot if (dp->dom_family == family) 689008Sroot goto found; 699008Sroot return (0); 709008Sroot found: 719008Sroot for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 7211569Ssam if (pr->pr_type && pr->pr_type == type) 739008Sroot return (pr); 749008Sroot return (0); 759008Sroot } 769008Sroot 779008Sroot struct protosw * 7821766Skarels pffindproto(family, protocol, type) 7921766Skarels int family, protocol, type; 809008Sroot { 819008Sroot register struct domain *dp; 829008Sroot register struct protosw *pr; 8321766Skarels struct protosw *maybe = 0; 849008Sroot 859008Sroot if (family == 0) 869008Sroot return (0); 879008Sroot for (dp = domains; dp; dp = dp->dom_next) 889008Sroot if (dp->dom_family == family) 899008Sroot goto found; 909008Sroot return (0); 919008Sroot found: 9221766Skarels for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) { 9324519Skarels if ((pr->pr_protocol == protocol) && (pr->pr_type == type)) 949008Sroot return (pr); 9524519Skarels 9621766Skarels if (type == SOCK_RAW && pr->pr_type == SOCK_RAW && 9721766Skarels pr->pr_protocol == 0 && maybe == (struct protosw *)0) 9821766Skarels maybe = pr; 9921766Skarels } 10021766Skarels return (maybe); 1019008Sroot } 1029008Sroot 10324767Skarels pfctlinput(cmd, sa) 1049008Sroot int cmd; 10524767Skarels struct sockaddr *sa; 1069008Sroot { 1079008Sroot register struct domain *dp; 1089008Sroot register struct protosw *pr; 1099008Sroot 1109008Sroot for (dp = domains; dp; dp = dp->dom_next) 1119008Sroot for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 1129008Sroot if (pr->pr_ctlinput) 11324767Skarels (*pr->pr_ctlinput)(cmd, sa); 1149008Sroot } 1159008Sroot 1169008Sroot pfslowtimo() 1179008Sroot { 1189008Sroot register struct domain *dp; 1199008Sroot register struct protosw *pr; 1209008Sroot 1219008Sroot for (dp = domains; dp; dp = dp->dom_next) 1229008Sroot for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 1239008Sroot if (pr->pr_slowtimo) 1249008Sroot (*pr->pr_slowtimo)(); 1259161Ssam timeout(pfslowtimo, (caddr_t)0, hz/2); 1269008Sroot } 1279008Sroot 1289008Sroot pffasttimo() 1299008Sroot { 1309008Sroot register struct domain *dp; 1319008Sroot register struct protosw *pr; 1329008Sroot 1339008Sroot for (dp = domains; dp; dp = dp->dom_next) 1349008Sroot for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 1359008Sroot if (pr->pr_fasttimo) 1369008Sroot (*pr->pr_fasttimo)(); 1379161Ssam timeout(pffasttimo, (caddr_t)0, hz/5); 1389008Sroot } 139