diff options
author | Maciej <sppmacd@pm.me> | 2022-05-28 18:46:55 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-05-28 23:33:46 +0100 |
commit | 1ffba0b8b4aa26c28288f9191782523c7e9b7017 (patch) | |
tree | 6c6f1c2ee205115df565d3b89d9ef7dae1bc3085 /Userland/Services/NetworkServer | |
parent | d90131bce1874f4d1453b3b2a402b725b4e59130 (diff) | |
download | serenity-1ffba0b8b4aa26c28288f9191782523c7e9b7017.zip |
NetworkServer: Support setting default gateway
This commit adds an IPv4Gateway to Network.ini. If that option is set to
value other than 0.0.0.0, the NetworkServer adds a default route (e.g.
with address 0.0.0.0/0) with the specified destination.
Diffstat (limited to 'Userland/Services/NetworkServer')
-rw-r--r-- | Userland/Services/NetworkServer/main.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/Userland/Services/NetworkServer/main.cpp b/Userland/Services/NetworkServer/main.cpp index e476155011..d5e194f5f5 100644 --- a/Userland/Services/NetworkServer/main.cpp +++ b/Userland/Services/NetworkServer/main.cpp @@ -22,6 +22,7 @@ ErrorOr<int> serenity_main(Main::Arguments) TRY(Core::System::unveil("/bin/DHCPClient", "x")); TRY(Core::System::unveil("/etc/Network.ini", "r")); TRY(Core::System::unveil("/bin/ifconfig", "x")); + TRY(Core::System::unveil("/bin/route", "x")); TRY(Core::System::unveil(nullptr, nullptr)); auto config_file = TRY(Core::ConfigFile::open_for_system("Network")); @@ -40,6 +41,7 @@ ErrorOr<int> serenity_main(Main::Arguments) bool dhcp_enabled = false; String ipv4_address = "0.0.0.0"; String ipv4_netmask = "0.0.0.0"; + String ipv4_gateway = "0.0.0.0"; }; Vector<String> interfaces_with_dhcp_enabled; @@ -59,6 +61,7 @@ ErrorOr<int> serenity_main(Main::Arguments) if (!config.dhcp_enabled) { config.ipv4_address = config_file->read_entry(ifname, "IPv4Address", "0.0.0.0"); config.ipv4_netmask = config_file->read_entry(ifname, "IPv4Netmask", "0.0.0.0"); + config.ipv4_gateway = config_file->read_entry(ifname, "IPv4Gateway", "0.0.0.0"); } } if (config.enabled) { @@ -69,6 +72,8 @@ ErrorOr<int> serenity_main(Main::Arguments) // FIXME: Do this asynchronously dbgln("Setting up interface {} statically ({}/{})", ifname, config.ipv4_address, config.ipv4_netmask); MUST(Core::command("ifconfig", { "-a", ifname.characters(), "-i", config.ipv4_address.characters(), "-m", config.ipv4_netmask.characters() }, {})); + if (config.ipv4_gateway != "0.0.0.0") + MUST(Core::command("route", { "add", "-n", "0.0.0.0", "-m", "0.0.0.0", "-g", config.ipv4_gateway, "-i", ifname }, {})); } } }); |