1 /* 2 * Copyright (c) 1982, 1986 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific prior written permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 * 12 * @(#)uipc_domain.c 7.2 (Berkeley) 12/30/87 13 */ 14 15 #include "param.h" 16 #include "socket.h" 17 #include "protosw.h" 18 #include "domain.h" 19 #include "time.h" 20 #include "kernel.h" 21 22 #define ADDDOMAIN(x) { \ 23 extern struct domain x/**/domain; \ 24 x/**/domain.dom_next = domains; \ 25 domains = &x/**/domain; \ 26 } 27 28 domaininit() 29 { 30 register struct domain *dp; 31 register struct protosw *pr; 32 33 #ifndef lint 34 ADDDOMAIN(unix); 35 #ifdef INET 36 ADDDOMAIN(inet); 37 #endif 38 #ifdef NS 39 ADDDOMAIN(ns); 40 #endif 41 #include "imp.h" 42 #if NIMP > 0 43 ADDDOMAIN(imp); 44 #endif 45 #endif 46 47 for (dp = domains; dp; dp = dp->dom_next) { 48 if (dp->dom_init) 49 (*dp->dom_init)(); 50 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 51 if (pr->pr_init) 52 (*pr->pr_init)(); 53 } 54 null_init(); 55 pffasttimo(); 56 pfslowtimo(); 57 } 58 59 struct protosw * 60 pffindtype(family, type) 61 int family, type; 62 { 63 register struct domain *dp; 64 register struct protosw *pr; 65 66 for (dp = domains; dp; dp = dp->dom_next) 67 if (dp->dom_family == family) 68 goto found; 69 return (0); 70 found: 71 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 72 if (pr->pr_type && pr->pr_type == type) 73 return (pr); 74 return (0); 75 } 76 77 struct protosw * 78 pffindproto(family, protocol, type) 79 int family, protocol, type; 80 { 81 register struct domain *dp; 82 register struct protosw *pr; 83 struct protosw *maybe = 0; 84 85 if (family == 0) 86 return (0); 87 for (dp = domains; dp; dp = dp->dom_next) 88 if (dp->dom_family == family) 89 goto found; 90 return (0); 91 found: 92 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) { 93 if ((pr->pr_protocol == protocol) && (pr->pr_type == type)) 94 return (pr); 95 96 if (type == SOCK_RAW && pr->pr_type == SOCK_RAW && 97 pr->pr_protocol == 0 && maybe == (struct protosw *)0) 98 maybe = pr; 99 } 100 return (maybe); 101 } 102 103 pfctlinput(cmd, sa) 104 int cmd; 105 struct sockaddr *sa; 106 { 107 register struct domain *dp; 108 register struct protosw *pr; 109 110 for (dp = domains; dp; dp = dp->dom_next) 111 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 112 if (pr->pr_ctlinput) 113 (*pr->pr_ctlinput)(cmd, sa); 114 } 115 116 pfslowtimo() 117 { 118 register struct domain *dp; 119 register struct protosw *pr; 120 121 for (dp = domains; dp; dp = dp->dom_next) 122 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 123 if (pr->pr_slowtimo) 124 (*pr->pr_slowtimo)(); 125 timeout(pfslowtimo, (caddr_t)0, hz/2); 126 } 127 128 pffasttimo() 129 { 130 register struct domain *dp; 131 register struct protosw *pr; 132 133 for (dp = domains; dp; dp = dp->dom_next) 134 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 135 if (pr->pr_fasttimo) 136 (*pr->pr_fasttimo)(); 137 timeout(pffasttimo, (caddr_t)0, hz/5); 138 } 139