Restructured interface code out to its own file, route search implemented
[tpg/acess2.git] / Modules / IPStack / ipstack.h
1 /*
2  * Acess2 IP Stack
3  * - Common Header
4  */
5 #ifndef _IPSTACK_H_
6 #define _IPSTACK_H_
7
8 #include <acess.h>
9 #include <vfs.h>
10
11 typedef union uIPv4     tIPv4;
12 typedef union uIPv6     tIPv6;
13 typedef struct sMacAddr tMacAddr;
14 typedef struct sAdapter tAdapter;
15 typedef struct sInterface       tInterface;
16 typedef struct sSocketFile      tSocketFile;
17
18 typedef void    (*tIPCallback)(tInterface *Interface, void *Address, int Length, void *Buffer);
19
20 enum eInterfaceTypes {
21         AF_NULL,
22         AF_INET4 = 4,   // tIPv4
23         AF_INET6 = 6    // tIPv6
24 };
25
26 union uIPv4 {
27         Uint32  L;
28         Uint8   B[4];
29 } __attribute__((packed));
30
31 union uIPv6 {
32         Uint16  W[8];
33         Uint32  L[4];
34         Uint8   B[16];
35 } __attribute__((packed));
36
37 struct sMacAddr {
38         Uint8   B[6];
39 } __attribute__((packed));
40
41 struct sInterface {
42         struct sInterface       *Next;
43         tVFS_Node       Node;
44         tAdapter        *Adapter;
45          int    TimeoutDelay;   // Time in miliseconds before a packet times out
46          int    Type;   // 0 for disabled, 4 for IPv4 and 6 for IPv6
47         
48         //TODO: Remove explicit mentions of IPv4/IPv6 and make more general
49         union {
50                 struct  {
51                         tIPv6   Address;
52                          int    SubnetBits;     //Should this be outside the union?
53                 }       IP6;
54                 
55                 struct {
56                         tIPv4   Address;
57                         tIPv4   Gateway;
58                          int    SubnetBits;
59                 }       IP4;
60         };
61 };
62
63 /**
64  * \brief Represents a network adapter
65  */
66 struct sAdapter {
67         struct sAdapter *Next;
68         
69          int    DeviceFD;
70          int    NRef;
71         
72         tMacAddr        MacAddr;
73          int    DeviceLen;
74         char    Device[];
75 };
76
77 /**
78  * \brief Describes a socket file definition
79  */
80 struct sSocketFile
81 {
82         struct sSocketFile      *Next;
83         const char      *Name;
84         
85         tVFS_Node       *(*Init)(tInterface *Interface);
86 };
87
88 static const tMacAddr cMAC_BROADCAST = {{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}};
89
90 #define MAC_SET(t,v)    memcpy(&(t),&(v),sizeof(tMacAddr))
91 #define IP4_SET(t,v)    (t).L = (v).L;
92 #define IP6_SET(t,v)    memcpy(&(t),&(v),sizeof(tIPv6))
93
94 #define MAC_EQU(a,b)    (memcmp(&(a),&(b),sizeof(tMacAddr))==0)
95 #define IP4_EQU(a,b)    ((a).L==(b).L)
96 #define IP6_EQU(a,b)    (memcmp(&(a),&(b),sizeof(tIPv6))==0)
97
98 // === FUNCTIONS ===
99 #define htonb(v)        (v)
100 #define htons(v)        BigEndian16(v)
101 #define htonl(v)        BigEndian32(v)
102 #define ntonb(v)        (v)
103 #define ntohs(v)        BigEndian16(v)
104 #define ntohl(v)        BigEndian32(v)
105
106 extern int      IPStack_AddFile(tSocketFile *File);
107 extern int      IPStack_GetAddressSize(int AddressType);
108 extern int      IPStack_CompareAddress(int AddressType, void *Address1, void *Address2, int CheckBits);
109
110 #endif

UCC git Repository :: git.ucc.asn.au