git.ucc.asn.au
/
tpg
/
acess2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Usermode/Libs - x86_64 port in progress
[tpg/acess2.git]
/
Modules
/
IPStack
/
udp.c
diff --git
a/Modules/IPStack/udp.c
b/Modules/IPStack/udp.c
index
760c997
..
c1dbe92
100644
(file)
--- a/
Modules/IPStack/udp.c
+++ b/
Modules/IPStack/udp.c
@@
-11,10
+11,12
@@
// === PROTOTYPES ===
void UDP_Initialise();
void UDP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffer);
// === PROTOTYPES ===
void UDP_Initialise();
void UDP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffer);
+void UDP_Unreachable(tInterface *Interface, int Code, void *Address, int Length, void *Buffer);
+void UDP_SendPacket(tUDPChannel *Channel, void *Data, size_t Length);
// --- Listening Server
tVFS_Node *UDP_Server_Init(tInterface *Interface);
char *UDP_Server_ReadDir(tVFS_Node *Node, int ID);
// --- Listening Server
tVFS_Node *UDP_Server_Init(tInterface *Interface);
char *UDP_Server_ReadDir(tVFS_Node *Node, int ID);
-tVFS_Node *UDP_Server_FindDir(tVFS_Node *Node, char *Name);
+tVFS_Node *UDP_Server_FindDir(tVFS_Node *Node, c
onst c
har *Name);
int UDP_Server_IOCtl(tVFS_Node *Node, int ID, void *Data);
void UDP_Server_Close(tVFS_Node *Node);
// --- Client Channels
int UDP_Server_IOCtl(tVFS_Node *Node, int ID, void *Data);
void UDP_Server_Close(tVFS_Node *Node);
// --- Client Channels
@@
-29,13
+31,13
@@
Uint16 UDP_int_AllocatePort();
void UDP_int_FreePort(Uint16 Port);
// === GLOBALS ===
void UDP_int_FreePort(Uint16 Port);
// === GLOBALS ===
-t
Spinlock
glUDP_Servers;
+t
Mutex
glUDP_Servers;
tUDPServer *gpUDP_Servers;
tUDPServer *gpUDP_Servers;
-t
Spinlock
glUDP_Channels;
+t
Mutex
glUDP_Channels;
tUDPChannel *gpUDP_Channels;
tUDPChannel *gpUDP_Channels;
-t
Spinlock
glUDP_Ports;
+t
Mutex
glUDP_Ports;
Uint32 gUDP_Ports[0x10000/32];
tSocketFile gUDP_ServerFile = {NULL, "udps", UDP_Server_Init};
Uint32 gUDP_Ports[0x10000/32];
tSocketFile gUDP_ServerFile = {NULL, "udps", UDP_Server_Init};
@@
-50,11
+52,12
@@
void UDP_Initialise()
{
IPStack_AddFile(&gUDP_ServerFile);
IPStack_AddFile(&gUDP_ClientFile);
{
IPStack_AddFile(&gUDP_ServerFile);
IPStack_AddFile(&gUDP_ClientFile);
+ //IPv4_RegisterCallback(IP4PROT_UDP, UDP_GetPacket, UDP_Unreachable);
IPv4_RegisterCallback(IP4PROT_UDP, UDP_GetPacket);
}
/**
IPv4_RegisterCallback(IP4PROT_UDP, UDP_GetPacket);
}
/**
- * \brief Scan a list of tUDPChannel
'
s and find process the first match
+ * \brief Scan a list of tUDPChannels and find process the first match
* \return 0 if no match was found, -1 on error and 1 if a match was found
*/
int UDP_int_ScanList(tUDPChannel *List, tInterface *Interface, void *Address, int Length, void *Buffer)
* \return 0 if no match was found, -1 on error and 1 if a match was found
*/
int UDP_int_ScanList(tUDPChannel *List, tInterface *Interface, void *Address, int Length, void *Buffer)
@@
-69,9
+72,7
@@
int UDP_int_ScanList(tUDPChannel *List, tInterface *Interface, void *Address, in
chan = chan->Next)
{
if(chan->Interface != Interface) continue;
chan = chan->Next)
{
if(chan->Interface != Interface) continue;
- //Log("[UDP ] Local (0x%04x) == Dest (0x%04x)", chan->LocalPort, ntohs(hdr->DestPort));
if(chan->LocalPort != ntohs(hdr->DestPort)) continue;
if(chan->LocalPort != ntohs(hdr->DestPort)) continue;
- //Log("[UDP ] Remote (0x%04x) == Source (0x%04x)", chan->RemotePort, ntohs(hdr->SourcePort));
if(chan->RemotePort != ntohs(hdr->SourcePort)) continue;
if(Interface->Type == 4) {
if(chan->RemotePort != ntohs(hdr->SourcePort)) continue;
if(Interface->Type == 4) {
@@
-82,7
+83,7
@@
int UDP_int_ScanList(tUDPChannel *List, tInterface *Interface, void *Address, in
}
else {
Warning("[UDP ] Address type %i unknown", Interface->Type);
}
else {
Warning("[UDP ] Address type %i unknown", Interface->Type);
-
RELEASE
(&glUDP_Channels);
+
Mutex_Release
(&glUDP_Channels);
return -1;
}
return -1;
}
@@
-95,13
+96,13
@@
int UDP_int_ScanList(tUDPChannel *List, tInterface *Interface, void *Address, in
memcpy(pack->Data, hdr->Data, len);
// Add the packet to the channel's queue
memcpy(pack->Data, hdr->Data, len);
// Add the packet to the channel's queue
- LOCK(&chan->lQueue);
+
SHORT
LOCK(&chan->lQueue);
if(chan->Queue)
chan->QueueEnd->Next = pack;
else
chan->QueueEnd = chan->Queue = pack;
if(chan->Queue)
chan->QueueEnd->Next = pack;
else
chan->QueueEnd = chan->Queue = pack;
-
RELEASE
(&chan->lQueue);
-
RELEASE
(&glUDP_Channels);
+
SHORTREL
(&chan->lQueue);
+
Mutex_Release
(&glUDP_Channels);
return 1;
}
return 0;
return 1;
}
return 0;
@@
-123,14
+124,14
@@
void UDP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffe
Log("[UDP ] hdr->Checksum = 0x%x", ntohs(hdr->Checksum));
// Check registered connections
Log("[UDP ] hdr->Checksum = 0x%x", ntohs(hdr->Checksum));
// Check registered connections
-
LOCK
(&glUDP_Channels);
+
Mutex_Acquire
(&glUDP_Channels);
ret = UDP_int_ScanList(gpUDP_Channels, Interface, Address, Length, Buffer);
ret = UDP_int_ScanList(gpUDP_Channels, Interface, Address, Length, Buffer);
-
RELEASE
(&glUDP_Channels);
+
Mutex_Release
(&glUDP_Channels);
if(ret != 0) return ;
// TODO: Server/Listener
if(ret != 0) return ;
// TODO: Server/Listener
-
LOCK
(&glUDP_Servers);
+
Mutex_Acquire
(&glUDP_Servers);
for(srv = gpUDP_Servers;
srv;
srv = srv->Next)
for(srv = gpUDP_Servers;
srv;
srv = srv->Next)
@@
-144,7
+145,15
@@
void UDP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffe
Warning("[UDP ] TODO - Add channel on connection");
//TODO
}
Warning("[UDP ] TODO - Add channel on connection");
//TODO
}
- RELEASE(&glUDP_Servers);
+ Mutex_Release(&glUDP_Servers);
+
+}
+
+/**
+ * \brief Handle an ICMP Unrechable Error
+ */
+void UDP_Unreachable(tInterface *Interface, int Code, void *Address, int Length, void *Buffer)
+{
}
}
@@
-192,10
+201,10
@@
tVFS_Node *UDP_Server_Init(tInterface *Interface)
new->Node.IOCtl = UDP_Server_IOCtl;
new->Node.Close = UDP_Server_Close;
new->Node.IOCtl = UDP_Server_IOCtl;
new->Node.Close = UDP_Server_Close;
-
LOCK
(&glUDP_Servers);
+
Mutex_Acquire
(&glUDP_Servers);
new->Next = gpUDP_Servers;
gpUDP_Servers = new;
new->Next = gpUDP_Servers;
gpUDP_Servers = new;
-
RELEASE
(&glUDP_Servers);
+
Mutex_Release
(&glUDP_Servers);
return &new->Node;
}
return &new->Node;
}
@@
-212,13
+221,13
@@
char *UDP_Server_ReadDir(tVFS_Node *Node, int ID)
if( srv->ListenPort == 0 ) return NULL;
// Lock (so another thread can't collide with us here) and wait for a connection
if( srv->ListenPort == 0 ) return NULL;
// Lock (so another thread can't collide with us here) and wait for a connection
-
LOCK
( &srv->Lock );
+
Mutex_Acquire
( &srv->Lock );
while( srv->NewChannels == NULL ) Threads_Yield();
// Pop the connection off the new list
chan = srv->NewChannels;
srv->NewChannels = chan->Next;
// Release the lock
while( srv->NewChannels == NULL ) Threads_Yield();
// Pop the connection off the new list
chan = srv->NewChannels;
srv->NewChannels = chan->Next;
// Release the lock
-
RELEASE
( &srv->Lock );
+
Mutex_Release
( &srv->Lock );
// Create the ID string and return it
ret = malloc(11+1);
// Create the ID string and return it
ret = malloc(11+1);
@@
-230,7
+239,7
@@
char *UDP_Server_ReadDir(tVFS_Node *Node, int ID)
/**
* \brief Take a string and find the channel
*/
/**
* \brief Take a string and find the channel
*/
-tVFS_Node *UDP_Server_FindDir(tVFS_Node *Node, char *Name)
+tVFS_Node *UDP_Server_FindDir(tVFS_Node *Node, c
onst c
har *Name)
{
tUDPServer *srv = Node->ImplPtr;
tUDPChannel *chan;
{
tUDPServer *srv = Node->ImplPtr;
tUDPChannel *chan;
@@
-315,7
+324,7
@@
void UDP_Server_Close(tVFS_Node *Node)
// Remove from the main list first
// Remove from the main list first
-
LOCK
(&glUDP_Servers);
+
Mutex_Acquire
(&glUDP_Servers);
if(gpUDP_Servers == srv)
gpUDP_Servers = gpUDP_Servers->Next;
else
if(gpUDP_Servers == srv)
gpUDP_Servers = gpUDP_Servers->Next;
else
@@
-328,28
+337,28
@@
void UDP_Server_Close(tVFS_Node *Node)
else
prev->Next = prev->Next->Next;
}
else
prev->Next = prev->Next->Next;
}
-
RELEASE
(&glUDP_Servers);
+
Mutex_Release
(&glUDP_Servers);
-
LOCK
(&srv->Lock);
+
Mutex_Acquire
(&srv->Lock);
for(chan = srv->Channels;
chan;
chan = chan->Next)
{
// Clear Queue
for(chan = srv->Channels;
chan;
chan = chan->Next)
{
// Clear Queue
- LOCK(&chan->lQueue);
+
SHORT
LOCK(&chan->lQueue);
while(chan->Queue)
{
tmp = chan->Queue;
chan->Queue = tmp->Next;
free(tmp);
}
while(chan->Queue)
{
tmp = chan->Queue;
chan->Queue = tmp->Next;
free(tmp);
}
-
RELEASE
(&chan->lQueue);
+
SHORTREL
(&chan->lQueue);
// Free channel structure
free(chan);
}
// Free channel structure
free(chan);
}
-
RELEASE
(&srv->Lock);
+
Mutex_Release
(&srv->Lock);
free(srv);
}
free(srv);
}
@@
-368,10
+377,10
@@
tVFS_Node *UDP_Channel_Init(tInterface *Interface)
new->Node.IOCtl = UDP_Channel_IOCtl;
new->Node.Close = UDP_Channel_Close;
new->Node.IOCtl = UDP_Channel_IOCtl;
new->Node.Close = UDP_Channel_Close;
-
LOCK
(&glUDP_Channels);
+
Mutex_Acquire
(&glUDP_Channels);
new->Next = gpUDP_Channels;
gpUDP_Channels = new;
new->Next = gpUDP_Channels;
gpUDP_Channels = new;
-
RELEASE
(&glUDP_Channels);
+
Mutex_Release
(&glUDP_Channels);
return &new->Node;
}
return &new->Node;
}
@@
-391,15
+400,19
@@
Uint64 UDP_Channel_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buf
for(;;)
{
for(;;)
{
- LOCK(&chan->lQueue);
+ VFS_SelectNode(Node, VFS_SELECT_READ, NULL, "UDP_Channel_Read");
+ SHORTLOCK(&chan->lQueue);
if(chan->Queue == NULL) {
if(chan->Queue == NULL) {
-
RELEASE
(&chan->lQueue);
+
SHORTREL
(&chan->lQueue);
continue;
}
pack = chan->Queue;
chan->Queue = pack->Next;
continue;
}
pack = chan->Queue;
chan->Queue = pack->Next;
- if(!chan->Queue) chan->QueueEnd = NULL;
- RELEASE(&chan->lQueue);
+ if(!chan->Queue) {
+ chan->QueueEnd = NULL;
+ VFS_MarkAvaliable(Node, 0); // Nothing left
+ }
+ SHORTREL(&chan->lQueue);
break;
}
break;
}
@@
-512,7
+525,7
@@
void UDP_Channel_Close(tVFS_Node *Node)
tUDPChannel *prev;
// Remove from the main list first
tUDPChannel *prev;
// Remove from the main list first
-
LOCK
(&glUDP_Channels);
+
Mutex_Acquire
(&glUDP_Channels);
if(gpUDP_Channels == chan)
gpUDP_Channels = gpUDP_Channels->Next;
else
if(gpUDP_Channels == chan)
gpUDP_Channels = gpUDP_Channels->Next;
else
@@
-525,10
+538,10
@@
void UDP_Channel_Close(tVFS_Node *Node)
else
prev->Next = prev->Next->Next;
}
else
prev->Next = prev->Next->Next;
}
-
RELEASE
(&glUDP_Channels);
+
Mutex_Release
(&glUDP_Channels);
// Clear Queue
// Clear Queue
- LOCK(&chan->lQueue);
+
SHORT
LOCK(&chan->lQueue);
while(chan->Queue)
{
tUDPPacket *tmp;
while(chan->Queue)
{
tUDPPacket *tmp;
@@
-536,7
+549,7
@@
void UDP_Channel_Close(tVFS_Node *Node)
chan->Queue = tmp->Next;
free(tmp);
}
chan->Queue = tmp->Next;
free(tmp);
}
-
RELEASE
(&chan->lQueue);
+
SHORTREL
(&chan->lQueue);
// Free channel structure
free(chan);
// Free channel structure
free(chan);
@@
-548,7
+561,7
@@
void UDP_Channel_Close(tVFS_Node *Node)
Uint16 UDP_int_AllocatePort()
{
int i;
Uint16 UDP_int_AllocatePort()
{
int i;
-
LOCK
(&glUDP_Ports);
+
Mutex_Acquire
(&glUDP_Ports);
// Fast Search
for( i = UDP_ALLOC_BASE; i < 0x10000; i += 32 )
if( gUDP_Ports[i/32] != 0xFFFFFFFF )
// Fast Search
for( i = UDP_ALLOC_BASE; i < 0x10000; i += 32 )
if( gUDP_Ports[i/32] != 0xFFFFFFFF )
@@
-559,7
+572,7
@@
Uint16 UDP_int_AllocatePort()
if( !(gUDP_Ports[i/32] & (1 << (i%32))) )
return i;
}
if( !(gUDP_Ports[i/32] & (1 << (i%32))) )
return i;
}
-
RELEASE
(&glUDP_Ports);
+
Mutex_Release
(&glUDP_Ports);
}
/**
}
/**
@@
-568,13
+581,13
@@
Uint16 UDP_int_AllocatePort()
*/
int UDP_int_MarkPortAsUsed(Uint16 Port)
{
*/
int UDP_int_MarkPortAsUsed(Uint16 Port)
{
-
LOCK
(&glUDP_Ports);
+
Mutex_Acquire
(&glUDP_Ports);
if( gUDP_Ports[Port/32] & (1 << (Port%32)) ) {
return 0;
if( gUDP_Ports[Port/32] & (1 << (Port%32)) ) {
return 0;
-
RELEASE
(&glUDP_Ports);
+
Mutex_Release
(&glUDP_Ports);
}
gUDP_Ports[Port/32] |= 1 << (Port%32);
}
gUDP_Ports[Port/32] |= 1 << (Port%32);
-
RELEASE
(&glUDP_Ports);
+
Mutex_Release
(&glUDP_Ports);
return 1;
}
return 1;
}
@@
-583,7
+596,7
@@
int UDP_int_MarkPortAsUsed(Uint16 Port)
*/
void UDP_int_FreePort(Uint16 Port)
{
*/
void UDP_int_FreePort(Uint16 Port)
{
-
LOCK
(&glUDP_Ports);
+
Mutex_Acquire
(&glUDP_Ports);
gUDP_Ports[Port/32] &= ~(1 << (Port%32));
gUDP_Ports[Port/32] &= ~(1 << (Port%32));
-
RELEASE
(&glUDP_Ports);
+
Mutex_Release
(&glUDP_Ports);
}
}
UCC
git Repository :: git.ucc.asn.au