libnetfilter_conntrack  1.0.8
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 
13 int __build_expect(struct nfnl_subsys_handle *ssh,
14  struct nfnlhdr *req,
15  size_t size,
16  uint16_t type,
17  uint16_t flags,
18  const struct nf_expect *exp)
19 {
20  struct nlmsghdr *nlh;
21  struct nfgenmsg *nfh;
22  uint8_t l3num;
23  char *buf;
24 
25  if (test_bit(ATTR_ORIG_L3PROTO, exp->master.set))
26  l3num = exp->master.orig.l3protonum;
27  else if (test_bit(ATTR_ORIG_L3PROTO, exp->expected.set))
28  l3num = exp->expected.orig.l3protonum;
29  else
30  return -1;
31 
32  memset(req, 0, size);
33 
34  buf = (char *)&req->nlh;
35  nlh = mnl_nlmsg_put_header(buf);
36  nlh->nlmsg_type = (NFNL_SUBSYS_CTNETLINK_EXP << 8) | type;
37  nlh->nlmsg_flags = flags;
38  nlh->nlmsg_seq = 0;
39 
40  nfh = mnl_nlmsg_put_extra_header(nlh, sizeof(struct nfgenmsg));
41  nfh->nfgen_family = l3num;
42  nfh->version = NFNETLINK_V0;
43  nfh->res_id = 0;
44 
45  return nfexp_nlmsg_build(nlh, exp);
46 }