Beispiel #1
0
static int cmd_node_set_addr(struct nlmsghdr *nlh, const struct cmd *cmd,
                             struct cmdl *cmdl, void *data)
{
    char *str;
    uint32_t addr;
    struct nlattr *nest;
    char buf[MNL_SOCKET_BUFFER_SIZE];

    if (cmdl->argc != cmdl->optind + 1) {
        fprintf(stderr, "Usage: %s node set address ADDRESS\n",
                cmdl->argv[0]);
        return -EINVAL;
    }

    str = shift_cmdl(cmdl);
    addr = str2addr(str);
    if (!addr)
        return -1;

    if (!(nlh = msg_init(buf, TIPC_NL_NET_SET))) {
        fprintf(stderr, "error, message initialisation failed\n");
        return -1;
    }

    nest = mnl_attr_nest_start(nlh, TIPC_NLA_NET);
    mnl_attr_put_u32(nlh, TIPC_NLA_NET_ADDR, addr);
    mnl_attr_nest_end(nlh, nest);

    return msg_doit(nlh, NULL, NULL);
}
Beispiel #2
0
static int cmd_link_mon_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd,
				 struct cmdl *cmdl, void *data)
{
	int size;
	char buf[MNL_SOCKET_BUFFER_SIZE];
	struct nlattr *attrs;

	if (cmdl->argc != cmdl->optind + 1) {
		fprintf(stderr, "error, missing value\n");
		return -EINVAL;
	}
	size = atoi(shift_cmdl(cmdl));

	nlh = msg_init(buf, TIPC_NL_MON_SET);
	if (!nlh) {
		fprintf(stderr, "error, message initialisation failed\n");
		return -1;
	}
	attrs = mnl_attr_nest_start(nlh, TIPC_NLA_MON);

	mnl_attr_put_u32(nlh, TIPC_NLA_MON_ACTIVATION_THRESHOLD, size);

	mnl_attr_nest_end(nlh, attrs);

	return msg_doit(nlh, NULL, NULL);
}
Beispiel #3
0
static int cmd_node_set_netid(struct nlmsghdr *nlh, const struct cmd *cmd,
                              struct cmdl *cmdl, void *data)
{
    int netid;
    char buf[MNL_SOCKET_BUFFER_SIZE];
    struct nlattr *nest;

    if (help_flag) {
        (cmd->help)(cmdl);
        return -EINVAL;
    }

    if (!(nlh = msg_init(buf, TIPC_NL_NET_SET))) {
        fprintf(stderr, "error, message initialisation failed\n");
        return -1;
    }

    if (cmdl->argc != cmdl->optind + 1) {
        fprintf(stderr, "Usage: %s node set netid NETID\n",
                cmdl->argv[0]);
        return -EINVAL;
    }
    netid = atoi(shift_cmdl(cmdl));

    nest = mnl_attr_nest_start(nlh, TIPC_NLA_NET);
    mnl_attr_put_u32(nlh, TIPC_NLA_NET_ID, netid);
    mnl_attr_nest_end(nlh, nest);

    return msg_doit(nlh, NULL, NULL);
}
Beispiel #4
0
static int cmd_link_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd,
			     struct cmdl *cmdl, void *data)
{
	int val;
	int prop;
	char buf[MNL_SOCKET_BUFFER_SIZE];
	struct nlattr *props;
	struct nlattr *attrs;
	struct opt *opt;
	struct opt opts[] = {
		{ "link",		OPT_KEYVAL,	NULL },
		{ NULL }
	};

	if (strcmp(cmd->cmd, PRIORITY_STR) == 0)
		prop = TIPC_NLA_PROP_PRIO;
	else if ((strcmp(cmd->cmd, TOLERANCE_STR) == 0))
		prop = TIPC_NLA_PROP_TOL;
	else if ((strcmp(cmd->cmd, WINDOW_STR) == 0))
		prop = TIPC_NLA_PROP_WIN;
	else
		return -EINVAL;

	if (help_flag) {
		(cmd->help)(cmdl);
		return -EINVAL;
	}

	if (cmdl->optind >= cmdl->argc) {
		fprintf(stderr, "error, missing value\n");
		return -EINVAL;
	}
	val = atoi(shift_cmdl(cmdl));

	if (parse_opts(opts, cmdl) < 0)
		return -EINVAL;

	nlh = msg_init(buf, TIPC_NL_LINK_SET);
	if (!nlh) {
		fprintf(stderr, "error, message initialisation failed\n");
		return -1;
	}
	attrs = mnl_attr_nest_start(nlh, TIPC_NLA_LINK);

	opt = get_opt(opts, "link");
	if (!opt) {
		fprintf(stderr, "error, missing link\n");
		return -EINVAL;
	}
	mnl_attr_put_strz(nlh, TIPC_NLA_LINK_NAME, opt->val);

	props = mnl_attr_nest_start(nlh, TIPC_NLA_LINK_PROP);
	mnl_attr_put_u32(nlh, prop, val);
	mnl_attr_nest_end(nlh, props);

	mnl_attr_nest_end(nlh, attrs);

	return msg_doit(nlh, link_get_cb, &prop);
}