xref: /csrg-svn/sys/netinet/udp_usrreq.c (revision 4887)
1 /*	udp_usrreq.c	4.3	81/11/14	*/
2 
3 #include "../h/param.h"
4 #include "../h/dir.h"
5 #include "../h/user.h"
6 #include "../h/mbuf.h"
7 #include "../h/protosw.h"
8 #include "../h/socket.h"
9 #include "../h/socketvar.h"
10 #include "../net/inet.h"
11 #include "../net/inet_host.h"
12 #include "../net/inet_pcb.h"
13 #include "../net/inet_systm.h"
14 #include "../net/udp.h"
15 #include "../net/udp_var.h"
16 
17 udp_init()
18 {
19 
20 	udb.inp_next = udb.inp_prev = &udp;
21 }
22 
23 udp_input(m)
24 	struct mbuf *m;
25 {
26 	register struct inpcb *inp;
27 	int raddr, rport;
28 	int addr, port;
29 
30 	inp = inpcb_lookup(&udb, addr, port);
31 	if (inp == 0)
32 		goto bad;
33 	/* sostuff(inp->inp_socket, m, raddr, rport); */
34 	return;
35 bad:
36 	m_freem(m);
37 	/* gen icmp? */
38 }
39 
40 udp_ctlinput(m)
41 	struct mbuf *m;
42 {
43 
44 	m_freem(m);
45 }
46 
47 udp_advise(m)
48 	struct mbuf *m;
49 {
50 
51 	m_freem(m);
52 }
53 
54 udp_output(raddr, rport, m)
55 	int raddr, rport;
56 	struct mbuf *m;
57 {
58 
59 	/* setup header */
60 	ip_output(m);
61 }
62 
63 udp_usrreq(so, req, m, addr)
64 	struct socket *so;
65 	int req;
66 	struct mbuf *m;
67 	struct in_addr *addr;
68 {
69 	struct inpcb *inp = sotoinpcb(so);
70 	int error;
71 
72 	switch (req) {
73 
74 	case PRU_ATTACH:
75 		if (inp != 0)
76 			return (EINVAL);
77 		inp = in_pcballoc();
78 		if (inp == NULL)
79 			return (ENOBUFS);
80 		so->so_pcb = (caddr_t)inp;
81 		break;
82 
83 	case PRU_DETACH:
84 		if (inp == 0)
85 			return (ENOTCONN);
86 		sofree(inp->inp_socket);
87 		udp_detach(inp);
88 		break;
89 
90 	case PRU_CONNECT:
91 		if (inp->inp_fhost)
92 			return (EISCONN);
93 		inp->inp_fhost = in_hmake((struct in_addr *)addr, &error);
94 		if (inp->inp_fhost == 0)
95 			return (error);
96 		soisconnected(so);
97 		break;
98 
99 	case PRU_DISCONNECT:
100 		if (inp->inp_fhost == 0)
101 			return (ENOTCONN);
102 		h_free(inp->inp_fhost);
103 		inp->inp_fhost = 0;
104 		soisdisconnected(so);
105 		break;
106 
107 	case PRU_SEND:
108 #if 0
109 		if (addr) {
110 			if (inp->inp_fhost)
111 				return (EISCONN);
112 			udp_output(addr->in_fhost, addr->in_fport, m);
113 		} else
114 			udp_output(inp->inp_fhost->h_addr, ip->inp_fport, m);
115 #endif
116 		break;
117 
118 	case PRU_ABORT:
119 		in_pcbfree(inp);
120 		sofree(so);
121 		soisdisconnected(so);
122 		break;
123 
124 	case PRU_CONTROL:
125 		return (EOPNOTSUPP);
126 
127 	default:
128 		panic("udp_usrreq");
129 	}
130 	return (0);
131 }
132 
133 udp_sense()
134 {
135 
136 }
137