]>
The Tcpdump Group git mirrors - tcpdump/blob - print-openflow.c
2 * This module implements printing of the very basic (version-independent)
3 * OpenFlow header and iteration over OpenFlow messages. It is intended for
4 * dispatching of version-specific OpenFlow message decoding.
7 * Copyright (c) 2013 The TCPDUMP project
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
37 #include <tcpdump-stdinc.h>
39 #include "interface.h"
43 #define OF_VER_1_0 0x01
46 of_header_print(const uint8_t version
, const uint8_t type
,
47 const uint16_t length
, const uint32_t xid
) {
48 printf("\n\tversion unknown (0x%02x), type 0x%02x, length %u, xid 0x%08x",
49 version
, type
, length
, xid
);
52 /* Print a single OpenFlow message. */
54 of_header_body_print(const u_char
*cp
, const u_char
*ep
) {
55 uint8_t version
, type
;
59 if (ep
< cp
+ OF_HEADER_LEN
)
71 length
= EXTRACT_16BITS(cp
);
75 xid
= EXTRACT_32BITS(cp
);
77 /* Message length includes the header length and a message always includes
78 * the basic header. A message length underrun fails decoding of the rest of
79 * the current packet. At the same time, try decoding as much of the current
80 * message as possible even when it does not end within the current TCP
82 if (length
< OF_HEADER_LEN
) {
83 of_header_print(version
, type
, length
, xid
);
86 /* Decode known protocol versions further without printing the header (the
87 * type decoding is version-specific. */
90 return of10_header_body_print(cp
, ep
, type
, length
, xid
);
92 of_header_print(version
, type
, length
, xid
);
93 TCHECK2(*cp
, length
- OF_HEADER_LEN
);
94 return cp
+ length
- OF_HEADER_LEN
; /* done with current message */
97 corrupt
: /* fail current packet */
99 TCHECK2(*cp
, ep
- cp
);
102 printf(" [|openflow]");
106 /* Print a TCP segment worth of OpenFlow messages presuming the segment begins
107 * on a message boundary. */
109 openflow_print(const u_char
*cp
, const u_int len
) {
110 const u_char
*ep
= cp
+ len
;
112 printf(": OpenFlow");
114 cp
= of_header_body_print(cp
, ep
);