source: rtems/cpukit/libnetworking/netinet/ip_output.c @ b25b88e7

4.104.115
Last change on this file since b25b88e7 was b25b88e7, checked in by Ralf Corsepius <ralf.corsepius@…>, on 03/28/10 at 05:50:29

Add HAVE_CONFIG_H support to let files receive configure defines.

  • Property mode set to 100644
File size: 31.7 KB
RevLine 
[39e6e65a]1/*
2 * Copyright (c) 1982, 1986, 1988, 1990, 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 * 4. 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_output.c 8.3 (Berkeley) 1/21/94
[0c67b436]30 * $FreeBSD: src/sys/netinet/ip_output.c,v 1.271 2007/03/23 09:43:36 bms Exp $
31 */
32
33/*
[39e6e65a]34 *      $Id$
35 */
36
[b25b88e7]37#ifdef HAVE_CONFIG_H
38#include "config.h"
39#endif
40
[39e6e65a]41#define _IP_VHL
42
43#include <sys/param.h>
[c301570]44#include <rtems/bsd/sys/queue.h>
[39e6e65a]45#include <sys/systm.h>
46#include <sys/malloc.h>
47#include <sys/mbuf.h>
[b3f8c9e1]48#include <errno.h>
[39e6e65a]49#include <sys/protosw.h>
50#include <sys/socket.h>
51#include <sys/socketvar.h>
52
53#include <net/if.h>
54#include <net/route.h>
55
56#include <netinet/in.h>
57#include <netinet/in_systm.h>
58#include <netinet/ip.h>
59#include <netinet/in_pcb.h>
60#include <netinet/in_var.h>
61#include <netinet/ip_var.h>
62
63#include <machine/in_cksum.h>
64
65#if !defined(COMPAT_IPFW) || COMPAT_IPFW == 1
66#undef COMPAT_IPFW
67#define COMPAT_IPFW 1
68#else
69#undef COMPAT_IPFW
70#endif
71
72u_short ip_id;
73
[e5d6315e]74static struct mbuf *ip_insertoptions(struct mbuf *, struct mbuf *, int *);
[39e6e65a]75static void     ip_mloopback
[e5d6315e]76        (struct ifnet *, struct mbuf *, struct sockaddr_in *, int);
[39e6e65a]77static int      ip_getmoptions
[e5d6315e]78        (int, struct ip_moptions *, struct mbuf **);
79static int      ip_optcopy(struct ip *, struct ip *);
80static int      ip_pcbopts(struct mbuf **, struct mbuf *);
[39e6e65a]81static int      ip_setmoptions
[e5d6315e]82        (int, struct ip_moptions **, struct mbuf *);
[39e6e65a]83
84extern  struct protosw inetsw[];
85
86/*
87 * IP output.  The packet in mbuf chain m contains a skeletal IP
88 * header (with len, off, ttl, proto, tos, src, dst).
89 * The mbuf chain containing the packet will be freed.
90 * The mbuf opt, if present, will not be freed.
91 */
92int
[dd967330]93ip_output(struct mbuf *m0, struct mbuf *opt, struct route *ro, int flags,
94        struct ip_moptions *imo)
[39e6e65a]95{
96        struct ip *ip, *mhip;
97        struct ifnet *ifp;
98        struct mbuf *m = m0;
99        int hlen = sizeof (struct ip);
[3274c876]100        int len = 0, off, error = 0;
[39e6e65a]101        struct sockaddr_in *dst;
102        struct in_ifaddr *ia;
103        int isbroadcast;
104
105#ifdef  DIAGNOSTIC
106        if ((m->m_flags & M_PKTHDR) == 0)
107                panic("ip_output no HDR");
108        if (!ro)
109                panic("ip_output no route, proto = %d",
110                      mtod(m, struct ip *)->ip_p);
111#endif
112        if (opt) {
113                m = ip_insertoptions(m, opt, &len);
114                hlen = len;
115        }
116        ip = mtod(m, struct ip *);
117        /*
118         * Fill in IP header.
119         */
120        if ((flags & (IP_FORWARDING|IP_RAWOUTPUT)) == 0) {
[f94e799e]121#ifdef _IP_VHL
[39e6e65a]122                ip->ip_vhl = IP_MAKE_VHL(IPVERSION, hlen >> 2);
[f94e799e]123#else
124                ip->ip_v = IPVERSION;
125                ip->ip_hl = hlen >> 2;
126#endif
[39e6e65a]127                ip->ip_off &= IP_DF;
128                ip->ip_id = htons(ip_id++);
129                ipstat.ips_localout++;
130        } else {
[491f63a]131#ifdef _IP_VHL
[39e6e65a]132                hlen = IP_VHL_HL(ip->ip_vhl) << 2;
[491f63a]133#else
134                hlen = ip->ip_hl << 2;
135#endif
[39e6e65a]136        }
137
138        dst = (struct sockaddr_in *)&ro->ro_dst;
139        /*
140         * If there is a cached route,
141         * check that it is to the same destination
142         * and is still up.  If not, free it and try again.
143         */
144        if (ro->ro_rt && ((ro->ro_rt->rt_flags & RTF_UP) == 0 ||
145           dst->sin_addr.s_addr != ip->ip_dst.s_addr)) {
146                RTFREE(ro->ro_rt);
147                ro->ro_rt = (struct rtentry *)0;
148        }
[0c67b436]149        if (ro->ro_rt == NULL) {
[39e6e65a]150                dst->sin_family = AF_INET;
151                dst->sin_len = sizeof(*dst);
152                dst->sin_addr = ip->ip_dst;
153        }
154        /*
155         * If routing to interface only,
156         * short circuit routing lookup.
157         */
158#define ifatoia(ifa)    ((struct in_ifaddr *)(ifa))
159#define sintosa(sin)    ((struct sockaddr *)(sin))
160        if (flags & IP_ROUTETOIF) {
161                if ((ia = ifatoia(ifa_ifwithdstaddr(sintosa(dst)))) == 0 &&
162                    (ia = ifatoia(ifa_ifwithnet(sintosa(dst)))) == 0) {
163                        ipstat.ips_noroute++;
164                        error = ENETUNREACH;
165                        goto bad;
166                }
167                ifp = ia->ia_ifp;
168                ip->ip_ttl = 1;
169                isbroadcast = in_broadcast(dst->sin_addr, ifp);
170        } else {
171                /*
172                 * If this is the case, we probably don't want to allocate
173                 * a protocol-cloned route since we didn't get one from the
174                 * ULP.  This lets TCP do its thing, while not burdening
175                 * forwarding or ICMP with the overhead of cloning a route.
176                 * Of course, we still want to do any cloning requested by
177                 * the link layer, as this is probably required in all cases
178                 * for correct operation (as it is for ARP).
179                 */
180                if (ro->ro_rt == 0)
181                        rtalloc_ign(ro, RTF_PRCLONING);
182                if (ro->ro_rt == 0) {
183                        ipstat.ips_noroute++;
184                        error = EHOSTUNREACH;
185                        goto bad;
186                }
187                ia = ifatoia(ro->ro_rt->rt_ifa);
188                ifp = ro->ro_rt->rt_ifp;
189                ro->ro_rt->rt_use++;
190                if (ro->ro_rt->rt_flags & RTF_GATEWAY)
191                        dst = (struct sockaddr_in *)ro->ro_rt->rt_gateway;
192                if (ro->ro_rt->rt_flags & RTF_HOST)
193                        isbroadcast = (ro->ro_rt->rt_flags & RTF_BROADCAST);
194                else
195                        isbroadcast = in_broadcast(dst->sin_addr, ifp);
196        }
197        if (IN_MULTICAST(ntohl(ip->ip_dst.s_addr))) {
198                struct in_multi *inm;
199
200                m->m_flags |= M_MCAST;
201                /*
202                 * IP destination address is multicast.  Make sure "dst"
203                 * still points to the address in "ro".  (It may have been
204                 * changed to point to a gateway address, above.)
205                 */
206                dst = (struct sockaddr_in *)&ro->ro_dst;
207                /*
208                 * See if the caller provided any multicast options
209                 */
210                if (imo != NULL) {
211                        ip->ip_ttl = imo->imo_multicast_ttl;
212                        if (imo->imo_multicast_ifp != NULL)
213                                ifp = imo->imo_multicast_ifp;
214                        if (imo->imo_multicast_vif != -1)
215                                ip->ip_src.s_addr =
216                                    ip_mcast_src(imo->imo_multicast_vif);
217                } else
218                        ip->ip_ttl = IP_DEFAULT_MULTICAST_TTL;
219                /*
220                 * Confirm that the outgoing interface supports multicast.
221                 */
222                if ((imo == NULL) || (imo->imo_multicast_vif == -1)) {
223                        if ((ifp->if_flags & IFF_MULTICAST) == 0) {
224                                ipstat.ips_noroute++;
225                                error = ENETUNREACH;
226                                goto bad;
227                        }
228                }
229                /*
230                 * If source address not specified yet, use address
231                 * of outgoing interface.
232                 */
233                if (ip->ip_src.s_addr == INADDR_ANY) {
234                        register struct in_ifaddr *ia;
235
236                        for (ia = in_ifaddr; ia; ia = ia->ia_next)
237                                if (ia->ia_ifp == ifp) {
238                                        ip->ip_src = IA_SIN(ia)->sin_addr;
239                                        break;
240                                }
241                }
242
243                IN_LOOKUP_MULTI(ip->ip_dst, ifp, inm);
244                if (inm != NULL &&
245                   (imo == NULL || imo->imo_multicast_loop)) {
246                        /*
247                         * If we belong to the destination multicast group
248                         * on the outgoing interface, and the caller did not
249                         * forbid loopback, loop back a copy.
250                         */
251                        ip_mloopback(ifp, m, dst, hlen);
252                }
253                else {
254                        /*
255                         * If we are acting as a multicast router, perform
256                         * multicast forwarding as if the packet had just
257                         * arrived on the interface to which we are about
258                         * to send.  The multicast forwarding function
259                         * recursively calls this function, using the
260                         * IP_FORWARDING flag to prevent infinite recursion.
261                         *
262                         * Multicasts that are looped back by ip_mloopback(),
263                         * above, will be forwarded by the ip_input() routine,
264                         * if necessary.
265                         */
266                        if (ip_mrouter && (flags & IP_FORWARDING) == 0) {
267                                /*
268                                 * Check if rsvp daemon is running. If not, don't
269                                 * set ip_moptions. This ensures that the packet
270                                 * is multicast and not just sent down one link
271                                 * as prescribed by rsvpd.
272                                 */
273                                if (!rsvp_on)
274                                  imo = NULL;
275                                if (ip_mforward(ip, ifp, m, imo) != 0) {
276                                        m_freem(m);
277                                        goto done;
278                                }
279                        }
280                }
281
282                /*
283                 * Multicasts with a time-to-live of zero may be looped-
284                 * back, above, but must not be transmitted on a network.
285                 * Also, multicasts addressed to the loopback interface
286                 * are not sent -- the above call to ip_mloopback() will
287                 * loop back a copy if this host actually belongs to the
288                 * destination group on the loopback interface.
289                 */
290                if (ip->ip_ttl == 0 || ifp->if_flags & IFF_LOOPBACK) {
291                        m_freem(m);
292                        goto done;
293                }
294
295                goto sendit;
296        }
297#ifndef notdef
298        /*
299         * If source address not specified yet, use address
300         * of outgoing interface.
301         */
302        if (ip->ip_src.s_addr == INADDR_ANY)
303                ip->ip_src = IA_SIN(ia)->sin_addr;
304#endif
305        /*
306         * Verify that we have any chance at all of being able to queue
307         *      the packet or packet fragments
308         */
309        if ((ifp->if_snd.ifq_len + ip->ip_len / ifp->if_mtu + 1) >=
310                ifp->if_snd.ifq_maxlen) {
311                        error = ENOBUFS;
312                        goto bad;
313        }
314
315        /*
316         * Look for broadcast address and
[0c67b436]317         * verify user is allowed to send
[39e6e65a]318         * such a packet.
319         */
320        if (isbroadcast) {
321                if ((ifp->if_flags & IFF_BROADCAST) == 0) {
322                        error = EADDRNOTAVAIL;
323                        goto bad;
324                }
325                if ((flags & IP_ALLOWBROADCAST) == 0) {
326                        error = EACCES;
327                        goto bad;
328                }
329                /* don't allow broadcast messages to be fragmented */
[f94e799e]330                if (ip->ip_len > ifp->if_mtu) {
[39e6e65a]331                        error = EMSGSIZE;
332                        goto bad;
333                }
334                m->m_flags |= M_BCAST;
335        } else {
336                m->m_flags &= ~M_BCAST;
337        }
338
339sendit:
340        /*
341         * IpHack's section.
342         * - Xlate: translate packet's addr/port (NAT).
343         * - Firewall: deny/allow/etc.
344         * - Wrap: fake packet's addr/port <unimpl.>
345         * - Encapsulate: put it in another IP and send out. <unimp.>
346         */
347
348#ifdef COMPAT_IPFW
349        if (ip_nat_ptr && !(*ip_nat_ptr)(&ip, &m, ifp, IP_NAT_OUT)) {
350                error = EACCES;
351                goto done;
352        }
353
354        /*
355         * Check with the firewall...
356         */
357        if (ip_fw_chk_ptr) {
358#ifdef IPDIVERT
359                ip_divert_port = (*ip_fw_chk_ptr)(&ip,
360                    hlen, ifp, ip_divert_ignore, &m);
361                ip_divert_ignore = 0;
362                if (ip_divert_port) {           /* Divert packet */
363                        (*inetsw[ip_protox[IPPROTO_DIVERT]].pr_input)(m, 0);
364                        goto done;
365                }
366#else
367                /* If ipfw says divert, we have to just drop packet */
368                if ((*ip_fw_chk_ptr)(&ip, hlen, ifp, 0, &m)) {
369                        m_freem(m);
370                        goto done;
371                }
372#endif
373                if (!m) {
374                        error = EACCES;
375                        goto done;
376                }
377        }
378#endif /* COMPAT_IPFW */
379
380        /*
[0c67b436]381         * If small enough for interface, or the interface will take
382         * care of the fragmentation for us, we can just send directly.
[39e6e65a]383         */
384        if ((u_short)ip->ip_len <= ifp->if_mtu) {
[0c67b436]385                ip->ip_len = htons(ip->ip_len);
386                ip->ip_off = htons(ip->ip_off);
[39e6e65a]387                ip->ip_sum = 0;
[491f63a]388#ifdef _IP_VHL
[39e6e65a]389                if (ip->ip_vhl == IP_VHL_BORING) {
[491f63a]390#else
391                if ((ip->ip_hl == 5) && (ip->ip_v = IPVERSION)) {
392#endif
[39e6e65a]393                        ip->ip_sum = in_cksum_hdr(ip);
394                } else {
395                        ip->ip_sum = in_cksum(m, hlen);
396                }
397                error = (*ifp->if_output)(ifp, m,
398                                (struct sockaddr *)dst, ro->ro_rt);
399                goto done;
400        }
401        /*
402         * Too large for interface; fragment if possible.
403         * Must be able to put at least 8 bytes per fragment.
404         */
405        if (ip->ip_off & IP_DF) {
406                error = EMSGSIZE;
407                /*
408                 * This case can happen if the user changed the MTU
409                 * of an interface after enabling IP on it.  Because
410                 * most netifs don't keep track of routes pointing to
411                 * them, there is no way for one to update all its
412                 * routes when the MTU is changed.
413                 */
414                if ((ro->ro_rt->rt_flags & (RTF_UP | RTF_HOST))
415                    && !(ro->ro_rt->rt_rmx.rmx_locks & RTV_MTU)
416                    && (ro->ro_rt->rt_rmx.rmx_mtu > ifp->if_mtu)) {
417                        ro->ro_rt->rt_rmx.rmx_mtu = ifp->if_mtu;
418                }
419                ipstat.ips_cantfrag++;
420                goto bad;
421        }
422        len = (ifp->if_mtu - hlen) &~ 7;
423        if (len < 8) {
424                error = EMSGSIZE;
425                goto bad;
426        }
427
428    {
429        int mhlen, firstlen = len;
430        struct mbuf **mnext = &m->m_nextpkt;
431
432        /*
433         * Loop through length of segment after first fragment,
434         * make new header and copy data of each part and link onto chain.
435         */
436        m0 = m;
437        mhlen = sizeof (struct ip);
438        for (off = hlen + len; off < (u_short)ip->ip_len; off += len) {
439                MGETHDR(m, M_DONTWAIT, MT_HEADER);
440                if (m == 0) {
441                        error = ENOBUFS;
442                        ipstat.ips_odropped++;
443                        goto sendorfree;
444                }
[793249a]445                m->m_flags |= (m0->m_flags & M_MCAST);
[39e6e65a]446                m->m_data += max_linkhdr;
447                mhip = mtod(m, struct ip *);
448                *mhip = *ip;
449                if (hlen > sizeof (struct ip)) {
450                        mhlen = ip_optcopy(ip, mhip) + sizeof (struct ip);
[491f63a]451#ifdef _IP_VHL
[39e6e65a]452                        mhip->ip_vhl = IP_MAKE_VHL(IPVERSION, mhlen >> 2);
[491f63a]453#else
454                        mhip->ip_v = IPVERSION;
455                        mhip->ip_hl = mhlen >> 2;
456#endif
[39e6e65a]457                }
458                m->m_len = mhlen;
459                mhip->ip_off = ((off - hlen) >> 3) + (ip->ip_off & ~IP_MF);
460                if (ip->ip_off & IP_MF)
461                        mhip->ip_off |= IP_MF;
462                if (off + len >= (u_short)ip->ip_len)
463                        len = (u_short)ip->ip_len - off;
464                else
465                        mhip->ip_off |= IP_MF;
466                mhip->ip_len = htons((u_short)(len + mhlen));
467                m->m_next = m_copy(m0, off, len);
468                if (m->m_next == 0) {
469                        (void) m_free(m);
470                        error = ENOBUFS;        /* ??? */
471                        ipstat.ips_odropped++;
472                        goto sendorfree;
473                }
474                m->m_pkthdr.len = mhlen + len;
[0c67b436]475                m->m_pkthdr.rcvif = NULL;
476                mhip->ip_off = htons(mhip->ip_off);
[39e6e65a]477                mhip->ip_sum = 0;
[491f63a]478#ifdef _IP_VHL
[39e6e65a]479                if (mhip->ip_vhl == IP_VHL_BORING) {
[491f63a]480#else
481                if ((mhip->ip_hl == 5) && (mhip->ip_v == IPVERSION) ) {
482#endif
[39e6e65a]483                        mhip->ip_sum = in_cksum_hdr(mhip);
484                } else {
485                        mhip->ip_sum = in_cksum(m, mhlen);
486                }
487                *mnext = m;
488                mnext = &m->m_nextpkt;
489                ipstat.ips_ofragments++;
490        }
491        /*
492         * Update first fragment by trimming what's been copied out
493         * and updating header, then send each fragment (in order).
494         */
495        m = m0;
496        m_adj(m, hlen + firstlen - (u_short)ip->ip_len);
497        m->m_pkthdr.len = hlen + firstlen;
498        ip->ip_len = htons((u_short)m->m_pkthdr.len);
[0c67b436]499        ip->ip_off |= IP_MF;
500        ip->ip_off = htons(ip->ip_off);
[39e6e65a]501        ip->ip_sum = 0;
[491f63a]502#ifdef _IP_VHL
[39e6e65a]503        if (ip->ip_vhl == IP_VHL_BORING) {
[491f63a]504#else
505        if ((ip->ip_hl == 5) && (ip->ip_v == IPVERSION) ) {
506#endif
[39e6e65a]507                ip->ip_sum = in_cksum_hdr(ip);
508        } else {
509                ip->ip_sum = in_cksum(m, hlen);
510        }
511sendorfree:
512        for (m = m0; m; m = m0) {
513                m0 = m->m_nextpkt;
514                m->m_nextpkt = 0;
515                if (error == 0)
516                        error = (*ifp->if_output)(ifp, m,
517                            (struct sockaddr *)dst, ro->ro_rt);
518                else
519                        m_freem(m);
520        }
521
522        if (error == 0)
523                ipstat.ips_fragmented++;
524    }
525done:
526        return (error);
527bad:
528        m_freem(m0);
529        goto done;
530}
531
532/*
533 * Insert IP options into preformed packet.
534 * Adjust IP destination as required for IP source routing,
535 * as indicated by a non-zero in_addr at the start of the options.
536 *
537 * XXX This routine assumes that the packet has no options in place.
538 */
539static struct mbuf *
[dd967330]540ip_insertoptions(struct mbuf *m, struct mbuf *opt, int *phlen)
[39e6e65a]541{
542        register struct ipoption *p = mtod(opt, struct ipoption *);
543        struct mbuf *n;
544        register struct ip *ip = mtod(m, struct ip *);
[387cc207]545        uint32_t optlen;
[39e6e65a]546
547        optlen = opt->m_len - sizeof(p->ipopt_dst);
[387cc207]548        if (optlen + ip->ip_len > IP_MAXPACKET)
[39e6e65a]549                return (m);             /* XXX should fail */
550        if (p->ipopt_dst.s_addr)
551                ip->ip_dst = p->ipopt_dst;
552        if (m->m_flags & M_EXT || m->m_data - optlen < m->m_pktdat) {
553                MGETHDR(n, M_DONTWAIT, MT_HEADER);
554                if (n == 0)
555                        return (m);
556                n->m_pkthdr.len = m->m_pkthdr.len + optlen;
557                m->m_len -= sizeof(struct ip);
558                m->m_data += sizeof(struct ip);
559                n->m_next = m;
560                m = n;
561                m->m_len = optlen + sizeof(struct ip);
562                m->m_data += max_linkhdr;
563                (void)memcpy(mtod(m, void *), ip, sizeof(struct ip));
564        } else {
565                m->m_data -= optlen;
566                m->m_len += optlen;
567                m->m_pkthdr.len += optlen;
568                ovbcopy((caddr_t)ip, mtod(m, caddr_t), sizeof(struct ip));
569        }
570        ip = mtod(m, struct ip *);
571        bcopy(p->ipopt_list, ip + 1, optlen);
572        *phlen = sizeof(struct ip) + optlen;
[491f63a]573#ifdef _IP_VHL
[39e6e65a]574        ip->ip_vhl = IP_MAKE_VHL(IPVERSION, *phlen >> 2);
[491f63a]575#else
576        ip->ip_v = IPVERSION;
577        ip->ip_hl = *phlen >> 2;
578#endif
[39e6e65a]579        ip->ip_len += optlen;
580        return (m);
581}
582
583/*
584 * Copy options from ip to jp,
585 * omitting those not copied during fragmentation.
586 */
587static int
[dd967330]588ip_optcopy(struct ip *ip, struct ip *jp)
[39e6e65a]589{
590        register u_char *cp, *dp;
591        int opt, optlen, cnt;
592
593        cp = (u_char *)(ip + 1);
594        dp = (u_char *)(jp + 1);
[491f63a]595#ifdef _IP_VHL
[39e6e65a]596        cnt = (IP_VHL_HL(ip->ip_vhl) << 2) - sizeof (struct ip);
[491f63a]597#else
598        cnt = (ip->ip_hl << 2) - sizeof (struct ip);
599#endif
[39e6e65a]600        for (; cnt > 0; cnt -= optlen, cp += optlen) {
601                opt = cp[0];
602                if (opt == IPOPT_EOL)
603                        break;
604                if (opt == IPOPT_NOP) {
605                        /* Preserve for IP mcast tunnel's LSRR alignment. */
606                        *dp++ = IPOPT_NOP;
607                        optlen = 1;
608                        continue;
609                } else
610                        optlen = cp[IPOPT_OLEN];
611                /* bogus lengths should have been caught by ip_dooptions */
612                if (optlen > cnt)
613                        optlen = cnt;
614                if (IPOPT_COPIED(opt)) {
615                        bcopy(cp, dp, optlen);
616                        dp += optlen;
617                }
618        }
619        for (optlen = dp - (u_char *)(jp+1); optlen & 0x3; optlen++)
620                *dp++ = IPOPT_EOL;
621        return (optlen);
622}
623
624/*
625 * IP socket option processing.
626 */
627int
[dd967330]628ip_ctloutput(int op, struct socket *so, int level, int optname,
629        struct mbuf **mp)
[39e6e65a]630{
[0c67b436]631        struct  inpcb *inp = sotoinpcb(so);
[39e6e65a]632        register struct mbuf *m = *mp;
633        register int optval = 0;
634        int error = 0;
635
636        if (level != IPPROTO_IP) {
637                error = EINVAL;
638                if (op == PRCO_SETOPT && *mp)
639                        (void) m_free(*mp);
640        } else switch (op) {
641
642        case PRCO_SETOPT:
643                switch (optname) {
644                case IP_OPTIONS:
645#ifdef notyet
646                case IP_RETOPTS:
647                        return (ip_pcbopts(optname, &inp->inp_options, m));
648#else
649                        return (ip_pcbopts(&inp->inp_options, m));
650#endif
651
652                case IP_TOS:
653                case IP_TTL:
654                case IP_RECVOPTS:
655                case IP_RECVRETOPTS:
656                case IP_RECVDSTADDR:
657                case IP_RECVIF:
658                        if (m == 0 || m->m_len != sizeof(int))
659                                error = EINVAL;
660                        else {
661                                optval = *mtod(m, int *);
662                                switch (optname) {
663
664                                case IP_TOS:
665                                        inp->inp_ip_tos = optval;
666                                        break;
667
668                                case IP_TTL:
669                                        inp->inp_ip_ttl = optval;
670                                        break;
671#define OPTSET(bit) \
672        if (optval) \
673                inp->inp_flags |= bit; \
674        else \
675                inp->inp_flags &= ~bit;
676
677                                case IP_RECVOPTS:
678                                        OPTSET(INP_RECVOPTS);
679                                        break;
680
681                                case IP_RECVRETOPTS:
682                                        OPTSET(INP_RECVRETOPTS);
683                                        break;
684
685                                case IP_RECVDSTADDR:
686                                        OPTSET(INP_RECVDSTADDR);
687                                        break;
688
689                                case IP_RECVIF:
690                                        OPTSET(INP_RECVIF);
691                                        break;
692                                }
693                        }
694                        break;
695#undef OPTSET
696
697                case IP_MULTICAST_IF:
698                case IP_MULTICAST_VIF:
699                case IP_MULTICAST_TTL:
700                case IP_MULTICAST_LOOP:
701                case IP_ADD_MEMBERSHIP:
702                case IP_DROP_MEMBERSHIP:
703                        error = ip_setmoptions(optname, &inp->inp_moptions, m);
704                        break;
705
706                case IP_PORTRANGE:
707                        if (m == 0 || m->m_len != sizeof(int))
708                                error = EINVAL;
709                        else {
710                                optval = *mtod(m, int *);
711
712                                switch (optval) {
713
714                                case IP_PORTRANGE_DEFAULT:
715                                        inp->inp_flags &= ~(INP_LOWPORT);
716                                        inp->inp_flags &= ~(INP_HIGHPORT);
717                                        break;
718
719                                case IP_PORTRANGE_HIGH:
720                                        inp->inp_flags &= ~(INP_LOWPORT);
721                                        inp->inp_flags |= INP_HIGHPORT;
722                                        break;
723
724                                case IP_PORTRANGE_LOW:
725                                        inp->inp_flags &= ~(INP_HIGHPORT);
726                                        inp->inp_flags |= INP_LOWPORT;
727                                        break;
728
729                                default:
730                                        error = EINVAL;
731                                        break;
732                                }
733                        }
734                        break;
735
736                default:
737                        error = ENOPROTOOPT;
738                        break;
739                }
740                if (m)
741                        (void)m_free(m);
742                break;
743
744        case PRCO_GETOPT:
745                switch (optname) {
746                case IP_OPTIONS:
747                case IP_RETOPTS:
748                        *mp = m = m_get(M_WAIT, MT_SOOPTS);
749                        if (inp->inp_options) {
750                                m->m_len = inp->inp_options->m_len;
751                                bcopy(mtod(inp->inp_options, void *),
752                                    mtod(m, void *), m->m_len);
753                        } else
754                                m->m_len = 0;
755                        break;
756
757                case IP_TOS:
758                case IP_TTL:
759                case IP_RECVOPTS:
760                case IP_RECVRETOPTS:
761                case IP_RECVDSTADDR:
762                case IP_RECVIF:
763                        *mp = m = m_get(M_WAIT, MT_SOOPTS);
764                        m->m_len = sizeof(int);
765                        switch (optname) {
766
767                        case IP_TOS:
768                                optval = inp->inp_ip_tos;
769                                break;
770
771                        case IP_TTL:
772                                optval = inp->inp_ip_ttl;
773                                break;
774
775#define OPTBIT(bit)     (inp->inp_flags & bit ? 1 : 0)
776
777                        case IP_RECVOPTS:
778                                optval = OPTBIT(INP_RECVOPTS);
779                                break;
780
781                        case IP_RECVRETOPTS:
782                                optval = OPTBIT(INP_RECVRETOPTS);
783                                break;
784
785                        case IP_RECVDSTADDR:
786                                optval = OPTBIT(INP_RECVDSTADDR);
787                                break;
788
789                        case IP_RECVIF:
790                                optval = OPTBIT(INP_RECVIF);
791                                break;
792                        }
793                        *mtod(m, int *) = optval;
794                        break;
795
796                case IP_MULTICAST_IF:
797                case IP_MULTICAST_VIF:
798                case IP_MULTICAST_TTL:
799                case IP_MULTICAST_LOOP:
800                case IP_ADD_MEMBERSHIP:
801                case IP_DROP_MEMBERSHIP:
802                        error = ip_getmoptions(optname, inp->inp_moptions, mp);
803                        break;
804
805                case IP_PORTRANGE:
806                        *mp = m = m_get(M_WAIT, MT_SOOPTS);
807                        m->m_len = sizeof(int);
808
809                        if (inp->inp_flags & INP_HIGHPORT)
810                                optval = IP_PORTRANGE_HIGH;
811                        else if (inp->inp_flags & INP_LOWPORT)
812                                optval = IP_PORTRANGE_LOW;
813                        else
814                                optval = 0;
815
816                        *mtod(m, int *) = optval;
817                        break;
818
819                default:
820                        error = ENOPROTOOPT;
821                        break;
822                }
823                break;
824        }
825        return (error);
826}
827
828/*
829 * Set up IP options in pcb for insertion in output packets.
830 * Store in mbuf with pointer in pcbopt, adding pseudo-option
831 * with destination address if source routed.
832 */
833static int
834#ifdef notyet
[dd967330]835ip_pcbopts(int optname, struct mbuf **pcbopt, struct mbuf *m)
[39e6e65a]836#else
[dd967330]837ip_pcbopts(struct mbuf **pcbopt, struct mbuf *m)
[39e6e65a]838#endif
839{
840        register int cnt, optlen;
841        register u_char *cp;
842        u_char opt;
843
844        /* turn off any old options */
845        if (*pcbopt)
846                (void)m_free(*pcbopt);
847        *pcbopt = 0;
848        if (m == (struct mbuf *)0 || m->m_len == 0) {
849                /*
850                 * Only turning off any previous options.
851                 */
852                if (m)
853                        (void)m_free(m);
854                return (0);
855        }
856
857#ifndef vax
858        if (m->m_len % sizeof(long))
859                goto bad;
860#endif
861        /*
862         * IP first-hop destination address will be stored before
863         * actual options; move other options back
864         * and clear it when none present.
865         */
866        if (m->m_data + m->m_len + sizeof(struct in_addr) >= &m->m_dat[MLEN])
867                goto bad;
868        cnt = m->m_len;
869        m->m_len += sizeof(struct in_addr);
870        cp = mtod(m, u_char *) + sizeof(struct in_addr);
871        ovbcopy(mtod(m, caddr_t), (caddr_t)cp, (unsigned)cnt);
872        bzero(mtod(m, caddr_t), sizeof(struct in_addr));
873
874        for (; cnt > 0; cnt -= optlen, cp += optlen) {
875                opt = cp[IPOPT_OPTVAL];
876                if (opt == IPOPT_EOL)
877                        break;
878                if (opt == IPOPT_NOP)
879                        optlen = 1;
880                else {
881                        optlen = cp[IPOPT_OLEN];
882                        if (optlen <= IPOPT_OLEN || optlen > cnt)
883                                goto bad;
884                }
885                switch (opt) {
886
887                default:
888                        break;
889
890                case IPOPT_LSRR:
891                case IPOPT_SSRR:
892                        /*
893                         * user process specifies route as:
894                         *      ->A->B->C->D
895                         * D must be our final destination (but we can't
896                         * check that since we may not have connected yet).
897                         * A is first hop destination, which doesn't appear in
898                         * actual IP option, but is stored before the options.
899                         */
900                        if (optlen < IPOPT_MINOFF - 1 + sizeof(struct in_addr))
901                                goto bad;
902                        m->m_len -= sizeof(struct in_addr);
903                        cnt -= sizeof(struct in_addr);
904                        optlen -= sizeof(struct in_addr);
905                        cp[IPOPT_OLEN] = optlen;
906                        /*
907                         * Move first hop before start of options.
908                         */
909                        bcopy((caddr_t)&cp[IPOPT_OFFSET+1], mtod(m, caddr_t),
910                            sizeof(struct in_addr));
911                        /*
912                         * Then copy rest of options back
913                         * to close up the deleted entry.
914                         */
915                        ovbcopy((caddr_t)(&cp[IPOPT_OFFSET+1] +
916                            sizeof(struct in_addr)),
917                            (caddr_t)&cp[IPOPT_OFFSET+1],
918                            (unsigned)cnt + sizeof(struct in_addr));
919                        break;
920                }
921        }
922        if (m->m_len > MAX_IPOPTLEN + sizeof(struct in_addr))
923                goto bad;
924        *pcbopt = m;
925        return (0);
926
927bad:
928        (void)m_free(m);
929        return (EINVAL);
930}
931
932/*
933 * Set the IP multicast options in response to user setsockopt().
934 */
935static int
[dd967330]936ip_setmoptions(int optname, struct ip_moptions **imop, struct mbuf *m)
[39e6e65a]937{
[0c67b436]938        int error = 0;
[39e6e65a]939        u_char loop;
[0c67b436]940        int i;
[39e6e65a]941        struct in_addr addr;
[0c67b436]942        struct ip_mreq *mreq;
943        struct ifnet *ifp;
944        struct ip_moptions *imo = *imop;
[39e6e65a]945        struct route ro;
946        register struct sockaddr_in *dst;
947        int s;
948
949        if (imo == NULL) {
950                /*
951                 * No multicast option buffer attached to the pcb;
952                 * allocate one and initialize to default values.
953                 */
954                imo = (struct ip_moptions*)malloc(sizeof(*imo), M_IPMOPTS,
955                    M_WAITOK);
956
957                if (imo == NULL)
958                        return (ENOBUFS);
959                *imop = imo;
960                imo->imo_multicast_ifp = NULL;
961                imo->imo_multicast_vif = -1;
962                imo->imo_multicast_ttl = IP_DEFAULT_MULTICAST_TTL;
963                imo->imo_multicast_loop = IP_DEFAULT_MULTICAST_LOOP;
964                imo->imo_num_memberships = 0;
965        }
966
967        switch (optname) {
968        /* store an index number for the vif you wanna use in the send */
969        case IP_MULTICAST_VIF:
970                if (!legal_vif_num) {
971                        error = EOPNOTSUPP;
972                        break;
973                }
974                if (m == NULL || m->m_len != sizeof(int)) {
975                        error = EINVAL;
976                        break;
977                }
978                i = *(mtod(m, int *));
979                if (!legal_vif_num(i) && (i != -1)) {
980                        error = EINVAL;
981                        break;
982                }
983                imo->imo_multicast_vif = i;
984                break;
985
986        case IP_MULTICAST_IF:
987                /*
988                 * Select the interface for outgoing multicast packets.
989                 */
990                if (m == NULL || m->m_len != sizeof(struct in_addr)) {
991                        error = EINVAL;
992                        break;
993                }
994                addr = *(mtod(m, struct in_addr *));
995                /*
996                 * INADDR_ANY is used to remove a previous selection.
997                 * When no interface is selected, a default one is
998                 * chosen every time a multicast packet is sent.
999                 */
1000                if (addr.s_addr == INADDR_ANY) {
1001                        imo->imo_multicast_ifp = NULL;
1002                        break;
1003                }
1004                /*
1005                 * The selected interface is identified by its local
1006                 * IP address.  Find the interface and confirm that
1007                 * it supports multicasting.
1008                 */
1009                s = splimp();
1010                INADDR_TO_IFP(addr, ifp);
1011                if (ifp == NULL || (ifp->if_flags & IFF_MULTICAST) == 0) {
1012                        splx(s);
1013                        error = EADDRNOTAVAIL;
1014                        break;
1015                }
1016                imo->imo_multicast_ifp = ifp;
1017                splx(s);
1018                break;
1019
1020        case IP_MULTICAST_TTL:
1021                /*
1022                 * Set the IP time-to-live for outgoing multicast packets.
1023                 */
1024                if (m == NULL || m->m_len != 1) {
1025                        error = EINVAL;
1026                        break;
1027                }
1028                imo->imo_multicast_ttl = *(mtod(m, u_char *));
1029                break;
1030
1031        case IP_MULTICAST_LOOP:
1032                /*
1033                 * Set the loopback flag for outgoing multicast packets.
1034                 * Must be zero or one.
1035                 */
1036                if (m == NULL || m->m_len != 1 ||
1037                   (loop = *(mtod(m, u_char *))) > 1) {
1038                        error = EINVAL;
1039                        break;
1040                }
1041                imo->imo_multicast_loop = loop;
1042                break;
1043
1044        case IP_ADD_MEMBERSHIP:
1045                /*
1046                 * Add a multicast group membership.
1047                 * Group must be a valid IP multicast address.
1048                 */
1049                if (m == NULL || m->m_len != sizeof(struct ip_mreq)) {
1050                        error = EINVAL;
1051                        break;
1052                }
1053                mreq = mtod(m, struct ip_mreq *);
1054                if (!IN_MULTICAST(ntohl(mreq->imr_multiaddr.s_addr))) {
1055                        error = EINVAL;
1056                        break;
1057                }
1058                s = splimp();
1059                /*
1060                 * If no interface address was provided, use the interface of
1061                 * the route to the given multicast address.
1062                 */
1063                if (mreq->imr_interface.s_addr == INADDR_ANY) {
1064                        bzero((caddr_t)&ro, sizeof(ro));
1065                        dst = (struct sockaddr_in *)&ro.ro_dst;
1066                        dst->sin_len = sizeof(*dst);
1067                        dst->sin_family = AF_INET;
1068                        dst->sin_addr = mreq->imr_multiaddr;
1069                        rtalloc(&ro);
1070                        if (ro.ro_rt == NULL) {
1071                                error = EADDRNOTAVAIL;
1072                                splx(s);
1073                                break;
1074                        }
1075                        ifp = ro.ro_rt->rt_ifp;
1076                        rtfree(ro.ro_rt);
1077                }
1078                else {
1079                        INADDR_TO_IFP(mreq->imr_interface, ifp);
1080                }
1081
1082                /*
1083                 * See if we found an interface, and confirm that it
1084                 * supports multicast.
1085                 */
1086                if (ifp == NULL || (ifp->if_flags & IFF_MULTICAST) == 0) {
1087                        error = EADDRNOTAVAIL;
1088                        splx(s);
1089                        break;
1090                }
1091                /*
1092                 * See if the membership already exists or if all the
1093                 * membership slots are full.
1094                 */
1095                for (i = 0; i < imo->imo_num_memberships; ++i) {
1096                        if (imo->imo_membership[i]->inm_ifp == ifp &&
1097                            imo->imo_membership[i]->inm_addr.s_addr
1098                                                == mreq->imr_multiaddr.s_addr)
1099                                break;
1100                }
1101                if (i < imo->imo_num_memberships) {
1102                        error = EADDRINUSE;
1103                        splx(s);
1104                        break;
1105                }
1106                if (i == IP_MAX_MEMBERSHIPS) {
1107                        error = ETOOMANYREFS;
1108                        splx(s);
1109                        break;
1110                }
1111                /*
1112                 * Everything looks good; add a new record to the multicast
1113                 * address list for the given interface.
1114                 */
1115                if ((imo->imo_membership[i] =
1116                    in_addmulti(&mreq->imr_multiaddr, ifp)) == NULL) {
1117                        error = ENOBUFS;
1118                        splx(s);
1119                        break;
1120                }
1121                ++imo->imo_num_memberships;
1122                splx(s);
1123                break;
1124
1125        case IP_DROP_MEMBERSHIP:
1126                /*
1127                 * Drop a multicast group membership.
1128                 * Group must be a valid IP multicast address.
1129                 */
1130                if (m == NULL || m->m_len != sizeof(struct ip_mreq)) {
1131                        error = EINVAL;
1132                        break;
1133                }
1134                mreq = mtod(m, struct ip_mreq *);
1135                if (!IN_MULTICAST(ntohl(mreq->imr_multiaddr.s_addr))) {
1136                        error = EINVAL;
1137                        break;
1138                }
1139
1140                s = splimp();
1141                /*
1142                 * If an interface address was specified, get a pointer
1143                 * to its ifnet structure.
1144                 */
1145                if (mreq->imr_interface.s_addr == INADDR_ANY)
1146                        ifp = NULL;
1147                else {
1148                        INADDR_TO_IFP(mreq->imr_interface, ifp);
1149                        if (ifp == NULL) {
1150                                error = EADDRNOTAVAIL;
1151                                splx(s);
1152                                break;
1153                        }
1154                }
1155                /*
1156                 * Find the membership in the membership array.
1157                 */
1158                for (i = 0; i < imo->imo_num_memberships; ++i) {
1159                        if ((ifp == NULL ||
1160                             imo->imo_membership[i]->inm_ifp == ifp) &&
1161                             imo->imo_membership[i]->inm_addr.s_addr ==
1162                             mreq->imr_multiaddr.s_addr)
1163                                break;
1164                }
1165                if (i == imo->imo_num_memberships) {
1166                        error = EADDRNOTAVAIL;
1167                        splx(s);
1168                        break;
1169                }
1170                /*
1171                 * Give up the multicast address record to which the
1172                 * membership points.
1173                 */
1174                in_delmulti(imo->imo_membership[i]);
1175                /*
1176                 * Remove the gap in the membership array.
1177                 */
1178                for (++i; i < imo->imo_num_memberships; ++i)
1179                        imo->imo_membership[i-1] = imo->imo_membership[i];
1180                --imo->imo_num_memberships;
1181                splx(s);
1182                break;
1183
1184        default:
1185                error = EOPNOTSUPP;
1186                break;
1187        }
1188
1189        /*
1190         * If all options have default values, no need to keep the mbuf.
1191         */
1192        if (imo->imo_multicast_ifp == NULL &&
1193            imo->imo_multicast_vif == -1 &&
1194            imo->imo_multicast_ttl == IP_DEFAULT_MULTICAST_TTL &&
1195            imo->imo_multicast_loop == IP_DEFAULT_MULTICAST_LOOP &&
1196            imo->imo_num_memberships == 0) {
1197                free(*imop, M_IPMOPTS);
1198                *imop = NULL;
1199        }
1200
1201        return (error);
1202}
1203
1204/*
1205 * Return the IP multicast options in response to user getsockopt().
1206 */
1207static int
[dd967330]1208ip_getmoptions(int optname, struct ip_moptions *imo,
1209        struct mbuf **mp)
[39e6e65a]1210{
1211        u_char *ttl;
1212        u_char *loop;
1213        struct in_addr *addr;
1214        struct in_ifaddr *ia;
1215
1216        *mp = m_get(M_WAIT, MT_SOOPTS);
1217
1218        switch (optname) {
1219
1220        case IP_MULTICAST_VIF:
1221                if (imo != NULL)
1222                        *(mtod(*mp, int *)) = imo->imo_multicast_vif;
1223                else
1224                        *(mtod(*mp, int *)) = -1;
1225                (*mp)->m_len = sizeof(int);
1226                return(0);
1227
1228        case IP_MULTICAST_IF:
1229                addr = mtod(*mp, struct in_addr *);
1230                (*mp)->m_len = sizeof(struct in_addr);
1231                if (imo == NULL || imo->imo_multicast_ifp == NULL)
1232                        addr->s_addr = INADDR_ANY;
1233                else {
1234                        IFP_TO_IA(imo->imo_multicast_ifp, ia);
1235                        addr->s_addr = (ia == NULL) ? INADDR_ANY
1236                                        : IA_SIN(ia)->sin_addr.s_addr;
1237                }
1238                return (0);
1239
1240        case IP_MULTICAST_TTL:
1241                ttl = mtod(*mp, u_char *);
1242                (*mp)->m_len = 1;
1243                *ttl = (imo == NULL) ? IP_DEFAULT_MULTICAST_TTL
1244                                     : imo->imo_multicast_ttl;
1245                return (0);
1246
1247        case IP_MULTICAST_LOOP:
1248                loop = mtod(*mp, u_char *);
1249                (*mp)->m_len = 1;
1250                *loop = (imo == NULL) ? IP_DEFAULT_MULTICAST_LOOP
1251                                      : imo->imo_multicast_loop;
1252                return (0);
1253
1254        default:
1255                return (EOPNOTSUPP);
1256        }
1257}
1258
1259/*
1260 * Discard the IP multicast options.
1261 */
1262void
[dd967330]1263ip_freemoptions(struct ip_moptions *imo)
[39e6e65a]1264{
1265        register int i;
1266
1267        if (imo != NULL) {
1268                for (i = 0; i < imo->imo_num_memberships; ++i)
1269                        in_delmulti(imo->imo_membership[i]);
1270                free(imo, M_IPMOPTS);
1271        }
1272}
1273
1274/*
1275 * Routine called from ip_output() to loop back a copy of an IP multicast
1276 * packet to the input queue of a specified interface.  Note that this
1277 * calls the output routine of the loopback "driver", but with an interface
1278 * pointer that might NOT be a loopback interface -- evil, but easier than
1279 * replicating that code here.
1280 */
1281static void
[dd967330]1282ip_mloopback(struct ifnet *ifp, struct mbuf *m, struct sockaddr_in *dst,
1283        int hlen)
[39e6e65a]1284{
1285        register struct ip *ip;
1286        struct mbuf *copym;
1287
1288        copym = m_copy(m, 0, M_COPYALL);
1289        if (copym != NULL && (copym->m_flags & M_EXT || copym->m_len < hlen))
1290                copym = m_pullup(copym, hlen);
1291        if (copym != NULL) {
1292                /*
1293                 * We don't bother to fragment if the IP length is greater
1294                 * than the interface's MTU.  Can this possibly matter?
1295                 */
1296                ip = mtod(copym, struct ip *);
[0c67b436]1297                ip->ip_len = htons(ip->ip_len);
1298                ip->ip_off = htons(ip->ip_off);
[39e6e65a]1299                ip->ip_sum = 0;
[f94e799e]1300#ifdef _IP_VHL
[39e6e65a]1301                if (ip->ip_vhl == IP_VHL_BORING) {
1302                        ip->ip_sum = in_cksum_hdr(ip);
1303                } else {
1304                        ip->ip_sum = in_cksum(copym, hlen);
1305                }
[f94e799e]1306#else
1307                ip->ip_sum = in_cksum(copym, hlen);
1308#endif
[39e6e65a]1309                /*
1310                 * NB:
1311                 * It's not clear whether there are any lingering
1312                 * reentrancy problems in other areas which might
1313                 * be exposed by using ip_input directly (in
1314                 * particular, everything which modifies the packet
1315                 * in-place).  Yet another option is using the
1316                 * protosw directly to deliver the looped back
1317                 * packet.  For the moment, we'll err on the side
1318                 * of safety by continuing to abuse looutput().
1319                 */
1320#ifdef notdef
1321                copym->m_pkthdr.rcvif = ifp;
[f94e799e]1322                ip_input(copym);
[39e6e65a]1323#else
1324                (void) looutput(ifp, copym, (struct sockaddr *)dst, NULL);
1325#endif
1326        }
1327}
Note: See TracBrowser for help on using the repository browser.