Esempio n. 1
0
static void devgroup_parse(struct xt_option_call *cb)
{
	struct xt_devgroup_info *info = cb->data;
	unsigned int id;
	char *end;

	xtables_option_parse(cb);
	switch (cb->entry->id) {
	case O_SRC_GROUP:
		info->src_group = strtoul(cb->arg, &end, 0);
		if (end != cb->arg && (*end == '/' || *end == '\0')) {
			if (*end == '/')
				info->src_mask = strtoul(end+1, &end, 0);
			else
				info->src_mask = 0xffffffff;
			if (*end != '\0' || end == cb->arg)
				xtables_error(PARAMETER_PROBLEM,
					      "Bad src-group value `%s'",
					      cb->arg);
		} else {
			id = xtables_lmap_name2id(devgroups, cb->arg);
			if (id == -1)
				xtables_error(PARAMETER_PROBLEM,
					      "Device group `%s' not found",
					      cb->arg);
			info->src_group = id;
			info->src_mask  = 0xffffffff;
		}
		info->flags |= XT_DEVGROUP_MATCH_SRC;
		if (cb->invert)
			info->flags |= XT_DEVGROUP_INVERT_SRC;
		break;
	case O_DST_GROUP:
		info->dst_group = strtoul(cb->arg, &end, 0);
		if (end != cb->arg && (*end == '/' || *end == '\0')) {
			if (*end == '/')
				info->dst_mask = strtoul(end+1, &end, 0);
			else
				info->dst_mask = 0xffffffff;
			if (*end != '\0' || end == cb->arg)
				xtables_error(PARAMETER_PROBLEM,
					      "Bad dst-group value `%s'",
					      cb->arg);
		} else {
			id = xtables_lmap_name2id(devgroups, cb->arg);
			if (id == -1)
				xtables_error(PARAMETER_PROBLEM,
					      "Device group `%s' not found",
					      cb->arg);
			info->dst_group = id;
			info->dst_mask  = 0xffffffff;
		}
		info->flags |= XT_DEVGROUP_MATCH_DST;
		if (cb->invert)
			info->flags |= XT_DEVGROUP_INVERT_DST;
		break;
	}
}
Esempio n. 2
0
static void realm_parse(struct xt_option_call *cb)
{
	struct xt_realm_info *realminfo = cb->data;
	int id;
	char *end;

	xtables_option_parse(cb);
	realminfo->id = strtoul(cb->arg, &end, 0);
	if (end != cb->arg && (*end == '/' || *end == '\0')) {
		if (*end == '/')
			realminfo->mask = strtoul(end+1, &end, 0);
		else
			realminfo->mask = 0xffffffff;
		if (*end != '\0' || end == cb->arg)
			xtables_error(PARAMETER_PROBLEM,
				   "Bad realm value \"%s\"", cb->arg);
	} else {
		id = xtables_lmap_name2id(realms, cb->arg);
		if (id == -1)
			xtables_error(PARAMETER_PROBLEM,
				   "Realm \"%s\" not found", cb->arg);
		realminfo->id = id;
		realminfo->mask = 0xffffffff;
	}
	if (cb->invert)
		realminfo->invert = 1;
}
Esempio n. 3
0
static void devgroup_parse_groupspec(const char *arg, unsigned int *group,
				     unsigned int *mask)
{
	char *end;
	bool ok;

	ok = xtables_strtoui(arg, &end, group, 0, UINT32_MAX);
	if (ok && (*end == '/' || *end == '\0')) {
		if (*end == '/')
			ok = xtables_strtoui(end + 1, NULL, mask,
			                     0, UINT32_MAX);
		else
			*mask = ~0U;
		if (!ok)
			xtables_error(PARAMETER_PROBLEM,
				      "Bad group value \"%s\"", arg);
	} else {
		*group = xtables_lmap_name2id(devgroups, arg);
		if (*group == -1)
			xtables_error(PARAMETER_PROBLEM,
				      "Device group \"%s\" not found", arg);
		*mask = ~0U;
	}
}