Linux Netfilter development
 help / color / mirror / Atom feed
From: Eric Leblond <eric@inl.fr>
To: netfilter-devel@vger.kernel.org
Cc: Eric Leblond <eric@inl.fr>
Subject: [ULOGD PATCH 05/14] New MAC2STR plugin for hwmac address conversion.
Date: Sun, 23 Mar 2008 17:25:13 +0100	[thread overview]
Message-ID: <12062895232654-git-send-email-eric@inl.fr> (raw)
In-Reply-To: <1206289522679-git-send-email-eric@inl.fr>

This patch introduces a new plugin MAC2STR which is in charge
of conversion to string of MAC address. It is used by database
output plugin to store MAC related information.

Signed-off-by: Eric Leblond <eric@inl.fr>
---
 filter/Makefile.am            |    6 ++-
 filter/ulogd_filter_MAC2STR.c |  111 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 116 insertions(+), 1 deletions(-)
 create mode 100644 filter/ulogd_filter_MAC2STR.c

diff --git a/filter/Makefile.am b/filter/Makefile.am
index 52b639c..958a5de 100644
--- a/filter/Makefile.am
+++ b/filter/Makefile.am
@@ -4,7 +4,8 @@ INCLUDES = $(all_includes) -I$(top_srcdir)/include
 
 pkglib_LTLIBRARIES = ulogd_filter_IFINDEX.la ulogd_filter_PWSNIFF.la \
 		     ulogd_filter_PRINTPKT.la ulogd_filter_PRINTFLOW.la \
-		     ulogd_filter_IP2STR.la ulogd_filter_IP2BIN.la
+		     ulogd_filter_IP2STR.la ulogd_filter_IP2BIN.la \
+		     ulogd_filter_MAC2STR.la
 
 ulogd_filter_IFINDEX_la_SOURCES = ulogd_filter_IFINDEX.c
 ulogd_filter_IFINDEX_la_LDFLAGS = -module -lnfnetlink
@@ -18,6 +19,9 @@ ulogd_filter_IP2STR_la_LDFLAGS = -module
 ulogd_filter_IP2BIN_la_SOURCES = ulogd_filter_IP2BIN.c
 ulogd_filter_IP2BIN_la_LDFLAGS = -module
 
+ulogd_filter_MAC2STR_la_SOURCES = ulogd_filter_MAC2STR.c
+ulogd_filter_MAC2STR_la_LDFLAGS = -module
+
 ulogd_filter_PRINTPKT_la_SOURCES = ulogd_filter_PRINTPKT.c ../util/printpkt.c
 ulogd_filter_PRINTPKT_la_LDFLAGS = -module
 
