ell.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH 17/17] icmp6: Ignore bad prefixes per RFC4862
@ 2022-05-13 14:55 Andrew Zaborowski
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Zaborowski @ 2022-05-13 14:55 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 1757 bytes --]

"Silently ignore" Prefix Information options with a preferred time
longer than valid time and those matching the link-local prefix as
mandated by RFC4862 Section 5.5.3.  These prefixes are also invalid
according to RFC4861.
---
 ell/icmp6.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/ell/icmp6.c b/ell/icmp6.c
index ab2fe9c..57cdd1b 100644
--- a/ell/icmp6.c
+++ b/ell/icmp6.c
@@ -819,6 +819,26 @@ struct l_icmp6_router *_icmp6_router_parse(const struct nd_router_advert *ra,
 			i->preferred_lifetime = l_get_be32(opts + 8);
 			memcpy(i->address, opts + 16, 16);
 
+			/*
+			 * Only the initial Prefix Length bits of the prefix
+			 * are valid.  The remaining bits "MUST" be ignored
+			 * by the receiver.
+			 */
+			l_net_mask_prefix(i->address, i->prefix_len, 16);
+
+			/*
+			 * For SLAAC (RFC4862) we need to "silently ignore"
+			 * routes with a preferred lifetime longer than valid
+			 * lifetime, and those with the link-local prefix.
+			 * Since it makes sense, do it regardless of SLAAC.
+			 */
+			if (i->preferred_lifetime > i->valid_lifetime)
+				break;
+
+			if (i->prefix_len >= 10 &&
+					IN6_IS_ADDR_LINKLOCAL(i->address))
+				break;
+
 			n_routes += 1;
 			break;
 		}
@@ -871,6 +891,13 @@ struct l_icmp6_router *_icmp6_router_parse(const struct nd_router_advert *ra,
 			i->valid_lifetime = l_get_be32(opts + 4);
 			memcpy(i->address, opts + 8, (i->prefix_len + 7) / 8);
 
+			/*
+			 * Only the initial Prefix Length bits of the prefix
+			 * are valid.  The remaining bits "MUST" be ignored
+			 * by the receiver.
+			 */
+			l_net_clear_host_bits(i->address, i->prefix_len, 16);
+
 			n_routes += 1;
 			break;
 		}
-- 
2.32.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 17/17] icmp6: Ignore bad prefixes per RFC4862
@ 2022-05-18 19:02 Denis Kenzior
  0 siblings, 0 replies; 3+ messages in thread
From: Denis Kenzior @ 2022-05-18 19:02 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 454 bytes --]

Hi Andrew,

On 5/13/22 17:47, Andrew Zaborowski wrote:
> "Silently ignore" Prefix Information options with a preferred time
> longer than valid time and those matching the link-local prefix as
> mandated by RFC4862 Section 5.5.3.  These prefixes are also invalid
> according to RFC4861.
> ---
>   ell/icmp6.c | 32 ++++++++++++++++++++++++++++++--
>   1 file changed, 30 insertions(+), 2 deletions(-)
> 

Applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 17/17] icmp6: Ignore bad prefixes per RFC4862
@ 2022-05-13 22:47 Andrew Zaborowski
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Zaborowski @ 2022-05-13 22:47 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 2130 bytes --]

"Silently ignore" Prefix Information options with a preferred time
longer than valid time and those matching the link-local prefix as
mandated by RFC4862 Section 5.5.3.  These prefixes are also invalid
according to RFC4861.
---
 ell/icmp6.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/ell/icmp6.c b/ell/icmp6.c
index ab2fe9c..96ba1ec 100644
--- a/ell/icmp6.c
+++ b/ell/icmp6.c
@@ -45,6 +45,7 @@
 #include "time-private.h"
 #include "queue.h"
 #include "net.h"
+#include "net-private.h"
 #include "netlink.h"
 #include "rtnl.h"
 #include "missing.h"
@@ -817,7 +818,27 @@ struct l_icmp6_router *_icmp6_router_parse(const struct nd_router_advert *ra,
 			i->onlink = true;
 			i->valid_lifetime = l_get_be32(opts + 4);
 			i->preferred_lifetime = l_get_be32(opts + 8);
-			memcpy(i->address, opts + 16, 16);
+
+			/*
+			 * Only the initial Prefix Length bits of the prefix
+			 * are valid.  The remaining bits "MUST" be ignored
+			 * by the receiver.
+			 */
+			memcpy(i->address, net_prefix_from_ipv6(opts + 16,
+							i->prefix_len), 16);
+
+			/*
+			 * For SLAAC (RFC4862) we need to "silently ignore"
+			 * routes with a preferred lifetime longer than valid
+			 * lifetime, and those with the link-local prefix.
+			 * Since it makes sense, do it regardless of SLAAC.
+			 */
+			if (i->preferred_lifetime > i->valid_lifetime)
+				break;
+
+			if (i->prefix_len >= 10 &&
+					IN6_IS_ADDR_LINKLOCAL(i->address))
+				break;
 
 			n_routes += 1;
 			break;
@@ -869,7 +890,14 @@ struct l_icmp6_router *_icmp6_router_parse(const struct nd_router_advert *ra,
 			i->onlink = false;
 			i->preference = preference;
 			i->valid_lifetime = l_get_be32(opts + 4);
-			memcpy(i->address, opts + 8, (i->prefix_len + 7) / 8);
+
+			/*
+			 * Only the initial Prefix Length bits of the prefix
+			 * are valid.  The remaining bits "MUST" be ignored
+			 * by the receiver.
+			 */
+			memcpy(i->address, net_prefix_from_ipv6(opts + 8,
+							i->prefix_len), 16);
 
 			n_routes += 1;
 			break;
-- 
2.32.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-05-18 19:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-13 14:55 [PATCH 17/17] icmp6: Ignore bad prefixes per RFC4862 Andrew Zaborowski
2022-05-13 22:47 Andrew Zaborowski
2022-05-18 19:02 Denis Kenzior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).