]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/netat/aurp_ri.c
xnu-792.24.17.tar.gz
[apple/xnu.git] / bsd / netat / aurp_ri.c
index c4f36f4a0e8ff4343acf337a31d093382b7a143e..44d8df2546f4040046bf0f657af0ac2dae586063 100644 (file)
@@ -1,29 +1,23 @@
 /*
  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
  *
- * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
+ * @APPLE_LICENSE_HEADER_START@
  * 
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. The rights granted to you under the License
- * may not be used to create, or enable the creation or redistribution of,
- * unlawful or unlicensed copies of an Apple operating system, or to
- * circumvent, violate, or enable the circumvention or violation of, any
- * terms of an Apple operating system software license agreement.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License").  You may not use this file except in compliance with the
+ * License.  Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
  * 
- * Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this file.
- * 
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
  * 
- * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
+ * @APPLE_LICENSE_HEADER_END@
  */
 /*
  *     Copyright (c) 1996 Apple Computer, Inc. 
@@ -33,9 +27,6 @@
  *
  *     File: ri.c
  */
-#ifdef AURP_SUPPORT
-
 #include <sys/errno.h>
 #include <sys/types.h>
 #include <sys/param.h>
@@ -161,12 +152,14 @@ void AURPsndRIRsp(state)
        gbuf_t *m;
        aurp_hdr_t *hdrp;
        short len = 0;
-       int msize = 0;
+       int s, msize = 0;
 
+       ATDISABLE(s, aurpgen_lock);
 
        /* make sure we're in a valid state to send RI response */
        if ((state->snd_state == AURPSTATE_Unconnected) ||
                (state->snd_state == AURPSTATE_WaitingForRIAck2)) {
+               ATENABLE(s, aurpgen_lock);
                return;
        }
 
