]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
iw: add command to inject a frame via direct mesh link to mesh peer
authorPradeep Kumar Chitrapu <pradeepc@codeaurora.org>
Mon, 8 Apr 2019 23:29:23 +0000 (04:59 +0530)
committerJohannes Berg <johannes.berg@intel.com>
Fri, 26 Apr 2019 09:54:18 +0000 (11:54 +0200)
Add mpath command to inject ethernet frame over direct mesh link to
given peer, bypassing the mpath table lookup. This helps to send data
frames over unexcersized direct mesh path, which is not selected as
next_hop node. This can be helpful in measuring link metrics.

Format:
$ iw dev <devname> mpath probe <Peer MAC> frame <pattern>

Example:
$ iw wlan0 mpath probe aa:bb:cc:dd:ee:ff frame aa:bb:cc:dd:ee:ff:kk:ll:mm:nn:oo:pp:yy:zz

Frame pattern is supplied as hex pattern of the form aa:bb:cc without
leading 0x. Frame type and length are expected to be of ethernet frame
type.

Signed-off-by: Pradeep Kumar Chitrapu <pradeepc@codeaurora.org>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
mpath.c

diff --git a/mpath.c b/mpath.c
index ff0b7419fd2be08888b7801956f9967a36b6fbb0..e39c24ba4403f50f01d3151989bd6663c3e48570 100644 (file)
--- a/mpath.c
+++ b/mpath.c
@@ -90,6 +90,45 @@ static int print_mpath_handler(struct nl_msg *msg, void *arg)
        return NL_SKIP;
 }
 
+static int handle_mpath_probe(struct nl80211_state *state,
+                             struct nl_msg *msg,
+                             int argc, char **argv,
+                             enum id_input id)
+{
+       unsigned char dst[ETH_ALEN];
+       unsigned char *frame;
+       size_t frame_len;
+
+       if (argc < 3)
+               return 1;
+
+       if (mac_addr_a2n(dst, argv[0])) {
+               fprintf(stderr, "invalid mac address\n");
+               return 2;
+       }
+
+       if (strcmp("frame", argv[1]) != 0)
+               return 1;
+
+       frame = parse_hex(argv[2], &frame_len);
+       if (!frame) {
+               fprintf(stderr, "invalid frame pattern: %p\n", frame);
+               return 2;
+       }
+
+       NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst);
+       NLA_PUT(msg, NL80211_ATTR_FRAME, frame_len, frame);
+
+       return 0;
+ nla_put_failure:
+       return -ENOBUFS;
+}
+COMMAND(mpath, probe, "<destination MAC address> frame <frame>",
+       NL80211_CMD_PROBE_MESH_LINK, 0, CIB_NETDEV, handle_mpath_probe,
+       "Inject ethernet frame to given peer overriding the next hop\n"
+       "lookup from mpath table.\n."
+       "Example: iw dev wlan0 mpath probe xx:xx:xx:xx:xx:xx frame 01:xx:xx:00\n");
+
 static int handle_mpath_get(struct nl80211_state *state,
                            struct nl_msg *msg,
                            int argc, char **argv,