diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2019-05-02 14:07:25 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2019-05-02 16:29:56 +0200 |
commit | c1c0f16c1fedb46547c2e104beeaaeac5933b214 (patch) | |
tree | 64210ba7c774c3e2a214600c7cf85a6cc754642b /src/expect/api.c | |
parent | a2fa46c606a36904a26aaf38598fa194c3fbcf4b (diff) |
src: replace old libnfnetlink parser
Use the new libmnl version, remove duplicated code.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/expect/api.c')
-rw-r--r-- | src/expect/api.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/src/expect/api.c b/src/expect/api.c index 3f17630..b50a47f 100644 --- a/src/expect/api.c +++ b/src/expect/api.c @@ -594,6 +594,23 @@ int nfexp_build_query(struct nfnl_subsys_handle *ssh, return __build_query_exp(ssh, qt, data, buffer, size); } +static int __parse_expect_message_type(const struct nlmsghdr *nlh) +{ + uint16_t type = NFNL_MSG_TYPE(nlh->nlmsg_type); + uint16_t flags = nlh->nlmsg_flags; + int ret = NFCT_T_UNKNOWN; + + if (type == IPCTNL_MSG_EXP_NEW) { + if (flags & (NLM_F_CREATE|NLM_F_EXCL)) + ret = NFCT_T_NEW; + else + ret = NFCT_T_UPDATE; + } else if (type == IPCTNL_MSG_EXP_DELETE) + ret = NFCT_T_DESTROY; + + return ret; +} + /** * nfexp_parse_expect - translate a netlink message to a conntrack object * \param type do the translation iif the message type is of a certain type @@ -623,26 +640,15 @@ int nfexp_parse_expect(enum nf_conntrack_msg_type type, struct nf_expect *exp) { unsigned int flags; - int len = nlh->nlmsg_len; - struct nfgenmsg *nfhdr = NLMSG_DATA(nlh); - struct nfattr *cda[CTA_EXPECT_MAX]; assert(nlh != NULL); assert(exp != NULL); - len -= NLMSG_LENGTH(sizeof(struct nfgenmsg)); - if (len < 0) { - errno = EINVAL; - return NFCT_T_ERROR; - } - flags = __parse_expect_message_type(nlh); if (!(flags & type)) return 0; - nfnl_parse_attr(cda, CTA_EXPECT_MAX, NFA_DATA(nfhdr), len); - - __parse_expect(nlh, cda, exp); + nfexp_nlmsg_parse(nlh, exp); return flags; } |