net: transform packet data accessor into template

Supports stronger typing of raw accesses and const correctness.

Issue #1915
This commit is contained in:
Christian Helmuth
2016-05-09 15:47:28 +02:00
parent 3df03fbc41
commit abed38e8ac
6 changed files with 19 additions and 14 deletions

View File

@ -26,7 +26,7 @@ static const int verbose = 1;
bool Session_component::handle_arp(Ethernet_frame *eth, Genode::size_t size)
{
Arp_packet *arp =
new (eth->data()) Arp_packet(size - sizeof(Ethernet_frame));
new (eth->data<void>()) Arp_packet(size - sizeof(Ethernet_frame));
if (arp->ethernet_ipv4() &&
arp->opcode() == Arp_packet::REQUEST) {
@ -55,14 +55,14 @@ bool Session_component::handle_arp(Ethernet_frame *eth, Genode::size_t size)
bool Session_component::handle_ip(Ethernet_frame *eth, Genode::size_t size)
{
Ipv4_packet *ip =
new (eth->data()) Ipv4_packet(size - sizeof(Ethernet_frame));
new (eth->data<void>()) Ipv4_packet(size - sizeof(Ethernet_frame));
if (ip->protocol() == Udp_packet::IP_ID)
{
Udp_packet *udp = new (ip->data())
Udp_packet *udp = new (ip->data<void>())
Udp_packet(size - sizeof(Ipv4_packet));
if (Dhcp_packet::is_dhcp(udp)) {
Dhcp_packet *dhcp = new (udp->data())
Dhcp_packet *dhcp = new (udp->data<void>())
Dhcp_packet(size - sizeof(Ipv4_packet) - sizeof(Udp_packet));
if (dhcp->op() == Dhcp_packet::REQUEST) {
dhcp->broadcast(true);

View File

@ -24,7 +24,7 @@ using namespace Net;
bool Net::Nic::handle_arp(Ethernet_frame *eth, Genode::size_t size) {
Arp_packet *arp = new (eth->data())
Arp_packet *arp = new (eth->data<void>())
Arp_packet(size - sizeof(Ethernet_frame));
/* ignore broken packets */
@ -66,18 +66,18 @@ bool Net::Nic::handle_arp(Ethernet_frame *eth, Genode::size_t size) {
bool Net::Nic::handle_ip(Ethernet_frame *eth, Genode::size_t size) {
Ipv4_packet *ip = new (eth->data())
Ipv4_packet *ip = new (eth->data<void>())
Ipv4_packet(size - sizeof(Ethernet_frame));
/* is it an UDP packet ? */
if (ip->protocol() == Udp_packet::IP_ID)
{
Udp_packet *udp = new (ip->data())
Udp_packet *udp = new (ip->data<void>())
Udp_packet(size - sizeof(Ipv4_packet));
/* is it a DHCP packet ? */
if (Dhcp_packet::is_dhcp(udp)) {
Dhcp_packet *dhcp = new (udp->data())
Dhcp_packet *dhcp = new (udp->data<void>())
Dhcp_packet(size - sizeof(Ipv4_packet) - sizeof(Udp_packet));
/* check for DHCP ACKs containing new client ips */