1*6341Ssam /* uipc_proto.c 4.19 82/03/28 */ 24825Swnj 34787Swnj #include "../h/param.h" 44825Swnj #include "../h/socket.h" 54825Swnj #include "../h/protosw.h" 64825Swnj #include "../h/mbuf.h" 75091Swnj #include "../net/in.h" 85091Swnj #include "../net/in_systm.h" 94825Swnj 104787Swnj /* 114787Swnj * Protocol configuration table and routines to search it. 124890Swnj * 134890Swnj * SHOULD INCLUDE A HEADER FILE GIVING DESIRED PROTOCOLS 144787Swnj */ 154787Swnj 164787Swnj /* 174890Swnj * Local protocol handler. 184787Swnj */ 194927Swnj int piusrreq(); 204787Swnj 214787Swnj /* 224787Swnj * TCP/IP protocol family: IP, ICMP, UDP, TCP. 234787Swnj */ 245091Swnj int ip_output(); 254890Swnj int ip_init(),ip_slowtimo(),ip_drain(); 265170Swnj int icmp_input(),icmp_ctlinput(); 274890Swnj int icmp_drain(); 284890Swnj int udp_input(),udp_ctlinput(); 295170Swnj int udp_usrreq(); 304890Swnj int udp_init(); 314890Swnj int tcp_input(),tcp_ctlinput(); 325170Swnj int tcp_usrreq(); 334890Swnj int tcp_init(),tcp_fasttimo(),tcp_slowtimo(),tcp_drain(); 34*6341Ssam int rip_input(),rip_output(); 354787Swnj 365621Swnj /* 375621Swnj * IMP protocol family: raw interface 385621Swnj */ 395621Swnj #include "imp.h" 405621Swnj #if NIMP > 0 41*6341Ssam int rimp_output(); 425621Swnj #endif 435621Swnj 445621Swnj /* 455848Sroot * PUP-I protocol family: raw interface 465848Sroot */ 475848Sroot #include "pup.h" 485848Sroot #if NPUP > 0 49*6341Ssam int rpup_output(); 505848Sroot #endif 515848Sroot 525848Sroot /* 535621Swnj * Sundries. 545621Swnj */ 555621Swnj int raw_init(),raw_usrreq(),raw_input(); 565621Swnj 574787Swnj struct protosw protosw[] = { 585149Swnj { SOCK_STREAM, PF_UNIX, 0, PR_CONNREQUIRED, 594825Swnj 0, 0, 0, 0, 605149Swnj piusrreq, 614825Swnj 0, 0, 0, 0, 624890Swnj }, 635149Swnj { SOCK_DGRAM, PF_UNIX, 0, PR_ATOMIC|PR_ADDR, 644825Swnj 0, 0, 0, 0, 655149Swnj piusrreq, 664825Swnj 0, 0, 0, 0, 674890Swnj }, 685149Swnj { SOCK_RDM, PF_UNIX, 0, PR_ATOMIC|PR_ADDR, 694890Swnj 0, 0, 0, 0, 705149Swnj piusrreq, 714890Swnj 0, 0, 0, 0, 724890Swnj }, 735149Swnj { SOCK_RAW, PF_UNIX, 0, PR_ATOMIC|PR_ADDR, 744890Swnj 0, 0, 0, 0, 755149Swnj piusrreq, 764890Swnj 0, 0, 0, 0, 774890Swnj }, 784787Swnj { 0, 0, 0, 0, 795091Swnj 0, ip_output, 0, 0, 805149Swnj 0, 814890Swnj ip_init, 0, ip_slowtimo, ip_drain, 824890Swnj }, 834787Swnj { 0, 0, IPPROTO_ICMP, 0, 845170Swnj icmp_input, 0, icmp_ctlinput, 0, 855149Swnj 0, 864890Swnj 0, 0, 0, icmp_drain, 874890Swnj }, 884825Swnj { SOCK_DGRAM, PF_INET, IPPROTO_UDP, PR_ATOMIC|PR_ADDR, 894890Swnj udp_input, 0, udp_ctlinput, 0, 905149Swnj udp_usrreq, 914890Swnj udp_init, 0, 0, 0, 924890Swnj }, 935011Swnj { SOCK_STREAM, PF_INET, IPPROTO_TCP, PR_CONNREQUIRED|PR_WANTRCVD, 944890Swnj tcp_input, 0, tcp_ctlinput, 0, 955149Swnj tcp_usrreq, 964890Swnj tcp_init, tcp_fasttimo, tcp_slowtimo, tcp_drain, 974890Swnj }, 985621Swnj { 0, 0, 0, 0, 995621Swnj raw_input, 0, 0, 0, 1005621Swnj raw_usrreq, 1015621Swnj raw_init, 0, 0, 0, 1025621Swnj }, 1035644Ssam { SOCK_RAW, PF_INET, IPPROTO_RAW, PR_ATOMIC|PR_ADDR, 104*6341Ssam rip_input, rip_output, 0, 0, 105*6341Ssam raw_usrreq, 1065621Swnj 0, 0, 0, 0, 1074890Swnj } 1085621Swnj #if NIMP > 0 1095621Swnj , 1105621Swnj { SOCK_RAW, PF_IMPLINK, 0, PR_ATOMIC|PR_ADDR, 111*6341Ssam 0, rimp_output, 0, 0, 112*6341Ssam raw_usrreq, 1135621Swnj 0, 0, 0, 0, 1145621Swnj } 1155621Swnj #endif 1165848Sroot #if NPUP > 0 1175848Sroot , 1185848Sroot { SOCK_RAW, PF_PUP, 0, PR_ATOMIC|PR_ADDR, 119*6341Ssam 0, rpup_output, 0, 0, 1206030Sroot raw_usrreq, 1215848Sroot 0, 0, 0, 0, 1225848Sroot } 1235848Sroot #endif 1244787Swnj }; 1254787Swnj 1264890Swnj #define NPROTOSW (sizeof(protosw) / sizeof(protosw[0])) 1274890Swnj 1284890Swnj struct protosw *protoswLAST = &protosw[NPROTOSW-1]; 1294890Swnj 1304787Swnj /* 1314787Swnj * Operations on protocol table and protocol families. 1324787Swnj */ 1334787Swnj 1344787Swnj /* 1354890Swnj * Initialize all protocols. 1364890Swnj */ 1374890Swnj pfinit() 1384890Swnj { 1394890Swnj register struct protosw *pr; 1404890Swnj 1414927Swnj COUNT(PFINIT); 1424890Swnj for (pr = protoswLAST; pr >= protosw; pr--) 1434890Swnj if (pr->pr_init) 1444890Swnj (*pr->pr_init)(); 1454890Swnj } 1464890Swnj 1474890Swnj /* 1484787Swnj * Find a standard protocol in a protocol family 1494787Swnj * of a specific type. 1504787Swnj */ 1514825Swnj struct protosw * 1524890Swnj pffindtype(family, type) 1534787Swnj int family, type; 1544787Swnj { 1554787Swnj register struct protosw *pr; 1564787Swnj 1574927Swnj COUNT(PFFINDTYPE); 1584787Swnj if (family == 0) 1594787Swnj return (0); 1605011Swnj for (pr = protosw; pr <= protoswLAST; pr++) 1614787Swnj if (pr->pr_family == family && pr->pr_type == type) 1624787Swnj return (pr); 1634787Swnj return (0); 1644787Swnj } 1654787Swnj 1664787Swnj /* 1674787Swnj * Find a specified protocol in a specified protocol family. 1684787Swnj */ 1694825Swnj struct protosw * 1704890Swnj pffindproto(family, protocol) 1714825Swnj int family, protocol; 1724787Swnj { 1734787Swnj register struct protosw *pr; 1744787Swnj 1754927Swnj COUNT(PFFINDPROTO); 1764787Swnj if (family == 0) 1774787Swnj return (0); 1785011Swnj for (pr = protosw; pr <= protoswLAST; pr++) 1794825Swnj if (pr->pr_family == family && pr->pr_protocol == protocol) 1804787Swnj return (pr); 1814787Swnj return (0); 1824787Swnj } 1835248Sroot 1845248Sroot /* 1855248Sroot * Slow timeout on all protocols. 1865248Sroot */ 1875248Sroot pfslowtimo() 1885248Sroot { 1895248Sroot register struct protosw *pr; 1905248Sroot 1915248Sroot COUNT(PFSLOWTIMO); 1925248Sroot for (pr = protoswLAST; pr >= protosw; pr--) 1935248Sroot if (pr->pr_slowtimo) 1945248Sroot (*pr->pr_slowtimo)(); 1955248Sroot } 1965248Sroot 1975248Sroot pffasttimo() 1985248Sroot { 1995248Sroot register struct protosw *pr; 2005248Sroot 2015248Sroot COUNT(PFSLOWTIMO); 2025248Sroot for (pr = protoswLAST; pr >= protosw; pr--) 2035272Sroot if (pr->pr_fasttimo) 2045272Sroot (*pr->pr_fasttimo)(); 2055248Sroot } 206