summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2016-04-26 14:16:58 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2016-05-09 22:57:10 +0200
commit600890067c40e1846398db373b9c38b6fe9a16a6 (patch)
treea2419ba0f0a817937bce9ca0f048ec43d24e5b42 /include
parent813da08a8bd9d320d6a6a52b3cacc87b8d0ed1f9 (diff)
libnftnl: constify object arguments to various functions
flow table support needs constant object arguments to printing functions to avoid ugly casts. While at it, also constify object arguments to message construction, destructor and a few helper functions. Signed-off-by: Patrick McHardy <kaber@trash.net> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'include')
-rw-r--r--include/data_reg.h8
-rw-r--r--include/expr_ops.h6
-rw-r--r--include/libnftnl/chain.h8
-rw-r--r--include/libnftnl/expr.h4
-rw-r--r--include/libnftnl/gen.h14
-rw-r--r--include/libnftnl/rule.h10
-rw-r--r--include/libnftnl/ruleset.h2
-rw-r--r--include/libnftnl/set.h24
-rw-r--r--include/libnftnl/table.h22
-rw-r--r--include/libnftnl/trace.h2
-rw-r--r--include/libnftnl/udata.h2
-rw-r--r--include/utils.h8
12 files changed, 57 insertions, 53 deletions
diff --git a/include/data_reg.h b/include/data_reg.h
index 0f2ae9a..e749b5b 100644
--- a/include/data_reg.h
+++ b/include/data_reg.h
@@ -23,11 +23,13 @@ union nftnl_data_reg {
};
};
-int nftnl_data_reg_snprintf(char *buf, size_t size, union nftnl_data_reg *reg,
- uint32_t output_format, uint32_t flags, int reg_type);
+int nftnl_data_reg_snprintf(char *buf, size_t size,
+ const union nftnl_data_reg *reg,
+ uint32_t output_format, uint32_t flags,
+ int reg_type);
struct nlattr;
int nftnl_parse_data(union nftnl_data_reg *data, struct nlattr *attr, int *type);
-void nftnl_free_verdict(union nftnl_data_reg *data);
+void nftnl_free_verdict(const union nftnl_data_reg *data);
#endif
diff --git a/include/expr_ops.h b/include/expr_ops.h
index cecad95..3c0cb18 100644
--- a/include/expr_ops.h
+++ b/include/expr_ops.h
@@ -12,12 +12,12 @@ struct expr_ops {
const char *name;
uint32_t alloc_len;
int max_attr;
- void (*free)(struct nftnl_expr *e);
+ void (*free)(const struct nftnl_expr *e);
int (*set)(struct nftnl_expr *e, uint16_t type, const void *data, uint32_t data_len);
const void *(*get)(const struct nftnl_expr *e, uint16_t type, uint32_t *data_len);
int (*parse)(struct nftnl_expr *e, struct nlattr *attr);
- void (*build)(struct nlmsghdr *nlh, struct nftnl_expr *e);
- int (*snprintf)(char *buf, size_t len, uint32_t type, uint32_t flags, struct nftnl_expr *e);
+ void (*build)(struct nlmsghdr *nlh, const struct nftnl_expr *e);
+ int (*snprintf)(char *buf, size_t len, uint32_t type, uint32_t flags, const struct nftnl_expr *e);
int (*xml_parse)(struct nftnl_expr *e, mxml_node_t *tree,
struct nftnl_parse_err *err);
int (*json_parse)(struct nftnl_expr *e, json_t *data,
diff --git a/include/libnftnl/chain.h b/include/libnftnl/chain.h
index 9ac8830..4c0d071 100644
--- a/include/libnftnl/chain.h
+++ b/include/libnftnl/chain.h
@@ -15,7 +15,7 @@ extern "C" {
struct nftnl_chain;
struct nftnl_chain *nftnl_chain_alloc(void);
-void nftnl_chain_free(struct nftnl_chain *);
+void nftnl_chain_free(const struct nftnl_chain *);
enum nftnl_chain_attr {
NFTNL_CHAIN_NAME = 0,
@@ -62,8 +62,8 @@ int nftnl_chain_parse(struct nftnl_chain *c, enum nftnl_parse_type type,
const char *data, struct nftnl_parse_err *err);
int nftnl_chain_parse_file(struct nftnl_chain *c, enum nftnl_parse_type type,
FILE *fp, struct nftnl_parse_err *err);
-int nftnl_chain_snprintf(char *buf, size_t size, struct nftnl_chain *t, uint32_t type, uint32_t flags);
-int nftnl_chain_fprintf(FILE *fp, struct nftnl_chain *c, uint32_t type, uint32_t flags);
+int nftnl_chain_snprintf(char *buf, size_t size, const struct nftnl_chain *t, uint32_t type, uint32_t flags);
+int nftnl_chain_fprintf(FILE *fp, const struct nftnl_chain *c, uint32_t type, uint32_t flags);
#define nftnl_chain_nlmsg_build_hdr nftnl_nlmsg_build_hdr
int nftnl_chain_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_chain *t);
@@ -72,7 +72,7 @@ struct nftnl_chain_list;
struct nftnl_chain_list *nftnl_chain_list_alloc(void);
void nftnl_chain_list_free(struct nftnl_chain_list *list);
-int nftnl_chain_list_is_empty(struct nftnl_chain_list *list);
+int nftnl_chain_list_is_empty(const struct nftnl_chain_list *list);
int nftnl_chain_list_foreach(struct nftnl_chain_list *chain_list, int (*cb)(struct nftnl_chain *t, void *data), void *data);
void nftnl_chain_list_add(struct nftnl_chain *r, struct nftnl_chain_list *list);
diff --git a/include/libnftnl/expr.h b/include/libnftnl/expr.h
index da6a251..f192103 100644
--- a/include/libnftnl/expr.h
+++ b/include/libnftnl/expr.h
@@ -17,7 +17,7 @@ enum {
};
struct nftnl_expr *nftnl_expr_alloc(const char *name);
-void nftnl_expr_free(struct nftnl_expr *expr);
+void nftnl_expr_free(const struct nftnl_expr *expr);
bool nftnl_expr_is_set(const struct nftnl_expr *expr, uint16_t type);
void nftnl_expr_set(struct nftnl_expr *expr, uint16_t type, const void *data, uint32_t data_len);
@@ -36,7 +36,7 @@ uint32_t nftnl_expr_get_u32(const struct nftnl_expr *expr, uint16_t type);
uint64_t nftnl_expr_get_u64(const struct nftnl_expr *expr, uint16_t type);
const char *nftnl_expr_get_str(const struct nftnl_expr *expr, uint16_t type);
-int nftnl_expr_snprintf(char *buf, size_t buflen, struct nftnl_expr *expr, uint32_t type, uint32_t flags);
+int nftnl_expr_snprintf(char *buf, size_t buflen, const struct nftnl_expr *expr, uint32_t type, uint32_t flags);
enum {
NFTNL_EXPR_PAYLOAD_DREG = NFTNL_EXPR_BASE,
diff --git a/include/libnftnl/gen.h b/include/libnftnl/gen.h
index 3eb8470..d0f638f 100644
--- a/include/libnftnl/gen.h
+++ b/include/libnftnl/gen.h
@@ -15,7 +15,7 @@ extern "C" {
struct nftnl_gen;
struct nftnl_gen *nftnl_gen_alloc(void);
-void nftnl_gen_free(struct nftnl_gen *);
+void nftnl_gen_free(const struct nftnl_gen *);
enum {
NFTNL_GEN_ID = 0,
@@ -28,18 +28,18 @@ void nftnl_gen_unset(struct nftnl_gen *gen, uint16_t attr);
void nftnl_gen_set(struct nftnl_gen *gen, uint16_t attr, const void *data);
void nftnl_gen_set_data(struct nftnl_gen *gen, uint16_t attr,
const void *data, uint32_t data_len);
-const void *nftnl_gen_get(struct nftnl_gen *gen, uint16_t attr);
-const void *nftnl_gen_get_data(struct nftnl_gen *gen, uint16_t attr,
- uint32_t *data_len);
+const void *nftnl_gen_get(const struct nftnl_gen *gen, uint16_t attr);
+const void *nftnl_gen_get_data(const struct nftnl_gen *gen, uint16_t attr,
+ uint32_t *data_len);
void nftnl_gen_set_u32(struct nftnl_gen *gen, uint16_t attr, uint32_t data);
-uint32_t nftnl_gen_get_u32(struct nftnl_gen *gen, uint16_t attr);
+uint32_t nftnl_gen_get_u32(const struct nftnl_gen *gen, uint16_t attr);
struct nlmsghdr;
int nftnl_gen_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_gen *gen);
-int nftnl_gen_snprintf(char *buf, size_t size, struct nftnl_gen *gen, uint32_t type, uint32_t flags);
-int nftnl_gen_fprintf(FILE *fp, struct nftnl_gen *gen, uint32_t type, uint32_t flags);
+int nftnl_gen_snprintf(char *buf, size_t size, const struct nftnl_gen *gen, uint32_t type, uint32_t flags);
+int nftnl_gen_fprintf(FILE *fp, const struct nftnl_gen *gen, uint32_t type, uint32_t flags);
#define nftnl_gen_nlmsg_build_hdr nftnl_nlmsg_build_hdr
int nftnl_gen_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_gen *gen);
diff --git a/include/libnftnl/rule.h b/include/libnftnl/rule.h
index d5b50ad..6f9d8c1 100644
--- a/include/libnftnl/rule.h
+++ b/include/libnftnl/rule.h
@@ -16,7 +16,7 @@ struct nftnl_rule;
struct nftnl_expr;
struct nftnl_rule *nftnl_rule_alloc(void);
-void nftnl_rule_free(struct nftnl_rule *);
+void nftnl_rule_free(const struct nftnl_rule *);
enum nftnl_rule_attr {
NFTNL_RULE_FAMILY = 0,
@@ -58,8 +58,8 @@ int nftnl_rule_parse(struct nftnl_rule *r, enum nftnl_parse_type type,
const char *data, struct nftnl_parse_err *err);
int nftnl_rule_parse_file(struct nftnl_rule *r, enum nftnl_parse_type type,
FILE *fp, struct nftnl_parse_err *err);
-int nftnl_rule_snprintf(char *buf, size_t size, struct nftnl_rule *t, uint32_t type, uint32_t flags);
-int nftnl_rule_fprintf(FILE *fp, struct nftnl_rule *r, uint32_t type, uint32_t flags);
+int nftnl_rule_snprintf(char *buf, size_t size, const struct nftnl_rule *t, uint32_t type, uint32_t flags);
+int nftnl_rule_fprintf(FILE *fp, const struct nftnl_rule *r, uint32_t type, uint32_t flags);
#define nftnl_rule_nlmsg_build_hdr nftnl_nlmsg_build_hdr
int nftnl_rule_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_rule *t);
@@ -78,7 +78,7 @@ struct nftnl_rule_list;
struct nftnl_rule_list *nftnl_rule_list_alloc(void);
void nftnl_rule_list_free(struct nftnl_rule_list *list);
-int nftnl_rule_list_is_empty(struct nftnl_rule_list *list);
+int nftnl_rule_list_is_empty(const struct nftnl_rule_list *list);
void nftnl_rule_list_add(struct nftnl_rule *r, struct nftnl_rule_list *list);
void nftnl_rule_list_add_tail(struct nftnl_rule *r, struct nftnl_rule_list *list);
void nftnl_rule_list_del(struct nftnl_rule *r);
@@ -89,7 +89,7 @@ struct nftnl_rule_list_iter;
struct nftnl_rule_list_iter *nftnl_rule_list_iter_create(struct nftnl_rule_list *l);
struct nftnl_rule *nftnl_rule_list_iter_cur(struct nftnl_rule_list_iter *iter);
struct nftnl_rule *nftnl_rule_list_iter_next(struct nftnl_rule_list_iter *iter);
-void nftnl_rule_list_iter_destroy(struct nftnl_rule_list_iter *iter);
+void nftnl_rule_list_iter_destroy(const struct nftnl_rule_list_iter *iter);
/*
* Compat
diff --git a/include/libnftnl/ruleset.h b/include/libnftnl/ruleset.h
index c184af6..83c2334 100644
--- a/include/libnftnl/ruleset.h
+++ b/include/libnftnl/ruleset.h
@@ -16,7 +16,7 @@ extern "C" {
struct nftnl_ruleset;
struct nftnl_ruleset *nftnl_ruleset_alloc(void);
-void nftnl_ruleset_free(struct nftnl_ruleset *r);
+void nftnl_ruleset_free(const struct nftnl_ruleset *r);
enum {
NFTNL_RULESET_TABLELIST = 0,
diff --git a/include/libnftnl/set.h b/include/libnftnl/set.h
index 11243f5..c9a879a 100644
--- a/include/libnftnl/set.h
+++ b/include/libnftnl/set.h
@@ -29,7 +29,7 @@ enum nftnl_set_attr {
struct nftnl_set;
struct nftnl_set *nftnl_set_alloc(void);
-void nftnl_set_free(struct nftnl_set *s);
+void nftnl_set_free(const struct nftnl_set *s);
struct nftnl_set *nftnl_set_clone(const struct nftnl_set *set);
@@ -42,12 +42,12 @@ void nftnl_set_set_u32(struct nftnl_set *s, uint16_t attr, uint32_t val);
void nftnl_set_set_u64(struct nftnl_set *s, uint16_t attr, uint64_t val);
void nftnl_set_set_str(struct nftnl_set *s, uint16_t attr, const char *str);
-const void *nftnl_set_get(struct nftnl_set *s, uint16_t attr);
-const void *nftnl_set_get_data(struct nftnl_set *s, uint16_t attr,
- uint32_t *data_len);
-const char *nftnl_set_get_str(struct nftnl_set *s, uint16_t attr);
-uint32_t nftnl_set_get_u32(struct nftnl_set *s, uint16_t attr);
-uint64_t nftnl_set_get_u64(struct nftnl_set *s, uint16_t attr);
+const void *nftnl_set_get(const struct nftnl_set *s, uint16_t attr);
+const void *nftnl_set_get_data(const struct nftnl_set *s, uint16_t attr,
+ uint32_t *data_len);
+const char *nftnl_set_get_str(const struct nftnl_set *s, uint16_t attr);
+uint32_t nftnl_set_get_u32(const struct nftnl_set *s, uint16_t attr);
+uint64_t nftnl_set_get_u64(const struct nftnl_set *s, uint16_t attr);
struct nlmsghdr;
@@ -56,14 +56,14 @@ void nftnl_set_nlmsg_build_payload(struct nlmsghdr *nlh, struct nftnl_set *s);
int nftnl_set_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_set *s);
int nftnl_set_elems_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_set *s);
-int nftnl_set_snprintf(char *buf, size_t size, struct nftnl_set *s, uint32_t type, uint32_t flags);
-int nftnl_set_fprintf(FILE *fp, struct nftnl_set *s, uint32_t type, uint32_t flags);
+int nftnl_set_snprintf(char *buf, size_t size, const struct nftnl_set *s, uint32_t type, uint32_t flags);
+int nftnl_set_fprintf(FILE *fp, const struct nftnl_set *s, uint32_t type, uint32_t flags);
struct nftnl_set_list;
struct nftnl_set_list *nftnl_set_list_alloc(void);
void nftnl_set_list_free(struct nftnl_set_list *list);
-int nftnl_set_list_is_empty(struct nftnl_set_list *list);
+int nftnl_set_list_is_empty(const struct nftnl_set_list *list);
void nftnl_set_list_add(struct nftnl_set *s, struct nftnl_set_list *list);
void nftnl_set_list_add_tail(struct nftnl_set *s, struct nftnl_set_list *list);
void nftnl_set_list_del(struct nftnl_set *s);
@@ -73,7 +73,7 @@ struct nftnl_set_list_iter;
struct nftnl_set_list_iter *nftnl_set_list_iter_create(struct nftnl_set_list *l);
struct nftnl_set *nftnl_set_list_iter_cur(struct nftnl_set_list_iter *iter);
struct nftnl_set *nftnl_set_list_iter_next(struct nftnl_set_list_iter *iter);
-void nftnl_set_list_iter_destroy(struct nftnl_set_list_iter *iter);
+void nftnl_set_list_iter_destroy(const struct nftnl_set_list_iter *iter);
int nftnl_set_parse(struct nftnl_set *s, enum nftnl_parse_type type,
const char *data, struct nftnl_parse_err *err);
@@ -126,7 +126,7 @@ int nftnl_set_elem_parse(struct nftnl_set_elem *e, enum nftnl_parse_type type,
const char *data, struct nftnl_parse_err *err);
int nftnl_set_elem_parse_file(struct nftnl_set_elem *e, enum nftnl_parse_type type,
FILE *fp, struct nftnl_parse_err *err);
-int nftnl_set_elem_snprintf(char *buf, size_t size, struct nftnl_set_elem *s, uint32_t type, uint32_t flags);
+int nftnl_set_elem_snprintf(char *buf, size_t size, const struct nftnl_set_elem *s, uint32_t type, uint32_t flags);
int nftnl_set_elem_fprintf(FILE *fp, struct nftnl_set_elem *se, uint32_t type, uint32_t flags);
int nftnl_set_elem_foreach(struct nftnl_set *s, int (*cb)(struct nftnl_set_elem *e, void *data), void *data);
diff --git a/include/libnftnl/table.h b/include/libnftnl/table.h
index c52d579..8972d09 100644
--- a/include/libnftnl/table.h
+++ b/include/libnftnl/table.h
@@ -15,7 +15,7 @@ extern "C" {
struct nftnl_table;
struct nftnl_table *nftnl_table_alloc(void);
-void nftnl_table_free(struct nftnl_table *);
+void nftnl_table_free(const struct nftnl_table *);
enum nftnl_table_attr {
NFTNL_TABLE_NAME = 0,
@@ -31,16 +31,16 @@ void nftnl_table_unset(struct nftnl_table *t, uint16_t attr);
void nftnl_table_set(struct nftnl_table *t, uint16_t attr, const void *data);
void nftnl_table_set_data(struct nftnl_table *t, uint16_t attr,
const void *data, uint32_t data_len);
-const void *nftnl_table_get(struct nftnl_table *t, uint16_t attr);
-const void *nftnl_table_get_data(struct nftnl_table *t, uint16_t attr,
- uint32_t *data_len);
+const void *nftnl_table_get(const struct nftnl_table *t, uint16_t attr);
+const void *nftnl_table_get_data(const struct nftnl_table *t, uint16_t attr,
+ uint32_t *data_len);
void nftnl_table_set_u8(struct nftnl_table *t, uint16_t attr, uint8_t data);
void nftnl_table_set_u32(struct nftnl_table *t, uint16_t attr, uint32_t data);
void nftnl_table_set_str(struct nftnl_table *t, uint16_t attr, const char *str);
-uint8_t nftnl_table_get_u8(struct nftnl_table *t, uint16_t attr);
-uint32_t nftnl_table_get_u32(struct nftnl_table *t, uint16_t attr);
-const char *nftnl_table_get_str(struct nftnl_table *t, uint16_t attr);
+uint8_t nftnl_table_get_u8(const struct nftnl_table *t, uint16_t attr);
+uint32_t nftnl_table_get_u32(const struct nftnl_table *t, uint16_t attr);
+const char *nftnl_table_get_str(const struct nftnl_table *t, uint16_t attr);
struct nlmsghdr;
@@ -50,8 +50,8 @@ int nftnl_table_parse(struct nftnl_table *t, enum nftnl_parse_type type,
const char *data, struct nftnl_parse_err *err);
int nftnl_table_parse_file(struct nftnl_table *t, enum nftnl_parse_type type,
FILE *fp, struct nftnl_parse_err *err);
-int nftnl_table_snprintf(char *buf, size_t size, struct nftnl_table *t, uint32_t type, uint32_t flags);
-int nftnl_table_fprintf(FILE *fp, struct nftnl_table *t, uint32_t type, uint32_t flags);
+int nftnl_table_snprintf(char *buf, size_t size, const struct nftnl_table *t, uint32_t type, uint32_t flags);
+int nftnl_table_fprintf(FILE *fp, const struct nftnl_table *t, uint32_t type, uint32_t flags);
#define nftnl_table_nlmsg_build_hdr nftnl_nlmsg_build_hdr
int nftnl_table_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_table *t);
@@ -60,7 +60,7 @@ struct nftnl_table_list;
struct nftnl_table_list *nftnl_table_list_alloc(void);
void nftnl_table_list_free(struct nftnl_table_list *list);
-int nftnl_table_list_is_empty(struct nftnl_table_list *list);
+int nftnl_table_list_is_empty(const struct nftnl_table_list *list);
int nftnl_table_list_foreach(struct nftnl_table_list *table_list, int (*cb)(struct nftnl_table *t, void *data), void *data);
void nftnl_table_list_add(struct nftnl_table *r, struct nftnl_table_list *list);
@@ -71,7 +71,7 @@ struct nftnl_table_list_iter;
struct nftnl_table_list_iter *nftnl_table_list_iter_create(struct nftnl_table_list *l);
struct nftnl_table *nftnl_table_list_iter_next(struct nftnl_table_list_iter *iter);
-void nftnl_table_list_iter_destroy(struct nftnl_table_list_iter *iter);
+void nftnl_table_list_iter_destroy(const struct nftnl_table_list_iter *iter);
/*
* Compat
diff --git a/include/libnftnl/trace.h b/include/libnftnl/trace.h
index 674bc16..18ab0c3 100644
--- a/include/libnftnl/trace.h
+++ b/include/libnftnl/trace.h
@@ -35,7 +35,7 @@ enum nftnl_trace_attr {
struct nftnl_trace;
struct nftnl_trace *nftnl_trace_alloc(void);
-void nftnl_trace_free(struct nftnl_trace *trace);
+void nftnl_trace_free(const struct nftnl_trace *trace);
bool nftnl_trace_is_set(const struct nftnl_trace *trace, uint16_t type);
diff --git a/include/libnftnl/udata.h b/include/libnftnl/udata.h
index 312ce26..d36cef7 100644
--- a/include/libnftnl/udata.h
+++ b/include/libnftnl/udata.h
@@ -13,7 +13,7 @@ struct nftnl_udata_buf;
/* nftnl_udata_buf */
struct nftnl_udata_buf *nftnl_udata_buf_alloc(uint32_t data_size);
-void nftnl_udata_buf_free(struct nftnl_udata_buf *buf);
+void nftnl_udata_buf_free(const struct nftnl_udata_buf *buf);
uint32_t nftnl_udata_buf_len(const struct nftnl_udata_buf *buf);
void *nftnl_udata_buf_data(const struct nftnl_udata_buf *buf);
void nftnl_udata_buf_put(struct nftnl_udata_buf *buf, const void *data,
diff --git a/include/utils.h b/include/utils.h
index 0087dbb..46ff18a 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -77,8 +77,10 @@ uint32_t nftnl_str2cmd(const char *cmd);
enum nftnl_cmd_type nftnl_flag2cmd(uint32_t flags);
-int nftnl_fprintf(FILE *fp, void *obj, uint32_t cmd, uint32_t type,
- uint32_t flags, int (*snprintf_cb)(char *buf, size_t bufsiz,
- void *obj, uint32_t cmd, uint32_t type, uint32_t flags));
+int nftnl_fprintf(FILE *fpconst, const void *obj, uint32_t cmd, uint32_t type,
+ uint32_t flags,
+ int (*snprintf_cb)(char *buf, size_t bufsiz, const void *obj,
+ uint32_t cmd, uint32_t type,
+ uint32_t flags));
#endif