]> granicus.if.org Git - libnl/commitdiff
route:tc: allow to set chain index for tc objects
authorVolodymyr Bendiuga <volodymyr.bendiuga@westermo.se>
Thu, 3 May 2018 06:51:35 +0000 (08:51 +0200)
committerThomas Haller <thaller@redhat.com>
Wed, 10 Oct 2018 09:00:21 +0000 (11:00 +0200)
This is useful when one wants to chain filters.

Signed-off-by: Volodymyr Bendiuga <volodymyr.bendiuga@westermo.se>
include/netlink-private/tc.h
include/netlink-private/types.h
include/netlink/route/tc.h
lib/route/tc.c
libnl-route-3.sym

index 939cd182f7e5447daf475c71c0f2775554142a14..b0f9c506adfbc22e5532cedd16f03f6c9bc7a8d1 100644 (file)
@@ -32,7 +32,8 @@ extern "C" {
 #define TCA_ATTR_MPU           0x0800
 #define TCA_ATTR_OVERHEAD      0x1000
 #define TCA_ATTR_LINKTYPE      0x2000
-#define TCA_ATTR_MAX           TCA_ATTR_LINKTYPE
+#define TCA_ATTR_CHAIN          0x4000
+#define TCA_ATTR_MAX            TCA_ATTR_CHAIN
 
 extern int tca_parse(struct nlattr **, int, struct rtnl_tc *,
                      const struct nla_policy *);
index 0c6e2eaa812274d3bdd46589bc9bd8982abb30d1..f94a927e946a0a91f1cf62e2720733c953ec421c 100644 (file)
@@ -541,7 +541,8 @@ struct rtnl_tstats
        struct nl_data *        pre ##_subdata;         \
        struct rtnl_link *      pre ##_link;            \
        struct rtnl_tc_ops *    pre ##_ops;             \
-       enum rtnl_tc_type       pre ##_type
+       enum rtnl_tc_type       pre ##_type;            \
+       uint32_t                pre ##_chain
 
 struct rtnl_tc
 {
index f1f0f8d16b770484c3569119d8cb63a46f7cc127..55b474d1d02087692dfdc011458f6f2499a1661b 100644 (file)
@@ -109,6 +109,8 @@ extern char *               rtnl_tc_handle2str(uint32_t, char *, size_t);
 extern int             rtnl_tc_str2handle(const char *, uint32_t *);
 extern int             rtnl_classid_generate(const char *, uint32_t *,
                                              uint32_t);
+extern void            rtnl_tc_set_chain(struct rtnl_tc *, uint32_t);
+extern uint32_t         rtnl_tc_get_chain(struct rtnl_tc *);
 
 #ifdef __cplusplus
 }
index 694c48e2945a7e239b529f965b4e820b4ab69d6e..4b185ed1189bfaecd25a29985d292c58b94b06f4 100644 (file)
@@ -32,6 +32,7 @@ static struct rtnl_tc_type_ops *tc_type_ops[__RTNL_TC_TYPE_MAX];
 static struct nla_policy tc_policy[TCA_MAX+1] = {
        [TCA_KIND]      = { .type = NLA_STRING,
                            .maxlen = TCKINDSIZ },
+       [TCA_CHAIN]     = { .type = NLA_U32 },
        [TCA_STATS]     = { .minlen = sizeof(struct tc_stats) },
        [TCA_STATS2]    = { .type = NLA_NESTED },
 };
@@ -79,6 +80,9 @@ int rtnl_tc_msg_parse(struct nlmsghdr *n, struct rtnl_tc *tc)
        nla_strlcpy(kind, tb[TCA_KIND], sizeof(kind));
        rtnl_tc_set_kind(tc, kind);
 
+       if (tb[TCA_CHAIN])
+               rtnl_tc_set_chain(tc, nla_get_u32(tb[TCA_CHAIN]));
+
        tm = nlmsg_data(n);
        tc->tc_family  = tm->tcm_family;
        tc->tc_ifindex = tm->tcm_ifindex;
@@ -216,6 +220,9 @@ int rtnl_tc_msg_build(struct rtnl_tc *tc, int type, int flags,
        if (tc->ce_mask & TCA_ATTR_KIND)
                NLA_PUT_STRING(msg, TCA_KIND, tc->tc_kind);
 
+       if (tc->ce_mask & TCA_ATTR_CHAIN)
+               NLA_PUT_U32(msg, TCA_CHAIN, tc->tc_chain);
+
        ops = rtnl_tc_get_ops(tc);
        if (ops && (ops->to_msg_fill || ops->to_msg_fill_raw)) {
                struct nlattr *opts;
@@ -560,6 +567,32 @@ uint64_t rtnl_tc_get_stat(struct rtnl_tc *tc, enum rtnl_tc_stat id)
        return tc->tc_stats[id];
 }
 
+/**
+ * Set the chain index of a traffic control object
+ * @arg tc             traffic control object
+ * @arg chain          chain index of traffic control object
+ *
+ */
+void rtnl_tc_set_chain(struct rtnl_tc *tc, uint32_t chain)
+{
+       tc->tc_chain = chain;
+       tc->ce_mask |= TCA_ATTR_CHAIN;
+}
+
+/**
+ * Return chain index of traffic control object
+ * @arg tc             traffic control object
+ *
+ * @return chain index of traffic control object or 0 if not set.
+ */
+uint32_t rtnl_tc_get_chain(struct rtnl_tc *tc)
+{
+       if (tc->ce_mask & TCA_ATTR_CHAIN)
+               return tc->tc_chain;
+       else
+               return 0;
+}
+
 /** @} */
 
 /**
index 6b02f3552dce655de7de59bce806deb5e1edff00..d161ebbf593b2063b83c66c36b6fa041decce977 100644 (file)
@@ -1125,4 +1125,6 @@ global:
        rtnl_rule_set_protocol;
        rtnl_rule_set_sport;
        rtnl_rule_set_sport_range;
+       rtnl_tc_get_chain;
+       rtnl_tc_set_chain;
 } libnl_3_4;