From patchwork Mon Oct 21 20:09:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Croce X-Patchwork-Id: 1180839 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="iuWukpnh"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46xnnr44ySz9s7T for ; Tue, 22 Oct 2019 07:10:56 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730294AbfJUUKb (ORCPT ); Mon, 21 Oct 2019 16:10:31 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:53971 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726672AbfJUUKa (ORCPT ); Mon, 21 Oct 2019 16:10:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571688629; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tIRfkARawuYx5E17weGS9sdJ1VOiUwg/d8BMqTS+xF4=; b=iuWukpnhAp5fVoiPpV1ZhizQuaprjNdTX0ggFKuwzBko00BXMW67Q01WxdvcoiCWndl6L+ uVjqRtq9QRJGNyPm3XzeDlmRQ+sHpk6TrVga1qTErhVKtJRji1Ww3rFQIfUQ6AhE8TOqjP FuuMLOJxPBN1msbcS4lc7EOfz4xo5aU= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-168-6Buyy3G_MOCrG4jyuVyEoA-1; Mon, 21 Oct 2019 16:10:27 -0400 Received: by mail-wm1-f72.google.com with SMTP id i23so29707wmb.3 for ; Mon, 21 Oct 2019 13:10:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SMEGf4c6Ma+Bze2+ZiGp43bjN8huF03EIdt6wvA9wXw=; b=EzoMQPMGhZ9vQ1ZeM8NFbReM1xyIVUaPeNailtbhXQyMsVrT6/iYc+e7tZiOc8gS9l BA6qEar7py4eQKowS9gConjZhU8dhSJUiDjP875jpW0XkQ59M19kvJCX3PX69knUjpL6 afw5fArSTlJLIXHtzM6UqDoyGCRaNvLC15EPidN/VJ7S6fbwmeKrkyE36VvQWlDWIdxE p0a9WlHgUrqVLEono/nBuVi9jhFvRlpjk7OP594qfnQILKYepLHE3njc1KnyS+xUk3vj IL0eJAE054OdhGtsHV4jlLdsZMxX4BcUENOcpOrdgt0DtJB0ZYks39kOCkKw1gL6RRrl mnIw== X-Gm-Message-State: APjAAAXvAWd+YskcW4rl+aY2VqpCGesKM7ZEoXUuuSmE9p+45dYGTXSj id8/0oCbSNV4JU+Bbm1ZdGaykgx9Gs8weVM1qQYqmdLlZ341KH8IhDfYzxdaib514WT24ch+DOD UQHEF0GzD7UX1t4qQ X-Received: by 2002:a1c:c912:: with SMTP id f18mr8901558wmb.168.1571688626069; Mon, 21 Oct 2019 13:10:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqx15FjYZFXXvyV63hNCvlR9L6mdwPxb6AMjC6rMphOyiOSYm40k8lVTtPDL8hhtsd7I1xplIA== X-Received: by 2002:a1c:c912:: with SMTP id f18mr8901544wmb.168.1571688625838; Mon, 21 Oct 2019 13:10:25 -0700 (PDT) Received: from turbo.teknoraver.net (net-109-115-41-234.cust.vodafonedsl.it. [109.115.41.234]) by smtp.gmail.com with ESMTPSA id l18sm20701933wrn.48.2019.10.21.13.10.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 13:10:25 -0700 (PDT) From: Matteo Croce To: netdev@vger.kernel.org Cc: Jay Vosburgh , Veaceslav Falico , Andy Gospodarek , "David S . Miller " , Stanislav Fomichev , Daniel Borkmann , Song Liu , Alexei Starovoitov , Paul Blakey , linux-kernel@vger.kernel.org Subject: [PATCH net-next 1/4] flow_dissector: add meaningful comments Date: Mon, 21 Oct 2019 22:09:45 +0200 Message-Id: <20191021200948.23775-2-mcroce@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191021200948.23775-1-mcroce@redhat.com> References: <20191021200948.23775-1-mcroce@redhat.com> MIME-Version: 1.0 X-MC-Unique: 6Buyy3G_MOCrG4jyuVyEoA-1 X-Mimecast-Spam-Score: 0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Documents two piece of code which can't be understood at a glance. Signed-off-by: Matteo Croce Reviewed-by: Simon Horman --- include/net/flow_dissector.h | 1 + net/core/flow_dissector.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/include/net/flow_dissector.h b/include/net/flow_dissector.h index 90bd210be060..7747af3cc500 100644 --- a/include/net/flow_dissector.h +++ b/include/net/flow_dissector.h @@ -282,6 +282,7 @@ struct flow_keys { struct flow_dissector_key_vlan cvlan; struct flow_dissector_key_keyid keyid; struct flow_dissector_key_ports ports; + /* 'addrs' must be the last member */ struct flow_dissector_key_addrs addrs; }; diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c index 7c09d87d3269..affde70dad47 100644 --- a/net/core/flow_dissector.c +++ b/net/core/flow_dissector.c @@ -1374,6 +1374,9 @@ static inline size_t flow_keys_hash_length(const struct flow_keys *flow) { size_t diff = FLOW_KEYS_HASH_OFFSET + sizeof(flow->addrs); BUILD_BUG_ON((sizeof(*flow) - FLOW_KEYS_HASH_OFFSET) % sizeof(u32)); + /* flow.addrs MUST be the last member in struct flow_keys because + * different L3 protocols have different address length + */ BUILD_BUG_ON(offsetof(typeof(*flow), addrs) != sizeof(*flow) - sizeof(flow->addrs)); @@ -1421,6 +1424,9 @@ __be32 flow_get_u32_dst(const struct flow_keys *flow) } EXPORT_SYMBOL(flow_get_u32_dst); +/* Sort the source and destination IP (and the ports if the IP are the same), + * to have consistent hash within the two directions + */ static inline void __flow_hash_consistentify(struct flow_keys *keys) { int addr_diff, i;