From 83ee1e2c452b30b013059a7ba8008ba0388941f4 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czarnota Date: Mon, 7 Oct 2019 15:06:26 +0200 Subject: [13/17] act: add cookie parameter --- include/linux-private/linux/pkt_cls.h | 2 ++ include/netlink-private/types.h | 4 ++++ include/netlink/route/action.h | 1 + lib/route/act.c | 29 +++++++++++++++++++++++++++ libnl-route-3.sym | 1 + 5 files changed, 37 insertions(+) diff --git a/include/linux-private/linux/pkt_cls.h b/include/linux-private/linux/pkt_cls.h index 69408f2..1152e67 100644 --- a/include/linux-private/linux/pkt_cls.h +++ b/include/linux-private/linux/pkt_cls.h @@ -81,6 +81,8 @@ enum { TCA_ACT_OPTIONS, TCA_ACT_INDEX, TCA_ACT_STATS, + TCA_ACT_PAD, + TCA_ACT_COOKIE, __TCA_ACT_MAX }; diff --git a/include/netlink-private/types.h b/include/netlink-private/types.h index 3d784ff..a1d863c 100644 --- a/include/netlink-private/types.h +++ b/include/netlink-private/types.h @@ -561,9 +561,13 @@ struct rtnl_cls uint16_t c_protocol; }; +#define TC_COOKIE_MAX_SIZE 16 + struct rtnl_act { NL_TC_GENERIC(c); + unsigned char cookie[TC_COOKIE_MAX_SIZE]; + uint8_t is_cookie_set; struct rtnl_act * a_next; }; diff --git a/include/netlink/route/action.h b/include/netlink/route/action.h index 7d4c185..6696b70 100644 --- a/include/netlink/route/action.h +++ b/include/netlink/route/action.h @@ -41,6 +41,7 @@ extern int rtnl_act_remove(struct rtnl_act **, struct rtnl_act *); extern int rtnl_act_fill(struct nl_msg *, int, struct rtnl_act *); extern void rtnl_act_put_all(struct rtnl_act **); extern int rtnl_act_parse(struct rtnl_act **, struct nlattr *); +extern int rtnl_act_set_cookie(struct rtnl_act *, const unsigned char *, unsigned int); #ifdef __cplusplus } #endif diff --git a/lib/route/act.c b/lib/route/act.c index 836219d..8b0ac60 100644 --- a/lib/route/act.c +++ b/lib/route/act.c @@ -89,6 +89,9 @@ static int rtnl_act_fill_one(struct nl_msg *msg, struct rtnl_act *act, int order if (tc->ce_mask & TCA_ATTR_KIND) NLA_PUT_STRING(msg, TCA_ACT_KIND, tc->tc_kind); + if (act->is_cookie_set) + NLA_PUT(msg, TCA_ACT_COOKIE, sizeof(act->cookie), act->cookie); + ops = rtnl_tc_get_ops(tc); if (ops && (ops->to_msg_fill || ops->to_msg_fill_raw)) { struct nlattr *opts; @@ -392,6 +395,19 @@ void rtnl_act_put_all(struct rtnl_act **head) *head = NULL; } +int rtnl_act_set_cookie(struct rtnl_act *act, const unsigned char *cookie, + unsigned int size) +{ + if (size > TC_COOKIE_MAX_SIZE) + return -NLE_ATTRSIZE; + + act->is_cookie_set = 1; + + memcpy(act->cookie, cookie, size); + + return 0; +} + int rtnl_act_parse(struct rtnl_act **head, struct nlattr *tb) { struct rtnl_act *act; @@ -399,6 +415,8 @@ int rtnl_act_parse(struct rtnl_act **head, struct nlattr *tb) struct nlattr *tb2[TCA_ACT_MAX + 1]; struct nlattr *nla[TCA_ACT_MAX_PRIO + 1]; char kind[TCKINDSIZ]; + unsigned char cookie[TC_COOKIE_MAX_SIZE]; + unsigned int cklen; int err, i; err = nla_parse(nla, TCA_ACT_MAX_PRIO, nla_data(tb), @@ -440,6 +458,17 @@ int rtnl_act_parse(struct rtnl_act **head, struct nlattr *tb) tc->ce_mask |= TCA_ATTR_OPTS; } + if (tb2[TCA_ACT_COOKIE]) { + cklen = nla_len(tb2[TCA_ACT_COOKIE]); + nla_memcpy(cookie, tb2[TCA_ACT_COOKIE], sizeof(cookie)); + + err = rtnl_act_set_cookie(act, cookie, cklen); + if (err) + goto err_free; + + act->is_cookie_set = 1; + } + ops = rtnl_tc_get_ops(tc); if (ops && ops->to_msg_parser) { void *data = rtnl_tc_data(tc); diff --git a/libnl-route-3.sym b/libnl-route-3.sym index 01f1dc6..321bea7 100644 --- a/libnl-route-3.sym +++ b/libnl-route-3.sym @@ -83,6 +83,7 @@ global: rtnl_act_put; rtnl_act_put_all; rtnl_act_remove; + rtnl_act_set_cookie; rtnl_addr_add; rtnl_addr_alloc; rtnl_addr_alloc_cache; -- 2.17.1