Example #1
0
	void SimpleDashelConnection::connectionClosed(Dashel::Stream *stream, bool abnormal)
	{
		// if the stream being closed is the current one (not old), clear breakpoints and reset current
		if (stream == this->stream)
		{
			clearBreakpoints();
			this->stream = nullptr;
		}
		if (abnormal)
		{
			SEND_NOTIFICATION(LOG_WARNING, "client disconnected abnormally", stream->getTargetName());
		}
		else
		{
			SEND_NOTIFICATION(LOG_INFO, "client disconnected properly", stream->getTargetName());
		}
	}
Example #2
0
	//! Disconnect old streams
	void SimpleDashelConnection::closeOldStreams()
	{
		for (size_t i = 0; i < toDisconnect.size(); ++i)
		{
			SEND_NOTIFICATION(LOG_WARNING, "old client disconnected", toDisconnect[i]->getTargetName());
			closeStream(toDisconnect[i]);
		}
		toDisconnect.clear();
	}
Example #3
0
	SimpleDashelConnection::SimpleDashelConnection(unsigned port)
	{
		try
		{
			listenStream = Dashel::Hub::connect(FormatableString("tcpin:port=%0").arg(port));
		}
		catch (const Dashel::DashelException& e)
		{
			SEND_NOTIFICATION(FATAL_ERROR, "cannot create listening port", std::to_string(port), e.what());
			abort();
		}
	}
Example #4
0
/* process an input packet, possibly generating a reply.
 *
 * If all goes well, this routine eventually calls a state-specific
 * transition function.
 */
void process_packet(struct msg_digest **mdp)
{
	struct msg_digest *md = *mdp;
	struct state *st = NULL;
	int vmaj, vmin;
	enum state_kind from_state = STATE_UNDEFINED;   /* state we started in */

#define SEND_NOTIFICATION(t) { \
		if (st) \
			send_notification_from_state(st, from_state, t); \
		else \
			send_notification_from_md(md, t); }

	if (!in_struct(&md->hdr, &isakmp_hdr_desc, &md->packet_pbs,
		       &md->message_pbs)) {
		/*
		 * The packet was very badly mangled. We can't be sure of any
		 * content - not even to look for major version number!
		 * So we'll just silently drop it
		 */
		libreswan_log("Received packet with mangled IKE header - dropped");
		SEND_NOTIFICATION(PAYLOAD_MALFORMED);
		return;
	}

	if (md->packet_pbs.roof < md->message_pbs.roof) {
		/* I don't think this can happen if in_struct() did not fail */
		libreswan_log(
			"received packet size (%u) is smaller than from "
			"size specified in ISAKMP HDR (%u) - packet dropped",
			(unsigned) pbs_room(&md->packet_pbs),
			md->hdr.isa_length);
		/* abort processing corrupt packet */
		return;
	} else if (md->packet_pbs.roof > md->message_pbs.roof) {
		/*
		 * Some (old?) versions of the Cisco VPN client send an additional
		 * 16 bytes of zero bytes - Complain but accept it
		 */
		DBG(DBG_CONTROL, {
			DBG_log(
			"size (%u) in received packet is larger than the size "
			"specified in ISAKMP HDR (%u) - ignoring extraneous bytes",
			(unsigned) pbs_room(&md->packet_pbs),
			md->hdr.isa_length);
			DBG_dump("extraneous bytes:", md->message_pbs.roof,
				md->packet_pbs.roof - md->message_pbs.roof);
		});
Example #5
0
	void SimpleDashelConnection::connectionCreated(Dashel::Stream *stream)
	{
		const std::string& targetName(stream->getTargetName());
		if (targetName.substr(0, targetName.find_first_of(':')) == "tcp")
		{
			// schedule current stream for disconnection
			if (this->stream)
			{
				toDisconnect.push_back(this->stream);
				clearBreakpoints();
			}

			// set new stream as current stream
			this->stream = stream;
			SEND_NOTIFICATION(LOG_INFO, "new client connected", stream->getTargetName());
		}
	}
Example #6
0
	void SimpleDashelConnection::incomingData(Dashel::Stream *stream)
	{
		// if we receive data from an old connection, disregard as we'll close the old stream soon
		if (stream != this->stream)
		{
			// read one byte to avoid deadlock
			char c;
			stream->read(&c, 1);
			return;
		}

		try
		{
			// receive data
			uint16_t temp;
			uint16_t len;

			stream->read(&temp, 2);
			len = bswap16(temp);
			stream->read(&temp, 2);
			lastMessageSource = bswap16(temp);
			lastMessageData.resize(len+2);
			stream->read(&lastMessageData[0], lastMessageData.size());

			// execute event on all VM that are linked to this connection
			for (auto vmStateToEnvironmentKV: vmStateToEnvironment)
			{
				if (vmStateToEnvironmentKV.second.second == this)
				{
					AsebaProcessIncomingEvents(vmStateToEnvironmentKV.first);
					AsebaVMRun(vmStateToEnvironmentKV.first, 1000);
				}
			}
		}
		catch (Dashel::DashelException e)
		{
			SEND_NOTIFICATION(LOG_ERROR, "cannot read from socket", stream->getTargetName(), e.what());
		}
	}
Example #7
0
	void SimpleDashelConnection::sendBuffer(uint16_t nodeId, const uint8_t* data, uint16_t length)
	{
		if (stream)
		{
			try
			{
				uint16_t temp;

				// this may happen if target has disconnected
				temp = bswap16(length - 2);
				stream->write(&temp, 2);
				temp = bswap16(nodeId);
				stream->write(&temp, 2);
				stream->write(data, length);
				stream->flush();
			}
			catch (Dashel::DashelException e)
			{
				SEND_NOTIFICATION(LOG_ERROR, "cannot read from socket", stream->getTargetName(), e.what());
			}
		}
	}