Changeset 02a09ed in mainline for uspace/srv/net/udp/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/udp/pdu.c

    redf0d27 r02a09ed  
    4040#include <mem.h>
    4141#include <stdlib.h>
    42 
     42#include <inet/addr.h>
     43#include <net/socket_codes.h>
    4344#include "msg.h"
    4445#include "pdu.h"
     
    8485}
    8586
    86 static void udp_phdr_setup(udp_pdu_t *pdu, udp_phdr_t *phdr)
    87 {
    88         // FIXME: Check for correctness
    89        
    90         uint32_t src;
    91         inet_addr_pack(&pdu->src, &src);
    92        
    93         uint32_t dest;
    94         inet_addr_pack(&pdu->dest, &dest);
    95        
    96         phdr->src_addr = host2uint32_t_be(src);
    97         phdr->dest_addr = host2uint32_t_be(dest);
    98         phdr->zero = 0;
    99         phdr->protocol = IP_PROTO_UDP;
    100         phdr->udp_length = host2uint16_t_be(pdu->data_size);
     87static uint16_t udp_phdr_setup(udp_pdu_t *pdu, udp_phdr_t *phdr)
     88{
     89        addr32_t src_v4;
     90        addr128_t src_v6;
     91        uint16_t src_af = inet_addr_get(&pdu->src, &src_v4, &src_v6);
     92       
     93        addr32_t dest_v4;
     94        addr128_t dest_v6;
     95        uint16_t dest_af = inet_addr_get(&pdu->dest, &dest_v4, &dest_v6);
     96       
     97        assert(src_af == dest_af);
     98       
     99        switch (src_af) {
     100        case AF_INET:
     101                phdr->src_addr = host2uint32_t_be(src_v4);
     102                phdr->dest_addr = host2uint32_t_be(dest_v4);
     103                phdr->zero = 0;
     104                phdr->protocol = IP_PROTO_UDP;
     105                phdr->udp_length = host2uint16_t_be(pdu->data_size);
     106                break;
     107        case AF_INET6:
     108                // FIXME TODO
     109                assert(false);
     110        default:
     111                assert(false);
     112        }
     113       
     114        return src_af;
    101115}
    102116
     
    115129{
    116130        uint16_t cs_phdr;
    117         uint16_t cs_all;
    118131        udp_phdr_t phdr;
    119 
    120         udp_phdr_setup(pdu, &phdr);
    121         cs_phdr = udp_checksum_calc(UDP_CHECKSUM_INIT, (void *)&phdr,
    122             sizeof(udp_phdr_t));
    123         cs_all = udp_checksum_calc(cs_phdr, pdu->data, pdu->data_size);
    124 
    125         return cs_all;
     132       
     133        uint16_t af = udp_phdr_setup(pdu, &phdr);
     134        switch (af) {
     135        case AF_INET:
     136                cs_phdr = udp_checksum_calc(UDP_CHECKSUM_INIT, (void *) &phdr,
     137                    sizeof(udp_phdr_t));
     138                break;
     139        case AF_INET6:
     140                // FIXME TODO
     141                assert(false);
     142        default:
     143                assert(false);
     144        }
     145       
     146        return udp_checksum_calc(cs_phdr, pdu->data, pdu->data_size);
    126147}
    127148
Note: See TracChangeset for help on using the changeset viewer.