Statistics
| Branch: | Revision:

root / slirp / ip_input.c @ 31a60e22

History | View | Annotate | Download (17.1 kB)

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
int ip_defttl;
49

    
50
#ifdef LOG_ENABLED
51
struct ipstat ipstat;
52
#endif
53

    
54
struct ipq ipq;
55

    
56
/*
57
 * IP initialization: fill in IP protocol switch table.
58
 * All protocols not implemented in kernel go to raw IP protocol handler.
59
 */
60
void
61
ip_init()
62
{
63
        ipq.next = ipq.prev = (ipqp_32)&ipq;
64
        ip_id = tt.tv_sec & 0xffff;
65
        udp_init();
66
        tcp_init();
67
        ip_defttl = IPDEFTTL;
68
}
69

    
70
/*
71
 * Ip input routine.  Checksum and byte swap header.  If fragmented
72
 * try to reassemble.  Process options.  Pass to next level.
73
 */
74
void
75
ip_input(m)
76
        struct mbuf *m;
77
{
78
        register struct ip *ip;
79
        int hlen;
80

    
81
        DEBUG_CALL("ip_input");
82
        DEBUG_ARG("m = %lx", (long)m);
83
        DEBUG_ARG("m_len = %d", m->m_len);
84

    
85
        STAT(ipstat.ips_total++);
86

    
87
        if (m->m_len < sizeof (struct ip)) {
88
                STAT(ipstat.ips_toosmall++);
89
                return;
90
        }
91

    
92
        ip = mtod(m, struct ip *);
93

    
94
        if (ip->ip_v != IPVERSION) {
95
                STAT(ipstat.ips_badvers++);
96
                goto bad;
97
        }
98

    
99
        hlen = ip->ip_hl << 2;
100
        if (hlen<sizeof(struct ip ) || hlen>m->m_len) {/* min header length */
101
          STAT(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
          STAT(ipstat.ips_badsum++);
111
          goto bad;
112
        }
113

    
114
        /*
115
         * Convert fields to host representation.
116
         */
117
        NTOHS(ip->ip_len);
118
        if (ip->ip_len < hlen) {
119
                STAT(ipstat.ips_badlen++);
120
                goto bad;
121
        }
122
        NTOHS(ip->ip_id);
123
        NTOHS(ip->ip_off);
124

    
125
        /*
126
         * Check that the amount of data in the buffers
127
         * is as at least much as the IP header would have us expect.
128
         * Trim mbufs if longer than we expect.
129
         * Drop packet if shorter than we expect.
130
         */
131
        if (m->m_len < ip->ip_len) {
132
                STAT(ipstat.ips_tooshort++);
133
                goto bad;
134
        }
135
        /* Should drop packet if mbuf too long? hmmm... */
136
        if (m->m_len > ip->ip_len)
137
           m_adj(m, ip->ip_len - m->m_len);
138

    
139
        /* check ip_ttl for a correct ICMP reply */
140
        if(ip->ip_ttl==0 || ip->ip_ttl==1) {
141
          icmp_error(m, ICMP_TIMXCEED,ICMP_TIMXCEED_INTRANS, 0,"ttl");
142
          goto bad;
143
        }
144

    
145
        /*
146
         * Process options and, if not destined for us,
147
         * ship it on.  ip_dooptions returns 1 when an
148
         * error was detected (causing an icmp message
149
         * to be sent and the original packet to be freed).
150
         */
151
/* We do no IP options */
152
/*        if (hlen > sizeof (struct ip) && ip_dooptions(m))
153
 *                goto next;
154
 */
155
        /*
156
         * If offset or IP_MF are set, must reassemble.
157
         * Otherwise, nothing need be done.
158
         * (We could look in the reassembly queue to see
159
         * if the packet was previously fragmented,
160
         * but it's not worth the time; just let them time out.)
161
         *
162
         * XXX This should fail, don't fragment yet
163
         */
164
        if (ip->ip_off &~ IP_DF) {
165
          register struct ipq *fp;
166
                /*
167
                 * Look for queue of fragments
168
                 * of this datagram.
169
                 */
170
                for (fp = (struct ipq *) ipq.next; fp != &ipq;
171
                     fp = (struct ipq *) fp->next)
172
                  if (ip->ip_id == fp->ipq_id &&
173
                      ip->ip_src.s_addr == fp->ipq_src.s_addr &&
174
                      ip->ip_dst.s_addr == fp->ipq_dst.s_addr &&
175
                      ip->ip_p == fp->ipq_p)
176
                    goto found;
177
                fp = 0;
178
        found:
179

    
180
                /*
181
                 * Adjust ip_len to not reflect header,
182
                 * set ip_mff if more fragments are expected,
183
                 * convert offset of this to bytes.
184
                 */
185
                ip->ip_len -= hlen;
186
                if (ip->ip_off & IP_MF)
187
                  ((struct ipasfrag *)ip)->ipf_mff |= 1;
188
                else
189
                  ((struct ipasfrag *)ip)->ipf_mff &= ~1;
190

    
191
                ip->ip_off <<= 3;
192

    
193
                /*
194
                 * If datagram marked as having more fragments
195
                 * or if this is not the first fragment,
196
                 * attempt reassembly; if it succeeds, proceed.
197
                 */
198
                if (((struct ipasfrag *)ip)->ipf_mff & 1 || ip->ip_off) {
199
                        STAT(ipstat.ips_fragments++);
200
                        ip = ip_reass((struct ipasfrag *)ip, fp);
201
                        if (ip == 0)
202
                                return;
203
                        STAT(ipstat.ips_reassembled++);
204
                        m = dtom(ip);
205
                } else
206
                        if (fp)
207
                              ip_freef(fp);
208

    
209
        } else
210
                ip->ip_len -= hlen;
211

    
212
        /*
213
         * Switch out to protocol's input routine.
214
         */
215
        STAT(ipstat.ips_delivered++);
216
        switch (ip->ip_p) {
217
         case IPPROTO_TCP:
218
                tcp_input(m, hlen, (struct socket *)NULL);
219
                break;
220
         case IPPROTO_UDP:
221
                udp_input(m, hlen);
222
                break;
223
         case IPPROTO_ICMP:
224
                icmp_input(m, hlen);
225
                break;
226
         default:
227
                STAT(ipstat.ips_noproto++);
228
                m_free(m);
229
        }
230
        return;
231
bad:
232
        m_freem(m);
233
        return;
234
}
235

    
236
/*
237
 * Take incoming datagram fragment and try to
238
 * reassemble it into whole datagram.  If a chain for
239
 * reassembly of this datagram already exists, then it
240
 * is given as fp; otherwise have to make a chain.
241
 */
242
struct ip *
243
ip_reass(ip, fp)
244
        register struct ipasfrag *ip;
245
        register struct ipq *fp;
246
{
247
        register struct mbuf *m = dtom(ip);
248
        register struct ipasfrag *q;
249
        int hlen = ip->ip_hl << 2;
250
        int i, next;
251

    
252
        DEBUG_CALL("ip_reass");
253
        DEBUG_ARG("ip = %lx", (long)ip);
254
        DEBUG_ARG("fp = %lx", (long)fp);
255
        DEBUG_ARG("m = %lx", (long)m);
256

    
257
        /*
258
         * Presence of header sizes in mbufs
259
         * would confuse code below.
260
         * Fragment m_data is concatenated.
261
         */
262
        m->m_data += hlen;
263
        m->m_len -= hlen;
264

    
265
        /*
266
         * If first fragment to arrive, create a reassembly queue.
267
         */
268
        if (fp == 0) {
269
          struct mbuf *t;
270
          if ((t = m_get()) == NULL) goto dropfrag;
271
          fp = mtod(t, struct ipq *);
272
          insque_32(fp, &ipq);
273
          fp->ipq_ttl = IPFRAGTTL;
274
          fp->ipq_p = ip->ip_p;
275
          fp->ipq_id = ip->ip_id;
276
          fp->ipq_next = fp->ipq_prev = (ipasfragp_32)fp;
277
          fp->ipq_src = ((struct ip *)ip)->ip_src;
278
          fp->ipq_dst = ((struct ip *)ip)->ip_dst;
279
          q = (struct ipasfrag *)fp;
280
          goto insert;
281
        }
282

    
283
        /*
284
         * Find a segment which begins after this one does.
285
         */
286
        for (q = (struct ipasfrag *)fp->ipq_next; q != (struct ipasfrag *)fp;
287
            q = (struct ipasfrag *)q->ipf_next)
288
                if (q->ip_off > ip->ip_off)
289
                        break;
290

    
291
        /*
292
         * If there is a preceding segment, it may provide some of
293
         * our data already.  If so, drop the data from the incoming
294
         * segment.  If it provides all of our data, drop us.
295
         */
296
        if (q->ipf_prev != (ipasfragp_32)fp) {
297
                i = ((struct ipasfrag *)(q->ipf_prev))->ip_off +
298
                  ((struct ipasfrag *)(q->ipf_prev))->ip_len - ip->ip_off;
299
                if (i > 0) {
300
                        if (i >= ip->ip_len)
301
                                goto dropfrag;
302
                        m_adj(dtom(ip), i);
303
                        ip->ip_off += i;
304
                        ip->ip_len -= i;
305
                }
306
        }
307

    
308
        /*
309
         * While we overlap succeeding segments trim them or,
310
         * if they are completely covered, dequeue them.
311
         */
312
        while (q != (struct ipasfrag *)fp && ip->ip_off + ip->ip_len > q->ip_off) {
313
                i = (ip->ip_off + ip->ip_len) - q->ip_off;
314
                if (i < q->ip_len) {
315
                        q->ip_len -= i;
316
                        q->ip_off += i;
317
                        m_adj(dtom(q), i);
318
                        break;
319
                }
320
                q = (struct ipasfrag *) q->ipf_next;
321
                m_freem(dtom((struct ipasfrag *) q->ipf_prev));
322
                ip_deq((struct ipasfrag *) q->ipf_prev);
323
        }
324

    
325
insert:
326
        /*
327
         * Stick new segment in its place;
328
         * check for complete reassembly.
329
         */
330
        ip_enq(ip, (struct ipasfrag *) q->ipf_prev);
331
        next = 0;
332
        for (q = (struct ipasfrag *) fp->ipq_next; q != (struct ipasfrag *)fp;
333
             q = (struct ipasfrag *) q->ipf_next) {
334
                if (q->ip_off != next)
335
                        return (0);
336
                next += q->ip_len;
337
        }
338
        if (((struct ipasfrag *)(q->ipf_prev))->ipf_mff & 1)
339
                return (0);
340

    
341
        /*
342
         * Reassembly is complete; concatenate fragments.
343
         */
344
        q = (struct ipasfrag *) fp->ipq_next;
345
        m = dtom(q);
346

    
347
        q = (struct ipasfrag *) q->ipf_next;
348
        while (q != (struct ipasfrag *)fp) {
349
          struct mbuf *t;
350
          t = dtom(q);
351
          q = (struct ipasfrag *) q->ipf_next;
352
          m_cat(m, t);
353
        }
354

    
355
        /*
356
         * Create header for new ip packet by
357
         * modifying header of first packet;
358
         * dequeue and discard fragment reassembly header.
359
         * Make header visible.
360
         */
361
        ip = (struct ipasfrag *) fp->ipq_next;
362

    
363
        /*
364
         * If the fragments concatenated to an mbuf that's
365
         * bigger than the total size of the fragment, then and
366
         * m_ext buffer was alloced. But fp->ipq_next points to
367
         * the old buffer (in the mbuf), so we must point ip
368
         * into the new buffer.
369
         */
370
        if (m->m_flags & M_EXT) {
371
          int delta;
372
          delta = (char *)ip - m->m_dat;
373
          ip = (struct ipasfrag *)(m->m_ext + delta);
374
        }
375

    
376
        /* DEBUG_ARG("ip = %lx", (long)ip);
377
         * ip=(struct ipasfrag *)m->m_data; */
378

    
379
        ip->ip_len = next;
380
        ip->ipf_mff &= ~1;
381
        ((struct ip *)ip)->ip_src = fp->ipq_src;
382
        ((struct ip *)ip)->ip_dst = fp->ipq_dst;
383
        remque_32(fp);
384
        (void) m_free(dtom(fp));
385
        m = dtom(ip);
386
        m->m_len += (ip->ip_hl << 2);
387
        m->m_data -= (ip->ip_hl << 2);
388

    
389
        return ((struct ip *)ip);
390

    
391
dropfrag:
392
        STAT(ipstat.ips_fragdropped++);
393
        m_freem(m);
394
        return (0);
395
}
396

    
397
/*
398
 * Free a fragment reassembly header and all
399
 * associated datagrams.
400
 */
401
void
402
ip_freef(fp)
403
        struct ipq *fp;
404
{
405
        register struct ipasfrag *q, *p;
406

    
407
        for (q = (struct ipasfrag *) fp->ipq_next; q != (struct ipasfrag *)fp;
408
            q = p) {
409
                p = (struct ipasfrag *) q->ipf_next;
410
                ip_deq(q);
411
                m_freem(dtom(q));
412
        }
413
        remque_32(fp);
414
        (void) m_free(dtom(fp));
415
}
416

    
417
/*
418
 * Put an ip fragment on a reassembly chain.
419
 * Like insque, but pointers in middle of structure.
420
 */
421
void
422
ip_enq(p, prev)
423
        register struct ipasfrag *p, *prev;
424
{
425
        DEBUG_CALL("ip_enq");
426
        DEBUG_ARG("prev = %lx", (long)prev);
427
        p->ipf_prev = (ipasfragp_32) prev;
428
        p->ipf_next = prev->ipf_next;
429
        ((struct ipasfrag *)(prev->ipf_next))->ipf_prev = (ipasfragp_32) p;
430
        prev->ipf_next = (ipasfragp_32) p;
431
}
432

    
433
/*
434
 * To ip_enq as remque is to insque.
435
 */
436
void
437
ip_deq(p)
438
        register struct ipasfrag *p;
439
{
440
        ((struct ipasfrag *)(p->ipf_prev))->ipf_next = p->ipf_next;
441
        ((struct ipasfrag *)(p->ipf_next))->ipf_prev = p->ipf_prev;
442
}
443

    
444
/*
445
 * IP timer processing;
446
 * if a timer expires on a reassembly
447
 * queue, discard it.
448
 */
449
void
450
ip_slowtimo()
451
{
452
        register struct ipq *fp;
453

    
454
        DEBUG_CALL("ip_slowtimo");
455

    
456
        fp = (struct ipq *) ipq.next;
457
        if (fp == 0)
458
           return;
459

    
460
        while (fp != &ipq) {
461
                --fp->ipq_ttl;
462
                fp = (struct ipq *) fp->next;
463
                if (((struct ipq *)(fp->prev))->ipq_ttl == 0) {
464
                        STAT(ipstat.ips_fragtimeout++);
465
                        ip_freef((struct ipq *) fp->prev);
466
                }
467
        }
468
}
469

    
470
/*
471
 * Do option processing on a datagram,
472
 * possibly discarding it if bad options are encountered,
473
 * or forwarding it if source-routed.
474
 * Returns 1 if packet has been forwarded/freed,
475
 * 0 if the packet should be processed further.
476
 */
477

    
478
#ifdef notdef
479

    
480
int
481
ip_dooptions(m)
482
        struct mbuf *m;
483
{
484
        register struct ip *ip = mtod(m, struct ip *);
485
        register u_char *cp;
486
        register struct ip_timestamp *ipt;
487
        register struct in_ifaddr *ia;
488
/*        int opt, optlen, cnt, off, code, type = ICMP_PARAMPROB, forward = 0; */
489
        int opt, optlen, cnt, off, code, type, forward = 0;
490
        struct in_addr *sin, dst;
491
typedef u_int32_t n_time;
492
        n_time ntime;
493

    
494
        dst = ip->ip_dst;
495
        cp = (u_char *)(ip + 1);
496
        cnt = (ip->ip_hl << 2) - sizeof (struct ip);
497
        for (; cnt > 0; cnt -= optlen, cp += optlen) {
498
                opt = cp[IPOPT_OPTVAL];
499
                if (opt == IPOPT_EOL)
500
                        break;
501
                if (opt == IPOPT_NOP)
502
                        optlen = 1;
503
                else {
504
                        optlen = cp[IPOPT_OLEN];
505
                        if (optlen <= 0 || optlen > cnt) {
506
                                code = &cp[IPOPT_OLEN] - (u_char *)ip;
507
                                goto bad;
508
                        }
509
                }
510
                switch (opt) {
511

    
512
                default:
513
                        break;
514

    
515
                /*
516
                 * Source routing with record.
517
                 * Find interface with current destination address.
518
                 * If none on this machine then drop if strictly routed,
519
                 * or do nothing if loosely routed.
520
                 * Record interface address and bring up next address
521
                 * component.  If strictly routed make sure next
522
                 * address is on directly accessible net.
523
                 */
524
                case IPOPT_LSRR:
525
                case IPOPT_SSRR:
526
                        if ((off = cp[IPOPT_OFFSET]) < IPOPT_MINOFF) {
527
                                code = &cp[IPOPT_OFFSET] - (u_char *)ip;
528
                                goto bad;
529
                        }
530
                        ipaddr.sin_addr = ip->ip_dst;
531
                        ia = (struct in_ifaddr *)
532
                                ifa_ifwithaddr((struct sockaddr *)&ipaddr);
533
                        if (ia == 0) {
534
                                if (opt == IPOPT_SSRR) {
535
                                        type = ICMP_UNREACH;
536
                                        code = ICMP_UNREACH_SRCFAIL;
537
                                        goto bad;
538
                                }
539
                                /*
540
                                 * Loose routing, and not at next destination
541
                                 * yet; nothing to do except forward.
542
                                 */
543
                                break;
544
                        }
545
                        off--;                        / * 0 origin *  /
546
                        if (off > optlen - sizeof(struct in_addr)) {
547
                                /*
548
                                 * End of source route.  Should be for us.
549
                                 */
550
                                save_rte(cp, ip->ip_src);
551
                                break;
552
                        }
553
                        /*
554
                         * locate outgoing interface
555
                         */
556
                        bcopy((caddr_t)(cp + off), (caddr_t)&ipaddr.sin_addr,
557
                            sizeof(ipaddr.sin_addr));
558
                        if (opt == IPOPT_SSRR) {
559
#define        INA        struct in_ifaddr *
560
#define        SA        struct sockaddr *
561
                             if ((ia = (INA)ifa_ifwithdstaddr((SA)&ipaddr)) == 0)
562
                                ia = (INA)ifa_ifwithnet((SA)&ipaddr);
563
                        } else
564
                                ia = ip_rtaddr(ipaddr.sin_addr);
565
                        if (ia == 0) {
566
                                type = ICMP_UNREACH;
567
                                code = ICMP_UNREACH_SRCFAIL;
568
                                goto bad;
569
                        }
570
                        ip->ip_dst = ipaddr.sin_addr;
571
                        bcopy((caddr_t)&(IA_SIN(ia)->sin_addr),
572
                            (caddr_t)(cp + off), sizeof(struct in_addr));
573
                        cp[IPOPT_OFFSET] += sizeof(struct in_addr);
574
                        /*
575
                         * Let ip_intr's mcast routing check handle mcast pkts
576
                         */
577
                        forward = !IN_MULTICAST(ntohl(ip->ip_dst.s_addr));
578
                        break;
579

    
580
                case IPOPT_RR:
581
                        if ((off = cp[IPOPT_OFFSET]) < IPOPT_MINOFF) {
582
                                code = &cp[IPOPT_OFFSET] - (u_char *)ip;
583
                                goto bad;
584
                        }
585
                        /*
586
                         * If no space remains, ignore.
587
                         */
588
                        off--;                         * 0 origin *
589
                        if (off > optlen - sizeof(struct in_addr))
590
                                break;
591
                        bcopy((caddr_t)(&ip->ip_dst), (caddr_t)&ipaddr.sin_addr,
592
                            sizeof(ipaddr.sin_addr));
593
                        /*
594
                         * locate outgoing interface; if we're the destination,
595
                         * use the incoming interface (should be same).
596
                         */
597
                        if ((ia = (INA)ifa_ifwithaddr((SA)&ipaddr)) == 0 &&
598
                            (ia = ip_rtaddr(ipaddr.sin_addr)) == 0) {
599
                                type = ICMP_UNREACH;
600
                                code = ICMP_UNREACH_HOST;
601
                                goto bad;
602
                        }
603
                        bcopy((caddr_t)&(IA_SIN(ia)->sin_addr),
604
                            (caddr_t)(cp + off), sizeof(struct in_addr));
605
                        cp[IPOPT_OFFSET] += sizeof(struct in_addr);
606
                        break;
607

    
608
                case IPOPT_TS:
609
                        code = cp - (u_char *)ip;
610
                        ipt = (struct ip_timestamp *)cp;
611
                        if (ipt->ipt_len < 5)
612
                                goto bad;
613
                        if (ipt->ipt_ptr > ipt->ipt_len - sizeof (int32_t)) {
614
                                if (++ipt->ipt_oflw == 0)
615
                                        goto bad;
616
                                break;
617
                        }
618
                        sin = (struct in_addr *)(cp + ipt->ipt_ptr - 1);
619
                        switch (ipt->ipt_flg) {
620

    
621
                        case IPOPT_TS_TSONLY:
622
                                break;
623

    
624
                        case IPOPT_TS_TSANDADDR:
625
                                if (ipt->ipt_ptr + sizeof(n_time) +
626
                                    sizeof(struct in_addr) > ipt->ipt_len)
627
                                        goto bad;
628
                                ipaddr.sin_addr = dst;
629
                                ia = (INA)ifaof_ i f p foraddr((SA)&ipaddr,
630
                                                            m->m_pkthdr.rcvif);
631
                                if (ia == 0)
632
                                        continue;
633
                                bcopy((caddr_t)&IA_SIN(ia)->sin_addr,
634
                                    (caddr_t)sin, sizeof(struct in_addr));
635
                                ipt->ipt_ptr += sizeof(struct in_addr);
636
                                break;
637

    
638
                        case IPOPT_TS_PRESPEC:
639
                                if (ipt->ipt_ptr + sizeof(n_time) +
640
                                    sizeof(struct in_addr) > ipt->ipt_len)
641
                                        goto bad;
642
                                bcopy((caddr_t)sin, (caddr_t)&ipaddr.sin_addr,
643
                                    sizeof(struct in_addr));
644
                                if (ifa_ifwithaddr((SA)&ipaddr) == 0)
645
                                        continue;
646
                                ipt->ipt_ptr += sizeof(struct in_addr);
647
                                break;
648

    
649
                        default:
650
                                goto bad;
651
                        }
652
                        ntime = iptime();
653
                        bcopy((caddr_t)&ntime, (caddr_t)cp + ipt->ipt_ptr - 1,
654
                            sizeof(n_time));
655
                        ipt->ipt_ptr += sizeof(n_time);
656
                }
657
        }
658
        if (forward) {
659
                ip_forward(m, 1);
660
                return (1);
661
        }
662
                }
663
        }
