Skip to content

fix: prefer using iproute2 instead of ifconfig #1090

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

Merged
merged 2 commits into from
Nov 24, 2024
Merged

fix: prefer using iproute2 instead of ifconfig #1090

merged 2 commits into from
Nov 24, 2024

Conversation

hellodword
Copy link
Contributor

resolves #1089

Same with this

ip -c=never addr show || ip addr show || ifconfig -a

Copy link
Owner

@scop scop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a comment, preferably in the commit message, about why are we making this change?

Copy link
Collaborator

@akinomyoga akinomyoga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit message starts with chore: (which is used for something outside the code, such as library and CI setups), but I think this is more like fix: because this fixes an actual problem #1089.

Also, a test for wol is failing.

@hellodword
Copy link
Contributor Author

Thanks for your review and patience :)

I learned the CONTRIBUTING.md again, and I'll learn to test it locally before pushing to this pr.

@akinomyoga
Copy link
Collaborator

I rebased it and adjusted the code comment and the commit message.

@akinomyoga akinomyoga changed the title chore: prefer using iproute2 instead of ifconfig fix: prefer using iproute2 instead of ifconfig May 13, 2024
@akinomyoga
Copy link
Collaborator

The test for wol is failing because the test requires 33:33:33:33:33:33, which is missing with the iproute2 implementation. The ifconfig command generates 33:33:33:33:33:33 as an HWaddr configured in test/fixtures/shared/bin/ifconfig while ip doesn't read HWaddr in test/fixtures/shared/bin/ifconfig.

@hellodword
Copy link
Contributor Author

The test for wol is failing because the test requires 33:33:33:33:33:33, which is missing with the iproute2 implementation. The ifconfig command generates 33:33:33:33:33:33 as an HWaddr configured in test/fixtures/shared/bin/ifconfig while ip doesn't read HWaddr in test/fixtures/shared/bin/ifconfig.

Thanks!

So a test/fixtures/shared/bin/ip is required, right?

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 33:33:33:33:33:33 brd ff:ff:ff:ff:ff:ff link-netnsid 0

for link show up and:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 33:33:33:33:33:33 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 192.168.80.11/24 brd 192.168.80.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::000:0000:0000:0000/64 scope link 
       valid_lft forever preferred_lft forever

for addr show

Copy link
Collaborator

@akinomyoga akinomyoga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I added another commit to solve another issue in the test framework. I think now this is ready.

hellodword and others added 2 commits August 26, 2024 20:59
For `_comp_compgen_available_interfaces`, we prefer to use ip
(iproute) since long interface names will be truncated by ifconfig
(respective packages in the operating system, e.g. inetutils) [1].
Even for the other functions that use "ifconfig" and "ip", we change
to use `ip` because `ip`'s behavior is more uniform among the systems
and also `ip` is becoming more common in Linux distributions.

[1]: https://github.com/scop/bash-completion/pull/1090/files

