Exemplo n.º 1
0
/*ARGSUSED*/
static void
dlpi_notify(dlpi_handle_t dlpi, dlpi_notifyinfo_t *info, void *arg)
{
	struct portdata *port = arg;
	int rc;

	switch (info->dni_note) {
	case DL_NOTE_SPEED:
		/* libdlpi gives us Kbps, and we want Mbps */
		if (port->speed == info->dni_speed / 1000)
			break;
		port->speed = info->dni_speed / 1000;
		if ((rc = STP_IN_changed_port_speed(port->port_index,
		    port->speed)) != 0)
			syslog(LOG_ERR, "STP can't change port speed on %s: %s",
			    port->name, STP_IN_get_error_explanation(rc));
		break;

	case DL_NOTE_PHYS_ADDR:
		if (memcmp(info->dni_physaddr, port->mac_addr, ETHERADDRL) != 0)
			rstp_change_mac(port, info->dni_physaddr);
		break;

	case DL_NOTE_LINK_DOWN:
		if (!port->phys_status)
			break;
		port->phys_status = B_FALSE;
		if (!port->admin_status || protect != DLADM_BRIDGE_PROT_STP ||
		    port->sdu_failed)
			break;
		if ((rc = STP_IN_enable_port(port->port_index, False)) != 0)
			syslog(LOG_ERR, "STP can't disable port %s: %s",
			    port->name, STP_IN_get_error_explanation(rc));
		break;

	case DL_NOTE_LINK_UP:
		if (port->phys_status)
			break;
		port->phys_status = B_TRUE;
		if (!port->admin_status || protect != DLADM_BRIDGE_PROT_STP ||
		    port->sdu_failed) {
			port->bpdu_protect = B_FALSE;
			break;
		}
		/*
		 * If we're not running STP, and the link state has just come
		 * up, then clear out any protection shutdown state, and allow
		 * us to forward again.
		 */
		if (port->admin_non_stp && port->bpdu_protect) {
			port->bpdu_protect = B_FALSE;
			enable_forwarding(port);
		}
		if ((rc = STP_IN_enable_port(port->port_index, True)) != 0)
			syslog(LOG_ERR, "STP can't enable port %s: %s",
			    port->name, STP_IN_get_error_explanation(rc));
		break;
	}
}
Exemplo n.º 2
0
int bridge_start(void)
{
	BITMAP_T ports;
	UID_MSG_T msg;
	UID_STP_CFG_T uid_cfg;
	register int iii;

	//rl_callback_handler_install(get_prompt(), rl_read_cli);

	if (0 != UiD_SocketInit(&uid_socket, UID_REPL_PATH,
				UID_BIND_AS_CLIENT)) {
		printf("FATAL: can't init the connection\n");
		exit(-3);
	}

	/* send HANDSHAKE */
	msg.header.sender_pid = my_pid;
	msg.header.cmd_type = UID_CNTRL;
	msg.body.cntrl.cmd = UID_BRIDGE_HANDSHAKE;
	msg.body.cntrl.param1 = NUMBER_OF_PORTS;
	iii = UiD_SocketSendto(&uid_socket, &msg, sizeof(UID_MSG_T));
	if (iii < 0) {
		printf("can't send HANDSHAKE: %s\n", strerror(errno));
		printf("May be 'mngr' is not alive ? :(\n");
		return (-4);
	}

	stp_cli_init();

	STP_IN_init(NUMBER_OF_PORTS);
	BitmapClear(&enabled_ports);
	BitmapClear(&ports);
	for (iii = 1; iii <= NUMBER_OF_PORTS; iii++) {
		BitmapSetBit(&ports, iii - 1);
	}

	uid_cfg.field_mask = BR_CFG_STATE;
	uid_cfg.stp_enabled = STP_ENABLED;
	snprintf(uid_cfg.vlan_name, NAME_LEN - 1, "B%ld", (long)my_pid);
	iii = STP_IN_stpm_set_cfg(0, &ports, &uid_cfg);
	if (STP_OK != iii) {
		printf("FATAL: can't enable:%s\n",
		       STP_IN_get_error_explanation (iii));
		return (-1);
	}
	return 0;
}
Exemplo n.º 3
0
void bridge_shutdown(void)
{
	UID_MSG_T msg;
	int rc;

	/* send SHUTDOWN */
	msg.header.sender_pid = my_pid;
	msg.header.cmd_type = UID_CNTRL;
	msg.body.cntrl.cmd = UID_BRIDGE_SHUTDOWN;
	UiD_SocketSendto(&uid_socket, &msg, sizeof(UID_MSG_T));
	UiD_SocketClose(&uid_socket);

	rc = STP_IN_stpm_delete(0);
	if (STP_OK != rc) {
		printf("FATAL: can't delete:%s\n",
		       STP_IN_get_error_explanation (rc));
		exit(1);
	}
}