664
        return (0);
665
bad:
666
        /* ip->ip_len -= ip->ip_hl << 2;   XXX icmp_error adds in hdr length */
667

    
668
/* Not yet */
669
         icmp_error(m, type, code, 0, 0);
670

    
671
        STAT(ipstat.ips_badoptions++);
672
        return (1);
673
}
674

    
675
#endif /* notdef */
676

    
677
/*
678
 * Strip out IP options, at higher
679
 * level protocol in the kernel.
680
 * Second argument is buffer to which options
681
 * will be moved, and return value is their length.
682
 * (XXX) should be deleted; last arg currently ignored.
683
 */
684
void
685
ip_stripoptions(m, mopt)
686
        register struct mbuf *m;
687
        struct mbuf *mopt;
688
{
689
        register int i;
690
        struct ip *ip = mtod(m, struct ip *);
691
        register caddr_t opts;
692
        int olen;
693

    
694
        olen = (ip->ip_hl<<2) - sizeof (struct ip);
695
        opts = (caddr_t)(ip + 1);
696
        i = m->m_len - (sizeof (struct ip) + olen);
697
        memcpy(opts, opts  + olen, (unsigned)i);
698
        m->m_len -= olen;
699

    
700
        ip->ip_hl = sizeof(struct ip) >> 2;
701
}