nfs swap patch; bzip loader
[openwrt.git] / obsolete-buildroot / sources / dnsmasq1-openwrt.patch
1 diff -x CVS -urN dnsmasq-1.18/dhcp.c dnsmasq.old/dhcp.c
2 --- dnsmasq-1.18/dhcp.c 2003-11-05 08:30:20.000000000 -0600
3 +++ dnsmasq.old/dhcp.c 2004-01-05 23:40:11.000000000 -0600
4 @@ -15,14 +15,20 @@
5
6 #include "dnsmasq.h"
7
8 -static int next_token (char *token, int buffsize, FILE * fp);
9 +struct dhcpOfferedAddr {
10 + u_int8_t hostname[16];
11 + u_int8_t chaddr[16];
12 + u_int32_t yiaddr; /* network order */
13 + u_int32_t expires; /* host order */
14 +};
15
16 void load_dhcp(char *file, char *suffix, time_t now, char *hostname)
17 {
18 - char token[MAXTOK], *dot;
19 + char *dot;
20 struct all_addr host_address;
21 - time_t ttd, tts;
22 + time_t ttd;
23 FILE *fp = fopen (file, "r");
24 + struct dhcpOfferedAddr lease;
25
26 if (!fp)
27 {
28 @@ -34,154 +40,45 @@
29
30 /* remove all existing DHCP cache entries */
31 cache_unhash_dhcp();
32 -
33 - while ((next_token(token, MAXTOK, fp)))
34 - {
35 - if (strcmp(token, "lease") == 0)
36 - {
37 - hostname[0] = '\0';
38 - ttd = tts = (time_t)(-1);
39 -#ifdef HAVE_IPV6
40 - if (next_token(token, MAXTOK, fp) &&
41 - inet_pton(AF_INET, token, &host_address))
42 -#else
43 - if (next_token(token, MAXTOK, fp) &&
44 - (host_address.addr4.s_addr = inet_addr(token)) != (in_addr_t) -1)
45 -#endif
46 - {
47 - if (next_token(token, MAXTOK, fp) && *token == '{')
48 - {
49 - while (next_token(token, MAXTOK, fp) && *token != '}')
50 +
51 + while (fread(&lease, sizeof(lease), 1, fp)) {
52 + host_address.addr.addr4.s_addr = lease.yiaddr;
53 +
54 + strcpy(hostname,lease.hostname);
55 + if (lease.expires>(unsigned)now)
56 + ttd = lease.expires;
57 + else
58 + ttd = -1;
59 + dot = strchr(hostname, '.');
60 + if (suffix)
61 {
62 - if ((strcmp(token, "client-hostname") == 0) ||
63 - (strcmp(token, "hostname") == 0))
64 - {
65 - if (next_token(hostname, MAXDNAME, fp))
66 - if (!canonicalise(hostname))
67 - {
68 - *hostname = 0;
69 - syslog(LOG_ERR, "bad name in %s", file);
70 - }
71 - }
72 - else if ((strcmp(token, "ends") == 0) ||
73 - (strcmp(token, "starts") == 0))
74 - {
75 - struct tm lease_time;
76 - int is_ends = (strcmp(token, "ends") == 0);
77 - if (next_token(token, MAXTOK, fp) && /* skip weekday */
78 - next_token(token, MAXTOK, fp) && /* Get date from lease file */
79 - sscanf (token, "%d/%d/%d",
80 - &lease_time.tm_year,
81 - &lease_time.tm_mon,
82 - &lease_time.tm_mday) == 3 &&
83 - next_token(token, MAXTOK, fp) &&
84 - sscanf (token, "%d:%d:%d:",
85 - &lease_time.tm_hour,
86 - &lease_time.tm_min,
87 - &lease_time.tm_sec) == 3)
88 - {
89 - /* There doesn't seem to be a universally available library function
90 - which converts broken-down _GMT_ time to seconds-in-epoch.
91 - The following was borrowed from ISC dhcpd sources, where
92 - it is noted that it might not be entirely accurate for odd seconds.
93 - Since we're trying to get the same answer as dhcpd, that's just
94 - fine here. */
95 - static int months [11] = { 31, 59, 90, 120, 151, 181,
96 - 212, 243, 273, 304, 334 };
97 - time_t time = ((((((365 * (lease_time.tm_year - 1970) + /* Days in years since '70 */
98 - (lease_time.tm_year - 1969) / 4 + /* Leap days since '70 */
99 - (lease_time.tm_mon > 1 /* Days in months this year */
100 - ? months [lease_time.tm_mon - 2]
101 - : 0) +
102 - (lease_time.tm_mon > 2 && /* Leap day this year */
103 - !((lease_time.tm_year - 1972) & 3)) +
104 - lease_time.tm_mday - 1) * 24) + /* Day of month */
105 - lease_time.tm_hour) * 60) +
106 - lease_time.tm_min) * 60) + lease_time.tm_sec;
107 - if (is_ends)
108 - ttd = time;
109 - else
110 - tts = time; }
111 + if (dot)
112 + { /* suffix and lease has ending: must match */
113 + if (strcmp(dot+1, suffix) != 0)
114 + syslog(LOG_WARNING,
115 + "Ignoring DHCP lease for %s because it has an illegal domain part", hostname);
116 + else
117 + cache_add_dhcp_entry(hostname, &host_address, ttd, F_REVERSE);
118 }
119 - }
120 -
121 - /* missing info? */
122 - if (!*hostname)
123 - continue;
124 - if (ttd == (time_t)(-1))
125 - continue;
126 -
127 - /* infinite lease to is represented by -1 */
128 - /* This makes is to the lease file as
129 - start time one less than end time. */
130 - /* We use -1 as infinite in ttd */
131 - if ((tts != -1) && (ttd == tts - 1))
132 - ttd = (time_t)(-1);
133 - else if (ttd < now)
134 - continue;
135 -
136 - dot = strchr(hostname, '.');
137 - if (suffix)
138 - {
139 - if (dot)
140 - { /* suffix and lease has ending: must match */
141 - if (strcmp(dot+1, suffix) != 0)
142 - syslog(LOG_WARNING,
143 - "Ignoring DHCP lease for %s because it has an illegal domain part", hostname);
144 - else
145 - cache_add_dhcp_entry(hostname, &host_address, ttd, F_REVERSE);
146 - }
147 - else
148 - { /* suffix exists but lease has no ending - add lease and lease.suffix */
149 - cache_add_dhcp_entry(hostname, &host_address, ttd, 0);
150 - strncat(hostname, ".", MAXDNAME);
151 - strncat(hostname, suffix, MAXDNAME);
152 - hostname[MAXDNAME-1] = 0; /* in case strncat hit limit */
153 - /* Make FQDN canonical for reverse lookups */
154 - cache_add_dhcp_entry(hostname, &host_address, ttd, F_REVERSE);
155 - }
156 - }
157 - else
158 - { /* no suffix */
159 - if (dot) /* no lease ending allowed */
160 - syslog(LOG_WARNING,
161 - "Ignoring DHCP lease for %s because it has a domain part", hostname);
162 - else
163 - cache_add_dhcp_entry(hostname, &host_address, ttd, F_REVERSE);
164 - }
165 - }
166 - }
167 - }
168 - }
169 + else
170 + { /* suffix exists but lease has no ending - add lease and lease.suffix */
171 + cache_add_dhcp_entry(hostname, &host_address, ttd, 0);
172 + strncat(hostname, ".", MAXDNAME);
173 + strncat(hostname, suffix, MAXDNAME);
174 + hostname[MAXDNAME-1] = 0; /* in case strncat hit limit */
175 + /* Make FQDN canonical for reverse lookups */
176 + cache_add_dhcp_entry(hostname, &host_address, ttd, F_REVERSE);
177 + }
178 + }
179 + else
180 + { /* no suffix */
181 + if (dot) /* no lease ending allowed */
182 + syslog(LOG_WARNING,
183 + "Ignoring DHCP lease for %s because it has a domain part", hostname);
184 + else
185 + cache_add_dhcp_entry(hostname, &host_address, ttd, F_REVERSE);
186 + }
187 + }
188 fclose(fp);
189
190 }
191 -
192 -static int next_token (char *token, int buffsize, FILE * fp)
193 -{
194 - int c, count = 0;
195 - char *cp = token;
196 -
197 - while((c = getc(fp)) != EOF)
198 - {
199 - if (c == '#')
200 - do { c = getc(fp); } while (c != '\n' && c != EOF);
201 -
202 - if (c == ' ' || c == '\t' || c == '\n' || c == ';')
203 - {
204 - if (count)
205 - break;
206 - }
207 - else if ((c != '"') && (count<buffsize-1))
208 - {
209 - *cp++ = c;
210 - count++;
211 - }
212 - }
213 -
214 - *cp = 0;
215 - return count ? 1 : 0;
216 -}
217 -
218 -
219 -
This page took 0.056666 seconds and 5 git commands to generate.