Preliminary Static config support for Gentoo



I've only got a work-in-progress for it, and unfortunately have not had
time to finish it up(midterms, etc). Currently it will pull all the
necessary info out, and build the commands but not run them. When I
tried running them by hand, or through NM, I had problems when trying to
set the gateway.

Hopefully someone that knows more about the iproute tools can help out.

This patch also cleans uo my earlier code to conform to the contributing
guidelines, and rips out the need to check for iproute/net-tools,
settling on iproute, which will always be listed as a dependency.

This patch *should* apply, and I certainly hope it does. I'm not sure if
I have my work directory anymore, as I've been cleaning my laptop off,
awaiting a replacement that is on the way.

Robert

On Mon, 2004-11-01 at 16:29 -0500, Dan Williams wrote:
> AFAIK Linksys uses a different passphrase->key hashing scheme, I'll try
> to find out.
> 
> How about that Gentoo rediff of the static IP stuff?? :)
> 
> Dan
> 
> On Mon, 2004-11-01 at 16:21 -0500, Robert Paskowitz wrote:
> > I'm fairly certain it worked fine on an acx100 card i hat (DWL-650+). I
> > no longer have the card though, and cannot test, but I'll ask around on
> > other success.
> > 
> > Robert
> 
> 
Index: NetworkManagerGentoo.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/src/backends/NetworkManagerGentoo.c,v
retrieving revision 1.6
diff -u -r1.6 NetworkManagerGentoo.c
--- NetworkManagerGentoo.c	13 Oct 2004 20:57:23 -0000	1.6
+++ NetworkManagerGentoo.c	15 Oct 2004 04:29:22 -0000
@@ -30,14 +30,6 @@
 #include "NetworkManagerSystem.h"
 #include "NetworkManagerUtils.h"
 
-typedef enum GENTOOConfType
-{
-	GENTOO_CONF_TYPE_IFCONFIG = 0,
-	GENTOO_CONF_TYPE_IPROUTE
-} GENTOOConfType;
-
-static GENTOOConfType nm_system_gentoo_conf_type;
-
 /*
  * nm_system_init
  *
@@ -46,14 +38,10 @@
  */
 void nm_system_init (void)
 {
-// TODO: autodetect conf type, probably by checking if /sbin/ip exists
-
-/* It's not safe to assume the the iproute stuff exists, but seeing as it 
- * is far more convinient to flush stuff with /sbin/ip with iproute
- * I think it would be acceptable to introduce the sys-apps/iproute2
- * package as a dependancy for Gentoo.
-*/
-	nm_system_gentoo_conf_type = GENTOO_CONF_TYPE_IPROUTE;
+	/* While dhcpcd is the client of choice, it's not forced upon the user
+	 * So we should probably put in a check for available clients, and
+	 * modify our commands appropriatly.
+	 */
 }
 
 /*
@@ -139,17 +127,7 @@
 	/* Not really applicable for test devices */
 	if (nm_device_is_test_device (dev))
 		return;
-
-	if (nm_system_gentoo_conf_type == GENTOO_CONF_TYPE_IPROUTE) {
-		snprintf (buf, 100, "/sbin/ip route flush dev %s", nm_device_get_iface (dev));
-	} else if (nm_system_gentoo_conf_type == GENTOO_CONF_TYPE_IFCONFIG) {
-// FIXME: this command still isn't right
-
-/* See note above */
-		snprintf (buf, 100, "/sbin/route del dev %s", nm_device_get_iface (dev));
-	} else {
-		snprintf (buf, 100, "/bin/false");
-	}
+	snprintf (buf, 100, "/sbin/ip route flush dev %s", nm_device_get_iface (dev));
 	nm_spawn_process (buf);
 }
 
@@ -169,16 +147,7 @@
 	if (nm_device_is_test_device (dev))
 		return;
 
-	if (nm_system_gentoo_conf_type == GENTOO_CONF_TYPE_IPROUTE) {
-		snprintf (buf, 100, "/sbin/ip address flush dev %s", nm_device_get_iface (dev));
-	} else if (nm_system_gentoo_conf_type == GENTOO_CONF_TYPE_IFCONFIG) {
-// FIXME: find the correct command
-
-/* See note above */
-		snprintf (buf, 100, "/bin/false");
-	} else {
-		snprintf (buf, 100, "/bin/false");
-	}
+	snprintf (buf, 100, "/sbin/ip address flush dev %s", nm_device_get_iface (dev));
 	nm_spawn_process (buf);
 }
 
