if( strcmp(argv[1], "route") == 0 )
{
// Add new route
- if( strcmp(argv[2], "add") == 0 )
+ if( argc > 2 && strcmp(argv[2], "add") == 0 )
{
uint8_t dest[16] = {0};
uint8_t nextHop[16] = {0};
int addrType, subnetBits = -1;
int nextHopType, nextHopBits=-1;
- char *ifaceName;
+ char *ifaceName = NULL;
int metric = DEFAULT_METRIC;
// Usage:
// ifconfig route add <host>[/<prefix>] <interface> [<metric>]
return 0;
}
// Delete a route
- else if( strcmp(argv[2], "del") == 0 )
+ else if( argc > 2 && strcmp(argv[2], "del") == 0 )
{
// Usage:
// ifconfig route del <routenum>
fprintf(stderr, " %s [<interface>]\n", ProgName);
fprintf(stderr, " Print the current interfaces (or only <interface> if passed)\n");
fprintf(stderr, "\n");
- fprintf(stderr, " %s routes\n", ProgName);
+ fprintf(stderr, " %s route\n", ProgName);
fprintf(stderr, " Print the routing tables\n");
- fprintf(stderr, " %s routes add <host>[/<prefix>] [<nexthop> OR <iface>] [<metric>]\n", ProgName);
+ fprintf(stderr, " %s route add <host>[/<prefix>] [<nexthop> OR <iface>] [<metric>]\n", ProgName);
fprintf(stderr, " Add a new route\n");
- fprintf(stderr, " %s routes del <host>[/<prefix>]\n", ProgName);
- fprintf(stderr, " %s routes del <routenum>\n", ProgName);
+ fprintf(stderr, " %s route del <host>[/<prefix>]\n", ProgName);
+ fprintf(stderr, " %s route del <routenum>\n", ProgName);
fprintf(stderr, " Add a new route\n");
fprintf(stderr, "\n");
fprintf(stderr, "A note on Acess's IP Stack:\n");
dp = open(IPSTACK_ROOT"/routes", OPENFLAG_READ);
+ printf("Type\tNetwork \tGateway \tMetric\tIFace\n");
+
while( readdir(dp, filename) )
{
if(filename[0] == '.') continue;
return ;
}
- type = ioctl(fd, 4, NULL);
-
- // Ignore -1 values
- if( type == -1 ) {
- return ;
- }
-
- printf("%s:\t", Name);
- {
- int call_num = ioctl(fd, 3, "get_interface");
- int len = ioctl(fd, call_num, NULL);
- char *buf = malloc(len+1);
- ioctl(fd, call_num, buf);
- printf("'%s'\t", buf);
- free(buf);
+ 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);
}
+ 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)
printf("DISABLED\n");
break;
case 4: // IPv4
- {
- uint8_t net[4], addr[4];
- int subnet, metric;
- printf("IPv4\n");
- 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("\tNetwork: %s/%i\n", Net_PrintAddress(4, net), subnet);
- printf("\tGateway: %s\n", Net_PrintAddress(4, addr));
- printf("\tMetric: %i\n", metric);
- }
+ printf("IPv4\t");
break;
case 6: // IPv6
- {
- uint16_t net[8], addr[8];
- int subnet, metric;
- printf("IPv6\n");
- 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("\tNetwork: %s/%i\n", Net_PrintAddress(6, net), subnet);
- printf("\tGateway: %s\n", Net_PrintAddress(6, addr));
- printf("\tMetric: %i\n", metric);
- }
+ printf("IPv6\t");
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
+ {
+ int call_num = ioctl(fd, 3, "get_interface");
+ int len = ioctl(fd, call_num, NULL);
+ char *buf = malloc(len+1);
+ ioctl(fd, call_num, buf);
+ printf("'%s'\t", buf);
+ free(buf);
+ }
+
printf("\n");
close(fd);
{
int fd;
int num;
- char tmp[sizeof(IPSTACK_ROOT"/routes/") + 5]; // enough for 4 digits
char *ifaceToFree = NULL;
// Get interface name
}
// 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);
/**
* \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)
{