Tags: patch

new version
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..ffeb744
--- /dev/null
+++ b/bond.c
@@ -0,0 +1,104 @@
+/*
+ * 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 "netcfg.h"
+#include <debian-installer.h>
+
+int netcfg_configure_bonding(struct debconfclient *client, char **interface)
+{
+    FILE *fp;
+
+    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 max_bonds=0", mode);
+
+    if (di_exec_shell_log(cmd)) {
+        di_error("Could not modprobe bonding module");
+        free(bonding_iface);
+        free(slaves);
+        return 1;
+    }
+
+    if ((fp = file_open("/sys/class/net/bonding_masters", "w"))) {
+      fprintf(fp, "+%s", bonding_iface);
+      fclose(fp);
+    }
+
+    char sysfs_path[100];
+    snprintf(sysfs_path, sizeof(sysfs_path), "/sys/class/net/%s/bonding/slaves", bonding_iface);
+
+    char *rest, *slave, *ptr = slaves;
+
+    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/debian/netcfg-common.templates b/debian/netcfg-common.templates
index 4525305..ec75376 100644
--- a/debian/netcfg-common.templates
+++ b/debian/netcfg-common.templates
@@ -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..311c90f 100644
--- a/netcfg.c
+++ b/netcfg.c
@@ -219,9 +219,11 @@ int main(int argc, char *argv[])
             else {
                 if (is_wireless_iface(interface.name))
                     state = WCONFIG;
-                else
+                else {
+                    netcfg_configure_bonding(client, &interface.name);
                     state = GET_METHOD;
                 }
+            }
             break;
         case GET_HOSTNAME_ONLY:
             if(netcfg_get_hostname(client, "netcfg/get_hostname", hostname, 0))
diff --git a/netcfg.h b/netcfg.h
index 771fed3..992dbf6 100644
--- a/netcfg.h
+++ b/netcfg.h
@@ -247,6 +247,7 @@ extern int netcfg_gateway_reachable(const struct netcfg_interface *interface);
 extern void preseed_hostname_from_fqdn(struct debconfclient *client, char *fqdn);
 
 extern int netcfg_dhcp(struct debconfclient *client, struct netcfg_interface *interface);
+extern int netcfg_configure_bonding(struct debconfclient *client, char **interface);
 
 extern void rtrim(char *);
 

Reply via email to