diff --git a/jc/parsers/ifconfig.py b/jc/parsers/ifconfig.py index fa1abcdf..7eb2f07b 100644 --- a/jc/parsers/ifconfig.py +++ b/jc/parsers/ifconfig.py @@ -355,69 +355,135 @@ def parse( # SOFTWARE. # Linux syntax - re_linux_interface = re.compile( - r"(?P[a-zA-Z0-9:._-]+)\s+Link encap:(?P\S+\s?\S+)(\s+HWaddr\s+\b" - r"(?P[0-9A-Fa-f:?]+))?", - re.I) - re_linux_ipv4 = re.compile( - r"inet addr:(?P
(?:[0-9]{1,3}\.){3}[0-9]{1,3})(\s+Bcast:" - r"(?P(?:[0-9]{1,3}\.){3}[0-9]{1,3}))?\s+Mask:(?P(?:[0-9]{1,3}\.){3}[0-9]{1,3})", - re.I) - re_linux_ipv6 = re.compile( - r"inet6 addr:\s+(?P
\S+)/(?P[0-9]+)\s+Scope:(?PLink|Host)", - re.I) - re_linux_state = re.compile( - r"\W+(?P(?:\w+\s)+)(?:\s+)?MTU:(?P[0-9]+)\s+Metric:(?P[0-9]+)", re.I) - re_linux_rx = re.compile( - r"RX packets:(?P[0-9]+)\s+errors:(?P[0-9]+)\s+dropped:" - r"(?P[0-9]+)\s+overruns:(?P[0-9]+)\s+frame:(?P[0-9]+)", - re.I) - re_linux_tx = re.compile( - r"TX packets:(?P[0-9]+)\s+errors:(?P[0-9]+)\s+dropped:" - r"(?P[0-9]+)\s+overruns:(?P[0-9]+)\s+carrier:(?P[0-9]+)", - re.I) - re_linux_bytes = re.compile(r"\W+RX bytes:(?P\d+)\s+\(.*\)\s+TX bytes:(?P\d+)\s+\(.*\)", re.I) - re_linux_tx_stats = re.compile(r"collisions:(?P[0-9]+)\s+txqueuelen:[0-9]+", re.I) - + re_linux_interface = re.compile(r''' + (?P[a-zA-Z0-9:._-]+)\s+ + Link encap:(?P\S+\s?\S+) + (\s+HWaddr\s+\b(?P[0-9A-Fa-f:?]+))? + ''', re.IGNORECASE | re.VERBOSE + ) + re_linux_ipv4 = re.compile(r''' + inet addr:(?P
(?:[0-9]{1,3}\.){3}[0-9]{1,3})(\s+ + Bcast:(?P(?:[0-9]{1,3}\.){3}[0-9]{1,3}))?\s+ + Mask:(?P(?:[0-9]{1,3}\.){3}[0-9]{1,3}) + ''', re.IGNORECASE | re.VERBOSE + ) + re_linux_ipv6 = re.compile(r''' + inet6 addr:\s+(?P
\S+)/ + (?P[0-9]+)\s+ + Scope:(?PLink|Host) + ''', re.IGNORECASE | re.VERBOSE + ) + re_linux_state = re.compile(r''' + \W+(?P(?:\w+\s)+)(?:\s+)? + MTU:(?P[0-9]+)\s+ + Metric:(?P[0-9]+) + ''', re.IGNORECASE | re.VERBOSE + ) + re_linux_rx = re.compile(r''' + RX packets:(?P[0-9]+)\s+ + errors:(?P[0-9]+)\s+ + dropped:(?P[0-9]+)\s+ + overruns:(?P[0-9]+)\s+ + frame:(?P[0-9]+) + ''', re.IGNORECASE | re.VERBOSE + ) + re_linux_tx = re.compile(r''' + TX packets:(?P[0-9]+)\s+ + errors:(?P[0-9]+)\s+ + dropped:(?P[0-9]+)\s+ + overruns:(?P[0-9]+)\s+ + carrier:(?P[0-9]+) + ''', re.IGNORECASE | re.VERBOSE + ) + re_linux_bytes = re.compile(r''' + \W+RX bytes:(?P\d+)\s+\(.*\)\s+ + TX bytes:(?P\d+)\s+\(.*\) + ''', re.IGNORECASE | re.VERBOSE + ) + re_linux_tx_stats = re.compile(r''' + collisions:(?P[0-9]+)\s+ + txqueuelen:[0-9]+ + ''', re.IGNORECASE | re.VERBOSE + ) # OpenBSD syntax - re_openbsd_interface = re.compile( - r"(?P[a-zA-Z0-9:._-]+):\s+flags=(?P[0-9]+)<(?P\S+)?>\s+mtu\s+(?P[0-9]+)", - re.I) - re_openbsd_ipv4 = re.compile( - r"inet (?P
(?:[0-9]{1,3}\.){3}[0-9]{1,3})\s+netmask\s+" - r"(?P(?:[0-9]{1,3}\.){3}[0-9]{1,3})(\s+broadcast\s+" - r"(?P(?:[0-9]{1,3}\.){3}[0-9]{1,3}))?", - re.I) - re_openbsd_ipv6 = re.compile( - r'inet6\s+(?P
\S+)\s+prefixlen\s+(?P[0-9]+)\s+scopeid\s+(?P\w+x\w+)<(?Plink|host|global)>', - re.I) - re_openbsd_details = re.compile( - r"\S+\s+(?:(?P[0-9A-Fa-f:?]+)\s+)?txqueuelen\s+[0-9]+\s+\((?P\S+\s?\S+)\)", re.I) - re_openbsd_rx = re.compile(r"RX packets (?P[0-9]+)\s+bytes\s+(?P\d+)\s+.*", re.I) - re_openbsd_rx_stats = re.compile( - r"RX errors (?P[0-9]+)\s+dropped\s+(?P[0-9]+)\s+overruns\s+" - r"(?P[0-9]+)\s+frame\s+(?P[0-9]+)", - re.I) - re_openbsd_tx = re.compile(r"TX packets (?P[0-9]+)\s+bytes\s+(?P\d+)\s+.*", re.I) - re_openbsd_tx_stats = re.compile( - r"TX errors (?P[0-9]+)\s+dropped\s+(?P[0-9]+)\s+overruns\s+" - r"(?P[0-9]+)\s+carrier\s+(?P[0-9]+)\s+collisions\s+(?P[0-9]+)", - re.I) - + re_openbsd_interface = re.compile(r''' + (?P[a-zA-Z0-9:._-]+):\s+ + flags=(?P[0-9]+) + <(?P\S+)?>\s+ + mtu\s+(?P[0-9]+) + ''', re.IGNORECASE | re.VERBOSE + ) + re_openbsd_ipv4 = re.compile(r''' + inet\s(?P
(?:[0-9]{1,3}\.){3}[0-9]{1,3})\s+netmask\s+ + (?P(?:[0-9]{1,3}\.){3}[0-9]{1,3})(\s+broadcast\s+ + (?P(?:[0-9]{1,3}\.){3}[0-9]{1,3}))? + ''', re.IGNORECASE | re.VERBOSE + ) + re_openbsd_ipv6 = re.compile(r''' + inet6\s+(?P
\S+)\s+ + prefixlen\s+(?P[0-9]+)\s+ + scopeid\s+(?P\w+x\w+) + <(?Plink|host|global)> + ''', re.IGNORECASE | re.VERBOSE + ) + re_openbsd_details = re.compile(r''' + \S+\s+(?:(?P[0-9A-Fa-f:?]+)\s+)? + txqueuelen\s+[0-9]+\s+ + \((?P\S+\s?\S+)\) + ''', re.IGNORECASE | re.VERBOSE + ) + re_openbsd_rx = re.compile(r''' + RX\spackets\s(?P[0-9]+)\s+ + bytes\s+(?P\d+)\s+.* + ''', re.IGNORECASE | re.VERBOSE + ) + re_openbsd_rx_stats = re.compile(r''' + RX\serrors\s(?P[0-9]+)\s+ + dropped\s+(?P[0-9]+)\s+ + overruns\s+(?P[0-9]+)\s+ + frame\s+(?P[0-9]+) + ''', re.IGNORECASE | re.VERBOSE + ) + re_openbsd_tx = re.compile(r''' + TX\spackets\s(?P[0-9]+)\s+ + bytes\s+(?P\d+)\s+.* + ''', re.IGNORECASE | re.VERBOSE + ) + re_openbsd_tx_stats = re.compile(r''' + TX\serrors\s(?P[0-9]+)\s+ + dropped\s+(?P[0-9]+)\s+ + overruns\s+(?P[0-9]+)\s+ + carrier\s+(?P[0-9]+)\s+ + collisions\s+(?P[0-9]+) + ''', re.IGNORECASE | re.VERBOSE + ) # FreeBSD syntax - re_freebsd_interface = re.compile( - r"(?P[a-zA-Z0-9:._-]+):\s+flags=(?P[0-9]+)<(?P\S+)>\s+metric\s+" - r"(?P[0-9]+)\s+mtu\s+(?P[0-9]+)", - re.I) - re_freebsd_ipv4 = re.compile( - r"inet (?P
(?:[0-9]{1,3}\.){3}[0-9]{1,3})\s+netmask\s+(?P0x\S+)(\s+broadcast\s+" - r"(?P(?:[0-9]{1,3}\.){3}[0-9]{1,3}))?", - re.I) - re_freebsd_ipv6 = re.compile(r"\s?inet6\s(?P
.*)(?:\%\w+\d+)\sprefixlen\s(?P\d+)(?:\s\w+)?\sscopeid\s(?P\w+x\w+)", re.I) - re_freebsd_details = re.compile(r"ether\s+(?P[0-9A-Fa-f:?]+)", re.I) - + re_freebsd_interface = re.compile(r''' + (?P[a-zA-Z0-9:._-]+):\s+ + flags=(?P[0-9]+) + <(?P\S+)>\s+ + metric\s+(?P[0-9]+)\s+ + mtu\s+(?P[0-9]+) + ''', re.IGNORECASE | re.VERBOSE + ) + re_freebsd_ipv4 = re.compile(r''' + inet\s(?P
(?:[0-9]{1,3}\.){3}[0-9]{1,3})\s+ + netmask\s+(?P0x\S+)(\s+ + broadcast\s+(?P(?:[0-9]{1,3}\.){3}[0-9]{1,3}))? + ''', re.IGNORECASE | re.VERBOSE + ) + re_freebsd_ipv6 = re.compile(r''' + \s?inet6\s(?P
.*)(?:\%\w+\d+)\s + prefixlen\s(?P\d+)(?:\s\w+)?\s + scopeid\s(?P\w+x\w+) + ''', re.IGNORECASE | re.VERBOSE + ) + re_freebsd_details = re.compile(r''' + ether\s+(?P[0-9A-Fa-f:?]+) + ''', re.IGNORECASE | re.VERBOSE + ) re_linux = [ re_linux_interface, re_linux_ipv4, re_linux_ipv6, re_linux_state, re_linux_rx, re_linux_tx, diff --git a/tests/fixtures/freebsd12/ifconfig-extra-fields.out b/tests/fixtures/freebsd12/ifconfig-extra-fields.out new file mode 100644 index 00000000..4c0cba8b --- /dev/null +++ b/tests/fixtures/freebsd12/ifconfig-extra-fields.out @@ -0,0 +1,10 @@ +cxl3: flags=8843 metric 0 mtu 1500 + options=6ec07bb + ether 00:07:43:3d:b7:70 + hwaddr 00:07:43:3d:b7:88 media: Ethernet 10Gbase-LR + status: active + nd6 options=29 + plugged: SFP/SFP+/SFP28 10G Base-LR (LC) + vendor: INNOLIGHT PN: TR-PX13L-N00 SN: INJBL0431986 DATE: 2020-01-04 + module temperature: 21.20 C voltage: 3.16 Volts + lane 1: RX power: 0.49 mW (-3.10 dBm) TX bias: 23.85 mA