Changeset 330df83 in mainline for uspace/srv


Ignore:
Timestamp:
2013-07-19T20:42:57Z (12 years ago)
Author:
Manuele Conti <conti.ma@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f4cbf9dd
Parents:
8a8a08d1 (diff), cd18cd1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge with mainline changes.

Location:
uspace/srv/net
Files:
31 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/dnsrsrv/dns_msg.c

    r8a8a08d1 r330df83  
    296296uint32_t dns_uint32_t_decode(uint8_t *buf, size_t buf_size)
    297297{
    298         uint32_t w;
    299298        assert(buf_size >= 4);
    300 
    301         w = ((uint32_t) buf[0] << 24) +
     299       
     300        uint32_t w = ((uint32_t) buf[0] << 24) +
    302301            ((uint32_t) buf[1] << 16) +
    303302            ((uint32_t) buf[2] << 8) +
    304303            buf[3];
    305 
     304       
    306305        return w;
     306}
     307
     308/** Decode unaligned big-endian 128-bit integer */
     309void dns_addr128_t_decode(uint8_t *buf, size_t buf_size, addr128_t addr)
     310{
     311        assert(buf_size >= 16);
     312       
     313        addr128_t_be2host(buf, addr);
    307314}
    308315
     
    400407        int rc;
    401408
    402         rr = calloc(1, sizeof (dns_rr_t));
     409        rr = calloc(1, sizeof(dns_rr_t));
    403410        if (rr == NULL)
    404411                return ENOMEM;
     
    427434
    428435        rr->rtype = dns_uint16_t_decode(bp, bsz);
    429         bp += sizeof(uint16_t); bsz -= sizeof(uint16_t);
     436        bp += sizeof(uint16_t);
     437        bsz -= sizeof(uint16_t);
    430438
    431439        rr->rclass = dns_uint16_t_decode(bp, bsz);
    432         bp += sizeof(uint16_t); bsz -= sizeof(uint16_t);
     440        bp += sizeof(uint16_t);
     441        bsz -= sizeof(uint16_t);
    433442
    434443        rr->ttl = dns_uint32_t_decode(bp, bsz);
    435         bp += sizeof(uint32_t); bsz -= sizeof(uint32_t);
     444        bp += sizeof(uint32_t);
     445        bsz -= sizeof(uint32_t);
    436446
    437447        rdlength = dns_uint16_t_decode(bp, bsz);
    438         bp += sizeof(uint16_t); bsz -= sizeof(uint16_t);
     448        bp += sizeof(uint16_t);
     449        bsz -= sizeof(uint16_t);
    439450
    440451        if (rdlength > bsz) {
  • uspace/srv/net/dnsrsrv/dns_msg.h

    r8a8a08d1 r330df83  
    4040#include <stdbool.h>
    4141#include <stdint.h>
     42#include <inet/addr.h>
    4243#include "dns_std.h"
    4344#include "dns_type.h"
     
    4950extern int dns_name_decode(dns_pdu_t *, size_t, char **, size_t *);
    5051extern uint32_t dns_uint32_t_decode(uint8_t *, size_t);
     52extern void dns_addr128_t_decode(uint8_t *, size_t, addr128_t);
     53
    5154
    5255#endif
  • uspace/srv/net/dnsrsrv/dns_std.h

    r8a8a08d1 r330df83  
    6565        DTYPE_MX        = 15,
    6666        DTYPE_TXT       = 16,
     67        DTYPE_AAAA      = 28,
    6768        DQTYPE_AXFR     = 252,
    6869        DQTYPE_MAILB    = 253,
  • uspace/srv/net/dnsrsrv/dnsrsrv.c

    r8a8a08d1 r330df83  
    8989        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_get_srvaddr_srv()");
    9090       
     91        uint16_t af = IPC_GET_ARG1(*icall);
     92       
    9193        char *name;
    9294        int rc = async_data_write_accept((void **) &name, true, 0,
     
    98100       
    99101        dns_host_info_t *hinfo;
    100         rc = dns_name2host(name, &hinfo);
     102        rc = dns_name2host(name, &hinfo, af);
    101103        if (rc != EOK) {
    102104                async_answer_0(iid, rc);
  • uspace/srv/net/dnsrsrv/query.c

    r8a8a08d1 r330df83  
    3939#include <stdlib.h>
    4040#include <str.h>
    41 
     41#include <net/socket_codes.h>
    4242#include "dns_msg.h"
    4343#include "dns_std.h"
     
    4848static uint16_t msg_id;
    4949
    50 int dns_name2host(const char *name, dns_host_info_t **rinfo)
     50static int dns_name_query(const char *name, dns_qtype_t qtype,
     51    dns_host_info_t *info)
    5152{
    52         dns_message_t *msg;
    53         dns_message_t *amsg;
    54         dns_question_t *question;
    55         dns_host_info_t *info;
    56         char *sname, *cname;
    57         size_t eoff;
    58         int rc;
    59 
    60         question = calloc(1, sizeof(dns_question_t));
    61         if (question == NULL)
    62                 return ENOMEM;
    63 
    64         question->qname = (char *)name;
    65         question->qtype = DTYPE_A;
     53        /* Start with the caller-provided name */
     54        char *sname = str_dup(name);
     55        if (sname == NULL)
     56                return ENOMEM;
     57       
     58        char *qname = str_dup(name);
     59        if (qname == NULL) {
     60                free(sname);
     61                return ENOMEM;
     62        }
     63       
     64        dns_question_t *question = calloc(1, sizeof(dns_question_t));
     65        if (question == NULL) {
     66                free(qname);
     67                free(sname);
     68                return ENOMEM;
     69        }
     70       
     71        question->qname = qname;
     72        question->qtype = qtype;
    6673        question->qclass = DC_IN;
    67 
    68         msg = dns_message_new();
    69         if (msg == NULL)
    70                 return ENOMEM;
    71 
    72         list_append(&question->msg, &msg->question);
    73 
     74       
     75        dns_message_t *msg = dns_message_new();
     76        if (msg == NULL) {
     77                free(question);
     78                free(qname);
     79                free(sname);
     80                return ENOMEM;
     81        }
     82       
    7483        msg->id = msg_id++;
    7584        msg->qr = QR_QUERY;
     
    7988        msg->rd = true;
    8089        msg->ra = false;
    81 
    82         rc = dns_request(msg, &amsg);
     90       
     91        list_append(&question->msg, &msg->question);
     92       
     93        dns_message_t *amsg;
     94        int rc = dns_request(msg, &amsg);
    8395        if (rc != EOK) {
     96                dns_message_destroy(msg);
     97                free(sname);
    8498                return rc;
    8599        }
    86 
    87         /* Start with the caller-provided name */
    88         sname = str_dup(name);
    89 
     100       
    90101        list_foreach(amsg->answer, link) {
    91102                dns_rr_t *rr = list_get_instance(link, dns_rr_t, msg);
    92 
     103               
    93104                log_msg(LOG_DEFAULT, LVL_DEBUG, " - '%s' %u/%u, dsize %zu",
    94                         rr->name, rr->rtype, rr->rclass, rr->rdata_size);
    95 
    96                 if (rr->rtype == DTYPE_CNAME && rr->rclass == DC_IN &&
    97                     str_cmp(rr->name, sname) == 0) {
     105                    rr->name, rr->rtype, rr->rclass, rr->rdata_size);
     106               
     107                if ((rr->rtype == DTYPE_CNAME) && (rr->rclass == DC_IN) &&
     108                    (str_cmp(rr->name, sname) == 0)) {
     109                       
    98110                        log_msg(LOG_DEFAULT, LVL_DEBUG, "decode cname (%p, %zu, %zu)",
    99111                            amsg->pdu.data, amsg->pdu.size, rr->roff);
     112                       
     113                        char *cname;
     114                        size_t eoff;
    100115                        rc = dns_name_decode(&amsg->pdu, rr->roff, &cname, &eoff);
    101116                        if (rc != EOK) {
    102                                 log_msg(LOG_DEFAULT, LVL_DEBUG,
    103                                     "error decoding cname");
    104                                 assert(rc == EINVAL || rc == ENOMEM);
     117                                assert((rc == EINVAL) || (rc == ENOMEM));
     118                               
     119                                log_msg(LOG_DEFAULT, LVL_DEBUG, "error decoding cname");
     120                               
    105121                                dns_message_destroy(msg);
    106122                                dns_message_destroy(amsg);
     123                                free(sname);
     124                               
    107125                                return rc;
    108126                        }
    109 
     127                       
    110128                        log_msg(LOG_DEFAULT, LVL_DEBUG, "name = '%s' "
    111129                            "cname = '%s'", sname, cname);
    112 
     130                       
     131                        /* Continue looking for the more canonical name */
    113132                        free(sname);
    114                         /* Continue looking for the more canonical name */
    115133                        sname = cname;
    116134                }
    117 
    118                 if (rr->rtype == DTYPE_A && rr->rclass == DC_IN &&
    119                         rr->rdata_size == sizeof(uint32_t) &&
    120                             str_cmp(rr->name, sname) == 0) {
    121 
    122                         info = calloc(1, sizeof(dns_host_info_t));
    123                         if (info == NULL) {
     135               
     136                if ((qtype == DTYPE_A) && (rr->rtype == DTYPE_A) &&
     137                    (rr->rclass == DC_IN) && (rr->rdata_size == sizeof(addr32_t)) &&
     138                    (str_cmp(rr->name, sname) == 0)) {
     139                       
     140                        info->cname = str_dup(rr->name);
     141                        if (info->cname == NULL) {
    124142                                dns_message_destroy(msg);
    125143                                dns_message_destroy(amsg);
     144                                free(sname);
     145                               
    126146                                return ENOMEM;
    127147                        }
    128 
    129                         info->cname = str_dup(rr->name);
     148                       
    130149                        inet_addr_set(dns_uint32_t_decode(rr->rdata, rr->rdata_size),
    131150                            &info->addr);
     
    133152                        dns_message_destroy(msg);
    134153                        dns_message_destroy(amsg);
    135                         *rinfo = info;
     154                        free(sname);
     155                       
    136156                        return EOK;
    137157                }
    138         }
    139 
     158               
     159                if ((qtype == DTYPE_AAAA) && (rr->rtype == DTYPE_AAAA) &&
     160                    (rr->rclass == DC_IN) && (rr->rdata_size == sizeof(addr128_t)) &&
     161                    (str_cmp(rr->name, sname) == 0)) {
     162               
     163                        info->cname = str_dup(rr->name);
     164                        if (info->cname == NULL) {
     165                                dns_message_destroy(msg);
     166                                dns_message_destroy(amsg);
     167                                free(sname);
     168                               
     169                                return ENOMEM;
     170                        }
     171                       
     172                        addr128_t addr;
     173                        dns_addr128_t_decode(rr->rdata, rr->rdata_size, addr);
     174                       
     175                        inet_addr_set6(addr, &info->addr);
     176                       
     177                        dns_message_destroy(msg);
     178                        dns_message_destroy(amsg);
     179                        free(sname);
     180                       
     181                        return EOK;
     182                }
     183        }
     184       
     185        log_msg(LOG_DEFAULT, LVL_DEBUG, "'%s' not resolved, fail", sname);
     186       
    140187        dns_message_destroy(msg);
    141188        dns_message_destroy(amsg);
    142         log_msg(LOG_DEFAULT, LVL_DEBUG, "'%s' not resolved, fail", sname);
    143 
     189        free(sname);
     190       
    144191        return EIO;
     192}
     193
     194int dns_name2host(const char *name, dns_host_info_t **rinfo, uint16_t af)
     195{
     196        dns_host_info_t *info = calloc(1, sizeof(dns_host_info_t));
     197        if (info == NULL)
     198                return ENOMEM;
     199       
     200        int rc;
     201       
     202        switch (af) {
     203        case AF_NONE:
     204                rc = dns_name_query(name, DTYPE_AAAA, info);
     205               
     206                if (rc != EOK)
     207                        rc = dns_name_query(name, DTYPE_A, info);
     208               
     209                break;
     210        case AF_INET:
     211                rc = dns_name_query(name, DTYPE_A, info);
     212                break;
     213        case AF_INET6:
     214                rc = dns_name_query(name, DTYPE_AAAA, info);
     215                break;
     216        default:
     217                rc = EINVAL;
     218        }
     219       
     220        if (rc == EOK)
     221                *rinfo = info;
     222        else
     223                free(info);
     224       
     225        return rc;
    145226}
    146227
  • uspace/srv/net/dnsrsrv/query.h

    r8a8a08d1 r330df83  
    3939#include "dns_type.h"
    4040
    41 extern int dns_name2host(const char *, dns_host_info_t **);
     41extern int dns_name2host(const char *, dns_host_info_t **, uint16_t);
    4242extern void dns_hostinfo_destroy(dns_host_info_t *);
    4343
  • uspace/srv/net/ethip/pdu.c

    r8a8a08d1 r330df83  
    4646#include "pdu.h"
    4747
    48 #define MAC48_BYTES 6
    49 
    5048/** Encode Ethernet PDU. */
    5149int eth_pdu_encode(eth_frame_t *frame, void **rdata, size_t *rsize)
  • uspace/srv/net/inetsrv/addrobj.c

    r8a8a08d1 r330df83  
    119119                    inet_addrobj_t, addr_list);
    120120               
    121                 if (inet_naddr_compare_mask(&naddr->naddr, addr)) {
    122                         fibril_mutex_unlock(&addr_list_lock);
    123                         log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_addrobj_find: found %p",
    124                             naddr);
    125                         return naddr;
     121                switch (find) {
     122                case iaf_net:
     123                        if (inet_naddr_compare_mask(&naddr->naddr, addr)) {
     124                                fibril_mutex_unlock(&addr_list_lock);
     125                                log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_addrobj_find: found %p",
     126                                    naddr);
     127                                return naddr;
     128                        }
     129                        break;
     130                case iaf_addr:
     131                        if (inet_naddr_compare(&naddr->naddr, addr)) {
     132                                fibril_mutex_unlock(&addr_list_lock);
     133                                log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_addrobj_find: found %p",
     134                                    naddr);
     135                                return naddr;
     136                        }
     137                        break;
    126138                }
    127139        }
  • uspace/srv/net/inetsrv/icmp.c

    r8a8a08d1 r330df83  
    153153                return ENOMEM;
    154154       
    155         icmp_echo_t *request = (icmp_echo_t *)rdata;
     155        icmp_echo_t *request = (icmp_echo_t *) rdata;
    156156       
    157157        request->type = ICMP_ECHO_REQUEST;
  • uspace/srv/net/inetsrv/icmpv6.c

    r8a8a08d1 r330df83  
    7878        inet_dgram_t rdgram;
    7979       
    80         rdgram.src = dgram->dest;
     80        inet_get_srcaddr(&dgram->src, 0, &rdgram.src);
    8181        rdgram.dest = dgram->src;
    8282        rdgram.tos = 0;
     
    8484        rdgram.size = size;
    8585       
    86         icmpv6_pseudo_header phdr;
     86        icmpv6_phdr_t phdr;
    8787       
    8888        host2addr128_t_be(dest_v6, phdr.src_addr);
     
    9494        uint16_t cs_phdr =
    9595            inet_checksum_calc(INET_CHECKSUM_INIT, &phdr,
    96             sizeof(icmpv6_pseudo_header));
     96            sizeof(icmpv6_phdr_t));
    9797       
    9898        uint16_t cs_all = inet_checksum_calc(cs_phdr, reply, size);
     
    150150        case ICMPV6_NEIGHBOUR_SOLICITATION:
    151151        case ICMPV6_NEIGHBOUR_ADVERTISEMENT:
    152 #ifdef ACCEPT_RA
    153152        case ICMPV6_ROUTER_ADVERTISEMENT:
    154 #endif
    155153                return ndp_received(dgram);
    156154        default:
     
    186184        dgram.size = rsize;
    187185       
    188         icmpv6_pseudo_header phdr;
     186        icmpv6_phdr_t phdr;
    189187       
    190188        host2addr128_t_be(sdu->src, phdr.src_addr);
     
    196194        uint16_t cs_phdr =
    197195            inet_checksum_calc(INET_CHECKSUM_INIT, &phdr,
    198             sizeof(icmpv6_pseudo_header));
     196            sizeof(icmpv6_phdr_t));
    199197       
    200198        uint16_t cs_all = inet_checksum_calc(cs_phdr, rdata, rsize);
  • uspace/srv/net/inetsrv/icmpv6_std.h

    r8a8a08d1 r330df83  
    104104        /** Next header */
    105105        uint8_t next;
    106 } icmpv6_pseudo_header;
     106} icmpv6_phdr_t;
    107107
    108108/** NDP neighbour body */
  • uspace/srv/net/inetsrv/inet_link.c

    r8a8a08d1 r330df83  
    5151static bool first_link = true;
    5252static bool first_link6 = true;
     53
     54static FIBRIL_MUTEX_INITIALIZE(ip_ident_lock);
     55static uint16_t ip_ident = 0;
    5356
    5457static int inet_link_open(service_id_t);
     
    335338}
    336339
    337 /** Send IPv4 datagram over Internet link */
     340/** Send IPv4 datagram over Internet link
     341 *
     342 * @param ilink Internet link
     343 * @param lsrc  Source IPv4 address
     344 * @param ldest Destination IPv4 address
     345 * @param dgram IPv4 datagram body
     346 * @param proto Protocol
     347 * @param ttl   Time-to-live
     348 * @param df    Do-not-Fragment flag
     349 *
     350 * @return EOK on success
     351 * @return ENOMEM when not enough memory to create the datagram
     352 * @return ENOTSUP if networking mode is not supported
     353 *
     354 */
    338355int inet_link_send_dgram(inet_link_t *ilink, addr32_t lsrc, addr32_t ldest,
    339356    inet_dgram_t *dgram, uint8_t proto, uint8_t ttl, int df)
     
    366383        packet.proto = proto;
    367384        packet.ttl = ttl;
     385       
     386        /* Allocate identifier */
     387        fibril_mutex_lock(&ip_ident_lock);
     388        packet.ident = ++ip_ident;
     389        fibril_mutex_unlock(&ip_ident_lock);
     390       
    368391        packet.df = df;
    369392        packet.data = dgram->data;
    370393        packet.size = dgram->size;
    371394       
     395        int rc;
    372396        size_t offs = 0;
    373         int rc;
    374397       
    375398        do {
     
    392415}
    393416
    394 /** Send IPv6 datagram over Internet link */
     417/** Send IPv6 datagram over Internet link
     418 *
     419 * @param ilink Internet link
     420 * @param ldest Destination MAC address
     421 * @param dgram IPv6 datagram body
     422 * @param proto Next header
     423 * @param ttl   Hop limit
     424 * @param df    Do-not-Fragment flag (unused)
     425 *
     426 * @return EOK on success
     427 * @return ENOMEM when not enough memory to create the datagram
     428 *
     429 */
    395430int inet_link_send_dgram6(inet_link_t *ilink, addr48_t ldest,
    396431    inet_dgram_t *dgram, uint8_t proto, uint8_t ttl, int df)
     
    421456        packet.proto = proto;
    422457        packet.ttl = ttl;
     458       
     459        /* Allocate identifier */
     460        fibril_mutex_lock(&ip_ident_lock);
     461        packet.ident = ++ip_ident;
     462        fibril_mutex_unlock(&ip_ident_lock);
     463       
    423464        packet.df = df;
    424465        packet.data = dgram->data;
  • uspace/srv/net/inetsrv/inet_std.h

    r8a8a08d1 r330df83  
    4040#include <sys/types.h>
    4141
     42#define IP6_NEXT_FRAGMENT  44
     43
    4244/** IPv4 Datagram header (fixed part) */
    4345typedef struct {
     
    4850        /** Total Length */
    4951        uint16_t tot_len;
    50         /** Identification */
     52        /** Identifier */
    5153        uint16_t id;
    5254        /** Flags, Fragment Offset */
     
    9092};
    9193
     94/** Bits in ip6_header_fragment_t.offsmf */
     95enum flags_offsmt_bits {
     96        /** More fragments */
     97        OF_FLAG_M = 0,
     98        /** Fragment offset, highest bit */
     99        OF_FRAGOFF_h = 15,
     100        /** Fragment offset, lowest bit */
     101        OF_FRAGOFF_l = 3
     102};
     103
    92104/** IPv6 Datagram header (fixed part) */
    93105typedef struct {
     
    114126        /** Reserved */
    115127        uint8_t reserved;
    116         /** Fragment Offset, Flags */
    117         uint16_t foff_flags;
    118         /** Identification */
     128        /** Fragmentation offset, reserved and M flag */
     129        uint16_t offsmf;
     130        /** Identifier */
    119131        uint32_t id;
    120132} ip6_header_fragment_t;
  • uspace/srv/net/inetsrv/inetsrv.c

    r8a8a08d1 r330df83  
    6262#define NAME "inetsrv"
    6363
     64static inet_naddr_t solicited_node_mask = {
     65        .family = AF_INET6,
     66        .addr6 = {0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01, 0xff, 0, 0, 0},
     67        .prefix = 104
     68};
     69
     70static inet_addr_t multicast_all_nodes = {
     71        .family = AF_INET,
     72        .addr6 = {0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01}
     73};
     74
    6475static void inet_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg);
    6576
     
    514525
    515526        addr = inet_addrobj_find(&packet->dest, iaf_addr);
    516         if (addr != NULL) {
     527        if ((addr != NULL) ||
     528            (inet_naddr_compare_mask(&solicited_node_mask, &packet->dest)) ||
     529            (inet_addr_compare(&multicast_all_nodes, &packet->dest))) {
    517530                /* Destined for one of the local addresses */
    518531
  • uspace/srv/net/inetsrv/inetsrv.h

    r8a8a08d1 r330df83  
    113113        uint8_t ttl;
    114114        /** Identifier */
    115         uint16_t ident;
     115        uint32_t ident;
    116116        /** Do not fragment */
    117117        bool df;
  • uspace/srv/net/inetsrv/ndp.c

    r8a8a08d1 r330df83  
    3838#include <mem.h>
    3939#include <malloc.h>
     40#include <io/log.h>
    4041#include <net/socket_codes.h>
    4142#include "ntrans.h"
     
    5455    {0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01, 0xff, 0, 0, 0};
    5556
     57/** Compute solicited node MAC multicast address from target IPv6 address
     58 *
     59 * @param ip_addr  Target IPv6 address
     60 * @param mac_addr Solicited MAC address to be assigned
     61 *
     62 */
    5663static void ndp_solicited_node_mac(addr128_t ip_addr, addr48_t mac_addr)
    5764{
     
    6067}
    6168
     69/** Compute solicited node IPv6 multicast address from target IPv6 address
     70 *
     71 * @param ip_addr      Target IPv6 address
     72 * @param ip_solicited Solicited IPv6 address to be assigned
     73 *
     74 */
    6275static void ndp_solicited_node_ip(addr128_t ip_addr,
    6376    addr128_t ip_solicited)
     
    88101int ndp_received(inet_dgram_t *dgram)
    89102{
     103        log_msg(LOG_DEFAULT, LVL_DEBUG, "ndp_received()");
     104       
    90105        ndp_packet_t packet;
    91106        int rc = ndp_pdu_decode(dgram, &packet);
     
    100115       
    101116        inet_addrobj_t *laddr;
     117       
     118        log_msg(LOG_DEFAULT, LVL_DEBUG, "NDP PDU decoded; opcode: %d",
     119            packet.opcode);
    102120       
    103121        switch (packet.opcode) {
     
    138156}
    139157
     158/** Translate IPv6 to MAC address
     159 *
     160 * @param src  Source IPv6 address
     161 * @param dest Destination IPv6 address
     162 * @param mac  Target MAC address to be assigned
     163 * @param link Network interface
     164 *
     165 * @return EOK on success
     166 * @return ENOENT when NDP translation failed
     167 *
     168 */
    140169int ndp_translate(addr128_t src_addr, addr128_t ip_addr, addr48_t mac_addr,
    141170    inet_link_t *ilink)
  • uspace/srv/net/inetsrv/ndp.h

    r8a8a08d1 r330df83  
    3535 */
    3636
    37 #ifndef ETH_NDP_H_
    38 #define ETH_NDP_H_
     37#ifndef NDP_H_
     38#define NDP_H_
    3939
    4040#include <sys/types.h>
  • uspace/srv/net/inetsrv/ntrans.c

    r8a8a08d1 r330df83  
    4747static FIBRIL_CONDVAR_INITIALIZE(ntrans_cv);
    4848
     49/** Look for address in translation table
     50 *
     51 * @param ip_addr IPv6 address
     52 *
     53 * @return inet_ntrans_t with the address on success
     54 * @return NULL if nothing found
     55 */
    4956static inet_ntrans_t *ntrans_find(addr128_t ip_addr)
    5057{
     
    6067}
    6168
     69/** Add entry to translation table
     70 *
     71 * @param ip_addr  IPv6 address of the new entry
     72 * @param mac_addr MAC address of the new entry
     73 *
     74 * @return EOK on success
     75 * @return ENOMEM if not enough memory
     76 *
     77 */
    6278int ntrans_add(addr128_t ip_addr, addr48_t mac_addr)
    6379{
     
    86102}
    87103
     104/** Remove entry from translation table
     105 *
     106 * @param ip_addr IPv6 address of the entry to be removed
     107 *
     108 * @return EOK on success
     109 * @return ENOENT when no such address found
     110 *
     111 */
    88112int ntrans_remove(addr128_t ip_addr)
    89113{
     
    104128}
    105129
     130/** Translate IPv6 address to MAC address using the translation table
     131 *
     132 * @param ip_addr  IPv6 address to be translated
     133 * @param mac_addr MAC address to be assigned
     134 *
     135 * @return EOK on success
     136 * @return ENOENT when no such address found
     137 *
     138 */
    106139int ntrans_lookup(addr128_t ip_addr, addr48_t mac_addr)
    107140{
     
    118151}
    119152
     153/** Wait on translation table CV for some time
     154 *
     155 * @param timeout Timeout in microseconds
     156 *
     157 * @return EOK if woken up by another fibril
     158 * @return ETIMEDOUT if timed out
     159 *
     160 */
    120161int ntrans_wait_timeout(suseconds_t timeout)
    121162{
  • uspace/srv/net/inetsrv/pdu.c

    r8a8a08d1 r330df83  
    4949#include "pdu.h"
    5050
    51 static FIBRIL_MUTEX_INITIALIZE(ip_ident_lock);
    52 static uint16_t ip_ident = 0;
    53 
    5451/** One's complement addition.
    5552 *
     
    107104 */
    108105int inet_pdu_encode(inet_packet_t *packet, addr32_t src, addr32_t dest,
    109    size_t offs, size_t mtu, void **rdata, size_t *rsize, size_t *roffs)
     106    size_t offs, size_t mtu, void **rdata, size_t *rsize, size_t *roffs)
    110107{
    111108        /* Upper bound for fragment offset field */
     
    117114       
    118115        size_t hdr_size = sizeof(ip_header_t);
    119        
    120         size_t data_offs = ROUND_UP(hdr_size, 4);
    121        
     116        if (hdr_size >= mtu)
     117                return EINVAL;
     118       
     119        assert(hdr_size % 4 == 0);
    122120        assert(offs % FRAG_OFFS_UNIT == 0);
    123121        assert(offs / FRAG_OFFS_UNIT < fragoff_limit);
     
    125123        /* Value for the fragment offset field */
    126124        uint16_t foff = offs / FRAG_OFFS_UNIT;
    127        
    128         if (hdr_size >= mtu)
    129                 return EINVAL;
    130125       
    131126        /* Amount of space in the PDU available for payload */
     
    152147                return ENOMEM;
    153148       
    154         /* Allocate identifier */
    155         fibril_mutex_lock(&ip_ident_lock);
    156         uint16_t ident = ++ip_ident;
    157         fibril_mutex_unlock(&ip_ident_lock);
    158        
    159149        /* Encode header fields */
    160150        ip_header_t *hdr = (ip_header_t *) data;
     
    164154        hdr->tos = packet->tos;
    165155        hdr->tot_len = host2uint16_t_be(size);
    166         hdr->id = host2uint16_t_be(ident);
     156        hdr->id = host2uint16_t_be(packet->ident);
    167157        hdr->flags_foff = host2uint16_t_be(flags_foff);
    168158        hdr->ttl = packet->ttl;
     
    178168       
    179169        /* Copy payload */
    180         memcpy((uint8_t *) data + data_offs, packet->data + offs, xfer_size);
     170        memcpy((uint8_t *) data + hdr_size, packet->data + offs, xfer_size);
    181171       
    182172        *rdata = data;
     
    202192 * @param rdata  Place to store pointer to allocated data buffer
    203193 * @param rsize  Place to store size of allocated data buffer
    204  * @param roffs Place to store offset of remaning data
     194 * @param roffs  Place to store offset of remaning data
    205195 *
    206196 */
     
    208198    size_t offs, size_t mtu, void **rdata, size_t *rsize, size_t *roffs)
    209199{
     200        /* IPv6 mandates a minimal MTU of 1280 bytes */
     201        if (mtu < 1280)
     202                return ELIMIT;
     203       
    210204        /* Upper bound for fragment offset field */
    211         size_t fragoff_limit = 1 << (FF_FRAGOFF_h - FF_FRAGOFF_l);
     205        size_t fragoff_limit = 1 << (OF_FRAGOFF_h - OF_FRAGOFF_l);
    212206       
    213207        /* Verify that total size of datagram is within reasonable bounds */
     
    215209                return ELIMIT;
    216210       
    217         size_t hdr_size = sizeof(ip6_header_t);
    218        
    219         size_t data_offs = ROUND_UP(hdr_size, 4);
    220        
     211        /* Determine whether we need the Fragment extension header */
     212        bool fragment;
     213        if (offs == 0)
     214                fragment = (packet->size + sizeof(ip6_header_t) > mtu);
     215        else
     216                fragment = true;
     217       
     218        size_t hdr_size;
     219        if (fragment)
     220                hdr_size = sizeof(ip6_header_t) + sizeof(ip6_header_fragment_t);
     221        else
     222                hdr_size = sizeof(ip6_header_t);
     223       
     224        if (hdr_size >= mtu)
     225                return EINVAL;
     226       
     227        assert(sizeof(ip6_header_t) % 8 == 0);
     228        assert(hdr_size % 8 == 0);
    221229        assert(offs % FRAG_OFFS_UNIT == 0);
    222230        assert(offs / FRAG_OFFS_UNIT < fragoff_limit);
    223231       
    224 #if 0
    225         // FIXME TODO fragmentation
    226        
    227232        /* Value for the fragment offset field */
    228233        uint16_t foff = offs / FRAG_OFFS_UNIT;
    229 #endif
    230        
    231         if (hdr_size >= mtu)
    232                 return EINVAL;
    233234       
    234235        /* Amount of space in the PDU available for payload */
     
    245246        size_t rem_offs = offs + xfer_size;
    246247       
    247 #if 0
    248         // FIXME TODO fragmentation
    249        
    250248        /* Flags */
    251         uint16_t flags_foff =
    252             (packet->df ? BIT_V(uint16_t, FF_FLAG_DF) : 0) +
    253             (rem_offs < packet->size ? BIT_V(uint16_t, FF_FLAG_MF) : 0) +
    254             (foff << FF_FRAGOFF_l);
    255 #endif
     249        uint16_t offsmf =
     250            (rem_offs < packet->size ? BIT_V(uint16_t, OF_FLAG_M) : 0) +
     251            (foff << OF_FRAGOFF_l);
    256252       
    257253        void *data = calloc(size, 1);
     
    259255                return ENOMEM;
    260256       
    261 #if 0
    262         // FIXME TODO fragmentation
    263        
    264         /* Allocate identifier */
    265         fibril_mutex_lock(&ip_ident_lock);
    266         uint16_t ident = ++ip_ident;
    267         fibril_mutex_unlock(&ip_ident_lock);
    268 #endif
    269        
    270257        /* Encode header fields */
    271258        ip6_header_t *hdr6 = (ip6_header_t *) data;
     
    273260        hdr6->ver_tc = (6 << (VI_VERSION_l));
    274261        memset(hdr6->tc_fl, 0, 3);
    275         hdr6->payload_len = host2uint16_t_be(packet->size);
    276         hdr6->next = packet->proto;
    277262        hdr6->hop_limit = packet->ttl;
    278263       
     
    280265        host2addr128_t_be(dest, hdr6->dest_addr);
    281266       
     267        /* Optionally encode Fragment extension header fields */
     268        if (fragment) {
     269                assert(offsmf != 0);
     270               
     271                hdr6->payload_len = host2uint16_t_be(packet->size +
     272                    sizeof(ip6_header_fragment_t));
     273                hdr6->next = IP6_NEXT_FRAGMENT;
     274               
     275                ip6_header_fragment_t *hdr6f = (ip6_header_fragment_t *)
     276                    (hdr6 + 1);
     277               
     278                hdr6f->next = packet->proto;
     279                hdr6f->reserved = 0;
     280                hdr6f->offsmf = host2uint16_t_be(offsmf);
     281                hdr6f->id = host2uint32_t_be(packet->ident);
     282        } else {
     283                assert(offsmf == 0);
     284               
     285                hdr6->payload_len = host2uint16_t_be(packet->size);
     286                hdr6->next = packet->proto;
     287        }
     288       
    282289        /* Copy payload */
    283         memcpy((uint8_t *) data + data_offs, packet->data + offs, xfer_size);
     290        memcpy((uint8_t *) data + hdr_size, packet->data + offs, xfer_size);
    284291       
    285292        *rdata = data;
     
    290297}
    291298
     299/** Decode IPv4 datagram
     300 *
     301 * @param data   Serialized IPv4 datagram
     302 * @param size   Length of serialized IPv4 datagram
     303 * @param packet IP datagram structure to be filled
     304 *
     305 * @return EOK on success
     306 * @return EINVAL if the datagram is invalid or damaged
     307 * @return ENOMEM if not enough memory
     308 *
     309 */
    292310int inet_pdu_decode(void *data, size_t size, inet_packet_t *packet)
    293311{
     
    353371}
    354372
     373/** Decode IPv6 datagram
     374 *
     375 * @param data   Serialized IPv6 datagram
     376 * @param size   Length of serialized IPv6 datagram
     377 * @param packet IP datagram structure to be filled
     378 *
     379 * @return EOK on success
     380 * @return EINVAL if the datagram is invalid or damaged
     381 * @return ENOMEM if not enough memory
     382 *
     383 */
    355384int inet_pdu_decode6(void *data, size_t size, inet_packet_t *packet)
    356385{
     
    373402        size_t payload_len = uint16_t_be2host(hdr6->payload_len);
    374403        if (payload_len + sizeof(ip6_header_t) > size) {
    375                 log_msg(LOG_DEFAULT, LVL_DEBUG, "Total Length = %zu > PDU size = %zu",
     404                log_msg(LOG_DEFAULT, LVL_DEBUG, "Payload Length = %zu > PDU size = %zu",
    376405                    payload_len + sizeof(ip6_header_t), size);
    377406                return EINVAL;
    378407        }
    379408       
    380 #if 0
    381         // FIXME TODO fragmentation
    382        
    383         uint16_t ident = uint16_t_be2host(hdr->id);
    384         uint16_t flags_foff = uint16_t_be2host(hdr->flags_foff);
    385         uint16_t foff = BIT_RANGE_EXTRACT(uint16_t, FF_FRAGOFF_h, FF_FRAGOFF_l,
    386             flags_foff);
    387 #endif
    388        
    389         /* XXX Checksum */
     409        uint32_t ident;
     410        uint16_t offsmf;
     411        uint16_t foff;
     412        uint16_t next;
     413        size_t data_offs = sizeof(ip6_header_t);
     414       
     415        /* Fragment extension header */
     416        if (hdr6->next == IP6_NEXT_FRAGMENT) {
     417                ip6_header_fragment_t *hdr6f = (ip6_header_fragment_t *)
     418                    (hdr6 + 1);
     419               
     420                ident = uint32_t_be2host(hdr6f->id);
     421                offsmf = uint16_t_be2host(hdr6f->offsmf);
     422                foff = BIT_RANGE_EXTRACT(uint16_t, OF_FRAGOFF_h, OF_FRAGOFF_l,
     423                    offsmf);
     424                next = hdr6f->next;
     425                data_offs += sizeof(ip6_header_fragment_t);
     426                payload_len -= sizeof(ip6_header_fragment_t);
     427        } else {
     428                ident = 0;
     429                offsmf = 0;
     430                foff = 0;
     431                next = hdr6->next;
     432        }
    390433       
    391434        addr128_t src;
     
    399442       
    400443        packet->tos = 0;
    401         packet->proto = hdr6->next;
     444        packet->proto = next;
    402445        packet->ttl = hdr6->hop_limit;
    403        
    404 #if 0
    405         // FIXME TODO fragmentation
    406        
    407446        packet->ident = ident;
    408         packet->df = (flags_foff & BIT_V(uint16_t, FF_FLAG_DF)) != 0;
    409         packet->mf = (flags_foff & BIT_V(uint16_t, FF_FLAG_MF)) != 0;
     447       
     448        packet->df = 1;
     449        packet->mf = (offsmf & BIT_V(uint16_t, OF_FLAG_M)) != 0;
    410450        packet->offs = foff * FRAG_OFFS_UNIT;
    411        
    412         /* XXX IP options */
    413         size_t data_offs = sizeof(uint32_t) *
    414             BIT_RANGE_EXTRACT(uint8_t, VI_IHL_h, VI_IHL_l, hdr->ver_ihl);
    415 #endif
    416        
    417         packet->ident = 0;
    418         packet->df = 0;
    419         packet->mf = 0;
    420         packet->offs = 0;
    421451       
    422452        packet->size = payload_len;
     
    427457        }
    428458       
    429         memcpy(packet->data, (uint8_t *) data + sizeof(ip6_header_t), packet->size);
     459        memcpy(packet->data, (uint8_t *) data + data_offs, packet->size);
    430460       
    431461        return EOK;
    432462}
    433463
     464/** Encode NDP packet
     465 *
     466 * @param ndp   NDP packet structure to be serialized
     467 * @param dgram IPv6 datagram structure to be filled
     468 *
     469 * @return EOK on success
     470 *
     471 */
    434472int ndp_pdu_encode(ndp_packet_t *ndp, inet_dgram_t *dgram)
    435473{
     
    464502        addr48(ndp->sender_hw_addr, message->mac);
    465503       
    466         icmpv6_pseudo_header phdr;
     504        icmpv6_phdr_t phdr;
    467505       
    468506        host2addr128_t_be(ndp->sender_proto_addr, phdr.src_addr);
     
    474512        uint16_t cs_phdr =
    475513            inet_checksum_calc(INET_CHECKSUM_INIT, &phdr,
    476             sizeof(icmpv6_pseudo_header));
     514            sizeof(icmpv6_phdr_t));
    477515       
    478516        uint16_t cs_all = inet_checksum_calc(cs_phdr, dgram->data,
     
    484522}
    485523
     524/** Decode NDP packet
     525 *
     526 * @param dgram Incoming IPv6 datagram encapsulating NDP packet
     527 * @param ndp   NDP packet structure to be filled
     528 *
     529 * @return EOK on success
     530 * @return EINVAL if the Datagram is invalid
     531 *
     532 */
    486533int ndp_pdu_decode(inet_dgram_t *dgram, ndp_packet_t *ndp)
    487534{
  • uspace/srv/net/inetsrv/reass.c

    r8a8a08d1 r330df83  
    164164                return NULL;
    165165
    166         link_initialize(&rdg->map_link);
     166        list_append(&rdg->map_link, &reass_dgram_map);
    167167        list_initialize(&rdg->frags);
    168168
  • uspace/srv/net/tcp/conn.c

    r8a8a08d1 r330df83  
    312312static bool tcp_socket_match(tcp_sock_t *sock, tcp_sock_t *patt)
    313313{
     314        log_msg(LOG_DEFAULT, LVL_DEBUG2,
     315            "tcp_socket_match(sock=(%u), pat=(%u))", sock->port, patt->port);
     316       
    314317        if ((!inet_addr_is_any(&patt->addr)) &&
    315318            (!inet_addr_compare(&patt->addr, &sock->addr)))
     
    351354{
    352355        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_find_ref(%p)", sp);
     356       
     357        log_msg(LOG_DEFAULT, LVL_DEBUG2, "compare conn (f:(%u), l:(%u))",
     358            sp->foreign.port, sp->local.port);
    353359       
    354360        fibril_mutex_lock(&conn_list_lock);
     
    357363                tcp_conn_t *conn = list_get_instance(link, tcp_conn_t, link);
    358364                tcp_sockpair_t *csp = &conn->ident;
     365               
     366                log_msg(LOG_DEFAULT, LVL_DEBUG2, " - with (f:(%u), l:(%u))",
     367                    csp->foreign.port, csp->local.port);
    359368               
    360369                if (tcp_sockpair_match(sp, csp)) {
  • uspace/srv/net/tcp/pdu.c

    r8a8a08d1 r330df83  
    172172                phdr6->tcp_length =
    173173                    host2uint32_t_be(pdu->header_size + pdu->text_size);
    174                 memset(phdr6->zero, 0, 3);
     174                memset(phdr6->zeroes, 0, 3);
    175175                phdr6->next = IP_PROTO_TCP;
    176176                break;
  • uspace/srv/net/tcp/sock.c

    r8a8a08d1 r330df83  
    613613        ipc_callid_t wcallid;
    614614        size_t length;
    615         uint8_t buffer[TCP_SOCK_FRAGMENT_SIZE];
    616615        tcp_error_t trc;
    617616        int rc;
     617       
     618        uint8_t *buffer = calloc(TCP_SOCK_FRAGMENT_SIZE, 1);
     619        if (buffer == NULL) {
     620                async_answer_0(callid, ENOMEM);
     621                return;
     622        }
    618623
    619624        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_sock_send()");
     
    625630        if (sock_core == NULL) {
    626631                async_answer_0(callid, ENOTSOCK);
    627                 return;
     632                goto out;
    628633        }
    629634
     
    641646                        fibril_mutex_unlock(&socket->lock);
    642647                        async_answer_0(callid, EINVAL);
    643                         return;
     648                        goto out;
    644649                }
    645650
     
    651656                        fibril_mutex_unlock(&socket->lock);
    652657                        async_answer_0(callid, rc);
    653                         return;
     658                        goto out;
    654659                }
    655660
     
    676681                        fibril_mutex_unlock(&socket->lock);
    677682                        async_answer_0(callid, rc);
    678                         return;
     683                        goto out;
    679684                }
    680685        }
     
    685690            IPC_GET_ARG2(answer));
    686691        fibril_mutex_unlock(&socket->lock);
     692       
     693out:
     694        free(buffer);
    687695}
    688696
  • uspace/srv/net/tcp/std.h

    r8a8a08d1 r330df83  
    7575};
    7676
    77 /** TCP IPv4 pseudo header */
     77/** TCP over IPv4 checksum pseudo header */
    7878typedef struct {
    7979        /** Source address */
     
    8989} tcp_phdr_t;
    9090
    91 /** TCP IPv6 pseudo header */
     91/** TCP over IPv6 checksum pseudo header */
    9292typedef struct {
    9393        /** Source address */
     
    9898        uint32_t tcp_length;
    9999        /** Zeroes */
    100         uint8_t zero[3];
     100        uint8_t zeroes[3];
    101101        /** Next header */
    102102        uint8_t next;
  • uspace/srv/net/tcp/tcp.c

    r8a8a08d1 r330df83  
    5454#define NAME       "tcp"
    5555
    56 #define IP_PROTO_TCP 6
    57 
    5856static int tcp_inet_ev_recv(inet_dgram_t *dgram);
    5957static void tcp_received_pdu(tcp_pdu_t *pdu);
  • uspace/srv/net/tcp/tqueue.c

    r8a8a08d1 r330df83  
    282282void tcp_transmit_segment(tcp_sockpair_t *sp, tcp_segment_t *seg)
    283283{
     284        log_msg(LOG_DEFAULT, LVL_DEBUG,
     285            "tcp_transmit_segment(f:(%u),l:(%u), %p)",
     286            sp->local.port, sp->foreign.port, seg);
     287       
    284288        log_msg(LOG_DEFAULT, LVL_DEBUG, "SEG.SEQ=%" PRIu32 ", SEG.WND=%" PRIu32,
    285289            seg->seq, seg->wnd);
  • uspace/srv/net/tcp/ucall.c

    r8a8a08d1 r330df83  
    298298        tcp_conn_t *conn;
    299299
     300        log_msg(LOG_DEFAULT, LVL_DEBUG,
     301            "tcp_as_segment_arrived(f:(%u), l:(%u))",
     302            sp->foreign.port, sp->local.port);
     303
    300304        conn = tcp_conn_find_ref(sp);
    301305        if (conn == NULL) {
  • uspace/srv/net/udp/assoc.c

    r8a8a08d1 r330df83  
    372372static bool udp_socket_match(udp_sock_t *sock, udp_sock_t *patt)
    373373{
     374        log_msg(LOG_DEFAULT, LVL_DEBUG,
     375            "udp_socket_match(sock=(%u), pat=(%u))", sock->port, patt->port);
     376       
    374377        if ((!inet_addr_is_any(&patt->addr)) &&
    375378            (!inet_addr_compare(&patt->addr, &sock->addr)))
  • uspace/srv/net/udp/pdu.c

    r8a8a08d1 r330df83  
    110110                host2addr128_t_be(dest_v6, phdr6->dest_addr);
    111111                phdr6->udp_length = host2uint32_t_be(pdu->data_size);
    112                 memset(phdr6->zero, 0, 3);
     112                memset(phdr6->zeroes, 0, 3);
    113113                phdr6->next = IP_PROTO_UDP;
    114114                break;
  • uspace/srv/net/udp/sock.c

    r8a8a08d1 r330df83  
    265265        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_send()");
    266266       
     267        uint8_t *buffer = calloc(UDP_FRAGMENT_SIZE, 1);
     268        if (buffer == NULL) {
     269                async_answer_0(callid, ENOMEM);
     270                return;
     271        }
     272       
    267273        struct sockaddr_in6 *addr6 = NULL;
    268274        struct sockaddr_in *addr;
     
    276282                if (rc != EOK) {
    277283                        async_answer_0(callid, rc);
    278                         return;
     284                        goto out;
    279285                }
    280286               
     
    357363                        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_sendto: Failed to "
    358364                            "determine local address.");
    359                         return;
     365                        goto out;
    360366                }
    361367               
     
    379385                        length = UDP_FRAGMENT_SIZE;
    380386               
    381                 uint8_t buffer[UDP_FRAGMENT_SIZE];
    382387                int rc = async_data_write_finalize(wcallid, buffer, length);
    383388                if (rc != EOK) {
     
    425430        if (addr6 != NULL)
    426431                free(addr6);
     432       
     433        free(buffer);
    427434}
    428435
  • uspace/srv/net/udp/std.h

    r8a8a08d1 r330df83  
    5454} udp_header_t;
    5555
    56 /** UDP IPv4 pseudo header */
     56/** UDP over IPv4 checksum pseudo header */
    5757typedef struct {
    5858        /** Source address */
     
    6868} udp_phdr_t;
    6969
    70 /** UDP IPv6 pseudo header */
     70/** UDP over IPv6 checksum pseudo header */
    7171typedef struct {
    7272        /** Source address */
     
    7676        /** UDP length */
    7777        uint32_t udp_length;
    78         /** Reserved */
    79         uint8_t zero[3];
     78        /** Zeroes */
     79        uint8_t zeroes[3];
    8080        /** Next header */
    8181        uint8_t next;
Note: See TracChangeset for help on using the changeset viewer.