1
0
mirror of git://projects.qi-hardware.com/wernermisc.git synced 2024-11-23 23:25:53 +02:00
wernermisc/m1/patches/rtems/fix-dns-in-dhcp.patch
2012-05-14 12:37:06 +08:00

88 lines
2.9 KiB
Diff

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)
Index: rtems/cpukit/libnetworking/rtems/rtems_dhcp.c
===================================================================
--- rtems.orig/cpukit/libnetworking/rtems/rtems_dhcp.c 2012-05-14 12:34:47.363444000 +0800
+++ rtems/cpukit/libnetworking/rtems/rtems_dhcp.c 2012-05-14 12:35:04.922660000 +0800
@@ -205,6 +205,35 @@
DHCP_DNS,
DHCP_HOST,
DHCP_DOMAIN_NAME };
+#define NUM_NAMESERVERS \
+ (sizeof rtems_bsdnet_config.name_server / sizeof rtems_bsdnet_config.name_server[0])
+static struct in_addr rtems_dhcpd_nameserver[NUM_NAMESERVERS];
+static int rtems_dhcpd_nameserver_count = 0;
+
+/*
+ * Clean any DNS entries add by a DHCP request.
+ */
+static void
+clean_dns_entries (void)
+{
+ int e;
+ for (e = 0; e < rtems_dhcpd_nameserver_count; ++e)
+ {
+ int n;
+ for (n = 0; n < rtems_bsdnet_nameserver_count; ++ n)
+ {
+ if (memcmp (&rtems_dhcpd_nameserver[e], &rtems_bsdnet_nameserver[n], 4) == 0)
+ {
+ if (n < (NUM_NAMESERVERS - 1))
+ memmove (&rtems_bsdnet_nameserver[n],
+ &rtems_bsdnet_nameserver[n + 1],
+ (NUM_NAMESERVERS - n - 1) * 4);
+ --rtems_bsdnet_nameserver_count;
+ }
+ }
+ }
+ rtems_dhcpd_nameserver_count = 0;
+}
/*
* Format an IP address in dotted decimal.
@@ -363,10 +392,12 @@
{
int dlen = 0;
while ((dlen < len) &&
- (rtems_bsdnet_nameserver_count <
- sizeof rtems_bsdnet_config.name_server /
- sizeof rtems_bsdnet_config.name_server[0]))
+ (rtems_dhcpd_nameserver_count < NUM_NAMESERVERS) &&
+ (rtems_bsdnet_nameserver_count < NUM_NAMESERVERS))
{
+ memcpy (&rtems_dhcpd_nameserver
+ [rtems_dhcpd_nameserver_count], p + dlen, 4);
+ rtems_dhcpd_nameserver_count++;
memcpy (&rtems_bsdnet_nameserver
[rtems_bsdnet_nameserver_count], p + dlen, 4);
rtems_bsdnet_nameserver_count++;
@@ -743,6 +774,15 @@
continue;
}
+ /*
+ * We have an ack. Clear the DNS entries that have been assigned by a previous
+ * DHCP request.
+ */
+ clean_dns_entries ();
+
+ /*
+ * Process this requests options.
+ */
process_options (&dhcp_req.vend[4], sizeof (dhcp_req.vend) - 4);
if (dhcp_message_type != DHCP_ACK)
@@ -857,6 +897,8 @@
struct sockaddr_dl *sdl = NULL;
struct proc *procp = NULL;
+ clean_dns_entries();
+
/*
* If we are to update the files create the root
* file structure.