/* NAT_control.c -- user interface and control functions for NAT */ #include #include #include #include #include #include #include "NAT_shared_defs.h" #include "NAT_types.h" #define USAGE \\\\ "Usage: %s [ show | clear | silent | arp | nat | verbose ]\\\\n", argv[0] void AppShow( void ) { int i; UINT32 *p1, *p2; char buf[1024]; int natfd; natfd = open(NAT_DEV_FILE, O_RDWR, 0); if ( natfd == -1 ) { printf("Failed to open %s\\\\n",NAT_DEV_FILE); return; } p1=(UINT32 *)buf; /* ingress counters */ p2=(UINT32 *)(buf+RX_CNTR_SIZE); /* egress counters */ ioctl(natfd,GET_RX_COUNTER,p1); ioctl(natfd,GET_TX_COUNTER,p2); for( i=0; i<3; i++ ) { printf("Port %d\\\\n", i); printf(" Ingress Counters\\\\n"); printf(" Received packets: %10u\\\\n", *p1++); printf(" Dropped packets: %10u\\\\n", *p1++); printf(" Exception packets: %10u\\\\n", *p1++); printf(" Bytes received: %10u\\\\n", *p1++); printf(" Egress Counters\\\\n"); printf(" Transmitted packets: %10u\\\\n", *p2++); printf(" Dropped packets: %10u\\\\n", *p2++); printf(" Transmitted bytes: %10u\\\\n", *p2++); printf(" Dropped bytes: %10u\\\\n\\\\n", *p2++); } close(natfd); return; } void AppSilent() { int natfd; natfd = open(NAT_DEV_FILE, O_RDWR, 0); if ( natfd == -1 ) { printf("Failed to open %s\\\\n",NAT_DEV_FILE); return; } ioctl(natfd,SILENT,NULL); close(natfd); } void AppVerbose() { int natfd; natfd = open(NAT_DEV_FILE, O_RDWR, 0); if ( natfd == -1 ) { printf("Failed to open %s\\\\n",NAT_DEV_FILE); return; } ioctl(natfd,VERBOSE,NULL); close(natfd); } void AppClear( void ) { int natfd; natfd = open(NAT_DEV_FILE, O_RDWR, 0); if ( natfd == -1 ) { printf("Failed to open %s\\\\n",NAT_DEV_FILE); return; } ioctl(natfd,CLR_RX_COUNTER,NULL); ioctl(natfd,CLR_TX_COUNTER,NULL); close(natfd); printf("Counters cleared\\\\n"); return; } void AppGetArpTbl( void ) { int natfd,i; arp_entry buf[ARP_TABLE_SIZE]; natfd = open(NAT_DEV_FILE, O_RDWR, 0); if ( natfd == -1 ) { printf("Failed to open %s\\\\n",NAT_DEV_FILE); return; } ioctl(natfd,GET_ARP_TABLE,buf); close(natfd); for (i=0;i %02X:%02X:%02X:%02X:%02X:%02X iface: %i\\\\n", IP2B(buf[i].ip_addr), ETH2B(buf[i].eth_w0), buf[i].ifnum); } return; } void AppGetNatTbl( void ) { int natfd,i; nat_entry buf[NAT_TABLE_SIZE]; unsigned char timer[2*NAT_TABLE_SIZE]; natfd = open(NAT_DEV_FILE, O_RDWR, 0); if ( natfd == -1 ) { printf("Failed to open %s\\\\n",NAT_DEV_FILE); return; } ioctl(natfd,GET_NAT_TABLE,buf); ioctl(natfd,GET_TIMER_TABLE,timer); for (i=0;i