1*ee67461eSJoseph Mingrone /* 2*ee67461eSJoseph Mingrone * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 3*ee67461eSJoseph Mingrone * 1997, 2000, 2011, 2012 4*ee67461eSJoseph Mingrone * The Regents of the University of California. All rights reserved. 5*ee67461eSJoseph Mingrone * 6*ee67461eSJoseph Mingrone * Redistribution and use in source and binary forms, with or without 7*ee67461eSJoseph Mingrone * modification, are permitted provided that: (1) source code distributions 8*ee67461eSJoseph Mingrone * retain the above copyright notice and this paragraph in its entirety, (2) 9*ee67461eSJoseph Mingrone * distributions including binary code include the above copyright notice and 10*ee67461eSJoseph Mingrone * this paragraph in its entirety in the documentation or other materials 11*ee67461eSJoseph Mingrone * provided with the distribution, and (3) all advertising materials mentioning 12*ee67461eSJoseph Mingrone * features or use of this software display the following acknowledgement: 13*ee67461eSJoseph Mingrone * ``This product includes software developed by the University of California, 14*ee67461eSJoseph Mingrone * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 15*ee67461eSJoseph Mingrone * the University nor the names of its contributors may be used to endorse 16*ee67461eSJoseph Mingrone * or promote products derived from this software without specific prior 17*ee67461eSJoseph Mingrone * written permission. 18*ee67461eSJoseph Mingrone * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 19*ee67461eSJoseph Mingrone * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 20*ee67461eSJoseph Mingrone * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 21*ee67461eSJoseph Mingrone */ 22*ee67461eSJoseph Mingrone /* 23*ee67461eSJoseph Mingrone * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. 24*ee67461eSJoseph Mingrone */ 25*ee67461eSJoseph Mingrone 26*ee67461eSJoseph Mingrone /* \summary: IP-over-InfiniBand (IPoIB) printer */ 27*ee67461eSJoseph Mingrone 28*ee67461eSJoseph Mingrone #include <config.h> 29*ee67461eSJoseph Mingrone 30*ee67461eSJoseph Mingrone #include "netdissect-stdinc.h" 31*ee67461eSJoseph Mingrone 32*ee67461eSJoseph Mingrone #include "netdissect.h" 33*ee67461eSJoseph Mingrone #include "extract.h" 34*ee67461eSJoseph Mingrone #include "addrtoname.h" 35*ee67461eSJoseph Mingrone 36*ee67461eSJoseph Mingrone 37*ee67461eSJoseph Mingrone extern const struct tok ethertype_values[]; 38*ee67461eSJoseph Mingrone 39*ee67461eSJoseph Mingrone #define IPOIB_HDRLEN 44 40*ee67461eSJoseph Mingrone 41*ee67461eSJoseph Mingrone static inline void 42*ee67461eSJoseph Mingrone ipoib_hdr_print(netdissect_options *ndo, const u_char *bp, u_int length) 43*ee67461eSJoseph Mingrone { 44*ee67461eSJoseph Mingrone uint16_t ether_type; 45*ee67461eSJoseph Mingrone 46*ee67461eSJoseph Mingrone ether_type = GET_BE_U_2(bp + 40); 47*ee67461eSJoseph Mingrone if (!ndo->ndo_qflag) { 48*ee67461eSJoseph Mingrone ND_PRINT(", ethertype %s (0x%04x)", 49*ee67461eSJoseph Mingrone tok2str(ethertype_values,"Unknown", ether_type), 50*ee67461eSJoseph Mingrone ether_type); 51*ee67461eSJoseph Mingrone } else { 52*ee67461eSJoseph Mingrone ND_PRINT(", ethertype %s", 53*ee67461eSJoseph Mingrone tok2str(ethertype_values,"Unknown", ether_type)); 54*ee67461eSJoseph Mingrone } 55*ee67461eSJoseph Mingrone 56*ee67461eSJoseph Mingrone ND_PRINT(", length %u: ", length); 57*ee67461eSJoseph Mingrone } 58*ee67461eSJoseph Mingrone 59*ee67461eSJoseph Mingrone /* 60*ee67461eSJoseph Mingrone * Print an InfiniBand frame. 61*ee67461eSJoseph Mingrone * This might be encapsulated within another frame; we might be passed 62*ee67461eSJoseph Mingrone * a pointer to a function that can print header information for that 63*ee67461eSJoseph Mingrone * frame's protocol, and an argument to pass to that function. 64*ee67461eSJoseph Mingrone */ 65*ee67461eSJoseph Mingrone static void 66*ee67461eSJoseph Mingrone ipoib_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen, 67*ee67461eSJoseph Mingrone void (*print_encap_header)(const u_char *), const u_char *encap_header_arg) 68*ee67461eSJoseph Mingrone { 69*ee67461eSJoseph Mingrone const u_char *orig_hdr = p; 70*ee67461eSJoseph Mingrone u_int orig_length; 71*ee67461eSJoseph Mingrone u_short ether_type; 72*ee67461eSJoseph Mingrone 73*ee67461eSJoseph Mingrone if (caplen < IPOIB_HDRLEN) { 74*ee67461eSJoseph Mingrone nd_print_trunc(ndo); 75*ee67461eSJoseph Mingrone ndo->ndo_ll_hdr_len += caplen; 76*ee67461eSJoseph Mingrone return; 77*ee67461eSJoseph Mingrone } 78*ee67461eSJoseph Mingrone 79*ee67461eSJoseph Mingrone if (length < IPOIB_HDRLEN) { 80*ee67461eSJoseph Mingrone nd_print_trunc(ndo); 81*ee67461eSJoseph Mingrone ndo->ndo_ll_hdr_len += length; 82*ee67461eSJoseph Mingrone return; 83*ee67461eSJoseph Mingrone } 84*ee67461eSJoseph Mingrone 85*ee67461eSJoseph Mingrone if (ndo->ndo_eflag) { 86*ee67461eSJoseph Mingrone nd_print_protocol_caps(ndo); 87*ee67461eSJoseph Mingrone if (print_encap_header != NULL) 88*ee67461eSJoseph Mingrone (*print_encap_header)(encap_header_arg); 89*ee67461eSJoseph Mingrone ipoib_hdr_print(ndo, p, length); 90*ee67461eSJoseph Mingrone } 91*ee67461eSJoseph Mingrone orig_length = length; 92*ee67461eSJoseph Mingrone 93*ee67461eSJoseph Mingrone ndo->ndo_ll_hdr_len += IPOIB_HDRLEN; 94*ee67461eSJoseph Mingrone length -= IPOIB_HDRLEN; 95*ee67461eSJoseph Mingrone caplen -= IPOIB_HDRLEN; 96*ee67461eSJoseph Mingrone ether_type = GET_BE_U_2(p + 40); 97*ee67461eSJoseph Mingrone p += IPOIB_HDRLEN; 98*ee67461eSJoseph Mingrone 99*ee67461eSJoseph Mingrone if (ethertype_print(ndo, ether_type, p, length, caplen, NULL, NULL) == 0) { 100*ee67461eSJoseph Mingrone /* ether_type not known, print raw packet */ 101*ee67461eSJoseph Mingrone if (!ndo->ndo_eflag) { 102*ee67461eSJoseph Mingrone if (print_encap_header != NULL) 103*ee67461eSJoseph Mingrone (*print_encap_header)(encap_header_arg); 104*ee67461eSJoseph Mingrone ipoib_hdr_print(ndo, orig_hdr , orig_length); 105*ee67461eSJoseph Mingrone } 106*ee67461eSJoseph Mingrone 107*ee67461eSJoseph Mingrone if (!ndo->ndo_suppress_default_print) 108*ee67461eSJoseph Mingrone ND_DEFAULTPRINT(p, caplen); 109*ee67461eSJoseph Mingrone } 110*ee67461eSJoseph Mingrone } 111*ee67461eSJoseph Mingrone 112*ee67461eSJoseph Mingrone /* 113*ee67461eSJoseph Mingrone * This is the top level routine of the printer. 'p' points 114*ee67461eSJoseph Mingrone * to the ether header of the packet, 'h->ts' is the timestamp, 115*ee67461eSJoseph Mingrone * 'h->len' is the length of the packet off the wire, and 'h->caplen' 116*ee67461eSJoseph Mingrone * is the number of bytes actually captured. 117*ee67461eSJoseph Mingrone */ 118*ee67461eSJoseph Mingrone void 119*ee67461eSJoseph Mingrone ipoib_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) 120*ee67461eSJoseph Mingrone { 121*ee67461eSJoseph Mingrone ndo->ndo_protocol = "ipoib"; 122*ee67461eSJoseph Mingrone ipoib_print(ndo, p, h->len, h->caplen, NULL, NULL); 123*ee67461eSJoseph Mingrone } 124