Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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>
  • Loading branch information...
commit d7aca17701519240bd69c0c6f7d55d0a09ce9346 1 parent bc717a9
@congwang congwang authored committed
Showing with 38 additions and 0 deletions.
  1. +2 −0  include/netlink/route/cls/u32.h
  2. +36 −0 lib/route/cls/u32.c
View
2  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,
View
36 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)
{
Please sign in to comment.
Something went wrong with that request. Please try again.