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