Ejemplo n.º 1
0
static int fw_clone(struct rtnl_cls *_dst, struct rtnl_cls *_src)
{
	struct rtnl_fw *dst = rtnl_cls_data(_dst);
	struct rtnl_fw *src = rtnl_cls_data(_src);

	if (src->cf_act && !(dst->cf_act = nl_data_clone(src->cf_act)))
		return -NLE_NOMEM;
	
	if (src->cf_police && !(dst->cf_police = nl_data_clone(src->cf_police)))
		return -NLE_NOMEM;

	return 0;
}
Ejemplo n.º 2
0
static int cgroup_msg_parser(struct rtnl_cls *cls)
{
	struct rtnl_cgroup *c = rtnl_cls_data(cls);
	struct nlattr *tb[TCA_CGROUP_MAX + 1];
	int err;

	err = tca_parse(tb, TCA_CGROUP_MAX, (struct rtnl_tc *) cls,
			cgroup_policy);
	if (err < 0)
		return err;

	if (tb[TCA_CGROUP_EMATCHES]) {
		if ((err = rtnl_ematch_parse_attr(tb[TCA_CGROUP_EMATCHES],
						  &c->cg_ematch)) < 0)
			return err;
		c->cg_mask |= CGROUP_ATTR_EMATCH;
	}

#if 0
	TODO:
	TCA_CGROUP_ACT,
	TCA_CGROUP_POLICE,
#endif

	return 0;
}
Ejemplo n.º 3
0
static void fw_free_data(struct rtnl_cls *cls)
{
	struct rtnl_fw *f = rtnl_cls_data(cls);

	nl_data_free(f->cf_act);
	nl_data_free(f->cf_police);
}
Ejemplo n.º 4
0
static int u32_get_opts(struct rtnl_cls *cls, struct nl_msg *msg)
{
	struct rtnl_u32 *u = rtnl_cls_data(cls);
	
	if (u->cu_mask & U32_ATTR_DIVISOR)
		NLA_PUT_U32(msg, TCA_U32_DIVISOR, u->cu_divisor);

	if (u->cu_mask & U32_ATTR_HASH)
		NLA_PUT_U32(msg, TCA_U32_HASH, u->cu_hash);

	if (u->cu_mask & U32_ATTR_CLASSID)
		NLA_PUT_U32(msg, TCA_U32_CLASSID, u->cu_classid);

	if (u->cu_mask & U32_ATTR_LINK)
		NLA_PUT_U32(msg, TCA_U32_LINK, u->cu_link);

	if (u->cu_mask & U32_ATTR_SELECTOR)
		NLA_PUT_DATA(msg, TCA_U32_SEL, u->cu_selector);

	if (u->cu_mask & U32_ATTR_ACTION)
		NLA_PUT_DATA(msg, TCA_U32_ACT, u->cu_act);

	if (u->cu_mask & U32_ATTR_POLICE)
		NLA_PUT_DATA(msg, TCA_U32_POLICE, u->cu_police);

	if (u->cu_mask & U32_ATTR_INDEV)
		NLA_PUT_STRING(msg, TCA_U32_INDEV, u->cu_indev);

	return 0;

nla_put_failure:
	return -NLE_NOMEM;
}
Ejemplo n.º 5
0
/**
 * Append new 32-bit key to the selector
 *
 * @arg cls	classifier to be modifier
 * @arg val	value to be matched (network byte-order)
 * @arg mask	mask to be applied before matching (network byte-order)
 * @arg off	offset, in bytes, to start matching
 * @arg offmask	offset mask
 *
 * General selectors define the pattern, mask and offset the pattern will be
 * matched to the packet contents. Using the general selectors you can match
 * virtually any single bit in the IP (or upper layer) header.
 *
*/
int rtnl_u32_add_key(struct rtnl_cls *cls, uint32_t val, uint32_t mask,
		     int off, int offmask)
{
	struct tc_u32_sel *sel;
	struct rtnl_u32 *u = rtnl_cls_data(cls);
	int err;

	sel = u32_selector_alloc(u);
	if (!sel)
		return -NLE_NOMEM;

	err = nl_data_append(u->cu_selector, NULL, sizeof(struct tc_u32_key));
	if (err < 0)
		return err;

	/* the selector might have been moved by realloc */
	sel = u32_selector(u);

	sel->keys[sel->nkeys].mask = mask;
	sel->keys[sel->nkeys].val = val & mask;
	sel->keys[sel->nkeys].off = off;
	sel->keys[sel->nkeys].offmask = offmask;
	sel->nkeys++;
	u->cu_mask |= U32_ATTR_SELECTOR;

	return 0;
}
Ejemplo n.º 6
0
static void u32_dump_details(struct rtnl_cls *cls, struct nl_dump_params *p)
{
	struct rtnl_u32 *u = rtnl_cls_data(cls);
	struct tc_u32_sel *s;

	if (!(u->cu_mask & U32_ATTR_SELECTOR)) {
		nl_dump(p, "no-selector\n");
		return;
	}
	
	s = u->cu_selector->d_data;

	nl_dump(p, "nkeys %u ", s->nkeys);

	if (u->cu_mask & U32_ATTR_HASH)
		nl_dump(p, "ht key 0x%x hash 0x%u",
			TC_U32_USERHTID(u->cu_hash), TC_U32_HASH(u->cu_hash));

	if (u->cu_mask & U32_ATTR_LINK)
		nl_dump(p, "link %u ", u->cu_link);

	if (u->cu_mask & U32_ATTR_INDEV)
		nl_dump(p, "indev %s ", u->cu_indev);

	print_selector(p, s, cls, u);
	nl_dump(p, "\n");

#if 0	
#define U32_ATTR_ACTION       0x040
#define U32_ATTR_POLICE       0x080

	struct nl_data   act;
	struct nl_data   police;
#endif
}
Ejemplo n.º 7
0
static void fw_dump_details(struct rtnl_cls *cls, struct nl_dump_params *p)
{
	struct rtnl_fw *f = rtnl_cls_data(cls);

	if (f->cf_mask & FW_ATTR_INDEV)
		nl_dump(p, "indev %s ", f->cf_indev);
}
Ejemplo n.º 8
0
static void cgroup_dump_line(struct rtnl_cls *cls, struct nl_dump_params *p)
{
	struct rtnl_cgroup *c = rtnl_cls_data(cls);

	if (c->cg_mask & CGROUP_ATTR_EMATCH)
		nl_dump(p, " ematch");
	else
		nl_dump(p, " match-all");
}
Ejemplo n.º 9
0
int rtnl_fw_set_classid(struct rtnl_cls *cls, uint32_t classid)
{
	struct rtnl_fw *f = rtnl_cls_data(cls);
	
	f->cf_classid = classid;
	f->cf_mask |= FW_ATTR_CLASSID;

	return 0;
}
Ejemplo n.º 10
0
static void fw_dump_line(struct rtnl_cls *cls, struct nl_dump_params *p)
{
	struct rtnl_fw *f = rtnl_cls_data(cls);
	char buf[32];

	if (f->cf_mask & FW_ATTR_CLASSID)
		nl_dump(p, " target %s",
			rtnl_tc_handle2str(f->cf_classid, buf, sizeof(buf)));
}
Ejemplo n.º 11
0
int rtnl_u32_set_classid(struct rtnl_cls *cls, uint32_t classid)
{
	struct rtnl_u32 *u = rtnl_cls_data(cls);
	
	u->cu_classid = classid;
	u->cu_mask |= U32_ATTR_CLASSID;

	return 0;
}
Ejemplo n.º 12
0
static void u32_free_data(struct rtnl_cls *cls)
{
	struct rtnl_u32 *u = rtnl_cls_data(cls);

	nl_data_free(u->cu_selector);
	nl_data_free(u->cu_act);
	nl_data_free(u->cu_police);
	nl_data_free(u->cu_pcnt);
}
Ejemplo n.º 13
0
static void cgroup_dump_details(struct rtnl_cls *cls, struct nl_dump_params *p)
{
	struct rtnl_cgroup *c = rtnl_cls_data(cls);

	if (c->cg_mask & CGROUP_ATTR_EMATCH) {
		nl_dump_line(p, "    ematch ");
		rtnl_ematch_tree_dump(c->cg_ematch, p);
	} else
		nl_dump(p, "no options.\n");
}
Ejemplo n.º 14
0
static int u32_clone(struct rtnl_cls *_dst, struct rtnl_cls *_src)
{
	struct rtnl_u32 *dst = rtnl_cls_data(_dst);
	struct rtnl_u32 *src = rtnl_cls_data(_src);

	if (src->cu_selector &&
	    !(dst->cu_selector = nl_data_clone(src->cu_selector)))
		return -NLE_NOMEM;

	if (src->cu_act && !(dst->cu_act = nl_data_clone(src->cu_act)))
		return -NLE_NOMEM;

	if (src->cu_police && !(dst->cu_police = nl_data_clone(src->cu_police)))
		return -NLE_NOMEM;

	if (src->cu_pcnt && !(dst->cu_pcnt = nl_data_clone(src->cu_pcnt)))
		return -NLE_NOMEM;

	return 0;
}
Ejemplo n.º 15
0
static void u32_dump_stats(struct rtnl_cls *cls, struct nl_dump_params *p)
{
	struct rtnl_u32 *u = rtnl_cls_data(cls);

	if (u->cu_mask & U32_ATTR_PCNT) {
		struct tc_u32_pcnt *pc = u->cu_pcnt->d_data;
		nl_dump(p, "\n");
		nl_dump_line(p, "    hit %8llu count %8llu\n",
			     pc->rhit, pc->rcnt);
	}
}
Ejemplo n.º 16
0
static void u32_dump_line(struct rtnl_cls *cls, struct nl_dump_params *p)
{
	struct rtnl_u32 *u = rtnl_cls_data(cls);
	char buf[32];

	if (u->cu_mask & U32_ATTR_DIVISOR)
		nl_dump(p, " divisor %u", u->cu_divisor);
	else if (u->cu_mask & U32_ATTR_CLASSID)
		nl_dump(p, " target %s",
			rtnl_tc_handle2str(u->cu_classid, buf, sizeof(buf)));
}
Ejemplo n.º 17
0
int rtnl_cls_set_kind(struct rtnl_cls *cls, const char *kind)
{
	if (cls->ce_mask & TCA_ATTR_KIND)
		return -NLE_EXIST;

	tca_set_kind((struct rtnl_tca *) cls, kind);

	/* Force allocation of data */
	rtnl_cls_data(cls);

	return 0;
}
Ejemplo n.º 18
0
static int cgroup_get_opts(struct rtnl_cls *cls, struct nl_msg *msg)
{
	struct rtnl_cgroup *c = rtnl_cls_data(cls);

	if (!(cls->ce_mask & TCA_ATTR_HANDLE))
		return -NLE_MISSING_ATTR;

	if (c->cg_mask & CGROUP_ATTR_EMATCH)
		return rtnl_ematch_fill_attr(msg, TCA_CGROUP_EMATCHES,
					     c->cg_ematch);

	return 0;
}
Ejemplo n.º 19
0
int rtnl_u32_set_flags(struct rtnl_cls *cls, int flags)
{
	struct tc_u32_sel *sel;
	struct rtnl_u32 *u = rtnl_cls_data(cls);

	sel = u32_selector_alloc(u);
	if (!sel)
		return -NLE_NOMEM;

	sel->flags |= flags;
	u->cu_mask |= U32_ATTR_SELECTOR;

	return 0;
}
Ejemplo n.º 20
0
void rtnl_cgroup_set_ematch(struct rtnl_cls *cls, struct rtnl_ematch_tree *tree)
{
	struct rtnl_cgroup *c = rtnl_cls_data(cls);

	if (c->cg_ematch) {
		rtnl_ematch_tree_free(c->cg_ematch);
		c->cg_mask &= ~CGROUP_ATTR_EMATCH;
	}

	c->cg_ematch = tree;

	if (tree)
		c->cg_mask |= CGROUP_ATTR_EMATCH;
}
Ejemplo n.º 21
0
static int fw_get_opts(struct rtnl_cls *cls, struct nl_msg *msg)
{
	struct rtnl_fw *f = rtnl_cls_data(cls);
	
	if (f->cf_mask & FW_ATTR_CLASSID)
		NLA_PUT_U32(msg, TCA_FW_CLASSID, f->cf_classid);

	if (f->cf_mask & FW_ATTR_ACTION)
		NLA_PUT_DATA(msg, TCA_FW_ACT, f->cf_act);

	if (f->cf_mask & FW_ATTR_POLICE)
		NLA_PUT_DATA(msg, TCA_FW_POLICE, f->cf_police);

	if (f->cf_mask & FW_ATTR_INDEV)
		NLA_PUT_STRING(msg, TCA_FW_INDEV, f->cf_indev);

	return 0;

nla_put_failure:
	return -NLE_NOMEM;
}
Ejemplo n.º 22
0
static int fw_msg_parser(struct rtnl_cls *cls)
{
	struct rtnl_fw *f = rtnl_cls_data(cls);
	struct nlattr *tb[TCA_FW_MAX + 1];
	int err;

	err = tca_parse(tb, TCA_FW_MAX, (struct rtnl_tca *) cls, fw_policy);
	if (err < 0)
		return err;

	if (tb[TCA_FW_CLASSID]) {
		f->cf_classid = nla_get_u32(tb[TCA_FW_CLASSID]);
		f->cf_mask |= FW_ATTR_CLASSID;
	}

	if (tb[TCA_FW_ACT]) {
		f->cf_act = nl_data_alloc_attr(tb[TCA_FW_ACT]);
		if (!f->cf_act)
			return -NLE_NOMEM;
		f->cf_mask |= FW_ATTR_ACTION;
	}

	if (tb[TCA_FW_POLICE]) {
		f->cf_police = nl_data_alloc_attr(tb[TCA_FW_POLICE]);
		if (!f->cf_police)
			return -NLE_NOMEM;
		f->cf_mask |= FW_ATTR_POLICE;
	}

	if (tb[TCA_FW_INDEV]) {
		nla_strlcpy(f->cf_indev, tb[TCA_FW_INDEV], IFNAMSIZ);
		f->cf_mask |= FW_ATTR_INDEV;
	}

	return 0;
}
Ejemplo n.º 23
0
static void cgroup_free_data(struct rtnl_cls *cls)
{
	struct rtnl_cgroup *c = rtnl_cls_data(cls);

	rtnl_ematch_tree_free(c->cg_ematch);
}
Ejemplo n.º 24
0
static int u32_msg_parser(struct rtnl_cls *cls)
{
	struct rtnl_u32 *u = rtnl_cls_data(cls);
	struct nlattr *tb[TCA_U32_MAX + 1];
	int err;

	err = tca_parse(tb, TCA_U32_MAX, (struct rtnl_tca *) cls, u32_policy);
	if (err < 0)
		return err;

	if (tb[TCA_U32_DIVISOR]) {
		u->cu_divisor = nla_get_u32(tb[TCA_U32_DIVISOR]);
		u->cu_mask |= U32_ATTR_DIVISOR;
	}

	if (tb[TCA_U32_SEL]) {
		u->cu_selector = nl_data_alloc_attr(tb[TCA_U32_SEL]);
		if (!u->cu_selector)
			goto errout_nomem;
		u->cu_mask |= U32_ATTR_SELECTOR;
	}

	if (tb[TCA_U32_HASH]) {
		u->cu_hash = nla_get_u32(tb[TCA_U32_HASH]);
		u->cu_mask |= U32_ATTR_HASH;
	}

	if (tb[TCA_U32_CLASSID]) {
		u->cu_classid = nla_get_u32(tb[TCA_U32_CLASSID]);
		u->cu_mask |= U32_ATTR_CLASSID;
	}

	if (tb[TCA_U32_LINK]) {
		u->cu_link = nla_get_u32(tb[TCA_U32_LINK]);
		u->cu_mask |= U32_ATTR_LINK;
	}

	if (tb[TCA_U32_ACT]) {
		u->cu_act = nl_data_alloc_attr(tb[TCA_U32_ACT]);
		if (!u->cu_act)
			goto errout_nomem;
		u->cu_mask |= U32_ATTR_ACTION;
	}

	if (tb[TCA_U32_POLICE]) {
		u->cu_police = nl_data_alloc_attr(tb[TCA_U32_POLICE]);
		if (!u->cu_police)
			goto errout_nomem;
		u->cu_mask |= U32_ATTR_POLICE;
	}

	if (tb[TCA_U32_PCNT]) {
		struct tc_u32_sel *sel;
		int pcnt_size;

		if (!tb[TCA_U32_SEL]) {
			err = -NLE_MISSING_ATTR;
			goto errout;
		}
		
		sel = u->cu_selector->d_data;
		pcnt_size = sizeof(struct tc_u32_pcnt) +
				(sel->nkeys * sizeof(uint64_t));
		if (nla_len(tb[TCA_U32_PCNT]) < pcnt_size) {
			err = -NLE_INVAL;
			goto errout;
		}

		u->cu_pcnt = nl_data_alloc_attr(tb[TCA_U32_PCNT]);
		if (!u->cu_pcnt)
			goto errout_nomem;
		u->cu_mask |= U32_ATTR_PCNT;
	}

	if (tb[TCA_U32_INDEV]) {
		nla_strlcpy(u->cu_indev, tb[TCA_U32_INDEV], IFNAMSIZ);
		u->cu_mask |= U32_ATTR_INDEV;
	}

	return 0;

errout_nomem:
	err = -NLE_NOMEM;
errout:
	return err;
}
Ejemplo n.º 25
0
struct rtnl_ematch_tree *rtnl_cgroup_get_ematch(struct rtnl_cls *cls)
{
	return ((struct rtnl_cgroup *) rtnl_cls_data(cls))->cg_ematch;
}