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;
}
예제 #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;
}
예제 #3
0
/**
 * Check global QOS trust setting.
 *   Keeps track of global QOS trust value.
 *   Sets internal "global trust changed" flag that is used when looping
 *      all the Ports in a Bridge or VRF.
 *
 * @param idl       - pointer to IDL
 * @param idl_seqno - current transaction sequence number
 */
void
qos_check_if_global_trust_changed(struct ovsdb_idl *idl, unsigned int idl_seqno)
{
    enum qos_trust qos_trust;
    const struct ovsrec_system *ovs_row = NULL;


    /* Clear global trust changed indicator. */
    global_trust_changed = false;

    /* nothing to do if System row is unchanged. */
    ovs_row = ovsrec_system_first(idl);
    if (OVSREC_IDL_IS_ROW_MODIFIED(ovs_row, idl_seqno) &&
        OVSREC_IDL_IS_COLUMN_MODIFIED(ovsrec_system_col_qos_config, idl_seqno))
    {
        qos_trust = get_qos_trust_value(&ovs_row->qos_config);

        /* only change saved QoS trust if default is valid */
        if (qos_trust != QOS_TRUST_MAX) {
            if (qos_trust != global_qos_trust)
            {
                /* Indicate trust change to rest of the world. */
                global_trust_changed = true;
                global_qos_trust = qos_trust;
            }
        }
    }

    return;
}
예제 #4
0
/* Configure management interface as dhcp mode.
 * On success, returns CMD_SUCCESS. On failure, returns CMD_OVSDB_FAILURE.
 */
static int
mgmt_intf_set_dhcp()
{
    const struct ovsrec_system *row = NULL;
    struct ovsdb_idl_txn* status_txn = NULL;
    enum ovsdb_idl_txn_status status;
    struct smap smap = SMAP_INITIALIZER(&smap);

    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 current mode is static remove static configs from DB. */
    smap_clone(&smap, &row->mgmt_intf);
    if (is_mode_static(row))
    {
        mgmt_intf_clear_ipv4_config_db(row, &smap);
        mgmt_intf_clear_ipv6_config_db(row, &smap);
    }

    smap_replace(&smap,
                 SYSTEM_MGMT_INTF_MAP_MODE,
                 SYSTEM_MGMT_INTF_MAP_MODE_DHCP);

    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;
    }
}
예제 #5
0
/*
 * Function        : cli_system_get_all
 * Resposibility     : Get System overview information from OVSDB
 * Return      : 0 on success 1 otherwise
 */
