int if_fsm(struct iface *iface, enum iface_event event) { int old_state; int new_state = 0; int i, ret = 0; old_state = iface->state; for (i = 0; iface_fsm[i].state != -1; i++) if ((iface_fsm[i].state & old_state) && (iface_fsm[i].event == event)) { new_state = iface_fsm[i].new_state; break; } if (iface_fsm[i].state == -1) { /* event outside of the defined fsm, ignore it. */ log_debug("if_fsm: interface %s, " "event %s not expected in state %s", iface->name, if_event_names[event], if_state_name(old_state)); return (0); } switch (iface_fsm[i].action) { case IF_ACT_STRT: ret = if_act_start(iface); break; case IF_ACT_RST: ret = if_act_reset(iface); break; case IF_ACT_NOTHING: /* do nothing */ break; } if (ret) { log_debug("if_fsm: error changing state for interface %s, " "event %s, state %s", iface->name, if_event_names[event], if_state_name(old_state)); return (-1); } if (new_state != 0) iface->state = new_state; log_debug("if_fsm: event %s resulted in action %s and changing " "state for interface %s from %s to %s", if_event_names[event], if_action_names[iface_fsm[i].action], iface->name, if_state_name(old_state), if_state_name(iface->state)); return (ret); }
int show_nbr_msg(struct imsg *imsg) { struct ctl_nbr *nbr; char *state; switch (imsg->hdr.type) { case IMSG_CTL_SHOW_NBR: nbr = imsg->data; if (asprintf(&state, "%s/%s", nbr_state_name(nbr->nbr_state), if_state_name(nbr->iface_state)) == -1) err(1, NULL); printf("%-15s %-3d %-12s %-10s", inet_ntoa(nbr->id), nbr->priority, state, fmt_timeframe_core(nbr->dead_timer)); printf("%-11s %s\n", nbr->name, nbr->uptime == 0 ? "-" : fmt_timeframe_core(nbr->uptime)); free(state); break; case IMSG_CTL_END: printf("\n"); return (1); default: break; } return (0); }
int show_interface_detail_msg(struct imsg *imsg) { struct ctl_iface *iface; switch (imsg->hdr.type) { case IMSG_CTL_SHOW_INTERFACE: iface = imsg->data; printf("\n"); printf("Interface %s, line protocol is %s\n", iface->name, print_link(iface->flags)); printf(" Internet address %s Area %s\n", log_in6addr(&iface->addr), inet_ntoa(iface->area)); printf(" Link type %s, state %s", get_media_descr(get_ifms_type(iface->if_type)), get_linkstate(iface->if_type, iface->linkstate)); if (iface->linkstate != LINK_STATE_DOWN && iface->baudrate > 0) { printf(", "); print_baudrate(iface->baudrate); } printf("\n"); printf(" Router ID %s, network type %s, cost: %d\n", inet_ntoa(iface->rtr_id), if_type_name(iface->type), iface->metric); printf(" Transmit delay is %d sec(s), state %s, priority %d\n", iface->transmit_delay, if_state_name(iface->state), iface->priority); printf(" Designated Router (ID) %s\n", inet_ntoa(iface->dr_id)); printf(" Interface address %s\n", log_in6addr(&iface->dr_addr)); printf(" Backup Designated Router (ID) %s\n", inet_ntoa(iface->bdr_id)); printf(" Interface address %s\n", log_in6addr(&iface->bdr_addr)); printf(" Timer intervals configured, " "hello %d, dead %d, wait %d, retransmit %d\n", iface->hello_interval, iface->dead_interval, iface->dead_interval, iface->rxmt_interval); if (iface->passive) printf(" Passive interface (No Hellos)\n"); else if (iface->hello_timer < 0) printf(" Hello timer not running\n"); else printf(" Hello timer due in %s\n", fmt_timeframe_core(iface->hello_timer)); printf(" Uptime %s\n", fmt_timeframe_core(iface->uptime)); printf(" Neighbor count is %d, adjacent neighbor count is " "%d\n", iface->nbr_cnt, iface->adj_cnt); break; case IMSG_CTL_END: printf("\n"); return (1); default: break; } return (0); }
int show_interface_msg(struct imsg *imsg) { struct ctl_iface *iface; char *netid; switch (imsg->hdr.type) { case IMSG_CTL_SHOW_INTERFACE: iface = imsg->data; if (asprintf(&netid, "%s", log_in6addr(&iface->addr)) == -1) err(1, NULL); printf("%-11s %-29s %-6s %-10s %-10s %s\n", iface->name, netid, if_state_name(iface->state), fmt_timeframe_core(iface->hello_timer), get_linkstate(iface->if_type, iface->linkstate), fmt_timeframe_core(iface->uptime)); free(netid); break; case IMSG_CTL_END: printf("\n"); return (1); default: break; } return (0); }
int show_interface_msg(struct imsg *imsg) { struct ctl_iface *iface; char *timers; switch (imsg->hdr.type) { case IMSG_CTL_SHOW_INTERFACE: iface = imsg->data; if (asprintf(&timers, "%u/%u", iface->hello_interval, iface->hello_holdtime) == -1) err(1, NULL); printf("%-11s %-10s %-10s %-8s %12s %3u\n", iface->name, if_state_name(iface->state), get_linkstate(iface->mediatype, iface->linkstate), iface->uptime == 0 ? "00:00:00" : fmt_timeframe_core(iface->uptime), timers, iface->adj_cnt); free(timers); break; case IMSG_CTL_END: printf("\n"); return (1); default: break; } return (0); }
int show_interface_msg(struct imsg *imsg) { struct ctl_iface *iface; char *netid; switch (imsg->hdr.type) { case IMSG_CTL_SHOW_INTERFACE: iface = imsg->data; if (asprintf(&netid, "%s/%d", inet_ntoa(iface->addr), mask2prefixlen(iface->mask.s_addr)) == -1) err(1, NULL); printf("%-11s %-18s %-6s %-10s %-10s %s %3d %3d\n", iface->name, netid, if_state_name(iface->state), iface->hello_timer.tv_sec < 0 ? "-" : fmt_timeframe_core(iface->hello_timer.tv_sec), get_linkstate(iface->mediatype, iface->linkstate), fmt_timeframe_core(iface->uptime), iface->nbr_cnt, iface->adj_cnt); free(netid); break; case IMSG_CTL_END: printf("\n"); return (1); default: break; } return (0); }
int show_interface_detail_msg(struct imsg *imsg) { struct ctl_iface *iface; switch (imsg->hdr.type) { case IMSG_CTL_SHOW_INTERFACE: iface = imsg->data; printf("\n"); printf("Interface %s, line protocol is %s\n", iface->name, print_link(iface->flags)); printf(" Internet address %s/%d, ", inet_ntoa(iface->addr), mask2prefixlen(iface->mask.s_addr)); printf("Area %s\n", inet_ntoa(iface->area)); printf(" Linkstate %s\n", get_linkstate(iface->mediatype, iface->linkstate)); printf(" Router ID %s, network type %s, cost: %d\n", inet_ntoa(iface->rtr_id), if_type_name(iface->type), iface->metric); printf(" Transmit delay is %d sec(s), state %s, priority %d\n", iface->transmit_delay, if_state_name(iface->state), iface->priority); printf(" Designated Router (ID) %s, ", inet_ntoa(iface->dr_id)); printf("interface address %s\n", inet_ntoa(iface->dr_addr)); printf(" Backup Designated Router (ID) %s, ", inet_ntoa(iface->bdr_id)); printf("interface address %s\n", inet_ntoa(iface->bdr_addr)); if (iface->dead_interval == FAST_RTR_DEAD_TIME) { printf(" Timer intervals configured, " "hello %d msec, dead %d, wait %d, retransmit %d\n", iface->fast_hello_interval, iface->dead_interval, iface->dead_interval, iface->rxmt_interval); } else { printf(" Timer intervals configured, " "hello %d, dead %d, wait %d, retransmit %d\n", iface->hello_interval, iface->dead_interval, iface->dead_interval, iface->rxmt_interval); } if (iface->passive) printf(" Passive interface (No Hellos)\n"); else if (iface->hello_timer.tv_sec < 0) printf(" Hello timer not running\n"); else printf(" Hello timer due in %s+%ldmsec\n", fmt_timeframe_core(iface->hello_timer.tv_sec), iface->hello_timer.tv_usec / 1000); printf(" Uptime %s\n", fmt_timeframe_core(iface->uptime)); printf(" Neighbor count is %d, adjacent neighbor count is " "%d\n", iface->nbr_cnt, iface->adj_cnt); if (iface->auth_type > 0) { switch (iface->auth_type) { case AUTH_SIMPLE: printf(" Simple password authentication " "enabled\n"); break; case AUTH_CRYPT: printf(" Message digest authentication " "enabled\n"); printf(" Primary key id is %d\n", iface->auth_keyid); break; default: break; } } break; case IMSG_CTL_END: printf("\n"); return (1); default: break; } return (0); }