selftests: mlxsw: devlink_trap_tunnel_ipip: Remove code duplication
authorAmit Cohen <amcohen@nvidia.com>
Fri, 8 Oct 2021 13:12:40 +0000 (16:12 +0300)
committerDavid S. Miller <davem@davemloft.net>
Fri, 8 Oct 2021 15:40:59 +0000 (16:40 +0100)
As part of adding same test for GRE tunnel with IPv6 underlay, an
optional improvement was found - call ipip_payload_get from
ecn_payload_get, so do not duplicate the code which creates the payload.

Signed-off-by: Amit Cohen <amcohen@nvidia.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
tools/testing/selftests/drivers/net/mlxsw/devlink_trap_tunnel_ipip.sh

index e2ab26b790a0273568882968aacd91b37d8365b9..c072c1633f1de50930b1ef69c73f7279b0cfadba 100755 (executable)
@@ -116,12 +116,16 @@ cleanup()
        forwarding_restore
 }
 
-ecn_payload_get()
+ipip_payload_get()
 {
+       local flags=$1; shift
+       local key=$1; shift
+
        p=$(:
-               )"0"$(                        : GRE flags
+               )"$flags"$(                   : GRE flags
                )"0:00:"$(                    : Reserved + version
                )"08:00:"$(                   : ETH protocol type
+               )"$key"$(                     : Key
                )"4"$(                        : IP version
                )"5:"$(                       : IHL
                )"00:"$(                      : IP TOS
@@ -137,6 +141,11 @@ ecn_payload_get()
        echo $p
 }
 
+ecn_payload_get()
+{
+       echo $(ipip_payload_get "0")
+}
+
 ecn_decap_test()
 {
        local trap_name="decap_error"
@@ -171,31 +180,6 @@ ecn_decap_test()
        tc filter del dev $swp1 egress protocol ip pref 1 handle 101 flower
 }
 
-ipip_payload_get()
-{
-       local flags=$1; shift
-       local key=$1; shift
-
-       p=$(:
-               )"$flags"$(                   : GRE flags
-               )"0:00:"$(                    : Reserved + version
-               )"08:00:"$(                   : ETH protocol type
-               )"$key"$(                     : Key
-               )"4"$(                        : IP version
-               )"5:"$(                       : IHL
-               )"00:"$(                      : IP TOS
-               )"00:14:"$(                   : IP total length
-               )"00:00:"$(                   : IP identification
-               )"20:00:"$(                   : IP flags + frag off
-               )"30:"$(                      : IP TTL
-               )"01:"$(                      : IP proto
-               )"E7:E6:"$(                   : IP header csum
-               )"C0:00:01:01:"$(             : IP saddr : 192.0.1.1
-               )"C0:00:02:01:"$(             : IP daddr : 192.0.2.1
-               )
-       echo $p
-}
-
 no_matching_tunnel_test()
 {
        local trap_name="decap_error"