Commit 570a7e3f authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Switch to using a linked list for the list of networks.

parent c98f3b55
......@@ -23,7 +23,6 @@ THE SOFTWARE.
#define MAXROUTES 512
#define MAXSRCS 256
#define MAXNEIGHBOURS 64
#define MAXNETS 16
#define MAXXROUTES 64
#define INFINITY ((unsigned short)(~0))
......
......@@ -38,20 +38,30 @@ THE SOFTWARE.
#include "route.h"
#include "filter.h"
struct network nets[MAXNETS];
int numnets = 0;
struct network *networks = NULL;
static struct network *
last_network(void)
{
struct network *net = networks;
if(!net)
return NULL;
while(net->next)
net = net->next;
return net;
}
struct network *
add_network(char *ifname)
{
struct network *net;
if(numnets >= MAXNETS) {
fprintf(stderr, "Too many networks.\n");
net = malloc(sizeof(struct network));
if(net == NULL)
return NULL;
}
net = &nets[numnets];
memset(net, 0, sizeof(struct network));
net->up = 0;
......@@ -65,7 +75,11 @@ add_network(char *ifname)
net->bucket_time = now.tv_sec;
net->bucket = BUCKET_TOKENS_MAX;
net->hello_seqno = (random() & 0xFFFF);
numnets++;
if(networks == NULL)
networks = net;
else
last_network()->next = net;
return net;
}
......
......@@ -21,6 +21,7 @@ THE SOFTWARE.
*/
struct network {
struct network *next;
int up;
unsigned int ifindex;
int wired;
......@@ -45,10 +46,10 @@ struct network {
unsigned int self_update_interval;
};
extern struct network nets[MAXNETS];
extern struct network *networks;
extern int numnets;
#define FOR_ALL_NETS(_net) for(_net = nets; _net < nets + numnets; _net++)
#define FOR_ALL_NETS(_net) for(_net = networks; _net; _net = _net->next)
struct network *add_network(char *ifname);
int network_idle(struct network *net);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment