2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.siproxd;
|
|
|
|
|
|
|
|
conf = ''
|
|
|
|
daemonize = 0
|
|
|
|
rtp_proxy_enable = 1
|
|
|
|
user = siproxd
|
|
|
|
if_inbound = ${cfg.ifInbound}
|
|
|
|
if_outbound = ${cfg.ifOutbound}
|
|
|
|
sip_listen_port = ${toString cfg.sipListenPort}
|
|
|
|
rtp_port_low = ${toString cfg.rtpPortLow}
|
|
|
|
rtp_port_high = ${toString cfg.rtpPortHigh}
|
|
|
|
rtp_dscp = ${toString cfg.rtpDscp}
|
|
|
|
sip_dscp = ${toString cfg.sipDscp}
|
|
|
|
${optionalString (cfg.hostsAllowReg != []) "hosts_allow_reg = ${concatStringsSep "," cfg.hostsAllowReg}"}
|
|
|
|
${optionalString (cfg.hostsAllowSip != []) "hosts_allow_sip = ${concatStringsSep "," cfg.hostsAllowSip}"}
|
|
|
|
${optionalString (cfg.hostsDenySip != []) "hosts_deny_sip = ${concatStringsSep "," cfg.hostsDenySip}"}
|
2023-04-29 16:46:19 +00:00
|
|
|
${optionalString (cfg.passwordFile != "") "proxy_auth_pwfile = ${cfg.passwordFile}"}
|
2020-04-24 23:36:52 +00:00
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
|
|
|
|
|
|
|
confFile = builtins.toFile "siproxd.conf" conf;
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
##### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.siproxd = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-08-20 17:08:02 +00:00
|
|
|
Whether to enable the Siproxd SIP
|
2020-11-24 20:58:05 +00:00
|
|
|
proxy/masquerading daemon.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
ifInbound = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "eth0";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Local network interface";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ifOutbound = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "ppp0";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Public network interface";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
hostsAllowReg = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2020-11-24 20:58:05 +00:00
|
|
|
default = [ ];
|
2020-04-24 23:36:52 +00:00
|
|
|
example = [ "192.168.1.0/24" "192.168.2.0/24" ];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-05-24 13:37:59 +00:00
|
|
|
Access control list for incoming SIP registrations.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
hostsAllowSip = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2020-11-24 20:58:05 +00:00
|
|
|
default = [ ];
|
2020-04-24 23:36:52 +00:00
|
|
|
example = [ "123.45.0.0/16" "123.46.0.0/16" ];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-05-24 13:37:59 +00:00
|
|
|
Access control list for incoming SIP traffic.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
hostsDenySip = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2020-11-24 20:58:05 +00:00
|
|
|
default = [ ];
|
2020-04-24 23:36:52 +00:00
|
|
|
example = [ "10.0.0.0/8" "11.0.0.0/8" ];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-05-24 13:37:59 +00:00
|
|
|
Access control list for denying incoming
|
2020-11-24 20:58:05 +00:00
|
|
|
SIP registrations and traffic.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
sipListenPort = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 5060;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-11-24 20:58:05 +00:00
|
|
|
Port to listen for incoming SIP messages.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
rtpPortLow = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 7070;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Bottom of UDP port range for incoming and outgoing RTP traffic
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
rtpPortHigh = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 7089;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Top of UDP port range for incoming and outgoing RTP traffic
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
rtpTimeout = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 300;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-08-20 17:08:02 +00:00
|
|
|
Timeout for an RTP stream. If for the specified
|
2020-04-24 23:36:52 +00:00
|
|
|
number of seconds no data is relayed on an active
|
|
|
|
stream, it is considered dead and will be killed.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
rtpDscp = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 46;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
DSCP (differentiated services) value to be assigned
|
2020-08-20 17:08:02 +00:00
|
|
|
to RTP packets. Allows QOS aware routers to handle
|
2020-04-24 23:36:52 +00:00
|
|
|
different types traffic with different priorities.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
sipDscp = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 0;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
DSCP (differentiated services) value to be assigned
|
2020-08-20 17:08:02 +00:00
|
|
|
to SIP packets. Allows QOS aware routers to handle
|
2020-04-24 23:36:52 +00:00
|
|
|
different types traffic with different priorities.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
passwordFile = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Path to per-user password file.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Extra configuration to add to siproxd configuration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
##### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
users.users.siproxyd = {
|
|
|
|
uid = config.ids.uids.siproxd;
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.siproxd = {
|
|
|
|
description = "SIP proxy/masquerading daemon";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkgs.siproxd}/sbin/siproxd -c ${confFile}";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|