示例#1
0
static void
dump_prev_cb(void)
{
    if (!cb_cursor.idx) {
	fprintf(stderr, "no more CBs\n");
	return;
    }

    dump_cb(cb_cursor.idx-1);
}
示例#2
0
static void
dump_all_cbs(void)
{
    int i;

    if (get_fe_hdr()) {
	fprintf(stderr, "error getting callback_state_entry_header\n");
	return;
    }

    for (i = 0; i < fe_cursor.hdr.nCBs; i++) {
	dump_cb(i);
    }
}
示例#3
0
static void
dump_last_cb(void)
{
    if (get_fe_hdr()) {
	fprintf(stderr, "error getting callback_state_entry_header\n");
	return;
    }

    if (!fe_cursor.hdr.nCBs) {
	fprintf(stderr, "no CBs present\n");
	return;
    }

    dump_cb(fe_cursor.hdr.nCBs-1);
}
示例#4
0
static void
dump_next_cb(void)
{
    if (get_fe_hdr()) {
	fprintf(stderr, "error getting callback_state_entry_header\n");
	return;
    }

    if ((cb_cursor.idx + 1) >= fe_cursor.hdr.nCBs) {
	fprintf(stderr, "no more CBs\n");
	return;
    }

    dump_cb(cb_cursor.idx+1);
}
示例#5
0
static void
prompt(void)
{
    char input[256];
    char prev_input[256];
    char * tok = NULL;
    afs_uint32 x, y, z;
    enum {
	PR_GLOBAL_MODE,
	PR_H_MODE,
	PR_FE_MODE,
	PR_CB_MODE
    } mode = PR_GLOBAL_MODE, next_mode;

    next_mode = mode;
    input[0] = prev_input[0] = '\0';

    while (1) {
	if (!tok) {
	    switch(mode) {
	    case PR_GLOBAL_MODE:
		printf(PROGNAME "> ");
		break;
	    case PR_H_MODE:
		printf(PROGNAME ": h(%d)> ", he_cursor.idx);
		break;
	    case PR_FE_MODE:
		printf(PROGNAME ": fe(%d)> ", fe_cursor.idx);
		break;
	    case PR_CB_MODE:
		printf(PROGNAME ": fe(%d):cb(%d)> ", fe_cursor.idx, cb_cursor.idx);
		break;
	    default:
		fprintf(stderr, "prompt state broken; aborting\n");
		return;
	    }
	    fgets(input, 256, stdin);

	    if (!strcmp(input, "")) {
		/* repeat last command */
		if (!strcmp(prev_input, "")) {
		    continue;
		}
		strlcpy(input, prev_input, sizeof(input));
	    } else {
		/* save command for repetition */
		strlcpy(prev_input, input, sizeof(prev_input));
	    }

	    tok = strtok(input, " \t\n");
	}
	while (tok && !strcmp(tok, ";")) {
	    tok = strtok(NULL, "; \t\n");
	}

	if (!tok) {
	    continue;
	}

	if (!strcasecmp(tok, "exit")) {
	    return;
	} else if (!strcasecmp(tok, "quit")) {
	    switch(mode) {
	    case PR_CB_MODE:
		next_mode = PR_FE_MODE;
		break;
	    case PR_FE_MODE:
	    case PR_H_MODE:
		next_mode = PR_GLOBAL_MODE;
		break;
	    default:
		return;
	    }
	} else if (!strcasecmp(tok, "h")) {
	    tok = strtok(NULL, " \t");
	    mode = PR_H_MODE;
	    if (!tok) {
		next_mode = mode;
	    }
	    continue;
	} else if (!strcasecmp(tok, "fe")) {
	    tok = strtok(NULL, " \t");
	    mode = PR_FE_MODE;
	    if (!tok) {
		next_mode = mode;
	    }
	    continue;
	} else if (!strcasecmp(tok, "fs")) {
	    tok = strtok(NULL, " \t");
	    mode = PR_GLOBAL_MODE;
	    if (!tok) {
		next_mode = mode;
	    }
	    continue;
	} else if (!strcasecmp(tok, "cb")) {
	    tok = strtok(NULL, " \t");
	    mode = PR_CB_MODE;
	    if (!tok) {
		next_mode = mode;
	    }
	    continue;
	} else if (!strcasecmp(tok, "help")) {
	    switch(mode) {
	    case PR_H_MODE:
		print_h_help();
		break;
	    case PR_FE_MODE:
		print_fe_help();
		break;
	    case PR_CB_MODE:
		print_cb_help();
		break;
	    default:
		print_global_help();
	    }
	    print_help();
	} else if (!strcasecmp(tok, "hexdump")) {
	    tok = strtok(NULL, " \t");
	    if (!tok) {
		hexdump_map(0, map_len);
		continue;
	    }
	    if (sscanf(tok, "%u", &x) != 1) {
		fprintf(stderr, "hexdump parse error 1\n");
		tok = NULL;
		continue;
	    }
	    tok = strtok(NULL, " \t");
	    if (!tok) {
		hexdump_map(x, map_len - x);
		continue;
	    }
	    if (sscanf(tok, "%u", &y) != 1) {
		fprintf(stderr, "hexdump parse error 2\n");
		continue;
	    }
	    hexdump_map(x,y);
	} else if (!strcasecmp(tok, "hdr")) {
	    switch(mode) {
	    case PR_H_MODE:
		dump_h_hdr();
		break;
	    case PR_FE_MODE:
		dump_cb_hdr();
		break;
	    case PR_CB_MODE:
		dump_this_fe();
		break;
	    default:
		dump_hdr();
	    }
	} else if (!strcasecmp(tok, "this")) {
	    switch(mode) {
	    case PR_H_MODE:
		dump_this_he();
		break;
	    case PR_FE_MODE:
		dump_this_fe();
		break;
	    case PR_CB_MODE:
		dump_this_cb();
		break;
	    default:
		fprintf(stderr, "command not valid for this mode\n");
	    }
	} else if (!strcasecmp(tok, "next")) {
	    switch(mode) {
	    case PR_H_MODE:
		dump_next_he();
		break;
	    case PR_FE_MODE:
		dump_next_fe();
		break;
	    case PR_CB_MODE:
		dump_next_cb();
		break;
	    default:
		fprintf(stderr, "command not valid for this mode\n");
	    }
	} else if (!strcasecmp(tok, "prev")) {
	    switch(mode) {
	    case PR_H_MODE:
		dump_prev_he();
		break;
	    case PR_FE_MODE:
		dump_prev_fe();
		break;
	    case PR_CB_MODE:
		dump_prev_cb();
		break;
	    default:
		fprintf(stderr, "command not valid for this mode\n");
	    }
	} else if (!strcasecmp(tok, "first")) {
	    switch(mode) {
	    case PR_H_MODE:
		dump_first_he();
		break;
	    case PR_FE_MODE:
		dump_first_fe();
		break;
	    case PR_CB_MODE:
		dump_first_cb();
		break;
	    default:
		fprintf(stderr, "command not valid for this mode\n");
	    }
	} else if (!strcasecmp(tok, "last")) {
	    switch(mode) {
	    case PR_H_MODE:
		dump_last_he();
		break;
	    case PR_FE_MODE:
		dump_last_fe();
		break;
	    case PR_CB_MODE:
		dump_last_cb();
		break;
	    default:
		fprintf(stderr, "command not valid for this mode\n");
	    }
	} else if (!strcasecmp(tok, "dump")) {
	    switch(mode) {
	    case PR_H_MODE:
		dump_all_hes();
		break;
	    case PR_FE_MODE:
		dump_all_fes();
		break;
	    case PR_CB_MODE:
		dump_all_cbs();
		break;
	    default:
		fprintf(stderr, "command not valid for this mode\n");
	    }
	} else if (!strcasecmp(tok, "find")) {
	    tok = strtok(NULL, " \t");
	    if (!tok || strcasecmp(tok, "by")) {
		tok = NULL;
		fprintf(stderr, "find syntax error 1 (%s)\n",
			(tok) ? tok : "nil");
		continue;
	    }
	    tok = strtok(NULL, " \t");
	    if (!tok) {
		fprintf(stderr, "find syntax error 2\n");
		continue;
	    }
	    switch(mode) {
	    case PR_H_MODE:
		fprintf(stderr, "not implemented yet\n");
		break;
	    case PR_FE_MODE:
		if (!strcasecmp(tok, "index")) {
		    tok = strtok(NULL, " \t");
		    if (!tok || sscanf(tok, "%u", &x) != 1) {
			tok = NULL;
			fprintf(stderr, "find syntax error 3\n");
			continue;
		    }
		    if (find_fe_by_index(x)) {
			fprintf(stderr, "find returned no results\n");
		    }
		} else if (!strcasecmp(tok, "fid")) {
		    tok = strtok(NULL, "(), \t");
		    if (!tok || sscanf(tok, "%u", &x) != 1) {
			tok = NULL;
			fprintf(stderr, "find syntax error 4\n");
			continue;
		    }
		    tok = strtok(NULL, "(), \t");
		    if (!tok || sscanf(tok, "%u", &y) != 1) {
			tok = NULL;
			fprintf(stderr, "find syntax error 5\n");
			continue;
		    }
		    tok = strtok(NULL, "(), \t");
		    if (!tok || sscanf(tok, "%u", &z) != 1) {
			tok = NULL;
			fprintf(stderr, "find syntax error 6\n");
			continue;
		    }
		    if (find_fe_by_fid(x,y,z)) {
			fprintf(stderr, "find returned no results\n");
		    }
		} else {
		    fprintf(stderr, "unsupported filter type\n");
		}
		break;
	    case PR_CB_MODE:
		if (!strcasecmp(tok, "index")) {
		    tok = strtok(NULL, " \t");
		    if (!tok || sscanf(tok, "%u", &x) != 1) {
			tok = NULL;
			fprintf(stderr, "find syntax error 3\n");
			continue;
		    }
		    if (find_cb_by_index(x)) {
			fprintf(stderr, "find returned no results\n");
		    }
		} else {
		    fprintf(stderr, "unsupported filter type\n");
		}
		break;
	    default:
		fprintf(stderr, "find not supported for this menu\n");
	    }
	} else if (!strcspn(tok, "0123456789")) {
	    if (sscanf(tok, "%u", &x) == 1) {
		switch(mode) {
		case PR_H_MODE:
		    dump_he(x);
		    break;
		case PR_FE_MODE:
		    dump_fe(x);
		    break;
		case PR_CB_MODE:
		    dump_cb(x);
		    break;
		default:
		    fprintf(stderr, "command not available from this menu\n");
		}
	    } else {
		fprintf(stderr, "input parse error ('%s')\n", tok);
	    }
	} else if (mode == PR_FE_MODE) {
	    if (!strcmp(tok, "timeout")) {
		dump_cb_timeout();
	    } else if (!strcmp(tok, "hash")) {
		dump_cb_fehash();
	    }
	} else {
	    fprintf(stderr, "unknown command\n");
	}
	tok = strtok(NULL, " \t");
	mode = next_mode;
    }
}
示例#6
0
static void
dump_this_cb(void)
{
    dump_cb(cb_cursor.idx);
}
示例#7
0
/**
 *  This function dumps sub-module's internal attributes
 *
 * @param[in] dump_cb - callback for dumping, if NULL, log will be used
 *
 * @return 0 when successful, otherwise ERROR
 */
