diff mbox series

[iproute2] iplink: fix accepting non-canonical ifxxx names

Message ID 20221102083811.3906521-1-a.s.protopopov@gmail.com (mailing list archive)
State New, archived
Delegated to: Stephen Hemminger
Headers show
Series [iproute2] iplink: fix accepting non-canonical ifxxx names | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Anton Protopopov Nov. 2, 2022, 8:38 a.m. UTC
The ip link command is supposed to support names like if<index>, but at the
moment it fails like this:

  # ip link show dev if2
  RTNETLINK answers: No such device
  Cannot send link get request: No such device

This happens because the name 'if2' is used as an attribute in a RTM_GETLINK
message. Fix this by converting a given device name to the canonical name.

Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
---
 ip/ip_common.h | 2 +-
 ip/ipaddress.c | 3 ++-
 ip/iplink.c    | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/ip/ip_common.h b/ip/ip_common.h
index c4cb1bcb..9ca4905b 100644
--- a/ip/ip_common.h
+++ b/ip/ip_common.h
@@ -94,7 +94,7 @@  int do_mptcp(int argc, char **argv);
 int do_ioam6(int argc, char **argv);
 int do_ipstats(int argc, char **argv);
 
-int iplink_get(char *name, __u32 filt_mask);
+int iplink_get(const char *name, __u32 filt_mask);
 int iplink_ifla_xstats(int argc, char **argv);
 
 int ip_link_list(req_filter_fn_t filter_fn, struct nlmsg_chain *linfo);
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index 456545bb..1896d018 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -2109,7 +2109,7 @@  static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
 	struct nlmsg_chain linfo = { NULL, NULL};
 	struct nlmsg_chain _ainfo = { NULL, NULL}, *ainfo = &_ainfo;
 	struct nlmsg_list *l;
-	char *filter_dev = NULL;
+	const char *filter_dev = NULL;
 	int no_link = 0;
 
 	ipaddr_reset_filter(oneline, 0);
@@ -2207,6 +2207,7 @@  static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
 			fprintf(stderr, "Device \"%s\" does not exist.\n", filter_dev);
 			return -1;
 		}
+		filter_dev = ll_index_to_name(filter.ifindex);
 	}
 
 	if (action == IPADD_FLUSH)
diff --git a/ip/iplink.c b/ip/iplink.c
index 92ce6c47..13ee5afe 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -1137,7 +1137,7 @@  static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
 	return 0;
 }
 
-int iplink_get(char *name, __u32 filt_mask)
+int iplink_get(const char *name, __u32 filt_mask)
 {
 	struct iplink_req req = {
 		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),