clientcallback";

/*-----------------------------------------------------------------------------
| Function : vtysh_udp_forwarder_context_clientcallback
| Responsibility : client callback routine
| Parameters :
|     void *p_private: void type object typecast to required
| Return : On success, returns e_vtysh_ok. On failure, returns e_vtysh_error.
-----------------------------------------------------------------------------*/
vtysh_ret_val
vtysh_udp_forwarder_context_clientcallback (void *p_private)
{
    vtysh_ovsdb_cbmsg_ptr p_msg = (vtysh_ovsdb_cbmsg *)p_private;
    const struct ovsrec_system *ovs_row = NULL;
    char *udp_status = NULL;

    ovs_row = ovsrec_system_first (p_msg->idl);
    if (!ovs_row) {
        return e_vtysh_ok;
    }

    udp_status = (char *)smap_get(&ovs_row->other_config,
                              SYSTEM_OTHER_CONFIG_MAP_UDP_BCAST_FWD_ENABLED);
    if (udp_status && !strcmp(udp_status, "true")) {
        vtysh_ovsdb_cli_print(p_msg, "%s", "ip udp-bcast-forward");
    }

    return e_vtysh_ok;
}
Ejemplo n.º 2
0
/*-----------------------------------------------------------------------------
| Function : show_sftp_server
| Responsibility : To show the current SFTP server status.
| Return : On success returns CMD_SUCCESS,
|          On failure returns CMD_OVSDB_FAILURE
-----------------------------------------------------------------------------*/
static int
show_sftp_server (void)
{
    const struct ovsrec_system *row = NULL;
    char *status = NULL;

    row = ovsrec_system_first(idl);
    if (!row) {
        VLOG_ERR(OVSDB_TXN_CREATE_ERROR);
        return CMD_OVSDB_FAILURE;
    }

    vty_out(vty, "%sSFTP server configuration %s",
                  VTY_NEWLINE, VTY_NEWLINE);
    vty_out(vty, "-------------------------%s",
                  VTY_NEWLINE);

    status = (char *)smap_get(&row->other_config, SFTP_SERVER_CONFIG);
    if (status == NULL) {
        vty_out(vty, "SFTP server : Disabled %s", VTY_NEWLINE);

        return CMD_SUCCESS;
    } else {
        if (!strcmp(status, "true")) {
            vty_out(vty, "SFTP server : Enabled %s", VTY_NEWLINE);
        } else if (!strcmp(status, "false")) {
            vty_out(vty, "SFTP server : Disabled %s", VTY_NEWLINE);
        }
    }

    vty_out(vty, "%s", VTY_NEWLINE);

    return CMD_SUCCESS;
}
Ejemplo n.º 3
0
/**
 * programs qos trust for a port
 *      called from bridge reconfigure after all ports in a bridge or VRF
 *      have been configured.
 *
 * @param ofproto   - pointer to bridge or VRF descriptor
 * @param aux       - opaque pointer passed through to provider layer,
 *                    is a bridge_reconfigure "struct port" pointer
 * @param port_cfg  - Port row in IDL
 * @param idl_seqno - current transaction sequence number
 */
void
qos_trust_send_change(struct ofproto *ofproto,
                      void *aux,
                      const struct ovsrec_port *port_cfg,
                      unsigned int idl_seqno)
{
    bool send_trust_change = false;

    if (global_trust_changed) {
        if (smap_get(&port_cfg->qos_config, "qos_trust") == NULL) {
            send_trust_change = true;
        }
    }
    if (send_trust_change ||
        OVSREC_IDL_IS_ROW_MODIFIED(port_cfg, idl_seqno)) {

        /* Make sure this port has interfaces that are 'system' type.
           QoS should not affect other types. */
        if ( ! strcmp(port_cfg->interfaces[0]->type,
                      OVSREC_INTERFACE_TYPE_SYSTEM)) {
            VLOG_DBG("%s: port %s TRUST change", __FUNCTION__, port_cfg->name);
            ofproto_set_port_qos_cfg(ofproto,
                                     aux,
                                     global_qos_trust,
                                     &port_cfg->qos_config,
                                     &port_cfg->other_config);
        }
    }
}
Ejemplo n.º 4
0
Archivo: dpdk.c Proyecto: shettyg/ovs
static int
get_dpdk_args(const struct smap *ovs_other_config, char ***argv,
              int argc)
{
    const char *extra_configuration;
    char **extra_args = NULL;
    int i;
    size_t extra_argc = 0;

    extra_configuration = smap_get(ovs_other_config, "dpdk-extra");
    if (extra_configuration) {
        extra_argc = extra_dpdk_args(extra_configuration, &extra_args, 0);
    }

    i = construct_dpdk_options(ovs_other_config, argv, argc, extra_args,
                               extra_argc);
    i = construct_dpdk_mutex_options(ovs_other_config, argv, i, extra_args,
                                     extra_argc);

    if (extra_configuration) {
        *argv = move_argv(argv, i, extra_args, extra_argc);
    }

    return i + extra_argc;
}
Ejemplo n.º 5
0
void *getmap(void *argv)
{
	struct timeval tvafter,tvpre;
	struct timezone tz;
	struct SMAP* map = ((struct thread_args *)argv)->map;
	struct file *fptr = ((struct thread_args *)argv)->fptr;
	int i, j, s,z;
	void *ret;
	struct PAIR pair;
	z = c++;
	s = (LOOP_TIMES/MAXTHEADS) * z;
	free(argv);
	
	
	
	gettimeofday (&tvpre , &tz);
	for (j = 0 ; j < 1; j++) {
	for (i = s; i < s + LOOP_TIMES/MAXTHEADS; i++) {
		if (i%2)
			SMAP_SET_NUM_KEY(&pair, i);
		else
			SMAP_SET_STR_KEY(&pair, buf[i], 7);
		ret = smap_get(map, &pair, 0);

	}	
	}
	gettimeofday (&tvafter , &tz);
	printf("get %d: %dms\n", z, (tvafter.tv_sec-tvpre.tv_sec)*1000+(tvafter.tv_usec-tvpre.tv_usec)/1000);
	stop_thr(fptr);
	return;
}
Ejemplo n.º 6
0
static void
get_local_iface_ids(const struct ovsrec_bridge *br_int, struct shash *lports)
{
    int i;

    for (i = 0; i < br_int->n_ports; i++) {
        const struct ovsrec_port *port_rec = br_int->ports[i];
        const char *iface_id;
        int j;

        if (!strcmp(port_rec->name, br_int->name)) {
            continue;
        }

        for (j = 0; j < port_rec->n_interfaces; j++) {
            const struct ovsrec_interface *iface_rec;

            iface_rec = port_rec->interfaces[j];
            iface_id = smap_get(&iface_rec->external_ids, "iface-id");
            if (!iface_id) {
                continue;
            }
            shash_add(lports, iface_id, iface_rec);
        }
    }
}
Ejemplo n.º 7
0
static void
construct_dpdk_options(const struct smap *ovs_other_config, struct svec *args)
{
    struct dpdk_options_map {
        const char *ovs_configuration;
        const char *dpdk_option;
        bool default_enabled;
        const char *default_value;
    } opts[] = {
        {"dpdk-lcore-mask",   "-c",             false, NULL},
        {"dpdk-hugepage-dir", "--huge-dir",     false, NULL},
        {"dpdk-socket-limit", "--socket-limit", false, NULL},
    };

    int i;

    /*First, construct from the flat-options (non-mutex)*/
    for (i = 0; i < ARRAY_SIZE(opts); ++i) {
        const char *value = smap_get(ovs_other_config,
                                     opts[i].ovs_configuration);
        if (!value && opts[i].default_enabled) {
            value = opts[i].default_value;
        }

        if (value) {
            if (!args_contains(args, opts[i].dpdk_option)) {
                svec_add(args, opts[i].dpdk_option);
                svec_add(args, value);
            } else {
                VLOG_WARN("Ignoring database defined option '%s' due to "
                          "dpdk-extra config", opts[i].dpdk_option);
            }
        }
    }
}
Ejemplo n.º 8
0
/* Check management interface is static.
 * On success, returns true. On failure, returns false.
 */
