From patchwork Fri Jun 4 04:24:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?0JzQsNGA0Log0JrQvtGA0LXQvdCx0LXRgNCz?= X-Patchwork-Id: 455038 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9B60C4708F for ; Fri, 4 Jun 2021 04:25:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B93AC6140B for ; Fri, 4 Jun 2021 04:25:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229800AbhFDE0r (ORCPT ); Fri, 4 Jun 2021 00:26:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229452AbhFDE0r (ORCPT ); Fri, 4 Jun 2021 00:26:47 -0400 Received: from mail-ua1-x935.google.com (mail-ua1-x935.google.com [IPv6:2607:f8b0:4864:20::935]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00970C06174A for ; Thu, 3 Jun 2021 21:24:50 -0700 (PDT) Received: by mail-ua1-x935.google.com with SMTP id m23so4548530uao.12 for ; Thu, 03 Jun 2021 21:24:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=1p6Vhy2bTbozEOWPiJDqnwlyFOp9kKQyHPsFai3s6Lg=; b=qW/uR5O3rDg5dd8IHvrPzQ8HOQZR/KHzNqZvgtBQ+7I+Yb3/BtkaekaLeicOwW5gVZ atj914uqm++8JsQ5OgDaFt9nwX9ZHLDuCbZFGH6Neh0QccefSAT7n1GjXAP9wTNxh6MB qbIZ6u4OUJpTD0mMEXoqPzcGhLnatW6Ua39jNOej98wonvionSOQ9XWG0iX5jJjomjRx lTt1ALFs5Gkwe6EHl5Rx4gWdPnjLvHfIswcmwUgdjaq+AKopgL9S+f8Xjgq9WTItGfw7 fJofcoCyb0eQkiF/YX52npfEpxiyhgMEWTxaNi4L1owEqx1P8lGVrkIlXXoRUsGL8pWB r/ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=1p6Vhy2bTbozEOWPiJDqnwlyFOp9kKQyHPsFai3s6Lg=; b=APnAsahT0oe2zBy5CgE0EOvRC0IJNDlteYrBqDS18kMLtD2VWstUm35edgU3Z78OGy 4e9Le0nOWOoSYtl3I7tNMdknPsFOrsOnUbcyzexbNxybL55C95WAD8EiudE1ghS9lnvE igqFRb8I86JkeF8CxPLbkCLYIVx1eqm7YqBbcUkKQy5cVQODvmFsNyUh+k8fZWQycVmi 02dbdC7EfE1RDAY5mHSzMRYgKC0ZVWGto81Aw6dwzrwBoXnKx+rPqdz8jGo+LGjnS8z2 OJATPSQG9Spwoy7uuA39Huk3hL+aLuzxfyEYEPCbqgyGXvOLG3ph6Qdy0Mwhv7uk7bpz I6ZQ== X-Gm-Message-State: AOAM5322Bcd0R5nzRMUj/bYqT4sRFy+aF4WdLty1NalJ1TdKSba7Zcvm kCdsXv15axKkTkZbtRfN+XFFsKMTGpM1OsZ2yyFVL2CAvW7z0A== X-Google-Smtp-Source: ABdhPJyRTuuz3T3aW5Rc1C6FnhYB75GgNtmjXeAPBppNp/eFmOx8/IY3RfGkQQm0Gvj7BbvvQU774kwtJEUNyrEEEHU= X-Received: by 2002:ab0:185a:: with SMTP id j26mr1938928uag.33.1622780690000; Thu, 03 Jun 2021 21:24:50 -0700 (PDT) MIME-Version: 1.0 From: =?utf-8?b?0JzQsNGA0Log0JrQvtGA0LXQvdCx0LXRgNCz?= Date: Fri, 4 Jun 2021 09:24:39 +0500 Message-ID: Subject: [PATCH] ip link get dev if%u" now works To: netdev@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The same: https://github.com/shemminger/iproute2/pull/43 I give any rights on this code, please merge. commit c71a164fb3abbce177cb2692e25ebc54e0156d5a (refs/remotes/origin/getindex) Author: Коренберг ☢️ Марк Date: Thu May 13 15:43:14 2021 +0500 ip: "ip link get dev if%u" now works diff --git a/ip/ip_common.h b/ip/ip_common.h index 9a31e837..1eb40a1e 100644 --- a/ip/ip_common.h +++ b/ip/ip_common.h @@ -89,7 +89,7 @@ int do_seg6(int argc, char **argv); int do_ipnh(int argc, char **argv); int do_mptcp(int argc, char **argv); -int iplink_get(char *name, __u32 filt_mask); +int iplink_get(unsigned ifindex, __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 0bbcee2b..9be6ea4d 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -10,6 +10,7 @@ * */ +#include #include #include #include @@ -2111,7 +2112,8 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action) * the link device */ if (filter_dev && filter.group == -1 && do_link == 1) { - if (iplink_get(filter_dev, RTEXT_FILTER_VF) < 0) { + assert(filter.ifindex); + if (iplink_get(filter.ifindex, RTEXT_FILTER_VF) < 0) { perror("Cannot send link get request"); delete_json_obj(); exit(1); diff --git a/ip/iplink.c b/ip/iplink.c index 27c9be44..43272c6b 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -1101,21 +1101,17 @@ 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(unsigned ifindex, __u32 filt_mask) { struct iplink_req req = { .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)), .n.nlmsg_flags = NLM_F_REQUEST, .n.nlmsg_type = RTM_GETLINK, .i.ifi_family = preferred_family, + .i.ifi_index = ifindex, }; struct nlmsghdr *answer; - if (name) { - addattr_l(&req.n, sizeof(req), - !check_ifname(name) ? IFLA_IFNAME : IFLA_ALT_IFNAME, - name, strlen(name) + 1); - } addattr32(&req.n, sizeof(req), IFLA_EXT_MASK, filt_mask); if (rtnl_talk(&rth, &req.n, &answer) < 0)