Hi there,

please consider merging attached patch, which enables basic configuration of 
bonding interface trough preseeding. 

I've had few racks of servers configured to do automatic installation trough 
netboot and preseeding. Two weeks back we migrated to 802.3ad in the whole 
infrastructure. The problem is, that now the interfaces won't transition to 
forwarding state unless they establish 802.3ad connection. Hence the patch.

I'm opened to suggestion to improve it.

Cheers
Michal
diff --git a/Makefile b/Makefile
index 70c0e2c..911abc6 100644
--- a/Makefile
+++ b/Makefile
@@ -8,7 +8,7 @@ TARGETS		?= netcfg-static netcfg
 
 LDOPTS		= -ldebconfclient -ldebian-installer
 CFLAGS		= -W -Wall -Werror -DNDEBUG -DNETCFG_VERSION="\"$(NETCFG_VERSION)\"" -DNETCFG_BUILD_DATE="\"$(NETCFG_BUILD_DATE)\"" -I.
-COMMON_OBJS	= netcfg-common.o wireless.o write_interface.o ipv6.o
+COMMON_OBJS	= netcfg-common.o wireless.o write_interface.o ipv6.o bond.o
 NETCFG_O   	= netcfg.o dhcp.o static.o ethtool-lite.o wpa.o wpa_ctrl.o rdnssd.o autoconfig.o
 NETCFG_STATIC_O	= netcfg-static.o static.o ethtool-lite.o
 
diff --git a/bond.c b/bond.c
new file mode 100644
index 0000000..46dac1a
--- /dev/null
+++ b/bond.c
@@ -0,0 +1,99 @@
+/*
+ * bond.c - Bonding configuration for debian-installer
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include "bond.h"
+#include "netcfg.h"
+#include <debian-installer.h>
+
+int netcfg_configure_bonding(struct debconfclient *client, char **interface)
+{
+    debconf_get(client, "netcfg/bonding");
+    if (strlen(client->value) == 0) {
+        return 0;
+    }
+
+    char *bonding_iface = strdup(client->value);
+
+    char *mode = "0";
+    debconf_get(client, "netcfg/bonding_mode");
+
+    if (strcmp(client->value, "balance-rr") == 0 || strcmp(client->value, "0") == 0) {
+        mode = "0";
+    } else if (strcmp(client->value, "active-backup") == 0 || strcmp(client->value, "1") == 0) {
+        mode = "1";
+    } else if (strcmp(client->value, "balance-xor") == 0 || strcmp(client->value, "2") == 0) {
+        mode = "2";
+    } else if (strcmp(client->value, "broadcast") == 0 || strcmp(client->value, "3") == 0) {
+        mode = "3";
+    } else if (strcmp(client->value, "802.3ad") == 0 || strcmp(client->value, "4") == 0) {
+        mode = "4";
+    } else if (strcmp(client->value, "balance-tlb") == 0 || strcmp(client->value, "5") == 0) {
+        mode = "5";
+    } else if (strcmp(client->value, "balance-alb") == 0 || strcmp(client->value, "6") == 0) {
+        mode = "6";
+    }
+
+    debconf_get(client, "netcfg/bonding_slaves");
+    char *slaves;
+
+    if (strlen(client->value) < 2) {
+        slaves = strdup(*interface);
+    } else {
+        slaves = strdup(client->value);
+    }
+
+    di_info("Creating bonding %s with mode=%s, slaves=%s", bonding_iface, mode, slaves);
+
+    char cmd[200];
+
+    snprintf(cmd, sizeof(cmd), "modprobe bonding mode=%s miimon=100", mode);
+    if (di_exec_shell_log(cmd)) {
+        di_error("Could not modprobe bonding module");
+        free(bonding_iface);
+        free(slaves);
+        return 1;
+    }
+
+    char sysfs_path[100];
+    snprintf(sysfs_path, sizeof(sysfs_path), "/sys/class/net/%s/bonding/slaves", bonding_iface);
+
+    char *rest, *slave, *ptr = slaves;
+    FILE *fp;
+
+    while((slave = strtok_r(ptr, " ,", &rest)) != NULL) {
+        ptr = rest;
+        snprintf(cmd, sizeof(cmd), "ip link set %s down", slave);
+        di_exec_shell_log(cmd);
+
+
+        if ((fp = file_open(sysfs_path, "w"))) {
+            fprintf(fp, "+%s", slave);
+            fclose(fp);
+        }
+    }
+
+    snprintf(cmd, sizeof(cmd), "ip link set %s up", bonding_iface);
+    di_exec_shell_log(cmd);
+
+    free(slaves);
+    free(*interface);
+    *interface = bonding_iface;
+
+    return 0;
+}
diff --git a/bond.h b/bond.h
new file mode 100644
index 0000000..cedfb0a
--- /dev/null
+++ b/bond.h
@@ -0,0 +1,27 @@
+/*
+ * bond.h - Bonding configuration for debian-installer
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifndef _BOND_H_
+#define _BOND_H_
+
+#include <cdebconf/debconfclient.h>
+
+int netcfg_configure_bonding(struct debconfclient *client, char **interface);
+
+#endif /* _BOND_H_ */
diff --git a/debian/netcfg-common.templates b/debian/netcfg-common.templates
index 4525305..ec75376 100644
--- a/debian/netcfg-common.templates
+++ b/debian/netcfg-common.templates
@@ -22,7 +22,7 @@ Type: string
 # :sl1:
 _Description: Domain name:
  The domain name is the part of your Internet address to the right of your
- host name.  It is often something that ends in .com, .net, .edu, or .org. 
+ host name.  It is often something that ends in .com, .net, .edu, or .org.
  If you are setting up a home network, you can make something up, but make
  sure you use the same domain name on all your computers.
 
@@ -371,3 +371,18 @@ _Choices: ${essid_list} Enter ESSID manually
 _Description: Wireless network:
  Select the wireless network to use during the installation process.
 
+Template: netcfg/bonding
+Type: string
+Description: for internal use; can be preseeded
+ Configure bonding interface
+
+Template: netcfg/bonding_mode
+Type: string
+Default: balance-rr
+Description: for internal use; can be preseeded
+ Configure bonding interface mode
+
+Template: netcfg/bonding_slaves
+Type: string
+Description: for internal use; can be preseeded
+ Configure bonding slaves (detected interface by default)
diff --git a/netcfg.c b/netcfg.c
index e544e61..8b86f0d 100644
--- a/netcfg.c
+++ b/netcfg.c
@@ -23,6 +23,7 @@
 
 #include "netcfg.h"
 #include "nm-conf.h"
+#include "bond.h"
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -217,10 +218,12 @@ int main(int argc, char *argv[])
             else if (! interface.name || ! num_interfaces)
                 state = GET_HOSTNAME_ONLY;
             else {
-                if (is_wireless_iface (interface.name))
+                if (is_wireless_iface(interface.name))
                     state = WCONFIG;
-                else
+                else {
+                    netcfg_configure_bonding(client, &interface.name);
                     state = GET_METHOD;
+                }
             }
             break;
         case GET_HOSTNAME_ONLY:

Reply via email to