From 720ffdc561b4b94aa42edaf4616fef0cadbf5638 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Mon, 2 Jan 2023 17:46:38 +0100 Subject: [PATCH] Interfaces: Diagnostics: Packet Capture - support mac addresses in "Host Address" field. closes https://github.com/opnsense/core/issues/6159 --- .../OPNsense/Diagnostics/forms/packetcapture.xml | 4 ++-- .../mvc/app/library/OPNsense/Firewall/Util.php | 10 ++++++++++ .../OPNsense/Diagnostics/FieldTypes/HostField.php | 2 +- src/opnsense/scripts/interfaces/capture.py | 2 ++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/forms/packetcapture.xml b/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/forms/packetcapture.xml index 9b6c16465..fa1685344 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/forms/packetcapture.xml +++ b/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/forms/packetcapture.xml @@ -35,13 +35,13 @@ text - This value is either the Source or Destination IP address or subnet in CIDR notation. + This value is either the Source or Destination IP/MAC address or subnet in CIDR notation. The packet capture will look for this address in either field. Matching can be negated by preceding the value with "not". Multiple IP addresses or CIDR subnets may be specified as boolean expression. If you leave this field blank, all packets on the specified interface will be captured. - Example: not 10.0.0.0/24 not and not 11.0.0.1 + Example: not 10.0.0.0/24 not and not 11.0.0.1 or 00:0a:01:02:03:04 diff --git a/src/opnsense/mvc/app/library/OPNsense/Firewall/Util.php b/src/opnsense/mvc/app/library/OPNsense/Firewall/Util.php index 1492e8c0d..c6a8b52ee 100644 --- a/src/opnsense/mvc/app/library/OPNsense/Firewall/Util.php +++ b/src/opnsense/mvc/app/library/OPNsense/Firewall/Util.php @@ -62,6 +62,16 @@ class Util return !empty(filter_var($address, FILTER_VALIDATE_IP)); } + /** + * is provided address a mac address. + * @param string $network address + * @return boolean + */ + public static function isMACAddress($address) + { + return !empty(filter_var($address, FILTER_VALIDATE_MAC)); + } + /** * is provided network valid * @param string $network network diff --git a/src/opnsense/mvc/app/models/OPNsense/Diagnostics/FieldTypes/HostField.php b/src/opnsense/mvc/app/models/OPNsense/Diagnostics/FieldTypes/HostField.php index 165094f89..f50415655 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Diagnostics/FieldTypes/HostField.php +++ b/src/opnsense/mvc/app/models/OPNsense/Diagnostics/FieldTypes/HostField.php @@ -51,7 +51,7 @@ class HostField extends BaseField $parts = preg_split('/ /', $data, -1, PREG_SPLIT_NO_EMPTY); $tokens = []; foreach ($parts as $part) { - if (Util::isIpAddress($part) || Util::isSubnet($part)) { + if (Util::isIpAddress($part) || Util::isSubnet($part) || Util::isMACAddress($part)) { $tokens[] = 'net'; } elseif (in_array(strtolower($part), ['and', 'or', 'not'])) { $tokens[] = strtolower($part); diff --git a/src/opnsense/scripts/interfaces/capture.py b/src/opnsense/scripts/interfaces/capture.py index 09a322a9d..7cd1c57f1 100755 --- a/src/opnsense/scripts/interfaces/capture.py +++ b/src/opnsense/scripts/interfaces/capture.py @@ -140,6 +140,8 @@ if __name__ == '__main__': tokens.append(token) elif token.find('/') > -1: tokens.append('net %s' % token) + elif token.count(':') == 5 and sum([len(x) == 2 for x in token.split(':')]) == 6: + tokens.append('ether host %s' % token) else: tokens.append('host %s' % token) filters.append('( %s )' % ' '.join(tokens))