From patchwork Wed Oct 14 10:46:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Alin_N=C4=83stac?= X-Patchwork-Id: 1382057 X-Patchwork-Delegate: dedeckeh@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=gojx1UWS; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=olJW0mrg; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CB8Jy50qZz9sVH for ; Wed, 14 Oct 2020 21:48:17 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Message-Id:Date:Subject:To:From:Reply-To:Cc: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=qBTIH/pOXHuOkO6qXbTozYsYpl9r4PaU64zGIWtWVjw=; b=gojx1UWSShIWg3rWBrSBrv+Yw7 gZu9LPxnHIicf5CKS9BIzdgo2ccrePNxTwJedVI+cGHj656smddvbEtT17Wh5klcyNloUmRQr5a8s BFe1oVy+sIqoSKpsrV+BwvBSg5dnoLylaErmVI8RG8jxEWzmPrzzimZntyKJKKEdZRR1Rh5bJ/CXg pPZMIfwplGdQdzDQQjjhL+kbw/uAPY3ouqIw0j8NZrWIk6US8QGrhSyT9CjCtFJH+tnU+B3RL//GH RN/is4IXkL1fj364hy1PMOom+XpyGdHrmqdj6i+lmIJAiQjQx4Bt7UzlQ86SBZHPAtX58eV/wya56 NFWS3SsQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kSeIT-0002iU-Bz; Wed, 14 Oct 2020 10:46:17 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kSeIQ-0002h6-Ad for openwrt-devel@lists.openwrt.org; Wed, 14 Oct 2020 10:46:15 +0000 Received: by mail-wr1-x441.google.com with SMTP id n18so3216565wrs.5 for ; Wed, 14 Oct 2020 03:46:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=xRVncpPNmse32CTiKegz1vKJBV08xQk5BQFU1envUrY=; b=olJW0mrgjkvGVz7+/UWS3UQvZ/PVBdoytQCNp1/XrQ202bV8nQMe1ivaOQMW7LHw2/ 6xHSmx0CVYKUiKzcpzHlWw+gEQEpfy9ENvE15/U4Evmfu6uBuoDSDsV0aJBTDQxrGKv6 VFK5YwIIILIWf7SC/bEq1v1U+cez7N2SVAJdmSeED1LQJQbuTXJxYdM270/FbPEHKvtV 5w8o3L3B5GKKNj4CkW0KDrvJ9tGDlNvLAstdkAf0oriN1UKeNEp4QGvkwb81OqKKLi2P AWTpP8Q92Ib1iOPIMq76OJsRNvdzTDB2RxuOK77AG6PqV9H/K142+xMCtwegQiRrVVLO 2JfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=xRVncpPNmse32CTiKegz1vKJBV08xQk5BQFU1envUrY=; b=E+zyvaYN4t9Q0oiQoFS2Np0xq7rf/k8mO/7EDAtGOodig6cMV/v5joVpAuI5D0/l1k EA7UieHHR5mK7d/xU2iudb4pjAQh475jIpneQoCvDUvbjjm/1NtDn0C0xBOUYnZuTZyk pr+wQlMhS5HzESwd6YCct3SQxjdiHdEjnoHJdauQeKXdlmIeCLl0Ek2ZWB/6Q04bcsSK J8vrDikwsGFdUdkdDTYn5VWU7XORHx8i5ecdxNIVxxnefMbnvvUsGmZ7nYQFK/nGuQXE PC/i9gYzxXxJl/iAiwUgLd3uaXK8EJFR449zIvBlS8ITCCiWjT9axWsJVBnRS71Yq+K/ dkKw== X-Gm-Message-State: AOAM53214Llsyjt0NTIvVKvlrnVHWyezO7N86gAOI0VmcPFp9Kq+ux85 DeRq0cmUC/L1KcaG/bd8mZ8= X-Google-Smtp-Source: ABdhPJwX9lPfpMcZVnwm4fpGSECbpxuhgxOB10MUaSol9o+PJHQ0I42FRjVZX0Rxm4v5i5rlllMUQg== X-Received: by 2002:a05:6000:1112:: with SMTP id z18mr4694855wrw.3.1602672371031; Wed, 14 Oct 2020 03:46:11 -0700 (PDT) Received: from cplx1037.edegem.eu.thmulti.com ([2001:4158:f012:390:2a10:7bff:fec5:6f08]) by smtp.gmail.com with ESMTPSA id z191sm3311538wme.30.2020.10.14.03.46.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Oct 2020 03:46:10 -0700 (PDT) From: Alin Nastac To: Hans Dedecker , openwrt-devel Subject: [PATCH][odhcp6c] ra: exit on RTM_DELLINK event Date: Wed, 14 Oct 2020 12:46:09 +0200 Message-Id: <1602672369-15035-1-git-send-email-alin.nastac@gmail.com> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201014_064614_381007_1BFA4234 X-CRM114-Status: GOOD ( 17.15 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:441 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [alin.nastac[at]gmail.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -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 X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Also handle the netlink message correctly (the current code assumes that the entire buffer returned by recv contains just one netlink message). This fixes a timing issue that occurs when wan interface proto is pppoe, wan6 proto is dhcpv6 and PPP session is closed by the peer. Because odhpc6c doesn't react to pppoe-wan device deletion, sometimes netifd device created by the old pppd instance doesn't get released before new pppd instance execute the ppp-up script (pppoe-wan device is reffered by wan6 device alias), so device_claim() doesn't trigger device_set_ifindex(). That will impede default route creation for wan interface (pppoe-wan device will store the incorrect ifindex). Signed-off-by: Alin Nastac --- src/dhcpv6.c | 6 +++++- src/ra.c | 54 ++++++++++++++++++++++++++++++------------------------ 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/dhcpv6.c b/src/dhcpv6.c index bd8a2dc..4cd1abc 100644 --- a/src/dhcpv6.c +++ b/src/dhcpv6.c @@ -560,7 +560,11 @@ int dhcpv6_request(enum dhcpv6_msg type) struct timespec ts = {0, 0}; ts.tv_nsec = (dhcpv6_rand_delay((10000 * DHCPV6_REQ_DELAY) / 2) + (1000 * DHCPV6_REQ_DELAY) / 2) * 1000000; - while (nanosleep(&ts, &ts) < 0 && errno == EINTR); + while (nanosleep(&ts, &ts) < 0 && errno == EINTR) { + // Check for pending signal + if (odhcp6c_signal_process()) + return -1; + } } if (type == DHCPV6_MSG_UNKNOWN) diff --git a/src/ra.c b/src/ra.c index 337c0bd..9af48a2 100644 --- a/src/ra.c +++ b/src/ra.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -208,37 +209,42 @@ static int16_t pref_to_priority(uint8_t flags) bool ra_link_up(void) { static bool firstcall = true; - struct { - struct nlmsghdr hdr; - struct ifinfomsg msg; - uint8_t pad[4000]; - } resp; + char buf[4096]; bool ret = false; ssize_t read; - do { - read = recv(rtnl, &resp, sizeof(resp), MSG_DONTWAIT); + while ((read = recv(rtnl, &buf, sizeof(buf), MSG_DONTWAIT)) > 0) { + for (struct nlmsghdr *nlh = (struct nlmsghdr *)buf; + NLMSG_OK (nlh, read) && nlh->nlmsg_type != NLMSG_DONE; + nlh = NLMSG_NEXT(nlh, read)) { + if (nlh->nlmsg_type != RTM_NEWLINK && nlh->nlmsg_type != RTM_DELLINK) + continue; - if (read < 0 || !NLMSG_OK(&resp.hdr, (size_t)read) || - resp.hdr.nlmsg_type != RTM_NEWLINK || - resp.msg.ifi_index != if_index) - continue; + struct ifinfomsg *ifi = NLMSG_DATA(nlh); + if (ifi->ifi_index != if_index) + continue; - ssize_t alen = NLMSG_PAYLOAD(&resp.hdr, sizeof(resp.msg)); - for (struct rtattr *rta = (struct rtattr*)(resp.pad); - RTA_OK(rta, alen); rta = RTA_NEXT(rta, alen)) { - if (rta->rta_type == IFLA_ADDRESS && - RTA_PAYLOAD(rta) >= sizeof(rs.lladdr.data)) - memcpy(rs.lladdr.data, RTA_DATA(rta), sizeof(rs.lladdr.data)); - } + if (nlh->nlmsg_type == RTM_DELLINK) { + syslog(LOG_ERR, "Interface %s has been deleted, exiting", if_name); + exit(1); + } - bool hascarrier = resp.msg.ifi_flags & IFF_LOWER_UP; - if (!firstcall && nocarrier != !hascarrier) - ret = true; + ssize_t alen = IFLA_PAYLOAD(nlh); + for (struct rtattr *rta = IFLA_RTA(nlh); + RTA_OK(rta, alen); rta = RTA_NEXT(rta, alen)) { + if (rta->rta_type == IFLA_ADDRESS && + RTA_PAYLOAD(rta) >= sizeof(rs.lladdr.data)) + memcpy(rs.lladdr.data, RTA_DATA(rta), sizeof(rs.lladdr.data)); + } + + bool hascarrier = ifi->ifi_flags & IFF_LOWER_UP; + if (!firstcall && nocarrier != !hascarrier) + ret = true; - nocarrier = !hascarrier; - firstcall = false; - } while (read > 0); + nocarrier = !hascarrier; + firstcall = false; + } + } if (ret) { syslog(LOG_NOTICE, "carrier => %i event on %s", (int)!nocarrier, if_name);