Skip to contentSkip to conversation

Allow to compile for < 3.17 kernel version

PATCH In review Vadim Kochan 2 participants 4 messages Sep 25, 2014 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Allow to compile for < 3.17 kernel version

Added declaration checking for NFT_EXPR_LOG_LEVEL enum which was added for 3.17 kernel version.

---
 configure.ac              | 2 ++
 src/netlink_delinearize.c | 2 ++
 src/netlink_linearize.c   | 2 ++
 3 files changed, 6 insertions(+)
configure.ac +2 -0
index 3a7647f..d3971c7 100644
@@ -99,6 +99,8 @@ AC_TYPE_UINT16_T
 AC_TYPE_UINT32_T
 AC_TYPE_UINT64_T
 
+AC_CHECK_DECLS([NFT_EXPR_LOG_LEVEL],[],[],[[#include <libnftnl/expr.h>]])
+
 # Checks for library functions.
 AC_CHECK_FUNCS([memmove memset strchr strdup strerror strtoull])
 
src/netlink_delinearize.c +2 -0
index 796b632..cf2ec00 100644
@@ -447,11 +447,13 @@ static void netlink_parse_log(struct netlink_parse_ctx *ctx,
 			nft_rule_expr_get_u16(nle, NFT_EXPR_LOG_QTHRESHOLD);
 		stmt->log.flags |= STMT_LOG_QTHRESHOLD;
 	}
+#if HAVE_DECL_NFT_EXPR_LOG_LEVEL
 	if (nft_rule_expr_is_set(nle, NFT_EXPR_LOG_LEVEL)) {
 		stmt->log.level =
 			nft_rule_expr_get_u32(nle, NFT_EXPR_LOG_LEVEL);
 		stmt->log.flags |= STMT_LOG_LEVEL;
 	}
+#endif
 	list_add_tail(&stmt->list, &ctx->rule->stmts);
 }
 
src/netlink_linearize.c +2 -0
index c46b6d4..2b116f9 100644
@@ -586,10 +586,12 @@ static void netlink_gen_log_stmt(struct netlink_linearize_ctx *ctx,
 			nft_rule_expr_set_u16(nle, NFT_EXPR_LOG_QTHRESHOLD,
 					      stmt->log.qthreshold);
 	} else {
+#if HAVE_DECL_NFT_EXPR_LOG_LEVEL
 		if (stmt->log.flags & STMT_LOG_LEVEL) {
 			nft_rule_expr_set_u32(nle, NFT_EXPR_LOG_LEVEL,
 					      stmt->log.level);
 		}
+#endif
 	}
 	nft_rule_add_expr(ctx->nlr, nle);
 }
Signature · 1 line
2.1.0
#1 lore raw
Quoted 31 lines · Vadim Kochan

Added declaration checking for NFT_EXPR_LOG_LEVEL enum which was added for 3.17 kernel version.

---
 configure.ac              | 2 ++
 src/netlink_delinearize.c | 2 ++
 src/netlink_linearize.c   | 2 ++
 3 files changed, 6 insertions(+)
configure.ac +2 -0
index 3a7647f..d3971c7 100644
@@ -99,6 +99,8 @@ AC_TYPE_UINT16_T
 AC_TYPE_UINT32_T
 AC_TYPE_UINT64_T
 
+AC_CHECK_DECLS([NFT_EXPR_LOG_LEVEL],[],[],[[#include <libnftnl/expr.h>]])
+
 # Checks for library functions.
 AC_CHECK_FUNCS([memmove memset strchr strdup strerror strtoull])
 
src/netlink_delinearize.c +0 -0
index 796b632..cf2ec00 100644
@@ -447,11 +447,13 @@ static void netlink_parse_log(struct netlink_parse_ctx *ctx,
 			nft_rule_expr_get_u16(nle, NFT_EXPR_LOG_QTHRESHOLD);
 		stmt->log.flags |= STMT_LOG_QTHRESHOLD;
 	}

src/netlink_delinearize.c static void netlink_parse_log(struct netlink_parse_ctx *ctx, · line 459

Quoted 10 lines
src/netlink_delinearize.c +2 -0
+#if HAVE_DECL_NFT_EXPR_LOG_LEVEL
 	if (nft_rule_expr_is_set(nle, NFT_EXPR_LOG_LEVEL)) {
 		stmt->log.level =
 			nft_rule_expr_get_u32(nle, NFT_EXPR_LOG_LEVEL);
 		stmt->log.flags |= STMT_LOG_LEVEL;
 	}
+#endif
 	list_add_tail(&stmt->list, &ctx->rule->stmts);
 }
 

I don't want to pollute the source code with many ifdef's, sorry. And if I apply this, more similar follow up patches will come in the future.

I'll make a patch to some recommended libnftnl version at configure stage using PKG_CHECK_MODULES.

#2 lore raw
Quoted 4 lines · Pablo Neira Ayuso
Quoted 3 lines · Vadim Kochan

Added declaration checking for NFT_EXPR_LOG_LEVEL enum which was added for 3.17 kernel version.

[...]

Quoted 23 lines
Quoted 8 lines
src/netlink_delinearize.c +0 -0
index 796b632..cf2ec00 100644
@@ -447,11 +447,13 @@ static void netlink_parse_log(struct netlink_parse_ctx *ctx,
 			nft_rule_expr_get_u16(nle, NFT_EXPR_LOG_QTHRESHOLD);
 		stmt->log.flags |= STMT_LOG_QTHRESHOLD;
 	}

src/netlink_delinearize.c static void netlink_parse_log(struct netlink_parse_ctx *ctx, · line 459

Quoted 10 lines
src/netlink_delinearize.c +2 -0
+#if HAVE_DECL_NFT_EXPR_LOG_LEVEL
 	if (nft_rule_expr_is_set(nle, NFT_EXPR_LOG_LEVEL)) {
 		stmt->log.level =
 			nft_rule_expr_get_u32(nle, NFT_EXPR_LOG_LEVEL);
 		stmt->log.flags |= STMT_LOG_LEVEL;
 	}
+#endif
 	list_add_tail(&stmt->list, &ctx->rule->stmts);
 }
 

I don't want to pollute the source code with many ifdef's, sorry. And if I apply this, more similar follow up patches will come in the future.

Quoted 2 lines

I'll make a patch to some recommended libnftnl version at configure stage using PKG_CHECK_MODULES.

BTW, regarding the patch title, you should be able to compile libnftnl and nftables with no matter kernel version since we're caching the header files.

So the subject is innacurate. The real problem is that you cannot compile new nftables with old library version since NFT_EXPR_LOG_LEVEL, which is a different thing.

#3 lore raw

Thanks for response, I agree.

Quoted 39 lines · Pablo Neira Ayuso
Quoted 4 lines · Pablo Neira Ayuso
Quoted 3 lines · Vadim Kochan

Added declaration checking for NFT_EXPR_LOG_LEVEL enum which was added for 3.17 kernel version.

[...]

Quoted 23 lines
Quoted 8 lines
src/netlink_delinearize.c +0 -0
index 796b632..cf2ec00 100644
@@ -447,11 +447,13 @@ static void netlink_parse_log(struct netlink_parse_ctx *ctx,
                    nft_rule_expr_get_u16(nle, NFT_EXPR_LOG_QTHRESHOLD);
            stmt->log.flags |= STMT_LOG_QTHRESHOLD;
    }

src/netlink_delinearize.c static void netlink_parse_log(struct netlink_parse_ctx *ctx, · line 459

Quoted 10 lines
src/netlink_delinearize.c +2 -0
+#if HAVE_DECL_NFT_EXPR_LOG_LEVEL
    if (nft_rule_expr_is_set(nle, NFT_EXPR_LOG_LEVEL)) {
            stmt->log.level =
                    nft_rule_expr_get_u32(nle, NFT_EXPR_LOG_LEVEL);
            stmt->log.flags |= STMT_LOG_LEVEL;
    }
+#endif
    list_add_tail(&stmt->list, &ctx->rule->stmts);
 }
 

I don't want to pollute the source code with many ifdef's, sorry. And if I apply this, more similar follow up patches will come in the future.

Quoted 2 lines

I'll make a patch to some recommended libnftnl version at configure stage using PKG_CHECK_MODULES.

BTW, regarding the patch title, you should be able to compile libnftnl and nftables with no matter kernel version since we're caching the header files.

So the subject is innacurate. The real problem is that you cannot compile new nftables with old library version since NFT_EXPR_LOG_LEVEL, which is a different thing.