bool
is_mode_static(const struct ovsrec_system *ovs)
{
    const char *mode_value = NULL;

    mode_value = smap_get(&ovs->mgmt_intf, SYSTEM_MGMT_INTF_MAP_MODE);
    if (!mode_value || (strcmp(mode_value, "static") != 0))
        return false;

    return true;
}
Ejemplo n.º 9
0
/**
 * Process ACL table changes to determine if in_progress_aces
 * needs to be updated or not
 */
int
acl_reconfigure(struct ovsdb_idl *idl, unsigned int idl_seqno)
{
    int rc = 0;
    const struct ovsrec_acl *acl_row = NULL;
    const char *status_version_str;
    uint64_t status_version;
    bool in_progress_cleared = false;

    VLOG_DBG("acl_reconfigure...\n");

    ovs_assert(idl);

    OVSREC_ACL_FOR_EACH (acl_row, idl) {
        if (OVSREC_IDL_IS_ROW_INSERTED(acl_row, idl_seqno) ||
            OVSREC_IDL_IS_ROW_MODIFIED(acl_row, idl_seqno)) {
            /* Get the status version */
            status_version_str = smap_get(&acl_row->status, "version");
            /* If the status version is valid, then update in_progress_aces
             * only when in_progress_version == status_version and
             * cfg_version > in_progress_version.
             */
            if (status_version_str) {
                status_version = strtoull(status_version_str, NULL, 0);
                if (acl_row->in_progress_version[0] == status_version) {
                    /* Clear the in_progress_aces as we have finished
                     * processing the in_progress_aces.
                     */
                    ovsrec_acl_set_in_progress_aces(acl_row, NULL, NULL, 0);
                    in_progress_cleared = true;
                    rc++;
                }
            }
            /* If status_version_str is NULL, it is the first time we are
             * programming anything into aces column. We need to update
             * in_progress_aces column. The other condition to check is
             * if UI made a change and in_progress_cleared flag is true */
            if (!status_version_str ||
                ((in_progress_cleared == true) &&
                 (acl_row->cfg_version[0] > acl_row->in_progress_version[0]))) {
                ovsrec_acl_set_in_progress_aces(acl_row, acl_row->key_cfg_aces,
                    acl_row->value_cfg_aces, acl_row->n_cfg_aces);
                ovsrec_acl_set_in_progress_version(acl_row,
                                                   acl_row->cfg_version,1);
                rc++;
            }
        }
    } /* for each acl ROW */

    VLOG_DBG("%s: number of updates back to db: %d",__FUNCTION__,rc);

    return rc;
} /* acl_reconfigure */
Ejemplo n.º 10
0
static void
construct_dpdk_args(const struct smap *ovs_other_config, struct svec *args)
{
    const char *extra_configuration = smap_get(ovs_other_config, "dpdk-extra");

    if (extra_configuration) {
        svec_parse_words(args, extra_configuration);
    }

    construct_dpdk_options(ovs_other_config, args);
    construct_dpdk_mutex_options(ovs_other_config, args);
}
Ejemplo n.º 11
0
static const char *
get_chassis_id(const struct ovsdb_idl *ovs_idl)
{
    const struct ovsrec_open_vswitch *cfg = ovsrec_open_vswitch_first(ovs_idl);
    const char *chassis_id = cfg ? smap_get(&cfg->external_ids, "system-id") : NULL;

    if (!chassis_id) {
        static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1);
        VLOG_WARN_RL(&rl, "'system-id' in Open_vSwitch database is missing.");
    }

    return chassis_id;
}
Ejemplo n.º 12
0
/* Removes Ipv6 default gw and dns server configs from DB. */
void
mgmt_intf_clear_ipv6_config_db(const struct ovsrec_system *row,
                               struct smap *smap_mgmt_intf)
{
    const char* ip_addr;

    if (NULL == row)
    {
        VLOG_ERR("Invalid System row pointer");
        return;
    }

    ip_addr = smap_get(&row->mgmt_intf, SYSTEM_MGMT_INTF_MAP_IPV6);
    if (ip_addr != NULL)
    {
        smap_remove(smap_mgmt_intf, SYSTEM_MGMT_INTF_MAP_IPV6);
    }

    ip_addr = smap_get(&row->mgmt_intf,
                       SYSTEM_MGMT_INTF_MAP_DEFAULT_GATEWAY_V6);
    if (ip_addr != NULL)
    {
        smap_remove(smap_mgmt_intf, SYSTEM_MGMT_INTF_MAP_DEFAULT_GATEWAY_V6);
    }

    ip_addr = smap_get(&row->mgmt_intf, SYSTEM_MGMT_INTF_MAP_DNS_SERVER_1);
    if (ip_addr != NULL)
    {
        smap_remove(smap_mgmt_intf, SYSTEM_MGMT_INTF_MAP_DNS_SERVER_1);
    }

    ip_addr = smap_get(&row->mgmt_intf, SYSTEM_MGMT_INTF_MAP_DNS_SERVER_2);
    if (ip_addr != NULL)
    {
        smap_remove(smap_mgmt_intf, SYSTEM_MGMT_INTF_MAP_DNS_SERVER_2);
    }

