Changeset 89ac5513 in mainline for uspace/srv/net/inetsrv/sroute.c


Ignore:
Timestamp:
2013-06-23T19:54:53Z (11 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ddb1922
Parents:
3abf0760 (diff), 96cbd18 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

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

    r3abf0760 r89ac5513  
    9797inet_sroute_t *inet_sroute_find(inet_addr_t *addr)
    9898{
    99         uint32_t mask;
    100         inet_sroute_t *best;
    101 
    102         log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_sroute_find(%x)", (unsigned)addr->ipv4);
    103 
    104         fibril_mutex_lock(&sroute_list_lock);
    105 
    106         best = NULL;
    107 
    108         list_foreach(sroute_list, link) {
    109                 inet_sroute_t *sroute = list_get_instance(link,
    110                     inet_sroute_t, sroute_list);
    111 
     99        uint32_t addr_addr;
     100        int rc = inet_addr_pack(addr, &addr_addr);
     101        if (rc != EOK)
     102                return NULL;
     103       
     104        inet_sroute_t *best = NULL;
     105        uint8_t best_bits = 0;
     106       
     107        fibril_mutex_lock(&sroute_list_lock);
     108       
     109        list_foreach(sroute_list, link) {
     110                inet_sroute_t *sroute = list_get_instance(link,
     111                    inet_sroute_t, sroute_list);
     112               
     113                uint32_t dest_addr;
     114                uint8_t dest_bits;
     115                rc = inet_naddr_pack(&sroute->dest, &dest_addr, &dest_bits);
     116                if (rc != EOK)
     117                        continue;
     118               
    112119                /* Look for the most specific route */
    113                 if (best != NULL && best->dest.bits >= sroute->dest.bits)
     120                if ((best != NULL) && (best_bits >= dest_bits))
    114121                        continue;
    115 
    116                 mask = inet_netmask(sroute->dest.bits);
    117                 if ((sroute->dest.ipv4 & mask) == (addr->ipv4 & mask)) {
    118                         fibril_mutex_unlock(&sroute_list_lock);
    119                         log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_sroute_find: found %p",
     122               
     123                uint32_t mask = inet_netmask(dest_bits);
     124                if ((dest_addr & mask) == (addr_addr & mask)) {
     125                        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_sroute_find: found candidate %p",
    120126                            sroute);
    121                         return sroute;
     127                       
     128                        best = sroute;
     129                        best_bits = dest_bits;
    122130                }
    123131        }
    124 
    125         log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_sroute_find: Not found");
    126         fibril_mutex_unlock(&sroute_list_lock);
    127 
    128         return NULL;
     132       
     133        if (best == NULL)
     134                log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_sroute_find: Not found");
     135       
     136        fibril_mutex_unlock(&sroute_list_lock);
     137       
     138        return best;
    129139}
    130140
Note: See TracChangeset for help on using the changeset viewer.