*/
int memcmp(const void *m1, const void *m2, size_t Num)
{
+ if( Num == 0 ) return 1; // No bytes are always identical
+
while(Num--)
{
if(*(Uint8*)m1 != *(Uint8*)m2) break;
while(i--) Debug_Putchar(' ');
Debug_Puts(1, FuncName);
- Debug_FmtS("(%i)", tid);
+ Debug_FmtS("[%i]", tid);
Debug_Puts(1, ": RETURN");
// No Return
ENTER("pInterface xAddress", Interface, Address);
- // Check routing tables
+ // Check routing tables if not on this subnet
+ if( IPStack_CompareAddress(4, &Address, Interface->Address, Interface->SubnetBits) == 0 )
{
tRoute *route = IPStack_FindRoute(4, Interface, &Address);
if( route ) {
extern int IPStack_AddFile(tSocketFile *File);
extern int IPStack_GetAddressSize(int AddressType);
extern int IPStack_CompareAddress(int AddressType, void *Address1, void *Address2, int CheckBits);
+extern const char *IPStack_PrintAddress(int AddressType, void *Address);
extern tRoute *IPStack_FindRoute(int AddressType, tInterface *Interface, void *Address);
if( CheckBits < 0 ) CheckBits = 0;
if( CheckBits > size*8 ) CheckBits = size*8;
+ if( CheckBits == 0 ) return 1; // /0 matches anythin
+
// Check first bits/8 bytes
if( memcmp(Address1, Address2, CheckBits/8) != 0 ) return 0;
return 0;
}
+
+const char *IPStack_PrintAddress(int AddressType, void *Address)
+{
+ switch( AddressType )
+ {
+ case 4: {
+ static char ret[4*3+3+1];
+ Uint8 *addr = Address;
+ sprintf(ret, "%i.%i.%i.%i", addr[0], addr[1], addr[2], addr[3]);
+ return ret;
+ }
+
+ case 6: {
+ static char ret[8*4+7+1];
+ Uint16 *addr = Address;
+ sprintf(ret, "%x:%x:%x:%x:%x:%x:%x:%x",
+ addr[0], addr[1], addr[2], addr[3],
+ addr[4], addr[5], addr[6], addr[7]
+ );
+ return ret;
+ }
+
+ default:
+ return "";
+ }
+}
int IPStack_RouteDir_IOCtl(tVFS_Node *Node, int ID, void *Data)
{
int tmp;
+ ENTER("pNode iID pData", Node, ID, Data);
switch(ID)
{
// --- Standard IOCtls (0-3) ---
return tmp;
case 4: // Add Route
- if( !CheckString(Data) ) return -1;
- return IPStack_Route_Create(Data);
+ if( !CheckString(Data) ) LEAVE_RET('i', -1);
+ tmp = IPStack_Route_Create(Data);
+ LEAVE('i', tmp);
+ return tmp;
case 5: // Locate Route
{
tRoute *rt;
if( !CheckMem(Data, sizeof(int)) )
- return -1;
+ LEAVE_RET('i', -1);
if( !CheckMem(Data, sizeof(int) + IPStack_GetAddressSize(data->Type)) )
- return -1;
+ LEAVE_RET('i', -1);
+ Log_Debug("IPStack", "Route_RouteDir_IOCtl - FindRoute %i, %s\n",
+ data->Type, IPStack_PrintAddress(data->Type, data->Addr) );
rt = IPStack_FindRoute(data->Type, NULL, data->Addr);
if( !rt )
- return 0;
+ LEAVE_RET('i', 0);
+ LEAVE('i', rt->Node.Inode);
return rt->Node.Inode;
}
break;
}
+ LEAVE('i', 0);
return 0;
}
// Note: Oh man! This is such a hack
{
tVFS_Node *node = IPStack_Root_FindDir(NULL, InterfaceName);
- if( !node ) return 0;
+ if( !node ) {
+ Log_Debug("IPStack", "IPStack_Route_Create - Unknown interface '%s'\n", InterfaceName);
+ return 0;
+ }
iface = node->ImplPtr;
}
gIP_Routes = gIP_RoutesEnd = rt;
}
+ Log_Log("IPStack", "Route entry for '%s' created\n", InterfaceName);
+
return rt->Node.Inode;
}
tRoute *rt;
tRoute *best = NULL;
- if( Interface && AddressType != Interface->Type ) return NULL;
+ ENTER("iAddressType pInterface sAddress",
+ AddressType, Interface, IPStack_PrintAddress(AddressType, Address));
+
+ if( Interface && AddressType != Interface->Type ) {
+ LOG("Interface->Type (%i) != AddressType", Interface->Type);
+ LEAVE('n');
+ return NULL;
+ }
for( rt = gIP_Routes; rt; rt = rt->Next )
{
// Check address type
if( rt->AddressType != AddressType ) continue;
+ LOG("Checking network %s/%i", IPStack_PrintAddress(AddressType, rt->Network), rt->SubnetBits);
+
// Check if the address matches
if( !IPStack_CompareAddress(AddressType, rt->Network, Address, rt->SubnetBits) )
continue;
if( best ) {
// More direct routes are preferred
- if( best->SubnetBits > rt->SubnetBits ) continue;
+ if( best->SubnetBits > rt->SubnetBits ) {
+ LOG("Skipped - less direct (%i < %i)", rt->SubnetBits, best->SubnetBits);
+ continue;
+ }
// If equally direct, choose the best metric
- if( best->SubnetBits == rt->SubnetBits && best->Metric < rt->Metric ) continue;
+ if( best->SubnetBits == rt->SubnetBits && best->Metric < rt->Metric ) {
+ LOG("Skipped - higher metric (%i > %i)", rt->Metric, best->Metric);
+ continue;
+ }
}
best = rt;
}
+ LEAVE('p', best);
return best;
}
{
int fd;
int type;
- char path[sizeof(IPSTACK_ROOT)+7+FILENAME_MAX+1] = IPSTACK_ROOT"/route/";
+ char path[sizeof(IPSTACK_ROOT)+8+FILENAME_MAX+1] = IPSTACK_ROOT"/routes/";
strcat(path, Name);
int DoAutoConfig(const char *Device)
{
int tmp, fd;
- char path[sizeof(IPSTACK_ROOT)+5+1]; // ip000
+ char path[sizeof(IPSTACK_ROOT)+1+4+1]; // /0000
uint8_t addr[4] = {10,0,2,55};
uint8_t gw[4] = {10,0,2,1};
int subnet = 8;
// Set Subnet
ioctl(fd, ioctl(fd, 3, "getset_subnet"), &subnet);
- // Set Gateway
+ // Set routes
{
uint8_t net[4] = {0,0,0,0};
- AddRoute(path + sizeof(IPSTACK_ROOT) + 1, net, 0, gw);
+ AddRoute(path + sizeof(IPSTACK_ROOT), addr, 8, net); // This interface
+ AddRoute(path + sizeof(IPSTACK_ROOT), net, 0, gw); // Gateway
}
close(fd);
return -1;\r
}\r
\r
+ printf("Connection opened\n");\r
+ \r
writef(srv.FD, "USER %s %s %s : %s\n", gsUsername, gsHostname, gsRemoteAddress, gsRealName);\r
writef(srv.FD, "NICK %s", gsNickname);\r
\r
return -1;\r
}\r
\r
+ printf("iface = '%s'\n", iface);\r
+ \r
// Open client socket\r
// TODO: Move this out to libnet?\r
{\r
free(iface);\r
\r
if( fd == -1 ) {\r
+ fprintf(stderr, "Unable to open TCP Client for reading\n");\r
return -1;\r
}\r
-\r
+ \r
// Set remote port and address\r
+ printf("Setting port and remote address");\r
ioctl(fd, 5, &PortNumber);\r
ioctl(fd, 6, addrBuffer);\r
\r
// Connect\r
+ printf("Initiating connection");\r
if( ioctl(fd, 7, NULL) == 0 ) {\r
// Shouldn't happen :(\r
+ fprintf(stderr, "Unable to start connection\n");\r
return -1;\r
}\r
\r