2023-01-11 07:51:40 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.ulogd;
|
2023-10-09 19:29:22 +00:00
|
|
|
settingsFormat = pkgs.formats.ini { listsAsDuplicateKeys = true; };
|
2023-01-11 07:51:40 +00:00
|
|
|
settingsFile = settingsFormat.generate "ulogd.conf" cfg.settings;
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
services.ulogd = {
|
2024-04-21 15:54:59 +00:00
|
|
|
enable = mkEnableOption "ulogd, a userspace logging daemon for netfilter/iptables related logging";
|
2023-01-11 07:51:40 +00:00
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
example = {
|
2023-10-09 19:29:22 +00:00
|
|
|
global.stack = [
|
|
|
|
"log1:NFLOG,base1:BASE,ifi1:IFINDEX,ip2str1:IP2STR,print1:PRINTPKT,emu1:LOGEMU"
|
|
|
|
"log1:NFLOG,base1:BASE,pcap1:PCAP"
|
|
|
|
];
|
|
|
|
|
2023-01-11 07:51:40 +00:00
|
|
|
log1.group = 2;
|
2023-10-09 19:29:22 +00:00
|
|
|
|
2023-01-11 07:51:40 +00:00
|
|
|
pcap1 = {
|
2023-10-09 19:29:22 +00:00
|
|
|
sync = 1;
|
2023-01-11 07:51:40 +00:00
|
|
|
file = "/var/log/ulogd.pcap";
|
2023-10-09 19:29:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
emu1 = {
|
2023-01-11 07:51:40 +00:00
|
|
|
sync = 1;
|
2023-10-09 19:29:22 +00:00
|
|
|
file = "/var/log/ulogd_pkts.log";
|
2023-01-11 07:51:40 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
type = settingsFormat.type;
|
|
|
|
default = { };
|
2024-04-21 15:54:59 +00:00
|
|
|
description =
|
2023-10-09 19:29:22 +00:00
|
|
|
"Configuration for ulogd. See {file}`/share/doc/ulogd/` in `pkgs.ulogd.doc`.";
|
2023-01-11 07:51:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
logLevel = mkOption {
|
|
|
|
type = types.enum [ 1 3 5 7 8 ];
|
|
|
|
default = 5;
|
2024-04-21 15:54:59 +00:00
|
|
|
description =
|
2023-10-09 19:29:22 +00:00
|
|
|
"Log level (1 = debug, 3 = info, 5 = notice, 7 = error, 8 = fatal)";
|
2023-01-11 07:51:40 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.ulogd = {
|
|
|
|
description = "Ulogd Daemon";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
wants = [ "network-pre.target" ];
|
|
|
|
before = [ "network-pre.target" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
2023-10-09 19:29:22 +00:00
|
|
|
ExecStart =
|
|
|
|
"${pkgs.ulogd}/bin/ulogd -c ${settingsFile} --verbose --loglevel ${
|
|
|
|
toString cfg.logLevel
|
|
|
|
}";
|
2023-01-11 07:51:40 +00:00
|
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|