6#include <netlink/cli/utils.h>
7#include <netlink/cli/ct.h>
9#include <linux/netlink.h>
10#include <linux/netfilter/nfnetlink.h>
11#include <linux/netfilter/nfnetlink_conntrack.h>
16 struct nl_object_ops * ce_ops;
17 struct nl_cache * ce_cache;
24static void nf_conntrack_parse_callback(
struct nl_object *obj,
void *opaque)
34static int nf_conntrack_event_callback(
struct nl_msg *msg,
void *opaque)
39 enum cntl_msg_types type = (
enum cntl_msg_types) NFNL_MSG_TYPE(hdr->nlmsg_type);
41 int flags = hdr->nlmsg_flags;
43 if (type == IPCTNL_MSG_CT_DELETE) {
45 }
else if (type == IPCTNL_MSG_CT_NEW) {
46 if (flags & (NLM_F_CREATE|NLM_F_EXCL)) {
55 if ((err = nl_msg_parse(msg, &nf_conntrack_parse_callback, opaque)) < 0) {
62int main(
int argc,
char *argv[])
64 struct nl_sock *socket;
67 socket = nl_cli_alloc_socket();
69 nl_cli_fatal(ENOBUFS,
"Unable to allocate netlink socket");
81 NF_NETLINK_CONNTRACK_UPDATE |
82 NF_NETLINK_CONNTRACK_DESTROY |
83 NF_NETLINK_CONNTRACK_EXP_NEW |
84 NF_NETLINK_CONNTRACK_EXP_UPDATE |
85 NF_NETLINK_CONNTRACK_EXP_DESTROY);
87 nl_cli_connect(socket, NETLINK_NETFILTER);
98 fprintf(stderr,
"Lost events because of ENOBUFS\n");
105 nl_cli_fatal(err,
"Failed to receive: %s", nl_geterror(err));
@ NL_OK
Proceed with whatever would come next.
@ NL_CB_VALID
Message is valid.
@ NL_CB_CUSTOM
Customized handler specified by the user.
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
struct nlmsghdr * nlmsg_hdr(struct nl_msg *n)
Return actual netlink message.
void nl_object_dump(struct nl_object *obj, struct nl_dump_params *params)
Dump this object according to the specified parameters.
int nl_recvmsgs_default(struct nl_sock *sk)
Receive a set of message from a netlink socket using handlers in nl_sock.
void nl_join_groups(struct nl_sock *sk, int groups)
Join multicast groups (deprecated)
void nl_socket_disable_seq_check(struct nl_sock *sk)
Disable sequence number checking.
int nl_socket_modify_cb(struct nl_sock *sk, enum nl_cb_type type, enum nl_cb_kind kind, nl_recvmsg_msg_cb_t func, void *arg)
Modify the callback handler associated with the socket.
@ NL_DUMP_DETAILS
Dump all attributes but no statistics.
FILE * dp_fd
File descriptor the dumping output should go to.