From patchwork Sun Mar 10 05:31:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eli Britstein X-Patchwork-Id: 1053908 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=mellanox.com Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44H8yb4pxJz9s5c for ; Sun, 10 Mar 2019 16:32:55 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 9B24A8BF; Sun, 10 Mar 2019 05:32:21 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id DB14F870 for ; Sun, 10 Mar 2019 05:32:20 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by smtp1.linuxfoundation.org (Postfix) with ESMTP id CD2872D5 for ; Sun, 10 Mar 2019 05:32:19 +0000 (UTC) Received: from Internal Mail-Server by MTLPINE1 (envelope-from elibr@mellanox.com) with ESMTPS (AES256-SHA encrypted); 10 Mar 2019 07:32:15 +0200 Received: from dev-r-vrt-215.mtr.labs.mlnx. (dev-r-vrt-215.mtr.labs.mlnx [10.212.215.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x2A5WClS015669; Sun, 10 Mar 2019 07:32:15 +0200 From: Eli Britstein To: Ben Pfaff , dev@openvswitch.org Date: Sun, 10 Mar 2019 05:31:31 +0000 Message-Id: <20190310053132.17164-2-elibr@mellanox.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190310053132.17164-1-elibr@mellanox.com> References: <20190310053132.17164-1-elibr@mellanox.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Simon Horman , Eli Britstein , Andy Gospodarek Subject: [ovs-dev] [PATCH V6 1/2] Makefiles: Generate datapath ovs key fields macros X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Generate datapath ovs key fields offset and size array macros as a pre-step for bit-wise comparing fields, with no functional change. Signed-off-by: Eli Britstein Reviewed-by: Roi Dayan --- .gitignore | 1 + build-aux/extract-odp-netlink-macros-h | 55 ++++++++++++++++++++++++++ include/automake.mk | 11 ++++-- 3 files changed, 64 insertions(+), 3 deletions(-) create mode 100755 build-aux/extract-odp-netlink-macros-h diff --git a/.gitignore b/.gitignore index 60e7818c3..2ac9cdac7 100644 --- a/.gitignore +++ b/.gitignore @@ -68,6 +68,7 @@ cscope.* tags _debian odp-netlink.h +odp-netlink-macros.h OvsDpInterface.h /.vagrant/ testsuite.tmp.orig diff --git a/build-aux/extract-odp-netlink-macros-h b/build-aux/extract-odp-netlink-macros-h new file mode 100755 index 000000000..42be29ceb --- /dev/null +++ b/build-aux/extract-odp-netlink-macros-h @@ -0,0 +1,55 @@ +#!/bin/bash + +hfile=$1 + +function generate_fields_macros { + local struct_name=$1 + + # line_start is the line number where the definition of the struct begin + # line_end is the line number where the definition of the struct ends + line_start=`grep -nw $struct_name $hfile | grep { | cut -d ":" -f1` + num_lines=`tail -n +${line_start} $hfile | grep -n -m1 } | cut -d ":" -f1` + line_end=$((line_start+num_lines-1)) + + + STRUCT=`echo $struct_name | tr [a-z] [A-Z]` + echo "#define ${STRUCT}_OFFSETOF_SIZEOF_ARR { \\" + # for all the field lines, including the terminating }, remove ";" and + # replace with an item of {offsetof, sizeof}. + # 3 awk fields are for type struct and field + # 2 awk fields are for type and field + # else - terminating the array by item {0, 0} + awk_cmd="'{" + awk_cmd+=' if (NF == 3)' + awk_cmd+=' print " {offsetof(struct '"${struct_name}"', "$3"), sizeof("$1,$2")}, \\";' + awk_cmd+=' else if (NF == 2)' + awk_cmd+=' print " {offsetof(struct '"${struct_name}"', "$2"), sizeof(" $1")}, \\";' + awk_cmd+=' else' + awk_cmd+=' print " {0, 0}}";' + awk_cmd+="}'" + awk -F ";" "NR>${line_start} && NR<=${line_end}"' {print $1}' $hfile | eval "awk $awk_cmd" + + echo + echo +} + +echo "/* Generated automatically from -- do not modify! */" +echo "#ifndef ODP_NETLINK_MACROS_H" +echo "#define ODP_NETLINK_MACROS_H" +echo +echo + +generate_fields_macros "ovs_key_ethernet" +generate_fields_macros "ovs_key_ipv4" +generate_fields_macros "ovs_key_ipv6" +generate_fields_macros "ovs_key_tcp" +generate_fields_macros "ovs_key_udp" +generate_fields_macros "ovs_key_sctp" +generate_fields_macros "ovs_key_icmp" +generate_fields_macros "ovs_key_icmpv6" +generate_fields_macros "ovs_key_arp" +generate_fields_macros "ovs_key_nd" +generate_fields_macros "ovs_key_nd_extensions" + +echo +echo "#endif" diff --git a/include/automake.mk b/include/automake.mk index 3f3ed1ccd..f493feb93 100644 --- a/include/automake.mk +++ b/include/automake.mk @@ -1,10 +1,15 @@ -BUILT_SOURCES += include/odp-netlink.h +BUILT_SOURCES += include/odp-netlink.h include/odp-netlink-macros.h include/odp-netlink.h: datapath/linux/compat/include/linux/openvswitch.h \ build-aux/extract-odp-netlink-h $(AM_V_GEN)sed -f $(srcdir)/build-aux/extract-odp-netlink-h < $< > $@ -EXTRA_DIST += build-aux/extract-odp-netlink-h -CLEANFILES += include/odp-netlink.h + +include/odp-netlink-macros.h: include/odp-netlink.h \ + build-aux/extract-odp-netlink-macros-h + $(AM_V_GEN)bash -f $(srcdir)/build-aux/extract-odp-netlink-macros-h $< > $@ + +EXTRA_DIST += build-aux/extract-odp-netlink-h build-aux/extract-odp-netlink-macros-h +CLEANFILES += include/odp-netlink.h include/odp-netlink-macros.h include include/ovn/automake.mk include include/openflow/automake.mk