]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
Add mpp get/dump commands
authorHenning Rogge <hrogge@gmail.com>
Fri, 12 Sep 2014 06:59:43 +0000 (08:59 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Thu, 9 Oct 2014 14:35:39 +0000 (16:35 +0200)
Add the "mpp get" and "mpp dump" command to query to mac80211s mesh
proxy path table through nl80211.

Signed-off-by: Henning Rogge <henning.rogge@fkie.fraunhofer.de>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Makefile
mpp.c [new file with mode: 0644]

index f042e307c189deac3af726ca220563ed9779ed1c..c05b2c4599e298de8a84b707e54d02f0b57f33f4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,7 @@ CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing
 
 OBJS = iw.o genl.o event.o info.o phy.o \
        interface.o ibss.o station.o survey.o util.o \
-       mesh.o mpath.o scan.o reg.o version.o \
+       mesh.o mpath.o mpp.o scan.o reg.o version.o \
        reason.o status.o connect.o link.o offch.o ps.o cqm.o \
        bitrate.o wowlan.o coalesce.o roc.o p2p.o
 OBJS += sections.o
diff --git a/mpp.c b/mpp.c
new file mode 100644 (file)
index 0000000..2d20d6b
--- /dev/null
+++ b/mpp.c
@@ -0,0 +1,84 @@
+#include <net/if.h>
+#include <errno.h>
+#include <string.h>
+
+#include <netlink/genl/genl.h>
+#include <netlink/genl/family.h>
+#include <netlink/genl/ctrl.h>
+#include <netlink/msg.h>
+#include <netlink/attr.h>
+
+#include "nl80211.h"
+#include "iw.h"
+
+SECTION(mpp);
+
+static int print_mpp_handler(struct nl_msg *msg, void *arg)
+{
+       struct nlattr *tb[NL80211_ATTR_MAX + 1];
+       struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
+       char dst[20], next_hop[20], dev[20];
+
+       nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
+                 genlmsg_attrlen(gnlh, 0), NULL);
+
+       /*
+        * TODO: validate the interface and mac address!
+        * Otherwise, there's a race condition as soon as
+        * the kernel starts sending mpath notifications.
+        */
+
+       mac_addr_n2a(dst, nla_data(tb[NL80211_ATTR_MAC]));
+       mac_addr_n2a(next_hop, nla_data(tb[NL80211_ATTR_MPATH_NEXT_HOP]));
+       if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev);
+       printf("%s %s %s\n", dst, next_hop, dev);
+
+       return NL_SKIP;
+}
+
+static int handle_mpp_get(struct nl80211_state *state,
+                         struct nl_cb *cb,
+                         struct nl_msg *msg,
+                         int argc, char **argv,
+                         enum id_input id)
+{
+       unsigned char dst[ETH_ALEN];
+
+       if (argc < 1)
+               return 1;
+
+       if (mac_addr_a2n(dst, argv[0])) {
+               fprintf(stderr, "invalid mac address\n");
+               return 2;
+       }
+       argc--;
+       argv++;
+
+       if (argc)
+               return 1;
+
+       NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst);
+
+       nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_mpp_handler, NULL);
+
+       return 0;
+ nla_put_failure:
+       return -ENOBUFS;
+}
+COMMAND(mpp, get, "<MAC address>",
+       NL80211_CMD_GET_MPP, 0, CIB_NETDEV, handle_mpp_get,
+       "Get information on mesh proxy path to the given node.");
+
+static int handle_mpp_dump(struct nl80211_state *state,
+                            struct nl_cb *cb,
+                            struct nl_msg *msg,
+                            int argc, char **argv,
+                            enum id_input id)
+{
+       printf("DEST ADDR         PROXY NODE        IFACE\n");
+       nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_mpp_handler, NULL);
+       return 0;
+}
+COMMAND(mpp, dump, NULL,
+       NL80211_CMD_GET_MPP, NLM_F_DUMP, CIB_NETDEV, handle_mpp_dump,
+       "List known mesh proxy paths.");