print-decnet.c revision 56893
117680Spst/* 239297Sfenner * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997 317680Spst * The Regents of the University of California. All rights reserved. 417680Spst * 517680Spst * Redistribution and use in source and binary forms, with or without 617680Spst * modification, are permitted provided that: (1) source code distributions 717680Spst * retain the above copyright notice and this paragraph in its entirety, (2) 817680Spst * distributions including binary code include the above copyright notice and 917680Spst * this paragraph in its entirety in the documentation or other materials 1017680Spst * provided with the distribution, and (3) all advertising materials mentioning 1117680Spst * features or use of this software display the following acknowledgement: 1217680Spst * ``This product includes software developed by the University of California, 1317680Spst * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 1417680Spst * the University nor the names of its contributors may be used to endorse 1517680Spst * or promote products derived from this software without specific prior 1617680Spst * written permission. 1717680Spst * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 1817680Spst * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 1917680Spst * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 2017680Spst */ 2117680Spst 2217680Spst#ifndef lint 2326180Sfennerstatic const char rcsid[] = 2456893Sfenner "@(#) $Header: /tcpdump/master/tcpdump/print-decnet.c,v 1.27 1999/11/21 09:36:50 fenner Exp $ (LBL)"; 2517680Spst#endif 2617680Spst 2756893Sfenner#ifdef HAVE_CONFIG_H 2856893Sfenner#include "config.h" 2956893Sfenner#endif 3056893Sfenner 3117680Spst#include <sys/param.h> 3217680Spst#include <sys/time.h> 3317680Spst#include <sys/socket.h> 3417680Spst 3517680Spst#if __STDC__ 3617680Spststruct mbuf; 3717680Spststruct rtentry; 3817680Spst#endif 3917680Spst#include <net/if.h> 4017680Spst 4117680Spst#ifdef HAVE_LIBDNET 4217680Spst#include <netdnet/dnetdb.h> 4317680Spst#endif 4417680Spst 4517680Spst#include <ctype.h> 4639297Sfenner#ifdef HAVE_MALLOC_H 4739297Sfenner#include <malloc.h> 4839297Sfenner#endif 4917680Spst#include <stdio.h> 5017680Spst#include <stdlib.h> 5117680Spst#include <string.h> 5217680Spst#include <unistd.h> 5317680Spst 5417680Spst#include "decnet.h" 5517680Spst#include "extract.h" 5617680Spst#include "interface.h" 5717680Spst#include "addrtoname.h" 5817680Spst 5917680Spst/* Forwards */ 6017680Spststatic void print_decnet_ctlmsg(const union routehdr *, u_int); 6117680Spststatic void print_t_info(int); 6217680Spststatic void print_l1_routes(const char *, u_int); 6317680Spststatic void print_l2_routes(const char *, u_int); 6417680Spststatic void print_i_info(int); 6517680Spststatic void print_elist(const char *, u_int); 6617680Spststatic void print_nsp(const u_char *, u_int); 6717680Spststatic void print_reason(int); 6817680Spst#ifdef PRINT_NSPDATA 6917680Spststatic void pdata(u_char *, int); 7017680Spst#endif 7117680Spst 7217680Spst#ifdef HAVE_LIBDNET 7317680Spstextern char *dnet_htoa(struct dn_naddr *); 7417680Spst#endif 7517680Spst 7617680Spstvoid 7717680Spstdecnet_print(register const u_char *ap, register u_int length, 7817680Spst register u_int caplen) 7917680Spst{ 8017680Spst static union routehdr rhcopy; 8117680Spst register union routehdr *rhp = &rhcopy; 8217680Spst register int mflags; 8317680Spst int dst, src, hops; 8417680Spst u_int rhlen, nsplen, pktlen; 8517680Spst const u_char *nspp; 8617680Spst 8717680Spst if (length < sizeof(struct shorthdr)) { 8817680Spst (void)printf("[|decnet]"); 8917680Spst return; 9017680Spst } 9117680Spst 9217680Spst pktlen = EXTRACT_LE_16BITS(ap); 9317680Spst 9417680Spst rhlen = min(length, caplen); 9517680Spst rhlen = min(rhlen, sizeof(*rhp)); 9617680Spst memcpy((char *)rhp, (char *)&(ap[sizeof(short)]), rhlen); 9717680Spst 9817680Spst mflags = EXTRACT_LE_8BITS(rhp->rh_short.sh_flags); 9917680Spst 10017680Spst if (mflags & RMF_PAD) { 10117680Spst /* pad bytes of some sort in front of message */ 10217680Spst u_int padlen = mflags & RMF_PADMASK; 10317680Spst if (vflag) 10417680Spst (void) printf("[pad:%d] ", padlen); 10517680Spst ap += padlen; 10617680Spst length -= padlen; 10717680Spst caplen -= padlen; 10817680Spst rhlen = min(length, caplen); 10917680Spst rhlen = min(rhlen, sizeof(*rhp)); 11017680Spst memcpy((char *)rhp, (char *)&(ap[sizeof(short)]), rhlen); 11117680Spst mflags = EXTRACT_LE_8BITS(rhp->rh_short.sh_flags); 11217680Spst } 11317680Spst 11417680Spst if (mflags & RMF_FVER) { 11517680Spst (void) printf("future-version-decnet"); 11617680Spst default_print(ap, length); 11717680Spst return; 11817680Spst } 11917680Spst 12017680Spst /* is it a control message? */ 12117680Spst if (mflags & RMF_CTLMSG) { 12217680Spst print_decnet_ctlmsg(rhp, min(length, caplen)); 12317680Spst return; 12417680Spst } 12517680Spst 12617680Spst switch (mflags & RMF_MASK) { 12717680Spst case RMF_LONG: 12817680Spst dst = 12917680Spst EXTRACT_LE_16BITS(rhp->rh_long.lg_dst.dne_remote.dne_nodeaddr); 13017680Spst src = 13117680Spst EXTRACT_LE_16BITS(rhp->rh_long.lg_src.dne_remote.dne_nodeaddr); 13217680Spst hops = EXTRACT_LE_8BITS(rhp->rh_long.lg_visits); 13317680Spst nspp = &(ap[sizeof(short) + sizeof(struct longhdr)]); 13417680Spst nsplen = min((length - sizeof(struct longhdr)), 13517680Spst (caplen - sizeof(struct longhdr))); 13617680Spst break; 13717680Spst case RMF_SHORT: 13817680Spst dst = EXTRACT_LE_16BITS(rhp->rh_short.sh_dst); 13917680Spst src = EXTRACT_LE_16BITS(rhp->rh_short.sh_src); 14017680Spst hops = (EXTRACT_LE_8BITS(rhp->rh_short.sh_visits) & VIS_MASK)+1; 14117680Spst nspp = &(ap[sizeof(short) + sizeof(struct shorthdr)]); 14217680Spst nsplen = min((length - sizeof(struct shorthdr)), 14317680Spst (caplen - sizeof(struct shorthdr))); 14417680Spst break; 14517680Spst default: 14617680Spst (void) printf("unknown message flags under mask"); 14717680Spst default_print((u_char *)ap, length); 14817680Spst return; 14917680Spst } 15017680Spst 15117680Spst (void)printf("%s > %s %d ", 15217680Spst dnaddr_string(src), dnaddr_string(dst), pktlen); 15317680Spst if (vflag) { 15417680Spst if (mflags & RMF_RQR) 15517680Spst (void)printf("RQR "); 15617680Spst if (mflags & RMF_RTS) 15717680Spst (void)printf("RTS "); 15817680Spst if (mflags & RMF_IE) 15917680Spst (void)printf("IE "); 16017680Spst (void)printf("%d hops ", hops); 16117680Spst } 16217680Spst 16317680Spst print_nsp(nspp, nsplen); 16417680Spst} 16517680Spst 16617680Spststatic void 16717680Spstprint_decnet_ctlmsg(register const union routehdr *rhp, u_int length) 16817680Spst{ 16917680Spst int mflags = EXTRACT_LE_8BITS(rhp->rh_short.sh_flags); 17017680Spst register union controlmsg *cmp = (union controlmsg *)rhp; 17117680Spst int src, dst, info, blksize, eco, ueco, hello, other, vers; 17217680Spst etheraddr srcea, rtea; 17317680Spst int priority; 17417680Spst char *rhpx = (char *)rhp; 17517680Spst 17617680Spst switch (mflags & RMF_CTLMASK) { 17717680Spst case RMF_INIT: 17817680Spst (void)printf("init "); 17917680Spst src = EXTRACT_LE_16BITS(cmp->cm_init.in_src); 18017680Spst info = EXTRACT_LE_8BITS(cmp->cm_init.in_info); 18117680Spst blksize = EXTRACT_LE_16BITS(cmp->cm_init.in_blksize); 18217680Spst vers = EXTRACT_LE_8BITS(cmp->cm_init.in_vers); 18317680Spst eco = EXTRACT_LE_8BITS(cmp->cm_init.in_eco); 18417680Spst ueco = EXTRACT_LE_8BITS(cmp->cm_init.in_ueco); 18517680Spst hello = EXTRACT_LE_16BITS(cmp->cm_init.in_hello); 18617680Spst print_t_info(info); 18717680Spst (void)printf( 18817680Spst "src %sblksize %d vers %d eco %d ueco %d hello %d", 18917680Spst dnaddr_string(src), blksize, vers, eco, ueco, 19017680Spst hello); 19117680Spst break; 19217680Spst case RMF_VER: 19317680Spst (void)printf("verification "); 19417680Spst src = EXTRACT_LE_16BITS(cmp->cm_ver.ve_src); 19517680Spst other = EXTRACT_LE_8BITS(cmp->cm_ver.ve_fcnval); 19617680Spst (void)printf("src %s fcnval %o", dnaddr_string(src), other); 19717680Spst break; 19817680Spst case RMF_TEST: 19917680Spst (void)printf("test "); 20017680Spst src = EXTRACT_LE_16BITS(cmp->cm_test.te_src); 20117680Spst other = EXTRACT_LE_8BITS(cmp->cm_test.te_data); 20217680Spst (void)printf("src %s data %o", dnaddr_string(src), other); 20317680Spst break; 20417680Spst case RMF_L1ROUT: 20517680Spst (void)printf("lev-1-routing "); 20617680Spst src = EXTRACT_LE_16BITS(cmp->cm_l1rou.r1_src); 20717680Spst (void)printf("src %s ", dnaddr_string(src)); 20817680Spst print_l1_routes(&(rhpx[sizeof(struct l1rout)]), 20917680Spst length - sizeof(struct l1rout)); 21017680Spst break; 21117680Spst case RMF_L2ROUT: 21217680Spst (void)printf("lev-2-routing "); 21317680Spst src = EXTRACT_LE_16BITS(cmp->cm_l2rout.r2_src); 21417680Spst (void)printf("src %s ", dnaddr_string(src)); 21517680Spst print_l2_routes(&(rhpx[sizeof(struct l2rout)]), 21617680Spst length - sizeof(struct l2rout)); 21717680Spst break; 21817680Spst case RMF_RHELLO: 21917680Spst (void)printf("router-hello "); 22017680Spst vers = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_vers); 22117680Spst eco = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_eco); 22217680Spst ueco = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_ueco); 22317680Spst memcpy((char *)&srcea, (char *)&(cmp->cm_rhello.rh_src), 22417680Spst sizeof(srcea)); 22517680Spst src = EXTRACT_LE_16BITS(srcea.dne_remote.dne_nodeaddr); 22617680Spst info = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_info); 22717680Spst blksize = EXTRACT_LE_16BITS(cmp->cm_rhello.rh_blksize); 22817680Spst priority = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_priority); 22917680Spst hello = EXTRACT_LE_16BITS(cmp->cm_rhello.rh_hello); 23017680Spst print_i_info(info); 23117680Spst (void)printf( 23217680Spst "vers %d eco %d ueco %d src %s blksize %d pri %d hello %d", 23317680Spst vers, eco, ueco, dnaddr_string(src), 23417680Spst blksize, priority, hello); 23517680Spst print_elist(&(rhpx[sizeof(struct rhellomsg)]), 23617680Spst length - sizeof(struct rhellomsg)); 23717680Spst break; 23817680Spst case RMF_EHELLO: 23917680Spst (void)printf("endnode-hello "); 24017680Spst vers = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_vers); 24117680Spst eco = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_eco); 24217680Spst ueco = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_ueco); 24317680Spst memcpy((char *)&srcea, (char *)&(cmp->cm_ehello.eh_src), 24417680Spst sizeof(srcea)); 24517680Spst src = EXTRACT_LE_16BITS(srcea.dne_remote.dne_nodeaddr); 24617680Spst info = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_info); 24717680Spst blksize = EXTRACT_LE_16BITS(cmp->cm_ehello.eh_blksize); 24817680Spst /*seed*/ 24917680Spst memcpy((char *)&rtea, (char *)&(cmp->cm_ehello.eh_router), 25017680Spst sizeof(rtea)); 25117680Spst dst = EXTRACT_LE_16BITS(rtea.dne_remote.dne_nodeaddr); 25217680Spst hello = EXTRACT_LE_16BITS(cmp->cm_ehello.eh_hello); 25317680Spst other = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_data); 25417680Spst print_i_info(info); 25517680Spst (void)printf( 25617680Spst "vers %d eco %d ueco %d src %s blksize %d rtr %s hello %d data %o", 25717680Spst vers, eco, ueco, dnaddr_string(src), 25817680Spst blksize, dnaddr_string(dst), hello, other); 25917680Spst break; 26017680Spst 26117680Spst default: 26217680Spst (void)printf("unknown control message"); 26317680Spst default_print((u_char *)rhp, length); 26417680Spst break; 26517680Spst } 26617680Spst} 26717680Spst 26817680Spststatic void 26917680Spstprint_t_info(int info) 27017680Spst{ 27117680Spst int ntype = info & 3; 27217680Spst switch (ntype) { 27317680Spst case 0: (void)printf("reserved-ntype? "); break; 27417680Spst case TI_L2ROUT: (void)printf("l2rout "); break; 27517680Spst case TI_L1ROUT: (void)printf("l1rout "); break; 27617680Spst case TI_ENDNODE: (void)printf("endnode "); break; 27717680Spst } 27817680Spst if (info & TI_VERIF) 27917680Spst (void)printf("verif "); 28017680Spst if (info & TI_BLOCK) 28117680Spst (void)printf("blo "); 28217680Spst} 28317680Spst 28417680Spststatic void 28517680Spstprint_l1_routes(const char *rp, u_int len) 28617680Spst{ 28717680Spst int count; 28817680Spst int id; 28917680Spst int info; 29017680Spst 29117680Spst /* The last short is a checksum */ 29217680Spst while (len > (3 * sizeof(short))) { 29317680Spst count = EXTRACT_LE_16BITS(rp); 29417680Spst if (count > 1024) 29517680Spst return; /* seems to be bogus from here on */ 29617680Spst rp += sizeof(short); 29717680Spst len -= sizeof(short); 29817680Spst id = EXTRACT_LE_16BITS(rp); 29917680Spst rp += sizeof(short); 30017680Spst len -= sizeof(short); 30117680Spst info = EXTRACT_LE_16BITS(rp); 30217680Spst rp += sizeof(short); 30317680Spst len -= sizeof(short); 30417680Spst (void)printf("{ids %d-%d cost %d hops %d} ", id, id + count, 30517680Spst RI_COST(info), RI_HOPS(info)); 30617680Spst } 30717680Spst} 30817680Spst 30917680Spststatic void 31017680Spstprint_l2_routes(const char *rp, u_int len) 31117680Spst{ 31217680Spst int count; 31317680Spst int area; 31417680Spst int info; 31517680Spst 31617680Spst /* The last short is a checksum */ 31717680Spst while (len > (3 * sizeof(short))) { 31817680Spst count = EXTRACT_LE_16BITS(rp); 31917680Spst if (count > 1024) 32017680Spst return; /* seems to be bogus from here on */ 32117680Spst rp += sizeof(short); 32217680Spst len -= sizeof(short); 32317680Spst area = EXTRACT_LE_16BITS(rp); 32417680Spst rp += sizeof(short); 32517680Spst len -= sizeof(short); 32617680Spst info = EXTRACT_LE_16BITS(rp); 32717680Spst rp += sizeof(short); 32817680Spst len -= sizeof(short); 32917680Spst (void)printf("{areas %d-%d cost %d hops %d} ", area, area + count, 33017680Spst RI_COST(info), RI_HOPS(info)); 33117680Spst } 33217680Spst} 33317680Spst 33417680Spststatic void 33517680Spstprint_i_info(int info) 33617680Spst{ 33717680Spst int ntype = info & II_TYPEMASK; 33817680Spst switch (ntype) { 33917680Spst case 0: (void)printf("reserved-ntype? "); break; 34017680Spst case II_L2ROUT: (void)printf("l2rout "); break; 34117680Spst case II_L1ROUT: (void)printf("l1rout "); break; 34217680Spst case II_ENDNODE: (void)printf("endnode "); break; 34317680Spst } 34417680Spst if (info & II_VERIF) 34517680Spst (void)printf("verif "); 34617680Spst if (info & II_NOMCAST) 34717680Spst (void)printf("nomcast "); 34817680Spst if (info & II_BLOCK) 34917680Spst (void)printf("blo "); 35017680Spst} 35117680Spst 35217680Spststatic void 35317680Spstprint_elist(const char *elp, u_int len) 35417680Spst{ 35517680Spst /* Not enough examples available for me to debug this */ 35617680Spst} 35717680Spst 35817680Spststatic void 35917680Spstprint_nsp(const u_char *nspp, u_int nsplen) 36017680Spst{ 36117680Spst const struct nsphdr *nsphp = (struct nsphdr *)nspp; 36217680Spst int dst, src, flags; 36317680Spst 36417680Spst flags = EXTRACT_LE_8BITS(nsphp->nh_flags); 36517680Spst dst = EXTRACT_LE_16BITS(nsphp->nh_dst); 36617680Spst src = EXTRACT_LE_16BITS(nsphp->nh_src); 36717680Spst 36817680Spst switch (flags & NSP_TYPEMASK) { 36917680Spst case MFT_DATA: 37017680Spst switch (flags & NSP_SUBMASK) { 37117680Spst case MFS_BOM: 37217680Spst case MFS_MOM: 37317680Spst case MFS_EOM: 37417680Spst case MFS_BOM+MFS_EOM: 37517680Spst printf("data %d>%d ", src, dst); 37617680Spst { 37717680Spst struct seghdr *shp = (struct seghdr *)nspp; 37817680Spst int ack; 37917680Spst#ifdef PRINT_NSPDATA 38017680Spst u_char *dp; 38117680Spst#endif 38217680Spst u_int data_off = sizeof(struct minseghdr); 38317680Spst 38417680Spst ack = EXTRACT_LE_16BITS(shp->sh_seq[0]); 38517680Spst if (ack & SGQ_ACK) { /* acknum field */ 38617680Spst if ((ack & SGQ_NAK) == SGQ_NAK) 38717680Spst (void)printf("nak %d ", ack & SGQ_MASK); 38817680Spst else 38917680Spst (void)printf("ack %d ", ack & SGQ_MASK); 39017680Spst ack = EXTRACT_LE_16BITS(shp->sh_seq[1]); 39117680Spst data_off += sizeof(short); 39217680Spst if (ack & SGQ_OACK) { /* ackoth field */ 39317680Spst if ((ack & SGQ_ONAK) == SGQ_ONAK) 39417680Spst (void)printf("onak %d ", ack & SGQ_MASK); 39517680Spst else 39617680Spst (void)printf("oack %d ", ack & SGQ_MASK); 39717680Spst ack = EXTRACT_LE_16BITS(shp->sh_seq[2]); 39817680Spst data_off += sizeof(short); 39917680Spst } 40017680Spst } 40117680Spst (void)printf("seg %d ", ack & SGQ_MASK); 40217680Spst#ifdef PRINT_NSPDATA 40317680Spst dp = &(nspp[data_off]); 40417680Spst pdata(dp, 10); 40517680Spst#endif 40617680Spst } 40717680Spst break; 40817680Spst case MFS_ILS+MFS_INT: 40917680Spst printf("intr "); 41017680Spst { 41117680Spst struct seghdr *shp = (struct seghdr *)nspp; 41217680Spst int ack; 41317680Spst#ifdef PRINT_NSPDATA 41417680Spst u_char *dp; 41517680Spst#endif 41617680Spst u_int data_off = sizeof(struct minseghdr); 41717680Spst 41817680Spst ack = EXTRACT_LE_16BITS(shp->sh_seq[0]); 41917680Spst if (ack & SGQ_ACK) { /* acknum field */ 42017680Spst if ((ack & SGQ_NAK) == SGQ_NAK) 42117680Spst (void)printf("nak %d ", ack & SGQ_MASK); 42217680Spst else 42317680Spst (void)printf("ack %d ", ack & SGQ_MASK); 42417680Spst ack = EXTRACT_LE_16BITS(shp->sh_seq[1]); 42517680Spst data_off += sizeof(short); 42617680Spst if (ack & SGQ_OACK) { /* ackdat field */ 42717680Spst if ((ack & SGQ_ONAK) == SGQ_ONAK) 42817680Spst (void)printf("nakdat %d ", ack & SGQ_MASK); 42917680Spst else 43017680Spst (void)printf("ackdat %d ", ack & SGQ_MASK); 43117680Spst ack = EXTRACT_LE_16BITS(shp->sh_seq[2]); 43217680Spst data_off += sizeof(short); 43317680Spst } 43417680Spst } 43517680Spst (void)printf("seg %d ", ack & SGQ_MASK); 43617680Spst#ifdef PRINT_NSPDATA 43717680Spst dp = &(nspp[data_off]); 43817680Spst pdata(dp, 10); 43917680Spst#endif 44017680Spst } 44117680Spst break; 44217680Spst case MFS_ILS: 44317680Spst (void)printf("link-service %d>%d ", src, dst); 44417680Spst { 44517680Spst struct seghdr *shp = (struct seghdr *)nspp; 44617680Spst struct lsmsg *lsmp = 44717680Spst (struct lsmsg *)&(nspp[sizeof(struct seghdr)]); 44817680Spst int ack; 44917680Spst int lsflags, fcval; 45017680Spst 45117680Spst ack = EXTRACT_LE_16BITS(shp->sh_seq[0]); 45217680Spst if (ack & SGQ_ACK) { /* acknum field */ 45317680Spst if ((ack & SGQ_NAK) == SGQ_NAK) 45417680Spst (void)printf("nak %d ", ack & SGQ_MASK); 45517680Spst else 45617680Spst (void)printf("ack %d ", ack & SGQ_MASK); 45717680Spst ack = EXTRACT_LE_16BITS(shp->sh_seq[1]); 45817680Spst if (ack & SGQ_OACK) { /* ackdat field */ 45917680Spst if ((ack & SGQ_ONAK) == SGQ_ONAK) 46017680Spst (void)printf("nakdat %d ", ack & SGQ_MASK); 46117680Spst else 46217680Spst (void)printf("ackdat %d ", ack & SGQ_MASK); 46317680Spst ack = EXTRACT_LE_16BITS(shp->sh_seq[2]); 46417680Spst } 46517680Spst } 46617680Spst (void)printf("seg %d ", ack & SGQ_MASK); 46717680Spst lsflags = EXTRACT_LE_8BITS(lsmp->ls_lsflags); 46817680Spst fcval = EXTRACT_LE_8BITS(lsmp->ls_fcval); 46917680Spst switch (lsflags & LSI_MASK) { 47017680Spst case LSI_DATA: 47117680Spst (void)printf("dat seg count %d ", fcval); 47217680Spst switch (lsflags & LSM_MASK) { 47317680Spst case LSM_NOCHANGE: 47417680Spst break; 47517680Spst case LSM_DONOTSEND: 47617680Spst (void)printf("donotsend-data "); 47717680Spst break; 47817680Spst case LSM_SEND: 47917680Spst (void)printf("send-data "); 48017680Spst break; 48117680Spst default: 48217680Spst (void)printf("reserved-fcmod? %x", lsflags); 48317680Spst break; 48417680Spst } 48517680Spst break; 48617680Spst case LSI_INTR: 48717680Spst (void)printf("intr req count %d ", fcval); 48817680Spst break; 48917680Spst default: 49017680Spst (void)printf("reserved-fcval-int? %x", lsflags); 49117680Spst break; 49217680Spst } 49317680Spst } 49417680Spst break; 49517680Spst default: 49617680Spst (void)printf("reserved-subtype? %x %d > %d", flags, src, dst); 49717680Spst break; 49817680Spst } 49917680Spst break; 50017680Spst case MFT_ACK: 50117680Spst switch (flags & NSP_SUBMASK) { 50217680Spst case MFS_DACK: 50317680Spst (void)printf("data-ack %d>%d ", src, dst); 50417680Spst { 50517680Spst struct ackmsg *amp = (struct ackmsg *)nspp; 50617680Spst int ack; 50717680Spst 50817680Spst ack = EXTRACT_LE_16BITS(amp->ak_acknum[0]); 50917680Spst if (ack & SGQ_ACK) { /* acknum field */ 51017680Spst if ((ack & SGQ_NAK) == SGQ_NAK) 51117680Spst (void)printf("nak %d ", ack & SGQ_MASK); 51217680Spst else 51317680Spst (void)printf("ack %d ", ack & SGQ_MASK); 51417680Spst ack = EXTRACT_LE_16BITS(amp->ak_acknum[1]); 51517680Spst if (ack & SGQ_OACK) { /* ackoth field */ 51617680Spst if ((ack & SGQ_ONAK) == SGQ_ONAK) 51717680Spst (void)printf("onak %d ", ack & SGQ_MASK); 51817680Spst else 51917680Spst (void)printf("oack %d ", ack & SGQ_MASK); 52017680Spst } 52117680Spst } 52217680Spst } 52317680Spst break; 52417680Spst case MFS_IACK: 52517680Spst (void)printf("ils-ack %d>%d ", src, dst); 52617680Spst { 52717680Spst struct ackmsg *amp = (struct ackmsg *)nspp; 52817680Spst int ack; 52917680Spst 53017680Spst ack = EXTRACT_LE_16BITS(amp->ak_acknum[0]); 53117680Spst if (ack & SGQ_ACK) { /* acknum field */ 53217680Spst if ((ack & SGQ_NAK) == SGQ_NAK) 53317680Spst (void)printf("nak %d ", ack & SGQ_MASK); 53417680Spst else 53517680Spst (void)printf("ack %d ", ack & SGQ_MASK); 53617680Spst ack = EXTRACT_LE_16BITS(amp->ak_acknum[1]); 53717680Spst if (ack & SGQ_OACK) { /* ackdat field */ 53817680Spst if ((ack & SGQ_ONAK) == SGQ_ONAK) 53917680Spst (void)printf("nakdat %d ", ack & SGQ_MASK); 54017680Spst else 54117680Spst (void)printf("ackdat %d ", ack & SGQ_MASK); 54217680Spst } 54317680Spst } 54417680Spst } 54517680Spst break; 54617680Spst case MFS_CACK: 54717680Spst (void)printf("conn-ack %d", dst); 54817680Spst break; 54917680Spst default: 55017680Spst (void)printf("reserved-acktype? %x %d > %d", flags, src, dst); 55117680Spst break; 55217680Spst } 55317680Spst break; 55417680Spst case MFT_CTL: 55517680Spst switch (flags & NSP_SUBMASK) { 55617680Spst case MFS_CI: 55717680Spst case MFS_RCI: 55817680Spst if ((flags & NSP_SUBMASK) == MFS_CI) 55917680Spst (void)printf("conn-initiate "); 56017680Spst else 56117680Spst (void)printf("retrans-conn-initiate "); 56217680Spst (void)printf("%d>%d ", src, dst); 56317680Spst { 56417680Spst struct cimsg *cimp = (struct cimsg *)nspp; 56517680Spst int services, info, segsize; 56617680Spst#ifdef PRINT_NSPDATA 56717680Spst u_char *dp; 56817680Spst#endif 56917680Spst 57017680Spst services = EXTRACT_LE_8BITS(cimp->ci_services); 57117680Spst info = EXTRACT_LE_8BITS(cimp->ci_info); 57217680Spst segsize = EXTRACT_LE_16BITS(cimp->ci_segsize); 57317680Spst 57417680Spst switch (services & COS_MASK) { 57517680Spst case COS_NONE: 57617680Spst break; 57717680Spst case COS_SEGMENT: 57817680Spst (void)printf("seg "); 57917680Spst break; 58017680Spst case COS_MESSAGE: 58117680Spst (void)printf("msg "); 58217680Spst break; 58317680Spst case COS_CRYPTSER: 58417680Spst (void)printf("crypt "); 58517680Spst break; 58617680Spst } 58717680Spst switch (info & COI_MASK) { 58817680Spst case COI_32: 58917680Spst (void)printf("ver 3.2 "); 59017680Spst break; 59117680Spst case COI_31: 59217680Spst (void)printf("ver 3.1 "); 59317680Spst break; 59417680Spst case COI_40: 59517680Spst (void)printf("ver 4.0 "); 59617680Spst break; 59717680Spst case COI_41: 59817680Spst (void)printf("ver 4.1 "); 59917680Spst break; 60017680Spst } 60117680Spst (void)printf("segsize %d ", segsize); 60217680Spst#ifdef PRINT_NSPDATA 60317680Spst dp = &(nspp[sizeof(struct cimsg)]); 60417680Spst pdata(dp, nsplen - sizeof(struct cimsg)); 60517680Spst#endif 60617680Spst } 60717680Spst break; 60817680Spst case MFS_CC: 60917680Spst (void)printf("conn-confirm %d>%d ", src, dst); 61017680Spst { 61117680Spst struct ccmsg *ccmp = (struct ccmsg *)nspp; 61217680Spst int services, info; 61317680Spst u_int segsize, optlen; 61417680Spst#ifdef PRINT_NSPDATA 61517680Spst u_char *dp; 61617680Spst#endif 61717680Spst 61817680Spst services = EXTRACT_LE_8BITS(ccmp->cc_services); 61917680Spst info = EXTRACT_LE_8BITS(ccmp->cc_info); 62017680Spst segsize = EXTRACT_LE_16BITS(ccmp->cc_segsize); 62117680Spst optlen = EXTRACT_LE_8BITS(ccmp->cc_optlen); 62217680Spst 62317680Spst switch (services & COS_MASK) { 62417680Spst case COS_NONE: 62517680Spst break; 62617680Spst case COS_SEGMENT: 62717680Spst (void)printf("seg "); 62817680Spst break; 62917680Spst case COS_MESSAGE: 63017680Spst (void)printf("msg "); 63117680Spst break; 63217680Spst case COS_CRYPTSER: 63317680Spst (void)printf("crypt "); 63417680Spst break; 63517680Spst } 63617680Spst switch (info & COI_MASK) { 63717680Spst case COI_32: 63817680Spst (void)printf("ver 3.2 "); 63917680Spst break; 64017680Spst case COI_31: 64117680Spst (void)printf("ver 3.1 "); 64217680Spst break; 64317680Spst case COI_40: 64417680Spst (void)printf("ver 4.0 "); 64517680Spst break; 64617680Spst case COI_41: 64717680Spst (void)printf("ver 4.1 "); 64817680Spst break; 64917680Spst } 65017680Spst (void)printf("segsize %d ", segsize); 65117680Spst if (optlen) { 65217680Spst (void)printf("optlen %d ", optlen); 65317680Spst#ifdef PRINT_NSPDATA 65417680Spst optlen = min(optlen, nsplen - sizeof(struct ccmsg)); 65517680Spst dp = &(nspp[sizeof(struct ccmsg)]); 65617680Spst pdata(dp, optlen); 65717680Spst#endif 65817680Spst } 65917680Spst } 66017680Spst break; 66117680Spst case MFS_DI: 66217680Spst (void)printf("disconn-initiate %d>%d ", src, dst); 66317680Spst { 66417680Spst struct dimsg *dimp = (struct dimsg *)nspp; 66517680Spst int reason; 66617680Spst u_int optlen; 66717680Spst#ifdef PRINT_NSPDATA 66817680Spst u_char *dp; 66917680Spst#endif 67017680Spst 67117680Spst reason = EXTRACT_LE_16BITS(dimp->di_reason); 67217680Spst optlen = EXTRACT_LE_8BITS(dimp->di_optlen); 67317680Spst 67417680Spst print_reason(reason); 67517680Spst if (optlen) { 67617680Spst (void)printf("optlen %d ", optlen); 67717680Spst#ifdef PRINT_NSPDATA 67817680Spst optlen = min(optlen, nsplen - sizeof(struct dimsg)); 67917680Spst dp = &(nspp[sizeof(struct dimsg)]); 68017680Spst pdata(dp, optlen); 68117680Spst#endif 68217680Spst } 68317680Spst } 68417680Spst break; 68517680Spst case MFS_DC: 68617680Spst (void)printf("disconn-confirm %d>%d ", src, dst); 68717680Spst { 68817680Spst struct dcmsg *dcmp = (struct dcmsg *)nspp; 68917680Spst int reason; 69017680Spst 69117680Spst reason = EXTRACT_LE_16BITS(dcmp->dc_reason); 69217680Spst 69317680Spst print_reason(reason); 69417680Spst } 69517680Spst break; 69617680Spst default: 69717680Spst (void)printf("reserved-ctltype? %x %d > %d", flags, src, dst); 69817680Spst break; 69917680Spst } 70017680Spst break; 70117680Spst default: 70217680Spst (void)printf("reserved-type? %x %d > %d", flags, src, dst); 70317680Spst break; 70417680Spst } 70517680Spst} 70617680Spst 70717680Spststatic struct tok reason2str[] = { 70817680Spst { UC_OBJREJECT, "object rejected connect" }, 70917680Spst { UC_RESOURCES, "insufficient resources" }, 71017680Spst { UC_NOSUCHNODE, "unrecognized node name" }, 71117680Spst { DI_SHUT, "node is shutting down" }, 71217680Spst { UC_NOSUCHOBJ, "unrecognized object" }, 71317680Spst { UC_INVOBJFORMAT, "invalid object name format" }, 71417680Spst { UC_OBJTOOBUSY, "object too busy" }, 71517680Spst { DI_PROTOCOL, "protocol error discovered" }, 71617680Spst { DI_TPA, "third party abort" }, 71717680Spst { UC_USERABORT, "user abort" }, 71817680Spst { UC_INVNODEFORMAT, "invalid node name format" }, 71917680Spst { UC_LOCALSHUT, "local node shutting down" }, 72017680Spst { DI_LOCALRESRC, "insufficient local resources" }, 72117680Spst { DI_REMUSERRESRC, "insufficient remote user resources" }, 72217680Spst { UC_ACCESSREJECT, "invalid access control information" }, 72317680Spst { DI_BADACCNT, "bad ACCOUNT information" }, 72417680Spst { UC_NORESPONSE, "no response from object" }, 72517680Spst { UC_UNREACHABLE, "node unreachable" }, 72617680Spst { DC_NOLINK, "no link terminate" }, 72717680Spst { DC_COMPLETE, "disconnect complete" }, 72817680Spst { DI_BADIMAGE, "bad image data in connect" }, 72917680Spst { DI_SERVMISMATCH, "cryptographic service mismatch" }, 73017680Spst { 0, NULL } 73117680Spst}; 73217680Spst 73317680Spststatic void 73417680Spstprint_reason(register int reason) 73517680Spst{ 73617680Spst printf("%s ", tok2str(reason2str, "reason-%d", reason)); 73717680Spst} 73817680Spst 73917680Spstchar * 74017680Spstdnnum_string(u_short dnaddr) 74117680Spst{ 74217680Spst char *str; 74326180Sfenner int area = (u_short)(dnaddr & AREAMASK) >> AREASHIFT; 74417680Spst int node = dnaddr & NODEMASK; 74517680Spst 74617680Spst str = (char *)malloc(sizeof("00.0000")); 74717680Spst if (str == NULL) 74817680Spst error("dnnum_string: malloc"); 74917680Spst sprintf(str, "%d.%d", area, node); 75017680Spst return(str); 75117680Spst} 75217680Spst 75317680Spstchar * 75417680Spstdnname_string(u_short dnaddr) 75517680Spst{ 75617680Spst#ifdef HAVE_LIBDNET 75717680Spst struct dn_naddr dna; 75817680Spst 75917680Spst dna.a_len = sizeof(short); 76017680Spst memcpy((char *)dna.a_addr, (char *)&dnaddr, sizeof(short)); 76117680Spst return (savestr(dnet_htoa(&dna))); 76217680Spst#else 76317680Spst return(dnnum_string(dnaddr)); /* punt */ 76417680Spst#endif 76517680Spst} 76617680Spst 76717680Spst#ifdef PRINT_NSPDATA 76817680Spststatic void 76917680Spstpdata(u_char *dp, u_int maxlen) 77017680Spst{ 77117680Spst char c; 77217680Spst u_int x = maxlen; 77317680Spst 77417680Spst while (x-- > 0) { 77517680Spst c = *dp++; 77617680Spst if (isprint(c)) 77717680Spst putchar(c); 77817680Spst else 77917680Spst printf("\\%o", c & 0xFF); 78017680Spst } 78117680Spst} 78217680Spst#endif 783