patchlwIP - A Lightweight TCP/IP stack - Patches: patch #8361, Add support for NTP option in DHCP

 
 

You are not allowed to post comments on this tracker with your current authentication level.

patch #8361: Add support for NTP option in DHCP

Submitted by:  Claudius Zingerli <zeuz>
Submitted on:  Wed 26 Feb 2014 01:28:20 PM UTC  
 
Category:  DHCP Priority:  5 - Normal
Status:  Done Privacy:  Public
Assigned to:  Simon Goldschmidt <goldsimon> Open/Closed:  Closed
Planned Release:  None

Mon 16 Feb 2015 08:28:42 PM UTC, comment #4: 

Done, although with tiny changes (one callback for all addresses returned, changed define names)

Simon Goldschmidt <goldsimon>
Project AdministratorIn charge of this item.
Thu 19 Jun 2014 09:58:12 PM UTC, comment #3: 

Done
Tried to follow the same actions as for DNS so the code is homogeneous.

Requires an external function: ntp_setserver(), prototyped and explained in dhcp.c

See patch_dhcp.zip

(file #31583)

Sergio R. Caprile <scaprile>
Fri 13 Jun 2014 02:48:05 PM UTC, comment #2: 

This patch stores NTP server addresses in a local DHCP struct.
I think we should follow the same operations as for DNS servers:

  • The DHCP server gets the offered servers and calls sntp_addserver() for each one.
    • Pros: the DHCP module does not need to know about SNTP of the amount of memory for servers, it just calls the add function.
    • Cons: the dhcp module must know the prototype for this function and sntp.c is not part of the lwIP tree
  • The SNTP module provides a new sntp_addserver() function, similar to the current DNS module function.
  • Pros: SNTP_MAX_SERVERS is an SNTP module macro instead of NTP_MAX_SERVERS a DHCP module macro.

I can do the changes based on the OP uploaded patch, and submit a new patch, if you guys agree.

Sergio R. Caprile <scaprile>
Wed 26 Feb 2014 02:07:51 PM UTC, comment #1: 

Hello Claudius ! :)

Please use unified diff, with "diff -Nu", diff without context are useless.

And please use the bug tracker file upload feature so the patch is not damaged while converted to HTML.

Sylvain

Sylvain Rochet <gradator>
Project Member
Wed 26 Feb 2014 01:28:20 PM UTC, original submission:  

I added support for the NTP Server option in the DHCP request.

It is enabled if USE_DHCP_NTP is set to 1 in the config file. It requests up to NTP_MAX_SERVERS (default: 2) IP addresses for NTP servers. It does not support host names yet.

(Below is a diff of the original source tree () and my version. I have changed more than just NTP support and removed the other changes from the diff file as far as possible (Not so in opt.h, to not change line numbers))

diff -rwd v1.4.1/src/core/dhcp.c v1.4.1orig/src/core/dhcp.c
124,125c124
< #define DHCP_OPTION_IDX_NTP_SERVER  8
< #define DHCP_OPTION_IDX_DNS_SERVER  9
---

> #define DHCP_OPTION_IDX_DNS_SERVER  8

306,308d304
< #if LWIP_DHCP_NTP
<     dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, 5/*num options*/);
< #else
310d305
< #endif
315,317d309
< #if LWIP_DHCP_NTP
<     dhcp_option_byte(dhcp, DHCP_OPTION_NTP);
< #endif
519c511
< #if LWIP_DNS || LWIP_DHCP_NTP
---

> #if LWIP_DNS

526,531d517
< #if LWIP_DHCP_NTP
<   for (n=0;n<NTP_MAX_SERVERS;++n)
<   {
<         ip_addr_set_zero(&dhcp->ntp_ip_addr[n]);
<   }
< #endif
582,589d567
< #if LWIP_DHCP_NTP
<   n = 0;
<   while(dhcp_option_given(dhcp, DHCP_OPTION_IDX_NTP_SERVER + n) && (n < NTP_MAX_SERVERS)) {
<     ip4_addr_set_u32(&(dhcp->ntp_ip_addr[n]), htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_NTP_SERVER + n)));
<     n++;
<   }
< #endif
<
910,912d887
< #if LWIP_DHCP_NTP
<     dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, 5/*num options*/);
< #else
914d888
< #endif
919,921c893
< #if LWIP_DHCP_NTP
<     dhcp_option_byte(dhcp, DHCP_OPTION_NTP);
< #endif
---

>

1450,1455d1421
<         break;
<       case(DHCP_OPTION_NTP):
<         LWIP_ERROR("len == 4", len % 4 == 0, return ERR_VAL;);
<         decode_len = LWIP_MIN(len, 4 * DNS_MAX_SERVERS);
<               LWIP_ERROR("len >= decode_len", len >= decode_len, return ERR_VAL;);
<               decode_idx = DHCP_OPTION_IDX_NTP_SERVER;
diff -rwd v1.4.1/src/include/lwip/dhcp.h v1.4.1orig/src/include/lwip/dhcp.h
56,58d55
< #if LWIP_DHCP_NTP
<   ip_addr_t ntp_ip_addr[NTP_MAX_SERVERS];
< #endif
210d206
< #define DHCP_OPTION_NTP 42
diff -rwd v1.4.1/src/include/lwip/opt.h v1.4.1orig/src/include/lwip/opt.h
48,51d47
< //Use hardware based random number generator.
< #ifndef LWIP_USE_HW_RAND
< #define LWIP_USE_HW_RAND              0
< #endif
696,712d691
< #ifndef LWIP_DHCP_NTP
< #define LWIP_DHCP_NTP                  0
< #endif
<
< /* The maximum of NTP servers parsed from DHCP response*/
< #ifndef NTP_MAX_SERVERS
< #define NTP_MAX_SERVERS                 2
< #endif
<
< /**
<  * NTP_DEBUG: Enable debugging in NTP_Task.c.
<  */
< #ifndef NTP_DEBUG
< #define NTP_DEBUG                       LWIP_DBG_OFF
< #endif
<
<

Claudius Zingerli <zeuz>

 

Attached Files
file #31583:  patch_dhcp.zip added by scaprile (2KiB - application/zip)
file #30758:  dhcp.c.diff added by zeuz (4KiB - application/octet-stream - Unified diffs of the three files affected)
file #30759:  opt.h.diff added by zeuz (695B - application/octet-stream - Unified diffs of the three files affected)
file #30760:  dhcp.h.diff added by zeuz (666B - application/octet-stream - Unified diffs of the three files affected)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by goldsimon (Posted a comment)
  • -email is unavailable- added by gradator (Posted a comment)
  • -email is unavailable- added by zeuz (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

     

     

    Follow 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-02-16 goldsimon StatusNone => Done
        Assigned toNone => goldsimon
        Open/ClosedOpen => Closed
    2014-06-19 scaprile Attached File- => Added patch_dhcp.zip, #31583
    2014-03-03 zeuz Carbon-CopyRemoved zeuz => -
    2014-03-03 zeuz Attached File- => Added dhcp.c.diff, #30758
        Attached File- => Added opt.h.diff, #30759
        Attached File- => Added dhcp.h.diff, #30760
    2014-02-26 zeuz Carbon-Copy- => Added zeuz

    Back to the top


    Powered by Savane 3.5