Interfaces: Diagnostics: Packet Capture - support mac addresses in "Host Address" field. closes https://github.com/opnsense/core/issues/6159

This commit is contained in:
Ad Schellevis 2023-01-02 17:46:38 +01:00
parent e5d6acd2eb
commit 720ffdc561
4 changed files with 15 additions and 3 deletions

View File

@ -35,13 +35,13 @@
<label>Host Address</label>
<type>text</type>
<help>
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
</help>
</field>
<field>

View File

@ -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

View File

@ -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);

View File

@ -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))