7 #include <libmnl/libmnl.h>
8 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
10 #include <linux/netfilter/nf_conntrack_tcp.h>
14 struct mnl_socket *nl;
17 char buf[MNL_SOCKET_BUFFER_SIZE];
18 unsigned int seq, portid;
19 struct nf_conntrack *ct;
22 nl = mnl_socket_open(NETLINK_NETFILTER);
24 perror(
"mnl_socket_open");
28 if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) {
29 perror(
"mnl_socket_bind");
32 portid = mnl_socket_get_portid(nl);
34 nlh = mnl_nlmsg_put_header(buf);
35 nlh->nlmsg_type = (NFNL_SUBSYS_CTNETLINK << 8) | IPCTNL_MSG_CT_DELETE;
36 nlh->nlmsg_flags = NLM_F_REQUEST|NLM_F_ACK;
37 nlh->nlmsg_seq = seq = time(NULL);
39 nfh = mnl_nlmsg_put_extra_header(nlh,
sizeof(
struct nfgenmsg));
40 nfh->nfgen_family = AF_INET;
41 nfh->version = NFNETLINK_V0;
58 nfct_nlmsg_build(nlh, ct);
60 ret = mnl_socket_sendto(nl, nlh, nlh->nlmsg_len);
62 perror(
"mnl_socket_recvfrom");
66 ret = mnl_socket_recvfrom(nl, buf,
sizeof(buf));
68 ret = mnl_cb_run(buf, ret, seq, portid, NULL, NULL);
69 if (ret <= MNL_CB_STOP)
71 ret = mnl_socket_recvfrom(nl, buf,
sizeof(buf));
74 perror(
"mnl_socket_recvfrom");
void nfct_set_attr_u32(struct nf_conntrack *ct, const enum nf_conntrack_attr type, uint32_t value)
void nfct_set_attr_u16(struct nf_conntrack *ct, const enum nf_conntrack_attr type, uint16_t value)
struct nf_conntrack * nfct_new(void)
void nfct_set_attr_u8(struct nf_conntrack *ct, const enum nf_conntrack_attr type, uint8_t value)