From patchwork Thu Jan 12 04:40:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Mendoza-Jonas X-Patchwork-Id: 714228 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tzY3L5ZFrz9t0q for ; Thu, 12 Jan 2017 15:40:30 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="ACEWdXUD"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3tzY3L4CtLzDqRF for ; Thu, 12 Jan 2017 15:40:30 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="ACEWdXUD"; dkim-atps=neutral X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from mendozajonas.com (mendozajonas.com [188.166.185.233]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3tzY385s2lzDqDN for ; Thu, 12 Jan 2017 15:40:20 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="ACEWdXUD"; dkim-atps=neutral Received: from skellige.ozlabs.ibm.com (unknown [122.99.82.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: sam@mendozajonas.com) by mendozajonas.com (Postfix) with ESMTPSA id BCB20143FAE; Thu, 12 Jan 2017 12:40:15 +0800 (SGT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mendozajonas.com; s=mail; t=1484196016; bh=e5KMH/jUwjH6iUpVAOZ/qPv6xxQwhK67CdPIFFL1Nj0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ACEWdXUD4d4J0vruUgvBvsPAUxHV7Q8UnRfRy0ZBMlHWFc2nCPGahDWIqzDsyUlte oSZKz8fL/J3SPBaMD79RtHBYCo09Mwmfc5luaaJNgHkdt1ifYFwSI8qkUfhi8C/Cjf T08T8lKzlPb3imlGjOl0rZ7CFx6iHfvpqtfEK+2g= From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH 2/2] discover/network: Ensure interfaces have device before configuring Date: Thu, 12 Jan 2017 15:40:02 +1100 Message-Id: <20170112044002.30422-2-sam@mendozajonas.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170112044002.30422-1-sam@mendozajonas.com> References: <20170112044002.30422-1-sam@mendozajonas.com> X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Samuel Mendoza-Jonas MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Reorganise network_handle_nlmsg() slightly to create interface->dev just before calling configure_interface() rather than only for brand new interfaces. This ensures existing interfaces which have had ->dev removed but receive a new configure event do not access a NULL pointer during the configuration process. Signed-off-by: Samuel Mendoza-Jonas --- discover/network.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/discover/network.c b/discover/network.c index c3cf30a..6ae4417 100644 --- a/discover/network.c +++ b/discover/network.c @@ -214,13 +214,12 @@ static int network_send_link_query(struct network *network) return 0; } -static void add_interface(struct network *network, +static void create_interface_dev(struct network *network, struct interface *interface) { char *uuid = mac_bytes_to_string(interface, interface->hwaddr, sizeof(interface->hwaddr)); - list_add(&network->interfaces, &interface->list); interface->dev = discover_device_create(network->handler, uuid, interface->name); interface->dev->device->type = DEVICE_TYPE_NETWORK; @@ -563,7 +562,8 @@ static int network_handle_nlmsg(struct network *network, struct nlmsghdr *nlmsg) interface->state = IFSTATE_NEW; memcpy(interface->hwaddr, ifaddr, sizeof(interface->hwaddr)); strncpy(interface->name, ifname, sizeof(interface->name) - 1); - add_interface(network, interface); + list_add(&network->interfaces, &interface->list); + create_interface_dev(network, interface); } /* A repeated RTM_NEWLINK can represent an interface name change */ @@ -582,6 +582,9 @@ static int network_handle_nlmsg(struct network *network, struct nlmsghdr *nlmsg) interface->hwaddr, interface->name, info->ifi_flags & IFF_LOWER_UP); + if (!interface->dev) + create_interface_dev(network, interface); + configure_interface(network, interface, info->ifi_flags & IFF_UP, info->ifi_flags & IFF_LOWER_UP);