~ubuntu-branches/ubuntu/precise/babeld/precise

« back to all changes in this revision

Viewing changes to network.h

  • 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:
1
 
/*
2
 
Copyright (c) 2007, 2008 by Juliusz Chroboczek
3
 
 
4
 
Permission is hereby granted, free of charge, to any person obtaining a copy
5
 
of this software and associated documentation files (the "Software"), to deal
6
 
in the Software without restriction, including without limitation the rights
7
 
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
 
copies of the Software, and to permit persons to whom the Software is
9
 
furnished to do so, subject to the following conditions:
10
 
 
11
 
The above copyright notice and this permission notice shall be included in
12
 
all copies or substantial portions of the Software.
13
 
 
14
 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
 
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
 
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17
 
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
 
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
 
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
 
THE SOFTWARE.
21
 
*/
22
 
 
23
 
struct buffered_update {
24
 
    unsigned char id[8];
25
 
    unsigned char prefix[16];
26
 
    unsigned char plen;
27
 
    unsigned char pad[3];
28
 
};
29
 
 
30
 
struct network_conf {
31
 
    char *ifname;
32
 
    unsigned hello_interval;
33
 
    unsigned update_interval;
34
 
    unsigned short cost;
35
 
    char wired;
36
 
    char split_horizon;
37
 
    char lq;
38
 
    char faraway;
39
 
    int channel;
40
 
    struct network_conf *next;
41
 
};
42
 
 
43
 
#define CONFIG_DEFAULT 0
44
 
#define CONFIG_NO 1
45
 
#define CONFIG_YES 2
46
 
 
47
 
#define NET_UP (1 << 0)
48
 
#define NET_WIRED (1<<1)
49
 
#define NET_SPLIT_HORIZON (1 << 2)
50
 
#define NET_LQ (1 << 3)
51
 
#define NET_FARAWAY (1 << 4)
52
 
 
53
 
/* Only INTERFERING can appear on the wire. */
54
 
#define NET_CHANNEL_UNKNOWN 0
55
 
#define NET_CHANNEL_INTERFERING 255
56
 
#define NET_CHANNEL_NONINTERFERING -2
57
 
 
58
 
struct network {
59
 
    struct network *next;
60
 
    struct network_conf *conf;
61
 
    unsigned int ifindex;
62
 
    unsigned short flags;
63
 
    unsigned short cost;
64
 
    int channel;
65
 
    struct timeval hello_timeout;
66
 
    struct timeval update_timeout;
67
 
    struct timeval flush_timeout;
68
 
    struct timeval update_flush_timeout;
69
 
    char ifname[IF_NAMESIZE];
70
 
    unsigned char *ipv4;
71
 
    int numll;
72
 
    unsigned char (*ll)[16];
73
 
    int buffered;
74
 
    int bufsize;
75
 
    char have_buffered_hello;
76
 
    char have_buffered_id;
77
 
    char have_buffered_nh;
78
 
    char have_buffered_prefix;
79
 
    unsigned char buffered_id[16];
80
 
    unsigned char buffered_nh[4];
81
 
    unsigned char buffered_prefix[16];
82
 
    unsigned char *sendbuf;
83
 
    struct buffered_update *buffered_updates;
84
 
    int num_buffered_updates;
85
 
    int update_bufsize;
86
 
    time_t bucket_time;
87
 
    unsigned int bucket;
88
 
    time_t activity_time;
89
 
    unsigned short hello_seqno;
90
 
    unsigned hello_interval;
91
 
    unsigned update_interval;
92
 
};
93
 
 
94
 
#define NET_CONF(_net, _field) \
95
 
    ((_net)->conf ? (_net)->conf->_field : 0)
96
 
 
97
 
extern struct network *networks;
98
 
extern int numnets;
99
 
 
100
 
#define FOR_ALL_NETS(_net) for(_net = networks; _net; _net = _net->next)
101
 
 
102
 
static inline int
103
 
net_up(struct network *net)
104
 
{
105
 
    return !!(net->flags & NET_UP);
106
 
}
107
 
 
108
 
struct network *add_network(char *ifname, struct network_conf *conf);
109
 
int network_idle(struct network *net);
110
 
int update_hello_interval(struct network *net);
111
 
unsigned jitter(struct network *net, int urgent);
112
 
unsigned update_jitter(struct network *net, int urgent);
113
 
void set_timeout(struct timeval *timeout, int msecs);
114
 
int network_up(struct network *net, int up);
115
 
int network_ll_address(struct network *net, const unsigned char *address);
116
 
void check_networks(void);