Annotation of XNU/bsd/netat/aurp_tickle.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) 1996 Apple Computer, Inc. 
                     24:  *
                     25:  *             Created April 8, 1996 by Tuyen Nguyen
                     26:  *   Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
                     27:  *
                     28:  *     File: tickle.c
                     29:  */
                     30: #include <sys/errno.h>
                     31: #include <sys/types.h>
                     32: #include <sys/param.h>
                     33: #include <machine/spl.h>
                     34: #include <sys/systm.h>
                     35: #include <sys/kernel.h>
                     36: #include <sys/proc.h>
                     37: #include <sys/filedesc.h>
                     38: #include <sys/fcntl.h>
                     39: #include <sys/mbuf.h>
                     40: #include <sys/socket.h>
                     41: #include <sys/socketvar.h>
                     42: #include <net/if.h>
                     43: 
                     44: #include <netat/sysglue.h>
                     45: #include <netat/appletalk.h>
                     46: #include <netat/at_var.h>
                     47: #include <netat/routing_tables.h>
                     48: #include <netat/at_pcb.h>
                     49: #include <netat/aurp.h>
                     50: #include <netat/debug.h>
                     51: 
                     52: /* */
                     53: void AURPsndTickle(state)
                     54:        aurp_state_t *state;
                     55: {
                     56:        int msize;
                     57:        gbuf_t *m;
                     58:        aurp_hdr_t *hdrp;
                     59: 
                     60:        if (state->rcv_state == AURPSTATE_Unconnected)
                     61:                return;
                     62: 
                     63:        /* stop trying if the retry count exceeds the maximum retry value */
                     64:        if (++state->tickle_retry > AURP_MaxTickleRetry) {
                     65:                dPrintf(D_M_AURP, D_L_WARNING,
                     66:                        ("AURPsndTickle: no response, %d\n", state->rem_node));
                     67:                /*
                     68:                 * the tunnel peer seems to have disappeared, update state info
                     69:                 */
                     70:                state->snd_state = AURPSTATE_Unconnected;
                     71:                state->rcv_state = AURPSTATE_Unconnected;
                     72:                state->tickle_retry = 0;
                     73:                AURPcleanup(state);
                     74: 
                     75:                /* purge all routes associated with the tunnel peer */
                     76:                AURPpurgeri(state->rem_node);
                     77:                return;
                     78:        }
                     79: 
                     80:   if (state->tickle_retry > 1) {
                     81:        msize = sizeof(aurp_hdr_t);
                     82:        if ((m = (gbuf_t *)gbuf_alloc(msize, PRI_MED)) != 0) {
                     83:                gbuf_wset(m,msize);
                     84: 
                     85:                /* construct the tickle packet */
                     86:                hdrp = (aurp_hdr_t *)gbuf_rptr(m);
                     87:                hdrp->connection_id = state->rcv_connection_id;
                     88:                hdrp->sequence_number = 0;
                     89:                hdrp->command_code = AURPCMD_Tickle;
                     90:                hdrp->flags = 0;
                     91: 
                     92:                /* send the packet */
                     93:                AURPsend(m, AUD_AURP, state->rem_node);
                     94:        }
                     95:   }
                     96: 
                     97:        /* start the retry timer */
                     98:        timeout(AURPsndTickle, state, AURP_TickleRetryInterval*HZ);
                     99: }
                    100: 
                    101: /* */
                    102: void AURPrcvTickle(state, m)
                    103:        aurp_state_t *state;
                    104:        gbuf_t *m;
                    105: {
                    106:        aurp_hdr_t *hdrp = (aurp_hdr_t *)gbuf_rptr(m);
                    107: 
                    108:        /* make sure we're in a valid state to accept it */
                    109:        if (state->snd_state == AURPSTATE_Unconnected) {
                    110:                dPrintf(D_M_AURP, D_L_WARNING,
                    111:                        ("AURPrcvTickle: unexpected request\n"));
                    112:                gbuf_freem(m);
                    113:                return;
                    114:        }
                    115: 
                    116:        /* construct the tickle ack packet */
                    117:        gbuf_wset(m,sizeof(aurp_hdr_t));
                    118:        hdrp->command_code = AURPCMD_TickleAck;
                    119:        hdrp->flags = 0;
                    120: 
                    121:        /* send the packet */
                    122:        AURPsend(m, AUD_AURP, state->rem_node);
                    123: }
                    124: 
                    125: /* */
                    126: void AURPrcvTickleAck(state, m)
                    127:        aurp_state_t *state;
                    128:        gbuf_t *m;
                    129: {
                    130:        aurp_hdr_t *hdrp = (aurp_hdr_t *)gbuf_rptr(m);
                    131: 
                    132:        /* make sure we're in a valid state to accept it */
                    133:        if (state->rcv_state == AURPSTATE_Unconnected) {
                    134:                dPrintf(D_M_AURP, D_L_WARNING,
                    135:                        ("AURPrcvTickleAck: unexpected response\n"));
                    136:                gbuf_freem(m);
                    137:                return;
                    138:        }
                    139: 
                    140:        /* check for the correct connection id */
                    141:        if (hdrp->connection_id != state->rcv_connection_id) {
                    142:                dPrintf(D_M_AURP, D_L_WARNING,
                    143:                        ("AURPrcvTickleAck: invalid connection id, r=%d, m=%d\n",
                    144:                        hdrp->connection_id, state->rcv_connection_id));
                    145:                gbuf_freem(m);
                    146:                return;
                    147:        }
                    148:        gbuf_freem(m);
                    149: 
                    150:        /* update state info */
                    151:        state->tickle_retry = 0;
                    152: }

unix.superglobalmegacorp.com

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