From 47fac6f603c236d7b149e0ec593269322572b352 Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Sun, 30 Mar 2014 19:51:56 +0200 Subject: [PATCH] Add initial support for CER-ID --- CMakeLists.txt | 4 ++++ README | 2 ++ src/dhcpv6.c | 13 ++++++++++++- src/odhcp6c.h | 14 ++++++++++++++ src/script.c | 4 +++- 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 47537e9..aedeebf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,10 @@ if(${EXT_PREFIX_CLASS}) add_definitions(-DEXT_PREFIX_CLASS=${EXT_PREFIX_CLASS}) endif(${EXT_PREFIX_CLASS}) +if(${EXT_CER_ID}) + add_definitions(-DEXT_CER_ID=${EXT_CER_ID}) +endif(${EXT_CER_ID}) + if(${EXT_BFD_PING}) add_definitions(-DEXT_BFD_PING) set(BFD_SOURCE src/bfd.c) diff --git a/README b/README index 0b4cf9a..6f5c62c 100644 --- a/README +++ b/README @@ -28,6 +28,8 @@ especially routers. It compiles to only about 30 KB (-Os -s). g) Information-Refresh Options h) Configurable SOL_MAX_RT i) DS-Lite AFTR-Name Option + j) Prefix Class (experimental) + k) CER-ID (experimental) 4. Support for requesting and parsing Router Advertisements a) parsing of prefixes, routes, MTU and RDNSS options diff --git a/src/dhcpv6.c b/src/dhcpv6.c index c87d289..afea77f 100644 --- a/src/dhcpv6.c +++ b/src/dhcpv6.c @@ -175,6 +175,9 @@ int init_dhcpv6(const char *ifname, unsigned int options, int sol_timeout) htons(DHCPV6_OPT_INF_MAX_RT), #ifdef EXT_PREFIX_CLASS htons(DHCPV6_OPT_PREFIX_CLASS), +#endif +#ifdef EXT_CER_ID + htons(DHCPV6_OPT_CER_ID), #endif }; odhcp6c_add_state(STATE_ORO, oro, sizeof(oro)); @@ -1010,7 +1013,15 @@ static int dhcpv6_handle_reply(enum dhcpv6_msg orig, _unused const int rc, if (inf_max_rt >= DHCPV6_INF_MAX_RT_MIN && inf_max_rt <= DHCPV6_INF_MAX_RT_MAX) dhcpv6_retx[DHCPV6_MSG_INFO_REQ].max_timeo = inf_max_rt; - }else if (otype != DHCPV6_OPT_CLIENTID && +#ifdef EXT_CER_ID + } else if (otype == DHCPV6_OPT_CER_ID && olen == -4 + + sizeof(struct dhcpv6_cer_id)) { + struct dhcpv6_cer_id *cer_id = (void*)&odata[-4]; + struct in6_addr any = IN6ADDR_ANY_INIT; + if (memcmp(&cer_id->addr, &any, sizeof(any))) + odhcp6c_add_state(STATE_CER, &cer_id->addr, sizeof(any)); +#endif + } else if (otype != DHCPV6_OPT_CLIENTID && otype != DHCPV6_OPT_SERVERID) { odhcp6c_add_state(STATE_CUSTOM_OPTS, &odata[-4], olen + 4); diff --git a/src/odhcp6c.h b/src/odhcp6c.h index f9a3fec..2bc289b 100644 --- a/src/odhcp6c.h +++ b/src/odhcp6c.h @@ -67,6 +67,10 @@ enum dhcvp6_opt { /* draft-bhandari-dhc-class-based-prefix, not yet standardized */ DHCPV6_OPT_PREFIX_CLASS = EXT_PREFIX_CLASS, #endif +#ifdef EXT_CER_ID + /* draft-donley-dhc-cer-id-option-03 */ + DHCPV6_OPT_CER_ID = EXT_CER_ID, +#endif }; enum dhcpv6_opt_npt { @@ -170,6 +174,15 @@ struct dhcpv6_auth_reconfigure { uint8_t key[16]; } _packed; +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; +} _packed; + #define dhcpv6_for_each_option(start, end, otype, olen, odata)\ for (uint8_t *_o = (uint8_t*)(start); _o + 4 <= (uint8_t*)(end) &&\ @@ -215,6 +228,7 @@ enum odhcp6c_state { STATE_AFTR_NAME, STATE_VENDORCLASS, STATE_USERCLASS, + STATE_CER, _STATE_MAX }; diff --git a/src/script.c b/src/script.c index 61bab67..9089409 100644 --- a/src/script.c +++ b/src/script.c @@ -232,7 +232,7 @@ void script_delay_call(const char *status, int timeout) void script_call(const char *status) { size_t dns_len, search_len, custom_len, sntp_ip_len, ntp_ip_len, ntp_dns_len; - size_t sip_ip_len, sip_fqdn_len, aftr_name_len; + size_t sip_ip_len, sip_fqdn_len, aftr_name_len, cer_len; odhcp6c_expire(); if (delayed_call) { @@ -249,6 +249,7 @@ void script_call(const char *status) struct in6_addr *sip = odhcp6c_get_state(STATE_SIP_IP, &sip_ip_len); uint8_t *sip_fqdn = odhcp6c_get_state(STATE_SIP_FQDN, &sip_fqdn_len); uint8_t *aftr_name = odhcp6c_get_state(STATE_AFTR_NAME, &aftr_name_len); + struct in6_addr *cer = odhcp6c_get_state(STATE_CER, &cer_len); size_t prefix_len, address_len, ra_pref_len, ra_route_len, ra_dns_len; uint8_t *prefix = odhcp6c_get_state(STATE_IA_PD, &prefix_len); @@ -268,6 +269,7 @@ void script_call(const char *status) fqdn_to_env("SIP_DOMAIN", sip_fqdn, sip_fqdn_len); fqdn_to_env("AFTR", aftr_name, aftr_name_len); fqdn_to_ip_env("AFTR_IP", aftr_name, aftr_name_len); + ipv6_to_env("CER", cer, cer_len / sizeof(*cer)); bin_to_env(custom, custom_len); entry_to_env("PREFIXES", prefix, prefix_len, ENTRY_PREFIX); entry_to_env("ADDRESSES", address, address_len, ENTRY_ADDRESS); -- 2.25.1