xref: /freebsd/contrib/tcpdump/print-enc.c (revision 3c602fabf9b894ff79f08a80cbb7ad3b1eb84e62)
15b0fe478SBruce M Simpson /*	$OpenBSD: print-enc.c,v 1.7 2002/02/19 19:39:40 millert Exp $	*/
25b0fe478SBruce M Simpson 
35b0fe478SBruce M Simpson /*
45b0fe478SBruce M Simpson  * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996
55b0fe478SBruce M Simpson  *	The Regents of the University of California.  All rights reserved.
65b0fe478SBruce M Simpson  *
75b0fe478SBruce M Simpson  * Redistribution and use in source and binary forms, with or without
85b0fe478SBruce M Simpson  * modification, are permitted provided that: (1) source code distributions
95b0fe478SBruce M Simpson  * retain the above copyright notice and this paragraph in its entirety, (2)
105b0fe478SBruce M Simpson  * distributions including binary code include the above copyright notice and
115b0fe478SBruce M Simpson  * this paragraph in its entirety in the documentation or other materials
125b0fe478SBruce M Simpson  * provided with the distribution, and (3) all advertising materials mentioning
135b0fe478SBruce M Simpson  * features or use of this software display the following acknowledgement:
145b0fe478SBruce M Simpson  * ``This product includes software developed by the University of California,
155b0fe478SBruce M Simpson  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
165b0fe478SBruce M Simpson  * the University nor the names of its contributors may be used to endorse
175b0fe478SBruce M Simpson  * or promote products derived from this software without specific prior
185b0fe478SBruce M Simpson  * written permission.
195b0fe478SBruce M Simpson  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
205b0fe478SBruce M Simpson  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
215b0fe478SBruce M Simpson  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
225b0fe478SBruce M Simpson  */
235b0fe478SBruce M Simpson 
24*3c602fabSXin LI #define NETDISSECT_REWORKED
255b0fe478SBruce M Simpson #ifdef HAVE_CONFIG_H
265b0fe478SBruce M Simpson #include "config.h"
275b0fe478SBruce M Simpson #endif
285b0fe478SBruce M Simpson 
295b0fe478SBruce M Simpson #include <tcpdump-stdinc.h>
305b0fe478SBruce M Simpson 
315b0fe478SBruce M Simpson #include "interface.h"
3227df3f5dSRui Paulo #include "extract.h"
335b0fe478SBruce M Simpson 
34*3c602fabSXin LI /* From $OpenBSD: if_enc.h,v 1.8 2001/06/25 05:14:00 angelos Exp $ */
35*3c602fabSXin LI /*
36*3c602fabSXin LI  * The authors of this code are John Ioannidis (ji@tla.org),
37*3c602fabSXin LI  * Angelos D. Keromytis (kermit@csd.uch.gr) and
38*3c602fabSXin LI  * Niels Provos (provos@physnet.uni-hamburg.de).
39*3c602fabSXin LI  *
40*3c602fabSXin LI  * This code was written by John Ioannidis for BSD/OS in Athens, Greece,
41*3c602fabSXin LI  * in November 1995.
42*3c602fabSXin LI  *
43*3c602fabSXin LI  * Ported to OpenBSD and NetBSD, with additional transforms, in December 1996,
44*3c602fabSXin LI  * by Angelos D. Keromytis.
45*3c602fabSXin LI  *
46*3c602fabSXin LI  * Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis
47*3c602fabSXin LI  * and Niels Provos.
48*3c602fabSXin LI  *
49*3c602fabSXin LI  * Copyright (C) 1995, 1996, 1997, 1998 by John Ioannidis, Angelos D. Keromytis
50*3c602fabSXin LI  * and Niels Provos.
51*3c602fabSXin LI  * Copyright (c) 2001, Angelos D. Keromytis.
52*3c602fabSXin LI  *
53*3c602fabSXin LI  * Permission to use, copy, and modify this software with or without fee
54*3c602fabSXin LI  * is hereby granted, provided that this entire notice is included in
55*3c602fabSXin LI  * all copies of any software which is or includes a copy or
56*3c602fabSXin LI  * modification of this software.
57*3c602fabSXin LI  * You may use this code under the GNU public license if you so wish. Please
58*3c602fabSXin LI  * contribute changes back to the authors under this freer than GPL license
59*3c602fabSXin LI  * so that we may further the use of strong encryption without limitations to
60*3c602fabSXin LI  * all.
61*3c602fabSXin LI  *
62*3c602fabSXin LI  * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
63*3c602fabSXin LI  * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
64*3c602fabSXin LI  * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
65*3c602fabSXin LI  * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
66*3c602fabSXin LI  * PURPOSE.
67*3c602fabSXin LI  */
68*3c602fabSXin LI 
69*3c602fabSXin LI #define ENC_HDRLEN	12
70*3c602fabSXin LI 
71*3c602fabSXin LI /* From $OpenBSD: mbuf.h,v 1.56 2002/01/25 15:50:23 art Exp $	*/
72*3c602fabSXin LI #define M_CONF		0x0400  /* packet was encrypted (ESP-transport) */
73*3c602fabSXin LI #define M_AUTH		0x0800  /* packet was authenticated (AH) */
74*3c602fabSXin LI 
75*3c602fabSXin LI struct enchdr {
76*3c602fabSXin LI 	uint32_t af;
77*3c602fabSXin LI 	uint32_t spi;
78*3c602fabSXin LI 	uint32_t flags;
79*3c602fabSXin LI };
805b0fe478SBruce M Simpson 
815b0fe478SBruce M Simpson #define ENC_PRINT_TYPE(wh, xf, nam) \
825b0fe478SBruce M Simpson 	if ((wh) & (xf)) { \
83*3c602fabSXin LI 		ND_PRINT((ndo, "%s%s", nam, (wh) == (xf) ? "): " : ",")); \
845b0fe478SBruce M Simpson 		(wh) &= ~(xf); \
855b0fe478SBruce M Simpson 	}
865b0fe478SBruce M Simpson 
875b0fe478SBruce M Simpson u_int
88*3c602fabSXin LI enc_if_print(netdissect_options *ndo,
89*3c602fabSXin LI              const struct pcap_pkthdr *h, register const u_char *p)
905b0fe478SBruce M Simpson {
915b0fe478SBruce M Simpson 	register u_int length = h->len;
925b0fe478SBruce M Simpson 	register u_int caplen = h->caplen;
935b0fe478SBruce M Simpson 	int flags;
945b0fe478SBruce M Simpson 	const struct enchdr *hdr;
955b0fe478SBruce M Simpson 
965b0fe478SBruce M Simpson 	if (caplen < ENC_HDRLEN) {
97*3c602fabSXin LI 		ND_PRINT((ndo, "[|enc]"));
985b0fe478SBruce M Simpson 		goto out;
995b0fe478SBruce M Simpson 	}
1005b0fe478SBruce M Simpson 
1015b0fe478SBruce M Simpson 	hdr = (struct enchdr *)p;
1025b0fe478SBruce M Simpson 	flags = hdr->flags;
1035b0fe478SBruce M Simpson 	if (flags == 0)
104*3c602fabSXin LI 		ND_PRINT((ndo, "(unprotected): "));
1055b0fe478SBruce M Simpson 	else
106*3c602fabSXin LI 		ND_PRINT((ndo, "("));
1075b0fe478SBruce M Simpson 	ENC_PRINT_TYPE(flags, M_AUTH, "authentic");
1085b0fe478SBruce M Simpson 	ENC_PRINT_TYPE(flags, M_CONF, "confidential");
1095b0fe478SBruce M Simpson 	/* ENC_PRINT_TYPE(flags, M_TUNNEL, "tunnel"); */
110*3c602fabSXin LI 	ND_PRINT((ndo, "SPI 0x%08x: ", EXTRACT_32BITS(&hdr->spi)));
1115b0fe478SBruce M Simpson 
1125b0fe478SBruce M Simpson 	length -= ENC_HDRLEN;
113a5779b6eSRui Paulo 	caplen -= ENC_HDRLEN;
114a5779b6eSRui Paulo 	p += ENC_HDRLEN;
115a5779b6eSRui Paulo 
116a5779b6eSRui Paulo 	switch (hdr->af) {
117a5779b6eSRui Paulo 	case AF_INET:
118*3c602fabSXin LI 		ip_print(ndo, p, length);
119a5779b6eSRui Paulo 		break;
120661c9d81SRui Paulo #ifdef INET6
121a5779b6eSRui Paulo 	case AF_INET6:
122*3c602fabSXin LI 		ip6_print(ndo, p, length);
123a5779b6eSRui Paulo 		break;
12427df3f5dSRui Paulo #endif /*INET6*/
125a5779b6eSRui Paulo 	}
1265b0fe478SBruce M Simpson 
1275b0fe478SBruce M Simpson out:
1285b0fe478SBruce M Simpson 	return (ENC_HDRLEN);
1295b0fe478SBruce M Simpson }
1301de50e9fSSam Leffler 
1311de50e9fSSam Leffler 
1321de50e9fSSam Leffler /*
1331de50e9fSSam Leffler  * Local Variables:
1341de50e9fSSam Leffler  * c-style: whitesmith
1351de50e9fSSam Leffler  * c-basic-offset: 8
1361de50e9fSSam Leffler  * End:
1371de50e9fSSam Leffler  */
138