+static int
+auth_print(netdissect_options *ndo, register const u_char *pptr)
+{
+ const struct bfd_auth_header_t *bfd_auth_header;
+ int i;
+
+ pptr += sizeof (const struct bfd_header_t);
+ bfd_auth_header = (const struct bfd_auth_header_t *)pptr;
+ ND_TCHECK(*bfd_auth_header);
+ ND_PRINT((ndo, "\n\tAuthentication: %s (%u), length: %u",
+ tok2str(bfd_v1_authentication_values,"Unknown",bfd_auth_header->auth_type),
+ bfd_auth_header->auth_type,
+ bfd_auth_header->auth_len));
+ pptr += 2;
+ ND_PRINT((ndo, "\n\t Auth Key ID: %d", *pptr));
+
+ switch(bfd_auth_header->auth_type) {
+ case AUTH_PASSWORD:
+/*
+ * Simple Password Authentication Section Format
+ *
+ * 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
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Auth Type | Auth Len | Auth Key ID | Password... |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | ... |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+ if (bfd_auth_header->auth_len < AUTH_PASSWORD_FIELD_MIN_LEN ||
+ bfd_auth_header->auth_len > AUTH_PASSWORD_FIELD_MAX_LEN) {
+ ND_PRINT((ndo, "[invalid length %d]",
+ bfd_auth_header->auth_len));
+ break;
+ }
+ pptr++;
+ ND_PRINT((ndo, ", Password: "));
+ /* the length is equal to the password length plus three */
+ if (fn_printn(ndo, pptr, bfd_auth_header->auth_len - 3,
+ ndo->ndo_snapend))
+ goto trunc;
+ break;
+ case AUTH_MD5:
+ case AUTH_MET_MD5:
+/*
+ * Keyed MD5 and Meticulous Keyed MD5 Authentication Section Format
+ *
+ * 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
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Auth Type | Auth Len | Auth Key ID | Reserved |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Sequence Number |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Auth Key/Digest... |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | ... |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+ if (bfd_auth_header->auth_len != AUTH_MD5_FIELD_LEN) {
+ ND_PRINT((ndo, "[invalid length %d]",
+ bfd_auth_header->auth_len));
+ break;
+ }
+ pptr += 2;
+ ND_TCHECK2(*pptr, 4);
+ ND_PRINT((ndo, ", Sequence Number: 0x%08x", EXTRACT_32BITS(pptr)));
+ pptr += 4;
+ ND_TCHECK2(*pptr, AUTH_MD5_HASH_LEN);
+ ND_PRINT((ndo, "\n\t Digest: "));
+ for(i = 0; i < AUTH_MD5_HASH_LEN; i++)
+ ND_PRINT((ndo, "%02x", pptr[i]));
+ break;
+ case AUTH_SHA1:
+ case AUTH_MET_SHA1:
+/*
+ * Keyed SHA1 and Meticulous Keyed SHA1 Authentication Section Format
+ *
+ * 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
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Auth Type | Auth Len | Auth Key ID | Reserved |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Sequence Number |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Auth Key/Hash... |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | ... |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+ if (bfd_auth_header->auth_len != AUTH_SHA1_FIELD_LEN) {
+ ND_PRINT((ndo, "[invalid length %d]",
+ bfd_auth_header->auth_len));
+ break;
+ }
+ pptr += 2;
+ ND_TCHECK2(*pptr, 4);
+ ND_PRINT((ndo, ", Sequence Number: 0x%08x", EXTRACT_32BITS(pptr)));
+ pptr += 4;
+ ND_TCHECK2(*pptr, AUTH_SHA1_HASH_LEN);
+ ND_PRINT((ndo, "\n\t Hash: "));
+ for(i = 0; i < AUTH_SHA1_HASH_LEN; i++)
+ ND_PRINT((ndo, "%02x", pptr[i]));
+ break;
+ }
+ return 0;
+
+trunc:
+ return 1;
+}
+