2008-11-03 04:13:42 +00:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
2004-06-24 14:18:37 +00:00
|
|
|
/* NetworkManager -- Network link manager
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
2008-06-26 18:31:52 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2004-06-24 14:18:37 +00:00
|
|
|
*
|
2011-05-02 22:38:51 -05:00
|
|
|
* Copyright (C) 2004 - 2011 Red Hat, Inc.
|
2008-11-03 04:13:42 +00:00
|
|
|
* Copyright (C) 2005 - 2008 Novell, Inc.
|
2004-06-24 14:18:37 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <glib.h>
|
2009-07-29 12:12:41 -04:00
|
|
|
#include <errno.h>
|
|
|
|
|
#include <fcntl.h>
|
2004-06-24 14:18:37 +00:00
|
|
|
#include <stdio.h>
|
2005-03-26 03:42:05 +00:00
|
|
|
#include <string.h>
|
2009-07-29 12:12:41 -04:00
|
|
|
#include <unistd.h>
|
2010-05-26 16:28:51 -07:00
|
|
|
#include <ctype.h>
|
2011-07-22 12:50:54 -05:00
|
|
|
#include <stdlib.h>
|
2004-06-24 14:18:37 +00:00
|
|
|
|
|
|
|
|
#include "NetworkManagerUtils.h"
|
2005-03-14 Ray Strode <rstrode@redhat.com>
Fourth (probably working) cut at porting to
dbus 0.30 api and new hal. This cut adds
some new logging macros to make debugging
easier.
* dispatcher-daemon/NetworkManagerDispatcher.c:
* info-daemon/NetworkmanagerInfo.c:
* info-daemon/NetworkManagerInfoPassphraseDialog.c:
* info-daemon/NetworkManagerInfoVPN.c:
* src/NetworkManager.c:
* src/NetworkManagerAP.c:
* src/NetworkManagerAPList.c:
* src/NetworkManagerDHCP.c:
* src/NetworkManagerDbus.c:
* src/NetworkManagerDevice.c:
* src/NetworkManagerPolicy.c:
* src/NetworkManagerSystem.c:
* src/NetworkManagerUtils.c:
* src/NetworkManagerWireless.c:
* src/autoip.c:
* src/nm-dbus-nm.c:
* src/backends/NetworkManagerDebian.c:
* src/backends/NetworkManagerGentoo.c:
* src/backends/NetworkManagerRedHat.c:
* src/backends/NetworkManagerSlackware.c:
use new logging macros.
* dispatcher-daemon/NetworkManagerDispatcher.c:
(nmd_dbus_filter): s/dbus_free/g_free/
* info-daemon/Makefile.am: link in utils library.
* info-daemon/NetworkmanagerInfo.c: use new logging
macros.
(nmi_dbus_get_network): don't assume enumerations
are 32-bit.
(nmi_dbus_nmi_message_handler): don't free what
doesn't belong to us.
* libnm_glib/libnm_glib.c:
(libnm_glib_get_nm_status):
(libnm_glib_init): don't free what doesn't
belong to us.
(libnm_glib_dbus): strdup result, so it doesn't get
lost when message is unref'd.
* panel-applet/NMWirelessAppletDbus.c:
(nmwa_dbus_update_devices): s/dbus_free/g_free/
* src/NetworkManager.c:
(nm_monitor_wired_link_state): request initial status
dump of all cards when we start up, instead of relying
on /sys/.../carrier.
(nm_info_handler), (nm_set_up_log_handlers):
log handlers to specify what syslog priorites
the logging macros default to.
* src/NetworkManagerAPList.c:
(nm_ap_list_populate_from_nmi):
s/dbus_free_string_array/g_strfreev/
* src/NetworkManagerDbus.c:
(nm_dbus_get_network_object):
validate d-bus message argument types.
Advance message iterator after reading argument,
prepend instead of append to GSList.
* src/NetworkManagerDevice.c:
(nm_device_probe_wired_link_status):
remove redundant /sys in /sys path. remove wrong
contents == NULL means has carrier assumption.
* src/nm-netlink-monitor.c
(nm_netlink_monitor_request_status): implement
function to ask kernel to dump interface link
status over netlink socket.
* test/*.c: s/dbus_free/g_free/
* utils/nm-utils.h:
(nm_print_backtrace): new macro to print backtrace.
(nm_get_timestamp): new macro to get sub-second precise
unix timestamp.
(nm_info), (nm_debug), (nm_warning), (nm_error):
new logging functions. nm_info just prints,
nm_debug includes timestamp and function,
nm_warning includes function, nm_error includes
backtrace and sigtrap.
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@497 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2005-03-15 05:30:15 +00:00
|
|
|
#include "nm-utils.h"
|
2010-04-07 12:28:57 -07:00
|
|
|
#include "nm-logging.h"
|
2005-12-31 08:21:24 +00:00
|
|
|
#include "nm-device.h"
|
2008-04-27 14:30:06 +00:00
|
|
|
#include "nm-dbus-manager.h"
|
|
|
|
|
#include "nm-dispatcher-action.h"
|
|
|
|
|
#include "nm-dbus-glib-types.h"
|
2011-01-13 13:28:52 -06:00
|
|
|
#include "nm-setting-connection.h"
|
|
|
|
|
#include "nm-setting-ip4-config.h"
|
|
|
|
|
#include "nm-setting-ip6-config.h"
|
2011-07-01 14:56:07 -05:00
|
|
|
#include "nm-setting-wireless.h"
|
|
|
|
|
#include "nm-setting-wireless-security.h"
|
|
|
|
|
#include "nm-manager-auth.h"
|
2004-06-24 14:18:37 +00:00
|
|
|
|
2004-07-06 01:34:10 +00:00
|
|
|
/*
|
|
|
|
|
* nm_ethernet_address_is_valid
|
|
|
|
|
*
|
2006-05-17 15:02:57 +00:00
|
|
|
* Compares an Ethernet address against known invalid addresses.
|
2004-07-06 01:34:10 +00:00
|
|
|
*
|
|
|
|
|
*/
|
2007-11-15 18:33:17 +00:00
|
|
|
gboolean
|
|
|
|
|
nm_ethernet_address_is_valid (const struct ether_addr *test_addr)
|
2004-07-06 01:34:10 +00:00
|
|
|
{
|
2007-11-15 18:33:17 +00:00
|
|
|
guint8 invalid_addr1[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
|
|
|
|
guint8 invalid_addr2[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
|
|
|
|
guint8 invalid_addr3[ETH_ALEN] = {0x44, 0x44, 0x44, 0x44, 0x44, 0x44};
|
|
|
|
|
guint8 invalid_addr4[ETH_ALEN] = {0x00, 0x30, 0xb4, 0x00, 0x00, 0x00}; /* prism54 dummy MAC */
|
2004-07-06 01:34:10 +00:00
|
|
|
|
2004-07-15 Dan Williams <dcbw@redhat.com>
* src/Makefile.am
- Turn on warnings
* src/NetworkManager.c
- nm_create_device_and_add_to_list(): call nm_device_deactivate() rather
that doing the deactivation ourselves
- Cancel an pending actions on a device if its being removed
- Break up link state checking a bit, make non-active wireless cards
deactivated to save power
- Remove unused variables
* src/NetworkManager.h
- Add support for "pending" device
* src/NetworkManagerAP.h
src/NetworkManagerAP.c
- Add support for determining whether and AP has encryption enabled or not
- AP address is now "struct ether_addr" rather than a string
* src/NetworkManagerDbus.h
src/NetworkManagerDbus.c
- Add signal NeedKeyForNetwork, method SetKeyForNetwork (testing only)
- Changes for AP address from struct ether_addr->string
* src/NetworkManagerDevice.h
src/NetworkManagerDevice.c
- Remove unused variables, fix warnings
- Add support for Pending Actions (things that block a device from being "active"
until they are completed).
- First pending action: Get a WEP key from the user
- Add nm_device_is_wire[d|less](), rename nm_device_is_wireless()
- Clean up explicit testing of dev->iface_type to use nm_device_is_wireless()
- Update wireless link checking to try to determine if the AP we are associated
with is correct, but the WEP key we are using is just wrong. If its wrong,
trigger the GetUserKey pending action on the device
- If dhclient can't get an IP address, it brings the device down. Bring it back
up in that case, otherwise we can't scan or link-check on it
- Add IP address change notifications at appropriate points (still needs some work)
- Add nm_device_need_ap_switch(), checks whether we need to switch access points or not
* src/NetworkManagerPolicy.h
src/NetworkManagerPolicy.c
- Split out "best" access point determiniation into separate function
- Make device activation 2-stage: first the device is pending, then
in the next iteration through it becomes "active" unless it has
pending actions
* src/NetworkManagerUtils.h
src/NetworkManagerUtils.c
- Clean up unused variables and warnings
- Wrap our debug macros in {} to prevent possible confusion
* src/NetworkManagerWireless.c
- Forgot to return current best priority, which lead to last available AP always
being chosen no matter what its priority was. Corrected.
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@15 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2004-07-15 16:51:48 +00:00
|
|
|
g_return_val_if_fail (test_addr != NULL, FALSE);
|
2004-07-06 01:34:10 +00:00
|
|
|
|
|
|
|
|
/* Compare the AP address the card has with invalid ethernet MAC addresses. */
|
2007-11-15 20:33:08 +00:00
|
|
|
if (!memcmp (test_addr->ether_addr_octet, &invalid_addr1, ETH_ALEN))
|
2007-11-15 18:33:17 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
2007-11-15 20:33:08 +00:00
|
|
|
if (!memcmp (test_addr->ether_addr_octet, &invalid_addr2, ETH_ALEN))
|
2007-11-15 18:33:17 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
2007-11-15 20:33:08 +00:00
|
|
|
if (!memcmp (test_addr->ether_addr_octet, &invalid_addr3, ETH_ALEN))
|
2007-11-15 18:33:17 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
2007-11-15 20:33:08 +00:00
|
|
|
if (!memcmp (test_addr->ether_addr_octet, &invalid_addr4, ETH_ALEN))
|
2007-11-15 18:33:17 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (test_addr->ether_addr_octet[0] & 1) /* Multicast addresses */
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
2004-07-06 01:34:10 +00:00
|
|
|
}
|
|
|
|
|
|
2004-06-24 14:18:37 +00:00
|
|
|
|
2008-04-27 12:23:17 +00:00
|
|
|
int
|
|
|
|
|
nm_spawn_process (const char *args)
|
2004-08-12 Dan Williams <dcbw@redhat.com>
* info-daemon/passphrase.glade
- Set window title to " "
* panel-applet/Makefile.am
panel-applet/keyring.png
- Deliver to correct place
* panel-applet/NMWirelessApplet.[ch]
- Add comments
- Remove applet->have_active_device as its no longer used
- (nmwa_load_theme): load keyring.png too
- (error_dialog): remove
- (show_warning_dialog): subsume functionality of error dialog too
- (nmwa_destroy, nmwa_new): create and dispose of an application-wide GConfClient
- (nmwa_handle_network_choice): add to deal with user clicking on an item from
the networks menu
- (nmwa_menu_item_activated): GtkMenuItem "activate" signal handler
- (nmwa_button_clicked, nmwa_setup_widgets): create and populate the menu on startup
and when we get broadcasts of changed wireless access points only, not when the
user clicks on the button to display the menu (too long of a wait)
- (nmwa_add_menu_item): Make active network bold, and place a keyring icon beside
networks that are encrypted
- (nmwa_dispose_menu, nmwa_menu_item_data_free): dispose of the data we place on each
menu item with g_object_set_data()
* panel-applet/NMWirelessAppletDbus.[ch]
- (nmwa_dbus_get_bool): add method to return boolean value from dbus message
- (nmwa_dbus_get_active_network): add (nmwa_dbus_get_string() wrapper to get active network)
- (nmwa_dbus_add_networks_to_menu): clean up, only show one instance of each ESSID in the menu
- (nmwa_dbus_set_network): force NetworkManager to use a particular network for wireless cards
- (nmwa_dbus_init, nmwa_dbus_filter): Trap network appear/disappear and device
activation/deactivation signals and rebuild the menu when they happen
* src/NetworkManager.c
- (main): use new nm_spawn_process() rather than system()
* src/NetworkManagerDbus.c
- (nm_dbus_devices_handle_request): don't compare AP structure addresses directly, but essids
instead. Since we can now force best_aps to stick around, the AP structure to which
dev->options.wireless.best_ap points to won't necessarily be in the device's device list
if a scan has happened since the best_ap was frozen. Also add "setNetwork" method
to freeze the best_ap.
* src/NetworkManagerDevice.[ch]
- (nm_device_activation_worker): Use new nm_spawn_process() call rather than system()
- (nm_device_*_best_ap): add freeze/unfreeze/get_frozen functions, and don't really update
the best_ap in nm_device_update_best_ap() if the best_ap is frozen AND in the device's
ap list
* src/NetworkManagerUtils.[ch]
- (nm_spawn_process): add replacement for system() usage
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@48 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2004-08-12 19:58:01 +00:00
|
|
|
{
|
2008-04-27 12:23:17 +00:00
|
|
|
gint num_args;
|
|
|
|
|
char **argv = NULL;
|
|
|
|
|
int status = -1;
|
|
|
|
|
GError *error = NULL;
|
2004-10-28 19:49:55 +00:00
|
|
|
|
2004-08-12 Dan Williams <dcbw@redhat.com>
* info-daemon/passphrase.glade
- Set window title to " "
* panel-applet/Makefile.am
panel-applet/keyring.png
- Deliver to correct place
* panel-applet/NMWirelessApplet.[ch]
- Add comments
- Remove applet->have_active_device as its no longer used
- (nmwa_load_theme): load keyring.png too
- (error_dialog): remove
- (show_warning_dialog): subsume functionality of error dialog too
- (nmwa_destroy, nmwa_new): create and dispose of an application-wide GConfClient
- (nmwa_handle_network_choice): add to deal with user clicking on an item from
the networks menu
- (nmwa_menu_item_activated): GtkMenuItem "activate" signal handler
- (nmwa_button_clicked, nmwa_setup_widgets): create and populate the menu on startup
and when we get broadcasts of changed wireless access points only, not when the
user clicks on the button to display the menu (too long of a wait)
- (nmwa_add_menu_item): Make active network bold, and place a keyring icon beside
networks that are encrypted
- (nmwa_dispose_menu, nmwa_menu_item_data_free): dispose of the data we place on each
menu item with g_object_set_data()
* panel-applet/NMWirelessAppletDbus.[ch]
- (nmwa_dbus_get_bool): add method to return boolean value from dbus message
- (nmwa_dbus_get_active_network): add (nmwa_dbus_get_string() wrapper to get active network)
- (nmwa_dbus_add_networks_to_menu): clean up, only show one instance of each ESSID in the menu
- (nmwa_dbus_set_network): force NetworkManager to use a particular network for wireless cards
- (nmwa_dbus_init, nmwa_dbus_filter): Trap network appear/disappear and device
activation/deactivation signals and rebuild the menu when they happen
* src/NetworkManager.c
- (main): use new nm_spawn_process() rather than system()
* src/NetworkManagerDbus.c
- (nm_dbus_devices_handle_request): don't compare AP structure addresses directly, but essids
instead. Since we can now force best_aps to stick around, the AP structure to which
dev->options.wireless.best_ap points to won't necessarily be in the device's device list
if a scan has happened since the best_ap was frozen. Also add "setNetwork" method
to freeze the best_ap.
* src/NetworkManagerDevice.[ch]
- (nm_device_activation_worker): Use new nm_spawn_process() call rather than system()
- (nm_device_*_best_ap): add freeze/unfreeze/get_frozen functions, and don't really update
the best_ap in nm_device_update_best_ap() if the best_ap is frozen AND in the device's
ap list
* src/NetworkManagerUtils.[ch]
- (nm_spawn_process): add replacement for system() usage
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@48 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2004-08-12 19:58:01 +00:00
|
|
|
g_return_val_if_fail (args != NULL, -1);
|
|
|
|
|
|
2008-04-27 12:23:17 +00:00
|
|
|
if (!g_shell_parse_argv (args, &num_args, &argv, &error)) {
|
2010-04-07 12:28:57 -07:00
|
|
|
nm_log_warn (LOGD_CORE, "could not parse arguments for '%s': %s", args, error->message);
|
2008-04-27 12:23:17 +00:00
|
|
|
g_error_free (error);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2004-10-28 19:49:55 +00:00
|
|
|
|
2008-04-27 12:23:17 +00:00
|
|
|
if (!g_spawn_sync ("/", argv, NULL, 0, NULL, NULL, NULL, NULL, &status, &error)) {
|
2010-04-07 12:28:57 -07:00
|
|
|
nm_log_warn (LOGD_CORE, "could not spawn process '%s': %s", args, error->message);
|
2008-04-27 12:23:17 +00:00
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
2004-10-28 19:49:55 +00:00
|
|
|
|
2008-04-27 12:23:17 +00:00
|
|
|
g_strfreev (argv);
|
|
|
|
|
return status;
|
2004-08-12 Dan Williams <dcbw@redhat.com>
* info-daemon/passphrase.glade
- Set window title to " "
* panel-applet/Makefile.am
panel-applet/keyring.png
- Deliver to correct place
* panel-applet/NMWirelessApplet.[ch]
- Add comments
- Remove applet->have_active_device as its no longer used
- (nmwa_load_theme): load keyring.png too
- (error_dialog): remove
- (show_warning_dialog): subsume functionality of error dialog too
- (nmwa_destroy, nmwa_new): create and dispose of an application-wide GConfClient
- (nmwa_handle_network_choice): add to deal with user clicking on an item from
the networks menu
- (nmwa_menu_item_activated): GtkMenuItem "activate" signal handler
- (nmwa_button_clicked, nmwa_setup_widgets): create and populate the menu on startup
and when we get broadcasts of changed wireless access points only, not when the
user clicks on the button to display the menu (too long of a wait)
- (nmwa_add_menu_item): Make active network bold, and place a keyring icon beside
networks that are encrypted
- (nmwa_dispose_menu, nmwa_menu_item_data_free): dispose of the data we place on each
menu item with g_object_set_data()
* panel-applet/NMWirelessAppletDbus.[ch]
- (nmwa_dbus_get_bool): add method to return boolean value from dbus message
- (nmwa_dbus_get_active_network): add (nmwa_dbus_get_string() wrapper to get active network)
- (nmwa_dbus_add_networks_to_menu): clean up, only show one instance of each ESSID in the menu
- (nmwa_dbus_set_network): force NetworkManager to use a particular network for wireless cards
- (nmwa_dbus_init, nmwa_dbus_filter): Trap network appear/disappear and device
activation/deactivation signals and rebuild the menu when they happen
* src/NetworkManager.c
- (main): use new nm_spawn_process() rather than system()
* src/NetworkManagerDbus.c
- (nm_dbus_devices_handle_request): don't compare AP structure addresses directly, but essids
instead. Since we can now force best_aps to stick around, the AP structure to which
dev->options.wireless.best_ap points to won't necessarily be in the device's device list
if a scan has happened since the best_ap was frozen. Also add "setNetwork" method
to freeze the best_ap.
* src/NetworkManagerDevice.[ch]
- (nm_device_activation_worker): Use new nm_spawn_process() call rather than system()
- (nm_device_*_best_ap): add freeze/unfreeze/get_frozen functions, and don't really update
the best_ap in nm_device_update_best_ap() if the best_ap is frozen AND in the device's
ap list
* src/NetworkManagerUtils.[ch]
- (nm_spawn_process): add replacement for system() usage
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@48 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2004-08-12 19:58:01 +00:00
|
|
|
}
|
2004-08-16 19:46:43 +00:00
|
|
|
|
2005-12-04 02:23:29 +00:00
|
|
|
/*
|
|
|
|
|
* nm_utils_ip4_netmask_to_prefix
|
|
|
|
|
*
|
|
|
|
|
* Figure out the network prefix from a netmask. Netmask
|
|
|
|
|
* MUST be in network byte order.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2008-07-07 18:57:37 +00:00
|
|
|
guint32
|
|
|
|
|
nm_utils_ip4_netmask_to_prefix (guint32 netmask)
|
|
|
|
|
{
|
|
|
|
|
guchar *p, *end;
|
|
|
|
|
guint32 prefix = 0;
|
|
|
|
|
|
|
|
|
|
p = (guchar *) &netmask;
|
|
|
|
|
end = p + sizeof (guint32);
|
|
|
|
|
|
|
|
|
|
while ((*p == 0xFF) && p < end) {
|
|
|
|
|
prefix += 8;
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (p < end) {
|
|
|
|
|
guchar v = *p;
|
|
|
|
|
|
|
|
|
|
while (v) {
|
|
|
|
|
prefix++;
|
|
|
|
|
v <<= 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return prefix;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* nm_utils_ip4_prefix_to_netmask
|
|
|
|
|
*
|
|
|
|
|
* Figure out the netmask from a prefix.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
guint32
|
|
|
|
|
nm_utils_ip4_prefix_to_netmask (guint32 prefix)
|
2005-12-04 02:23:29 +00:00
|
|
|
{
|
2008-07-07 18:57:37 +00:00
|
|
|
guint32 msk = 0x80000000;
|
|
|
|
|
guint32 netmask = 0;
|
2005-12-04 02:23:29 +00:00
|
|
|
|
2008-07-07 18:57:37 +00:00
|
|
|
while (prefix > 0) {
|
|
|
|
|
netmask |= msk;
|
|
|
|
|
msk >>= 1;
|
|
|
|
|
prefix--;
|
|
|
|
|
}
|
2006-08-24 11:01:37 +00:00
|
|
|
|
2008-07-07 18:57:37 +00:00
|
|
|
return (guint32) htonl (netmask);
|
2005-12-04 02:23:29 +00:00
|
|
|
}
|
|
|
|
|
|
2008-04-21 03:02:32 +00:00
|
|
|
void
|
|
|
|
|
nm_utils_merge_ip4_config (NMIP4Config *ip4_config, NMSettingIP4Config *setting)
|
|
|
|
|
{
|
2008-10-29 14:35:25 +00:00
|
|
|
int i, j;
|
2012-03-20 17:17:49 +01:00
|
|
|
gboolean setting_never_default;
|
2008-05-06 Dan Williams <dcbw@redhat.com>
* src/dhcp-manager/nm-dhcp-manager.c
- (nm_dhcp_manager_get_ip4_config): clean up; update for changes to
NMIP4Config to support multiple IP addresses
* src/NetworkManagerUtils.c
- (nm_utils_merge_ip4_config): update for multiple IP addresses
* src/nm-ip4-config.c
src/nm-ip4-config.h
- Store a list of IPv4 address/netmask/gateway tuples
- (nm_ip4_config_get_gateway, nm_ip4_config_set_gateway,
nm_ip4_config_get_netmask, nm_ip4_config_set_netmask,
nm_ip4_config_get_broadcast, nm_ip4_config_set_broadcast,
nm_ip4_config_set_address): remove
- (nm_ip4_config_take_address, nm_ip4_config_add_address,
nm_ip4_config_replace_address, nm_ip4_config_get_num_addresses):
new functions; handle multiple IPv4 addresses
* src/nm-device.c
src/ppp-manager/nm-ppp-manager.c
src/vpn-manager/nm-vpn-connection.c
src/NetworkManagerPolicy.c
test/nm-tool.c
libnm-glib/libnm-glib-test.c
- update for changes to NMIP4Config for multiple IPv4 addresses
* src/NetworkManagerSystem.c
- (nm_system_device_set_ip4_route): don't add the route if any address
is on the same subnet as the destination
- (check_one_address): ignore the exact match, just match family and
interface index
- (add_ip4_addresses): add all IPv4 addresses in an NMIP4Config to
an interface
- (nm_system_device_set_from_ip4_config): use add_ip4_addresses()
- (nm_system_vpn_device_set_from_ip4_config): use add_ip4_addresses()
* introspection/nm-ip4-config.xml
- Remove 'address', 'gateway', 'netmask', and 'broadcast' properties
- Add 'addresses' property which is an array of (uuu) tuples of
address/netmask/gateway
* libnm-util/nm-setting-ip4-config.c
- (set_property): use ip-address <-> GValue converters from nm-utils.c
* libnm-glib/nm-ip4-config.c
libnm-glib/nm-ip4-config.h
- Handle D-Bus interface changes to support multiple IP addresses
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3637 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-05-06 21:53:22 +00:00
|
|
|
|
2008-04-21 03:02:32 +00:00
|
|
|
if (!setting)
|
|
|
|
|
return; /* Defaults are just fine */
|
|
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
if (nm_setting_ip4_config_get_ignore_auto_dns (setting)) {
|
2008-05-23 07:35:43 +00:00
|
|
|
nm_ip4_config_reset_nameservers (ip4_config);
|
2009-05-11 20:02:07 -04:00
|
|
|
nm_ip4_config_reset_domains (ip4_config);
|
2008-05-23 07:35:43 +00:00
|
|
|
nm_ip4_config_reset_searches (ip4_config);
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
if (nm_setting_ip4_config_get_ignore_auto_routes (setting))
|
2008-08-06 22:23:48 +00:00
|
|
|
nm_ip4_config_reset_routes (ip4_config);
|
|
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
for (i = 0; i < nm_setting_ip4_config_get_num_dns (setting); i++) {
|
|
|
|
|
guint32 ns;
|
|
|
|
|
gboolean found = FALSE;
|
2008-04-21 03:02:32 +00:00
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
/* Avoid dupes */
|
|
|
|
|
ns = nm_setting_ip4_config_get_dns (setting, i);
|
|
|
|
|
for (j = 0; j < nm_ip4_config_get_num_nameservers (ip4_config); j++) {
|
|
|
|
|
if (nm_ip4_config_get_nameserver (ip4_config, j) == ns) {
|
|
|
|
|
found = TRUE;
|
|
|
|
|
break;
|
2008-04-21 03:02:32 +00:00
|
|
|
}
|
|
|
|
|
}
|
2008-10-29 14:35:25 +00:00
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
|
nm_ip4_config_add_nameserver (ip4_config, ns);
|
2008-04-21 03:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
2008-05-06 Dan Williams <dcbw@redhat.com>
* src/dhcp-manager/nm-dhcp-manager.c
- (nm_dhcp_manager_get_ip4_config): clean up; update for changes to
NMIP4Config to support multiple IP addresses
* src/NetworkManagerUtils.c
- (nm_utils_merge_ip4_config): update for multiple IP addresses
* src/nm-ip4-config.c
src/nm-ip4-config.h
- Store a list of IPv4 address/netmask/gateway tuples
- (nm_ip4_config_get_gateway, nm_ip4_config_set_gateway,
nm_ip4_config_get_netmask, nm_ip4_config_set_netmask,
nm_ip4_config_get_broadcast, nm_ip4_config_set_broadcast,
nm_ip4_config_set_address): remove
- (nm_ip4_config_take_address, nm_ip4_config_add_address,
nm_ip4_config_replace_address, nm_ip4_config_get_num_addresses):
new functions; handle multiple IPv4 addresses
* src/nm-device.c
src/ppp-manager/nm-ppp-manager.c
src/vpn-manager/nm-vpn-connection.c
src/NetworkManagerPolicy.c
test/nm-tool.c
libnm-glib/libnm-glib-test.c
- update for changes to NMIP4Config for multiple IPv4 addresses
* src/NetworkManagerSystem.c
- (nm_system_device_set_ip4_route): don't add the route if any address
is on the same subnet as the destination
- (check_one_address): ignore the exact match, just match family and
interface index
- (add_ip4_addresses): add all IPv4 addresses in an NMIP4Config to
an interface
- (nm_system_device_set_from_ip4_config): use add_ip4_addresses()
- (nm_system_vpn_device_set_from_ip4_config): use add_ip4_addresses()
* introspection/nm-ip4-config.xml
- Remove 'address', 'gateway', 'netmask', and 'broadcast' properties
- Add 'addresses' property which is an array of (uuu) tuples of
address/netmask/gateway
* libnm-util/nm-setting-ip4-config.c
- (set_property): use ip-address <-> GValue converters from nm-utils.c
* libnm-glib/nm-ip4-config.c
libnm-glib/nm-ip4-config.h
- Handle D-Bus interface changes to support multiple IP addresses
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3637 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-05-06 21:53:22 +00:00
|
|
|
/* DNS search domains */
|
2008-10-29 14:35:25 +00:00
|
|
|
for (i = 0; i < nm_setting_ip4_config_get_num_dns_searches (setting); i++) {
|
|
|
|
|
const char *search = nm_setting_ip4_config_get_dns_search (setting, i);
|
2008-05-06 Dan Williams <dcbw@redhat.com>
* src/dhcp-manager/nm-dhcp-manager.c
- (nm_dhcp_manager_get_ip4_config): clean up; update for changes to
NMIP4Config to support multiple IP addresses
* src/NetworkManagerUtils.c
- (nm_utils_merge_ip4_config): update for multiple IP addresses
* src/nm-ip4-config.c
src/nm-ip4-config.h
- Store a list of IPv4 address/netmask/gateway tuples
- (nm_ip4_config_get_gateway, nm_ip4_config_set_gateway,
nm_ip4_config_get_netmask, nm_ip4_config_set_netmask,
nm_ip4_config_get_broadcast, nm_ip4_config_set_broadcast,
nm_ip4_config_set_address): remove
- (nm_ip4_config_take_address, nm_ip4_config_add_address,
nm_ip4_config_replace_address, nm_ip4_config_get_num_addresses):
new functions; handle multiple IPv4 addresses
* src/nm-device.c
src/ppp-manager/nm-ppp-manager.c
src/vpn-manager/nm-vpn-connection.c
src/NetworkManagerPolicy.c
test/nm-tool.c
libnm-glib/libnm-glib-test.c
- update for changes to NMIP4Config for multiple IPv4 addresses
* src/NetworkManagerSystem.c
- (nm_system_device_set_ip4_route): don't add the route if any address
is on the same subnet as the destination
- (check_one_address): ignore the exact match, just match family and
interface index
- (add_ip4_addresses): add all IPv4 addresses in an NMIP4Config to
an interface
- (nm_system_device_set_from_ip4_config): use add_ip4_addresses()
- (nm_system_vpn_device_set_from_ip4_config): use add_ip4_addresses()
* introspection/nm-ip4-config.xml
- Remove 'address', 'gateway', 'netmask', and 'broadcast' properties
- Add 'addresses' property which is an array of (uuu) tuples of
address/netmask/gateway
* libnm-util/nm-setting-ip4-config.c
- (set_property): use ip-address <-> GValue converters from nm-utils.c
* libnm-glib/nm-ip4-config.c
libnm-glib/nm-ip4-config.h
- Handle D-Bus interface changes to support multiple IP addresses
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3637 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-05-06 21:53:22 +00:00
|
|
|
gboolean found = FALSE;
|
2008-04-21 03:02:32 +00:00
|
|
|
|
2008-05-06 Dan Williams <dcbw@redhat.com>
* src/dhcp-manager/nm-dhcp-manager.c
- (nm_dhcp_manager_get_ip4_config): clean up; update for changes to
NMIP4Config to support multiple IP addresses
* src/NetworkManagerUtils.c
- (nm_utils_merge_ip4_config): update for multiple IP addresses
* src/nm-ip4-config.c
src/nm-ip4-config.h
- Store a list of IPv4 address/netmask/gateway tuples
- (nm_ip4_config_get_gateway, nm_ip4_config_set_gateway,
nm_ip4_config_get_netmask, nm_ip4_config_set_netmask,
nm_ip4_config_get_broadcast, nm_ip4_config_set_broadcast,
nm_ip4_config_set_address): remove
- (nm_ip4_config_take_address, nm_ip4_config_add_address,
nm_ip4_config_replace_address, nm_ip4_config_get_num_addresses):
new functions; handle multiple IPv4 addresses
* src/nm-device.c
src/ppp-manager/nm-ppp-manager.c
src/vpn-manager/nm-vpn-connection.c
src/NetworkManagerPolicy.c
test/nm-tool.c
libnm-glib/libnm-glib-test.c
- update for changes to NMIP4Config for multiple IPv4 addresses
* src/NetworkManagerSystem.c
- (nm_system_device_set_ip4_route): don't add the route if any address
is on the same subnet as the destination
- (check_one_address): ignore the exact match, just match family and
interface index
- (add_ip4_addresses): add all IPv4 addresses in an NMIP4Config to
an interface
- (nm_system_device_set_from_ip4_config): use add_ip4_addresses()
- (nm_system_vpn_device_set_from_ip4_config): use add_ip4_addresses()
* introspection/nm-ip4-config.xml
- Remove 'address', 'gateway', 'netmask', and 'broadcast' properties
- Add 'addresses' property which is an array of (uuu) tuples of
address/netmask/gateway
* libnm-util/nm-setting-ip4-config.c
- (set_property): use ip-address <-> GValue converters from nm-utils.c
* libnm-glib/nm-ip4-config.c
libnm-glib/nm-ip4-config.h
- Handle D-Bus interface changes to support multiple IP addresses
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3637 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-05-06 21:53:22 +00:00
|
|
|
/* Avoid dupes */
|
2008-10-29 14:35:25 +00:00
|
|
|
for (j = 0; j < nm_ip4_config_get_num_searches (ip4_config); j++) {
|
|
|
|
|
if (!strcmp (search, nm_ip4_config_get_search (ip4_config, j))) {
|
2008-05-06 Dan Williams <dcbw@redhat.com>
* src/dhcp-manager/nm-dhcp-manager.c
- (nm_dhcp_manager_get_ip4_config): clean up; update for changes to
NMIP4Config to support multiple IP addresses
* src/NetworkManagerUtils.c
- (nm_utils_merge_ip4_config): update for multiple IP addresses
* src/nm-ip4-config.c
src/nm-ip4-config.h
- Store a list of IPv4 address/netmask/gateway tuples
- (nm_ip4_config_get_gateway, nm_ip4_config_set_gateway,
nm_ip4_config_get_netmask, nm_ip4_config_set_netmask,
nm_ip4_config_get_broadcast, nm_ip4_config_set_broadcast,
nm_ip4_config_set_address): remove
- (nm_ip4_config_take_address, nm_ip4_config_add_address,
nm_ip4_config_replace_address, nm_ip4_config_get_num_addresses):
new functions; handle multiple IPv4 addresses
* src/nm-device.c
src/ppp-manager/nm-ppp-manager.c
src/vpn-manager/nm-vpn-connection.c
src/NetworkManagerPolicy.c
test/nm-tool.c
libnm-glib/libnm-glib-test.c
- update for changes to NMIP4Config for multiple IPv4 addresses
* src/NetworkManagerSystem.c
- (nm_system_device_set_ip4_route): don't add the route if any address
is on the same subnet as the destination
- (check_one_address): ignore the exact match, just match family and
interface index
- (add_ip4_addresses): add all IPv4 addresses in an NMIP4Config to
an interface
- (nm_system_device_set_from_ip4_config): use add_ip4_addresses()
- (nm_system_vpn_device_set_from_ip4_config): use add_ip4_addresses()
* introspection/nm-ip4-config.xml
- Remove 'address', 'gateway', 'netmask', and 'broadcast' properties
- Add 'addresses' property which is an array of (uuu) tuples of
address/netmask/gateway
* libnm-util/nm-setting-ip4-config.c
- (set_property): use ip-address <-> GValue converters from nm-utils.c
* libnm-glib/nm-ip4-config.c
libnm-glib/nm-ip4-config.h
- Handle D-Bus interface changes to support multiple IP addresses
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3637 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-05-06 21:53:22 +00:00
|
|
|
found = TRUE;
|
|
|
|
|
break;
|
2008-04-21 03:02:32 +00:00
|
|
|
}
|
|
|
|
|
}
|
2008-05-06 Dan Williams <dcbw@redhat.com>
* src/dhcp-manager/nm-dhcp-manager.c
- (nm_dhcp_manager_get_ip4_config): clean up; update for changes to
NMIP4Config to support multiple IP addresses
* src/NetworkManagerUtils.c
- (nm_utils_merge_ip4_config): update for multiple IP addresses
* src/nm-ip4-config.c
src/nm-ip4-config.h
- Store a list of IPv4 address/netmask/gateway tuples
- (nm_ip4_config_get_gateway, nm_ip4_config_set_gateway,
nm_ip4_config_get_netmask, nm_ip4_config_set_netmask,
nm_ip4_config_get_broadcast, nm_ip4_config_set_broadcast,
nm_ip4_config_set_address): remove
- (nm_ip4_config_take_address, nm_ip4_config_add_address,
nm_ip4_config_replace_address, nm_ip4_config_get_num_addresses):
new functions; handle multiple IPv4 addresses
* src/nm-device.c
src/ppp-manager/nm-ppp-manager.c
src/vpn-manager/nm-vpn-connection.c
src/NetworkManagerPolicy.c
test/nm-tool.c
libnm-glib/libnm-glib-test.c
- update for changes to NMIP4Config for multiple IPv4 addresses
* src/NetworkManagerSystem.c
- (nm_system_device_set_ip4_route): don't add the route if any address
is on the same subnet as the destination
- (check_one_address): ignore the exact match, just match family and
interface index
- (add_ip4_addresses): add all IPv4 addresses in an NMIP4Config to
an interface
- (nm_system_device_set_from_ip4_config): use add_ip4_addresses()
- (nm_system_vpn_device_set_from_ip4_config): use add_ip4_addresses()
* introspection/nm-ip4-config.xml
- Remove 'address', 'gateway', 'netmask', and 'broadcast' properties
- Add 'addresses' property which is an array of (uuu) tuples of
address/netmask/gateway
* libnm-util/nm-setting-ip4-config.c
- (set_property): use ip-address <-> GValue converters from nm-utils.c
* libnm-glib/nm-ip4-config.c
libnm-glib/nm-ip4-config.h
- Handle D-Bus interface changes to support multiple IP addresses
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3637 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-05-06 21:53:22 +00:00
|
|
|
|
|
|
|
|
if (!found)
|
2008-10-29 14:35:25 +00:00
|
|
|
nm_ip4_config_add_search (ip4_config, search);
|
2008-04-21 03:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
2008-05-06 Dan Williams <dcbw@redhat.com>
* src/dhcp-manager/nm-dhcp-manager.c
- (nm_dhcp_manager_get_ip4_config): clean up; update for changes to
NMIP4Config to support multiple IP addresses
* src/NetworkManagerUtils.c
- (nm_utils_merge_ip4_config): update for multiple IP addresses
* src/nm-ip4-config.c
src/nm-ip4-config.h
- Store a list of IPv4 address/netmask/gateway tuples
- (nm_ip4_config_get_gateway, nm_ip4_config_set_gateway,
nm_ip4_config_get_netmask, nm_ip4_config_set_netmask,
nm_ip4_config_get_broadcast, nm_ip4_config_set_broadcast,
nm_ip4_config_set_address): remove
- (nm_ip4_config_take_address, nm_ip4_config_add_address,
nm_ip4_config_replace_address, nm_ip4_config_get_num_addresses):
new functions; handle multiple IPv4 addresses
* src/nm-device.c
src/ppp-manager/nm-ppp-manager.c
src/vpn-manager/nm-vpn-connection.c
src/NetworkManagerPolicy.c
test/nm-tool.c
libnm-glib/libnm-glib-test.c
- update for changes to NMIP4Config for multiple IPv4 addresses
* src/NetworkManagerSystem.c
- (nm_system_device_set_ip4_route): don't add the route if any address
is on the same subnet as the destination
- (check_one_address): ignore the exact match, just match family and
interface index
- (add_ip4_addresses): add all IPv4 addresses in an NMIP4Config to
an interface
- (nm_system_device_set_from_ip4_config): use add_ip4_addresses()
- (nm_system_vpn_device_set_from_ip4_config): use add_ip4_addresses()
* introspection/nm-ip4-config.xml
- Remove 'address', 'gateway', 'netmask', and 'broadcast' properties
- Add 'addresses' property which is an array of (uuu) tuples of
address/netmask/gateway
* libnm-util/nm-setting-ip4-config.c
- (set_property): use ip-address <-> GValue converters from nm-utils.c
* libnm-glib/nm-ip4-config.c
libnm-glib/nm-ip4-config.h
- Handle D-Bus interface changes to support multiple IP addresses
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3637 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-05-06 21:53:22 +00:00
|
|
|
/* IPv4 addresses */
|
2008-10-29 14:35:25 +00:00
|
|
|
for (i = 0; i < nm_setting_ip4_config_get_num_addresses (setting); i++) {
|
|
|
|
|
NMIP4Address *setting_addr = nm_setting_ip4_config_get_address (setting, i);
|
|
|
|
|
guint32 num;
|
2008-04-21 03:02:32 +00:00
|
|
|
|
2008-05-06 Dan Williams <dcbw@redhat.com>
* src/dhcp-manager/nm-dhcp-manager.c
- (nm_dhcp_manager_get_ip4_config): clean up; update for changes to
NMIP4Config to support multiple IP addresses
* src/NetworkManagerUtils.c
- (nm_utils_merge_ip4_config): update for multiple IP addresses
* src/nm-ip4-config.c
src/nm-ip4-config.h
- Store a list of IPv4 address/netmask/gateway tuples
- (nm_ip4_config_get_gateway, nm_ip4_config_set_gateway,
nm_ip4_config_get_netmask, nm_ip4_config_set_netmask,
nm_ip4_config_get_broadcast, nm_ip4_config_set_broadcast,
nm_ip4_config_set_address): remove
- (nm_ip4_config_take_address, nm_ip4_config_add_address,
nm_ip4_config_replace_address, nm_ip4_config_get_num_addresses):
new functions; handle multiple IPv4 addresses
* src/nm-device.c
src/ppp-manager/nm-ppp-manager.c
src/vpn-manager/nm-vpn-connection.c
src/NetworkManagerPolicy.c
test/nm-tool.c
libnm-glib/libnm-glib-test.c
- update for changes to NMIP4Config for multiple IPv4 addresses
* src/NetworkManagerSystem.c
- (nm_system_device_set_ip4_route): don't add the route if any address
is on the same subnet as the destination
- (check_one_address): ignore the exact match, just match family and
interface index
- (add_ip4_addresses): add all IPv4 addresses in an NMIP4Config to
an interface
- (nm_system_device_set_from_ip4_config): use add_ip4_addresses()
- (nm_system_vpn_device_set_from_ip4_config): use add_ip4_addresses()
* introspection/nm-ip4-config.xml
- Remove 'address', 'gateway', 'netmask', and 'broadcast' properties
- Add 'addresses' property which is an array of (uuu) tuples of
address/netmask/gateway
* libnm-util/nm-setting-ip4-config.c
- (set_property): use ip-address <-> GValue converters from nm-utils.c
* libnm-glib/nm-ip4-config.c
libnm-glib/nm-ip4-config.h
- Handle D-Bus interface changes to support multiple IP addresses
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3637 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-05-06 21:53:22 +00:00
|
|
|
num = nm_ip4_config_get_num_addresses (ip4_config);
|
2008-10-29 14:35:25 +00:00
|
|
|
for (j = 0; j < num; j++) {
|
|
|
|
|
NMIP4Address *cfg_addr = nm_ip4_config_get_address (ip4_config, j);
|
2008-04-21 03:02:32 +00:00
|
|
|
|
2008-05-06 Dan Williams <dcbw@redhat.com>
* src/dhcp-manager/nm-dhcp-manager.c
- (nm_dhcp_manager_get_ip4_config): clean up; update for changes to
NMIP4Config to support multiple IP addresses
* src/NetworkManagerUtils.c
- (nm_utils_merge_ip4_config): update for multiple IP addresses
* src/nm-ip4-config.c
src/nm-ip4-config.h
- Store a list of IPv4 address/netmask/gateway tuples
- (nm_ip4_config_get_gateway, nm_ip4_config_set_gateway,
nm_ip4_config_get_netmask, nm_ip4_config_set_netmask,
nm_ip4_config_get_broadcast, nm_ip4_config_set_broadcast,
nm_ip4_config_set_address): remove
- (nm_ip4_config_take_address, nm_ip4_config_add_address,
nm_ip4_config_replace_address, nm_ip4_config_get_num_addresses):
new functions; handle multiple IPv4 addresses
* src/nm-device.c
src/ppp-manager/nm-ppp-manager.c
src/vpn-manager/nm-vpn-connection.c
src/NetworkManagerPolicy.c
test/nm-tool.c
libnm-glib/libnm-glib-test.c
- update for changes to NMIP4Config for multiple IPv4 addresses
* src/NetworkManagerSystem.c
- (nm_system_device_set_ip4_route): don't add the route if any address
is on the same subnet as the destination
- (check_one_address): ignore the exact match, just match family and
interface index
- (add_ip4_addresses): add all IPv4 addresses in an NMIP4Config to
an interface
- (nm_system_device_set_from_ip4_config): use add_ip4_addresses()
- (nm_system_vpn_device_set_from_ip4_config): use add_ip4_addresses()
* introspection/nm-ip4-config.xml
- Remove 'address', 'gateway', 'netmask', and 'broadcast' properties
- Add 'addresses' property which is an array of (uuu) tuples of
address/netmask/gateway
* libnm-util/nm-setting-ip4-config.c
- (set_property): use ip-address <-> GValue converters from nm-utils.c
* libnm-glib/nm-ip4-config.c
libnm-glib/nm-ip4-config.h
- Handle D-Bus interface changes to support multiple IP addresses
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3637 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-05-06 21:53:22 +00:00
|
|
|
/* Dupe, override with user-specified address */
|
2008-10-29 14:35:25 +00:00
|
|
|
if (nm_ip4_address_get_address (cfg_addr) == nm_ip4_address_get_address (setting_addr)) {
|
|
|
|
|
nm_ip4_config_replace_address (ip4_config, j, setting_addr);
|
2008-05-06 Dan Williams <dcbw@redhat.com>
* src/dhcp-manager/nm-dhcp-manager.c
- (nm_dhcp_manager_get_ip4_config): clean up; update for changes to
NMIP4Config to support multiple IP addresses
* src/NetworkManagerUtils.c
- (nm_utils_merge_ip4_config): update for multiple IP addresses
* src/nm-ip4-config.c
src/nm-ip4-config.h
- Store a list of IPv4 address/netmask/gateway tuples
- (nm_ip4_config_get_gateway, nm_ip4_config_set_gateway,
nm_ip4_config_get_netmask, nm_ip4_config_set_netmask,
nm_ip4_config_get_broadcast, nm_ip4_config_set_broadcast,
nm_ip4_config_set_address): remove
- (nm_ip4_config_take_address, nm_ip4_config_add_address,
nm_ip4_config_replace_address, nm_ip4_config_get_num_addresses):
new functions; handle multiple IPv4 addresses
* src/nm-device.c
src/ppp-manager/nm-ppp-manager.c
src/vpn-manager/nm-vpn-connection.c
src/NetworkManagerPolicy.c
test/nm-tool.c
libnm-glib/libnm-glib-test.c
- update for changes to NMIP4Config for multiple IPv4 addresses
* src/NetworkManagerSystem.c
- (nm_system_device_set_ip4_route): don't add the route if any address
is on the same subnet as the destination
- (check_one_address): ignore the exact match, just match family and
interface index
- (add_ip4_addresses): add all IPv4 addresses in an NMIP4Config to
an interface
- (nm_system_device_set_from_ip4_config): use add_ip4_addresses()
- (nm_system_vpn_device_set_from_ip4_config): use add_ip4_addresses()
* introspection/nm-ip4-config.xml
- Remove 'address', 'gateway', 'netmask', and 'broadcast' properties
- Add 'addresses' property which is an array of (uuu) tuples of
address/netmask/gateway
* libnm-util/nm-setting-ip4-config.c
- (set_property): use ip-address <-> GValue converters from nm-utils.c
* libnm-glib/nm-ip4-config.c
libnm-glib/nm-ip4-config.h
- Handle D-Bus interface changes to support multiple IP addresses
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3637 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-05-06 21:53:22 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2008-04-21 03:02:32 +00:00
|
|
|
}
|
2008-05-06 Dan Williams <dcbw@redhat.com>
* src/dhcp-manager/nm-dhcp-manager.c
- (nm_dhcp_manager_get_ip4_config): clean up; update for changes to
NMIP4Config to support multiple IP addresses
* src/NetworkManagerUtils.c
- (nm_utils_merge_ip4_config): update for multiple IP addresses
* src/nm-ip4-config.c
src/nm-ip4-config.h
- Store a list of IPv4 address/netmask/gateway tuples
- (nm_ip4_config_get_gateway, nm_ip4_config_set_gateway,
nm_ip4_config_get_netmask, nm_ip4_config_set_netmask,
nm_ip4_config_get_broadcast, nm_ip4_config_set_broadcast,
nm_ip4_config_set_address): remove
- (nm_ip4_config_take_address, nm_ip4_config_add_address,
nm_ip4_config_replace_address, nm_ip4_config_get_num_addresses):
new functions; handle multiple IPv4 addresses
* src/nm-device.c
src/ppp-manager/nm-ppp-manager.c
src/vpn-manager/nm-vpn-connection.c
src/NetworkManagerPolicy.c
test/nm-tool.c
libnm-glib/libnm-glib-test.c
- update for changes to NMIP4Config for multiple IPv4 addresses
* src/NetworkManagerSystem.c
- (nm_system_device_set_ip4_route): don't add the route if any address
is on the same subnet as the destination
- (check_one_address): ignore the exact match, just match family and
interface index
- (add_ip4_addresses): add all IPv4 addresses in an NMIP4Config to
an interface
- (nm_system_device_set_from_ip4_config): use add_ip4_addresses()
- (nm_system_vpn_device_set_from_ip4_config): use add_ip4_addresses()
* introspection/nm-ip4-config.xml
- Remove 'address', 'gateway', 'netmask', and 'broadcast' properties
- Add 'addresses' property which is an array of (uuu) tuples of
address/netmask/gateway
* libnm-util/nm-setting-ip4-config.c
- (set_property): use ip-address <-> GValue converters from nm-utils.c
* libnm-glib/nm-ip4-config.c
libnm-glib/nm-ip4-config.h
- Handle D-Bus interface changes to support multiple IP addresses
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3637 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-05-06 21:53:22 +00:00
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
if (j == num)
|
2008-05-06 Dan Williams <dcbw@redhat.com>
* src/dhcp-manager/nm-dhcp-manager.c
- (nm_dhcp_manager_get_ip4_config): clean up; update for changes to
NMIP4Config to support multiple IP addresses
* src/NetworkManagerUtils.c
- (nm_utils_merge_ip4_config): update for multiple IP addresses
* src/nm-ip4-config.c
src/nm-ip4-config.h
- Store a list of IPv4 address/netmask/gateway tuples
- (nm_ip4_config_get_gateway, nm_ip4_config_set_gateway,
nm_ip4_config_get_netmask, nm_ip4_config_set_netmask,
nm_ip4_config_get_broadcast, nm_ip4_config_set_broadcast,
nm_ip4_config_set_address): remove
- (nm_ip4_config_take_address, nm_ip4_config_add_address,
nm_ip4_config_replace_address, nm_ip4_config_get_num_addresses):
new functions; handle multiple IPv4 addresses
* src/nm-device.c
src/ppp-manager/nm-ppp-manager.c
src/vpn-manager/nm-vpn-connection.c
src/NetworkManagerPolicy.c
test/nm-tool.c
libnm-glib/libnm-glib-test.c
- update for changes to NMIP4Config for multiple IPv4 addresses
* src/NetworkManagerSystem.c
- (nm_system_device_set_ip4_route): don't add the route if any address
is on the same subnet as the destination
- (check_one_address): ignore the exact match, just match family and
interface index
- (add_ip4_addresses): add all IPv4 addresses in an NMIP4Config to
an interface
- (nm_system_device_set_from_ip4_config): use add_ip4_addresses()
- (nm_system_vpn_device_set_from_ip4_config): use add_ip4_addresses()
* introspection/nm-ip4-config.xml
- Remove 'address', 'gateway', 'netmask', and 'broadcast' properties
- Add 'addresses' property which is an array of (uuu) tuples of
address/netmask/gateway
* libnm-util/nm-setting-ip4-config.c
- (set_property): use ip-address <-> GValue converters from nm-utils.c
* libnm-glib/nm-ip4-config.c
libnm-glib/nm-ip4-config.h
- Handle D-Bus interface changes to support multiple IP addresses
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3637 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-05-06 21:53:22 +00:00
|
|
|
nm_ip4_config_add_address (ip4_config, setting_addr);
|
2008-04-21 03:02:32 +00:00
|
|
|
}
|
2008-06-02 08:44:48 +00:00
|
|
|
|
2008-08-06 22:23:48 +00:00
|
|
|
/* IPv4 routes */
|
2008-10-29 14:35:25 +00:00
|
|
|
for (i = 0; i < nm_setting_ip4_config_get_num_routes (setting); i++) {
|
|
|
|
|
NMIP4Route *setting_route = nm_setting_ip4_config_get_route (setting, i);
|
|
|
|
|
guint32 num;
|
2008-06-02 08:44:48 +00:00
|
|
|
|
2008-08-06 22:23:48 +00:00
|
|
|
num = nm_ip4_config_get_num_routes (ip4_config);
|
2008-10-29 14:35:25 +00:00
|
|
|
for (j = 0; j < num; j++) {
|
|
|
|
|
NMIP4Route *cfg_route = nm_ip4_config_get_route (ip4_config, j);
|
2008-08-06 22:23:48 +00:00
|
|
|
|
|
|
|
|
/* Dupe, override with user-specified route */
|
2008-10-29 14:35:25 +00:00
|
|
|
if ( (nm_ip4_route_get_dest (cfg_route) == nm_ip4_route_get_dest (setting_route))
|
|
|
|
|
&& (nm_ip4_route_get_prefix (cfg_route) == nm_ip4_route_get_prefix (setting_route))
|
|
|
|
|
&& (nm_ip4_route_get_next_hop (cfg_route) == nm_ip4_route_get_next_hop (setting_route))) {
|
|
|
|
|
nm_ip4_config_replace_route (ip4_config, j, setting_route);
|
2008-06-02 08:44:48 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
if (j == num)
|
2008-08-06 22:23:48 +00:00
|
|
|
nm_ip4_config_add_route (ip4_config, setting_route);
|
2008-06-02 08:44:48 +00:00
|
|
|
}
|
2008-12-09 20:01:49 +00:00
|
|
|
|
2012-03-20 17:17:49 +01:00
|
|
|
setting_never_default = nm_setting_ip4_config_get_never_default (setting);
|
|
|
|
|
|
|
|
|
|
if (nm_setting_ip4_config_get_ignore_auto_routes (setting))
|
|
|
|
|
nm_ip4_config_set_never_default (ip4_config, setting_never_default);
|
|
|
|
|
else {
|
|
|
|
|
if (setting_never_default)
|
|
|
|
|
nm_ip4_config_set_never_default (ip4_config, TRUE);
|
|
|
|
|
}
|
2008-04-21 03:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
2009-07-29 12:12:41 -04:00
|
|
|
static inline gboolean
|
|
|
|
|
ip6_addresses_equal (const struct in6_addr *a, const struct in6_addr *b)
|
|
|
|
|
{
|
|
|
|
|
return memcmp (a, b, sizeof (struct in6_addr)) == 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* This is exactly identical to nm_utils_merge_ip4_config, with s/4/6/,
|
|
|
|
|
* except that we can't compare addresses with ==.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
nm_utils_merge_ip6_config (NMIP6Config *ip6_config, NMSettingIP6Config *setting)
|
|
|
|
|
{
|
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
|
|
if (!setting)
|
|
|
|
|
return; /* Defaults are just fine */
|
|
|
|
|
|
|
|
|
|
if (nm_setting_ip6_config_get_ignore_auto_dns (setting)) {
|
|
|
|
|
nm_ip6_config_reset_nameservers (ip6_config);
|
|
|
|
|
nm_ip6_config_reset_domains (ip6_config);
|
|
|
|
|
nm_ip6_config_reset_searches (ip6_config);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (nm_setting_ip6_config_get_ignore_auto_routes (setting))
|
|
|
|
|
nm_ip6_config_reset_routes (ip6_config);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nm_setting_ip6_config_get_num_dns (setting); i++) {
|
|
|
|
|
const struct in6_addr *ns;
|
|
|
|
|
gboolean found = FALSE;
|
|
|
|
|
|
|
|
|
|
/* Avoid dupes */
|
|
|
|
|
ns = nm_setting_ip6_config_get_dns (setting, i);
|
|
|
|
|
for (j = 0; j < nm_ip6_config_get_num_nameservers (ip6_config); j++) {
|
|
|
|
|
if (ip6_addresses_equal (nm_ip6_config_get_nameserver (ip6_config, j), ns)) {
|
|
|
|
|
found = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
|
nm_ip6_config_add_nameserver (ip6_config, ns);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* DNS search domains */
|
|
|
|
|
for (i = 0; i < nm_setting_ip6_config_get_num_dns_searches (setting); i++) {
|
|
|
|
|
const char *search = nm_setting_ip6_config_get_dns_search (setting, i);
|
|
|
|
|
gboolean found = FALSE;
|
|
|
|
|
|
|
|
|
|
/* Avoid dupes */
|
|
|
|
|
for (j = 0; j < nm_ip6_config_get_num_searches (ip6_config); j++) {
|
|
|
|
|
if (!strcmp (search, nm_ip6_config_get_search (ip6_config, j))) {
|
|
|
|
|
found = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
|
nm_ip6_config_add_search (ip6_config, search);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* IPv6 addresses */
|
|
|
|
|
for (i = 0; i < nm_setting_ip6_config_get_num_addresses (setting); i++) {
|
|
|
|
|
NMIP6Address *setting_addr = nm_setting_ip6_config_get_address (setting, i);
|
|
|
|
|
guint32 num;
|
|
|
|
|
|
|
|
|
|
num = nm_ip6_config_get_num_addresses (ip6_config);
|
|
|
|
|
for (j = 0; j < num; j++) {
|
|
|
|
|
NMIP6Address *cfg_addr = nm_ip6_config_get_address (ip6_config, j);
|
|
|
|
|
|
|
|
|
|
/* Dupe, override with user-specified address */
|
|
|
|
|
if (ip6_addresses_equal (nm_ip6_address_get_address (cfg_addr), nm_ip6_address_get_address (setting_addr))) {
|
|
|
|
|
nm_ip6_config_replace_address (ip6_config, j, setting_addr);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (j == num)
|
|
|
|
|
nm_ip6_config_add_address (ip6_config, setting_addr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* IPv6 routes */
|
|
|
|
|
for (i = 0; i < nm_setting_ip6_config_get_num_routes (setting); i++) {
|
|
|
|
|
NMIP6Route *setting_route = nm_setting_ip6_config_get_route (setting, i);
|
|
|
|
|
guint32 num;
|
|
|
|
|
|
|
|
|
|
num = nm_ip6_config_get_num_routes (ip6_config);
|
|
|
|
|
for (j = 0; j < num; j++) {
|
|
|
|
|
NMIP6Route *cfg_route = nm_ip6_config_get_route (ip6_config, j);
|
|
|
|
|
|
|
|
|
|
/* Dupe, override with user-specified route */
|
|
|
|
|
if ( ip6_addresses_equal (nm_ip6_route_get_dest (cfg_route), nm_ip6_route_get_dest (setting_route))
|
|
|
|
|
&& (nm_ip6_route_get_prefix (cfg_route) == nm_ip6_route_get_prefix (setting_route))
|
|
|
|
|
&& ip6_addresses_equal (nm_ip6_route_get_next_hop (cfg_route), nm_ip6_route_get_next_hop (setting_route))) {
|
|
|
|
|
nm_ip6_config_replace_route (ip6_config, j, setting_route);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (j == num)
|
|
|
|
|
nm_ip6_config_add_route (ip6_config, setting_route);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (nm_setting_ip6_config_get_never_default (setting))
|
|
|
|
|
nm_ip6_config_set_never_default (ip6_config, TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-02 22:38:51 -05:00
|
|
|
static void
|
|
|
|
|
dump_object_to_props (GObject *object, GHashTable *hash)
|
|
|
|
|
{
|
|
|
|
|
GParamSpec **pspecs;
|
|
|
|
|
guint len = 0, i;
|
|
|
|
|
|
|
|
|
|
pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (object), &len);
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
|
value_hash_add_object_property (hash,
|
|
|
|
|
pspecs[i]->name,
|
|
|
|
|
object,
|
|
|
|
|
pspecs[i]->name,
|
|
|
|
|
pspecs[i]->value_type);
|
|
|
|
|
}
|
|
|
|
|
g_free (pspecs);
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-11 16:01:12 -05:00
|
|
|
static void
|
|
|
|
|
dump_dhcp4_to_props (NMDHCP4Config *config, GHashTable *hash)
|
|
|
|
|
{
|
|
|
|
|
GSList *options, *iter;
|
|
|
|
|
|
|
|
|
|
options = nm_dhcp4_config_list_options (config);
|
|
|
|
|
for (iter = options; iter; iter = g_slist_next (iter)) {
|
|
|
|
|
const char *option = (const char *) iter->data;
|
|
|
|
|
const char *val;
|
|
|
|
|
|
|
|
|
|
val = nm_dhcp4_config_get_option (config, option);
|
|
|
|
|
value_hash_add_str (hash, option, val);
|
|
|
|
|
}
|
|
|
|
|
g_slist_free (options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
dump_dhcp6_to_props (NMDHCP6Config *config, GHashTable *hash)
|
|
|
|
|
{
|
|
|
|
|
GSList *options, *iter;
|
|
|
|
|
|
|
|
|
|
options = nm_dhcp6_config_list_options (config);
|
|
|
|
|
for (iter = options; iter; iter = g_slist_next (iter)) {
|
|
|
|
|
const char *option = (const char *) iter->data;
|
|
|
|
|
const char *val;
|
|
|
|
|
|
|
|
|
|
val = nm_dhcp6_config_get_option (config, option);
|
|
|
|
|
value_hash_add_str (hash, option, val);
|
|
|
|
|
}
|
|
|
|
|
g_slist_free (options);
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-02 22:38:51 -05:00
|
|
|
static void
|
|
|
|
|
fill_device_props (NMDevice *device,
|
|
|
|
|
GHashTable *dev_hash,
|
|
|
|
|
GHashTable *ip4_hash,
|
|
|
|
|
GHashTable *ip6_hash,
|
|
|
|
|
GHashTable *dhcp4_hash,
|
|
|
|
|
GHashTable *dhcp6_hash)
|
|
|
|
|
{
|
|
|
|
|
NMIP4Config *ip4_config;
|
|
|
|
|
NMIP6Config *ip6_config;
|
|
|
|
|
NMDHCP4Config *dhcp4_config;
|
|
|
|
|
NMDHCP6Config *dhcp6_config;
|
|
|
|
|
|
|
|
|
|
/* If the action is for a VPN, send the VPN's IP interface instead of the device's */
|
|
|
|
|
value_hash_add_str (dev_hash, NMD_DEVICE_PROPS_IP_INTERFACE, nm_device_get_ip_iface (device));
|
|
|
|
|
value_hash_add_str (dev_hash, NMD_DEVICE_PROPS_INTERFACE, nm_device_get_iface (device));
|
|
|
|
|
value_hash_add_uint (dev_hash, NMD_DEVICE_PROPS_TYPE, nm_device_get_device_type (device));
|
|
|
|
|
value_hash_add_uint (dev_hash, NMD_DEVICE_PROPS_STATE, nm_device_get_state (device));
|
|
|
|
|
value_hash_add_object_path (dev_hash, NMD_DEVICE_PROPS_PATH, nm_device_get_path (device));
|
|
|
|
|
|
|
|
|
|
ip4_config = nm_device_get_ip4_config (device);
|
|
|
|
|
if (ip4_config)
|
|
|
|
|
dump_object_to_props (G_OBJECT (ip4_config), ip4_hash);
|
|
|
|
|
|
|
|
|
|
ip6_config = nm_device_get_ip6_config (device);
|
|
|
|
|
if (ip6_config)
|
|
|
|
|
dump_object_to_props (G_OBJECT (ip6_config), ip6_hash);
|
|
|
|
|
|
|
|
|
|
dhcp4_config = nm_device_get_dhcp4_config (device);
|
|
|
|
|
if (dhcp4_config)
|
2011-05-11 16:01:12 -05:00
|
|
|
dump_dhcp4_to_props (dhcp4_config, dhcp4_hash);
|
2011-05-02 22:38:51 -05:00
|
|
|
|
|
|
|
|
dhcp6_config = nm_device_get_dhcp6_config (device);
|
|
|
|
|
if (dhcp6_config)
|
2011-05-11 16:01:12 -05:00
|
|
|
dump_dhcp6_to_props (dhcp6_config, dhcp6_hash);
|
2011-05-02 22:38:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
fill_vpn_props (NMIP4Config *ip4_config,
|
|
|
|
|
NMIP6Config *ip6_config,
|
|
|
|
|
GHashTable *ip4_hash,
|
|
|
|
|
GHashTable *ip6_hash)
|
|
|
|
|
{
|
|
|
|
|
if (ip4_config)
|
|
|
|
|
dump_object_to_props (G_OBJECT (ip4_config), ip4_hash);
|
|
|
|
|
if (ip6_config)
|
|
|
|
|
dump_object_to_props (G_OBJECT (ip6_config), ip6_hash);
|
|
|
|
|
}
|
|
|
|
|
|
core: fix dbus-glib crash on shutdown with systemd
It's really dbus-glib's fault, but the problem seems to be that when
short-lived D-Bus calls are made (with dbus_g_proxy_call_no_reply)
and the service is activated, then quits immediately like the
dispatcher does, there's not enough time for internal dbus-glib
housekeeping. The GetNameOwner call that's kicked off when the
DBusGProxy is created hasn't returned by the time the proxy is
being unrefed, so the proxy doesn't end up on the
unassociated_proxies list. But when the proxy is destroyed, and
it destroys it's DBusGProxyManager, the manager expects that
the proxy is on unassociated_proxies. Thus the crash.
I'm not entirely sure why we hit this only at shutdown with
systemd; it could be that systemd is killing the bus daemon at
the same time as we're running the dispatcher and that's why the
GetNameOwner call doesn't complete.
Work around all this by expecting a message return, which works fine
during normal operation, but on shutdown allows us to avoid urefing
the proxy until everything in dbus-glib has been handled, which at
shutdown time really just means leaking it. But then we exit, so
it's cleaned up anyway.
2011-02-21 17:03:09 -06:00
|
|
|
static void
|
|
|
|
|
dispatcher_done_cb (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
dbus_g_proxy_end_call (proxy, call, NULL, G_TYPE_INVALID);
|
|
|
|
|
g_object_unref (proxy);
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-27 14:30:06 +00:00
|
|
|
void
|
|
|
|
|
nm_utils_call_dispatcher (const char *action,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
NMDevice *device,
|
2011-05-02 22:38:51 -05:00
|
|
|
const char *vpn_iface,
|
|
|
|
|
NMIP4Config *vpn_ip4_config,
|
|
|
|
|
NMIP6Config *vpn_ip6_config)
|
2008-04-27 14:30:06 +00:00
|
|
|
{
|
|
|
|
|
NMDBusManager *dbus_mgr;
|
|
|
|
|
DBusGProxy *proxy;
|
|
|
|
|
DBusGConnection *g_connection;
|
|
|
|
|
GHashTable *connection_hash;
|
|
|
|
|
GHashTable *connection_props;
|
|
|
|
|
GHashTable *device_props;
|
2011-05-02 22:38:51 -05:00
|
|
|
GHashTable *device_ip4_props;
|
|
|
|
|
GHashTable *device_ip6_props;
|
|
|
|
|
GHashTable *device_dhcp4_props;
|
|
|
|
|
GHashTable *device_dhcp6_props;
|
|
|
|
|
GHashTable *vpn_ip4_props;
|
|
|
|
|
GHashTable *vpn_ip6_props;
|
2008-04-27 14:30:06 +00:00
|
|
|
|
|
|
|
|
g_return_if_fail (action != NULL);
|
2008-10-08 22:40:42 +00:00
|
|
|
|
|
|
|
|
/* All actions except 'hostname' require a device */
|
2011-05-02 22:38:51 -05:00
|
|
|
if (strcmp (action, "hostname") != 0)
|
2008-10-08 22:40:42 +00:00
|
|
|
g_return_if_fail (NM_IS_DEVICE (device));
|
2011-05-02 22:38:51 -05:00
|
|
|
/* VPN actions require at least an IPv4 config (for now) */
|
|
|
|
|
if (strcmp (action, "vpn-up") == 0)
|
|
|
|
|
g_return_if_fail (vpn_ip4_config != NULL);
|
2008-04-27 14:30:06 +00:00
|
|
|
|
|
|
|
|
dbus_mgr = nm_dbus_manager_get ();
|
|
|
|
|
g_connection = nm_dbus_manager_get_connection (dbus_mgr);
|
|
|
|
|
proxy = dbus_g_proxy_new_for_name (g_connection,
|
|
|
|
|
NM_DISPATCHER_DBUS_SERVICE,
|
|
|
|
|
NM_DISPATCHER_DBUS_PATH,
|
|
|
|
|
NM_DISPATCHER_DBUS_IFACE);
|
|
|
|
|
if (!proxy) {
|
2010-04-07 12:28:57 -07:00
|
|
|
nm_log_err (LOGD_CORE, "could not get dispatcher proxy!");
|
2008-04-27 14:30:06 +00:00
|
|
|
g_object_unref (dbus_mgr);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (connection) {
|
2011-01-26 14:14:37 -06:00
|
|
|
connection_hash = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_NO_SECRETS);
|
2008-04-27 14:30:06 +00:00
|
|
|
|
2009-01-22 12:35:04 +02:00
|
|
|
connection_props = value_hash_create ();
|
2008-04-27 14:30:06 +00:00
|
|
|
|
|
|
|
|
/* path */
|
2009-01-22 12:35:04 +02:00
|
|
|
value_hash_add_object_path (connection_props,
|
|
|
|
|
NMD_CONNECTION_PROPS_PATH,
|
|
|
|
|
nm_connection_get_path (connection));
|
2008-04-27 14:30:06 +00:00
|
|
|
} else {
|
2009-01-22 12:35:04 +02:00
|
|
|
connection_hash = value_hash_create ();
|
|
|
|
|
connection_props = value_hash_create ();
|
2008-04-27 14:30:06 +00:00
|
|
|
}
|
|
|
|
|
|
2009-01-22 12:35:04 +02:00
|
|
|
device_props = value_hash_create ();
|
2011-05-02 22:38:51 -05:00
|
|
|
device_ip4_props = value_hash_create ();
|
|
|
|
|
device_ip6_props = value_hash_create ();
|
|
|
|
|
device_dhcp4_props = value_hash_create ();
|
|
|
|
|
device_dhcp6_props = value_hash_create ();
|
|
|
|
|
vpn_ip4_props = value_hash_create ();
|
|
|
|
|
vpn_ip6_props = value_hash_create ();
|
|
|
|
|
|
|
|
|
|
/* hostname actions only send the hostname */
|
|
|
|
|
if (strcmp (action, "hostname") != 0) {
|
|
|
|
|
fill_device_props (device,
|
|
|
|
|
device_props,
|
|
|
|
|
device_ip4_props,
|
|
|
|
|
device_ip6_props,
|
|
|
|
|
device_dhcp4_props,
|
|
|
|
|
device_dhcp6_props);
|
|
|
|
|
if (vpn_iface)
|
|
|
|
|
fill_vpn_props (vpn_ip4_config, NULL, vpn_ip4_props, vpn_ip6_props);
|
2008-10-08 22:40:42 +00:00
|
|
|
}
|
2008-04-27 14:30:06 +00:00
|
|
|
|
core: fix dbus-glib crash on shutdown with systemd
It's really dbus-glib's fault, but the problem seems to be that when
short-lived D-Bus calls are made (with dbus_g_proxy_call_no_reply)
and the service is activated, then quits immediately like the
dispatcher does, there's not enough time for internal dbus-glib
housekeeping. The GetNameOwner call that's kicked off when the
DBusGProxy is created hasn't returned by the time the proxy is
being unrefed, so the proxy doesn't end up on the
unassociated_proxies list. But when the proxy is destroyed, and
it destroys it's DBusGProxyManager, the manager expects that
the proxy is on unassociated_proxies. Thus the crash.
I'm not entirely sure why we hit this only at shutdown with
systemd; it could be that systemd is killing the bus daemon at
the same time as we're running the dispatcher and that's why the
GetNameOwner call doesn't complete.
Work around all this by expecting a message return, which works fine
during normal operation, but on shutdown allows us to avoid urefing
the proxy until everything in dbus-glib has been handled, which at
shutdown time really just means leaking it. But then we exit, so
it's cleaned up anyway.
2011-02-21 17:03:09 -06:00
|
|
|
/* Do a non-blocking call, but wait for the reply, because dbus-glib
|
|
|
|
|
* sometimes needs time to complete internal housekeeping. If we use
|
|
|
|
|
* dbus_g_proxy_call_no_reply(), that housekeeping (specifically the
|
|
|
|
|
* GetNameOwner response) doesn't complete and we run into an assert
|
|
|
|
|
* on unreffing the proxy.
|
|
|
|
|
*/
|
|
|
|
|
dbus_g_proxy_begin_call_with_timeout (proxy, "Action",
|
|
|
|
|
dispatcher_done_cb,
|
2011-05-02 22:38:51 -05:00
|
|
|
dbus_mgr, /* automatically unref the dbus mgr when call is done */
|
core: fix dbus-glib crash on shutdown with systemd
It's really dbus-glib's fault, but the problem seems to be that when
short-lived D-Bus calls are made (with dbus_g_proxy_call_no_reply)
and the service is activated, then quits immediately like the
dispatcher does, there's not enough time for internal dbus-glib
housekeeping. The GetNameOwner call that's kicked off when the
DBusGProxy is created hasn't returned by the time the proxy is
being unrefed, so the proxy doesn't end up on the
unassociated_proxies list. But when the proxy is destroyed, and
it destroys it's DBusGProxyManager, the manager expects that
the proxy is on unassociated_proxies. Thus the crash.
I'm not entirely sure why we hit this only at shutdown with
systemd; it could be that systemd is killing the bus daemon at
the same time as we're running the dispatcher and that's why the
GetNameOwner call doesn't complete.
Work around all this by expecting a message return, which works fine
during normal operation, but on shutdown allows us to avoid urefing
the proxy until everything in dbus-glib has been handled, which at
shutdown time really just means leaking it. But then we exit, so
it's cleaned up anyway.
2011-02-21 17:03:09 -06:00
|
|
|
g_object_unref,
|
|
|
|
|
5000,
|
|
|
|
|
G_TYPE_STRING, action,
|
|
|
|
|
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, connection_hash,
|
|
|
|
|
DBUS_TYPE_G_MAP_OF_VARIANT, connection_props,
|
|
|
|
|
DBUS_TYPE_G_MAP_OF_VARIANT, device_props,
|
2011-05-02 22:38:51 -05:00
|
|
|
DBUS_TYPE_G_MAP_OF_VARIANT, device_ip4_props,
|
|
|
|
|
DBUS_TYPE_G_MAP_OF_VARIANT, device_ip6_props,
|
|
|
|
|
DBUS_TYPE_G_MAP_OF_VARIANT, device_dhcp4_props,
|
|
|
|
|
DBUS_TYPE_G_MAP_OF_VARIANT, device_dhcp6_props,
|
|
|
|
|
G_TYPE_STRING, vpn_iface ? vpn_iface : "",
|
|
|
|
|
DBUS_TYPE_G_MAP_OF_VARIANT, vpn_ip4_props,
|
|
|
|
|
DBUS_TYPE_G_MAP_OF_VARIANT, vpn_ip6_props,
|
core: fix dbus-glib crash on shutdown with systemd
It's really dbus-glib's fault, but the problem seems to be that when
short-lived D-Bus calls are made (with dbus_g_proxy_call_no_reply)
and the service is activated, then quits immediately like the
dispatcher does, there's not enough time for internal dbus-glib
housekeeping. The GetNameOwner call that's kicked off when the
DBusGProxy is created hasn't returned by the time the proxy is
being unrefed, so the proxy doesn't end up on the
unassociated_proxies list. But when the proxy is destroyed, and
it destroys it's DBusGProxyManager, the manager expects that
the proxy is on unassociated_proxies. Thus the crash.
I'm not entirely sure why we hit this only at shutdown with
systemd; it could be that systemd is killing the bus daemon at
the same time as we're running the dispatcher and that's why the
GetNameOwner call doesn't complete.
Work around all this by expecting a message return, which works fine
during normal operation, but on shutdown allows us to avoid urefing
the proxy until everything in dbus-glib has been handled, which at
shutdown time really just means leaking it. But then we exit, so
it's cleaned up anyway.
2011-02-21 17:03:09 -06:00
|
|
|
G_TYPE_INVALID);
|
2008-04-27 14:30:06 +00:00
|
|
|
g_hash_table_destroy (connection_hash);
|
|
|
|
|
g_hash_table_destroy (connection_props);
|
|
|
|
|
g_hash_table_destroy (device_props);
|
2011-05-02 22:38:51 -05:00
|
|
|
g_hash_table_destroy (device_ip4_props);
|
|
|
|
|
g_hash_table_destroy (device_ip6_props);
|
|
|
|
|
g_hash_table_destroy (device_dhcp4_props);
|
|
|
|
|
g_hash_table_destroy (device_dhcp6_props);
|
|
|
|
|
g_hash_table_destroy (vpn_ip4_props);
|
|
|
|
|
g_hash_table_destroy (vpn_ip6_props);
|
2008-04-27 14:30:06 +00:00
|
|
|
}
|
2008-04-21 03:02:32 +00:00
|
|
|
|
2009-06-11 00:39:12 -04:00
|
|
|
gboolean
|
|
|
|
|
nm_match_spec_hwaddr (const GSList *specs, const char *hwaddr)
|
|
|
|
|
{
|
|
|
|
|
const GSList *iter;
|
|
|
|
|
char *hwaddr_match, *p;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (hwaddr != NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
p = hwaddr_match = g_strdup_printf ("mac:%s", hwaddr);
|
|
|
|
|
|
|
|
|
|
while (*p) {
|
|
|
|
|
*p = g_ascii_tolower (*p);
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (iter = specs; iter; iter = g_slist_next (iter)) {
|
|
|
|
|
if (!strcmp ((const char *) iter->data, hwaddr_match)) {
|
|
|
|
|
g_free (hwaddr_match);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (hwaddr_match);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-26 16:28:51 -07:00
|
|
|
#define BUFSIZE 10
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
parse_subchannels (const char *subchannels, guint32 *a, guint32 *b, guint32 *c)
|
|
|
|
|
{
|
|
|
|
|
long unsigned int tmp;
|
|
|
|
|
char buf[BUFSIZE + 1];
|
|
|
|
|
const char *p = subchannels;
|
|
|
|
|
int i = 0;
|
|
|
|
|
char *pa = NULL, *pb = NULL, *pc = NULL;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (subchannels != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (a != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (*a == 0, FALSE);
|
|
|
|
|
g_return_val_if_fail (b != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (*b == 0, FALSE);
|
|
|
|
|
g_return_val_if_fail (c != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (*c == 0, FALSE);
|
|
|
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
|
if (!isxdigit (subchannels[0]))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
/* Get the first channel */
|
|
|
|
|
while (*p && (*p != ',')) {
|
|
|
|
|
if (!isxdigit (*p) && (*p != '.'))
|
|
|
|
|
return FALSE; /* Invalid chars */
|
|
|
|
|
if (i >= BUFSIZE)
|
|
|
|
|
return FALSE; /* Too long to be a subchannel */
|
|
|
|
|
buf[i++] = *p++;
|
|
|
|
|
}
|
|
|
|
|
buf[i] = '\0';
|
|
|
|
|
|
|
|
|
|
/* and grab each of its elements, there should be 3 */
|
|
|
|
|
pa = &buf[0];
|
|
|
|
|
pb = strchr (buf, '.');
|
|
|
|
|
if (pb)
|
|
|
|
|
pc = strchr (pb + 1, '.');
|
|
|
|
|
if (!pa || !pb || !pc)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
/* Split the string */
|
|
|
|
|
*pb++ = '\0';
|
|
|
|
|
*pc++ = '\0';
|
|
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
tmp = strtoul (pa, NULL, 16);
|
|
|
|
|
if (errno)
|
|
|
|
|
return FALSE;
|
|
|
|
|
*a = (guint32) tmp;
|
|
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
tmp = strtoul (pb, NULL, 16);
|
|
|
|
|
if (errno)
|
|
|
|
|
return FALSE;
|
|
|
|
|
*b = (guint32) tmp;
|
|
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
tmp = strtoul (pc, NULL, 16);
|
|
|
|
|
if (errno)
|
|
|
|
|
return FALSE;
|
|
|
|
|
*c = (guint32) tmp;
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-17 21:24:14 -07:00
|
|
|
#define SUBCHAN_TAG "s390-subchannels:"
|
2010-05-26 16:28:51 -07:00
|
|
|
|
|
|
|
|
gboolean
|
2010-06-17 21:24:14 -07:00
|
|
|
nm_match_spec_s390_subchannels (const GSList *specs, const char *subchannels)
|
2010-05-26 16:28:51 -07:00
|
|
|
{
|
|
|
|
|
const GSList *iter;
|
|
|
|
|
guint32 a = 0, b = 0, c = 0;
|
|
|
|
|
guint32 spec_a = 0, spec_b = 0, spec_c = 0;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (subchannels != NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
if (!parse_subchannels (subchannels, &a, &b, &c))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
for (iter = specs; iter; iter = g_slist_next (iter)) {
|
|
|
|
|
const char *spec = iter->data;
|
|
|
|
|
|
|
|
|
|
if (!strncmp (spec, SUBCHAN_TAG, strlen (SUBCHAN_TAG))) {
|
|
|
|
|
spec += strlen (SUBCHAN_TAG);
|
|
|
|
|
if (parse_subchannels (spec, &spec_a, &spec_b, &spec_c)) {
|
|
|
|
|
if (a == spec_a && b == spec_b && c == spec_c)
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-01 14:56:07 -05:00
|
|
|
const char *
|
|
|
|
|
nm_utils_get_shared_wifi_permission (NMConnection *connection)
|
|
|
|
|
{
|
|
|
|
|
NMSettingWireless *s_wifi;
|
|
|
|
|
NMSettingWirelessSecurity *s_wsec;
|
|
|
|
|
NMSettingIP4Config *s_ip4;
|
|
|
|
|
const char *method = NULL;
|
|
|
|
|
|
|
|
|
|
s_ip4 = nm_connection_get_setting_ip4_config (connection);
|
|
|
|
|
if (s_ip4)
|
|
|
|
|
method = nm_setting_ip4_config_get_method (s_ip4);
|
|
|
|
|
|
|
|
|
|
if (g_strcmp0 (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED) != 0)
|
|
|
|
|
return NULL; /* Not shared */
|
|
|
|
|
|
|
|
|
|
s_wifi = nm_connection_get_setting_wireless (connection);
|
|
|
|
|
if (s_wifi) {
|
|
|
|
|
s_wsec = nm_connection_get_setting_wireless_security (connection);
|
|
|
|
|
if (nm_setting_wireless_get_security (s_wifi) || s_wsec)
|
|
|
|
|
return NM_AUTH_PERMISSION_WIFI_SHARE_PROTECTED;
|
|
|
|
|
else
|
|
|
|
|
return NM_AUTH_PERMISSION_WIFI_SHARE_OPEN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-22 12:35:04 +02:00
|
|
|
/*********************************/
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
nm_gvalue_destroy (gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GValue *value = (GValue *) data;
|
|
|
|
|
|
|
|
|
|
g_value_unset (value);
|
|
|
|
|
g_slice_free (GValue, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GHashTable *
|
|
|
|
|
value_hash_create (void)
|
|
|
|
|
{
|
|
|
|
|
return g_hash_table_new_full (g_str_hash, g_str_equal, g_free, nm_gvalue_destroy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
value_hash_add (GHashTable *hash,
|
|
|
|
|
const char *key,
|
|
|
|
|
GValue *value)
|
|
|
|
|
{
|
|
|
|
|
g_hash_table_insert (hash, g_strdup (key), value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
value_hash_add_str (GHashTable *hash,
|
|
|
|
|
const char *key,
|
|
|
|
|
const char *str)
|
|
|
|
|
{
|
|
|
|
|
GValue *value;
|
|
|
|
|
|
|
|
|
|
value = g_slice_new0 (GValue);
|
|
|
|
|
g_value_init (value, G_TYPE_STRING);
|
|
|
|
|
g_value_set_string (value, str);
|
|
|
|
|
|
|
|
|
|
value_hash_add (hash, key, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
value_hash_add_object_path (GHashTable *hash,
|
|
|
|
|
const char *key,
|
|
|
|
|
const char *op)
|
|
|
|
|
{
|
|
|
|
|
GValue *value;
|
|
|
|
|
|
|
|
|
|
value = g_slice_new0 (GValue);
|
|
|
|
|
g_value_init (value, DBUS_TYPE_G_OBJECT_PATH);
|
|
|
|
|
g_value_set_boxed (value, op);
|
|
|
|
|
|
|
|
|
|
value_hash_add (hash, key, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
value_hash_add_uint (GHashTable *hash,
|
|
|
|
|
const char *key,
|
|
|
|
|
guint32 val)
|
|
|
|
|
{
|
|
|
|
|
GValue *value;
|
|
|
|
|
|
|
|
|
|
value = g_slice_new0 (GValue);
|
|
|
|
|
g_value_init (value, G_TYPE_UINT);
|
|
|
|
|
g_value_set_uint (value, val);
|
|
|
|
|
|
|
|
|
|
value_hash_add (hash, key, value);
|
|
|
|
|
}
|
2009-06-11 00:39:12 -04:00
|
|
|
|
2010-03-16 23:51:55 -07:00
|
|
|
void
|
|
|
|
|
value_hash_add_bool (GHashTable *hash,
|
|
|
|
|
const char *key,
|
|
|
|
|
gboolean val)
|
|
|
|
|
{
|
|
|
|
|
GValue *value;
|
|
|
|
|
|
|
|
|
|
value = g_slice_new0 (GValue);
|
|
|
|
|
g_value_init (value, G_TYPE_BOOLEAN);
|
|
|
|
|
g_value_set_boolean (value, val);
|
|
|
|
|
|
|
|
|
|
value_hash_add (hash, key, value);
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-02 22:38:51 -05:00
|
|
|
void
|
|
|
|
|
value_hash_add_object_property (GHashTable *hash,
|
|
|
|
|
const char *key,
|
|
|
|
|
GObject *object,
|
|
|
|
|
const char *prop,
|
|
|
|
|
GType val_type)
|
|
|
|
|
{
|
|
|
|
|
GValue *value;
|
|
|
|
|
|
|
|
|
|
value = g_slice_new0 (GValue);
|
|
|
|
|
g_value_init (value, val_type);
|
|
|
|
|
g_object_get_property (object, prop, value);
|
|
|
|
|
value_hash_add (hash, key, value);
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-29 12:12:41 -04:00
|
|
|
gboolean
|
|
|
|
|
nm_utils_do_sysctl (const char *path, const char *value)
|
|
|
|
|
{
|
|
|
|
|
int fd, len, nwrote, total;
|
|
|
|
|
|
|
|
|
|
fd = open (path, O_WRONLY | O_TRUNC);
|
|
|
|
|
if (fd == -1)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
len = strlen (value);
|
|
|
|
|
total = 0;
|
|
|
|
|
do {
|
|
|
|
|
nwrote = write (fd, value + total, len - total);
|
|
|
|
|
if (nwrote == -1) {
|
|
|
|
|
if (errno == EINTR)
|
|
|
|
|
continue;
|
|
|
|
|
close (fd);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
total += nwrote;
|
|
|
|
|
} while (total < len);
|
|
|
|
|
|
|
|
|
|
close (fd);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-03 03:42:43 -07:00
|
|
|
gboolean
|
|
|
|
|
nm_utils_get_proc_sys_net_value (const char *path,
|
|
|
|
|
const char *iface,
|
2011-07-12 09:08:04 +02:00
|
|
|
gint32 *out_value)
|
2010-05-03 03:42:43 -07:00
|
|
|
{
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
char *contents = NULL;
|
|
|
|
|
gboolean success = FALSE;
|
|
|
|
|
long int tmp;
|
|
|
|
|
|
|
|
|
|
if (!g_file_get_contents (path, &contents, NULL, &error)) {
|
2010-05-04 16:12:52 -07:00
|
|
|
nm_log_dbg (LOGD_DEVICE, "(%s): error reading %s: (%d) %s",
|
|
|
|
|
iface, path,
|
|
|
|
|
error ? error->code : -1,
|
|
|
|
|
error && error->message ? error->message : "(unknown)");
|
2010-05-03 03:42:43 -07:00
|
|
|
g_clear_error (&error);
|
|
|
|
|
} else {
|
|
|
|
|
errno = 0;
|
|
|
|
|
tmp = strtol (contents, NULL, 10);
|
2011-07-12 09:08:04 +02:00
|
|
|
if (errno == 0) {
|
|
|
|
|
*out_value = (gint32) tmp;
|
2010-05-03 03:42:43 -07:00
|
|
|
success = TRUE;
|
|
|
|
|
}
|
|
|
|
|
g_free (contents);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-12 09:08:04 +02:00
|
|
|
gboolean
|
|
|
|
|
nm_utils_get_proc_sys_net_value_with_bounds (const char *path,
|
|
|
|
|
const char *iface,
|
|
|
|
|
gint32 *out_value,
|
|
|
|
|
gint32 valid_min,
|
|
|
|
|
gint32 valid_max)
|
|
|
|
|
{
|
|
|
|
|
gboolean result;
|
|
|
|
|
gint32 val;
|
|
|
|
|
|
|
|
|
|
result = nm_utils_get_proc_sys_net_value (path, iface, &val);
|
|
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
|
if (val >= valid_min && val <= valid_max)
|
|
|
|
|
*out_value = val;
|
|
|
|
|
else
|
|
|
|
|
result = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-13 13:28:52 -06:00
|
|
|
static char *
|
|
|
|
|
get_new_connection_name (const GSList *existing,
|
|
|
|
|
const char *format,
|
|
|
|
|
const char *preferred)
|
|
|
|
|
{
|
|
|
|
|
GSList *names = NULL;
|
|
|
|
|
const GSList *iter;
|
|
|
|
|
char *cname = NULL;
|
|
|
|
|
int i = 0;
|
|
|
|
|
gboolean preferred_found = FALSE;
|
|
|
|
|
|
|
|
|
|
for (iter = existing; iter; iter = g_slist_next (iter)) {
|
|
|
|
|
NMConnection *candidate = NM_CONNECTION (iter->data);
|
|
|
|
|
const char *id;
|
|
|
|
|
|
2011-03-08 13:41:28 +01:00
|
|
|
id = nm_connection_get_id (candidate);
|
2011-01-13 13:28:52 -06:00
|
|
|
g_assert (id);
|
|
|
|
|
names = g_slist_append (names, (gpointer) id);
|
|
|
|
|
|
|
|
|
|
if (preferred && !preferred_found && (strcmp (preferred, id) == 0))
|
|
|
|
|
preferred_found = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Return the preferred name if it was unique */
|
|
|
|
|
if (preferred && !preferred_found) {
|
|
|
|
|
g_slist_free (names);
|
|
|
|
|
return g_strdup (preferred);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Otherwise find the next available unique connection name using the given
|
|
|
|
|
* connection name template.
|
|
|
|
|
*/
|
|
|
|
|
while (!cname && (i++ < 10000)) {
|
|
|
|
|
char *temp;
|
|
|
|
|
gboolean found = FALSE;
|
|
|
|
|
|
|
|
|
|
temp = g_strdup_printf (format, i);
|
|
|
|
|
for (iter = names; iter; iter = g_slist_next (iter)) {
|
|
|
|
|
if (!strcmp (iter->data, temp)) {
|
|
|
|
|
found = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!found)
|
|
|
|
|
cname = temp;
|
|
|
|
|
else
|
|
|
|
|
g_free (temp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_slist_free (names);
|
|
|
|
|
return cname;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nm_utils_complete_generic (NMConnection *connection,
|
|
|
|
|
const char *ctype,
|
|
|
|
|
const GSList *existing,
|
|
|
|
|
const char *format,
|
2011-02-25 11:58:16 -06:00
|
|
|
const char *preferred,
|
|
|
|
|
gboolean default_enable_ipv6)
|
2011-01-13 13:28:52 -06:00
|
|
|
{
|
|
|
|
|
NMSettingConnection *s_con;
|
|
|
|
|
NMSettingIP4Config *s_ip4;
|
|
|
|
|
NMSettingIP6Config *s_ip6;
|
|
|
|
|
const char *method;
|
|
|
|
|
char *id, *uuid;
|
|
|
|
|
|
2011-12-05 12:27:47 +01:00
|
|
|
s_con = nm_connection_get_setting_connection (connection);
|
2011-01-13 13:28:52 -06:00
|
|
|
if (!s_con) {
|
|
|
|
|
s_con = (NMSettingConnection *) nm_setting_connection_new ();
|
|
|
|
|
nm_connection_add_setting (connection, NM_SETTING (s_con));
|
|
|
|
|
}
|
|
|
|
|
g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_TYPE, ctype, NULL);
|
|
|
|
|
|
|
|
|
|
if (!nm_setting_connection_get_uuid (s_con)) {
|
|
|
|
|
uuid = nm_utils_uuid_generate ();
|
|
|
|
|
g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_UUID, uuid, NULL);
|
|
|
|
|
g_free (uuid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Add a connection ID if absent */
|
|
|
|
|
if (!nm_setting_connection_get_id (s_con)) {
|
|
|
|
|
id = get_new_connection_name (existing, format, preferred);
|
|
|
|
|
g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_ID, id, NULL);
|
|
|
|
|
g_free (id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Add an 'auto' IPv4 connection if present */
|
2011-12-05 12:27:47 +01:00
|
|
|
s_ip4 = nm_connection_get_setting_ip4_config (connection);
|
2011-01-13 13:28:52 -06:00
|
|
|
if (!s_ip4) {
|
|
|
|
|
s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
|
|
|
|
|
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
|
|
|
|
|
}
|
|
|
|
|
method = nm_setting_ip4_config_get_method (s_ip4);
|
|
|
|
|
if (!method) {
|
|
|
|
|
g_object_set (G_OBJECT (s_ip4),
|
|
|
|
|
NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-25 11:58:16 -06:00
|
|
|
/* Add an 'auto' IPv6 setting if allowed and not preset */
|
2011-12-05 12:27:47 +01:00
|
|
|
s_ip6 = nm_connection_get_setting_ip6_config (connection);
|
2011-02-25 11:58:16 -06:00
|
|
|
if (!s_ip6 && default_enable_ipv6) {
|
2011-01-13 13:28:52 -06:00
|
|
|
s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
|
|
|
|
|
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
|
|
|
|
|
}
|
2011-02-25 11:58:16 -06:00
|
|
|
if (s_ip6 && !nm_setting_ip6_config_get_method (s_ip6)) {
|
2011-01-13 13:28:52 -06:00
|
|
|
g_object_set (G_OBJECT (s_ip6),
|
|
|
|
|
NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
|
|
|
|
|
NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-12 14:54:24 -06:00
|
|
|
gboolean
|
|
|
|
|
nm_utils_is_uuid (const char *str)
|
|
|
|
|
{
|
|
|
|
|
const char *p = str;
|
|
|
|
|
int num_dashes = 0;
|
|
|
|
|
|
|
|
|
|
while (*p) {
|
|
|
|
|
if (*p == '-')
|
|
|
|
|
num_dashes++;
|
|
|
|
|
else if (!isxdigit (*p))
|
|
|
|
|
return FALSE;
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (num_dashes == 4) && (p - str == 36);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-12 14:48:44 -06:00
|
|
|
char *
|
2012-02-22 23:40:18 -06:00
|
|
|
nm_utils_new_vlan_name (const char *parent_iface, guint32 vlan_id)
|
2012-02-12 14:48:44 -06:00
|
|
|
{
|
2012-02-22 23:40:18 -06:00
|
|
|
return g_strdup_printf ("%s.%d", parent_iface, vlan_id);
|
2012-02-12 14:48:44 -06:00
|
|
|
}
|
|
|
|
|
|