[v2] app/testpmd: fix mpls encap ipv4 version and ihl

Message ID 20190325130013.3737-1-salehals@mellanox.com
State New
Delegated to: Ferruh Yigit
Headers show
Series
  • [v2] app/testpmd: fix mpls encap ipv4 version and ihl
Related show

Checks

Context Check Description
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/intel-Performance-Testing success Performance Testing PASS
ci/Intel-compilation fail Compilation issues
ci/checkpatch success coding style OK

Commit Message

Saleh Alsouqi March 25, 2019, 1:01 p.m.
According to ietf rfc791 (see [1])

    "The Version field indicates the format of the
    internet header."

    "Internet Header Length (ihl) is the length of the
    internet header in 32 bit words, and thus points
    to the beginning of the data. Note that
    the minimum value for a correct header is 5."

Having version and ihl set to 0 would result in a
corrupted/incorrect encapsulating packet for MPLS,
this commit sets these fields to 4 and 5 respectively
as a default value.

[1] https://tools.ietf.org/html/rfc791

Fixes: 3e77031be855 ("app/testpmd: add MPLSoGRE encapsulation")
Fixes: a1191d39cb57 ("app/testpmd: add MPLSoUDP encapsulation")
Cc: stable@dpdk.org

Signed-off-by: Saleh Alsouqi <salehals@mellanox.com>
---
v2:
        - Include netinet/ip.h in librte_net/rte_ip.h
          to use existing definitions instead of defining
          our own.

        - Move definitions from testpmd.h to librte_net/rte_ip.h
---
 app/test-pmd/cmdline_flow.c | 6 ++++++
 lib/librte_net/rte_ip.h     | 5 +++++
 2 files changed, 11 insertions(+)

Comments

