| 1 | /*
|
|---|
| 2 | * Copyright (c) 2013 Jiri Svoboda
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup inet
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /**
|
|---|
| 33 | * @file
|
|---|
| 34 | * @brief
|
|---|
| 35 | */
|
|---|
| 36 |
|
|---|
| 37 | #include <async.h>
|
|---|
| 38 | #include <errno.h>
|
|---|
| 39 | #include <macros.h>
|
|---|
| 40 | #include <io/log.h>
|
|---|
| 41 | #include <ipc/inet.h>
|
|---|
| 42 | #include <loc.h>
|
|---|
| 43 | #include <stdlib.h>
|
|---|
| 44 | #include <str.h>
|
|---|
| 45 | #include <stddef.h>
|
|---|
| 46 | #include <types/inetcfg.h>
|
|---|
| 47 |
|
|---|
| 48 | #include "addrobj.h"
|
|---|
| 49 | #include "inetsrv.h"
|
|---|
| 50 | #include "inet_link.h"
|
|---|
| 51 | #include "inetcfg.h"
|
|---|
| 52 | #include "sroute.h"
|
|---|
| 53 |
|
|---|
| 54 | static int inetcfg_addr_create_static(char *name, inet_naddr_t *naddr,
|
|---|
| 55 | sysarg_t link_id, sysarg_t *addr_id)
|
|---|
| 56 | {
|
|---|
| 57 | inet_link_t *ilink;
|
|---|
| 58 | inet_addrobj_t *addr;
|
|---|
| 59 | inet_addr_t iaddr;
|
|---|
| 60 | int rc;
|
|---|
| 61 |
|
|---|
| 62 | ilink = inet_link_get_by_id(link_id);
|
|---|
| 63 | if (ilink == NULL) {
|
|---|
| 64 | log_msg(LOG_DEFAULT, LVL_DEBUG, "Link %lu not found.",
|
|---|
| 65 | (unsigned long) link_id);
|
|---|
| 66 | return ENOENT;
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | addr = inet_addrobj_new();
|
|---|
| 70 | if (addr == NULL) {
|
|---|
| 71 | *addr_id = 0;
|
|---|
| 72 | return ENOMEM;
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | addr->naddr = *naddr;
|
|---|
| 76 | addr->ilink = ilink;
|
|---|
| 77 | addr->name = str_dup(name);
|
|---|
| 78 | rc = inet_addrobj_add(addr);
|
|---|
| 79 | if (rc != EOK) {
|
|---|
| 80 | log_msg(LOG_DEFAULT, LVL_DEBUG, "Duplicate address name '%s'.", addr->name);
|
|---|
| 81 | inet_addrobj_delete(addr);
|
|---|
| 82 | return rc;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | inet_naddr_addr(&addr->naddr, &iaddr);
|
|---|
| 86 | rc = iplink_addr_add(ilink->iplink, &iaddr);
|
|---|
| 87 | if (rc != EOK) {
|
|---|
| 88 | log_msg(LOG_DEFAULT, LVL_ERROR, "Failed setting IP address on internet link.");
|
|---|
| 89 | inet_addrobj_remove(addr);
|
|---|
| 90 | inet_addrobj_delete(addr);
|
|---|
| 91 | return rc;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | return EOK;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | static int inetcfg_addr_delete(sysarg_t addr_id)
|
|---|
| 98 | {
|
|---|
| 99 | inet_addrobj_t *addr;
|
|---|
| 100 |
|
|---|
| 101 | addr = inet_addrobj_get_by_id(addr_id);
|
|---|
| 102 | if (addr == NULL)
|
|---|
| 103 | return ENOENT;
|
|---|
| 104 |
|
|---|
| 105 | inet_addrobj_remove(addr);
|
|---|
| 106 | inet_addrobj_delete(addr);
|
|---|
| 107 |
|
|---|
| 108 | return EOK;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | static int inetcfg_addr_get(sysarg_t addr_id, inet_addr_info_t *ainfo)
|
|---|
| 112 | {
|
|---|
| 113 | inet_addrobj_t *addr;
|
|---|
| 114 |
|
|---|
| 115 | addr = inet_addrobj_get_by_id(addr_id);
|
|---|
| 116 | if (addr == NULL)
|
|---|
| 117 | return ENOENT;
|
|---|
| 118 |
|
|---|
| 119 | ainfo->naddr = addr->naddr;
|
|---|
| 120 | ainfo->ilink = addr->ilink->svc_id;
|
|---|
| 121 | ainfo->name = str_dup(addr->name);
|
|---|
| 122 |
|
|---|
| 123 | return EOK;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | static int inetcfg_addr_get_id(char *name, sysarg_t link_id, sysarg_t *addr_id)
|
|---|
| 127 | {
|
|---|
| 128 | inet_link_t *ilink;
|
|---|
| 129 | inet_addrobj_t *addr;
|
|---|
| 130 |
|
|---|
| 131 | ilink = inet_link_get_by_id(link_id);
|
|---|
| 132 | if (ilink == NULL) {
|
|---|
| 133 | log_msg(LOG_DEFAULT, LVL_DEBUG, "Link %zu not found.", (size_t) link_id);
|
|---|
| 134 | return ENOENT;
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | addr = inet_addrobj_find_by_name(name, ilink);
|
|---|
| 138 | if (addr == NULL) {
|
|---|
| 139 | log_msg(LOG_DEFAULT, LVL_DEBUG, "Address '%s' not found.", name);
|
|---|
| 140 | return ENOENT;
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | *addr_id = addr->id;
|
|---|
| 144 | return EOK;
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | static int inetcfg_get_addr_list(sysarg_t **addrs, size_t *count)
|
|---|
| 148 | {
|
|---|
| 149 | return inet_addrobj_get_id_list(addrs, count);
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | static int inetcfg_get_link_list(sysarg_t **addrs, size_t *count)
|
|---|
| 153 | {
|
|---|
| 154 | return inet_link_get_id_list(addrs, count);
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | static int inetcfg_get_sroute_list(sysarg_t **sroutes, size_t *count)
|
|---|
| 158 | {
|
|---|
| 159 | return inet_sroute_get_id_list(sroutes, count);
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | static int inetcfg_link_add(sysarg_t link_id)
|
|---|
| 163 | {
|
|---|
| 164 | return inet_link_open(link_id);
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | static int inetcfg_link_get(sysarg_t link_id, inet_link_info_t *linfo)
|
|---|
| 168 | {
|
|---|
| 169 | inet_link_t *ilink;
|
|---|
| 170 |
|
|---|
| 171 | ilink = inet_link_get_by_id(link_id);
|
|---|
| 172 | if (ilink == NULL) {
|
|---|
| 173 | return ENOENT;
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 176 | linfo->name = str_dup(ilink->svc_name);
|
|---|
| 177 | linfo->def_mtu = ilink->def_mtu;
|
|---|
| 178 | if (ilink->mac_valid) {
|
|---|
| 179 | addr48(ilink->mac, linfo->mac_addr);
|
|---|
| 180 | } else {
|
|---|
| 181 | memset(linfo->mac_addr, 0, sizeof(linfo->mac_addr));
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | return EOK;
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | static int inetcfg_link_remove(sysarg_t link_id)
|
|---|
| 188 | {
|
|---|
| 189 | return ENOTSUP;
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | static int inetcfg_sroute_create(char *name, inet_naddr_t *dest,
|
|---|
| 193 | inet_addr_t *router, sysarg_t *sroute_id)
|
|---|
| 194 | {
|
|---|
| 195 | inet_sroute_t *sroute;
|
|---|
| 196 |
|
|---|
| 197 | sroute = inet_sroute_new();
|
|---|
| 198 | if (sroute == NULL) {
|
|---|
| 199 | *sroute_id = 0;
|
|---|
| 200 | return ENOMEM;
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|
| 203 | sroute->dest = *dest;
|
|---|
| 204 | sroute->router = *router;
|
|---|
| 205 | sroute->name = str_dup(name);
|
|---|
| 206 | inet_sroute_add(sroute);
|
|---|
| 207 |
|
|---|
| 208 | *sroute_id = sroute->id;
|
|---|
| 209 | return EOK;
|
|---|
| 210 | }
|
|---|
| 211 |
|
|---|
| 212 | static int inetcfg_sroute_delete(sysarg_t sroute_id)
|
|---|
| 213 | {
|
|---|
| 214 | inet_sroute_t *sroute;
|
|---|
| 215 |
|
|---|
| 216 | sroute = inet_sroute_get_by_id(sroute_id);
|
|---|
| 217 | if (sroute == NULL)
|
|---|
| 218 | return ENOENT;
|
|---|
| 219 |
|
|---|
| 220 | inet_sroute_remove(sroute);
|
|---|
| 221 | inet_sroute_delete(sroute);
|
|---|
| 222 |
|
|---|
| 223 | return EOK;
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | static int inetcfg_sroute_get(sysarg_t sroute_id, inet_sroute_info_t *srinfo)
|
|---|
| 227 | {
|
|---|
| 228 | inet_sroute_t *sroute;
|
|---|
| 229 |
|
|---|
| 230 | sroute = inet_sroute_get_by_id(sroute_id);
|
|---|
| 231 | if (sroute == NULL)
|
|---|
| 232 | return ENOENT;
|
|---|
| 233 |
|
|---|
| 234 | srinfo->dest = sroute->dest;
|
|---|
| 235 | srinfo->router = sroute->router;
|
|---|
| 236 | srinfo->name = str_dup(sroute->name);
|
|---|
| 237 |
|
|---|
| 238 | return EOK;
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | static int inetcfg_sroute_get_id(char *name, sysarg_t *sroute_id)
|
|---|
| 242 | {
|
|---|
| 243 | inet_sroute_t *sroute;
|
|---|
| 244 |
|
|---|
| 245 | sroute = inet_sroute_find_by_name(name);
|
|---|
| 246 | if (sroute == NULL) {
|
|---|
| 247 | log_msg(LOG_DEFAULT, LVL_DEBUG, "Static route '%s' not found.", name);
|
|---|
| 248 | return ENOENT;
|
|---|
| 249 | }
|
|---|
| 250 |
|
|---|
| 251 | *sroute_id = sroute->id;
|
|---|
| 252 | return EOK;
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| 255 | static void inetcfg_addr_create_static_srv(ipc_callid_t iid,
|
|---|
| 256 | ipc_call_t *icall)
|
|---|
| 257 | {
|
|---|
| 258 | log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_addr_create_static_srv()");
|
|---|
| 259 |
|
|---|
| 260 | sysarg_t link_id = IPC_GET_ARG1(*icall);
|
|---|
| 261 |
|
|---|
| 262 | ipc_callid_t callid;
|
|---|
| 263 | size_t size;
|
|---|
| 264 | if (!async_data_write_receive(&callid, &size)) {
|
|---|
| 265 | async_answer_0(callid, EINVAL);
|
|---|
| 266 | async_answer_0(iid, EINVAL);
|
|---|
| 267 | return;
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | if (size != sizeof(inet_naddr_t)) {
|
|---|
| 271 | async_answer_0(callid, EINVAL);
|
|---|
| 272 | async_answer_0(iid, EINVAL);
|
|---|
| 273 | return;
|
|---|
| 274 | }
|
|---|
| 275 |
|
|---|
| 276 | inet_naddr_t naddr;
|
|---|
| 277 | int rc = async_data_write_finalize(callid, &naddr, size);
|
|---|
| 278 | if (rc != EOK) {
|
|---|
| 279 | async_answer_0(callid, rc);
|
|---|
| 280 | async_answer_0(iid, rc);
|
|---|
| 281 | return;
|
|---|
| 282 | }
|
|---|
| 283 |
|
|---|
| 284 | char *name;
|
|---|
| 285 | rc = async_data_write_accept((void **) &name, true, 0, LOC_NAME_MAXLEN,
|
|---|
| 286 | 0, NULL);
|
|---|
| 287 | if (rc != EOK) {
|
|---|
| 288 | async_answer_0(iid, rc);
|
|---|
| 289 | return;
|
|---|
| 290 | }
|
|---|
| 291 |
|
|---|
| 292 | sysarg_t addr_id = 0;
|
|---|
| 293 | rc = inetcfg_addr_create_static(name, &naddr, link_id, &addr_id);
|
|---|
| 294 | free(name);
|
|---|
| 295 | async_answer_1(iid, rc, addr_id);
|
|---|
| 296 | }
|
|---|
| 297 |
|
|---|
| 298 | static void inetcfg_addr_delete_srv(ipc_callid_t callid, ipc_call_t *call)
|
|---|
| 299 | {
|
|---|
| 300 | sysarg_t addr_id;
|
|---|
| 301 | int rc;
|
|---|
| 302 |
|
|---|
| 303 | log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_addr_delete_srv()");
|
|---|
| 304 |
|
|---|
| 305 | addr_id = IPC_GET_ARG1(*call);
|
|---|
| 306 |
|
|---|
| 307 | rc = inetcfg_addr_delete(addr_id);
|
|---|
| 308 | async_answer_0(callid, rc);
|
|---|
| 309 | }
|
|---|
| 310 |
|
|---|
| 311 | static void inetcfg_addr_get_srv(ipc_callid_t iid, ipc_call_t *icall)
|
|---|
| 312 | {
|
|---|
| 313 | log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_addr_get_srv()");
|
|---|
| 314 |
|
|---|
| 315 | sysarg_t addr_id = IPC_GET_ARG1(*icall);
|
|---|
| 316 |
|
|---|
| 317 | inet_addr_info_t ainfo;
|
|---|
| 318 |
|
|---|
| 319 | inet_naddr_any(&ainfo.naddr);
|
|---|
| 320 | ainfo.ilink = 0;
|
|---|
| 321 | ainfo.name = NULL;
|
|---|
| 322 |
|
|---|
| 323 | int rc = inetcfg_addr_get(addr_id, &ainfo);
|
|---|
| 324 | if (rc != EOK) {
|
|---|
| 325 | async_answer_0(iid, rc);
|
|---|
| 326 | return;
|
|---|
| 327 | }
|
|---|
| 328 |
|
|---|
| 329 | ipc_callid_t callid;
|
|---|
| 330 | size_t size;
|
|---|
| 331 | if (!async_data_read_receive(&callid, &size)) {
|
|---|
| 332 | async_answer_0(callid, EREFUSED);
|
|---|
| 333 | async_answer_0(iid, EREFUSED);
|
|---|
| 334 | return;
|
|---|
| 335 | }
|
|---|
| 336 |
|
|---|
| 337 | if (size != sizeof(inet_naddr_t)) {
|
|---|
| 338 | async_answer_0(callid, EINVAL);
|
|---|
| 339 | async_answer_0(iid, EINVAL);
|
|---|
| 340 | return;
|
|---|
| 341 | }
|
|---|
| 342 |
|
|---|
| 343 | rc = async_data_read_finalize(callid, &ainfo.naddr, size);
|
|---|
| 344 | if (rc != EOK) {
|
|---|
| 345 | async_answer_0(callid, rc);
|
|---|
| 346 | async_answer_0(iid, rc);
|
|---|
| 347 | return;
|
|---|
| 348 | }
|
|---|
| 349 |
|
|---|
| 350 | if (!async_data_read_receive(&callid, &size)) {
|
|---|
| 351 | async_answer_0(callid, EREFUSED);
|
|---|
| 352 | async_answer_0(iid, EREFUSED);
|
|---|
| 353 | return;
|
|---|
| 354 | }
|
|---|
| 355 |
|
|---|
| 356 | rc = async_data_read_finalize(callid, ainfo.name,
|
|---|
| 357 | min(size, str_size(ainfo.name)));
|
|---|
| 358 | free(ainfo.name);
|
|---|
| 359 |
|
|---|
| 360 | if (rc != EOK) {
|
|---|
| 361 | async_answer_0(callid, rc);
|
|---|
| 362 | async_answer_0(iid, rc);
|
|---|
| 363 | return;
|
|---|
| 364 | }
|
|---|
| 365 |
|
|---|
| 366 | async_answer_1(iid, (sysarg_t) rc, ainfo.ilink);
|
|---|
| 367 | }
|
|---|
| 368 |
|
|---|
| 369 | static void inetcfg_addr_get_id_srv(ipc_callid_t callid, ipc_call_t *call)
|
|---|
| 370 | {
|
|---|
| 371 | char *name;
|
|---|
| 372 | sysarg_t link_id;
|
|---|
| 373 | sysarg_t addr_id;
|
|---|
| 374 | int rc;
|
|---|
| 375 |
|
|---|
| 376 | log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_addr_get_id_srv()");
|
|---|
| 377 |
|
|---|
| 378 | link_id = IPC_GET_ARG1(*call);
|
|---|
| 379 |
|
|---|
| 380 | rc = async_data_write_accept((void **) &name, true, 0, LOC_NAME_MAXLEN,
|
|---|
| 381 | 0, NULL);
|
|---|
| 382 | if (rc != EOK) {
|
|---|
| 383 | async_answer_0(callid, rc);
|
|---|
| 384 | return;
|
|---|
| 385 | }
|
|---|
| 386 |
|
|---|
| 387 | addr_id = 0;
|
|---|
| 388 | rc = inetcfg_addr_get_id(name, link_id, &addr_id);
|
|---|
| 389 | free(name);
|
|---|
| 390 | async_answer_1(callid, rc, addr_id);
|
|---|
| 391 | }
|
|---|
| 392 |
|
|---|
| 393 | static void inetcfg_get_addr_list_srv(ipc_callid_t callid, ipc_call_t *call)
|
|---|
| 394 | {
|
|---|
| 395 | ipc_callid_t rcallid;
|
|---|
| 396 | size_t count;
|
|---|
| 397 | size_t max_size;
|
|---|
| 398 | size_t act_size;
|
|---|
| 399 | size_t size;
|
|---|
| 400 | sysarg_t *id_buf;
|
|---|
| 401 | int rc;
|
|---|
| 402 |
|
|---|
| 403 | log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_get_addr_list_srv()");
|
|---|
| 404 |
|
|---|
| 405 | if (!async_data_read_receive(&rcallid, &max_size)) {
|
|---|
| 406 | async_answer_0(rcallid, EREFUSED);
|
|---|
| 407 | async_answer_0(callid, EREFUSED);
|
|---|
| 408 | return;
|
|---|
| 409 | }
|
|---|
| 410 |
|
|---|
| 411 | rc = inetcfg_get_addr_list(&id_buf, &count);
|
|---|
| 412 | if (rc != EOK) {
|
|---|
| 413 | async_answer_0(rcallid, rc);
|
|---|
| 414 | async_answer_0(callid, rc);
|
|---|
| 415 | return;
|
|---|
| 416 | }
|
|---|
| 417 |
|
|---|
| 418 | act_size = count * sizeof(sysarg_t);
|
|---|
| 419 | size = min(act_size, max_size);
|
|---|
| 420 |
|
|---|
| 421 | sysarg_t retval = async_data_read_finalize(rcallid, id_buf, size);
|
|---|
| 422 | free(id_buf);
|
|---|
| 423 |
|
|---|
| 424 | async_answer_1(callid, retval, act_size);
|
|---|
| 425 | }
|
|---|
| 426 |
|
|---|
| 427 | static void inetcfg_get_link_list_srv(ipc_callid_t callid, ipc_call_t *call)
|
|---|
| 428 | {
|
|---|
| 429 | ipc_callid_t rcallid;
|
|---|
| 430 | size_t count;
|
|---|
| 431 | size_t max_size;
|
|---|
| 432 | size_t act_size;
|
|---|
| 433 | size_t size;
|
|---|
| 434 | sysarg_t *id_buf;
|
|---|
| 435 | int rc;
|
|---|
| 436 |
|
|---|
| 437 | log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_get_addr_list_srv()");
|
|---|
| 438 |
|
|---|
| 439 | if (!async_data_read_receive(&rcallid, &max_size)) {
|
|---|
| 440 | async_answer_0(rcallid, EREFUSED);
|
|---|
| 441 | async_answer_0(callid, EREFUSED);
|
|---|
| 442 | return;
|
|---|
| 443 | }
|
|---|
| 444 |
|
|---|
| 445 | rc = inetcfg_get_link_list(&id_buf, &count);
|
|---|
| 446 | if (rc != EOK) {
|
|---|
| 447 | async_answer_0(rcallid, rc);
|
|---|
| 448 | async_answer_0(callid, rc);
|
|---|
| 449 | return;
|
|---|
| 450 | }
|
|---|
| 451 |
|
|---|
| 452 | act_size = count * sizeof(sysarg_t);
|
|---|
| 453 | size = min(act_size, max_size);
|
|---|
| 454 |
|
|---|
| 455 | sysarg_t retval = async_data_read_finalize(rcallid, id_buf, size);
|
|---|
| 456 | free(id_buf);
|
|---|
| 457 |
|
|---|
| 458 | async_answer_1(callid, retval, act_size);
|
|---|
| 459 | }
|
|---|
| 460 |
|
|---|
| 461 | static void inetcfg_get_sroute_list_srv(ipc_callid_t callid, ipc_call_t *call)
|
|---|
| 462 | {
|
|---|
| 463 | ipc_callid_t rcallid;
|
|---|
| 464 | size_t count;
|
|---|
| 465 | size_t max_size;
|
|---|
| 466 | size_t act_size;
|
|---|
| 467 | size_t size;
|
|---|
| 468 | sysarg_t *id_buf;
|
|---|
| 469 | int rc;
|
|---|
| 470 |
|
|---|
| 471 | log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_get_sroute_list_srv()");
|
|---|
| 472 |
|
|---|
| 473 | if (!async_data_read_receive(&rcallid, &max_size)) {
|
|---|
| 474 | async_answer_0(rcallid, EREFUSED);
|
|---|
| 475 | async_answer_0(callid, EREFUSED);
|
|---|
| 476 | return;
|
|---|
| 477 | }
|
|---|
| 478 |
|
|---|
| 479 | rc = inetcfg_get_sroute_list(&id_buf, &count);
|
|---|
| 480 | if (rc != EOK) {
|
|---|
| 481 | async_answer_0(rcallid, rc);
|
|---|
| 482 | async_answer_0(callid, rc);
|
|---|
| 483 | return;
|
|---|
| 484 | }
|
|---|
| 485 |
|
|---|
| 486 | act_size = count * sizeof(sysarg_t);
|
|---|
| 487 | size = min(act_size, max_size);
|
|---|
| 488 |
|
|---|
| 489 | sysarg_t retval = async_data_read_finalize(rcallid, id_buf, size);
|
|---|
| 490 | free(id_buf);
|
|---|
| 491 |
|
|---|
| 492 | async_answer_1(callid, retval, act_size);
|
|---|
| 493 | }
|
|---|
| 494 |
|
|---|
| 495 | static void inetcfg_link_add_srv(ipc_callid_t callid, ipc_call_t *call)
|
|---|
| 496 | {
|
|---|
| 497 | sysarg_t link_id;
|
|---|
| 498 | int rc;
|
|---|
| 499 |
|
|---|
| 500 | log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_link_add_srv()");
|
|---|
| 501 |
|
|---|
| 502 | link_id = IPC_GET_ARG1(*call);
|
|---|
| 503 |
|
|---|
| 504 | rc = inetcfg_link_add(link_id);
|
|---|
| 505 | async_answer_0(callid, rc);
|
|---|
| 506 | }
|
|---|
| 507 |
|
|---|
| 508 | static void inetcfg_link_get_srv(ipc_callid_t callid, ipc_call_t *call)
|
|---|
| 509 | {
|
|---|
| 510 | ipc_callid_t name_callid;
|
|---|
| 511 | ipc_callid_t laddr_callid;
|
|---|
| 512 | size_t name_max_size;
|
|---|
| 513 | size_t laddr_max_size;
|
|---|
| 514 |
|
|---|
| 515 | sysarg_t link_id;
|
|---|
| 516 | inet_link_info_t linfo;
|
|---|
| 517 | int rc;
|
|---|
| 518 |
|
|---|
| 519 | link_id = IPC_GET_ARG1(*call);
|
|---|
| 520 | log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_link_get_srv()");
|
|---|
| 521 |
|
|---|
| 522 | linfo.name = NULL;
|
|---|
| 523 |
|
|---|
| 524 | if (!async_data_read_receive(&name_callid, &name_max_size)) {
|
|---|
| 525 | async_answer_0(name_callid, EREFUSED);
|
|---|
| 526 | async_answer_0(callid, EREFUSED);
|
|---|
| 527 | return;
|
|---|
| 528 | }
|
|---|
| 529 |
|
|---|
| 530 | if (!async_data_read_receive(&laddr_callid, &laddr_max_size)) {
|
|---|
| 531 | async_answer_0(name_callid, EREFUSED);
|
|---|
| 532 | async_answer_0(callid, EREFUSED);
|
|---|
| 533 | return;
|
|---|
| 534 | }
|
|---|
| 535 |
|
|---|
| 536 | rc = inetcfg_link_get(link_id, &linfo);
|
|---|
| 537 | if (rc != EOK) {
|
|---|
| 538 | async_answer_0(laddr_callid, rc);
|
|---|
| 539 | async_answer_0(name_callid, rc);
|
|---|
| 540 | async_answer_0(callid, rc);
|
|---|
| 541 | return;
|
|---|
| 542 | }
|
|---|
| 543 |
|
|---|
| 544 | sysarg_t retval = async_data_read_finalize(name_callid, linfo.name,
|
|---|
| 545 | min(name_max_size, str_size(linfo.name)));
|
|---|
| 546 | if (retval != EOK) {
|
|---|
| 547 | free(linfo.name);
|
|---|
| 548 | async_answer_0(laddr_callid, retval);
|
|---|
| 549 | async_answer_0(callid, retval);
|
|---|
| 550 | return;
|
|---|
| 551 | }
|
|---|
| 552 |
|
|---|
| 553 | retval = async_data_read_finalize(laddr_callid, &linfo.mac_addr,
|
|---|
| 554 | min(laddr_max_size, sizeof(linfo.mac_addr)));
|
|---|
| 555 |
|
|---|
| 556 | free(linfo.name);
|
|---|
| 557 |
|
|---|
| 558 | async_answer_1(callid, retval, linfo.def_mtu);
|
|---|
| 559 | }
|
|---|
| 560 |
|
|---|
| 561 | static void inetcfg_link_remove_srv(ipc_callid_t callid, ipc_call_t *call)
|
|---|
| 562 | {
|
|---|
| 563 | sysarg_t link_id;
|
|---|
| 564 | int rc;
|
|---|
| 565 |
|
|---|
| 566 | log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_link_remove_srv()");
|
|---|
| 567 |
|
|---|
| 568 | link_id = IPC_GET_ARG1(*call);
|
|---|
| 569 |
|
|---|
| 570 | rc = inetcfg_link_remove(link_id);
|
|---|
| 571 | async_answer_0(callid, rc);
|
|---|
| 572 | }
|
|---|
| 573 |
|
|---|
| 574 | static void inetcfg_sroute_create_srv(ipc_callid_t iid,
|
|---|
| 575 | ipc_call_t *icall)
|
|---|
| 576 | {
|
|---|
| 577 | log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_sroute_create_srv()");
|
|---|
| 578 |
|
|---|
| 579 | ipc_callid_t callid;
|
|---|
| 580 | size_t size;
|
|---|
| 581 | if (!async_data_write_receive(&callid, &size)) {
|
|---|
| 582 | async_answer_0(callid, EINVAL);
|
|---|
| 583 | async_answer_0(iid, EINVAL);
|
|---|
| 584 | return;
|
|---|
| 585 | }
|
|---|
| 586 |
|
|---|
| 587 | if (size != sizeof(inet_naddr_t)) {
|
|---|
| 588 | async_answer_0(callid, EINVAL);
|
|---|
| 589 | async_answer_0(iid, EINVAL);
|
|---|
| 590 | return;
|
|---|
| 591 | }
|
|---|
| 592 |
|
|---|
| 593 | inet_naddr_t dest;
|
|---|
| 594 | int rc = async_data_write_finalize(callid, &dest, size);
|
|---|
| 595 | if (rc != EOK) {
|
|---|
| 596 | async_answer_0(callid, rc);
|
|---|
| 597 | async_answer_0(iid, rc);
|
|---|
| 598 | return;
|
|---|
| 599 | }
|
|---|
| 600 |
|
|---|
| 601 | if (!async_data_write_receive(&callid, &size)) {
|
|---|
| 602 | async_answer_0(callid, EINVAL);
|
|---|
| 603 | async_answer_0(iid, EINVAL);
|
|---|
| 604 | return;
|
|---|
| 605 | }
|
|---|
| 606 |
|
|---|
| 607 | if (size != sizeof(inet_addr_t)) {
|
|---|
| 608 | async_answer_0(callid, EINVAL);
|
|---|
| 609 | async_answer_0(iid, EINVAL);
|
|---|
| 610 | return;
|
|---|
| 611 | }
|
|---|
| 612 |
|
|---|
| 613 | inet_addr_t router;
|
|---|
| 614 | rc = async_data_write_finalize(callid, &router, size);
|
|---|
| 615 | if (rc != EOK) {
|
|---|
| 616 | async_answer_0(callid, rc);
|
|---|
| 617 | async_answer_0(iid, rc);
|
|---|
| 618 | return;
|
|---|
| 619 | }
|
|---|
| 620 |
|
|---|
| 621 | char *name;
|
|---|
| 622 | rc = async_data_write_accept((void **) &name, true, 0, LOC_NAME_MAXLEN,
|
|---|
| 623 | 0, NULL);
|
|---|
| 624 | if (rc != EOK) {
|
|---|
| 625 | async_answer_0(iid, rc);
|
|---|
| 626 | return;
|
|---|
| 627 | }
|
|---|
| 628 |
|
|---|
| 629 | sysarg_t sroute_id = 0;
|
|---|
| 630 | rc = inetcfg_sroute_create(name, &dest, &router, &sroute_id);
|
|---|
| 631 | free(name);
|
|---|
| 632 | async_answer_1(iid, rc, sroute_id);
|
|---|
| 633 | }
|
|---|
| 634 |
|
|---|
| 635 | static void inetcfg_sroute_delete_srv(ipc_callid_t callid, ipc_call_t *call)
|
|---|
| 636 | {
|
|---|
| 637 | sysarg_t sroute_id;
|
|---|
| 638 | int rc;
|
|---|
| 639 |
|
|---|
| 640 | log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_sroute_delete_srv()");
|
|---|
| 641 |
|
|---|
| 642 | sroute_id = IPC_GET_ARG1(*call);
|
|---|
| 643 |
|
|---|
| 644 | rc = inetcfg_sroute_delete(sroute_id);
|
|---|
| 645 | async_answer_0(callid, rc);
|
|---|
| 646 | }
|
|---|
| 647 |
|
|---|
| 648 | static void inetcfg_sroute_get_srv(ipc_callid_t iid, ipc_call_t *icall)
|
|---|
| 649 | {
|
|---|
| 650 | log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_sroute_get_srv()");
|
|---|
| 651 |
|
|---|
| 652 | sysarg_t sroute_id = IPC_GET_ARG1(*icall);
|
|---|
| 653 |
|
|---|
| 654 | inet_sroute_info_t srinfo;
|
|---|
| 655 |
|
|---|
| 656 | inet_naddr_any(&srinfo.dest);
|
|---|
| 657 | inet_addr_any(&srinfo.router);
|
|---|
| 658 | srinfo.name = NULL;
|
|---|
| 659 |
|
|---|
| 660 | int rc = inetcfg_sroute_get(sroute_id, &srinfo);
|
|---|
| 661 | if (rc != EOK) {
|
|---|
| 662 | async_answer_0(iid, rc);
|
|---|
| 663 | return;
|
|---|
| 664 | }
|
|---|
| 665 |
|
|---|
| 666 | ipc_callid_t callid;
|
|---|
| 667 | size_t size;
|
|---|
| 668 | if (!async_data_read_receive(&callid, &size)) {
|
|---|
| 669 | async_answer_0(callid, EREFUSED);
|
|---|
| 670 | async_answer_0(iid, EREFUSED);
|
|---|
| 671 | return;
|
|---|
| 672 | }
|
|---|
| 673 |
|
|---|
| 674 | if (size != sizeof(inet_naddr_t)) {
|
|---|
| 675 | async_answer_0(callid, EINVAL);
|
|---|
| 676 | async_answer_0(iid, EINVAL);
|
|---|
| 677 | return;
|
|---|
| 678 | }
|
|---|
| 679 |
|
|---|
| 680 | rc = async_data_read_finalize(callid, &srinfo.dest, size);
|
|---|
| 681 | if (rc != EOK) {
|
|---|
| 682 | async_answer_0(callid, rc);
|
|---|
| 683 | async_answer_0(iid, rc);
|
|---|
| 684 | return;
|
|---|
| 685 | }
|
|---|
| 686 |
|
|---|
| 687 | if (!async_data_read_receive(&callid, &size)) {
|
|---|
| 688 | async_answer_0(callid, EREFUSED);
|
|---|
| 689 | async_answer_0(iid, EREFUSED);
|
|---|
| 690 | return;
|
|---|
| 691 | }
|
|---|
| 692 |
|
|---|
| 693 | if (size != sizeof(inet_addr_t)) {
|
|---|
| 694 | async_answer_0(callid, EINVAL);
|
|---|
| 695 | async_answer_0(iid, EINVAL);
|
|---|
| 696 | return;
|
|---|
| 697 | }
|
|---|
| 698 |
|
|---|
| 699 | rc = async_data_read_finalize(callid, &srinfo.router, size);
|
|---|
| 700 | if (rc != EOK) {
|
|---|
| 701 | async_answer_0(callid, rc);
|
|---|
| 702 | async_answer_0(iid, rc);
|
|---|
| 703 | return;
|
|---|
| 704 | }
|
|---|
| 705 |
|
|---|
| 706 | if (!async_data_read_receive(&callid, &size)) {
|
|---|
| 707 | async_answer_0(callid, EREFUSED);
|
|---|
| 708 | async_answer_0(iid, EREFUSED);
|
|---|
| 709 | return;
|
|---|
| 710 | }
|
|---|
| 711 |
|
|---|
| 712 | rc = async_data_read_finalize(callid, srinfo.name,
|
|---|
| 713 | min(size, str_size(srinfo.name)));
|
|---|
| 714 | free(srinfo.name);
|
|---|
| 715 |
|
|---|
| 716 | async_answer_0(iid, (sysarg_t) rc);
|
|---|
| 717 | }
|
|---|
| 718 |
|
|---|
| 719 | static void inetcfg_sroute_get_id_srv(ipc_callid_t callid, ipc_call_t *call)
|
|---|
| 720 | {
|
|---|
| 721 | char *name;
|
|---|
| 722 | sysarg_t sroute_id;
|
|---|
| 723 | int rc;
|
|---|
| 724 |
|
|---|
| 725 | log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_sroute_get_id_srv()");
|
|---|
| 726 |
|
|---|
| 727 | rc = async_data_write_accept((void **) &name, true, 0, LOC_NAME_MAXLEN,
|
|---|
| 728 | 0, NULL);
|
|---|
| 729 | if (rc != EOK) {
|
|---|
| 730 | async_answer_0(callid, rc);
|
|---|
| 731 | return;
|
|---|
| 732 | }
|
|---|
| 733 |
|
|---|
| 734 | sroute_id = 0;
|
|---|
| 735 | rc = inetcfg_sroute_get_id(name, &sroute_id);
|
|---|
| 736 | free(name);
|
|---|
| 737 | async_answer_1(callid, rc, sroute_id);
|
|---|
| 738 | }
|
|---|
| 739 |
|
|---|
| 740 | void inet_cfg_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
|
|---|
| 741 | {
|
|---|
| 742 | log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_cfg_conn()");
|
|---|
| 743 |
|
|---|
| 744 | /* Accept the connection */
|
|---|
| 745 | async_answer_0(iid, EOK);
|
|---|
| 746 |
|
|---|
| 747 | while (true) {
|
|---|
| 748 | ipc_call_t call;
|
|---|
| 749 | ipc_callid_t callid = async_get_call(&call);
|
|---|
| 750 | sysarg_t method = IPC_GET_IMETHOD(call);
|
|---|
| 751 |
|
|---|
| 752 | log_msg(LOG_DEFAULT, LVL_DEBUG, "method %d", (int)method);
|
|---|
| 753 | if (!method) {
|
|---|
| 754 | /* The other side has hung up */
|
|---|
| 755 | async_answer_0(callid, EOK);
|
|---|
| 756 | return;
|
|---|
| 757 | }
|
|---|
| 758 |
|
|---|
| 759 | switch (method) {
|
|---|
| 760 | case INETCFG_ADDR_CREATE_STATIC:
|
|---|
| 761 | inetcfg_addr_create_static_srv(callid, &call);
|
|---|
| 762 | break;
|
|---|
| 763 | case INETCFG_ADDR_DELETE:
|
|---|
| 764 | inetcfg_addr_delete_srv(callid, &call);
|
|---|
| 765 | break;
|
|---|
| 766 | case INETCFG_ADDR_GET:
|
|---|
| 767 | inetcfg_addr_get_srv(callid, &call);
|
|---|
| 768 | break;
|
|---|
| 769 | case INETCFG_ADDR_GET_ID:
|
|---|
| 770 | inetcfg_addr_get_id_srv(callid, &call);
|
|---|
| 771 | break;
|
|---|
| 772 | case INETCFG_GET_ADDR_LIST:
|
|---|
| 773 | inetcfg_get_addr_list_srv(callid, &call);
|
|---|
| 774 | break;
|
|---|
| 775 | case INETCFG_GET_LINK_LIST:
|
|---|
| 776 | inetcfg_get_link_list_srv(callid, &call);
|
|---|
| 777 | break;
|
|---|
| 778 | case INETCFG_GET_SROUTE_LIST:
|
|---|
| 779 | inetcfg_get_sroute_list_srv(callid, &call);
|
|---|
| 780 | break;
|
|---|
| 781 | case INETCFG_LINK_ADD:
|
|---|
| 782 | inetcfg_link_add_srv(callid, &call);
|
|---|
| 783 | break;
|
|---|
| 784 | case INETCFG_LINK_GET:
|
|---|
| 785 | inetcfg_link_get_srv(callid, &call);
|
|---|
| 786 | break;
|
|---|
| 787 | case INETCFG_LINK_REMOVE:
|
|---|
| 788 | inetcfg_link_remove_srv(callid, &call);
|
|---|
| 789 | break;
|
|---|
| 790 | case INETCFG_SROUTE_CREATE:
|
|---|
| 791 | inetcfg_sroute_create_srv(callid, &call);
|
|---|
| 792 | break;
|
|---|
| 793 | case INETCFG_SROUTE_DELETE:
|
|---|
| 794 | inetcfg_sroute_delete_srv(callid, &call);
|
|---|
| 795 | break;
|
|---|
| 796 | case INETCFG_SROUTE_GET:
|
|---|
| 797 | inetcfg_sroute_get_srv(callid, &call);
|
|---|
| 798 | break;
|
|---|
| 799 | case INETCFG_SROUTE_GET_ID:
|
|---|
| 800 | inetcfg_sroute_get_id_srv(callid, &call);
|
|---|
| 801 | break;
|
|---|
| 802 | default:
|
|---|
| 803 | async_answer_0(callid, EINVAL);
|
|---|
| 804 | }
|
|---|
| 805 | }
|
|---|
| 806 | }
|
|---|
| 807 |
|
|---|
| 808 | /** @}
|
|---|
| 809 | */
|
|---|