From patchwork Sat Mar 2 06:58:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Goldstein X-Patchwork-Id: 224466 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 DD2602C02C2 for ; Sat, 2 Mar 2013 17:59:34 +1100 (EST) Received: from localhost ([::1]:58165 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBgPt-0003fR-6j for incoming@patchwork.ozlabs.org; Sat, 02 Mar 2013 01:59:33 -0500 Received: from eggs.gnu.org ([208.118.235.92]:36684) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBgPP-0003Il-K9 for qemu-devel@nongnu.org; Sat, 02 Mar 2013 01:59:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UBgPL-0003Mq-SJ for qemu-devel@nongnu.org; Sat, 02 Mar 2013 01:59:03 -0500 Received: from mail-gh0-f172.google.com ([209.85.160.172]:38986) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBgPL-0003Mk-OU for qemu-devel@nongnu.org; Sat, 02 Mar 2013 01:58:59 -0500 Received: by mail-gh0-f172.google.com with SMTP id z22so599437ghb.3 for ; Fri, 01 Mar 2013 22:58:59 -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=YFBmTzrake5IBJSSJxFDWuMqns8j+0W1Shrd7gkzka0=; b=ke/6BAxZTVMKroNi79actL3gh23IhVxYeKxL5OSp/t6inEX/rXzXnvkWFJwhv10gn0 sVqJ4So2txLVduOXXFxl54gZ+dR02Viqb0pYqptSXhlkPJ3PyGJuahK/hRRQLfl67h3r vRzu/kgxkDXPAs8NGI+e9z5le5ZU5jfHnDNSEz7NuB58dS0UZCE1I04wSA/JHGKHSBm4 /ZG7PBD9IDf2c/7Xvy4+aj1mnl9RbpZ+EQizm9DPbSC6/ruJmQWAQVnMqHh2T51alyX+ ksrnNgrwSe4l8T5pCjxg9lDcHCyyZ+0/M1O2e+UHM9lHZKBxQ15aaVSfWGTwrIkz1uS9 45ew== X-Received: by 10.236.191.202 with SMTP id g50mr9473979yhn.171.1362207539239; Fri, 01 Mar 2013 22:58:59 -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 s34sm23304914yhe.9.2013.03.01.22.58.58 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 01 Mar 2013 22:58:58 -0800 (PST) From: Doug Goldstein To: qemu-devel@nongnu.org Date: Sat, 2 Mar 2013 00:58:48 -0600 Message-Id: <1362207528-27804-3-git-send-email-cardoe@cardoe.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1362207528-27804-1-git-send-email-cardoe@cardoe.com> References: <1361757620-23318-1-git-send-email-cardoe@cardoe.com> <1362207528-27804-1-git-send-email-cardoe@cardoe.com> X-Gm-Message-State: ALoCoQk9fD/o3g/Nh4WEYSept1ScX2+82a5ZSD/ADxkCM68uxZbsoqJWuZoFFHWHgvmDU2YD8gau X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.160.172 Cc: Anthony Liguori , Corey Bryant , Doug Goldstein , Richa Marwaha Subject: [Qemu-devel] [PATCHv2 2/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 ee67740..39d343c 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,12 +71,27 @@ 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 len = strlen(entry->d_name); + + /* We only want files ending in .conf */ + if (len > 5 && + strcmp(".conf", &entry->d_name[len-5]) == 0) + return 1; + + return 0; +} + static int parse_acl_file(const char *filename, ACLList *acl_list) { FILE *f; char line[4096]; int ret = -EINVAL; ACLRule *acl_rule; + struct dirent **include_list = NULL; + int i, include_count = 0; + char *conf_file; f = fopen(filename, "r"); if (f == NULL) { @@ -137,6 +153,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, alphasort); + if (include_count < 0) { + ret = -errno; + fprintf(stderr, "Unable to retrieve conf files from '%s': %s\n", + arg, strerror(errno)); + goto failure; + } + + 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); + ret = -ENOMEM; + goto failure; + } + + /* ignore errors like 'include' cmd */ + 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); @@ -152,6 +199,14 @@ static int parse_acl_file(const char *filename, ACLList *acl_list) failure: fclose(f); + if (include_list) { + for (i = 0; i < include_count; i++) { + if (include_list[i]) + free(include_list[i]); + } + free(include_list); + } + return ret; }