network_config: Leverage a default network file
This will alleviate the need for pre-generating configuration files.
Required for fixing reading of DHCP attributes, as interfaces added by
newer firmware versions will sometimes override old DHCP settings as
they are always read from the first file.
Tested: Ran on a real BMC, cleared the flash. Verified interfaces came
up with default settings and added configurations to the interfaces.
Change-Id: I5fe111be86b59b833d789abdaadee4a43f2e24d3
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/60-phosphor-networkd-default.network.in b/60-phosphor-networkd-default.network.in
new file mode 100644
index 0000000..4230aeb
--- /dev/null
+++ b/60-phosphor-networkd-default.network.in
@@ -0,0 +1,16 @@
+[Match]
+Name=*
+Name=!lo
+[Network]
+DHCP=true
+LinkLocalAddressing=@LINK_LOCAL_AUTOCONFIGURATION@
+IPv6AcceptRA=@ENABLE_IPV6_ACCEPT_RA@
+[DHCP]
+ClientIdentifier=mac
+UseDNS=true
+UseDomains=true
+UseNTP=true
+UseHostname=true
+SendHostname=true
+[IPv6AcceptRA]
+DHCPv6Client=true
diff --git a/meson.build b/meson.build
index d0ac5ce..7b130ec 100644
--- a/meson.build
+++ b/meson.build
@@ -70,6 +70,14 @@
subdir('src')
configure_file(
+ input: '60-phosphor-networkd-default.network.in',
+ output: '60-phosphor-networkd-default.network',
+ configuration: conf_data,
+ install: true,
+ install_dir: dependency('systemd').get_variable(
+ pkgconfig: 'systemdutildir') / 'network')
+
+configure_file(
input: 'xyz.openbmc_project.Network.service.in',
output: 'xyz.openbmc_project.Network.service',
configuration: {
diff --git a/src/meson.build b/src/meson.build
index 2e07084..926d6bd 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -51,7 +51,6 @@
'neighbor.cpp',
'ipaddress.cpp',
'netlink.cpp',
- 'network_config.cpp',
'network_manager.cpp',
'system_configuration.cpp',
'system_queries.cpp',
diff --git a/src/network_config.cpp b/src/network_config.cpp
deleted file mode 100644
index 249be58..0000000
--- a/src/network_config.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-#include "config.h"
-
-#include "network_config.hpp"
-
-#include "config_parser.hpp"
-
-namespace phosphor
-{
-namespace network
-{
-
-namespace bmc
-{
-void writeDHCPDefault(const std::filesystem::path& filename,
- std::string_view interface)
-{
- config::Parser config;
- config.map["Match"].emplace_back()["Name"].emplace_back(interface);
- {
- auto& network = config.map["Network"].emplace_back();
- network["DHCP"].emplace_back("true");
- auto& lla = network["LinkLocalAddressing"];
-#ifdef LINK_LOCAL_AUTOCONFIGURATION
- lla.emplace_back("true");
-#else
- lla.emplace_back("false");
-#endif
- auto& ra = network["IPv6AcceptRA"];
-#ifdef ENABLE_IPV6_ACCEPT_RA
- ra.emplace_back("true");
-#else
- ra.emplace_back("false");
-#endif
- }
- {
- auto& dhcp = config.map["DHCP"].emplace_back();
- dhcp["ClientIdentifier"].emplace_back("mac");
- dhcp["UseDNS"].emplace_back("true");
- dhcp["UseDomains"].emplace_back("true");
- dhcp["UseNTP"].emplace_back("true");
- dhcp["UseHostname"].emplace_back("true");
- dhcp["SendHostname"].emplace_back("true");
- }
- config.map["IPv6AcceptRA"].emplace_back()["DHCPv6Client"].emplace_back(
- "true");
- config.writeFile(filename);
-}
-} // namespace bmc
-
-} // namespace network
-} // namespace phosphor
diff --git a/src/network_config.hpp b/src/network_config.hpp
deleted file mode 100644
index a5c7300..0000000
--- a/src/network_config.hpp
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <filesystem>
-#include <string_view>
-
-namespace phosphor
-{
-namespace network
-{
-
-namespace bmc
-{
-void writeDHCPDefault(const std::filesystem::path& filename,
- std::string_view interface);
-}
-
-} // namespace network
-} // namespace phosphor
diff --git a/src/network_manager.cpp b/src/network_manager.cpp
index 6763b4b..0032525 100644
--- a/src/network_manager.cpp
+++ b/src/network_manager.cpp
@@ -3,7 +3,6 @@
#include "network_manager.hpp"
#include "ipaddress.hpp"
-#include "network_config.hpp"
#include "system_queries.hpp"
#include "types.hpp"
@@ -43,43 +42,6 @@
setConfDir(confDir);
}
-bool Manager::createDefaultNetworkFiles()
-{
- auto isCreated = false;
- try
- {
- for (const auto& interface : system::getInterfaces())
- {
- // if the interface has '.' in the name, it means that this is a
- // VLAN - don't create the network file.
- if (interface.name->find(".") != std::string::npos)
- {
- continue;
- }
-
- fs::path filePath =
- config::pathForIntfConf(confDir, *interface.name);
-
- // create the interface specific network file
- // if not existing.
- if (!fs::is_regular_file(filePath))
- {
- bmc::writeDHCPDefault(filePath, *interface.name);
- log<level::INFO>(
- "Created the default network file.",
- entry("INTERFACE=%s", interface.name->c_str()));
- isCreated = true;
- }
- }
- }
- catch (const std::exception& e)
- {
- log<level::ERR>("Unable to create the default network file");
- }
-
- return isCreated;
-}
-
void Manager::setConfDir(const fs::path& dir)
{
confDir = dir;
@@ -195,7 +157,6 @@
fs::remove(file.path());
}
}
- createDefaultNetworkFiles();
log<level::INFO>("Network Factory Reset queued.");
}
diff --git a/src/network_manager.hpp b/src/network_manager.hpp
index 18bb7d5..09c3d55 100644
--- a/src/network_manager.hpp
+++ b/src/network_manager.hpp
@@ -102,11 +102,6 @@
return dhcpConf;
}
- /** @brief create the default network files for each interface
- * @return true if network file created else false
- */
- bool createDefaultNetworkFiles();
-
/** @brief This function gets the MAC address from the VPD and
* sets it on the corresponding ethernet interface during first
* Boot, once it sets the MAC from VPD, it creates a file named
diff --git a/src/network_manager_main.cpp b/src/network_manager_main.cpp
index c28b02e..876ed0a 100644
--- a/src/network_manager_main.cpp
+++ b/src/network_manager_main.cpp
@@ -288,13 +288,6 @@
manager = std::make_unique<Manager>(bus, DEFAULT_OBJPATH, NETWORK_CONF_DIR);
- // create the default network files if the network file
- // is not there for any interface.
- if (manager->createDefaultNetworkFiles())
- {
- manager->reloadConfigs();
- }
-
// RTNETLINK event handler
rtnetlink::Server svr(event);