From nobody Wed Jan 10 00:58:25 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4T8qDK3TDCz5739d; Wed, 10 Jan 2024 00:58:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4T8qDK2wGRz4ckj; Wed, 10 Jan 2024 00:58:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704848305; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=IpJprHIl4F+uDzMu+o6T5IfZiZ8BEZ/QIGL+GRoGfLs=; b=r+xxP3kFVayoDsL0xQ5GvfFoK5CPsceSqZyEbk4ujHOxWSI80AmSPjyToWZpVLlP3dBRaW +e0jYosWT+xiTYzkUGX4AGsmLgpTLVNuxYug1kX0B9gt7b5+slIXA8zZc2JURW0SefzEVP Ez5gUswvyfoX0WvAKyeFHaIhlOlhM9lFKviHiiow9Ts0zNpNSpBygnw7HOtksd9hXZzO0a wsNyP4BzfEvRfTS9v7/uDbg6AHPtju443QrNvHCPsfRDZcAnFzUdLLWxi6u554yy0NhbuG KW18H2EOXbt6rSROgVwaQbtFLHY0DiUqkbj72OSdyybbRhh/EN++4vE4rYUZGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704848305; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=IpJprHIl4F+uDzMu+o6T5IfZiZ8BEZ/QIGL+GRoGfLs=; b=uiTxnV/1TnQYkHMvXq64dSvzwOiwxzwg7ZxPziPQZVheuY5blVR7LdUKhKpuesXi1YGlYf nZ2Wm1WbyoqPlUsQjAar+c4NXYmE0qgHkBiVzSlzFxkS+mNzk4dFE7biNBkkfOmZq2iyLL o4+ZGjQV6NCkWrYWRCvK0cfJqR53B4DJJEulTDY6IOkmWoA+tJxCEFsAm3vn8VxKG9gz1a 2thsHe18vxyB+O4q930RWI74fVokHWFhr7DrHH2mDR57c9RYReRnl98b6JNNgrpyl1+3PB vncGyF455fITtp/pqtE4sUrB0Izkia02yvVyxDi6iItZUnAd5NB8rvoFwUBndA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704848305; a=rsa-sha256; cv=none; b=B4pOS9PpMAT2nyEWXCSRefE94XterUBk3BAFtBT5qKUpSICTLlM1uwN9nd7bgCkoUzZUHR wMMNFBeEcRl7jpWiDFy5YjAuIecdatJjzfUv1ZHoWnJMgxSBVlGNSZkesi2JbrpDbbR5nO WS5AnwDHS8p6MXaEacmMBIuswHUCSOQwxxEOKoVMuhmY82uAKKR0wqCGJUdByRCjI+v+MT 0WNoT1W+CKqe03dqvpxHgGoP5OKvyAGLLgk/aZGE0DTOahAqOYDxLkjEPceyoMfkjBkG2X 3qFwKQKrVDCIuC1yaMnUi1v1FmWzlTyNd5cG+dmpdK7RMasqosxkorrr7UrTPA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4T8qDK1gl8z1CkS; Wed, 10 Jan 2024 00:58:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 40A0wPki087538; Wed, 10 Jan 2024 00:58:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40A0wPUS087535; Wed, 10 Jan 2024 00:58:25 GMT (envelope-from git) Date: Wed, 10 Jan 2024 00:58:25 GMT Message-Id: <202401100058.40A0wPUS087535@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 8338ea1d3cc7 - main - tests/netlink: add minimal test for a group writer List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 8338ea1d3cc705f08674285a884d3aa485bf6290 Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=8338ea1d3cc705f08674285a884d3aa485bf6290 commit 8338ea1d3cc705f08674285a884d3aa485bf6290 Author: Gleb Smirnoff AuthorDate: 2024-01-10 00:56:51 +0000 Commit: Gleb Smirnoff CommitDate: 2024-01-10 00:56:51 +0000 tests/netlink: add minimal test for a group writer Subscribe a socket for RTNLGRP_IPV4_ROUTE announcements, add & delete a route and check that announcements came in. --- tests/sys/netlink/netlink_socket.c | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/sys/netlink/netlink_socket.c b/tests/sys/netlink/netlink_socket.c index 51a3824a31f2..3015a585199b 100644 --- a/tests/sys/netlink/netlink_socket.c +++ b/tests/sys/netlink/netlink_socket.c @@ -39,6 +39,9 @@ #include #include +#include +#include + #include static struct itimerval itv = { @@ -253,6 +256,51 @@ ATF_TC_BODY(sizes, tc) cmsg_check(&msg); } +/* + * Check that NETLINK_ADD_MEMBERSHIP subscribes us. Add & delete a temporary + * route and check if announcements came in. + */ +ATF_TC_WITHOUT_HEAD(membership); +ATF_TC_BODY(membership, tc) +{ + struct { + struct nlmsghdr hdr; + struct rtmsg rtm; + struct nlattr rta_dst; + struct in_addr dst; + struct nlattr rta_oif; + uint32_t oif; + } msg = { + .hdr.nlmsg_type = RTM_NEWROUTE, + .hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL, + .hdr.nlmsg_len = sizeof(msg), + .rtm.rtm_family = AF_INET, + .rtm.rtm_protocol = RTPROT_STATIC, + .rtm.rtm_type = RTN_UNICAST, + .rtm.rtm_dst_len = 32, + .rta_dst.nla_type = RTA_DST, + .rta_dst.nla_len = sizeof(struct in_addr) + + sizeof(struct nlattr), + .dst.s_addr = inet_addr("127.0.0.127"), + .rta_oif.nla_type = RTA_OIF, + .rta_oif.nla_len = sizeof(uint32_t) + sizeof(struct nlattr), + .oif = 1, + }; + int fd; + + ATF_REQUIRE((fd = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) != -1); + ATF_REQUIRE(setsockopt(fd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, + &(int){RTNLGRP_IPV4_ROUTE}, sizeof(int)) == 0); + ATF_REQUIRE(send(fd, &msg, sizeof(msg), 0) == sizeof(msg)); + msg.hdr.nlmsg_type = RTM_DELROUTE; + msg.hdr.nlmsg_len -= sizeof(struct nlattr) + sizeof(uint32_t); + ATF_REQUIRE(send(fd, &msg, msg.hdr.nlmsg_len, 0) == msg.hdr.nlmsg_len); + ATF_REQUIRE(recv(fd, &msg, sizeof(msg), 0) == sizeof(msg)); + ATF_REQUIRE(msg.hdr.nlmsg_type == RTM_NEWROUTE); + ATF_REQUIRE(recv(fd, &msg, sizeof(msg), 0) == sizeof(msg)); + ATF_REQUIRE(msg.hdr.nlmsg_type == RTM_DELROUTE); +} + ATF_TP_ADD_TCS(tp) { if (modfind("netlink") == -1) @@ -261,6 +309,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, overflow); ATF_TP_ADD_TC(tp, peek); ATF_TP_ADD_TC(tp, sizes); + ATF_TP_ADD_TC(tp, membership); return (atf_no_error()); }