3 * ===================================
4 * HARP | Host ATM Research Platform
5 * ===================================
8 * This Host ATM Research Platform ("HARP") file (the "Software") is
9 * made available by Network Computing Services, Inc. ("NetworkCS")
10 * "AS IS". NetworkCS does not provide maintenance, improvements or
11 * support of any kind.
13 * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14 * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15 * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16 * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17 * In no event shall NetworkCS be responsible for any damages, including
18 * but not limited to consequential damages, arising from or relating to
19 * any use of the Software or related support.
21 * Copyright 1994-1998 Network Computing Services, Inc.
23 * Copies of this Software may be made, however, the above copyright
24 * notice must be reproduced on all copies.
26 * @(#) $FreeBSD: src/usr.sbin/atm/scspd/scsp_if.c,v 1.3 1999/08/28 01:15:33 peter Exp $
32 * Server Cache Synchronization Protocol (SCSP) Support
33 * ----------------------------------------------------
35 * Interface to client server protocol
39 #include <sys/types.h>
40 #include <sys/param.h>
41 #include <sys/socket.h>
43 #include <netinet/in.h>
44 #include <netatm/port.h>
45 #include <netatm/queue.h>
46 #include <netatm/atm.h>
47 #include <netatm/atm_if.h>
48 #include <netatm/atm_sap.h>
49 #include <netatm/atm_sys.h>
50 #include <netatm/atm_ioctl.h>
65 __RCSID("@(#) $FreeBSD: src/usr.sbin/atm/scspd/scsp_if.c,v 1.3 1999/08/28 01:15:33 peter Exp $");
70 * SCSP client server interface FSM actions
72 #define SCSP_CIFSM_ACTION_CNT 11
73 int scsp_client_act_00
74 __P((Scsp_dcs *, Scsp_msg *, Scsp_if_msg *));
75 int scsp_client_act_01
76 __P((Scsp_dcs *, Scsp_msg *, Scsp_if_msg *));
77 int scsp_client_act_02
78 __P((Scsp_dcs *, Scsp_msg *, Scsp_if_msg *));
79 int scsp_client_act_03
80 __P((Scsp_dcs *, Scsp_msg *, Scsp_if_msg *));
81 int scsp_client_act_04
82 __P((Scsp_dcs *, Scsp_msg *, Scsp_if_msg *));
83 int scsp_client_act_05
84 __P((Scsp_dcs *, Scsp_msg *, Scsp_if_msg *));
85 int scsp_client_act_06
86 __P((Scsp_dcs *, Scsp_msg *, Scsp_if_msg *));
87 int scsp_client_act_07
88 __P((Scsp_dcs *, Scsp_msg *, Scsp_if_msg *));
89 int scsp_client_act_08
90 __P((Scsp_dcs *, Scsp_msg *, Scsp_if_msg *));
91 int scsp_client_act_09
92 __P((Scsp_dcs *, Scsp_msg *, Scsp_if_msg *));
93 int scsp_client_act_10
94 __P((Scsp_dcs *, Scsp_msg *, Scsp_if_msg *));
96 static int (*scsp_action_vector[SCSP_CIFSM_ACTION_CNT])() = {
112 * Client server interface FSM state table
114 static int client_state_table[SCSP_CIFSM_EVENT_CNT][SCSP_CIFSM_STATE_CNT] = {
116 { 1, 3, 3, 3 }, /* 0 */
117 { 2, 5, 5, 5 }, /* 1 */
118 { 0, 4, 0, 0 }, /* 2 */
119 { 0, 6, 6, 1 }, /* 3 */
120 { 1, 0, 7, 7 }, /* 4 */
121 { 7, 7, 7, 7 }, /* 5 */
122 { 1, 1, 8, 8 }, /* 6 */
123 { 0, 0, 10, 10 }, /* 7 */
124 { 0, 0, 1, 1 }, /* 8 */
125 { 0, 0, 9, 9 } /* 9 */
130 * SCSP client server interface finite state machine
133 * ssp pointer to server control block
134 * event the event which has occurred
135 * msg pointer to message from DCS, if there is one
136 * cmsg pointer to message from server, if there is one
140 * errno error encountered
144 scsp_cfsm(dcsp, event, msg, cmsg)
150 int action, rc, state;
153 * Select an action from the state table
155 state = dcsp->sd_client_state;
156 action = client_state_table[event][state];
157 if (scsp_trace_mode & SCSP_TRACE_CFSM) {
158 scsp_trace("Server I/F FSM: state=%d, event=%d, action=%d\n",
159 state, event, action);
161 if (action >= SCSP_CIFSM_ACTION_CNT || action <= 0) {
162 scsp_log(LOG_ERR, "Server I/F FSM--invalid action %d; state=%d, event=%d",
163 action, dcsp->sd_client_state, event);
168 * Perform the selected action
170 rc = scsp_action_vector[action](dcsp, msg, cmsg);
177 * SCSP client server interface finite state machine action 0
178 * Unexpected action -- log an error message
181 * dcsp pointer to DCS control block
182 * msg pointer to message from DCS (ignored)
183 * cmsg pointer to message from server (ignored)
186 * EOPNOTSUPP always returns EOPNOTSUPP
190 scsp_client_act_00(dcsp, msg, cmsg)
195 scsp_log(LOG_ERR, "Server I/F FSM error--unexpected action, state=%d",
196 dcsp->sd_client_state);
202 * SCSP client server interface finite state machine action 1
207 * dcsp pointer to DCS control block
208 * msg pointer to message from DCS
209 * cmsg pointer to message from server
216 scsp_client_act_01(dcsp, msg, cmsg)
226 * SCSP client server interface finite state machine action 2
228 * CA FSM went to Cache Summarize state--go to Summarize
231 * dcsp pointer to DCS control block
232 * msg pointer to message from DCS
233 * cmsg pointer to message from server
237 * else errno describing error
241 scsp_client_act_02(dcsp, msg, cmsg)
249 dcsp->sd_client_state = SCSP_CIFSM_SUM;
256 * SCSP client server interface finite state machine action 3
258 * CA FSM went down--clean up and go to Null
261 * dcsp pointer to DCS control block
262 * msg pointer to message from DCS
263 * cmsg pointer to message from server
267 * else errno describing error
271 scsp_client_act_03(dcsp, msg, cmsg)
279 dcsp->sd_client_state = SCSP_CIFSM_NULL;
286 * SCSP client server interface finite state machine action 4
288 * CA FSM went to Update Cache state--go to Update state
291 * dcsp pointer to DCS control block
292 * msg pointer to message from DCS
293 * cmsg pointer to message from server
297 * else errno describing error
301 scsp_client_act_04(dcsp, msg, cmsg)
309 dcsp->sd_client_state = SCSP_CIFSM_UPD;
316 * SCSP client server interface finite state machine action 5
318 * The CA FSM went to Cache Summarize state from Summarize,
319 * Update, or Aligned, implying that the CA FSM went down and came
320 * back up--copy the server's cache to the DCSs CSAS list and go to
324 * dcsp pointer to DCS control block
325 * msg pointer to message from DCS
326 * cmsg pointer to message from server
330 * else errno describing error
334 scsp_client_act_05(dcsp, msg, cmsg)
340 Scsp_cse *csep, *ncsep;
343 * Copy the cache summmary to the CSAS list
345 for (i = 0; i < SCSP_HASHSZ; i++) {
346 for (csep = dcsp->sd_server->ss_cache[i]; csep;
347 csep = csep->sc_next) {
348 ncsep = scsp_dup_cse(csep);
349 LINK2TAIL(ncsep, Scsp_cse, dcsp->sd_ca_csas,
357 dcsp->sd_client_state = SCSP_CIFSM_SUM;
364 * SCSP client server interface finite state machine action 6
366 * CA FSM went to Aligned state--go to Aligned
369 * dcsp pointer to DCS control block
370 * msg pointer to message from DCS
371 * cmsg pointer to message from server
375 * else errno describing error
379 scsp_client_act_06(dcsp, msg, cmsg)
387 dcsp->sd_client_state = SCSP_CIFSM_ALIGN;
394 * SCSP client server interface finite state machine action 7
396 * We received a Solicit Rsp or Update Req from the server--pass it
400 * dcsp pointer to DCS control block
401 * msg pointer to message from DCS
402 * cmsg pointer to message from server
406 * else errno describing error
410 scsp_client_act_07(dcsp, msg, cmsg)
417 Scsp_atmarp_csa *acp;
420 * Allocate memory for a CSA record
422 csap = (Scsp_csa *)UM_ALLOC(sizeof(Scsp_csa));
424 scsp_mem_err("scsp_client_act_07: sizeof(Scsp_csa)");
426 acp = (Scsp_atmarp_csa *)UM_ALLOC(sizeof(Scsp_atmarp_csa));
428 scsp_mem_err("scsp_client_act_07: sizeof(Scsp_atmarp_csa)");
430 UM_ZERO(csap, sizeof(Scsp_csa));
431 UM_ZERO(acp, sizeof(Scsp_atmarp_csa));
434 * Build a CSA record from the server's message
436 csap->hops = dcsp->sd_hops;
437 csap->null = (cmsg->si_atmarp.sa_state == SCSP_ASTATE_DEL) ||
438 (cmsg->si_type == SCSP_SOLICIT_RSP &&
439 cmsg->si_rc != SCSP_RSP_OK);
440 csap->seq = cmsg->si_atmarp.sa_seq;
441 csap->key = cmsg->si_atmarp.sa_key;
442 csap->oid = cmsg->si_atmarp.sa_oid;
443 csap->atmarp_data = acp;
444 acp->sa_state = cmsg->si_atmarp.sa_state;
445 acp->sa_sha = cmsg->si_atmarp.sa_cha;
446 acp->sa_ssa = cmsg->si_atmarp.sa_csa;
447 acp->sa_spa = cmsg->si_atmarp.sa_cpa;
448 acp->sa_tpa = cmsg->si_atmarp.sa_cpa;
453 rc = scsp_cafsm(dcsp, SCSP_CAFSM_CACHE_UPD, (void *)csap);
460 * SCSP client server interface finite state machine action 8
462 * Update Rsp from server--pass the update to the CA FSM.
465 * dcsp pointer to DCS control block
466 * msg pointer to message from DCS
467 * cmsg pointer to message from server
471 * else errno describing error
475 scsp_client_act_08(dcsp, msg, cmsg)
483 * Pass the response to the CA FSM
485 switch (dcsp->sd_server->ss_pid) {
486 case SCSP_PROTO_ATMARP:
487 rc = scsp_cafsm(dcsp, SCSP_CAFSM_CACHE_RSP, cmsg);
490 rc = EPROTONOSUPPORT;
498 * SCSP client server interface finite state machine action 9
500 * CSU Solicit from DCS--pass Solicit Ind to server
503 * dcsp pointer to DCS control block
504 * msg pointer to message from DCS
505 * cmsg pointer to message from server
509 * else errno describing error
513 scsp_client_act_09(dcsp, msg, cmsg)
523 * Get memory for a Solicit Ind
525 csip = (Scsp_if_msg *)UM_ALLOC(sizeof(Scsp_if_msg));
527 scsp_mem_err("scsp_client_act_09: sizeof(Scsp_if_msg)");
531 * Loop through list of CSAs
533 for (csap = msg->sc_csu_msg->csu_csa_rec; csap;
536 * Fill out the Solicit Indication
538 UM_ZERO(csip, sizeof(Scsp_if_msg));
539 csip->si_type = SCSP_SOLICIT_IND;
540 csip->si_proto = dcsp->sd_server->ss_pid;
541 csip->si_tok = (u_long)dcsp;
542 csip->si_len = sizeof(Scsp_if_msg_hdr) +
543 sizeof(Scsp_sum_msg);
544 csip->si_sum.ss_hops = csap->hops;
545 csip->si_sum.ss_null = csap->null;
546 csip->si_sum.ss_seq = csap->seq;
547 csip->si_sum.ss_key = csap->key;
548 csip->si_sum.ss_oid = csap->oid;
551 * Send the Solicit Ind to the server
553 rc = scsp_if_sock_write(dcsp->sd_server->ss_sock, csip);
565 * SCSP client server interface finite state machine action 10
567 * CSU Request from DCS--pass it to the server as a Cache Update
571 * dcsp pointer to DCS control block
572 * msg pointer to message from DCS
573 * cmsg pointer to message from server
577 * else errno describing error
581 scsp_client_act_10(dcsp, msg, cmsg)
588 Scsp_atmarp_csa *acp;
592 * Get memory for a Cache Update Ind
594 cuip = (Scsp_if_msg *)UM_ALLOC(sizeof(Scsp_if_msg));
596 scsp_mem_err("scsp_client_act_10: sizeof(Scsp_if_msg)");
600 * Loop through CSAs in message
602 for (csap = msg->sc_csu_msg->csu_csa_rec; csap;
604 acp = csap->atmarp_data;
609 * Fill out the Cache Update Ind
611 UM_ZERO(cuip, sizeof(Scsp_if_msg));
612 cuip->si_type = SCSP_UPDATE_IND;
613 cuip->si_proto = dcsp->sd_server->ss_pid;
614 cuip->si_tok = (u_long)dcsp;
615 switch(dcsp->sd_server->ss_pid) {
616 case SCSP_PROTO_ATMARP:
617 cuip->si_len = sizeof(Scsp_if_msg_hdr) +
618 sizeof(Scsp_atmarp_msg);
619 cuip->si_atmarp.sa_state = acp->sa_state;
620 cuip->si_atmarp.sa_cpa = acp->sa_spa;
621 cuip->si_atmarp.sa_cha = acp->sa_sha;
622 cuip->si_atmarp.sa_csa = acp->sa_ssa;
623 cuip->si_atmarp.sa_key = csap->key;
624 cuip->si_atmarp.sa_oid = csap->oid;
625 cuip->si_atmarp.sa_seq = csap->seq;
627 case SCSP_PROTO_NHRP:
629 * Not implemented yet
635 * Send the Cache Update Ind to the server
637 rc = scsp_if_sock_write(dcsp->sd_server->ss_sock, cuip);