@@ -194,20 +163,51 @@
  */
 gboolean nm_system_device_setup_static_ip4_config (NMDevice *dev)
 {
 	syslog (LOG_WARNING, "nm_system_device_setup_static_ip4_config() is not implemented yet for this distribution.\n");
+#define IPBITS  (sizeof (guint32) * 8)
+	struct in_addr	ip_addr, net_addr, broad_addr, gate_addr;
+	int			i, err;
+	guint32		prefix = IPBITS;
+	char		*iface;
+	char		*buf;
+	char		*addr, *netmask, *broadcast, *gateway;
+	
+	
+	/* Extract the addresses back into strings */
+
+	ip_addr.s_addr = nm_device_config_get_ip4_address (dev);
+	net_addr.s_addr = nm_device_config_get_ip4_netmask (dev);
+	broad_addr.s_addr = nm_device_config_get_ip4_broadcast (dev);
+	gate_addr.s_addr = nm_device_config_get_ip4_gateway (dev);
+	
+	addr = g_strdup (inet_ntoa (ip_addr));
+	netmask = g_strdup (inet_ntoa (net_addr));
+	broadcast = g_strdup (inet_ntoa (broad_addr));
+	gateway = g_strdup (inet_ntoa (gate_addr));
+	iface = nm_device_get_iface (dev);
+	
+	/* Flush the device and routes */
+	nm_system_device_flush_addresses (dev);
+	nm_system_device_flush_routes (dev);
+
+	/* Set the IP/broadcast */
+	buf = g_strdup_printf("/sbin/ip addr add local %s dev %s broadcast %s %s", addr, iface, broadcast, iface);
+	syslog (LOG_WARNING, "Running: %s", buf);
+	/* Set the gateway */
+	buf = g_strdup_printf("/sbin/ip route replace default dev %s via %s", iface, gateway);
+	syslog (LOG_WARNING, "Running: %s", buf);
+	
+	/* Inform other computers the we are on network */
+	buf = g_strdup_printf ("/sbin/arping -q -A -c 1 -I %s %s", iface, addr);
+	syslog (LOG_WARNING, "Running: %s", buf);
+	buf = g_strdup_printf ("/sbin/arping -q -U -c 1 -I %s %s", iface, addr);
+	syslog (LOG_WARNING, "Running: %s", buf);
+	
+	return(TRUE);
+	
+error:
+	g_free(buf);
+	return(FALSE);
 }
 
 
