10f74e101Schristos /* 20f74e101Schristos * Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997 30f74e101Schristos * The Regents of the University of California. All rights reserved. 40f74e101Schristos * 50f74e101Schristos * Redistribution and use in source and binary forms, with or without 60f74e101Schristos * modification, are permitted provided that: (1) source code distributions 70f74e101Schristos * retain the above copyright notice and this paragraph in its entirety, (2) 80f74e101Schristos * distributions including binary code include the above copyright notice and 90f74e101Schristos * this paragraph in its entirety in the documentation or other materials 100f74e101Schristos * provided with the distribution, and (3) all advertising materials mentioning 110f74e101Schristos * features or use of this software display the following acknowledgement: 120f74e101Schristos * ``This product includes software developed by the University of California, 130f74e101Schristos * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 140f74e101Schristos * the University nor the names of its contributors may be used to endorse 150f74e101Schristos * or promote products derived from this software without specific prior 160f74e101Schristos * written permission. 170f74e101Schristos * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 180f74e101Schristos * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 190f74e101Schristos * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 200f74e101Schristos */ 210f74e101Schristos 2211b3aaa1Schristos #include <sys/cdefs.h> 230f74e101Schristos #ifndef lint 24*26ba0b50Schristos __RCSID("$NetBSD: print-ipfc.c,v 1.8 2024/09/02 16:15:31 christos Exp $"); 250f74e101Schristos #endif 260f74e101Schristos 27dc860a36Sspz /* \summary: IP over Fibre Channel printer */ 28dc860a36Sspz 29dc860a36Sspz /* specification: RFC 2625 */ 30dc860a36Sspz 31c74ad251Schristos #include <config.h> 320f74e101Schristos 33c74ad251Schristos #include "netdissect-stdinc.h" 340f74e101Schristos 350f74e101Schristos #include <string.h> 360f74e101Schristos 37c74ad251Schristos #define ND_LONGJMP_FROM_TCHECK 38fdccd7e4Schristos #include "netdissect.h" 390f74e101Schristos #include "addrtoname.h" 400f74e101Schristos 410f74e101Schristos 42b3a00663Schristos struct ipfc_header { 43c74ad251Schristos nd_byte ipfc_dhost[2+MAC_ADDR_LEN]; 44c74ad251Schristos nd_byte ipfc_shost[2+MAC_ADDR_LEN]; 45b3a00663Schristos }; 46b3a00663Schristos 47b3a00663Schristos #define IPFC_HDRLEN 16 48b3a00663Schristos 490f74e101Schristos /* Extract src, dst addresses */ 50c74ad251Schristos static void 510f74e101Schristos extract_ipfc_addrs(const struct ipfc_header *ipfcp, char *ipfcsrc, 520f74e101Schristos char *ipfcdst) 530f74e101Schristos { 540f74e101Schristos /* 550f74e101Schristos * We assume that, as per RFC 2625, the lower 48 bits of the 560f74e101Schristos * source and destination addresses are MAC addresses. 570f74e101Schristos */ 58c74ad251Schristos memcpy(ipfcdst, (const char *)&ipfcp->ipfc_dhost[2], MAC_ADDR_LEN); 59c74ad251Schristos memcpy(ipfcsrc, (const char *)&ipfcp->ipfc_shost[2], MAC_ADDR_LEN); 600f74e101Schristos } 610f74e101Schristos 620f74e101Schristos /* 630f74e101Schristos * Print the Network_Header 640f74e101Schristos */ 65c74ad251Schristos static void 66b3a00663Schristos ipfc_hdr_print(netdissect_options *ndo, 67c74ad251Schristos const struct ipfc_header *ipfcp _U_, u_int length, 68c74ad251Schristos const u_char *ipfcsrc, const u_char *ipfcdst) 690f74e101Schristos { 700f74e101Schristos const char *srcname, *dstname; 710f74e101Schristos 72b3a00663Schristos srcname = etheraddr_string(ndo, ipfcsrc); 73b3a00663Schristos dstname = etheraddr_string(ndo, ipfcdst); 740f74e101Schristos 750f74e101Schristos /* 76fdccd7e4Schristos * XXX - should we show the upper 16 bits of the addresses? 77fdccd7e4Schristos * Do so only if "vflag" is set? 78fdccd7e4Schristos * Section 3.3 "FC Port and Node Network Addresses" says that 79fdccd7e4Schristos * 80fdccd7e4Schristos * In this specification, both the Source and Destination 81fdccd7e4Schristos * 4-bit NAA identifiers SHALL be set to binary '0001' 82fdccd7e4Schristos * indicating that an IEEE 48-bit MAC address is contained 83fdccd7e4Schristos * in the lower 48 bits of the network address fields. The 84fdccd7e4Schristos * high order 12 bits in the network address fields SHALL 85fdccd7e4Schristos * be set to 0x0000. 86fdccd7e4Schristos * 87fdccd7e4Schristos * so, for captures following this specification, the upper 16 88fdccd7e4Schristos * bits should be 0x1000, followed by a MAC address. 890f74e101Schristos */ 90c74ad251Schristos ND_PRINT("%s > %s, length %u: ", srcname, dstname, length); 910f74e101Schristos } 920f74e101Schristos 93fdccd7e4Schristos static u_int 94b3a00663Schristos ipfc_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen) 950f74e101Schristos { 960f74e101Schristos const struct ipfc_header *ipfcp = (const struct ipfc_header *)p; 97c74ad251Schristos nd_mac_addr srcmac, dstmac; 98dc860a36Sspz struct lladdr_info src, dst; 99fdccd7e4Schristos int llc_hdrlen; 1000f74e101Schristos 101c74ad251Schristos ndo->ndo_protocol = "ipfc"; 102c74ad251Schristos ND_TCHECK_LEN(p, IPFC_HDRLEN); 1030f74e101Schristos /* 1040f74e101Schristos * Get the network addresses into a canonical form 1050f74e101Schristos */ 106c74ad251Schristos extract_ipfc_addrs(ipfcp, (char *)srcmac, (char *)dstmac); 1070f74e101Schristos 108b3a00663Schristos if (ndo->ndo_eflag) 109c74ad251Schristos ipfc_hdr_print(ndo, ipfcp, length, srcmac, dstmac); 1100f74e101Schristos 111c74ad251Schristos src.addr = srcmac; 112dc860a36Sspz src.addr_string = etheraddr_string; 113c74ad251Schristos dst.addr = dstmac; 114dc860a36Sspz dst.addr_string = etheraddr_string; 115dc860a36Sspz 1160f74e101Schristos /* Skip over Network_Header */ 1170f74e101Schristos length -= IPFC_HDRLEN; 1180f74e101Schristos p += IPFC_HDRLEN; 1190f74e101Schristos caplen -= IPFC_HDRLEN; 1200f74e101Schristos 1210f74e101Schristos /* Try to print the LLC-layer header & higher layers */ 122dc860a36Sspz llc_hdrlen = llc_print(ndo, p, length, caplen, &src, &dst); 123fdccd7e4Schristos if (llc_hdrlen < 0) { 1240f74e101Schristos /* 1250f74e101Schristos * Some kinds of LLC packet we cannot 1260f74e101Schristos * handle intelligently 1270f74e101Schristos */ 128b3a00663Schristos if (!ndo->ndo_suppress_default_print) 129b3a00663Schristos ND_DEFAULTPRINT(p, caplen); 130fdccd7e4Schristos llc_hdrlen = -llc_hdrlen; 1310f74e101Schristos } 132fdccd7e4Schristos return (IPFC_HDRLEN + llc_hdrlen); 1330f74e101Schristos } 1340f74e101Schristos 1350f74e101Schristos /* 1360f74e101Schristos * This is the top level routine of the printer. 'p' points 1370f74e101Schristos * to the Network_Header of the packet, 'h->ts' is the timestamp, 1380f74e101Schristos * 'h->len' is the length of the packet off the wire, and 'h->caplen' 1390f74e101Schristos * is the number of bytes actually captured. 1400f74e101Schristos */ 141c74ad251Schristos void 142c74ad251Schristos ipfc_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) 1430f74e101Schristos { 144c74ad251Schristos ndo->ndo_protocol = "ipfc"; 145c74ad251Schristos ndo->ndo_ll_hdr_len += ipfc_print(ndo, p, h->len, h->caplen); 1460f74e101Schristos } 147