Ferruh Yigit March 25, 2019, 1:30 p.m. | #1
On 3/25/2019 1:01 PM, Saleh Alsouqi wrote:
> According to ietf rfc791 (see [1])
> 
>     "The Version field indicates the format of the
>     internet header."
> 
>     "Internet Header Length (ihl) is the length of the
>     internet header in 32 bit words, and thus points
>     to the beginning of the data. Note that
>     the minimum value for a correct header is 5."
> 
> Having version and ihl set to 0 would result in a
> corrupted/incorrect encapsulating packet for MPLS,
> this commit sets these fields to 4 and 5 respectively
> as a default value.
> 
> [1] https://tools.ietf.org/html/rfc791
> 
> Fixes: 3e77031be855 ("app/testpmd: add MPLSoGRE encapsulation")
> Fixes: a1191d39cb57 ("app/testpmd: add MPLSoUDP encapsulation")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Saleh Alsouqi <salehals@mellanox.com>
> ---
> v2:
>         - Include netinet/ip.h in librte_net/rte_ip.h
>           to use existing definitions instead of defining
>           our own.
> 
>         - Move definitions from testpmd.h to librte_net/rte_ip.h
> ---
>  app/test-pmd/cmdline_flow.c | 6 ++++++
>  lib/librte_net/rte_ip.h     | 5 +++++
>  2 files changed, 11 insertions(+)
> 
> diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
> index 36659a64a..f536307c9 100644
> --- a/app/test-pmd/cmdline_flow.c
> +++ b/app/test-pmd/cmdline_flow.c
> @@ -3767,11 +3767,14 @@ parse_vc_action_mplsogre_encap(struct context *ctx, const struct token *token,
>  			.src_addr = mplsogre_encap_conf.ipv4_src,
>  			.dst_addr = mplsogre_encap_conf.ipv4_dst,
>  			.next_proto_id = IPPROTO_GRE,
> +			.version_ihl = IPV4_VHL_DEF,
> +			.time_to_live = IPDEFTTL,
>  		},
>  	};
>  	struct rte_flow_item_ipv6 ipv6 = {
>  		.hdr =  {
>  			.proto = IPPROTO_GRE,
> +			.hop_limits = IPDEFTTL,
>  		},
>  	};
>  	struct rte_flow_item_gre gre = {
> @@ -3955,11 +3958,14 @@ parse_vc_action_mplsoudp_encap(struct context *ctx, const struct token *token,
>  			.src_addr = mplsoudp_encap_conf.ipv4_src,
>  			.dst_addr = mplsoudp_encap_conf.ipv4_dst,
>  			.next_proto_id = IPPROTO_UDP,
> +			.version_ihl = IPV4_VHL_DEF,
> +			.time_to_live = IPDEFTTL,
>  		},
>  	};
>  	struct rte_flow_item_ipv6 ipv6 = {
>  		.hdr =  {
>  			.proto = IPPROTO_UDP,
> +			.hop_limits = IPDEFTTL,
>  		},
>  	};
>  	struct rte_flow_item_udp udp = {
> diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h
> index f9b909090..499a2f79c 100644
> --- a/lib/librte_net/rte_ip.h
> +++ b/lib/librte_net/rte_ip.h
> @@ -17,6 +17,7 @@
>  
>  #include <stdint.h>
>  #include <netinet/in.h>
> +#include <netinet/ip.h>
>  
>  #include <rte_byteorder.h>
>  #include <rte_mbuf.h>
> @@ -89,6 +90,10 @@ struct ipv4_hdr {
>  #define IS_IPV4_MCAST(x) \
>  	((x) >= IPV4_MIN_MCAST && (x) <= IPV4_MAX_MCAST) /**< check if IPv4 address is multicast */
>  
> +/* IPv4 default fields values */
> +#define IPV4_MIN_IHL    (0x5)
> +#define IPV4_VHL_DEF    (IPVERSION | IPV4_MIN_IHL)

There are existing defines for this [1], since we have one in public header, can
you please replace them too,
perhaps in two patches, first one introduces this define and replaces old ones,
second one fixes the mpls issue?

[1]
$ git grep VHL | grep define
app/test-pmd/csumonly.c:#define IP_VHL_DEF (IP_VERSION | IP_HDRLEN)
app/test-pmd/flowgen.c:#define IP_VHL_DEF (IP_VERSION | IP_HDRLEN)
app/test-pmd/txonly.c:#define IP_VHL_DEF (IP_VERSION | IP_HDRLEN)
app/test/packet_burst_generator.c:#define IP_VHL_DEF (IP_VERSION | IP_HDRLEN)
examples/tep_termination/vxlan_setup.c:#define IP_VHL_DEF (IP_VERSION | IP_HDRLEN)


> +
>  /**
>   * @internal Calculate a sum of all words in the buffer.
>   * Helper routine for the rte_raw_cksum().
>
Ferruh Yigit April 16, 2019, 9:59 a.m. | #2
On 3/25/2019 1:30 PM, Ferruh Yigit wrote:
> On 3/25/2019 1:01 PM, Saleh Alsouqi wrote:
>> According to ietf rfc791 (see [1])
>>
>>     "The Version field indicates the format of the
>>     internet header."
>>
>>     "Internet Header Length (ihl) is the length of the
>>     internet header in 32 bit words, and thus points
>>     to the beginning of the data. Note that
>>     the minimum value for a correct header is 5."
>>
>> Having version and ihl set to 0 would result in a
>> corrupted/incorrect encapsulating packet for MPLS,
>> this commit sets these fields to 4 and 5 respectively
>> as a default value.
>>
>> [1] https://tools.ietf.org/html/rfc791
>>
>> Fixes: 3e77031be855 ("app/testpmd: add MPLSoGRE encapsulation")
>> Fixes: a1191d39cb57 ("app/testpmd: add MPLSoUDP encapsulation")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Saleh Alsouqi <salehals@mellanox.com>
>> ---
>> v2:
>>         - Include netinet/ip.h in librte_net/rte_ip.h
>>           to use existing definitions instead of defining
>>           our own.
>>
>>         - Move definitions from testpmd.h to librte_net/rte_ip.h
>> ---
>>  app/test-pmd/cmdline_flow.c | 6 ++++++
>>  lib/librte_net/rte_ip.h     | 5 +++++
>>  2 files changed, 11 insertions(+)
>>
>> diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
>> index 36659a64a..f536307c9 100644
>> --- a/app/test-pmd/cmdline_flow.c
>> +++ b/app/test-pmd/cmdline_flow.c
>> @@ -3767,11 +3767,14 @@ parse_vc_action_mplsogre_encap(struct context *ctx, const struct token *token,
>>  			.src_addr = mplsogre_encap_conf.ipv4_src,
>>  			.dst_addr = mplsogre_encap_conf.ipv4_dst,
>>  			.next_proto_id = IPPROTO_GRE,
>> +			.version_ihl = IPV4_VHL_DEF,
>> +			.time_to_live = IPDEFTTL,
>>  		},
>>  	};
>>  	struct rte_flow_item_ipv6 ipv6 = {
>>  		.hdr =  {
>>  			.proto = IPPROTO_GRE,
>> +			.hop_limits = IPDEFTTL,
>>  		},
>>  	};
>>  	struct rte_flow_item_gre gre = {
>> @@ -3955,11 +3958,14 @@ parse_vc_action_mplsoudp_encap(struct context *ctx, const struct token *token,
>>  			.src_addr = mplsoudp_encap_conf.ipv4_src,
>>  			.dst_addr = mplsoudp_encap_conf.ipv4_dst,
>>  			.next_proto_id = IPPROTO_UDP,
>> +			.version_ihl = IPV4_VHL_DEF,
>> +			.time_to_live = IPDEFTTL,
>>  		},
>>  	};
>>  	struct rte_flow_item_ipv6 ipv6 = {
>>  		.hdr =  {
>>  			.proto = IPPROTO_UDP,
>> +			.hop_limits = IPDEFTTL,
>>  		},
>>  	};
>>  	struct rte_flow_item_udp udp = {
>> diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h
>> index f9b909090..499a2f79c 100644
>> --- a/lib/librte_net/rte_ip.h
>> +++ b/lib/librte_net/rte_ip.h
>> @@ -17,6 +17,7 @@
>>  
>>  #include <stdint.h>
>>  #include <netinet/in.h>
>> +#include <netinet/ip.h>
>>  
>>  #include <rte_byteorder.h>
>>  #include <rte_mbuf.h>
>> @@ -89,6 +90,10 @@ struct ipv4_hdr {
>>  #define IS_IPV4_MCAST(x) \
>>  	((x) >= IPV4_MIN_MCAST && (x) <= IPV4_MAX_MCAST) /**< check if IPv4 address is multicast */
>>  
>> +/* IPv4 default fields values */
>> +#define IPV4_MIN_IHL    (0x5)
>> +#define IPV4_VHL_DEF    (IPVERSION | IPV4_MIN_IHL)
> 
> There are existing defines for this [1], since we have one in public header, can
> you please replace them too,
> perhaps in two patches, first one introduces this define and replaces old ones,
> second one fixes the mpls issue?
> 
> [1]
> $ git grep VHL | grep define
> app/test-pmd/csumonly.c:#define IP_VHL_DEF (IP_VERSION | IP_HDRLEN)
> app/test-pmd/flowgen.c:#define IP_VHL_DEF (IP_VERSION | IP_HDRLEN)
> app/test-pmd/txonly.c:#define IP_VHL_DEF (IP_VERSION | IP_HDRLEN)
> app/test/packet_burst_generator.c:#define IP_VHL_DEF (IP_VERSION | IP_HDRLEN)
> examples/tep_termination/vxlan_setup.c:#define IP_VHL_DEF (IP_VERSION | IP_HDRLEN)

Let me get this as it is, and I will send another patch to update existing defines.

Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
Ferruh Yigit April 16, 2019, 10:02 a.m. | #3
On 4/16/2019 10:59 AM, Ferruh Yigit wrote:
> On 3/25/2019 1:30 PM, Ferruh Yigit wrote:
>> On 3/25/2019 1:01 PM, Saleh Alsouqi wrote:
>>> According to ietf rfc791 (see [1])
>>>
>>>     "The Version field indicates the format of the
>>>     internet header."
>>>
>>>     "Internet Header Length (ihl) is the length of the
>>>     internet header in 32 bit words, and thus points
>>>     to the beginning of the data. Note that
>>>     the minimum value for a correct header is 5."
>>>
>>> Having version and ihl set to 0 would result in a
>>> corrupted/incorrect encapsulating packet for MPLS,
>>> this commit sets these fields to 4 and 5 respectively
>>> as a default value.
>>>
>>> [1] https://tools.ietf.org/html/rfc791
>>>
>>> Fixes: 3e77031be855 ("app/testpmd: add MPLSoGRE encapsulation")
>>> Fixes: a1191d39cb57 ("app/testpmd: add MPLSoUDP encapsulation")
>>> Cc: stable@dpdk.org
>>>
>>> Signed-off-by: Saleh Alsouqi <salehals@mellanox.com>
>>> ---
>>> v2:
>>>         - Include netinet/ip.h in librte_net/rte_ip.h
>>>           to use existing definitions instead of defining
>>>           our own.
>>>
>>>         - Move definitions from testpmd.h to librte_net/rte_ip.h
>>> ---
>>>  app/test-pmd/cmdline_flow.c | 6 ++++++
>>>  lib/librte_net/rte_ip.h     | 5 +++++
>>>  2 files changed, 11 insertions(+)
>>>
>>> diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
>>> index 36659a64a..f536307c9 100644
>>> --- a/app/test-pmd/cmdline_flow.c
>>> +++ b/app/test-pmd/cmdline_flow.c
>>> @@ -3767,11 +3767,14 @@ parse_vc_action_mplsogre_encap(struct context *ctx, const struct token *token,
>>>  			.src_addr = mplsogre_encap_conf.ipv4_src,
>>>  			.dst_addr = mplsogre_encap_conf.ipv4_dst,
>>>  			.next_proto_id = IPPROTO_GRE,
>>> +			.version_ihl = IPV4_VHL_DEF,
>>> +			.time_to_live = IPDEFTTL,
>>>  		},
>>>  	};
>>>  	struct rte_flow_item_ipv6 ipv6 = {
>>>  		.hdr =  {
>>>  			.proto = IPPROTO_GRE,
>>> +			.hop_limits = IPDEFTTL,
>>>  		},
>>>  	};
>>>  	struct rte_flow_item_gre gre = {
>>> @@ -3955,11 +3958,14 @@ parse_vc_action_mplsoudp_encap(struct context *ctx, const struct token *token,
>>>  			.src_addr = mplsoudp_encap_conf.ipv4_src,
>>>  			.dst_addr = mplsoudp_encap_conf.ipv4_dst,
>>>  			.next_proto_id = IPPROTO_UDP,
>>> +			.version_ihl = IPV4_VHL_DEF,
>>> +			.time_to_live = IPDEFTTL,
>>>  		},
>>>  	};
>>>  	struct rte_flow_item_ipv6 ipv6 = {
>>>  		.hdr =  {
>>>  			.proto = IPPROTO_UDP,
>>> +			.hop_limits = IPDEFTTL,
>>>  		},
>>>  	};
>>>  	struct rte_flow_item_udp udp = {
>>> diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h
>>> index f9b909090..499a2f79c 100644
>>> --- a/lib/librte_net/rte_ip.h
>>> +++ b/lib/librte_net/rte_ip.h
>>> @@ -17,6 +17,7 @@
>>>  
>>>  #include <stdint.h>
>>>  #include <netinet/in.h>
>>> +#include <netinet/ip.h>
>>>  
>>>  #include <rte_byteorder.h>
>>>  #include <rte_mbuf.h>
>>> @@ -89,6 +90,10 @@ struct ipv4_hdr {
>>>  #define IS_IPV4_MCAST(x) \
>>>  	((x) >= IPV4_MIN_MCAST && (x) <= IPV4_MAX_MCAST) /**< check if IPv4 address is multicast */
>>>  
>>> +/* IPv4 default fields values */
>>> +#define IPV4_MIN_IHL    (0x5)
>>> +#define IPV4_VHL_DEF    (IPVERSION | IPV4_MIN_IHL)
>>
>> There are existing defines for this [1], since we have one in public header, can
>> you please replace them too,
>> perhaps in two patches, first one introduces this define and replaces old ones,
>> second one fixes the mpls issue?
>>
>> [1]
>> $ git grep VHL | grep define
>> app/test-pmd/csumonly.c:#define IP_VHL_DEF (IP_VERSION | IP_HDRLEN)
>> app/test-pmd/flowgen.c:#define IP_VHL_DEF (IP_VERSION | IP_HDRLEN)
>> app/test-pmd/txonly.c:#define IP_VHL_DEF (IP_VERSION | IP_HDRLEN)
>> app/test/packet_burst_generator.c:#define IP_VHL_DEF (IP_VERSION | IP_HDRLEN)
>> examples/tep_termination/vxlan_setup.c:#define IP_VHL_DEF (IP_VERSION | IP_HDRLEN)
> 
> Let me get this as it is, and I will send another patch to update existing defines.
> 
> Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
> 

Ahh, this seems causing build errors in FreeBSD:
http://mails.dpdk.org/archives/test-report/2019-March/077811.html

Patch

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 36659a64a..f536307c9 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -3767,11 +3767,14 @@  parse_vc_action_mplsogre_encap(struct context *ctx, const struct token *token,
 			.src_addr = mplsogre_encap_conf.ipv4_src,
 			.dst_addr = mplsogre_encap_conf.ipv4_dst,
 			.next_proto_id = IPPROTO_GRE,
+			.version_ihl = IPV4_VHL_DEF,
+			.time_to_live = IPDEFTTL,
 		},
 	};
 	struct rte_flow_item_ipv6 ipv6 = {
 		.hdr =  {
 			.proto = IPPROTO_GRE,
+			.hop_limits = IPDEFTTL,
 		},
 	};
 	struct rte_flow_item_gre gre = {
@@ -3955,11 +3958,14 @@  parse_vc_action_mplsoudp_encap(struct context *ctx, const struct token *token,
 			.src_addr = mplsoudp_encap_conf.ipv4_src,
 			.dst_addr = mplsoudp_encap_conf.ipv4_dst,
 			.next_proto_id = IPPROTO_UDP,
+			.version_ihl = IPV4_VHL_DEF,
+			.time_to_live = IPDEFTTL,
 		},
 	};
 	struct rte_flow_item_ipv6 ipv6 = {
 		.hdr =  {
 			.proto = IPPROTO_UDP,
+			.hop_limits = IPDEFTTL,
 		},
 	};
 	struct rte_flow_item_udp udp = {
diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h
index f9b909090..499a2f79c 100644
--- a/lib/librte_net/rte_ip.h
+++ b/lib/librte_net/rte_ip.h
@@ -17,6 +17,7 @@ 
 
 #include <stdint.h>
 #include <netinet/in.h>
+#include <netinet/ip.h>
 
 #include <rte_byteorder.h>
 #include <rte_mbuf.h>
@@ -89,6 +90,10 @@  struct ipv4_hdr {
 #define IS_IPV4_MCAST(x) \
 	((x) >= IPV4_MIN_MCAST && (x) <= IPV4_MAX_MCAST) /**< check if IPv4 address is multicast */
 
+/* IPv4 default fields values */
+#define IPV4_MIN_IHL    (0x5)
+#define IPV4_VHL_DEF    (IPVERSION | IPV4_MIN_IHL)
+
 /**
  * @internal Calculate a sum of all words in the buffer.
  * Helper routine for the rte_raw_cksum().