2005-06-15 Dan Williams <dcbw@redhat.com>
* src/backends/NetworkManagerDebian.c - Add nm_system_device_get_use_dhcp() to debian backend Patch from Kay Sievers: * src/backends/NetworkManagerSuSE.c - Update debian backend for static IP nameservers * src/NetworkManagerDevice.c - Actually set the device to use static IP or DHCP rather than always DHCP git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@671 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
13
ChangeLog
13
ChangeLog
@@ -1,3 +1,16 @@
|
|||||||
|
2005-06-15 Dan Williams <dcbw@redhat.com>
|
||||||
|
|
||||||
|
* src/backends/NetworkManagerDebian.c
|
||||||
|
- Add nm_system_device_get_use_dhcp() to debian backend
|
||||||
|
|
||||||
|
Patch from Kay Sievers:
|
||||||
|
* src/backends/NetworkManagerSuSE.c
|
||||||
|
- Update debian backend for static IP nameservers
|
||||||
|
|
||||||
|
* src/NetworkManagerDevice.c
|
||||||
|
- Actually set the device to use static IP or DHCP rather
|
||||||
|
than always DHCP
|
||||||
|
|
||||||
2005-06-15 Dan Williams <dcbw@redhat.com>
|
2005-06-15 Dan Williams <dcbw@redhat.com>
|
||||||
|
|
||||||
Patch from Thom May:
|
Patch from Thom May:
|
||||||
|
@@ -383,6 +383,7 @@ NMDevice *nm_device_new (const char *iface, const char *udi, gboolean test_dev,
|
|||||||
|
|
||||||
/* Grab IP config data for this device from the system configuration files */
|
/* Grab IP config data for this device from the system configuration files */
|
||||||
dev->system_config_data = nm_system_device_get_system_config (dev);
|
dev->system_config_data = nm_system_device_get_system_config (dev);
|
||||||
|
dev->use_dhcp = nm_system_device_get_use_dhcp (dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
dev->worker = g_thread_create (nm_device_worker, dev, TRUE, &error);
|
dev->worker = g_thread_create (nm_device_worker, dev, TRUE, &error);
|
||||||
|
@@ -608,6 +608,27 @@ void nm_system_device_free_system_config (NMDevice *dev, void *system_config_dat
|
|||||||
nm_ip4_config_unref (sys_data->config);
|
nm_ip4_config_unref (sys_data->config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nm_system_device_get_use_dhcp
|
||||||
|
*
|
||||||
|
* Return whether the distro-specific system config tells us to use
|
||||||
|
* dhcp for this device.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
gboolean nm_system_device_get_use_dhcp (NMDevice *dev)
|
||||||
|
{
|
||||||
|
DebSystemConfigData *sys_data;
|
||||||
|
|
||||||
|
g_return_val_if_fail (dev != NULL, TRUE);
|
||||||
|
|
||||||
|
if ((sys_data = nm_device_get_system_config_data (dev)))
|
||||||
|
return sys_data->use_dhcp;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
NMIP4Config *nm_system_device_new_ip4_system_config (NMDevice *dev)
|
NMIP4Config *nm_system_device_new_ip4_system_config (NMDevice *dev)
|
||||||
{
|
{
|
||||||
DebSystemConfigData *sys_data;
|
DebSystemConfigData *sys_data;
|
||||||
|
@@ -344,6 +344,82 @@ typedef struct SuSESystemConfigData
|
|||||||
gboolean use_dhcp;
|
gboolean use_dhcp;
|
||||||
} SuSESystemConfigData;
|
} SuSESystemConfigData;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* set_ip4_config_from_resolv_conf
|
||||||
|
*
|
||||||
|
* Add nameservers and search names from a resolv.conf format file.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static void set_ip4_config_from_resolv_conf (const char *filename, NMIP4Config *ip4_config)
|
||||||
|
{
|
||||||
|
char * contents = NULL;
|
||||||
|
char ** split_contents = NULL;
|
||||||
|
int i, len;
|
||||||
|
|
||||||
|
g_return_if_fail (filename != NULL);
|
||||||
|
g_return_if_fail (ip4_config != NULL);
|
||||||
|
|
||||||
|
if (!g_file_get_contents (filename, &contents, NULL, NULL) || (contents == NULL))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!(split_contents = g_strsplit (contents, "\n", 0)))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
len = g_strv_length (split_contents);
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
char *line = split_contents[i];
|
||||||
|
|
||||||
|
/* Ignore comments */
|
||||||
|
if (!line || (line[0] == ';'))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
line = g_strstrip (line);
|
||||||
|
if ((strncmp (line, "search", 6) == 0) && (strlen (line) > 6))
|
||||||
|
{
|
||||||
|
char *searches = g_strdup (line + 7);
|
||||||
|
char **split_searches = NULL;
|
||||||
|
|
||||||
|
if (!searches || !strlen (searches))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* Allow space-separated search domains */
|
||||||
|
if (split_searches == g_strsplit (searches, " ", 0))
|
||||||
|
{
|
||||||
|
int m, srch_len;
|
||||||
|
|
||||||
|
srch_len = g_strv_length (split_searches);
|
||||||
|
for (m = 0; m < srch_len; m++)
|
||||||
|
{
|
||||||
|
if (split_searches[m])
|
||||||
|
nm_ip4_config_add_domain (ip4_config, split_searches[m]);
|
||||||
|
}
|
||||||
|
g_strfreev (split_searches);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Only 1 item, add the whole line */
|
||||||
|
nm_ip4_config_add_domain (ip4_config, searches);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_free (searches);
|
||||||
|
}
|
||||||
|
else if ((strncmp (line, "nameserver", 10) == 0) && (strlen (line) > 10))
|
||||||
|
{
|
||||||
|
guint32 addr = (guint32) (inet_addr (line + 11));
|
||||||
|
|
||||||
|
if (addr != (guint32) -1)
|
||||||
|
nm_ip4_config_add_nameserver (ip4_config, addr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
g_strfreev (split_contents);
|
||||||
|
|
||||||
|
out:
|
||||||
|
g_free (contents);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nm_system_device_get_system_config
|
* nm_system_device_get_system_config
|
||||||
*
|
*
|
||||||
@@ -362,10 +438,13 @@ void *nm_system_device_get_system_config (NMDevice *dev)
|
|||||||
FILE *f = NULL;
|
FILE *f = NULL;
|
||||||
char buffer[512];
|
char buffer[512];
|
||||||
gboolean error = FALSE;
|
gboolean error = FALSE;
|
||||||
|
int i, len;
|
||||||
|
struct in_addr temp_addr;
|
||||||
|
char *ip_str;
|
||||||
|
|
||||||
g_return_val_if_fail (dev != NULL, NULL);
|
g_return_val_if_fail (dev != NULL, NULL);
|
||||||
|
|
||||||
/* SuSE store this information in /etc/sysconfig/network/ifcfg-<MAC address> */
|
/* SuSE stores this information usually in /etc/sysconfig/network/ifcfg-*-<MAC address> */
|
||||||
|
|
||||||
sys_data = g_malloc0 (sizeof (SuSESystemConfigData));
|
sys_data = g_malloc0 (sizeof (SuSESystemConfigData));
|
||||||
sys_data->use_dhcp = TRUE;
|
sys_data->use_dhcp = TRUE;
|
||||||
@@ -410,6 +489,7 @@ found:
|
|||||||
|
|
||||||
if ((buf = svGetValue (file, "BOOTPROTO")))
|
if ((buf = svGetValue (file, "BOOTPROTO")))
|
||||||
{
|
{
|
||||||
|
nm_debug ("BOOTPROTO=%s", buf);
|
||||||
if (strcasecmp (buf, "dhcp"))
|
if (strcasecmp (buf, "dhcp"))
|
||||||
sys_data->use_dhcp = FALSE;
|
sys_data->use_dhcp = FALSE;
|
||||||
free (buf);
|
free (buf);
|
||||||
@@ -485,6 +565,8 @@ found:
|
|||||||
error = TRUE;
|
error = TRUE;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_ip4_config_from_resolv_conf (SYSCONFDIR"/resolv.conf", sys_data->config);
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
@@ -492,6 +574,7 @@ out:
|
|||||||
|
|
||||||
if (error)
|
if (error)
|
||||||
{
|
{
|
||||||
|
nm_debug ("error, enable dhcp");
|
||||||
sys_data->use_dhcp = TRUE;
|
sys_data->use_dhcp = TRUE;
|
||||||
/* Clear out the config */
|
/* Clear out the config */
|
||||||
nm_ip4_config_unref (sys_data->config);
|
nm_ip4_config_unref (sys_data->config);
|
||||||
@@ -499,10 +582,33 @@ out:
|
|||||||
}
|
}
|
||||||
|
|
||||||
nm_debug ("------ Config (%s)", nm_device_get_iface (dev));
|
nm_debug ("------ Config (%s)", nm_device_get_iface (dev));
|
||||||
nm_debug (" DHCP=%u", sys_data->use_dhcp);
|
nm_debug ("dhcp=%u", sys_data->use_dhcp);
|
||||||
nm_debug (" ADDR=0x%08x", GUINT_FROM_BE(nm_ip4_config_get_address (sys_data->config)));
|
|
||||||
nm_debug (" GW= 0x%08x", GUINT_FROM_BE(nm_ip4_config_get_gateway (sys_data->config)));
|
temp_addr.s_addr = nm_ip4_config_get_address (sys_data->config);
|
||||||
nm_debug (" NM= 0x%08x", GUINT_FROM_BE(nm_ip4_config_get_netmask (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);
|
||||||
|
|
||||||
|
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");
|
nm_debug ("---------------------\n");
|
||||||
|
|
||||||
return (void *)sys_data;
|
return (void *)sys_data;
|
||||||
|
Reference in New Issue
Block a user