diff mbox

[ovs-dev] Explain initialization when using csum()

Message ID 1469385395-31181-1-git-send-email-rmoats@us.ibm.com
State Accepted
Headers show

Commit Message

Ryan Moats July 24, 2016, 6:36 p.m. UTC
The checksum method csum() requires its output location to be
intialized to zero when that output location is part of the
checksum.  Add comments to the various places where csum is
called documenting where the initialization has occurred.

Signed-off-by: Ryan Moats <rmoats@us.ibm.com>
---
 lib/bfd.c                | 1 +
 lib/flow.c               | 3 +++
 lib/netdev-native-tnl.c  | 1 +
 ovn/controller/pinctrl.c | 1 +
 4 files changed, 6 insertions(+)

Comments

Ben Pfaff July 24, 2016, 6:50 p.m. UTC | #1
On Sun, Jul 24, 2016 at 06:36:35PM +0000, Ryan Moats wrote:
> The checksum method csum() requires its output location to be
> intialized to zero when that output location is part of the
> checksum.  Add comments to the various places where csum is
> called documenting where the initialization has occurred.
> 
> Signed-off-by: Ryan Moats <rmoats@us.ibm.com>

Applied, thanks!
diff mbox

Patch

diff --git a/lib/bfd.c b/lib/bfd.c
index 8dac953..7a34e89 100644
--- a/lib/bfd.c
+++ b/lib/bfd.c
@@ -629,6 +629,7 @@  bfd_put_packet(struct bfd *bfd, struct dp_packet *p,
     ip->ip_proto = IPPROTO_UDP;
     put_16aligned_be32(&ip->ip_src, bfd->ip_src);
     put_16aligned_be32(&ip->ip_dst, bfd->ip_dst);
+    /* Checksum has already been zeroed by put_zeros call. */
     ip->ip_csum = csum(ip, sizeof *ip);
 
     udp = dp_packet_put_zeros(p, sizeof *udp);
diff --git a/lib/flow.c b/lib/flow.c
index 1fa3bf4..51f6819 100644
--- a/lib/flow.c
+++ b/lib/flow.c
@@ -2226,6 +2226,7 @@  flow_compose_l4(struct dp_packet *p, const struct flow *flow)
             icmp = dp_packet_put_zeros(p, l4_len);
             icmp->icmp_type = ntohs(flow->tp_src);
             icmp->icmp_code = ntohs(flow->tp_dst);
+            /* Checksum has already been zeroed by put_zeros call. */
             icmp->icmp_csum = csum(icmp, ICMP_HEADER_LEN);
         } else if (flow->nw_proto == IPPROTO_IGMP) {
             struct igmp_header *igmp;
@@ -2235,6 +2236,7 @@  flow_compose_l4(struct dp_packet *p, const struct flow *flow)
             igmp->igmp_type = ntohs(flow->tp_src);
             igmp->igmp_code = ntohs(flow->tp_dst);
             put_16aligned_be32(&igmp->group, flow->igmp_group_ip4);
+            /* Checksum has already been zeroed by put_zeros call. */
             igmp->igmp_csum = csum(igmp, IGMP_HEADER_LEN);
         } else if (flow->nw_proto == IPPROTO_ICMPV6) {
             struct icmp6_hdr *icmp;
@@ -2323,6 +2325,7 @@  flow_compose(struct dp_packet *p, const struct flow *flow)
 
         ip = dp_packet_l3(p);
         ip->ip_tot_len = htons(p->l4_ofs - p->l3_ofs + l4_len);
+        /* Checksum has already been zeroed by put_zeros call. */
         ip->ip_csum = csum(ip, sizeof *ip);
     } else if (flow->dl_type == htons(ETH_TYPE_IPV6)) {
         struct ovs_16aligned_ip6_hdr *nh;
diff --git a/lib/netdev-native-tnl.c b/lib/netdev-native-tnl.c
index 15975ad..ce2582f 100644
--- a/lib/netdev-native-tnl.c
+++ b/lib/netdev-native-tnl.c
@@ -273,6 +273,7 @@  netdev_tnl_ip_build_header(struct ovs_action_push_tnl *data,
         ip->ip_frag_off = (params->flow->tunnel.flags & FLOW_TNL_F_DONT_FRAGMENT) ?
                           htons(IP_DF) : 0;
 
+        /* Checksum has already been zeroed by eth_build_header. */
         ip->ip_csum = csum(ip, sizeof *ip);
 
         data->header_len += IP_HEADER_LEN;
diff --git a/ovn/controller/pinctrl.c b/ovn/controller/pinctrl.c
index 62f4748..0ae6501 100644
--- a/ovn/controller/pinctrl.c
+++ b/ovn/controller/pinctrl.c
@@ -345,6 +345,7 @@  pinctrl_handle_put_dhcp_opts(
     struct ip_header *out_ip = dp_packet_l3(&pkt_out);
     out_ip->ip_tot_len = htons(pkt_out.l4_ofs - pkt_out.l3_ofs + new_l4_size);
     udp->udp_csum = 0;
+    /* Checksum needs to be initialized to zero. */
     out_ip->ip_csum = 0;
     out_ip->ip_csum = csum(out_ip, sizeof *out_ip);