NetworkManager/src/NetworkManagerUtils.c

507 lines
13 KiB
C
Raw Normal View History

/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* 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.
*
* 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.
*
* Copyright (C) 2004 - 2008 Red Hat, Inc.
* Copyright (C) 2005 - 2008 Novell, Inc.
*/
#include <glib.h>
#include <stdio.h>
#include <string.h>
#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"
#include "nm-device.h"
#include "nm-device-wifi.h"
#include "nm-device-ethernet.h"
#include "nm-dbus-manager.h"
#include "nm-dispatcher-action.h"
#include "nm-dbus-glib-types.h"
#include <netlink/addr.h>
#include <netinet/in.h>
/*
* nm_ethernet_address_is_valid
*
* Compares an Ethernet address against known invalid addresses.
*
*/
gboolean
nm_ethernet_address_is_valid (const struct ether_addr *test_addr)
{
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-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);
/* Compare the AP address the card has with invalid ethernet MAC addresses. */
if (!memcmp (test_addr->ether_addr_octet, &invalid_addr1, ETH_ALEN))
return FALSE;
if (!memcmp (test_addr->ether_addr_octet, &invalid_addr2, ETH_ALEN))
return FALSE;
if (!memcmp (test_addr->ether_addr_octet, &invalid_addr3, ETH_ALEN))
return FALSE;
if (!memcmp (test_addr->ether_addr_octet, &invalid_addr4, ETH_ALEN))
return FALSE;
if (test_addr->ether_addr_octet[0] & 1) /* Multicast addresses */
return FALSE;
return TRUE;
}
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
{
gint num_args;
char **argv = NULL;
int status = -1;
GError *error = NULL;
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);
if (!g_shell_parse_argv (args, &num_args, &argv, &error)) {
nm_warning ("could not parse arguments for '%s': %s", args, error->message);
g_error_free (error);
return -1;
}
if (!g_spawn_sync ("/", argv, NULL, 0, NULL, NULL, NULL, NULL, &status, &error)) {
nm_warning ("could not spawn process '%s': %s", args, error->message);
g_error_free (error);
}
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
}
void
nm_print_device_capabilities (NMDevice *dev)
{
gboolean full_support = TRUE;
guint32 caps;
const char * driver = NULL;
g_return_if_fail (dev != NULL);
caps = nm_device_get_capabilities (dev);
driver = nm_device_get_driver (dev);
if (!driver)
driver = "<unknown>";
if (caps == NM_DEVICE_CAP_NONE || !(NM_DEVICE_CAP_NM_SUPPORTED)) {
nm_info ("%s: driver '%s' is unsupported",
nm_device_get_iface (dev), driver);
return;
}
if (NM_IS_DEVICE_ETHERNET (dev)) {
if (!(caps & NM_DEVICE_CAP_CARRIER_DETECT)) {
nm_info ("%s: driver '%s' does not support carrier detection.\n"
"\tYou must switch to it manually.",
nm_device_get_iface (dev), driver);
full_support = FALSE;
}
} else if (NM_IS_DEVICE_WIFI (dev)) {
/* Print out WPA support */
}
if (full_support) {
nm_info ("%s: driver is '%s'.",
nm_device_get_iface (dev), driver);
}
}
struct nl_addr *
nm_utils_ip4_addr_to_nl_addr (guint32 ip4_addr)
{
struct nl_addr * nla = NULL;
if (!(nla = nl_addr_alloc (sizeof (in_addr_t))))
return NULL;
nl_addr_set_family (nla, AF_INET);
nl_addr_set_binary_addr (nla, &ip4_addr, sizeof (guint32));
return nla;
}
/*
* nm_utils_ip4_netmask_to_prefix
*
* Figure out the network prefix from a netmask. Netmask
* MUST be in network byte order.
*
*/
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)
{
guint32 msk = 0x80000000;
guint32 netmask = 0;
while (prefix > 0) {
netmask |= msk;
msk >>= 1;
prefix--;
}
return (guint32) htonl (netmask);
}
/* From hostap, Copyright (c) 2002-2005, Jouni Malinen <jkmaline@cc.hut.fi> */
static int hex2num (char c)
{
if (c >= '0' && c <= '9')
return c - '0';
if (c >= 'a' && c <= 'f')
return c - 'a' + 10;
if (c >= 'A' && c <= 'F')
return c - 'A' + 10;
return -1;
}
static int hex2byte (const char *hex)
{
int a, b;
a = hex2num(*hex++);
if (a < 0)
return -1;
b = hex2num(*hex++);
if (b < 0)
return -1;
return (a << 4) | b;
}
char *
nm_utils_hexstr2bin (const char *hex,
size_t len)
{
size_t i;
int a;
const char * ipos = hex;
char * buf = NULL;
char * opos;
/* Length must be a multiple of 2 */
if ((len % 2) != 0)
return NULL;
opos = buf = g_malloc0 ((len / 2) + 1);
for (i = 0; i < len; i += 2) {
a = hex2byte (ipos);
if (a < 0) {
g_free (buf);
return NULL;
}
*opos++ = a;
ipos += 2;
}
return buf;
}
/* End from hostap */
char *
nm_ether_ntop (const struct ether_addr *mac)
{
/* we like leading zeros and all-caps, instead
* of what glibc's ether_ntop() gives us
*/
return g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X",
mac->ether_addr_octet[0], mac->ether_addr_octet[1],
mac->ether_addr_octet[2], mac->ether_addr_octet[3],
mac->ether_addr_octet[4], mac->ether_addr_octet[5]);
}
void
nm_utils_merge_ip4_config (NMIP4Config *ip4_config, NMSettingIP4Config *setting)
{
int i, 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
if (!setting)
return; /* Defaults are just fine */
if (nm_setting_ip4_config_get_ignore_auto_dns (setting)) {
nm_ip4_config_reset_nameservers (ip4_config);
nm_ip4_config_reset_searches (ip4_config);
}
if (nm_setting_ip4_config_get_ignore_auto_routes (setting))
nm_ip4_config_reset_routes (ip4_config);
for (i = 0; i < nm_setting_ip4_config_get_num_dns (setting); i++) {
guint32 ns;
gboolean found = FALSE;
/* 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;
}
}
if (!found)
nm_ip4_config_add_nameserver (ip4_config, ns);
}
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 */
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-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 */
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-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)
nm_ip4_config_add_search (ip4_config, search);
}
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 */
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-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);
for (j = 0; j < num; j++) {
NMIP4Address *cfg_addr = nm_ip4_config_get_address (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
/* Dupe, override with user-specified address */
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-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 (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);
}
/* IPv4 routes */
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;
num = nm_ip4_config_get_num_routes (ip4_config);
for (j = 0; j < num; j++) {
NMIP4Route *cfg_route = nm_ip4_config_get_route (ip4_config, j);
/* Dupe, override with user-specified route */
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);
break;
}
}
if (j == num)
nm_ip4_config_add_route (ip4_config, setting_route);
}
}
static void
nm_gvalue_destroy (gpointer data)
{
GValue *value = (GValue *) data;
g_value_unset (value);
g_slice_free (GValue, value);
}
static GValue *
str_to_gvalue (const char *str)
{
GValue *value;
value = g_slice_new0 (GValue);
g_value_init (value, G_TYPE_STRING);
g_value_set_string (value, str);
return value;
}
static GValue *
op_to_gvalue (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);
return value;
}
static GValue *
uint_to_gvalue (guint32 val)
{
GValue *value;
value = g_slice_new0 (GValue);
g_value_init (value, G_TYPE_UINT);
g_value_set_uint (value, val);
return value;
}
void
nm_utils_call_dispatcher (const char *action,
NMConnection *connection,
NMDevice *device,
const char *vpn_iface)
{
NMDBusManager *dbus_mgr;
DBusGProxy *proxy;
DBusGConnection *g_connection;
GHashTable *connection_hash;
GHashTable *connection_props;
GHashTable *device_props;
g_return_if_fail (action != NULL);
/* All actions except 'hostname' require a device */
if (strcmp (action, "hostname"))
g_return_if_fail (NM_IS_DEVICE (device));
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) {
nm_warning ("Error: could not get dispatcher proxy!");
g_object_unref (dbus_mgr);
return;
}
if (connection) {
connection_hash = nm_connection_to_hash (connection);
connection_props = g_hash_table_new_full (g_str_hash, g_str_equal,
NULL, nm_gvalue_destroy);
/* Service name */
if (nm_connection_get_scope (connection) == NM_CONNECTION_SCOPE_USER) {
g_hash_table_insert (connection_props,
NMD_CONNECTION_PROPS_SERVICE_NAME,
str_to_gvalue (NM_DBUS_SERVICE_USER_SETTINGS));
} else if (nm_connection_get_scope (connection) == NM_CONNECTION_SCOPE_SYSTEM) {
g_hash_table_insert (connection_props,
NMD_CONNECTION_PROPS_SERVICE_NAME,
str_to_gvalue (NM_DBUS_SERVICE_SYSTEM_SETTINGS));
}
/* path */
g_hash_table_insert (connection_props,
NMD_CONNECTION_PROPS_PATH,
op_to_gvalue (nm_connection_get_path (connection)));
} else {
connection_hash = g_hash_table_new (g_direct_hash, g_direct_equal);
connection_props = g_hash_table_new (g_direct_hash, g_direct_equal);
}
device_props = g_hash_table_new_full (g_str_hash, g_str_equal,
NULL, nm_gvalue_destroy);
/* Hostname actions do not require a device */
if (strcmp (action, "hostname")) {
/* interface */
g_hash_table_insert (device_props, NMD_DEVICE_PROPS_INTERFACE,
str_to_gvalue (nm_device_get_iface (device)));
/* IP interface */
if (vpn_iface) {
g_hash_table_insert (device_props, NMD_DEVICE_PROPS_IP_INTERFACE,
str_to_gvalue (vpn_iface));
} else if (nm_device_get_ip_iface (device)) {
g_hash_table_insert (device_props, NMD_DEVICE_PROPS_IP_INTERFACE,
str_to_gvalue (nm_device_get_ip_iface (device)));
}
/* type */
g_hash_table_insert (device_props, NMD_DEVICE_PROPS_TYPE,
uint_to_gvalue (nm_device_get_device_type (device)));
/* state */
g_hash_table_insert (device_props, NMD_DEVICE_PROPS_STATE,
uint_to_gvalue (nm_device_get_state (device)));
g_hash_table_insert (device_props, NMD_DEVICE_PROPS_PATH,
op_to_gvalue (nm_device_get_udi (device)));
}
dbus_g_proxy_call_no_reply (proxy, "Action",
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,
G_TYPE_INVALID);
g_object_unref (proxy);
g_hash_table_destroy (connection_hash);
g_hash_table_destroy (connection_props);
g_hash_table_destroy (device_props);
g_object_unref (dbus_mgr);
}