Home | History | Annotate | Line # | Download | only in dist
print-enc.c revision 1.6
      1  1.1  christos /*	$OpenBSD: print-enc.c,v 1.7 2002/02/19 19:39:40 millert Exp $	*/
      2  1.1  christos 
      3  1.1  christos /*
      4  1.1  christos  * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996
      5  1.1  christos  *	The Regents of the University of California.  All rights reserved.
      6  1.1  christos  *
      7  1.1  christos  * Redistribution and use in source and binary forms, with or without
      8  1.1  christos  * modification, are permitted provided that: (1) source code distributions
      9  1.1  christos  * retain the above copyright notice and this paragraph in its entirety, (2)
     10  1.1  christos  * distributions including binary code include the above copyright notice and
     11  1.1  christos  * this paragraph in its entirety in the documentation or other materials
     12  1.1  christos  * provided with the distribution, and (3) all advertising materials mentioning
     13  1.1  christos  * features or use of this software display the following acknowledgement:
     14  1.1  christos  * ``This product includes software developed by the University of California,
     15  1.1  christos  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
     16  1.1  christos  * the University nor the names of its contributors may be used to endorse
     17  1.1  christos  * or promote products derived from this software without specific prior
     18  1.1  christos  * written permission.
     19  1.1  christos  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
     20  1.1  christos  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
     21  1.1  christos  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
     22  1.1  christos  */
     23  1.1  christos 
     24  1.2  christos #include <sys/cdefs.h>
     25  1.1  christos #ifndef lint
     26  1.6  christos __RCSID("$NetBSD: print-enc.c,v 1.6 2017/01/24 23:29:14 christos Exp $");
     27  1.1  christos #endif
     28  1.1  christos 
     29  1.1  christos #ifdef HAVE_CONFIG_H
     30  1.1  christos #include "config.h"
     31  1.1  christos #endif
     32  1.1  christos 
     33  1.6  christos #include <netdissect-stdinc.h>
     34  1.1  christos 
     35  1.6  christos #include "netdissect.h"
     36  1.1  christos #include "extract.h"
     37  1.1  christos 
     38  1.4  christos /* From $OpenBSD: if_enc.h,v 1.8 2001/06/25 05:14:00 angelos Exp $ */
     39  1.4  christos /*
     40  1.4  christos  * The authors of this code are John Ioannidis (ji (at) tla.org),
     41  1.4  christos  * Angelos D. Keromytis (kermit (at) csd.uch.gr) and
     42  1.4  christos  * Niels Provos (provos (at) physnet.uni-hamburg.de).
     43  1.4  christos  *
     44  1.4  christos  * This code was written by John Ioannidis for BSD/OS in Athens, Greece,
     45  1.4  christos  * in November 1995.
     46  1.4  christos  *
     47  1.4  christos  * Ported to OpenBSD and NetBSD, with additional transforms, in December 1996,
     48  1.4  christos  * by Angelos D. Keromytis.
     49  1.4  christos  *
     50  1.4  christos  * Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis
     51  1.4  christos  * and Niels Provos.
     52  1.4  christos  *
     53  1.4  christos  * Copyright (C) 1995, 1996, 1997, 1998 by John Ioannidis, Angelos D. Keromytis
     54  1.4  christos  * and Niels Provos.
     55  1.4  christos  * Copyright (c) 2001, Angelos D. Keromytis.
     56  1.4  christos  *
     57  1.4  christos  * Permission to use, copy, and modify this software with or without fee
     58  1.4  christos  * is hereby granted, provided that this entire notice is included in
     59  1.4  christos  * all copies of any software which is or includes a copy or
     60  1.4  christos  * modification of this software.
     61  1.4  christos  * You may use this code under the GNU public license if you so wish. Please
     62  1.4  christos  * contribute changes back to the authors under this freer than GPL license
     63  1.4  christos  * so that we may further the use of strong encryption without limitations to
     64  1.4  christos  * all.
     65  1.4  christos  *
     66  1.4  christos  * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
     67  1.4  christos  * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
     68  1.4  christos  * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
     69  1.4  christos  * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
     70  1.4  christos  * PURPOSE.
     71  1.4  christos  */
     72  1.4  christos 
     73  1.4  christos #define ENC_HDRLEN	12
     74  1.4  christos 
     75  1.4  christos /* From $OpenBSD: mbuf.h,v 1.56 2002/01/25 15:50:23 art Exp $	*/
     76  1.4  christos #define M_CONF		0x0400  /* packet was encrypted (ESP-transport) */
     77  1.4  christos #define M_AUTH		0x0800  /* packet was authenticated (AH) */
     78  1.4  christos 
     79  1.4  christos struct enchdr {
     80  1.4  christos 	uint32_t af;
     81  1.4  christos 	uint32_t spi;
     82  1.4  christos 	uint32_t flags;
     83  1.4  christos };
     84  1.1  christos 
     85  1.1  christos #define ENC_PRINT_TYPE(wh, xf, nam) \
     86  1.1  christos 	if ((wh) & (xf)) { \
     87  1.4  christos 		ND_PRINT((ndo, "%s%s", nam, (wh) == (xf) ? "): " : ",")); \
     88  1.1  christos 		(wh) &= ~(xf); \
     89  1.1  christos 	}
     90  1.1  christos 
     91  1.1  christos u_int
     92  1.4  christos enc_if_print(netdissect_options *ndo,
     93  1.4  christos              const struct pcap_pkthdr *h, register const u_char *p)
     94  1.1  christos {
     95  1.1  christos 	register u_int length = h->len;
     96  1.1  christos 	register u_int caplen = h->caplen;
     97  1.1  christos 	int flags;
     98  1.1  christos 	const struct enchdr *hdr;
     99  1.1  christos 
    100  1.1  christos 	if (caplen < ENC_HDRLEN) {
    101  1.4  christos 		ND_PRINT((ndo, "[|enc]"));
    102  1.1  christos 		goto out;
    103  1.1  christos 	}
    104  1.1  christos 
    105  1.6  christos 	hdr = (const struct enchdr *)p;
    106  1.1  christos 	flags = hdr->flags;
    107  1.1  christos 	if (flags == 0)
    108  1.4  christos 		ND_PRINT((ndo, "(unprotected): "));
    109  1.1  christos 	else
    110  1.4  christos 		ND_PRINT((ndo, "("));
    111  1.1  christos 	ENC_PRINT_TYPE(flags, M_AUTH, "authentic");
    112  1.1  christos 	ENC_PRINT_TYPE(flags, M_CONF, "confidential");
    113  1.1  christos 	/* ENC_PRINT_TYPE(flags, M_TUNNEL, "tunnel"); */
    114  1.4  christos 	ND_PRINT((ndo, "SPI 0x%08x: ", EXTRACT_32BITS(&hdr->spi)));
    115  1.1  christos 
    116  1.1  christos 	length -= ENC_HDRLEN;
    117  1.1  christos 	caplen -= ENC_HDRLEN;
    118  1.1  christos 	p += ENC_HDRLEN;
    119  1.4  christos 
    120  1.1  christos 	switch (hdr->af) {
    121  1.1  christos 	case AF_INET:
    122  1.4  christos 		ip_print(ndo, p, length);
    123  1.1  christos 		break;
    124  1.5  christos #ifdef AF_INET6
    125  1.1  christos 	case AF_INET6:
    126  1.4  christos 		ip6_print(ndo, p, length);
    127  1.1  christos 		break;
    128  1.5  christos #endif
    129  1.1  christos 	}
    130  1.1  christos 
    131  1.1  christos out:
    132  1.1  christos 	return (ENC_HDRLEN);
    133  1.1  christos }
    134  1.1  christos 
    135  1.1  christos 
    136  1.1  christos /*
    137  1.1  christos  * Local Variables:
    138  1.1  christos  * c-style: whitesmith
    139  1.1  christos  * c-basic-offset: 8
    140  1.1  christos  * End:
    141  1.1  christos  */
    142