conntrack_grp_create.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <arpa/inet.h>
#include <libnetfilter_conntrack/libnetfilter_conntrack.h>
#include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h>
int main(void)
{
int ret;
struct nfct_handle *h;
struct nf_conntrack *ct;
ct = nfct_new();
if (!ct) {
perror("nfct_new");
return 0;
}
struct nfct_attr_grp_ipv4 grp_ipv4 = {
.src = inet_addr("1.1.1.1"),
.dst = inet_addr("2.2.2.2")
};
nfct_set_attr_grp(ct, ATTR_GRP_ORIG_IPV4, &grp_ipv4);
struct nfct_attr_grp_port grp_port = {
.sport = htons(20),
.dport = htons(10)
};
nfct_set_attr_grp(ct, ATTR_GRP_ORIG_PORT, &grp_port);
nfct_set_attr_u8(ct, ATTR_L4PROTO, IPPROTO_TCP);
nfct_setobjopt(ct, NFCT_SOPT_SETUP_REPLY);
nfct_set_attr_u8(ct, ATTR_TCP_STATE, TCP_CONNTRACK_SYN_SENT);
nfct_set_attr_u32(ct, ATTR_TIMEOUT, 100);
nfct_set_attr(ct, ATTR_HELPER_NAME, "ftp");
h = nfct_open(CONNTRACK, 0);
if (!h) {
perror("nfct_open");
nfct_destroy(ct);
return -1;
}
ret = nfct_query(h, NFCT_Q_CREATE, ct);
printf("TEST: create conntrack ");
if (ret == -1)
printf("(%d)(%s)\n", ret, strerror(errno));
else
printf("(OK)\n");
nfct_close(h);
nfct_destroy(ct);
ret == -1 ? exit(EXIT_FAILURE) : exit(EXIT_SUCCESS);
}
nfct_open
struct nfct_handle * nfct_open(uint8_t, unsigned)
Definition main.c:84
nfct_close
int nfct_close(struct nfct_handle *cth)
Definition main.c:105
nfct_query
int nfct_query(struct nfct_handle *h, const enum nf_conntrack_query query, const void *data)
Definition conntrack/api.c:991
nfct_set_attr_u32
void nfct_set_attr_u32(struct nf_conntrack *ct, const enum nf_conntrack_attr type, uint32_t value)
Definition conntrack/api.c:439
nfct_destroy
void nfct_destroy(struct nf_conntrack *ct)
Definition conntrack/api.c:93
nfct_set_attr
void nfct_set_attr(struct nf_conntrack *ct, const enum nf_conntrack_attr type, const void *value)
Definition conntrack/api.c:399
nfct_setobjopt
int nfct_setobjopt(struct nf_conntrack *ct, unsigned int option)
Definition conntrack/api.c:169
nfct_set_attr_grp
void nfct_set_attr_grp(struct nf_conntrack *ct, const enum nf_conntrack_attr_grp type, const void *value)
Definition conntrack/api.c:630
nfct_set_attr_u8
void nfct_set_attr_u8(struct nf_conntrack *ct, const enum nf_conntrack_attr type, uint8_t value)
Definition conntrack/api.c:413
nfct_new
struct nf_conntrack * nfct_new(void)
Definition conntrack/api.c:76
nfct_attr_grp_ipv4
Definition libnetfilter_conntrack.h:172
nfct_attr_grp_port
Definition libnetfilter_conntrack.h:180