ipv6: constexpr compile-time SLAAC settings

This commit is contained in:
giomba 2021-12-26 14:37:29 +01:00
parent 3d206c0d23
commit 42e70e9c20
4 changed files with 12 additions and 9 deletions

View File

@ -14,6 +14,8 @@ int udp_server(char* output_buffer, const char* input_buffer, int len) {
void setup() {
pinMode(13, OUTPUT);
/* Customize coppino library configuration settings by editing settings.h */
/* setup serial for Internet connectivity
* attach a SLIP daemon on the other endpoint; a good one is `tunslip6` by Contiki
* $ tunslip6 -s /dev/ttyUSB0 -L -v5 -B 19200 2001:db8:1324::1/64
@ -26,8 +28,6 @@ void setup() {
* Note: pay attention to enter exactly 64 bits / 8 bytes
*/
ipv6::setEUI("\xde\xad\xbe\xef\x12\x34\x56\x78");
/* enable or disable IPv6 Stateless Auto-Configuration (SLAAC) */
ipv6::SLAAC(false);
/* set global address -- will be overwritten if SLAAC is enabled and a Router Advertisement is received */
ipv6::setGlobalAddress("\x20\x01\x04\x70\xc8\x44\x00\x31\x00\x00\x00\x00\x00\x00\xca\xfe");

View File

@ -10,7 +10,6 @@ namespace ipv6
uint8_t HOP_LIMIT = 64;
IPv6Addr LINK_LOCAL_ADDRESS;
IPv6Addr GLOBAL_ADDRESS;
bool slaac_enable;
/******** buffers ********/
IPv6Packet packetin;
@ -23,10 +22,6 @@ namespace ipv6
memcpy(&LINK_LOCAL_ADDRESS, "\xfe\x80", 2);
memcpy(((char *)&LINK_LOCAL_ADDRESS) + 8, eui, 8);
}
void SLAAC(bool enable)
{
slaac_enable = enable;
}
void setGlobalAddress(const char *address)
{
memcpy(&GLOBAL_ADDRESS, address, 16);
@ -242,7 +237,7 @@ namespace ipv6
memcpy(output_buffer + 2, &checksum, 2);
return len;
}
else if (type == ICMP_RADV_TYPE && slaac_enable)
else if (type == ICMP_RADV_TYPE && ENABLE_SLAAC)
{ /* if it is IVMPc6 Router Advertisement, then... */
ICMPv6_RADV *radv = (ICMPv6_RADV *)input_buffer;
HOP_LIMIT = (radv->cur_hop_limit != 0) ? radv->cur_hop_limit : 64;

View File

@ -1,6 +1,7 @@
#ifndef COPPINO_IPV6_H
#define COPPINO_IPV6_H
#include "settings.h"
#include "Arduino.h"
#include "slip.h"
@ -102,7 +103,6 @@ namespace ipv6
/* 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 */
}

8
src/settings.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef __COPPINO_SETTINGS_
#define __COPPINO_SETTINGS_
/* coppino configuration settings */
// Enable IPv6 automatic prefix configuration (listens for RADV)
constexpr bool ENABLE_SLAAC = false;
#endif