1# SPDX-License-Identifier: GPL-2.0 2 3import sys 4from pathlib import Path 5from .consts import KSRC, KSFT_DIR 6from .ksft import ksft_pr, ktap_result 7 8# Resolve paths 9try: 10 if (KSFT_DIR / "kselftest-list.txt").exists(): 11 # Running in "installed" selftests 12 tools_full_path = KSFT_DIR 13 SPEC_PATH = KSFT_DIR / "net/lib/specs" 14 15 sys.path.append(tools_full_path.as_posix()) 16 from net.lib.ynl.pyynl.lib import YnlFamily, NlError, Netlink 17 else: 18 # Running in tree 19 tools_full_path = KSRC / "tools" 20 SPEC_PATH = KSRC / "Documentation/netlink/specs" 21 22 sys.path.append(tools_full_path.as_posix()) 23 from net.ynl.pyynl.lib import YnlFamily, NlError, Netlink 24except ModuleNotFoundError as e: 25 ksft_pr("Failed importing `ynl` library from kernel sources") 26 ksft_pr(str(e)) 27 ktap_result(True, comment="SKIP") 28 sys.exit(4) 29 30__all__ = [ 31 "NlError", "Netlink", "YnlFamily", "SPEC_PATH", 32 "EthtoolFamily", "RtnlFamily", "RtnlAddrFamily", 33 "NetdevFamily", "NetshaperFamily", "DevlinkFamily", "PSPFamily", 34] 35 36# 37# Wrapper classes, loading the right specs 38# Set schema='' to avoid jsonschema validation, it's slow 39# 40class EthtoolFamily(YnlFamily): 41 def __init__(self, recv_size=0): 42 super().__init__((SPEC_PATH / Path('ethtool.yaml')).as_posix(), 43 schema='', recv_size=recv_size) 44 45 46class RtnlFamily(YnlFamily): 47 def __init__(self, recv_size=0): 48 super().__init__((SPEC_PATH / Path('rt-link.yaml')).as_posix(), 49 schema='', recv_size=recv_size) 50 51class RtnlAddrFamily(YnlFamily): 52 def __init__(self, recv_size=0): 53 super().__init__((SPEC_PATH / Path('rt-addr.yaml')).as_posix(), 54 schema='', recv_size=recv_size) 55 56class NetdevFamily(YnlFamily): 57 def __init__(self, recv_size=0): 58 super().__init__((SPEC_PATH / Path('netdev.yaml')).as_posix(), 59 schema='', recv_size=recv_size) 60 61class NetshaperFamily(YnlFamily): 62 def __init__(self, recv_size=0): 63 super().__init__((SPEC_PATH / Path('net_shaper.yaml')).as_posix(), 64 schema='', recv_size=recv_size) 65 66class DevlinkFamily(YnlFamily): 67 def __init__(self, recv_size=0): 68 super().__init__((SPEC_PATH / Path('devlink.yaml')).as_posix(), 69 schema='', recv_size=recv_size) 70 71class PSPFamily(YnlFamily): 72 def __init__(self, recv_size=0): 73 super().__init__((SPEC_PATH / Path('psp.yaml')).as_posix(), 74 schema='', recv_size=recv_size) 75