    return;
}
Ejemplo n.º 13
0
void check_tree_shape(AST *ptr) {
    /* TODO: Implement me. */
    /* Hint: This function is just asking to be table-driven */
    if (ptr) {
        AST_lst *children = ptr->children;
        if (ptr->type == node_FUNCTION) {
            AST *first_child = children->val;
            AST_lst *grandchildren = first_child->children;
            while (grandchildren) {
                if ((grandchildren->val)->type != node_VAR) {
                    fatal_error("Function definition arguments don't take in VAR arguments");
                }
                check_tree_shape(grandchildren->val);
                grandchildren = grandchildren->next;
            }
            children = children->next;
        }
        while (children) {
            check_tree_shape(children->val);
            children = children->next;
        }
        node_type ptr_type = ptr->type;
        if (ptr_type == node_INT || ptr_type == node_STRING || ptr_type == node_VAR) {
            if (AST_lst_len(ptr->children) != 0) {
                fatal_error("INT/STRING/VAR type have children");
            }
        } else if (ptr_type == node_STRUCT || ptr_type == node_SEQ) {
            if (AST_lst_len(ptr->children) < smap_get(num_args,ptr->val)) {
                fatal_error("STRUCT/SEQ don't have enough children");
            }
        } else if (smap_get(num_args,ptr->val) == -1) {
            fatal_error("Function called is not defined");
        } else if (AST_lst_len(ptr->children) != smap_get(num_args,ptr->val)) {
            fatal_error("Wrong number of children");
        }
    }
}
Ejemplo n.º 14
0
/**************************************************************************//**
 * This function determines if hw_ready_state can be set for the interface
 * associated with the port_row
 *
 * @param[in]   port_row  - Pointer to @see struct ovsrec_port
 *
 * @return      true      - If the hw_ready_state can be set
 *                          true
 *              false     - If the hw_ready_state is false
*****************************************************************************/
static bool
acl_ports_is_hw_ready(const struct ovsrec_port *port_row)
{
    const char *status_str = NULL;
    int acl_type_iter;

    ovs_assert(port_row);

    /* set hw_ready_state to true for following conditions,
     * - If ACL is NOT configured for this port
     * - If ACL is configured and applied status is success
     */
    for (acl_type_iter = ACL_CFG_MIN_PORT_TYPES;
            acl_type_iter <= ACL_CFG_MAX_PORT_TYPES; acl_type_iter++) {
        const struct ovsrec_acl *acl_row =
            acl_db_util_get_cfg(&acl_db_accessor[acl_type_iter], port_row);
        if(!acl_row) {
            VLOG_DBG("port %s: ACL not configured \n", port_row->name);
            /* do not block hw_ready on the interface due to this ACL */
        } else {
            /* ACL is configured on this port so verify if
             * ACL is applied successfully in hw or not
             */
            const struct smap acl_status =
                acl_db_util_get_cfg_status(&acl_db_accessor[acl_type_iter],
                                           port_row);
            if (smap_is_empty(&acl_status)) {
                return false;
            }

            status_str = smap_get(&acl_status, OPS_CLS_STATUS_CODE_STR);
            if (status_str == NULL) {
                return false;
            }

            VLOG_DBG("port %s: ACL %s configured, apply status %s \n",
                      port_row->name, acl_row->name,
                      status_str);

            if(strtoul(status_str, NULL, 10) != OPS_CLS_STATUS_SUCCESS) {
                /* block hw_ready on this interface */
                return false;
            }
        } /* end if !applied */
    }

    return true;
}
Ejemplo n.º 15
0
/* Retrieves the OVN Southbound remote location from the
 * "external-ids:ovn-remote" key in 'ovs_idl' and returns a copy of it.
 *
 * XXX ovn-controller does not support this changing mid-run, but that should
 * be addressed later. */
static char *
get_ovnsb_remote(struct ovsdb_idl *ovs_idl)
{
    while (1) {
        ovsdb_idl_run(ovs_idl);

        const struct ovsrec_open_vswitch *cfg
            = ovsrec_open_vswitch_first(ovs_idl);
        if (cfg) {
            const char *remote = smap_get(&cfg->external_ids, "ovn-remote");
            if (remote) {
                return xstrdup(remote);
            }
        }

        VLOG_INFO("OVN OVSDB remote not specified.  Waiting...");
        ovsdb_idl_wait(ovs_idl);
        poll_block();
    }
}
Ejemplo n.º 16
0
/* Retrieves the OVN Southbound remote's json session probe interval from the
 * "external-ids:ovn-remote-probe-interval" key in 'ovs_idl' and returns it.
 *
 * This function must be called after get_ovnsb_remote(). */
static bool
get_ovnsb_remote_probe_interval(struct ovsdb_idl *ovs_idl, int *value)
{
    const struct ovsrec_open_vswitch *cfg = ovsrec_open_vswitch_first(ovs_idl);
    if (!cfg) {
        return false;
    }

    const char *probe_interval =
        smap_get(&cfg->external_ids, "ovn-remote-probe-interval");
    if (probe_interval) {
        if (str_to_int(probe_interval, 10, value)) {
            return true;
        }

        VLOG_WARN("Invalid value for OVN remote probe interval: %s",
                  probe_interval);
    }

    return false;
}
Ejemplo n.º 17
0
static const struct ovsrec_bridge *
get_br_int(struct controller_ctx *ctx)
{
    const struct ovsrec_open_vswitch *cfg;
    cfg = ovsrec_open_vswitch_first(ctx->ovs_idl);
    if (!cfg) {
        return NULL;
    }

    const char *br_int_name = smap_get(&cfg->external_ids, "ovn-bridge");
    if (!br_int_name) {
        br_int_name = DEFAULT_BRIDGE_NAME;
    }

    const struct ovsrec_bridge *br;
    br = get_bridge(ctx->ovs_idl, br_int_name);
    if (!br) {
        return create_br_int(ctx, cfg, br_int_name);
    }
    return br;
}
Ejemplo n.º 18
0
Archivo: dpdk.c Proyecto: shettyg/ovs
static int
construct_dpdk_options(const struct smap *ovs_other_config,
                       char ***argv, const int initial_size,
                       char **extra_args, const size_t extra_argc)
{
    struct dpdk_options_map {
        const char *ovs_configuration;
        const char *dpdk_option;
        bool default_enabled;
        const char *default_value;
    } opts[] = {
        {"dpdk-lcore-mask", "-c", false, NULL},
        {"dpdk-hugepage-dir", "--huge-dir", false, NULL},
    };

    int i, ret = initial_size;

    /*First, construct from the flat-options (non-mutex)*/
    for (i = 0; i < ARRAY_SIZE(opts); ++i) {
        const char *lookup = smap_get(ovs_other_config,
                                      opts[i].ovs_configuration);
        if (!lookup && opts[i].default_enabled) {
            lookup = opts[i].default_value;
        }

        if (lookup) {
            if (!argv_contains(extra_args, extra_argc, opts[i].dpdk_option)) {
                dpdk_option_extend(argv, ret, opts[i].dpdk_option, lookup);
                ret += 2;
            } else {
                VLOG_WARN("Ignoring database defined option '%s' due to "
                          "dpdk_extras config", opts[i].dpdk_option);
            }
        }
    }

    return ret;
}
Ejemplo n.º 19
0
static const struct ovsrec_bridge *
get_br_int(struct ovsdb_idl *ovs_idl)
{
    const struct ovsrec_open_vswitch *cfg = ovsrec_open_vswitch_first(ovs_idl);
    if (!cfg) {
        return NULL;
    }

    const char *br_int_name = smap_get(&cfg->external_ids, "ovn-bridge");
    if (!br_int_name) {
        br_int_name = DEFAULT_BRIDGE_NAME;
    }

    const struct ovsrec_bridge *br;
    OVSREC_BRIDGE_FOR_EACH (br, ovs_idl) {
        if (!strcmp(br->name, br_int_name)) {
            return br;
        }
    }

    static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
    VLOG_WARN_RL(&rl, "%s: integration bridge does not exist", br_int_name);
    return NULL;
}
Ejemplo n.º 20
0
Archivo: dpdk.c Proyecto: shettyg/ovs
static int
process_vhost_flags(char *flag, char *default_val, int size,
                    const struct smap *ovs_other_config,
                    char **new_val)
{
    const char *val;
    int changed = 0;

    val = smap_get(ovs_other_config, flag);

    /* Process the vhost-sock-dir flag if it is provided, otherwise resort to
     * default value.
     */
    if (val && (strlen(val) <= size)) {
        changed = 1;
        *new_val = xstrdup(val);
        VLOG_INFO("User-provided %s in use: %s", flag, *new_val);
    } else {
        VLOG_INFO("No %s provided - defaulting to %s", flag, default_val);
        *new_val = default_val;
    }

    return changed;
}
Ejemplo n.º 21
0
/* Check for any static def-gateway or nameserver config
 * before removing static IPv6.
 * On success, returns CMD_SUCCESS. On failure, returns CMD_ERR_NOTHING_TODO.
 */
