14 #include <netlink/cli/utils.h>
15 #include <netlink/cli/link.h>
16 #include <linux/netfilter/nfnetlink_log.h>
17 #include <netlink/netfilter/nfnl.h>
18 #include <netlink/netfilter/log.h>
20 static struct nfnl_log *alloc_log(
void)
24 log = nfnl_log_alloc();
31 static void obj_input(
struct nl_object *obj,
void *arg)
42 static int event_input(
struct nl_msg *msg,
void *arg)
44 if (nl_msg_parse(msg, &obj_input, NULL) < 0)
45 fprintf(stderr,
"<<EVENT>> Unknown message type\n");
51 int main(
int argc,
char *argv[])
53 struct nl_sock *nf_sock;
54 struct nl_sock *rt_sock;
55 struct nl_cache *link_cache;
57 enum nfnl_log_copy_mode copy_mode;
62 nf_sock = nl_cli_alloc_socket();
66 if ((argc > 1 && !strcasecmp(argv[1],
"-h")) || argc < 3) {
67 printf(
"Usage: nf-log family group [ copy_mode ] "
72 nl_cli_connect(nf_sock, NETLINK_NETFILTER);
74 family = nl_str2af(argv[1]);
75 if (family == AF_UNSPEC)
77 argv[1], nl_geterror(family));
79 nfnl_log_pf_unbind(nf_sock, family);
80 if ((err = nfnl_log_pf_bind(nf_sock, family)) < 0)
85 nfnl_log_set_group(log, atoi(argv[2]));
87 copy_mode = NFNL_LOG_COPY_META;
89 copy_mode = nfnl_log_str2copy_mode(argv[3]);
92 "Unable to parse copy mode \"%s\": %s",
93 argv[3], nl_geterror(copy_mode));
95 nfnl_log_set_copy_mode(log, copy_mode);
99 copy_range = atoi(argv[4]);
100 nfnl_log_set_copy_range(log, copy_range);
102 if ((err = nfnl_log_create(nf_sock, log)) < 0)
110 .dp_dump_msgtype = 1,
113 printf(
"log params: ");
117 rt_sock = nl_cli_alloc_socket();
118 nl_cli_connect(rt_sock, NETLINK_ROUTE);
119 link_cache = nl_cli_link_alloc_cache(rt_sock);
123 int nffd, rtfd, maxfd, retval;
136 retval = select(maxfd+1, &rfds, NULL, NULL, NULL);
139 if (FD_ISSET(nffd, &rfds))
141 if (FD_ISSET(rtfd, &rfds))