int
mlag_l3_interface_peer_print(void (*dump_cb)(const char *, ...))
{
    int i, cnt, total_cnt, tmp;

    if (dump_cb == NULL) {
       	MLAG_LOG(MLAG_LOG_NOTICE, "L3 interface local peer dump:\n");
    	MLAG_LOG(MLAG_LOG_NOTICE, "is_initialized=%d, is_started=%d, "
    	        "is_peer_start=%d, is_master_sync_done=%d\n",
    			 is_inited, is_started, is_peer_start, is_master_sync_done);
    }
    else {
    	dump_cb("L3 interface local peer dump:\n");
    	dump_cb("is_initialized=%d, is_started=%d, is_peer_start=%d, "
    	        "is_master_sync_done=%d\n",
   			    is_inited, is_started, is_peer_start, is_master_sync_done);
    }

    if (dump_cb == NULL) {
        MLAG_LOG(MLAG_LOG_NOTICE, "ipl_ifindex=%lu, ipl_vlan_id=%d\n",
                 ipl_ifindex, ipl_vlan_id);
    }
    else {
        dump_cb("ipl_ifindex=%lu, ipl_vlan_id=%d\n",
                ipl_ifindex, ipl_vlan_id);
    }

    if (!is_inited) {
        goto bail;
    }

    /* Print IPL vlan list */
    if (dump_cb == NULL) {
        MLAG_LOG(MLAG_LOG_NOTICE, "ipl vlan list:\n");
    }
    else {
        dump_cb("ipl vlan list:\n");
    }

    for (i = 1, total_cnt = 0; i < VLAN_N_VID; i++) {
        if (ipl_vlan_list[i]) {
        	total_cnt++;
        }
    }
    for (i = 1, cnt = 0, tmp = 0; i < VLAN_N_VID; i++) {
        if (ipl_vlan_list[i]) {
        	if ((++cnt > 100) &&
                (cnt < (total_cnt-100))) {
        		continue;
        	}
       		tmp++;
       		if (dump_cb == NULL) {
       			MLAG_LOG(MLAG_LOG_NOTICE, "%d  ", i);
       		}
       		else {
       			dump_cb("%d  ", i);
       		}
        	if (tmp >= 10) {
        		if (dump_cb == NULL) {
        			MLAG_LOG(MLAG_LOG_NOTICE, "\n");
        		}
        		else {
        			dump_cb("\n");
        		}
        		tmp = 0;
        	}
        }
    }
    if (dump_cb == NULL) {
    	MLAG_LOG(MLAG_LOG_NOTICE, "\ntotal vlans in ipl_vlan_list: %d\n", total_cnt);
    	MLAG_LOG(MLAG_LOG_NOTICE, "\n");
    }
    else {
    	dump_cb("\ntotal vlans in ipl_vlan_list: %d\n", total_cnt);
    	dump_cb("\n");
    }

bail:
    return 0;
}