ctx->vars = NULL;
}
-EXPORT_SYMBOL(nft_ctx_add_include_path);
-int nft_ctx_add_include_path(struct nft_ctx *ctx, const char *path)
+static bool nft_ctx_find_include_path(struct nft_ctx *ctx, const char *path)
+{
+ unsigned int i;
+
+ for (i = 0; i < ctx->num_include_paths; i++) {
+ if (!strcmp(ctx->include_paths[i], path))
+ return true;
+ }
+
+ return false;
+}
+
+static int __nft_ctx_add_include_path(struct nft_ctx *ctx, const char *path)
{
char **tmp;
int pcount = ctx->num_include_paths;
return 0;
}
+EXPORT_SYMBOL(nft_ctx_add_include_path);
+int nft_ctx_add_include_path(struct nft_ctx *ctx, const char *path)
+{
+ char canonical_path[PATH_MAX];
+
+ if (!realpath(path, canonical_path))
+ return -1;
+
+ if (nft_ctx_find_include_path(ctx, canonical_path))
+ return 0;
+
+ return __nft_ctx_add_include_path(ctx, canonical_path);
+}
+
EXPORT_SYMBOL(nft_ctx_clear_include_paths);
void nft_ctx_clear_include_paths(struct nft_ctx *ctx)
{
case OPT_INCLUDEPATH:
if (nft_ctx_add_include_path(nft, optarg)) {
fprintf(stderr,
- "Failed to add include path '%s'\n",
+ "Warning: Cannot include path '%s'\n",
optarg);
- goto out_fail;
}
break;
case OPT_NUMERIC:
--- /dev/null
+#!/bin/bash
+
+set -e
+
+trap "rm -rf $tmpdir" EXIT
+
+tmpdir=$(mktemp -d)
+mkdir -p $tmpdir/test/include
+cat > $tmpdir/test/main << EOF
+table inet test {
+ chain test {
+ include "include/*";
+ }
+}
+EOF
+echo "tcp dport 22 accept;" > $tmpdir/test/include/one
+echo "tcp dport 25 accept;" > $tmpdir/test/include/two
+
+$NFT -I $tmpdir/test/ -f $tmpdir/test/main