The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1 | /* |
| 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 Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 22 | /* \summary: IP over Fibre Channel printer */ |
| 23 | |
| 24 | /* specification: RFC 2625 */ |
| 25 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 26 | #ifdef HAVE_CONFIG_H |
| 27 | #include "config.h" |
| 28 | #endif |
| 29 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 30 | #include <netdissect-stdinc.h> |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 31 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 32 | #include <string.h> |
| 33 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 34 | #include "netdissect.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 35 | #include "addrtoname.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 36 | |
| 37 | #include "ether.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 38 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 39 | struct ipfc_header { |
| 40 | u_char ipfc_dhost[8]; |
| 41 | u_char ipfc_shost[8]; |
| 42 | }; |
| 43 | |
| 44 | #define IPFC_HDRLEN 16 |
| 45 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 46 | /* Extract src, dst addresses */ |
| 47 | static inline void |
| 48 | extract_ipfc_addrs(const struct ipfc_header *ipfcp, char *ipfcsrc, |
| 49 | char *ipfcdst) |
| 50 | { |
| 51 | /* |
| 52 | * We assume that, as per RFC 2625, the lower 48 bits of the |
| 53 | * source and destination addresses are MAC addresses. |
| 54 | */ |
| 55 | memcpy(ipfcdst, (const char *)&ipfcp->ipfc_dhost[2], 6); |
| 56 | memcpy(ipfcsrc, (const char *)&ipfcp->ipfc_shost[2], 6); |
| 57 | } |
| 58 | |
| 59 | /* |
| 60 | * Print the Network_Header |
| 61 | */ |
| 62 | static inline void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 63 | ipfc_hdr_print(netdissect_options *ndo, |
| 64 | register const struct ipfc_header *ipfcp _U_, |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 65 | register u_int length, register const u_char *ipfcsrc, |
| 66 | register const u_char *ipfcdst) |
| 67 | { |
| 68 | const char *srcname, *dstname; |
| 69 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 70 | srcname = etheraddr_string(ndo, ipfcsrc); |
| 71 | dstname = etheraddr_string(ndo, ipfcdst); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 72 | |
| 73 | /* |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 74 | * XXX - should we show the upper 16 bits of the addresses? |
| 75 | * Do so only if "vflag" is set? |
| 76 | * Section 3.3 "FC Port and Node Network Addresses" says that |
| 77 | * |
| 78 | * In this specification, both the Source and Destination |
| 79 | * 4-bit NAA identifiers SHALL be set to binary '0001' |
| 80 | * indicating that an IEEE 48-bit MAC address is contained |
| 81 | * in the lower 48 bits of the network address fields. The |
| 82 | * high order 12 bits in the network address fields SHALL |
| 83 | * be set to 0x0000. |
| 84 | * |
| 85 | * so, for captures following this specification, the upper 16 |
| 86 | * bits should be 0x1000, followed by a MAC address. |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 87 | */ |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 88 | ND_PRINT((ndo, "%s > %s, length %u: ", srcname, dstname, length)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 89 | } |
| 90 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 91 | static u_int |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 92 | ipfc_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 93 | { |
| 94 | const struct ipfc_header *ipfcp = (const struct ipfc_header *)p; |
| 95 | struct ether_header ehdr; |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 96 | struct lladdr_info src, dst; |
| 97 | int llc_hdrlen; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 98 | |
| 99 | if (caplen < IPFC_HDRLEN) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 100 | ND_PRINT((ndo, "[|ipfc]")); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 101 | return (caplen); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 102 | } |
| 103 | /* |
| 104 | * Get the network addresses into a canonical form |
| 105 | */ |
| 106 | extract_ipfc_addrs(ipfcp, (char *)ESRC(&ehdr), (char *)EDST(&ehdr)); |
| 107 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 108 | if (ndo->ndo_eflag) |
| 109 | ipfc_hdr_print(ndo, ipfcp, length, ESRC(&ehdr), EDST(&ehdr)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 110 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 111 | src.addr = ESRC(&ehdr); |
| 112 | src.addr_string = etheraddr_string; |
| 113 | dst.addr = EDST(&ehdr); |
| 114 | dst.addr_string = etheraddr_string; |
| 115 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 116 | /* Skip over Network_Header */ |
| 117 | length -= IPFC_HDRLEN; |
| 118 | p += IPFC_HDRLEN; |
| 119 | caplen -= IPFC_HDRLEN; |
| 120 | |
| 121 | /* Try to print the LLC-layer header & higher layers */ |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 122 | llc_hdrlen = llc_print(ndo, p, length, caplen, &src, &dst); |
| 123 | if (llc_hdrlen < 0) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 124 | /* |
| 125 | * Some kinds of LLC packet we cannot |
| 126 | * handle intelligently |
| 127 | */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 128 | if (!ndo->ndo_suppress_default_print) |
| 129 | ND_DEFAULTPRINT(p, caplen); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 130 | llc_hdrlen = -llc_hdrlen; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 131 | } |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 132 | return (IPFC_HDRLEN + llc_hdrlen); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | /* |
| 136 | * This is the top level routine of the printer. 'p' points |
| 137 | * to the Network_Header of the packet, 'h->ts' is the timestamp, |
| 138 | * 'h->len' is the length of the packet off the wire, and 'h->caplen' |
| 139 | * is the number of bytes actually captured. |
| 140 | */ |
| 141 | u_int |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 142 | ipfc_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, register const u_char *p) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 143 | { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 144 | return (ipfc_print(ndo, p, h->len, h->caplen)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 145 | } |