123416Smckusick /* 229123Smckusick * Copyright (c) 1982, 1986 Regents of the University of California. 333187Sbostic * All rights reserved. 423416Smckusick * 533187Sbostic * Redistribution and use in source and binary forms are permitted 634860Sbostic * provided that the above copyright notice and this paragraph are 734860Sbostic * duplicated in all such forms and that any documentation, 834860Sbostic * advertising materials, and other materials related to such 934860Sbostic * distribution and use acknowledge that the software was developed 1034860Sbostic * by the University of California, Berkeley. The name of the 1134860Sbostic * University may not be used to endorse or promote products derived 1234860Sbostic * from this software without specific prior written permission. 1334860Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1434860Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1534860Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1633187Sbostic * 17*41997Smckusick * @(#)uipc_domain.c 7.6 (Berkeley) 05/15/90 1823416Smckusick */ 197425Sroot 2017102Sbloom #include "param.h" 2117102Sbloom #include "socket.h" 2217102Sbloom #include "protosw.h" 2317102Sbloom #include "domain.h" 2437330Skarels #include "mbuf.h" 2517102Sbloom #include "time.h" 2617102Sbloom #include "kernel.h" 277425Sroot 289008Sroot #define ADDDOMAIN(x) { \ 299008Sroot extern struct domain x/**/domain; \ 309008Sroot x/**/domain.dom_next = domains; \ 319008Sroot domains = &x/**/domain; \ 329008Sroot } 339008Sroot 349008Sroot domaininit() 357500Sroot { 369161Ssam register struct domain *dp; 379161Ssam register struct protosw *pr; 387500Sroot 399161Ssam #ifndef lint 409008Sroot ADDDOMAIN(unix); 4137330Skarels ADDDOMAIN(route); 4225765Skarels #ifdef INET 439008Sroot ADDDOMAIN(inet); 449008Sroot #endif 4518816Ssklower #ifdef NS 4618816Ssklower ADDDOMAIN(ns); 4718816Ssklower #endif 4837330Skarels #ifdef ISO 4937330Skarels ADDDOMAIN(iso); 5037330Skarels #endif 51*41997Smckusick #ifdef RMP 52*41997Smckusick ADDDOMAIN(rmp); 53*41997Smckusick #endif 5410025Ssam #include "imp.h" 5510025Ssam #if NIMP > 0 569008Sroot ADDDOMAIN(imp); 579008Sroot #endif 589161Ssam #endif 599008Sroot 6016993Skarels for (dp = domains; dp; dp = dp->dom_next) { 6116993Skarels if (dp->dom_init) 6216993Skarels (*dp->dom_init)(); 639008Sroot for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 649008Sroot if (pr->pr_init) 659008Sroot (*pr->pr_init)(); 6616993Skarels } 6737330Skarels 6837330Skarels if (max_linkhdr < 16) /* XXX */ 6937330Skarels max_linkhdr = 16; 7037330Skarels max_hdr = max_linkhdr + max_protohdr; 7137330Skarels max_datalen = MHLEN - max_hdr; 729161Ssam pffasttimo(); 739161Ssam pfslowtimo(); 749008Sroot } 759008Sroot 769008Sroot struct protosw * 779008Sroot pffindtype(family, type) 789008Sroot int family, type; 799008Sroot { 809008Sroot register struct domain *dp; 819008Sroot register struct protosw *pr; 829008Sroot 839008Sroot for (dp = domains; dp; dp = dp->dom_next) 849008Sroot if (dp->dom_family == family) 859008Sroot goto found; 869008Sroot return (0); 879008Sroot found: 889008Sroot for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 8911569Ssam if (pr->pr_type && pr->pr_type == type) 909008Sroot return (pr); 919008Sroot return (0); 929008Sroot } 939008Sroot 949008Sroot struct protosw * 9521766Skarels pffindproto(family, protocol, type) 9621766Skarels int family, protocol, type; 979008Sroot { 989008Sroot register struct domain *dp; 999008Sroot register struct protosw *pr; 10021766Skarels struct protosw *maybe = 0; 1019008Sroot 1029008Sroot if (family == 0) 1039008Sroot return (0); 1049008Sroot for (dp = domains; dp; dp = dp->dom_next) 1059008Sroot if (dp->dom_family == family) 1069008Sroot goto found; 1079008Sroot return (0); 1089008Sroot found: 10921766Skarels for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) { 11024519Skarels if ((pr->pr_protocol == protocol) && (pr->pr_type == type)) 1119008Sroot return (pr); 11224519Skarels 11321766Skarels if (type == SOCK_RAW && pr->pr_type == SOCK_RAW && 11421766Skarels pr->pr_protocol == 0 && maybe == (struct protosw *)0) 11521766Skarels maybe = pr; 11621766Skarels } 11721766Skarels return (maybe); 1189008Sroot } 1199008Sroot 12024767Skarels pfctlinput(cmd, sa) 1219008Sroot int cmd; 12224767Skarels struct sockaddr *sa; 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_ctlinput) 13040668Skarels (*pr->pr_ctlinput)(cmd, sa, (caddr_t) 0); 1319008Sroot } 1329008Sroot 1339008Sroot pfslowtimo() 1349008Sroot { 1359008Sroot register struct domain *dp; 1369008Sroot register struct protosw *pr; 1379008Sroot 1389008Sroot for (dp = domains; dp; dp = dp->dom_next) 1399008Sroot for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 1409008Sroot if (pr->pr_slowtimo) 1419008Sroot (*pr->pr_slowtimo)(); 1429161Ssam timeout(pfslowtimo, (caddr_t)0, hz/2); 1439008Sroot } 1449008Sroot 1459008Sroot pffasttimo() 1469008Sroot { 1479008Sroot register struct domain *dp; 1489008Sroot register struct protosw *pr; 1499008Sroot 1509008Sroot for (dp = domains; dp; dp = dp->dom_next) 1519008Sroot for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 1529008Sroot if (pr->pr_fasttimo) 1539008Sroot (*pr->pr_fasttimo)(); 1549161Ssam timeout(pffasttimo, (caddr_t)0, hz/5); 1559008Sroot } 156