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