Ignore:
File:
1 edited

Legend:

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

    r02a09ed ra1a101d  
    4242#include <stdlib.h>
    4343#include <str.h>
     44
    4445#include "sroute.h"
    4546#include "inetsrv.h"
    4647#include "inet_link.h"
     48#include "inet_util.h"
    4749
    4850static FIBRIL_MUTEX_INITIALIZE(sroute_list_lock);
     
    9597inet_sroute_t *inet_sroute_find(inet_addr_t *addr)
    9698{
    97         uint16_t addr_af = inet_addr_get(addr, NULL, NULL);
    98        
    99         inet_sroute_t *best = NULL;
    100         uint8_t best_bits = 0;
    101        
    102         fibril_mutex_lock(&sroute_list_lock);
    103        
    104         list_foreach(sroute_list, link) {
    105                 inet_sroute_t *sroute = list_get_instance(link,
    106                     inet_sroute_t, sroute_list);
    107                
    108                 uint8_t dest_bits;
    109                 uint16_t dest_af = inet_naddr_get(&sroute->dest, NULL, NULL,
    110                     &dest_bits);
    111                
    112                 /* Skip comparison with different address family */
    113                 if (addr_af != dest_af)
     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
     112                /* Look for the most specific route */
     113                if (best != NULL && best->dest.bits >= sroute->dest.bits)
    114114                        continue;
    115                
    116                 /* Look for the most specific route */
    117                 if ((best != NULL) && (best_bits >= dest_bits))
    118                         continue;
    119                
    120                 if (inet_naddr_compare_mask(&sroute->dest, addr)) {
    121                         log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_sroute_find: found candidate %p",
     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",
    122120                            sroute);
    123                        
    124                         best = sroute;
    125                         best_bits = dest_bits;
     121                        return sroute;
    126122                }
    127123        }
    128        
    129         if (best == NULL)
    130                 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_sroute_find: Not found");
    131        
    132         fibril_mutex_unlock(&sroute_list_lock);
    133        
    134         return best;
     124
     125        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_sroute_find: Not found");
     126        fibril_mutex_unlock(&sroute_list_lock);
     127
     128        return NULL;
    135129}
    136130
Note: See TracChangeset for help on using the changeset viewer.