From patchwork Sat Jul 28 17:21:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Engelhardt X-Patchwork-Id: 173881 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 592B22C007E for ; Sun, 29 Jul 2012 03:21:56 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752983Ab2G1RVu (ORCPT ); Sat, 28 Jul 2012 13:21:50 -0400 Received: from seven.medozas.de ([5.9.24.206]:34349 "EHLO seven.medozas.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752985Ab2G1RVR (ORCPT ); Sat, 28 Jul 2012 13:21:17 -0400 Received: by seven.medozas.de (Postfix, from userid 25121) id 60DCC96A02C1; Sat, 28 Jul 2012 19:21:13 +0200 (CEST) From: Jan Engelhardt To: pablo@netfilter.org Cc: netfilter-devel@vger.kernel.org Subject: [PATCH 4/7] libxt_devgroup: consolidate devgroup specification parsing Date: Sat, 28 Jul 2012 19:21:06 +0200 Message-Id: <1343496069-5442-5-git-send-email-jengelh@inai.de> X-Mailer: git-send-email 1.7.7 In-Reply-To: <1343496069-5442-1-git-send-email-jengelh@inai.de> References: <1343496069-5442-1-git-send-email-jengelh@inai.de> Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org This is a small cleanup, reducing the two copies of X/Y parsing to one. Signed-off-by: Jan Engelhardt --- extensions/libxt_devgroup.c | 70 ++++++++++++++++++------------------------ 1 files changed, 30 insertions(+), 40 deletions(-) diff --git a/extensions/libxt_devgroup.c b/extensions/libxt_devgroup.c index 4487c83..69ae279 100644 --- a/extensions/libxt_devgroup.c +++ b/extensions/libxt_devgroup.c @@ -42,58 +42,48 @@ static void devgroup_init(struct xt_entry_match *match) fprintf(stderr, "Warning: %s: %s\n", file, strerror(errno)); } +static void devgroup_parse_groupspec(const char *arg, unsigned int *group, + unsigned int *mask) +{ + char *end; + + *group = strtoul(arg, &end, 0); + if (end != arg && (*end == '/' || *end == '\0')) { + if (*end == '/') + *mask = strtoul(end + 1, &end, 0); + else + *mask = ~0U; + if (*end != '\0' || end == arg) + xtables_error(PARAMETER_PROBLEM, + "Bad group value \"%s\"", arg); + } else { + *group = xtables_lmap_name2id(devgroups, arg); + if (*group == -1) + xtables_error(PARAMETER_PROBLEM, + "Device group \"%s\" not found", arg); + *mask = ~0U; + } +} + static void devgroup_parse(struct xt_option_call *cb) { struct xt_devgroup_info *info = cb->data; - unsigned int id; - char *end; + unsigned int id, mask; xtables_option_parse(cb); switch (cb->entry->id) { case O_SRC_GROUP: - info->src_group = strtoul(cb->arg, &end, 0); - if (end != cb->arg && (*end == '/' || *end == '\0')) { - if (*end == '/') - info->src_mask = strtoul(end+1, &end, 0); - else - info->src_mask = 0xffffffff; - if (*end != '\0' || end == cb->arg) - xtables_error(PARAMETER_PROBLEM, - "Bad src-group value `%s'", - cb->arg); - } else { - id = xtables_lmap_name2id(devgroups, cb->arg); - if (id == -1) - xtables_error(PARAMETER_PROBLEM, - "Device group `%s' not found", - cb->arg); - info->src_group = id; - info->src_mask = 0xffffffff; - } + devgroup_parse_groupspec(cb->arg, &id, &mask); + info->src_group = id; + info->src_mask = mask; info->flags |= XT_DEVGROUP_MATCH_SRC; if (cb->invert) info->flags |= XT_DEVGROUP_INVERT_SRC; break; case O_DST_GROUP: - info->dst_group = strtoul(cb->arg, &end, 0); - if (end != cb->arg && (*end == '/' || *end == '\0')) { - if (*end == '/') - info->dst_mask = strtoul(end+1, &end, 0); - else - info->dst_mask = 0xffffffff; - if (*end != '\0' || end == cb->arg) - xtables_error(PARAMETER_PROBLEM, - "Bad dst-group value `%s'", - cb->arg); - } else { - id = xtables_lmap_name2id(devgroups, cb->arg); - if (id == -1) - xtables_error(PARAMETER_PROBLEM, - "Device group `%s' not found", - cb->arg); - info->dst_group = id; - info->dst_mask = 0xffffffff; - } + devgroup_parse_groupspec(cb->arg, &id, &mask); + info->dst_group = id; + info->dst_mask = mask; info->flags |= XT_DEVGROUP_MATCH_DST; if (cb->invert) info->flags |= XT_DEVGROUP_INVERT_DST;