diff options
| author | quentin@aristote.fr <quentin@aristote.fr> | 2024-06-08 19:38:25 +0200 |
|---|---|---|
| committer | quentin@aristote.fr <quentin@aristote.fr> | 2024-06-08 19:38:25 +0200 |
| commit | 20dc8e5c5e24cea8d643726504b59166e987031a (patch) | |
| tree | 0057ea161b60a811d7887bf8a0b15fc34db6f4ff | |
| parent | 9c570593b8e61f65961345350ad738f175d67558 (diff) | |
networking: dhcp: add bridge around enp3s0
| -rw-r--r-- | config/networking/bridges.nix | 46 | ||||
| -rw-r--r-- | config/networking/default.nix | 6 | ||||
| -rw-r--r-- | config/networking/services/dhcp.nix | 2 |
3 files changed, 36 insertions, 18 deletions
diff --git a/config/networking/bridges.nix b/config/networking/bridges.nix index cdef41b..9e18ea8 100644 --- a/config/networking/bridges.nix +++ b/config/networking/bridges.nix @@ -1,26 +1,46 @@ -{ config, lib, utils, pkgs, ... }: - -let nets = config.personal.networking.networks; +{ + config, + lib, + pkgs, + ... +}: let + nets = config.personal.networking.networks; in { - config = lib.mkMerge ([{ - systemd.services.hostapd.postStart = lib.mkForce (lib.mkBefore '' - sleep 3 - ''); - }] ++ (builtins.map (network: - let + config = lib.mkMerge ([ + { + systemd.services.hostapd.postStart = lib.mkForce (lib.mkBefore '' + sleep 3 + ''); + } + { + # create a bridge on top of enp3s0 along with a dummy interface + # for kea to work even when enp3s0 is disconnected + # if you change this, you may want to change: + # - the kea configuration in ./services/dhcp.nix + # - the eth0 net configuration ./default.nix + networking = { + bridges.eth0.interfaces = ["enp3s0" "enp3s0-dummy"]; + localCommands = '' + ip link add enp3s0-dummy type dummy + ''; + }; + boot.kernelModules = ["dummy"]; + } + ] + ++ (builtins.map (network: let bridge = network.interface; device = network.device; in { - networking.bridges."${bridge}".interfaces = [ ]; + networking.bridges."${bridge}".interfaces = []; systemd.services."${bridge}-netdev".script = '' echo Setting forward delay to 0 for ${bridge}... ip link set ${bridge} type bridge forward_delay 0 ''; - systemd.services.hostapd.postStart = lib.mkForce ('' + systemd.services.hostapd.postStart = lib.mkForce '' echo Setting ${device} to hairpin mode... ${pkgs.iproute2}/bin/bridge link set dev ${device} hairpin on - ''); - }) [ nets.wan nets.iot ])); + ''; + }) [nets.wan nets.iot])); } diff --git a/config/networking/default.nix b/config/networking/default.nix index 136be95..7ffc32b 100644 --- a/config/networking/default.nix +++ b/config/networking/default.nix @@ -93,11 +93,9 @@ in { }; }; }; - eth0 = let + eth0 = { device = "enp3s0"; - in { - inherit device; - interface = device; + interface = "eth0"; subnet = "192.168.4"; machines = { self.ip = "192.168.4.1"; diff --git a/config/networking/services/dhcp.nix b/config/networking/services/dhcp.nix index 87ffc08..d27bbce 100644 --- a/config/networking/services/dhcp.nix +++ b/config/networking/services/dhcp.nix @@ -11,7 +11,7 @@ in { services.kea.dhcp4 = { enable = true; settings = let - subnets = with nets; [wan iot]; + subnets = with nets; [wan iot eth0]; in { interfaces-config = { interfaces = builtins.map (network: network.interface) subnets; |
