2009-03-03 21:57:43 +00:00
|
|
|
/* packet-memcache.c
|
|
|
|
* Routines for Memcache Binary Protocol
|
|
|
|
* http://code.google.com/p/memcached/wiki/MemcacheBinaryProtocol
|
|
|
|
*
|
2009-03-15 21:13:27 +00:00
|
|
|
* Copyright 2009, Stig Bjorlykke <stig@bjorlykke.org>
|
2009-03-03 21:57:43 +00:00
|
|
|
*
|
2009-05-24 22:39:07 +00:00
|
|
|
* Routines for Memcache Textual Protocol
|
|
|
|
* http://code.sixapart.com/svn/memcached/trunk/server/doc/protocol.txt
|
|
|
|
*
|
|
|
|
* Copyright 2009, Rama Chitta <rama@gear6.com>
|
|
|
|
*
|
2009-03-03 21:57:43 +00:00
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2009-03-03 21:57:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2009-08-26 19:27:49 +00:00
|
|
|
#include <stdio.h>
|
2013-12-03 22:16:49 +00:00
|
|
|
#include <stdlib.h>
|
2012-05-15 20:57:21 +00:00
|
|
|
|
2009-05-24 22:39:07 +00:00
|
|
|
#include <glib.h>
|
2010-04-21 10:15:01 +00:00
|
|
|
|
2009-05-24 22:39:07 +00:00
|
|
|
#include <epan/packet.h>
|
|
|
|
#include <epan/strutil.h>
|
2009-03-03 21:57:43 +00:00
|
|
|
#include <epan/prefs.h>
|
|
|
|
#include <epan/expert.h>
|
|
|
|
|
|
|
|
#include "packet-tcp.h"
|
|
|
|
|
2009-05-24 22:39:07 +00:00
|
|
|
#define PNAME "Memcache Protocol"
|
2009-03-03 21:57:43 +00:00
|
|
|
#define PSNAME "MEMCACHE"
|
|
|
|
#define PFNAME "memcache"
|
|
|
|
|
2013-03-04 17:48:56 +00:00
|
|
|
#define MEMCACHE_DEFAULT_RANGE "11211"
|
2009-03-03 21:57:43 +00:00
|
|
|
#define MEMCACHE_HEADER_LEN 24
|
|
|
|
|
|
|
|
/* Magic Byte */
|
|
|
|
#define MAGIC_REQUEST 0x80
|
|
|
|
#define MAGIC_RESPONSE 0x81
|
|
|
|
|
|
|
|
/* Response Status */
|
|
|
|
#define RS_NO_ERROR 0x0000
|
|
|
|
#define RS_KEY_NOT_FOUND 0x0001
|
|
|
|
#define RS_KEY_EXISTS 0x0002
|
|
|
|
#define RS_VALUE_TOO_BIG 0x0003
|
|
|
|
#define RS_INVALID_ARGUMENTS 0x0004
|
|
|
|
#define RS_ITEM_NOT_STORED 0x0005
|
|
|
|
#define RS_UNKNOWN_COMMAND 0x0081
|
|
|
|
#define RS_OUT_OF_MEMORY 0x0082
|
|
|
|
|
|
|
|
/* Command Opcodes */
|
|
|
|
#define OP_GET 0x00
|
|
|
|
#define OP_SET 0x01
|
|
|
|
#define OP_ADD 0x02
|
|
|
|
#define OP_REPLACE 0x03
|
|
|
|
#define OP_DELETE 0x04
|
|
|
|
#define OP_INCREMENT 0x05
|
|
|
|
#define OP_DECREMENT 0x06
|
|
|
|
#define OP_QUIT 0x07
|
|
|
|
#define OP_FLUSH 0x08
|
|
|
|
#define OP_GET_Q 0x09
|
|
|
|
#define OP_NO_OP 0x0A
|
|
|
|
#define OP_VERSION 0x0B
|
|
|
|
#define OP_GET_K 0x0C
|
|
|
|
#define OP_GET_K_Q 0x0D
|
|
|
|
#define OP_APPEND 0x0E
|
|
|
|
#define OP_PREPEND 0x0F
|
|
|
|
#define OP_STAT 0x10
|
|
|
|
#define OP_SET_Q 0x11
|
|
|
|
#define OP_ADD_Q 0x12
|
|
|
|
#define OP_REPLACE_Q 0x13
|
|
|
|
#define OP_DELETE_Q 0x14
|
|
|
|
#define OP_INCREMENT_Q 0x15
|
|
|
|
#define OP_DECREMENT_Q 0x16
|
|
|
|
#define OP_QUIT_Q 0x17
|
|
|
|
#define OP_FLUSH_Q 0x18
|
|
|
|
#define OP_APPEND_Q 0x19
|
|
|
|
#define OP_PREPEND_Q 0x1A
|
|
|
|
|
2009-05-24 22:39:07 +00:00
|
|
|
/* Internally defined command opcodes used in the textual dissector only */
|
|
|
|
/* This values are not defined in any standard and can be redefined here */
|
|
|
|
#define OP_GETS 0xF0
|
|
|
|
#define OP_CAS 0xF1
|
|
|
|
#define OP_VERBOSE 0xF2
|
|
|
|
|
2009-03-03 21:57:43 +00:00
|
|
|
/* Data Types */
|
|
|
|
#define DT_RAW_BYTES 0x00
|
|
|
|
|
|
|
|
static int proto_memcache = -1;
|
|
|
|
|
2013-03-04 17:48:56 +00:00
|
|
|
void proto_reg_handoff_memcache(void);
|
|
|
|
|
|
|
|
static range_t *memcache_tcp_port_range = NULL;
|
|
|
|
static range_t *memcache_udp_port_range = NULL;
|
|
|
|
static dissector_handle_t memcache_tcp_handle;
|
|
|
|
static dissector_handle_t memcache_udp_handle;
|
|
|
|
|
2009-03-03 21:57:43 +00:00
|
|
|
static int hf_magic = -1;
|
|
|
|
static int hf_opcode = -1;
|
|
|
|
static int hf_extras_length = -1;
|
|
|
|
static int hf_key_length = -1;
|
|
|
|
static int hf_value_length = -1;
|
|
|
|
static int hf_data_type = -1;
|
|
|
|
static int hf_reserved = -1;
|
|
|
|
static int hf_status = -1;
|
|
|
|
static int hf_total_body_length = -1;
|
|
|
|
static int hf_opaque = -1;
|
|
|
|
static int hf_cas = -1;
|
|
|
|
static int hf_extras = -1;
|
|
|
|
static int hf_extras_flags = -1;
|
|
|
|
static int hf_extras_expiration = -1;
|
|
|
|
static int hf_extras_delta = -1;
|
|
|
|
static int hf_extras_initial = -1;
|
|
|
|
static int hf_extras_unknown = -1;
|
|
|
|
static int hf_key = -1;
|
|
|
|
static int hf_value = -1;
|
|
|
|
static int hf_uint64_response = -1;
|
|
|
|
|
2009-05-24 22:39:07 +00:00
|
|
|
static int hf_command = -1;
|
|
|
|
static int hf_subcommand = -1;
|
|
|
|
static int hf_flags = -1;
|
|
|
|
static int hf_expiration = -1;
|
|
|
|
static int hf_noreply = -1;
|
|
|
|
|
|
|
|
static int hf_response = -1;
|
|
|
|
|
|
|
|
static int hf_version = -1;
|
|
|
|
static int hf_slabclass = -1;
|
|
|
|
static int hf_name = -1;
|
|
|
|
static int hf_name_value = -1;
|
|
|
|
|
2009-03-03 21:57:43 +00:00
|
|
|
static gint ett_memcache = -1;
|
|
|
|
static gint ett_extras = -1;
|
|
|
|
|
2013-08-29 02:17:00 +00:00
|
|
|
static expert_field ei_value_missing = EI_INIT;
|
|
|
|
static expert_field ei_extras_missing = EI_INIT;
|
|
|
|
static expert_field ei_value_length = EI_INIT;
|
|
|
|
static expert_field ei_key_missing = EI_INIT;
|
|
|
|
static expert_field ei_key_unknown = EI_INIT;
|
|
|
|
static expert_field ei_extras_unknown = EI_INIT;
|
|
|
|
static expert_field ei_value_unknown = EI_INIT;
|
2013-08-23 03:17:34 +00:00
|
|
|
static expert_field ei_status_response = EI_INIT;
|
2013-08-29 02:17:00 +00:00
|
|
|
static expert_field ei_opcode_unknown = EI_INIT;
|
|
|
|
static expert_field ei_reserved_value = EI_INIT;
|
|
|
|
static expert_field ei_magic_unknown = EI_INIT;
|
2013-08-23 03:17:34 +00:00
|
|
|
|
2009-03-03 21:57:43 +00:00
|
|
|
static const value_string magic_vals[] = {
|
|
|
|
{ MAGIC_REQUEST, "Request" },
|
|
|
|
{ MAGIC_RESPONSE, "Response" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const value_string status_vals[] = {
|
|
|
|
{ RS_NO_ERROR, "No error" },
|
|
|
|
{ RS_KEY_NOT_FOUND, "Key not found" },
|
|
|
|
{ RS_KEY_EXISTS, "Key exists" },
|
|
|
|
{ RS_VALUE_TOO_BIG, "Value too big" },
|
|
|
|
{ RS_INVALID_ARGUMENTS, "Invalid arguments" },
|
|
|
|
{ RS_ITEM_NOT_STORED, "Item not stored" },
|
|
|
|
{ RS_UNKNOWN_COMMAND, "Unknown command" },
|
|
|
|
{ RS_OUT_OF_MEMORY, "Out of memory" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const value_string opcode_vals[] = {
|
|
|
|
{ OP_GET, "Get" },
|
|
|
|
{ OP_SET, "Set" },
|
|
|
|
{ OP_ADD, "Add" },
|
|
|
|
{ OP_REPLACE, "Replace" },
|
|
|
|
{ OP_DELETE, "Delete" },
|
|
|
|
{ OP_INCREMENT, "Increment" },
|
|
|
|
{ OP_DECREMENT, "Decrement" },
|
|
|
|
{ OP_QUIT, "Quit" },
|
|
|
|
{ OP_FLUSH, "Flush" },
|
|
|
|
{ OP_GET_Q, "Get Quietly" },
|
|
|
|
{ OP_NO_OP, "No-op" },
|
|
|
|
{ OP_VERSION, "Version" },
|
|
|
|
{ OP_GET_K, "Get Key" },
|
|
|
|
{ OP_GET_K_Q, "Get Key Quietly" },
|
|
|
|
{ OP_APPEND, "Append" },
|
|
|
|
{ OP_PREPEND, "Prepend" },
|
|
|
|
{ OP_STAT, "Statistics" },
|
|
|
|
{ OP_SET_Q, "Set Quietly" },
|
|
|
|
{ OP_ADD_Q, "Add Quietly" },
|
|
|
|
{ OP_REPLACE_Q, "Replace Quietly" },
|
|
|
|
{ OP_DELETE_Q, "Delete Quietly" },
|
|
|
|
{ OP_INCREMENT_Q, "Increment Quietly" },
|
|
|
|
{ OP_DECREMENT_Q, "Decrement Quietly" },
|
|
|
|
{ OP_QUIT_Q, "Quit Quietly" },
|
|
|
|
{ OP_FLUSH_Q, "Flush Quietly" },
|
|
|
|
{ OP_APPEND_Q, "Append Quietly" },
|
|
|
|
{ OP_PREPEND_Q, "Prepend Quietly" },
|
2009-05-24 22:39:07 +00:00
|
|
|
/* Internally defined values not valid here */
|
2009-03-03 21:57:43 +00:00
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const value_string data_type_vals[] = {
|
|
|
|
{ DT_RAW_BYTES, "Raw bytes" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
2009-05-24 22:39:07 +00:00
|
|
|
/* memcache message types. */
|
2010-04-28 16:09:25 +00:00
|
|
|
typedef enum _memcache_type {
|
|
|
|
MEMCACHE_REQUEST,
|
2009-05-24 22:39:07 +00:00
|
|
|
MEMCACHE_RESPONSE,
|
|
|
|
MEMCACHE_UNKNOWN
|
|
|
|
} memcache_type_t;
|
|
|
|
|
|
|
|
/* desegmentation of MEMCACHE header */
|
|
|
|
static gboolean memcache_desegment_headers = TRUE;
|
|
|
|
|
|
|
|
/* desegmentation of MEMCACHE payload */
|
|
|
|
static gboolean memcache_desegment_body = TRUE;
|
|
|
|
|
|
|
|
/* should refer to either the request or the response dissector.
|
|
|
|
*/
|
2010-04-28 16:09:25 +00:00
|
|
|
typedef int (*ReqRespDissector)(tvbuff_t*, packet_info *, proto_tree *,
|
2009-05-24 22:39:07 +00:00
|
|
|
int, const guchar*, const guchar*, guint8);
|
|
|
|
|
|
|
|
/* determines if a packet contains a memcache
|
|
|
|
* request or reply by looking at its first token.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
is_memcache_request_or_reply(const gchar *data, int linelen, guint8 *opcode,
|
2010-04-28 16:09:25 +00:00
|
|
|
memcache_type_t *type, int *expect_content_length,
|
2009-05-24 22:39:07 +00:00
|
|
|
ReqRespDissector *reqresp_dissector);
|
|
|
|
|
2010-04-28 16:09:25 +00:00
|
|
|
static guint
|
2009-03-03 21:57:43 +00:00
|
|
|
get_memcache_pdu_len (packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
|
|
|
|
{
|
|
|
|
guint32 body_len;
|
|
|
|
|
|
|
|
/* Get the length of the memcache body */
|
|
|
|
body_len = tvb_get_ntohl(tvb, offset+8);
|
|
|
|
|
|
|
|
/* That length doesn't include the header; add that in */
|
|
|
|
return body_len + MEMCACHE_HEADER_LEN;
|
|
|
|
}
|
|
|
|
|
2010-04-28 16:09:25 +00:00
|
|
|
static void
|
|
|
|
dissect_extras (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
|
2009-03-03 21:57:43 +00:00
|
|
|
gint offset, guint8 extras_len, guint8 opcode, gboolean request)
|
|
|
|
{
|
|
|
|
proto_tree *extras_tree = NULL;
|
|
|
|
proto_item *extras_item = NULL, *ti;
|
|
|
|
gint save_offset = offset;
|
|
|
|
gboolean illegal = FALSE; /* Set when extras shall not be present */
|
|
|
|
gboolean missing = FALSE; /* Set when extras is missing */
|
|
|
|
|
|
|
|
if (extras_len) {
|
2011-07-19 18:48:31 +00:00
|
|
|
extras_item = proto_tree_add_item (tree, hf_extras, tvb, offset, extras_len, ENC_NA);
|
2009-03-03 21:57:43 +00:00
|
|
|
extras_tree = proto_item_add_subtree (extras_item, ett_extras);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (opcode) {
|
|
|
|
|
|
|
|
case OP_GET:
|
|
|
|
case OP_GET_Q:
|
|
|
|
case OP_GET_K:
|
|
|
|
case OP_GET_K_Q:
|
|
|
|
if (extras_len) {
|
|
|
|
if (request) {
|
|
|
|
/* Request shall not have extras */
|
|
|
|
illegal = TRUE;
|
|
|
|
} else {
|
2011-07-19 10:51:12 +00:00
|
|
|
proto_tree_add_item (extras_tree, hf_extras_flags, tvb, offset, 4, ENC_BIG_ENDIAN);
|
2009-03-03 21:57:43 +00:00
|
|
|
offset += 4;
|
|
|
|
}
|
|
|
|
} else if (!request) {
|
|
|
|
/* Response must have extras */
|
|
|
|
missing = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_SET:
|
|
|
|
case OP_SET_Q:
|
|
|
|
case OP_ADD:
|
|
|
|
case OP_ADD_Q:
|
|
|
|
case OP_REPLACE:
|
|
|
|
case OP_REPLACE_Q:
|
|
|
|
if (extras_len) {
|
|
|
|
if (request) {
|
2011-07-19 10:51:12 +00:00
|
|
|
proto_tree_add_item (extras_tree, hf_extras_flags, tvb, offset, 4, ENC_BIG_ENDIAN);
|
2009-03-03 21:57:43 +00:00
|
|
|
offset += 4;
|
2009-05-24 22:39:07 +00:00
|
|
|
|
2011-07-19 10:51:12 +00:00
|
|
|
proto_tree_add_item (extras_tree, hf_extras_expiration, tvb, offset, 4, ENC_BIG_ENDIAN);
|
2009-03-03 21:57:43 +00:00
|
|
|
offset += 4;
|
|
|
|
} else {
|
|
|
|
/* Response shall not have extras */
|
|
|
|
illegal = TRUE;
|
|
|
|
}
|
|
|
|
} else if (request) {
|
|
|
|
/* Request must have extras */
|
|
|
|
missing = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_INCREMENT:
|
|
|
|
case OP_INCREMENT_Q:
|
|
|
|
case OP_DECREMENT:
|
|
|
|
case OP_DECREMENT_Q:
|
|
|
|
if (extras_len) {
|
|
|
|
if (request) {
|
2011-07-19 10:51:12 +00:00
|
|
|
proto_tree_add_item (extras_tree, hf_extras_delta, tvb, offset, 8, ENC_BIG_ENDIAN);
|
2009-03-03 21:57:43 +00:00
|
|
|
offset += 8;
|
|
|
|
|
2011-07-19 10:51:12 +00:00
|
|
|
proto_tree_add_item (extras_tree, hf_extras_initial, tvb, offset, 8, ENC_BIG_ENDIAN);
|
2009-03-03 21:57:43 +00:00
|
|
|
offset += 8;
|
|
|
|
|
2011-07-19 10:51:12 +00:00
|
|
|
proto_tree_add_item (extras_tree, hf_extras_expiration, tvb, offset, 4, ENC_BIG_ENDIAN);
|
2009-03-03 21:57:43 +00:00
|
|
|
offset += 4;
|
|
|
|
} else {
|
|
|
|
/* Response must not have extras (response is in Value) */
|
|
|
|
illegal = TRUE;
|
|
|
|
}
|
|
|
|
} else if (request) {
|
|
|
|
/* Request must have extras */
|
|
|
|
missing = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_FLUSH:
|
|
|
|
case OP_FLUSH_Q:
|
|
|
|
if (extras_len) {
|
2011-07-19 10:51:12 +00:00
|
|
|
proto_tree_add_item (extras_tree, hf_extras_expiration, tvb, offset, 4, ENC_BIG_ENDIAN);
|
2009-03-03 21:57:43 +00:00
|
|
|
offset += 4;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_DELETE:
|
|
|
|
case OP_DELETE_Q:
|
|
|
|
case OP_QUIT:
|
|
|
|
case OP_QUIT_Q:
|
|
|
|
case OP_VERSION:
|
|
|
|
case OP_APPEND:
|
|
|
|
case OP_APPEND_Q:
|
|
|
|
case OP_PREPEND:
|
|
|
|
case OP_PREPEND_Q:
|
|
|
|
case OP_STAT:
|
|
|
|
/* Must not have extras */
|
|
|
|
if (extras_len) {
|
|
|
|
illegal = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (extras_len) {
|
|
|
|
/* Decode as unknown extras */
|
2011-07-19 18:48:31 +00:00
|
|
|
proto_tree_add_item (extras_tree, hf_extras_unknown, tvb, offset, extras_len, ENC_NA);
|
2009-03-03 21:57:43 +00:00
|
|
|
offset += extras_len;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (illegal) {
|
2011-07-19 18:48:31 +00:00
|
|
|
ti = proto_tree_add_item (extras_tree, hf_extras_unknown, tvb, offset, extras_len, ENC_NA);
|
2013-09-09 00:44:09 +00:00
|
|
|
expert_add_info_format(pinfo, ti, &ei_extras_unknown, "%s %s shall not have Extras",
|
2013-08-23 03:17:34 +00:00
|
|
|
val_to_str (opcode, opcode_vals, "Opcode %d"),
|
|
|
|
request ? "Request" : "Response");
|
2009-03-03 21:57:43 +00:00
|
|
|
offset += extras_len;
|
|
|
|
} else if (missing) {
|
2013-08-23 03:17:34 +00:00
|
|
|
proto_tree_add_expert_format(tree, pinfo, &ei_extras_missing, tvb, offset, 0, "%s %s must have Extras",
|
2009-03-03 21:57:43 +00:00
|
|
|
val_to_str (opcode, opcode_vals, "Opcode %d"),
|
|
|
|
request ? "Request" : "Response");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((offset - save_offset) != extras_len) {
|
2013-09-09 00:44:09 +00:00
|
|
|
expert_add_info_format(pinfo, extras_item, &ei_extras_unknown, "Illegal Extras length, should be %d", offset - save_offset);
|
2009-03-03 21:57:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-28 16:09:25 +00:00
|
|
|
static void
|
|
|
|
dissect_key (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
|
2009-06-02 19:35:45 +00:00
|
|
|
gint offset, int key_len, guint8 opcode, gboolean request)
|
2009-03-03 21:57:43 +00:00
|
|
|
{
|
|
|
|
proto_item *ti = NULL;
|
|
|
|
gboolean illegal = FALSE; /* Set when key shall not be present */
|
|
|
|
gboolean missing = FALSE; /* Set when key is missing */
|
|
|
|
|
|
|
|
if (key_len) {
|
2011-10-15 18:46:26 +00:00
|
|
|
ti = proto_tree_add_item (tree, hf_key, tvb, offset, key_len, ENC_ASCII|ENC_NA);
|
2009-03-03 21:57:43 +00:00
|
|
|
offset += key_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
if (key_len) {
|
|
|
|
if ((opcode == OP_QUIT) || (opcode == OP_QUIT_Q) || (opcode == OP_NO_OP) || (opcode == OP_VERSION)) {
|
|
|
|
/* Request and Response must not have key */
|
|
|
|
illegal = TRUE;
|
|
|
|
}
|
|
|
|
if ((opcode == OP_SET) || (opcode == OP_ADD) || (opcode == OP_REPLACE) || (opcode == OP_DELETE) ||
|
|
|
|
(opcode == OP_SET_Q) || (opcode == OP_ADD_Q) || (opcode == OP_REPLACE_Q) || (opcode == OP_DELETE_Q) ||
|
|
|
|
(opcode == OP_FLUSH) || (opcode == OP_APPEND) || (opcode == OP_PREPEND) ||
|
|
|
|
(opcode == OP_FLUSH_Q) || (opcode == OP_APPEND_Q) || (opcode == OP_PREPEND_Q))
|
|
|
|
{
|
|
|
|
/* Response must not have a key */
|
|
|
|
if (!request) {
|
|
|
|
illegal = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((opcode == OP_GET) || (opcode == OP_GET_Q) || (opcode == OP_GET_K) || (opcode == OP_GET_K_Q) ||
|
|
|
|
(opcode == OP_SET) || (opcode == OP_ADD) || (opcode == OP_REPLACE) || (opcode == OP_DELETE) ||
|
|
|
|
(opcode == OP_SET_Q) || (opcode == OP_ADD_Q) || (opcode == OP_REPLACE_Q) || (opcode == OP_DELETE_Q) ||
|
|
|
|
(opcode == OP_INCREMENT) || (opcode == OP_DECREMENT) || (opcode == OP_INCREMENT_Q) || (opcode == OP_DECREMENT_Q))
|
|
|
|
{
|
|
|
|
/* Request must have key */
|
|
|
|
if (request) {
|
|
|
|
missing = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (illegal) {
|
2013-09-09 00:44:09 +00:00
|
|
|
expert_add_info_format(pinfo, ti, &ei_key_unknown, "%s %s shall not have Key",
|
2013-08-23 03:17:34 +00:00
|
|
|
val_to_str (opcode, opcode_vals, "Opcode %d"),
|
|
|
|
request ? "Request" : "Response");
|
2009-03-03 21:57:43 +00:00
|
|
|
} else if (missing) {
|
2013-08-23 03:17:34 +00:00
|
|
|
proto_tree_add_expert_format(tree, pinfo, &ei_key_missing, tvb, offset, 0, "%s %s must have Key",
|
2009-03-03 21:57:43 +00:00
|
|
|
val_to_str (opcode, opcode_vals, "Opcode %d"),
|
|
|
|
request ? "Request" : "Response");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-28 16:09:25 +00:00
|
|
|
static void
|
|
|
|
dissect_value (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
|
2009-03-06 15:41:02 +00:00
|
|
|
gint offset, guint32 value_len, guint8 opcode, gboolean request)
|
2009-03-03 21:57:43 +00:00
|
|
|
{
|
|
|
|
proto_item *ti = NULL;
|
|
|
|
gboolean illegal = FALSE; /* Set when value shall not be present */
|
|
|
|
gboolean missing = FALSE; /* Set when value is missing */
|
|
|
|
|
|
|
|
if (value_len > 0) {
|
|
|
|
if (!request && ((opcode == OP_INCREMENT) || (opcode == OP_DECREMENT))) {
|
2011-07-19 10:51:12 +00:00
|
|
|
ti = proto_tree_add_item (tree, hf_uint64_response, tvb, offset, 8, ENC_BIG_ENDIAN);
|
2009-03-03 21:57:43 +00:00
|
|
|
if (value_len != 8) {
|
2013-09-09 00:44:09 +00:00
|
|
|
expert_add_info_format(pinfo, ti, &ei_value_length, "Illegal Value length, should be 8");
|
2009-03-03 21:57:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
2011-10-15 18:46:26 +00:00
|
|
|
ti = proto_tree_add_item (tree, hf_value, tvb, offset, value_len, ENC_ASCII|ENC_NA);
|
2009-03-03 21:57:43 +00:00
|
|
|
}
|
|
|
|
offset += value_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
if (value_len) {
|
2010-04-28 16:09:25 +00:00
|
|
|
if ((opcode == OP_GET) || (opcode == OP_GET_Q) || (opcode == OP_GET_K) || (opcode == OP_GET_K_Q) ||
|
2009-03-03 21:57:43 +00:00
|
|
|
(opcode == OP_INCREMENT) || (opcode == OP_DECREMENT) || (opcode == OP_VERSION) ||
|
|
|
|
(opcode == OP_INCREMENT_Q) || (opcode == OP_DECREMENT_Q))
|
|
|
|
{
|
|
|
|
/* Request must not have value */
|
|
|
|
if (request) {
|
|
|
|
illegal = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((opcode == OP_DELETE) || (opcode == OP_QUIT) || (opcode == OP_FLUSH) || (opcode == OP_NO_OP) ||
|
|
|
|
(opcode == OP_DELETE_Q) || (opcode == OP_QUIT_Q) || (opcode == OP_FLUSH_Q))
|
|
|
|
{
|
|
|
|
/* Request and Response must not have value */
|
|
|
|
illegal = TRUE;
|
|
|
|
}
|
|
|
|
if ((opcode == OP_SET) || (opcode == OP_ADD) || (opcode == OP_REPLACE) ||
|
|
|
|
(opcode == OP_SET_Q) || (opcode == OP_ADD_Q) || (opcode == OP_REPLACE_Q) ||
|
|
|
|
(opcode == OP_APPEND) || (opcode == OP_PREPEND) || (opcode == OP_APPEND_Q) || (opcode == OP_PREPEND_Q))
|
|
|
|
{
|
|
|
|
/* Response must not have value */
|
|
|
|
if (!request) {
|
|
|
|
illegal = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((opcode == OP_SET) || (opcode == OP_ADD) || (opcode == OP_REPLACE) ||
|
|
|
|
(opcode == OP_SET_Q) || (opcode == OP_ADD_Q) || (opcode == OP_REPLACE_Q) ||
|
|
|
|
(opcode == OP_APPEND) || (opcode == OP_PREPEND) || (opcode == OP_APPEND_Q) || (opcode == OP_PREPEND_Q))
|
|
|
|
{
|
|
|
|
/* Request must have a value */
|
|
|
|
if (request) {
|
|
|
|
missing = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (illegal) {
|
2013-09-09 00:44:09 +00:00
|
|
|
expert_add_info_format(pinfo, ti, &ei_value_unknown, "%s %s shall not have Value",
|
2013-08-23 03:17:34 +00:00
|
|
|
val_to_str (opcode, opcode_vals, "Opcode %d"),
|
|
|
|
request ? "Request" : "Response");
|
2009-03-03 21:57:43 +00:00
|
|
|
} else if (missing) {
|
2013-08-23 03:17:34 +00:00
|
|
|
proto_tree_add_expert_format(tree, pinfo, &ei_value_missing, tvb, offset, 0, "%s %s must have Value",
|
2009-03-03 21:57:43 +00:00
|
|
|
val_to_str (opcode, opcode_vals, "Opcode %d"),
|
2010-04-28 16:09:25 +00:00
|
|
|
request ? "Request" : "Response");
|
2009-03-03 21:57:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-09 17:46:28 +00:00
|
|
|
static int
|
|
|
|
dissect_memcache (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
|
2009-03-03 21:57:43 +00:00
|
|
|
{
|
|
|
|
proto_tree *memcache_tree;
|
|
|
|
proto_item *memcache_item, *ti;
|
|
|
|
gint offset = 0;
|
|
|
|
guint8 magic, opcode, extras_len;
|
|
|
|
guint16 key_len, status = 0;
|
|
|
|
guint32 body_len, value_len;
|
|
|
|
gboolean request;
|
|
|
|
|
2009-05-24 22:39:07 +00:00
|
|
|
col_set_str (pinfo->cinfo, COL_PROTOCOL, PSNAME);
|
|
|
|
col_clear (pinfo->cinfo, COL_INFO);
|
2009-03-03 21:57:43 +00:00
|
|
|
|
2011-07-19 18:48:31 +00:00
|
|
|
memcache_item = proto_tree_add_item (tree, proto_memcache, tvb, offset, -1, ENC_NA);
|
2009-03-03 21:57:43 +00:00
|
|
|
memcache_tree = proto_item_add_subtree (memcache_item, ett_memcache);
|
|
|
|
|
|
|
|
magic = tvb_get_guint8 (tvb, offset);
|
2011-07-19 10:51:12 +00:00
|
|
|
ti = proto_tree_add_item (memcache_tree, hf_magic, tvb, offset, 1, ENC_BIG_ENDIAN);
|
2009-03-03 21:57:43 +00:00
|
|
|
offset += 1;
|
|
|
|
|
2013-03-29 00:26:23 +00:00
|
|
|
if (try_val_to_str (magic, magic_vals) == NULL) {
|
2013-09-09 00:44:09 +00:00
|
|
|
expert_add_info_format(pinfo, ti, &ei_magic_unknown, "Unknown magic byte: %d", magic);
|
2009-03-03 21:57:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
opcode = tvb_get_guint8 (tvb, offset);
|
2011-07-19 10:51:12 +00:00
|
|
|
ti = proto_tree_add_item (memcache_tree, hf_opcode, tvb, offset, 1, ENC_BIG_ENDIAN);
|
2009-03-03 21:57:43 +00:00
|
|
|
offset += 1;
|
|
|
|
|
2013-03-29 00:26:23 +00:00
|
|
|
if (try_val_to_str (opcode, opcode_vals) == NULL) {
|
2013-09-09 00:44:09 +00:00
|
|
|
expert_add_info_format(pinfo, ti, &ei_opcode_unknown, "Unknown opcode: %d", opcode);
|
2009-03-03 21:57:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
proto_item_append_text (memcache_item, ", %s %s", val_to_str (opcode, opcode_vals, "Unknown opcode (%d)"),
|
|
|
|
val_to_str (magic, magic_vals, "Unknown magic (%d)"));
|
|
|
|
|
2010-04-28 16:09:25 +00:00
|
|
|
col_append_fstr (pinfo->cinfo, COL_INFO, "%s %s",
|
2009-05-24 22:39:07 +00:00
|
|
|
val_to_str (opcode, opcode_vals, "Unknown opcode (%d)"),
|
|
|
|
val_to_str (magic, magic_vals, "Unknown magic (%d)"));
|
2009-03-03 21:57:43 +00:00
|
|
|
|
|
|
|
key_len = tvb_get_ntohs (tvb, offset);
|
2011-07-19 10:51:12 +00:00
|
|
|
proto_tree_add_item (memcache_tree, hf_key_length, tvb, offset, 2, ENC_BIG_ENDIAN);
|
2009-03-03 21:57:43 +00:00
|
|
|
offset += 2;
|
|
|
|
|
|
|
|
extras_len = tvb_get_guint8 (tvb, offset);
|
2011-07-19 10:51:12 +00:00
|
|
|
proto_tree_add_item (memcache_tree, hf_extras_length, tvb, offset, 1, ENC_BIG_ENDIAN);
|
2009-03-03 21:57:43 +00:00
|
|
|
offset += 1;
|
|
|
|
|
2011-07-19 10:51:12 +00:00
|
|
|
proto_tree_add_item (memcache_tree, hf_data_type, tvb, offset, 1, ENC_BIG_ENDIAN);
|
2009-03-03 21:57:43 +00:00
|
|
|
offset += 1;
|
|
|
|
|
|
|
|
status = tvb_get_ntohs (tvb, offset);
|
|
|
|
if (magic & 0x01) { /* We suppose this is a response, even when unknown magic byte */
|
|
|
|
request = FALSE;
|
2011-07-19 10:51:12 +00:00
|
|
|
ti = proto_tree_add_item (memcache_tree, hf_status, tvb, offset, 2, ENC_BIG_ENDIAN);
|
2009-03-03 21:57:43 +00:00
|
|
|
if (status != 0) {
|
2013-09-09 00:44:09 +00:00
|
|
|
expert_add_info_format(pinfo, ti, &ei_status_response, "%s: %s",
|
2009-03-03 21:57:43 +00:00
|
|
|
val_to_str (opcode, opcode_vals, "Unknown opcode (%d)"),
|
|
|
|
val_to_str (status, status_vals, "Status: %d"));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
request = TRUE;
|
2011-07-19 10:51:12 +00:00
|
|
|
ti = proto_tree_add_item (memcache_tree, hf_reserved, tvb, offset, 2, ENC_BIG_ENDIAN);
|
2009-03-03 21:57:43 +00:00
|
|
|
if (status != 0) {
|
2013-09-09 00:44:09 +00:00
|
|
|
expert_add_info_format(pinfo, ti, &ei_reserved_value, "Reserved value: %d", status);
|
2009-03-03 21:57:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
offset += 2;
|
|
|
|
|
|
|
|
body_len = tvb_get_ntohl (tvb, offset);
|
|
|
|
value_len = body_len - extras_len - key_len;
|
|
|
|
ti = proto_tree_add_uint (memcache_tree, hf_value_length, tvb, offset, 0, value_len);
|
|
|
|
PROTO_ITEM_SET_GENERATED (ti);
|
|
|
|
|
2011-07-19 10:51:12 +00:00
|
|
|
proto_tree_add_item (memcache_tree, hf_total_body_length, tvb, offset, 4, ENC_BIG_ENDIAN);
|
2009-03-03 21:57:43 +00:00
|
|
|
offset += 4;
|
|
|
|
|
2011-07-19 10:51:12 +00:00
|
|
|
proto_tree_add_item (memcache_tree, hf_opaque, tvb, offset, 4, ENC_BIG_ENDIAN);
|
2009-03-03 21:57:43 +00:00
|
|
|
offset += 4;
|
|
|
|
|
2011-07-19 10:51:12 +00:00
|
|
|
proto_tree_add_item (memcache_tree, hf_cas, tvb, offset, 8, ENC_BIG_ENDIAN);
|
2009-03-03 21:57:43 +00:00
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
if (status == 0) {
|
|
|
|
dissect_extras (tvb, pinfo, memcache_tree, offset, extras_len, opcode, request);
|
|
|
|
offset += extras_len;
|
|
|
|
|
|
|
|
dissect_key (tvb, pinfo, memcache_tree, offset, key_len, opcode, request);
|
|
|
|
offset += key_len;
|
|
|
|
|
|
|
|
dissect_value (tvb, pinfo, memcache_tree, offset, value_len, opcode, request);
|
2012-06-04 22:24:46 +00:00
|
|
|
/*offset += value_len;*/
|
2009-03-03 21:57:43 +00:00
|
|
|
} else if (body_len) {
|
2011-10-15 18:46:26 +00:00
|
|
|
proto_tree_add_item (memcache_tree, hf_value, tvb, offset, body_len, ENC_ASCII|ENC_NA);
|
2012-06-04 22:24:46 +00:00
|
|
|
/*offset += body_len;*/
|
2010-04-28 16:09:25 +00:00
|
|
|
|
|
|
|
col_append_fstr (pinfo->cinfo, COL_INFO, " (%s)",
|
2009-05-24 22:39:07 +00:00
|
|
|
val_to_str (status, status_vals, "Unknown status: %d"));
|
2009-03-03 21:57:43 +00:00
|
|
|
} else {
|
2013-08-23 03:17:34 +00:00
|
|
|
proto_tree_add_expert_format(memcache_tree, pinfo, &ei_value_missing, tvb, offset, 0, "%s with status %s (%d) must have Value",
|
2009-03-03 21:57:43 +00:00
|
|
|
val_to_str (opcode, opcode_vals, "Opcode %d"),
|
2012-08-10 22:55:02 +00:00
|
|
|
val_to_str_const (status, status_vals, "Unknown"), status);
|
2009-03-03 21:57:43 +00:00
|
|
|
}
|
2013-11-09 17:46:28 +00:00
|
|
|
|
|
|
|
return tvb_length(tvb);
|
2009-03-03 21:57:43 +00:00
|
|
|
}
|
|
|
|
|
2009-05-24 22:39:07 +00:00
|
|
|
/* Obtain the content length by peeping into the header.
|
|
|
|
*/
|
2010-04-28 16:09:25 +00:00
|
|
|
static gboolean
|
|
|
|
get_payload_length (tvbuff_t *tvb, const int token_number, int offset,
|
2009-05-24 22:39:07 +00:00
|
|
|
guint32 *bytes, gboolean *content_length_found)
|
|
|
|
{
|
|
|
|
const guchar *next_token;
|
|
|
|
const guchar *line, *lineend;
|
2009-06-11 11:52:42 +00:00
|
|
|
guchar *bytes_val;
|
2009-05-24 22:39:07 +00:00
|
|
|
int tokenlen, i = 0, linelen;
|
|
|
|
gint next_offset;
|
|
|
|
|
|
|
|
/* get the header line. */
|
|
|
|
linelen = tvb_find_line_end (tvb, offset,
|
|
|
|
tvb_ensure_length_remaining (tvb, offset), &next_offset,
|
|
|
|
FALSE);
|
|
|
|
if (linelen < 0) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
line = tvb_get_ptr (tvb, offset, linelen);
|
|
|
|
lineend = line + linelen;
|
|
|
|
|
|
|
|
while (++i < token_number) {
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
offset += (int) (next_token - line);
|
|
|
|
line = next_token;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* line or the next_token has the value we want. */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-09-22 15:50:55 +00:00
|
|
|
bytes_val = tvb_get_string (wmem_packet_scope(), tvb, offset, tokenlen);
|
2009-05-24 22:39:07 +00:00
|
|
|
if (bytes_val) {
|
|
|
|
if (sscanf (bytes_val, "%u", bytes) == 1) {
|
|
|
|
*content_length_found = TRUE;
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reached this far, we got what we want. */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if a PDU needs to be desegmented. */
|
|
|
|
static gboolean
|
|
|
|
desegment_pdus (tvbuff_t *tvb, packet_info *pinfo, const int offset,
|
|
|
|
const int data_offset, guint32 content_length)
|
|
|
|
{
|
|
|
|
gint length_remaining, reported_length_remaining;
|
|
|
|
|
|
|
|
/* data_offset has been set to start of the data block. */
|
2010-04-28 16:09:25 +00:00
|
|
|
if (!tvb_bytes_exist (tvb, data_offset, content_length)) {
|
2009-05-24 22:39:07 +00:00
|
|
|
|
|
|
|
length_remaining = tvb_length_remaining (tvb, data_offset);
|
|
|
|
reported_length_remaining = tvb_reported_length_remaining (tvb, data_offset);
|
|
|
|
|
2010-04-28 16:09:25 +00:00
|
|
|
if (length_remaining < reported_length_remaining) {
|
2009-05-24 22:39:07 +00:00
|
|
|
/* It's a waste of time asking for more
|
|
|
|
* data, because that data wasn't captured.
|
|
|
|
*/
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-04-28 16:09:25 +00:00
|
|
|
if (length_remaining == -1) {
|
2009-05-24 22:39:07 +00:00
|
|
|
length_remaining = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
pinfo->desegment_offset = offset; /* start of the packet. */
|
|
|
|
pinfo->desegment_len = (content_length + 2) - length_remaining; /* add 2 for /r/n */
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Optionally do reassembly of the requests, responses and data.
|
|
|
|
*/
|
2009-05-26 16:01:12 +00:00
|
|
|
static gboolean
|
2009-05-24 22:39:07 +00:00
|
|
|
memcache_req_resp_hdrs_do_reassembly (
|
2010-04-28 16:09:25 +00:00
|
|
|
tvbuff_t *tvb, const int offset, packet_info *pinfo,
|
|
|
|
const gboolean desegment_headers, const gboolean desegment_body,
|
2009-05-24 22:39:07 +00:00
|
|
|
const memcache_type_t type, const int expect_content_length)
|
|
|
|
{
|
|
|
|
int linelen;
|
|
|
|
gint next_offset;
|
|
|
|
gint length_remaining;
|
|
|
|
gint reported_length_remaining;
|
|
|
|
guint32 content_length = 0;
|
|
|
|
gboolean content_length_found = FALSE;
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If header desegmentation is activated, check the
|
|
|
|
* header in this tvbuff.
|
2010-04-28 16:09:25 +00:00
|
|
|
* request one more byte (we don't know how many bytes
|
2009-05-24 22:39:07 +00:00
|
|
|
* we'll need, so we just ask for one).
|
|
|
|
*/
|
2010-04-28 16:09:25 +00:00
|
|
|
if (desegment_headers && pinfo->can_desegment) {
|
2009-05-24 22:39:07 +00:00
|
|
|
next_offset = offset;
|
|
|
|
|
|
|
|
reported_length_remaining = tvb_reported_length_remaining (tvb, next_offset);
|
|
|
|
/*
|
|
|
|
* Request one more byte if there're no
|
|
|
|
* bytes left in the reported data (if there're
|
|
|
|
* bytes left in the reported data, but not in
|
|
|
|
* the available data, requesting more bytes
|
|
|
|
* won't help, as those bytes weren't captured).
|
|
|
|
*/
|
2010-04-28 16:09:25 +00:00
|
|
|
if (reported_length_remaining < 1) {
|
2009-05-24 22:39:07 +00:00
|
|
|
pinfo->desegment_offset = offset;
|
|
|
|
pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
length_remaining = tvb_length_remaining (tvb, next_offset);
|
|
|
|
|
2010-04-28 16:09:25 +00:00
|
|
|
/* Request one more byte if we cannot find a
|
2009-05-24 22:39:07 +00:00
|
|
|
* header (i.e. a line end).
|
|
|
|
*/
|
|
|
|
linelen = tvb_find_line_end (tvb, next_offset, -1, &next_offset, TRUE);
|
2010-04-28 16:09:25 +00:00
|
|
|
if (linelen == -1 && length_remaining >= reported_length_remaining) {
|
2009-05-24 22:39:07 +00:00
|
|
|
/* Not enough data; ask for one more byte. */
|
|
|
|
pinfo->desegment_offset = offset;
|
|
|
|
pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT;
|
2010-04-28 16:09:25 +00:00
|
|
|
return FALSE;
|
2009-05-24 22:39:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Browse through the header to find the content length.
|
|
|
|
*
|
|
|
|
* request:
|
|
|
|
* <command name> <key> <flags> <exptime> <bytes> [noreply]\r\n
|
|
|
|
* cas <key> <flags> <exptime> <bytes> <cas unqiue> [noreply]\r\n
|
|
|
|
*
|
|
|
|
* response:
|
2010-04-28 16:09:25 +00:00
|
|
|
* VALUE <key> <flags> <bytes> [<cas unique>]\r\n
|
2009-05-24 22:39:07 +00:00
|
|
|
* <data block>\r\n
|
2010-04-28 16:09:25 +00:00
|
|
|
*/
|
|
|
|
if (expect_content_length == TRUE) {
|
2009-05-24 22:39:07 +00:00
|
|
|
switch (type) {
|
|
|
|
|
|
|
|
case MEMCACHE_REQUEST:
|
|
|
|
/* Get the fifth token in the header.*/
|
|
|
|
ret = get_payload_length (tvb, 5 , offset, &content_length, &content_length_found);
|
2010-04-28 16:09:25 +00:00
|
|
|
if (!ret) {
|
|
|
|
return FALSE;
|
2009-05-24 22:39:07 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MEMCACHE_RESPONSE:
|
|
|
|
/* Get the fourth token in the header.*/
|
|
|
|
ret = get_payload_length (tvb, 4 , offset, &content_length, &content_length_found);
|
2010-04-28 16:09:25 +00:00
|
|
|
if (!ret) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-05-24 22:39:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* Unrecognized message type. */
|
2010-04-28 16:09:25 +00:00
|
|
|
return FALSE;
|
2009-05-24 22:39:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-28 16:09:25 +00:00
|
|
|
/* We have reached the end of a header, so there
|
|
|
|
* should be 'content_length' bytes after this
|
|
|
|
* followed by CRLF. The next_offset points to the
|
|
|
|
* start of the data bytes.
|
2009-05-24 22:39:07 +00:00
|
|
|
*/
|
|
|
|
if (desegment_body && content_length_found) {
|
|
|
|
return !desegment_pdus (tvb, pinfo, offset, next_offset, content_length);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No further desegmentation needed. */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Dissect a memcache message. */
|
|
|
|
static int
|
|
|
|
dissect_memcache_message (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
|
|
|
|
{
|
|
|
|
const guchar *line;
|
|
|
|
const guchar *lineend;
|
|
|
|
int orig_offset;
|
|
|
|
int first_linelen;
|
|
|
|
int datalen;
|
|
|
|
int expect_content_length = FALSE;
|
|
|
|
gint next_offset;
|
|
|
|
|
|
|
|
gboolean is_request_or_reply;
|
|
|
|
memcache_type_t memcache_type;
|
|
|
|
ReqRespDissector reqresp_dissector = NULL;
|
|
|
|
proto_tree *memcache_tree = NULL;
|
|
|
|
proto_item *memcache_item = NULL;
|
|
|
|
guint8 opcode = 0xff; /* set to something that is not in the list. */
|
|
|
|
|
|
|
|
/* Find a line end in the packet.
|
|
|
|
* Note that "tvb_find_line_end ()" will return a value that
|
|
|
|
* is not longer than what's in the buffer, so the
|
|
|
|
* "tvb_get_ptr ()" call won't throw an exception.
|
|
|
|
*/
|
|
|
|
first_linelen = tvb_find_line_end (tvb, offset,
|
|
|
|
tvb_ensure_length_remaining (tvb, offset), &next_offset,
|
|
|
|
FALSE);
|
2010-04-28 16:09:25 +00:00
|
|
|
if (first_linelen < 0) {
|
2009-05-24 22:39:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
line = tvb_get_ptr (tvb, offset, first_linelen);
|
|
|
|
lineend = line + first_linelen;
|
|
|
|
|
|
|
|
memcache_type = MEMCACHE_UNKNOWN; /* packet type not known yet */
|
|
|
|
|
2010-04-28 16:09:25 +00:00
|
|
|
/* Look at the first token of the first line to
|
|
|
|
* determine if it is a request or a response?
|
2009-05-24 22:39:07 +00:00
|
|
|
*/
|
2010-04-28 16:09:25 +00:00
|
|
|
is_request_or_reply =
|
|
|
|
is_memcache_request_or_reply ((const gchar *)line,
|
|
|
|
first_linelen, &opcode, &memcache_type,
|
2009-05-24 22:39:07 +00:00
|
|
|
&expect_content_length, &reqresp_dissector);
|
|
|
|
if (is_request_or_reply) {
|
|
|
|
|
|
|
|
/* Yes, it is a request or a response.
|
|
|
|
* Do header and body desegmentation if we've been told to.
|
|
|
|
*/
|
2010-04-28 16:09:25 +00:00
|
|
|
if (!memcache_req_resp_hdrs_do_reassembly (tvb, offset, pinfo, memcache_desegment_headers,
|
|
|
|
memcache_desegment_body, memcache_type,
|
2009-05-24 22:39:07 +00:00
|
|
|
expect_content_length))
|
|
|
|
{
|
|
|
|
/* More data needed for desegmentation. */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-28 16:09:25 +00:00
|
|
|
/* Columns and summary display. */
|
2009-05-24 22:39:07 +00:00
|
|
|
col_set_str (pinfo->cinfo, COL_PROTOCOL, PSNAME);
|
|
|
|
|
|
|
|
/* If the packet is a memcache request or reply,
|
|
|
|
* put the first line from the buffer into the summary
|
|
|
|
* Otherwise, just call it a continuation.
|
|
|
|
*/
|
|
|
|
if (is_request_or_reply) {
|
|
|
|
line = tvb_get_ptr (tvb, offset, first_linelen);
|
2010-04-28 16:09:25 +00:00
|
|
|
col_add_fstr (pinfo->cinfo, COL_INFO, "%s ",
|
2009-05-24 22:39:07 +00:00
|
|
|
format_text (line, first_linelen));
|
|
|
|
} else {
|
|
|
|
col_set_str (pinfo->cinfo, COL_INFO, "MEMCACHE Continuation");
|
|
|
|
}
|
|
|
|
|
|
|
|
orig_offset = offset;
|
|
|
|
|
2011-07-19 18:48:31 +00:00
|
|
|
memcache_item = proto_tree_add_item (tree, proto_memcache, tvb, offset, -1, ENC_NA);
|
2009-05-24 22:39:07 +00:00
|
|
|
memcache_tree = proto_item_add_subtree (memcache_item, ett_memcache);
|
|
|
|
|
2010-04-28 16:09:25 +00:00
|
|
|
/* Process the packet data. The first line is expected to be a
|
2013-02-26 01:06:19 +00:00
|
|
|
* header. If it's not a header then we don't dissect.
|
2010-04-28 16:09:25 +00:00
|
|
|
* At this point, we already know if it is a request or a
|
2009-05-24 22:39:07 +00:00
|
|
|
* response.
|
|
|
|
*/
|
|
|
|
if (tvb_reported_length_remaining (tvb, offset) != 0) {
|
|
|
|
/* Dissect a request or a response. */
|
|
|
|
if (is_request_or_reply && reqresp_dissector) {
|
2012-07-12 17:22:47 +00:00
|
|
|
next_offset = reqresp_dissector (tvb, pinfo, memcache_tree,
|
|
|
|
offset, line, lineend, opcode);
|
|
|
|
if (next_offset == -1) {
|
|
|
|
/* Error in dissecting. */
|
|
|
|
return -1;
|
2009-05-24 22:39:07 +00:00
|
|
|
}
|
2012-07-12 17:22:47 +00:00
|
|
|
offset = next_offset;
|
2009-05-24 22:39:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If a 'bytes' value was supplied, the amount of data to be
|
|
|
|
* processed as MEMCACHE payload is the minimum of the 'bytes'
|
|
|
|
* value and the amount of data remaining in the frame.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
datalen = tvb_length_remaining (tvb, offset);
|
|
|
|
if (datalen > 0) {
|
|
|
|
/*
|
|
|
|
* We've processed "datalen" bytes worth of data
|
|
|
|
* (which may be no data at all); advance the
|
|
|
|
* offset past whatever data we've processed.
|
|
|
|
*/
|
|
|
|
offset += datalen;
|
|
|
|
}
|
|
|
|
|
|
|
|
return offset - orig_offset;
|
|
|
|
}
|
|
|
|
|
2010-04-28 16:09:25 +00:00
|
|
|
/* Payload dissector
|
2009-05-24 22:39:07 +00:00
|
|
|
* <data block>\r\n
|
2010-04-28 16:09:25 +00:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
content_data_dissector (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset,
|
2009-05-24 22:39:07 +00:00
|
|
|
int content_length, guint8 opcode)
|
|
|
|
{
|
|
|
|
gint datalen;
|
|
|
|
gboolean short_pkt = FALSE;
|
|
|
|
|
2010-04-28 16:09:25 +00:00
|
|
|
/*
|
|
|
|
* Expecting to read 'content_length' number of bytes from
|
|
|
|
* the buffer. It is not necessary that we have all the
|
2009-05-24 22:39:07 +00:00
|
|
|
* content_length bytes available to read.
|
|
|
|
*/
|
2011-04-18 15:29:25 +00:00
|
|
|
if (tvb_reported_length_remaining (tvb, offset) != 0) {
|
2009-05-24 22:39:07 +00:00
|
|
|
/* bytes actually remaining in this tvbuff. */
|
|
|
|
datalen = tvb_length_remaining (tvb, offset);
|
|
|
|
if (content_length >= 0) {
|
|
|
|
if (datalen >= (content_length + 2)) { /* also consider \r\n*/
|
|
|
|
datalen = content_length;
|
|
|
|
} else {
|
|
|
|
short_pkt = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* dissect the data block. */
|
|
|
|
dissect_value (tvb, pinfo, tree, offset, datalen, opcode, TRUE);
|
|
|
|
if (datalen > 0) {
|
|
|
|
/*
|
|
|
|
* We've processed "datalen" bytes worth of data
|
|
|
|
* (which may be no data at all); advance the
|
|
|
|
* offset past whatever data we've processed.
|
|
|
|
*/
|
|
|
|
if (!short_pkt) {
|
|
|
|
offset += (datalen + 2); /* go past /r/n*/
|
|
|
|
} else {
|
|
|
|
offset += datalen; /* short packet; no /r/n*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the occurrences of a ':' in a stat response. */
|
|
|
|
static guint
|
2010-04-28 16:09:25 +00:00
|
|
|
find_stat_colon (const guchar *line, const guchar *lineend,
|
2009-05-24 22:39:07 +00:00
|
|
|
const guchar **first_colon, const guchar **last_colon)
|
|
|
|
{
|
|
|
|
const guchar *linep, *temp;
|
|
|
|
guint occurrences = 0;
|
|
|
|
guchar c;
|
|
|
|
|
|
|
|
linep = line;
|
2010-04-28 16:09:25 +00:00
|
|
|
while (linep < lineend) {
|
2009-05-24 22:39:07 +00:00
|
|
|
temp = linep;
|
|
|
|
c = *linep++;
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case ':':
|
|
|
|
occurrences++;
|
|
|
|
if (occurrences == 1) {
|
|
|
|
*first_colon = temp;
|
|
|
|
} else if (occurrences == 2) {
|
|
|
|
*last_colon = temp;
|
|
|
|
} else {
|
2010-04-28 16:09:25 +00:00
|
|
|
/* anything other than 1 or 2;
|
|
|
|
* return immediately
|
2009-05-24 22:39:07 +00:00
|
|
|
*/
|
|
|
|
return occurrences;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return occurrences;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* incr/decr response dissector */
|
|
|
|
static int
|
|
|
|
incr_dissector (tvbuff_t *tvb, proto_tree *tree, int offset)
|
|
|
|
{
|
|
|
|
gint next_offset;
|
2011-04-18 15:29:25 +00:00
|
|
|
int linelen;
|
2009-05-24 22:39:07 +00:00
|
|
|
const guchar *line, *lineend;
|
|
|
|
|
|
|
|
const guchar *next_token;
|
|
|
|
int tokenlen;
|
|
|
|
|
|
|
|
/* expecting to read 'bytes' number of bytes from the buffer. */
|
2011-04-18 15:29:25 +00:00
|
|
|
if (tvb_reported_length_remaining (tvb, offset) != 0) {
|
2009-05-24 22:39:07 +00:00
|
|
|
/* Find the end of the line. */
|
|
|
|
linelen = tvb_find_line_end (tvb, offset,
|
|
|
|
tvb_ensure_length_remaining (tvb, offset), &next_offset,
|
|
|
|
FALSE);
|
|
|
|
if (linelen < 0) {
|
|
|
|
/* header is out of the packet limits. */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a buffer that refers to the line.
|
2010-04-28 16:09:25 +00:00
|
|
|
* in other words, the unstructured portion
|
2009-05-24 22:39:07 +00:00
|
|
|
* of memcache.
|
|
|
|
*/
|
|
|
|
line = tvb_get_ptr (tvb, offset, linelen);
|
|
|
|
lineend = line + linelen;
|
2010-04-28 16:09:25 +00:00
|
|
|
|
2009-05-24 22:39:07 +00:00
|
|
|
/* 64 bit value */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-07-19 10:51:12 +00:00
|
|
|
proto_tree_add_item (tree, hf_uint64_response, tvb, offset, tokenlen, ENC_BIG_ENDIAN);
|
2009-05-24 22:39:07 +00:00
|
|
|
|
|
|
|
/* CRLF */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0) {
|
|
|
|
return next_offset;
|
|
|
|
} else {
|
|
|
|
return -1; /* invalid token */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* stats response dissector */
|
|
|
|
static int
|
|
|
|
stat_dissector (tvbuff_t *tvb, proto_tree *tree, int offset)
|
|
|
|
{
|
|
|
|
guint occurrences = 0;
|
|
|
|
const guchar *first_colon = NULL, *last_colon = NULL;
|
|
|
|
int tokenlen, linelen;
|
|
|
|
gint next_offset;
|
|
|
|
const guchar *next_token;
|
|
|
|
const guchar *line, *lineend;
|
|
|
|
guint32 slabclass;
|
|
|
|
guchar response_chars[21];
|
|
|
|
|
2011-04-18 15:29:25 +00:00
|
|
|
while (tvb_reported_length_remaining (tvb, offset) != 0) {
|
2009-05-24 22:39:07 +00:00
|
|
|
/* Find the end of the line. */
|
|
|
|
linelen = tvb_find_line_end (tvb, offset,
|
|
|
|
tvb_ensure_length_remaining (tvb, offset), &next_offset,
|
|
|
|
FALSE);
|
|
|
|
if (linelen < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a buffer that refers to the line.
|
|
|
|
*/
|
|
|
|
line = tvb_get_ptr (tvb, offset, linelen);
|
|
|
|
lineend = line + linelen;
|
|
|
|
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if ((tokenlen == 4) && strncmp (line, "STAT", tokenlen) == 0) {
|
2011-10-15 18:46:26 +00:00
|
|
|
proto_tree_add_item (tree, hf_command, tvb, offset, tokenlen, ENC_ASCII|ENC_NA);
|
2009-05-24 22:39:07 +00:00
|
|
|
offset += (int) (next_token - line);
|
|
|
|
line = next_token;
|
|
|
|
occurrences = find_stat_colon (line, lineend, &first_colon, &last_colon);
|
|
|
|
} else if ((tokenlen == 3) && strncmp (line, "END", tokenlen) == 0) {
|
|
|
|
/* done. reached an end of response. */
|
|
|
|
offset += (int) (next_token - line);
|
|
|
|
return offset;
|
|
|
|
} else {
|
|
|
|
/* invalid token */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (occurrences) {
|
|
|
|
case 2: /* stats items: 2 colons */
|
|
|
|
/* subcommand 'items' */
|
|
|
|
tokenlen = (int) (first_colon - line);
|
2011-10-15 18:46:26 +00:00
|
|
|
proto_tree_add_item (tree, hf_subcommand, tvb, offset, tokenlen, ENC_ASCII|ENC_NA);
|
2009-05-24 22:39:07 +00:00
|
|
|
offset += tokenlen + 1;
|
|
|
|
|
|
|
|
/* slabclass */
|
|
|
|
tokenlen = (int) (last_colon - first_colon - 1);
|
|
|
|
if (tokenlen > 10 || tokenlen <= 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
memcpy (response_chars, first_colon + 1, tokenlen);
|
|
|
|
response_chars[tokenlen] = '\0';
|
|
|
|
|
|
|
|
slabclass = (guint32) strtoul (response_chars, NULL, 10);
|
|
|
|
proto_tree_add_uint (tree, hf_slabclass, tvb, offset, tokenlen, slabclass);
|
|
|
|
offset += tokenlen + 1;
|
|
|
|
line = last_colon + 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: /* stats slabs: 1 colon */
|
|
|
|
tokenlen = (int) (first_colon - line);
|
|
|
|
if (tokenlen > 10 || tokenlen <= 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
memcpy (response_chars, line, tokenlen);
|
|
|
|
response_chars[tokenlen] = '\0';
|
|
|
|
|
|
|
|
slabclass = (guint32) strtoul (response_chars, NULL, 10);
|
|
|
|
proto_tree_add_uint (tree, hf_slabclass, tvb, offset, tokenlen, slabclass);
|
|
|
|
|
|
|
|
offset += (int) (tokenlen + 1);
|
|
|
|
line = first_colon + 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0: /* stats: 0 colons */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* invalid token. */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* <hf_name> <hf_name_value>\r\n */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0) {
|
|
|
|
return -1; /* invalid token */
|
|
|
|
}
|
|
|
|
|
2011-10-15 18:46:26 +00:00
|
|
|
proto_tree_add_item (tree, hf_name, tvb, offset, tokenlen, ENC_ASCII|ENC_NA);
|
2009-05-24 22:39:07 +00:00
|
|
|
offset += (int) (next_token - line);
|
|
|
|
line = next_token;
|
|
|
|
|
|
|
|
/* value */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0) {
|
|
|
|
return -1; /* invalid token */
|
|
|
|
}
|
2011-10-15 18:46:26 +00:00
|
|
|
proto_tree_add_item (tree, hf_name_value, tvb, offset, tokenlen, ENC_ASCII|ENC_NA);
|
2009-05-24 22:39:07 +00:00
|
|
|
|
|
|
|
offset = next_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get/gets response dissector */
|
|
|
|
static int
|
|
|
|
get_response_dissector (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset)
|
|
|
|
{
|
|
|
|
gint next_offset;
|
2011-04-18 15:29:25 +00:00
|
|
|
int linelen;
|
2009-05-24 22:39:07 +00:00
|
|
|
const guchar *line, *lineend;
|
|
|
|
const guchar *next_token;
|
|
|
|
int tokenlen;
|
|
|
|
guint16 flags;
|
|
|
|
guint32 bytes;
|
|
|
|
guint64 cas;
|
|
|
|
guint8 opcode = 0xff;
|
|
|
|
gchar response_chars[21]; /* cover uint64 (20 + 1) bytes*/
|
|
|
|
|
|
|
|
/* expecting to read 'bytes' number of bytes from the buffer. */
|
2011-04-18 15:29:25 +00:00
|
|
|
while (tvb_reported_length_remaining (tvb, offset) != 0) {
|
2009-05-24 22:39:07 +00:00
|
|
|
/* Find the end of the line. */
|
|
|
|
linelen = tvb_find_line_end (tvb, offset,
|
|
|
|
tvb_ensure_length_remaining (tvb, offset), &next_offset,
|
|
|
|
FALSE);
|
|
|
|
if (linelen < 0) {
|
|
|
|
/* header is out of the packet limits. */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a buffer that refers to the line.
|
2010-04-28 16:09:25 +00:00
|
|
|
* in other words, the unstructured portion
|
2009-05-24 22:39:07 +00:00
|
|
|
* of memcache.
|
|
|
|
*/
|
|
|
|
line = tvb_get_ptr (tvb, offset, linelen);
|
|
|
|
lineend = line + linelen;
|
2010-04-28 16:09:25 +00:00
|
|
|
|
2009-05-24 22:39:07 +00:00
|
|
|
/* VALUE token */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0) {
|
|
|
|
/* error */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((tokenlen == 5) && strncmp (line, "VALUE", tokenlen) == 0) {
|
|
|
|
/* proceed */
|
|
|
|
} else if ((tokenlen == 3) && strncmp (line, "END", tokenlen) == 0) {
|
|
|
|
/* done. reached an end of response. */
|
|
|
|
offset += (int) (next_token - line);
|
|
|
|
return offset;
|
|
|
|
} else {
|
|
|
|
/* invalid token */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
offset += (int) (next_token - line);
|
|
|
|
line = next_token;
|
|
|
|
|
|
|
|
/* key */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
2010-04-28 16:09:25 +00:00
|
|
|
if (tokenlen == 0) {
|
2009-05-24 22:39:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
dissect_key (tvb, pinfo, tree, offset, tokenlen, opcode, TRUE);
|
|
|
|
offset += (int) (next_token - line);
|
|
|
|
line = next_token;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0 || tokenlen > 5) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
memcpy (response_chars, line, tokenlen);
|
|
|
|
response_chars[tokenlen] = '\0';
|
|
|
|
|
|
|
|
flags = (guint16) strtoul (response_chars, NULL, 10);
|
|
|
|
proto_tree_add_uint (tree, hf_flags, tvb, offset, tokenlen, flags);
|
|
|
|
|
|
|
|
offset += (int) (next_token - line);
|
|
|
|
line = next_token;
|
2010-04-28 16:09:25 +00:00
|
|
|
|
2009-05-24 22:39:07 +00:00
|
|
|
/* bytes */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0 || tokenlen > 10) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
memcpy (response_chars, line, tokenlen);
|
|
|
|
response_chars[tokenlen] = '\0';
|
|
|
|
|
|
|
|
bytes = (guint32) strtoul (response_chars, NULL, 10);
|
|
|
|
proto_tree_add_uint (tree, hf_value_length, tvb, offset, tokenlen, bytes);
|
|
|
|
|
|
|
|
offset += (int) (next_token - line);
|
|
|
|
line = next_token;
|
|
|
|
|
|
|
|
/* check if cas id is present */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen > 20) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tokenlen != 0) { /* reached the end of line; CRLF */
|
|
|
|
memcpy (response_chars, line, tokenlen);
|
|
|
|
response_chars[tokenlen] = '\0';
|
|
|
|
|
|
|
|
cas = (guint64) strtoul (response_chars, NULL, 10);
|
2009-05-24 23:23:06 +00:00
|
|
|
proto_tree_add_uint64 (tree, hf_cas, tvb, offset, tokenlen, cas);
|
2009-05-24 22:39:07 +00:00
|
|
|
|
|
|
|
/* CRLF */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen != 0) {
|
|
|
|
return -1; /* invalid token */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
offset = next_offset;
|
|
|
|
/* <datablock>\r\n */
|
2010-04-28 16:09:25 +00:00
|
|
|
offset = content_data_dissector (tvb, pinfo, tree, offset, bytes, opcode);
|
2009-05-24 22:39:07 +00:00
|
|
|
if (offset == -1) {
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Basic memcache response dissector. */
|
2010-04-28 16:09:25 +00:00
|
|
|
static int
|
2009-05-24 22:39:07 +00:00
|
|
|
memcache_response_dissector (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset,
|
|
|
|
const guchar *line, const guchar *lineend, guint8 opcode)
|
|
|
|
{
|
|
|
|
const guchar *next_token;
|
|
|
|
int tokenlen;
|
|
|
|
|
|
|
|
switch (opcode) {
|
|
|
|
|
|
|
|
case OP_GET:
|
|
|
|
case OP_GETS:
|
|
|
|
return get_response_dissector (tvb, pinfo, tree, offset);
|
|
|
|
|
|
|
|
case OP_VERSION:
|
|
|
|
/* response code. */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0) {
|
|
|
|
return -1;
|
2010-04-28 16:09:25 +00:00
|
|
|
}
|
2009-05-24 22:39:07 +00:00
|
|
|
if ((tokenlen == 7) && strncmp (line, "VERSION", tokenlen) == 0) {
|
|
|
|
offset += (int) (next_token - line);
|
|
|
|
line = next_token;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* version string */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0) {
|
|
|
|
/* expecting version string. */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-10-15 18:46:26 +00:00
|
|
|
proto_tree_add_item (tree, hf_version, tvb, offset, tokenlen, ENC_ASCII|ENC_NA);
|
2009-05-24 22:39:07 +00:00
|
|
|
offset += (int) (next_token - line);
|
|
|
|
line = next_token;
|
|
|
|
|
|
|
|
/* CRLF */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
2009-06-11 11:52:42 +00:00
|
|
|
if (tokenlen != 0) {
|
2009-05-24 22:39:07 +00:00
|
|
|
/* invalid token */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
|
|
|
|
case OP_STAT:
|
|
|
|
return stat_dissector (tvb, tree, offset);
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* response code. */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* all the following mark an end of a response.
|
|
|
|
* should take care of set, add, cas, append, replace
|
2010-04-28 16:09:25 +00:00
|
|
|
* prepend, flush_all, verbosity, delete and to an extent
|
2009-05-24 22:39:07 +00:00
|
|
|
* incr, decr and stat commands.
|
|
|
|
*/
|
|
|
|
if ((tokenlen == 6 && strncmp (line, "STORED", tokenlen) == 0) ||
|
|
|
|
(tokenlen == 10 && strncmp (line, "NOT_STORED", tokenlen) == 0) ||
|
|
|
|
(tokenlen == 6 && strncmp (line, "EXISTS", tokenlen) == 0) ||
|
|
|
|
(tokenlen == 9 && strncmp (line, "NOT_FOUND", tokenlen) == 0) ||
|
|
|
|
(tokenlen == 7 && strncmp (line, "DELETED", tokenlen) == 0) ||
|
|
|
|
(tokenlen == 2 && strncmp (line, "OK", tokenlen) == 0) ||
|
2010-04-28 16:09:25 +00:00
|
|
|
(tokenlen == 3 && strncmp (line, "END", tokenlen) == 0))
|
2009-05-24 22:39:07 +00:00
|
|
|
{
|
2011-10-15 18:46:26 +00:00
|
|
|
proto_tree_add_item (tree, hf_response, tvb, offset, tokenlen, ENC_ASCII|ENC_NA);
|
2009-05-24 22:39:07 +00:00
|
|
|
offset += (int) (next_token - line);
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if we have reached this point:
|
2010-04-28 16:09:25 +00:00
|
|
|
* it is either an incr/decr response of the format
|
|
|
|
* <value>\r\n.
|
2009-05-24 22:39:07 +00:00
|
|
|
* or
|
|
|
|
* "stats sizes" response of the format:
|
|
|
|
* <size> <count> \r\n
|
|
|
|
*/
|
|
|
|
if (opcode == OP_INCREMENT) {
|
|
|
|
return incr_dissector (tvb, tree, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Basic memcache request dissector. */
|
2010-04-28 16:09:25 +00:00
|
|
|
static int
|
2009-05-24 22:39:07 +00:00
|
|
|
memcache_request_dissector (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset,
|
|
|
|
const guchar *line, const guchar *lineend, guint8 opcode)
|
|
|
|
{
|
|
|
|
const guchar *next_token;
|
|
|
|
int tokenlen;
|
|
|
|
|
|
|
|
guint16 flags;
|
|
|
|
guint32 expiration;
|
|
|
|
guint32 bytes;
|
|
|
|
guint64 cas;
|
|
|
|
gchar response_chars[21]; /* cover uint64 (20 + 1) bytes*/
|
|
|
|
|
|
|
|
/* command. */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2011-10-15 18:46:26 +00:00
|
|
|
proto_tree_add_item (tree, hf_command, tvb, offset, tokenlen, ENC_ASCII|ENC_NA);
|
2009-05-24 22:39:07 +00:00
|
|
|
offset += (int) (next_token - line);
|
|
|
|
line = next_token;
|
|
|
|
|
|
|
|
switch (opcode) {
|
|
|
|
|
|
|
|
case OP_SET:
|
|
|
|
case OP_ADD:
|
|
|
|
case OP_REPLACE:
|
|
|
|
case OP_APPEND:
|
|
|
|
case OP_PREPEND:
|
|
|
|
case OP_CAS:
|
|
|
|
|
|
|
|
/* key */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
2010-04-28 16:09:25 +00:00
|
|
|
if (tokenlen == 0) {
|
2009-05-24 22:39:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
dissect_key (tvb, pinfo, tree, offset, tokenlen, opcode, TRUE);
|
|
|
|
offset += (int) (next_token - line);
|
|
|
|
line = next_token;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0 || tokenlen > 5) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
memcpy (response_chars, line, tokenlen);
|
|
|
|
response_chars[tokenlen] = '\0';
|
|
|
|
|
|
|
|
flags = (guint16) strtoul (response_chars, NULL, 10);
|
|
|
|
proto_tree_add_uint (tree, hf_flags, tvb, offset, tokenlen, flags);
|
|
|
|
|
|
|
|
offset += (int) (next_token - line);
|
|
|
|
line = next_token;
|
2010-04-28 16:09:25 +00:00
|
|
|
|
|
|
|
/* expiration */
|
2009-05-24 22:39:07 +00:00
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0 || tokenlen > 10) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
memcpy (response_chars, line, tokenlen);
|
|
|
|
response_chars[tokenlen] = '\0';
|
|
|
|
|
|
|
|
expiration = (guint32) strtoul (response_chars, NULL, 10);
|
|
|
|
proto_tree_add_uint (tree, hf_expiration, tvb, offset, tokenlen, expiration);
|
|
|
|
|
|
|
|
offset += (int) (next_token - line);
|
|
|
|
line = next_token;
|
|
|
|
|
|
|
|
/* bytes */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0 || tokenlen > 10) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
memcpy (response_chars, line, tokenlen);
|
|
|
|
response_chars[tokenlen] = '\0';
|
|
|
|
|
|
|
|
bytes = (guint32) strtoul (response_chars, NULL, 10);
|
|
|
|
proto_tree_add_uint (tree, hf_value_length, tvb, offset, tokenlen, bytes);
|
|
|
|
|
|
|
|
offset += (int) (next_token - line);
|
|
|
|
line = next_token;
|
|
|
|
|
|
|
|
/* cas id. */
|
|
|
|
if (opcode == OP_CAS) {
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0 || tokenlen > 20) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
memcpy (response_chars, line, tokenlen);
|
|
|
|
response_chars[tokenlen] = '\0';
|
|
|
|
|
|
|
|
cas = (guint64) strtoul (response_chars, NULL, 10);
|
2009-05-24 23:23:06 +00:00
|
|
|
proto_tree_add_uint64 (tree, hf_cas, tvb, offset, tokenlen, cas);
|
2009-05-24 22:39:07 +00:00
|
|
|
|
|
|
|
offset += (int) (next_token - line);
|
|
|
|
line = next_token;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if the following bit is "noreply" or
|
2010-04-28 16:09:25 +00:00
|
|
|
* the actual data block.
|
2009-05-24 22:39:07 +00:00
|
|
|
*/
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen != 0) {
|
2010-04-28 16:09:25 +00:00
|
|
|
if (tokenlen == 7 && strncmp (line, "noreply", 7) == 0) {
|
2011-10-15 18:46:26 +00:00
|
|
|
proto_tree_add_item (tree, hf_noreply, tvb, offset, tokenlen, ENC_ASCII|ENC_NA);
|
2009-05-24 22:39:07 +00:00
|
|
|
}
|
|
|
|
offset += (int) (next_token - line);
|
|
|
|
}
|
|
|
|
|
|
|
|
offset += 2 ; /* go past /r/n*/
|
|
|
|
/* <datablock>\r\n */
|
2010-04-28 16:09:25 +00:00
|
|
|
offset = content_data_dissector (tvb, pinfo, tree, offset, bytes, opcode);
|
2009-05-24 22:39:07 +00:00
|
|
|
if (offset == -1) {
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_INCREMENT:
|
|
|
|
case OP_DECREMENT:
|
|
|
|
/* key */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
2010-04-28 16:09:25 +00:00
|
|
|
if (tokenlen == 0) {
|
2009-05-24 22:39:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
dissect_key (tvb, pinfo, tree, offset, tokenlen, opcode, TRUE);
|
|
|
|
offset += (int) (next_token - line);
|
|
|
|
line = next_token;
|
|
|
|
|
|
|
|
/* value */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2011-10-15 18:46:26 +00:00
|
|
|
proto_tree_add_item (tree, hf_value, tvb, offset, tokenlen, ENC_ASCII|ENC_NA);
|
2009-05-24 22:39:07 +00:00
|
|
|
offset += (int) (next_token - line);
|
|
|
|
line = next_token;
|
|
|
|
|
|
|
|
/* check for "noreply" */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0) {
|
|
|
|
return offset; /* reached CRLF */
|
|
|
|
}
|
|
|
|
if (tokenlen == 7 && strncmp (line, "noreply", 7) == 0) {
|
2011-10-15 18:46:26 +00:00
|
|
|
proto_tree_add_item (tree, hf_noreply, tvb, offset, tokenlen, ENC_ASCII|ENC_NA);
|
2009-05-24 22:39:07 +00:00
|
|
|
offset += (int) (next_token - line);
|
|
|
|
line = next_token;
|
|
|
|
} else {
|
|
|
|
return -1; /* should have been noreply or CRLF. */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* CRLF */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0) {
|
|
|
|
return offset; /* CRLF */
|
|
|
|
} else {
|
|
|
|
/*something's wrong; invalid command maybe. */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_DELETE:
|
|
|
|
/* key */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
2010-04-28 16:09:25 +00:00
|
|
|
if (tokenlen == 0) {
|
2009-05-24 22:39:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* dissect key. */
|
|
|
|
dissect_key (tvb, pinfo, tree, offset, tokenlen, opcode, TRUE);
|
|
|
|
offset += (int) (next_token - line);
|
|
|
|
line = next_token;
|
|
|
|
|
2013-02-26 01:06:19 +00:00
|
|
|
/* check if it's expiration or noreply */
|
2009-05-24 22:39:07 +00:00
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0) {
|
|
|
|
return offset; /* neither expiration nor noreply; CRLF */
|
|
|
|
}
|
|
|
|
if (tokenlen <= 10) {
|
|
|
|
if (tokenlen == 7 && strncmp (line, "noreply", 7) == 0) {
|
|
|
|
/* noreply */
|
2011-10-15 18:46:26 +00:00
|
|
|
proto_tree_add_item (tree, hf_noreply, tvb, offset, tokenlen, ENC_ASCII|ENC_NA);
|
2009-05-24 22:39:07 +00:00
|
|
|
} else {
|
|
|
|
/* expiration */
|
|
|
|
memcpy (response_chars, line, tokenlen);
|
|
|
|
response_chars[tokenlen] = '\0';
|
|
|
|
|
|
|
|
expiration = (guint32) strtoul (response_chars, NULL, 10);
|
|
|
|
proto_tree_add_uint (tree, hf_expiration, tvb, offset, tokenlen, expiration);
|
|
|
|
}
|
|
|
|
offset += (int) (next_token - line);
|
|
|
|
line = next_token;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* CRLF */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0) {
|
|
|
|
return offset;
|
|
|
|
} else {
|
|
|
|
/*something's wrong; invalid command maybe. */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_GET:
|
|
|
|
case OP_GETS:
|
|
|
|
/* could be followed by any number of keys, add
|
|
|
|
* them one by one. tokenlen cannot be 0 to begin
|
|
|
|
* with.
|
|
|
|
*/
|
|
|
|
while (tokenlen != 0) {
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0) {
|
|
|
|
return offset; /* CRLF */
|
|
|
|
}
|
|
|
|
dissect_key (tvb, pinfo, tree, offset, tokenlen, opcode, TRUE);
|
|
|
|
offset += (int) (next_token - line);
|
|
|
|
line = next_token;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_STAT:
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0) { /* just the 'stats' command;*/
|
|
|
|
return offset;
|
|
|
|
} else { /* there is a sub command; record it*/
|
2011-10-15 18:46:26 +00:00
|
|
|
proto_tree_add_item (tree, hf_subcommand, tvb, offset, tokenlen, ENC_ASCII|ENC_NA);
|
2009-05-24 22:39:07 +00:00
|
|
|
offset += (int) (next_token - line);
|
|
|
|
line = next_token;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* CRLF */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0) {
|
|
|
|
return offset;
|
|
|
|
} else {
|
|
|
|
/* something's wrong; invalid command maybe. */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_FLUSH:
|
2013-02-26 01:06:19 +00:00
|
|
|
/* check if it's expiration or noreply */
|
2009-05-24 22:39:07 +00:00
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0) {
|
|
|
|
return offset; /* neither expiration nor noreply; CRLF */
|
|
|
|
}
|
|
|
|
if (tokenlen <= 10) {
|
|
|
|
if (tokenlen == 7 && strncmp (line, "noreply", 7) == 0) {
|
|
|
|
/* noreply */
|
2011-10-15 18:46:26 +00:00
|
|
|
proto_tree_add_item (tree, hf_noreply, tvb, offset, tokenlen, ENC_ASCII|ENC_NA);
|
2009-05-24 22:39:07 +00:00
|
|
|
} else {
|
|
|
|
/* expiration */
|
|
|
|
memcpy (response_chars, line, tokenlen);
|
|
|
|
response_chars[tokenlen] = '\0';
|
|
|
|
|
|
|
|
expiration = (guint32) strtoul (response_chars, NULL, 10);
|
|
|
|
proto_tree_add_uint (tree, hf_expiration, tvb, offset, tokenlen, expiration);
|
|
|
|
}
|
|
|
|
offset += (int) (next_token - line);
|
|
|
|
line = next_token;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* maybe noreply now? */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0) {
|
|
|
|
return offset;
|
2010-04-28 16:09:25 +00:00
|
|
|
}
|
|
|
|
if (tokenlen == 7 && strncmp (line, "noreply", 7) == 0) {
|
2009-05-24 22:39:07 +00:00
|
|
|
/* noreply */
|
2011-10-15 18:46:26 +00:00
|
|
|
proto_tree_add_item (tree, hf_noreply, tvb, offset, tokenlen, ENC_ASCII|ENC_NA);
|
2009-05-24 22:39:07 +00:00
|
|
|
offset += (int) (next_token - line);
|
|
|
|
} else {
|
|
|
|
return -1; /* expecting CRLF and if not noreply*/
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_VERBOSE:
|
|
|
|
/* not implemented for now.*/
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_VERSION:
|
|
|
|
case OP_QUIT:
|
|
|
|
/* CRLF */
|
|
|
|
tokenlen = get_token_len (line, lineend, &next_token);
|
|
|
|
if (tokenlen == 0) {
|
|
|
|
return offset;
|
|
|
|
} else {
|
|
|
|
/*something's wrong; invalid command maybe. */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* invalid command maybe; break out. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* any message that is not starting with the following keywords
|
|
|
|
* is a response.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
is_memcache_request_or_reply (const gchar *data, int linelen, guint8 *opcode,
|
2010-04-28 16:09:25 +00:00
|
|
|
memcache_type_t *type, int *expect_content_length,
|
2009-05-24 22:39:07 +00:00
|
|
|
ReqRespDissector *reqresp_dissector)
|
|
|
|
{
|
|
|
|
const guchar *ptr = (const guchar *)data;
|
|
|
|
int is_request_or_response = FALSE;
|
|
|
|
int indx = 0;
|
|
|
|
|
|
|
|
/* look for a space */
|
|
|
|
while (indx < linelen) {
|
|
|
|
if (*ptr == ' ')
|
|
|
|
break;
|
|
|
|
|
|
|
|
ptr++;
|
|
|
|
indx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* is it a response? */
|
|
|
|
switch (indx) {
|
|
|
|
case 2:
|
|
|
|
if (strncmp (data, "OK", indx) == 0) {
|
|
|
|
*type = MEMCACHE_RESPONSE;
|
|
|
|
is_request_or_response = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
if (strncmp (data, "END", indx) == 0) {
|
|
|
|
*type = MEMCACHE_RESPONSE;
|
|
|
|
is_request_or_response = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
if (strncmp (data, "STAT", indx) == 0) {
|
|
|
|
*opcode = OP_STAT;
|
|
|
|
*type = MEMCACHE_RESPONSE;
|
|
|
|
is_request_or_response = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
if (strncmp (data, "VALUE", indx) == 0) {
|
|
|
|
*opcode = OP_GET;
|
|
|
|
*type = MEMCACHE_RESPONSE;
|
|
|
|
*expect_content_length = TRUE;
|
|
|
|
is_request_or_response = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
if (strncmp (data, "EXISTS", indx) == 0 ||
|
|
|
|
strncmp (data, "STORED", indx) == 0) {
|
|
|
|
*type = MEMCACHE_RESPONSE;
|
|
|
|
is_request_or_response = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 7:
|
2010-04-28 16:09:25 +00:00
|
|
|
if (strncmp (data, "VERSION", indx) == 0) {
|
2009-05-24 22:39:07 +00:00
|
|
|
*opcode = OP_VERSION;
|
|
|
|
*type = MEMCACHE_RESPONSE;
|
|
|
|
is_request_or_response = TRUE;
|
|
|
|
} else if (strncmp (data, "DELETED", indx) == 0) {
|
|
|
|
*opcode = OP_DELETE;
|
|
|
|
*type = MEMCACHE_RESPONSE;
|
|
|
|
is_request_or_response = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 9:
|
|
|
|
if (strncmp (data, "NOT_FOUND", indx) == 0) {
|
|
|
|
*type = MEMCACHE_RESPONSE;
|
|
|
|
is_request_or_response = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 10:
|
|
|
|
if (strncmp (data, "NOT_STORED", indx) == 0) {
|
|
|
|
*type = MEMCACHE_RESPONSE;
|
|
|
|
is_request_or_response = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break; /* is it a request? */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_request_or_response && reqresp_dissector) {
|
|
|
|
*reqresp_dissector = memcache_response_dissector;
|
|
|
|
return is_request_or_response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* is it a request? */
|
2010-04-28 16:09:25 +00:00
|
|
|
switch (indx) {
|
|
|
|
case 3:
|
2009-05-24 22:39:07 +00:00
|
|
|
if (strncmp (data, "get", indx) == 0) {
|
|
|
|
*opcode = OP_GET;
|
2010-04-28 16:09:25 +00:00
|
|
|
*type = MEMCACHE_REQUEST;
|
2009-05-24 22:39:07 +00:00
|
|
|
is_request_or_response = TRUE;
|
|
|
|
} else if (strncmp (data, "set", indx) == 0) {
|
|
|
|
*opcode = OP_SET;
|
2010-04-28 16:09:25 +00:00
|
|
|
*type = MEMCACHE_REQUEST;
|
2009-05-24 22:39:07 +00:00
|
|
|
*expect_content_length = TRUE;
|
|
|
|
is_request_or_response = TRUE;
|
|
|
|
} else if (strncmp (data, "add", indx) == 0) {
|
|
|
|
*opcode = OP_ADD;
|
2010-04-28 16:09:25 +00:00
|
|
|
*type = MEMCACHE_REQUEST;
|
2009-05-24 22:39:07 +00:00
|
|
|
*expect_content_length = TRUE;
|
|
|
|
is_request_or_response = TRUE;
|
|
|
|
} else if (strncmp (data, "cas", indx) == 0) {
|
|
|
|
*opcode = OP_CAS;
|
2010-04-28 16:09:25 +00:00
|
|
|
*type = MEMCACHE_REQUEST;
|
2009-05-24 22:39:07 +00:00
|
|
|
*expect_content_length = TRUE;
|
|
|
|
is_request_or_response = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-04-28 16:09:25 +00:00
|
|
|
case 4:
|
2009-05-24 22:39:07 +00:00
|
|
|
if (strncmp (data, "gets", indx) == 0) {
|
|
|
|
*opcode = OP_GETS;
|
2010-04-28 16:09:25 +00:00
|
|
|
*type = MEMCACHE_REQUEST;
|
2009-05-24 22:39:07 +00:00
|
|
|
is_request_or_response = TRUE;
|
|
|
|
} else if (strncmp (data, "incr", indx) == 0) {
|
|
|
|
*opcode = OP_INCREMENT;
|
2010-04-28 16:09:25 +00:00
|
|
|
*type = MEMCACHE_REQUEST;
|
2009-05-24 22:39:07 +00:00
|
|
|
is_request_or_response = TRUE;
|
|
|
|
} else if (strncmp (data, "decr", indx) == 0) {
|
|
|
|
*opcode = OP_DECREMENT;
|
2010-04-28 16:09:25 +00:00
|
|
|
*type = MEMCACHE_REQUEST;
|
2009-05-24 22:39:07 +00:00
|
|
|
is_request_or_response = TRUE;
|
|
|
|
} else if (strncmp (data, "quit", indx) == 0) {
|
|
|
|
*opcode = OP_QUIT;
|
2010-04-28 16:09:25 +00:00
|
|
|
*type = MEMCACHE_REQUEST;
|
2009-05-24 22:39:07 +00:00
|
|
|
is_request_or_response = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
if (strncmp (data, "stats", indx) == 0) {
|
|
|
|
*opcode = OP_STAT;
|
|
|
|
*type = MEMCACHE_REQUEST;
|
|
|
|
is_request_or_response = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-04-28 16:09:25 +00:00
|
|
|
case 6:
|
2009-05-24 22:39:07 +00:00
|
|
|
if (strncmp (data, "append", indx) == 0) {
|
|
|
|
*opcode = OP_APPEND;
|
2010-04-28 16:09:25 +00:00
|
|
|
*type = MEMCACHE_REQUEST;
|
2009-05-24 22:39:07 +00:00
|
|
|
*expect_content_length = TRUE;
|
|
|
|
is_request_or_response = TRUE;
|
|
|
|
} else if (strncmp (data, "delete", indx) == 0) {
|
|
|
|
*opcode = OP_DELETE;
|
2010-04-28 16:09:25 +00:00
|
|
|
*type = MEMCACHE_REQUEST;
|
2009-05-24 22:39:07 +00:00
|
|
|
is_request_or_response = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-04-28 16:09:25 +00:00
|
|
|
case 7:
|
2009-05-24 22:39:07 +00:00
|
|
|
if (strncmp (data, "replace", indx) == 0) {
|
|
|
|
*opcode = OP_REPLACE;
|
|
|
|
*type = MEMCACHE_REQUEST;
|
|
|
|
*expect_content_length = TRUE;
|
|
|
|
is_request_or_response = TRUE;
|
|
|
|
} else if (strncmp (data, "prepend", indx) == 0) {
|
|
|
|
*opcode = OP_PREPEND;
|
|
|
|
*type = MEMCACHE_REQUEST;
|
|
|
|
*expect_content_length = TRUE;
|
|
|
|
is_request_or_response = TRUE;
|
|
|
|
} else if (strncmp (data, "version", indx) == 0) {
|
|
|
|
*opcode = OP_VERSION;
|
|
|
|
*type = MEMCACHE_REQUEST;
|
|
|
|
is_request_or_response = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-04-28 16:09:25 +00:00
|
|
|
case 9:
|
2009-05-24 22:39:07 +00:00
|
|
|
if (strncmp (data, "flush_all", indx) == 0) {
|
|
|
|
*opcode = OP_FLUSH;
|
|
|
|
*type = MEMCACHE_REQUEST;
|
|
|
|
is_request_or_response = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-04-28 16:09:25 +00:00
|
|
|
default:
|
2009-05-24 22:39:07 +00:00
|
|
|
break; /* check if it is an 'incr' or 'stats sizes' response. */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_request_or_response && reqresp_dissector) {
|
|
|
|
*reqresp_dissector = memcache_request_dissector;
|
|
|
|
return is_request_or_response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX:
|
|
|
|
* Recognize 'incr', 'decr' and 'stats sizes' responses.
|
|
|
|
* I don't have a solution for this yet.
|
|
|
|
*/
|
|
|
|
return is_request_or_response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* dissect memcache textual protocol PDUs. */
|
|
|
|
static void
|
|
|
|
dissect_memcache_text (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|
|
|
{
|
|
|
|
int offset = 0;
|
2010-04-28 16:09:25 +00:00
|
|
|
int len;
|
2009-05-24 22:39:07 +00:00
|
|
|
|
2010-04-28 16:09:25 +00:00
|
|
|
while (tvb_reported_length_remaining (tvb, offset) != 0) {
|
2009-05-24 22:39:07 +00:00
|
|
|
|
|
|
|
/* dissect the memcache packet. */
|
|
|
|
len = dissect_memcache_message (tvb, offset, pinfo, tree);
|
|
|
|
if (len == -1)
|
|
|
|
break;
|
|
|
|
offset += len;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* OK, we've set the Protocol and Info columns for the
|
|
|
|
* first MEMCACHE message; set a fence so that subsequent
|
|
|
|
* MEMCACHE messages don't overwrite the Info column.
|
|
|
|
*/
|
|
|
|
col_set_fence (pinfo->cinfo, COL_INFO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Dissect tcp packets based on the type of protocol (text/binary) */
|
2013-11-09 17:46:28 +00:00
|
|
|
static int
|
|
|
|
dissect_memcache_tcp (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
|
2010-04-28 16:09:25 +00:00
|
|
|
{
|
2009-05-24 22:39:07 +00:00
|
|
|
gint offset = 0;
|
|
|
|
guint8 magic;
|
|
|
|
|
|
|
|
magic = tvb_get_guint8 (tvb, offset);
|
|
|
|
|
2013-03-29 00:26:23 +00:00
|
|
|
if (try_val_to_str (magic, magic_vals) != NULL) {
|
2009-05-24 22:39:07 +00:00
|
|
|
tcp_dissect_pdus (tvb, pinfo, tree, memcache_desegment_body, 12,
|
2013-11-09 17:46:28 +00:00
|
|
|
get_memcache_pdu_len, dissect_memcache, data);
|
2009-05-24 22:39:07 +00:00
|
|
|
} else {
|
|
|
|
dissect_memcache_text (tvb, pinfo, tree);
|
|
|
|
}
|
2013-11-09 17:46:28 +00:00
|
|
|
|
|
|
|
return tvb_length(tvb);
|
2009-03-03 21:57:43 +00:00
|
|
|
}
|
|
|
|
|
2009-05-24 22:39:07 +00:00
|
|
|
/* Dissect udp packets based on the type of protocol (text/binary) */
|
2013-11-09 17:46:28 +00:00
|
|
|
static int
|
|
|
|
dissect_memcache_udp (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
|
2009-03-03 21:57:43 +00:00
|
|
|
{
|
2009-05-24 22:39:07 +00:00
|
|
|
gint offset = 0;
|
|
|
|
guint8 magic;
|
|
|
|
|
|
|
|
magic = tvb_get_guint8 (tvb, offset);
|
|
|
|
|
2013-03-29 00:26:23 +00:00
|
|
|
if (try_val_to_str (magic, magic_vals) != NULL) {
|
2013-11-09 17:46:28 +00:00
|
|
|
dissect_memcache (tvb, pinfo, tree, data);
|
2009-05-24 22:39:07 +00:00
|
|
|
} else {
|
|
|
|
dissect_memcache_message (tvb, 0, pinfo, tree);
|
|
|
|
}
|
2013-11-09 17:46:28 +00:00
|
|
|
|
|
|
|
return tvb_length(tvb);
|
2009-03-03 21:57:43 +00:00
|
|
|
}
|
|
|
|
|
2010-04-28 16:09:25 +00:00
|
|
|
/* Registration functions; register memcache protocol,
|
2009-05-24 22:39:07 +00:00
|
|
|
* its configuration options and also register the tcp and udp
|
|
|
|
* dissectors.
|
|
|
|
*/
|
2010-04-28 16:09:25 +00:00
|
|
|
void
|
2009-03-03 21:57:43 +00:00
|
|
|
proto_register_memcache (void)
|
2010-04-28 16:09:25 +00:00
|
|
|
{
|
|
|
|
static hf_register_info hf[] = {
|
2009-03-03 21:57:43 +00:00
|
|
|
{ &hf_magic,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Magic", "memcache.magic",
|
|
|
|
FT_UINT8, BASE_DEC, VALS (magic_vals), 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
"Magic number", HFILL } },
|
|
|
|
|
2009-03-03 21:57:43 +00:00
|
|
|
{ &hf_opcode,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Opcode", "memcache.opcode",
|
|
|
|
FT_UINT8, BASE_DEC, VALS (opcode_vals), 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
"Command code", HFILL } },
|
|
|
|
|
2009-03-03 21:57:43 +00:00
|
|
|
{ &hf_extras_length,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Extras length", "memcache.extras.length",
|
|
|
|
FT_UINT8, BASE_DEC, NULL, 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
"Length in bytes of the command extras", HFILL } },
|
|
|
|
|
2009-03-03 21:57:43 +00:00
|
|
|
{ &hf_key_length,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Key Length", "memcache.key.length",
|
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
"Length in bytes of the text key that follows the command extras", HFILL } },
|
|
|
|
|
2009-03-03 21:57:43 +00:00
|
|
|
{ &hf_value_length,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Value length", "memcache.value.length",
|
|
|
|
FT_UINT32, BASE_DEC, NULL, 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
"Length in bytes of the value that follows the key", HFILL } },
|
|
|
|
|
2009-03-03 21:57:43 +00:00
|
|
|
{ &hf_data_type,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Data type", "memcache.data_type",
|
|
|
|
FT_UINT8, BASE_DEC, VALS (data_type_vals), 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
NULL, HFILL } },
|
|
|
|
|
2009-03-03 21:57:43 +00:00
|
|
|
{ &hf_reserved,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Reserved", "memcache.reserved",
|
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
"Reserved for future use", HFILL } },
|
|
|
|
|
2009-03-03 21:57:43 +00:00
|
|
|
{ &hf_status,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Status", "memcache.status",
|
|
|
|
FT_UINT16, BASE_DEC, VALS (status_vals), 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
"Status of the response", HFILL } },
|
|
|
|
|
2009-03-03 21:57:43 +00:00
|
|
|
{ &hf_total_body_length,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Total body length", "memcache.total_body_length",
|
|
|
|
FT_UINT32, BASE_DEC, NULL, 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
"Length in bytes of extra + key + value", HFILL } },
|
|
|
|
|
2009-03-03 21:57:43 +00:00
|
|
|
{ &hf_opaque,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Opaque", "memcache.opaque",
|
|
|
|
FT_UINT32, BASE_DEC, NULL, 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
NULL, HFILL } },
|
|
|
|
|
2009-03-03 21:57:43 +00:00
|
|
|
{ &hf_cas,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "CAS", "memcache.cas",
|
|
|
|
FT_UINT64, BASE_DEC, NULL, 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
"Data version check", HFILL } },
|
|
|
|
|
2009-03-03 21:57:43 +00:00
|
|
|
{ &hf_extras,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Extras", "memcache.extras",
|
|
|
|
FT_NONE, BASE_NONE, NULL, 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
NULL, HFILL } },
|
|
|
|
|
2009-03-03 21:57:43 +00:00
|
|
|
{ &hf_extras_flags,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Flags", "memcache.extras.flags",
|
|
|
|
FT_UINT32, BASE_HEX, NULL, 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
NULL, HFILL } },
|
|
|
|
|
2009-03-03 21:57:43 +00:00
|
|
|
{ &hf_extras_expiration,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Expiration", "memcache.extras.expiration",
|
|
|
|
FT_UINT32, BASE_DEC, NULL, 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
NULL, HFILL } },
|
|
|
|
|
2009-03-03 21:57:43 +00:00
|
|
|
{ &hf_extras_delta,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Amount to add", "memcache.extras.delta",
|
|
|
|
FT_UINT64, BASE_DEC, NULL, 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
NULL, HFILL } },
|
|
|
|
|
2009-03-03 21:57:43 +00:00
|
|
|
{ &hf_extras_initial,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Initial value", "memcache.extras.initial",
|
|
|
|
FT_UINT64, BASE_DEC, NULL, 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
NULL, HFILL } },
|
|
|
|
|
2009-03-03 21:57:43 +00:00
|
|
|
{ &hf_extras_unknown,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Unknown", "memcache.extras.unknown",
|
|
|
|
FT_BYTES, BASE_NONE, NULL, 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
"Unknown Extras", HFILL } },
|
|
|
|
|
2009-03-03 21:57:43 +00:00
|
|
|
{ &hf_key,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Key", "memcache.key",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
NULL, HFILL } },
|
|
|
|
|
2009-03-03 21:57:43 +00:00
|
|
|
{ &hf_value,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Value", "memcache.value",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
NULL, HFILL } },
|
|
|
|
|
2010-04-28 16:09:25 +00:00
|
|
|
{ &hf_uint64_response,
|
|
|
|
{ "Response", "memcache.extras.response",
|
|
|
|
FT_UINT64, BASE_DEC, NULL, 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
NULL, HFILL } },
|
|
|
|
|
|
|
|
{ &hf_command,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Command", "memcache.command",
|
|
|
|
FT_STRING, BASE_NONE , NULL, 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
NULL, HFILL } },
|
|
|
|
|
|
|
|
{ &hf_subcommand,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Sub command", "memcache.subcommand",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
"Sub command if any", HFILL } },
|
|
|
|
|
|
|
|
{ &hf_flags,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Flags", "memcache.flags",
|
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
NULL, HFILL } },
|
|
|
|
|
|
|
|
{ &hf_expiration,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Expiration", "memcache.expiration",
|
|
|
|
FT_UINT32, BASE_DEC, NULL, 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
NULL, HFILL } },
|
|
|
|
|
|
|
|
{ &hf_noreply,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Noreply", "memcache.noreply",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
"Client does not expect a reply", HFILL } },
|
|
|
|
|
|
|
|
{ &hf_response,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Response", "memcache.response",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
"Response command", HFILL } },
|
|
|
|
|
|
|
|
{ &hf_version,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Version", "memcache.version",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
"Version of running memcache", HFILL } },
|
|
|
|
|
|
|
|
{ &hf_slabclass,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Slab class", "memcache.slabclass",
|
|
|
|
FT_UINT32, BASE_DEC, NULL, 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
"Slab class of a stat", HFILL } },
|
|
|
|
|
|
|
|
{ &hf_name,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Stat name", "memcache.name",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
"Name of a stat", HFILL } },
|
|
|
|
|
|
|
|
{ &hf_name_value,
|
2010-04-28 16:09:25 +00:00
|
|
|
{ "Stat value", "memcache.name_value",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x0,
|
2009-05-24 22:39:07 +00:00
|
|
|
"Value of a stat", HFILL } },
|
2009-03-03 21:57:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_memcache,
|
|
|
|
&ett_extras
|
|
|
|
};
|
|
|
|
|
2013-08-23 03:17:34 +00:00
|
|
|
static ei_register_info ei[] = {
|
2013-08-29 02:17:00 +00:00
|
|
|
{ &ei_extras_unknown, { "memcache.extras.notexpected", PI_UNDECODED, PI_WARN, "shall not have Extras", EXPFILL }},
|
|
|
|
{ &ei_extras_missing, { "memcache.extras.missing", PI_UNDECODED, PI_WARN, "must have Extras", EXPFILL }},
|
|
|
|
{ &ei_key_unknown, { "memcache.key.notexpected", PI_UNDECODED, PI_WARN, "shall not have Key", EXPFILL }},
|
|
|
|
{ &ei_key_missing, { "memcache.key.missing", PI_UNDECODED, PI_WARN, "must have Key", EXPFILL }},
|
|
|
|
{ &ei_value_length, { "memcache.value.invalid", PI_UNDECODED, PI_WARN, "Illegal Value length, should be 8", EXPFILL }},
|
|
|
|
{ &ei_value_unknown, { "memcache.value.notexpected", PI_UNDECODED, PI_WARN, "shall not have Value", EXPFILL }},
|
|
|
|
{ &ei_value_missing, { "memcache.value.missing", PI_UNDECODED, PI_WARN, "must have Value", EXPFILL }},
|
|
|
|
{ &ei_magic_unknown, { "memcache.magic.unknown", PI_UNDECODED, PI_WARN, "Unknown magic byte", EXPFILL }},
|
|
|
|
{ &ei_opcode_unknown, { "memcache.opcode.unknown", PI_UNDECODED, PI_WARN, "Unknown opcode", EXPFILL }},
|
2013-08-23 03:17:34 +00:00
|
|
|
{ &ei_status_response, { "memcache.status.response", PI_RESPONSE_CODE, PI_NOTE, "Error response", EXPFILL }},
|
2013-08-29 02:17:00 +00:00
|
|
|
{ &ei_reserved_value, { "memcache.reserved.expert", PI_UNDECODED, PI_WARN, "Reserved value", EXPFILL }},
|
2013-08-23 03:17:34 +00:00
|
|
|
};
|
|
|
|
|
2013-08-29 02:17:00 +00:00
|
|
|
module_t *memcache_module;
|
|
|
|
expert_module_t *expert_memcache;
|
2009-03-03 21:57:43 +00:00
|
|
|
|
|
|
|
proto_memcache = proto_register_protocol (PNAME, PSNAME, PFNAME);
|
2013-11-09 17:46:28 +00:00
|
|
|
memcache_tcp_handle = new_register_dissector ("memcache.tcp", dissect_memcache_tcp, proto_memcache);
|
|
|
|
memcache_udp_handle = new_register_dissector ("memcache.udp", dissect_memcache_udp, proto_memcache);
|
2010-04-28 16:09:25 +00:00
|
|
|
|
2009-03-03 21:57:43 +00:00
|
|
|
proto_register_field_array (proto_memcache, hf, array_length (hf));
|
|
|
|
proto_register_subtree_array (ett, array_length (ett));
|
2013-08-23 03:17:34 +00:00
|
|
|
expert_memcache = expert_register_protocol(proto_memcache);
|
|
|
|
expert_register_field_array(expert_memcache, ei, array_length(ei));
|
2009-03-03 21:57:43 +00:00
|
|
|
|
|
|
|
/* Register our configuration options */
|
2013-03-04 17:48:56 +00:00
|
|
|
memcache_module = prefs_register_protocol (proto_memcache, proto_reg_handoff_memcache);
|
2009-03-03 21:57:43 +00:00
|
|
|
|
2010-04-28 16:09:25 +00:00
|
|
|
prefs_register_bool_preference (memcache_module, "desegment_headers",
|
2009-05-24 22:39:07 +00:00
|
|
|
"Reassemble MEMCACHE headers spanning multiple TCP segments",
|
|
|
|
"Whether the MEMCACHE dissector should reassemble headers "
|
|
|
|
"of a request spanning multiple TCP segments. "
|
|
|
|
"To use this option, you must also enable "
|
2010-04-28 16:09:25 +00:00
|
|
|
"\"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
|
2009-05-24 22:39:07 +00:00
|
|
|
&memcache_desegment_headers);
|
|
|
|
|
2010-04-28 16:09:25 +00:00
|
|
|
prefs_register_bool_preference (memcache_module, "desegment_pdus",
|
2009-03-03 21:57:43 +00:00
|
|
|
"Reassemble PDUs spanning multiple TCP segments",
|
|
|
|
"Whether the memcache dissector should reassemble PDUs"
|
|
|
|
" spanning multiple TCP segments."
|
|
|
|
" To use this option, you must also enable \"Allow subdissectors"
|
|
|
|
" to reassemble TCP streams\" in the TCP protocol settings.",
|
2009-05-24 22:39:07 +00:00
|
|
|
&memcache_desegment_body);
|
2013-03-04 17:48:56 +00:00
|
|
|
|
|
|
|
range_convert_str(&memcache_tcp_port_range, MEMCACHE_DEFAULT_RANGE, 65535);
|
|
|
|
range_convert_str(&memcache_udp_port_range, MEMCACHE_DEFAULT_RANGE, 65535);
|
|
|
|
|
|
|
|
prefs_register_range_preference(memcache_module, "tcp.ports", \
|
|
|
|
"MEMCACHE TCP Port range", \
|
|
|
|
"MEMCACHE TCP Port range", \
|
|
|
|
&memcache_tcp_port_range, \
|
|
|
|
65535);
|
|
|
|
prefs_register_range_preference(memcache_module, "udp.ports", \
|
|
|
|
"MEMCACHE UDP Port range", \
|
|
|
|
"MEMCACHE UDP Port range", \
|
|
|
|
&memcache_udp_port_range, \
|
|
|
|
65535);
|
|
|
|
}
|
|
|
|
|
2009-05-24 22:39:07 +00:00
|
|
|
/* Register the tcp and udp memcache dissectors. */
|
2010-04-28 16:09:25 +00:00
|
|
|
void
|
2009-03-03 21:57:43 +00:00
|
|
|
proto_reg_handoff_memcache (void)
|
|
|
|
{
|
2013-08-29 02:17:00 +00:00
|
|
|
static range_t *orig_memcache_tcp_port_range = NULL;
|
|
|
|
static range_t *orig_memcache_udp_port_range = NULL;
|
|
|
|
|
|
|
|
dissector_delete_uint_range("tcp.port", orig_memcache_tcp_port_range, memcache_tcp_handle);
|
|
|
|
dissector_delete_uint_range("udp.port", orig_memcache_udp_port_range, memcache_udp_handle);
|
|
|
|
g_free(orig_memcache_tcp_port_range);
|
|
|
|
g_free(orig_memcache_udp_port_range);
|
2009-03-03 21:57:43 +00:00
|
|
|
|
2013-03-04 17:48:56 +00:00
|
|
|
orig_memcache_tcp_port_range = range_copy(memcache_tcp_port_range);
|
|
|
|
orig_memcache_udp_port_range = range_copy(memcache_udp_port_range);
|
2013-08-27 19:21:20 +00:00
|
|
|
dissector_add_uint_range("tcp.port", orig_memcache_tcp_port_range, memcache_tcp_handle);
|
|
|
|
dissector_add_uint_range("udp.port", orig_memcache_udp_port_range, memcache_udp_handle);
|
2009-03-03 21:57:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* c-basic-offset: 2
|
2010-04-28 16:09:25 +00:00
|
|
|
* tab-width: 8
|
2009-03-03 21:57:43 +00:00
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
2011-09-21 17:49:11 +00:00
|
|
|
* ex: set shiftwidth=2 tabstop=8 expandtab:
|
2010-04-28 16:09:25 +00:00
|
|
|
* :indentSize=2:tabSize=8:noTabs=true:
|
2009-03-03 21:57:43 +00:00
|
|
|
*/
|