Ticket #1841: dhcp-dns-revised.diff
File dhcp-dns-revised.diff, 3.0 KB (added by Sebastien Bourdeauducq, on 02/24/12 at 21:13:25) |
---|
-
cpukit/libnetworking/rtems/rtems_dhcp.c
commit efedf0ad42d7d8989b62ec7c158b0a0a1f3b4197 Author: Sebastien Bourdeauducq <sebastien@milkymist.org> Date: Fri Feb 24 23:04:56 2012 +0100 Fix incorrect processing of DNS info from DHCP (revised patch) diff --git a/cpukit/libnetworking/rtems/rtems_dhcp.c b/cpukit/libnetworking/rtems/rtems_dhcp.c index 285ce1e..4039a48 100644
a b static const char dhcp_request_parameters[5] = { DHCP_SUBNET, 187 187 DHCP_DNS, 188 188 DHCP_HOST, 189 189 DHCP_DOMAIN_NAME }; 190 #define NUM_NAMESERVERS \ 191 (sizeof rtems_bsdnet_config.name_server / sizeof rtems_bsdnet_config.name_server[0]) 192 static struct in_addr rtems_dhcpd_nameserver[NUM_NAMESERVERS]; 193 static int rtems_dhcpd_nameserver_count = 0; 194 195 /* 196 * Clean any DNS entries add by a DHCP request. 197 */ 198 static void 199 clean_dns_entries (void) 200 { 201 int e; 202 for (e = 0; e < rtems_dhcpd_nameserver_count; ++e) 203 { 204 int n; 205 for (n = 0; n < rtems_bsdnet_nameserver_count; ++ n) 206 { 207 if (memcmp (&rtems_dhcpd_nameserver[e], &rtems_bsdnet_nameserver[n], 4) == 0) 208 { 209 if (n < (NUM_NAMESERVERS - 1)) 210 memmove (&rtems_bsdnet_nameserver[n], 211 &rtems_bsdnet_nameserver[n + 1], 212 (NUM_NAMESERVERS - n - 1) * 4); 213 --rtems_bsdnet_nameserver_count; 214 } 215 } 216 } 217 rtems_dhcpd_nameserver_count = 0; 218 } 190 219 191 220 /* 192 221 * Format an IP address in dotted decimal. … … process_options (unsigned char *optbuf, int optbufSize) 345 374 { 346 375 int dlen = 0; 347 376 while ((dlen < len) && 348 (rtems_bsdnet_nameserver_count < 349 sizeof rtems_bsdnet_config.name_server / 350 sizeof rtems_bsdnet_config.name_server[0])) 377 (rtems_dhcpd_nameserver_count < NUM_NAMESERVERS) && 378 (rtems_bsdnet_nameserver_count < NUM_NAMESERVERS)) 351 379 { 380 memcpy (&rtems_dhcpd_nameserver 381 [rtems_dhcpd_nameserver_count], p + dlen, 4); 382 rtems_dhcpd_nameserver_count++; 352 383 memcpy (&rtems_bsdnet_nameserver 353 384 [rtems_bsdnet_nameserver_count], p + dlen, 4); 354 385 rtems_bsdnet_nameserver_count++; … … dhcp_task (rtems_task_argument _sdl) 725 756 continue; 726 757 } 727 758 759 /* 760 * We have an ack. Clear the DNS entries that have been assigned by a previous 761 * DHCP request. 762 */ 763 clean_dns_entries (); 764 765 /* 766 * Process this requests options. 767 */ 728 768 process_options (&dhcp_req.vend[4], sizeof (dhcp_req.vend) - 4); 729 769 730 770 if (dhcp_message_type != DHCP_ACK) … … dhcp_init (int update_files) 839 879 struct sockaddr_dl *sdl = NULL; 840 880 struct proc *procp = NULL; 841 881 882 clean_dns_entries(); 883 842 884 /* 843 885 * If we are to update the files create the root 844 886 * file structure.