Ignore:
File:
1 edited

Legend:

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

    r69a93df7 r5a324d99  
    144144}
    145145
    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);
     146static 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;
    153181}
    154182
     
    235263        uint16_t cs_phdr;
    236264        uint16_t cs_headers;
    237         uint16_t cs_all;
    238265        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));
     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
    243282        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;
     283        return tcp_checksum_calc(cs_headers, pdu->text, pdu->text_size);
    247284}
    248285
     
    271308
    272309        sp->local.port = uint16_t_be2host(hdr->dest_port);
    273         sp->local.addr = pdu->dest_addr;
     310        sp->local.addr = pdu->dest;
    274311        sp->foreign.port = uint16_t_be2host(hdr->src_port);
    275         sp->foreign.addr = pdu->src_addr;
     312        sp->foreign.addr = pdu->src;
    276313
    277314        *seg = nseg;
     
    290327                return ENOMEM;
    291328
    292         npdu->src_addr = sp->local.addr;
    293         npdu->dest_addr = sp->foreign.addr;
     329        npdu->src = sp->local.addr;
     330        npdu->dest = sp->foreign.addr;
    294331        tcp_header_encode(sp, seg, &npdu->header, &npdu->header_size);
    295332
Note: See TracChangeset for help on using the changeset viewer.