File tree Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -86,6 +86,18 @@ type nwTos = int8
86
86
87
87
type tpPort = int16
88
88
89
+ let mk_pseudo_header (src : nwAddr ) (dst : nwAddr ) (proto : int ) (len : int ) =
90
+ (* XXX(seliopou): pseudo_header's allocated on every call. Given the usage
91
+ * pattern of this library, though, would it be safe to allocate once and
92
+ * reuse? *)
93
+ let pseudo_header = Cstruct. create 12 in
94
+ Cstruct.BE. set_uint32 pseudo_header 0 src;
95
+ Cstruct.BE. set_uint32 pseudo_header 4 dst;
96
+ Cstruct. set_uint8 pseudo_header 8 0 ;
97
+ Cstruct. set_uint8 pseudo_header 9 proto;
98
+ Cstruct.BE. set_uint16 pseudo_header 10 len;
99
+ pseudo_header
100
+
89
101
module Tcp = struct
90
102
91
103
module Flags = struct
@@ -204,15 +216,8 @@ module Tcp = struct
204
216
205
217
206
218
let checksum (bits : Cstruct.t ) (src : nwAddr ) (dst : nwAddr ) (pkt : t ) =
207
- (* XXX(seliopou): pseudo_header's allocated on every call. Would it be safe
208
- * to allocate once and reuse? *)
209
- let pseudo_header = Cstruct. create 12 in
210
219
let length = len pkt in
211
- Cstruct.BE. set_uint32 pseudo_header 0 src;
212
- Cstruct.BE. set_uint32 pseudo_header 4 dst;
213
- Cstruct. set_uint8 pseudo_header 8 0 ;
214
- Cstruct. set_uint8 pseudo_header 9 0x6 ;
215
- Cstruct.BE. set_uint16 pseudo_header 10 length;
220
+ let pseudo_header = mk_pseudo_header src dst 0x6 length in
216
221
set_tcp_chksum bits 0 ;
217
222
let chksum = Checksum. ones_complement_list
218
223
(if (length mod 2 ) = 0
You can’t perform that action at this time.
0 commit comments