From nobody Sat Apr 08 19:44:57 2023 X-Original-To: dev-commits-src-branches@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 4Pv5L237bNz44nXr; Sat, 8 Apr 2023 19:44:58 +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 4Pv5L20yflz44Ls; Sat, 8 Apr 2023 19:44:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1680983098; 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=/7HJ6G05jtAslTr+wRZS73RqcBiR3BtomKJ4JiYc2Ag=; b=EyTKOmUFY3Ophi5jcMIemPQ4N19rEiyABky1IFTV+1l1MGm8ukPPlatbEwSS9bR72xN2O8 1PhiKxnZNsvspLuYQwMKMMlw6OtlOlZ8BeMe0TDW6VG9u3WctrF/UFZR6cPbi6S76N2wAj Dhbp3XQ9+Ovc5L40LkgNcE7abLaMxCG9kiS9mnroYvD2fXUNdL1icAAIgiQrHnkga5rTaI HGOdb0Ep80xp29bGYO/i5X6oAtj63tJ05aUS3+TsDHtkaHFi3EhUTurLLGVCyzKYv6mw1u rHwJNLrkuNpKlG87MMdSk7n45rJoCSFDofIxRIR0NIXlZfq1onnWqFxfIugUvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1680983098; 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=/7HJ6G05jtAslTr+wRZS73RqcBiR3BtomKJ4JiYc2Ag=; b=EA/vdogf5AEPh6GACO0+13cR4secsknaZWiTcoxRJNu73S8u+qp4rA00Z9WzSbPjcb3hk1 T5axSeKNO5pYctY31aP0TizFoRtVhi9HVgKf+zmhTU+5M9fL60FXXXeRv9NReKJBpWIdsj jeNElDLzsdbfExqLC6NNAHu2RJn/kQLl+tIAko1oshNJ3XMS3fjUXzQVmYHVuQoYAnWXPO cd30gmzv1sdV62EMTJmoWTKmVa28P2G+xQ9LvbCJDE9z43QUHGH4+XFPaUfcrCNIjUxatZ gDz7oFnrmis41jh/q2DnhGgXfC19ybtrcLkfp4vehbLiFI4ajM1+TQpVFhi6fQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1680983098; a=rsa-sha256; cv=none; b=Otp5NMwwqGBVZQLcoiD8wNgFBArFRSB8fttuEazkPkf9bMYJCsWqD2Wdiv7zasHr7Vs8n9 0ytaLtbhYsnV5sX6zw3VTQS/1YIsNovntkXOeeKbWNbs25qJE53JradAJ4OoPpq5GAD0zr XT7fr2kEP0IPru8UfSP91paG35KH1jcly2gtGo6rVAI9bfD9v+xKSv9LqDZgP1YNdGaMOp fqTuuoQ/3oOYu7TjUB/VLWTdmotgUKkan5UX51WbbNmmrLjO7rIQkYFyq0m71Jt5PdrZsF B6Dis3bbYqXripryp/ct/7qJdtMt8I+W3p4DTqsm50j9RWfHfpySScSgQDf3Zw== 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 4Pv5L16kcWzfYb; Sat, 8 Apr 2023 19:44:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 338Jiv53018834; Sat, 8 Apr 2023 19:44:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 338Jivep018833; Sat, 8 Apr 2023 19:44:57 GMT (envelope-from git) Date: Sat, 8 Apr 2023 19:44:57 GMT Message-Id: <202304081944.338Jivep018833@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: b68dcb393a47 - stable/13 - netlink: improve attribute decoding in python tests List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: b68dcb393a476c3c4b0583c7ab99a7ba280ed836 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=b68dcb393a476c3c4b0583c7ab99a7ba280ed836 commit b68dcb393a476c3c4b0583c7ab99a7ba280ed836 Author: Alexander V. Chernikov AuthorDate: 2023-02-17 18:04:53 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-04-08 19:13:50 +0000 netlink: improve attribute decoding in python tests MFC after: 2 weeks (cherry picked from commit ff8da9b2bab43920a19c16855ac3d30b5ccb1df2) --- tests/atf_python/sys/net/netlink.py | 131 +++++++++++++++++++++++++----------- 1 file changed, 92 insertions(+), 39 deletions(-) diff --git a/tests/atf_python/sys/net/netlink.py b/tests/atf_python/sys/net/netlink.py index ba7d41c7cbf8..16cb746157cc 100644 --- a/tests/atf_python/sys/net/netlink.py +++ b/tests/atf_python/sys/net/netlink.py @@ -72,36 +72,38 @@ class NlErrattrType(Enum): class RtattrType(Enum): RTA_UNSPEC = 0 - RTA_DST = auto() - RTA_SRC = auto() - RTA_IIF = auto() - RTA_OIF = auto() - RTA_GATEWAY = auto() - RTA_PRIORITY = auto() - RTA_PREFSRC = auto() - RTA_METRICS = auto() - RTA_MULTIPATH = auto() - RTA_PROTOINFO = auto() - RTA_FLOW = auto() - RTA_CACHEINFO = auto() - RTA_SESSION = auto() - RTA_MP_ALGO = auto() - RTA_TABLE = auto() - RTA_MARK = auto() - RTA_MFC_STATS = auto() - RTA_VIA = auto() - RTA_NEWDST = auto() - RTA_PREF = auto() - RTA_ENCAP_TYPE = auto() - RTA_ENCAP = auto() - RTA_EXPIRES = auto() - RTA_PAD = auto() - RTA_UID = auto() - RTA_TTL_PROPAGATE = auto() - RTA_IP_PROTO = auto() - RTA_SPORT = auto() - RTA_DPORT = auto() - RTA_NH_ID = auto() + RTA_DST = 1 + RTA_SRC = 2 + RTA_IIF = 3 + RTA_OIF = 4 + RTA_GATEWAY = 5 + RTA_PRIORITY = 6 + RTA_PREFSRC = 7 + RTA_METRICS = 8 + RTA_MULTIPATH = 9 + # RTA_PROTOINFO = 10 + RTA_KNH_ID = 10 + RTA_FLOW = 11 + RTA_CACHEINFO = 12 + RTA_SESSION = 13 + # RTA_MP_ALGO = 14 + RTA_RTFLAGS = 14 + RTA_TABLE = 15 + RTA_MARK = 16 + RTA_MFC_STATS = 17 + RTA_VIA = 18 + RTA_NEWDST = 19 + RTA_PREF = 20 + RTA_ENCAP_TYPE = 21 + RTA_ENCAP = 22 + RTA_EXPIRES = 23 + RTA_PAD = 24 + RTA_UID = 25 + RTA_TTL_PROPAGATE = 26 + RTA_IP_PROTO = 27 + RTA_SPORT = 28 + RTA_DPORT = 29 + RTA_NH_ID = 30 class NlMsgType(Enum): @@ -314,6 +316,32 @@ class NlRtaxType(Enum): RTAX_FASTOPEN_NO_COOKIE = auto() +class RtFlagsBSD(Enum): + RTF_UP = 0x1 + RTF_GATEWAY = 0x2 + RTF_HOST = 0x4 + RTF_REJECT = 0x8 + RTF_DYNAMIC = 0x10 + RTF_MODIFIED = 0x20 + RTF_DONE = 0x40 + RTF_XRESOLVE = 0x200 + RTF_LLINFO = 0x400 + RTF_LLDATA = 0x400 + RTF_STATIC = 0x800 + RTF_BLACKHOLE = 0x1000 + RTF_PROTO2 = 0x4000 + RTF_PROTO1 = 0x8000 + RTF_PROTO3 = 0x40000 + RTF_FIXEDMTU = 0x80000 + RTF_PINNED = 0x100000 + RTF_LOCAL = 0x200000 + RTF_BROADCAST = 0x400000 + RTF_MULTICAST = 0x800000 + RTF_STICKY = 0x10000000 + RTF_RNH_LOCKED = 0x40000000 + RTF_GWFLAG_COMPAT = 0x80000000 + + class NlRtGroup(Enum): RTNLGRP_NONE = 0 RTNLGRP_LINK = auto() @@ -496,13 +524,17 @@ class NlHelper: cls = AddressFamilyLinux return cls + @staticmethod + def build_propmap(cls): + ret = {} + for prop in dir(cls): + if not prop.startswith("_"): + ret[getattr(cls, prop).value] = prop + return ret + def get_propmap(self, cls): if cls not in self._pmap: - ret = {} - for prop in dir(cls): - if not prop.startswith("_"): - ret[getattr(cls, prop).value] = prop - self._pmap[cls] = ret + self._pmap[cls] = self.build_propmap(cls) return self._pmap[cls] def get_name_propmap(self, cls): @@ -536,8 +568,8 @@ class NlHelper: def get_rta_name(self, val): return self.get_attr_byval(RtattrType, val) - def get_bitmask_map(self, cls, val): - propmap = self.get_propmap(cls) + @staticmethod + def get_bitmask_map(propmap, val): v = 1 ret = {} while val: @@ -551,7 +583,13 @@ class NlHelper: return ret def get_bitmask_str(self, cls, val): - bmap = self.get_bitmask_map(cls, val) + bmap = self.get_bitmask_map(self.get_propmap(cls), val) + return ",".join([v for k, v in bmap.items()]) + + @staticmethod + def get_bitmask_str_uncached(cls, val): + pmap = NlHelper.build_propmap(cls) + bmap = NlHelper.get_bitmask_map(pmap, val) return ",".join([v for k, v in bmap.items()]) def get_nlm_flags_str(self, msg_str: str, reply: bool, val): @@ -743,6 +781,12 @@ class NlAttrU8(NlAttr): return self._to_bytes(struct.pack("@B", self.u8)) +class NlAttrRtFlags(NlAttrU32): + def _print_attr_value(self): + s = NlHelper.get_bitmask_str_uncached(RtFlagsBSD, self.u32) + return " rtflags={}".format(s) + + class NlAttrIp(NlAttr): def __init__(self, nla_type, addr: str): super().__init__(nla_type, b"") @@ -808,6 +852,11 @@ class NlAttrNhId(NlAttrU32): return " nh_id={}".format(self.u32) +class NlAttrKNhId(NlAttrU32): + def _print_attr_value(self): + return " knh_id={}".format(self.u32) + + class NlAttrMac(NlAttr): def _print_attr_value(self): return ' mac="' + ":".join(["{:02X}".format(b) for b in self._data]) + '"' @@ -956,9 +1005,13 @@ rtnl_route_attrs = prepare_attrs_map( AttrDescr(RtattrType.RTA_SRC, NlAttrIp), AttrDescr(RtattrType.RTA_IIF, NlAttrIfindex), AttrDescr(RtattrType.RTA_OIF, NlAttrIfindex), - AttrDescr(RtattrType.RTA_GATEWAY, NlAttrTable), + AttrDescr(RtattrType.RTA_GATEWAY, NlAttrIp), + AttrDescr(RtattrType.RTA_TABLE, NlAttrTable), + AttrDescr(RtattrType.RTA_PRIORITY, NlAttrU32), AttrDescr(RtattrType.RTA_VIA, NlAttrVia), AttrDescr(RtattrType.RTA_NH_ID, NlAttrNhId), + AttrDescr(RtattrType.RTA_KNH_ID, NlAttrKNhId), + AttrDescr(RtattrType.RTA_RTFLAGS, NlAttrRtFlags), AttrDescr( RtattrType.RTA_METRICS, NlAttrNested,