+ case OPTION_6RD:
+ /* Option binary format (see RFC 5969):
+ * 0 1 2 3
+ * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | OPTION_6RD | option-length | IPv4MaskLen | 6rdPrefixLen |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | 6rdPrefix |
+ * ... (16 octets) ...
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * ... 6rdBRIPv4Address(es) ...
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * We convert it to a string
+ * "IPv4MaskLen 6rdPrefixLen 6rdPrefix 6rdBRIPv4Address..."
+ *
+ * Sanity check: ensure that our length is at least 22 bytes, that
+ * IPv4MaskLen <= 32,
+ * 6rdPrefixLen <= 128,
+ * 6rdPrefixLen + (32 - IPv4MaskLen) <= 128
+ * (2nd condition need no check - it follows from 1st and 3rd).
+ * Else, return envvar with empty value ("optname=")
+ */
+ if (len >= (1 + 1 + 16 + 4)
+ && option[0] <= 32
+ && (option[1] + 32 - option[0]) <= 128
+ ) {
+ /* IPv4MaskLen */
+ dest += sprintf(dest, "%u ", *option++);
+ /* 6rdPrefixLen */
+ dest += sprintf(dest, "%u ", *option++);
+ /* 6rdPrefix */
+ dest += sprint_nip6(dest, /* "", */ option);
+ option += 16;
+ len -= 1 + 1 + 16 + 4;
+ /* "+ 4" above corresponds to the length of IPv4 addr
+ * we consume in the loop below */
+ while (1) {
+ /* 6rdBRIPv4Address(es) */
+ dest += sprint_nip(dest, " ", option);
+ option += 4;
+ len -= 4; /* do we have yet another 4+ bytes? */
+ if (len < 0)
+ break; /* no */
+ }
+ }
+
+ return ret;