]> git.decadent.org.uk Git - odhcp6c.git/blobdiff - src/odhcp6c.h
Fix handling of DHCPv6 messages containing option lengths exceeding the message
[odhcp6c.git] / src / odhcp6c.h
index 61dee63ffcc9a57b5c918cc5d7e106ca289b4f97..87715214622def7044354a6fc46a78c70a35620b 100644 (file)
 
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 
-#ifndef SOL_NETLINK
-#define SOL_NETLINK 270
-#endif
-
 #define ND_OPT_RECURSIVE_DNS 25
 #define ND_OPT_DNSSL 31
 
@@ -38,6 +34,7 @@ enum dhcvp6_opt {
        DHCPV6_OPT_ELAPSED = 8,
        DHCPV6_OPT_RELAY_MSG = 9,
        DHCPV6_OPT_AUTH = 11,
+       DHCPV6_OPT_UNICAST = 12,
        DHCPV6_OPT_STATUS = 13,
        DHCPV6_OPT_RAPID_COMMIT = 14,
        DHCPV6_OPT_RECONF_MESSAGE = 19,
@@ -81,11 +78,17 @@ enum dhcpv6_msg {
 };
 
 enum dhcpv6_status {
+       DHCPV6_Success = 0,
+       DHCPV6_UnspecFail = 1,
        DHCPV6_NoAddrsAvail = 2,
+       DHCPV6_NoBinding = 3,
+       DHCPV6_NotOnLink = 4,
+       DHCPV6_UseMulticast = 5,
        DHCPV6_NoPrefixAvail = 6,
+       _DHCPV6_Status_Max
 };
 
-typedef int(reply_handler)(enum dhcpv6_msg orig,
+typedef int(reply_handler)(enum dhcpv6_msg orig, const int rc,
                const void *opt, const void *end);
 
 // retransmission strategy
@@ -93,12 +96,12 @@ struct dhcpv6_retx {
        bool delay;
        uint8_t init_timeo;
        uint16_t max_timeo;
+       uint8_t max_rc;
        char name[8];
        reply_handler *handler_reply;
        int(*handler_finish)(void);
 };
 
-
 // DHCPv6 Protocol Headers
 struct dhcpv6_header {
        uint8_t msg_type;
@@ -152,7 +155,7 @@ struct dhcpv6_auth_reconfigure {
 #define dhcpv6_for_each_option(start, end, otype, olen, odata)\
        for (uint8_t *_o = (uint8_t*)(start); _o + 4 <= (uint8_t*)(end) &&\
                ((otype) = _o[0] << 8 | _o[1]) && ((odata) = (void*)&_o[4]) &&\
-               ((olen) = _o[2] << 8 | _o[3]) + (odata) <= (uint8_t*)(end); \
+                ((olen) = _o[2] << 8 | _o[3]); \
                _o += 4 + (_o[2] << 8 | _o[3]))
 
 
@@ -162,6 +165,7 @@ struct dhcpv6_server_cand {
        int16_t preference;
        uint8_t duid_len;
        uint8_t duid[130];
+       struct in6_addr server_addr;
        void *ia_na;
        void *ia_pd;
        size_t ia_na_len;
@@ -199,12 +203,11 @@ struct icmp6_opt {
 
 
 enum dhcpv6_mode {
-       DHCPV6_UNKNOWN,
+       DHCPV6_UNKNOWN = -1,
        DHCPV6_STATELESS,
        DHCPV6_STATEFUL
 };
 
-
 enum odhcp6c_ia_mode {
        IA_MODE_NONE,
        IA_MODE_TRY,
@@ -219,6 +222,8 @@ struct odhcp6c_entry {
        struct in6_addr target;
        uint32_t valid;
        uint32_t preferred;
+       uint32_t t1;
+       uint32_t t2;
        uint16_t class;
 };
 
@@ -227,6 +232,7 @@ int init_dhcpv6(const char *ifname, int request_pd, int sol_timeout);
 void dhcpv6_set_ia_mode(enum odhcp6c_ia_mode na, enum odhcp6c_ia_mode pd);
 int dhcpv6_request(enum dhcpv6_msg type);
 int dhcpv6_poll_reconfigure(void);
+int dhcpv6_promote_server_cand(void);
 
 int init_rtnetlink(void);
 int set_rtnetlink_addr(int ifindex, const struct in6_addr *addr,
@@ -240,10 +246,13 @@ void script_delay_call(const char *status, int timeout);
 bool odhcp6c_signal_process(void);
 uint64_t odhcp6c_get_milli_time(void);
 void 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);
+void 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);
 void* odhcp6c_move_state(enum odhcp6c_state state, size_t *len);
 void* odhcp6c_get_state(enum odhcp6c_state state, size_t *len);