blob: fc6a91a0ae30509beed9aa7e44ea091a81246254 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001From: Sven Eckelmann <sven@narfation.org>
2Date: Mon, 10 May 2021 15:05:42 +0200
3Subject: batman-adv: Always send iface index+name in genlmsg
4
5The batman-adv netlink messages often contain the interface index and
6interface name in the same message. This makes it easy for the receiver to
7operate on the incoming data when it either needs to print something or
8needs to operate on the interface index.
9
10But one of the attributes was missing for:
11
12* neighbor table dumps
13* originator table dumps
14* gateway list dumps
15* query of hardif information
16* query of vid information
17
18The userspace therefore had to implement special workarounds using
19SIOCGIFNAME or SIOCGIFINDEX depending on what was actually provided.
20Providing both information simplifies the userspace code massively without
21adding a lot of extra overhead in the kernel portion.
22
23Signed-off-by: Sven Eckelmann <sven@narfation.org>
24Origin: upstream, https://git.open-mesh.org/batman-adv.git/commit/77c7d62618259f22f36427eaa62668e6e1c43090
25
26--- a/net/batman-adv/bat_iv_ogm.c
27+++ b/net/batman-adv/bat_iv_ogm.c
28@@ -1849,6 +1849,8 @@ batadv_iv_ogm_orig_dump_subentry(struct
29 orig_node->orig) ||
30 nla_put(msg, BATADV_ATTR_NEIGH_ADDRESS, ETH_ALEN,
31 neigh_node->addr) ||
32+ nla_put_string(msg, BATADV_ATTR_HARD_IFNAME,
33+ neigh_node->if_incoming->net_dev->name) ||
34 nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX,
35 neigh_node->if_incoming->net_dev->ifindex) ||
36 nla_put_u8(msg, BATADV_ATTR_TQ, tq_avg) ||
37@@ -2078,6 +2080,8 @@ batadv_iv_ogm_neigh_dump_neigh(struct sk
38
39 if (nla_put(msg, BATADV_ATTR_NEIGH_ADDRESS, ETH_ALEN,
40 hardif_neigh->addr) ||
41+ nla_put_string(msg, BATADV_ATTR_HARD_IFNAME,
42+ hardif_neigh->if_incoming->net_dev->name) ||
43 nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX,
44 hardif_neigh->if_incoming->net_dev->ifindex) ||
45 nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS,
46@@ -2459,6 +2463,8 @@ static int batadv_iv_gw_dump_entry(struc
47 router->addr) ||
48 nla_put_string(msg, BATADV_ATTR_HARD_IFNAME,
49 router->if_incoming->net_dev->name) ||
50+ nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX,
51+ router->if_incoming->net_dev->ifindex) ||
52 nla_put_u32(msg, BATADV_ATTR_BANDWIDTH_DOWN,
53 gw_node->bandwidth_down) ||
54 nla_put_u32(msg, BATADV_ATTR_BANDWIDTH_UP,
55--- a/net/batman-adv/bat_v.c
56+++ b/net/batman-adv/bat_v.c
57@@ -145,6 +145,8 @@ batadv_v_neigh_dump_neigh(struct sk_buff
58
59 if (nla_put(msg, BATADV_ATTR_NEIGH_ADDRESS, ETH_ALEN,
60 hardif_neigh->addr) ||
61+ nla_put_string(msg, BATADV_ATTR_HARD_IFNAME,
62+ hardif_neigh->if_incoming->net_dev->name) ||
63 nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX,
64 hardif_neigh->if_incoming->net_dev->ifindex) ||
65 nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS,
66@@ -297,6 +299,8 @@ batadv_v_orig_dump_subentry(struct sk_bu
67 if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN, orig_node->orig) ||
68 nla_put(msg, BATADV_ATTR_NEIGH_ADDRESS, ETH_ALEN,
69 neigh_node->addr) ||
70+ nla_put_string(msg, BATADV_ATTR_HARD_IFNAME,
71+ neigh_node->if_incoming->net_dev->name) ||
72 nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX,
73 neigh_node->if_incoming->net_dev->ifindex) ||
74 nla_put_u32(msg, BATADV_ATTR_THROUGHPUT, throughput) ||
75@@ -737,6 +741,12 @@ static int batadv_v_gw_dump_entry(struct
76 genlmsg_cancel(msg, hdr);
77 goto out;
78 }
79+
80+ if (nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX,
81+ router->if_incoming->net_dev->ifindex)) {
82+ genlmsg_cancel(msg, hdr);
83+ goto out;
84+ }
85
86 if (nla_put_u32(msg, BATADV_ATTR_BANDWIDTH_DOWN,
87 gw_node->bandwidth_down)) {
88--- a/net/batman-adv/netlink.c
89+++ b/net/batman-adv/netlink.c
90@@ -813,6 +813,10 @@ static int batadv_netlink_hardif_fill(st
91 bat_priv->soft_iface->ifindex))
92 goto nla_put_failure;
93
94+ if (nla_put_string(msg, BATADV_ATTR_MESH_IFNAME,
95+ bat_priv->soft_iface->name))
96+ goto nla_put_failure;
97+
98 if (nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX,
99 net_dev->ifindex) ||
100 nla_put_string(msg, BATADV_ATTR_HARD_IFNAME,
101@@ -1044,6 +1048,10 @@ static int batadv_netlink_vlan_fill(stru
102 bat_priv->soft_iface->ifindex))
103 goto nla_put_failure;
104
105+ if (nla_put_string(msg, BATADV_ATTR_MESH_IFNAME,
106+ bat_priv->soft_iface->name))
107+ goto nla_put_failure;
108+
109 if (nla_put_u32(msg, BATADV_ATTR_VLANID, vlan->vid & VLAN_VID_MASK))
110 goto nla_put_failure;
111