For the adventurous here is a patch that enables this feature:
diff -ru a/etc/init.d/log b/etc/init.d/log
--- a/etc/init.d/log 2023-03-30 14:49:52.382027565 +0200
+++ b/etc/init.d/log 2023-03-30 14:49:52.378694231 +0200
@@ -20,7 +20,9 @@
'log_port:port:514' \
'log_proto:or("tcp", "udp"):udp' \
'log_trailer_null:bool:0' \
- 'log_prefix:string'
+ 'log_prefix:string' \
+ 'log_use_dhcp:bool:1' \
+ 'log_dhcp_interface:list(string):lan'
}
validate_log_daemon()
@@ -65,8 +67,31 @@
start_service_remote()
{
- PIDCOUNT="$(( ${PIDCOUNT} + 1))"
- local pid_file="/var/run/logread.${PIDCOUNT}.pid"
+ # If someone really wants to automatically search all interfaces
+ # aka placing an asterisk in the log_dhcp_interface list
+ [ "$log_dhcp_interface" = "*" ] && {
+ echo "Searching for all interfaces! That's a security risk."
+ log_dhcp_interface="$(ubus call network.interface dump | \
+ jsonfilter -e "@.interface[@]['interface']")"
+ }
+
+ # There could be more than one server be published via DHCP, catch 'em all.
+ [ "$log_remote" -ne 0 -a "$log_use_dhcp" -ne 0 -a -z "$log_ip" ] && {
+ for entry in $log_dhcp_interface; do
+ log_ip="$log_ip $(ubus call network.interface."$entry" status | \
+ jsonfilter -e "@.data['logserver']")"
+ done
+ }
+
+ # To remove duplicate IP adresses
+ _log_ip=$log_ip; log_ip=''
+ for entry in $_log_ip; do
+ local duplicate=0
+ for log_entry in $log_ip; do
+ [ "$entry" = "$log_entry" ] && duplicate=1
+ done
+ [ "$duplicate" = 0 ] && log_ip="$log_ip $entry"
+ done
[ "$2" = 0 ] || {
echo "validation failed"
@@ -76,14 +101,19 @@
[ -z "${log_ip}" ] && return
[ -z "${log_hostname}" ] && log_hostname=$(cat /proc/sys/kernel/hostname)
- procd_open_instance logremote
- procd_set_param command "$PROG" -f -h "$log_hostname" -r "$log_ip" "${log_port}" -p "$pid_file"
- case "${log_proto}" in
- "udp") procd_append_param command -u;;
- "tcp") [ "${log_trailer_null}" -eq 1 ] && procd_append_param command -0;;
- esac
- [ -z "${log_prefix}" ] || procd_append_param command -P "${log_prefix}"
- procd_close_instance
+ for _log_ip in $log_ip; do
+ PIDCOUNT="$(( ${PIDCOUNT} + 1))"
+ local pid_file="/var/run/logread.${PIDCOUNT}.pid"
+
+ procd_open_instance logremote."$PIDCOUNT"
+ procd_set_param command "$PROG" -f -h "$log_hostname" -r "$_log_ip" "${log_port}" -p "$pid_file"
+ case "${log_proto}" in
+ "udp") procd_append_param command -u;;
+ "tcp") [ "${log_trailer_null}" -eq 1 ] && procd_append_param command -0;;
+ esac
+ [ -z "${log_prefix}" ] || procd_append_param command -P "${log_prefix}"
+ procd_close_instance
+ done
}
register_mount_trigger()
diff -ru a/lib/netifd/dhcp.script b/lib/netifd/dhcp.script
--- a/lib/netifd/dhcp.script 2023-03-30 14:49:46.368694193 +0200
+++ b/lib/netifd/dhcp.script 2023-03-30 14:51:23.235361487 +0200
@@ -52,6 +52,15 @@
echo "Environment variable 'timesvr' will be deprecated; use 'timesrv' instead."
fi
+ if [ -n "$opt7" -a -z "$logsrv" ]; then
+ # IPv4 Hex to IP-notation conversion
+ [[ "$opt7" =~ ^[[:xdigit:]]{8}$ ]] && \
+ logsrv="$(printf "%d.%d.%d.%d\n" $(echo "$opt7" | sed 's/../0x& /g'))"
+ # IPv6 Hex to IP-Notation conversion #### UNTESTED. Always 64 bit? ####
+ [[ "$opt7" =~ ^[[:xdigit:]]{32}$ ]] && \
+ logsrv="$(echo "$opt7" | sed 's/..../:&/g'))"
+ fi
+
proto_add_data
[ -n "$ZONE" ] && json_add_string zone "$ZONE"
[ -n "$ntpsrv" ] && json_add_string ntpserver "$ntpsrv"
@@ -61,6 +70,7 @@
[ -n "$timezone" ] && json_add_int timezone "$timezone"
[ -n "$lease" ] && json_add_int leasetime "$lease"
[ -n "$serverid" ] && json_add_string dhcpserver "$serverid"
+ [ -n "$logsrv" ] && json_add_string logserver "$logsrv"
proto_close_data
proto_send_update "$INTERFACE"
It introduces two new options to the uci system and enables the ability to send log messages to multiple IP addresses, so with it it's possible to set multiple values to the log_ip
option in the simplest way, if you just want that you needn't care about the new options, just the patch.
The first added option is the boolean switch log_use_dhcp
, it enables searching for DHCP provided log servers and is disabled by default.
To enable it issue uci set system.@system[0].log_use_dhcp='1'
The second one is optional, log_dhcp_interface
, it holds a list of the interfaces where the log system shall search for dhcp provided log server IPs. It defaults to lan
, by default the most trustworthy network in my opinion. You can alter and add interfaces here eg. with
uci set system.@system[0].log_dhcp_interface='lan'
At the end a uci set network.lan.reqopts="7"
enables the obtainment of DHCP provided log server IP addresses on that particular interface.
With IPv4 it works here flawless tested with 22.03.0, 22.03.3 and Snapshot. IPv6 is untested, if someone will test it I'd be happy about a short response if it works. In the patch it expects a completely transmitted IP address, not a shortened one, should work, but I'm not shure.
Have fun with it