git: d2de66a90d01 - main - ng_socket: with getsockname() return node ID for unnamed node
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 28 Nov 2023 04:12:41 UTC
The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=d2de66a90d01810b1869b7dcac290267f05e4b1d commit d2de66a90d01810b1869b7dcac290267f05e4b1d Author: Gleb Smirnoff <glebius@FreeBSD.org> AuthorDate: 2023-11-28 04:11:38 +0000 Commit: Gleb Smirnoff <glebius@FreeBSD.org> CommitDate: 2023-11-28 04:11:38 +0000 ng_socket: with getsockname() return node ID for unnamed node Reviewed by: afedorov Differential Revision: https://reviews.freebsd.org/D42691 --- sys/netgraph/ng_socket.c | 3 +++ tests/sys/netgraph/socket.c | 7 +++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/sys/netgraph/ng_socket.c b/sys/netgraph/ng_socket.c index 4afa46c3d0f0..8a8f127ee39b 100644 --- a/sys/netgraph/ng_socket.c +++ b/sys/netgraph/ng_socket.c @@ -523,6 +523,9 @@ ng_getsockaddr(struct socket *so, struct sockaddr **addr) if (NG_NODE_HAS_NAME(node)) bcopy(NG_NODE_NAME(node), sg->sg_data, strlen(NG_NODE_NAME(node))); + else + snprintf(sg->sg_data, sizeof(sg->sg_data), "[%x]", + ng_node2ID(node)); mtx_unlock(&pcbp->sockdata->mtx); sg->sg_len = sg_len; diff --git a/tests/sys/netgraph/socket.c b/tests/sys/netgraph/socket.c index bd40e4358866..1e5d68e1d21f 100644 --- a/tests/sys/netgraph/socket.c +++ b/tests/sys/netgraph/socket.c @@ -42,13 +42,12 @@ ATF_TC_BODY(getsockname, tc) char name[NG_NODESIZ] = NAME; int cs; -#if 0 - /* Unnamed node. */ + /* Unnamed node returns its ID as name. */ ATF_REQUIRE(NgMkSockNode(NULL, &cs, NULL) == 0); ATF_REQUIRE(getsockname(cs, (struct sockaddr *)&sg, &len) == 0); + ATF_REQUIRE(strspn(sg.sg_data, "[0123456789abcdef]") >= 3 && + sg.sg_data[strspn(sg.sg_data, "[0123456789abcdef]")] == '\0'); close(cs); - /* Unnamed node doesn't return any name/ID now. */ -#endif /* Named node. */ ATF_REQUIRE(NgMkSockNode(name, &cs, NULL) == 0);