From ad312f988901a940a5ecfbdca1be8a4f3385f728 Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Sun, 31 Aug 2014 20:38:06 +0300 Subject: [PATCH] net: add IPv4 support Currently only ARP is integrated. --- ip.cc | 11 +++++++++++ ip.hh | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/ip.cc b/ip.cc index d38229ca49..f6a8dc4633 100644 --- a/ip.cc +++ b/ip.cc @@ -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); +} + } diff --git a/ip.hh b/ip.hh index 259a16db30..ba14f99a7d 100644 --- a/ip.hh +++ b/ip.hh @@ -10,6 +10,7 @@ #include #include #include "byteorder.hh" +#include "arp.hh" namespace net { @@ -47,6 +48,21 @@ struct hash { 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 _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;