From 3a691dd81a50d45f08a1c7a1a484667dbd207e4c Mon Sep 17 00:00:00 2001
From: kaiyou <dev@kaiyou.fr>
Date: Sun, 12 Mar 2023 13:33:30 +0100
Subject: [PATCH] Load most common kernel modules on startup

---
 cmd/hepto/service.go | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/cmd/hepto/service.go b/cmd/hepto/service.go
index 028752b..5d36efa 100644
--- a/cmd/hepto/service.go
+++ b/cmd/hepto/service.go
@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"net"
 	"os"
+	"os/exec"
 	"path"
 	"time"
 
@@ -51,6 +52,26 @@ var Start = &cobra.Command{
 				return err
 			}
 		}
+		// Load useful kernel modules for later operations
+		// This uses exec at the moment, which is undesireable in case hepto is used in a very
+		// limited environment
+		desiredModules := []string{
+			"nf_conntrack", // Required by most CNI
+			"ip6_tables",   // Required by kube-router, kube-proxy, Calico, and even Cilium
+			"ip6table_filter",
+			"ip6table_nat",
+			"ip6table_mangle",
+			"ip_tables", // Not used since hepto is IPv6 only, but required by most CNI
+			"iptable_filter",
+			"iptable_nat",
+			"iptable_mangle",
+		}
+		for _, mod := range desiredModules {
+			err := exec.Command("modprobe", "--", mod).Run()
+			if err != nil {
+				return err
+			}
+		}
 		return nil
 	},
 	RunE: func(cmd *cobra.Command, args []string) error {
-- 
GitLab