static int
mgmt_intf_remove_static_ipv6_address(struct smap *smap, const char *ipv6)
{
    const char *cfg_ip, *cfg_gw, *cfg_dns, *cfg_ipv6;
    struct in6_addr addrv6;

    memset (&addrv6, 0, sizeof (struct in6_addr));

    if (NULL == smap || NULL == ipv6)
    {
        VLOG_ERR("Invalid parameters");
        return CMD_ERR_NOTHING_TODO;
    }

    cfg_ipv6 =  smap_get(smap, SYSTEM_MGMT_INTF_MAP_IPV6);
    if (!cfg_ipv6 || strcmp(ipv6, cfg_ipv6) != 0)
    {
        vty_out(vty, "  %s %s", OVSDB_INVALID_VALUE_ERROR, VTY_NEWLINE);
        return CMD_ERR_NOTHING_TODO;
    }

    cfg_gw =  smap_get(smap, SYSTEM_MGMT_INTF_MAP_DEFAULT_GATEWAY_V6);
    if (cfg_gw && strcmp(MGMT_INTF_DEFAULT_IPV6, cfg_gw) != 0)
    {
        vty_out(vty, "  %s %s", OVSDB_REMOVE_IPV6_STATIC_CONF, VTY_NEWLINE);
        return CMD_ERR_NOTHING_TODO;
    }

    cfg_dns =  smap_get(smap, SYSTEM_MGMT_INTF_MAP_DNS_SERVER_1);
    if (cfg_dns && (inet_pton(AF_INET6, cfg_dns,&addrv6) == 1))
    {
        if (strcmp(MGMT_INTF_DEFAULT_IPV6, cfg_dns) != 0)
        {
            vty_out(vty, "  %s %s", OVSDB_REMOVE_IPV6_STATIC_CONF, VTY_NEWLINE);
            return CMD_ERR_NOTHING_TODO;
        }
    }

    cfg_dns =  smap_get(smap, SYSTEM_MGMT_INTF_MAP_DNS_SERVER_2);
    if (cfg_dns && (inet_pton(AF_INET6, cfg_dns,&addrv6) == 1))
    {
        if (strcmp(MGMT_INTF_DEFAULT_IPV6, cfg_dns) != 0)
        {
            vty_out(vty, "  %s %s", OVSDB_REMOVE_IPV6_STATIC_CONF, VTY_NEWLINE);
            return CMD_ERR_NOTHING_TODO;
        }
    }

    /* If no static IPv4 address then change the mode to DHCP. */
    cfg_ip =  smap_get(smap, SYSTEM_MGMT_INTF_MAP_IP);
    if (!cfg_ip || strcmp(MGMT_INTF_DEFAULT_IP, cfg_ip) == 0)
    {
        smap_replace(smap, SYSTEM_MGMT_INTF_MAP_MODE,
                           SYSTEM_MGMT_INTF_MAP_MODE_DHCP);
        smap_remove(smap, SYSTEM_MGMT_INTF_MAP_IPV6);
    }
    else
    {
    /* Replace defualt IPv6 value in to DB to flush previous
     * config from stack.
     */
        smap_replace(smap, SYSTEM_MGMT_INTF_MAP_IPV6, MGMT_INTF_DEFAULT_IPV6);
    }
    return CMD_SUCCESS;
}
Ejemplo n.º 22
0
Archivo: dpdk.c Proyecto: shettyg/ovs
static int
construct_dpdk_mutex_options(const struct smap *ovs_other_config,
                             char ***argv, const int initial_size,
                             char **extra_args, const size_t extra_argc)
{
    struct dpdk_exclusive_options_map {
        const char *category;
        const char *ovs_dpdk_options[MAX_DPDK_EXCL_OPTS];
        const char *eal_dpdk_options[MAX_DPDK_EXCL_OPTS];
        const char *default_value;
        int default_option;
    } excl_opts[] = {
        {"memory type",
         {"dpdk-alloc-mem", "dpdk-socket-mem", NULL,},
         {"-m",             "--socket-mem",    NULL,},
         "1024,0", 1
        },
    };

    int i, ret = initial_size;
    for (i = 0; i < ARRAY_SIZE(excl_opts); ++i) {
        int found_opts = 0, scan, found_pos = -1;
        const char *found_value;
        struct dpdk_exclusive_options_map *popt = &excl_opts[i];

        for (scan = 0; scan < MAX_DPDK_EXCL_OPTS
                 && popt->ovs_dpdk_options[scan]; ++scan) {
            const char *lookup = smap_get(ovs_other_config,
                                          popt->ovs_dpdk_options[scan]);
            if (lookup && strlen(lookup)) {
                found_opts++;
                found_pos = scan;
                found_value = lookup;
            }
        }

        if (!found_opts) {
            if (popt->default_option) {
                found_pos = popt->default_option;
                found_value = popt->default_value;
            } else {
                continue;
            }
        }

        if (found_opts > 1) {
            VLOG_ERR("Multiple defined options for %s. Please check your"
                     " database settings and reconfigure if necessary.",
                     popt->category);
        }

        if (!argv_contains(extra_args, extra_argc,
                           popt->eal_dpdk_options[found_pos])) {
            dpdk_option_extend(argv, ret, popt->eal_dpdk_options[found_pos],
                               found_value);
            ret += 2;
        } else {
            VLOG_WARN("Ignoring database defined option '%s' due to "
                      "dpdk_extras config", popt->eal_dpdk_options[found_pos]);
        }
    }

    return ret;
}
Ejemplo n.º 23
0
/* Returns this chassis's Chassis record, if it is available and is currently
 * amenable to a transaction. */
