From patchwork Fri Jul 26 22:37:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13743222 Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD18763CB for ; Fri, 26 Jul 2024 22:37:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722033479; cv=none; b=BkEifRw5BC084zidbqO+oTcs9jJeqAiT2KHD+4/aVpgEpmfX5QLGke5h2ZdWTlrg9MD1XURMqxt9RYe6OF+j1QrZlgZzd9mGmNTbL7MJADGCSV64/U1hzoCJTIPq+hxBNRkpt+NTF+ij2XVWnVO2trnIiRdyMhbtZu0dNAuS7sI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722033479; c=relaxed/simple; bh=klJsN22jHsAkvzgwDk9KmS4RBqYR+l6/Cy4aX/JZuVQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=uYeXhbfLlbAIziPzHX+jybpE/CBnSuU3sxYvGvY1XzH6Rb/3245zut25j9g6yR8NzDEZfEZme6MdRpJkkkzcezwtIq0UGYL+5C28Vvo5XF6UWCgd3NwNL2C4yGMAA/sN+/DtAlcWwDPAtzhLOcUD6AH817BWMhMrJiyzX2Z9gmo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=J/gLy+yn; arc=none smtp.client-ip=209.85.167.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="J/gLy+yn" Received: by mail-oi1-f181.google.com with SMTP id 5614622812f47-3db145c8010so875961b6e.3 for ; Fri, 26 Jul 2024 15:37:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722033477; x=1722638277; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=M22Gx1LCi3yrWXnXYGkeHZ8tg/2Eu2sCI+X6K59XQnA=; b=J/gLy+yn9ZGM2KYhCsBndp7NJuhD7N3DYiO5DyrJnUPPRwAman7QVxTmcdclY7DQaW EgFVI/r8j1qAgov/ovuQVPOxITqyjnPsiWyxETc4dL6XcRJMNo/FiWc1ha5nWr1XpmEc nv32n0G9p7Et0SyFtCbnnzu3Z/PQlyJIAMJ2O+TJhjaMCXlxu9aXFSUZwBS1UtN3/oB4 kZtkNS0Vf4RGBjsC+KGZD5VmBDtziY6GUXWqfGxM3wTuNrLoAUf1MJOatiI6Pmmh6ppc 5F4EBn1RydEW7Qvm6n4MUl2Urh4AZ+5KI5JdjRdlGMRp2B+saO3B0Z2CTpUGLtIWJ8R/ 7HRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722033477; x=1722638277; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=M22Gx1LCi3yrWXnXYGkeHZ8tg/2Eu2sCI+X6K59XQnA=; b=FWuGHl9sU8tKjbtDQyq81EkMSwpluWJIW7RSoCjykBl80bS7JyF+PvrNt/H2gSLnVt yrUDYqnrHGe9dAC8+faB12CkLOu1LGfkVY7ygewMBYNelqk4Zafllv4LCcQ8/Ts/Wfsa ta3bkiAUUdTQSwX/u7oZNuY3Ez+ifsxhCva6GiMMS67V0tD8tGv8cnJ/SH/3LNs1NL7F dJ4bKkIfUjRd0aKQ0ksyiYnYA0YdDcWcxJB1AP4rVJfr7P2kzugG2ExOFDKhNIWYA20L qK2HJp4Q1GYHqc1dtpZGJTmbhp+e1mPkLyUQZUboJIN87F72qmcieVXOwbHujZ6kNkmD 6Kgg== X-Gm-Message-State: AOJu0YxMN3AZDMN+i6xuHJaUK+Z/6Bd0RRuN5wW7j9P2bcl+n2LXs0/p sfcYmmpBRIU2zfJ+JjMd1jFUrWkyTuL1TuboIvHM4Hd3lvDeMN8ApLK5Qw== X-Google-Smtp-Source: AGHT+IGEHUIIxaKp7DzlLlWQQ7aPJjF+U+lxcI8TiH0P/CMWtx2QpSQiz9IBbUabvTfiAj8Dki6JLA== X-Received: by 2002:a05:6808:1701:b0:3d6:2da2:2b4e with SMTP id 5614622812f47-3db2369da3emr1009625b6e.14.1722033476652; Fri, 26 Jul 2024 15:37:56 -0700 (PDT) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3db13521040sm892574b6e.46.2024.07.26.15.37.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jul 2024 15:37:56 -0700 (PDT) From: Denis Kenzior To: iwd@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 1/3] wired: Update to the new l_netlink_send API Date: Fri, 26 Jul 2024 17:37:43 -0500 Message-ID: <20240726223754.159303-1-denkenz@gmail.com> X-Mailer: git-send-email 2.45.2 Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 --- wired/ethdev.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/wired/ethdev.c b/wired/ethdev.c index e5353582494e..a933cc18e343 100644 --- a/wired/ethdev.c +++ b/wired/ethdev.c @@ -723,7 +723,8 @@ static void setup_adapter_interface(struct l_dbus_interface *interface) bool ethdev_init(const char *whitelist, const char *blacklist) { - struct ifinfomsg msg; + struct ifinfomsg ifi; + struct l_netlink_message *nlm; if (rtnl) return false; @@ -760,10 +761,11 @@ bool ethdev_init(const char *whitelist, const char *blacklist) if (blacklist) blacklist_filter = l_strsplit(blacklist, ','); - memset(&msg, 0, sizeof(msg)); + memset(&ifi, 0, sizeof(ifi)); + nlm = l_netlink_message_new_sized(RTM_GETLINK, NLM_F_DUMP, sizeof(ifi)); + l_netlink_message_add_header(nlm, &ifi, sizeof(ifi)); - l_netlink_send(rtnl, RTM_GETLINK, NLM_F_DUMP, &msg, sizeof(msg), - getlink_callback, NULL, NULL); + l_netlink_send(rtnl, nlm, getlink_callback, NULL, NULL); return true; } From patchwork Fri Jul 26 22:37:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13743223 Received: from mail-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73B5C2C684 for ; Fri, 26 Jul 2024 22:37:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722033479; cv=none; b=ScMzzb7NqNLYjBhn658i+jxbpw++ODlipX9kqaaaCnYzdDqblkcROmgWkSNoDU+fAxKSDhoKucs19oKfqwaZKiQiMbd9P92d602im15KouiqN9tYVd7H8yTVGl7qSd5W/vb68DQ86aS+9t3F68DmUSRKoXPF+Yq4cKb3cFDoY+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722033479; c=relaxed/simple; bh=RGxWIpELRzPmeNWgjbtIsOZIGWA2AMv2AbW5bAzbjWA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=THJcpPDoPwgKNK7ynTKzjXfvTCRSB8fs5C/BDr+Uc25GUGl3TK393TkH2/o7lCm1bxBhurn2OOYEfwqquejPNBsZ6cW0DxvBYO8spA44Ki/NPAsnx+WwzK2c1zQWugJDsCGBOGumQNOcB+aHFpztJ/AW3rrhVAC/w8h7ZkX5sTc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UFC9HPPC; arc=none smtp.client-ip=209.85.167.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UFC9HPPC" Received: by mail-oi1-f173.google.com with SMTP id 5614622812f47-3cabac56b38so988237b6e.3 for ; Fri, 26 Jul 2024 15:37:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722033477; x=1722638277; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NamKfRr5DtJxVxIFQPJ6TuNsJh1PqVsocMWMEysLyu0=; b=UFC9HPPCvgFxwclY405XrvNUdoQ1cl1juWuDYJjCpEINjiPN+VdIj7iXrFxYMQFXMu zhSwMPDlb8iMfQLosF1/Y0Pbz/2tM7kLdkuGEUUQDPq1Rxxd3tVLixquUt4N0gDPBKw1 UsuFcPt805c+eWtKjl1jFg9Op9LDpfEQXVQtzN3xoKNy49Dal3GFcbkk4d43wOn5098v qeo0FDZ+CeJtUSO69Zx3TgoXDN9jGUAIOxFM1pirJJ8Fo5u5DoX2tHJmCAsk7x8HvA+Y p14+N5ATTXRQq/L4u6WlQwLgOYEMbhaB0AcwfVI0fmjgZd+kjWG7XyDARP203mJ8fzUy oGaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722033477; x=1722638277; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NamKfRr5DtJxVxIFQPJ6TuNsJh1PqVsocMWMEysLyu0=; b=fsNOspEbdB52Rvl90DoM/Zxv6vpb3L6dskxEfvZYmrLG936OkzYGOHOgrsevA+ig7W Fi3cHBc+tkcFmomKeynYxfUMShHFoWpNcOCtaB5ZurbjPtvZ470YspLvod2OuCoQ8c2L 033x/T/+I+wPnKfcWGk0KpmhGOuFR2SIm806As5tXP3E3q/+mYsGGy/jajgczeftob06 a+kcjUZoa6wb1nT0lFJG0cM3JCBbVsCKayMOB4bPl0xdMVvwkOP7x/jNELc9saE6tR83 5PxG2qH3rJf+14Z0yjkPJxj1pQGPU9LhkEYBhJPtKpXXc/vtY2dm2754+MKlTze4TTUZ octw== X-Gm-Message-State: AOJu0YzgrOurSj8zaH7gMzpZYQ3rEjrI86nLAq7ZTXQzgUyRbVnIs8jF MeorOD/dmG8eAEEzTgWu+c8L6PZDzl6gCki5dK2UBZanmqI9Li8VR6Irpw== X-Google-Smtp-Source: AGHT+IH7Pf7/avhq14zVcXNU/m7zjsJMyA7kB5po1BEnZQd83IDk2Dn98Ogu3yZaZZpylu5iF9hi9g== X-Received: by 2002:a05:6808:1821:b0:3da:a97d:3579 with SMTP id 5614622812f47-3db23a87735mr1546595b6e.16.1722033477309; Fri, 26 Jul 2024 15:37:57 -0700 (PDT) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3db13521040sm892574b6e.46.2024.07.26.15.37.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jul 2024 15:37:57 -0700 (PDT) From: Denis Kenzior To: iwd@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 2/3] netdev: Update to the new l_netlink_send API Date: Fri, 26 Jul 2024 17:37:44 -0500 Message-ID: <20240726223754.159303-2-denkenz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240726223754.159303-1-denkenz@gmail.com> References: <20240726223754.159303-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 --- src/netdev.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/netdev.c b/src/netdev.c index 2d70fc38eea9..e27a0019b7ea 100644 --- a/src/netdev.c +++ b/src/netdev.c @@ -6093,23 +6093,19 @@ error: static void netdev_get_link(struct netdev *netdev) { - struct ifinfomsg *rtmmsg; - size_t bufsize; + struct ifinfomsg ifi; + struct l_netlink_message *nlm = + l_netlink_message_new_sized(RTM_GETLINK, 0, sizeof(ifi)); - /* Query interface flags */ - bufsize = NLMSG_ALIGN(sizeof(struct ifinfomsg)); - rtmmsg = l_malloc(bufsize); - memset(rtmmsg, 0, bufsize); + memset(&ifi, 0, sizeof(ifi)); + ifi.ifi_family = AF_UNSPEC; + ifi.ifi_index = netdev->index; - rtmmsg->ifi_family = AF_UNSPEC; - rtmmsg->ifi_index = netdev->index; + l_netlink_message_add_header(nlm, &ifi, sizeof(ifi)); - netdev->get_link_cmd_id = l_netlink_send(rtnl, RTM_GETLINK, 0, rtmmsg, - bufsize, netdev_getlink_cb, + netdev->get_link_cmd_id = l_netlink_send(rtnl, nlm, netdev_getlink_cb, netdev, NULL); L_WARN_ON(netdev->get_link_cmd_id == 0); - - l_free(rtmmsg); } struct netdev *netdev_create_from_genl(struct l_genl_msg *msg, From patchwork Fri Jul 26 22:37:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13743224 Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BB0A149E1D for ; Fri, 26 Jul 2024 22:37:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722033480; cv=none; b=P9YoiiRsnoE+L1VMCmcKUhwCcBHbGGod+gfTzeVeAK6Mw1o1n2RW1+wiOy0QfyNYqy6Mlo3u4Dn2BHuqjWyRUwsLQlNNXvlrMOXKhC/YFnpRdxBtii4UTObxCs6YbAfLl7a3NySQi5gPabXuP1EypmzXXQ1U9vBqTd8H1h7SVl0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722033480; c=relaxed/simple; bh=yMdtlX3sjcnkj9bZoG6+Hcx6Q8ZkAtaWiuOoHPgcRCA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T+zmjlvQj7vop8ANqy10TuTQvfje8dKywy0dCVhr8i9YBI/YzS/4tdcbr47OjnbHjfQA8cMf5mNmqbaTCAu9WFjgzoeJ5Bhr/J4SEwD8yjPmLME7DkiGL8RX2RZfaFoY7924j1LKkqrNrsxnCjxv1GpjHQQ4NykkGS/x37fWELE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fmgyPprv; arc=none smtp.client-ip=209.85.167.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fmgyPprv" Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-3db1646da25so687205b6e.1 for ; Fri, 26 Jul 2024 15:37:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722033478; x=1722638278; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=a5aAKMYPoJ5T2PE2UIZ8SxR5MEJeKgUYFDtgCXOQHmQ=; b=fmgyPprvlPgG4FqjkAphq/LyEr7PDLaYbLdFE2J3KvtheYxOEMGdHl7ezn8BE2mAc+ zpzmo9lii9YsiTuHqEeZqUdZ/QAD4j9M0dDXvcAWWmeidkfrp7eHtOav7GfupEryjC4s 2EWBjEzN6eXtU9Y1QT9fnoKZtQ9KIg6MuI+PoU3nqeJJPvaxwLz7TZ0KbnI4zoTkSpyN +FxKUe0+viTRo26HXd3m07ylQ49EIGPvFjmkSp7R+S1JVXSCTHmSmjGxts8titjA5mMw sThaNmWrarYMpXCENFpybKzaG4pGXcNQSjsP+BcdsFOlkSSemP78SLlnnlLZJOoZK07N y9xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722033478; x=1722638278; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=a5aAKMYPoJ5T2PE2UIZ8SxR5MEJeKgUYFDtgCXOQHmQ=; b=Qmh/IRE9Hx93fNBV0Nt9qBUFiIDsnvNaIjjym/w+7/u0IhglPcI+VMgyt4OcTT1ywR 37YE2k5h1wNKNwhikqkvZKPyB3hTOC4DQURJc4bVC+ojDIyu5F7Uw1RkqlYl/dLb6021 qlkbP8Hk8rYnzQXp2go6c56fIoz7+LZ+p1KMcaLE0WIP0c/mAYKPXk35btXmJOFWJTra 0flQ8gr+ch4qP2wl4FdCA2enPTsr0Mv4BEggd5R1H+MZA6HdoAW1LQCsw71z3NMjn03L y5IBpY9bt7xaCrsc9eEJ4N+vYMWif4eAf0Zplrtep42shgqRrurQi2FK0/icKapEsX23 ia3A== X-Gm-Message-State: AOJu0YwzCC7iSqWfMEsOBQKMy7ItvcndDBFJFXUUSdkOkMjwXfaJiIAt Z9beWc+cJUc0fDRfLOgbRc+wJ21mskKYigXXz+eYJllmajux/QRxeEYD2w== X-Google-Smtp-Source: AGHT+IEhm2SxPYq7EnFZH03PyNITloCEvGg3/fwvkgqIA570wPBuWJOY+81bjRqJHXp+m8fEn3vU8A== X-Received: by 2002:a05:6808:17a7:b0:3d5:1bc8:e979 with SMTP id 5614622812f47-3db23e7ab53mr505479b6e.1.1722033478019; Fri, 26 Jul 2024 15:37:58 -0700 (PDT) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3db13521040sm892574b6e.46.2024.07.26.15.37.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jul 2024 15:37:57 -0700 (PDT) From: Denis Kenzior To: iwd@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 3/3] monitor: Update to the new ell l_netlink_send API Date: Fri, 26 Jul 2024 17:37:45 -0500 Message-ID: <20240726223754.159303-3-denkenz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240726223754.159303-1-denkenz@gmail.com> References: <20240726223754.159303-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 --- monitor/main.c | 88 ++++++++++++++------------------------------------ 1 file changed, 24 insertions(+), 64 deletions(-) diff --git a/monitor/main.c b/monitor/main.c index 32f5ec4fc7f3..c560db775caa 100644 --- a/monitor/main.c +++ b/monitor/main.c @@ -260,22 +260,6 @@ static struct l_genl *genl_lookup(const char *ifname) return genl; } -static size_t rta_add(void *rta_buf, unsigned short type, uint16_t len, - const void *data) -{ - unsigned short rta_len = RTA_LENGTH(len); - struct rtattr *rta = rta_buf; - - memset(RTA_DATA(rta), 0, RTA_SPACE(len)); - - rta->rta_len = rta_len; - rta->rta_type = type; - if (len) - memcpy(RTA_DATA(rta), data, len); - - return RTA_SPACE(len); -} - static bool rta_linkinfo_kind(struct rtattr *rta, unsigned short len, const char* kind) { @@ -304,10 +288,9 @@ static struct l_netlink *rtm_interface_send_message(struct l_netlink *rtnl, { size_t nlmon_type_len = strlen(NLMON_TYPE); unsigned short ifname_len = 0; - size_t bufsize; - struct ifinfomsg *rtmmsg; - void *rta_buf; - struct rtattr *linkinfo_rta; + struct l_netlink_message *nlm; + struct ifinfomsg ifi; + uint16_t flags = 0; if (ifname) { ifname_len = strlen(ifname) + 1; @@ -316,64 +299,41 @@ static struct l_netlink *rtm_interface_send_message(struct l_netlink *rtnl, return NULL; } + if (!L_IN_SET(rtm_msg_type, RTM_NEWLINK, RTM_DELLINK, RTM_GETLINK)) + return NULL; + if (!rtnl) rtnl = l_netlink_new(NETLINK_ROUTE); if (!rtnl) return NULL; - bufsize = NLMSG_LENGTH(sizeof(struct ifinfomsg)) + - RTA_SPACE(ifname_len) + RTA_SPACE(0) + - RTA_SPACE(nlmon_type_len); - - rtmmsg = l_malloc(bufsize); - memset(rtmmsg, 0, bufsize); - - rtmmsg->ifi_family = AF_UNSPEC; - rtmmsg->ifi_change = ~0; - - rta_buf = rtmmsg + 1; - - if (ifname) - rta_buf += rta_add(rta_buf, IFLA_IFNAME, ifname_len, ifname); - - linkinfo_rta = rta_buf; - - rta_buf += rta_add(rta_buf, IFLA_LINKINFO, 0, NULL); - rta_buf += rta_add(rta_buf, IFLA_INFO_KIND, nlmon_type_len, NLMON_TYPE); - - linkinfo_rta->rta_len = rta_buf - (void *) linkinfo_rta; + memset(&ifi, 0, sizeof(ifi)); + ifi.ifi_family = AF_UNSPEC; + ifi.ifi_change = ~0; switch (rtm_msg_type) { case RTM_NEWLINK: - rtmmsg->ifi_flags = IFF_UP | IFF_ALLMULTI | IFF_NOARP; - - l_netlink_send(rtnl, RTM_NEWLINK, NLM_F_CREATE|NLM_F_EXCL, - rtmmsg, rta_buf - (void *) rtmmsg, callback, - user_data, destroy); + ifi.ifi_flags = IFF_UP | IFF_ALLMULTI | IFF_NOARP; + flags = NLM_F_CREATE | NLM_F_EXCL; break; - - case RTM_DELLINK: - rta_buf += rta_add(rta_buf, IFLA_IFNAME, ifname_len, ifname); - - l_netlink_send(rtnl, RTM_DELLINK, 0, rtmmsg, - rta_buf - (void *)rtmmsg, callback, user_data, - destroy); - break; - case RTM_GETLINK: - l_netlink_send(rtnl, RTM_GETLINK, NLM_F_DUMP, rtmmsg, - rta_buf - (void *)rtmmsg, callback, user_data, - destroy); - break; - - default: - l_netlink_destroy(rtnl); - rtnl = NULL; + flags = NLM_F_DUMP; break; } - l_free(rtmmsg); + nlm = l_netlink_message_new(rtm_msg_type, flags);; + l_netlink_message_add_header(nlm, &ifi, sizeof(ifi)); + + if (ifname) + l_netlink_message_append(nlm, IFLA_IFNAME, ifname, ifname_len); + + l_netlink_message_enter_nested(nlm, IFLA_LINKINFO); + l_netlink_message_append(nlm, IFLA_INFO_KIND, + NLMON_TYPE, nlmon_type_len); + l_netlink_message_leave_nested(nlm); + + l_netlink_send(rtnl, nlm, callback, user_data, destroy); return rtnl; }