// === 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_MkNod(tVFS_Node *Node, const char *Name, Uint Flags);
- int IPStack_RouteDir_Relink(tVFS_Node *Node, const char *OldName, const char *NewName);
+ int IPStack_RouteDir_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]);
+tVFS_Node *IPStack_RouteDir_FindDir(tVFS_Node *Node, const char *Name, Uint Flags);
+tVFS_Node *IPStack_RouteDir_MkNod(tVFS_Node *Node, const char *Name, Uint Flags);
+ int IPStack_RouteDir_Unlink(tVFS_Node *Node, const char *OldName);
tRoute *_Route_FindExactRoute(int Type, void *Network, int Subnet, int Metric);
int _Route_ParseRouteName(const char *Name, void *Addr, int *SubnetBits, int *Metric);
int IPStack_RouteDir_IOCtl(tVFS_Node *Node, int ID, void *Data);
// - Route Management
tRoute *IPStack_Route_Create(int AddrType, void *Network, int SubnetBits, int Metric);
tRoute *IPStack_AddRoute(const char *Interface, void *Network, int SubnetBits, void *NextHop, int Metric);
-tRoute *_Route_FindInterfaceRoute(int AddressType, void *Address);
-tRoute *IPStack_FindRoute(int AddressType, tInterface *Interface, void *Address);
+tRoute *_Route_FindInterfaceRoute(int AddressType, const void *Address);
+tRoute *IPStack_FindRoute(int AddressType, tInterface *Interface, const void *Address);
// - Individual Routes
int IPStack_Route_IOCtl(tVFS_Node *Node, int ID, void *Data);
.ReadDir = IPStack_RouteDir_ReadDir,
.FindDir = IPStack_RouteDir_FindDir,
.MkNod = IPStack_RouteDir_MkNod,
- .Relink = IPStack_RouteDir_Relink,
+ .Unlink = IPStack_RouteDir_Unlink,
.IOCtl = IPStack_RouteDir_IOCtl
};
tVFS_Node gIP_RouteNode = {
/**
* \brief ReadDir for the /Devices/ip/routes/ directory
*/
-char *IPStack_RouteDir_ReadDir(tVFS_Node *Node, int Pos)
+int IPStack_RouteDir_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX])
{
tRoute *rt;
for(rt = gIP_Routes; rt && Pos --; rt = rt->Next);
- if( !rt ) return NULL;
+ if( !rt ) return -EINVAL;
{
int addrlen = IPStack_GetAddressSize(rt->AddressType);
- int len = sprintf(NULL, "%i::%i:%i", rt->AddressType, rt->SubnetBits, rt->Metric) + addrlen*2;
- char buf[len+1];
int ofs;
- ofs = sprintf(buf, "%i:", rt->AddressType);
- ofs += Hex(buf+ofs, addrlen, rt->Network);
- sprintf(buf+ofs, ":%i:%i", rt->SubnetBits, rt->Metric);
- return strdup(buf);
+ ofs = sprintf(Dest, "%i:", rt->AddressType);
+ ofs += Hex(Dest+ofs, addrlen, rt->Network);
+ sprintf(Dest+ofs, ":%i:%i", rt->SubnetBits, rt->Metric);
+ return 0;
}
}
/**
* \brief FindDir for the /Devices/ip/routes/ directory
*/
-tVFS_Node *IPStack_RouteDir_FindDir(tVFS_Node *Node, const char *Name)
+tVFS_Node *IPStack_RouteDir_FindDir(tVFS_Node *Node, const char *Name, Uint Flags)
{
// Interpret the name as <type>:<addr>, returning the interface for
// needed to access that address.
{
LOG("Why does this route not have a node? trying to find an iface for the next hop");
- rt = _Route_FindInterfaceRoute(type, rt->NextHop);
- if(!rt) {
+ void *nextrt = _Route_FindInterfaceRoute(type, rt->NextHop);
+ if(!nextrt) {
Log_Notice("Cannot find route to next hop '%s'",
IPStack_PrintAddress(type, rt->NextHop));
return NULL;
}
+ rt = nextrt;
}
if( !rt->Interface ) {
Log_Notice("Routes", "No interface for route %p, what the?", rt);
/**
* \brief Create a new route node
*/
-int IPStack_RouteDir_MkNod(tVFS_Node *Node, const char *Name, Uint Flags)
+tVFS_Node *IPStack_RouteDir_MkNod(tVFS_Node *Node, const char *Name, Uint Flags)
{
- if( Flags ) return -EINVAL;
- if( Threads_GetUID() != 0 ) return -EACCES;
+ if( Flags ) {
+ errno = EINVAL;
+ return NULL;
+ }
+ if( Threads_GetUID() != 0 ) {
+ errno = EACCES;
+ return NULL;
+ }
int type = _Route_ParseRouteName(Name, NULL, NULL, NULL);
- if( type <= 0 ) return -EINVAL;
+ if( type <= 0 ) {
+ errno = EINVAL;
+ return NULL;
+ }
int size = IPStack_GetAddressSize(type);
Uint8 addrdata[size];
_Route_ParseRouteName(Name, addrdata, &subnet, &metric);
// Check for duplicates
- if( _Route_FindExactRoute(type, addrdata, subnet, metric) )
- return -EEXIST;
+ if( _Route_FindExactRoute(type, addrdata, subnet, metric) ) {
+ errno = EEXIST;
+ return NULL;
+ }
- IPStack_Route_Create(type, addrdata, subnet, metric);
+ tRoute *rt = IPStack_Route_Create(type, addrdata, subnet, metric);
+ rt->Node.ReferenceCount ++;
- return 0;
+ return &rt->Node;
}
/**
* \brief Rename / Delete a route
*/
-int IPStack_RouteDir_Relink(tVFS_Node *Node, const char *OldName, const char *NewName)
+int IPStack_RouteDir_Unlink(tVFS_Node *Node, const char *OldName)
{
tRoute *rt;
rt = _Route_FindExactRoute(type, addr, subnet, metric);
}
- if( NewName == NULL )
- {
- // Delete the route
- tRoute *prev = NULL;
- for(tRoute *r = gIP_Routes; r && r != rt; prev = r, r = r->Next);
-
- if(prev)
- prev->Next = rt->Next;
- else
- gIP_Routes = rt->Next;
- free(rt);
- }
- else
- {
- // Change the route
- int type = _Route_ParseRouteName(NewName, NULL, NULL, NULL);
- if(type <= 0) return -EINVAL;
- Uint8 addr[IPStack_GetAddressSize(type)];
- int subnet, metric;
- _Route_ParseRouteName(NewName, addr, &subnet, &metric);
+ // Delete the route
+ tRoute *prev = NULL;
+ for(tRoute *r = gIP_Routes; r && r != rt; prev = r, r = r->Next);
- return -ENOTIMPL;
- }
+ if(prev)
+ prev->Next = rt->Next;
+ else
+ gIP_Routes = rt->Next;
+ free(rt);
return 0;
}
/**
* \brief Locates what interface should be used to get directly to an address
*/
-tRoute *_Route_FindInterfaceRoute(int AddressType, void *Address)
+tRoute *_Route_FindInterfaceRoute(int AddressType, const void *Address)
{
tRoute *best = NULL, *rt;
int addrSize = IPStack_GetAddressSize(AddressType);
/**
*/
-tRoute *IPStack_FindRoute(int AddressType, tInterface *Interface, void *Address)
+tRoute *IPStack_FindRoute(int AddressType, tInterface *Interface, const void *Address)
{
tRoute *rt;
tRoute *best = NULL;