summaryrefslogtreecommitdiff
path: root/src/ipcpd/unicast/pol/link_state.c
diff options
context:
space:
mode:
authorDimitri Staessens <[email protected]>2020-02-15 10:07:56 +0100
committerSander Vrijders <[email protected]>2020-02-16 18:24:50 +0100
commit8d38af64d1d34bff9b2548df29f3a680cdfbb0c6 (patch)
treeaec969fb9a59676f728c7d72e15fe5580d07d27e /src/ipcpd/unicast/pol/link_state.c
parent35a9691c41f7fa69a4631b39547c8fa147b044f5 (diff)
downloadouroboros-8d38af64d1d34bff9b2548df29f3a680cdfbb0c6.tar.gz
ouroboros-8d38af64d1d34bff9b2548df29f3a680cdfbb0c6.zip
ipcpd: Fix minor things in graph and link_state
The vertex was used before definition in the graph implementation. Fixed potential data race in link_state algorithm. Added missing asserts. Removed initialization of variables where not needed to let compiler warn about uninitialized uses. Signed-off-by: Dimitri Staessens <[email protected]> Signed-off-by: Sander Vrijders <[email protected]>
Diffstat (limited to 'src/ipcpd/unicast/pol/link_state.c')
-rw-r--r--src/ipcpd/unicast/pol/link_state.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/ipcpd/unicast/pol/link_state.c b/src/ipcpd/unicast/pol/link_state.c
index 4ddebd51..e2656a98 100644
--- a/src/ipcpd/unicast/pol/link_state.c
+++ b/src/ipcpd/unicast/pol/link_state.c
@@ -144,6 +144,8 @@ static int str_adj(struct adjacency * adj,
char seqnobuf[64];
struct tm * tm;
+ assert(adj);
+
if (len < LS_ENTRY_SIZE)
return -1;
@@ -183,6 +185,9 @@ static int lsdb_getattr(const char * path,
struct adjacency * adj;
struct timespec now;
+ assert(path);
+ assert(st);
+
clock_gettime(CLOCK_REALTIME_COARSE, &now);
pthread_rwlock_rdlock(&ls.db_lock);
@@ -213,6 +218,8 @@ static int lsdb_read(const char * path,
struct adjacency * a;
int size;
+ assert(path);
+
pthread_rwlock_rdlock(&ls.db_lock);
if (ls.db_len + ls.nbs_len == 0)
@@ -240,6 +247,8 @@ static int lsdb_readdir(char *** buf)
char entry[RIB_PATH_LEN + 1];
ssize_t idx = 0;
+ assert(buf);
+
pthread_rwlock_rdlock(&ls.db_lock);
if (ls.db_len + ls.nbs_len == 0) {
@@ -348,8 +357,8 @@ static int lsdb_add_nb(uint64_t addr,
return 0;
}
-static int lsdb_del_nb(uint64_t addr,
- int fd)
+static int lsdb_del_nb(uint64_t addr,
+ int fd)
{
struct list_head * p;
struct list_head * h;
@@ -377,14 +386,16 @@ static int lsdb_del_nb(uint64_t addr,
static int nbr_to_fd(uint64_t addr)
{
struct list_head * p;
+ int fd;
pthread_rwlock_rdlock(&ls.db_lock);
list_for_each(p, &ls.nbs) {
struct nb * nb = list_entry(p, struct nb, next);
if (nb->addr == addr && nb->type == NB_DT) {
+ fd = nb->fd;
pthread_rwlock_unlock(&ls.db_lock);
- return nb->fd;
+ return fd;
}
}
@@ -401,6 +412,8 @@ static void calculate_pff(struct routing_i * instance)
struct list_head * q;
int fds[PROG_MAX_FLOWS];
+ assert(instance);
+
if (graph_routing_table(ls.graph, ls.routing_algo,
ipcpi.dt_addr, &table))
return;
@@ -460,6 +473,8 @@ static int lsdb_add_link(uint64_t src,
struct timespec now;
int ret = -1;
+ assert(qs);
+
clock_gettime(CLOCK_REALTIME_COARSE, &now);
pthread_rwlock_wrlock(&ls.db_lock);
@@ -537,7 +552,11 @@ static int lsdb_del_link(uint64_t src,
static void * periodic_recalc_pff(void * o)
{
bool modified;
- struct routing_i * inst = (struct routing_i *) o;
+ struct routing_i * inst;
+
+ assert(o);
+
+ inst = (struct routing_i *) o;
while (true) {
pthread_mutex_lock(&inst->lock);
@@ -547,6 +566,7 @@ static void * periodic_recalc_pff(void * o)
if (modified)
calculate_pff(inst);
+
sleep(RECALC_TIME);
}
@@ -783,6 +803,8 @@ static void handle_event(void * self,
(void) self;
+ assert(o);
+
c = (struct conn *) o;
memset(&qs, 0, sizeof(qs));