[ovs-dev] [PATCH v2] ofpbuf: simplify ofpbuf_l4_size()

Pravin B Shelar pshelar at nicira.com
Tue Mar 3 01:29:44 UTC 2015


There is bug in dpif-packet clone where it does not copy
pading size for buffer. That resulted in incorrect SCTP
checksum. This pach also fixes this issue.

Signed-off-by: Pravin B Shelar <pshelar at nicira.com>
---
 lib/ofpbuf.h          |    5 ++---
 lib/packet-dpif.c     |    1 +
 tests/ofproto-dpif.at |    6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/ofpbuf.h b/lib/ofpbuf.h
index 4e7038d..c0a55bb 100644
--- a/lib/ofpbuf.h
+++ b/lib/ofpbuf.h
@@ -337,9 +337,8 @@ static inline void ofpbuf_set_l4(struct ofpbuf *b, void *l4)
 static inline size_t ofpbuf_l4_size(const struct ofpbuf *b)
 {
     return b->l4_ofs != UINT16_MAX
-        ? (const char *)ofpbuf_tail(b) - (const char *)ofpbuf_l4(b)
-        - ofpbuf_l2_pad_size(b)
-        : 0;
+           ? ofpbuf_size(b) - ofpbuf_l2_pad_size(b) - b->l4_ofs
+           : 0;
 }
 
 static inline const void *ofpbuf_get_tcp_payload(const struct ofpbuf *b)
diff --git a/lib/packet-dpif.c b/lib/packet-dpif.c
index db739c5..bc0e236 100644
--- a/lib/packet-dpif.c
+++ b/lib/packet-dpif.c
@@ -53,6 +53,7 @@ dpif_packet_clone_from_ofpbuf(const struct ofpbuf *b)
     p->ofpbuf.l2_5_ofs = b->l2_5_ofs;
     p->ofpbuf.l3_ofs = b->l3_ofs;
     p->ofpbuf.l4_ofs = b->l4_ofs;
+    p->ofpbuf.l2_pad_size = b->l2_pad_size;
 
     return p;
 }
diff --git a/tests/ofproto-dpif.at b/tests/ofproto-dpif.at
index cdbd7fa..4932fcc 100644
--- a/tests/ofproto-dpif.at
+++ b/tests/ofproto-dpif.at
@@ -1466,13 +1466,13 @@ NXT_PACKET_IN (xid=0x0): table_id=5 cookie=0x7 total_len=102 in_port=1 tun_id=0x
 sctp,in_port=0,dl_vlan=80,dl_vlan_pcp=0,dl_src=80:81:81:81:81:81,dl_dst=82:82:82:82:82:82,nw_src=83.83.83.83,nw_dst=84.84.84.84,nw_tos=0,nw_ecn=0,nw_ttl=0,tp_src=1112,tp_dst=2223 sctp_csum:d9d79157
 dnl
 NXT_PACKET_IN (xid=0x0): table_id=6 cookie=0x8 total_len=102 in_port=1 tun_id=0x6 reg0=0x1 reg1=0x2 reg2=0x3 reg3=0x4 reg4=0x5 (via action) data_len=102 (unbuffered)
-sctp,in_port=0,dl_vlan=80,dl_vlan_pcp=0,dl_src=80:81:81:81:81:81,dl_dst=82:82:82:82:82:82,nw_src=83.83.83.83,nw_dst=84.84.84.84,nw_tos=0,nw_ecn=0,nw_ttl=0,tp_src=85,tp_dst=2223 sctp_csum:7f12662e
+sctp,in_port=0,dl_vlan=80,dl_vlan_pcp=0,dl_src=80:81:81:81:81:81,dl_dst=82:82:82:82:82:82,nw_src=83.83.83.83,nw_dst=84.84.84.84,nw_tos=0,nw_ecn=0,nw_ttl=0,tp_src=85,tp_dst=2223 sctp_csum:dd778f5f
 dnl
 NXT_PACKET_IN (xid=0x0): table_id=7 cookie=0x9 total_len=102 in_port=1 tun_id=0x6 reg0=0x1 reg1=0x2 reg2=0x3 reg3=0x4 reg4=0x5 (via action) data_len=102 (unbuffered)
-sctp,in_port=0,dl_vlan=80,dl_vlan_pcp=0,dl_src=80:81:81:81:81:81,dl_dst=82:82:82:82:82:82,nw_src=83.83.83.83,nw_dst=84.84.84.84,nw_tos=0,nw_ecn=0,nw_ttl=0,tp_src=85,tp_dst=86 sctp_csum:a7e86f67
+sctp,in_port=0,dl_vlan=80,dl_vlan_pcp=0,dl_src=80:81:81:81:81:81,dl_dst=82:82:82:82:82:82,nw_src=83.83.83.83,nw_dst=84.84.84.84,nw_tos=0,nw_ecn=0,nw_ttl=0,tp_src=85,tp_dst=86 sctp_csum:62051f56
 dnl
 NXT_PACKET_IN (xid=0x0): table_id=7 cookie=0x9 total_len=102 in_port=1 tun_id=0x6 reg0=0x1 reg1=0x2 reg2=0x3 reg3=0x4 reg4=0x5 (via action) data_len=102 (unbuffered)
-sctp,in_port=0,dl_vlan=80,dl_vlan_pcp=0,dl_src=80:81:81:81:81:81,dl_dst=82:82:82:82:82:82,nw_src=83.83.83.83,nw_dst=84.84.84.84,nw_tos=0,nw_ecn=0,nw_ttl=0,tp_src=85,tp_dst=86 sctp_csum:a7e86f67
+sctp,in_port=0,dl_vlan=80,dl_vlan_pcp=0,dl_src=80:81:81:81:81:81,dl_dst=82:82:82:82:82:82,nw_src=83.83.83.83,nw_dst=84.84.84.84,nw_tos=0,nw_ecn=0,nw_ttl=0,tp_src=85,tp_dst=86 sctp_csum:62051f56
 ])
 
 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
-- 
1.7.1




More information about the dev mailing list