int nft_ctx_add_include_path(struct nft_ctx* '\*ctx'*, const char* '\*path'*);
void nft_ctx_clear_include_paths(struct nft_ctx* '\*ctx'*);
-int nft_run_cmd_from_buffer(struct nft_ctx* '\*nft'*,
- char* '\*buf'*, size_t* 'buflen'*);
+int nft_run_cmd_from_buffer(struct nft_ctx* '\*nft'*, const char* '\*buf'*);
int nft_run_cmd_from_filename(struct nft_ctx* '\*nft'*,
const char* '\*filename'*);*
=== nft_run_cmd_from_buffer() and nft_run_cmd_from_filename()
These functions perform the actual work of parsing user input into nftables commands and executing them.
-The *nft_run_cmd_from_buffer*() function passes the command(s) contained in 'buf' with size 'buflen' to the library, respecting settings and state in 'nft'.
+The *nft_run_cmd_from_buffer*() function passes the command(s) contained in 'buf' (which must be null-terminated) to the library, respecting settings and state in 'nft'.
The *nft_run_cmd_from_filename*() function passes the content of 'filename' to the library, respecting settings and state in 'nft'.
while (1) {
if (nft_ctx_buffer_output(nft) ||
- nft_run_cmd_from_buffer(nft, list_cmd, strlen(list_cmd))) {
+ nft_run_cmd_from_buffer(nft, list_cmd)) {
rc = 1;
break;
}
if (buf[0] == 'q' && buf[1] == '\0')
break;
- if (nft_run_cmd_from_buffer(nft, buf, strlen(buf))) {
+ if (nft_run_cmd_from_buffer(nft, buf)) {
rc = 1;
break;
}
int do_command_list_json(struct netlink_ctx *ctx, struct cmd *cmd);
-int nft_parse_json_buffer(struct nft_ctx *nft, char *buf, size_t buflen,
+int nft_parse_json_buffer(struct nft_ctx *nft, const char *buf,
struct list_head *msgs, struct list_head *cmds);
int nft_parse_json_filename(struct nft_ctx *nft, const char *filename,
struct list_head *msgs, struct list_head *cmds);
}
static inline int
-nft_parse_json_buffer(struct nft_ctx *nft, char *buf, size_t buflen,
+nft_parse_json_buffer(struct nft_ctx *nft, const char *buf,
struct list_head *msgs, struct list_head *cmds)
{
return -EINVAL;
}
+
static inline int
nft_parse_json_filename(struct nft_ctx *nft, const char *filename,
struct list_head *msgs, struct list_head *cmds)
int nft_ctx_add_include_path(struct nft_ctx *ctx, const char *path);
void nft_ctx_clear_include_paths(struct nft_ctx *ctx);
-int nft_run_cmd_from_buffer(struct nft_ctx *nft, char *buf, size_t buflen);
+int nft_run_cmd_from_buffer(struct nft_ctx *nft, const char *buf);
int nft_run_cmd_from_filename(struct nft_ctx *nft, const char *filename);
#endif /* LIB_NFTABLES_H */
self.nft_run_cmd_from_buffer = lib.nft_run_cmd_from_buffer
self.nft_run_cmd_from_buffer.restype = c_int
- self.nft_run_cmd_from_buffer.argtypes = [c_void_p, c_char_p, c_int]
+ self.nft_run_cmd_from_buffer.argtypes = [c_void_p, c_char_p]
self.nft_ctx_free = lib.nft_ctx_free
lib.nft_ctx_free.argtypes = [c_void_p]
output -- a string containing output written to stdout
error -- a string containing output written to stderr
"""
- rc = self.nft_run_cmd_from_buffer(self.__ctx, cmdline, len(cmdline))
+ rc = self.nft_run_cmd_from_buffer(self.__ctx, cmdline)
output = self.nft_ctx_get_output_buffer(self.__ctx)
error = self.nft_ctx_get_error_buffer(self.__ctx)
-Wno-redundant-decls
libnftables_la_LIBADD = ${LIBMNL_LIBS} ${LIBNFTNL_LIBS} libparser.la
+libnftables_la_LDFLAGS = -version-info 1:0:0
if BUILD_MINIGMP
noinst_LTLIBRARIES += libminigmp.la
if (hist == NULL || strcmp(hist->line, line))
add_history(line);
- nft_run_cmd_from_buffer(cli_nft, line, strlen(line) + 1);
+ nft_run_cmd_from_buffer(cli_nft, line);
xfree(line);
}
.name = "<cmdline>",
};
-static int nft_parse_bison_buffer(struct nft_ctx *nft, char *buf, size_t buflen,
+static int nft_parse_bison_buffer(struct nft_ctx *nft, const char *buf,
struct list_head *msgs, struct list_head *cmds)
{
struct cmd *cmd;
return 0;
}
-int nft_run_cmd_from_buffer(struct nft_ctx *nft, char *buf, size_t buflen)
+int nft_run_cmd_from_buffer(struct nft_ctx *nft, const char *buf)
{
struct cmd *cmd, *next;
LIST_HEAD(msgs);
LIST_HEAD(cmds);
- size_t nlbuflen;
char *nlbuf;
int rc = -EINVAL;
- nlbuflen = max(buflen + 1, strlen(buf) + 2);
- nlbuf = xzalloc(nlbuflen);
- snprintf(nlbuf, nlbuflen, "%s\n", buf);
+ nlbuf = xzalloc(strlen(buf) + 2);
+ sprintf(nlbuf, "%s\n", buf);
if (nft->output.json)
- rc = nft_parse_json_buffer(nft, nlbuf, nlbuflen, &msgs, &cmds);
+ rc = nft_parse_json_buffer(nft, nlbuf, &msgs, &cmds);
if (rc == -EINVAL)
- rc = nft_parse_bison_buffer(nft, nlbuf, nlbuflen, &msgs, &cmds);
+ rc = nft_parse_bison_buffer(nft, nlbuf, &msgs, &cmds);
if (rc)
goto err;
if (i + 1 < argc)
strcat(buf, " ");
}
- rc = !!nft_run_cmd_from_buffer(nft, buf, len);
+ rc = !!nft_run_cmd_from_buffer(nft, buf);
} else if (filename != NULL) {
rc = !!nft_run_cmd_from_filename(nft, filename);
} else if (interactive) {
}
-int nft_parse_json_buffer(struct nft_ctx *nft, char *buf, size_t buflen,
+int nft_parse_json_buffer(struct nft_ctx *nft, const char *buf,
struct list_head *msgs, struct list_head *cmds)
{
struct json_ctx ctx = {