summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog28
-rw-r--r--TODO5
-rw-r--r--src/NetworkManagerDevice.c3
-rw-r--r--src/NetworkManagerUtils.c10
-rw-r--r--src/backends/NetworkManagerDebian.c28
-rw-r--r--src/backends/NetworkManagerGentoo.c29
-rw-r--r--src/backends/NetworkManagerRedHat.c201
-rw-r--r--src/backends/NetworkManagerSlackware.c15
-rw-r--r--src/backends/NetworkManagerSystem.h21
9 files changed, 280 insertions, 60 deletions
diff --git a/ChangeLog b/ChangeLog
index 190a0529d6..9b85af5914 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,31 @@
+2004-10-12 Dan Williams <dcbw@redhat.com>
+
+ * TODO
+ - Remove bit about static IP address support
+
+ * src/NetworkManagerUtils.c
+ - (nm_spawn_process): Add some error reporting
+
+ * src/NetworkManagerDevice.c
+ - (nm_device_activation_configure_ip): hook up to the static config
+ routines in the backends
+
+ * src/backends/NetworkManagerRedHat.c
+ - (nm_system_device_update_config_info): use shvar.c routines to
+ parse the config file iformation, not our own
+ - (nm_system_device_setup_static_ip4_config): new function, based
+ heavily on 'ifup' script and 'ipcalc' tool code. Set up a device
+ with a static IP address and gateway
+
+ * src/backends/shvar.[ch]
+ - Parser (filched from initscripts package) for ifcfg-* files
+
+ * src/backends/NetworkManagerSystem.h
+ src/backends/NetworkManagerGentoo.c
+ src/backends/NetworkManagerDebian.c
+ src/backends/NetworkManagerSlackware.c
+ - Stub nm_system_device_update_config_info() and nm_system_device_setup_static_ip4_config()
+
2004-10-11 Dan Williams <dcbw@redhat.com>
* TODO
diff --git a/TODO b/TODO
index 9bb3935550..3444853287 100644
--- a/TODO
+++ b/TODO
@@ -18,11 +18,6 @@ There is currently no logic to gracefully recover from a crashed/killed dbus or
Access points can be set not to broadcast their ESSIDs, which the client must know. These appear as blank ESSIDs to cards doing wireless scanning, even though the rest of the AP's information is known (channel, rate, etc). There has to be a way to deal with this as many companies do not broadcast ESSIDs for security measures. Workarounds for this practice could include brute-forcing the Allowed Networks list if no suitable wireless network is found to begin with. Obviously, there would be no way to detect if a WEP key was wrong, because unless the ESSID and WEP key are both correct, we cannot associate with the access point to see if we have a link. Code exists to do this for wireless cards that do not support wireless scanning, and this code could be adapted.
-- Support static IP addresses
-
-We need to support static IP addresses for interfaces. This should be done by parsing the normal /etc/sysconfig/network-scripts/ifcfg-* files.
-
-
- Store Allowed Network WEP keys in gnome-keyring
These keys should probably be encrypted, rather than being stored in GConf.
diff --git a/src/NetworkManagerDevice.c b/src/NetworkManagerDevice.c
index 48ade7308b..c2278ef58b 100644
--- a/src/NetworkManagerDevice.c
+++ b/src/NetworkManagerDevice.c
@@ -1386,8 +1386,7 @@ static gboolean nm_device_activation_configure_ip (NMDevice *dev)
else
{
/* Manually set up the device */
- /* FIXME: implement */
- syslog (LOG_ERR, "NetworkManager does not currently support static IP addresses\n");
+ success = nm_system_device_setup_static_ip4_config (dev);
}
return (success);
diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c
index fc46db32de..3ec84e5767 100644
--- a/src/NetworkManagerUtils.c
+++ b/src/NetworkManagerUtils.c
@@ -183,18 +183,26 @@ int nm_spawn_process (char *args)
gint num_args;
char **argv;
int exit_status;
+ GError *error = NULL;
g_return_val_if_fail (args != NULL, -1);
if (g_shell_parse_argv (args, &num_args, &argv, NULL))
{
- if (g_spawn_sync ("/", argv, NULL, 0, NULL, NULL, NULL, NULL, &exit_status, NULL))
+ if (g_spawn_sync ("/", argv, NULL, 0, NULL, NULL, NULL, NULL, &exit_status, &error))
{
g_strfreev (argv);
return (exit_status);
}
+ else
+ syslog (LOG_ERR, "nm_spawn_process('%s'): could not spawn process. (%s)\n", args, error->message);
+
g_strfreev (argv);
+ if (error)
+ g_error_free (error);
}
+ else
+ syslog (LOG_ERR, "nm_spawn_process('%s'): could not parse arguments (%s)\n", args, error->message);
return (-1);
}
diff --git a/src/backends/NetworkManagerDebian.c b/src/backends/NetworkManagerDebian.c
index 710a4f4c4d..2293189ec8 100644
--- a/src/backends/NetworkManagerDebian.c
+++ b/src/backends/NetworkManagerDebian.c
@@ -162,6 +162,34 @@ void nm_system_device_flush_addresses (NMDevice *dev)
/*
+ * nm_system_device_setup_static_ip4_config
+ *
+ * Set up the device with a particular IPv4 address/netmask/gateway.
+ *
+ * Returns: TRUE on success
+ * FALSE on error
+ *
+ */
+gboolean nm_system_device_setup_static_ip4_config (NMDevice *dev)
+{
+ syslog (LOG_WARN, "nm_system_device_setup_static_ip4_config() is not implemented yet for this distribution.\n");
+}
+
+
+/*
+ * nm_system_device_update_config_info
+ *
+ * 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_update_config_info (NMDevice *dev)
+{
+}
+
+
+/*
* nm_system_enable_loopback
*
* Bring up the loopback interface
diff --git a/src/backends/NetworkManagerGentoo.c b/src/backends/NetworkManagerGentoo.c
index 4ad0a42ad5..f3edfe5f15 100644
--- a/src/backends/NetworkManagerGentoo.c
+++ b/src/backends/NetworkManagerGentoo.c
@@ -169,6 +169,35 @@ void nm_system_device_flush_addresses (NMDevice *dev)
nm_spawn_process (buf);
}
+
+/*
+ * nm_system_device_setup_static_ip4_config
+ *
+ * Set up the device with a particular IPv4 address/netmask/gateway.
+ *
+ * Returns: TRUE on success
+ * FALSE on error
+ *
+ */
+gboolean nm_system_device_setup_static_ip4_config (NMDevice *dev)
+{
+ syslog (LOG_WARN, "nm_system_device_setup_static_ip4_config() is not implemented yet for this distribution.\n");
+}
+
+
+/*
+ * nm_system_device_update_config_info
+ *
+ * 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_update_config_info (NMDevice *dev)
+{
+}
+
+
/*
* nm_system_enable_loopback
*
diff --git a/src/backends/NetworkManagerRedHat.c b/src/backends/NetworkManagerRedHat.c
index 6e34b2c818..b52a1d1ef7 100644
--- a/src/backends/NetworkManagerRedHat.c
+++ b/src/backends/NetworkManagerRedHat.c
@@ -28,6 +28,13 @@
#include "NetworkManagerDevice.h"
+/* Hmm, not good form, but we don't have support
+ * for multiple files for each system-specific
+ * backend yet...
+ */
+#include "shvar.c"
+
+
/*
* nm_system_init
*
@@ -162,15 +169,90 @@ void nm_system_device_flush_addresses (NMDevice *dev)
/*
- * nm_system_device_setup_ip_config
+ * nm_system_device_setup_static_ip4_config
*
* Set up the device with a particular IPv4 address/netmask/gateway.
*
+ * Returns: TRUE on success
+ * FALSE on error
+ *
*/
-void nm_system_device_setup_ip4_config (NMDevice *dev)
+gboolean nm_system_device_setup_static_ip4_config (NMDevice *dev)
{
- g_return_if_fail (dev != NULL);
- g_return_if_fail (!nm_device_config_get_use_dhcp (dev));
+#define IPBITS (sizeof (guint32) * 8)
+ struct in_addr temp_addr;
+ struct in_addr temp_addr2;
+ char *s_tmp;
+ char *s_tmp2;
+ int i;
+ guint32 addr;
+ guint32 netmask;
+ guint32 prefix = IPBITS; /* initialize with # bits in ip4 address */
+ guint32 broadcast;
+ char *buf;
+ int err;
+ char *iface;
+
+ g_return_val_if_fail (dev != NULL, FALSE);
+ g_return_val_if_fail (!nm_device_config_get_use_dhcp (dev), FALSE);
+
+ addr = nm_device_config_get_ip4_address (dev);
+ netmask = nm_device_config_get_ip4_netmask (dev);
+ iface = nm_device_get_iface (dev);
+
+ /* Calculate the prefix (# bits stripped off by the netmask) */
+ for (i = 0; i < IPBITS; i++)
+ {
+ if (!(ntohl (netmask) & ((2 << i) - 1)))
+ prefix--;
+ }
+
+ /* Calculate the broadcast address */
+ broadcast = ((addr & (int)netmask) | ~(int)netmask);
+
+ /* FIXME: what if some other device is already using our IP address? */
+
+ /* Set our IP address */
+ temp_addr.s_addr = addr;
+ temp_addr2.s_addr = broadcast;
+ s_tmp = g_strdup (inet_ntoa (temp_addr));
+ s_tmp2 = g_strdup (inet_ntoa (temp_addr2));
+ buf = g_strdup_printf ("/sbin/ip addr add %s/%d brd %s dev %s label %s", s_tmp, prefix, s_tmp2, iface, iface);
+ g_free (s_tmp);
+ g_free (s_tmp2);
+ if ((err = nm_spawn_process (buf)))
+ {
+ syslog (LOG_ERR, "Error: could not set network configuration for device '%s' using command:\n '%s'", iface, buf);
+ goto error;
+ }
+ g_free (buf);
+
+ /* Alert other computers of our new address */
+ temp_addr.s_addr = addr;
+ buf = g_strdup_printf ("/sbin/arping -q -A -c 1 -I %s %s", iface, inet_ntoa (temp_addr));
+ nm_spawn_process (buf);
+ g_free (buf);
+ g_usleep (G_USEC_PER_SEC * 2);
+ buf = g_strdup_printf ("/sbin/arping -q -U -c 1 -I %s %s", iface, inet_ntoa (temp_addr));
+ nm_spawn_process (buf);
+ g_free (buf);
+
+ /* Set the default route to be this device's gateway */
+ temp_addr.s_addr = nm_device_config_get_ip4_gateway (dev);
+ buf = g_strdup_printf ("/sbin/ip route replace default via %s dev %s", inet_ntoa (temp_addr), iface);
+ if ((err = nm_spawn_process (buf)))
+ {
+ syslog (LOG_ERR, "Error: could not set default route using command\n '%s'", buf);
+ goto error;
+ }
+ g_free (buf);
+ return (TRUE);
+
+error:
+ g_free (buf);
+ nm_system_device_flush_addresses (dev);
+ nm_system_device_flush_routes (dev);
+ return (FALSE);
}
@@ -183,7 +265,7 @@ void nm_system_device_setup_ip4_config (NMDevice *dev)
void nm_system_enable_loopback (void)
{
nm_spawn_process ("/sbin/ip link set dev lo up");
- nm_spawn_process ("/sbin/ip addr add 127.0.0.1/8 brd 127.255.255.255 dev lo label loopback");
+ nm_spawn_process ("/sbin/ip addr add 127.0.0.1/8 brd 127.255.255.255 dev lo scope host label loopback");
}
@@ -249,9 +331,8 @@ void nm_system_load_device_modules (void)
void nm_system_device_update_config_info (NMDevice *dev)
{
char *cfg_file_path = NULL;
- FILE *file = NULL;
- char buffer[100];
- gboolean data_good = FALSE;
+ shvarFile *file;
+ char *buf = NULL;
gboolean use_dhcp = TRUE;
guint32 ip4_address = 0;
guint32 ip4_netmask = 0;
@@ -274,52 +355,88 @@ void nm_system_device_update_config_info (NMDevice *dev)
if (!cfg_file_path)
return;
- if (!(file = fopen (cfg_file_path, "r")))
+ if (!(file = svNewFile (cfg_file_path)))
{
g_free (cfg_file_path);
return;
}
+ 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;
+ }
+
+ buf = svGetValue (file, "BOOTPROTO");
+ if (buf)
+ {
+ if (strcmp (buf, "dhcp"))
+ use_dhcp = FALSE;
+ free (buf);
+ }
+
+ buf = svGetValue (file, "IPADDR");
+ if (buf)
+ {
+ ip4_address = inet_addr (buf);
+ free (buf);
+ }
- while (fgets (buffer, 499, file) && !feof (file))
+ buf = svGetValue (file, "GATEWAY");
+ if (buf)
{
- /* Kock off newline if any */
- g_strstrip (buffer);
+ ip4_gateway = inet_addr (buf);
+ free (buf);
+ }
- if (strncmp (buffer, "DEVICE=", 7) == 0)
+ buf = svGetValue (file, "NETMASK");
+ if (buf)
+ {
+ ip4_netmask = inet_addr (buf);
+ free (buf);
+ }
+ else
+ {
+ /* Make a default netmask if we have an IP address */
+ if (ip4_address)
{
- /* Make sure this config file is for this device */
- if (strcmp (&buffer[7], nm_device_get_iface (dev)) != 0)
- {
- syslog (LOG_WARNING, "System config file '%s' was not actually for device '%s'\n",
- cfg_file_path, nm_device_get_iface (dev));
- break;
- }
+ if (((ntohl (ip4_address) & 0xFF000000) >> 24) <= 127)
+ ip4_netmask = htonl (0xFF000000);
+ else if (((ntohl (ip4_address) & 0xFF000000) >> 24) <= 191)
+ ip4_netmask = htonl (0xFFFF0000);
else
- data_good = TRUE;
+ ip4_netmask = htonl (0xFFFFFF00);
}
- else if (strncmp (buffer, "BOOTPROTO=dhcp", 14) == 0)
- use_dhcp = TRUE;
- else if (strncmp (buffer, "BOOTPROTO=none", 14) == 0)
- use_dhcp = FALSE;
- else if (strncmp (buffer, "IPADDR=", 7) == 0)
- ip4_address = inet_addr (&buffer[7]);
- else if (strncmp (buffer, "GATEWAY=", 8) == 0)
- ip4_gateway = inet_addr (&buffer[8]);
- else if (strncmp (buffer, "NETMASK=", 8) == 0)
- ip4_netmask = inet_addr (&buffer[8]);
}
- fclose (file);
- g_free (cfg_file_path);
- /* If successful, set values on the device */
- if (data_good)
+ if (!use_dhcp && (!ip4_address || !ip4_gateway || !ip4_netmask))
{
- nm_device_config_set_use_dhcp (dev, use_dhcp);
- if (ip4_address)
- nm_device_config_set_ip4_address (dev, ip4_address);
- if (ip4_gateway)
- nm_device_config_set_ip4_gateway (dev, ip4_gateway);
- if (ip4_netmask)
- nm_device_config_set_ip4_netmask (dev, ip4_netmask);
+ syslog (LOG_ERR, "Error: network configuration for device '%s' was invalid (non-DCHP configuration,"
+ " but no address/gateway specificed). Will use DHCP instead.\n", nm_device_get_iface (dev));
+ use_dhcp = TRUE;
}
+
+ /* If successful, set values on the device */
+ nm_device_config_set_use_dhcp (dev, use_dhcp);
+ if (ip4_address)
+ nm_device_config_set_ip4_address (dev, ip4_address);
+ if (ip4_gateway)
+ nm_device_config_set_ip4_gateway (dev, ip4_gateway);
+ if (ip4_netmask)
+ nm_device_config_set_ip4_netmask (dev, ip4_netmask);
+
+#if 0
+ syslog (LOG_DEBUG, "------ Config (%s)", nm_device_get_iface (dev));
+ syslog (LOG_DEBUG, " DHCP=%d\n", use_dhcp);
+ syslog (LOG_DEBUG, " ADDR=%d\n", ip4_address);
+ syslog (LOG_DEBUG, " GW=%d\n", ip4_gateway);
+ syslog (LOG_DEBUG, " NM=%d\n", ip4_netmask);
+ syslog (LOG_DEBUG, "---------------------\n");
+#endif
+
+out:
+ svCloseFile (file);
}
diff --git a/src/backends/NetworkManagerSlackware.c b/src/backends/NetworkManagerSlackware.c
index 84d60bb62d..c04db22069 100644
--- a/src/backends/NetworkManagerSlackware.c
+++ b/src/backends/NetworkManagerSlackware.c
@@ -156,6 +156,21 @@ void nm_system_device_flush_addresses (NMDevice *dev)
/*
+ * nm_system_device_setup_static_ip4_config
+ *
+ * Set up the device with a particular IPv4 address/netmask/gateway.
+ *
+ * Returns: TRUE on success
+ * FALSE on error
+ *
+ */
+gboolean nm_system_device_setup_static_ip4_config (NMDevice *dev)
+{
+ syslog (LOG_WARN, "nm_system_device_setup_static_ip4_config() is not implemented yet for this distribution.\n");
+}
+
+
+/*
* nm_system_device_update_config_info
*
* Retrieve any relevant configuration info for a particular device
diff --git a/src/backends/NetworkManagerSystem.h b/src/backends/NetworkManagerSystem.h
index 383fa4bbc7..567cc818f1 100644
--- a/src/backends/NetworkManagerSystem.h
+++ b/src/backends/NetworkManagerSystem.h
@@ -30,25 +30,26 @@
void nm_system_init (void);
-gboolean nm_system_device_run_dhcp (NMDevice *dev);
+gboolean nm_system_device_run_dhcp (NMDevice *dev);
-void nm_system_device_stop_dhcp (NMDevice *dev);
+void nm_system_device_stop_dhcp (NMDevice *dev);
-void nm_system_device_flush_routes (NMDevice *dev);
+void nm_system_device_flush_routes (NMDevice *dev);
-void nm_system_device_flush_addresses (NMDevice *dev);
+void nm_system_device_flush_addresses (NMDevice *dev);
-void nm_system_device_update_config_info(NMDevice *dev);
+void nm_system_device_update_config_info (NMDevice *dev);
+gboolean nm_system_device_setup_static_ip4_config (NMDevice *dev);
-void nm_system_enable_loopback (void);
+void nm_system_enable_loopback (void);
-void nm_system_delete_default_route (void);
+void nm_system_delete_default_route (void);
-void nm_system_kill_all_dhcp_daemons (void);
+void nm_system_kill_all_dhcp_daemons (void);
-void nm_system_update_dns (void);
+void nm_system_update_dns (void);
-void nm_system_load_device_modules (void);
+void nm_system_load_device_modules (void);
#endif