int
cli_system_get_all()
{
    const struct ovsrec_subsystem* pSys = NULL;
    const struct ovsrec_system* pVswitch = NULL;
    const struct ovsrec_fan* pFan = NULL;
    struct ovsrec_fan* pFanSort = NULL;
    const struct ovsrec_led* pLed = NULL;
    const struct ovsrec_power_supply* pPSU = NULL;
    const struct ovsrec_temp_sensor* pTempSen = NULL;
    int n = 0, i = 0;

    pSys = ovsrec_subsystem_first(idl);
    pVswitch = ovsrec_system_first(idl);

    if (pSys && pVswitch)
    {
        format_sys_output(vty, pSys,pVswitch);
    }
    else
        VLOG_ERR("Unable to retrieve data\n");


    vty_out(vty,"%sFan details:%s%s",VTY_NEWLINE,VTY_NEWLINE, VTY_NEWLINE);
    vty_out(vty,"%-15s%-10s%-10s%s","Name","Speed","Status",VTY_NEWLINE);
    vty_out(vty,"%s%s","--------------------------------",VTY_NEWLINE);
    n = pSys->n_fans;
    if (0 != n)
    {
        pFanSort = (struct ovsrec_fan*)calloc (n,sizeof(struct ovsrec_fan));

        OVSREC_FAN_FOR_EACH (pFan,idl)
        {
            if (pFan)
            {
                memcpy (pFanSort+i,pFan,sizeof(struct ovsrec_fan));
                i++;
            }
        }

        qsort((void*)pFanSort,n,sizeof(struct ovsrec_fan),compare_fan);

        for (i = 0; i < n ; i++)
        {
            vty_out(vty,"%-15s",(pFanSort+i)->name);
            vty_out(vty,"%-10s",(pFanSort+i)->speed);
            vty_out(vty,"%-10s",(pFanSort+i)->status);
            vty_out(vty,"%s",VTY_NEWLINE);
        }
    }
예제 #6
0
파일: ecmp_vty.c 프로젝트: bluecmd/ops-cli
static int
ecmp_config_set_status (bool status, const char * field)
{
  const struct ovsrec_system *ovs_row = NULL;
  enum ovsdb_idl_txn_status txn_status;
  struct ovsdb_idl_txn *status_txn = cli_do_config_start ();
  bool rc = false;
  struct smap smap_ecmp_config;

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

  /* Need to set ecmp_config status */
  ovs_row = ovsrec_system_first (idl);

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

  rc = smap_get_bool (&ovs_row->ecmp_config, field,
                      SYSTEM_ECMP_CONFIG_ENABLE_DEFAULT);

  if (rc != status)
    {
      smap_clone (&smap_ecmp_config, &ovs_row->ecmp_config);
      smap_replace (&smap_ecmp_config, field, status ? "true" : "false");
      VLOG_DBG ("%s Set the ecmp config to status = %s old state = %s",
                __func__, status ? "enabled" : "disabled",
                rc ? "enabled" : "disabled");
      ovsrec_system_set_ecmp_config (ovs_row, &smap_ecmp_config);
      smap_destroy (&smap_ecmp_config);
    }

  txn_status = cli_do_config_finish (status_txn);

  if (txn_status == TXN_SUCCESS || txn_status == TXN_UNCHANGED)
    return CMD_SUCCESS;
  else
    {
      VLOG_ERR (OVSDB_TXN_COMMIT_ERROR);
      return CMD_OVSDB_FAILURE;
    }
}
예제 #7
0
/*-----------------------------------------------------------------------------
| Function : sftp_server_enable_disable
| Responsibility : To enable/disable SFTP server.
| Parameters :
|     bool enable: If true, enable SFTP server and if false
|                  disable the SFTP server.
| Return : On success returns CMD_SUCCESS,
|          On failure returns CMD_OVSDB_FAILURE
-----------------------------------------------------------------------------*/
static int
sftp_server_enable_disable (bool enable)
{
    const struct ovsrec_system *row = NULL;
    enum ovsdb_idl_txn_status txn_status;
    struct ovsdb_idl_txn *status_txn = cli_do_config_start();
    struct smap smap;

    if (status_txn == NULL)
    {
        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->other_config);

    if (enable) {
        smap_replace(&smap, SFTP_SERVER_CONFIG, "true");
    } else {
        smap_replace(&smap, SFTP_SERVER_CONFIG, "false");
    }

    ovsrec_system_set_other_config(row, &smap);

    txn_status = cli_do_config_finish(status_txn);
    smap_destroy(&smap);

    if (txn_status == TXN_SUCCESS || txn_status == TXN_UNCHANGED)
    {
        return CMD_SUCCESS;
    }
    else
    {
        VLOG_ERR(OVSDB_TXN_COMMIT_ERROR);
        return CMD_OVSDB_FAILURE;
    }
}
static inline bool
classifierd_system_is_configured(void)
{
    const struct ovsrec_system *sysrow = NULL;

    if (system_configured) {
        return true;
    }

    sysrow = ovsrec_system_first(idl);
    if (sysrow && sysrow->cur_cfg > INT64_C(0)) {
        VLOG_DBG("System now configured (cur_cfg=%" PRId64 ").",
                 sysrow->cur_cfg);
        return (system_configured = true);
    }

    return false;
} /* classifierd_system_is_configured */
예제 #9
0
/*-----------------------------------------------------------------------------
| Function       : udpfwd_globalconfig
| Responsibility : To enable/disable udp broadcast forwarding and dhcp-relay.
| Parameters     :
|        status  : If true, enable UDP broadcast forwarding/dhcp-relay and
|                  if false disable the UDP broadcast forwarding/dhcp-relay
| Return         : On success returns CMD_SUCCESS,
|                  On failure returns CMD_OVSDB_FAILURE
-----------------------------------------------------------------------------*/
int8_t udpfwd_globalconfig(const char *status)
{
    const struct ovsrec_system *ovs_row = NULL;
    struct ovsdb_idl_txn *status_txn = cli_do_config_start();
    struct smap smap_status_value;
    enum ovsdb_idl_txn_status txn_status;
    char *key = NULL;

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

    ovs_row = ovsrec_system_first(idl);
    if (!ovs_row) {
        VLOG_ERR(OVSDB_ROW_FETCH_ERROR);
        cli_do_config_abort(status_txn);
        return CMD_OVSDB_FAILURE;
    }

    key = SYSTEM_OTHER_CONFIG_MAP_UDP_BCAST_FWD_ENABLED;

    smap_clone(&smap_status_value, &ovs_row->other_config);

    /* Update the latest config status. */
    smap_replace(&smap_status_value, key, status);

    ovsrec_system_set_other_config(ovs_row, &smap_status_value);
    smap_destroy(&smap_status_value);
    txn_status = cli_do_config_finish(status_txn);

    if (txn_status == TXN_SUCCESS || txn_status == TXN_UNCHANGED)
    {
        return CMD_SUCCESS;
    }
    else
    {
        VLOG_ERR(OVSDB_TXN_COMMIT_ERROR);
        return CMD_OVSDB_FAILURE;
    }
}
예제 #10
0
/* Sets logrotation period value in DB*/
static int set_logrotate_period(const char *period_value)
{
    const struct ovsrec_system *ovs = NULL;
    enum ovsdb_idl_txn_status txn_status;
    struct ovsdb_idl_txn *txn = cli_do_config_start();


    if (NULL == txn)
        {
        VLOG_ERR_LOGROTATE_TRANSACTION_CREATE_FAILED;
        cli_do_config_abort(txn);
        return CMD_OVSDB_FAILURE;
        }

    ovs = ovsrec_system_first(idl);
    if (NULL == ovs)
        {
        VLOG_ERR_LOGROTATE_OPENVSWITCH_READ_FAILED;
        cli_do_config_abort(txn);
        return CMD_OVSDB_FAILURE;
        }

    if(NULL != period_value)
        {
        smap_replace((struct smap *)&ovs->logrotate_config, SYSTEM_LOGROTATE_CONFIG_MAP_PERIOD, period_value);
        }

    ovsrec_system_set_logrotate_config(ovs, &ovs->logrotate_config);

    txn_status = cli_do_config_finish(txn);

    if(txn_status == TXN_SUCCESS || txn_status == TXN_UNCHANGED)
        {
        return CMD_SUCCESS;
        }
    else
        {
        VLOG_ERR(OVSDB_TXN_COMMIT_ERROR);
        return CMD_OVSDB_FAILURE;
        }
}
예제 #11
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;
    }
}
예제 #12
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;
    }
}
예제 #13
0
/* Configuring static ip on management interface.
 * On success, returns CMD_SUCCESS. On failure, returns CMD_OVSDB_FAILURE.
 */
