Annotation of kernel/bsd/netiso/clnp_raw.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_raw.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: #include <sys/malloc.h>
        !            96: 
        !            97: #include <net/if.h>
        !            98: #include <net/route.h>
        !            99: #include <net/raw_cb.h>
        !           100: 
        !           101: #include <netiso/iso.h>
        !           102: #include <netiso/iso_pcb.h>
        !           103: #include <netiso/clnp.h>
        !           104: #include <netiso/clnp_stat.h>
        !           105: #include <netiso/argo_debug.h>
        !           106: 
        !           107: #include <netiso/tp_user.h>            /* XXX -- defines SOL_NETWORK */
        !           108: 
        !           109: struct sockproto       rclnp_proto     = { PF_ISO, 0 };
        !           110: /*
        !           111:  * FUNCTION:           rclnp_input
        !           112:  *
        !           113:  * PURPOSE:                    Setup generic address an protocol structures for
        !           114:  *                                     raw input routine, then pass them along with the
        !           115:  *                                     mbuf chain.
        !           116:  *
        !           117:  * RETURNS:                    none
        !           118:  *
        !           119:  * SIDE EFFECTS:       
        !           120:  *
        !           121:  * NOTES:                      The protocol field of rclnp_proto is set to zero indicating
        !           122:  *                                     no protocol.
        !           123:  */
        !           124: rclnp_input(m, src, dst, hdrlen)
        !           125: struct mbuf            *m;             /* ptr to packet */
        !           126: struct sockaddr_iso    *src;   /* ptr to src address */
        !           127: struct sockaddr_iso    *dst;   /* ptr to dest address */
        !           128: int                                    hdrlen; /* length (in bytes) of clnp header */
        !           129: {
        !           130: #ifdef TROLL
        !           131:        if (trollctl.tr_ops & TR_CHUCK) {
        !           132:                m_freem(m);
        !           133:                return;
        !           134:        }
        !           135: #endif /* TROLL */
        !           136: 
        !           137:        raw_input(m, &rclnp_proto, (struct sockaddr *)src, (struct sockaddr *)dst);
        !           138: }
        !           139: 
        !           140: /*
        !           141:  * FUNCTION:           rclnp_output
        !           142:  *
        !           143:  * PURPOSE:                    Prepare to send a raw clnp packet. Setup src and dest
        !           144:  *                                     addresses, count the number of bytes to send, and
        !           145:  *                                     call clnp_output.
        !           146:  *
        !           147:  * RETURNS:                    success - 0
        !           148:  *                                     failure - an appropriate error code
        !           149:  *
        !           150:  * SIDE EFFECTS:       
        !           151:  *
        !           152:  * NOTES:                      
        !           153:  */
        !           154: rclnp_output(m0, so)
        !           155: struct mbuf            *m0;            /* packet to send */
        !           156: struct socket  *so;    /* socket to send from */
        !           157: {
        !           158:        register struct mbuf    *m;                     /* used to scan a chain */
        !           159:        int                                             len = 0;        /* store length of chain here */
        !           160:        struct rawisopcb                *rp = sotorawisopcb(so); /* ptr to raw cb */
        !           161:        int                                             error;          /* return value of function */
        !           162:        int                                             flags;          /* flags for clnp_output */
        !           163: 
        !           164:        if (0 == (m0->m_flags & M_PKTHDR))
        !           165:                return (EINVAL);
        !           166:        /*
        !           167:         *      Set up src address. If user has bound socket to an address, use it.
        !           168:         *      Otherwise, do not specify src (clnp_output will fill it in).
        !           169:         */
        !           170:        if (rp->risop_rcb.rcb_laddr) {
        !           171:                if (rp->risop_isop.isop_sladdr.siso_family != AF_ISO) {
        !           172: bad:
        !           173:                        m_freem(m0);
        !           174:                        return(EAFNOSUPPORT);
        !           175:                }
        !           176:        }
        !           177:        /* set up dest address */
        !           178:        if (rp->risop_rcb.rcb_faddr == 0)
        !           179:                goto bad;
        !           180:        rp->risop_isop.isop_sfaddr =
        !           181:                                *(struct sockaddr_iso *)rp->risop_rcb.rcb_faddr;
        !           182:        rp->risop_isop.isop_faddr = &rp->risop_isop.isop_sfaddr;
        !           183: 
        !           184:        /* get flags and ship it off */
        !           185:        flags = rp->risop_flags & CLNP_VFLAGS;
        !           186: 
        !           187:        error = clnp_output(m0, &rp->risop_isop, m0->m_pkthdr.len,
        !           188:                                                                                                flags|CLNP_NOCACHE);
        !           189: 
        !           190:        return (error);
        !           191: }
        !           192: 
        !           193: /*
        !           194:  * FUNCTION:           rclnp_ctloutput
        !           195:  *
        !           196:  * PURPOSE:                    Raw clnp socket option processing
        !           197:  *                                     All options are stored inside an mbuf. 
        !           198:  *
        !           199:  * RETURNS:                    success - 0
        !           200:  *                                     failure - unix error code
        !           201:  *
        !           202:  * SIDE EFFECTS:       If the options mbuf does not exist, it the mbuf passed
        !           203:  *                                     is used.
        !           204:  *
        !           205:  * NOTES:                      
        !           206:  */
        !           207: rclnp_ctloutput(op, so, level, optname, m)
        !           208: int                            op;                             /* type of operation */
        !           209: struct socket  *so;                    /* ptr to socket */
        !           210: int                    level;                  /* level of option */
        !           211: int                            optname;                /* name of option */
        !           212: struct mbuf            **m;                    /* ptr to ptr to option data */
        !           213: {
        !           214:        int                                             error = 0;
        !           215:        register struct rawisopcb       *rp = sotorawisopcb(so);/* raw cb ptr */
        !           216: 
        !           217:        IFDEBUG(D_CTLOUTPUT)
        !           218:                printf("rclnp_ctloutput: op = x%x, level = x%x, name = x%x\n",
        !           219:                        op, level, optname);
        !           220:                if (*m != NULL) {
        !           221:                        printf("rclnp_ctloutput: %d bytes of mbuf data\n", (*m)->m_len);
        !           222:                        dump_buf(mtod((*m), caddr_t), (*m)->m_len);
        !           223:                }
        !           224:        ENDDEBUG
        !           225: 
        !           226: #ifdef SOL_NETWORK
        !           227:        if (level != SOL_NETWORK)
        !           228:                error = EINVAL;
        !           229:        else switch (op) {
        !           230: #else
        !           231:        switch (op) {
        !           232: #endif /* SOL_NETWORK */
        !           233:                case PRCO_SETOPT:
        !           234:                        switch (optname) {
        !           235:                                case CLNPOPT_FLAGS: {
        !           236:                                        u_short usr_flags;
        !           237:                                        /* 
        !           238:                                         *      Insure that the data passed has exactly one short in it 
        !           239:                                         */
        !           240:                                        if ((*m == NULL) || ((*m)->m_len != sizeof(short))) {
        !           241:                                                error = EINVAL;
        !           242:                                                break;
        !           243:                                        }
        !           244:                                         
        !           245:                                        /*
        !           246:                                         *      Don't allow invalid flags to be set
        !           247:                                         */
        !           248:                                        usr_flags = (*mtod((*m), short *));
        !           249: 
        !           250:                                        if ((usr_flags & (CLNP_VFLAGS)) != usr_flags) {
        !           251:                                                error = EINVAL;
        !           252:                                        } else
        !           253:                                                rp->risop_flags |= usr_flags;
        !           254: 
        !           255:                                        } break;
        !           256:                        
        !           257:                                case CLNPOPT_OPTS:
        !           258:                                        if (error = clnp_set_opts(&rp->risop_isop.isop_options, m))
        !           259:                                                break;
        !           260:                                        rp->risop_isop.isop_optindex = m_get(M_WAIT, MT_SOOPTS);
        !           261:                                        (void) clnp_opt_sanity(rp->risop_isop.isop_options, 
        !           262:                                                mtod(rp->risop_isop.isop_options, caddr_t),
        !           263:                                                rp->risop_isop.isop_options->m_len, 
        !           264:                                                mtod(rp->risop_isop.isop_optindex,
        !           265:                                                        struct clnp_optidx *));
        !           266:                                        break;
        !           267:                        } 
        !           268:                        break;
        !           269: 
        !           270:                case PRCO_GETOPT:
        !           271: #ifdef notdef
        !           272:                        /* commented out to keep hi C quiet */
        !           273:                        switch (optname) {
        !           274:                                default:
        !           275:                                        error = EINVAL;
        !           276:                                        break;
        !           277:                        }
        !           278: #endif /* notdef */
        !           279:                        break;
        !           280:                default:
        !           281:                        error = EINVAL;
        !           282:                        break;
        !           283:        }
        !           284:        if (op == PRCO_SETOPT) {
        !           285:                /* note: m_freem does not barf is *m is NULL */
        !           286:                m_freem(*m);
        !           287:                *m = NULL;
        !           288:        }
        !           289:        
        !           290:        return error;
        !           291: }
        !           292: 
        !           293: /*ARGSUSED*/
        !           294: clnp_usrreq(so, req, m, nam, control)
        !           295:        register struct socket *so;
        !           296:        int req;
        !           297:        struct mbuf *m, *nam, *control;
        !           298: {
        !           299:        register int error = 0;
        !           300:        register struct rawisopcb *rp = sotorawisopcb(so);
        !           301: 
        !           302:        rp = sotorawisopcb(so);
        !           303:        switch (req) {
        !           304: 
        !           305:        case PRU_ATTACH:
        !           306:                if (rp)
        !           307:                        panic("rip_attach");
        !           308:                MALLOC(rp, struct rawisopcb *, sizeof *rp, M_PCB, M_WAITOK);
        !           309:                if (rp == 0)
        !           310:                        return (ENOBUFS);
        !           311:                bzero((caddr_t)rp, sizeof *rp);
        !           312:                so->so_pcb = (caddr_t)rp;
        !           313:                break;
        !           314: 
        !           315:        case PRU_DETACH:
        !           316:                if (rp == 0)
        !           317:                        panic("rip_detach");
        !           318:                if (rp->risop_isop.isop_options)
        !           319:                        m_freem(rp->risop_isop.isop_options);
        !           320:                if (rp->risop_isop.isop_route.ro_rt)
        !           321:                        RTFREE(rp->risop_isop.isop_route.ro_rt);
        !           322:                if (rp->risop_rcb.rcb_laddr)
        !           323:                        rp->risop_rcb.rcb_laddr = 0;
        !           324:                /* free clnp cached hdr if necessary */
        !           325:                if (rp->risop_isop.isop_clnpcache != NULL) {
        !           326:                        struct clnp_cache *clcp = 
        !           327:                                mtod(rp->risop_isop.isop_clnpcache, struct clnp_cache *);
        !           328:                        if (clcp->clc_hdr != NULL) {
        !           329:                                m_free(clcp->clc_hdr);
        !           330:                        }
        !           331:                        m_free(rp->risop_isop.isop_clnpcache);
        !           332:                }
        !           333:                if (rp->risop_isop.isop_optindex != NULL)
        !           334:                        m_free(rp->risop_isop.isop_optindex);
        !           335: 
        !           336:                break;
        !           337: 
        !           338:        case PRU_BIND:
        !           339:            {
        !           340:                struct sockaddr_iso *addr = mtod(nam, struct sockaddr_iso *);
        !           341: 
        !           342:                if (nam->m_len != sizeof(*addr))
        !           343:                        return (EINVAL);
        !           344:                if ((ifnet == 0) ||
        !           345:                    (addr->siso_family != AF_ISO) ||
        !           346:                    (addr->siso_addr.isoa_len  &&
        !           347:                     ifa_ifwithaddr((struct sockaddr *)addr) == 0))
        !           348:                        return (EADDRNOTAVAIL);
        !           349:                rp->risop_isop.isop_sladdr = *addr;
        !           350:                rp->risop_rcb.rcb_laddr = (struct sockaddr *)
        !           351:                        (rp->risop_isop.isop_laddr = &rp->risop_isop.isop_sladdr);
        !           352:                return (0);
        !           353:            }
        !           354:        case PRU_CONNECT:
        !           355:            {
        !           356:                struct sockaddr_iso *addr = mtod(nam, struct sockaddr_iso *);
        !           357: 
        !           358:                if ((nam->m_len > sizeof(*addr)) || (addr->siso_len > sizeof(*addr)))
        !           359:                        return (EINVAL);
        !           360:                if (ifnet == 0)
        !           361:                        return (EADDRNOTAVAIL);
        !           362:                if (addr->siso_family != AF_ISO)
        !           363:                rp->risop_isop.isop_sfaddr = *addr;
        !           364:                rp->risop_rcb.rcb_faddr = (struct sockaddr *)
        !           365:                        (rp->risop_isop.isop_faddr = &rp->risop_isop.isop_sfaddr);
        !           366:                soisconnected(so);
        !           367:                return (0);
        !           368:            }
        !           369:        }
        !           370:        error =  raw_usrreq(so, req, m, nam, control);
        !           371: 
        !           372:        if (error && req == PRU_ATTACH && so->so_pcb)
        !           373:                free((caddr_t)rp, M_PCB);
        !           374:        return (error);
        !           375: }

unix.superglobalmegacorp.com

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