net: add IPv4 support

Currently only ARP is integrated.
This commit is contained in:
Avi Kivity
2014-08-31 20:38:06 +03:00
parent 370a46462c
commit ad312f9889
2 changed files with 27 additions and 0 deletions

11
ip.cc
View File

@@ -45,4 +45,15 @@ uint16_t ip_checksum(void* data, size_t len) {
return htons(~csum);
}
ipv4::ipv4(interface* netif)
: _netif(netif)
, _global_arp(netif)
, _arp(_global_arp) {
}
void ipv4::set_host_address(ipv4_address ip) {
_host_address = ip;
_arp.set_self_addr(ip);
}
}

16
ip.hh
View File

@@ -10,6 +10,7 @@
#include <cstdint>
#include <array>
#include "byteorder.hh"
#include "arp.hh"
namespace net {
@@ -47,6 +48,21 @@ struct hash<net::ipv4_address> {
namespace net {
class ipv4 {
public:
using address_type = ipv4_address;
static address_type broadcast_address() { return ipv4_address(0xffffffff); }
static uint16_t arp_protocol_type() { return 0x0800; }
private:
interface* _netif;
arp _global_arp;
arp_for<ipv4> _arp;
ipv4_address _host_address;
public:
explicit ipv4(interface* netif);
void set_host_address(ipv4_address ip);
};
struct ip_hdr {
uint8_t ihl : 4;
uint8_t ver : 4;