Notice: We have migrated to GitLab launching 2024-05-01 see here: https://gitlab.rtems.org/

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)

New patch

  • 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, 
    187187                                                         DHCP_DNS,
    188188                                                         DHCP_HOST,
    189189                                                         DHCP_DOMAIN_NAME };
     190#define NUM_NAMESERVERS \
     191  (sizeof rtems_bsdnet_config.name_server / sizeof rtems_bsdnet_config.name_server[0])
     192static struct in_addr rtems_dhcpd_nameserver[NUM_NAMESERVERS];
     193static int rtems_dhcpd_nameserver_count = 0;
     194
     195/*
     196 * Clean any DNS entries add by a DHCP request.
     197 */
     198static void
     199clean_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}
    190219
    191220/*
    192221 * Format an IP address in dotted decimal.
    process_options (unsigned char *optbuf, int optbufSize) 
    345374        {
    346375          int dlen = 0;
    347376          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))
    351379          {
     380            memcpy (&rtems_dhcpd_nameserver
     381                    [rtems_dhcpd_nameserver_count], p + dlen, 4);
     382            rtems_dhcpd_nameserver_count++;
    352383            memcpy (&rtems_bsdnet_nameserver
    353384                    [rtems_bsdnet_nameserver_count], p + dlen, 4);
    354385            rtems_bsdnet_nameserver_count++;
    dhcp_task (rtems_task_argument _sdl) 
    725756        continue;
    726757      }
    727758
     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       */
    728768      process_options (&dhcp_req.vend[4], sizeof (dhcp_req.vend) - 4);
    729769
    730770      if (dhcp_message_type != DHCP_ACK)
    dhcp_init (int update_files) 
    839879  struct sockaddr_dl   *sdl = NULL;
    840880  struct proc          *procp = NULL;
    841881
     882  clean_dns_entries();
     883 
    842884  /*
    843885   * If we are to update the files create the root
    844886   * file structure.