mirror of
https://github.com/fosrl/gerbil.git
synced 2026-02-07 21:46:40 +00:00
Allow changing mtu; set default low
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Sample from https://github.com/traefik/traefik-library-image/blob/5070edb25b03cca6802d75d5037576c840f73fdd/v3.1/alpine/entrypoint.sh
|
||||
|
||||
set -e
|
||||
|
||||
# first arg is `-f` or `--some-option`
|
||||
@@ -9,13 +7,4 @@ if [ "${1#-}" != "$1" ]; then
|
||||
set -- gerbil "$@"
|
||||
fi
|
||||
|
||||
# if our command is a valid Gerbil subcommand, let's invoke it through Gerbil instead
|
||||
# (this allows for "docker run gerbil version", etc)
|
||||
if gerbil "$1" --help >/dev/null 2>&1
|
||||
then
|
||||
set -- gerbil "$@"
|
||||
else
|
||||
echo "= '$1' is not a Gerbil command: assuming shell execution." 1>&2
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
13
main.go
13
main.go
@@ -9,6 +9,7 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -22,6 +23,7 @@ import (
|
||||
var (
|
||||
interfaceName = "wg0"
|
||||
listenAddr = ":3003"
|
||||
mtu = 1420
|
||||
lastReadings = make(map[string]PeerReading)
|
||||
mu sync.Mutex
|
||||
)
|
||||
@@ -77,6 +79,7 @@ func main() {
|
||||
|
||||
// Define command line flags
|
||||
interfaceNameArg := flag.String("interface", "wg0", "Name of the WireGuard interface")
|
||||
mtuRead := flag.String("mtu", "1280", "MTU of the interface")
|
||||
configFile := flag.String("config", "", "Path to local configuration file")
|
||||
remoteConfigURL := flag.String("remoteConfig", "", "URL to fetch remote configuration")
|
||||
listenAddrArg := flag.String("listen", ":3003", "Address to listen on")
|
||||
@@ -97,6 +100,11 @@ func main() {
|
||||
listenAddr = *listenAddrArg
|
||||
}
|
||||
|
||||
mtu, err = strconv.Atoi(*mtuRead)
|
||||
if err != nil {
|
||||
logger.Fatal("Failed to parse MTU: %v", err)
|
||||
}
|
||||
|
||||
// Validate that only one config option is provided
|
||||
if (*configFile != "" && *remoteConfigURL != "") || (*configFile == "" && *remoteConfigURL == "") {
|
||||
logger.Fatal("Please provide either --config or --remoteConfig, but not both")
|
||||
@@ -288,6 +296,11 @@ func ensureWireguardInterface(wgconfig WgConfig) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get interface: %v", err)
|
||||
}
|
||||
|
||||
if err := netlink.LinkSetMTU(link, mtu); err != nil {
|
||||
return fmt.Errorf("failed to set MTU: %v", err)
|
||||
}
|
||||
|
||||
if err := netlink.LinkSetUp(link); err != nil {
|
||||
return fmt.Errorf("failed to bring up interface: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user