mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-22 09:30:45 +00:00
net: teach an interface/device about hardware addresses
Since the interface must add its own hardware address when sending packets, it better know about them.
This commit is contained in:
4
net.cc
4
net.cc
@@ -39,6 +39,10 @@ future<packet, ethernet_address> interface::receive(uint16_t proto_num) {
|
||||
return pr.get_future();
|
||||
}
|
||||
|
||||
interface::interface(std::unique_ptr<device> dev)
|
||||
: _dev(std::move(dev)), _hw_address(_dev->hw_address()) {
|
||||
}
|
||||
|
||||
void interface::run() {
|
||||
_dev->receive().then([this] (packet p) {
|
||||
auto eh = p.get_header<eth_hdr>(0);
|
||||
|
||||
5
net.hh
5
net.hh
@@ -132,11 +132,13 @@ private:
|
||||
class interface {
|
||||
std::unique_ptr<device> _dev;
|
||||
std::unordered_map<uint16_t, promise<packet, ethernet_address>> _proto_map;
|
||||
ethernet_address _hw_address;
|
||||
private:
|
||||
future<packet, ethernet_address> receive(uint16_t proto_num);
|
||||
future<> send(uint16_t proto_num, ethernet_address to, packet p);
|
||||
public:
|
||||
explicit interface(std::unique_ptr<device> dev) : _dev(std::move(dev)) {}
|
||||
explicit interface(std::unique_ptr<device> dev);
|
||||
ethernet_address hw_address() { return _hw_address; }
|
||||
void run();
|
||||
friend class l3_protocol;
|
||||
};
|
||||
@@ -146,6 +148,7 @@ public:
|
||||
virtual ~device() {}
|
||||
virtual future<packet> receive() = 0;
|
||||
virtual future<> send(packet p) = 0;
|
||||
virtual ethernet_address hw_address() = 0;
|
||||
};
|
||||
|
||||
inline
|
||||
|
||||
@@ -339,6 +339,7 @@ public:
|
||||
explicit virtio_net_device(sstring tap_device, init x = init());
|
||||
virtual future<packet> 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<net::device> create_virtio_net_device(sstring tap_device) {
|
||||
return std::make_unique<virtio_net_device>(tap_device);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user