Index: uspace/srv/net/inetsrv/pdu.c
===================================================================
--- uspace/srv/net/inetsrv/pdu.c	(revision b7fd2a02e4161f4edd38548e7f8456b8021549be)
+++ uspace/srv/net/inetsrv/pdu.c	(revision a35b458e9db1ca95e679799dc7c1b12c83359ca3)
@@ -107,33 +107,33 @@
 	/* Upper bound for fragment offset field */
 	size_t fragoff_limit = 1 << (FF_FRAGOFF_h - FF_FRAGOFF_l + 1);
-	
+
 	/* Verify that total size of datagram is within reasonable bounds */
 	if (packet->size > FRAG_OFFS_UNIT * fragoff_limit)
 		return ELIMIT;
-	
+
 	size_t hdr_size = sizeof(ip_header_t);
 	if (hdr_size >= mtu)
 		return EINVAL;
-	
+
 	assert(hdr_size % 4 == 0);
 	assert(offs % FRAG_OFFS_UNIT == 0);
 	assert(offs / FRAG_OFFS_UNIT < fragoff_limit);
-	
+
 	/* Value for the fragment offset field */
 	uint16_t foff = offs / FRAG_OFFS_UNIT;
-	
+
 	/* Amount of space in the PDU available for payload */
 	size_t spc_avail = mtu - hdr_size;
 	spc_avail -= (spc_avail % FRAG_OFFS_UNIT);
-	
+
 	/* Amount of data (payload) to transfer */
 	size_t xfer_size = min(packet->size - offs, spc_avail);
-	
+
 	/* Total PDU size */
 	size_t size = hdr_size + xfer_size;
-	
+
 	/* Offset of remaining payload */
 	size_t rem_offs = offs + xfer_size;
-	
+
 	/* Flags */
 	uint16_t flags_foff =
@@ -141,12 +141,12 @@
 	    (rem_offs < packet->size ? BIT_V(uint16_t, FF_FLAG_MF) : 0) +
 	    (foff << FF_FRAGOFF_l);
-	
+
 	void *data = calloc(size, 1);
 	if (data == NULL)
 		return ENOMEM;
-	
+
 	/* Encode header fields */
 	ip_header_t *hdr = (ip_header_t *) data;
-	
+
 	hdr->ver_ihl =
 	    (4 << VI_VERSION_l) | (hdr_size / sizeof(uint32_t));
@@ -160,17 +160,17 @@
 	hdr->src_addr = host2uint32_t_be(src);
 	hdr->dest_addr = host2uint32_t_be(dest);
-	
+
 	/* Compute checksum */
 	uint16_t chksum = inet_checksum_calc(INET_CHECKSUM_INIT,
 	    (void *) hdr, hdr_size);
 	hdr->chksum = host2uint16_t_be(chksum);
-	
+
 	/* Copy payload */
 	memcpy((uint8_t *) data + hdr_size, packet->data + offs, xfer_size);
-	
+
 	*rdata = data;
 	*rsize = size;
 	*roffs = rem_offs;
-	
+
 	return EOK;
 }
@@ -200,12 +200,12 @@
 	if (mtu < 1280)
 		return ELIMIT;
-	
+
 	/* Upper bound for fragment offset field */
 	size_t fragoff_limit = 1 << (OF_FRAGOFF_h - OF_FRAGOFF_l);
-	
+
 	/* Verify that total size of datagram is within reasonable bounds */
 	if (offs + packet->size > FRAG_OFFS_UNIT * fragoff_limit)
 		return ELIMIT;
-	
+
 	/* Determine whether we need the Fragment extension header */
 	bool fragment;
@@ -214,5 +214,5 @@
 	else
 		fragment = true;
-	
+
 	size_t hdr_size;
 	if (fragment)
@@ -220,59 +220,59 @@
 	else
 		hdr_size = sizeof(ip6_header_t);
-	
+
 	if (hdr_size >= mtu)
 		return EINVAL;
-	
+
 	static_assert(sizeof(ip6_header_t) % 8 == 0);
 	assert(hdr_size % 8 == 0);
 	assert(offs % FRAG_OFFS_UNIT == 0);
 	assert(offs / FRAG_OFFS_UNIT < fragoff_limit);
-	
+
 	/* Value for the fragment offset field */
 	uint16_t foff = offs / FRAG_OFFS_UNIT;
-	
+
 	/* Amount of space in the PDU available for payload */
 	size_t spc_avail = mtu - hdr_size;
 	spc_avail -= (spc_avail % FRAG_OFFS_UNIT);
-	
+
 	/* Amount of data (payload) to transfer */
 	size_t xfer_size = min(packet->size - offs, spc_avail);
-	
+
 	/* Total PDU size */
 	size_t size = hdr_size + xfer_size;
-	
+
 	/* Offset of remaining payload */
 	size_t rem_offs = offs + xfer_size;