Co-authored-by: Koichi Murase <myoga.murase@gmail.com>
Co-authored-by: Yedaya Katsman <43016107+yedayak@users.noreply.github.com>
To test `_comp_compgen_xinetd_services`, we have been using a
directory /test/fixtures/shared/bin (which contained two files `arp`
and `ifconfig`as a mock /etc/xinetd.d.  However, the directory
/test/fixtures/shared/bin is shared with other tests, and the contents
of the files therein are not proper xinetd configurations.  We want to
prepare a separate directory for a mock /etc/xinetd.d.  This patch
adds it under /test/fixtures/_comp_compgen_xinetd_services/xinetd.d.
@yedayak
Copy link
Collaborator

yedayak commented Aug 26, 2024

I rebased on origin/main

@yedayak
Copy link
Collaborator

yedayak commented Sep 1, 2024

The issue of truncation seems to only affect the inetutils version of ifconfig, but the net-tools version doesn't seem to work currently with long interfaces, presumably because it needs some changes in the awk command. I still think this should be merged, but ideally we will make a follow-up PR that fixes ifconfig where it's possible.
My testing was flawed (I tested with an interface with numbers in the name). The issue only seems to happen to the inetutils version.

@akinomyoga
Copy link
Collaborator

akinomyoga commented Sep 1, 2024

The issue of truncation seems to only affect the inetutils version of ifconfig, but the net-tools version doesn't seem to work currently with long interfaces, presumably because it needs some changes in the awk command. I still think this should be merged, but ideally we will make a follow-up PR that fixes ifconfig where it's possible. My testing was flawed (I tested with an interface with numbers in the name). The issue only seems to happen to the inetutils version.

Thank you. So, does that mean the issue of truncation will be totally solved by this PR? Or does it mean there is another issue with the truncation with inetutils? In the latter case, is the part "I still think this should be merged, but ideally we will make a follow-up PR that fixes ifconfig where it's possible." (which was deleted) would be still valid?

@yedayak
Copy link
Collaborator

yedayak commented Sep 2, 2024

Yeah this should totally fix the problem, I think we should merge this. Since the other ifconfig doesn't have an issue there is no need to fix it in a new PR

@akinomyoga
Copy link
Collaborator

Thank you for your clarification!

@scop
Copy link
Owner

scop commented Nov 24, 2024

Unfortunately this has fallen through the cracks based on my old "changes requested" review that has not been reset (I look through open PR's from the list view but do not generally open all of them, including those in that state). And because of that, it also missed the 2.15.0 release :/

Sorry about that, merging now.

@scop scop merged commit 3b1586b into scop:main Nov 24, 2024
7 checks passed
@hellodword hellodword deleted the patch-1 branch November 24, 2024 22:57
yedayak added a commit to yedayak/bash-completion that referenced this pull request Nov 26, 2024
akinomyoga pushed a commit that referenced this pull request Nov 26, 2024
yedayak added a commit to yedayak/bash-completion that referenced this pull request May 11, 2025
bjacquin added a commit to bjacquin/bash-completion that referenced this pull request Jun 15, 2025
Since scop#1090, iproute2 is preferred over ifconfig, however iproute2
provide the list of network interface in name@link in case an interface
is bound to another one (such as macvtap for example), while the real
interface name is not.

  $ ip link show
  2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
      link/ether 48:21:0b:52:19:22 brd ff:ff:ff:ff:ff:ff
  4: eth0.128@eth0: <BROADCAST,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
      link/ether 48:21:0b:52:19:22 brd ff:ff:ff:ff:ff:ff

bash-completion using name@link as provided by iproute2 output then
provide such name in auto completion list, leading to invalid interface
name when auto completing tcpdump arguments.

  $ tcpdump -i <TAB>
  eth0      eth0.128@eth0

This commit handle this use case to drop link name after name@.

  $ tcpdump -i <TAB>
  eth0      eth0.128

See: scop#1090
See: https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/tree/lib/utils.c?h=v6.15.0#n1306
bjacquin added a commit to bjacquin/bash-completion that referenced this pull request Jun 16, 2025
Since scop#1090, iproute2 is preferred over ifconfig, however iproute2
provide the list of network interface in name@link in case an interface
is bound to another one (such as macvtap for example), while the real
interface name is not.

  $ ip link show
  2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
      link/ether 48:21:0b:52:19:22 brd ff:ff:ff:ff:ff:ff
  4: eth0.128@eth0: <BROADCAST,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
      link/ether 48:21:0b:52:19:22 brd ff:ff:ff:ff:ff:ff

bash-completion using name@link as provided by iproute2 output then
provide such name in auto completion list, leading to invalid interface
name when auto completing tcpdump arguments.

  $ tcpdump -i <TAB>
  eth0      eth0.128@eth0

This commit handle this use case to drop link name after name@.

  $ tcpdump -i <TAB>
  eth0      eth0.128

See: scop#1090
See: https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/tree/lib/utils.c?h=v6.15.0#n1306
yedayak added a commit to yedayak/bash-completion that referenced this pull request Jun 16, 2025
We have a fallback to `ifconfig` if `ip` doesn't exist, but it wasn't
tested anywhere that does have `ip` (pretty sure that's all of our current
distro tests).

Introduce a parameterized fixture that "hides" `ip` or `ifconfig` and,
use it in tests.
Also introduce another test that actually makes sure that we find the
correct interfaces.

Follow up to scop#1090
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong network interface name if the name is long
4 participants