ipv4: Fix log message for martian source
Subsystems (3)
PATCH 1/1 ipv4: Fix log message for martian source
From: Clara Engler <[email protected]>
At the current moment, the log message for packets with a martian source IP address is wrong. In fact, the current syntax looks as follows:
``` martian source <DESTINATION> from <SOURCE>, on dev <DEV> ```
This is wrong because <SOURCE> and <DESTINATION> need to be swapped.
Another verification for this claim can be seen when looking at the (correct) implementation for logging packets with a martian destination IP address, which happens to be identical, as it can be seen in line 2477 on the same file.
--- net/ipv4/route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/route.c +1 -1
@@ -1796,7 +1796,7 @@ static void ip_handle_martian_source(struct net_device *dev,* the only hint is MAC header. */ pr_warn ("martian source %pI4 from %pI4, on dev %s\n" , - &daddr, &saddr, dev->name); + &saddr, &daddr, dev->name);if (dev->hard_header_len &&skb_mac_header_was_set (skb)) { print_hex_dump(KERN_WARNING, "ll header: ", DUMP_PREFIX_OFFSET, 16, 1,
Signature · 1 line
2.50.1 (Apple Git-155)
Jakub Kicinski
maintainernet/ipv4/route.c static void ip_handle_martian_source(struct net_device *dev, · line 1799
Quoted 6 lines · On Wed, 26 Nov 2025 22:59:58 +0100 Clara Engler wrote:
net/ipv4/route.c +1
-1@@ -1796,7 +1796,7 @@ static void ip_handle_martian_source(struct net_device *dev,* the only hint is MAC header. */ pr_warn ("martian source %pI4 from %pI4, on dev %s\n" , - &daddr, &saddr, dev->name); + &saddr, &daddr, dev->name);
imagine there was another comma in this print:
martian source, %pI4 from %pI4, on dev %s
we should leave it as is, I think.
People may be grepping logs for this exact format..
Signature · 1 line
pw-bot: reject
Quoted 5 lines · Jakub Kicinski
imagine there was another comma in this print:
martian source, %pI4 from %pI4, on dev %s
we should leave it as is, I think.
Yes, this comma indeed makes it more helpful.
Personally, my preference would lie in a format such as the following:
martian source (src={SRC}, dst={DST}, dev={DEV}with a respective similar change to the martian destination.
Quoted 1 line
People may be grepping logs for this exact format..
I agree with you partially. For such a trivial change, it is probably not worth to pursue this any further, but I don't think "log stability" is something to aim for/guarantee.
Thank You
Clara
Jakub Kicinski
maintainerQuoted 5 lines · On Fri, 28 Nov 2025 17:47:33 +0100 Clara Engler wrote:
Quoted 1 line
People may be grepping logs for this exact format..
I agree with you partially. For such a trivial change, it is probably not worth to pursue this any further, but I don't think "log stability" is something to aim for/guarantee.
Could you explain how you discovered the issue? (it should ideally be part of the commit msg TBH)
Quoted 2 lines · Jakub Kicinski
Could you explain how you discovered the issue? (it should ideally be part of the commit msg TBH)
In the past few days, I toyed around with TUN interfaces and using them as a tunnel (receiving packets via a TUN and sending them over a TCP stream; receiving packets from a TCP stream and writing them to a TUN).[^1]
When these IP addresses contained local IPs (i.e. 10.0.0.0/8 in source and destination), everything worked fine. However, sending them to a real routeable IP address on the internet led to them being treated as a martian packet, obviously. I was able to fix this with some sysctl's and iptables settings, but while debugging I found the log message rather confusing, as I was unsure on whether the packet that gets dropped was the packet originating from me, or the response from the endpoint, as "martian source <ROUTEABLE IP>" could also be falsely interpreted as the response packet being martian, due to the word "source" followed by the routeable IP address, implying the source address of that packet is set to this IP.
[^1]: https://backreference.org/2010/03/26/tuntap-interface-tutorial
Jakub Kicinski
maintainerQuoted 21 lines · On Mon, 1 Dec 2025 19:54:23 +0100 Clara Engler wrote:
Quoted 2 lines · Jakub Kicinski
Could you explain how you discovered the issue? (it should ideally be part of the commit msg TBH)
In the past few days, I toyed around with TUN interfaces and using them as a tunnel (receiving packets via a TUN and sending them over a TCP stream; receiving packets from a TCP stream and writing them to a TUN).[^1]
When these IP addresses contained local IPs (i.e. 10.0.0.0/8 in source and destination), everything worked fine. However, sending them to a real routeable IP address on the internet led to them being treated as a martian packet, obviously. I was able to fix this with some sysctl's and iptables settings, but while debugging I found the log message rather confusing, as I was unsure on whether the packet that gets dropped was the packet originating from me, or the response from the endpoint, as "martian source <ROUTEABLE IP>" could also be falsely interpreted as the response packet being martian, due to the word "source" followed by the routeable IP address, implying the source address of that packet is set to this IP.
Quoted 1 line
[^1]: https://backreference.org/2010/03/26/tuntap-interface-tutorial
I see. Sounds legit, we can adjust the error msg per you suggestion. Unfortunately, we just entered a merge window and then there will be an end-of-year shutdown period so you'll need to post v2 in around a month :(
Quoted 4 lines · Jakub Kicinski
I see. Sounds legit, we can adjust the error msg per you suggestion. Unfortunately, we just entered a merge window and then there will be an end-of-year shutdown period so you'll need to post v2 in around a month :(
Alright, will come back to it at the start of next year!