Skip to content

Commit c7dcc22

Browse files
committed
- Compile time NO_DNS option to compile without DNS client
(this means CNAMEs will not be followed to find the true host name that needs updating, and no "server" line will be given in the DDNS update package) - Support for Linux 2.4 * differences in netlink constants * IPv6 addresses do not always have lifetime info so use default TTL
1 parent d378b44 commit c7dcc22

File tree

3 files changed

+67
-7
lines changed

3 files changed

+67
-7
lines changed

dnsquery.c

+12
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ int ttl;
137137
return found;
138138
}
139139

140+
#ifndef NO_DNS
140141
static int
141142
res_init_callback(struct dns_qcache *c)
142143
{
@@ -151,6 +152,7 @@ do_res_init(void)
151152
if (!query_item('r', NULL, res_init_callback)) return 0;
152153
return 1;
153154
}
155+
#endif
154156

155157
static int
156158
local_hostname_callback(struct dns_qcache *c)
@@ -180,6 +182,7 @@ struct dns_qcache *c;
180182
return c->value;
181183
}
182184

185+
#ifndef NO_DNS
183186
static int
184187
domain_length(unsigned char *buf, int startpos, int len, int seed)
185188
{
@@ -362,15 +365,21 @@ unsigned char buf[4096];
362365
if (verbose) fprintf(stderr, "DNS response incomplete (no answer or authority section)");
363366
return -1;
364367
}
368+
#endif /* NO_DNS */
365369

366370
char *
367371
canonical_hostname(void)
368372
{
369373
char *hostname;
374+
#ifndef NO_DNS
370375
struct dns_qcache *c;
371376
int tries = 8;
377+
#endif
372378

373379
if (!(hostname = local_hostname())) return NULL;
380+
#ifdef NO_DNS
381+
return hostname;
382+
#else
374383
if (!do_res_init()) return NULL;
375384

376385
while (tries-- > 0) {
@@ -381,8 +390,10 @@ int tries = 8;
381390

382391
fprintf(stderr, "Too many CNAMEs encountered while querying local hostname\n");
383392
return NULL;
393+
#endif
384394
}
385395

396+
#ifndef NO_DNS
386397
char *
387398
soa_mname(char *host)
388399
{
@@ -398,3 +409,4 @@ struct dns_qcache *c;
398409
}
399410
return NULL;
400411
}
412+
#endif

dnsupdate.c

+24-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ static int
2020
update_with_list(struct ipl *todo, int verbose, char *override_hostname, char **argv)
2121
{
2222
char *hostname;
23+
#ifndef NO_DNS
2324
char *server;
25+
#endif
2426
int hostname_len, n;
2527
int total_len, written, pid;
2628
int pipefd[2];
@@ -43,6 +45,7 @@ char ipbuf[64];
4345
return 0;
4446
}
4547

48+
#ifndef NO_DNS
4649
if (!(server = soa_mname(hostname))) {
4750
fprintf(stderr, "DNS update: cannot find server to which to send update\n");
4851
free(hostname);
@@ -53,10 +56,16 @@ char ipbuf[64];
5356
free(hostname);
5457
return 0;
5558
}
59+
#endif
5660

5761
hostname_len = strlen(hostname);
5862
/* "server " + host + " 53\n" + blank line at the end */
59-
total_len = 7 + strlen(server) + 4 + 1;
63+
total_len =
64+
#ifdef NO_DNS
65+
0;
66+
#else
67+
7 + strlen(server) + 4 + 1;
68+
#endif
6069
for (cur = todo; cur; cur = cur->next) {
6170
/* "update delete " + host + " " + ttl + " aaaa (ffff:){7}ffff\n" */
6271
total_len += 14 + hostname_len + 1 + 12 + 46;
@@ -65,12 +74,18 @@ char ipbuf[64];
6574
if (!(buf = malloc(total_len))) {
6675
fprintf(stderr, "DNS update: malloc failure\n");
6776
free(hostname);
77+
#ifndef NO_DNS
6878
free(server);
79+
#endif
6980
return 0;
7081
}
7182

83+
#ifdef NO_DNS
84+
p = buf;
85+
#else
7286
sprintf(buf, "server %s 53\n", server);
7387
p = buf + strlen(buf);
88+
#endif
7489

7590
for (cur = todo; cur; cur = cur->next) {
7691
if (cur->ttl == -2) {
@@ -102,7 +117,9 @@ char ipbuf[64];
102117
perror("DNS update: pipe");
103118
free(buf);
104119
free(hostname);
120+
#ifndef NO_DNS
105121
free(server);
122+
#endif
106123
return 0;
107124
}
108125

@@ -112,7 +129,9 @@ char ipbuf[64];
112129
close(pipefd[1]);
113130
free(buf);
114131
free(hostname);
132+
#ifndef NO_DNS
115133
free(server);
134+
#endif
116135
return 0;
117136
}
118137

@@ -138,7 +157,9 @@ char ipbuf[64];
138157
close(pipefd[1]);
139158
free(buf);
140159
free(hostname);
160+
#ifndef NO_DNS
141161
free(server);
162+
#endif
142163
return 0;
143164
}
144165
written += n;
@@ -147,7 +168,9 @@ char ipbuf[64];
147168

