net/dhcpv4: Move timers inside the net_if dhcpv4 context

The dhcpv4 state machine has a dedicated context within each net_if
structure.  For reasons unknown the timers used by the dhcpv4 state
machine have been placed in net_if outside of the dhcpv4 context area.
Relocate them into the dhcpv4 context.

Change-Id: I0531f493610dffda9ca9208993597a5665bde997
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
This commit is contained in:
Marcus Shawcroft 2017-02-14 20:51:25 +00:00 committed by Jukka Rissanen
commit 8df38dc55f
2 changed files with 22 additions and 19 deletions

View file

@ -288,13 +288,16 @@ struct net_if {
/** Number of attempts made for REQUEST and RENEWAL messages */
uint8_t attempts;
/** Timer for DHCPv4 Client requests (DISCOVER,
* REQUEST or RENEWAL)
*/
struct k_delayed_work timer;
/** T1 (Renewal) timer */
struct k_delayed_work t1_timer;
} dhcpv4;
/** Timer for DHCPv4 Client requests (DISCOVER, REQUEST or RENEWAL) */
struct k_delayed_work dhcpv4_timeout;
/** T1 (Renewal) timer */
struct k_delayed_work dhcpv4_t1_timer;
#endif
} __net_if_align;

View file

@ -175,8 +175,8 @@ static inline void unset_dhcpv4_on_iface(struct net_if *iface)
memset(iface->dhcpv4.server_id.s4_addr, 0, 4);
memset(iface->dhcpv4.server_id.s4_addr, 0, 4);
memset(iface->dhcpv4.requested_ip.s4_addr, 0, 4);
k_delayed_work_cancel(&iface->dhcpv4_timeout);
k_delayed_work_cancel(&iface->dhcpv4_t1_timer);
k_delayed_work_cancel(&iface->dhcpv4.timer);
k_delayed_work_cancel(&iface->dhcpv4.t1_timer);
}
/* Add magic cookie to DCHPv4 messages */
@ -406,8 +406,8 @@ static void send_request(struct net_if *iface, bool renewal)
net_dhcpv4_state_name(iface->dhcpv4.state),
iface->dhcpv4.xid, timeout);
k_delayed_work_init(&iface->dhcpv4_timeout, dhcpv4_timeout);
k_delayed_work_submit(&iface->dhcpv4_timeout, timeout * MSEC_PER_SEC);
k_delayed_work_init(&iface->dhcpv4.timer, dhcpv4_timeout);
k_delayed_work_submit(&iface->dhcpv4.timer, timeout * MSEC_PER_SEC);
iface->dhcpv4.attempts++;
return;
@ -452,8 +452,8 @@ static void send_discover(struct net_if *iface)
net_dhcpv4_state_name(iface->dhcpv4.state),
iface->dhcpv4.xid, timeout);
k_delayed_work_init(&iface->dhcpv4_timeout, dhcpv4_timeout);
k_delayed_work_submit(&iface->dhcpv4_timeout, timeout * MSEC_PER_SEC);
k_delayed_work_init(&iface->dhcpv4.timer, dhcpv4_timeout);
k_delayed_work_submit(&iface->dhcpv4.timer, timeout * MSEC_PER_SEC);
iface->dhcpv4.attempts++;
return;
@ -469,7 +469,7 @@ fail:
static void dhcpv4_timeout(struct k_work *work)
{
struct net_if *iface = CONTAINER_OF(work, struct net_if,
dhcpv4_timeout);
dhcpv4.timer);
NET_DBG("state=%s", net_dhcpv4_state_name(iface->dhcpv4.state));
if (!iface) {
@ -526,7 +526,7 @@ static void dhcpv4_timeout(struct k_work *work)
static void dhcpv4_t1_timeout(struct k_work *work)
{
struct net_if *iface = CONTAINER_OF(work, struct net_if,
dhcpv4_t1_timer);
dhcpv4.t1_timer);
NET_DBG("");
@ -706,7 +706,7 @@ static inline void handle_dhcpv4_reply(struct net_if *iface,
}
/* Send DHCPv4 Request Message */
k_delayed_work_cancel(&iface->dhcpv4_timeout);
k_delayed_work_cancel(&iface->dhcpv4.timer);
iface->dhcpv4.attempts = 0;
send_request(iface, false);
@ -720,7 +720,7 @@ static inline void handle_dhcpv4_reply(struct net_if *iface,
return;
}
k_delayed_work_cancel(&iface->dhcpv4_timeout);
k_delayed_work_cancel(&iface->dhcpv4.timer);
iface->dhcpv4.attempts = 0;
@ -755,8 +755,8 @@ static inline void handle_dhcpv4_reply(struct net_if *iface,
timeout);
/* Start renewal time */
k_delayed_work_init(&iface->dhcpv4_t1_timer, dhcpv4_t1_timeout);
k_delayed_work_submit(&iface->dhcpv4_t1_timer,
k_delayed_work_init(&iface->dhcpv4.t1_timer, dhcpv4_t1_timeout);
k_delayed_work_submit(&iface->dhcpv4.t1_timer,
timeout * MSEC_PER_SEC);
}
}
@ -896,6 +896,6 @@ void net_dhcpv4_start(struct net_if *iface)
NET_DBG("enter state=%s timeout=%"PRIu32"s",
net_dhcpv4_state_name(iface->dhcpv4.state), timeout);
k_delayed_work_init(&iface->dhcpv4_timeout, dhcpv4_timeout);
k_delayed_work_submit(&iface->dhcpv4_timeout, timeout * MSEC_PER_SEC);
k_delayed_work_init(&iface->dhcpv4.timer, dhcpv4_timeout);
k_delayed_work_submit(&iface->dhcpv4.timer, timeout * MSEC_PER_SEC);
}