2002-06-21 00:43:23 +00:00
|
|
|
/*
|
|
|
|
* Decode and print Zephyr packets.
|
|
|
|
*
|
2005-07-11 03:54:22 +00:00
|
|
|
* http://web.mit.edu/zephyr/doc/protocol
|
|
|
|
*
|
2002-06-21 00:43:23 +00:00
|
|
|
* Copyright (c) 2001 Nickolai Zeldovich <kolya@MIT.EDU>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that: (1) source code
|
|
|
|
* distributions retain the above copyright notice and this paragraph
|
|
|
|
* in its entirety, and (2) distributions including binary code include
|
|
|
|
* the above copyright notice and this paragraph in its entirety in
|
|
|
|
* the documentation or other materials provided with the distribution.
|
|
|
|
* The name of the author(s) may not be used to endorse or promote
|
|
|
|
* products derived from this software without specific prior written
|
|
|
|
* permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE.
|
|
|
|
*/
|
|
|
|
|
2017-01-31 19:17:06 +00:00
|
|
|
/* \summary: Zephyr printer */
|
|
|
|
|
2002-06-21 00:43:23 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2017-01-31 19:17:06 +00:00
|
|
|
#include <netdissect-stdinc.h>
|
2004-03-31 09:17:26 +00:00
|
|
|
|
2002-06-21 00:43:23 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2017-01-31 19:17:06 +00:00
|
|
|
#include "netdissect.h"
|
2002-06-21 00:43:23 +00:00
|
|
|
|
|
|
|
struct z_packet {
|
2017-01-31 19:17:06 +00:00
|
|
|
const char *version;
|
2002-06-21 00:43:23 +00:00
|
|
|
int numfields;
|
|
|
|
int kind;
|
2017-01-31 19:17:06 +00:00
|
|
|
const char *uid;
|
2002-06-21 00:43:23 +00:00
|
|
|
int port;
|
|
|
|
int auth;
|
|
|
|
int authlen;
|
2017-01-31 19:17:06 +00:00
|
|
|
const char *authdata;
|
|
|
|
const char *class;
|
|
|
|
const char *inst;
|
|
|
|
const char *opcode;
|
|
|
|
const char *sender;
|
2004-03-31 09:17:26 +00:00
|
|
|
const char *recipient;
|
2017-01-31 19:17:06 +00:00
|
|
|
const char *format;
|
2002-06-21 00:43:23 +00:00
|
|
|
int cksum;
|
|
|
|
int multi;
|
2017-01-31 19:17:06 +00:00
|
|
|
const char *multi_uid;
|
2002-06-21 00:43:23 +00:00
|
|
|
/* Other fields follow here.. */
|
|
|
|
};
|
|
|
|
|
2003-03-02 08:22:26 +00:00
|
|
|
enum z_packet_type {
|
2002-06-21 00:43:23 +00:00
|
|
|
Z_PACKET_UNSAFE = 0,
|
|
|
|
Z_PACKET_UNACKED,
|
|
|
|
Z_PACKET_ACKED,
|
|
|
|
Z_PACKET_HMACK,
|
|
|
|
Z_PACKET_HMCTL,
|
|
|
|
Z_PACKET_SERVACK,
|
|
|
|
Z_PACKET_SERVNAK,
|
|
|
|
Z_PACKET_CLIENTACK,
|
|
|
|
Z_PACKET_STAT
|
2003-03-02 08:22:26 +00:00
|
|
|
};
|
2002-06-21 00:43:23 +00:00
|
|
|
|
2015-01-06 19:03:11 +00:00
|
|
|
static const struct tok z_types[] = {
|
2002-06-21 00:43:23 +00:00
|
|
|
{ Z_PACKET_UNSAFE, "unsafe" },
|
|
|
|
{ Z_PACKET_UNACKED, "unacked" },
|
|
|
|
{ Z_PACKET_ACKED, "acked" },
|
|
|
|
{ Z_PACKET_HMACK, "hm-ack" },
|
|
|
|
{ Z_PACKET_HMCTL, "hm-ctl" },
|
|
|
|
{ Z_PACKET_SERVACK, "serv-ack" },
|
|
|
|
{ Z_PACKET_SERVNAK, "serv-nak" },
|
|
|
|
{ Z_PACKET_CLIENTACK, "client-ack" },
|
|
|
|
{ Z_PACKET_STAT, "stat" }
|
|
|
|
};
|
|
|
|
|
2015-01-06 19:03:11 +00:00
|
|
|
static char z_buf[256];
|
2002-06-21 00:43:23 +00:00
|
|
|
|
2017-01-31 19:17:06 +00:00
|
|
|
static const char *
|
|
|
|
parse_field(netdissect_options *ndo, const char **pptr, int *len)
|
2002-06-21 00:43:23 +00:00
|
|
|
{
|
2017-01-31 19:17:06 +00:00
|
|
|
const char *s;
|
2002-06-21 00:43:23 +00:00
|
|
|
|
|
|
|
if (*len <= 0 || !pptr || !*pptr)
|
|
|
|
return NULL;
|
2017-01-31 19:17:06 +00:00
|
|
|
if (*pptr > (const char *) ndo->ndo_snapend)
|
2002-06-21 00:43:23 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
s = *pptr;
|
2017-01-31 19:17:06 +00:00
|
|
|
while (*pptr <= (const char *) ndo->ndo_snapend && *len >= 0 && **pptr) {
|
2002-06-21 00:43:23 +00:00
|
|
|
(*pptr)++;
|
|
|
|
(*len)--;
|
|
|
|
}
|
|
|
|
(*pptr)++;
|
|
|
|
(*len)--;
|
2017-01-31 19:17:06 +00:00
|
|
|
if (*len < 0 || *pptr > (const char *) ndo->ndo_snapend)
|
2002-06-21 00:43:23 +00:00
|
|
|
return NULL;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
2017-01-31 19:17:06 +00:00
|
|
|
z_triple(const char *class, const char *inst, const char *recipient)
|
2002-06-21 00:43:23 +00:00
|
|
|
{
|
|
|
|
if (!*recipient)
|
|
|
|
recipient = "*";
|
|
|
|
snprintf(z_buf, sizeof(z_buf), "<%s,%s,%s>", class, inst, recipient);
|
|
|
|
z_buf[sizeof(z_buf)-1] = '\0';
|
|
|
|
return z_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
2017-01-31 19:17:06 +00:00
|
|
|
str_to_lower(const char *string)
|
2002-06-21 00:43:23 +00:00
|
|
|
{
|
2017-01-31 19:17:06 +00:00
|
|
|
char *zb_string;
|
|
|
|
|
2002-06-21 00:43:23 +00:00
|
|
|
strncpy(z_buf, string, sizeof(z_buf));
|
|
|
|
z_buf[sizeof(z_buf)-1] = '\0';
|
|
|
|
|
2017-01-31 19:17:06 +00:00
|
|
|
zb_string = z_buf;
|
|
|
|
while (*zb_string) {
|
|
|
|
*zb_string = tolower((unsigned char)(*zb_string));
|
|
|
|
zb_string++;
|
2002-06-21 00:43:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return z_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-01-06 19:03:11 +00:00
|
|
|
zephyr_print(netdissect_options *ndo, const u_char *cp, int length)
|
2002-06-21 00:43:23 +00:00
|
|
|
{
|
|
|
|
struct z_packet z;
|
2017-01-31 19:17:06 +00:00
|
|
|
const char *parse = (const char *) cp;
|
2002-06-21 00:43:23 +00:00
|
|
|
int parselen = length;
|
2017-01-31 19:17:06 +00:00
|
|
|
const char *s;
|
2002-06-21 00:43:23 +00:00
|
|
|
int lose = 0;
|
|
|
|
|
2009-03-21 16:23:46 +00:00
|
|
|
/* squelch compiler warnings */
|
|
|
|
|
|
|
|
z.kind = 0;
|
|
|
|
z.class = 0;
|
|
|
|
z.inst = 0;
|
|
|
|
z.opcode = 0;
|
|
|
|
z.sender = 0;
|
|
|
|
z.recipient = 0;
|
|
|
|
|
2002-06-21 00:43:23 +00:00
|
|
|
#define PARSE_STRING \
|
2015-01-06 19:03:11 +00:00
|
|
|
s = parse_field(ndo, &parse, &parselen); \
|
2002-06-21 00:43:23 +00:00
|
|
|
if (!s) lose = 1;
|
|
|
|
|
|
|
|
#define PARSE_FIELD_INT(field) \
|
|
|
|
PARSE_STRING \
|
|
|
|
if (!lose) field = strtol(s, 0, 16);
|
|
|
|
|
|
|
|
#define PARSE_FIELD_STR(field) \
|
|
|
|
PARSE_STRING \
|
|
|
|
if (!lose) field = s;
|
|
|
|
|
|
|
|
PARSE_FIELD_STR(z.version);
|
|
|
|
if (lose) return;
|
|
|
|
if (strncmp(z.version, "ZEPH", 4))
|
|
|
|
return;
|
|
|
|
|
|
|
|
PARSE_FIELD_INT(z.numfields);
|
|
|
|
PARSE_FIELD_INT(z.kind);
|
|
|
|
PARSE_FIELD_STR(z.uid);
|
|
|
|
PARSE_FIELD_INT(z.port);
|
|
|
|
PARSE_FIELD_INT(z.auth);
|
|
|
|
PARSE_FIELD_INT(z.authlen);
|
|
|
|
PARSE_FIELD_STR(z.authdata);
|
|
|
|
PARSE_FIELD_STR(z.class);
|
|
|
|
PARSE_FIELD_STR(z.inst);
|
|
|
|
PARSE_FIELD_STR(z.opcode);
|
|
|
|
PARSE_FIELD_STR(z.sender);
|
|
|
|
PARSE_FIELD_STR(z.recipient);
|
|
|
|
PARSE_FIELD_STR(z.format);
|
|
|
|
PARSE_FIELD_INT(z.cksum);
|
|
|
|
PARSE_FIELD_INT(z.multi);
|
|
|
|
PARSE_FIELD_STR(z.multi_uid);
|
|
|
|
|
|
|
|
if (lose) {
|
2015-01-06 19:03:11 +00:00
|
|
|
ND_PRINT((ndo, " [|zephyr] (%d)", length));
|
2002-06-21 00:43:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-06 19:03:11 +00:00
|
|
|
ND_PRINT((ndo, " zephyr"));
|
2002-06-21 00:43:23 +00:00
|
|
|
if (strncmp(z.version+4, "0.2", 3)) {
|
2015-01-06 19:03:11 +00:00
|
|
|
ND_PRINT((ndo, " v%s", z.version+4));
|
2002-06-21 00:43:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-06 19:03:11 +00:00
|
|
|
ND_PRINT((ndo, " %s", tok2str(z_types, "type %d", z.kind)));
|
2002-06-21 00:43:23 +00:00
|
|
|
if (z.kind == Z_PACKET_SERVACK) {
|
|
|
|
/* Initialization to silence warnings */
|
2017-01-31 19:17:06 +00:00
|
|
|
const char *ackdata = NULL;
|
2002-06-21 00:43:23 +00:00
|
|
|
PARSE_FIELD_STR(ackdata);
|
|
|
|
if (!lose && strcmp(ackdata, "SENT"))
|
2015-01-06 19:03:11 +00:00
|
|
|
ND_PRINT((ndo, "/%s", str_to_lower(ackdata)));
|
2002-06-21 00:43:23 +00:00
|
|
|
}
|
2015-01-06 19:03:11 +00:00
|
|
|
if (*z.sender) ND_PRINT((ndo, " %s", z.sender));
|
2002-06-21 00:43:23 +00:00
|
|
|
|
|
|
|
if (!strcmp(z.class, "USER_LOCATE")) {
|
|
|
|
if (!strcmp(z.opcode, "USER_HIDE"))
|
2015-01-06 19:03:11 +00:00
|
|
|
ND_PRINT((ndo, " hide"));
|
2002-06-21 00:43:23 +00:00
|
|
|
else if (!strcmp(z.opcode, "USER_UNHIDE"))
|
2015-01-06 19:03:11 +00:00
|
|
|
ND_PRINT((ndo, " unhide"));
|
2002-06-21 00:43:23 +00:00
|
|
|
else
|
2015-01-06 19:03:11 +00:00
|
|
|
ND_PRINT((ndo, " locate %s", z.inst));
|
2002-06-21 00:43:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(z.class, "ZEPHYR_ADMIN")) {
|
2015-01-06 19:03:11 +00:00
|
|
|
ND_PRINT((ndo, " zephyr-admin %s", str_to_lower(z.opcode)));
|
2002-06-21 00:43:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(z.class, "ZEPHYR_CTL")) {
|
|
|
|
if (!strcmp(z.inst, "CLIENT")) {
|
|
|
|
if (!strcmp(z.opcode, "SUBSCRIBE") ||
|
|
|
|
!strcmp(z.opcode, "SUBSCRIBE_NODEFS") ||
|
|
|
|
!strcmp(z.opcode, "UNSUBSCRIBE")) {
|
|
|
|
|
2015-01-06 19:03:11 +00:00
|
|
|
ND_PRINT((ndo, " %ssub%s", strcmp(z.opcode, "SUBSCRIBE") ? "un" : "",
|
2002-06-21 00:43:23 +00:00
|
|
|
strcmp(z.opcode, "SUBSCRIBE_NODEFS") ? "" :
|
2015-01-06 19:03:11 +00:00
|
|
|
"-nodefs"));
|
2002-06-21 00:43:23 +00:00
|
|
|
if (z.kind != Z_PACKET_SERVACK) {
|
|
|
|
/* Initialization to silence warnings */
|
2017-01-31 19:17:06 +00:00
|
|
|
const char *c = NULL, *i = NULL, *r = NULL;
|
2002-06-21 00:43:23 +00:00
|
|
|
PARSE_FIELD_STR(c);
|
|
|
|
PARSE_FIELD_STR(i);
|
|
|
|
PARSE_FIELD_STR(r);
|
2015-01-06 19:03:11 +00:00
|
|
|
if (!lose) ND_PRINT((ndo, " %s", z_triple(c, i, r)));
|
2002-06-21 00:43:23 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(z.opcode, "GIMME")) {
|
2015-01-06 19:03:11 +00:00
|
|
|
ND_PRINT((ndo, " ret"));
|
2002-06-21 00:43:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(z.opcode, "GIMMEDEFS")) {
|
2015-01-06 19:03:11 +00:00
|
|
|
ND_PRINT((ndo, " gimme-defs"));
|
2002-06-21 00:43:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(z.opcode, "CLEARSUB")) {
|
2015-01-06 19:03:11 +00:00
|
|
|
ND_PRINT((ndo, " clear-subs"));
|
2002-06-21 00:43:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-06 19:03:11 +00:00
|
|
|
ND_PRINT((ndo, " %s", str_to_lower(z.opcode)));
|
2002-06-21 00:43:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(z.inst, "HM")) {
|
2015-01-06 19:03:11 +00:00
|
|
|
ND_PRINT((ndo, " %s", str_to_lower(z.opcode)));
|
2002-06-21 00:43:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(z.inst, "REALM")) {
|
|
|
|
if (!strcmp(z.opcode, "ADD_SUBSCRIBE"))
|
2015-01-06 19:03:11 +00:00
|
|
|
ND_PRINT((ndo, " realm add-subs"));
|
2002-06-21 00:43:23 +00:00
|
|
|
if (!strcmp(z.opcode, "REQ_SUBSCRIBE"))
|
2015-01-06 19:03:11 +00:00
|
|
|
ND_PRINT((ndo, " realm req-subs"));
|
2002-06-21 00:43:23 +00:00
|
|
|
if (!strcmp(z.opcode, "RLM_SUBSCRIBE"))
|
2015-01-06 19:03:11 +00:00
|
|
|
ND_PRINT((ndo, " realm rlm-sub"));
|
2002-06-21 00:43:23 +00:00
|
|
|
if (!strcmp(z.opcode, "RLM_UNSUBSCRIBE"))
|
2015-01-06 19:03:11 +00:00
|
|
|
ND_PRINT((ndo, " realm rlm-unsub"));
|
2002-06-21 00:43:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(z.class, "HM_CTL")) {
|
2015-01-06 19:03:11 +00:00
|
|
|
ND_PRINT((ndo, " hm_ctl %s", str_to_lower(z.inst)));
|
|
|
|
ND_PRINT((ndo, " %s", str_to_lower(z.opcode)));
|
2002-06-21 00:43:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(z.class, "HM_STAT")) {
|
|
|
|
if (!strcmp(z.inst, "HMST_CLIENT") && !strcmp(z.opcode, "GIMMESTATS")) {
|
2015-01-06 19:03:11 +00:00
|
|
|
ND_PRINT((ndo, " get-client-stats"));
|
2002-06-21 00:43:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(z.class, "WG_CTL")) {
|
2015-01-06 19:03:11 +00:00
|
|
|
ND_PRINT((ndo, " wg_ctl %s", str_to_lower(z.inst)));
|
|
|
|
ND_PRINT((ndo, " %s", str_to_lower(z.opcode)));
|
2002-06-21 00:43:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(z.class, "LOGIN")) {
|
|
|
|
if (!strcmp(z.opcode, "USER_FLUSH")) {
|
2015-01-06 19:03:11 +00:00
|
|
|
ND_PRINT((ndo, " flush_locs"));
|
2002-06-21 00:43:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(z.opcode, "NONE") ||
|
|
|
|
!strcmp(z.opcode, "OPSTAFF") ||
|
|
|
|
!strcmp(z.opcode, "REALM-VISIBLE") ||
|
|
|
|
!strcmp(z.opcode, "REALM-ANNOUNCED") ||
|
|
|
|
!strcmp(z.opcode, "NET-VISIBLE") ||
|
|
|
|
!strcmp(z.opcode, "NET-ANNOUNCED")) {
|
2015-01-06 19:03:11 +00:00
|
|
|
ND_PRINT((ndo, " set-exposure %s", str_to_lower(z.opcode)));
|
2002-06-21 00:43:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!*z.recipient)
|
|
|
|
z.recipient = "*";
|
|
|
|
|
2015-01-06 19:03:11 +00:00
|
|
|
ND_PRINT((ndo, " to %s", z_triple(z.class, z.inst, z.recipient)));
|
2002-06-21 00:43:23 +00:00
|
|
|
if (*z.opcode)
|
2015-01-06 19:03:11 +00:00
|
|
|
ND_PRINT((ndo, " op %s", z.opcode));
|
2002-06-21 00:43:23 +00:00
|
|
|
}
|