net/context: Add a way to set/get ttl/hop_limit from net_context

Since net_context_sendto_new() does not take a net_pkt anymore, the only
way to set net_pkt's ttl/hop_limit is to pass it through net_context.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
Tomasz Bursztyka 2019-02-15 09:45:09 +01:00 committed by Anas Nashif
parent f72b113876
commit 6435553dea
2 changed files with 33 additions and 0 deletions

View file

@ -293,6 +293,12 @@ struct net_context {
/** Network interface assigned to this context */
s8_t iface;
/** IPv6 hop limit or IPv4 ttl for packets sent via this context. */
union {
u8_t ipv6_hop_limit;
u8_t ipv4_ttl;
};
};
static inline bool net_context_is_used(struct net_context *context)
@ -491,6 +497,28 @@ static inline void net_context_set_iface(struct net_context *context,
context->iface = net_if_get_by_iface(iface);
}
static inline u8_t net_context_get_ipv4_ttl(struct net_context *context)
{
return context->ipv4_ttl;
}
static inline void net_context_set_ipv4_ttl(struct net_context *context,
u8_t ttl)
{
context->ipv4_ttl = ttl;
}
static inline u8_t net_context_get_ipv6_hop_limit(struct net_context *context)
{
return context->ipv6_hop_limit;
}
static inline void net_context_set_ipv6_hop_limit(struct net_context *context,
u8_t hop_limit)
{
context->ipv6_hop_limit = hop_limit;
}
/**
* @brief Get network context.
*

View file

@ -875,6 +875,8 @@ int net_context_create_ipv4_new(struct net_context *context,
}
}
net_pkt_set_ipv4_ttl(pkt, net_context_get_ipv4_ttl(context));
return net_ipv4_create_new(pkt, src, dst);
}
#endif /* CONFIG_NET_IPV4 */
@ -921,6 +923,9 @@ int net_context_create_ipv6_new(struct net_context *context,
(struct in6_addr *)dst);
}
net_pkt_set_ipv6_hop_limit(pkt,
net_context_get_ipv6_hop_limit(context));
return net_ipv6_create_new(pkt, src, dst);
}
#endif /* CONFIG_NET_IPV6 */