const struct sbrec_chassis *
chassis_run(struct controller_ctx *ctx, const char *chassis_id,
            const struct ovsrec_bridge *br_int)
{
    if (!ctx->ovnsb_idl_txn) {
        return NULL;
    }

    const struct ovsrec_open_vswitch *cfg;
    const char *encap_type, *encap_ip;
    static bool inited = false;

    cfg = ovsrec_open_vswitch_first(ctx->ovs_idl);
    if (!cfg) {
        VLOG_INFO("No Open_vSwitch row defined.");
        return NULL;
    }

    encap_type = smap_get(&cfg->external_ids, "ovn-encap-type");
    encap_ip = smap_get(&cfg->external_ids, "ovn-encap-ip");
    if (!encap_type || !encap_ip) {
        VLOG_INFO("Need to specify an encap type and ip");
        return NULL;
    }

    char *tokstr = xstrdup(encap_type);
    char *save_ptr = NULL;
    char *token;
    uint32_t req_tunnels = 0;
    for (token = strtok_r(tokstr, ",", &save_ptr); token != NULL;
         token = strtok_r(NULL, ",", &save_ptr)) {
        uint32_t type = get_tunnel_type(token);
        if (!type) {
            VLOG_INFO("Unknown tunnel type: %s", token);
        }
        req_tunnels |= type;
    }
    free(tokstr);

    const char *hostname = smap_get_def(&cfg->external_ids, "hostname", "");
    char hostname_[HOST_NAME_MAX + 1];
    if (!hostname[0]) {
        if (gethostname(hostname_, sizeof hostname_)) {
            hostname_[0] = '\0';
        }
        hostname = hostname_;
    }

    const char *bridge_mappings = get_bridge_mappings(&cfg->external_ids);
    const char *datapath_type =
        br_int && br_int->datapath_type ? br_int->datapath_type : "";

    struct ds iface_types = DS_EMPTY_INITIALIZER;
    ds_put_cstr(&iface_types, "");
    for (int j = 0; j < cfg->n_iface_types; j++) {
        ds_put_format(&iface_types, "%s,", cfg->iface_types[j]);
    }
    ds_chomp(&iface_types, ',');
    const char *iface_types_str = ds_cstr(&iface_types);

    const struct sbrec_chassis *chassis_rec
        = get_chassis(ctx->ovnsb_idl, chassis_id);

    if (chassis_rec) {
        if (strcmp(hostname, chassis_rec->hostname)) {
            sbrec_chassis_set_hostname(chassis_rec, hostname);
        }

        /* Determine new values for Chassis external-ids. */
        const char *chassis_bridge_mappings
            = get_bridge_mappings(&chassis_rec->external_ids);
        const char *chassis_datapath_type
            = smap_get_def(&chassis_rec->external_ids, "datapath-type", "");
        const char *chassis_iface_types
            = smap_get_def(&chassis_rec->external_ids, "iface-types", "");

        /* If any of the external-ids should change, update them. */
        if (strcmp(bridge_mappings, chassis_bridge_mappings) ||
            strcmp(datapath_type, chassis_datapath_type) ||
            strcmp(iface_types_str, chassis_iface_types)) {
            struct smap new_ids;
            smap_clone(&new_ids, &chassis_rec->external_ids);
            smap_replace(&new_ids, "ovn-bridge-mappings", bridge_mappings);
            smap_replace(&new_ids, "datapath-type", datapath_type);
            smap_replace(&new_ids, "iface-types", iface_types_str);
            sbrec_chassis_verify_external_ids(chassis_rec);
            sbrec_chassis_set_external_ids(chassis_rec, &new_ids);
            smap_destroy(&new_ids);
        }

        /* Compare desired tunnels against those currently in the database. */
        uint32_t cur_tunnels = 0;
        bool same = true;
        for (int i = 0; i < chassis_rec->n_encaps; i++) {
            cur_tunnels |= get_tunnel_type(chassis_rec->encaps[i]->type);
            same = same && !strcmp(chassis_rec->encaps[i]->ip, encap_ip);

            same = same && smap_get_bool(&chassis_rec->encaps[i]->options,
                                         "csum", false);
        }
        same = same && req_tunnels == cur_tunnels;

        if (same) {
            /* Nothing changed. */
            inited = true;
            ds_destroy(&iface_types);
            return chassis_rec;
        } else if (!inited) {
            struct ds cur_encaps = DS_EMPTY_INITIALIZER;
            for (int i = 0; i < chassis_rec->n_encaps; i++) {
                ds_put_format(&cur_encaps, "%s,",
                              chassis_rec->encaps[i]->type);
            }
            ds_chomp(&cur_encaps, ',');

            VLOG_WARN("Chassis config changing on startup, make sure "
                      "multiple chassis are not configured : %s/%s->%s/%s",
                      ds_cstr(&cur_encaps),
                      chassis_rec->encaps[0]->ip,
                      encap_type, encap_ip);
            ds_destroy(&cur_encaps);
        }
    }

    ovsdb_idl_txn_add_comment(ctx->ovnsb_idl_txn,
                              "ovn-controller: registering chassis '%s'",
                              chassis_id);

    if (!chassis_rec) {
        struct smap ext_ids = SMAP_INITIALIZER(&ext_ids);
        smap_add(&ext_ids, "ovn-bridge-mappings", bridge_mappings);
        smap_add(&ext_ids, "datapath-type", datapath_type);
        smap_add(&ext_ids, "iface-types", iface_types_str);
        chassis_rec = sbrec_chassis_insert(ctx->ovnsb_idl_txn);
        sbrec_chassis_set_name(chassis_rec, chassis_id);
        sbrec_chassis_set_hostname(chassis_rec, hostname);
        sbrec_chassis_set_external_ids(chassis_rec, &ext_ids);
        smap_destroy(&ext_ids);
    }

    ds_destroy(&iface_types);
    int n_encaps = count_1bits(req_tunnels);
    struct sbrec_encap **encaps = xmalloc(n_encaps * sizeof *encaps);
    const struct smap options = SMAP_CONST1(&options, "csum", "true");

    for (int i = 0; i < n_encaps; i++) {
        const char *type = pop_tunnel_name(&req_tunnels);

        encaps[i] = sbrec_encap_insert(ctx->ovnsb_idl_txn);

        sbrec_encap_set_type(encaps[i], type);
        sbrec_encap_set_ip(encaps[i], encap_ip);
        sbrec_encap_set_options(encaps[i], &options);
    }

    sbrec_chassis_set_encaps(chassis_rec, encaps, n_encaps);
    free(encaps);

    inited = true;
    return chassis_rec;
}
Ejemplo n.º 24
0
/* Print management interface configuration.
 */
