Skip to content

Commit 4675d9c

Browse files
committed
Add Files.
1 parent 2eec8d1 commit 4675d9c

File tree

6 files changed

+40
-10
lines changed

6 files changed

+40
-10
lines changed

ppp/app/client/VEthernetNetworkSwitcher.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ using ppp::threading::Timer;
2222
using ppp::threading::Executors;
2323
using ppp::net::AddressFamily;
2424
using ppp::net::IPEndPoint;
25+
using ppp::net::Ipep;
2526
using ppp::net::native::ip_hdr;
2627
using ppp::net::native::udp_hdr;
2728
using ppp::net::native::icmp_hdr;
@@ -71,7 +72,7 @@ namespace ppp {
7172
boost::asio::ip::udp::endpoint sourceEP = IPEndPoint::ToEndPoint<boost::asio::ip::udp>(frame->Source);
7273
std::shared_ptr<VEthernetDatagramPort> datagram = AllocDatagramPort(sourceEP);
7374
if (NULL != datagram) {
74-
const std::shared_ptr<BufferSegment>& messages = packet->Payload;
75+
const std::shared_ptr<BufferSegment>& messages = frame->Payload;
7576
if (NULL != messages) {
7677
boost::asio::ip::udp::endpoint destinationEP = IPEndPoint::ToEndPoint<boost::asio::ip::udp>(frame->Destination);
7778
return datagram->SendTo(messages->Buffer.get(), messages->Length, destinationEP);
@@ -119,6 +120,7 @@ namespace ppp {
119120

120121
VEthernetNetworkSwitcher::VEthernetDatagramPortPtr VEthernetNetworkSwitcher::AllocDatagramPort(const boost::asio::ip::udp::endpoint& sourceEP) noexcept {
121122
using VEthernetDisposedEventHandler = VEthernetDatagramPort::VEthernetDisposedEventHandler;
123+
using VEthernetMessageEventHandler = VEthernetDatagramPort::VEthernetMessageEventHandler;
122124

123125
SynchronizedObjectScope scope(syncobj_);
124126
if (this->IsDisposed()) {
@@ -145,6 +147,25 @@ namespace ppp {
145147
[self, this](VEthernetDatagramPort* datagram) noexcept {
146148
DeleteDatagramPort(datagram->GetLocalEndPoint());
147149
});
150+
datagram->MessageEvent = make_shared_object<VEthernetMessageEventHandler>(
151+
[self, this](VEthernetDatagramPort* datagram, void* packet, int packet_size, const boost::asio::ip::udp::endpoint& destinationEP) noexcept {
152+
boost::asio::ip::udp::endpoint remoteEP = Ipep::V6ToV4(destinationEP);
153+
boost::asio::ip::address address = remoteEP.address();
154+
if (address.is_v4()) {
155+
std::shared_ptr<BufferSegment> messages = make_shared_object<BufferSegment>();
156+
messages->Buffer = std::shared_ptr<Byte>(reinterpret_cast<Byte*>(packet), [](Byte*) noexcept {});
157+
messages->Length = packet_size;
158+
159+
std::shared_ptr<UdpFrame> frame = make_shared_object<UdpFrame>();
160+
frame->AddressesFamily = AddressFamily::InterNetwork;
161+
frame->Source = IPEndPoint::ToEndPoint(remoteEP);
162+
frame->Destination = IPEndPoint::ToEndPoint(datagram->GetLocalEndPoint());
163+
frame->Payload = messages;
164+
165+
std::shared_ptr<IPFrame> ip = UdpFrame::ToIp(frame.get());
166+
Output(ip.get());
167+
}
168+
});
148169
return datagram;
149170
}
150171

ppp/app/server/VirtualEthernetDatagramPort.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ namespace ppp {
124124
bool disposing = false;
125125
if (!ec) {
126126
if (sz > 0) {
127-
boost::asio::ip::udp::endpoint destinationEP = Ipep::V6ToV4(sourceEP_);
128-
if (!manager_->DoSendTo(transmission_, remoteEP_, destinationEP, buffer_.get(), sz, nullof<YieldContext>())) {
127+
boost::asio::ip::udp::endpoint remoteEP = Ipep::V6ToV4(remoteEP_);
128+
if (!manager_->DoSendTo(transmission_, sourceEP_, remoteEP, buffer_.get(), sz, nullof<YieldContext>())) {
129129
disposing = true;
130130
transmission_->Dispose();
131131
}

ppp/ethernet/VEthernet.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,21 @@ namespace ppp
351351
return true;
352352
}
353353

354+
bool VEthernet::Output(IPFrame* packet) noexcept
355+
{
356+
if (NULL == packet)
357+
{
358+
return false;
359+
}
360+
361+
std::shared_ptr<BufferSegment> messages = IPFrame::ToArray(packet);
362+
if (NULL == messages) {
363+
return false;
364+
}
365+
366+
return Output(messages->Buffer, messages->Length);
367+
}
368+
354369
bool VEthernet::Output(const void* packet, int packet_length) noexcept
355370
{
356371
std::shared_ptr<ITap> tap = GetTap();

ppp/ethernet/VEthernet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ namespace ppp
4343
virtual std::shared_ptr<VNetstack> NewNetstack() noexcept;
4444
virtual bool OnPacketInput(const std::shared_ptr<IPFrame>& packet) noexcept;
4545
virtual void OnTick(uint64_t now) noexcept;
46+
bool Output(IPFrame* packet) noexcept;
4647
virtual bool Output(const void* packet, int packet_length) noexcept;
4748
virtual bool Output(const std::shared_ptr<Byte>& packet, int packet_length) noexcept;
4849

ppp/threading/Executors.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,6 @@ namespace ppp
361361

362362
}
363363

364-
Executors::Awaitable::~Awaitable() noexcept
365-
{
366-
completed = true;
367-
cv.notify_all();
368-
}
369-
370364
void Executors::Awaitable::Processed() noexcept
371365
{
372366
completed = true;

ppp/threading/Executors.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ namespace ppp
1515
{
1616
public:
1717
Awaitable() noexcept;
18-
virtual ~Awaitable() noexcept;
1918

2019
public:
2120
virtual void Processed() noexcept;

0 commit comments

Comments
 (0)