33 #include <boost/range/adaptor/map.hpp>
34 #include <pcap/pcap.h>
42 time::nanoseconds idleTimeout)
43 : m_localEndpoint(std::
move(localEndpoint))
44 , m_isListening(false)
46 , m_pcap(m_localEndpoint->getName())
47 , m_idleFaceTimeout(idleTimeout)
62 shared_ptr<Face> face;
64 face = createFace(remoteEndpoint, params).second;
66 catch (
const boost::system::system_error& e) {
69 onConnectFailed(504,
"Face creation failed: "s + e.what());
90 m_socket.assign(m_pcap.
getFd());
97 asyncRead(onFaceCreated, onFaceCreationFailed);
105 m_socket.async_read_some(boost::asio::null_buffers(),
106 [=] (
const auto& e,
auto) { this->handleRead(e, onFaceCreated, onReceiveFailed); });
110 EthernetChannel::handleRead(
const boost::system::error_code& error,
115 if (error != boost::asio::error::operation_aborted) {
118 onReceiveFailed(500,
"Receive failed: " + error.message());
128 if (pkt ==
nullptr) {
132 const ether_header* eh;
134 m_localEndpoint->getEthernetAddress());
139 ethernet::Address sender(eh->ether_shost);
142 processIncomingPacket(pkt, len, sender, onFaceCreated, onReceiveFailed);
148 if (nDropped - m_nDropped > 0)
150 m_nDropped = nDropped;
153 asyncRead(onFaceCreated, onReceiveFailed);
157 EthernetChannel::processIncomingPacket(
const uint8_t* packet,
size_t length,
158 const ethernet::Address& sender,
164 bool isCreated =
false;
165 shared_ptr<Face> face;
169 std::tie(isCreated, face) = createFace(sender, params);
171 catch (
const EthernetTransport::Error& e) {
174 onReceiveFailed(504,
"Face creation failed: "s + e.what());
185 transport->receivePayload(packet, length, sender);
188 std::pair<bool, shared_ptr<Face>>
189 EthernetChannel::createFace(
const ethernet::Address& remoteEndpoint,
190 const FaceParams& params)
192 auto it = m_channelFaces.find(remoteEndpoint);
193 if (it != m_channelFaces.end()) {
196 return {
false, it->second};
200 GenericLinkService::Options options;
201 options.allowFragmentation =
true;
202 options.allowReassembly =
true;
203 options.reliabilityOptions.isEnabled = params.wantLpReliability;
205 auto linkService = make_unique<GenericLinkService>(options);
206 auto transport = make_unique<UnicastEthernetTransport>(*m_localEndpoint, remoteEndpoint,
207 params.persistency, m_idleFaceTimeout,
211 m_channelFaces[remoteEndpoint] = face;
213 m_channelFaces.erase(remoteEndpoint);
222 EthernetChannel::updateFilter()
228 ") && (ether dst " + m_localEndpoint->getEthernetAddress().toString() +
")";
229 for (
const auto& addr : m_channelFaces | boost::adaptors::map_keys) {
230 filter +=
" && (not ether src " + addr.toString() +
")";
234 filter +=
" && (not vlan)";