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