From patchwork Tue Nov 28 14:08:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Borja Salazar X-Patchwork-Id: 842170 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="a6EYVP9O"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=fon-com.20150623.gappssmtp.com header.i=@fon-com.20150623.gappssmtp.com header.b="CpiCX1U9"; 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 3ymQX536Zyz9rxj for ; Wed, 29 Nov 2017 01:09:25 +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=FjfhvpgeaczW0nSPoEOkYEYWWXx95ERQXOFKepWKB7Q=; b=a6EYVP9OZCubLq pSLl+5m29oCEpOONy5gNoQDhiBoMp3O78glsJsqnf9Ka+2UDwKfLEqY+u03e9X/JD/Kb8Enycn+J0 D3nK79jOY94lC3+JQaE2Lce4kJEswXWeQfNJEQC64AL1fBtDa/C49TVQGclf16ENXvD7R0Qy24ypT ZadFtnbNpwVXP0n3DgxWZ2lVY9h4SLgRUnoNGeGlgY2q9BSVA49h1qvxxNc0zg6Ju9YFDjWW//Ya/ nv8NMaCso/cR9gKHIPT3nlNb5enCeMplCTqynl5Jy5XWIkzm0t1Wprh1QKWgrDjn6pmws0MM6ziVD znUvhFJ2IYWiPDPXerFg==; 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 1eJgZd-0003UD-8U; Tue, 28 Nov 2017 14:09:21 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eJgZC-000322-Mr for lede-dev@lists.infradead.org; Tue, 28 Nov 2017 14:08:57 +0000 Received: by mail-wm0-x243.google.com with SMTP id r68so2217675wmr.1 for ; Tue, 28 Nov 2017 06:08:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fon-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=ru7KCIpzw9oZZbEN3jUouRz4dAPQXlNj+nfiHyC8KUk=; b=CpiCX1U9jesMjIyyWtua/gD5A+YS7mn5+/zmthALuXKDlp4B2JGBYN7ptTBA46wxKk Zh7kjF/7BSoREC9XaVFjJcF3qnG1aQqAfSJeUqxIfT6xgmanU+Yid+/tTI+4wRY3cz+J gZmY0ci+z1ZBfOg/waAEhnB6HlWS7VUQpi6BvrKtaloootUqbQKTObWTdwiINrBJZu7t veINg180NM9DGtMeLEVypK3mTIcRiUTjVdHv90sx7wXsF0Fbr4qlGFikV5yFgJCcT9Pd fiDIKxBOgUwQjxMQRpMlXfVbBANk5deHy98tVyKQEq/8xHeQiKQH03lLE4L4qq4k5Ypv hDzw== 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=ru7KCIpzw9oZZbEN3jUouRz4dAPQXlNj+nfiHyC8KUk=; b=ifAbrexUYeQLcItYQhP0hrcdqmCgZTsF7FPhccIWWkTmuSQOWGvRHe+q857wYQJsTO MmdI8ybU1Cb7SZnp4Gx64am5LooN3BggRcom8ZdRfI61raNOw4EdV951t7f0YiIYYkXS MZPSvALFyR8xUvEQgP2qfcvWGtFHxewZGNQXVjSpwuw5bWobLXRw7N/iqAwt2dXh6OP2 cXvlDMf+FJrFDf45o4IntM0MQ0chk3JpWp0wU5MnPnqadNP/bOx+KLXkqDVwJNwWRz35 A3XjiuVVsm/5vqs1RFfpAWX5kLOs/pZFPb/PCEh3iY+V1PZ2l21KfQAtg6fSlXFOgyqv 72+g== X-Gm-Message-State: AJaThX6GpNeL2G5ZBlFfMEVm+F65cDS9jkOW6DI48ZxbpX5EgtPF/GEV tySKp42U8dSAXCDMKjuh5SLRbBPW X-Google-Smtp-Source: AGs4zMbhvGoRpN6LrYmBZ+0naOnG2EXb/lfsDekb27xpRdNlaLaI4yToQl/HRsva3NpgJap5BOVT2g== X-Received: by 10.28.155.18 with SMTP id d18mr20382548wme.107.1511878111541; Tue, 28 Nov 2017 06:08:31 -0800 (PST) Received: from BSalazar.fon.ofi ([213.27.197.25]) by smtp.gmail.com with ESMTPSA id 26sm28120637wrw.19.2017.11.28.06.08.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Nov 2017 06:08:30 -0800 (PST) From: Borja Salazar To: lede-dev@lists.infradead.org Date: Tue, 28 Nov 2017 15:08:27 +0100 Message-Id: <20171128140827.26922-1-borja.salazar@fon.com> X-Mailer: git-send-email 2.11.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171128_060855_146413_8E38049D X-CRM114-Status: UNSURE ( 9.37 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:400c:c09:0:0:0:243 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 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 odhcpd v2] dhcpv4: notify DHCP ACK and RELEASE via ubus 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: Borja Salazar MIME-Version: 1.0 Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org if the ubus object has any subscription notify DHCP ACK and DHCP RELEASE events using ubus notifications. Signed-off-by: Borja Salazar --- src/dhcpv4.c | 16 ++++++++++++++++ src/odhcpd.h | 2 ++ src/ubus.c | 24 ++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/src/dhcpv4.c b/src/dhcpv4.c index 166582e..9fd6a8d 100644 --- a/src/dhcpv4.c +++ b/src/dhcpv4.c @@ -723,6 +723,14 @@ static void handle_dhcpv4(void *addr, void *data, size_t len, req->chaddr[0],req->chaddr[1],req->chaddr[2], req->chaddr[3],req->chaddr[4],req->chaddr[5]); +#ifdef WITH_UBUS + if (ubus_has_subscribers() && reqmsg == DHCPV4_MSG_RELEASE) { + char req_chaddr_str[13]; + memset(&req_chaddr_str, 0, sizeof(req_chaddr_str)); + odhcpd_hexlify(req_chaddr_str, req->chaddr, ETH_ALEN); + ubus_event_bcast("dhcp.release", req_chaddr_str, inet_ntoa(req->ciaddr), hostname, iface->ifname); + } +#endif if (reqmsg == DHCPV4_MSG_DECLINE || reqmsg == DHCPV4_MSG_RELEASE) return; @@ -870,6 +878,14 @@ static void handle_dhcpv4(void *addr, void *data, size_t len, req->chaddr[3],req->chaddr[4],req->chaddr[5], inet_ntoa(dest.sin_addr)); +#ifdef WITH_UBUS + if (ubus_has_subscribers() && msg == DHCPV4_MSG_ACK) { + char reply_chaddr_str[13]; + memset(&reply_chaddr_str, 0, sizeof(reply_chaddr_str)); + odhcpd_hexlify(reply_chaddr_str, reply.chaddr, ETH_ALEN); + ubus_event_bcast("dhcp.ack", reply_chaddr_str, inet_ntoa(reply.yiaddr), hostname, iface->ifname); + } +#endif sendto(sock, &reply, sizeof(reply), MSG_DONTWAIT, (struct sockaddr*)&dest, sizeof(dest)); } diff --git a/src/odhcpd.h b/src/odhcpd.h index 45badd3..7ee4f44 100644 --- a/src/odhcpd.h +++ b/src/odhcpd.h @@ -296,6 +296,8 @@ int ubus_init(void); const char* ubus_get_ifname(const char *name); void ubus_apply_network(void); bool ubus_has_prefix(const char *name, const char *ifname); +void ubus_event_bcast(const char *type, const char *mac, const char *ip, const char *name, const char *interface); +bool ubus_has_subscribers(void); #endif int netlink_add_netevent_handler(struct netevent_handler *hdlr); diff --git a/src/ubus.c b/src/ubus.c index 95eeff7..741daed 100644 --- a/src/ubus.c +++ b/src/ubus.c @@ -311,6 +311,30 @@ static const struct blobmsg_policy obj_attrs[OBJ_ATTR_MAX] = { [OBJ_ATTR_PATH] = { .name = "path", .type = BLOBMSG_TYPE_STRING }, }; +bool ubus_has_subscribers(void) +{ + return main_object.has_subscribers; +} + +void ubus_event_bcast(const char *type, const char *mac, const char *ip, const char *name, const char *interface) +{ + + if (!ubus || !main_object.has_subscribers) + return; + + blob_buf_init(&b, 0); + if (mac) + blobmsg_add_string(&b, "mac", mac); + if (ip) + blobmsg_add_string(&b, "ip", ip); + if (name) + blobmsg_add_string(&b, "name", name); + if (interface) + blobmsg_add_string(&b, "interface", interface); + + ubus_notify(ubus, &main_object, type, b.head, -1); + +} static void handle_event(_unused struct ubus_context *ctx, _unused struct ubus_event_handler *ev, _unused const char *type, struct blob_attr *msg)