X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2Fifconfig_src%2Fmain.c;h=334ea1370d53c06775a36565e3df5b12e3e981fb;hb=c95a4a86afd477a8d6dc6949e0ce6175a41553d1;hp=6091bdcce40fd55b962613e419f23ea88b17be84;hpb=7ab41f4e18165ed116576d0872e6faa41a1981f2;p=tpg%2Facess2.git diff --git a/Usermode/Applications/ifconfig_src/main.c b/Usermode/Applications/ifconfig_src/main.c index 6091bdcc..334ea137 100644 --- a/Usermode/Applications/ifconfig_src/main.c +++ b/Usermode/Applications/ifconfig_src/main.c @@ -227,7 +227,7 @@ void DumpRoutes(void) dp = open(IPSTACK_ROOT"/routes", OPENFLAG_READ); - printf("ID\tType\tNetwork \tGateway \tMetric\tIFace\n"); + printf("Type\tNetwork \tGateway \tMetric\tIFace\n"); while( readdir(dp, filename) ) { @@ -327,15 +327,24 @@ void DumpRoute(const char *Name) return ; } - type = ioctl(fd, 4, NULL); - - // Ignore -1 values - if( type == -1 ) { - return ; + int ofs = 2; + type = atoi(Name); + + int i; + int len = Net_GetAddressSize(type); + uint8_t net[len], gw[len]; + int subnet, metric; + for( i = 0; i < len; i ++ ) { + char tmp[5] = "0x00"; + tmp[2] = Name[ofs++]; + tmp[3] = Name[ofs++]; + net[i] = atoi(tmp); } - - // Number - printf("%s\t", Name); + ofs ++; + subnet = atoi(Name+ofs); + ofs ++; + metric = atoi(Name+ofs); + ioctl(fd, ioctl(fd, 3, "get_nexthop"), gw); // Get Gateway/NextHop // Get the address type switch(type) @@ -344,37 +353,18 @@ void DumpRoute(const char *Name) printf("DISABLED\n"); break; case 4: // IPv4 - { - uint8_t net[4], addr[4]; - int subnet, metric; printf("IPv4\t"); - ioctl(fd, ioctl(fd, 3, "get_network"), net); // Get Network - ioctl(fd, ioctl(fd, 3, "get_nexthop"), addr); // Get Gateway/NextHop - subnet = ioctl(fd, ioctl(fd, 3, "getset_subnetbits"), NULL); // Get Subnet Bits - metric = ioctl(fd, ioctl(fd, 3, "getset_metric"), NULL); // Get Subnet Bits - printf("%s/%i\t", Net_PrintAddress(4, net), subnet); - printf("%s \t", Net_PrintAddress(4, addr)); - printf("%i\t", metric); - } break; case 6: // IPv6 - { - uint16_t net[8], addr[8]; - int subnet, metric; printf("IPv6\t"); - ioctl(fd, ioctl(fd, 3, "get_network"), net); // Get Network - ioctl(fd, ioctl(fd, 3, "get_nexthop"), addr); // Get Gateway/NextHop - subnet = ioctl(fd, ioctl(fd, 3, "getset_subnetbits"), NULL); // Get Subnet Bits - metric = ioctl(fd, ioctl(fd, 3, "getset_metric"), NULL); // Get Subnet Bits - printf("%s/%i\t", Net_PrintAddress(6, net), subnet); - printf("%s\t", Net_PrintAddress(6, addr)); - printf("%i\t", metric); - } break; default: // Unknow printf("UNKNOWN (%i)\n", type); break; } + printf("%s/%i\t", Net_PrintAddress(type, net), subnet); + printf("%s \t", Net_PrintAddress(type, gw)); + printf("%i\t", metric); // Interface { @@ -417,7 +407,6 @@ void AddRoute(const char *Interface, int AddressType, void *Dest, int MaskBits, { int fd; int num; - char tmp[sizeof(IPSTACK_ROOT"/routes/") + 5]; // enough for 4 digits char *ifaceToFree = NULL; // Get interface name @@ -460,19 +449,33 @@ void AddRoute(const char *Interface, int AddressType, void *Dest, int MaskBits, } // Create route - fd = open(IPSTACK_ROOT"/routes", 0); - num = ioctl(fd, ioctl(fd, 3, "add_route"), (char*)Interface); - close(fd); - - // Open route - sprintf(tmp, IPSTACK_ROOT"/routes/%i", num); - fd = open(tmp, 0); + int addrsize = Net_GetAddressSize(AddressType); + int len = snprintf(NULL, 0, "/Devices/ip/routes/%i::%i:%i", AddressType, MaskBits, Metric) + addrsize*2; + char path[len+1]; + { + int i, ofs; + ofs = sprintf(path, "/Devices/ip/routes/%i:", AddressType); + for( i = 0; i < addrsize; i ++ ) + sprintf(path+ofs+i*2, "%02x", ((uint8_t*)Dest)[i]); + ofs += addrsize*2; + sprintf(path+ofs, ":%i:%i", MaskBits, Metric); + } + + fd = open(path, 0); + if( fd != -1 ) { + close(fd); + fprintf(stderr, "Unable to create route '%s', already exists\n", path); + return ; + } + fd = open(path, OPENFLAG_CREATE, 0); + if( fd == -1 ) { + fprintf(stderr, "Unable to create '%s'\n", path); + return ; + } - ioctl(fd, ioctl(fd, 3, "set_network"), Dest); if( NextHop ) ioctl(fd, ioctl(fd, 3, "set_nexthop"), NextHop); - ioctl(fd, ioctl(fd, 3, "getset_subnetbits"), &MaskBits); - ioctl(fd, ioctl(fd, 3, "getset_metric"), &Metric); + ioctl(fd, ioctl(fd, 3, "set_interface"), (void*)Interface); close(fd); @@ -483,8 +486,8 @@ void AddRoute(const char *Interface, int AddressType, void *Dest, int MaskBits, /** * \note Debugging HACK! - * \brief Autoconfigure the specified device to 10.0.2.55/8 using - * 10.0.2.1 as the gateway. + * \brief Autoconfigure the specified device to 10.0.2.55/24 using + * 10.0.2.2 as the gateway. */ int DoAutoConfig(const char *Device) {