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.
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$");
70 * SCSP client server interface FSM actions
72 #define SCSP_CIFSM_ACTION_CNT 11
73 int scsp_client_act_00(Scsp_dcs *, Scsp_msg *, Scsp_if_msg *);
74 int scsp_client_act_01(Scsp_dcs *, Scsp_msg *, Scsp_if_msg *);
75 int scsp_client_act_02(Scsp_dcs *, Scsp_msg *, Scsp_if_msg *);
76 int scsp_client_act_03(Scsp_dcs *, Scsp_msg *, Scsp_if_msg *);
77 int scsp_client_act_04(Scsp_dcs *, Scsp_msg *, Scsp_if_msg *);
78 int scsp_client_act_05(Scsp_dcs *, Scsp_msg *, Scsp_if_msg *);
79 int scsp_client_act_06(Scsp_dcs *, Scsp_msg *, Scsp_if_msg *);
80 int scsp_client_act_07(Scsp_dcs *, Scsp_msg *, Scsp_if_msg *);
81 int scsp_client_act_08(Scsp_dcs *, Scsp_msg *, Scsp_if_msg *);
82 int scsp_client_act_09(Scsp_dcs *, Scsp_msg *, Scsp_if_msg *);
83 int scsp_client_act_10(Scsp_dcs *, Scsp_msg *, Scsp_if_msg *);
85 static int (*scsp_action_vector[SCSP_CIFSM_ACTION_CNT])() = {
101 * Client server interface FSM state table
103 static int client_state_table[SCSP_CIFSM_EVENT_CNT][SCSP_CIFSM_STATE_CNT] = {
105 { 1, 3, 3, 3 }, /* 0 */
106 { 2, 5, 5, 5 }, /* 1 */
107 { 0, 4, 0, 0 }, /* 2 */
108 { 0, 6, 6, 1 }, /* 3 */
109 { 1, 0, 7, 7 }, /* 4 */
110 { 7, 7, 7, 7 }, /* 5 */
111 { 1, 1, 8, 8 }, /* 6 */
112 { 0, 0, 10, 10 }, /* 7 */
113 { 0, 0, 1, 1 }, /* 8 */
114 { 0, 0, 9, 9 } /* 9 */
119 * SCSP client server interface finite state machine
122 * ssp pointer to server control block
123 * event the event which has occurred
124 * msg pointer to message from DCS, if there is one
125 * cmsg pointer to message from server, if there is one
129 * errno error encountered
133 scsp_cfsm(dcsp, event, msg, cmsg)
139 int action, rc, state;
142 * Select an action from the state table
144 state = dcsp->sd_client_state;
145 action = client_state_table[event][state];
146 if (scsp_trace_mode & SCSP_TRACE_CFSM) {
147 scsp_trace("Server I/F FSM: state=%d, event=%d, action=%d\n",
148 state, event, action);
150 if (action >= SCSP_CIFSM_ACTION_CNT || action <= 0) {
151 scsp_log(LOG_ERR, "Server I/F FSM--invalid action %d; state=%d, event=%d",
152 action, dcsp->sd_client_state, event);
157 * Perform the selected action
159 rc = scsp_action_vector[action](dcsp, msg, cmsg);
166 * SCSP client server interface finite state machine action 0
167 * Unexpected action -- log an error message
170 * dcsp pointer to DCS control block
171 * msg pointer to message from DCS (ignored)
172 * cmsg pointer to message from server (ignored)
175 * EOPNOTSUPP always returns EOPNOTSUPP
179 scsp_client_act_00(dcsp, msg, cmsg)
184 scsp_log(LOG_ERR, "Server I/F FSM error--unexpected action, state=%d",
185 dcsp->sd_client_state);
191 * SCSP client server interface finite state machine action 1
196 * dcsp pointer to DCS control block
197 * msg pointer to message from DCS
198 * cmsg pointer to message from server
205 scsp_client_act_01(dcsp, msg, cmsg)
215 * SCSP client server interface finite state machine action 2
217 * CA FSM went to Cache Summarize state--go to Summarize
220 * dcsp pointer to DCS control block
221 * msg pointer to message from DCS
222 * cmsg pointer to message from server
226 * else errno describing error
230 scsp_client_act_02(dcsp, msg, cmsg)
238 dcsp->sd_client_state = SCSP_CIFSM_SUM;
245 * SCSP client server interface finite state machine action 3
247 * CA FSM went down--clean up and go to Null
250 * dcsp pointer to DCS control block
251 * msg pointer to message from DCS
252 * cmsg pointer to message from server
256 * else errno describing error
260 scsp_client_act_03(dcsp, msg, cmsg)
268 dcsp->sd_client_state = SCSP_CIFSM_NULL;
275 * SCSP client server interface finite state machine action 4
277 * CA FSM went to Update Cache state--go to Update state
280 * dcsp pointer to DCS control block
281 * msg pointer to message from DCS
282 * cmsg pointer to message from server
286 * else errno describing error
290 scsp_client_act_04(dcsp, msg, cmsg)
298 dcsp->sd_client_state = SCSP_CIFSM_UPD;
305 * SCSP client server interface finite state machine action 5
307 * The CA FSM went to Cache Summarize state from Summarize,
308 * Update, or Aligned, implying that the CA FSM went down and came
309 * back up--copy the server's cache to the DCSs CSAS list and go to
313 * dcsp pointer to DCS control block
314 * msg pointer to message from DCS
315 * cmsg pointer to message from server
319 * else errno describing error
323 scsp_client_act_05(dcsp, msg, cmsg)
329 Scsp_cse *csep, *ncsep;
332 * Copy the cache summmary to the CSAS list
334 for (i = 0; i < SCSP_HASHSZ; i++) {
335 for (csep = dcsp->sd_server->ss_cache[i]; csep;
336 csep = csep->sc_next) {
337 ncsep = scsp_dup_cse(csep);
338 LINK2TAIL(ncsep, Scsp_cse, dcsp->sd_ca_csas,
346 dcsp->sd_client_state = SCSP_CIFSM_SUM;
353 * SCSP client server interface finite state machine action 6
355 * CA FSM went to Aligned state--go to Aligned
358 * dcsp pointer to DCS control block
359 * msg pointer to message from DCS
360 * cmsg pointer to message from server
364 * else errno describing error
368 scsp_client_act_06(dcsp, msg, cmsg)
376 dcsp->sd_client_state = SCSP_CIFSM_ALIGN;
383 * SCSP client server interface finite state machine action 7
385 * We received a Solicit Rsp or Update Req from the server--pass it
389 * dcsp pointer to DCS control block
390 * msg pointer to message from DCS
391 * cmsg pointer to message from server
395 * else errno describing error
399 scsp_client_act_07(dcsp, msg, cmsg)
406 Scsp_atmarp_csa *acp;
409 * Allocate memory for a CSA record
411 csap = calloc(1, sizeof(Scsp_csa));
413 scsp_mem_err("scsp_client_act_07: sizeof(Scsp_csa)");
414 acp = calloc(1, sizeof(Scsp_atmarp_csa));
416 scsp_mem_err("scsp_client_act_07: sizeof(Scsp_atmarp_csa)");
419 * Build a CSA record from the server's message
421 csap->hops = dcsp->sd_hops;
422 csap->null = (cmsg->si_atmarp.sa_state == SCSP_ASTATE_DEL) ||
423 (cmsg->si_type == SCSP_SOLICIT_RSP &&
424 cmsg->si_rc != SCSP_RSP_OK);
425 csap->seq = cmsg->si_atmarp.sa_seq;
426 csap->key = cmsg->si_atmarp.sa_key;
427 csap->oid = cmsg->si_atmarp.sa_oid;
428 csap->atmarp_data = acp;
429 acp->sa_state = cmsg->si_atmarp.sa_state;
430 acp->sa_sha = cmsg->si_atmarp.sa_cha;
431 acp->sa_ssa = cmsg->si_atmarp.sa_csa;
432 acp->sa_spa = cmsg->si_atmarp.sa_cpa;
433 acp->sa_tpa = cmsg->si_atmarp.sa_cpa;
438 rc = scsp_cafsm(dcsp, SCSP_CAFSM_CACHE_UPD, (void *)csap);
445 * SCSP client server interface finite state machine action 8
447 * Update Rsp from server--pass the update to the CA FSM.
450 * dcsp pointer to DCS control block
451 * msg pointer to message from DCS
452 * cmsg pointer to message from server
456 * else errno describing error
460 scsp_client_act_08(dcsp, msg, cmsg)
468 * Pass the response to the CA FSM
470 switch (dcsp->sd_server->ss_pid) {
471 case SCSP_PROTO_ATMARP:
472 rc = scsp_cafsm(dcsp, SCSP_CAFSM_CACHE_RSP, cmsg);
475 rc = EPROTONOSUPPORT;
483 * SCSP client server interface finite state machine action 9
485 * CSU Solicit from DCS--pass Solicit Ind to server
488 * dcsp pointer to DCS control block
489 * msg pointer to message from DCS
490 * cmsg pointer to message from server
494 * else errno describing error
498 scsp_client_act_09(dcsp, msg, cmsg)
508 * Get memory for a Solicit Ind
510 csip = calloc(1, sizeof(Scsp_if_msg));
512 scsp_mem_err("scsp_client_act_09: sizeof(Scsp_if_msg)");
515 * Loop through list of CSAs
517 for (csap = msg->sc_csu_msg->csu_csa_rec; csap;
520 * Fill out the Solicit Indication
522 bzero(csip, sizeof(Scsp_if_msg));
523 csip->si_type = SCSP_SOLICIT_IND;
524 csip->si_proto = dcsp->sd_server->ss_pid;
525 csip->si_tok = (u_long)dcsp;
526 csip->si_len = sizeof(Scsp_if_msg_hdr) +
527 sizeof(Scsp_sum_msg);
528 csip->si_sum.ss_hops = csap->hops;
529 csip->si_sum.ss_null = csap->null;
530 csip->si_sum.ss_seq = csap->seq;
531 csip->si_sum.ss_key = csap->key;
532 csip->si_sum.ss_oid = csap->oid;
535 * Send the Solicit Ind to the server
537 rc = scsp_if_sock_write(dcsp->sd_server->ss_sock, csip);
548 * SCSP client server interface finite state machine action 10
550 * CSU Request from DCS--pass it to the server as a Cache Update
554 * dcsp pointer to DCS control block
555 * msg pointer to message from DCS
556 * cmsg pointer to message from server
560 * else errno describing error
564 scsp_client_act_10(dcsp, msg, cmsg)
571 Scsp_atmarp_csa *acp;
575 * Get memory for a Cache Update Ind
577 cuip = malloc(sizeof(Scsp_if_msg));
579 scsp_mem_err("scsp_client_act_10: sizeof(Scsp_if_msg)");
582 * Loop through CSAs in message
584 for (csap = msg->sc_csu_msg->csu_csa_rec; csap;
586 acp = csap->atmarp_data;
591 * Fill out the Cache Update Ind
593 bzero(cuip, sizeof(Scsp_if_msg));
594 cuip->si_type = SCSP_UPDATE_IND;
595 cuip->si_proto = dcsp->sd_server->ss_pid;
596 cuip->si_tok = (u_long)dcsp;
597 switch(dcsp->sd_server->ss_pid) {
598 case SCSP_PROTO_ATMARP:
599 cuip->si_len = sizeof(Scsp_if_msg_hdr) +
600 sizeof(Scsp_atmarp_msg);
601 cuip->si_atmarp.sa_state = acp->sa_state;
602 cuip->si_atmarp.sa_cpa = acp->sa_spa;
603 cuip->si_atmarp.sa_cha = acp->sa_sha;
604 cuip->si_atmarp.sa_csa = acp->sa_ssa;
605 cuip->si_atmarp.sa_key = csap->key;
606 cuip->si_atmarp.sa_oid = csap->oid;
607 cuip->si_atmarp.sa_seq = csap->seq;
609 case SCSP_PROTO_NHRP:
611 * Not implemented yet
617 * Send the Cache Update Ind to the server
619 rc = scsp_if_sock_write(dcsp->sd_server->ss_sock, cuip);