Skip to content
Permalink
Browse files

net: ip: ipv6_nbr: use temp variables for ntoh conversion

The network to host byte order conversion is actually in place
on the network buffer. This prevents the reuse and forwarding of
RA packets. This commit uses temporary variables instead.

Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
  • Loading branch information...
alexanderwachter authored and jukkar committed Jun 25, 2019
1 parent d864f5d commit 8a69b83d3ff6d721df2b26143ad1918e6fc5fc4b
Showing with 17 additions and 16 deletions.
  1. +17 −16 subsys/net/ip/ipv6_nbr.c
@@ -2184,6 +2184,7 @@ static inline bool handle_ra_prefix(struct net_pkt *pkt)
NET_PKT_DATA_ACCESS_DEFINE(rapfx_access,
struct net_icmpv6_nd_opt_prefix_info);
struct net_icmpv6_nd_opt_prefix_info *pfx_info;
u32_t valid_lifetime, preferred_lifetime;

pfx_info = (struct net_icmpv6_nd_opt_prefix_info *)
net_pkt_get_data(pkt, &rapfx_access);
@@ -2193,17 +2194,17 @@ static inline bool handle_ra_prefix(struct net_pkt *pkt)

net_pkt_acknowledge_data(pkt, &rapfx_access);

pfx_info->valid_lifetime = ntohl(pfx_info->valid_lifetime);
pfx_info->preferred_lifetime = ntohl(pfx_info->preferred_lifetime);
valid_lifetime = ntohl(pfx_info->valid_lifetime);
preferred_lifetime = ntohl(pfx_info->preferred_lifetime);

if (pfx_info->valid_lifetime >= pfx_info->preferred_lifetime &&
if (valid_lifetime >= preferred_lifetime &&
!net_ipv6_is_ll_addr(&pfx_info->prefix)) {
if (pfx_info->flags & NET_ICMPV6_RA_FLAG_ONLINK) {
handle_prefix_onlink(pkt, pfx_info);
}

if ((pfx_info->flags & NET_ICMPV6_RA_FLAG_AUTONOMOUS) &&
pfx_info->valid_lifetime &&
valid_lifetime &&
(pfx_info->prefix_len == NET_IPV6_DEFAULT_PREFIX_LEN)) {
handle_prefix_autonomous(pkt, pfx_info);
}
@@ -2265,7 +2266,8 @@ static enum net_verdict handle_ra_input(struct net_pkt *pkt,
struct net_icmpv6_nd_opt_hdr *nd_opt_hdr;
struct net_icmpv6_ra_hdr *ra_hdr;
struct net_if_router *router;
u32_t mtu;
u32_t mtu, reachable_time, retrans_timer;
u16_t router_lifetime;

ra_hdr = (struct net_icmpv6_ra_hdr *)net_pkt_get_data(pkt, &ra_access);
if (!ra_hdr) {
@@ -2289,9 +2291,9 @@ static enum net_verdict handle_ra_input(struct net_pkt *pkt,

net_pkt_acknowledge_data(pkt, &ra_access);

ra_hdr->router_lifetime = ntohs(ra_hdr->router_lifetime);
ra_hdr->reachable_time = ntohl(ra_hdr->reachable_time);
ra_hdr->retrans_timer = ntohl(ra_hdr->retrans_timer);
router_lifetime = ntohs(ra_hdr->router_lifetime);
reachable_time = ntohl(ra_hdr->reachable_time);
retrans_timer = ntohl(ra_hdr->retrans_timer);

if (ra_hdr->cur_hop_limit) {
net_ipv6_set_hop_limit(net_pkt_iface(pkt),
@@ -2300,17 +2302,16 @@ static enum net_verdict handle_ra_input(struct net_pkt *pkt,
net_if_ipv6_get_hop_limit(net_pkt_iface(pkt)));
}

if (ra_hdr->reachable_time &&
ra_hdr->reachable_time <= MAX_REACHABLE_TIME &&
if (reachable_time && reachable_time <= MAX_REACHABLE_TIME &&
(net_if_ipv6_get_reachable_time(net_pkt_iface(pkt)) !=
ra_hdr->reachable_time)) {
reachable_time)) {
net_if_ipv6_set_base_reachable_time(net_pkt_iface(pkt),
ra_hdr->reachable_time);
reachable_time);
net_if_ipv6_set_reachable_time(
net_pkt_iface(pkt)->config.ip.ipv6);
}

if (ra_hdr->retrans_timer) {
if (retrans_timer) {
net_if_ipv6_set_retrans_timer(net_pkt_iface(pkt),
ra_hdr->retrans_timer);
}
@@ -2399,7 +2400,7 @@ static enum net_verdict handle_ra_input(struct net_pkt *pkt,

router = net_if_ipv6_router_lookup(net_pkt_iface(pkt), &ip_hdr->src);
if (router) {
if (!ra_hdr->router_lifetime) {
if (!router_lifetime) {
/* TODO: Start rs_timer on iface if no routers
* at all available on iface.
*/
@@ -2410,11 +2411,11 @@ static enum net_verdict handle_ra_input(struct net_pkt *pkt,
}

net_if_ipv6_router_update_lifetime(
router, ra_hdr->router_lifetime);
router, router_lifetime);
}
} else {
net_if_ipv6_router_add(net_pkt_iface(pkt),
&ip_hdr->src, ra_hdr->router_lifetime);
&ip_hdr->src, router_lifetime);
}

if (nbr && net_ipv6_nbr_data(nbr)->pending) {

0 comments on commit 8a69b83

Please sign in to comment.
You can’t perform that action at this time.