libnetfilter_conntrack 1.1.0
expect/build.c
1/*
2 * (C) 2005-2011 by Pablo Neira Ayuso <pablo@netfilter.org>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 */
9
10#include "internal/internal.h"
11#include <libmnl/libmnl.h>
12
13int __build_expect(struct nfnlhdr *req,
14 size_t size,
15 uint16_t type,
16 uint16_t flags,
17 const struct nf_expect *exp)
18{
19 struct nlmsghdr *nlh;
20 struct nfgenmsg *nfh;
21 uint8_t l3num;
22 char *buf;
23
24 if (test_bit(ATTR_ORIG_L3PROTO, exp->master.set))
25 l3num = exp->master.orig.l3protonum;
26 else if (test_bit(ATTR_ORIG_L3PROTO, exp->expected.set))
27 l3num = exp->expected.orig.l3protonum;
28 else
29 return -1;
30
31 buf = (char *)&req->nlh;
32 nlh = mnl_nlmsg_put_header(buf);
33 nlh->nlmsg_type = (NFNL_SUBSYS_CTNETLINK_EXP << 8) | type;
34 nlh->nlmsg_flags = flags;
35 nlh->nlmsg_seq = 0;
36
37 nfh = mnl_nlmsg_put_extra_header(nlh, sizeof(struct nfgenmsg));
38 nfh->nfgen_family = l3num;
39 nfh->version = NFNETLINK_V0;
40 nfh->res_id = 0;
41
42 return nfexp_nlmsg_build(nlh, exp);
43}