From patchwork Wed Oct 4 10:50:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Lebleu X-Patchwork-Id: 821259 X-Patchwork-Delegate: blogic@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="OmA2Dl23"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="slAvQzIN"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="hsyQjdjC"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3y6XvR5KGCz9t2h for ; Wed, 4 Oct 2017 21:58:43 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:Message-Id: Date:To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=uVmpB2aYv61320P36hUjqiGMJPwxjCTf15ToWxCCU/s=; b=OmA2Dl23GPcYpi aiHcVQXhqjbIyZU1E/RGK/bau46BpS3vSvQuWNK21arybeR4ZHBT7QmOJVQchVlQx8mrjtsyhxmbo E5IyWMy59kkLYOBzRbJuU2zzsjcOiqVqsORGrhif6dW4NxUVj03YQ6tXq0F/w5hpIWAJ8g1ilO5d/ uz9pT6CEOz8LKQZeI55hkcigYLpwTHdlmW89+p4geh3Kk6P7wtb76VWWaMG2NQO3BNMtlEtiToSd3 yCjcL0MtBrZCE6lSunhdeFgZsINCE8Gl+Uppc+y2wdPli6jf8XcMvfC3USJZaPCwgDsouWN7JW9aD sHR8fr0Jv7C9SeRcXWmQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dzhNs-0004gj-EX; Wed, 04 Oct 2017 10:58:36 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dzhNr-0004cg-3P for lede-dev@bombadil.infradead.org; Wed, 04 Oct 2017 10:58:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=84+iclQ2rB30u4Btqx35q9FNfSnmcxF8QsHniiQ+Gpk=; b=slAvQzINUuGvSoxET4sM2ozFw Rc4bwVX96Pem8S9CcOvZ4f6JYFPxVJ8L7HnhO3GRmheKaUHBQJ1T22f2MLeUEvvi3LIoGbaf3Xja3 MpjtV5F5psb4CnxoMbFHM62/uFWFGsijRHKBX7bI0qiFu5xdxbEnqOA7dsomVGD7sBll9UIZT2wL2 SpVY/RU17rOXrzW0YZpAvu1zwxNBjaWIVaJwWDpUYHaS6T652UKdmZhAkNShp/y+Nq6sRVm5XGwmo +DM8VSmDJty7aOnR2W1iyhxBfQEwGifmg1PGURc2bXJQDajBNjIZfwED5L4eqC7miIECiTbxD/HoQ YusHjCKPA==; Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dzhGt-0005XI-Va for lede-dev@lists.infradead.org; Wed, 04 Oct 2017 10:51:25 +0000 Received: by mail-wr0-x244.google.com with SMTP id z96so6444787wrb.0 for ; Wed, 04 Oct 2017 03:51:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=84+iclQ2rB30u4Btqx35q9FNfSnmcxF8QsHniiQ+Gpk=; b=hsyQjdjCPz/gkD0EO5+GQNx7JPR6zCx4ilnso223luWnhVCAHBK5itLbnMZHJNz15E K599DzkDM/ESb68IQ8bxJ9SJ/fuxTDUMq5TIRNXwICLkTozBAklDWrpHGKZmgIdQVkG0 5GGsAbTX+NhAszGSGD7pgYI7e7zq3I9w1t0B3Vrp1ZyinvKVTjIXypq5bhlsJS2IA2Cf zB6gGk93ppICVB0Zd19jzCBfhtpLZejQ1gl7Etfox/sw040DXINhHx2iZU/OU2zW/V/P PoNH/1h4SMIaCikS3V98ChsrINh2G68FxBn9uWVjFBCCJDVKORDrHEbBXk/GtUtD/VzU YXwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=84+iclQ2rB30u4Btqx35q9FNfSnmcxF8QsHniiQ+Gpk=; b=YFRZW5GTVhL4+dtH1EdcEba3+/YXoJnEVq/mihzUrqsAL3B3Cpt8dTVRaXy6W+viXr /abiWaJ5yVkPRGOYsFuUU0OrBaTJZs2puXbcRJNjBoPS8YlrL9991u7fYwSWFwm9+iT8 mjsJHtjwAhICv2Pcd3d4HoBGGQMOy89whiYSOHoQoYBkG+VgUzODfFwNNydqWtlNVQKX 6xMPHAwNywov7aJbNZhMl+KCZ1Z8O/vHupfbZwLDCaUvL9Rst7cAiVquzwJh0pioWuP3 SruYd4W00a8pxy7zDnkF2roBmWPv2hdopzkd0TS/t2pM8Qk2ei+RQq3TYI/Ye+GChghw 0e2g== X-Gm-Message-State: AMCzsaXoZVOBpVLBny43nw6W5vNhcQeJiRlyJufCcVFDu0Vdje+zafhK F6z6E5iVWlWrxnzc/kcs+eyF1Q== X-Google-Smtp-Source: AOwi7QBxGvbtC56dr1qExUNuS1VIUBU4GdLnOze7ipeezMX6x45PsUXMoYaxOBtRlvsqKofwRB/x1w== X-Received: by 10.223.158.8 with SMTP id u8mr6664278wre.16.1507114262290; Wed, 04 Oct 2017 03:51:02 -0700 (PDT) Received: from cplx1045.edegem.eu.thmulti.com (12.125.146.82.ipv4.evonet.be. [82.146.125.12]) by smtp.gmail.com with ESMTPSA id m138sm10141007wmd.29.2017.10.04.03.51.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 Oct 2017 03:51:01 -0700 (PDT) From: pme.lebleu@gmail.com To: lede-dev@lists.infradead.org Date: Wed, 4 Oct 2017 12:50:59 +0200 Message-Id: <1507114259-8698-1-git-send-email-pme.lebleu@gmail.com> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171004_115124_060381_2E5A57A2 X-CRM114-Status: GOOD ( 13.78 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.1 on casper.infradead.org summary: Content analysis details: (-2.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:400c:c0c:0:0:0:244 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (pme.lebleu[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Subject: [LEDE-DEV] [PATCH][RFC] procd: service: add data within the service itself X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pierre Lebleu MIME-Version: 1.0 Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Pierre Lebleu It gives the ability to create firewall data within the service itself rather than within an instance. Signed-off-by: Pierre Lebleu --- service/service.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- service/service.h | 2 ++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/service/service.c b/service/service.c index 9c798aa..595f6f7 100644 --- a/service/service.c +++ b/service/service.c @@ -84,6 +84,7 @@ service_alloc(const char *name) s->name = new_name; s->avl.key = s->name; INIT_LIST_HEAD(&s->validators); + blobmsg_list_simple_init(&s->data); return s; } @@ -95,6 +96,7 @@ enum { SERVICE_SET_TRIGGER, SERVICE_SET_VALIDATE, SERVICE_SET_AUTOSTART, + SERVICE_SET_DATA, __SERVICE_SET_MAX }; @@ -105,8 +107,20 @@ static const struct blobmsg_policy service_set_attrs[__SERVICE_SET_MAX] = { [SERVICE_SET_TRIGGER] = { "triggers", BLOBMSG_TYPE_ARRAY }, [SERVICE_SET_VALIDATE] = { "validate", BLOBMSG_TYPE_ARRAY }, [SERVICE_SET_AUTOSTART] = { "autostart", BLOBMSG_TYPE_BOOL }, + [SERVICE_SET_DATA] = { "data", BLOBMSG_TYPE_TABLE }, }; +static void +service_fill_any(struct blobmsg_list *l, struct blob_attr *cur) +{ + if (!cur) + return; + + DEBUG(2, "Add data for service\n"); + + blobmsg_list_fill(l, blobmsg_data(cur), blobmsg_data_len(cur), false); +} + static int service_update(struct service *s, struct blob_attr **tb, bool add) { @@ -148,6 +162,8 @@ service_update(struct service *s, struct blob_attr **tb, bool add) vlist_flush(&s->instances); } + service_fill_any(&s->data, tb[SERVICE_SET_DATA]); + s->deleted = false; rc(s->name, "running"); @@ -159,6 +175,7 @@ static void service_delete(struct service *s) { vlist_flush_all(&s->instances); + blobmsg_list_free(&s->data); s->deleted = true; service_stopped(s); } @@ -316,6 +333,13 @@ service_dump(struct service *s, bool verbose) blobmsg_add_blob(&b, s->trigger); if (verbose && !list_empty(&s->validators)) service_validate_dump(&b, s); + if (!avl_is_empty(&s->data.avl)) { + struct blobmsg_list_node *var; + void *e = blobmsg_open_table(&b, "data"); + blobmsg_list_for_each(&s->data, var) + blobmsg_add_blob(&b, var->data); + blobmsg_close_table(&b, e); + } blobmsg_close_table(&b, c); } @@ -598,13 +622,30 @@ service_get_data(struct ubus_context *ctx, struct ubus_object *obj, blob_buf_init(&b, 0); avl_for_each_element(&services, s, avl) { void *cs = NULL; + void *ci = NULL; + struct blobmsg_list_node *var; if (name && strcmp(name, s->name)) continue; + blobmsg_list_for_each(&s->data, var) { + if (type && strcmp(blobmsg_name(var->data), type)) + continue; + + if (!cs) + cs = blobmsg_open_table(&b, s->name); + + if (!ci) + ci = blobmsg_open_table(&b, "*"); + + blobmsg_add_blob(&b, var->data); + } + + if (ci) + blobmsg_close_table(&b, ci), ci = NULL; + vlist_for_each_element(&s->instances, in, node) { - struct blobmsg_list_node *var; - void *ci = NULL; + ci = NULL; if (instance && strcmp(instance, in->name)) continue; diff --git a/service/service.h b/service/service.h index a433c9f..15333c4 100644 --- a/service/service.h +++ b/service/service.h @@ -18,6 +18,7 @@ #include #include #include +#include "../utils/utils.h" extern struct avl_tree services; @@ -46,6 +47,7 @@ struct service { struct blob_attr *trigger; struct vlist_tree instances; struct list_head validators; + struct blobmsg_list data; }; void service_validate_add(struct service *s, struct blob_attr *attr);