diff options
author | Jeremy Allison <jra@samba.org> | 2008-01-08 13:11:12 -0800 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2008-01-08 13:11:12 -0800 |
commit | 7ca33d1112f415a41ed48be02a7f732a2c640ff7 (patch) | |
tree | 75e8fb14d3277c0d3bf02fe5d7f094a6245d26ea /source3 | |
parent | 791fe3119ef1756fc476b17b8c590241bee5de2e (diff) | |
download | samba-7ca33d1112f415a41ed48be02a7f732a2c640ff7.tar.gz samba-7ca33d1112f415a41ed48be02a7f732a2c640ff7.tar.bz2 samba-7ca33d1112f415a41ed48be02a7f732a2c640ff7.zip |
Move the DNS tsig update to using struct sockaddr_storage
from struct in_addr. Still only does IPv4 updates but now
it'll be easy to add IPv6 when we have time.
Jeremy.
(This used to be commit ac3a433befca2c6b674fc7e7f2f2c700d78b0a0c)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/libaddns/dns.h | 8 | ||||
-rw-r--r-- | source3/libaddns/dnsrecord.c | 35 | ||||
-rw-r--r-- | source3/utils/net_dns.c | 37 |
3 files changed, 47 insertions, 33 deletions
diff --git a/source3/libaddns/dns.h b/source3/libaddns/dns.h index b901acf4cc..a83c0b4f8e 100644 --- a/source3/libaddns/dns.h +++ b/source3/libaddns/dns.h @@ -411,7 +411,7 @@ DNS_ERROR dns_create_update( TALLOC_CTX *mem_ctx, const char *name, struct dns_update_request **preq ); DNS_ERROR dns_create_probe(TALLOC_CTX *mem_ctx, const char *zone, const char *host, int num_ips, - const struct in_addr *iplist, + const struct sockaddr_storage *sslist, struct dns_update_request **preq); DNS_ERROR dns_create_rrec(TALLOC_CTX *mem_ctx, const char *name, uint16 type, uint16 r_class, uint32 ttl, @@ -426,7 +426,7 @@ DNS_ERROR dns_create_tkey_record(TALLOC_CTX *mem_ctx, const char *keyname, struct dns_rrec **prec); DNS_ERROR dns_create_name_in_use_record(TALLOC_CTX *mem_ctx, const char *name, - const struct in_addr *ip, + const struct sockaddr_storage *ip, struct dns_rrec **prec); DNS_ERROR dns_create_delete_record(TALLOC_CTX *mem_ctx, const char *name, uint16 type, uint16 r_class, @@ -435,7 +435,7 @@ DNS_ERROR dns_create_name_not_in_use_record(TALLOC_CTX *mem_ctx, const char *name, uint32 type, struct dns_rrec **prec); DNS_ERROR dns_create_a_record(TALLOC_CTX *mem_ctx, const char *host, - uint32 ttl, struct in_addr ip, + uint32 ttl, const struct sockaddr_storage *pss, struct dns_rrec **prec); DNS_ERROR dns_unmarshall_tkey_record(TALLOC_CTX *mem_ctx, struct dns_rrec *rec, struct dns_tkey_record **ptkey); @@ -517,7 +517,7 @@ DNS_ERROR dns_sign_update(struct dns_update_request *req, DNS_ERROR dns_create_update_request(TALLOC_CTX *mem_ctx, const char *domainname, const char *hostname, - const struct in_addr *ip_addr, + const struct sockaddr_storage *ip_addr, size_t num_adds, struct dns_update_request **preq); diff --git a/source3/libaddns/dnsrecord.c b/source3/libaddns/dnsrecord.c index cb8a7c1a95..500cbd6681 100644 --- a/source3/libaddns/dnsrecord.c +++ b/source3/libaddns/dnsrecord.c @@ -119,12 +119,19 @@ DNS_ERROR dns_create_rrec(TALLOC_CTX *mem_ctx, const char *name, } DNS_ERROR dns_create_a_record(TALLOC_CTX *mem_ctx, const char *host, - uint32 ttl, struct in_addr ip, + uint32 ttl, const struct sockaddr_storage *pss, struct dns_rrec **prec) { uint8 *data; DNS_ERROR err; + struct in_addr ip; + if (pss->ss_family != AF_INET) { + /* Silently ignore this. */ + return ERROR_DNS_SUCCESS; + } + + ip = ((struct sockaddr_in *)pss)->sin_addr; if (!(data = (uint8 *)TALLOC_MEMDUP(mem_ctx, (const void *)&ip.s_addr, sizeof(ip.s_addr)))) { return ERROR_DNS_NO_MEMORY; @@ -142,11 +149,11 @@ DNS_ERROR dns_create_a_record(TALLOC_CTX *mem_ctx, const char *host, DNS_ERROR dns_create_name_in_use_record(TALLOC_CTX *mem_ctx, const char *name, - const struct in_addr *ip, + const struct sockaddr_storage *ss, struct dns_rrec **prec) { - if (ip != NULL) { - return dns_create_a_record(mem_ctx, name, 0, *ip, prec); + if (ss != NULL) { + return dns_create_a_record(mem_ctx, name, 0, ss, prec); } return dns_create_rrec(mem_ctx, name, QTYPE_ANY, DNS_CLASS_IN, 0, 0, @@ -321,7 +328,7 @@ DNS_ERROR dns_add_rrec(TALLOC_CTX *mem_ctx, struct dns_rrec *rec, DNS_ERROR dns_create_probe(TALLOC_CTX *mem_ctx, const char *zone, const char *host, int num_ips, - const struct in_addr *iplist, + const struct sockaddr_storage *sslist, struct dns_update_request **preq) { struct dns_update_request *req; @@ -340,7 +347,7 @@ DNS_ERROR dns_create_probe(TALLOC_CTX *mem_ctx, const char *zone, for (i=0; i<num_ips; i++) { err = dns_create_name_in_use_record(req, host, - &iplist[i], &rec); + &sslist[i], &rec); if (!ERR_DNS_IS_OK(err)) goto error; err = dns_add_rrec(req, rec, &req->num_preqs, &req->preqs); @@ -358,14 +365,14 @@ DNS_ERROR dns_create_probe(TALLOC_CTX *mem_ctx, const char *zone, DNS_ERROR dns_create_update_request(TALLOC_CTX *mem_ctx, const char *domainname, const char *hostname, - const struct in_addr *ip_addrs, + const struct sockaddr_storage *ss_addrs, size_t num_addrs, struct dns_update_request **preq) { struct dns_update_request *req; struct dns_rrec *rec; DNS_ERROR err; - size_t i; + size_t i; err = dns_create_update(mem_ctx, domainname, &req); if (!ERR_DNS_IS_OK(err)) return err; @@ -388,7 +395,7 @@ DNS_ERROR dns_create_update_request(TALLOC_CTX *mem_ctx, err = dns_create_delete_record(req, hostname, QTYPE_A, DNS_CLASS_ANY, &rec); if (!ERR_DNS_IS_OK(err)) goto error; - + err = dns_add_rrec(req, rec, &req->num_updates, &req->updates); if (!ERR_DNS_IS_OK(err)) goto error; @@ -396,15 +403,15 @@ DNS_ERROR dns_create_update_request(TALLOC_CTX *mem_ctx, * .. and add our IPs */ - for ( i=0; i<num_addrs; i++ ) { - err = dns_create_a_record(req, hostname, 3600, ip_addrs[i], &rec); - if (!ERR_DNS_IS_OK(err)) + for ( i=0; i<num_addrs; i++ ) { + err = dns_create_a_record(req, hostname, 3600, &ss_addrs[i], &rec); + if (!ERR_DNS_IS_OK(err)) goto error; err = dns_add_rrec(req, rec, &req->num_updates, &req->updates); - if (!ERR_DNS_IS_OK(err)) + if (!ERR_DNS_IS_OK(err)) goto error; - } + } *preq = req; return ERROR_DNS_SUCCESS; diff --git a/source3/utils/net_dns.c b/source3/utils/net_dns.c index 8b82a96892..c661c77ce6 100644 --- a/source3/utils/net_dns.c +++ b/source3/utils/net_dns.c @@ -32,14 +32,14 @@ DNS_ERROR DoDNSUpdate(char *pszServerName, const char *pszDomainName, const char *pszHostName, - const struct in_addr *iplist, size_t num_addrs ); + const struct sockaddr_storage *sslist, size_t num_addrs ); /********************************************************************* *********************************************************************/ DNS_ERROR DoDNSUpdate(char *pszServerName, const char *pszDomainName, const char *pszHostName, - const struct in_addr *iplist, size_t num_addrs ) + const struct sockaddr_storage *sslist, size_t num_addrs ) { DNS_ERROR err; struct dns_connection *conn; @@ -65,7 +65,7 @@ DNS_ERROR DoDNSUpdate(char *pszServerName, */ err = dns_create_probe(mem_ctx, pszDomainName, pszHostName, - num_addrs, iplist, &req); + num_addrs, sslist, &req); if (!ERR_DNS_IS_OK(err)) goto error; err = dns_update_transaction(mem_ctx, conn, req, &resp); @@ -81,7 +81,7 @@ DNS_ERROR DoDNSUpdate(char *pszServerName, */ err = dns_create_update_request(mem_ctx, pszDomainName, pszHostName, - iplist, num_addrs, &req); + sslist, num_addrs, &req); if (!ERR_DNS_IS_OK(err)) goto error; err = dns_update_transaction(mem_ctx, conn, req, &resp); @@ -141,30 +141,37 @@ error: /********************************************************************* *********************************************************************/ -int get_my_ip_address( struct in_addr **ips ) +int get_my_ip_address( struct sockaddr_storage **pp_ss ) + { struct iface_struct nics[MAX_INTERFACES]; int i, n; - struct in_addr *list; + struct sockaddr_storage *list = NULL; int count = 0; /* find the first non-loopback address from our list of interfaces */ n = get_interfaces(nics, MAX_INTERFACES); - - if ( (list = SMB_MALLOC_ARRAY( struct in_addr, n )) == NULL ) { + + if (n <= 0) { + return -1; + } + + if ( (list = SMB_MALLOC_ARRAY( struct sockaddr_storage, n )) == NULL ) { return -1; } for ( i=0; i<n; i++ ) { + if (is_loopback_addr(&nics[i].ip)) { + continue; + } +#if defined(HAVE_IPV6) if ((nics[i].ip.ss_family == AF_INET)) { - struct in_addr ifip; - - ifip = ((const struct sockaddr_in *)&nics[i].ip)->sin_addr; - - if (!is_loopback_ip_v4(ifip)) { - memcpy(&list[count++], &ifip, sizeof(struct in_addr)); - } + memcpy(&list[count++], &nics[i].ip); + } else +#endif + if ((nics[i].ip.ss_family == AF_INET)) { + memcpy(&list[count++], &nics[i].ip); } } *ips = list; |