Message ID | 1399898422-16527-1-git-send-email-weilong.chen@linaro.org |
---|---|
State | Not Applicable |
Headers | show |
Hi Weilong, please check this patch according to the latest code. There is some code difference and it will be good to test it before submitting. Thanks, Maxim. On 05/12/2014 04:40 PM, Weilong Chen wrote: > Signed-off-by: Weilong Chen <weilong.chen@linaro.org> > --- > include/helper/odp_udp.h | 32 +++++++++++++++++++++----------- > 1 file changed, 21 insertions(+), 11 deletions(-) > > diff --git a/include/helper/odp_udp.h b/include/helper/odp_udp.h > index 28313ab..c984dc0 100644 > --- a/include/helper/odp_udp.h > +++ b/include/helper/odp_udp.h > @@ -33,6 +33,14 @@ typedef struct ODP_PACKED { > uint16be_t chksum; /**< UDP header and data checksum (0 if not used)*/ > } odp_udphdr_t; > > +/** UDP pseudo header */ > +typedef struct ODP_PACKET { > + uint32be_t src_addr; > + uint32be_t dst_addr; > + uint8_t pad; > + uint8_t proto; > + uint16be_t length; > +} odp_udpphdr_t; > /** > * UDP checksum > * > @@ -43,7 +51,8 @@ typedef struct ODP_PACKED { > */ > static inline uint16_t odp_ipv4_udp_chksum(odp_packet_t pkt) > { > - uint32_t sum = 0; > + uint32_t sum; > + odp_udpphdr_t phdr; > odp_udphdr_t *udph; > odp_ipv4hdr_t *iph; > uint16_t udplen; > @@ -59,23 +68,24 @@ static inline uint16_t odp_ipv4_udp_chksum(odp_packet_t pkt) > udplen = odp_be_to_cpu_16(udph->length); > > /* the source ip */ > - sum += (iph->src_addr >> 16) & 0xFFFF; > - sum += (iph->src_addr) & 0xFFFF; > + phdr.src_addr = iph->src_addr; > /* the dest ip */ > - sum += (iph->dst_addr >> 16) & 0xFFFF; > - sum += (iph->dst_addr) & 0xFFFF; > + phdr.dst_addr = iph->dst_addr; > /* proto */ > - sum += odp_cpu_to_be_16(ODP_IPPROTO_UDP); > + phdr.pad = 0; > + phdr.proto = ODP_IPPROTO_UDP; > /* the length */ > - sum += udph->length; > + phdr.length = udph->length; > + > + sum = odp_chksum(&phdr, sizeof(odp_udpphdr_t)); > + /* calc udp header and data chksum */ > + sum += odp_chksum(udph, udplen); > + > /* Fold sum to 16 bits: add carrier to result */ > while ((sum >> 16) != 0) > sum = (sum & 0xFFFF) + (sum >> 16); > > - /* calc udp header and data chksum */ > - sum += ~(odp_chksum(udph, udplen)); > - > - return (uint16_t)(~sum); > + return (uint16_t)sum; > } > > /** @internal Compile time assert */
diff --git a/include/helper/odp_udp.h b/include/helper/odp_udp.h index 28313ab..c984dc0 100644 --- a/include/helper/odp_udp.h +++ b/include/helper/odp_udp.h @@ -33,6 +33,14 @@ typedef struct ODP_PACKED { uint16be_t chksum; /**< UDP header and data checksum (0 if not used)*/ } odp_udphdr_t; +/** UDP pseudo header */ +typedef struct ODP_PACKET { + uint32be_t src_addr; + uint32be_t dst_addr; + uint8_t pad; + uint8_t proto; + uint16be_t length; +} odp_udpphdr_t; /** * UDP checksum * @@ -43,7 +51,8 @@ typedef struct ODP_PACKED { */ static inline uint16_t odp_ipv4_udp_chksum(odp_packet_t pkt) { - uint32_t sum = 0; + uint32_t sum; + odp_udpphdr_t phdr; odp_udphdr_t *udph; odp_ipv4hdr_t *iph; uint16_t udplen; @@ -59,23 +68,24 @@ static inline uint16_t odp_ipv4_udp_chksum(odp_packet_t pkt) udplen = odp_be_to_cpu_16(udph->length); /* the source ip */ - sum += (iph->src_addr >> 16) & 0xFFFF; - sum += (iph->src_addr) & 0xFFFF; + phdr.src_addr = iph->src_addr; /* the dest ip */ - sum += (iph->dst_addr >> 16) & 0xFFFF; - sum += (iph->dst_addr) & 0xFFFF; + phdr.dst_addr = iph->dst_addr; /* proto */ - sum += odp_cpu_to_be_16(ODP_IPPROTO_UDP); + phdr.pad = 0; + phdr.proto = ODP_IPPROTO_UDP; /* the length */ - sum += udph->length; + phdr.length = udph->length; + + sum = odp_chksum(&phdr, sizeof(odp_udpphdr_t)); + /* calc udp header and data chksum */ + sum += odp_chksum(udph, udplen); + /* Fold sum to 16 bits: add carrier to result */ while ((sum >> 16) != 0) sum = (sum & 0xFFFF) + (sum >> 16); - /* calc udp header and data chksum */ - sum += ~(odp_chksum(udph, udplen)); - - return (uint16_t)(~sum); + return (uint16_t)sum; } /** @internal Compile time assert */
Signed-off-by: Weilong Chen <weilong.chen@linaro.org> --- include/helper/odp_udp.h | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-)