From patchwork Mon Feb 25 02:00:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Goldstein X-Patchwork-Id: 222817 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EC8CC2C00DC for ; Mon, 25 Feb 2013 13:01:19 +1100 (EST) Received: from localhost ([::1]:59406 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9nNW-0004Dd-4x for incoming@patchwork.ozlabs.org; Sun, 24 Feb 2013 21:01:18 -0500 Received: from eggs.gnu.org ([208.118.235.92]:59496) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9nN2-00031G-91 for qemu-devel@nongnu.org; Sun, 24 Feb 2013 21:00:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U9nMy-0003OG-2E for qemu-devel@nongnu.org; Sun, 24 Feb 2013 21:00:47 -0500 Received: from mail-yh0-x235.google.com ([2607:f8b0:4002:c01::235]:46377) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9nMx-0003OC-UE for qemu-devel@nongnu.org; Sun, 24 Feb 2013 21:00:43 -0500 Received: by mail-yh0-f53.google.com with SMTP id q3so419209yhf.26 for ; Sun, 24 Feb 2013 18:00:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=IN1/Ca0M3GjFr7LaZGut7Ptepqm9vDSLFQCTuU4XVXM=; b=L1zfRT4Eo3kPtiiYsAsLn40FAHHLvbngwZodon1V+5USUQINytGxkxSTpnu9L7kBDM U9PQGDvMhnX6E/H20+93/t/56yaq6eii6UmzezEY1E0ZdL4Jlp+UotzqLyftw6HbVYyx /IoH1KEmw/Tb1xXTooCvj+Yj2C8RvQHk0WjYEm4Hp88AUfJHvl6cgr/jktHQHx2jW5A3 fYqhLRjiRs4bq27i24xU5b4d3GFnsMfwz1HeJWhsjaeliP/4tx1Lb639pXBE3rXgK8Up ZMriIWJVT4l+Q9Fi2rkc8gwu6KSFmzPAwawrcoDzD2sCWRjKSm2cTyTlaoGX6vpIXYYf jhKA== X-Received: by 10.236.86.200 with SMTP id w48mr17603551yhe.5.1361757643378; Sun, 24 Feb 2013 18:00:43 -0800 (PST) Received: from localhost.localdomain (c-68-62-173-137.hsd1.al.comcast.net. [68.62.173.137]) by mx.google.com with ESMTPS id s34sm22916600yhe.9.2013.02.24.18.00.42 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 24 Feb 2013 18:00:42 -0800 (PST) From: Doug Goldstein To: qemu-devel@nongnu.org Date: Sun, 24 Feb 2013 20:00:19 -0600 Message-Id: <1361757620-23318-2-git-send-email-cardoe@cardoe.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1361757620-23318-1-git-send-email-cardoe@cardoe.com> References: <1361757620-23318-1-git-send-email-cardoe@cardoe.com> X-Gm-Message-State: ALoCoQnnmwooNma2GpZqEwL47t7KTuM9CedOBmX2czxVOKw3dGdLNAVgpcJhOqkYugYVEBTfVUER X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4002:c01::235 Cc: Anthony Liguori , Corey Bryant , Doug Goldstein , Richa Marwaha Subject: [Qemu-devel] [PATCH 1/2] bridge helper: support conf dirs X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Allow the bridge helper to take a config directory rather than having to specify every file in the directory manually via an include statement. Signed-off-by: Doug Goldstein CC: Anthony Liguori CC: Richa Marwaha CC: Corey Bryant TO: qemu-devel@nongnu.org --- qemu-bridge-helper.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/qemu-bridge-helper.c b/qemu-bridge-helper.c index 287bfd5..b8771a3 100644 --- a/qemu-bridge-helper.c +++ b/qemu-bridge-helper.c @@ -16,6 +16,7 @@ #include "config-host.h" #include +#include #include #include #include @@ -70,6 +71,26 @@ static void usage(void) "Usage: qemu-bridge-helper [--use-vnet] --br=bridge --fd=unixfd\n"); } +static int filter_bridge_conf_dir(const struct dirent *entry) +{ + ssize_t name_pos; + + /* We want to check the last 5 bytes for '.conf' */ + name_pos = strlen(entry->d_name) - 6; + + /* We need the file to at least be called 'a.conf' to make + * sense of this. + */ + if (name_pos < 1) + return 0; + + /* If the file didn't end in '.conf', skip it */ + if (strcmp(".conf", entry->d_name + name_pos)) + return 0; + + return 1; +} + static int parse_acl_file(const char *filename, ACLList *acl_list) { FILE *f; @@ -84,6 +105,9 @@ static int parse_acl_file(const char *filename, ACLList *acl_list) while (fgets(line, sizeof(line), f) != NULL) { char *ptr = line; char *cmd, *arg, *argend; + struct dirent **include_list = NULL; + int i, include_count; + char *conf_file; while (isspace(*ptr)) { ptr++; @@ -137,6 +161,37 @@ static int parse_acl_file(const char *filename, ACLList *acl_list) snprintf(acl_rule->iface, IFNAMSIZ, "%s", arg); } QSIMPLEQ_INSERT_TAIL(acl_list, acl_rule, entry); + } else if (strcmp(cmd, "includedir") == 0) { + include_count = scandir(arg, &include_list, + filter_bridge_conf_dir, NULL); + if (include_count < 0) { + fprintf(stderr, "Unable to retrieve conf files from '%s': %s\n", + arg, strerror(errno)); + fclose(f); + return -1; + } + + for (i = 0; i < include_count; i++) { + if (asprintf(&conf_file, "%s/%s", arg, + include_list[i]->d_name) < 0) { + fprintf(stderr, "Failed to allocate memory for " + "file path: %s/%s\n", + arg, include_list[i]->d_name); + fclose(f); + errno = ENOMEM; + return -1; + } + + parse_acl_file(conf_file, acl_list); + + free(conf_file); + free(include_list[i]); + include_list[i] = NULL; + } + free(include_list); + include_list = NULL; + include_count = 0; + } else if (strcmp(cmd, "include") == 0) { /* ignore errors */ parse_acl_file(arg, acl_list);