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

📄 pppoptnp.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* pppoptnp.c - options processor *//* Copyright 1999 Wind River Systems, Inc. */#include "copyright_wrs.h"   /*modification history -------------------- 01o,08jul02,as  added changes necessary to support rfc 2472, page 8, par. 401n,28may02,rvr fixed build warnings  01m,17may02,as  added support for IPV6 Interface identifier specific processing                in ppp_configure_request_option_processor and                 ppp_configure_nak_option_processor01m,17jul02,emr  Bring into line for PPP 2.001l,17feb02,vk  modifications in address length validation for class4 				in ppp_configure_request_option_processor ()01k,04feb02,jr	modifications as part of memory reduction01j,04nov01,ijm do not accept option if target has not been configured                to do so, SPR# 68164. fix increment_range_option to handle                ranges for numerical options only: shorts and longs.01i,21may01,sd	changed ppp_configure_nak_option_processor () to remove the EID 				option from the configure request only if 				it is set as negotiable01h,21may01,sd	changed ppp_configure_request_option_processor () to nak the 				invalid EID option values with class 001f,23apr01,sj  in range_option_value_match, local configured values should be             	compared with in Host Byte Order01e,02mar00,sj  in Range checking, fixed case when step == 001d,10feb00,sj  in process_configure_request retry alternate values 01c,14dec99,sj  set length of preferred nak data correctly01b,10nov99,sj  use remote_configured list01a,02oct99,sj 	derived from Routerware source base*//**$Log:: /Rtrware/devdrvrs/ppp/pppoptn $ *  * 7     10/01/98 11:43a Alex * Updated the PPP source code to conform * to a single build.  *  * 6     4/30/98 3:03p Alex * Ppp v4.2.0 check in *  * 1     4/24/98 12:10a Release Engineer * code cleanup, code style changes, * linted, system level test * PPP v4.2.0*/#include "vxWorks.h"#include "stddef.h"#include "stdio.h"#include "ctype.h"#include "string.h"#include "stdlib.h"#include "ppp/kstart.h"#include "ppp/kppp.h"#include "private/ppp/pppoptn.h"#include "private/ppp/pppstate.h"#include "pfw/pfw.h"#include "private/ppp/vlcpstr.h"      /* added EID support - WindNet Multilink */#include "pfw/pfwMemory.h"            /* WindNet Multilink  */#include "pfw/pfwStack.h"             /* WindNet Multilink  */#include "private/ppp/pppNcpLibP.h"   /*  Added to support IPV6 */#include "private/ppp/pppIpv6cpComponentP.h"   /*  Added to support IPV6 */LOCAL OPTION_LIST_ENTRY *find_next_matching_option 			    (OPTION_LIST_ENTRY *sptr_option);LOCAL void increment_range_option (			UNION_OPTION_DATA_TYPES *uptr_matching_option_data,			UNION_OPTION_DATA_TYPES *uptr_step_size,BYTE length);LOCAL ALTERNATE_OPTION *find_alternate_option_to_nak_with(			BYTE nak_option_number_to_match,			OPTION_LIST_ENTRY *sptr_local_option);LOCAL void find_range_option_to_nak_with (BYTE nak_option_number_to_match,			OPTION_LIST_ENTRY *sptr_local_option,			OPTION_LIST_ENTRY *sptr_range_option);/* change from static to non-static - WindNet Multilink */void ppp_negotiation_error (PFW_PLUGIN_OBJ_STATE *pluginState,			OPTION_LIST_ENTRY *sptr_received_option,			OPTION_LISTS *sptr_option_lists);TEST set_option_values_from_nak     (    PFW_OBJ *,    OPTION_LISTS *             sptr_option_lists,    OPTION_LIST_ENTRY *        sptr_local_option    );TEST set_option_values_for_nak     (    PFW_OBJ *,    OPTION_LIST_ENTRY *        sptr_local_option,    OPTION_LIST_ENTRY *        sptr_remote_option    );/* IPV6 Support */LOCAL void nakProcessingCheckForInterfaceIdentifier    (    OPTION_LISTS *            sptr_option_lists,     OPTION_LIST_ENTRY *       sptr_remote_option,    OPTION_LIST_ENTRY *       sptr_local_option,    PFW_PLUGIN_OBJ_STATE *    pPluginState    );extern void generateNewInterfaceIdentifier    (    OPTION_LIST_ENTRY *           sptr_remote_option    );/* IPV6 Support *//* change from static to non-static - WindNet Multilink */#if 0LOCAL BOOLEAN option_is_zero (OPTION_LIST_ENTRY *sptr_remote_option);/******************************************************************************** option_is_zero -*/LOCAL BOOLEAN option_is_zero     (    OPTION_LIST_ENTRY *sptr_remote_option    )    {    if (sptr_remote_option->length == sizeof (USHORT))	{	if (sptr_remote_option->uptr_data->_ushort == 0x0000)	    {	    return (TRUE);	    }	}    if (sptr_remote_option->length == sizeof (ULONG))	{	if (sptr_remote_option->uptr_data->_ulong == 0x00000000L)	    {	    return (TRUE);	    }	}    return (FALSE);    }#endif/******************************************************************************** ppp_configure_request_option_processor -*/TEST ppp_configure_request_option_processor    (    OPTION_LIST_ENTRY *sptr_remote_option,    OPTION_LISTS      *sptr_option_lists,	/* LCP option lists */    PFW_PLUGIN_OBJ_STATE * pluginState    )    {    OPTION_LIST_ENTRY *     sptr_local_option    = NULL;    OPTION_LIST_ENTRY *     sptr_option          = NULL;	BOOL                    eidValid             = TRUE;	int                     valueLength          = 0; /* added - WindNet Multilink */    sptr_local_option = find_matching_option(			    &sptr_option_lists->remote_configured,			    /*&sptr_option_lists->configured,*/			    sptr_remote_option->type.generic);    sptr_option = find_matching_option(			    &sptr_option_lists->configured,			    /*&sptr_option_lists->configured,*/			    sptr_remote_option->type.generic);    /* this should never happen but just in case */    if (sptr_local_option == NULL)	{	return (FAIL); 	}	/* added for EID support - WindNet Multilink */	/* if it is EID then validate the class and address feilds */	if (sptr_remote_option->type.generic == LCP_ENDPOINT_DISCRIMINATOR)  		{		valueLength = sptr_remote_option->length -1; /* length of the address */				if (sptr_remote_option->uptr_data == NULL)			{			sptr_remote_option->length = 1;			sptr_remote_option->uptr_data = 				(UNION_OPTION_DATA_TYPES *) pfwMalloc 				((pfwStackObjPfwGet (pluginState->stackObj))				, sptr_remote_option->length);			if (sptr_remote_option->uptr_data == NULL)			    {	    		printf("PPP: Out of Memory for New Option \r\n");			    return (FAIL);	    		}			bzero ((char *)(sptr_remote_option->uptr_data->byte_array),								 sptr_remote_option->length); 			return FAIL;			}				switch (sptr_remote_option->uptr_data->byte_array [0])			{			case 0:				if (valueLength != 0)					eidValid = FALSE;				break;			case 1:				if ((valueLength <= 0) || (valueLength > 20))					eidValid = FALSE;				break;			case 2:				if (valueLength != 4)					eidValid = FALSE;				break;			case 3:				if (valueLength != 6)					eidValid = FALSE;				break;			case 4:				if ((valueLength != 4) && (valueLength != 8) && 					(valueLength != 12) && (valueLength != 16) &&					(valueLength != 20))					eidValid = FALSE;				break;			case 5:				if (valueLength < 0 || valueLength > 15)					eidValid = FALSE;				break;			default:				eidValid = FALSE;				break;			}		if (eidValid == FALSE)			{			bzero ((char *)(sptr_remote_option->uptr_data->byte_array),						sptr_remote_option->length); 			sptr_remote_option->length = 1;			return FAIL;			}		} 	/* added for EID support - WindNet Multilink *//* IPV6 Support */	/* Added for IPV6 Interface Identifier */    if (strcmp (pluginState->pluginObj->name, "PPP_IPV6CP") == 0)        {   	    if (sptr_remote_option->type.generic == IPV6_INTERFACE_IDENTIFIER_OPTION_TYPE)            {            /* Local and remote IPV6 Interface Identifier equal to zero */            if (memcmp (sptr_remote_option->uptr_data,			                    sptr_option->uptr_data,                                 sptr_local_option->length) == 0)	    		{                return (FAIL);			    }		/* Local and remote IPV6 Interface Identifier are not equal */    		else			    {                int index = 0;                int sum = 0;                 for(index = 0; index < sptr_local_option->length;index++)                    sum += sptr_remote_option->uptr_data->byte_array[index];                            if (sum == 0)                    {        		    return (FAIL);                    }                                }			}		}	/* Added for IPV6 Interface Identifier *//* IPV6 Support */    if (sptr_local_option->option_flags.negotiable == PPP_FLAG_ON) 	{	return (PASS);	}    if (option_value_match (sptr_local_option,sptr_remote_option) != NULL)	{	return (PASS);	}    if (alternate_option_value_match (sptr_local_option,sptr_remote_option)	!= NULL)	{	return (PASS);	}    if (range_option_value_match (sptr_local_option,sptr_remote_option) == TRUE)	{	return (PASS);	}    if (set_option_values_for_nak (pluginState->pluginObj->pfwObj,				sptr_local_option,sptr_remote_option)== FAIL)	{	/* 	 * set_option_values_for_nak resets the nak_option_selected counter 	 * allowing us to start with the first configured value. In this	 * scheme we rely on the MAX_FAILURE (max # naks before a reject) 	 * mechanism to terminate the nak value selection loop	 */	if (set_option_values_for_nak (pluginState->pluginObj->pfwObj,				sptr_local_option,sptr_remote_option)== FAIL)	    {	    ppp_negotiation_error (pluginState, sptr_remote_option,							    sptr_option_lists);	    }	}    return (FAIL);    }/******************************************************************************** option_entry_print -** NOMANUAL*/void option_entry_print    (    OPTION_LIST_ENTRY *sptr_option    )    {    ALTERNATE_OPTION *sptr_alternate_option = NULL;    int i = 0;    if (sptr_option == NULL)        {        printf ("option entry is NULL\n");        return;        }    printf ("<option: %d, ",sptr_option->type.generic);    printf ("length: %d",sptr_option->length);    if (sptr_option->length == sizeof(USHORT))        {        printf (", data: 0x%04x",ntohs(*(USHORT *)sptr_option->uptr_data));        }    else if (sptr_option->length == sizeof(ULONG))        {        printf (", data: 0x%08lx",ntohl(*(ULONG *)sptr_option->uptr_data));        }    else if (sptr_option->length > 0)        {        printf (", data: 0x");        for (i = 0; i<sptr_option->length; i++)            {            printf ("%02x",sptr_option->uptr_data->byte_array[i]);            }        }    printf ("nak_option = %d>\n",            sptr_option->nak_option_selected);    if (sptr_option->option_flags.alternate_checking_enabled)        {        printf ("Alternates: ");          for (sptr_alternate_option =             sptr_option->alternate_option_list.sptr_forward_link;             sptr_alternate_option != NULL;             sptr_alternate_option =                 sptr_alternate_option->links.sptr_forward_link)            {            if (sptr_alternate_option->length == sizeof(USHORT))                printf ("data: 0x%04x",                        ntohs(*(USHORT *)sptr_alternate_option->uptr_data));            else if (sptr_alternate_option->length == sizeof(ULONG))                printf ("data: 0x%08lx",                        ntohl(*(ULONG *)sptr_alternate_option->uptr_data));            else if (sptr_alternate_option->length > 0)                {                printf ("data: 0x");                for (i = 0; i<sptr_alternate_option->length; i++)                    printf ("%02x",                            sptr_alternate_option->uptr_data->byte_array[i]);                }            }        }    printf ("\n");    if (sptr_option->option_flags.range_checking_enabled)        {        if (sptr_option->range_option == NULL)            {            return;            }        printf ("Range values: ");        switch (sptr_option->length)            {            case sizeof (USHORT):                printf ("Min: %d Max: %d Step = %d\n",                  ntohs(sptr_option->range_option->uptr_lowest_value->_ushort),                  ntohs(sptr_option->range_option->uptr_highest_value->_ushort),                  ntohs(sptr_option->range_option->uptr_step->_ushort)                       );                  break;

⌨️ 快捷键说明

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