Changeset bdae198 in mainline for uspace/srv


Ignore:
Timestamp:
2013-08-04T12:01:10Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ea509069
Parents:
b08879c2 (diff), d856110 (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 mainline changes

Location:
uspace/srv/net
Files:
4 added
37 edited

Legend:

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

    rb08879c2 rbdae198  
    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

    rb08879c2 rbdae198  
    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);
    5153
    5254#endif
  • uspace/srv/net/dnsrsrv/dns_std.h

    rb08879c2 rbdae198  
    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

    rb08879c2 rbdae198  
    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

    rb08879c2 rbdae198  
    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

    rb08879c2 rbdae198  
    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/ethip.c

    rb08879c2 rbdae198  
    5656static int ethip_close(iplink_srv_t *srv);
    5757static int ethip_send(iplink_srv_t *srv, iplink_sdu_t *sdu);
     58static int ethip_send6(iplink_srv_t *srv, iplink_sdu6_t *sdu);
    5859static int ethip_get_mtu(iplink_srv_t *srv, size_t *mtu);
     60static int ethip_get_mac48(iplink_srv_t *srv, addr48_t *mac);
    5961static int ethip_addr_add(iplink_srv_t *srv, inet_addr_t *addr);
    6062static int ethip_addr_remove(iplink_srv_t *srv, inet_addr_t *addr);
     
    6668        .close = ethip_close,
    6769        .send = ethip_send,
     70        .send6 = ethip_send6,
    6871        .get_mtu = ethip_get_mtu,
     72        .get_mac48 = ethip_get_mac48,
    6973        .addr_add = ethip_addr_add,
    7074        .addr_remove = ethip_addr_remove
     
    169173       
    170174        ethip_nic_t *nic = (ethip_nic_t *) srv->arg;
    171        
    172         addr32_t src_v4;
    173         addr128_t src_v6;
    174         uint16_t src_af = inet_addr_get(&sdu->src, &src_v4, &src_v6);
    175        
    176         addr32_t dest_v4;
    177         addr128_t dest_v6;
    178         uint16_t dest_af = inet_addr_get(&sdu->dest, &dest_v4, &dest_v6);
    179        
    180         if (src_af != dest_af)
    181                 return EINVAL;
    182        
    183         int rc;
    184175        eth_frame_t frame;
    185176       
    186         switch (src_af) {
    187         case AF_INET:
    188                 rc = arp_translate(nic, src_v4, dest_v4, frame.dest);
    189                 if (rc != EOK) {
    190                         log_msg(LOG_DEFAULT, LVL_WARN, "Failed to look up IPv4 address 0x%"
    191                             PRIx32, dest_v4);
    192                         return rc;
    193                 }
    194                
    195                 addr48(nic->mac_addr, frame.src);
    196                 frame.etype_len = ETYPE_IP;
    197                 frame.data = sdu->data;
    198                 frame.size = sdu->size;
    199                
    200                 break;
    201         case AF_INET6:
    202                 // FIXME TODO
    203                 return ENOTSUP;
    204         default:
    205                 return EINVAL;
    206         }
     177        int rc = arp_translate(nic, sdu->src, sdu->dest, frame.dest);
     178        if (rc != EOK) {
     179                log_msg(LOG_DEFAULT, LVL_WARN, "Failed to look up IPv4 address 0x%"
     180                    PRIx32, sdu->dest);
     181                return rc;
     182        }
     183       
     184        addr48(nic->mac_addr, frame.src);
     185        frame.etype_len = ETYPE_IP;
     186        frame.data = sdu->data;
     187        frame.size = sdu->size;
    207188       
    208189        void *data;
    209190        size_t size;
    210191        rc = eth_pdu_encode(&frame, &data, &size);
     192        if (rc != EOK)
     193                return rc;
     194       
     195        rc = ethip_nic_send(nic, data, size);
     196        free(data);
     197       
     198        return rc;
     199}
     200
     201static int ethip_send6(iplink_srv_t *srv, iplink_sdu6_t *sdu)
     202{
     203        log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_send6()");
     204       
     205        ethip_nic_t *nic = (ethip_nic_t *) srv->arg;
     206        eth_frame_t frame;
     207       
     208        addr48(sdu->dest, frame.dest);
     209        addr48(nic->mac_addr, frame.src);
     210        frame.etype_len = ETYPE_IPV6;
     211        frame.data = sdu->data;
     212        frame.size = sdu->size;
     213       
     214        void *data;
     215        size_t size;
     216        int rc = eth_pdu_encode(&frame, &data, &size);
    211217        if (rc != EOK)
    212218                return rc;
     
    268274}
    269275
     276static int ethip_get_mac48(iplink_srv_t *srv, addr48_t *mac)
     277{
     278        log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_get_mac48()");
     279       
     280        ethip_nic_t *nic = (ethip_nic_t *) srv->arg;
     281        addr48(nic->mac_addr, *mac);
     282       
     283        return EOK;
     284}
     285
    270286static int ethip_addr_add(iplink_srv_t *srv, inet_addr_t *addr)
    271287{
  • uspace/srv/net/ethip/ethip.h

    rb08879c2 rbdae198  
    4646
    4747typedef struct {
    48         link_t addr_list;
     48        link_t link;
    4949        inet_addr_t addr;
    5050} ethip_link_addr_t;
    5151
    5252typedef struct ethip_nic {
    53         link_t nic_list;
     53        link_t link;
    5454        service_id_t svc_id;
    5555        char *svc_name;
     
    6161        /** MAC address */
    6262        addr48_t mac_addr;
    63         /** List of IP addresses configured on this link */
    64         list_t addr_list; /* of ethip_link_addr_t */
     63       
     64        /**
     65         * List of IP addresses configured on this link
     66         * (of the type ethip_link_addr_t)
     67         */
     68        list_t addr_list;
    6569} ethip_nic_t;
    6670
  • uspace/srv/net/ethip/ethip_nic.c

    rb08879c2 rbdae198  
    4545#include <device/nic.h>
    4646#include <stdlib.h>
    47 
     47#include <net/socket_codes.h>
     48#include <mem.h>
    4849#include "ethip.h"
    4950#include "ethip_nic.h"
     
    8384                already_known = false;
    8485
    85                 list_foreach(ethip_nic_list, nic_link) {
    86                         ethip_nic_t *nic = list_get_instance(nic_link,
    87                             ethip_nic_t, nic_list);
     86                list_foreach(ethip_nic_list, link) {
     87                        ethip_nic_t *nic = list_get_instance(link,
     88                            ethip_nic_t, link);
    8889                        if (nic->svc_id == svcs[i]) {
    8990                                already_known = true;
     
    108109{
    109110        ethip_nic_t *nic = calloc(1, sizeof(ethip_nic_t));
    110 
    111111        if (nic == NULL) {
    112112                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed allocating NIC structure. "
     
    114114                return NULL;
    115115        }
    116 
    117         link_initialize(&nic->nic_list);
     116       
     117        link_initialize(&nic->link);
    118118        list_initialize(&nic->addr_list);
    119 
     119       
    120120        return nic;
    121121}
     
    130130        }
    131131       
    132         link_initialize(&laddr->addr_list);
     132        link_initialize(&laddr->link);
    133133        laddr->addr = *addr;
    134134       
     
    140140        if (nic->svc_name != NULL)
    141141                free(nic->svc_name);
     142       
    142143        free(nic);
    143144}
     
    180181
    181182        log_msg(LOG_DEFAULT, LVL_DEBUG, "Opened NIC '%s'", nic->svc_name);
    182         list_append(&nic->nic_list, &ethip_nic_list);
     183        list_append(&nic->link, &ethip_nic_list);
    183184        in_list = true;
    184185
     
    209210error:
    210211        if (in_list)
    211                 list_remove(&nic->nic_list);
     212                list_remove(&nic->link);
     213       
    212214        if (nic->sess != NULL)
    213215                async_hangup(nic->sess);
     216       
    214217        ethip_nic_delete(nic);
    215218        return rc;
     
    312315        list_foreach(ethip_nic_list, link) {
    313316                log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_find_by_iplink_sid - element");
    314                 ethip_nic_t *nic = list_get_instance(link, ethip_nic_t,
    315                     nic_list);
     317                ethip_nic_t *nic = list_get_instance(link, ethip_nic_t, link);
    316318
    317319                if (nic->iplink_sid == iplink_sid) {
     
    334336}
    335337
     338/** Setup accepted multicast addresses
     339 *
     340 * Currently the set of accepted multicast addresses is
     341 * determined only based on IPv6 addresses.
     342 *
     343 */
     344static int ethip_nic_setup_multicast(ethip_nic_t *nic)
     345{
     346        log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_setup_multicast()");
     347       
     348        /* Count the number of multicast addresses */
     349       
     350        size_t count = 0;
     351       
     352        list_foreach(nic->addr_list, link) {
     353                ethip_link_addr_t *laddr = list_get_instance(link,
     354                    ethip_link_addr_t, link);
     355               
     356                uint16_t af = inet_addr_get(&laddr->addr, NULL, NULL);
     357                if (af == AF_INET6)
     358                        count++;
     359        }
     360       
     361        if (count == 0)
     362                return nic_multicast_set_mode(nic->sess, NIC_MULTICAST_BLOCKED,
     363                    NULL, 0);
     364       
     365        nic_address_t *mac_list = calloc(count, sizeof(nic_address_t));
     366        if (mac_list == NULL)
     367                return ENOMEM;
     368       
     369        /* Create the multicast MAC list */
     370       
     371        size_t i = 0;
     372       
     373        list_foreach(nic->addr_list, link) {
     374                assert(i < count);
     375               
     376                ethip_link_addr_t *laddr = list_get_instance(link,
     377                    ethip_link_addr_t, link);
     378               
     379                addr128_t v6;
     380                uint16_t af = inet_addr_get(&laddr->addr, NULL, &v6);
     381                if (af != AF_INET6)
     382                        continue;
     383               
     384                addr48_t mac;
     385                addr48_solicited_node(v6, mac);
     386               
     387                /* Avoid duplicate addresses in the list */
     388               
     389                bool found = false;
     390               
     391                for (size_t j = 0; j < i; j++) {
     392                        if (addr48_compare(mac_list[j].address, mac)) {
     393                                found = true;
     394                                break;
     395                        }
     396                }
     397               
     398                if (!found) {
     399                        addr48(mac, mac_list[i].address);
     400                        i++;
     401                } else
     402                        count--;
     403        }
     404       
     405        /* Setup the multicast MAC list */
     406       
     407        int rc = nic_multicast_set_mode(nic->sess, NIC_MULTICAST_LIST,
     408            mac_list, count);
     409       
     410        free(mac_list);
     411        return rc;
     412}
     413
    336414int ethip_nic_addr_add(ethip_nic_t *nic, inet_addr_t *addr)
    337415{
     
    342420                return ENOMEM;
    343421       
    344         list_append(&laddr->addr_list, &nic->addr_list);
    345         return EOK;
     422        list_append(&laddr->link, &nic->addr_list);
     423       
     424        return ethip_nic_setup_multicast(nic);
    346425}
    347426
     
    354433                return ENOENT;
    355434       
    356         list_remove(&laddr->addr_list);
     435        list_remove(&laddr->link);
    357436        ethip_link_addr_delete(laddr);
    358         return EOK;
     437       
     438        return ethip_nic_setup_multicast(nic);
    359439}
    360440
     
    366446        list_foreach(nic->addr_list, link) {
    367447                ethip_link_addr_t *laddr = list_get_instance(link,
    368                     ethip_link_addr_t, addr_list);
     448                    ethip_link_addr_t, link);
    369449               
    370450                if (inet_addr_compare(addr, &laddr->addr))
  • uspace/srv/net/ethip/pdu.c

    rb08879c2 rbdae198  
    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/Makefile

    rb08879c2 rbdae198  
    3939        inetping.c \
    4040        inetping6.c \
     41        ndp.c \
     42        ntrans.c \
    4143        pdu.c \
    4244        reass.c \
  • uspace/srv/net/inetsrv/addrobj.c

    rb08879c2 rbdae198  
    4242#include <stdlib.h>
    4343#include <str.h>
     44#include <net/socket_codes.h>
    4445#include "addrobj.h"
    4546#include "inetsrv.h"
    4647#include "inet_link.h"
     48#include "ndp.h"
    4749
    4850static inet_addrobj_t *inet_addrobj_find_by_name_locked(const char *, inet_link_t *);
     
    117119                    inet_addrobj_t, addr_list);
    118120               
    119                 if (inet_naddr_compare_mask(&naddr->naddr, addr)) {
    120                         fibril_mutex_unlock(&addr_list_lock);
    121                         log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_addrobj_find: found %p",
    122                             naddr);
    123                         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;
    124138                }
    125139        }
     
    214228        inet_naddr_addr(&addr->naddr, &lsrc_addr);
    215229       
    216         return inet_link_send_dgram(addr->ilink, &lsrc_addr, ldest, dgram,
    217             proto, ttl, df);
     230        addr32_t lsrc_v4;
     231        addr128_t lsrc_v6;
     232        uint16_t lsrc_af = inet_addr_get(&lsrc_addr, &lsrc_v4, &lsrc_v6);
     233       
     234        addr32_t ldest_v4;
     235        addr128_t ldest_v6;
     236        uint16_t ldest_af = inet_addr_get(ldest, &ldest_v4, &ldest_v6);
     237       
     238        if (lsrc_af != ldest_af)
     239                return EINVAL;
     240       
     241        int rc;
     242        addr48_t ldest_mac;
     243       
     244        switch (ldest_af) {
     245        case AF_INET:
     246                return inet_link_send_dgram(addr->ilink, lsrc_v4, ldest_v4,
     247                    dgram, proto, ttl, df);
     248        case AF_INET6:
     249                /*
     250                 * Translate local destination IPv6 address.
     251                 */
     252                rc = ndp_translate(lsrc_v6, ldest_v6, ldest_mac, addr->ilink);
     253                if (rc != EOK)
     254                        return rc;
     255               
     256                return inet_link_send_dgram6(addr->ilink, ldest_mac, dgram,
     257                    proto, ttl, df);
     258        }
     259       
     260        return ENOTSUP;
    218261}
    219262
  • uspace/srv/net/inetsrv/icmp.c

    rb08879c2 rbdae198  
    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

    rb08879c2 rbdae198  
    4747#include "pdu.h"
    4848
    49 static int ndp_received(inet_dgram_t *dgram)
    50 {
    51         // FIXME TODO
    52         return ENOTSUP;
    53 }
    54 
    5549static int icmpv6_recv_echo_request(inet_dgram_t *dgram)
    5650{
     
    8478        inet_dgram_t rdgram;
    8579       
    86         rdgram.src = dgram->dest;
     80        inet_get_srcaddr(&dgram->src, 0, &rdgram.src);
    8781        rdgram.dest = dgram->src;
    8882        rdgram.tos = 0;
     
    9084        rdgram.size = size;
    9185       
    92         icmpv6_pseudo_header phdr;
     86        icmpv6_phdr_t phdr;
    9387       
    9488        host2addr128_t_be(dest_v6, phdr.src_addr);
     
    10094        uint16_t cs_phdr =
    10195            inet_checksum_calc(INET_CHECKSUM_INIT, &phdr,
    102             sizeof(icmpv6_pseudo_header));
     96            sizeof(icmpv6_phdr_t));
    10397       
    10498        uint16_t cs_all = inet_checksum_calc(cs_phdr, reply, size);
     
    156150        case ICMPV6_NEIGHBOUR_SOLICITATION:
    157151        case ICMPV6_NEIGHBOUR_ADVERTISEMENT:
    158 #ifdef ACCEPT_RA
    159152        case ICMPV6_ROUTER_ADVERTISEMENT:
    160 #endif
    161153                return ndp_received(dgram);
    162154        default:
     
    192184        dgram.size = rsize;
    193185       
    194         icmpv6_pseudo_header phdr;
     186        icmpv6_phdr_t phdr;
    195187       
    196188        host2addr128_t_be(sdu->src, phdr.src_addr);
     
    202194        uint16_t cs_phdr =
    203195            inet_checksum_calc(INET_CHECKSUM_INIT, &phdr,
    204             sizeof(icmpv6_pseudo_header));
     196            sizeof(icmpv6_phdr_t));
    205197       
    206198        uint16_t cs_all = inet_checksum_calc(cs_phdr, rdata, rsize);
  • uspace/srv/net/inetsrv/icmpv6_std.h

    rb08879c2 rbdae198  
    4747#define INET6_HOP_LIMIT_MAX  255
    4848
     49#define NDP_FLAG_ROUTER     0x80
     50#define NDP_FLAG_OVERRIDE   0x40
     51#define NDP_FLAG_SOLICITED  0x20
     52
    4953/** ICMPv6 message type */
    5054enum icmpv6_type {
     
    8387                        uint8_t flags;
    8488                        /** Reserved bytes */
    85                         uint8_t reserved [3];
     89                        uint8_t reserved[3];
    8690                } ndp;
    8791        } un;
     
    9195typedef struct {
    9296        /** Source IPv6 address */
    93         uint8_t src_addr [16];
     97        uint8_t src_addr[16];
    9498        /** Target IPv6 address */
    95         uint8_t dest_addr [16];
     99        uint8_t dest_addr[16];
    96100        /** ICMPv6 length */
    97101        uint32_t length;
    98102        /** Zeroes */
    99         uint8_t zeroes [3];
     103        uint8_t zeroes[3];
    100104        /** Next header */
    101105        uint8_t next;
    102 } icmpv6_pseudo_header;
     106} icmpv6_phdr_t;
    103107
    104108/** NDP neighbour body */
    105109typedef struct {
    106110        /** Target IPv6 address */
    107         uint8_t target_address [16];
     111        uint8_t target_address[16];
    108112        /** Option code */
    109113        uint8_t option;
     
    111115        uint8_t length;
    112116        /** MAC address */
    113         uint8_t mac [6];
     117        uint8_t mac[6];
    114118} ndp_message_t;
    115119
     
    131135        uint32_t reserved;
    132136        /** Prefix */
    133         uint8_t prefix [16];
     137        uint8_t prefix[16];
    134138} ndp_prefix_t;
    135139
  • uspace/srv/net/inetsrv/inet_link.c

    rb08879c2 rbdae198  
    4949#include "pdu.h"
    5050
     51static bool first_link = true;
     52static bool first_link6 = true;
     53
     54static FIBRIL_MUTEX_INITIALIZE(ip_ident_lock);
     55static uint16_t ip_ident = 0;
     56
    5157static int inet_link_open(service_id_t);
    5258static int inet_iplink_recv(iplink_t *, iplink_recv_sdu_t *, uint16_t);
     
    5864static LIST_INITIALIZE(inet_link_list);
    5965static FIBRIL_MUTEX_INITIALIZE(inet_discovery_lock);
     66
     67static addr128_t link_local_node_ip =
     68    {0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xfe, 0, 0, 0};
     69
     70static void inet_link_local_node_ip(addr48_t mac_addr,
     71    addr128_t ip_addr)
     72{
     73        memcpy(ip_addr, link_local_node_ip, 16);
     74       
     75        ip_addr[8] = mac_addr[0] ^ 0x02;
     76        ip_addr[9] = mac_addr[1];
     77        ip_addr[10] = mac_addr[2];
     78        ip_addr[13] = mac_addr[3];
     79        ip_addr[14] = mac_addr[4];
     80        ip_addr[15] = mac_addr[5];
     81}
    6082
    6183static int inet_iplink_recv(iplink_t *iplink, iplink_recv_sdu_t *sdu, uint16_t af)
     
    159181        if (ilink->svc_name != NULL)
    160182                free(ilink->svc_name);
     183       
    161184        free(ilink);
    162185}
     
    201224                goto error;
    202225        }
     226       
     227        /*
     228         * Get the MAC address of the link. If the link has a MAC
     229         * address, we assume that it supports NDP.
     230         */
     231        rc = iplink_get_mac48(ilink->iplink, &ilink->mac);
     232        ilink->mac_valid = (rc == EOK);
    203233
    204234        log_msg(LOG_DEFAULT, LVL_DEBUG, "Opened IP link '%s'", ilink->svc_name);
    205235        list_append(&ilink->link_list, &inet_link_list);
    206236
    207         inet_addrobj_t *addr;
    208         inet_addrobj_t *addr6;
    209 
    210         static int first = 1;
    211        
    212         addr = inet_addrobj_new();
    213         addr6 = inet_addrobj_new();
    214        
    215         if (first) {
     237        inet_addrobj_t *addr = NULL;
     238       
     239        if (first_link) {
     240                addr = inet_addrobj_new();
     241               
    216242                inet_naddr(&addr->naddr, 127, 0, 0, 1, 24);
    217                 inet_naddr6(&addr6->naddr, 0, 0, 0, 0, 0, 0, 0, 1, 128);
    218                 first = 0;
     243                first_link = false;
    219244        } else {
    220245                /*
    221246                 * FIXME
    222                  * Setting static IP addresses for testing purposes
     247                 * Setting static IPv4 address for testing purposes:
    223248                 * 10.0.2.15/24
    224                  * fd19:1680::4/120
    225249                 */
     250                addr = inet_addrobj_new();
     251               
    226252                inet_naddr(&addr->naddr, 10, 0, 2, 15, 24);
    227                 inet_naddr6(&addr6->naddr, 0xfd19, 0x1680, 0, 0, 0, 0, 0, 4, 120);
    228         }
    229        
    230         addr->ilink = ilink;
    231         addr6->ilink = ilink;
    232         addr->name = str_dup("v4a");
    233         addr6->name = str_dup("v6a");
    234        
    235         rc = inet_addrobj_add(addr);
    236         if (rc != EOK) {
    237                 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed adding IPv4 address.");
    238                 inet_addrobj_delete(addr);
    239                 /* XXX Roll back */
    240                 return rc;
    241         }
    242        
    243         rc = inet_addrobj_add(addr6);
    244         if (rc != EOK) {
    245                 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed adding IPv6 address.");
    246                 inet_addrobj_delete(addr6);
    247                 /* XXX Roll back */
    248                 return rc;
    249         }
    250        
    251         inet_naddr_addr(&addr->naddr, &iaddr);
    252         rc = iplink_addr_add(ilink->iplink, &iaddr);
    253         if (rc != EOK) {
    254                 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed setting IPv4 address on internet link.");
    255                 inet_addrobj_remove(addr);
    256                 inet_addrobj_delete(addr);
    257                 /* XXX Roll back */
    258                 return rc;
    259         }
    260        
    261         inet_naddr_addr(&addr6->naddr, &iaddr);
    262         rc = iplink_addr_add(ilink->iplink, &iaddr);
    263         if (rc != EOK) {
    264                 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed setting IPv6 address on internet link.");
    265                 inet_addrobj_remove(addr6);
    266                 inet_addrobj_delete(addr6);
    267                 /* XXX Roll back */
    268                 return rc;
     253        }
     254       
     255        if (addr != NULL) {
     256                addr->ilink = ilink;
     257                addr->name = str_dup("v4a");
     258               
     259                rc = inet_addrobj_add(addr);
     260                if (rc == EOK) {
     261                        inet_naddr_addr(&addr->naddr, &iaddr);
     262                        rc = iplink_addr_add(ilink->iplink, &iaddr);
     263                        if (rc != EOK) {
     264                                log_msg(LOG_DEFAULT, LVL_ERROR,
     265                                    "Failed setting IPv4 address on internet link.");
     266                                inet_addrobj_remove(addr);
     267                                inet_addrobj_delete(addr);
     268                        }
     269                } else {
     270                        log_msg(LOG_DEFAULT, LVL_ERROR, "Failed adding IPv4 address.");
     271                        inet_addrobj_delete(addr);
     272                }
     273        }
     274       
     275        inet_addrobj_t *addr6 = NULL;
     276       
     277        if (first_link6) {
     278                addr6 = inet_addrobj_new();
     279               
     280                inet_naddr6(&addr6->naddr, 0, 0, 0, 0, 0, 0, 0, 1, 128);
     281                first_link6 = false;
     282        } else if (ilink->mac_valid) {
     283                addr6 = inet_addrobj_new();
     284               
     285                addr128_t link_local;
     286                inet_link_local_node_ip(ilink->mac, link_local);
     287               
     288                inet_naddr_set6(link_local, 64, &addr6->naddr);
     289        }
     290       
     291        if (addr6 != NULL) {
     292                addr6->ilink = ilink;
     293                addr6->name = str_dup("v6a");
     294               
     295                rc = inet_addrobj_add(addr6);
     296                if (rc == EOK) {
     297                        inet_naddr_addr(&addr6->naddr, &iaddr);
     298                        rc = iplink_addr_add(ilink->iplink, &iaddr);
     299                        if (rc != EOK) {
     300                                log_msg(LOG_DEFAULT, LVL_ERROR,
     301                                    "Failed setting IPv6 address on internet link.");
     302                                inet_addrobj_remove(addr6);
     303                                inet_addrobj_delete(addr6);
     304                        }
     305                } else {
     306                        log_msg(LOG_DEFAULT, LVL_ERROR, "Failed adding IPv6 address.");
     307                        inet_addrobj_delete(addr6);
     308                }
    269309        }
    270310       
     
    298338}
    299339
    300 /** Send datagram over Internet link */
    301 int inet_link_send_dgram(inet_link_t *ilink, inet_addr_t *lsrc,
    302     inet_addr_t *ldest, inet_dgram_t *dgram, uint8_t proto, uint8_t ttl, int df)
    303 {
     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 */
     355int inet_link_send_dgram(inet_link_t *ilink, addr32_t lsrc, addr32_t ldest,
     356    inet_dgram_t *dgram, uint8_t proto, uint8_t ttl, int df)
     357{
     358        addr32_t src_v4;
     359        uint16_t src_af = inet_addr_get(&dgram->src, &src_v4, NULL);
     360        if (src_af != AF_INET)
     361                return EINVAL;
     362       
     363        addr32_t dest_v4;
     364        uint16_t dest_af = inet_addr_get(&dgram->dest, &dest_v4, NULL);
     365        if (dest_af != AF_INET)
     366                return EINVAL;
     367       
    304368        /*
    305369         * Fill packet structure. Fragmentation is performed by
    306370         * inet_pdu_encode().
    307371         */
     372       
     373        iplink_sdu_t sdu;
     374       
     375        sdu.src = lsrc;
     376        sdu.dest = ldest;
    308377       
    309378        inet_packet_t packet;
     
    314383        packet.proto = proto;
    315384        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       
    316391        packet.df = df;
    317392        packet.data = dgram->data;
    318393        packet.size = dgram->size;
    319394       
    320         iplink_sdu_t sdu;
     395        int rc;
    321396        size_t offs = 0;
    322         int rc;
    323        
    324         sdu.src = *lsrc;
    325         sdu.dest = *ldest;
    326397       
    327398        do {
    328399                /* Encode one fragment */
     400               
    329401                size_t roffs;
    330                 rc = inet_pdu_encode(&packet, offs, ilink->def_mtu, &sdu.data,
    331                     &sdu.size, &roffs);
     402                rc = inet_pdu_encode(&packet, src_v4, dest_v4, offs, ilink->def_mtu,
     403                    &sdu.data, &sdu.size, &roffs);
    332404                if (rc != EOK)
    333405                        return rc;
     
    335407                /* Send the PDU */
    336408                rc = iplink_send(ilink->iplink, &sdu);
     409               
    337410                free(sdu.data);
    338                
     411                offs = roffs;
     412        } while (offs < packet.size);
     413       
     414        return rc;
     415}
     416
     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 */
     430int inet_link_send_dgram6(inet_link_t *ilink, addr48_t ldest,
     431    inet_dgram_t *dgram, uint8_t proto, uint8_t ttl, int df)
     432{
     433        addr128_t src_v6;
     434        uint16_t src_af = inet_addr_get(&dgram->src, NULL, &src_v6);
     435        if (src_af != AF_INET6)
     436                return EINVAL;
     437       
     438        addr128_t dest_v6;
     439        uint16_t dest_af = inet_addr_get(&dgram->dest, NULL, &dest_v6);
     440        if (dest_af != AF_INET6)
     441                return EINVAL;
     442       
     443        iplink_sdu6_t sdu6;
     444        addr48(ldest, sdu6.dest);
     445       
     446        /*
     447         * Fill packet structure. Fragmentation is performed by
     448         * inet_pdu_encode6().
     449         */
     450       
     451        inet_packet_t packet;
     452       
     453        packet.src = dgram->src;
     454        packet.dest = dgram->dest;
     455        packet.tos = dgram->tos;
     456        packet.proto = proto;
     457        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       
     464        packet.df = df;
     465        packet.data = dgram->data;
     466        packet.size = dgram->size;
     467       
     468        int rc;
     469        size_t offs = 0;
     470       
     471        do {
     472                /* Encode one fragment */
     473               
     474                size_t roffs;
     475                rc = inet_pdu_encode6(&packet, src_v6, dest_v6, offs, ilink->def_mtu,
     476                    &sdu6.data, &sdu6.size, &roffs);
     477                if (rc != EOK)
     478                        return rc;
     479               
     480                /* Send the PDU */
     481                rc = iplink_send6(ilink->iplink, &sdu6);
     482               
     483                free(sdu6.data);
    339484                offs = roffs;
    340485        } while (offs < packet.size);
  • uspace/srv/net/inetsrv/inet_link.h

    rb08879c2 rbdae198  
    4242
    4343extern int inet_link_discovery_start(void);
    44 extern int inet_link_send_dgram(inet_link_t *, inet_addr_t *,
    45     inet_addr_t *, inet_dgram_t *, uint8_t, uint8_t, int);
     44extern int inet_link_send_dgram(inet_link_t *, addr32_t,
     45    addr32_t, inet_dgram_t *, uint8_t, uint8_t, int);
     46extern int inet_link_send_dgram6(inet_link_t *, addr48_t, inet_dgram_t *,
     47    uint8_t, uint8_t, int);
    4648extern inet_link_t *inet_link_get_by_id(sysarg_t);
    4749
  • uspace/srv/net/inetsrv/inet_std.h

    rb08879c2 rbdae198  
    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/inetping6.c

    rb08879c2 rbdae198  
    109109        aid_t req = async_send_1(exch, INETPING6_EV_RECV, sdu->seq_no, &answer);
    110110       
    111         int rc = async_data_write_start(exch, sdu->src, 16);
     111        int rc = async_data_write_start(exch, sdu->src, sizeof(addr128_t));
    112112        if (rc != EOK) {
    113113                async_exchange_end(exch);
     
    116116        }
    117117       
    118         rc = async_data_write_start(exch, sdu->dest, 16);
     118        rc = async_data_write_start(exch, sdu->dest, sizeof(addr128_t));
    119119        if (rc != EOK) {
    120120                async_exchange_end(exch);
  • uspace/srv/net/inetsrv/inetsrv.c

    rb08879c2 rbdae198  
    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_INET6,
     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

    rb08879c2 rbdae198  
    113113        uint8_t ttl;
    114114        /** Identifier */
    115         uint16_t ident;
     115        uint32_t ident;
    116116        /** Do not fragment */
    117117        bool df;
     
    141141        iplink_t *iplink;
    142142        size_t def_mtu;
     143        addr48_t mac;
     144        bool mac_valid;
    143145} inet_link_t;
    144146
  • uspace/srv/net/inetsrv/pdu.c

    rb08879c2 rbdae198  
    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 *
     
    8885}
    8986
    90 /** Encode Internet PDU.
     87/** Encode IPv4 PDU.
    9188 *
    9289 * Encode internet packet into PDU (serialized form). Will encode a
     
    9693 * be set in the header, otherwise the offset will equal @a packet->size.
    9794 *
    98  * @param packet        Packet to encode
    99  * @param offs          Offset into packet payload (in bytes)
    100  * @param mtu           MTU (Maximum Transmission Unit) in bytes
    101  * @param rdata         Place to store pointer to allocated data buffer
    102  * @param rsize         Place to store size of allocated data buffer
    103  * @param roffs         Place to store offset of remaning data
    104  */
    105 int inet_pdu_encode(inet_packet_t *packet, size_t offs, size_t mtu,
    106     void **rdata, size_t *rsize, size_t *roffs)
    107 {
    108         addr32_t src_v4;
    109         addr128_t src_v6;
    110         uint16_t src_af = inet_addr_get(&packet->src, &src_v4, &src_v6);
    111        
    112         addr32_t dest_v4;
    113         addr128_t dest_v6;
    114         uint16_t dest_af = inet_addr_get(&packet->dest, &dest_v4, &dest_v6);
    115        
    116         if (src_af != dest_af)
    117                 return EINVAL;
    118        
     95 * @param packet Packet to encode
     96 * @param src    Source address
     97 * @param dest   Destination address
     98 * @param offs   Offset into packet payload (in bytes)
     99 * @param mtu    MTU (Maximum Transmission Unit) in bytes
     100 * @param rdata  Place to store pointer to allocated data buffer
     101 * @param rsize  Place to store size of allocated data buffer
     102 * @param roffs  Place to store offset of remaning data
     103 *
     104 */
     105int inet_pdu_encode(inet_packet_t *packet, addr32_t src, addr32_t dest,
     106    size_t offs, size_t mtu, void **rdata, size_t *rsize, size_t *roffs)
     107{
    119108        /* Upper bound for fragment offset field */
    120109        size_t fragoff_limit = 1 << (FF_FRAGOFF_h - FF_FRAGOFF_l);
     
    124113                return ELIMIT;
    125114       
    126         size_t hdr_size;
    127        
    128         switch (src_af) {
    129         case AF_INET:
    130                 hdr_size = sizeof(ip_header_t);
    131                 break;
    132         case AF_INET6:
    133                 hdr_size = sizeof(ip6_header_t);
    134                 break;
    135         default:
    136                 assert(false);
    137         }
    138        
    139         size_t data_offs = ROUND_UP(hdr_size, 4);
    140        
     115        size_t hdr_size = sizeof(ip_header_t);
     116        if (hdr_size >= mtu)
     117                return EINVAL;
     118       
     119        assert(hdr_size % 4 == 0);
    141120        assert(offs % FRAG_OFFS_UNIT == 0);
    142121        assert(offs / FRAG_OFFS_UNIT < fragoff_limit);
     
    144123        /* Value for the fragment offset field */
    145124        uint16_t foff = offs / FRAG_OFFS_UNIT;
    146        
    147         if (hdr_size >= mtu)
    148                 return EINVAL;
    149125       
    150126        /* Amount of space in the PDU available for payload */
     
    171147                return ENOMEM;
    172148       
    173         /* Allocate identifier */
    174         fibril_mutex_lock(&ip_ident_lock);
    175         uint16_t ident = ++ip_ident;
    176         fibril_mutex_unlock(&ip_ident_lock);
    177        
    178149        /* Encode header fields */
    179         ip_header_t *hdr;
    180         ip6_header_t *hdr6;
    181        
    182         switch (src_af) {
    183         case AF_INET:
    184                 hdr = (ip_header_t *) data;
    185                
    186                 hdr->ver_ihl =
    187                     (4 << VI_VERSION_l) | (hdr_size / sizeof(uint32_t));
    188                 hdr->tos = packet->tos;
    189                 hdr->tot_len = host2uint16_t_be(size);
    190                 hdr->id = host2uint16_t_be(ident);
    191                 hdr->flags_foff = host2uint16_t_be(flags_foff);
    192                 hdr->ttl = packet->ttl;
    193                 hdr->proto = packet->proto;
    194                 hdr->chksum = 0;
    195                 hdr->src_addr = host2uint32_t_be(src_v4);
    196                 hdr->dest_addr = host2uint32_t_be(dest_v4);
    197                
    198                 /* Compute checksum */
    199                 uint16_t chksum = inet_checksum_calc(INET_CHECKSUM_INIT,
    200                     (void *) hdr, hdr_size);
    201                 hdr->chksum = host2uint16_t_be(chksum);
    202                
    203                 break;
    204         case AF_INET6:
    205                 // TODO FIXME: fragmentation
    206                
    207                 hdr6 = (ip6_header_t *) data;
    208                
    209                 hdr6->ver_tc = (6 << (VI_VERSION_l));
    210                 memset(hdr6->tc_fl, 0, 3);
    211                 hdr6->payload_len = host2uint16_t_be(packet->size);
    212                 hdr6->next = packet->proto;
    213                 hdr6->hop_limit = packet->ttl;
    214                
    215                 host2addr128_t_be(src_v6, hdr6->src_addr);
    216                 host2addr128_t_be(dest_v6, hdr6->dest_addr);
    217                
    218                 break;
    219         default:
    220                 assert(false);
    221         }
     150        ip_header_t *hdr = (ip_header_t *) data;
     151       
     152        hdr->ver_ihl =
     153            (4 << VI_VERSION_l) | (hdr_size / sizeof(uint32_t));
     154        hdr->tos = packet->tos;
     155        hdr->tot_len = host2uint16_t_be(size);
     156        hdr->id = host2uint16_t_be(packet->ident);
     157        hdr->flags_foff = host2uint16_t_be(flags_foff);
     158        hdr->ttl = packet->ttl;
     159        hdr->proto = packet->proto;
     160        hdr->chksum = 0;
     161        hdr->src_addr = host2uint32_t_be(src);
     162        hdr->dest_addr = host2uint32_t_be(dest);
     163       
     164        /* Compute checksum */
     165        uint16_t chksum = inet_checksum_calc(INET_CHECKSUM_INIT,
     166            (void *) hdr, hdr_size);
     167        hdr->chksum = host2uint16_t_be(chksum);
    222168       
    223169        /* Copy payload */
    224         memcpy((uint8_t *) data + data_offs, packet->data + offs, xfer_size);
     170        memcpy((uint8_t *) data + hdr_size, packet->data + offs, xfer_size);
    225171       
    226172        *rdata = data;
     
    231177}
    232178
     179/** Encode IPv6 PDU.
     180 *
     181 * Encode internet packet into PDU (serialized form). Will encode a
     182 * fragment of the payload starting at offset @a offs. The resulting
     183 * PDU will have at most @a mtu bytes. @a *roffs will be set to the offset
     184 * of remaining payload. If some data is remaining, the MF flag will
     185 * be set in the header, otherwise the offset will equal @a packet->size.
     186 *
     187 * @param packet Packet to encode
     188 * @param src    Source address
     189 * @param dest   Destination address
     190 * @param offs   Offset into packet payload (in bytes)
     191 * @param mtu    MTU (Maximum Transmission Unit) in bytes
     192 * @param rdata  Place to store pointer to allocated data buffer
     193 * @param rsize  Place to store size of allocated data buffer
     194 * @param roffs  Place to store offset of remaning data
     195 *
     196 */
     197int inet_pdu_encode6(inet_packet_t *packet, addr128_t src, addr128_t dest,
     198    size_t offs, size_t mtu, void **rdata, size_t *rsize, size_t *roffs)
     199{
     200        /* IPv6 mandates a minimal MTU of 1280 bytes */
     201        if (mtu < 1280)
     202                return ELIMIT;
     203       
     204        /* Upper bound for fragment offset field */
     205        size_t fragoff_limit = 1 << (OF_FRAGOFF_h - OF_FRAGOFF_l);
     206       
     207        /* Verify that total size of datagram is within reasonable bounds */
     208        if (offs + packet->size > FRAG_OFFS_UNIT * fragoff_limit)
     209                return ELIMIT;
     210       
     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);
     229        assert(offs % FRAG_OFFS_UNIT == 0);
     230        assert(offs / FRAG_OFFS_UNIT < fragoff_limit);
     231       
     232        /* Value for the fragment offset field */
     233        uint16_t foff = offs / FRAG_OFFS_UNIT;
     234       
     235        /* Amount of space in the PDU available for payload */
     236        size_t spc_avail = mtu - hdr_size;
     237        spc_avail -= (spc_avail % FRAG_OFFS_UNIT);
     238       
     239        /* Amount of data (payload) to transfer */
     240        size_t xfer_size = min(packet->size - offs, spc_avail);
     241       
     242        /* Total PDU size */
     243        size_t size = hdr_size + xfer_size;
     244       
     245        /* Offset of remaining payload */
     246        size_t rem_offs = offs + xfer_size;
     247       
     248        /* Flags */
     249        uint16_t offsmf =
     250            (rem_offs < packet->size ? BIT_V(uint16_t, OF_FLAG_M) : 0) +
     251            (foff << OF_FRAGOFF_l);
     252       
     253        void *data = calloc(size, 1);
     254        if (data == NULL)
     255                return ENOMEM;
     256       
     257        /* Encode header fields */
     258        ip6_header_t *hdr6 = (ip6_header_t *) data;
     259       
     260        hdr6->ver_tc = (6 << (VI_VERSION_l));
     261        memset(hdr6->tc_fl, 0, 3);
     262        hdr6->hop_limit = packet->ttl;
     263       
     264        host2addr128_t_be(src, hdr6->src_addr);
     265        host2addr128_t_be(dest, hdr6->dest_addr);
     266       
     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       
     289        /* Copy payload */
     290        memcpy((uint8_t *) data + hdr_size, packet->data + offs, xfer_size);
     291       
     292        *rdata = data;
     293        *rsize = size;
     294        *roffs = rem_offs;
     295       
     296        return EOK;
     297}
     298
     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 */
    233310int inet_pdu_decode(void *data, size_t size, inet_packet_t *packet)
    234311{
     
    257334        if (tot_len > size) {
    258335                log_msg(LOG_DEFAULT, LVL_DEBUG, "Total Length = %zu > PDU size = %zu",
    259                         tot_len, size);
     336                    tot_len, size);
    260337                return EINVAL;
    261338        }
     
    294371}
    295372
     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 */
    296384int inet_pdu_decode6(void *data, size_t size, inet_packet_t *packet)
    297385{
    298         // FIXME TODO
    299         return ENOTSUP;
     386        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_pdu_decode6()");
     387       
     388        if (size < sizeof(ip6_header_t)) {
     389                log_msg(LOG_DEFAULT, LVL_DEBUG, "PDU too short (%zu)", size);
     390                return EINVAL;
     391        }
     392       
     393        ip6_header_t *hdr6 = (ip6_header_t *) data;
     394       
     395        uint8_t version = BIT_RANGE_EXTRACT(uint8_t, VI_VERSION_h,
     396            VI_VERSION_l, hdr6->ver_tc);
     397        if (version != 6) {
     398                log_msg(LOG_DEFAULT, LVL_DEBUG, "Version (%d) != 6", version);
     399                return EINVAL;
     400        }
     401       
     402        size_t payload_len = uint16_t_be2host(hdr6->payload_len);
     403        if (payload_len + sizeof(ip6_header_t) > size) {
     404                log_msg(LOG_DEFAULT, LVL_DEBUG, "Payload Length = %zu > PDU size = %zu",
     405                    payload_len + sizeof(ip6_header_t), size);
     406                return EINVAL;
     407        }
     408       
     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        }
     433       
     434        addr128_t src;
     435        addr128_t dest;
     436       
     437        addr128_t_be2host(hdr6->src_addr, src);
     438        inet_addr_set6(src, &packet->src);
     439       
     440        addr128_t_be2host(hdr6->dest_addr, dest);
     441        inet_addr_set6(dest, &packet->dest);
     442       
     443        packet->tos = 0;
     444        packet->proto = next;
     445        packet->ttl = hdr6->hop_limit;
     446        packet->ident = ident;
     447       
     448        packet->df = 1;
     449        packet->mf = (offsmf & BIT_V(uint16_t, OF_FLAG_M)) != 0;
     450        packet->offs = foff * FRAG_OFFS_UNIT;
     451       
     452        packet->size = payload_len;
     453        packet->data = calloc(packet->size, 1);
     454        if (packet->data == NULL) {
     455                log_msg(LOG_DEFAULT, LVL_WARN, "Out of memory.");
     456                return ENOMEM;
     457        }
     458       
     459        memcpy(packet->data, (uint8_t *) data + data_offs, packet->size);
     460       
     461        return EOK;
     462}
     463
     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 */
     472int ndp_pdu_encode(ndp_packet_t *ndp, inet_dgram_t *dgram)
     473{
     474        inet_addr_set6(ndp->sender_proto_addr, &dgram->src);
     475        inet_addr_set6(ndp->target_proto_addr, &dgram->dest);
     476        dgram->tos = 0;
     477        dgram->size = sizeof(icmpv6_message_t) + sizeof(ndp_message_t);
     478       
     479        dgram->data = calloc(1, dgram->size);
     480        if (dgram->data == NULL)
     481                return ENOMEM;
     482       
     483        icmpv6_message_t *icmpv6 = (icmpv6_message_t *) dgram->data;
     484       
     485        icmpv6->type = ndp->opcode;
     486        icmpv6->code = 0;
     487        memset(icmpv6->un.ndp.reserved, 0, 3);
     488       
     489        ndp_message_t *message = (ndp_message_t *) (icmpv6 + 1);
     490       
     491        if (ndp->opcode == ICMPV6_NEIGHBOUR_SOLICITATION) {
     492                host2addr128_t_be(ndp->solicited_ip, message->target_address);
     493                message->option = 1;
     494                icmpv6->un.ndp.flags = 0;
     495        } else {
     496                host2addr128_t_be(ndp->sender_proto_addr, message->target_address);
     497                message->option = 2;
     498                icmpv6->un.ndp.flags = NDP_FLAG_OVERRIDE | NDP_FLAG_SOLICITED;
     499        }
     500       
     501        message->length = 1;
     502        addr48(ndp->sender_hw_addr, message->mac);
     503       
     504        icmpv6_phdr_t phdr;
     505       
     506        host2addr128_t_be(ndp->sender_proto_addr, phdr.src_addr);
     507        host2addr128_t_be(ndp->target_proto_addr, phdr.dest_addr);
     508        phdr.length = host2uint32_t_be(dgram->size);
     509        memset(phdr.zeroes, 0, 3);
     510        phdr.next = IP_PROTO_ICMPV6;
     511       
     512        uint16_t cs_phdr =
     513            inet_checksum_calc(INET_CHECKSUM_INIT, &phdr,
     514            sizeof(icmpv6_phdr_t));
     515       
     516        uint16_t cs_all = inet_checksum_calc(cs_phdr, dgram->data,
     517            dgram->size);
     518       
     519        icmpv6->checksum = host2uint16_t_be(cs_all);
     520       
     521        return EOK;
     522}
     523
     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 */
     533int ndp_pdu_decode(inet_dgram_t *dgram, ndp_packet_t *ndp)
     534{
     535        uint16_t src_af = inet_addr_get(&dgram->src, NULL,
     536            &ndp->sender_proto_addr);
     537        if (src_af != AF_INET6)
     538                return EINVAL;
     539       
     540        if (dgram->size < sizeof(icmpv6_message_t) + sizeof(ndp_message_t))
     541                return EINVAL;
     542       
     543        icmpv6_message_t *icmpv6 = (icmpv6_message_t *) dgram->data;
     544       
     545        ndp->opcode = icmpv6->type;
     546       
     547        ndp_message_t *message = (ndp_message_t *) (icmpv6 + 1);
     548       
     549        addr128_t_be2host(message->target_address, ndp->target_proto_addr);
     550        addr48(message->mac, ndp->sender_hw_addr);
     551       
     552        return EOK;
    300553}
    301554
  • uspace/srv/net/inetsrv/pdu.h

    rb08879c2 rbdae198  
    4040#include <sys/types.h>
    4141#include "inetsrv.h"
     42#include "ndp.h"
    4243
    4344#define INET_CHECKSUM_INIT 0xffff
     
    4546extern uint16_t inet_checksum_calc(uint16_t, void *, size_t);
    4647
    47 extern int inet_pdu_encode(inet_packet_t *, size_t, size_t, void **,
    48     size_t *, size_t *);
     48extern int inet_pdu_encode(inet_packet_t *, addr32_t, addr32_t, size_t, size_t,
     49    void **, size_t *, size_t *);
     50extern int inet_pdu_encode6(inet_packet_t *, addr128_t, addr128_t, size_t,
     51    size_t, void **, size_t *, size_t *);
    4952extern int inet_pdu_decode(void *, size_t, inet_packet_t *);
    5053extern int inet_pdu_decode6(void *, size_t, inet_packet_t *);
     54
     55extern int ndp_pdu_decode(inet_dgram_t *, ndp_packet_t *);
     56extern int ndp_pdu_encode(ndp_packet_t *, inet_dgram_t *);
    5157
    5258#endif
  • uspace/srv/net/inetsrv/reass.c

    rb08879c2 rbdae198  
    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/loopip/loopip.c

    rb08879c2 rbdae198  
    4040#include <inet/iplink_srv.h>
    4141#include <inet/addr.h>
     42#include <net/socket_codes.h>
    4243#include <io/log.h>
    4344#include <loc.h>
     
    5051static int loopip_close(iplink_srv_t *srv);
    5152static int loopip_send(iplink_srv_t *srv, iplink_sdu_t *sdu);
     53static int loopip_send6(iplink_srv_t *srv, iplink_sdu6_t *sdu);
    5254static int loopip_get_mtu(iplink_srv_t *srv, size_t *mtu);
     55static int loopip_get_mac48(iplink_srv_t *srv, addr48_t *mac);
    5356static int loopip_addr_add(iplink_srv_t *srv, inet_addr_t *addr);
    5457static int loopip_addr_remove(iplink_srv_t *srv, inet_addr_t *addr);
     
    6063        .close = loopip_close,
    6164        .send = loopip_send,
     65        .send6 = loopip_send6,
    6266        .get_mtu = loopip_get_mtu,
     67        .get_mac48 = loopip_get_mac48,
    6368        .addr_add = loopip_addr_add,
    6469        .addr_remove = loopip_addr_remove
     
    162167        log_msg(LOG_DEFAULT, LVL_DEBUG, "loopip_send()");
    163168       
    164         addr32_t src_v4;
    165         addr128_t src_v6;
    166         uint16_t src_af = inet_addr_get(&sdu->src, &src_v4, &src_v6);
    167        
    168         addr32_t dest_v4;
    169         addr128_t dest_v6;
    170         uint16_t dest_af = inet_addr_get(&sdu->dest, &dest_v4, &dest_v6);
    171        
    172         if (src_af != dest_af)
    173                 return EINVAL;
    174        
    175169        rqueue_entry_t *rqe = calloc(1, sizeof(rqueue_entry_t));
    176170        if (rqe == NULL)
     
    180174         * Clone SDU
    181175         */
    182         rqe->af = src_af;
     176        rqe->af = AF_INET;
    183177        rqe->sdu.data = malloc(sdu->size);
    184178        if (rqe->sdu.data == NULL) {
     
    198192}
    199193
     194static int loopip_send6(iplink_srv_t *srv, iplink_sdu6_t *sdu)
     195{
     196        log_msg(LOG_DEFAULT, LVL_DEBUG, "loopip6_send()");
     197       
     198        rqueue_entry_t *rqe = calloc(1, sizeof(rqueue_entry_t));
     199        if (rqe == NULL)
     200                return ENOMEM;
     201       
     202        /*
     203         * Clone SDU
     204         */
     205        rqe->af = AF_INET6;
     206        rqe->sdu.data = malloc(sdu->size);
     207        if (rqe->sdu.data == NULL) {
     208                free(rqe);
     209                return ENOMEM;
     210        }
     211       
     212        memcpy(rqe->sdu.data, sdu->data, sdu->size);
     213        rqe->sdu.size = sdu->size;
     214       
     215        /*
     216         * Insert to receive queue
     217         */
     218        prodcons_produce(&loopip_rcv_queue, &rqe->link);
     219       
     220        return EOK;
     221}
     222
    200223static int loopip_get_mtu(iplink_srv_t *srv, size_t *mtu)
    201224{
     
    203226        *mtu = 1500;
    204227        return EOK;
     228}
     229
     230static int loopip_get_mac48(iplink_srv_t *src, addr48_t *mac)
     231{
     232        log_msg(LOG_DEFAULT, LVL_DEBUG, "loopip_get_mac48()");
     233        return ENOTSUP;
    205234}
    206235
  • uspace/srv/net/slip/slip.c

    rb08879c2 rbdae198  
    5858static int slip_close(iplink_srv_t *);
    5959static int slip_send(iplink_srv_t *, iplink_sdu_t *);
     60static int slip_send6(iplink_srv_t *, iplink_sdu6_t *);
    6061static int slip_get_mtu(iplink_srv_t *, size_t *);
     62static int slip_get_mac48(iplink_srv_t *, addr48_t *);
    6163static int slip_addr_add(iplink_srv_t *, inet_addr_t *);
    6264static int slip_addr_remove(iplink_srv_t *, inet_addr_t *);
     
    6870        .close = slip_close,
    6971        .send = slip_send,
     72        .send6 = slip_send6,
    7073        .get_mtu = slip_get_mtu,
     74        .get_mac48 = slip_get_mac48,
    7175        .addr_add = slip_addr_add,
    7276        .addr_remove = slip_addr_remove
     
    122126int slip_send(iplink_srv_t *srv, iplink_sdu_t *sdu)
    123127{
     128        log_msg(LOG_DEFAULT, LVL_DEBUG, "slip_send()");
     129       
    124130        async_sess_t *sess = (async_sess_t *) srv->arg;
    125131        uint8_t *data = sdu->data;
    126         unsigned i;
    127 
    128         log_msg(LOG_DEFAULT, LVL_DEBUG, "slip_send()");
    129 
     132       
    130133        /*
    131          * Strictly speaking, this is not prescribed by the RFC, but the RFC
    132          * suggests to start with sending a SLIP_END byte as a synchronization
    133          * measure for dealing with previous possible noise on the line.
    134          */
     134         * Strictly speaking, this is not prescribed by the RFC, but the RFC
     135         * suggests to start with sending a SLIP_END byte as a synchronization
     136         * measure for dealing with previous possible noise on the line.
     137         */
    135138        write_buffered(sess, SLIP_END);
    136 
    137         for (i = 0; i < sdu->size; i++) {
     139       
     140        for (size_t i = 0; i < sdu->size; i++) {
    138141                switch (data[i]) {
    139142                case SLIP_END:
     
    150153                }
    151154        }
     155       
    152156        write_buffered(sess, SLIP_END);
    153157        write_flush(sess);
    154 
    155         return EOK;
     158       
     159        return EOK;
     160}
     161
     162int slip_send6(iplink_srv_t *srv, iplink_sdu6_t *sdu)
     163{
     164        log_msg(LOG_DEFAULT, LVL_DEBUG, "slip_send6()");
     165       
     166        return ENOTSUP;
    156167}
    157168
     
    161172        *mtu = SLIP_MTU;
    162173        return EOK;
     174}
     175
     176int slip_get_mac48(iplink_srv_t *src, addr48_t *mac)
     177{
     178        log_msg(LOG_DEFAULT, LVL_DEBUG, "slip_get_mac48()");
     179        return ENOTSUP;
    163180}
    164181
  • uspace/srv/net/tcp/conn.c

    rb08879c2 rbdae198  
    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

    rb08879c2 rbdae198  
    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

    rb08879c2 rbdae198  
    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

    rb08879c2 rbdae198  
    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

    rb08879c2 rbdae198  
    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

    rb08879c2 rbdae198  
    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

    rb08879c2 rbdae198  
    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

    rb08879c2 rbdae198  
    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

    rb08879c2 rbdae198  
    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

    rb08879c2 rbdae198  
    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

    rb08879c2 rbdae198  
    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.