1#!/usr/bin/env python3

2# Copyright 2017-2018 Canonical Ltd.

3# All rights reserved.

4#

5# Written by:

6# Jonathan Cave <jonathan.cave@canonical.com>

7# Taihsiang Ho <taihsiang.ho@canonical.com>

8#

9# Print info about drivers we can identify automatically and also those we

10# identify in the special interest list!

11

12 from pathlib import Path

13 import subprocess as sp

14 import sys

15

16# Store pairs of (interface, driver)

17 driver_list = []

18

19# Find drivers in sysfs

20 for interface in Path("/sys/class/net").iterdir():

21 mod_path = Path("{}/device/driver/module".format(interface))

22 if mod_path.is_symlink():

23 driver_list.append((interface.name, mod_path.resolve().name))

24

25# Add user requested modules to the list. Create "unknown" interfaces if none

26# of the identified interfaces above are using it

27 for user_driver in sys.argv[1:]:

28 if user_driver:

29 if Path("/sys/module/{}".format(user_driver)).exists():

30 if not any(x[1] == user_driver for x in driver_list):

31 driver_list.append(("unknown", user_driver))

32 else:

33 print("Requested driver {} not loaded\n".format(user_driver))

34

35# Produce the output

36 for interface, driver in driver_list:

37 print("Interface {} using module {}".format(interface, driver))

38 sysfs_path = Path("/sys/module/{}/parameters".format(driver))

39 if sysfs_path.is_dir():

40 print(" Parameters:")

41 for path in Path(sysfs_path).iterdir():

42 if path.is_file():

43 # Path.read_text is new in python 3.5 but we want to support

44 # trusty as well, which uses python 3.4 by default.

45 with open(str(path), "r") as f:

46 print(" {}: {}".format(path.name, f.read().strip()))

47 print()

48 print("Checking kernel ring buffer for {} messages:".format(driver))

49 cmd = "dmesg -T -x | grep {} || true".format(driver)

50 output = sp.check_output(cmd, shell=True)

51 print(output.decode(sys.stdout.encoding))

52 print()