xref: /csrg-svn/sys/kern/uipc_proto.c (revision 4890)
1 /*	uipc_proto.c	4.3	81/11/14	*/
2 
3 #include "../h/param.h"
4 #include "../h/socket.h"
5 #include "../h/protocol.h"
6 #include "../h/protosw.h"
7 #include "../h/mbuf.h"
8 #include "../net/inet.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	pi_usrreq();
20 
21 /*
22  * TCP/IP protocol family: IP, ICMP, UDP, TCP.
23  */
24 int	ip_input(),ip_output(),ip_ctloutput();
25 int	ip_init(),ip_slowtimo(),ip_drain();
26 int	icmp_input();
27 int	icmp_drain();
28 int	udp_input(),udp_ctlinput();
29 int	udp_usrreq(),udp_sense();
30 int	udp_init();
31 int	tcp_input(),tcp_ctlinput();
32 int	tcp_usrreq(),tcp_sense();
33 int	tcp_init(),tcp_fasttimo(),tcp_slowtimo(),tcp_drain();
34 int	ri_input(),ri_ctlinput();
35 int	ri_usrreq(),ri_sense();
36 
37 struct protosw protosw[] = {
38 { SOCK_STREAM,	PF_LOCAL,	0,		PR_CONNREQUIRED,
39   0,		0,		0,		0,
40   pi_usrreq,	0,		0,
41   0,		0,		0,		0,
42 },
43 { SOCK_DGRAM,	PF_LOCAL,	0,		PR_ATOMIC|PR_ADDR,
44   0,		0,		0,		0,
45   pi_usrreq,	0,		0,
46   0,		0,		0,		0,
47 },
48 { SOCK_RDM,	PF_LOCAL,	0,		PR_ATOMIC|PR_ADDR,
49   0,		0,		0,		0,
50   pi_usrreq,	0,		0,
51   0,		0,		0,		0,
52 },
53 { SOCK_RAW,	PF_LOCAL,	0,		PR_ATOMIC|PR_ADDR,
54   0,		0,		0,		0,
55   pi_usrreq,	0,		0,
56   0,		0,		0,		0,
57 },
58 { 0,		0,		0,		0,
59   ip_input,	ip_output,	0,		0,
60   0,		0,		0,
61   ip_init,	0,		ip_slowtimo,	ip_drain,
62 },
63 { 0,		0,		IPPROTO_ICMP,	0,
64   icmp_input,	0,		0,		0,
65   0,		0,		0,
66   0,		0,		0,		icmp_drain,
67 },
68 { SOCK_DGRAM,	PF_INET,	IPPROTO_UDP,	PR_ATOMIC|PR_ADDR,
69   udp_input,	0,		udp_ctlinput,	0,
70   udp_usrreq,	udp_sense,	MLEN,
71   udp_init,	0,		0,		0,
72 },
73 { SOCK_STREAM,	PF_INET,	IPPROTO_TCP,	PR_CONNREQUIRED,
74   tcp_input,	0,		tcp_ctlinput,	0,
75   tcp_usrreq,	tcp_sense,	MLEN,
76   tcp_init,	tcp_fasttimo,	tcp_slowtimo,	tcp_drain,
77 },
78 { SOCK_RAW,	PF_INET,	IPPROTO_RAW,	PR_ATOMIC|PR_ADDR,
79   ri_input,	0,		ri_ctlinput,	0,
80   ri_usrreq,	ri_sense,	MLEN,
81   0,		0,		0,		0,
82 }
83 };
84 
85 #define	NPROTOSW	(sizeof(protosw) / sizeof(protosw[0]))
86 
87 struct	protosw *protoswLAST = &protosw[NPROTOSW-1];
88 
89 /*
90  * Operations on protocol table and protocol families.
91  */
92 
93 /*
94  * Initialize all protocols.
95  */
96 pfinit()
97 {
98 	register struct protosw *pr;
99 
100 	for (pr = protoswLAST; pr >= protosw; pr--)
101 		if (pr->pr_init)
102 			(*pr->pr_init)();
103 }
104 
105 /*
106  * Find a standard protocol in a protocol family
107  * of a specific type.
108  */
109 struct protosw *
110 pffindtype(family, type)
111 	int family, type;
112 {
113 	register struct protosw *pr;
114 
115 	if (family == 0)
116 		return (0);
117 	for (pr = protosw; pr < protoswLAST; pr++)
118 		if (pr->pr_family == family && pr->pr_type == type)
119 			return (pr);
120 	return (0);
121 }
122 
123 /*
124  * Find a specified protocol in a specified protocol family.
125  */
126 struct protosw *
127 pffindproto(family, protocol)
128 	int family, protocol;
129 {
130 	register struct protosw *pr;
131 
132 	if (family == 0)
133 		return (0);
134 	for (pr = protosw; pr < protoswLAST; pr++)
135 		if (pr->pr_family == family && pr->pr_protocol == protocol)
136 			return (pr);
137 	return (0);
138 }
139