From: Masatake YAMATO Date: Wed, 26 Oct 2022 03:01:37 +0000 (+0900) Subject: lsfd: unify the code for reading /proc/net/tcp and udp X-Git-Tag: v2.39-rc1~448^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=58d2f31eb08dc36c5b1ab6b630da3bff346c59c4;p=thirdparty%2Futil-linux.git lsfd: unify the code for reading /proc/net/tcp and udp Signed-off-by: Masatake YAMATO --- diff --git a/misc-utils/lsfd-sock-xinfo.c b/misc-utils/lsfd-sock-xinfo.c index 263ffc36e9..5ee8ee933a 100644 --- a/misc-utils/lsfd-sock-xinfo.c +++ b/misc-utils/lsfd-sock-xinfo.c @@ -596,9 +596,22 @@ static struct sock_xinfo_class tcp_xinfo_class = { .free = NULL, }; +static bool L3_verify_initial_line(const char *line) +{ + /* At least we expect two white spaces. */ + if (strncmp (line, " ", 2) != 0) + return false; + line += 2; + + /* Skip white spaces. */ + while (*line == ' ') + line++; + + return (strncmp(line, "sl", 2) == 0); +} + #define TCP_LINE_LEN 256 static void load_xinfo_from_proc_inet_L3(ino_t netns_inode, const char *proc_file, - bool (*verify_initial_line)(const char *), struct sock_xinfo_class *class) { char line[TCP_LINE_LEN]; @@ -610,7 +623,7 @@ static void load_xinfo_from_proc_inet_L3(ino_t netns_inode, const char *proc_fil if (fgets(line, sizeof(line), tcp_fp) == NULL) goto out; - if (!verify_initial_line(line)) + if (!L3_verify_initial_line(line)) /* Unexpected line */ goto out; @@ -652,25 +665,10 @@ static void load_xinfo_from_proc_inet_L3(ino_t netns_inode, const char *proc_fil fclose(tcp_fp); } -static bool tcp_verify_initial_line(const char *line) -{ - /* At least we expect two white spaces. */ - if (strncmp (line, " ", 2) != 0) - return false; - line += 2; - - /* Skip white spaces. */ - while (*line == ' ') - line++; - - return (strncmp(line, "sl", 2) == 0); -} - - static void load_xinfo_from_proc_tcp(ino_t netns_inode) { load_xinfo_from_proc_inet_L3(netns_inode, - "/proc/net/tcp", tcp_verify_initial_line, + "/proc/net/tcp", &tcp_xinfo_class); } @@ -724,6 +722,5 @@ static void load_xinfo_from_proc_udp(ino_t netns_inode) { load_xinfo_from_proc_inet_L3(netns_inode, "/proc/net/udp", - tcp_verify_initial_line, &udp_xinfo_class); }