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 the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 * 17 * @(#)uipc_domain.c 7.3 (Berkeley) 06/29/88 18 */ 19 20 #include "param.h" 21 #include "socket.h" 22 #include "protosw.h" 23 #include "domain.h" 24 #include "time.h" 25 #include "kernel.h" 26 27 #define ADDDOMAIN(x) { \ 28 extern struct domain x/**/domain; \ 29 x/**/domain.dom_next = domains; \ 30 domains = &x/**/domain; \ 31 } 32 33 domaininit() 34 { 35 register struct domain *dp; 36 register struct protosw *pr; 37 38 #ifndef lint 39 ADDDOMAIN(unix); 40 #ifdef INET 41 ADDDOMAIN(inet); 42 #endif 43 #ifdef NS 44 ADDDOMAIN(ns); 45 #endif 46 #include "imp.h" 47 #if NIMP > 0 48 ADDDOMAIN(imp); 49 #endif 50 #endif 51 52 for (dp = domains; dp; dp = dp->dom_next) { 53 if (dp->dom_init) 54 (*dp->dom_init)(); 55 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 56 if (pr->pr_init) 57 (*pr->pr_init)(); 58 } 59 null_init(); 60 pffasttimo(); 61 pfslowtimo(); 62 } 63 64 struct protosw * 65 pffindtype(family, type) 66 int family, type; 67 { 68 register struct domain *dp; 69 register struct protosw *pr; 70 71 for (dp = domains; dp; dp = dp->dom_next) 72 if (dp->dom_family == family) 73 goto found; 74 return (0); 75 found: 76 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 77 if (pr->pr_type && pr->pr_type == type) 78 return (pr); 79 return (0); 80 } 81 82 struct protosw * 83 pffindproto(family, protocol, type) 84 int family, protocol, type; 85 { 86 register struct domain *dp; 87 register struct protosw *pr; 88 struct protosw *maybe = 0; 89 90 if (family == 0) 91 return (0); 92 for (dp = domains; dp; dp = dp->dom_next) 93 if (dp->dom_family == family) 94 goto found; 95 return (0); 96 found: 97 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) { 98 if ((pr->pr_protocol == protocol) && (pr->pr_type == type)) 99 return (pr); 100 101 if (type == SOCK_RAW && pr->pr_type == SOCK_RAW && 102 pr->pr_protocol == 0 && maybe == (struct protosw *)0) 103 maybe = pr; 104 } 105 return (maybe); 106 } 107 108 pfctlinput(cmd, sa) 109 int cmd; 110 struct sockaddr *sa; 111 { 112 register struct domain *dp; 113 register struct protosw *pr; 114 115 for (dp = domains; dp; dp = dp->dom_next) 116 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 117 if (pr->pr_ctlinput) 118 (*pr->pr_ctlinput)(cmd, sa); 119 } 120 121 pfslowtimo() 122 { 123 register struct domain *dp; 124 register struct protosw *pr; 125 126 for (dp = domains; dp; dp = dp->dom_next) 127 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 128 if (pr->pr_slowtimo) 129 (*pr->pr_slowtimo)(); 130 timeout(pfslowtimo, (caddr_t)0, hz/2); 131 } 132 133 pffasttimo() 134 { 135 register struct domain *dp; 136 register struct protosw *pr; 137 138 for (dp = domains; dp; dp = dp->dom_next) 139 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 140 if (pr->pr_fasttimo) 141 (*pr->pr_fasttimo)(); 142 timeout(pffasttimo, (caddr_t)0, hz/5); 143 } 144