1
0
mirror of git://projects.qi-hardware.com/wernermisc.git synced 2024-12-21 05:17:41 +02:00
wernermisc/m1/patches/rtems/fix-dns-in-dhcp.patch
Werner Almesberger fe7a334808 M1 build process update
- synchronized patch set with
  http://www.milkymist.org/wiki/index.php?title=Pending_RTEMS_PRs

- switched from using RTEMS CVS to git

- commented out patches already applied in git

- updated softusb-input.h update process
2012-02-25 20:35:09 -03:00

88 lines
3.0 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)
diff --git a/cpukit/libnetworking/rtems/rtems_dhcp.c b/cpukit/libnetworking/rtems/rtems_dhcp.c
index 285ce1e..4039a48 100644
--- a/cpukit/libnetworking/rtems/rtems_dhcp.c
+++ b/cpukit/libnetworking/rtems/rtems_dhcp.c
@@ -187,6 +187,35 @@ static const char dhcp_request_parameters[5] = { DHCP_SUBNET,
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.
@@ -345,10 +374,12 @@ process_options (unsigned char *optbuf, int optbufSize)
{
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++;
@@ -725,6 +756,15 @@ dhcp_task (rtems_task_argument _sdl)
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)
@@ -839,6 +879,8 @@ dhcp_init (int update_files)
struct sockaddr_dl *sdl = NULL;
struct proc *procp = NULL;
+ clean_dns_entries();
+
/*
* If we are to update the files create the root
* file structure.