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_cafsm.c,v 1.3 1999/08/28 01:15:32 peter Exp $
27 * @(#) $DragonFly: src/usr.sbin/atm/scspd/scsp_cafsm.c,v 1.3 2003/11/03 19:31:35 eirikn Exp $
32 * Server Cache Synchronization Protocol (SCSP) Support
33 * ----------------------------------------------------
35 * Cache Alignment finite state machine
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>
66 #define CA_ACTION_CNT 20
67 int scsp_ca_act_00(Scsp_dcs *, void *);
68 int scsp_ca_act_01(Scsp_dcs *, void *);
69 int scsp_ca_act_02(Scsp_dcs *, void *);
70 int scsp_ca_act_03(Scsp_dcs *, void *);
71 int scsp_ca_act_04(Scsp_dcs *, void *);
72 int scsp_ca_act_05(Scsp_dcs *, void *);
73 int scsp_ca_act_06(Scsp_dcs *, void *);
74 int scsp_ca_act_07(Scsp_dcs *, void *);
75 int scsp_ca_act_08(Scsp_dcs *, void *);
76 int scsp_ca_act_09(Scsp_dcs *, void *);
77 int scsp_ca_act_10(Scsp_dcs *, void *);
78 int scsp_ca_act_11(Scsp_dcs *, void *);
79 int scsp_ca_act_12(Scsp_dcs *, void *);
80 int scsp_ca_act_13(Scsp_dcs *, void *);
81 int scsp_ca_act_14(Scsp_dcs *, void *);
82 int scsp_ca_act_15(Scsp_dcs *, void *);
83 int scsp_ca_act_16(Scsp_dcs *, void *);
84 int scsp_ca_act_17(Scsp_dcs *, void *);
85 int scsp_ca_act_18(Scsp_dcs *, void *);
86 int scsp_ca_act_19(Scsp_dcs *, void *);
88 static int (*scsp_ca_act_vec[CA_ACTION_CNT])() = {
114 static int ca_state_table[SCSP_CAFSM_EVENT_CNT][SCSP_CAFSM_STATE_CNT] = {
116 { 1, 1, 1, 1, 1, 1 }, /* 0 */
117 { 2, 2, 2, 2, 2, 2 }, /* 1 */
118 { 0, 3, 4, 5, 15, 15 }, /* 2 */
119 { 0, 17, 17, 17, 7, 7 }, /* 3 */
120 { 0, 17, 17, 17, 8, 8 }, /* 4 */
121 { 0, 17, 17, 17, 10, 10 }, /* 5 */
122 { 0, 6, 6, 0, 9, 9 }, /* 6 */
123 { 0, 0, 0, 0, 12, 12 }, /* 7 */
124 { 0, 0, 0, 0, 13, 13 }, /* 8 */
125 { 18, 14, 14, 14, 11, 11 }, /* 9 */
126 { 0, 19, 0, 0, 16, 16 }, /* 10 */
131 * Cache Alignment finite state machine
134 * dcsp pointer to a DCS control block for the neighbor
135 * event the event which has occurred
136 * p pointer to further parameter, if there is one
140 * errno error encountered
144 scsp_cafsm(dcsp, event, p)
149 int action, rc, state;
152 * Select an action from the state table
154 state = dcsp->sd_ca_state;
155 action = ca_state_table[event][state];
156 if (scsp_trace_mode & SCSP_TRACE_CAFSM) {
157 scsp_trace("CAFSM: state=%d, event=%d, action=%d\n",
158 state, event, action);
160 if (action >= CA_ACTION_CNT || action < 0) {
161 scsp_log(LOG_ERR, "CA FSM--invalid action state=%d, event=%d, action=%d",
162 state, event, action);
167 * Perform the selected action
169 rc = scsp_ca_act_vec[action](dcsp, p);
176 * CA finite state machine action 0
177 * Unexpected action -- log an error message and go to Master/Slave
178 * Negotiation. The unexpected action is probably from a protocol
182 * dcsp pointer to DCS control block
186 * EOPNOTSUPP always returns EOPNOTSUPP
190 scsp_ca_act_00(dcsp, p)
197 * Log an error message
199 scsp_log(LOG_ERR, "CA FSM error--unexpected action, state=%d",
205 dcsp->sd_ca_state = SCSP_CAFSM_NEG;
208 * Clear out the DCS block
210 scsp_dcs_cleanup(dcsp);
213 * Notify the client I/F FSM
215 rc = scsp_cfsm(dcsp, SCSP_CIFSM_CA_DOWN, (Scsp_msg *)0,
223 * CA finite state machine action 1
224 * Hello FSM has reached Bidirectional state -- go to Master/Slave
225 * Negotiation state, make a copy of the client's cache, send first CA
229 * dcsp pointer to DCS control block
234 * errno error encountered
238 scsp_ca_act_01(dcsp, p)
243 Scsp_cse *csep, *dupp;
248 dcsp->sd_ca_state = SCSP_CAFSM_NEG;
251 * Make a copy of client's cache entries for cache alignment
253 for (i = 0; i < SCSP_HASHSZ; i++) {
254 for (csep = dcsp->sd_server->ss_cache[i];
255 csep; csep = csep->sc_next) {
256 dupp = scsp_dup_cse(csep);
257 LINK2TAIL(dupp, Scsp_cse, dcsp->sd_ca_csas,
263 * Select an initial sequence number
265 dcsp->sd_ca_seq = (int)time((time_t *)0);
270 rc = scsp_send_ca(dcsp);
272 HARP_TIMER(&dcsp->sd_ca_rexmt_t, dcsp->sd_ca_rexmt_int,
273 scsp_ca_retran_timeout);
281 * CA finite state machine action 2
282 * Hello FSM has gone down -- go to Down state
285 * dcsp pointer to DCS control block
290 * errno error encountered
294 scsp_ca_act_02(dcsp, p)
303 dcsp->sd_ca_state = SCSP_CAFSM_DOWN;
306 * Clear out the DCS block
308 scsp_dcs_cleanup(dcsp);
311 * Notify the client I/F FSM
313 rc = scsp_cfsm(dcsp, SCSP_CIFSM_CA_DOWN, (Scsp_msg *)0,
321 * CA finite state machine action 3
322 * CA message received -- select Cache Summarize Master or Slave state
325 * dcsp pointer to DCS control block
326 * p pointer to received message
330 * errno error encountered
334 scsp_ca_act_03(dcsp, p)
339 Scsp_msg *msg = (Scsp_msg *)p;
342 * Check for slave role for LS
344 if (msg->sc_ca->ca_m &&
347 msg->sc_ca->ca_mcp.rec_cnt == 0 &&
348 scsp_cmp_id(&msg->sc_ca->ca_mcp.sid,
349 &msg->sc_ca->ca_mcp.rid) > 0) {
352 * Stop the retransmit timer
354 HARP_CANCEL(&dcsp->sd_ca_rexmt_t);
359 dcsp->sd_ca_state = SCSP_CAFSM_SLAVE;
360 (void)scsp_cfsm(dcsp, SCSP_CIFSM_CA_SUMM,
361 (Scsp_msg *)0, (Scsp_if_msg *)0);
364 * Save the master's sequence number
366 dcsp->sd_ca_seq = msg->sc_ca->ca_seq;
371 rc = scsp_send_ca(dcsp);
374 * Check for master role for LS
376 if (!msg->sc_ca->ca_m &&
378 scsp_cmp_id(&msg->sc_ca->ca_mcp.sid,
379 &msg->sc_ca->ca_mcp.rid) < 0) {
381 * Stop the retransmit timer
383 HARP_CANCEL(&dcsp->sd_ca_rexmt_t);
388 dcsp->sd_ca_state = SCSP_CAFSM_MASTER;
389 rc = scsp_cfsm(dcsp, SCSP_CIFSM_CA_SUMM,
390 (Scsp_msg *)0, (Scsp_if_msg *)0);
393 * Process the CA message
395 scsp_process_ca(dcsp, msg->sc_ca);
398 * Increment the sequence number
405 rc = scsp_send_ca(dcsp);
407 HARP_TIMER(&dcsp->sd_ca_rexmt_t,
408 dcsp->sd_ca_rexmt_int,
409 scsp_ca_retran_timeout);
413 * Ignore the message, go to Master/Slave Negotiation
415 dcsp->sd_ca_state = SCSP_CAFSM_NEG;
423 * CA finite state machine action 4
424 * CA message received while in Cache Summarize Master state -- process
428 * dcsp pointer to DCS control block
429 * p pointer to received message
433 * errno error encountered
437 scsp_ca_act_04(dcsp, p)
442 Scsp_msg *msg = (Scsp_msg *)p;
445 * If the other side thinks he's the master, or if the
446 * initialization bit is set, or if the message is out
447 * of sequence, go back to Master/Slave Negotiation state
449 if (msg->sc_ca->ca_m || msg->sc_ca->ca_i ||
450 msg->sc_ca->ca_seq < dcsp->sd_ca_seq - 1 ||
451 msg->sc_ca->ca_seq > dcsp->sd_ca_seq) {
452 HARP_CANCEL(&dcsp->sd_ca_rexmt_t);
453 dcsp->sd_ca_state = SCSP_CAFSM_NEG;
454 scsp_dcs_cleanup(dcsp);
455 return(scsp_ca_act_01(dcsp, (Scsp_msg *)0));
459 * Ignore any duplicate messages
461 if (msg->sc_ca->ca_seq == dcsp->sd_ca_seq - 1) {
466 * Stop the retransmission timer
468 HARP_CANCEL(&dcsp->sd_ca_rexmt_t);
471 * Process the CA message
473 scsp_process_ca(dcsp, msg->sc_ca);
476 * Increment the CA sequence number
481 * If we have no more CSAS records to send and the slave sent
482 * a message with the 'O' bit off, we're done with Summarize
485 if (!dcsp->sd_ca_csas && !msg->sc_ca->ca_o) {
487 * Free any CA message saved for retransmission
489 if (dcsp->sd_ca_rexmt_msg) {
490 scsp_free_msg(dcsp->sd_ca_rexmt_msg);
491 dcsp->sd_ca_rexmt_msg = (Scsp_msg *)0;
495 * If the CRL is empty, we go directly to Aligned state;
496 * otherwise, we go to Update Cache and send a CSUS
500 * Go to Aligned state
502 dcsp->sd_ca_state = SCSP_CAFSM_ALIGNED;
503 rc = scsp_cfsm(dcsp, SCSP_CIFSM_CA_ALIGN,
508 * Go to Cache Update state
510 dcsp->sd_ca_state = SCSP_CAFSM_UPDATE;
511 (void)scsp_cfsm(dcsp, SCSP_CIFSM_CA_UPD,
514 rc = scsp_send_csus(dcsp);
518 * There are more CSAS records to be exchanged--
519 * continue the cache exchange
521 rc = scsp_send_ca(dcsp);
529 * CA finite state machine action 5
530 * CA message received while in Cache Summarize Slave state -- process
534 * dcsp pointer to DCS control block
535 * p pointer to received message
539 * errno error encountered
543 scsp_ca_act_05(dcsp, p)
548 Scsp_msg *msg = (Scsp_msg *)p;
551 * If the other side thinks we're the master, or if the
552 * initialization bit is set, or if the message is out
553 * of sequence, go back to Master/Slave Negotiation state
555 if (!msg->sc_ca->ca_m || msg->sc_ca->ca_i ||
556 msg->sc_ca->ca_seq < dcsp->sd_ca_seq ||
557 msg->sc_ca->ca_seq > dcsp->sd_ca_seq + 1) {
558 HARP_CANCEL(&dcsp->sd_ca_rexmt_t);
559 dcsp->sd_ca_state = SCSP_CAFSM_NEG;
560 scsp_dcs_cleanup(dcsp);
561 return(scsp_ca_act_01(dcsp, (Scsp_msg *)0));
565 * If this is a duplicate, retransmit the last message
567 if (msg->sc_ca->ca_seq == dcsp->sd_ca_seq) {
568 if (dcsp->sd_ca_rexmt_msg) {
569 rc = scsp_send_msg(dcsp, dcsp->sd_ca_rexmt_msg);
571 HARP_TIMER(&dcsp->sd_ca_rexmt_t,
572 dcsp->sd_ca_rexmt_int,
573 scsp_ca_retran_timeout);
580 * Free the last CA message
582 if (dcsp->sd_ca_rexmt_msg) {
583 scsp_free_msg(dcsp->sd_ca_rexmt_msg);
584 dcsp->sd_ca_rexmt_msg = (Scsp_msg *)0;
588 * Process the CA message
590 scsp_process_ca(dcsp, msg->sc_ca);
593 * Increment the CA sequence number
598 * Answer the CA message
600 rc = scsp_send_ca(dcsp);
605 * If we're done sending CSAS records and the other side is,
606 * too, we're done with Summarize state
608 if (!dcsp->sd_ca_csas && !msg->sc_ca->ca_o) {
610 * If the CRL is empty, we go directly to Aligned state;
611 * otherwise, we go to Update Cache and send a CSUS
615 * Go to Aligned state
617 dcsp->sd_ca_state = SCSP_CAFSM_ALIGNED;
618 rc = scsp_cfsm(dcsp, SCSP_CIFSM_CA_ALIGN,
623 * Go to Cache Update state
625 dcsp->sd_ca_state = SCSP_CAFSM_UPDATE;
626 HARP_CANCEL(&dcsp->sd_ca_rexmt_t);
627 HARP_TIMER(&dcsp->sd_ca_rexmt_t,
628 dcsp->sd_ca_rexmt_int,
629 scsp_ca_retran_timeout);
630 (void)scsp_cfsm(dcsp, SCSP_CIFSM_CA_UPD,
633 rc = scsp_send_csus(dcsp);
642 * CA finite state machine action 6
643 * Retransmit timer expired -- retransmit last CA message
646 * dcsp pointer to DCS control block
651 * errno error encountered
655 scsp_ca_act_06(dcsp, p)
662 * Resend the CA message
664 rc = scsp_send_msg(dcsp, dcsp->sd_ca_rexmt_msg);
667 * Restart the retransmit timer
670 HARP_TIMER(&dcsp->sd_ca_rexmt_t, dcsp->sd_ca_rexmt_int,
671 scsp_ca_retran_timeout);
679 * CA finite state machine action 7
680 * CSU Solicit received -- send it to the client interface FSM
683 * dcsp pointer to DCS control block
684 * p pointer to received message
688 * errno error encountered
692 scsp_ca_act_07(dcsp, p)
697 Scsp_msg *msg = (Scsp_msg *)p;
700 * Cancel the CA retransmit timer and free any CA message
701 * saved for retransmission
703 if (dcsp->sd_ca_rexmt_msg) {
704 HARP_CANCEL(&dcsp->sd_ca_rexmt_t);
705 scsp_free_msg(dcsp->sd_ca_rexmt_msg);
706 dcsp->sd_ca_rexmt_msg = (Scsp_msg *)0;
710 * Pass the CSUS to the client interface FSM
712 rc = scsp_cfsm(dcsp, SCSP_CIFSM_CSU_SOL, msg,
720 * CA finite state machine action 8
721 * CSU Request received -- pass it to the client interface FSM
724 * dcsp pointer to DCS control block
725 * p pointer to received message
729 * errno error encountered
733 scsp_ca_act_08(dcsp, p)
738 Scsp_msg *msg = (Scsp_msg *)p;
742 * Check whether this messages answers a CSUS
744 scsp_csus_ack(dcsp, msg);
747 * If all CSAs requestd in CSUS messages have been
748 * received, the cache is aligned, so go to Aligned State
750 if (!dcsp->sd_csus_rexmt_msg && !dcsp->sd_crl &&
751 dcsp->sd_ca_state != SCSP_CAFSM_ALIGNED) {
752 dcsp->sd_ca_state = SCSP_CAFSM_ALIGNED;
753 rc = scsp_cfsm(dcsp, SCSP_CIFSM_CA_ALIGN,
754 (Scsp_msg *)0, (Scsp_if_msg *)0);
758 * Pass the CSU Req to the client interface FSM
760 rc = scsp_cfsm(dcsp, SCSP_CIFSM_CSU_REQ, msg,
764 * Move the CSA chain from the message to the list of
765 * requests that need acknowledgements
767 for (csap = msg->sc_csu_msg->csu_csa_rec; csap;
769 LINK2TAIL(csap, Scsp_csa, dcsp->sd_csu_ack_pend, next);
771 msg->sc_csu_msg->csu_csa_rec = (Scsp_csa *)0;
778 * CA finite state machine action 9
779 * CA Retransmit timer expired in Update Cache or Aligned state--free
780 * the saved CA message
783 * dcsp pointer to DCS control block
788 * errno error encountered
792 scsp_ca_act_09(dcsp, p)
797 * Free any CA message saved for retransmission
799 if (dcsp->sd_ca_rexmt_msg) {
800 scsp_free_msg(dcsp->sd_ca_rexmt_msg);
801 dcsp->sd_ca_rexmt_msg = (Scsp_msg *)0;
809 * CA finite state machine action 10
810 * CSU Reply received -- Process the message
813 * dcsp pointer to DCS control block
814 * p pointer to received message
818 * errno error encountered
822 scsp_ca_act_10(dcsp, p)
827 Scsp_msg *msg = (Scsp_msg *)p;
828 Scsp_csu_rexmt *rxp, *next_rxp;
829 Scsp_csa *csap, *next_csap, *mcp;
832 * Dequeue acknowledged CSAs. For each CSAS in the received
833 * message, find the corresponding CSA on the CSU Request
834 * retransmit queue. Remove the CSA from the queue; if this
835 * results in the retransmit queue entry being empty, delete
836 * the entry. If the DCS has a newer CSA, send a CSUS to
839 * Caution--potentially confusing lack of indentation ahead.
841 for (mcp = msg->sc_csu_msg->csu_csa_rec; mcp;
843 for (rxp = dcsp->sd_csu_rexmt; rxp; rxp = next_rxp) {
844 next_rxp = rxp->sr_next;
845 for (csap = rxp->sr_csa; csap; csap = next_csap) {
846 next_csap = csap->next;
847 if (scsp_cmp_key(&csap->key, &mcp->key) ||
848 scsp_cmp_id(&csap->oid, &mcp->oid))
851 * Found a CSA whose key and ID are equal to
852 * those in the CSU Reply
854 if (csap->seq == mcp->seq) {
856 * The queued seq no is equal to the
857 * received seq no--the CSA is acknowledged
859 UNLINK(csap, Scsp_csa, rxp->sr_csa, next);
861 } else if (csap->seq < mcp->seq) {
863 * Queued seq no is less than received.
864 * We must dequeue the CSA and send a
865 * CSUS to request the more-up-to-date
868 UNLINK(mcp, Scsp_csa,
869 msg->sc_csu_msg->csu_csa_rec,
871 LINK2TAIL(mcp, Scsp_csa, dcsp->sd_crl, next);
872 UNLINK(csap, Scsp_csa, rxp->sr_csa, next);
874 if (!dcsp->sd_csus_rexmt_msg) {
875 rc = scsp_send_csus(dcsp);
882 * Queued seq no is greater than
883 * received. Ignore the received CSAS.
887 * If the retransmission block is empty, stop the
891 HARP_CANCEL(&rxp->sr_t);
892 UNLINK(rxp, Scsp_csu_rexmt,
893 dcsp->sd_csu_rexmt, sr_next);
898 } /* for (csap = ... */
899 } /* for (rxp = ... */
900 } /* for (mcp = ... */
907 * CA finite state machine action 11
908 * Updated cache entry -- update the summary cache and send a
912 * dcsp pointer to DCS control block
913 * p pointer to CSA describing new cache entry
917 * errno error encountered
921 scsp_ca_act_11(dcsp, p)
926 Scsp_csa *csap = (Scsp_csa *)p;
930 * Get the state of the CSA
932 switch(dcsp->sd_server->ss_pid) {
933 case SCSP_PROTO_ATMARP:
934 state = csap->atmarp_data->sa_state;
941 if (state < SCSP_ASTATE_NEW || state > SCSP_ASTATE_DEL) {
947 * Look up the cache summary entry for the CSA
949 SCSP_LOOKUP(dcsp->sd_server, &csap->key, csep);
952 * Process ATMARP entries
954 if (dcsp->sd_server->ss_pid == SCSP_PROTO_ATMARP) {
956 case SCSP_ASTATE_NEW:
957 case SCSP_ASTATE_UPD:
959 * Add the entry if we don't have it already
962 csep = (Scsp_cse *)UM_ALLOC(
965 scsp_mem_err("scsp_ca_act_11: sizeof(Scsp_cse)");
966 UM_ZERO(csep, sizeof(Scsp_cse));
968 csep->sc_key = csap->key;
969 SCSP_ADD(dcsp->sd_server, csep);
973 * Update the cache summary entry
975 csep->sc_seq = csap->seq;
976 csep->sc_oid = csap->oid;
978 case SCSP_ASTATE_DEL:
980 * Delete any entry, but don't send the
984 SCSP_DELETE(dcsp->sd_server, csep);
994 * Send the CSA in a CSU Request
997 rc = scsp_send_csu_req(dcsp, csap);
1004 * CA finite state machine action 12
1005 * CSUS retransmit timer expired--send a CSUS with any pending CSA
1009 * dcsp pointer to DCS control block
1014 * errno error encountered
1018 scsp_ca_act_12(dcsp, p)
1024 rc = scsp_send_csus(dcsp);
1031 * CA finite state machine action 13
1032 * CSU retransmit timer fired in Update or Aligned state--
1033 * retransmit CSU Req
1036 * dcsp pointer to DCS control block
1037 * p pointer to retransmission block whose timer fired
1041 * errno error encountered
1045 scsp_ca_act_13(dcsp, p)
1050 Scsp_csu_rexmt *rxp = (Scsp_csu_rexmt *)p;
1051 Scsp_csa *csap, *csap1, *next_csap;
1054 * Unlink and free the retransmit request block
1057 UNLINK(rxp, Scsp_csu_rexmt, dcsp->sd_csu_rexmt, sr_next);
1061 * Increment the transmission count for the CSAs in the request
1063 for (csap1 = csap; csap1; csap1 = next_csap) {
1064 next_csap = csap1->next;
1066 if (csap1->trans_ct >= dcsp->sd_csu_rexmt_max) {
1068 * We've already sent this as many times as
1069 * the limit allows. Drop this CSA.
1071 UNLINK(csap1, Scsp_csa, csap, next);
1072 SCSP_FREE_CSA(csap1);
1077 * Send another CSU Request with the CSA list, if it isn't
1081 rc = scsp_send_csu_req(dcsp, csap);
1089 * CA finite state machine action 14
1090 * Updated cache entry in Master/Slave Negotiation, Master, or
1091 * Slave state--add entry to cache and CSA list
1094 * dcsp pointer to DCS control block
1095 * p pointer to new cache summary entry
1099 * errno error encountered
1103 scsp_ca_act_14(dcsp, p)
1107 Scsp_csa *csap = (Scsp_csa *)p;
1108 Scsp_cse *csep, *csep1;
1111 * Check to see whether we already have this
1113 SCSP_LOOKUP(dcsp->sd_server, &csap->key, csep);
1116 * If we don't already have it and it's not being deleted,
1117 * build a new cache summary entry
1119 if (!csep && !csap->null) {
1121 * Get memory for a new entry
1123 csep = (Scsp_cse *)UM_ALLOC(sizeof(Scsp_cse));
1125 scsp_mem_err("scsp_ca_act_14: sizeof(Scsp_cse)");
1127 UM_ZERO(csep, sizeof(Scsp_cse));
1130 * Fill out the new cache entry
1132 csep->sc_seq = csap->seq;
1133 csep->sc_key = csap->key;
1134 csep->sc_oid = csap->oid;
1137 * Duplicate the new cache entry
1139 csep1 = scsp_dup_cse(csep);
1142 * Add entry to the summary cache and the CSAS list
1144 SCSP_ADD(dcsp->sd_server, csep);
1145 LINK2TAIL(csep1, Scsp_cse, dcsp->sd_ca_csas, sc_next);
1148 * We already have the entry. Find it on the CSAS
1151 for (csep1 = dcsp->sd_ca_csas; csep1;
1152 csep1 = csep1->sc_next) {
1153 if (scsp_cmp_key(&csep->sc_key,
1154 &csep1->sc_key) == 0)
1159 * Update or delete the entry
1163 * The null flag is set--delete the entry
1165 SCSP_DELETE(dcsp->sd_server, csep);
1168 UNLINK(csep1, Scsp_cse,
1177 csep->sc_seq = csap->seq;
1178 csep->sc_oid = csap->oid;
1180 csep1 = scsp_dup_cse(csep);
1181 LINK2TAIL(csep1, Scsp_cse,
1182 dcsp->sd_ca_csas, sc_next);
1184 csep1->sc_seq = csap->seq;
1185 csep1->sc_oid = csap->oid;
1195 * CA finite state machine action 15
1196 * CA message received in Update Cache state--if we have a saved CA
1197 * message, retransmit it; otherwise, go to Master/Slave Negotiation
1201 * dcsp pointer to DCS control block
1206 * errno error encountered
1210 scsp_ca_act_15(dcsp, p)
1215 Scsp_msg *msg = (Scsp_msg *)p;
1218 * If we don't have a saved CA message, or the sequence no. in
1219 * the received message isn't right, fall back to Master/Slave
1222 if (!dcsp->sd_ca_rexmt_msg ||
1223 msg->sc_ca->ca_seq != dcsp->sd_ca_seq) {
1224 dcsp->sd_ca_state = SCSP_CAFSM_NEG;
1225 scsp_dcs_cleanup(dcsp);
1226 rc = scsp_ca_act_01(dcsp, (Scsp_msg *)0);
1229 * Retransmit the saved CA message and reset the
1232 rc = scsp_send_msg(dcsp, dcsp->sd_ca_rexmt_msg);
1234 HARP_CANCEL(&dcsp->sd_ca_rexmt_t);
1235 HARP_TIMER(&dcsp->sd_ca_rexmt_t,
1236 dcsp->sd_ca_rexmt_int,
1237 scsp_ca_retran_timeout);
1246 * CA finite state machine action 16
1247 * Update Response received from client in Update Cache or Aligned
1248 * state. Move the acknowledged CSA to the acknowledged queue. If
1249 * the list of CSAs pending acknowledgement is empty, send a CSU
1253 * dcsp pointer to DCS control block
1254 * p pointer to message from client
1258 * errno error encountered
1262 scsp_ca_act_16(dcsp, p)
1267 Scsp_if_msg *cmsg = (Scsp_if_msg *)p;
1271 * Find the acknowledged CSA
1273 for (csap = dcsp->sd_csu_ack_pend, found = 0; csap && !found;
1274 csap = csap->next) {
1275 switch (dcsp->sd_server->ss_pid) {
1276 case SCSP_PROTO_ATMARP:
1277 found = ((scsp_cmp_key(&csap->key,
1278 &cmsg->si_atmarp.sa_key) == 0) &&
1279 (scsp_cmp_id(&csap->oid,
1280 &cmsg->si_atmarp.sa_oid) == 0));
1284 * Protocol not implemented
1286 return(EPROTONOSUPPORT);
1293 if (scsp_trace_mode & SCSP_TRACE_CAFSM) {
1294 scsp_trace("scsp_ca_act_16: can't find CSA entry for Update Response\n");
1299 if (cmsg->si_rc == SCSP_RSP_OK) {
1301 * The server accepted the cache entry
1305 * Update SCSP's cache
1307 scsp_update_cache(dcsp, csap);
1310 * Send this CSA to any other DCSs in the server group
1312 rc = scsp_propagate_csa(dcsp, csap);
1316 * Move the CSA from the ACK pending queue to the
1317 * acknowledged queue
1319 UNLINK(csap, Scsp_csa, dcsp->sd_csu_ack_pend, next);
1320 LINK2TAIL(csap, Scsp_csa, dcsp->sd_csu_ack, next);
1321 if (!dcsp->sd_csu_ack_pend) {
1323 * ACK pending list is empty--send a CSU Reply
1325 csap = dcsp->sd_csu_ack;
1326 dcsp->sd_csu_ack = (Scsp_csa *)0;
1327 rc = scsp_send_csu_reply(dcsp, csap);
1335 * CA finite state machine action 17
1339 * dcsp pointer to DCS control block
1347 scsp_ca_act_17(dcsp, p)
1356 * CA finite state machine action 18
1357 * Updated cache entry in Down state--add entry to summary cache
1360 * dcsp pointer to DCS control block
1361 * p pointer to new cache summary entry
1365 * errno error encountered
1369 scsp_ca_act_18(dcsp, p)
1373 Scsp_csa *csap = (Scsp_csa *)p;
1376 * Update the cache as appropriate
1378 scsp_update_cache(dcsp, csap);
1385 * CA finite state machine action 19
1386 * Update Response received from client in Master/Slave Negotiation
1387 * state. Update the cache as appropriate.
1390 * dcsp pointer to DCS control block
1391 * p pointer to message from client
1395 * errno error encountered
1399 scsp_ca_act_19(dcsp, p)
1403 Scsp_if_msg *cmsg = (Scsp_if_msg *)p;
1407 * Ignore the message if the client rejected the update
1409 if (cmsg->si_rc != SCSP_RSP_OK) {
1414 * Create a CSAS from the client's update
1416 csap = (Scsp_csa *)UM_ALLOC(sizeof(Scsp_csa));
1418 scsp_mem_err("scsp_ca_act_19: sizeof(Scsp_csa)");
1420 UM_ZERO(csap, sizeof(Scsp_csa));
1423 switch (dcsp->sd_server->ss_pid) {
1424 case SCSP_PROTO_ATMARP:
1425 csap->null = cmsg->si_atmarp.sa_state ==
1427 csap->seq = cmsg->si_atmarp.sa_seq;
1428 csap->key = cmsg->si_atmarp.sa_key;
1429 csap->oid = cmsg->si_atmarp.sa_oid;
1436 * Update SCSP's cache
1438 scsp_update_cache(dcsp, csap);