[Bug 272818] hv_kvp_daemon high CPU usage on Internet router

From: <bugzilla-noreply_at_freebsd.org>
Date: Mon, 31 Jul 2023 14:03:02 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=272818

--- Comment #4 from Greg Becker <greg@codeconcepts.com> ---
Thanks Wencey, that's exactly what I wanted to see, which invalidates all my
original presumptions.

So, now presuming that there are contexts in which these hv_kvp_daemon scripts
run where there is a default route, then the pipeline should return that route. 

So I deleted the default route on one of my machines to see what 'route -n get
default' (thanks Yuri!) would return, and curiously it prints a "No error: 0"
error message to stderr and exits zero.  However, my new awk command should
give the same error as from the grep in the original pipeline when there is no
default route.


root@sm1:~ # route delete default
delete net default

root@sm1:~ # route -n get default
route: route has not been found: No error: 0
root@sm1:~ # echo $?
0

root@sm1:~ # route -n get default | awk -v ifce=ix0 '$1 ~ /gateway:/ || ($1 ~
/interface:/ && $2 == ifce) {val[n++] = $2} END{ if (n == 2) print val[0]; exit
(n != 2)}'
route: route has not been found: No error: 0
root@sm1:~ # echo $?
1


And after I restore my default route it seems to do the right thing:

root@sm1:~ # route add default 172.16.1.1
root@sm1:~ # route -n get default | awk -v ifce=ix0 '$1 ~ /gateway:/ || ($1 ~
/interface:/ && $2 ==
ifce) {val[n++] = $2} END{ if (n == 2) print val[0]; exit (n != 2)}'
172.16.1.1

root@sm1:~ # echo $?
0


So, it appears to me that the following pipeline would work.  Is there any way
you can test this out?  Presumably the interface is a positional parameter to
the script, so you'd need to replace the "ix0" in my awk command with something
like ifce="$1" or whatever...  Note that this also presumes the output of
'route -n get default' is fairly rigid.


route -n get default | awk -v ifce=ix0 '$1 ~ /gateway:/ || ($1 ~ /interface:/
&& $2 == ifce) {val[n++] = $2} END{ if (n == 2) print val[0]; exit (n != 2)}'


I'm not the hp_kvp_daemon maintainer, so I wont speculate as to why they are
doing this directly via route(4).

Hope this helps!
Greg

-- 
You are receiving this mail because:
You are the assignee for the bug.