mirror of
https://github.com/RGBCube/serenity
synced 2025-05-23 20:45:07 +00:00

Previously the system had no concept of assigning different routes for different destination addresses as the default gateway IP address was directly assigned to a network adapter. This default gateway was statically assigned and any update would remove the previously existing route. This patch is a beginning step towards implementing #180. It implements a simple global routing table that is referenced during the routing process. With this implementation it is now possible for a user or service (i.e. DHCP) to dynamically add routes to the table. The routing table will select the most specific route when possible. It will select any direct match between the destination and routing entry addresses. If the destination address overlaps between multiple entries, the Kernel will use the longest prefix match, or the longest number of matching bits between the destination address and the routing address. In the event that there is no entries found for a specific destination address, this implementation supports entries for a default route to be set for any specified interface. This is a small first step towards enhancing the system's routing capabilities. Future enhancements would include referencing a configuration file at boot to load pre-defined static routes.
30 lines
700 B
C
30 lines
700 B
C
/*
|
|
* Copyright (c) 2020, Marios Prokopakis <mariosprokopakis@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <Kernel/API/POSIX/sys/socket.h>
|
|
#include <Kernel/API/POSIX/sys/types.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
struct rtentry {
|
|
struct sockaddr rt_dst; /* the target address */
|
|
struct sockaddr rt_gateway; /* the gateway address */
|
|
struct sockaddr rt_genmask; /* the target network mask */
|
|
unsigned short int rt_flags;
|
|
char* rt_dev;
|
|
/* FIXME: complete the struct */
|
|
};
|
|
|
|
#define RTF_UP 0x1 /* do not delete the route */
|
|
#define RTF_GATEWAY 0x2 /* the route is a gateway and not an end host */
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|