From 2eeba313a949d1a343912b547587e6d935fb8ffd Mon Sep 17 00:00:00 2001 From: "/C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=laforge/emailAddress=laforge@netfilter.org" Date: Thu, 28 Jul 2005 21:16:02 +0000 Subject: initial version --- src/Makefile.am | 15 ++++++ src/libipulog_compat.c | 0 src/libnfnetlink_log.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 src/Makefile.am create mode 100644 src/libipulog_compat.c create mode 100644 src/libnfnetlink_log.c (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..256770d --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,15 @@ +#AUTOMAKE_OPTIONS = no-dependencies foreign + +#EXTRA_DIST = $(man_MANS) acinclude.m4 + +INCLUDES=-I../include -I/lib/modules/$(shell (uname -r))/build/include +AM_CFLAGS=-fPIC -Wall +LIBS= + +lib_LTLIBRARIES = libnfnetlink_log.la libnfnetlink_log_libipulog.la + +libnfnetlink_log_la_LDFLAGS = -Wc,-nostartfiles +libnfnetlink_log_la_SOURCES = libnfnetlink_log.c + +libnfnetlink_log_libipulog_la_LDFLAGS = -Wc,-nostartfiles +libnfnetlink_log_libipulog_la_SOURCES = libipulog_compat.c diff --git a/src/libipulog_compat.c b/src/libipulog_compat.c new file mode 100644 index 0000000..e69de29 diff --git a/src/libnfnetlink_log.c b/src/libnfnetlink_log.c new file mode 100644 index 0000000..d62419a --- /dev/null +++ b/src/libnfnetlink_log.c @@ -0,0 +1,127 @@ +/* libnfqnetlink.c: generic library for access to nf_queue + * + * (C) 2005 by Harald Welte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "libnfnetlink_log.h" + +/*********************************************************************** + * low level stuff + ***********************************************************************/ + +int nfulnl_open(struct nfulnl_handle *h) +{ + int err; + + memset(h, 0, sizeof(*h)); + + err = nfnl_open(&h->nfnlh, NFNL_SUBSYS_ULOG, 0); + if (err < 0) + return err; + + return 0; +} + +int nfulnl_close(struct nfulnl_handle *h) +{ + return nfnl_close(&h->nfnlh); +} + +/* build a NFULNL_MSG_CONFIG message */ +static int +__build_send_cfg_msg(struct nfulnl_handle *h, u_int8_t command, + u_int16_t queuenum, u_int16_t pf) +{ + char buf[NLMSG_LENGTH(sizeof(struct nlmsghdr)) + +NLMSG_LENGTH(sizeof(struct nfgenmsg)) + +NFA_LENGTH(sizeof(struct nfulnl_msg_config_cmd))]; + struct nfulnl_msg_config_cmd cmd; + struct nlmsghdr *nmh = (struct nlmsghdr *) buf; + + nfnl_fill_hdr(&h->nfnlh, nmh, 0, AF_UNSPEC, queuenum, + NFULNL_MSG_CONFIG, NLM_F_REQUEST|NLM_F_ACK); + + cmd.command = command; + cmd.pf = htons(pf); + nfnl_addattr_l(nmh, sizeof(buf), NFULA_CFG_CMD, &cmd, sizeof(cmd)); + + return nfnl_send(&h->nfnlh, nmh); +} + +/* bind nf_queue from a specific protocol family */ +int nfulnl_bind_pf(struct nfulnl_handle *h, u_int16_t pf) +{ + return __build_send_cfg_msg(h, NFULNL_CFG_CMD_PF_BIND, 0, pf); +} + +/* unbind nf_queue from a specific protocol family */ +int nfulnl_unbind_pf(struct nfulnl_handle *h, u_int16_t pf) +{ + return __build_send_cfg_msg(h, NFULNL_CFG_CMD_PF_UNBIND, 0, pf); +} + +/* bind this socket to a specific queue number */ +int nfulnl_bind_group(struct nfulnl_handle *h, + struct nfulnl_g_handle *gh, u_int16_t num) +{ + gh->h = h; + gh->id = num; + + return __build_send_cfg_msg(h, NFULNL_CFG_CMD_BIND, num, 0); +} + +/* unbind this socket from a specific queue number */ +int nfulnl_unbind_group(struct nfulnl_g_handle *gh) +{ + int ret = __build_send_cfg_msg(gh->h, NFULNL_CFG_CMD_UNBIND, gh->id, 0); + if (ret == 0) + gh->h = NULL; + + return ret; +} + +int nfulnl_set_mode(struct nfulnl_g_handle *gh, + u_int8_t mode, u_int32_t range) +{ + char buf[NLMSG_LENGTH(sizeof(struct nlmsghdr)) + +NLMSG_LENGTH(sizeof(struct nfgenmsg)) + +NFA_LENGTH(sizeof(struct nfulnl_msg_config_params))]; + struct nfulnl_msg_config_params params; + struct nlmsghdr *nmh = (struct nlmsghdr *) buf; + + nfnl_fill_hdr(&gh->h->nfnlh, nmh, 0, AF_UNSPEC, gh->id, + NFULNL_MSG_CONFIG, NLM_F_REQUEST|NLM_F_ACK); + + params.copy_range = htonl(range); + params.copy_mode = mode; + nfnl_addattr_l(nmh, sizeof(buf), NFULA_CFG_PARAMS, ¶ms, + sizeof(params)); + + return nfnl_send(&gh->h->nfnlh, nmh); +} + -- cgit v1.2.3