Skip to content

Commit

Permalink
Merge pull request #5 from Fail-Safe/main
Browse files Browse the repository at this point in the history
Switch to TXT record per neighbor
  • Loading branch information
kissadamfkut committed Apr 21, 2023
2 parents 82c82da + e3fbd2f commit f39af8a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -19,5 +19,4 @@

## Known issues

- SSIDs with '|' character are not supported at the moment
- With large number of APs (>20) the full umdns update takes a few interations/minutes
9 changes: 4 additions & 5 deletions bin
Expand Up @@ -5,7 +5,7 @@
NAME=rrm_nr

# We wrap everything into this function to allow GC by ash, esp. for low-mem devices
function _do_updates() {
_do_updates() {
local rrm_nr_lists

OIFS=$IFS
Expand All @@ -16,7 +16,7 @@ function _do_updates() {
for wifi_iface in $(ubus list hostapd.* | awk -F. '{ print $2; }'); do
net_ssid=$(iwinfo ${wifi_iface} info | head -n1 | cut -d\" -f2)
[ -z "${net_ssid}" ] && logger -t "rrm_nr" -p daemon.error "${wifi_iface}: does not have ssid according to iwinfo." && continue

# Discover other nodes
rrm_nr_lists=""

Expand All @@ -26,9 +26,8 @@ function _do_updates() {
[ ${net_ssid} = $(iwinfo ${other_iface} info | head -n1 | cut -d\" -f2) ] && rrm_nr_lists="${rrm_nr_lists}"$'\n'"$(/bin/ubus call hostapd.${other_iface} rrm_nr_get_own | /usr/bin/jsonfilter -e '$.value')"
done


# Sort at the end stabilizes the result, so we can compare it across runs
for discovered_node in $(ubus call umdns browse | jsonfilter -e '@["_rrm_nr._udp"][*].txt' | tr '|' '\n' | grep "\"${net_ssid}\""); do #TODO replace tr with sed "s= ]|[ = ]\n[ ="
for discovered_node in $(ubus call umdns browse '{ "service": "_rrm_nr._udp", "array": true }' | jsonfilter -e '@["_rrm_nr._udp"][*].txt[*]' | grep "\"${net_ssid}\"" | sed "s/${net_ssid}=//g"); do
rrm_nr_lists="${rrm_nr_lists}"$'\n'"${discovered_node}"
done

Expand Down Expand Up @@ -58,4 +57,4 @@ while true; do
sleep 60
done

exit 0
exit 0
17 changes: 12 additions & 5 deletions initscript
Expand Up @@ -22,24 +22,31 @@ start_service() {
IFS=$'\x0a'

for value in $(ubus list hostapd.*); do
rrm_own="${rrm_own}|$(/bin/ubus call ${value} rrm_nr_get_own | /usr/bin/jsonfilter -e '$.value')"
curr_value=$(/bin/ubus call "${value}" rrm_nr_get_own | /usr/bin/jsonfilter -e '$.value')
ssid=$(echo "$curr_value" | awk -F, '{ print $2; }' | sed 's/^ *"//;s/" *$//')
# Using + as the delimiter instead of |. Because + is an invalid character to use in SSID naming,
# this removes the known issue where | could not be used in the SSID name.
rrm_own="${rrm_own}+${ssid}=${curr_value}"
done

rrm_own="${rrm_own#*+}"
IFS='+'
set -- $rrm_own

IFS=$OIFS

procd_open_instance
procd_set_param command /bin/sh "/usr/bin/rrm_nr"
#https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml?search=5247
procd_add_mdns "rrm_nr" "udp" "5247" "${rrm_own:1}"
procd_add_mdns "rrm_nr" "udp" "5247" "$@"
procd_close_instance
}

boot(){
boot() {
sleep 30
start
}

service_triggers()
{
service_triggers() {
procd_add_reload_trigger wireless
}
17 changes: 17 additions & 0 deletions umdns_repo.patch
@@ -0,0 +1,17 @@
diff --git a/package/network/services/umdns/Makefile b/package/network/services/umdns/Makefile
index a25233ad5a..3f3c64a240 100644
--- a/package/network/services/umdns/Makefile
+++ b/package/network/services/umdns/Makefile
@@ -12,9 +12,9 @@ PKG_RELEASE:=$(AUTORELEASE)

PKG_SOURCE_URL=$(PROJECT_GIT)/project/mdnsd.git
PKG_SOURCE_PROTO:=git
-PKG_SOURCE_DATE:=2021-05-13
-PKG_SOURCE_VERSION:=b777a0b53f7d89ab2a60e3eed7d98036806da9a4
-PKG_MIRROR_HASH:=54992acf7edd32610de7bcb0ea7c58b20f69bf1ac20be69e76abcff41f25e775
+PKG_SOURCE_DATE:=2023-01-16
+PKG_SOURCE_VERSION:=65b3308d13de7d7975444d34389651612e2a4d38
+PKG_MIRROR_HASH:=945fdf51a299b68982aab74e8fba5614f2553a7b4c49a3a53b3093ea8aac0279

PKG_MAINTAINER:=John Crispin <john@phrozen.org>
PKG_LICENSE:=LGPL-2.1

0 comments on commit f39af8a

Please sign in to comment.