99 lines
2.6 KiB
C++
99 lines
2.6 KiB
C++
#ifndef COPPINO_IPV6_H
|
|
#define COPPINO_IPV6_H
|
|
|
|
namespace ipv6 {
|
|
/* maximum length for an IPv6 packet */
|
|
const uint8_t LEN = 128;
|
|
|
|
/* ICMP Types */
|
|
const uint8_t ICMP_ECHO_REQUEST_TYPE = 128;
|
|
const uint8_t ICMP_ECHO_REPLY_TYPE = 129;
|
|
const uint8_t ICMP_RADV_TYPE = 134;
|
|
|
|
/* Next-Header Types */
|
|
const uint8_t NH_ICMP = 58;
|
|
const uint8_t NH_UDP = 17;
|
|
|
|
class IPv6Addr {
|
|
private:
|
|
char address[16];
|
|
public:
|
|
IPv6Addr();
|
|
IPv6Addr(const char* address);
|
|
};
|
|
|
|
extern const IPv6Addr ALL_NODES_ADDRESS;
|
|
|
|
class IPv6Packet {
|
|
private:
|
|
char packet[LEN];
|
|
public:
|
|
IPv6Packet();
|
|
IPv6Packet(const char* buffer, int len);
|
|
void setLen(int len);
|
|
int getLen();
|
|
void setSrcAddress(const IPv6Addr* address);
|
|
const IPv6Addr* getSrcAddress();
|
|
void setDstAddress(const IPv6Addr* address);
|
|
const IPv6Addr* getDstAddress();
|
|
void setNextHeader(uint8_t next_header);
|
|
void setFlow(const char* flow);
|
|
void setPayload(char* payload, int len);
|
|
void send();
|
|
|
|
void doAction();
|
|
};
|
|
|
|
/* incoming and outgoing packets buffer */
|
|
extern IPv6Packet packetin;
|
|
extern IPv6Packet packetout;
|
|
|
|
/* Note: content of message may be changed */
|
|
int handleICMP(char* output_buffer, const char* input_buffer, int len);
|
|
|
|
/* Compute internet checksum. Actually it is not so straightforward: */
|
|
uint16_t compute_checksum(
|
|
const IPv6Addr* src_addr, /* source IPv6 address */
|
|
const IPv6Addr* dst_addr, /* destination IPv6 address */
|
|
uint8_t next_header, /* IPv6 next header number */
|
|
int upper_len, /* length as found in the upper layer protocol */
|
|
const char* payload, /* IPv6 payload */
|
|
int len /* IPv6 payload length */
|
|
);
|
|
|
|
/* RFC 4861 -- begin */
|
|
struct ICMPv6_RADV {
|
|
uint8_t type;
|
|
uint8_t code;
|
|
char checksum[2];
|
|
uint8_t cur_hop_limit;
|
|
uint8_t mo_flags;
|
|
uint16_t router_lifetime;
|
|
uint32_t reachable_time;
|
|
uint32_t retrans_time;
|
|
};
|
|
|
|
struct ICMPv6_RADV_Option {
|
|
uint8_t type;
|
|
uint8_t len;
|
|
};
|
|
|
|
struct ICMPv6_RADV_PrefixInformation {
|
|
uint8_t type;
|
|
uint8_t len;
|
|
uint8_t prefix_length;
|
|
uint8_t la_flags;
|
|
uint32_t valid_lifetime;
|
|
uint32_t preferred_lifetime;
|
|
uint32_t reserved2;
|
|
char prefix[16];
|
|
};
|
|
/* RFC 4861 -- end */
|
|
|
|
void setEUI(const char* eui); /* 64bit Extended Unique Identifier */
|
|
void SLAAC(bool enable); /* enable IPv6 automatic prefix configuration (listens for RADV) */
|
|
void setGlobalAddress(const char* address); /* global IPv6 address, manually configured */
|
|
}
|
|
|
|
#endif
|