Skip to content

Commit 0db93b2

Browse files
committed
addrwatch: Various fixes
Makefile changes include: * Remove USE_UCLIBC, as uclibc is no longer supported * Package output modules * Move main binary (back) to /usr/sbin, as it is system administration related and requires superuser privileges New patches: * 003-add-space-for-null-byte.patch - from fln/addrwatch@374cfd2 * 004-more-specific-library-linking.patch - from fln/addrwatch#24 Init script changes include: * Change from explicit disable to explicit enable, so that the service is disabled by default and on first install * Set config option default values to default values of the main binary * Fix command-line option names and format (from https://forum.openwrt.org/t/cant-start-addrwatch-service/60499/3) * Always use the --quiet command-line option, as the procd instance is not configured to capture stdout/stderr * Change the syslog config option to start the syslog output module Signed-off-by: Jeffery To <jeffery.to@gmail.com>
1 parent f7432ce commit 0db93b2

5 files changed

Lines changed: 168 additions & 25 deletions

File tree

net/addrwatch/Makefile

Lines changed: 75 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
99

1010
PKG_NAME:=addrwatch
1111
PKG_VERSION:=1.0.2
12-
PKG_RELEASE:=2
12+
PKG_RELEASE:=3
1313

1414
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
1515
PKG_SOURCE_URL:=https://github.com/fln/addrwatch/releases/download/v$(PKG_VERSION)
@@ -21,34 +21,102 @@ PKG_LICENSE_FILES:=COPYING
2121

2222
PKG_INSTALL:=1
2323
PKG_BUILD_PARALLEL:=1
24-
PKG_BUILD_DEPENDS:=USE_UCLIBC:argp-standalone USE_MUSL:argp-standalone
24+
PKG_BUILD_DEPENDS:=USE_MUSL:argp-standalone
25+
PKG_FIXUP:=autoreconf
2526

2627
include $(INCLUDE_DIR)/package.mk
2728

28-
define Package/addrwatch
29+
define Package/addrwatch/Default
2930
SECTION:=net
3031
CATEGORY:=Network
31-
DEPENDS:=+libpcap +libevent2
3232
TITLE:=IPv4/IPv6 and ethernet address pairing tool
3333
URL:=https://github.com/fln/addrwatch
3434
endef
3535

36-
define Package/addrwatch/description
36+
define Package/addrwatch/Default/description
3737
This is a tool similar to arpwatch. It main purpose is to monitor network and
3838
log discovered ethernet/ip pairings. Addrwatch is extremely useful in networks
3939
with IPv6 autoconfiguration (RFC4862) enabled. It allows to track IPv6
4040
addresses of hosts using IPv6 privacy extensions (RFC4941).
4141
endef
4242

43+
define Package/addrwatch
44+
$(call Package/addrwatch/Default)
45+
DEPENDS:=+libpcap +libevent2
46+
endef
47+
48+
define Package/addrwatch/description
49+
$(call Package/addrwatch/Default/description)
50+
51+
This contains the main addrwatch program.
52+
endef
53+
54+
define Package/addrwatch-mysql
55+
$(call Package/addrwatch/Default)
56+
TITLE+= (MySQL output module)
57+
DEPENDS:=+addrwatch +libmariadb
58+
endef
59+
60+
define Package/addrwatch-mysql/description
61+
$(call Package/addrwatch/Default/description)
62+
63+
This contains the MySQL output module.
64+
endef
65+
66+
define Package/addrwatch-stdout
67+
$(call Package/addrwatch/Default)
68+
TITLE+= (stdout output module)
69+
DEPENDS:=+addrwatch
70+
endef
71+
72+
define Package/addrwatch-stdout/description
73+
$(call Package/addrwatch/Default/description)
74+
75+
This contains the stdout output module.
76+
endef
77+
78+
define Package/addrwatch-syslog
79+
$(call Package/addrwatch/Default)
80+
TITLE+= (syslog output module)
81+
DEPENDS:=+addrwatch
82+
endef
83+
84+
define Package/addrwatch-syslog/description
85+
$(call Package/addrwatch/Default/description)
86+
87+
This contains the syslog output module.
88+
endef
89+
4390
define Package/addrwatch/conffiles
4491
/etc/config/addrwatch
4592
endef
4693

