Changeset 984a9ba in mainline for uspace/srv/net/inetsrv/inetsrv.c


Ignore:
Timestamp:
2018-07-05T09:34:09Z (6 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
63d46341
Parents:
76f566d
Message:

do not expose the call capability handler from the async framework

Keep the call capability handler encapsulated within the async framework
and do not expose it explicitly via its API. Use the pointer to
ipc_call_t as the sole object identifying an IPC call in the code that
uses the async framework.

This plugs a major leak in the abstraction and also simplifies both the
async framework (slightly) and all IPC servers.

File:
1 edited

Legend:

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

    r76f566d r984a9ba  
    8282static LIST_INITIALIZE(client_list);
    8383
    84 static void inet_default_conn(cap_call_handle_t, ipc_call_t *, void *);
     84static void inet_default_conn(ipc_call_t *, void *);
    8585
    8686static errno_t inet_init(void)
     
    120120}
    121121
    122 static void inet_callback_create_srv(inet_client_t *client, cap_call_handle_t chandle,
    123     ipc_call_t *call)
     122static void inet_callback_create_srv(inet_client_t *client, ipc_call_t *call)
    124123{
    125124        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_callback_create_srv()");
     
    127126        async_sess_t *sess = async_callback_receive(EXCHANGE_SERIALIZE);
    128127        if (sess == NULL) {
    129                 async_answer_0(chandle, ENOMEM);
     128                async_answer_0(call, ENOMEM);
    130129                return;
    131130        }
    132131
    133132        client->sess = sess;
    134         async_answer_0(chandle, EOK);
     133        async_answer_0(call, EOK);
    135134}
    136135
     
    230229}
    231230
    232 static void inet_get_srcaddr_srv(inet_client_t *client, cap_call_handle_t icall_handle,
    233     ipc_call_t *icall)
     231static void inet_get_srcaddr_srv(inet_client_t *client, ipc_call_t *icall)
    234232{
    235233        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_get_srcaddr_srv()");
     
    237235        uint8_t tos = IPC_GET_ARG1(*icall);
    238236
    239         cap_call_handle_t chandle;
     237        ipc_call_t call;
    240238        size_t size;
    241         if (!async_data_write_receive(&chandle, &size)) {
    242                 async_answer_0(chandle, EREFUSED);
    243                 async_answer_0(icall_handle, EREFUSED);
     239        if (!async_data_write_receive(&call, &size)) {
     240                async_answer_0(&call, EREFUSED);
     241                async_answer_0(icall, EREFUSED);
    244242                return;
    245243        }
    246244
    247245        if (size != sizeof(inet_addr_t)) {
    248                 async_answer_0(chandle, EINVAL);
    249                 async_answer_0(icall_handle, EINVAL);
     246                async_answer_0(&call, EINVAL);
     247                async_answer_0(icall, EINVAL);
    250248                return;
    251249        }
    252250
    253251        inet_addr_t remote;
    254         errno_t rc = async_data_write_finalize(chandle, &remote, size);
    255         if (rc != EOK) {
    256                 async_answer_0(chandle, rc);
    257                 async_answer_0(icall_handle, rc);
     252        errno_t rc = async_data_write_finalize(&call, &remote, size);
     253        if (rc != EOK) {
     254                async_answer_0(&call, rc);
     255                async_answer_0(icall, rc);
    258256        }
    259257
     
    261259        rc = inet_get_srcaddr(&remote, tos, &local);
    262260        if (rc != EOK) {
    263                 async_answer_0(icall_handle, rc);
    264                 return;
    265         }
    266 
    267         if (!async_data_read_receive(&chandle, &size)) {
    268                 async_answer_0(chandle, EREFUSED);
    269                 async_answer_0(icall_handle, EREFUSED);
     261                async_answer_0(icall, rc);
     262                return;
     263        }
     264
     265        if (!async_data_read_receive(&call, &size)) {
     266                async_answer_0(&call, EREFUSED);
     267                async_answer_0(icall, EREFUSED);
    270268                return;
    271269        }
    272270
    273271        if (size != sizeof(inet_addr_t)) {
    274                 async_answer_0(chandle, EINVAL);
    275                 async_answer_0(icall_handle, EINVAL);
    276                 return;
    277         }
    278 
    279         rc = async_data_read_finalize(chandle, &local, size);
    280         if (rc != EOK) {
    281                 async_answer_0(chandle, rc);
    282                 async_answer_0(icall_handle, rc);
    283                 return;
    284         }
    285 
    286         async_answer_0(icall_handle, rc);
    287 }
    288 
    289 static void inet_send_srv(inet_client_t *client, cap_call_handle_t icall_handle,
    290     ipc_call_t *icall)
     272                async_answer_0(&call, EINVAL);
     273                async_answer_0(icall, EINVAL);
     274                return;
     275        }
     276
     277        rc = async_data_read_finalize(&call, &local, size);
     278        if (rc != EOK) {
     279                async_answer_0(&call, rc);
     280                async_answer_0(icall, rc);
     281                return;
     282        }
     283
     284        async_answer_0(icall, rc);
     285}
     286
     287static void inet_send_srv(inet_client_t *client, ipc_call_t *icall)
    291288{
    292289        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_send_srv()");
     
    300297        int df = IPC_GET_ARG4(*icall);
    301298
    302         cap_call_handle_t chandle;
     299        ipc_call_t call;
    303300        size_t size;
    304         if (!async_data_write_receive(&chandle, &size)) {
    305                 async_answer_0(chandle, EREFUSED);
    306                 async_answer_0(icall_handle, EREFUSED);
     301        if (!async_data_write_receive(&call, &size)) {
     302                async_answer_0(&call, EREFUSED);
     303                async_answer_0(icall, EREFUSED);
    307304                return;
    308305        }
    309306
    310307        if (size != sizeof(inet_addr_t)) {
    311                 async_answer_0(chandle, EINVAL);
    312                 async_answer_0(icall_handle, EINVAL);
    313                 return;
    314         }
    315 
    316         errno_t rc = async_data_write_finalize(chandle, &dgram.src, size);
    317         if (rc != EOK) {
    318                 async_answer_0(chandle, rc);
    319                 async_answer_0(icall_handle, rc);
    320         }
    321 
    322         if (!async_data_write_receive(&chandle, &size)) {
    323                 async_answer_0(chandle, EREFUSED);
    324                 async_answer_0(icall_handle, EREFUSED);
     308                async_answer_0(&call, EINVAL);
     309                async_answer_0(icall, EINVAL);
     310                return;
     311        }
     312
     313        errno_t rc = async_data_write_finalize(&call, &dgram.src, size);
     314        if (rc != EOK) {
     315                async_answer_0(&call, rc);
     316                async_answer_0(icall, rc);
     317        }
     318
     319        if (!async_data_write_receive(&call, &size)) {
     320                async_answer_0(&call, EREFUSED);
     321                async_answer_0(icall, EREFUSED);
    325322                return;
    326323        }
    327324
    328325        if (size != sizeof(inet_addr_t)) {
    329                 async_answer_0(chandle, EINVAL);
    330                 async_answer_0(icall_handle, EINVAL);
    331                 return;
    332         }
    333 
    334         rc = async_data_write_finalize(chandle, &dgram.dest, size);
    335         if (rc != EOK) {
    336                 async_answer_0(chandle, rc);
    337                 async_answer_0(icall_handle, rc);
     326                async_answer_0(&call, EINVAL);
     327                async_answer_0(icall, EINVAL);
     328                return;
     329        }
     330
     331        rc = async_data_write_finalize(&call, &dgram.dest, size);
     332        if (rc != EOK) {
     333                async_answer_0(&call, rc);
     334                async_answer_0(icall, rc);
    338335        }
    339336
     
    341338            &dgram.size);
    342339        if (rc != EOK) {
    343                 async_answer_0(icall_handle, rc);
     340                async_answer_0(icall, rc);
    344341                return;
    345342        }
     
    348345
    349346        free(dgram.data);
    350         async_answer_0(icall_handle, rc);
    351 }
    352 
    353 static void inet_set_proto_srv(inet_client_t *client, cap_call_handle_t chandle,
    354     ipc_call_t *call)
     347        async_answer_0(icall, rc);
     348}
     349
     350static void inet_set_proto_srv(inet_client_t *client, ipc_call_t *call)
    355351{
    356352        sysarg_t proto;
     
    360356
    361357        if (proto > UINT8_MAX) {
    362                 async_answer_0(chandle, EINVAL);
     358                async_answer_0(call, EINVAL);
    363359                return;
    364360        }
    365361
    366362        client->protocol = proto;
    367         async_answer_0(chandle, EOK);
     363        async_answer_0(call, EOK);
    368364}
    369365
     
    387383}
    388384
    389 static void inet_default_conn(cap_call_handle_t icall_handle, ipc_call_t *icall, void *arg)
     385static void inet_default_conn(ipc_call_t *icall, void *arg)
    390386{
    391387        inet_client_t client;
     
    394390
    395391        /* Accept the connection */
    396         async_answer_0(icall_handle, EOK);
     392        async_answer_0(icall, EOK);
    397393
    398394        inet_client_init(&client);
     
    400396        while (true) {
    401397                ipc_call_t call;
    402                 cap_call_handle_t chandle = async_get_call(&call);
     398                async_get_call(&call);
    403399                sysarg_t method = IPC_GET_IMETHOD(call);
    404400
    405401                if (!method) {
    406402                        /* The other side has hung up */
    407                         async_answer_0(chandle, EOK);
     403                        async_answer_0(&call, EOK);
    408404                        return;
    409405                }
     
    411407                switch (method) {
    412408                case INET_CALLBACK_CREATE:
    413                         inet_callback_create_srv(&client, chandle, &call);
     409                        inet_callback_create_srv(&client, &call);
    414410                        break;
    415411                case INET_GET_SRCADDR:
    416                         inet_get_srcaddr_srv(&client, chandle, &call);
     412                        inet_get_srcaddr_srv(&client, &call);
    417413                        break;
    418414                case INET_SEND:
    419                         inet_send_srv(&client, chandle, &call);
     415                        inet_send_srv(&client, &call);
    420416                        break;
    421417                case INET_SET_PROTO:
    422                         inet_set_proto_srv(&client, chandle, &call);
     418                        inet_set_proto_srv(&client, &call);
    423419                        break;
    424420                default:
    425                         async_answer_0(chandle, EINVAL);
     421                        async_answer_0(&call, EINVAL);
    426422                }
    427423        }
Note: See TracChangeset for help on using the changeset viewer.