]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: make the logic for verifying the initial line of /proc/net/{tcp,udp} more flexible
authorMasatake YAMATO <yamato@redhat.com>
Wed, 26 Oct 2022 02:56:00 +0000 (11:56 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Wed, 26 Oct 2022 02:56:00 +0000 (11:56 +0900)
The format of /proc/net/udp was changed in
6c25449e1a32 ("net: udp: fix alignment problem in udp4_seq_show()").
This kind of change can be applied to /proc/net/tcp, too.

Co-Authored-by: Thomas Weißschuh <thomas@t-8ch.de>
Co-Authored-by: Masatake YAMATO <yamato@redhat.com>
misc-utils/lsfd-sock-xinfo.c

index 1ef2f40b7c0668548621c44885c80a4350843cff..263ffc36e97df4c142c24ce297e361f996f69f18 100644 (file)
@@ -654,10 +654,19 @@ static void load_xinfo_from_proc_inet_L3(ino_t netns_inode, const char *proc_fil
 
 static bool tcp_verify_initial_line(const char *line)
 {
-       return (line[0] == ' ' && line[1] == ' '
-               && line[2] == 's' && line[3] == 'l');
+       /* 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,
@@ -711,17 +720,10 @@ static struct sock_xinfo_class udp_xinfo_class = {
        .free = NULL,
 };
 
-static bool udp_verify_initial_line(const char *line)
-{
-       return (line[0] == ' ' && line[1] == ' ' && line[2] == ' '
-               && line[3] == 's' && line[4] == 'l');
-}
-
-
 static void load_xinfo_from_proc_udp(ino_t netns_inode)
 {
        load_xinfo_from_proc_inet_L3(netns_inode,
                                     "/proc/net/udp",
-                                    udp_verify_initial_line,
+                                    tcp_verify_initial_line,
                                     &udp_xinfo_class);
 }