Index: uspace/srv/net/il/ip/ip.c
===================================================================
--- uspace/srv/net/il/ip/ip.c	(revision fd8e8e1bdc24e6988dc181ca0cab34d17aac6da7)
+++ uspace/srv/net/il/ip/ip.c	(revision b40bfac35889b2187b633463ec6137713aa555e9)
@@ -41,5 +41,4 @@
 #include <async.h>
 #include <errno.h>
-#include <err.h>
 #include <fibril_synch.h>
 #include <stdio.h>
@@ -254,5 +253,5 @@
 int ip_initialize(async_client_conn_t client_connection)
 {
-	ERROR_DECLARE;
+	int rc;
 
 	fibril_rwlock_initialize(&ip_globals.lock);
@@ -265,13 +264,22 @@
 	ip_globals.gateway.gateway.s_addr = 0;
 	ip_globals.gateway.netif = NULL;
-	ERROR_PROPAGATE(ip_netifs_initialize(&ip_globals.netifs));
-	ERROR_PROPAGATE(ip_protos_initialize(&ip_globals.protos));
 	ip_globals.client_connection = client_connection;
-	ERROR_PROPAGATE(modules_initialize(&ip_globals.modules));
-	ERROR_PROPAGATE(add_module(NULL, &ip_globals.modules, ARP_NAME,
-	    ARP_FILENAME, SERVICE_ARP, 0, arp_connect_module));
+	
+	rc = ip_netifs_initialize(&ip_globals.netifs);
+	if (rc != EOK)
+		goto out;
+	rc = ip_protos_initialize(&ip_globals.protos);
+	if (rc != EOK)
+		goto out;
+	rc = modules_initialize(&ip_globals.modules);
+	if (rc != EOK)
+		goto out;
+	rc = add_module(NULL, &ip_globals.modules, ARP_NAME, ARP_FILENAME,
+	    SERVICE_ARP, 0, arp_connect_module);
+
+out:
 	fibril_rwlock_write_unlock(&ip_globals.lock);
 
-	return EOK;
+	return rc;
 }
 
