qemu/slirp/ip_input.c
<<
>>
Prefs
   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. Neither the name of the University nor the names of its contributors
  14 *    may be used to endorse or promote products derived from this software
  15 *    without specific prior written permission.
  16 *
  17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27 * SUCH DAMAGE.
  28 *
  29 *      @(#)ip_input.c  8.2 (Berkeley) 1/4/94
  30 * ip_input.c,v 1.11 1994/11/16 10:17:08 jkh Exp
  31 */
  32
  33/*
  34 * Changes and additions relating to SLiRP are
  35 * Copyright (c) 1995 Danny Gasparovski.
  36 *
  37 * Please read the file COPYRIGHT for the
  38 * terms and conditions of the copyright.
  39 */
  40
  41#include "qemu/osdep.h"
  42#include "slirp.h"
  43#include "ip_icmp.h"
  44
  45static struct ip *ip_reass(Slirp *slirp, struct ip *ip, struct ipq *fp);
  46static void ip_freef(Slirp *slirp, struct ipq *fp);
  47static void ip_enq(register struct ipasfrag *p,
  48                   register struct ipasfrag *prev);
  49static void ip_deq(register struct ipasfrag *p);
  50
  51/*
  52 * IP initialization: fill in IP protocol switch table.
  53 * All protocols not implemented in kernel go to raw IP protocol handler.
  54 */
  55void
  56ip_init(Slirp *slirp)
  57{
  58    slirp->ipq.ip_link.next = slirp->ipq.ip_link.prev = &slirp->ipq.ip_link;
  59    udp_init(slirp);
  60    tcp_init(slirp);
  61    icmp_init(slirp);
  62}
  63
  64void ip_cleanup(Slirp *slirp)
  65{
  66    udp_cleanup(slirp);
  67    tcp_cleanup(slirp);
  68    icmp_cleanup(slirp);
  69}
  70
  71/*
  72 * Ip input routine.  Checksum and byte swap header.  If fragmented
  73 * try to reassemble.  Process options.  Pass to next level.
  74 */
  75void
  76ip_input(struct mbuf *m)
  77{
  78        Slirp *slirp = m->slirp;
  79        register struct ip *ip;
  80        int hlen;
  81
  82        if (!slirp->in_enabled) {
  83                goto bad;
  84        }
  85
  86        DEBUG_CALL("ip_input");
  87        DEBUG_ARG("m = %p", m);
  88        DEBUG_ARG("m_len = %d", m->m_len);
  89
  90        if (m->m_len < sizeof (struct ip)) {
  91                goto bad;
  92        }
  93
  94        ip = mtod(m, struct ip *);
  95
  96        if (ip->ip_v != IPVERSION) {
  97                goto bad;
  98        }
  99
 100        hlen = ip->ip_hl << 2;
 101        if (hlen<sizeof(struct ip ) || hlen>m->m_len) {/* min header length */
 102          goto bad;                                  /* or packet too short */
 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          goto bad;
 111        }
 112
 113        /*
 114         * Convert fields to host representation.
 115         */
 116        NTOHS(ip->ip_len);
 117        if (ip->ip_len < hlen) {
 118                goto bad;
 119        }
 120        NTOHS(ip->ip_id);
 121        NTOHS(ip->ip_off);
 122
 123        /*
 124         * Check that the amount of data in the buffers
 125         * is as at least much as the IP header would have us expect.
 126         * Trim mbufs if longer than we expect.
 127         * Drop packet if shorter than we expect.
 128         */
 129        if (m->m_len < ip->ip_len) {
 130                goto bad;
 131        }
 132
 133        /* Should drop packet if mbuf too long? hmmm... */
 134        if (m->m_len > ip->ip_len)
 135           m_adj(m, ip->ip_len - m->m_len);
 136
 137        /* check ip_ttl for a correct ICMP reply */
 138        if (ip->ip_ttl == 0) {
 139            icmp_send_error(m, ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS, 0, "ttl");
 140            goto bad;
 141        }
 142
 143        /*
 144         * If offset or IP_MF are set, must reassemble.
 145         * Otherwise, nothing need be done.
 146         * (We could look in the reassembly queue to see
 147         * if the packet was previously fragmented,
 148         * but it's not worth the time; just let them time out.)
 149         *
 150         * XXX This should fail, don't fragment yet
 151         */
 152        if (ip->ip_off &~ IP_DF) {
 153          register struct ipq *fp;
 154      struct qlink *l;
 155                /*
 156                 * Look for queue of fragments
 157                 * of this datagram.
 158                 */
 159                for (l = slirp->ipq.ip_link.next; l != &slirp->ipq.ip_link;
 160                     l = l->next) {
 161            fp = container_of(l, struct ipq, ip_link);
 162            if (ip->ip_id == fp->ipq_id &&
 163                    ip->ip_src.s_addr == fp->ipq_src.s_addr &&
 164                    ip->ip_dst.s_addr == fp->ipq_dst.s_addr &&
 165                    ip->ip_p == fp->ipq_p)
 166                    goto found;
 167        }
 168        fp = NULL;
 169        found:
 170
 171                /*
 172                 * Adjust ip_len to not reflect header,
 173                 * set ip_mff if more fragments are expected,
 174                 * convert offset of this to bytes.
 175                 */
 176                ip->ip_len -= hlen;
 177                if (ip->ip_off & IP_MF)
 178                  ip->ip_tos |= 1;
 179                else
 180                  ip->ip_tos &= ~1;
 181
 182                ip->ip_off <<= 3;
 183
 184                /*
 185                 * If datagram marked as having more fragments
 186                 * or if this is not the first fragment,
 187                 * attempt reassembly; if it succeeds, proceed.
 188                 */
 189                if (ip->ip_tos & 1 || ip->ip_off) {
 190                        ip = ip_reass(slirp, ip, fp);
 191                        if (ip == NULL)
 192                                return;
 193                        m = dtom(slirp, ip);
 194                } else
 195                        if (fp)
 196                           ip_freef(slirp, fp);
 197
 198        } else
 199                ip->ip_len -= hlen;
 200
 201        /*
 202         * Switch out to protocol's input routine.
 203         */
 204        switch (ip->ip_p) {
 205         case IPPROTO_TCP:
 206                tcp_input(m, hlen, (struct socket *)NULL, AF_INET);
 207                break;
 208         case IPPROTO_UDP:
 209                udp_input(m, hlen);
 210                break;
 211         case IPPROTO_ICMP:
 212                icmp_input(m, hlen);
 213                break;
 214         default:
 215                m_free(m);
 216        }
 217        return;
 218bad:
 219        m_free(m);
 220}
 221
 222#define iptofrag(P) ((struct ipasfrag *)(((char*)(P)) - sizeof(struct qlink)))
 223#define fragtoip(P) ((struct ip*)(((char*)(P)) + sizeof(struct qlink)))
 224/*
 225 * Take incoming datagram fragment and try to
 226 * reassemble it into whole datagram.  If a chain for
 227 * reassembly of this datagram already exists, then it
 228 * is given as fp; otherwise have to make a chain.
 229 */
 230static struct ip *
 231ip_reass(Slirp *slirp, struct ip *ip, struct ipq *fp)
 232{
 233        register struct mbuf *m = dtom(slirp, ip);
 234        register struct ipasfrag *q;
 235        int hlen = ip->ip_hl << 2;
 236        int i, next;
 237
 238        DEBUG_CALL("ip_reass");
 239        DEBUG_ARG("ip = %p", ip);
 240        DEBUG_ARG("fp = %p", fp);
 241        DEBUG_ARG("m = %p", m);
 242
 243        /*
 244         * Presence of header sizes in mbufs
 245         * would confuse code below.
 246         * Fragment m_data is concatenated.
 247         */
 248        m->m_data += hlen;
 249        m->m_len -= hlen;
 250
 251        /*
 252         * If first fragment to arrive, create a reassembly queue.
 253         */
 254        if (fp == NULL) {
 255          struct mbuf *t = m_get(slirp);
 256
 257          if (t == NULL) {
 258              goto dropfrag;
 259          }
 260          fp = mtod(t, struct ipq *);
 261          insque(&fp->ip_link, &slirp->ipq.ip_link);
 262          fp->ipq_ttl = IPFRAGTTL;
 263          fp->ipq_p = ip->ip_p;
 264          fp->ipq_id = ip->ip_id;
 265          fp->frag_link.next = fp->frag_link.prev = &fp->frag_link;
 266          fp->ipq_src = ip->ip_src;
 267          fp->ipq_dst = ip->ip_dst;
 268          q = (struct ipasfrag *)fp;
 269          goto insert;
 270        }
 271
 272        /*
 273         * Find a segment which begins after this one does.
 274         */
 275        for (q = fp->frag_link.next; q != (struct ipasfrag *)&fp->frag_link;
 276            q = q->ipf_next)
 277                if (q->ipf_off > ip->ip_off)
 278                        break;
 279
 280        /*
 281         * If there is a preceding segment, it may provide some of
 282         * our data already.  If so, drop the data from the incoming
 283         * segment.  If it provides all of our data, drop us.
 284         */
 285        if (q->ipf_prev != &fp->frag_link) {
 286        struct ipasfrag *pq = q->ipf_prev;
 287                i = pq->ipf_off + pq->ipf_len - ip->ip_off;
 288                if (i > 0) {
 289                        if (i >= ip->ip_len)
 290                                goto dropfrag;
 291                        m_adj(dtom(slirp, ip), i);
 292                        ip->ip_off += i;
 293                        ip->ip_len -= i;
 294                }
 295        }
 296
 297        /*
 298         * While we overlap succeeding segments trim them or,
 299         * if they are completely covered, dequeue them.
 300         */
 301        while (q != (struct ipasfrag*)&fp->frag_link &&
 302            ip->ip_off + ip->ip_len > q->ipf_off) {
 303                struct ipasfrag *prev;
 304                i = (ip->ip_off + ip->ip_len) - q->ipf_off;
 305                if (i < q->ipf_len) {
 306                        q->ipf_len -= i;
 307                        q->ipf_off += i;
 308                        m_adj(dtom(slirp, q), i);
 309                        break;
 310                }
 311                prev = q;
 312                q = q->ipf_next;
 313                ip_deq(prev);
 314                m_free(dtom(slirp, prev));
 315        }
 316
 317insert:
 318        /*
 319         * Stick new segment in its place;
 320         * check for complete reassembly.
 321         */
 322        ip_enq(iptofrag(ip), q->ipf_prev);
 323        next = 0;
 324        for (q = fp->frag_link.next; q != (struct ipasfrag*)&fp->frag_link;
 325            q = q->ipf_next) {
 326                if (q->ipf_off != next)
 327                        return NULL;
 328                next += q->ipf_len;
 329        }
 330        if (((struct ipasfrag *)(q->ipf_prev))->ipf_tos & 1)
 331                return NULL;
 332
 333        /*
 334         * Reassembly is complete; concatenate fragments.
 335         */
 336    q = fp->frag_link.next;
 337        m = dtom(slirp, q);
 338
 339        int was_ext = m->m_flags & M_EXT;
 340
 341        q = (struct ipasfrag *) q->ipf_next;
 342        while (q != (struct ipasfrag*)&fp->frag_link) {
 343          struct mbuf *t = dtom(slirp, q);
 344          q = (struct ipasfrag *) q->ipf_next;
 345          m_cat(m, t);
 346        }
 347
 348        /*
 349         * Create header for new ip packet by
 350         * modifying header of first packet;
 351         * dequeue and discard fragment reassembly header.
 352         * Make header visible.
 353         */
 354        q = fp->frag_link.next;
 355
 356        /*
 357         * If the fragments concatenated to an mbuf that's bigger than the total
 358         * size of the fragment and the mbuf was not already using an m_ext buffer,
 359         * then an m_ext buffer was alloced. But fp->ipq_next points to the old
 360         * buffer (in the mbuf), so we must point ip into the new buffer.
 361         */
 362        if (!was_ext && m->m_flags & M_EXT) {
 363          int delta = (char *)q - m->m_dat;
 364          q = (struct ipasfrag *)(m->m_ext + delta);
 365        }
 366
 367    ip = fragtoip(q);
 368        ip->ip_len = next;
 369        ip->ip_tos &= ~1;
 370        ip->ip_src = fp->ipq_src;
 371        ip->ip_dst = fp->ipq_dst;
 372        remque(&fp->ip_link);
 373        (void) m_free(dtom(slirp, fp));
 374        m->m_len += (ip->ip_hl << 2);
 375        m->m_data -= (ip->ip_hl << 2);
 376
 377        return ip;
 378
 379dropfrag:
 380        m_free(m);
 381        return NULL;
 382}
 383
 384/*
 385 * Free a fragment reassembly header and all
 386 * associated datagrams.
 387 */
 388static void
 389ip_freef(Slirp *slirp, struct ipq *fp)
 390{
 391        register struct ipasfrag *q, *p;
 392
 393        for (q = fp->frag_link.next; q != (struct ipasfrag*)&fp->frag_link; q = p) {
 394                p = q->ipf_next;
 395                ip_deq(q);
 396                m_free(dtom(slirp, q));
 397        }
 398        remque(&fp->ip_link);
 399        (void) m_free(dtom(slirp, fp));
 400}
 401
 402/*
 403 * Put an ip fragment on a reassembly chain.
 404 * Like insque, but pointers in middle of structure.
 405 */
 406static void
 407ip_enq(register struct ipasfrag *p, register struct ipasfrag *prev)
 408{
 409        DEBUG_CALL("ip_enq");
 410        DEBUG_ARG("prev = %p", prev);
 411        p->ipf_prev =  prev;
 412        p->ipf_next = prev->ipf_next;
 413        ((struct ipasfrag *)(prev->ipf_next))->ipf_prev = p;
 414        prev->ipf_next = p;
 415}
 416
 417/*
 418 * To ip_enq as remque is to insque.
 419 */
 420static void
 421ip_deq(register struct ipasfrag *p)
 422{
 423        ((struct ipasfrag *)(p->ipf_prev))->ipf_next = p->ipf_next;
 424        ((struct ipasfrag *)(p->ipf_next))->ipf_prev = p->ipf_prev;
 425}
 426
 427/*
 428 * IP timer processing;
 429 * if a timer expires on a reassembly
 430 * queue, discard it.
 431 */
 432void
 433ip_slowtimo(Slirp *slirp)
 434{
 435    struct qlink *l;
 436
 437        DEBUG_CALL("ip_slowtimo");
 438
 439    l = slirp->ipq.ip_link.next;
 440
 441        if (l == NULL)
 442           return;
 443
 444    while (l != &slirp->ipq.ip_link) {
 445        struct ipq *fp = container_of(l, struct ipq, ip_link);
 446        l = l->next;
 447                if (--fp->ipq_ttl == 0) {
 448                        ip_freef(slirp, fp);
 449                }
 450    }
 451}
 452
 453/*
 454 * Do option processing on a datagram,
 455 * possibly discarding it if bad options are encountered,
 456 * or forwarding it if source-routed.
 457 * Returns 1 if packet has been forwarded/freed,
 458 * 0 if the packet should be processed further.
 459 */
 460
 461#ifdef notdef
 462
 463int
 464ip_dooptions(m)
 465        struct mbuf *m;
 466{
 467        register struct ip *ip = mtod(m, struct ip *);
 468        register u_char *cp;
 469        register struct ip_timestamp *ipt;
 470        register struct in_ifaddr *ia;
 471        int opt, optlen, cnt, off, code, type, forward = 0;
 472        struct in_addr *sin, dst;
 473typedef uint32_t n_time;
 474        n_time ntime;
 475
 476        dst = ip->ip_dst;
 477        cp = (u_char *)(ip + 1);
 478        cnt = (ip->ip_hl << 2) - sizeof (struct ip);
 479        for (; cnt > 0; cnt -= optlen, cp += optlen) {
 480                opt = cp[IPOPT_OPTVAL];
 481                if (opt == IPOPT_EOL)
 482                        break;
 483                if (opt == IPOPT_NOP)
 484                        optlen = 1;
 485                else {
 486                        optlen = cp[IPOPT_OLEN];
 487                        if (optlen <= 0 || optlen > cnt) {
 488                                code = &cp[IPOPT_OLEN] - (u_char *)ip;
 489                                goto bad;
 490                        }
 491                }
 492                switch (opt) {
 493
 494                default:
 495                        break;
 496
 497                /*
 498                 * Source routing with record.
 499                 * Find interface with current destination address.
 500                 * If none on this machine then drop if strictly routed,
 501                 * or do nothing if loosely routed.
 502                 * Record interface address and bring up next address
 503                 * component.  If strictly routed make sure next
 504                 * address is on directly accessible net.
 505                 */
 506                case IPOPT_LSRR:
 507                case IPOPT_SSRR:
 508                        if ((off = cp[IPOPT_OFFSET]) < IPOPT_MINOFF) {
 509                                code = &cp[IPOPT_OFFSET] - (u_char *)ip;
 510                                goto bad;
 511                        }
 512                        ipaddr.sin_addr = ip->ip_dst;
 513                        ia = (struct in_ifaddr *)
 514                                ifa_ifwithaddr((struct sockaddr *)&ipaddr);
 515                        if (ia == 0) {
 516                                if (opt == IPOPT_SSRR) {
 517                                        type = ICMP_UNREACH;
 518                                        code = ICMP_UNREACH_SRCFAIL;
 519                                        goto bad;
 520                                }
 521                                /*
 522                                 * Loose routing, and not at next destination
 523                                 * yet; nothing to do except forward.
 524                                 */
 525                                break;
 526                        }
 527                        off--; /* 0 origin */
 528                        if (off > optlen - sizeof(struct in_addr)) {
 529                                /*
 530                                 * End of source route.  Should be for us.
 531                                 */
 532                                save_rte(cp, ip->ip_src);
 533                                break;
 534                        }
 535                        /*
 536                         * locate outgoing interface
 537                         */
 538                        bcopy((caddr_t)(cp + off), (caddr_t)&ipaddr.sin_addr,
 539                            sizeof(ipaddr.sin_addr));
 540                        if (opt == IPOPT_SSRR) {
 541#define INA     struct in_ifaddr *
 542#define SA      struct sockaddr *
 543                            if ((ia = (INA)ifa_ifwithdstaddr((SA)&ipaddr)) == 0)
 544                                ia = (INA)ifa_ifwithnet((SA)&ipaddr);
 545                        } else
 546                                ia = ip_rtaddr(ipaddr.sin_addr);
 547                        if (ia == 0) {
 548                                type = ICMP_UNREACH;
 549                                code = ICMP_UNREACH_SRCFAIL;
 550                                goto bad;
 551                        }
 552                        ip->ip_dst = ipaddr.sin_addr;
 553                        bcopy((caddr_t)&(IA_SIN(ia)->sin_addr),
 554                            (caddr_t)(cp + off), sizeof(struct in_addr));
 555                        cp[IPOPT_OFFSET] += sizeof(struct in_addr);
 556                        /*
 557                         * Let ip_intr's mcast routing check handle mcast pkts
 558                         */
 559                        forward = !IN_MULTICAST(ntohl(ip->ip_dst.s_addr));
 560                        break;
 561
 562                case IPOPT_RR:
 563                        if ((off = cp[IPOPT_OFFSET]) < IPOPT_MINOFF) {
 564                                code = &cp[IPOPT_OFFSET] - (u_char *)ip;
 565                                goto bad;
 566                        }
 567                        /*
 568                         * If no space remains, ignore.
 569                         */
 570                        off--; /* 0 origin */
 571                        if (off > optlen - sizeof(struct in_addr))
 572                                break;
 573                        bcopy((caddr_t)(&ip->ip_dst), (caddr_t)&ipaddr.sin_addr,
 574                            sizeof(ipaddr.sin_addr));
 575                        /*
 576                         * locate outgoing interface; if we're the destination,
 577                         * use the incoming interface (should be same).
 578                         */
 579                        if ((ia = (INA)ifa_ifwithaddr((SA)&ipaddr)) == 0 &&
 580                            (ia = ip_rtaddr(ipaddr.sin_addr)) == 0) {
 581                                type = ICMP_UNREACH;
 582                                code = ICMP_UNREACH_HOST;
 583                                goto bad;
 584                        }
 585                        bcopy((caddr_t)&(IA_SIN(ia)->sin_addr),
 586                            (caddr_t)(cp + off), sizeof(struct in_addr));
 587                        cp[IPOPT_OFFSET] += sizeof(struct in_addr);
 588                        break;
 589
 590                case IPOPT_TS:
 591                        code = cp - (u_char *)ip;
 592                        ipt = (struct ip_timestamp *)cp;
 593                        if (ipt->ipt_len < 5)
 594                                goto bad;
 595                        if (ipt->ipt_ptr > ipt->ipt_len - sizeof (int32_t)) {
 596                                if (++ipt->ipt_oflw == 0)
 597                                        goto bad;
 598                                break;
 599                        }
 600                        sin = (struct in_addr *)(cp + ipt->ipt_ptr - 1);
 601                        switch (ipt->ipt_flg) {
 602
 603                        case IPOPT_TS_TSONLY:
 604                                break;
 605
 606                        case IPOPT_TS_TSANDADDR:
 607                                if (ipt->ipt_ptr + sizeof(n_time) +
 608                                    sizeof(struct in_addr) > ipt->ipt_len)
 609                                        goto bad;
 610                                ipaddr.sin_addr = dst;
 611                                ia = (INA)ifaof_ i f p foraddr((SA)&ipaddr,
 612                                                            m->m_pkthdr.rcvif);
 613                                if (ia == 0)
 614                                        continue;
 615                                bcopy((caddr_t)&IA_SIN(ia)->sin_addr,
 616                                    (caddr_t)sin, sizeof(struct in_addr));
 617                                ipt->ipt_ptr += sizeof(struct in_addr);
 618                                break;
 619
 620                        case IPOPT_TS_PRESPEC:
 621                                if (ipt->ipt_ptr + sizeof(n_time) +
 622                                    sizeof(struct in_addr) > ipt->ipt_len)
 623                                        goto bad;
 624                                bcopy((caddr_t)sin, (caddr_t)&ipaddr.sin_addr,
 625                                    sizeof(struct in_addr));
 626                                if (ifa_ifwithaddr((SA)&ipaddr) == 0)
 627                                        continue;
 628                                ipt->ipt_ptr += sizeof(struct in_addr);
 629                                break;
 630
 631                        default:
 632                                goto bad;
 633                        }
 634                        ntime = iptime();
 635                        bcopy((caddr_t)&ntime, (caddr_t)cp + ipt->ipt_ptr - 1,
 636                            sizeof(n_time));
 637                        ipt->ipt_ptr += sizeof(n_time);
 638                }
 639        }
 640        if (forward) {
 641                ip_forward(m, 1);
 642                return (1);
 643        }
 644        return (0);
 645bad:
 646        icmp_send_error(m, type, code, 0, 0);
 647
 648        return (1);
 649}
 650
 651#endif /* notdef */
 652
 653/*
 654 * Strip out IP options, at higher
 655 * level protocol in the kernel.
 656 * Second argument is buffer to which options
 657 * will be moved, and return value is their length.
 658 * (XXX) should be deleted; last arg currently ignored.
 659 */
 660void
 661ip_stripoptions(register struct mbuf *m, struct mbuf *mopt)
 662{
 663        register int i;
 664        struct ip *ip = mtod(m, struct ip *);
 665        register caddr_t opts;
 666        int olen;
 667
 668        olen = (ip->ip_hl<<2) - sizeof (struct ip);
 669        opts = (caddr_t)(ip + 1);
 670        i = m->m_len - (sizeof (struct ip) + olen);
 671        memcpy(opts, opts  + olen, (unsigned)i);
 672        m->m_len -= olen;
 673
 674        ip->ip_hl = sizeof(struct ip) >> 2;
 675}
 676