static inline lagopus_result_t s_add_stage(lagopus_pipeline_stage_t ps) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; if (ps != NULL && IS_VALID_STRING(ps->m_name) == true) { void *val = (void *)ps; if ((ret = lagopus_hashmap_add(&s_ps_name_tbl, (void *)(ps->m_name), &val, false)) == LAGOPUS_RESULT_OK) { val = (void *)true; ret = lagopus_hashmap_add(&s_ps_obj_tbl, (void *)ps, &val, true); } } else { ret = LAGOPUS_RESULT_INVALID_ARGS; } return ret; }
static inline lagopus_result_t s_config_add(testobj_config_t *o) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; if (o != NULL && IS_VALID_STRING(o->m_name) == true) { void *val = (void *)o; ret = lagopus_hashmap_add(&s_tbl, (void *)(o->m_name), &val, false); } else { ret = LAGOPUS_RESULT_INVALID_ARGS; } return ret; }
static lagopus_result_t channel_set_dpid(const char *channel_name, uint64_t dpid) { lagopus_result_t ret; struct channel *chan = NULL; struct channel_list *chan_list = NULL; void *valptr = NULL; if (dpid == UNUSED_DPID) { return LAGOPUS_RESULT_INVALID_ARGS; } ret = lagopus_hashmap_find(&main_table, (void *)channel_name, (void **)&chan); if (chan == NULL) { return LAGOPUS_RESULT_NOT_FOUND; } if (channel_dpid_get(chan) != UNUSED_DPID) { return LAGOPUS_RESULT_BUSY; } ret = channel_dpid_set(chan, dpid); if (ret != LAGOPUS_RESULT_OK) { return ret; } ret = lagopus_hashmap_find(&dp_table, (void *)dpid, (void **)&chan_list); if (ret == LAGOPUS_RESULT_NOT_FOUND) { chan_list = channel_list_alloc(); if (chan_list == NULL) { ret = LAGOPUS_RESULT_NO_MEMORY; goto done; } valptr = chan_list; ret = lagopus_hashmap_add(&dp_table, (void *)dpid, (void **)&valptr, false); if (ret != LAGOPUS_RESULT_OK) { goto done; } } else if (ret != LAGOPUS_RESULT_OK) { goto done; } channel_id_set(chan, channel_list_channel_id_get(chan_list)); ret = channel_list_insert(chan_list, chan); done: return ret; }
static inline lagopus_result_t queue_conf_add(queue_conf_t *conf) { if (queue_table != NULL) { if (conf != NULL && IS_VALID_STRING(conf->name) == true) { void *val = (void *) conf; return lagopus_hashmap_add(&queue_table, (char *) (conf->name), &val, false); } else { return LAGOPUS_RESULT_INVALID_ARGS; } } else { return LAGOPUS_RESULT_NOT_STARTED; } }
/** * Add ipv4 addr information notified from netlink. */ void rib_notifier_ipv4_addr_add(int ifindex, struct in_addr *addr, int prefixlen, struct in_addr *broad, char *label) { lagopus_result_t rv; struct ifinfo_entry *entry; struct ifinfo_entry *dentry; uint8_t hwaddr[UPDATER_ETH_LEN]; struct bridge *bridge; struct notification_entry *nentry = NULL; addr_ipv4_log("add", ifindex, addr, prefixlen, broad, label); /* new ifinfo entry to registered to ifinfo_hashmap. */ entry = calloc(1, sizeof(struct ifinfo_entry)); if (entry == NULL) { lagopus_msg_warning("no memory.\n"); return; } memset(entry, 0, sizeof(struct ifinfo_entry)); memcpy(entry->ifname, label, strlen(label)); if (dp_tapio_interface_info_get(label, hwaddr, &bridge) != LAGOPUS_RESULT_OK) { lagopus_msg_warning("get interface info failed.\n"); ifinfo_entry_free(entry); return; } memcpy(entry->hwaddr, hwaddr, UPDATER_ETH_LEN); entry->rib = &(bridge->rib); dentry = entry; lagopus_hashmap_add(&ifinfo_hashmap, (void *)ifindex, (void **)&dentry, true); /* create and set notification entry. */ nentry = rib_create_notification_entry(NOTIFICATION_TYPE_IFADDR, NOTIFICATION_ACTION_TYPE_ADD); if (nentry) { /* add notification entry to queue. */ nentry->ifaddr.ifindex = ifindex; rv = rib_add_notification_entry(&bridge->rib, nentry); } else { lagopus_msg_warning("create notification entry failed\n"); ifinfo_entry_free(entry); } return; }
static inline lagopus_result_t bridge_register(uint64_t dpid, struct ofp_bridgeq *bridgeq) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; struct ofp_bridgeq *brq = bridgeq; if (bridgeq != NULL && bridgeq->ofp_bridge != NULL && dpid == bridgeq->ofp_bridge->dpid) { /* add to bridgeq_table */ ret = lagopus_hashmap_add(&bridgeq_table, (void *)bridgeq->ofp_bridge->dpid, (void **)&brq, true); } else { ret = LAGOPUS_RESULT_INVALID_ARGS; } return ret; }
static lagopus_result_t channel_add_internal(const char *channel_name, struct addrunion *addr, struct channel **channel) { lagopus_result_t ret; struct channel *chan = NULL; void *valptr = NULL; if (main_table == NULL) { return LAGOPUS_RESULT_ANY_FAILURES; } ret = lagopus_hashmap_find(&main_table, (void *)channel_name, (void **)&chan); if (ret == LAGOPUS_RESULT_OK && chan != NULL) { /* FIXME support auxiliary connections */ return LAGOPUS_RESULT_ALREADY_EXISTS; } else if (ret != LAGOPUS_RESULT_NOT_FOUND) { return ret; } #define UNUSED_DPID 0 chan = channel_alloc(addr, em, UNUSED_DPID); if (chan == NULL) { return LAGOPUS_RESULT_NO_MEMORY; } lagopus_msg_debug(10, "channel allocated %p\n", chan); valptr = chan; ret = lagopus_hashmap_add(&main_table, (void *)channel_name, (void **)&valptr, false); if (ret != LAGOPUS_RESULT_OK) { channel_free(chan); } if (ret != LAGOPUS_RESULT_OK) { channel_delete_internal((const char *) channel_name); } else { *channel = chan; } return ret; }
static inline lagopus_result_t s_add_addr(void *addr, size_t sz) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; if (likely(s_tbl != NULL)) { if (likely(addr != NULL)) { void *val; #ifdef LAGOPUS_ARCH_32_BITS val = (void *)((uint32_t)sz); #else val = (void *)sz; #endif /* LAGOPUS_ARCH_32_BITS */ ret = lagopus_hashmap_add(&s_tbl, addr, &val, false); } else { ret = LAGOPUS_RESULT_INVALID_ARGS; } } else { ret = LAGOPUS_RESULT_NOT_OPERATIONAL; } return ret; }
static void check_status_and_send_traps(void) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; struct port_stat *port_stat; size_t index; char ifname[IFNAMSIZ + 1]; size_t len = 0; struct ifTable_entry *entry = NULL; int32_t ifAdminStatus, ifOperStatus; int32_t old_ifAdminStatus, old_ifOperStatus; if ((ret = dp_get_port_stat(&port_stat)) == LAGOPUS_RESULT_OK) { /* check each port_stat, send trap if needed! */ for (index = 0; dataplane_interface_get_ifDescr( port_stat, index, ifname, &len) == LAGOPUS_RESULT_OK; index++) { if (len > 0) { int32_t ifIndex = (int32_t) (index + 1); if (dataplane_interface_get_ifAdminStatus( port_stat, index, &ifAdminStatus) == LAGOPUS_RESULT_OK && dataplane_interface_get_ifOperStatus( port_stat, index, &ifOperStatus) == LAGOPUS_RESULT_OK) { /* Note: * index may be changed if a port is attached/detacched to vSwitch, * so use ifName as key. */ ret = lagopus_hashmap_find(&iftable_entry_hash, (void *)ifname, (void *)&entry); if (ret == LAGOPUS_RESULT_OK) { old_ifAdminStatus = entry->ifAdminStatus; old_ifOperStatus = entry->ifOperStatus; entry->ifAdminStatus = ifAdminStatus; entry->ifOperStatus = ifOperStatus; if (ifOperStatus != old_ifOperStatus) { /* operation status prior to administration status */ if (ifOperStatus == up) { /* is up */ (void)send_linkUp_trap(ifIndex, ifAdminStatus, ifOperStatus); } else if (ifOperStatus != up && old_ifOperStatus == up) { (void)send_linkDown_trap(ifIndex, ifAdminStatus, ifOperStatus); } } else if (ifAdminStatus != old_ifAdminStatus) { if (ifAdminStatus == up) { (void)send_linkUp_trap(ifIndex, ifAdminStatus, ifOperStatus); } else if (ifAdminStatus != up && old_ifAdminStatus == up) { (void)send_linkDown_trap(ifIndex, ifAdminStatus, ifOperStatus); } } } else { /* The entry does not exist in previous status checking, */ /* so the port_stat is attached recentry. */ if (ifOperStatus == up) { (void)send_linkUp_trap(ifIndex, ifAdminStatus, ifOperStatus); } if ((entry = (struct ifTable_entry *) malloc (sizeof(*entry))) != NULL) { entry->ifAdminStatus = ifAdminStatus; entry->ifOperStatus = ifOperStatus; if ((ret = lagopus_hashmap_add(&iftable_entry_hash, (void *)ifname, (void **)&entry, false)) != LAGOPUS_RESULT_OK) { lagopus_perror(ret); free(entry); } } else { lagopus_perror(LAGOPUS_RESULT_NO_MEMORY); } } } } } } }