libnetfilter_conntrack  1.0.9
conntrack/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_conntrack(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_conntrack *ct)
19 {
20  uint8_t l3num = ct->head.orig.l3protonum;
21  struct nlmsghdr *nlh;
22  struct nfgenmsg *nfh;
23  char *buf;
24 
25  if (!test_bit(ATTR_ORIG_L3PROTO, ct->head.set)) {
26  errno = EINVAL;
27  return -1;
28  }
29 
30  memset(req, 0, size);
31 
32  buf = (char *)&req->nlh;
33  nlh = mnl_nlmsg_put_header(buf);
34  nlh->nlmsg_type = (NFNL_SUBSYS_CTNETLINK << 8) | type;
35  nlh->nlmsg_flags = flags;
36  nlh->nlmsg_seq = 0;
37 
38  nfh = mnl_nlmsg_put_extra_header(nlh, sizeof(struct nfgenmsg));
39  nfh->nfgen_family = l3num;
40  nfh->version = NFNETLINK_V0;
41  nfh->res_id = 0;
42 
43  return nfct_nlmsg_build(nlh, ct);
44 }