Changes in uspace/srv/net/tcp/pdu.c [12df1f1:69a93df7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tcp/pdu.c
r12df1f1 r69a93df7 40 40 #include <mem.h> 41 41 #include <stdlib.h> 42 #include <net/socket_codes.h>43 42 #include "pdu.h" 44 43 #include "segment.h" … … 145 144 } 146 145 147 static uint16_t tcp_phdr_setup(tcp_pdu_t *pdu, tcp_phdr_t *phdr, 148 tcp_phdr6_t *phdr6) 149 { 150 addr32_t src_v4; 151 addr128_t src_v6; 152 uint16_t src_af = inet_addr_get(&pdu->src, &src_v4, &src_v6); 153 154 addr32_t dest_v4; 155 addr128_t dest_v6; 156 uint16_t dest_af = inet_addr_get(&pdu->dest, &dest_v4, &dest_v6); 157 158 assert(src_af == dest_af); 159 160 switch (src_af) { 161 case AF_INET: 162 phdr->src = host2uint32_t_be(src_v4); 163 phdr->dest = host2uint32_t_be(dest_v4); 164 phdr->zero = 0; 165 phdr->protocol = IP_PROTO_TCP; 166 phdr->tcp_length = 167 host2uint16_t_be(pdu->header_size + pdu->text_size); 168 break; 169 case AF_INET6: 170 host2addr128_t_be(src_v6, phdr6->src); 171 host2addr128_t_be(dest_v6, phdr6->dest); 172 phdr6->tcp_length = 173 host2uint32_t_be(pdu->header_size + pdu->text_size); 174 memset(phdr6->zeroes, 0, 3); 175 phdr6->next = IP_PROTO_TCP; 176 break; 177 default: 178 assert(false); 179 } 180 181 return src_af; 146 static void tcp_phdr_setup(tcp_pdu_t *pdu, tcp_phdr_t *phdr) 147 { 148 phdr->src_addr = host2uint32_t_be(pdu->src_addr.ipv4); 149 phdr->dest_addr = host2uint32_t_be(pdu->dest_addr.ipv4); 150 phdr->zero = 0; 151 phdr->protocol = 6; /* XXX Magic number */ 152 phdr->tcp_length = host2uint16_t_be(pdu->header_size + pdu->text_size); 182 153 } 183 154 … … 264 235 uint16_t cs_phdr; 265 236 uint16_t cs_headers; 237 uint16_t cs_all; 266 238 tcp_phdr_t phdr; 267 tcp_phdr6_t phdr6; 268 269 uint16_t af = tcp_phdr_setup(pdu, &phdr, &phdr6); 270 switch (af) { 271 case AF_INET: 272 cs_phdr = tcp_checksum_calc(TCP_CHECKSUM_INIT, (void *) &phdr, 273 sizeof(tcp_phdr_t)); 274 break; 275 case AF_INET6: 276 cs_phdr = tcp_checksum_calc(TCP_CHECKSUM_INIT, (void *) &phdr6, 277 sizeof(tcp_phdr6_t)); 278 break; 279 default: 280 assert(false); 281 } 282 239 240 tcp_phdr_setup(pdu, &phdr); 241 cs_phdr = tcp_checksum_calc(TCP_CHECKSUM_INIT, (void *)&phdr, 242 sizeof(tcp_phdr_t)); 283 243 cs_headers = tcp_checksum_calc(cs_phdr, pdu->header, pdu->header_size); 284 return tcp_checksum_calc(cs_headers, pdu->text, pdu->text_size); 244 cs_all = tcp_checksum_calc(cs_headers, pdu->text, pdu->text_size); 245 246 return cs_all; 285 247 } 286 248 … … 309 271 310 272 sp->local.port = uint16_t_be2host(hdr->dest_port); 311 sp->local.addr = pdu->dest ;273 sp->local.addr = pdu->dest_addr; 312 274 sp->foreign.port = uint16_t_be2host(hdr->src_port); 313 sp->foreign.addr = pdu->src ;275 sp->foreign.addr = pdu->src_addr; 314 276 315 277 *seg = nseg; … … 328 290 return ENOMEM; 329 291 330 npdu->src = sp->local.addr;331 npdu->dest = sp->foreign.addr;292 npdu->src_addr = sp->local.addr; 293 npdu->dest_addr = sp->foreign.addr; 332 294 tcp_header_encode(sp, seg, &npdu->header, &npdu->header_size); 333 295
Note:
See TracChangeset
for help on using the changeset viewer.