10 #include "internal/internal.h"
11 #include <libmnl/libmnl.h>
13 static int __parse_message(
const struct nlmsghdr *nlh)
15 uint16_t type = NFNL_MSG_TYPE(nlh->nlmsg_type);
16 uint16_t flags = nlh->nlmsg_flags;
17 int ret = NFCT_T_UNKNOWN;
20 case IPCTNL_MSG_CT_NEW:
21 if (flags & (NLM_F_CREATE|NLM_F_EXCL))
26 case IPCTNL_MSG_CT_DELETE:
36 int __callback(
struct nlmsghdr *nlh,
struct nfattr *nfa[],
void *data)
38 int ret = NFNL_CB_STOP;
40 struct nf_conntrack *ct = NULL;
41 struct nf_expect *exp = NULL;
42 struct __data_container *container = data;
43 uint8_t subsys = NFNL_SUBSYS_ID(nlh->nlmsg_type);
45 if (nlh->nlmsg_len < NLMSG_LENGTH(
sizeof(
struct nfgenmsg))) {
47 return NFNL_CB_FAILURE;
49 type = __parse_message(nlh);
50 if (!(type & container->type))
51 return NFNL_CB_CONTINUE;
54 case NFNL_SUBSYS_CTNETLINK:
57 return NFNL_CB_FAILURE;
59 nfct_nlmsg_parse(nlh, ct);
61 if (container->h->cb) {
62 ret = container->h->cb(type, ct, container->data);
63 }
else if (container->h->cb2) {
64 ret = container->h->cb2(nlh, type, ct,
68 case NFNL_SUBSYS_CTNETLINK_EXP:
71 return NFNL_CB_FAILURE;
73 nfexp_nlmsg_parse(nlh, exp);
75 if (container->h->expect_cb) {
76 ret = container->h->expect_cb(type, exp,
78 }
else if (container->h->expect_cb2) {
79 ret = container->h->expect_cb2(nlh, type, exp,
85 ret = NFNL_CB_FAILURE;
89 if (ret == NFCT_CB_STOLEN)
90 return NFNL_CB_CONTINUE;
void nfct_destroy(struct nf_conntrack *ct)
struct nf_conntrack * nfct_new(void)
struct nf_expect * nfexp_new(void)
void nfexp_destroy(struct nf_expect *exp)