void
mgmt_intf_show(const struct ovsrec_system *row)
{
    const char *val;
    const char *subnet;

    val = smap_get(&row->mgmt_intf, SYSTEM_MGMT_INTF_MAP_MODE);
    if (val)
        vty_out(vty, "  Address Mode\t\t\t: %s%s", val, VTY_NEWLINE);
    else
        vty_out(vty, "  Address Mode\t\t\t: dhcp%s", VTY_NEWLINE);

    val = smap_get(&row->mgmt_intf_status, SYSTEM_MGMT_INTF_MAP_IP);
    subnet = smap_get(&row->mgmt_intf_status, SYSTEM_MGMT_INTF_MAP_SUBNET_MASK);

    if (val && subnet && (strcmp(val,MGMT_INTF_DEFAULT_IP) != 0))
        vty_out(vty, "  IPv4 address/subnet-mask\t: %s/%s%s", val, subnet,
                                                              VTY_NEWLINE);
    else
        vty_out(vty, "  IPv4 address/subnet-mask\t: %s", VTY_NEWLINE);

    val = smap_get(&row->mgmt_intf_status,
                   SYSTEM_MGMT_INTF_MAP_DEFAULT_GATEWAY);
    if (val && (strcmp(val,MGMT_INTF_DEFAULT_IP) != 0))
        vty_out(vty, "  Default gateway IPv4\t\t: %s%s", val, VTY_NEWLINE);
    else
        vty_out(vty, "  Default gateway IPv4\t\t: %s", VTY_NEWLINE);

    val = smap_get(&row->mgmt_intf_status, SYSTEM_MGMT_INTF_MAP_IPV6);
    if (val)
        vty_out(vty, "  IPv6 address/prefix\t\t: %s%s", val, VTY_NEWLINE);
    else
        vty_out(vty, "  IPv6 address/prefix\t\t: %s", VTY_NEWLINE);

    val = smap_get(&row->mgmt_intf_status, SYSTEM_MGMT_INTF_MAP_IPV6_LINKLOCAL);
    if (val)
        vty_out(vty, "  IPv6 link local address/prefix: %s%s", val,
                                                                   VTY_NEWLINE);
    else
        vty_out(vty, "  IPv6 link local address/prefix: %s", VTY_NEWLINE);

    val = smap_get(&row->mgmt_intf_status,
                                       SYSTEM_MGMT_INTF_MAP_DEFAULT_GATEWAY_V6);

    if (val)
        vty_out(vty, "  Default gateway IPv6\t\t: %s%s", val, VTY_NEWLINE);
    else
        vty_out(vty, "  Default gateway IPv6\t\t: %s",VTY_NEWLINE);

    val = smap_get(&row->mgmt_intf_status, SYSTEM_MGMT_INTF_MAP_DNS_SERVER_1);
    if (val && (strcmp(val,MGMT_INTF_DEFAULT_IP) != 0))
        vty_out(vty, "  Primary Nameserver\t\t: %s%s", val, VTY_NEWLINE);
    else
        vty_out(vty, "  Primary Nameserver\t\t: %s", VTY_NEWLINE);

    val = smap_get(&row->mgmt_intf_status, SYSTEM_MGMT_INTF_MAP_DNS_SERVER_2);
    if (val && (strcmp(val, MGMT_INTF_DEFAULT_IP) != 0))
        vty_out(vty, "  Secondary Nameserver\t\t: %s%s", val, VTY_NEWLINE);
    else
        vty_out(vty, "  Secondary Nameserver\t\t: %s", VTY_NEWLINE);
}
Ejemplo n.º 25
0
static const char *
get_chassis_id(const struct ovsdb_idl *ovs_idl)
{
    const struct ovsrec_open_vswitch *cfg = ovsrec_open_vswitch_first(ovs_idl);
    return cfg ? smap_get(&cfg->external_ids, "system-id") : NULL;
}
Ejemplo n.º 26
0
/**************************************************************************//**
 * This function processes port row to determine if hw_ready_state for each
 * interface needs to be set to true or false
 *
 * @param[in]   port_row       - Pointer to @see struct
 *                               ovsrec_port
 *
 * @return      A non-zero value if a transaction commit to
 *              OVSDB is required
*****************************************************************************/
static int
acl_port_update_hw_ready_state(const struct ovsrec_port *port_row)
{
    int rc = 0;
    unsigned int intf_idx;
    const char *hw_status = NULL;
    bool hw_ready_state = false;
    const char *port_admin_state = NULL;

    ovs_assert(port_row);

    VLOG_DBG("%s: port name: %s\n",__FUNCTION__,port_row->name);

    hw_ready_state = acl_ports_is_hw_ready(port_row);

    for(intf_idx = 0; intf_idx < port_row->n_interfaces; intf_idx++) {
        if (port_row->interfaces[intf_idx] == NULL) {
            continue;
        }

        hw_status =
             smap_get(
               (const struct smap *)&port_row->interfaces[intf_idx]->hw_status,
               OPS_INTF_HW_READY_KEY_STR);

        if (hw_ready_state) {

            if((hw_status == NULL) ||
               (strncmp(hw_status,
                        OPS_INTF_HW_READY_VALUE_STR_FALSE,
                        strlen(OPS_INTF_HW_READY_VALUE_STR_FALSE)) == 0)) {
                VLOG_DBG("port %s: setting hw_ready_state to true on "
                          "interface %s\n", port_row->name,
                          port_row->interfaces[intf_idx]->name);

                /* set interface hw_ready_state to true in db */
                ovsrec_interface_update_hw_status_setkey(
                                         port_row->interfaces[intf_idx],
                                         OPS_INTF_HW_READY_KEY_STR,
                                         OPS_INTF_HW_READY_VALUE_STR_TRUE);

                /* increment rc to indicate db update */
                rc++;
            }

            /* If hw_ready was blocked due to acls, set the hw_status
             * to true and delete hw_blocked_reason key
             */
            hw_status =
             smap_get(
              (const struct smap *)&port_row->interfaces[intf_idx]->hw_status,
              OPS_INTF_HW_READY_BLOCKED_REASON_STR);
            if((hw_status != NULL) &&
               (strncmp(hw_status, OPS_INTF_HW_READY_BLOCKED_REASON_VALUE_STR_ACLS,
                        strlen(OPS_INTF_HW_READY_BLOCKED_REASON_VALUE_STR_ACLS)) == 0)) {

                ovsrec_interface_update_hw_status_delkey(
                                     port_row->interfaces[intf_idx],
                                     OPS_INTF_HW_READY_BLOCKED_REASON_STR);

                /* set the user_config to up */
                ovsrec_interface_update_user_config_setkey(
                                port_row->interfaces[intf_idx],
                                INTERFACE_USER_CONFIG_MAP_ADMIN,
                                OVSREC_INTERFACE_USER_CONFIG_ADMIN_UP);

                /* update the admin_state in port table to up */
                port_admin_state = OVSREC_INTERFACE_ADMIN_STATE_UP;

                /* increment rc to indicate db update */
                rc++;
            }
        }
        else
        {
            if((hw_status == NULL) ||
               (strncmp(hw_status,
                        OPS_INTF_HW_READY_VALUE_STR_TRUE,
                        strlen(OPS_INTF_HW_READY_VALUE_STR_TRUE)) == 0)) {

                /* set interface hw_ready_state to false in db */
                ovsrec_interface_update_hw_status_setkey(
                                            port_row->interfaces[intf_idx],
                                            OPS_INTF_HW_READY_KEY_STR,
                                            OPS_INTF_HW_READY_VALUE_STR_FALSE);

                /* set interface hw_ready_blocked_reason in db */
                ovsrec_interface_update_hw_status_setkey(
                              port_row->interfaces[intf_idx],
                              OPS_INTF_HW_READY_BLOCKED_REASON_STR,
                              OPS_INTF_HW_READY_BLOCKED_REASON_VALUE_STR_ACLS);

                /* set the user_config to down */
                ovsrec_interface_update_user_config_setkey(
                                port_row->interfaces[intf_idx],
                                INTERFACE_USER_CONFIG_MAP_ADMIN,
                                OVSREC_INTERFACE_USER_CONFIG_ADMIN_DOWN);

                /* update the admin_state in port table to down */
                port_admin_state = OVSREC_INTERFACE_ADMIN_STATE_DOWN;

                /* increment rc to indicate db update */
                rc++;
            }
        }
    } /* end for loop */

    /* set the admin_state in port table */
    if (port_admin_state != NULL) {
        ovsrec_port_set_admin(port_row, port_admin_state);
    }

    return rc;
}
Ejemplo n.º 27
0
node_type lookup_keyword_enum(char *str) {
    if (smap_get(keyword_str_to_enum, keywords[0]) == -1) {
	initialize_keyword_to_enum_mapping();
    }
    return smap_get(keyword_str_to_enum, str);
}
Ejemplo n.º 28
0
void gather_decls(AST *ast, char *env, int is_top_level, int can_declare_function) {
    /* TODO: Implement me. */
    /* Hint: switch statements are pretty cool, and they work 
     *       brilliantly with enums. */
    if (ast) {
        smap_increment(stack_sizes,env,0);
        AST_lst *children = ast->children;
        switch (ast->type) {
            case node_STRING:
                smap_put(strings,ast->val, num_strings);//(intptr_t) ast->val);
                num_strings++;
                // don't need to check children because shouldn't have children
                break;
            case node_VAR:
                if (!is_top_level) { // if we're not in the top level stack
                    if (smap_get(stack_decls,ast->val) == -1) { // check the stack declarations first
                        if (smap_get(decls,ast->val) == -1) { // otherwise check the global declarations
                            fatal_error("Variable called is not defined"); // if not in either stack or global declarations -> ERROR
                        }
                    }
                } else { // otherwise directly check global declarations
                    if (smap_get(decls,ast->val) == -1) {
                        fatal_error("Variable called is not defined");
                    }
                }
                break;
            case node_CALL:
                if (smap_get(func_decls,ast->val) == -1) {
                    fatal_error("Function called is not defined");
                }
                break;
            case node_FUNCTION:
                if (!can_declare_function) {
                    fatal_error("Tried to declare function when not at top level");
                }
                AST *first_child = children->val;
                if (smap_get(func_decls,first_child->val) != -1) {
                    fatal_error("Tried to declare function that already exists");
                } else {
                    smap_put(func_decls,first_child->val,smap_get(stack_sizes,env)); // still not sure about value either, maybe just set to 1
                }
                smap_put(stack_sizes,first_child->val,0); // initialized stack_size for this function
                is_top_level = 0;
                smap_del(stack_decls); // clean out whatever was in stack_decls from a previous function declaration
                stack_decls = smap_new();
                AST_lst *grandchildren = first_child->children;
                while (grandchildren) {
                    smap_put(stack_decls,(grandchildren->val)->val,smap_get(stack_sizes,first_child->val)); // again, not sure aboue value yet
                    smap_increment(stack_sizes,first_child->val,1); // increment only by one cause I'm just gonna count the number of words
                    grandchildren = grandchildren->next;
                }
                children = children->next;
                break;
            case node_ASSIGN:
                if (!strcmp(env,"if") || !strcmp(env,"for") || !strcmp(env,"while")) { // can be assigned to but just can't be declared
                    if (!is_top_level) {
                        if (smap_get(stack_decls,(children->val)->val) == -1 && smap_get(decls,(children->val)->val) == -1) {
                            fatal_error("Tried to declare variable in IF/FOR/WHILE");
                        }
                    } else {
                        if (smap_get(decls,(children->val)->val) == -1) {
                            fatal_error("Tried to declare variable in IF/FOR/WHILE");
                        }
                    }
                }
                if (!is_top_level) { // if we're not in the top level stack
                    if (smap_get(stack_decls,(children->val)->val) == -1 && smap_get(decls,(children->val)->val) == -1) { // if it's not in either stack or global declarations
                        smap_put(stack_decls,(children->val)->val,smap_get(stack_sizes,env)); // put it in the stack_declarations, still unsure about value
                        smap_increment(stack_sizes,env,1); // increment the stack size
                    }
                } else { // else we're just in the global stack frame
                    if (smap_get(decls,(children->val)->val) == -1) { // if not there
                        if (size_of_decls_arr == 0) {
                            decls_arr = safe_malloc(sizeof(char *));
                        } else {
                            decls_arr = safe_realloc(decls_arr,(size_of_decls_arr + 1) * sizeof(char *));
                        }
                        decls_arr[size_of_decls_arr] = (children->val)->val;
                        size_of_decls_arr++;
                        smap_increment(stack_sizes,env,1);  // increment stack size of env = "" global frame...should equal size_of_decls_arr;
                    }
                    smap_put(decls,(children->val)->val, smap_get(stack_sizes,env)); // still not sure about value
                }
                break;
        }
        can_declare_function = 0;
        while (children) {
            if (ast->type == node_IF || ast->type == node_WHILE || ast->type == node_FOR) {
                gather_decls(children->val,ast->val,is_top_level, can_declare_function);
            } else if (ast->type == node_FUNCTION) {
                gather_decls(children->val,((ast->children)->val)->val,is_top_level, can_declare_function);
            } else {
                gather_decls(children->val,env,is_top_level, can_declare_function);
            }
            children = children->next;
        }
    }

}
Ejemplo n.º 29
0
/* Configuring IPv6 default gateway on management interface.
 * On success, returns CMD_SUCCESS. On failure, returns CMD_OVSDB_FAILURE.
 */
