2014-09-12 06:59:51

by Henning Rogge

[permalink] [raw]
Subject: [PATCH v2] Add mpp get/dump commands

Add the "mpp get" and "mpp dump" command to query to mac80211s mesh
proxy path table through nl80211.

Signed-off-by: Henning Rogge <[email protected]>
---
Makefile | 2 +-
mpp.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
nl80211.h | 11 +++++++++
3 files changed, 96 insertions(+), 1 deletion(-)
create mode 100644 mpp.c

diff --git a/Makefile b/Makefile
index f042e30..c05b2c4 100644
--- 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
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.");
diff --git a/nl80211.h b/nl80211.h
index be9519b..80cff48 100644
--- a/nl80211.h
+++ b/nl80211.h
@@ -722,6 +722,10 @@
* QoS mapping is relevant for IP packets, it is only valid during an
* association. This is cleared on disassociation and AP restart.
*
+ * @NL80211_CMD_GET_MPP: Get mesh path attributes for mesh proxy path to
+ * destination %NL80211_ATTR_MAC on the interface identified by
+ * %NL80211_ATTR_IFINDEX.
+ *
* @NL80211_CMD_MAX: highest used command number
* @__NL80211_CMD_AFTER_LAST: internal use
*/
@@ -893,6 +897,8 @@ enum nl80211_commands {

NL80211_CMD_SET_QOS_MAP,

+ NL80211_CMD_GET_MPP,
+
/* add new commands above here */

/* used to define NL80211_CMD_MAX below */
@@ -1591,6 +1597,9 @@ enum nl80211_commands {
* creation then the new interface will be owned by the netlink socket
* that created it and will be destroyed when the socket is closed
*
+ * @NL80211_ATTR_TDLS_INITIATOR: flag attribute indicating the current end is
+ * the TDLS link initiator.
+ *
* @NL80211_ATTR_MAX: highest attribute number currently defined
* @__NL80211_ATTR_AFTER_LAST: internal use
*/
@@ -1931,6 +1940,8 @@ enum nl80211_attrs {
NL80211_ATTR_CSA_C_OFFSETS_TX,
NL80211_ATTR_MAX_CSA_COUNTERS,

+ NL80211_ATTR_TDLS_INITIATOR,
+
/* add attributes here, update the policy in nl80211.c */

__NL80211_ATTR_AFTER_LAST,
--
1.9.1



2014-10-09 15:36:03

by Henning Rogge

[permalink] [raw]
Subject: Re: [PATCH v2] Add mpp get/dump commands

On Thu, Oct 9, 2014 at 4:36 PM, Johannes Berg <[email protected]> wrote:
> On Fri, 2014-09-12 at 08:59 +0200, Henning Rogge wrote:
>> Add the "mpp get" and "mpp dump" command to query to mac80211s mesh
>> proxy path table through nl80211.
>
> Applied.
>
>> nl80211.h | 11 +++++++++
>
> Please don't send me nl80211.h updates though.

Had to change it to make the source compile... so next time change it,
but not add it to the commit?

Henning Rogge

2014-10-09 15:39:57

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH v2] Add mpp get/dump commands

On Thu, 2014-10-09 at 17:35 +0200, Henning Rogge wrote:

> Had to change it to make the source compile... so next time change it,
> but not add it to the commit?

Yeah, see over on the thread with Lorenzo as well, where I explained
this. I just copy nl80211.h from the kernel tree to make sure no
mismatches happen.

johannes


2014-10-09 14:36:22

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH v2] Add mpp get/dump commands

On Fri, 2014-09-12 at 08:59 +0200, Henning Rogge wrote:
> Add the "mpp get" and "mpp dump" command to query to mac80211s mesh
> proxy path table through nl80211.

Applied.

> nl80211.h | 11 +++++++++

Please don't send me nl80211.h updates though.

johannes