script: fix possible negative delay
[project/odhcp6c.git] / src / odhcp6c.h
index 08a816f4446dd893d89db315bf6f8932200ab2b8..e41aa3c56d3a5ae5f23b112746d0f57786e7bdbe 100644 (file)
@@ -1,5 +1,6 @@
 /**
  * Copyright (C) 2012-2014 Steven Barth <steven@midlink.org>
+ * Copyright (C) 2018 Hans Dedecker <dedeckeh@gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License v2 as published by
@@ -18,7 +19,7 @@
 
 #define _unused __attribute__((unused))
 #define _packed __attribute__((packed))
-#define __aligned(n) __attribute__((aligned(n)))
+#define _aligned(n) __attribute__((aligned(n)))
 
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 
@@ -32,7 +33,7 @@
 #define DHCPV6_REB_MAX_RT 600
 #define DHCPV6_INF_MAX_RT 120
 
-#define DEFAULT_MIN_UPDATE_INTERVAL 30
+#define RA_MIN_ADV_INTERVAL 3   /* RFC 4861 paragraph 6.2.1 */
 
 enum dhcvp6_opt {
        DHCPV6_OPT_CLIENTID = 1,
@@ -50,6 +51,7 @@ enum dhcvp6_opt {
        DHCPV6_OPT_RAPID_COMMIT = 14,
        DHCPV6_OPT_USER_CLASS = 15,
        DHCPV6_OPT_VENDOR_CLASS = 16,
+       DHCPV6_OPT_INTERFACE_ID = 18,
        DHCPV6_OPT_RECONF_MESSAGE = 19,
        DHCPV6_OPT_RECONF_ACCEPT = 20,
        DHCPV6_OPT_DNS_SERVERS = 23,
@@ -227,6 +229,7 @@ struct dhcpv6_server_cand {
        int16_t preference;
        uint8_t duid_len;
        uint8_t duid[130];
+       struct in6_addr server_addr;
        uint32_t sol_max_rt;
        uint32_t inf_max_rt;
        void *ia_na;
@@ -258,8 +261,7 @@ enum odhcp6c_state {
        STATE_RA_DNS,
        STATE_RA_SEARCH,
        STATE_AFTR_NAME,
-       STATE_VENDORCLASS,
-       STATE_USERCLASS,
+       STATE_OPTS,
        STATE_CER,
        STATE_S46_MAPT,
        STATE_S46_MAPE,
@@ -282,6 +284,10 @@ enum dhcpv6_mode {
        DHCPV6_STATEFUL
 };
 
+enum ra_config {
+       RA_RDNSS_DEFAULT_LIFETIME = 1,
+};
+
 enum odhcp6c_ia_mode {
        IA_MODE_NONE,
        IA_MODE_TRY,
@@ -316,6 +322,23 @@ struct odhcp6c_request_prefix {
        uint16_t length;
 };
 
+enum odhcp6c_opt_flags {
+       OPT_U8 = 0,
+       OPT_IP6,
+       OPT_DNS_STR,
+       OPT_USER_CLASS,
+       OPT_MASK_SIZE = 0x0F,
+       OPT_ARRAY = 0x10,
+       OPT_INTERNAL = 0x20,
+       OPT_NO_PASSTHRU = 0x40,
+};
+
+struct odhcp6c_opt {
+       uint16_t code;
+       uint8_t flags;
+       const char *str;
+};
+
 int init_dhcpv6(const char *ifname, unsigned int client_options, int sol_timeout);
 int dhcpv6_set_ia_mode(enum odhcp6c_ia_mode na, enum odhcp6c_ia_mode pd);
 int dhcpv6_request(enum dhcpv6_msg type);
@@ -339,10 +362,11 @@ bool odhcp6c_signal_process(void);
 uint64_t odhcp6c_get_milli_time(void);
 int odhcp6c_random(void *buf, size_t len);
 bool odhcp6c_is_bound(void);
+bool odhcp6c_addr_in_scope(const struct in6_addr *addr);
 
 // State manipulation
 void odhcp6c_clear_state(enum odhcp6c_state state);
-void odhcp6c_add_state(enum odhcp6c_state state, const void *data, size_t len);
+int odhcp6c_add_state(enum odhcp6c_state state, const void *data, size_t len);
 void odhcp6c_append_state(enum odhcp6c_state state, const void *data, size_t len);
 int odhcp6c_insert_state(enum odhcp6c_state state, size_t offset, const void *data, size_t len);
 size_t odhcp6c_remove_state(enum odhcp6c_state state, size_t offset, size_t len);
@@ -350,7 +374,9 @@ void* odhcp6c_move_state(enum odhcp6c_state state, size_t *len);
 void* odhcp6c_get_state(enum odhcp6c_state state, size_t *len);
 
 // Entry manipulation
-bool odhcp6c_update_entry(enum odhcp6c_state state, struct odhcp6c_entry *new, uint32_t safe, bool filterexcess);
+bool odhcp6c_update_entry(enum odhcp6c_state state, struct odhcp6c_entry *new,
+                               uint32_t safe, unsigned int holdoff_interval);
 
 void odhcp6c_expire(void);
 uint32_t odhcp6c_elapsed(void);
+struct odhcp6c_opt *odhcp6c_find_opt(const uint16_t code);