static int
mgmt_intf_set_default_gw_ipv6(bool set, const char *gw_v6)
{
    const struct ovsrec_system *row = NULL;
    struct smap smap = SMAP_INITIALIZER(&smap);
    const char *cfg_gw = NULL;
    struct ovsdb_idl_txn* status_txn = NULL;
    enum ovsdb_idl_txn_status status;

    if (!is_valid_ip_address(gw_v6))
    {
        vty_out(vty, "  %s %s", OVSDB_INVALID_IPV4_IPV6_ERROR,VTY_NEWLINE);
        return CMD_SUCCESS;
    }

    status_txn = cli_do_config_start();
    if (NULL == status_txn)
    {
        VLOG_ERR(OVSDB_TXN_CREATE_ERROR);
        cli_do_config_abort(status_txn);
        return CMD_OVSDB_FAILURE;
    }

    row = ovsrec_system_first(idl);

    if (!row)
    {
        VLOG_ERR(OVSDB_ROW_FETCH_ERROR);
        cli_do_config_abort(status_txn);
        return CMD_OVSDB_FAILURE;
    }

    if (!is_mode_static(row))
    {
        vty_out(vty, "  %s %s", OVSDB_MODE_ERROR, VTY_NEWLINE);
        cli_do_config_abort(status_txn);
        return CMD_SUCCESS;
    }

    smap_clone(&smap, &row->mgmt_intf);

    if(!smap_get(&smap, SYSTEM_MGMT_INTF_MAP_IPV6))
    {
        vty_out(vty, "  %s %s", OVSDB_NO_IP_ERROR, VTY_NEWLINE);
        cli_do_config_abort(status_txn);
        smap_destroy(&smap);
        return CMD_SUCCESS;
    }

    if (set)
    {
        smap_replace(&smap, SYSTEM_MGMT_INTF_MAP_DEFAULT_GATEWAY_V6, gw_v6);
    }
    else
    {
        cfg_gw = smap_get(&smap, SYSTEM_MGMT_INTF_MAP_DEFAULT_GATEWAY_V6);
        if (!cfg_gw || strcmp(gw_v6, cfg_gw) != 0)
        {
            vty_out(vty, "  %s %s", OVSDB_INVALID_VALUE_ERROR, VTY_NEWLINE);
            cli_do_config_abort(status_txn);
            smap_destroy(&smap);
            return CMD_SUCCESS;
        }

        smap_replace(&smap, SYSTEM_MGMT_INTF_MAP_DEFAULT_GATEWAY_V6,
                                            MGMT_INTF_DEFAULT_IPV6);

    }

    ovsrec_system_set_mgmt_intf(row, &smap);

    smap_destroy(&smap);

    status = cli_do_config_finish(status_txn);
    if (TXN_SUCCESS == status || TXN_UNCHANGED == status)
    {
        return CMD_SUCCESS;
    }
    else
    {
        VLOG_ERR(OVSDB_TXN_COMMIT_ERROR);
        return CMD_OVSDB_FAILURE;
    }
}
Ejemplo n.º 30
0
/* Configuring management interface DNS server.
 * On success, returns CMD_SUCCESS. On failure, returns CMD_OVSDB_FAILURE.
 */
