]>
Commit | Line | Data |
---|---|---|
2ef1be68 | 1 | #include <net/if.h> |
3d1e8704 | 2 | #include <errno.h> |
d5ac8ad3 | 3 | #include <string.h> |
2ef1be68 | 4 | |
3d1e8704 LCC |
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> | |
3d1e8704 | 10 | |
f408e01b | 11 | #include "nl80211.h" |
3d1e8704 LCC |
12 | #include "iw.h" |
13 | ||
4698bfc2 JB |
14 | SECTION(mpath); |
15 | ||
3d1e8704 LCC |
16 | enum plink_state { |
17 | LISTEN, | |
18 | OPN_SNT, | |
19 | OPN_RCVD, | |
20 | CNF_RCVD, | |
21 | ESTAB, | |
22 | HOLDING, | |
23 | BLOCKED | |
24 | }; | |
25 | ||
26 | enum plink_actions { | |
27 | PLINK_ACTION_UNDEFINED, | |
28 | PLINK_ACTION_OPEN, | |
29 | PLINK_ACTION_BLOCK, | |
30 | }; | |
31 | ||
32 | ||
3d1e8704 LCC |
33 | static int print_mpath_handler(struct nl_msg *msg, void *arg) |
34 | { | |
35 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
36 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
37 | struct nlattr *pinfo[NL80211_MPATH_INFO_MAX + 1]; | |
38 | char dst[20], next_hop[20], dev[20]; | |
39 | static struct nla_policy mpath_policy[NL80211_MPATH_INFO_MAX + 1] = { | |
40 | [NL80211_MPATH_INFO_FRAME_QLEN] = { .type = NLA_U32 }, | |
456ce438 | 41 | [NL80211_MPATH_INFO_SN] = { .type = NLA_U32 }, |
3d1e8704 LCC |
42 | [NL80211_MPATH_INFO_METRIC] = { .type = NLA_U32 }, |
43 | [NL80211_MPATH_INFO_EXPTIME] = { .type = NLA_U32 }, | |
44 | [NL80211_MPATH_INFO_DISCOVERY_TIMEOUT] = { .type = NLA_U32 }, | |
45 | [NL80211_MPATH_INFO_DISCOVERY_RETRIES] = { .type = NLA_U8 }, | |
46 | [NL80211_MPATH_INFO_FLAGS] = { .type = NLA_U8 }, | |
47 | }; | |
48 | ||
49 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
50 | genlmsg_attrlen(gnlh, 0), NULL); | |
51 | ||
52 | /* | |
53 | * TODO: validate the interface and mac address! | |
54 | * Otherwise, there's a race condition as soon as | |
55 | * the kernel starts sending mpath notifications. | |
56 | */ | |
57 | ||
58 | if (!tb[NL80211_ATTR_MPATH_INFO]) { | |
5fe70c0e | 59 | fprintf(stderr, "mpath info missing!\n"); |
3d1e8704 LCC |
60 | return NL_SKIP; |
61 | } | |
62 | if (nla_parse_nested(pinfo, NL80211_MPATH_INFO_MAX, | |
63 | tb[NL80211_ATTR_MPATH_INFO], | |
64 | mpath_policy)) { | |
5fe70c0e | 65 | fprintf(stderr, "failed to parse nested attributes!\n"); |
3d1e8704 LCC |
66 | return NL_SKIP; |
67 | } | |
68 | ||
69 | mac_addr_n2a(dst, nla_data(tb[NL80211_ATTR_MAC])); | |
70 | mac_addr_n2a(next_hop, nla_data(tb[NL80211_ATTR_MPATH_NEXT_HOP])); | |
71 | if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev); | |
72 | printf("%s %s %s", dst, next_hop, dev); | |
456ce438 | 73 | if (pinfo[NL80211_MPATH_INFO_SN]) |
3d1e8704 | 74 | printf("\t%u", |
456ce438 | 75 | nla_get_u32(pinfo[NL80211_MPATH_INFO_SN])); |
3d1e8704 LCC |
76 | if (pinfo[NL80211_MPATH_INFO_METRIC]) |
77 | printf("\t%u", | |
78 | nla_get_u32(pinfo[NL80211_MPATH_INFO_METRIC])); | |
79 | if (pinfo[NL80211_MPATH_INFO_FRAME_QLEN]) | |
80 | printf("\t%u", | |
81 | nla_get_u32(pinfo[NL80211_MPATH_INFO_FRAME_QLEN])); | |
82 | if (pinfo[NL80211_MPATH_INFO_EXPTIME]) | |
83 | printf("\t%u", | |
84 | nla_get_u32(pinfo[NL80211_MPATH_INFO_EXPTIME])); | |
85 | if (pinfo[NL80211_MPATH_INFO_DISCOVERY_TIMEOUT]) | |
86 | printf("\t%u", | |
87 | nla_get_u32(pinfo[NL80211_MPATH_INFO_DISCOVERY_TIMEOUT])); | |
88 | if (pinfo[NL80211_MPATH_INFO_DISCOVERY_RETRIES]) | |
89 | printf("\t%u", | |
90 | nla_get_u8(pinfo[NL80211_MPATH_INFO_DISCOVERY_RETRIES])); | |
91 | if (pinfo[NL80211_MPATH_INFO_FLAGS]) | |
92 | printf("\t0x%x", | |
93 | nla_get_u8(pinfo[NL80211_MPATH_INFO_FLAGS])); | |
94 | ||
95 | printf("\n"); | |
96 | return NL_SKIP; | |
97 | } | |
98 | ||
7c37a24d JB |
99 | static int handle_mpath_get(struct nl80211_state *state, |
100 | struct nl_cb *cb, | |
f5f937fb JB |
101 | struct nl_msg *msg, |
102 | int argc, char **argv) | |
3d1e8704 | 103 | { |
3d1e8704 LCC |
104 | unsigned char dst[ETH_ALEN]; |
105 | ||
f5f937fb | 106 | if (argc < 1) |
5e75fd04 | 107 | return 1; |
3d1e8704 LCC |
108 | |
109 | if (mac_addr_a2n(dst, argv[0])) { | |
110 | fprintf(stderr, "invalid mac address\n"); | |
5e75fd04 | 111 | return 2; |
3d1e8704 LCC |
112 | } |
113 | argc--; | |
114 | argv++; | |
115 | ||
f5f937fb | 116 | if (argc) |
5e75fd04 | 117 | return 1; |
3d1e8704 LCC |
118 | |
119 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); | |
3d1e8704 | 120 | |
3d1e8704 | 121 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_mpath_handler, NULL); |
3d1e8704 | 122 | |
70391ccf | 123 | return 0; |
3d1e8704 | 124 | nla_put_failure: |
70391ccf | 125 | return -ENOBUFS; |
3d1e8704 | 126 | } |
f5f937fb | 127 | COMMAND(mpath, get, "<MAC address>", |
70cf4544 JB |
128 | NL80211_CMD_GET_MPATH, 0, CIB_NETDEV, handle_mpath_get, |
129 | "Get information on mesh path to the given node."); | |
f5f937fb | 130 | COMMAND(mpath, del, "<MAC address>", |
70cf4544 JB |
131 | NL80211_CMD_DEL_MPATH, 0, CIB_NETDEV, handle_mpath_get, |
132 | "Remove the mesh path to the given node."); | |
f5f937fb | 133 | |
7c37a24d JB |
134 | static int handle_mpath_set(struct nl80211_state *state, |
135 | struct nl_cb *cb, | |
f5f937fb JB |
136 | struct nl_msg *msg, |
137 | int argc, char **argv) | |
3d1e8704 | 138 | { |
3d1e8704 LCC |
139 | unsigned char dst[ETH_ALEN]; |
140 | unsigned char next_hop[ETH_ALEN]; | |
141 | ||
f5f937fb | 142 | if (argc < 3) |
5e75fd04 | 143 | return 1; |
3d1e8704 LCC |
144 | |
145 | if (mac_addr_a2n(dst, argv[0])) { | |
146 | fprintf(stderr, "invalid destination mac address\n"); | |
5e75fd04 | 147 | return 2; |
3d1e8704 LCC |
148 | } |
149 | argc--; | |
150 | argv++; | |
151 | ||
f5f937fb | 152 | if (strcmp("next_hop", argv[0]) != 0) |
5e75fd04 | 153 | return 1; |
3d1e8704 LCC |
154 | argc--; |
155 | argv++; | |
156 | ||
157 | if (mac_addr_a2n(next_hop, argv[0])) { | |
158 | fprintf(stderr, "invalid next hop mac address\n"); | |
5e75fd04 | 159 | return 2; |
3d1e8704 LCC |
160 | } |
161 | argc--; | |
162 | argv++; | |
163 | ||
f5f937fb | 164 | if (argc) |
5e75fd04 | 165 | return 1; |
3d1e8704 | 166 | |
3d1e8704 | 167 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
3d1e8704 LCC |
168 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
169 | ||
3d1e8704 | 170 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_mpath_handler, NULL); |
70391ccf | 171 | return 0; |
3d1e8704 | 172 | nla_put_failure: |
70391ccf | 173 | return -ENOBUFS; |
3d1e8704 | 174 | } |
f5f937fb | 175 | COMMAND(mpath, new, "<destination MAC address> next_hop <next hop MAC address>", |
70cf4544 JB |
176 | NL80211_CMD_NEW_MPATH, 0, CIB_NETDEV, handle_mpath_set, |
177 | "Create a new mesh path (instead of relying on automatic discovery)."); | |
f5f937fb | 178 | COMMAND(mpath, set, "<destination MAC address> next_hop <next hop MAC address>", |
70cf4544 JB |
179 | NL80211_CMD_SET_MPATH, 0, CIB_NETDEV, handle_mpath_set, |
180 | "Set an existing mesh path's next hop."); | |
3d1e8704 | 181 | |
7c37a24d JB |
182 | static int handle_mpath_dump(struct nl80211_state *state, |
183 | struct nl_cb *cb, | |
f5f937fb JB |
184 | struct nl_msg *msg, |
185 | int argc, char **argv) | |
3d1e8704 | 186 | { |
e1fa918a | 187 | printf("DEST ADDR NEXT HOP IFACE\tSN\tMETRIC\tQLEN\t" |
794c1e00 | 188 | "EXPTIME\t\tDTIM\tDRET\tFLAGS\n"); |
3d1e8704 | 189 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_mpath_handler, NULL); |
70391ccf | 190 | return 0; |
3d1e8704 | 191 | } |
f5f937fb | 192 | COMMAND(mpath, dump, NULL, |
70cf4544 JB |
193 | NL80211_CMD_GET_MPATH, NLM_F_DUMP, CIB_NETDEV, handle_mpath_dump, |
194 | "List known mesh paths."); |