2020-01-18 08:38:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 08:38:21 +00:00
|
|
|
*/
|
|
|
|
|
2020-08-25 01:35:19 +00:00
|
|
|
#include <AK/Singleton.h>
|
2019-04-02 13:46:44 +00:00
|
|
|
#include <Kernel/Net/LoopbackAdapter.h>
|
|
|
|
|
2020-02-16 00:27:42 +00:00
|
|
|
namespace Kernel {
|
|
|
|
|
2021-06-04 04:43:16 +00:00
|
|
|
static bool s_loopback_initialized = false;
|
2020-08-25 01:35:19 +00:00
|
|
|
|
2022-08-19 18:53:40 +00:00
|
|
|
LockRefPtr<LoopbackAdapter> LoopbackAdapter::try_create()
|
2019-04-02 13:46:44 +00:00
|
|
|
{
|
2021-09-28 00:49:56 +00:00
|
|
|
auto interface_name = KString::try_create("loop"sv);
|
|
|
|
if (interface_name.is_error())
|
|
|
|
return {};
|
2022-08-19 18:53:40 +00:00
|
|
|
return adopt_lock_ref_if_nonnull(new LoopbackAdapter(interface_name.release_value()));
|
2019-04-02 13:46:44 +00:00
|
|
|
}
|
|
|
|
|
2021-09-28 00:49:56 +00:00
|
|
|
LoopbackAdapter::LoopbackAdapter(NonnullOwnPtr<KString> interface_name)
|
|
|
|
: NetworkAdapter(move(interface_name))
|
2019-04-02 13:46:44 +00:00
|
|
|
{
|
2021-06-04 04:43:16 +00:00
|
|
|
VERIFY(!s_loopback_initialized);
|
|
|
|
s_loopback_initialized = true;
|
2019-11-28 06:12:05 +00:00
|
|
|
set_mtu(65536);
|
2020-02-09 11:03:07 +00:00
|
|
|
set_mac_address({ 19, 85, 2, 9, 0x55, 0xaa });
|
2019-04-02 13:46:44 +00:00
|
|
|
}
|
|
|
|
|
2022-03-16 19:15:15 +00:00
|
|
|
LoopbackAdapter::~LoopbackAdapter() = default;
|
2019-04-02 13:46:44 +00:00
|
|
|
|
2020-07-28 18:19:22 +00:00
|
|
|
void LoopbackAdapter::send_raw(ReadonlyBytes payload)
|
2019-04-02 13:46:44 +00:00
|
|
|
{
|
2021-01-10 14:43:09 +00:00
|
|
|
dbgln("LoopbackAdapter: Sending {} byte(s) to myself.", payload.size());
|
2020-07-28 18:19:22 +00:00
|
|
|
did_receive(payload);
|
2019-04-02 13:46:44 +00:00
|
|
|
}
|
2020-02-16 00:27:42 +00:00
|
|
|
|
|
|
|
}
|