From: Paul B. S. <pa...@us...> - 2001-09-03 18:41:09
|
Update of /cvsroot/linux-atm/linux-atm/src/debug In directory usw-pr-cvs1:/tmp/cvs-serv10656/debug Added Files: Tag: V2_4_0 ed.c svctor.c delay.c dnstest.c Makefile.am znth.c peek.pl Log Message: --- NEW FILE: ed.c --- /* ed.c - eni memory dump */ #if HAVE_CONFIG_H #include <config.h> #endif #include <stdlib.h> #include <stdio.h> #include <sys/ioctl.h> #include <sys/types.h> #include <sys/socket.h> #include <atm.h> #include <linux/atmdev.h> #include <linux/sonet.h> #include <linux/atm_eni.h> static void usage(const char *name) { fprintf(stderr,"usage: %s itf\n",name); exit(1); } int main(int argc,char **argv) { struct atmif_sioc req; int s; if (argc != 2) usage(argv[0]); if ((s = socket(PF_ATMPVC,SOCK_DGRAM,ATM_AAL5)) < 0) { perror("socket"); return 1; } req.number = atoi(argv[1]); if (ioctl(s,ENI_MEMDUMP,&req) < 0) { perror("ioctl ENI_MEMDUMP"); return 1; } return 0; } --- NEW FILE: svctor.c --- /* svctor.c - SVC Torture */ /* Written 1998,1999 by Werner Almesberger, EPFL ICA */ /* * This program frantically tries to concurrently set up connections to * itself. Once it has obtained all the connections it was looking for, * it exits, leaving the system with a lot of things to clean up. */ #if HAVE_CONFIG_H #include <config.h> #endif #define ITF 0 /* interface we use - should be command-line arg */ #define MAX_PAR 4 /* maximum number of concurrent connect()s */ #define EXIT_LIM 3 /* exit after establishing that many connections */ #define MAX_ADDR 10 /* maximum number of local addresses */ #define SAP "bhli:oui=0x0060D7,id=0x010000ff" #define QOS "ubr,aal5:tx:max_sdu=100,rx:max_sdu=100" #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <signal.h> #include <errno.h> #include <atm.h> #include <sys/types.h> #include <sys/time.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <linux/atmdev.h> int main(void) { static int fd[MAX_PAR]; /* to force initialization */ struct sockaddr_atmsvc local[MAX_ADDR]; struct atmif_sioc req; struct atm_sap sap; struct atm_qos qos; int listen_fd; fd_set rset,wset; int fds,completed = 0,connects = 0,accepts = 0; FD_ZERO(&rset); FD_ZERO(&wset); if (text2sap(SAP,&sap,0) < 0) { fprintf(stderr,"text2sap\n"); return 1; } if (text2qos(QOS,&qos,0) < 0) { fprintf(stderr,"text2qos\n"); return 1; } listen_fd = socket(PF_ATMSVC,SOCK_DGRAM,0); if (listen_fd < 0) { perror("socket"); return 1; } req.number = ITF; req.arg = local; req.length = sizeof(local); if (ioctl(listen_fd,ATM_GETADDR,&req) < 0) { perror("ioctl"); return 1; } if (!req.length) { fprintf(stderr,"No local address\n"); return 1; } if (setsockopt(listen_fd,SOL_ATM,SO_ATMSAP,&sap,sizeof(sap)) < 0) { perror("setsockopt SO_ATMSAP"); return 1; } if (setsockopt(listen_fd,SOL_ATM,SO_ATMQOS,&qos,sizeof(qos)) < 0) { perror("setsockopt SO_ATMQOS"); return 1; } if (bind(listen_fd,(struct sockaddr *) local,sizeof(*local)) < 0) { perror("bind"); return 1; } if (fcntl(listen_fd,F_SETFL,O_NONBLOCK) < 0) { perror("fnctl"); return 1; } if (listen(listen_fd,5) < 0) { perror("listen"); return 1; } FD_SET(listen_fd,&rset); fds = listen_fd+1; (void) signal(SIGCHLD,SIG_IGN); while (1) { static struct timeval no_delay; fd_set _rset = rset; fd_set _wset = wset; int ret,i,empty; no_delay.tv_sec = 0; no_delay.tv_usec = 100000; ret = select(fds,&_rset,&_wset,NULL,&no_delay); if (ret < 0) { perror("select"); return 1; } if (FD_ISSET(listen_fd,&_rset)) { pid_t pid; pid = fork(); if (pid < 0) { perror("fork"); return 1; } if (!pid) { if (accept(listen_fd,NULL,NULL) >= 0) exit(0); perror("accept"); return 1; } accepts++; } empty = -1; for (i = 0; i < MAX_PAR; i++) if (!fd[i]) empty = i; else if (FD_ISSET(fd[i],&_wset)) { struct sockaddr_atmsvc dummy; if (connect(fd[i],(struct sockaddr *) &dummy,sizeof(dummy)) < 0) { perror("connect"); return 1; } FD_CLR(fd[i],&wset); fd[i] = 0; empty = i; if (++completed == EXIT_LIM) { printf("%d attempted, %d completed, %d accepts\n", connects,completed,accepts); return 0; } } if (empty != -1) { fd[empty] = socket(PF_ATMSVC,SOCK_DGRAM,0); if (fd[empty] < 0) { perror("socket"); return 1; } if (fcntl(fd[empty],F_SETFL,O_NONBLOCK) < 0) { perror("fnctl"); return 1; } if (setsockopt(fd[empty],SOL_ATM,SO_ATMSAP,&sap,sizeof(sap)) < 0) { perror("setsockopt SO_ATMSAP"); return 1; } if (setsockopt(fd[empty],SOL_ATM,SO_ATMQOS,&qos,sizeof(qos)) < 0) { perror("setsockopt SO_ATMQOS"); return 1; } if (connect(fd[empty],(struct sockaddr *) local,sizeof(*local)) < 0 && errno != EINPROGRESS) { perror("connect"); return 1; } FD_SET(fd[empty],&wset); if (fds <= fd[empty]) fds = fd[empty]+1; connects++; } } return 0; } --- NEW FILE: delay.c --- /* delay.c - Simplistic AAL5-level software delay line */ /* Written 1996-2000 by Werner Almesberger, EPFL-LRC/ICA */ /* * BUGS: * - delay increases with load * - processing delay is far too big (always measure with ping first) * - horrifying command-line syntax */ #if HAVE_CONFIG_H #include <config.h> #endif #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <string.h> #include <errno.h> #include <fcntl.h> #include <sys/time.h> #include <sys/types.h> #include "atm.h" typedef struct _packet { struct timeval due; int size; struct _packet *next; char data[1]; } PACKET; typedef struct _link { int in,out; struct timeval delay; PACKET *queue,*last; struct _link *next; } LINK; static LINK *links = NULL; static fd_set in; static int fds = 0; #define LESS(a,b) ((a).tv_sec < (b).tv_sec || ((a).tv_sec == (b).tv_sec && \ (a).tv_usec < (b).tv_usec)) static void loop(void) { LINK *lnk; PACKET *p; struct timeval now,next,delta,*to; fd_set curr; char *buffer; int ready,size; if (!(buffer = malloc(sizeof(PACKET)-1+ATM_MAX_AAL5_PDU+4095))) { perror("buffer"); exit(1); } buffer = (char *) (((unsigned long) buffer+4095-(sizeof(PACKET)-1)) & ~4095); if (gettimeofday(&now,NULL) < 0) { perror("gettimeofday"); exit(1); } while (1) { curr = in; for (lnk = links; lnk; lnk = lnk->next) if (lnk->queue) break; if (!lnk) to = NULL; else { for (next = lnk->queue->due; lnk; lnk = lnk->next) if (lnk->queue && LESS(lnk->queue->due,next)) next = lnk->queue->due; delta.tv_sec = next.tv_sec-now.tv_sec; delta.tv_usec = next.tv_usec-now.tv_usec; if (delta.tv_usec < 0) { delta.tv_sec--; delta.tv_usec += 1000000; } if (delta.tv_usec > 0) { delta.tv_sec++; delta.tv_usec -= 1000000; } if (delta.tv_sec < 0) delta.tv_sec = delta.tv_usec = 0; to = δ } if ((ready = select(fds,&curr,NULL,NULL,to)) < 0) { perror("select"); exit(1); } if (gettimeofday(&now,NULL) < 0) { perror("gettimeofday"); exit(1); } if (ready) for (lnk = links; lnk; lnk = lnk->next) while (1) { size = read(lnk->in,buffer,ATM_MAX_AAL5_PDU); if (size < 0) { if (errno == EAGAIN) break; else { perror("read"); exit(1); } } if (size > 0) { if (!(p = malloc(sizeof(PACKET)-1+size))) { perror("malloc"); exit(1); } memcpy(p->data,buffer,size); p->size = size; p->due.tv_sec = now.tv_sec+lnk->delay.tv_sec; p->due.tv_usec = now.tv_usec+lnk->delay.tv_usec; if (p->due.tv_usec > 1000000) { p->due.tv_sec++; p->due.tv_usec -= 1000000; } p->next = NULL; if (lnk->queue) lnk->last->next = p; else lnk->queue = p; lnk->last = p; } } for (lnk = links; lnk; lnk = lnk->next) while (lnk->queue && LESS(lnk->queue->due,now)) { p = lnk->queue; lnk->queue = p->next; if ((size = write(lnk->out,p->data,p->size)) < 0) { perror("write"); exit(1); } if (p->size != size) fprintf(stderr,"short write: %d < %d\n",size,p->size); free(p); } } } static int setup(char *spec,int tx) { struct sockaddr_atmpvc addr; struct atm_qos qos; char *here; int fd; if (!(here = strchr(spec,','))) { memset(&qos,0,sizeof(qos)); if (tx) qos.txtp.traffic_class = ATM_UBR; else qos.rxtp.traffic_class = ATM_UBR; } else { *here = 0; if (text2qos(here+1,&qos,0) < 0) { fprintf(stderr,"invalid QOS: %s\n",here+1); exit(1); } } if (tx) qos.rxtp.traffic_class = ATM_NONE; else qos.txtp.traffic_class = ATM_NONE; qos.aal = ATM_AAL5; if (text2atm(spec,(struct sockaddr *) &addr,sizeof(addr), T2A_PVC | T2A_NAME) < 0) { fprintf(stderr,"invalid PVC: %s\n",spec); exit(1); } if ((fd = socket(PF_ATMPVC,SOCK_DGRAM,0)) < 0) { perror("socket"); exit(1); } if (setsockopt(fd,SOL_ATM,SO_ATMQOS,&qos,sizeof(qos)) < 0) { perror("setsockopt SO_ATMQOS"); exit(1); } if (bind(fd,(struct sockaddr *) &addr,sizeof(addr)) < 0) { perror("bind"); exit(1); } return fd; } static void usage(const char *name) { fprintf(stderr,"usage: %s path ...\n",name); fprintf(stderr," path :== vc/vc/delay\n"); fprintf(stderr," vc :== [itf.]vpi.vci[,qos_spec]\n"); fprintf(stderr," delay :== timeunit\n"); fprintf(stderr," unit :== s | ms\n"); exit(1); } int main(int argc,char **argv) { LINK *dsc; const char *name; unsigned long delay; char *end,*here; name = argv[0]; FD_ZERO(&in); if (argc < 2) usage(name); while (argc > 1) { argc--; argv++; if (!(dsc = malloc(sizeof(LINK)))) { perror("malloc"); return 1; } if (!(here = strtok(*argv,"/"))) usage(name); dsc->in = setup(here,0); FD_SET(dsc->in,&in); if (dsc->in >= fds) fds = dsc->in+1; if (fcntl(dsc->in,F_SETFL,O_NONBLOCK) < 0) { perror("fcntl"); return 1; } if (!(here = strtok(NULL,"/"))) usage(name); dsc->out = setup(here,1); if (!(here = strtok(NULL,"/"))) usage(name); delay = strtoul(here,&end,10); switch (*end) { case 's': dsc->delay.tv_sec = delay; dsc->delay.tv_usec = 0; break; case 'm': dsc->delay.tv_sec = delay/1000; dsc->delay.tv_usec = (delay % 1000)*1000; if (*++end != 's') usage(name); break; default: usage(name); } if (end[1]) usage(name); dsc->queue = dsc->last = NULL; dsc->next = links; links = dsc; } loop(); return 0; } --- NEW FILE: dnstest.c --- #if HAVE_CONFIG_H #include <config.h> #endif #include <stdlib.h> #include <stdio.h> #include <string.h> #include <netinet/in.h> #include <arpa/nameser.h> #include <netdb.h> #include <resolv.h> #include <atm.h> int main(int argc, char **argv) { int i; unsigned char *pnsap; struct sockaddr_atmsvc addr; unsigned char buffer[1024]; if (argc != 2) { printf("Usage: %s <name> \n", argv[0]); exit(0); } if (text2atm(argv[1], (struct sockaddr *) &addr, sizeof(addr), T2A_NAME) < 0) { perror("text2atm()"); exit(1); } if (atm2text(buffer, 1024, (struct sockaddr *) &addr, A2T_NAME) < 0) { perror("atm2text()"); exit(2); } printf("Looking up %s \n", argv[1]); printf("Direct: "); pnsap = (unsigned char *) &(addr.sas_addr.prv); for (i = 0; i < 20; i++) { printf("%02X", pnsap[i]); } printf("\n"); printf("Reverse: %s \n", buffer); exit(0); } --- NEW FILE: Makefile.am --- # Remove the # for more hardware-specific debugging programs. # I'll need those only if you're fiddling with the guts of drivers. noinst_PROGRAMS = delay svctor # ed dnstest znth LDADD = $(top_builddir)/src/lib/libatm.la delay_SOURCES = delay.c svctor_SOURCES = svctor.c #ed_SOURCES = ed.c #dnstest_SOURCES = dnstest.c #znth_SOURCES = znth.c #EXTRA_DIST = peek.pl EXTRA_DIST = peek.pl ed.c dnstest.c znth.c --- NEW FILE: znth.c --- /* znth.c - ZN122x timestamp adjustments history */ /* Written 1996-1998 by Werner Almesberger, EPFL-LRC/ICA */ #if HAVE_CONFIG_H #include <config.h> #endif #include <stdlib.h> #include <stdio.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <sys/time.h> #include <atm.h> #include <linux/atm_zatm.h> int main(int argc,char **argv) { struct atmif_sioc sioc; struct zatm_t_hist history[ZATM_TIMER_HISTORY_SIZE]; char *end; int s,i; if (argc != 2 || ((sioc.number = strtoul(argv[1],&end,0)), *end)) { fprintf(stderr,"usage: %s itf\n",*argv); return 1; } if ((s = socket(PF_ATMPVC,SOCK_DGRAM,0)) < 0) { perror("socket"); return 1; } sioc.arg = history; sioc.length = sizeof(history); if (ioctl(s,ZATM_GETTHIST,&sioc) < 0) { perror("ioctl ZATM_GETTHIST"); return 1; } for (i = 0; i < ZATM_TIMER_HISTORY_SIZE; i++) { struct timeval diff; if (!history[i].real.tv_sec) continue; printf("%2ld:%02ld:%02ld.%06ld: ", ((long) history[i].real.tv_sec/3600) % 24, ((long) history[i].real.tv_sec/60) % 60, (long) history[i].real.tv_sec % 60, (long) history[i].real.tv_usec); history[i].expected.tv_sec += history[i].expected.tv_usec/1000000; history[i].expected.tv_usec %= 1000000; diff.tv_sec = history[i].expected.tv_sec-history[i].real.tv_sec; diff.tv_usec = history[i].expected.tv_usec-history[i].real.tv_usec; if (diff.tv_sec < -2000 || diff.tv_sec > 2000) printf("%11ld SECONDS\n",(long) diff.tv_sec); else { diff.tv_usec += diff.tv_sec*1000000; printf("%11ld usec\n",(long) diff.tv_usec); } } return 0; } --- NEW FILE: peek.pl --- #!/usr/bin/perl $base = 0x220000; $off = $ARGV[0]; $dsc = $base+hex($off)*4; $start = ($dsc & ~15)-64; $| = 1; printf("Descriptor is at 0x%06x\n",$dsc); system("hexdump -e'\"%06.6_ax \" 16/1 \"%02x \" \"\\n\"' -s $start /var/tmp/all"); |