94+
CONFIGURE_ARGS+= \
95+
--enable-mysql
96+
4797
define Package/addrwatch/install
48-
$(INSTALL_DIR) $(1)/usr/bin $(1)/etc/config $(1)/etc/init.d
49-
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/addrwatch $(1)/usr/bin/
98+
$(INSTALL_DIR) $(1)/usr/sbin $(1)/etc/config $(1)/etc/init.d
99+
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/addrwatch $(1)/usr/sbin/
50100
$(INSTALL_BIN) ./files/addrwatch.init $(1)/etc/init.d/addrwatch
51101
$(INSTALL_CONF) ./files/addrwatch.config $(1)/etc/config/addrwatch
52102
endef
53103

104+
define Package/addrwatch-mysql/install
105+
$(INSTALL_DIR) $(1)/usr/sbin
106+
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/addrwatch_mysql $(1)/usr/sbin/
107+
endef
108+
109+
define Package/addrwatch-stdout/install
110+
$(INSTALL_DIR) $(1)/usr/sbin
111+
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/addrwatch_stdout $(1)/usr/sbin/
112+
endef
113+
114+
define Package/addrwatch-syslog/install
115+
$(INSTALL_DIR) $(1)/usr/sbin
116+
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/addrwatch_syslog $(1)/usr/sbin/
117+
endef
118+
54119
$(eval $(call BuildPackage,addrwatch))
120+
$(eval $(call BuildPackage,addrwatch-mysql))
121+
$(eval $(call BuildPackage,addrwatch-stdout))
122+
$(eval $(call BuildPackage,addrwatch-syslog))
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

22
config addrwatch
3-
option disabled '0'
3+
option enabled '0'
44
list interface 'lan'
55
#list interface 'wan'
6-
#option syslog '1'
6+
#option syslog '0'
77
#option verbose '0'
88
#option output '/var/log/addrwatch'
99
#list blacklist '192.168.1.1'
1010
#option hashsize '1'
11-
#option ratelimit '-1'
11+
#option ratelimit '0'
1212

net/addrwatch/files/addrwatch.init

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@ USE_PROCD=1
66

77
validate_section_addrwatch() {
88
uci_load_validate addrwatch addrwatch "$1" "$2" \
9-
'disabled:bool:0' \
9+
'enabled:bool:0' \
1010
'interface:list(string):lan' \
11-
'syslog:bool:1' \
11+
'syslog:bool:0' \
1212
'output:string' \
13-
'quiet:bool:0' \
1413
'verbose:bool:0' \
1514
'ipv4only:bool:0' \
1615
'ipv6only:bool:0' \
1716
'blacklist:list(or(ip4addr,ip6addr))' \
18-
'hashsize:range(1,65536):1024'\
19-
'ratelimit:integer:3600'
17+
'hashsize:range(1,65536):1'\
18+
'ratelimit:integer:0'
2019
}
2120

