20 #include "NetworkStack.h" 22 #include "modules/Module.h" 23 #include "pedigree/kernel/LockGuard.h" 24 #include "pedigree/kernel/Log.h" 25 #include "pedigree/kernel/processor/Processor.h" 43 size_t totalLength = p->
tot_len;
47 char *output =
new char[totalLength];
53 1, reinterpret_cast<uintptr_t>(output), totalLength))
61 if (!pDevice->
send(totalLength, reinterpret_cast<uintptr_t>(output)))
71 static void netifStatusUpdate(
struct netif *netif)
83 static void netifLinkUpdate(
struct netif *netif)
95 static err_t netifInit(
struct netif *netif)
102 MemoryCopy(netif->
hwaddr, info.mac.getMac(), 6);
106 netif->output = etharp_output;
107 netif->output_ip6 = ethip6_output;
109 netif_set_status_callback(netif, netifStatusUpdate);
110 netif_set_link_callback(netif, netifLinkUpdate);
115 NetworkStack::NetworkStack()
116 :
RequestQueue(
"Network Stack"), m_pLoopback(0), m_Children(),
117 m_MemPool(
"network-pool")
123 m_NextInterfaceNumber(0)
127 FATAL(
"NetworkStack created multiple times.");
134 #if defined(X86_COMMON) || defined(HOSTED) 136 if (!m_MemPool.initialise(4096, 1600))
137 if (!m_MemPool.initialise(2048, 1600))
138 if (!m_MemPool.initialise(1024, 1600))
139 ERROR(
"Couldn't get a valid buffer pool for networking use");
140 #elif defined(ARM_COMMON) 142 NOTICE(
"allocating memory pool");
143 if (!m_MemPool.initialise(1024, 1600))
144 if (!m_MemPool.initialise(512, 1600))
145 if (!m_MemPool.initialise(128, 1600))
146 ERROR(
"Couldn't get a valid buffer pool for networking use");
148 #warning Unhandled architecture for the NetworkStack buffer pool 152 NetworkStack::~NetworkStack()
160 uint64_t p1, uint64_t p2, uint64_t p3, uint64_t p4, uint64_t p5,
161 uint64_t p6, uint64_t p7, uint64_t p8)
166 #if defined(THREADS) || defined(UTILITY_LINUX) 170 struct pbuf *p =
reinterpret_cast<struct
pbuf *
>(p1);
171 struct netif *iface =
reinterpret_cast<struct netif *
>(p2);
173 iface->
input(p, iface);
179 size_t nBytes, uintptr_t packet,
Network *pCard, uint32_t offset)
190 struct netif *iface = getInterface(pCard);
193 ERROR(
"Network Stack: no lwIP interface for received packet");
201 struct pbuf *buf = p;
202 while (buf !=
nullptr)
204 size_t copyLength = buf->
len;
206 buf->
payload, reinterpret_cast<void *>(packet), buf->
len);
216 ERROR(
"Network Stack: Out of memory pool space, dropping incoming " 222 uint64_t result = addRequest(
223 0, reinterpret_cast<uint64_t>(p), reinterpret_cast<uintptr_t>(iface));
228 #if defined(THREADS) || defined(UTILITY_LINUX) 232 size_t interfaceNumber = m_NextInterfaceNumber++;
234 if (interfaceNumber >= 0xFFU)
236 FATAL(
"Too many network interfaces!");
241 struct netif *iface =
new struct netif;
242 ByteSet(iface, 0,
sizeof(*iface));
249 ByteSet(&ipaddr, 0,
sizeof(ipaddr));
250 ByteSet(&netmask, 0,
sizeof(netmask));
251 ByteSet(&gateway, 0,
sizeof(gateway));
253 iface->
name[0] =
'e';
254 iface->
name[1] =
'n';
255 iface->
num = interfaceNumber;
259 m_Interfaces.insert(pDevice, iface);
283 struct netif *iface = m_Interfaces.lookup(pDevice);
284 m_Interfaces.remove(pDevice);
286 if (iface !=
nullptr)
294 NetworkStack::Packet::Packet() =
default;
296 NetworkStack::Packet::~Packet()
305 bool NetworkStack::Packet::copyFrom(uintptr_t otherPacket,
size_t size)
307 uint8_t *safePacket =
reinterpret_cast<uint8_t *
>(
313 MemoryCopy(safePacket, reinterpret_cast<void *>(otherPacket), size);
315 m_Buffer =
reinterpret_cast<uintptr_t
>(safePacket);
316 m_PacketLength = size;
329 delete g_NetworkStack;
333 MODULE_INFO(
"network-stack", &entry, &exit,
"config",
"vfs",
"lwip");
u8_t hwaddr[NETIF_MAX_HWADDR_LEN]
virtual void droppedPacket()
Called when a packet is dropped by the system.
void pushBack(const T &value)
struct netif * netif_add(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input)
A vector / dynamic array.
#define netif_is_link_up(netif)
virtual const StationInfo & getStationInfo()
#define NETIF_FLAG_BROADCAST
void receive(size_t nBytes, uintptr_t packet, Network *pCard, uint32_t offset)
#define NETIF_FLAG_ETHERNET
Network * getDevice(size_t n)
err_t tcpip_input(struct pbuf *p, struct netif *inp)
#define NETIF_FLAG_LINK_UP
virtual bool send(size_t nBytes, uintptr_t buffer)=0
void netif_remove(struct netif *netif)
void deRegisterDevice(Network *pDevice)
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
u16_t pbuf_copy_partial(const struct pbuf *buf, void *dataptr, u16_t len, u16_t offset)
#define netif_is_up(netif)
static NetworkStack & instance()
void registerDevice(Network *pDevice)
#define NETIF_FLAG_ETHARP
void free(uintptr_t buffer)
Frees an allocated buffer, allowing it to be used elsewhere.
virtual uint64_t executeRequest(uint64_t p1, uint64_t p2, uint64_t p3, uint64_t p4, uint64_t p5, uint64_t p6, uint64_t p7, uint64_t p8)
static NetworkFilter & instance()
netif_linkoutput_fn linkoutput
Vector< Device * > m_Children