From: chas w. <ch...@us...> - 2003-07-19 21:07:22
|
Update of /cvsroot/linux-atm/linux-atm/src/ilmid In directory sc8-pr-cvs1:/tmp/cvs-serv29312 Modified Files: Tag: V2_5_0 Makefile.am atmf_uni.c atmf_uni.h ilmid.c io.c io.h message.c message.h mib.c mib.h Added Files: Tag: V2_5_0 actions.c actions.h ilmid.8 ilmid.h states.c states.h wait.c wait.h Log Message: ilmi updates from ek...@cm... --- NEW FILE: actions.c --- #include <unistd.h> #include <stdlib.h> #include <sys/time.h> #include <errno.h> #include "asn_incl.h" #include "rfc1155_smi.h" #include "rfc1157_snmp.h" #include "message.h" #include "util.h" #include "io.h" #include "atmd.h" #include "mib.h" #include "atmf_uni.h" #include "sysgroup.h" #include "ilmid.h" #define COMPONENT "ILMI" extern struct attachment_point *apoint; extern int retries; extern long int requestID; void action_A1( int fd, Msgs *msgs ){ /* Reset Uptime */ diag( COMPONENT, DIAG_INFO, "Action A1: reset uptime" ); resetUpTime(); } void action_A2( int fd, Msgs *msgs ){ /* Reset Attachment Point */ diag( COMPONENT, DIAG_INFO, "Action A2: reset attachment point" ); /* should probably use reset_apoint() here */ if( apoint->atmfPortMyIfName.octs ){ free( apoint->atmfPortMyIfName.octs ); apoint->atmfPortMyIfName.octs = NULL; } memset( apoint, 0, sizeof( struct attachment_point )); } void action_A3( int fd, Msgs *msgs ){ /* Set Attachment Point */ /* This doesn't really exist */ /* see copy_attachment_point() */ diag( COMPONENT, DIAG_INFO, "Action A3: set attachment point" ); } void action_A4( int fd, Msgs *msgs ){ /* Clear Tables */ diag( COMPONENT, DIAG_INFO, "Action A4: clear tables" ); deleteNetPrefix(); } void action_A5( int fd, Msgs *msgs ){ /* start timer */ /* Our timer is provided by select() */ diag( COMPONENT, DIAG_INFO, "Action A5: start timer" ); } void action_A6( int fd, Msgs *msgs ){ /* stop timer */ diag( COMPONENT, DIAG_INFO, "Action A6: stop timer" ); } void action_A7( int fd, Msgs *msgs ){ diag( COMPONENT, DIAG_INFO, "Action A7: clear retries" ); retries = 0; } void action_A8( int fd, Msgs *msgs ){ diag( COMPONENT, DIAG_INFO, "Action A8: increment retries" ); retries++; } void action_A9( int fd, Msgs *msgs ){ /* clear all SVCs */ /* not sure how to do this, yet */ diag( COMPONENT, DIAG_INFO, "Action A9: release SVCs" ); } void action_A10( int fd, Msgs *msgs ){ diag( COMPONENT, DIAG_INFO, "Action A10: start signalling" ); /* not sure how to do this, yet */ } void action_A11( int fd, Msgs *msgs ){ diag( COMPONENT, DIAG_INFO, "Action A11: set coldstart" ); (msgs->coldstart)->data->a.trap->time_stamp = accessUpTime(); send_message( fd, msgs->coldstart ); } /* Attachment point info */ /* ILMI spec - page 90 */ void action_A12( int fd, Msgs *msgs ){ diag( COMPONENT, DIAG_INFO, "Action A12: get attachment point" ); msgs->apointmsg->data->a.get_next_request->request_id = ++requestID; send_message( fd, msgs->apointmsg ); } /* Configuration info */ /* ILMI spec - page 90 */ void action_A13( int fd, Msgs *msgs ){ Message *config; diag( COMPONENT, DIAG_INFO, "Action A13: get configuration" ); /* don't actually get all of the config info -- we probably will not be using much of it anyway */ config = msgs->config; config->data->a.get_next_request->request_id = ++requestID; send_message( fd, config ); } void action_A14( int fd, Msgs *msgs ){ diag( COMPONENT, DIAG_INFO, "Action A14: send getNextRequest" ); msgs->addrtable->data->a.get_next_request->request_id = ++requestID; send_message( fd, msgs->addrtable ); } void action_A15( int fd, Msgs *msgs ){ diag( COMPONENT, DIAG_INFO, "Action A15: send set request" ); msgs->set->data->a.get_next_request->request_id = ++requestID; send_message( fd, msgs->set ); } void action_get_sysgroup( int fd, Msgs *msgs ){ diag( COMPONENT, DIAG_INFO, "Action Get Sysgroup: request system mib" ); msgs->sysmsg->data->a.get_request->request_id = ++requestID; send_message( fd, msgs->sysmsg ); } --- NEW FILE: actions.h --- #ifndef __ACTIONS_H #define __ACTIONS_H #include "ilmid.h" void action_A1( int fd, Msgs *msgs ); void action_A2( int fd, Msgs *msgs ); void action_A3( int fd, Msgs *msgs ); void action_A4( int fd, Msgs *msgs ); void action_A5( int fd, Msgs *msgs ); void action_A6( int fd, Msgs *msgs ); void action_A7( int fd, Msgs *msgs ); void action_A8( int fd, Msgs *msgs ); void action_A9( int fd, Msgs *msgs ); void action_A10( int fd, Msgs *msgs ); void action_A11( int fd, Msgs *msgs ); void action_A12( int fd, Msgs *msgs ); void action_A13( int fd, Msgs *msgs ); void action_A14( int fd, Msgs *msgs ); void action_A15( int fd, Msgs *msgs ); void action_get_sysgroup( int fd, Msgs *msgs ); #endif --- NEW FILE: ilmid.8 --- .\" .TH ilmid 1 "2 Aug 2001" .SH NAME ilmid \- Integrated Local Management Interface Daemon .SH SYNOPSIS .B ilmid [ .B \-b ] [ .B \-d ] [ .B \-v ] [ .BI \-l\ logfile ] [ .B \-x ] [ .BI \-q\ qos ] [ .BI \-i\ local_ip ] [ .BI \-u\ uni ] <interface> .SH PARAMETERS .TP 15 .B \-b Puts the process in the background. .TP 15 .B \-d Turn on debugging output. .TP 15 .B \-v Verbose. .TP 15 .BI \-l\ logfile Set the location of the log file. .TP 15 .B \-x No var bindings? .TP 15 .BI \-q\ qos Set the qos parameters to use on the ilmi VC. .TP 15 .BI \-i\ local_ip the address that should be used by the switch for network management. .TP 15 .BI \-u\ uni uni version. This can be 3.0, 3.1 or 4.0. .SH DESCRIPTION ilmid implements SNMP on an ATM PVC. It is used to negotiate operating parameters with a switch. .SH SEE ALSO .BR atmsigd (8) --- NEW FILE: ilmid.h --- #ifndef __ILMID_H #define __ILMID_H #define ECOLDSTART 1 #define ETIMEOUT 2 #define ESETPREFIX 3 #define EALARM 4 #include "message.h" #include "asn1/asn_incl.h" typedef struct { Message *apointmsg; Message *coldstart; Message *addrtable; Message *poll; Message *set; Message *config; Message *sysmsg; } Msgs; typedef struct attachment_point { AsnOcts atmfPortMyIfName; AsnInt atmfPortMyIfIdentifier; AsnOcts atmfMySystemIdentifier; AsnInt sysUpTime; // char sysIdMem[6]; } AttPoint; typedef struct configuration_info { AsnInt atmfAtmLayerUniVersion; AsnInt atmfAtmLayerMaxVpiBits; AsnInt atmfAtmLayerMaxVciBits; AsnInt atmfAtmLayerUniType; AsnInt atmfAtmLayerDeviceType; AsnInt atmfAddressRegistrationAdminStatus; } Config; typedef struct __sysgroup { AsnOcts sysDescr; AsnOcts sysObjectID; AsnInt sysUpTime; AsnOcts sysContact; AsnOcts sysName; AsnOcts sysLocation; AsnInt sysServices; } SysGroup; typedef enum _State { up, down } State; #endif --- NEW FILE: states.c --- #include <unistd.h> #include <sys/time.h> #include <errno.h> #include "asn_incl.h" #include "rfc1155_smi.h" #include "rfc1157_snmp.h" #include "message.h" #include "util.h" #include "io.h" #include "atmd.h" #include "mib.h" #include "atmf_uni.h" #include "states.h" #include "ilmid.h" #include "actions.h" #include "wait.h" extern int retries; extern int ilmi_errno; extern long int requestID; extern AsnOid *esi_oid; extern AttPoint *apoint; extern Config *config; extern int alarm_flag; extern State ilmi_state; extern AttPoint *newapoint; Message *wait_for_response( int fd, int itf, Msgs *msgs, int sec ); void copy_attachment_point( AttPoint *, AttPoint * ); int compare_attachment_point( AttPoint *, AttPoint * ); #define RESPONSE_TIMEOUT 2 #define POLL_PERIOD 15 #define COMPONENT "ILMI" /* state functions */ int state_stopped( int fd, int itf, Msgs *msgs ){ diag( COMPONENT, DIAG_INFO, "State S1: stopped" ); ilmi_state = down; action_A1( fd, msgs ); /* reset uptime */ action_A2( fd, msgs ); /* reset attachment point info */ action_A4( fd, msgs ); /* clear tables */ return S2; } int state_failing( int fd, int itf, Msgs *msgs ){ Message *m; diag( COMPONENT, DIAG_INFO, "State S2: failing" ); ilmi_state = down; action_A11( fd, msgs ); /* send coldstart */ action_A12( fd, msgs ); /* send "get" for attachment point */ /* continue to ask for attachment point as long as it times out */ while(( m = wait_for_attachment_point( fd, itf, msgs )) == NULL ){ if( ilmi_errno == ECOLDSTART ) return S1; action_A11( fd, msgs ); /* send coldstart */ action_A12( fd, msgs ); /* send "get" for attachment point */ } action_A11( fd, msgs ); /* one more for good measure */ return S3; } int state_establishing( int fd, int itf, Msgs *msgs ){ Message *m; diag( COMPONENT, DIAG_INFO, "State S3: establishing" ); ilmi_state = down; /* if they are the same ... */ if( compare_attachment_point( apoint, newapoint ) == 0 ){ action_A13( fd, msgs ); /* request config */ } else{ // reset_apoint( apoint ); /* copy( dest, src ) */ copy_attachment_point( apoint, newapoint ); /* action_A3 */ action_A9( fd, msgs ); /* release SVCs */ action_A13( fd, msgs ); /* request config */ action_A7( fd, msgs ); /* retries = 0 */ action_A5( fd, msgs ); /* start timer */ } while(( m = wait_for_config( fd, itf, msgs )) == NULL ){ if( ilmi_errno == ETIMEOUT ) action_A13( fd, msgs ); else if( ilmi_errno == ECOLDSTART ) return S1; } return S4; } int state_config( int fd, int itf, Msgs *msgs ){ Message *tmp; int newstate = S1; diag( COMPONENT, DIAG_INFO, "State S4: config" ); ilmi_state = down; if( config->atmfAtmLayerUniVersion == 0 ){ diag( COMPONENT, DIAG_ERROR, "remote IME did not negotiate " "a UNI version -- using configured uni version." ); } else if( config->atmfAtmLayerUniVersion < atmfAtmLayerUniVersionValue ){ diag( COMPONENT, DIAG_ERROR, "remote IME does not support" " the locally configured uni version" ); atmfAtmLayerUniVersionValue = config->atmfAtmLayerUniVersion; } if( config->atmfAtmLayerDeviceType == 2 /* NODE */ ){ action_A6( fd, msgs ); /* stop timer */ action_A10( fd, msgs ); /* Start signalling */ action_A14( fd, msgs ); /* request address status */ action_A7( fd, msgs ); /* retries = 0 */ action_A5( fd, msgs ); /* start timer */ newstate = S5; /* retrieve network prefixes */ } else if( config->atmfAtmLayerDeviceType == 1 /* USER */ ){ diag( COMPONENT, DIAG_ERROR, "Remote device is also a host" ); action_A10( fd, msgs ); /* start signalling */ action_A14( fd, msgs ); /* get next prefix */ action_A7( fd, msgs ); /* retries = 0 */ action_A5( fd, msgs ); /* start timer */ newstate = S6; } else if( config->atmfAtmLayerDeviceType == 0 /* ??? */ ){ diag( COMPONENT, DIAG_ERROR, "Remote IME does not know " "what type of device it is -- assume NODE" ); action_A6( fd, msgs ); /* stop timer */ action_A10( fd, msgs ); /* Start signalling */ action_A14( fd, msgs ); /* request address status */ action_A7( fd, msgs ); /* retries = 0 */ action_A5( fd, msgs ); /* start timer */ newstate = S5; /* retrieve network prefixes */ } while(( tmp = wait_for_status( fd, itf, msgs )) == NULL ){ if( ilmi_errno == ETIMEOUT ){ action_A14( fd, msgs ); /* request address status */ action_A8( fd, msgs ); /* retries++ */ action_A5( fd, msgs ); /* start timer */ } else if( ilmi_errno == ECOLDSTART ){ return S1; } } action_get_sysgroup( fd, msgs ); while(( tmp = wait_for_sysgroup( fd, itf, msgs )) == NULL ){ if( ilmi_errno == ETIMEOUT ){ action_get_sysgroup( fd, msgs ); action_A8( fd, msgs ); /* retries++ */ action_A5( fd, msgs ); /* start timer */ } else if( ilmi_errno == ECOLDSTART ){ return S1; } } return newstate; } int state_retrievePrefixes( int fd, int itf, Msgs *msgs ){ int newstate = S1; diag( COMPONENT, DIAG_INFO, "State S5: retrieve prefixes" ); ilmi_state = down; /* assume address registration is supported on peer */ wait_for_prefix( fd, itf, msgs ); newstate = S6; /* register network prefixes */ return newstate; } int state_registerPrefixes( int fd, int itf, Msgs *msgs ){ Message *m; diag( COMPONENT, DIAG_INFO, "State S6: register prefixes" ); ilmi_state = down; /* If RegistrationAdminStatus == 0, switch is confused. Assume * it supports registration. */ if(( config->atmfAddressRegistrationAdminStatus == 1 ) || ( config->atmfAddressRegistrationAdminStatus == 0 )){ action_A6( fd, msgs ); /* stop timer */ action_A15( fd, msgs ); /* set request for table entry */ action_A7( fd, msgs ); /* retries = 0 */ action_A5( fd, msgs ); /* start timer */ while(( m = wait_for_setresponse( fd, itf, msgs )) == NULL ){ if( ilmi_errno == ETIMEOUT ){ /* set request for table entry */ action_A15( fd, msgs ); action_A8( fd, msgs ); /* retries++ */ action_A5( fd, msgs ); /* start timer */ } else if( ilmi_errno == ECOLDSTART ){ return S1; } } } else{ diag( COMPONENT, DIAG_ERROR, "address registration not supported" ); action_A6( fd, msgs ); /* stop timer */ action_A12( fd, msgs ); /* request a.point */ action_A7( fd, msgs ); /* retries = 0 */ action_A5( fd, msgs ); /* start timer */ } return S9; /* verify */ } int state_retrieveAddresses( int fd, int itf, Msgs *msgs ){ /* This would only be called on a switch -- not yet implemented */ diag( COMPONENT, DIAG_INFO, "State S7: retrieve addresses" ); ilmi_state = down; return S9; } int state_registerAddresses( int fd, int itf, Msgs *msgs ){ /* not yet implemented */ diag( COMPONENT, DIAG_INFO, "State S8: register addresses" ); ilmi_state = down; return S9; } /* Should spend most of our time here */ /* ask for updates. if new prefix is set, update and notify user */ int state_verify( int fd, int itf, Msgs *msgs ){ Message *m; diag( COMPONENT, DIAG_INFO, "State S9: verify" ); ilmi_state = up; action_A6( fd, msgs ); /* stop timer */ action_A7( fd, msgs ); /* retries = 0 */ action_A5( fd, msgs ); /* start timer */ m = wait_for_response( fd, itf, msgs, POLL_PERIOD ); if(( m == NULL ) && ( ilmi_errno == ECOLDSTART )){ return S1; } else if( ilmi_errno == EALARM ){ /* interface information must be no older than 30 seconds */ alarm_flag = 0; action_A12( fd, msgs ); /* request attachment point */ while((( m = wait_for_attachment_point( fd, itf, msgs )) == NULL ) && ( retries < 4 )){ action_A12( fd, msgs ); action_A8( fd, msgs ); } if( retries >= 4 ) return S2; /* check for attachment point change */ } return S9; } --- NEW FILE: states.h --- #ifndef __STATES_H #define __STATES_H #include "message.h" #include "asn1/asn_incl.h" #include "ilmid.h" /* Ilmi states */ #define S1 0 #define S2 1 #define S3 2 #define S4 3 #define S5 4 #define S6 5 #define S7 6 #define S8 7 #define S9 8 #define STATES 9 int state_stopped( int fd, int itf, Msgs *msgs ); int state_failing( int fd, int itf, Msgs *msgs ); int state_establishing( int fd, int itf, Msgs *msgs ); int state_config( int fd, int itf, Msgs *msgs ); int state_retrievePrefixes( int fd, int itf, Msgs *msgs ); int state_registerPrefixes( int fd, int itf, Msgs *msgs ); int state_retrieveAddresses( int fd, int itf, Msgs *msgs ); int state_registerAddresses( int fd, int itf, Msgs *msgs ); int state_verify( int fd, int itf, Msgs *msgs ); #endif --- NEW FILE: wait.c --- #include <unistd.h> #include <stdlib.h> #include <sys/time.h> #include <errno.h> #include "asn_incl.h" #include "rfc1155_smi.h" #include "rfc1157_snmp.h" #include "message.h" #include "util.h" #include "io.h" #include "atmd.h" #include "mib.h" #include "atmf_uni.h" #include "sysgroup.h" #include "ilmid.h" extern int ilmi_errno; extern AttPoint *apoint; extern Config *config; extern SysGroup *remsys; Message *wait_for_response( int fd, int itf, Msgs *msgs, int sec ); void copy_attachment_point( AttPoint *, AttPoint * ); int compare_attachment_point( AttPoint *, AttPoint * ); extern AttPoint *newapoint; #define RESPONSE_TIMEOUT 2 #define POLL_PERIOD 15 #define COMPONENT "ILMI" /* support functions */ #define RESP_RID(x) ((x)->data->a.get_response->request_id) #define GETNEXT_RID(x) ((x)->data->a.get_next_request->request_id) void reset_apoint( AttPoint *a ){ if( a->atmfPortMyIfName.octs != NULL ){ free( a->atmfPortMyIfName.octs ); a->atmfPortMyIfName.octs = NULL; } if( a->atmfMySystemIdentifier.octs != NULL ){ free( a->atmfMySystemIdentifier.octs ); a->atmfMySystemIdentifier.octs = NULL; } memset( a, 0, sizeof( AttPoint )); } static void reset_remsys( void ){ if( remsys->sysDescr.octs != NULL ) free( remsys->sysDescr.octs ); if( remsys->sysObjectID.octs != NULL ) free( remsys->sysObjectID.octs ); if( remsys->sysContact.octs != NULL ) free( remsys->sysContact.octs ); if( remsys->sysName.octs != NULL ) free( remsys->sysName.octs ); if( remsys->sysLocation.octs != NULL ) free( remsys->sysLocation.octs ); memset( remsys, 0, sizeof( SysGroup )); } void wait_for_prefix( int fd, int itf, Msgs *msgs ){ while(( wait_for_response( fd, itf, msgs, RESPONSE_TIMEOUT ) != NULL ) && ( ilmi_errno != ESETPREFIX )); } static void AsnOctsCopy( dest, src ) AsnOcts *dest; AsnOcts *src; { if( src->octetLen > 0 ){ dest->octs = (char *)malloc( src->octetLen + 1 ); memset( dest->octs, 0, src->octetLen + 1 ); dest->octetLen = src->octetLen; memcpy( dest->octs, src->octs, src->octetLen ); } else { dest->octs = (char *)malloc( 8 ); dest->octetLen = 8; memcpy( dest->octs, "(empty)\0", 8 ); } } Message *wait_for_sysgroup( int fd, int itf, Msgs *msgs ){ Message *m = NULL; VarBind *varbind; VarBindList *vbl; m = wait_for_response( fd, itf, msgs, RESPONSE_TIMEOUT ); if( m == NULL ) return NULL; while( GETNEXT_RID( msgs->sysmsg ) != RESP_RID( m )) m = wait_for_response( fd, itf, msgs, RESPONSE_TIMEOUT ); reset_remsys(); vbl = m->data->a.get_response->variable_bindings; FOR_EACH_LIST_ELMT( varbind, vbl ){ if( AsnOidCompare( &sysDescr, &varbind->name ) == AsnOidEqual ){ AsnOctsCopy( &remsys->sysDescr, varbind->value->a.simple->a.string ); } else if( AsnOidCompare( &sysObjectID, &varbind->name ) == AsnOidEqual ){ AsnOctsCopy( &remsys->sysObjectID, varbind->value->a.simple->a.string ); } else if( AsnOidCompare( &sysUpTime, &varbind->name ) == AsnOidEqual ){ remsys->sysUpTime = varbind->value->a.simple->a.number; } else if( AsnOidCompare( &sysContact, &varbind->name ) == AsnOidEqual ){ AsnOctsCopy( &remsys->sysContact, varbind->value->a.simple->a.string ); } else if( AsnOidCompare( &sysName, &varbind->name ) == AsnOidEqual ){ AsnOctsCopy( &remsys->sysName, varbind->value->a.simple->a.string ); } else if( AsnOidCompare( &sysLocation, &varbind->name ) == AsnOidEqual ){ AsnOctsCopy( &remsys->sysLocation, varbind->value->a.simple->a.string ); } else if( AsnOidCompare( &sysServices, &varbind->name ) == AsnOidEqual ){ remsys->sysServices = varbind->value->a.simple->a.number; } } return m; } Message *wait_for_attachment_point( int fd, int itf, Msgs *msgs ){ Message *m = NULL; VarBind *varbind; VarBindList *vbl; m = wait_for_response( fd, itf, msgs, RESPONSE_TIMEOUT ); if( m == NULL ) return NULL; while( GETNEXT_RID( msgs->apointmsg ) != RESP_RID( m )){ m = wait_for_response( fd, itf, msgs, RESPONSE_TIMEOUT ); if( m == NULL ) return NULL; } reset_apoint( newapoint ); vbl = m->data->a.get_response->variable_bindings; FOR_EACH_LIST_ELMT( varbind, vbl ){ if( AsnOidCompare( &atmfMySystemIdentifier, &varbind->name ) == AsnOidEqual ){ AsnOctsCopy( &(newapoint->atmfMySystemIdentifier), varbind->value->a.simple->a.string ); } else if( AsnOidCompare( &atmfPortMyIdentifier, &varbind->name ) == AsnOidEqual ){ newapoint->atmfPortMyIfIdentifier = varbind->value->a.simple->a.number; } else if( AsnOidCompare( &sysUpTime, &varbind->name ) == AsnOidEqual ){ newapoint->sysUpTime = varbind->value->a.simple->a.number; } else if( AsnOidCompare( &atmfPortMyIfName, &varbind->name ) == AsnOidEqual ){ AsnOctsCopy( &(newapoint->atmfPortMyIfName), varbind->value->a.simple->a.string ); } } return m; } Message *wait_for_config( int fd, int itf, Msgs *msgs ){ Message *m = NULL; VarBind *varbind; VarBindList *vbl; m = wait_for_response( fd, itf, msgs, RESPONSE_TIMEOUT ); if( m == NULL ) return NULL; if( RESP_RID( m ) != GETNEXT_RID( msgs->config )){ diag( COMPONENT, DIAG_ERROR, "received response with invalid request id" ); } vbl = m->data->a.get_response->variable_bindings; FOR_EACH_LIST_ELMT( varbind, vbl ){ if( AsnOidCompare( &atmfAtmLayerDeviceType, &varbind->name ) == AsnOidEqual ) config->atmfAtmLayerDeviceType = varbind->value->a.simple->a.number; else if( AsnOidCompare( &atmfAtmLayerUniVersion, &varbind->name ) == AsnOidEqual ) config->atmfAtmLayerUniVersion = varbind->value->a.simple->a.number; else if( AsnOidCompare( &atmfAtmLayerUniType, &varbind->name ) == AsnOidEqual ) config->atmfAtmLayerUniType = varbind->value->a.simple->a.number; else if( AsnOidCompare( &atmfAtmLayerMaxVpiBits, &varbind->name ) == AsnOidEqual ) config->atmfAtmLayerMaxVpiBits = varbind->value->a.simple->a.number; else if( AsnOidCompare( &atmfAtmLayerMaxVciBits, &varbind->name ) == AsnOidEqual ) config->atmfAtmLayerMaxVciBits = varbind->value->a.simple->a.number; else if( AsnOidCompare( &atmfAddressRegistrationAdminStatus, &varbind->name ) == AsnOidEqual ) config->atmfAddressRegistrationAdminStatus = varbind->value->a.simple->a.number; } return m; } Message *wait_for_status( int fd, int itf, Msgs *msgs ){ Message *m = NULL; m = wait_for_response( fd, itf, msgs, RESPONSE_TIMEOUT ); if( m == NULL ) return NULL; while( RESP_RID( m ) != GETNEXT_RID( msgs->addrtable )){ m = wait_for_response( fd, itf, msgs, RESPONSE_TIMEOUT ); if( m == NULL ) return NULL; } return m; } Message *wait_for_setresponse( int fd, int itf, Msgs *msgs ){ Message *m = NULL; m = wait_for_response( fd, itf, msgs, RESPONSE_TIMEOUT ); return m; } --- NEW FILE: wait.h --- #ifndef __WAIT_H #define __WAIT_H #include "ilmid.h" void wait_for_prefix( int fd, int itf, Msgs *msgs ); Message *wait_for_sysgroup( int fd, int itf, Msgs *msgs ); Message *wait_for_attachment_point( int fd, int itf, Msgs *msgs ); Message *wait_for_config( int fd, int itf, Msgs *msgs ); Message *wait_for_status( int fd, int itf, Msgs *msgs ); Message *wait_for_setresponse( int fd, int itf, Msgs *msgs ); void reset_apoint( AttPoint *a ); #endif Index: Makefile.am =================================================================== RCS file: /cvsroot/linux-atm/linux-atm/src/ilmid/Makefile.am,v retrieving revision 1.2.2.1 retrieving revision 1.2.2.2 diff -C2 -d -r1.2.2.1 -r1.2.2.2 *** Makefile.am 2 May 2003 13:47:16 -0000 1.2.2.1 --- Makefile.am 19 Jul 2003 21:07:19 -0000 1.2.2.2 *************** *** 8,15 **** util.c util.h io.c io.h message.c message.h \ atmf_uni.c atmf_uni.h mib.c mib.h \ ! sysgroup.c sysgroup.h ilmid.c ilmid_LDADD = $(top_builddir)/src/lib/libatm.la \ $(top_builddir)/src/ilmid/asn1/libasn1.a ilmid_DEPENDENCIES = $(ilmid_LDADD) EXTRA_DIST = COPYRIGHT --- 8,18 ---- util.c util.h io.c io.h message.c message.h \ atmf_uni.c atmf_uni.h mib.c mib.h \ ! sysgroup.c sysgroup.h ilmid.c \ ! wait.c wait.h states.c states.h actions.c actions.h ilmid_LDADD = $(top_builddir)/src/lib/libatm.la \ $(top_builddir)/src/ilmid/asn1/libasn1.a ilmid_DEPENDENCIES = $(ilmid_LDADD) + + man_MANS = ilmid.8 EXTRA_DIST = COPYRIGHT Index: atmf_uni.c =================================================================== RCS file: /cvsroot/linux-atm/linux-atm/src/ilmid/atmf_uni.c,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** atmf_uni.c 9 Oct 2001 22:33:06 -0000 1.2 --- atmf_uni.c 19 Jul 2003 21:07:19 -0000 1.2.2.1 *************** *** 38,42 **** --- 38,47 ---- #define INVALID 2 + AsnOid foreQ2931AdminConfigType = + {19, "\53\06\01\04\01\202\106\02\02\02\01\06\02\01\01\01\13\00\00" }; + AsnOid foreQ2931NNIProto = + {19, "\53\06\01\04\01\202\106\02\02\02\01\06\02\01\01\01\102\00\00" }; AsnOid atmfPortIndex = {13, "\53\06\01\04\01\202\141\02\01\01\01\01\00"}; + AsnOid atmfPortMyIfName = {13, "\53\06\01\04\01\202\141\02\01\01\01\07\00"}; AsnOid atmfPortMyIdentifier = {13, "\53\06\01\04\01\202\141\02\01\01\01\10\00"}; AsnOid atmfMyIpNmAddress = {11, "\53\06\01\04\01\202\141\02\01\02\00"}; *************** *** 44,49 **** --- 49,84 ---- AsnOid atmfAtmLayerMaxVpiBits = {13, "\53\06\01\04\01\202\141\02\02\01\01\6\00"}; AsnOid atmfAtmLayerMaxVciBits = {13, "\53\06\01\04\01\202\141\02\02\01\01\7\00"}; + AsnOid atmfAtmLayerUniType = {13, "\53\06\01\04\01\202\141\02\02\01\01\10\00"}; AsnOid atmfAtmLayerUniVersion = {13, "\53\06\01\04\01\202\141\02\02\01\01\11\00"}; + AsnOid atmfAtmLayerDeviceType = {13, "\53\06\01\04\01\202\141\02\02\01\01\12\00"}; + AsnOid atmfAtmLayerIlmiVersion = {13, "\53\06\01\04\01\202\141\02\02\01\01\13\00"}; + AsnOid atmfAtmLayerNniSigVersion = {13, "\53\06\01\04\01\202\141\02\02\01\01\14\00"}; AsnOid atmfNetPrefixStatus = {NETPREFIX_LEN, "\53\06\01\04\01\202\141\02\07\01\01\03"}; + AsnOid atmfSrvcRegATMAddress = + // {26, "\53\06\01\04\01\202\141\02\10\01\01\03\00\12\01\03\06\01\04\01\202\141\01\05\01\01"}; + {25, "\53\06\01\04\01\202\141\02\10\01\01\03\00\12\01\03\06\01\04\01\202\141\01\05\01"}; + + + AsnOid atmfSrvcRegTable = { 10, "\53\06\01\04\01\202\141\02\10\01" }; + AsnOid atmfAddressTable = { 9, "\53\06\01\04\01\202\141\02\06" }; + AsnOid atmfAddressStatus = { 12, "\53\06\01\04\01\202\141\02\06\01\01\03" }; + AsnOid atmfAddressRegistrationAdminStatus = + { 13, "\53\06\01\04\01\202\141\02\13\01\01\02\00" }; + + /* 1 = PublicUNI + 2 = automode + 3 = iisp + 4 = ftPNNI + 5 = privateNNI + 6 = privateUNI + */ + AsnInt foreQ2931AdminConfigTypeValue = 6; /* private uni */ + + /* 1 = none + 2 = ftpnni + 3 = forum-pnni + 4 = iisp + */ + AsnInt foreQ2931NNIProtoValue = 1; /* none */ AsnInt atmfPortIndexValue = 0; *************** *** 55,59 **** AsnInt atmfAtmLayerMaxVpiBitsValue; AsnInt atmfAtmLayerMaxVciBitsValue; ! #if defined(UNI30) || defined(DYNAMIC_UNI) --- 90,97 ---- AsnInt atmfAtmLayerMaxVpiBitsValue; AsnInt atmfAtmLayerMaxVciBitsValue; ! AsnInt atmfAtmLayerUniTypeValue = 2; /* private */ ! AsnInt atmfAtmLayerDeviceTypeValue = 1; /* user (ATM End System) */ ! AsnInt atmfAtmLayerIlmiVersionValue = 2; /* version4point0 */ ! AsnInt atmfAtmLayerNniSigVersionValue = 1; /* unsupported */ #if defined(UNI30) || defined(DYNAMIC_UNI) *************** *** 68,71 **** --- 106,110 ---- static AsnOid atmNetPrefix = {0, NULL}; + static AsnOcts atmLecsAddress = {0, NULL}; typedef struct NetPrefixNode *************** *** 111,114 **** --- 150,154 ---- AsnOid *varBindName; + diag(COMPONENT,DIAG_DEBUG,"getNetPrefix"); varBindName = &varbind->name; if(AsnOidSize(varBindName) != NETPREFIX_LEN + INDEX_LEN || *************** *** 165,168 **** --- 205,209 ---- AsnOid *varBindName; + diag(COMPONENT,DIAG_DEBUG,"setNetPrefix"); varBindName = &varbind->name; if(varbind->value->choiceId != OBJECTSYNTAX_SIMPLE || *************** *** 203,204 **** --- 244,275 ---- return NOERROR; } + + AsnInt getLecsAddress(VarBind *varbind, Variable *var) + { + int cmp; + NetPrefixNode *prefix; + AsnOid *varBindName; + + diag(COMPONENT,DIAG_INFO,"getLecsAddress" ); + varBindName = &varbind->name; + if(AsnOidSize(varBindName) != 25 ) return NOSUCHNAME; + + /* + for(prefix = (NetPrefixNode *) var->value, cmp = AsnOidLess; + prefix != NULL && (cmp = AsnOidCompare(varBindName, prefix->name)) < + AsnOidEqual; + prefix = prefix->next); + + if(cmp != AsnOidEqual) + return NOSUCHNAME; + */ + + varbind->value = Asn1Alloc(sizeof(struct ObjectSyntax)); + varbind->value->choiceId = OBJECTSYNTAX_SIMPLE; + varbind->value->a.simple = Asn1Alloc(sizeof(struct SimpleSyntax)); + varbind->value->a.simple->choiceId = SIMPLESYNTAX_NUMBER; + varbind->value->a.simple->a.number = VALID; + + return NOERROR; + } + Index: atmf_uni.h =================================================================== RCS file: /cvsroot/linux-atm/linux-atm/src/ilmid/atmf_uni.h,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** atmf_uni.h 9 Oct 2001 22:33:06 -0000 1.2 --- atmf_uni.h 19 Jul 2003 21:07:19 -0000 1.2.2.1 *************** *** 30,34 **** --- 30,37 ---- #include "mib.h" + extern AsnOid foreQ2931NNIProto; + extern AsnOid foreQ2931AdminConfigType; extern AsnOid atmfPortIndex; + extern AsnOid atmfPortMyIfName; extern AsnOid atmfPortMyIdentifier; extern AsnOid atmfMyIpNmAddress; *************** *** 37,42 **** --- 40,56 ---- extern AsnOid atmfAtmLayerMaxVpiBits; extern AsnOid atmfAtmLayerMaxVciBits; + extern AsnOid atmfAtmLayerUniType; extern AsnOid atmfAtmLayerUniVersion; + extern AsnOid atmfAtmLayerDeviceType; + extern AsnOid atmfAtmLayerIlmiVersion; + extern AsnOid atmfAtmLayerNniSigVersion; + extern AsnOid atmfSrvcRegATMAddress; + extern AsnOid atmfSrvcRegTable; + extern AsnOid atmfAddressTable; + extern AsnOid atmfAddressStatus; + extern AsnOid atmfAddressRegistrationAdminStatus; + extern AsnInt foreQ2931NNIProtoValue; + extern AsnInt foreQ2931AdminConfigTypeValue; extern AsnInt atmfPortIndexValue; extern IpAddress atmfMyIpNmAddressValue; *************** *** 44,48 **** --- 58,66 ---- extern AsnInt atmfAtmLayerMaxVpiBitsValue; extern AsnInt atmfAtmLayerMaxVciBitsValue; + extern AsnInt atmfAtmLayerUniTypeValue; extern AsnInt atmfAtmLayerUniVersionValue; + extern AsnInt atmfAtmLayerDeviceTypeValue; + extern AsnInt atmfAtmLayerIlmiVersionValue; + extern AsnInt atmfAtmLayerNniSigVersionValue; AsnOid *accessNetPrefix(void); *************** *** 52,55 **** --- 70,77 ---- AsnInt setNetPrefix(VarBind *varbind, Variable *var); AsnInt getMyIp(VarBind *varbind, Variable *var); + + AsnOid *accessLecsAddress( void ); + AsnInt setLecsAddress(VarBind *varbind, Variable *var); + AsnInt getLecsAddress(VarBind *varbind, Variable *var); #endif Index: ilmid.c =================================================================== RCS file: /cvsroot/linux-atm/linux-atm/src/ilmid/ilmid.c,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** ilmid.c 9 Oct 2001 22:33:06 -0000 1.2 --- ilmid.c 19 Jul 2003 21:07:19 -0000 1.2.2.1 *************** *** 30,33 **** --- 30,37 ---- */ + /* + * Reference material used: af-ilmi-0065.000 + */ + #if HAVE_CONFIG_H #include <config.h> *************** *** 35,40 **** --- 39,48 ---- #include <unistd.h> + #include <stdlib.h> + #include <stdarg.h> #include <sys/time.h> + #include <sys/types.h> #include <errno.h> + #include <signal.h> #include "asn_incl.h" #include "rfc1155_smi.h" *************** *** 47,50 **** --- 55,59 ---- #include "atmf_uni.h" #include "sysgroup.h" + #include "states.h" #define RESPONSE_TIMEOUT 2 *************** *** 52,64 **** #define COMPONENT "ILMI" ! typedef enum IlmiState { NO_CHANGE, RESTART, VERIFY, NET_PREFIX, ! ADDRESS, POLL, IDLE } IlmiState; ! const char *state2text[7] = { "NO_CHANGE", "RESTART", "VERIFY", "NET_PREFIX", ! "ADDRESS", "POLL", "IDLE" }; ! void usage(char *name); ! void ilmi_loop(int fd, int itf); ! void usage(char *name) ! { fprintf(stderr, "usage: %s [-b] [-d] [-v] [-l logfile] [-x] [-q qos]\n" "%13s[ -i local_ip ] [ -u uni ] <interface>\n",name,""); --- 61,112 ---- #define COMPONENT "ILMI" ! /* Globals */ ! /* ! static const char *state_names[STATES] = { ! "Stopped", ! "Link Failing", ! "Establishing", ! "Configuring", ! "Retrieve Network Prefixes", ! "Registering Network Prefixes", ! "Retrieving Addresses", ! "Registering Addresses", ! "Verifying" ! }; ! */ ! typedef int (*Func)(int,int,Msgs *); ! static Func state_functions[STATES] = { ! state_stopped, ! state_failing, ! state_establishing, ! state_config, ! state_retrievePrefixes, ! state_registerPrefixes, ! state_retrieveAddresses, ! state_registerAddresses, ! state_verify ! }; ! ! AsnOid *esi_oid = NULL; ! int retries = 0; ! int ilmi_errno = 0; ! int alarm_flag = 0; ! long int requestID = 0; ! State ilmi_state = down; ! ! AttPoint _apoint; ! AttPoint *apoint = &_apoint; /* attachment point */ ! Config _config; ! Config *config = &_config; /* Remote IME configuration */ ! SysGroup _remsys; ! SysGroup *remsys = &_remsys; ! AttPoint _newapoint; ! AttPoint *newapoint = &_newapoint; ! ! void usage( char * ); ! void ilmi_loop( int, int ); ! ! void usage( char *name ){ fprintf(stderr, "usage: %s [-b] [-d] [-v] [-l logfile] [-x] [-q qos]\n" "%13s[ -i local_ip ] [ -u uni ] <interface>\n",name,""); *************** *** 67,141 **** } ! void ilmi_loop(int fd, int itf) ! { ! int no_response; ! long int requestID; ! Message *poll_message, *set_message, *coldstart_message, *in_message; ! AsnOid *set_oid, *netprefix_oid, *esi_oid; VarBind *varbind; ! struct timeval timeout; ! IlmiState state, new_state; ! ! resetUpTime(); ! poll_message = create_poll_message(); ! set_message = create_set_message(); ! set_oid = &((VarBind *) FIRST_LIST_ELMT(set_message->data->a.set_request->variable_bindings))->name; ! esi_oid = get_esi(fd,itf); ! coldstart_message = create_coldstart_message(); ! in_message = alloc_t(Message); ! ! /* Address registration state machine */ ! new_state = RESTART; ! for(;;) ! { ! state = new_state; ! diag(COMPONENT, DIAG_DEBUG, "entering state %s", state2text[state]); ! ! /* Output for the current state */ ! switch(state) ! { ! case RESTART: ! deleteNetPrefix(); ! diag(COMPONENT, DIAG_INFO, "sending cold-start"); ! coldstart_message->data->a.trap->time_stamp = accessUpTime(); ! send_message(fd, coldstart_message); ! no_response = 0; ! ! case VERIFY: ! diag(COMPONENT, DIAG_INFO, "sending get-next"); ! poll_message->data->a.get_next_request->request_id = ++requestID; ! send_message(fd, poll_message); ! break; ! case ADDRESS: ! diag(COMPONENT, DIAG_INFO, "setting the atm address on the switch"); ! set_message->data->a.set_request->request_id = ++requestID; ! send_message(fd, set_message); ! break; ! case POLL: ! diag(COMPONENT, DIAG_INFO, "sending get-next request"); ! poll_message->data->a.get_next_request->request_id = ++requestID; ! send_message(fd, poll_message); ! break; } ! /* Set the time-out period */ ! if(state == IDLE) ! timeout.tv_sec = POLL_PERIOD; ! else ! timeout.tv_sec = RESPONSE_TIMEOUT; ! timeout.tv_usec = 0; - new_state = NO_CHANGE; - /* Input handling loop */ - while(new_state == NO_CHANGE) - { - ResetNibbleMem(); - if(wait_for_message(fd, &timeout) && - !read_message(fd, in_message)) - { - switch(in_message->data->choiceId) - { case PDUS_GET_REQUEST: diag(COMPONENT, DIAG_INFO, "received get request"); --- 115,154 ---- } ! /* returns non-zero if switch set a prefix */ ! int handle_set_request( int fd, int itf, Msgs *msgs, Message *m ){ ! VarBindList *vbl; VarBind *varbind; ! AsnOid *netprefix_oid, *set_oid; ! /* use varbind to compare OIDs of incoming message and that of ! an address status message */ ! varbind = (VarBind *)FIRST_LIST_ELMT( ! m->data->a.get_request->variable_bindings ); ! if( AsnOidCompare( &atmfNetPrefixStatus, &varbind->name ) == AsnOidRoot ){ ! vbl = msgs->set->data->a.set_request->variable_bindings; ! set_oid = &((VarBind *)FIRST_LIST_ELMT( vbl ))->name; ! netprefix_oid = accessNetPrefix(); ! if( netprefix_oid != NULL ){ ! diag( COMPONENT, DIAG_INFO, ! "switch registered a network prefix"); ! set_oid->octetLen = ADDRESS_LEN + 1; ! AsnOidAppend( set_oid, netprefix_oid ); ! AsnOidAppend( set_oid, esi_oid ); ! update_nsap( itf, netprefix_oid, esi_oid ); ! return 1; ! } else{ ! diag( COMPONENT, DIAG_INFO, ! "switch did not register prefix?" ); ! } ! } ! return 0; } ! /* returns E value (ECOLDSTART, . . .) */ ! int handle_request( int fd, int itf, Msgs *msgs, Message *in_message ){ ! int retval = 0; ! switch( in_message->data->choiceId ){ case PDUS_GET_REQUEST: diag(COMPONENT, DIAG_INFO, "received get request"); *************** *** 156,202 **** break; - case PDUS_GET_RESPONSE: - diag(COMPONENT, DIAG_INFO, "received get response"); - if(in_message->data->a.get_response->request_id == requestID) - { - varbind = (VarBind *) FIRST_LIST_ELMT(in_message->data->a.get_response->variable_bindings); - switch(state) - { - case RESTART: - case VERIFY: - if(in_message->data->a.get_response->error_status == NOERROR && - AsnOidCompare(&atmAddressStatus, &varbind->name) == AsnOidRoot) - new_state = RESTART; - else - new_state = NET_PREFIX; - break; - - case ADDRESS: - if(in_message->data->a.get_response->error_status == NOERROR) - { - diag(COMPONENT, DIAG_INFO, "ATM address registered"); - update_nsap(itf, netprefix_oid, esi_oid); - no_response = 0; - new_state = POLL; - } - else - new_state = RESTART; - break; - - case POLL: - if(in_message->data->a.get_response->error_status == NOERROR && - AsnOidCompare(&varbind->name, set_oid) == AsnOidEqual) - { - no_response = 0; - new_state = IDLE; - } - else - new_state = RESTART; - break; - } - } - else diag(COMPONENT, DIAG_ERROR, "received response with invalid request id"); - break; - case PDUS_SET_REQUEST: diag(COMPONENT, DIAG_INFO, "received set request"); --- 169,172 ---- *************** *** 205,274 **** &in_message->data->a.set_request->error_index); in_message->data->choiceId = PDUS_GET_RESPONSE; send_message(fd, in_message); break; case PDUS_TRAP: ! diag(COMPONENT, DIAG_INFO, "received trap"); ! if(in_message->data->a.trap->generic_trap == COLDSTART && ! state != RESTART) ! new_state = RESTART; break; ! default: ! diag(COMPONENT, DIAG_ERROR, "received message with invalid choice"); break; } ! if((state == NET_PREFIX || new_state == NET_PREFIX) && ! (netprefix_oid = accessNetPrefix()) != NULL) ! { ! diag(COMPONENT, DIAG_INFO, "switch registered a network prefix"); ! set_oid->octetLen = ADDRESS_LEN + 1; ! AsnOidAppend(set_oid, netprefix_oid); ! AsnOidAppend(set_oid, esi_oid); ! new_state = ADDRESS; } } ! else /* Timeout occurred */ ! { ! switch(state) ! { ! case RESTART: ! case VERIFY: ! diag(COMPONENT, DIAG_INFO, "switch did not respond to get-next -- resending"); ! if(++no_response == 4) ! new_state = RESTART; ! else ! new_state = VERIFY; ! break; ! case NET_PREFIX: ! diag(COMPONENT, DIAG_INFO, "switch did not register a network prefix -- restarting"); ! new_state = RESTART; ! break; ! case ADDRESS: ! diag(COMPONENT, DIAG_INFO, "switch did not respond to set request -- resending"); ! new_state = ADDRESS; ! break; ! case POLL: ! if(++no_response == 4) ! { ! new_state = RESTART; ! diag(COMPONENT, DIAG_INFO, "switch is not responding"); } - else - new_state = IDLE; - break; - case IDLE: - new_state = POLL; - break; } } } } } int main(int argc, char *argv[]) { ! int fd, opt, itf = 0, bg = 0; pid_t pid; const char *qos; set_application("ilmid"); --- 175,354 ---- &in_message->data->a.set_request->error_index); in_message->data->choiceId = PDUS_GET_RESPONSE; + if( handle_set_request( fd, itf, msgs, in_message )) + retval = ESETPREFIX; send_message(fd, in_message); break; case PDUS_TRAP: ! if( in_message->data->a.trap->generic_trap == COLDSTART ){ ! diag( COMPONENT, DIAG_INFO, "received coldstart trap" ); ! retval = ECOLDSTART; ! } else diag( COMPONENT, DIAG_INFO, "received trap" ); break; ! ! case PDUS_GET_RESPONSE: break; } ! return retval; } + + /* if a non-null value is returned from this function, the caller must + free that memory */ + + Message *wait_for_response( int fd, int itf, Msgs *msgs, int sec ){ + Message *in_message; + static Message m; + struct timeval timeout; + int numfds = 0; + + in_message = (Message *)(&m); + timeout.tv_sec = sec; + timeout.tv_usec = 0; + + ilmi_errno = 0; + wait_top: + ResetNibbleMem(); + numfds = wait_for_message( fd, &timeout ); + if(( numfds > 0 ) && !read_message( fd, in_message )){ + switch( in_message->data->choiceId ){ + case PDUS_GET_REQUEST: + case PDUS_GET_NEXT_REQUEST: + case PDUS_SET_REQUEST: + case PDUS_TRAP: + ilmi_errno = + handle_request( fd, itf, msgs, in_message ); + if( ilmi_errno > 0 ) return NULL; + else goto wait_top; + /* no more evil than "break" */ + case PDUS_GET_RESPONSE: + diag( COMPONENT, DIAG_INFO, + "received get-response" ); + return in_message; + default: + diag( COMPONENT, DIAG_ERROR, + "received message with invalid choice" ); + goto wait_top; } ! } else{ ! if( numfds == 0 ) ilmi_errno = ETIMEOUT; ! if(( numfds < 0 ) && ( errno == EINTR )) ilmi_errno = EALARM; ! return NULL; /* no data read */ } } + + Msgs *create_msgs( void ){ + Msgs *m = alloc_t( Msgs ); + if( m == NULL ) return NULL; + + m->coldstart = create_coldstart_message(); + m->addrtable = create_va_getnext_message( 2, + &atmfAddressStatus, + &atmfSrvcRegTable ); + m->poll = create_getnext_message( atmfAddressTable ); + m->set = create_set_message(); + m->config = create_va_get_message( 6, + &atmfAtmLayerUniVersion, + &atmfAtmLayerMaxVpiBits, + &atmfAtmLayerMaxVciBits, + &atmfAtmLayerUniType, + &atmfAtmLayerDeviceType, + &atmfAddressRegistrationAdminStatus ); + m->apointmsg = create_va_get_message( 3, + &atmfPortMyIdentifier, + &atmfPortMyIfName, /* some extra adjacency info */ + &atmfMySystemIdentifier, + &sysUpTime ); + m->sysmsg = create_va_get_message( 7, + &sysDescr, + &sysObjectID, + &sysUpTime, + &sysContact, + &sysName, + &sysLocation, + &sysServices ); + + return m; + } + + void copy_attachment_point( AttPoint *dest, AttPoint *src ){ + dest->sysUpTime = src->sysUpTime; + dest->atmfPortMyIfIdentifier = src->atmfPortMyIfIdentifier; + + dest->atmfMySystemIdentifier.octs = + malloc( src->atmfMySystemIdentifier.octetLen ); + dest->atmfMySystemIdentifier.octetLen = + src->atmfMySystemIdentifier.octetLen; + if( dest->atmfMySystemIdentifier.octs != NULL ){ + memcpy( dest->atmfMySystemIdentifier.octs, + src->atmfMySystemIdentifier.octs, 6 ); + } else diag( COMPONENT, DIAG_FATAL, "malloc() failed" ); + + /* copy the port name */ + dest->atmfPortMyIfName.octs = + malloc( src->atmfPortMyIfName.octetLen + 1 ); + dest->atmfPortMyIfName.octetLen = src->atmfPortMyIfName.octetLen; + if( dest->atmfPortMyIfName.octs != NULL ){ + memcpy( dest->atmfPortMyIfName.octs, + src->atmfPortMyIfName.octs, + src->atmfPortMyIfName.octetLen ); + } else diag( COMPONENT, DIAG_FATAL, "malloc() failed" ); + } + + /* section 8.3.2 */ + int compare_attachment_point( a, b ) + AttPoint *a; /* current a'point */ + AttPoint *b; /* newly aquired a'point info */ + { + if(( a == NULL ) || ( b == NULL )) return -1; + if( a->atmfPortMyIfIdentifier != b->atmfPortMyIfIdentifier ) + return -1; + if( a->atmfMySystemIdentifier.octetLen != + b->atmfMySystemIdentifier.octetLen ) return -1; + if( memcmp( a->atmfMySystemIdentifier.octs, + b->atmfMySystemIdentifier.octs, + b->atmfMySystemIdentifier.octetLen ) != 0 ) return -1; + if( b->sysUpTime < a->sysUpTime ) return -1; + return 0; } + + void handler( int sig ){ + switch( sig ){ + case SIGALRM: + alarm_flag = 1; + diag( COMPONENT, DIAG_INFO, + "received alarm: time to poll for attachment point" ); + break; + case SIGTERM: + case SIGSTOP: + case SIGINT: + case SIGKILL: + ilmi_state = down; + exit( 1 ); } } + + void ilmi_loop( int fd, int itf ){ + int state = S1; + Msgs *msgs = create_msgs(); + struct itimerval setpoint; + esi_oid = get_esi( fd, itf); + // apoint->atmfMySystemIdentifier.octs = &(apoint->sysIdMem[0]); + + setpoint.it_interval.tv_sec = 30; + setpoint.it_interval.tv_usec = 0; + setpoint.it_value.tv_sec = 30; + setpoint.it_value.tv_usec = 0; + signal( SIGALRM, handler ); + setitimer( ITIMER_REAL, &setpoint, NULL ); + + for( ;; ) state = state_functions[state]( fd, itf, msgs ); } int main(int argc, char *argv[]) { ! int opt, bg = 0; pid_t pid; const char *qos; + int fd, itf = 0; set_application("ilmid"); *************** *** 307,311 **** case 'u': { ! int version; if (!strcmp(optarg,"3.0") || !strcmp(optarg,"30")) --- 387,391 ---- case 'u': { ! int version = 2; if (!strcmp(optarg,"3.0") || !strcmp(optarg,"30")) *************** *** 349,353 **** } ! InitNibbleMem(512, 512); fd = open_ilmi(itf,qos); ilmi_loop(fd, itf); --- 429,440 ---- } ! InitNibbleMem(1024, 512); ! memset( remsys, 0, sizeof( _remsys )); ! memset( apoint, 0, sizeof( _apoint )); ! memset( newapoint, 0, sizeof( _newapoint )); ! signal( SIGTERM, handler ); ! signal( SIGKILL, handler ); ! signal( SIGINT, handler ); ! signal( SIGSTOP, handler ); fd = open_ilmi(itf,qos); ilmi_loop(fd, itf); Index: io.c =================================================================== RCS file: /cvsroot/linux-atm/linux-atm/src/ilmid/io.c,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** io.c 9 Oct 2001 22:33:06 -0000 1.2 --- io.c 19 Jul 2003 21:07:19 -0000 1.2.2.1 *************** *** 26,29 **** --- 26,30 ---- #endif + #include <unistd.h> #include <sys/socket.h> #include <netinet/in.h> *************** *** 33,36 **** --- 34,38 ---- #include <atm.h> #include <linux/atmdev.h> + #include "ilmid.h" #include "io.h" #include "atmd.h" *************** *** 43,46 **** --- 45,50 ---- registered the "official" address) - HACK */ + extern SysGroup *remsys; + extern State ilmi_state; static short atm_itf = -1; /* bad value */ *************** *** 177,182 **** FD_SET(fd, &fdvar); ! if((numfds = select(fd + 1, &fdvar, 0, 0, timeout)) < 0) diag(COMPONENT, DIAG_FATAL, "select: %s", strerror(errno)); return numfds; --- 181,188 ---- FD_SET(fd, &fdvar); ! if((numfds = select(fd + 1, &fdvar, 0, 0, timeout)) < 0){ ! if( errno != EINTR ) diag(COMPONENT, DIAG_FATAL, "select: %s", strerror(errno)); + } return numfds; *************** *** 300,302 **** --- 306,309 ---- return error; } + return 0; } Index: io.h =================================================================== RCS file: /cvsroot/linux-atm/linux-atm/src/ilmid/io.h,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** io.h 9 Oct 2001 22:33:06 -0000 1.2 --- io.h 19 Jul 2003 21:07:19 -0000 1.2.2.1 *************** *** 28,31 **** --- 28,32 ---- #include <atm.h> #include <linux/atmdev.h> + #include "ilmid.h" #include "asn_incl.h" #include "rfc1155_smi.h" Index: message.c =================================================================== RCS file: /cvsroot/linux-atm/linux-atm/src/ilmid/message.c,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** message.c 9 Oct 2001 22:33:06 -0000 1.2 --- message.c 19 Jul 2003 21:07:19 -0000 1.2.2.1 *************** *** 28,39 **** #endif #include "message.h" #include "atmf_uni.h" #include "util.h" int no_var_bindings = 0; ! AsnOid atmAddressStatus = {ADDRESS_LEN, ADDRESS_OID}; Message *create_poll_message(void) { --- 28,129 ---- #endif + #include <unistd.h> + #include <stdarg.h> + #include "message.h" #include "atmf_uni.h" #include "util.h" + #include "sysgroup.h" int no_var_bindings = 0; ! // AsnOid atmAddressStatus = {ADDRESS_LEN, ADDRESS_OID}; ! ! Message *create_va_getnext_message( int n, ... ){ ! Message *m = alloc_t( Message ); ! VarBind *entry; ! AsnOid *what; ! va_list ap; ! int count; + if( m == NULL ) return NULL; + m->version = VERSION_1; + m->community.octs = "ILMI"; + m->community.octetLen = 4; + m->data = alloc_t( PDUs ); + m->data->choiceId = PDUS_GET_NEXT_REQUEST; + m->data->a.get_next_request = alloc_t( GetRequest_PDU ); + m->data->a.get_next_request->error_status = 0; + m->data->a.get_next_request->error_index = 0; + m->data->a.get_next_request->variable_bindings = alloc_t( VarBindList ); + AsnListInit( m->data->a.get_next_request->variable_bindings, + sizeof( VarBind )); + va_start( ap, n ); + count = 0; + while( count < n ){ + what = va_arg( ap, AsnOid* ); + entry = AppendVarBind( + m->data->a.get_next_request->variable_bindings ); + entry->name.octs = alloc( what->octetLen ); + entry->name.octetLen = what->octetLen; + memcpy( entry->name.octs, what->octs, what->octetLen ); + entry->value = alloc_t( ObjectSyntax ); + entry->value->choiceId = OBJECTSYNTAX_SIMPLE; + entry->value->a.simple = alloc_t( SimpleSyntax ); + entry->value->a.simple->choiceId = SIMPLESYNTAX_NUMBER; + count++; + } + va_end(ap); + return m; + } + + Message *create_va_get_message( int n, ... ){ + Message *m = alloc_t( Message ); + VarBind *entry; + AsnOid *what; + va_list ap; + int count; + + if( m == NULL ) return NULL; + m->version = VERSION_1; + m->community.octs = "ILMI"; + m->community.octetLen = 4; + m->data = alloc_t( PDUs ); + m->data->choiceId = PDUS_GET_REQUEST; + m->data->a.get_request = alloc_t( GetRequest_PDU ); + m->data->a.get_request->error_status = 0; + m->data->a.get_request->error_index = 0; + m->data->a.get_request->variable_bindings = alloc_t( VarBindList ); + AsnListInit( m->data->a.get_request->variable_bindings, + sizeof( VarBind )); + va_start( ap, n ); + count = 0; + while( count < n ){ + what = va_arg( ap, AsnOid* ); + entry = AppendVarBind( + m->data->a.get_request->variable_bindings ); + entry->name.octs = alloc( what->octetLen ); + entry->name.octetLen = what->octetLen; + memcpy( entry->name.octs, what->octs, what->octetLen ); + entry->value = alloc_t( ObjectSyntax ); + entry->value->choiceId = OBJECTSYNTAX_SIMPLE; + entry->value->a.simple = alloc_t( SimpleSyntax ); + entry->value->a.simple->choiceId = SIMPLESYNTAX_NUMBER; + count++; + } + va_end(ap); + return m; + } + + + Message *create_get_message( AsnOid what ){ + return create_va_get_message( 1, &what ); + } + + Message *create_getnext_message( AsnOid what ){ + return create_va_getnext_message( 1, &what ); + } + + #ifdef notdef Message *create_poll_message(void) { *************** *** 65,68 **** --- 155,159 ---- return poll_message; } + #endif Message *create_set_message(void) Index: message.h =================================================================== RCS file: /cvsroot/linux-atm/linux-atm/src/ilmid/message.h,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** message.h 9 Oct 2001 22:33:06 -0000 1.2 --- message.h 19 Jul 2003 21:07:19 -0000 1.2.2.1 *************** *** 34,42 **** extern int no_var_bindings; ! AsnOid atmAddressStatus; Message *create_poll_message(void); Message *create_set_message(void); Message *create_coldstart_message(void); #endif --- 34,47 ---- extern int no_var_bindings; ! //AsnOid atmAddressStatus; Message *create_poll_message(void); Message *create_set_message(void); Message *create_coldstart_message(void); + Message *create_va_getnext_message( int, ... ); + Message *create_va_get_message( int, ... ); + Message *create_getnext_message( AsnOid ); + Message *create_get_message( AsnOid ); + void free_message( Message *m ); #endif Index: mib.c =================================================================== RCS file: /cvsroot/linux-atm/linux-atm/src/ilmid/mib.c,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** mib.c 9 Oct 2001 22:33:06 -0000 1.2 --- mib.c 19 Jul 2003 21:07:19 -0000 1.2.2.1 *************** *** 47,50 **** --- 47,53 ---- { &sysLocation, getString, NULL, NULL, &sysLocationValue }, { &sysServices, getInteger, NULL, NULL, &sysServicesValue }, + { &foreQ2931AdminConfigType, getInteger, NULL, NULL, + &foreQ2931AdminConfigTypeValue }, + { &foreQ2931NNIProto, getInteger, NULL, NULL, &foreQ2931NNIProtoValue }, { &atmfPortIndex, getInteger, NULL, NULL, &atmfPortIndexValue }, { &atmfPortMyIdentifier, getInteger, NULL, NULL, &atmfPortIndexValue }, *************** *** 53,63 **** { &atmfAtmLayerMaxVpiBits, getVpiRange, NULL, NULL, &atmfAtmLayerMaxVpiBitsValue }, { &atmfAtmLayerMaxVciBits, getVciRange, NULL, NULL, &atmfAtmLayerMaxVciBitsValue }, { &atmfAtmLayerUniVersion, getInteger, NULL, NULL, &atmfAtmLayerUniVersionValue }, { &atmfNetPrefixStatus, getNetPrefix, getnextNetPrefix, setNetPrefix, NULL }, { NULL } }; ! void MIBget(VarBindList *list, PDUInt *status, AsnInt *index) { VarBind *varbind; --- 56,75 ---- { &atmfAtmLayerMaxVpiBits, getVpiRange, NULL, NULL, &atmfAtmLayerMaxVpiBitsValue }, { &atmfAtmLayerMaxVciBits, getVciRange, NULL, NULL, &atmfAtmLayerMaxVciBitsValue }, + { &atmfAtmLayerUniType, getInteger, NULL, NULL, &atmfAtmLayerUniTypeValue}, { &atmfAtmLayerUniVersion, getInteger, NULL, NULL, &atmfAtmLayerUniVersionValue }, + { &atmfAtmLayerDeviceType, getInteger, NULL, NULL, + &atmfAtmLayerDeviceTypeValue}, + { &atmfAtmLayerIlmiVersion, getInteger, NULL, NULL, + &atmfAtmLayerIlmiVersionValue}, + { &atmfAtmLayerNniSigVersion, getInteger, NULL, NULL, + &atmfAtmLayerNniSigVersionValue}, { &atmfNetPrefixStatus, getNetPrefix, getnextNetPrefix, setNetPrefix, NULL }, { NULL } }; ! ! ! void MIBget(VarBindList *list, PDUInt *status, AsnInt *offset) { VarBind *varbind; *************** *** 65,69 **** AsnOidResult result; ! *index = 1; FOR_EACH_LIST_ELMT(varbind, list) { --- 77,81 ---- AsnOidResult result; ! *offset = 1; FOR_EACH_LIST_ELMT(varbind, list) { *************** *** 92,103 **** return; ! (*index)++; } ! *index = 0; return; } ! void MIBgetnext(VarBindList *list, PDUInt *status, AsnInt *index) { VarBind *varbind; --- 104,115 ---- return; ! (*offset)++; } ! *offset = 0; return; } ! void MIBgetnext(VarBindList *list, PDUInt *status, AsnInt *offset) { VarBind *varbind; *************** *** 105,109 **** AsnOidResult result; ! *index = 1; FOR_EACH_LIST_ELMT(varbind, list) { --- 117,121 ---- AsnOidResult result; ! *offset = 1; FOR_EACH_LIST_ELMT(varbind, list) { *************** *** 140,150 **** return; ! (*index)++; } ! *index = 0; return; } ! void MIBset(VarBindList *list, PDUInt *status, AsnInt *index) { VarBind *varbind; --- 152,162 ---- return; ! (*offset)++; } ! *offset = 0; return; } ! void MIBset(VarBindList *list, PDUInt *status, AsnInt *offset) { VarBind *varbind; *************** *** 152,156 **** AsnOidResult result; ! *index = 1; FOR_EACH_LIST_ELMT(varbind, list) { --- 164,168 ---- AsnOidResult result; ! *offset = 1; FOR_EACH_LIST_ELMT(varbind, list) { *************** *** 183,189 **** return; ! (*index)++; } ! *index = 0; return; } --- 195,201 ---- return; ! (*offset)++; } ! *offset = 0; return; } *************** *** 245,249 **** return NOERROR; } - #include <stdint.h> --- 257,260 ---- Index: mib.h =================================================================== RCS file: /cvsroot/linux-atm/linux-atm/src/ilmid/mib.h,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** mib.h 9 Oct 2001 22:33:06 -0000 1.2 --- mib.h 19 Jul 2003 21:07:19 -0000 1.2.2.1 *************** *** 40,46 **** } Variable; ! void MIBget(VarBindList *list, PDUInt *status, AsnInt *index); ! void MIBgetnext(VarBindList *list, PDUInt *status, AsnInt *index); ! void MIBset(VarBindList *list, PDUInt *status, AsnInt *index); void *MIBdelete(AsnOid *oid); --- 40,46 ---- } Variable; ! void MIBget(VarBindList *list, PDUInt *status, AsnInt *offset); ! void MIBgetnext(VarBindList *list, PDUInt *status, AsnInt *offset); ! void MIBset(VarBindList *list, PDUInt *status, AsnInt *offset); void *MIBdelete(AsnOid *oid); |