2221
start_instance() {
@@ -27,7 +26,7 @@ start_instance() {
2726
echo "validation of config $cfg failed"
2827
return 1
2928
}
30-
[ $disabled -ne 0 ] && return 1
29+
[ $enabled -eq 1 ] || return 1
3130

3231
for iface in $interface; do
3332
local netdev
@@ -36,15 +35,13 @@ start_instance() {
3635
done
3736

3837
procd_open_instance
39-
procd_set_param command /usr/sbin/addrwatch
40-
[ "$syslog" -eq 1 ] && procd_append_param command --syslog
41-
[ -n "$output" ] && procd_append_param command --output "$output"
42-
[ "$quiet" -eq 1 ] && procd_append_param command --quiet
43-
[ "$verbose" -eq 1 ] && procd_append_param command --verbose
44-
[ "$ipv4only" -eq 1 ] && procd_append_param command --ipv4only
45-
[ "$ipv6only" -eq 1 ] && procd_append_param command --ipv6only
46-
[ -n "$hashsize" ] && procd_append_param command --hashsize "$hashsize"
47-
[ -n "$ratelimit" ] && procd_append_param command --ratelimit "$ratelimit"
38+
procd_set_param command /usr/sbin/addrwatch --quiet
39+
[ -n "$output" ] && procd_append_param command "--output=$output"
40+
[ "$verbose" -eq 1 ] && procd_append_param command "--verbose"
41+
[ "$ipv4only" -eq 1 ] && procd_append_param command "--ipv4-only"
42+
[ "$ipv6only" -eq 1 ] && procd_append_param command "--ipv6-only"
43+
[ -n "$hashsize" ] && procd_append_param command "--hashsize=$hashsize"
44+
[ -n "$ratelimit" ] && procd_append_param command "--ratelimit=$ratelimit"
4845
for blitem in $blacklist; do
4946
procd_append_param command "--blacklist=$blitem"
5047
done
@@ -57,6 +54,18 @@ start_instance() {
5754
done
5855
procd_close_trigger
5956
procd_close_instance
57+
58+
[ "$syslog" -eq 1 ] && {
59+
if [ -x /usr/sbin/addrwatch_syslog ]; then
60+
procd_open_instance
61+
procd_set_param command /usr/sbin/addrwatch_syslog
62+
procd_set_param respawn
63+
procd_close_instance
64+
else
65+
echo "Cannot find /usr/sbin/addrwatch_syslog" >&2
66+
echo "Install the addrwatch-syslog package to enable syslog output" >&2
67+
fi
68+
}
6069
}
6170

6271
start_service() {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
From 374cfd2cabe4db9882d8a210adff430cc579f859 Mon Sep 17 00:00:00 2001
2+
From: Julius Kriukas <julius@kriukas.lt>
3+
Date: Sun, 8 Mar 2020 12:46:55 +0200
4+
Subject: [PATCH] Use HOST_NAME_MAX+1 to add space for null byte
5+
6+
---
7+
src/addrwatch.c | 2 +-
8+
1 file changed, 1 insertion(+), 1 deletion(-)
9+
10+
--- a/src/addrwatch.c
11+
+++ b/src/addrwatch.c
12+
@@ -501,7 +501,7 @@ int main(int argc, char *argv[])
13+
argp_parse(&argp, argc, argv, 0, &optind, 0);
14+
15+
if (!cfg.hostname) {
16+
- cfg.hostname_len = HOST_NAME_MAX;
17+
+ cfg.hostname_len = HOST_NAME_MAX + 1;
18+
cfg.hostname = (char *)calloc(cfg.hostname_len, sizeof(char));
19+
gethostname(cfg.hostname, cfg.hostname_len);
20+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
From 1988f6228225e10bccc50941798f1e1b4ca1ff62 Mon Sep 17 00:00:00 2001
2+
From: Jeffery To <jeffery.to@gmail.com>
3+
Date: Fri, 18 Jun 2021 15:46:47 +0800
4+
Subject: [PATCH] More specific library linking
5+
6+
Currently, the main binary and all output modules are linked to the same
7+
set of libraries. This changes the linking so that only the main binary
8+
is linked to pcap, and only addrwatch_mysql is linked to mysqlclient.
9+
10+
This allows the main binary and output modules to be packaged separately
11+
with fewer dependencies for each individual package.
12+
---
13+
configure.ac | 4 ++--
14+
src/Makefile.am | 3 ++-
15+
2 files changed, 4 insertions(+), 3 deletions(-)
16+
17+
--- a/configure.ac
18+
+++ b/configure.ac
19+
@@ -12,7 +12,7 @@ optional_modules=""
20+
AC_SUBST([optional_modules])
21+
22+
# Checks for libraries.
23+
-AC_CHECK_LIB([pcap], [pcap_open_live])
24+
+AC_CHECK_LIB([pcap], [pcap_open_live], :)
25+
AC_CHECK_LIB([rt], [shm_open])
26+
27+
PKG_CHECK_MODULES(LIBEVENT, [libevent >= 1.4], , [
28+
@@ -46,7 +46,7 @@ AC_ARG_ENABLE([sqlite3],
29+
)
30+
AC_ARG_ENABLE([mysql],
31+
AS_HELP_STRING([--enable-mysql], [Enable MySQL database output]),
32+
- AC_CHECK_LIB([mysqlclient], [mysql_real_connect], , [
33+
+ AC_CHECK_LIB([mysqlclient], [mysql_real_connect], :, [
34+
AC_MSG_ERROR([Unable to find libmysqlclient.])
35+
])
36+
optional_modules="${optional_modules} addrwatch_mysql"
37+
--- a/src/Makefile.am
38+
+++ b/src/Makefile.am
39+
@@ -9,5 +9,6 @@ addrwatch_stdout_SOURCES = addrwatch_std
40+
addrwatch_syslog_SOURCES = addrwatch_syslog.c shm_client.c shm_client.h
41+
addrwatch_mysql_SOURCES = addrwatch_mysql.c shm_client.c shm_client.h util.c util.h
42+
43+
-addrwatch_LDADD = @LIBEVENT_LIBS@
44+
+addrwatch_LDADD = @LIBEVENT_LIBS@ -lpcap
45+
+addrwatch_mysql_LDADD = -lmysqlclient
46+

0 commit comments

Comments
 (0)