diff --git a/repos/os/include/net/arp.h b/repos/os/include/net/arp.h
index a48a3bee9e..c7c0248478 100644
--- a/repos/os/include/net/arp.h
+++ b/repos/os/include/net/arp.h
@@ -195,31 +195,31 @@ class Net::Arp_packet
/**
* \return operation code (Arp_packet::Opcode).
*/
- Genode::uint16_t opcode() { return host_to_big_endian(_opcode); }
+ Genode::uint16_t opcode() const { return host_to_big_endian(_opcode); }
/**
* \return source MAC address.
*/
- Mac_address src_mac() {
- return Mac_address(&_src_mac_addr); }
+ Mac_address src_mac() const {
+ return Mac_address((void *)&_src_mac_addr); }
/**
* \return source IP address.
*/
- Ipv4_address src_ip() {
- return Ipv4_address(&_src_ip_addr); }
+ Ipv4_address src_ip() const {
+ return Ipv4_address((void *)&_src_ip_addr); }
/**
* \return destination MAC address.
*/
- Mac_address dst_mac() {
- return Mac_address(&_dst_mac_addr); }
+ Mac_address dst_mac() const {
+ return Mac_address((void *)&_dst_mac_addr); }
/**
* \return destination IP address.
*/
- Ipv4_address dst_ip() {
- return Ipv4_address(&_dst_ip_addr); }
+ Ipv4_address dst_ip() const {
+ return Ipv4_address((void *)&_dst_ip_addr); }
/******************************
@@ -297,7 +297,7 @@ class Net::Arp_packet
* \return true when ARP packet really targets ethernet
* address resolution with respect to IPv4 addresses.
*/
- bool ethernet_ipv4() {
+ bool ethernet_ipv4() const {
return ( host_to_big_endian(_hw_addr_type) == ETHERNET
&& host_to_big_endian(_prot_addr_type) == Ethernet_frame::IPV4
&& _hw_addr_sz == Ethernet_frame::ADDR_LEN
@@ -314,6 +314,13 @@ class Net::Arp_packet
*/
void * operator new(__SIZE_TYPE__ size, void* addr) { return addr; }
+
+ /*********
+ ** Log **
+ *********/
+
+ void print(Genode::Output &output) const;
+
} __attribute__((packed));
#endif /* _NET__ARP_H_ */
diff --git a/repos/os/include/net/dhcp.h b/repos/os/include/net/dhcp.h
index 2cfc90ae72..f6b207b7c0 100644
--- a/repos/os/include/net/dhcp.h
+++ b/repos/os/include/net/dhcp.h
@@ -185,12 +185,12 @@ class Net::Dhcp_packet
** DHCP field read-accessors **
*******************************/
- Genode::uint8_t op() { return _op; }
- Genode::uint8_t htype() { return _htype; }
- Genode::uint8_t hlen() { return _hlen; }
- Genode::uint8_t hops() { return _hops; }
- Genode::uint32_t xid() { return host_to_big_endian(_xid); }
- Genode::uint16_t secs() { return host_to_big_endian(_secs); }
+ Genode::uint8_t op() const { return _op; }
+ Genode::uint8_t htype() const { return _htype; }
+ Genode::uint8_t hlen() const { return _hlen; }
+ Genode::uint8_t hops() const { return _hops; }
+ Genode::uint32_t xid() const { return host_to_big_endian(_xid); }
+ Genode::uint16_t secs() const { return host_to_big_endian(_secs); }
bool broadcast() { return _flags & BROADCAST; }
@@ -198,13 +198,13 @@ class Net::Dhcp_packet
return Ipv4_address(&_ciaddr); }
Ipv4_address yiaddr() {
return Ipv4_address(&_yiaddr); }
- Ipv4_address siaddr() {
- return Ipv4_address(&_siaddr); }
+ Ipv4_address siaddr() const {
+ return Ipv4_address((void *)&_siaddr); }
Ipv4_address giaddr() {
return Ipv4_address(&_giaddr); }
- Mac_address client_mac() {
- return Mac_address(&_chaddr); }
+ Mac_address client_mac() const {
+ return Mac_address((void *)&_chaddr); }
const char* server_name() { return (const char*) &_sname; }
const char* file() { return (const char*) &_file; }
@@ -255,7 +255,7 @@ class Net::Dhcp_packet
** Convenience methods **
*************************/
- static bool is_dhcp(Udp_packet *udp)
+ static bool is_dhcp(Udp_packet const *udp)
{
return ((udp->src_port() == Dhcp_packet::BOOTPC ||
udp->src_port() == Dhcp_packet::BOOTPS) &&
@@ -273,6 +273,13 @@ class Net::Dhcp_packet
*/
void * operator new(__SIZE_TYPE__ size, void* addr) { return addr; }
+
+ /*********
+ ** log **
+ *********/
+
+ void print(Genode::Output &output) const;
+
} __attribute__((packed));
#endif /* _DHCP_H_ */
diff --git a/repos/os/include/net/dump.h b/repos/os/include/net/dump.h
deleted file mode 100644
index e44aaf10de..0000000000
--- a/repos/os/include/net/dump.h
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * \brief Dump header info of network packets
- * \author Martin Stein
- * \date 2016-08-15
- */
-
-/*
- * Copyright (C) 2016 Genode Labs GmbH
- *
- * This file is part of the Genode OS framework, which is distributed
- * under the terms of the GNU General Public License version 2.
- */
-
-#ifndef _NET__DUMP_H_
-#define _NET__DUMP_H_
-
-/* Genode includes */
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-namespace Net
-{
- void dump_tcp(void * const base, Genode::size_t const size)
- {
- Tcp_packet * tcp = new (base) Tcp_packet(size);
- Genode::printf(
- "\033[32mTCP\033[0m %u > %u flags '",
- tcp->src_port(),
- tcp->dst_port());
-
- if (tcp->fin()) { Genode::printf("f"); }
- if (tcp->syn()) { Genode::printf("s"); }
- if (tcp->rst()) { Genode::printf("r"); }
- if (tcp->psh()) { Genode::printf("p"); }
- if (tcp->ack()) { Genode::printf("a"); }
- if (tcp->urg()) { Genode::printf("u"); }
- Genode::printf("' ");
- }
-
- void dump_dhcp(void * const base, Genode::size_t const size)
- {
- Dhcp_packet * dhcp = new (base) Dhcp_packet(size);
- Genode::printf(
- "\033[32mDHCP\033[0m %x:%x:%x:%x:%x:%x > %u.%u.%u.%u cmd %u ",
- dhcp->client_mac().addr[0],
- dhcp->client_mac().addr[1],
- dhcp->client_mac().addr[2],
- dhcp->client_mac().addr[3],
- dhcp->client_mac().addr[4],
- dhcp->client_mac().addr[5],
- dhcp->siaddr().addr[0],
- dhcp->siaddr().addr[1],
- dhcp->siaddr().addr[2],
- dhcp->siaddr().addr[3],
- dhcp->op());
- }
-
- void dump_udp(void * const base, Genode::size_t const size)
- {
- Udp_packet * udp = new (base) Udp_packet(size);
- Genode::printf(
- "\033[32mUDP\033[0m %u > %u ",
- udp->src_port(),
- udp->dst_port());
-
- Genode::size_t data_size = size - sizeof(Udp_packet);
- void * data = udp->data();
- if (Dhcp_packet::is_dhcp(udp)) { dump_dhcp(data, data_size); }
- }
-
- void dump_ipv4(void * const base, Genode::size_t const size)
- {
- Ipv4_packet * ipv4 = new (base) Ipv4_packet(size);
- Genode::printf(
- "\033[32mIPV4\033[0m %u.%u.%u.%u > %u.%u.%u.%u ",
- ipv4->src().addr[0],
- ipv4->src().addr[1],
- ipv4->src().addr[2],
- ipv4->src().addr[3],
- ipv4->dst().addr[0],
- ipv4->dst().addr[1],
- ipv4->dst().addr[2],
- ipv4->dst().addr[3]);
-
- void * data = ipv4->data();
- Genode::size_t data_size = size - sizeof(Ipv4_packet);
- switch (ipv4->protocol()) {
- case Tcp_packet::IP_ID: dump_tcp(data, data_size); break;
- case Udp_packet::IP_ID: dump_udp(data, data_size); break;
- default: ; }
- }
-
- void dump_arp(void * const base, Genode::size_t const size)
- {
- Arp_packet * arp = new (base) Arp_packet(size);
- if (!arp->ethernet_ipv4()) { return; }
- Genode::printf(
- "\033[32mARP\033[0m %x:%x:%x:%x:%x:%x %u.%u.%u.%u "
- "> %x:%x:%x:%x:%x:%x %u.%u.%u.%u cmd %u ",
- arp->src_mac().addr[0],
- arp->src_mac().addr[1],
- arp->src_mac().addr[2],
- arp->src_mac().addr[3],
- arp->src_mac().addr[4],
- arp->src_mac().addr[5],
- arp->src_ip().addr[0],
- arp->src_ip().addr[1],
- arp->src_ip().addr[2],
- arp->src_ip().addr[3],
- arp->dst_mac().addr[0],
- arp->dst_mac().addr[1],
- arp->dst_mac().addr[2],
- arp->dst_mac().addr[3],
- arp->dst_mac().addr[4],
- arp->dst_mac().addr[5],
- arp->dst_ip().addr[0],
- arp->dst_ip().addr[1],
- arp->dst_ip().addr[2],
- arp->dst_ip().addr[3],
- arp->opcode());
- }
-
- void dump_eth(void * const base, Genode::size_t const size)
- {
- Ethernet_frame * eth = new (base) Ethernet_frame(size);
- Genode::printf(
- "\033[32mETH\033[0m %x:%x:%x:%x:%x:%x > %x:%x:%x:%x:%x:%x ",
- eth->src().addr[0],
- eth->src().addr[1],
- eth->src().addr[2],
- eth->src().addr[3],
- eth->src().addr[4],
- eth->src().addr[5],
- eth->dst().addr[0],
- eth->dst().addr[1],
- eth->dst().addr[2],
- eth->dst().addr[3],
- eth->dst().addr[4],
- eth->dst().addr[5]);
-
- void * data = eth->data();
- Genode::size_t data_size = size - sizeof(Ethernet_frame);
- switch (eth->type()) {
- case Ethernet_frame::ARP: dump_arp(data, data_size); break;
- case Ethernet_frame::IPV4: dump_ipv4(data, data_size); break;
- default: ; }
- }
-}
-
-#endif /* _NET__DUMP_H_ */
diff --git a/repos/os/include/net/ethernet.h b/repos/os/include/net/ethernet.h
index bf0c06d173..f3afe686f7 100644
--- a/repos/os/include/net/ethernet.h
+++ b/repos/os/include/net/ethernet.h
@@ -128,17 +128,17 @@ class Net::Ethernet_frame
/**
* \return destination MAC address of frame.
*/
- Mac_address dst() { return Mac_address(&_dst_mac); }
+ Mac_address dst() const { return Mac_address((void *)&_dst_mac); }
/**
* \return source MAC address of frame.
*/
- Mac_address src() { return Mac_address(&_src_mac); }
+ Mac_address src() const { return Mac_address((void *)&_src_mac); }
/**
* \return EtherType - type of encapsulated protocol.
*/
- Genode::uint16_t type() { return host_to_big_endian(_type); }
+ Genode::uint16_t type() const { return host_to_big_endian(_type); }
/**
* \return payload data.
@@ -182,6 +182,13 @@ class Net::Ethernet_frame
*/
void * operator new(__SIZE_TYPE__ size, void* addr) { return addr; }
+
+ /*********
+ ** log **
+ *********/
+
+ void print(Genode::Output &output) const;
+
} __attribute__((packed));
diff --git a/repos/os/include/net/ipv4.h b/repos/os/include/net/ipv4.h
index 0515f69fad..3e71265905 100644
--- a/repos/os/include/net/ipv4.h
+++ b/repos/os/include/net/ipv4.h
@@ -172,12 +172,12 @@ class Net::Ipv4_packet
Genode::size_t fragment_offset() { return _fragment_offset; }
Genode::uint8_t time_to_live() { return _time_to_live; }
- Genode::uint8_t protocol() { return _protocol; }
+ Genode::uint8_t protocol() const { return _protocol; }
Genode::uint16_t checksum() { return host_to_big_endian(_header_checksum); }
- Ipv4_address dst() { return Ipv4_address(&_dst_addr); }
- Ipv4_address src() { return Ipv4_address(&_src_addr); }
+ Ipv4_address dst() const { return Ipv4_address((void *)&_dst_addr); }
+ Ipv4_address src() const { return Ipv4_address((void *)&_src_addr); }
template T const * header() const { return (T const *)(this); }
template T * data() { return (T *)(_data); }
@@ -207,6 +207,13 @@ class Net::Ipv4_packet
*/
void * operator new(__SIZE_TYPE__ size, void* addr) { return addr; }
+
+ /*********
+ ** log **
+ *********/
+
+ void print(Genode::Output &output) const;
+
} __attribute__((packed));
diff --git a/repos/os/include/net/tcp.h b/repos/os/include/net/tcp.h
index 4e639a25e4..b4589b4dbd 100644
--- a/repos/os/include/net/tcp.h
+++ b/repos/os/include/net/tcp.h
@@ -78,9 +78,9 @@ class Net::Tcp_packet
void src_port(Genode::uint16_t p) { _src_port = host_to_big_endian(p); }
void dst_port(Genode::uint16_t p) { _dst_port = host_to_big_endian(p); }
- uint16_t src_port() { return host_to_big_endian(_src_port); }
- uint16_t dst_port() { return host_to_big_endian(_dst_port); }
- uint16_t flags() { return host_to_big_endian(_flags); }
+ uint16_t src_port() const { return host_to_big_endian(_src_port); }
+ uint16_t dst_port() const { return host_to_big_endian(_dst_port); }
+ uint16_t flags() const { return host_to_big_endian(_flags); }
Tcp_packet(size_t size) {
if (size < sizeof(Tcp_packet)) { throw No_tcp_packet(); } }
@@ -136,6 +136,13 @@ class Net::Tcp_packet
*/
void * operator new(__SIZE_TYPE__ size, void * addr) { return addr; }
+
+ /*********
+ ** log **
+ *********/
+
+ void print(Genode::Output &output) const;
+
} __attribute__((packed));
#endif /* _TCP_H_ */
diff --git a/repos/os/include/net/udp.h b/repos/os/include/net/udp.h
index 57d10c934a..a568b8a932 100644
--- a/repos/os/include/net/udp.h
+++ b/repos/os/include/net/udp.h
@@ -75,10 +75,10 @@ class Net::Udp_packet
** UDP field read-accessors **
******************************/
- Genode::uint16_t src_port() { return host_to_big_endian(_src_port); }
- Genode::uint16_t dst_port() { return host_to_big_endian(_dst_port); }
- Genode::uint16_t length() { return host_to_big_endian(_length); }
- Genode::uint16_t checksum() { return host_to_big_endian(_checksum); }
+ Genode::uint16_t src_port() const { return host_to_big_endian(_src_port); }
+ Genode::uint16_t dst_port() const { return host_to_big_endian(_dst_port); }
+ Genode::uint16_t length() const { return host_to_big_endian(_length); }
+ Genode::uint16_t checksum() const { return host_to_big_endian(_checksum); }
void src_port(Genode::uint16_t p) { _src_port = host_to_big_endian(p); }
void dst_port(Genode::uint16_t p) { _dst_port = host_to_big_endian(p); }
@@ -155,6 +155,14 @@ class Net::Udp_packet
/* one's complement of sum */
_checksum = host_to_big_endian((Genode::uint16_t) ~sum);
}
+
+
+ /*********
+ ** log **
+ *********/
+
+ void print(Genode::Output &output) const;
+
} __attribute__((packed));
#endif /* _UDP_H_ */
diff --git a/repos/os/lib/mk/net.mk b/repos/os/lib/mk/net.mk
index 75b74246b9..9f603d004b 100644
--- a/repos/os/lib/mk/net.mk
+++ b/repos/os/lib/mk/net.mk
@@ -1,3 +1,3 @@
-SRC_CC = ethernet.cc ipv4.cc mac_address.cc
+SRC_CC = ethernet.cc ipv4.cc dhcp.cc arp.cc udp.cc tcp.cc mac_address.cc
vpath %.cc $(REP_DIR)/src/lib/net
diff --git a/repos/os/src/lib/net/arp.cc b/repos/os/src/lib/net/arp.cc
new file mode 100644
index 0000000000..5bb111eaa7
--- /dev/null
+++ b/repos/os/src/lib/net/arp.cc
@@ -0,0 +1,27 @@
+/*
+ * \brief Address resolution protocol
+ * \author Stefan Kalkowski
+ * \date 2010-08-24
+ *
+ * ARP is used to determine a network host's link layer or
+ * hardware address when only its Network Layer address is known.
+ */
+
+/*
+ * Copyright (C) 2010-2013 Genode Labs GmbH
+ *
+ * This file is part of the Genode OS framework, which is distributed
+ * under the terms of the GNU General Public License version 2.
+ */
+
+/* Genode includes */
+#include
+#include
+
+
+void Net::Arp_packet::print(Genode::Output &output) const
+{
+ if (!ethernet_ipv4()) { return; }
+ Genode::print(output, "\033[32mARP\033[0m ", src_mac(), " ", src_ip(),
+ " > ", dst_mac(), " ", dst_ip(), " cmd ", opcode());
+}
diff --git a/repos/os/src/lib/net/dhcp.cc b/repos/os/src/lib/net/dhcp.cc
new file mode 100644
index 0000000000..64eba64cd8
--- /dev/null
+++ b/repos/os/src/lib/net/dhcp.cc
@@ -0,0 +1,23 @@
+/*
+ * \brief DHCP related definitions
+ * \author Stefan Kalkowski
+ * \date 2010-08-19
+ */
+
+/*
+ * Copyright (C) 2010-2013 Genode Labs GmbH
+ *
+ * This file is part of the Genode OS framework, which is distributed
+ * under the terms of the GNU General Public License version 2.
+ */
+
+/* Genode */
+#include
+#include
+
+
+void Net::Dhcp_packet::print(Genode::Output &output) const
+{
+ Genode::print(output, "\033[32mDHCP\033[0m ", client_mac(),
+ " > ", siaddr(), " cmd ", op());
+}
diff --git a/repos/os/src/lib/net/ethernet.cc b/repos/os/src/lib/net/ethernet.cc
index bb009a7698..75cbbb9fa0 100644
--- a/repos/os/src/lib/net/ethernet.cc
+++ b/repos/os/src/lib/net/ethernet.cc
@@ -11,6 +11,26 @@
* under the terms of the GNU General Public License version 2.
*/
+/* Genode includes */
#include
+#include
+#include
+#include
const Net::Mac_address Net::Ethernet_frame::BROADCAST(0xFF);
+
+
+void Net::Ethernet_frame::print(Genode::Output &output) const
+{
+ Genode::print(output, "\033[32mETH\033[0m ", src(), " > ", dst(), " ");
+ switch (type()) {
+ case Ethernet_frame::ARP:
+ Genode::print(output,
+ *reinterpret_cast(data()));
+ break;
+ case Ethernet_frame::IPV4:
+ Genode::print(output,
+ *reinterpret_cast(data()));
+ break;
+ default: ; }
+}
diff --git a/repos/os/src/lib/net/ipv4.cc b/repos/os/src/lib/net/ipv4.cc
index 86c826483d..712485b948 100644
--- a/repos/os/src/lib/net/ipv4.cc
+++ b/repos/os/src/lib/net/ipv4.cc
@@ -14,11 +14,30 @@
#include
#include
+#include
+#include
#include
using namespace Genode;
using namespace Net;
+
+void Net::Ipv4_packet::print(Genode::Output &output) const
+{
+ Genode::print(output, "\033[32mIPV4\033[0m ", src(), " > ", dst(), " ");
+ switch (protocol()) {
+ case Tcp_packet::IP_ID:
+ Genode::print(output,
+ *reinterpret_cast(data()));
+ break;
+ case Udp_packet::IP_ID:
+ Genode::print(output,
+ *reinterpret_cast(data()));
+ break;
+ default: ; }
+}
+
+
struct Scanner_policy_number
{
static bool identifier_char(char c, unsigned i ) {
diff --git a/repos/os/src/lib/net/tcp.cc b/repos/os/src/lib/net/tcp.cc
new file mode 100644
index 0000000000..9ac7f25b55
--- /dev/null
+++ b/repos/os/src/lib/net/tcp.cc
@@ -0,0 +1,31 @@
+/*
+ * \brief Transmission Control Protocol
+ * \author Martin Stein
+ * \date 2016-06-15
+ */
+
+/*
+ * Copyright (C) 2016 Genode Labs GmbH
+ *
+ * This file is part of the Genode OS framework, which is distributed
+ * under the terms of the GNU General Public License version 2.
+ */
+
+/* Genode includes */
+#include
+#include
+
+
+void Net::Tcp_packet::print(Genode::Output &output) const
+{
+ Genode::print(output, "\033[32mTCP\033[0m ", src_port(),
+ " > ", dst_port(), " flags '");
+
+ if (fin()) { Genode::print(output, "f"); }
+ if (syn()) { Genode::print(output, "s"); }
+ if (rst()) { Genode::print(output, "r"); }
+ if (psh()) { Genode::print(output, "p"); }
+ if (ack()) { Genode::print(output, "a"); }
+ if (urg()) { Genode::print(output, "u"); }
+ Genode::print(output, "' ");
+}
diff --git a/repos/os/src/lib/net/udp.cc b/repos/os/src/lib/net/udp.cc
new file mode 100644
index 0000000000..549a2f3b74
--- /dev/null
+++ b/repos/os/src/lib/net/udp.cc
@@ -0,0 +1,28 @@
+/*
+ * \brief User datagram protocol.
+ * \author Stefan Kalkowski
+ * \date 2010-08-19
+ */
+
+/*
+ * Copyright (C) 2010-2013 Genode Labs GmbH
+ *
+ * This file is part of the Genode OS framework, which is distributed
+ * under the terms of the GNU General Public License version 2.
+ */
+
+/* Genode */
+#include
+#include
+#include
+
+
+void Net::Udp_packet::print(Genode::Output &output) const
+{
+ Genode::print(output, "\033[32mUDP\033[0m ", src_port(),
+ " > ", dst_port(), " ");
+ if (Dhcp_packet::is_dhcp(this)) {
+ Genode::print(output,
+ *reinterpret_cast(data()));
+ }
+}