The RFC is definitely unclear about size of prefix to be sended, but as I concluded from it the only restriction is that we must set net and host bits of prefix to zero. But on the other hand previous approach leads to wasting resources, so I reworked code to send only necessary data.

On 08/31/2014 01:59 AM, Simon Kelley wrote:


In principle, this is fine.

Just based on reading the RFC (which isn't very clear) I think the
strategy of always sending the prefix as full-sized may not be valid, or
at least may confuse some hosts.



Prefix Length
                8-bit unsigned integer.  The number of leading bits in
                the Prefix that are valid.  The value ranges from 0 to
                128.  The Prefix field is 0, 8, or 16 octets depending on
                Length.

I read this as saying that if the prefix length is <= 64, then the
Prefix field should be 8 octets long and the total option length should
be 2*8 octets, and if the prefix-length is zero, the total option length
should be 1 unit if 8 octets, just for the header.

So I don't think it's necessarily legit to always make the option length
24 octets, certainly reducing the option length for short prefix is
definitely OK, so we should do that, to confirm to the principle of "be
conservative about what you send"

Cheers,

Simon.


--
Best regards,
Ilya Ponetaev
D-Link Corp.
diff --git a/src/radv-protocol.h b/src/radv-protocol.h
index e576012..72ccda4 100644
--- a/src/radv-protocol.h
+++ b/src/radv-protocol.h
@@ -50,6 +50,7 @@ struct prefix_opt {
 #define ICMP6_OPT_PREFIX       3
 #define ICMP6_OPT_MTU          5
 #define ICMP6_OPT_ADV_INTERVAL 7
+#define ICMP6_OPT_RT_INFO     24
 #define ICMP6_OPT_RDNSS       25
 #define ICMP6_OPT_DNSSL       31
 
diff --git a/src/radv.c b/src/radv.c
index f5b517b..50decc4 100644
--- a/src/radv.c
+++ b/src/radv.c
@@ -648,6 +648,36 @@ static int add_prefixes(struct in6_addr *local,  int prefix,
 		  inet_ntop(AF_INET6, local, daemon->addrbuff, ADDRSTRLEN);
 		  if (!option_bool(OPT_QUIET_RA))
 		    my_syslog(MS_DHCP | LOG_INFO, "RTR-ADVERT(%s) %s", param->if_name, daemon->addrbuff); 		    
+		  
+		  /* Send Route Information option (RFC4191, 2.3) */
+		  put_opt6_char(ICMP6_OPT_RT_INFO);
+		  /* Length in units of 8 octets will be 1 (header) +
+		   * 0, 1 or 2 (0...128 bits / 64 bit per unit)
+		   * */
+		  if (0 == prefix)
+			  /* Hardly a possible situation, but strictly comply with RFC
+			   * */
+			  put_opt6_char(1);
+		  else if (prefix < 65) {
+			  put_opt6_char(2);
+		  } else
+			  put_opt6_char(3);
+		  put_opt6_char(prefix);
+		  /* Medium priority for default
+		   * */
+		  put_opt6_char(0);
+		  /* "valid lifetime" seems more reasonable than "preferred"
+		   * */
+		  put_opt6_long(valid);
+		  /* Actual prefix, only necessary part
+		   * Don't append any data in case of prefix length == 0
+		   * */
+		  if (0 != prefix) {
+			  if (prefix < 65)
+				  put_opt6((void *)local, 8);
+			  else
+				  put_opt6((void *)local, 16);
+		  }
 		}
 	    }
 	}
_______________________________________________
Dnsmasq-discuss mailing list
[email protected]
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss

Reply via email to