blob: ab5a81312f68832584634c225c3304bcae859e6f [file] [log] [blame]
The Android Open Source Project2949f582009-03-03 19:30:46 -08001/*
2 * Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 */
21
Elliott Hughese2e3bd12017-05-15 10:59:29 -070022/* \summary: IP over Fibre Channel printer */
23
24/* specification: RFC 2625 */
25
The Android Open Source Project2949f582009-03-03 19:30:46 -080026#ifdef HAVE_CONFIG_H
Elliott Hughes820eced2021-08-20 18:00:50 -070027#include <config.h>
The Android Open Source Project2949f582009-03-03 19:30:46 -080028#endif
29
Elliott Hughes820eced2021-08-20 18:00:50 -070030#include "netdissect-stdinc.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080031
The Android Open Source Project2949f582009-03-03 19:30:46 -080032#include <string.h>
33
Elliott Hughes820eced2021-08-20 18:00:50 -070034#define ND_LONGJMP_FROM_TCHECK
Elliott Hughese2e3bd12017-05-15 10:59:29 -070035#include "netdissect.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080036#include "addrtoname.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080037
The Android Open Source Project2949f582009-03-03 19:30:46 -080038
Elliott Hughes892a68b2015-10-19 14:43:53 -070039struct ipfc_header {
Elliott Hughes820eced2021-08-20 18:00:50 -070040 nd_byte ipfc_dhost[2+MAC_ADDR_LEN];
41 nd_byte ipfc_shost[2+MAC_ADDR_LEN];
Elliott Hughes892a68b2015-10-19 14:43:53 -070042};
43
44#define IPFC_HDRLEN 16
45
The Android Open Source Project2949f582009-03-03 19:30:46 -080046/* Extract src, dst addresses */
Elliott Hughes820eced2021-08-20 18:00:50 -070047static void
The Android Open Source Project2949f582009-03-03 19:30:46 -080048extract_ipfc_addrs(const struct ipfc_header *ipfcp, char *ipfcsrc,
Elliott Hughes820eced2021-08-20 18:00:50 -070049 char *ipfcdst)
The Android Open Source Project2949f582009-03-03 19:30:46 -080050{
51 /*
52 * We assume that, as per RFC 2625, the lower 48 bits of the
53 * source and destination addresses are MAC addresses.
54 */
Elliott Hughes820eced2021-08-20 18:00:50 -070055 memcpy(ipfcdst, (const char *)&ipfcp->ipfc_dhost[2], MAC_ADDR_LEN);
56 memcpy(ipfcsrc, (const char *)&ipfcp->ipfc_shost[2], MAC_ADDR_LEN);
The Android Open Source Project2949f582009-03-03 19:30:46 -080057}
58
59/*
60 * Print the Network_Header
61 */
Elliott Hughes820eced2021-08-20 18:00:50 -070062static void
Elliott Hughes892a68b2015-10-19 14:43:53 -070063ipfc_hdr_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -070064 const struct ipfc_header *ipfcp _U_, u_int length,
65 const u_char *ipfcsrc, const u_char *ipfcdst)
The Android Open Source Project2949f582009-03-03 19:30:46 -080066{
67 const char *srcname, *dstname;
68
Elliott Hughes892a68b2015-10-19 14:43:53 -070069 srcname = etheraddr_string(ndo, ipfcsrc);
70 dstname = etheraddr_string(ndo, ipfcdst);
The Android Open Source Project2949f582009-03-03 19:30:46 -080071
72 /*
Elliott Hughese2e3bd12017-05-15 10:59:29 -070073 * XXX - should we show the upper 16 bits of the addresses?
74 * Do so only if "vflag" is set?
75 * Section 3.3 "FC Port and Node Network Addresses" says that
76 *
77 * In this specification, both the Source and Destination
78 * 4-bit NAA identifiers SHALL be set to binary '0001'
79 * indicating that an IEEE 48-bit MAC address is contained
80 * in the lower 48 bits of the network address fields. The
81 * high order 12 bits in the network address fields SHALL
82 * be set to 0x0000.
83 *
84 * so, for captures following this specification, the upper 16
85 * bits should be 0x1000, followed by a MAC address.
The Android Open Source Project2949f582009-03-03 19:30:46 -080086 */
Elliott Hughes820eced2021-08-20 18:00:50 -070087 ND_PRINT("%s > %s, length %u: ", srcname, dstname, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -080088}
89
Elliott Hughese2e3bd12017-05-15 10:59:29 -070090static u_int
Elliott Hughes892a68b2015-10-19 14:43:53 -070091ipfc_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen)
The Android Open Source Project2949f582009-03-03 19:30:46 -080092{
93 const struct ipfc_header *ipfcp = (const struct ipfc_header *)p;
Elliott Hughes820eced2021-08-20 18:00:50 -070094 nd_mac_addr srcmac, dstmac;
Elliott Hughese2e3bd12017-05-15 10:59:29 -070095 struct lladdr_info src, dst;
96 int llc_hdrlen;
The Android Open Source Project2949f582009-03-03 19:30:46 -080097
Elliott Hughes820eced2021-08-20 18:00:50 -070098 ndo->ndo_protocol = "ipfc";
99 ND_TCHECK_LEN(p, IPFC_HDRLEN);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800100 /*
101 * Get the network addresses into a canonical form
102 */
Elliott Hughes820eced2021-08-20 18:00:50 -0700103 extract_ipfc_addrs(ipfcp, (char *)srcmac, (char *)dstmac);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800104
Elliott Hughes892a68b2015-10-19 14:43:53 -0700105 if (ndo->ndo_eflag)
Elliott Hughes820eced2021-08-20 18:00:50 -0700106 ipfc_hdr_print(ndo, ipfcp, length, srcmac, dstmac);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800107
Elliott Hughes820eced2021-08-20 18:00:50 -0700108 src.addr = srcmac;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700109 src.addr_string = etheraddr_string;
Elliott Hughes820eced2021-08-20 18:00:50 -0700110 dst.addr = dstmac;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700111 dst.addr_string = etheraddr_string;
112
The Android Open Source Project2949f582009-03-03 19:30:46 -0800113 /* Skip over Network_Header */
114 length -= IPFC_HDRLEN;
115 p += IPFC_HDRLEN;
116 caplen -= IPFC_HDRLEN;
117
118 /* Try to print the LLC-layer header & higher layers */
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700119 llc_hdrlen = llc_print(ndo, p, length, caplen, &src, &dst);
120 if (llc_hdrlen < 0) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800121 /*
122 * Some kinds of LLC packet we cannot
123 * handle intelligently
124 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700125 if (!ndo->ndo_suppress_default_print)
126 ND_DEFAULTPRINT(p, caplen);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700127 llc_hdrlen = -llc_hdrlen;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800128 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700129 return (IPFC_HDRLEN + llc_hdrlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800130}
131
132/*
133 * This is the top level routine of the printer. 'p' points
134 * to the Network_Header of the packet, 'h->ts' is the timestamp,
135 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
136 * is the number of bytes actually captured.
137 */
Elliott Hughes820eced2021-08-20 18:00:50 -0700138void
139ipfc_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800140{
Elliott Hughes820eced2021-08-20 18:00:50 -0700141 ndo->ndo_protocol = "ipfc";
142 ndo->ndo_ll_hdr_len += ipfc_print(ndo, p, h->len, h->caplen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800143}