odhcp6c: add option to ignore Server Unicast option
[project/odhcp6c.git] / src / odhcp6c.h
index 928f82f32e1004502ecaf2b61e8439af9e9716d5..ad4f7937b3fd2c462d4556052f74a3b2de0e628d 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,6 +19,7 @@
 
 #define _unused __attribute__((unused))
 #define _packed __attribute__((packed))
+#define _aligned(n) __attribute__((aligned(n)))
 
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 
@@ -31,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,
@@ -49,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,
@@ -116,6 +119,7 @@ enum dhcpv6_config {
        DHCPV6_STRICT_OPTIONS = 1,
        DHCPV6_CLIENT_FQDN = 2,
        DHCPV6_ACCEPT_RECONFIGURE = 4,
+       DHCPV6_IGNORE_OPT_UNICAST = 8,
 };
 
 typedef int(reply_handler)(enum dhcpv6_msg orig, const int rc,
@@ -226,6 +230,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;
@@ -257,8 +262,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,
@@ -281,6 +285,10 @@ enum dhcpv6_mode {
        DHCPV6_STATEFUL
 };
 
+enum ra_config {
+       RA_RDNSS_DEFAULT_LIFETIME = 1,
+};
+
 enum odhcp6c_ia_mode {
        IA_MODE_NONE,
        IA_MODE_TRY,
@@ -302,11 +310,37 @@ struct odhcp6c_entry {
        uint8_t auxtarget[];
 };
 
+// Include padding after auxtarget to align the next entry
+#define odhcp6c_entry_size(entry) \
+       (sizeof(struct odhcp6c_entry) + (((entry)->auxlen + 3) & ~3))
+
+#define odhcp6c_next_entry(entry) \
+       ((struct odhcp6c_entry *)((uint8_t *)(entry) + odhcp6c_entry_size(entry)))
+
+
 struct odhcp6c_request_prefix {
        uint32_t iaid;
        uint16_t length;
 };
 
+enum odhcp6c_opt_flags {
+       OPT_U8 = 0,
+       OPT_IP6,
+       OPT_STR,
+       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);
@@ -317,10 +351,10 @@ int init_rtnetlink(void);
 int set_rtnetlink_addr(int ifindex, const struct in6_addr *addr,
                uint32_t pref, uint32_t valid);
 
-int ra_conf_hoplimit(int newvalue);
-int ra_conf_mtu(int newvalue);
-int ra_conf_reachable(int newvalue);
-int ra_conf_retransmit(int newvalue);
+int ra_get_hoplimit(void);
+int ra_get_mtu(void);
+int ra_get_reachable(void);
+int ra_get_retransmit(void);
 
 int script_init(const char *path, const char *ifname);
 ssize_t script_unhexlify(uint8_t *dst, size_t len, const char *src);
@@ -330,10 +364,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);
@@ -341,7 +376,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);