+/* RFC5613 Section 2.2 (w/o the TLVs) */
+static int
+ospf6_print_lls(netdissect_options *ndo,
+ const u_char *cp, const u_int len)
+{
+ uint16_t llsdatalen;
+
+ if (len == 0)
+ return 0;
+ if (len < OSPF_LLS_HDRLEN)
+ goto trunc;
+ /* Checksum */
+ ND_TCHECK_2(cp);
+ ND_PRINT((ndo, "\n\tLLS Checksum 0x%04x", EXTRACT_BE_U_2(cp)));
+ cp += 2;
+ /* LLS Data Length */
+ ND_TCHECK_2(cp);
+ llsdatalen = EXTRACT_BE_U_2(cp);
+ ND_PRINT((ndo, ", Data Length %u", llsdatalen));
+ if (llsdatalen < OSPF_LLS_HDRLEN || llsdatalen > len)
+ goto trunc;
+ cp += 2;
+ /* LLS TLVs */
+ ND_TCHECK2(*cp, llsdatalen - OSPF_LLS_HDRLEN);
+ /* FIXME: code in print-ospf.c can be reused to decode the TLVs */
+
+ return llsdatalen;
+trunc:
+ return -1;
+}
+
+/* RFC6506 Section 4.1 */
+static int
+ospf6_decode_at(netdissect_options *ndo,
+ const u_char *cp, const u_int len)
+{
+ uint16_t authdatalen;
+
+ if (len == 0)
+ return 0;
+ if (len < OSPF6_AT_HDRLEN)
+ goto trunc;
+ /* Authentication Type */
+ ND_TCHECK_2(cp);
+ ND_PRINT((ndo, "\n\tAuthentication Type %s", tok2str(ospf6_auth_type_str, "unknown (0x%04x)", EXTRACT_BE_U_2(cp))));
+ cp += 2;
+ /* Auth Data Len */
+ ND_TCHECK_2(cp);
+ authdatalen = EXTRACT_BE_U_2(cp);
+ ND_PRINT((ndo, ", Length %u", authdatalen));
+ if (authdatalen < OSPF6_AT_HDRLEN || authdatalen > len)
+ goto trunc;
+ cp += 2;
+ /* Reserved */
+ ND_TCHECK_2(cp);
+ cp += 2;
+ /* Security Association ID */
+ ND_TCHECK_2(cp);
+ ND_PRINT((ndo, ", SAID %u", EXTRACT_BE_U_2(cp)));
+ cp += 2;
+ /* Cryptographic Sequence Number (High-Order 32 Bits) */
+ ND_TCHECK_4(cp);
+ ND_PRINT((ndo, ", CSN 0x%08x", EXTRACT_BE_U_4(cp)));
+ cp += 4;
+ /* Cryptographic Sequence Number (Low-Order 32 Bits) */
+ ND_TCHECK_4(cp);
+ ND_PRINT((ndo, ":%08x", EXTRACT_BE_U_4(cp)));
+ cp += 4;
+ /* Authentication Data */
+ ND_TCHECK2(*cp, authdatalen - OSPF6_AT_HDRLEN);
+ if (ndo->ndo_vflag > 1)
+ print_unknown_data(ndo,cp, "\n\tAuthentication Data ", authdatalen - OSPF6_AT_HDRLEN);
+ return 0;
+
+trunc:
+ return 1;
+}
+
+/* The trailing data may include LLS and/or AT data (in this specific order).
+ * LLS data may be present only in Hello and DBDesc packets with the L-bit set.
+ * AT data may be present in Hello and DBDesc packets with the AT-bit set or in
+ * any other packet type, thus decode the AT data regardless of the AT-bit.
+ */
+static int
+ospf6_decode_v3_trailer(netdissect_options *ndo,
+ const struct ospf6hdr *op, const u_char *cp, const unsigned len)
+{
+ int llslen = 0;
+ int lls_hello = 0;
+ int lls_dd = 0;
+
+ if (op->ospf6_type == OSPF_TYPE_HELLO) {
+ const struct hello6 *hellop = (const struct hello6 *)((const uint8_t *)op + OSPF6HDR_LEN);
+ ND_TCHECK(hellop->hello_options);
+ if (EXTRACT_BE_U_4(&hellop->hello_options) & OSPF6_OPTION_L)
+ lls_hello = 1;
+ } else if (op->ospf6_type == OSPF_TYPE_DD) {
+ const struct dd6 *ddp = (const struct dd6 *)((const uint8_t *)op + OSPF6HDR_LEN);
+ ND_TCHECK(ddp->db_options);
+ if (EXTRACT_BE_U_4(&ddp->db_options) & OSPF6_OPTION_L)
+ lls_dd = 1;
+ }
+ if ((lls_hello || lls_dd) && (llslen = ospf6_print_lls(ndo, cp, len)) < 0)
+ goto trunc;
+ return ospf6_decode_at(ndo, cp + llslen, len - llslen);
+
+trunc:
+ return 1;
+}
+