import struct


def upstream_forward(sock, data):
	"""
	Forward a DNS request to a upstream server using TLS.

	Params:
		sock - socket object connected to upstream server
		data - wireformat DNS request packet to forward

	Returns:
		A wireformat DNS response packet

	Notes:
		Using DNS over TLS format as described here:
		https://tools.ietf.org/html/rfc7858
	"""

	sock.send(struct.pack('!H', len(data)) + data)
	return sock.recv(4096)[2:]