@@ -219,13 +219,8 @@
  */
 void nm_system_enable_loopback (void)
 {
-	if (nm_system_gentoo_conf_type == GENTOO_CONF_TYPE_IPROUTE) {
 		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");
-	} else if (nm_system_gentoo_conf_type == GENTOO_CONF_TYPE_IFCONFIG) {
-		nm_spawn_process ("/sbin/ifconfig lo 127.0.0.1 up");
-		nm_spawn_process ("/sbin/route add -net 127.0.0.0 netmask 255.0.0.0 gw 127.0.0.1 dev lo");
-	}
 }
 
 /*
@@ -236,11 +231,7 @@
  */
 void nm_system_delete_default_route (void)
 {
-	if (nm_system_gentoo_conf_type == GENTOO_CONF_TYPE_IPROUTE) {
 		nm_spawn_process ("/sbin/ip route del default");
-	} else if (nm_system_gentoo_conf_type == GENTOO_CONF_TYPE_IFCONFIG) {
-		nm_spawn_process ("/sbin/route del default");
-	}
 }
 
 /*
@@ -288,129 +279,128 @@
  */
 void nm_system_device_update_config_info (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;
+	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;
-        guint32  ip4_address = 0;
-        guint32  ip4_netmask = 0;
-        guint32  ip4_gateway = 0;
-
-        g_return_if_fail (dev != NULL);
-
-        /* We use DHCP on an interface unless told not to */
-        nm_device_config_set_use_dhcp (dev, TRUE);
-        nm_device_config_set_ip4_address (dev, 0);
-        nm_device_config_set_ip4_gateway (dev, 0);
-        nm_device_config_set_ip4_netmask (dev, 0);
-
-        /* Gentoo systems store this information in
-         * /etc/conf.d/net, this is for all interfaces.
-         */
-
-        cfg_file_path = g_strdup_printf ("/etc/conf.d/net");
-        if (!cfg_file_path)
-                return;
-
-        if (!(file = fopen (cfg_file_path, "r")))
-        {
-                g_free (cfg_file_path);
-                return;
-        }
+	char            *confToken;
+	gboolean         data_good = FALSE;
+	gboolean         use_dhcp = TRUE;
+	guint32  ip4_address = 0;
+	guint32  ip4_netmask = 0;
+	guint32  ip4_gateway = 0;
+
+	g_return_if_fail (dev != NULL);
+
+	/* We use DHCP on an interface unless told not to */
+	nm_device_config_set_use_dhcp (dev, TRUE);
+	nm_device_config_set_ip4_address (dev, 0);
+	nm_device_config_set_ip4_gateway (dev, 0);
+	nm_device_config_set_ip4_netmask (dev, 0);
+
+	/* Gentoo systems store this information in
+	* /etc/conf.d/net, this is for all interfaces.
+	*/
+
+	cfg_file_path = g_strdup_printf ("/etc/conf.d/net");
+	if (!cfg_file_path)
+		return;
+
+	if (!(file = fopen (cfg_file_path, "r")))
+	{
+		g_free (cfg_file_path);
+		return;
+	}
 	sprintf(confline, "iface_%s", nm_device_get_iface (dev));
 	sprintf(dhcpline, "iface_%s=\"dhcp\"", nm_device_get_iface (dev));
-        while (fgets (buffer, 499, 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)
-                        {
-                                syslog (LOG_WARNING, "System config file '%s' does not define device '%s'\n",
-                                                cfg_file_path, nm_device_get_iface (dev));
-                                break;
-                        }
-                        else
-                                data_good = TRUE;
-
+		while (fgets (buffer, 499, file) && !feof (file))
+		{
+			/* Kock off newline if any */
+			g_strstrip (buffer);
 
-                
-			if (strncmp (buffer, dhcpline, strlen(dhcpline)) == 0)
-			{
-				use_dhcp = TRUE;
-			}
-			else
+			if (strncmp (buffer, confline, strlen(confline)) == 0)
 			{
-				syslog (LOG_WARNING, "Device '%s' is setup as static, and we do not (yet) support that\n",
-						nm_device_get_iface (dev));
-				use_dhcp = FALSE;
-				confToken = strtok(&buffer[strlen(confline) + 2], " ");
-				while (count < 3)
+				/* 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)
 				{
-					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)
+					syslog (LOG_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, " ");
-						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)
-		{
-			sprintf(ipline, "gateway=\"%s/", nm_device_get_iface (dev));
-			if (strncmp(buffer, ipline, strlen(ipline) - 1) == 0)
+			/* If we aren't using dhcp, then try to get the gateway */
+			if (!use_dhcp)
 			{
-				sprintf(ipline, "gateway=\"%s/%%d.%%d.%%d.%%d\"", nm_device_get_iface (dev) );
-				sscanf(buffer, ipline, &ipa, &ipb, &ipc, &ipd);
-				sprintf(ipline, "%d.%d.%d.%d", ipa, ipb, ipc, ipd);
-				ip4_gateway = inet_addr (ipline);
-			}
-		}		
+				sprintf(ipline, "gateway=\"%s/", nm_device_get_iface (dev));
+				if (strncmp(buffer, ipline, strlen(ipline) - 1) == 0)
+				{
+					sprintf(ipline, "gateway=\"%s/%%d.%%d.%%d.%%d\"", nm_device_get_iface (dev) );
+					sscanf(buffer, ipline, &ipa, &ipb, &ipc, &ipd);
+					sprintf(ipline, "%d.%d.%d.%d", ipa, ipb, ipc, ipd);
+					ip4_gateway = inet_addr (ipline);
+				}
+			}		
         }
-        fclose (file);
-        g_free (cfg_file_path);
+		fclose (file);
+		g_free (cfg_file_path);
 
-        /* If successful, set values on the device */
-        if (data_good)
-        {
-                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 successful, set values on the device */
+		if (data_good)
+		{
+			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 (ip4_broadcast)
+				nm_device_config_set_ip4_broadcast (dev, ip4_broadcast);
         }
 }

Attachment: signature.asc
Description: This is a digitally signed message part



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]