X-Git-Url: https://git.decadent.org.uk/gitweb/?p=odhcp6c.git;a=blobdiff_plain;f=src%2Fodhcp6c.h;h=a33a92ea2b56be8bba85a4dc79eb581238c154e5;hp=1b46af01df98325b62913b06131bdcaff8cb4e6a;hb=8563be22c8d9e3cf38b26d69d52368c68ad3a6dd;hpb=95ec756737ef80ce929de4bd63cc2291eb6497b2 diff --git a/src/odhcp6c.h b/src/odhcp6c.h index 1b46af0..a33a92e 100644 --- a/src/odhcp6c.h +++ b/src/odhcp6c.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2012 Steven Barth + * Copyright (C) 2012-2013 Steven Barth * * 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 @@ -21,13 +21,16 @@ #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 +#define DHCPV6_SOL_MAX_RT 3600 +#define DHCPV6_REQ_MAX_RT 30 +#define DHCPV6_CNF_MAX_RT 4 +#define DHCPV6_REN_MAX_RT 600 +#define DHCPV6_REB_MAX_RT 600 +#define DHCPV6_INF_MAX_RT 3600 + enum dhcvp6_opt { DHCPV6_OPT_CLIENTID = 1, DHCPV6_OPT_SERVERID = 2, @@ -38,6 +41,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, @@ -51,9 +55,14 @@ enum dhcvp6_opt { DHCPV6_OPT_NTP_SERVER = 56, DHCPV6_OPT_SIP_SERVER_D = 21, DHCPV6_OPT_SIP_SERVER_A = 22, - - /* draft-bhandari-dhc-class-based-prefix */ - DHCPV6_OPT_PREFIX_CLASS = 200, /* NOT STANDARDIZED! */ + DHCPV6_OPT_AFTR_NAME = 64, + DHCPV6_OPT_PD_EXCLUDE = 67, + DHCPV6_OPT_SOL_MAX_RT = 82, + DHCPV6_OPT_INF_MAX_RT = 83, +#ifdef EXT_PREFIX_CLASS + /* draft-bhandari-dhc-class-based-prefix, not yet standardized */ + DHCPV6_OPT_PREFIX_CLASS = EXT_PREFIX_CLASS, +#endif }; enum dhcpv6_opt_npt { @@ -78,11 +87,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 @@ -90,12 +105,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; @@ -134,6 +149,18 @@ struct dhcpv6_duid { uint8_t data[128]; } _packed; +struct dhcpv6_auth_reconfigure { + uint16_t type; + uint16_t len; + uint8_t protocol; + uint8_t algorithm; + uint8_t rdm; + uint64_t replay; + uint8_t reconf_type; + uint8_t key[16]; +} _packed; + + #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]) &&\ @@ -147,6 +174,13 @@ 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; + void *ia_pd; + size_t ia_na_len; + size_t ia_pd_len; }; @@ -167,6 +201,7 @@ enum odhcp6c_state { STATE_RA_ROUTE, STATE_RA_PREFIX, STATE_RA_DNS, + STATE_AFTR_NAME, _STATE_MAX }; @@ -179,12 +214,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, @@ -199,14 +233,17 @@ struct odhcp6c_entry { struct in6_addr target; uint32_t valid; uint32_t preferred; - uint32_t prefix_class; + uint32_t t1; + uint32_t t2; + uint16_t class; }; -int init_dhcpv6(const char *ifname, int request_pd); -void dhcpv6_set_ia_na_mode(enum odhcp6c_ia_mode mode); +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, @@ -215,20 +252,26 @@ int set_rtnetlink_addr(int ifindex, const struct in6_addr *addr, int script_init(const char *path, const char *ifname); ssize_t script_unhexlify(uint8_t *dst, size_t len, const char *src); void script_call(const char *status); +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); // Entry manipulation struct odhcp6c_entry* odhcp6c_find_entry(enum odhcp6c_state state, const struct odhcp6c_entry *new); -void odhcp6c_update_entry(enum odhcp6c_state state, struct odhcp6c_entry *new); -void odhcp6c_update_entry_safe(enum odhcp6c_state state, struct odhcp6c_entry *new, uint32_t safe); +bool odhcp6c_update_entry(enum odhcp6c_state state, struct odhcp6c_entry *new); +bool odhcp6c_update_entry_safe(enum odhcp6c_state state, struct odhcp6c_entry *new, uint32_t safe); void odhcp6c_expire(void); +uint32_t odhcp6c_elapsed(void);