xref: /dflybsd-src/contrib/tcpdump/print-ipfc.c (revision 59c07fbdf8168fa08c76c515186d561b5a92690c)
141c99275SPeter Avalos /*
241c99275SPeter Avalos  * Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997
341c99275SPeter Avalos  *	The Regents of the University of California.  All rights reserved.
441c99275SPeter Avalos  *
541c99275SPeter Avalos  * Redistribution and use in source and binary forms, with or without
641c99275SPeter Avalos  * modification, are permitted provided that: (1) source code distributions
741c99275SPeter Avalos  * retain the above copyright notice and this paragraph in its entirety, (2)
841c99275SPeter Avalos  * distributions including binary code include the above copyright notice and
941c99275SPeter Avalos  * this paragraph in its entirety in the documentation or other materials
1041c99275SPeter Avalos  * provided with the distribution, and (3) all advertising materials mentioning
1141c99275SPeter Avalos  * features or use of this software display the following acknowledgement:
1241c99275SPeter Avalos  * ``This product includes software developed by the University of California,
1341c99275SPeter Avalos  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
1441c99275SPeter Avalos  * the University nor the names of its contributors may be used to endorse
1541c99275SPeter Avalos  * or promote products derived from this software without specific prior
1641c99275SPeter Avalos  * written permission.
1741c99275SPeter Avalos  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
1841c99275SPeter Avalos  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1941c99275SPeter Avalos  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2041c99275SPeter Avalos  */
2141c99275SPeter Avalos 
22411677aeSAaron LI /* \summary: IP over Fibre Channel printer */
23411677aeSAaron LI 
24411677aeSAaron LI /* specification: RFC 2625 */
2541c99275SPeter Avalos 
2641c99275SPeter Avalos #ifdef HAVE_CONFIG_H
27*ed775ee7SAntonio Huete Jimenez #include <config.h>
2841c99275SPeter Avalos #endif
2941c99275SPeter Avalos 
30*ed775ee7SAntonio Huete Jimenez #include "netdissect-stdinc.h"
3141c99275SPeter Avalos 
3241c99275SPeter Avalos #include <string.h>
3341c99275SPeter Avalos 
34*ed775ee7SAntonio Huete Jimenez #define ND_LONGJMP_FROM_TCHECK
35411677aeSAaron LI #include "netdissect.h"
3641c99275SPeter Avalos #include "addrtoname.h"
3741c99275SPeter Avalos 
3841c99275SPeter Avalos 
39411677aeSAaron LI struct ipfc_header {
40*ed775ee7SAntonio Huete Jimenez 	nd_byte ipfc_dhost[2+MAC_ADDR_LEN];
41*ed775ee7SAntonio Huete Jimenez 	nd_byte ipfc_shost[2+MAC_ADDR_LEN];
42411677aeSAaron LI };
43411677aeSAaron LI 
44411677aeSAaron LI #define IPFC_HDRLEN 16
4541c99275SPeter Avalos 
4641c99275SPeter Avalos /* Extract src, dst addresses */
47*ed775ee7SAntonio Huete Jimenez static void
extract_ipfc_addrs(const struct ipfc_header * ipfcp,char * ipfcsrc,char * ipfcdst)4841c99275SPeter Avalos extract_ipfc_addrs(const struct ipfc_header *ipfcp, char *ipfcsrc,
4941c99275SPeter Avalos 		   char *ipfcdst)
5041c99275SPeter Avalos {
5141c99275SPeter Avalos 	/*
5241c99275SPeter Avalos 	 * We assume that, as per RFC 2625, the lower 48 bits of the
5341c99275SPeter Avalos 	 * source and destination addresses are MAC addresses.
5441c99275SPeter Avalos 	 */
55*ed775ee7SAntonio Huete Jimenez 	memcpy(ipfcdst, (const char *)&ipfcp->ipfc_dhost[2], MAC_ADDR_LEN);
56*ed775ee7SAntonio Huete Jimenez 	memcpy(ipfcsrc, (const char *)&ipfcp->ipfc_shost[2], MAC_ADDR_LEN);
5741c99275SPeter Avalos }
5841c99275SPeter Avalos 
5941c99275SPeter Avalos /*
6041c99275SPeter Avalos  * Print the Network_Header
6141c99275SPeter Avalos  */
62*ed775ee7SAntonio Huete Jimenez static void
ipfc_hdr_print(netdissect_options * ndo,const struct ipfc_header * ipfcp _U_,u_int length,const u_char * ipfcsrc,const u_char * ipfcdst)63411677aeSAaron LI ipfc_hdr_print(netdissect_options *ndo,
64*ed775ee7SAntonio Huete Jimenez 	       const struct ipfc_header *ipfcp _U_, u_int length,
65*ed775ee7SAntonio Huete Jimenez 	       const u_char *ipfcsrc, const u_char *ipfcdst)
6641c99275SPeter Avalos {
6741c99275SPeter Avalos 	const char *srcname, *dstname;
6841c99275SPeter Avalos 
69411677aeSAaron LI 	srcname = etheraddr_string(ndo, ipfcsrc);
70411677aeSAaron LI 	dstname = etheraddr_string(ndo, ipfcdst);
7141c99275SPeter Avalos 
7241c99275SPeter Avalos 	/*
73411677aeSAaron LI 	 * XXX - should we show the upper 16 bits of the addresses?
74411677aeSAaron LI 	 * Do so only if "vflag" is set?
75411677aeSAaron LI 	 * Section 3.3 "FC Port and Node Network Addresses" says that
76411677aeSAaron LI 	 *
77411677aeSAaron LI 	 *    In this specification, both the Source and Destination
78411677aeSAaron LI 	 *    4-bit NAA identifiers SHALL be set to binary '0001'
79411677aeSAaron LI 	 *    indicating that an IEEE 48-bit MAC address is contained
80411677aeSAaron LI 	 *    in the lower 48 bits of the network address fields. The
81411677aeSAaron LI 	 *    high order 12 bits in the network address fields SHALL
82411677aeSAaron LI 	 *    be set to 0x0000.
83411677aeSAaron LI 	 *
84411677aeSAaron LI 	 * so, for captures following this specification, the upper 16
85411677aeSAaron LI 	 * bits should be 0x1000, followed by a MAC address.
8641c99275SPeter Avalos 	 */
87*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("%s > %s, length %u: ", srcname, dstname, length);
8841c99275SPeter Avalos }
8941c99275SPeter Avalos 
90411677aeSAaron LI static u_int
ipfc_print(netdissect_options * ndo,const u_char * p,u_int length,u_int caplen)91411677aeSAaron LI ipfc_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen)
9241c99275SPeter Avalos {
9341c99275SPeter Avalos 	const struct ipfc_header *ipfcp = (const struct ipfc_header *)p;
94*ed775ee7SAntonio Huete Jimenez 	nd_mac_addr srcmac, dstmac;
95411677aeSAaron LI 	struct lladdr_info src, dst;
96411677aeSAaron LI 	int llc_hdrlen;
9741c99275SPeter Avalos 
98*ed775ee7SAntonio Huete Jimenez 	ndo->ndo_protocol = "ipfc";
99*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_LEN(p, IPFC_HDRLEN);
10041c99275SPeter Avalos 	/*
10141c99275SPeter Avalos 	 * Get the network addresses into a canonical form
10241c99275SPeter Avalos 	 */
103*ed775ee7SAntonio Huete Jimenez 	extract_ipfc_addrs(ipfcp, (char *)srcmac, (char *)dstmac);
10441c99275SPeter Avalos 
105411677aeSAaron LI 	if (ndo->ndo_eflag)
106*ed775ee7SAntonio Huete Jimenez 		ipfc_hdr_print(ndo, ipfcp, length, srcmac, dstmac);
107411677aeSAaron LI 
108*ed775ee7SAntonio Huete Jimenez 	src.addr = srcmac;
109411677aeSAaron LI 	src.addr_string = etheraddr_string;
110*ed775ee7SAntonio Huete Jimenez 	dst.addr = dstmac;
111411677aeSAaron LI 	dst.addr_string = etheraddr_string;
11241c99275SPeter Avalos 
11341c99275SPeter Avalos 	/* Skip over Network_Header */
11441c99275SPeter Avalos 	length -= IPFC_HDRLEN;
11541c99275SPeter Avalos 	p += IPFC_HDRLEN;
11641c99275SPeter Avalos 	caplen -= IPFC_HDRLEN;
11741c99275SPeter Avalos 
11841c99275SPeter Avalos 	/* Try to print the LLC-layer header & higher layers */
119411677aeSAaron LI 	llc_hdrlen = llc_print(ndo, p, length, caplen, &src, &dst);
120411677aeSAaron LI 	if (llc_hdrlen < 0) {
12141c99275SPeter Avalos 		/*
12241c99275SPeter Avalos 		 * Some kinds of LLC packet we cannot
12341c99275SPeter Avalos 		 * handle intelligently
12441c99275SPeter Avalos 		 */
125411677aeSAaron LI 		if (!ndo->ndo_suppress_default_print)
126411677aeSAaron LI 			ND_DEFAULTPRINT(p, caplen);
127411677aeSAaron LI 		llc_hdrlen = -llc_hdrlen;
12841c99275SPeter Avalos 	}
129411677aeSAaron LI 	return (IPFC_HDRLEN + llc_hdrlen);
13041c99275SPeter Avalos }
13141c99275SPeter Avalos 
13241c99275SPeter Avalos /*
13341c99275SPeter Avalos  * This is the top level routine of the printer.  'p' points
13441c99275SPeter Avalos  * to the Network_Header of the packet, 'h->ts' is the timestamp,
13541c99275SPeter Avalos  * 'h->len' is the length of the packet off the wire, and 'h->caplen'
13641c99275SPeter Avalos  * is the number of bytes actually captured.
13741c99275SPeter Avalos  */
138*ed775ee7SAntonio Huete Jimenez void
ipfc_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)139*ed775ee7SAntonio Huete Jimenez ipfc_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
14041c99275SPeter Avalos {
141*ed775ee7SAntonio Huete Jimenez 	ndo->ndo_protocol = "ipfc";
142*ed775ee7SAntonio Huete Jimenez 	ndo->ndo_ll_hdr_len += ipfc_print(ndo, p, h->len, h->caplen);
14341c99275SPeter Avalos }
144