[ovs-dev,v1] odp-util: calc checksum of ip hdr for tunnel encap
diff mbox series

Message ID 1569285533-10496-1-git-send-email-martinbj2008@gmail.com
State New
Headers show
Series
  • [ovs-dev,v1] odp-util: calc checksum of ip hdr for tunnel encap
Related show

Commit Message

Martin Zhang Sept. 24, 2019, 12:38 a.m. UTC
From: Martin Zhang <martinbj2008@gmail.com>

When parse tnl_push, if IPv4 is used,
we forget to fill the ipv4 checksum fields.

In the patch:
csum has been used as a variable,
so we neeed rename it to udp_csum.

Signed-off-by: Martin Zhang <martinbj2008@gmail.com>
Signed-off-by: Dujie <dujie@didiglobal.com>
---
 lib/odp-util.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Ben Pfaff Sept. 25, 2019, 4:21 p.m. UTC | #1
On Tue, Sep 24, 2019 at 08:38:53AM +0800, martinbj2008@gmail.com wrote:
> From: Martin Zhang <martinbj2008@gmail.com>
> 
> When parse tnl_push, if IPv4 is used,
> we forget to fill the ipv4 checksum fields.
> 
> In the patch:
> csum has been used as a variable,
> so we neeed rename it to udp_csum.
> 
> Signed-off-by: Martin Zhang <martinbj2008@gmail.com>
> Signed-off-by: Dujie <dujie@didiglobal.com>

Thanks for the patch.

This fails to build for me:

      CC       lib/odp-util.lo
    ../lib/odp-util.c:1533:16: error: implicit declaration of function 'csum' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    ../lib/odp-util.c:1533:16: error: this function declaration is not a prototype [-Werror,-Wstrict-prototypes]

Patch
diff mbox series

diff --git a/lib/odp-util.c b/lib/odp-util.c
index fe59a56..fe539ec 100644
--- a/lib/odp-util.c
+++ b/lib/odp-util.c
@@ -1482,7 +1482,7 @@  ovs_parse_tnl_push(const char *s, struct ovs_action_push_tnl *data)
     struct gre_base_hdr *greh;
     struct erspan_base_hdr *ersh;
     struct erspan_md2 *md2;
-    uint16_t gre_proto, gre_flags, dl_type, udp_src, udp_dst, csum, sid;
+    uint16_t gre_proto, gre_flags, dl_type, udp_src, udp_dst, udp_csum, sid;
     ovs_be32 sip, dip;
     uint32_t tnl_type = 0, header_len = 0, ip_len = 0, erspan_idx = 0;
     void *l3, *l4;
@@ -1516,6 +1516,7 @@  ovs_parse_tnl_push(const char *s, struct ovs_action_push_tnl *data)
     if (eth->eth_type == htons(ETH_TYPE_IP)) {
         /* IPv4 */
         uint16_t ip_frag_off;
+	memset(ip, 0, sizeof(*ip));
         if (!ovs_scan_len(s, &n, "ipv4(src="IP_SCAN_FMT",dst="IP_SCAN_FMT",proto=%"SCNi8
                           ",tos=%"SCNi8",ttl=%"SCNi8",frag=0x%"SCNx16"),",
                           IP_SCAN_ARGS(&sip),
@@ -1529,6 +1530,7 @@  ovs_parse_tnl_push(const char *s, struct ovs_action_push_tnl *data)
         ip->ip_frag_off = htons(ip_frag_off);
         ip->ip_ihl_ver = IP_IHL_VER(5, 4);
         ip_len = sizeof *ip;
+	ip->ip_csum = csum(ip, ip_len);
     } else {
         char sip6_s[IPV6_SCAN_LEN + 1];
         char dip6_s[IPV6_SCAN_LEN + 1];
@@ -1557,13 +1559,13 @@  ovs_parse_tnl_push(const char *s, struct ovs_action_push_tnl *data)
     udp = (struct udp_header *) l4;
     greh = (struct gre_base_hdr *) l4;
     if (ovs_scan_len(s, &n, "udp(src=%"SCNi16",dst=%"SCNi16",csum=0x%"SCNx16"),",
-                     &udp_src, &udp_dst, &csum)) {
+                     &udp_src, &udp_dst, &udp_csum)) {
         uint32_t vx_flags, vni;
 
         udp->udp_src = htons(udp_src);
         udp->udp_dst = htons(udp_dst);
         udp->udp_len = 0;
-        udp->udp_csum = htons(csum);
+        udp->udp_csum = htons(udp_csum);
 
         if (ovs_scan_len(s, &n, "vxlan(flags=0x%"SCNx32",vni=0x%"SCNx32"))",
                          &vx_flags, &vni)) {
@@ -1629,6 +1631,7 @@  ovs_parse_tnl_push(const char *s, struct ovs_action_push_tnl *data)
         ovs_16aligned_be32 *options = (ovs_16aligned_be32 *) (greh + 1);
 
         if (greh->flags & htons(GRE_CSUM)) {
+            uint16_t csum;
             if (!ovs_scan_len(s, &n, ",csum=0x%"SCNx16, &csum)) {
                 return -EINVAL;
             }