-	
+
 	/* Flags */
 	uint16_t offsmf =
 	    (rem_offs < packet->size ? BIT_V(uint16_t, OF_FLAG_M) : 0) +
 	    (foff << OF_FRAGOFF_l);
-	
+
 	void *data = calloc(size, 1);
 	if (data == NULL)
 		return ENOMEM;
-	
+
 	/* Encode header fields */
 	ip6_header_t *hdr6 = (ip6_header_t *) data;
-	
+
 	hdr6->ver_tc = (6 << (VI_VERSION_l));
 	memset(hdr6->tc_fl, 0, 3);
 	hdr6->hop_limit = packet->ttl;
-	
+
 	host2addr128_t_be(src, hdr6->src_addr);
 	host2addr128_t_be(dest, hdr6->dest_addr);
-	
+
 	/* Optionally encode Fragment extension header fields */
 	if (fragment) {
 		assert(offsmf != 0);
-		
+
 		hdr6->payload_len = host2uint16_t_be(packet->size +
 		    sizeof(ip6_header_fragment_t));
 		hdr6->next = IP6_NEXT_FRAGMENT;
-		
+
 		ip6_header_fragment_t *hdr6f = (ip6_header_fragment_t *)
 		    (hdr6 + 1);
-		
+
 		hdr6f->next = packet->proto;
 		hdr6f->reserved = 0;
@@ -281,16 +281,16 @@
 	} else {
 		assert(offsmf == 0);
-		
+
 		hdr6->payload_len = host2uint16_t_be(packet->size);
 		hdr6->next = packet->proto;
 	}
-	
+
 	/* Copy payload */
 	memcpy((uint8_t *) data + hdr_size, packet->data + offs, xfer_size);
-	
+
 	*rdata = data;
 	*rsize = size;
 	*roffs = rem_offs;
-	
+
 	return EOK;
 }
@@ -312,12 +312,12 @@
 {
 	log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_pdu_decode()");
-	
+
 	if (size < sizeof(ip_header_t)) {
 		log_msg(LOG_DEFAULT, LVL_DEBUG, "PDU too short (%zu)", size);
 		return EINVAL;
 	}
-	
+
 	ip_header_t *hdr = (ip_header_t *) data;
-	
+
 	uint8_t version = BIT_RANGE_EXTRACT(uint8_t, VI_VERSION_h,
 	    VI_VERSION_l, hdr->ver_ihl);
@@ -326,5 +326,5 @@
 		return EINVAL;
 	}
-	
+
 	size_t tot_len = uint16_t_be2host(hdr->tot_len);
 	if (tot_len < sizeof(ip_header_t)) {
@@ -332,5 +332,5 @@
 		return EINVAL;
 	}
-	
+
 	if (tot_len > size) {
 		log_msg(LOG_DEFAULT, LVL_DEBUG, "Total Length = %zu > PDU size = %zu",
@@ -338,5 +338,5 @@
 		return EINVAL;
 	}
-	
+
 	uint16_t ident = uint16_t_be2host(hdr->id);
 	uint16_t flags_foff = uint16_t_be2host(hdr->flags_foff);
@@ -344,5 +344,5 @@
 	    flags_foff);
 	/* XXX Checksum */
-	
+
 	inet_addr_set(uint32_t_be2host(hdr->src_addr), &packet->src);
 	inet_addr_set(uint32_t_be2host(hdr->dest_addr), &packet->dest);
@@ -351,13 +351,13 @@
 	packet->ttl = hdr->ttl;
 	packet->ident = ident;
-	
+
 	packet->df = (flags_foff & BIT_V(uint16_t, FF_FLAG_DF)) != 0;
 	packet->mf = (flags_foff & BIT_V(uint16_t, FF_FLAG_MF)) != 0;
 	packet->offs = foff * FRAG_OFFS_UNIT;
-	
+
 	/* XXX IP options */
 	size_t data_offs = sizeof(uint32_t) *
 	    BIT_RANGE_EXTRACT(uint8_t, VI_IHL_h, VI_IHL_l, hdr->ver_ihl);
-	
+
 	packet->size = tot_len - data_offs;
 	packet->data = calloc(packet->size, 1);
@@ -366,8 +366,8 @@
 		return ENOMEM;
 	}
-	
+
 	memcpy(packet->data, (uint8_t *) data + data_offs, packet->size);
 	packet->link_id = link_id;
-	
+
 	return EOK;
 }
@@ -389,12 +389,12 @@
 {
 	log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_pdu_decode6()");
-	
+
 	if (size < sizeof(ip6_header_t)) {
 		log_msg(LOG_DEFAULT, LVL_DEBUG, "PDU too short (%zu)", size);
 		return EINVAL;
 	}
-	
+
 	ip6_header_t *hdr6 = (ip6_header_t *) data;
-	
+
 	uint8_t version = BIT_RANGE_EXTRACT(uint8_t, VI_VERSION_h,
 	    VI_VERSION_l, hdr6->ver_tc);
@@ -403,5 +403,5 @@
 		return EINVAL;
 	}
