dhcpv6-ia: rework reconfigure accept logic
[project/odhcpd.git] / src / dhcpv6.h
index 9b38283..de815cf 100644 (file)
@@ -13,6 +13,9 @@
  */
 #pragma once
 
  */
 #pragma once
 
+#include <libubox/ustream.h>
+#include "odhcpd.h"
+
 #define ALL_DHCPV6_RELAYS {{{0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
                0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02}}}
 
 #define ALL_DHCPV6_RELAYS {{{0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
                0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02}}}
 
 #define DHCPV6_OPT_IA_PREFIX 26
 #define DHCPV6_OPT_INFO_REFRESH 32
 #define DHCPV6_OPT_FQDN 39
 #define DHCPV6_OPT_IA_PREFIX 26
 #define DHCPV6_OPT_INFO_REFRESH 32
 #define DHCPV6_OPT_FQDN 39
-
-#ifdef EXT_PREFIX_CLASS
-/* draft-bhandari-dhc-class-based-prefix, not yet standardized */
-#define DHCPV6_OPT_PREFIX_CLASS EXT_PREFIX_CLASS
-#endif
+#define DHCPV6_OPT_SOL_MAX_RT 82
+#define DHCPV6_OPT_INF_MAX_RT 83
 
 #define DHCPV6_DUID_VENDOR 2
 
 
 #define DHCPV6_DUID_VENDOR 2
 
@@ -66,6 +66,7 @@
 #define DHCPV6_STATUS_NOADDRSAVAIL 2
 #define DHCPV6_STATUS_NOBINDING 3
 #define DHCPV6_STATUS_NOTONLINK 4
 #define DHCPV6_STATUS_NOADDRSAVAIL 2
 #define DHCPV6_STATUS_NOBINDING 3
 #define DHCPV6_STATUS_NOTONLINK 4
+#define DHCPV6_STATUS_USEMULTICAST 5
 #define DHCPV6_STATUS_NOPREFIXAVAIL 6
 
 // I just remembered I have an old one lying around...
 #define DHCPV6_STATUS_NOPREFIXAVAIL 6
 
 // I just remembered I have an old one lying around...
@@ -75,6 +76,9 @@
 
 #define DHCPV6_HOP_COUNT_LIMIT 32
 
 
 #define DHCPV6_HOP_COUNT_LIMIT 32
 
+#define DHCPV6_REC_TIMEOUT     2000 /* msec */
+#define DHCPV6_REC_MAX_RC      8
+
 struct dhcpv6_client_header {
        uint8_t msg_type;
        uint8_t transaction_id[3];
 struct dhcpv6_client_header {
        uint8_t msg_type;
        uint8_t transaction_id[3];
@@ -138,25 +142,45 @@ struct dhcpv6_ia_addr {
 
 struct dhcpv6_assignment {
        struct list_head head;
 
 struct dhcpv6_assignment {
        struct list_head head;
+       struct interface *iface;
+
        struct sockaddr_in6 peer;
        time_t valid_until;
        struct sockaddr_in6 peer;
        time_t valid_until;
-       time_t reconf_sent;
-       bool all_class;
-       uint8_t classes_cnt;
-       uint16_t *classes;
+
+       struct uloop_timeout reconf_timer;
+       bool accept_reconf;
        int reconf_cnt;
        int reconf_cnt;
-       char *hostname;
        uint8_t key[16];
        uint8_t key[16];
+
+       char *hostname;
        uint32_t assigned;
        uint32_t iaid;
        uint8_t mac[6];
        uint8_t length; // length == 128 -> IA_NA, length <= 64 -> IA_PD
        uint32_t assigned;
        uint32_t iaid;
        uint8_t mac[6];
        uint8_t length; // length == 128 -> IA_NA, length <= 64 -> IA_PD
-       bool accept_reconf;
+
+       struct odhcpd_ipaddr *managed;
+       ssize_t managed_size;
+       struct ustream_fd managed_sock;
+
+       uint32_t leasetime;
+       unsigned int flags;
+
        uint8_t clid_len;
        uint8_t clid_data[];
 };
 
        uint8_t clid_len;
        uint8_t clid_data[];
 };
 
+struct dhcpv6_cer_id {
+       uint16_t type;
+       uint16_t len;
+       uint16_t reserved;
+       uint16_t auth_type;
+       uint8_t auth[16];
+       struct in6_addr addr;
+};
 
 
+typedef void (*dhcpv6_binding_cb_handler_t)(struct in6_addr *addr, int prefix,
+                                               uint32_t pref, uint32_t valid,
+                                               void *arg);
 
 #define dhcpv6_for_each_option(start, end, otype, olen, odata)\
        for (uint8_t *_o = (uint8_t*)(start); _o + 4 <= (end) &&\
 
 #define dhcpv6_for_each_option(start, end, otype, olen, odata)\
        for (uint8_t *_o = (uint8_t*)(start); _o + 4 <= (end) &&\
@@ -165,8 +189,12 @@ struct dhcpv6_assignment {
                _o += 4 + (_o[2] << 8 | _o[3]))
 
 int dhcpv6_init_ia(struct interface *iface, int socket);
                _o += 4 + (_o[2] << 8 | _o[3]))
 
 int dhcpv6_init_ia(struct interface *iface, int socket);
-size_t dhcpv6_handle_ia(uint8_t *buf, size_t buflen, struct interface *iface,
+ssize_t dhcpv6_handle_ia(uint8_t *buf, size_t buflen, struct interface *iface,
                const struct sockaddr_in6 *addr, const void *data, const uint8_t *end);
 int dhcpv6_ia_init(void);
 int setup_dhcpv6_ia_interface(struct interface *iface, bool enable);
                const struct sockaddr_in6 *addr, const void *data, const uint8_t *end);
 int dhcpv6_ia_init(void);
 int setup_dhcpv6_ia_interface(struct interface *iface, bool enable);
+void dhcpv6_enum_ia_addrs(struct interface *iface, struct dhcpv6_assignment *c, time_t now,
+                               dhcpv6_binding_cb_handler_t func, void *arg);
 void dhcpv6_write_statefile(void);
 void dhcpv6_write_statefile(void);
+void dhcpv6_ia_preupdate(struct interface *iface);
+void dhcpv6_ia_postupdate(struct interface *iface);