xref: /csrg-svn/sys/kern/uipc_proto.c (revision 5272)
1*5272Sroot /*	uipc_proto.c	4.13	81/12/20	*/
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 
374787Swnj struct protosw protosw[] = {
385149Swnj { SOCK_STREAM,	PF_UNIX,	0,		PR_CONNREQUIRED,
394825Swnj   0,		0,		0,		0,
405149Swnj   piusrreq,
414825Swnj   0,		0,		0,		0,
424890Swnj },
435149Swnj { SOCK_DGRAM,	PF_UNIX,	0,		PR_ATOMIC|PR_ADDR,
444825Swnj   0,		0,		0,		0,
455149Swnj   piusrreq,
464825Swnj   0,		0,		0,		0,
474890Swnj },
485149Swnj { SOCK_RDM,	PF_UNIX,	0,		PR_ATOMIC|PR_ADDR,
494890Swnj   0,		0,		0,		0,
505149Swnj   piusrreq,
514890Swnj   0,		0,		0,		0,
524890Swnj },
535149Swnj { SOCK_RAW,	PF_UNIX,	0,		PR_ATOMIC|PR_ADDR,
544890Swnj   0,		0,		0,		0,
555149Swnj   piusrreq,
564890Swnj   0,		0,		0,		0,
574890Swnj },
584787Swnj { 0,		0,		0,		0,
595091Swnj   0,		ip_output,	0,		0,
605149Swnj   0,
614890Swnj   ip_init,	0,		ip_slowtimo,	ip_drain,
624890Swnj },
634787Swnj { 0,		0,		IPPROTO_ICMP,	0,
645170Swnj   icmp_input,	0,		icmp_ctlinput,	0,
655149Swnj   0,
664890Swnj   0,		0,		0,		icmp_drain,
674890Swnj },
684825Swnj { SOCK_DGRAM,	PF_INET,	IPPROTO_UDP,	PR_ATOMIC|PR_ADDR,
694890Swnj   udp_input,	0,		udp_ctlinput,	0,
705149Swnj   udp_usrreq,
714890Swnj   udp_init,	0,		0,		0,
724890Swnj },
735011Swnj { SOCK_STREAM,	PF_INET,	IPPROTO_TCP,	PR_CONNREQUIRED|PR_WANTRCVD,
744890Swnj   tcp_input,	0,		tcp_ctlinput,	0,
755149Swnj   tcp_usrreq,
764890Swnj   tcp_init,	tcp_fasttimo,	tcp_slowtimo,	tcp_drain,
774890Swnj },
784825Swnj { SOCK_RAW,	PF_INET,	IPPROTO_RAW,	PR_ATOMIC|PR_ADDR,
795149Swnj   rip_input,	rip_output,	rip_ctlinput,	0,
805149Swnj   rip_usrreq,
815149Swnj   0,		0,		rip_slowtimo,	0,
824890Swnj }
834787Swnj };
844787Swnj 
854890Swnj #define	NPROTOSW	(sizeof(protosw) / sizeof(protosw[0]))
864890Swnj 
874890Swnj struct	protosw *protoswLAST = &protosw[NPROTOSW-1];
884890Swnj 
894787Swnj /*
904787Swnj  * Operations on protocol table and protocol families.
914787Swnj  */
924787Swnj 
934787Swnj /*
944890Swnj  * Initialize all protocols.
954890Swnj  */
964890Swnj pfinit()
974890Swnj {
984890Swnj 	register struct protosw *pr;
994890Swnj 
1004927Swnj COUNT(PFINIT);
1014890Swnj 	for (pr = protoswLAST; pr >= protosw; pr--)
1024890Swnj 		if (pr->pr_init)
1034890Swnj 			(*pr->pr_init)();
1044890Swnj }
1054890Swnj 
1064890Swnj /*
1074787Swnj  * Find a standard protocol in a protocol family
1084787Swnj  * of a specific type.
1094787Swnj  */
1104825Swnj struct protosw *
1114890Swnj pffindtype(family, type)
1124787Swnj 	int family, type;
1134787Swnj {
1144787Swnj 	register struct protosw *pr;
1154787Swnj 
1164927Swnj COUNT(PFFINDTYPE);
1174787Swnj 	if (family == 0)
1184787Swnj 		return (0);
1195011Swnj 	for (pr = protosw; pr <= protoswLAST; pr++)
1204787Swnj 		if (pr->pr_family == family && pr->pr_type == type)
1214787Swnj 			return (pr);
1224787Swnj 	return (0);
1234787Swnj }
1244787Swnj 
1254787Swnj /*
1264787Swnj  * Find a specified protocol in a specified protocol family.
1274787Swnj  */
1284825Swnj struct protosw *
1294890Swnj pffindproto(family, protocol)
1304825Swnj 	int family, protocol;
1314787Swnj {
1324787Swnj 	register struct protosw *pr;
1334787Swnj 
1344927Swnj COUNT(PFFINDPROTO);
1354787Swnj 	if (family == 0)
1364787Swnj 		return (0);
1375011Swnj 	for (pr = protosw; pr <= protoswLAST; pr++)
1384825Swnj 		if (pr->pr_family == family && pr->pr_protocol == protocol)
1394787Swnj 			return (pr);
1404787Swnj 	return (0);
1414787Swnj }
1425248Sroot 
1435248Sroot /*
1445248Sroot  * Slow timeout on all protocols.
1455248Sroot  */
1465248Sroot pfslowtimo()
1475248Sroot {
1485248Sroot 	register struct protosw *pr;
1495248Sroot 
1505248Sroot COUNT(PFSLOWTIMO);
1515248Sroot 	for (pr = protoswLAST; pr >= protosw; pr--)
1525248Sroot 		if (pr->pr_slowtimo)
1535248Sroot 			(*pr->pr_slowtimo)();
1545248Sroot }
1555248Sroot 
1565248Sroot pffasttimo()
1575248Sroot {
1585248Sroot 	register struct protosw *pr;
1595248Sroot 
1605248Sroot COUNT(PFSLOWTIMO);
1615248Sroot 	for (pr = protoswLAST; pr >= protosw; pr--)
162*5272Sroot 		if (pr->pr_fasttimo)
163*5272Sroot 			(*pr->pr_fasttimo)();
1645248Sroot }
165