1 | /*
|
---|
2 | * Copyright (c) 1982, 1986, 1988, 1993
|
---|
3 | * The Regents of the University of California. All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | * 1. Redistributions of source code must retain the above copyright
|
---|
9 | * notice, this list of conditions and the following disclaimer.
|
---|
10 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
11 | * notice, this list of conditions and the following disclaimer in the
|
---|
12 | * documentation and/or other materials provided with the distribution.
|
---|
13 | * 3. All advertising materials mentioning features or use of this software
|
---|
14 | * must display the following acknowledgement:
|
---|
15 | * This product includes software developed by the University of
|
---|
16 | * California, Berkeley and its contributors.
|
---|
17 | * 4. Neither the name of the University nor the names of its contributors
|
---|
18 | * may be used to endorse or promote products derived from this software
|
---|
19 | * without specific prior written permission.
|
---|
20 | *
|
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
---|
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
---|
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
---|
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
31 | * SUCH DAMAGE.
|
---|
32 | *
|
---|
33 | * @(#)ip_input.c 8.2 (Berkeley) 1/4/94
|
---|
34 | * ip_input.c,v 1.11 1994/11/16 10:17:08 jkh Exp
|
---|
35 | */
|
---|
36 |
|
---|
37 | /*
|
---|
38 | * Changes and additions relating to SLiRP are
|
---|
39 | * Copyright (c) 1995 Danny Gasparovski.
|
---|
40 | *
|
---|
41 | * Please read the file COPYRIGHT for the
|
---|
42 | * terms and conditions of the copyright.
|
---|
43 | */
|
---|
44 |
|
---|
45 | #include <slirp.h>
|
---|
46 | #include "ip_icmp.h"
|
---|
47 |
|
---|
48 |
|
---|
49 | /*
|
---|
50 | * IP initialization: fill in IP protocol switch table.
|
---|
51 | * All protocols not implemented in kernel go to raw IP protocol handler.
|
---|
52 | */
|
---|
53 | void
|
---|
54 | ip_init(PNATState pData)
|
---|
55 | {
|
---|
56 | int i = 0;
|
---|
57 | for (i = 0; i < IPREASS_NHASH; ++i)
|
---|
58 | TAILQ_INIT(&ipq[i]);
|
---|
59 | maxnipq = 100; /* ??? */
|
---|
60 | maxfragsperpacket = 16;
|
---|
61 | nipq = 0;
|
---|
62 | ip_currid = tt.tv_sec & 0xffff;
|
---|
63 | udp_init(pData);
|
---|
64 | tcp_init(pData);
|
---|
65 | }
|
---|
66 |
|
---|
67 | /*
|
---|
68 | * Ip input routine. Checksum and byte swap header. If fragmented
|
---|
69 | * try to reassemble. Process options. Pass to next level.
|
---|
70 | */
|
---|
71 | void
|
---|
72 | ip_input(PNATState pData, struct mbuf *m)
|
---|
73 | {
|
---|
74 | register struct ip *ip;
|
---|
75 | int hlen;
|
---|
76 |
|
---|
77 | DEBUG_CALL("ip_input");
|
---|
78 | DEBUG_ARG("m = %lx", (long)m);
|
---|
79 | DEBUG_ARG("m_len = %d", m->m_len);
|
---|
80 |
|
---|
81 | ipstat.ips_total++;
|
---|
82 |
|
---|
83 | if (m->m_len < sizeof(struct ip))
|
---|
84 | {
|
---|
85 | ipstat.ips_toosmall++;
|
---|
86 | return;
|
---|
87 | }
|
---|
88 |
|
---|
89 | ip = mtod(m, struct ip *);
|
---|
90 | if (ip->ip_v != IPVERSION)
|
---|
91 | {
|
---|
92 | ipstat.ips_badvers++;
|
---|
93 | goto bad;
|
---|
94 | }
|
---|
95 |
|
---|
96 | hlen = ip->ip_hl << 2;
|
---|
97 | if ( hlen < sizeof(struct ip)
|
---|
98 | || hlen > m->m_len)
|
---|
99 | {
|
---|
100 | /* min header length */
|
---|
101 | ipstat.ips_badhlen++; /* or packet too short */
|
---|
102 | goto bad;
|
---|
103 | }
|
---|
104 |
|
---|
105 | /* keep ip header intact for ICMP reply
|
---|
106 | * ip->ip_sum = cksum(m, hlen);
|
---|
107 | * if (ip->ip_sum) {
|
---|
108 | */
|
---|
109 | if (cksum(m, hlen))
|
---|
110 | {
|
---|
111 | ipstat.ips_badsum++;
|
---|
112 | goto bad;
|
---|
113 | }
|
---|
114 |
|
---|
115 | /*
|
---|
116 | * Convert fields to host representation.
|
---|
117 | */
|
---|
118 | NTOHS(ip->ip_len);
|
---|
119 | if (ip->ip_len < hlen)
|
---|
120 | {
|
---|
121 | ipstat.ips_badlen++;
|
---|
122 | goto bad;
|
---|
123 | }
|
---|
124 | NTOHS(ip->ip_id);
|
---|
125 | NTOHS(ip->ip_off);
|
---|
126 |
|
---|
127 | /*
|
---|
128 | * Check that the amount of data in the buffers
|
---|
129 | * is as at least much as the IP header would have us expect.
|
---|
130 | * Trim mbufs if longer than we expect.
|
---|
131 | * Drop packet if shorter than we expect.
|
---|
132 | */
|
---|
133 | if (m->m_len < ip->ip_len)
|
---|
134 | {
|
---|
135 | ipstat.ips_tooshort++;
|
---|
136 | goto bad;
|
---|
137 | }
|
---|
138 | /* Should drop packet if mbuf too long? hmmm... */
|
---|
139 | if (m->m_len > ip->ip_len)
|
---|
140 | m_adj(m, ip->ip_len - m->m_len);
|
---|
141 |
|
---|
142 | /* check ip_ttl for a correct ICMP reply */
|
---|
143 | if (ip->ip_ttl==0 || ip->ip_ttl == 1)
|
---|
144 | {
|
---|
145 | icmp_error(pData, m, ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS, 0, "ttl");
|
---|
146 | goto bad;
|
---|
147 | }
|
---|
148 |
|
---|
149 | ip->ip_ttl--;
|
---|
150 | /*
|
---|
151 | * If offset or IP_MF are set, must reassemble.
|
---|
152 | * Otherwise, nothing need be done.
|
---|
153 | * (We could look in the reassembly queue to see
|
---|
154 | * if the packet was previously fragmented,
|
---|
155 | * but it's not worth the time; just let them time out.)
|
---|
156 | *
|
---|
157 | * XXX This should fail, don't fragment yet
|
---|
158 | */
|
---|
159 | if (ip->ip_off & (IP_MF | IP_OFFMASK))
|
---|
160 | {
|
---|
161 | m = ip_reass(pData, m);
|
---|
162 | if (m == NULL)
|
---|
163 | return;
|
---|
164 | ip = mtod(m, struct ip *);
|
---|
165 | hlen = ip->ip_len;
|
---|
166 | }
|
---|
167 | else
|
---|
168 | ip->ip_len -= hlen;
|
---|
169 |
|
---|
170 | /*
|
---|
171 | * Switch out to protocol's input routine.
|
---|
172 | */
|
---|
173 | ipstat.ips_delivered++;
|
---|
174 | switch (ip->ip_p)
|
---|
175 | {
|
---|
176 | case IPPROTO_TCP:
|
---|
177 | tcp_input(pData, m, hlen, (struct socket *)NULL);
|
---|
178 | break;
|
---|
179 | case IPPROTO_UDP:
|
---|
180 | udp_input(pData, m, hlen);
|
---|
181 | break;
|
---|
182 | case IPPROTO_ICMP:
|
---|
183 | icmp_input(pData, m, hlen);
|
---|
184 | break;
|
---|
185 | default:
|
---|
186 | ipstat.ips_noproto++;
|
---|
187 | m_free(pData, m);
|
---|
188 | }
|
---|
189 | return;
|
---|
190 | bad:
|
---|
191 | m_freem(pData, m);
|
---|
192 | return;
|
---|
193 | }
|
---|
194 |
|
---|
195 | struct mbuf *
|
---|
196 | ip_reass(PNATState pData, struct mbuf* m)
|
---|
197 | {
|
---|
198 | struct ip *ip;
|
---|
199 | struct mbuf *p, *q, *nq;
|
---|
200 | struct ipq_t *fp = NULL;
|
---|
201 | struct ipqhead *head;
|
---|
202 | int i, hlen, next;
|
---|
203 | u_short hash;
|
---|
204 |
|
---|
205 | /* If maxnipq or maxfragsperpacket are 0, never accept fragments. */
|
---|
206 | if ( maxnipq == 0
|
---|
207 | || maxfragsperpacket == 0)
|
---|
208 | {
|
---|
209 | ipstat.ips_fragments++;
|
---|
210 | ipstat.ips_fragdropped++;
|
---|
211 | m_freem(pData, m);
|
---|
212 | return (NULL);
|
---|
213 | }
|
---|
214 |
|
---|
215 | ip = mtod(m, struct ip *);
|
---|
216 | hlen = ip->ip_hl << 2;
|
---|
217 |
|
---|
218 | hash = IPREASS_HASH(ip->ip_src.s_addr, ip->ip_id);
|
---|
219 | head = &ipq[hash];
|
---|
220 |
|
---|
221 | /*
|
---|
222 | * Look for queue of fragments
|
---|
223 | * of this datagram.
|
---|
224 | */
|
---|
225 | TAILQ_FOREACH(fp, head, ipq_list)
|
---|
226 | if (ip->ip_id == fp->ipq_id &&
|
---|
227 | ip->ip_src.s_addr == fp->ipq_src.s_addr &&
|
---|
228 | ip->ip_dst.s_addr == fp->ipq_dst.s_addr &&
|
---|
229 | ip->ip_p == fp->ipq_p)
|
---|
230 | goto found;
|
---|
231 |
|
---|
232 | fp = NULL;
|
---|
233 |
|
---|
234 | /*
|
---|
235 | * Attempt to trim the number of allocated fragment queues if it
|
---|
236 | * exceeds the administrative limit.
|
---|
237 | */
|
---|
238 | if ((nipq > maxnipq) && (maxnipq > 0))
|
---|
239 | {
|
---|
240 | /*
|
---|
241 | * drop something from the tail of the current queue
|
---|
242 | * before proceeding further
|
---|
243 | */
|
---|
244 | struct ipq_t *q = TAILQ_LAST(head, ipqhead);
|
---|
245 | if (q == NULL)
|
---|
246 | {
|
---|
247 | /* gak */
|
---|
248 | for (i = 0; i < IPREASS_NHASH; i++)
|
---|
249 | {
|
---|
250 | struct ipq_t *r = TAILQ_LAST(&ipq[i], ipqhead);
|
---|
251 | if (r)
|
---|
252 | {
|
---|
253 | ipstat.ips_fragtimeout += r->ipq_nfrags;
|
---|
254 | ip_freef(pData, &ipq[i], r);
|
---|
255 | break;
|
---|
256 | }
|
---|
257 | }
|
---|
258 | }
|
---|
259 | else
|
---|
260 | {
|
---|
261 | ipstat.ips_fragtimeout += q->ipq_nfrags;
|
---|
262 | ip_freef(pData, head, q);
|
---|
263 | }
|
---|
264 | }
|
---|
265 |
|
---|
266 | found:
|
---|
267 | /*
|
---|
268 | * Adjust ip_len to not reflect header,
|
---|
269 | * convert offset of this to bytes.
|
---|
270 | */
|
---|
271 | ip->ip_len -= hlen;
|
---|
272 | if (ip->ip_off & IP_MF)
|
---|
273 | {
|
---|
274 | /*
|
---|
275 | * Make sure that fragments have a data length
|
---|
276 | * that's a non-zero multiple of 8 bytes.
|
---|
277 | */
|
---|
278 | if (ip->ip_len == 0 || (ip->ip_len & 0x7) != 0)
|
---|
279 | {
|
---|
280 | ipstat.ips_toosmall++; /* XXX */
|
---|
281 | goto dropfrag;
|
---|
282 | }
|
---|
283 | m->m_flags |= M_FRAG;
|
---|
284 | }
|
---|
285 | else
|
---|
286 | m->m_flags &= ~M_FRAG;
|
---|
287 | ip->ip_off <<= 3;
|
---|
288 |
|
---|
289 |
|
---|
290 | /*
|
---|
291 | * Attempt reassembly; if it succeeds, proceed.
|
---|
292 | * ip_reass() will return a different mbuf.
|
---|
293 | */
|
---|
294 | ipstat.ips_fragments++;
|
---|
295 |
|
---|
296 | /* Previous ip_reass() started here. */
|
---|
297 | /*
|
---|
298 | * Presence of header sizes in mbufs
|
---|
299 | * would confuse code below.
|
---|
300 | */
|
---|
301 | m->m_data += hlen;
|
---|
302 | m->m_len -= hlen;
|
---|
303 |
|
---|
304 | /*
|
---|
305 | * If first fragment to arrive, create a reassembly queue.
|
---|
306 | */
|
---|
307 | if (fp == NULL)
|
---|
308 | {
|
---|
309 | fp = RTMemAlloc(sizeof(struct ipq_t));
|
---|
310 | if (fp == NULL)
|
---|
311 | goto dropfrag;
|
---|
312 | TAILQ_INSERT_HEAD(head, fp, ipq_list);
|
---|
313 | nipq++;
|
---|
314 | fp->ipq_nfrags = 1;
|
---|
315 | fp->ipq_ttl = IPFRAGTTL;
|
---|
316 | fp->ipq_p = ip->ip_p;
|
---|
317 | fp->ipq_id = ip->ip_id;
|
---|
318 | fp->ipq_src = ip->ip_src;
|
---|
319 | fp->ipq_dst = ip->ip_dst;
|
---|
320 | fp->ipq_frags = m;
|
---|
321 | m->m_nextpkt = NULL;
|
---|
322 | goto done;
|
---|
323 | }
|
---|
324 | else
|
---|
325 | {
|
---|
326 | fp->ipq_nfrags++;
|
---|
327 | }
|
---|
328 |
|
---|
329 | #define GETIP(m) ((struct ip*)(MBUF_IP_HEADER(m)))
|
---|
330 |
|
---|
331 |
|
---|
332 | /*
|
---|
333 | * Find a segment which begins after this one does.
|
---|
334 | */
|
---|
335 | for (p = NULL, q = fp->ipq_frags; q; p = q, q = q->m_nextpkt)
|
---|
336 | if (GETIP(q)->ip_off > ip->ip_off)
|
---|
337 | break;
|
---|
338 |
|
---|
339 | /*
|
---|
340 | * If there is a preceding segment, it may provide some of
|
---|
341 | * our data already. If so, drop the data from the incoming
|
---|
342 | * segment. If it provides all of our data, drop us, otherwise
|
---|
343 | * stick new segment in the proper place.
|
---|
344 | *
|
---|
345 | * If some of the data is dropped from the the preceding
|
---|
346 | * segment, then it's checksum is invalidated.
|
---|
347 | */
|
---|
348 | if (p)
|
---|
349 | {
|
---|
350 | i = GETIP(p)->ip_off + GETIP(p)->ip_len - ip->ip_off;
|
---|
351 | if (i > 0)
|
---|
352 | {
|
---|
353 | if (i >= ip->ip_len)
|
---|
354 | goto dropfrag;
|
---|
355 | m_adj(m, i);
|
---|
356 | ip->ip_off += i;
|
---|
357 | ip->ip_len -= i;
|
---|
358 | }
|
---|
359 | m->m_nextpkt = p->m_nextpkt;
|
---|
360 | p->m_nextpkt = m;
|
---|
361 | }
|
---|
362 | else
|
---|
363 | {
|
---|
364 | m->m_nextpkt = fp->ipq_frags;
|
---|
365 | fp->ipq_frags = m;
|
---|
366 | }
|
---|
367 |
|
---|
368 | /*
|
---|
369 | * While we overlap succeeding segments trim them or,
|
---|
370 | * if they are completely covered, dequeue them.
|
---|
371 | */
|
---|
372 | for (; q != NULL && ip->ip_off + ip->ip_len > GETIP(q)->ip_off;
|
---|
373 | q = nq)
|
---|
374 | {
|
---|
375 | i = (ip->ip_off + ip->ip_len) - GETIP(q)->ip_off;
|
---|
376 | if (i < GETIP(q)->ip_len)
|
---|
377 | {
|
---|
378 | GETIP(q)->ip_len -= i;
|
---|
379 | GETIP(q)->ip_off += i;
|
---|
380 | m_adj(q, i);
|
---|
381 | break;
|
---|
382 | }
|
---|
383 | nq = q->m_nextpkt;
|
---|
384 | m->m_nextpkt = nq;
|
---|
385 | ipstat.ips_fragdropped++;
|
---|
386 | fp->ipq_nfrags--;
|
---|
387 | m_freem(pData, q);
|
---|
388 | }
|
---|
389 |
|
---|
390 | /*
|
---|
391 | * Check for complete reassembly and perform frag per packet
|
---|
392 | * limiting.
|
---|
393 | *
|
---|
394 | * Frag limiting is performed here so that the nth frag has
|
---|
395 | * a chance to complete the packet before we drop the packet.
|
---|
396 | * As a result, n+1 frags are actually allowed per packet, but
|
---|
397 | * only n will ever be stored. (n = maxfragsperpacket.)
|
---|
398 | *
|
---|
399 | */
|
---|
400 | next = 0;
|
---|
401 | for (p = NULL, q = fp->ipq_frags; q; p = q, q = q->m_nextpkt)
|
---|
402 | {
|
---|
403 | if (GETIP(q)->ip_off != next)
|
---|
404 | {
|
---|
405 | if (fp->ipq_nfrags > maxfragsperpacket)
|
---|
406 | {
|
---|
407 | ipstat.ips_fragdropped += fp->ipq_nfrags;
|
---|
408 | ip_freef(pData, head, fp);
|
---|
409 | }
|
---|
410 | goto done;
|
---|
411 | }
|
---|
412 | next += GETIP(q)->ip_len;
|
---|
413 | }
|
---|
414 | /* Make sure the last packet didn't have the IP_MF flag */
|
---|
415 | if (p->m_flags & M_FRAG)
|
---|
416 | {
|
---|
417 | if (fp->ipq_nfrags > maxfragsperpacket)
|
---|
418 | {
|
---|
419 | ipstat.ips_fragdropped += fp->ipq_nfrags;
|
---|
420 | ip_freef(pData, head, fp);
|
---|
421 | }
|
---|
422 | goto done;
|
---|
423 | }
|
---|
424 |
|
---|
425 | /*
|
---|
426 | * Reassembly is complete. Make sure the packet is a sane size.
|
---|
427 | */
|
---|
428 | q = fp->ipq_frags;
|
---|
429 | ip = GETIP(q);
|
---|
430 | if (next + (ip->ip_hl << 2) > IP_MAXPACKET)
|
---|
431 | {
|
---|
432 | ipstat.ips_fragdropped += fp->ipq_nfrags;
|
---|
433 | ip_freef(pData, head, fp);
|
---|
434 | goto done;
|
---|
435 | }
|
---|
436 |
|
---|
437 | /*
|
---|
438 | * Concatenate fragments.
|
---|
439 | */
|
---|
440 | m = q;
|
---|
441 | nq = q->m_nextpkt;
|
---|
442 | q->m_nextpkt = NULL;
|
---|
443 | for (q = nq; q != NULL; q = nq)
|
---|
444 | {
|
---|
445 | nq = q->m_nextpkt;
|
---|
446 | q->m_nextpkt = NULL;
|
---|
447 | m_cat(pData, m, q);
|
---|
448 | }
|
---|
449 |
|
---|
450 | /*
|
---|
451 | * Create header for new ip packet by modifying header of first
|
---|
452 | * packet; dequeue and discard fragment reassembly header.
|
---|
453 | * Make header visible.
|
---|
454 | */
|
---|
455 | #if 0
|
---|
456 | ip->ip_len = (ip->ip_hl << 2) + next;
|
---|
457 | #else
|
---|
458 | ip->ip_len = next;
|
---|
459 | #endif
|
---|
460 | ip->ip_src = fp->ipq_src;
|
---|
461 | ip->ip_dst = fp->ipq_dst;
|
---|
462 | TAILQ_REMOVE(head, fp, ipq_list);
|
---|
463 | nipq--;
|
---|
464 | RTMemFree(fp);
|
---|
465 |
|
---|
466 | m->m_len += (ip->ip_hl << 2);
|
---|
467 | m->m_data -= (ip->ip_hl << 2);
|
---|
468 | /* some debugging cruft by sklower, below, will go away soon */
|
---|
469 | #if 0
|
---|
470 | if (m->m_flags & M_PKTHDR) /* XXX this should be done elsewhere */
|
---|
471 | m_fixhdr(m);
|
---|
472 | #endif
|
---|
473 | ipstat.ips_reassembled++;
|
---|
474 | return (m);
|
---|
475 |
|
---|
476 | dropfrag:
|
---|
477 | ipstat.ips_fragdropped++;
|
---|
478 | if (fp != NULL)
|
---|
479 | fp->ipq_nfrags--;
|
---|
480 | m_freem(pData, m);
|
---|
481 |
|
---|
482 | done:
|
---|
483 | return NULL;
|
---|
484 |
|
---|
485 | #undef GETIP
|
---|
486 | }
|
---|
487 |
|
---|
488 | void
|
---|
489 | ip_freef(PNATState pData, struct ipqhead *fhp, struct ipq_t *fp)
|
---|
490 | {
|
---|
491 | struct mbuf *q;
|
---|
492 |
|
---|
493 | while (fp->ipq_frags)
|
---|
494 | {
|
---|
495 | q = fp->ipq_frags;
|
---|
496 | fp->ipq_frags = q->m_nextpkt;
|
---|
497 | m_freem(pData, q);
|
---|
498 | }
|
---|
499 | TAILQ_REMOVE(fhp, fp, ipq_list);
|
---|
500 | RTMemFree(fp);
|
---|
501 | nipq--;
|
---|
502 | }
|
---|
503 |
|
---|
504 | /*
|
---|
505 | * IP timer processing;
|
---|
506 | * if a timer expires on a reassembly
|
---|
507 | * queue, discard it.
|
---|
508 | */
|
---|
509 | void
|
---|
510 | ip_slowtimo(PNATState pData)
|
---|
511 | {
|
---|
512 | register struct ipq_t *fp;
|
---|
513 |
|
---|
514 | /* XXX: the fragment expiration is the same but requier
|
---|
515 | * additional loop see (see ip_input.c in FreeBSD tree)
|
---|
516 | */
|
---|
517 | int i;
|
---|
518 | DEBUG_CALL("ip_slowtimo");
|
---|
519 | for (i = 0; i < IPREASS_NHASH; i++)
|
---|
520 | {
|
---|
521 | for(fp = TAILQ_FIRST(&ipq[i]); fp;)
|
---|
522 | {
|
---|
523 | struct ipq_t *fpp;
|
---|
524 |
|
---|
525 | fpp = fp;
|
---|
526 | fp = TAILQ_NEXT(fp, ipq_list);
|
---|
527 | if(--fpp->ipq_ttl == 0)
|
---|
528 | {
|
---|
529 | ipstat.ips_fragtimeout += fpp->ipq_nfrags;
|
---|
530 | ip_freef(pData, &ipq[i], fpp);
|
---|
531 | }
|
---|
532 | }
|
---|
533 | }
|
---|
534 | /*
|
---|
535 | * If we are over the maximum number of fragments
|
---|
536 | * (due to the limit being lowered), drain off
|
---|
537 | * enough to get down to the new limit.
|
---|
538 | */
|
---|
539 | if (maxnipq >= 0 && nipq > maxnipq)
|
---|
540 | {
|
---|
541 | for (i = 0; i < IPREASS_NHASH; i++)
|
---|
542 | {
|
---|
543 | while (nipq > maxnipq && !TAILQ_EMPTY(&ipq[i]))
|
---|
544 | {
|
---|
545 | ipstat.ips_fragdropped += TAILQ_FIRST(&ipq[i])->ipq_nfrags;
|
---|
546 | ip_freef(pData, &ipq[i], TAILQ_FIRST(&ipq[i]));
|
---|
547 | }
|
---|
548 | }
|
---|
549 | }
|
---|
550 | }
|
---|
551 |
|
---|
552 |
|
---|
553 | /*
|
---|
554 | * Strip out IP options, at higher
|
---|
555 | * level protocol in the kernel.
|
---|
556 | * Second argument is buffer to which options
|
---|
557 | * will be moved, and return value is their length.
|
---|
558 | * (XXX) should be deleted; last arg currently ignored.
|
---|
559 | */
|
---|
560 | void
|
---|
561 | ip_stripoptions(struct mbuf *m, struct mbuf *mopt)
|
---|
562 | {
|
---|
563 | register int i;
|
---|
564 | struct ip *ip = mtod(m, struct ip *);
|
---|
565 | register caddr_t opts;
|
---|
566 | int olen;
|
---|
567 |
|
---|
568 | olen = (ip->ip_hl<<2) - sizeof(struct ip);
|
---|
569 | opts = (caddr_t)(ip + 1);
|
---|
570 | i = m->m_len - (sizeof(struct ip) + olen);
|
---|
571 | memcpy(opts, opts + olen, (unsigned)i);
|
---|
572 | m->m_len -= olen;
|
---|
573 |
|
---|
574 | ip->ip_hl = sizeof(struct ip) >> 2;
|
---|
575 | }
|
---|