accf_http.c revision 1.2.2.2 1 1.2.2.2 haad /* $NetBSD: accf_http.c,v 1.2.2.2 2008/10/19 22:17:46 haad Exp $ */
2 1.2.2.2 haad
3 1.2.2.2 haad /*-
4 1.2.2.2 haad * Copyright (c) 2000 Paycounter, Inc.
5 1.2.2.2 haad * Author: Alfred Perlstein <alfred (at) paycounter.com>, <alfred (at) FreeBSD.org>
6 1.2.2.2 haad * All rights reserved.
7 1.2.2.2 haad *
8 1.2.2.2 haad * Redistribution and use in source and binary forms, with or without
9 1.2.2.2 haad * modification, are permitted provided that the following conditions
10 1.2.2.2 haad * are met:
11 1.2.2.2 haad * 1. Redistributions of source code must retain the above copyright
12 1.2.2.2 haad * notice, this list of conditions and the following disclaimer.
13 1.2.2.2 haad * 2. Redistributions in binary form must reproduce the above copyright
14 1.2.2.2 haad * notice, this list of conditions and the following disclaimer in the
15 1.2.2.2 haad * documentation and/or other materials provided with the distribution.
16 1.2.2.2 haad *
17 1.2.2.2 haad * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 1.2.2.2 haad * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 1.2.2.2 haad * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 1.2.2.2 haad * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 1.2.2.2 haad * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 1.2.2.2 haad * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 1.2.2.2 haad * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 1.2.2.2 haad * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 1.2.2.2 haad * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 1.2.2.2 haad * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 1.2.2.2 haad * SUCH DAMAGE.
28 1.2.2.2 haad */
29 1.2.2.2 haad
30 1.2.2.2 haad #include <sys/cdefs.h>
31 1.2.2.2 haad __KERNEL_RCSID(0, "$NetBSD: accf_http.c,v 1.2.2.2 2008/10/19 22:17:46 haad Exp $");
32 1.2.2.2 haad
33 1.2.2.2 haad #define ACCEPT_FILTER_MOD
34 1.2.2.2 haad
35 1.2.2.2 haad #include <sys/param.h>
36 1.2.2.2 haad #include <sys/kernel.h>
37 1.2.2.2 haad #include <sys/mbuf.h>
38 1.2.2.2 haad #include <sys/lkm.h>
39 1.2.2.2 haad #include <sys/signalvar.h>
40 1.2.2.2 haad #include <sys/sysctl.h>
41 1.2.2.2 haad #include <sys/socket.h>
42 1.2.2.2 haad #include <sys/socketvar.h>
43 1.2.2.2 haad
44 1.2.2.2 haad #include <netinet/accept_filter.h>
45 1.2.2.2 haad
46 1.2.2.2 haad /* check for GET/HEAD */
47 1.2.2.2 haad static void sohashttpget(struct socket *so, void *arg, int waitflag);
48 1.2.2.2 haad /* check for HTTP/1.0 or HTTP/1.1 */
49 1.2.2.2 haad static void soparsehttpvers(struct socket *so, void *arg, int waitflag);
50 1.2.2.2 haad /* check for end of HTTP/1.x request */
51 1.2.2.2 haad static void soishttpconnected(struct socket *so, void *arg, int waitflag);
52 1.2.2.2 haad /* strcmp on an mbuf chain */
53 1.2.2.2 haad static int mbufstrcmp(struct mbuf *m, struct mbuf *npkt, int offset, const char *cmp);
54 1.2.2.2 haad /* strncmp on an mbuf chain */
55 1.2.2.2 haad static int mbufstrncmp(struct mbuf *m, struct mbuf *npkt, int offset,
56 1.2.2.2 haad int len, const char *cmp);
57 1.2.2.2 haad /* socketbuffer is full */
58 1.2.2.2 haad static int sbfull(struct sockbuf *sb);
59 1.2.2.2 haad
60 1.2.2.2 haad static struct accept_filter accf_http_filter = {
61 1.2.2.2 haad .accf_name = "httpready",
62 1.2.2.2 haad .accf_callback = sohashttpget,
63 1.2.2.2 haad };
64 1.2.2.2 haad
65 1.2.2.2 haad /*
66 1.2.2.2 haad * Names of HTTP Accept filter sysctl objects
67 1.2.2.2 haad */
68 1.2.2.2 haad
69 1.2.2.2 haad #define ACCFCTL_PARSEVER 1 /* Parse HTTP version */
70 1.2.2.2 haad
71 1.2.2.2 haad static int parse_http_version = 1;
72 1.2.2.2 haad
73 1.2.2.2 haad SYSCTL_SETUP(sysctl_net_inet_accf__http_setup, "sysctl net.inet.accf.http subtree setup")
74 1.2.2.2 haad {
75 1.2.2.2 haad sysctl_createv(clog, 0, NULL, NULL,
76 1.2.2.2 haad CTLFLAG_PERMANENT,
77 1.2.2.2 haad CTLTYPE_NODE, "net", NULL,
78 1.2.2.2 haad NULL, 0, NULL, 0,
79 1.2.2.2 haad CTL_NET, CTL_EOL);
80 1.2.2.2 haad sysctl_createv(clog, 0, NULL, NULL,
81 1.2.2.2 haad CTLFLAG_PERMANENT,
82 1.2.2.2 haad CTLTYPE_NODE, "inet", NULL,
83 1.2.2.2 haad NULL, 0, NULL, 0,
84 1.2.2.2 haad CTL_NET, PF_INET, CTL_EOL);
85 1.2.2.2 haad sysctl_createv(clog, 0, NULL, NULL,
86 1.2.2.2 haad CTLFLAG_PERMANENT,
87 1.2.2.2 haad CTLTYPE_NODE, "accf", NULL,
88 1.2.2.2 haad NULL, 0, NULL, 0,
89 1.2.2.2 haad CTL_NET, PF_INET, SO_ACCEPTFILTER, CTL_EOL);
90 1.2.2.2 haad sysctl_createv(clog, 0, NULL, NULL,
91 1.2.2.2 haad CTLFLAG_PERMANENT,
92 1.2.2.2 haad CTLTYPE_NODE, "http",
93 1.2.2.2 haad SYSCTL_DESCR("HTTP accept filter"),
94 1.2.2.2 haad NULL, 0, NULL, 0,
95 1.2.2.2 haad CTL_NET, PF_INET, SO_ACCEPTFILTER, ACCF_HTTP, CTL_EOL);
96 1.2.2.2 haad sysctl_createv(clog, 0, NULL, NULL,
97 1.2.2.2 haad CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
98 1.2.2.2 haad CTLTYPE_INT, "parsehttpversion",
99 1.2.2.2 haad SYSCTL_DESCR("Parse http version so that non "
100 1.2.2.2 haad "1.x requests work"),
101 1.2.2.2 haad NULL, 0, &parse_http_version, 0,
102 1.2.2.2 haad CTL_NET, PF_INET, SO_ACCEPTFILTER, ACCF_HTTP,
103 1.2.2.2 haad ACCFCTL_PARSEVER, CTL_EOL);
104 1.2.2.2 haad }
105 1.2.2.2 haad
106 1.2.2.2 haad void accf_httpattach(int);
107 1.2.2.2 haad void accf_httpattach(int num)
108 1.2.2.2 haad {
109 1.2.2.2 haad accept_filt_generic_mod_event(NULL, LKM_E_LOAD, &accf_http_filter);
110 1.2.2.2 haad }
111 1.2.2.2 haad
112 1.2.2.2 haad /*
113 1.2.2.2 haad * This code is to make HTTP ready accept filer as LKM.
114 1.2.2.2 haad * To compile as LKM we need to move this set of code into
115 1.2.2.2 haad * another file and include this file for compilation when
116 1.2.2.2 haad * making LKM
117 1.2.2.2 haad */
118 1.2.2.2 haad
119 1.2.2.2 haad #ifdef _LKM
120 1.2.2.2 haad static int accf_http_handle(struct lkm_table * lkmtp, int cmd);
121 1.2.2.2 haad int accf_http_lkmentry(struct lkm_table * lkmtp, int cmd, int ver);
122 1.2.2.2 haad
123 1.2.2.2 haad MOD_MISC("accf_http");
124 1.2.2.2 haad
125 1.2.2.2 haad static int accf_http_handle(struct lkm_table * lkmtp, int cmd)
126 1.2.2.2 haad {
127 1.2.2.2 haad
128 1.2.2.2 haad return accept_filt_generic_mod_event(lkmtp, cmd, &accf_http_filter);
129 1.2.2.2 haad }
130 1.2.2.2 haad
131 1.2.2.2 haad /*
132 1.2.2.2 haad * the module entry point.
133 1.2.2.2 haad */
134 1.2.2.2 haad int
135 1.2.2.2 haad accf_http_lkmentry(struct lkm_table *lkmtp, int cmd, int ver)
136 1.2.2.2 haad {
137 1.2.2.2 haad DISPATCH(lkmtp, cmd, ver, accf_http_handle, accf_http_handle,
138 1.2.2.2 haad accf_http_handle)
139 1.2.2.2 haad }
140 1.2.2.2 haad #endif
141 1.2.2.2 haad
142 1.2.2.2 haad #ifdef ACCF_HTTP_DEBUG
143 1.2.2.2 haad #define DPRINT(fmt, args...) \
144 1.2.2.2 haad do { \
145 1.2.2.2 haad printf("%s:%d: " fmt "\n", __func__, __LINE__, ##args); \
146 1.2.2.2 haad } while (0)
147 1.2.2.2 haad #else
148 1.2.2.2 haad #define DPRINT(fmt, args...)
149 1.2.2.2 haad #endif
150 1.2.2.2 haad
151 1.2.2.2 haad static int
152 1.2.2.2 haad sbfull(struct sockbuf *sb)
153 1.2.2.2 haad {
154 1.2.2.2 haad
155 1.2.2.2 haad DPRINT("sbfull, cc(%ld) >= hiwat(%ld): %d, "
156 1.2.2.2 haad "mbcnt(%ld) >= mbmax(%ld): %d",
157 1.2.2.2 haad sb->sb_cc, sb->sb_hiwat, sb->sb_cc >= sb->sb_hiwat,
158 1.2.2.2 haad sb->sb_mbcnt, sb->sb_mbmax, sb->sb_mbcnt >= sb->sb_mbmax);
159 1.2.2.2 haad return (sb->sb_cc >= sb->sb_hiwat || sb->sb_mbcnt >= sb->sb_mbmax);
160 1.2.2.2 haad }
161 1.2.2.2 haad
162 1.2.2.2 haad /*
163 1.2.2.2 haad * start at mbuf m, (must provide npkt if exists)
164 1.2.2.2 haad * starting at offset in m compare characters in mbuf chain for 'cmp'
165 1.2.2.2 haad */
166 1.2.2.2 haad static int
167 1.2.2.2 haad mbufstrcmp(struct mbuf *m, struct mbuf *npkt, int offset, const char *cmp)
168 1.2.2.2 haad {
169 1.2.2.2 haad struct mbuf *n;
170 1.2.2.2 haad
171 1.2.2.2 haad for (; m != NULL; m = n) {
172 1.2.2.2 haad n = npkt;
173 1.2.2.2 haad if (npkt)
174 1.2.2.2 haad npkt = npkt->m_nextpkt;
175 1.2.2.2 haad for (; m; m = m->m_next) {
176 1.2.2.2 haad for (; offset < m->m_len; offset++, cmp++) {
177 1.2.2.2 haad if (*cmp == '\0')
178 1.2.2.2 haad return (1);
179 1.2.2.2 haad else if (*cmp != *(mtod(m, char *) + offset))
180 1.2.2.2 haad return (0);
181 1.2.2.2 haad }
182 1.2.2.2 haad if (*cmp == '\0')
183 1.2.2.2 haad return (1);
184 1.2.2.2 haad offset = 0;
185 1.2.2.2 haad }
186 1.2.2.2 haad }
187 1.2.2.2 haad return (0);
188 1.2.2.2 haad }
189 1.2.2.2 haad
190 1.2.2.2 haad /*
191 1.2.2.2 haad * start at mbuf m, (must provide npkt if exists)
192 1.2.2.2 haad * starting at offset in m compare characters in mbuf chain for 'cmp'
193 1.2.2.2 haad * stop at 'max' characters
194 1.2.2.2 haad */
195 1.2.2.2 haad static int
196 1.2.2.2 haad mbufstrncmp(struct mbuf *m, struct mbuf *npkt, int offset, int len, const char *cmp)
197 1.2.2.2 haad {
198 1.2.2.2 haad struct mbuf *n;
199 1.2.2.2 haad
200 1.2.2.2 haad for (; m != NULL; m = n) {
201 1.2.2.2 haad n = npkt;
202 1.2.2.2 haad if (npkt)
203 1.2.2.2 haad npkt = npkt->m_nextpkt;
204 1.2.2.2 haad for (; m; m = m->m_next) {
205 1.2.2.2 haad for (; offset < m->m_len; offset++, cmp++, len--) {
206 1.2.2.2 haad if (len == 0 || *cmp == '\0')
207 1.2.2.2 haad return (1);
208 1.2.2.2 haad else if (*cmp != *(mtod(m, char *) + offset))
209 1.2.2.2 haad return (0);
210 1.2.2.2 haad }
211 1.2.2.2 haad if (len == 0 || *cmp == '\0')
212 1.2.2.2 haad return (1);
213 1.2.2.2 haad offset = 0;
214 1.2.2.2 haad }
215 1.2.2.2 haad }
216 1.2.2.2 haad return (0);
217 1.2.2.2 haad }
218 1.2.2.2 haad
219 1.2.2.2 haad #define STRSETUP(sptr, slen, str) \
220 1.2.2.2 haad do { \
221 1.2.2.2 haad sptr = str; \
222 1.2.2.2 haad slen = sizeof(str) - 1; \
223 1.2.2.2 haad } while(0)
224 1.2.2.2 haad
225 1.2.2.2 haad static void
226 1.2.2.2 haad sohashttpget(struct socket *so, void *arg, int waitflag)
227 1.2.2.2 haad {
228 1.2.2.2 haad
229 1.2.2.2 haad if ((so->so_state & SS_CANTRCVMORE) == 0 && !sbfull(&so->so_rcv)) {
230 1.2.2.2 haad struct mbuf *m;
231 1.2.2.2 haad const char *cmp;
232 1.2.2.2 haad int cmplen, cc;
233 1.2.2.2 haad
234 1.2.2.2 haad m = so->so_rcv.sb_mb;
235 1.2.2.2 haad cc = so->so_rcv.sb_cc - 1;
236 1.2.2.2 haad if (cc < 1)
237 1.2.2.2 haad return;
238 1.2.2.2 haad switch (*mtod(m, char *)) {
239 1.2.2.2 haad case 'G':
240 1.2.2.2 haad STRSETUP(cmp, cmplen, "ET ");
241 1.2.2.2 haad break;
242 1.2.2.2 haad case 'H':
243 1.2.2.2 haad STRSETUP(cmp, cmplen, "EAD ");
244 1.2.2.2 haad break;
245 1.2.2.2 haad default:
246 1.2.2.2 haad goto fallout;
247 1.2.2.2 haad }
248 1.2.2.2 haad if (cc < cmplen) {
249 1.2.2.2 haad if (mbufstrncmp(m, m->m_nextpkt, 1, cc, cmp) == 1) {
250 1.2.2.2 haad DPRINT("short cc (%d) but mbufstrncmp ok", cc);
251 1.2.2.2 haad return;
252 1.2.2.2 haad } else {
253 1.2.2.2 haad DPRINT("short cc (%d) mbufstrncmp failed", cc);
254 1.2.2.2 haad goto fallout;
255 1.2.2.2 haad }
256 1.2.2.2 haad }
257 1.2.2.2 haad if (mbufstrcmp(m, m->m_nextpkt, 1, cmp) == 1) {
258 1.2.2.2 haad DPRINT("mbufstrcmp ok");
259 1.2.2.2 haad if (parse_http_version == 0)
260 1.2.2.2 haad soishttpconnected(so, arg, waitflag);
261 1.2.2.2 haad else
262 1.2.2.2 haad soparsehttpvers(so, arg, waitflag);
263 1.2.2.2 haad return;
264 1.2.2.2 haad }
265 1.2.2.2 haad DPRINT("mbufstrcmp bad");
266 1.2.2.2 haad }
267 1.2.2.2 haad
268 1.2.2.2 haad fallout:
269 1.2.2.2 haad DPRINT("fallout");
270 1.2.2.2 haad so->so_upcall = NULL;
271 1.2.2.2 haad so->so_rcv.sb_flags &= ~SB_UPCALL;
272 1.2.2.2 haad soisconnected(so);
273 1.2.2.2 haad return;
274 1.2.2.2 haad }
275 1.2.2.2 haad
276 1.2.2.2 haad static void
277 1.2.2.2 haad soparsehttpvers(struct socket *so, void *arg, int waitflag)
278 1.2.2.2 haad {
279 1.2.2.2 haad struct mbuf *m, *n;
280 1.2.2.2 haad int i, cc, spaces, inspaces;
281 1.2.2.2 haad
282 1.2.2.2 haad if ((so->so_state & SS_CANTRCVMORE) != 0 || sbfull(&so->so_rcv))
283 1.2.2.2 haad goto fallout;
284 1.2.2.2 haad
285 1.2.2.2 haad m = so->so_rcv.sb_mb;
286 1.2.2.2 haad cc = so->so_rcv.sb_cc;
287 1.2.2.2 haad inspaces = spaces = 0;
288 1.2.2.2 haad for (m = so->so_rcv.sb_mb; m; m = n) {
289 1.2.2.2 haad n = m->m_nextpkt;
290 1.2.2.2 haad for (; m; m = m->m_next) {
291 1.2.2.2 haad for (i = 0; i < m->m_len; i++, cc--) {
292 1.2.2.2 haad switch (*(mtod(m, char *) + i)) {
293 1.2.2.2 haad case ' ':
294 1.2.2.2 haad /* tabs? '\t' */
295 1.2.2.2 haad if (!inspaces) {
296 1.2.2.2 haad spaces++;
297 1.2.2.2 haad inspaces = 1;
298 1.2.2.2 haad }
299 1.2.2.2 haad break;
300 1.2.2.2 haad case '\r':
301 1.2.2.2 haad case '\n':
302 1.2.2.2 haad DPRINT("newline");
303 1.2.2.2 haad goto fallout;
304 1.2.2.2 haad default:
305 1.2.2.2 haad if (spaces != 2) {
306 1.2.2.2 haad inspaces = 0;
307 1.2.2.2 haad break;
308 1.2.2.2 haad }
309 1.2.2.2 haad
310 1.2.2.2 haad /*
311 1.2.2.2 haad * if we don't have enough characters
312 1.2.2.2 haad * left (cc < sizeof("HTTP/1.0") - 1)
313 1.2.2.2 haad * then see if the remaining ones
314 1.2.2.2 haad * are a request we can parse.
315 1.2.2.2 haad */
316 1.2.2.2 haad if (cc < sizeof("HTTP/1.0") - 1) {
317 1.2.2.2 haad if (mbufstrncmp(m, n, i, cc,
318 1.2.2.2 haad "HTTP/1.") == 1) {
319 1.2.2.2 haad DPRINT("ok");
320 1.2.2.2 haad goto readmore;
321 1.2.2.2 haad } else {
322 1.2.2.2 haad DPRINT("bad");
323 1.2.2.2 haad goto fallout;
324 1.2.2.2 haad }
325 1.2.2.2 haad } else if (
326 1.2.2.2 haad mbufstrcmp(m, n, i, "HTTP/1.0") ||
327 1.2.2.2 haad mbufstrcmp(m, n, i, "HTTP/1.1")) {
328 1.2.2.2 haad DPRINT("ok");
329 1.2.2.2 haad soishttpconnected(so,
330 1.2.2.2 haad arg, waitflag);
331 1.2.2.2 haad return;
332 1.2.2.2 haad } else {
333 1.2.2.2 haad DPRINT("bad");
334 1.2.2.2 haad goto fallout;
335 1.2.2.2 haad }
336 1.2.2.2 haad }
337 1.2.2.2 haad }
338 1.2.2.2 haad }
339 1.2.2.2 haad }
340 1.2.2.2 haad readmore:
341 1.2.2.2 haad DPRINT("readmore");
342 1.2.2.2 haad /*
343 1.2.2.2 haad * if we hit here we haven't hit something
344 1.2.2.2 haad * we don't understand or a newline, so try again
345 1.2.2.2 haad */
346 1.2.2.2 haad so->so_upcall = soparsehttpvers;
347 1.2.2.2 haad so->so_rcv.sb_flags |= SB_UPCALL;
348 1.2.2.2 haad return;
349 1.2.2.2 haad
350 1.2.2.2 haad fallout:
351 1.2.2.2 haad DPRINT("fallout");
352 1.2.2.2 haad so->so_upcall = NULL;
353 1.2.2.2 haad so->so_rcv.sb_flags &= ~SB_UPCALL;
354 1.2.2.2 haad soisconnected(so);
355 1.2.2.2 haad return;
356 1.2.2.2 haad }
357 1.2.2.2 haad
358 1.2.2.2 haad
359 1.2.2.2 haad #define NCHRS 3
360 1.2.2.2 haad
361 1.2.2.2 haad static void
362 1.2.2.2 haad soishttpconnected(struct socket *so, void *arg, int waitflag)
363 1.2.2.2 haad {
364 1.2.2.2 haad char a, b, c;
365 1.2.2.2 haad struct mbuf *m, *n;
366 1.2.2.2 haad int ccleft, copied;
367 1.2.2.2 haad
368 1.2.2.2 haad DPRINT("start");
369 1.2.2.2 haad if ((so->so_state & SS_CANTRCVMORE) != 0 || sbfull(&so->so_rcv))
370 1.2.2.2 haad goto gotit;
371 1.2.2.2 haad
372 1.2.2.2 haad /*
373 1.2.2.2 haad * Walk the socketbuffer and copy the last NCHRS (3) into a, b, and c
374 1.2.2.2 haad * copied - how much we've copied so far
375 1.2.2.2 haad * ccleft - how many bytes remaining in the socketbuffer
376 1.2.2.2 haad * just loop over the mbufs subtracting from 'ccleft' until we only
377 1.2.2.2 haad * have NCHRS left
378 1.2.2.2 haad */
379 1.2.2.2 haad copied = 0;
380 1.2.2.2 haad ccleft = so->so_rcv.sb_cc;
381 1.2.2.2 haad if (ccleft < NCHRS)
382 1.2.2.2 haad goto readmore;
383 1.2.2.2 haad a = b = c = '\0';
384 1.2.2.2 haad for (m = so->so_rcv.sb_mb; m; m = n) {
385 1.2.2.2 haad n = m->m_nextpkt;
386 1.2.2.2 haad for (; m; m = m->m_next) {
387 1.2.2.2 haad ccleft -= m->m_len;
388 1.2.2.2 haad if (ccleft <= NCHRS) {
389 1.2.2.2 haad char *src;
390 1.2.2.2 haad int tocopy;
391 1.2.2.2 haad
392 1.2.2.2 haad tocopy = (NCHRS - ccleft) - copied;
393 1.2.2.2 haad src = mtod(m, char *) + (m->m_len - tocopy);
394 1.2.2.2 haad
395 1.2.2.2 haad while (tocopy--) {
396 1.2.2.2 haad switch (copied++) {
397 1.2.2.2 haad case 0:
398 1.2.2.2 haad a = *src++;
399 1.2.2.2 haad break;
400 1.2.2.2 haad case 1:
401 1.2.2.2 haad b = *src++;
402 1.2.2.2 haad break;
403 1.2.2.2 haad case 2:
404 1.2.2.2 haad c = *src++;
405 1.2.2.2 haad break;
406 1.2.2.2 haad }
407 1.2.2.2 haad }
408 1.2.2.2 haad }
409 1.2.2.2 haad }
410 1.2.2.2 haad }
411 1.2.2.2 haad if (c == '\n' && (b == '\n' || (b == '\r' && a == '\n'))) {
412 1.2.2.2 haad /* we have all request headers */
413 1.2.2.2 haad goto gotit;
414 1.2.2.2 haad }
415 1.2.2.2 haad
416 1.2.2.2 haad readmore:
417 1.2.2.2 haad so->so_upcall = soishttpconnected;
418 1.2.2.2 haad so->so_rcv.sb_flags |= SB_UPCALL;
419 1.2.2.2 haad return;
420 1.2.2.2 haad
421 1.2.2.2 haad gotit:
422 1.2.2.2 haad so->so_upcall = NULL;
423 1.2.2.2 haad so->so_rcv.sb_flags &= ~SB_UPCALL;
424 1.2.2.2 haad soisconnected(so);
425 1.2.2.2 haad return;
426 1.2.2.2 haad }
427