mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-22 09:30:45 +00:00
net: add IPv4 support
Currently only ARP is integrated.
This commit is contained in:
11
ip.cc
11
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
16
ip.hh
16
ip.hh
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user