*-f*::
*--file 'filename'*::
Read input from 'filename'. If 'filename' is -, read from stdin.
+ The directory path to this file is inserted at the beginning the list of
+ directories to be searched for included files (see *-I/--includepath*).
*-D*::
*--define 'name=value'*::
#include <cmd.h>
#include <errno.h>
#include <sys/stat.h>
+#include <libgen.h>
static int nft_netlink(struct nft_ctx *nft,
struct list_head *cmds, struct list_head *msgs)
return __nft_run_cmd_from_filename(nft, filename);
}
+static int nft_ctx_add_basedir_include_path(struct nft_ctx *nft,
+ const char *filename)
+{
+ const char *basedir = dirname(xstrdup(filename));
+ int ret;
+
+ ret = nft_ctx_add_include_path(nft, basedir);
+
+ free_const(basedir);
+
+ return ret;
+}
+
EXPORT_SYMBOL(nft_run_cmd_from_filename);
int nft_run_cmd_from_filename(struct nft_ctx *nft, const char *filename)
{
!nft_output_json(&nft->output))
nft->stdin_buf = stdin_to_buffer();
+ if (!nft->stdin_buf &&
+ nft_ctx_add_basedir_include_path(nft, filename) < 0)
+ return -1;
+
if (nft->optimize_flags) {
ret = nft_run_optimized_file(nft, filename);
free_const(nft->stdin_buf);