From patchwork Fri Sep 4 02:59:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Kimmel X-Patchwork-Id: 1357149 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=none (p=none dis=none) header.from=bareminimum.eu 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=YnTMwdxX; 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 4BjMsd42ZPz9sVK for ; Fri, 4 Sep 2020 13:02:13 +1000 (AEST) 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:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=2g19gc2pZq+JheP+2eIX4zFWzvOlNxW5f3zLUGvJvhw=; b=YnTMwdxX0Osym0zaPXGuvKB9u l+sOS76907wWpMcWT1IkJJ3b+cGi0doGz86JhG6C21iUk9P1GFZ3JrHZArIlHISigrvBiwsHKBIwY XQBcch5812k7G1n+GgGgoCg0JZxMD+8dlSkZXMiCiKSahm8YMWpI2fgySYwfmP6wtmZmpUf5zBR2v jQqDbiUFF9TQQQEUI/1JHsL5hIpVO6FOHv3pFvf/K2t6ux+kd7i+CEpzXAG6w/Ek6Yivu0cRH40s0 SpmQBm74BI95P5NOo2PwSV1SPcMUKQTzCsvkWIrbIQzcNyhVOkzBeDl+EN2a/PqjN+QptfNbg1tBQ 2ItquCaeg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kE1xj-0008C2-7g; Fri, 04 Sep 2020 03:00:27 +0000 Received: from mail.nerd2nerd.org ([2a01:4f8:190:3211::25]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kE1xc-00089x-Nq for openwrt-devel@lists.openwrt.org; Fri, 04 Sep 2020 03:00:22 +0000 Received: from kosch.limbus.lpm.pw (200116b828f1af0276d435fffe9b7588.dip.versatel-1u1.de [IPv6:2001:16b8:28f1:af02:76d4:35ff:fe9b:7588]) by mail.nerd2nerd.org (Postfix) with ESMTPA id CFB0C6091B; Fri, 4 Sep 2020 05:00:14 +0200 (CEST) From: Johannes Kimmel To: openwrt-devel@lists.openwrt.org Subject: [PATCH 2/4] netifd: vxlan: refactor mapping of boolean attrs Date: Fri, 4 Sep 2020 04:59:41 +0200 Message-Id: <20200904025943.9067-2-fff@bareminimum.eu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200904025943.9067-1-fff@bareminimum.eu> References: <20200904025943.9067-1-fff@bareminimum.eu> MIME-Version: 1.0 Authentication-Results: mail.nerd2nerd.org; auth=pass smtp.auth=info@bareminimum.eu smtp.mailfrom=fff@bareminimum.eu X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200903_230020_892688_F1A9BA5D X-CRM114-Status: GOOD ( 11.06 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 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: , Cc: Johannes Kimmel Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Add a small function to handle boolean options and make use of it to handle: - rxcsum - txcsum Signed-off-by: Johannes Kimmel --- system-linux.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/system-linux.c b/system-linux.c index 5ff8749..88b064c 100644 --- a/system-linux.c +++ b/system-linux.c @@ -3073,6 +3073,17 @@ failure: #endif #ifdef IFLA_VXLAN_MAX +static void system_vxlan_map_bool_attr(struct nl_msg *msg, struct blob_attr **tb_data, int attrtype, int vxlandatatype, bool invert) { + struct blob_attr *cur; + if ((cur = tb_data[vxlandatatype])) { + bool val = blobmsg_get_bool(cur); + if (invert) { + val = !val; + } + nla_put_u8(msg, attrtype, val); + } +} + static int system_add_vxlan(const char *name, const unsigned int link, struct blob_attr **tb, bool v6) { struct blob_attr *tb_data[__VXLAN_DATA_ATTR_MAX]; @@ -3210,16 +3221,9 @@ static int system_add_vxlan(const char *name, const unsigned int link, struct bl nla_put(msg, IFLA_VXLAN_PORT_RANGE, sizeof(srcports), &srcports); } - if ((cur = tb_data[VXLAN_DATA_ATTR_RXCSUM])) { - bool rxcsum = blobmsg_get_bool(cur); - nla_put_u8(msg, IFLA_VXLAN_UDP_ZERO_CSUM6_RX, !rxcsum); - } - - if ((cur = tb_data[VXLAN_DATA_ATTR_TXCSUM])) { - bool txcsum = blobmsg_get_bool(cur); - nla_put_u8(msg, IFLA_VXLAN_UDP_CSUM, txcsum); - nla_put_u8(msg, IFLA_VXLAN_UDP_ZERO_CSUM6_TX, !txcsum); - } + system_vxlan_map_bool_attr(msg, tb_data, IFLA_VXLAN_UDP_CSUM, VXLAN_DATA_ATTR_TXCSUM, false); + system_vxlan_map_bool_attr(msg, tb_data, IFLA_VXLAN_UDP_ZERO_CSUM6_RX, VXLAN_DATA_ATTR_RXCSUM, true); + system_vxlan_map_bool_attr(msg, tb_data, IFLA_VXLAN_UDP_ZERO_CSUM6_TX, VXLAN_DATA_ATTR_TXCSUM, true); if ((cur = tb[TUNNEL_ATTR_TOS])) { char *str = blobmsg_get_string(cur);