8#include <netlink/cli/utils.h>
9#include <netlink/cli/link.h>
10#include <netlink/netfilter/nfnl.h>
11#include <netlink/netfilter/log.h>
13#include <linux/netfilter/nfnetlink_log.h>
14#include <linux/netlink.h>
16static struct nfnl_log *alloc_log(
void)
20 log = nfnl_log_alloc();
27static void obj_input(
struct nl_object *obj,
void *arg)
38static int event_input(
struct nl_msg *msg,
void *arg)
40 if (nl_msg_parse(msg, &obj_input, NULL) < 0)
41 fprintf(stderr,
"<<EVENT>> Unknown message type\n");
47int main(
int argc,
char *argv[])
49 struct nl_sock *nf_sock;
50 struct nl_sock *rt_sock;
57 nf_sock = nl_cli_alloc_socket();
61 if ((argc > 1 && !strcasecmp(argv[1],
"-h")) || argc < 3) {
62 printf(
"Usage: nf-log family group [ copy_mode ] "
67 nl_cli_connect(nf_sock, NETLINK_NETFILTER);
69 family = nl_str2af(argv[1]);
70 if (family == AF_UNSPEC)
72 argv[1], nl_geterror(family));
74 nfnl_log_pf_unbind(nf_sock, family);
75 if ((err = nfnl_log_pf_bind(nf_sock, family)) < 0)
80 nfnl_log_set_group(log, atoi(argv[2]));
82 copy_mode = NFNL_LOG_COPY_META;
84 copy_mode = nfnl_log_str2copy_mode(argv[3]);
87 "Unable to parse copy mode \"%s\": %s",
88 argv[3], nl_geterror(copy_mode));
90 nfnl_log_set_copy_mode(log, copy_mode);
94 copy_range = atoi(argv[4]);
95 nfnl_log_set_copy_range(log, copy_range);
97 if ((err = nfnl_log_create(nf_sock, log)) < 0)
105 .dp_dump_msgtype = 1,
108 printf(
"log params: ");
112 rt_sock = nl_cli_alloc_socket();
113 nl_cli_connect(rt_sock, NETLINK_ROUTE);
114 nl_cli_link_alloc_cache(rt_sock);
118 int nffd, rtfd, maxfd, retval;
131 retval = select(maxfd+1, &rfds, NULL, NULL, NULL);
134 if (FD_ISSET(nffd, &rfds))
136 if (FD_ISSET(rtfd, &rfds))
@ NL_STOP
Stop parsing altogether and discard remaining messages.
@ 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.
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.
int nl_socket_get_fd(const struct nl_sock *sk)
Return the file descriptor of the backing socket.
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_STATS
Dump all attributes including statistics.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.