net: ipv6: Allow user to tweak packet hop limit value
The default hop limit is defined in struct net_if. It is possible that user might want to tweak it for each network packet. For this purpose, a net_nbuf_set_ipv6_hop_limit(buf) function is created. Change-Id: I7568330358f80f0f5007d6d3c411c120b043c04f Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
31d3406efa
commit
42bd36ec77
3 changed files with 26 additions and 3 deletions
|
@ -81,6 +81,9 @@ struct net_nbuf {
|
||||||
* adds IPv6 extension headers to the network packet.
|
* adds IPv6 extension headers to the network packet.
|
||||||
*/
|
*/
|
||||||
uint16_t ipv6_prev_hdr_start;
|
uint16_t ipv6_prev_hdr_start;
|
||||||
|
|
||||||
|
/* IPv6 hop limit for this network packet. */
|
||||||
|
uint8_t ipv6_hop_limit;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint8_t ll_reserve; /* link layer header length */
|
uint8_t ll_reserve; /* link layer header length */
|
||||||
|
@ -374,6 +377,19 @@ static inline void net_nbuf_set_ipv6_hdr_prev(struct net_buf *buf,
|
||||||
((struct net_nbuf *)
|
((struct net_nbuf *)
|
||||||
net_buf_user_data(buf))->ipv6_prev_hdr_start = offset;
|
net_buf_user_data(buf))->ipv6_prev_hdr_start = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline uint8_t net_nbuf_ipv6_hop_limit(struct net_buf *buf)
|
||||||
|
{
|
||||||
|
return ((struct net_nbuf *)
|
||||||
|
net_buf_user_data(buf))->ipv6_hop_limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void net_nbuf_set_ipv6_hop_limit(struct net_buf *buf,
|
||||||
|
uint8_t hop_limit)
|
||||||
|
{
|
||||||
|
((struct net_nbuf *)
|
||||||
|
net_buf_user_data(buf))->ipv6_hop_limit = hop_limit;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_NET_IPV6_FRAGMENT)
|
#if defined(CONFIG_NET_IPV6_FRAGMENT)
|
||||||
|
|
|
@ -814,7 +814,8 @@ struct net_if_router *net_if_ipv6_router_add(struct net_if *iface,
|
||||||
bool net_if_ipv6_router_rm(struct net_if_router *router);
|
bool net_if_ipv6_router_rm(struct net_if_router *router);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get IPv6 hop limit specified for a given interface
|
* @brief Get IPv6 hop limit specified for a given interface. This is the
|
||||||
|
* default value but can be overridden by the user.
|
||||||
*
|
*
|
||||||
* @param iface Network interface
|
* @param iface Network interface
|
||||||
*
|
*
|
||||||
|
@ -826,7 +827,7 @@ static inline uint8_t net_if_ipv6_get_hop_limit(struct net_if *iface)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set IPv6 hop limit of a given interface
|
* @brief Set the default IPv6 hop limit of a given interface.
|
||||||
*
|
*
|
||||||
* @param iface Network interface
|
* @param iface Network interface
|
||||||
* @param hop_limit New hop limit
|
* @param hop_limit New hop limit
|
||||||
|
|
|
@ -477,7 +477,13 @@ struct net_buf *net_ipv6_create_raw(struct net_buf *buf,
|
||||||
NET_IPV6_BUF(buf)->flow = 0;
|
NET_IPV6_BUF(buf)->flow = 0;
|
||||||
|
|
||||||
NET_IPV6_BUF(buf)->nexthdr = 0;
|
NET_IPV6_BUF(buf)->nexthdr = 0;
|
||||||
NET_IPV6_BUF(buf)->hop_limit = net_if_ipv6_get_hop_limit(iface);
|
|
||||||
|
/* User can tweak the default hop limit if needed */
|
||||||
|
NET_IPV6_BUF(buf)->hop_limit = net_nbuf_ipv6_hop_limit(buf);
|
||||||
|
if (NET_IPV6_BUF(buf)->hop_limit == 0) {
|
||||||
|
NET_IPV6_BUF(buf)->hop_limit =
|
||||||
|
net_if_ipv6_get_hop_limit(iface);
|
||||||
|
}
|
||||||
|
|
||||||
net_ipaddr_copy(&NET_IPV6_BUF(buf)->dst, dst);
|
net_ipaddr_copy(&NET_IPV6_BUF(buf)->dst, dst);
|
||||||
net_ipaddr_copy(&NET_IPV6_BUF(buf)->src, src);
|
net_ipaddr_copy(&NET_IPV6_BUF(buf)->src, src);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue