Skip to content

Commit 76956cf

Browse files
committed
Handle IPv4-mapped IPv6 addresses when resolving connection owner
1 parent ea3e0d6 commit 76956cf

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/display/ui_state.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -98,31 +98,41 @@ impl UIState {
9898
connections_to_procs: &'a HashMap<LocalSocket, String>,
9999
local_socket: &LocalSocket,
100100
) -> Option<&'a String> {
101-
let &LocalSocket { port, protocol, .. } = local_socket;
102-
103101
let name = connections_to_procs
102+
// direct match
104103
.get(local_socket)
104+
// IPv4-mapped IPv6 addresses
105+
.or_else(|| {
106+
let swapped: IpAddr = match local_socket.ip {
107+
IpAddr::V4(v4) => v4.to_ipv6_mapped().into(),
108+
IpAddr::V6(v6) => v6.to_ipv4_mapped()?.into(),
109+
};
110+
connections_to_procs.get(&LocalSocket {
111+
ip: swapped,
112+
..*local_socket
113+
})
114+
})
115+
// address unspecified
105116
.or_else(|| {
106117
connections_to_procs.get(&LocalSocket {
107118
ip: Ipv4Addr::UNSPECIFIED.into(),
108-
port,
109-
protocol,
119+
..*local_socket
110120
})
111121
})
112122
.or_else(|| {
113123
connections_to_procs.get(&LocalSocket {
114124
ip: Ipv6Addr::UNSPECIFIED.into(),
115-
port,
116-
protocol,
125+
..*local_socket
117126
})
118127
});
119128

120129
// only log each orphan connection once
121130
if name.is_none() && self.known_orphan_sockets.borrow_mut().insert(*local_socket) {
122131
match connections_to_procs
123132
.iter()
124-
.find(|(socket, _)| socket.port == port && socket.protocol == protocol)
125-
{
133+
.find(|(&LocalSocket { port, protocol, .. }, _)| {
134+
port == local_socket.port && protocol == local_socket.protocol
135+
}) {
126136
Some((lookalike, name)) => {
127137
warn!(
128138
r#""{name}" owns a similar looking connection, but its local ip doesn't match."#

0 commit comments

Comments
 (0)