| 1 |
/* |
| 2 |
* (C) 2005-2011 by Pablo Neira Ayuso <[email protected]> |
| 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 nfnlhdr *req, |
| 14 |
size_t size, |
| 15 |
uint16_t type, |
| 16 |
uint16_t flags, |
| 17 |
const struct nf_conntrack *ct) |
| 18 |
{ |
| 19 |
uint8_t l3num = ct->head.orig.l3protonum; |
| 20 |
struct nlmsghdr *nlh; |
| 21 |
struct nfgenmsg *nfh; |
| 22 |
char *buf; |
| 23 |
|
| 24 |
if (!test_bit(ATTR_ORIG_L3PROTO, ct->head.set)) { |
| 25 |
errno = EINVAL; |
| 26 |
return -1; |
| 27 |
} |
| 28 |
|
| 29 |
buf = (char *)&req->nlh; |
| 30 |
nlh = mnl_nlmsg_put_header(buf); |
| 31 |
nlh->nlmsg_type = (NFNL_SUBSYS_CTNETLINK << 8) | type; |
| 32 |
nlh->nlmsg_flags = flags; |
| 33 |
nlh->nlmsg_seq = 0; |
| 34 |
|
| 35 |
nfh = mnl_nlmsg_put_extra_header(nlh, sizeof(struct nfgenmsg)); |
| 36 |
nfh->nfgen_family = l3num; |
| 37 |
nfh->version = NFNETLINK_V0; |
| 38 |
nfh->res_id = 0; |
| 39 |
|
| 40 |
return nfct_nlmsg_build(nlh, ct); |
| 41 |
} |