Skip to content

Commit 0bbb00f

Browse files
Improve logging on rejected packets
1 parent 7acf1ac commit 0bbb00f

File tree

2 files changed

+39
-14
lines changed

2 files changed

+39
-14
lines changed

src/iface/interface/ipv4.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,27 @@ impl InterfaceInner {
181181
{
182182
// Ignore IP packets not directed at us, or broadcast, or any of the multicast groups.
183183
// If AnyIP is enabled, also check if the packet is routed locally.
184-
if !self.any_ip
185-
|| !ipv4_repr.dst_addr.x_is_unicast()
186-
|| self
187-
.routes
188-
.lookup(&IpAddress::Ipv4(ipv4_repr.dst_addr), self.now)
189-
.map_or(true, |router_addr| !self.has_ip_addr(router_addr))
184+
185+
if !self.any_ip {
186+
net_trace!("Rejecting IPv4 packet; any_ip=false");
187+
return None;
188+
}
189+
190+
if !ipv4_repr.dst_addr.x_is_unicast() {
191+
net_trace!(
192+
"Rejecting IPv4 packet; {} is not a unicast address",
193+
ipv4_repr.dst_addr
194+
);
195+
return None;
196+
}
197+
198+
if self
199+
.routes
200+
.lookup(&IpAddress::Ipv4(ipv4_repr.dst_addr), self.now)
201+
.map_or(true, |router_addr| !self.has_ip_addr(router_addr))
190202
{
203+
net_trace!("Rejecting IPv4 packet; no matching routes");
204+
191205
return None;
192206
}
193207
}

src/iface/interface/ipv6.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,26 @@ impl InterfaceInner {
212212
&& !self.has_multicast_group(ipv6_repr.dst_addr)
213213
&& !ipv6_repr.dst_addr.is_loopback()
214214
{
215-
// If AnyIP is enabled, also check if the packet is routed locally.
216-
if !self.any_ip
217-
|| !ipv6_repr.dst_addr.x_is_unicast()
218-
|| self
219-
.routes
220-
.lookup(&IpAddress::Ipv6(ipv6_repr.dst_addr), self.now)
221-
.map_or(true, |router_addr| !self.has_ip_addr(router_addr))
215+
if !self.any_ip {
216+
net_trace!("Rejecting IPv6 packet; any_ip=false");
217+
return None;
218+
}
219+
220+
if !ipv6_repr.dst_addr.x_is_unicast() {
221+
net_trace!(
222+
"Rejecting IPv6 packet; {} is not a unicast address",
223+
ipv4_repr.dst_addr
224+
);
225+
return None;
226+
}
227+
228+
if self
229+
.routes
230+
.lookup(&IpAddress::Ipv6(ipv6_repr.dst_addr), self.now)
231+
.map_or(true, |router_addr| !self.has_ip_addr(router_addr))
222232
{
223-
net_trace!("packet IP address not for this interface");
233+
net_trace!("Rejecting IPv6 packet; no matching routes");
234+
224235
return None;
225236
}
226237
}

0 commit comments

Comments
 (0)