From 844541f4c43c2469b9955b78480cbe36fde653d0 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Fri, 10 Jun 2016 14:13:00 +0200 Subject: src: assert when setting unknown attributes If this attribute is not supported by the library, we should rise an assertion so the client knows something is wrong, instead of silently going through. The only case I can think may hit this problem is version mismatch between library and tools. This should not ever really happen, so better bail out from the library itself in this case. Signed-off-by: Pablo Neira Ayuso --- include/utils.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'include') diff --git a/include/utils.h b/include/utils.h index 46ff18a..21694b6 100644 --- a/include/utils.h +++ b/include/utils.h @@ -43,6 +43,15 @@ void __nftnl_assert_fail(uint16_t attr, const char *filename, int line); nftnl_assert(data, attr, _validate_array[_attr] == _data_len); \ }) +void __nftnl_assert_attr_exists(uint16_t attr, uint16_t attr_max, + const char *filename, int line); + +#define nftnl_assert_attr_exists(_attr, _attr_max) \ +({ \ + if (_attr > _attr_max) \ + __nftnl_assert_attr_exists(_attr, _attr_max, __FILE__, __LINE__); \ +}) + #define SNPRINTF_BUFFER_SIZE(ret, size, len, offset) \ if (ret < 0) \ return ret; \ -- cgit v1.2.3