Changeset View
Changeset View
Standalone View
Standalone View
head/contrib/tcpdump/print-wb.c
Show First 20 Lines • Show All 180 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
int i; | int i; | ||||
const char *cp; | const char *cp; | ||||
const struct id_off *io; | const struct id_off *io; | ||||
char c; | char c; | ||||
int nid; | int nid; | ||||
ND_PRINT((ndo, " wb-id:")); | ND_PRINT((ndo, " wb-id:")); | ||||
if (len < sizeof(*id) || (u_char *)(id + 1) > ndo->ndo_snapend) | if (len < sizeof(*id) || !ND_TTEST(*id)) | ||||
return (-1); | return (-1); | ||||
len -= sizeof(*id); | len -= sizeof(*id); | ||||
ND_PRINT((ndo, " %u/%s:%u (max %u/%s:%u) ", | ND_PRINT((ndo, " %u/%s:%u (max %u/%s:%u) ", | ||||
EXTRACT_32BITS(&id->pi_ps.slot), | EXTRACT_32BITS(&id->pi_ps.slot), | ||||
ipaddr_string(ndo, &id->pi_ps.page.p_sid), | ipaddr_string(ndo, &id->pi_ps.page.p_sid), | ||||
EXTRACT_32BITS(&id->pi_ps.page.p_uid), | EXTRACT_32BITS(&id->pi_ps.page.p_uid), | ||||
EXTRACT_32BITS(&id->pi_mslot), | EXTRACT_32BITS(&id->pi_mslot), | ||||
ipaddr_string(ndo, &id->pi_mpage.p_sid), | ipaddr_string(ndo, &id->pi_mpage.p_sid), | ||||
EXTRACT_32BITS(&id->pi_mpage.p_uid))); | EXTRACT_32BITS(&id->pi_mpage.p_uid))); | ||||
nid = EXTRACT_16BITS(&id->pi_ps.nid); | nid = EXTRACT_16BITS(&id->pi_ps.nid); | ||||
len -= sizeof(*io) * nid; | len -= sizeof(*io) * nid; | ||||
io = (struct id_off *)(id + 1); | io = (struct id_off *)(id + 1); | ||||
cp = (char *)(io + nid); | cp = (char *)(io + nid); | ||||
if ((u_char *)cp + len <= ndo->ndo_snapend) { | if (ND_TTEST2(cp, len)) { | ||||
ND_PRINT((ndo, "\"")); | ND_PRINT((ndo, "\"")); | ||||
fn_print(ndo, (u_char *)cp, (u_char *)cp + len); | fn_print(ndo, (u_char *)cp, (u_char *)cp + len); | ||||
ND_PRINT((ndo, "\"")); | ND_PRINT((ndo, "\"")); | ||||
} | } | ||||
c = '<'; | c = '<'; | ||||
for (i = 0; i < nid && (u_char *)(io + 1) <= ndo->ndo_snapend; ++io, ++i) { | for (i = 0; i < nid && ND_TTEST(*io); ++io, ++i) { | ||||
ND_PRINT((ndo, "%c%s:%u", | ND_PRINT((ndo, "%c%s:%u", | ||||
c, ipaddr_string(ndo, &io->id), EXTRACT_32BITS(&io->off))); | c, ipaddr_string(ndo, &io->id), EXTRACT_32BITS(&io->off))); | ||||
c = ','; | c = ','; | ||||
} | } | ||||
if (i >= nid) { | if (i >= nid) { | ||||
ND_PRINT((ndo, ">")); | ND_PRINT((ndo, ">")); | ||||
return (0); | return (0); | ||||
} | } | ||||
return (-1); | return (-1); | ||||
} | } | ||||
static int | static int | ||||
wb_rreq(netdissect_options *ndo, | wb_rreq(netdissect_options *ndo, | ||||
const struct pkt_rreq *rreq, u_int len) | const struct pkt_rreq *rreq, u_int len) | ||||
{ | { | ||||
ND_PRINT((ndo, " wb-rreq:")); | ND_PRINT((ndo, " wb-rreq:")); | ||||
if (len < sizeof(*rreq) || (u_char *)(rreq + 1) > ndo->ndo_snapend) | if (len < sizeof(*rreq) || !ND_TTEST(*rreq)) | ||||
return (-1); | return (-1); | ||||
ND_PRINT((ndo, " please repair %s %s:%u<%u:%u>", | ND_PRINT((ndo, " please repair %s %s:%u<%u:%u>", | ||||
ipaddr_string(ndo, &rreq->pr_id), | ipaddr_string(ndo, &rreq->pr_id), | ||||
ipaddr_string(ndo, &rreq->pr_page.p_sid), | ipaddr_string(ndo, &rreq->pr_page.p_sid), | ||||
EXTRACT_32BITS(&rreq->pr_page.p_uid), | EXTRACT_32BITS(&rreq->pr_page.p_uid), | ||||
EXTRACT_32BITS(&rreq->pr_sseq), | EXTRACT_32BITS(&rreq->pr_sseq), | ||||
EXTRACT_32BITS(&rreq->pr_eseq))); | EXTRACT_32BITS(&rreq->pr_eseq))); | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
wb_preq(netdissect_options *ndo, | wb_preq(netdissect_options *ndo, | ||||
const struct pkt_preq *preq, u_int len) | const struct pkt_preq *preq, u_int len) | ||||
{ | { | ||||
ND_PRINT((ndo, " wb-preq:")); | ND_PRINT((ndo, " wb-preq:")); | ||||
if (len < sizeof(*preq) || (u_char *)(preq + 1) > ndo->ndo_snapend) | if (len < sizeof(*preq) || !ND_TTEST(*preq)) | ||||
return (-1); | return (-1); | ||||
ND_PRINT((ndo, " need %u/%s:%u", | ND_PRINT((ndo, " need %u/%s:%u", | ||||
EXTRACT_32BITS(&preq->pp_low), | EXTRACT_32BITS(&preq->pp_low), | ||||
ipaddr_string(ndo, &preq->pp_page.p_sid), | ipaddr_string(ndo, &preq->pp_page.p_sid), | ||||
EXTRACT_32BITS(&preq->pp_page.p_uid))); | EXTRACT_32BITS(&preq->pp_page.p_uid))); | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
wb_prep(netdissect_options *ndo, | wb_prep(netdissect_options *ndo, | ||||
const struct pkt_prep *prep, u_int len) | const struct pkt_prep *prep, u_int len) | ||||
{ | { | ||||
int n; | int n; | ||||
const struct pgstate *ps; | const struct pgstate *ps; | ||||
const u_char *ep = ndo->ndo_snapend; | const u_char *ep = ndo->ndo_snapend; | ||||
ND_PRINT((ndo, " wb-prep:")); | ND_PRINT((ndo, " wb-prep:")); | ||||
if (len < sizeof(*prep)) { | if (len < sizeof(*prep)) { | ||||
return (-1); | return (-1); | ||||
} | } | ||||
n = EXTRACT_32BITS(&prep->pp_n); | n = EXTRACT_32BITS(&prep->pp_n); | ||||
ps = (const struct pgstate *)(prep + 1); | ps = (const struct pgstate *)(prep + 1); | ||||
while (--n >= 0 && (u_char *)(ps + 1) <= ep) { | while (--n >= 0 && ND_TTEST(*ps)) { | ||||
const struct id_off *io, *ie; | const struct id_off *io, *ie; | ||||
char c = '<'; | char c = '<'; | ||||
ND_PRINT((ndo, " %u/%s:%u", | ND_PRINT((ndo, " %u/%s:%u", | ||||
EXTRACT_32BITS(&ps->slot), | EXTRACT_32BITS(&ps->slot), | ||||
ipaddr_string(ndo, &ps->page.p_sid), | ipaddr_string(ndo, &ps->page.p_sid), | ||||
EXTRACT_32BITS(&ps->page.p_uid))); | EXTRACT_32BITS(&ps->page.p_uid))); | ||||
io = (struct id_off *)(ps + 1); | io = (struct id_off *)(ps + 1); | ||||
for (ie = io + ps->nid; io < ie && (u_char *)(io + 1) <= ep; ++io) { | for (ie = io + ps->nid; io < ie && ND_TTEST(*io); ++io) { | ||||
ND_PRINT((ndo, "%c%s:%u", c, ipaddr_string(ndo, &io->id), | ND_PRINT((ndo, "%c%s:%u", c, ipaddr_string(ndo, &io->id), | ||||
EXTRACT_32BITS(&io->off))); | EXTRACT_32BITS(&io->off))); | ||||
c = ','; | c = ','; | ||||
} | } | ||||
ND_PRINT((ndo, ">")); | ND_PRINT((ndo, ">")); | ||||
ps = (struct pgstate *)io; | ps = (struct pgstate *)io; | ||||
} | } | ||||
return ((u_char *)ps <= ep? 0 : -1); | return ((u_char *)ps <= ep? 0 : -1); | ||||
Show All 15 Lines | static const char *dopstr[] = { | ||||
"PSCODE", | "PSCODE", | ||||
"PSCOMP", | "PSCOMP", | ||||
"REF", | "REF", | ||||
"SKIP", | "SKIP", | ||||
"HOLE", | "HOLE", | ||||
}; | }; | ||||
static int | static int | ||||
wb_dops(netdissect_options *ndo, | wb_dops(netdissect_options *ndo, const struct pkt_dop *dop, | ||||
const struct dophdr *dh, uint32_t ss, uint32_t es) | uint32_t ss, uint32_t es) | ||||
{ | { | ||||
const struct dophdr *dh = (const struct dophdr *)((const u_char *)dop + sizeof(*dop)); | |||||
ND_PRINT((ndo, " <")); | ND_PRINT((ndo, " <")); | ||||
for ( ; ss <= es; ++ss) { | for ( ; ss <= es; ++ss) { | ||||
register int t = dh->dh_type; | int t; | ||||
if (!ND_TTEST(*dh)) { | |||||
ND_PRINT((ndo, "%s", tstr)); | |||||
break; | |||||
} | |||||
t = dh->dh_type; | |||||
if (t > DT_MAXTYPE) | if (t > DT_MAXTYPE) | ||||
ND_PRINT((ndo, " dop-%d!", t)); | ND_PRINT((ndo, " dop-%d!", t)); | ||||
else { | else { | ||||
ND_PRINT((ndo, " %s", dopstr[t])); | ND_PRINT((ndo, " %s", dopstr[t])); | ||||
if (t == DT_SKIP || t == DT_HOLE) { | if (t == DT_SKIP || t == DT_HOLE) { | ||||
uint32_t ts = EXTRACT_32BITS(&dh->dh_ts); | uint32_t ts = EXTRACT_32BITS(&dh->dh_ts); | ||||
ND_PRINT((ndo, "%d", ts - ss + 1)); | ND_PRINT((ndo, "%d", ts - ss + 1)); | ||||
if (ss > ts || ts > es) { | if (ss > ts || ts > es) { | ||||
ND_PRINT((ndo, "[|]")); | ND_PRINT((ndo, "[|]")); | ||||
if (ts < ss) | if (ts < ss) | ||||
return (0); | return (0); | ||||
} | } | ||||
ss = ts; | ss = ts; | ||||
} | } | ||||
} | } | ||||
dh = DOP_NEXT(dh); | dh = DOP_NEXT(dh); | ||||
if ((u_char *)dh > ndo->ndo_snapend) { | |||||
ND_PRINT((ndo, "%s", tstr)); | |||||
break; | |||||
} | } | ||||
} | |||||
ND_PRINT((ndo, " >")); | ND_PRINT((ndo, " >")); | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
wb_rrep(netdissect_options *ndo, | wb_rrep(netdissect_options *ndo, | ||||
const struct pkt_rrep *rrep, u_int len) | const struct pkt_rrep *rrep, u_int len) | ||||
{ | { | ||||
const struct pkt_dop *dop = &rrep->pr_dop; | const struct pkt_dop *dop = &rrep->pr_dop; | ||||
ND_PRINT((ndo, " wb-rrep:")); | ND_PRINT((ndo, " wb-rrep:")); | ||||
if (len < sizeof(*rrep) || (u_char *)(rrep + 1) > ndo->ndo_snapend) | if (len < sizeof(*rrep) || !ND_TTEST(*rrep)) | ||||
return (-1); | return (-1); | ||||
len -= sizeof(*rrep); | len -= sizeof(*rrep); | ||||
ND_PRINT((ndo, " for %s %s:%u<%u:%u>", | ND_PRINT((ndo, " for %s %s:%u<%u:%u>", | ||||
ipaddr_string(ndo, &rrep->pr_id), | ipaddr_string(ndo, &rrep->pr_id), | ||||
ipaddr_string(ndo, &dop->pd_page.p_sid), | ipaddr_string(ndo, &dop->pd_page.p_sid), | ||||
EXTRACT_32BITS(&dop->pd_page.p_uid), | EXTRACT_32BITS(&dop->pd_page.p_uid), | ||||
EXTRACT_32BITS(&dop->pd_sseq), | EXTRACT_32BITS(&dop->pd_sseq), | ||||
EXTRACT_32BITS(&dop->pd_eseq))); | EXTRACT_32BITS(&dop->pd_eseq))); | ||||
if (ndo->ndo_vflag) | if (ndo->ndo_vflag) | ||||
return (wb_dops(ndo, (const struct dophdr *)(dop + 1), | return (wb_dops(ndo, dop, | ||||
EXTRACT_32BITS(&dop->pd_sseq), | EXTRACT_32BITS(&dop->pd_sseq), | ||||
EXTRACT_32BITS(&dop->pd_eseq))); | EXTRACT_32BITS(&dop->pd_eseq))); | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
wb_drawop(netdissect_options *ndo, | wb_drawop(netdissect_options *ndo, | ||||
const struct pkt_dop *dop, u_int len) | const struct pkt_dop *dop, u_int len) | ||||
{ | { | ||||
ND_PRINT((ndo, " wb-dop:")); | ND_PRINT((ndo, " wb-dop:")); | ||||
if (len < sizeof(*dop) || (u_char *)(dop + 1) > ndo->ndo_snapend) | if (len < sizeof(*dop) || !ND_TTEST(*dop)) | ||||
return (-1); | return (-1); | ||||
len -= sizeof(*dop); | len -= sizeof(*dop); | ||||
ND_PRINT((ndo, " %s:%u<%u:%u>", | ND_PRINT((ndo, " %s:%u<%u:%u>", | ||||
ipaddr_string(ndo, &dop->pd_page.p_sid), | ipaddr_string(ndo, &dop->pd_page.p_sid), | ||||
EXTRACT_32BITS(&dop->pd_page.p_uid), | EXTRACT_32BITS(&dop->pd_page.p_uid), | ||||
EXTRACT_32BITS(&dop->pd_sseq), | EXTRACT_32BITS(&dop->pd_sseq), | ||||
EXTRACT_32BITS(&dop->pd_eseq))); | EXTRACT_32BITS(&dop->pd_eseq))); | ||||
if (ndo->ndo_vflag) | if (ndo->ndo_vflag) | ||||
return (wb_dops(ndo, (const struct dophdr *)(dop + 1), | return (wb_dops(ndo, dop, | ||||
EXTRACT_32BITS(&dop->pd_sseq), | EXTRACT_32BITS(&dop->pd_sseq), | ||||
EXTRACT_32BITS(&dop->pd_eseq))); | EXTRACT_32BITS(&dop->pd_eseq))); | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Print whiteboard multicast packets. | * Print whiteboard multicast packets. | ||||
*/ | */ | ||||
void | void | ||||
wb_print(netdissect_options *ndo, | wb_print(netdissect_options *ndo, | ||||
register const void *hdr, register u_int len) | register const void *hdr, register u_int len) | ||||
{ | { | ||||
register const struct pkt_hdr *ph; | register const struct pkt_hdr *ph; | ||||
ph = (const struct pkt_hdr *)hdr; | ph = (const struct pkt_hdr *)hdr; | ||||
if (len < sizeof(*ph) || (u_char *)(ph + 1) > ndo->ndo_snapend) { | if (len < sizeof(*ph) || !ND_TTEST(*ph)) { | ||||
ND_PRINT((ndo, "%s", tstr)); | ND_PRINT((ndo, "%s", tstr)); | ||||
return; | return; | ||||
} | } | ||||
len -= sizeof(*ph); | len -= sizeof(*ph); | ||||
if (ph->ph_flags) | if (ph->ph_flags) | ||||
ND_PRINT((ndo, "*")); | ND_PRINT((ndo, "*")); | ||||
switch (ph->ph_type) { | switch (ph->ph_type) { | ||||
Show All 40 Lines |