static int
mgmt_intf_set_static(bool set, const char *ip, enum ip_type type)
{
    const struct ovsrec_system *row = NULL;
    struct smap smap = SMAP_INITIALIZER(&smap);
    struct ovsdb_idl_txn* status_txn = NULL;
    enum ovsdb_idl_txn_status status;

    const char *subnet = NULL;
    const char *ip_addr = NULL;
    unsigned short subnet_in = 0;
    char buf[MAX_IPV4_OR_IPV6_SUBNET_CIDR_STR_LEN];

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

    memset(buf, 0, MAX_IPV4_OR_IPV6_SUBNET_CIDR_STR_LEN);
    strncpy(buf, ip, MAX_IPV4_OR_IPV6_SUBNET_CIDR_STR_LEN);
    ip_addr   = strtok(buf, "/");
    subnet    = strtok(NULL, "\0");
    subnet_in = atoi(subnet);

    if (IPV4 == type)
    {
        if (IS_INVALID_IPV4_SUBNET(subnet_in))
        {
            vty_out(vty, "  %s %s", OVSDB_INVALID_SUBNET_ERROR, VTY_NEWLINE);
            return CMD_SUCCESS;
        }
    }else if (IPV6 == type) {
        if (IS_INVALID_IPV6_SUBNET(subnet_in))
        {
            vty_out(vty, "  %s %s", OVSDB_INVALID_SUBNET_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;
    }

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

    if (set)
        smap_replace(&smap, SYSTEM_MGMT_INTF_MAP_MODE,
                            SYSTEM_MGMT_INTF_MAP_MODE_STATIC);

    if (IPV4 == type) {
        if (set)
        {
            smap_replace(&smap, SYSTEM_MGMT_INTF_MAP_IP, ip_addr);
            smap_replace(&smap, SYSTEM_MGMT_INTF_MAP_SUBNET_MASK, subnet);
        }
        else
        {
            if (mgmt_intf_remove_static_ipv4_address(&smap, ip_addr, subnet)
                                                               != CMD_SUCCESS)
            {
                cli_do_config_abort(status_txn);
                smap_destroy(&smap);
                return CMD_SUCCESS;
            }
        }
    }else if (IPV6 == type) {
        if (set)
            smap_replace(&smap, SYSTEM_MGMT_INTF_MAP_IPV6, ip);
        else
        {
            if (mgmt_intf_remove_static_ipv6_address(&smap, ip) != CMD_SUCCESS)
            {
                cli_do_config_abort(status_txn);
                smap_destroy(&smap);
                return CMD_SUCCESS;
            }
        }
    }

    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;
    }
}
예제 #14
0
}

