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. ...@@ -23,7 +23,6 @@ THE SOFTWARE.
#define MAXROUTES 512 #define MAXROUTES 512
#define MAXSRCS 256 #define MAXSRCS 256
#define MAXNEIGHBOURS 64 #define MAXNEIGHBOURS 64
#define MAXNETS 16
#define MAXXROUTES 64 #define MAXXROUTES 64
#define INFINITY ((unsigned short)(~0)) #define INFINITY ((unsigned short)(~0))
......
...@@ -38,20 +38,30 @@ THE SOFTWARE. ...@@ -38,20 +38,30 @@ THE SOFTWARE.
#include "route.h" #include "route.h"
#include "filter.h" #include "filter.h"
struct network nets[MAXNETS]; struct network *networks = NULL;
int numnets = 0;
static struct network *
last_network(void)
{
struct network *net = networks;
if(!net)
return NULL;
while(net->next)
net = net->next;
return net;
}
struct network * struct network *
add_network(char *ifname) add_network(char *ifname)
{ {
struct network *net; struct network *net;
if(numnets >= MAXNETS) { net = malloc(sizeof(struct network));
fprintf(stderr, "Too many networks.\n"); if(net == NULL)
return NULL; return NULL;
}
net = &nets[numnets];
memset(net, 0, sizeof(struct network)); memset(net, 0, sizeof(struct network));
net->up = 0; net->up = 0;
...@@ -65,7 +75,11 @@ add_network(char *ifname) ...@@ -65,7 +75,11 @@ add_network(char *ifname)
net->bucket_time = now.tv_sec; net->bucket_time = now.tv_sec;
net->bucket = BUCKET_TOKENS_MAX; net->bucket = BUCKET_TOKENS_MAX;
net->hello_seqno = (random() & 0xFFFF); net->hello_seqno = (random() & 0xFFFF);
numnets++;
if(networks == NULL)
networks = net;
else
last_network()->next = net;
return net; return net;
} }
......
...@@ -21,6 +21,7 @@ THE SOFTWARE. ...@@ -21,6 +21,7 @@ THE SOFTWARE.
*/ */
struct network { struct network {
struct network *next;
int up; int up;
unsigned int ifindex; unsigned int ifindex;
int wired; int wired;
...@@ -45,10 +46,10 @@ struct network { ...@@ -45,10 +46,10 @@ struct network {
unsigned int self_update_interval; unsigned int self_update_interval;
}; };
extern struct network nets[MAXNETS]; extern struct network *networks;
extern int numnets; 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); struct network *add_network(char *ifname);
int network_idle(struct network *net); 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