Changeset bf9e6fc in mainline for uspace/srv/net/inetsrv/addrobj.c


Ignore:
Timestamp:
2012-05-13T10:01:08Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ce1836e
Parents:
f8dbc12
Message:

Detect duplicate address names.

File:
1 edited

Legend:

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

    rf8dbc12 rbf9e6fc  
    4848#include "inet_util.h"
    4949
     50static inet_addrobj_t *inet_addrobj_find_by_name_locked(const char *, inet_link_t *);
     51
    5052static FIBRIL_MUTEX_INITIALIZE(addr_list_lock);
    5153static LIST_INITIALIZE(addr_list);
     
    7779}
    7880
    79 void inet_addrobj_add(inet_addrobj_t *addr)
    80 {
    81         fibril_mutex_lock(&addr_list_lock);
     81int inet_addrobj_add(inet_addrobj_t *addr)
     82{
     83        inet_addrobj_t *aobj;
     84
     85        fibril_mutex_lock(&addr_list_lock);
     86        aobj = inet_addrobj_find_by_name_locked(addr->name, addr->ilink);
     87        if (aobj != NULL) {
     88                /* Duplicate address name */
     89                fibril_mutex_unlock(&addr_list_lock);
     90                return EEXISTS;
     91        }
     92
    8293        list_append(&addr->addr_list, &addr_list);
    8394        fibril_mutex_unlock(&addr_list_lock);
     95
     96        return EOK;
    8497}
    8598
     
    130143 * @return      Address object
    131144 */
    132 inet_addrobj_t *inet_addrobj_find_by_name(const char *name, inet_link_t *ilink)
    133 {
    134         log_msg(LVL_DEBUG, "inet_addrobj_find_by_name('%s', '%s')",
     145static inet_addrobj_t *inet_addrobj_find_by_name_locked(const char *name, inet_link_t *ilink)
     146{
     147        assert(fibril_mutex_is_locked(&addr_list_lock));
     148
     149        log_msg(LVL_DEBUG, "inet_addrobj_find_by_name_locked('%s', '%s')",
    135150            name, ilink->svc_name);
    136151
    137         fibril_mutex_lock(&addr_list_lock);
    138 
    139152        list_foreach(addr_list, link) {
    140153                inet_addrobj_t *naddr = list_get_instance(link,
     
    142155
    143156                if (naddr->ilink == ilink && str_cmp(naddr->name, name) == 0) {
    144                         fibril_mutex_unlock(&addr_list_lock);
    145                         log_msg(LVL_DEBUG, "inet_addrobj_find_by_name: found %p",
     157                        log_msg(LVL_DEBUG, "inet_addrobj_find_by_name_locked: found %p",
    146158                            naddr);
    147159                        return naddr;
     
    149161        }
    150162
    151         log_msg(LVL_DEBUG, "inet_addrobj_find_by_name: Not found");
    152         fibril_mutex_unlock(&addr_list_lock);
     163        log_msg(LVL_DEBUG, "inet_addrobj_find_by_name_locked: Not found");
    153164
    154165        return NULL;
     166}
     167
     168
     169/** Find address object on a link, with a specific name.
     170 *
     171 * @param name  Address object name
     172 * @param ilink Inet link
     173 * @return      Address object
     174 */
     175inet_addrobj_t *inet_addrobj_find_by_name(const char *name, inet_link_t *ilink)
     176{
     177        inet_addrobj_t *aobj;
     178
     179        log_msg(LVL_DEBUG, "inet_addrobj_find_by_name('%s', '%s')",
     180            name, ilink->svc_name);
     181
     182        fibril_mutex_lock(&addr_list_lock);
     183        aobj = inet_addrobj_find_by_name_locked(name, ilink);
     184        fibril_mutex_unlock(&addr_list_lock);
     185
     186        return aobj;
    155187}
    156188
Note: See TracChangeset for help on using the changeset viewer.