DEFUN (show_logrotate_config,
       show_logrotate_cmd,
       "show logrotate",
       SHOW_STR
       "Show logrotate config parameters\n"
       )
{
    const struct ovsrec_system *ovs = NULL;
    const char *data = NULL;

    ovsdb_idl_run(idl);
    ovsdb_idl_wait(idl);

    ovs = ovsrec_system_first(idl);

    if(ovs) {
        vty_out (vty, "Logrotate configurations : %s", VTY_NEWLINE);
        data = smap_get(&ovs->logrotate_config, SYSTEM_LOGROTATE_CONFIG_MAP_PERIOD);
        vty_out (vty, "Period            : %s%s", (NULL == data) ? SYSTEM_LOGROTATE_CONFIG_MAP_PERIOD_DEFAULT : data, VTY_NEWLINE);
        data = smap_get(&ovs->logrotate_config, SYSTEM_LOGROTATE_CONFIG_MAP_MAXSIZE);
        vty_out (vty, "Maxsize           : %sMB%s", (NULL == data) ? SYSTEM_LOGROTATE_CONFIG_MAP_MAXSIZE_DEFAULT : data, VTY_NEWLINE);
        data = smap_get(&ovs->logrotate_config, SYSTEM_LOGROTATE_CONFIG_MAP_TARGET);
        if (data != NULL)
            {
            vty_out (vty, "Target            : %s%s", smap_get(&ovs->logrotate_config, SYSTEM_LOGROTATE_CONFIG_MAP_TARGET), VTY_NEWLINE);
            }
    }
    else {
        VLOG_ERR("Couldn't retrieve any logrotate columns");
/*-----------------------------------------------------------------------------
| Function : vtysh_dhcp_relay_context_clientcallback
| Responsibility : client callback routine for dhcp-relay
| 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_dhcp_relay_context_clientcallback (void *p_private)
{
    vtysh_ovsdb_cbmsg_ptr p_msg = (vtysh_ovsdb_cbmsg *)p_private;
    const struct ovsrec_system *ovs_row = NULL;
    char *status = NULL;
    char *validation_status = NULL;
    char *policy = NULL;
    char *remote_id = NULL;

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

    status = (char *)smap_get(&ovs_row->dhcp_config,
                                  SYSTEM_DHCP_CONFIG_MAP_V4RELAY_DISABLED);
    if (status && !strcmp(status, "true")) {
        vtysh_ovsdb_cli_print(p_msg, "%s", "no dhcp-relay");
    }

    status = (char *)smap_get(&ovs_row->dhcp_config,
                 SYSTEM_DHCP_CONFIG_MAP_V4RELAY_HOP_COUNT_INCREMENT_DISABLED);
    if (status && !strcmp(status, "true")) {
        vtysh_ovsdb_cli_print(p_msg, "%s", "no dhcp-relay hop-count-increment");
    }

    status = (char *)smap_get(&ovs_row->dhcp_config,
                 SYSTEM_DHCP_CONFIG_MAP_V4RELAY_OPTION82_ENABLED);
    validation_status = (char *)smap_get(&ovs_row->dhcp_config,
                 SYSTEM_DHCP_CONFIG_MAP_V4RELAY_OPTION82_VALIDATION_ENABLED);
    policy = (char *)smap_get(&ovs_row->dhcp_config,
                 SYSTEM_DHCP_CONFIG_MAP_V4RELAY_OPTION82_POLICY);

    if (policy == NULL) {
        /*
         * To display the default policy "replace" in the running-config
         * of option 82 with validation.
         */
        policy = "replace";
    }
    remote_id = (char *)smap_get(&ovs_row->dhcp_config,
                 SYSTEM_DHCP_CONFIG_MAP_V4RELAY_OPTION82_REMOTE_ID);
    if (status && !strcmp(status, "true")) {
        if (policy != NULL) {
            if (validation_status && !strcmp(validation_status, "true")) {
                if (remote_id && !strcmp(remote_id, "ip")) {
                    vtysh_ovsdb_cli_print(p_msg, "%s %s %s",
                          "dhcp-relay option 82", policy, "validate ip");
                }
                else {
                    vtysh_ovsdb_cli_print(p_msg, "%s %s %s",
                          "dhcp-relay option 82", policy, "validate");
                }
            }
            else {
                if (remote_id && !strcmp(remote_id, "ip")) {
                    vtysh_ovsdb_cli_print(p_msg, "%s %s %s",
                          "dhcp-relay option 82", policy, "ip");
                }
                else {
                vtysh_ovsdb_cli_print(p_msg, "%s %s",
                          "dhcp-relay option 82", policy);
                }
            }
        }
    }

    return e_vtysh_ok;
}
예제 #16
0
/* Sets logrotation target uri in DB*/
static int set_logrotate_target(const char *uri)
{
    const struct ovsrec_system *ovs = NULL;
    enum ovsdb_idl_txn_status txn_status;
    struct ovsdb_idl_txn *txn;
    const char *ip_value;
    struct in_addr addr;
    struct in6_addr addrv6;
    boolean is_ipv4 = TRUE;

    if(strncmp(uri,SYSTEM_LOGROTATE_CONFIG_MAP_TARGET_DEFAULT,5))
        {
        if(strlen(uri) <= 7)
            {
            VLOG_ERR("URI not valid\n");
            return CMD_ERR_NOTHING_TODO;
            }
        if(strncmp(uri,"tftp://",7))
            {
            VLOG_ERR("Only tftp protocol is supported\n");
            return CMD_ERR_NOTHING_TODO;
            }

        ip_value = uri+7;

        if(inet_pton(AF_INET, ip_value,&addr) <= 0)
            {
            if(inet_pton(AF_INET6, ip_value, &addrv6) <= 0)
                {
                VLOG_ERR("Invalid IPv4 or IPv6 address\n");
                return CMD_ERR_NOTHING_TODO;
                }
            is_ipv4 = FALSE;
            }

        if(is_ipv4 && (!IS_VALID_IPV4(htonl(addr.s_addr))))
            {
            VLOG_ERR("IPv4 :Broadcast, multicast and loopback addresses are not allowed\n");
            return CMD_ERR_NOTHING_TODO;
            }

        if((!is_ipv4) && (!IS_VALID_IPV6(&addrv6)))
            {
            VLOG_ERR("IPv6 :Multicast and loopback addresses are not allowed\n");
            return CMD_ERR_NOTHING_TODO;
            }
        }

    txn = cli_do_config_start();
    if (NULL == txn)
        {
        VLOG_ERR_LOGROTATE_TRANSACTION_CREATE_FAILED;
        cli_do_config_abort(txn);
        return CMD_OVSDB_FAILURE;
        }

    ovs = ovsrec_system_first(idl);
    if (NULL == ovs)
        {
        VLOG_ERR_LOGROTATE_OPENVSWITCH_READ_FAILED;
        cli_do_config_abort(txn);
        return CMD_OVSDB_FAILURE;
        }

    if((NULL != uri) && (strncmp(uri,SYSTEM_LOGROTATE_CONFIG_MAP_TARGET_DEFAULT,5)))
        {
        smap_replace((struct smap *)&ovs->logrotate_config, SYSTEM_LOGROTATE_CONFIG_MAP_TARGET, uri);
        }
    else
        {
        smap_remove((struct smap *)&ovs->logrotate_config, SYSTEM_LOGROTATE_CONFIG_MAP_TARGET);
        }

    ovsrec_system_set_logrotate_config(ovs, &ovs->logrotate_config);

    txn_status = cli_do_config_finish(txn);

    if(txn_status == TXN_SUCCESS || txn_status == TXN_UNCHANGED)
        {
        return CMD_SUCCESS;
        }
    else
        {
        VLOG_ERR(OVSDB_TXN_COMMIT_ERROR);
        return CMD_OVSDB_FAILURE;
        }
}
/**
 * Executes the qos_apply_port_command for the given port_name and
 * schedule_profile_name.
 */
