summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCong Wang <xiyou.wangcong@gmail.com>2013-12-13 23:24:50 (GMT)
committerThomas Haller <thaller@redhat.com>2013-12-17 16:14:10 (GMT)
commitd7aca17701519240bd69c0c6f7d55d0a09ce9346 (patch)
treef8efcb317947f6d9b8477e9f36e53a87526581b1
parentbc717a9bfcac70eead2d04e6978d136166294d34 (diff)
downloadlibnl-d7aca17701519240bd69c0c6f7d55d0a09ce9346.zip
libnl-d7aca17701519240bd69c0c6f7d55d0a09ce9346.tar.gz
libnl-d7aca17701519240bd69c0c6f7d55d0a09ce9346.tar.bz2
u32: add rtnl_u32_get_key()
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Cc: Thomas Graf <tgraf@suug.ch> Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r--include/netlink/route/cls/u32.h2
-rw-r--r--lib/route/cls/u32.c36
2 files changed, 38 insertions, 0 deletions
diff --git a/include/netlink/route/cls/u32.h b/include/netlink/route/cls/u32.h
index 34328d9..a74bfcd 100644
--- a/include/netlink/route/cls/u32.h
+++ b/include/netlink/route/cls/u32.h
@@ -32,6 +32,8 @@ extern int rtnl_u32_set_cls_terminal(struct rtnl_cls *);
extern int rtnl_u32_set_flags(struct rtnl_cls *, int);
extern int rtnl_u32_add_key(struct rtnl_cls *, uint32_t, uint32_t,
int, int);
+extern int rtnl_u32_get_key(struct rtnl_cls *, uint8_t, uint32_t *, uint32_t *,
+ int *, int *);
extern int rtnl_u32_add_key_uint8(struct rtnl_cls *, uint8_t, uint8_t,
int, int);
extern int rtnl_u32_add_key_uint16(struct rtnl_cls *, uint16_t, uint16_t,
diff --git a/lib/route/cls/u32.c b/lib/route/cls/u32.c
index e79ec9b..567fab9 100644
--- a/lib/route/cls/u32.c
+++ b/lib/route/cls/u32.c
@@ -570,6 +570,42 @@ int rtnl_u32_add_key(struct rtnl_cls *cls, uint32_t val, uint32_t mask,
return 0;
}
+/**
+ * Get the 32-bit key from the selector
+ *
+ * @arg cls classifier to be retrieve
+ * @arg index the index of the array of keys, start with 0
+ * @arg val pointer to store value after masked (network byte-order)
+ * @arg mask pointer to store the mask (network byte-order)
+ * @arg off pointer to store the offset
+ * @arg offmask pointer to store offset mask
+ *
+*/
+int rtnl_u32_get_key(struct rtnl_cls *cls, uint8_t index,
+ uint32_t *val, uint32_t *mask, int *off, int *offmask)
+{
+ struct tc_u32_sel *sel;
+ struct rtnl_u32 *u;
+
+ if (!(u = rtnl_tc_data(TC_CAST(cls))))
+ return -NLE_NOMEM;
+
+ if (!(u->cu_mask & U32_ATTR_SELECTOR))
+ return -NLE_INVAL;
+
+ /* the selector might have been moved by realloc */
+ sel = u32_selector(u);
+ if (index >= sel->nkeys)
+ return -NLE_RANGE;
+
+ *mask = sel->keys[index].mask;
+ *val = sel->keys[index].val;
+ *off = sel->keys[index].off;
+ *offmask = sel->keys[index].offmask;
+ return 0;
+}
+
+
int rtnl_u32_add_key_uint8(struct rtnl_cls *cls, uint8_t val, uint8_t mask,
int off, int offmask)
{