@@ -302,6 +310,4 @@
 static int ip_netif_initialize(ip_netif_ref ip_netif)
 {
-	ERROR_DECLARE;
-
 	measured_string_t names[] = {
 		{
@@ -342,7 +348,8 @@
 	char *data;
 	measured_string_t address;
-	int index;
 	ip_route_ref route;
 	in_addr_t gateway;
+	int index;
+	int rc;
 
 	ip_netif->arp = NULL;
@@ -354,6 +361,9 @@
 
 	// get configuration
-	ERROR_PROPAGATE(net_get_device_conf_req(ip_globals.net_phone,
-	    ip_netif->device_id, &configuration, count, &data));
+	rc = net_get_device_conf_req(ip_globals.net_phone, ip_netif->device_id,
+	    &configuration, count, &data);
+	if (rc != EOK)
+		return rc;
+	
 	if (configuration) {
 		if (configuration[0].value)
@@ -383,10 +393,9 @@
 				return index;
 			}
-			if (ERROR_OCCURRED(inet_pton(AF_INET,
-			    configuration[2].value,
-			    (uint8_t *) &route->address.s_addr)) ||
-			    ERROR_OCCURRED(inet_pton(AF_INET,
-			    configuration[3].value,
-			    (uint8_t *) &route->netmask.s_addr)) ||
+			
+			if ((inet_pton(AF_INET, configuration[2].value,
+			    (uint8_t *) &route->address.s_addr) != EOK) ||
+			    (inet_pton(AF_INET, configuration[3].value,
+			    (uint8_t *) &route->netmask.s_addr) != EOK) ||
 			    (inet_pton(AF_INET, configuration[4].value,
 			    (uint8_t *) &gateway.s_addr) == EINVAL) ||
@@ -434,7 +443,10 @@
 			address.value = (char *) &route->address.s_addr;
 			address.length = CONVERT_SIZE(in_addr_t, char, 1);
-			ERROR_PROPAGATE(arp_device_req(ip_netif->arp->phone,
+			
+			rc = arp_device_req(ip_netif->arp->phone,
 			    ip_netif->device_id, SERVICE_IP, ip_netif->service,
-			    &address));
+			    &address);
+			if (rc != EOK)
+				return rc;
 		} else {
 			ip_netif->arp = 0;
@@ -443,6 +455,9 @@
 
 	// get packet dimensions
-	ERROR_PROPAGATE(nil_packet_size_req(ip_netif->phone,
-	    ip_netif->device_id, &ip_netif->packet_dimension));
+	rc = nil_packet_size_req(ip_netif->phone, ip_netif->device_id,
+	    &ip_netif->packet_dimension);
+	if (rc != EOK)
+		return rc;
+	
 	if (ip_netif->packet_dimension.content < IP_MIN_CONTENT) {
 		printf("Maximum transmission unit %d bytes is too small, at "
@@ -610,6 +625,4 @@
     measured_string_ref destination)
 {
-	ERROR_DECLARE;
-
 	size_t length;
 	ip_header_ref header;
@@ -617,4 +630,5 @@
 	ip_header_ref middle_header;
 	packet_t next;
+	int rc;
 
 	length = packet_get_data_length(packet);
@@ -624,10 +638,12 @@
 	header = (ip_header_ref) packet_get_data(packet);
 	if (destination) {
-		ERROR_PROPAGATE(packet_set_addr(packet, NULL,
-		    (uint8_t *) destination->value,
-		    CONVERT_SIZE(char, uint8_t, destination->length)));
+		rc = packet_set_addr(packet, NULL, (uint8_t *) destination->value,
+		    CONVERT_SIZE(char, uint8_t, destination->length));
 	} else {
-		ERROR_PROPAGATE(packet_set_addr(packet, NULL, NULL, 0));
-	}
+		rc = packet_set_addr(packet, NULL, NULL, 0);
+	}
+	if (rc != EOK)
+		return rc;
+	
 	header->version = IPV4;
 	header->fragment_offset_high = 0;
@@ -669,10 +685,11 @@
 			    IP_HEADER_CHECKSUM(middle_header);
 			if (destination) {
-				if (ERROR_OCCURRED(packet_set_addr(next, NULL,
+				rc = packet_set_addr(next, NULL,
 				    (uint8_t *) destination->value,
 				    CONVERT_SIZE(char, uint8_t,
-				    destination->length)))) {
+				    destination->length));
+				if (rc != EOK) {
 				    	free(last_header);
-					return ERROR_CODE;
+					return rc;
 				}
 			}
@@ -699,11 +716,11 @@
 		    IP_HEADER_CHECKSUM(middle_header);
 		if (destination) {
-			if (ERROR_OCCURRED(packet_set_addr(next, NULL,
+			rc = packet_set_addr(next, NULL,
 			    (uint8_t *) destination->value,
-			    CONVERT_SIZE(char, uint8_t,
-			    destination->length)))) {
+			    CONVERT_SIZE(char, uint8_t, destination->length));
+			if (rc != EOK) {
 				free(last_header);
-				return ERROR_CODE;
-			    }
+				return rc;
+			}
 		}
 		length += packet_get_data_length(next);
@@ -741,8 +758,7 @@
     const struct sockaddr *src, const struct sockaddr *dest, socklen_t addrlen)
 {
-	ERROR_DECLARE;
-
 	void *data;
 	size_t offset;
+	int rc;
 
 	data = packet_suffix(new_packet, length);
@@ -752,5 +768,9 @@
 	memcpy(data, ((void *) header) + IP_TOTAL_LENGTH(header) - length,
 	    length);
-	ERROR_PROPAGATE(packet_trim(packet, 0, length));
+	
+	rc = packet_trim(packet, 0, length);
+	if (rc != EOK)
+		return rc;
+	
 	header->total_length = htons(IP_TOTAL_LENGTH(header) - length);
 	new_header->total_length = htons(IP_HEADER_LENGTH(new_header) + length);
@@ -761,6 +781,9 @@
 	    IP_COMPUTE_FRAGMENT_OFFSET_LOW(offset);
 	new_header->header_checksum = IP_HEADER_CHECKSUM(new_header);
-	ERROR_PROPAGATE(packet_set_addr(new_packet, (const uint8_t *) src,
-	    (const uint8_t *) dest, addrlen));
+	
+	rc = packet_set_addr(new_packet, (const uint8_t *) src,
+	    (const uint8_t *) dest, addrlen);
+	if (rc != EOK)
+		return rc;
 
 	return pq_insert_after(packet, new_packet);
@@ -796,6 +819,4 @@
     socklen_t addr_len)
 {
-	ERROR_DECLARE;
-
 	packet_t new_packet;
 	ip_header_ref header;
@@ -806,4 +827,5 @@
 	socklen_t addrlen;
 	int result;
+	int rc;
 
 	result = packet_get_addr(packet, (uint8_t **) &src, (uint8_t **) &dest);
@@ -839,20 +861,20 @@
 
 	// trim the unused space
-	if (ERROR_OCCURRED(packet_trim(new_packet, 0,
-	    IP_HEADER_LENGTH(header) - IP_HEADER_LENGTH(last_header)))) {
-		return ip_release_and_return(packet, ERROR_CODE);
-	}
+	rc = packet_trim(new_packet, 0,
+	    IP_HEADER_LENGTH(header) - IP_HEADER_LENGTH(last_header));
+	if (rc != EOK)
+		return ip_release_and_return(packet, rc);
 
 	// biggest multiple of 8 lower than content
 	// TODO even fragmentation?
 	length = length & ~0x7;
-	if (ERROR_OCCURRED(ip_fragment_packet_data(packet, new_packet, header,
-	    last_header,
+	
+	rc = ip_fragment_packet_data(packet, new_packet, header, last_header,
 	    ((IP_HEADER_DATA_LENGTH(header) -
 	    ((length - IP_HEADER_LENGTH(header)) & ~0x7)) %
-	    ((length - IP_HEADER_LENGTH(last_header)) & ~0x7)), src, dest,
-	    addrlen))) {
-		return ip_release_and_return(packet, ERROR_CODE);
-	}
+	    ((length - IP_HEADER_LENGTH(last_header)) & ~0x7)),
+	    src, dest, addrlen);
+	if (rc != EOK)
+		return ip_release_and_return(packet, rc);
 
 	// mark the first as fragmented
@@ -872,10 +894,10 @@
 			return ip_release_and_return(packet, ENOMEM);
 
-		if (ERROR_OCCURRED(ip_fragment_packet_data(packet, new_packet,
-		    header, middle_header,
-		    (length - IP_HEADER_LENGTH(middle_header)) & ~0x7, src,
-		    dest, addrlen))) {
-			return ip_release_and_return(packet, ERROR_CODE);
-		}
+		rc = ip_fragment_packet_data(packet, new_packet, header,
+		    middle_header,
+		    (length - IP_HEADER_LENGTH(middle_header)) & ~0x7,
+		    src, dest, addrlen);
+		if (rc != EOK)
+			return ip_release_and_return(packet, rc);
 	}
 
@@ -974,10 +996,9 @@
     in_addr_t *src, in_addr_t dest, services_t error)
 {
-	ERROR_DECLARE;
-
 	measured_string_t destination;
 	measured_string_ref translation;
 	char *data;
 	int phone;
+	int rc;
 
 	// get destination hardware address
@@ -987,10 +1008,10 @@
 		destination.length = CONVERT_SIZE(dest.s_addr, char, 1);
 
-		if (ERROR_OCCURRED(arp_translate_req(netif->arp->phone,
-		    netif->device_id, SERVICE_IP, &destination, &translation,
-		    &data))) {
+		rc = arp_translate_req(netif->arp->phone, netif->device_id,
+		    SERVICE_IP, &destination, &translation, &data);
+		if (rc != EOK) {
 			pq_release_remote(ip_globals.net_phone,
 			    packet_get_id(packet));
-			return ERROR_CODE;
+			return rc;
 		}
 
@@ -1014,5 +1035,6 @@
 	}
 
-	if (ERROR_OCCURRED(ip_prepare_packet(src, dest, packet, translation))) {
+	rc = ip_prepare_packet(src, dest, packet, translation);
+	if (rc != EOK) {
 		pq_release_remote(ip_globals.net_phone, packet_get_id(packet));
 	} else {
@@ -1032,5 +1054,5 @@
 	}
 
-	return ERROR_CODE;
+	return rc;
 }
 
@@ -1158,9 +1180,8 @@
 ip_device_req_local(int il_phone, device_id_t device_id, services_t netif)
 {
-	ERROR_DECLARE;
-
 	ip_netif_ref ip_netif;
 	ip_route_ref route;
 	int index;
+	int rc;
 
 	ip_netif = (ip_netif_ref) malloc(sizeof(ip_netif_t));
@@ -1168,7 +1189,8 @@
 		return ENOMEM;
 
-	if (ERROR_OCCURRED(ip_routes_initialize(&ip_netif->routes))) {
+	rc = ip_routes_initialize(&ip_netif->routes);
+	if (rc != EOK) {
 		free(ip_netif);
-		return ERROR_CODE;
+		return rc;
 	}
 
@@ -1178,9 +1200,11 @@
 
 	fibril_rwlock_write_lock(&ip_globals.netifs_lock);
-	if (ERROR_OCCURRED(ip_netif_initialize(ip_netif))) {
+
+	rc = ip_netif_initialize(ip_netif);
+	if (rc != EOK) {
 		fibril_rwlock_write_unlock(&ip_globals.netifs_lock);
 		ip_routes_destroy(&ip_netif->routes);
 		free(ip_netif);
-		return ERROR_CODE;
+		return rc;
 	}
 	if (ip_netif->arp)
@@ -1226,6 +1250,4 @@
     services_t sender, services_t error)
 {
-	ERROR_DECLARE;
-
 	int addrlen;
 	ip_netif_ref netif;
@@ -1236,4 +1258,5 @@
 	in_addr_t *src;
 	int phone;
+	int rc;
 
 	// addresses in the host byte order
@@ -1323,8 +1346,8 @@
 	}
 
-	ERROR_CODE = ip_send_route(packet, netif, route, src, *dest, error);
+	rc = ip_send_route(packet, netif, route, src, *dest, error);
 	fibril_rwlock_read_unlock(&ip_globals.netifs_lock);
 
-	return ERROR_CODE;
+	return rc;
 }
 
@@ -1431,6 +1454,4 @@
     services_t error)
 {
-	ERROR_DECLARE;
-
 	ip_proto_ref proto;
 	int phone;
@@ -1442,4 +1463,5 @@
 	struct sockaddr_in dest_in;
 	socklen_t addrlen;
+	int rc;
 
 	if ((header->flags & IPFLAG_MORE_FRAGMENTS) ||
@@ -1467,15 +1489,16 @@
 	}
 
-	if (ERROR_OCCURRED(packet_set_addr(packet, (uint8_t *) src,
-	    (uint8_t *) dest, addrlen))) {
-		return ip_release_and_return(packet, ERROR_CODE);
-	}
+	rc = packet_set_addr(packet, (uint8_t *) src, (uint8_t *) dest,
+	    addrlen);
+	if (rc != EOK)
+		return ip_release_and_return(packet, rc);
 
 	// trim padding if present
 	if (!error &&
 	    (IP_TOTAL_LENGTH(header) < packet_get_data_length(packet))) {
-		if (ERROR_OCCURRED(packet_trim(packet, 0,
-		    packet_get_data_length(packet) - IP_TOTAL_LENGTH(header))))
-			return ip_release_and_return(packet, ERROR_CODE);
+		rc = packet_trim(packet, 0,
+		    packet_get_data_length(packet) - IP_TOTAL_LENGTH(header));
+		if (rc != EOK)
+			return ip_release_and_return(packet, rc);
 	}
 
@@ -1498,12 +1521,12 @@
 		received_msg = proto->received_msg;
 		fibril_rwlock_read_unlock(&ip_globals.protos_lock);
-		ERROR_CODE = received_msg(device_id, packet, service, error);
+		rc = received_msg(device_id, packet, service, error);
 	} else {
-		ERROR_CODE = tl_received_msg(proto->phone, device_id, packet,
+		rc = tl_received_msg(proto->phone, device_id, packet,
 		    proto->service, error);
 		fibril_rwlock_read_unlock(&ip_globals.protos_lock);
 	}
 
-	return ERROR_CODE;
+	return rc;
 }
 
@@ -1532,6 +1555,4 @@
 ip_process_packet(device_id_t device_id, packet_t packet)
 {
-	ERROR_DECLARE;
-
 	ip_header_ref header;
 	in_addr_t dest;
@@ -1541,4 +1562,5 @@
 	struct sockaddr_in addr_in;
 	socklen_t addrlen;
+	int rc;
 
 	header = (ip_header_ref) packet_get_data(packet);
@@ -1585,6 +1607,7 @@
 	}
 
-	ERROR_PROPAGATE(packet_set_addr(packet, NULL, (uint8_t *) &addr,
-	    addrlen));
+	rc = packet_set_addr(packet, NULL, (uint8_t *) &addr, addrlen);
+	if (rc != EOK)
+		return rc;
 
 	route = ip_find_route(dest);
@@ -1867,6 +1890,4 @@
     int *answer_count)
 {
-	ERROR_DECLARE;
-	
 	packet_t packet;
 	struct sockaddr *addr;
@@ -1878,4 +1899,5 @@
 	size_t headerlen;
 	device_id_t device_id;
+	int rc;
 	
 	*answer_count = 0;
@@ -1893,6 +1915,8 @@
 	
 	case NET_IL_SEND:
-		ERROR_PROPAGATE(packet_translate_remote(ip_globals.net_phone,
-		    &packet, IPC_GET_PACKET(call)));
+		rc = packet_translate_remote(ip_globals.net_phone, &packet,
+		    IPC_GET_PACKET(call));
+		if (rc != EOK)
+			return rc;
 		return ip_send_msg_local(0, IPC_GET_DEVICE(call), packet, 0,
 		    IPC_GET_ERROR(call));
@@ -1903,11 +1927,15 @@
 	
 	case NET_IL_RECEIVED:
-		ERROR_PROPAGATE(packet_translate_remote(ip_globals.net_phone,
-		    &packet, IPC_GET_PACKET(call)));
+		rc = packet_translate_remote(ip_globals.net_phone, &packet,
+		    IPC_GET_PACKET(call));
+		if (rc != EOK)
+			return rc;
 		return ip_receive_message(IPC_GET_DEVICE(call), packet);
 	
 	case NET_IP_RECEIVED_ERROR:
-		ERROR_PROPAGATE(packet_translate_remote(ip_globals.net_phone,
-		    &packet, IPC_GET_PACKET(call)));
+		rc = packet_translate_remote(ip_globals.net_phone, &packet,
+		    IPC_GET_PACKET(call));
+		if (rc != EOK)
+			return rc;
 		return ip_received_error_msg_local(0, IPC_GET_DEVICE(call),
 		    packet, IPC_GET_TARGET(call), IPC_GET_ERROR(call));
@@ -1923,22 +1951,31 @@
 
 	case NET_IP_GET_ROUTE:
-		ERROR_PROPAGATE(data_receive((void **) &addr, &addrlen));
-		ERROR_PROPAGATE(ip_get_route_req_local(0, IP_GET_PROTOCOL(call),
-		    addr, (socklen_t) addrlen, &device_id, &header,
-		    &headerlen));
+		rc = data_receive((void **) &addr, &addrlen);
+		if (rc != EOK)
+			return rc;
+		
+		rc = ip_get_route_req_local(0, IP_GET_PROTOCOL(call), addr,
+		    (socklen_t) addrlen, &device_id, &header, &headerlen);
+		if (rc != EOK)
+			return rc;
+		
 		IPC_SET_DEVICE(answer, device_id);
 		IP_SET_HEADERLEN(answer, headerlen);
 		
 		*answer_count = 2;
-			
-		if (ERROR_NONE(data_reply(&headerlen, sizeof(headerlen))))
-			ERROR_CODE = data_reply(header, headerlen);
+		
+		rc = data_reply(&headerlen, sizeof(headerlen));
+		if (rc == EOK)
+			rc = data_reply(header, headerlen);
 			
 		free(header);
-		return ERROR_CODE;
+		return rc;
 	
 	case NET_IL_PACKET_SPACE:
-		ERROR_PROPAGATE(ip_packet_size_message(IPC_GET_DEVICE(call),
-		    &addrlen, &prefix, &content, &suffix));
+		rc = ip_packet_size_message(IPC_GET_DEVICE(call), &addrlen,
+		    &prefix, &content, &suffix);
+		if (rc != EOK)
+			return rc;
+		
 		IPC_SET_ADDR(answer, addrlen);
 		IPC_SET_PREFIX(answer, prefix);
@@ -2005,9 +2042,9 @@
 int main(int argc, char *argv[])
 {
-	ERROR_DECLARE;
+	int rc;
 	
 	/* Start the module */
-	ERROR_PROPAGATE(il_module_start_standalone(il_client_connection));
-	return EOK;
+	rc = il_module_start_standalone(il_client_connection);
+	return rc;
 }
 
