xref: /csrg-svn/sys/kern/uipc_proto.c (revision 5848)
1*5848Sroot /*	uipc_proto.c	4.16	82/02/15	*/
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();
345149Swnj int	rip_input(),rip_output(),rip_ctlinput();
355149Swnj int	rip_usrreq(),rip_slowtimo();
364787Swnj 
375621Swnj /*
385621Swnj  * IMP protocol family: raw interface
395621Swnj  */
405621Swnj #include "imp.h"
415621Swnj #if NIMP > 0
42*5848Sroot int	rimp_usrreq(),rimp_output(),rimp_ctlinput();
435621Swnj #endif
445621Swnj 
455621Swnj /*
46*5848Sroot  * PUP-I protocol family: raw interface
47*5848Sroot  */
48*5848Sroot #include "pup.h"
49*5848Sroot #if NPUP > 0
50*5848Sroot int	rpup_usrreq(),rpup_output(),rpup_ctlinput();
51*5848Sroot #endif
52*5848Sroot 
53*5848Sroot /*
545621Swnj  * Sundries.
555621Swnj */
565621Swnj int	raw_init(),raw_usrreq(),raw_input();
575621Swnj 
584787Swnj struct protosw protosw[] = {
595149Swnj { SOCK_STREAM,	PF_UNIX,	0,		PR_CONNREQUIRED,
604825Swnj   0,		0,		0,		0,
615149Swnj   piusrreq,
624825Swnj   0,		0,		0,		0,
634890Swnj },
645149Swnj { SOCK_DGRAM,	PF_UNIX,	0,		PR_ATOMIC|PR_ADDR,
654825Swnj   0,		0,		0,		0,
665149Swnj   piusrreq,
674825Swnj   0,		0,		0,		0,
684890Swnj },
695149Swnj { SOCK_RDM,	PF_UNIX,	0,		PR_ATOMIC|PR_ADDR,
704890Swnj   0,		0,		0,		0,
715149Swnj   piusrreq,
724890Swnj   0,		0,		0,		0,
734890Swnj },
745149Swnj { SOCK_RAW,	PF_UNIX,	0,		PR_ATOMIC|PR_ADDR,
754890Swnj   0,		0,		0,		0,
765149Swnj   piusrreq,
774890Swnj   0,		0,		0,		0,
784890Swnj },
794787Swnj { 0,		0,		0,		0,
805091Swnj   0,		ip_output,	0,		0,
815149Swnj   0,
824890Swnj   ip_init,	0,		ip_slowtimo,	ip_drain,
834890Swnj },
844787Swnj { 0,		0,		IPPROTO_ICMP,	0,
855170Swnj   icmp_input,	0,		icmp_ctlinput,	0,
865149Swnj   0,
874890Swnj   0,		0,		0,		icmp_drain,
884890Swnj },
894825Swnj { SOCK_DGRAM,	PF_INET,	IPPROTO_UDP,	PR_ATOMIC|PR_ADDR,
904890Swnj   udp_input,	0,		udp_ctlinput,	0,
915149Swnj   udp_usrreq,
924890Swnj   udp_init,	0,		0,		0,
934890Swnj },
945011Swnj { SOCK_STREAM,	PF_INET,	IPPROTO_TCP,	PR_CONNREQUIRED|PR_WANTRCVD,
954890Swnj   tcp_input,	0,		tcp_ctlinput,	0,
965149Swnj   tcp_usrreq,
974890Swnj   tcp_init,	tcp_fasttimo,	tcp_slowtimo,	tcp_drain,
984890Swnj },
995621Swnj { 0,		0,		0,		0,
1005621Swnj   raw_input,	0,		0,		0,
1015621Swnj   raw_usrreq,
1025621Swnj   raw_init,	0,		0,		0,
1035621Swnj },
1045644Ssam { SOCK_RAW,	PF_INET,	IPPROTO_RAW,	PR_ATOMIC|PR_ADDR,
1055149Swnj   rip_input,	rip_output,	rip_ctlinput,	0,
1065149Swnj   rip_usrreq,
1075621Swnj   0,		0,		0,		0,
1084890Swnj }
1095621Swnj #if NIMP > 0
1105621Swnj ,
1115621Swnj { SOCK_RAW,	PF_IMPLINK,	0,		PR_ATOMIC|PR_ADDR,
112*5848Sroot   0,		rimp_output,	rimp_ctlinput,	0,
113*5848Sroot   rimp_usrreq,
1145621Swnj   0,		0,		0,		0,
1155621Swnj }
1165621Swnj #endif
117*5848Sroot #if NPUP > 0
118*5848Sroot ,
119*5848Sroot { SOCK_RAW,	PF_PUP,		0,		PR_ATOMIC|PR_ADDR,
120*5848Sroot   0,		rpup_output,	rpup_ctlinput,	0,
121*5848Sroot   rpup_usrreq,
122*5848Sroot   0,		0,		0,		0,
123*5848Sroot }
124*5848Sroot #endif
1254787Swnj };
1264787Swnj 
1274890Swnj #define	NPROTOSW	(sizeof(protosw) / sizeof(protosw[0]))
1284890Swnj 
1294890Swnj struct	protosw *protoswLAST = &protosw[NPROTOSW-1];
1304890Swnj 
1314787Swnj /*
1324787Swnj  * Operations on protocol table and protocol families.
1334787Swnj  */
1344787Swnj 
1354787Swnj /*
1364890Swnj  * Initialize all protocols.
1374890Swnj  */
1384890Swnj pfinit()
1394890Swnj {
1404890Swnj 	register struct protosw *pr;
1414890Swnj 
1424927Swnj COUNT(PFINIT);
1434890Swnj 	for (pr = protoswLAST; pr >= protosw; pr--)
1444890Swnj 		if (pr->pr_init)
1454890Swnj 			(*pr->pr_init)();
1464890Swnj }
1474890Swnj 
1484890Swnj /*
1494787Swnj  * Find a standard protocol in a protocol family
1504787Swnj  * of a specific type.
1514787Swnj  */
1524825Swnj struct protosw *
1534890Swnj pffindtype(family, type)
1544787Swnj 	int family, type;
1554787Swnj {
1564787Swnj 	register struct protosw *pr;
1574787Swnj 
1584927Swnj COUNT(PFFINDTYPE);
1594787Swnj 	if (family == 0)
1604787Swnj 		return (0);
1615011Swnj 	for (pr = protosw; pr <= protoswLAST; pr++)
1624787Swnj 		if (pr->pr_family == family && pr->pr_type == type)
1634787Swnj 			return (pr);
1644787Swnj 	return (0);
1654787Swnj }
1664787Swnj 
1674787Swnj /*
1684787Swnj  * Find a specified protocol in a specified protocol family.
1694787Swnj  */
1704825Swnj struct protosw *
1714890Swnj pffindproto(family, protocol)
1724825Swnj 	int family, protocol;
1734787Swnj {
1744787Swnj 	register struct protosw *pr;
1754787Swnj 
1764927Swnj COUNT(PFFINDPROTO);
1774787Swnj 	if (family == 0)
1784787Swnj 		return (0);
1795011Swnj 	for (pr = protosw; pr <= protoswLAST; pr++)
1804825Swnj 		if (pr->pr_family == family && pr->pr_protocol == protocol)
1814787Swnj 			return (pr);
1824787Swnj 	return (0);
1834787Swnj }
1845248Sroot 
1855248Sroot /*
1865248Sroot  * Slow timeout on all protocols.
1875248Sroot  */
1885248Sroot pfslowtimo()
1895248Sroot {
1905248Sroot 	register struct protosw *pr;
1915248Sroot 
1925248Sroot COUNT(PFSLOWTIMO);
1935248Sroot 	for (pr = protoswLAST; pr >= protosw; pr--)
1945248Sroot 		if (pr->pr_slowtimo)
1955248Sroot 			(*pr->pr_slowtimo)();
1965248Sroot }
1975248Sroot 
1985248Sroot pffasttimo()
1995248Sroot {
2005248Sroot 	register struct protosw *pr;
2015248Sroot 
2025248Sroot COUNT(PFSLOWTIMO);
2035248Sroot 	for (pr = protoswLAST; pr >= protosw; pr--)
2045272Sroot 		if (pr->pr_fasttimo)
2055272Sroot 			(*pr->pr_fasttimo)();
2065248Sroot }
207