diff options
Diffstat (limited to 'src/ipcpd/unicast')
-rw-r--r-- | src/ipcpd/unicast/addr-auth/flat.c | 22 | ||||
-rw-r--r-- | src/ipcpd/unicast/dir/dht.c | 8 | ||||
-rw-r--r-- | src/ipcpd/unicast/dt.c | 23 | ||||
-rw-r--r-- | src/ipcpd/unicast/fa.c | 3 | ||||
-rw-r--r-- | src/ipcpd/unicast/main.c | 27 | ||||
-rw-r--r-- | src/ipcpd/unicast/routing/link-state.c | 17 |
6 files changed, 54 insertions, 46 deletions
diff --git a/src/ipcpd/unicast/addr-auth/flat.c b/src/ipcpd/unicast/addr-auth/flat.c index c4562935..dfdeccd6 100644 --- a/src/ipcpd/unicast/addr-auth/flat.c +++ b/src/ipcpd/unicast/addr-auth/flat.c @@ -35,13 +35,13 @@ #include "flat.h" #define NAME_LEN 8 +#define INVALID_ADDRESS 0 struct { - uint8_t addr_size; + uint8_t addr_size; + uint32_t addr; } flat; -#define INVALID_ADDRESS 0 - struct addr_auth_ops flat_ops = { .init = flat_init, .fini = flat_fini, @@ -57,6 +57,12 @@ int flat_init(const void * info) return -1; } +#if defined (CONFIG_OUROBOROS_DEBUG) && defined (IPCP_DEBUG_LOCAL) + flat.addr = getpid(); +#else + while (flat.addr == INVALID_ADDRESS) + random_buffer(&flat.addr,sizeof(flat.addr)); +#endif return 0; } @@ -67,13 +73,5 @@ int flat_fini(void) uint64_t flat_address(void) { - uint32_t addr = INVALID_ADDRESS; - -#if defined (CONFIG_OUROBOROS_DEBUG) && defined (IPCP_DEBUG_LOCAL) - addr = getpid(); -#else - while (addr == INVALID_ADDRESS) - random_buffer(&addr,sizeof(addr)); -#endif - return addr; + return (uint64_t) flat.addr; } diff --git a/src/ipcpd/unicast/dir/dht.c b/src/ipcpd/unicast/dir/dht.c index 483570e8..da39e567 100644 --- a/src/ipcpd/unicast/dir/dht.c +++ b/src/ipcpd/unicast/dir/dht.c @@ -45,6 +45,7 @@ #include <ouroboros/utils.h> #include <ouroboros/pthread.h> +#include "addr-auth.h" #include "common/connmgr.h" #include "dht.h" #include "dt.h" @@ -2258,7 +2259,7 @@ int dht_bootstrap(void * dir) pthread_rwlock_wrlock(&dht->lock); #ifndef __DHT_TEST__ - dht->b = hash_len(ipcpi.dir_hash_algo); + dht->b = ipcp_dir_hash_len(); #else dht->b = DHT_TEST_KEY_LEN; #endif @@ -2845,7 +2846,10 @@ void * dht_create(void) dht->b = 0; dht->id = NULL; #ifndef __DHT_TEST__ - dht->addr = ipcpi.dt_addr; + dht->addr = addr_auth_address(); + if (dht->addr == INVALID_ADDR) + goto fail_bmp; + dht->tpm = tpm_create(2, 1, dht_handle_packet, dht); if (dht->tpm == NULL) goto fail_tpm_create; diff --git a/src/ipcpd/unicast/dt.c b/src/ipcpd/unicast/dt.c index 2bb5ed2f..14eaac09 100644 --- a/src/ipcpd/unicast/dt.c +++ b/src/ipcpd/unicast/dt.c @@ -41,6 +41,7 @@ #include <ouroboros/fccntl.h> #endif +#include "addr-auth.h" #include "common/comp.h" #include "common/connmgr.h" #include "ca.h" @@ -144,6 +145,8 @@ static void dt_pci_shrink(struct shm_du_buff * sdb) struct { struct psched * psched; + uint64_t addr; + struct pff * pff[QOS_CUBE_MAX]; struct routing_i * routing[QOS_CUBE_MAX]; #ifdef IPCP_FLOW_STATS @@ -209,7 +212,7 @@ static int dt_rib_read(const char * path, return 0; } - if (dt.stat[fd].addr == ipcpi.dt_addr) + if (dt.stat[fd].addr == dt.addr) sprintf(addrstr, "%s", dt.comps[fd].name); else sprintf(addrstr, "%" PRIu64, dt.stat[fd].addr); @@ -454,7 +457,7 @@ static void packet_handler(int fd, head = shm_du_buff_head(sdb); dt_pci_des(head, &dt_pci); - if (dt_pci.dst_addr != ipcpi.dt_addr) { + if (dt_pci.dst_addr != dt.addr) { if (dt_pci.ttl == 0) { log_dbg("TTL was zero."); ipcp_sdb_release(sdb); @@ -575,11 +578,17 @@ int dt_init(struct dt_config cfg) memset(&info, 0, sizeof(info)); + dt.addr = addr_auth_address(); + if (dt.addr == INVALID_ADDR) { + log_err("Failed to get address"); + return -1; + } + strcpy(info.comp_name, DT_COMP); strcpy(info.protocol, DT_PROTO); info.pref_version = 1; info.pref_syntax = PROTO_FIXED; - info.addr = ipcpi.dt_addr; + info.addr = dt.addr; if (cfg.eid_size != 8) { /* only support 64 bits from now */ log_warn("Invalid EID size. Only 64 bit is supported."); @@ -647,7 +656,7 @@ int dt_init(struct dt_config cfg) dt.n_flows = 0; #endif - sprintf(dtstr, "%s.%" PRIu64, DT, ipcpi.dt_addr); + sprintf(dtstr, "%s.%" PRIu64, DT, dt.addr); if (rib_reg(dtstr, &r_ops)) { log_err("Failed to register RIB."); goto fail_rib_reg; @@ -683,7 +692,7 @@ void dt_fini(void) char dtstr[RIB_NAME_STRLEN + 1]; int i; - sprintf(dtstr, "%s.%" PRIu64, DT, ipcpi.dt_addr); + sprintf(dtstr, "%s.%" PRIu64, DT, dt.addr); rib_unreg(dtstr); #ifdef IPCP_FLOW_STATS for (i = 0; i < PROG_MAX_FLOWS; ++i) @@ -769,7 +778,7 @@ int dt_reg_comp(void * comp, pthread_rwlock_unlock(&dt.lock); #ifdef IPCP_FLOW_STATS - stat_used(eid, ipcpi.dt_addr); + stat_used(eid, dt.addr); #endif return eid; } @@ -786,7 +795,7 @@ int dt_write_packet(uint64_t dst_addr, size_t len; assert(sdb); - assert(dst_addr != ipcpi.dt_addr); + assert(dst_addr != dt.addr); len = shm_du_buff_len(sdb); diff --git a/src/ipcpd/unicast/fa.c b/src/ipcpd/unicast/fa.c index 3631fd7b..ecc3894e 100644 --- a/src/ipcpd/unicast/fa.c +++ b/src/ipcpd/unicast/fa.c @@ -41,6 +41,7 @@ #include <ouroboros/random.h> #include <ouroboros/pthread.h> +#include "addr-auth.h" #include "dir.h" #include "fa.h" #include "psched.h" @@ -765,7 +766,7 @@ int fa_alloc(int fd, msg->code = FLOW_REQ; msg->s_eid = hton64(eid); - msg->s_addr = hton64(ipcpi.dt_addr); + msg->s_addr = hton64(addr_auth_address()); msg->delay = hton32(qs.delay); msg->bandwidth = hton64(qs.bandwidth); msg->availability = qs.availability; diff --git a/src/ipcpd/unicast/main.c b/src/ipcpd/unicast/main.c index e6cb2994..bd1fee51 100644 --- a/src/ipcpd/unicast/main.c +++ b/src/ipcpd/unicast/main.c @@ -55,13 +55,8 @@ #include <assert.h> #include <inttypes.h> -struct ipcp ipcpi; - static int initialize_components(const struct ipcp_config * conf) { - strcpy(ipcpi.layer_name, conf->layer_info.name); - ipcpi.dir_hash_algo = (enum hash_algo) conf->layer_info.dir_hash_algo; - assert(ipcp_dir_hash_len() != 0); if (addr_auth_init(conf->unicast.addr_auth_type, @@ -70,13 +65,7 @@ static int initialize_components(const struct ipcp_config * conf) goto fail_addr_auth; } - ipcpi.dt_addr = addr_auth_address(); - if (ipcpi.dt_addr == 0) { - log_err("Failed to get a valid address."); - goto fail_addr_auth; - } - - log_info("IPCP got address %" PRIu64 ".", ipcpi.dt_addr); + log_info("IPCP got address %" PRIu64 ".", addr_auth_address()); if (ca_init(conf->unicast.cong_avoid)) { log_err("Failed to initialize congestion avoidance."); @@ -188,8 +177,9 @@ static int bootstrap_components(void) static int unicast_ipcp_enroll(const char * dst, struct layer_info * info) { - struct conn conn; - uint8_t id[ENROLL_ID_LEN]; + struct ipcp_config * conf; + struct conn conn; + uint8_t id[ENROLL_ID_LEN]; if (random_buffer(id, ENROLL_ID_LEN) < 0) { log_err("Failed to generate enrollment ID."); @@ -209,7 +199,11 @@ static int unicast_ipcp_enroll(const char * dst, goto fail_enroll_boot; } - if (initialize_components(enroll_get_conf()) < 0) { + conf = enroll_get_conf(); + + *info = conf->layer_info; + + if (initialize_components(conf) < 0) { log_err_id(id, "Failed to initialize components."); goto fail_enroll_boot; } @@ -227,9 +221,6 @@ static int unicast_ipcp_enroll(const char * dst, log_info_id(id, "Enrolled with %s.", dst); - info->dir_hash_algo = (enum pol_dir_hash) ipcpi.dir_hash_algo; - strcpy(info->name, ipcpi.layer_name); - return 0; fail_start_comp: diff --git a/src/ipcpd/unicast/routing/link-state.c b/src/ipcpd/unicast/routing/link-state.c index 57c0c7cb..0bc6a852 100644 --- a/src/ipcpd/unicast/routing/link-state.c +++ b/src/ipcpd/unicast/routing/link-state.c @@ -42,6 +42,7 @@ #include <ouroboros/rib.h> #include <ouroboros/utils.h> +#include "addr-auth.h" #include "common/comp.h" #include "common/connmgr.h" #include "graph.h" @@ -106,6 +107,8 @@ struct nb { }; struct { + uint64_t addr; + struct list_head nbs; size_t nbs_len; fset_t * mgmt_set; @@ -418,7 +421,7 @@ static void calculate_pff(struct routing_i * instance) assert(instance); if (graph_routing_table(ls.graph, ls.routing_algo, - ipcpi.dt_addr, &table)) + ls.addr, &table)) return; pff_lock(instance->pff); @@ -667,7 +670,7 @@ static void * lsupdate(void * o) continue; } - if (adj->src == ipcpi.dt_addr) { + if (adj->src == ls.addr) { adj->seqno++; send_lsm(adj->src, adj->dst, adj->seqno); adj->stamp = now.tv_sec; @@ -820,13 +823,13 @@ static void handle_event(void * self, pthread_cleanup_push(__cleanup_rwlock_unlock, &ls.db_lock); - send_lsm(ipcpi.dt_addr, c->conn_info.addr, 0); + send_lsm(ls.addr, c->conn_info.addr, 0); pthread_cleanup_pop(true); if (lsdb_add_nb(c->conn_info.addr, c->flow_info.fd, NB_DT)) log_dbg("Failed to add neighbor to LSDB."); - if (lsdb_add_link(ipcpi.dt_addr, c->conn_info.addr, 0, &qs)) + if (lsdb_add_link(ls.addr, c->conn_info.addr, 0, &qs)) log_dbg("Failed to add new adjacency to LSDB."); break; case NOTIFY_DT_CONN_DEL: @@ -835,7 +838,7 @@ static void handle_event(void * self, if (lsdb_del_nb(c->conn_info.addr, c->flow_info.fd)) log_dbg("Failed to delete neighbor from LSDB."); - if (lsdb_del_link(ipcpi.dt_addr, c->conn_info.addr)) + if (lsdb_del_link(ls.addr, c->conn_info.addr)) log_dbg("Local link was not in LSDB."); break; case NOTIFY_DT_CONN_QOS: @@ -927,11 +930,13 @@ int link_state_init(enum pol_routing pr) memset(&info, 0, sizeof(info)); + ls.addr = addr_auth_address(); + strcpy(info.comp_name, LS_COMP); strcpy(info.protocol, LS_PROTO); info.pref_version = 1; info.pref_syntax = PROTO_GPB; - info.addr = ipcpi.dt_addr; + info.addr = ls.addr; switch (pr) { case ROUTING_LINK_STATE: |