{
struct GNUNET_MessageHeader *hdr;
size_t reply_len;
- uint16_t spt;
- uint16_t dpt;
+ uint16_t source_port;
+ uint16_t destination_port;
GNUNET_array_grow (rr->client_wait_list,
rr->client_wait_list_length,
struct sockaddr_in *src = (struct sockaddr_in *) &rr->src_addr;
struct sockaddr_in *dst = (struct sockaddr_in *) &rr->dst_addr;
- spt = dst->sin_port;
- dpt = src->sin_port;
+ source_port = dst->sin_port;
+ destination_port = src->sin_port;
GNUNET_TUN_initialize_ipv4_header (&ip4,
IPPROTO_UDP,
reply_len - off - sizeof (struct GNUNET_TUN_IPv4Header),
struct sockaddr_in6 *src = (struct sockaddr_in6 *) &rr->src_addr;
struct sockaddr_in6 *dst = (struct sockaddr_in6 *) &rr->dst_addr;
- spt = dst->sin6_port;
- dpt = src->sin6_port;
+ source_port = dst->sin6_port;
+ destination_port = src->sin6_port;
GNUNET_TUN_initialize_ipv6_header (&ip6,
IPPROTO_UDP,
reply_len - sizeof (struct GNUNET_TUN_IPv6Header),
{
struct GNUNET_TUN_UdpHeader udp;
- udp.spt = spt;
- udp.dpt = dpt;
+ udp.source_port = source_port;
+ udp.destination_port = destination_port;
udp.len = htons (reply_len - off);
if (AF_INET == rr->src_addr.ss_family)
GNUNET_TUN_calculate_udp4_checksum (&ip4,
dsta4->sin_family = AF_INET;
srca4->sin_addr = ip4->source_address;
dsta4->sin_addr = ip4->destination_address;
- srca4->sin_port = udp->spt;
- dsta4->sin_port = udp->dpt;
+ srca4->sin_port = udp->source_port;
+ dsta4->sin_port = udp->destination_port;
#if HAVE_SOCKADDR_IN_SIN_LEN
srca4->sin_len = sizeof (struct sockaddr_in))
dsta4->sin_len = sizeof (struct sockaddr_in);
dsta6->sin6_family = AF_INET6;
srca6->sin6_addr = ip6->source_address;
dsta6->sin6_addr = ip6->destination_address;
- srca6->sin6_port = udp->spt;
- dsta6->sin6_port = udp->dpt;
+ srca6->sin6_port = udp->source_port;
+ dsta6->sin6_port = udp->destination_port;
#if HAVE_SOCKADDR_IN_SIN_LEN
srca6->sin6_len = sizeof (struct sockaddr_in6);
dsta6->sin6_len = sizeof (struct sockaddr_in6);
*
* @param service_map map of services (TCP or UDP)
* @param desc service descriptor
- * @param dpt destination port
+ * @param destination_port destination port
* @return NULL if we are not aware of such a service
*/
static struct LocalService *
find_service (struct GNUNET_CONTAINER_MultiHashMap *service_map,
const GNUNET_HashCode *desc,
- uint16_t dpt)
+ uint16_t destination_port)
{
char key[sizeof (GNUNET_HashCode) + sizeof (uint16_t)];
- memcpy (&key[0], &dpt, sizeof (uint16_t));
+ memcpy (&key[0], &destination_port, sizeof (uint16_t));
memcpy (&key[sizeof(uint16_t)], desc, sizeof (GNUNET_HashCode));
return GNUNET_CONTAINER_multihashmap_get (service_map,
(GNUNET_HashCode *) key);
*
* @param service_map map of services (TCP or UDP)
* @param name name of the service
- * @param dpt destination port
+ * @param destination_port destination port
* @param service service information record to store (service->name will be set).
*/
static void
store_service (struct GNUNET_CONTAINER_MultiHashMap *service_map,
const char *name,
- uint16_t dpt,
+ uint16_t destination_port,
struct LocalService *service)
{
char key[sizeof (GNUNET_HashCode) + sizeof (uint16_t)];
GNUNET_CRYPTO_hash (name, strlen (name) + 1, &desc);
service->name = GNUNET_strdup (name);
- memcpy (&key[0], &dpt, sizeof (uint16_t));
+ memcpy (&key[0], &destination_port, sizeof (uint16_t));
memcpy (&key[sizeof(uint16_t)], &desc, sizeof (GNUNET_HashCode));
if (GNUNET_OK !=
GNUNET_CONTAINER_multihashmap_put (service_map,
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_("Got duplicate service records for `%s:%u'\n"),
name,
- (unsigned int) dpt);
+ (unsigned int) destination_port);
}
}
const struct GNUNET_TUN_IPv6Header *ipv6;
const struct GNUNET_TUN_UdpHeader *udp;
size_t mlen;
- uint16_t spt;
- uint16_t dpt;
+ uint16_t source_port;
+ uint16_t destination_port;
uint8_t protocol;
{
/* Find out if this is an ICMP packet in response to an existing
TCP/UDP packet and if so, figure out ports / protocol of the
existing session from the IP data in the ICMP payload */
- spt = 0;
- dpt = 0;
+ source_port = 0;
+ destination_port = 0;
protocol = IPPROTO_ICMP;
switch (af)
{
/* could be TCP or UDP, but both have the ports in the right
place, so that doesn't matter here */
udp = (const struct GNUNET_TUN_UdpHeader *) &ipv4[1];
- spt = ntohs (udp->spt);
- dpt = ntohs (udp->dpt);
+ source_port = ntohs (udp->source_port);
+ destination_port = ntohs (udp->destination_port);
/* throw away ICMP payload, won't be useful for the other side anyway */
pktlen = sizeof (struct GNUNET_TUN_IcmpHeader);
break;
/* could be TCP or UDP, but both have the ports in the right
place, so that doesn't matter here */
udp = (const struct GNUNET_TUN_UdpHeader *) &ipv6[1];
- spt = ntohs (udp->spt);
- dpt = ntohs (udp->dpt);
+ source_port = ntohs (udp->source_port);
+ destination_port = ntohs (udp->destination_port);
/* throw away ICMP payload, won't be useful for the other side anyway */
pktlen = sizeof (struct GNUNET_TUN_IcmpHeader);
break;
case IPPROTO_UDP:
state = get_redirect_state (af, IPPROTO_UDP,
source_ip,
- spt,
+ source_port,
destination_ip,
- dpt,
+ destination_port,
NULL);
break;
case IPPROTO_TCP:
state = get_redirect_state (af, IPPROTO_TCP,
source_ip,
- spt,
+ source_port,
destination_ip,
- dpt,
+ destination_port,
NULL);
break;
default:
inet_ntop (af,
source_ip,
sbuf, sizeof (sbuf)),
- (unsigned int) ntohs (udp->spt),
+ (unsigned int) ntohs (udp->source_port),
inet_ntop (af,
destination_ip,
dbuf, sizeof (dbuf)),
- (unsigned int) ntohs (udp->dpt));
+ (unsigned int) ntohs (udp->destination_port));
}
if (pktlen < sizeof (struct GNUNET_TUN_UdpHeader))
{
}
state = get_redirect_state (af, IPPROTO_UDP,
source_ip,
- ntohs (udp->spt),
+ ntohs (udp->source_port),
destination_ip,
- ntohs (udp->dpt),
+ ntohs (udp->destination_port),
NULL);
if (NULL == state)
{
inet_ntop (af,
source_ip,
sbuf, sizeof (sbuf)),
- (unsigned int) ntohs (tcp->spt),
+ (unsigned int) ntohs (tcp->source_port),
inet_ntop (af,
destination_ip,
dbuf, sizeof (dbuf)),
- (unsigned int) ntohs (tcp->dpt));
+ (unsigned int) ntohs (tcp->destination_port));
}
if (pktlen < sizeof (struct GNUNET_TUN_TcpHeader))
{
}
state = get_redirect_state (af, IPPROTO_TCP,
source_ip,
- ntohs (tcp->spt),
+ ntohs (tcp->source_port),
destination_ip,
- ntohs (tcp->dpt),
+ ntohs (tcp->destination_port),
NULL);
if (NULL == state)
{
sender will need to lookup the correct values anyway */
memcpy (buf, tcp, pktlen);
mtcp = (struct GNUNET_TUN_TcpHeader *) buf;
- mtcp->spt = 0;
- mtcp->dpt = 0;
+ mtcp->source_port = 0;
+ mtcp->destination_port = 0;
mtcp->crc = 0;
mlen = sizeof (struct GNUNET_EXIT_TcpDataMessage) + (pktlen - sizeof (struct GNUNET_TUN_TcpHeader));
{
struct GNUNET_TUN_UdpHeader *pkt4_udp = (struct GNUNET_TUN_UdpHeader *) &pkt4[1];
- pkt4_udp->spt = htons (src_address->port);
- pkt4_udp->dpt = htons (dst_address->port);
+ pkt4_udp->source_port = htons (src_address->port);
+ pkt4_udp->destination_port = htons (dst_address->port);
pkt4_udp->len = htons ((uint16_t) payload_length);
GNUNET_TUN_calculate_udp4_checksum (pkt4,
pkt4_udp,
struct GNUNET_TUN_TcpHeader *pkt4_tcp = (struct GNUNET_TUN_TcpHeader *) &pkt4[1];
*pkt4_tcp = *tcp_header;
- pkt4_tcp->spt = htons (src_address->port);
- pkt4_tcp->dpt = htons (dst_address->port);
+ pkt4_tcp->source_port = htons (src_address->port);
+ pkt4_tcp->destination_port = htons (dst_address->port);
GNUNET_TUN_calculate_tcp4_checksum (pkt4,
pkt4_tcp,
payload,
{
struct GNUNET_TUN_UdpHeader *pkt6_udp = (struct GNUNET_TUN_UdpHeader *) &pkt6[1];
- pkt6_udp->spt = htons (src_address->port);
- pkt6_udp->dpt = htons (dst_address->port);
+ pkt6_udp->source_port = htons (src_address->port);
+ pkt6_udp->destination_port = htons (dst_address->port);
pkt6_udp->len = htons ((uint16_t) payload_length);
GNUNET_TUN_calculate_udp6_checksum (pkt6,
pkt6_udp,
/* memcpy first here as some TCP header fields are initialized this way! */
*pkt6_tcp = *tcp_header;
- pkt6_tcp->spt = htons (src_address->port);
- pkt6_tcp->dpt = htons (dst_address->port);
+ pkt6_tcp->source_port = htons (src_address->port);
+ pkt6_tcp->destination_port = htons (dst_address->port);
GNUNET_TUN_calculate_tcp6_checksum (pkt6,
pkt6_tcp,
payload,
"Received data from %s for forwarding to TCP service %s on port %u\n",
GNUNET_i2s (sender),
GNUNET_h2s (&start->service_descriptor),
- (unsigned int) ntohs (start->tcp_header.dpt));
+ (unsigned int) ntohs (start->tcp_header.destination_port));
if (NULL == (state->serv = find_service (tcp_services, &start->service_descriptor,
- ntohs (start->tcp_header.dpt))))
+ ntohs (start->tcp_header.destination_port))))
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("No service found for %s on port %d!\n"),
"TCP",
- ntohs (start->tcp_header.dpt));
+ ntohs (start->tcp_header.destination_port));
GNUNET_STATISTICS_update (stats,
gettext_noop ("# TCP requests dropped (no such service)"),
1, GNUNET_NO);
inet_ntop (af,
&state->ri.remote_address.address,
buf, sizeof (buf)),
- (unsigned int) ntohs (start->tcp_header.dpt));
+ (unsigned int) ntohs (start->tcp_header.destination_port));
}
state->ri.remote_address.proto = IPPROTO_TCP;
- state->ri.remote_address.port = ntohs (start->tcp_header.dpt);
+ state->ri.remote_address.port = ntohs (start->tcp_header.destination_port);
setup_state_record (state);
send_tcp_packet_via_tun (&state->ri.remote_address,
&state->ri.local_address,
sizeof (struct GNUNET_TUN_TcpHeader),
&state->ri.remote_address.address.ipv4,
&state->ri.local_address.address.ipv4);
- udp->spt = htons (state->ri.remote_address.port);
- udp->dpt = htons (state->ri.local_address.port);
+ udp->source_port = htons (state->ri.remote_address.port);
+ udp->destination_port = htons (state->ri.local_address.port);
udp->len = htons (0);
udp->crc = htons (0);
}
sizeof (struct GNUNET_TUN_TcpHeader),
&state->ri.remote_address.address.ipv6,
&state->ri.local_address.address.ipv6);
- udp->spt = htons (state->ri.remote_address.port);
- udp->dpt = htons (state->ri.local_address.port);
+ udp->source_port = htons (state->ri.remote_address.port);
+ udp->destination_port = htons (state->ri.local_address.port);
udp->len = htons (0);
udp->crc = htons (0);
}
*/
struct GNUNET_TUN_IPv4Header
{
- unsigned header_length:4 GNUNET_PACKED;
- unsigned version:4 GNUNET_PACKED;
+ unsigned int header_length:4 GNUNET_PACKED;
+ unsigned int version:4 GNUNET_PACKED;
uint8_t diff_serv;
uint16_t total_length GNUNET_PACKED;
uint16_t identification GNUNET_PACKED;
- unsigned flags:3 GNUNET_PACKED;
- unsigned fragmentation_offset:13 GNUNET_PACKED;
+ unsigned int flags:3 GNUNET_PACKED;
+ unsigned int fragmentation_offset:13 GNUNET_PACKED;
uint8_t ttl;
uint8_t protocol;
uint16_t checksum GNUNET_PACKED;
*/
struct GNUNET_TUN_IPv6Header
{
- unsigned traffic_class_h:4 GNUNET_PACKED;
- unsigned version:4 GNUNET_PACKED;
- unsigned traffic_class_l:4 GNUNET_PACKED;
- unsigned flow_label:20 GNUNET_PACKED;
+ unsigned int traffic_class_h:4 GNUNET_PACKED;
+ unsigned int version:4 GNUNET_PACKED;
+ unsigned int traffic_class_l:4 GNUNET_PACKED;
+ unsigned int flow_label:20 GNUNET_PACKED;
uint16_t payload_length GNUNET_PACKED;
uint8_t next_header;
uint8_t hop_limit;
*/
struct GNUNET_TUN_TcpHeader
{
- unsigned spt:16 GNUNET_PACKED;
- unsigned dpt:16 GNUNET_PACKED;
- unsigned seq:32 GNUNET_PACKED;
- unsigned ack:32 GNUNET_PACKED;
+ uint16_t source_port GNUNET_PACKED;
+ uint16_t destination_port GNUNET_PACKED;
+ uint32_t seq GNUNET_PACKED;
+ uint32_t ack GNUNET_PACKED;
+#if __BYTE_ORDER == __LITTLE_ENDIAN
/**
* Reserved.
*/
- unsigned rsv:4 GNUNET_PACKED;
+ unsigned int reserved : 4 GNUNET_PACKED;
/**
* Number of 32-bit words in TCP header.
*/
- unsigned off:4 GNUNET_PACKED;
- unsigned flg:8 GNUNET_PACKED;
+ unsigned int off : 4 GNUNET_PACKED;
+#elif __BYTE_ORDER == __BIG_ENDIAN
+ /**
+ * Number of 32-bit words in TCP header.
+ */
+ unsigned int off : 4 GNUNET_PACKED;
+ /**
+ * Reserved.
+ */
+ unsigned int reserved : 4 GNUNET_PACKED;
+#endif
+ uint8_t flags;
+
/**
* Window size.
*/
- unsigned wsz:16 GNUNET_PACKED;
- unsigned crc:16 GNUNET_PACKED;
+ uint16_t window_size GNUNET_PACKED;
+
+ uint16_t crc GNUNET_PACKED;
+
/**
* Urgent pointer.
*/
- unsigned urg:16 GNUNET_PACKED;
+ uint16_t urgent_pointer GNUNET_PACKED;
};
*/
struct GNUNET_TUN_UdpHeader
{
- uint16_t spt GNUNET_PACKED;
- uint16_t dpt GNUNET_PACKED;
+ uint16_t source_port GNUNET_PACKED;
+ uint16_t destination_port GNUNET_PACKED;
uint16_t len GNUNET_PACKED;
uint16_t crc GNUNET_PACKED;
};
const struct GNUNET_TUN_UdpHeader *udp;
const struct GNUNET_TUN_TcpHeader *tcp;
const struct GNUNET_TUN_IcmpHeader *icmp;
- uint16_t spt;
- uint16_t dpt;
+ uint16_t source_port;
+ uint16_t destination_port;
switch (protocol)
{
GNUNET_break_op (0);
return;
}
- spt = ntohs (udp->spt);
- dpt = ntohs (udp->dpt);
+ source_port = ntohs (udp->source_port);
+ destination_port = ntohs (udp->destination_port);
get_tunnel_key_from_ips (af,
IPPROTO_UDP,
source_ip,
- spt,
+ source_port,
destination_ip,
- dpt,
+ destination_port,
&key);
}
break;
GNUNET_break_op (0);
return;
}
- spt = ntohs (tcp->spt);
- dpt = ntohs (tcp->dpt);
+ source_port = ntohs (tcp->source_port);
+ destination_port = ntohs (tcp->destination_port);
get_tunnel_key_from_ips (af,
IPPROTO_TCP,
source_ip,
- spt,
+ source_port,
destination_ip,
- dpt,
+ destination_port,
&key);
}
break;
return;
}
icmp = payload;
- spt = 0;
- dpt = 0;
+ source_port = 0;
+ destination_port = 0;
get_tunnel_key_from_ips (af,
IPPROTO_ICMP,
source_ip,
"Routing %s packet from %s:%u -> %s:%u to destination %s:%u\n",
(protocol == IPPROTO_TCP) ? "TCP" : "UDP",
inet_ntop (af, source_ip, sbuf, sizeof (sbuf)),
- spt,
+ source_port,
inet_ntop (af, destination_ip, dbuf, sizeof (dbuf)),
- dpt,
+ destination_port,
inet_ntop (destination->details.exit_destination.af,
&destination->details.exit_destination.ip,
xbuf, sizeof (xbuf)),
- dpt);
+ destination_port);
}
}
else
"Routing %s packet from %s:%u -> %s:%u to service %s at peer %s\n",
(protocol == IPPROTO_TCP) ? "TCP" : "UDP",
inet_ntop (af, source_ip, sbuf, sizeof (sbuf)),
- spt,
+ source_port,
inet_ntop (af, destination_ip, dbuf, sizeof (dbuf)),
- dpt,
+ destination_port,
GNUNET_h2s (&destination->details.service_destination.service_descriptor),
GNUNET_i2s (&destination->details.service_destination.target));
}
ts->source_ip.v6 = * (const struct in6_addr *) source_ip;
ts->destination_ip.v6 = * (const struct in6_addr *) destination_ip;
}
- ts->source_port = spt;
- ts->destination_port = dpt;
+ ts->source_port = source_port;
+ ts->destination_port = destination_port;
ts->heap_node = GNUNET_CONTAINER_heap_insert (tunnel_heap,
ts,
GNUNET_TIME_absolute_get ().abs_value);
usm->header.type = htons (GNUNET_MESSAGE_TYPE_VPN_UDP_TO_SERVICE);
/* if the source port is below 32000, we assume it has a special
meaning; if not, we pick a random port (this is a heuristic) */
- usm->source_port = (ntohs (udp->spt) < 32000) ? udp->spt : 0;
- usm->destination_port = udp->dpt;
+ usm->source_port = (ntohs (udp->source_port) < 32000) ? udp->source_port : 0;
+ usm->destination_port = udp->destination_port;
usm->service_descriptor = destination->details.service_destination.service_descriptor;
memcpy (&usm[1],
&udp[1],
uim->header.size = htons ((uint16_t) mlen);
uim->header.type = htons (GNUNET_MESSAGE_TYPE_VPN_UDP_TO_INTERNET);
uim->af = htonl (destination->details.exit_destination.af);
- uim->source_port = (ntohs (udp->spt) < 32000) ? udp->spt : 0;
- uim->destination_port = udp->dpt;
+ uim->source_port = (ntohs (udp->source_port) < 32000) ? udp->source_port : 0;
+ uim->destination_port = udp->destination_port;
switch (destination->details.exit_destination.af)
{
case AF_INET:
sizeof (struct GNUNET_TUN_TcpHeader),
&ts->source_ip.v4,
&ts->destination_ip.v4);
- udp->spt = htons (ts->source_port);
- udp->dpt = htons (ts->destination_port);
+ udp->source_port = htons (ts->source_port);
+ udp->destination_port = htons (ts->destination_port);
udp->len = htons (0);
udp->crc = htons (0);
}
sizeof (struct GNUNET_TUN_TcpHeader),
&ts->source_ip.v6,
&ts->destination_ip.v6);
- udp->spt = htons (ts->source_port);
- udp->dpt = htons (ts->destination_port);
+ udp->source_port = htons (ts->source_port);
+ udp->destination_port = htons (ts->destination_port);
udp->len = htons (0);
udp->crc = htons (0);
}
&ts->destination_ip.v4,
&ts->source_ip.v4);
if (0 == ntohs (reply->source_port))
- udp->spt = htons (ts->destination_port);
+ udp->source_port = htons (ts->destination_port);
else
- udp->spt = reply->source_port;
+ udp->source_port = reply->source_port;
if (0 == ntohs (reply->destination_port))
- udp->dpt = htons (ts->source_port);
+ udp->destination_port = htons (ts->source_port);
else
- udp->dpt = reply->destination_port;
+ udp->destination_port = reply->destination_port;
udp->len = htons (mlen + sizeof (struct GNUNET_TUN_UdpHeader));
GNUNET_TUN_calculate_udp4_checksum (ipv4,
udp,
&ts->destination_ip.v6,
&ts->source_ip.v6);
if (0 == ntohs (reply->source_port))
- udp->spt = htons (ts->destination_port);
+ udp->source_port = htons (ts->destination_port);
else
- udp->spt = reply->source_port;
+ udp->source_port = reply->source_port;
if (0 == ntohs (reply->destination_port))
- udp->dpt = htons (ts->source_port);
+ udp->destination_port = htons (ts->source_port);
else
- udp->dpt = reply->destination_port;
+ udp->destination_port = reply->destination_port;
udp->len = htons (mlen + sizeof (struct GNUNET_TUN_UdpHeader));
GNUNET_TUN_calculate_udp6_checksum (ipv6,
udp,
&ts->destination_ip.v4,
&ts->source_ip.v4);
*tcp = data->tcp_header;
- tcp->spt = htons (ts->destination_port);
- tcp->dpt = htons (ts->source_port);
+ tcp->source_port = htons (ts->destination_port);
+ tcp->destination_port = htons (ts->source_port);
GNUNET_TUN_calculate_tcp4_checksum (ipv4,
tcp,
&data[1],
&ts->destination_ip.v6,
&ts->source_ip.v6);
*tcp = data->tcp_header;
- tcp->spt = htons (ts->destination_port);
- tcp->dpt = htons (ts->source_port);
+ tcp->source_port = htons (ts->destination_port);
+ tcp->destination_port = htons (ts->source_port);
GNUNET_TUN_calculate_tcp6_checksum (ipv6,
tcp,
&data[1],