On Mon, Jun 13, 2005 at 08:58:04PM +0200, Kay Sievers wrote: > On Wed, Jun 08, 2005 at 10:29:12PM -0400, Dan Williams wrote: > > > > > > On Thu, 9 Jun 2005, Kay Sievers wrote: > > > > > Hi, > > > here is a first rough cut on a SuSE backend for NetworkManager. I got it > > > running and it can successfully change over from wired to wireless. :) > > > It's only a one night hack, so don't expect too much. > > > > Great! Will apply shortly. > > > > > (The currently SuSE shipped D-BUS, can't authorize the on_console user. > > > So if anyone wants to try this, the policy-file needs to be to adapted. > > > We will add the missing stuff to D-BUS soon.) > > > > > > Btw: NM seems to read the config files for static setups, but static > > > configurations are not supported until now, or do I miss something? > > > > Correct, static configs have been supported for a while, but of course > > depend on > > reading the system's config files since NM doesn't have a configuration > > applet > > (which arguably it should not). Therefore, the user uses the normal system > > tools to configure static IP addresses, and NetworkManager picks those > > settings > > up from the config files. Backends should implement this functionality if > > they > > wish to support static IP. > > It does not work here and I can't see how: > NMDevice *dev->use_dhcp > can ever be FALSE in src/NetworkManagerDevice.c. > > Attached patch makes it following the parsed system config.
Better attach it. :) Kay
Index: src/NetworkManagerDevice.c =================================================================== RCS file: /cvs/gnome/NetworkManager/src/NetworkManagerDevice.c,v retrieving revision 1.136 diff -u -p -r1.136 NetworkManagerDevice.c --- src/NetworkManagerDevice.c 10 Jun 2005 03:47:47 -0000 1.136 +++ src/NetworkManagerDevice.c 13 Jun 2005 18:49:55 -0000 @@ -383,6 +383,7 @@ NMDevice *nm_device_new (const char *ifa /* Grab IP config data for this device from the system configuration files */ 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); Index: src/backends/NetworkManagerSuSE.c =================================================================== RCS file: /cvs/gnome/NetworkManager/src/backends/NetworkManagerSuSE.c,v retrieving revision 1.1 diff -u -p -r1.1 NetworkManagerSuSE.c --- src/backends/NetworkManagerSuSE.c 10 Jun 2005 03:43:15 -0000 1.1 +++ src/backends/NetworkManagerSuSE.c 13 Jun 2005 18:49:55 -0000 @@ -345,6 +345,82 @@ typedef struct 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 * * Read in the config file for a device. @@ -362,10 +438,13 @@ void *nm_system_device_get_system_config 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); - /* 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->use_dhcp = TRUE; @@ -411,6 +490,7 @@ found: if ((buf = svGetValue (file, "BOOTPROTO"))) { if (strcasecmp (buf, "dhcp")) + nm_debug ("method=%s, dhcp disabled", buf); sys_data->use_dhcp = FALSE; free (buf); } @@ -485,6 +565,8 @@ found: error = TRUE; goto out; } + + set_ip4_config_from_resolv_conf (SYSCONFDIR"/resolv.conf", sys_data->config); } out: @@ -492,6 +574,7 @@ out: if (error) { + nm_debug ("error, enable dhcp"); sys_data->use_dhcp = TRUE; /* Clear out the config */ nm_ip4_config_unref (sys_data->config); @@ -499,10 +582,33 @@ out: } nm_debug ("------ Config (%s)", nm_device_get_iface (dev)); - 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))); - nm_debug (" NM= 0x%08x", GUINT_FROM_BE(nm_ip4_config_get_netmask (sys_data->config))); + 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); + + 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 (void *)sys_data;
_______________________________________________ NetworkManager-list mailing list NetworkManager-list@gnome.org http://mail.gnome.org/mailman/listinfo/networkmanager-list