From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: Sven Eckelmann <sven@narfation.org>, Antonio Quartulli <a@unstable.cc>
Subject: [B.A.T.M.A.N.] [RFC v4 09/20] batctl: Support generic netlink for isolation_mark command
Date: Fri, 7 Dec 2018 21:31:58 +0100 [thread overview]
Message-ID: <20181207203209.22633-10-sven@narfation.org> (raw)
In-Reply-To: <20181207203209.22633-1-sven@narfation.org>
sysfs should be avoided for new settings of network interfaces. To still
provide a common configuration infrastructure, all the existing settings
subcommands also have to be reimplemented via generic netlink while still
using sysfs as fallback.
The isolation_mark implementation is using the commands
BATADV_CMD_SET_MESH/BATADV_CMD_GET_MESH to set/get the configuration of
the mark/mask using the u32 attributes BATADV_ATTR_ISOLATION_MARK
and BATADV_ATTR_ISOLATION_MASK.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
Cc: Antonio Quartulli <a@unstable.cc>
---
isolation_mark.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 121 insertions(+), 2 deletions(-)
diff --git a/isolation_mark.c b/isolation_mark.c
index 13ba869..461053f 100644
--- a/isolation_mark.c
+++ b/isolation_mark.c
@@ -20,16 +20,135 @@
* License-Filename: LICENSES/preferred/GPL-2.0
*/
+#include <errno.h>
#include <stddef.h>
+#include <stdint.h>
+#include <string.h>
#include "main.h"
#include "sys.h"
+static struct isolation_mark_data {
+ uint32_t isolation_mark;
+ uint32_t isolation_mask;
+} isolation_mark;
+
+static int parse_isolation_mark(struct state *state, int argc, char *argv[])
+{
+ struct settings_data *settings = state->cmd->arg;
+ struct isolation_mark_data *data = settings->data;
+ char *mask_ptr;
+ char buff[256];
+ uint32_t mark;
+ uint32_t mask;
+ char *endptr;
+
+ if (argc != 2) {
+ fprintf(stderr, "Error - incorrect number of arguments (expected 1)\n");
+ return -EINVAL;
+ }
+
+ strncpy(buff, argv[1], sizeof(buff));
+ buff[sizeof(buff) - 1] = '\0';
+
+ /* parse the mask if it has been specified, otherwise assume the mask is
+ * the biggest possible
+ */
+ mask = 0xFFFFFFFF;
+ mask_ptr = strchr(buff, '/');
+ if (mask_ptr) {
+ *mask_ptr = '\0';
+ mask_ptr++;
+
+ /* the mask must be entered in hex base as it is going to be a
+ * bitmask and not a prefix length
+ */
+ mask = strtoul(mask_ptr, &endptr, 16);
+ if (!endptr || *endptr != '\0')
+ goto inval_format;
+ }
+
+ /* the mark can be entered in any base */
+ mark = strtoul(buff, &endptr, 0);
+ if (!endptr || *endptr != '\0')
+ goto inval_format;
+
+ data->isolation_mask = mask;
+ /* erase bits not covered by the mask */
+ data->isolation_mark = mark & mask;
+
+ return 0;
+
+inval_format:
+ fprintf(stderr, "Error - incorrect number of arguments (expected 1)\n");
+ fprintf(stderr, "The following formats for mark(/mask) are allowed:\n");
+ fprintf(stderr, " * 0x12345678\n");
+ fprintf(stderr, " * 0x12345678/0xabcdef09\n");
+ return -EINVAL;
+}
+
+static int print_isolation_mark(struct nl_msg *msg, void *arg)
+{
+ struct nlattr *attrs[BATADV_ATTR_MAX + 1];
+ struct nlmsghdr *nlh = nlmsg_hdr(msg);
+ struct genlmsghdr *ghdr;
+ int *result = arg;
+
+ if (!genlmsg_valid_hdr(nlh, 0))
+ return NL_OK;
+
+ ghdr = nlmsg_data(nlh);
+
+ if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0),
+ genlmsg_len(ghdr), batadv_netlink_policy)) {
+ return NL_OK;
+ }
+
+ if (!attrs[BATADV_ATTR_ISOLATION_MARK] ||
+ !attrs[BATADV_ATTR_ISOLATION_MASK])
+ return NL_OK;
+
+ printf("0x%08x/0x%08x\n",
+ nla_get_u32(attrs[BATADV_ATTR_ISOLATION_MARK]),
+ nla_get_u32(attrs[BATADV_ATTR_ISOLATION_MASK]));
+
+ *result = 0;
+ return NL_STOP;
+}
+
+static int get_isolation_mark(struct state *state)
+{
+ return sys_simple_nlquery(state, BATADV_CMD_GET_MESH,
+ NULL, print_isolation_mark);
+}
+
+static int set_attrs_isolation_mark(struct nl_msg *msg, void *arg)
+{
+ struct state *state = arg;
+ struct settings_data *settings = state->cmd->arg;
+ struct isolation_mark_data *data = settings->data;
+
+ nla_put_u32(msg, BATADV_ATTR_ISOLATION_MARK, data->isolation_mark);
+ nla_put_u32(msg, BATADV_ATTR_ISOLATION_MASK, data->isolation_mask);
+
+ return 0;
+}
+
+static int set_isolation_mark(struct state *state)
+{
+ return sys_simple_nlquery(state, BATADV_CMD_SET_MESH,
+ set_attrs_isolation_mark, NULL);
+}
+
static struct settings_data batctl_settings_isolation_mark = {
.sysfs_name = "isolation_mark",
- .params = NULL,
+ .data = &isolation_mark,
+ .parse = parse_isolation_mark,
+ .netlink_get = get_isolation_mark,
+ .netlink_set = set_isolation_mark,
};
COMMAND_NAMED(SUBCOMMAND, isolation_mark, "mark", handle_sys_setting,
- COMMAND_FLAG_MESH_IFACE, &batctl_settings_isolation_mark,
+ COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK,
+ &batctl_settings_isolation_mark,
"[mark] \tdisplay or modify isolation_mark setting");
--
2.19.2
next prev parent reply other threads:[~2018-12-07 20:31 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-07 20:31 [B.A.T.M.A.N.] [RFC v4 00/20] batctl: netlink restructuring, part 3 Sven Eckelmann
2018-12-07 20:31 ` [B.A.T.M.A.N.] [RFC v4 01/20] batctl: Add support for config mcast group in event monitor Sven Eckelmann
2018-12-07 20:31 ` [B.A.T.M.A.N.] [RFC v4 02/20] batctl: Don't allocate new buffer for vlan parent device Sven Eckelmann
2018-12-07 20:31 ` [B.A.T.M.A.N.] [RFC v4 03/20] batctl: Automatically translate vlan to mesh_iface Sven Eckelmann
2018-12-07 20:31 ` [B.A.T.M.A.N.] [RFC v4 04/20] batctl: Add settings_data hooks for netlink integration Sven Eckelmann
2018-12-07 20:31 ` [B.A.T.M.A.N.] [RFC v4 05/20] batctl: Parse the arguments for gw_mode Sven Eckelmann
2018-12-07 20:31 ` [B.A.T.M.A.N.] [RFC v4 06/20] batctl: Add netlink simple query helper Sven Eckelmann
2018-12-07 20:31 ` [B.A.T.M.A.N.] [RFC v4 07/20] batctl: Support generic netlink for gw_mode command Sven Eckelmann
2018-12-07 20:31 ` [B.A.T.M.A.N.] [RFC v4 08/20] batctl: Support generic netlink for loglevel command Sven Eckelmann
2019-01-07 16:57 ` Linus Lüssing
2018-12-07 20:31 ` Sven Eckelmann [this message]
2018-12-07 20:31 ` [B.A.T.M.A.N.] [RFC v4 10/20] batctl: Support generic netlink for orig_interval command Sven Eckelmann
2018-12-07 20:32 ` [B.A.T.M.A.N.] [RFC v4 11/20] batctl: Add helper to read/write boolean configuration values Sven Eckelmann
2018-12-07 20:32 ` [B.A.T.M.A.N.] [RFC v4 12/20] batctl: Support generic netlink for aggregation command Sven Eckelmann
2018-12-07 20:32 ` [B.A.T.M.A.N.] [RFC v4 13/20] batctl: Support generic netlink for ap_isolation command Sven Eckelmann
2018-12-07 20:32 ` [B.A.T.M.A.N.] [RFC v4 14/20] batctl: Support generic netlink for bonding command Sven Eckelmann
2018-12-07 20:32 ` [B.A.T.M.A.N.] [RFC v4 15/20] batctl: Support generic netlink for bridge_loop_avoidance command Sven Eckelmann
2018-12-07 20:32 ` [B.A.T.M.A.N.] [RFC v4 16/20] batctl: Support generic netlink for distributed_arp_table command Sven Eckelmann
2018-12-07 20:32 ` [B.A.T.M.A.N.] [RFC v4 17/20] batctl: Support generic netlink for fragmentation command Sven Eckelmann
2018-12-07 20:32 ` [B.A.T.M.A.N.] [RFC v4 18/20] batctl: Support generic netlink for multicast_mode command Sven Eckelmann
2018-12-07 20:32 ` [B.A.T.M.A.N.] [RFC v4 19/20] batctl: Support generic netlink for network_coding command Sven Eckelmann
2018-12-07 20:32 ` [B.A.T.M.A.N.] [RFC v4 20/20] batctl: Drop settings_date param lists Sven Eckelmann
2019-01-07 18:57 ` [B.A.T.M.A.N.] [RFC v4 00/20] batctl: netlink restructuring, part 3 Linus Lüssing
2019-01-08 7:37 ` Sven Eckelmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181207203209.22633-10-sven@narfation.org \
--to=sven@narfation.org \
--cc=a@unstable.cc \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).