10#include "virtio_net.h"
11#include "virtio_net_buffer.h"
14#include <l4/l4virtio/server/virtio>
41 void const *
req_id()
const {
return _req_id; }
46 virtual void copy_header(Virtio_net::Hdr *dst_header)
const = 0;
78 return (_pkt.pos && _pkt.left >= Mac_addr::Addr_length)
86 return (_pkt.pos && _pkt.left >= Mac_addr::Addr_length * 2)
87 ?
Mac_addr(_pkt.pos + Mac_addr::Addr_length)
93 if (!_pkt.pos || _pkt.left < 14)
96 uint8_t *p =
reinterpret_cast<uint8_t *
>(_pkt.pos);
97 return p[12] == 0x81U && p[13] == 0x00U;
100 uint16_t vlan_id()
const
102 if (!has_vlan() || _pkt.left < 16)
103 return VLAN_ID_NATIVE;
105 uint8_t *p =
reinterpret_cast<uint8_t *
>(_pkt.pos);
106 return (uint16_t{p[14]} << 8 | p[15]) & 0xfffU;
120 uint8_t
const *buffer(
size_t *size)
const
123 return reinterpret_cast<uint8_t
const *
>(_pkt.pos);
126 void dump_pkt()
const
128 Dbg pkt_debug(Dbg::Packet, Dbg::Debug,
"PKT");
129 if (pkt_debug.is_active())
131 pkt_debug.cprintf(
"\t");
132 src_mac().print(pkt_debug);
133 pkt_debug.cprintf(
" -> ");
134 dst_mac().print(pkt_debug);
135 pkt_debug.cprintf(
"\n");
137 Dbg pkt_trace(Dbg::Packet, Dbg::Trace,
"PKT");
138 if (pkt_trace.is_active() && _pkt.left >= 14)
140 uint8_t
const *packet =
reinterpret_cast<uint8_t
const *
>(_pkt.pos);
141 pkt_trace.cprintf(
"\n\tEthertype: ");
142 uint16_t ether_type = uint16_t{packet[12]} << 8 | packet[13];
143 char const *protocol;
146 case 0x0800: protocol =
"IPv4";
break;
147 case 0x0806: protocol =
"ARP";
break;
148 case 0x8100: protocol =
"Vlan";
break;
149 case 0x86dd: protocol =
"IPv6";
break;
150 case 0x8863: protocol =
"PPPoE Discovery";
break;
151 case 0x8864: protocol =
"PPPoE Session";
break;
152 default: protocol =
nullptr;
155 pkt_trace.cprintf(
"%s\n", protocol);
157 pkt_trace.cprintf(
"%04x\n", ether_type);
A wrapper class around the value of a MAC address.
A network request to only a single destination.
virtual void copy_header(Virtio_net::Hdr *dst_header) const =0
Populate the virtio-net header for the destination.
void const * req_id() const
Identifier for the underlying Net_request, used for logging purposes.
virtual bool done()=0
Check whether the transfer has been completed, i.e.
Buffer & cur_buf()
Buffer containing (a part of) the packet data.
Data buffer used to transfer packets.