From: chas w. <ch...@us...> - 2007-07-11 16:32:55
|
Update of /cvsroot/linux-atm/linux-atm/src/ilmid In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv4106/src/ilmid Modified Files: Tag: V2_5_0 Makefile.am ilmid.c ilmid.h io.c io.h Log Message: add ilmidiag support from ek...@cm... Index: Makefile.am =================================================================== RCS file: /cvsroot/linux-atm/linux-atm/src/ilmid/Makefile.am,v retrieving revision 1.2.2.3 retrieving revision 1.2.2.4 diff -C2 -d -r1.2.2.3 -r1.2.2.4 *** Makefile.am 20 Apr 2005 17:05:47 -0000 1.2.2.3 --- Makefile.am 11 Jul 2007 16:07:57 -0000 1.2.2.4 *************** *** 3,7 **** INCLUDES = -I$(srcdir)/../ilmid/asn1 ! sbin_PROGRAMS = ilmid ilmid_SOURCES = rfc1157_snmp.c rfc1157_snmp.h rfc1155_smi.c rfc1155_smi.h \ --- 3,7 ---- INCLUDES = -I$(srcdir)/../ilmid/asn1 ! sbin_PROGRAMS = ilmid ilmidiag ilmid_SOURCES = rfc1157_snmp.c rfc1157_snmp.h rfc1155_smi.c rfc1155_smi.h \ *************** *** 14,17 **** --- 14,21 ---- ilmid_DEPENDENCIES = $(ilmid_LDADD) + ilmidiag_SOURCES = ilmidiag.c + ilmidiag_LDADD = $(top_builddir)/src/lib/libatm.la + ilmidiag_DEPENDENCIES = $(ilmid_LDADD) + man_MANS = ilmid.8 Index: ilmid.c =================================================================== RCS file: /cvsroot/linux-atm/linux-atm/src/ilmid/ilmid.c,v retrieving revision 1.2.2.2 retrieving revision 1.2.2.3 diff -C2 -d -r1.2.2.2 -r1.2.2.3 *** ilmid.c 14 Apr 2007 15:50:58 -0000 1.2.2.2 --- ilmid.c 11 Jul 2007 16:07:57 -0000 1.2.2.3 *************** *** 43,46 **** --- 43,47 ---- #include <sys/time.h> #include <sys/types.h> + #include <sys/wait.h> #include <errno.h> #include <signal.h> *************** *** 60,63 **** --- 61,68 ---- #define POLL_PERIOD 15 #define COMPONENT "ILMI" + #ifndef MAX + # define MAX(a,b) ((a) > (b) ? (a) : (b)) + #endif + /* Globals */ *************** *** 96,99 **** --- 101,106 ---- State ilmi_state = down; + static int diagfd = -1; + AttPoint _apoint; AttPoint *apoint = &_apoint; /* attachment point */ *************** *** 110,114 **** 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,""); fprintf(stderr, "%6s %s -V\n","",name); exit(1); --- 117,121 ---- void usage( char *name ){ fprintf(stderr, "usage: %s [-b] [-d] [-v] [-l logfile] [-x] [-q qos]\n" ! "%13s[ -i local_ip ] [ -u uni ] <itf>[.<vpi>.<vci>]\n",name,""); fprintf(stderr, "%6s %s -V\n","",name); exit(1); *************** *** 201,204 **** --- 208,212 ---- struct timeval timeout; int numfds = 0; + fd_set fdvar; in_message = (Message *)(&m); *************** *** 208,214 **** 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: --- 216,236 ---- ilmi_errno = 0; wait_top: + waitpid(0, NULL, WNOHANG); ResetNibbleMem(); ! FD_ZERO(&fdvar); ! FD_SET(fd, &fdvar); ! FD_SET(diagfd, &fdvar); ! numfds = select(MAX(fd,diagfd)+1, &fdvar, NULL, NULL, &timeout); ! ! if ((numfds > 0) && FD_ISSET(diagfd, &fdvar)) { ! if (fork() == 0) { ! close(fd); ! handle_ilmidiag(diagfd, apoint, config); ! exit(0); ! } ! } ! ! if(( numfds > 0 ) && FD_ISSET(fd, &fdvar) && ! !read_message( fd, in_message )){ switch( in_message->data->choiceId ){ case PDUS_GET_REQUEST: *************** *** 234,239 **** if(( numfds < 0 ) && ( errno == EINTR )) ilmi_errno = EALARM; return NULL; /* no data read */ ! } ! } Msgs *create_msgs( void ){ --- 256,261 ---- if(( numfds < 0 ) && ( errno == EINTR )) ilmi_errno = EALARM; return NULL; /* no data read */ ! } ! } Msgs *create_msgs( void ){ *************** *** 348,357 **** { int opt, bg = 0; pid_t pid; const char *qos; ! int fd, itf = 0; set_application("ilmid"); set_verbosity(NULL, DIAG_WARN); qos = NULL; while((opt = getopt(argc, argv, "bdhi:l:q:xvu:V")) != EOF) --- 370,381 ---- { int opt, bg = 0; + int fd; pid_t pid; const char *qos; ! struct sockaddr_atmpvc ilmipvc; set_application("ilmid"); set_verbosity(NULL, DIAG_WARN); + text2atm("0.0.16", (struct sockaddr *)&ilmipvc, sizeof(ilmipvc), T2A_PVC); qos = NULL; while((opt = getopt(argc, argv, "bdhi:l:q:xvu:V")) != EOF) *************** *** 414,418 **** } if(argc == optind + 1) ! itf = atoi(argv[optind++]); if(argc != optind) --- 438,449 ---- } if(argc == optind + 1) ! if (text2atm(argv[optind++], (struct sockaddr *)&ilmipvc, ! sizeof(ilmipvc), T2A_PVC) < 0) { ! char *endp = NULL; ! int itf = strtoul(argv[optind-1], &endp, 0); ! if (argv[optind-1] == endp || *endp != '\0') ! diag(COMPONENT, DIAG_FATAL, "Invalid pvc or interface number."); ! ilmipvc.sap_addr.itf = itf; ! } if(argc != optind) *************** *** 437,442 **** signal( SIGINT, handler ); signal( SIGSTOP, handler ); ! fd = open_ilmi(itf,qos); ! ilmi_loop(fd, itf); close(fd); return 0; --- 468,474 ---- signal( SIGINT, handler ); signal( SIGSTOP, handler ); ! fd = open_ilmi(&ilmipvc,qos); ! open_ilmidiag(&diagfd, &ilmipvc); ! ilmi_loop(fd, ilmipvc.sap_addr.itf); close(fd); return 0; Index: ilmid.h =================================================================== RCS file: /cvsroot/linux-atm/linux-atm/src/ilmid/Attic/ilmid.h,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** ilmid.h 19 Jul 2003 21:07:19 -0000 1.1.2.1 --- ilmid.h 11 Jul 2007 16:07:57 -0000 1.1.2.2 *************** *** 49,52 **** --- 49,69 ---- typedef enum _State { up, down } State; + #define ATM_REMOTE_SYSNAME_LEN 15 + #define ATM_REMOTE_CONTACT_LEN 30 + #define ATM_REMOTE_PORTNAME_LEN 10 + #define ILMIDIAG_DIR "/tmp/.ilmi" + #define ILMIDIAG_BACKLOG 1 + struct ilmi_state { + unsigned char ilmi_version; /* ilmi version */ + unsigned char uni_version; /* negotiated signalling version */ + unsigned char vpi_bits; /* negotiated vpi bits */ + unsigned char vci_bits; /* negotiated vci bits */ + unsigned char state; /* up/down */ + unsigned int remote_portid; /* id of switch port we're using */ + char remote_sysname[ATM_REMOTE_SYSNAME_LEN]; + char remote_contact[ATM_REMOTE_CONTACT_LEN]; + char remote_portname[ATM_REMOTE_PORTNAME_LEN]; + }; + #endif Index: io.c =================================================================== RCS file: /cvsroot/linux-atm/linux-atm/src/ilmid/io.c,v retrieving revision 1.2.2.2 retrieving revision 1.2.2.3 diff -C2 -d -r1.2.2.2 -r1.2.2.3 *** io.c 6 Oct 2005 15:39:58 -0000 1.2.2.2 --- io.c 11 Jul 2007 16:07:57 -0000 1.2.2.3 *************** *** 28,31 **** --- 28,33 ---- #include <unistd.h> #include <sys/socket.h> + #include <sys/un.h> + #include <sys/types.h> #include <netinet/in.h> #include <sys/ioctl.h> *************** *** 34,37 **** --- 36,41 ---- #include <atm.h> #include <linux/atmdev.h> + #include <sys/types.h> + #include <sys/stat.h> #include "ilmid.h" #include "io.h" *************** *** 289,295 **** ! int open_ilmi(int itf,const char *qos_spec) { - struct sockaddr_atmpvc addr; struct atm_qos qos; int fd; --- 293,298 ---- ! int open_ilmi(struct sockaddr_atmpvc *pvc, const char *qos_spec) { struct atm_qos qos; int fd; *************** *** 298,302 **** diag(COMPONENT, DIAG_FATAL, "socket: %s", strerror(errno)); ! atm_itf = itf; memset(&qos, 0, sizeof(qos)); qos.rxtp.max_sdu = MAX_ILMI_MSG; --- 301,305 ---- diag(COMPONENT, DIAG_FATAL, "socket: %s", strerror(errno)); ! atm_itf = pvc->sap_addr.itf; memset(&qos, 0, sizeof(qos)); qos.rxtp.max_sdu = MAX_ILMI_MSG; *************** *** 309,319 **** diag(COMPONENT,DIAG_FATAL,"setsockopt SO_ATMQOS: %s",strerror(errno)); ! memset(&addr, 0, sizeof(addr)); ! addr.sap_family = AF_ATMPVC; ! addr.sap_addr.itf = itf; ! addr.sap_addr.vpi = 0; ! addr.sap_addr.vci = SNMP_VCI; ! ! if(bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) diag(COMPONENT, DIAG_FATAL, "bind: %s", strerror(errno)); --- 312,316 ---- diag(COMPONENT,DIAG_FATAL,"setsockopt SO_ATMQOS: %s",strerror(errno)); ! if(bind(fd, (struct sockaddr *) pvc, sizeof(*pvc)) < 0) diag(COMPONENT, DIAG_FATAL, "bind: %s", strerror(errno)); *************** *** 340,341 **** --- 337,434 ---- return 0; } + + int open_ilmidiag(int *listenfd, const struct sockaddr_atmpvc *vc) { + int fd = -1; + struct sockaddr_un addr; + struct stat dir; + mode_t oldumask; + + /* check for directory that holds the sockets */ + if ((stat(ILMIDIAG_DIR, &dir) < 0) && (errno == ENOENT)) { + if (mkdir(ILMIDIAG_DIR, 0755) < 0) return -1; + else diag(COMPONENT, DIAG_DEBUG, + "Created directory " ILMIDIAG_DIR); + } + + fd = socket(AF_UNIX, SOCK_STREAM, 0); + if (fd < 0) return -1; + + memset(&addr, 0, sizeof(addr)); + snprintf(addr.sun_path, sizeof(addr.sun_path) - 1, + "%s/%d.%d.%d", + ILMIDIAG_DIR, + vc->sap_addr.itf, + vc->sap_addr.vpi, + vc->sap_addr.vci); + addr.sun_family = AF_UNIX; + unlink(addr.sun_path); + oldumask = umask(0); + if (bind(fd, (struct sockaddr *)&addr, SUN_LEN(&addr)) < 0) { + diag(COMPONENT, DIAG_ERROR, "unable to bind ilmidiag socket: " + "%s", strerror(errno)); + close(fd); + unlink(addr.sun_path); + umask(oldumask); + return -1; + } + umask(oldumask); + + if (listen(fd, ILMIDIAG_BACKLOG) < 0) { + diag(COMPONENT, DIAG_FATAL, "Unable to listen on diag socket:" + " %s", strerror(errno)); + close(fd); + unlink(addr.sun_path); + return -1; + } + *listenfd = fd; + return 0; + } + + int handle_ilmidiag(int fd, AttPoint *apoint, Config *config) { + struct sockaddr_un incoming; + socklen_t inlen = sizeof(incoming); + struct atm_cirange cir; + struct ilmi_state ic; + int newfd = accept(fd, (struct sockaddr *)&incoming, &inlen); + + if (newfd < 0) return -1; + /* Since this is a unix socket, there's no need to be portable. */ + + memset( &ic, 0, sizeof( ic )); + ic.ilmi_version = 2; /* version4point0 */ + ic.uni_version = atmfAtmLayerUniVersionValue & 0xff; + + if( get_ci_range( &cir ) < 0 ) + diag( COMPONENT, DIAG_ERROR, "get_ci_range() failed" ); + else{ + if( cir.vpi_bits < config->atmfAtmLayerMaxVpiBits ) + ic.vpi_bits = cir.vpi_bits; + else ic.vpi_bits = config->atmfAtmLayerMaxVpiBits & 0xff; + if( cir.vci_bits < config->atmfAtmLayerMaxVciBits ) + ic.vci_bits = cir.vci_bits; + else ic.vci_bits = config->atmfAtmLayerMaxVciBits & 0xff; + } + + ic.state = ( ilmi_state == down ) ? 0 : 1; + if( remsys->sysName.octs ) strncpy( ic.remote_sysname, + remsys->sysName.octs, + ( remsys->sysName.octetLen < ATM_REMOTE_SYSNAME_LEN ) + ? remsys->sysName.octetLen : ATM_REMOTE_SYSNAME_LEN ); + else strncpy( ic.remote_sysname, "(empty)", 7 ); + if( remsys->sysContact.octs ) strncpy( ic.remote_contact, + remsys->sysContact.octs, + ( remsys->sysContact.octetLen < ATM_REMOTE_CONTACT_LEN ) + ? remsys->sysContact.octetLen : ATM_REMOTE_CONTACT_LEN ); + else strncpy( ic.remote_contact, "(empty)", 7 ); + ic.remote_portid = apoint->atmfPortMyIfIdentifier; + if( apoint->atmfPortMyIfName.octs ) strncpy( + ic.remote_portname, apoint->atmfPortMyIfName.octs, + ( apoint->atmfPortMyIfName.octetLen < ATM_REMOTE_PORTNAME_LEN ) + ? apoint->atmfPortMyIfName.octetLen : ATM_REMOTE_PORTNAME_LEN ); + else strncpy( ic.remote_portname, "(empty)", 7 ); + + write(newfd, &ic, sizeof(ic)); + close(newfd); + exit(0); + } + Index: io.h =================================================================== RCS file: /cvsroot/linux-atm/linux-atm/src/ilmid/io.h,v retrieving revision 1.2.2.2 retrieving revision 1.2.2.3 diff -C2 -d -r1.2.2.2 -r1.2.2.3 *** io.h 6 Oct 2005 15:39:58 -0000 1.2.2.2 --- io.h 11 Jul 2007 16:07:57 -0000 1.2.2.3 *************** *** 40,46 **** int read_message(int fd, Message *message); int send_message(int fd, Message *message); ! int open_ilmi(int itf,const char *qos_spec); int get_ci_range(struct atm_cirange *ci); void add_lecs(int itf, char *lecs); #endif --- 40,48 ---- int read_message(int fd, Message *message); int send_message(int fd, Message *message); ! int open_ilmi(struct sockaddr_atmpvc *, const char *qos_spec); int get_ci_range(struct atm_cirange *ci); void add_lecs(int itf, char *lecs); + int open_ilmidiag(int *listenfd, const struct sockaddr_atmpvc *); + int handle_ilmidiag(int fd, AttPoint *apoint, Config *config); #endif |