38 #include <dns/result.h>
45 static void ddns_fwd_srv_connector(
struct lease *
lease,
49 isc_result_t eresult);
55 static void data_string_append (
struct data_string *ds1,
58 memcpy (ds1 ->
buffer -> data + ds1 -> len,
61 ds1 -> len += ds2 -> len;
84 int server_updates_a = 1;
86 int ignorep = 0, client_ignorep = 0;
105 if ((old != NULL) && (old->
ddns_cb != NULL)) {
109 }
else if (lease6 != NULL) {
110 if ((old6 != NULL) && (old6->
ddns_cb != NULL)) {
123 if (ddns_cb == NULL) {
139 scope = &(lease->
scope);
143 }
else if (lease6 != NULL) {
144 scope = &(lease6->
scope);
149 memset (&d1, 0,
sizeof(d1));
150 memset (&ddns_hostname, 0,
sizeof (ddns_hostname));
151 memset (&ddns_domainname, 0,
sizeof (ddns_domainname));
152 memset (&old_ddns_fwd_name, 0,
sizeof (ddns_fwd_name));
153 memset (&ddns_fwd_name, 0,
sizeof (ddns_fwd_name));
154 memset (&ddns_dhcid, 0,
sizeof (ddns_dhcid));
161 packet->
options, options, scope,
170 options, scope, oc,
MDL))
181 options, scope, oc,
MDL))
184 server_updates_a = 0;
195 options, scope, oc,
MDL)) {
208 options, scope, oc,
MDL))
219 options, scope, oc,
MDL);
227 options, scope, oc,
MDL);
232 if (ddns_hostname.len + ddns_domainname.len > 253) {
233 log_error (
"ddns_update: host.domain name too long");
239 ddns_hostname.len + ddns_domainname.len + 2,
241 if (ddns_fwd_name.buffer) {
242 ddns_fwd_name.data = ddns_fwd_name.buffer->data;
243 data_string_append (&ddns_fwd_name, &ddns_hostname);
244 ddns_fwd_name.buffer->data[ddns_fwd_name.len] =
'.';
246 data_string_append (&ddns_fwd_name, &ddns_domainname);
247 ddns_fwd_name.buffer->data[ddns_fwd_name.len] =
'\0';
248 ddns_fwd_name.terminated = 1;
256 if (old_ddns_fwd_name.len != ddns_fwd_name.len ||
257 memcmp (old_ddns_fwd_name.data, ddns_fwd_name.data,
258 old_ddns_fwd_name.len)) {
267 #if defined (DDNS_UPDATE_SLOW_TRANSITION)
291 options, scope, oc,
MDL)) {
300 "ddns-client-fqdn")) {
303 if (old_ddns_fwd_name.len == ddns_fwd_name.len &&
304 !memcmp (old_ddns_fwd_name.data, ddns_fwd_name.data,
305 old_ddns_fwd_name.len) &&
310 options, scope, oc,
MDL))) {
319 if ((!ddns_fwd_name.len) || (ddns_fwd_name.len > 255)) {
320 if (ddns_fwd_name.len > 255) {
321 log_error (
"client provided fqdn: too long");
325 if (do_remove != 0) {
355 #ifndef USE_OLD_DDNS_TTL
356 else if (lease6 != NULL) {
357 ddns_ttl = lease6->
prefer/2;
369 if (d1.len == sizeof (u_int32_t))
375 ddns_cb->
ttl = ddns_ttl;
395 rev_name_len = snprintf(buf,
sizeof(buf),
"%u.%u.%u.%u.",
402 rev_name_len += d1.len;
404 if (rev_name_len > 255) {
405 log_error(
"ddns_update: Calculated rev domain "
416 rev_name_len =
sizeof(
"0.1.2.3.4.5.6.7."
458 data_string_append(rname, &d1);
463 for (i=0; i<16; i++) {
465 (*a & 0xF), ((*a >> 4) & 0xF));
469 strcat(p,
"ip6.arpa.");
470 rname->
len = strlen((
const char *)rname->
data);
515 if (lease6 != NULL) {
521 }
else if ((lease != NULL) &&
522 (lease->
uid != NULL) &&
528 (lease->
uid[0] == 255)) {
539 }
else if (lease != NULL)
560 options, scope, oc,
MDL))
579 ddns_fwd_srv_connector(lease, lease6, scope, ddns_cb,
605 }
else if (client_ignorep &&
672 memcpy(&bp->
data[5], d1.data, d1.len);
674 bp, &bp->
data[5], d1.len,
689 bp ->
data [0] = server_updates_a;
691 bp, &bp->
data [0], 1,
694 bp ->
data [1] = server_updates_a;
696 bp, &bp->
data [1], 1,
703 options, scope, oc,
MDL))
708 bp, &bp->
data [2], 1,
711 bp ->
data [3] = 255;
713 bp, &bp->
data [3], 1,
716 bp ->
data [4] = 255;
718 bp, &bp->
data [4], 1,
721 if (ddns_fwd_name.len) {
722 memcpy (&bp ->
data [5],
723 ddns_fwd_name.data, ddns_fwd_name.len);
737 if (ddns_cb != NULL) {
782 struct lease *lease = NULL;
785 struct in6_addr addr;
793 return (ISC_R_SUCCESS);
801 return (ISC_R_SUCCESS);
803 if (inscope != NULL) {
807 scope = &(lease->
scope);
815 if (iasubopt_hash_lookup(&lease6, pool->
leases,
817 scope = &(lease6->
scope);
828 lease_dereference(&lease,
MDL);
834 return(ISC_R_FAILURE);
838 switch(ddns_cb->
state) {
840 unset(*scope,
"ddns-rev-name");
842 unset(*scope,
"ddns-client-fqdn");
863 memset(&lease_dhcid, 0,
sizeof(lease_dhcid));
872 unset(*scope,
"ddns-fwd-name");
880 lease_dereference(&lease,
MDL);
886 return(ISC_R_SUCCESS);
907 update_lease_failed(
struct lease *lease,
916 sprintf(reason,
"unknown");
917 sprintf(lease_address,
"unknown");
924 if (ddns_cb != NULL) {
929 sprintf(reason,
"duplicate IPv4 fixed-address entry");
931 sprintf(reason,
"duplicate IPv6 fixed-address6 entry "
932 "or overlapping pools");
938 sprintf(reason,
"corrupted ddns_cb structure (address "
943 log_error(
"Failed to properly update internal lease structure with "
945 log_error(
"control block structures. Tried to update lease for"
946 "%s address, ddns_cb=%p.", lease_address, ddns_cb);
949 log_error(
"This condition can occur, if DHCP server configuration is "
951 log_error(
"In particular, please do check that your configuration:");
952 log_error(
"a) does not have overlapping pools (especially containing");
953 log_error(
" %s address).", lease_address);
954 log_error(
"b) there are no duplicate fixed-address or fixed-address6");
955 log_error(
"entries for the %s address.", lease_address);
957 log_error(
"Possible reason for this failure: %s", reason);
959 log_fatal(
"%s(%d): Failed to update lease database with DDNS info for "
960 "address %s. Lease database inconsistent. Unable to recover."
961 " Terminating.", file, line, lease_address);
972 safe_lease_update(
struct lease *lease,
975 const char *file,
int line)
979 log_fatal(
"Impossible condition at %s:%d (called from %s:%d).",
983 if ( (lease->
ddns_cb == NULL) && (newcb == NULL) ) {
995 log_error(
"%s(%d): Invalid lease update. Tried to "
996 "clear already NULL DDNS control block "
997 "pointer for lease %s.",
1000 #if defined (DNS_UPDATES_MEMORY_CHECKS)
1001 update_lease_failed(lease, NULL, oldcb, newcb, file, line);
1016 log_error(
"%s(%d): Failed to update internal lease "
1017 "structure with DDNS control block. Existing"
1018 " ddns_cb structure does not match "
1019 "expectations.IPv4=%s, old ddns_cb=%p, tried"
1020 "to update to new ddns_cb=%p", file, line,
1023 #if defined (DNS_UPDATES_MEMORY_CHECKS)
1024 update_lease_failed(lease, NULL, oldcb, newcb, file, line);
1040 safe_lease6_update(
struct iasubopt *lease6,
1043 const char *file,
int line)
1047 if (lease6 == NULL) {
1049 log_fatal(
"Impossible condition at %s:%d (called from %s:%d).",
1053 if ( (lease6->
ddns_cb == NULL) && (newcb == NULL) ) {
1054 inet_ntop(AF_INET6, &lease6->
addr, addrbuf,
1060 log_error(
"%s(%d): Failed to update internal lease "
1061 "structure. Tried to clear already NULL "
1062 "DDNS control block pointer for lease %s.",
1063 file, line, addrbuf);
1065 #if defined (DNS_UPDATES_MEMORY_CHECKS)
1066 update_lease_failed(NULL, lease6, oldcb, newcb, file, line);
1082 inet_ntop(AF_INET6, &lease6->
addr, addrbuf,
1085 log_error(
"%s(%d): Failed to update internal lease "
1086 "structure with DDNS control block. Existing"
1087 " ddns_cb structure does not match "
1088 "expectations.IPv6=%s, old ddns_cb=%p, tried"
1089 "to update to new ddns_cb=%p", file, line,
1090 addrbuf, oldcb, newcb);
1092 #if defined (DNS_UPDATES_MEMORY_CHECKS)
1093 update_lease_failed(NULL, lease6, oldcb, newcb, file, line);
1123 ddns_update_lease_ptr(
struct lease *lease,
1127 const char * file,
int line)
1130 sprintf(ddns_address,
"unknown");
1131 if (ddns_cb == NULL) {
1132 log_info(
"%s(%d): No control block for lease update",
1134 return (ISC_R_FAILURE);
1140 #if defined (DEBUG_DNS_UPDATES)
1141 log_info(
"%s(%d): Updating lease_ptr for ddns_cp=%p (addr=%s)",
1142 file, line, ddns_cb, ddns_address );
1150 #if defined (DEBUG_DNS_UPDATES)
1151 log_info(
"lease is static, returning");
1153 return (ISC_R_SUCCESS);
1162 return (ISC_R_SUCCESS);
1165 if (lease != NULL) {
1166 safe_lease_update(lease, ddns_cb, ddns_cb_set,
1168 }
else if (lease6 != NULL) {
1169 safe_lease6_update(lease6, ddns_cb, ddns_cb_set,
1175 #if defined (DEBUG_DNS_UPDATES)
1176 log_info(
"%s(%d): find_lease_by_ip_addr(%s) successful:"
1177 "lease=%p", file, line, ddns_address,
1181 safe_lease_update(find_lease, ddns_cb,
1182 ddns_cb_set, file, line);
1183 lease_dereference(&find_lease,
MDL);
1186 log_error(
"%s(%d): ddns_update_lease_ptr failed. "
1187 "Lease for %s not found.",
1190 #if defined (DNS_UPDATES_MEMORY_CHECKS)
1191 update_lease_failed(NULL, NULL, ddns_cb, ddns_cb_set,
1198 return(ISC_R_FAILURE);
1202 struct iasubopt *find_lease6 = NULL;
1204 struct in6_addr addr;
1212 inet_ntop(AF_INET6, &addr, addrbuf,
1214 log_error(
"%s(%d): Pool for lease %s not found.",
1215 file, line, addrbuf);
1216 #if defined (DNS_UPDATES_MEMORY_CHECKS)
1217 update_lease_failed(NULL, NULL, ddns_cb, ddns_cb_set,
1224 return(ISC_R_FAILURE);
1227 if (iasubopt_hash_lookup(&find_lease6, pool->
leases,
1229 find_lease6->
ddns_cb = ddns_cb_set;
1232 inet_ntop(AF_INET6, &addr, addrbuf,
1234 log_error(
"%s(%d): Lease %s not found within pool.",
1235 file, line, addrbuf);
1236 #if defined (DNS_UPDATES_MEMORY_CHECKS)
1237 update_lease_failed(NULL, NULL, ddns_cb, ddns_cb_set,
1244 return(ISC_R_FAILURE);
1249 log_fatal(
"Impossible condition at %s:%d, called from %s:%d.",
1253 return(ISC_R_SUCCESS);
1258 isc_result_t eresult)
1260 if (eresult == ISC_R_SUCCESS) {
1261 log_info(
"Added reverse map from %.*s to %.*s",
1267 ddns_update_lease_text(ddns_cb, NULL);
1269 log_error(
"Unable to add reverse map from %.*s to %.*s: %s",
1274 isc_result_totext (eresult));
1277 ddns_update_lease_ptr(NULL, NULL, ddns_cb, NULL,
MDL);
1302 isc_result_t eresult)
1304 isc_result_t result = eresult;
1308 log_info(
"Removed reverse map on %.*s",
1313 case DNS_R_NXDOMAIN:
1317 ddns_update_lease_text(ddns_cb, NULL);
1320 result = ISC_R_SUCCESS;
1321 #if defined (DEBUG_DNS_UPDATES)
1322 log_info(
"DDNS: removed map or no reverse map to remove %.*s",
1329 log_error(
"Can't remove reverse map on %.*s: %s",
1332 isc_result_totext (eresult));
1336 ddns_update_lease_ptr(NULL, NULL, ddns_cb, NULL,
MDL);
1337 ddns_fwd_srv_connector(NULL, NULL, NULL, ddns_cb->
next_op, result);
1373 isc_result_t eresult)
1375 isc_result_t result;
1376 const char *logstr = NULL;
1384 log_info(
"Added new forward map from %.*s to %s",
1389 ddns_update_lease_text(ddns_cb, NULL);
1393 if (ddns_cb->
zone != NULL) {
1401 if (result == ISC_R_SUCCESS) {
1408 case DNS_R_YXDOMAIN:
1409 logstr =
"DHCID mismatch, belongs to another client.";
1413 case DNS_R_NXDOMAIN:
1414 logstr =
"Has an address record but no DHCID, not mine.";
1418 logstr = isc_result_totext(eresult);
1422 if (logstr != NULL) {
1423 log_error(
"Forward map from %.*s to %s FAILED: %s",
1426 ddns_address, logstr);
1429 ddns_update_lease_ptr(NULL, NULL, ddns_cb, NULL,
MDL);
1447 isc_result_t eresult)
1449 isc_result_t result;
1457 log_info (
"Added new forward map from %.*s to %s",
1462 ddns_update_lease_text(ddns_cb, NULL);
1466 if (ddns_cb->
zone != NULL) {
1474 if (result == ISC_R_SUCCESS) {
1480 case DNS_R_YXDOMAIN:
1483 ddns_cb->
cur_func = ddns_fwd_srv_add2;
1486 if (result == ISC_R_SUCCESS) {
1492 log_error (
"Unable to add forward map from %.*s to %s: %s",
1496 isc_result_totext (eresult));
1500 ddns_update_lease_ptr(NULL, NULL, ddns_cb, NULL,
MDL);
1517 ddns_fwd_srv_connector(
struct lease *lease,
1521 isc_result_t eresult)
1523 isc_result_t result = ISC_R_FAILURE;
1525 if (ddns_cb == NULL) {
1530 if (eresult == ISC_R_SUCCESS) {
1538 ddns_cb->
cur_func = ddns_fwd_srv_add1;
1546 ddns_update_lease_text(ddns_cb, inscope);
1550 if (result == ISC_R_SUCCESS) {
1551 ddns_update_lease_ptr(lease, lease6, ddns_cb, ddns_cb,
MDL);
1574 isc_result_t eresult)
1576 if (eresult == ISC_R_SUCCESS) {
1577 ddns_update_lease_text(ddns_cb, NULL);
1582 if (ddns_cb->
zone != NULL) {
1587 ddns_cb->
cur_func = ddns_ptr_remove;
1590 if (eresult == ISC_R_SUCCESS) {
1596 ddns_update_lease_ptr(NULL, NULL, ddns_cb, NULL,
MDL);
1597 ddns_fwd_srv_connector(NULL, NULL, NULL, ddns_cb->
next_op, eresult);
1612 isc_result_t eresult)
1614 isc_result_t result = eresult;
1621 log_info(
"Removed forward map from %.*s to %s",
1628 ddns_cb->
cur_func = ddns_fwd_srv_rem2;
1630 if (result == ISC_R_SUCCESS) {
1636 case DNS_R_NXDOMAIN:
1637 ddns_update_lease_text(ddns_cb, NULL);
1639 #if defined (DEBUG_DNS_UPDATES)
1640 log_info(
"DDNS: no forward map to remove. %p", ddns_cb);
1646 if (ddns_cb->
zone != NULL) {
1651 ddns_cb->
cur_func = ddns_ptr_remove;
1654 if (result == ISC_R_SUCCESS) {
1660 eresult = ISC_R_SUCCESS;
1668 ddns_update_lease_ptr(NULL, NULL, ddns_cb, NULL,
MDL);
1669 ddns_fwd_srv_connector(NULL, NULL, NULL, ddns_cb->
next_op, eresult);
1701 isc_boolean_t active)
1703 isc_result_t rcode, execute_add = ISC_R_FAILURE;
1705 isc_result_t result = ISC_R_FAILURE;
1732 if (add_ddns_cb == NULL) {
1733 if ((lease != NULL) && (lease->
ddns_cb != NULL)) {
1743 ((active == ISC_FALSE) &&
1750 if (ddns_cb->
next_op != NULL) {
1754 #if defined (DEBUG_DNS_UPDATES)
1755 log_info(
"DDNS %s(%d): removal already in "
1756 "progress new ddns_cb=%p",
1759 return (ISC_R_SUCCESS);
1761 }
else if ((lease6 != NULL) && (lease6->
ddns_cb != NULL)) {
1771 ((active == ISC_FALSE) &&
1778 if (ddns_cb->
next_op != NULL) {
1782 #if defined (DEBUG_DNS_UPDATES)
1783 log_info(
"DDNS %s(%d): removal already in "
1784 "progress new ddns_cb=%p",
1787 return (ISC_R_SUCCESS);
1795 if (ddns_cb == NULL) {
1804 if (lease != NULL) {
1805 scope = &(lease->
scope);
1809 }
else if (lease6 != NULL) {
1810 scope = &(lease6->
scope);
1823 if (active == ISC_TRUE) {
1839 execute_add = ISC_R_SUCCESS;
1854 execute_add = ISC_R_FAILURE;
1858 "ddns-client-fqdn")) {
1869 memset(&leaseid, 0,
sizeof(leaseid));
1906 ddns_cb->
next_op = add_ddns_cb;
1919 ddns_cb->
cur_func = ddns_fwd_srv_rem1;
1922 if (rcode == ISC_R_SUCCESS) {
1923 ddns_update_lease_ptr(lease, lease6, ddns_cb,
1925 return (ISC_R_SUCCESS);
1932 execute_add = ISC_R_FAILURE;
1937 unset(*scope,
"ddns-fwd-name");
1944 ddns_cb->
cur_func = ddns_ptr_remove;
1951 if (execute_add != ISC_R_SUCCESS) {
1953 ddns_fwd_srv_connector(lease, lease6, scope,
1954 add_ddns_cb, execute_add);
1958 result = ISC_R_SUCCESS;
1962 if (rcode == ISC_R_SUCCESS) {
1963 ddns_update_lease_ptr(lease, lease6, ddns_cb, ddns_cb,
1970 execute_add = ISC_R_FAILURE;
1981 ddns_fwd_srv_connector(lease, lease6, scope, add_ddns_cb, execute_add);
1982 if (ddns_cb != NULL)
int find_lease(struct lease **, struct packet *, struct shared_network *, int *, int *, struct lease *, const char *, int)
#define DDNS_STATIC_LEASE
const char * piaddr(const struct iaddr addr)
#define FQDN_NO_CLIENT_UPDATE
struct dhcp_ddns_cb * ddns_cb
#define DDNS_STATE_ADD_FW_NXDOMAIN
int get_dhcid(dhcp_ddns_cb_t *, int, const u_int8_t *, unsigned)
struct universe server_universe
isc_result_t ddns_modify_ptr(dhcp_ddns_cb_t *ddns_cb, const char *file, int line)
#define DDNS_STATE_REM_PTR
struct dhcp_ddns_cb * ddns_cb
#define SV_DDNS_REV_DOMAIN_NAME
int find_bound_string(struct data_string *value, struct binding_scope *scope, const char *name)
dhcp_ddns_cb_t * ddns_cb_alloc(const char *file, int line)
void data_string_forget(struct data_string *data, const char *file, int line)
int log_error(const char *,...) __attribute__((__format__(__printf__
#define DDNS_UPDATE_STYLE_STANDARD
struct binding_scope * scope
#define DDNS_STATE_REM_FW_YXDHCID
struct data_string fwd_name
#define DDNS_ACTIVE_LEASE
#define DDNS_CLIENT_DID_UPDATE
struct option_state * options
void ddns_cb_free(dhcp_ddns_cb_t *ddns_cb, const char *file, int line)
#define SV_DDNS_HOST_NAME
void log_fatal(const char *,...) __attribute__((__format__(__printf__
void dhcid_tolease(struct data_string *, struct data_string *)
struct data_string rev_name
struct hardware hardware_addr
int unset(struct binding_scope *scope, const char *name)
int evaluate_option_cache(struct data_string *result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct option_cache *oc, const char *file, int line)
#define MAX_ADDRESS_STRING_LEN
dns_rdataclass_t dhcid_class
#define SV_UPDATE_OPTIMIZATION
#define DDNS_STATE_ADD_PTR
int buffer_allocate(struct buffer **ptr, unsigned len, const char *file, int line)
int write_lease(struct lease *lease)
struct dhcp_ddns_cb * next_op
#define DDNS_CONFLICT_OVERRIDE
struct data_string iaid_duid
#define DDNS_UPDATE_STYLE_INTERIM
int save_option_buffer(struct universe *universe, struct option_state *options, struct buffer *bp, unsigned char *buffer, unsigned length, unsigned code, int terminatep)
isc_result_t dhcid_fromlease(struct data_string *, struct data_string *)
void ddns_cancel(dhcp_ddns_cb_t *ddns_cb, const char *file, int line)
struct option_cache * lookup_option(struct universe *universe, struct option_state *options, unsigned code)
int int log_info(const char *,...) __attribute__((__format__(__printf__
u_int32_t getULong(const unsigned char *)
isc_result_t ipv6_pool_dereference(struct ipv6_pool **pool, const char *file, int line)
de-reference an IPv6 pool structure.
isc_result_t find_ipv6_pool(struct ipv6_pool **pool, u_int16_t type, const struct in6_addr *addr)
#define SV_DO_REVERSE_UPDATES
#define SV_DDNS_DOMAIN_NAME
isc_result_t ddns_removals(struct lease *, struct iasubopt *, struct dhcp_ddns_cb *, isc_boolean_t)
int evaluate_boolean_option_cache(int *ignorep, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct option_cache *oc, const char *file, int line)
int ddns_updates(struct packet *, struct lease *, struct lease *, struct iasubopt *, struct iasubopt *, struct option_state *)
isc_result_t iasubopt_dereference(struct iasubopt **iasubopt, const char *file, int line)
#define FQDN_SERVER_UPDATE
#define DDNS_STATE_ADD_FW_YXDHCID
u_int8_t hbuf[HARDWARE_ADDR_LEN+1]
void ddns_cb_forget_zone(dhcp_ddns_cb_t *ddns_cb)
struct universe fqdn_universe
int write_ia(const struct ia_xx *)
#define SV_DDNS_CONFLICT_DETECT
#define DHO_DHCP_CLIENT_IDENTIFIER
const unsigned char * data
int bind_ds_value(struct binding_scope **scope, const char *name, struct data_string *value)
struct binding_scope * scope
void data_string_copy(struct data_string *dest, const struct data_string *src, const char *file, int line)
#define SV_UPDATE_STATIC_LEASES
int find_lease_by_ip_addr(struct lease **, struct iaddr, const char *, int)
#define DDNS_STATE_CLEANUP
#define DDNS_STATE_REM_FW_NXRR
#define MAX_DEFAULT_DDNS_TTL
#define SV_CLIENT_UPDATES
#define SV_DO_FORWARD_UPDATES
int buffer_dereference(struct buffer **ptr, const char *file, int line)
isc_result_t ddns_modify_fwd(dhcp_ddns_cb_t *ddns_cb, const char *file, int line)