Annotation of XNU/bsd/netat/ddp_proto.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
                      3:  *
                      4:  * @APPLE_LICENSE_HEADER_START@
                      5:  * 
                      6:  * The contents of this file constitute Original Code as defined in and
                      7:  * are subject to the Apple Public Source License Version 1.1 (the
                      8:  * "License").  You may not use this file except in compliance with the
                      9:  * License.  Please obtain a copy of the License at
                     10:  * http://www.apple.com/publicsource and read it before using this file.
                     11:  * 
                     12:  * This Original Code and all software distributed under the License are
                     13:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
                     14:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
                     15:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
                     16:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
                     17:  * License for the specific language governing rights and limitations
                     18:  * under the License.
                     19:  * 
                     20:  * @APPLE_LICENSE_HEADER_END@
                     21:  */
                     22: /*
                     23:  *     Copyright (c) 1988, 1989, 1997, 1998 Apple Computer, Inc. 
                     24:  *
                     25:  *   Modified for MP, 1996 by Tuyen Nguyen
                     26:  *   Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
                     27:  */
                     28: 
                     29: /* ddp_proto.c: 2.0, 1.23; 10/18/93; Apple Computer, Inc. */
                     30: 
                     31: #include <sys/errno.h>
                     32: #include <sys/types.h>
                     33: #include <sys/param.h>
                     34: #include <machine/spl.h>
                     35: #include <sys/systm.h>
                     36: #include <sys/kernel.h>
                     37: #include <sys/proc.h>
                     38: #include <sys/filedesc.h>
                     39: #include <sys/fcntl.h>
                     40: #include <sys/mbuf.h>
                     41: #include <sys/ioctl.h>
                     42: #include <sys/malloc.h>
                     43: #include <sys/socket.h>
                     44: #include <sys/socketvar.h>
                     45: #include <sys/buf.h>
                     46: 
                     47: #include <net/if.h>
                     48: 
                     49: #include <netat/sysglue.h>
                     50: #include <netat/appletalk.h>
                     51: #include <netat/at_var.h>
                     52: #include <netat/ddp.h>
                     53: #include <netat/zip.h>
                     54: #include <netat/at_pcb.h>
                     55: #include <netat/asp.h>
                     56: #include <netat/atp.h>
                     57: #include <netat/debug.h>
                     58: #include <netat/adsp.h>
                     59: #include <netat/adsp_internal.h>
                     60: 
                     61: extern atlock_t ddpall_lock;
                     62: extern atlock_t ddpinp_lock;
                     63: 
                     64: extern struct atpcb ddp_head;
                     65: extern gref_t *atp_inputQ[];
                     66: extern struct atp_state *atp_used_list;
                     67: extern asp_scb_t *asp_scbQ[];
                     68: extern asp_scb_t *scb_used_list;
                     69: extern CCB *adsp_inputQ[];
                     70: extern CCB *ccb_used_list;
                     71: 
                     72: void ddp_putmsg(gref, mp)
                     73:        gref_t *gref;
                     74:        gbuf_t *mp;
                     75: {
                     76:        u_char socket;
                     77:        register ioc_t  *iocbp;
                     78:        register int    error;
                     79:        at_ddp_t *ddp;
                     80: 
                     81:        switch(gbuf_type(mp)) {
                     82:        case MSG_DATA :
                     83:                /* If this message is going out on a socket that's not bound, 
                     84:                 * nail it.
                     85:                 */
                     86:                ddp = (at_ddp_t *)gbuf_rptr(mp);
                     87:                if ((ddp->type == DDP_ATP) || (ddp->type == DDP_ADSP)) {
                     88:                        if ((gref == 0) || (gref->lport == 0)) {
                     89:                                int src_addr_included = 
                     90:                                  ((ddp->type==DDP_ATP) && ddp->src_node)? 1 : 0;
                     91:                                (void)ddp_output(&mp, ddp->src_socket, 
                     92:                                                 src_addr_included);
                     93:                                return;
                     94:                        }
                     95:                }
                     96: 
                     97:                if (gref && (gref->lport == 0)) {
                     98:                        gbuf_freel(mp);
                     99:                        atalk_notify(gref, ENOTCONN);
                    100:                        return;
                    101:                }
                    102:                if ((error = ddp_output(&mp, gref->lport, 0)) != 0) {
                    103:                        if (gref)
                    104:                                atalk_notify(gref, error);
                    105:                }
                    106:                return;
                    107: 
                    108:        case MSG_IOCTL :
                    109:                iocbp = (ioc_t *)gbuf_rptr(mp);
                    110:                if (DDP_IOC_MYIOCTL(iocbp->ioc_cmd)) {
                    111:                        switch(iocbp->ioc_cmd) {
                    112:                        case DDP_IOC_GET_CFG :
                    113:                          /* *** to be replaced with DDP_GETSOCKNAME sockopt *** */
                    114: #ifdef APPLETALK_DEBUG
                    115:                                kprintf("ddp_putmsg: DDP_IOC_GET_CFG\n");
                    116: #endif
                    117:                                if (gbuf_cont(mp))
                    118:                                        gbuf_freem(gbuf_cont(mp));
                    119:                                if ((gbuf_cont(mp) = 
                    120:                                     gbuf_alloc(sizeof(at_inet_t),
                    121:                                                PRI_MED)) == NULL) {
                    122:                                        ioc_ack(ENOBUFS, mp, gref);
                    123:                                        break;
                    124:                                }
                    125:                                {
                    126:                                /* *** was ddp_get_cfg() *** */
                    127:                                  ddp_addr_t *cfgp = 
                    128:                                    (ddp_addr_t *)gbuf_rptr(gbuf_cont(mp));
                    129:                                  cfgp->inet.net = gref->laddr.s_net;
                    130:                                  cfgp->inet.node = gref->laddr.s_node;
                    131:                                  cfgp->inet.socket = gref->lport;
                    132:                                  cfgp->ddptype = gref->ddptype;
                    133:                                }
                    134:                                gbuf_wset(gbuf_cont(mp), sizeof(ddp_addr_t));
                    135:                                iocbp->ioc_count = sizeof(ddp_addr_t);
                    136:                                ioc_ack(0, mp, gref);
                    137:                                break;
                    138:                        case DDP_IOC_GET_STATS :
                    139: #ifdef APPLETALK_DEBUG
                    140:                                kprintf("ddp_putmsg: DDP_IOC_GET_STATS\n");
                    141: #endif
                    142:                                if (gbuf_cont(mp))
                    143:                                        gbuf_freem(gbuf_cont(mp));
                    144:                                if ((gbuf_cont(mp) = gbuf_alloc(sizeof(at_ddp_stats_t),
                    145:                                        PRI_MED)) == NULL) {
                    146:                                        ioc_ack(ENOBUFS, mp, gref);
                    147:                                        break;
                    148:                                }
                    149:                                ddp_get_stats(
                    150:                                        (at_ddp_stats_t *)gbuf_rptr(gbuf_cont(mp)));
                    151:                                gbuf_wset(gbuf_cont(mp),sizeof(at_ddp_stats_t));
                    152:                                iocbp->ioc_count = sizeof(at_ddp_stats_t);
                    153:                                ioc_ack(0, mp, gref);
                    154:                                break;
                    155:                        }
                    156:                } else {
                    157:                        /* Unknown ioctl */
                    158:                        ioc_ack(EINVAL, mp, gref);
                    159:                }
                    160:                break;
                    161:        default :
                    162: #ifdef APPLETALK_DEBUG
                    163:                kprintf("unexpected message type in ddp_putmsg: %d/n", 
                    164:                        gbuf_type(mp));
                    165: #endif
                    166:                gbuf_freem(mp);
                    167:                break;
                    168:        }
                    169:        return;
                    170: } /* ddp_putmsg */
                    171: 
                    172: gbuf_t  *ddp_compress_msg(mp)
                    173: register gbuf_t        *mp;
                    174: {
                    175:         register gbuf_t   *tmp;
                    176: 
                    177:         while (gbuf_len(mp) == 0) {
                    178:                 tmp = mp;
                    179:                 mp = gbuf_cont(mp);
                    180:                 gbuf_freeb(tmp);
                    181: 
                    182:                if (mp == NULL)
                    183:                        break;
                    184:        }
                    185:        return (mp);
                    186: }
                    187: 
                    188: int
                    189: list_pids(pids, max_size)
                    190:      int pids[];
                    191:      int max_size;
                    192: {
                    193:        int 
                    194:          s,
                    195:          i = 0, 
                    196:          k,
                    197:          *debugP = &pids[i],
                    198:          space = max_size;
                    199: 
                    200:        asp_scb_t *scb;
                    201:        struct atp_state *atp;
                    202:        gref_t *gref;
                    203:        CCB *sp;
                    204:        
                    205: #ifdef NOT_YET
                    206: /* *** This doesn't work because the socket being used to decide whether
                    207:        AppleTalk can be terminated prevents it from being terminated. *** */
                    208: 
                    209:        for (gref = ddp_head.atpcb_next; gref != &ddp_head;
                    210:               gref = gref->atpcb_next) {
                    211:                pids[i++] = gref->pid;
                    212:                space--;
                    213:        }
                    214: #endif
                    215:        while (debugP != &pids[i]) {
                    216:                dPrintf(D_M_DDP,D_L_TRACE, ("ddp pid=%d\n", *debugP));
                    217:                debugP++;
                    218:        }
                    219: 
                    220:        /* originally from asp_stop() */
                    221:        ATDISABLE(s, aspall_lock);
                    222:        for (scb = scb_used_list; scb && space; scb = scb->next_scb) {
                    223:                pids[i++] = scb->pid;
                    224:                space--;
                    225:        }
                    226:        for (k=0; k < 256 && space ; k++) {
                    227:            if ((scb = asp_scbQ[k]))
                    228:                do {
                    229:                        pids[i++] = scb->pid;
                    230:                        space--;
                    231:                } while (space && (scb = scb->next_scb) != 0);
                    232:        }
                    233:        ATENABLE(s, aspall_lock);
                    234:        while (debugP != &pids[i]) {
                    235:                dPrintf(D_M_ASP, D_L_TRACE, ("asp pid=%d\n", *debugP));
                    236:                debugP++;
                    237:        }
                    238: 
                    239:        /* originally from atp_stop */
                    240:        ATDISABLE(s, atpall_lock);
                    241:        for (atp = atp_used_list; atp && space; atp = atp->atp_trans_waiting) {
                    242:                pids[i++] = atp->atp_pid;
                    243:                space--;
                    244:        }
                    245:        for (k=0; k < 256 && space; k++) {
                    246:          if ((gref = atp_inputQ[k]) && (gref != (gref_t *)1)) {
                    247:                atp = (struct atp_state *)gref->info;   
                    248:                if (!atp->dflag) {
                    249:                  pids[i++] = atp->atp_pid;
                    250:                  space--;
                    251:                }
                    252:          }
                    253:        }
                    254:        ATENABLE(s, atpall_lock);
                    255:        while (debugP != &pids[i]) {
                    256:                dPrintf(D_M_ATP, D_L_TRACE, ("atp pid=%d\n", *debugP));
                    257:                debugP++;
                    258:        }
                    259: 
                    260:        /* originally from adsp_stop() */
                    261:        ATDISABLE(s, adspall_lock);
                    262:        for (sp = ccb_used_list; sp && space ; sp = sp->otccbLink) {
                    263:                pids[i++] = sp->pid;
                    264:                space--;
                    265:        }
                    266:        for (k=0; k < 256 && space ; k++) {
                    267:            if ((sp = adsp_inputQ[k]))
                    268:                do {
                    269:                pids[i++] = sp->pid;
                    270:                space--;
                    271:                } while ((sp = sp->otccbLink) != 0);
                    272:        }
                    273:        ATENABLE(s, adspall_lock);
                    274: 
                    275:        while (debugP != &pids[i]) {
                    276:                dPrintf(D_M_ADSP, D_L_TRACE, ("adsp pid=%d\n", *debugP));
                    277:                debugP++;
                    278:        }
                    279: 
                    280:        return(i);
                    281: }

unix.superglobalmegacorp.com

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