@@ -174,6 +167,7 @@ void AURPsndRIRsp(state)
        state->snd_state = AURPSTATE_WaitingForRIAck1;
 
        if (state->rsp_m == 0) {
+               ATENABLE(s, aurpgen_lock);
                msize = sizeof(aurp_hdr_t);
                if ((m = (gbuf_t *)gbuf_alloc(msize+AURP_MaxPktSize, PRI_MED)) == 0) {
                        timeout(AURPsndRIRsp_locked, state, AURP_RetryInterval*HZ);
@@ -207,6 +201,8 @@ void AURPsndRIRsp(state)
        timeout(AURPsndRIRsp_locked, state, AURP_RetryInterval*HZ);
        state->snd_tmo = 1;
 
+       if (msize == 0)
+               ATENABLE(s, aurpgen_lock);
 
        /* send the packet */
        if (m) {
@@ -233,11 +229,13 @@ void AURPsndRIUpd(state)
        short len = 0;
        int s, msize = 0;
 
+       ATDISABLE(s, aurpgen_lock);
 
        /* make sure we're in a valid state to send update */
        if (state->snd_next_entry || (state->upd_m == 0) ||
                (state->snd_state == AURPSTATE_Unconnected) ||
                        (state->snd_state == AURPSTATE_WaitingForRIAck1)) {
+               ATENABLE(s, aurpgen_lock);
                return;
        }
 
@@ -245,6 +243,7 @@ void AURPsndRIUpd(state)
        state->snd_state = AURPSTATE_WaitingForRIAck2;
 
        if (state->snd_tmo == 0) {
+               ATENABLE(s, aurpgen_lock);
                msize = sizeof(aurp_hdr_t);
                m = state->upd_m;
                len = gbuf_len(m);
@@ -265,6 +264,8 @@ void AURPsndRIUpd(state)
        timeout(AURPsndRIUpd_locked, state, AURP_RetryInterval*HZ);
        state->snd_tmo = 1;
 
+       if (msize == 0)
+               ATENABLE(s, aurpgen_lock);
 
        /* send the packet */
        if (m) {
@@ -282,10 +283,12 @@ void AURPrcvRIReq(state, m)
        aurp_hdr_t *hdrp = (aurp_hdr_t *)gbuf_rptr(m);
        int s;
 
+       ATDISABLE(s, aurpgen_lock);
 
        /* make sure we're in a valid state to accept it */
        if ((state->snd_state == AURPSTATE_Unconnected) ||
                        (state->snd_state == AURPSTATE_WaitingForRIAck2)) {
+               ATENABLE(s, aurpgen_lock);
                dPrintf(D_M_AURP, D_L_WARNING, ("AURPrcvRIReq: unexpected request\n"));
                gbuf_freem(m);
                return;
@@ -293,6 +296,7 @@ void AURPrcvRIReq(state, m)
 
        /* check for the correct connection id */
        if (hdrp->connection_id != state->snd_connection_id) {
+               ATENABLE(s, aurpgen_lock);
                dPrintf(D_M_AURP, D_L_WARNING,
                        ("AURPrcvRIReq: invalid connection id, r=%d, m=%d\n",
                        hdrp->connection_id, state->snd_connection_id));
@@ -306,8 +310,10 @@ void AURPrcvRIReq(state, m)
                        gbuf_freem(state->rsp_m);
                        state->rsp_m = 0;
                }
+               ATENABLE(s, aurpgen_lock);
                AURPsndRIRsp(state);
-       } 
+       } else
+               ATENABLE(s, aurpgen_lock);
 
        gbuf_freem(m);
 }
@@ -318,10 +324,13 @@ void AURPrcvRIRsp(state, m)
        gbuf_t *m;
 {
        aurp_hdr_t *hdrp = (aurp_hdr_t *)gbuf_rptr(m);
+       int s;
 
+       ATDISABLE(s, aurpgen_lock);
 
        /* make sure we're in a valid state to accept it */
        if (state->rcv_state != AURPSTATE_WaitingForRIRsp) {
+               ATENABLE(s, aurpgen_lock);
                dPrintf(D_M_AURP, D_L_WARNING, ("AURPrcvRIRsp: unexpected response\n"));
                gbuf_freem(m);
                return;
@@ -329,6 +338,7 @@ void AURPrcvRIRsp(state, m)
 
        /* check for the correct connection id */
        if (hdrp->connection_id != state->rcv_connection_id) {
+               ATENABLE(s, aurpgen_lock);
                dPrintf(D_M_AURP, D_L_WARNING,
                        ("AURPrcvRIRsp: invalid connection id, r=%d, m=%d\n",
                        hdrp->connection_id, state->rcv_connection_id));
@@ -338,6 +348,7 @@ void AURPrcvRIRsp(state, m)
 
        /* check for the correct sequence number */
        if (hdrp->sequence_number != state->rcv_sequence_number) {
+               ATENABLE(s, aurpgen_lock);
                if ( ((state->rcv_sequence_number == AURP_FirstSeqNum) &&
                        (hdrp->sequence_number == AURP_LastSeqNum)) ||
                (hdrp->sequence_number == (state->rcv_sequence_number-1)) ) {
@@ -353,6 +364,7 @@ void AURPrcvRIRsp(state, m)
        gbuf_rinc(m,sizeof(*hdrp));
        if (hdrp->flags & AURPFLG_LAST)
                state->rcv_state = AURPSTATE_Connected;
+       ATENABLE(s, aurpgen_lock);
 
        dPrintf(D_M_AURP, D_L_INFO, ("AURPrcvRIRsp: len=%ld\n", gbuf_len(m)));
 
@@ -445,10 +457,12 @@ void AURPrcvRIAck(state, m)
        gbuf_t *dat_m;
        aurp_hdr_t *hdrp = (aurp_hdr_t *)gbuf_rptr(m);
        unsigned char snd_state;
+       int s;
        int flag;
 
        dPrintf(D_M_AURP, D_L_INFO, ("AURPrcvRIAck: state=%d\n",
                state->snd_state));
+       ATDISABLE(s, aurpgen_lock);
 
        /* make sure we're in a valid state to accept it */
        snd_state = state->snd_state;
@@ -478,6 +492,7 @@ void AURPrcvRIAck(state, m)
 
                /* update state info */
                state->snd_state = AURPSTATE_Connected;
+               ATENABLE(s, aurpgen_lock);
 
                if (state->snd_next_entry) /* more RI responses to send? */
                        AURPsndRIRsp(state);
@@ -487,7 +502,8 @@ void AURPrcvRIAck(state, m)
                        AURPsndZRsp(state, dat_m, flag);
                else if (dat_m)
                        gbuf_freem(dat_m);
-       } 
+       } else
+               ATENABLE(s, aurpgen_lock);
 
        gbuf_freem(m);
 }
@@ -815,14 +831,17 @@ void AURPrtupdate(entry, ev)
                                (!(state->snd_sui & AURPFLG_ND))) continue;
                if ((ev == AURPEV_NetDistChange) &&
                                (!(state->snd_sui & AURPFLG_NDC))) continue;
+               ATDISABLE(s, aurpgen_lock);
          if ((state->snd_state != AURPSTATE_Unconnected) &&
                        (state->snd_state != AURPSTATE_WaitingForRIAck2)) {
                if ((m = state->upd_m) == 0) {
                        /*
                         * we don't have the RI update buffer yet, allocate one
                         */
+                       ATENABLE(s, aurpgen_lock);
                        if ((m = (gbuf_t *)gbuf_alloc(msize+AURP_MaxPktSize, PRI_HI)) == 0)
                                continue;
+                       ATDISABLE(s, aurpgen_lock);
                        state->upd_m = m;
                        gbuf_rinc(m,msize);
                        gbuf_wset(m,0);
@@ -840,11 +859,11 @@ void AURPrtupdate(entry, ev)
                 * if the RI update buffer is full, send the RI update now
                 */
                if (gbuf_len(m) > (AURP_MaxPktSize-6)) {
+                       ATENABLE(s, aurpgen_lock);
                        AURPsndRIUpd(state);
                        continue;
                }
          }
+               ATENABLE(s, aurpgen_lock);
        }
 }
-
-#endif  /* AURP_SUPPORT */