Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/tcp/pdu.c

    r5a324d99 r69a93df7  
    144144}
    145145
    146 static ip_ver_t tcp_phdr_setup(tcp_pdu_t *pdu, tcp_phdr_t *phdr,
    147     tcp_phdr6_t *phdr6)
    148 {
    149         addr32_t src_v4;
    150         addr128_t src_v6;
    151         uint16_t src_ver = inet_addr_get(&pdu->src, &src_v4, &src_v6);
    152 
    153         addr32_t dest_v4;
    154         addr128_t dest_v6;
    155         uint16_t dest_ver = inet_addr_get(&pdu->dest, &dest_v4, &dest_v6);
    156 
    157         assert(src_ver == dest_ver);
    158 
    159         switch (src_ver) {
    160         case ip_v4:
    161                 phdr->src = host2uint32_t_be(src_v4);
    162                 phdr->dest = host2uint32_t_be(dest_v4);
    163                 phdr->zero = 0;
    164                 phdr->protocol = IP_PROTO_TCP;
    165                 phdr->tcp_length =
    166                     host2uint16_t_be(pdu->header_size + pdu->text_size);
    167                 break;
    168         case ip_v6:
    169                 host2addr128_t_be(src_v6, phdr6->src);
    170                 host2addr128_t_be(dest_v6, phdr6->dest);
    171                 phdr6->tcp_length =
    172                     host2uint32_t_be(pdu->header_size + pdu->text_size);
    173                 memset(phdr6->zeroes, 0, 3);
    174                 phdr6->next = IP_PROTO_TCP;
    175                 break;
    176         default:
    177                 assert(false);
    178         }
    179 
    180         return src_ver;
     146static 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);
    181153}
    182154
     
    263235        uint16_t cs_phdr;
    264236        uint16_t cs_headers;
     237        uint16_t cs_all;
    265238        tcp_phdr_t phdr;
    266         tcp_phdr6_t phdr6;
    267 
    268         ip_ver_t ver = tcp_phdr_setup(pdu, &phdr, &phdr6);
    269         switch (ver) {
    270         case ip_v4:
    271                 cs_phdr = tcp_checksum_calc(TCP_CHECKSUM_INIT, (void *) &phdr,
    272                     sizeof(tcp_phdr_t));
    273                 break;
    274         case ip_v6:
    275                 cs_phdr = tcp_checksum_calc(TCP_CHECKSUM_INIT, (void *) &phdr6,
    276                     sizeof(tcp_phdr6_t));
    277                 break;
    278         default:
    279                 assert(false);
    280         }
    281 
     239
     240        tcp_phdr_setup(pdu, &phdr);
     241        cs_phdr = tcp_checksum_calc(TCP_CHECKSUM_INIT, (void *)&phdr,
     242            sizeof(tcp_phdr_t));
    282243        cs_headers = tcp_checksum_calc(cs_phdr, pdu->header, pdu->header_size);
    283         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;
    284247}
    285248
     
    308271
    309272        sp->local.port = uint16_t_be2host(hdr->dest_port);
    310         sp->local.addr = pdu->dest;
     273        sp->local.addr = pdu->dest_addr;
    311274        sp->foreign.port = uint16_t_be2host(hdr->src_port);
    312         sp->foreign.addr = pdu->src;
     275        sp->foreign.addr = pdu->src_addr;
    313276
    314277        *seg = nseg;
     
    327290                return ENOMEM;
    328291
    329         npdu->src = sp->local.addr;
    330         npdu->dest = sp->foreign.addr;
     292        npdu->src_addr = sp->local.addr;
     293        npdu->dest_addr = sp->foreign.addr;
    331294        tcp_header_encode(sp, seg, &npdu->header, &npdu->header_size);
    332295
Note: See TracChangeset for help on using the changeset viewer.