Commit Graph

266 Commits

Author SHA1 Message Date
kor-elf ba4d026642 Add initial CHANGELOG.md with version 0.1.0 release notes 2025-11-08 15:14:12 +05:00
kor-elf 3c01301fbf Add English version of README with detailed project overview and setup instructions 2025-11-08 15:13:54 +05:00
kor-elf 8cb5563361 Add initial README.md with project overview and setup instructions 2025-11-08 15:13:38 +05:00
kor-elf e7035cffb8 Add systemd service file for kor-elf-shield 2025-11-08 15:13:10 +05:00
kor-elf 30e48f46a2 Add logrotate configuration for kor-elf-shield logs 2025-11-08 15:12:46 +05:00
kor-elf 6a310bca22 Fix typo in comment within kor-elf-shield.toml configuration 2025-11-08 14:31:14 +05:00
kor-elf 1398735070 Corrected typos 2025-11-08 14:30:38 +05:00
kor-elf a5394a2aa1 Move configuration files to assets/configs directory 2025-11-04 19:12:56 +05:00
kor-elf c305feac4a There was a typo in ConfigPath .conf, it should be .toml 2025-11-04 19:12:36 +05:00
kor-elf e409d458f8 Add third-party licenses file
- Added `LICENSE-3RD-PARTY.txt` containing licenses for dependencies used in the project.
2025-11-02 22:57:17 +05:00
kor-elf 859e7ad4da Add "reopen_logger" command to daemon for log file management
- Introduced `CmdReopenLogger` for reopening daemon log files.
- Added `ReOpen` method to `Logger` interface and its implementations.
- Updated daemon logic to handle the "reopen_logger" command via Unix socket communication.
- Extended localization files with translations for new command messages.
- Registered `CmdReopenLogger` in the main CLI application.
2025-11-02 22:41:39 +05:00
kor-elf 85d55bc262 Improve error message when daemon is not running in stop command 2025-11-02 21:10:49 +05:00
kor-elf d9cfecfb1e Add "status" command to daemon for runtime health checking
- Introduced `CmdStatus` command to verify if the daemon is running via Unix socket communication.
- Updated daemon logic to handle the "status" command and respond accordingly.
- Extended localization files with translations for status command messages.
- Registered `CmdStatus` in the main CLI application.
2025-11-02 21:10:27 +05:00
kor-elf c8a0df90c2 Add "stop" command to daemon with Unix socket communication
- Introduced a `CmdStop` command for stopping the daemon, clearing nftables firewall rules.
- Implemented `NewSocketClient` in `internal/socket/socket.go` for Unix socket interaction.
- Updated daemon logic to handle the "stop" command via socket communication.
- Extended localization files with translations for stop command messages.
2025-11-02 20:59:15 +05:00
kor-elf 1183dde0f4 Refactor socket handling logic to use Connect interface abstraction
- Introduced `Connect` interface with methods for `Read`, `Write`, and `Close`.
- Added `connect` struct as an implementation of `Connect` for `net.Conn`.
- Updated command handling to use `Connect` abstraction, improving modularity and testability.
- Renamed `handleConn` to `handleAction` for better clarity.
2025-11-02 20:24:12 +05:00
kor-elf 0e3e8cf169 Handle closed network connection error in socket handling
- Added `isUseOfClosedNetworkError` function to identify specific "use of closed network connection" errors.
- Updated socket handling logic in `Run` method to gracefully handle closed connection errors with improved debug logging.
2025-11-02 17:42:01 +05:00
kor-elf 51ffb17bed Log service stop action in daemon for better traceability 2025-11-02 17:41:06 +05:00
kor-elf 6b11626376 Remove unused variable err in runDaemon function 2025-11-02 16:32:08 +05:00
kor-elf e6f2d9108f Add Unix socket support to daemon
- Introduced `Socket` interface and implementation in `internal/daemon/socket/socket.go`.
- Added socket file management (`EnsureNoOtherProcess`, `Create`, `Close`) and command handling via `Run`.
- Updated `DaemonOptions` and configuration to include `socket_file` path.
- Integrated socket lifecycle into daemon's `Run` method for process communication.
- Added validation and default configuration for `socket_file` in `setting` package.
2025-11-02 16:15:57 +05:00
kor-elf f81085dec2 Reorganize imports in main.go for better readability 2025-11-02 14:52:22 +05:00
kor-elf a978518afa Refine comment in pidfile.go for clarity. 2025-11-02 14:04:07 +05:00
kor-elf 453aa2d20c Improve port validation error message
- Replaced generic error message with a formatted message specifying the parameter name for better clarity.
2025-11-02 00:31:14 +05:00
kor-elf b9bd3edb9c Add IP-based traffic control to firewall configuration
- Introduced `IP` struct for managing IP-based rules, including fields for IPs, actions, directions, protocols, ports, and rate limits.
- Added methods to process IP configurations into `InIPs` and `OutIPs`.
- Extended reload methods for input and output to include IP-based rule handling.
- Updated `firewall.toml` with IP configuration examples and detailed documentation.
- Enhanced validation logic for IP-based settings to ensure proper configuration.
2025-11-02 00:30:17 +05:00
kor-elf 4bfa7ffc1b Update IcmpInRate field for improved readability
- Changed rate format from "1/s" to "1/second" in `defaultIp4` function.
2025-11-01 11:32:13 +05:00
kor-elf e42ddded71 Add port-based traffic control support to firewall configuration
- Introduced `Ports` struct with customizable fields for numbers, directions, protocols, actions, and rate limiting.
- Added methods to convert port configurations into `InPorts` and `OutPorts`.
- Updated `firewall` settings to include port-related configurations and extended validation.
- Enhanced input and output reload methods to process port-based rules for better granularity.
- Updated `firewall.toml` with port settings, including examples and documentation.
2025-11-01 10:58:00 +05:00
kor-elf 7abdd78ad5 Add IPv6 support to firewall configuration
- Introduced `IP6` struct with `enable` and `icmp_strict` options.
- Extended `firewall.toml` with new IPv6-related settings and documentation.
- Updated input reload methods to include IPv6 rules and ICMPv6 handling.
- Added strict ICMPv6 mode with granular rule definitions.
- Incorporated IPv6 support in settings validation and configuration logic.
2025-10-29 22:27:08 +05:00
kor-elf 165b6f8d79 Add centralized validation for firewall and daemon configurations
- Introduced `validate` package for centralized configuration validation.
- Added validation for paths, filenames, and specific extensions (e.g., `.toml`, `.pid`, `.log`).
- Enhanced `firewall` settings with validation logic (e.g., `table_name`, `chain_input_name`, `saves_rules_path`, `icmp_in_rate`, `input_drop`).
- Updated `daemon` PID file handling for additional checks on file type and content.
- Improved error handling and validation coverage for settings initialization.
2025-10-29 21:55:52 +05:00
kor-elf 10e13be291 Add centralized firewall chain management and default policy configuration
- Consolidated chain creation and management into a `chain` package for improved structure.
- Introduced default policies (`default_allow_input`, `default_allow_output`, `default_allow_forward`) for input, output, and forward traffic control.
- Added support for policy-specific drop behaviors (`input_drop`, `output_drop`, `forward_drop`) to firewall configuration.
- Updated reload methods to utilize the centralized `chain` management interface.
- Enhanced `firewall.toml` with new policy options and improved documentation.
- Refactored related code to streamline chain handling and configuration logic.
2025-10-29 00:39:55 +05:00
kor-elf dde619f6be Add ICMP traffic handling in firewall configuration
- Introduced `icmp_in`, `icmp_in_rate`, `icmp_out`, `icmp_out_rate`, and `icmp_timestamp_drop` options for ICMP traffic control.
- Added rules for managing incoming and outgoing ICMP traffic based on configuration settings.
- Updated `firewall.toml` with ICMP-related options and documentation.
- Enhanced input and output reload methods to include ICMP traffic handling.
2025-10-28 20:54:39 +05:00
kor-elf 52d5df5ca8 Add packet filtering for invalid and out-of-order packets
- Introduced `packet_filter` option to enable dropping invalid and out-of-order packets.
- Added new nftables chains and rules to handle invalid state and TCP flag anomalies.
- Updated `firewall.toml` with `packet_filter` configuration and documentation.
- Enhanced firewall initialization to include packet filtering logic.
2025-10-27 22:40:02 +05:00
kor-elf 6b9af27090 Add DNS traffic handling with strict nftables rules
- Introduced `dns_strict` and `dns_strict_ns` options for enhanced DNS traffic control.
- Added parsing of `/etc/resolv.conf` to retrieve and process nameserver addresses.
- Updated firewall configuration to apply specific rules for DNS traffic.
- Enhanced `firewall.toml` with new options for DNS strict mode and documentation.
2025-10-27 20:54:31 +05:00
kor-elf 2ada717857 Refactor firewall options into a dedicated struct
- Extracted `SavesRules` and `SavesRulesPath` into `options` struct for improved organization.
- Updated `firewall` settings to utilize the new `options` struct.
- Modified `firewall.toml` configuration to reflect the structural changes.
- Adjusted related methods and functions to handle the new structure.
2025-10-27 19:20:27 +05:00
kor-elf a9892bdb7f Add fallback to clear firewall rules on reload failure
- Updated `daemon.go` to invoke `d.firewall.ClearRules()` if `d.firewall.Reload()` fails, ensuring a clean state.
2025-10-27 00:01:08 +05:00
kor-elf 5b55ae506a Fix import formatting in start.go to improve code readability and maintain consistency. 2025-10-26 23:30:06 +05:00
kor-elf c30b8043c3 Correct import order in main.go for improved readability and adherence to Go conventions. 2025-10-26 23:28:44 +05:00
kor-elf 3fa3c2bc88 Wrap file.Close() in a deferred function to handle error suppression during PID file operations. 2025-10-26 23:28:13 +05:00
kor-elf 72e76c660e Add default policies and enhanced nftables chain handling in firewall
- Introduced default input, output, and forward policies for firewall management.
- Enhanced chain configuration with specific naming for input, output, and forward chains.
- Updated `firewall.toml` with policy settings and chain name configurations.
- Refactored `firewall` package to include reload and configuration synchronization for policies.
2025-10-26 23:26:11 +05:00
kor-elf 7f882fa3ae Update import paths to use fully qualified module name
- Replaced local import paths with fully qualified paths prefixed by `git.kor-elf.net`.
- Updated `go.mod` module declaration to match the new module name.
2025-10-26 19:58:22 +05:00
kor-elf 729953cc17 Add firewall package with nftables support and configuration handling
- Introduced `firewall` package with `API` interface for managing nftables rules.
- Added `Reload`, `ClearRules`, and `SavesRules` methods for rule management.
- Implemented configuration parsing for firewall settings using `firewall.toml`.
- Updated `internal/setting` with default firewall configurations.
- Integrated `go-nftables-client` for low-level manipulation of nftables.
2025-10-26 00:20:41 +05:00
kor-elf 3d1d4f5200 Add testing mode and firewall configuration to daemon
- Introduced `testing` and `testing_interval` options in configuration for test mode management.
- Added support for firewall configuration and integration via `firewall` package.
- Updated daemon lifecycle to handle testing mode and test interval expiration.
- Extended `kor-elf-shield.toml` with new configuration options and documentation.
2025-10-26 00:19:44 +05:00
kor-elf 2a884b24b9 Refactor runDaemon to pass context and improve logger cleanup
- Updated `runDaemon` to accept and propagate context for better lifecycle management.
- Wrapped logger `Sync` call in a function to handle errors gracefully.
2025-10-25 20:40:35 +05:00
kor-elf 6a89550737 Validate logger in pidfile and improve PID-related log messages
- Ensure `logger` is not nil during PID file initialization.
- Standardize usage of "PID" in log messages for consistency and clarity.
2025-10-25 20:38:41 +05:00
kor-elf 927bd8162d Add daemon package with support for start command
- Introduced `Daemon` interface and default implementation for process management.
- Added `start` CLI command to initialize and run the daemon.
- Integrated PID file handling using `pidfile` package for ensuring single process execution.
- Updated main application to register `start` command.
2025-10-13 20:44:59 +05:00
kor-elf a07357cdd1 Add pidfile package to manage daemon PID files
- Introduced `PidFile` interface with methods for PID file validation, creation, and removal.
- Implemented `EnsureNoOtherProcess` to handle PID file conflicts and outdated entries.
- Added structured logger support for better observability in PID file operations.
2025-10-13 20:42:48 +05:00
kor-elf 23aaeb0dbc Remove unused debug log statement from Config.Log.Level in main.go. 2025-10-13 20:42:03 +05:00
kor-elf a7b88ff4fe Add pid_file configuration and validation in setting package
- Introduced `pid_file` field in configuration with default path.
- Implemented validation for `pid_file` in `ToDaemonOptions` with localized error handling.
- Updated `kor-elf-shield.toml` to include `pid_file` documentation.
2025-10-13 20:41:30 +05:00
kor-elf 932670e36d Refactor EnsureDir to use mkdirAllWithChmod for improved permission handling and directory creation 2025-10-13 20:40:28 +05:00
kor-elf e5ae14d855 Add Fatal method to Logger interface and implement os.Exit(1) behavior
- Introduced `Fatal` method for structured logging with immediate program exit.
- Updated `falseLogger` to implement `Fatal` method.
- Added `zap.AddCallerSkip(1)` for accurate caller information in logs.
- Adjusted `LoggerOptions` argument in `NewLogger` for consistency.
2025-10-13 20:39:20 +05:00
kor-elf 2ffad8584a Add falseLogger as a no-op logger implementation. 2025-10-12 17:21:49 +05:00
kor-elf 1ef42ce3ba Add Logger interface and implementation using zap for structured logging 2025-10-12 17:21:25 +05:00