Changes in uspace/srv/net/tcp/pdu.c [69a93df7:12df1f1] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tcp/pdu.c
r69a93df7 r12df1f1 40 40 #include <mem.h> 41 41 #include <stdlib.h> 42 #include <net/socket_codes.h> 42 43 #include "pdu.h" 43 44 #include "segment.h" … … 144 145 } 145 146 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); 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; 153 182 } 154 183 … … 235 264 uint16_t cs_phdr; 236 265 uint16_t cs_headers; 237 uint16_t cs_all;238 266 tcp_phdr_t phdr; 239 240 tcp_phdr_setup(pdu, &phdr); 241 cs_phdr = tcp_checksum_calc(TCP_CHECKSUM_INIT, (void *)&phdr, 242 sizeof(tcp_phdr_t)); 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 243 283 cs_headers = tcp_checksum_calc(cs_phdr, pdu->header, pdu->header_size); 244 cs_all = tcp_checksum_calc(cs_headers, pdu->text, pdu->text_size); 245 246 return cs_all; 284 return tcp_checksum_calc(cs_headers, pdu->text, pdu->text_size); 247 285 } 248 286 … … 271 309 272 310 sp->local.port = uint16_t_be2host(hdr->dest_port); 273 sp->local.addr = pdu->dest _addr;311 sp->local.addr = pdu->dest; 274 312 sp->foreign.port = uint16_t_be2host(hdr->src_port); 275 sp->foreign.addr = pdu->src _addr;313 sp->foreign.addr = pdu->src; 276 314 277 315 *seg = nseg; … … 290 328 return ENOMEM; 291 329 292 npdu->src _addr= sp->local.addr;293 npdu->dest _addr= sp->foreign.addr;330 npdu->src = sp->local.addr; 331 npdu->dest = sp->foreign.addr; 294 332 tcp_header_encode(sp, seg, &npdu->header, &npdu->header_size); 295 333
Note:
See TracChangeset
for help on using the changeset viewer.