Changes in uspace/srv/net/inetsrv/addrobj.c [36fcd0a:09ab0a9a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/inetsrv/addrobj.c
r36fcd0a r09ab0a9a 1 1 /* 2 * Copyright (c) 20 24Jiri Svoboda2 * Copyright (c) 2012 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 38 38 #include <errno.h> 39 39 #include <fibril_synch.h> 40 #include <inet/eth_addr.h>41 40 #include <io/log.h> 42 41 #include <ipc/loc.h> 43 #include <sif.h>44 #include <stdio.h>45 42 #include <stdlib.h> 46 43 #include <str.h> … … 213 210 } 214 211 215 /** Count number of non-temporary address objects configured for link.216 *217 * @param ilink Inet link218 * @return Number of address objects configured for this link219 */220 unsigned inet_addrobj_cnt_by_link(inet_link_t *ilink)221 {222 unsigned cnt;223 224 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_addrobj_cnt_by_link()");225 226 fibril_mutex_lock(&addr_list_lock);227 228 cnt = 0;229 list_foreach(addr_list, addr_list, inet_addrobj_t, naddr) {230 if (naddr->ilink == ilink && naddr->temp == false)231 ++cnt;232 }233 234 fibril_mutex_unlock(&addr_list_lock);235 return cnt;236 }237 238 212 /** Send datagram from address object */ 239 213 errno_t inet_addrobj_send_dgram(inet_addrobj_t *addr, inet_addr_t *ldest, … … 255 229 256 230 errno_t rc; 257 eth_addr_t ldest_mac;231 addr48_t ldest_mac; 258 232 259 233 switch (ldest_ver) { … … 265 239 * Translate local destination IPv6 address. 266 240 */ 267 rc = ndp_translate(lsrc_v6, ldest_v6, &ldest_mac, addr->ilink);241 rc = ndp_translate(lsrc_v6, ldest_v6, ldest_mac, addr->ilink); 268 242 if (rc != EOK) 269 243 return rc; 270 244 271 return inet_link_send_dgram6(addr->ilink, &ldest_mac, dgram,245 return inet_link_send_dgram6(addr->ilink, ldest_mac, dgram, 272 246 proto, ttl, df); 273 247 default: … … 307 281 } 308 282 309 /** Load address object from SIF node.310 *311 * @param anode SIF node to load address object from312 * @return EOK on success or an error code313 */314 static errno_t inet_addrobj_load(sif_node_t *anode)315 {316 errno_t rc;317 const char *sid;318 const char *snaddr;319 const char *slink;320 const char *name;321 char *endptr;322 int id;323 inet_naddr_t naddr;324 inet_addrobj_t *addr;325 inet_link_t *link;326 327 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_addrobj_load()");328 329 sid = sif_node_get_attr(anode, "id");330 if (sid == NULL)331 return EIO;332 333 snaddr = sif_node_get_attr(anode, "naddr");334 if (snaddr == NULL)335 return EIO;336 337 slink = sif_node_get_attr(anode, "link");338 if (slink == NULL)339 return EIO;340 341 name = sif_node_get_attr(anode, "name");342 if (name == NULL)343 return EIO;344 345 log_msg(LOG_DEFAULT, LVL_NOTE, "inet_addrobj_load(): id='%s' "346 "naddr='%s' link='%s' name='%s'", sid, snaddr, slink, name);347 348 id = strtoul(sid, &endptr, 10);349 if (*endptr != '\0')350 return EIO;351 352 rc = inet_naddr_parse(snaddr, &naddr, NULL);353 if (rc != EOK)354 return EIO;355 356 link = inet_link_get_by_svc_name(slink);357 if (link == NULL) {358 log_msg(LOG_DEFAULT, LVL_ERROR, "Link '%s' not found",359 slink);360 return EIO;361 }362 363 addr = inet_addrobj_new();364 if (addr == NULL)365 return ENOMEM;366 367 addr->id = id;368 addr->naddr = naddr;369 addr->ilink = link;370 addr->name = str_dup(name);371 372 if (addr->name == NULL) {373 inet_addrobj_delete(addr);374 return ENOMEM;375 }376 377 inet_addrobj_add(addr);378 return EOK;379 }380 381 /** Load address objects from SIF node.382 *383 * @param naddrs SIF node to load address objects from384 * @return EOK on success or an error code385 */386 errno_t inet_addrobjs_load(sif_node_t *naddrs)387 {388 sif_node_t *naddr;389 const char *ntype;390 errno_t rc;391 392 naddr = sif_node_first_child(naddrs);393 while (naddr != NULL) {394 ntype = sif_node_get_type(naddr);395 if (str_cmp(ntype, "address") != 0) {396 rc = EIO;397 goto error;398 }399 400 rc = inet_addrobj_load(naddr);401 if (rc != EOK)402 goto error;403 404 naddr = sif_node_next_child(naddr);405 }406 407 return EOK;408 error:409 return rc;410 411 }412 413 /** Save address object to SIF node.414 *415 * @param addr Address object416 * @param naddr SIF node to save addres to417 * @return EOK on success or an error code418 */419 static errno_t inet_addrobj_save(inet_addrobj_t *addr, sif_node_t *naddr)420 {421 char *str = NULL;422 errno_t rc;423 int rv;424 425 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_addrobj_save(%p, %p)",426 addr, naddr);427 428 /* id */429 430 rv = asprintf(&str, "%zu", addr->id);431 if (rv < 0) {432 str = NULL;433 rc = ENOMEM;434 goto error;435 }436 437 rc = sif_node_set_attr(naddr, "id", str);438 if (rc != EOK)439 goto error;440 441 free(str);442 str = NULL;443 444 /* dest */445 446 rc = inet_naddr_format(&addr->naddr, &str);447 if (rc != EOK)448 goto error;449 450 rc = sif_node_set_attr(naddr, "naddr", str);451 if (rc != EOK)452 goto error;453 454 free(str);455 str = NULL;456 457 /* link */458 459 rc = sif_node_set_attr(naddr, "link", addr->ilink->svc_name);460 if (rc != EOK)461 goto error;462 463 /* name */464 465 rc = sif_node_set_attr(naddr, "name", addr->name);466 if (rc != EOK)467 goto error;468 469 free(str);470 471 return rc;472 error:473 if (str != NULL)474 free(str);475 return rc;476 }477 478 /** Save address objects to SIF node.479 *480 * @param cnode SIF node to save address objects to481 * @return EOK on success or an error code482 */483 errno_t inet_addrobjs_save(sif_node_t *cnode)484 {485 sif_node_t *naddr;486 errno_t rc;487 488 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_addrobjs_save()");489 490 fibril_mutex_lock(&addr_list_lock);491 492 list_foreach(addr_list, addr_list, inet_addrobj_t, addr) {493 if (addr->temp == false) {494 rc = sif_node_append_child(cnode, "address", &naddr);495 if (rc != EOK)496 goto error;497 498 rc = inet_addrobj_save(addr, naddr);499 if (rc != EOK)500 goto error;501 }502 }503 504 fibril_mutex_unlock(&addr_list_lock);505 return EOK;506 error:507 fibril_mutex_unlock(&addr_list_lock);508 return rc;509 }510 511 283 /** @} 512 284 */
Note:
See TracChangeset
for help on using the changeset viewer.