]> git.saurik.com Git - apple/xnu.git/blob - bsd/netat/aurp_tickle.c
967b9b3b59312194bcd50276991582105e495f64
[apple/xnu.git] / bsd / netat / aurp_tickle.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /*
24 * Copyright (c) 1996 Apple Computer, Inc.
25 *
26 * Created April 8, 1996 by Tuyen Nguyen
27 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
28 *
29 * File: tickle.c
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/socket.h>
42 #include <sys/socketvar.h>
43 #include <net/if.h>
44
45 #include <netat/sysglue.h>
46 #include <netat/appletalk.h>
47 #include <netat/at_var.h>
48 #include <netat/routing_tables.h>
49 #include <netat/at_pcb.h>
50 #include <netat/aurp.h>
51 #include <netat/debug.h>
52
53 /* */
54 void AURPsndTickle(state)
55 aurp_state_t *state;
56 {
57 int msize;
58 gbuf_t *m;
59 aurp_hdr_t *hdrp;
60
61 atalk_lock();
62
63 if (state->rcv_state == AURPSTATE_Unconnected) {
64 atalk_unlock();
65 return;
66 }
67 /* stop trying if the retry count exceeds the maximum retry value */
68 if (++state->tickle_retry > AURP_MaxTickleRetry) {
69 dPrintf(D_M_AURP, D_L_WARNING,
70 ("AURPsndTickle: no response, %d\n", state->rem_node));
71 /*
72 * the tunnel peer seems to have disappeared, update state info
73 */
74 state->snd_state = AURPSTATE_Unconnected;
75 state->rcv_state = AURPSTATE_Unconnected;
76 state->tickle_retry = 0;
77 AURPcleanup(state);
78
79 /* purge all routes associated with the tunnel peer */
80 AURPpurgeri(state->rem_node);
81 atalk_unlock();
82 return;
83 }
84
85 if (state->tickle_retry > 1) {
86 msize = sizeof(aurp_hdr_t);
87 if ((m = (gbuf_t *)gbuf_alloc(msize, PRI_MED)) != 0) {
88 gbuf_wset(m,msize);
89
90 /* construct the tickle packet */
91 hdrp = (aurp_hdr_t *)gbuf_rptr(m);
92 hdrp->connection_id = state->rcv_connection_id;
93 hdrp->sequence_number = 0;
94 hdrp->command_code = AURPCMD_Tickle;
95 hdrp->flags = 0;
96
97 /* send the packet */
98 AURPsend(m, AUD_AURP, state->rem_node);
99 }
100 }
101
102 /* start the retry timer */
103 timeout(AURPsndTickle, state, AURP_TickleRetryInterval*HZ);
104
105 atalk_unlock();
106 }
107
108 /* */
109 void AURPrcvTickle(state, m)
110 aurp_state_t *state;
111 gbuf_t *m;
112 {
113 aurp_hdr_t *hdrp = (aurp_hdr_t *)gbuf_rptr(m);
114
115 /* make sure we're in a valid state to accept it */
116 if (state->snd_state == AURPSTATE_Unconnected) {
117 dPrintf(D_M_AURP, D_L_WARNING,
118 ("AURPrcvTickle: unexpected request\n"));
119 gbuf_freem(m);
120 return;
121 }
122
123 /* construct the tickle ack packet */
124 gbuf_wset(m,sizeof(aurp_hdr_t));
125 hdrp->command_code = AURPCMD_TickleAck;
126 hdrp->flags = 0;
127
128 /* send the packet */
129 AURPsend(m, AUD_AURP, state->rem_node);
130 }
131
132 /* */
133 void AURPrcvTickleAck(state, m)
134 aurp_state_t *state;
135 gbuf_t *m;
136 {
137 aurp_hdr_t *hdrp = (aurp_hdr_t *)gbuf_rptr(m);
138
139 /* make sure we're in a valid state to accept it */
140 if (state->rcv_state == AURPSTATE_Unconnected) {
141 dPrintf(D_M_AURP, D_L_WARNING,
142 ("AURPrcvTickleAck: unexpected response\n"));
143 gbuf_freem(m);
144 return;
145 }
146
147 /* check for the correct connection id */
148 if (hdrp->connection_id != state->rcv_connection_id) {
149 dPrintf(D_M_AURP, D_L_WARNING,
150 ("AURPrcvTickleAck: invalid connection id, r=%d, m=%d\n",
151 hdrp->connection_id, state->rcv_connection_id));
152 gbuf_freem(m);
153 return;
154 }
155 gbuf_freem(m);
156
157 /* update state info */
158 state->tickle_retry = 0;
159 }