diff --git a/filter/ulogd_filter_MAC2STR.c b/filter/ulogd_filter_MAC2STR.c
new file mode 100644
index 0000000..38d0565
--- /dev/null
+++ b/filter/ulogd_filter_MAC2STR.c
@@ -0,0 +1,111 @@
+/* ulogd_filter_MAC2STR.c, Version $Revision: 1500 $
+ *
+ * ulogd interpreter plugin for HWMAC
+ *
+ * (C) 2008 by Eric Leblond <eric@inl.fr>
+ *
+ * Based on ulogd_filter_IFINDEX.c Harald Welte <laforge@gnumonks.org>
+ *
+ *  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
+ *
+ * $Id: ulogd_filter_IFINDEX.c 1500 2005-10-03 16:54:02Z laforge $
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <arpa/inet.h>
+#include <ulogd/ulogd.h>
+
+#define IPADDR_LENGTH 128
+
+enum input_keys {
+	KEY_RAW_MAC,
+	KEY_RAW_MACLEN,
+};
+
+enum output_keys {
+	KEY_MAC_SADDR,
+};
+
+static struct ulogd_key mac2str_inp[] = {
+	[KEY_RAW_MAC] = {
+		.type = ULOGD_RET_RAW,
+		.flags = ULOGD_RETF_NONE,
+		.name = "raw.mac",
+	},
+	[KEY_RAW_MACLEN] = { 
+		.type = ULOGD_RET_UINT16, 
+		.flags = ULOGD_RETF_NONE, 
+		.name = "raw.mac_len", 
+	},
+
+};
+
+static struct ulogd_key mac2str_keys[] = {
+	{
+		.type = ULOGD_RET_STRING,
+		.flags = ULOGD_RETF_FREE,
+		.name = "mac.saddr.str",
+	},
+};
+
+static int interp_mac2str(struct ulogd_pluginstance *pi)
+{
+	struct ulogd_key *ret = pi->output.keys;
+	struct ulogd_key *inp = pi->input.keys;
+
+	if (pp_is_valid(inp, KEY_RAW_MAC)) {
+		unsigned char *mac = (unsigned char *) GET_VALUE(inp, KEY_RAW_MAC).ptr;
+		int len = GET_VALUE(inp, KEY_RAW_MACLEN).ui16;
+		char *mac_str = calloc(len/sizeof(char)*3, sizeof(char));
+		char *buf_cur = mac_str;
+		int i;
+		
+		if (mac_str == NULL)
+			return -1;
+
+		for (i = 0; i < len; i++)
+			buf_cur += sprintf(buf_cur, "%02x%c", mac[i],
+					   i == len - 1 ? 0 : ':');
+
+		ret[KEY_MAC_SADDR].u.value.ptr = mac_str;
+		ret[KEY_MAC_SADDR].flags |= ULOGD_RETF_VALID;
+	}
+
+	return 0;
+}
+
+static struct ulogd_plugin mac2str_pluging = {
+	.name = "MAC2STR",
+	.input = {
+		.keys = mac2str_inp,
+		.num_keys = ARRAY_SIZE(mac2str_inp),
+		.type = ULOGD_DTYPE_PACKET,
+		},
+	.output = {
+		.keys = mac2str_keys,
+		.num_keys = ARRAY_SIZE(mac2str_keys),
+		.type = ULOGD_DTYPE_PACKET,
+		},
+	.interp = &interp_mac2str,
+	.version = ULOGD_VERSION,
+};
+
+void __attribute__ ((constructor)) init(void);
+
+void init(void)
+{
+	ulogd_register_plugin(&mac2str_pluging);
+}
-- 
1.5.2.5


  parent reply	other threads:[~2008-03-23 16:25 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-23 16:25 [ULOGD PATCH 0/14] Misc improvements and bugfixes Eric Leblond
2008-03-23 16:25 ` [ULOGD PATCH 01/14] Fix SQL reconnection algorithm Eric Leblond
2008-04-05 13:55   ` Pablo Neira Ayuso
2008-03-23 16:25 ` [ULOGD PATCH 02/14] Suppress ip_as_string configuration variable Eric Leblond
2008-04-05 15:05   ` Pablo Neira Ayuso
2008-04-05 19:00     ` Eric Leblond
2008-04-07 23:50       ` Pablo Neira Ayuso
2008-03-23 16:25 ` [ULOGD PATCH 03/14] Fix type of raw.mac_len key in NFLOG Eric Leblond
2008-04-05 14:30   ` Pablo Neira Ayuso
2008-03-23 16:25 ` [ULOGD PATCH 04/14] Fix type of raw.mac_len key in ULOG Eric Leblond
2008-04-05 14:33   ` Pablo Neira Ayuso
2008-03-23 16:25 ` Eric Leblond [this message]
2008-04-05 14:35   ` [ULOGD PATCH 05/14] New MAC2STR plugin for hwmac address conversion Pablo Neira Ayuso
2008-03-23 16:25 ` [ULOGD PATCH 06/14] MAC address handling in MySQL output plugin Eric Leblond
2008-04-05 14:51   ` Pablo Neira Ayuso
2008-04-05 19:03     ` Eric Leblond
2008-04-07 23:52       ` Pablo Neira Ayuso
2008-03-23 16:25 ` [ULOGD PATCH 07/14] MAC address handling in PgSQL " Eric Leblond
2008-04-05 14:52   ` Pablo Neira Ayuso
2008-03-23 16:25 ` [ULOGD PATCH 08/14] Add state option to NFLOG input plugin Eric Leblond
2008-04-05 15:10   ` Pablo Neira Ayuso
2008-04-05 19:15     ` Eric Leblond
2008-04-07 23:56       ` Pablo Neira Ayuso
2008-04-10  4:56         ` Eric Leblond
2008-04-13  7:03           ` Eric Leblond
2008-04-16 11:39             ` Pablo Neira Ayuso
2008-04-16 13:22               ` [ULOGD PATCH 0/7] Resend, add label to SQL logging Eric Leblond
2008-04-16 13:22               ` [ULOGD PATCH 1/7] Add label option to NFLOG input plugin Eric Leblond
2008-04-27  7:27                 ` Pablo Neira Ayuso
2008-04-27  8:44                   ` Eric Leblond
2008-04-28 13:44                     ` Pablo Neira Ayuso
2008-04-28 13:53                       ` [ULOGD PATCH 0/3] Resend: rename label to numeric_label Eric Leblond
2008-04-28 13:53                         ` [PATCH 1/3] Add numeric_label option to ULOG input plugin Eric Leblond
2008-04-28 13:53                           ` [PATCH 2/3] Add numeric_label option to NFLOG " Eric Leblond
2008-04-28 13:53                             ` [PATCH 3/3] Update default configuration to fit last changes Eric Leblond
2008-04-29 14:26                         ` [ULOGD PATCH 0/3] Resend: rename label to numeric_label Pablo Neira Ayuso
2008-04-16 13:22               ` [ULOGD PATCH 2/7] Add label support to MySQL schema Eric Leblond
2008-04-16 13:22               ` [ULOGD PATCH 3/7] Add label option to ULOG input plugin Eric Leblond
2008-04-16 13:22               ` [ULOGD PATCH 4/7] Add hook output to ULOG input module Eric Leblond
2008-04-16 13:22               ` [ULOGD PATCH 5/7] Add label support to PGSQL output module Eric Leblond
2008-04-16 13:22               ` [ULOGD PATCH 6/7] Update default configuration to fit last changes Eric Leblond
2008-04-16 13:22               ` [ULOGD PATCH 7/7] Convert SQL procedure to function in MySQL plugins Eric Leblond
2008-03-23 16:25 ` [ULOGD PATCH 09/14] Add state support to MySQL schema Eric Leblond
2008-03-23 16:25 ` [ULOGD PATCH 10/14] Add state option to ULOG input plugin Eric Leblond
2008-03-23 16:25 ` [ULOGD PATCH 11/14] Add hook output to ULOG input module Eric Leblond
2008-03-23 16:25 ` [ULOGD PATCH 12/14] Add state support to PGSQL output module Eric Leblond
2008-03-23 16:25 ` [ULOGD PATCH 13/14] Update default configuration to fit last changes Eric Leblond
2008-03-23 16:25 ` [ULOGD PATCH 14/14] Fix computation of length of mac address Eric Leblond
2008-04-05 14:56   ` Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=12062895232654-git-send-email-eric@inl.fr \
    --to=eric@inl.fr \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox