Modules/IPStack - Abstract HW addr cache, IPv6 TX (no ND yet)
[tpg/acess2.git] / KernelLand / 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 /**
42  * \brief Route definition structure
43  */
44 typedef struct sRoute {
45         struct sRoute   *Next;
46         
47         tVFS_Node       Node;   //!< Node for route manipulation
48         
49         tInterface      *Interface;     //!< Interface for this route
50          int    AddressType;    //!< 0: Invalid, 4: IPv4, 6: IPv4
51         void    *Network;       //!< Network - Pointer to tIPv4/tIPv6/... at end of structure
52          int    SubnetBits;     //!< Number of bits in \a Network that are valid
53         void    *NextHop;       //!< Next Hop address - Pointer to tIPv4/tIPv6/... at end of structure
54          int    Metric; //!< Route priority
55 }       tRoute;
56
57 struct sInterface {
58         struct sInterface       *Next;  //!< Next interface in list
59         
60         tVFS_Node       Node;   //!< Node to use the interface
61         
62         tAdapter        *Adapter;       //!< Adapter the interface is associated with
63          int    TimeoutDelay;   //!< Time in miliseconds before a packet times out
64          int    Type;   //!< Interface type, see ::eInterfaceTypes
65         
66         void    *Address;       //!< IP address (stored after the Name)
67          int    SubnetBits;     //!< Number of bits that denote the address network
68         
69         tRoute  Route;  //!< Interface route
70         
71         char    Name[];
72 };
73
74 #if 0
75 /**
76  * \brief Represents a network adapter
77  */
78 struct sAdapter {
79         struct sAdapter *Next;
80         
81          int    DeviceFD;       //!< File descriptor of the device
82          int    NRef;   //!< Number of times it's been referenced
83         
84         tMacAddr        MacAddr;        //!< Physical address of the adapter
85          int    DeviceLen;      //!< Device name length
86         char    Device[];       //!< Device name
87 };
88 #endif
89
90 /**
91  * \brief Describes a socket file definition
92  */
93 struct sSocketFile
94 {
95         struct sSocketFile      *Next;
96         const char      *Name;
97         
98         tVFS_Node       *(*Init)(tInterface *Interface);
99 };
100
101 static const tMacAddr cMAC_BROADCAST = {{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}};
102 static const tMacAddr cMAC_ZERO = {{0x00,0x00,0x00,0x00,0x00,0x00}};
103
104 #define MAC_SET(t,v)    memcpy(&(t),&(v),sizeof(tMacAddr))
105 #define IP4_SET(t,v)    (t).L = (v).L;
106 #define IP6_SET(t,v)    memcpy(&(t),&(v),sizeof(tIPv6))
107
108 #define MAC_EQU(a,b)    (memcmp(&(a),&(b),sizeof(tMacAddr))==0)
109 #define IP4_EQU(a,b)    ((a).L==(b).L)
110 #define IP6_EQU(a,b)    (memcmp(&(a),&(b),sizeof(tIPv6))==0)
111
112 // === FUNCTIONS ===
113 #define htonb(v)        (v)
114 #define htons(v)        BigEndian16(v)
115 #define htonl(v)        BigEndian32(v)
116 #define ntonb(v)        (v)
117 #define ntohs(v)        BigEndian16(v)
118 #define ntohl(v)        BigEndian32(v)
119
120 extern int      IPStack_AddFile(tSocketFile *File);
121 extern int      IPStack_GetAddressSize(int AddressType);
122 extern int      IPStack_CompareAddress(int AddressType, const void *Address1, const void *Address2, int CheckBits);
123 extern bool     IPStack_AddressIsBroadcast(int AddrType, const void *Addr, int SubnetBits);
124 extern const char       *IPStack_PrintAddress(int AddressType, const void *Address);
125
126 extern tRoute   *IPStack_FindRoute(int AddressType, tInterface *Interface, const void *Address);
127
128 #endif

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