]> git.ipfire.org Git - thirdparty/libnl.git/commitdiff
Add rtnl_tc_data_check()
authorThomas Graf <tgraf@suug.ch>
Thu, 9 Jun 2011 10:28:04 +0000 (12:28 +0200)
committerThomas Graf <tgraf@suug.ch>
Thu, 9 Jun 2011 10:28:04 +0000 (12:28 +0200)
Behaves like rtnl_tc_data() but verifies that the traffic control
object is of the expected type.

include/netlink/route/tc-api.h
lib/route/tc.c

index 8ed940aee056af497a3be403bfe1fcdac42064b1..d89408f843adbf40428e280f1bc7eb042b4e530a 100644 (file)
@@ -124,6 +124,8 @@ extern int                  rtnl_tc_compare(struct nl_object *,
                                                uint32_t, int);
 
 extern void *                  rtnl_tc_data(struct rtnl_tc *);
+extern void *                  rtnl_tc_data_check(struct rtnl_tc *,
+                                                  struct rtnl_tc_ops *);
 
 extern struct rtnl_tc_ops *    rtnl_tc_lookup_ops(enum rtnl_tc_type,
                                                   const char *);
index da8c75f8a8a8f7473afec9a96f48f977cbcded31..983555a8eb09283ea2cdac6483fdd6dabcb1ee31 100644 (file)
@@ -1010,6 +1010,21 @@ void *rtnl_tc_data(struct rtnl_tc *tc)
        return nl_data_get(tc->tc_subdata);
 }
 
+void *rtnl_tc_data_check(struct rtnl_tc *tc, struct rtnl_tc_ops *ops)
+{
+       if (tc->tc_ops != ops) {
+               char buf[64];
+
+               snprintf(buf, sizeof(buf),
+                        "tc object %p used in %s context but is of type %s",
+                        tc, ops->to_kind, tc->tc_ops->to_kind);
+
+               return NULL;
+       }
+
+       return rtnl_tc_data(tc);
+}
+
 void rtnl_tc_type_register(struct rtnl_tc_type_ops *ops)
 {
        if (ops->tt_type > RTNL_TC_TYPE_MAX)