| 1 |
#ifndef _PROTO_PKT_RIP |
| 2 |
#define _PROTO_PKT_RIP |
| 3 |
|
| 4 |
#include "protoPkt.h" |
| 5 |
#include "protoAddress.h" |
| 6 |
|
| 7 |
class ProtoPktRIP : public ProtoPkt |
| 8 |
{ |
| 9 |
public: |
| 10 |
ProtoPktRIP(void* bufferPtr = NULL, |
| 11 |
unsigned int numBytes = 0, |
| 12 |
unsigned int pktLength = 0, // inits from buffer if non-zero |
| 13 |
bool freeOnDestruct = false); |
| 14 |
~ProtoPktRIP(); |
| 15 |
|
| 16 |
enum Command |
| 17 |
{ |
| 18 |
INVALID = 0, |
| 19 |
REQUEST = 1, |
| 20 |
RESPONSE = 2 |
| 21 |
}; |
| 22 |
|
| 23 |
enum {VERSION = 2}; |
| 24 |
|
| 25 |
enum AddressFamily |
| 26 |
{ |
| 27 |
NONE = 0, |
| 28 |
IPv4 = 2, // AF_INET |
| 29 |
AUTH = 0xffff // Indicates Authentication entry |
| 30 |
}; |
| 31 |
|
| 32 |
enum AuthType |
| 33 |
{ |
| 34 |
AUTH_NONE = 0, |
| 35 |
AUTH_PASS = 2 |
| 36 |
}; |
| 37 |
|
| 38 |
class RouteEntry : public ProtoPkt |
| 39 |
{ |
| 40 |
public: |
| 41 |
RouteEntry(void* bufferPtr = NULL, |
| 42 |
unsigned int numBytes = 0, |
| 43 |
bool initFromBuffer = false, |
| 44 |
bool freeOnDestruct = false); |
| 45 |
~RouteEntry(); |
| 46 |
|
| 47 |
// Use these to build a route entry |
| 48 |
// (call them in order) |
| 49 |
bool InitIntoBuffer(void* bufferPtr = NULL, |
| 50 |
unsigned int numBytes = 0, |
| 51 |
bool freeOnDestruct = false); |
| 52 |
void SetAddressFamily(AddressFamily family) |
| 53 |
{SetUINT16((unsigned int)(2*OFFSET_FAMILY), (UINT16)family);} |
| 54 |
void SetRouteTag(UINT16 tag) |
| 55 |
{SetUINT16(2*OFFSET_TAG, tag);} |
| 56 |
bool SetAddress(const ProtoAddress& addr); |
| 57 |
bool SetMask(const ProtoAddress& addr); |
| 58 |
bool SetMaskLength(UINT8 maskLen); |
| 59 |
bool SetNextHop(const ProtoAddress& addr); |
| 60 |
void SetMetric(UINT32 metric) |
| 61 |
{SetUINT32(4*OFFSET_METRIC, metric);} |
| 62 |
|
| 63 |
// Use these to parse a route entry |
| 64 |
bool InitFromBuffer(unsigned int pktLength = 0, |
| 65 |
void* bufferPtr = NULL, |
| 66 |
unsigned int numBytes = 0, |
| 67 |
bool freeOnDestruct = false); |
| 68 |
AddressFamily GetAddressFamily() const |
| 69 |
{return (AddressFamily)(GetUINT16((unsigned int)(2*OFFSET_FAMILY)));} |
| 70 |
UINT16 GetRouteTag() const |
| 71 |
{return GetUINT16(2*OFFSET_TAG);} |
| 72 |
bool GetAddress(ProtoAddress& addr) const; |
| 73 |
bool GetMask(ProtoAddress& addr) const; |
| 74 |
UINT8 GetMaskLength() const; |
| 75 |
bool GetNextHop(ProtoAddress& addr) const; |
| 76 |
UINT32 GetMetric() const |
| 77 |
{return GetUINT32(4*OFFSET_METRIC);} |
| 78 |
|
| 79 |
private: |
| 80 |
enum |
| 81 |
{ |
| 82 |
OFFSET_FAMILY = 0, // UINT16 offset |
| 83 |
OFFSET_TAG = OFFSET_FAMILY + 1, // UINT16 offset |
| 84 |
OFFSET_ADDR = (OFFSET_TAG+1)/2, // UINT32 offset |
| 85 |
OFFSET_MASK = OFFSET_ADDR + 1, // UINT32 offset |
| 86 |
OFFSET_NHOP = OFFSET_MASK + 1, // UINT32 offset |
| 87 |
OFFSET_METRIC = OFFSET_NHOP + 1 // UINT32 offset |
| 88 |
}; |
| 89 |
}; // end class ProtoPktRIP::RouteEntry |
| 90 |
|
| 91 |
bool InitIntoBuffer(void* bufferPtr = NULL, |
| 92 |
unsigned int numBytes = 0, |
| 93 |
bool freeOnDestruct = false); |
| 94 |
void SetCommand(Command cmd) |
| 95 |
{SetUINT8(OFFSET_COMMAND, (UINT8)cmd);} |
| 96 |
void SetVersion(UINT8 version) |
| 97 |
{SetUINT8(OFFSET_VERSION, version);} |
| 98 |
|
| 99 |
bool AddRouteEntry(const ProtoAddress& destAddr, |
| 100 |
UINT32 maskLen, |
| 101 |
const ProtoAddress& nextHop, |
| 102 |
UINT32 metric = 1, |
| 103 |
UINT16 routeTag = 0); |
| 104 |
|
| 105 |
bool InitFromBuffer(unsigned int pktLength = 0, |
| 106 |
void* bufferPtr = NULL, |
| 107 |
unsigned int numBytes = 0, |
| 108 |
bool freeOnDestruct = false); |
| 109 |
Command GetCommand() const |
| 110 |
{return (Command)(GetUINT8(OFFSET_COMMAND));} |
| 111 |
UINT8 GetVersion() const |
| 112 |
{return GetUINT8(OFFSET_VERSION);} |
| 113 |
|
| 114 |
unsigned int GetNumEntry() const; |
| 115 |
// Note this does _not_ copy data, but wraps "entry" around |
| 116 |
// the appropriate internal ProtoPktRIP buffer area |
| 117 |
bool AccessRouteEntry(unsigned int index, RouteEntry& entry); |
| 118 |
|
| 119 |
|
| 120 |
private: |
| 121 |
enum |
| 122 |
{ |
| 123 |
OFFSET_COMMAND = 0, // UINT8 offset |
| 124 |
OFFSET_VERSION = OFFSET_COMMAND+1, // UINT8 offset |
| 125 |
OFFSET_RESERVED = (OFFSET_VERSION+1)/2, // UINT16 offset |
| 126 |
OFFSET_PAYLOAD = (OFFSET_RESERVED+1)/2 // UINT32 offset |
| 127 |
}; |
| 128 |
|
| 129 |
}; // end class ProtoPktRIP |
| 130 |
|
| 131 |
|
| 132 |
#endif // _PROTO_PKT_RIP |