Ticket #2877: fix-2877.patch

File fix-2877.patch, 4.7 KB (added by Stavros Passas, on Jan 20, 2017 at 9:33:28 AM)
  • cpukit/libnetworking/nfs/bootp_subr.c

    From 358eb88e87c4ec37ed4d1dc37493bc5d0442e029 Mon Sep 17 00:00:00 2001
    From: Stavros Passas <stavros.passas@movidius.com>
    Date: Fri, 20 Jan 2017 09:22:46 +0000
    Subject: [PATCH] Fix DHCP client protocol. Fixes #2877
    
    ---
     cpukit/libnetworking/nfs/bootp_subr.c   | 10 ++++++++--
     cpukit/libnetworking/rtems/bootp.h      |  4 +++-
     cpukit/libnetworking/rtems/rtems_dhcp.c | 28 +++++++++++++++++++++++++---
     3 files changed, 36 insertions(+), 6 deletions(-)
    
    diff --git a/cpukit/libnetworking/nfs/bootp_subr.c b/cpukit/libnetworking/nfs/bootp_subr.c
    index 911e322..e04eb11 100644
    a b int 
    282282bootpc_call(
    283283     struct bootp_packet *call,
    284284     struct bootp_packet *reply,        /* output */
    285      struct proc *procp)
     285     struct proc *procp,
     286     char * exp_vend,
     287     unsigned int exp_vend_len)
    286288{
    287289        struct socket *so;
    288290        struct sockaddr_in *sin;
    bootpc_call( 
    448450                        if (bcmp(reply->chaddr,call->chaddr,call->hlen))
    449451                          continue;
    450452
     453                        if (exp_vend && exp_vend_len>0 &&
     454                            bcmp(exp_vend, reply->vend, exp_vend_len))
     455                          continue;
     456
    451457                        goto gotreply;  /* break two levels */
    452458
    453459                } /* while secs */
    bootpc_init(bool update_files, bool forever) 
    10491055    call.secs = 0;
    10501056    call.flags = htons(0x8000); /* We need an broadcast answer */
    10511057 
    1052     error = bootpc_call(&call,&reply,procp);
     1058    error = bootpc_call(&call,&reply,procp, NULL, 0);
    10531059 
    10541060    if (!error)
    10551061      break;
  • cpukit/libnetworking/rtems/bootp.h

    diff --git a/cpukit/libnetworking/rtems/bootp.h b/cpukit/libnetworking/rtems/bootp.h
    index d8eeb76..07d69ec 100644
    a b bool bootpc_init(bool, bool); 
    2121int bootpc_call(
    2222     struct bootp_packet *call,
    2323     struct bootp_packet *reply,
    24      struct proc *procp);
     24     struct proc *procp,
     25     char *exp_vend,
     26     unsigned int exp_vend_len);
    2527int bootpc_fakeup_interface(struct ifreq *ireq,
    2628                                    struct socket *so,
    2729                                    struct proc *procp);
  • cpukit/libnetworking/rtems/rtems_dhcp.c

    diff --git a/cpukit/libnetworking/rtems/rtems_dhcp.c b/cpukit/libnetworking/rtems/rtems_dhcp.c
    index 74ea870..29af727 100644
    a b dhcp_task (rtems_task_argument _sdl) 
    760760      /*
    761761       * Send the Request.
    762762       */
    763       error = bootpc_call ((struct bootp_packet *)&call, (struct bootp_packet *)&dhcp_req, procp);
     763      error = bootpc_call ((struct bootp_packet *)&call,
     764                           (struct bootp_packet *)&dhcp_req, procp, NULL, 0);
    764765      if (error) {
    765766        rtems_bsdnet_semaphore_release ();
    766767        printf ("DHCP call failed -- error %d", error);
    dhcp_init (int update_files) 
    901902  struct ifaddr        *ifa;
    902903  struct sockaddr_dl   *sdl = NULL;
    903904  struct proc          *procp = NULL;
     905  char expected_dhcp_payload[7];
    904906
    905907  clean_dns_entries();
    906908
    dhcp_init (int update_files) 
    957959    return -1;
    958960  }
    959961
     962
    960963  /*
    961964   * Build the DHCP Discover
    962965   */
    963966  dhcp_discover_req (&call, sdl, &xid);
    964967
    965968  /*
     969   * Expect a DHCP offer as response to DHCP discover
     970   */
     971  memcpy(expected_dhcp_payload, dhcp_magic_cookie, sizeof(dhcp_magic_cookie));
     972  expected_dhcp_payload[sizeof(dhcp_magic_cookie)  ]=0x35; // DHCP
     973  expected_dhcp_payload[sizeof(dhcp_magic_cookie)+1]=0x01; // Length : 1
     974  expected_dhcp_payload[sizeof(dhcp_magic_cookie)+2]=0x02; // DHCP_OFFER
     975
     976  /*
    966977   * Send the Discover.
    967978   */
    968   error = bootpc_call ((struct bootp_packet *)&call, (struct bootp_packet *)&reply, procp);
     979  error = bootpc_call ((struct bootp_packet *)&call,
     980                       (struct bootp_packet *)&reply, procp,
     981                       expected_dhcp_payload, sizeof(expected_dhcp_payload));
    969982  if (error) {
    970983    printf ("BOOTP call failed -- %s\n", strerror(error));
    971984    soclose (so);
    dhcp_init (int update_files) 
    9901003  }
    9911004
    9921005  /*
     1006   * Expect a DHCP_ACK as response to the DHCP REQUEST
     1007   * No need to reinitialize the whole expected_dhcp_payload variable,
     1008   * header and first two bytes of the payload are filled from DHCP offer
     1009   */
     1010  expected_dhcp_payload[sizeof(dhcp_magic_cookie)+2]=0x05; // DHCP_ACK
     1011
     1012  /*
    9931013   * Send a DHCP REQUEST
    9941014   */
    9951015  dhcp_request_req (&call, &reply, sdl, true);
    9961016
    997   error = bootpc_call ((struct bootp_packet *)&call, (struct bootp_packet *)&reply, procp);
     1017  error = bootpc_call ((struct bootp_packet *)&call,
     1018                       (struct bootp_packet *)&reply, procp,
     1019                       expected_dhcp_payload, sizeof(expected_dhcp_payload));
    9981020  if (error) {
    9991021    printf ("BOOTP call failed -- %s\n", strerror(error));
    10001022    soclose (so);