📄 pppipcpcomponent.c
字号:
/* pppIpcpComponent.c - PPP IP Control Protocol *//* Copyright 1999 Wind River Systems, Inc. */#include "copyright_wrs.h"/* modification history -------------------- 02q,12apr03,ijm fixed compiler warning02p,26nov02,ijm restore default values in link reset handler02o,04oct02,ijm subscribe to PPP_LINK_RESET instead of LCP_DOWN event,SPR 8304202n,09aug02,adb DOC edits02m,01jul02,as Added support for backward compatiblity of vjc compression02l,28may02,rvr fixed build warnings02k,22may02,vk Removed the functions common for ipcp and ipv6cp and created a generic file for both 02k,17jul02,emr Bring into line for PPP 2.002j,26feb02,jr Setting the pointer to NULL after freeing02i,04feb02,vk Modifications in PFW_PARAMETER_GET in ipcp_optionsHandler() to construct the configuration strings from option_list_entry structures02h,04feb02,ak modifications as part of memory reduction process 02g,08nov01,ijm added number_of_configuration_naks and configuration requests limit02f,03nov01,ijm merged router stack changes02e,13apr01,ijm corrected NUMBER_OF_IPCP_OPTIONS comparison from < to <=02d,02mar01,ijm released last_txed_ncp_configuration_request_packet when stack is deleted02c,28feb01,ijm release interfaces when stack is deleted (SPR# 63868)02b,10nov00,sj unregister with m2Lib before deleting component02a,11oct00,sj use PPP_IP_DNS_INTERFACE to set negotiated DNS01z,29sep00,sj merging with TOR2_0-WINDNET_PPP-CUM_PATCH_201y,09aug00,adb support opening connections in passive mode01x,03aug00,sj merging with Openstack to bring in conditional compilation of RAS_AMM01w,01aug00,adb Remove unnecessary socket call; SPR 3337201v,18jul00,qli added compilation #define of RAS inclusion01u,12jul00,qli added RAS AMM support01t,08jul00,bsn merged from the PPP radius-ras branch01s,27jun00,bsn added IPCP_UP and IPCP_DOWN event notifications01r,09jun00,qli bug fix on setting islocalConfig flag01q,22may00,qli bug fix in ipcp_optionsHandler, GET command always calculate strlen 2 bytes short01p,22may00,qli preset isLocalConfig flag prior to calling ipcp_setStackData01o,19may00,qli added RAS support;added ipcp_setStackData utility01n,21mar00,sj fixed bad DESCRIPTION block01m,20mar00,sj added description01l,17mar00,cn corrected usage of compressing connection identifier.01k,14mar00,cn corrected use of max slot identifier in VJC compression.01j,25feb00,sj update MIB variables from accepted lists01i,24feb00,cn added removeAlternateValues.01h,22feb00,sj adding MIB II registrations01g,17feb00,cn fixed build_dns_addr_accepted_parameters to change dns entries only when required. Also added ipcpOptionIndexGet ()01f,10feb00,sj added profileDataCopy and fixed stackDataConstruct01e,04feb00,sgv added DNS neotiation parameters and M2 instrumentation01d,29nov99,sgv added comments01c,12oct99,sgv created from routerware IPCP code01b,22sep99,sgv Modified for the new framework interface01a,12jun99,sgv written*//*DESCRIPTIONThis module implements IPCP specified in RFC 1332 and Name Server Extensions specified in RFC 1877INCLUDE FILES pppIpcpComponent.h */#include "ppp/pppIpcpComponent.h"#include "private/ppp/pppIpcpComponentP.h"#include "private/ppp/pppNcpLibP.h" #include "ppp/m2pppIpcpGroup.h"#include "inetLib.h"#include "ppp/rasamm.h"#include "ppp/interfaces/pppHcInterfaces.h"#include "private/ppp/pppIpState.h"/* defines *//* * these are indexes in the IPCP_OPTION_TYPE enum defined in kppp.h of * the related IPCP options types */#define IP_PRIMARY_DNS_ADDRESS_INDEX 0x4#define IP_SECONDARY_DNS_ADDRESS_INDEX 0x5#define IP_HEADER_COMPRESSION_INDEX 0x6 typedef struct ipcpParams { char * name; PFW_PARAMETER_HANDLER handler; } IPCP_PARAMS;LOCAL STATUS ipcp_IpAddr (PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE, void *, char *);LOCAL STATUS ipcp_VJC (PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE, void *, char *);LOCAL STATUS ipcp_HC (PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE, void *, char *);LOCAL STATUS ipcp_primaryDnsAddr (PFW_OBJ *pfw, PFW_PARAMETER_OPERATION_TYPE type, void *pData, char *value);LOCAL STATUS ipcp_secondaryDnsAddr (PFW_OBJ *pfw, PFW_PARAMETER_OPERATION_TYPE type, void *pData, char *value);LOCAL STATUS ipcp_optionsHandler ( PFW_OBJ *pfwObj, IPCP_OPTION_TYPE optionType, PFW_PARAMETER_OPERATION_TYPE type, void *pData, char *value);void ipcpInterfacesInit ( PPP_IPCP_COMPONENT * pComponent);/* Component Interfaces */LOCAL STATUS ipcpOptionIndexGet (char * optionName, IPCP_OPTION_TYPE optionType);LOCAL STATUS profileDataConstruct (PFW_OBJ *pfw, void *profileData);LOCAL STATUS ipcpProfileDataCopy ( PFW_OBJ *, void * srcProfileData, void * dstProfileData);LOCAL STATUS profileDataDestruct ( PFW_OBJ * pfw, void * profileData);LOCAL STATUS ipcpSend (PFW_PLUGIN_OBJ_STATE *state, M_BLK_ID * pkt);LOCAL STATUS ipcpReceive (PFW_PLUGIN_OBJ_STATE *state, M_BLK_ID * pkt);LOCAL STATUS stackAdd (PFW_PLUGIN_OBJ_STATE *state, PFW_PLUGIN_OBJ_CALLBACKS * callbacks);LOCAL STATUS stackDelete (PFW_PLUGIN_OBJ_STATE *state);LOCAL STATUS stackDataDestruct (PFW_OBJ *pfw, void * stackData, void * profileData);LOCAL STATUS stackDataConstruct (PFW_OBJ *pfw, void * stackData, void * profileData);LOCAL STATUS ipcpInterfaceBind (PFW_PLUGIN_OBJ * pluginObj);/* NCP event handlers */LOCAL STATUS setStackLRIpAddrFromRAS(PFW_PLUGIN_OBJ_STATE * componentState, void *eventData);LOCAL STATUS relStackLRIpAddrToRAS(PFW_PLUGIN_OBJ_STATE * componentState, void *eventData);/* utilities */LOCAL void removeAlternateValues (IPCP_CONFIG_STRINGS * ipcpOption, char * remoteOrLocal);LOCAL STATUS ipcp_setStackData (PFW_OBJ * pfw, IPCP_PROFILE_DATA * pData, IPCP_CONFIG_OPTION * ipcpOption, char *value);LOCAL void ipcpOptionConfigStringsFree (IPCP_CONFIG_STRINGS *);void initialize_ipcp_mibs ( PFW_PLUGIN_OBJ_STATE * pPfwPlugingObjState );char * getIpcpOptionName ( PFW_OBJ * pfw, char * optionName );IMPORT void ncpLinkReset (NCP_STACK_DATA * pNcpStackData);IMPORT void get_value_string ( UNION_OPTION_DATA_TYPES * pData, BYTE length, char * pValue_type_string, char * pValue_string, UNION_OPTION_TYPES optionType, char * pOptionName );IMPORT void ipcpSetSendActionFunctions ( STATE_MACHINE_ACTION_TABLE * actionTable );/* IPCP state Action table */STATE_MACHINE_ACTION_TABLE ipcpStateActionTable = { ipcp_set_ppp_state, ipcp_null_state, ipcp_this_layer_start, ipcp_this_layer_finished, ipcp_this_layer_up, ipcp_this_layer_down, ipcp_initialize_restart_counter, ipcp_zero_restart_counter, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, };LOCAL IPCP_PARAMS ipcpParams[] = { {"ipcp_ipAddr",ipcp_IpAddr}, {"ipcp_vjcParams",ipcp_VJC}, {"ipcp_hcParams",ipcp_HC}, {"ipcp_maxConfigRequests",ipcp_maxConfigRequests}, {"ipcp_primaryDnsAddr",ipcp_primaryDnsAddr}, {"ipcp_secondaryDnsAddr",ipcp_secondaryDnsAddr}, {"ipcp_configReqSendInterval",ipcp_configReqSendInterval}, {"ipcp_maxTerminationRequests",ipcp_maxTerminationRequests}, {"ipcp_terminationReqInterval",ipcp_TerminationReqInterval} }; LOCAL int numIpcpParams = NELEMENTS (ipcpParams);/********************************************************************************* pppIpcpComponentCreate - initialize and add the IPCP component to framework** This component implements the rfc 1332** RETURNS: OK or ERROR*/STATUS pppIpcpComponentCreate ( PFW_OBJ *pfw ) { PPP_IPCP_COMPONENT *pComponent = NULL; PFW_PLUGIN_OBJ *ipcpPluginObj = NULL; IPCP_CONFIG_OPTION *ipcpOption = NULL; PPP_NCP_COMPONENT *pNcpComponent = NULL; int i = 0; pComponent = (PPP_IPCP_COMPONENT *) pfwMalloc (pfw, sizeof (PPP_IPCP_COMPONENT)); if (pComponent == NULL) { printf ("pppIpcpInit - Unable to allocate memory\n"); return (ERROR); } pNcpComponent = (PPP_NCP_COMPONENT *) &(pComponent->pppNcpComponent); bzero ((char *)pComponent, sizeof (PPP_IPCP_COMPONENT)); ipcpPluginObj = (PFW_PLUGIN_OBJ *) &(pNcpComponent->pfwComponentObj); strcpy (ipcpPluginObj->name, "PPP_IPCP"); ipcpPluginObj->pfwObj = pfw; ipcpPluginObj->profileDataSize = sizeof (IPCP_PROFILE_DATA); ipcpPluginObj->stackDataSize = sizeof (IPCP_STACK_DATA); ipcpPluginObj->profileDataConstruct = profileDataConstruct; ipcpPluginObj->profileDataCopy = ipcpProfileDataCopy; ipcpPluginObj->profileDataDestruct = profileDataDestruct; ipcpPluginObj->receive = ipcpReceive; ipcpPluginObj->send = ipcpSend; ipcpPluginObj->stackAdd = stackAdd; ipcpPluginObj->stackDelete = stackDelete; ipcpPluginObj->stackDataShow = NULL; ipcpPluginObj->stackDataConstruct = stackDataConstruct; ipcpPluginObj->stackDataDestruct = stackDataDestruct; ipcpPluginObj->interfaceBind = ipcpInterfaceBind; pNcpComponent->pfwComponentObj.protocol = IPCP_PROTOCOL; pNcpComponent->pfwComponentObj.layerObj = (struct pfwLayerObj *) pfwLayerObjGet (pfw, "CONTROL_LAYER"); if (pfwComponentAdd (&pNcpComponent->pfwComponentObj) == ERROR) { printf ("pppIpcpInit - IPCP could not be added to the framework\n"); return (ERROR); } /* Add configuration parameters */ for (i = 0; i < numIpcpParams; i++) { if (pfwParameterAdd (ipcpPluginObj, ipcpParams[i].name, ipcpParams[i].handler) == ERROR) { printf ("pppIpcpComponent: Parameter %s could not be added\n",ipcpParams[i].name); return (ERROR); } } /* * HC and VJC are added to the framework and for both the Option type will * be 2. But both will be having a diffrent name */ /* IP HC option */ ipcpOption = &pComponent->option[ipcpOptionIndexGet ("HC", IP_COMPRESSION_OPTION_TYPE)]; ipcpOption->optionType = IP_COMPRESSION_OPTION_TYPE; bzero(ipcpOption->optionTypeString,sizeof(ipcpOption->optionTypeString)); strcpy(ipcpOption->optionTypeString,"NBO"); bzero(ipcpOption->name,sizeof(ipcpOption->name)); strcpy(ipcpOption->name,"IP Compression"); /* IP VJC option */ ipcpOption = &pComponent->option[ipcpOptionIndexGet ("VJC", IP_COMPRESSION_OPTION_TYPE)]; ipcpOption->optionType = IP_COMPRESSION_OPTION_TYPE; bzero (ipcpOption->optionTypeString, sizeof (ipcpOption->optionTypeString)); strcpy (ipcpOption->optionTypeString, "H4"); bzero (ipcpOption->name, sizeof (ipcpOption->name)); strcpy (ipcpOption->name, "VJC Compression"); /* IP address */ ipcpOption = &pComponent->option[ipcpOptionIndexGet ("IP", IP_ADDRESS_OPTION_TYPE)]; ipcpOption->optionType = IP_ADDRESS_OPTION_TYPE; bzero(ipcpOption->optionTypeString,sizeof(ipcpOption->optionTypeString)); strcpy(ipcpOption->optionTypeString,"IP"); bzero(ipcpOption->name,sizeof(ipcpOption->name)); strcpy(ipcpOption->name,"IP ADDRESS"); /* Primary DNS address */ ipcpOption = &pComponent->option[ipcpOptionIndexGet ("DNS", PRIMARY_DNS_ADDRESS)]; ipcpOption->optionType = PRIMARY_DNS_ADDRESS; bzero(ipcpOption->optionTypeString,sizeof(ipcpOption->optionTypeString)); strcpy(ipcpOption->optionTypeString,"IP"); bzero(ipcpOption->name,sizeof(ipcpOption->name)); strcpy(ipcpOption->name,"PRIMARY DNS SERVER IP ADDRESS"); /* Secondary DNS address */ ipcpOption = &pComponent->option[ipcpOptionIndexGet ("SDNS", SECONDARY_DNS_ADDRESS)]; ipcpOption->optionType = SECONDARY_DNS_ADDRESS; bzero(ipcpOption->optionTypeString,sizeof(ipcpOption->optionTypeString)); strcpy(ipcpOption->optionTypeString,"IP"); bzero(ipcpOption->name,sizeof(ipcpOption->name)); strcpy(ipcpOption->name,"SECONDARY DNS SERVER IP ADDRESS"); ipcpSetSendActionFunctions (&ipcpStateActionTable); /* publish the event we'll raise when we attain OPENED state */ if (pfwEventPublish (pfw,"IPCP_UP_EVENT") == NULL) { printf ("IPCP_UP_EVENT publish failed \n"); return ERROR; } /* publish the event we'll raise when we go out of OPENED state */ if (pfwEventPublish(pfw,"IPCP_DOWN_EVENT") == NULL) { printf ("IPCP_DOWN_EVENT publish failed \n"); return ERROR; } return (OK); }/********************************************************************************* pppIpcpComponentDelete - delete the IPCP component from the framework** The IPCP plugin object which is allocated by the pppIpcpComponentCreate is* freed if there is no active reference to this object from a stack or* profile object in the framework.** RETURNS: OK or ERROR*/STATUS pppIpcpComponentDelete ( PFW_OBJ *pfw ) { PFW_COMPONENT_OBJ *pComponent = NULL; pComponent = pfwComponentObjGetByName (pfw, "PPP_IPCP"); if (pComponent == NULL) return ERROR; m2pppIpcpGroupUnregister (pfw); if (pfwComponentDelete (pComponent) == OK) { pfwFree (pComponent); pComponent = NULL; return OK; } return (ERROR); }/******************************************************************************** ipcpInterfaceBind -*/LOCAL STATUS ipcpInterfaceBind ( PFW_PLUGIN_OBJ * pluginObj ) { PPP_IPCP_MIB_INTERFACE * ipcpMibStatusEntry = NULL; PPP_IPCP_COMPONENT * pComponent = (PPP_IPCP_COMPONENT *)pluginObj; PFW_OBJ * pfw = pluginObj->pfwObj; int i = 0; CONTROL_PROTOCOL_INTERFACE * ipcpControlInterface = NULL; /* get CONTROL_PROTOCOL_INTERFACE ID and bind to it */ if ((i = pfwInterfaceIdGet(pfw, "CONTROL_PROTOCOL_INTERFACE")) > 0) { ipcpControlInterface = &pComponent->ipcpControlInterface; ipcpControlInterface->interfaceObj.id = i; ipcpControlInterface->interfaceObj.pluginObj = pluginObj; ipcpControlInterface->pppPhaseGet = ipcp_pppPhaseGet; ipcpControlInterface->pppStateGet = ipcp_pppStateGet; ipcpControlInterface->executeStateMachine = execute_ppp_state_machine; pfwInterfaceBind (&ipcpControlInterface->interfaceObj); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -