diff --git a/net.cc b/net.cc index e5ad25d86e..e33a3a112f 100644 --- a/net.cc +++ b/net.cc @@ -39,6 +39,10 @@ future interface::receive(uint16_t proto_num) { return pr.get_future(); } +interface::interface(std::unique_ptr dev) + : _dev(std::move(dev)), _hw_address(_dev->hw_address()) { +} + void interface::run() { _dev->receive().then([this] (packet p) { auto eh = p.get_header(0); diff --git a/net.hh b/net.hh index 0261363f9b..425a2d002c 100644 --- a/net.hh +++ b/net.hh @@ -132,11 +132,13 @@ private: class interface { std::unique_ptr _dev; std::unordered_map> _proto_map; + ethernet_address _hw_address; private: future receive(uint16_t proto_num); future<> send(uint16_t proto_num, ethernet_address to, packet p); public: - explicit interface(std::unique_ptr dev) : _dev(std::move(dev)) {} + explicit interface(std::unique_ptr dev); + ethernet_address hw_address() { return _hw_address; } void run(); friend class l3_protocol; }; @@ -146,6 +148,7 @@ public: virtual ~device() {} virtual future receive() = 0; virtual future<> send(packet p) = 0; + virtual ethernet_address hw_address() = 0; }; inline diff --git a/virtio.cc b/virtio.cc index 4822e85e1b..18e1500e98 100644 --- a/virtio.cc +++ b/virtio.cc @@ -339,6 +339,7 @@ public: explicit virtio_net_device(sstring tap_device, init x = init()); virtual future receive() override; virtual future<> send(packet p) override; + virtual ethernet_address hw_address() override; }; virtio_net_device::txq::txq(virtio_net_device& dev, vring::config config, @@ -514,6 +515,10 @@ void virtio_net_device::queue_rx_packet(packet p) { _rx_queue_length.signal(1); } +ethernet_address virtio_net_device::hw_address() { + return { 0x12, 0x23, 0x34, 0x56, 0x67, 0x78 }; +} + std::unique_ptr create_virtio_net_device(sstring tap_device) { return std::make_unique(tap_device); }