⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pppbacptx.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
	BACP_CONFIGURE_ACK_PACKET *sptr_configuration_ack_packet = NULL;	BACP_STACK_DATA * pStackData = (BACP_STACK_DATA *) pluginState->stackData;	M_BLK_ID packet = pStackData->last_rxed_bacp_configuration_request_packet;	OPTION_LIST_ENTRY *sptr_configured_option = NULL;	OPTION_LIST_ENTRY *sptr_accepted_option = NULL;	PARAMETER_NOT_USED (end_state);	PARAMETER_NOT_USED (pMblk);	/* 	 * we are about to send an ACK so we reset nak_option_selected counters	 * for the options we are accepting	 */    sptr_accepted_option = 					pStackData->option_lists.rx_accepted.sptr_forward_link;	while (sptr_accepted_option)		{		sptr_configured_option = find_matching_option 				(&pStackData->option_lists.remote_configured,				sptr_accepted_option->type.generic);		if (sptr_configured_option == NULL)				{			printf ("BACP configure ack send: FATAL ERROR: no matching \					option found in remote_configured option list\n");			return;			}		sptr_configured_option->nak_option_selected = 0;		sptr_accepted_option = sptr_accepted_option->sptr_forward_link;		}	/* in the received packet, change the code to configure ack and send it */	sptr_configuration_ack_packet = mtod (packet, BACP_CONFIGURE_ACK_PACKET *);	sptr_configuration_ack_packet->code = CONFIGURE_ACK;	pStackData->last_rxed_bacp_configuration_request_packet = NULL;#ifdef PPP_DEBUG	logMsg ("%s Tx configAck: ",(int)pluginState->pluginObj->name,2,3,4,5,6);	print_options_in_packet (packet);#endif /* PPP_DEBUG	*/		pfwSend (pluginState, packet);    }/******************************************************************************** bacp_send_configuration_nak - send bacp configuration nak** This routine is used to send BACP configuration nak packet. Last received BACP * configure request packet itself is reconstructed to nak packet if its of the * required size else a new packet is allocated and the options are copied. * bacp_send_control_packet is called to pass the given packet down in the * protocol stack. ** RETURNS: N/A*/LOCAL void bacp_send_configuration_nak	(	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_NAK_PACKET *sptr_configuration_nak_packet = NULL;	BACP_PACKET *sptr_bacp_rx_packet = NULL;	BACP_STACK_DATA * pStackData = (BACP_STACK_DATA *) pluginState->stackData;	BACP_PROFILE_DATA * pProfileData = 				(BACP_PROFILE_DATA *) pluginState->profileData;	M_BLK_ID rx_packet = pStackData->last_rxed_bacp_configuration_request_packet;	M_BLK_ID packet = NULL;	BYTE rxed_identifier;	PARAMETER_NOT_USED (end_state);	PARAMETER_NOT_USED (pMblk);	/* Max-Failure: discussion; RFC 1661, page 25 */ 	if (++pStackData->number_of_configuration_naks >		pProfileData->maximum_number_of_configuration_failures)		{		copy_configuration_options_list (pluginState->pluginObj->pfwObj,				    &pStackData->option_lists.tx_nak,				    &pStackData->option_lists.tx_reject);		bacp_send_configuration_reject (pluginState, pMblk, end_state);		return;		}	if (rx_packet == NULL)		return;	sptr_bacp_rx_packet = mtod (rx_packet, BACP_PACKET *);	rxed_identifier = sptr_bacp_rx_packet->bacp_header.id;	number_of_bytes_to_send = sizeof (PPP_HEADER) + sizeof (BACP_HEADER);	number_of_bytes_to_send = (USHORT) (number_of_bytes_to_send +	get_size_of_ppp_options (&pStackData->option_lists.tx_nak));	/* use the received packet if it is of the required size 									else allocate a new packet */ 	if (rx_packet->pClBlk->clSize >= number_of_bytes_to_send)		{		rx_packet->mBlkHdr.mData = rx_packet->pClBlk->clNode.pClBuf;		rx_packet->mBlkHdr.mLen = 0;		packet = rx_packet;		bzero (packet->mBlkHdr.mData, number_of_bytes_to_send);		}	else 		{		netMblkClChainFree (rx_packet);		pStackData->last_rxed_bacp_configuration_request_packet = NULL;		if ((packet = netTupleGet (pStackData->netPoolId,			number_of_bytes_to_send, M_DONTWAIT, MT_DATA, TRUE)) == NULL)			return;		}	/* copy the options */	sptr_configuration_nak_packet = mtod (packet, BACP_CONFIGURE_NAK_PACKET *);	store_ppp_options_in_packet (&pStackData->option_lists.tx_nak,		(PPP_OPTION *) &sptr_configuration_nak_packet->options);	packet->mBlkHdr.mLen = number_of_bytes_to_send;	pStackData->last_rxed_bacp_configuration_request_packet = NULL;	bacp_send_control_packet (pluginState, packet, CONFIGURE_NAK, 												rxed_identifier);    }/******************************************************************************* bacp_send_configuration_reject - send BACP configure reject packet** This routine is used to send BACP configuration reject packet. Last received * BACP configure request packet itself is reconstructed to reject packet if its * of the required size else a new packet is allocated and the options copied.* bacp_send_control_packet is called to pass the given packet down in the * protocol stack. ** RETURNS: N/A*/LOCAL void bacp_send_configuration_reject	(	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_REJECT_PACKET *sptr_configuration_reject_packet = NULL;	BACP_PACKET *sptr_bacp_rx_packet = NULL;	BACP_STACK_DATA * pStackData = (BACP_STACK_DATA *) pluginState->stackData;	M_BLK_ID rx_packet = pStackData->last_rxed_bacp_configuration_request_packet;	M_BLK_ID packet = NULL;	BYTE rxed_identifier;    PARAMETER_NOT_USED (end_state);    PARAMETER_NOT_USED (pMblk);	if (rx_packet == NULL)		return;	sptr_bacp_rx_packet = mtod (rx_packet, BACP_PACKET *);	rxed_identifier = sptr_bacp_rx_packet->bacp_header.id;	number_of_bytes_to_send = sizeof (PPP_HEADER) + sizeof (BACP_HEADER);	number_of_bytes_to_send = (USHORT) (number_of_bytes_to_send +		get_size_of_ppp_options (&pStackData->option_lists.tx_reject));	/* use the received packet if it is of the required size 									else allocate a new packet */	if (rx_packet->pClBlk->clSize >= number_of_bytes_to_send)		{		/* use received packet */		rx_packet->mBlkHdr.mData = rx_packet->pClBlk->clNode.pClBuf;		rx_packet->mBlkHdr.mLen = 0;		packet = rx_packet;		bzero (packet->mBlkHdr.mData, number_of_bytes_to_send);		}	else		{		netMblkClChainFree (rx_packet);		pStackData->last_rxed_bacp_configuration_request_packet = NULL;				if ((packet = netTupleGet (pStackData->netPoolId,				number_of_bytes_to_send, M_DONTWAIT, MT_DATA, TRUE)) == NULL)			return;		}	/* copy the options */	sptr_configuration_reject_packet = mtod (packet, 										BACP_CONFIGURE_REJECT_PACKET *);	store_ppp_options_in_packet (&pStackData->option_lists.tx_reject,		(PPP_OPTION *) &sptr_configuration_reject_packet->options);	packet->mBlkHdr.mLen = number_of_bytes_to_send;	pStackData->last_rxed_bacp_configuration_request_packet = NULL;    bacp_send_control_packet (pluginState, packet, CONFIGURE_REJECT, 								rxed_identifier);    }/******************************************************************************** bacp_send_termination_request - send BACP termination request packet** This routine is called to send the BACP termination request packet. * This function gets a buffer of the size of the termination request packet * to be sent, using the netPoolId and calls bacp_send_control_packet () to send * the packet.** RETURNS: N/A*/LOCAL void bacp_send_termination_request	(	PFW_PLUGIN_OBJ_STATE * pluginState,		/* state for the stack */	M_BLK_ID pMblk,							/* BACP packet */	PPP_STATE end_state						/* end state */	)	{	BACP_STACK_DATA * pStackData = (BACP_STACK_DATA *) pluginState->stackData;	M_BLK_ID packet = NULL;	PARAMETER_NOT_USED (end_state);	PARAMETER_NOT_USED (pMblk);	if ((packet = netTupleGet (pStackData->netPoolId, sizeof (BACP_TERMINATE_REQUEST),							M_DONTWAIT, MT_DATA, TRUE)) == NULL)		{		logMsg("BACP couldn't get packet for Terminate request \n"											,1,2,3,4,5,6);		return;		}	pStackData->id_sequence_number++;	++pStackData->number_of_termination_requests;	packet->mBlkHdr.mLen = sizeof (BACP_TERMINATE_REQUEST);	bacp_send_control_packet (pluginState,packet, TERMINATION_REQUEST,							pStackData->id_sequence_number);    }/******************************************************************************** bacp_send_termination_ack - send BACP termination ack packet** This routine is called to send the BACP termination ack packet. This function * gets a buffer of the size of the termination ack packet to be sent, * using the netPoolId. bacp_send_control_packet () is called to send the packet.** RETURNS: N/A*/LOCAL void bacp_send_termination_ack	(	PFW_PLUGIN_OBJ_STATE * pluginState,		/* state for the stack */	M_BLK_ID rx_packet,						/* BACP packet */	PPP_STATE end_state						/* end state */	)	{	BACP_TERMINATE_ACK *sptr_termination_ack_packet = NULL;	BACP_STACK_DATA * pStackData = (BACP_STACK_DATA *) pluginState->stackData;	M_BLK_ID packet = pStackData->last_rxed_bacp_termination_request_packet;    PARAMETER_NOT_USED (end_state);    PARAMETER_NOT_USED (rx_packet);	if (packet == NULL) 		{		logMsg("BACP:NULL Terminate request packet while trying \						to send termination ack \n",1,2,3,4,5,6);		return;		}	/* to get the id of the stored received terminate request packet */    sptr_termination_ack_packet = mtod(packet, BACP_TERMINATE_ACK *);    pStackData->last_rxed_bacp_termination_request_packet = NULL;	/* forms the ack packet and sends */    bacp_send_control_packet (pluginState, packet, TERMINATION_ACK,				    sptr_termination_ack_packet->id);    }/******************************************************************************** bacp_send_code_reject - send BACP code reject packet** This routine is called to send the BACP code reject packet. This function * gets a buffer of the size of the code reject packet to be sent, using the * netPoolId. The received packet is copied as the rejected packet, the id is * generated and bacp_send_control_packet () is called with the formed packet,* to send the packet.** RETURNS: N/A*/LOCAL void bacp_send_code_reject	(	PFW_PLUGIN_OBJ_STATE * pluginState,		/* state for the stack */	M_BLK_ID rx_packet,						/* BACP packet */	PPP_STATE end_state						/* end state */	)	{	BACP_CODE_REJECT_PACKET *sptr_code_reject_packet = NULL;	BACP_STACK_DATA * pStackData = (BACP_STACK_DATA *) pluginState->stackData;	M_BLK_ID packet = NULL;	BACP_PACKET *sptr_bacp_rx_packet = NULL;    USHORT number_of_bytes_in_tx_packet = 0;	USHORT number_of_bytes_to_copy = 0;	PARAMETER_NOT_USED (end_state);	if (rx_packet == NULL)		return;	sptr_bacp_rx_packet = mtod (rx_packet, BACP_PACKET *);	/* get the number of bytes to copy */	number_of_bytes_to_copy = ntohs (sptr_bacp_rx_packet->bacp_header.length);	number_of_bytes_in_tx_packet = (USHORT) (sizeof (PPP_HEADER) +				sizeof (BACP_HEADER) + number_of_bytes_to_copy);	/* if bytes to send > remote MRRU, then restrict the packet size */	if (number_of_bytes_in_tx_packet > pStackData->bundleRemoteMRRU)		{			number_of_bytes_in_tx_packet = pStackData->bundleRemoteMRRU 									+ sizeof (PPP_HEADER);		number_of_bytes_to_copy =   number_of_bytes_in_tx_packet -							sizeof (BACP_HEADER);		}	/* allocate the packet of required size */	if ((packet = netTupleGet (pStackData->netPoolId,	    number_of_bytes_in_tx_packet, M_DONTWAIT, MT_DATA, TRUE)) == NULL)		{		netMblkClChainFree (rx_packet);		return;		}	sptr_code_reject_packet = mtod (packet, BACP_CODE_REJECT_PACKET *);		/* copy the received packet as the rejected packet */	memcpy (&sptr_code_reject_packet->rejected_packet,			&sptr_bacp_rx_packet->bacp_header, number_of_bytes_to_copy);	netMblkClChainFree (rx_packet);	pStackData->id_sequence_number++;		packet->mBlkHdr.mLen = number_of_bytes_in_tx_packet;	bacp_send_control_packet (pluginState, packet, CODE_REJECT,					    pStackData->id_sequence_number);    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -