📄 pppbacptx.c
字号:
/* pppbacptx.c - BACP packet sender *//* Copyright 1999 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02c,06aug02,jr fixed build warnings 02b,16feb02,jr Formatted the Debug Messages and initialized the local variables as part of the memory reduction process01a,02feb01,sd created*//*DESCRIPTIONThis module implements the send functions for the BACP protocol.The functions are called to send the various BACP packets, for a configure request and terminate request packet the timer is started to keep track of the requests sent with the handler routines which take care of the retries.once the packet is formed the pfwSend () is called to send the packet down the protocol stack.The module also has functions for forming a duplicate packet.*//* includes */#include "private/ppp/pppoptn.h"#include "ppp/pppBacpComponent.h"#include "private/ppp/pppBacpComponentP.h"#include "private/ppp/vbacputil.h"/**$Log:: $ * * 4 4/ * Bacp * v4.2.0 * check in * * 1 4 * code * cleanup * , code * style * changes * , * linted, * system * level * test * BACP * v4.2.0*/IMPORT void print_options_in_packet (M_BLK_ID packet);/* locals */LOCAL void bacp_send_control_packet (PFW_PLUGIN_OBJ_STATE * pluginState, M_BLK_ID packet, PPP_CONTROL_CODE code, BYTE id);LOCAL void bacp_send_configuration_request (PFW_PLUGIN_OBJ_STATE * pluginObjState, M_BLK_ID pMblk, PPP_STATE end_state);LOCAL void bacp_send_configuration_ack (PFW_PLUGIN_OBJ_STATE * pluginObjState, M_BLK_ID pMblk, PPP_STATE end_state);LOCAL void bacp_send_configuration_nak (PFW_PLUGIN_OBJ_STATE * pluginObjState, M_BLK_ID pMblk, PPP_STATE end_state);LOCAL void bacp_send_configuration_reject (PFW_PLUGIN_OBJ_STATE * pluginObjState, M_BLK_ID pMblk, PPP_STATE end_state);LOCAL void bacp_send_termination_request (PFW_PLUGIN_OBJ_STATE * pluginObjState, M_BLK_ID pMblk, PPP_STATE end_state);LOCAL void bacp_send_termination_ack (PFW_PLUGIN_OBJ_STATE * pluginObjState, M_BLK_ID pMblk, PPP_STATE end_state);LOCAL void bacp_send_code_reject (PFW_PLUGIN_OBJ_STATE * pluginObjState, M_BLK_ID pMblk, PPP_STATE end_state);/******************************************************************************** bacpSetSendActionFunctions - update action table with send functions** This function assigns the send function pointers of the * STATE_MACHINE_ACTION_TABLE to the send functions implemented.** RETURNS: N/A */void bacpSetSendActionFunctions ( STATE_MACHINE_ACTION_TABLE * actionTable /* BACP action table */ ) { actionTable->send_configuration_request = bacp_send_configuration_request; actionTable->send_configuration_ack = bacp_send_configuration_ack; actionTable->send_configuration_nak = bacp_send_configuration_nak; actionTable->send_configuration_reject = bacp_send_configuration_reject; actionTable->send_termination_request = bacp_send_termination_request; actionTable->send_termination_ack = bacp_send_termination_ack; actionTable->send_code_reject = bacp_send_code_reject; }/******************************************************************************** bacp_send_configuration_request - send BACP configuration request packet** This function is used to send BACP configuration request packet. * If the last_txed_bacp_configuration_request_packet is not NULL, then it is * sent (i.e it is a retry) else a new packet is constructed and the option field * is filled. Finally the packet is given to the function * bacp_send_control_packet () to process it further and send. ** RETURNS: N/A*/LOCAL void bacp_send_configuration_request ( PFW_PLUGIN_OBJ_STATE * pluginState, /* state for the stack */ M_BLK_ID pMblk, /* BACP packet */ PPP_STATE end_state /* end state */ ) { USHORT number_of_bytes_to_send = 0; BACP_CONFIGURE_REQUEST *sptr_configuration_request_packet = NULL; BACP_STACK_DATA * pStackData = (BACP_STACK_DATA *) pluginState->stackData; M_BLK_ID packet = NULL; M_BLK_ID retryPacket = NULL; BYTE identifier; OPTION_LIST_ENTRY * sptr_favored_peer_option = NULL; PARAMETER_NOT_USED (end_state); PARAMETER_NOT_USED (pMblk); retryPacket = pStackData->last_txed_bacp_configuration_request_packet; if ((packet = retryPacket) == NULL) { /* check if we are opening a new connection */ if (pStackData->option_lists.tx_accepted.sptr_forward_link == NULL && pStackData->option_lists.tx_accepted.sptr_backward_link == NULL) { sptr_favored_peer_option = find_matching_option (&pStackData->option_lists.configured, BACP_FAVORED_PEER); pStackData->local_favored_peer_id = ntohl (sptr_favored_peer_option->uptr_data->_ulong); copy_configuration_options_list (pluginState->pluginObj->pfwObj, &pStackData->option_lists.configured, &pStackData->option_lists.tx_accepted); } /* get the upper limit on the number of bytes in the packet */ number_of_bytes_to_send = BACP_PACKET_HEADER_SIZE; number_of_bytes_to_send += (USHORT) get_size_of_ppp_options (&pStackData->option_lists.tx_accepted); if ((packet = netTupleGet (pStackData->netPoolId, number_of_bytes_to_send, M_DONTWAIT, MT_DATA, TRUE)) == NULL) { logMsg("BACP : netTupleGet failed for Configure \ request packet size %lu \n",number_of_bytes_to_send,2,3,4,5,6); return; } sptr_configuration_request_packet = mtod (packet, BACP_CONFIGURE_REQUEST *); /* * filter options with default values: * REF: RFC 1661; page 28, paragraph 1 */ store_ppp_options_in_packet (&pStackData->option_lists.tx_accepted, (PPP_OPTION *)&sptr_configuration_request_packet->options); pStackData->id_sequence_number = (BYTE) (pStackData->id_sequence_number + 1); identifier = pStackData->id_sequence_number; packet->mBlkHdr.mLen = number_of_bytes_to_send; pStackData->length_of_last_txed_bacp_packet = number_of_bytes_to_send; } else { sptr_configuration_request_packet = mtod (packet, BACP_CONFIGURE_REQUEST *); identifier = sptr_configuration_request_packet->id;#ifdef PPP_DEBUG logMsg ("BACP configure request sending retry packet: time %ld, ID %d\n", tickGet (), identifier,3,4,5,6);#endif /* PPP_DEBUG */ } bacp_send_control_packet (pluginState, packet, CONFIGURE_REQUEST, identifier); }/******************************************************************************** bacp_send_control_packet - BACP send packet ** All the BACP control packets are sent using this function. BACP statistics are * updated based on the type of control packet. If retry is required, it is * performed and timer is used for doing this. Finally pfwSend () * is called to pass the given packet down in the protocol stack.** RETURNS: N/A*/LOCAL void bacp_send_control_packet ( PFW_PLUGIN_OBJ_STATE * pluginState, /* state for the stack */ M_BLK_ID packet, /* BCAP packet */ PPP_CONTROL_CODE code, /* packet code */ BYTE id /* identifier */ ) { M_BLK_ID pDupPacket = NULL; PPP_PACKET *sptr_tx_packet = NULL; USHORT number_of_bytes_to_send = packet->mBlkHdr.mLen; BACP_STACK_DATA * pStackData = (BACP_STACK_DATA *) pluginState->stackData; BACP_PROFILE_DATA * pProfileData = (BACP_PROFILE_DATA *)pluginState->profileData; /* update the number of bytes transmitted */ pStackData->bacp_statistics.number_of_tx_bytes += number_of_bytes_to_send; /* convert to a pointer if type PPP_PACKET */ sptr_tx_packet = mtod (packet, PPP_PACKET *); /* if configure request, duplicate the packet to keep a copy */ if (code == CONFIGURE_REQUEST && (pDupPacket = bacpDupPkt (packet)) == NULL) return; /* if it is not retry of configure request then fill up the packet header */ if (((code == CONFIGURE_REQUEST) && (packet != pStackData->last_txed_bacp_configuration_request_packet)) || (code != CONFIGURE_REQUEST)) {#if 0 sptr_tx_packet->header.hdlc_address = HDLC_ADDRESS; sptr_tx_packet->header.hdlc_control = UNNUMBERED_INFORMATION;#endif sptr_tx_packet->code = (BYTE_ENUM (PPP_CONTROL_CODE)) code; sptr_tx_packet->id = id; sptr_tx_packet->length = htons ((USHORT)(number_of_bytes_to_send - sizeof (PPP_HEADER))); sptr_tx_packet->header.protocol_type = htons ((USHORT)BACP_PROTOCOL); /* save the id if it is configure request or terminate request */ if (code == CONFIGURE_REQUEST || code == TERMINATION_REQUEST) pStackData->last_id_of_bacp_packet_sent = id; } /* update the statistics */ ++pStackData->bacp_statistics.number_of_tx_packets; ++pStackData->bacp_statistics.number_of_control_tx_packets [ sptr_tx_packet->code];#ifdef PPP_DEBUG switch (code) { case CONFIGURE_REQUEST: logMsg ("%s Tx configReq: ",(int)pluginState->pluginObj->name,2,3,4,5,6); print_options_in_packet (packet); break; case CONFIGURE_REJECT: logMsg ("%s Tx configReject: ",(int)pluginState->pluginObj->name,2,3,4,5,6); print_options_in_packet (packet); break; case CONFIGURE_NAK: logMsg ("%s Tx configNak: ",(int)pluginState->pluginObj->name,2,3,4,5,6); print_options_in_packet (packet); break; case TERMINATION_ACK: logMsg ("%s Tx TerminationAck: id = %d\n ", (int)pluginState->pluginObj->name, sptr_tx_packet->id,3,4,5,6); break; case CODE_REJECT: logMsg ("%s Tx CodeReject: id = %d\n ", (int)pluginState->pluginObj->name, sptr_tx_packet->id,3,4,5,6); break; default: break; }#endif /* PPP_DEBUG */ /* send the packet */ pfwSend (pluginState, packet); /* start the timer, if it is configure request or terminate request */ switch (code) { case CONFIGURE_REQUEST: /* keep reference to last sent packet */ if (pStackData->last_txed_bacp_configuration_request_packet != NULL) netMblkClChainFree ( pStackData->last_txed_bacp_configuration_request_packet); if (pDupPacket != NULL) pStackData->last_txed_bacp_configuration_request_packet = pDupPacket; pfwTimerCancel (pStackData->retryTimer); if (pfwTimerStart (pStackData->retryTimer, PFW_100_MILLISECOND, pProfileData->maximum_bacp_configuration_request_send_interval * 10, retry_bacp_configure_request, 0) == ERROR) { logMsg ("send config Req: timerStart failed; state = %d\n", pStackData->stateData.state, 2, 3, 4, 5, 6); } break; case TERMINATION_REQUEST: pfwTimerCancel (pStackData->retryTimer); if (pfwTimerStart (pStackData->retryTimer, PFW_SECOND, pProfileData->maximum_bacp_termination_request_send_interval, retry_bacp_termination_request, 0) == ERROR) { logMsg ("send Termination Req: timerStart failed; state = %d\n", pStackData->stateData.state, 2, 3, 4, 5, 6); } break; default: break; } }/******************************************************************************** bacp_send_configuration_ack - send bacp configuration ack** This routine is used to send BACP configuration ack packet. Last received BACP* configure request packet itself is reconstructed to ack packet by changing * necessary fields and bacp_send_control_packet is called to pass the given * packet down in the protocol stack. ** RETURNS: N/A*/ LOCAL void bacp_send_configuration_ack ( PFW_PLUGIN_OBJ_STATE * pluginState, /* state for the stack */ M_BLK_ID pMblk, /* BACP packet */ PPP_STATE end_state /* end state */ ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -