* [PATCH] ip link get dev if%u" now works
@ 2021-06-04 4:24 Марк Коренберг
2021-06-06 3:51 ` Stephen Hemminger
2021-06-10 0:07 ` Stephen Hemminger
0 siblings, 2 replies; 3+ messages in thread
From: Марк Коренберг @ 2021-06-04 4:24 UTC (permalink / raw)
To: netdev
[-- Attachment #1: Type: text/plain, Size: 128 bytes --]
The same:
https://github.com/shemminger/iproute2/pull/43
I give any rights on this code, please merge.
--
Segmentation fault
[-- Attachment #2: ifu.patch --]
[-- Type: text/x-patch, Size: 2144 bytes --]
commit c71a164fb3abbce177cb2692e25ebc54e0156d5a (refs/remotes/origin/getindex)
Author: Коренберг ☢️ Марк <mark@ideco.ru>
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 <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -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)
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ip link get dev if%u" now works
2021-06-04 4:24 [PATCH] ip link get dev if%u" now works Марк Коренберг
@ 2021-06-06 3:51 ` Stephen Hemminger
2021-06-10 0:07 ` Stephen Hemminger
1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2021-06-06 3:51 UTC (permalink / raw)
To: Марк
Коренберг
Cc: netdev
On Fri, 4 Jun 2021 09:24:39 +0500
Марк Коренберг <socketpair@gmail.com> wrote:
> The same:
> https://github.com/shemminger/iproute2/pull/43
>
> I give any rights on this code, please merge.
>
Read the comment, all patches for iproute be submitted as normal
patches to netdev@vger.kernel.org.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ip link get dev if%u" now works
2021-06-04 4:24 [PATCH] ip link get dev if%u" now works Марк Коренберг
2021-06-06 3:51 ` Stephen Hemminger
@ 2021-06-10 0:07 ` Stephen Hemminger
1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2021-06-10 0:07 UTC (permalink / raw)
To: Марк
Коренберг
Cc: netdev
> commit c71a164fb3abbce177cb2692e25ebc54e0156d5a (refs/remotes/origin/getindex)
> Author: Коренберг ☢️ Марк <mark@ideco.ru>
> Date: Thu May 13 15:43:14 2021 +0500
>
> ip: "ip link get dev if%u" now works
Patch is missing Signed-off-by
>
> 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);
WARNING: Prefer 'unsigned int' to bare use of 'unsigned'
#94: FILE: ip/ip_common.h:92:
+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 <assert.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> @@ -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);
No assert() please do more complete error message and handling.
> + 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);
> - }
The old code supported matching by alter name, it looks like with your
change it no longer does.
> addattr32(&req.n, sizeof(req), IFLA_EXT_MASK, filt_mask);
>
> if (rtnl_talk(&rth, &req.n, &answer) < 0)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-06-10 0:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-04 4:24 [PATCH] ip link get dev if%u" now works Марк Коренберг
2021-06-06 3:51 ` Stephen Hemminger
2021-06-10 0:07 ` Stephen Hemminger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).