]> The Tcpdump Group git mirrors - tcpdump/blob - print-wb.c
Update the "Error converting time" tests for packet times
[tcpdump] / print-wb.c
1 /*
2 * Copyright (c) 1993, 1994, 1995, 1996
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 */
21
22 /* \summary: White Board printer */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include "netdissect-stdinc.h"
29
30 #define ND_LONGJMP_FROM_TCHECK
31 #include "netdissect.h"
32 #include "addrtoname.h"
33 #include "extract.h"
34
35
36 #if 0
37 /*
38 * Largest packet size. Everything should fit within this space.
39 * For instance, multiline objects are sent piecewise.
40 */
41 #define MAXFRAMESIZE 1024
42 #endif
43
44 /*
45 * Multiple drawing ops can be sent in one packet. Each one starts on a
46 * an even multiple of DOP_ALIGN bytes, which must be a power of two.
47 */
48 #define DOP_ALIGN 4
49 #define DOP_ROUNDUP(x) roundup2(x, DOP_ALIGN)
50 #define DOP_NEXT(d)\
51 ((const struct dophdr *)((const u_char *)(d) + \
52 DOP_ROUNDUP(GET_BE_U_2((d)->dh_len) + sizeof(*(d)))))
53
54 /*
55 * Format of the whiteboard packet header.
56 * The transport level header.
57 */
58 struct pkt_hdr {
59 nd_uint32_t ph_src; /* site id of source */
60 nd_uint32_t ph_ts; /* time stamp (for skew computation) */
61 nd_uint16_t ph_version; /* version number */
62 nd_uint8_t ph_type; /* message type */
63 nd_uint8_t ph_flags; /* message flags */
64 };
65
66 /* Packet types */
67 #define PT_DRAWOP 0 /* drawing operation */
68 #define PT_ID 1 /* announcement packet */
69 #define PT_RREQ 2 /* repair request */
70 #define PT_RREP 3 /* repair reply */
71 #define PT_KILL 4 /* terminate participation */
72 #define PT_PREQ 5 /* page vector request */
73 #define PT_PREP 7 /* page vector reply */
74
75 #if 0
76 /* flags */
77 #define PF_USER 0x01 /* hint that packet has interactive data */
78 #define PF_VIS 0x02 /* only visible ops wanted */
79 #endif
80
81 struct PageID {
82 nd_uint32_t p_sid; /* session id of initiator */
83 nd_uint32_t p_uid; /* page number */
84 };
85
86 struct dophdr {
87 nd_uint32_t dh_ts; /* sender's timestamp */
88 nd_uint16_t dh_len; /* body length */
89 nd_uint8_t dh_flags;
90 nd_uint8_t dh_type; /* body type */
91 /* body follows */
92 };
93 /*
94 * Drawing op sub-types.
95 */
96 #define DT_RECT 2
97 #define DT_LINE 3
98 #define DT_ML 4
99 #define DT_DEL 5
100 #define DT_XFORM 6
101 #define DT_ELL 7
102 #define DT_CHAR 8
103 #define DT_STR 9
104 #define DT_NOP 10
105 #define DT_PSCODE 11
106 #define DT_PSCOMP 12
107 #define DT_REF 13
108 #define DT_SKIP 14
109 #define DT_HOLE 15
110 static const struct tok dop_str[] = {
111 { DT_RECT, "RECT" },
112 { DT_LINE, "LINE" },
113 { DT_ML, "ML" },
114 { DT_DEL, "DEL" },
115 { DT_XFORM, "XFORM" },
116 { DT_ELL, "ELL" },
117 { DT_CHAR, "CHAR" },
118 { DT_STR, "STR" },
119 { DT_NOP, "NOP" },
120 { DT_PSCODE, "PSCODE" },
121 { DT_PSCOMP, "PSCOMP" },
122 { DT_REF, "REF" },
123 { DT_SKIP, "SKIP" },
124 { DT_HOLE, "HOLE" },
125 { 0, NULL }
126 };
127
128 /*
129 * A drawing operation.
130 */
131 struct pkt_dop {
132 struct PageID pd_page; /* page that operations apply to */
133 nd_uint32_t pd_sseq; /* start sequence number */
134 nd_uint32_t pd_eseq; /* end sequence number */
135 /* drawing ops follow */
136 };
137
138 /*
139 * A repair request.
140 */
141 struct pkt_rreq {
142 nd_uint32_t pr_id; /* source id of drawops to be repaired */
143 struct PageID pr_page; /* page of drawops */
144 nd_uint32_t pr_sseq; /* start seqno */
145 nd_uint32_t pr_eseq; /* end seqno */
146 };
147
148 /*
149 * A repair reply.
150 */
151 struct pkt_rrep {
152 nd_uint32_t pr_id; /* original site id of ops */
153 struct pkt_dop pr_dop;
154 /* drawing ops follow */
155 };
156
157 struct id_off {
158 nd_uint32_t id;
159 nd_uint32_t off;
160 };
161
162 struct pgstate {
163 nd_uint32_t slot;
164 struct PageID page;
165 nd_uint16_t nid;
166 nd_uint16_t rsvd;
167 /* seqptr's */
168 };
169
170 /*
171 * An announcement packet.
172 */
173 struct pkt_id {
174 nd_uint32_t pi_mslot;
175 struct PageID pi_mpage; /* current page */
176 struct pgstate pi_ps;
177 /* seqptr's */
178 /* null-terminated site name */
179 };
180
181 struct pkt_preq {
182 struct PageID pp_page;
183 nd_uint32_t pp_low;
184 nd_uint32_t pp_high;
185 };
186
187 struct pkt_prep {
188 nd_uint32_t pp_n; /* size of pageid array */
189 /* pgstate's follow */
190 };
191
192 static int
193 wb_id(netdissect_options *ndo,
194 const struct pkt_id *id, u_int len)
195 {
196 u_int i;
197 const u_char *sitename;
198 const struct id_off *io;
199 char c;
200 u_int nid;
201
202 ND_PRINT(" wb-id:");
203 if (len < sizeof(*id))
204 return (-1);
205 len -= sizeof(*id);
206
207 ND_PRINT(" %u/%s:%u (max %u/%s:%u) ",
208 GET_BE_U_4(id->pi_ps.slot),
209 GET_IPADDR_STRING(id->pi_ps.page.p_sid),
210 GET_BE_U_4(id->pi_ps.page.p_uid),
211 GET_BE_U_4(id->pi_mslot),
212 GET_IPADDR_STRING(id->pi_mpage.p_sid),
213 GET_BE_U_4(id->pi_mpage.p_uid));
214 /* now the rest of the fixed-size part of struct pkt_id */
215 ND_TCHECK_SIZE(id);
216
217 nid = GET_BE_U_2(id->pi_ps.nid);
218 if (len < sizeof(*io) * nid)
219 return (-1);
220 len -= sizeof(*io) * nid;
221 io = (const struct id_off *)(id + 1);
222 sitename = (const u_char *)(io + nid);
223
224 c = '<';
225 for (i = 0; i < nid; ++io, ++i) {
226 ND_PRINT("%c%s:%u",
227 c, GET_IPADDR_STRING(io->id), GET_BE_U_4(io->off));
228 c = ',';
229 }
230 ND_PRINT("> \"");
231 nd_printjnp(ndo, sitename, len);
232 ND_PRINT("\"");
233 return (0);
234 }
235
236 static int
237 wb_rreq(netdissect_options *ndo,
238 const struct pkt_rreq *rreq, u_int len)
239 {
240 ND_PRINT(" wb-rreq:");
241 if (len < sizeof(*rreq))
242 return (-1);
243
244 ND_PRINT(" please repair %s %s:%u<%u:%u>",
245 GET_IPADDR_STRING(rreq->pr_id),
246 GET_IPADDR_STRING(rreq->pr_page.p_sid),
247 GET_BE_U_4(rreq->pr_page.p_uid),
248 GET_BE_U_4(rreq->pr_sseq),
249 GET_BE_U_4(rreq->pr_eseq));
250 return (0);
251 }
252
253 static int
254 wb_preq(netdissect_options *ndo,
255 const struct pkt_preq *preq, u_int len)
256 {
257 ND_PRINT(" wb-preq:");
258 if (len < sizeof(*preq))
259 return (-1);
260
261 ND_PRINT(" need %u/%s:%u",
262 GET_BE_U_4(preq->pp_low),
263 GET_IPADDR_STRING(preq->pp_page.p_sid),
264 GET_BE_U_4(preq->pp_page.p_uid));
265 /* now the rest of the fixed-size part of struct pkt_req */
266 ND_TCHECK_SIZE(preq);
267 return (0);
268 }
269
270 static int
271 wb_prep(netdissect_options *ndo,
272 const struct pkt_prep *prep, u_int len)
273 {
274 u_int n;
275 const struct pgstate *ps;
276
277 ND_PRINT(" wb-prep:");
278 if (len < sizeof(*prep))
279 return (-1);
280 n = GET_BE_U_4(prep->pp_n);
281 ps = (const struct pgstate *)(prep + 1);
282 while (n != 0) {
283 const struct id_off *io, *ie;
284 char c = '<';
285
286 ND_PRINT(" %u/%s:%u",
287 GET_BE_U_4(ps->slot),
288 GET_IPADDR_STRING(ps->page.p_sid),
289 GET_BE_U_4(ps->page.p_uid));
290 /* now the rest of the fixed-size part of struct pgstate */
291 ND_TCHECK_SIZE(ps);
292 io = (const struct id_off *)(ps + 1);
293 for (ie = io + GET_U_1(ps->nid); io < ie; ++io) {
294 ND_PRINT("%c%s:%u", c, GET_IPADDR_STRING(io->id),
295 GET_BE_U_4(io->off));
296 c = ',';
297 }
298 ND_PRINT(">");
299 ps = (const struct pgstate *)io;
300 n--;
301 }
302 return 0;
303 }
304
305 static void
306 wb_dops(netdissect_options *ndo, const struct pkt_dop *dop,
307 uint32_t ss, uint32_t es)
308 {
309 const struct dophdr *dh = (const struct dophdr *)((const u_char *)dop + sizeof(*dop));
310
311 ND_PRINT(" <");
312 for ( ; ss <= es; ++ss) {
313 u_int t;
314
315 t = GET_U_1(dh->dh_type);
316
317 ND_PRINT(" %s", tok2str(dop_str, "dop-%u!", t));
318 if (t == DT_SKIP || t == DT_HOLE) {
319 uint32_t ts = GET_BE_U_4(dh->dh_ts);
320 ND_PRINT("%u", ts - ss + 1);
321 if (ss > ts || ts > es) {
322 ND_PRINT("[|]");
323 if (ts < ss)
324 return;
325 }
326 ss = ts;
327 }
328 dh = DOP_NEXT(dh);
329 }
330 ND_PRINT(" >");
331 }
332
333 static int
334 wb_rrep(netdissect_options *ndo,
335 const struct pkt_rrep *rrep, u_int len)
336 {
337 const struct pkt_dop *dop = &rrep->pr_dop;
338
339 ND_PRINT(" wb-rrep:");
340 if (len < sizeof(*rrep))
341 return (-1);
342 len -= sizeof(*rrep);
343
344 ND_PRINT(" for %s %s:%u<%u:%u>",
345 GET_IPADDR_STRING(rrep->pr_id),
346 GET_IPADDR_STRING(dop->pd_page.p_sid),
347 GET_BE_U_4(dop->pd_page.p_uid),
348 GET_BE_U_4(dop->pd_sseq),
349 GET_BE_U_4(dop->pd_eseq));
350
351 if (ndo->ndo_vflag)
352 wb_dops(ndo, dop,
353 GET_BE_U_4(dop->pd_sseq),
354 GET_BE_U_4(dop->pd_eseq));
355 return (0);
356 }
357
358 static int
359 wb_drawop(netdissect_options *ndo,
360 const struct pkt_dop *dop, u_int len)
361 {
362 ND_PRINT(" wb-dop:");
363 if (len < sizeof(*dop))
364 return (-1);
365 len -= sizeof(*dop);
366
367 ND_PRINT(" %s:%u<%u:%u>",
368 GET_IPADDR_STRING(dop->pd_page.p_sid),
369 GET_BE_U_4(dop->pd_page.p_uid),
370 GET_BE_U_4(dop->pd_sseq),
371 GET_BE_U_4(dop->pd_eseq));
372
373 if (ndo->ndo_vflag)
374 wb_dops(ndo, dop,
375 GET_BE_U_4(dop->pd_sseq),
376 GET_BE_U_4(dop->pd_eseq));
377 return (0);
378 }
379
380 /*
381 * Print whiteboard multicast packets.
382 */
383 void
384 wb_print(netdissect_options *ndo,
385 const u_char *hdr, u_int len)
386 {
387 const struct pkt_hdr *ph;
388 uint8_t type;
389 int print_result;
390
391 ndo->ndo_protocol = "wb";
392 ph = (const struct pkt_hdr *)hdr;
393 if (len < sizeof(*ph))
394 goto invalid;
395 ND_TCHECK_SIZE(ph);
396 len -= sizeof(*ph);
397
398 if (GET_U_1(ph->ph_flags))
399 ND_PRINT("*");
400 type = GET_U_1(ph->ph_type);
401 switch (type) {
402
403 case PT_KILL:
404 ND_PRINT(" wb-kill");
405 return;
406
407 case PT_ID:
408 print_result = wb_id(ndo, (const struct pkt_id *)(ph + 1), len);
409 break;
410
411 case PT_RREQ:
412 print_result = wb_rreq(ndo, (const struct pkt_rreq *)(ph + 1), len);
413 break;
414
415 case PT_RREP:
416 print_result = wb_rrep(ndo, (const struct pkt_rrep *)(ph + 1), len);
417 break;
418
419 case PT_DRAWOP:
420 print_result = wb_drawop(ndo, (const struct pkt_dop *)(ph + 1), len);
421 break;
422
423 case PT_PREQ:
424 print_result = wb_preq(ndo, (const struct pkt_preq *)(ph + 1), len);
425 break;
426
427 case PT_PREP:
428 print_result = wb_prep(ndo, (const struct pkt_prep *)(ph + 1), len);
429 break;
430
431 default:
432 ND_PRINT(" wb-%u!", type);
433 print_result = -1;
434 }
435 if (print_result < 0)
436 goto invalid;
437 return;
438
439 invalid:
440 nd_print_invalid(ndo);
441 }