|
9 | 9 |
|
10 | 10 | import argparse |
11 | 11 | import os |
| 12 | +import string |
12 | 13 | import sys |
13 | 14 |
|
14 | 15 | import yaml |
@@ -45,7 +46,7 @@ def main(program, options): |
45 | 46 | if options.ifname in denylist: |
46 | 47 | raise ValueError(f"Interface name '{options.ifname}' is denied in denylist.") |
47 | 48 |
|
48 | | - programs = ["tcpreplay", "tcpdump", "ip"] |
| 49 | + programs = ["tcpreplay", "tcpdump", "ip", "ethtool"] |
49 | 50 | if program not in programs: |
50 | 51 | raise ValueError(f"Invalid program {program} called with wrapper, valid programs are: {programs}") |
51 | 52 |
|
@@ -86,6 +87,18 @@ def main(program, options): |
86 | 87 | args.append(options.ifname) |
87 | 88 | args.append(options.action) |
88 | 89 |
|
| 90 | + elif program == "ethtool": |
| 91 | + allowed_chars = set(string.ascii_letters + string.digits + "-/:") |
| 92 | + |
| 93 | + if options.subcommand == "change": |
| 94 | + for arg in options.ethtool_change_args: |
| 95 | + if arg.startswith("-") or not allowed_chars.issuperset(arg): |
| 96 | + raise ValueError(f"ethtool --change arg '{arg}' contains invalid characters") |
| 97 | + |
| 98 | + args.append("--change") |
| 99 | + args.append(options.ifname) |
| 100 | + args.extend(options.ethtool_change_args) |
| 101 | + |
89 | 102 | try: |
90 | 103 | os.execvp(args[0], args) |
91 | 104 | except FileNotFoundError as e: |
@@ -114,6 +127,17 @@ if __name__ == "__main__": |
114 | 127 | ip_parser.add_argument("ifname", type=str, help="interface name") |
115 | 128 | ip_parser.add_argument("action", type=str, choices=["up", "down"], help="action, one of {%(choices)s}") |
116 | 129 |
|
| 130 | + # ethtool |
| 131 | + ethtool_parser = subparsers.add_parser("ethtool") |
| 132 | + ethtool_subparsers = ethtool_parser.add_subparsers(dest="subcommand") |
| 133 | + |
| 134 | + # ethtool: change |
| 135 | + ethtool_change_parser = ethtool_subparsers.add_parser("change") |
| 136 | + ethtool_change_parser.add_argument("ifname", type=str, help="interface name") |
| 137 | + ethtool_change_parser.add_argument( |
| 138 | + "ethtool_change_args", metavar="ARG", nargs=argparse.REMAINDER, help="ethtool --change args" |
| 139 | + ) |
| 140 | + |
117 | 141 | args = parser.parse_args() |
118 | 142 | try: |
119 | 143 | main(args.program, args) |
|
0 commit comments