diff options
author | Dan Williams <dcbw@redhat.com> | 2008-04-08 02:58:02 +0000 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2008-04-08 02:58:02 +0000 |
commit | 54aac18883227be866fc6fdfbc58a2bb0cfd3add (patch) | |
tree | 7a15fc0565e174ee400580323cc3d7d36b28acd2 /src/backends | |
parent | d773c8986ad8d20a8a52a50f35db6b0634985c3b (diff) | |
download | NetworkManager-54aac18883227be866fc6fdfbc58a2bb0cfd3add.tar.gz |
2008-04-07 Dan Williams <dcbw@redhat.com>
* include/NetworkManager.h
- Remove the DOWN and CANCELLED device states
- Add UNMANAGED and UNAVAILABLE device states
- Document the device states
* introspection/nm-device.xml
src/nm-device-interface.c
src/nm-device-interface.h
- Add the 'managed' property
* test/nm-tool.c
- (detail_device): print out device state
* src/NetworkManagerSystem.h
src/backends/NetworkManagerArch.c
src/backends/NetworkManagerDebian.c
src/backends/NetworkManagerFrugalware.c
src/backends/NetworkManagerGentoo.c
src/backends/NetworkManagerMandriva.c
src/backends/NetworkManagerPaldo.c
src/backends/NetworkManagerRedHat.c
src/backends/NetworkManagerSlackware.c
src/backends/NetworkManagerSuSE.c
- (nm_system_device_get_system_config, nm_system_device_get_disabled
nm_system_device_free_system_config): remove; they were unused and
their functionality should be re-implemented in each distro's
system settings service plugin
* src/nm-gsm-device.c
src/nm-gsm-device.h
src/nm-cdma-device.c
src/nm-cdma-device.h
- (*_new): take the 'managed' argument
* src/nm-device.c
- (nm_device_set_address): remove, fold into nm_device_bring_up()
- (nm_device_init): start in unmanaged state, not disconnected
- (constructor): don't start device until the system settings service
has had a chance to figure out if the device is managed or not
- (nm_device_deactivate, nm_device_bring_up, nm_device_bring_down):
don't set device state here, let callers handle that as appropriate
- (nm_device_dispose): don't touch the device if it's not managed
- (set_property, get_property, nm_device_class_init): implement the
'managed' property
- (nm_device_state_changed): bring the device up if its now managed,
and deactivate it if it used to be active
- (nm_device_get_managed, nm_device_set_managed): do the right thing
with the managed state
* src/nm-hal-manager.c
- (wired_device_creator, wireless_device_creator, modem_device_creator):
take initial managed state and pass it along to device constructors
- (create_device_and_add_to_list): get managed state and pass to
type creators
* src/nm-device-802-11-wireless.c
- (real_can_activate): fold in most of
nm_device_802_11_wireless_can_activate()
- (can_scan): can't scan in UNAVAILABLE or UNMANAGED
- (link_timeout_cb): instead of deactivating, change device state and
let the device state handler to it
- (real_update_hw_address): clean up
- (state_changed_cb): when entering UNAVAILABLE state, schedule an idle
handler to transition to DISCONNECTED if the device isn't rfkilled
* src/nm-device-802-3-ethernet.c
- (set_carrier): move above callers and get rid of prototype
- (device_state_changed): when entering UNAVAILABLE state, schedule an
idle handler to transition to DISCONNECTED if the device has a
carrier
- (real_update_hw_address): clean up
- (link_timeout_cb, ppp_state_changed): change state instead of calling
deactivation directly as deactivation doesn't change state anymore
* src/NetworkManagerPolicy.c
- (schedule_activate_check): yay, remove wireless_enabled hack since
the NMManager and wireless devices work that out themselves now
- (device_state_changed): change to a switch and update for new device
states
- (device_carrier_changed): remove; device handles this now through
state changes
- (device_added): don't care about carrier any more; the initial
activation check will happen when the device transitions to
DISCONNECTED
* src/nm-manager.c
- (dispose): clear unmanaged devices
- (handle_unmanaged_devices): update unmanaged device list and toggle
the managed property on each device when needed
- (system_settings_properties_changed_cb): handle signals from the
system settings service
- (system_settings_get_unmanaged_devices_cb): handle callback from
getting the unmanaged device list method call
- (query_unmanaged_devices): ask the system settings service for its
list of unmanaged devices
- (nm_manager_name_owner_changed, initial_get_connections): get unmanaged
devices
- (manager_set_wireless_enabled): push rfkill state down to wireless
devices directly and let them handle the necessary state transitions
- (manager_device_state_changed): update for new device states
- (nm_manager_add_device): set initial rfkill state on wireless devices
- (nm_manager_remove_device): don't touch the device if it's unmanaged
- (nm_manager_activate_connection): return error if the device is
unmanaged
- (nm_manager_sleep): handle new device states correctly; don't change
the state of unavailable/unmanaged devices
* libnm-glib/nm-device-802-11-wireless.c
- (state_changed_cb): update for new device states
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3540 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
Diffstat (limited to 'src/backends')
-rw-r--r-- | src/backends/NetworkManagerArch.c | 137 | ||||
-rw-r--r-- | src/backends/NetworkManagerDebian.c | 133 | ||||
-rw-r--r-- | src/backends/NetworkManagerFrugalware.c | 161 | ||||
-rw-r--r-- | src/backends/NetworkManagerGentoo.c | 177 | ||||
-rw-r--r-- | src/backends/NetworkManagerMandriva.c | 233 | ||||
-rw-r--r-- | src/backends/NetworkManagerPaldo.c | 240 | ||||
-rw-r--r-- | src/backends/NetworkManagerRedHat.c | 232 | ||||
-rw-r--r-- | src/backends/NetworkManagerSlackware.c | 30 | ||||
-rw-r--r-- | src/backends/NetworkManagerSuSE.c | 280 |
9 files changed, 0 insertions, 1623 deletions
diff --git a/src/backends/NetworkManagerArch.c b/src/backends/NetworkManagerArch.c index f61bf104e4..4c94e9fe8f 100644 --- a/src/backends/NetworkManagerArch.c +++ b/src/backends/NetworkManagerArch.c @@ -491,143 +491,6 @@ static GHashTable * ArchReadConfig(const char* file, const char* dev) return ifs; } - -typedef struct ArchSystemConfigData -{ - NMIP4Config * config; - gboolean use_dhcp; -} ArchSystemConfigData; - - - -/* - * nm_system_device_get_system_config - * - * Retrieve any relevant configuration info for a particular device - * from the system network configuration information. Clear out existing - * info before setting stuff too. - * - */ -void* nm_system_device_get_system_config (NMDevice * dev) -{ - - GHashTable* ifh; - gpointer val; - ArchSystemConfigData* sys_data=NULL; - - g_return_val_if_fail (dev != NULL, NULL); - - sys_data = g_malloc0 (sizeof (ArchSystemConfigData)); - sys_data->use_dhcp = TRUE; - sys_data->config=NULL; - - ifh=ArchReadConfig("/etc/rc.conf",nm_device_get_iface(dev)); - if (ifh==NULL) - { - g_free(sys_data); - return NULL; - } - val=g_hash_table_lookup(ifh,nm_device_get_iface(dev)); - if (val && !g_hash_table_lookup(ifh, "dhcp")) - { - /* This device does not use DHCP */ - - sys_data->use_dhcp=FALSE; - sys_data->config = nm_ip4_config_new(); - - nm_ip4_config_set_address (sys_data->config, inet_addr (val)); - - val = g_hash_table_lookup(ifh, "gateway"); - if (val) - nm_ip4_config_set_gateway (sys_data->config, inet_addr (val)); - - val = g_hash_table_lookup(ifh, "netmask"); - if (val) - nm_ip4_config_set_netmask (sys_data->config, inet_addr (val)); - else - { - guint32 addr = nm_ip4_config_get_address (sys_data->config); - - /* Make a default netmask if we have an IP address */ - if (((ntohl (addr) & 0xFF000000) >> 24) <= 127) - nm_ip4_config_set_netmask (sys_data->config, htonl (0xFF000000)); - else if (((ntohl (addr) & 0xFF000000) >> 24) <= 191) - nm_ip4_config_set_netmask (sys_data->config, htonl (0xFFFF0000)); - else - nm_ip4_config_set_netmask (sys_data->config, htonl (0xFFFFFF00)); - } - - val = g_hash_table_lookup(ifh, "broadcast"); - if (val) - nm_ip4_config_set_broadcast (sys_data->config, inet_addr (val)); - else - { - guint32 broadcast = ((nm_ip4_config_get_address (sys_data->config) & nm_ip4_config_get_netmask (sys_data->config)) - | ~nm_ip4_config_get_netmask (sys_data->config)); - nm_ip4_config_set_broadcast (sys_data->config, broadcast); - } - - nm_generic_set_ip4_config_from_resolv_conf (SYSCONFDIR"/resolv.conf", sys_data->config); -#if 0 - { - int j; - nm_debug ("------ Config (%s)", nm_device_get_iface (dev)); - nm_debug (" ADDR=%d", nm_ip4_config_get_address (sys_data->config)); - nm_debug (" GW =%d", nm_ip4_config_get_gateway (sys_data->config)); - nm_debug (" NM =%d", nm_ip4_config_get_netmask (sys_data->config)); - nm_debug (" NSs =%d",nm_ip4_config_get_num_nameservers(sys_data->config)); - for (j=0;j<nm_ip4_config_get_num_nameservers(sys_data->config);j++) - { - nm_debug (" NS =%d",nm_ip4_config_get_nameserver(sys_data->config,j)); - } - nm_debug ("---------------------\n"); - } -#endif - - } - - g_hash_table_destroy(ifh); - - - return (void *)sys_data; -} - -/* - * nm_system_device_free_system_config - * - * Free stored system config data - * - */ -void nm_system_device_free_system_config (NMDevice *dev, void *system_config_data) -{ - ArchSystemConfigData *sys_data = (ArchSystemConfigData*) system_config_data; - - g_return_if_fail (dev != NULL); - - if (!sys_data) - { - return; - } - - if (sys_data->config) - g_object_unref (sys_data->config); - - -} - - -/* - * nm_system_device_get_disabled - * - * Return whether the distro-specific system config tells us to use - * dhcp for this device. - * - */ -gboolean nm_system_device_get_disabled (NMDevice *dev) -{ - return FALSE; -} - /* * nm_system_activate_nis * diff --git a/src/backends/NetworkManagerDebian.c b/src/backends/NetworkManagerDebian.c index 780f6dfd48..5f61ffabc0 100644 --- a/src/backends/NetworkManagerDebian.c +++ b/src/backends/NetworkManagerDebian.c @@ -214,139 +214,6 @@ void nm_system_device_add_ip6_link_address (NMDevice *dev) nm_generic_device_add_ip6_link_address (dev); } -typedef struct DebSystemConfigData -{ - NMIP4Config * config; - gboolean use_dhcp; -} DebSystemConfigData; - -/* - * nm_system_device_get_system_config - * - * Retrieve any relevant configuration info for a particular device - * from the system network configuration information. Clear out existing - * info before setting stuff too. - * - */ -void* nm_system_device_get_system_config (NMDevice *dev) -{ - DebSystemConfigData * sys_data = NULL; - if_block *curr_device; - const char *buf; - gboolean error = FALSE; - - g_return_val_if_fail (dev != NULL, NULL); - - sys_data = g_malloc0 (sizeof (DebSystemConfigData)); - sys_data->use_dhcp = TRUE; - - ifparser_init(); - - /* Make sure this config file is for this device */ - curr_device = ifparser_getif(nm_device_get_iface (dev)); - if (curr_device == NULL) - goto out; - - buf = ifparser_getkey(curr_device, "inet"); - if (buf) - { - if (strcmp (buf, "dhcp")!=0) - sys_data->use_dhcp = FALSE; - } - - sys_data->config = nm_ip4_config_new (); - - buf = ifparser_getkey (curr_device, "address"); - if (buf) - nm_ip4_config_set_address (sys_data->config, inet_addr (buf)); - - buf = ifparser_getkey (curr_device, "gateway"); - if (buf) - nm_ip4_config_set_gateway (sys_data->config, inet_addr (buf)); - - buf = ifparser_getkey (curr_device, "netmask"); - if (buf) - nm_ip4_config_set_netmask (sys_data->config, inet_addr (buf)); - else - { - guint32 addr = nm_ip4_config_get_address (sys_data->config); - - /* Make a default netmask if we have an IP address */ - if (((ntohl (addr) & 0xFF000000) >> 24) <= 127) - nm_ip4_config_set_netmask (sys_data->config, htonl (0xFF000000)); - else if (((ntohl (addr) & 0xFF000000) >> 24) <= 191) - nm_ip4_config_set_netmask (sys_data->config, htonl (0xFFFF0000)); - else - nm_ip4_config_set_netmask (sys_data->config, htonl (0xFFFFFF00)); - } - - buf = ifparser_getkey (curr_device, "broadcast"); - if (buf) - nm_ip4_config_set_broadcast (sys_data->config, inet_addr (buf)); - else - { - guint32 broadcast = ((nm_ip4_config_get_address (sys_data->config) & nm_ip4_config_get_netmask (sys_data->config)) - | ~nm_ip4_config_get_netmask (sys_data->config)); - nm_ip4_config_set_broadcast (sys_data->config, broadcast); - } - - if (!sys_data->use_dhcp) - nm_generic_set_ip4_config_from_resolv_conf (SYSCONFDIR"/resolv.conf", sys_data->config); - -#if 0 - nm_debug ("------ Config (%s)", nm_device_get_iface (dev)); - nm_debug (" DHCP=%s\n", sys_data->use_dhcp); - nm_debug (" ADDR=%d\n", nm_ip4_config_get_address (sys_data->config)); - nm_debug (" GW=%d\n", nm_ip4_config_get_gateway (sys_data->config)); - nm_debug (" NM=%d\n", nm_ip4_config_get_netmask (sys_data->config)); - nm_debug ("---------------------\n"); -#endif - -out: - ifparser_destroy(); - if (error) - { - sys_data->use_dhcp = TRUE; - /* Clear out the config */ - g_object_unref (sys_data->config); - sys_data->config = NULL; - } - - return (void *)sys_data; -} - -/* - * nm_system_device_free_system_config - * - * Free stored system config data - * - */ -void nm_system_device_free_system_config (NMDevice *dev, void *system_config_data) -{ - DebSystemConfigData *sys_data = (DebSystemConfigData *)system_config_data; - - g_return_if_fail (dev != NULL); - - if (!sys_data) - return; - - if (sys_data->config) - g_object_unref (sys_data->config); -} - - -/* - * nm_system_device_get_disabled - * - * Return whether the distro-specific system config tells us to use - * dhcp for this device. - * - */ -gboolean nm_system_device_get_disabled (NMDevice *dev) -{ - return FALSE; -} - /* * nm_system_activate_nis * diff --git a/src/backends/NetworkManagerFrugalware.c b/src/backends/NetworkManagerFrugalware.c index d7c97ac09b..95847ceb3b 100644 --- a/src/backends/NetworkManagerFrugalware.c +++ b/src/backends/NetworkManagerFrugalware.c @@ -40,12 +40,6 @@ // Provided by the frugalwareutils package on Frugalware #include <libfwnetconfig.h> -typedef struct FWDeviceConfigData -{ - NMIP4Config * config; - gboolean use_dhcp; -} FWDeviceConfigData; - /* * nm_system_init * @@ -274,37 +268,6 @@ void nm_system_flush_arp_cache (void) nm_spawn_process ("/usr/sbin/ip neigh flush all"); } -void nm_system_device_free_system_config (NMDevice *dev, void *system_config_data) -{ -} - -/* - * get_current_profile_name - * - * Retrieve the current network profile, if any - * - */ -static char *get_current_profile_name (void) -{ - char * buf; - - buf = fwnet_lastprofile(); - return buf; -} - -/* - * nm_system_device_get_disabled - * - * Return whether the distro-specific system config tells us to use - * dhcp for this device. - * - */ -gboolean nm_system_device_get_disabled (NMDevice *dev) -{ - return FALSE; -} - - /* * nm_system_activate_nis * @@ -345,127 +308,3 @@ gboolean nm_system_should_modify_resolv_conf (void) return TRUE; } - -/* - * nm_system_device_get_system_config - * - * Read in the config file for a device. - * - */ -void *nm_system_device_get_system_config (NMDevice *dev) -{ - fwnet_profile_t *profile; - fwnet_interface_t *interface; - FWDeviceConfigData *sys_data = NULL; - int dhcp, i; - char *data = NULL; - gboolean error = FALSE; - char ip[15]; - char netmask[15]; - char mybroadcast[15]; - int ret; - - sys_data = g_malloc0 (sizeof (FWDeviceConfigData)); - sys_data->use_dhcp = TRUE; - - profile = fwnet_parseprofile(get_current_profile_name()); - - for (i=0; i<g_list_length(profile->interfaces); i++) - { - interface = g_list_nth_data(profile->interfaces, i); - if(!strcmp(interface->name, nm_device_get_iface (dev))) - break; - interface = NULL; - } - - if (!interface) - return NULL; - - dhcp = fwnet_is_dhcp(interface); - - if (!dhcp) - sys_data->use_dhcp = FALSE; - else - goto out; - - sys_data->config = nm_ip4_config_new (); - - if (!(sys_data->use_dhcp)) - { - data = g_list_nth_data(interface->options, 0); - - ret = sscanf(data, "%s netmask %s broadcast %s", ip, netmask, mybroadcast); - - if (ret >= 1) - { - nm_ip4_config_set_address (sys_data->config, inet_addr (ip)); - } - else - { - nm_warning ("Network configuration for device '%s' was invalid (non-DHCP configuration, " - "but could not split options. Will use DHCP instead.", nm_device_get_iface (dev)); - error = TRUE; - goto out; - } - - if (ret >= 2) - { - nm_ip4_config_set_netmask (sys_data->config, inet_addr (netmask)); - } - else - { - guint32 addr = nm_ip4_config_get_address (sys_data->config); - - /* Make a default netmask if we have an IP address */ - if (((ntohl (addr) & 0xFF000000) >> 24) <= 127) - nm_ip4_config_set_netmask (sys_data->config, htonl (0xFF000000)); - else if (((ntohl (addr) & 0xFF000000) >> 24) <= 191) - nm_ip4_config_set_netmask (sys_data->config, htonl (0xFFFF0000)); - else - nm_ip4_config_set_netmask (sys_data->config, htonl (0xFFFFFF00)); - } - - if (ret >= 3) - { - nm_ip4_config_set_broadcast (sys_data->config, inet_addr (mybroadcast)); - } - else - { - guint32 broadcast = ((nm_ip4_config_get_address (sys_data->config) & nm_ip4_config_get_netmask (sys_data->config)) - | ~nm_ip4_config_get_netmask (sys_data->config)); - nm_ip4_config_set_broadcast (sys_data->config, broadcast); - } - - if (interface->gateway != NULL) - { - nm_ip4_config_set_gateway (sys_data->config, inet_addr (interface->gateway)); - } - else - { - nm_warning ("Network configuration for device '%s' was invalid (non-DHCP configuration, " - "but no gateway specified. Will use DHCP instead.", nm_device_get_iface (dev)); - error = TRUE; - goto out; - } - } - -#if 0 - nm_debug ("------ Config (%s)", nm_device_get_iface (dev)); - nm_debug (" DHCP=%d\n", sys_data->use_dhcp); - nm_debug (" ADDR=%d\n", nm_ip4_config_get_address (sys_data->config)); - nm_debug (" GW=%d\n", nm_ip4_config_get_gateway (sys_data->config)); - nm_debug (" NM=%d\n", nm_ip4_config_get_netmask (sys_data->config)); - nm_debug ("---------------------\n"); -#endif - -out: - if (error) - { - sys_data->use_dhcp = TRUE; - /* Clear out the config */ - g_object_unref (sys_data->config); - sys_data->config = NULL; - } - - return (void *)sys_data; -} diff --git a/src/backends/NetworkManagerGentoo.c b/src/backends/NetworkManagerGentoo.c index 1afa59f169..b72cc16a6e 100644 --- a/src/backends/NetworkManagerGentoo.c +++ b/src/backends/NetworkManagerGentoo.c @@ -243,157 +243,6 @@ void nm_system_device_add_ip6_link_address (NMDevice *dev) nm_generic_device_add_ip6_link_address (dev); } -typedef struct GentooSystemConfigData -{ - NMIP4Config * config; - gboolean use_dhcp; -} GentooSystemConfigData; - - -/* - * nm_system_device_get_system_config - * - * Retrieve any relevant configuration info for a particular device - * from the system network configuration information. Clear out existing - * info before setting stuff too. - * - */ -void *nm_system_device_get_system_config (NMDevice *dev) -{ - char *cfg_file_path = NULL; - FILE *file = NULL; - char buffer[100]; - char confline[100], dhcpline[100], ipline[100]; - int ipa, ipb, ipc, ipd; - int nNext = 0, bNext = 0, count = 0; - char *confToken; - gboolean data_good = FALSE; - gboolean use_dhcp = TRUE; - GentooSystemConfigData *sys_data = NULL; - guint32 ip4_address = 0; - guint32 ip4_netmask = 0; - guint32 ip4_gateway = 0; - guint32 ip4_broadcast = 0; - - g_return_val_if_fail (dev != NULL, NULL); - - sys_data = g_malloc0 (sizeof (GentooSystemConfigData)); - sys_data->config = nm_device_get_ip4_config(dev); - /* We use DHCP on an interface unless told not to */ - sys_data->use_dhcp = TRUE; - nm_device_set_use_dhcp (dev, TRUE); -// nm_ip4_config_set_address (sys_data->config, 0); -// nm_ip4_config_set_gateway (sys_data->config, 0); -// nm_ip4_config_set_netmask (sys_data->config, 0); - - /* Gentoo systems store this information in - * /etc/conf.d/net, this is for all interfaces. - */ - - cfg_file_path = g_strdup ("/etc/conf.d/net"); - if (!cfg_file_path) { - g_free (sys_data); - return NULL; - } - - if (!(file = fopen (cfg_file_path, "r"))) - { - g_free (cfg_file_path); - g_free (sys_data); - return NULL; - } - snprintf(confline, 100, "iface_%s", nm_device_get_iface (dev)); - snprintf(dhcpline, 100, "iface_%s=\"dhcp\"", nm_device_get_iface (dev)); - /* buffer is char[100], guess this fgets call was fairly wrong then? */ - while (fgets (buffer, 100, file) && !feof (file)) - { - /* Kock off newline if any */ - g_strstrip (buffer); - - if (strncmp (buffer, confline, strlen(confline)) == 0) - { - /* Make sure this config file is for this device */ - if (strncmp (&buffer[strlen(confline) - strlen(nm_device_get_iface (dev))], - nm_device_get_iface (dev), strlen(nm_device_get_iface (dev))) != 0) - { - nm_warning ("System config file '%s' does not define device '%s'\n", - cfg_file_path, nm_device_get_iface (dev)); - break; - } - else - data_good = TRUE; - - if (strncmp (buffer, dhcpline, strlen(dhcpline)) == 0) - { - use_dhcp = TRUE; - } - else - { - use_dhcp = FALSE; - confToken = strtok(&buffer[strlen(confline) + 2], " "); - while (count < 3) - { - if (nNext == 1 && bNext == 1) - { - ip4_address = inet_addr (confToken); - count++; - continue; - } - if (strcmp(confToken, "netmask") == 0) - { - confToken = strtok(NULL, " "); - ip4_netmask = inet_addr (confToken); - count++; - nNext = 1; - } - else if (strcmp(confToken, "broadcast") == 0) - { - confToken = strtok(NULL, " "); - count++; - bNext = 1; - } - else - { - ip4_address = inet_addr (confToken); - count++; - } - confToken = strtok(NULL, " "); - } - } - } - /* If we aren't using dhcp, then try to get the gateway */ - if (!use_dhcp) - { - snprintf(ipline, 100, "gateway=\"%s/", nm_device_get_iface (dev)); - if (strncmp(buffer, ipline, strlen(ipline) - 1) == 0) - { - snprintf(ipline, 100, "gateway=\"%s/%%d.%%d.%%d.%%d\"", nm_device_get_iface (dev) ); - sscanf(buffer, ipline, &ipa, &ipb, &ipc, &ipd); - snprintf(ipline, 100, "%d.%d.%d.%d", ipa, ipb, ipc, ipd); - ip4_gateway = inet_addr (ipline); - } - } - } - fclose (file); - g_free (cfg_file_path); - - /* If successful, set values on the device */ - if (data_good) - { - nm_warning("data good :-)"); - nm_device_set_use_dhcp (dev, use_dhcp); - if (ip4_address) - nm_ip4_config_set_address (sys_data->config, ip4_address); - if (ip4_gateway) - nm_ip4_config_set_gateway (sys_data->config, ip4_gateway); - if (ip4_netmask) - nm_ip4_config_set_netmask (sys_data->config, ip4_netmask); - if (ip4_broadcast) - nm_ip4_config_set_broadcast (sys_data->config, ip4_broadcast); - } - return (void *)sys_data; -} - /* * nm_system_device_replace_default_route * @@ -408,32 +257,6 @@ nm_system_device_replace_default_route (const char *iface, nm_generic_device_replace_default_route (iface, gw, mss); } -void nm_system_device_free_system_config (NMDevice *dev, void *system_config_data) -{ - GentooSystemConfigData *sys_data = (GentooSystemConfigData *)system_config_data; - - g_return_if_fail (dev != NULL); - - g_return_if_fail(sys_data != NULL); - - if (sys_data->config) - g_object_unref (sys_data->config); - - g_free (sys_data); -} - -/* - * nm_system_device_get_disabled - * - * Return whether the distro-specific system config tells us to use - * dhcp for this device. - * - */ -gboolean nm_system_device_get_disabled (NMDevice *dev) -{ - return FALSE; -} - /* * nm_system_activate_nis * diff --git a/src/backends/NetworkManagerMandriva.c b/src/backends/NetworkManagerMandriva.c index ec9979d19e..62ae4715f7 100644 --- a/src/backends/NetworkManagerMandriva.c +++ b/src/backends/NetworkManagerMandriva.c @@ -265,239 +265,6 @@ void nm_system_device_add_ip6_link_address (NMDevice *dev) nm_generic_device_add_ip6_link_address (dev); } - -typedef struct MandrivaSystemConfigData -{ - NMIP4Config * config; - gboolean use_dhcp; - gboolean system_disabled; -} MandrivaSystemConfigData; - - -/* - * get_current_profile_name - * - * Retrieve the current network profile, if any - * - */ -static char *get_current_profile_name (void) -{ - shvarFile * file; - char * buf; - - if (!(file = svNewFile (SYSCONFDIR"/sysconfig/network"))) - return NULL; - - buf = svGetValue (file, "CURRENT_PROFILE"); - if (!buf) - buf = strdup ("default"); - svCloseFile (file); - - return buf; -} - - -/* - * nm_system_device_get_system_config - * - * Read in the config file for a device. - * - */ -void *nm_system_device_get_system_config (NMDevice *dev) -{ - char * cfg_file_path = NULL; - shvarFile * file; - char * buf = NULL; - MandrivaSystemConfigData * sys_data = NULL; - gboolean error = FALSE; - - g_return_val_if_fail (dev != NULL, NULL); - - /* Red Hat/Fedora Core systems store this information in - * /etc/sysconfig/network-scripts/ifcfg-* where * is the interface - * name. - */ - - sys_data = g_malloc0 (sizeof (MandrivaSystemConfigData)); - sys_data->use_dhcp = TRUE; - - cfg_file_path = g_strdup_printf (SYSCONFDIR"/sysconfig/network-scripts/ifcfg-%s", nm_device_get_iface (dev)); - if (!cfg_file_path) - return sys_data; - - if (!(file = svNewFile (cfg_file_path))) - { - g_free (cfg_file_path); - return sys_data; - } - g_free (cfg_file_path); - - /* Make sure this config file is for this device */ - buf = svGetValue (file, "DEVICE"); - if (!buf || strcmp (buf, nm_device_get_iface (dev))) - { - free (buf); - goto out; - } - - if ((buf = svGetValue (file, "BOOTPROTO"))) - { - if (strcasecmp (buf, "dhcp")) - sys_data->use_dhcp = FALSE; - free (buf); - } - - if ((buf = svGetValue (file, "NM_CONTROLLED"))) - { - nm_debug ("NM_CONTROLLED=%s", buf); - if (!strcasecmp (buf, "no")) - { - nm_info ("System configuration disables device %s", nm_device_get_iface (dev)); - sys_data->system_disabled = TRUE; - } - free (buf); - } - - sys_data->config = nm_ip4_config_new (); - - if (!(sys_data->use_dhcp)) - { - if ((buf = svGetValue (file, "IPADDR"))) - { - nm_ip4_config_set_address (sys_data->config, inet_addr (buf)); - free (buf); - } - else - { - nm_warning ("Network configuration for device '%s' was invalid (non-DHCP configuration, " - "but no IP address specified. Will use DHCP instead.", nm_device_get_iface (dev)); - error = TRUE; - goto out; - } - - if ((buf = svGetValue (file, "GATEWAY"))) - { - nm_ip4_config_set_gateway (sys_data->config, inet_addr (buf)); - free (buf); - } - else - { - nm_warning ("Network configuration for device '%s' was invalid (non-DHCP configuration, " - "but no gateway specified. Will use DHCP instead.", nm_device_get_iface (dev)); - error = TRUE; - goto out; - } - - if ((buf = svGetValue (file, "NETMASK"))) - { - nm_ip4_config_set_netmask (sys_data->config, inet_addr (buf)); - free (buf); - } - else - { - guint32 addr = nm_ip4_config_get_address (sys_data->config); - - /* Make a default netmask if we have an IP address */ - if (((ntohl (addr) & 0xFF000000) >> 24) <= 127) - nm_ip4_config_set_netmask (sys_data->config, htonl (0xFF000000)); - else if (((ntohl (addr) & 0xFF000000) >> 24) <= 191) - nm_ip4_config_set_netmask (sys_data->config, htonl (0xFFFF0000)); - else - nm_ip4_config_set_netmask (sys_data->config, htonl (0xFFFFFF00)); - } - - if ((buf = svGetValue (file, "BROADCAST"))) - { - nm_ip4_config_set_broadcast (sys_data->config, inet_addr (buf)); - free (buf); - } - else - { - guint32 broadcast = ((nm_ip4_config_get_address (sys_data->config) & nm_ip4_config_get_netmask (sys_data->config)) - | ~nm_ip4_config_get_netmask (sys_data->config)); - nm_ip4_config_set_broadcast (sys_data->config, broadcast); - } - } - - /* If we're using Static IP, grab DNS servers from the profile's config file */ - if (!sys_data->use_dhcp) - { - char * cur_profile_name = get_current_profile_name (); - - if (cur_profile_name) - { - char *filename = g_strdup_printf (SYSCONFDIR"/sysconfig/networking/profiles/%s/resolv.conf", cur_profile_name); - - nm_generic_set_ip4_config_from_resolv_conf (filename, sys_data->config); - g_free (filename); - g_free (cur_profile_name); - } - } - -#if 0 - nm_debug ("------ Config (%s)", nm_device_get_iface (dev)); - nm_debug (" DHCP=%d\n", sys_data->use_dhcp); - nm_debug (" ADDR=%d\n", nm_ip4_config_get_address (sys_data->config)); - nm_debug (" GW=%d\n", nm_ip4_config_get_gateway (sys_data->config)); - nm_debug (" NM=%d\n", nm_ip4_config_get_netmask (sys_data->config)); - nm_debug ("---------------------\n"); -#endif - -out: - svCloseFile (file); - - if (error) - { - sys_data->use_dhcp = TRUE; - /* Clear out the config */ - g_object_unref (sys_data->config); - sys_data->config = NULL; - } - - return (void *)sys_data; -} - - -/* - * nm_system_device_free_system_config - * - * Free stored system config data - * - */ -void nm_system_device_free_system_config (NMDevice *dev, void *system_config_data) -{ - MandrivaSystemConfigData *sys_data = (MandrivaSystemConfigData *)system_config_data; - - g_return_if_fail (dev != NULL); - - if (!sys_data) - return; - - if (sys_data->config) - g_object_unref (sys_data->config); -} - - -/* - * nm_system_device_get_disabled - * - * Return whether the distro-specific system config tells us to use - * dhcp for this device. - * - */ -gboolean nm_system_device_get_disabled (NMDevice *dev) -{ - MandrivaSystemConfigData *sys_data; - - g_return_val_if_fail (dev != NULL, FALSE); - - if ((sys_data = nm_device_get_system_config_data (dev))) - return sys_data->system_disabled; - - return FALSE; -} - - /* * nm_system_activate_nis * diff --git a/src/backends/NetworkManagerPaldo.c b/src/backends/NetworkManagerPaldo.c index 33ad87898e..1b8d2e9851 100644 --- a/src/backends/NetworkManagerPaldo.c +++ b/src/backends/NetworkManagerPaldo.c @@ -228,246 +228,6 @@ void nm_system_device_add_ip6_link_address (NMDevice *dev) nm_generic_device_add_ip6_link_address (dev); } - -typedef struct PaldoSystemConfigData -{ - NMIP4Config * config; - gboolean use_dhcp; - gboolean system_disabled; -} PaldoSystemConfigData; - -#define PALDO_NETDEVICE_CONFIG_DIR SYSCONFDIR "/network/devices" - -static GKeyFile *nm_system_device_get_netdevice_file (NMDevice *dev) -{ - GDir *dir; - GKeyFile *file; - const char *entry; - char *path; - char *file_udi; - - dir = g_dir_open (PALDO_NETDEVICE_CONFIG_DIR, 0, NULL); - if (dir == NULL) - return NULL; - - file = g_key_file_new (); - - for (entry = g_dir_read_name (dir); entry != NULL; entry = g_dir_read_name (dir)) - { - if (!g_str_has_suffix (entry, ".netdevice")) - continue; - - path = g_strdup_printf ("%s/%s", PALDO_NETDEVICE_CONFIG_DIR, entry); - if (!g_key_file_load_from_file (file, path, G_KEY_FILE_NONE, NULL)) - { - g_free (path); - continue; - } - g_free (path); - - file_udi = g_key_file_get_string (file, "Network Device", "UDI", NULL); - if (file_udi == NULL) - continue; - - if (strcmp (file_udi, nm_device_get_udi (dev)) != 0) { - g_free (file_udi); - continue; - } - - g_free (file_udi); - break; - } - - if (entry == NULL) - { - g_key_file_free (file); - file = NULL; - } - - g_dir_close (dir); - - return file; -} - -static NMIP4Config *netdevice_file_get_ip4_config (GKeyFile *file) -{ - NMIP4Config *ip4_config; - char **ipaddress_list; - char **ipaddress; - char *gateway; - char *value; - struct in_addr addr; - - ipaddress_list = g_key_file_get_string_list (file, "Network Device", "IPAddress", NULL, NULL); - if (ipaddress_list == NULL) - return NULL; - - ip4_config = nm_ip4_config_new (); - - for (ipaddress = ipaddress_list; *ipaddress != NULL; ipaddress++) - { - char *mask_slash, *mask_str; - int mask, hostmask; - - mask_slash = strchr (*ipaddress, '/'); - if (mask_slash == NULL) - continue; - - mask_str = mask_slash + 1; - if (*mask_str == '\0') - continue; - *mask_slash = '\0'; - - if (!inet_aton (*ipaddress, &addr)) - continue; - - mask = atoi (mask_str); - if (mask < 0 || mask > 32) - continue; - - hostmask = (1 << (32 - mask)) - 1; - nm_ip4_config_set_address (ip4_config, addr.s_addr); - nm_ip4_config_set_netmask (ip4_config, ~hostmask); - nm_ip4_config_set_broadcast (ip4_config, addr.s_addr | hostmask); - - break; - } - - g_strfreev (ipaddress_list); - - if (ipaddress == NULL) - { - g_object_unref (ip4_config); - return NULL; - } - - gateway = g_key_file_get_string (file, "Network Device", "Gateway", NULL); - if (gateway != NULL) - { - if (inet_aton (gateway, &addr)) - nm_ip4_config_set_gateway (ip4_config, addr.s_addr); - - g_free (gateway); - } - - ipaddress_list = g_key_file_get_string_list (file, "Network Device", "Nameserver", NULL, NULL); - if (ipaddress_list != NULL) - { - for (ipaddress = ipaddress_list; *ipaddress != NULL; ipaddress++) - { - if (!inet_aton (*ipaddress, &addr)) - continue; - - nm_ip4_config_add_nameserver (ip4_config, addr.s_addr); - } - - g_strfreev (ipaddress_list); - } - - value = g_key_file_get_string (file, "Network Device", "Domain", NULL); - if (value != NULL) - { - nm_ip4_config_add_domain (ip4_config, value); - g_free (value); - } - - value = g_key_file_get_string (file, "Network Device", "Hostname", NULL); - if (value != NULL) - { - nm_ip4_config_set_hostname (ip4_config, value); - g_free (value); - } - - return ip4_config; -} - -/* - * nm_system_device_get_system_config - * - * Read in the config file for a device. - * - */ -void *nm_system_device_get_system_config (NMDevice *dev) -{ - PaldoSystemConfigData *sys_data = NULL; - GKeyFile *file; - char *method; - GError *error = NULL; - gboolean value; - - g_return_val_if_fail (dev != NULL, NULL); - - sys_data = g_malloc0 (sizeof (PaldoSystemConfigData)); - sys_data->use_dhcp = TRUE; - - file = nm_system_device_get_netdevice_file (dev); - if (file == NULL) - return sys_data; - - method = g_key_file_get_string (file, "Network Device", "Method", NULL); - if (method != NULL && strcmp (method, "static") == 0) - { - sys_data->config = netdevice_file_get_ip4_config (file); - - /* only disable dhcp if valid config has been found */ - if (sys_data->config != NULL) - sys_data->use_dhcp = FALSE; - } - g_free (method); - - value = g_key_file_get_boolean (file, "Network Device", "Disabled", &error); - if (error == NULL) - sys_data->system_disabled = value; - g_clear_error (&error); - - g_key_file_free (file); - - /* FIXME: add /etc/network/networks/example.network files */ - - return (void *)sys_data; -} - - -/* - * nm_system_device_free_system_config - * - * Free stored system config data - * - */ -void nm_system_device_free_system_config (NMDevice *dev, void *system_config_data) -{ - PaldoSystemConfigData *sys_data = (PaldoSystemConfigData *)system_config_data; - - g_return_if_fail (dev != NULL); - - if (!sys_data) - return; - - if (sys_data->config) - g_object_unref (sys_data->config); -} - - -/* - * nm_system_device_get_disabled - * - * Return whether the distro-specific system config tells us to - * disable this device. - * - */ -gboolean nm_system_device_get_disabled (NMDevice *dev) -{ - PaldoSystemConfigData *sys_data; - - g_return_val_if_fail (dev != NULL, FALSE); - - if ((sys_data = nm_device_get_system_config_data (dev))) - return sys_data->system_disabled; - - return FALSE; -} - - /* * nm_system_activate_nis * diff --git a/src/backends/NetworkManagerRedHat.c b/src/backends/NetworkManagerRedHat.c index f29ee25c9b..a9cec5b4bb 100644 --- a/src/backends/NetworkManagerRedHat.c +++ b/src/backends/NetworkManagerRedHat.c @@ -252,238 +252,6 @@ void nm_system_device_add_ip6_link_address (NMDevice *dev) nm_generic_device_add_ip6_link_address (dev); } - -typedef struct RHSystemConfigData -{ - NMIP4Config * config; - gboolean use_dhcp; - gboolean system_disabled; -} RHSystemConfigData; - - -/* - * get_current_profile_name - * - * Retrieve the current network profile, if any - * - */ -static char *get_current_profile_name (void) -{ - shvarFile * file; - char * buf; - - if (!(file = svNewFile (SYSCONFDIR"/sysconfig/network"))) - return NULL; - - buf = svGetValue (file, "CURRENT_PROFILE"); - if (!buf) - buf = strdup ("default"); - svCloseFile (file); - - return buf; -} - - -/* - * nm_system_device_get_system_config - * - * Read in the config file for a device. - * - */ -void *nm_system_device_get_system_config (NMDevice *dev) -{ - char * cfg_file_path = NULL; - shvarFile * file; - char * buf = NULL; - RHSystemConfigData * sys_data = NULL; - gboolean error = FALSE; - - g_return_val_if_fail (dev != NULL, NULL); - - /* Red Hat/Fedora Core systems store this information in - * /etc/sysconfig/network-scripts/ifcfg-* where * is the interface - * name. - */ - - sys_data = g_malloc0 (sizeof (RHSystemConfigData)); - sys_data->use_dhcp = TRUE; - - cfg_file_path = g_strdup_printf (SYSCONFDIR"/sysconfig/network-scripts/ifcfg-%s", nm_device_get_iface (dev)); - if (!cfg_file_path) - return sys_data; - - if (!(file = svNewFile (cfg_file_path))) - { - g_free (cfg_file_path); - return sys_data; - } - g_free (cfg_file_path); - - /* Make sure this config file is for this device */ - buf = svGetValue (file, "DEVICE"); - if (!buf || strcmp (buf, nm_device_get_iface (dev))) - { - free (buf); - goto out; - } - - if ((buf = svGetValue (file, "BOOTPROTO"))) - { - if (strcasecmp (buf, "dhcp")) - sys_data->use_dhcp = FALSE; - free (buf); - } - - if ((buf = svGetValue (file, "NM_CONTROLLED"))) - { - nm_debug ("NM_CONTROLLED=%s", buf); - if (!strcasecmp (buf, "no")) - { - nm_info ("System configuration disables device %s", nm_device_get_iface (dev)); - sys_data->system_disabled = TRUE; - } - free (buf); - } - - sys_data->config = nm_ip4_config_new (); - - if (!(sys_data->use_dhcp)) - { - if ((buf = svGetValue (file, "IPADDR"))) - { - nm_ip4_config_set_address (sys_data->config, inet_addr (buf)); - free (buf); - } - else - { - nm_warning ("Network configuration for device '%s' was invalid (non-DHCP configuration, " - "but no IP address specified. Will use DHCP instead.", nm_device_get_iface (dev)); - error = TRUE; - goto out; - } - - if ((buf = svGetValue (file, "GATEWAY"))) - { - nm_ip4_config_set_gateway (sys_data->config, inet_addr (buf)); - free (buf); - } - else - { - nm_warning ("Network configuration for device '%s' was invalid (non-DHCP configuration, " - "but no gateway specified. Will use DHCP instead.", nm_device_get_iface (dev)); - error = TRUE; - goto out; - } - - if ((buf = svGetValue (file, "NETMASK"))) - { - nm_ip4_config_set_netmask (sys_data->config, inet_addr (buf)); - free (buf); - } - else - { - guint32 addr = nm_ip4_config_get_address (sys_data->config); - - /* Make a default netmask if we have an IP address */ - if (((ntohl (addr) & 0xFF000000) >> 24) <= 127) - nm_ip4_config_set_netmask (sys_data->config, htonl (0xFF000000)); - else if (((ntohl (addr) & 0xFF000000) >> 24) <= 191) - nm_ip4_config_set_netmask (sys_data->config, htonl (0xFFFF0000)); - else - nm_ip4_config_set_netmask (sys_data->config, htonl (0xFFFFFF00)); - } - - if ((buf = svGetValue (file, "BROADCAST"))) - { - nm_ip4_config_set_broadcast (sys_data->config, inet_addr (buf)); - free (buf); - } - else - { - guint32 broadcast = ((nm_ip4_config_get_address (sys_data->config) & nm_ip4_config_get_netmask (sys_data->config)) - | ~nm_ip4_config_get_netmask (sys_data->config)); - nm_ip4_config_set_broadcast (sys_data->config, broadcast); - } - } - - /* If we're using Static IP, grab DNS servers from the profile's config file */ - if (!sys_data->use_dhcp) - { - char * cur_profile_name = get_current_profile_name (); - - if (cur_profile_name) - { - char *filename = g_strdup_printf (SYSCONFDIR"/sysconfig/networking/profiles/%s/resolv.conf", cur_profile_name); - - nm_generic_set_ip4_config_from_resolv_conf (filename, sys_data->config); - g_free (filename); - g_free (cur_profile_name); - } - } - -#if 0 - nm_debug ("------ Config (%s)", nm_device_get_iface (dev)); - nm_debug (" DHCP=%d\n", sys_data->use_dhcp); - nm_debug (" ADDR=%d\n", nm_ip4_config_get_address (sys_data->config)); - nm_debug (" GW=%d\n", nm_ip4_config_get_gateway (sys_data->config)); - nm_debug (" NM=%d\n", nm_ip4_config_get_netmask (sys_data->config)); - nm_debug ("---------------------\n"); -#endif - -out: - svCloseFile (file); - - if (error) - { - sys_data->use_dhcp = TRUE; - /* Clear out the config */ - g_object_unref (sys_data->config); - sys_data->config = NULL; - } - - return (void *)sys_data; -} - - -/* - * nm_system_device_free_system_config - * - * Free stored system config data - * - */ -void nm_system_device_free_system_config (NMDevice *dev, void *system_config_data) -{ - RHSystemConfigData *sys_data = (RHSystemConfigData *)system_config_data; - - g_return_if_fail (dev != NULL); - - if (!sys_data) - return; - - if (sys_data->config) - g_object_unref (sys_data->config); -} - - -/* - * nm_system_device_get_disabled - * - * Return whether the distro-specific system config tells us to use - * dhcp for this device. - * - */ -gboolean nm_system_device_get_disabled (NMDevice *dev) -{ - RHSystemConfigData *sys_data; - - g_return_val_if_fail (dev != NULL, FALSE); - - if ((sys_data = nm_device_get_system_config_data (dev))) - return sys_data->system_disabled; - - return FALSE; -} - /* * nm_system_activate_nis * diff --git a/src/backends/NetworkManagerSlackware.c b/src/backends/NetworkManagerSlackware.c index beeb1e06fd..15a31012ad 100644 --- a/src/backends/NetworkManagerSlackware.c +++ b/src/backends/NetworkManagerSlackware.c @@ -99,19 +99,6 @@ void nm_system_device_flush_addresses_with_iface (const char *iface) } /* - * nm_system_device_get_system_config - * - * Retrieve any relevant configuration info for a particular device - * from the system network configuration information. Clear out existing - * info before setting stuff too. - * - */ -void *nm_system_device_get_system_config (NMDevice *dev) -{ - return NULL; -} - -/* * nm_system_device_has_active_routes * * Find out whether the specified device has any routes in the routing @@ -233,23 +220,6 @@ void nm_system_flush_arp_cache (void) nm_generic_flush_arp_cache (); } -void nm_system_device_free_system_config (NMDevice *dev, void *system_config_data) -{ -} - -/* - * nm_system_device_get_disabled - * - * Return whether the distro-specific system config tells us to use - * dhcp for this device. - * - */ -gboolean nm_system_device_get_disabled (NMDevice *dev) -{ - return FALSE; -} - - /* * nm_system_activate_nis * diff --git a/src/backends/NetworkManagerSuSE.c b/src/backends/NetworkManagerSuSE.c index 1ae0bbf1ab..30be3ba441 100644 --- a/src/backends/NetworkManagerSuSE.c +++ b/src/backends/NetworkManagerSuSE.c @@ -249,286 +249,6 @@ void nm_system_device_add_ip6_link_address (NMDevice *dev) nm_generic_device_add_ip6_link_address (dev); } - -typedef struct SuSEDeviceConfigData -{ - NMIP4Config * config; - gboolean use_dhcp; - gboolean system_disabled; - guint32 mtu; -} SuSEDeviceConfigData; - - -/* - * nm_system_device_get_system_config - * - * Read in the config file for a device. - * - * SuSE stores this information in /etc/sysconfig/network/ifcfg-*-<MAC address> - * - */ -void *nm_system_device_get_system_config (NMDevice *dev) -{ - char *cfg_file_path = NULL; - char mac[18]; - struct stat statbuf; - shvarFile *file; - char *buf = NULL; - SuSEDeviceConfigData *sys_data = NULL; - struct ether_addr hw_addr; - FILE *f = NULL; - char buffer[512]; - gboolean error = FALSE; - int i, len; - struct in_addr temp_addr; - char *ip_str; - - g_return_val_if_fail (dev != NULL, NULL); - - sys_data = g_malloc0 (sizeof (SuSEDeviceConfigData)); - sys_data->use_dhcp = TRUE; - - if (NM_IS_DEVICE_802_3_ETHERNET (dev)) - nm_device_802_3_ethernet_get_address (NM_DEVICE_802_3_ETHERNET (dev), &hw_addr); - else if (NM_IS_DEVICE_802_11_WIRELESS (dev)) - nm_device_802_11_wireless_get_address (NM_DEVICE_802_11_WIRELESS (dev), &hw_addr); - - sprintf (mac, "%02x:%02x:%02x:%02x:%02x:%02x", - hw_addr.ether_addr_octet[0], hw_addr.ether_addr_octet[1], - hw_addr.ether_addr_octet[2], hw_addr.ether_addr_octet[3], - hw_addr.ether_addr_octet[4], hw_addr.ether_addr_octet[5]); - cfg_file_path = g_strdup_printf (SYSCONFDIR"/sysconfig/network/ifcfg-eth-id-%s", mac); - if (!cfg_file_path) - return sys_data; - if (stat(cfg_file_path, &statbuf) == 0) - goto found; - - g_free(cfg_file_path); - cfg_file_path = g_strdup_printf (SYSCONFDIR"/sysconfig/network/ifcfg-wlan-id-%s", mac); - if (!cfg_file_path) - return sys_data; - if (stat(cfg_file_path, &statbuf) == 0) - goto found; - - g_free(cfg_file_path); - cfg_file_path = g_strdup_printf (SYSCONFDIR"/sysconfig/network/ifcfg-%s", nm_device_get_iface (dev)); - if (!cfg_file_path) - return sys_data; - if (stat(cfg_file_path, &statbuf) == 0) - goto found; - - g_free (cfg_file_path); - return sys_data; - -found: - nm_debug ("found config '%s' for interface '%s'", cfg_file_path, nm_device_get_iface (dev)); - if (!(file = svNewFile (cfg_file_path))) - { - g_free (cfg_file_path); - return sys_data; - } - g_free (cfg_file_path); - - if ((buf = svGetValue (file, "BOOTPROTO"))) - { - nm_debug ("BOOTPROTO=%s", buf); - if (strcasecmp (buf, "dhcp")) - sys_data->use_dhcp = FALSE; - free (buf); - } - - if ((buf = svGetValue (file, "NM_CONTROLLED"))) - { - nm_debug ("NM_CONTROLLED=%s", buf); - if (!strcasecmp (buf, "no")) - { - nm_info ("System configuration disables device %s", nm_device_get_iface (dev)); - sys_data->system_disabled = TRUE; - } - free (buf); - } - - if ((buf = svGetValue (file, "MTU"))) - { - guint32 mtu; - - errno = 0; - mtu = strtoul (buf, NULL, 10); - if (!errno && mtu > 500 && mtu < INT_MAX) - sys_data->mtu = mtu; - free (buf); - } - - sys_data->config = nm_ip4_config_new (); - - if (!sys_data->use_dhcp || sys_data->system_disabled) - { - buf = svGetValue (file, "IPADDR"); - if (buf) - { - struct in_addr ip; - int ret; - - ret = inet_aton (buf, &ip); - if (ret) - nm_ip4_config_set_address (sys_data->config, ip.s_addr); - else - error = TRUE; - free (buf); - } - else - error = TRUE; - - if (error) - { - nm_warning ("Network configuration for device '%s' was invalid: Non-DHCP configuration, " - "but no IP address specified. Will use DHCP instead.", nm_device_get_iface (dev)); - goto out; - } - - if ((buf = svGetValue (file, "NETMASK"))) - { - nm_ip4_config_set_netmask (sys_data->config, inet_addr (buf)); - free (buf); - } - else - { - guint32 ip4addr = nm_ip4_config_get_address (sys_data->config); - - /* Make a default netmask if we have an IP address */ - if (((ntohl (ip4addr) & 0xFF000000) >> 24) <= 127) - nm_ip4_config_set_netmask (sys_data->config, htonl (0xFF000000)); - else if (((ntohl (ip4addr) & 0xFF000000) >> 24) <= 191) - nm_ip4_config_set_netmask (sys_data->config, htonl (0xFFFF0000)); - else - nm_ip4_config_set_netmask (sys_data->config, htonl (0xFFFFFF00)); - } - - if ((buf = svGetValue (file, "BROADCAST"))) - { - nm_ip4_config_set_broadcast (sys_data->config, inet_addr (buf)); - free (buf); - } - else - { - guint32 broadcast = ((nm_ip4_config_get_address (sys_data->config) & nm_ip4_config_get_netmask (sys_data->config)) - | ~nm_ip4_config_get_netmask (sys_data->config)); - nm_ip4_config_set_broadcast (sys_data->config, broadcast); - } - - nm_ip4_config_set_mtu (sys_data->config, sys_data->mtu); - - buf = NULL; - if ((f = fopen (SYSCONFDIR"/sysconfig/network/routes", "r"))) - { - while (fgets (buffer, 512, f) && !feof (f)) - { - buf = strtok(buffer, " "); - if (strcmp(buf, "default") == 0) - { - buf = strtok(NULL, " "); - if (buf) - nm_ip4_config_set_gateway (sys_data->config, inet_addr (buf)); - break; - } - } - fclose (f); - } - if (!buf) - nm_info ("Network configuration for device '%s' does not specify a gateway but is " - "statically configured (non-DHCP).", nm_device_get_iface (dev)); - - nm_generic_set_ip4_config_from_resolv_conf (SYSCONFDIR"/resolv.conf", sys_data->config); - } - -out: - svCloseFile (file); - - if (error) - { - nm_debug ("error, enable dhcp"); - sys_data->use_dhcp = TRUE; - /* Clear out the config */ - g_object_unref (sys_data->config); - sys_data->config = NULL; - } - - nm_debug ("------ Config (%s)", nm_device_get_iface (dev)); - nm_debug ("dhcp=%u", sys_data->use_dhcp); - - temp_addr.s_addr = nm_ip4_config_get_address (sys_data->config); - ip_str = g_strdup (inet_ntoa (temp_addr)); - nm_debug ("addr=%s", ip_str); - g_free (ip_str); - - temp_addr.s_addr = nm_ip4_config_get_gateway (sys_data->config); - ip_str = g_strdup (inet_ntoa (temp_addr)); - nm_debug ("gw=%s", ip_str); - g_free (ip_str); - - temp_addr.s_addr = nm_ip4_config_get_netmask (sys_data->config); - ip_str = g_strdup (inet_ntoa (temp_addr)); - nm_debug ("mask=%s", ip_str); - g_free (ip_str); - - if (sys_data->mtu) - nm_debug ("mtu=%u", sys_data->mtu); - - len = nm_ip4_config_get_num_nameservers (sys_data->config); - for (i = 0; i < len; i++) - { - guint ns_addr = nm_ip4_config_get_nameserver (sys_data->config, i); - - temp_addr.s_addr = ns_addr; - ip_str = g_strdup (inet_ntoa (temp_addr)); - nm_debug ("ns_%u=%s", i, ip_str); - g_free (ip_str); - } - nm_debug ("---------------------\n"); - - return sys_data; -} - - -/* - * nm_system_device_free_system_config - * - * Free stored system config data - * - */ -void nm_system_device_free_system_config (NMDevice *dev, void *system_config_data) -{ - SuSEDeviceConfigData *sys_data = (SuSEDeviceConfigData *)system_config_data; - - g_return_if_fail (dev != NULL); - - if (!sys_data) - return; - - if (sys_data->config) - g_object_unref (sys_data->config); -} - - -/* - * nm_system_device_get_disabled - * - * Return whether the distribution has flagged this device as disabled. - * - */ -gboolean nm_system_device_get_disabled (NMDevice *dev) -{ - SuSEDeviceConfigData *sys_data; - - g_return_val_if_fail (dev != NULL, FALSE); - - if ((sys_data = nm_device_get_system_config_data (dev))) - return sys_data->system_disabled; - - return FALSE; -} - - /* * nm_system_activate_nis * |