~as-s/helenos/ipv6

« back to all changes in this revision

Viewing changes to uspace/srv/net/udp/pdu.c

  • Committer: Anthony Steinhauser
  • Date: 2013-07-08 01:07:36 UTC
  • Revision ID: as@strmilov.cz-20130708010736-pbvrszhamp0v64ez
HelenOS networking stack supports IPv6

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Copyright (c) 2012 Jiri Svoboda
 
3
 * Copyright (c) 2013 Antonin Steinhauser
3
4
 * All rights reserved.
4
5
 *
5
6
 * Redistribution and use in source and binary forms, with or without
85
86
 
86
87
static void udp_phdr_setup(udp_pdu_t *pdu, udp_phdr_t *phdr)
87
88
{
88
 
        phdr->src_addr = pdu->src.s_addr;
89
 
        phdr->dest_addr = pdu->dest.s_addr;
 
89
        in_addr_t src, dest;
 
90
        ipv6_to_ipv4(&src, &pdu->src);
 
91
        ipv6_to_ipv4(&dest, &pdu->dest);
 
92
        phdr->src_addr = src.s_addr;
 
93
        phdr->dest_addr = dest.s_addr;
90
94
        phdr->zero = 0;
91
95
        phdr->protocol = IP_PROTO_UDP;
92
96
        phdr->udp_length = host2uint16_t_be(pdu->data_size);
93
97
}
94
98
 
 
99
/**
 
100
 * Set up UDP over IPv6 pseudoheader for checksum computation
 
101
 *
 
102
 * @param pdu UDP PDU
 
103
 * @param phdr UDP pseudoheader to be filled
 
104
 */
 
105
static void udp_phdr6_setup(udp_pdu_t *pdu, udp_phdr6_t *phdr)
 
106
{
 
107
        memcpy(phdr->src_addr, pdu->src.s6_addr, 16);
 
108
        memcpy(phdr->dest_addr, pdu->dest.s6_addr, 16);
 
109
        phdr->udp_length = host2uint32_t_be(pdu->data_size);
 
110
        memset(phdr->zeroes, 0, 3);
 
111
        phdr->next = IP_PROTO_UDP;
 
112
}
 
113
 
95
114
udp_pdu_t *udp_pdu_new(void)
96
115
{
97
116
        return calloc(1, sizeof(udp_pdu_t));
108
127
        uint16_t cs_phdr;
109
128
        uint16_t cs_all;
110
129
        udp_phdr_t phdr;
111
 
 
112
 
        udp_phdr_setup(pdu, &phdr);
113
 
        cs_phdr = udp_checksum_calc(UDP_CHECKSUM_INIT, (void *)&phdr,
114
 
            sizeof(udp_phdr_t));
 
130
        udp_phdr6_t phdr6;
 
131
 
 
132
        if (is_mapped(&pdu->src)) {
 
133
                udp_phdr_setup(pdu, &phdr);
 
134
                cs_phdr = udp_checksum_calc(UDP_CHECKSUM_INIT, (void *)&phdr,
 
135
                    sizeof(udp_phdr_t));
 
136
        } else {
 
137
                udp_phdr6_setup(pdu, &phdr6);
 
138
                cs_phdr = udp_checksum_calc(UDP_CHECKSUM_INIT, (void *)&phdr6,
 
139
                    sizeof(udp_phdr6_t));
 
140
        }
 
141
 
115
142
        cs_all = udp_checksum_calc(cs_phdr, pdu->data, pdu->data_size);
116
143
 
117
144
        return cs_all;