Changeset a35b458 in mainline for uspace/srv/net/inetsrv


Ignore:
Timestamp:
2018-03-02T20:10:49Z (8 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f1380b7
Parents:
3061bc1
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
Message:

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

Location:
uspace/srv/net/inetsrv
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/inetsrv/addrobj.c

    r3061bc1 ra35b458  
    113113{
    114114        fibril_mutex_lock(&addr_list_lock);
    115        
     115
    116116        list_foreach(addr_list, addr_list, inet_addrobj_t, naddr) {
    117117                switch (find) {
     
    134134                }
    135135        }
    136        
     136
    137137        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_addrobj_find: Not found");
    138138        fibril_mutex_unlock(&addr_list_lock);
    139        
     139
    140140        return NULL;
    141141}
  • uspace/srv/net/inetsrv/icmpv6.c

    r3061bc1 ra35b458  
    5050{
    5151        log_msg(LOG_DEFAULT, LVL_DEBUG, "icmpv6_recv_echo_request()");
    52        
     52
    5353        if (dgram->size < sizeof(icmpv6_message_t))
    5454                return EINVAL;
    55        
     55
    5656        icmpv6_message_t *request = (icmpv6_message_t *) dgram->data;
    5757        size_t size = dgram->size;
    58        
     58
    5959        addr128_t src_v6;
    6060        ip_ver_t src_ver = inet_addr_get(&dgram->src, NULL, &src_v6);
    61        
     61
    6262        addr128_t dest_v6;
    6363        ip_ver_t dest_ver = inet_addr_get(&dgram->dest, NULL, &dest_v6);
    64        
     64
    6565        if ((src_ver != dest_ver) || (src_ver != ip_v6))
    6666                return EINVAL;
    67        
     67
    6868        icmpv6_message_t *reply = calloc(1, size);
    6969        if (reply == NULL)
    7070                return ENOMEM;
    71        
     71
    7272        memcpy(reply, request, size);
    73        
     73
    7474        reply->type = ICMPV6_ECHO_REPLY;
    7575        reply->code = 0;
    7676        reply->checksum = 0;
    77        
     77
    7878        inet_dgram_t rdgram;
    79        
     79
    8080        inet_get_srcaddr(&dgram->src, 0, &rdgram.src);
    8181        rdgram.dest = dgram->src;
     
    8484        rdgram.data = reply;
    8585        rdgram.size = size;
    86        
     86
    8787        icmpv6_phdr_t phdr;
    88        
     88
    8989        host2addr128_t_be(dest_v6, phdr.src_addr);
    9090        host2addr128_t_be(src_v6, phdr.dest_addr);
     
    9292        memset(phdr.zeroes, 0, 3);
    9393        phdr.next = IP_PROTO_ICMPV6;
    94        
     94
    9595        uint16_t cs_phdr =
    9696            inet_checksum_calc(INET_CHECKSUM_INIT, &phdr,
    9797            sizeof(icmpv6_phdr_t));
    98        
     98
    9999        uint16_t cs_all = inet_checksum_calc(cs_phdr, reply, size);
    100        
     100
    101101        reply->checksum = host2uint16_t_be(cs_all);
    102        
     102
    103103        errno_t rc = inet_route_packet(&rdgram, IP_PROTO_ICMPV6,
    104104            INET6_HOP_LIMIT_MAX, 0);
    105        
     105
    106106        free(reply);
    107        
     107
    108108        return rc;
    109109}
     
    112112{
    113113        log_msg(LOG_DEFAULT, LVL_DEBUG, "icmpv6_recv_echo_reply()");
    114        
     114
    115115        if (dgram->size < sizeof(icmpv6_message_t))
    116116                return EINVAL;
    117        
     117
    118118        inetping_sdu_t sdu;
    119        
     119
    120120        sdu.src = dgram->src;
    121121        sdu.dest = dgram->dest;
    122        
     122
    123123        icmpv6_message_t *reply = (icmpv6_message_t *) dgram->data;
    124        
     124
    125125        sdu.seq_no = uint16_t_be2host(reply->un.echo.seq_no);
    126126        sdu.data = reply + sizeof(icmpv6_message_t);
    127127        sdu.size = dgram->size - sizeof(icmpv6_message_t);
    128        
     128
    129129        uint16_t ident = uint16_t_be2host(reply->un.echo.ident);
    130        
     130
    131131        return inetping_recv(ident, &sdu);
    132132}
     
    135135{
    136136        log_msg(LOG_DEFAULT, LVL_DEBUG, "icmpv6_recv()");
    137        
     137
    138138        if (dgram->size < 1)
    139139                return EINVAL;
    140        
     140
    141141        uint8_t type = *(uint8_t *) dgram->data;
    142        
     142
    143143        switch (type) {
    144144        case ICMPV6_ECHO_REQUEST:
     
    153153                break;
    154154        }
    155        
     155
    156156        return EINVAL;
    157157}
     
    163163        if (rdata == NULL)
    164164                return ENOMEM;
    165        
     165
    166166        icmpv6_message_t *request = (icmpv6_message_t *) rdata;
    167        
     167
    168168        request->type = ICMPV6_ECHO_REQUEST;
    169169        request->code = 0;
     
    171171        request->un.echo.ident = host2uint16_t_be(ident);
    172172        request->un.echo.seq_no = host2uint16_t_be(sdu->seq_no);
    173        
     173
    174174        memcpy(rdata + sizeof(icmpv6_message_t), sdu->data, sdu->size);
    175        
     175
    176176        inet_dgram_t dgram;
    177        
     177
    178178        dgram.src = sdu->src;
    179179        dgram.dest = sdu->dest;
     
    182182        dgram.data = rdata;
    183183        dgram.size = rsize;
    184        
     184
    185185        icmpv6_phdr_t phdr;
    186        
     186
    187187        assert(sdu->src.version == ip_v6);
    188188        assert(sdu->dest.version == ip_v6);
    189        
     189
    190190        host2addr128_t_be(sdu->src.addr6, phdr.src_addr);
    191191        host2addr128_t_be(sdu->dest.addr6, phdr.dest_addr);
     
    193193        memset(phdr.zeroes, 0, 3);
    194194        phdr.next = IP_PROTO_ICMPV6;
    195        
     195
    196196        uint16_t cs_phdr =
    197197            inet_checksum_calc(INET_CHECKSUM_INIT, &phdr,
    198198            sizeof(icmpv6_phdr_t));
    199        
     199
    200200        uint16_t cs_all = inet_checksum_calc(cs_phdr, rdata, rsize);
    201        
     201
    202202        request->checksum = host2uint16_t_be(cs_all);
    203        
     203
    204204        errno_t rc = inet_route_packet(&dgram, IP_PROTO_ICMPV6,
    205205            INET6_HOP_LIMIT_MAX, 0);
    206        
     206
    207207        free(rdata);
    208        
     208
    209209        return rc;
    210210}
  • uspace/srv/net/inetsrv/inet_link.c

    r3061bc1 ra35b458  
    154154        if (ilink->svc_name != NULL)
    155155                free(ilink->svc_name);
    156        
     156
    157157        free(ilink);
    158158}
     
    197197                goto error;
    198198        }
    199        
     199
    200200        /*
    201201         * Get the MAC address of the link. If the link has a MAC
     
    221221
    222222        inet_addrobj_t *addr = NULL;
    223        
     223
    224224        /* XXX FIXME Cannot rely on loopback being the first IP link service!! */
    225225        if (first_link) {
    226226                addr = inet_addrobj_new();
    227                
     227
    228228                inet_naddr(&addr->naddr, 127, 0, 0, 1, 24);
    229229                first_link = false;
    230230        }
    231        
     231
    232232        if (addr != NULL) {
    233233                addr->ilink = ilink;
    234234                addr->name = str_dup("v4a");
    235                
     235
    236236                rc = inet_addrobj_add(addr);
    237237                if (rc == EOK) {
     
    249249                }
    250250        }
    251        
     251
    252252        inet_addrobj_t *addr6 = NULL;
    253        
     253
    254254        if (first_link6) {
    255255                addr6 = inet_addrobj_new();
    256                
     256
    257257                inet_naddr6(&addr6->naddr, 0, 0, 0, 0, 0, 0, 0, 1, 128);
    258258                first_link6 = false;
    259259        } else if (ilink->mac_valid) {
    260260                addr6 = inet_addrobj_new();
    261                
     261
    262262                addr128_t link_local;
    263263                inet_link_local_node_ip(ilink->mac, link_local);
    264                
     264
    265265                inet_naddr_set6(link_local, 64, &addr6->naddr);
    266266        }
    267        
     267
    268268        if (addr6 != NULL) {
    269269                addr6->ilink = ilink;
    270270                addr6->name = str_dup("v6a");
    271                
     271
    272272                rc = inet_addrobj_add(addr6);
    273273                if (rc == EOK) {
     
    285285                }
    286286        }
    287        
     287
    288288        log_msg(LOG_DEFAULT, LVL_DEBUG, "Configured link '%s'.", ilink->svc_name);
    289289        return EOK;
    290        
     290
    291291error:
    292292        if (ilink->iplink != NULL)
    293293                iplink_close(ilink->iplink);
    294        
     294
    295295        inet_link_delete(ilink);
    296296        return rc;
     
    319319        if (src_ver != ip_v4)
    320320                return EINVAL;
    321        
     321
    322322        addr32_t dest_v4;
    323323        ip_ver_t dest_ver = inet_addr_get(&dgram->dest, &dest_v4, NULL);
    324324        if (dest_ver != ip_v4)
    325325                return EINVAL;
    326        
     326
    327327        /*
    328328         * Fill packet structure. Fragmentation is performed by
    329329         * inet_pdu_encode().
    330330         */
    331        
     331
    332332        iplink_sdu_t sdu;
    333        
     333
    334334        sdu.src = lsrc;
    335335        sdu.dest = ldest;
    336        
     336
    337337        inet_packet_t packet;
    338        
     338
    339339        packet.src = dgram->src;
    340340        packet.dest = dgram->dest;
     
    342342        packet.proto = proto;
    343343        packet.ttl = ttl;
    344        
     344
    345345        /* Allocate identifier */
    346346        fibril_mutex_lock(&ip_ident_lock);
    347347        packet.ident = ++ip_ident;
    348348        fibril_mutex_unlock(&ip_ident_lock);
    349        
     349
    350350        packet.df = df;
    351351        packet.data = dgram->data;
    352352        packet.size = dgram->size;
    353        
     353
    354354        errno_t rc;
    355355        size_t offs = 0;
    356        
     356
    357357        do {
    358358                /* Encode one fragment */
    359                
     359
    360360                size_t roffs;
    361361                rc = inet_pdu_encode(&packet, src_v4, dest_v4, offs, ilink->def_mtu,
     
    363363                if (rc != EOK)
    364364                        return rc;
    365                
     365
    366366                /* Send the PDU */
    367367                rc = iplink_send(ilink->iplink, &sdu);
    368                
     368
    369369                free(sdu.data);
    370370                offs = roffs;
    371371        } while (offs < packet.size);
    372        
     372
    373373        return rc;
    374374}
     
    394394        if (src_ver != ip_v6)
    395395                return EINVAL;
    396        
     396
    397397        addr128_t dest_v6;
    398398        ip_ver_t dest_ver = inet_addr_get(&dgram->dest, NULL, &dest_v6);
    399399        if (dest_ver != ip_v6)
    400400                return EINVAL;
    401        
     401
    402402        iplink_sdu6_t sdu6;
    403403        addr48(ldest, sdu6.dest);
    404        
     404
    405405        /*
    406406         * Fill packet structure. Fragmentation is performed by
    407407         * inet_pdu_encode6().
    408408         */
    409        
     409
    410410        inet_packet_t packet;
    411        
     411
    412412        packet.src = dgram->src;
    413413        packet.dest = dgram->dest;
     
    415415        packet.proto = proto;
    416416        packet.ttl = ttl;
    417        
     417
    418418        /* Allocate identifier */
    419419        fibril_mutex_lock(&ip_ident_lock);
    420420        packet.ident = ++ip_ident;
    421421        fibril_mutex_unlock(&ip_ident_lock);
    422        
     422
    423423        packet.df = df;
    424424        packet.data = dgram->data;
    425425        packet.size = dgram->size;
    426        
     426
    427427        errno_t rc;
    428428        size_t offs = 0;
    429        
     429
    430430        do {
    431431                /* Encode one fragment */
    432                
     432
    433433                size_t roffs;
    434434                rc = inet_pdu_encode6(&packet, src_v6, dest_v6, offs, ilink->def_mtu,
     
    436436                if (rc != EOK)
    437437                        return rc;
    438                
     438
    439439                /* Send the PDU */
    440440                rc = iplink_send6(ilink->iplink, &sdu6);
    441                
     441
    442442                free(sdu6.data);
    443443                offs = roffs;
    444444        } while (offs < packet.size);
    445        
     445
    446446        return rc;
    447447}
  • uspace/srv/net/inetsrv/inetcfg.c

    r3061bc1 ra35b458  
    257257{
    258258        log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_addr_create_static_srv()");
    259        
     259
    260260        sysarg_t link_id = IPC_GET_ARG1(*icall);
    261        
     261
    262262        ipc_callid_t callid;
    263263        size_t size;
     
    267267                return;
    268268        }
    269        
     269
    270270        if (size != sizeof(inet_naddr_t)) {
    271271                async_answer_0(callid, EINVAL);
     
    273273                return;
    274274        }
    275        
     275
    276276        inet_naddr_t naddr;
    277277        errno_t rc = async_data_write_finalize(callid, &naddr, size);
     
    281281                return;
    282282        }
    283        
     283
    284284        char *name;
    285285        rc = async_data_write_accept((void **) &name, true, 0, LOC_NAME_MAXLEN,
     
    289289                return;
    290290        }
    291        
     291
    292292        sysarg_t addr_id = 0;
    293293        rc = inetcfg_addr_create_static(name, &naddr, link_id, &addr_id);
     
    312312{
    313313        log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_addr_get_srv()");
    314        
     314
    315315        sysarg_t addr_id = IPC_GET_ARG1(*icall);
    316        
     316
    317317        inet_addr_info_t ainfo;
    318        
     318
    319319        inet_naddr_any(&ainfo.naddr);
    320320        ainfo.ilink = 0;
    321321        ainfo.name = NULL;
    322        
     322
    323323        errno_t rc = inetcfg_addr_get(addr_id, &ainfo);
    324324        if (rc != EOK) {
     
    326326                return;
    327327        }
    328        
     328
    329329        ipc_callid_t callid;
    330330        size_t size;
     
    334334                return;
    335335        }
    336        
     336
    337337        if (size != sizeof(inet_naddr_t)) {
    338338                async_answer_0(callid, EINVAL);
     
    340340                return;
    341341        }
    342        
     342
    343343        rc = async_data_read_finalize(callid, &ainfo.naddr, size);
    344344        if (rc != EOK) {
     
    347347                return;
    348348        }
    349        
     349
    350350        if (!async_data_read_receive(&callid, &size)) {
    351351                async_answer_0(callid, EREFUSED);
     
    353353                return;
    354354        }
    355        
     355
    356356        rc = async_data_read_finalize(callid, ainfo.name,
    357357            min(size, str_size(ainfo.name)));
    358358        free(ainfo.name);
    359        
    360         if (rc != EOK) {
    361                 async_answer_0(callid, rc);
    362                 async_answer_0(iid, rc);
    363                 return;
    364         }
    365        
     359
     360        if (rc != EOK) {
     361                async_answer_0(callid, rc);
     362                async_answer_0(iid, rc);
     363                return;
     364        }
     365
    366366        async_answer_1(iid, rc, ainfo.ilink);
    367367}
     
    584584                return;
    585585        }
    586        
     586
    587587        if (size != sizeof(inet_naddr_t)) {
    588588                async_answer_0(callid, EINVAL);
     
    590590                return;
    591591        }
    592        
     592
    593593        inet_naddr_t dest;
    594594        errno_t rc = async_data_write_finalize(callid, &dest, size);
     
    598598                return;
    599599        }
    600        
     600
    601601        if (!async_data_write_receive(&callid, &size)) {
    602602                async_answer_0(callid, EINVAL);
     
    604604                return;
    605605        }
    606        
     606
    607607        if (size != sizeof(inet_addr_t)) {
    608608                async_answer_0(callid, EINVAL);
     
    610610                return;
    611611        }
    612        
     612
    613613        inet_addr_t router;
    614614        rc = async_data_write_finalize(callid, &router, size);
     
    618618                return;
    619619        }
    620        
     620
    621621        char *name;
    622622        rc = async_data_write_accept((void **) &name, true, 0, LOC_NAME_MAXLEN,
     
    626626                return;
    627627        }
    628        
     628
    629629        sysarg_t sroute_id = 0;
    630630        rc = inetcfg_sroute_create(name, &dest, &router, &sroute_id);
     
    649649{
    650650        log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_sroute_get_srv()");
    651        
     651
    652652        sysarg_t sroute_id = IPC_GET_ARG1(*icall);
    653        
     653
    654654        inet_sroute_info_t srinfo;
    655        
     655
    656656        inet_naddr_any(&srinfo.dest);
    657657        inet_addr_any(&srinfo.router);
    658658        srinfo.name = NULL;
    659        
     659
    660660        errno_t rc = inetcfg_sroute_get(sroute_id, &srinfo);
    661661        if (rc != EOK) {
     
    663663                return;
    664664        }
    665        
     665
    666666        ipc_callid_t callid;
    667667        size_t size;
     
    671671                return;
    672672        }
    673        
     673
    674674        if (size != sizeof(inet_naddr_t)) {
    675675                async_answer_0(callid, EINVAL);
     
    677677                return;
    678678        }
    679        
     679
    680680        rc = async_data_read_finalize(callid, &srinfo.dest, size);
    681681        if (rc != EOK) {
     
    684684                return;
    685685        }
    686        
     686
    687687        if (!async_data_read_receive(&callid, &size)) {
    688688                async_answer_0(callid, EREFUSED);
     
    690690                return;
    691691        }
    692        
     692
    693693        if (size != sizeof(inet_addr_t)) {
    694694                async_answer_0(callid, EINVAL);
     
    696696                return;
    697697        }
    698        
     698
    699699        rc = async_data_read_finalize(callid, &srinfo.router, size);
    700700        if (rc != EOK) {
     
    703703                return;
    704704        }
    705        
     705
    706706        if (!async_data_read_receive(&callid, &size)) {
    707707                async_answer_0(callid, EREFUSED);
     
    709709                return;
    710710        }
    711        
     711
    712712        rc = async_data_read_finalize(callid, srinfo.name,
    713713            min(size, str_size(srinfo.name)));
    714714        free(srinfo.name);
    715        
     715
    716716        async_answer_0(iid, rc);
    717717}
  • uspace/srv/net/inetsrv/inetsrv.c

    r3061bc1 ra35b458  
    8787{
    8888        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_init()");
    89        
     89
    9090        port_id_t port;
    9191        errno_t rc = async_create_port(INTERFACE_INET,
     
    9393        if (rc != EOK)
    9494                return rc;
    95        
     95
    9696        rc = async_create_port(INTERFACE_INETCFG,
    9797            inet_cfg_conn, NULL, &port);
    9898        if (rc != EOK)
    9999                return rc;
    100        
     100
    101101        rc = async_create_port(INTERFACE_INETPING,
    102102            inetping_conn, NULL, &port);
    103103        if (rc != EOK)
    104104                return rc;
    105        
     105
    106106        rc = loc_server_register(NAME);
    107107        if (rc != EOK) {
     
    109109                return EEXIST;
    110110        }
    111        
     111
    112112        service_id_t sid;
    113113        rc = loc_service_register(SERVICE_NAME_INET, &sid);
     
    116116                return EEXIST;
    117117        }
    118        
     118
    119119        return EOK;
    120120}
     
    234234{
    235235        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_get_srcaddr_srv()");
    236        
     236
    237237        uint8_t tos = IPC_GET_ARG1(*icall);
    238        
     238
    239239        ipc_callid_t callid;
    240240        size_t size;
     
    244244                return;
    245245        }
    246        
     246
    247247        if (size != sizeof(inet_addr_t)) {
    248248                async_answer_0(callid, EINVAL);
     
    250250                return;
    251251        }
    252        
     252
    253253        inet_addr_t remote;
    254254        errno_t rc = async_data_write_finalize(callid, &remote, size);
     
    257257                async_answer_0(iid, rc);
    258258        }
    259        
     259
    260260        inet_addr_t local;
    261261        rc = inet_get_srcaddr(&remote, tos, &local);
     
    264264                return;
    265265        }
    266        
     266
    267267        if (!async_data_read_receive(&callid, &size)) {
    268268                async_answer_0(callid, EREFUSED);
     
    270270                return;
    271271        }
    272        
     272
    273273        if (size != sizeof(inet_addr_t)) {
    274274                async_answer_0(callid, EINVAL);
     
    276276                return;
    277277        }
    278        
     278
    279279        rc = async_data_read_finalize(callid, &local, size);
    280280        if (rc != EOK) {
     
    283283                return;
    284284        }
    285        
     285
    286286        async_answer_0(iid, rc);
    287287}
     
    291291{
    292292        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_send_srv()");
    293        
     293
    294294        inet_dgram_t dgram;
    295        
     295
    296296        dgram.iplink = IPC_GET_ARG1(*icall);
    297297        dgram.tos = IPC_GET_ARG2(*icall);
    298        
     298
    299299        uint8_t ttl = IPC_GET_ARG3(*icall);
    300300        int df = IPC_GET_ARG4(*icall);
    301        
     301
    302302        ipc_callid_t callid;
    303303        size_t size;
     
    307307                return;
    308308        }
    309        
     309
    310310        if (size != sizeof(inet_addr_t)) {
    311311                async_answer_0(callid, EINVAL);
     
    313313                return;
    314314        }
    315        
     315
    316316        errno_t rc = async_data_write_finalize(callid, &dgram.src, size);
    317317        if (rc != EOK) {
     
    319319                async_answer_0(iid, rc);
    320320        }
    321        
     321
    322322        if (!async_data_write_receive(&callid, &size)) {
    323323                async_answer_0(callid, EREFUSED);
     
    325325                return;
    326326        }
    327        
     327
    328328        if (size != sizeof(inet_addr_t)) {
    329329                async_answer_0(callid, EINVAL);
     
    331331                return;
    332332        }
    333        
     333
    334334        rc = async_data_write_finalize(callid, &dgram.dest, size);
    335335        if (rc != EOK) {
     
    337337                async_answer_0(iid, rc);
    338338        }
    339        
     339
    340340        rc = async_data_write_accept(&dgram.data, false, 0, 0, 0,
    341341            &dgram.size);
     
    344344                return;
    345345        }
    346        
     346
    347347        rc = inet_send(client, &dgram, client->protocol, ttl, df);
    348        
     348
    349349        free(dgram.data);
    350350        async_answer_0(iid, rc);
  • uspace/srv/net/inetsrv/ndp.c

    r3061bc1 ra35b458  
    6868        inet_dgram_t dgram;
    6969        ndp_pdu_encode(packet, &dgram);
    70        
     70
    7171        inet_link_send_dgram6(link, packet->target_hw_addr, &dgram,
    7272            IP_PROTO_ICMPV6, INET6_HOP_LIMIT_MAX, 0);
    73        
     73
    7474        free(dgram.data);
    75        
     75
    7676        return EOK;
    7777}
     
    8686{
    8787        log_msg(LOG_DEFAULT, LVL_DEBUG, "ndp_received()");
    88        
     88
    8989        ndp_packet_t packet;
    9090        errno_t rc = ndp_pdu_decode(dgram, &packet);
    9191        if (rc != EOK)
    9292                return rc;
    93        
     93
    9494        inet_addr_t sender;
    9595        inet_addr_set6(packet.sender_proto_addr, &sender);
    96        
     96
    9797        inet_addr_t target;
    9898        inet_addr_set6(packet.target_proto_addr, &target);
    99        
     99
    100100        inet_addrobj_t *laddr;
    101        
     101
    102102        log_msg(LOG_DEFAULT, LVL_DEBUG, "NDP PDU decoded; opcode: %d",
    103103            packet.opcode);
    104        
     104
    105105        switch (packet.opcode) {
    106106        case ICMPV6_NEIGHBOUR_SOLICITATION:
     
    111111                        if (rc != EOK)
    112112                                return rc;
    113                        
     113
    114114                        ndp_packet_t reply;
    115                        
     115
    116116                        reply.opcode = ICMPV6_NEIGHBOUR_ADVERTISEMENT;
    117117                        addr48(laddr->ilink->mac, reply.sender_hw_addr);
     
    119119                        addr48(packet.sender_hw_addr, reply.target_hw_addr);
    120120                        addr128(packet.sender_proto_addr, reply.target_proto_addr);
    121                        
     121
    122122                        ndp_send_packet(laddr->ilink, &reply);
    123123                }
    124                
     124
    125125                break;
    126126        case ICMPV6_NEIGHBOUR_ADVERTISEMENT:
     
    129129                        return ntrans_add(packet.sender_proto_addr,
    130130                            packet.sender_hw_addr);
    131                
     131
    132132                break;
    133133        case ICMPV6_ROUTER_ADVERTISEMENT:
     
    136136                return ENOTSUP;
    137137        }
    138        
     138
    139139        return EOK;
    140140}
     
    159159                return EOK;
    160160        }
    161        
     161
    162162        errno_t rc = ntrans_lookup(ip_addr, mac_addr);
    163163        if (rc == EOK)
    164164                return EOK;
    165        
     165
    166166        ndp_packet_t packet;
    167        
     167
    168168        packet.opcode = ICMPV6_NEIGHBOUR_SOLICITATION;
    169169        addr48(ilink->mac, packet.sender_hw_addr);
     
    172172        addr48_solicited_node(ip_addr, packet.target_hw_addr);
    173173        ndp_solicited_node_ip(ip_addr, packet.target_proto_addr);
    174        
     174
    175175        rc = ndp_send_packet(ilink, &packet);
    176176        if (rc != EOK)
    177177                return rc;
    178        
     178
    179179        (void) ntrans_wait_timeout(NDP_REQUEST_TIMEOUT);
    180        
     180
    181181        return ntrans_lookup(ip_addr, mac_addr);
    182182}
  • uspace/srv/net/inetsrv/ntrans.c

    r3061bc1 ra35b458  
    142142                return ENOENT;
    143143        }
    144        
     144
    145145        fibril_mutex_unlock(&ntrans_list_lock);
    146146        addr48(ntrans->mac_addr, mac_addr);
     
    162162            timeout);
    163163        fibril_mutex_unlock(&ntrans_list_lock);
    164        
     164
    165165        return rc;
    166166}
  • uspace/srv/net/inetsrv/pdu.c

    r3061bc1 ra35b458  
    107107        /* Upper bound for fragment offset field */
    108108        size_t fragoff_limit = 1 << (FF_FRAGOFF_h - FF_FRAGOFF_l + 1);
    109        
     109
    110110        /* Verify that total size of datagram is within reasonable bounds */
    111111        if (packet->size > FRAG_OFFS_UNIT * fragoff_limit)
    112112                return ELIMIT;
    113        
     113
    114114        size_t hdr_size = sizeof(ip_header_t);
    115115        if (hdr_size >= mtu)
    116116                return EINVAL;
    117        
     117
    118118        assert(hdr_size % 4 == 0);
    119119        assert(offs % FRAG_OFFS_UNIT == 0);
    120120        assert(offs / FRAG_OFFS_UNIT < fragoff_limit);
    121        
     121
    122122        /* Value for the fragment offset field */
    123123        uint16_t foff = offs / FRAG_OFFS_UNIT;
    124        
     124
    125125        /* Amount of space in the PDU available for payload */
    126126        size_t spc_avail = mtu - hdr_size;
    127127        spc_avail -= (spc_avail % FRAG_OFFS_UNIT);
    128        
     128
    129129        /* Amount of data (payload) to transfer */
    130130        size_t xfer_size = min(packet->size - offs, spc_avail);
    131        
     131
    132132        /* Total PDU size */
    133133        size_t size = hdr_size + xfer_size;
    134        
     134
    135135        /* Offset of remaining payload */
    136136        size_t rem_offs = offs + xfer_size;
    137        
     137
    138138        /* Flags */
    139139        uint16_t flags_foff =
     
    141141            (rem_offs < packet->size ? BIT_V(uint16_t, FF_FLAG_MF) : 0) +
    142142            (foff << FF_FRAGOFF_l);
    143        
     143
    144144        void *data = calloc(size, 1);
    145145        if (data == NULL)
    146146                return ENOMEM;
    147        
     147
    148148        /* Encode header fields */
    149149        ip_header_t *hdr = (ip_header_t *) data;
    150        
     150
    151151        hdr->ver_ihl =
    152152            (4 << VI_VERSION_l) | (hdr_size / sizeof(uint32_t));
     
    160160        hdr->src_addr = host2uint32_t_be(src);
    161161        hdr->dest_addr = host2uint32_t_be(dest);
    162        
     162
    163163        /* Compute checksum */
    164164        uint16_t chksum = inet_checksum_calc(INET_CHECKSUM_INIT,
    165165            (void *) hdr, hdr_size);
    166166        hdr->chksum = host2uint16_t_be(chksum);
    167        
     167
    168168        /* Copy payload */
    169169        memcpy((uint8_t *) data + hdr_size, packet->data + offs, xfer_size);
    170        
     170
    171171        *rdata = data;
    172172        *rsize = size;
    173173        *roffs = rem_offs;
    174        
     174
    175175        return EOK;
    176176}
     
    200200        if (mtu < 1280)
    201201                return ELIMIT;
    202        
     202
    203203        /* Upper bound for fragment offset field */
    204204        size_t fragoff_limit = 1 << (OF_FRAGOFF_h - OF_FRAGOFF_l);
    205        
     205
    206206        /* Verify that total size of datagram is within reasonable bounds */
    207207        if (offs + packet->size > FRAG_OFFS_UNIT * fragoff_limit)
    208208                return ELIMIT;
    209        
     209
    210210        /* Determine whether we need the Fragment extension header */
    211211        bool fragment;
     
    214214        else
    215215                fragment = true;
    216        
     216
    217217        size_t hdr_size;
    218218        if (fragment)
     
    220220        else
    221221                hdr_size = sizeof(ip6_header_t);
    222        
     222
    223223        if (hdr_size >= mtu)
    224224                return EINVAL;
    225        
     225
    226226        static_assert(sizeof(ip6_header_t) % 8 == 0);
    227227        assert(hdr_size % 8 == 0);
    228228        assert(offs % FRAG_OFFS_UNIT == 0);
    229229        assert(offs / FRAG_OFFS_UNIT < fragoff_limit);
    230        
     230
    231231        /* Value for the fragment offset field */
    232232        uint16_t foff = offs / FRAG_OFFS_UNIT;
    233        
     233
    234234        /* Amount of space in the PDU available for payload */
    235235        size_t spc_avail = mtu - hdr_size;
    236236        spc_avail -= (spc_avail % FRAG_OFFS_UNIT);
    237        
     237
    238238        /* Amount of data (payload) to transfer */
    239239        size_t xfer_size = min(packet->size - offs, spc_avail);
    240        
     240
    241241        /* Total PDU size */
    242242        size_t size = hdr_size + xfer_size;
    243        
     243
    244244        /* Offset of remaining payload */
    245245        size_t rem_offs = offs + xfer_size;
    246        
     246
    247247        /* Flags */
    248248        uint16_t offsmf =
    249249            (rem_offs < packet->size ? BIT_V(uint16_t, OF_FLAG_M) : 0) +
    250250            (foff << OF_FRAGOFF_l);
    251        
     251
    252252        void *data = calloc(size, 1);
    253253        if (data == NULL)
    254254                return ENOMEM;
    255        
     255
    256256        /* Encode header fields */
    257257        ip6_header_t *hdr6 = (ip6_header_t *) data;
    258        
     258
    259259        hdr6->ver_tc = (6 << (VI_VERSION_l));
    260260        memset(hdr6->tc_fl, 0, 3);
    261261        hdr6->hop_limit = packet->ttl;
    262        
     262
    263263        host2addr128_t_be(src, hdr6->src_addr);
    264264        host2addr128_t_be(dest, hdr6->dest_addr);
    265        
     265
    266266        /* Optionally encode Fragment extension header fields */
    267267        if (fragment) {
    268268                assert(offsmf != 0);
    269                
     269
    270270                hdr6->payload_len = host2uint16_t_be(packet->size +
    271271                    sizeof(ip6_header_fragment_t));
    272272                hdr6->next = IP6_NEXT_FRAGMENT;
    273                
     273
    274274                ip6_header_fragment_t *hdr6f = (ip6_header_fragment_t *)
    275275                    (hdr6 + 1);
    276                
     276
    277277                hdr6f->next = packet->proto;
    278278                hdr6f->reserved = 0;
     
    281281        } else {
    282282                assert(offsmf == 0);
    283                
     283
    284284                hdr6->payload_len = host2uint16_t_be(packet->size);
    285285                hdr6->next = packet->proto;
    286286        }
    287        
     287
    288288        /* Copy payload */
    289289        memcpy((uint8_t *) data + hdr_size, packet->data + offs, xfer_size);
    290        
     290
    291291        *rdata = data;
    292292        *rsize = size;
    293293        *roffs = rem_offs;
    294        
     294
    295295        return EOK;
    296296}
     
    312312{
    313313        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_pdu_decode()");
    314        
     314
    315315        if (size < sizeof(ip_header_t)) {
    316316                log_msg(LOG_DEFAULT, LVL_DEBUG, "PDU too short (%zu)", size);
    317317                return EINVAL;
    318318        }
    319        
     319
    320320        ip_header_t *hdr = (ip_header_t *) data;
    321        
     321
    322322        uint8_t version = BIT_RANGE_EXTRACT(uint8_t, VI_VERSION_h,
    323323            VI_VERSION_l, hdr->ver_ihl);
     
    326326                return EINVAL;
    327327        }
    328        
     328
    329329        size_t tot_len = uint16_t_be2host(hdr->tot_len);
    330330        if (tot_len < sizeof(ip_header_t)) {
     
    332332                return EINVAL;
    333333        }
    334        
     334
    335335        if (tot_len > size) {
    336336                log_msg(LOG_DEFAULT, LVL_DEBUG, "Total Length = %zu > PDU size = %zu",
     
    338338                return EINVAL;
    339339        }
    340        
     340
    341341        uint16_t ident = uint16_t_be2host(hdr->id);
    342342        uint16_t flags_foff = uint16_t_be2host(hdr->flags_foff);
     
    344344            flags_foff);
    345345        /* XXX Checksum */
    346        
     346
    347347        inet_addr_set(uint32_t_be2host(hdr->src_addr), &packet->src);
    348348        inet_addr_set(uint32_t_be2host(hdr->dest_addr), &packet->dest);
     
    351351        packet->ttl = hdr->ttl;
    352352        packet->ident = ident;
    353        
     353
    354354        packet->df = (flags_foff & BIT_V(uint16_t, FF_FLAG_DF)) != 0;
    355355        packet->mf = (flags_foff & BIT_V(uint16_t, FF_FLAG_MF)) != 0;
    356356        packet->offs = foff * FRAG_OFFS_UNIT;
    357        
     357
    358358        /* XXX IP options */
    359359        size_t data_offs = sizeof(uint32_t) *
    360360            BIT_RANGE_EXTRACT(uint8_t, VI_IHL_h, VI_IHL_l, hdr->ver_ihl);
    361        
     361
    362362        packet->size = tot_len - data_offs;
    363363        packet->data = calloc(packet->size, 1);
     
    366366                return ENOMEM;
    367367        }
    368        
     368
    369369        memcpy(packet->data, (uint8_t *) data + data_offs, packet->size);
    370370        packet->link_id = link_id;
    371        
     371
    372372        return EOK;
    373373}
     
    389389{
    390390        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_pdu_decode6()");
    391        
     391
    392392        if (size < sizeof(ip6_header_t)) {
    393393                log_msg(LOG_DEFAULT, LVL_DEBUG, "PDU too short (%zu)", size);
    394394                return EINVAL;
    395395        }
    396        
     396
    397397        ip6_header_t *hdr6 = (ip6_header_t *) data;
    398        
     398
    399399        uint8_t version = BIT_RANGE_EXTRACT(uint8_t, VI_VERSION_h,
    400400            VI_VERSION_l, hdr6->ver_tc);
     
    403403                return EINVAL;
    404404        }
    405        
     405
    406406        size_t payload_len = uint16_t_be2host(hdr6->payload_len);
    407407        if (payload_len + sizeof(ip6_header_t) > size) {
     
    410410                return EINVAL;
    411411        }
    412        
     412
    413413        uint32_t ident;
    414414        uint16_t offsmf;
     
    416416        uint16_t next;
    417417        size_t data_offs = sizeof(ip6_header_t);
    418        
     418
    419419        /* Fragment extension header */
    420420        if (hdr6->next == IP6_NEXT_FRAGMENT) {
    421421                ip6_header_fragment_t *hdr6f = (ip6_header_fragment_t *)
    422422                    (hdr6 + 1);
    423                
     423
    424424                ident = uint32_t_be2host(hdr6f->id);
    425425                offsmf = uint16_t_be2host(hdr6f->offsmf);
     
    435435                next = hdr6->next;
    436436        }
    437        
     437
    438438        addr128_t src;
    439439        addr128_t dest;
    440        
     440
    441441        addr128_t_be2host(hdr6->src_addr, src);
    442442        inet_addr_set6(src, &packet->src);
    443        
     443
    444444        addr128_t_be2host(hdr6->dest_addr, dest);
    445445        inet_addr_set6(dest, &packet->dest);
    446        
     446
    447447        packet->tos = 0;
    448448        packet->proto = next;
    449449        packet->ttl = hdr6->hop_limit;
    450450        packet->ident = ident;
    451        
     451
    452452        packet->df = 1;
    453453        packet->mf = (offsmf & BIT_V(uint16_t, OF_FLAG_M)) != 0;
    454454        packet->offs = foff * FRAG_OFFS_UNIT;
    455        
     455
    456456        packet->size = payload_len;
    457457        packet->data = calloc(packet->size, 1);
     
    460460                return ENOMEM;
    461461        }
    462        
     462
    463463        memcpy(packet->data, (uint8_t *) data + data_offs, packet->size);
    464464        packet->link_id = link_id;
     
    480480        dgram->tos = 0;
    481481        dgram->size = sizeof(icmpv6_message_t) + sizeof(ndp_message_t);
    482        
     482
    483483        dgram->data = calloc(1, dgram->size);
    484484        if (dgram->data == NULL)
    485485                return ENOMEM;
    486        
     486
    487487        icmpv6_message_t *icmpv6 = (icmpv6_message_t *) dgram->data;
    488        
     488
    489489        icmpv6->type = ndp->opcode;
    490490        icmpv6->code = 0;
    491491        memset(icmpv6->un.ndp.reserved, 0, 3);
    492        
     492
    493493        ndp_message_t *message = (ndp_message_t *) (icmpv6 + 1);
    494        
     494
    495495        if (ndp->opcode == ICMPV6_NEIGHBOUR_SOLICITATION) {
    496496                host2addr128_t_be(ndp->solicited_ip, message->target_address);
     
    502502                icmpv6->un.ndp.flags = NDP_FLAG_OVERRIDE | NDP_FLAG_SOLICITED;
    503503        }
    504        
     504
    505505        message->length = 1;
    506506        addr48(ndp->sender_hw_addr, message->mac);
    507        
     507
    508508        icmpv6_phdr_t phdr;
    509        
     509
    510510        host2addr128_t_be(ndp->sender_proto_addr, phdr.src_addr);
    511511        host2addr128_t_be(ndp->target_proto_addr, phdr.dest_addr);
     
    513513        memset(phdr.zeroes, 0, 3);
    514514        phdr.next = IP_PROTO_ICMPV6;
    515        
     515
    516516        uint16_t cs_phdr =
    517517            inet_checksum_calc(INET_CHECKSUM_INIT, &phdr,
    518518            sizeof(icmpv6_phdr_t));
    519        
     519
    520520        uint16_t cs_all = inet_checksum_calc(cs_phdr, dgram->data,
    521521            dgram->size);
    522        
     522
    523523        icmpv6->checksum = host2uint16_t_be(cs_all);
    524        
     524
    525525        return EOK;
    526526}
     
    541541        if (src_ver != ip_v6)
    542542                return EINVAL;
    543        
     543
    544544        if (dgram->size < sizeof(icmpv6_message_t) + sizeof(ndp_message_t))
    545545                return EINVAL;
    546        
     546
    547547        icmpv6_message_t *icmpv6 = (icmpv6_message_t *) dgram->data;
    548        
     548
    549549        ndp->opcode = icmpv6->type;
    550        
     550
    551551        ndp_message_t *message = (ndp_message_t *) (icmpv6 + 1);
    552        
     552
    553553        addr128_t_be2host(message->target_address, ndp->target_proto_addr);
    554554        addr48(message->mac, ndp->sender_hw_addr);
    555        
     555
    556556        return EOK;
    557557}
  • uspace/srv/net/inetsrv/sroute.c

    r3061bc1 ra35b458  
    9696{
    9797        ip_ver_t addr_ver = inet_addr_get(addr, NULL, NULL);
    98        
     98
    9999        inet_sroute_t *best = NULL;
    100100        uint8_t best_bits = 0;
    101        
    102         fibril_mutex_lock(&sroute_list_lock);
    103        
     101
     102        fibril_mutex_lock(&sroute_list_lock);
     103
    104104        list_foreach(sroute_list, sroute_list, inet_sroute_t, sroute) {
    105105                uint8_t dest_bits;
    106106                ip_ver_t dest_ver = inet_naddr_get(&sroute->dest, NULL, NULL,
    107107                    &dest_bits);
    108                
     108
    109109                /* Skip comparison with different address family */
    110110                if (addr_ver != dest_ver)
    111111                        continue;
    112                
     112
    113113                /* Look for the most specific route */
    114114                if ((best != NULL) && (best_bits >= dest_bits))
    115115                        continue;
    116                
     116
    117117                if (inet_naddr_compare_mask(&sroute->dest, addr)) {
    118118                        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_sroute_find: found candidate %p",
    119119                            sroute);
    120                        
     120
    121121                        best = sroute;
    122122                        best_bits = dest_bits;
    123123                }
    124124        }
    125        
     125
    126126        if (best == NULL)
    127127                log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_sroute_find: Not found");
    128        
    129         fibril_mutex_unlock(&sroute_list_lock);
    130        
     128
     129        fibril_mutex_unlock(&sroute_list_lock);
     130
    131131        return best;
    132132}
Note: See TracChangeset for help on using the changeset viewer.