From bbfa7c6c22e4981138f09ccca08a7bf5650dbcf9 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Fri, 2 Jun 2023 21:10:23 +0700 Subject: [PATCH] internal/router: relax dnsmasq lease file parsing condition On DD-WRT v3.0-r52189, dnsmasq version 2.89 lease format looks like: 1685794060 00:00:00:00:00:04 9 It has 6 fields, while the current parser only looks for line with exact 5 fields, which is too restricted. In fact, the parser shold just skip line with less than 4 fields, because the 4th field is the hostname, which is the last client info that ctrld needs. --- internal/router/client_info.go | 2 +- internal/router/client_info_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/router/client_info.go b/internal/router/client_info.go index 1548c67..97446c0 100644 --- a/internal/router/client_info.go +++ b/internal/router/client_info.go @@ -105,7 +105,7 @@ func dnsmasqReadClientInfoReader(reader io.Reader) error { r := routerPlatform.Load() return lineread.Reader(reader, func(line []byte) error { fields := bytes.Fields(line) - if len(fields) != 5 { + if len(fields) < 4 { return nil } mac := string(fields[1]) diff --git a/internal/router/client_info_test.go b/internal/router/client_info_test.go index 5ea8b65..fac801c 100644 --- a/internal/router/client_info_test.go +++ b/internal/router/client_info_test.go @@ -78,6 +78,12 @@ lease 192.168.1.2 { iscDHCPReadClientInfoReader, "00:00:00:00:00:02", }, + { + "", + `1685794060 00:00:00:00:00:04 192.168.0.209 cuonglm-ThinkPad-X1-Carbon-Gen-9 00:00:00:00:00:04 9`, + dnsmasqReadClientInfoReader, + "00:00:00:00:00:04", + }, } for _, tc := range tests {