~ubuntu-branches/ubuntu/utopic/babeld/utopic-proposed

« back to all changes in this revision

Viewing changes to neighbour.c

  • Committer: Package Import Robot
  • Author(s): Stéphane Glondu
  • Date: 2011-12-08 20:49:12 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20111208204912-oiizndrm9va3aplf
Tags: 1.3.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
#include "babeld.h"
30
30
#include "util.h"
31
 
#include "network.h"
 
31
#include "interface.h"
32
32
#include "neighbour.h"
33
33
#include "source.h"
34
34
#include "route.h"
39
39
struct neighbour *neighs = NULL;
40
40
 
41
41
static struct neighbour *
42
 
find_neighbour_nocreate(const unsigned char *address, struct network *net)
 
42
find_neighbour_nocreate(const unsigned char *address, struct interface *ifp)
43
43
{
44
44
    struct neighbour *neigh;
45
45
    FOR_ALL_NEIGHBOURS(neigh) {
46
46
        if(memcmp(address, neigh->address, 16) == 0 &&
47
 
           neigh->network == net)
 
47
           neigh->ifp == ifp)
48
48
            return neigh;
49
49
    }
50
50
    return NULL;
71
71
}
72
72
 
73
73
struct neighbour *
74
 
find_neighbour(const unsigned char *address, struct network *net)
 
74
find_neighbour(const unsigned char *address, struct interface *ifp)
75
75
{
76
76
    struct neighbour *neigh;
77
77
    const struct timeval zero = {0, 0};
78
78
 
79
 
    neigh = find_neighbour_nocreate(address, net);
 
79
    neigh = find_neighbour_nocreate(address, ifp);
80
80
    if(neigh)
81
81
        return neigh;
82
82
 
83
83
    debugf("Creating neighbour %s on %s.\n",
84
 
           format_address(address), net->ifname);
 
84
           format_address(address), ifp->name);
85
85
 
86
86
    neigh = malloc(sizeof(struct neighbour));
87
87
    if(neigh == NULL) {
97
97
    neigh->hello_time = zero;
98
98
    neigh->hello_interval = 0;
99
99
    neigh->ihu_interval = 0;
100
 
    neigh->network = net;
 
100
    neigh->ifp = ifp;
101
101
    neigh->next = neighs;
102
102
    neighs = neigh;
103
103
    local_notify_neighbour(neigh, LOCAL_ADD);
104
 
    send_hello(net);
 
104
    send_hello(ifp);
105
105
    return neigh;
106
106
}
107
107
 
174
174
    /* Make sure to give neighbours some feedback early after association */
175
175
    if((neigh->reach & 0xBF00) == 0x8000) {
176
176
        /* A new neighbour */
177
 
        send_hello(neigh->network);
 
177
        send_hello(neigh->ifp);
178
178
    } else {
179
179
        /* Don't send hellos, in order to avoid a positive feedback loop. */
180
180
        int a = (neigh->reach & 0xC000);
181
181
        int b = (neigh->reach & 0x3000);
182
182
        if((a == 0xC000 && b == 0) || (a == 0 && b == 0x3000)) {
183
183
            /* Reachability is either 1100 or 0011 */
184
 
            send_self_update(neigh->network);
 
184
            send_self_update(neigh->ifp);
185
185
        }
186
186
    }
187
187
 
269
269
 
270
270
    if((reach & 0xFFF0) == 0 || delay >= 180000) {
271
271
        return INFINITY;
272
 
    } else if((neigh->network->flags & NET_LQ)) {
 
272
    } else if((neigh->ifp->flags & IF_LQ)) {
273
273
        int sreach =
274
274
            ((reach & 0x8000) >> 2) +
275
275
            ((reach & 0x4000) >> 1) +
276
276
            (reach & 0x3FFF);
277
277
        /* 0 <= sreach <= 0x7FFF */
278
 
        int cost = (0x8000 * neigh->network->cost) / (sreach + 1);
279
 
        /* cost >= network->cost */
 
278
        int cost = (0x8000 * neigh->ifp->cost) / (sreach + 1);
 
279
        /* cost >= interface->cost */
280
280
        if(delay >= 40000)
281
281
            cost = (cost * (delay - 20000) + 10000) / 20000;
282
282
        return MIN(cost, INFINITY);
283
283
    } else {
284
284
        /* To lose one hello is a misfortune, to lose two is carelessness. */
285
285
        if((reach & 0xC000) == 0xC000)
286
 
            return neigh->network->cost;
 
286
            return neigh->ifp->cost;
287
287
        else if((reach & 0xC000) == 0)
288
288
            return INFINITY;
289
289
        else if((reach & 0x2000))
290
 
            return neigh->network->cost;
 
290
            return neigh->ifp->cost;
291
291
        else
292
292
            return INFINITY;
293
293
    }
298
298
{
299
299
    unsigned a, b;
300
300
 
301
 
    if(!net_up(neigh->network))
 
301
    if(!if_up(neigh->ifp))
302
302
        return INFINITY;
303
303
 
304
304
    a = neighbour_txcost(neigh);
310
310
    if(b >= INFINITY)
311
311
        return INFINITY;
312
312
 
313
 
    if(!(neigh->network->flags & NET_LQ) || (a <= 256 && b <= 256)) {
 
313
    if(!(neigh->ifp->flags & IF_LQ) || (a < 256 && b < 256)) {
314
314
        return a;
315
315
    } else {
316
316
        /* a = 256/alpha, b = 256/beta, where alpha and beta are the expected