Refactor code structure for improved readability and maintainability

This commit is contained in:
Daniel Lavrushin 2026-04-23 14:10:58 +02:00
parent e46a53843b
commit ca4aca6823
No known key found for this signature in database
GPG key ID: 67D627A2ADB43DD0
5 changed files with 69 additions and 9 deletions

View file

@ -21,7 +21,22 @@ title: Keenetic
1. Plug a USB drive into the router
2. Install Entware through the package manager
More details: https://help.keenetic.com/hc/en-us/articles/360021214160
More details: [help.keenetic.com](https://help.keenetic.com/hc/en-us/articles/360021214160)
## Enable Netfilter components
Keenetic NDMS does not ship all the netfilter kernel modules b4 needs out of the box. Before installing b4, enable the required components:
1. In the router web interface, go to **System settings** → **Component options**
2. Enable **Netfilter** — the base netfilter component
3. Once Netfilter is enabled, a new option appears: enable **Xtables-addons for Netfilter** (provides `xt_connbytes` and other extensions b4 relies on)
4. Apply the changes and wait for the router to reboot or reload components
Then, over SSH, install the iptables userspace:
```bash
opkg install iptables
```
## Install b4
@ -57,3 +72,15 @@ The installer detects the architecture automatically.
:::warning Without Entware
Without Entware, b4 is placed in `/tmp`, which is cleared on every reboot. For persistent operation, Entware is required.
:::
## Troubleshooting
After starting the service, check the log:
```bash
cat /var/log/b4/errors.log
```
If you see `xt_connbytes kernel module is not available`, the Netfilter components weren't enabled correctly — return to [Enable Netfilter components](#enable-netfilter-components) above and make sure both **Netfilter** and **Xtables-addons for Netfilter** are active.
If the log is empty (or has no errors), the b4 web interface should be reachable on the router's LAN IP.

View file

@ -23,7 +23,29 @@ title: Keenetic
1. Вставьте USB-накопитель в роутер
2. Установите Entware через менеджер пакетов
Подробнее: https://help.keenetic.com/hc/ru/articles/360021214160
Подробнее: [help.keenetic.com](https://help.keenetic.com/hc/en-us/articles/360021214160)
## Включите компоненты Netfilter
Прошивка Keenetic NDMS не содержит всех модулей netfilter, которые нужны b4, "из коробки". Перед установкой b4 включите необходимые компоненты:
1. В веб-интерфейсе роутера откройте **Параметры системы** → **Обновление компонентов**
1. Включите компонент **NetFilter** — это базовый компонент netfilter
1. После включения NetFilter в списке появится **Xtables-addons for Netfilter** — включите и его (даёт `xt_connbytes` и другие расширения, от которых зависит b4)
1. Примените изменения и дождитесь перезагрузки / применения компонентов
![20260423140614](../../../../../static/img/keenetic/20260423140614.png)
![20260423140726](../../../../../static/img/keenetic/20260423140726.png)
Затем по SSH установите пользовательскую часть iptables:
```bash
opkg install iptables
```
:::info
Компоненты системы в Keenetic доступны только под учёткой `admin`
:::
## Установка b4
@ -43,11 +65,11 @@ curl -fsSL https://raw.githubusercontent.com/DanielLavrushin/b4/main/install.sh
## Пути
| Что | Где |
| --- | --- |
| Бинарник | `/opt/sbin/b4` |
| Конфигурация | `/opt/etc/b4/b4.json` |
| Сервис | `/opt/etc/init.d/S99b4` |
| Что | Где |
| ------------ | ----------------------- |
| Бинарник | `/opt/sbin/b4` |
| Конфигурация | `/opt/etc/b4/b4.json` |
| Сервис | `/opt/etc/init.d/S99b4` |
## Архитектура
@ -59,3 +81,15 @@ curl -fsSL https://raw.githubusercontent.com/DanielLavrushin/b4/main/install.sh
:::warning Без Entware
Без Entware b4 устанавливается в `/tmp`, который очищается при каждой перезагрузке. Для постоянной работы Entware обязателен.
:::
## Диагностика
После запуска сервиса проверьте лог:
```bash
cat /var/log/b4/errors.log
```
Если там есть `xt_connbytes kernel module is not available`, компоненты Netfilter включены не полностью — вернитесь к разделу [Включите компоненты Netfilter](#включите-компоненты-netfilter) выше и убедитесь, что активированы **оба** компонента: **NetFilter** и **Xtables-addons for Netfilter**.
Если лог пустой (или в нём нет ошибок), веб-интерфейс b4 должен быть доступен по LAN-адресу роутера.

Binary file not shown.

After

Width:  |  Height:  |  Size: 518 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 296 KiB

View file

@ -106,8 +106,7 @@ _keenetic_load_kmods() {
log_info "You may need to enable 'Kernel modules for Netfilter' in the package manager"
fi
# xt_connbytes is mandatory for the iptables backend (b4's tables rules).
if ! _kmod_available "xt_connbytes" && ! _kmod_available "nf_tables"; then
if ! _kmod_available "xt_connbytes" && ! _nft_functional; then
log_warn "xt_connbytes kernel module not available — b4 will fail to start on iptables"
log_info "Enable it via router web UI: System settings > Component options"
log_info " look for 'Netfilter kernel modules' / 'xtables-addons' / 'Connection tracking extensions'"