⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 print-isoclns.c

📁 TCPDUMP的C语言源代码,是在数据链路层的应用
💻 C
📖 第 1 页 / 共 5 页
字号:
trunctlv:    printf("%spacket exceeded snapshot",ident);    return(0);}/* * this is the common IS-REACH decoder it is called * from various EXTD-IS REACH style TLVs (22,24,222) */static intisis_print_ext_is_reach (const u_int8_t *tptr,const char *ident, int tlv_type) {    char ident_buffer[20];    int subtlv_type,subtlv_len,subtlv_sum_len;    int proc_bytes = 0; /* how many bytes did we process ? */        if (!TTEST2(*tptr, NODE_ID_LEN))        return(0);    printf("%sIS Neighbor: %s", ident, isis_print_id(tptr, NODE_ID_LEN));    tptr+=(NODE_ID_LEN);    if (tlv_type != ISIS_TLV_IS_ALIAS_ID) { /* the Alias TLV Metric field is implicit 0 */        if (!TTEST2(*tptr, 3))    /* and is therefore skipped */	    return(0);	printf(", Metric: %d",EXTRACT_24BITS(tptr));	tptr+=3;    }            if (!TTEST2(*tptr, 1))        return(0);    subtlv_sum_len=*(tptr++); /* read out subTLV length */    proc_bytes=NODE_ID_LEN+3+1;    printf(", %ssub-TLVs present",subtlv_sum_len ? "" : "no ");    if (subtlv_sum_len) {        printf(" (%u)",subtlv_sum_len);        while (subtlv_sum_len>0) {            if (!TTEST2(*tptr,2))                return(0);            subtlv_type=*(tptr++);            subtlv_len=*(tptr++);            /* prepend the ident string */            snprintf(ident_buffer, sizeof(ident_buffer), "%s  ",ident);            if(!isis_print_is_reach_subtlv(tptr,subtlv_type,subtlv_len,ident_buffer))                return(0);            tptr+=subtlv_len;            subtlv_sum_len-=(subtlv_len+2);            proc_bytes+=(subtlv_len+2);        }    }    return(proc_bytes);}/* * this is the common Multi Topology ID decoder * it is called from various MT-TLVs (222,229,235,237) */static intisis_print_mtid (const u_int8_t *tptr,const char *ident) {        if (!TTEST2(*tptr, 2))        return(0);    printf("%s%s",           ident,           tok2str(isis_mt_values,                   "Reserved for IETF Consensus",                   ISIS_MASK_MTID(EXTRACT_16BITS(tptr))));    printf(" Topology (0x%03x), Flags: [%s]",           ISIS_MASK_MTID(EXTRACT_16BITS(tptr)),           bittok2str(isis_mt_flag_values, "none",ISIS_MASK_MTFLAGS(EXTRACT_16BITS(tptr))));    return(2);}/* * this is the common extended IP reach decoder * it is called from TLVs (135,235,236,237) * we process the TLV and optional subTLVs and return * the amount of processed bytes */static intisis_print_extd_ip_reach (const u_int8_t *tptr, const char *ident, u_int16_t afi) {    char ident_buffer[20];#ifdef INET6    u_int8_t prefix[sizeof(struct in6_addr)]; /* shared copy buffer for IPv4 and IPv6 prefixes */#else    u_int8_t prefix[sizeof(struct in_addr)]; /* shared copy buffer for IPv4 prefixes */#endif    u_int metric, status_byte, bit_length, byte_length, sublen, processed, subtlvtype, subtlvlen;    if (!TTEST2(*tptr, 4))        return (0);    metric = EXTRACT_32BITS(tptr);    processed=4;    tptr+=4;        if (afi == AF_INET) {        if (!TTEST2(*tptr, 1)) /* fetch status byte */            return (0);        status_byte=*(tptr++);        bit_length = status_byte&0x3f;        if (bit_length > 32) {            printf("%sIPv4 prefix: bad bit length %u",                   ident,                   bit_length);            return (0);        }        processed++;#ifdef INET6    } else if (afi == AF_INET6) {        if (!TTEST2(*tptr, 1)) /* fetch status & prefix_len byte */            return (0);        status_byte=*(tptr++);        bit_length=*(tptr++);        if (bit_length > 128) {            printf("%sIPv6 prefix: bad bit length %u",                   ident,                   bit_length);            return (0);        }        processed+=2;#endif    } else        return (0); /* somebody is fooling us */    byte_length = (bit_length + 7) / 8; /* prefix has variable length encoding */       if (!TTEST2(*tptr, byte_length))        return (0);    memset(prefix, 0, sizeof prefix);   /* clear the copy buffer */    memcpy(prefix,tptr,byte_length);    /* copy as much as is stored in the TLV */    tptr+=byte_length;    processed+=byte_length;    if (afi == AF_INET)        printf("%sIPv4 prefix: %15s/%u",               ident,               ipaddr_string(prefix),               bit_length);#ifdef INET6    if (afi == AF_INET6)        printf("%sIPv6 prefix: %s/%u",               ident,               ip6addr_string(prefix),               bit_length);#endif        printf(", Distribution: %s, Metric: %u",           ISIS_MASK_TLV_EXTD_IP_UPDOWN(status_byte) ? "down" : "up",           metric);    if (afi == AF_INET && ISIS_MASK_TLV_EXTD_IP_SUBTLV(status_byte))        printf(", sub-TLVs present");#ifdef INET6    if (afi == AF_INET6)        printf(", %s%s",               ISIS_MASK_TLV_EXTD_IP6_IE(status_byte) ? "External" : "Internal",               ISIS_MASK_TLV_EXTD_IP6_SUBTLV(status_byte) ? ", sub-TLVs present" : "");#endif        if ((afi == AF_INET  && ISIS_MASK_TLV_EXTD_IP_SUBTLV(status_byte))#ifdef INET6     || (afi == AF_INET6 && ISIS_MASK_TLV_EXTD_IP6_SUBTLV(status_byte))#endif	) {        /* assume that one prefix can hold more           than one subTLV - therefore the first byte must reflect           the aggregate bytecount of the subTLVs for this prefix        */        if (!TTEST2(*tptr, 1))            return (0);        sublen=*(tptr++);        processed+=sublen+1;        printf(" (%u)",sublen);   /* print out subTLV length */                while (sublen>0) {            if (!TTEST2(*tptr,2))                return (0);            subtlvtype=*(tptr++);            subtlvlen=*(tptr++);            /* prepend the ident string */            snprintf(ident_buffer, sizeof(ident_buffer), "%s  ",ident);            if(!isis_print_ip_reach_subtlv(tptr,subtlvtype,subtlvlen,ident_buffer))                return(0);            tptr+=subtlvlen;            sublen-=(subtlvlen+2);        }    }    return (processed);}/* * isis_print * Decode IS-IS packets.  Return 0 on error. */static int isis_print (const u_int8_t *p, u_int length){    const struct isis_common_header *isis_header;    const struct isis_iih_lan_header *header_iih_lan;    const struct isis_iih_ptp_header *header_iih_ptp;    const struct isis_lsp_header *header_lsp;    const struct isis_csnp_header *header_csnp;    const struct isis_psnp_header *header_psnp;    const struct isis_tlv_lsp *tlv_lsp;    const struct isis_tlv_ptp_adj *tlv_ptp_adj;    const struct isis_tlv_is_reach *tlv_is_reach;    const struct isis_tlv_es_reach *tlv_es_reach;    u_int8_t pdu_type, max_area, id_length, tlv_type, tlv_len, tmp, alen, lan_alen, prefix_len;    u_int8_t ext_is_len, ext_ip_len, mt_len;    const u_int8_t *optr, *pptr, *tptr;    u_short packet_len,pdu_len;    u_int i,vendor_id;    packet_len=length;    optr = p; /* initialize the _o_riginal pointer to the packet start -                 need it for parsing the checksum TLV */    isis_header = (const struct isis_common_header *)p;    TCHECK(*isis_header);    pptr = p+(ISIS_COMMON_HEADER_SIZE);    header_iih_lan = (const struct isis_iih_lan_header *)pptr;    header_iih_ptp = (const struct isis_iih_ptp_header *)pptr;    header_lsp = (const struct isis_lsp_header *)pptr;    header_csnp = (const struct isis_csnp_header *)pptr;    header_psnp = (const struct isis_psnp_header *)pptr;    if (!eflag)        printf("IS-IS");    /*     * Sanity checking of the header.     */    if (isis_header->version != ISIS_VERSION) {	printf("version %d packet not supported", isis_header->version);	return (0);    }    if ((isis_header->id_length != SYSTEM_ID_LEN) && (isis_header->id_length != 0)) {	printf("system ID length of %d is not supported",	       isis_header->id_length);	return (0);    }    if (isis_header->pdu_version != ISIS_VERSION) {	printf("version %d packet not supported", isis_header->pdu_version);	return (0);    }    max_area = isis_header->max_area;    switch(max_area) {    case 0:	max_area = 3;	 /* silly shit */	break;    case 255:	printf("bad packet -- 255 areas");	return (0);    default:	break;    }    id_length = isis_header->id_length;    switch(id_length) {    case 0:        id_length = 6;	 /* silly shit again */	break;    case 1:              /* 1-8 are valid sys-ID lenghts */    case 2:    case 3:    case 4:    case 5:    case 6:    case 7:    case 8:        break;    case 255:        id_length = 0;   /* entirely useless */	break;    default:        break;    }    /* toss any non 6-byte sys-ID len PDUs */    if (id_length != 6 ) { 	printf("bad packet -- illegal sys-ID length (%u)", id_length);	return (0);    }    pdu_type=isis_header->pdu_type;    /* in non-verbose mode print the basic PDU Type plus PDU specific brief information*/    if (vflag < 1) {        printf("%s%s",               eflag ? "" : ", ",               tok2str(isis_pdu_values,"unknown PDU-Type %u",pdu_type));	switch (pdu_type) {	case ISIS_PDU_L1_LAN_IIH:	case ISIS_PDU_L2_LAN_IIH:	    printf(", src-id %s",                   isis_print_id(header_iih_lan->source_id,SYSTEM_ID_LEN));	    printf(", lan-id %s, prio %u",                   isis_print_id(header_iih_lan->lan_id,NODE_ID_LEN),                   header_iih_lan->priority);	    break;	case ISIS_PDU_PTP_IIH:	    printf(", src-id %s", isis_print_id(header_iih_ptp->source_id,SYSTEM_ID_LEN));	    break;	case ISIS_PDU_L1_LSP:	case ISIS_PDU_L2_LSP:	    printf(", lsp-id %s, seq 0x%08x, lifetime %5us",		   isis_print_id(header_lsp->lsp_id, LSP_ID_LEN),		   EXTRACT_32BITS(header_lsp->sequence_number),		   EXTRACT_16BITS(header_lsp->remaining_lifetime));	    break;	case ISIS_PDU_L1_CSNP:	case ISIS_PDU_L2_CSNP:	    printf(", src-id %s", isis_print_id(header_csnp->source_id,NODE_ID_LEN));	    break;	case ISIS_PDU_L1_PSNP:	case ISIS_PDU_L2_PSNP:	    printf(", src-id %s", isis_print_id(header_psnp->source_id,NODE_ID_LEN));	    break;	}	printf(", length %u", length);        return(1);    }    /* ok they seem to want to know everything - lets fully decode it */    printf("%slength %u", eflag ? "" : ", ",length);    printf("\n\t%s, hlen: %u, v: %u, pdu-v: %u, sys-id-len: %u (%u), max-area: %u (%u)",           tok2str(isis_pdu_values,                   "unknown, type %u",                   pdu_type),           isis_header->fixed_len,           isis_header->version,           isis_header->pdu_version,	   id_length,	   isis_header->id_length,           max_area,           isis_header->max_area);    if (vflag > 1) {        if(!print_unknown_data(optr,"\n\t",8)) /* provide the _o_riginal pointer */            return(0);                         /* for optionally debugging the common header */    }    switch (pdu_type) {    case ISIS_PDU_L1_LAN_IIH:    case ISIS_PDU_L2_LAN_IIH:	if (isis_header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE)) {	    printf(", bogus fixed header length %u should be %lu",		   isis_header->fixed_len, (unsigned long)ISIS_IIH_LAN_HEADER_SIZE);	    return (0);	}	pdu_len=EXTRACT_16BITS(header_iih_lan->pdu_len);	if (packet_len>pdu_len) {            packet_len=pdu_len; /* do TLV decoding as long as it makes sense */            length=pdu_len;	}	TCHECK(*header_iih_lan);	printf("\n\t  source-id: %s,  holding time: %us, Flags: [%s]",               isis_print_id(header_iih_lan->source_id,SYSTEM_ID_LEN),               EXTRACT_16BITS(header_iih_lan->holding_time),               tok2str(isis_iih_circuit_type_values,                       "unknown circuit type 0x%02x",                       header_iih_lan->circuit_type));	printf("\n\t  lan-id:    %s

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -