@@ -23,6 +23,8 @@ protected function groups(string $search, string $like, int $limit, ?User $user)
2323 ->orWhere ('serial ' , 'like ' , $ like )
2424 ->orWhere ('notes ' , 'like ' , $ like );
2525
26+ $ mac = strtolower (str_replace ([': ' , '- ' ], '' , $ search ));
27+
2628 if (preg_match ('/^[0-9.]+$/ ' , $ search ) && str_contains ($ search , '. ' )) {
2729 $ query ->leftJoin ('ports ' , 'ports.device_id ' , '= ' , 'devices.device_id ' )
2830 ->leftJoin ('ipv4_addresses ' , 'ipv4_addresses.port_id ' , '= ' , 'ports.port_id ' );
@@ -35,15 +37,22 @@ protected function groups(string $search, string $like, int $limit, ?User $user)
3537 $ query ->leftJoin ('ports ' , 'ports.device_id ' , '= ' , 'devices.device_id ' )
3638 ->leftJoin ('ipv6_addresses ' , 'ipv6_addresses.port_id ' , '= ' , 'ports.port_id ' );
3739 $ q ->orWhere ('ipv6_addresses.ipv6_address ' , 'like ' , $ like )
40+ ->orWhere ('ipv6_addresses.ipv6_compressed ' , 'like ' , $ like )
3841 ->orWhere ('overwrite_ip ' , 'like ' , $ like )
39- ->orWhere ('ports.ifPhysAddress ' , 'like ' , '% ' . str_replace ( ' : ' , '' , $ search ) . '% ' );
42+ ->orWhere ('ports.ifPhysAddress ' , 'like ' , '% ' . $ mac . '% ' );
4043 if (\LibreNMS \Util \IPv6::isValid ($ search , false )) {
4144 $ q ->orWhere ('ip ' , '= ' , inet_pton ($ search ));
4245 }
43- } elseif (ctype_xdigit ($ mac = str_replace ([ ' : ' , ' - ' ], '' , $ search ) )) {
46+ } elseif (ctype_xdigit ($ mac )) {
4447 $ query ->leftJoin ('ports ' , 'ports.device_id ' , '= ' , 'devices.device_id ' );
4548 $ q ->orWhere ('ports.ifPhysAddress ' , 'like ' , '% ' . $ mac . '% ' );
4649 }
50+
51+ // A MAC-style search (with or without separators) can also match FDB entries
52+ if (ctype_xdigit ($ mac )) {
53+ $ query ->leftJoin ('ports_fdb ' , 'ports_fdb.device_id ' , '= ' , 'devices.device_id ' );
54+ $ q ->orWhere ('ports_fdb.mac_address ' , 'like ' , '% ' . $ mac . '% ' );
55+ }
4756 });
4857
4958 $ devices = $ query ->orderBy ('display ' )->limit ($ limit )->get ()
0 commit comments