From patchwork Sat Mar 29 04:29:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken-ichirou MATSUZAWA X-Patchwork-Id: 334928 X-Patchwork-Delegate: regit@netfilter.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id A67681400AD for ; Sat, 29 Mar 2014 15:29:24 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750928AbaC2E3Y (ORCPT ); Sat, 29 Mar 2014 00:29:24 -0400 Received: from mail-pd0-f172.google.com ([209.85.192.172]:65097 "EHLO mail-pd0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750713AbaC2E3X (ORCPT ); Sat, 29 Mar 2014 00:29:23 -0400 Received: by mail-pd0-f172.google.com with SMTP id p10so5694226pdj.3 for ; Fri, 28 Mar 2014 21:29:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=htyc4hbI8U8HwP5j0oxC9tqK8vgqZJpBckeHYtofMV4=; b=Gkis/7pz4jfXJT0ELsRRyUZBDLYTZgDJM/laepwdKUHKkeIsUlq3XxNtJm6DsXLdYP 0SogxKT0ovU0PCdA2ylcFy5zNWTDtqg2tJEiP+WEYVAtFb/wULbMs/kgdmGDB9HFSwGw 6Gcwc/RNHU+IXkEE34HWx5DeckDfsGUZl5Jcp4aj5RCMI19xBxPrrSo+VYPymhJ3VXLF ZtpDP9o/hD7zgFHA0HEinNazJUzzKcTjYE+07wo4nyeyH5MIfbtofXXdCvFQgkZlNax1 bfWX0w8I+hLo9pqBKBSFBk3LrppcDKD6St3c4KMUjtk3Rr8ozdpm9PCBemHrCWGBSClA 3Svw== X-Received: by 10.68.229.106 with SMTP id sp10mr12548554pbc.23.1396067362800; Fri, 28 Mar 2014 21:29:22 -0700 (PDT) Received: from gmail.com (KD106159154146.ppp-bb.dion.ne.jp. [106.159.154.146]) by mx.google.com with ESMTPSA id pi1sm5368884pac.14.2014.03.28.21.29.19 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 28 Mar 2014 21:29:21 -0700 (PDT) Date: Sat, 29 Mar 2014 13:29:15 +0900 From: Ken-ichirou MATSUZAWA To: The netfilter developer mailinglist Cc: Eric Leblond Subject: [ulogd RFC PATCH 2/2] ip2str: introduce changable address separator Message-ID: <20140329042915.GC22821@gmail.com> References: <20140329042336.GA22821@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20140329042336.GA22821@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org This patch make change address string separator by "v4sep" or "v6sep" in config file, because graphite uses `.' as path separator and statsd uses `:' as path and value separator. Now I am testing ulogd and statsd (actually statsite) using ulogd config: stack=ct1:NFCT,ip2str1:IP2STR,sprint:SPRINT [ct1] # in event mode, NF_NETLINK_CONNTRACK_DESTROY only event_mask=4 [ip2str1] v4sep="_" v6sep="_" [sprint] form="myrouter...(||unknown).: + \|kv\n" proto="tcp" dest="8125@192.168.1.1" Signed-off-by: Ken-ichirou MATSUZAWA --- filter/ulogd_filter_IP2STR.c | 74 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/filter/ulogd_filter_IP2STR.c b/filter/ulogd_filter_IP2STR.c index 732e1ef..774b9cf 100644 --- a/filter/ulogd_filter_IP2STR.c +++ b/filter/ulogd_filter_IP2STR.c @@ -137,10 +137,55 @@ static struct ulogd_key ip2str_keys[] = { }, }; +enum ip2str_conf { + IP2STR_CONF_V6SEP = 0, + IP2STR_CONF_V4SEP, + IP2STR_CONF_MAX +}; + +static struct config_keyset ip2str_config_kset = { + .num_ces = 2, + .ces = { + [IP2STR_CONF_V6SEP] = { + .key = "v6sep", + .type = CONFIG_TYPE_STRING, + .options = CONFIG_OPT_NONE, + .u = {.string = ":"}, + }, + [IP2STR_CONF_V4SEP] = { + .key = "v4sep", + .type = CONFIG_TYPE_STRING, + .options = CONFIG_OPT_NONE, + .u = {.string = "."}, + }, + }, +}; + +#define v6sep_ce(x) (x->ces[IP2STR_CONF_V6SEP]) +#define v4sep_ce(x) (x->ces[IP2STR_CONF_V4SEP]) + static char ipstr_array[MAX_KEY-START_KEY][IPADDR_LENGTH]; -static int ip2str(struct ulogd_key *inp, int index, int oindex) +void change_separator(char family, char *addr, char to) { + char from; + char *cur; + + switch(family) { + case AF_INET6: from = ':'; break; + case AF_INET: from = '.'; break; + default: + ulogd_log(ULOGD_NOTICE, "Unknown protocol family\n"); + return; + } + + for (cur = strchr(addr, from); cur != NULL; cur = strchr(cur + 1, from)) + *cur = to; +} + +static int ip2str(struct ulogd_pluginstance *upi, int index, int oindex) +{ + struct ulogd_key *inp = upi->input.keys; char family = ikey_get_u8(&inp[KEY_OOB_FAMILY]); char convfamily = family; @@ -173,11 +218,17 @@ static int ip2str(struct ulogd_key *inp, int index, int oindex) inet_ntop(AF_INET6, ikey_get_u128(&inp[index]), ipstr_array[oindex], sizeof(ipstr_array[oindex])); + if (*v6sep_ce(upi->config_kset).u.string != ':') + change_separator(convfamily, ipstr_array[oindex], + *v6sep_ce(upi->config_kset).u.string); break; case AF_INET: ip = ikey_get_u32(&inp[index]); inet_ntop(AF_INET, &ip, ipstr_array[oindex], sizeof(ipstr_array[oindex])); + if (*v4sep_ce(upi->config_kset).u.string != '.') + change_separator(convfamily, ipstr_array[oindex], + *v4sep_ce(upi->config_kset).u.string); break; default: /* TODO error handling */ @@ -197,7 +248,7 @@ static int interp_ip2str(struct ulogd_pluginstance *pi) /* Iter on all addr fields */ for (i = START_KEY; i <= MAX_KEY; i++) { if (pp_is_valid(inp, i)) { - fret = ip2str(inp, i, i-START_KEY); + fret = ip2str(pi, i, i-START_KEY); if (fret != ULOGD_IRET_OK) return fret; okey_set_ptr(&ret[i-START_KEY], @@ -208,6 +259,23 @@ static int interp_ip2str(struct ulogd_pluginstance *pi) return ULOGD_IRET_OK; } +static int configure_ip2str(struct ulogd_pluginstance *upi, + struct ulogd_pluginstance_stack *stack) +{ + int ret = config_parse_file(upi->id, upi->config_kset); + + if (ret < 0) + return ret; + + if (strlen(v6sep_ce(upi->config_kset).u.string) > 1) + ulogd_log(ULOGD_NOTICE, "only one char v6 separator is allowed," + " using: %c\n", *v6sep_ce(upi->config_kset).u.string); + if (strlen(v4sep_ce(upi->config_kset).u.string) > 1) + ulogd_log(ULOGD_NOTICE, "only one char v4 separator is allowed," + " using: %c\n", *v4sep_ce(upi->config_kset).u.string); + return ret; +} + static struct ulogd_plugin ip2str_pluging = { .name = "IP2STR", .input = { @@ -220,7 +288,9 @@ static struct ulogd_plugin ip2str_pluging = { .num_keys = ARRAY_SIZE(ip2str_keys), .type = ULOGD_DTYPE_PACKET | ULOGD_DTYPE_FLOW, }, + .config_kset = &ip2str_config_kset, .interp = &interp_ip2str, + .configure = &configure_ip2str, .version = VERSION, };