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