From patchwork Tue Nov 7 11:02:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 835234 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="QQiKIBSZ"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="s0f2AX2M"; 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 3yWRPT6lzgz9t3h for ; Tue, 7 Nov 2017 22:03:41 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version: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=4EoPggPBQhtTgL85xghGTn9Lote1rq1T9K8dujlMJTY=; b=QQiKIBSZDzcpf7 fAVxBdqjSJc0OnvtuxoGFd83PIxGPT9opSr6yxVqTq29Q5sZgq1Ys8ZsgXlwZ4QUkXqYSTZojLkVb Zw2OdjK/tQ6kZhmaXeLg+G+7X8fCHbyBEeSjx0y1VkyyKmh7GBWR/JZfKFd2L2g46KNeDYx1eREnI D/a21hOXIC+eRw3I5sDnygIoQ6i0teciFJjOjaHH9x6nICKIqHovxOdRisHEvUWfzzMfJesRW/L1A gzIp7/hrAheEzd/yHzFYj5Gopv3GAduIEOM0ihmWuV7f+/YRtNrsRcHh3p/d9SBpZJ0+yRjRu5eCH NKC6YR0MVuLuv3+hVrmw==; 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 1eC1fO-0000E2-Ln; Tue, 07 Nov 2017 11:03:38 +0000 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eC1fJ-00007J-Vu for lede-dev@lists.infradead.org; Tue, 07 Nov 2017 11:03:36 +0000 Received: by mail-lf0-x241.google.com with SMTP id k40so13966087lfi.4 for ; Tue, 07 Nov 2017 03:03:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=mwDQwvZK9EZcAO/lG2oYU2qOZo0Qv0AFQkWXuOq39rg=; b=s0f2AX2MECoEptlbByGDFRrZv2oPlOlBhwO2/D2rnTl8SUF2GhDUUtoBJxhytKLbyY JXJ7jCGpyzOLrciXIxtnAfAswM5FzLmFQC6Esetkrj2lIUCthHTifx4F4DhngPP0e72y F+3iyOZfpSU6Mv7JHZLMEyMn4FBmOLr5s0Xe3302Zgp2rq5/TmUQIeN1IBHnDY3AZYEE f53wdpH+vaKjJJBN5y5K7GYh7G3Q9S/grXYkNDmKrFEXdvpBrLlpWhDRJdYTWzhc0pSX AM6i+I3m29ve961lASVd3IbsX3qkjxdJTkQoe+iGMGhPgM89TeIeoI6mJBQmZgEzb2FA vNxg== 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:mime-version :content-transfer-encoding; bh=mwDQwvZK9EZcAO/lG2oYU2qOZo0Qv0AFQkWXuOq39rg=; b=haj0lx2Dp9qdMvROfTKWhDZPnJXeQcOBK60GF1WIXaEYi8G16jwnkFnuQgsDBOHkVO Sj9wsgF+s90b8gtECIm2WDpxpyqoJiEneg+lc5RZtw4JTEnWAeVEAxuCLeiroSsoohkj VHSHPFJ3vYfQK6xxLtfPYisa+K8ysogTf7fB3Q0PWEnB4priOnIG7zFuNIAvPv+3R2kG v3/Dd290YSd2bwqxojtnA+V90OjdMo7rJYc26Q+KxF/1U7rya0rkZfNs3tLM96y3chzw Y0H3IXxx0JcOCig+7OLH+E1SrLmxuPE6fE2biyavhiTj9XejkiG3eHmGBhh/nTtBphfE fbMA== X-Gm-Message-State: AJaThX4Lu/yNyxxxqCsuQrI1lULbxImzhxpo8yPa4AZ/i+HMrkbbhade e+P5I3CI02Oh2dwpt0ji2DU= X-Google-Smtp-Source: ABhQp+Su9p0/786jJUtfIEVMtOvu9CMOUi9ph6JEJVJ5bIkhAixLTCrGgvGzMw6nSUeqVJZEYXCgJA== X-Received: by 10.25.147.209 with SMTP id w78mr7346808lfk.169.1510052591363; Tue, 07 Nov 2017 03:03:11 -0800 (PST) Received: from linux-samsung.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id q88sm171114lfi.14.2017.11.07.03.03.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Nov 2017 03:03:10 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Luka Perkov Date: Tue, 7 Nov 2017 12:02:53 +0100 Message-Id: <20171107110253.31718-1-zajec5@gmail.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171107_030334_361896_A06C851B X-CRM114-Status: UNSURE ( 9.50 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -1.8 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:4010:c07:0:0:0:241 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (zajec5[at]gmail.com) 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (zajec5[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain Subject: [LEDE-DEV] [PATCH packages] rpcd-mod-lxc: add "info" ubus method (similar to the lxc-info) 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: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , openwrt-devel@lists.openwrt.org, lede-dev@lists.infradead.org Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Rafał Miłecki This method allows getting basic info about a queried container. It's based on the lxc-info command-line tool. Example output: > ubus call lxc info '{ "name": "foo" }' { "name": "foo", "state": "RUNNING", "pid": 2946, "ips": [ "192.168.0.124" ] } Signed-off-by: Rafał Miłecki --- utils/rpcd-mod-lxc/files/lxc.c | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/utils/rpcd-mod-lxc/files/lxc.c b/utils/rpcd-mod-lxc/files/lxc.c index 0d52f167..6db1b311 100644 --- a/utils/rpcd-mod-lxc/files/lxc.c +++ b/utils/rpcd-mod-lxc/files/lxc.c @@ -317,6 +317,48 @@ out: } static int +rpc_lxc_info(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct blob_attr *tb[__RPC_LXC_RENAME_MAX]; + struct rpc_lxc *l = NULL; + char **addresses; + void *k; + pid_t initpid; + + blobmsg_parse(rpc_lxc_min_policy, __RPC_LXC_MAX, tb, blob_data(msg), blob_len(msg)); + + l = rpc_lxc_init(tb); + if (!l) + return UBUS_STATUS_INVALID_ARGUMENT; + blob_buf_init(&buf, 0); + + blobmsg_add_string(&buf, "name", l->container->name); + + blobmsg_add_string(&buf, "state", l->container->state(l->container)); + + initpid = l->container->init_pid(l->container); + if (initpid >= 0) + blobmsg_add_u32(&buf, "pid", initpid); + + k = blobmsg_open_array(&buf, "ips"); + addresses = l->container->get_ips(l->container, NULL, NULL, 0); + if (addresses) { + int i; + + for (i = 0; addresses[i]; i++) + blobmsg_add_string(&buf, "ip", addresses[i]); + } + blobmsg_close_array(&buf, k); + + ubus_send_reply(ctx, req, buf.head); + rpc_lxc_done(l); + + return UBUS_STATUS_OK; +} + +static int rpc_lxc_rename(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) @@ -480,6 +522,7 @@ rpc_lxc_api_init(const struct rpc_daemon_ops *o, struct ubus_context *ctx) UBUS_METHOD("stop", rpc_lxc_stop, rpc_lxc_min_policy), UBUS_METHOD("freeze", rpc_lxc_freeze, rpc_lxc_min_policy), UBUS_METHOD("unfreeze", rpc_lxc_unfreeze, rpc_lxc_min_policy), + UBUS_METHOD("info", rpc_lxc_info, rpc_lxc_min_policy), UBUS_METHOD("rename", rpc_lxc_rename, rpc_lxc_rename_policy), UBUS_METHOD("create", rpc_lxc_create, rpc_lxc_create_policy), UBUS_METHOD("destroy", rpc_lxc_destroy, rpc_lxc_min_policy),