mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-28 18:00:10 +01:00
distro: remove nm_backend_enable_loopback()
We don't need to use distribution-specific network scripts to just bring up the loopback interface. I'm not aware of any init dependency problems but even if there are some, it is more practical to solve them in the respective configuration files. This function also tried to add 127.0.0.1 to the list of addresses but not ::1. We don't need to set the interfaces up as this is done by the kernel.
This commit is contained in:
parent
3ada5b5a6a
commit
3efc2c4b9d
17 changed files with 13 additions and 167 deletions
|
|
@ -37,8 +37,3 @@
|
|||
|
||||
#include "NetworkManagerGeneric.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
|
||||
void nm_backend_enable_loopback (void)
|
||||
{
|
||||
nm_generic_enable_loopback ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,12 +31,3 @@
|
|||
#include "NetworkManagerGeneric.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "nm-logging.h"
|
||||
|
||||
void nm_backend_enable_loopback (void)
|
||||
{
|
||||
/* ifupdown isn't always installed (bgo #625427) */
|
||||
if (g_file_test ("/sbin/ifup", G_FILE_TEST_EXISTS))
|
||||
nm_spawn_process ("/sbin/ifup lo");
|
||||
else
|
||||
nm_generic_enable_loopback ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,8 +30,3 @@
|
|||
#include "NetworkManagerGeneric.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "nm-logging.h"
|
||||
|
||||
void nm_backend_enable_loopback (void)
|
||||
{
|
||||
nm_generic_enable_loopback ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,8 +25,3 @@
|
|||
|
||||
/* Provided by the frugalwareutils package on Frugalware */
|
||||
#include <libfwnetconfig.h>
|
||||
|
||||
void nm_backend_enable_loopback (void)
|
||||
{
|
||||
fwnet_loup ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,68 +44,3 @@
|
|||
#include <netlink/route/addr.h>
|
||||
#include <netlink/netlink.h>
|
||||
|
||||
/*
|
||||
* nm_generic_enable_loopback
|
||||
*
|
||||
* Bring up the loopback interface
|
||||
*
|
||||
*/
|
||||
void nm_generic_enable_loopback (void)
|
||||
{
|
||||
struct nl_sock * nlh = NULL;
|
||||
struct rtnl_addr * addr = NULL;
|
||||
struct nl_addr * nl_addr = NULL;
|
||||
guint32 binaddr = 0;
|
||||
int iface_idx = -1;
|
||||
int err;
|
||||
|
||||
nlh = nm_netlink_get_default_handle ();
|
||||
if (!nlh)
|
||||
return;
|
||||
|
||||
iface_idx = nm_netlink_iface_to_index ("lo");
|
||||
if (iface_idx < 0)
|
||||
return;
|
||||
|
||||
nm_system_iface_set_up (iface_idx, TRUE, NULL);
|
||||
|
||||
addr = rtnl_addr_alloc ();
|
||||
if (!addr)
|
||||
return;
|
||||
|
||||
binaddr = htonl (0x7f000001); /* 127.0.0.1 */
|
||||
nl_addr = nl_addr_build (AF_INET, &binaddr, sizeof(binaddr));
|
||||
if (!nl_addr)
|
||||
goto out;
|
||||
rtnl_addr_set_local (addr, nl_addr);
|
||||
nl_addr_put (nl_addr);
|
||||
|
||||
binaddr = htonl (0x7fffffff); /* 127.255.255.255 */
|
||||
nl_addr = nl_addr_build (AF_INET, &binaddr, sizeof(binaddr));
|
||||
if (!nl_addr)
|
||||
goto out;
|
||||
rtnl_addr_set_broadcast (addr, nl_addr);
|
||||
nl_addr_put (nl_addr);
|
||||
|
||||
rtnl_addr_set_prefixlen (addr, 8);
|
||||
rtnl_addr_set_ifindex (addr, iface_idx);
|
||||
rtnl_addr_set_scope (addr, RT_SCOPE_HOST);
|
||||
rtnl_addr_set_label (addr, "lo");
|
||||
|
||||
err = rtnl_addr_add (nlh, addr, 0);
|
||||
if (err && (err != -NLE_EXIST)) {
|
||||
nm_log_warn (LOGD_CORE, "error setting loopback address: (%d) %s",
|
||||
err, nl_geterror (err));
|
||||
}
|
||||
out:
|
||||
if (addr)
|
||||
rtnl_addr_put (addr);
|
||||
}
|
||||
|
||||
#ifdef TARGET_GENERIC
|
||||
void nm_backend_enable_loopback (void)
|
||||
{
|
||||
nm_generic_enable_loopback ();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,4 @@
|
|||
|
||||
#include "nm-backend.h"
|
||||
|
||||
void nm_generic_enable_loopback (void);
|
||||
|
||||
#endif /* NM_GENERIC_H */
|
||||
|
|
|
|||
|
|
@ -32,34 +32,3 @@
|
|||
#include "NetworkManagerGeneric.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "nm-logging.h"
|
||||
|
||||
static void openrc_start_lo_if_necessary()
|
||||
{
|
||||
/* No need to run net.lo if it is already running */
|
||||
if (nm_spawn_process ("/etc/init.d/net.lo status") != 0)
|
||||
nm_spawn_process ("/etc/init.d/net.lo start");
|
||||
}
|
||||
|
||||
void nm_backend_enable_loopback (void)
|
||||
{
|
||||
gchar *comm;
|
||||
|
||||
/* If anything goes wrong trying to open /proc/1/comm, we will assume OpenRC */
|
||||
if (!g_file_get_contents ("/proc/1/comm", &comm, NULL, NULL)) {
|
||||
nm_log_info (LOGD_CORE, "NetworkManager is running with OpenRC...");
|
||||
openrc_start_lo_if_necessary ();
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_strstr_len (comm, -1, "systemd")) {
|
||||
/* We use the generic loopback enabler if using systemd. */
|
||||
nm_log_info (LOGD_CORE, "NetworkManager is running with systemd...");
|
||||
nm_generic_enable_loopback ();
|
||||
} else {
|
||||
/* OpenRC otherwise. */
|
||||
nm_log_info (LOGD_CORE, "NetworkManager is running with OpenRC...");
|
||||
openrc_start_lo_if_necessary();
|
||||
}
|
||||
|
||||
g_free (comm);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,8 +32,3 @@
|
|||
|
||||
#include "NetworkManagerGeneric.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
|
||||
void nm_backend_enable_loopback (void)
|
||||
{
|
||||
nm_generic_enable_loopback ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,8 +31,3 @@
|
|||
#include "NetworkManagerGeneric.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "nm-logging.h"
|
||||
|
||||
void nm_backend_enable_loopback (void)
|
||||
{
|
||||
nm_generic_enable_loopback ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,8 +27,3 @@
|
|||
|
||||
#include "NetworkManagerGeneric.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
|
||||
void nm_backend_enable_loopback (void)
|
||||
{
|
||||
nm_generic_enable_loopback ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,8 +29,3 @@
|
|||
#include "NetworkManagerGeneric.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "nm-logging.h"
|
||||
|
||||
void nm_backend_enable_loopback (void)
|
||||
{
|
||||
nm_generic_enable_loopback ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,8 +25,3 @@
|
|||
#endif
|
||||
|
||||
#include "NetworkManagerGeneric.h"
|
||||
|
||||
void nm_backend_enable_loopback (void)
|
||||
{
|
||||
nm_generic_enable_loopback ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,8 +25,3 @@
|
|||
|
||||
#include "NetworkManagerGeneric.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
|
||||
void nm_backend_enable_loopback (void)
|
||||
{
|
||||
nm_generic_enable_loopback ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,8 +25,3 @@
|
|||
#endif
|
||||
|
||||
#include "NetworkManagerGeneric.h"
|
||||
|
||||
void nm_backend_enable_loopback (void)
|
||||
{
|
||||
nm_generic_enable_loopback ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,8 +30,3 @@
|
|||
#include "NetworkManagerGeneric.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "nm-logging.h"
|
||||
|
||||
void nm_backend_enable_loopback (void)
|
||||
{
|
||||
nm_generic_enable_loopback ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,4 @@
|
|||
|
||||
/* Random disto-specific stuff */
|
||||
|
||||
void nm_backend_enable_loopback (void);
|
||||
|
||||
#endif /* NM_BACKEND_H */
|
||||
|
|
|
|||
16
src/main.c
16
src/main.c
|
|
@ -42,7 +42,6 @@
|
|||
#include "NetworkManagerUtils.h"
|
||||
#include "nm-manager.h"
|
||||
#include "nm-policy.h"
|
||||
#include "backends/nm-backend.h"
|
||||
#include "nm-dns-manager.h"
|
||||
#include "nm-dbus-manager.h"
|
||||
#include "nm-supplicant-manager.h"
|
||||
|
|
@ -55,6 +54,7 @@
|
|||
#include "nm-policy-hosts.h"
|
||||
#include "nm-config.h"
|
||||
#include "nm-posix-signals.h"
|
||||
#include "nm-system.h"
|
||||
|
||||
#if !defined(NM_DIST_VERSION)
|
||||
# define NM_DIST_VERSION VERSION
|
||||
|
|
@ -640,8 +640,18 @@ main (int argc, char *argv[])
|
|||
|
||||
nm_manager_start (manager);
|
||||
|
||||
/* Bring up the loopback interface. */
|
||||
nm_backend_enable_loopback ();
|
||||
/* Make sure the loopback interface is up. If interface is down, we bring
|
||||
* it up and kernel will assign it link-local IPv4 and IPv6 addresses. If
|
||||
* it was already up, we assume is in clean state.
|
||||
*
|
||||
* TODO: it might be desirable to check the list of addresses and compare
|
||||
* it with a list of expected addresses (one of the protocol families
|
||||
* could be disabled). The 'lo' interface is sometimes used for assigning
|
||||
* global addresses so their availability doesn't depend on the state of
|
||||
* physical interfaces.
|
||||
*/
|
||||
nm_log_dbg (LOGD_CORE, "setting up local loopback");
|
||||
nm_system_iface_set_up (nm_netlink_iface_to_index ("lo"), TRUE, NULL);
|
||||
|
||||
success = TRUE;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue