summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Britstein <elibr@mellanox.com>2019-03-21 07:44:15 +0000
committerBen Pfaff <blp@ovn.org>2019-03-25 16:32:15 -0700
commit5f44aaba7b11ab11113de80cc45201076d35f32d (patch)
treefa4001b159b282ecfc764555e46725ae7666e6c6
parentc7ea79f544752d498429e4962e8bdaf6d4b90630 (diff)
downloadopenvswitch-5f44aaba7b11ab11113de80cc45201076d35f32d.tar.gz
Makefiles: Generate datapath ovs key fields macros
Generate datapath ovs key fields offset and size array macros as a pre-step for bit-wise comparing fields, with no functional change. Reviewed-by: Roi Dayan <roid@mellanox.com> Signed-off-by: Eli Britstein <elibr@mellanox.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
-rw-r--r--.gitignore1
-rwxr-xr-xbuild-aux/extract-odp-netlink-macros-h60
-rw-r--r--include/automake.mk11
3 files changed, 69 insertions, 3 deletions
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..7152f298c
--- /dev/null
+++ b/build-aux/extract-odp-netlink-macros-h
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+hfile=$1
+
+generate_fields_macros () {
+ local struct_name=$1
+ local line_start
+ local num_lines
+ local line_end
+ local awk_cmd
+ local STRUCT
+
+ # 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 <struct name> and field <field_name>
+ # 2 awk fields are for type <type> and field <field_name>
+ # else - terminating the array by item {0, 0}
+ awk_cmd="'{"
+ awk_cmd=$awk_cmd' if (NF == 3)'
+ awk_cmd=$awk_cmd' print " {offsetof(struct '"${struct_name}"', "$3"), sizeof("$1,$2")}, \\";'
+ awk_cmd=$awk_cmd' else if (NF == 2)'
+ awk_cmd=$awk_cmd' print " {offsetof(struct '"${struct_name}"', "$2"), sizeof(" $1")}, \\";'
+ awk_cmd=$awk_cmd' else'
+ awk_cmd=$awk_cmd' print " {0, 0}}";'
+ awk_cmd=$awk_cmd"}'"
+ awk -F ";" "NR>${line_start} && NR<=${line_end}"' {print $1}' $hfile | eval "awk $awk_cmd"
+
+ echo
+ echo
+}
+
+echo "/* Generated automatically from <include/odp-netlink.h> -- 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..01031e88d 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)sh -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