xref: /csrg-svn/sys/kern/uipc_proto.c (revision 6585)
1*6585Ssam /*	uipc_proto.c	4.20	82/04/24	*/
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();
26*6585Ssam int	icmp_input();
274890Swnj int	udp_input(),udp_ctlinput();
285170Swnj int	udp_usrreq();
294890Swnj int	udp_init();
304890Swnj int	tcp_input(),tcp_ctlinput();
315170Swnj int	tcp_usrreq();
324890Swnj int	tcp_init(),tcp_fasttimo(),tcp_slowtimo(),tcp_drain();
336341Ssam int	rip_input(),rip_output();
344787Swnj 
355621Swnj /*
365621Swnj  * IMP protocol family: raw interface
375621Swnj  */
385621Swnj #include "imp.h"
395621Swnj #if NIMP > 0
406341Ssam int	rimp_output();
415621Swnj #endif
425621Swnj 
435621Swnj /*
445848Sroot  * PUP-I protocol family: raw interface
455848Sroot  */
465848Sroot #include "pup.h"
475848Sroot #if NPUP > 0
486341Ssam int	rpup_output();
495848Sroot #endif
505848Sroot 
515848Sroot /*
525621Swnj  * Sundries.
535621Swnj */
54*6585Ssam int	raw_init(),raw_usrreq(),raw_input(),raw_ctlinput();
555621Swnj 
564787Swnj struct protosw protosw[] = {
575149Swnj { SOCK_STREAM,	PF_UNIX,	0,		PR_CONNREQUIRED,
584825Swnj   0,		0,		0,		0,
595149Swnj   piusrreq,
604825Swnj   0,		0,		0,		0,
614890Swnj },
625149Swnj { SOCK_DGRAM,	PF_UNIX,	0,		PR_ATOMIC|PR_ADDR,
634825Swnj   0,		0,		0,		0,
645149Swnj   piusrreq,
654825Swnj   0,		0,		0,		0,
664890Swnj },
675149Swnj { SOCK_RDM,	PF_UNIX,	0,		PR_ATOMIC|PR_ADDR,
684890Swnj   0,		0,		0,		0,
695149Swnj   piusrreq,
704890Swnj   0,		0,		0,		0,
714890Swnj },
725149Swnj { SOCK_RAW,	PF_UNIX,	0,		PR_ATOMIC|PR_ADDR,
734890Swnj   0,		0,		0,		0,
745149Swnj   piusrreq,
754890Swnj   0,		0,		0,		0,
764890Swnj },
774787Swnj { 0,		0,		0,		0,
785091Swnj   0,		ip_output,	0,		0,
795149Swnj   0,
804890Swnj   ip_init,	0,		ip_slowtimo,	ip_drain,
814890Swnj },
82*6585Ssam { 0,		PF_INET,	IPPROTO_ICMP,	0,
83*6585Ssam   icmp_input,	0,		0,		0,
845149Swnj   0,
85*6585Ssam   0,		0,		0,		0,
864890Swnj },
874825Swnj { SOCK_DGRAM,	PF_INET,	IPPROTO_UDP,	PR_ATOMIC|PR_ADDR,
884890Swnj   udp_input,	0,		udp_ctlinput,	0,
895149Swnj   udp_usrreq,
904890Swnj   udp_init,	0,		0,		0,
914890Swnj },
925011Swnj { SOCK_STREAM,	PF_INET,	IPPROTO_TCP,	PR_CONNREQUIRED|PR_WANTRCVD,
934890Swnj   tcp_input,	0,		tcp_ctlinput,	0,
945149Swnj   tcp_usrreq,
954890Swnj   tcp_init,	tcp_fasttimo,	tcp_slowtimo,	tcp_drain,
964890Swnj },
975621Swnj { 0,		0,		0,		0,
98*6585Ssam   raw_input,	0,		raw_ctlinput,	0,
995621Swnj   raw_usrreq,
1005621Swnj   raw_init,	0,		0,		0,
1015621Swnj },
1025644Ssam { SOCK_RAW,	PF_INET,	IPPROTO_RAW,	PR_ATOMIC|PR_ADDR,
103*6585Ssam   rip_input,	rip_output,	0,	0,
1046341Ssam   raw_usrreq,
1055621Swnj   0,		0,		0,		0,
1064890Swnj }
1075621Swnj #if NIMP > 0
1085621Swnj ,
1095621Swnj { SOCK_RAW,	PF_IMPLINK,	0,		PR_ATOMIC|PR_ADDR,
1106341Ssam   0,		rimp_output,	0,		0,
1116341Ssam   raw_usrreq,
1125621Swnj   0,		0,		0,		0,
1135621Swnj }
1145621Swnj #endif
1155848Sroot #if NPUP > 0
1165848Sroot ,
1175848Sroot { SOCK_RAW,	PF_PUP,		0,		PR_ATOMIC|PR_ADDR,
1186341Ssam   0,		rpup_output,	0,		0,
1196030Sroot   raw_usrreq,
1205848Sroot   0,		0,		0,		0,
1215848Sroot }
1225848Sroot #endif
1234787Swnj };
1244787Swnj 
1254890Swnj #define	NPROTOSW	(sizeof(protosw) / sizeof(protosw[0]))
1264890Swnj 
1274890Swnj struct	protosw *protoswLAST = &protosw[NPROTOSW-1];
1284890Swnj 
1294787Swnj /*
1304787Swnj  * Operations on protocol table and protocol families.
1314787Swnj  */
1324787Swnj 
1334787Swnj /*
1344890Swnj  * Initialize all protocols.
1354890Swnj  */
1364890Swnj pfinit()
1374890Swnj {
1384890Swnj 	register struct protosw *pr;
1394890Swnj 
1404927Swnj COUNT(PFINIT);
1414890Swnj 	for (pr = protoswLAST; pr >= protosw; pr--)
1424890Swnj 		if (pr->pr_init)
1434890Swnj 			(*pr->pr_init)();
1444890Swnj }
1454890Swnj 
1464890Swnj /*
1474787Swnj  * Find a standard protocol in a protocol family
1484787Swnj  * of a specific type.
1494787Swnj  */
1504825Swnj struct protosw *
1514890Swnj pffindtype(family, type)
1524787Swnj 	int family, type;
1534787Swnj {
1544787Swnj 	register struct protosw *pr;
1554787Swnj 
1564927Swnj COUNT(PFFINDTYPE);
1574787Swnj 	if (family == 0)
1584787Swnj 		return (0);
1595011Swnj 	for (pr = protosw; pr <= protoswLAST; pr++)
1604787Swnj 		if (pr->pr_family == family && pr->pr_type == type)
1614787Swnj 			return (pr);
1624787Swnj 	return (0);
1634787Swnj }
1644787Swnj 
1654787Swnj /*
1664787Swnj  * Find a specified protocol in a specified protocol family.
1674787Swnj  */
1684825Swnj struct protosw *
1694890Swnj pffindproto(family, protocol)
1704825Swnj 	int family, protocol;
1714787Swnj {
1724787Swnj 	register struct protosw *pr;
1734787Swnj 
1744927Swnj COUNT(PFFINDPROTO);
1754787Swnj 	if (family == 0)
1764787Swnj 		return (0);
1775011Swnj 	for (pr = protosw; pr <= protoswLAST; pr++)
1784825Swnj 		if (pr->pr_family == family && pr->pr_protocol == protocol)
1794787Swnj 			return (pr);
1804787Swnj 	return (0);
1814787Swnj }
1825248Sroot 
183*6585Ssam pfctlinput(cmd, arg)
184*6585Ssam 	int cmd;
185*6585Ssam 	caddr_t arg;
186*6585Ssam {
187*6585Ssam 	register struct protosw *pr;
188*6585Ssam COUNT(PFCTLINPUT);
189*6585Ssam 
190*6585Ssam 	for (pr = protosw; pr <= protoswLAST; pr++)
191*6585Ssam 		if (pr->pr_ctlinput)
192*6585Ssam 			(*pr->pr_ctlinput)(cmd, arg);
193*6585Ssam }
194*6585Ssam 
1955248Sroot /*
1965248Sroot  * Slow timeout on all protocols.
1975248Sroot  */
1985248Sroot pfslowtimo()
1995248Sroot {
2005248Sroot 	register struct protosw *pr;
2015248Sroot 
2025248Sroot COUNT(PFSLOWTIMO);
2035248Sroot 	for (pr = protoswLAST; pr >= protosw; pr--)
2045248Sroot 		if (pr->pr_slowtimo)
2055248Sroot 			(*pr->pr_slowtimo)();
2065248Sroot }
2075248Sroot 
2085248Sroot pffasttimo()
2095248Sroot {
2105248Sroot 	register struct protosw *pr;
2115248Sroot 
2125248Sroot COUNT(PFSLOWTIMO);
2135248Sroot 	for (pr = protoswLAST; pr >= protosw; pr--)
2145272Sroot 		if (pr->pr_fasttimo)
2155272Sroot 			(*pr->pr_fasttimo)();
2165248Sroot }
217