示例#1
0
static void
parse_long_opts(int option_index, char *opt_arg)
{
    errno = 0;

    if (!*(long_options[option_index].flag))
        *(long_options[option_index].flag) = 1;

    switch (option_index) {
    case ADD_OPT_INDEX:
        strncpy(if_name, opt_arg, sizeof(if_name));
        if_kindex = if_nametoindex(opt_arg);
        vr_op = SANDESH_OP_ADD;
        break;

    case CREATE_OPT_INDEX:
        strncpy(if_name, opt_arg, sizeof(if_name));
        break;

    case VRF_OPT_INDEX:
        vrf_id = strtoul(opt_arg, NULL, 0);
        if (errno)
            Usage();
        break;

    case MAC_OPT_INDEX:
        mac_opt = ether_aton(opt_arg);
        if (mac_opt)
            memcpy(vr_ifmac, mac_opt, sizeof(vr_ifmac));
        break;

    case DELETE_OPT_INDEX:
        vr_op = SANDESH_OP_DELETE;
        vr_ifindex = strtoul(opt_arg, NULL, 0);
        if (errno)
            Usage();
        break;

    case GET_OPT_INDEX:
        vr_op = SANDESH_OP_GET;
        vr_ifindex = strtoul(opt_arg, NULL, 0);
        if (errno)
            Usage();
        break;

    case POLICY_OPT_INDEX:
        vr_ifflags |= VIF_FLAG_POLICY_ENABLED;
        break;

    case LIST_OPT_INDEX:
        vr_op = SANDESH_OP_DUMP;
        break;

    case TYPE_OPT_INDEX:
        vr_if_type = vr_get_if_type(optarg);
        if (vr_if_type == VIF_TYPE_HOST)
            need_xconnect_if = true;
        break;

    case SET_OPT_INDEX:
        vr_op = SANDESH_OP_ADD;
        vr_ifindex = strtoul(opt_arg, NULL, 0);
        if (errno)
            Usage();
        break;

    case VLAN_OPT_INDEX:
        vr_ifflags |= VIF_FLAG_SERVICE_IF;
        vlan_id = strtoul(opt_arg, NULL, 0);
        if (errno)
            Usage();
        break;

    case XCONNECT_OPT_INDEX:
        if_xconnect_kindex = if_nametoindex(opt_arg);
        if (!if_xconnect_kindex) {
            printf("%s does not seem to be a  valid physical interface name\n",
                    opt_arg);
            Usage();
        }

        break;

    case DHCP_OPT_INDEX:
        vr_ifflags |= VIF_FLAG_DHCP_ENABLED;
        break;

    case VHOST_PHYS_OPT_INDEX:
        vr_ifflags |= VIF_FLAG_VHOST_PHYS;
        break;

    default:
        break;
    }

    return;
}
示例#2
0
static void
parse_long_opts(int option_index, char *opt_arg)
{
    errno = 0;

    if (!*(long_options[option_index].flag))
        *(long_options[option_index].flag) = 1;

    switch (option_index) {
    case ADD_OPT_INDEX:
        strncpy(if_name, opt_arg, sizeof(if_name));
        if_kindex = if_nametoindex(opt_arg);
        vr_op = SANDESH_OP_ADD;
        break;

    case CREATE_OPT_INDEX:
        strncpy(if_name, opt_arg, sizeof(if_name));
        break;

    case VRF_OPT_INDEX:
        vrf_id = strtoul(opt_arg, NULL, 0);
        if (errno)
            Usage();
        break;

    case MAC_OPT_INDEX:
        mac_opt = ether_aton(opt_arg);
        if (mac_opt)
            memcpy(vr_ifmac, mac_opt, sizeof(vr_ifmac));
        break;

    case DELETE_OPT_INDEX:
        vr_op = SANDESH_OP_DELETE;
        vr_ifindex = strtoul(opt_arg, NULL, 0);
        if (errno)
            Usage();
        break;

    case GET_OPT_INDEX:
        vr_op = SANDESH_OP_GET;
        vr_ifindex = strtoul(opt_arg, NULL, 0);
        if (errno)
            Usage();
        break;

    case MODE_OPT_INDEX:
        if (opt_arg[0] == 'x')
            vr_ifflags |= VIF_FLAG_XCONNECT;
        break;

    case POLICY_OPT_INDEX:
        vr_ifflags |= VIF_FLAG_POLICY_ENABLED;
        break;

    case LIST_OPT_INDEX:
        vr_op = SANDESH_OP_DUMP;
        break;

    case TYPE_OPT_INDEX:
        vr_if_type = vr_get_if_type(optarg);
        break;

    case SET_OPT_INDEX:
        vr_op = SANDESH_OP_ADD;
        vr_ifindex = strtoul(opt_arg, NULL, 0);
        if (errno)
            Usage();
        break;

    case VLAN_OPT_INDEX:
        vr_ifflags |= VIF_FLAG_SERVICE_IF;
        vlan_id = strtoul(opt_arg, NULL, 0);
        if (errno)
            Usage();
        break;

    default:
        break;
    }

    return;
}