1 /* uipc_proto.c 4.23 82/09/06 */ 2 3 #include "../h/param.h" 4 #include "../h/socket.h" 5 #include "../h/protosw.h" 6 #include "../h/mbuf.h" 7 #include <time.h> 8 #include "../h/kernel.h" 9 #include "../net/in.h" 10 #include "../net/in_systm.h" 11 12 /* 13 * Protocol configuration table and routines to search it. 14 * 15 * SHOULD INCLUDE A HEADER FILE GIVING DESIRED PROTOCOLS 16 */ 17 18 /* 19 * Local protocol handler. 20 */ 21 int piusrreq(); 22 23 /* 24 * TCP/IP protocol family: IP, ICMP, UDP, TCP. 25 */ 26 int ip_output(); 27 int ip_init(),ip_slowtimo(),ip_drain(); 28 int icmp_input(); 29 int udp_input(),udp_ctlinput(); 30 int udp_usrreq(); 31 int udp_init(); 32 int tcp_input(),tcp_ctlinput(); 33 int tcp_usrreq(); 34 int tcp_init(),tcp_fasttimo(),tcp_slowtimo(),tcp_drain(); 35 int rip_input(),rip_output(); 36 37 /* 38 * IMP protocol family: raw interface. 39 * Using the raw interface entry to get the timer routine 40 * in is a kludge. 41 */ 42 #include "imp.h" 43 #if NIMP > 0 44 int rimp_output(), hostslowtimo(); 45 #endif 46 47 /* 48 * PUP-I protocol family: raw interface 49 */ 50 #include "pup.h" 51 #if NPUP > 0 52 int rpup_output(); 53 #endif 54 55 /* 56 * Sundries. 57 */ 58 int raw_init(),raw_usrreq(),raw_input(),raw_ctlinput(); 59 60 struct protosw protosw[] = { 61 { SOCK_STREAM, PF_UNIX, 0, PR_CONNREQUIRED, 62 0, 0, 0, 0, 63 piusrreq, 64 0, 0, 0, 0, 65 }, 66 { SOCK_DGRAM, PF_UNIX, 0, PR_ATOMIC|PR_ADDR, 67 0, 0, 0, 0, 68 piusrreq, 69 0, 0, 0, 0, 70 }, 71 { SOCK_RDM, PF_UNIX, 0, PR_ATOMIC|PR_ADDR, 72 0, 0, 0, 0, 73 piusrreq, 74 0, 0, 0, 0, 75 }, 76 { SOCK_RAW, PF_UNIX, 0, PR_ATOMIC|PR_ADDR, 77 0, 0, 0, 0, 78 piusrreq, 79 0, 0, 0, 0, 80 }, 81 { 0, 0, 0, 0, 82 0, ip_output, 0, 0, 83 0, 84 ip_init, 0, ip_slowtimo, ip_drain, 85 }, 86 { 0, PF_INET, IPPROTO_ICMP, 0, 87 icmp_input, 0, 0, 0, 88 0, 89 0, 0, 0, 0, 90 }, 91 { SOCK_DGRAM, PF_INET, IPPROTO_UDP, PR_ATOMIC|PR_ADDR, 92 udp_input, 0, udp_ctlinput, 0, 93 udp_usrreq, 94 udp_init, 0, 0, 0, 95 }, 96 { SOCK_STREAM, PF_INET, IPPROTO_TCP, PR_CONNREQUIRED|PR_WANTRCVD, 97 tcp_input, 0, tcp_ctlinput, 0, 98 tcp_usrreq, 99 tcp_init, tcp_fasttimo, tcp_slowtimo, tcp_drain, 100 }, 101 { 0, 0, 0, 0, 102 raw_input, 0, raw_ctlinput, 0, 103 raw_usrreq, 104 raw_init, 0, 0, 0, 105 }, 106 { SOCK_RAW, PF_INET, IPPROTO_RAW, PR_ATOMIC|PR_ADDR, 107 rip_input, rip_output, 0, 0, 108 raw_usrreq, 109 0, 0, 0, 0, 110 } 111 #if NIMP > 0 112 , 113 { SOCK_RAW, PF_IMPLINK, 0, PR_ATOMIC|PR_ADDR, 114 0, rimp_output, 0, 0, 115 raw_usrreq, 116 0, 0, hostslowtimo, 0, 117 } 118 #endif 119 #if NPUP > 0 120 , 121 { SOCK_RAW, PF_PUP, 0, PR_ATOMIC|PR_ADDR, 122 0, rpup_output, 0, 0, 123 raw_usrreq, 124 0, 0, 0, 0, 125 } 126 #endif 127 }; 128 129 #define NPROTOSW (sizeof(protosw) / sizeof(protosw[0])) 130 131 struct protosw *protoswLAST = &protosw[NPROTOSW-1]; 132 133 /* 134 * Operations on protocol table and protocol families. 135 */ 136 137 /* 138 * Initialize all protocols. 139 */ 140 pfinit() 141 { 142 register struct protosw *pr; 143 144 for (pr = protoswLAST; pr >= protosw; pr--) 145 if (pr->pr_init) 146 (*pr->pr_init)(); 147 pffasttimo(); 148 pfslowtimo(); 149 } 150 151 /* 152 * Find a standard protocol in a protocol family 153 * of a specific type. 154 */ 155 struct protosw * 156 pffindtype(family, type) 157 int family, type; 158 { 159 register struct protosw *pr; 160 161 if (family == 0) 162 return (0); 163 for (pr = protosw; pr <= protoswLAST; pr++) 164 if (pr->pr_family == family && pr->pr_type == type) 165 return (pr); 166 return (0); 167 } 168 169 /* 170 * Find a specified protocol in a specified protocol family. 171 */ 172 struct protosw * 173 pffindproto(family, protocol) 174 int family, protocol; 175 { 176 register struct protosw *pr; 177 178 if (family == 0) 179 return (0); 180 for (pr = protosw; pr <= protoswLAST; pr++) 181 if (pr->pr_family == family && pr->pr_protocol == protocol) 182 return (pr); 183 return (0); 184 } 185 186 pfctlinput(cmd, arg) 187 int cmd; 188 caddr_t arg; 189 { 190 register struct protosw *pr; 191 192 for (pr = protosw; pr <= protoswLAST; pr++) 193 if (pr->pr_ctlinput) 194 (*pr->pr_ctlinput)(cmd, arg); 195 } 196 197 /* 198 * Slow timeout on all protocols. 199 */ 200 pfslowtimo() 201 { 202 register struct protosw *pr; 203 204 for (pr = protoswLAST; pr >= protosw; pr--) 205 if (pr->pr_slowtimo) 206 (*pr->pr_slowtimo)(); 207 timeout(pfslowtimo, 0, hz / PR_SLOWHZ); 208 } 209 210 pffasttimo() 211 { 212 register struct protosw *pr; 213 214 for (pr = protoswLAST; pr >= protosw; pr--) 215 if (pr->pr_fasttimo) 216 (*pr->pr_fasttimo)(); 217 timeout(pffasttimo, 0, hz / PR_FASTHZ); 218 } 219