148169
free(buf);
149170
free(hostname);
171+
#ifndef NO_DNS
150172
free(server);
173+
#endif
151174

152175
for (;;) {
153176
while (waitpid(pid, &n, 0) < 0) sleep(1);

watchip.c

+31-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <string.h>
55
#include <errno.h>
66
#include <sys/socket.h>
7+
#include <linux/types.h>
78
#include <linux/netlink.h>
89
#include <linux/rtnetlink.h>
910
#include <arpa/inet.h>
@@ -461,10 +462,13 @@ int ttl = -2;
461462
}
462463
}
463464
if (ttl == -2) {
464-
if (ifa->ifa_family == AF_INET6) {
465-
return 1; /* no lifetime information -- ignore address */
466-
} else {
465+
/* no lifetime information -- use default TTL if there is one */
466+
if (w->default_ttl >= 0) {
467+
/* For IPv4, a default TTL should always be supplied */
467468
ttl = w->default_ttl;
469+
} else {
470+
/* else ignore the address */
471+
return 1;
468472
}
469473
}
470474
if (!rta_addr) return 1;
@@ -653,9 +657,30 @@ int rcvbuf = 32768;
653657
bindaddr.nl_family = AF_NETLINK;
654658
bindaddr.nl_groups = 0;
655659

656-
if (((w->filter_sense) != 0) && (w->filter)) bindaddr.nl_groups |= 1 << (RTNLGRP_LINK-1);
657-
if (w->filter6) bindaddr.nl_groups |= 1 << (RTNLGRP_IPV6_IFADDR-1);
658-
if (w->filter4) bindaddr.nl_groups |= 1 << (RTNLGRP_IPV4_IFADDR-1);
660+
if (((w->filter_sense) != 0) && (w->filter)) bindaddr.nl_groups |=
661+
#if defined(RTNLGRP_LINK)
662+
1 << (RTNLGRP_LINK-1);
663+
#elif defined(RTMGRP_LINK)
664+
RTMGRP_LINK;
665+
#else
666+
#error "Need either RTNLGRP_LINK or RTMGRP_LINK defined"
667+
#endif
668+
if (w->filter6) bindaddr.nl_groups |=
669+
#if defined(RTNLGRP_IPV6_IFADDR)
670+
1 << (RTNLGRP_IPV6_IFADDR-1);
671+
#elif defined(RTMGRP_IPV6_IFADDR)
672+
RTMGRP_IPV6_IFADDR;
673+
#else
674+
#error "Need either RTNLGRP_IPV6_IFADDR or RTMGRP_IPV6_IFADDR defined"
675+
#endif
676+
if (w->filter4) bindaddr.nl_groups |=
677+
#if defined(RTNLGRP_IPV4_IFADDR)
678+
1 << (RTNLGRP_IPV4_IFADDR-1);
679+
#elif defined(RTMGRP_IPV4_IFADDR)
680+
RTMGRP_IPV4_IFADDR;
681+
#else
682+
#error "Need either RTNLGRP_IPV4_IFADDR or RTMGRP_IPV4_IFADDR defined"
683+
#endif
659684

660685
if (bind(w->netlink_socket, (struct sockaddr *)(&bindaddr), sizeof(bindaddr)) < 0) {
661686
perror("bind(..RTNLGRP_IPV4_IFADDR and/or RTNLGRP_IPV6_IFADDR..)");

0 commit comments

Comments
 (0)