tests: (test_mkfds::sockdiag) verify the recived message
authorMasatake YAMATO <yamato@redhat.com>
Mon, 1 Apr 2024 21:34:40 +0000 (06:34 +0900)
committerChris Hofstaedtler <zeha@debian.org>
Sat, 27 Apr 2024 12:23:31 +0000 (14:23 +0200)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Gbp-Pq: Topic upstream
Gbp-Pq: Name tests-test_mkfds-sockdiag-verify-the-recived-message.patch

tests/helpers/test_mkfds.c

index 39427ba09a2ef00d10a549b68b5f021bcb449cbb..4b138c2efd1ed3a230d4db12ee8d7aa8333f8440 100644 (file)
@@ -3200,6 +3200,25 @@ static int send_diag_request(int diagsd, void *req, size_t req_size)
        return 0;
 }
 
+static int recv_diag_request(int diagsd)
+{
+       __attribute__((aligned(sizeof(void *)))) uint8_t buf[8192];
+       const struct nlmsghdr *h;
+       int r = recvfrom(diagsd, buf, sizeof(buf), 0, NULL, NULL);;
+       if (r < 0)
+               return errno;
+
+       h = (void *)buf;
+       if (!NLMSG_OK(h, (size_t)r))
+               return -1;
+
+       if (h->nlmsg_type == NLMSG_ERROR) {
+               struct nlmsgerr *e = (struct nlmsgerr *)NLMSG_DATA(h);
+               return - e->error;
+       }
+       return 0;
+}
+
 static void *make_sockdiag(const struct factory *factory, struct fdesc fdescs[],
                           int argc, char ** argv)
 {
@@ -3243,6 +3262,16 @@ static void *make_sockdiag(const struct factory *factory, struct fdesc fdescs[],
                err(EXIT_FAILURE, "failed in sendmsg()");
        }
 
+       e = recv_diag_request(diagsd);
+       if (e != 0) {
+               close (diagsd);
+               if (e == ENOENT)
+                       err(EXIT_ENOENT, "failed in recvfrom()");
+               if (e > 0)
+                       err(EXIT_FAILURE, "failed in recvfrom()");
+               if (e < 0)
+                       errx(EXIT_FAILURE, "failed in recvfrom() => -1");
+       }
 
        if (diagsd != fdescs[0].fd) {
                if (dup2(diagsd, fdescs[0].fd) < 0) {