1127668Sbms/*	$OpenBSD: print-enc.c,v 1.7 2002/02/19 19:39:40 millert Exp $	*/
2127668Sbms
3127668Sbms/*
4127668Sbms * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996
5127668Sbms *	The Regents of the University of California.  All rights reserved.
6127668Sbms *
7127668Sbms * Redistribution and use in source and binary forms, with or without
8127668Sbms * modification, are permitted provided that: (1) source code distributions
9127668Sbms * retain the above copyright notice and this paragraph in its entirety, (2)
10127668Sbms * distributions including binary code include the above copyright notice and
11127668Sbms * this paragraph in its entirety in the documentation or other materials
12127668Sbms * provided with the distribution, and (3) all advertising materials mentioning
13127668Sbms * features or use of this software display the following acknowledgement:
14127668Sbms * ``This product includes software developed by the University of California,
15127668Sbms * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16127668Sbms * the University nor the names of its contributors may be used to endorse
17127668Sbms * or promote products derived from this software without specific prior
18127668Sbms * written permission.
19127668Sbms * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20127668Sbms * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21127668Sbms * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22127668Sbms */
23127668Sbms
24313537Sglebius/* \summary: OpenBSD IPsec encapsulation BPF layer printer */
25313537Sglebius
26127668Sbms#ifdef HAVE_CONFIG_H
27127668Sbms#include "config.h"
28127668Sbms#endif
29127668Sbms
30313537Sglebius#include <netdissect-stdinc.h>
31127668Sbms
32313537Sglebius#include "netdissect.h"
33214478Srpaulo#include "extract.h"
34127668Sbms
35276788Sdelphij/* From $OpenBSD: if_enc.h,v 1.8 2001/06/25 05:14:00 angelos Exp $ */
36276788Sdelphij/*
37276788Sdelphij * The authors of this code are John Ioannidis (ji@tla.org),
38276788Sdelphij * Angelos D. Keromytis (kermit@csd.uch.gr) and
39276788Sdelphij * Niels Provos (provos@physnet.uni-hamburg.de).
40276788Sdelphij *
41276788Sdelphij * This code was written by John Ioannidis for BSD/OS in Athens, Greece,
42276788Sdelphij * in November 1995.
43276788Sdelphij *
44276788Sdelphij * Ported to OpenBSD and NetBSD, with additional transforms, in December 1996,
45276788Sdelphij * by Angelos D. Keromytis.
46276788Sdelphij *
47276788Sdelphij * Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis
48276788Sdelphij * and Niels Provos.
49276788Sdelphij *
50276788Sdelphij * Copyright (C) 1995, 1996, 1997, 1998 by John Ioannidis, Angelos D. Keromytis
51276788Sdelphij * and Niels Provos.
52276788Sdelphij * Copyright (c) 2001, Angelos D. Keromytis.
53276788Sdelphij *
54276788Sdelphij * Permission to use, copy, and modify this software with or without fee
55276788Sdelphij * is hereby granted, provided that this entire notice is included in
56276788Sdelphij * all copies of any software which is or includes a copy or
57276788Sdelphij * modification of this software.
58276788Sdelphij * You may use this code under the GNU public license if you so wish. Please
59276788Sdelphij * contribute changes back to the authors under this freer than GPL license
60276788Sdelphij * so that we may further the use of strong encryption without limitations to
61276788Sdelphij * all.
62276788Sdelphij *
63276788Sdelphij * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
64276788Sdelphij * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
65276788Sdelphij * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
66276788Sdelphij * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
67276788Sdelphij * PURPOSE.
68276788Sdelphij */
69127668Sbms
70276788Sdelphij#define ENC_HDRLEN	12
71276788Sdelphij
72276788Sdelphij/* From $OpenBSD: mbuf.h,v 1.56 2002/01/25 15:50:23 art Exp $	*/
73276788Sdelphij#define M_CONF		0x0400  /* packet was encrypted (ESP-transport) */
74276788Sdelphij#define M_AUTH		0x0800  /* packet was authenticated (AH) */
75276788Sdelphij
76276788Sdelphijstruct enchdr {
77276788Sdelphij	uint32_t af;
78276788Sdelphij	uint32_t spi;
79276788Sdelphij	uint32_t flags;
80276788Sdelphij};
81276788Sdelphij
82127668Sbms#define ENC_PRINT_TYPE(wh, xf, nam) \
83127668Sbms	if ((wh) & (xf)) { \
84276788Sdelphij		ND_PRINT((ndo, "%s%s", nam, (wh) == (xf) ? "): " : ",")); \
85127668Sbms		(wh) &= ~(xf); \
86127668Sbms	}
87127668Sbms
88127668Sbmsu_int
89276788Sdelphijenc_if_print(netdissect_options *ndo,
90276788Sdelphij             const struct pcap_pkthdr *h, register const u_char *p)
91127668Sbms{
92127668Sbms	register u_int length = h->len;
93127668Sbms	register u_int caplen = h->caplen;
94127668Sbms	int flags;
95127668Sbms	const struct enchdr *hdr;
96127668Sbms
97127668Sbms	if (caplen < ENC_HDRLEN) {
98276788Sdelphij		ND_PRINT((ndo, "[|enc]"));
99127668Sbms		goto out;
100127668Sbms	}
101127668Sbms
102313537Sglebius	hdr = (const struct enchdr *)p;
103127668Sbms	flags = hdr->flags;
104127668Sbms	if (flags == 0)
105276788Sdelphij		ND_PRINT((ndo, "(unprotected): "));
106127668Sbms	else
107276788Sdelphij		ND_PRINT((ndo, "("));
108127668Sbms	ENC_PRINT_TYPE(flags, M_AUTH, "authentic");
109127668Sbms	ENC_PRINT_TYPE(flags, M_CONF, "confidential");
110127668Sbms	/* ENC_PRINT_TYPE(flags, M_TUNNEL, "tunnel"); */
111276788Sdelphij	ND_PRINT((ndo, "SPI 0x%08x: ", EXTRACT_32BITS(&hdr->spi)));
112127668Sbms
113127668Sbms	length -= ENC_HDRLEN;
114190207Srpaulo	caplen -= ENC_HDRLEN;
115190207Srpaulo	p += ENC_HDRLEN;
116276788Sdelphij
117190207Srpaulo	switch (hdr->af) {
118190207Srpaulo	case AF_INET:
119276788Sdelphij		ip_print(ndo, p, length);
120190207Srpaulo		break;
121285275Spkelsey#ifdef AF_INET6
122190207Srpaulo	case AF_INET6:
123276788Sdelphij		ip6_print(ndo, p, length);
124190207Srpaulo		break;
125285275Spkelsey#endif
126190207Srpaulo	}
127127668Sbms
128127668Sbmsout:
129127668Sbms	return (ENC_HDRLEN);
130127668Sbms}
131146773Ssam
132146773Ssam
133146773Ssam/*
134146773Ssam * Local Variables:
135146773Ssam * c-style: whitesmith
136146773Ssam * c-basic-offset: 8
137146773Ssam * End:
138146773Ssam */
139