From e738692558f9c3e88bc7e286a4d3b96c769c4748 Mon Sep 17 00:00:00 2001 From: kurogeek Date: Thu, 16 Jul 2026 16:25:51 +0700 Subject: [PATCH] clanService/phonebox: allow multi-clients to exist on one node --- inventories/default.nix | 10 +++- modules/clan/phonebox/default.nix | 79 +++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/inventories/default.nix b/inventories/default.nix index e16a544..638c940 100644 --- a/inventories/default.nix +++ b/inventories/default.nix @@ -155,6 +155,7 @@ input = "clan-core"; }; roles.default.tags."global-network" = { }; + roles.default.settings.extraYggdrasilIPs = [ ]; roles.default.settings.extraPeers = [ "tls://ygg.jjolly.dev:3443" "tls://[2602:fc24:18:7a42::1]:993" @@ -186,7 +187,7 @@ input = "clan-core"; }; roles.default.tags."phonebox" = { }; - roles.default.settings.extraYggdrasilIPs = [ "200:c806:c13b:b855:723f:473:55:7904" ]; + roles.default.settings.extraYggdrasilIPs = [ ]; roles.default.settings.extraPeers = [ "tls://ygg.jjolly.dev:3443" "tls://[2602:fc24:18:7a42::1]:993" @@ -204,6 +205,13 @@ roles.default.machines."adhil".settings = { ata-ethernet-iface = "end0"; }; + roles.default.machines."rigel".settings = { + extraClientNumbers = [ + "01" + "02" + ]; + extraFixedIPClient = { }; + }; }; pulse-stream = { diff --git a/modules/clan/phonebox/default.nix b/modules/clan/phonebox/default.nix index 9499094..462910f 100644 --- a/modules/clan/phonebox/default.nix +++ b/modules/clan/phonebox/default.nix @@ -24,6 +24,36 @@ description = ""; default = ""; }; + options.extraClientNumbers = lib.mkOption { + type = with lib.types; listOf str; + description = "List of client suffix number."; + default = [ ]; + }; + + options.extraFixedIPClient = lib.mkOption { + type = lib.types.attrsOf ( + lib.types.submodule { + options = { + ip = lib.mkOption { + type = lib.types.str; + description = "IP address for this client"; + }; + + name = lib.mkOption { + type = lib.types.str; + description = "Name of the client"; + }; + }; + } + ); + description = "Extra client to be added to pjsip config as a fixed IP auth"; + example = { + "01" = { + ip = "192.168.1.3"; + name = "bob"; + }; + }; + }; }; perInstance = { @@ -126,6 +156,41 @@ remove_existing=yes ''; + genLocalSIPEndpointV6 = + { localNumber }: + '' + [${localNumber}](internal_endpoint) + transport=transport-udp6 + aors=${localNumber} + auth=${localNumber} + + [${localNumber}](userpass_auth) + username=${localNumber} + password=${localNumber} + + [${localNumber}](dynamiic_aor) + max_contacts=1 + ''; + + genLocalSIPIPEndpoint = number: '' + + [${number}](internal_endpoint) + aors=${number} + auth=${number} + contact_deny=0.0.0.0/0 + contact_deny=::/0 + contact_permit=${settings.extraFixedIPClient.${number}.ip}/128 + + [${number}](dynamiic_aor) + max_contacts=1 + remove_existing=yes + + [${number}](userpass_auth) + username=${number} + password=${number} + + ''; + genLocalExtenConf = { localNumber }: '' @@ -356,6 +421,14 @@ + (genLocalExtenConf { localNumber = config.clan.core.vars.generators.phonebox.files.ata-local-number.value; }) + + lib.concatStringsSep "\n" ( + builtins.map (number: genLocalExtenConf { localNumber = number; }) settings.extraClientNumbers + ) + + lib.concatStringsSep "\n" ( + lib.mapAttrsToList ( + number: _: genLocalExtenConf { localNumber = number; } + ) settings.extraFixedIPClient + ) + serverConf; "rtp.conf" = '' @@ -409,6 +482,12 @@ + (genLocalSIPEndpoint { localNumber = config.clan.core.vars.generators.phonebox.files.ata-local-number.value; }) + + lib.concatStringsSep "\n" ( + builtins.map (number: genLocalSIPEndpointV6 { localNumber = number; }) settings.extraClientNumbers + ) + + lib.concatStringsSep "\n" ( + lib.mapAttrsToList (number: _: genLocalSIPIPEndpoint number) settings.extraFixedIPClient + ) + serverConf; }; };