From 714dfdc29a10ec35361bdd4320dcba9b0a11bba4 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Tue, 19 Aug 2025 10:59:02 +0200 Subject: [PATCH] [ROUTE] Add /f option to the add and delete command --- base/applications/network/route/lang/en-US.rc | 8 ++- base/applications/network/route/route.c | 57 ++++++++++++++++++- 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/base/applications/network/route/lang/en-US.rc b/base/applications/network/route/lang/en-US.rc index 9fe2357fe13..2f4bd26af52 100644 --- a/base/applications/network/route/lang/en-US.rc +++ b/base/applications/network/route/lang/en-US.rc @@ -12,8 +12,12 @@ BEGIN Manipulates the network routing tables.\n\n\ ROUTE [-f] [-p] command [destination]\n\ [MASK netmask] [gateway] [METRIC metric]\n\n\ - -f Not supported yet.\n\n\ - -p Not supported yet.\n\n\ + -f Cleans the routing table of all gateway entries prior to\n\ + executing the command. Can be used with the ADD and\n\ + DELETE command.\n\n\ + -p Makes a route persistent between boots of the system. By\n\ + default, routes are not persistent when the system is\n\ + restarted. Can be used with the ADD command.\n\n\ command One of the following options:\n\ PRINT Prints the routes.\n\ ADD Add a new route.\n\ diff --git a/base/applications/network/route/route.c b/base/applications/network/route/route.c index 2ba81a78e5b..59afe802d5e 100644 --- a/base/applications/network/route/route.c +++ b/base/applications/network/route/route.c @@ -29,7 +29,7 @@ #define IPBUF 17 #define IN_ADDR_OF(x) *((struct in_addr *)&(x)) -#define FLUSH_FLAG 0x1 +#define DELETE_FLAG 0x1 #define PERSISTENT_FLAG 0x2 static @@ -401,6 +401,51 @@ CreatePersistentIpForwardEntry( return Error; } +static +DWORD +DeleteCustomRoutes(VOID) +{ + WCHAR Destination[IPBUF], Netmask[IPBUF]; + PMIB_IPFORWARDTABLE IpForwardTable = NULL; + ULONG Size = 0; + DWORD Error = ERROR_SUCCESS; + ULONG i; + + if ((GetIpForwardTable(NULL, &Size, TRUE)) == ERROR_INSUFFICIENT_BUFFER) + { + if (!(IpForwardTable = malloc(Size))) + { + Error = ERROR_NOT_ENOUGH_MEMORY; + goto done; + } + } + + Error = GetIpForwardTable(IpForwardTable, &Size, TRUE); + if (Error != ERROR_SUCCESS) + goto done; + + for (i = 0; i < IpForwardTable->dwNumEntries; i++) + { + mbstowcs(Destination, inet_ntoa(IN_ADDR_OF(IpForwardTable->table[i].dwForwardDest)), IPBUF); + mbstowcs(Netmask, inet_ntoa(IN_ADDR_OF(IpForwardTable->table[i].dwForwardMask)), IPBUF); + + if ((wcscmp(Netmask, L"255.255.255.255") != 0) && + ((wcscmp(Destination, L"127.0.0.0") != 0) || (wcscmp(Netmask, L"255.0.0.0") != 0)) && + ((wcscmp(Destination, L"224.0.0.0") != 0) || (wcscmp(Netmask, L"240.0.0.0") != 0))) + { + Error = DeleteIpForwardEntry(&IpForwardTable->table[i]); + if (Error != ERROR_SUCCESS) + break; + } + } + +done: + if (IpForwardTable) + free(IpForwardTable); + + return Error; +} + static int AddRoute( @@ -414,7 +459,10 @@ AddRoute( if ((argc <= start) || !ConvertAddCmdLine(&RowToAdd, argc, argv, start)) return 1; - + + if (flags & DELETE_FLAG) + DeleteCustomRoutes(); + if (flags & PERSISTENT_FLAG) Error = CreatePersistentIpForwardEntry(&RowToAdd); else @@ -441,6 +489,9 @@ DeleteRoute( if ((argc < start + 2) || !ConvertAddCmdLine(&RowToDel, argc, argv, start)) return 1; + if (flags & DELETE_FLAG) + DeleteCustomRoutes(); + Error = DeleteIpForwardEntry(&RowToDel); if (Error != ERROR_SUCCESS) { @@ -467,7 +518,7 @@ wmain( { if (!_wcsicmp(&argv[i][1], L"f")) { - flags |= FLUSH_FLAG; + flags |= DELETE_FLAG; } else if (!_wcsicmp(&argv[i][1], L"p")) {