batctl: Fix upstream reference in backported patch
[feed/routing.git] / batctl / patches / 0005-batctl-Prefer-netlink-hardif-status-retrieval-over-s.patch
1 From: Sven Eckelmann <sven@narfation.org>
2 Date: Wed, 19 Jun 2019 09:37:50 +0200
3 Subject: batctl: Prefer netlink hardif status retrieval over sysfs
4
5 The sysfs code in batman-adv was changed to print a deprecated warning when
6 sysfs files are accessed. The `batctl if` call would therefore cause
7 warnings like this in the kernel log:
8
9 batman_adv: [Deprecated]: batctl (pid 18540) Use of sysfs file "iface_status".
10 Use batadv genl family instead
11
12 It is now appropriate to try the generic netlink BATADV_CMD_GET_HARDIF
13 request first to get the status of the interface before falling back to
14 sysfs.
15
16 Reported-by: Linus Lüssing <linus.luessing@c0d3.blue>
17 Signed-off-by: Sven Eckelmann <sven@narfation.org>
18
19 Origin: upstream, https://git.open-mesh.org/batctl.git/commit/ce5f0efb35bff8a80992df63876bcac1d4a94867
20
21 diff --git a/interface.c b/interface.c
22 index 5ff25a7b790d68aa69155f0cc7661080145ac86e..0a694c9f41f71a3dd72ae87b79b28434f7e8918f 100644
23 --- a/interface.c
24 +++ b/interface.c
25 @@ -67,18 +67,18 @@ static int get_iface_status_netlink_parse(struct nl_msg *msg, void *arg)
26 static char *get_iface_status_netlink(unsigned int meshif, unsigned int hardif,
27 char *iface_status)
28 {
29 + char *ret_status = NULL;
30 struct nl_sock *sock;
31 struct nl_msg *msg;
32 int batadv_family;
33 struct nl_cb *cb;
34 int ret;
35
36 - strncpy(iface_status, "<error reading status>\n", IFACE_STATUS_LEN);
37 - iface_status[IFACE_STATUS_LEN - 1] = '\0';
38 + iface_status[0] = '\0';
39
40 sock = nl_socket_alloc();
41 if (!sock)
42 - return iface_status;
43 + return NULL;
44
45 ret = genl_connect(sock);
46 if (ret < 0)
47 @@ -111,6 +111,9 @@ static char *get_iface_status_netlink(unsigned int meshif, unsigned int hardif,
48
49 nl_recvmsgs(sock, cb);
50
51 + if (strlen(iface_status) > 0)
52 + ret_status = iface_status;
53 +
54 err_free_msg:
55 nlmsg_free(msg);
56 err_free_cb:
57 @@ -118,7 +121,7 @@ static char *get_iface_status_netlink(unsigned int meshif, unsigned int hardif,
58 err_free_sock:
59 nl_socket_free(sock);
60
61 - return iface_status;
62 + return ret_status;
63 }
64
65 static struct nla_policy link_policy[IFLA_MAX + 1] = {
66 @@ -161,13 +164,17 @@ static int print_interfaces_rtnl_parse(struct nl_msg *msg, void *arg)
67 if (master != print_arg->ifindex)
68 goto err;
69
70 - snprintf(path_buff, sizeof(path_buff), SYS_IFACE_STATUS_FMT, ifname);
71 - ret = read_file("", path_buff, USE_READ_BUFF | SILENCE_ERRORS, 0, 0, 0);
72 - if (ret != EXIT_SUCCESS)
73 - status = get_iface_status_netlink(master, ifm->ifi_index,
74 - iface_status);
75 - else
76 - status = line_ptr;
77 + status = get_iface_status_netlink(master, ifm->ifi_index, iface_status);
78 + if (!status) {
79 + snprintf(path_buff, sizeof(path_buff), SYS_IFACE_STATUS_FMT,
80 + ifname);
81 + ret = read_file("", path_buff, USE_READ_BUFF | SILENCE_ERRORS,
82 + 0, 0, 0);
83 + if (ret != EXIT_SUCCESS)
84 + status = "<error reading status>\n";
85 + else
86 + status = line_ptr;
87 + }
88
89 printf("%s: %s", ifname, status);
90