Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp103217iog; Sun, 12 Jun 2022 20:31:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxB2DRaRGUh4M5F6QOARXPhtO8j3fg92niiv9BT+awJ66Tqr6tp2tFqz8yrEiePzsp5H3iy X-Received: by 2002:aa7:d295:0:b0:42d:e371:ded2 with SMTP id w21-20020aa7d295000000b0042de371ded2mr63989832edq.336.1655091060515; Sun, 12 Jun 2022 20:31:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655091060; cv=none; d=google.com; s=arc-20160816; b=HgKRQ0Hf3FE7eMvrDC/JgAJUCI+N8hghXzSzgqphng6IPVAXoLk0rbnzr64a/Fx/s3 pfQCqpln3JokndCimjx+Ail5V3pj8xymYImm+NXvLFq0K4+iVwZioZXDdY/E/kTp9fAc Cv0mni4FzV6hR0zbxcCU73sQobgXGyzjy2mgtC7zy+6AOf0Zbltf4uBhpb03K66kISpV y07d4OQFCLdx3zfKuTHMe1Xm95QadK1tf41IUy/vYauBQe8UbMrUBOgclbg5rNjvqfp0 hQyM+A2sn+akp6Q5ymqHivYD8WoJtBWcNd6gapi2W+piOWtGZEZcfPwSCbV0jAB7i/Yt Ofpg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5I2dj+cT/NCOtepo3+g1dbElxr84BofmUvMaWRJaUh0=; b=rHGO5w5kG5TwMRqAFb/AAorA/56MJfXCn4uYiPJChMyU6jcnL2Jv97roUVYlq3nNUs 1+S1VX1stjPm/VESscjSTmkBKGW70P1UPt8XugQBlxK+xP2CuhQXSX53OY9IEpazG6r+ XM3R7BpSpyrYDebE3Pa4RxenfZuPcGN1QCinHTqKDDzCWoqS7PSh1WWHHGwu5JO40T1s DrlWOnkBKJu41g4i8uLGSAYYfeW+lTIwbpnIfTlBb+JzsO/EqB3yFiqPzi2S4u0CYrgu yKqaMP0Q9wBQ3MIlOcdEQBGjVhQw7NkRseaTE1LkxbAqYDd97NY9voCaZYfwmKpIjdYt md2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fULwAz8n; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o8-20020a056402438800b0042e28c90fe7si6318648edc.19.2022.06.12.20.30.16; Sun, 12 Jun 2022 20:31:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fULwAz8n; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229682AbiFMDaG (ORCPT + 99 others); Sun, 12 Jun 2022 23:30:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231920AbiFMDaF (ORCPT ); Sun, 12 Jun 2022 23:30:05 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E7CD02125B for ; Sun, 12 Jun 2022 20:30:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655090998; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5I2dj+cT/NCOtepo3+g1dbElxr84BofmUvMaWRJaUh0=; b=fULwAz8nnSv5gpdIfVE7LR2D85ezEbyiyc8jxxAlLmr5vnN3ELfz5y0Up570EQdKIVr7Sm NHbvAipumWzzjaaEa3KKm4XPUTfmGA5yGn2p1Si9ptZtm+I7xTey+T7nUaZuCbdw0sre5T O8rSqQw1Kt0f1ZtNMDJ7T2FEwfx54gk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-184-svD0vTKlMtOGHnns9fA-FA-1; Sun, 12 Jun 2022 23:29:53 -0400 X-MC-Unique: svD0vTKlMtOGHnns9fA-FA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E80E2185A79C; Mon, 13 Jun 2022 03:29:52 +0000 (UTC) Received: from fs-i40c-03.fs.lab.eng.bos.redhat.com (fs-i40c-03.fs.lab.eng.bos.redhat.com [10.16.224.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id C0E00492C3B; Mon, 13 Jun 2022 03:29:52 +0000 (UTC) From: Alexander Aring To: stefan@datenfreihafen.org Cc: linux-wpan@vger.kernel.org, linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org, aahringo@redhat.com Subject: [PATCH wpan-next 2/2] 6lowpan: nhc: drop EEXIST limitation Date: Sun, 12 Jun 2022 23:29:22 -0400 Message-Id: <20220613032922.1030739-2-aahringo@redhat.com> In-Reply-To: <20220613032922.1030739-1-aahringo@redhat.com> References: <20220613032922.1030739-1-aahringo@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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-bluetooth@vger.kernel.org In nhc we have compression() and uncompression(). Currently we have a limitation that we return -EEXIST when it's the nhc is already registered according the nexthdr. But on receiving handling and the nhcid we can indeed support both at the same time. We remove the current static array implementation and replace it by a dynamic list handling to get rid of this limitation. Signed-off-by: Alexander Aring --- net/6lowpan/nhc.c | 69 ++++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/net/6lowpan/nhc.c b/net/6lowpan/nhc.c index 7b374595328d..3d7c50139142 100644 --- a/net/6lowpan/nhc.c +++ b/net/6lowpan/nhc.c @@ -12,13 +12,30 @@ #include "nhc.h" -static const struct lowpan_nhc *lowpan_nexthdr_nhcs[NEXTHDR_MAX + 1]; +struct lowpan_nhc_entry { + const struct lowpan_nhc *nhc; + struct list_head list; +}; + static DEFINE_SPINLOCK(lowpan_nhc_lock); +static LIST_HEAD(lowpan_nexthdr_nhcs); + +const struct lowpan_nhc *lowpan_nhc_by_nexthdr(u8 nexthdr) +{ + const struct lowpan_nhc_entry *e; + + list_for_each_entry(e, &lowpan_nexthdr_nhcs, list) { + if (e->nhc->nexthdr == nexthdr && + e->nhc->compress) + return e->nhc; + } + + return NULL; +} static const struct lowpan_nhc *lowpan_nhc_by_nhcid(struct sk_buff *skb) { - const struct lowpan_nhc *nhc; - int i; + const struct lowpan_nhc_entry *e; u8 id; if (!pskb_may_pull(skb, 1)) @@ -26,13 +43,9 @@ static const struct lowpan_nhc *lowpan_nhc_by_nhcid(struct sk_buff *skb) id = *skb->data; - for (i = 0; i < NEXTHDR_MAX + 1; i++) { - nhc = lowpan_nexthdr_nhcs[i]; - if (!nhc) - continue; - - if ((id & nhc->idmask) == nhc->id) - return nhc; + list_for_each_entry(e, &lowpan_nexthdr_nhcs, list) { + if ((id & e->nhc->idmask) == e->nhc->id) + return e->nhc; } return NULL; @@ -46,8 +59,8 @@ int lowpan_nhc_check_compression(struct sk_buff *skb, spin_lock_bh(&lowpan_nhc_lock); - nhc = lowpan_nexthdr_nhcs[hdr->nexthdr]; - if (!(nhc && nhc->compress)) + nhc = lowpan_nhc_by_nexthdr(hdr->nexthdr); + if (!nhc) ret = -ENOENT; spin_unlock_bh(&lowpan_nhc_lock); @@ -63,7 +76,7 @@ int lowpan_nhc_do_compression(struct sk_buff *skb, const struct ipv6hdr *hdr, spin_lock_bh(&lowpan_nhc_lock); - nhc = lowpan_nexthdr_nhcs[hdr->nexthdr]; + nhc = lowpan_nhc_by_nexthdr(hdr->nexthdr); /* check if the nhc module was removed in unlocked part. * TODO: this is a workaround we should prevent unloading * of nhc modules while unlocked part, this will always drop @@ -140,28 +153,34 @@ int lowpan_nhc_do_uncompression(struct sk_buff *skb, int lowpan_nhc_add(const struct lowpan_nhc *nhc) { - int ret = 0; + struct lowpan_nhc_entry *e; - spin_lock_bh(&lowpan_nhc_lock); + e = kmalloc(sizeof(*e), GFP_KERNEL); + if (!e) + return -ENOMEM; - if (lowpan_nexthdr_nhcs[nhc->nexthdr]) { - ret = -EEXIST; - goto out; - } + e->nhc = nhc; - lowpan_nexthdr_nhcs[nhc->nexthdr] = nhc; -out: + spin_lock_bh(&lowpan_nhc_lock); + list_add(&e->list, &lowpan_nexthdr_nhcs); spin_unlock_bh(&lowpan_nhc_lock); - return ret; + + return 0; } EXPORT_SYMBOL(lowpan_nhc_add); void lowpan_nhc_del(const struct lowpan_nhc *nhc) { - spin_lock_bh(&lowpan_nhc_lock); - - lowpan_nexthdr_nhcs[nhc->nexthdr] = NULL; + struct lowpan_nhc_entry *e, *tmp; + spin_lock_bh(&lowpan_nhc_lock); + list_for_each_entry_safe(e, tmp, &lowpan_nexthdr_nhcs, list) { + if (e->nhc == nhc) { + list_del(&e->list); + kfree(e); + break; + } + } spin_unlock_bh(&lowpan_nhc_lock); synchronize_net(); -- 2.31.1