]>
Commit | Line | Data |
---|---|---|
4a73ea10 HR |
1 | #include <net/if.h> |
2 | #include <errno.h> | |
3 | #include <string.h> | |
4 | ||
5 | #include <netlink/genl/genl.h> | |
6 | #include <netlink/genl/family.h> | |
7 | #include <netlink/genl/ctrl.h> | |
8 | #include <netlink/msg.h> | |
9 | #include <netlink/attr.h> | |
10 | ||
11 | #include "nl80211.h" | |
12 | #include "iw.h" | |
13 | ||
14 | SECTION(mpp); | |
15 | ||
16 | static int print_mpp_handler(struct nl_msg *msg, void *arg) | |
17 | { | |
18 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
19 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
20 | char dst[20], next_hop[20], dev[20]; | |
21 | ||
22 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
23 | genlmsg_attrlen(gnlh, 0), NULL); | |
24 | ||
25 | /* | |
26 | * TODO: validate the interface and mac address! | |
27 | * Otherwise, there's a race condition as soon as | |
28 | * the kernel starts sending mpath notifications. | |
29 | */ | |
30 | ||
31 | mac_addr_n2a(dst, nla_data(tb[NL80211_ATTR_MAC])); | |
32 | mac_addr_n2a(next_hop, nla_data(tb[NL80211_ATTR_MPATH_NEXT_HOP])); | |
33 | if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev); | |
34 | printf("%s %s %s\n", dst, next_hop, dev); | |
35 | ||
36 | return NL_SKIP; | |
37 | } | |
38 | ||
39 | static int handle_mpp_get(struct nl80211_state *state, | |
4a73ea10 HR |
40 | struct nl_msg *msg, |
41 | int argc, char **argv, | |
42 | enum id_input id) | |
43 | { | |
44 | unsigned char dst[ETH_ALEN]; | |
45 | ||
46 | if (argc < 1) | |
47 | return 1; | |
48 | ||
49 | if (mac_addr_a2n(dst, argv[0])) { | |
50 | fprintf(stderr, "invalid mac address\n"); | |
51 | return 2; | |
52 | } | |
53 | argc--; | |
54 | argv++; | |
55 | ||
56 | if (argc) | |
57 | return 1; | |
58 | ||
59 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); | |
60 | ||
34b23014 | 61 | register_handler(print_mpp_handler, NULL); |
4a73ea10 HR |
62 | |
63 | return 0; | |
64 | nla_put_failure: | |
65 | return -ENOBUFS; | |
66 | } | |
67 | COMMAND(mpp, get, "<MAC address>", | |
68 | NL80211_CMD_GET_MPP, 0, CIB_NETDEV, handle_mpp_get, | |
69 | "Get information on mesh proxy path to the given node."); | |
70 | ||
71 | static int handle_mpp_dump(struct nl80211_state *state, | |
4a73ea10 HR |
72 | struct nl_msg *msg, |
73 | int argc, char **argv, | |
74 | enum id_input id) | |
75 | { | |
76 | printf("DEST ADDR PROXY NODE IFACE\n"); | |
34b23014 | 77 | register_handler(print_mpp_handler, NULL); |
4a73ea10 HR |
78 | return 0; |
79 | } | |
80 | COMMAND(mpp, dump, NULL, | |
81 | NL80211_CMD_GET_MPP, NLM_F_DUMP, CIB_NETDEV, handle_mpp_dump, | |
82 | "List known mesh proxy paths."); |