~ubuntu-branches/ubuntu/trusty/batmand/trusty

« back to all changes in this revision

Viewing changes to batman.h

  • Committer: Bazaar Package Importer
  • Author(s): Holger Levsen
  • Date: 2007-11-26 09:10:49 UTC
  • Revision ID: james.westby@ubuntu.com-20071126091049-9fqg546f2c4ct759
Tags: upstream-0.2
ImportĀ upstreamĀ versionĀ 0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2006 B.A.T.M.A.N. contributors:
 
3
 * Thomas Lopatic, Corinna 'Elektra' Aichele, Axel Neumann, Marek Lindner
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of version 2 of the GNU General Public
 
6
 * License as published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
11
 * General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program; if not, write to the Free Software
 
15
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
16
 * 02110-1301, USA
 
17
 *
 
18
 */
 
19
 
 
20
 
 
21
 
 
22
#ifndef _BATMAN_BATMAN_H
 
23
#define _BATMAN_BATMAN_H
 
24
 
 
25
#include <sys/types.h>
 
26
#include <netinet/in.h>
 
27
#include <pthread.h>
 
28
#include <sys/un.h>
 
29
#include <stdint.h>
 
30
#include "list.h"
 
31
#include "bitarray.h"
 
32
#include "hash.h"
 
33
#include "allocate.h"
 
34
#include "profile.h"
 
35
 
 
36
 
 
37
 
 
38
#define SOURCE_VERSION "0.2"  //put exactly one distinct word inside the string like "0.3-pre-alpha" or "0.3-rc1" or "0.3"
 
39
 
 
40
#ifndef REVISION_VERSION
 
41
#define REVISION_VERSION "0"
 
42
#endif
 
43
 
 
44
#define COMPAT_VERSION 3
 
45
#define PORT 1966
 
46
#define UNIDIRECTIONAL 0x80
 
47
#define DIRECTLINK 0x40
 
48
#define ADDR_STR_LEN 16
 
49
 
 
50
#define UNIX_PATH "/var/run/batmand.socket"
 
51
 
 
52
/* #define PROFILE_DATA */
 
53
 
 
54
 
 
55
/*
 
56
 * No configuration files or fancy command line switches yet
 
57
 * To experiment with B.A.T.M.A.N. settings change them here
 
58
 * and recompile the code
 
59
 * Here is the stuff you may want to play with:
 
60
 */
 
61
 
 
62
#define JITTER 100
 
63
#define TTL 50                /* Time To Live of broadcast messages */
 
64
#define BIDIRECT_TIMEOUT 2
 
65
#define PURGE_TIMEOUT 200000  /* purge originators after time in ms if no valid packet comes in -> TODO: check influence on SEQ_RANGE */
 
66
#define SEQ_RANGE 128         /* sliding packet range of received orginator messages in squence numbers (should be a multiple of our word size) */
 
67
 
 
68
 
 
69
 
 
70
#define NUM_WORDS ( SEQ_RANGE / WORD_BIT_SIZE ) + ( ( SEQ_RANGE % WORD_BIT_SIZE > 0)? 1 : 0 )
 
71
 
 
72
 
 
73
 
 
74
 
 
75
extern uint8_t debug_level;
 
76
extern uint8_t gateway_class;
 
77
extern uint8_t routing_class;
 
78
extern uint8_t num_hna;
 
79
extern int16_t orginator_interval;
 
80
extern uint32_t pref_gateway;
 
81
 
 
82
extern unsigned char *hna_buff;
 
83
 
 
84
extern struct gw_node *curr_gateway;
 
85
extern pthread_t curr_gateway_thread_id;
 
86
extern pthread_mutex_t curr_gw_mutex;
 
87
 
 
88
extern uint8_t found_ifs;
 
89
extern int32_t receive_max_sock;
 
90
extern fd_set receive_wait_set;
 
91
 
 
92
extern uint8_t unix_client;
 
93
 
 
94
extern struct hashtable_t *orig_hash;
 
95
 
 
96
extern struct list_head if_list;
 
97
extern struct list_head hna_list;
 
98
extern struct list_head gw_list;
 
99
extern struct list_head forw_list;
 
100
extern struct vis_if vis_if;
 
101
extern struct unix_if unix_if;
 
102
extern struct debug_clients debug_clients;
 
103
 
 
104
extern char *gw2string[];
 
105
 
 
106
struct packet
 
107
{
 
108
        uint32_t orig;
 
109
        uint8_t  flags;    /* 0x80: UNIDIRECTIONAL link, 0x40: DIRECTLINK flag, ... */
 
110
        uint8_t  ttl;
 
111
        uint16_t seqno;
 
112
        uint8_t  gwflags;  /* flags related to gateway functions: gateway class */
 
113
        uint8_t  version;  /* batman version field */
 
114
} __attribute__((packed));
 
