Annotation of kernel/bsd/netiso/clnp_output.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
        !             7:  * Reserved.  This file contains Original Code and/or Modifications of
        !             8:  * Original Code as defined in and that are subject to the Apple Public
        !             9:  * Source License Version 1.1 (the "License").  You may not use this file
        !            10:  * except in compliance with the License.  Please obtain a copy of the
        !            11:  * License at http://www.apple.com/publicsource and read it before using
        !            12:  * this file.
        !            13:  * 
        !            14:  * The Original Code and all software distributed under the License are
        !            15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            19:  * License for the specific language governing rights and limitations
        !            20:  * under the License.
        !            21:  * 
        !            22:  * @APPLE_LICENSE_HEADER_END@
        !            23:  */
        !            24: 
        !            25: /*-
        !            26:  * Copyright (c) 1991, 1993
        !            27:  *     The Regents of the University of California.  All rights reserved.
        !            28:  *
        !            29:  * Redistribution and use in source and binary forms, with or without
        !            30:  * modification, are permitted provided that the following conditions
        !            31:  * are met:
        !            32:  * 1. Redistributions of source code must retain the above copyright
        !            33:  *    notice, this list of conditions and the following disclaimer.
        !            34:  * 2. Redistributions in binary form must reproduce the above copyright
        !            35:  *    notice, this list of conditions and the following disclaimer in the
        !            36:  *    documentation and/or other materials provided with the distribution.
        !            37:  * 3. All advertising materials mentioning features or use of this software
        !            38:  *    must display the following acknowledgement:
        !            39:  *     This product includes software developed by the University of
        !            40:  *     California, Berkeley and its contributors.
        !            41:  * 4. Neither the name of the University nor the names of its contributors
        !            42:  *    may be used to endorse or promote products derived from this software
        !            43:  *    without specific prior written permission.
        !            44:  *
        !            45:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
        !            46:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            47:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            48:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
        !            49:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            50:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            51:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            52:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            53:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            54:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            55:  * SUCH DAMAGE.
        !            56:  *
        !            57:  *     @(#)clnp_output.c       8.1 (Berkeley) 6/10/93
        !            58:  */
        !            59: 
        !            60: /***********************************************************
        !            61:                Copyright IBM Corporation 1987
        !            62: 
        !            63:                       All Rights Reserved
        !            64: 
        !            65: Permission to use, copy, modify, and distribute this software and its 
        !            66: documentation for any purpose and without fee is hereby granted, 
        !            67: provided that the above copyright notice appear in all copies and that
        !            68: both that copyright notice and this permission notice appear in 
        !            69: supporting documentation, and that the name of IBM not be
        !            70: used in advertising or publicity pertaining to distribution of the
        !            71: software without specific, written prior permission.  
        !            72: 
        !            73: IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
        !            74: ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
        !            75: IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
        !            76: ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
        !            77: WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
        !            78: ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
        !            79: SOFTWARE.
        !            80: 
        !            81: ******************************************************************/
        !            82: 
        !            83: /*
        !            84:  * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
        !            85:  */
        !            86: 
        !            87: #include <sys/param.h>
        !            88: #include <sys/mbuf.h>
        !            89: #include <sys/domain.h>
        !            90: #include <sys/protosw.h>
        !            91: #include <sys/socket.h>
        !            92: #include <sys/socketvar.h>
        !            93: #include <sys/errno.h>
        !            94: #include <sys/time.h>
        !            95: 
        !            96: #include <net/if.h>
        !            97: #include <net/route.h>
        !            98: 
        !            99: #include <netiso/iso.h>
        !           100: #include <netiso/iso_var.h>
        !           101: #include <netiso/iso_pcb.h>
        !           102: #include <netiso/clnp.h>
        !           103: #include <netiso/clnp_stat.h>
        !           104: #include <netiso/argo_debug.h>
        !           105: 
        !           106: static struct clnp_fixed dt_template = {
        !           107:        ISO8473_CLNP,   /* network identifier */
        !           108:        0,                              /* length */
        !           109:        ISO8473_V1,             /* version */
        !           110:        CLNP_TTL,               /* ttl */
        !           111:        CLNP_DT|CNF_SEG_OK|CNF_ERR_OK,          /* type */
        !           112:        0,                              /* segment length */
        !           113:        0                               /* checksum */
        !           114: };
        !           115: 
        !           116: static struct clnp_fixed raw_template = {
        !           117:        ISO8473_CLNP,   /* network identifier */
        !           118:        0,                              /* length */
        !           119:        ISO8473_V1,             /* version */
        !           120:        CLNP_TTL,               /* ttl */
        !           121:        CLNP_RAW|CNF_SEG_OK|CNF_ERR_OK,         /* type */
        !           122:        0,                              /* segment length */
        !           123:        0                               /* checksum */
        !           124: };
        !           125: 
        !           126: static struct clnp_fixed echo_template = {
        !           127:        ISO8473_CLNP,   /* network identifier */
        !           128:        0,                              /* length */
        !           129:        ISO8473_V1,             /* version */
        !           130:        CLNP_TTL,               /* ttl */
        !           131:        CLNP_EC|CNF_SEG_OK|CNF_ERR_OK,          /* type */
        !           132:        0,                              /* segment length */
        !           133:        0                               /* checksum */
        !           134: };
        !           135: 
        !           136: static struct clnp_fixed echor_template = {
        !           137:        ISO8473_CLNP,   /* network identifier */
        !           138:        0,                              /* length */
        !           139:        ISO8473_V1,             /* version */
        !           140:        CLNP_TTL,               /* ttl */
        !           141:        CLNP_ECR|CNF_SEG_OK|CNF_ERR_OK,         /* type */
        !           142:        0,                              /* segment length */
        !           143:        0                               /* checksum */
        !           144: };
        !           145: 
        !           146: #ifdef DECBIT
        !           147: u_char qos_option[] = {CLNPOVAL_QOS, 1, 
        !           148:        CLNPOVAL_GLOBAL|CLNPOVAL_SEQUENCING|CLNPOVAL_LOWDELAY};
        !           149: #endif /* DECBIT */
        !           150: 
        !           151: int                            clnp_id = 0;            /* id for segmented dgrams */
        !           152: 
        !           153: /*
        !           154:  * FUNCTION:           clnp_output
        !           155:  *
        !           156:  * PURPOSE:                    output the data in the mbuf as a clnp datagram
        !           157:  *
        !           158:  *                                     The data specified by m0 is sent as a clnp datagram. 
        !           159:  *                                     The mbuf chain m0 will be freed when this routine has
        !           160:  *                                     returned.
        !           161:  *
        !           162:  *                                     If options is non-null, it points to an mbuf which contains
        !           163:  *                                     options to be sent with the datagram. The options must
        !           164:  *                                     be formatted in the mbuf according to clnp rules. Options
        !           165:  *                                     will not be freed.
        !           166:  *
        !           167:  *                                     Datalen specifies the length of the data in m0. 
        !           168:  *
        !           169:  *                                     Src and dst are the addresses for the packet. 
        !           170:  *
        !           171:  *                                     If route is non-null, it is used as the route for 
        !           172:  *                                     the packet. 
        !           173:  *
        !           174:  *                                     By default, a DT is sent. However, if flags & CNLP_SEND_ER
        !           175:  *                                     then an ER will be sent. If flags & CLNP_SEND_RAW, then
        !           176:  *                                     the packet will be send as raw clnp.
        !           177:  *
        !           178:  * RETURNS:                    0       success
        !           179:  *                                     appropriate error code
        !           180:  *
        !           181:  * SIDE EFFECTS:       none
        !           182:  *
        !           183:  * NOTES:                      
        !           184:  *                                     Flags are interpretated as follows:
        !           185:  *                                             CLNP_NO_SEG - do not allow this pkt to be segmented.
        !           186:  *                                             CLNP_NO_ER  - have pkt request ER suppression.
        !           187:  *                                             CLNP_SEND_RAW - send pkt as RAW DT rather than TP DT
        !           188:  *                                             CLNP_NO_CKSUM - don't compute clnp checksum
        !           189:  *                                             CLNP_ECHO - send as ECHO packet
        !           190:  *
        !           191:  *                                     When checking for a cached packet, clnp checks
        !           192:  *                                     that the route taken is still up. It does not
        !           193:  *                                     check that the route is still to the same destination.
        !           194:  *                                     This means that any entity that alters an existing
        !           195:  *                                     route for an isopcb (such as when a redirect arrives)
        !           196:  *                                     must invalidate the clnp cache. It might be perferable
        !           197:  *                                     to have clnp check that the route has the same dest, but
        !           198:  *                                     by avoiding this check, we save a call to iso_addrmatch1.
        !           199:  */
        !           200: clnp_output(m0, isop, datalen, flags)
        !           201: struct mbuf                    *m0;            /* data for the packet */
        !           202: struct isopcb          *isop;          /* iso pcb */
        !           203: int                                    datalen;        /* number of bytes of data in m0 */
        !           204: int                                    flags;          /* flags */
        !           205: {
        !           206:        int                                                     error = 0;              /* return value of function */
        !           207:        register struct mbuf            *m = m0;                /* mbuf for clnp header chain */
        !           208:        register struct clnp_fixed      *clnp;                  /* ptr to fixed part of hdr */
        !           209:        register caddr_t                        hoff;                   /* offset into header */
        !           210:        int                                                     total_len;              /* total length of packet */
        !           211:        struct iso_addr                         *src;           /* ptr to source address */
        !           212:        struct iso_addr                         *dst;           /* ptr to destination address */
        !           213:        struct clnp_cache                       clc;            /* storage for cache information */
        !           214:        struct clnp_cache                       *clcp = NULL;   /* ptr to clc */
        !           215:        int                                                     hdrlen = 0;
        !           216: 
        !           217:        dst = &isop->isop_faddr->siso_addr;
        !           218:        if (isop->isop_laddr == 0) {
        !           219:                struct iso_ifaddr *ia = 0;
        !           220:                clnp_route(dst, &isop->isop_route, flags, 0, &ia);
        !           221:                if (ia == 0 || ia->ia_ifa.ifa_addr->sa_family != AF_ISO)
        !           222:                        return (ENETUNREACH);
        !           223:                src = &ia->ia_addr.siso_addr;
        !           224:        } else
        !           225:                src = &isop->isop_laddr->siso_addr;
        !           226: 
        !           227:        IFDEBUG(D_OUTPUT)
        !           228:                printf("clnp_output: to %s", clnp_iso_addrp(dst));
        !           229:                printf(" from %s of %d bytes\n", clnp_iso_addrp(src), datalen);
        !           230:                printf("\toptions x%x, flags x%x, isop_clnpcache x%x\n", 
        !           231:                        isop->isop_options, flags, isop->isop_clnpcache);
        !           232:        ENDDEBUG
        !           233: 
        !           234:        if (isop->isop_clnpcache != NULL) {
        !           235:                clcp = mtod(isop->isop_clnpcache, struct clnp_cache *);
        !           236:        }
        !           237:        
        !           238:        /*
        !           239:         *      Check if cache is valid ...
        !           240:         */
        !           241:        IFDEBUG(D_OUTPUT)
        !           242:                printf("clnp_output: ck cache: clcp %x\n", clcp);
        !           243:                if (clcp != NULL) {
        !           244:                        printf("\tclc_dst %s\n", clnp_iso_addrp(&clcp->clc_dst));
        !           245:                        printf("\tisop_opts x%x, clc_opts x%x\n", isop->isop_options,
        !           246:                                clcp->clc_options);
        !           247:                        if (isop->isop_route.ro_rt)
        !           248:                                printf("\tro_rt x%x, rt_flags x%x\n",
        !           249:                                        isop->isop_route.ro_rt, isop->isop_route.ro_rt->rt_flags);
        !           250:                        printf("\tflags x%x, clc_flags x%x\n", flags, clcp->clc_flags);
        !           251:                        printf("\tclc_hdr x%x\n", clcp->clc_hdr);
        !           252:                }
        !           253:        ENDDEBUG
        !           254:        if ((clcp != NULL) &&                                                           /* cache exists */
        !           255:                (isop->isop_options == clcp->clc_options) &&    /* same options */
        !           256:                (iso_addrmatch1(dst, &clcp->clc_dst)) &&                /* dst still same */
        !           257:                (isop->isop_route.ro_rt != NULL) &&                             /* route exists */
        !           258:                (isop->isop_route.ro_rt == clcp->clc_rt) &&             /* and is cached */
        !           259:                (isop->isop_route.ro_rt->rt_flags & RTF_UP) &&  /* route still up */
        !           260:                (flags == clcp->clc_flags) &&                                   /* same flags */
        !           261:                (clcp->clc_hdr != NULL)) {                                              /* hdr mbuf exists */
        !           262:                /*
        !           263:                 *      The cache is valid
        !           264:                 */
        !           265: 
        !           266:                IFDEBUG(D_OUTPUT)
        !           267:                        printf("clnp_output: using cache\n");
        !           268:                ENDDEBUG
        !           269: 
        !           270:                m = m_copy(clcp->clc_hdr, 0, (int)M_COPYALL);
        !           271:                if (m == NULL) {
        !           272:                        /*
        !           273:                         *      No buffers left to copy cached packet header. Use
        !           274:                         *      the cached packet header this time, and
        !           275:                         *      mark the hdr as vacant
        !           276:                         */
        !           277:                        m = clcp->clc_hdr;
        !           278:                        clcp->clc_hdr = NULL;
        !           279:                }
        !           280:                m->m_next = m0; /* ASSUMES pkt hdr is 1 mbuf long */
        !           281:                clnp = mtod(m, struct clnp_fixed *);
        !           282:        } else {
        !           283:                struct clnp_optidx      *oidx = NULL;           /* index to clnp options */
        !           284: 
        !           285:                /*
        !           286:                 *      The cache is not valid. Allocate an mbuf (if necessary)
        !           287:                 *      to hold cached info. If one is not available, then
        !           288:                 *      don't bother with the cache
        !           289:                 */
        !           290:                INCSTAT(cns_cachemiss);
        !           291:                if (flags & CLNP_NOCACHE) {
        !           292:                        clcp = &clc;
        !           293:                } else {
        !           294:                        if (isop->isop_clnpcache == NULL) {
        !           295:                                /*
        !           296:                                 *      There is no clnpcache. Allocate an mbuf to hold one
        !           297:                                 */
        !           298:                                if ((isop->isop_clnpcache = m_get(M_DONTWAIT, MT_HEADER))
        !           299:                                        == NULL) {
        !           300:                                        /*
        !           301:                                         *      No mbufs available. Pretend that we don't want
        !           302:                                         *      caching this time.
        !           303:                                         */
        !           304:                                        IFDEBUG(D_OUTPUT)
        !           305:                                                printf("clnp_output: no mbufs to allocate to cache\n");
        !           306:                                        ENDDEBUG
        !           307:                                        flags  |= CLNP_NOCACHE;
        !           308:                                        clcp = &clc;
        !           309:                                } else {
        !           310:                                        clcp = mtod(isop->isop_clnpcache, struct clnp_cache *);
        !           311:                                }
        !           312:                        } else {
        !           313:                                /*
        !           314:                                 *      A clnpcache mbuf exists. If the clc_hdr is not null,
        !           315:                                 *      we must free it, as a new one is about to be created.
        !           316:                                 */
        !           317:                                clcp = mtod(isop->isop_clnpcache, struct clnp_cache *);
        !           318:                                if (clcp->clc_hdr != NULL) {
        !           319:                                        /*
        !           320:                                         *      The clc_hdr is not null but a clnpcache mbuf exists.
        !           321:                                         *      This means that there was a cache, but the existing
        !           322:                                         *      copy of the hdr is no longer valid. Free it now
        !           323:                                         *      before we lose the pointer to it.
        !           324:                                         */
        !           325:                                        IFDEBUG(D_OUTPUT)
        !           326:                                                printf("clnp_output: freeing old clc_hdr 0x%x\n",
        !           327:                                                clcp->clc_hdr);
        !           328:                                        ENDDEBUG
        !           329:                                        m_free(clcp->clc_hdr);
        !           330:                                        IFDEBUG(D_OUTPUT)
        !           331:                                                printf("clnp_output: freed old clc_hdr (done)\n");
        !           332:                                        ENDDEBUG
        !           333:                                }
        !           334:                        }
        !           335:                }
        !           336:                IFDEBUG(D_OUTPUT)
        !           337:                        printf("clnp_output: NEW clcp x%x\n",clcp);
        !           338:                ENDDEBUG
        !           339:                bzero((caddr_t)clcp, sizeof(struct clnp_cache));
        !           340: 
        !           341:                if (isop->isop_optindex)
        !           342:                        oidx = mtod(isop->isop_optindex, struct clnp_optidx *);
        !           343: 
        !           344:                /*
        !           345:                 *      Don't allow packets with security, quality of service,
        !           346:                 *      priority, or error report options to be sent.
        !           347:                 */
        !           348:                if ((isop->isop_options) && (oidx)) {
        !           349:                        if ((oidx->cni_securep) ||
        !           350:                                (oidx->cni_priorp) ||
        !           351:                                (oidx->cni_qos_formatp) ||
        !           352:                                (oidx->cni_er_reason != ER_INVALREAS)) {
        !           353:                                IFDEBUG(D_OUTPUT)
        !           354:                                        printf("clnp_output: pkt dropped - option unsupported\n");
        !           355:                                ENDDEBUG
        !           356:                                m_freem(m0);
        !           357:                                return(EINVAL);
        !           358:                        }
        !           359:                }
        !           360: 
        !           361:                /*
        !           362:                 *      Don't allow any invalid flags to be set
        !           363:                 */
        !           364:                if ((flags & (CLNP_VFLAGS)) != flags) {
        !           365:                        IFDEBUG(D_OUTPUT)
        !           366:                                printf("clnp_output: packet dropped - flags unsupported\n");
        !           367:                        ENDDEBUG
        !           368:                        INCSTAT(cns_odropped);
        !           369:                        m_freem(m0);
        !           370:                        return(EINVAL);
        !           371:                }
        !           372: 
        !           373:                /*
        !           374:                 *      Don't allow funny lengths on dst; src may be zero in which
        !           375:                 *      case we insert the source address based upon the interface
        !           376:                 */
        !           377:                if ((src->isoa_len > sizeof(struct iso_addr)) || 
        !           378:                        (dst->isoa_len == 0) ||
        !           379:                        (dst->isoa_len > sizeof(struct iso_addr))) {
        !           380:                        m_freem(m0);
        !           381:                        INCSTAT(cns_odropped);
        !           382:                        return(ENAMETOOLONG);
        !           383:                }
        !           384: 
        !           385:                /*
        !           386:                 *      Grab mbuf to contain header
        !           387:                 */
        !           388:                MGETHDR(m, M_DONTWAIT, MT_HEADER);
        !           389:                if (m == 0) {
        !           390:                        m_freem(m0);
        !           391:                        INCSTAT(cns_odropped);
        !           392:                        return(ENOBUFS);
        !           393:                }
        !           394:                INCSTAT(cns_sent);
        !           395:                m->m_next = m0;
        !           396:                clnp = mtod(m, struct clnp_fixed *);
        !           397:                clcp->clc_segoff = 0;
        !           398: 
        !           399:                /*
        !           400:                 *      Fill in all of fixed hdr except lengths and checksum
        !           401:                 */
        !           402:                if (flags & CLNP_SEND_RAW) {
        !           403:                        *clnp = raw_template;
        !           404:                } else if (flags & CLNP_ECHO) {
        !           405:                        *clnp = echo_template;
        !           406:                } else if (flags & CLNP_ECHOR) {
        !           407:                        *clnp = echor_template;
        !           408:                } else {
        !           409:                        *clnp = dt_template;
        !           410:                }
        !           411:                if (flags & CLNP_NO_SEG)
        !           412:                        clnp->cnf_type &= ~CNF_SEG_OK;
        !           413:                if (flags & CLNP_NO_ER)
        !           414:                        clnp->cnf_type &= ~CNF_ERR_OK;
        !           415: 
        !           416:                /*
        !           417:                 *      Route packet; special case for source rt
        !           418:                 */
        !           419:                if ((isop->isop_options) && CLNPSRCRT_VALID(oidx)) {
        !           420:                        IFDEBUG(D_OUTPUT)
        !           421:                                printf("clnp_output: calling clnp_srcroute\n");
        !           422:                        ENDDEBUG
        !           423:                        error = clnp_srcroute(isop->isop_options, oidx, &isop->isop_route,
        !           424:                                &clcp->clc_firsthop, &clcp->clc_ifa, dst);
        !           425:                } else {
        !           426:                        IFDEBUG(D_OUTPUT)
        !           427:                        ENDDEBUG
        !           428:                        error = clnp_route(dst, &isop->isop_route, flags, 
        !           429:                                &clcp->clc_firsthop, &clcp->clc_ifa);
        !           430:                }
        !           431:                if (error || (clcp->clc_ifa == 0)) {
        !           432:                        IFDEBUG(D_OUTPUT)
        !           433:                                printf("clnp_output: route failed, errno %d\n", error);
        !           434:                                printf("@clcp:\n");
        !           435:                                dump_buf(clcp, sizeof (struct clnp_cache));
        !           436:                        ENDDEBUG
        !           437:                        goto bad;
        !           438:                }
        !           439:                clcp->clc_rt = isop->isop_route.ro_rt;  /* XXX */
        !           440:                clcp->clc_ifp = clcp->clc_ifa->ia_ifp;  /* XXX */
        !           441: 
        !           442:                IFDEBUG(D_OUTPUT)
        !           443:                        printf("clnp_output: packet routed to %s\n", 
        !           444:                                clnp_iso_addrp(
        !           445:                                        &((struct sockaddr_iso *)clcp->clc_firsthop)->siso_addr));
        !           446:                ENDDEBUG
        !           447:                
        !           448:                /*
        !           449:                 *      If src address is not yet specified, use address of 
        !           450:                 *      interface. NOTE: this will now update the laddr field in
        !           451:                 *      the isopcb. Is this desirable? RAH?
        !           452:                 */
        !           453:                if (src->isoa_len == 0) {
        !           454:                        src = &(clcp->clc_ifa->ia_addr.siso_addr);
        !           455:                        IFDEBUG(D_OUTPUT)
        !           456:                                printf("clnp_output: new src %s\n", clnp_iso_addrp(src));
        !           457:                        ENDDEBUG
        !           458:                }
        !           459: 
        !           460:                /*
        !           461:                 *      Insert the source and destination address,
        !           462:                 */
        !           463:                hoff = (caddr_t)clnp + sizeof(struct clnp_fixed);
        !           464:                CLNP_INSERT_ADDR(hoff, *dst);
        !           465:                CLNP_INSERT_ADDR(hoff, *src);
        !           466: 
        !           467:                /*
        !           468:                 *      Leave room for the segment part, if segmenting is selected
        !           469:                 */
        !           470:                if (clnp->cnf_type & CNF_SEG_OK) {
        !           471:                        clcp->clc_segoff = hoff - (caddr_t)clnp;
        !           472:                        hoff += sizeof(struct clnp_segment);
        !           473:                }
        !           474: 
        !           475:                clnp->cnf_hdr_len = m->m_len = (u_char)(hoff - (caddr_t)clnp);
        !           476:                hdrlen = clnp->cnf_hdr_len;
        !           477: 
        !           478: #ifdef DECBIT
        !           479:                /*
        !           480:                 *      Add the globally unique QOS (with room for congestion experienced
        !           481:                 *      bit). I can safely assume that this option is not in the options
        !           482:                 *      mbuf below because I checked that the option was not specified
        !           483:                 *      previously
        !           484:                 */
        !           485:                if ((m->m_len + sizeof(qos_option)) < MLEN) {
        !           486:                        bcopy((caddr_t)qos_option, hoff, sizeof(qos_option));
        !           487:                        clnp->cnf_hdr_len += sizeof(qos_option);
        !           488:                        hdrlen += sizeof(qos_option);
        !           489:                        m->m_len += sizeof(qos_option);
        !           490:                }
        !           491: #endif /* DECBIT */
        !           492: 
        !           493:                /*
        !           494:                 *      If an options mbuf is present, concatenate a copy to the hdr mbuf.
        !           495:                 */
        !           496:                if (isop->isop_options) {
        !           497:                        struct mbuf *opt_copy = m_copy(isop->isop_options, 0, (int)M_COPYALL);
        !           498:                        if (opt_copy == NULL) {
        !           499:                                error = ENOBUFS;
        !           500:                                goto bad;
        !           501:                        }
        !           502:                        /* Link in place */
        !           503:                        opt_copy->m_next = m->m_next;
        !           504:                        m->m_next = opt_copy;
        !           505: 
        !           506:                        /* update size of header */
        !           507:                        clnp->cnf_hdr_len += opt_copy->m_len;
        !           508:                        hdrlen += opt_copy->m_len;
        !           509:                }
        !           510: 
        !           511:                if (hdrlen > CLNP_HDR_MAX) {
        !           512:                        error = EMSGSIZE;
        !           513:                        goto bad;
        !           514:                }
        !           515: 
        !           516:                /*
        !           517:                 *      Now set up the cache entry in the pcb
        !           518:                 */
        !           519:                if ((flags & CLNP_NOCACHE) == 0) {
        !           520:                        if (clcp->clc_hdr = m_copy(m, 0, (int)clnp->cnf_hdr_len)) {
        !           521:                                clcp->clc_dst  = *dst;
        !           522:                                clcp->clc_flags = flags;
        !           523:                                clcp->clc_options = isop->isop_options;
        !           524:                        }
        !           525:                }
        !           526:        }
        !           527:        /*
        !           528:         *      If small enough for interface, send directly
        !           529:         *      Fill in segmentation part of hdr if using the full protocol
        !           530:         */
        !           531:        total_len = clnp->cnf_hdr_len + datalen;
        !           532:        if (clnp->cnf_type & CNF_SEG_OK) {
        !           533:                struct clnp_segment     seg_part;               /* segment part of hdr */
        !           534:                seg_part.cng_id = htons(clnp_id++);
        !           535:                seg_part.cng_off = htons(0);
        !           536:                seg_part.cng_tot_len = htons(total_len);
        !           537:                (void) bcopy((caddr_t)&seg_part, (caddr_t) clnp + clcp->clc_segoff, 
        !           538:                        sizeof(seg_part));
        !           539:        }
        !           540:        if (total_len <= SN_MTU(clcp->clc_ifp, clcp->clc_rt)) {
        !           541:                HTOC(clnp->cnf_seglen_msb, clnp->cnf_seglen_lsb, total_len);
        !           542:                m->m_pkthdr.len = total_len;
        !           543:                /*
        !           544:                 *      Compute clnp checksum (on header only)
        !           545:                 */
        !           546:                if (flags & CLNP_NO_CKSUM) {
        !           547:                        HTOC(clnp->cnf_cksum_msb, clnp->cnf_cksum_lsb, 0);
        !           548:                } else {
        !           549:                        iso_gen_csum(m, CLNP_CKSUM_OFF, (int)clnp->cnf_hdr_len);
        !           550:                }
        !           551: 
        !           552:                IFDEBUG(D_DUMPOUT)
        !           553:                        struct mbuf *mdump = m;
        !           554:                        printf("clnp_output: sending dg:\n");
        !           555:                        while (mdump != NULL) {
        !           556:                                dump_buf(mtod(mdump, caddr_t), mdump->m_len);
        !           557:                                mdump = mdump->m_next;
        !           558:                        }
        !           559:                ENDDEBUG
        !           560: 
        !           561:                error = SN_OUTPUT(clcp, m);
        !           562:                goto done;
        !           563:        } else {
        !           564:                /*
        !           565:                 * Too large for interface; fragment if possible.
        !           566:                 */
        !           567:                error = clnp_fragment(clcp->clc_ifp, m, clcp->clc_firsthop,
        !           568:                                                        total_len, clcp->clc_segoff, flags, clcp->clc_rt);
        !           569:                goto done;
        !           570:        }
        !           571: bad:
        !           572:        m_freem(m);
        !           573: done:
        !           574:        if (error) {
        !           575:                clnp_stat.cns_sent--;
        !           576:                clnp_stat.cns_odropped++;
        !           577:        }
        !           578:        return (error);
        !           579: }
        !           580: 
        !           581: int clnp_ctloutput()
        !           582: {
        !           583: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.