Changeset 984a9ba in mainline for uspace/srv/net/inetsrv/inetping.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/inetping.c

    r76f566d r984a9ba  
    136136}
    137137
    138 static void inetping_send_srv(inetping_client_t *client, cap_call_handle_t icall_handle,
    139     ipc_call_t *icall)
     138static void inetping_send_srv(inetping_client_t *client, ipc_call_t *icall)
    140139{
    141140        log_msg(LOG_DEFAULT, LVL_DEBUG, "inetping_send_srv()");
     
    146145        sdu.seq_no = IPC_GET_ARG1(*icall);
    147146
    148         cap_call_handle_t chandle;
     147        ipc_call_t call;
    149148        size_t size;
    150         if (!async_data_write_receive(&chandle, &size)) {
    151                 async_answer_0(chandle, EREFUSED);
    152                 async_answer_0(icall_handle, EREFUSED);
     149        if (!async_data_write_receive(&call, &size)) {
     150                async_answer_0(&call, EREFUSED);
     151                async_answer_0(icall, EREFUSED);
    153152                return;
    154153        }
    155154
    156155        if (size != sizeof(sdu.src)) {
    157                 async_answer_0(chandle, EINVAL);
    158                 async_answer_0(icall_handle, EINVAL);
    159                 return;
    160         }
    161 
    162         rc = async_data_write_finalize(chandle, &sdu.src, size);
    163         if (rc != EOK) {
    164                 async_answer_0(chandle, rc);
    165                 async_answer_0(icall_handle, rc);
    166                 return;
    167         }
    168 
    169         if (!async_data_write_receive(&chandle, &size)) {
    170                 async_answer_0(chandle, EREFUSED);
    171                 async_answer_0(icall_handle, EREFUSED);
     156                async_answer_0(&call, EINVAL);
     157                async_answer_0(icall, EINVAL);
     158                return;
     159        }
     160
     161        rc = async_data_write_finalize(&call, &sdu.src, size);
     162        if (rc != EOK) {
     163                async_answer_0(&call, rc);
     164                async_answer_0(icall, rc);
     165                return;
     166        }
     167
     168        if (!async_data_write_receive(&call, &size)) {
     169                async_answer_0(&call, EREFUSED);
     170                async_answer_0(icall, EREFUSED);
    172171                return;
    173172        }
    174173
    175174        if (size != sizeof(sdu.dest)) {
    176                 async_answer_0(chandle, EINVAL);
    177                 async_answer_0(icall_handle, EINVAL);
    178                 return;
    179         }
    180 
    181         rc = async_data_write_finalize(chandle, &sdu.dest, size);
    182         if (rc != EOK) {
    183                 async_answer_0(chandle, rc);
    184                 async_answer_0(icall_handle, rc);
     175                async_answer_0(&call, EINVAL);
     176                async_answer_0(icall, EINVAL);
     177                return;
     178        }
     179
     180        rc = async_data_write_finalize(&call, &sdu.dest, size);
     181        if (rc != EOK) {
     182                async_answer_0(&call, rc);
     183                async_answer_0(icall, rc);
    185184                return;
    186185        }
     
    189188            &sdu.size);
    190189        if (rc != EOK) {
    191                 async_answer_0(icall_handle, rc);
     190                async_answer_0(icall, rc);
    192191                return;
    193192        }
     
    196195        free(sdu.data);
    197196
    198         async_answer_0(icall_handle, rc);
    199 }
    200 
    201 static void inetping_get_srcaddr_srv(inetping_client_t *client,
    202     cap_call_handle_t icall_handle, ipc_call_t *icall)
     197        async_answer_0(icall, rc);
     198}
     199
     200static void inetping_get_srcaddr_srv(inetping_client_t *client, ipc_call_t *icall)
    203201{
    204202        log_msg(LOG_DEFAULT, LVL_DEBUG, "inetping_get_srcaddr_srv()");
    205203
    206         cap_call_handle_t chandle;
     204        ipc_call_t call;
    207205        size_t size;
    208206
     
    210208        inet_addr_t remote;
    211209
    212         if (!async_data_write_receive(&chandle, &size)) {
    213                 async_answer_0(chandle, EREFUSED);
    214                 async_answer_0(icall_handle, EREFUSED);
     210        if (!async_data_write_receive(&call, &size)) {
     211                async_answer_0(&call, EREFUSED);
     212                async_answer_0(icall, EREFUSED);
    215213                return;
    216214        }
    217215
    218216        if (size != sizeof(remote)) {
    219                 async_answer_0(chandle, EINVAL);
    220                 async_answer_0(icall_handle, EINVAL);
    221                 return;
    222         }
    223 
    224         errno_t rc = async_data_write_finalize(chandle, &remote, size);
    225         if (rc != EOK) {
    226                 async_answer_0(chandle, rc);
    227                 async_answer_0(icall_handle, rc);
     217                async_answer_0(&call, EINVAL);
     218                async_answer_0(icall, EINVAL);
     219                return;
     220        }
     221
     222        errno_t rc = async_data_write_finalize(&call, &remote, size);
     223        if (rc != EOK) {
     224                async_answer_0(&call, rc);
     225                async_answer_0(icall, rc);
    228226                return;
    229227        }
     
    231229        rc = inetping_get_srcaddr(client, &remote, &local);
    232230        if (rc != EOK) {
    233                 async_answer_0(icall_handle, rc);
    234                 return;
    235         }
    236 
    237         if (!async_data_read_receive(&chandle, &size)) {
    238                 async_answer_0(chandle, EREFUSED);
    239                 async_answer_0(icall_handle, EREFUSED);
     231                async_answer_0(icall, rc);
     232                return;
     233        }
     234
     235        if (!async_data_read_receive(&call, &size)) {
     236                async_answer_0(&call, EREFUSED);
     237                async_answer_0(icall, EREFUSED);
    240238                return;
    241239        }
    242240
    243241        if (size != sizeof(local)) {
    244                 async_answer_0(chandle, EINVAL);
    245                 async_answer_0(icall_handle, EINVAL);
    246                 return;
    247         }
    248 
    249         rc = async_data_read_finalize(chandle, &local, size);
     242                async_answer_0(&call, EINVAL);
     243                async_answer_0(icall, EINVAL);
     244                return;
     245        }
     246
     247        rc = async_data_read_finalize(&call, &local, size);
    250248        if (rc != EOK)
    251                 async_answer_0(chandle, rc);
    252 
    253         async_answer_0(icall_handle, rc);
     249                async_answer_0(&call, rc);
     250
     251        async_answer_0(icall, rc);
    254252}
    255253
     
    281279}
    282280
    283 void inetping_conn(cap_call_handle_t icall_handle, ipc_call_t *icall, void *arg)
     281void inetping_conn(ipc_call_t *icall, void *arg)
    284282{
    285283        log_msg(LOG_DEFAULT, LVL_DEBUG, "inetping_conn()");
    286284
    287285        /* Accept the connection */
    288         async_answer_0(icall_handle, EOK);
     286        async_answer_0(icall, EOK);
    289287
    290288        inetping_client_t client;
     
    295293        while (true) {
    296294                ipc_call_t call;
    297                 cap_call_handle_t chandle = async_get_call(&call);
     295                async_get_call(&call);
    298296                sysarg_t method = IPC_GET_IMETHOD(call);
    299297
    300298                if (!method) {
    301299                        /* The other side has hung up */
    302                         async_answer_0(chandle, EOK);
     300                        async_answer_0(&call, EOK);
    303301                        break;
    304302                }
     
    306304                switch (method) {
    307305                case INETPING_SEND:
    308                         inetping_send_srv(&client, chandle, &call);
     306                        inetping_send_srv(&client, &call);
    309307                        break;
    310308                case INETPING_GET_SRCADDR:
    311                         inetping_get_srcaddr_srv(&client, chandle, &call);
     309                        inetping_get_srcaddr_srv(&client, &call);
    312310                        break;
    313311                default:
    314                         async_answer_0(chandle, EINVAL);
     312                        async_answer_0(&call, EINVAL);
    315313                }
    316314        }
Note: See TracChangeset for help on using the changeset viewer.