115
 
 
116
struct orig_node                 /* structure for orig_list maintaining nodes of mesh */
 
117
{
 
118
        uint32_t orig;
 
119
        struct neigh_node *router;
 
120
        struct batman_if *batman_if;
 
121
        uint16_t *bidirect_link;    /* if node is a bidrectional neighbour, when my originator packet was broadcasted (replied) by this node and received by me */
 
122
        uint32_t last_valid;        /* when last packet from this node was received */
 
123
        uint8_t  gwflags;           /* flags related to gateway functions: gateway class */
 
124
        unsigned char *hna_buff;
 
125
        int16_t  hna_buff_len;
 
126
        uint16_t last_seqno;        /* last and best known squence number */
 
127
        struct list_head neigh_list;
 
128
};
 
129
 
 
130
struct neigh_node
 
131
{
 
132
        struct list_head list;
 
133
        uint32_t addr;
 
134
        uint8_t packet_count;
 
135
        uint8_t  last_ttl;         /* ttl of last received packet */
 
136
        uint32_t last_valid;       /* when last packet via this neighbour was received */
 
137
        TYPE_OF_WORD seq_bits[ NUM_WORDS ];
 
138
        struct batman_if *if_incoming;
 
139
};
 
140
 
 
141
struct hna_node
 
142
{
 
143
        struct list_head list;
 
144
        uint32_t addr;
 
145
        uint16_t netmask;
 
146
};
 
147
 
 
148
struct forw_node                 /* structure for forw_list maintaining packets to be send/forwarded */
 
149
{
 
150
        struct list_head list;
 
151
        uint32_t send_time;
 
152
        uint8_t  own;
 
153
        unsigned char *pack_buff;
 
154
        int32_t  pack_buff_len;
 
155
        struct batman_if *if_outgoing;
 
156
};
 
157
 
 
158
struct gw_node
 
159
{
 
160
        struct list_head list;
 
161
        struct orig_node *orig_node;
 
162
        uint16_t unavail_factor;
 
163
        uint32_t last_failure;
 
164
        uint32_t deleted;
 
165
};
 
166
 
 
167
struct batman_if
 
168
{
 
169
        struct list_head list;
 
170
        char *dev;
 
171
        int32_t udp_send_sock;
 
172
        int32_t udp_recv_sock;
 
173
        int32_t tcp_gw_sock;
 
174
        int32_t tunnel_sock;
 
175
        int16_t if_num;
 
176
        uint8_t if_rp_filter_old;
 
177
        uint8_t if_send_redirects_old;
 
178
        pthread_t listen_thread_id;
 
179
        struct sockaddr_in addr;
 
180
        struct sockaddr_in broad;
 
181
        struct packet out;
 
182
        struct list_head client_list;
 
183
};
 
184
 
 
185
struct gw_client
 
186
{
 
187
        struct list_head list;
 
188
        struct batman_if *batman_if;
 
189
        int32_t sock;
 
190
        uint32_t last_keep_alive;
 
191
        struct sockaddr_in addr;
 
192
};
 
193
 
 
194
struct vis_if {
 
195
        int32_t sock;
 
196
        struct sockaddr_in addr;
 
197
};
 
198
 
 
199
struct unix_if {
 
200
        int32_t unix_sock;
 
201
        pthread_t listen_thread_id;
 
202
        struct sockaddr_un addr;
 
203
        struct list_head client_list;
 
204
};
 
205
 
 
206
struct unix_client {
 
207
        struct list_head list;
 
208
        int32_t sock;
 
209
        uint8_t debug_level;
 
210
};
 
211
 
 
212
struct debug_clients {
 
213
        void *fd_list[4];
 
214
        int16_t clients_num[4];
 
215
        pthread_mutex_t *mutex[4];
 
216
};
 
217
 
 
218
struct debug_level_info {
 
219
        struct list_head list;
 
220
        int32_t fd;
 
221
};
 
222
 
 
223
struct curr_gw_data {
 
224
        unsigned int orig;
 
225
        struct gw_node *gw_node;
 
226
        struct batman_if *batman_if;
 
227
};
 
228
 
 
229
 
 
230
int8_t batman( void );
 
231
void usage( void );
 
232
void verbose_usage( void );
 
233
void update_routes( struct orig_node *orig_node, struct neigh_node *neigh_node, unsigned char *hna_recv_buff, int16_t hna_buff_len );
 
234
void update_gw_list( struct orig_node *orig_node, uint8_t new_gwflags );
 
235
void choose_gw();
 
236
 
 
237
 
 
238
#endif