Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1019237pxb; Wed, 6 Apr 2022 06:53:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWXLtiFZOsMwkZsqhLsZLunzTPZ+jIXmkNUvpCI2c9ZMj2eVG5CW4kHy80YWE0owWWBc8i X-Received: by 2002:a17:90b:38c7:b0:1c7:6afb:fac6 with SMTP id nn7-20020a17090b38c700b001c76afbfac6mr9985914pjb.198.1649253191121; Wed, 06 Apr 2022 06:53:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649253191; cv=none; d=google.com; s=arc-20160816; b=JwUnH3w+Owt7wQqMRuFh6GCu1rUgsNQZ3/Obb1AvN0F2SeDAxJXD+0O5N2vOxAhUGJ zHOkGtt7Zn1w5vHxhblyXZgnMaDJlC5BN30lBcbdSkJbaNQMr39moKiLElhqXaQCKHci uGvt46Cd6NND8xqd5OQ9YFgJqTETJWNA6ItIpmWH3CsWJOEVfkhtqFH9k5Kg9oJKnYA9 a1Gxh9T5rM44wdzt4ZdlQOoql4bHnwOBc0w5EXI3DRIQftydokTMpFCx8teo7Bgnrj7g BFSL/n1nCMURENGdv5aNhvKofPOG2Tll01coN/3HGS2gtGCj5w4NMlxKmLPgscYMR3/D VCBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=HxMo+FHlHl6aAGrKLTq0pIbdcTpu1zlgrd5QYJGjBGk=; b=lxZQapHMa5mIVLgVGXWtueM9gS6rrobBN28hIseuxySOhCU7ZB1rsMO5CiygJrnEwi RnZzF+clhzjjUQ/8FDlA64TcPvwNxrX4kZ5w4tcfaO7jDFPrGaXDrxikDQ4jW2HDKOEU yOibbcVX5ZAvaDP3I/OPIOEhe63ocYmV9VWFn3N34C7te4E1FtE8u01UXraQ4tpJcRaO Zt3UNLqGD7sssqBZ5uRaFpE64F9cRIZ0pDVpkixRF/zJIcPBUZGjmNQSoYHE2puAd6KC NgN0azDrhPQBfRpaoSdqr91zKDyOBUXbkSouUSEbaRanv55UVBRoKtIIbFnLCJYHSBPE M+AQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PPpgchgO; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id 3-20020a630b03000000b003823abafdf4si15975560pgl.371.2022.04.06.06.53.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 06:53:11 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PPpgchgO; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4BE9925A4BB; Wed, 6 Apr 2022 04:47:31 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1841681AbiDFBZP (ORCPT + 99 others); Tue, 5 Apr 2022 21:25:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349273AbiDEJtd (ORCPT ); Tue, 5 Apr 2022 05:49:33 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B1BA26FA; Tue, 5 Apr 2022 02:43:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9C97C615E5; Tue, 5 Apr 2022 09:43:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD491C385A2; Tue, 5 Apr 2022 09:43:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649151815; bh=hcHNfnlR3uq16SdqCxgn15X9mJ344yk9MYVAcYO4ANQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PPpgchgOtd9Zdn2YxDCmNOpXFYp9bVxvstpWgt5VEO3pfv2ROiBb9r+j1KMUJSybQ AMBecLsl4XwKmtXsD+v/t1+0VUvzspJSTsgxpQNBZSZG4+qSiHXrmVopCiYx4dC9FX iHfvmrMH1/YHPoQkYodCmvKtDI3DnTjVUPUC2DFA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jianlin Shi , Hangbin Liu , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.15 552/913] bareudp: use ipv6_mod_enabled to check if IPv6 enabled Date: Tue, 5 Apr 2022 09:26:54 +0200 Message-Id: <20220405070356.393753958@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hangbin Liu [ Upstream commit e077ed58c243afc197bc2a2ba0e1ff61135e4ec2 ] bareudp_create_sock() use AF_INET6 by default if IPv6 CONFIG enabled. But if user start kernel with ipv6.disable=1, the bareudp sock will created failed, which cause the interface open failed even with ethertype ip. e.g. # ip link add bareudp1 type bareudp dstport 2 ethertype ip # ip link set bareudp1 up RTNETLINK answers: Address family not supported by protocol Fix it by using ipv6_mod_enabled() to check if IPv6 enabled. There is no need to check IS_ENABLED(CONFIG_IPV6) as ipv6_mod_enabled() will return false when CONFIG_IPV6 no enabled in include/linux/ipv6.h. Reported-by: Jianlin Shi Fixes: 571912c69f0e ("net: UDP tunnel encapsulation module for tunnelling different protocols like MPLS, IP, NSH etc.") Signed-off-by: Hangbin Liu Link: https://lore.kernel.org/r/20220315062618.156230-1-liuhangbin@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/bareudp.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/net/bareudp.c b/drivers/net/bareudp.c index 54e321a695ce..98c915943f32 100644 --- a/drivers/net/bareudp.c +++ b/drivers/net/bareudp.c @@ -141,14 +141,14 @@ static int bareudp_udp_encap_recv(struct sock *sk, struct sk_buff *skb) skb_reset_network_header(skb); skb_reset_mac_header(skb); - if (!IS_ENABLED(CONFIG_IPV6) || family == AF_INET) + if (!ipv6_mod_enabled() || family == AF_INET) err = IP_ECN_decapsulate(oiph, skb); else err = IP6_ECN_decapsulate(oiph, skb); if (unlikely(err)) { if (log_ecn_error) { - if (!IS_ENABLED(CONFIG_IPV6) || family == AF_INET) + if (!ipv6_mod_enabled() || family == AF_INET) net_info_ratelimited("non-ECT from %pI4 " "with TOS=%#x\n", &((struct iphdr *)oiph)->saddr, @@ -214,11 +214,12 @@ static struct socket *bareudp_create_sock(struct net *net, __be16 port) int err; memset(&udp_conf, 0, sizeof(udp_conf)); -#if IS_ENABLED(CONFIG_IPV6) - udp_conf.family = AF_INET6; -#else - udp_conf.family = AF_INET; -#endif + + if (ipv6_mod_enabled()) + udp_conf.family = AF_INET6; + else + udp_conf.family = AF_INET; + udp_conf.local_udp_port = port; /* Open UDP socket */ err = udp_sock_create(net, &udp_conf, &sock); @@ -441,7 +442,7 @@ static netdev_tx_t bareudp_xmit(struct sk_buff *skb, struct net_device *dev) } rcu_read_lock(); - if (IS_ENABLED(CONFIG_IPV6) && info->mode & IP_TUNNEL_INFO_IPV6) + if (ipv6_mod_enabled() && info->mode & IP_TUNNEL_INFO_IPV6) err = bareudp6_xmit_skb(skb, dev, bareudp, info); else err = bareudp_xmit_skb(skb, dev, bareudp, info); @@ -471,7 +472,7 @@ static int bareudp_fill_metadata_dst(struct net_device *dev, use_cache = ip_tunnel_dst_cache_usable(skb, info); - if (!IS_ENABLED(CONFIG_IPV6) || ip_tunnel_info_af(info) == AF_INET) { + if (!ipv6_mod_enabled() || ip_tunnel_info_af(info) == AF_INET) { struct rtable *rt; __be32 saddr; -- 2.34.1