static void test_free(void) { struct filter_desc_list_t list; CU_ASSERT_EQUAL(filterlist_free(NULL), -1); CU_ASSERT_EQUAL(filterlist_init(&list), 0); CU_ASSERT_EQUAL(filterlist_free(&list), 0); list.num = 1; list.data = (struct filter_desc_t *)malloc(sizeof(struct filter_desc_t)); CU_ASSERT_EQUAL(filterlist_free(&list), 0); CU_ASSERT_EQUAL(list.num, 0); CU_ASSERT_EQUAL(list.data, NULL); }
static void test_find(void) { struct filter_desc_list_t list; struct filter_desc_t desc; const struct filter_desc_t const * desc_new; CU_ASSERT_EQUAL(filterlist_init(&list), 0); CU_ASSERT_EQUAL(filterlist_find(NULL, NULL), NULL); CU_ASSERT_EQUAL(filterlist_find(&list, NULL), NULL); CU_ASSERT_EQUAL(filterlist_find(NULL, ""), NULL); CU_ASSERT_EQUAL(filterlist_find(&list, ""), NULL); memset(&desc, 0, sizeof(desc)); desc.name = "name"; CU_ASSERT_EQUAL(filterlist_init(&list), 0); CU_ASSERT_EQUAL(list.num, 0); CU_ASSERT_EQUAL(filterlist_append(&list, &desc), 0); CU_ASSERT_EQUAL(list.num, 1); CU_ASSERT_EQUAL(filterlist_find(&list, "test"), NULL); desc_new = filterlist_find(&list, "name"); CU_ASSERT_NOT_EQUAL(desc_new, NULL); CU_ASSERT_STRING_EQUAL(desc_new->name, "name"); CU_ASSERT_EQUAL(filterlist_free(&list), 0); CU_ASSERT_EQUAL(list.num, 0); CU_ASSERT_EQUAL(list.data, NULL); }
void free_config(struct bgpd_config *conf) { struct listen_addr *la; struct mrt *m; free_rdomains(&conf->rdomains); free_networks(&conf->networks); filterlist_free(conf->filters); while ((la = TAILQ_FIRST(conf->listen_addrs)) != NULL) { TAILQ_REMOVE(conf->listen_addrs, la, entry); free(la); } free(conf->listen_addrs); while ((m = LIST_FIRST(conf->mrt)) != NULL) { LIST_REMOVE(m, entry); free(m); } free(conf->mrt); free(conf->csock); free(conf->rcsock); free(conf); }
static void test_append(void) { struct filter_desc_list_t list; struct filter_desc_t desc; CU_ASSERT_EQUAL(filterlist_init(&list), 0); CU_ASSERT_EQUAL(filterlist_append(NULL, NULL), -1); CU_ASSERT_EQUAL(filterlist_append(&list, NULL), -1); CU_ASSERT_EQUAL(filterlist_append(NULL, &desc), -1); CU_ASSERT_EQUAL(filterlist_append(&list, &desc), 0); CU_ASSERT_EQUAL(filterlist_free(&list), 0); memset(&desc, 0, sizeof(desc)); CU_ASSERT_EQUAL(filterlist_init(&list), 0); CU_ASSERT_EQUAL(list.num, 0); CU_ASSERT_EQUAL(filterlist_append(&list, &desc), 0); CU_ASSERT_EQUAL(list.num, 1); CU_ASSERT_EQUAL(filterlist_append(&list, &desc), 0); CU_ASSERT_EQUAL(list.num, 2); CU_ASSERT_EQUAL(filterlist_free(&list), 0); }
int merge_config(struct bgpd_config *xconf, struct bgpd_config *conf, struct peer *peer_l) { struct listen_addr *nla, *ola, *next; struct network *n; struct rdomain *rd; /* * merge the freshly parsed conf into the running xconf */ if (!conf->as) { log_warnx("configuration error: AS not given"); return (1); } if ((conf->flags & BGPD_FLAG_REFLECTOR) && conf->clusterid == 0) conf->clusterid = conf->bgpid; /* adjust FIB priority if changed */ /* if xconf is uninitialized we get RTP_NONE */ if (xconf->fib_priority != conf->fib_priority) { kr_fib_decouple_all(xconf->fib_priority); kr_fib_update_prio_all(conf->fib_priority); kr_fib_couple_all(conf->fib_priority); } /* take over the easy config changes */ xconf->flags = conf->flags; xconf->log = conf->log; xconf->bgpid = conf->bgpid; xconf->clusterid = conf->clusterid; xconf->as = conf->as; xconf->short_as = conf->short_as; xconf->holdtime = conf->holdtime; xconf->min_holdtime = conf->min_holdtime; xconf->connectretry = conf->connectretry; xconf->fib_priority = conf->fib_priority; /* clear old control sockets and use new */ free(xconf->csock); free(xconf->rcsock); xconf->csock = conf->csock; xconf->rcsock = conf->rcsock; /* set old one to NULL so we don't double free */ conf->csock = NULL; conf->rcsock = NULL; /* clear all current filters and take over the new ones */ filterlist_free(xconf->filters); xconf->filters = conf->filters; conf->filters = NULL; /* switch the network statements, but first remove the old ones */ free_networks(&xconf->networks); while ((n = TAILQ_FIRST(&conf->networks)) != NULL) { TAILQ_REMOVE(&conf->networks, n, entry); TAILQ_INSERT_TAIL(&xconf->networks, n, entry); } /* switch the rdomain configs, first remove the old ones */ free_rdomains(&xconf->rdomains); while ((rd = SIMPLEQ_FIRST(&conf->rdomains)) != NULL) { SIMPLEQ_REMOVE_HEAD(&conf->rdomains, entry); SIMPLEQ_INSERT_TAIL(&xconf->rdomains, rd, entry); } /* * merge new listeners: * -flag all existing ones as to be deleted * -those that are in both new and old: flag to keep * -new ones get inserted and flagged as to reinit * -remove all that are still flagged for deletion */ TAILQ_FOREACH(nla, xconf->listen_addrs, entry) nla->reconf = RECONF_DELETE; /* no new listeners? preserve default ones */ if (TAILQ_EMPTY(conf->listen_addrs)) TAILQ_FOREACH(ola, xconf->listen_addrs, entry) if (ola->flags & DEFAULT_LISTENER) ola->reconf = RECONF_KEEP; /* else loop over listeners and merge configs */ for (nla = TAILQ_FIRST(conf->listen_addrs); nla != NULL; nla = next) { next = TAILQ_NEXT(nla, entry); TAILQ_FOREACH(ola, xconf->listen_addrs, entry) if (!memcmp(&nla->sa, &ola->sa, sizeof(nla->sa))) break; if (ola == NULL) { /* new listener, copy over */ TAILQ_REMOVE(conf->listen_addrs, nla, entry); TAILQ_INSERT_TAIL(xconf->listen_addrs, nla, entry); nla->reconf = RECONF_REINIT; } else /* exists, just flag */ ola->reconf = RECONF_KEEP; } /* finally clean up the original list and remove all stale entires */ for (nla = TAILQ_FIRST(xconf->listen_addrs); nla != NULL; nla = next) { next = TAILQ_NEXT(nla, entry); if (nla->reconf == RECONF_DELETE) { TAILQ_REMOVE(xconf->listen_addrs, nla, entry); free(nla); } } /* conf is merged so free it */ free_config(conf); return (0); }