static int
qos_apply_port_command(const char *port_name,
        const char *schedule_profile_name)
{
    if (port_name == NULL) {
        vty_out(vty, "port_name cannot be NULL.%s", VTY_NEWLINE);
        return CMD_OVSDB_FAILURE;
    }

    if (schedule_profile_name == NULL) {
        vty_out(vty, "schedule_profile_name cannot be NULL.%s", VTY_NEWLINE);
        return CMD_OVSDB_FAILURE;
    }

    if (!qos_is_valid_string(schedule_profile_name)) {
        vty_out(vty, QOS_INVALID_STRING_ERROR_MESSAGE, VTY_NEWLINE);
        return CMD_OVSDB_FAILURE;
    }

    if (is_member_of_lag(port_name)) {
        vty_out(vty, "QoS Schedule Profile cannot be\
 configured on a member of a LAG.%s",
                VTY_NEWLINE);
        return CMD_OVSDB_FAILURE;
    }

    /* Retrieve the system row. */
    const struct ovsrec_system *system_row = ovsrec_system_first(idl);
    if (system_row == NULL) {
        vty_out(vty, "System config does not exist.%s", VTY_NEWLINE);
        return CMD_OVSDB_FAILURE;
    }

    /* Get the queue profile from the system row. */
    struct ovsrec_q_profile *queue_profile_row = system_row->q_profile;

    /* If the profile is strict, make sure the 'strict' profile exists. */
    if (strncmp(schedule_profile_name, OVSREC_QUEUE_ALGORITHM_STRICT,
            QOS_CLI_STRING_BUFFER_SIZE) == 0) {
        int result = qos_schedule_profile_create_strict_profile_commit();
        if (result != CMD_SUCCESS) {
            return result;
        }
    }

    /* Retrieve the schedule profile. */
    struct ovsrec_qos *schedule_profile_row = qos_get_schedule_profile_row(
            schedule_profile_name);
    if (schedule_profile_row == NULL) {
        vty_out(vty, "Profile %s does not exist.%s",
                schedule_profile_name, VTY_NEWLINE);
        return CMD_OVSDB_FAILURE;
    }

    /* Perform some checks, but only if the profile is not strict.
     * The strict profile does not contain any queues. */
    if (strncmp(schedule_profile_name, OVSREC_QUEUE_ALGORITHM_STRICT,
            QOS_CLI_STRING_BUFFER_SIZE) != 0) {
        /* Check that the profile is complete. */
        if (!qos_schedule_profile_is_complete(schedule_profile_row, true)) {
            return CMD_OVSDB_FAILURE;
        }

        /* Check that profiles contain all the same queues. */
        if (!qos_profiles_contain_same_queues(queue_profile_row,
                schedule_profile_row)) {
            vty_out(vty, "The queue profile and schedule profile\
 cannot contain different queues.%s", VTY_NEWLINE);
            return CMD_OVSDB_FAILURE;
        }
    }
예제 #18
0
/*-----------------------------------------------------------------------------
| Responsibility : To show the UDP Broadcast Forwarder configurations.
| Parameters     :
|       *ifname  : Interface name
| Return         : On success returns CMD_SUCCESS,
|                  On failure returns CMD_OVSDB_FAILURE
-----------------------------------------------------------------------------*/
int8_t
show_udp_forwarder_configuration (const char *ifname)
{
    const struct ovsrec_udp_bcast_forwarder_server *row_serv = NULL;
    const struct ovsrec_system *ovs_row = NULL;
    const struct ovsdb_datum *datum = NULL;
    char *udp_status = NULL ;
    int index = 0;
    size_t i = 0;
    bool entry_found = false;

    ovs_row = ovsrec_system_first(idl);
    if (ovs_row == NULL)
    {
        VLOG_ERR(OVSDB_ROW_FETCH_ERROR);
        return CMD_OVSDB_FAILURE;
    }

    udp_status = (char *)smap_get(&ovs_row->other_config,
                         SYSTEM_OTHER_CONFIG_MAP_UDP_BCAST_FWD_ENABLED);
    if (!udp_status)
    {
        udp_status = "disabled";
    }
    else
    {
        if (!strcmp(udp_status, "true"))
            udp_status = "enabled";
        else
            udp_status = "disabled";
    }

    vty_out(vty, "%sUDP Broadcast Forwarder : %s%s", VTY_NEWLINE,
            udp_status, VTY_NEWLINE);
    vty_out(vty, "%s", VTY_NEWLINE);

    if (ifname)
    {
        vty_out(vty, "Interface: %s%s", ifname, VTY_NEWLINE);
        vty_out(vty, "%2sIP Forward Addresses%4sUDP Port %s", "", "",
                     VTY_NEWLINE);
        vty_out(vty, "%2s------------------------------- %s", "",
                     VTY_NEWLINE);
    }

    row_serv = ovsrec_udp_bcast_forwarder_server_first(idl);

    OVSREC_UDP_BCAST_FORWARDER_SERVER_FOR_EACH (row_serv, idl)
    {
        /* get the interface details. */
        if(row_serv->src_port)
        {
            if (ifname)
            {
                if(!strcmp(row_serv->src_port->name, ifname))
                {
                    if(row_serv->n_ipv4_ucast_server)
                    {
                        for (i = 0; i < row_serv->n_ipv4_ucast_server; i++)
                        {
                            /* get the UDP port number. */
                            datum =
                            ovsrec_udp_bcast_forwarder_server_get_udp_dport
                                    (row_serv, OVSDB_TYPE_INTEGER);
                            if ((NULL!=datum) && (datum->n >0))
                            {
                                index = datum->keys[0].integer;
                            }
                            vty_out(vty, "%2s%s%16s%d%s", "",
                                    row_serv->ipv4_ucast_server[i], "",
                                    index, VTY_NEWLINE);
                        }
                        entry_found = true;
                    }
                }
            }
            else
            {
                vty_out(vty, "Interface: %s%s",
                        row_serv->src_port->name, VTY_NEWLINE);
                vty_out(vty, "%2sIP Forward Addresses%4sUDP Port%s",
                        "", "", VTY_NEWLINE);
                vty_out(vty, "%2s-----------------------------%s",
                        "", VTY_NEWLINE);

                for (i = 0; i < row_serv->n_ipv4_ucast_server; i++)
                {
                    /* get the UDP port number. */
                    datum = ovsrec_udp_bcast_forwarder_server_get_udp_dport
                                                (row_serv, OVSDB_TYPE_INTEGER);
                    if ((NULL!=datum) && (datum->n >0))
                    {
                        index = datum->keys[0].integer;
                    }
                    vty_out(vty, "%2s%s%16s%d%s", "",
                                 row_serv->ipv4_ucast_server[i], "",
                                 index, VTY_NEWLINE);
                }
                entry_found = true;
            }
        }
    }

    if (entry_found == false)
    {
        if (ifname)
            vty_out(vty, "No forward address configuration found on "
                    "the interface %s.%s", ifname, VTY_NEWLINE);
        else
            vty_out(vty, "No forward address configuration found.%s",
                    VTY_NEWLINE);
    }

    return CMD_SUCCESS;
}