37 #include <dns/result.h> 44 static void ddns_fwd_srv_connector(
struct lease *
lease,
48 isc_result_t eresult);
54 static void data_string_append (
struct data_string *ds1,
57 memcpy (ds1 ->
buffer -> data + ds1 -> len,
60 ds1 -> len += ds2 -> len;
83 int server_updates_a = 1;
85 int ignorep = 0, client_ignorep = 0;
104 if ((old != NULL) && (old->
ddns_cb != NULL)) {
108 }
else if (lease6 != NULL) {
109 if ((old6 != NULL) && (old6->
ddns_cb != NULL)) {
122 if (ddns_cb == NULL) {
142 }
else if (lease6 != NULL) {
143 scope = &(lease6->
scope);
148 memset (&d1, 0,
sizeof(d1));
149 memset (&ddns_hostname, 0,
sizeof (ddns_hostname));
150 memset (&ddns_domainname, 0,
sizeof (ddns_domainname));
151 memset (&old_ddns_fwd_name, 0,
sizeof (ddns_fwd_name));
152 memset (&ddns_fwd_name, 0,
sizeof (ddns_fwd_name));
153 memset (&ddns_dhcid, 0,
sizeof (ddns_dhcid));
169 options, scope, oc,
MDL))
180 options, scope, oc,
MDL))
183 server_updates_a = 0;
194 options, scope, oc,
MDL)) {
207 options, scope, oc,
MDL))
218 options, scope, oc,
MDL);
230 options, scope, oc,
MDL)) {
234 MDL) && ddns_hostname.len > 0));
242 options, scope, oc,
MDL);
247 if (ddns_hostname.len + ddns_domainname.len > 253) {
248 log_error (
"ddns_update: host.domain name too long");
255 ddns_domainname.len + 2,
MDL)) {
256 ddns_fwd_name.data = ddns_fwd_name.buffer->data;
257 data_string_append (&ddns_fwd_name, &ddns_hostname);
258 ddns_fwd_name.buffer->data[ddns_fwd_name.len] =
'.';
260 data_string_append (&ddns_fwd_name, &ddns_domainname);
261 ddns_fwd_name.buffer->data[ddns_fwd_name.len] =
'\0';
262 ddns_fwd_name.terminated = 1;
270 if (old_ddns_fwd_name.len != ddns_fwd_name.len ||
271 memcmp (old_ddns_fwd_name.data, ddns_fwd_name.data,
272 old_ddns_fwd_name.len)) {
281 #if defined (DDNS_UPDATE_SLOW_TRANSITION) 305 options, scope, oc,
MDL)) {
314 "ddns-client-fqdn")) {
317 if (old_ddns_fwd_name.len == ddns_fwd_name.len &&
318 !memcmp (old_ddns_fwd_name.data, ddns_fwd_name.data,
319 old_ddns_fwd_name.len) &&
324 options, scope, oc,
MDL))) {
333 if ((!ddns_fwd_name.len) || (ddns_fwd_name.len > 255)) {
334 if (ddns_fwd_name.len > 255) {
335 log_error (
"client provided fqdn: too long");
339 if (do_remove != 0) {
369 #ifndef USE_OLD_DDNS_TTL 370 else if (lease6 != NULL) {
371 ddns_ttl = lease6->
prefer/2;
383 if (d1.len == sizeof (u_int32_t))
389 ddns_cb->
ttl = ddns_ttl;
409 rev_name_len = snprintf(buf,
sizeof(buf),
"%u.%u.%u.%u.",
416 rev_name_len += d1.len;
418 if (rev_name_len > 255) {
419 log_error(
"ddns_update: Calculated rev domain " 430 rev_name_len =
sizeof(
"0.1.2.3.4.5.6.7." 455 rev_name_len,
MDL)) {
472 data_string_append(rname, &d1);
477 for (i=0; i<16; i++) {
479 (*a & 0xF), ((*a >> 4) & 0xF));
483 strcat(p,
"ip6.arpa.");
484 rname->
len = strlen((
const char *)rname->
data);
529 if (lease6 != NULL) {
535 }
else if ((
lease != NULL) &&
553 }
else if (
lease != NULL)
574 options, scope, oc,
MDL))
593 ddns_fwd_srv_connector(
lease, lease6, scope, ddns_cb,
619 }
else if (client_ignorep &&
686 memcpy(&bp->
data[5], d1.data, d1.len);
688 bp, &bp->
data[5], d1.len,
703 bp ->
data [0] = server_updates_a;
705 bp, &bp->
data [0], 1,
708 bp ->
data [1] = server_updates_a;
710 bp, &bp->
data [1], 1,
717 options, scope, oc,
MDL))
722 bp, &bp->
data [2], 1,
725 bp ->
data [3] = 255;
727 bp, &bp->
data [3], 1,
730 bp ->
data [4] = 255;
732 bp, &bp->
data [4], 1,
735 if (ddns_fwd_name.len) {
736 memcpy (&bp ->
data [5],
737 ddns_fwd_name.data, ddns_fwd_name.len);
751 if (ddns_cb != NULL) {
799 struct in6_addr addr;
807 return (ISC_R_SUCCESS);
815 return (ISC_R_SUCCESS);
817 if (inscope != NULL) {
829 if (iasubopt_hash_lookup(&lease6,
pool->leases,
831 scope = &(lease6->
scope);
848 return(ISC_R_FAILURE);
852 switch(ddns_cb->
state) {
854 unset(*scope,
"ddns-rev-name");
856 unset(*scope,
"ddns-client-fqdn");
877 memset(&lease_dhcid, 0,
sizeof(lease_dhcid));
886 unset(*scope,
"ddns-fwd-name");
900 return(ISC_R_SUCCESS);
930 sprintf(reason,
"unknown");
931 sprintf(lease_address,
"unknown");
938 if (ddns_cb != NULL) {
943 sprintf(reason,
"duplicate IPv4 fixed-address entry");
945 sprintf(reason,
"duplicate IPv6 fixed-address6 entry " 946 "or overlapping pools");
952 sprintf(reason,
"corrupted ddns_cb structure (address " 957 log_error(
"Failed to properly update internal lease structure with " 959 log_error(
"control block structures. Tried to update lease for" 960 "%s address, ddns_cb=%p.", lease_address, ddns_cb);
963 log_error(
"This condition can occur, if DHCP server configuration is " 965 log_error(
"In particular, please do check that your configuration:");
966 log_error(
"a) does not have overlapping pools (especially containing");
967 log_error(
" %s address).", lease_address);
968 log_error(
"b) there are no duplicate fixed-address or fixed-address6");
969 log_error(
"entries for the %s address.", lease_address);
971 log_error(
"Possible reason for this failure: %s", reason);
973 log_fatal(
"%s(%d): Failed to update lease database with DDNS info for " 974 "address %s. Lease database inconsistent. Unable to recover." 975 " Terminating.",
file,
line, lease_address);
993 log_fatal(
"Impossible condition at %s:%d (called from %s:%d).",
1009 log_error(
"%s(%d): Invalid lease update. Tried to " 1010 "clear already NULL DDNS control block " 1011 "pointer for lease %s.",
1014 #if defined (DNS_UPDATES_MEMORY_CHECKS) 1030 log_error(
"%s(%d): Failed to update internal lease " 1031 "structure with DDNS control block. Existing" 1032 " ddns_cb structure does not match " 1033 "expectations.IPv4=%s, old ddns_cb=%p, tried" 1034 "to update to new ddns_cb=%p",
file,
line,
1037 #if defined (DNS_UPDATES_MEMORY_CHECKS) 1054 safe_lease6_update(
struct iasubopt *lease6,
1061 if (lease6 == NULL) {
1063 log_fatal(
"Impossible condition at %s:%d (called from %s:%d).",
1067 if ( (lease6->
ddns_cb == NULL) && (newcb == NULL) ) {
1068 inet_ntop(AF_INET6, &lease6->
addr, addrbuf,
1074 log_error(
"%s(%d): Failed to update internal lease " 1075 "structure. Tried to clear already NULL " 1076 "DDNS control block pointer for lease %s.",
1079 #if defined (DNS_UPDATES_MEMORY_CHECKS) 1080 update_lease_failed(NULL, lease6, oldcb, newcb,
file,
line);
1096 inet_ntop(AF_INET6, &lease6->
addr, addrbuf,
1099 log_error(
"%s(%d): Failed to update internal lease " 1100 "structure with DDNS control block. Existing" 1101 " ddns_cb structure does not match " 1102 "expectations.IPv6=%s, old ddns_cb=%p, tried" 1103 "to update to new ddns_cb=%p",
file,
line,
1104 addrbuf, oldcb, newcb);
1106 #if defined (DNS_UPDATES_MEMORY_CHECKS) 1107 update_lease_failed(NULL, lease6, oldcb, newcb,
file,
line);
1144 sprintf(ddns_address,
"unknown");
1145 if (ddns_cb == NULL) {
1146 log_info(
"%s(%d): No control block for lease update",
1148 return (ISC_R_FAILURE);
1153 #if defined (DEBUG_DNS_UPDATES) 1154 log_info(
"%s(%d): Updating lease_ptr for ddns_cp=%p (addr=%s)",
1155 file,
line, ddns_cb, ddns_address );
1163 #if defined (DEBUG_DNS_UPDATES) 1164 log_info(
"lease is static, returning");
1166 return (ISC_R_SUCCESS);
1175 return (ISC_R_SUCCESS);
1178 if (
lease != NULL) {
1179 safe_lease_update(
lease, ddns_cb, ddns_cb_set,
1181 }
else if (lease6 != NULL) {
1182 safe_lease6_update(lease6, ddns_cb, ddns_cb_set,
1188 #if defined (DEBUG_DNS_UPDATES) 1189 log_info(
"%s(%d): find_lease_by_ip_addr(%s) successful:" 1190 "lease=%p",
file,
line, ddns_address,
1199 log_error(
"%s(%d): ddns_update_lease_ptr failed. " 1200 "Lease for %s not found.",
1203 #if defined (DNS_UPDATES_MEMORY_CHECKS) 1204 update_lease_failed(NULL, NULL,
ddns_cb, ddns_cb_set,
1211 return(ISC_R_FAILURE);
1215 struct iasubopt *find_lease6 = NULL;
1217 struct in6_addr addr;
1225 inet_ntop(AF_INET6, &addr, addrbuf,
1227 log_error(
"%s(%d): Pool for lease %s not found.",
1229 #if defined (DNS_UPDATES_MEMORY_CHECKS) 1230 update_lease_failed(NULL, NULL, ddns_cb, ddns_cb_set,
1237 return(ISC_R_FAILURE);
1240 if (iasubopt_hash_lookup(&find_lease6,
pool->leases,
1242 find_lease6->
ddns_cb = ddns_cb_set;
1245 inet_ntop(AF_INET6, &addr, addrbuf,
1247 log_error(
"%s(%d): Lease %s not found within pool.",
1249 #if defined (DNS_UPDATES_MEMORY_CHECKS) 1250 update_lease_failed(NULL, NULL, ddns_cb, ddns_cb_set,
1257 return(ISC_R_FAILURE);
1262 log_fatal(
"Impossible condition at %s:%d, called from %s:%d.",
1266 return(ISC_R_SUCCESS);
1271 isc_result_t eresult)
1273 if (eresult == ISC_R_SUCCESS) {
1274 log_info(
"Added reverse map from %.*s to %.*s",
1280 ddns_update_lease_text(ddns_cb, NULL);
1282 log_error(
"Unable to add reverse map from %.*s to %.*s: %s",
1287 isc_result_totext (eresult));
1290 ddns_update_lease_ptr(NULL, NULL, ddns_cb, NULL,
MDL);
1315 isc_result_t eresult)
1317 isc_result_t result = eresult;
1321 log_info(
"Removed reverse map on %.*s",
1326 case DNS_R_NXDOMAIN:
1330 ddns_update_lease_text(ddns_cb, NULL);
1333 result = ISC_R_SUCCESS;
1334 #if defined (DEBUG_DNS_UPDATES) 1335 log_info(
"DDNS: removed map or no reverse map to remove %.*s",
1342 log_error(
"Can't remove reverse map on %.*s: %s",
1345 isc_result_totext (eresult));
1353 result = ISC_R_FAILURE;
1355 ddns_update_lease_ptr(NULL, NULL, ddns_cb, NULL,
MDL);
1356 ddns_fwd_srv_connector(NULL, NULL, NULL, ddns_cb->
next_op, result);
1392 isc_result_t eresult)
1394 isc_result_t result;
1395 const char *logstr = NULL;
1403 log_info(
"Added new forward map from %.*s to %s",
1408 ddns_update_lease_text(ddns_cb, NULL);
1412 if (ddns_cb->
zone != NULL) {
1420 if (result == ISC_R_SUCCESS) {
1427 case DNS_R_YXDOMAIN:
1428 logstr =
"DHCID mismatch, belongs to another client.";
1432 case DNS_R_NXDOMAIN:
1433 logstr =
"Has an address record but no DHCID, not mine.";
1437 logstr = isc_result_totext(eresult);
1441 if (logstr != NULL) {
1442 log_error(
"Forward map from %.*s to %s FAILED: %s",
1445 ddns_address, logstr);
1448 ddns_update_lease_ptr(NULL, NULL, ddns_cb, NULL,
MDL);
1466 isc_result_t eresult)
1468 isc_result_t result;
1476 log_info (
"Added new forward map from %.*s to %s",
1481 ddns_update_lease_text(ddns_cb, NULL);
1485 if (ddns_cb->
zone != NULL) {
1493 if (result == ISC_R_SUCCESS) {
1499 case DNS_R_YXDOMAIN:
1502 ddns_cb->
cur_func = ddns_fwd_srv_add2;
1505 if (result == ISC_R_SUCCESS) {
1511 log_error (
"Unable to add forward map from %.*s to %s: %s",
1515 isc_result_totext (eresult));
1519 ddns_update_lease_ptr(NULL, NULL, ddns_cb, NULL,
MDL);
1540 isc_result_t eresult)
1542 isc_result_t result = ISC_R_FAILURE;
1544 if (ddns_cb == NULL) {
1549 if (eresult == ISC_R_SUCCESS) {
1557 ddns_cb->
cur_func = ddns_fwd_srv_add1;
1565 ddns_update_lease_text(ddns_cb, inscope);
1569 if (result == ISC_R_SUCCESS) {
1570 ddns_update_lease_ptr(
lease, lease6, ddns_cb, ddns_cb,
MDL);
1593 isc_result_t eresult)
1610 if ((eresult == ISC_R_SUCCESS) ||
1611 (eresult == DNS_R_YXRRSET)) {
1612 ddns_update_lease_text(ddns_cb, NULL);
1613 eresult = ISC_R_SUCCESS;
1619 if (ddns_cb->
zone != NULL) {
1624 ddns_cb->
cur_func = ddns_ptr_remove;
1625 if (eresult == ISC_R_SUCCESS)
1629 if (eresult == ISC_R_SUCCESS) {
1634 ddns_update_lease_ptr(NULL, NULL, ddns_cb, NULL,
MDL);
1635 ddns_fwd_srv_connector(NULL, NULL, NULL, ddns_cb->
next_op, eresult);
1650 isc_result_t eresult)
1652 isc_result_t result = eresult;
1659 log_info(
"Removed forward map from %.*s to %s",
1666 ddns_cb->
cur_func = ddns_fwd_srv_rem2;
1668 if (result == ISC_R_SUCCESS) {
1674 case DNS_R_NXDOMAIN:
1675 ddns_update_lease_text(ddns_cb, NULL);
1677 #if defined (DEBUG_DNS_UPDATES) 1678 log_info(
"DDNS: no forward map to remove. %p", ddns_cb);
1682 eresult = ISC_R_SUCCESS;
1697 if (ddns_cb->
zone != NULL) {
1702 ddns_cb->
cur_func = ddns_ptr_remove;
1703 if (eresult == ISC_R_SUCCESS)
1707 if (result == ISC_R_SUCCESS) {
1714 ddns_update_lease_ptr(NULL, NULL, ddns_cb, NULL,
MDL);
1715 ddns_fwd_srv_connector(NULL, NULL, NULL, ddns_cb->
next_op, eresult);
1747 isc_boolean_t active)
1749 isc_result_t rcode, execute_add = ISC_R_FAILURE;
1751 isc_result_t result = ISC_R_FAILURE;
1778 if (add_ddns_cb == NULL) {
1789 ((active == ISC_FALSE) &&
1796 if (ddns_cb->
next_op != NULL) {
1800 #if defined (DEBUG_DNS_UPDATES) 1801 log_info(
"DDNS %s(%d): removal already in " 1802 "progress new ddns_cb=%p",
1805 return (ISC_R_SUCCESS);
1807 }
else if ((lease6 != NULL) && (lease6->
ddns_cb != NULL)) {
1817 ((active == ISC_FALSE) &&
1824 if (ddns_cb->
next_op != NULL) {
1828 #if defined (DEBUG_DNS_UPDATES) 1829 log_info(
"DDNS %s(%d): removal already in " 1830 "progress new ddns_cb=%p",
1833 return (ISC_R_SUCCESS);
1841 if (ddns_cb == NULL) {
1850 if (
lease != NULL) {
1855 }
else if (lease6 != NULL) {
1856 scope = &(lease6->
scope);
1869 if (active == ISC_TRUE) {
1885 execute_add = ISC_R_SUCCESS;
1900 execute_add = ISC_R_FAILURE;
1904 "ddns-client-fqdn")) {
1915 memset(&leaseid, 0,
sizeof(leaseid));
1952 ddns_cb->
next_op = add_ddns_cb;
1965 ddns_cb->
cur_func = ddns_fwd_srv_rem1;
1968 if (rcode == ISC_R_SUCCESS) {
1969 ddns_update_lease_ptr(
lease, lease6, ddns_cb,
1971 return (ISC_R_SUCCESS);
1978 execute_add = ISC_R_FAILURE;
1983 unset(*scope,
"ddns-fwd-name");
1990 ddns_cb->
cur_func = ddns_ptr_remove;
1998 if (execute_add != ISC_R_SUCCESS) {
2000 ddns_fwd_srv_connector(
lease, lease6, scope,
2001 add_ddns_cb, execute_add);
2005 result = ISC_R_SUCCESS;
2009 if (rcode == ISC_R_SUCCESS) {
2010 ddns_update_lease_ptr(
lease, lease6, ddns_cb, ddns_cb,
2017 execute_add = ISC_R_FAILURE;
2028 ddns_fwd_srv_connector(
lease, lease6, scope, add_ddns_cb, execute_add);
2029 if (ddns_cb != NULL)
int data_string_new(struct data_string *new_string, const char *src, unsigned int len, const char *file, int line)
Constructs a null-terminated data_string from a char* and length.
int find_lease(struct lease **, struct packet *, struct shared_network *, int *, int *, struct lease *, const char *, int)
#define DDNS_STATIC_LEASE
#define SV_USE_HOST_DECL_NAMES
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_EXECUTE_NEXT
#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)