15 #include "internal/internal.h"
30 struct nf_expect *exp;
32 exp = malloc(
sizeof(
struct nf_expect));
36 memset(exp, 0,
sizeof(
struct nf_expect));
78 return sizeof(
struct nf_expect);
90 struct nf_expect *clone;
96 memcpy(clone, exp,
sizeof(*exp));
126 int nfexp_cmp(
const struct nf_expect *exp1,
const struct nf_expect *exp2,
129 assert(exp1 != NULL);
130 assert(exp2 != NULL);
132 return __cmp_expect(exp1, exp2, flags);
158 enum nf_conntrack_msg_type type,
159 int (*cb)(
enum nf_conntrack_msg_type type,
160 struct nf_expect *exp,
164 struct __data_container *container;
168 container = malloc(
sizeof(
struct __data_container));
171 memset(container, 0,
sizeof(
struct __data_container));
175 container->type = type;
176 container->data = data;
178 h->nfnl_cb_exp.call = __callback;
179 h->nfnl_cb_exp.data = container;
180 h->nfnl_cb_exp.attr_count = CTA_EXPECT_MAX;
182 nfnl_callback_register(h->nfnlssh_exp,
186 nfnl_callback_register(h->nfnlssh_exp,
187 IPCTNL_MSG_EXP_DELETE,
201 nfnl_callback_unregister(h->nfnlssh_exp, IPCTNL_MSG_EXP_NEW);
202 nfnl_callback_unregister(h->nfnlssh_exp, IPCTNL_MSG_EXP_DELETE);
205 free(h->nfnl_cb_exp.data);
207 h->nfnl_cb_exp.call = NULL;
208 h->nfnl_cb_exp.data = NULL;
209 h->nfnl_cb_exp.attr_count = 0;
232 enum nf_conntrack_msg_type type,
233 int (*cb)(
const struct nlmsghdr *nlh,
234 enum nf_conntrack_msg_type type,
235 struct nf_expect *exp,
239 struct __data_container *container;
243 container = malloc(
sizeof(
struct __data_container));
246 memset(container, 0,
sizeof(
struct __data_container));
250 container->type = type;
251 container->data = data;
253 h->nfnl_cb_exp.call = __callback;
254 h->nfnl_cb_exp.data = container;
255 h->nfnl_cb_exp.attr_count = CTA_EXPECT_MAX;
257 nfnl_callback_register(h->nfnlssh_exp,
261 nfnl_callback_register(h->nfnlssh_exp,
262 IPCTNL_MSG_EXP_DELETE,
276 nfnl_callback_unregister(h->nfnlssh_exp, IPCTNL_MSG_EXP_NEW);
277 nfnl_callback_unregister(h->nfnlssh_exp, IPCTNL_MSG_EXP_DELETE);
279 h->expect_cb2 = NULL;
280 free(h->nfnl_cb_exp.data);
282 h->nfnl_cb_exp.call = NULL;
283 h->nfnl_cb_exp.data = NULL;
284 h->nfnl_cb_exp.attr_count = 0;
309 const enum nf_expect_attr type,
313 assert(value != NULL);
315 if (type >= ATTR_EXP_MAX)
318 if (set_exp_attr_array[type]) {
319 set_exp_attr_array[type](exp, value);
320 set_bit(type, exp->set);
331 const enum nf_expect_attr type,
344 const enum nf_expect_attr type,
357 const enum nf_expect_attr type,
372 const enum nf_expect_attr type)
376 if (type >= ATTR_EXP_MAX) {
381 if (!test_bit(type, exp->set)) {
386 return get_exp_attr_array[type](exp);
399 const enum nf_expect_attr type)
402 return ret == NULL ? 0 : *ret;
415 const enum nf_expect_attr type)
418 return ret == NULL ? 0 : *ret;
431 const enum nf_expect_attr type)
434 return ret == NULL ? 0 : *ret;
446 const enum nf_expect_attr type)
450 if (type >= ATTR_EXP_MAX) {
454 return test_bit(type, exp->set);
466 const enum nf_expect_attr type)
470 if (type >= ATTR_EXP_MAX) {
474 unset_bit(type, exp->set);
509 const struct nf_expect *exp)
515 return __build_expect(ssh, req, size, type, flags, exp);
519 __build_query_exp(
struct nfnl_subsys_handle *ssh,
520 const enum nf_conntrack_query qt,
521 const void *data,
void *buffer,
unsigned int size)
523 struct nfnlhdr *req = buffer;
524 const uint8_t *family = data;
527 assert(data != NULL);
530 memset(req, 0, size);
534 __build_expect(ssh, req, size, IPCTNL_MSG_EXP_NEW, NLM_F_REQUEST|NLM_F_CREATE|NLM_F_ACK|NLM_F_EXCL, data);
536 case NFCT_Q_CREATE_UPDATE:
537 __build_expect(ssh, req, size, IPCTNL_MSG_EXP_NEW, NLM_F_REQUEST|NLM_F_CREATE|NLM_F_ACK, data);
540 __build_expect(ssh, req, size, IPCTNL_MSG_EXP_GET, NLM_F_REQUEST|NLM_F_ACK, data);
543 __build_expect(ssh, req, size, IPCTNL_MSG_EXP_DELETE, NLM_F_REQUEST|NLM_F_ACK, data);
546 nfnl_fill_hdr(ssh, &req->nlh, 0, *family, 0, IPCTNL_MSG_EXP_DELETE, NLM_F_REQUEST|NLM_F_ACK);
549 nfnl_fill_hdr(ssh, &req->nlh, 0, *family, 0, IPCTNL_MSG_EXP_GET, NLM_F_REQUEST|NLM_F_DUMP);
589 const enum nf_conntrack_query qt,
594 return __build_query_exp(ssh, qt, data, buffer, size);
622 const struct nlmsghdr *nlh,
623 struct nf_expect *exp)
626 int len = nlh->nlmsg_len;
627 struct nfgenmsg *nfhdr = NLMSG_DATA(nlh);
628 struct nfattr *cda[CTA_EXPECT_MAX];
633 len -= NLMSG_LENGTH(
sizeof(
struct nfgenmsg));
639 flags = __parse_expect_message_type(nlh);
643 nfnl_parse_attr(cda, CTA_EXPECT_MAX, NFA_DATA(nfhdr), len);
645 __parse_expect(nlh, cda, exp);
669 const enum nf_conntrack_query qt,
672 const size_t size = 4096;
679 assert(data != NULL);
681 if (__build_query_exp(h->nfnlssh_exp, qt, data, &u.req, size) == -1)
684 return nfnl_query(h->nfnlh, &u.req.nlh);
701 const enum nf_conntrack_query qt,
704 const size_t size = 4096;
711 assert(data != NULL);
713 if (__build_query_exp(h->nfnlssh_exp, qt, data, &u.req, size) == -1)
716 return nfnl_send(h->nfnlh, &u.req.nlh);
737 return nfnl_catch(h->nfnlh);
776 const struct nf_expect *exp,
777 unsigned int msg_type,
778 unsigned int out_type,
785 return __snprintf_expect(buf, size, exp, msg_type, out_type, flags);
void nfexp_set_attr(struct nf_expect *exp, const enum nf_expect_attr type, const void *value)
size_t nfexp_maxsize(void)
int nfexp_callback_register2(struct nfct_handle *h, enum nf_conntrack_msg_type type, int(*cb)(const struct nlmsghdr *nlh, enum nf_conntrack_msg_type type, struct nf_expect *exp, void *data), void *data)
void nfexp_set_attr_u32(struct nf_expect *exp, const enum nf_expect_attr type, uint32_t value)
uint32_t nfexp_get_attr_u32(const struct nf_expect *exp, const enum nf_expect_attr type)
void nfexp_callback_unregister2(struct nfct_handle *h)
void nfexp_set_attr_u16(struct nf_expect *exp, const enum nf_expect_attr type, uint16_t value)
int nfexp_build_expect(struct nfnl_subsys_handle *ssh, void *req, size_t size, uint16_t type, uint16_t flags, const struct nf_expect *exp)
int nfexp_query(struct nfct_handle *h, const enum nf_conntrack_query qt, const void *data)
struct nf_expect * nfexp_clone(const struct nf_expect *exp)
int nfexp_cmp(const struct nf_expect *exp1, const struct nf_expect *exp2, unsigned int flags)
int nfexp_send(struct nfct_handle *h, const enum nf_conntrack_query qt, const void *data)
uint16_t nfexp_get_attr_u16(const struct nf_expect *exp, const enum nf_expect_attr type)
struct nf_expect * nfexp_new(void)
int nfexp_attr_unset(struct nf_expect *exp, const enum nf_expect_attr type)
int nfexp_parse_expect(enum nf_conntrack_msg_type type, const struct nlmsghdr *nlh, struct nf_expect *exp)
int nfexp_snprintf(char *buf, unsigned int size, const struct nf_expect *exp, unsigned int msg_type, unsigned int out_type, unsigned int flags)
int nfexp_build_query(struct nfnl_subsys_handle *ssh, const enum nf_conntrack_query qt, const void *data, void *buffer, unsigned int size)
void nfexp_set_attr_u8(struct nf_expect *exp, const enum nf_expect_attr type, uint8_t value)
int nfexp_callback_register(struct nfct_handle *h, enum nf_conntrack_msg_type type, int(*cb)(enum nf_conntrack_msg_type type, struct nf_expect *exp, void *data), void *data)
int nfexp_attr_is_set(const struct nf_expect *exp, const enum nf_expect_attr type)
int nfexp_catch(struct nfct_handle *h)
uint8_t nfexp_get_attr_u8(const struct nf_expect *exp, const enum nf_expect_attr type)
void nfexp_callback_unregister(struct nfct_handle *h)
size_t nfexp_sizeof(const struct nf_expect *exp)
void nfexp_destroy(struct nf_expect *exp)
const void * nfexp_get_attr(const struct nf_expect *exp, const enum nf_expect_attr type)