-
Notifications
You must be signed in to change notification settings - Fork 547
LocalIP: consider preferred source address when retrieving default route #1883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
We do support multiple IPs on one interface (as it is very common for IPv6). We only use the default route to get the preferred interface. As for multiple IPs on the same interface, we dont have preferences. Try |
I know fastfetch can display multiple IP addresses, but I want to keep the default behavior of showing one main IP address which corresponds to the default gateway (as suggested by the relevant option |
|
Are you saying the current behavior of |
It is. But if we can find which IP the kernel prefers, it would be of course better. |
I'm not familar with how netlink works. Does it work with IPv6? |
Yes it does. I didn't implement it for IPv6 just yet, but it should be a matter of swapping AF_INET for AF_INET6 and parsing route addresses differently. |
Does it mean it will show GUA after it gets implemented? |
@jannispl After applied your patch, no IP is displayed. |
I'm not sure how IPv6 should be handled. The default route will most likely be a link-local address. Also, IPv6 routes do not seem to have the concept of a "preferred source address". Additionally, interfaces very often have even multiple GUA, for instance when using privacy extensions. Additionally, the way IPv6 is handled currently (as a fallback for when no IPv4 is present) seems kinda odd to me. It could make sense to split the
Hmm, this would indicate that you have a default route with a non-zero preferred source address that is not part of the interface's addresses. What do you get for |
I guess no?
There are temp addresses. I think it's ok to report them if the kernel use them for connection by default |
I don't have many systems with ipv6 properly configured, but for those that have it, I have a link-local gateway in the default route.
Not sure how to accurately tell which address the kernel is going to use. Maybe we should implement something like |
I made a logic mistake when checking for |
Please use |
Although LocalIP module is called LocalIP, it detects some info about the interfaces themselves like MTU and mac address. Split it would make the information duplicate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances the local IP detection functionality to prioritize the preferred source address from the default route instead of simply using the first IP address found on the default route interface. The implementation adds netlink socket communication on Linux to retrieve routing information directly from the kernel, similar to how the ip route
command works.
Key changes:
- Replaces
/proc/net/route
parsing with netlink socket communication for more complete routing information - Adds preferred source address retrieval functionality across all supported platforms
- Updates IP filtering logic to prefer the default route's source address when available
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
File | Description |
---|---|
src/detection/localip/localip_linux.c | Updates IP filtering logic to use preferred source address for default route determination |
src/common/netif/netif_linux.c | Replaces proc filesystem parsing with comprehensive netlink-based route lookup |
src/common/netif/netif_windows.c | Updates function signature to support preferred source address parameter |
src/common/netif/netif_haiku.c | Updates function signature to support preferred source address parameter |
src/common/netif/netif_bsd.c | Adds preferred source address extraction from routing messages |
src/common/netif/netif.h | Adds new function declaration for preferred source address retrieval |
src/common/netif/netif.c | Implements caching and initialization for preferred source address functionality |
@jannispl Please address ( or close ) the feedback from AI. |
6f80039
to
bf5a55c
Compare
Thanks |
On my system, the default route's interface has more than one IP address:
In its default configuration, fastfetch appears to retrieve the first IP address it finds on the default route's interface:
I expected it to show the default route's preferred source address (
10.0.0.8
) instead. Unfortunately, this information is not present in/proc/net/route
so we have to resort to communicating with the kernel directly - much likeip route
does.