10 typedef struct sRoute {
14 int AddressType; // 0: Invalid, 4: IPv4, 6: IPv4
15 void *Network; // Pointer to tIPv4/tIPv6/... at end of structure
17 void *NextHop; // Pointer to tIPv4/tIPv6/... at end of structure
18 tInterface *Interface;
23 char *IPStack_RouteDir_ReadDir(tVFS_Node *Node, int Pos);
24 tVFS_Node *IPStack_RouteDir_FindDir(tVFS_Node *Node, const char *Name);
25 int IPStack_RouteDir_IOCtl(tVFS_Node *Node, int ID, void *Data);
26 int IPStack_Route_Create(const char *InterfaceName);
27 // - Individual Routes
28 Uint64 IPStack_Route_IOCtl(tVFS_Node *Node, int ID, void *Data);
32 int giIP_NextRouteId = 1;
34 tRoute *gIP_RoutesEnd;
35 tVFS_Node gIP_RouteNode = {
36 Flags: VFS_FFLAG_DIRECTORY,
39 ACLs: &gVFS_ACL_EveryoneRX,
40 ReadDir: IPStack_RouteDir_ReadDir,
41 FindDir: IPStack_RouteDir_FindDir,
42 IOCtl: IPStack_RouteDir_IOCtl
47 * \brief ReadDir for the /Devices/ip/routes/ directory
49 char *IPStack_RouteDir_ReadDir(tVFS_Node *Node, int Pos)
53 for(rt = gIP_Routes; rt && Pos --; rt = rt->Next);
60 int len = snprintf(NULL, 12, "%i", rt->Node.Inode);
62 sprintf(buf, "%i", rt->Node.Inode);
68 * \brief FindDir for the /Devices/ip/routes/ directory
70 tVFS_Node *IPStack_RouteDir_FindDir(tVFS_Node *Node, const char *Name)
74 // Zero is invalid, sorry :)
75 if( !num ) return NULL;
77 // The list is inherently sorted, so we can do a quick search
78 for(rt = gIP_Routes; rt && rt->Node.Inode < num; rt = rt->Next);
79 // Fast fail on larger number
80 if( rt->Node.Inode > num )
87 * \brief Names for interface IOCtl Calls
89 static const char *casIOCtls_RouteDir[] = {
91 "add_route" // Add a route - char *InterfaceName
95 int IPStack_RouteDir_IOCtl(tVFS_Node *Node, int ID, void *Data)
99 // --- Standard IOCtls (0-3) ---
101 LEAVE('i', DRV_TYPE_MISC);
102 return DRV_TYPE_MISC;
104 case DRV_IOCTL_IDENT:
105 tmp = ModUtil_SetIdent(Data, STR(IDENT));
109 case DRV_IOCTL_VERSION:
113 case DRV_IOCTL_LOOKUP:
114 tmp = ModUtil_LookupString( (char**)casIOCtls_RouteDir, (char*)Data );
119 if( !CheckString(Data) ) return -1;
120 return IPStack_Route_Create(Data);
126 * \brief Create a new route entry
128 int IPStack_Route_Create(const char *InterfaceName)
135 // Note: Oh man! This is such a hack
137 tVFS_Node *node = IPStack_Root_FindDir(NULL, InterfaceName);
138 if( !node ) return 0;
139 iface = node->ImplPtr;
142 // Get the size of the specified address type
143 size = IPStack_GetAddressSize(iface->AddressType);
149 rt = calloc(1, sizeof(tRoute) + size*2 );
154 rt->AddressType = iface->AddressType;
155 rt->Network = (void *)( (tVAddr)rt + sizeof(tRoute) );
157 rt->NextHop = (void *)( (tVAddr)rt + sizeof(tRoute) + size );
158 rt->Interface = iface;