net: Allow user to tweak IPv4 TTL per packet

User was able to tweak IPv6 hop-limit so introduce similar
feature for IPv4 Time-To-Live value.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2017-09-27 16:29:16 +03:00
parent eda6403850
commit c50d555c1e
2 changed files with 27 additions and 2 deletions

View file

@ -95,8 +95,15 @@ struct net_pkt {
u8_t family : 4; /* IPv4 vs IPv6 */
u8_t _unused : 3;
union {
/* IPv6 hop limit or IPv4 ttl for this network packet.
* The value is shared between IPv6 and IPv4.
*/
u8_t ipv6_hop_limit;
u8_t ipv4_ttl;
};
#if defined(CONFIG_NET_IPV6)
u8_t ipv6_hop_limit; /* IPv6 hop limit for this network packet. */
u8_t ipv6_ext_len; /* length of extension headers */
u8_t ipv6_ext_opt_len; /* IPv6 ND option length */
@ -249,6 +256,19 @@ static inline bool net_pkt_forwarding(struct net_pkt *pkt)
}
#endif
#if defined(CONFIG_NET_IPV4)
static inline u8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
{
return pkt->ipv4_ttl;
}
static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
u8_t ttl)
{
pkt->ipv4_ttl = ttl;
}
#endif
#if defined(CONFIG_NET_IPV6)
static inline u8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
{

View file

@ -42,7 +42,12 @@ struct net_pkt *net_ipv4_create_raw(struct net_pkt *pkt,
NET_IPV4_HDR(pkt)->tos = 0x00;
NET_IPV4_HDR(pkt)->proto = 0;
NET_IPV4_HDR(pkt)->ttl = net_if_ipv4_get_ttl(iface);
/* User can tweak the default TTL if needed */
NET_IPV4_HDR(pkt)->ttl = net_pkt_ipv4_ttl(pkt);
if (NET_IPV4_HDR(pkt)->ttl == 0) {
NET_IPV4_HDR(pkt)->ttl = net_if_ipv4_get_ttl(iface);
}
NET_IPV4_HDR(pkt)->offset[0] = NET_IPV4_HDR(pkt)->offset[1] = 0;
NET_IPV4_HDR(pkt)->id[0] = NET_IPV4_HDR(pkt)->id[1] = 0;