Multiple IPStack Related changes (and other bugfixes)
[tpg/acess2.git] / Modules / IPStack / routing.c
index 33b756c..381ddf7 100644 (file)
 // === IMPORTS ===
 tVFS_Node      *IPStack_Root_FindDir(tVFS_Node *Node, const char *Filename);
 
-// === TYPES ===
-typedef struct sRoute {
-       struct sRoute   *Next;
-       
-       tVFS_Node       Node;
-       
-       tInterface      *Interface;     // Interface for this route
-        int    AddressType;    // 0: Invalid, 4: IPv4, 6: IPv4
-       void    *Network;       // Network - Pointer to tIPv4/tIPv6/... at end of structure
-        int    SubnetBits;     // Number of bits in \a Network that are valid
-       void    *NextHop;       // Next Hop address - Pointer to tIPv4/tIPv6/... at end of structure
-        int    Metric; // Route priority
-}      tRoute;
-
 // === PROTOTYPES ===
 // - Routes directory
 char   *IPStack_RouteDir_ReadDir(tVFS_Node *Node, int Pos);
 tVFS_Node      *IPStack_RouteDir_FindDir(tVFS_Node *Node, const char *Name);
  int   IPStack_RouteDir_IOCtl(tVFS_Node *Node, int ID, void *Data);
  int   IPStack_Route_Create(const char *InterfaceName);
-tRoute *IPStack_FindRoute(int AddressType, void *Address);
+tRoute *IPStack_FindRoute(int AddressType, tInterface *Interface, void *Address);
 // - Individual Routes
  int   IPStack_Route_IOCtl(tVFS_Node *Node, int ID, void *Data);
 
@@ -146,7 +132,7 @@ int IPStack_RouteDir_IOCtl(tVFS_Node *Node, int ID, void *Data)
                        if( !CheckMem(Data, sizeof(int) + IPStack_GetAddressSize(data->Type)) )
                                return -1;
                        
-                       rt = IPStack_FindRoute(data->Type, data->Addr);
+                       rt = IPStack_FindRoute(data->Type, NULL, data->Addr);
                        
                        if( !rt )
                                return 0;
@@ -214,15 +200,21 @@ int IPStack_Route_Create(const char *InterfaceName)
 
 /**
  */
-tRoute *IPStack_FindRoute(int AddressType, void *Address)
+tRoute *IPStack_FindRoute(int AddressType, tInterface *Interface, void *Address)
 {
        tRoute  *rt;
        tRoute  *best = NULL;
        
+       if( Interface && AddressType != Interface->Type )       return NULL;
+       
        for( rt = gIP_Routes; rt; rt = rt->Next )
        {
+               // Check interface
+               if( Interface && rt->Interface != Interface )   continue;
+               // Check address type
                if( rt->AddressType != AddressType )    continue;
                
+               // Check if the address matches
                if( !IPStack_CompareAddress(AddressType, rt->Network, Address, rt->SubnetBits) )
                        continue;
                
@@ -244,12 +236,13 @@ tRoute    *IPStack_FindRoute(int AddressType, void *Address)
  */
 static const char *casIOCtls_Route[] = {
        DRV_IOCTLNAMES,
-       "get_network",  // Get network - (void *Data)
-       "set_network",  // Set network - (void *Data)
-       "get_nexthop",  // Get next hop - (void *Data)
-       "set_nexthop",  // Set next hop - (void *Data)
-       "getset_subnetbits",    // Get/Set subnet bits - (int *Bits)
-       "getset_metric",        // Get/Set metric - (int *Metric)
+       "get_network",  // Get network - (void *Data), returns boolean success
+       "set_network",  // Set network - (void *Data), returns boolean success
+       "get_nexthop",  // Get next hop - (void *Data), returns boolean success
+       "set_nexthop",  // Set next hop - (void *Data), returns boolean success
+       "getset_subnetbits",    // Get/Set subnet bits - (int *Bits), returns current value
+       "getset_metric",        // Get/Set metric - (int *Metric), returns current value
+       "get_interface",        // Get interface name - (char *Name), returns name length, NULL OK
        NULL
        };
 
@@ -325,6 +318,15 @@ int IPStack_Route_IOCtl(tVFS_Node *Node, int ID, void *Data)
                }
                return rt->Metric;
        
+       // Get interface name
+       case 10:
+               if( Data ) {
+                       if( !CheckMem(Data, strlen(rt->Interface->Name) + 1) )
+                               return -1;
+                       strcpy(Data, rt->Interface->Name);
+               }
+               return strlen(rt->Interface->Name);
+       
        default:
                return 0;
        }

UCC git Repository :: git.ucc.asn.au