VirtualBox

source: vbox/trunk/include/VBox/VBoxPktDmp.h@ 82681

最後變更 在這個檔案從82681是 82681,由 vboxsync 提交於 5 年 前

Network/DevVirtioNet_1_0.cpp: Ported skeletal framwork from VirtIO 0.9 to VirtIO 1.0 semantics. Builds but not working. See BugRef(8561) Comment #49 for details

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 6.8 KB
 
1/* $Id: VBoxPktDmp.h 82681 2020-01-09 04:31:04Z vboxsync $ */
2/** @file
3 * VBoxPktDmp.h - Dump Ethernet frame into debug log.
4 */
5
6/*
7 * Copyright (C) 2016-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27#ifndef VBOX_INCLUDED_VBoxPktDmp_h
28#define VBOX_INCLUDED_VBoxPktDmp_h
29#ifndef RT_WITHOUT_PRAGMA_ONCE
30# pragma once
31#endif
32
33#include <iprt/net.h>
34#include <iprt/log.h>
35#if defined(LOG_ENABLED) && !defined(VBOX_DEVICE_STRUCT_TESTCASE)
36# include <iprt/asm.h>
37#endif
38
39
40DECLINLINE(const char *) vboxEthTypeStr(uint16_t uType)
41{
42 switch (uType)
43 {
44 case RTNET_ETHERTYPE_IPV4: return "IP";
45 case RTNET_ETHERTYPE_IPV6: return "IPv6";
46 case RTNET_ETHERTYPE_ARP: return "ARP";
47 }
48 return "unknown";
49}
50
51
52//DECLHIDDEN(void)
53DECLINLINE(void) vboxEthPacketDump(const char *pcszInstance, const char *pcszText, const uint8_t *pcPacket, uint32_t cb)
54{
55#if defined(LOG_ENABLED) && !defined(VBOX_DEVICE_STRUCT_TESTCASE)
56 AssertReturnVoid(cb >= 14);
57
58 const uint8_t *pHdr = pcPacket;
59 const uint8_t *pEnd = pcPacket + cb;
60 AssertReturnVoid(pEnd - pHdr >= 14);
61 uint16_t uEthType = RT_N2H_U16(*(uint16_t*)(pHdr+12));
62 Log2(("%s: %s (%d bytes), %RTmac => %RTmac, EthType=%s(0x%x)\n", pcszInstance,
63 pcszText, cb, pHdr+6, pHdr, vboxEthTypeStr(uEthType), uEthType));
64 pHdr += sizeof(RTNETETHERHDR);
65 if (uEthType == RTNET_ETHERTYPE_VLAN)
66 {
67 AssertReturnVoid(pEnd - pHdr >= 4);
68 uEthType = RT_N2H_U16(*(uint16_t*)(pHdr+2));
69 Log2((" + VLAN: id=%d EthType=%s(0x%x)\n", RT_N2H_U16(*(uint16_t*)(pHdr)) & 0xFFF,
70 vboxEthTypeStr(uEthType), uEthType));
71 pHdr += 2 * sizeof(uint16_t);
72 }
73 uint8_t uProto = 0xFF;
74 switch (uEthType)
75 {
76 case RTNET_ETHERTYPE_IPV6:
77 AssertReturnVoid(pEnd - pHdr >= 40);
78 uProto = pHdr[6];
79 Log2((" + IPv6: %RTnaipv6 => %RTnaipv6\n", pHdr+8, pHdr+24));
80 pHdr += 40;
81 break;
82 case RTNET_ETHERTYPE_IPV4:
83 AssertReturnVoid(pEnd - pHdr >= 20);
84 uProto = pHdr[9];
85 Log2((" + IP: %RTnaipv4 => %RTnaipv4\n", *(uint32_t*)(pHdr+12), *(uint32_t*)(pHdr+16)));
86 pHdr += (pHdr[0] & 0xF) * 4;
87 break;
88 case RTNET_ETHERTYPE_ARP:
89 AssertReturnVoid(pEnd - pHdr >= 28);
90 AssertReturnVoid(RT_N2H_U16(*(uint16_t*)(pHdr+2)) == RTNET_ETHERTYPE_IPV4);
91 switch (RT_N2H_U16(*(uint16_t*)(pHdr+6)))
92 {
93 case 1: /* ARP request */
94 Log2((" + ARP-REQ: who-has %RTnaipv4 tell %RTnaipv4\n",
95 *(uint32_t*)(pHdr+24), *(uint32_t*)(pHdr+14)));
96 break;
97 case 2: /* ARP reply */
98 Log2((" + ARP-RPL: %RTnaipv4 is-at %RTmac\n",
99 *(uint32_t*)(pHdr+14), pHdr+8));
100 break;
101 default:
102 Log2((" + ARP: unknown op %d\n", RT_N2H_U16(*(uint16_t*)(pHdr+6))));
103 break;
104 }
105 break;
106 /* There is no default case as uProto is initialized with 0xFF */
107 }
108 while (uProto != 0xFF)
109 {
110 switch (uProto)
111 {
112 case 0: /* IPv6 Hop-by-Hop option*/
113 case 60: /* IPv6 Destination option*/
114 case 43: /* IPv6 Routing option */
115 case 44: /* IPv6 Fragment option */
116 Log2((" + IPv6 option (%d): <not implemented>\n", uProto));
117 uProto = pHdr[0];
118 pHdr += pHdr[1] * 8 + 8; /* Skip to the next extension/protocol */
119 break;
120 case 51: /* IPv6 IPsec AH */
121 Log2((" + IPv6 IPsec AH: <not implemented>\n"));
122 uProto = pHdr[0];
123 pHdr += (pHdr[1] + 2) * 4; /* Skip to the next extension/protocol */
124 break;
125 case 50: /* IPv6 IPsec ESP */
126 /* Cannot decode IPsec, fall through */
127 Log2((" + IPv6 IPsec ESP: <not implemented>\n"));
128 uProto = 0xFF;
129 break;
130 case 59: /* No Next Header */
131 Log2((" + IPv6 No Next Header\n"));
132 uProto = 0xFF;
133 break;
134 case 58: /* IPv6-ICMP */
135 switch (pHdr[0])
136 {
137 case 1: Log2((" + IPv6-ICMP: destination unreachable, code %d\n", pHdr[1])); break;
138 case 128: Log2((" + IPv6-ICMP: echo request\n")); break;
139 case 129: Log2((" + IPv6-ICMP: echo reply\n")); break;
140 default: Log2((" + IPv6-ICMP: unknown type %d, code %d\n", pHdr[0], pHdr[1])); break;
141 }
142 uProto = 0xFF;
143 break;
144 case 1: /* ICMP */
145 switch (pHdr[0])
146 {
147 case 0: Log2((" + ICMP: echo reply\n")); break;
148 case 8: Log2((" + ICMP: echo request\n")); break;
149 case 3: Log2((" + ICMP: destination unreachable, code %d\n", pHdr[1])); break;
150 default: Log2((" + ICMP: unknown type %d, code %d\n", pHdr[0], pHdr[1])); break;
151 }
152 uProto = 0xFF;
153 break;
154 case 6: /* TCP */
155 Log2((" + TCP: src=%d dst=%d seq=%x ack=%x\n",
156 RT_N2H_U16(*(uint16_t*)(pHdr)), RT_N2H_U16(*(uint16_t*)(pHdr+2)),
157 RT_N2H_U32(*(uint32_t*)(pHdr+4)), RT_N2H_U32(*(uint32_t*)(pHdr+8))));
158 uProto = 0xFF;
159 break;
160 case 17: /* UDP */
161 Log2((" + UDP: src=%d dst=%d\n",
162 RT_N2H_U16(*(uint16_t*)(pHdr)), RT_N2H_U16(*(uint16_t*)(pHdr+2))));
163 uProto = 0xFF;
164 break;
165 default:
166 Log2((" + Unknown: proto=0x%x\n", uProto));
167 uProto = 0xFF;
168 break;
169 }
170 }
171 Log3(("%.*Rhxd\n", cb, pcPacket));
172#else
173 RT_NOREF4(pcszInstance, pcszText, pcPacket, cb);
174#endif
175}
176
177#endif /* !VBOX_INCLUDED_VBoxPktDmp_h */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette