Changeset 02a09ed in mainline for uspace/srv/net/tcp/pdu.c


Ignore:
Timestamp:
2013-06-28T20:20:03Z (11 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1d24ad3
Parents:
edf0d27
Message:

add basic infrastructure for IPv6 (inactive)
make inet_addr_t a universal address type

File:
1 edited

Legend:

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

    redf0d27 r02a09ed  
    4040#include <mem.h>
    4141#include <stdlib.h>
     42#include <net/socket_codes.h>
    4243#include "pdu.h"
    4344#include "segment.h"
     
    144145}
    145146
    146 static void tcp_phdr_setup(tcp_pdu_t *pdu, tcp_phdr_t *phdr)
    147 {
    148         // FIXME: Check for correctness
    149        
    150         uint32_t src_addr;
    151         inet_addr_pack(&pdu->src_addr, &src_addr);
    152        
    153         uint32_t dest_addr;
    154         inet_addr_pack(&pdu->dest_addr, &dest_addr);
    155        
    156         phdr->src_addr = host2uint32_t_be(src_addr);
    157         phdr->dest_addr = host2uint32_t_be(dest_addr);
    158         phdr->zero = 0;
    159         phdr->protocol = 6; /* XXX Magic number */
    160         phdr->tcp_length = host2uint16_t_be(pdu->header_size + pdu->text_size);
     147static uint16_t tcp_phdr_setup(tcp_pdu_t *pdu, tcp_phdr_t *phdr)
     148{
     149        addr32_t src_v4;
     150        addr128_t src_v6;
     151        uint16_t src_af = inet_addr_get(&pdu->src, &src_v4, &src_v6);
     152       
     153        addr32_t dest_v4;
     154        addr128_t dest_v6;
     155        uint16_t dest_af = inet_addr_get(&pdu->dest, &dest_v4, &dest_v6);
     156       
     157        assert(src_af == dest_af);
     158       
     159        switch (src_af) {
     160        case AF_INET:
     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 AF_INET6:
     169                // FIXME TODO
     170                assert(false);
     171        default:
     172                assert(false);
     173        }
     174       
     175        return src_af;
    161176}
    162177
     
    243258        uint16_t cs_phdr;
    244259        uint16_t cs_headers;
    245         uint16_t cs_all;
    246260        tcp_phdr_t phdr;
    247 
    248         tcp_phdr_setup(pdu, &phdr);
    249         cs_phdr = tcp_checksum_calc(TCP_CHECKSUM_INIT, (void *)&phdr,
    250             sizeof(tcp_phdr_t));
     261       
     262        uint16_t af = tcp_phdr_setup(pdu, &phdr);
     263        switch (af) {
     264        case AF_INET:
     265                cs_phdr = tcp_checksum_calc(TCP_CHECKSUM_INIT, (void *) &phdr,
     266                    sizeof(tcp_phdr_t));
     267                break;
     268        case AF_INET6:
     269                // FIXME TODO
     270                assert(false);
     271        default:
     272                assert(false);
     273        }
     274       
    251275        cs_headers = tcp_checksum_calc(cs_phdr, pdu->header, pdu->header_size);
    252         cs_all = tcp_checksum_calc(cs_headers, pdu->text, pdu->text_size);
    253 
    254         return cs_all;
     276        return tcp_checksum_calc(cs_headers, pdu->text, pdu->text_size);
    255277}
    256278
     
    279301
    280302        sp->local.port = uint16_t_be2host(hdr->dest_port);
    281         sp->local.addr = pdu->dest_addr;
     303        sp->local.addr = pdu->dest;
    282304        sp->foreign.port = uint16_t_be2host(hdr->src_port);
    283         sp->foreign.addr = pdu->src_addr;
     305        sp->foreign.addr = pdu->src;
    284306
    285307        *seg = nseg;
     
    298320                return ENOMEM;
    299321
    300         npdu->src_addr = sp->local.addr;
    301         npdu->dest_addr = sp->foreign.addr;
     322        npdu->src = sp->local.addr;
     323        npdu->dest = sp->foreign.addr;
    302324        tcp_header_encode(sp, seg, &npdu->header, &npdu->header_size);
    303325
Note: See TracChangeset for help on using the changeset viewer.