-	
+
 	size_t payload_len = uint16_t_be2host(hdr6->payload_len);
 	if (payload_len + sizeof(ip6_header_t) > size) {
@@ -410,5 +410,5 @@
 		return EINVAL;
 	}
-	
+
 	uint32_t ident;
 	uint16_t offsmf;
@@ -416,10 +416,10 @@
 	uint16_t next;
 	size_t data_offs = sizeof(ip6_header_t);
-	
+
 	/* Fragment extension header */
 	if (hdr6->next == IP6_NEXT_FRAGMENT) {
 		ip6_header_fragment_t *hdr6f = (ip6_header_fragment_t *)
 		    (hdr6 + 1);
-		
+
 		ident = uint32_t_be2host(hdr6f->id);
 		offsmf = uint16_t_be2host(hdr6f->offsmf);
@@ -435,23 +435,23 @@
 		next = hdr6->next;
 	}
-	
+
 	addr128_t src;
 	addr128_t dest;
-	
+
 	addr128_t_be2host(hdr6->src_addr, src);
 	inet_addr_set6(src, &packet->src);
-	
+
 	addr128_t_be2host(hdr6->dest_addr, dest);
 	inet_addr_set6(dest, &packet->dest);
-	
+
 	packet->tos = 0;
 	packet->proto = next;
 	packet->ttl = hdr6->hop_limit;
 	packet->ident = ident;
-	
+
 	packet->df = 1;
 	packet->mf = (offsmf & BIT_V(uint16_t, OF_FLAG_M)) != 0;
 	packet->offs = foff * FRAG_OFFS_UNIT;
-	
+
 	packet->size = payload_len;
 	packet->data = calloc(packet->size, 1);
@@ -460,5 +460,5 @@
 		return ENOMEM;
 	}
-	
+
 	memcpy(packet->data, (uint8_t *) data + data_offs, packet->size);
 	packet->link_id = link_id;
@@ -480,17 +480,17 @@
 	dgram->tos = 0;
 	dgram->size = sizeof(icmpv6_message_t) + sizeof(ndp_message_t);
-	
+
 	dgram->data = calloc(1, dgram->size);
 	if (dgram->data == NULL)
 		return ENOMEM;
-	
+
 	icmpv6_message_t *icmpv6 = (icmpv6_message_t *) dgram->data;
-	
+
 	icmpv6->type = ndp->opcode;
 	icmpv6->code = 0;
 	memset(icmpv6->un.ndp.reserved, 0, 3);
-	
+
 	ndp_message_t *message = (ndp_message_t *) (icmpv6 + 1);
-	
+
 	if (ndp->opcode == ICMPV6_NEIGHBOUR_SOLICITATION) {
 		host2addr128_t_be(ndp->solicited_ip, message->target_address);
@@ -502,10 +502,10 @@
 		icmpv6->un.ndp.flags = NDP_FLAG_OVERRIDE | NDP_FLAG_SOLICITED;
 	}
-	
+
 	message->length = 1;
 	addr48(ndp->sender_hw_addr, message->mac);
-	
+
 	icmpv6_phdr_t phdr;
-	
+
 	host2addr128_t_be(ndp->sender_proto_addr, phdr.src_addr);
 	host2addr128_t_be(ndp->target_proto_addr, phdr.dest_addr);
@@ -513,14 +513,14 @@
 	memset(phdr.zeroes, 0, 3);
 	phdr.next = IP_PROTO_ICMPV6;
-	
+
 	uint16_t cs_phdr =
 	    inet_checksum_calc(INET_CHECKSUM_INIT, &phdr,
 	    sizeof(icmpv6_phdr_t));
-	
+
 	uint16_t cs_all = inet_checksum_calc(cs_phdr, dgram->data,
 	    dgram->size);
-	
+
 	icmpv6->checksum = host2uint16_t_be(cs_all);
-	
+
 	return EOK;
 }
@@ -541,17 +541,17 @@
 	if (src_ver != ip_v6)
 		return EINVAL;
-	
+
 	if (dgram->size < sizeof(icmpv6_message_t) + sizeof(ndp_message_t))
 		return EINVAL;
-	
+
 	icmpv6_message_t *icmpv6 = (icmpv6_message_t *) dgram->data;
-	
+
 	ndp->opcode = icmpv6->type;
-	
+
 	ndp_message_t *message = (ndp_message_t *) (icmpv6 + 1);
-	
+
 	addr128_t_be2host(message->target_address, ndp->target_proto_addr);
 	addr48(message->mac, ndp->sender_hw_addr);
-	
+
 	return EOK;
 }