static int
mgmt_intf_set_dns(bool set, const char *dns1, const char *dns2)
{
    const struct ovsrec_system *row = NULL;
    struct smap smap = SMAP_INITIALIZER(&smap);
    const char *cfg_dns1 = NULL;
    const char *cfg_dns2 = NULL;
    struct ovsdb_idl_txn* status_txn = NULL;
    enum ovsdb_idl_txn_status status;

    status_txn = cli_do_config_start();
    if (NULL == status_txn)
    {
        VLOG_ERR(OVSDB_TXN_CREATE_ERROR);
        cli_do_config_abort(status_txn);
        return CMD_OVSDB_FAILURE;
    }

    row = ovsrec_system_first(idl);

    if (!row)
    {
        VLOG_ERR(OVSDB_ROW_FETCH_ERROR);
        cli_do_config_abort(status_txn);
        return CMD_OVSDB_FAILURE;
    }

    smap_clone(&smap, &row->mgmt_intf);

    /* Handle primary DNS server configuration. */
    if (set)
    {
        smap_replace(&smap, SYSTEM_MGMT_INTF_MAP_DNS_SERVER_1, dns1);

        if (dns2)
        {
            smap_replace(&smap, SYSTEM_MGMT_INTF_MAP_DNS_SERVER_2, dns2);
        }
        else
        {
            smap_replace(&smap, SYSTEM_MGMT_INTF_MAP_DNS_SERVER_2,
                                            MGMT_INTF_DEFAULT_IP);
        }
    }
    else
    {
        cfg_dns1 = smap_get(&smap, SYSTEM_MGMT_INTF_MAP_DNS_SERVER_1);
        if (!cfg_dns1 || strcmp(dns1, cfg_dns1) != 0)
        {
            vty_out(vty, "  %s %s", OVSDB_INVALID_VALUE_ERROR, VTY_NEWLINE);
            cli_do_config_abort(status_txn);
            smap_destroy(&smap);
            return CMD_SUCCESS;
        }

        cfg_dns2 = smap_get(&smap, SYSTEM_MGMT_INTF_MAP_DNS_SERVER_2);
        if (dns2)
        {
            if (!cfg_dns2 || strcmp(dns2, cfg_dns2) != 0)
            {
                vty_out(vty, "  %s %s", OVSDB_INVALID_VALUE_ERROR, VTY_NEWLINE);
                cli_do_config_abort(status_txn);
                smap_destroy(&smap);
                return CMD_SUCCESS;
            }

            smap_replace(&smap, SYSTEM_MGMT_INTF_MAP_DNS_SERVER_2,
                                              MGMT_INTF_DEFAULT_IP);
        }
        else if (cfg_dns2 && strcmp(cfg_dns2, MGMT_INTF_DEFAULT_IP) != 0)
        {
            vty_out(vty, "  %s %s", OVSDB_DNS_DEPENDENCY_ERROR, VTY_NEWLINE);
            cli_do_config_abort(status_txn);
            smap_destroy(&smap);
            return CMD_SUCCESS;
        }

        smap_replace(&smap, SYSTEM_MGMT_INTF_MAP_DNS_SERVER_1,
                                              MGMT_INTF_DEFAULT_IP);
    }

    ovsrec_system_set_mgmt_intf(row, &smap);

    smap_destroy(&smap);

    status = cli_do_config_finish(status_txn);
    if (TXN_SUCCESS == status || TXN_UNCHANGED == status)
    {
        return CMD_SUCCESS;
    }
    else
    {
        VLOG_ERR(OVSDB_TXN_COMMIT_ERROR);
        return CMD_OVSDB_FAILURE;
    }
}