mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
mtu icmpv6 option implemented
This commit is contained in:
parent
1206f6fd5e
commit
1b3e758505
@ -45,6 +45,7 @@
|
||||
#define RADIO_CONF radio_cc1100
|
||||
#define RADIO RADIO_CONF
|
||||
|
||||
#define MUTLIHOP_HOPLIMIT 64
|
||||
|
||||
extern uint8_t ipv6_ext_hdr_len;
|
||||
|
||||
@ -52,8 +53,8 @@ extern uint8_t ipv6_ext_hdr_len;
|
||||
#define LLHDR_ICMPV6HDR_LENGTH (LL_HEADER_LENGTH + IPV6_HEADER_LENGTH + ipv6_ext_hdr_len + ICMP_HEADER_LENGTH)
|
||||
#define IPV6HDR_ICMPV6HDR_LENGTH (IPV6_HEADER_LENGTH + ipv6_ext_hdr_len + ICMP_HEADER_LENGTH)
|
||||
/* global buffer*/
|
||||
|
||||
uint8_t buffer[BUFFER_SIZE];
|
||||
/* packet length*/
|
||||
extern uint16_t packet_length;
|
||||
|
||||
/* ipv6 extension header length */
|
||||
@ -85,6 +86,10 @@ typedef struct link_layer_addr{
|
||||
} link_layer_addr;
|
||||
|
||||
#define HTONS(a) (uint16_t)((((uint16_t) (a)) << 8) | (((uint16_t) (a)) >> 8))
|
||||
#define HTONL(a) ((((uint32_t) (a) & 0xff000000) >> 24) | \
|
||||
(((uint32_t) (a) & 0x00ff0000) >> 8) | \
|
||||
(((uint32_t) (a) & 0x0000ff00) << 8) | \
|
||||
(((uint32_t) (a) & 0x000000ff) << 24))
|
||||
|
||||
void create_link_local_prefix(ipv6_addr *ipaddr);
|
||||
|
||||
|
@ -12,18 +12,23 @@ uint16_t packet_length;
|
||||
|
||||
#define IP_BUFFER ((struct ipv6_hdr*)&buffer[LL_HEADER_LENGTH])
|
||||
#define ICMP_BUFFER ((struct icmpv6_hdr*)&buffer[LLHDR_IPV6HDR_LENGTH])
|
||||
/* fields after icmp header*/
|
||||
#define RA_BUFFER ((struct router_advertisement*)&buffer[LLHDR_ICMPV6HDR_LENGTH])
|
||||
#define IPH_LLH_BUFFER &buffer[LL_HEADER_LENGTH + IPV6_HEADER_LENGTH]
|
||||
#define OPT_FIELD_BUFFER ((struct option_hdr*)&buffer[LLHDR_IPV6HDR_LENGTH + option_field_length])
|
||||
#define OPT_ST_FIELD_BUFFER ((struct option_src_trgt_lla*)&buffer[LLHDR_IPV6HDR_LENGTH + option_field_length])
|
||||
#define OPT_MTU_BUFFER ((struct option_mtu*)&buffer[LLHDR_IPV6HDR_LENGTH + option_field_length])
|
||||
|
||||
uint8_t rs_count;
|
||||
|
||||
option_prefix_info *prefix; /** prefix list pointer */
|
||||
|
||||
/* send router solicitation message - RFC4861 section 4.1 */
|
||||
void send_rs(void){
|
||||
//uint8_t ipv6_ext_hdr_len = 0;
|
||||
if(rs_count < MAX_RTR_SOLICITATIONS){
|
||||
if(rs_count < MAX_RTR_SOL){
|
||||
packet_length = 0;
|
||||
|
||||
ICMP_BUFFER->type = ICMP_ROUTER_SOLICITATION;
|
||||
ICMP_BUFFER->type = ICMP_RTR_SOL;
|
||||
ICMP_BUFFER->code = 0;
|
||||
|
||||
IP_BUFFER->version_trafficclass = IPV6_VERSION;
|
||||
@ -35,24 +40,24 @@ void send_rs(void){
|
||||
create_all_routers_mcast_addr(&IP_BUFFER->destaddr);
|
||||
PRINT6ADDR(&IP_BUFFER->destaddr);
|
||||
/* set payload length */
|
||||
IP_BUFFER->length = ICMP_HEADER_LENGTH + RS_LENGTH + SLLAO_OPT_LENGTH;
|
||||
set_llao(&buffer[LLHDR_ICMPV6HDR_LENGTH + RS_LENGTH], SLLAO_OPT_LENGTH);
|
||||
IP_BUFFER->length = ICMP_HEADER_LENGTH + RTR_SOL_LENGTH + SLLAO_OPT_LENGTH;
|
||||
set_llao(&buffer[LLHDR_ICMPV6HDR_LENGTH + RTR_SOL_LENGTH], SLLAO_OPT_LENGTH);
|
||||
ICMP_BUFFER->checksum = 0;
|
||||
ICMP_BUFFER->checksum = ~chksum_calc(ICMP_NEXTHEADER);
|
||||
printf("%x\n",ICMP_BUFFER->checksum);
|
||||
|
||||
rs_count++;
|
||||
// sleep 4 sec
|
||||
swtimer_usleep(ROUTER_SOLICITATION_INTERVAL * 1000000);
|
||||
swtimer_usleep(RTR_SOL_INTERVAL * 1000000);
|
||||
}
|
||||
}
|
||||
|
||||
void recv_rs(void){
|
||||
option_field_length = RS_LENGTH;
|
||||
option_field_length = RTR_SOL_LENGTH;
|
||||
uint8_t *llao;
|
||||
/* get link layer address option from buf */
|
||||
if(OPT_FIELD_BUFFER->type == SLLAO_OPT_LENGTH){
|
||||
llao = OPT_FIELD_BUFFER;
|
||||
if(OPT_ST_FIELD_BUFFER->type == SLLAO_OPT_LENGTH){
|
||||
llao = OPT_ST_FIELD_BUFFER;
|
||||
}
|
||||
|
||||
if(llao != NULL){
|
||||
@ -68,8 +73,44 @@ void send_ra(ipv6_addr *addr){
|
||||
IP_BUFFER->flowlabel = 0;
|
||||
IP_BUFFER->nextheader = ICMP_NEXTHEADER;
|
||||
IP_BUFFER->hoplimit = NEIGHBOR_DISCOVERY_HOPLIMIT;
|
||||
|
||||
// not solicited
|
||||
create_all_nodes_mcast_addr(&IP_BUFFER->destaddr);
|
||||
|
||||
ICMP_BUFFER->type = ICMP_RTR_ADV;
|
||||
ICMP_BUFFER->code = 0;
|
||||
|
||||
// set current ttl
|
||||
RA_BUFFER->hoplimit = MULTIHOP_HOPLIMIT;
|
||||
// set M and O flag, last 6 bits are zero
|
||||
RA_BUFFER->autoconfig_flags = (ND_M_FLAG << 7) | (ND_O_FLAG << 6);
|
||||
RA_BUFFER->router_lifetime = MAX_RTR_ADV_INTERVAL * MAX_RTR_ADV;
|
||||
RA_BUFFER->reachable_time = 0;
|
||||
RA_BUFFER->retrans_timer = 0;
|
||||
|
||||
set_llao((uint8_t *)OPT_ST_FIELD_BUFFER,SLLAO_OPT_LENGTH);
|
||||
|
||||
/* set MTU options */
|
||||
OPT_MTU_BUFFER->type = MTU_OPTION_TYPE;
|
||||
OPT_MTU_BUFFER->length = MTU_OPTION_LENGTH;
|
||||
OPT_MTU_BUFFER->reserved = 0;
|
||||
// 1500 octets mtu
|
||||
OPT_MTU_BUFFER->mtu = HTONL(1500);
|
||||
|
||||
/* set packet length */
|
||||
packet_length = IPV6_HEADER_LENGTH + ICMP_HEADER_LENGTH +
|
||||
RTR_ADV_LENGTH + SLLAO_OPT_LEN + MTU_OPTION_HDR_LENGTH;
|
||||
/* set payload length field */
|
||||
|
||||
/* set prefix option */
|
||||
for(){
|
||||
|
||||
}
|
||||
|
||||
IP_BUFFER->length = packet_length - IPV6_HEADER_LENGTH;
|
||||
|
||||
/* calculate checksum */
|
||||
ICMP_BUFFER->checksum = 0;
|
||||
ICMP_BUFFER->checksum = ~chksum_calc(ICMP_NEXTHEADER);
|
||||
}
|
||||
|
||||
/* link-layer address option - RFC4861 section 4.6.1/ RFC4944 8. */
|
||||
|
@ -1,19 +1,55 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#define RS_LENGTH 4
|
||||
#define SLLAO_OPT_LENGTH 16 // 16 if 802.15.4 otherwise 8
|
||||
#define ND_OPT_TYPE 0
|
||||
#define ND_OPT_LENGTH 1
|
||||
#define ND_OPT_DATA 2
|
||||
#define ICMP_ROUTER_SOLICITATION 133
|
||||
#define ROUTER_SOLICITATION_INTERVAL 4
|
||||
#define MAX_RTR_SOLICITATIONS 3
|
||||
/* router advertisment */
|
||||
#define ND_M_FLAG 0
|
||||
#define ND_O_FLAG 0
|
||||
#define MAX_RTR_ADV 3
|
||||
#define MAX_RTR_ADV_INTERVAL 600
|
||||
#define RTR_ADV_LENGTH 12
|
||||
#define ICMP_RTR_ADV 134
|
||||
/* router solicitation */
|
||||
#define ICMP_RTR_ 133
|
||||
#define RTR_SOL_LENGTH 4
|
||||
#define RTR_SOL_INTERVAL 4
|
||||
#define MAX_RTR_SOL 3
|
||||
/* mtu option rfc4861 4.6.4*/
|
||||
#define MTU_OPTION_TYPE 5
|
||||
#define MTU_OPTION_LENGTH 1
|
||||
#define MTU_OPTION_HDR_LENGTH 8
|
||||
|
||||
typedef struct option_hdr {
|
||||
typedef struct option_src_trgt_lla {
|
||||
uint8_t type;
|
||||
uint8_t length;
|
||||
} option_hdr;
|
||||
} option_src_trgt_lla;
|
||||
|
||||
typedef struct option_mtu {
|
||||
uint8_t type;
|
||||
uint8_t length;
|
||||
uint16_t reserved;
|
||||
uint32_t mtu;
|
||||
} option_mtu;
|
||||
|
||||
typedef struct option_prefix_info {
|
||||
uint8_t type;
|
||||
uint8_t length;
|
||||
uint8_t prefix_length;
|
||||
uint8_t reserved1;
|
||||
uint32_t valid_lifetime;
|
||||
uint32_t preferred_lifetime;
|
||||
ipv6_addr prefix;
|
||||
} option_prefix_info;
|
||||
|
||||
struct router_advertisement {
|
||||
uint8_t hoplimit;
|
||||
uint8_t autoconfig_flags;
|
||||
uint16_t router_lifetime;
|
||||
uint32_t reachable_time;
|
||||
uint32_t retrans_timer;
|
||||
};
|
||||
|
||||
void send_rs(void);
|
||||
uint16_t chksum_calc(uint8_t type);
|
||||
|
Loading…
Reference in New Issue
Block a user