Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions net/lanstat/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# SPDX-License-Identifier: MIT

include $(TOPDIR)/rules.mk

PKG_NAME:=lanstat
PKG_VERSION:=1.0.1
PKG_RELEASE:=1

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/wbpluto/lanstat/tar.gz/v$(PKG_VERSION)?
PKG_HASH:=5bd75ec0ca1c0217885337919e989e63f945b0c4c37b7a37224a23dac6c27174

PKG_MAINTAINER:=Junwei Huang <hjw@live.cn>
PKG_LICENSE:=MIT
PKG_LICENSE_FILES:=LICENSE

PKG_BUILD_PARALLEL:=1

include $(INCLUDE_DIR)/package.mk

define Package/lanstat
SECTION:=net
CATEGORY:=Network
SUBMENU:=Monitoring
TITLE:=Lightweight native LAN bandwidth monitor with modern Web UI
URL:=https://github.com/wbpluto/lanstat
endef

define Package/lanstat/description
A lightweight, single-binary C11 packet & bandwidth monitor for OpenWrt.
Uses AF_PACKET + TPACKET_V2 zero-copy ring buffer and serves a built-in
gzip-compressed real-time Mbps dashboard with offline IEEE OUI vendor lookup
and multi-language UI without external runtime dependencies.
endef

define Package/lanstat/conffiles
/etc/config/lanstat
endef

define Build/Compile
$(TARGET_CC) $(TARGET_CFLAGS) -std=c11 -Wall -Wextra -I$(PKG_BUILD_DIR)/src \
$(PKG_BUILD_DIR)/src/main.c \
$(PKG_BUILD_DIR)/src/hosts.c \
$(PKG_BUILD_DIR)/src/capture.c \
$(PKG_BUILD_DIR)/src/http.c \
-o $(PKG_BUILD_DIR)/lanstat $(TARGET_LDFLAGS)
endef

define Package/lanstat/install
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/lanstat $(1)/usr/sbin/lanstat
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_CONF) ./files/lanstat.config $(1)/etc/config/lanstat
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/lanstat.init $(1)/etc/init.d/lanstat
endef

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The PR body still lists "optional static LuCI menu entry (Status -> Bandwidth Monitor)", but this package no longer ships one. Please update the description to point to the separate luci-app-lanstat PR.


Generated by Claude Code

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed, thanks


Generated by Claude Code


$(eval $(call BuildPackage,lanstat))
9 changes: 9 additions & 0 deletions net/lanstat/files/lanstat.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
config lanstat 'main'
option enabled '1'
option interface 'lan'
option bind '0.0.0.0'
option port '6670'
option promisc '1'
option track_external '0'
option max_hosts '512'
option ring_kb '1024'
39 changes: 39 additions & 0 deletions net/lanstat/files/lanstat.init
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/sh /etc/rc.common

START=95
STOP=10
USE_PROCD=1

PROG=/usr/sbin/lanstat

start_service() {
local enabled iface dev bind port promisc track_ext max_hosts ring_kb

. /lib/functions/network.sh
config_load lanstat
config_get_bool enabled main enabled 1
[ "$enabled" -eq 1 ] || return 0

config_get iface main interface "lan"
network_get_device dev "$iface" || dev="$iface"
[ -n "$dev" ] || dev="$iface"
config_get bind main bind "0.0.0.0"
config_get port main port "6670"
config_get_bool promisc main promisc 1
config_get_bool track_ext main track_external 0
config_get max_hosts main max_hosts "512"
config_get ring_kb main ring_kb "1024"

procd_open_instance
procd_set_param command "$PROG" -i "$dev" -b "$bind" -p "$port" -m "$max_hosts" -r "$ring_kb"
[ "$promisc" -eq 0 ] && procd_append_param command -n
[ "$track_ext" -eq 1 ] && procd_append_param command -e
procd_set_param respawn 3600 5 5
procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
}

service_triggers() {
procd_add_reload_trigger "lanstat"
}