tcpdump-4.9.3/0000755000026300017510000000000013544415543011336 5ustar mcrmcrtcpdump-4.9.3/mib.h0000644000026300017510000006452313544412561012265 0ustar mcrmcr/* * This file was generated by tcpdump/makemib on Wed Sep 26 12:12:31 EDT 1990 * You probably don't want to edit this by hand! * * struct mib somename = { desc, oid-octet, type, child-pointer, next-pointer }; */ /* parse problem: new name "mib" for mgmt.mib(1) ignored */ /* parse problem: no parent for 0.nullSpecific(0) */ static struct obj _proteon_obj = { "proteon", 1, 0, NULL, NULL }, _ibm_obj = { "ibm", 2, 0, NULL, &_proteon_obj }, _cmu_obj = { "cmu", 3, 0, NULL, &_ibm_obj }, _unix_obj = { "unix", 4, 0, NULL, &_cmu_obj }, _acc_obj = { "acc", 5, 0, NULL, &_unix_obj }, _twg_obj = { "twg", 6, 0, NULL, &_acc_obj }, _cayman_obj = { "cayman", 7, 0, NULL, &_twg_obj }, _nysernet_obj = { "nysernet", 8, 0, NULL, &_cayman_obj }, _cisco_obj = { "cisco", 9, 0, NULL, &_nysernet_obj }, _nsc_obj = { "nsc", 10, 0, NULL, &_cisco_obj }, _hp_obj = { "hp", 11, 0, NULL, &_nsc_obj }, _epilogue_obj = { "epilogue", 12, 0, NULL, &_hp_obj }, _utennessee_obj = { "utennessee", 13, 0, NULL, &_epilogue_obj }, _bbn_obj = { "bbn", 14, 0, NULL, &_utennessee_obj }, _xylogics_obj = { "xylogics", 15, 0, NULL, &_bbn_obj }, _unisys_obj = { "unisys", 16, 0, NULL, &_xylogics_obj }, _canstar_obj = { "canstar", 17, 0, NULL, &_unisys_obj }, _wellfleet_obj = { "wellfleet", 18, 0, NULL, &_canstar_obj }, _trw_obj = { "trw", 19, 0, NULL, &_wellfleet_obj }, _mit_obj = { "mit", 20, 0, NULL, &_trw_obj }, _eon_obj = { "eon", 21, 0, NULL, &_mit_obj }, _spartacus_obj = { "spartacus", 22, 0, NULL, &_eon_obj }, _excelan_obj = { "excelan", 23, 0, NULL, &_spartacus_obj }, _spider_obj = { "spider", 24, 0, NULL, &_excelan_obj }, _nsfnet_obj = { "nsfnet", 25, 0, NULL, &_spider_obj }, _sytek_obj = { "sytek", 26, 0, NULL, &_nsfnet_obj }, _intergraph_obj = { "intergraph", 27, 0, NULL, &_sytek_obj }, _interlan_obj = { "interlan", 28, 0, NULL, &_intergraph_obj }, _vitalink_obj = { "vitalink", 29, 0, NULL, &_interlan_obj }, _ulana_obj = { "ulana", 30, 0, NULL, &_vitalink_obj }, _nswc_obj = { "nswc", 31, 0, NULL, &_ulana_obj }, _santacruzoperation_obj = { "santacruzoperation", 32, 0, NULL, &_nswc_obj }, _xyplex_obj = { "xyplex", 33, 0, NULL, &_santacruzoperation_obj }, _cray_obj = { "cray", 34, 0, NULL, &_xyplex_obj }, _bellnorthernresearch_obj = { "bellnorthernresearch", 35, 0, NULL, &_cray_obj }, _dec_obj = { "dec", 36, 0, NULL, &_bellnorthernresearch_obj }, _touch_obj = { "touch", 37, 0, NULL, &_dec_obj }, _networkresearchcorp_obj = { "networkresearchcorp", 38, 0, NULL, &_touch_obj }, _baylor_obj = { "baylor", 39, 0, NULL, &_networkresearchcorp_obj }, _nmfeccllnl_obj = { "nmfeccllnl", 40, 0, NULL, &_baylor_obj }, _sri_obj = { "sri", 41, 0, NULL, &_nmfeccllnl_obj }, _sun_obj = { "sun", 42, 0, NULL, &_sri_obj }, _3com_obj = { "3com", 43, 0, NULL, &_sun_obj }, _cmc_obj = { "cmc", 44, 0, NULL, &_3com_obj }, _synoptics_obj = { "synoptics", 45, 0, NULL, &_cmc_obj }, _cheyenne_obj = { "cheyenne", 46, 0, NULL, &_synoptics_obj }, _prime_obj = { "prime", 47, 0, NULL, &_cheyenne_obj }, _mcnc_obj = { "mcnc", 48, 0, NULL, &_prime_obj }, _chipcom_obj = { "chipcom", 49, 0, NULL, &_mcnc_obj }, _opticaldatasystems_obj = { "opticaldatasystems", 50, 0, NULL, &_chipcom_obj }, _gated_obj = { "gated", 51, 0, NULL, &_opticaldatasystems_obj }, _cabletron_obj = { "cabletron", 52, 0, NULL, &_gated_obj }, _apollo_obj = { "apollo", 53, 0, NULL, &_cabletron_obj }, _desktalksystems_obj = { "desktalksystems", 54, 0, NULL, &_apollo_obj }, _ssds_obj = { "ssds", 55, 0, NULL, &_desktalksystems_obj }, _castlerock_obj = { "castlerock", 56, 0, NULL, &_ssds_obj }, _mips_obj = { "mips", 57, 0, NULL, &_castlerock_obj }, _tgv_obj = { "tgv", 58, 0, NULL, &_mips_obj }, _silicongraphics_obj = { "silicongraphics", 59, 0, NULL, &_tgv_obj }, _ubc_obj = { "ubc", 60, 0, NULL, &_silicongraphics_obj }, _merit_obj = { "merit", 61, 0, NULL, &_ubc_obj }, _fibercom_obj = { "fibercom", 62, 0, NULL, &_merit_obj }, _apple_obj = { "apple", 63, 0, NULL, &_fibercom_obj }, _gandalf_obj = { "gandalf", 64, 0, NULL, &_apple_obj }, _dartmouth_obj = { "dartmouth", 65, 0, NULL, &_gandalf_obj }, _davidsystems_obj = { "davidsystems", 66, 0, NULL, &_dartmouth_obj }, _reuter_obj = { "reuter", 67, 0, NULL, &_davidsystems_obj }, _cornell_obj = { "cornell", 68, 0, NULL, &_reuter_obj }, _tmac_obj = { "tmac", 69, 0, NULL, &_cornell_obj }, _locus_obj = { "locus", 70, 0, NULL, &_tmac_obj }, _nasa_obj = { "nasa", 71, 0, NULL, &_locus_obj }, _retix_obj = { "retix", 72, 0, NULL, &_nasa_obj }, _boeing_obj = { "boeing", 73, 0, NULL, &_retix_obj }, _att_obj = { "att", 74, 0, NULL, &_boeing_obj }, _ungermannbass_obj = { "ungermannbass", 75, 0, NULL, &_att_obj }, _digitalanalysis_obj = { "digitalanalysis", 76, 0, NULL, &_ungermannbass_obj }, _hplanman_obj = { "hplanman", 77, 0, NULL, &_digitalanalysis_obj }, _netlabs_obj = { "netlabs", 78, 0, NULL, &_hplanman_obj }, _icl_obj = { "icl", 79, 0, NULL, &_netlabs_obj }, _auspex_obj = { "auspex", 80, 0, NULL, &_icl_obj }, _lannet_obj = { "lannet", 81, 0, NULL, &_auspex_obj }, _ncd_obj = { "ncd", 82, 0, NULL, &_lannet_obj }, _raycom_obj = { "raycom", 83, 0, NULL, &_ncd_obj }, _pirellifocom_obj = { "pirellifocom", 84, 0, NULL, &_raycom_obj }, _datability_obj = { "datability", 85, 0, NULL, &_pirellifocom_obj }, _networkappltech_obj = { "networkappltech", 86, 0, NULL, &_datability_obj }, _link_obj = { "link", 87, 0, NULL, &_networkappltech_obj }, _nyu_obj = { "nyu", 88, 0, NULL, &_link_obj }, _rnd_obj = { "rnd", 89, 0, NULL, &_nyu_obj }, _intercon_obj = { "intercon", 90, 0, NULL, &_rnd_obj }, _learningtree_obj = { "learningtree", 91, 0, NULL, &_intercon_obj }, _webstercomputer_obj = { "webstercomputer", 92, 0, NULL, &_learningtree_obj }, _frontier_obj = { "frontier", 93, 0, NULL, &_webstercomputer_obj }, _nokia_obj = { "nokia", 94, 0, NULL, &_frontier_obj }, _allenbradley_obj = { "allenbradley", 95, 0, NULL, &_nokia_obj }, _cern_obj = { "cern", 96, 0, NULL, &_allenbradley_obj }, _sigma_obj = { "sigma", 97, 0, NULL, &_cern_obj }, _emergingtech_obj = { "emergingtech", 98, 0, NULL, &_sigma_obj }, _snmpresearch_obj = { "snmpresearch", 99, 0, NULL, &_emergingtech_obj }, _ohiostate_obj = { "ohiostate", 100, 0, NULL, &_snmpresearch_obj }, _ultra_obj = { "ultra", 101, 0, NULL, &_ohiostate_obj }, _ccur_obj = { "ccur", 136, 0, NULL, &_ultra_obj }, _enterprises_obj = { "enterprises", 1, 0, &_ccur_obj, NULL }, _snmpInPkts_obj = { "snmpInPkts", 1, 0, NULL, NULL }, _snmpOutPkts_obj = { "snmpOutPkts", 2, 0, NULL, &_snmpInPkts_obj }, _snmpInBadVersions_obj = { "snmpInBadVersions", 3, 0, NULL, &_snmpOutPkts_obj }, _snmpInBadCommunityNames_obj = { "snmpInBadCommunityNames", 4, 0, NULL, &_snmpInBadVersions_obj }, _snmpInBadCommunityUses_obj = { "snmpInBadCommunityUses", 5, 0, NULL, &_snmpInBadCommunityNames_obj }, _snmpInASNParseErrs_obj = { "snmpInASNParseErrs", 6, 0, NULL, &_snmpInBadCommunityUses_obj }, _snmpInBadTypes_obj = { "snmpInBadTypes", 7, 0, NULL, &_snmpInASNParseErrs_obj }, _snmpInTooBigs_obj = { "snmpInTooBigs", 8, 0, NULL, &_snmpInBadTypes_obj }, _snmpInNoSuchNames_obj = { "snmpInNoSuchNames", 9, 0, NULL, &_snmpInTooBigs_obj }, _snmpInBadValues_obj = { "snmpInBadValues", 10, 0, NULL, &_snmpInNoSuchNames_obj }, _snmpInReadOnlys_obj = { "snmpInReadOnlys", 11, 0, NULL, &_snmpInBadValues_obj }, _snmpInGenErrs_obj = { "snmpInGenErrs", 12, 0, NULL, &_snmpInReadOnlys_obj }, _snmpInTotalReqVars_obj = { "snmpInTotalReqVars", 13, 0, NULL, &_snmpInGenErrs_obj }, _snmpInTotalSetVars_obj = { "snmpInTotalSetVars", 14, 0, NULL, &_snmpInTotalReqVars_obj }, _snmpInGetRequests_obj = { "snmpInGetRequests", 15, 0, NULL, &_snmpInTotalSetVars_obj }, _snmpInGetNexts_obj = { "snmpInGetNexts", 16, 0, NULL, &_snmpInGetRequests_obj }, _snmpInSetRequests_obj = { "snmpInSetRequests", 17, 0, NULL, &_snmpInGetNexts_obj }, _snmpInGetResponses_obj = { "snmpInGetResponses", 18, 0, NULL, &_snmpInSetRequests_obj }, _snmpInTraps_obj = { "snmpInTraps", 19, 0, NULL, &_snmpInGetResponses_obj }, _snmpOutTooBigs_obj = { "snmpOutTooBigs", 20, 0, NULL, &_snmpInTraps_obj }, _snmpOutNoSuchNames_obj = { "snmpOutNoSuchNames", 21, 0, NULL, &_snmpOutTooBigs_obj }, _snmpOutBadValues_obj = { "snmpOutBadValues", 22, 0, NULL, &_snmpOutNoSuchNames_obj }, _snmpOutReadOnlys_obj = { "snmpOutReadOnlys", 23, 0, NULL, &_snmpOutBadValues_obj }, _snmpOutGenErrs_obj = { "snmpOutGenErrs", 24, 0, NULL, &_snmpOutReadOnlys_obj }, _snmpOutGetRequests_obj = { "snmpOutGetRequests", 25, 0, NULL, &_snmpOutGenErrs_obj }, _snmpOutGetNexts_obj = { "snmpOutGetNexts", 26, 0, NULL, &_snmpOutGetRequests_obj }, _snmpOutSetRequests_obj = { "snmpOutSetRequests", 27, 0, NULL, &_snmpOutGetNexts_obj }, _snmpOutGetResponses_obj = { "snmpOutGetResponses", 28, 0, NULL, &_snmpOutSetRequests_obj }, _snmpOutTraps_obj = { "snmpOutTraps", 29, 0, NULL, &_snmpOutGetResponses_obj }, _snmpEnableAuthTraps_obj = { "snmpEnableAuthTraps", 30, 0, NULL, &_snmpOutTraps_obj }, _egpNeighState_obj = { "egpNeighState", 1, 0, NULL, NULL }, _egpNeighAddr_obj = { "egpNeighAddr", 2, 0, NULL, &_egpNeighState_obj }, _egpNeighAs_obj = { "egpNeighAs", 3, 0, NULL, &_egpNeighAddr_obj }, _egpNeighInMsgs_obj = { "egpNeighInMsgs", 4, 0, NULL, &_egpNeighAs_obj }, _egpNeighInErrs_obj = { "egpNeighInErrs", 5, 0, NULL, &_egpNeighInMsgs_obj }, _egpNeighOutMsgs_obj = { "egpNeighOutMsgs", 6, 0, NULL, &_egpNeighInErrs_obj }, _egpNeighOutErrs_obj = { "egpNeighOutErrs", 7, 0, NULL, &_egpNeighOutMsgs_obj }, _egpNeighInErrMsgs_obj = { "egpNeighInErrMsgs", 8, 0, NULL, &_egpNeighOutErrs_obj }, _egpNeighOutErrMsgs_obj = { "egpNeighOutErrMsgs", 9, 0, NULL, &_egpNeighInErrMsgs_obj }, _egpNeighStateUps_obj = { "egpNeighStateUps", 10, 0, NULL, &_egpNeighOutErrMsgs_obj }, _egpNeighStateDowns_obj = { "egpNeighStateDowns", 11, 0, NULL, &_egpNeighStateUps_obj }, _egpNeighIntervalHello_obj = { "egpNeighIntervalHello", 12, 0, NULL, &_egpNeighStateDowns_obj }, _egpNeighIntervalPoll_obj = { "egpNeighIntervalPoll", 13, 0, NULL, &_egpNeighIntervalHello_obj }, _egpNeighMode_obj = { "egpNeighMode", 14, 0, NULL, &_egpNeighIntervalPoll_obj }, _egpNeighEventTrigger_obj = { "egpNeighEventTrigger", 15, 0, NULL, &_egpNeighMode_obj }, _egpNeighEntry_obj = { "egpNeighEntry", 1, 0, &_egpNeighEventTrigger_obj, NULL }, _egpInMsgs_obj = { "egpInMsgs", 1, 0, NULL, NULL }, _egpInErrors_obj = { "egpInErrors", 2, 0, NULL, &_egpInMsgs_obj }, _egpOutMsgs_obj = { "egpOutMsgs", 3, 0, NULL, &_egpInErrors_obj }, _egpOutErrors_obj = { "egpOutErrors", 4, 0, NULL, &_egpOutMsgs_obj }, _egpNeighTable_obj = { "egpNeighTable", 5, 0, &_egpNeighEntry_obj, &_egpOutErrors_obj }, _egpAs_obj = { "egpAs", 6, 0, NULL, &_egpNeighTable_obj }, _udpLocalAddress_obj = { "udpLocalAddress", 1, 0, NULL, NULL }, _udpLocalPort_obj = { "udpLocalPort", 2, 0, NULL, &_udpLocalAddress_obj }, _udpEntry_obj = { "udpEntry", 1, 0, &_udpLocalPort_obj, NULL }, _udpInDatagrams_obj = { "udpInDatagrams", 1, 0, NULL, NULL }, _udpNoPorts_obj = { "udpNoPorts", 2, 0, NULL, &_udpInDatagrams_obj }, _udpInErrors_obj = { "udpInErrors", 3, 0, NULL, &_udpNoPorts_obj }, _udpOutDatagrams_obj = { "udpOutDatagrams", 4, 0, NULL, &_udpInErrors_obj }, _udpTable_obj = { "udpTable", 5, 0, &_udpEntry_obj, &_udpOutDatagrams_obj }, _tcpConnState_obj = { "tcpConnState", 1, 0, NULL, NULL }, _tcpConnLocalAddress_obj = { "tcpConnLocalAddress", 2, 0, NULL, &_tcpConnState_obj }, _tcpConnLocalPort_obj = { "tcpConnLocalPort", 3, 0, NULL, &_tcpConnLocalAddress_obj }, _tcpConnRemAddress_obj = { "tcpConnRemAddress", 4, 0, NULL, &_tcpConnLocalPort_obj }, _tcpConnRemPort_obj = { "tcpConnRemPort", 5, 0, NULL, &_tcpConnRemAddress_obj }, _tcpConnEntry_obj = { "tcpConnEntry", 1, 0, &_tcpConnRemPort_obj, NULL }, _tcpRtoAlgorithm_obj = { "tcpRtoAlgorithm", 1, 0, NULL, NULL }, _tcpRtoMin_obj = { "tcpRtoMin", 2, 0, NULL, &_tcpRtoAlgorithm_obj }, _tcpRtoMax_obj = { "tcpRtoMax", 3, 0, NULL, &_tcpRtoMin_obj }, _tcpMaxConn_obj = { "tcpMaxConn", 4, 0, NULL, &_tcpRtoMax_obj }, _tcpActiveOpens_obj = { "tcpActiveOpens", 5, 0, NULL, &_tcpMaxConn_obj }, _tcpPassiveOpens_obj = { "tcpPassiveOpens", 6, 0, NULL, &_tcpActiveOpens_obj }, _tcpAttemptFails_obj = { "tcpAttemptFails", 7, 0, NULL, &_tcpPassiveOpens_obj }, _tcpEstabResets_obj = { "tcpEstabResets", 8, 0, NULL, &_tcpAttemptFails_obj }, _tcpCurrEstab_obj = { "tcpCurrEstab", 9, 0, NULL, &_tcpEstabResets_obj }, _tcpInSegs_obj = { "tcpInSegs", 10, 0, NULL, &_tcpCurrEstab_obj }, _tcpOutSegs_obj = { "tcpOutSegs", 11, 0, NULL, &_tcpInSegs_obj }, _tcpRetransSegs_obj = { "tcpRetransSegs", 12, 0, NULL, &_tcpOutSegs_obj }, _tcpConnTable_obj = { "tcpConnTable", 13, 0, &_tcpConnEntry_obj, &_tcpRetransSegs_obj }, _tcpInErrs_obj = { "tcpInErrs", 14, 0, NULL, &_tcpConnTable_obj }, _tcpOutRsts_obj = { "tcpOutRsts", 15, 0, NULL, &_tcpInErrs_obj }, _icmpInMsgs_obj = { "icmpInMsgs", 1, 0, NULL, NULL }, _icmpInErrors_obj = { "icmpInErrors", 2, 0, NULL, &_icmpInMsgs_obj }, _icmpInDestUnreachs_obj = { "icmpInDestUnreachs", 3, 0, NULL, &_icmpInErrors_obj }, _icmpInTimeExcds_obj = { "icmpInTimeExcds", 4, 0, NULL, &_icmpInDestUnreachs_obj }, _icmpInParmProbs_obj = { "icmpInParmProbs", 5, 0, NULL, &_icmpInTimeExcds_obj }, _icmpInSrcQuenchs_obj = { "icmpInSrcQuenchs", 6, 0, NULL, &_icmpInParmProbs_obj }, _icmpInRedirects_obj = { "icmpInRedirects", 7, 0, NULL, &_icmpInSrcQuenchs_obj }, _icmpInEchos_obj = { "icmpInEchos", 8, 0, NULL, &_icmpInRedirects_obj }, _icmpInEchoReps_obj = { "icmpInEchoReps", 9, 0, NULL, &_icmpInEchos_obj }, _icmpInTimestamps_obj = { "icmpInTimestamps", 10, 0, NULL, &_icmpInEchoReps_obj }, _icmpInTimestampReps_obj = { "icmpInTimestampReps", 11, 0, NULL, &_icmpInTimestamps_obj }, _icmpInAddrMasks_obj = { "icmpInAddrMasks", 12, 0, NULL, &_icmpInTimestampReps_obj }, _icmpInAddrMaskReps_obj = { "icmpInAddrMaskReps", 13, 0, NULL, &_icmpInAddrMasks_obj }, _icmpOutMsgs_obj = { "icmpOutMsgs", 14, 0, NULL, &_icmpInAddrMaskReps_obj }, _icmpOutErrors_obj = { "icmpOutErrors", 15, 0, NULL, &_icmpOutMsgs_obj }, _icmpOutDestUnreachs_obj = { "icmpOutDestUnreachs", 16, 0, NULL, &_icmpOutErrors_obj }, _icmpOutTimeExcds_obj = { "icmpOutTimeExcds", 17, 0, NULL, &_icmpOutDestUnreachs_obj }, _icmpOutParmProbs_obj = { "icmpOutParmProbs", 18, 0, NULL, &_icmpOutTimeExcds_obj }, _icmpOutSrcQuenchs_obj = { "icmpOutSrcQuenchs", 19, 0, NULL, &_icmpOutParmProbs_obj }, _icmpOutRedirects_obj = { "icmpOutRedirects", 20, 0, NULL, &_icmpOutSrcQuenchs_obj }, _icmpOutEchos_obj = { "icmpOutEchos", 21, 0, NULL, &_icmpOutRedirects_obj }, _icmpOutEchoReps_obj = { "icmpOutEchoReps", 22, 0, NULL, &_icmpOutEchos_obj }, _icmpOutTimestamps_obj = { "icmpOutTimestamps", 23, 0, NULL, &_icmpOutEchoReps_obj }, _icmpOutTimestampReps_obj = { "icmpOutTimestampReps", 24, 0, NULL, &_icmpOutTimestamps_obj }, _icmpOutAddrMasks_obj = { "icmpOutAddrMasks", 25, 0, NULL, &_icmpOutTimestampReps_obj }, _icmpOutAddrMaskReps_obj = { "icmpOutAddrMaskReps", 26, 0, NULL, &_icmpOutAddrMasks_obj }, _ipNetToMediaIfIndex_obj = { "ipNetToMediaIfIndex", 1, 0, NULL, NULL }, _ipNetToMediaPhysAddress_obj = { "ipNetToMediaPhysAddress", 2, 0, NULL, &_ipNetToMediaIfIndex_obj }, _ipNetToMediaNetAddress_obj = { "ipNetToMediaNetAddress", 3, 0, NULL, &_ipNetToMediaPhysAddress_obj }, _ipNetToMediaType_obj = { "ipNetToMediaType", 4, 0, NULL, &_ipNetToMediaNetAddress_obj }, _ipNetToMediaEntry_obj = { "ipNetToMediaEntry", 1, 0, &_ipNetToMediaType_obj, NULL }, _ipRouteDest_obj = { "ipRouteDest", 1, 0, NULL, NULL }, _ipRouteIfIndex_obj = { "ipRouteIfIndex", 2, 0, NULL, &_ipRouteDest_obj }, _ipRouteMetric1_obj = { "ipRouteMetric1", 3, 0, NULL, &_ipRouteIfIndex_obj }, _ipRouteMetric2_obj = { "ipRouteMetric2", 4, 0, NULL, &_ipRouteMetric1_obj }, _ipRouteMetric3_obj = { "ipRouteMetric3", 5, 0, NULL, &_ipRouteMetric2_obj }, _ipRouteMetric4_obj = { "ipRouteMetric4", 6, 0, NULL, &_ipRouteMetric3_obj }, _ipRouteNextHop_obj = { "ipRouteNextHop", 7, 0, NULL, &_ipRouteMetric4_obj }, _ipRouteType_obj = { "ipRouteType", 8, 0, NULL, &_ipRouteNextHop_obj }, _ipRouteProto_obj = { "ipRouteProto", 9, 0, NULL, &_ipRouteType_obj }, _ipRouteAge_obj = { "ipRouteAge", 10, 0, NULL, &_ipRouteProto_obj }, _ipRouteMask_obj = { "ipRouteMask", 11, 0, NULL, &_ipRouteAge_obj }, _ipRouteEntry_obj = { "ipRouteEntry", 1, 0, &_ipRouteMask_obj, NULL }, _ipAdEntAddr_obj = { "ipAdEntAddr", 1, 0, NULL, NULL }, _ipAdEntIfIndex_obj = { "ipAdEntIfIndex", 2, 0, NULL, &_ipAdEntAddr_obj }, _ipAdEntNetMask_obj = { "ipAdEntNetMask", 3, 0, NULL, &_ipAdEntIfIndex_obj }, _ipAdEntBcastAddr_obj = { "ipAdEntBcastAddr", 4, 0, NULL, &_ipAdEntNetMask_obj }, _ipAdEntReasmMaxSize_obj = { "ipAdEntReasmMaxSize", 5, 0, NULL, &_ipAdEntBcastAddr_obj }, _ipAddrEntry_obj = { "ipAddrEntry", 1, 0, &_ipAdEntReasmMaxSize_obj, NULL }, _ipForwarding_obj = { "ipForwarding", 1, 0, NULL, NULL }, _ipDefaultTTL_obj = { "ipDefaultTTL", 2, 0, NULL, &_ipForwarding_obj }, _ipInReceives_obj = { "ipInReceives", 3, 0, NULL, &_ipDefaultTTL_obj }, _ipInHdrErrors_obj = { "ipInHdrErrors", 4, 0, NULL, &_ipInReceives_obj }, _ipInAddrErrors_obj = { "ipInAddrErrors", 5, 0, NULL, &_ipInHdrErrors_obj }, _ipForwDatagrams_obj = { "ipForwDatagrams", 6, 0, NULL, &_ipInAddrErrors_obj }, _ipInUnknownProtos_obj = { "ipInUnknownProtos", 7, 0, NULL, &_ipForwDatagrams_obj }, _ipInDiscards_obj = { "ipInDiscards", 8, 0, NULL, &_ipInUnknownProtos_obj }, _ipInDelivers_obj = { "ipInDelivers", 9, 0, NULL, &_ipInDiscards_obj }, _ipOutRequests_obj = { "ipOutRequests", 10, 0, NULL, &_ipInDelivers_obj }, _ipOutDiscards_obj = { "ipOutDiscards", 11, 0, NULL, &_ipOutRequests_obj }, _ipOutNoRoutes_obj = { "ipOutNoRoutes", 12, 0, NULL, &_ipOutDiscards_obj }, _ipReasmTimeout_obj = { "ipReasmTimeout", 13, 0, NULL, &_ipOutNoRoutes_obj }, _ipReasmReqds_obj = { "ipReasmReqds", 14, 0, NULL, &_ipReasmTimeout_obj }, _ipReasmOKs_obj = { "ipReasmOKs", 15, 0, NULL, &_ipReasmReqds_obj }, _ipReasmFails_obj = { "ipReasmFails", 16, 0, NULL, &_ipReasmOKs_obj }, _ipFragOKs_obj = { "ipFragOKs", 17, 0, NULL, &_ipReasmFails_obj }, _ipFragFails_obj = { "ipFragFails", 18, 0, NULL, &_ipFragOKs_obj }, _ipFragCreates_obj = { "ipFragCreates", 19, 0, NULL, &_ipFragFails_obj }, _ipAddrTable_obj = { "ipAddrTable", 20, 0, &_ipAddrEntry_obj, &_ipFragCreates_obj }, _ipRoutingTable_obj = { "ipRoutingTable", 21, 0, &_ipRouteEntry_obj, &_ipAddrTable_obj }, _ipNetToMediaTable_obj = { "ipNetToMediaTable", 22, 0, &_ipNetToMediaEntry_obj, &_ipRoutingTable_obj }, _atIfIndex_obj = { "atIfIndex", 1, 0, NULL, NULL }, _atPhysAddress_obj = { "atPhysAddress", 2, 0, NULL, &_atIfIndex_obj }, _atNetAddress_obj = { "atNetAddress", 3, 0, NULL, &_atPhysAddress_obj }, _atEntry_obj = { "atEntry", 1, 0, &_atNetAddress_obj, NULL }, _atTable_obj = { "atTable", 1, 0, &_atEntry_obj, NULL }, _ifIndex_obj = { "ifIndex", 1, 0, NULL, NULL }, _ifDescr_obj = { "ifDescr", 2, 0, NULL, &_ifIndex_obj }, _ifType_obj = { "ifType", 3, 0, NULL, &_ifDescr_obj }, _ifMtu_obj = { "ifMtu", 4, 0, NULL, &_ifType_obj }, _ifSpeed_obj = { "ifSpeed", 5, 0, NULL, &_ifMtu_obj }, _ifPhysAddress_obj = { "ifPhysAddress", 6, 0, NULL, &_ifSpeed_obj }, _ifAdminStatus_obj = { "ifAdminStatus", 7, 0, NULL, &_ifPhysAddress_obj }, _ifOperStatus_obj = { "ifOperStatus", 8, 0, NULL, &_ifAdminStatus_obj }, _ifLastChange_obj = { "ifLastChange", 9, 0, NULL, &_ifOperStatus_obj }, _ifInOctets_obj = { "ifInOctets", 10, 0, NULL, &_ifLastChange_obj }, _ifInUcastPkts_obj = { "ifInUcastPkts", 11, 0, NULL, &_ifInOctets_obj }, _ifInNUcastPkts_obj = { "ifInNUcastPkts", 12, 0, NULL, &_ifInUcastPkts_obj }, _ifInDiscards_obj = { "ifInDiscards", 13, 0, NULL, &_ifInNUcastPkts_obj }, _ifInErrors_obj = { "ifInErrors", 14, 0, NULL, &_ifInDiscards_obj }, _ifInUnknownProtos_obj = { "ifInUnknownProtos", 15, 0, NULL, &_ifInErrors_obj }, _ifOutOctets_obj = { "ifOutOctets", 16, 0, NULL, &_ifInUnknownProtos_obj }, _ifOutUcastPkts_obj = { "ifOutUcastPkts", 17, 0, NULL, &_ifOutOctets_obj }, _ifOutNUcastPkts_obj = { "ifOutNUcastPkts", 18, 0, NULL, &_ifOutUcastPkts_obj }, _ifOutDiscards_obj = { "ifOutDiscards", 19, 0, NULL, &_ifOutNUcastPkts_obj }, _ifOutErrors_obj = { "ifOutErrors", 20, 0, NULL, &_ifOutDiscards_obj }, _ifOutQLen_obj = { "ifOutQLen", 21, 0, NULL, &_ifOutErrors_obj }, _ifSpecific_obj = { "ifSpecific", 22, 0, NULL, &_ifOutQLen_obj }, _ifEntry_obj = { "ifEntry", 1, 0, &_ifSpecific_obj, NULL }, _ifNumber_obj = { "ifNumber", 1, 0, NULL, NULL }, _ifTable_obj = { "ifTable", 2, 0, &_ifEntry_obj, &_ifNumber_obj }, _sysDescr_obj = { "sysDescr", 1, 0, NULL, NULL }, _sysObjectID_obj = { "sysObjectID", 2, 0, NULL, &_sysDescr_obj }, _sysUpTime_obj = { "sysUpTime", 3, 0, NULL, &_sysObjectID_obj }, _sysContact_obj = { "sysContact", 4, 0, NULL, &_sysUpTime_obj }, _sysName_obj = { "sysName", 5, 0, NULL, &_sysContact_obj }, _sysLocation_obj = { "sysLocation", 6, 0, NULL, &_sysName_obj }, _sysServices_obj = { "sysServices", 7, 0, NULL, &_sysLocation_obj }, _system_obj = { "system", 1, 0, &_sysServices_obj, NULL }, _interfaces_obj = { "interfaces", 2, 0, &_ifTable_obj, &_system_obj }, _at_obj = { "at", 3, 0, &_atTable_obj, &_interfaces_obj }, _ip_obj = { "ip", 4, 0, &_ipNetToMediaTable_obj, &_at_obj }, _icmp_obj = { "icmp", 5, 0, &_icmpOutAddrMaskReps_obj, &_ip_obj }, _tcp_obj = { "tcp", 6, 0, &_tcpOutRsts_obj, &_icmp_obj }, _udp_obj = { "udp", 7, 0, &_udpTable_obj, &_tcp_obj }, _egp_obj = { "egp", 8, 0, &_egpAs_obj, &_udp_obj }, _transmission_obj = { "transmission", 10, 0, NULL, &_egp_obj }, _snmp_obj = { "snmp", 11, 0, &_snmpEnableAuthTraps_obj, &_transmission_obj }, _usmMIBCompliances_obj = { "usmMIBCompliances", 1, 0, NULL, NULL }, _usmMIBGroups_obj = { "usmMIBGroups", 2, 0, NULL, &_usmMIBCompliances_obj }, _usmUserEngineID_obj = { "usmUserEngineID", 1, 0, NULL, NULL }, _usmUserName_obj = { "usmUserName", 2, 0, NULL, &_usmUserEngineID_obj }, _usmUserSecurityName_obj = { "usmUserSecurityName", 3, 0, NULL, &_usmUserName_obj }, _usmUserCloneFrom_obj = { "usmUserCloneFrom", 4, 0, NULL, &_usmUserSecurityName_obj }, _usmUserAuthProtocol_obj = { "usmUserAuthProtocol", 5, 0, NULL, &_usmUserCloneFrom_obj }, _usmUserAuthKeyChange_obj = { "usmUserAuthKeyChange", 6, 0, NULL, &_usmUserAuthProtocol_obj }, _usmUserOwnAuthKeyChange_obj = { "usmUserOwnAuthKeyChange", 7, 0, NULL, &_usmUserAuthKeyChange_obj }, _usmUserPrivProtocol_obj = { "usmUserPrivProtocol", 8, 0, NULL, &_usmUserOwnAuthKeyChange_obj }, _usmUserPrivKeyChange_obj = { "usmUserPrivKeyChange", 9, 0, NULL, &_usmUserPrivProtocol_obj }, _usmUserOwnPrivKeyChange_obj = { "usmUserOwnPrivKeyChange", 10, 0, NULL, &_usmUserPrivKeyChange_obj }, _usmUserPublic_obj = { "usmUserPublic", 11, 0, NULL, &_usmUserOwnPrivKeyChange_obj }, _usmUserStorageType_obj = { "usmUserStorageType", 12, 0, NULL, &_usmUserPublic_obj }, _usmUserStatus_obj = { "usmUserStatus", 13, 0, NULL, &_usmUserStorageType_obj }, _usmUserEntry_obj = { "usmUserEntry", 1, 0, &_usmUserStatus_obj, NULL }, _usmUserSpinLock_obj = { "usmUserSpinLock", 1, 0, NULL, NULL }, _usmUserTable_obj = { "usmUserTable", 2, 0, &_usmUserEntry_obj, &_usmUserSpinLock_obj }, _usmStatsUnsupportedSecLevels_obj = { "usmStatsUnsupportedSecLevels", 1, 0, NULL, NULL }, _usmStatsNotInTimeWindows_obj = { "usmStatsNotInTimeWindows", 2, 0, NULL, &_usmStatsUnsupportedSecLevels_obj }, _usmStatsUnknownUserNames_obj = { "usmStatsUnknownUserNames", 3, 0, NULL, &_usmStatsNotInTimeWindows_obj }, _usmStatsUnknownEngineIDs_obj = { "usmStatsUnknownEngineIDs", 4, 0, NULL, &_usmStatsUnknownUserNames_obj }, _usmStatsWrongDigests_obj = { "usmStatsWrongDigests", 5, 0, NULL, &_usmStatsUnknownEngineIDs_obj }, _usmStatsDecryptionErrors_obj = { "usmStatsDecryptionErrors", 6, 0, NULL, &_usmStatsWrongDigests_obj }, _usmStats_obj = { "usmStats", 1, 0, &_usmStatsDecryptionErrors_obj, NULL }, _usmUser_obj = { "usmUser", 2, 0, &_usmUserTable_obj, &_usmStats_obj }, _usmMIBObjects_obj = { "usmMIBObjects", 1, 0, &_usmUser_obj, NULL }, _usmMIBConformance_obj = { "usmMIBConformance", 2, 0, &_usmMIBGroups_obj, &_usmMIBObjects_obj }, _snmpMPDMIBCompliances_obj = { "snmpMPDMIBCompliances", 1, 0, NULL, NULL }, _snmpMPDMIBGroups_obj = { "snmpMPDMIBGroups", 2, 0, NULL, &_snmpMPDMIBCompliances_obj }, _snmpUnknownSecurityModels_obj = { "snmpUnknownSecurityModels", 1, 0, NULL, NULL }, _snmpInvalidMsgs_obj = { "snmpInvalidMsgs", 2, 0, NULL, &_snmpUnknownSecurityModels_obj }, _snmpUnknownPDUHandlers_obj = { "snmpUnknownPDUHandlers", 3, 0, NULL, &_snmpInvalidMsgs_obj }, _snmpMPDStats_obj = { "snmpMPDStats", 1, 0, &_snmpUnknownPDUHandlers_obj, NULL }, _snmpMPDAdmin_obj = { "snmpMPDAdmin", 1, 0, NULL, NULL }, _snmpMPDMIBObjects_obj = { "snmpMPDMIBObjects", 2, 0, &_snmpMPDStats_obj, &_snmpMPDAdmin_obj }, _snmpMPDMIBConformance_obj = { "snmpMPDMIBConformance", 3, 0, &_snmpMPDMIBGroups_obj, &_snmpMPDMIBObjects_obj }, _snmpEngineID_obj = { "snmpEngineID", 1, 0, NULL, NULL }, _snmpEngineBoots_obj = { "snmpEngineBoots", 2, 0, NULL, &_snmpEngineID_obj }, _snmpEngineTime_obj = { "snmpEngineTime", 3, 0, NULL, &_snmpEngineBoots_obj }, _snmpEngineMaxMessageSize_obj = { "snmpEngineMaxMessageSize", 4, 0, NULL, &_snmpEngineTime_obj }, _snmpEngine_obj = { "snmpEngine", 1, 0, &_snmpEngineMaxMessageSize_obj, NULL }, _snmpFrameworkAdmin_obj = { "snmpFrameworkAdmin", 1, 0, NULL, NULL }, _snmpFrameworkMIBObjects_obj = { "snmpFrameworkMIBObjects", 2, 0, &_snmpEngine_obj, &_snmpFrameworkAdmin_obj }, _snmpFrameworkMIBConformance_obj = { "snmpFrameworkMIBConformance", 3, 0, NULL, &_snmpFrameworkMIBObjects_obj }, _snmpFrameworkMIB_obj = { "snmpFrameworkMIB", 10, 0, &_snmpFrameworkMIBConformance_obj, NULL }, _snmpMPDMIB_obj = { "snmpMPDMIB", 11, 0, &_snmpMPDMIBConformance_obj, &_snmpFrameworkMIB_obj }, _snmpUsmMIB_obj = { "snmpUsmMIB", 15, 0, &_usmMIBConformance_obj, &_snmpMPDMIB_obj }, _snmpModules_obj = { "snmpModules", 3, 0, &_snmpUsmMIB_obj, NULL }, _mib_obj = { "mib", 1, 0, &_snmp_obj, NULL }, _directory_obj = { "directory", 1, 0, NULL, NULL }, _mgmt_obj = { "mgmt", 2, 0, &_mib_obj, &_directory_obj }, _experimental_obj = { "experimental", 3, 0, NULL, &_mgmt_obj }, _private_obj = { "private", 4, 0, &_enterprises_obj, &_experimental_obj }, _security_obj = { "security", 5, 0, NULL, &_private_obj }, _snmpV2_obj = { "snmpV2", 6, 0, &_snmpModules_obj, &_security_obj }, _internet_obj = { "internet", 1, 0, &_snmpV2_obj, NULL }, _dod_obj = { "dod", 6, 0, &_internet_obj, NULL }, _org_obj = { "org", 3, 0, &_dod_obj, NULL }, _iso_obj = { "iso", 1, 0, &_org_obj, NULL }, *mibroot = &_iso_obj; tcpdump-4.9.3/print-802_11.c0000644000026300017510000026671613544412724013466 0ustar mcrmcr/* * Copyright (c) 2001 * Fortress Technologies, Inc. All rights reserved. * Charlie Lenahan (clenahan@fortresstech.com) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of * the University nor the names of its contributors may be used to endorse * or promote products derived from this software without specific prior * written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* \summary: IEEE 802.11 printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include "netdissect.h" #include "addrtoname.h" #include "extract.h" #include "cpack.h" /* Lengths of 802.11 header components. */ #define IEEE802_11_FC_LEN 2 #define IEEE802_11_DUR_LEN 2 #define IEEE802_11_DA_LEN 6 #define IEEE802_11_SA_LEN 6 #define IEEE802_11_BSSID_LEN 6 #define IEEE802_11_RA_LEN 6 #define IEEE802_11_TA_LEN 6 #define IEEE802_11_ADDR1_LEN 6 #define IEEE802_11_SEQ_LEN 2 #define IEEE802_11_CTL_LEN 2 #define IEEE802_11_CARRIED_FC_LEN 2 #define IEEE802_11_HT_CONTROL_LEN 4 #define IEEE802_11_IV_LEN 3 #define IEEE802_11_KID_LEN 1 /* Frame check sequence length. */ #define IEEE802_11_FCS_LEN 4 /* Lengths of beacon components. */ #define IEEE802_11_TSTAMP_LEN 8 #define IEEE802_11_BCNINT_LEN 2 #define IEEE802_11_CAPINFO_LEN 2 #define IEEE802_11_LISTENINT_LEN 2 #define IEEE802_11_AID_LEN 2 #define IEEE802_11_STATUS_LEN 2 #define IEEE802_11_REASON_LEN 2 /* Length of previous AP in reassocation frame */ #define IEEE802_11_AP_LEN 6 #define T_MGMT 0x0 /* management */ #define T_CTRL 0x1 /* control */ #define T_DATA 0x2 /* data */ #define T_RESV 0x3 /* reserved */ #define ST_ASSOC_REQUEST 0x0 #define ST_ASSOC_RESPONSE 0x1 #define ST_REASSOC_REQUEST 0x2 #define ST_REASSOC_RESPONSE 0x3 #define ST_PROBE_REQUEST 0x4 #define ST_PROBE_RESPONSE 0x5 /* RESERVED 0x6 */ /* RESERVED 0x7 */ #define ST_BEACON 0x8 #define ST_ATIM 0x9 #define ST_DISASSOC 0xA #define ST_AUTH 0xB #define ST_DEAUTH 0xC #define ST_ACTION 0xD /* RESERVED 0xE */ /* RESERVED 0xF */ static const struct tok st_str[] = { { ST_ASSOC_REQUEST, "Assoc Request" }, { ST_ASSOC_RESPONSE, "Assoc Response" }, { ST_REASSOC_REQUEST, "ReAssoc Request" }, { ST_REASSOC_RESPONSE, "ReAssoc Response" }, { ST_PROBE_REQUEST, "Probe Request" }, { ST_PROBE_RESPONSE, "Probe Response" }, { ST_BEACON, "Beacon" }, { ST_ATIM, "ATIM" }, { ST_DISASSOC, "Disassociation" }, { ST_AUTH, "Authentication" }, { ST_DEAUTH, "DeAuthentication" }, { ST_ACTION, "Action" }, { 0, NULL } }; #define CTRL_CONTROL_WRAPPER 0x7 #define CTRL_BAR 0x8 #define CTRL_BA 0x9 #define CTRL_PS_POLL 0xA #define CTRL_RTS 0xB #define CTRL_CTS 0xC #define CTRL_ACK 0xD #define CTRL_CF_END 0xE #define CTRL_END_ACK 0xF static const struct tok ctrl_str[] = { { CTRL_CONTROL_WRAPPER, "Control Wrapper" }, { CTRL_BAR, "BAR" }, { CTRL_BA, "BA" }, { CTRL_PS_POLL, "Power Save-Poll" }, { CTRL_RTS, "Request-To-Send" }, { CTRL_CTS, "Clear-To-Send" }, { CTRL_ACK, "Acknowledgment" }, { CTRL_CF_END, "CF-End" }, { CTRL_END_ACK, "CF-End+CF-Ack" }, { 0, NULL } }; #define DATA_DATA 0x0 #define DATA_DATA_CF_ACK 0x1 #define DATA_DATA_CF_POLL 0x2 #define DATA_DATA_CF_ACK_POLL 0x3 #define DATA_NODATA 0x4 #define DATA_NODATA_CF_ACK 0x5 #define DATA_NODATA_CF_POLL 0x6 #define DATA_NODATA_CF_ACK_POLL 0x7 #define DATA_QOS_DATA 0x8 #define DATA_QOS_DATA_CF_ACK 0x9 #define DATA_QOS_DATA_CF_POLL 0xA #define DATA_QOS_DATA_CF_ACK_POLL 0xB #define DATA_QOS_NODATA 0xC #define DATA_QOS_CF_POLL_NODATA 0xE #define DATA_QOS_CF_ACK_POLL_NODATA 0xF /* * The subtype field of a data frame is, in effect, composed of 4 flag * bits - CF-Ack, CF-Poll, Null (means the frame doesn't actually have * any data), and QoS. */ #define DATA_FRAME_IS_CF_ACK(x) ((x) & 0x01) #define DATA_FRAME_IS_CF_POLL(x) ((x) & 0x02) #define DATA_FRAME_IS_NULL(x) ((x) & 0x04) #define DATA_FRAME_IS_QOS(x) ((x) & 0x08) /* * Bits in the frame control field. */ #define FC_VERSION(fc) ((fc) & 0x3) #define FC_TYPE(fc) (((fc) >> 2) & 0x3) #define FC_SUBTYPE(fc) (((fc) >> 4) & 0xF) #define FC_TO_DS(fc) ((fc) & 0x0100) #define FC_FROM_DS(fc) ((fc) & 0x0200) #define FC_MORE_FLAG(fc) ((fc) & 0x0400) #define FC_RETRY(fc) ((fc) & 0x0800) #define FC_POWER_MGMT(fc) ((fc) & 0x1000) #define FC_MORE_DATA(fc) ((fc) & 0x2000) #define FC_PROTECTED(fc) ((fc) & 0x4000) #define FC_ORDER(fc) ((fc) & 0x8000) struct mgmt_header_t { uint16_t fc; uint16_t duration; uint8_t da[IEEE802_11_DA_LEN]; uint8_t sa[IEEE802_11_SA_LEN]; uint8_t bssid[IEEE802_11_BSSID_LEN]; uint16_t seq_ctrl; }; #define MGMT_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\ IEEE802_11_DA_LEN+IEEE802_11_SA_LEN+\ IEEE802_11_BSSID_LEN+IEEE802_11_SEQ_LEN) #define CAPABILITY_ESS(cap) ((cap) & 0x0001) #define CAPABILITY_IBSS(cap) ((cap) & 0x0002) #define CAPABILITY_CFP(cap) ((cap) & 0x0004) #define CAPABILITY_CFP_REQ(cap) ((cap) & 0x0008) #define CAPABILITY_PRIVACY(cap) ((cap) & 0x0010) struct ssid_t { uint8_t element_id; uint8_t length; u_char ssid[33]; /* 32 + 1 for null */ }; struct rates_t { uint8_t element_id; uint8_t length; uint8_t rate[16]; }; struct challenge_t { uint8_t element_id; uint8_t length; uint8_t text[254]; /* 1-253 + 1 for null */ }; struct fh_t { uint8_t element_id; uint8_t length; uint16_t dwell_time; uint8_t hop_set; uint8_t hop_pattern; uint8_t hop_index; }; struct ds_t { uint8_t element_id; uint8_t length; uint8_t channel; }; struct cf_t { uint8_t element_id; uint8_t length; uint8_t count; uint8_t period; uint16_t max_duration; uint16_t dur_remaing; }; struct tim_t { uint8_t element_id; uint8_t length; uint8_t count; uint8_t period; uint8_t bitmap_control; uint8_t bitmap[251]; }; #define E_SSID 0 #define E_RATES 1 #define E_FH 2 #define E_DS 3 #define E_CF 4 #define E_TIM 5 #define E_IBSS 6 /* reserved 7 */ /* reserved 8 */ /* reserved 9 */ /* reserved 10 */ /* reserved 11 */ /* reserved 12 */ /* reserved 13 */ /* reserved 14 */ /* reserved 15 */ /* reserved 16 */ #define E_CHALLENGE 16 /* reserved 17 */ /* reserved 18 */ /* reserved 19 */ /* reserved 16 */ /* reserved 16 */ struct mgmt_body_t { uint8_t timestamp[IEEE802_11_TSTAMP_LEN]; uint16_t beacon_interval; uint16_t listen_interval; uint16_t status_code; uint16_t aid; u_char ap[IEEE802_11_AP_LEN]; uint16_t reason_code; uint16_t auth_alg; uint16_t auth_trans_seq_num; int challenge_present; struct challenge_t challenge; uint16_t capability_info; int ssid_present; struct ssid_t ssid; int rates_present; struct rates_t rates; int ds_present; struct ds_t ds; int cf_present; struct cf_t cf; int fh_present; struct fh_t fh; int tim_present; struct tim_t tim; }; struct ctrl_control_wrapper_hdr_t { uint16_t fc; uint16_t duration; uint8_t addr1[IEEE802_11_ADDR1_LEN]; uint16_t carried_fc[IEEE802_11_CARRIED_FC_LEN]; uint16_t ht_control[IEEE802_11_HT_CONTROL_LEN]; }; #define CTRL_CONTROL_WRAPPER_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\ IEEE802_11_ADDR1_LEN+\ IEEE802_11_CARRIED_FC_LEN+\ IEEE802_11_HT_CONTROL_LEN) struct ctrl_rts_hdr_t { uint16_t fc; uint16_t duration; uint8_t ra[IEEE802_11_RA_LEN]; uint8_t ta[IEEE802_11_TA_LEN]; }; #define CTRL_RTS_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\ IEEE802_11_RA_LEN+IEEE802_11_TA_LEN) struct ctrl_cts_hdr_t { uint16_t fc; uint16_t duration; uint8_t ra[IEEE802_11_RA_LEN]; }; #define CTRL_CTS_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN) struct ctrl_ack_hdr_t { uint16_t fc; uint16_t duration; uint8_t ra[IEEE802_11_RA_LEN]; }; #define CTRL_ACK_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN) struct ctrl_ps_poll_hdr_t { uint16_t fc; uint16_t aid; uint8_t bssid[IEEE802_11_BSSID_LEN]; uint8_t ta[IEEE802_11_TA_LEN]; }; #define CTRL_PS_POLL_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_AID_LEN+\ IEEE802_11_BSSID_LEN+IEEE802_11_TA_LEN) struct ctrl_end_hdr_t { uint16_t fc; uint16_t duration; uint8_t ra[IEEE802_11_RA_LEN]; uint8_t bssid[IEEE802_11_BSSID_LEN]; }; #define CTRL_END_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\ IEEE802_11_RA_LEN+IEEE802_11_BSSID_LEN) struct ctrl_end_ack_hdr_t { uint16_t fc; uint16_t duration; uint8_t ra[IEEE802_11_RA_LEN]; uint8_t bssid[IEEE802_11_BSSID_LEN]; }; #define CTRL_END_ACK_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\ IEEE802_11_RA_LEN+IEEE802_11_BSSID_LEN) struct ctrl_ba_hdr_t { uint16_t fc; uint16_t duration; uint8_t ra[IEEE802_11_RA_LEN]; }; #define CTRL_BA_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN) struct ctrl_bar_hdr_t { uint16_t fc; uint16_t dur; uint8_t ra[IEEE802_11_RA_LEN]; uint8_t ta[IEEE802_11_TA_LEN]; uint16_t ctl; uint16_t seq; }; #define CTRL_BAR_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\ IEEE802_11_RA_LEN+IEEE802_11_TA_LEN+\ IEEE802_11_CTL_LEN+IEEE802_11_SEQ_LEN) struct meshcntl_t { uint8_t flags; uint8_t ttl; uint8_t seq[4]; uint8_t addr4[6]; uint8_t addr5[6]; uint8_t addr6[6]; }; #define IV_IV(iv) ((iv) & 0xFFFFFF) #define IV_PAD(iv) (((iv) >> 24) & 0x3F) #define IV_KEYID(iv) (((iv) >> 30) & 0x03) #define PRINT_SSID(p) \ if (p.ssid_present) { \ ND_PRINT((ndo, " (")); \ fn_print(ndo, p.ssid.ssid, NULL); \ ND_PRINT((ndo, ")")); \ } #define PRINT_RATE(_sep, _r, _suf) \ ND_PRINT((ndo, "%s%2.1f%s", _sep, (.5 * ((_r) & 0x7f)), _suf)) #define PRINT_RATES(p) \ if (p.rates_present) { \ int z; \ const char *sep = " ["; \ for (z = 0; z < p.rates.length ; z++) { \ PRINT_RATE(sep, p.rates.rate[z], \ (p.rates.rate[z] & 0x80 ? "*" : "")); \ sep = " "; \ } \ if (p.rates.length != 0) \ ND_PRINT((ndo, " Mbit]")); \ } #define PRINT_DS_CHANNEL(p) \ if (p.ds_present) \ ND_PRINT((ndo, " CH: %u", p.ds.channel)); \ ND_PRINT((ndo, "%s", \ CAPABILITY_PRIVACY(p.capability_info) ? ", PRIVACY" : "")); #define MAX_MCS_INDEX 76 /* * Indices are: * * the MCS index (0-76); * * 0 for 20 MHz, 1 for 40 MHz; * * 0 for a long guard interval, 1 for a short guard interval. */ static const float ieee80211_float_htrates[MAX_MCS_INDEX+1][2][2] = { /* MCS 0 */ { /* 20 Mhz */ { 6.5, /* SGI */ 7.2, }, /* 40 Mhz */ { 13.5, /* SGI */ 15.0, }, }, /* MCS 1 */ { /* 20 Mhz */ { 13.0, /* SGI */ 14.4, }, /* 40 Mhz */ { 27.0, /* SGI */ 30.0, }, }, /* MCS 2 */ { /* 20 Mhz */ { 19.5, /* SGI */ 21.7, }, /* 40 Mhz */ { 40.5, /* SGI */ 45.0, }, }, /* MCS 3 */ { /* 20 Mhz */ { 26.0, /* SGI */ 28.9, }, /* 40 Mhz */ { 54.0, /* SGI */ 60.0, }, }, /* MCS 4 */ { /* 20 Mhz */ { 39.0, /* SGI */ 43.3, }, /* 40 Mhz */ { 81.0, /* SGI */ 90.0, }, }, /* MCS 5 */ { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, }, /* 40 Mhz */ { 108.0, /* SGI */ 120.0, }, }, /* MCS 6 */ { /* 20 Mhz */ { 58.5, /* SGI */ 65.0, }, /* 40 Mhz */ { 121.5, /* SGI */ 135.0, }, }, /* MCS 7 */ { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, }, /* 40 Mhz */ { 135.0, /* SGI */ 150.0, }, }, /* MCS 8 */ { /* 20 Mhz */ { 13.0, /* SGI */ 14.4, }, /* 40 Mhz */ { 27.0, /* SGI */ 30.0, }, }, /* MCS 9 */ { /* 20 Mhz */ { 26.0, /* SGI */ 28.9, }, /* 40 Mhz */ { 54.0, /* SGI */ 60.0, }, }, /* MCS 10 */ { /* 20 Mhz */ { 39.0, /* SGI */ 43.3, }, /* 40 Mhz */ { 81.0, /* SGI */ 90.0, }, }, /* MCS 11 */ { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, }, /* 40 Mhz */ { 108.0, /* SGI */ 120.0, }, }, /* MCS 12 */ { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, }, /* 40 Mhz */ { 162.0, /* SGI */ 180.0, }, }, /* MCS 13 */ { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, }, /* 40 Mhz */ { 216.0, /* SGI */ 240.0, }, }, /* MCS 14 */ { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, }, /* 40 Mhz */ { 243.0, /* SGI */ 270.0, }, }, /* MCS 15 */ { /* 20 Mhz */ { 130.0, /* SGI */ 144.4, }, /* 40 Mhz */ { 270.0, /* SGI */ 300.0, }, }, /* MCS 16 */ { /* 20 Mhz */ { 19.5, /* SGI */ 21.7, }, /* 40 Mhz */ { 40.5, /* SGI */ 45.0, }, }, /* MCS 17 */ { /* 20 Mhz */ { 39.0, /* SGI */ 43.3, }, /* 40 Mhz */ { 81.0, /* SGI */ 90.0, }, }, /* MCS 18 */ { /* 20 Mhz */ { 58.5, /* SGI */ 65.0, }, /* 40 Mhz */ { 121.5, /* SGI */ 135.0, }, }, /* MCS 19 */ { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, }, /* 40 Mhz */ { 162.0, /* SGI */ 180.0, }, }, /* MCS 20 */ { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, }, /* 40 Mhz */ { 243.0, /* SGI */ 270.0, }, }, /* MCS 21 */ { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, }, /* 40 Mhz */ { 324.0, /* SGI */ 360.0, }, }, /* MCS 22 */ { /* 20 Mhz */ { 175.5, /* SGI */ 195.0, }, /* 40 Mhz */ { 364.5, /* SGI */ 405.0, }, }, /* MCS 23 */ { /* 20 Mhz */ { 195.0, /* SGI */ 216.7, }, /* 40 Mhz */ { 405.0, /* SGI */ 450.0, }, }, /* MCS 24 */ { /* 20 Mhz */ { 26.0, /* SGI */ 28.9, }, /* 40 Mhz */ { 54.0, /* SGI */ 60.0, }, }, /* MCS 25 */ { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, }, /* 40 Mhz */ { 108.0, /* SGI */ 120.0, }, }, /* MCS 26 */ { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, }, /* 40 Mhz */ { 162.0, /* SGI */ 180.0, }, }, /* MCS 27 */ { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, }, /* 40 Mhz */ { 216.0, /* SGI */ 240.0, }, }, /* MCS 28 */ { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, }, /* 40 Mhz */ { 324.0, /* SGI */ 360.0, }, }, /* MCS 29 */ { /* 20 Mhz */ { 208.0, /* SGI */ 231.1, }, /* 40 Mhz */ { 432.0, /* SGI */ 480.0, }, }, /* MCS 30 */ { /* 20 Mhz */ { 234.0, /* SGI */ 260.0, }, /* 40 Mhz */ { 486.0, /* SGI */ 540.0, }, }, /* MCS 31 */ { /* 20 Mhz */ { 260.0, /* SGI */ 288.9, }, /* 40 Mhz */ { 540.0, /* SGI */ 600.0, }, }, /* MCS 32 */ { /* 20 Mhz */ { 0.0, /* SGI */ 0.0, }, /* not valid */ /* 40 Mhz */ { 6.0, /* SGI */ 6.7, }, }, /* MCS 33 */ { /* 20 Mhz */ { 39.0, /* SGI */ 43.3, }, /* 40 Mhz */ { 81.0, /* SGI */ 90.0, }, }, /* MCS 34 */ { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, }, /* 40 Mhz */ { 108.0, /* SGI */ 120.0, }, }, /* MCS 35 */ { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, }, /* 40 Mhz */ { 135.0, /* SGI */ 150.0, }, }, /* MCS 36 */ { /* 20 Mhz */ { 58.5, /* SGI */ 65.0, }, /* 40 Mhz */ { 121.5, /* SGI */ 135.0, }, }, /* MCS 37 */ { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, }, /* 40 Mhz */ { 162.0, /* SGI */ 180.0, }, }, /* MCS 38 */ { /* 20 Mhz */ { 97.5, /* SGI */ 108.3, }, /* 40 Mhz */ { 202.5, /* SGI */ 225.0, }, }, /* MCS 39 */ { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, }, /* 40 Mhz */ { 108.0, /* SGI */ 120.0, }, }, /* MCS 40 */ { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, }, /* 40 Mhz */ { 135.0, /* SGI */ 150.0, }, }, /* MCS 41 */ { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, }, /* 40 Mhz */ { 135.0, /* SGI */ 150.0, }, }, /* MCS 42 */ { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, }, /* 40 Mhz */ { 162.0, /* SGI */ 180.0, }, }, /* MCS 43 */ { /* 20 Mhz */ { 91.0, /* SGI */ 101.1, }, /* 40 Mhz */ { 189.0, /* SGI */ 210.0, }, }, /* MCS 44 */ { /* 20 Mhz */ { 91.0, /* SGI */ 101.1, }, /* 40 Mhz */ { 189.0, /* SGI */ 210.0, }, }, /* MCS 45 */ { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, }, /* 40 Mhz */ { 216.0, /* SGI */ 240.0, }, }, /* MCS 46 */ { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, }, /* 40 Mhz */ { 162.0, /* SGI */ 180.0, }, }, /* MCS 47 */ { /* 20 Mhz */ { 97.5, /* SGI */ 108.3, }, /* 40 Mhz */ { 202.5, /* SGI */ 225.0, }, }, /* MCS 48 */ { /* 20 Mhz */ { 97.5, /* SGI */ 108.3, }, /* 40 Mhz */ { 202.5, /* SGI */ 225.0, }, }, /* MCS 49 */ { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, }, /* 40 Mhz */ { 243.0, /* SGI */ 270.0, }, }, /* MCS 50 */ { /* 20 Mhz */ { 136.5, /* SGI */ 151.7, }, /* 40 Mhz */ { 283.5, /* SGI */ 315.0, }, }, /* MCS 51 */ { /* 20 Mhz */ { 136.5, /* SGI */ 151.7, }, /* 40 Mhz */ { 283.5, /* SGI */ 315.0, }, }, /* MCS 52 */ { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, }, /* 40 Mhz */ { 324.0, /* SGI */ 360.0, }, }, /* MCS 53 */ { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, }, /* 40 Mhz */ { 135.0, /* SGI */ 150.0, }, }, /* MCS 54 */ { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, }, /* 40 Mhz */ { 162.0, /* SGI */ 180.0, }, }, /* MCS 55 */ { /* 20 Mhz */ { 91.0, /* SGI */ 101.1, }, /* 40 Mhz */ { 189.0, /* SGI */ 210.0, }, }, /* MCS 56 */ { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, }, /* 40 Mhz */ { 162.0, /* SGI */ 180.0, }, }, /* MCS 57 */ { /* 20 Mhz */ { 91.0, /* SGI */ 101.1, }, /* 40 Mhz */ { 189.0, /* SGI */ 210.0, }, }, /* MCS 58 */ { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, }, /* 40 Mhz */ { 216.0, /* SGI */ 240.0, }, }, /* MCS 59 */ { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, }, /* 40 Mhz */ { 243.0, /* SGI */ 270.0, }, }, /* MCS 60 */ { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, }, /* 40 Mhz */ { 216.0, /* SGI */ 240.0, }, }, /* MCS 61 */ { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, }, /* 40 Mhz */ { 243.0, /* SGI */ 270.0, }, }, /* MCS 62 */ { /* 20 Mhz */ { 130.0, /* SGI */ 144.4, }, /* 40 Mhz */ { 270.0, /* SGI */ 300.0, }, }, /* MCS 63 */ { /* 20 Mhz */ { 130.0, /* SGI */ 144.4, }, /* 40 Mhz */ { 270.0, /* SGI */ 300.0, }, }, /* MCS 64 */ { /* 20 Mhz */ { 143.0, /* SGI */ 158.9, }, /* 40 Mhz */ { 297.0, /* SGI */ 330.0, }, }, /* MCS 65 */ { /* 20 Mhz */ { 97.5, /* SGI */ 108.3, }, /* 40 Mhz */ { 202.5, /* SGI */ 225.0, }, }, /* MCS 66 */ { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, }, /* 40 Mhz */ { 243.0, /* SGI */ 270.0, }, }, /* MCS 67 */ { /* 20 Mhz */ { 136.5, /* SGI */ 151.7, }, /* 40 Mhz */ { 283.5, /* SGI */ 315.0, }, }, /* MCS 68 */ { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, }, /* 40 Mhz */ { 243.0, /* SGI */ 270.0, }, }, /* MCS 69 */ { /* 20 Mhz */ { 136.5, /* SGI */ 151.7, }, /* 40 Mhz */ { 283.5, /* SGI */ 315.0, }, }, /* MCS 70 */ { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, }, /* 40 Mhz */ { 324.0, /* SGI */ 360.0, }, }, /* MCS 71 */ { /* 20 Mhz */ { 175.5, /* SGI */ 195.0, }, /* 40 Mhz */ { 364.5, /* SGI */ 405.0, }, }, /* MCS 72 */ { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, }, /* 40 Mhz */ { 324.0, /* SGI */ 360.0, }, }, /* MCS 73 */ { /* 20 Mhz */ { 175.5, /* SGI */ 195.0, }, /* 40 Mhz */ { 364.5, /* SGI */ 405.0, }, }, /* MCS 74 */ { /* 20 Mhz */ { 195.0, /* SGI */ 216.7, }, /* 40 Mhz */ { 405.0, /* SGI */ 450.0, }, }, /* MCS 75 */ { /* 20 Mhz */ { 195.0, /* SGI */ 216.7, }, /* 40 Mhz */ { 405.0, /* SGI */ 450.0, }, }, /* MCS 76 */ { /* 20 Mhz */ { 214.5, /* SGI */ 238.3, }, /* 40 Mhz */ { 445.5, /* SGI */ 495.0, }, }, }; static const char *auth_alg_text[]={"Open System","Shared Key","EAP"}; #define NUM_AUTH_ALGS (sizeof auth_alg_text / sizeof auth_alg_text[0]) static const char *status_text[] = { "Successful", /* 0 */ "Unspecified failure", /* 1 */ "Reserved", /* 2 */ "Reserved", /* 3 */ "Reserved", /* 4 */ "Reserved", /* 5 */ "Reserved", /* 6 */ "Reserved", /* 7 */ "Reserved", /* 8 */ "Reserved", /* 9 */ "Cannot Support all requested capabilities in the Capability " "Information field", /* 10 */ "Reassociation denied due to inability to confirm that association " "exists", /* 11 */ "Association denied due to reason outside the scope of the " "standard", /* 12 */ "Responding station does not support the specified authentication " "algorithm ", /* 13 */ "Received an Authentication frame with authentication transaction " "sequence number out of expected sequence", /* 14 */ "Authentication rejected because of challenge failure", /* 15 */ "Authentication rejected due to timeout waiting for next frame in " "sequence", /* 16 */ "Association denied because AP is unable to handle additional" "associated stations", /* 17 */ "Association denied due to requesting station not supporting all of " "the data rates in BSSBasicRateSet parameter", /* 18 */ "Association denied due to requesting station not supporting " "short preamble operation", /* 19 */ "Association denied due to requesting station not supporting " "PBCC encoding", /* 20 */ "Association denied due to requesting station not supporting " "channel agility", /* 21 */ "Association request rejected because Spectrum Management " "capability is required", /* 22 */ "Association request rejected because the information in the " "Power Capability element is unacceptable", /* 23 */ "Association request rejected because the information in the " "Supported Channels element is unacceptable", /* 24 */ "Association denied due to requesting station not supporting " "short slot operation", /* 25 */ "Association denied due to requesting station not supporting " "DSSS-OFDM operation", /* 26 */ "Association denied because the requested STA does not support HT " "features", /* 27 */ "Reserved", /* 28 */ "Association denied because the requested STA does not support " "the PCO transition time required by the AP", /* 29 */ "Reserved", /* 30 */ "Reserved", /* 31 */ "Unspecified, QoS-related failure", /* 32 */ "Association denied due to QAP having insufficient bandwidth " "to handle another QSTA", /* 33 */ "Association denied due to excessive frame loss rates and/or " "poor conditions on current operating channel", /* 34 */ "Association (with QBSS) denied due to requesting station not " "supporting the QoS facility", /* 35 */ "Association denied due to requesting station not supporting " "Block Ack", /* 36 */ "The request has been declined", /* 37 */ "The request has not been successful as one or more parameters " "have invalid values", /* 38 */ "The TS has not been created because the request cannot be honored. " "Try again with the suggested changes to the TSPEC", /* 39 */ "Invalid Information Element", /* 40 */ "Group Cipher is not valid", /* 41 */ "Pairwise Cipher is not valid", /* 42 */ "AKMP is not valid", /* 43 */ "Unsupported RSN IE version", /* 44 */ "Invalid RSN IE Capabilities", /* 45 */ "Cipher suite is rejected per security policy", /* 46 */ "The TS has not been created. However, the HC may be capable of " "creating a TS, in response to a request, after the time indicated " "in the TS Delay element", /* 47 */ "Direct Link is not allowed in the BSS by policy", /* 48 */ "Destination STA is not present within this QBSS.", /* 49 */ "The Destination STA is not a QSTA.", /* 50 */ }; #define NUM_STATUSES (sizeof status_text / sizeof status_text[0]) static const char *reason_text[] = { "Reserved", /* 0 */ "Unspecified reason", /* 1 */ "Previous authentication no longer valid", /* 2 */ "Deauthenticated because sending station is leaving (or has left) " "IBSS or ESS", /* 3 */ "Disassociated due to inactivity", /* 4 */ "Disassociated because AP is unable to handle all currently " " associated stations", /* 5 */ "Class 2 frame received from nonauthenticated station", /* 6 */ "Class 3 frame received from nonassociated station", /* 7 */ "Disassociated because sending station is leaving " "(or has left) BSS", /* 8 */ "Station requesting (re)association is not authenticated with " "responding station", /* 9 */ "Disassociated because the information in the Power Capability " "element is unacceptable", /* 10 */ "Disassociated because the information in the SupportedChannels " "element is unacceptable", /* 11 */ "Invalid Information Element", /* 12 */ "Reserved", /* 13 */ "Michael MIC failure", /* 14 */ "4-Way Handshake timeout", /* 15 */ "Group key update timeout", /* 16 */ "Information element in 4-Way Handshake different from (Re)Association" "Request/Probe Response/Beacon", /* 17 */ "Group Cipher is not valid", /* 18 */ "AKMP is not valid", /* 20 */ "Unsupported RSN IE version", /* 21 */ "Invalid RSN IE Capabilities", /* 22 */ "IEEE 802.1X Authentication failed", /* 23 */ "Cipher suite is rejected per security policy", /* 24 */ "Reserved", /* 25 */ "Reserved", /* 26 */ "Reserved", /* 27 */ "Reserved", /* 28 */ "Reserved", /* 29 */ "Reserved", /* 30 */ "TS deleted because QoS AP lacks sufficient bandwidth for this " "QoS STA due to a change in BSS service characteristics or " "operational mode (e.g. an HT BSS change from 40 MHz channel " "to 20 MHz channel)", /* 31 */ "Disassociated for unspecified, QoS-related reason", /* 32 */ "Disassociated because QoS AP lacks sufficient bandwidth for this " "QoS STA", /* 33 */ "Disassociated because of excessive number of frames that need to be " "acknowledged, but are not acknowledged for AP transmissions " "and/or poor channel conditions", /* 34 */ "Disassociated because STA is transmitting outside the limits " "of its TXOPs", /* 35 */ "Requested from peer STA as the STA is leaving the BSS " "(or resetting)", /* 36 */ "Requested from peer STA as it does not want to use the " "mechanism", /* 37 */ "Requested from peer STA as the STA received frames using the " "mechanism for which a set up is required", /* 38 */ "Requested from peer STA due to time out", /* 39 */ "Reserved", /* 40 */ "Reserved", /* 41 */ "Reserved", /* 42 */ "Reserved", /* 43 */ "Reserved", /* 44 */ "Peer STA does not support the requested cipher suite", /* 45 */ "Association denied due to requesting STA not supporting HT " "features", /* 46 */ }; #define NUM_REASONS (sizeof reason_text / sizeof reason_text[0]) static int wep_print(netdissect_options *ndo, const u_char *p) { uint32_t iv; if (!ND_TTEST2(*p, IEEE802_11_IV_LEN + IEEE802_11_KID_LEN)) return 0; iv = EXTRACT_LE_32BITS(p); ND_PRINT((ndo, " IV:%3x Pad %x KeyID %x", IV_IV(iv), IV_PAD(iv), IV_KEYID(iv))); return 1; } static int parse_elements(netdissect_options *ndo, struct mgmt_body_t *pbody, const u_char *p, int offset, u_int length) { u_int elementlen; struct ssid_t ssid; struct challenge_t challenge; struct rates_t rates; struct ds_t ds; struct cf_t cf; struct tim_t tim; /* * We haven't seen any elements yet. */ pbody->challenge_present = 0; pbody->ssid_present = 0; pbody->rates_present = 0; pbody->ds_present = 0; pbody->cf_present = 0; pbody->tim_present = 0; while (length != 0) { /* Make sure we at least have the element ID and length. */ if (!ND_TTEST2(*(p + offset), 2)) return 0; if (length < 2) return 0; elementlen = *(p + offset + 1); /* Make sure we have the entire element. */ if (!ND_TTEST2(*(p + offset + 2), elementlen)) return 0; if (length < elementlen + 2) return 0; switch (*(p + offset)) { case E_SSID: memcpy(&ssid, p + offset, 2); offset += 2; length -= 2; if (ssid.length != 0) { if (ssid.length > sizeof(ssid.ssid) - 1) return 0; memcpy(&ssid.ssid, p + offset, ssid.length); offset += ssid.length; length -= ssid.length; } ssid.ssid[ssid.length] = '\0'; /* * Present and not truncated. * * If we haven't already seen an SSID IE, * copy this one, otherwise ignore this one, * so we later report the first one we saw. */ if (!pbody->ssid_present) { pbody->ssid = ssid; pbody->ssid_present = 1; } break; case E_CHALLENGE: memcpy(&challenge, p + offset, 2); offset += 2; length -= 2; if (challenge.length != 0) { if (challenge.length > sizeof(challenge.text) - 1) return 0; memcpy(&challenge.text, p + offset, challenge.length); offset += challenge.length; length -= challenge.length; } challenge.text[challenge.length] = '\0'; /* * Present and not truncated. * * If we haven't already seen a challenge IE, * copy this one, otherwise ignore this one, * so we later report the first one we saw. */ if (!pbody->challenge_present) { pbody->challenge = challenge; pbody->challenge_present = 1; } break; case E_RATES: memcpy(&rates, p + offset, 2); offset += 2; length -= 2; if (rates.length != 0) { if (rates.length > sizeof rates.rate) return 0; memcpy(&rates.rate, p + offset, rates.length); offset += rates.length; length -= rates.length; } /* * Present and not truncated. * * If we haven't already seen a rates IE, * copy this one if it's not zero-length, * otherwise ignore this one, so we later * report the first one we saw. * * We ignore zero-length rates IEs as some * devices seem to put a zero-length rates * IE, followed by an SSID IE, followed by * a non-zero-length rates IE into frames, * even though IEEE Std 802.11-2007 doesn't * seem to indicate that a zero-length rates * IE is valid. */ if (!pbody->rates_present && rates.length != 0) { pbody->rates = rates; pbody->rates_present = 1; } break; case E_DS: memcpy(&ds, p + offset, 2); offset += 2; length -= 2; if (ds.length != 1) { offset += ds.length; length -= ds.length; break; } ds.channel = *(p + offset); offset += 1; length -= 1; /* * Present and not truncated. * * If we haven't already seen a DS IE, * copy this one, otherwise ignore this one, * so we later report the first one we saw. */ if (!pbody->ds_present) { pbody->ds = ds; pbody->ds_present = 1; } break; case E_CF: memcpy(&cf, p + offset, 2); offset += 2; length -= 2; if (cf.length != 6) { offset += cf.length; length -= cf.length; break; } memcpy(&cf.count, p + offset, 6); offset += 6; length -= 6; /* * Present and not truncated. * * If we haven't already seen a CF IE, * copy this one, otherwise ignore this one, * so we later report the first one we saw. */ if (!pbody->cf_present) { pbody->cf = cf; pbody->cf_present = 1; } break; case E_TIM: memcpy(&tim, p + offset, 2); offset += 2; length -= 2; if (tim.length <= 3) { offset += tim.length; length -= tim.length; break; } if (tim.length - 3 > (int)sizeof tim.bitmap) return 0; memcpy(&tim.count, p + offset, 3); offset += 3; length -= 3; memcpy(tim.bitmap, p + offset, tim.length - 3); offset += tim.length - 3; length -= tim.length - 3; /* * Present and not truncated. * * If we haven't already seen a TIM IE, * copy this one, otherwise ignore this one, * so we later report the first one we saw. */ if (!pbody->tim_present) { pbody->tim = tim; pbody->tim_present = 1; } break; default: #if 0 ND_PRINT((ndo, "(1) unhandled element_id (%d) ", *(p + offset))); #endif offset += 2 + elementlen; length -= 2 + elementlen; break; } } /* No problems found. */ return 1; } /********************************************************************************* * Print Handle functions for the management frame types *********************************************************************************/ static int handle_beacon(netdissect_options *ndo, const u_char *p, u_int length) { struct mgmt_body_t pbody; int offset = 0; int ret; memset(&pbody, 0, sizeof(pbody)); if (!ND_TTEST2(*p, IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN + IEEE802_11_CAPINFO_LEN)) return 0; if (length < IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN + IEEE802_11_CAPINFO_LEN) return 0; memcpy(&pbody.timestamp, p, IEEE802_11_TSTAMP_LEN); offset += IEEE802_11_TSTAMP_LEN; length -= IEEE802_11_TSTAMP_LEN; pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset); offset += IEEE802_11_BCNINT_LEN; length -= IEEE802_11_BCNINT_LEN; pbody.capability_info = EXTRACT_LE_16BITS(p+offset); offset += IEEE802_11_CAPINFO_LEN; length -= IEEE802_11_CAPINFO_LEN; ret = parse_elements(ndo, &pbody, p, offset, length); PRINT_SSID(pbody); PRINT_RATES(pbody); ND_PRINT((ndo, " %s", CAPABILITY_ESS(pbody.capability_info) ? "ESS" : "IBSS")); PRINT_DS_CHANNEL(pbody); return ret; } static int handle_assoc_request(netdissect_options *ndo, const u_char *p, u_int length) { struct mgmt_body_t pbody; int offset = 0; int ret; memset(&pbody, 0, sizeof(pbody)); if (!ND_TTEST2(*p, IEEE802_11_CAPINFO_LEN + IEEE802_11_LISTENINT_LEN)) return 0; if (length < IEEE802_11_CAPINFO_LEN + IEEE802_11_LISTENINT_LEN) return 0; pbody.capability_info = EXTRACT_LE_16BITS(p); offset += IEEE802_11_CAPINFO_LEN; length -= IEEE802_11_CAPINFO_LEN; pbody.listen_interval = EXTRACT_LE_16BITS(p+offset); offset += IEEE802_11_LISTENINT_LEN; length -= IEEE802_11_LISTENINT_LEN; ret = parse_elements(ndo, &pbody, p, offset, length); PRINT_SSID(pbody); PRINT_RATES(pbody); return ret; } static int handle_assoc_response(netdissect_options *ndo, const u_char *p, u_int length) { struct mgmt_body_t pbody; int offset = 0; int ret; memset(&pbody, 0, sizeof(pbody)); if (!ND_TTEST2(*p, IEEE802_11_CAPINFO_LEN + IEEE802_11_STATUS_LEN + IEEE802_11_AID_LEN)) return 0; if (length < IEEE802_11_CAPINFO_LEN + IEEE802_11_STATUS_LEN + IEEE802_11_AID_LEN) return 0; pbody.capability_info = EXTRACT_LE_16BITS(p); offset += IEEE802_11_CAPINFO_LEN; length -= IEEE802_11_CAPINFO_LEN; pbody.status_code = EXTRACT_LE_16BITS(p+offset); offset += IEEE802_11_STATUS_LEN; length -= IEEE802_11_STATUS_LEN; pbody.aid = EXTRACT_LE_16BITS(p+offset); offset += IEEE802_11_AID_LEN; length -= IEEE802_11_AID_LEN; ret = parse_elements(ndo, &pbody, p, offset, length); ND_PRINT((ndo, " AID(%x) :%s: %s", ((uint16_t)(pbody.aid << 2 )) >> 2 , CAPABILITY_PRIVACY(pbody.capability_info) ? " PRIVACY " : "", (pbody.status_code < NUM_STATUSES ? status_text[pbody.status_code] : "n/a"))); return ret; } static int handle_reassoc_request(netdissect_options *ndo, const u_char *p, u_int length) { struct mgmt_body_t pbody; int offset = 0; int ret; memset(&pbody, 0, sizeof(pbody)); if (!ND_TTEST2(*p, IEEE802_11_CAPINFO_LEN + IEEE802_11_LISTENINT_LEN + IEEE802_11_AP_LEN)) return 0; if (length < IEEE802_11_CAPINFO_LEN + IEEE802_11_LISTENINT_LEN + IEEE802_11_AP_LEN) return 0; pbody.capability_info = EXTRACT_LE_16BITS(p); offset += IEEE802_11_CAPINFO_LEN; length -= IEEE802_11_CAPINFO_LEN; pbody.listen_interval = EXTRACT_LE_16BITS(p+offset); offset += IEEE802_11_LISTENINT_LEN; length -= IEEE802_11_LISTENINT_LEN; memcpy(&pbody.ap, p+offset, IEEE802_11_AP_LEN); offset += IEEE802_11_AP_LEN; length -= IEEE802_11_AP_LEN; ret = parse_elements(ndo, &pbody, p, offset, length); PRINT_SSID(pbody); ND_PRINT((ndo, " AP : %s", etheraddr_string(ndo, pbody.ap ))); return ret; } static int handle_reassoc_response(netdissect_options *ndo, const u_char *p, u_int length) { /* Same as a Association Reponse */ return handle_assoc_response(ndo, p, length); } static int handle_probe_request(netdissect_options *ndo, const u_char *p, u_int length) { struct mgmt_body_t pbody; int offset = 0; int ret; memset(&pbody, 0, sizeof(pbody)); ret = parse_elements(ndo, &pbody, p, offset, length); PRINT_SSID(pbody); PRINT_RATES(pbody); return ret; } static int handle_probe_response(netdissect_options *ndo, const u_char *p, u_int length) { struct mgmt_body_t pbody; int offset = 0; int ret; memset(&pbody, 0, sizeof(pbody)); if (!ND_TTEST2(*p, IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN + IEEE802_11_CAPINFO_LEN)) return 0; if (length < IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN + IEEE802_11_CAPINFO_LEN) return 0; memcpy(&pbody.timestamp, p, IEEE802_11_TSTAMP_LEN); offset += IEEE802_11_TSTAMP_LEN; length -= IEEE802_11_TSTAMP_LEN; pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset); offset += IEEE802_11_BCNINT_LEN; length -= IEEE802_11_BCNINT_LEN; pbody.capability_info = EXTRACT_LE_16BITS(p+offset); offset += IEEE802_11_CAPINFO_LEN; length -= IEEE802_11_CAPINFO_LEN; ret = parse_elements(ndo, &pbody, p, offset, length); PRINT_SSID(pbody); PRINT_RATES(pbody); PRINT_DS_CHANNEL(pbody); return ret; } static int handle_atim(void) { /* the frame body for ATIM is null. */ return 1; } static int handle_disassoc(netdissect_options *ndo, const u_char *p, u_int length) { struct mgmt_body_t pbody; memset(&pbody, 0, sizeof(pbody)); if (!ND_TTEST2(*p, IEEE802_11_REASON_LEN)) return 0; if (length < IEEE802_11_REASON_LEN) return 0; pbody.reason_code = EXTRACT_LE_16BITS(p); ND_PRINT((ndo, ": %s", (pbody.reason_code < NUM_REASONS) ? reason_text[pbody.reason_code] : "Reserved")); return 1; } static int handle_auth(netdissect_options *ndo, const u_char *p, u_int length) { struct mgmt_body_t pbody; int offset = 0; int ret; memset(&pbody, 0, sizeof(pbody)); if (!ND_TTEST2(*p, 6)) return 0; if (length < 6) return 0; pbody.auth_alg = EXTRACT_LE_16BITS(p); offset += 2; length -= 2; pbody.auth_trans_seq_num = EXTRACT_LE_16BITS(p + offset); offset += 2; length -= 2; pbody.status_code = EXTRACT_LE_16BITS(p + offset); offset += 2; length -= 2; ret = parse_elements(ndo, &pbody, p, offset, length); if ((pbody.auth_alg == 1) && ((pbody.auth_trans_seq_num == 2) || (pbody.auth_trans_seq_num == 3))) { ND_PRINT((ndo, " (%s)-%x [Challenge Text] %s", (pbody.auth_alg < NUM_AUTH_ALGS) ? auth_alg_text[pbody.auth_alg] : "Reserved", pbody.auth_trans_seq_num, ((pbody.auth_trans_seq_num % 2) ? ((pbody.status_code < NUM_STATUSES) ? status_text[pbody.status_code] : "n/a") : ""))); return ret; } ND_PRINT((ndo, " (%s)-%x: %s", (pbody.auth_alg < NUM_AUTH_ALGS) ? auth_alg_text[pbody.auth_alg] : "Reserved", pbody.auth_trans_seq_num, (pbody.auth_trans_seq_num % 2) ? ((pbody.status_code < NUM_STATUSES) ? status_text[pbody.status_code] : "n/a") : "")); return ret; } static int handle_deauth(netdissect_options *ndo, const uint8_t *src, const u_char *p, u_int length) { struct mgmt_body_t pbody; const char *reason = NULL; memset(&pbody, 0, sizeof(pbody)); if (!ND_TTEST2(*p, IEEE802_11_REASON_LEN)) return 0; if (length < IEEE802_11_REASON_LEN) return 0; pbody.reason_code = EXTRACT_LE_16BITS(p); reason = (pbody.reason_code < NUM_REASONS) ? reason_text[pbody.reason_code] : "Reserved"; if (ndo->ndo_eflag) { ND_PRINT((ndo, ": %s", reason)); } else { ND_PRINT((ndo, " (%s): %s", etheraddr_string(ndo, src), reason)); } return 1; } #define PRINT_HT_ACTION(v) (\ (v) == 0 ? ND_PRINT((ndo, "TxChWidth")) : \ (v) == 1 ? ND_PRINT((ndo, "MIMOPwrSave")) : \ ND_PRINT((ndo, "Act#%d", (v))) \ ) #define PRINT_BA_ACTION(v) (\ (v) == 0 ? ND_PRINT((ndo, "ADDBA Request")) : \ (v) == 1 ? ND_PRINT((ndo, "ADDBA Response")) : \ (v) == 2 ? ND_PRINT((ndo, "DELBA")) : \ ND_PRINT((ndo, "Act#%d", (v))) \ ) #define PRINT_MESHLINK_ACTION(v) (\ (v) == 0 ? ND_PRINT((ndo, "Request")) : \ (v) == 1 ? ND_PRINT((ndo, "Report")) : \ ND_PRINT((ndo, "Act#%d", (v))) \ ) #define PRINT_MESHPEERING_ACTION(v) (\ (v) == 0 ? ND_PRINT((ndo, "Open")) : \ (v) == 1 ? ND_PRINT((ndo, "Confirm")) : \ (v) == 2 ? ND_PRINT((ndo, "Close")) : \ ND_PRINT((ndo, "Act#%d", (v))) \ ) #define PRINT_MESHPATH_ACTION(v) (\ (v) == 0 ? ND_PRINT((ndo, "Request")) : \ (v) == 1 ? ND_PRINT((ndo, "Report")) : \ (v) == 2 ? ND_PRINT((ndo, "Error")) : \ (v) == 3 ? ND_PRINT((ndo, "RootAnnouncement")) : \ ND_PRINT((ndo, "Act#%d", (v))) \ ) #define PRINT_MESH_ACTION(v) (\ (v) == 0 ? ND_PRINT((ndo, "MeshLink")) : \ (v) == 1 ? ND_PRINT((ndo, "HWMP")) : \ (v) == 2 ? ND_PRINT((ndo, "Gate Announcement")) : \ (v) == 3 ? ND_PRINT((ndo, "Congestion Control")) : \ (v) == 4 ? ND_PRINT((ndo, "MCCA Setup Request")) : \ (v) == 5 ? ND_PRINT((ndo, "MCCA Setup Reply")) : \ (v) == 6 ? ND_PRINT((ndo, "MCCA Advertisement Request")) : \ (v) == 7 ? ND_PRINT((ndo, "MCCA Advertisement")) : \ (v) == 8 ? ND_PRINT((ndo, "MCCA Teardown")) : \ (v) == 9 ? ND_PRINT((ndo, "TBTT Adjustment Request")) : \ (v) == 10 ? ND_PRINT((ndo, "TBTT Adjustment Response")) : \ ND_PRINT((ndo, "Act#%d", (v))) \ ) #define PRINT_MULTIHOP_ACTION(v) (\ (v) == 0 ? ND_PRINT((ndo, "Proxy Update")) : \ (v) == 1 ? ND_PRINT((ndo, "Proxy Update Confirmation")) : \ ND_PRINT((ndo, "Act#%d", (v))) \ ) #define PRINT_SELFPROT_ACTION(v) (\ (v) == 1 ? ND_PRINT((ndo, "Peering Open")) : \ (v) == 2 ? ND_PRINT((ndo, "Peering Confirm")) : \ (v) == 3 ? ND_PRINT((ndo, "Peering Close")) : \ (v) == 4 ? ND_PRINT((ndo, "Group Key Inform")) : \ (v) == 5 ? ND_PRINT((ndo, "Group Key Acknowledge")) : \ ND_PRINT((ndo, "Act#%d", (v))) \ ) static int handle_action(netdissect_options *ndo, const uint8_t *src, const u_char *p, u_int length) { if (!ND_TTEST2(*p, 2)) return 0; if (length < 2) return 0; if (ndo->ndo_eflag) { ND_PRINT((ndo, ": ")); } else { ND_PRINT((ndo, " (%s): ", etheraddr_string(ndo, src))); } switch (p[0]) { case 0: ND_PRINT((ndo, "Spectrum Management Act#%d", p[1])); break; case 1: ND_PRINT((ndo, "QoS Act#%d", p[1])); break; case 2: ND_PRINT((ndo, "DLS Act#%d", p[1])); break; case 3: ND_PRINT((ndo, "BA ")); PRINT_BA_ACTION(p[1]); break; case 7: ND_PRINT((ndo, "HT ")); PRINT_HT_ACTION(p[1]); break; case 13: ND_PRINT((ndo, "MeshAction ")); PRINT_MESH_ACTION(p[1]); break; case 14: ND_PRINT((ndo, "MultiohopAction ")); PRINT_MULTIHOP_ACTION(p[1]); break; case 15: ND_PRINT((ndo, "SelfprotectAction ")); PRINT_SELFPROT_ACTION(p[1]); break; case 127: ND_PRINT((ndo, "Vendor Act#%d", p[1])); break; default: ND_PRINT((ndo, "Reserved(%d) Act#%d", p[0], p[1])); break; } return 1; } /********************************************************************************* * Print Body funcs *********************************************************************************/ static int mgmt_body_print(netdissect_options *ndo, uint16_t fc, const uint8_t *src, const u_char *p, u_int length) { ND_PRINT((ndo, "%s", tok2str(st_str, "Unhandled Management subtype(%x)", FC_SUBTYPE(fc)))); /* There may be a problem w/ AP not having this bit set */ if (FC_PROTECTED(fc)) return wep_print(ndo, p); switch (FC_SUBTYPE(fc)) { case ST_ASSOC_REQUEST: return handle_assoc_request(ndo, p, length); case ST_ASSOC_RESPONSE: return handle_assoc_response(ndo, p, length); case ST_REASSOC_REQUEST: return handle_reassoc_request(ndo, p, length); case ST_REASSOC_RESPONSE: return handle_reassoc_response(ndo, p, length); case ST_PROBE_REQUEST: return handle_probe_request(ndo, p, length); case ST_PROBE_RESPONSE: return handle_probe_response(ndo, p, length); case ST_BEACON: return handle_beacon(ndo, p, length); case ST_ATIM: return handle_atim(); case ST_DISASSOC: return handle_disassoc(ndo, p, length); case ST_AUTH: return handle_auth(ndo, p, length); case ST_DEAUTH: return handle_deauth(ndo, src, p, length); case ST_ACTION: return handle_action(ndo, src, p, length); default: return 1; } } /********************************************************************************* * Handles printing all the control frame types *********************************************************************************/ static int ctrl_body_print(netdissect_options *ndo, uint16_t fc, const u_char *p) { ND_PRINT((ndo, "%s", tok2str(ctrl_str, "Unknown Ctrl Subtype", FC_SUBTYPE(fc)))); switch (FC_SUBTYPE(fc)) { case CTRL_CONTROL_WRAPPER: /* XXX - requires special handling */ break; case CTRL_BAR: if (!ND_TTEST2(*p, CTRL_BAR_HDRLEN)) return 0; if (!ndo->ndo_eflag) ND_PRINT((ndo, " RA:%s TA:%s CTL(%x) SEQ(%u) ", etheraddr_string(ndo, ((const struct ctrl_bar_hdr_t *)p)->ra), etheraddr_string(ndo, ((const struct ctrl_bar_hdr_t *)p)->ta), EXTRACT_LE_16BITS(&(((const struct ctrl_bar_hdr_t *)p)->ctl)), EXTRACT_LE_16BITS(&(((const struct ctrl_bar_hdr_t *)p)->seq)))); break; case CTRL_BA: if (!ND_TTEST2(*p, CTRL_BA_HDRLEN)) return 0; if (!ndo->ndo_eflag) ND_PRINT((ndo, " RA:%s ", etheraddr_string(ndo, ((const struct ctrl_ba_hdr_t *)p)->ra))); break; case CTRL_PS_POLL: if (!ND_TTEST2(*p, CTRL_PS_POLL_HDRLEN)) return 0; ND_PRINT((ndo, " AID(%x)", EXTRACT_LE_16BITS(&(((const struct ctrl_ps_poll_hdr_t *)p)->aid)))); break; case CTRL_RTS: if (!ND_TTEST2(*p, CTRL_RTS_HDRLEN)) return 0; if (!ndo->ndo_eflag) ND_PRINT((ndo, " TA:%s ", etheraddr_string(ndo, ((const struct ctrl_rts_hdr_t *)p)->ta))); break; case CTRL_CTS: if (!ND_TTEST2(*p, CTRL_CTS_HDRLEN)) return 0; if (!ndo->ndo_eflag) ND_PRINT((ndo, " RA:%s ", etheraddr_string(ndo, ((const struct ctrl_cts_hdr_t *)p)->ra))); break; case CTRL_ACK: if (!ND_TTEST2(*p, CTRL_ACK_HDRLEN)) return 0; if (!ndo->ndo_eflag) ND_PRINT((ndo, " RA:%s ", etheraddr_string(ndo, ((const struct ctrl_ack_hdr_t *)p)->ra))); break; case CTRL_CF_END: if (!ND_TTEST2(*p, CTRL_END_HDRLEN)) return 0; if (!ndo->ndo_eflag) ND_PRINT((ndo, " RA:%s ", etheraddr_string(ndo, ((const struct ctrl_end_hdr_t *)p)->ra))); break; case CTRL_END_ACK: if (!ND_TTEST2(*p, CTRL_END_ACK_HDRLEN)) return 0; if (!ndo->ndo_eflag) ND_PRINT((ndo, " RA:%s ", etheraddr_string(ndo, ((const struct ctrl_end_ack_hdr_t *)p)->ra))); break; } return 1; } /* * Data Frame - Address field contents * * To Ds | From DS | Addr 1 | Addr 2 | Addr 3 | Addr 4 * 0 | 0 | DA | SA | BSSID | n/a * 0 | 1 | DA | BSSID | SA | n/a * 1 | 0 | BSSID | SA | DA | n/a * 1 | 1 | RA | TA | DA | SA */ /* * Function to get source and destination MAC addresses for a data frame. */ static void get_data_src_dst_mac(uint16_t fc, const u_char *p, const uint8_t **srcp, const uint8_t **dstp) { #define ADDR1 (p + 4) #define ADDR2 (p + 10) #define ADDR3 (p + 16) #define ADDR4 (p + 24) if (!FC_TO_DS(fc)) { if (!FC_FROM_DS(fc)) { /* not To DS and not From DS */ *srcp = ADDR2; *dstp = ADDR1; } else { /* not To DS and From DS */ *srcp = ADDR3; *dstp = ADDR1; } } else { if (!FC_FROM_DS(fc)) { /* From DS and not To DS */ *srcp = ADDR2; *dstp = ADDR3; } else { /* To DS and From DS */ *srcp = ADDR4; *dstp = ADDR3; } } #undef ADDR1 #undef ADDR2 #undef ADDR3 #undef ADDR4 } static void get_mgmt_src_dst_mac(const u_char *p, const uint8_t **srcp, const uint8_t **dstp) { const struct mgmt_header_t *hp = (const struct mgmt_header_t *) p; if (srcp != NULL) *srcp = hp->sa; if (dstp != NULL) *dstp = hp->da; } /* * Print Header funcs */ static void data_header_print(netdissect_options *ndo, uint16_t fc, const u_char *p) { u_int subtype = FC_SUBTYPE(fc); if (DATA_FRAME_IS_CF_ACK(subtype) || DATA_FRAME_IS_CF_POLL(subtype) || DATA_FRAME_IS_QOS(subtype)) { ND_PRINT((ndo, "CF ")); if (DATA_FRAME_IS_CF_ACK(subtype)) { if (DATA_FRAME_IS_CF_POLL(subtype)) ND_PRINT((ndo, "Ack/Poll")); else ND_PRINT((ndo, "Ack")); } else { if (DATA_FRAME_IS_CF_POLL(subtype)) ND_PRINT((ndo, "Poll")); } if (DATA_FRAME_IS_QOS(subtype)) ND_PRINT((ndo, "+QoS")); ND_PRINT((ndo, " ")); } #define ADDR1 (p + 4) #define ADDR2 (p + 10) #define ADDR3 (p + 16) #define ADDR4 (p + 24) if (!FC_TO_DS(fc) && !FC_FROM_DS(fc)) { ND_PRINT((ndo, "DA:%s SA:%s BSSID:%s ", etheraddr_string(ndo, ADDR1), etheraddr_string(ndo, ADDR2), etheraddr_string(ndo, ADDR3))); } else if (!FC_TO_DS(fc) && FC_FROM_DS(fc)) { ND_PRINT((ndo, "DA:%s BSSID:%s SA:%s ", etheraddr_string(ndo, ADDR1), etheraddr_string(ndo, ADDR2), etheraddr_string(ndo, ADDR3))); } else if (FC_TO_DS(fc) && !FC_FROM_DS(fc)) { ND_PRINT((ndo, "BSSID:%s SA:%s DA:%s ", etheraddr_string(ndo, ADDR1), etheraddr_string(ndo, ADDR2), etheraddr_string(ndo, ADDR3))); } else if (FC_TO_DS(fc) && FC_FROM_DS(fc)) { ND_PRINT((ndo, "RA:%s TA:%s DA:%s SA:%s ", etheraddr_string(ndo, ADDR1), etheraddr_string(ndo, ADDR2), etheraddr_string(ndo, ADDR3), etheraddr_string(ndo, ADDR4))); } #undef ADDR1 #undef ADDR2 #undef ADDR3 #undef ADDR4 } static void mgmt_header_print(netdissect_options *ndo, const u_char *p) { const struct mgmt_header_t *hp = (const struct mgmt_header_t *) p; ND_PRINT((ndo, "BSSID:%s DA:%s SA:%s ", etheraddr_string(ndo, (hp)->bssid), etheraddr_string(ndo, (hp)->da), etheraddr_string(ndo, (hp)->sa))); } static void ctrl_header_print(netdissect_options *ndo, uint16_t fc, const u_char *p) { switch (FC_SUBTYPE(fc)) { case CTRL_BAR: ND_PRINT((ndo, " RA:%s TA:%s CTL(%x) SEQ(%u) ", etheraddr_string(ndo, ((const struct ctrl_bar_hdr_t *)p)->ra), etheraddr_string(ndo, ((const struct ctrl_bar_hdr_t *)p)->ta), EXTRACT_LE_16BITS(&(((const struct ctrl_bar_hdr_t *)p)->ctl)), EXTRACT_LE_16BITS(&(((const struct ctrl_bar_hdr_t *)p)->seq)))); break; case CTRL_BA: ND_PRINT((ndo, "RA:%s ", etheraddr_string(ndo, ((const struct ctrl_ba_hdr_t *)p)->ra))); break; case CTRL_PS_POLL: ND_PRINT((ndo, "BSSID:%s TA:%s ", etheraddr_string(ndo, ((const struct ctrl_ps_poll_hdr_t *)p)->bssid), etheraddr_string(ndo, ((const struct ctrl_ps_poll_hdr_t *)p)->ta))); break; case CTRL_RTS: ND_PRINT((ndo, "RA:%s TA:%s ", etheraddr_string(ndo, ((const struct ctrl_rts_hdr_t *)p)->ra), etheraddr_string(ndo, ((const struct ctrl_rts_hdr_t *)p)->ta))); break; case CTRL_CTS: ND_PRINT((ndo, "RA:%s ", etheraddr_string(ndo, ((const struct ctrl_cts_hdr_t *)p)->ra))); break; case CTRL_ACK: ND_PRINT((ndo, "RA:%s ", etheraddr_string(ndo, ((const struct ctrl_ack_hdr_t *)p)->ra))); break; case CTRL_CF_END: ND_PRINT((ndo, "RA:%s BSSID:%s ", etheraddr_string(ndo, ((const struct ctrl_end_hdr_t *)p)->ra), etheraddr_string(ndo, ((const struct ctrl_end_hdr_t *)p)->bssid))); break; case CTRL_END_ACK: ND_PRINT((ndo, "RA:%s BSSID:%s ", etheraddr_string(ndo, ((const struct ctrl_end_ack_hdr_t *)p)->ra), etheraddr_string(ndo, ((const struct ctrl_end_ack_hdr_t *)p)->bssid))); break; default: /* We shouldn't get here - we should already have quit */ break; } } static int extract_header_length(netdissect_options *ndo, uint16_t fc) { int len; switch (FC_TYPE(fc)) { case T_MGMT: return MGMT_HDRLEN; case T_CTRL: switch (FC_SUBTYPE(fc)) { case CTRL_CONTROL_WRAPPER: return CTRL_CONTROL_WRAPPER_HDRLEN; case CTRL_BAR: return CTRL_BAR_HDRLEN; case CTRL_BA: return CTRL_BA_HDRLEN; case CTRL_PS_POLL: return CTRL_PS_POLL_HDRLEN; case CTRL_RTS: return CTRL_RTS_HDRLEN; case CTRL_CTS: return CTRL_CTS_HDRLEN; case CTRL_ACK: return CTRL_ACK_HDRLEN; case CTRL_CF_END: return CTRL_END_HDRLEN; case CTRL_END_ACK: return CTRL_END_ACK_HDRLEN; default: ND_PRINT((ndo, "unknown 802.11 ctrl frame subtype (%d)", FC_SUBTYPE(fc))); return 0; } case T_DATA: len = (FC_TO_DS(fc) && FC_FROM_DS(fc)) ? 30 : 24; if (DATA_FRAME_IS_QOS(FC_SUBTYPE(fc))) len += 2; return len; default: ND_PRINT((ndo, "unknown 802.11 frame type (%d)", FC_TYPE(fc))); return 0; } } static int extract_mesh_header_length(const u_char *p) { return (p[0] &~ 3) ? 0 : 6*(1 + (p[0] & 3)); } /* * Print the 802.11 MAC header. */ static void ieee_802_11_hdr_print(netdissect_options *ndo, uint16_t fc, const u_char *p, u_int hdrlen, u_int meshdrlen) { if (ndo->ndo_vflag) { if (FC_MORE_DATA(fc)) ND_PRINT((ndo, "More Data ")); if (FC_MORE_FLAG(fc)) ND_PRINT((ndo, "More Fragments ")); if (FC_POWER_MGMT(fc)) ND_PRINT((ndo, "Pwr Mgmt ")); if (FC_RETRY(fc)) ND_PRINT((ndo, "Retry ")); if (FC_ORDER(fc)) ND_PRINT((ndo, "Strictly Ordered ")); if (FC_PROTECTED(fc)) ND_PRINT((ndo, "Protected ")); if (FC_TYPE(fc) != T_CTRL || FC_SUBTYPE(fc) != CTRL_PS_POLL) ND_PRINT((ndo, "%dus ", EXTRACT_LE_16BITS( &((const struct mgmt_header_t *)p)->duration))); } if (meshdrlen != 0) { const struct meshcntl_t *mc = (const struct meshcntl_t *)&p[hdrlen - meshdrlen]; int ae = mc->flags & 3; ND_PRINT((ndo, "MeshData (AE %d TTL %u seq %u", ae, mc->ttl, EXTRACT_LE_32BITS(mc->seq))); if (ae > 0) ND_PRINT((ndo, " A4:%s", etheraddr_string(ndo, mc->addr4))); if (ae > 1) ND_PRINT((ndo, " A5:%s", etheraddr_string(ndo, mc->addr5))); if (ae > 2) ND_PRINT((ndo, " A6:%s", etheraddr_string(ndo, mc->addr6))); ND_PRINT((ndo, ") ")); } switch (FC_TYPE(fc)) { case T_MGMT: mgmt_header_print(ndo, p); break; case T_CTRL: ctrl_header_print(ndo, fc, p); break; case T_DATA: data_header_print(ndo, fc, p); break; default: break; } } #ifndef roundup2 #define roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */ #endif static const char tstr[] = "[|802.11]"; static u_int ieee802_11_print(netdissect_options *ndo, const u_char *p, u_int length, u_int orig_caplen, int pad, u_int fcslen) { uint16_t fc; u_int caplen, hdrlen, meshdrlen; struct lladdr_info src, dst; int llc_hdrlen; caplen = orig_caplen; /* Remove FCS, if present */ if (length < fcslen) { ND_PRINT((ndo, "%s", tstr)); return caplen; } length -= fcslen; if (caplen > length) { /* Amount of FCS in actual packet data, if any */ fcslen = caplen - length; caplen -= fcslen; ndo->ndo_snapend -= fcslen; } if (caplen < IEEE802_11_FC_LEN) { ND_PRINT((ndo, "%s", tstr)); return orig_caplen; } fc = EXTRACT_LE_16BITS(p); hdrlen = extract_header_length(ndo, fc); if (hdrlen == 0) { /* Unknown frame type or control frame subtype; quit. */ return (0); } if (pad) hdrlen = roundup2(hdrlen, 4); if (ndo->ndo_Hflag && FC_TYPE(fc) == T_DATA && DATA_FRAME_IS_QOS(FC_SUBTYPE(fc))) { if (caplen < hdrlen + 1) { ND_PRINT((ndo, "%s", tstr)); return hdrlen; } meshdrlen = extract_mesh_header_length(p+hdrlen); hdrlen += meshdrlen; } else meshdrlen = 0; if (caplen < hdrlen) { ND_PRINT((ndo, "%s", tstr)); return hdrlen; } if (ndo->ndo_eflag) ieee_802_11_hdr_print(ndo, fc, p, hdrlen, meshdrlen); /* * Go past the 802.11 header. */ length -= hdrlen; caplen -= hdrlen; p += hdrlen; src.addr_string = etheraddr_string; dst.addr_string = etheraddr_string; switch (FC_TYPE(fc)) { case T_MGMT: get_mgmt_src_dst_mac(p - hdrlen, &src.addr, &dst.addr); if (!mgmt_body_print(ndo, fc, src.addr, p, length)) { ND_PRINT((ndo, "%s", tstr)); return hdrlen; } break; case T_CTRL: if (!ctrl_body_print(ndo, fc, p - hdrlen)) { ND_PRINT((ndo, "%s", tstr)); return hdrlen; } break; case T_DATA: if (DATA_FRAME_IS_NULL(FC_SUBTYPE(fc))) return hdrlen; /* no-data frame */ /* There may be a problem w/ AP not having this bit set */ if (FC_PROTECTED(fc)) { ND_PRINT((ndo, "Data")); if (!wep_print(ndo, p)) { ND_PRINT((ndo, "%s", tstr)); return hdrlen; } } else { get_data_src_dst_mac(fc, p - hdrlen, &src.addr, &dst.addr); llc_hdrlen = llc_print(ndo, p, length, caplen, &src, &dst); if (llc_hdrlen < 0) { /* * Some kinds of LLC packet we cannot * handle intelligently */ if (!ndo->ndo_suppress_default_print) ND_DEFAULTPRINT(p, caplen); llc_hdrlen = -llc_hdrlen; } hdrlen += llc_hdrlen; } break; default: /* We shouldn't get here - we should already have quit */ break; } return hdrlen; } /* * This is the top level routine of the printer. 'p' points * to the 802.11 header of the packet, 'h->ts' is the timestamp, * 'h->len' is the length of the packet off the wire, and 'h->caplen' * is the number of bytes actually captured. */ u_int ieee802_11_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) { return ieee802_11_print(ndo, p, h->len, h->caplen, 0, 0); } /* $FreeBSD: src/sys/net80211/ieee80211_radiotap.h,v 1.5 2005/01/22 20:12:05 sam Exp $ */ /* NetBSD: ieee802_11_radio.h,v 1.2 2006/02/26 03:04:03 dyoung Exp */ /*- * Copyright (c) 2003, 2004 David Young. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of David Young may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED BY DAVID YOUNG ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID * YOUNG BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. */ /* A generic radio capture format is desirable. It must be * rigidly defined (e.g., units for fields should be given), * and easily extensible. * * The following is an extensible radio capture format. It is * based on a bitmap indicating which fields are present. * * I am trying to describe precisely what the application programmer * should expect in the following, and for that reason I tell the * units and origin of each measurement (where it applies), or else I * use sufficiently weaselly language ("is a monotonically nondecreasing * function of...") that I cannot set false expectations for lawyerly * readers. */ /* * The radio capture header precedes the 802.11 header. * * Note well: all radiotap fields are little-endian. */ struct ieee80211_radiotap_header { uint8_t it_version; /* Version 0. Only increases * for drastic changes, * introduction of compatible * new fields does not count. */ uint8_t it_pad; uint16_t it_len; /* length of the whole * header in bytes, including * it_version, it_pad, * it_len, and data fields. */ uint32_t it_present; /* A bitmap telling which * fields are present. Set bit 31 * (0x80000000) to extend the * bitmap by another 32 bits. * Additional extensions are made * by setting bit 31. */ }; /* Name Data type Units * ---- --------- ----- * * IEEE80211_RADIOTAP_TSFT uint64_t microseconds * * Value in microseconds of the MAC's 64-bit 802.11 Time * Synchronization Function timer when the first bit of the * MPDU arrived at the MAC. For received frames, only. * * IEEE80211_RADIOTAP_CHANNEL 2 x uint16_t MHz, bitmap * * Tx/Rx frequency in MHz, followed by flags (see below). * Note that IEEE80211_RADIOTAP_XCHANNEL must be used to * represent an HT channel as there is not enough room in * the flags word. * * IEEE80211_RADIOTAP_FHSS uint16_t see below * * For frequency-hopping radios, the hop set (first byte) * and pattern (second byte). * * IEEE80211_RADIOTAP_RATE uint8_t 500kb/s or index * * Tx/Rx data rate. If bit 0x80 is set then it represents an * an MCS index and not an IEEE rate. * * IEEE80211_RADIOTAP_DBM_ANTSIGNAL int8_t decibels from * one milliwatt (dBm) * * RF signal power at the antenna, decibel difference from * one milliwatt. * * IEEE80211_RADIOTAP_DBM_ANTNOISE int8_t decibels from * one milliwatt (dBm) * * RF noise power at the antenna, decibel difference from one * milliwatt. * * IEEE80211_RADIOTAP_DB_ANTSIGNAL uint8_t decibel (dB) * * RF signal power at the antenna, decibel difference from an * arbitrary, fixed reference. * * IEEE80211_RADIOTAP_DB_ANTNOISE uint8_t decibel (dB) * * RF noise power at the antenna, decibel difference from an * arbitrary, fixed reference point. * * IEEE80211_RADIOTAP_LOCK_QUALITY uint16_t unitless * * Quality of Barker code lock. Unitless. Monotonically * nondecreasing with "better" lock strength. Called "Signal * Quality" in datasheets. (Is there a standard way to measure * this?) * * IEEE80211_RADIOTAP_TX_ATTENUATION uint16_t unitless * * Transmit power expressed as unitless distance from max * power set at factory calibration. 0 is max power. * Monotonically nondecreasing with lower power levels. * * IEEE80211_RADIOTAP_DB_TX_ATTENUATION uint16_t decibels (dB) * * Transmit power expressed as decibel distance from max power * set at factory calibration. 0 is max power. Monotonically * nondecreasing with lower power levels. * * IEEE80211_RADIOTAP_DBM_TX_POWER int8_t decibels from * one milliwatt (dBm) * * Transmit power expressed as dBm (decibels from a 1 milliwatt * reference). This is the absolute power level measured at * the antenna port. * * IEEE80211_RADIOTAP_FLAGS uint8_t bitmap * * Properties of transmitted and received frames. See flags * defined below. * * IEEE80211_RADIOTAP_ANTENNA uint8_t antenna index * * Unitless indication of the Rx/Tx antenna for this packet. * The first antenna is antenna 0. * * IEEE80211_RADIOTAP_RX_FLAGS uint16_t bitmap * * Properties of received frames. See flags defined below. * * IEEE80211_RADIOTAP_XCHANNEL uint32_t bitmap * uint16_t MHz * uint8_t channel number * uint8_t .5 dBm * * Extended channel specification: flags (see below) followed by * frequency in MHz, the corresponding IEEE channel number, and * finally the maximum regulatory transmit power cap in .5 dBm * units. This property supersedes IEEE80211_RADIOTAP_CHANNEL * and only one of the two should be present. * * IEEE80211_RADIOTAP_MCS uint8_t known * uint8_t flags * uint8_t mcs * * Bitset indicating which fields have known values, followed * by bitset of flag values, followed by the MCS rate index as * in IEEE 802.11n. * * * IEEE80211_RADIOTAP_AMPDU_STATUS u32, u16, u8, u8 unitless * * Contains the AMPDU information for the subframe. * * IEEE80211_RADIOTAP_VHT u16, u8, u8, u8[4], u8, u8, u16 * * Contains VHT information about this frame. * * IEEE80211_RADIOTAP_VENDOR_NAMESPACE * uint8_t OUI[3] * uint8_t subspace * uint16_t length * * The Vendor Namespace Field contains three sub-fields. The first * sub-field is 3 bytes long. It contains the vendor's IEEE 802 * Organizationally Unique Identifier (OUI). The fourth byte is a * vendor-specific "namespace selector." * */ enum ieee80211_radiotap_type { IEEE80211_RADIOTAP_TSFT = 0, IEEE80211_RADIOTAP_FLAGS = 1, IEEE80211_RADIOTAP_RATE = 2, IEEE80211_RADIOTAP_CHANNEL = 3, IEEE80211_RADIOTAP_FHSS = 4, IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5, IEEE80211_RADIOTAP_DBM_ANTNOISE = 6, IEEE80211_RADIOTAP_LOCK_QUALITY = 7, IEEE80211_RADIOTAP_TX_ATTENUATION = 8, IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9, IEEE80211_RADIOTAP_DBM_TX_POWER = 10, IEEE80211_RADIOTAP_ANTENNA = 11, IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12, IEEE80211_RADIOTAP_DB_ANTNOISE = 13, IEEE80211_RADIOTAP_RX_FLAGS = 14, /* NB: gap for netbsd definitions */ IEEE80211_RADIOTAP_XCHANNEL = 18, IEEE80211_RADIOTAP_MCS = 19, IEEE80211_RADIOTAP_AMPDU_STATUS = 20, IEEE80211_RADIOTAP_VHT = 21, IEEE80211_RADIOTAP_NAMESPACE = 29, IEEE80211_RADIOTAP_VENDOR_NAMESPACE = 30, IEEE80211_RADIOTAP_EXT = 31 }; /* channel attributes */ #define IEEE80211_CHAN_TURBO 0x00010 /* Turbo channel */ #define IEEE80211_CHAN_CCK 0x00020 /* CCK channel */ #define IEEE80211_CHAN_OFDM 0x00040 /* OFDM channel */ #define IEEE80211_CHAN_2GHZ 0x00080 /* 2 GHz spectrum channel. */ #define IEEE80211_CHAN_5GHZ 0x00100 /* 5 GHz spectrum channel */ #define IEEE80211_CHAN_PASSIVE 0x00200 /* Only passive scan allowed */ #define IEEE80211_CHAN_DYN 0x00400 /* Dynamic CCK-OFDM channel */ #define IEEE80211_CHAN_GFSK 0x00800 /* GFSK channel (FHSS PHY) */ #define IEEE80211_CHAN_GSM 0x01000 /* 900 MHz spectrum channel */ #define IEEE80211_CHAN_STURBO 0x02000 /* 11a static turbo channel only */ #define IEEE80211_CHAN_HALF 0x04000 /* Half rate channel */ #define IEEE80211_CHAN_QUARTER 0x08000 /* Quarter rate channel */ #define IEEE80211_CHAN_HT20 0x10000 /* HT 20 channel */ #define IEEE80211_CHAN_HT40U 0x20000 /* HT 40 channel w/ ext above */ #define IEEE80211_CHAN_HT40D 0x40000 /* HT 40 channel w/ ext below */ /* Useful combinations of channel characteristics, borrowed from Ethereal */ #define IEEE80211_CHAN_A \ (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM) #define IEEE80211_CHAN_B \ (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK) #define IEEE80211_CHAN_G \ (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN) #define IEEE80211_CHAN_TA \ (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM | IEEE80211_CHAN_TURBO) #define IEEE80211_CHAN_TG \ (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN | IEEE80211_CHAN_TURBO) /* For IEEE80211_RADIOTAP_FLAGS */ #define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received * during CFP */ #define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received * with short * preamble */ #define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received * with WEP encryption */ #define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received * with fragmentation */ #define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */ #define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding between * 802.11 header and payload * (to 32-bit boundary) */ #define IEEE80211_RADIOTAP_F_BADFCS 0x40 /* does not pass FCS check */ /* For IEEE80211_RADIOTAP_RX_FLAGS */ #define IEEE80211_RADIOTAP_F_RX_BADFCS 0x0001 /* frame failed crc check */ #define IEEE80211_RADIOTAP_F_RX_PLCP_CRC 0x0002 /* frame failed PLCP CRC check */ /* For IEEE80211_RADIOTAP_MCS known */ #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_KNOWN 0x01 #define IEEE80211_RADIOTAP_MCS_MCS_INDEX_KNOWN 0x02 /* MCS index field */ #define IEEE80211_RADIOTAP_MCS_GUARD_INTERVAL_KNOWN 0x04 #define IEEE80211_RADIOTAP_MCS_HT_FORMAT_KNOWN 0x08 #define IEEE80211_RADIOTAP_MCS_FEC_TYPE_KNOWN 0x10 #define IEEE80211_RADIOTAP_MCS_STBC_KNOWN 0x20 #define IEEE80211_RADIOTAP_MCS_NESS_KNOWN 0x40 #define IEEE80211_RADIOTAP_MCS_NESS_BIT_1 0x80 /* For IEEE80211_RADIOTAP_MCS flags */ #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_MASK 0x03 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_20 0 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_40 1 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_20L 2 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_20U 3 #define IEEE80211_RADIOTAP_MCS_SHORT_GI 0x04 /* short guard interval */ #define IEEE80211_RADIOTAP_MCS_HT_GREENFIELD 0x08 #define IEEE80211_RADIOTAP_MCS_FEC_LDPC 0x10 #define IEEE80211_RADIOTAP_MCS_STBC_MASK 0x60 #define IEEE80211_RADIOTAP_MCS_STBC_1 1 #define IEEE80211_RADIOTAP_MCS_STBC_2 2 #define IEEE80211_RADIOTAP_MCS_STBC_3 3 #define IEEE80211_RADIOTAP_MCS_STBC_SHIFT 5 #define IEEE80211_RADIOTAP_MCS_NESS_BIT_0 0x80 /* For IEEE80211_RADIOTAP_AMPDU_STATUS */ #define IEEE80211_RADIOTAP_AMPDU_REPORT_ZEROLEN 0x0001 #define IEEE80211_RADIOTAP_AMPDU_IS_ZEROLEN 0x0002 #define IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN 0x0004 #define IEEE80211_RADIOTAP_AMPDU_IS_LAST 0x0008 #define IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR 0x0010 #define IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN 0x0020 /* For IEEE80211_RADIOTAP_VHT known */ #define IEEE80211_RADIOTAP_VHT_STBC_KNOWN 0x0001 #define IEEE80211_RADIOTAP_VHT_TXOP_PS_NA_KNOWN 0x0002 #define IEEE80211_RADIOTAP_VHT_GUARD_INTERVAL_KNOWN 0x0004 #define IEEE80211_RADIOTAP_VHT_SGI_NSYM_DIS_KNOWN 0x0008 #define IEEE80211_RADIOTAP_VHT_LDPC_EXTRA_OFDM_SYM_KNOWN 0x0010 #define IEEE80211_RADIOTAP_VHT_BEAMFORMED_KNOWN 0x0020 #define IEEE80211_RADIOTAP_VHT_BANDWIDTH_KNOWN 0x0040 #define IEEE80211_RADIOTAP_VHT_GROUP_ID_KNOWN 0x0080 #define IEEE80211_RADIOTAP_VHT_PARTIAL_AID_KNOWN 0x0100 /* For IEEE80211_RADIOTAP_VHT flags */ #define IEEE80211_RADIOTAP_VHT_STBC 0x01 #define IEEE80211_RADIOTAP_VHT_TXOP_PS_NA 0x02 #define IEEE80211_RADIOTAP_VHT_SHORT_GI 0x04 #define IEEE80211_RADIOTAP_VHT_SGI_NSYM_M10_9 0x08 #define IEEE80211_RADIOTAP_VHT_LDPC_EXTRA_OFDM_SYM 0x10 #define IEEE80211_RADIOTAP_VHT_BEAMFORMED 0x20 #define IEEE80211_RADIOTAP_VHT_BANDWIDTH_MASK 0x1f #define IEEE80211_RADIOTAP_VHT_NSS_MASK 0x0f #define IEEE80211_RADIOTAP_VHT_MCS_MASK 0xf0 #define IEEE80211_RADIOTAP_VHT_MCS_SHIFT 4 #define IEEE80211_RADIOTAP_CODING_LDPC_USERn 0x01 #define IEEE80211_CHAN_FHSS \ (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_GFSK) #define IEEE80211_CHAN_A \ (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM) #define IEEE80211_CHAN_B \ (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK) #define IEEE80211_CHAN_PUREG \ (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_OFDM) #define IEEE80211_CHAN_G \ (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN) #define IS_CHAN_FHSS(flags) \ ((flags & IEEE80211_CHAN_FHSS) == IEEE80211_CHAN_FHSS) #define IS_CHAN_A(flags) \ ((flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) #define IS_CHAN_B(flags) \ ((flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) #define IS_CHAN_PUREG(flags) \ ((flags & IEEE80211_CHAN_PUREG) == IEEE80211_CHAN_PUREG) #define IS_CHAN_G(flags) \ ((flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) #define IS_CHAN_ANYG(flags) \ (IS_CHAN_PUREG(flags) || IS_CHAN_G(flags)) static void print_chaninfo(netdissect_options *ndo, uint16_t freq, int flags, int presentflags) { ND_PRINT((ndo, "%u MHz", freq)); if (presentflags & (1 << IEEE80211_RADIOTAP_MCS)) { /* * We have the MCS field, so this is 11n, regardless * of what the channel flags say. */ ND_PRINT((ndo, " 11n")); } else { if (IS_CHAN_FHSS(flags)) ND_PRINT((ndo, " FHSS")); if (IS_CHAN_A(flags)) { if (flags & IEEE80211_CHAN_HALF) ND_PRINT((ndo, " 11a/10Mhz")); else if (flags & IEEE80211_CHAN_QUARTER) ND_PRINT((ndo, " 11a/5Mhz")); else ND_PRINT((ndo, " 11a")); } if (IS_CHAN_ANYG(flags)) { if (flags & IEEE80211_CHAN_HALF) ND_PRINT((ndo, " 11g/10Mhz")); else if (flags & IEEE80211_CHAN_QUARTER) ND_PRINT((ndo, " 11g/5Mhz")); else ND_PRINT((ndo, " 11g")); } else if (IS_CHAN_B(flags)) ND_PRINT((ndo, " 11b")); if (flags & IEEE80211_CHAN_TURBO) ND_PRINT((ndo, " Turbo")); } /* * These apply to 11n. */ if (flags & IEEE80211_CHAN_HT20) ND_PRINT((ndo, " ht/20")); else if (flags & IEEE80211_CHAN_HT40D) ND_PRINT((ndo, " ht/40-")); else if (flags & IEEE80211_CHAN_HT40U) ND_PRINT((ndo, " ht/40+")); ND_PRINT((ndo, " ")); } static int print_radiotap_field(netdissect_options *ndo, struct cpack_state *s, uint32_t bit, uint8_t *flagsp, uint32_t presentflags) { u_int i; int rc; switch (bit) { case IEEE80211_RADIOTAP_TSFT: { uint64_t tsft; rc = cpack_uint64(s, &tsft); if (rc != 0) goto trunc; ND_PRINT((ndo, "%" PRIu64 "us tsft ", tsft)); break; } case IEEE80211_RADIOTAP_FLAGS: { uint8_t flagsval; rc = cpack_uint8(s, &flagsval); if (rc != 0) goto trunc; *flagsp = flagsval; if (flagsval & IEEE80211_RADIOTAP_F_CFP) ND_PRINT((ndo, "cfp ")); if (flagsval & IEEE80211_RADIOTAP_F_SHORTPRE) ND_PRINT((ndo, "short preamble ")); if (flagsval & IEEE80211_RADIOTAP_F_WEP) ND_PRINT((ndo, "wep ")); if (flagsval & IEEE80211_RADIOTAP_F_FRAG) ND_PRINT((ndo, "fragmented ")); if (flagsval & IEEE80211_RADIOTAP_F_BADFCS) ND_PRINT((ndo, "bad-fcs ")); break; } case IEEE80211_RADIOTAP_RATE: { uint8_t rate; rc = cpack_uint8(s, &rate); if (rc != 0) goto trunc; /* * XXX On FreeBSD rate & 0x80 means we have an MCS. On * Linux and AirPcap it does not. (What about * Mac OS X, NetBSD, OpenBSD, and DragonFly BSD?) * * This is an issue either for proprietary extensions * to 11a or 11g, which do exist, or for 11n * implementations that stuff a rate value into * this field, which also appear to exist. * * We currently handle that by assuming that * if the 0x80 bit is set *and* the remaining * bits have a value between 0 and 15 it's * an MCS value, otherwise it's a rate. If * there are cases where systems that use * "0x80 + MCS index" for MCS indices > 15, * or stuff a rate value here between 64 and * 71.5 Mb/s in here, we'll need a preference * setting. Such rates do exist, e.g. 11n * MCS 7 at 20 MHz with a long guard interval. */ if (rate >= 0x80 && rate <= 0x8f) { /* * XXX - we don't know the channel width * or guard interval length, so we can't * convert this to a data rate. * * If you want us to show a data rate, * use the MCS field, not the Rate field; * the MCS field includes not only the * MCS index, it also includes bandwidth * and guard interval information. * * XXX - can we get the channel width * from XChannel and the guard interval * information from Flags, at least on * FreeBSD? */ ND_PRINT((ndo, "MCS %u ", rate & 0x7f)); } else ND_PRINT((ndo, "%2.1f Mb/s ", .5 * rate)); break; } case IEEE80211_RADIOTAP_CHANNEL: { uint16_t frequency; uint16_t flags; rc = cpack_uint16(s, &frequency); if (rc != 0) goto trunc; rc = cpack_uint16(s, &flags); if (rc != 0) goto trunc; /* * If CHANNEL and XCHANNEL are both present, skip * CHANNEL. */ if (presentflags & (1 << IEEE80211_RADIOTAP_XCHANNEL)) break; print_chaninfo(ndo, frequency, flags, presentflags); break; } case IEEE80211_RADIOTAP_FHSS: { uint8_t hopset; uint8_t hoppat; rc = cpack_uint8(s, &hopset); if (rc != 0) goto trunc; rc = cpack_uint8(s, &hoppat); if (rc != 0) goto trunc; ND_PRINT((ndo, "fhset %d fhpat %d ", hopset, hoppat)); break; } case IEEE80211_RADIOTAP_DBM_ANTSIGNAL: { int8_t dbm_antsignal; rc = cpack_int8(s, &dbm_antsignal); if (rc != 0) goto trunc; ND_PRINT((ndo, "%ddBm signal ", dbm_antsignal)); break; } case IEEE80211_RADIOTAP_DBM_ANTNOISE: { int8_t dbm_antnoise; rc = cpack_int8(s, &dbm_antnoise); if (rc != 0) goto trunc; ND_PRINT((ndo, "%ddBm noise ", dbm_antnoise)); break; } case IEEE80211_RADIOTAP_LOCK_QUALITY: { uint16_t lock_quality; rc = cpack_uint16(s, &lock_quality); if (rc != 0) goto trunc; ND_PRINT((ndo, "%u sq ", lock_quality)); break; } case IEEE80211_RADIOTAP_TX_ATTENUATION: { uint16_t tx_attenuation; rc = cpack_uint16(s, &tx_attenuation); if (rc != 0) goto trunc; ND_PRINT((ndo, "%d tx power ", -(int)tx_attenuation)); break; } case IEEE80211_RADIOTAP_DB_TX_ATTENUATION: { uint8_t db_tx_attenuation; rc = cpack_uint8(s, &db_tx_attenuation); if (rc != 0) goto trunc; ND_PRINT((ndo, "%ddB tx attenuation ", -(int)db_tx_attenuation)); break; } case IEEE80211_RADIOTAP_DBM_TX_POWER: { int8_t dbm_tx_power; rc = cpack_int8(s, &dbm_tx_power); if (rc != 0) goto trunc; ND_PRINT((ndo, "%ddBm tx power ", dbm_tx_power)); break; } case IEEE80211_RADIOTAP_ANTENNA: { uint8_t antenna; rc = cpack_uint8(s, &antenna); if (rc != 0) goto trunc; ND_PRINT((ndo, "antenna %u ", antenna)); break; } case IEEE80211_RADIOTAP_DB_ANTSIGNAL: { uint8_t db_antsignal; rc = cpack_uint8(s, &db_antsignal); if (rc != 0) goto trunc; ND_PRINT((ndo, "%ddB signal ", db_antsignal)); break; } case IEEE80211_RADIOTAP_DB_ANTNOISE: { uint8_t db_antnoise; rc = cpack_uint8(s, &db_antnoise); if (rc != 0) goto trunc; ND_PRINT((ndo, "%ddB noise ", db_antnoise)); break; } case IEEE80211_RADIOTAP_RX_FLAGS: { uint16_t rx_flags; rc = cpack_uint16(s, &rx_flags); if (rc != 0) goto trunc; /* Do nothing for now */ break; } case IEEE80211_RADIOTAP_XCHANNEL: { uint32_t flags; uint16_t frequency; uint8_t channel; uint8_t maxpower; rc = cpack_uint32(s, &flags); if (rc != 0) goto trunc; rc = cpack_uint16(s, &frequency); if (rc != 0) goto trunc; rc = cpack_uint8(s, &channel); if (rc != 0) goto trunc; rc = cpack_uint8(s, &maxpower); if (rc != 0) goto trunc; print_chaninfo(ndo, frequency, flags, presentflags); break; } case IEEE80211_RADIOTAP_MCS: { uint8_t known; uint8_t flags; uint8_t mcs_index; static const char *ht_bandwidth[4] = { "20 MHz", "40 MHz", "20 MHz (L)", "20 MHz (U)" }; float htrate; rc = cpack_uint8(s, &known); if (rc != 0) goto trunc; rc = cpack_uint8(s, &flags); if (rc != 0) goto trunc; rc = cpack_uint8(s, &mcs_index); if (rc != 0) goto trunc; if (known & IEEE80211_RADIOTAP_MCS_MCS_INDEX_KNOWN) { /* * We know the MCS index. */ if (mcs_index <= MAX_MCS_INDEX) { /* * And it's in-range. */ if (known & (IEEE80211_RADIOTAP_MCS_BANDWIDTH_KNOWN|IEEE80211_RADIOTAP_MCS_GUARD_INTERVAL_KNOWN)) { /* * And we know both the bandwidth and * the guard interval, so we can look * up the rate. */ htrate = ieee80211_float_htrates \ [mcs_index] \ [((flags & IEEE80211_RADIOTAP_MCS_BANDWIDTH_MASK) == IEEE80211_RADIOTAP_MCS_BANDWIDTH_40 ? 1 : 0)] \ [((flags & IEEE80211_RADIOTAP_MCS_SHORT_GI) ? 1 : 0)]; } else { /* * We don't know both the bandwidth * and the guard interval, so we can * only report the MCS index. */ htrate = 0.0; } } else { /* * The MCS value is out of range. */ htrate = 0.0; } if (htrate != 0.0) { /* * We have the rate. * Print it. */ ND_PRINT((ndo, "%.1f Mb/s MCS %u ", htrate, mcs_index)); } else { /* * We at least have the MCS index. * Print it. */ ND_PRINT((ndo, "MCS %u ", mcs_index)); } } if (known & IEEE80211_RADIOTAP_MCS_BANDWIDTH_KNOWN) { ND_PRINT((ndo, "%s ", ht_bandwidth[flags & IEEE80211_RADIOTAP_MCS_BANDWIDTH_MASK])); } if (known & IEEE80211_RADIOTAP_MCS_GUARD_INTERVAL_KNOWN) { ND_PRINT((ndo, "%s GI ", (flags & IEEE80211_RADIOTAP_MCS_SHORT_GI) ? "short" : "long")); } if (known & IEEE80211_RADIOTAP_MCS_HT_FORMAT_KNOWN) { ND_PRINT((ndo, "%s ", (flags & IEEE80211_RADIOTAP_MCS_HT_GREENFIELD) ? "greenfield" : "mixed")); } if (known & IEEE80211_RADIOTAP_MCS_FEC_TYPE_KNOWN) { ND_PRINT((ndo, "%s FEC ", (flags & IEEE80211_RADIOTAP_MCS_FEC_LDPC) ? "LDPC" : "BCC")); } if (known & IEEE80211_RADIOTAP_MCS_STBC_KNOWN) { ND_PRINT((ndo, "RX-STBC%u ", (flags & IEEE80211_RADIOTAP_MCS_STBC_MASK) >> IEEE80211_RADIOTAP_MCS_STBC_SHIFT)); } break; } case IEEE80211_RADIOTAP_AMPDU_STATUS: { uint32_t reference_num; uint16_t flags; uint8_t delim_crc; uint8_t reserved; rc = cpack_uint32(s, &reference_num); if (rc != 0) goto trunc; rc = cpack_uint16(s, &flags); if (rc != 0) goto trunc; rc = cpack_uint8(s, &delim_crc); if (rc != 0) goto trunc; rc = cpack_uint8(s, &reserved); if (rc != 0) goto trunc; /* Do nothing for now */ break; } case IEEE80211_RADIOTAP_VHT: { uint16_t known; uint8_t flags; uint8_t bandwidth; uint8_t mcs_nss[4]; uint8_t coding; uint8_t group_id; uint16_t partial_aid; static const char *vht_bandwidth[32] = { "20 MHz", "40 MHz", "20 MHz (L)", "20 MHz (U)", "80 MHz", "80 MHz (L)", "80 MHz (U)", "80 MHz (LL)", "80 MHz (LU)", "80 MHz (UL)", "80 MHz (UU)", "160 MHz", "160 MHz (L)", "160 MHz (U)", "160 MHz (LL)", "160 MHz (LU)", "160 MHz (UL)", "160 MHz (UU)", "160 MHz (LLL)", "160 MHz (LLU)", "160 MHz (LUL)", "160 MHz (UUU)", "160 MHz (ULL)", "160 MHz (ULU)", "160 MHz (UUL)", "160 MHz (UUU)", "unknown (26)", "unknown (27)", "unknown (28)", "unknown (29)", "unknown (30)", "unknown (31)" }; rc = cpack_uint16(s, &known); if (rc != 0) goto trunc; rc = cpack_uint8(s, &flags); if (rc != 0) goto trunc; rc = cpack_uint8(s, &bandwidth); if (rc != 0) goto trunc; for (i = 0; i < 4; i++) { rc = cpack_uint8(s, &mcs_nss[i]); if (rc != 0) goto trunc; } rc = cpack_uint8(s, &coding); if (rc != 0) goto trunc; rc = cpack_uint8(s, &group_id); if (rc != 0) goto trunc; rc = cpack_uint16(s, &partial_aid); if (rc != 0) goto trunc; for (i = 0; i < 4; i++) { u_int nss, mcs; nss = mcs_nss[i] & IEEE80211_RADIOTAP_VHT_NSS_MASK; mcs = (mcs_nss[i] & IEEE80211_RADIOTAP_VHT_MCS_MASK) >> IEEE80211_RADIOTAP_VHT_MCS_SHIFT; if (nss == 0) continue; ND_PRINT((ndo, "User %u MCS %u ", i, mcs)); ND_PRINT((ndo, "%s FEC ", (coding & (IEEE80211_RADIOTAP_CODING_LDPC_USERn << i)) ? "LDPC" : "BCC")); } if (known & IEEE80211_RADIOTAP_VHT_BANDWIDTH_KNOWN) { ND_PRINT((ndo, "%s ", vht_bandwidth[bandwidth & IEEE80211_RADIOTAP_VHT_BANDWIDTH_MASK])); } if (known & IEEE80211_RADIOTAP_VHT_GUARD_INTERVAL_KNOWN) { ND_PRINT((ndo, "%s GI ", (flags & IEEE80211_RADIOTAP_VHT_SHORT_GI) ? "short" : "long")); } break; } default: /* this bit indicates a field whose * size we do not know, so we cannot * proceed. Just print the bit number. */ ND_PRINT((ndo, "[bit %u] ", bit)); return -1; } return 0; trunc: ND_PRINT((ndo, "%s", tstr)); return rc; } static int print_in_radiotap_namespace(netdissect_options *ndo, struct cpack_state *s, uint8_t *flags, uint32_t presentflags, int bit0) { #define BITNO_32(x) (((x) >> 16) ? 16 + BITNO_16((x) >> 16) : BITNO_16((x))) #define BITNO_16(x) (((x) >> 8) ? 8 + BITNO_8((x) >> 8) : BITNO_8((x))) #define BITNO_8(x) (((x) >> 4) ? 4 + BITNO_4((x) >> 4) : BITNO_4((x))) #define BITNO_4(x) (((x) >> 2) ? 2 + BITNO_2((x) >> 2) : BITNO_2((x))) #define BITNO_2(x) (((x) & 2) ? 1 : 0) uint32_t present, next_present; int bitno; enum ieee80211_radiotap_type bit; int rc; for (present = presentflags; present; present = next_present) { /* * Clear the least significant bit that is set. */ next_present = present & (present - 1); /* * Get the bit number, within this presence word, * of the remaining least significant bit that * is set. */ bitno = BITNO_32(present ^ next_present); /* * Stop if this is one of the "same meaning * in all presence flags" bits. */ if (bitno >= IEEE80211_RADIOTAP_NAMESPACE) break; /* * Get the radiotap bit number of that bit. */ bit = (enum ieee80211_radiotap_type)(bit0 + bitno); rc = print_radiotap_field(ndo, s, bit, flags, presentflags); if (rc != 0) return rc; } return 0; } u_int ieee802_11_radio_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen) { #define BIT(n) (1U << n) #define IS_EXTENDED(__p) \ (EXTRACT_LE_32BITS(__p) & BIT(IEEE80211_RADIOTAP_EXT)) != 0 struct cpack_state cpacker; const struct ieee80211_radiotap_header *hdr; uint32_t presentflags; const uint32_t *presentp, *last_presentp; int vendor_namespace; uint8_t vendor_oui[3]; uint8_t vendor_subnamespace; uint16_t skip_length; int bit0; u_int len; uint8_t flags; int pad; u_int fcslen; if (caplen < sizeof(*hdr)) { ND_PRINT((ndo, "%s", tstr)); return caplen; } hdr = (const struct ieee80211_radiotap_header *)p; len = EXTRACT_LE_16BITS(&hdr->it_len); if (len < sizeof(*hdr)) { /* * The length is the length of the entire header, so * it must be as large as the fixed-length part of * the header. */ ND_PRINT((ndo, "%s", tstr)); return caplen; } /* * If we don't have the entire radiotap header, just give up. */ if (caplen < len) { ND_PRINT((ndo, "%s", tstr)); return caplen; } cpack_init(&cpacker, (const uint8_t *)hdr, len); /* align against header start */ cpack_advance(&cpacker, sizeof(*hdr)); /* includes the 1st bitmap */ for (last_presentp = &hdr->it_present; (const u_char*)(last_presentp + 1) <= p + len && IS_EXTENDED(last_presentp); last_presentp++) cpack_advance(&cpacker, sizeof(hdr->it_present)); /* more bitmaps */ /* are there more bitmap extensions than bytes in header? */ if ((const u_char*)(last_presentp + 1) > p + len) { ND_PRINT((ndo, "%s", tstr)); return caplen; } /* * Start out at the beginning of the default radiotap namespace. */ bit0 = 0; vendor_namespace = 0; memset(vendor_oui, 0, 3); vendor_subnamespace = 0; skip_length = 0; /* Assume no flags */ flags = 0; /* Assume no Atheros padding between 802.11 header and body */ pad = 0; /* Assume no FCS at end of frame */ fcslen = 0; for (presentp = &hdr->it_present; presentp <= last_presentp; presentp++) { presentflags = EXTRACT_LE_32BITS(presentp); /* * If this is a vendor namespace, we don't handle it. */ if (vendor_namespace) { /* * Skip past the stuff we don't understand. * If we add support for any vendor namespaces, * it'd be added here; use vendor_oui and * vendor_subnamespace to interpret the fields. */ if (cpack_advance(&cpacker, skip_length) != 0) { /* * Ran out of space in the packet. */ break; } /* * We've skipped it all; nothing more to * skip. */ skip_length = 0; } else { if (print_in_radiotap_namespace(ndo, &cpacker, &flags, presentflags, bit0) != 0) { /* * Fatal error - can't process anything * more in the radiotap header. */ break; } } /* * Handle the namespace switch bits; we've already handled * the extension bit in all but the last word above. */ switch (presentflags & (BIT(IEEE80211_RADIOTAP_NAMESPACE)|BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE))) { case 0: /* * We're not changing namespaces. * advance to the next 32 bits in the current * namespace. */ bit0 += 32; break; case BIT(IEEE80211_RADIOTAP_NAMESPACE): /* * We're switching to the radiotap namespace. * Reset the presence-bitmap index to 0, and * reset the namespace to the default radiotap * namespace. */ bit0 = 0; vendor_namespace = 0; memset(vendor_oui, 0, 3); vendor_subnamespace = 0; skip_length = 0; break; case BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE): /* * We're switching to a vendor namespace. * Reset the presence-bitmap index to 0, * note that we're in a vendor namespace, * and fetch the fields of the Vendor Namespace * item. */ bit0 = 0; vendor_namespace = 1; if ((cpack_align_and_reserve(&cpacker, 2)) == NULL) { ND_PRINT((ndo, "%s", tstr)); break; } if (cpack_uint8(&cpacker, &vendor_oui[0]) != 0) { ND_PRINT((ndo, "%s", tstr)); break; } if (cpack_uint8(&cpacker, &vendor_oui[1]) != 0) { ND_PRINT((ndo, "%s", tstr)); break; } if (cpack_uint8(&cpacker, &vendor_oui[2]) != 0) { ND_PRINT((ndo, "%s", tstr)); break; } if (cpack_uint8(&cpacker, &vendor_subnamespace) != 0) { ND_PRINT((ndo, "%s", tstr)); break; } if (cpack_uint16(&cpacker, &skip_length) != 0) { ND_PRINT((ndo, "%s", tstr)); break; } break; default: /* * Illegal combination. The behavior in this * case is undefined by the radiotap spec; we * just ignore both bits. */ break; } } if (flags & IEEE80211_RADIOTAP_F_DATAPAD) pad = 1; /* Atheros padding */ if (flags & IEEE80211_RADIOTAP_F_FCS) fcslen = 4; /* FCS at end of packet */ return len + ieee802_11_print(ndo, p + len, length - len, caplen - len, pad, fcslen); #undef BITNO_32 #undef BITNO_16 #undef BITNO_8 #undef BITNO_4 #undef BITNO_2 #undef BIT } static u_int ieee802_11_avs_radio_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen) { uint32_t caphdr_len; if (caplen < 8) { ND_PRINT((ndo, "%s", tstr)); return caplen; } caphdr_len = EXTRACT_32BITS(p + 4); if (caphdr_len < 8) { /* * Yow! The capture header length is claimed not * to be large enough to include even the version * cookie or capture header length! */ ND_PRINT((ndo, "%s", tstr)); return caplen; } if (caplen < caphdr_len) { ND_PRINT((ndo, "%s", tstr)); return caplen; } return caphdr_len + ieee802_11_print(ndo, p + caphdr_len, length - caphdr_len, caplen - caphdr_len, 0, 0); } #define PRISM_HDR_LEN 144 #define WLANCAP_MAGIC_COOKIE_BASE 0x80211000 #define WLANCAP_MAGIC_COOKIE_V1 0x80211001 #define WLANCAP_MAGIC_COOKIE_V2 0x80211002 /* * For DLT_PRISM_HEADER; like DLT_IEEE802_11, but with an extra header, * containing information such as radio information, which we * currently ignore. * * If, however, the packet begins with WLANCAP_MAGIC_COOKIE_V1 or * WLANCAP_MAGIC_COOKIE_V2, it's really DLT_IEEE802_11_RADIO_AVS * (currently, on Linux, there's no ARPHRD_ type for * DLT_IEEE802_11_RADIO_AVS, as there is a ARPHRD_IEEE80211_PRISM * for DLT_PRISM_HEADER, so ARPHRD_IEEE80211_PRISM is used for * the AVS header, and the first 4 bytes of the header are used to * indicate whether it's a Prism header or an AVS header). */ u_int prism_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) { u_int caplen = h->caplen; u_int length = h->len; uint32_t msgcode; if (caplen < 4) { ND_PRINT((ndo, "%s", tstr)); return caplen; } msgcode = EXTRACT_32BITS(p); if (msgcode == WLANCAP_MAGIC_COOKIE_V1 || msgcode == WLANCAP_MAGIC_COOKIE_V2) return ieee802_11_avs_radio_print(ndo, p, length, caplen); if (caplen < PRISM_HDR_LEN) { ND_PRINT((ndo, "%s", tstr)); return caplen; } return PRISM_HDR_LEN + ieee802_11_print(ndo, p + PRISM_HDR_LEN, length - PRISM_HDR_LEN, caplen - PRISM_HDR_LEN, 0, 0); } /* * For DLT_IEEE802_11_RADIO; like DLT_IEEE802_11, but with an extra * header, containing information such as radio information. */ u_int ieee802_11_radio_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) { return ieee802_11_radio_print(ndo, p, h->len, h->caplen); } /* * For DLT_IEEE802_11_RADIO_AVS; like DLT_IEEE802_11, but with an * extra header, containing information such as radio information, * which we currently ignore. */ u_int ieee802_11_radio_avs_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) { return ieee802_11_avs_radio_print(ndo, p, h->len, h->caplen); } tcpdump-4.9.3/print-dvmrp.c0000644000026300017510000002175413544412561013772 0ustar mcrmcr/* * Copyright (c) 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of * the University nor the names of its contributors may be used to endorse * or promote products derived from this software without specific prior * written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* \summary: Distance Vector Multicast Routing Protocol printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #include "extract.h" #include "addrtoname.h" /* * See: RFC 1075 and draft-ietf-idmr-dvmrp-v3 * * DVMRP message types and flag values shamelessly stolen from * mrouted/dvmrp.h. */ #define DVMRP_PROBE 1 /* for finding neighbors */ #define DVMRP_REPORT 2 /* for reporting some or all routes */ #define DVMRP_ASK_NEIGHBORS 3 /* sent by mapper, asking for a list */ /* of this router's neighbors */ #define DVMRP_NEIGHBORS 4 /* response to such a request */ #define DVMRP_ASK_NEIGHBORS2 5 /* as above, want new format reply */ #define DVMRP_NEIGHBORS2 6 #define DVMRP_PRUNE 7 /* prune message */ #define DVMRP_GRAFT 8 /* graft message */ #define DVMRP_GRAFT_ACK 9 /* graft acknowledgement */ /* * 'flags' byte values in DVMRP_NEIGHBORS2 reply. */ #define DVMRP_NF_TUNNEL 0x01 /* neighbors reached via tunnel */ #define DVMRP_NF_SRCRT 0x02 /* tunnel uses IP source routing */ #define DVMRP_NF_DOWN 0x10 /* kernel state of interface */ #define DVMRP_NF_DISABLED 0x20 /* administratively disabled */ #define DVMRP_NF_QUERIER 0x40 /* I am the subnet's querier */ static int print_probe(netdissect_options *, const u_char *, const u_char *, u_int); static int print_report(netdissect_options *, const u_char *, const u_char *, u_int); static int print_neighbors(netdissect_options *, const u_char *, const u_char *, u_int); static int print_neighbors2(netdissect_options *, const u_char *, const u_char *, u_int, uint8_t, uint8_t); static int print_prune(netdissect_options *, const u_char *); static int print_graft(netdissect_options *, const u_char *); static int print_graft_ack(netdissect_options *, const u_char *); void dvmrp_print(netdissect_options *ndo, register const u_char *bp, register u_int len) { register const u_char *ep; register u_char type; uint8_t major_version, minor_version; ep = (const u_char *)ndo->ndo_snapend; if (bp >= ep) return; ND_TCHECK(bp[1]); type = bp[1]; /* Skip IGMP header */ bp += 8; len -= 8; switch (type) { case DVMRP_PROBE: ND_PRINT((ndo, " Probe")); if (ndo->ndo_vflag) { if (print_probe(ndo, bp, ep, len) < 0) goto trunc; } break; case DVMRP_REPORT: ND_PRINT((ndo, " Report")); if (ndo->ndo_vflag > 1) { if (print_report(ndo, bp, ep, len) < 0) goto trunc; } break; case DVMRP_ASK_NEIGHBORS: ND_PRINT((ndo, " Ask-neighbors(old)")); break; case DVMRP_NEIGHBORS: ND_PRINT((ndo, " Neighbors(old)")); if (print_neighbors(ndo, bp, ep, len) < 0) goto trunc; break; case DVMRP_ASK_NEIGHBORS2: ND_PRINT((ndo, " Ask-neighbors2")); break; case DVMRP_NEIGHBORS2: ND_PRINT((ndo, " Neighbors2")); /* * extract version from IGMP group address field */ bp -= 4; ND_TCHECK2(bp[0], 4); major_version = *(bp + 3); minor_version = *(bp + 2); bp += 4; if (print_neighbors2(ndo, bp, ep, len, major_version, minor_version) < 0) goto trunc; break; case DVMRP_PRUNE: ND_PRINT((ndo, " Prune")); if (print_prune(ndo, bp) < 0) goto trunc; break; case DVMRP_GRAFT: ND_PRINT((ndo, " Graft")); if (print_graft(ndo, bp) < 0) goto trunc; break; case DVMRP_GRAFT_ACK: ND_PRINT((ndo, " Graft-ACK")); if (print_graft_ack(ndo, bp) < 0) goto trunc; break; default: ND_PRINT((ndo, " [type %d]", type)); break; } return; trunc: ND_PRINT((ndo, "[|dvmrp]")); return; } static int print_report(netdissect_options *ndo, register const u_char *bp, register const u_char *ep, register u_int len) { register uint32_t mask, origin; register int metric, done; register u_int i, width; while (len > 0) { if (len < 3) { ND_PRINT((ndo, " [|]")); return (0); } ND_TCHECK2(bp[0], 3); mask = (uint32_t)0xff << 24 | bp[0] << 16 | bp[1] << 8 | bp[2]; width = 1; if (bp[0]) width = 2; if (bp[1]) width = 3; if (bp[2]) width = 4; ND_PRINT((ndo, "\n\tMask %s", intoa(htonl(mask)))); bp += 3; len -= 3; do { if (bp + width + 1 > ep) { ND_PRINT((ndo, " [|]")); return (0); } if (len < width + 1) { ND_PRINT((ndo, "\n\t [Truncated Report]")); return (0); } origin = 0; for (i = 0; i < width; ++i) { ND_TCHECK(*bp); origin = origin << 8 | *bp++; } for ( ; i < 4; ++i) origin <<= 8; ND_TCHECK(*bp); metric = *bp++; done = metric & 0x80; metric &= 0x7f; ND_PRINT((ndo, "\n\t %s metric %d", intoa(htonl(origin)), metric)); len -= width + 1; } while (!done); } return (0); trunc: return (-1); } static int print_probe(netdissect_options *ndo, register const u_char *bp, register const u_char *ep, register u_int len) { register uint32_t genid; ND_TCHECK2(bp[0], 4); if ((len < 4) || ((bp + 4) > ep)) { /* { (ctags) */ ND_PRINT((ndo, " [|}")); return (0); } genid = EXTRACT_32BITS(bp); bp += 4; len -= 4; ND_PRINT((ndo, ndo->ndo_vflag > 1 ? "\n\t" : " ")); ND_PRINT((ndo, "genid %u", genid)); if (ndo->ndo_vflag < 2) return (0); while ((len > 0) && (bp < ep)) { ND_TCHECK2(bp[0], 4); ND_PRINT((ndo, "\n\tneighbor %s", ipaddr_string(ndo, bp))); bp += 4; len -= 4; } return (0); trunc: return (-1); } static int print_neighbors(netdissect_options *ndo, register const u_char *bp, register const u_char *ep, register u_int len) { const u_char *laddr; register u_char metric; register u_char thresh; register int ncount; while (len > 0 && bp < ep) { ND_TCHECK2(bp[0], 7); laddr = bp; bp += 4; metric = *bp++; thresh = *bp++; ncount = *bp++; len -= 7; while (--ncount >= 0) { ND_TCHECK2(bp[0], 4); ND_PRINT((ndo, " [%s ->", ipaddr_string(ndo, laddr))); ND_PRINT((ndo, " %s, (%d/%d)]", ipaddr_string(ndo, bp), metric, thresh)); bp += 4; len -= 4; } } return (0); trunc: return (-1); } static int print_neighbors2(netdissect_options *ndo, register const u_char *bp, register const u_char *ep, register u_int len, uint8_t major_version, uint8_t minor_version) { const u_char *laddr; register u_char metric, thresh, flags; register int ncount; ND_PRINT((ndo, " (v %d.%d):", major_version, minor_version)); while (len > 0 && bp < ep) { ND_TCHECK2(bp[0], 8); laddr = bp; bp += 4; metric = *bp++; thresh = *bp++; flags = *bp++; ncount = *bp++; len -= 8; while (--ncount >= 0 && (len >= 4) && (bp + 4) <= ep) { ND_PRINT((ndo, " [%s -> ", ipaddr_string(ndo, laddr))); ND_PRINT((ndo, "%s (%d/%d", ipaddr_string(ndo, bp), metric, thresh)); if (flags & DVMRP_NF_TUNNEL) ND_PRINT((ndo, "/tunnel")); if (flags & DVMRP_NF_SRCRT) ND_PRINT((ndo, "/srcrt")); if (flags & DVMRP_NF_QUERIER) ND_PRINT((ndo, "/querier")); if (flags & DVMRP_NF_DISABLED) ND_PRINT((ndo, "/disabled")); if (flags & DVMRP_NF_DOWN) ND_PRINT((ndo, "/down")); ND_PRINT((ndo, ")]")); bp += 4; len -= 4; } if (ncount != -1) { ND_PRINT((ndo, " [|]")); return (0); } } return (0); trunc: return (-1); } static int print_prune(netdissect_options *ndo, register const u_char *bp) { ND_TCHECK2(bp[0], 12); ND_PRINT((ndo, " src %s grp %s", ipaddr_string(ndo, bp), ipaddr_string(ndo, bp + 4))); bp += 8; ND_PRINT((ndo, " timer ")); unsigned_relts_print(ndo, EXTRACT_32BITS(bp)); return (0); trunc: return (-1); } static int print_graft(netdissect_options *ndo, register const u_char *bp) { ND_TCHECK2(bp[0], 8); ND_PRINT((ndo, " src %s grp %s", ipaddr_string(ndo, bp), ipaddr_string(ndo, bp + 4))); return (0); trunc: return (-1); } static int print_graft_ack(netdissect_options *ndo, register const u_char *bp) { ND_TCHECK2(bp[0], 8); ND_PRINT((ndo, " src %s grp %s", ipaddr_string(ndo, bp), ipaddr_string(ndo, bp + 4))); return (0); trunc: return (-1); } tcpdump-4.9.3/addrtostr.c0000644000026300017510000001321613544412561013510 0ustar mcrmcr/* * Copyright (c) 1999 Kungliga Tekniska Högskolan * (Royal Institute of Technology, Stockholm, Sweden). * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the Kungliga Tekniska * Högskolan and its contributors. * * 4. Neither the name of the Institute nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "addrtostr.h" #include #include /* * */ #ifndef IN6ADDRSZ #define IN6ADDRSZ 16 /* IPv6 T_AAAA */ #endif #ifndef INT16SZ #define INT16SZ 2 /* word size */ #endif const char * addrtostr (const void *src, char *dst, size_t size) { const u_char *srcaddr = (const u_char *)src; const char digits[] = "0123456789"; int i; const char *orig_dst = dst; if (size < INET_ADDRSTRLEN) { errno = ENOSPC; return NULL; } for (i = 0; i < 4; ++i) { int n = *srcaddr++; int non_zerop = 0; if (non_zerop || n / 100 > 0) { *dst++ = digits[n / 100]; n %= 100; non_zerop = 1; } if (non_zerop || n / 10 > 0) { *dst++ = digits[n / 10]; n %= 10; non_zerop = 1; } *dst++ = digits[n]; if (i != 3) *dst++ = '.'; } *dst++ = '\0'; return orig_dst; } /* * Convert IPv6 binary address into presentation (printable) format. */ const char * addrtostr6 (const void *src, char *dst, size_t size) { /* * Note that int32_t and int16_t need only be "at least" large enough * to contain a value of the specified size. On some systems, like * Crays, there is no such thing as an integer variable with 16 bits. * Keep this in mind if you think this function should have been coded * to use pointer overlays. All the world's not a VAX. */ const u_char *srcaddr = (const u_char *)src; char *dp; size_t space_left, added_space; int snprintfed; struct { int base; int len; } best, cur; uint16_t words [IN6ADDRSZ / INT16SZ]; int i; /* Preprocess: * Copy the input (bytewise) array into a wordwise array. * Find the longest run of 0x00's in src[] for :: shorthanding. */ for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) words[i] = (srcaddr[2*i] << 8) | srcaddr[2*i + 1]; best.len = 0; best.base = -1; cur.len = 0; cur.base = -1; for (i = 0; i < (int)(IN6ADDRSZ / INT16SZ); i++) { if (words[i] == 0) { if (cur.base == -1) cur.base = i, cur.len = 1; else cur.len++; } else if (cur.base != -1) { if (best.base == -1 || cur.len > best.len) best = cur; cur.base = -1; } } if ((cur.base != -1) && (best.base == -1 || cur.len > best.len)) best = cur; if (best.base != -1 && best.len < 2) best.base = -1; /* Format the result. */ dp = dst; space_left = size; #define APPEND_CHAR(c) \ { \ if (space_left == 0) { \ errno = ENOSPC; \ return (NULL); \ } \ *dp++ = c; \ space_left--; \ } for (i = 0; i < (int)(IN6ADDRSZ / INT16SZ); i++) { /* Are we inside the best run of 0x00's? */ if (best.base != -1 && i >= best.base && i < (best.base + best.len)) { if (i == best.base) APPEND_CHAR(':'); continue; } /* Are we following an initial run of 0x00s or any real hex? */ if (i != 0) APPEND_CHAR(':'); /* Is this address an encapsulated IPv4? */ if (i == 6 && best.base == 0 && (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { if (!addrtostr(srcaddr+12, dp, space_left)) { errno = ENOSPC; return (NULL); } added_space = strlen(dp); dp += added_space; space_left -= added_space; break; } snprintfed = snprintf (dp, space_left, "%x", words[i]); if (snprintfed < 0) return (NULL); if ((size_t) snprintfed >= space_left) { errno = ENOSPC; return (NULL); } dp += snprintfed; space_left -= snprintfed; } /* Was it a trailing run of 0x00's? */ if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ)) APPEND_CHAR(':'); APPEND_CHAR('\0'); return (dst); } tcpdump-4.9.3/print-ospf6.c0000644000026300017510000007356113544412724013703 0ustar mcrmcr/* * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of * the University nor the names of its contributors may be used to endorse * or promote products derived from this software without specific prior * written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * OSPF support contributed by Jeffrey Honig (jch@mitchell.cit.cornell.edu) */ /* \summary: IPv6 Open Shortest Path First (OSPFv3) printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include "netdissect.h" #include "addrtoname.h" #include "extract.h" #include "ospf.h" #define OSPF_TYPE_HELLO 1 /* Hello */ #define OSPF_TYPE_DD 2 /* Database Description */ #define OSPF_TYPE_LS_REQ 3 /* Link State Request */ #define OSPF_TYPE_LS_UPDATE 4 /* Link State Update */ #define OSPF_TYPE_LS_ACK 5 /* Link State Ack */ /* Options *_options */ #define OSPF6_OPTION_V6 0x01 /* V6 bit: A bit for peeping tom */ #define OSPF6_OPTION_E 0x02 /* E bit: External routes advertised */ #define OSPF6_OPTION_MC 0x04 /* MC bit: Multicast capable */ #define OSPF6_OPTION_N 0x08 /* N bit: For type-7 LSA */ #define OSPF6_OPTION_R 0x10 /* R bit: Router bit */ #define OSPF6_OPTION_DC 0x20 /* DC bit: Demand circuits */ /* The field is actually 24-bit (RFC5340 Section A.2). */ #define OSPF6_OPTION_AF 0x0100 /* AF bit: Multiple address families */ #define OSPF6_OPTION_L 0x0200 /* L bit: Link-local signaling (LLS) */ #define OSPF6_OPTION_AT 0x0400 /* AT bit: Authentication trailer */ /* db_flags */ #define OSPF6_DB_INIT 0x04 /* */ #define OSPF6_DB_MORE 0x02 #define OSPF6_DB_MASTER 0x01 #define OSPF6_DB_M6 0x10 /* IPv6 MTU */ /* ls_type */ #define LS_TYPE_ROUTER 1 /* router link */ #define LS_TYPE_NETWORK 2 /* network link */ #define LS_TYPE_INTER_AP 3 /* Inter-Area-Prefix */ #define LS_TYPE_INTER_AR 4 /* Inter-Area-Router */ #define LS_TYPE_ASE 5 /* ASE */ #define LS_TYPE_GROUP 6 /* Group membership */ #define LS_TYPE_NSSA 7 /* NSSA */ #define LS_TYPE_LINK 8 /* Link LSA */ #define LS_TYPE_INTRA_AP 9 /* Intra-Area-Prefix */ #define LS_TYPE_INTRA_ATE 10 /* Intra-Area-TE */ #define LS_TYPE_GRACE 11 /* Grace LSA */ #define LS_TYPE_RI 12 /* Router information */ #define LS_TYPE_INTER_ASTE 13 /* Inter-AS-TE */ #define LS_TYPE_L1VPN 14 /* L1VPN */ #define LS_TYPE_MASK 0x1fff #define LS_SCOPE_LINKLOCAL 0x0000 #define LS_SCOPE_AREA 0x2000 #define LS_SCOPE_AS 0x4000 #define LS_SCOPE_MASK 0x6000 #define LS_SCOPE_U 0x8000 /* rla_link.link_type */ #define RLA_TYPE_ROUTER 1 /* point-to-point to another router */ #define RLA_TYPE_TRANSIT 2 /* connection to transit network */ #define RLA_TYPE_VIRTUAL 4 /* virtual link */ /* rla_flags */ #define RLA_FLAG_B 0x01 #define RLA_FLAG_E 0x02 #define RLA_FLAG_V 0x04 #define RLA_FLAG_W 0x08 #define RLA_FLAG_N 0x10 /* lsa_prefix options */ #define LSA_PREFIX_OPT_NU 0x01 #define LSA_PREFIX_OPT_LA 0x02 #define LSA_PREFIX_OPT_MC 0x04 #define LSA_PREFIX_OPT_P 0x08 #define LSA_PREFIX_OPT_DN 0x10 /* sla_tosmetric breakdown */ #define SLA_MASK_TOS 0x7f000000 #define SLA_MASK_METRIC 0x00ffffff #define SLA_SHIFT_TOS 24 /* asla_metric */ #define ASLA_FLAG_FWDADDR 0x02000000 #define ASLA_FLAG_ROUTETAG 0x01000000 #define ASLA_MASK_METRIC 0x00ffffff /* RFC6506 Section 4.1 */ #define OSPF6_AT_HDRLEN 16U #define OSPF6_AUTH_TYPE_HMAC 0x0001 typedef uint32_t rtrid_t; /* link state advertisement header */ struct lsa6_hdr { uint16_t ls_age; uint16_t ls_type; rtrid_t ls_stateid; rtrid_t ls_router; uint32_t ls_seq; uint16_t ls_chksum; uint16_t ls_length; }; /* Length of an IPv6 address, in bytes. */ #define IPV6_ADDR_LEN_BYTES (128/8) struct lsa6_prefix { uint8_t lsa_p_len; uint8_t lsa_p_opt; uint16_t lsa_p_metric; uint8_t lsa_p_prefix[IPV6_ADDR_LEN_BYTES]; /* maximum length */ }; /* link state advertisement */ struct lsa6 { struct lsa6_hdr ls_hdr; /* Link state types */ union { /* Router links advertisements */ struct { union { uint8_t flg; uint32_t opt; } rla_flgandopt; #define rla_flags rla_flgandopt.flg #define rla_options rla_flgandopt.opt struct rlalink6 { uint8_t link_type; uint8_t link_zero[1]; uint16_t link_metric; uint32_t link_ifid; uint32_t link_nifid; rtrid_t link_nrtid; } rla_link[1]; /* may repeat */ } un_rla; /* Network links advertisements */ struct { uint32_t nla_options; rtrid_t nla_router[1]; /* may repeat */ } un_nla; /* Inter Area Prefix LSA */ struct { uint32_t inter_ap_metric; struct lsa6_prefix inter_ap_prefix[1]; } un_inter_ap; /* AS external links advertisements */ struct { uint32_t asla_metric; struct lsa6_prefix asla_prefix[1]; /* some optional fields follow */ } un_asla; #if 0 /* Summary links advertisements */ struct { struct in_addr sla_mask; uint32_t sla_tosmetric[1]; /* may repeat */ } un_sla; /* Multicast group membership */ struct mcla { uint32_t mcla_vtype; struct in_addr mcla_vid; } un_mcla[1]; #endif /* Type 7 LSA */ /* Link LSA */ struct llsa { union { uint8_t pri; uint32_t opt; } llsa_priandopt; #define llsa_priority llsa_priandopt.pri #define llsa_options llsa_priandopt.opt struct in6_addr llsa_lladdr; uint32_t llsa_nprefix; struct lsa6_prefix llsa_prefix[1]; } un_llsa; /* Intra-Area-Prefix */ struct { uint16_t intra_ap_nprefix; uint16_t intra_ap_lstype; rtrid_t intra_ap_lsid; rtrid_t intra_ap_rtid; struct lsa6_prefix intra_ap_prefix[1]; } un_intra_ap; } lsa_un; }; /* * the main header */ struct ospf6hdr { uint8_t ospf6_version; uint8_t ospf6_type; uint16_t ospf6_len; rtrid_t ospf6_routerid; rtrid_t ospf6_areaid; uint16_t ospf6_chksum; uint8_t ospf6_instanceid; uint8_t ospf6_rsvd; }; /* * The OSPF6 header length is 16 bytes, regardless of how your compiler * might choose to pad the above structure. */ #define OSPF6HDR_LEN 16 /* Hello packet */ struct hello6 { uint32_t hello_ifid; union { uint8_t pri; uint32_t opt; } hello_priandopt; #define hello_priority hello_priandopt.pri #define hello_options hello_priandopt.opt uint16_t hello_helloint; uint16_t hello_deadint; rtrid_t hello_dr; rtrid_t hello_bdr; rtrid_t hello_neighbor[1]; /* may repeat */ }; /* Database Description packet */ struct dd6 { uint32_t db_options; uint16_t db_mtu; uint8_t db_mbz; uint8_t db_flags; uint32_t db_seq; struct lsa6_hdr db_lshdr[1]; /* may repeat */ }; /* Link State Request */ struct lsr6 { uint16_t ls_mbz; uint16_t ls_type; rtrid_t ls_stateid; rtrid_t ls_router; }; /* Link State Update */ struct lsu6 { uint32_t lsu_count; struct lsa6 lsu_lsa[1]; /* may repeat */ }; static const char tstr[] = " [|ospf3]"; static const struct tok ospf6_option_values[] = { { OSPF6_OPTION_V6, "V6" }, { OSPF6_OPTION_E, "External" }, { OSPF6_OPTION_MC, "Deprecated" }, { OSPF6_OPTION_N, "NSSA" }, { OSPF6_OPTION_R, "Router" }, { OSPF6_OPTION_DC, "Demand Circuit" }, { OSPF6_OPTION_AF, "AFs Support" }, { OSPF6_OPTION_L, "LLS" }, { OSPF6_OPTION_AT, "Authentication Trailer" }, { 0, NULL } }; static const struct tok ospf6_rla_flag_values[] = { { RLA_FLAG_B, "ABR" }, { RLA_FLAG_E, "External" }, { RLA_FLAG_V, "Virtual-Link Endpoint" }, { RLA_FLAG_W, "Wildcard Receiver" }, { RLA_FLAG_N, "NSSA Translator" }, { 0, NULL } }; static const struct tok ospf6_asla_flag_values[] = { { ASLA_FLAG_EXTERNAL, "External Type 2" }, { ASLA_FLAG_FWDADDR, "Forwarding" }, { ASLA_FLAG_ROUTETAG, "Tag" }, { 0, NULL } }; static const struct tok ospf6_type_values[] = { { OSPF_TYPE_HELLO, "Hello" }, { OSPF_TYPE_DD, "Database Description" }, { OSPF_TYPE_LS_REQ, "LS-Request" }, { OSPF_TYPE_LS_UPDATE, "LS-Update" }, { OSPF_TYPE_LS_ACK, "LS-Ack" }, { 0, NULL } }; static const struct tok ospf6_lsa_values[] = { { LS_TYPE_ROUTER, "Router" }, { LS_TYPE_NETWORK, "Network" }, { LS_TYPE_INTER_AP, "Inter-Area Prefix" }, { LS_TYPE_INTER_AR, "Inter-Area Router" }, { LS_TYPE_ASE, "External" }, { LS_TYPE_GROUP, "Deprecated" }, { LS_TYPE_NSSA, "NSSA" }, { LS_TYPE_LINK, "Link" }, { LS_TYPE_INTRA_AP, "Intra-Area Prefix" }, { LS_TYPE_INTRA_ATE, "Intra-Area TE" }, { LS_TYPE_GRACE, "Grace" }, { LS_TYPE_RI, "Router Information" }, { LS_TYPE_INTER_ASTE, "Inter-AS-TE" }, { LS_TYPE_L1VPN, "Layer 1 VPN" }, { 0, NULL } }; static const struct tok ospf6_ls_scope_values[] = { { LS_SCOPE_LINKLOCAL, "Link Local" }, { LS_SCOPE_AREA, "Area Local" }, { LS_SCOPE_AS, "Domain Wide" }, { 0, NULL } }; static const struct tok ospf6_dd_flag_values[] = { { OSPF6_DB_INIT, "Init" }, { OSPF6_DB_MORE, "More" }, { OSPF6_DB_MASTER, "Master" }, { OSPF6_DB_M6, "IPv6 MTU" }, { 0, NULL } }; static const struct tok ospf6_lsa_prefix_option_values[] = { { LSA_PREFIX_OPT_NU, "No Unicast" }, { LSA_PREFIX_OPT_LA, "Local address" }, { LSA_PREFIX_OPT_MC, "Deprecated" }, { LSA_PREFIX_OPT_P, "Propagate" }, { LSA_PREFIX_OPT_DN, "Down" }, { 0, NULL } }; static const struct tok ospf6_auth_type_str[] = { { OSPF6_AUTH_TYPE_HMAC, "HMAC" }, { 0, NULL } }; static void ospf6_print_ls_type(netdissect_options *ndo, register u_int ls_type, register const rtrid_t *ls_stateid) { ND_PRINT((ndo, "\n\t %s LSA (%d), %s Scope%s, LSA-ID %s", tok2str(ospf6_lsa_values, "Unknown", ls_type & LS_TYPE_MASK), ls_type & LS_TYPE_MASK, tok2str(ospf6_ls_scope_values, "Unknown", ls_type & LS_SCOPE_MASK), ls_type &0x8000 ? ", transitive" : "", /* U-bit */ ipaddr_string(ndo, ls_stateid))); } static int ospf6_print_lshdr(netdissect_options *ndo, register const struct lsa6_hdr *lshp, const u_char *dataend) { if ((const u_char *)(lshp + 1) > dataend) goto trunc; ND_TCHECK(lshp->ls_length); /* last field of struct lsa6_hdr */ ND_PRINT((ndo, "\n\t Advertising Router %s, seq 0x%08x, age %us, length %u", ipaddr_string(ndo, &lshp->ls_router), EXTRACT_32BITS(&lshp->ls_seq), EXTRACT_16BITS(&lshp->ls_age), EXTRACT_16BITS(&lshp->ls_length)-(u_int)sizeof(struct lsa6_hdr))); ospf6_print_ls_type(ndo, EXTRACT_16BITS(&lshp->ls_type), &lshp->ls_stateid); return (0); trunc: return (1); } static int ospf6_print_lsaprefix(netdissect_options *ndo, const uint8_t *tptr, u_int lsa_length) { const struct lsa6_prefix *lsapp = (const struct lsa6_prefix *)tptr; u_int wordlen; struct in6_addr prefix; if (lsa_length < sizeof (*lsapp) - IPV6_ADDR_LEN_BYTES) goto trunc; lsa_length -= sizeof (*lsapp) - IPV6_ADDR_LEN_BYTES; ND_TCHECK2(*lsapp, sizeof (*lsapp) - IPV6_ADDR_LEN_BYTES); wordlen = (lsapp->lsa_p_len + 31) / 32; if (wordlen * 4 > sizeof(struct in6_addr)) { ND_PRINT((ndo, " bogus prefixlen /%d", lsapp->lsa_p_len)); goto trunc; } if (lsa_length < wordlen * 4) goto trunc; lsa_length -= wordlen * 4; ND_TCHECK2(lsapp->lsa_p_prefix, wordlen * 4); memset(&prefix, 0, sizeof(prefix)); memcpy(&prefix, lsapp->lsa_p_prefix, wordlen * 4); ND_PRINT((ndo, "\n\t\t%s/%d", ip6addr_string(ndo, &prefix), lsapp->lsa_p_len)); if (lsapp->lsa_p_opt) { ND_PRINT((ndo, ", Options [%s]", bittok2str(ospf6_lsa_prefix_option_values, "none", lsapp->lsa_p_opt))); } ND_PRINT((ndo, ", metric %u", EXTRACT_16BITS(&lsapp->lsa_p_metric))); return sizeof(*lsapp) - IPV6_ADDR_LEN_BYTES + wordlen * 4; trunc: return -1; } /* * Print a single link state advertisement. If truncated return 1, else 0. */ static int ospf6_print_lsa(netdissect_options *ndo, register const struct lsa6 *lsap, const u_char *dataend) { register const struct rlalink6 *rlp; #if 0 register const struct tos_metric *tosp; #endif register const rtrid_t *ap; #if 0 register const struct aslametric *almp; register const struct mcla *mcp; #endif register const struct llsa *llsap; register const struct lsa6_prefix *lsapp; #if 0 register const uint32_t *lp; #endif register u_int prefixes; register int bytelen; register u_int length, lsa_length; uint32_t flags32; const uint8_t *tptr; if (ospf6_print_lshdr(ndo, &lsap->ls_hdr, dataend)) return (1); ND_TCHECK(lsap->ls_hdr.ls_length); length = EXTRACT_16BITS(&lsap->ls_hdr.ls_length); /* * The LSA length includes the length of the header; * it must have a value that's at least that length. * If it does, find the length of what follows the * header. */ if (length < sizeof(struct lsa6_hdr) || (const u_char *)lsap + length > dataend) return (1); lsa_length = length - sizeof(struct lsa6_hdr); tptr = (const uint8_t *)lsap+sizeof(struct lsa6_hdr); switch (EXTRACT_16BITS(&lsap->ls_hdr.ls_type)) { case LS_TYPE_ROUTER | LS_SCOPE_AREA: if (lsa_length < sizeof (lsap->lsa_un.un_rla.rla_options)) return (1); lsa_length -= sizeof (lsap->lsa_un.un_rla.rla_options); ND_TCHECK(lsap->lsa_un.un_rla.rla_options); ND_PRINT((ndo, "\n\t Options [%s]", bittok2str(ospf6_option_values, "none", EXTRACT_32BITS(&lsap->lsa_un.un_rla.rla_options)))); ND_PRINT((ndo, ", RLA-Flags [%s]", bittok2str(ospf6_rla_flag_values, "none", lsap->lsa_un.un_rla.rla_flags))); rlp = lsap->lsa_un.un_rla.rla_link; while (lsa_length != 0) { if (lsa_length < sizeof (*rlp)) return (1); lsa_length -= sizeof (*rlp); ND_TCHECK(*rlp); switch (rlp->link_type) { case RLA_TYPE_VIRTUAL: ND_PRINT((ndo, "\n\t Virtual Link: Neighbor Router-ID %s" "\n\t Neighbor Interface-ID %s, Interface %s", ipaddr_string(ndo, &rlp->link_nrtid), ipaddr_string(ndo, &rlp->link_nifid), ipaddr_string(ndo, &rlp->link_ifid))); break; case RLA_TYPE_ROUTER: ND_PRINT((ndo, "\n\t Neighbor Router-ID %s" "\n\t Neighbor Interface-ID %s, Interface %s", ipaddr_string(ndo, &rlp->link_nrtid), ipaddr_string(ndo, &rlp->link_nifid), ipaddr_string(ndo, &rlp->link_ifid))); break; case RLA_TYPE_TRANSIT: ND_PRINT((ndo, "\n\t Neighbor Network-ID %s" "\n\t Neighbor Interface-ID %s, Interface %s", ipaddr_string(ndo, &rlp->link_nrtid), ipaddr_string(ndo, &rlp->link_nifid), ipaddr_string(ndo, &rlp->link_ifid))); break; default: ND_PRINT((ndo, "\n\t Unknown Router Links Type 0x%02x", rlp->link_type)); return (0); } ND_PRINT((ndo, ", metric %d", EXTRACT_16BITS(&rlp->link_metric))); rlp++; } break; case LS_TYPE_NETWORK | LS_SCOPE_AREA: if (lsa_length < sizeof (lsap->lsa_un.un_nla.nla_options)) return (1); lsa_length -= sizeof (lsap->lsa_un.un_nla.nla_options); ND_TCHECK(lsap->lsa_un.un_nla.nla_options); ND_PRINT((ndo, "\n\t Options [%s]", bittok2str(ospf6_option_values, "none", EXTRACT_32BITS(&lsap->lsa_un.un_nla.nla_options)))); ND_PRINT((ndo, "\n\t Connected Routers:")); ap = lsap->lsa_un.un_nla.nla_router; while (lsa_length != 0) { if (lsa_length < sizeof (*ap)) return (1); lsa_length -= sizeof (*ap); ND_TCHECK(*ap); ND_PRINT((ndo, "\n\t\t%s", ipaddr_string(ndo, ap))); ++ap; } break; case LS_TYPE_INTER_AP | LS_SCOPE_AREA: if (lsa_length < sizeof (lsap->lsa_un.un_inter_ap.inter_ap_metric)) return (1); lsa_length -= sizeof (lsap->lsa_un.un_inter_ap.inter_ap_metric); ND_TCHECK(lsap->lsa_un.un_inter_ap.inter_ap_metric); ND_PRINT((ndo, ", metric %u", EXTRACT_32BITS(&lsap->lsa_un.un_inter_ap.inter_ap_metric) & SLA_MASK_METRIC)); tptr = (const uint8_t *)lsap->lsa_un.un_inter_ap.inter_ap_prefix; while (lsa_length != 0) { bytelen = ospf6_print_lsaprefix(ndo, tptr, lsa_length); if (bytelen < 0) goto trunc; lsa_length -= bytelen; tptr += bytelen; } break; case LS_TYPE_ASE | LS_SCOPE_AS: if (lsa_length < sizeof (lsap->lsa_un.un_asla.asla_metric)) return (1); lsa_length -= sizeof (lsap->lsa_un.un_asla.asla_metric); ND_TCHECK(lsap->lsa_un.un_asla.asla_metric); flags32 = EXTRACT_32BITS(&lsap->lsa_un.un_asla.asla_metric); ND_PRINT((ndo, "\n\t Flags [%s]", bittok2str(ospf6_asla_flag_values, "none", flags32))); ND_PRINT((ndo, " metric %u", EXTRACT_32BITS(&lsap->lsa_un.un_asla.asla_metric) & ASLA_MASK_METRIC)); tptr = (const uint8_t *)lsap->lsa_un.un_asla.asla_prefix; lsapp = (const struct lsa6_prefix *)tptr; bytelen = ospf6_print_lsaprefix(ndo, tptr, lsa_length); if (bytelen < 0) goto trunc; lsa_length -= bytelen; tptr += bytelen; if ((flags32 & ASLA_FLAG_FWDADDR) != 0) { const struct in6_addr *fwdaddr6; fwdaddr6 = (const struct in6_addr *)tptr; if (lsa_length < sizeof (*fwdaddr6)) return (1); lsa_length -= sizeof (*fwdaddr6); ND_TCHECK(*fwdaddr6); ND_PRINT((ndo, " forward %s", ip6addr_string(ndo, fwdaddr6))); tptr += sizeof(*fwdaddr6); } if ((flags32 & ASLA_FLAG_ROUTETAG) != 0) { if (lsa_length < sizeof (uint32_t)) return (1); lsa_length -= sizeof (uint32_t); ND_TCHECK(*(const uint32_t *)tptr); ND_PRINT((ndo, " tag %s", ipaddr_string(ndo, (const uint32_t *)tptr))); tptr += sizeof(uint32_t); } if (lsapp->lsa_p_metric) { if (lsa_length < sizeof (uint32_t)) return (1); lsa_length -= sizeof (uint32_t); ND_TCHECK(*(const uint32_t *)tptr); ND_PRINT((ndo, " RefLSID: %s", ipaddr_string(ndo, (const uint32_t *)tptr))); tptr += sizeof(uint32_t); } break; case LS_TYPE_LINK: /* Link LSA */ llsap = &lsap->lsa_un.un_llsa; if (lsa_length < sizeof (llsap->llsa_priandopt)) return (1); lsa_length -= sizeof (llsap->llsa_priandopt); ND_TCHECK(llsap->llsa_priandopt); ND_PRINT((ndo, "\n\t Options [%s]", bittok2str(ospf6_option_values, "none", EXTRACT_32BITS(&llsap->llsa_options)))); if (lsa_length < sizeof (llsap->llsa_lladdr) + sizeof (llsap->llsa_nprefix)) return (1); lsa_length -= sizeof (llsap->llsa_lladdr) + sizeof (llsap->llsa_nprefix); ND_TCHECK(llsap->llsa_nprefix); prefixes = EXTRACT_32BITS(&llsap->llsa_nprefix); ND_PRINT((ndo, "\n\t Priority %d, Link-local address %s, Prefixes %d:", llsap->llsa_priority, ip6addr_string(ndo, &llsap->llsa_lladdr), prefixes)); tptr = (const uint8_t *)llsap->llsa_prefix; while (prefixes > 0) { bytelen = ospf6_print_lsaprefix(ndo, tptr, lsa_length); if (bytelen < 0) goto trunc; prefixes--; lsa_length -= bytelen; tptr += bytelen; } break; case LS_TYPE_INTRA_AP | LS_SCOPE_AREA: /* Intra-Area-Prefix LSA */ if (lsa_length < sizeof (lsap->lsa_un.un_intra_ap.intra_ap_rtid)) return (1); lsa_length -= sizeof (lsap->lsa_un.un_intra_ap.intra_ap_rtid); ND_TCHECK(lsap->lsa_un.un_intra_ap.intra_ap_rtid); ospf6_print_ls_type(ndo, EXTRACT_16BITS(&lsap->lsa_un.un_intra_ap.intra_ap_lstype), &lsap->lsa_un.un_intra_ap.intra_ap_lsid); if (lsa_length < sizeof (lsap->lsa_un.un_intra_ap.intra_ap_nprefix)) return (1); lsa_length -= sizeof (lsap->lsa_un.un_intra_ap.intra_ap_nprefix); ND_TCHECK(lsap->lsa_un.un_intra_ap.intra_ap_nprefix); prefixes = EXTRACT_16BITS(&lsap->lsa_un.un_intra_ap.intra_ap_nprefix); ND_PRINT((ndo, "\n\t Prefixes %d:", prefixes)); tptr = (const uint8_t *)lsap->lsa_un.un_intra_ap.intra_ap_prefix; while (prefixes > 0) { bytelen = ospf6_print_lsaprefix(ndo, tptr, lsa_length); if (bytelen < 0) goto trunc; prefixes--; lsa_length -= bytelen; tptr += bytelen; } break; case LS_TYPE_GRACE | LS_SCOPE_LINKLOCAL: if (ospf_print_grace_lsa(ndo, tptr, lsa_length) == -1) { return 1; } break; case LS_TYPE_INTRA_ATE | LS_SCOPE_LINKLOCAL: if (ospf_print_te_lsa(ndo, tptr, lsa_length) == -1) { return 1; } break; default: if(!print_unknown_data(ndo,tptr, "\n\t ", lsa_length)) { return (1); } break; } return (0); trunc: return (1); } static int ospf6_decode_v3(netdissect_options *ndo, register const struct ospf6hdr *op, register const u_char *dataend) { register const rtrid_t *ap; register const struct lsr6 *lsrp; register const struct lsa6_hdr *lshp; register const struct lsa6 *lsap; register int i; switch (op->ospf6_type) { case OSPF_TYPE_HELLO: { register const struct hello6 *hellop = (const struct hello6 *)((const uint8_t *)op + OSPF6HDR_LEN); ND_TCHECK_32BITS(&hellop->hello_options); ND_PRINT((ndo, "\n\tOptions [%s]", bittok2str(ospf6_option_values, "none", EXTRACT_32BITS(&hellop->hello_options)))); ND_TCHECK(hellop->hello_deadint); ND_PRINT((ndo, "\n\t Hello Timer %us, Dead Timer %us, Interface-ID %s, Priority %u", EXTRACT_16BITS(&hellop->hello_helloint), EXTRACT_16BITS(&hellop->hello_deadint), ipaddr_string(ndo, &hellop->hello_ifid), hellop->hello_priority)); ND_TCHECK(hellop->hello_dr); if (EXTRACT_32BITS(&hellop->hello_dr) != 0) ND_PRINT((ndo, "\n\t Designated Router %s", ipaddr_string(ndo, &hellop->hello_dr))); ND_TCHECK(hellop->hello_bdr); if (EXTRACT_32BITS(&hellop->hello_bdr) != 0) ND_PRINT((ndo, ", Backup Designated Router %s", ipaddr_string(ndo, &hellop->hello_bdr))); if (ndo->ndo_vflag > 1) { ND_PRINT((ndo, "\n\t Neighbor List:")); ap = hellop->hello_neighbor; while ((const u_char *)ap < dataend) { ND_TCHECK(*ap); ND_PRINT((ndo, "\n\t %s", ipaddr_string(ndo, ap))); ++ap; } } break; /* HELLO */ } case OSPF_TYPE_DD: { register const struct dd6 *ddp = (const struct dd6 *)((const uint8_t *)op + OSPF6HDR_LEN); ND_TCHECK(ddp->db_options); ND_PRINT((ndo, "\n\tOptions [%s]", bittok2str(ospf6_option_values, "none", EXTRACT_32BITS(&ddp->db_options)))); ND_TCHECK(ddp->db_flags); ND_PRINT((ndo, ", DD Flags [%s]", bittok2str(ospf6_dd_flag_values,"none",ddp->db_flags))); ND_TCHECK(ddp->db_seq); ND_PRINT((ndo, ", MTU %u, DD-Sequence 0x%08x", EXTRACT_16BITS(&ddp->db_mtu), EXTRACT_32BITS(&ddp->db_seq))); if (ndo->ndo_vflag > 1) { /* Print all the LS adv's */ lshp = ddp->db_lshdr; while ((const u_char *)lshp < dataend) { if (ospf6_print_lshdr(ndo, lshp++, dataend)) goto trunc; } } break; } case OSPF_TYPE_LS_REQ: if (ndo->ndo_vflag > 1) { lsrp = (const struct lsr6 *)((const uint8_t *)op + OSPF6HDR_LEN); while ((const u_char *)lsrp < dataend) { ND_TCHECK(*lsrp); ND_PRINT((ndo, "\n\t Advertising Router %s", ipaddr_string(ndo, &lsrp->ls_router))); ospf6_print_ls_type(ndo, EXTRACT_16BITS(&lsrp->ls_type), &lsrp->ls_stateid); ++lsrp; } } break; case OSPF_TYPE_LS_UPDATE: if (ndo->ndo_vflag > 1) { register const struct lsu6 *lsup = (const struct lsu6 *)((const uint8_t *)op + OSPF6HDR_LEN); ND_TCHECK(lsup->lsu_count); i = EXTRACT_32BITS(&lsup->lsu_count); lsap = lsup->lsu_lsa; while ((const u_char *)lsap < dataend && i--) { if (ospf6_print_lsa(ndo, lsap, dataend)) goto trunc; lsap = (const struct lsa6 *)((const u_char *)lsap + EXTRACT_16BITS(&lsap->ls_hdr.ls_length)); } } break; case OSPF_TYPE_LS_ACK: if (ndo->ndo_vflag > 1) { lshp = (const struct lsa6_hdr *)((const uint8_t *)op + OSPF6HDR_LEN); while ((const u_char *)lshp < dataend) { if (ospf6_print_lshdr(ndo, lshp++, dataend)) goto trunc; } } break; default: break; } return (0); trunc: return (1); } /* RFC5613 Section 2.2 (w/o the TLVs) */ static int ospf6_print_lls(netdissect_options *ndo, const u_char *cp, const u_int len) { uint16_t llsdatalen; if (len == 0) return 0; if (len < OSPF_LLS_HDRLEN) goto trunc; /* Checksum */ ND_TCHECK2(*cp, 2); ND_PRINT((ndo, "\n\tLLS Checksum 0x%04x", EXTRACT_16BITS(cp))); cp += 2; /* LLS Data Length */ ND_TCHECK2(*cp, 2); llsdatalen = EXTRACT_16BITS(cp); ND_PRINT((ndo, ", Data Length %u", llsdatalen)); if (llsdatalen < OSPF_LLS_HDRLEN || llsdatalen > len) goto trunc; cp += 2; /* LLS TLVs */ ND_TCHECK2(*cp, llsdatalen - OSPF_LLS_HDRLEN); /* FIXME: code in print-ospf.c can be reused to decode the TLVs */ return llsdatalen; trunc: return -1; } /* RFC6506 Section 4.1 */ static int ospf6_decode_at(netdissect_options *ndo, const u_char *cp, const u_int len) { uint16_t authdatalen; if (len == 0) return 0; if (len < OSPF6_AT_HDRLEN) goto trunc; /* Authentication Type */ ND_TCHECK2(*cp, 2); ND_PRINT((ndo, "\n\tAuthentication Type %s", tok2str(ospf6_auth_type_str, "unknown (0x%04x)", EXTRACT_16BITS(cp)))); cp += 2; /* Auth Data Len */ ND_TCHECK2(*cp, 2); authdatalen = EXTRACT_16BITS(cp); ND_PRINT((ndo, ", Length %u", authdatalen)); if (authdatalen < OSPF6_AT_HDRLEN || authdatalen > len) goto trunc; cp += 2; /* Reserved */ ND_TCHECK2(*cp, 2); cp += 2; /* Security Association ID */ ND_TCHECK2(*cp, 2); ND_PRINT((ndo, ", SAID %u", EXTRACT_16BITS(cp))); cp += 2; /* Cryptographic Sequence Number (High-Order 32 Bits) */ ND_TCHECK2(*cp, 4); ND_PRINT((ndo, ", CSN 0x%08x", EXTRACT_32BITS(cp))); cp += 4; /* Cryptographic Sequence Number (Low-Order 32 Bits) */ ND_TCHECK2(*cp, 4); ND_PRINT((ndo, ":%08x", EXTRACT_32BITS(cp))); cp += 4; /* Authentication Data */ ND_TCHECK2(*cp, authdatalen - OSPF6_AT_HDRLEN); if (ndo->ndo_vflag > 1) print_unknown_data(ndo,cp, "\n\tAuthentication Data ", authdatalen - OSPF6_AT_HDRLEN); return 0; trunc: return 1; } /* The trailing data may include LLS and/or AT data (in this specific order). * LLS data may be present only in Hello and DBDesc packets with the L-bit set. * AT data may be present in Hello and DBDesc packets with the AT-bit set or in * any other packet type, thus decode the AT data regardless of the AT-bit. */ static int ospf6_decode_v3_trailer(netdissect_options *ndo, const struct ospf6hdr *op, const u_char *cp, const unsigned len) { int llslen = 0; int lls_hello = 0; int lls_dd = 0; if (op->ospf6_type == OSPF_TYPE_HELLO) { const struct hello6 *hellop = (const struct hello6 *)((const uint8_t *)op + OSPF6HDR_LEN); ND_TCHECK(hellop->hello_options); if (EXTRACT_32BITS(&hellop->hello_options) & OSPF6_OPTION_L) lls_hello = 1; } else if (op->ospf6_type == OSPF_TYPE_DD) { const struct dd6 *ddp = (const struct dd6 *)((const uint8_t *)op + OSPF6HDR_LEN); ND_TCHECK(ddp->db_options); if (EXTRACT_32BITS(&ddp->db_options) & OSPF6_OPTION_L) lls_dd = 1; } if ((lls_hello || lls_dd) && (llslen = ospf6_print_lls(ndo, cp, len)) < 0) goto trunc; return ospf6_decode_at(ndo, cp + llslen, len - llslen); trunc: return 1; } void ospf6_print(netdissect_options *ndo, register const u_char *bp, register u_int length) { register const struct ospf6hdr *op; register const u_char *dataend; register const char *cp; uint16_t datalen; op = (const struct ospf6hdr *)bp; /* If the type is valid translate it, or just print the type */ /* value. If it's not valid, say so and return */ ND_TCHECK(op->ospf6_type); cp = tok2str(ospf6_type_values, "unknown packet type (%u)", op->ospf6_type); ND_PRINT((ndo, "OSPFv%u, %s, length %d", op->ospf6_version, cp, length)); if (*cp == 'u') { return; } if(!ndo->ndo_vflag) { /* non verbose - so lets bail out here */ return; } /* OSPFv3 data always comes first and optional trailing data may follow. */ ND_TCHECK(op->ospf6_len); datalen = EXTRACT_16BITS(&op->ospf6_len); if (datalen > length) { ND_PRINT((ndo, " [len %d]", datalen)); return; } dataend = bp + datalen; ND_TCHECK(op->ospf6_routerid); ND_PRINT((ndo, "\n\tRouter-ID %s", ipaddr_string(ndo, &op->ospf6_routerid))); ND_TCHECK(op->ospf6_areaid); if (EXTRACT_32BITS(&op->ospf6_areaid) != 0) ND_PRINT((ndo, ", Area %s", ipaddr_string(ndo, &op->ospf6_areaid))); else ND_PRINT((ndo, ", Backbone Area")); ND_TCHECK(op->ospf6_instanceid); if (op->ospf6_instanceid) ND_PRINT((ndo, ", Instance %u", op->ospf6_instanceid)); /* Do rest according to version. */ switch (op->ospf6_version) { case 3: /* ospf version 3 */ if (ospf6_decode_v3(ndo, op, dataend) || ospf6_decode_v3_trailer(ndo, op, dataend, length - datalen)) goto trunc; break; } /* end switch on version */ return; trunc: ND_PRINT((ndo, "%s", tstr)); } tcpdump-4.9.3/cpack.h0000644000026300017510000000457313544412561012576 0ustar mcrmcr/*- * Copyright (c) 2003, 2004 David Young. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of David Young may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED BY DAVID YOUNG ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID * YOUNG BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. */ #ifndef _CPACK_H #define _CPACK_H struct cpack_state { const uint8_t *c_buf; const uint8_t *c_next; size_t c_len; }; int cpack_init(struct cpack_state *, const uint8_t *, size_t); int cpack_uint8(struct cpack_state *, uint8_t *); int cpack_uint16(struct cpack_state *, uint16_t *); int cpack_uint32(struct cpack_state *, uint32_t *); int cpack_uint64(struct cpack_state *, uint64_t *); const uint8_t *cpack_next_boundary(const uint8_t *buf, const uint8_t *p, size_t alignment); const uint8_t *cpack_align_and_reserve(struct cpack_state *cs, size_t wordsize); #define cpack_int8(__s, __p) cpack_uint8((__s), (uint8_t*)(__p)) #define cpack_int16(__s, __p) cpack_uint16((__s), (uint16_t*)(__p)) #define cpack_int32(__s, __p) cpack_uint32((__s), (uint32_t*)(__p)) #define cpack_int64(__s, __p) cpack_uint64((__s), (uint64_t*)(__p)) extern int cpack_advance(struct cpack_state *, const size_t); #endif /* _CPACK_H */ tcpdump-4.9.3/print-nsh.c0000644000026300017510000001262313544412561013425 0ustar mcrmcr/* Copyright (c) 2015, bugyo * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* \summary: Network Service Header (NSH) printer */ /* specification: draft-ietf-sfc-nsh-01 */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #include "extract.h" static const char tstr[] = " [|NSH]"; static const struct tok nsh_flags [] = { { 0x20, "O" }, { 0x10, "C" }, { 0, NULL } }; #define NSH_BASE_HDR_LEN 4 #define NSH_SERVICE_PATH_HDR_LEN 4 #define NSH_HDR_WORD_SIZE 4U void nsh_print(netdissect_options *ndo, const u_char *bp, u_int len) { int n, vn; uint8_t ver; uint8_t flags; uint8_t length; uint8_t md_type; uint8_t next_protocol; uint32_t service_path_id; uint8_t service_index; uint32_t ctx; uint16_t tlv_class; uint8_t tlv_type; uint8_t tlv_len; u_int next_len; /* print Base Header and Service Path Header */ if (len < NSH_BASE_HDR_LEN + NSH_SERVICE_PATH_HDR_LEN) goto trunc; ND_TCHECK2(*bp, NSH_BASE_HDR_LEN + NSH_SERVICE_PATH_HDR_LEN); ver = (uint8_t)(*bp >> 6); flags = *bp; bp += 1; length = *bp; bp += 1; md_type = *bp; bp += 1; next_protocol = *bp; bp += 1; service_path_id = EXTRACT_24BITS(bp); bp += 3; service_index = *bp; bp += 1; ND_PRINT((ndo, "NSH, ")); if (ndo->ndo_vflag > 1) { ND_PRINT((ndo, "ver %d, ", ver)); } ND_PRINT((ndo, "flags [%s], ", bittok2str_nosep(nsh_flags, "none", flags))); if (ndo->ndo_vflag > 2) { ND_PRINT((ndo, "length %d, ", length)); ND_PRINT((ndo, "md type 0x%x, ", md_type)); } if (ndo->ndo_vflag > 1) { ND_PRINT((ndo, "next-protocol 0x%x, ", next_protocol)); } ND_PRINT((ndo, "service-path-id 0x%06x, ", service_path_id)); ND_PRINT((ndo, "service-index 0x%x", service_index)); /* Make sure we have all the headers */ if (len < length * NSH_HDR_WORD_SIZE) goto trunc; ND_TCHECK2(*bp, length * NSH_HDR_WORD_SIZE); /* * length includes the lengths of the Base and Service Path headers. * That means it must be at least 2. */ if (length < 2) goto trunc; /* * Print, or skip, the Context Headers. * (length - 2) is the length of those headers. */ if (ndo->ndo_vflag > 2) { if (md_type == 0x01) { for (n = 0; n < length - 2; n++) { ctx = EXTRACT_32BITS(bp); bp += NSH_HDR_WORD_SIZE; ND_PRINT((ndo, "\n Context[%02d]: 0x%08x", n, ctx)); } } else if (md_type == 0x02) { n = 0; while (n < length - 2) { tlv_class = EXTRACT_16BITS(bp); bp += 2; tlv_type = *bp; bp += 1; tlv_len = *bp; bp += 1; ND_PRINT((ndo, "\n TLV Class %d, Type %d, Len %d", tlv_class, tlv_type, tlv_len)); n += 1; if (length - 2 < n + tlv_len) { ND_PRINT((ndo, " ERROR: invalid-tlv-length")); return; } for (vn = 0; vn < tlv_len; vn++) { ctx = EXTRACT_32BITS(bp); bp += NSH_HDR_WORD_SIZE; ND_PRINT((ndo, "\n Value[%02d]: 0x%08x", vn, ctx)); } n += tlv_len; } } else { ND_PRINT((ndo, "ERROR: unknown-next-protocol")); return; } } else { bp += (length - 2) * NSH_HDR_WORD_SIZE; } ND_PRINT((ndo, ndo->ndo_vflag ? "\n " : ": ")); /* print Next Protocol */ next_len = len - length * NSH_HDR_WORD_SIZE; switch (next_protocol) { case 0x1: ip_print(ndo, bp, next_len); break; case 0x2: ip6_print(ndo, bp, next_len); break; case 0x3: ether_print(ndo, bp, next_len, ndo->ndo_snapend - bp, NULL, NULL); break; default: ND_PRINT((ndo, "ERROR: unknown-next-protocol")); return; } return; trunc: ND_PRINT((ndo, "%s", tstr)); } tcpdump-4.9.3/print-beep.c0000644000026300017510000000332613544412561013550 0ustar mcrmcr/* * Copyright (C) 2000, Richard Sharpe * * This software may be distributed either under the terms of the * BSD-style license that accompanies tcpdump or under the GNU GPL * version 2 or later. * * print-beep.c * */ /* \summary: Blocks Extensible Exchange Protocol (BEEP) printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include "netdissect.h" /* Check for a string but not go beyond length * Return TRUE on match, FALSE otherwise * * Looks at the first few chars up to tl1 ... */ static int l_strnstart(netdissect_options *ndo, const char *tstr1, u_int tl1, const char *str2, u_int l2) { if (!ND_TTEST2(*str2, tl1)) { /* * We don't have tl1 bytes worth of captured data * for the string, so we can't check for this * string. */ return 0; } if (tl1 > l2) return 0; return (strncmp(tstr1, str2, tl1) == 0 ? 1 : 0); } void beep_print(netdissect_options *ndo, const u_char *bp, u_int length) { if (l_strnstart(ndo, "MSG", 4, (const char *)bp, length)) /* A REQuest */ ND_PRINT((ndo, " BEEP MSG")); else if (l_strnstart(ndo, "RPY ", 4, (const char *)bp, length)) ND_PRINT((ndo, " BEEP RPY")); else if (l_strnstart(ndo, "ERR ", 4, (const char *)bp, length)) ND_PRINT((ndo, " BEEP ERR")); else if (l_strnstart(ndo, "ANS ", 4, (const char *)bp, length)) ND_PRINT((ndo, " BEEP ANS")); else if (l_strnstart(ndo, "NUL ", 4, (const char *)bp, length)) ND_PRINT((ndo, " BEEP NUL")); else if (l_strnstart(ndo, "SEQ ", 4, (const char *)bp, length)) ND_PRINT((ndo, " BEEP SEQ")); else if (l_strnstart(ndo, "END", 4, (const char *)bp, length)) ND_PRINT((ndo, " BEEP END")); else ND_PRINT((ndo, " BEEP (payload or undecoded)")); } tcpdump-4.9.3/print-lldp.c0000644000026300017510000016241413544412561013574 0ustar mcrmcr/* * Copyright (c) 1998-2007 The TCPDUMP project * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code * distributions retain the above copyright notice and this paragraph * in its entirety, and (2) distributions including binary code include * the above copyright notice and this paragraph in its entirety in * the documentation or other materials provided with the distribution. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. * * Original code by Hannes Gredler (hannes@gredler.at) * IEEE and TIA extensions by Carles Kishimoto * DCBX extensions by Kaladhar Musunuru */ /* \summary: IEEE 802.1ab Link Layer Discovery Protocol (LLDP) printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include "netdissect.h" #include "extract.h" #include "addrtoname.h" #include "af.h" #include "oui.h" #define LLDP_EXTRACT_TYPE(x) (((x)&0xfe00)>>9) #define LLDP_EXTRACT_LEN(x) ((x)&0x01ff) /* * TLV type codes */ #define LLDP_END_TLV 0 #define LLDP_CHASSIS_ID_TLV 1 #define LLDP_PORT_ID_TLV 2 #define LLDP_TTL_TLV 3 #define LLDP_PORT_DESCR_TLV 4 #define LLDP_SYSTEM_NAME_TLV 5 #define LLDP_SYSTEM_DESCR_TLV 6 #define LLDP_SYSTEM_CAP_TLV 7 #define LLDP_MGMT_ADDR_TLV 8 #define LLDP_PRIVATE_TLV 127 static const struct tok lldp_tlv_values[] = { { LLDP_END_TLV, "End" }, { LLDP_CHASSIS_ID_TLV, "Chassis ID" }, { LLDP_PORT_ID_TLV, "Port ID" }, { LLDP_TTL_TLV, "Time to Live" }, { LLDP_PORT_DESCR_TLV, "Port Description" }, { LLDP_SYSTEM_NAME_TLV, "System Name" }, { LLDP_SYSTEM_DESCR_TLV, "System Description" }, { LLDP_SYSTEM_CAP_TLV, "System Capabilities" }, { LLDP_MGMT_ADDR_TLV, "Management Address" }, { LLDP_PRIVATE_TLV, "Organization specific" }, { 0, NULL} }; /* * Chassis ID subtypes */ #define LLDP_CHASSIS_CHASSIS_COMP_SUBTYPE 1 #define LLDP_CHASSIS_INTF_ALIAS_SUBTYPE 2 #define LLDP_CHASSIS_PORT_COMP_SUBTYPE 3 #define LLDP_CHASSIS_MAC_ADDR_SUBTYPE 4 #define LLDP_CHASSIS_NETWORK_ADDR_SUBTYPE 5 #define LLDP_CHASSIS_INTF_NAME_SUBTYPE 6 #define LLDP_CHASSIS_LOCAL_SUBTYPE 7 static const struct tok lldp_chassis_subtype_values[] = { { LLDP_CHASSIS_CHASSIS_COMP_SUBTYPE, "Chassis component"}, { LLDP_CHASSIS_INTF_ALIAS_SUBTYPE, "Interface alias"}, { LLDP_CHASSIS_PORT_COMP_SUBTYPE, "Port component"}, { LLDP_CHASSIS_MAC_ADDR_SUBTYPE, "MAC address"}, { LLDP_CHASSIS_NETWORK_ADDR_SUBTYPE, "Network address"}, { LLDP_CHASSIS_INTF_NAME_SUBTYPE, "Interface name"}, { LLDP_CHASSIS_LOCAL_SUBTYPE, "Local"}, { 0, NULL} }; /* * Port ID subtypes */ #define LLDP_PORT_INTF_ALIAS_SUBTYPE 1 #define LLDP_PORT_PORT_COMP_SUBTYPE 2 #define LLDP_PORT_MAC_ADDR_SUBTYPE 3 #define LLDP_PORT_NETWORK_ADDR_SUBTYPE 4 #define LLDP_PORT_INTF_NAME_SUBTYPE 5 #define LLDP_PORT_AGENT_CIRC_ID_SUBTYPE 6 #define LLDP_PORT_LOCAL_SUBTYPE 7 static const struct tok lldp_port_subtype_values[] = { { LLDP_PORT_INTF_ALIAS_SUBTYPE, "Interface alias"}, { LLDP_PORT_PORT_COMP_SUBTYPE, "Port component"}, { LLDP_PORT_MAC_ADDR_SUBTYPE, "MAC address"}, { LLDP_PORT_NETWORK_ADDR_SUBTYPE, "Network Address"}, { LLDP_PORT_INTF_NAME_SUBTYPE, "Interface Name"}, { LLDP_PORT_AGENT_CIRC_ID_SUBTYPE, "Agent circuit ID"}, { LLDP_PORT_LOCAL_SUBTYPE, "Local"}, { 0, NULL} }; /* * System Capabilities */ #define LLDP_CAP_OTHER (1 << 0) #define LLDP_CAP_REPEATER (1 << 1) #define LLDP_CAP_BRIDGE (1 << 2) #define LLDP_CAP_WLAN_AP (1 << 3) #define LLDP_CAP_ROUTER (1 << 4) #define LLDP_CAP_PHONE (1 << 5) #define LLDP_CAP_DOCSIS (1 << 6) #define LLDP_CAP_STATION_ONLY (1 << 7) static const struct tok lldp_cap_values[] = { { LLDP_CAP_OTHER, "Other"}, { LLDP_CAP_REPEATER, "Repeater"}, { LLDP_CAP_BRIDGE, "Bridge"}, { LLDP_CAP_WLAN_AP, "WLAN AP"}, { LLDP_CAP_ROUTER, "Router"}, { LLDP_CAP_PHONE, "Telephone"}, { LLDP_CAP_DOCSIS, "Docsis"}, { LLDP_CAP_STATION_ONLY, "Station Only"}, { 0, NULL} }; #define LLDP_PRIVATE_8021_SUBTYPE_PORT_VLAN_ID 1 #define LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_VLAN_ID 2 #define LLDP_PRIVATE_8021_SUBTYPE_VLAN_NAME 3 #define LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_IDENTITY 4 #define LLDP_PRIVATE_8021_SUBTYPE_CONGESTION_NOTIFICATION 8 #define LLDP_PRIVATE_8021_SUBTYPE_ETS_CONFIGURATION 9 #define LLDP_PRIVATE_8021_SUBTYPE_ETS_RECOMMENDATION 10 #define LLDP_PRIVATE_8021_SUBTYPE_PFC_CONFIGURATION 11 #define LLDP_PRIVATE_8021_SUBTYPE_APPLICATION_PRIORITY 12 #define LLDP_PRIVATE_8021_SUBTYPE_EVB 13 #define LLDP_PRIVATE_8021_SUBTYPE_CDCP 14 static const struct tok lldp_8021_subtype_values[] = { { LLDP_PRIVATE_8021_SUBTYPE_PORT_VLAN_ID, "Port VLAN Id"}, { LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_VLAN_ID, "Port and Protocol VLAN ID"}, { LLDP_PRIVATE_8021_SUBTYPE_VLAN_NAME, "VLAN name"}, { LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_IDENTITY, "Protocol Identity"}, { LLDP_PRIVATE_8021_SUBTYPE_CONGESTION_NOTIFICATION, "Congestion Notification"}, { LLDP_PRIVATE_8021_SUBTYPE_ETS_CONFIGURATION, "ETS Configuration"}, { LLDP_PRIVATE_8021_SUBTYPE_ETS_RECOMMENDATION, "ETS Recommendation"}, { LLDP_PRIVATE_8021_SUBTYPE_PFC_CONFIGURATION, "Priority Flow Control Configuration"}, { LLDP_PRIVATE_8021_SUBTYPE_APPLICATION_PRIORITY, "Application Priority"}, { LLDP_PRIVATE_8021_SUBTYPE_EVB, "EVB"}, { LLDP_PRIVATE_8021_SUBTYPE_CDCP,"CDCP"}, { 0, NULL} }; #define LLDP_8021_PORT_PROTOCOL_VLAN_SUPPORT (1 << 1) #define LLDP_8021_PORT_PROTOCOL_VLAN_STATUS (1 << 2) static const struct tok lldp_8021_port_protocol_id_values[] = { { LLDP_8021_PORT_PROTOCOL_VLAN_SUPPORT, "supported"}, { LLDP_8021_PORT_PROTOCOL_VLAN_STATUS, "enabled"}, { 0, NULL} }; #define LLDP_PRIVATE_8023_SUBTYPE_MACPHY 1 #define LLDP_PRIVATE_8023_SUBTYPE_MDIPOWER 2 #define LLDP_PRIVATE_8023_SUBTYPE_LINKAGGR 3 #define LLDP_PRIVATE_8023_SUBTYPE_MTU 4 static const struct tok lldp_8023_subtype_values[] = { { LLDP_PRIVATE_8023_SUBTYPE_MACPHY, "MAC/PHY configuration/status"}, { LLDP_PRIVATE_8023_SUBTYPE_MDIPOWER, "Power via MDI"}, { LLDP_PRIVATE_8023_SUBTYPE_LINKAGGR, "Link aggregation"}, { LLDP_PRIVATE_8023_SUBTYPE_MTU, "Max frame size"}, { 0, NULL} }; #define LLDP_PRIVATE_TIA_SUBTYPE_CAPABILITIES 1 #define LLDP_PRIVATE_TIA_SUBTYPE_NETWORK_POLICY 2 #define LLDP_PRIVATE_TIA_SUBTYPE_LOCAL_ID 3 #define LLDP_PRIVATE_TIA_SUBTYPE_EXTENDED_POWER_MDI 4 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_HARDWARE_REV 5 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_FIRMWARE_REV 6 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SOFTWARE_REV 7 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SERIAL_NUMBER 8 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MANUFACTURER_NAME 9 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MODEL_NAME 10 #define LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_ASSET_ID 11 static const struct tok lldp_tia_subtype_values[] = { { LLDP_PRIVATE_TIA_SUBTYPE_CAPABILITIES, "LLDP-MED Capabilities" }, { LLDP_PRIVATE_TIA_SUBTYPE_NETWORK_POLICY, "Network policy" }, { LLDP_PRIVATE_TIA_SUBTYPE_LOCAL_ID, "Location identification" }, { LLDP_PRIVATE_TIA_SUBTYPE_EXTENDED_POWER_MDI, "Extended power-via-MDI" }, { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_HARDWARE_REV, "Inventory - hardware revision" }, { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_FIRMWARE_REV, "Inventory - firmware revision" }, { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SOFTWARE_REV, "Inventory - software revision" }, { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SERIAL_NUMBER, "Inventory - serial number" }, { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MANUFACTURER_NAME, "Inventory - manufacturer name" }, { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MODEL_NAME, "Inventory - model name" }, { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_ASSET_ID, "Inventory - asset ID" }, { 0, NULL} }; #define LLDP_PRIVATE_TIA_LOCATION_ALTITUDE_METERS 1 #define LLDP_PRIVATE_TIA_LOCATION_ALTITUDE_FLOORS 2 static const struct tok lldp_tia_location_altitude_type_values[] = { { LLDP_PRIVATE_TIA_LOCATION_ALTITUDE_METERS, "meters"}, { LLDP_PRIVATE_TIA_LOCATION_ALTITUDE_FLOORS, "floors"}, { 0, NULL} }; /* ANSI/TIA-1057 - Annex B */ #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A1 1 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A2 2 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A3 3 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A4 4 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A5 5 #define LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A6 6 static const struct tok lldp_tia_location_lci_catype_values[] = { { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A1, "national subdivisions (state,canton,region,province,prefecture)"}, { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A2, "county, parish, gun, district"}, { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A3, "city, township, shi"}, { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A4, "city division, borough, city district, ward chou"}, { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A5, "neighborhood, block"}, { LLDP_PRIVATE_TIA_LOCATION_LCI_CATYPE_A6, "street"}, { 0, NULL} }; static const struct tok lldp_tia_location_lci_what_values[] = { { 0, "location of DHCP server"}, { 1, "location of the network element believed to be closest to the client"}, { 2, "location of the client"}, { 0, NULL} }; /* * From RFC 3636 - dot3MauType */ #define LLDP_MAU_TYPE_UNKNOWN 0 #define LLDP_MAU_TYPE_AUI 1 #define LLDP_MAU_TYPE_10BASE_5 2 #define LLDP_MAU_TYPE_FOIRL 3 #define LLDP_MAU_TYPE_10BASE_2 4 #define LLDP_MAU_TYPE_10BASE_T 5 #define LLDP_MAU_TYPE_10BASE_FP 6 #define LLDP_MAU_TYPE_10BASE_FB 7 #define LLDP_MAU_TYPE_10BASE_FL 8 #define LLDP_MAU_TYPE_10BROAD36 9 #define LLDP_MAU_TYPE_10BASE_T_HD 10 #define LLDP_MAU_TYPE_10BASE_T_FD 11 #define LLDP_MAU_TYPE_10BASE_FL_HD 12 #define LLDP_MAU_TYPE_10BASE_FL_FD 13 #define LLDP_MAU_TYPE_100BASE_T4 14 #define LLDP_MAU_TYPE_100BASE_TX_HD 15 #define LLDP_MAU_TYPE_100BASE_TX_FD 16 #define LLDP_MAU_TYPE_100BASE_FX_HD 17 #define LLDP_MAU_TYPE_100BASE_FX_FD 18 #define LLDP_MAU_TYPE_100BASE_T2_HD 19 #define LLDP_MAU_TYPE_100BASE_T2_FD 20 #define LLDP_MAU_TYPE_1000BASE_X_HD 21 #define LLDP_MAU_TYPE_1000BASE_X_FD 22 #define LLDP_MAU_TYPE_1000BASE_LX_HD 23 #define LLDP_MAU_TYPE_1000BASE_LX_FD 24 #define LLDP_MAU_TYPE_1000BASE_SX_HD 25 #define LLDP_MAU_TYPE_1000BASE_SX_FD 26 #define LLDP_MAU_TYPE_1000BASE_CX_HD 27 #define LLDP_MAU_TYPE_1000BASE_CX_FD 28 #define LLDP_MAU_TYPE_1000BASE_T_HD 29 #define LLDP_MAU_TYPE_1000BASE_T_FD 30 #define LLDP_MAU_TYPE_10GBASE_X 31 #define LLDP_MAU_TYPE_10GBASE_LX4 32 #define LLDP_MAU_TYPE_10GBASE_R 33 #define LLDP_MAU_TYPE_10GBASE_ER 34 #define LLDP_MAU_TYPE_10GBASE_LR 35 #define LLDP_MAU_TYPE_10GBASE_SR 36 #define LLDP_MAU_TYPE_10GBASE_W 37 #define LLDP_MAU_TYPE_10GBASE_EW 38 #define LLDP_MAU_TYPE_10GBASE_LW 39 #define LLDP_MAU_TYPE_10GBASE_SW 40 static const struct tok lldp_mau_types_values[] = { { LLDP_MAU_TYPE_UNKNOWN, "Unknown"}, { LLDP_MAU_TYPE_AUI, "AUI"}, { LLDP_MAU_TYPE_10BASE_5, "10BASE_5"}, { LLDP_MAU_TYPE_FOIRL, "FOIRL"}, { LLDP_MAU_TYPE_10BASE_2, "10BASE2"}, { LLDP_MAU_TYPE_10BASE_T, "10BASET duplex mode unknown"}, { LLDP_MAU_TYPE_10BASE_FP, "10BASEFP"}, { LLDP_MAU_TYPE_10BASE_FB, "10BASEFB"}, { LLDP_MAU_TYPE_10BASE_FL, "10BASEFL duplex mode unknown"}, { LLDP_MAU_TYPE_10BROAD36, "10BROAD36"}, { LLDP_MAU_TYPE_10BASE_T_HD, "10BASET hdx"}, { LLDP_MAU_TYPE_10BASE_T_FD, "10BASET fdx"}, { LLDP_MAU_TYPE_10BASE_FL_HD, "10BASEFL hdx"}, { LLDP_MAU_TYPE_10BASE_FL_FD, "10BASEFL fdx"}, { LLDP_MAU_TYPE_100BASE_T4, "100BASET4"}, { LLDP_MAU_TYPE_100BASE_TX_HD, "100BASETX hdx"}, { LLDP_MAU_TYPE_100BASE_TX_FD, "100BASETX fdx"}, { LLDP_MAU_TYPE_100BASE_FX_HD, "100BASEFX hdx"}, { LLDP_MAU_TYPE_100BASE_FX_FD, "100BASEFX fdx"}, { LLDP_MAU_TYPE_100BASE_T2_HD, "100BASET2 hdx"}, { LLDP_MAU_TYPE_100BASE_T2_FD, "100BASET2 fdx"}, { LLDP_MAU_TYPE_1000BASE_X_HD, "1000BASEX hdx"}, { LLDP_MAU_TYPE_1000BASE_X_FD, "1000BASEX fdx"}, { LLDP_MAU_TYPE_1000BASE_LX_HD, "1000BASELX hdx"}, { LLDP_MAU_TYPE_1000BASE_LX_FD, "1000BASELX fdx"}, { LLDP_MAU_TYPE_1000BASE_SX_HD, "1000BASESX hdx"}, { LLDP_MAU_TYPE_1000BASE_SX_FD, "1000BASESX fdx"}, { LLDP_MAU_TYPE_1000BASE_CX_HD, "1000BASECX hdx"}, { LLDP_MAU_TYPE_1000BASE_CX_FD, "1000BASECX fdx"}, { LLDP_MAU_TYPE_1000BASE_T_HD, "1000BASET hdx"}, { LLDP_MAU_TYPE_1000BASE_T_FD, "1000BASET fdx"}, { LLDP_MAU_TYPE_10GBASE_X, "10GBASEX"}, { LLDP_MAU_TYPE_10GBASE_LX4, "10GBASELX4"}, { LLDP_MAU_TYPE_10GBASE_R, "10GBASER"}, { LLDP_MAU_TYPE_10GBASE_ER, "10GBASEER"}, { LLDP_MAU_TYPE_10GBASE_LR, "10GBASELR"}, { LLDP_MAU_TYPE_10GBASE_SR, "10GBASESR"}, { LLDP_MAU_TYPE_10GBASE_W, "10GBASEW"}, { LLDP_MAU_TYPE_10GBASE_EW, "10GBASEEW"}, { LLDP_MAU_TYPE_10GBASE_LW, "10GBASELW"}, { LLDP_MAU_TYPE_10GBASE_SW, "10GBASESW"}, { 0, NULL} }; #define LLDP_8023_AUTONEGOTIATION_SUPPORT (1 << 0) #define LLDP_8023_AUTONEGOTIATION_STATUS (1 << 1) static const struct tok lldp_8023_autonegotiation_values[] = { { LLDP_8023_AUTONEGOTIATION_SUPPORT, "supported"}, { LLDP_8023_AUTONEGOTIATION_STATUS, "enabled"}, { 0, NULL} }; #define LLDP_TIA_CAPABILITY_MED (1 << 0) #define LLDP_TIA_CAPABILITY_NETWORK_POLICY (1 << 1) #define LLDP_TIA_CAPABILITY_LOCATION_IDENTIFICATION (1 << 2) #define LLDP_TIA_CAPABILITY_EXTENDED_POWER_MDI_PSE (1 << 3) #define LLDP_TIA_CAPABILITY_EXTENDED_POWER_MDI_PD (1 << 4) #define LLDP_TIA_CAPABILITY_INVENTORY (1 << 5) static const struct tok lldp_tia_capabilities_values[] = { { LLDP_TIA_CAPABILITY_MED, "LLDP-MED capabilities"}, { LLDP_TIA_CAPABILITY_NETWORK_POLICY, "network policy"}, { LLDP_TIA_CAPABILITY_LOCATION_IDENTIFICATION, "location identification"}, { LLDP_TIA_CAPABILITY_EXTENDED_POWER_MDI_PSE, "extended power via MDI-PSE"}, { LLDP_TIA_CAPABILITY_EXTENDED_POWER_MDI_PD, "extended power via MDI-PD"}, { LLDP_TIA_CAPABILITY_INVENTORY, "Inventory"}, { 0, NULL} }; #define LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_1 1 #define LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_2 2 #define LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_3 3 #define LLDP_TIA_DEVICE_TYPE_NETWORK_CONNECTIVITY 4 static const struct tok lldp_tia_device_type_values[] = { { LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_1, "endpoint class 1"}, { LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_2, "endpoint class 2"}, { LLDP_TIA_DEVICE_TYPE_ENDPOINT_CLASS_3, "endpoint class 3"}, { LLDP_TIA_DEVICE_TYPE_NETWORK_CONNECTIVITY, "network connectivity"}, { 0, NULL} }; #define LLDP_TIA_APPLICATION_TYPE_VOICE 1 #define LLDP_TIA_APPLICATION_TYPE_VOICE_SIGNALING 2 #define LLDP_TIA_APPLICATION_TYPE_GUEST_VOICE 3 #define LLDP_TIA_APPLICATION_TYPE_GUEST_VOICE_SIGNALING 4 #define LLDP_TIA_APPLICATION_TYPE_SOFTPHONE_VOICE 5 #define LLDP_TIA_APPLICATION_TYPE_VIDEO_CONFERENCING 6 #define LLDP_TIA_APPLICATION_TYPE_STREAMING_VIDEO 7 #define LLDP_TIA_APPLICATION_TYPE_VIDEO_SIGNALING 8 static const struct tok lldp_tia_application_type_values[] = { { LLDP_TIA_APPLICATION_TYPE_VOICE, "voice"}, { LLDP_TIA_APPLICATION_TYPE_VOICE_SIGNALING, "voice signaling"}, { LLDP_TIA_APPLICATION_TYPE_GUEST_VOICE, "guest voice"}, { LLDP_TIA_APPLICATION_TYPE_GUEST_VOICE_SIGNALING, "guest voice signaling"}, { LLDP_TIA_APPLICATION_TYPE_SOFTPHONE_VOICE, "softphone voice"}, { LLDP_TIA_APPLICATION_TYPE_VIDEO_CONFERENCING, "video conferencing"}, { LLDP_TIA_APPLICATION_TYPE_STREAMING_VIDEO, "streaming video"}, { LLDP_TIA_APPLICATION_TYPE_VIDEO_SIGNALING, "video signaling"}, { 0, NULL} }; #define LLDP_TIA_NETWORK_POLICY_X_BIT (1 << 5) #define LLDP_TIA_NETWORK_POLICY_T_BIT (1 << 6) #define LLDP_TIA_NETWORK_POLICY_U_BIT (1 << 7) static const struct tok lldp_tia_network_policy_bits_values[] = { { LLDP_TIA_NETWORK_POLICY_U_BIT, "Unknown"}, { LLDP_TIA_NETWORK_POLICY_T_BIT, "Tagged"}, { LLDP_TIA_NETWORK_POLICY_X_BIT, "reserved"}, { 0, NULL} }; #define LLDP_EXTRACT_NETWORK_POLICY_VLAN(x) (((x)&0x1ffe)>>1) #define LLDP_EXTRACT_NETWORK_POLICY_L2_PRIORITY(x) (((x)&0x01ff)>>6) #define LLDP_EXTRACT_NETWORK_POLICY_DSCP(x) ((x)&0x003f) #define LLDP_TIA_LOCATION_DATA_FORMAT_COORDINATE_BASED 1 #define LLDP_TIA_LOCATION_DATA_FORMAT_CIVIC_ADDRESS 2 #define LLDP_TIA_LOCATION_DATA_FORMAT_ECS_ELIN 3 static const struct tok lldp_tia_location_data_format_values[] = { { LLDP_TIA_LOCATION_DATA_FORMAT_COORDINATE_BASED, "coordinate-based LCI"}, { LLDP_TIA_LOCATION_DATA_FORMAT_CIVIC_ADDRESS, "civic address LCI"}, { LLDP_TIA_LOCATION_DATA_FORMAT_ECS_ELIN, "ECS ELIN"}, { 0, NULL} }; #define LLDP_TIA_LOCATION_DATUM_WGS_84 1 #define LLDP_TIA_LOCATION_DATUM_NAD_83_NAVD_88 2 #define LLDP_TIA_LOCATION_DATUM_NAD_83_MLLW 3 static const struct tok lldp_tia_location_datum_type_values[] = { { LLDP_TIA_LOCATION_DATUM_WGS_84, "World Geodesic System 1984"}, { LLDP_TIA_LOCATION_DATUM_NAD_83_NAVD_88, "North American Datum 1983 (NAVD88)"}, { LLDP_TIA_LOCATION_DATUM_NAD_83_MLLW, "North American Datum 1983 (MLLW)"}, { 0, NULL} }; #define LLDP_TIA_POWER_SOURCE_PSE 1 #define LLDP_TIA_POWER_SOURCE_LOCAL 2 #define LLDP_TIA_POWER_SOURCE_PSE_AND_LOCAL 3 static const struct tok lldp_tia_power_source_values[] = { { LLDP_TIA_POWER_SOURCE_PSE, "PSE - primary power source"}, { LLDP_TIA_POWER_SOURCE_LOCAL, "local - backup power source"}, { LLDP_TIA_POWER_SOURCE_PSE_AND_LOCAL, "PSE+local - reserved"}, { 0, NULL} }; #define LLDP_TIA_POWER_PRIORITY_CRITICAL 1 #define LLDP_TIA_POWER_PRIORITY_HIGH 2 #define LLDP_TIA_POWER_PRIORITY_LOW 3 static const struct tok lldp_tia_power_priority_values[] = { { LLDP_TIA_POWER_PRIORITY_CRITICAL, "critical"}, { LLDP_TIA_POWER_PRIORITY_HIGH, "high"}, { LLDP_TIA_POWER_PRIORITY_LOW, "low"}, { 0, NULL} }; #define LLDP_TIA_POWER_VAL_MAX 1024 static const struct tok lldp_tia_inventory_values[] = { { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_HARDWARE_REV, "Hardware revision" }, { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_FIRMWARE_REV, "Firmware revision" }, { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SOFTWARE_REV, "Software revision" }, { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SERIAL_NUMBER, "Serial number" }, { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MANUFACTURER_NAME, "Manufacturer name" }, { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MODEL_NAME, "Model name" }, { LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_ASSET_ID, "Asset ID" }, { 0, NULL} }; /* * From RFC 3636 - ifMauAutoNegCapAdvertisedBits */ #define LLDP_MAU_PMD_OTHER (1 << 15) #define LLDP_MAU_PMD_10BASE_T (1 << 14) #define LLDP_MAU_PMD_10BASE_T_FD (1 << 13) #define LLDP_MAU_PMD_100BASE_T4 (1 << 12) #define LLDP_MAU_PMD_100BASE_TX (1 << 11) #define LLDP_MAU_PMD_100BASE_TX_FD (1 << 10) #define LLDP_MAU_PMD_100BASE_T2 (1 << 9) #define LLDP_MAU_PMD_100BASE_T2_FD (1 << 8) #define LLDP_MAU_PMD_FDXPAUSE (1 << 7) #define LLDP_MAU_PMD_FDXAPAUSE (1 << 6) #define LLDP_MAU_PMD_FDXSPAUSE (1 << 5) #define LLDP_MAU_PMD_FDXBPAUSE (1 << 4) #define LLDP_MAU_PMD_1000BASE_X (1 << 3) #define LLDP_MAU_PMD_1000BASE_X_FD (1 << 2) #define LLDP_MAU_PMD_1000BASE_T (1 << 1) #define LLDP_MAU_PMD_1000BASE_T_FD (1 << 0) static const struct tok lldp_pmd_capability_values[] = { { LLDP_MAU_PMD_10BASE_T, "10BASE-T hdx"}, { LLDP_MAU_PMD_10BASE_T_FD, "10BASE-T fdx"}, { LLDP_MAU_PMD_100BASE_T4, "100BASE-T4"}, { LLDP_MAU_PMD_100BASE_TX, "100BASE-TX hdx"}, { LLDP_MAU_PMD_100BASE_TX_FD, "100BASE-TX fdx"}, { LLDP_MAU_PMD_100BASE_T2, "100BASE-T2 hdx"}, { LLDP_MAU_PMD_100BASE_T2_FD, "100BASE-T2 fdx"}, { LLDP_MAU_PMD_FDXPAUSE, "Pause for fdx links"}, { LLDP_MAU_PMD_FDXAPAUSE, "Asym PAUSE for fdx"}, { LLDP_MAU_PMD_FDXSPAUSE, "Sym PAUSE for fdx"}, { LLDP_MAU_PMD_FDXBPAUSE, "Asym and Sym PAUSE for fdx"}, { LLDP_MAU_PMD_1000BASE_X, "1000BASE-{X LX SX CX} hdx"}, { LLDP_MAU_PMD_1000BASE_X_FD, "1000BASE-{X LX SX CX} fdx"}, { LLDP_MAU_PMD_1000BASE_T, "1000BASE-T hdx"}, { LLDP_MAU_PMD_1000BASE_T_FD, "1000BASE-T fdx"}, { 0, NULL} }; #define LLDP_MDI_PORT_CLASS (1 << 0) #define LLDP_MDI_POWER_SUPPORT (1 << 1) #define LLDP_MDI_POWER_STATE (1 << 2) #define LLDP_MDI_PAIR_CONTROL_ABILITY (1 << 3) static const struct tok lldp_mdi_values[] = { { LLDP_MDI_PORT_CLASS, "PSE"}, { LLDP_MDI_POWER_SUPPORT, "supported"}, { LLDP_MDI_POWER_STATE, "enabled"}, { LLDP_MDI_PAIR_CONTROL_ABILITY, "can be controlled"}, { 0, NULL} }; #define LLDP_MDI_PSE_PORT_POWER_PAIRS_SIGNAL 1 #define LLDP_MDI_PSE_PORT_POWER_PAIRS_SPARE 2 static const struct tok lldp_mdi_power_pairs_values[] = { { LLDP_MDI_PSE_PORT_POWER_PAIRS_SIGNAL, "signal"}, { LLDP_MDI_PSE_PORT_POWER_PAIRS_SPARE, "spare"}, { 0, NULL} }; #define LLDP_MDI_POWER_CLASS0 1 #define LLDP_MDI_POWER_CLASS1 2 #define LLDP_MDI_POWER_CLASS2 3 #define LLDP_MDI_POWER_CLASS3 4 #define LLDP_MDI_POWER_CLASS4 5 static const struct tok lldp_mdi_power_class_values[] = { { LLDP_MDI_POWER_CLASS0, "class0"}, { LLDP_MDI_POWER_CLASS1, "class1"}, { LLDP_MDI_POWER_CLASS2, "class2"}, { LLDP_MDI_POWER_CLASS3, "class3"}, { LLDP_MDI_POWER_CLASS4, "class4"}, { 0, NULL} }; #define LLDP_AGGREGATION_CAPABILTIY (1 << 0) #define LLDP_AGGREGATION_STATUS (1 << 1) static const struct tok lldp_aggregation_values[] = { { LLDP_AGGREGATION_CAPABILTIY, "supported"}, { LLDP_AGGREGATION_STATUS, "enabled"}, { 0, NULL} }; /* * DCBX protocol subtypes. */ #define LLDP_DCBX_SUBTYPE_1 1 #define LLDP_DCBX_SUBTYPE_2 2 static const struct tok lldp_dcbx_subtype_values[] = { { LLDP_DCBX_SUBTYPE_1, "DCB Capability Exchange Protocol Rev 1" }, { LLDP_DCBX_SUBTYPE_2, "DCB Capability Exchange Protocol Rev 1.01" }, { 0, NULL} }; #define LLDP_DCBX_CONTROL_TLV 1 #define LLDP_DCBX_PRIORITY_GROUPS_TLV 2 #define LLDP_DCBX_PRIORITY_FLOW_CONTROL_TLV 3 #define LLDP_DCBX_APPLICATION_TLV 4 /* * Interface numbering subtypes. */ #define LLDP_INTF_NUMB_IFX_SUBTYPE 2 #define LLDP_INTF_NUMB_SYSPORT_SUBTYPE 3 static const struct tok lldp_intf_numb_subtype_values[] = { { LLDP_INTF_NUMB_IFX_SUBTYPE, "Interface Index" }, { LLDP_INTF_NUMB_SYSPORT_SUBTYPE, "System Port Number" }, { 0, NULL} }; #define LLDP_INTF_NUM_LEN 5 #define LLDP_EVB_MODE_NOT_SUPPORTED 0 #define LLDP_EVB_MODE_EVB_BRIDGE 1 #define LLDP_EVB_MODE_EVB_STATION 2 #define LLDP_EVB_MODE_RESERVED 3 static const struct tok lldp_evb_mode_values[]={ { LLDP_EVB_MODE_NOT_SUPPORTED, "Not Supported"}, { LLDP_EVB_MODE_EVB_BRIDGE, "EVB Bridge"}, { LLDP_EVB_MODE_EVB_STATION, "EVB Staion"}, { LLDP_EVB_MODE_RESERVED, "Reserved for future Standardization"}, { 0, NULL}, }; #define NO_OF_BITS 8 #define LLDP_PRIVATE_8021_SUBTYPE_CONGESTION_NOTIFICATION_LENGTH 6 #define LLDP_PRIVATE_8021_SUBTYPE_ETS_CONFIGURATION_LENGTH 25 #define LLDP_PRIVATE_8021_SUBTYPE_ETS_RECOMMENDATION_LENGTH 25 #define LLDP_PRIVATE_8021_SUBTYPE_PFC_CONFIGURATION_LENGTH 6 #define LLDP_PRIVATE_8021_SUBTYPE_APPLICATION_PRIORITY_MIN_LENGTH 5 #define LLDP_PRIVATE_8021_SUBTYPE_EVB_LENGTH 9 #define LLDP_PRIVATE_8021_SUBTYPE_CDCP_MIN_LENGTH 8 #define LLDP_IANA_SUBTYPE_MUDURL 1 static const struct tok lldp_iana_subtype_values[] = { { LLDP_IANA_SUBTYPE_MUDURL, "MUD-URL" }, { 0, NULL } }; static void print_ets_priority_assignment_table(netdissect_options *ndo, const u_char *ptr) { ND_PRINT((ndo, "\n\t Priority Assignment Table")); ND_PRINT((ndo, "\n\t Priority : 0 1 2 3 4 5 6 7")); ND_PRINT((ndo, "\n\t Value : %-3d %-3d %-3d %-3d %-3d %-3d %-3d %-3d", ptr[0]>>4,ptr[0]&0x0f,ptr[1]>>4,ptr[1]&0x0f,ptr[2]>>4, ptr[2] & 0x0f, ptr[3] >> 4, ptr[3] & 0x0f)); } static void print_tc_bandwidth_table(netdissect_options *ndo, const u_char *ptr) { ND_PRINT((ndo, "\n\t TC Bandwidth Table")); ND_PRINT((ndo, "\n\t TC%% : 0 1 2 3 4 5 6 7")); ND_PRINT((ndo, "\n\t Value : %-3d %-3d %-3d %-3d %-3d %-3d %-3d %-3d", ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6], ptr[7])); } static void print_tsa_assignment_table(netdissect_options *ndo, const u_char *ptr) { ND_PRINT((ndo, "\n\t TSA Assignment Table")); ND_PRINT((ndo, "\n\t Traffic Class: 0 1 2 3 4 5 6 7")); ND_PRINT((ndo, "\n\t Value : %-3d %-3d %-3d %-3d %-3d %-3d %-3d %-3d", ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6], ptr[7])); } /* * Print IEEE 802.1 private extensions. (802.1AB annex E) */ static int lldp_private_8021_print(netdissect_options *ndo, const u_char *tptr, u_int tlv_len) { int subtype, hexdump = FALSE; u_int sublen; u_int tval; u_int i; if (tlv_len < 4) { return hexdump; } subtype = *(tptr+3); ND_PRINT((ndo, "\n\t %s Subtype (%u)", tok2str(lldp_8021_subtype_values, "unknown", subtype), subtype)); switch (subtype) { case LLDP_PRIVATE_8021_SUBTYPE_PORT_VLAN_ID: if (tlv_len < 6) { return hexdump; } ND_PRINT((ndo, "\n\t port vlan id (PVID): %u", EXTRACT_16BITS(tptr + 4))); break; case LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_VLAN_ID: if (tlv_len < 7) { return hexdump; } ND_PRINT((ndo, "\n\t port and protocol vlan id (PPVID): %u, flags [%s] (0x%02x)", EXTRACT_16BITS(tptr+5), bittok2str(lldp_8021_port_protocol_id_values, "none", *(tptr+4)), *(tptr + 4))); break; case LLDP_PRIVATE_8021_SUBTYPE_VLAN_NAME: if (tlv_len < 6) { return hexdump; } ND_PRINT((ndo, "\n\t vlan id (VID): %u", EXTRACT_16BITS(tptr + 4))); if (tlv_len < 7) { return hexdump; } sublen = *(tptr+6); if (tlv_len < 7+sublen) { return hexdump; } ND_PRINT((ndo, "\n\t vlan name: ")); safeputs(ndo, tptr + 7, sublen); break; case LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_IDENTITY: if (tlv_len < 5) { return hexdump; } sublen = *(tptr+4); if (tlv_len < 5+sublen) { return hexdump; } ND_PRINT((ndo, "\n\t protocol identity: ")); safeputs(ndo, tptr + 5, sublen); break; case LLDP_PRIVATE_8021_SUBTYPE_CONGESTION_NOTIFICATION: if(tlv_len> i) & 0x01)); tval=*(tptr+5); ND_PRINT((ndo, "\n\t Pre-Priority Ready Indicator")); ND_PRINT((ndo, "\n\t Priority : 0 1 2 3 4 5 6 7")); ND_PRINT((ndo, "\n\t Value : ")); for(i=0;i> i) & 0x01)); break; case LLDP_PRIVATE_8021_SUBTYPE_ETS_CONFIGURATION: if(tlv_len> 7, (tval >> 6) & 0x02, (tval >> 3) & 0x07, tval & 0x07)); /*Print Priority Assignment Table*/ print_ets_priority_assignment_table(ndo, tptr + 5); /*Print TC Bandwidth Table*/ print_tc_bandwidth_table(ndo, tptr + 9); /* Print TSA Assignment Table */ print_tsa_assignment_table(ndo, tptr + 17); break; case LLDP_PRIVATE_8021_SUBTYPE_ETS_RECOMMENDATION: if(tlv_len> 7, (tval >> 6) & 0x01, (tval >> 4) & 0x03, (tval & 0x0f))); ND_PRINT((ndo, "\n\t PFC Enable")); tval=*(tptr+5); ND_PRINT((ndo, "\n\t Priority : 0 1 2 3 4 5 6 7")); ND_PRINT((ndo, "\n\t Value : ")); for(i=0;i> i) & 0x01)); break; case LLDP_PRIVATE_8021_SUBTYPE_APPLICATION_PRIORITY: if(tlv_len> 5, (tval >> 3) & 0x03, (tval & 0x07), EXTRACT_16BITS(tptr + i + 5))); i=i+3; } break; case LLDP_PRIVATE_8021_SUBTYPE_EVB: if(tlv_len> 3, (tval >> 2) & 0x01, (tval >> 1) & 0x01, tval & 0x01)); ND_PRINT((ndo, "\n\t EVB Station Status")); tval=*(tptr+5); ND_PRINT((ndo, "\n\t RES: %d, SGID: %d, RRREQ: %d,RRSTAT: %d", tval >> 4, (tval >> 3) & 0x01, (tval >> 2) & 0x01, tval & 0x03)); tval=*(tptr+6); ND_PRINT((ndo, "\n\t R: %d, RTE: %d, ",tval >> 5, tval & 0x1f)); tval=*(tptr+7); ND_PRINT((ndo, "EVB Mode: %s [%d]", tok2str(lldp_evb_mode_values, "unknown", tval >> 6), tval >> 6)); ND_PRINT((ndo, "\n\t ROL: %d, RWD: %d, ", (tval >> 5) & 0x01, tval & 0x1f)); tval=*(tptr+8); ND_PRINT((ndo, "RES: %d, ROL: %d, RKA: %d", tval >> 6, (tval >> 5) & 0x01, tval & 0x1f)); break; case LLDP_PRIVATE_8021_SUBTYPE_CDCP: if(tlv_len> 7, (tval >> 4) & 0x07, (tval >> 3) & 0x01)); ND_PRINT((ndo, "ChnCap: %d", EXTRACT_16BITS(tptr + 6) & 0x0fff)); sublen=tlv_len-8; if(sublen%3!=0) { return hexdump; } i=0; while(i> 12, tval & 0x000fff)); i=i+3; } break; default: hexdump = TRUE; break; } return hexdump; } /* * Print IEEE 802.3 private extensions. (802.3bc) */ static int lldp_private_8023_print(netdissect_options *ndo, const u_char *tptr, u_int tlv_len) { int subtype, hexdump = FALSE; if (tlv_len < 4) { return hexdump; } subtype = *(tptr+3); ND_PRINT((ndo, "\n\t %s Subtype (%u)", tok2str(lldp_8023_subtype_values, "unknown", subtype), subtype)); switch (subtype) { case LLDP_PRIVATE_8023_SUBTYPE_MACPHY: if (tlv_len < 9) { return hexdump; } ND_PRINT((ndo, "\n\t autonegotiation [%s] (0x%02x)", bittok2str(lldp_8023_autonegotiation_values, "none", *(tptr+4)), *(tptr + 4))); ND_PRINT((ndo, "\n\t PMD autoneg capability [%s] (0x%04x)", bittok2str(lldp_pmd_capability_values,"unknown", EXTRACT_16BITS(tptr+5)), EXTRACT_16BITS(tptr + 5))); ND_PRINT((ndo, "\n\t MAU type %s (0x%04x)", tok2str(lldp_mau_types_values, "unknown", EXTRACT_16BITS(tptr+7)), EXTRACT_16BITS(tptr + 7))); break; case LLDP_PRIVATE_8023_SUBTYPE_MDIPOWER: if (tlv_len < 7) { return hexdump; } ND_PRINT((ndo, "\n\t MDI power support [%s], power pair %s, power class %s", bittok2str(lldp_mdi_values, "none", *(tptr+4)), tok2str(lldp_mdi_power_pairs_values, "unknown", *(tptr+5)), tok2str(lldp_mdi_power_class_values, "unknown", *(tptr + 6)))); break; case LLDP_PRIVATE_8023_SUBTYPE_LINKAGGR: if (tlv_len < 9) { return hexdump; } ND_PRINT((ndo, "\n\t aggregation status [%s], aggregation port ID %u", bittok2str(lldp_aggregation_values, "none", *(tptr+4)), EXTRACT_32BITS(tptr + 5))); break; case LLDP_PRIVATE_8023_SUBTYPE_MTU: if (tlv_len < 6) { return hexdump; } ND_PRINT((ndo, "\n\t MTU size %u", EXTRACT_16BITS(tptr + 4))); break; default: hexdump = TRUE; break; } return hexdump; } /* * Extract 34bits of latitude/longitude coordinates. */ static uint64_t lldp_extract_latlon(const u_char *tptr) { uint64_t latlon; latlon = *tptr & 0x3; latlon = (latlon << 32) | EXTRACT_32BITS(tptr+1); return latlon; } /* objects defined in IANA subtype 00 00 5e * (right now there is only one) */ static int lldp_private_iana_print(netdissect_options *ndo, const u_char *tptr, u_int tlv_len) { int subtype, hexdump = FALSE; if (tlv_len < 8) { return hexdump; } subtype = *(tptr+3); ND_PRINT((ndo, "\n\t %s Subtype (%u)", tok2str(lldp_iana_subtype_values, "unknown", subtype), subtype)); switch (subtype) { case LLDP_IANA_SUBTYPE_MUDURL: ND_PRINT((ndo, "\n\t MUD-URL=")); (void)fn_printn(ndo, tptr+4, tlv_len-4, NULL); break; default: hexdump=TRUE; } return hexdump; } /* * Print private TIA extensions. */ static int lldp_private_tia_print(netdissect_options *ndo, const u_char *tptr, u_int tlv_len) { int subtype, hexdump = FALSE; uint8_t location_format; uint16_t power_val; u_int lci_len; uint8_t ca_type, ca_len; if (tlv_len < 4) { return hexdump; } subtype = *(tptr+3); ND_PRINT((ndo, "\n\t %s Subtype (%u)", tok2str(lldp_tia_subtype_values, "unknown", subtype), subtype)); switch (subtype) { case LLDP_PRIVATE_TIA_SUBTYPE_CAPABILITIES: if (tlv_len < 7) { return hexdump; } ND_PRINT((ndo, "\n\t Media capabilities [%s] (0x%04x)", bittok2str(lldp_tia_capabilities_values, "none", EXTRACT_16BITS(tptr + 4)), EXTRACT_16BITS(tptr + 4))); ND_PRINT((ndo, "\n\t Device type [%s] (0x%02x)", tok2str(lldp_tia_device_type_values, "unknown", *(tptr+6)), *(tptr + 6))); break; case LLDP_PRIVATE_TIA_SUBTYPE_NETWORK_POLICY: if (tlv_len < 8) { return hexdump; } ND_PRINT((ndo, "\n\t Application type [%s] (0x%02x)", tok2str(lldp_tia_application_type_values, "none", *(tptr+4)), *(tptr + 4))); ND_PRINT((ndo, ", Flags [%s]", bittok2str( lldp_tia_network_policy_bits_values, "none", *(tptr + 5)))); ND_PRINT((ndo, "\n\t Vlan id %u", LLDP_EXTRACT_NETWORK_POLICY_VLAN(EXTRACT_16BITS(tptr + 5)))); ND_PRINT((ndo, ", L2 priority %u", LLDP_EXTRACT_NETWORK_POLICY_L2_PRIORITY(EXTRACT_16BITS(tptr + 6)))); ND_PRINT((ndo, ", DSCP value %u", LLDP_EXTRACT_NETWORK_POLICY_DSCP(EXTRACT_16BITS(tptr + 6)))); break; case LLDP_PRIVATE_TIA_SUBTYPE_LOCAL_ID: if (tlv_len < 5) { return hexdump; } location_format = *(tptr+4); ND_PRINT((ndo, "\n\t Location data format %s (0x%02x)", tok2str(lldp_tia_location_data_format_values, "unknown", location_format), location_format)); switch (location_format) { case LLDP_TIA_LOCATION_DATA_FORMAT_COORDINATE_BASED: if (tlv_len < 21) { return hexdump; } ND_PRINT((ndo, "\n\t Latitude resolution %u, latitude value %" PRIu64, (*(tptr + 5) >> 2), lldp_extract_latlon(tptr + 5))); ND_PRINT((ndo, "\n\t Longitude resolution %u, longitude value %" PRIu64, (*(tptr + 10) >> 2), lldp_extract_latlon(tptr + 10))); ND_PRINT((ndo, "\n\t Altitude type %s (%u)", tok2str(lldp_tia_location_altitude_type_values, "unknown",(*(tptr+15)>>4)), (*(tptr + 15) >> 4))); ND_PRINT((ndo, "\n\t Altitude resolution %u, altitude value 0x%x", (EXTRACT_16BITS(tptr+15)>>6)&0x3f, ((EXTRACT_32BITS(tptr + 16) & 0x3fffffff)))); ND_PRINT((ndo, "\n\t Datum %s (0x%02x)", tok2str(lldp_tia_location_datum_type_values, "unknown", *(tptr+20)), *(tptr + 20))); break; case LLDP_TIA_LOCATION_DATA_FORMAT_CIVIC_ADDRESS: if (tlv_len < 6) { return hexdump; } lci_len = *(tptr+5); if (lci_len < 3) { return hexdump; } if (tlv_len < 7+lci_len) { return hexdump; } ND_PRINT((ndo, "\n\t LCI length %u, LCI what %s (0x%02x), Country-code ", lci_len, tok2str(lldp_tia_location_lci_what_values, "unknown", *(tptr+6)), *(tptr + 6))); /* Country code */ safeputs(ndo, tptr + 7, 2); lci_len = lci_len-3; tptr = tptr + 9; /* Decode each civic address element */ while (lci_len > 0) { if (lci_len < 2) { return hexdump; } ca_type = *(tptr); ca_len = *(tptr+1); tptr += 2; lci_len -= 2; ND_PRINT((ndo, "\n\t CA type \'%s\' (%u), length %u: ", tok2str(lldp_tia_location_lci_catype_values, "unknown", ca_type), ca_type, ca_len)); /* basic sanity check */ if ( ca_type == 0 || ca_len == 0) { return hexdump; } if (lci_len < ca_len) { return hexdump; } safeputs(ndo, tptr, ca_len); tptr += ca_len; lci_len -= ca_len; } break; case LLDP_TIA_LOCATION_DATA_FORMAT_ECS_ELIN: ND_PRINT((ndo, "\n\t ECS ELIN id ")); safeputs(ndo, tptr + 5, tlv_len - 5); break; default: ND_PRINT((ndo, "\n\t Location ID ")); print_unknown_data(ndo, tptr + 5, "\n\t ", tlv_len - 5); } break; case LLDP_PRIVATE_TIA_SUBTYPE_EXTENDED_POWER_MDI: if (tlv_len < 7) { return hexdump; } ND_PRINT((ndo, "\n\t Power type [%s]", (*(tptr + 4) & 0xC0 >> 6) ? "PD device" : "PSE device")); ND_PRINT((ndo, ", Power source [%s]", tok2str(lldp_tia_power_source_values, "none", (*(tptr + 4) & 0x30) >> 4))); ND_PRINT((ndo, "\n\t Power priority [%s] (0x%02x)", tok2str(lldp_tia_power_priority_values, "none", *(tptr+4)&0x0f), *(tptr + 4) & 0x0f)); power_val = EXTRACT_16BITS(tptr+5); if (power_val < LLDP_TIA_POWER_VAL_MAX) { ND_PRINT((ndo, ", Power %.1f Watts", ((float)power_val) / 10)); } else { ND_PRINT((ndo, ", Power %u (Reserved)", power_val)); } break; case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_HARDWARE_REV: case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_FIRMWARE_REV: case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SOFTWARE_REV: case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_SERIAL_NUMBER: case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MANUFACTURER_NAME: case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_MODEL_NAME: case LLDP_PRIVATE_TIA_SUBTYPE_INVENTORY_ASSET_ID: ND_PRINT((ndo, "\n\t %s ", tok2str(lldp_tia_inventory_values, "unknown", subtype))); safeputs(ndo, tptr + 4, tlv_len - 4); break; default: hexdump = TRUE; break; } return hexdump; } /* * Print DCBX Protocol fields (V 1.01). */ static int lldp_private_dcbx_print(netdissect_options *ndo, const u_char *pptr, u_int len) { int subtype, hexdump = FALSE; uint8_t tval; uint16_t tlv; uint32_t i, pgval, uval; u_int tlen, tlv_type, tlv_len; const u_char *tptr, *mptr; if (len < 4) { return hexdump; } subtype = *(pptr+3); ND_PRINT((ndo, "\n\t %s Subtype (%u)", tok2str(lldp_dcbx_subtype_values, "unknown", subtype), subtype)); /* by passing old version */ if (subtype == LLDP_DCBX_SUBTYPE_1) return TRUE; tptr = pptr + 4; tlen = len - 4; while (tlen >= sizeof(tlv)) { ND_TCHECK2(*tptr, sizeof(tlv)); tlv = EXTRACT_16BITS(tptr); tlv_type = LLDP_EXTRACT_TYPE(tlv); tlv_len = LLDP_EXTRACT_LEN(tlv); hexdump = FALSE; tlen -= sizeof(tlv); tptr += sizeof(tlv); /* loop check */ if (!tlv_type || !tlv_len) { break; } ND_TCHECK2(*tptr, tlv_len); if (tlen < tlv_len) { goto trunc; } /* decode every tlv */ switch (tlv_type) { case LLDP_DCBX_CONTROL_TLV: if (tlv_len < 10) { goto trunc; } ND_PRINT((ndo, "\n\t Control - Protocol Control (type 0x%x, length %d)", LLDP_DCBX_CONTROL_TLV, tlv_len)); ND_PRINT((ndo, "\n\t Oper_Version: %d", *tptr)); ND_PRINT((ndo, "\n\t Max_Version: %d", *(tptr + 1))); ND_PRINT((ndo, "\n\t Sequence Number: %d", EXTRACT_32BITS(tptr + 2))); ND_PRINT((ndo, "\n\t Acknowledgement Number: %d", EXTRACT_32BITS(tptr + 6))); break; case LLDP_DCBX_PRIORITY_GROUPS_TLV: if (tlv_len < 17) { goto trunc; } ND_PRINT((ndo, "\n\t Feature - Priority Group (type 0x%x, length %d)", LLDP_DCBX_PRIORITY_GROUPS_TLV, tlv_len)); ND_PRINT((ndo, "\n\t Oper_Version: %d", *tptr)); ND_PRINT((ndo, "\n\t Max_Version: %d", *(tptr + 1))); ND_PRINT((ndo, "\n\t Info block(0x%02X): ", *(tptr + 2))); tval = *(tptr+2); ND_PRINT((ndo, "Enable bit: %d, Willing bit: %d, Error Bit: %d", (tval & 0x80) ? 1 : 0, (tval & 0x40) ? 1 : 0, (tval & 0x20) ? 1 : 0)); ND_PRINT((ndo, "\n\t SubType: %d", *(tptr + 3))); ND_PRINT((ndo, "\n\t Priority Allocation")); /* * Array of 8 4-bit priority group ID values; we fetch all * 32 bits and extract each nibble. */ pgval = EXTRACT_32BITS(tptr+4); for (i = 0; i <= 7; i++) { ND_PRINT((ndo, "\n\t PgId_%d: %d", i, (pgval >> (28 - 4 * i)) & 0xF)); } ND_PRINT((ndo, "\n\t Priority Group Allocation")); for (i = 0; i <= 7; i++) ND_PRINT((ndo, "\n\t Pg percentage[%d]: %d", i, *(tptr + 8 + i))); ND_PRINT((ndo, "\n\t NumTCsSupported: %d", *(tptr + 8 + 8))); break; case LLDP_DCBX_PRIORITY_FLOW_CONTROL_TLV: if (tlv_len < 6) { goto trunc; } ND_PRINT((ndo, "\n\t Feature - Priority Flow Control")); ND_PRINT((ndo, " (type 0x%x, length %d)", LLDP_DCBX_PRIORITY_FLOW_CONTROL_TLV, tlv_len)); ND_PRINT((ndo, "\n\t Oper_Version: %d", *tptr)); ND_PRINT((ndo, "\n\t Max_Version: %d", *(tptr + 1))); ND_PRINT((ndo, "\n\t Info block(0x%02X): ", *(tptr + 2))); tval = *(tptr+2); ND_PRINT((ndo, "Enable bit: %d, Willing bit: %d, Error Bit: %d", (tval & 0x80) ? 1 : 0, (tval & 0x40) ? 1 : 0, (tval & 0x20) ? 1 : 0)); ND_PRINT((ndo, "\n\t SubType: %d", *(tptr + 3))); tval = *(tptr+4); ND_PRINT((ndo, "\n\t PFC Config (0x%02X)", *(tptr + 4))); for (i = 0; i <= 7; i++) ND_PRINT((ndo, "\n\t Priority Bit %d: %s", i, (tval & (1 << i)) ? "Enabled" : "Disabled")); ND_PRINT((ndo, "\n\t NumTCPFCSupported: %d", *(tptr + 5))); break; case LLDP_DCBX_APPLICATION_TLV: if (tlv_len < 4) { goto trunc; } ND_PRINT((ndo, "\n\t Feature - Application (type 0x%x, length %d)", LLDP_DCBX_APPLICATION_TLV, tlv_len)); ND_PRINT((ndo, "\n\t Oper_Version: %d", *tptr)); ND_PRINT((ndo, "\n\t Max_Version: %d", *(tptr + 1))); ND_PRINT((ndo, "\n\t Info block(0x%02X): ", *(tptr + 2))); tval = *(tptr+2); ND_PRINT((ndo, "Enable bit: %d, Willing bit: %d, Error Bit: %d", (tval & 0x80) ? 1 : 0, (tval & 0x40) ? 1 : 0, (tval & 0x20) ? 1 : 0)); ND_PRINT((ndo, "\n\t SubType: %d", *(tptr + 3))); tval = tlv_len - 4; mptr = tptr + 4; while (tval >= 6) { ND_PRINT((ndo, "\n\t Application Value")); ND_PRINT((ndo, "\n\t Application Protocol ID: 0x%04x", EXTRACT_16BITS(mptr))); uval = EXTRACT_24BITS(mptr+2); ND_PRINT((ndo, "\n\t SF (0x%x) Application Protocol ID is %s", (uval >> 22), (uval >> 22) ? "Socket Number" : "L2 EtherType")); ND_PRINT((ndo, "\n\t OUI: 0x%06x", uval & 0x3fffff)); ND_PRINT((ndo, "\n\t User Priority Map: 0x%02x", *(mptr + 5))); tval = tval - 6; mptr = mptr + 6; } break; default: hexdump = TRUE; break; } /* do we also want to see a hex dump ? */ if (ndo->ndo_vflag > 1 || (ndo->ndo_vflag && hexdump)) { print_unknown_data(ndo, tptr, "\n\t ", tlv_len); } tlen -= tlv_len; tptr += tlv_len; } trunc: return hexdump; } static char * lldp_network_addr_print(netdissect_options *ndo, const u_char *tptr, u_int len) { uint8_t af; static char buf[BUFSIZE]; const char * (*pfunc)(netdissect_options *, const u_char *); if (len < 1) return NULL; len--; af = *tptr; switch (af) { case AFNUM_INET: if (len < 4) return NULL; /* This cannot be assigned to ipaddr_string(), which is a macro. */ pfunc = getname; break; case AFNUM_INET6: if (len < 16) return NULL; /* This cannot be assigned to ip6addr_string(), which is a macro. */ pfunc = getname6; break; case AFNUM_802: if (len < 6) return NULL; pfunc = etheraddr_string; break; default: pfunc = NULL; break; } if (!pfunc) { snprintf(buf, sizeof(buf), "AFI %s (%u), no AF printer !", tok2str(af_values, "Unknown", af), af); } else { snprintf(buf, sizeof(buf), "AFI %s (%u): %s", tok2str(af_values, "Unknown", af), af, (*pfunc)(ndo, tptr+1)); } return buf; } static int lldp_mgmt_addr_tlv_print(netdissect_options *ndo, const u_char *pptr, u_int len) { uint8_t mgmt_addr_len, intf_num_subtype, oid_len; const u_char *tptr; u_int tlen; char *mgmt_addr; tlen = len; tptr = pptr; if (tlen < 1) { return 0; } mgmt_addr_len = *tptr++; tlen--; if (tlen < mgmt_addr_len) { return 0; } mgmt_addr = lldp_network_addr_print(ndo, tptr, mgmt_addr_len); if (mgmt_addr == NULL) { return 0; } ND_PRINT((ndo, "\n\t Management Address length %u, %s", mgmt_addr_len, mgmt_addr)); tptr += mgmt_addr_len; tlen -= mgmt_addr_len; if (tlen < LLDP_INTF_NUM_LEN) { return 0; } intf_num_subtype = *tptr; ND_PRINT((ndo, "\n\t %s Interface Numbering (%u): %u", tok2str(lldp_intf_numb_subtype_values, "Unknown", intf_num_subtype), intf_num_subtype, EXTRACT_32BITS(tptr + 1))); tptr += LLDP_INTF_NUM_LEN; tlen -= LLDP_INTF_NUM_LEN; /* * The OID is optional. */ if (tlen) { oid_len = *tptr; if (tlen < 1U + oid_len) { return 0; } if (oid_len) { ND_PRINT((ndo, "\n\t OID length %u", oid_len)); safeputs(ndo, tptr + 1, oid_len); } } return 1; } void lldp_print(netdissect_options *ndo, register const u_char *pptr, register u_int len) { uint8_t subtype; uint16_t tlv, cap, ena_cap; u_int oui, tlen, hexdump, tlv_type, tlv_len; const u_char *tptr; char *network_addr; tptr = pptr; tlen = len; ND_PRINT((ndo, "LLDP, length %u", len)); while (tlen >= sizeof(tlv)) { ND_TCHECK2(*tptr, sizeof(tlv)); tlv = EXTRACT_16BITS(tptr); tlv_type = LLDP_EXTRACT_TYPE(tlv); tlv_len = LLDP_EXTRACT_LEN(tlv); hexdump = FALSE; tlen -= sizeof(tlv); tptr += sizeof(tlv); if (ndo->ndo_vflag) { ND_PRINT((ndo, "\n\t%s TLV (%u), length %u", tok2str(lldp_tlv_values, "Unknown", tlv_type), tlv_type, tlv_len)); } /* infinite loop check */ if (!tlv_type || !tlv_len) { break; } ND_TCHECK2(*tptr, tlv_len); if (tlen < tlv_len) { goto trunc; } switch (tlv_type) { case LLDP_CHASSIS_ID_TLV: if (ndo->ndo_vflag) { if (tlv_len < 2) { goto trunc; } subtype = *tptr; ND_PRINT((ndo, "\n\t Subtype %s (%u): ", tok2str(lldp_chassis_subtype_values, "Unknown", subtype), subtype)); switch (subtype) { case LLDP_CHASSIS_MAC_ADDR_SUBTYPE: if (tlv_len < 1+6) { goto trunc; } ND_PRINT((ndo, "%s", etheraddr_string(ndo, tptr + 1))); break; case LLDP_CHASSIS_INTF_NAME_SUBTYPE: /* fall through */ case LLDP_CHASSIS_LOCAL_SUBTYPE: case LLDP_CHASSIS_CHASSIS_COMP_SUBTYPE: case LLDP_CHASSIS_INTF_ALIAS_SUBTYPE: case LLDP_CHASSIS_PORT_COMP_SUBTYPE: safeputs(ndo, tptr + 1, tlv_len - 1); break; case LLDP_CHASSIS_NETWORK_ADDR_SUBTYPE: network_addr = lldp_network_addr_print(ndo, tptr+1, tlv_len-1); if (network_addr == NULL) { goto trunc; } ND_PRINT((ndo, "%s", network_addr)); break; default: hexdump = TRUE; break; } } break; case LLDP_PORT_ID_TLV: if (ndo->ndo_vflag) { if (tlv_len < 2) { goto trunc; } subtype = *tptr; ND_PRINT((ndo, "\n\t Subtype %s (%u): ", tok2str(lldp_port_subtype_values, "Unknown", subtype), subtype)); switch (subtype) { case LLDP_PORT_MAC_ADDR_SUBTYPE: if (tlv_len < 1+6) { goto trunc; } ND_PRINT((ndo, "%s", etheraddr_string(ndo, tptr + 1))); break; case LLDP_PORT_INTF_NAME_SUBTYPE: /* fall through */ case LLDP_PORT_LOCAL_SUBTYPE: case LLDP_PORT_AGENT_CIRC_ID_SUBTYPE: case LLDP_PORT_INTF_ALIAS_SUBTYPE: case LLDP_PORT_PORT_COMP_SUBTYPE: safeputs(ndo, tptr + 1, tlv_len - 1); break; case LLDP_PORT_NETWORK_ADDR_SUBTYPE: network_addr = lldp_network_addr_print(ndo, tptr+1, tlv_len-1); if (network_addr == NULL) { goto trunc; } ND_PRINT((ndo, "%s", network_addr)); break; default: hexdump = TRUE; break; } } break; case LLDP_TTL_TLV: if (ndo->ndo_vflag) { if (tlv_len < 2) { goto trunc; } ND_PRINT((ndo, ": TTL %us", EXTRACT_16BITS(tptr))); } break; case LLDP_PORT_DESCR_TLV: if (ndo->ndo_vflag) { ND_PRINT((ndo, ": ")); safeputs(ndo, tptr, tlv_len); } break; case LLDP_SYSTEM_NAME_TLV: /* * The system name is also print in non-verbose mode * similar to the CDP printer. */ ND_PRINT((ndo, ": ")); safeputs(ndo, tptr, tlv_len); break; case LLDP_SYSTEM_DESCR_TLV: if (ndo->ndo_vflag) { ND_PRINT((ndo, "\n\t ")); safeputs(ndo, tptr, tlv_len); } break; case LLDP_SYSTEM_CAP_TLV: if (ndo->ndo_vflag) { /* * XXX - IEEE Std 802.1AB-2009 says the first octet * if a chassis ID subtype, with the system * capabilities and enabled capabilities following * it. */ if (tlv_len < 4) { goto trunc; } cap = EXTRACT_16BITS(tptr); ena_cap = EXTRACT_16BITS(tptr+2); ND_PRINT((ndo, "\n\t System Capabilities [%s] (0x%04x)", bittok2str(lldp_cap_values, "none", cap), cap)); ND_PRINT((ndo, "\n\t Enabled Capabilities [%s] (0x%04x)", bittok2str(lldp_cap_values, "none", ena_cap), ena_cap)); } break; case LLDP_MGMT_ADDR_TLV: if (ndo->ndo_vflag) { if (!lldp_mgmt_addr_tlv_print(ndo, tptr, tlv_len)) { goto trunc; } } break; case LLDP_PRIVATE_TLV: if (ndo->ndo_vflag) { if (tlv_len < 3) { goto trunc; } oui = EXTRACT_24BITS(tptr); ND_PRINT((ndo, ": OUI %s (0x%06x)", tok2str(oui_values, "Unknown", oui), oui)); switch (oui) { case OUI_IEEE_8021_PRIVATE: hexdump = lldp_private_8021_print(ndo, tptr, tlv_len); break; case OUI_IEEE_8023_PRIVATE: hexdump = lldp_private_8023_print(ndo, tptr, tlv_len); break; case OUI_IANA: hexdump = lldp_private_iana_print(ndo, tptr, tlv_len); break; case OUI_TIA: hexdump = lldp_private_tia_print(ndo, tptr, tlv_len); break; case OUI_DCBX: hexdump = lldp_private_dcbx_print(ndo, tptr, tlv_len); break; default: hexdump = TRUE; break; } } break; default: hexdump = TRUE; break; } /* do we also want to see a hex dump ? */ if (ndo->ndo_vflag > 1 || (ndo->ndo_vflag && hexdump)) { print_unknown_data(ndo, tptr, "\n\t ", tlv_len); } tlen -= tlv_len; tptr += tlv_len; } return; trunc: ND_PRINT((ndo, "\n\t[|LLDP]")); } /* * Local Variables: * c-style: whitesmith * c-basic-offset: 4 * End: */ tcpdump-4.9.3/print-telnet.c0000644000026300017510000003602613544412561014133 0ustar mcrmcr/* $NetBSD: print-telnet.c,v 1.2 1999/10/11 12:40:12 sjg Exp $ */ /*- * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Simon J. Gerraty. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the NetBSD * Foundation, Inc. and its contributors. * 4. Neither the name of The NetBSD Foundation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /* * @(#)Copyright (c) 1994, Simon J. Gerraty. * * This is free software. It comes with NO WARRANTY. * Permission to use, modify and distribute this source code * is granted subject to the following conditions. * 1/ that the above copyright notice and this notice * are preserved in all copies. */ /* \summary: Telnet option printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include "netdissect.h" static const char tstr[] = " [|telnet]"; #define TELCMDS #define TELOPTS /* NetBSD: telnet.h,v 1.9 2001/06/11 01:50:50 wiz Exp */ /* * Definitions for the TELNET protocol. */ #define IAC 255 /* interpret as command: */ #define DONT 254 /* you are not to use option */ #define DO 253 /* please, you use option */ #define WONT 252 /* I won't use option */ #define WILL 251 /* I will use option */ #define SB 250 /* interpret as subnegotiation */ #define GA 249 /* you may reverse the line */ #define EL 248 /* erase the current line */ #define EC 247 /* erase the current character */ #define AYT 246 /* are you there */ #define AO 245 /* abort output--but let prog finish */ #define IP 244 /* interrupt process--permanently */ #define BREAK 243 /* break */ #define DM 242 /* data mark--for connect. cleaning */ #define NOP 241 /* nop */ #define SE 240 /* end sub negotiation */ #define EOR 239 /* end of record (transparent mode) */ #define ABORT 238 /* Abort process */ #define SUSP 237 /* Suspend process */ #define xEOF 236 /* End of file: EOF is already used... */ #define SYNCH 242 /* for telfunc calls */ #ifdef TELCMDS static const char *telcmds[] = { "EOF", "SUSP", "ABORT", "EOR", "SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC", "EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC", 0, }; #else extern char *telcmds[]; #endif #define TELCMD_FIRST xEOF #define TELCMD_LAST IAC #define TELCMD_OK(x) ((unsigned int)(x) <= TELCMD_LAST && \ (unsigned int)(x) >= TELCMD_FIRST) #define TELCMD(x) telcmds[(x)-TELCMD_FIRST] /* telnet options */ #define TELOPT_BINARY 0 /* 8-bit data path */ #define TELOPT_ECHO 1 /* echo */ #define TELOPT_RCP 2 /* prepare to reconnect */ #define TELOPT_SGA 3 /* suppress go ahead */ #define TELOPT_NAMS 4 /* approximate message size */ #define TELOPT_STATUS 5 /* give status */ #define TELOPT_TM 6 /* timing mark */ #define TELOPT_RCTE 7 /* remote controlled transmission and echo */ #define TELOPT_NAOL 8 /* negotiate about output line width */ #define TELOPT_NAOP 9 /* negotiate about output page size */ #define TELOPT_NAOCRD 10 /* negotiate about CR disposition */ #define TELOPT_NAOHTS 11 /* negotiate about horizontal tabstops */ #define TELOPT_NAOHTD 12 /* negotiate about horizontal tab disposition */ #define TELOPT_NAOFFD 13 /* negotiate about formfeed disposition */ #define TELOPT_NAOVTS 14 /* negotiate about vertical tab stops */ #define TELOPT_NAOVTD 15 /* negotiate about vertical tab disposition */ #define TELOPT_NAOLFD 16 /* negotiate about output LF disposition */ #define TELOPT_XASCII 17 /* extended ascic character set */ #define TELOPT_LOGOUT 18 /* force logout */ #define TELOPT_BM 19 /* byte macro */ #define TELOPT_DET 20 /* data entry terminal */ #define TELOPT_SUPDUP 21 /* supdup protocol */ #define TELOPT_SUPDUPOUTPUT 22 /* supdup output */ #define TELOPT_SNDLOC 23 /* send location */ #define TELOPT_TTYPE 24 /* terminal type */ #define TELOPT_EOR 25 /* end or record */ #define TELOPT_TUID 26 /* TACACS user identification */ #define TELOPT_OUTMRK 27 /* output marking */ #define TELOPT_TTYLOC 28 /* terminal location number */ #define TELOPT_3270REGIME 29 /* 3270 regime */ #define TELOPT_X3PAD 30 /* X.3 PAD */ #define TELOPT_NAWS 31 /* window size */ #define TELOPT_TSPEED 32 /* terminal speed */ #define TELOPT_LFLOW 33 /* remote flow control */ #define TELOPT_LINEMODE 34 /* Linemode option */ #define TELOPT_XDISPLOC 35 /* X Display Location */ #define TELOPT_OLD_ENVIRON 36 /* Old - Environment variables */ #define TELOPT_AUTHENTICATION 37/* Authenticate */ #define TELOPT_ENCRYPT 38 /* Encryption option */ #define TELOPT_NEW_ENVIRON 39 /* New - Environment variables */ #define TELOPT_EXOPL 255 /* extended-options-list */ #define NTELOPTS (1+TELOPT_NEW_ENVIRON) #ifdef TELOPTS static const char *telopts[NTELOPTS+1] = { "BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME", "STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP", "NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS", "NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO", "DATA ENTRY TERMINAL", "SUPDUP", "SUPDUP OUTPUT", "SEND LOCATION", "TERMINAL TYPE", "END OF RECORD", "TACACS UID", "OUTPUT MARKING", "TTYLOC", "3270 REGIME", "X.3 PAD", "NAWS", "TSPEED", "LFLOW", "LINEMODE", "XDISPLOC", "OLD-ENVIRON", "AUTHENTICATION", "ENCRYPT", "NEW-ENVIRON", 0, }; #define TELOPT_FIRST TELOPT_BINARY #define TELOPT_LAST TELOPT_NEW_ENVIRON #define TELOPT_OK(x) ((unsigned int)(x) <= TELOPT_LAST) #define TELOPT(x) telopts[(x)-TELOPT_FIRST] #endif /* sub-option qualifiers */ #define TELQUAL_IS 0 /* option is... */ #define TELQUAL_SEND 1 /* send option */ #define TELQUAL_INFO 2 /* ENVIRON: informational version of IS */ #define TELQUAL_REPLY 2 /* AUTHENTICATION: client version of IS */ #define TELQUAL_NAME 3 /* AUTHENTICATION: client version of IS */ #define LFLOW_OFF 0 /* Disable remote flow control */ #define LFLOW_ON 1 /* Enable remote flow control */ #define LFLOW_RESTART_ANY 2 /* Restart output on any char */ #define LFLOW_RESTART_XON 3 /* Restart output only on XON */ /* * LINEMODE suboptions */ #define LM_MODE 1 #define LM_FORWARDMASK 2 #define LM_SLC 3 #define MODE_EDIT 0x01 #define MODE_TRAPSIG 0x02 #define MODE_ACK 0x04 #define MODE_SOFT_TAB 0x08 #define MODE_LIT_ECHO 0x10 #define MODE_MASK 0x1f #define SLC_SYNCH 1 #define SLC_BRK 2 #define SLC_IP 3 #define SLC_AO 4 #define SLC_AYT 5 #define SLC_EOR 6 #define SLC_ABORT 7 #define SLC_EOF 8 #define SLC_SUSP 9 #define SLC_EC 10 #define SLC_EL 11 #define SLC_EW 12 #define SLC_RP 13 #define SLC_LNEXT 14 #define SLC_XON 15 #define SLC_XOFF 16 #define SLC_FORW1 17 #define SLC_FORW2 18 #define SLC_MCL 19 #define SLC_MCR 20 #define SLC_MCWL 21 #define SLC_MCWR 22 #define SLC_MCBOL 23 #define SLC_MCEOL 24 #define SLC_INSRT 25 #define SLC_OVER 26 #define SLC_ECR 27 #define SLC_EWR 28 #define SLC_EBOL 29 #define SLC_EEOL 30 #define NSLC 30 /* * For backwards compatibility, we define SLC_NAMES to be the * list of names if SLC_NAMES is not defined. */ #define SLC_NAMELIST "0", "SYNCH", "BRK", "IP", "AO", "AYT", "EOR", \ "ABORT", "EOF", "SUSP", "EC", "EL", "EW", "RP", \ "LNEXT", "XON", "XOFF", "FORW1", "FORW2", \ "MCL", "MCR", "MCWL", "MCWR", "MCBOL", \ "MCEOL", "INSRT", "OVER", "ECR", "EWR", \ "EBOL", "EEOL", \ 0, #ifdef SLC_NAMES const char *slc_names[] = { SLC_NAMELIST }; #else extern char *slc_names[]; #define SLC_NAMES SLC_NAMELIST #endif #define SLC_NAME_OK(x) ((unsigned int)(x) <= NSLC) #define SLC_NAME(x) slc_names[x] #define SLC_NOSUPPORT 0 #define SLC_CANTCHANGE 1 #define SLC_VARIABLE 2 #define SLC_DEFAULT 3 #define SLC_LEVELBITS 0x03 #define SLC_FUNC 0 #define SLC_FLAGS 1 #define SLC_VALUE 2 #define SLC_ACK 0x80 #define SLC_FLUSHIN 0x40 #define SLC_FLUSHOUT 0x20 #define OLD_ENV_VAR 1 #define OLD_ENV_VALUE 0 #define NEW_ENV_VAR 0 #define NEW_ENV_VALUE 1 #define ENV_ESC 2 #define ENV_USERVAR 3 /* * AUTHENTICATION suboptions */ /* * Who is authenticating who ... */ #define AUTH_WHO_CLIENT 0 /* Client authenticating server */ #define AUTH_WHO_SERVER 1 /* Server authenticating client */ #define AUTH_WHO_MASK 1 #define AUTHTYPE_NULL 0 #define AUTHTYPE_KERBEROS_V4 1 #define AUTHTYPE_KERBEROS_V5 2 #define AUTHTYPE_SPX 3 #define AUTHTYPE_MINK 4 #define AUTHTYPE_CNT 5 #define AUTHTYPE_TEST 99 #ifdef AUTH_NAMES const char *authtype_names[] = { "NULL", "KERBEROS_V4", "KERBEROS_V5", "SPX", "MINK", 0, }; #else extern char *authtype_names[]; #endif #define AUTHTYPE_NAME_OK(x) ((unsigned int)(x) < AUTHTYPE_CNT) #define AUTHTYPE_NAME(x) authtype_names[x] /* * ENCRYPTion suboptions */ #define ENCRYPT_IS 0 /* I pick encryption type ... */ #define ENCRYPT_SUPPORT 1 /* I support encryption types ... */ #define ENCRYPT_REPLY 2 /* Initial setup response */ #define ENCRYPT_START 3 /* Am starting to send encrypted */ #define ENCRYPT_END 4 /* Am ending encrypted */ #define ENCRYPT_REQSTART 5 /* Request you start encrypting */ #define ENCRYPT_REQEND 6 /* Request you send encrypting */ #define ENCRYPT_ENC_KEYID 7 #define ENCRYPT_DEC_KEYID 8 #define ENCRYPT_CNT 9 #define ENCTYPE_ANY 0 #define ENCTYPE_DES_CFB64 1 #define ENCTYPE_DES_OFB64 2 #define ENCTYPE_CNT 3 #ifdef ENCRYPT_NAMES const char *encrypt_names[] = { "IS", "SUPPORT", "REPLY", "START", "END", "REQUEST-START", "REQUEST-END", "ENC-KEYID", "DEC-KEYID", 0, }; const char *enctype_names[] = { "ANY", "DES_CFB64", "DES_OFB64", 0, }; #else extern char *encrypt_names[]; extern char *enctype_names[]; #endif #define ENCRYPT_NAME_OK(x) ((unsigned int)(x) < ENCRYPT_CNT) #define ENCRYPT_NAME(x) encrypt_names[x] #define ENCTYPE_NAME_OK(x) ((unsigned int)(x) < ENCTYPE_CNT) #define ENCTYPE_NAME(x) enctype_names[x] /* normal */ static const char *cmds[] = { "IS", "SEND", "INFO", }; /* 37: Authentication */ static const char *authcmd[] = { "IS", "SEND", "REPLY", "NAME", }; static const char *authtype[] = { "NULL", "KERBEROS_V4", "KERBEROS_V5", "SPX", "MINK", "SRP", "RSA", "SSL", NULL, NULL, "LOKI", "SSA", "KEA_SJ", "KEA_SJ_INTEG", "DSS", "NTLM", }; /* 38: Encryption */ static const char *enccmd[] = { "IS", "SUPPORT", "REPLY", "START", "END", "REQUEST-START", "REQUEST-END", "END_KEYID", "DEC_KEYID", }; static const char *enctype[] = { "NULL", "DES_CFB64", "DES_OFB64", "DES3_CFB64", "DES3_OFB64", NULL, "CAST5_40_CFB64", "CAST5_40_OFB64", "CAST128_CFB64", "CAST128_OFB64", }; #define STR_OR_ID(x, tab) \ (((x) < sizeof(tab)/sizeof(tab[0]) && tab[(x)]) ? tab[(x)] : numstr(x)) static char * numstr(int x) { static char buf[20]; snprintf(buf, sizeof(buf), "%#x", x); return buf; } /* sp points to IAC byte */ static int telnet_parse(netdissect_options *ndo, const u_char *sp, u_int length, int print) { int i, x; u_int c; const u_char *osp, *p; #define FETCH(c, sp, length) \ do { \ if (length < 1) \ goto pktend; \ ND_TCHECK(*sp); \ c = *sp++; \ length--; \ } while (0) osp = sp; FETCH(c, sp, length); if (c != IAC) goto pktend; FETCH(c, sp, length); if (c == IAC) { /* ! */ if (print) ND_PRINT((ndo, "IAC IAC")); goto done; } i = c - TELCMD_FIRST; if (i < 0 || i > IAC - TELCMD_FIRST) goto pktend; switch (c) { case DONT: case DO: case WONT: case WILL: case SB: /* DONT/DO/WONT/WILL x */ FETCH(x, sp, length); if (x >= 0 && x < NTELOPTS) { if (print) ND_PRINT((ndo, "%s %s", telcmds[i], telopts[x])); } else { if (print) ND_PRINT((ndo, "%s %#x", telcmds[i], x)); } if (c != SB) break; /* IAC SB .... IAC SE */ p = sp; while (length > (u_int)(p + 1 - sp)) { ND_TCHECK2(*p, 2); if (p[0] == IAC && p[1] == SE) break; p++; } ND_TCHECK(*p); if (*p != IAC) goto pktend; switch (x) { case TELOPT_AUTHENTICATION: if (p <= sp) break; FETCH(c, sp, length); if (print) ND_PRINT((ndo, " %s", STR_OR_ID(c, authcmd))); if (p <= sp) break; FETCH(c, sp, length); if (print) ND_PRINT((ndo, " %s", STR_OR_ID(c, authtype))); break; case TELOPT_ENCRYPT: if (p <= sp) break; FETCH(c, sp, length); if (print) ND_PRINT((ndo, " %s", STR_OR_ID(c, enccmd))); if (p <= sp) break; FETCH(c, sp, length); if (print) ND_PRINT((ndo, " %s", STR_OR_ID(c, enctype))); break; default: if (p <= sp) break; FETCH(c, sp, length); if (print) ND_PRINT((ndo, " %s", STR_OR_ID(c, cmds))); break; } while (p > sp) { FETCH(x, sp, length); if (print) ND_PRINT((ndo, " %#x", x)); } /* terminating IAC SE */ if (print) ND_PRINT((ndo, " SE")); sp += 2; break; default: if (print) ND_PRINT((ndo, "%s", telcmds[i])); goto done; } done: return sp - osp; trunc: ND_PRINT((ndo, "%s", tstr)); pktend: return -1; #undef FETCH } void telnet_print(netdissect_options *ndo, const u_char *sp, u_int length) { int first = 1; const u_char *osp; int l; osp = sp; ND_TCHECK(*sp); while (length > 0 && *sp == IAC) { /* * Parse the Telnet command without printing it, * to determine its length. */ l = telnet_parse(ndo, sp, length, 0); if (l < 0) break; /* * now print it */ if (ndo->ndo_Xflag && 2 < ndo->ndo_vflag) { if (first) ND_PRINT((ndo, "\nTelnet:")); hex_print_with_offset(ndo, "\n", sp, l, sp - osp); if (l > 8) ND_PRINT((ndo, "\n\t\t\t\t")); else ND_PRINT((ndo, "%*s\t", (8 - l) * 3, "")); } else ND_PRINT((ndo, "%s", (first) ? " [telnet " : ", ")); (void)telnet_parse(ndo, sp, length, 1); first = 0; sp += l; length -= l; ND_TCHECK(*sp); } if (!first) { if (ndo->ndo_Xflag && 2 < ndo->ndo_vflag) ND_PRINT((ndo, "\n")); else ND_PRINT((ndo, "]")); } return; trunc: ND_PRINT((ndo, "%s", tstr)); } tcpdump-4.9.3/VERSION0000644000026300017510000000000613544415511012375 0ustar mcrmcr4.9.3 tcpdump-4.9.3/parsenfsfh.c0000644000026300017510000003157213544412561013646 0ustar mcrmcr/* * Copyright (c) 1993, 1994 Jeffrey C. Mogul, Digital Equipment Corporation, * Western Research Laboratory. All rights reserved. * Copyright (c) 2001 Compaq Computer Corporation. All rights reserved. * * Permission to use, copy, and modify this software and its * documentation is hereby granted only under the following terms and * conditions. Both the above copyright notice and this permission * notice must appear in all copies of the software, derivative works * or modified versions, and any portions thereof, and both notices * must appear in supporting documentation. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * THE SOFTWARE IS PROVIDED "AS IS" AND COMPAQ COMPUTER CORPORATION * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO * EVENT SHALL COMPAQ COMPUTER CORPORATION BE LIABLE FOR ANY * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS * SOFTWARE. */ /* * parsenfsfh.c - portable parser for NFS file handles * uses all sorts of heuristics * * Jeffrey C. Mogul * Digital Equipment Corporation * Western Research Laboratory */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include #include "netdissect.h" #include "nfsfh.h" /* * This routine attempts to parse a file handle (in network byte order), * using heuristics to guess what kind of format it is in. See the * file "fhandle_layouts" for a detailed description of the various * patterns we know about. * * The file handle is parsed into our internal representation of a * file-system id, and an internal representation of an inode-number. */ #define FHT_UNKNOWN 0 #define FHT_AUSPEX 1 #define FHT_DECOSF 2 #define FHT_IRIX4 3 #define FHT_IRIX5 4 #define FHT_SUNOS3 5 #define FHT_SUNOS4 6 #define FHT_ULTRIX 7 #define FHT_VMSUCX 8 #define FHT_SUNOS5 9 #define FHT_AIX32 10 #define FHT_HPUX9 11 #define FHT_BSD44 12 #ifdef ultrix /* Nasty hack to keep the Ultrix C compiler from emitting bogus warnings */ #define XFF(x) ((uint32_t)(x)) #else #define XFF(x) (x) #endif #define make_uint32(msb,b,c,lsb)\ (XFF(lsb) + (XFF(c)<<8) + (XFF(b)<<16) + (XFF(msb)<<24)) #define make_uint24(msb,b, lsb)\ (XFF(lsb) + (XFF(b)<<8) + (XFF(msb)<<16)) #define make_uint16(msb,lsb)\ (XFF(lsb) + (XFF(msb)<<8)) #ifdef __alpha /* or other 64-bit systems */ #define make_uint48(msb,b,c,d,e,lsb)\ ((lsb) + ((e)<<8) + ((d)<<16) + ((c)<<24) + ((b)<<32) + ((msb)<<40)) #else /* on 32-bit systems ignore high-order bits */ #define make_uint48(msb,b,c,d,e,lsb)\ ((lsb) + ((e)<<8) + ((d)<<16) + ((c)<<24)) #endif static int is_UCX(const unsigned char *, u_int); void Parse_fh(register const unsigned char *fh, u_int len, my_fsid *fsidp, uint32_t *inop, const char **osnamep, /* if non-NULL, return OS name here */ const char **fsnamep, /* if non-NULL, return server fs name here (for VMS) */ int ourself) /* true if file handle was generated on this host */ { register const unsigned char *fhp = fh; uint32_t temp; int fhtype = FHT_UNKNOWN; u_int i; /* * Require at least 16 bytes of file handle; it's variable-length * in NFSv3. "len" is in units of 32-bit words, not bytes. */ if (len < 16/4) fhtype = FHT_UNKNOWN; else { if (ourself) { /* File handle generated on this host, no need for guessing */ #if defined(IRIX40) fhtype = FHT_IRIX4; #endif #if defined(IRIX50) fhtype = FHT_IRIX5; #endif #if defined(IRIX51) fhtype = FHT_IRIX5; #endif #if defined(SUNOS4) fhtype = FHT_SUNOS4; #endif #if defined(SUNOS5) fhtype = FHT_SUNOS5; #endif #if defined(ultrix) fhtype = FHT_ULTRIX; #endif #if defined(__osf__) fhtype = FHT_DECOSF; #endif #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) \ || defined(__OpenBSD__) fhtype = FHT_BSD44; #endif } /* * This is basically a big decision tree */ else if ((fhp[0] == 0) && (fhp[1] == 0)) { /* bytes[0,1] == (0,0); rules out Ultrix, IRIX5, SUNOS5 */ /* probably rules out HP-UX, AIX unless they allow major=0 */ if ((fhp[2] == 0) && (fhp[3] == 0)) { /* bytes[2,3] == (0,0); must be Auspex */ /* XXX or could be Ultrix+MASSBUS "hp" disk? */ fhtype = FHT_AUSPEX; } else { /* * bytes[2,3] != (0,0); rules out Auspex, could be * DECOSF, SUNOS4, or IRIX4 */ if ((fhp[4] != 0) && (fhp[5] == 0) && (fhp[8] == 12) && (fhp[9] == 0)) { /* seems to be DECOSF, with minor == 0 */ fhtype = FHT_DECOSF; } else { /* could be SUNOS4 or IRIX4 */ /* XXX the test of fhp[5] == 8 could be wrong */ if ((fhp[4] == 0) && (fhp[5] == 8) && (fhp[6] == 0) && (fhp[7] == 0)) { /* looks like a length, not a file system typecode */ fhtype = FHT_IRIX4; } else { /* by elimination */ fhtype = FHT_SUNOS4; } } } } else { /* * bytes[0,1] != (0,0); rules out Auspex, IRIX4, SUNOS4 * could be IRIX5, DECOSF, UCX, Ultrix, SUNOS5 * could be AIX, HP-UX */ if ((fhp[2] == 0) && (fhp[3] == 0)) { /* * bytes[2,3] == (0,0); rules out OSF, probably not UCX * (unless the exported device name is just one letter!), * could be Ultrix, IRIX5, AIX, or SUNOS5 * might be HP-UX (depends on their values for minor devs) */ if ((fhp[6] == 0) && (fhp[7] == 0)) { fhtype = FHT_BSD44; } /*XXX we probably only need to test of these two bytes */ else if ((len >= 24/4) && (fhp[21] == 0) && (fhp[23] == 0)) { fhtype = FHT_ULTRIX; } else { /* Could be SUNOS5/IRIX5, maybe AIX */ /* XXX no obvious difference between SUNOS5 and IRIX5 */ if (fhp[9] == 10) fhtype = FHT_SUNOS5; /* XXX what about AIX? */ } } else { /* * bytes[2,3] != (0,0); rules out Ultrix, could be * DECOSF, SUNOS5, IRIX5, AIX, HP-UX, or UCX */ if ((fhp[8] == 12) && (fhp[9] == 0)) { fhtype = FHT_DECOSF; } else if ((fhp[8] == 0) && (fhp[9] == 10)) { /* could be SUNOS5/IRIX5, AIX, HP-UX */ if ((fhp[7] == 0) && (fhp[6] == 0) && (fhp[5] == 0) && (fhp[4] == 0)) { /* XXX is this always true of HP-UX? */ fhtype = FHT_HPUX9; } else if (fhp[7] == 2) { /* This would be MNT_NFS on AIX, which is impossible */ fhtype = FHT_SUNOS5; /* or maybe IRIX5 */ } else { /* * XXX Could be SUNOS5/IRIX5 or AIX. I don't * XXX see any way to disambiguate these, so * XXX I'm going with the more likely guess. * XXX Sorry, Big Blue. */ fhtype = FHT_SUNOS5; /* or maybe IRIX5 */ } } else { if (is_UCX(fhp, len)) { fhtype = FHT_VMSUCX; } else { fhtype = FHT_UNKNOWN; } } } } } /* XXX still needs to handle SUNOS3 */ switch (fhtype) { case FHT_AUSPEX: fsidp->Fsid_dev.Minor = fhp[7]; fsidp->Fsid_dev.Major = fhp[6]; fsidp->fsid_code = 0; *inop = make_uint32(fhp[12], fhp[13], fhp[14], fhp[15]); if (osnamep) *osnamep = "Auspex"; break; case FHT_BSD44: fsidp->Fsid_dev.Minor = fhp[0]; fsidp->Fsid_dev.Major = fhp[1]; fsidp->fsid_code = 0; *inop = make_uint32(fhp[15], fhp[14], fhp[13], fhp[12]); if (osnamep) *osnamep = "BSD 4.4"; break; case FHT_DECOSF: fsidp->fsid_code = make_uint32(fhp[7], fhp[6], fhp[5], fhp[4]); /* XXX could ignore 3 high-order bytes */ temp = make_uint32(fhp[3], fhp[2], fhp[1], fhp[0]); fsidp->Fsid_dev.Minor = temp & 0xFFFFF; fsidp->Fsid_dev.Major = (temp>>20) & 0xFFF; *inop = make_uint32(fhp[15], fhp[14], fhp[13], fhp[12]); if (osnamep) *osnamep = "OSF"; break; case FHT_IRIX4: fsidp->Fsid_dev.Minor = fhp[3]; fsidp->Fsid_dev.Major = fhp[2]; fsidp->fsid_code = 0; *inop = make_uint32(fhp[8], fhp[9], fhp[10], fhp[11]); if (osnamep) *osnamep = "IRIX4"; break; case FHT_IRIX5: fsidp->Fsid_dev.Minor = make_uint16(fhp[2], fhp[3]); fsidp->Fsid_dev.Major = make_uint16(fhp[0], fhp[1]); fsidp->fsid_code = make_uint32(fhp[4], fhp[5], fhp[6], fhp[7]); *inop = make_uint32(fhp[12], fhp[13], fhp[14], fhp[15]); if (osnamep) *osnamep = "IRIX5"; break; #ifdef notdef case FHT_SUNOS3: /* * XXX - none of the heuristics above return this. * Are there any SunOS 3.x systems around to care about? */ if (osnamep) *osnamep = "SUNOS3"; break; #endif case FHT_SUNOS4: fsidp->Fsid_dev.Minor = fhp[3]; fsidp->Fsid_dev.Major = fhp[2]; fsidp->fsid_code = make_uint32(fhp[4], fhp[5], fhp[6], fhp[7]); *inop = make_uint32(fhp[12], fhp[13], fhp[14], fhp[15]); if (osnamep) *osnamep = "SUNOS4"; break; case FHT_SUNOS5: temp = make_uint16(fhp[0], fhp[1]); fsidp->Fsid_dev.Major = (temp>>2) & 0x3FFF; temp = make_uint24(fhp[1], fhp[2], fhp[3]); fsidp->Fsid_dev.Minor = temp & 0x3FFFF; fsidp->fsid_code = make_uint32(fhp[4], fhp[5], fhp[6], fhp[7]); *inop = make_uint32(fhp[12], fhp[13], fhp[14], fhp[15]); if (osnamep) *osnamep = "SUNOS5"; break; case FHT_ULTRIX: fsidp->fsid_code = 0; fsidp->Fsid_dev.Minor = fhp[0]; fsidp->Fsid_dev.Major = fhp[1]; temp = make_uint32(fhp[7], fhp[6], fhp[5], fhp[4]); *inop = temp; if (osnamep) *osnamep = "Ultrix"; break; case FHT_VMSUCX: /* No numeric file system ID, so hash on the device-name */ if (sizeof(*fsidp) >= 14) { if (sizeof(*fsidp) > 14) memset((char *)fsidp, 0, sizeof(*fsidp)); /* just use the whole thing */ memcpy((char *)fsidp, (const char *)fh, 14); } else { uint32_t tempa[4]; /* at least 16 bytes, maybe more */ memset((char *)tempa, 0, sizeof(tempa)); memcpy((char *)tempa, (const char *)fh, 14); /* ensure alignment */ fsidp->Fsid_dev.Minor = tempa[0] + (tempa[1]<<1); fsidp->Fsid_dev.Major = tempa[2] + (tempa[3]<<1); fsidp->fsid_code = 0; } /* VMS file ID is: (RVN, FidHi, FidLo) */ *inop = make_uint32(fhp[26], fhp[27], fhp[23], fhp[22]); /* Caller must save (and null-terminate?) this value */ if (fsnamep) *fsnamep = (const char *)&(fhp[1]); if (osnamep) *osnamep = "VMS"; break; case FHT_AIX32: fsidp->Fsid_dev.Minor = make_uint16(fhp[2], fhp[3]); fsidp->Fsid_dev.Major = make_uint16(fhp[0], fhp[1]); fsidp->fsid_code = make_uint32(fhp[4], fhp[5], fhp[6], fhp[7]); *inop = make_uint32(fhp[12], fhp[13], fhp[14], fhp[15]); if (osnamep) *osnamep = "AIX32"; break; case FHT_HPUX9: fsidp->Fsid_dev.Major = fhp[0]; temp = make_uint24(fhp[1], fhp[2], fhp[3]); fsidp->Fsid_dev.Minor = temp; fsidp->fsid_code = make_uint32(fhp[4], fhp[5], fhp[6], fhp[7]); *inop = make_uint32(fhp[12], fhp[13], fhp[14], fhp[15]); if (osnamep) *osnamep = "HPUX9"; break; case FHT_UNKNOWN: #ifdef DEBUG /* XXX debugging */ for (i = 0; i < len*4; i++) (void)fprintf(stderr, "%x.", fhp[i]); (void)fprintf(stderr, "\n"); #endif /* Save the actual handle, so it can be display with -u */ for (i = 0; i < len*4 && i*2 < sizeof(fsidp->Opaque_Handle) - 1; i++) (void)snprintf(&(fsidp->Opaque_Handle[i*2]), 3, "%.2X", fhp[i]); fsidp->Opaque_Handle[i*2] = '\0'; /* XXX for now, give "bogus" values to aid debugging */ fsidp->fsid_code = 0; fsidp->Fsid_dev.Minor = 257; fsidp->Fsid_dev.Major = 257; *inop = 1; /* display will show this string instead of (257,257) */ if (fsnamep) *fsnamep = "Unknown"; if (osnamep) *osnamep = "Unknown"; break; } } /* * Is this a VMS UCX file handle? * Check for: * (1) leading code byte [XXX not yet] * (2) followed by string of printing chars & spaces * (3) followed by string of nulls */ static int is_UCX(const unsigned char *fhp, u_int len) { register u_int i; int seen_null = 0; /* * Require at least 28 bytes of file handle; it's variable-length * in NFSv3. "len" is in units of 32-bit words, not bytes. */ if (len < 28/4) return(0); for (i = 1; i < 14; i++) { if (ND_ISPRINT(fhp[i])) { if (seen_null) return(0); else continue; } else if (fhp[i] == 0) { seen_null = 1; continue; } else return(0); } return(1); } tcpdump-4.9.3/print-domain.c0000644000026300017510000004470313544412561014110 0ustar mcrmcr/* * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of * the University nor the names of its contributors may be used to endorse * or promote products derived from this software without specific prior * written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* \summary: Domain Name System (DNS) printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "nameser.h" #include #include "netdissect.h" #include "addrtoname.h" #include "addrtostr.h" #include "extract.h" static const char *ns_ops[] = { "", " inv_q", " stat", " op3", " notify", " update", " op6", " op7", " op8", " updateA", " updateD", " updateDA", " updateM", " updateMA", " zoneInit", " zoneRef", }; static const char *ns_resp[] = { "", " FormErr", " ServFail", " NXDomain", " NotImp", " Refused", " YXDomain", " YXRRSet", " NXRRSet", " NotAuth", " NotZone", " Resp11", " Resp12", " Resp13", " Resp14", " NoChange", }; /* skip over a domain name */ static const u_char * ns_nskip(netdissect_options *ndo, register const u_char *cp) { register u_char i; if (!ND_TTEST2(*cp, 1)) return (NULL); i = *cp++; while (i) { if ((i & INDIR_MASK) == INDIR_MASK) return (cp + 1); if ((i & INDIR_MASK) == EDNS0_MASK) { int bitlen, bytelen; if ((i & ~INDIR_MASK) != EDNS0_ELT_BITLABEL) return(NULL); /* unknown ELT */ if (!ND_TTEST2(*cp, 1)) return (NULL); if ((bitlen = *cp++) == 0) bitlen = 256; bytelen = (bitlen + 7) / 8; cp += bytelen; } else cp += i; if (!ND_TTEST2(*cp, 1)) return (NULL); i = *cp++; } return (cp); } /* print a */ static const u_char * blabel_print(netdissect_options *ndo, const u_char *cp) { int bitlen, slen, b; const u_char *bitp, *lim; char tc; if (!ND_TTEST2(*cp, 1)) return(NULL); if ((bitlen = *cp) == 0) bitlen = 256; slen = (bitlen + 3) / 4; lim = cp + 1 + slen; /* print the bit string as a hex string */ ND_PRINT((ndo, "\\[x")); for (bitp = cp + 1, b = bitlen; bitp < lim && b > 7; b -= 8, bitp++) { ND_TCHECK(*bitp); ND_PRINT((ndo, "%02x", *bitp)); } if (b > 4) { ND_TCHECK(*bitp); tc = *bitp++; ND_PRINT((ndo, "%02x", tc & (0xff << (8 - b)))); } else if (b > 0) { ND_TCHECK(*bitp); tc = *bitp++; ND_PRINT((ndo, "%1x", ((tc >> 4) & 0x0f) & (0x0f << (4 - b)))); } ND_PRINT((ndo, "/%d]", bitlen)); return lim; trunc: ND_PRINT((ndo, ".../%d]", bitlen)); return NULL; } static int labellen(netdissect_options *ndo, const u_char *cp) { register u_int i; if (!ND_TTEST2(*cp, 1)) return(-1); i = *cp; if ((i & INDIR_MASK) == EDNS0_MASK) { int bitlen, elt; if ((elt = (i & ~INDIR_MASK)) != EDNS0_ELT_BITLABEL) { ND_PRINT((ndo, "", elt)); return(-1); } if (!ND_TTEST2(*(cp + 1), 1)) return(-1); if ((bitlen = *(cp + 1)) == 0) bitlen = 256; return(((bitlen + 7) / 8) + 1); } else return(i); } const u_char * ns_nprint(netdissect_options *ndo, register const u_char *cp, register const u_char *bp) { register u_int i, l; register const u_char *rp = NULL; register int compress = 0; int elt; u_int offset, max_offset; if ((l = labellen(ndo, cp)) == (u_int)-1) return(NULL); if (!ND_TTEST2(*cp, 1)) return(NULL); max_offset = (u_int)(cp - bp); if (((i = *cp++) & INDIR_MASK) != INDIR_MASK) { compress = 0; rp = cp + l; } if (i != 0) while (i && cp < ndo->ndo_snapend) { if ((i & INDIR_MASK) == INDIR_MASK) { if (!compress) { rp = cp + 1; compress = 1; } if (!ND_TTEST2(*cp, 1)) return(NULL); offset = (((i << 8) | *cp) & 0x3fff); /* * This must move backwards in the packet. * No RFC explicitly says that, but BIND's * name decompression code requires it, * as a way of preventing infinite loops * and other bad behavior, and it's probably * what was intended (compress by pointing * to domain name suffixes already seen in * the packet). */ if (offset >= max_offset) { ND_PRINT((ndo, "")); return(NULL); } max_offset = offset; cp = bp + offset; if ((l = labellen(ndo, cp)) == (u_int)-1) return(NULL); if (!ND_TTEST2(*cp, 1)) return(NULL); i = *cp++; continue; } if ((i & INDIR_MASK) == EDNS0_MASK) { elt = (i & ~INDIR_MASK); switch(elt) { case EDNS0_ELT_BITLABEL: if (blabel_print(ndo, cp) == NULL) return (NULL); break; default: /* unknown ELT */ ND_PRINT((ndo, "", elt)); return(NULL); } } else { if (fn_printn(ndo, cp, l, ndo->ndo_snapend)) return(NULL); } cp += l; ND_PRINT((ndo, ".")); if ((l = labellen(ndo, cp)) == (u_int)-1) return(NULL); if (!ND_TTEST2(*cp, 1)) return(NULL); i = *cp++; if (!compress) rp += l + 1; } else ND_PRINT((ndo, ".")); return (rp); } /* print a */ static const u_char * ns_cprint(netdissect_options *ndo, register const u_char *cp) { register u_int i; if (!ND_TTEST2(*cp, 1)) return (NULL); i = *cp++; if (fn_printn(ndo, cp, i, ndo->ndo_snapend)) return (NULL); return (cp + i); } /* http://www.iana.org/assignments/dns-parameters */ const struct tok ns_type2str[] = { { T_A, "A" }, /* RFC 1035 */ { T_NS, "NS" }, /* RFC 1035 */ { T_MD, "MD" }, /* RFC 1035 */ { T_MF, "MF" }, /* RFC 1035 */ { T_CNAME, "CNAME" }, /* RFC 1035 */ { T_SOA, "SOA" }, /* RFC 1035 */ { T_MB, "MB" }, /* RFC 1035 */ { T_MG, "MG" }, /* RFC 1035 */ { T_MR, "MR" }, /* RFC 1035 */ { T_NULL, "NULL" }, /* RFC 1035 */ { T_WKS, "WKS" }, /* RFC 1035 */ { T_PTR, "PTR" }, /* RFC 1035 */ { T_HINFO, "HINFO" }, /* RFC 1035 */ { T_MINFO, "MINFO" }, /* RFC 1035 */ { T_MX, "MX" }, /* RFC 1035 */ { T_TXT, "TXT" }, /* RFC 1035 */ { T_RP, "RP" }, /* RFC 1183 */ { T_AFSDB, "AFSDB" }, /* RFC 1183 */ { T_X25, "X25" }, /* RFC 1183 */ { T_ISDN, "ISDN" }, /* RFC 1183 */ { T_RT, "RT" }, /* RFC 1183 */ { T_NSAP, "NSAP" }, /* RFC 1706 */ { T_NSAP_PTR, "NSAP_PTR" }, { T_SIG, "SIG" }, /* RFC 2535 */ { T_KEY, "KEY" }, /* RFC 2535 */ { T_PX, "PX" }, /* RFC 2163 */ { T_GPOS, "GPOS" }, /* RFC 1712 */ { T_AAAA, "AAAA" }, /* RFC 1886 */ { T_LOC, "LOC" }, /* RFC 1876 */ { T_NXT, "NXT" }, /* RFC 2535 */ { T_EID, "EID" }, /* Nimrod */ { T_NIMLOC, "NIMLOC" }, /* Nimrod */ { T_SRV, "SRV" }, /* RFC 2782 */ { T_ATMA, "ATMA" }, /* ATM Forum */ { T_NAPTR, "NAPTR" }, /* RFC 2168, RFC 2915 */ { T_KX, "KX" }, /* RFC 2230 */ { T_CERT, "CERT" }, /* RFC 2538 */ { T_A6, "A6" }, /* RFC 2874 */ { T_DNAME, "DNAME" }, /* RFC 2672 */ { T_SINK, "SINK" }, { T_OPT, "OPT" }, /* RFC 2671 */ { T_APL, "APL" }, /* RFC 3123 */ { T_DS, "DS" }, /* RFC 4034 */ { T_SSHFP, "SSHFP" }, /* RFC 4255 */ { T_IPSECKEY, "IPSECKEY" }, /* RFC 4025 */ { T_RRSIG, "RRSIG" }, /* RFC 4034 */ { T_NSEC, "NSEC" }, /* RFC 4034 */ { T_DNSKEY, "DNSKEY" }, /* RFC 4034 */ { T_SPF, "SPF" }, /* RFC-schlitt-spf-classic-02.txt */ { T_UINFO, "UINFO" }, { T_UID, "UID" }, { T_GID, "GID" }, { T_UNSPEC, "UNSPEC" }, { T_UNSPECA, "UNSPECA" }, { T_TKEY, "TKEY" }, /* RFC 2930 */ { T_TSIG, "TSIG" }, /* RFC 2845 */ { T_IXFR, "IXFR" }, /* RFC 1995 */ { T_AXFR, "AXFR" }, /* RFC 1035 */ { T_MAILB, "MAILB" }, /* RFC 1035 */ { T_MAILA, "MAILA" }, /* RFC 1035 */ { T_ANY, "ANY" }, { 0, NULL } }; const struct tok ns_class2str[] = { { C_IN, "IN" }, /* Not used */ { C_CHAOS, "CHAOS" }, { C_HS, "HS" }, { C_ANY, "ANY" }, { 0, NULL } }; /* print a query */ static const u_char * ns_qprint(netdissect_options *ndo, register const u_char *cp, register const u_char *bp, int is_mdns) { register const u_char *np = cp; register u_int i, class; cp = ns_nskip(ndo, cp); if (cp == NULL || !ND_TTEST2(*cp, 4)) return(NULL); /* print the qtype */ i = EXTRACT_16BITS(cp); cp += 2; ND_PRINT((ndo, " %s", tok2str(ns_type2str, "Type%d", i))); /* print the qclass (if it's not IN) */ i = EXTRACT_16BITS(cp); cp += 2; if (is_mdns) class = (i & ~C_QU); else class = i; if (class != C_IN) ND_PRINT((ndo, " %s", tok2str(ns_class2str, "(Class %d)", class))); if (is_mdns) { ND_PRINT((ndo, i & C_QU ? " (QU)" : " (QM)")); } ND_PRINT((ndo, "? ")); cp = ns_nprint(ndo, np, bp); return(cp ? cp + 4 : NULL); } /* print a reply */ static const u_char * ns_rprint(netdissect_options *ndo, register const u_char *cp, register const u_char *bp, int is_mdns) { register u_int i, class, opt_flags = 0; register u_short typ, len; register const u_char *rp; if (ndo->ndo_vflag) { ND_PRINT((ndo, " ")); if ((cp = ns_nprint(ndo, cp, bp)) == NULL) return NULL; } else cp = ns_nskip(ndo, cp); if (cp == NULL || !ND_TTEST2(*cp, 10)) return (ndo->ndo_snapend); /* print the type/qtype */ typ = EXTRACT_16BITS(cp); cp += 2; /* print the class (if it's not IN and the type isn't OPT) */ i = EXTRACT_16BITS(cp); cp += 2; if (is_mdns) class = (i & ~C_CACHE_FLUSH); else class = i; if (class != C_IN && typ != T_OPT) ND_PRINT((ndo, " %s", tok2str(ns_class2str, "(Class %d)", class))); if (is_mdns) { if (i & C_CACHE_FLUSH) ND_PRINT((ndo, " (Cache flush)")); } if (typ == T_OPT) { /* get opt flags */ cp += 2; opt_flags = EXTRACT_16BITS(cp); /* ignore rest of ttl field */ cp += 2; } else if (ndo->ndo_vflag > 2) { /* print ttl */ ND_PRINT((ndo, " [")); unsigned_relts_print(ndo, EXTRACT_32BITS(cp)); ND_PRINT((ndo, "]")); cp += 4; } else { /* ignore ttl */ cp += 4; } len = EXTRACT_16BITS(cp); cp += 2; rp = cp + len; ND_PRINT((ndo, " %s", tok2str(ns_type2str, "Type%d", typ))); if (rp > ndo->ndo_snapend) return(NULL); switch (typ) { case T_A: if (!ND_TTEST2(*cp, sizeof(struct in_addr))) return(NULL); ND_PRINT((ndo, " %s", intoa(htonl(EXTRACT_32BITS(cp))))); break; case T_NS: case T_CNAME: case T_PTR: #ifdef T_DNAME case T_DNAME: #endif ND_PRINT((ndo, " ")); if (ns_nprint(ndo, cp, bp) == NULL) return(NULL); break; case T_SOA: if (!ndo->ndo_vflag) break; ND_PRINT((ndo, " ")); if ((cp = ns_nprint(ndo, cp, bp)) == NULL) return(NULL); ND_PRINT((ndo, " ")); if ((cp = ns_nprint(ndo, cp, bp)) == NULL) return(NULL); if (!ND_TTEST2(*cp, 5 * 4)) return(NULL); ND_PRINT((ndo, " %u", EXTRACT_32BITS(cp))); cp += 4; ND_PRINT((ndo, " %u", EXTRACT_32BITS(cp))); cp += 4; ND_PRINT((ndo, " %u", EXTRACT_32BITS(cp))); cp += 4; ND_PRINT((ndo, " %u", EXTRACT_32BITS(cp))); cp += 4; ND_PRINT((ndo, " %u", EXTRACT_32BITS(cp))); cp += 4; break; case T_MX: ND_PRINT((ndo, " ")); if (!ND_TTEST2(*cp, 2)) return(NULL); if (ns_nprint(ndo, cp + 2, bp) == NULL) return(NULL); ND_PRINT((ndo, " %d", EXTRACT_16BITS(cp))); break; case T_TXT: while (cp < rp) { ND_PRINT((ndo, " \"")); cp = ns_cprint(ndo, cp); if (cp == NULL) return(NULL); ND_PRINT((ndo, "\"")); } break; case T_SRV: ND_PRINT((ndo, " ")); if (!ND_TTEST2(*cp, 6)) return(NULL); if (ns_nprint(ndo, cp + 6, bp) == NULL) return(NULL); ND_PRINT((ndo, ":%d %d %d", EXTRACT_16BITS(cp + 4), EXTRACT_16BITS(cp), EXTRACT_16BITS(cp + 2))); break; case T_AAAA: { char ntop_buf[INET6_ADDRSTRLEN]; if (!ND_TTEST2(*cp, sizeof(struct in6_addr))) return(NULL); ND_PRINT((ndo, " %s", addrtostr6(cp, ntop_buf, sizeof(ntop_buf)))); break; } case T_A6: { struct in6_addr a; int pbit, pbyte; char ntop_buf[INET6_ADDRSTRLEN]; if (!ND_TTEST2(*cp, 1)) return(NULL); pbit = *cp; pbyte = (pbit & ~7) / 8; if (pbit > 128) { ND_PRINT((ndo, " %u(bad plen)", pbit)); break; } else if (pbit < 128) { if (!ND_TTEST2(*(cp + 1), sizeof(a) - pbyte)) return(NULL); memset(&a, 0, sizeof(a)); memcpy(&a.s6_addr[pbyte], cp + 1, sizeof(a) - pbyte); ND_PRINT((ndo, " %u %s", pbit, addrtostr6(&a, ntop_buf, sizeof(ntop_buf)))); } if (pbit > 0) { ND_PRINT((ndo, " ")); if (ns_nprint(ndo, cp + 1 + sizeof(a) - pbyte, bp) == NULL) return(NULL); } break; } case T_OPT: ND_PRINT((ndo, " UDPsize=%u", class)); if (opt_flags & 0x8000) ND_PRINT((ndo, " DO")); break; case T_UNSPECA: /* One long string */ if (!ND_TTEST2(*cp, len)) return(NULL); if (fn_printn(ndo, cp, len, ndo->ndo_snapend)) return(NULL); break; case T_TSIG: { if (cp + len > ndo->ndo_snapend) return(NULL); if (!ndo->ndo_vflag) break; ND_PRINT((ndo, " ")); if ((cp = ns_nprint(ndo, cp, bp)) == NULL) return(NULL); cp += 6; if (!ND_TTEST2(*cp, 2)) return(NULL); ND_PRINT((ndo, " fudge=%u", EXTRACT_16BITS(cp))); cp += 2; if (!ND_TTEST2(*cp, 2)) return(NULL); ND_PRINT((ndo, " maclen=%u", EXTRACT_16BITS(cp))); cp += 2 + EXTRACT_16BITS(cp); if (!ND_TTEST2(*cp, 2)) return(NULL); ND_PRINT((ndo, " origid=%u", EXTRACT_16BITS(cp))); cp += 2; if (!ND_TTEST2(*cp, 2)) return(NULL); ND_PRINT((ndo, " error=%u", EXTRACT_16BITS(cp))); cp += 2; if (!ND_TTEST2(*cp, 2)) return(NULL); ND_PRINT((ndo, " otherlen=%u", EXTRACT_16BITS(cp))); cp += 2; } } return (rp); /* XXX This isn't always right */ } void ns_print(netdissect_options *ndo, register const u_char *bp, u_int length, int is_mdns) { register const HEADER *np; register int qdcount, ancount, nscount, arcount; register const u_char *cp; uint16_t b2; if(length < sizeof(*np)) { ND_PRINT((ndo, "domain")); ND_PRINT((ndo, " [length %u < %zu]", length, sizeof(*np))); ND_PRINT((ndo, " (invalid)")); return; } np = (const HEADER *)bp; ND_TCHECK(*np); /* get the byte-order right */ qdcount = EXTRACT_16BITS(&np->qdcount); ancount = EXTRACT_16BITS(&np->ancount); nscount = EXTRACT_16BITS(&np->nscount); arcount = EXTRACT_16BITS(&np->arcount); if (DNS_QR(np)) { /* this is a response */ ND_PRINT((ndo, "%d%s%s%s%s%s%s", EXTRACT_16BITS(&np->id), ns_ops[DNS_OPCODE(np)], ns_resp[DNS_RCODE(np)], DNS_AA(np)? "*" : "", DNS_RA(np)? "" : "-", DNS_TC(np)? "|" : "", DNS_AD(np)? "$" : "")); if (qdcount != 1) ND_PRINT((ndo, " [%dq]", qdcount)); /* Print QUESTION section on -vv */ cp = (const u_char *)(np + 1); while (qdcount--) { if (qdcount < EXTRACT_16BITS(&np->qdcount) - 1) ND_PRINT((ndo, ",")); if (ndo->ndo_vflag > 1) { ND_PRINT((ndo, " q:")); if ((cp = ns_qprint(ndo, cp, bp, is_mdns)) == NULL) goto trunc; } else { if ((cp = ns_nskip(ndo, cp)) == NULL) goto trunc; cp += 4; /* skip QTYPE and QCLASS */ } } ND_PRINT((ndo, " %d/%d/%d", ancount, nscount, arcount)); if (ancount--) { if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) goto trunc; while (cp < ndo->ndo_snapend && ancount--) { ND_PRINT((ndo, ",")); if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) goto trunc; } } if (ancount > 0) goto trunc; /* Print NS and AR sections on -vv */ if (ndo->ndo_vflag > 1) { if (cp < ndo->ndo_snapend && nscount--) { ND_PRINT((ndo, " ns:")); if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) goto trunc; while (cp < ndo->ndo_snapend && nscount--) { ND_PRINT((ndo, ",")); if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) goto trunc; } } if (nscount > 0) goto trunc; if (cp < ndo->ndo_snapend && arcount--) { ND_PRINT((ndo, " ar:")); if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) goto trunc; while (cp < ndo->ndo_snapend && arcount--) { ND_PRINT((ndo, ",")); if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) goto trunc; } } if (arcount > 0) goto trunc; } } else { /* this is a request */ ND_PRINT((ndo, "%d%s%s%s", EXTRACT_16BITS(&np->id), ns_ops[DNS_OPCODE(np)], DNS_RD(np) ? "+" : "", DNS_CD(np) ? "%" : "")); /* any weirdness? */ b2 = EXTRACT_16BITS(((const u_short *)np)+1); if (b2 & 0x6cf) ND_PRINT((ndo, " [b2&3=0x%x]", b2)); if (DNS_OPCODE(np) == IQUERY) { if (qdcount) ND_PRINT((ndo, " [%dq]", qdcount)); if (ancount != 1) ND_PRINT((ndo, " [%da]", ancount)); } else { if (ancount) ND_PRINT((ndo, " [%da]", ancount)); if (qdcount != 1) ND_PRINT((ndo, " [%dq]", qdcount)); } if (nscount) ND_PRINT((ndo, " [%dn]", nscount)); if (arcount) ND_PRINT((ndo, " [%dau]", arcount)); cp = (const u_char *)(np + 1); if (qdcount--) { cp = ns_qprint(ndo, cp, (const u_char *)np, is_mdns); if (!cp) goto trunc; while (cp < ndo->ndo_snapend && qdcount--) { cp = ns_qprint(ndo, (const u_char *)cp, (const u_char *)np, is_mdns); if (!cp) goto trunc; } } if (qdcount > 0) goto trunc; /* Print remaining sections on -vv */ if (ndo->ndo_vflag > 1) { if (ancount--) { if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) goto trunc; while (cp < ndo->ndo_snapend && ancount--) { ND_PRINT((ndo, ",")); if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) goto trunc; } } if (ancount > 0) goto trunc; if (cp < ndo->ndo_snapend && nscount--) { ND_PRINT((ndo, " ns:")); if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) goto trunc; while (nscount-- && cp < ndo->ndo_snapend) { ND_PRINT((ndo, ",")); if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) goto trunc; } } if (nscount > 0) goto trunc; if (cp < ndo->ndo_snapend && arcount--) { ND_PRINT((ndo, " ar:")); if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) goto trunc; while (cp < ndo->ndo_snapend && arcount--) { ND_PRINT((ndo, ",")); if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) goto trunc; } } if (arcount > 0) goto trunc; } } ND_PRINT((ndo, " (%d)", length)); return; trunc: ND_PRINT((ndo, "[|domain]")); } tcpdump-4.9.3/l2vpn.h0000644000026300017510000000141513544412561012546 0ustar mcrmcr/* * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code * distributions retain the above copyright notice and this paragraph * in its entirety, and (2) distributions including binary code include * the above copyright notice and this paragraph in its entirety in * the documentation or other materials provided with the distribution. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. * * Original code by Hannes Gredler (hannes@gredler.at) */ extern const struct tok l2vpn_encaps_values[]; extern const struct tok mpls_pw_types_values[]; tcpdump-4.9.3/print-vxlan.c0000644000026300017510000000432513544412561013765 0ustar mcrmcr/* * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code * distributions retain the above copyright notice and this paragraph * in its entirety, and (2) distributions including binary code include * the above copyright notice and this paragraph in its entirety in * the documentation or other materials provided with the distribution. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. * * Original code by Francesco Fondelli (francesco dot fondelli, gmail dot com) */ /* \summary: Virtual eXtensible Local Area Network (VXLAN) printer */ /* specification: RFC 7348 */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #include "extract.h" static const char tstr[] = " [|VXLAN]"; #define VXLAN_HDR_LEN 8 /* * VXLAN header, RFC7348 * Virtual eXtensible Local Area Network (VXLAN): A Framework * for Overlaying Virtualized Layer 2 Networks over Layer 3 Networks * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * |R|R|R|R|I|R|R|R| Reserved | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | VXLAN Network Identifier (VNI) | Reserved | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ void vxlan_print(netdissect_options *ndo, const u_char *bp, u_int len) { uint8_t flags; uint32_t vni; if (len < VXLAN_HDR_LEN) goto trunc; ND_TCHECK2(*bp, VXLAN_HDR_LEN); flags = *bp; bp += 4; vni = EXTRACT_24BITS(bp); bp += 4; ND_PRINT((ndo, "VXLAN, ")); ND_PRINT((ndo, "flags [%s] (0x%02x), ", flags & 0x08 ? "I" : ".", flags)); ND_PRINT((ndo, "vni %u\n", vni)); ether_print(ndo, bp, len - VXLAN_HDR_LEN, ndo->ndo_snapend - bp, NULL, NULL); return; trunc: ND_PRINT((ndo, "%s", tstr)); } tcpdump-4.9.3/machdep.h0000644000026300017510000000236613544412561013114 0ustar mcrmcr/* * Copyright (c) 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of * the University nor the names of its contributors may be used to endorse * or promote products derived from this software without specific prior * written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef netdissect_machdep_h #define netdissect_machdep_h int abort_on_misalignment(char *, size_t); #endif tcpdump-4.9.3/rpc_msg.h0000644000026300017510000000625713544412561013150 0ustar mcrmcr/* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for * unrestricted use provided that this legend is included on all tape * media and as a part of the software program in whole or part. Users * may copy or modify Sun RPC without charge, but are not authorized * to license or distribute it to anyone else except as part of a product or * program developed by the user. * * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. * * Sun RPC is provided with no support and without any obligation on the * part of Sun Microsystems, Inc. to assist in its use, correction, * modification or enhancement. * * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC * OR ANY PART THEREOF. * * In no event will Sun Microsystems, Inc. be liable for any lost revenue * or profits or other special, indirect and consequential damages, even if * Sun has been advised of the possibility of such damages. * * Sun Microsystems, Inc. * 2550 Garcia Avenue * Mountain View, California 94043 * * from: @(#)rpc_msg.h 1.7 86/07/16 SMI * from: @(#)rpc_msg.h 2.1 88/07/29 4.0 RPCSRC * $FreeBSD: src/include/rpc/rpc_msg.h,v 1.11.2.1 1999/08/29 14:39:07 peter Exp $ */ /* * rpc_msg.h * rpc message definition * * Copyright (C) 1984, Sun Microsystems, Inc. */ #define SUNRPC_MSG_VERSION ((uint32_t) 2) /* * Bottom up definition of an rpc message. * NOTE: call and reply use the same overall stuct but * different parts of unions within it. */ enum sunrpc_msg_type { SUNRPC_CALL=0, SUNRPC_REPLY=1 }; enum sunrpc_reply_stat { SUNRPC_MSG_ACCEPTED=0, SUNRPC_MSG_DENIED=1 }; enum sunrpc_accept_stat { SUNRPC_SUCCESS=0, SUNRPC_PROG_UNAVAIL=1, SUNRPC_PROG_MISMATCH=2, SUNRPC_PROC_UNAVAIL=3, SUNRPC_GARBAGE_ARGS=4, SUNRPC_SYSTEM_ERR=5 }; enum sunrpc_reject_stat { SUNRPC_RPC_MISMATCH=0, SUNRPC_AUTH_ERROR=1 }; /* * Reply part of an rpc exchange */ /* * Reply to an rpc request that was rejected by the server. */ struct sunrpc_rejected_reply { uint32_t rj_stat; /* enum reject_stat */ union { struct { uint32_t low; uint32_t high; } RJ_versions; uint32_t RJ_why; /* enum auth_stat - why authentication did not work */ } ru; #define rj_vers ru.RJ_versions #define rj_why ru.RJ_why }; /* * Body of a reply to an rpc request. */ struct sunrpc_reply_body { uint32_t rp_stat; /* enum reply_stat */ struct sunrpc_rejected_reply rp_reject; /* if rejected */ }; /* * Body of an rpc request call. */ struct sunrpc_call_body { uint32_t cb_rpcvers; /* must be equal to two */ uint32_t cb_prog; uint32_t cb_vers; uint32_t cb_proc; struct sunrpc_opaque_auth cb_cred; /* followed by opaque verifier */ }; /* * The rpc message */ struct sunrpc_msg { uint32_t rm_xid; uint32_t rm_direction; /* enum msg_type */ union { struct sunrpc_call_body RM_cmb; struct sunrpc_reply_body RM_rmb; } ru; #define rm_call ru.RM_cmb #define rm_reply ru.RM_rmb }; #define acpted_rply ru.RM_rmb.ru.RP_ar #define rjcted_rply ru.RM_rmb.ru.RP_dr tcpdump-4.9.3/nlpid.h0000644000026300017510000000246613544412561012622 0ustar mcrmcr/* * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code * distributions retain the above copyright notice and this paragraph * in its entirety, and (2) distributions including binary code include * the above copyright notice and this paragraph in its entirety in * the documentation or other materials provided with the distribution. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. * * Original code by Hannes Gredler (hannes@gredler.at) */ extern const struct tok nlpid_values[]; #define NLPID_NULLNS 0x00 #define NLPID_Q933 0x08 /* ANSI T1.617 Annex D or ITU-T Q.933 Annex A */ #define NLPID_LMI 0x09 /* The original, aka Cisco, aka Gang of Four */ #define NLPID_SNAP 0x80 #define NLPID_CLNP 0x81 /* iso9577 */ #define NLPID_ESIS 0x82 /* iso9577 */ #define NLPID_ISIS 0x83 /* iso9577 */ #define NLPID_CONS 0x84 #define NLPID_IDRP 0x85 #define NLPID_MFR 0xb1 /* FRF.15 */ #define NLPID_SPB 0xc1 /* IEEE 802.1aq/D4.5 */ #define NLPID_IP 0xcc #define NLPID_PPP 0xcf #define NLPID_X25_ESIS 0x8a #define NLPID_IP6 0x8e tcpdump-4.9.3/print-ldp.c0000644000026300017510000006054613544412724013424 0ustar mcrmcr/* * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code * distributions retain the above copyright notice and this paragraph * in its entirety, and (2) distributions including binary code include * the above copyright notice and this paragraph in its entirety in * the documentation or other materials provided with the distribution. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. * * Original code by Hannes Gredler (hannes@gredler.at) * and Steinar Haug (sthaug@nethelp.no) */ /* \summary: Label Distribution Protocol (LDP) printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #include "extract.h" #include "addrtoname.h" #include "l2vpn.h" #include "af.h" static const char tstr[] = " [|LDP]"; /* * ldp common header * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Version | PDU Length | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | LDP Identifier | * + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * */ struct ldp_common_header { uint8_t version[2]; uint8_t pdu_length[2]; uint8_t lsr_id[4]; uint8_t label_space[2]; }; #define LDP_VERSION 1 /* * ldp message header * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * |U| Message Type | Message Length | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Message ID | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | * + + * | Mandatory Parameters | * + + * | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | * + + * | Optional Parameters | * + + * | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ struct ldp_msg_header { uint8_t type[2]; uint8_t length[2]; uint8_t id[4]; }; #define LDP_MASK_MSG_TYPE(x) ((x)&0x7fff) #define LDP_MASK_U_BIT(x) ((x)&0x8000) #define LDP_MSG_NOTIF 0x0001 #define LDP_MSG_HELLO 0x0100 #define LDP_MSG_INIT 0x0200 #define LDP_MSG_KEEPALIVE 0x0201 #define LDP_MSG_ADDRESS 0x0300 #define LDP_MSG_ADDRESS_WITHDRAW 0x0301 #define LDP_MSG_LABEL_MAPPING 0x0400 #define LDP_MSG_LABEL_REQUEST 0x0401 #define LDP_MSG_LABEL_WITHDRAW 0x0402 #define LDP_MSG_LABEL_RELEASE 0x0403 #define LDP_MSG_LABEL_ABORT_REQUEST 0x0404 #define LDP_VENDOR_PRIVATE_MIN 0x3e00 #define LDP_VENDOR_PRIVATE_MAX 0x3eff #define LDP_EXPERIMENTAL_MIN 0x3f00 #define LDP_EXPERIMENTAL_MAX 0x3fff static const struct tok ldp_msg_values[] = { { LDP_MSG_NOTIF, "Notification" }, { LDP_MSG_HELLO, "Hello" }, { LDP_MSG_INIT, "Initialization" }, { LDP_MSG_KEEPALIVE, "Keepalive" }, { LDP_MSG_ADDRESS, "Address" }, { LDP_MSG_ADDRESS_WITHDRAW, "Address Withdraw" }, { LDP_MSG_LABEL_MAPPING, "Label Mapping" }, { LDP_MSG_LABEL_REQUEST, "Label Request" }, { LDP_MSG_LABEL_WITHDRAW, "Label Withdraw" }, { LDP_MSG_LABEL_RELEASE, "Label Release" }, { LDP_MSG_LABEL_ABORT_REQUEST, "Label Abort Request" }, { 0, NULL} }; #define LDP_MASK_TLV_TYPE(x) ((x)&0x3fff) #define LDP_MASK_F_BIT(x) ((x)&0x4000) #define LDP_TLV_FEC 0x0100 #define LDP_TLV_ADDRESS_LIST 0x0101 #define LDP_TLV_ADDRESS_LIST_AFNUM_LEN 2 #define LDP_TLV_HOP_COUNT 0x0103 #define LDP_TLV_PATH_VECTOR 0x0104 #define LDP_TLV_GENERIC_LABEL 0x0200 #define LDP_TLV_ATM_LABEL 0x0201 #define LDP_TLV_FR_LABEL 0x0202 #define LDP_TLV_STATUS 0x0300 #define LDP_TLV_EXTD_STATUS 0x0301 #define LDP_TLV_RETURNED_PDU 0x0302 #define LDP_TLV_RETURNED_MSG 0x0303 #define LDP_TLV_COMMON_HELLO 0x0400 #define LDP_TLV_IPV4_TRANSPORT_ADDR 0x0401 #define LDP_TLV_CONFIG_SEQ_NUMBER 0x0402 #define LDP_TLV_IPV6_TRANSPORT_ADDR 0x0403 #define LDP_TLV_COMMON_SESSION 0x0500 #define LDP_TLV_ATM_SESSION_PARM 0x0501 #define LDP_TLV_FR_SESSION_PARM 0x0502 #define LDP_TLV_FT_SESSION 0x0503 #define LDP_TLV_LABEL_REQUEST_MSG_ID 0x0600 #define LDP_TLV_MTU 0x0601 /* rfc 3988 */ static const struct tok ldp_tlv_values[] = { { LDP_TLV_FEC, "FEC" }, { LDP_TLV_ADDRESS_LIST, "Address List" }, { LDP_TLV_HOP_COUNT, "Hop Count" }, { LDP_TLV_PATH_VECTOR, "Path Vector" }, { LDP_TLV_GENERIC_LABEL, "Generic Label" }, { LDP_TLV_ATM_LABEL, "ATM Label" }, { LDP_TLV_FR_LABEL, "Frame-Relay Label" }, { LDP_TLV_STATUS, "Status" }, { LDP_TLV_EXTD_STATUS, "Extended Status" }, { LDP_TLV_RETURNED_PDU, "Returned PDU" }, { LDP_TLV_RETURNED_MSG, "Returned Message" }, { LDP_TLV_COMMON_HELLO, "Common Hello Parameters" }, { LDP_TLV_IPV4_TRANSPORT_ADDR, "IPv4 Transport Address" }, { LDP_TLV_CONFIG_SEQ_NUMBER, "Configuration Sequence Number" }, { LDP_TLV_IPV6_TRANSPORT_ADDR, "IPv6 Transport Address" }, { LDP_TLV_COMMON_SESSION, "Common Session Parameters" }, { LDP_TLV_ATM_SESSION_PARM, "ATM Session Parameters" }, { LDP_TLV_FR_SESSION_PARM, "Frame-Relay Session Parameters" }, { LDP_TLV_FT_SESSION, "Fault-Tolerant Session Parameters" }, { LDP_TLV_LABEL_REQUEST_MSG_ID, "Label Request Message ID" }, { LDP_TLV_MTU, "MTU" }, { 0, NULL} }; #define LDP_FEC_WILDCARD 0x01 #define LDP_FEC_PREFIX 0x02 #define LDP_FEC_HOSTADDRESS 0x03 /* From RFC 4906; should probably be updated to RFC 4447 (e.g., VC -> PW) */ #define LDP_FEC_MARTINI_VC 0x80 static const struct tok ldp_fec_values[] = { { LDP_FEC_WILDCARD, "Wildcard" }, { LDP_FEC_PREFIX, "Prefix" }, { LDP_FEC_HOSTADDRESS, "Host address" }, { LDP_FEC_MARTINI_VC, "Martini VC" }, { 0, NULL} }; #define LDP_FEC_MARTINI_IFPARM_MTU 0x01 #define LDP_FEC_MARTINI_IFPARM_DESC 0x03 #define LDP_FEC_MARTINI_IFPARM_VCCV 0x0c static const struct tok ldp_fec_martini_ifparm_values[] = { { LDP_FEC_MARTINI_IFPARM_MTU, "MTU" }, { LDP_FEC_MARTINI_IFPARM_DESC, "Description" }, { LDP_FEC_MARTINI_IFPARM_VCCV, "VCCV" }, { 0, NULL} }; /* draft-ietf-pwe3-vccv-04.txt */ static const struct tok ldp_fec_martini_ifparm_vccv_cc_values[] = { { 0x01, "PWE3 control word" }, { 0x02, "MPLS Router Alert Label" }, { 0x04, "MPLS inner label TTL = 1" }, { 0, NULL} }; /* draft-ietf-pwe3-vccv-04.txt */ static const struct tok ldp_fec_martini_ifparm_vccv_cv_values[] = { { 0x01, "ICMP Ping" }, { 0x02, "LSP Ping" }, { 0x04, "BFD" }, { 0, NULL} }; static u_int ldp_pdu_print(netdissect_options *, register const u_char *); /* * ldp tlv header * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * |U|F| Type | Length | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | * | Value | * ~ ~ * | | * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ #define TLV_TCHECK(minlen) \ ND_TCHECK2(*tptr, minlen); if (tlv_tlen < minlen) goto badtlv; static int ldp_tlv_print(netdissect_options *ndo, register const u_char *tptr, u_short msg_tlen) { struct ldp_tlv_header { uint8_t type[2]; uint8_t length[2]; }; const struct ldp_tlv_header *ldp_tlv_header; u_short tlv_type,tlv_len,tlv_tlen,af,ft_flags; u_char fec_type; u_int ui,vc_info_len, vc_info_tlv_type, vc_info_tlv_len,idx; char buf[100]; int i; ldp_tlv_header = (const struct ldp_tlv_header *)tptr; ND_TCHECK(*ldp_tlv_header); tlv_len=EXTRACT_16BITS(ldp_tlv_header->length); if (tlv_len + 4 > msg_tlen) { ND_PRINT((ndo, "\n\t\t TLV contents go past end of message")); return 0; } tlv_tlen=tlv_len; tlv_type=LDP_MASK_TLV_TYPE(EXTRACT_16BITS(ldp_tlv_header->type)); /* FIXME vendor private / experimental check */ ND_PRINT((ndo, "\n\t %s TLV (0x%04x), length: %u, Flags: [%s and %s forward if unknown]", tok2str(ldp_tlv_values, "Unknown", tlv_type), tlv_type, tlv_len, LDP_MASK_U_BIT(EXTRACT_16BITS(&ldp_tlv_header->type)) ? "continue processing" : "ignore", LDP_MASK_F_BIT(EXTRACT_16BITS(&ldp_tlv_header->type)) ? "do" : "don't")); tptr+=sizeof(struct ldp_tlv_header); switch(tlv_type) { case LDP_TLV_COMMON_HELLO: TLV_TCHECK(4); ND_PRINT((ndo, "\n\t Hold Time: %us, Flags: [%s Hello%s]", EXTRACT_16BITS(tptr), (EXTRACT_16BITS(tptr+2)&0x8000) ? "Targeted" : "Link", (EXTRACT_16BITS(tptr+2)&0x4000) ? ", Request for targeted Hellos" : "")); break; case LDP_TLV_IPV4_TRANSPORT_ADDR: TLV_TCHECK(4); ND_PRINT((ndo, "\n\t IPv4 Transport Address: %s", ipaddr_string(ndo, tptr))); break; case LDP_TLV_IPV6_TRANSPORT_ADDR: TLV_TCHECK(16); ND_PRINT((ndo, "\n\t IPv6 Transport Address: %s", ip6addr_string(ndo, tptr))); break; case LDP_TLV_CONFIG_SEQ_NUMBER: TLV_TCHECK(4); ND_PRINT((ndo, "\n\t Sequence Number: %u", EXTRACT_32BITS(tptr))); break; case LDP_TLV_ADDRESS_LIST: TLV_TCHECK(LDP_TLV_ADDRESS_LIST_AFNUM_LEN); af = EXTRACT_16BITS(tptr); tptr+=LDP_TLV_ADDRESS_LIST_AFNUM_LEN; tlv_tlen -= LDP_TLV_ADDRESS_LIST_AFNUM_LEN; ND_PRINT((ndo, "\n\t Address Family: %s, addresses", tok2str(af_values, "Unknown (%u)", af))); switch (af) { case AFNUM_INET: while(tlv_tlen >= sizeof(struct in_addr)) { ND_TCHECK2(*tptr, sizeof(struct in_addr)); ND_PRINT((ndo, " %s", ipaddr_string(ndo, tptr))); tlv_tlen-=sizeof(struct in_addr); tptr+=sizeof(struct in_addr); } break; case AFNUM_INET6: while(tlv_tlen >= sizeof(struct in6_addr)) { ND_TCHECK2(*tptr, sizeof(struct in6_addr)); ND_PRINT((ndo, " %s", ip6addr_string(ndo, tptr))); tlv_tlen-=sizeof(struct in6_addr); tptr+=sizeof(struct in6_addr); } break; default: /* unknown AF */ break; } break; case LDP_TLV_COMMON_SESSION: TLV_TCHECK(8); ND_PRINT((ndo, "\n\t Version: %u, Keepalive: %us, Flags: [Downstream %s, Loop Detection %s]", EXTRACT_16BITS(tptr), EXTRACT_16BITS(tptr+2), (EXTRACT_16BITS(tptr+6)&0x8000) ? "On Demand" : "Unsolicited", (EXTRACT_16BITS(tptr+6)&0x4000) ? "Enabled" : "Disabled" )); break; case LDP_TLV_FEC: TLV_TCHECK(1); fec_type = *tptr; ND_PRINT((ndo, "\n\t %s FEC (0x%02x)", tok2str(ldp_fec_values, "Unknown", fec_type), fec_type)); tptr+=1; tlv_tlen-=1; switch(fec_type) { case LDP_FEC_WILDCARD: break; case LDP_FEC_PREFIX: TLV_TCHECK(2); af = EXTRACT_16BITS(tptr); tptr+=LDP_TLV_ADDRESS_LIST_AFNUM_LEN; tlv_tlen-=LDP_TLV_ADDRESS_LIST_AFNUM_LEN; if (af == AFNUM_INET) { i=decode_prefix4(ndo, tptr, tlv_tlen, buf, sizeof(buf)); if (i == -2) goto trunc; if (i == -3) ND_PRINT((ndo, ": IPv4 prefix (goes past end of TLV)")); else if (i == -1) ND_PRINT((ndo, ": IPv4 prefix (invalid length)")); else ND_PRINT((ndo, ": IPv4 prefix %s", buf)); } else if (af == AFNUM_INET6) { i=decode_prefix6(ndo, tptr, tlv_tlen, buf, sizeof(buf)); if (i == -2) goto trunc; if (i == -3) ND_PRINT((ndo, ": IPv4 prefix (goes past end of TLV)")); else if (i == -1) ND_PRINT((ndo, ": IPv6 prefix (invalid length)")); else ND_PRINT((ndo, ": IPv6 prefix %s", buf)); } else ND_PRINT((ndo, ": Address family %u prefix", af)); break; case LDP_FEC_HOSTADDRESS: break; case LDP_FEC_MARTINI_VC: /* * We assume the type was supposed to be one of the MPLS * Pseudowire Types. */ TLV_TCHECK(7); vc_info_len = *(tptr+2); /* * According to RFC 4908, the VC info Length field can be zero, * in which case not only are there no interface parameters, * there's no VC ID. */ if (vc_info_len == 0) { ND_PRINT((ndo, ": %s, %scontrol word, group-ID %u, VC-info-length: %u", tok2str(mpls_pw_types_values, "Unknown", EXTRACT_16BITS(tptr)&0x7fff), EXTRACT_16BITS(tptr)&0x8000 ? "" : "no ", EXTRACT_32BITS(tptr+3), vc_info_len)); break; } /* Make sure we have the VC ID as well */ TLV_TCHECK(11); ND_PRINT((ndo, ": %s, %scontrol word, group-ID %u, VC-ID %u, VC-info-length: %u", tok2str(mpls_pw_types_values, "Unknown", EXTRACT_16BITS(tptr)&0x7fff), EXTRACT_16BITS(tptr)&0x8000 ? "" : "no ", EXTRACT_32BITS(tptr+3), EXTRACT_32BITS(tptr+7), vc_info_len)); if (vc_info_len < 4) { /* minimum 4, for the VC ID */ ND_PRINT((ndo, " (invalid, < 4")); return(tlv_len+4); /* Type & Length fields not included */ } vc_info_len -= 4; /* subtract out the VC ID, giving the length of the interface parameters */ /* Skip past the fixed information and the VC ID */ tptr+=11; tlv_tlen-=11; TLV_TCHECK(vc_info_len); while (vc_info_len > 2) { vc_info_tlv_type = *tptr; vc_info_tlv_len = *(tptr+1); if (vc_info_tlv_len < 2) break; if (vc_info_len < vc_info_tlv_len) break; ND_PRINT((ndo, "\n\t\tInterface Parameter: %s (0x%02x), len %u", tok2str(ldp_fec_martini_ifparm_values,"Unknown",vc_info_tlv_type), vc_info_tlv_type, vc_info_tlv_len)); switch(vc_info_tlv_type) { case LDP_FEC_MARTINI_IFPARM_MTU: ND_TCHECK_16BITS(tptr + 2); ND_PRINT((ndo, ": %u", EXTRACT_16BITS(tptr+2))); break; case LDP_FEC_MARTINI_IFPARM_DESC: ND_PRINT((ndo, ": ")); for (idx = 2; idx < vc_info_tlv_len; idx++) { ND_TCHECK_8BITS(tptr + idx); safeputchar(ndo, *(tptr + idx)); } break; case LDP_FEC_MARTINI_IFPARM_VCCV: ND_TCHECK_8BITS(tptr + 2); ND_PRINT((ndo, "\n\t\t Control Channels (0x%02x) = [%s]", *(tptr+2), bittok2str(ldp_fec_martini_ifparm_vccv_cc_values, "none", *(tptr+2)))); ND_TCHECK_8BITS(tptr + 3); ND_PRINT((ndo, "\n\t\t CV Types (0x%02x) = [%s]", *(tptr+3), bittok2str(ldp_fec_martini_ifparm_vccv_cv_values, "none", *(tptr+3)))); break; default: print_unknown_data(ndo, tptr+2, "\n\t\t ", vc_info_tlv_len-2); break; } vc_info_len -= vc_info_tlv_len; tptr += vc_info_tlv_len; } break; } break; case LDP_TLV_GENERIC_LABEL: TLV_TCHECK(4); ND_PRINT((ndo, "\n\t Label: %u", EXTRACT_32BITS(tptr) & 0xfffff)); break; case LDP_TLV_STATUS: TLV_TCHECK(8); ui = EXTRACT_32BITS(tptr); tptr+=4; ND_PRINT((ndo, "\n\t Status: 0x%02x, Flags: [%s and %s forward]", ui&0x3fffffff, ui&0x80000000 ? "Fatal error" : "Advisory Notification", ui&0x40000000 ? "do" : "don't")); ui = EXTRACT_32BITS(tptr); tptr+=4; if (ui) ND_PRINT((ndo, ", causing Message ID: 0x%08x", ui)); break; case LDP_TLV_FT_SESSION: TLV_TCHECK(12); ft_flags = EXTRACT_16BITS(tptr); ND_PRINT((ndo, "\n\t Flags: [%sReconnect, %sSave State, %sAll-Label Protection, %s Checkpoint, %sRe-Learn State]", ft_flags&0x8000 ? "" : "No ", ft_flags&0x8 ? "" : "Don't ", ft_flags&0x4 ? "" : "No ", ft_flags&0x2 ? "Sequence Numbered Label" : "All Labels", ft_flags&0x1 ? "" : "Don't ")); /* 16 bits (FT Flags) + 16 bits (Reserved) */ tptr+=4; ui = EXTRACT_32BITS(tptr); if (ui) ND_PRINT((ndo, ", Reconnect Timeout: %ums", ui)); tptr+=4; ui = EXTRACT_32BITS(tptr); if (ui) ND_PRINT((ndo, ", Recovery Time: %ums", ui)); break; case LDP_TLV_MTU: TLV_TCHECK(2); ND_PRINT((ndo, "\n\t MTU: %u", EXTRACT_16BITS(tptr))); break; /* * FIXME those are the defined TLVs that lack a decoder * you are welcome to contribute code ;-) */ case LDP_TLV_HOP_COUNT: case LDP_TLV_PATH_VECTOR: case LDP_TLV_ATM_LABEL: case LDP_TLV_FR_LABEL: case LDP_TLV_EXTD_STATUS: case LDP_TLV_RETURNED_PDU: case LDP_TLV_RETURNED_MSG: case LDP_TLV_ATM_SESSION_PARM: case LDP_TLV_FR_SESSION_PARM: case LDP_TLV_LABEL_REQUEST_MSG_ID: default: if (ndo->ndo_vflag <= 1) print_unknown_data(ndo, tptr, "\n\t ", tlv_tlen); break; } return(tlv_len+4); /* Type & Length fields not included */ trunc: ND_PRINT((ndo, "%s", tstr)); return 0; badtlv: ND_PRINT((ndo, "\n\t\t TLV contents go past end of TLV")); return(tlv_len+4); /* Type & Length fields not included */ } void ldp_print(netdissect_options *ndo, register const u_char *pptr, register u_int len) { u_int processed; while (len > (sizeof(struct ldp_common_header) + sizeof(struct ldp_msg_header))) { processed = ldp_pdu_print(ndo, pptr); if (processed == 0) return; if (len < processed) { ND_PRINT((ndo, " [remaining length %u < %u]", len, processed)); ND_PRINT((ndo, "%s", istr)); break; } len -= processed; pptr += processed; } } static u_int ldp_pdu_print(netdissect_options *ndo, register const u_char *pptr) { const struct ldp_common_header *ldp_com_header; const struct ldp_msg_header *ldp_msg_header; const u_char *tptr,*msg_tptr; u_short tlen; u_short pdu_len,msg_len,msg_type,msg_tlen; int hexdump,processed; ldp_com_header = (const struct ldp_common_header *)pptr; ND_TCHECK(*ldp_com_header); /* * Sanity checking of the header. */ if (EXTRACT_16BITS(&ldp_com_header->version) != LDP_VERSION) { ND_PRINT((ndo, "%sLDP version %u packet not supported", (ndo->ndo_vflag < 1) ? "" : "\n\t", EXTRACT_16BITS(&ldp_com_header->version))); return 0; } pdu_len = EXTRACT_16BITS(&ldp_com_header->pdu_length); if (pdu_len < sizeof(const struct ldp_common_header)-4) { /* length too short */ ND_PRINT((ndo, "%sLDP, pdu-length: %u (too short, < %u)", (ndo->ndo_vflag < 1) ? "" : "\n\t", pdu_len, (u_int)(sizeof(const struct ldp_common_header)-4))); return 0; } /* print the LSR-ID, label-space & length */ ND_PRINT((ndo, "%sLDP, Label-Space-ID: %s:%u, pdu-length: %u", (ndo->ndo_vflag < 1) ? "" : "\n\t", ipaddr_string(ndo, &ldp_com_header->lsr_id), EXTRACT_16BITS(&ldp_com_header->label_space), pdu_len)); /* bail out if non-verbose */ if (ndo->ndo_vflag < 1) return 0; /* ok they seem to want to know everything - lets fully decode it */ tptr = pptr + sizeof(const struct ldp_common_header); tlen = pdu_len - (sizeof(const struct ldp_common_header)-4); /* Type & Length fields not included */ while(tlen>0) { /* did we capture enough for fully decoding the msg header ? */ ND_TCHECK2(*tptr, sizeof(struct ldp_msg_header)); ldp_msg_header = (const struct ldp_msg_header *)tptr; msg_len=EXTRACT_16BITS(ldp_msg_header->length); msg_type=LDP_MASK_MSG_TYPE(EXTRACT_16BITS(ldp_msg_header->type)); if (msg_len < sizeof(struct ldp_msg_header)-4) { /* length too short */ /* FIXME vendor private / experimental check */ ND_PRINT((ndo, "\n\t %s Message (0x%04x), length: %u (too short, < %u)", tok2str(ldp_msg_values, "Unknown", msg_type), msg_type, msg_len, (u_int)(sizeof(struct ldp_msg_header)-4))); return 0; } /* FIXME vendor private / experimental check */ ND_PRINT((ndo, "\n\t %s Message (0x%04x), length: %u, Message ID: 0x%08x, Flags: [%s if unknown]", tok2str(ldp_msg_values, "Unknown", msg_type), msg_type, msg_len, EXTRACT_32BITS(&ldp_msg_header->id), LDP_MASK_U_BIT(EXTRACT_16BITS(&ldp_msg_header->type)) ? "continue processing" : "ignore")); msg_tptr=tptr+sizeof(struct ldp_msg_header); msg_tlen=msg_len-(sizeof(struct ldp_msg_header)-4); /* Type & Length fields not included */ /* did we capture enough for fully decoding the message ? */ ND_TCHECK2(*tptr, msg_len); hexdump=FALSE; switch(msg_type) { case LDP_MSG_NOTIF: case LDP_MSG_HELLO: case LDP_MSG_INIT: case LDP_MSG_KEEPALIVE: case LDP_MSG_ADDRESS: case LDP_MSG_LABEL_MAPPING: case LDP_MSG_ADDRESS_WITHDRAW: case LDP_MSG_LABEL_WITHDRAW: while(msg_tlen >= 4) { processed = ldp_tlv_print(ndo, msg_tptr, msg_tlen); if (processed == 0) break; msg_tlen-=processed; msg_tptr+=processed; } break; /* * FIXME those are the defined messages that lack a decoder * you are welcome to contribute code ;-) */ case LDP_MSG_LABEL_REQUEST: case LDP_MSG_LABEL_RELEASE: case LDP_MSG_LABEL_ABORT_REQUEST: default: if (ndo->ndo_vflag <= 1) print_unknown_data(ndo, msg_tptr, "\n\t ", msg_tlen); break; } /* do we want to see an additionally hexdump ? */ if (ndo->ndo_vflag > 1 || hexdump==TRUE) print_unknown_data(ndo, tptr+sizeof(struct ldp_msg_header), "\n\t ", msg_len); tptr += msg_len+4; tlen -= msg_len+4; } return pdu_len+4; trunc: ND_PRINT((ndo, "%s", tstr)); return 0; } /* * Local Variables: * c-style: whitesmith * c-basic-offset: 8 * End: */ tcpdump-4.9.3/print-cnfp.c0000644000026300017510000003330713544412561013565 0ustar mcrmcr/* $OpenBSD: print-cnfp.c,v 1.2 1998/06/25 20:26:59 mickey Exp $ */ /* * Copyright (c) 1998 Michael Shalayeff * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Michael Shalayeff. * 4. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* \summary: Cisco NetFlow protocol printer */ /* * Cisco NetFlow protocol * * See * * http://www.cisco.com/c/en/us/td/docs/net_mgmt/netflow_collection_engine/3-6/user/guide/format.html#wp1005892 */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include #include "netdissect.h" #include "addrtoname.h" #include "extract.h" #include "tcp.h" #include "ipproto.h" struct nfhdr_v1 { uint16_t version; /* version number */ uint16_t count; /* # of records */ uint32_t msys_uptime; uint32_t utc_sec; uint32_t utc_nsec; }; struct nfrec_v1 { struct in_addr src_ina; struct in_addr dst_ina; struct in_addr nhop_ina; uint16_t input; /* SNMP index of input interface */ uint16_t output; /* SNMP index of output interface */ uint32_t packets; /* packets in the flow */ uint32_t octets; /* layer 3 octets in the packets of the flow */ uint32_t start_time; /* sys_uptime value at start of flow */ uint32_t last_time; /* sys_uptime value when last packet of flow was received */ uint16_t srcport; /* TCP/UDP source port or equivalent */ uint16_t dstport; /* TCP/UDP source port or equivalent */ uint16_t pad1; /* pad */ uint8_t proto; /* IP protocol type */ uint8_t tos; /* IP type of service */ uint8_t tcp_flags; /* cumulative OR of TCP flags */ uint8_t pad[3]; /* padding */ uint32_t reserved; /* unused */ }; struct nfhdr_v5 { uint16_t version; /* version number */ uint16_t count; /* # of records */ uint32_t msys_uptime; uint32_t utc_sec; uint32_t utc_nsec; uint32_t sequence; /* flow sequence number */ uint8_t engine_type; /* type of flow-switching engine */ uint8_t engine_id; /* slot number of the flow-switching engine */ uint16_t sampling_interval; /* sampling mode and interval */ }; struct nfrec_v5 { struct in_addr src_ina; struct in_addr dst_ina; struct in_addr nhop_ina; uint16_t input; /* SNMP index of input interface */ uint16_t output; /* SNMP index of output interface */ uint32_t packets; /* packets in the flow */ uint32_t octets; /* layer 3 octets in the packets of the flow */ uint32_t start_time; /* sys_uptime value at start of flow */ uint32_t last_time; /* sys_uptime value when last packet of flow was received */ uint16_t srcport; /* TCP/UDP source port or equivalent */ uint16_t dstport; /* TCP/UDP source port or equivalent */ uint8_t pad1; /* pad */ uint8_t tcp_flags; /* cumulative OR of TCP flags */ uint8_t proto; /* IP protocol type */ uint8_t tos; /* IP type of service */ uint16_t src_as; /* AS number of the source */ uint16_t dst_as; /* AS number of the destination */ uint8_t src_mask; /* source address mask bits */ uint8_t dst_mask; /* destination address prefix mask bits */ uint16_t pad2; struct in_addr peer_nexthop; /* v6: IP address of the nexthop within the peer (FIB)*/ }; struct nfhdr_v6 { uint16_t version; /* version number */ uint16_t count; /* # of records */ uint32_t msys_uptime; uint32_t utc_sec; uint32_t utc_nsec; uint32_t sequence; /* v5 flow sequence number */ uint32_t reserved; /* v5 only */ }; struct nfrec_v6 { struct in_addr src_ina; struct in_addr dst_ina; struct in_addr nhop_ina; uint16_t input; /* SNMP index of input interface */ uint16_t output; /* SNMP index of output interface */ uint32_t packets; /* packets in the flow */ uint32_t octets; /* layer 3 octets in the packets of the flow */ uint32_t start_time; /* sys_uptime value at start of flow */ uint32_t last_time; /* sys_uptime value when last packet of flow was received */ uint16_t srcport; /* TCP/UDP source port or equivalent */ uint16_t dstport; /* TCP/UDP source port or equivalent */ uint8_t pad1; /* pad */ uint8_t tcp_flags; /* cumulative OR of TCP flags */ uint8_t proto; /* IP protocol type */ uint8_t tos; /* IP type of service */ uint16_t src_as; /* AS number of the source */ uint16_t dst_as; /* AS number of the destination */ uint8_t src_mask; /* source address mask bits */ uint8_t dst_mask; /* destination address prefix mask bits */ uint16_t flags; struct in_addr peer_nexthop; /* v6: IP address of the nexthop within the peer (FIB)*/ }; static void cnfp_v1_print(netdissect_options *ndo, const u_char *cp) { register const struct nfhdr_v1 *nh; register const struct nfrec_v1 *nr; const char *p_name; int nrecs, ver; #if 0 time_t t; #endif nh = (const struct nfhdr_v1 *)cp; ND_TCHECK(*nh); ver = EXTRACT_16BITS(&nh->version); nrecs = EXTRACT_32BITS(&nh->count); #if 0 /* * This is seconds since the UN*X epoch, and is followed by * nanoseconds. XXX - format it, rather than just dumping the * raw seconds-since-the-Epoch. */ t = EXTRACT_32BITS(&nh->utc_sec); #endif ND_PRINT((ndo, "NetFlow v%x, %u.%03u uptime, %u.%09u, ", ver, EXTRACT_32BITS(&nh->msys_uptime)/1000, EXTRACT_32BITS(&nh->msys_uptime)%1000, EXTRACT_32BITS(&nh->utc_sec), EXTRACT_32BITS(&nh->utc_nsec))); nr = (const struct nfrec_v1 *)&nh[1]; ND_PRINT((ndo, "%2u recs", nrecs)); for (; nrecs != 0; nr++, nrecs--) { char buf[20]; char asbuf[20]; /* * Make sure we have the entire record. */ ND_TCHECK(*nr); ND_PRINT((ndo, "\n started %u.%03u, last %u.%03u", EXTRACT_32BITS(&nr->start_time)/1000, EXTRACT_32BITS(&nr->start_time)%1000, EXTRACT_32BITS(&nr->last_time)/1000, EXTRACT_32BITS(&nr->last_time)%1000)); asbuf[0] = buf[0] = '\0'; ND_PRINT((ndo, "\n %s%s%s:%u ", intoa(nr->src_ina.s_addr), buf, asbuf, EXTRACT_16BITS(&nr->srcport))); ND_PRINT((ndo, "> %s%s%s:%u ", intoa(nr->dst_ina.s_addr), buf, asbuf, EXTRACT_16BITS(&nr->dstport))); ND_PRINT((ndo, ">> %s\n ", intoa(nr->nhop_ina.s_addr))); if (!ndo->ndo_nflag && (p_name = netdb_protoname(nr->proto)) != NULL) ND_PRINT((ndo, "%s ", p_name)); else ND_PRINT((ndo, "%u ", nr->proto)); /* tcp flags for tcp only */ if (nr->proto == IPPROTO_TCP) { int flags; flags = nr->tcp_flags; ND_PRINT((ndo, "%s%s%s%s%s%s%s", flags & TH_FIN ? "F" : "", flags & TH_SYN ? "S" : "", flags & TH_RST ? "R" : "", flags & TH_PUSH ? "P" : "", flags & TH_ACK ? "A" : "", flags & TH_URG ? "U" : "", flags ? " " : "")); } buf[0]='\0'; ND_PRINT((ndo, "tos %u, %u (%u octets) %s", nr->tos, EXTRACT_32BITS(&nr->packets), EXTRACT_32BITS(&nr->octets), buf)); } return; trunc: ND_PRINT((ndo, "[|cnfp]")); return; } static void cnfp_v5_print(netdissect_options *ndo, const u_char *cp) { register const struct nfhdr_v5 *nh; register const struct nfrec_v5 *nr; const char *p_name; int nrecs, ver; #if 0 time_t t; #endif nh = (const struct nfhdr_v5 *)cp; ND_TCHECK(*nh); ver = EXTRACT_16BITS(&nh->version); nrecs = EXTRACT_32BITS(&nh->count); #if 0 /* * This is seconds since the UN*X epoch, and is followed by * nanoseconds. XXX - format it, rather than just dumping the * raw seconds-since-the-Epoch. */ t = EXTRACT_32BITS(&nh->utc_sec); #endif ND_PRINT((ndo, "NetFlow v%x, %u.%03u uptime, %u.%09u, ", ver, EXTRACT_32BITS(&nh->msys_uptime)/1000, EXTRACT_32BITS(&nh->msys_uptime)%1000, EXTRACT_32BITS(&nh->utc_sec), EXTRACT_32BITS(&nh->utc_nsec))); ND_PRINT((ndo, "#%u, ", EXTRACT_32BITS(&nh->sequence))); nr = (const struct nfrec_v5 *)&nh[1]; ND_PRINT((ndo, "%2u recs", nrecs)); for (; nrecs != 0; nr++, nrecs--) { char buf[20]; char asbuf[20]; /* * Make sure we have the entire record. */ ND_TCHECK(*nr); ND_PRINT((ndo, "\n started %u.%03u, last %u.%03u", EXTRACT_32BITS(&nr->start_time)/1000, EXTRACT_32BITS(&nr->start_time)%1000, EXTRACT_32BITS(&nr->last_time)/1000, EXTRACT_32BITS(&nr->last_time)%1000)); asbuf[0] = buf[0] = '\0'; snprintf(buf, sizeof(buf), "/%u", nr->src_mask); snprintf(asbuf, sizeof(asbuf), ":%u", EXTRACT_16BITS(&nr->src_as)); ND_PRINT((ndo, "\n %s%s%s:%u ", intoa(nr->src_ina.s_addr), buf, asbuf, EXTRACT_16BITS(&nr->srcport))); snprintf(buf, sizeof(buf), "/%d", nr->dst_mask); snprintf(asbuf, sizeof(asbuf), ":%u", EXTRACT_16BITS(&nr->dst_as)); ND_PRINT((ndo, "> %s%s%s:%u ", intoa(nr->dst_ina.s_addr), buf, asbuf, EXTRACT_16BITS(&nr->dstport))); ND_PRINT((ndo, ">> %s\n ", intoa(nr->nhop_ina.s_addr))); if (!ndo->ndo_nflag && (p_name = netdb_protoname(nr->proto)) != NULL) ND_PRINT((ndo, "%s ", p_name)); else ND_PRINT((ndo, "%u ", nr->proto)); /* tcp flags for tcp only */ if (nr->proto == IPPROTO_TCP) { int flags; flags = nr->tcp_flags; ND_PRINT((ndo, "%s%s%s%s%s%s%s", flags & TH_FIN ? "F" : "", flags & TH_SYN ? "S" : "", flags & TH_RST ? "R" : "", flags & TH_PUSH ? "P" : "", flags & TH_ACK ? "A" : "", flags & TH_URG ? "U" : "", flags ? " " : "")); } buf[0]='\0'; ND_PRINT((ndo, "tos %u, %u (%u octets) %s", nr->tos, EXTRACT_32BITS(&nr->packets), EXTRACT_32BITS(&nr->octets), buf)); } return; trunc: ND_PRINT((ndo, "[|cnfp]")); return; } static void cnfp_v6_print(netdissect_options *ndo, const u_char *cp) { register const struct nfhdr_v6 *nh; register const struct nfrec_v6 *nr; const char *p_name; int nrecs, ver; #if 0 time_t t; #endif nh = (const struct nfhdr_v6 *)cp; ND_TCHECK(*nh); ver = EXTRACT_16BITS(&nh->version); nrecs = EXTRACT_32BITS(&nh->count); #if 0 /* * This is seconds since the UN*X epoch, and is followed by * nanoseconds. XXX - format it, rather than just dumping the * raw seconds-since-the-Epoch. */ t = EXTRACT_32BITS(&nh->utc_sec); #endif ND_PRINT((ndo, "NetFlow v%x, %u.%03u uptime, %u.%09u, ", ver, EXTRACT_32BITS(&nh->msys_uptime)/1000, EXTRACT_32BITS(&nh->msys_uptime)%1000, EXTRACT_32BITS(&nh->utc_sec), EXTRACT_32BITS(&nh->utc_nsec))); ND_PRINT((ndo, "#%u, ", EXTRACT_32BITS(&nh->sequence))); nr = (const struct nfrec_v6 *)&nh[1]; ND_PRINT((ndo, "%2u recs", nrecs)); for (; nrecs != 0; nr++, nrecs--) { char buf[20]; char asbuf[20]; /* * Make sure we have the entire record. */ ND_TCHECK(*nr); ND_PRINT((ndo, "\n started %u.%03u, last %u.%03u", EXTRACT_32BITS(&nr->start_time)/1000, EXTRACT_32BITS(&nr->start_time)%1000, EXTRACT_32BITS(&nr->last_time)/1000, EXTRACT_32BITS(&nr->last_time)%1000)); asbuf[0] = buf[0] = '\0'; snprintf(buf, sizeof(buf), "/%u", nr->src_mask); snprintf(asbuf, sizeof(asbuf), ":%u", EXTRACT_16BITS(&nr->src_as)); ND_PRINT((ndo, "\n %s%s%s:%u ", intoa(nr->src_ina.s_addr), buf, asbuf, EXTRACT_16BITS(&nr->srcport))); snprintf(buf, sizeof(buf), "/%d", nr->dst_mask); snprintf(asbuf, sizeof(asbuf), ":%u", EXTRACT_16BITS(&nr->dst_as)); ND_PRINT((ndo, "> %s%s%s:%u ", intoa(nr->dst_ina.s_addr), buf, asbuf, EXTRACT_16BITS(&nr->dstport))); ND_PRINT((ndo, ">> %s\n ", intoa(nr->nhop_ina.s_addr))); if (!ndo->ndo_nflag && (p_name = netdb_protoname(nr->proto)) != NULL) ND_PRINT((ndo, "%s ", p_name)); else ND_PRINT((ndo, "%u ", nr->proto)); /* tcp flags for tcp only */ if (nr->proto == IPPROTO_TCP) { int flags; flags = nr->tcp_flags; ND_PRINT((ndo, "%s%s%s%s%s%s%s", flags & TH_FIN ? "F" : "", flags & TH_SYN ? "S" : "", flags & TH_RST ? "R" : "", flags & TH_PUSH ? "P" : "", flags & TH_ACK ? "A" : "", flags & TH_URG ? "U" : "", flags ? " " : "")); } buf[0]='\0'; snprintf(buf, sizeof(buf), "(%u<>%u encaps)", (EXTRACT_16BITS(&nr->flags) >> 8) & 0xff, (EXTRACT_16BITS(&nr->flags)) & 0xff); ND_PRINT((ndo, "tos %u, %u (%u octets) %s", nr->tos, EXTRACT_32BITS(&nr->packets), EXTRACT_32BITS(&nr->octets), buf)); } return; trunc: ND_PRINT((ndo, "[|cnfp]")); return; } void cnfp_print(netdissect_options *ndo, const u_char *cp) { int ver; /* * First 2 bytes are the version number. */ ND_TCHECK2(*cp, 2); ver = EXTRACT_16BITS(cp); switch (ver) { case 1: cnfp_v1_print(ndo, cp); break; case 5: cnfp_v5_print(ndo, cp); break; case 6: cnfp_v6_print(ndo, cp); break; default: ND_PRINT((ndo, "NetFlow v%x", ver)); break; } return; trunc: ND_PRINT((ndo, "[|cnfp]")); return; } tcpdump-4.9.3/print-tcp.c0000644000026300017510000010754113544412561013427 0ustar mcrmcr/* $NetBSD: print-tcp.c,v 1.9 2007/07/26 18:15:12 plunky Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 * The Regents of the University of California. All rights reserved. * * Copyright (c) 1999-2004 The tcpdump.org project * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of * the University nor the names of its contributors may be used to endorse * or promote products derived from this software without specific prior * written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* \summary: TCP printer */ #ifndef lint #else __RCSID("$NetBSD: print-tcp.c,v 1.8 2007/07/24 11:53:48 drochner Exp $"); #endif #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include #include "netdissect.h" #include "addrtoname.h" #include "extract.h" #include "tcp.h" #include "ip.h" #include "ip6.h" #include "ipproto.h" #include "rpc_auth.h" #include "rpc_msg.h" #ifdef HAVE_LIBCRYPTO #include #include "signature.h" static int tcp_verify_signature(netdissect_options *ndo, const struct ip *ip, const struct tcphdr *tp, const u_char *data, int length, const u_char *rcvsig); #endif static void print_tcp_rst_data(netdissect_options *, register const u_char *sp, u_int length); static void print_tcp_fastopen_option(netdissect_options *ndo, register const u_char *cp, u_int datalen, int exp); #define MAX_RST_DATA_LEN 30 struct tha { struct in_addr src; struct in_addr dst; u_int port; }; struct tcp_seq_hash { struct tcp_seq_hash *nxt; struct tha addr; tcp_seq seq; tcp_seq ack; }; struct tha6 { struct in6_addr src; struct in6_addr dst; u_int port; }; struct tcp_seq_hash6 { struct tcp_seq_hash6 *nxt; struct tha6 addr; tcp_seq seq; tcp_seq ack; }; #define TSEQ_HASHSIZE 919 /* These tcp optinos do not have the size octet */ #define ZEROLENOPT(o) ((o) == TCPOPT_EOL || (o) == TCPOPT_NOP) static struct tcp_seq_hash tcp_seq_hash4[TSEQ_HASHSIZE]; static struct tcp_seq_hash6 tcp_seq_hash6[TSEQ_HASHSIZE]; static const struct tok tcp_flag_values[] = { { TH_FIN, "F" }, { TH_SYN, "S" }, { TH_RST, "R" }, { TH_PUSH, "P" }, { TH_ACK, "." }, { TH_URG, "U" }, { TH_ECNECHO, "E" }, { TH_CWR, "W" }, { 0, NULL } }; static const struct tok tcp_option_values[] = { { TCPOPT_EOL, "eol" }, { TCPOPT_NOP, "nop" }, { TCPOPT_MAXSEG, "mss" }, { TCPOPT_WSCALE, "wscale" }, { TCPOPT_SACKOK, "sackOK" }, { TCPOPT_SACK, "sack" }, { TCPOPT_ECHO, "echo" }, { TCPOPT_ECHOREPLY, "echoreply" }, { TCPOPT_TIMESTAMP, "TS" }, { TCPOPT_CC, "cc" }, { TCPOPT_CCNEW, "ccnew" }, { TCPOPT_CCECHO, "" }, { TCPOPT_SIGNATURE, "md5" }, { TCPOPT_SCPS, "scps" }, { TCPOPT_UTO, "uto" }, { TCPOPT_TCPAO, "tcp-ao" }, { TCPOPT_MPTCP, "mptcp" }, { TCPOPT_FASTOPEN, "tfo" }, { TCPOPT_EXPERIMENT2, "exp" }, { 0, NULL } }; static int tcp_cksum(netdissect_options *ndo, register const struct ip *ip, register const struct tcphdr *tp, register u_int len) { return nextproto4_cksum(ndo, ip, (const uint8_t *)tp, len, len, IPPROTO_TCP); } static int tcp6_cksum(netdissect_options *ndo, register const struct ip6_hdr *ip6, register const struct tcphdr *tp, register u_int len) { return nextproto6_cksum(ndo, ip6, (const uint8_t *)tp, len, len, IPPROTO_TCP); } void tcp_print(netdissect_options *ndo, register const u_char *bp, register u_int length, register const u_char *bp2, int fragmented) { register const struct tcphdr *tp; register const struct ip *ip; register u_char flags; register u_int hlen; register char ch; uint16_t sport, dport, win, urp; uint32_t seq, ack, thseq, thack; u_int utoval; uint16_t magic; register int rev; register const struct ip6_hdr *ip6; tp = (const struct tcphdr *)bp; ip = (const struct ip *)bp2; if (IP_V(ip) == 6) ip6 = (const struct ip6_hdr *)bp2; else ip6 = NULL; ch = '\0'; if (!ND_TTEST(tp->th_dport)) { ND_PRINT((ndo, "%s > %s: [|tcp]", ipaddr_string(ndo, &ip->ip_src), ipaddr_string(ndo, &ip->ip_dst))); return; } sport = EXTRACT_16BITS(&tp->th_sport); dport = EXTRACT_16BITS(&tp->th_dport); if (ip6) { if (ip6->ip6_nxt == IPPROTO_TCP) { ND_PRINT((ndo, "%s.%s > %s.%s: ", ip6addr_string(ndo, &ip6->ip6_src), tcpport_string(ndo, sport), ip6addr_string(ndo, &ip6->ip6_dst), tcpport_string(ndo, dport))); } else { ND_PRINT((ndo, "%s > %s: ", tcpport_string(ndo, sport), tcpport_string(ndo, dport))); } } else { if (ip->ip_p == IPPROTO_TCP) { ND_PRINT((ndo, "%s.%s > %s.%s: ", ipaddr_string(ndo, &ip->ip_src), tcpport_string(ndo, sport), ipaddr_string(ndo, &ip->ip_dst), tcpport_string(ndo, dport))); } else { ND_PRINT((ndo, "%s > %s: ", tcpport_string(ndo, sport), tcpport_string(ndo, dport))); } } ND_TCHECK(*tp); hlen = TH_OFF(tp) * 4; if (hlen < sizeof(*tp)) { ND_PRINT((ndo, " tcp %d [bad hdr length %u - too short, < %lu]", length - hlen, hlen, (unsigned long)sizeof(*tp))); return; } seq = EXTRACT_32BITS(&tp->th_seq); ack = EXTRACT_32BITS(&tp->th_ack); win = EXTRACT_16BITS(&tp->th_win); urp = EXTRACT_16BITS(&tp->th_urp); if (ndo->ndo_qflag) { ND_PRINT((ndo, "tcp %d", length - hlen)); if (hlen > length) { ND_PRINT((ndo, " [bad hdr length %u - too long, > %u]", hlen, length)); } return; } flags = tp->th_flags; ND_PRINT((ndo, "Flags [%s]", bittok2str_nosep(tcp_flag_values, "none", flags))); if (!ndo->ndo_Sflag && (flags & TH_ACK)) { /* * Find (or record) the initial sequence numbers for * this conversation. (we pick an arbitrary * collating order so there's only one entry for * both directions). */ rev = 0; if (ip6) { register struct tcp_seq_hash6 *th; struct tcp_seq_hash6 *tcp_seq_hash; const struct in6_addr *src, *dst; struct tha6 tha; tcp_seq_hash = tcp_seq_hash6; src = &ip6->ip6_src; dst = &ip6->ip6_dst; if (sport > dport) rev = 1; else if (sport == dport) { if (UNALIGNED_MEMCMP(src, dst, sizeof ip6->ip6_dst) > 0) rev = 1; } if (rev) { UNALIGNED_MEMCPY(&tha.src, dst, sizeof ip6->ip6_dst); UNALIGNED_MEMCPY(&tha.dst, src, sizeof ip6->ip6_src); tha.port = ((u_int)dport) << 16 | sport; } else { UNALIGNED_MEMCPY(&tha.dst, dst, sizeof ip6->ip6_dst); UNALIGNED_MEMCPY(&tha.src, src, sizeof ip6->ip6_src); tha.port = ((u_int)sport) << 16 | dport; } for (th = &tcp_seq_hash[tha.port % TSEQ_HASHSIZE]; th->nxt; th = th->nxt) if (memcmp((char *)&tha, (char *)&th->addr, sizeof(th->addr)) == 0) break; if (!th->nxt || (flags & TH_SYN)) { /* didn't find it or new conversation */ if (th->nxt == NULL) { th->nxt = (struct tcp_seq_hash6 *) calloc(1, sizeof(*th)); if (th->nxt == NULL) (*ndo->ndo_error)(ndo, "tcp_print: calloc"); } th->addr = tha; if (rev) th->ack = seq, th->seq = ack - 1; else th->seq = seq, th->ack = ack - 1; } else { if (rev) seq -= th->ack, ack -= th->seq; else seq -= th->seq, ack -= th->ack; } thseq = th->seq; thack = th->ack; } else { register struct tcp_seq_hash *th; struct tcp_seq_hash *tcp_seq_hash; struct tha tha; tcp_seq_hash = tcp_seq_hash4; if (sport > dport) rev = 1; else if (sport == dport) { if (UNALIGNED_MEMCMP(&ip->ip_src, &ip->ip_dst, sizeof ip->ip_dst) > 0) rev = 1; } if (rev) { UNALIGNED_MEMCPY(&tha.src, &ip->ip_dst, sizeof ip->ip_dst); UNALIGNED_MEMCPY(&tha.dst, &ip->ip_src, sizeof ip->ip_src); tha.port = ((u_int)dport) << 16 | sport; } else { UNALIGNED_MEMCPY(&tha.dst, &ip->ip_dst, sizeof ip->ip_dst); UNALIGNED_MEMCPY(&tha.src, &ip->ip_src, sizeof ip->ip_src); tha.port = ((u_int)sport) << 16 | dport; } for (th = &tcp_seq_hash[tha.port % TSEQ_HASHSIZE]; th->nxt; th = th->nxt) if (memcmp((char *)&tha, (char *)&th->addr, sizeof(th->addr)) == 0) break; if (!th->nxt || (flags & TH_SYN)) { /* didn't find it or new conversation */ if (th->nxt == NULL) { th->nxt = (struct tcp_seq_hash *) calloc(1, sizeof(*th)); if (th->nxt == NULL) (*ndo->ndo_error)(ndo, "tcp_print: calloc"); } th->addr = tha; if (rev) th->ack = seq, th->seq = ack - 1; else th->seq = seq, th->ack = ack - 1; } else { if (rev) seq -= th->ack, ack -= th->seq; else seq -= th->seq, ack -= th->ack; } thseq = th->seq; thack = th->ack; } } else { /*fool gcc*/ thseq = thack = rev = 0; } if (hlen > length) { ND_PRINT((ndo, " [bad hdr length %u - too long, > %u]", hlen, length)); return; } if (ndo->ndo_vflag && !ndo->ndo_Kflag && !fragmented) { /* Check the checksum, if possible. */ uint16_t sum, tcp_sum; if (IP_V(ip) == 4) { if (ND_TTEST2(tp->th_sport, length)) { sum = tcp_cksum(ndo, ip, tp, length); tcp_sum = EXTRACT_16BITS(&tp->th_sum); ND_PRINT((ndo, ", cksum 0x%04x", tcp_sum)); if (sum != 0) ND_PRINT((ndo, " (incorrect -> 0x%04x)", in_cksum_shouldbe(tcp_sum, sum))); else ND_PRINT((ndo, " (correct)")); } } else if (IP_V(ip) == 6 && ip6->ip6_plen) { if (ND_TTEST2(tp->th_sport, length)) { sum = tcp6_cksum(ndo, ip6, tp, length); tcp_sum = EXTRACT_16BITS(&tp->th_sum); ND_PRINT((ndo, ", cksum 0x%04x", tcp_sum)); if (sum != 0) ND_PRINT((ndo, " (incorrect -> 0x%04x)", in_cksum_shouldbe(tcp_sum, sum))); else ND_PRINT((ndo, " (correct)")); } } } length -= hlen; if (ndo->ndo_vflag > 1 || length > 0 || flags & (TH_SYN | TH_FIN | TH_RST)) { ND_PRINT((ndo, ", seq %u", seq)); if (length > 0) { ND_PRINT((ndo, ":%u", seq + length)); } } if (flags & TH_ACK) { ND_PRINT((ndo, ", ack %u", ack)); } ND_PRINT((ndo, ", win %d", win)); if (flags & TH_URG) ND_PRINT((ndo, ", urg %d", urp)); /* * Handle any options. */ if (hlen > sizeof(*tp)) { register const u_char *cp; register u_int i, opt, datalen; register u_int len; hlen -= sizeof(*tp); cp = (const u_char *)tp + sizeof(*tp); ND_PRINT((ndo, ", options [")); while (hlen > 0) { if (ch != '\0') ND_PRINT((ndo, "%c", ch)); ND_TCHECK(*cp); opt = *cp++; if (ZEROLENOPT(opt)) len = 1; else { ND_TCHECK(*cp); len = *cp++; /* total including type, len */ if (len < 2 || len > hlen) goto bad; --hlen; /* account for length byte */ } --hlen; /* account for type byte */ datalen = 0; /* Bail if "l" bytes of data are not left or were not captured */ #define LENCHECK(l) { if ((l) > hlen) goto bad; ND_TCHECK2(*cp, l); } ND_PRINT((ndo, "%s", tok2str(tcp_option_values, "unknown-%u", opt))); switch (opt) { case TCPOPT_MAXSEG: datalen = 2; LENCHECK(datalen); ND_PRINT((ndo, " %u", EXTRACT_16BITS(cp))); break; case TCPOPT_WSCALE: datalen = 1; LENCHECK(datalen); ND_PRINT((ndo, " %u", *cp)); break; case TCPOPT_SACK: datalen = len - 2; if (datalen % 8 != 0) { ND_PRINT((ndo, " invalid sack")); } else { uint32_t s, e; ND_PRINT((ndo, " %d ", datalen / 8)); for (i = 0; i < datalen; i += 8) { LENCHECK(i + 4); s = EXTRACT_32BITS(cp + i); LENCHECK(i + 8); e = EXTRACT_32BITS(cp + i + 4); if (rev) { s -= thseq; e -= thseq; } else { s -= thack; e -= thack; } ND_PRINT((ndo, "{%u:%u}", s, e)); } } break; case TCPOPT_CC: case TCPOPT_CCNEW: case TCPOPT_CCECHO: case TCPOPT_ECHO: case TCPOPT_ECHOREPLY: /* * those options share their semantics. * fall through */ datalen = 4; LENCHECK(datalen); ND_PRINT((ndo, " %u", EXTRACT_32BITS(cp))); break; case TCPOPT_TIMESTAMP: datalen = 8; LENCHECK(datalen); ND_PRINT((ndo, " val %u ecr %u", EXTRACT_32BITS(cp), EXTRACT_32BITS(cp + 4))); break; case TCPOPT_SIGNATURE: datalen = TCP_SIGLEN; LENCHECK(datalen); ND_PRINT((ndo, " ")); #ifdef HAVE_LIBCRYPTO switch (tcp_verify_signature(ndo, ip, tp, bp + TH_OFF(tp) * 4, length, cp)) { case SIGNATURE_VALID: ND_PRINT((ndo, "valid")); break; case SIGNATURE_INVALID: ND_PRINT((ndo, "invalid")); break; case CANT_CHECK_SIGNATURE: ND_PRINT((ndo, "can't check - ")); for (i = 0; i < TCP_SIGLEN; ++i) ND_PRINT((ndo, "%02x", cp[i])); break; } #else for (i = 0; i < TCP_SIGLEN; ++i) ND_PRINT((ndo, "%02x", cp[i])); #endif break; case TCPOPT_SCPS: datalen = 2; LENCHECK(datalen); ND_PRINT((ndo, " cap %02x id %u", cp[0], cp[1])); break; case TCPOPT_TCPAO: datalen = len - 2; /* RFC 5925 Section 2.2: * "The Length value MUST be greater than or equal to 4." * (This includes the Kind and Length fields already processed * at this point.) */ if (datalen < 2) { ND_PRINT((ndo, " invalid")); } else { LENCHECK(1); ND_PRINT((ndo, " keyid %u", cp[0])); LENCHECK(2); ND_PRINT((ndo, " rnextkeyid %u", cp[1])); if (datalen > 2) { ND_PRINT((ndo, " mac 0x")); for (i = 2; i < datalen; i++) { LENCHECK(i + 1); ND_PRINT((ndo, "%02x", cp[i])); } } } break; case TCPOPT_EOL: case TCPOPT_NOP: case TCPOPT_SACKOK: /* * Nothing interesting. * fall through */ break; case TCPOPT_UTO: datalen = 2; LENCHECK(datalen); utoval = EXTRACT_16BITS(cp); ND_PRINT((ndo, " 0x%x", utoval)); if (utoval & 0x0001) utoval = (utoval >> 1) * 60; else utoval >>= 1; ND_PRINT((ndo, " %u", utoval)); break; case TCPOPT_MPTCP: datalen = len - 2; LENCHECK(datalen); if (!mptcp_print(ndo, cp-2, len, flags)) goto bad; break; case TCPOPT_FASTOPEN: datalen = len - 2; LENCHECK(datalen); ND_PRINT((ndo, " ")); print_tcp_fastopen_option(ndo, cp, datalen, FALSE); break; case TCPOPT_EXPERIMENT2: datalen = len - 2; LENCHECK(datalen); if (datalen < 2) goto bad; /* RFC6994 */ magic = EXTRACT_16BITS(cp); ND_PRINT((ndo, "-")); switch(magic) { case 0xf989: /* TCP Fast Open RFC 7413 */ print_tcp_fastopen_option(ndo, cp + 2, datalen - 2, TRUE); break; default: /* Unknown magic number */ ND_PRINT((ndo, "%04x", magic)); break; } break; default: datalen = len - 2; if (datalen) ND_PRINT((ndo, " 0x")); for (i = 0; i < datalen; ++i) { LENCHECK(i + 1); ND_PRINT((ndo, "%02x", cp[i])); } break; } /* Account for data printed */ cp += datalen; hlen -= datalen; /* Check specification against observed length */ ++datalen; /* option octet */ if (!ZEROLENOPT(opt)) ++datalen; /* size octet */ if (datalen != len) ND_PRINT((ndo, "[len %d]", len)); ch = ','; if (opt == TCPOPT_EOL) break; } ND_PRINT((ndo, "]")); } /* * Print length field before crawling down the stack. */ ND_PRINT((ndo, ", length %u", length)); if (length <= 0) return; /* * Decode payload if necessary. */ bp += TH_OFF(tp) * 4; if ((flags & TH_RST) && ndo->ndo_vflag) { print_tcp_rst_data(ndo, bp, length); return; } if (ndo->ndo_packettype) { switch (ndo->ndo_packettype) { case PT_ZMTP1: zmtp1_print(ndo, bp, length); break; case PT_RESP: resp_print(ndo, bp, length); break; } return; } if (IS_SRC_OR_DST_PORT(TELNET_PORT)) { telnet_print(ndo, bp, length); } else if (IS_SRC_OR_DST_PORT(SMTP_PORT)) { ND_PRINT((ndo, ": ")); smtp_print(ndo, bp, length); } else if (IS_SRC_OR_DST_PORT(BGP_PORT)) bgp_print(ndo, bp, length); else if (IS_SRC_OR_DST_PORT(PPTP_PORT)) pptp_print(ndo, bp); else if (IS_SRC_OR_DST_PORT(REDIS_PORT)) resp_print(ndo, bp, length); #ifdef ENABLE_SMB else if (IS_SRC_OR_DST_PORT(NETBIOS_SSN_PORT)) nbt_tcp_print(ndo, bp, length); else if (IS_SRC_OR_DST_PORT(SMB_PORT)) smb_tcp_print(ndo, bp, length); #endif else if (IS_SRC_OR_DST_PORT(BEEP_PORT)) beep_print(ndo, bp, length); else if (IS_SRC_OR_DST_PORT(OPENFLOW_PORT_OLD) || IS_SRC_OR_DST_PORT(OPENFLOW_PORT_IANA)) openflow_print(ndo, bp, length); else if (IS_SRC_OR_DST_PORT(FTP_PORT)) { ND_PRINT((ndo, ": ")); ftp_print(ndo, bp, length); } else if (IS_SRC_OR_DST_PORT(HTTP_PORT) || IS_SRC_OR_DST_PORT(HTTP_PORT_ALT)) { ND_PRINT((ndo, ": ")); http_print(ndo, bp, length); } else if (IS_SRC_OR_DST_PORT(RTSP_PORT) || IS_SRC_OR_DST_PORT(RTSP_PORT_ALT)) { ND_PRINT((ndo, ": ")); rtsp_print(ndo, bp, length); } else if (length > 2 && (IS_SRC_OR_DST_PORT(NAMESERVER_PORT))) { /* domain_print() assumes it does not have to prepend a space before its * own output to separate it from the output of the calling function. This * works well with udp_print(), but requires a small prop here. */ ND_PRINT((ndo, " ")); /* * TCP DNS query has 2byte length at the head. * XXX packet could be unaligned, it can go strange */ ns_print(ndo, bp + 2, length - 2, 0); } else if (IS_SRC_OR_DST_PORT(MSDP_PORT)) { msdp_print(ndo, bp, length); } else if (IS_SRC_OR_DST_PORT(RPKI_RTR_PORT)) { rpki_rtr_print(ndo, bp, length); } else if (length > 0 && (IS_SRC_OR_DST_PORT(LDP_PORT))) { ldp_print(ndo, bp, length); } else if ((IS_SRC_OR_DST_PORT(NFS_PORT)) && length >= 4 && ND_TTEST2(*bp, 4)) { /* * If data present, header length valid, and NFS port used, * assume NFS. * Pass offset of data plus 4 bytes for RPC TCP msg length * to NFS print routines. */ uint32_t fraglen; register const struct sunrpc_msg *rp; enum sunrpc_msg_type direction; fraglen = EXTRACT_32BITS(bp) & 0x7FFFFFFF; if (fraglen > (length) - 4) fraglen = (length) - 4; rp = (const struct sunrpc_msg *)(bp + 4); if (ND_TTEST(rp->rm_direction)) { direction = (enum sunrpc_msg_type)EXTRACT_32BITS(&rp->rm_direction); if (dport == NFS_PORT && direction == SUNRPC_CALL) { ND_PRINT((ndo, ": NFS request xid %u ", EXTRACT_32BITS(&rp->rm_xid))); nfsreq_print_noaddr(ndo, (const u_char *)rp, fraglen, (const u_char *)ip); return; } if (sport == NFS_PORT && direction == SUNRPC_REPLY) { ND_PRINT((ndo, ": NFS reply xid %u ", EXTRACT_32BITS(&rp->rm_xid))); nfsreply_print_noaddr(ndo, (const u_char *)rp, fraglen, (const u_char *)ip); return; } } } return; bad: ND_PRINT((ndo, "[bad opt]")); if (ch != '\0') ND_PRINT((ndo, ">")); return; trunc: ND_PRINT((ndo, "[|tcp]")); if (ch != '\0') ND_PRINT((ndo, ">")); } /* * RFC1122 says the following on data in RST segments: * * 4.2.2.12 RST Segment: RFC-793 Section 3.4 * * A TCP SHOULD allow a received RST segment to include data. * * DISCUSSION * It has been suggested that a RST segment could contain * ASCII text that encoded and explained the cause of the * RST. No standard has yet been established for such * data. * */ static void print_tcp_rst_data(netdissect_options *ndo, register const u_char *sp, u_int length) { int c; ND_PRINT((ndo, ND_TTEST2(*sp, length) ? " [RST" : " [!RST")); if (length > MAX_RST_DATA_LEN) { length = MAX_RST_DATA_LEN; /* can use -X for longer */ ND_PRINT((ndo, "+")); /* indicate we truncate */ } ND_PRINT((ndo, " ")); while (length-- && sp < ndo->ndo_snapend) { c = *sp++; safeputchar(ndo, c); } ND_PRINT((ndo, "]")); } static void print_tcp_fastopen_option(netdissect_options *ndo, register const u_char *cp, u_int datalen, int exp) { u_int i; if (exp) ND_PRINT((ndo, "tfo")); if (datalen == 0) { /* Fast Open Cookie Request */ ND_PRINT((ndo, " cookiereq")); } else { /* Fast Open Cookie */ if (datalen % 2 != 0 || datalen < 4 || datalen > 16) { ND_PRINT((ndo, " invalid")); } else { ND_PRINT((ndo, " cookie ")); for (i = 0; i < datalen; ++i) ND_PRINT((ndo, "%02x", cp[i])); } } } #ifdef HAVE_LIBCRYPTO USES_APPLE_DEPRECATED_API static int tcp_verify_signature(netdissect_options *ndo, const struct ip *ip, const struct tcphdr *tp, const u_char *data, int length, const u_char *rcvsig) { struct tcphdr tp1; u_char sig[TCP_SIGLEN]; char zero_proto = 0; MD5_CTX ctx; uint16_t savecsum, tlen; const struct ip6_hdr *ip6; uint32_t len32; uint8_t nxt; if (data + length > ndo->ndo_snapend) { ND_PRINT((ndo, "snaplen too short, ")); return (CANT_CHECK_SIGNATURE); } tp1 = *tp; if (ndo->ndo_sigsecret == NULL) { ND_PRINT((ndo, "shared secret not supplied with -M, ")); return (CANT_CHECK_SIGNATURE); } MD5_Init(&ctx); /* * Step 1: Update MD5 hash with IP pseudo-header. */ if (IP_V(ip) == 4) { MD5_Update(&ctx, (const char *)&ip->ip_src, sizeof(ip->ip_src)); MD5_Update(&ctx, (const char *)&ip->ip_dst, sizeof(ip->ip_dst)); MD5_Update(&ctx, (const char *)&zero_proto, sizeof(zero_proto)); MD5_Update(&ctx, (const char *)&ip->ip_p, sizeof(ip->ip_p)); tlen = EXTRACT_16BITS(&ip->ip_len) - IP_HL(ip) * 4; tlen = htons(tlen); MD5_Update(&ctx, (const char *)&tlen, sizeof(tlen)); } else if (IP_V(ip) == 6) { ip6 = (const struct ip6_hdr *)ip; MD5_Update(&ctx, (const char *)&ip6->ip6_src, sizeof(ip6->ip6_src)); MD5_Update(&ctx, (const char *)&ip6->ip6_dst, sizeof(ip6->ip6_dst)); len32 = htonl(EXTRACT_16BITS(&ip6->ip6_plen)); MD5_Update(&ctx, (const char *)&len32, sizeof(len32)); nxt = 0; MD5_Update(&ctx, (const char *)&nxt, sizeof(nxt)); MD5_Update(&ctx, (const char *)&nxt, sizeof(nxt)); MD5_Update(&ctx, (const char *)&nxt, sizeof(nxt)); nxt = IPPROTO_TCP; MD5_Update(&ctx, (const char *)&nxt, sizeof(nxt)); } else { ND_PRINT((ndo, "IP version not 4 or 6, ")); return (CANT_CHECK_SIGNATURE); } /* * Step 2: Update MD5 hash with TCP header, excluding options. * The TCP checksum must be set to zero. */ savecsum = tp1.th_sum; tp1.th_sum = 0; MD5_Update(&ctx, (const char *)&tp1, sizeof(struct tcphdr)); tp1.th_sum = savecsum; /* * Step 3: Update MD5 hash with TCP segment data, if present. */ if (length > 0) MD5_Update(&ctx, data, length); /* * Step 4: Update MD5 hash with shared secret. */ MD5_Update(&ctx, ndo->ndo_sigsecret, strlen(ndo->ndo_sigsecret)); MD5_Final(sig, &ctx); if (memcmp(rcvsig, sig, TCP_SIGLEN) == 0) return (SIGNATURE_VALID); else return (SIGNATURE_INVALID); } USES_APPLE_RST #endif /* HAVE_LIBCRYPTO */ /* * Local Variables: * c-style: whitesmith * c-basic-offset: 8 * End: */ tcpdump-4.9.3/print-pptp.c0000644000026300017510000006363613544412561013632 0ustar mcrmcr/* * Copyright (c) 1991, 1993, 1994, 1995, 1996, 1997 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of * the University nor the names of its contributors may be used to endorse * or promote products derived from this software without specific prior * written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * PPTP support contributed by Motonori Shindo (mshindo@mshindo.net) */ /* \summary: Point-to-Point Tunnelling Protocol (PPTP) printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #include "extract.h" static const char tstr[] = " [|pptp]"; #define PPTP_MSG_TYPE_CTRL 1 /* Control Message */ #define PPTP_MSG_TYPE_MGMT 2 /* Management Message (currently not used */ #define PPTP_MAGIC_COOKIE 0x1a2b3c4d /* for sanity check */ #define PPTP_CTRL_MSG_TYPE_SCCRQ 1 #define PPTP_CTRL_MSG_TYPE_SCCRP 2 #define PPTP_CTRL_MSG_TYPE_StopCCRQ 3 #define PPTP_CTRL_MSG_TYPE_StopCCRP 4 #define PPTP_CTRL_MSG_TYPE_ECHORQ 5 #define PPTP_CTRL_MSG_TYPE_ECHORP 6 #define PPTP_CTRL_MSG_TYPE_OCRQ 7 #define PPTP_CTRL_MSG_TYPE_OCRP 8 #define PPTP_CTRL_MSG_TYPE_ICRQ 9 #define PPTP_CTRL_MSG_TYPE_ICRP 10 #define PPTP_CTRL_MSG_TYPE_ICCN 11 #define PPTP_CTRL_MSG_TYPE_CCRQ 12 #define PPTP_CTRL_MSG_TYPE_CDN 13 #define PPTP_CTRL_MSG_TYPE_WEN 14 #define PPTP_CTRL_MSG_TYPE_SLI 15 #define PPTP_FRAMING_CAP_ASYNC_MASK 0x00000001 /* Aynchronous */ #define PPTP_FRAMING_CAP_SYNC_MASK 0x00000002 /* Synchronous */ #define PPTP_BEARER_CAP_ANALOG_MASK 0x00000001 /* Analog */ #define PPTP_BEARER_CAP_DIGITAL_MASK 0x00000002 /* Digital */ static const char *pptp_message_type_string[] = { "NOT_DEFINED", /* 0 Not defined in the RFC2637 */ "SCCRQ", /* 1 Start-Control-Connection-Request */ "SCCRP", /* 2 Start-Control-Connection-Reply */ "StopCCRQ", /* 3 Stop-Control-Connection-Request */ "StopCCRP", /* 4 Stop-Control-Connection-Reply */ "ECHORQ", /* 5 Echo Request */ "ECHORP", /* 6 Echo Reply */ "OCRQ", /* 7 Outgoing-Call-Request */ "OCRP", /* 8 Outgoing-Call-Reply */ "ICRQ", /* 9 Incoming-Call-Request */ "ICRP", /* 10 Incoming-Call-Reply */ "ICCN", /* 11 Incoming-Call-Connected */ "CCRQ", /* 12 Call-Clear-Request */ "CDN", /* 13 Call-Disconnect-Notify */ "WEN", /* 14 WAN-Error-Notify */ "SLI" /* 15 Set-Link-Info */ #define PPTP_MAX_MSGTYPE_INDEX 16 }; /* common for all PPTP control messages */ struct pptp_hdr { uint16_t length; uint16_t msg_type; uint32_t magic_cookie; uint16_t ctrl_msg_type; uint16_t reserved0; }; struct pptp_msg_sccrq { uint16_t proto_ver; uint16_t reserved1; uint32_t framing_cap; uint32_t bearer_cap; uint16_t max_channel; uint16_t firm_rev; u_char hostname[64]; u_char vendor[64]; }; struct pptp_msg_sccrp { uint16_t proto_ver; uint8_t result_code; uint8_t err_code; uint32_t framing_cap; uint32_t bearer_cap; uint16_t max_channel; uint16_t firm_rev; u_char hostname[64]; u_char vendor[64]; }; struct pptp_msg_stopccrq { uint8_t reason; uint8_t reserved1; uint16_t reserved2; }; struct pptp_msg_stopccrp { uint8_t result_code; uint8_t err_code; uint16_t reserved1; }; struct pptp_msg_echorq { uint32_t id; }; struct pptp_msg_echorp { uint32_t id; uint8_t result_code; uint8_t err_code; uint16_t reserved1; }; struct pptp_msg_ocrq { uint16_t call_id; uint16_t call_ser; uint32_t min_bps; uint32_t max_bps; uint32_t bearer_type; uint32_t framing_type; uint16_t recv_winsiz; uint16_t pkt_proc_delay; uint16_t phone_no_len; uint16_t reserved1; u_char phone_no[64]; u_char subaddr[64]; }; struct pptp_msg_ocrp { uint16_t call_id; uint16_t peer_call_id; uint8_t result_code; uint8_t err_code; uint16_t cause_code; uint32_t conn_speed; uint16_t recv_winsiz; uint16_t pkt_proc_delay; uint32_t phy_chan_id; }; struct pptp_msg_icrq { uint16_t call_id; uint16_t call_ser; uint32_t bearer_type; uint32_t phy_chan_id; uint16_t dialed_no_len; uint16_t dialing_no_len; u_char dialed_no[64]; /* DNIS */ u_char dialing_no[64]; /* CLID */ u_char subaddr[64]; }; struct pptp_msg_icrp { uint16_t call_id; uint16_t peer_call_id; uint8_t result_code; uint8_t err_code; uint16_t recv_winsiz; uint16_t pkt_proc_delay; uint16_t reserved1; }; struct pptp_msg_iccn { uint16_t peer_call_id; uint16_t reserved1; uint32_t conn_speed; uint16_t recv_winsiz; uint16_t pkt_proc_delay; uint32_t framing_type; }; struct pptp_msg_ccrq { uint16_t call_id; uint16_t reserved1; }; struct pptp_msg_cdn { uint16_t call_id; uint8_t result_code; uint8_t err_code; uint16_t cause_code; uint16_t reserved1; u_char call_stats[128]; }; struct pptp_msg_wen { uint16_t peer_call_id; uint16_t reserved1; uint32_t crc_err; uint32_t framing_err; uint32_t hardware_overrun; uint32_t buffer_overrun; uint32_t timeout_err; uint32_t align_err; }; struct pptp_msg_sli { uint16_t peer_call_id; uint16_t reserved1; uint32_t send_accm; uint32_t recv_accm; }; /* attributes that appear more than once in above messages: Number of occurence attributes -------------------------------------- 2 uint32_t bearer_cap; 2 uint32_t bearer_type; 6 uint16_t call_id; 2 uint16_t call_ser; 2 uint16_t cause_code; 2 uint32_t conn_speed; 6 uint8_t err_code; 2 uint16_t firm_rev; 2 uint32_t framing_cap; 2 uint32_t framing_type; 2 u_char hostname[64]; 2 uint32_t id; 2 uint16_t max_channel; 5 uint16_t peer_call_id; 2 uint32_t phy_chan_id; 4 uint16_t pkt_proc_delay; 2 uint16_t proto_ver; 4 uint16_t recv_winsiz; 2 uint8_t reserved1; 9 uint16_t reserved1; 6 uint8_t result_code; 2 u_char subaddr[64]; 2 u_char vendor[64]; so I will prepare print out functions for these attributes (except for reserved*). */ /******************************************/ /* Attribute-specific print out functions */ /******************************************/ /* In these attribute-specific print-out functions, it't not necessary to do ND_TCHECK because they are already checked in the caller of these functions. */ static void pptp_bearer_cap_print(netdissect_options *ndo, const uint32_t *bearer_cap) { ND_PRINT((ndo, " BEARER_CAP(%s%s)", EXTRACT_32BITS(bearer_cap) & PPTP_BEARER_CAP_DIGITAL_MASK ? "D" : "", EXTRACT_32BITS(bearer_cap) & PPTP_BEARER_CAP_ANALOG_MASK ? "A" : "")); } static const struct tok pptp_btype_str[] = { { 1, "A" }, /* Analog */ { 2, "D" }, /* Digital */ { 3, "Any" }, { 0, NULL } }; static void pptp_bearer_type_print(netdissect_options *ndo, const uint32_t *bearer_type) { ND_PRINT((ndo, " BEARER_TYPE(%s)", tok2str(pptp_btype_str, "?", EXTRACT_32BITS(bearer_type)))); } static void pptp_call_id_print(netdissect_options *ndo, const uint16_t *call_id) { ND_PRINT((ndo, " CALL_ID(%u)", EXTRACT_16BITS(call_id))); } static void pptp_call_ser_print(netdissect_options *ndo, const uint16_t *call_ser) { ND_PRINT((ndo, " CALL_SER_NUM(%u)", EXTRACT_16BITS(call_ser))); } static void pptp_cause_code_print(netdissect_options *ndo, const uint16_t *cause_code) { ND_PRINT((ndo, " CAUSE_CODE(%u)", EXTRACT_16BITS(cause_code))); } static void pptp_conn_speed_print(netdissect_options *ndo, const uint32_t *conn_speed) { ND_PRINT((ndo, " CONN_SPEED(%u)", EXTRACT_32BITS(conn_speed))); } static const struct tok pptp_errcode_str[] = { { 0, "None" }, { 1, "Not-Connected" }, { 2, "Bad-Format" }, { 3, "Bad-Value" }, { 4, "No-Resource" }, { 5, "Bad-Call-ID" }, { 6, "PAC-Error" }, { 0, NULL } }; static void pptp_err_code_print(netdissect_options *ndo, const uint8_t *err_code) { ND_PRINT((ndo, " ERR_CODE(%u", *err_code)); if (ndo->ndo_vflag) { ND_PRINT((ndo, ":%s", tok2str(pptp_errcode_str, "?", *err_code))); } ND_PRINT((ndo, ")")); } static void pptp_firm_rev_print(netdissect_options *ndo, const uint16_t *firm_rev) { ND_PRINT((ndo, " FIRM_REV(%u)", EXTRACT_16BITS(firm_rev))); } static void pptp_framing_cap_print(netdissect_options *ndo, const uint32_t *framing_cap) { ND_PRINT((ndo, " FRAME_CAP(")); if (EXTRACT_32BITS(framing_cap) & PPTP_FRAMING_CAP_ASYNC_MASK) { ND_PRINT((ndo, "A")); /* Async */ } if (EXTRACT_32BITS(framing_cap) & PPTP_FRAMING_CAP_SYNC_MASK) { ND_PRINT((ndo, "S")); /* Sync */ } ND_PRINT((ndo, ")")); } static const struct tok pptp_ftype_str[] = { { 1, "A" }, /* Async */ { 2, "S" }, /* Sync */ { 3, "E" }, /* Either */ { 0, NULL } }; static void pptp_framing_type_print(netdissect_options *ndo, const uint32_t *framing_type) { ND_PRINT((ndo, " FRAME_TYPE(%s)", tok2str(pptp_ftype_str, "?", EXTRACT_32BITS(framing_type)))); } static void pptp_hostname_print(netdissect_options *ndo, const u_char *hostname) { ND_PRINT((ndo, " HOSTNAME(%.64s)", hostname)); } static void pptp_id_print(netdissect_options *ndo, const uint32_t *id) { ND_PRINT((ndo, " ID(%u)", EXTRACT_32BITS(id))); } static void pptp_max_channel_print(netdissect_options *ndo, const uint16_t *max_channel) { ND_PRINT((ndo, " MAX_CHAN(%u)", EXTRACT_16BITS(max_channel))); } static void pptp_peer_call_id_print(netdissect_options *ndo, const uint16_t *peer_call_id) { ND_PRINT((ndo, " PEER_CALL_ID(%u)", EXTRACT_16BITS(peer_call_id))); } static void pptp_phy_chan_id_print(netdissect_options *ndo, const uint32_t *phy_chan_id) { ND_PRINT((ndo, " PHY_CHAN_ID(%u)", EXTRACT_32BITS(phy_chan_id))); } static void pptp_pkt_proc_delay_print(netdissect_options *ndo, const uint16_t *pkt_proc_delay) { ND_PRINT((ndo, " PROC_DELAY(%u)", EXTRACT_16BITS(pkt_proc_delay))); } static void pptp_proto_ver_print(netdissect_options *ndo, const uint16_t *proto_ver) { ND_PRINT((ndo, " PROTO_VER(%u.%u)", /* Version.Revision */ EXTRACT_16BITS(proto_ver) >> 8, EXTRACT_16BITS(proto_ver) & 0xff)); } static void pptp_recv_winsiz_print(netdissect_options *ndo, const uint16_t *recv_winsiz) { ND_PRINT((ndo, " RECV_WIN(%u)", EXTRACT_16BITS(recv_winsiz))); } static const struct tok pptp_scrrp_str[] = { { 1, "Successful channel establishment" }, { 2, "General error" }, { 3, "Command channel already exists" }, { 4, "Requester is not authorized to establish a command channel" }, { 5, "The protocol version of the requester is not supported" }, { 0, NULL } }; static const struct tok pptp_echorp_str[] = { { 1, "OK" }, { 2, "General Error" }, { 0, NULL } }; static const struct tok pptp_ocrp_str[] = { { 1, "Connected" }, { 2, "General Error" }, { 3, "No Carrier" }, { 4, "Busy" }, { 5, "No Dial Tone" }, { 6, "Time-out" }, { 7, "Do Not Accept" }, { 0, NULL } }; static const struct tok pptp_icrp_str[] = { { 1, "Connect" }, { 2, "General Error" }, { 3, "Do Not Accept" }, { 0, NULL } }; static const struct tok pptp_cdn_str[] = { { 1, "Lost Carrier" }, { 2, "General Error" }, { 3, "Admin Shutdown" }, { 4, "Request" }, { 0, NULL } }; static void pptp_result_code_print(netdissect_options *ndo, const uint8_t *result_code, int ctrl_msg_type) { ND_PRINT((ndo, " RESULT_CODE(%u", *result_code)); if (ndo->ndo_vflag) { const struct tok *dict = ctrl_msg_type == PPTP_CTRL_MSG_TYPE_SCCRP ? pptp_scrrp_str : ctrl_msg_type == PPTP_CTRL_MSG_TYPE_StopCCRP ? pptp_echorp_str : ctrl_msg_type == PPTP_CTRL_MSG_TYPE_ECHORP ? pptp_echorp_str : ctrl_msg_type == PPTP_CTRL_MSG_TYPE_OCRP ? pptp_ocrp_str : ctrl_msg_type == PPTP_CTRL_MSG_TYPE_ICRP ? pptp_icrp_str : ctrl_msg_type == PPTP_CTRL_MSG_TYPE_CDN ? pptp_cdn_str : NULL; /* assertion error */ if (dict != NULL) ND_PRINT((ndo, ":%s", tok2str(dict, "?", *result_code))); } ND_PRINT((ndo, ")")); } static void pptp_subaddr_print(netdissect_options *ndo, const u_char *subaddr) { ND_PRINT((ndo, " SUB_ADDR(%.64s)", subaddr)); } static void pptp_vendor_print(netdissect_options *ndo, const u_char *vendor) { ND_PRINT((ndo, " VENDOR(%.64s)", vendor)); } /************************************/ /* PPTP message print out functions */ /************************************/ static void pptp_sccrq_print(netdissect_options *ndo, const u_char *dat) { const struct pptp_msg_sccrq *ptr = (const struct pptp_msg_sccrq *)dat; ND_TCHECK(ptr->proto_ver); pptp_proto_ver_print(ndo, &ptr->proto_ver); ND_TCHECK(ptr->reserved1); ND_TCHECK(ptr->framing_cap); pptp_framing_cap_print(ndo, &ptr->framing_cap); ND_TCHECK(ptr->bearer_cap); pptp_bearer_cap_print(ndo, &ptr->bearer_cap); ND_TCHECK(ptr->max_channel); pptp_max_channel_print(ndo, &ptr->max_channel); ND_TCHECK(ptr->firm_rev); pptp_firm_rev_print(ndo, &ptr->firm_rev); ND_TCHECK(ptr->hostname); pptp_hostname_print(ndo, &ptr->hostname[0]); ND_TCHECK(ptr->vendor); pptp_vendor_print(ndo, &ptr->vendor[0]); return; trunc: ND_PRINT((ndo, "%s", tstr)); } static void pptp_sccrp_print(netdissect_options *ndo, const u_char *dat) { const struct pptp_msg_sccrp *ptr = (const struct pptp_msg_sccrp *)dat; ND_TCHECK(ptr->proto_ver); pptp_proto_ver_print(ndo, &ptr->proto_ver); ND_TCHECK(ptr->result_code); pptp_result_code_print(ndo, &ptr->result_code, PPTP_CTRL_MSG_TYPE_SCCRP); ND_TCHECK(ptr->err_code); pptp_err_code_print(ndo, &ptr->err_code); ND_TCHECK(ptr->framing_cap); pptp_framing_cap_print(ndo, &ptr->framing_cap); ND_TCHECK(ptr->bearer_cap); pptp_bearer_cap_print(ndo, &ptr->bearer_cap); ND_TCHECK(ptr->max_channel); pptp_max_channel_print(ndo, &ptr->max_channel); ND_TCHECK(ptr->firm_rev); pptp_firm_rev_print(ndo, &ptr->firm_rev); ND_TCHECK(ptr->hostname); pptp_hostname_print(ndo, &ptr->hostname[0]); ND_TCHECK(ptr->vendor); pptp_vendor_print(ndo, &ptr->vendor[0]); return; trunc: ND_PRINT((ndo, "%s", tstr)); } static void pptp_stopccrq_print(netdissect_options *ndo, const u_char *dat) { const struct pptp_msg_stopccrq *ptr = (const struct pptp_msg_stopccrq *)dat; ND_TCHECK(ptr->reason); ND_PRINT((ndo, " REASON(%u", ptr->reason)); if (ndo->ndo_vflag) { switch (ptr->reason) { case 1: ND_PRINT((ndo, ":None")); break; case 2: ND_PRINT((ndo, ":Stop-Protocol")); break; case 3: ND_PRINT((ndo, ":Stop-Local-Shutdown")); break; default: ND_PRINT((ndo, ":?")); break; } } ND_PRINT((ndo, ")")); ND_TCHECK(ptr->reserved1); ND_TCHECK(ptr->reserved2); return; trunc: ND_PRINT((ndo, "%s", tstr)); } static void pptp_stopccrp_print(netdissect_options *ndo, const u_char *dat) { const struct pptp_msg_stopccrp *ptr = (const struct pptp_msg_stopccrp *)dat; ND_TCHECK(ptr->result_code); pptp_result_code_print(ndo, &ptr->result_code, PPTP_CTRL_MSG_TYPE_StopCCRP); ND_TCHECK(ptr->err_code); pptp_err_code_print(ndo, &ptr->err_code); ND_TCHECK(ptr->reserved1); return; trunc: ND_PRINT((ndo, "%s", tstr)); } static void pptp_echorq_print(netdissect_options *ndo, const u_char *dat) { const struct pptp_msg_echorq *ptr = (const struct pptp_msg_echorq *)dat; ND_TCHECK(ptr->id); pptp_id_print(ndo, &ptr->id); return; trunc: ND_PRINT((ndo, "%s", tstr)); } static void pptp_echorp_print(netdissect_options *ndo, const u_char *dat) { const struct pptp_msg_echorp *ptr = (const struct pptp_msg_echorp *)dat; ND_TCHECK(ptr->id); pptp_id_print(ndo, &ptr->id); ND_TCHECK(ptr->result_code); pptp_result_code_print(ndo, &ptr->result_code, PPTP_CTRL_MSG_TYPE_ECHORP); ND_TCHECK(ptr->err_code); pptp_err_code_print(ndo, &ptr->err_code); ND_TCHECK(ptr->reserved1); return; trunc: ND_PRINT((ndo, "%s", tstr)); } static void pptp_ocrq_print(netdissect_options *ndo, const u_char *dat) { const struct pptp_msg_ocrq *ptr = (const struct pptp_msg_ocrq *)dat; ND_TCHECK(ptr->call_id); pptp_call_id_print(ndo, &ptr->call_id); ND_TCHECK(ptr->call_ser); pptp_call_ser_print(ndo, &ptr->call_ser); ND_TCHECK(ptr->min_bps); ND_PRINT((ndo, " MIN_BPS(%u)", EXTRACT_32BITS(&ptr->min_bps))); ND_TCHECK(ptr->max_bps); ND_PRINT((ndo, " MAX_BPS(%u)", EXTRACT_32BITS(&ptr->max_bps))); ND_TCHECK(ptr->bearer_type); pptp_bearer_type_print(ndo, &ptr->bearer_type); ND_TCHECK(ptr->framing_type); pptp_framing_type_print(ndo, &ptr->framing_type); ND_TCHECK(ptr->recv_winsiz); pptp_recv_winsiz_print(ndo, &ptr->recv_winsiz); ND_TCHECK(ptr->pkt_proc_delay); pptp_pkt_proc_delay_print(ndo, &ptr->pkt_proc_delay); ND_TCHECK(ptr->phone_no_len); ND_PRINT((ndo, " PHONE_NO_LEN(%u)", EXTRACT_16BITS(&ptr->phone_no_len))); ND_TCHECK(ptr->reserved1); ND_TCHECK(ptr->phone_no); ND_PRINT((ndo, " PHONE_NO(%.64s)", ptr->phone_no)); ND_TCHECK(ptr->subaddr); pptp_subaddr_print(ndo, &ptr->subaddr[0]); return; trunc: ND_PRINT((ndo, "%s", tstr)); } static void pptp_ocrp_print(netdissect_options *ndo, const u_char *dat) { const struct pptp_msg_ocrp *ptr = (const struct pptp_msg_ocrp *)dat; ND_TCHECK(ptr->call_id); pptp_call_id_print(ndo, &ptr->call_id); ND_TCHECK(ptr->peer_call_id); pptp_peer_call_id_print(ndo, &ptr->peer_call_id); ND_TCHECK(ptr->result_code); pptp_result_code_print(ndo, &ptr->result_code, PPTP_CTRL_MSG_TYPE_OCRP); ND_TCHECK(ptr->err_code); pptp_err_code_print(ndo, &ptr->err_code); ND_TCHECK(ptr->cause_code); pptp_cause_code_print(ndo, &ptr->cause_code); ND_TCHECK(ptr->conn_speed); pptp_conn_speed_print(ndo, &ptr->conn_speed); ND_TCHECK(ptr->recv_winsiz); pptp_recv_winsiz_print(ndo, &ptr->recv_winsiz); ND_TCHECK(ptr->pkt_proc_delay); pptp_pkt_proc_delay_print(ndo, &ptr->pkt_proc_delay); ND_TCHECK(ptr->phy_chan_id); pptp_phy_chan_id_print(ndo, &ptr->phy_chan_id); return; trunc: ND_PRINT((ndo, "%s", tstr)); } static void pptp_icrq_print(netdissect_options *ndo, const u_char *dat) { const struct pptp_msg_icrq *ptr = (const struct pptp_msg_icrq *)dat; ND_TCHECK(ptr->call_id); pptp_call_id_print(ndo, &ptr->call_id); ND_TCHECK(ptr->call_ser); pptp_call_ser_print(ndo, &ptr->call_ser); ND_TCHECK(ptr->bearer_type); pptp_bearer_type_print(ndo, &ptr->bearer_type); ND_TCHECK(ptr->phy_chan_id); pptp_phy_chan_id_print(ndo, &ptr->phy_chan_id); ND_TCHECK(ptr->dialed_no_len); ND_PRINT((ndo, " DIALED_NO_LEN(%u)", EXTRACT_16BITS(&ptr->dialed_no_len))); ND_TCHECK(ptr->dialing_no_len); ND_PRINT((ndo, " DIALING_NO_LEN(%u)", EXTRACT_16BITS(&ptr->dialing_no_len))); ND_TCHECK(ptr->dialed_no); ND_PRINT((ndo, " DIALED_NO(%.64s)", ptr->dialed_no)); ND_TCHECK(ptr->dialing_no); ND_PRINT((ndo, " DIALING_NO(%.64s)", ptr->dialing_no)); ND_TCHECK(ptr->subaddr); pptp_subaddr_print(ndo, &ptr->subaddr[0]); return; trunc: ND_PRINT((ndo, "%s", tstr)); } static void pptp_icrp_print(netdissect_options *ndo, const u_char *dat) { const struct pptp_msg_icrp *ptr = (const struct pptp_msg_icrp *)dat; ND_TCHECK(ptr->call_id); pptp_call_id_print(ndo, &ptr->call_id); ND_TCHECK(ptr->peer_call_id); pptp_peer_call_id_print(ndo, &ptr->peer_call_id); ND_TCHECK(ptr->result_code); pptp_result_code_print(ndo, &ptr->result_code, PPTP_CTRL_MSG_TYPE_ICRP); ND_TCHECK(ptr->err_code); pptp_err_code_print(ndo, &ptr->err_code); ND_TCHECK(ptr->recv_winsiz); pptp_recv_winsiz_print(ndo, &ptr->recv_winsiz); ND_TCHECK(ptr->pkt_proc_delay); pptp_pkt_proc_delay_print(ndo, &ptr->pkt_proc_delay); ND_TCHECK(ptr->reserved1); return; trunc: ND_PRINT((ndo, "%s", tstr)); } static void pptp_iccn_print(netdissect_options *ndo, const u_char *dat) { const struct pptp_msg_iccn *ptr = (const struct pptp_msg_iccn *)dat; ND_TCHECK(ptr->peer_call_id); pptp_peer_call_id_print(ndo, &ptr->peer_call_id); ND_TCHECK(ptr->reserved1); ND_TCHECK(ptr->conn_speed); pptp_conn_speed_print(ndo, &ptr->conn_speed); ND_TCHECK(ptr->recv_winsiz); pptp_recv_winsiz_print(ndo, &ptr->recv_winsiz); ND_TCHECK(ptr->pkt_proc_delay); pptp_pkt_proc_delay_print(ndo, &ptr->pkt_proc_delay); ND_TCHECK(ptr->framing_type); pptp_framing_type_print(ndo, &ptr->framing_type); return; trunc: ND_PRINT((ndo, "%s", tstr)); } static void pptp_ccrq_print(netdissect_options *ndo, const u_char *dat) { const struct pptp_msg_ccrq *ptr = (const struct pptp_msg_ccrq *)dat; ND_TCHECK(ptr->call_id); pptp_call_id_print(ndo, &ptr->call_id); ND_TCHECK(ptr->reserved1); return; trunc: ND_PRINT((ndo, "%s", tstr)); } static void pptp_cdn_print(netdissect_options *ndo, const u_char *dat) { const struct pptp_msg_cdn *ptr = (const struct pptp_msg_cdn *)dat; ND_TCHECK(ptr->call_id); pptp_call_id_print(ndo, &ptr->call_id); ND_TCHECK(ptr->result_code); pptp_result_code_print(ndo, &ptr->result_code, PPTP_CTRL_MSG_TYPE_CDN); ND_TCHECK(ptr->err_code); pptp_err_code_print(ndo, &ptr->err_code); ND_TCHECK(ptr->cause_code); pptp_cause_code_print(ndo, &ptr->cause_code); ND_TCHECK(ptr->reserved1); ND_TCHECK(ptr->call_stats); ND_PRINT((ndo, " CALL_STATS(%.128s)", ptr->call_stats)); return; trunc: ND_PRINT((ndo, "%s", tstr)); } static void pptp_wen_print(netdissect_options *ndo, const u_char *dat) { const struct pptp_msg_wen *ptr = (const struct pptp_msg_wen *)dat; ND_TCHECK(ptr->peer_call_id); pptp_peer_call_id_print(ndo, &ptr->peer_call_id); ND_TCHECK(ptr->reserved1); ND_TCHECK(ptr->crc_err); ND_PRINT((ndo, " CRC_ERR(%u)", EXTRACT_32BITS(&ptr->crc_err))); ND_TCHECK(ptr->framing_err); ND_PRINT((ndo, " FRAMING_ERR(%u)", EXTRACT_32BITS(&ptr->framing_err))); ND_TCHECK(ptr->hardware_overrun); ND_PRINT((ndo, " HARDWARE_OVERRUN(%u)", EXTRACT_32BITS(&ptr->hardware_overrun))); ND_TCHECK(ptr->buffer_overrun); ND_PRINT((ndo, " BUFFER_OVERRUN(%u)", EXTRACT_32BITS(&ptr->buffer_overrun))); ND_TCHECK(ptr->timeout_err); ND_PRINT((ndo, " TIMEOUT_ERR(%u)", EXTRACT_32BITS(&ptr->timeout_err))); ND_TCHECK(ptr->align_err); ND_PRINT((ndo, " ALIGN_ERR(%u)", EXTRACT_32BITS(&ptr->align_err))); return; trunc: ND_PRINT((ndo, "%s", tstr)); } static void pptp_sli_print(netdissect_options *ndo, const u_char *dat) { const struct pptp_msg_sli *ptr = (const struct pptp_msg_sli *)dat; ND_TCHECK(ptr->peer_call_id); pptp_peer_call_id_print(ndo, &ptr->peer_call_id); ND_TCHECK(ptr->reserved1); ND_TCHECK(ptr->send_accm); ND_PRINT((ndo, " SEND_ACCM(0x%08x)", EXTRACT_32BITS(&ptr->send_accm))); ND_TCHECK(ptr->recv_accm); ND_PRINT((ndo, " RECV_ACCM(0x%08x)", EXTRACT_32BITS(&ptr->recv_accm))); return; trunc: ND_PRINT((ndo, "%s", tstr)); } void pptp_print(netdissect_options *ndo, const u_char *dat) { const struct pptp_hdr *hdr; uint32_t mc; uint16_t ctrl_msg_type; ND_PRINT((ndo, ": pptp")); hdr = (const struct pptp_hdr *)dat; ND_TCHECK(hdr->length); if (ndo->ndo_vflag) { ND_PRINT((ndo, " Length=%u", EXTRACT_16BITS(&hdr->length))); } ND_TCHECK(hdr->msg_type); if (ndo->ndo_vflag) { switch(EXTRACT_16BITS(&hdr->msg_type)) { case PPTP_MSG_TYPE_CTRL: ND_PRINT((ndo, " CTRL-MSG")); break; case PPTP_MSG_TYPE_MGMT: ND_PRINT((ndo, " MGMT-MSG")); break; default: ND_PRINT((ndo, " UNKNOWN-MSG-TYPE")); break; } } ND_TCHECK(hdr->magic_cookie); mc = EXTRACT_32BITS(&hdr->magic_cookie); if (mc != PPTP_MAGIC_COOKIE) { ND_PRINT((ndo, " UNEXPECTED Magic-Cookie!!(%08x)", mc)); } if (ndo->ndo_vflag || mc != PPTP_MAGIC_COOKIE) { ND_PRINT((ndo, " Magic-Cookie=%08x", mc)); } ND_TCHECK(hdr->ctrl_msg_type); ctrl_msg_type = EXTRACT_16BITS(&hdr->ctrl_msg_type); if (ctrl_msg_type < PPTP_MAX_MSGTYPE_INDEX) { ND_PRINT((ndo, " CTRL_MSGTYPE=%s", pptp_message_type_string[ctrl_msg_type])); } else { ND_PRINT((ndo, " UNKNOWN_CTRL_MSGTYPE(%u)", ctrl_msg_type)); } ND_TCHECK(hdr->reserved0); dat += 12; switch(ctrl_msg_type) { case PPTP_CTRL_MSG_TYPE_SCCRQ: pptp_sccrq_print(ndo, dat); break; case PPTP_CTRL_MSG_TYPE_SCCRP: pptp_sccrp_print(ndo, dat); break; case PPTP_CTRL_MSG_TYPE_StopCCRQ: pptp_stopccrq_print(ndo, dat); break; case PPTP_CTRL_MSG_TYPE_StopCCRP: pptp_stopccrp_print(ndo, dat); break; case PPTP_CTRL_MSG_TYPE_ECHORQ: pptp_echorq_print(ndo, dat); break; case PPTP_CTRL_MSG_TYPE_ECHORP: pptp_echorp_print(ndo, dat); break; case PPTP_CTRL_MSG_TYPE_OCRQ: pptp_ocrq_print(ndo, dat); break; case PPTP_CTRL_MSG_TYPE_OCRP: pptp_ocrp_print(ndo, dat); break; case PPTP_CTRL_MSG_TYPE_ICRQ: pptp_icrq_print(ndo, dat); break; case PPTP_CTRL_MSG_TYPE_ICRP: pptp_icrp_print(ndo, dat); break; case PPTP_CTRL_MSG_TYPE_ICCN: pptp_iccn_print(ndo, dat); break; case PPTP_CTRL_MSG_TYPE_CCRQ: pptp_ccrq_print(ndo, dat); break; case PPTP_CTRL_MSG_TYPE_CDN: pptp_cdn_print(ndo, dat); break; case PPTP_CTRL_MSG_TYPE_WEN: pptp_wen_print(ndo, dat); break; case PPTP_CTRL_MSG_TYPE_SLI: pptp_sli_print(ndo, dat); break; default: /* do nothing */ break; } return; trunc: ND_PRINT((ndo, "%s", tstr)); } tcpdump-4.9.3/send-ack.awk0000644000026300017510000000307613544412561013532 0ustar mcrmcrBEGIN { # we need the number of bytes in a packet to do the output # in packet numbers rather than byte numbers. if (packetsize <= 0) packetsize = 512 expectNext = 1 lastwin = -1 } { # convert tcp trace to send/ack form. n = split ($1,t,":") tim = t[1]*3600 + t[2]*60 + t[3] if (NR <= 1) { tzero = tim ltim = tim OFS = "\t" } if ($6 != "ack") { # we have a data packet record: # ignore guys with syn, fin or reset 'cause we # can't handle their sequence numbers. Try to # detect and add a flag character for 'anomalies': # * -> re-sent packet # - -> packet after hole (missing packet(s)) # # -> odd size packet if ($5 !~ /[SFR]/) { i = index($6,":") j = index($6,"(") strtSeq = substr($6,1,i-1) endSeq = substr($6,i+1,j-i-1) len = endSeq - strtSeq id = endSeq if (! timeOf[id]) timeOf[id] = tim if (endSeq - expectNext < 0) flag = "*" else { if (strtSeq - expectNext > 0) flag = "-" else if (len != packetsize) flag = "#" else flag = " " expectNext = endSeq } printf "%7.2f\t%7.2f\t%s send %s %d", tim-tzero, tim-ltim,\ flag, $5, strtSeq if (++timesSent[id] > 1) printf " (%.2f) [%d]", tim - timeOf[id], timesSent[id] if (len != packetsize) printf " <%d>", len } } else { id = $7 printf "%7.2f\t%7.2f\t%s ack %s %d", tim-tzero, tim-ltim,\ flag, $5, id if ($9 != lastwin) { printf " win %d", $9 lastwin = $9 } printf " (%.2f)", tim - timeOf[id] if (++timesAcked[id] > 1) printf " [%d]", timesAcked[id] } printf "\n" ltim = tim } tcpdump-4.9.3/print-olsr.c0000644000026300017510000005665213544412561013626 0ustar mcrmcr/* * Copyright (c) 1998-2007 The TCPDUMP project * Copyright (c) 2009 Florian Forster * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code * distributions retain the above copyright notice and this paragraph * in its entirety, and (2) distributions including binary code include * the above copyright notice and this paragraph in its entirety in * the documentation or other materials provided with the distribution. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. * * Original code by Hannes Gredler * IPv6 additions by Florian Forster */ /* \summary: Optimized Link State Routing Protocol (OLSR) printer */ /* specification: RFC 3626 */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #include "addrtoname.h" #include "extract.h" /* * RFC 3626 common header * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Packet Length | Packet Sequence Number | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Message Type | Vtime | Message Size | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Originator Address | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Time To Live | Hop Count | Message Sequence Number | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | * : MESSAGE : * | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Message Type | Vtime | Message Size | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Originator Address | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Time To Live | Hop Count | Message Sequence Number | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | * : MESSAGE : * | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * : : */ struct olsr_common { uint8_t packet_len[2]; uint8_t packet_seq[2]; }; #define OLSR_HELLO_MSG 1 /* rfc3626 */ #define OLSR_TC_MSG 2 /* rfc3626 */ #define OLSR_MID_MSG 3 /* rfc3626 */ #define OLSR_HNA_MSG 4 /* rfc3626 */ #define OLSR_POWERINFO_MSG 128 #define OLSR_NAMESERVICE_MSG 130 #define OLSR_HELLO_LQ_MSG 201 /* LQ extensions olsr.org */ #define OLSR_TC_LQ_MSG 202 /* LQ extensions olsr.org */ static const struct tok olsr_msg_values[] = { { OLSR_HELLO_MSG, "Hello" }, { OLSR_TC_MSG, "TC" }, { OLSR_MID_MSG, "MID" }, { OLSR_HNA_MSG, "HNA" }, { OLSR_POWERINFO_MSG, "Powerinfo" }, { OLSR_NAMESERVICE_MSG, "Nameservice" }, { OLSR_HELLO_LQ_MSG, "Hello-LQ" }, { OLSR_TC_LQ_MSG, "TC-LQ" }, { 0, NULL} }; struct olsr_msg4 { uint8_t msg_type; uint8_t vtime; uint8_t msg_len[2]; uint8_t originator[4]; uint8_t ttl; uint8_t hopcount; uint8_t msg_seq[2]; }; struct olsr_msg6 { uint8_t msg_type; uint8_t vtime; uint8_t msg_len[2]; uint8_t originator[16]; uint8_t ttl; uint8_t hopcount; uint8_t msg_seq[2]; }; struct olsr_hello { uint8_t res[2]; uint8_t htime; uint8_t will; }; struct olsr_hello_link { uint8_t link_code; uint8_t res; uint8_t len[2]; }; struct olsr_tc { uint8_t ans_seq[2]; uint8_t res[2]; }; struct olsr_hna4 { uint8_t network[4]; uint8_t mask[4]; }; struct olsr_hna6 { uint8_t network[16]; uint8_t mask[16]; }; /** gateway HNA flags */ enum gateway_hna_flags { GW_HNA_FLAG_LINKSPEED = 1 << 0, GW_HNA_FLAG_IPV4 = 1 << 1, GW_HNA_FLAG_IPV4_NAT = 1 << 2, GW_HNA_FLAG_IPV6 = 1 << 3, GW_HNA_FLAG_IPV6PREFIX = 1 << 4 }; /** gateway HNA field byte offsets in the netmask field of the HNA */ enum gateway_hna_fields { GW_HNA_PAD = 0, GW_HNA_FLAGS = 1, GW_HNA_UPLINK = 2, GW_HNA_DOWNLINK = 3, GW_HNA_V6PREFIXLEN = 4, GW_HNA_V6PREFIX = 5 }; #define OLSR_EXTRACT_LINK_TYPE(link_code) (link_code & 0x3) #define OLSR_EXTRACT_NEIGHBOR_TYPE(link_code) (link_code >> 2) static const struct tok olsr_link_type_values[] = { { 0, "Unspecified" }, { 1, "Asymmetric" }, { 2, "Symmetric" }, { 3, "Lost" }, { 0, NULL} }; static const struct tok olsr_neighbor_type_values[] = { { 0, "Not-Neighbor" }, { 1, "Symmetric" }, { 2, "Symmetric-MPR" }, { 0, NULL} }; struct olsr_lq_neighbor4 { uint8_t neighbor[4]; uint8_t link_quality; uint8_t neighbor_link_quality; uint8_t res[2]; }; struct olsr_lq_neighbor6 { uint8_t neighbor[16]; uint8_t link_quality; uint8_t neighbor_link_quality; uint8_t res[2]; }; #define MAX_SMARTGW_SPEED 320000000 /** * Convert an encoded 1 byte transport value (5 bits mantissa, 3 bits exponent) * to an uplink/downlink speed value * * @param value the encoded 1 byte transport value * @return the uplink/downlink speed value (in kbit/s) */ static uint32_t deserialize_gw_speed(uint8_t value) { uint32_t speed; uint32_t exp; if (!value) { return 0; } if (value == UINT8_MAX) { /* maximum value: also return maximum value */ return MAX_SMARTGW_SPEED; } speed = (value >> 3) + 1; exp = value & 7; while (exp-- > 0) { speed *= 10; } return speed; } /* * macro to convert the 8-bit mantissa/exponent to a double float * taken from olsr.org. */ #define VTIME_SCALE_FACTOR 0.0625 #define ME_TO_DOUBLE(me) \ (double)(VTIME_SCALE_FACTOR*(1+(double)(me>>4)/16)*(double)(1<<(me&0x0F))) /* * print a neighbor list with LQ extensions. */ static int olsr_print_lq_neighbor4(netdissect_options *ndo, const u_char *msg_data, u_int hello_len) { const struct olsr_lq_neighbor4 *lq_neighbor; while (hello_len >= sizeof(struct olsr_lq_neighbor4)) { lq_neighbor = (const struct olsr_lq_neighbor4 *)msg_data; if (!ND_TTEST(*lq_neighbor)) return (-1); ND_PRINT((ndo, "\n\t neighbor %s, link-quality %.2f%%" ", neighbor-link-quality %.2f%%", ipaddr_string(ndo, lq_neighbor->neighbor), ((double)lq_neighbor->link_quality/2.55), ((double)lq_neighbor->neighbor_link_quality/2.55))); msg_data += sizeof(struct olsr_lq_neighbor4); hello_len -= sizeof(struct olsr_lq_neighbor4); } return (0); } static int olsr_print_lq_neighbor6(netdissect_options *ndo, const u_char *msg_data, u_int hello_len) { const struct olsr_lq_neighbor6 *lq_neighbor; while (hello_len >= sizeof(struct olsr_lq_neighbor6)) { lq_neighbor = (const struct olsr_lq_neighbor6 *)msg_data; if (!ND_TTEST(*lq_neighbor)) return (-1); ND_PRINT((ndo, "\n\t neighbor %s, link-quality %.2f%%" ", neighbor-link-quality %.2f%%", ip6addr_string(ndo, lq_neighbor->neighbor), ((double)lq_neighbor->link_quality/2.55), ((double)lq_neighbor->neighbor_link_quality/2.55))); msg_data += sizeof(struct olsr_lq_neighbor6); hello_len -= sizeof(struct olsr_lq_neighbor6); } return (0); } /* * print a neighbor list. */ static int olsr_print_neighbor(netdissect_options *ndo, const u_char *msg_data, u_int hello_len) { int neighbor; ND_PRINT((ndo, "\n\t neighbor\n\t\t")); neighbor = 1; while (hello_len >= sizeof(struct in_addr)) { if (!ND_TTEST2(*msg_data, sizeof(struct in_addr))) return (-1); /* print 4 neighbors per line */ ND_PRINT((ndo, "%s%s", ipaddr_string(ndo, msg_data), neighbor % 4 == 0 ? "\n\t\t" : " ")); msg_data += sizeof(struct in_addr); hello_len -= sizeof(struct in_addr); } return (0); } void olsr_print(netdissect_options *ndo, const u_char *pptr, u_int length, int is_ipv6) { union { const struct olsr_common *common; const struct olsr_msg4 *msg4; const struct olsr_msg6 *msg6; const struct olsr_hello *hello; const struct olsr_hello_link *hello_link; const struct olsr_tc *tc; const struct olsr_hna4 *hna; } ptr; u_int msg_type, msg_len, msg_tlen, hello_len; uint16_t name_entry_type, name_entry_len; u_int name_entry_padding; uint8_t link_type, neighbor_type; const u_char *tptr, *msg_data; tptr = pptr; if (length < sizeof(struct olsr_common)) { goto trunc; } ND_TCHECK2(*tptr, sizeof(struct olsr_common)); ptr.common = (const struct olsr_common *)tptr; length = min(length, EXTRACT_16BITS(ptr.common->packet_len)); ND_PRINT((ndo, "OLSRv%i, seq 0x%04x, length %u", (is_ipv6 == 0) ? 4 : 6, EXTRACT_16BITS(ptr.common->packet_seq), length)); tptr += sizeof(struct olsr_common); /* * In non-verbose mode, just print version. */ if (ndo->ndo_vflag < 1) { return; } while (tptr < (pptr+length)) { union { const struct olsr_msg4 *v4; const struct olsr_msg6 *v6; } msgptr; int msg_len_valid = 0; if (is_ipv6) { ND_TCHECK2(*tptr, sizeof(struct olsr_msg6)); msgptr.v6 = (const struct olsr_msg6 *) tptr; msg_type = msgptr.v6->msg_type; msg_len = EXTRACT_16BITS(msgptr.v6->msg_len); if ((msg_len >= sizeof (struct olsr_msg6)) && (msg_len <= length)) msg_len_valid = 1; /* infinite loop check */ if (msg_type == 0 || msg_len == 0) { return; } ND_PRINT((ndo, "\n\t%s Message (%#04x), originator %s, ttl %u, hop %u" "\n\t vtime %.3fs, msg-seq 0x%04x, length %u%s", tok2str(olsr_msg_values, "Unknown", msg_type), msg_type, ip6addr_string(ndo, msgptr.v6->originator), msgptr.v6->ttl, msgptr.v6->hopcount, ME_TO_DOUBLE(msgptr.v6->vtime), EXTRACT_16BITS(msgptr.v6->msg_seq), msg_len, (msg_len_valid == 0) ? " (invalid)" : "")); if (!msg_len_valid) { return; } msg_tlen = msg_len - sizeof(struct olsr_msg6); msg_data = tptr + sizeof(struct olsr_msg6); } else /* (!is_ipv6) */ { ND_TCHECK2(*tptr, sizeof(struct olsr_msg4)); msgptr.v4 = (const struct olsr_msg4 *) tptr; msg_type = msgptr.v4->msg_type; msg_len = EXTRACT_16BITS(msgptr.v4->msg_len); if ((msg_len >= sizeof (struct olsr_msg4)) && (msg_len <= length)) msg_len_valid = 1; /* infinite loop check */ if (msg_type == 0 || msg_len == 0) { return; } ND_PRINT((ndo, "\n\t%s Message (%#04x), originator %s, ttl %u, hop %u" "\n\t vtime %.3fs, msg-seq 0x%04x, length %u%s", tok2str(olsr_msg_values, "Unknown", msg_type), msg_type, ipaddr_string(ndo, msgptr.v4->originator), msgptr.v4->ttl, msgptr.v4->hopcount, ME_TO_DOUBLE(msgptr.v4->vtime), EXTRACT_16BITS(msgptr.v4->msg_seq), msg_len, (msg_len_valid == 0) ? " (invalid)" : "")); if (!msg_len_valid) { return; } msg_tlen = msg_len - sizeof(struct olsr_msg4); msg_data = tptr + sizeof(struct olsr_msg4); } switch (msg_type) { case OLSR_HELLO_MSG: case OLSR_HELLO_LQ_MSG: if (msg_tlen < sizeof(struct olsr_hello)) goto trunc; ND_TCHECK2(*msg_data, sizeof(struct olsr_hello)); ptr.hello = (const struct olsr_hello *)msg_data; ND_PRINT((ndo, "\n\t hello-time %.3fs, MPR willingness %u", ME_TO_DOUBLE(ptr.hello->htime), ptr.hello->will)); msg_data += sizeof(struct olsr_hello); msg_tlen -= sizeof(struct olsr_hello); while (msg_tlen >= sizeof(struct olsr_hello_link)) { int hello_len_valid = 0; /* * link-type. */ ND_TCHECK2(*msg_data, sizeof(struct olsr_hello_link)); ptr.hello_link = (const struct olsr_hello_link *)msg_data; hello_len = EXTRACT_16BITS(ptr.hello_link->len); link_type = OLSR_EXTRACT_LINK_TYPE(ptr.hello_link->link_code); neighbor_type = OLSR_EXTRACT_NEIGHBOR_TYPE(ptr.hello_link->link_code); if ((hello_len <= msg_tlen) && (hello_len >= sizeof(struct olsr_hello_link))) hello_len_valid = 1; ND_PRINT((ndo, "\n\t link-type %s, neighbor-type %s, len %u%s", tok2str(olsr_link_type_values, "Unknown", link_type), tok2str(olsr_neighbor_type_values, "Unknown", neighbor_type), hello_len, (hello_len_valid == 0) ? " (invalid)" : "")); if (hello_len_valid == 0) break; msg_data += sizeof(struct olsr_hello_link); msg_tlen -= sizeof(struct olsr_hello_link); hello_len -= sizeof(struct olsr_hello_link); ND_TCHECK2(*msg_data, hello_len); if (msg_type == OLSR_HELLO_MSG) { if (olsr_print_neighbor(ndo, msg_data, hello_len) == -1) goto trunc; } else { if (is_ipv6) { if (olsr_print_lq_neighbor6(ndo, msg_data, hello_len) == -1) goto trunc; } else { if (olsr_print_lq_neighbor4(ndo, msg_data, hello_len) == -1) goto trunc; } } msg_data += hello_len; msg_tlen -= hello_len; } break; case OLSR_TC_MSG: case OLSR_TC_LQ_MSG: if (msg_tlen < sizeof(struct olsr_tc)) goto trunc; ND_TCHECK2(*msg_data, sizeof(struct olsr_tc)); ptr.tc = (const struct olsr_tc *)msg_data; ND_PRINT((ndo, "\n\t advertised neighbor seq 0x%04x", EXTRACT_16BITS(ptr.tc->ans_seq))); msg_data += sizeof(struct olsr_tc); msg_tlen -= sizeof(struct olsr_tc); if (msg_type == OLSR_TC_MSG) { if (olsr_print_neighbor(ndo, msg_data, msg_tlen) == -1) goto trunc; } else { if (is_ipv6) { if (olsr_print_lq_neighbor6(ndo, msg_data, msg_tlen) == -1) goto trunc; } else { if (olsr_print_lq_neighbor4(ndo, msg_data, msg_tlen) == -1) goto trunc; } } break; case OLSR_MID_MSG: { size_t addr_size = sizeof(struct in_addr); if (is_ipv6) addr_size = sizeof(struct in6_addr); while (msg_tlen >= addr_size) { ND_TCHECK2(*msg_data, addr_size); ND_PRINT((ndo, "\n\t interface address %s", is_ipv6 ? ip6addr_string(ndo, msg_data) : ipaddr_string(ndo, msg_data))); msg_data += addr_size; msg_tlen -= addr_size; } break; } case OLSR_HNA_MSG: if (is_ipv6) { int i = 0; ND_PRINT((ndo, "\n\t Advertised networks (total %u)", (unsigned int) (msg_tlen / sizeof(struct olsr_hna6)))); while (msg_tlen >= sizeof(struct olsr_hna6)) { const struct olsr_hna6 *hna6; ND_TCHECK2(*msg_data, sizeof(struct olsr_hna6)); hna6 = (const struct olsr_hna6 *)msg_data; ND_PRINT((ndo, "\n\t #%i: %s/%u", i, ip6addr_string(ndo, hna6->network), mask62plen (hna6->mask))); msg_data += sizeof(struct olsr_hna6); msg_tlen -= sizeof(struct olsr_hna6); } } else { int col = 0; ND_PRINT((ndo, "\n\t Advertised networks (total %u)", (unsigned int) (msg_tlen / sizeof(struct olsr_hna4)))); while (msg_tlen >= sizeof(struct olsr_hna4)) { ND_TCHECK2(*msg_data, sizeof(struct olsr_hna4)); ptr.hna = (const struct olsr_hna4 *)msg_data; /* print 4 prefixes per line */ if (!ptr.hna->network[0] && !ptr.hna->network[1] && !ptr.hna->network[2] && !ptr.hna->network[3] && !ptr.hna->mask[GW_HNA_PAD] && ptr.hna->mask[GW_HNA_FLAGS]) { /* smart gateway */ ND_PRINT((ndo, "%sSmart-Gateway:%s%s%s%s%s %u/%u", col == 0 ? "\n\t " : ", ", /* indent */ /* sgw */ /* LINKSPEED */ (ptr.hna->mask[GW_HNA_FLAGS] & GW_HNA_FLAG_LINKSPEED) ? " LINKSPEED" : "", /* IPV4 */ (ptr.hna->mask[GW_HNA_FLAGS] & GW_HNA_FLAG_IPV4) ? " IPV4" : "", /* IPV4-NAT */ (ptr.hna->mask[GW_HNA_FLAGS] & GW_HNA_FLAG_IPV4_NAT) ? " IPV4-NAT" : "", /* IPV6 */ (ptr.hna->mask[GW_HNA_FLAGS] & GW_HNA_FLAG_IPV6) ? " IPV6" : "", /* IPv6PREFIX */ (ptr.hna->mask[GW_HNA_FLAGS] & GW_HNA_FLAG_IPV6PREFIX) ? " IPv6-PREFIX" : "", /* uplink */ (ptr.hna->mask[GW_HNA_FLAGS] & GW_HNA_FLAG_LINKSPEED) ? deserialize_gw_speed(ptr.hna->mask[GW_HNA_UPLINK]) : 0, /* downlink */ (ptr.hna->mask[GW_HNA_FLAGS] & GW_HNA_FLAG_LINKSPEED) ? deserialize_gw_speed(ptr.hna->mask[GW_HNA_DOWNLINK]) : 0 )); } else { /* normal route */ ND_PRINT((ndo, "%s%s/%u", col == 0 ? "\n\t " : ", ", ipaddr_string(ndo, ptr.hna->network), mask2plen(EXTRACT_32BITS(ptr.hna->mask)))); } msg_data += sizeof(struct olsr_hna4); msg_tlen -= sizeof(struct olsr_hna4); col = (col + 1) % 4; } } break; case OLSR_NAMESERVICE_MSG: { u_int name_entries; u_int addr_size; int name_entries_valid; u_int i; if (msg_tlen < 4) goto trunc; ND_TCHECK2(*msg_data, 4); name_entries = EXTRACT_16BITS(msg_data+2); addr_size = 4; if (is_ipv6) addr_size = 16; name_entries_valid = 0; if ((name_entries > 0) && ((name_entries * (4 + addr_size)) <= msg_tlen)) name_entries_valid = 1; ND_PRINT((ndo, "\n\t Version %u, Entries %u%s", EXTRACT_16BITS(msg_data), name_entries, (name_entries_valid == 0) ? " (invalid)" : "")); if (name_entries_valid == 0) break; msg_data += 4; msg_tlen -= 4; for (i = 0; i < name_entries; i++) { int name_entry_len_valid = 0; if (msg_tlen < 4) break; ND_TCHECK2(*msg_data, 4); name_entry_type = EXTRACT_16BITS(msg_data); name_entry_len = EXTRACT_16BITS(msg_data+2); msg_data += 4; msg_tlen -= 4; if ((name_entry_len > 0) && ((addr_size + name_entry_len) <= msg_tlen)) name_entry_len_valid = 1; ND_PRINT((ndo, "\n\t #%u: type %#06x, length %u%s", (unsigned int) i, name_entry_type, name_entry_len, (name_entry_len_valid == 0) ? " (invalid)" : "")); if (name_entry_len_valid == 0) break; /* 32-bit alignment */ name_entry_padding = 0; if (name_entry_len%4 != 0) name_entry_padding = 4-(name_entry_len%4); if (msg_tlen < addr_size + name_entry_len + name_entry_padding) goto trunc; ND_TCHECK2(*msg_data, addr_size + name_entry_len + name_entry_padding); if (is_ipv6) ND_PRINT((ndo, ", address %s, name \"", ip6addr_string(ndo, msg_data))); else ND_PRINT((ndo, ", address %s, name \"", ipaddr_string(ndo, msg_data))); (void)fn_printn(ndo, msg_data + addr_size, name_entry_len, NULL); ND_PRINT((ndo, "\"")); msg_data += addr_size + name_entry_len + name_entry_padding; msg_tlen -= addr_size + name_entry_len + name_entry_padding; } /* for (i = 0; i < name_entries; i++) */ break; } /* case OLSR_NAMESERVICE_MSG */ /* * FIXME those are the defined messages that lack a decoder * you are welcome to contribute code ;-) */ case OLSR_POWERINFO_MSG: default: print_unknown_data(ndo, msg_data, "\n\t ", msg_tlen); break; } /* switch (msg_type) */ tptr += msg_len; } /* while (tptr < (pptr+length)) */ return; trunc: ND_PRINT((ndo, "[|olsr]")); } /* * Local Variables: * c-style: whitesmith * c-basic-offset: 4 * End: */ tcpdump-4.9.3/print-bt.c0000644000026300017510000000432513544412561013242 0ustar mcrmcr/* * Copyright (c) 2007 * paolo.abeni@email.it All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by Paolo Abeni.'' * The name of author may not be used to endorse or promote products derived * from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* \summary: Bluetooth printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #include "extract.h" #if defined(DLT_BLUETOOTH_HCI_H4_WITH_PHDR) && defined(HAVE_PCAP_BLUETOOTH_H) #include #define BT_HDRLEN sizeof(pcap_bluetooth_h4_header) /* * This is the top level routine of the printer. 'p' points * to the bluetooth header of the packet, 'h->ts' is the timestamp, * 'h->len' is the length of the packet off the wire, and 'h->caplen' * is the number of bytes actually captured. */ u_int bt_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) { u_int length = h->len; u_int caplen = h->caplen; const pcap_bluetooth_h4_header* hdr = (const pcap_bluetooth_h4_header*)p; if (caplen < BT_HDRLEN) { ND_PRINT((ndo, "[|bt]")); return (BT_HDRLEN); } caplen -= BT_HDRLEN; length -= BT_HDRLEN; p += BT_HDRLEN; if (ndo->ndo_eflag) ND_PRINT((ndo, "hci length %d, direction %s, ", length, (EXTRACT_32BITS(&hdr->direction)&0x1)?"in":"out")); if (!ndo->ndo_suppress_default_print) ND_DEFAULTPRINT(p, caplen); return (BT_HDRLEN); } #endif /* * Local Variables: * c-style: whitesmith * c-basic-offset: 8 * End: */ tcpdump-4.9.3/print-openflow.c0000644000026300017510000001142313544412724014464 0ustar mcrmcr/* * This module implements printing of the very basic (version-independent) * OpenFlow header and iteration over OpenFlow messages. It is intended for * dispatching of version-specific OpenFlow message decoding. * * * Copyright (c) 2013 The TCPDUMP project * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /* \summary: version-independent OpenFlow printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #include "extract.h" #include "openflow.h" #include "oui.h" static const char tstr[] = " [|openflow]"; #define OF_VER_1_0 0x01 const struct tok onf_exp_str[] = { { ONF_EXP_ONF, "ONF Extensions" }, { ONF_EXP_BUTE, "Budapest University of Technology and Economics" }, { ONF_EXP_NOVIFLOW, "NoviFlow" }, { ONF_EXP_L3, "L3+ Extensions, Vendor Neutral" }, { ONF_EXP_L4L7, "L4-L7 Extensions" }, { ONF_EXP_WMOB, "Wireless and Mobility Extensions" }, { ONF_EXP_FABS, "Forwarding Abstractions Extensions" }, { ONF_EXP_OTRANS, "Optical Transport Extensions" }, { 0, NULL } }; const char * of_vendor_name(const uint32_t vendor) { const struct tok *table = (vendor & 0xff000000) == 0 ? oui_values : onf_exp_str; return tok2str(table, "unknown", vendor); } static void of_header_print(netdissect_options *ndo, const uint8_t version, const uint8_t type, const uint16_t length, const uint32_t xid) { ND_PRINT((ndo, "\n\tversion unknown (0x%02x), type 0x%02x, length %u, xid 0x%08x", version, type, length, xid)); } /* Print a single OpenFlow message. */ static const u_char * of_header_body_print(netdissect_options *ndo, const u_char *cp, const u_char *ep) { uint8_t version, type; uint16_t length; uint32_t xid; if (ep < cp + OF_HEADER_LEN) goto invalid; /* version */ ND_TCHECK2(*cp, 1); version = *cp; cp += 1; /* type */ ND_TCHECK2(*cp, 1); type = *cp; cp += 1; /* length */ ND_TCHECK2(*cp, 2); length = EXTRACT_16BITS(cp); cp += 2; /* xid */ ND_TCHECK2(*cp, 4); xid = EXTRACT_32BITS(cp); cp += 4; /* Message length includes the header length and a message always includes * the basic header. A message length underrun fails decoding of the rest of * the current packet. At the same time, try decoding as much of the current * message as possible even when it does not end within the current TCP * segment. */ if (length < OF_HEADER_LEN) { of_header_print(ndo, version, type, length, xid); goto invalid; } /* Decode known protocol versions further without printing the header (the * type decoding is version-specific. */ switch (version) { case OF_VER_1_0: return of10_header_body_print(ndo, cp, ep, type, length, xid); default: of_header_print(ndo, version, type, length, xid); ND_TCHECK2(*cp, length - OF_HEADER_LEN); return cp + length - OF_HEADER_LEN; /* done with current message */ } invalid: /* fail current packet */ ND_PRINT((ndo, "%s", istr)); ND_TCHECK2(*cp, ep - cp); return ep; trunc: ND_PRINT((ndo, "%s", tstr)); return ep; } /* Print a TCP segment worth of OpenFlow messages presuming the segment begins * on a message boundary. */ void openflow_print(netdissect_options *ndo, const u_char *cp, const u_int len _U_) { ND_PRINT((ndo, ": OpenFlow")); while (cp < ndo->ndo_snapend) cp = of_header_body_print(ndo, cp, ndo->ndo_snapend); } tcpdump-4.9.3/appletalk.h0000644000026300017510000001007713544412561013466 0ustar mcrmcr/* * Copyright (c) 1988, 1989, 1990, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of * the University nor the names of its contributors may be used to endorse * or promote products derived from this software without specific prior * written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * AppleTalk protocol formats (courtesy Bill Croft of Stanford/SUMEX). */ struct LAP { uint8_t dst; uint8_t src; uint8_t type; }; #define lapShortDDP 1 /* short DDP type */ #define lapDDP 2 /* DDP type */ #define lapKLAP 'K' /* Kinetics KLAP type */ /* Datagram Delivery Protocol */ struct atDDP { uint16_t length; uint16_t checksum; uint16_t dstNet; uint16_t srcNet; uint8_t dstNode; uint8_t srcNode; uint8_t dstSkt; uint8_t srcSkt; uint8_t type; }; struct atShortDDP { uint16_t length; uint8_t dstSkt; uint8_t srcSkt; uint8_t type; }; #define ddpMaxWKS 0x7F #define ddpMaxData 586 #define ddpLengthMask 0x3FF #define ddpHopShift 10 #define ddpSize 13 /* size of DDP header (avoid struct padding) */ #define ddpSSize 5 #define ddpWKS 128 /* boundary of DDP well known sockets */ #define ddpRTMP 1 /* RTMP type */ #define ddpRTMPrequest 5 /* RTMP request type */ #define ddpNBP 2 /* NBP type */ #define ddpATP 3 /* ATP type */ #define ddpECHO 4 /* ECHO type */ #define ddpIP 22 /* IP type */ #define ddpARP 23 /* ARP type */ #define ddpEIGRP 88 /* EIGRP over Appletalk */ #define ddpKLAP 0x4b /* Kinetics KLAP type */ /* AppleTalk Transaction Protocol */ struct atATP { uint8_t control; uint8_t bitmap; uint16_t transID; int32_t userData; }; #define atpReqCode 0x40 #define atpRspCode 0x80 #define atpRelCode 0xC0 #define atpXO 0x20 #define atpEOM 0x10 #define atpSTS 0x08 #define atpFlagMask 0x3F #define atpControlMask 0xF8 #define atpMaxNum 8 #define atpMaxData 578 /* AppleTalk Echo Protocol */ struct atEcho { uint8_t echoFunction; uint8_t *echoData; }; #define echoSkt 4 /* the echoer socket */ #define echoSize 1 /* size of echo header */ #define echoRequest 1 /* echo request */ #define echoReply 2 /* echo request */ /* Name Binding Protocol */ struct atNBP { uint8_t control; uint8_t id; }; struct atNBPtuple { uint16_t net; uint8_t node; uint8_t skt; uint8_t enumerator; }; #define nbpBrRq 0x10 #define nbpLkUp 0x20 #define nbpLkUpReply 0x30 #define nbpNIS 2 #define nbpTupleMax 15 #define nbpHeaderSize 2 #define nbpTupleSize 5 #define nbpSkt 2 /* NIS */ /* Routing Table Maint. Protocol */ #define rtmpSkt 1 /* number of RTMP socket */ #define rtmpSize 4 /* minimum size */ #define rtmpTupleSize 3 /* Zone Information Protocol */ struct zipHeader { uint8_t command; uint8_t netcount; }; #define zipHeaderSize 2 #define zipQuery 1 #define zipReply 2 #define zipTakedown 3 #define zipBringup 4 #define ddpZIP 6 #define zipSkt 6 #define GetMyZone 7 #define GetZoneList 8 /* * UDP port range used for ddp-in-udp encapsulation is 16512-16639 * for client sockets (128-255) and 200-327 for server sockets * (0-127). We also try to recognize the pre-April 88 server * socket range of 768-895. */ #define atalk_port(p) \ (((unsigned)((p) - 16512) < 128) || \ ((unsigned)((p) - 200) < 128) || \ ((unsigned)((p) - 768) < 128)) tcpdump-4.9.3/print-hsrp.c0000644000026300017510000001110313544412561013601 0ustar mcrmcr/* * Copyright (C) 2001 Julian Cowley * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the project nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* \summary: Cisco Hot Standby Router Protocol (HSRP) printer */ /* Cisco Hot Standby Router Protocol (HSRP). */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #include "addrtoname.h" /* HSRP op code types. */ static const char *op_code_str[] = { "hello", "coup", "resign" }; /* HSRP states and associated names. */ static const struct tok states[] = { { 0, "initial" }, { 1, "learn" }, { 2, "listen" }, { 4, "speak" }, { 8, "standby" }, { 16, "active" }, { 0, NULL } }; /* * RFC 2281: * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Version | Op Code | State | Hellotime | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Holdtime | Priority | Group | Reserved | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Authentication Data | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Authentication Data | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Virtual IP Address | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ #define HSRP_AUTH_SIZE 8 /* HSRP protocol header. */ struct hsrp { uint8_t hsrp_version; uint8_t hsrp_op_code; uint8_t hsrp_state; uint8_t hsrp_hellotime; uint8_t hsrp_holdtime; uint8_t hsrp_priority; uint8_t hsrp_group; uint8_t hsrp_reserved; uint8_t hsrp_authdata[HSRP_AUTH_SIZE]; struct in_addr hsrp_virtaddr; }; void hsrp_print(netdissect_options *ndo, register const uint8_t *bp, register u_int len) { const struct hsrp *hp = (const struct hsrp *) bp; ND_TCHECK(hp->hsrp_version); ND_PRINT((ndo, "HSRPv%d", hp->hsrp_version)); if (hp->hsrp_version != 0) return; ND_TCHECK(hp->hsrp_op_code); ND_PRINT((ndo, "-")); ND_PRINT((ndo, "%s ", tok2strary(op_code_str, "unknown (%d)", hp->hsrp_op_code))); ND_PRINT((ndo, "%d: ", len)); ND_TCHECK(hp->hsrp_state); ND_PRINT((ndo, "state=%s ", tok2str(states, "Unknown (%d)", hp->hsrp_state))); ND_TCHECK(hp->hsrp_group); ND_PRINT((ndo, "group=%d ", hp->hsrp_group)); ND_TCHECK(hp->hsrp_reserved); if (hp->hsrp_reserved != 0) { ND_PRINT((ndo, "[reserved=%d!] ", hp->hsrp_reserved)); } ND_TCHECK(hp->hsrp_virtaddr); ND_PRINT((ndo, "addr=%s", ipaddr_string(ndo, &hp->hsrp_virtaddr))); if (ndo->ndo_vflag) { ND_PRINT((ndo, " hellotime=")); unsigned_relts_print(ndo, hp->hsrp_hellotime); ND_PRINT((ndo, " holdtime=")); unsigned_relts_print(ndo, hp->hsrp_holdtime); ND_PRINT((ndo, " priority=%d", hp->hsrp_priority)); ND_PRINT((ndo, " auth=\"")); if (fn_printn(ndo, hp->hsrp_authdata, sizeof(hp->hsrp_authdata), ndo->ndo_snapend)) { ND_PRINT((ndo, "\"")); goto trunc; } ND_PRINT((ndo, "\"")); } return; trunc: ND_PRINT((ndo, "[|hsrp]")); } tcpdump-4.9.3/print-krb.c0000644000026300017510000001441713544412561013416 0ustar mcrmcr/* * Copyright (c) 1995, 1996, 1997 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of * the University nor the names of its contributors may be used to endorse * or promote products derived from this software without specific prior * written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * Initial contribution from John Hawkinson (jhawk@mit.edu). */ /* \summary: Kerberos printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #include "extract.h" static const char tstr[] = " [|kerberos]"; static const u_char *c_print(netdissect_options *, register const u_char *, register const u_char *); static const u_char *krb4_print_hdr(netdissect_options *, const u_char *); static void krb4_print(netdissect_options *, const u_char *); #define AUTH_MSG_KDC_REQUEST 1<<1 #define AUTH_MSG_KDC_REPLY 2<<1 #define AUTH_MSG_APPL_REQUEST 3<<1 #define AUTH_MSG_APPL_REQUEST_MUTUAL 4<<1 #define AUTH_MSG_ERR_REPLY 5<<1 #define AUTH_MSG_PRIVATE 6<<1 #define AUTH_MSG_SAFE 7<<1 #define AUTH_MSG_APPL_ERR 8<<1 #define AUTH_MSG_DIE 63<<1 #define KERB_ERR_OK 0 #define KERB_ERR_NAME_EXP 1 #define KERB_ERR_SERVICE_EXP 2 #define KERB_ERR_AUTH_EXP 3 #define KERB_ERR_PKT_VER 4 #define KERB_ERR_NAME_MAST_KEY_VER 5 #define KERB_ERR_SERV_MAST_KEY_VER 6 #define KERB_ERR_BYTE_ORDER 7 #define KERB_ERR_PRINCIPAL_UNKNOWN 8 #define KERB_ERR_PRINCIPAL_NOT_UNIQUE 9 #define KERB_ERR_NULL_KEY 10 struct krb { uint8_t pvno; /* Protocol Version */ uint8_t type; /* Type+B */ }; static const struct tok type2str[] = { { AUTH_MSG_KDC_REQUEST, "KDC_REQUEST" }, { AUTH_MSG_KDC_REPLY, "KDC_REPLY" }, { AUTH_MSG_APPL_REQUEST, "APPL_REQUEST" }, { AUTH_MSG_APPL_REQUEST_MUTUAL, "APPL_REQUEST_MUTUAL" }, { AUTH_MSG_ERR_REPLY, "ERR_REPLY" }, { AUTH_MSG_PRIVATE, "PRIVATE" }, { AUTH_MSG_SAFE, "SAFE" }, { AUTH_MSG_APPL_ERR, "APPL_ERR" }, { AUTH_MSG_DIE, "DIE" }, { 0, NULL } }; static const struct tok kerr2str[] = { { KERB_ERR_OK, "OK" }, { KERB_ERR_NAME_EXP, "NAME_EXP" }, { KERB_ERR_SERVICE_EXP, "SERVICE_EXP" }, { KERB_ERR_AUTH_EXP, "AUTH_EXP" }, { KERB_ERR_PKT_VER, "PKT_VER" }, { KERB_ERR_NAME_MAST_KEY_VER, "NAME_MAST_KEY_VER" }, { KERB_ERR_SERV_MAST_KEY_VER, "SERV_MAST_KEY_VER" }, { KERB_ERR_BYTE_ORDER, "BYTE_ORDER" }, { KERB_ERR_PRINCIPAL_UNKNOWN, "PRINCIPAL_UNKNOWN" }, { KERB_ERR_PRINCIPAL_NOT_UNIQUE,"PRINCIPAL_NOT_UNIQUE" }, { KERB_ERR_NULL_KEY, "NULL_KEY"}, { 0, NULL} }; static const u_char * c_print(netdissect_options *ndo, register const u_char *s, register const u_char *ep) { register u_char c; register int flag; flag = 1; while (s < ep) { c = *s++; if (c == '\0') { flag = 0; break; } if (!ND_ISASCII(c)) { c = ND_TOASCII(c); ND_PRINT((ndo, "M-")); } if (!ND_ISPRINT(c)) { c ^= 0x40; /* DEL to ?, others to alpha */ ND_PRINT((ndo, "^")); } ND_PRINT((ndo, "%c", c)); } if (flag) return NULL; return (s); } static const u_char * krb4_print_hdr(netdissect_options *ndo, const u_char *cp) { cp += 2; #define PRINT if ((cp = c_print(ndo, cp, ndo->ndo_snapend)) == NULL) goto trunc PRINT; ND_PRINT((ndo, ".")); PRINT; ND_PRINT((ndo, "@")); PRINT; return (cp); trunc: ND_PRINT((ndo, "%s", tstr)); return (NULL); #undef PRINT } static void krb4_print(netdissect_options *ndo, const u_char *cp) { register const struct krb *kp; u_char type; u_short len; #define PRINT if ((cp = c_print(ndo, cp, ndo->ndo_snapend)) == NULL) goto trunc /* True if struct krb is little endian */ #define IS_LENDIAN(kp) (((kp)->type & 0x01) != 0) #define KTOHSP(kp, cp) (IS_LENDIAN(kp) ? EXTRACT_LE_16BITS(cp) : EXTRACT_16BITS(cp)) kp = (const struct krb *)cp; if ((&kp->type) >= ndo->ndo_snapend) { ND_PRINT((ndo, "%s", tstr)); return; } type = kp->type & (0xFF << 1); ND_PRINT((ndo, " %s %s: ", IS_LENDIAN(kp) ? "le" : "be", tok2str(type2str, NULL, type))); switch (type) { case AUTH_MSG_KDC_REQUEST: if ((cp = krb4_print_hdr(ndo, cp)) == NULL) return; cp += 4; /* ctime */ ND_TCHECK(*cp); ND_PRINT((ndo, " %dmin ", *cp++ * 5)); PRINT; ND_PRINT((ndo, ".")); PRINT; break; case AUTH_MSG_APPL_REQUEST: cp += 2; ND_TCHECK(*cp); ND_PRINT((ndo, "v%d ", *cp++)); PRINT; ND_TCHECK(*cp); ND_PRINT((ndo, " (%d)", *cp++)); ND_TCHECK(*cp); ND_PRINT((ndo, " (%d)", *cp)); break; case AUTH_MSG_KDC_REPLY: if ((cp = krb4_print_hdr(ndo, cp)) == NULL) return; cp += 10; /* timestamp + n + exp + kvno */ ND_TCHECK2(*cp, sizeof(short)); len = KTOHSP(kp, cp); ND_PRINT((ndo, " (%d)", len)); break; case AUTH_MSG_ERR_REPLY: if ((cp = krb4_print_hdr(ndo, cp)) == NULL) return; cp += 4; /* timestamp */ ND_TCHECK2(*cp, sizeof(short)); ND_PRINT((ndo, " %s ", tok2str(kerr2str, NULL, KTOHSP(kp, cp)))); cp += 4; PRINT; break; default: ND_PRINT((ndo, "(unknown)")); break; } return; trunc: ND_PRINT((ndo, "%s", tstr)); } void krb_print(netdissect_options *ndo, const u_char *dat) { register const struct krb *kp; kp = (const struct krb *)dat; if (dat >= ndo->ndo_snapend) { ND_PRINT((ndo, "%s", tstr)); return; } switch (kp->pvno) { case 1: case 2: case 3: ND_PRINT((ndo, " v%d", kp->pvno)); break; case 4: ND_PRINT((ndo, " v%d", kp->pvno)); krb4_print(ndo, (const u_char *)kp); break; case 106: case 107: ND_PRINT((ndo, " v5")); /* Decode ASN.1 here "someday" */ break; } return; } tcpdump-4.9.3/INSTALL.txt0000644000026300017510000001237713544412561013214 0ustar mcrmcrIf you have not built libpcap, and your system does not have libpcap installed, install libpcap first. Your system might provide a version of libpcap that can be installed; if so, to compile tcpdump you might need to install a "developer" version of libpcap as well as the "run-time" version. You can also install tcpdump.org's version of libpcap; see the README file in this directory for the ftp location. You will need an ANSI C compiler to build tcpdump. The configure script will abort if your compiler is not ANSI compliant. If this happens, use the generally available GNU C compiler (GCC). After libpcap has been built (either install it with "make install" or make sure both the libpcap and tcpdump source trees are in the same directory), run ./configure (a shell script). "configure" will determine your system attributes and generate an appropriate Makefile from Makefile.in. Now build tcpdump by running "make". If everything builds ok, su and type "make install". This will install tcpdump and the manual entry. Any user will be able to use tcpdump to read saved captures. Whether a user will be able to capture traffic depends on the OS and the configuration of the system; see the tcpdump man page for details. DO NOT give untrusted users the ability to capture traffic. If a user can capture traffic, he or she could use utilities such as tcpdump to capture any traffic on your net, including passwords. Note that most systems ship tcpdump, but usually an older version. Remember to remove or rename the installed binary when upgrading. If your system is not one which we have tested tcpdump on, you may have to modify the configure script and Makefile.in. Please send us patches for any modifications you need to make. Please see "PLATFORMS" for notes about tested platforms. FILES ----- CHANGES - description of differences between releases CONTRIBUTING - guidelines for contributing CREDITS - people that have helped tcpdump along INSTALL.txt - this file LICENSE - the license under which tcpdump is distributed Makefile.in - compilation rules (input to the configure script) README - description of distribution Readme.Win32 - notes on building tcpdump on Win32 systems (with WinPcap) VERSION - version of this release aclocal.m4 - autoconf macros addrtoname.c - address to hostname routines addrtoname.h - address to hostname definitions ah.h - IPSEC Authentication Header definitions appletalk.h - AppleTalk definitions ascii_strcasecmp.c - locale-independent case-independent string comparison routines atime.awk - TCP ack awk script atm.h - ATM traffic type definitions bpf_dump.c - BPF program printing routines, in case libpcap doesn't have them chdlc.h - Cisco HDLC definitions cpack.c - functions to extract packed data cpack.h - declarations of functions to extract packed data config.guess - autoconf support config.h.in - autoconf input config.sub - autoconf support configure - configure script (run this first) configure.ac - configure script source ether.h - Ethernet definitions ethertype.h - Ethernet type value definitions extract.h - alignment definitions gmpls.c - GMPLS definitions gmpls.h - GMPLS declarations gmt2local.c - time conversion routines gmt2local.h - time conversion prototypes install-sh - BSD style install script interface.h - globals, prototypes and definitions ip.h - IP definitions ip6.h - IPv6 definitions ipproto.c - IP protocol type value-to-name table ipproto.h - IP protocol type value definitions l2vpn.c - L2VPN encapsulation value-to-name table l2vpn.h - L2VPN encapsulation definitions lbl/os-*.h - OS-dependent defines and prototypes llc.h - LLC definitions machdep.c - machine dependent routines machdep.h - machine dependent definitions makemib - mib to header script mib.h - mib definitions missing/* - replacements for missing library functions mkdep - construct Makefile dependency list mpls.h - MPLS definitions nameser.h - DNS definitions netdissect.h - definitions and declarations for tcpdump-as-library (under development) nfs.h - Network File System V2 definitions nfsfh.h - Network File System file handle definitions nlpid.c - OSI NLPID value-to-name table nlpid.h - OSI NLPID definitions ospf.h - Open Shortest Path First definitions packetdat.awk - TCP chunk summary awk script parsenfsfh.c - Network File System file parser routines pcap_dump_ftell.c - pcap_dump_ftell() implementation, in case libpcap doesn't have it pcap-missing.h - declarations of functions possibly missing from libpcap ppp.h - Point to Point Protocol definitions print.c - Top-level routines for protocol printing print-*.c - The netdissect printers rpc_auth.h - definitions for ONC RPC authentication rpc_msg.h - definitions for ONC RPC messages send-ack.awk - unidirectional tcp send/ack awk script setsignal.c - OS-independent signal routines setsignal.h - OS-independent signal prototypes slcompress.h - SLIP/PPP Van Jacobson compression (RFC1144) definitions smb.h - SMB/CIFS definitions smbutil.c - SMB/CIFS utility routines stime.awk - TCP send awk script tcp.h - TCP definitions tcpdump.1 - manual entry tcpdump.c - main program timeval-operations.h - timeval operations macros udp.h - UDP definitions util-print.c - utility routines for protocol printers vfprintf.c - emulation routine win32 - headers and routines for building on Win32 systems tcpdump-4.9.3/print-bgp.c0000644000026300017510000030742313544412724013413 0ustar mcrmcr/* * Copyright (C) 1999 WIDE Project. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the project nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * Extensively modified by Hannes Gredler (hannes@gredler.at) for more * complete BGP support. */ /* \summary: Border Gateway Protocol (BGP) printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include #include "netdissect.h" #include "addrtoname.h" #include "extract.h" #include "af.h" #include "l2vpn.h" static const char tstr[] = "[|BGP]"; struct bgp { uint8_t bgp_marker[16]; uint16_t bgp_len; uint8_t bgp_type; }; #define BGP_SIZE 19 /* unaligned */ #define BGP_OPEN 1 #define BGP_UPDATE 2 #define BGP_NOTIFICATION 3 #define BGP_KEEPALIVE 4 #define BGP_ROUTE_REFRESH 5 static const struct tok bgp_msg_values[] = { { BGP_OPEN, "Open"}, { BGP_UPDATE, "Update"}, { BGP_NOTIFICATION, "Notification"}, { BGP_KEEPALIVE, "Keepalive"}, { BGP_ROUTE_REFRESH, "Route Refresh"}, { 0, NULL} }; struct bgp_open { uint8_t bgpo_marker[16]; uint16_t bgpo_len; uint8_t bgpo_type; uint8_t bgpo_version; uint16_t bgpo_myas; uint16_t bgpo_holdtime; uint32_t bgpo_id; uint8_t bgpo_optlen; /* options should follow */ }; #define BGP_OPEN_SIZE 29 /* unaligned */ struct bgp_opt { uint8_t bgpopt_type; uint8_t bgpopt_len; /* variable length */ }; #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */ #define BGP_CAP_HEADER_SIZE 2 /* some compilers may pad to 4 bytes */ struct bgp_notification { uint8_t bgpn_marker[16]; uint16_t bgpn_len; uint8_t bgpn_type; uint8_t bgpn_major; uint8_t bgpn_minor; }; #define BGP_NOTIFICATION_SIZE 21 /* unaligned */ struct bgp_route_refresh { uint8_t bgp_marker[16]; uint16_t len; uint8_t type; uint8_t afi[2]; /* the compiler messes this structure up */ uint8_t res; /* when doing misaligned sequences of int8 and int16 */ uint8_t safi; /* afi should be int16 - so we have to access it using */ }; /* EXTRACT_16BITS(&bgp_route_refresh->afi) (sigh) */ #define BGP_ROUTE_REFRESH_SIZE 23 #define bgp_attr_lenlen(flags, p) \ (((flags) & 0x10) ? 2 : 1) #define bgp_attr_len(flags, p) \ (((flags) & 0x10) ? EXTRACT_16BITS(p) : *(p)) #define BGPTYPE_ORIGIN 1 #define BGPTYPE_AS_PATH 2 #define BGPTYPE_NEXT_HOP 3 #define BGPTYPE_MULTI_EXIT_DISC 4 #define BGPTYPE_LOCAL_PREF 5 #define BGPTYPE_ATOMIC_AGGREGATE 6 #define BGPTYPE_AGGREGATOR 7 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */ #define BGPTYPE_ORIGINATOR_ID 9 /* RFC4456 */ #define BGPTYPE_CLUSTER_LIST 10 /* RFC4456 */ #define BGPTYPE_DPA 11 /* deprecated, draft-ietf-idr-bgp-dpa */ #define BGPTYPE_ADVERTISERS 12 /* deprecated RFC1863 */ #define BGPTYPE_RCID_PATH 13 /* deprecated RFC1863 */ #define BGPTYPE_MP_REACH_NLRI 14 /* RFC4760 */ #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC4760 */ #define BGPTYPE_EXTD_COMMUNITIES 16 /* RFC4360 */ #define BGPTYPE_AS4_PATH 17 /* RFC6793 */ #define BGPTYPE_AGGREGATOR4 18 /* RFC6793 */ #define BGPTYPE_PMSI_TUNNEL 22 /* RFC6514 */ #define BGPTYPE_TUNNEL_ENCAP 23 /* RFC5512 */ #define BGPTYPE_TRAFFIC_ENG 24 /* RFC5543 */ #define BGPTYPE_IPV6_EXTD_COMMUNITIES 25 /* RFC5701 */ #define BGPTYPE_AIGP 26 /* RFC7311 */ #define BGPTYPE_PE_DISTINGUISHER_LABEL 27 /* RFC6514 */ #define BGPTYPE_ENTROPY_LABEL 28 /* RFC6790 */ #define BGPTYPE_LARGE_COMMUNITY 32 /* draft-ietf-idr-large-community-05 */ #define BGPTYPE_ATTR_SET 128 /* RFC6368 */ #define BGP_MP_NLRI_MINSIZE 3 /* End of RIB Marker detection */ static const struct tok bgp_attr_values[] = { { BGPTYPE_ORIGIN, "Origin"}, { BGPTYPE_AS_PATH, "AS Path"}, { BGPTYPE_AS4_PATH, "AS4 Path"}, { BGPTYPE_NEXT_HOP, "Next Hop"}, { BGPTYPE_MULTI_EXIT_DISC, "Multi Exit Discriminator"}, { BGPTYPE_LOCAL_PREF, "Local Preference"}, { BGPTYPE_ATOMIC_AGGREGATE, "Atomic Aggregate"}, { BGPTYPE_AGGREGATOR, "Aggregator"}, { BGPTYPE_AGGREGATOR4, "Aggregator4"}, { BGPTYPE_COMMUNITIES, "Community"}, { BGPTYPE_ORIGINATOR_ID, "Originator ID"}, { BGPTYPE_CLUSTER_LIST, "Cluster List"}, { BGPTYPE_DPA, "DPA"}, { BGPTYPE_ADVERTISERS, "Advertisers"}, { BGPTYPE_RCID_PATH, "RCID Path / Cluster ID"}, { BGPTYPE_MP_REACH_NLRI, "Multi-Protocol Reach NLRI"}, { BGPTYPE_MP_UNREACH_NLRI, "Multi-Protocol Unreach NLRI"}, { BGPTYPE_EXTD_COMMUNITIES, "Extended Community"}, { BGPTYPE_PMSI_TUNNEL, "PMSI Tunnel"}, { BGPTYPE_TUNNEL_ENCAP, "Tunnel Encapsulation"}, { BGPTYPE_TRAFFIC_ENG, "Traffic Engineering"}, { BGPTYPE_IPV6_EXTD_COMMUNITIES, "IPv6 Extended Community"}, { BGPTYPE_AIGP, "Accumulated IGP Metric"}, { BGPTYPE_PE_DISTINGUISHER_LABEL, "PE Distinguisher Label"}, { BGPTYPE_ENTROPY_LABEL, "Entropy Label"}, { BGPTYPE_LARGE_COMMUNITY, "Large Community"}, { BGPTYPE_ATTR_SET, "Attribute Set"}, { 255, "Reserved for development"}, { 0, NULL} }; #define BGP_AS_SET 1 #define BGP_AS_SEQUENCE 2 #define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */ #define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */ #define BGP_AS_SEG_TYPE_MIN BGP_AS_SET #define BGP_AS_SEG_TYPE_MAX BGP_CONFED_AS_SET static const struct tok bgp_as_path_segment_open_values[] = { { BGP_AS_SEQUENCE, ""}, { BGP_AS_SET, "{ "}, { BGP_CONFED_AS_SEQUENCE, "( "}, { BGP_CONFED_AS_SET, "({ "}, { 0, NULL} }; static const struct tok bgp_as_path_segment_close_values[] = { { BGP_AS_SEQUENCE, ""}, { BGP_AS_SET, "}"}, { BGP_CONFED_AS_SEQUENCE, ")"}, { BGP_CONFED_AS_SET, "})"}, { 0, NULL} }; #define BGP_OPT_AUTH 1 #define BGP_OPT_CAP 2 static const struct tok bgp_opt_values[] = { { BGP_OPT_AUTH, "Authentication Information"}, { BGP_OPT_CAP, "Capabilities Advertisement"}, { 0, NULL} }; #define BGP_CAPCODE_MP 1 /* RFC2858 */ #define BGP_CAPCODE_RR 2 /* RFC2918 */ #define BGP_CAPCODE_ORF 3 /* RFC5291 */ #define BGP_CAPCODE_MR 4 /* RFC3107 */ #define BGP_CAPCODE_EXT_NH 5 /* RFC5549 */ #define BGP_CAPCODE_RESTART 64 /* RFC4724 */ #define BGP_CAPCODE_AS_NEW 65 /* RFC6793 */ #define BGP_CAPCODE_DYN_CAP 67 /* draft-ietf-idr-dynamic-cap */ #define BGP_CAPCODE_MULTISESS 68 /* draft-ietf-idr-bgp-multisession */ #define BGP_CAPCODE_ADD_PATH 69 /* RFC7911 */ #define BGP_CAPCODE_ENH_RR 70 /* draft-keyur-bgp-enhanced-route-refresh */ #define BGP_CAPCODE_RR_CISCO 128 static const struct tok bgp_capcode_values[] = { { BGP_CAPCODE_MP, "Multiprotocol Extensions"}, { BGP_CAPCODE_RR, "Route Refresh"}, { BGP_CAPCODE_ORF, "Cooperative Route Filtering"}, { BGP_CAPCODE_MR, "Multiple Routes to a Destination"}, { BGP_CAPCODE_EXT_NH, "Extended Next Hop Encoding"}, { BGP_CAPCODE_RESTART, "Graceful Restart"}, { BGP_CAPCODE_AS_NEW, "32-Bit AS Number"}, { BGP_CAPCODE_DYN_CAP, "Dynamic Capability"}, { BGP_CAPCODE_MULTISESS, "Multisession BGP"}, { BGP_CAPCODE_ADD_PATH, "Multiple Paths"}, { BGP_CAPCODE_ENH_RR, "Enhanced Route Refresh"}, { BGP_CAPCODE_RR_CISCO, "Route Refresh (Cisco)"}, { 0, NULL} }; #define BGP_NOTIFY_MAJOR_MSG 1 #define BGP_NOTIFY_MAJOR_OPEN 2 #define BGP_NOTIFY_MAJOR_UPDATE 3 #define BGP_NOTIFY_MAJOR_HOLDTIME 4 #define BGP_NOTIFY_MAJOR_FSM 5 #define BGP_NOTIFY_MAJOR_CEASE 6 #define BGP_NOTIFY_MAJOR_CAP 7 static const struct tok bgp_notify_major_values[] = { { BGP_NOTIFY_MAJOR_MSG, "Message Header Error"}, { BGP_NOTIFY_MAJOR_OPEN, "OPEN Message Error"}, { BGP_NOTIFY_MAJOR_UPDATE, "UPDATE Message Error"}, { BGP_NOTIFY_MAJOR_HOLDTIME,"Hold Timer Expired"}, { BGP_NOTIFY_MAJOR_FSM, "Finite State Machine Error"}, { BGP_NOTIFY_MAJOR_CEASE, "Cease"}, { BGP_NOTIFY_MAJOR_CAP, "Capability Message Error"}, { 0, NULL} }; /* draft-ietf-idr-cease-subcode-02 */ #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1 static const struct tok bgp_notify_minor_cease_values[] = { { BGP_NOTIFY_MINOR_CEASE_MAXPRFX, "Maximum Number of Prefixes Reached"}, { 2, "Administratively Shutdown"}, { 3, "Peer Unconfigured"}, { 4, "Administratively Reset"}, { 5, "Connection Rejected"}, { 6, "Other Configuration Change"}, { 7, "Connection Collision Resolution"}, { 0, NULL} }; static const struct tok bgp_notify_minor_msg_values[] = { { 1, "Connection Not Synchronized"}, { 2, "Bad Message Length"}, { 3, "Bad Message Type"}, { 0, NULL} }; static const struct tok bgp_notify_minor_open_values[] = { { 1, "Unsupported Version Number"}, { 2, "Bad Peer AS"}, { 3, "Bad BGP Identifier"}, { 4, "Unsupported Optional Parameter"}, { 5, "Authentication Failure"}, { 6, "Unacceptable Hold Time"}, { 7, "Capability Message Error"}, { 0, NULL} }; static const struct tok bgp_notify_minor_update_values[] = { { 1, "Malformed Attribute List"}, { 2, "Unrecognized Well-known Attribute"}, { 3, "Missing Well-known Attribute"}, { 4, "Attribute Flags Error"}, { 5, "Attribute Length Error"}, { 6, "Invalid ORIGIN Attribute"}, { 7, "AS Routing Loop"}, { 8, "Invalid NEXT_HOP Attribute"}, { 9, "Optional Attribute Error"}, { 10, "Invalid Network Field"}, { 11, "Malformed AS_PATH"}, { 0, NULL} }; static const struct tok bgp_notify_minor_fsm_values[] = { { 1, "In OpenSent State"}, { 2, "In OpenConfirm State"}, { 3, "In Established State"}, { 0, NULL } }; static const struct tok bgp_notify_minor_cap_values[] = { { 1, "Invalid Action Value" }, { 2, "Invalid Capability Length" }, { 3, "Malformed Capability Value" }, { 4, "Unsupported Capability Code" }, { 0, NULL } }; static const struct tok bgp_origin_values[] = { { 0, "IGP"}, { 1, "EGP"}, { 2, "Incomplete"}, { 0, NULL} }; #define BGP_PMSI_TUNNEL_RSVP_P2MP 1 #define BGP_PMSI_TUNNEL_LDP_P2MP 2 #define BGP_PMSI_TUNNEL_PIM_SSM 3 #define BGP_PMSI_TUNNEL_PIM_SM 4 #define BGP_PMSI_TUNNEL_PIM_BIDIR 5 #define BGP_PMSI_TUNNEL_INGRESS 6 #define BGP_PMSI_TUNNEL_LDP_MP2MP 7 static const struct tok bgp_pmsi_tunnel_values[] = { { BGP_PMSI_TUNNEL_RSVP_P2MP, "RSVP-TE P2MP LSP"}, { BGP_PMSI_TUNNEL_LDP_P2MP, "LDP P2MP LSP"}, { BGP_PMSI_TUNNEL_PIM_SSM, "PIM-SSM Tree"}, { BGP_PMSI_TUNNEL_PIM_SM, "PIM-SM Tree"}, { BGP_PMSI_TUNNEL_PIM_BIDIR, "PIM-Bidir Tree"}, { BGP_PMSI_TUNNEL_INGRESS, "Ingress Replication"}, { BGP_PMSI_TUNNEL_LDP_MP2MP, "LDP MP2MP LSP"}, { 0, NULL} }; static const struct tok bgp_pmsi_flag_values[] = { { 0x01, "Leaf Information required"}, { 0, NULL} }; #define BGP_AIGP_TLV 1 static const struct tok bgp_aigp_values[] = { { BGP_AIGP_TLV, "AIGP"}, { 0, NULL} }; /* Subsequent address family identifier, RFC2283 section 7 */ #define SAFNUM_RES 0 #define SAFNUM_UNICAST 1 #define SAFNUM_MULTICAST 2 #define SAFNUM_UNIMULTICAST 3 /* deprecated now */ /* labeled BGP RFC3107 */ #define SAFNUM_LABUNICAST 4 /* RFC6514 */ #define SAFNUM_MULTICAST_VPN 5 /* draft-nalawade-kapoor-tunnel-safi */ #define SAFNUM_TUNNEL 64 /* RFC4761 */ #define SAFNUM_VPLS 65 /* RFC6037 */ #define SAFNUM_MDT 66 /* RFC4364 */ #define SAFNUM_VPNUNICAST 128 /* RFC6513 */ #define SAFNUM_VPNMULTICAST 129 #define SAFNUM_VPNUNIMULTICAST 130 /* deprecated now */ /* RFC4684 */ #define SAFNUM_RT_ROUTING_INFO 132 #define BGP_VPN_RD_LEN 8 static const struct tok bgp_safi_values[] = { { SAFNUM_RES, "Reserved"}, { SAFNUM_UNICAST, "Unicast"}, { SAFNUM_MULTICAST, "Multicast"}, { SAFNUM_UNIMULTICAST, "Unicast+Multicast"}, { SAFNUM_LABUNICAST, "labeled Unicast"}, { SAFNUM_TUNNEL, "Tunnel"}, { SAFNUM_VPLS, "VPLS"}, { SAFNUM_MDT, "MDT"}, { SAFNUM_VPNUNICAST, "labeled VPN Unicast"}, { SAFNUM_VPNMULTICAST, "labeled VPN Multicast"}, { SAFNUM_VPNUNIMULTICAST, "labeled VPN Unicast+Multicast"}, { SAFNUM_RT_ROUTING_INFO, "Route Target Routing Information"}, { SAFNUM_MULTICAST_VPN, "Multicast VPN"}, { 0, NULL } }; /* well-known community */ #define BGP_COMMUNITY_NO_EXPORT 0xffffff01 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03 /* Extended community type - draft-ietf-idr-bgp-ext-communities-05 */ #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */ #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */ #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */ #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */ #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */ #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */ #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */ /* rfc2547 bgp-mpls-vpns */ #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */ #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatability */ #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatability */ #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatability */ #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */ #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatability */ #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */ #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatability */ #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */ #define BGP_EXT_COM_SOURCE_AS 0x0009 /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */ #define BGP_EXT_COM_VRF_RT_IMP 0x010b /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */ #define BGP_EXT_COM_L2VPN_RT_0 0x000a /* L2VPN Identifier,Format AS(2bytes):AN(4bytes) */ #define BGP_EXT_COM_L2VPN_RT_1 0xF10a /* L2VPN Identifier,Format IP address:AN(2bytes) */ /* http://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */ #define BGP_EXT_COM_EIGRP_GEN 0x8800 #define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801 #define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802 #define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803 #define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804 #define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805 static const struct tok bgp_extd_comm_flag_values[] = { { 0x8000, "vendor-specific"}, { 0x4000, "non-transitive"}, { 0, NULL}, }; static const struct tok bgp_extd_comm_subtype_values[] = { { BGP_EXT_COM_RT_0, "target"}, { BGP_EXT_COM_RT_1, "target"}, { BGP_EXT_COM_RT_2, "target"}, { BGP_EXT_COM_RO_0, "origin"}, { BGP_EXT_COM_RO_1, "origin"}, { BGP_EXT_COM_RO_2, "origin"}, { BGP_EXT_COM_LINKBAND, "link-BW"}, { BGP_EXT_COM_VPN_ORIGIN, "ospf-domain"}, { BGP_EXT_COM_VPN_ORIGIN2, "ospf-domain"}, { BGP_EXT_COM_VPN_ORIGIN3, "ospf-domain"}, { BGP_EXT_COM_VPN_ORIGIN4, "ospf-domain"}, { BGP_EXT_COM_OSPF_RTYPE, "ospf-route-type"}, { BGP_EXT_COM_OSPF_RTYPE2, "ospf-route-type"}, { BGP_EXT_COM_OSPF_RID, "ospf-router-id"}, { BGP_EXT_COM_OSPF_RID2, "ospf-router-id"}, { BGP_EXT_COM_L2INFO, "layer2-info"}, { BGP_EXT_COM_EIGRP_GEN , "eigrp-general-route (flag, tag)" }, { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY , "eigrp-route-metric (AS, delay)" }, { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW , "eigrp-route-metric (reliability, nexthop, bandwidth)" }, { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU , "eigrp-route-metric (load, MTU)" }, { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID , "eigrp-external-route (remote-AS, remote-ID)" }, { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC , "eigrp-external-route (remote-proto, remote-metric)" }, { BGP_EXT_COM_SOURCE_AS, "source-AS" }, { BGP_EXT_COM_VRF_RT_IMP, "vrf-route-import"}, { BGP_EXT_COM_L2VPN_RT_0, "l2vpn-id"}, { BGP_EXT_COM_L2VPN_RT_1, "l2vpn-id"}, { 0, NULL}, }; /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */ #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */ #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */ #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */ #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */ #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/ #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */ #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */ static const struct tok bgp_extd_comm_ospf_rtype_values[] = { { BGP_OSPF_RTYPE_RTR, "Router" }, { BGP_OSPF_RTYPE_NET, "Network" }, { BGP_OSPF_RTYPE_SUM, "Summary" }, { BGP_OSPF_RTYPE_EXT, "External" }, { BGP_OSPF_RTYPE_NSSA,"NSSA External" }, { BGP_OSPF_RTYPE_SHAM,"MPLS-VPN Sham" }, { 0, NULL }, }; /* ADD-PATH Send/Receive field values */ static const struct tok bgp_add_path_recvsend[] = { { 1, "Receive" }, { 2, "Send" }, { 3, "Both" }, { 0, NULL }, }; static char astostr[20]; /* * as_printf * * Convert an AS number into a string and return string pointer. * * Depending on bflag is set or not, AS number is converted into ASDOT notation * or plain number notation. * */ static char * as_printf(netdissect_options *ndo, char *str, int size, u_int asnum) { if (!ndo->ndo_bflag || asnum <= 0xFFFF) { snprintf(str, size, "%u", asnum); } else { snprintf(str, size, "%u.%u", asnum >> 16, asnum & 0xFFFF); } return str; } #define ITEMCHECK(minlen) if (itemlen < minlen) goto badtlv; int decode_prefix4(netdissect_options *ndo, const u_char *pptr, u_int itemlen, char *buf, u_int buflen) { struct in_addr addr; u_int plen, plenbytes; ND_TCHECK(pptr[0]); ITEMCHECK(1); plen = pptr[0]; if (32 < plen) return -1; itemlen -= 1; memset(&addr, 0, sizeof(addr)); plenbytes = (plen + 7) / 8; ND_TCHECK2(pptr[1], plenbytes); ITEMCHECK(plenbytes); memcpy(&addr, &pptr[1], plenbytes); if (plen % 8) { ((u_char *)&addr)[plenbytes - 1] &= ((0xff00 >> (plen % 8)) & 0xff); } snprintf(buf, buflen, "%s/%d", ipaddr_string(ndo, &addr), plen); return 1 + plenbytes; trunc: return -2; badtlv: return -3; } static int decode_labeled_prefix4(netdissect_options *ndo, const u_char *pptr, u_int itemlen, char *buf, u_int buflen) { struct in_addr addr; u_int plen, plenbytes; /* prefix length and label = 4 bytes */ ND_TCHECK2(pptr[0], 4); ITEMCHECK(4); plen = pptr[0]; /* get prefix length */ /* this is one of the weirdnesses of rfc3107 the label length (actually the label + COS bits) is added to the prefix length; we also do only read out just one label - there is no real application for advertisement of stacked labels in a single BGP message */ if (24 > plen) return -1; plen-=24; /* adjust prefixlen - labellength */ if (32 < plen) return -1; itemlen -= 4; memset(&addr, 0, sizeof(addr)); plenbytes = (plen + 7) / 8; ND_TCHECK2(pptr[4], plenbytes); ITEMCHECK(plenbytes); memcpy(&addr, &pptr[4], plenbytes); if (plen % 8) { ((u_char *)&addr)[plenbytes - 1] &= ((0xff00 >> (plen % 8)) & 0xff); } /* the label may get offsetted by 4 bits so lets shift it right */ snprintf(buf, buflen, "%s/%d, label:%u %s", ipaddr_string(ndo, &addr), plen, EXTRACT_24BITS(pptr+1)>>4, ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" ); return 4 + plenbytes; trunc: return -2; badtlv: return -3; } /* * bgp_vpn_ip_print * * print an ipv4 or ipv6 address into a buffer dependend on address length. */ static char * bgp_vpn_ip_print(netdissect_options *ndo, const u_char *pptr, u_int addr_length) { /* worst case string is s fully formatted v6 address */ static char addr[sizeof("1234:5678:89ab:cdef:1234:5678:89ab:cdef")]; char *pos = addr; switch(addr_length) { case (sizeof(struct in_addr) << 3): /* 32 */ ND_TCHECK2(pptr[0], sizeof(struct in_addr)); snprintf(pos, sizeof(addr), "%s", ipaddr_string(ndo, pptr)); break; case (sizeof(struct in6_addr) << 3): /* 128 */ ND_TCHECK2(pptr[0], sizeof(struct in6_addr)); snprintf(pos, sizeof(addr), "%s", ip6addr_string(ndo, pptr)); break; default: snprintf(pos, sizeof(addr), "bogus address length %u", addr_length); break; } pos += strlen(pos); trunc: *(pos) = '\0'; return (addr); } /* * bgp_vpn_sg_print * * print an multicast s,g entry into a buffer. * the s,g entry is encoded like this. * * +-----------------------------------+ * | Multicast Source Length (1 octet) | * +-----------------------------------+ * | Multicast Source (Variable) | * +-----------------------------------+ * | Multicast Group Length (1 octet) | * +-----------------------------------+ * | Multicast Group (Variable) | * +-----------------------------------+ * * return the number of bytes read from the wire. */ static int bgp_vpn_sg_print(netdissect_options *ndo, const u_char *pptr, char *buf, u_int buflen) { uint8_t addr_length; u_int total_length, offset; total_length = 0; /* Source address length, encoded in bits */ ND_TCHECK2(pptr[0], 1); addr_length = *pptr++; /* Source address */ ND_TCHECK2(pptr[0], (addr_length >> 3)); total_length += (addr_length >> 3) + 1; offset = strlen(buf); if (addr_length) { snprintf(buf + offset, buflen - offset, ", Source %s", bgp_vpn_ip_print(ndo, pptr, addr_length)); pptr += (addr_length >> 3); } /* Group address length, encoded in bits */ ND_TCHECK2(pptr[0], 1); addr_length = *pptr++; /* Group address */ ND_TCHECK2(pptr[0], (addr_length >> 3)); total_length += (addr_length >> 3) + 1; offset = strlen(buf); if (addr_length) { snprintf(buf + offset, buflen - offset, ", Group %s", bgp_vpn_ip_print(ndo, pptr, addr_length)); pptr += (addr_length >> 3); } trunc: return (total_length); } /* RDs and RTs share the same semantics * we use bgp_vpn_rd_print for * printing route targets inside a NLRI */ char * bgp_vpn_rd_print(netdissect_options *ndo, const u_char *pptr) { /* allocate space for the largest possible string */ static char rd[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")]; char *pos = rd; /* ok lets load the RD format */ switch (EXTRACT_16BITS(pptr)) { /* 2-byte-AS:number fmt*/ case 0: snprintf(pos, sizeof(rd) - (pos - rd), "%u:%u (= %u.%u.%u.%u)", EXTRACT_16BITS(pptr+2), EXTRACT_32BITS(pptr+4), *(pptr+4), *(pptr+5), *(pptr+6), *(pptr+7)); break; /* IP-address:AS fmt*/ case 1: snprintf(pos, sizeof(rd) - (pos - rd), "%u.%u.%u.%u:%u", *(pptr+2), *(pptr+3), *(pptr+4), *(pptr+5), EXTRACT_16BITS(pptr+6)); break; /* 4-byte-AS:number fmt*/ case 2: snprintf(pos, sizeof(rd) - (pos - rd), "%s:%u (%u.%u.%u.%u:%u)", as_printf(ndo, astostr, sizeof(astostr), EXTRACT_32BITS(pptr+2)), EXTRACT_16BITS(pptr+6), *(pptr+2), *(pptr+3), *(pptr+4), *(pptr+5), EXTRACT_16BITS(pptr+6)); break; default: snprintf(pos, sizeof(rd) - (pos - rd), "unknown RD format"); break; } pos += strlen(pos); *(pos) = '\0'; return (rd); } static int decode_rt_routing_info(netdissect_options *ndo, const u_char *pptr, char *buf, u_int buflen) { uint8_t route_target[8]; u_int plen; char asbuf[sizeof(astostr)]; /* bgp_vpn_rd_print() overwrites astostr */ /* NLRI "prefix length" from RFC 2858 Section 4. */ ND_TCHECK(pptr[0]); plen = pptr[0]; /* get prefix length */ /* NLRI "prefix" (ibid), valid lengths are { 0, 32, 33, ..., 96 } bits. * RFC 4684 Section 4 defines the layout of "origin AS" and "route * target" fields inside the "prefix" depending on its length. */ if (0 == plen) { /* Without "origin AS", without "route target". */ snprintf(buf, buflen, "default route target"); return 1; } if (32 > plen) return -1; /* With at least "origin AS", possibly with "route target". */ ND_TCHECK_32BITS(pptr + 1); as_printf(ndo, asbuf, sizeof(asbuf), EXTRACT_32BITS(pptr + 1)); plen-=32; /* adjust prefix length */ if (64 < plen) return -1; /* From now on (plen + 7) / 8 evaluates to { 0, 1, 2, ..., 8 } * and gives the number of octets in the variable-length "route * target" field inside this NLRI "prefix". Look for it. */ memset(&route_target, 0, sizeof(route_target)); ND_TCHECK2(pptr[5], (plen + 7) / 8); memcpy(&route_target, &pptr[5], (plen + 7) / 8); /* Which specification says to do this? */ if (plen % 8) { ((u_char *)&route_target)[(plen + 7) / 8 - 1] &= ((0xff00 >> (plen % 8)) & 0xff); } snprintf(buf, buflen, "origin AS: %s, route target %s", asbuf, bgp_vpn_rd_print(ndo, (u_char *)&route_target)); return 5 + (plen + 7) / 8; trunc: return -2; } static int decode_labeled_vpn_prefix4(netdissect_options *ndo, const u_char *pptr, char *buf, u_int buflen) { struct in_addr addr; u_int plen; ND_TCHECK(pptr[0]); plen = pptr[0]; /* get prefix length */ if ((24+64) > plen) return -1; plen-=(24+64); /* adjust prefixlen - labellength - RD len*/ if (32 < plen) return -1; memset(&addr, 0, sizeof(addr)); ND_TCHECK2(pptr[12], (plen + 7) / 8); memcpy(&addr, &pptr[12], (plen + 7) / 8); if (plen % 8) { ((u_char *)&addr)[(plen + 7) / 8 - 1] &= ((0xff00 >> (plen % 8)) & 0xff); } /* the label may get offsetted by 4 bits so lets shift it right */ snprintf(buf, buflen, "RD: %s, %s/%d, label:%u %s", bgp_vpn_rd_print(ndo, pptr+4), ipaddr_string(ndo, &addr), plen, EXTRACT_24BITS(pptr+1)>>4, ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" ); return 12 + (plen + 7) / 8; trunc: return -2; } /* * +-------------------------------+ * | | * | RD:IPv4-address (12 octets) | * | | * +-------------------------------+ * | MDT Group-address (4 octets) | * +-------------------------------+ */ #define MDT_VPN_NLRI_LEN 16 static int decode_mdt_vpn_nlri(netdissect_options *ndo, const u_char *pptr, char *buf, u_int buflen) { const u_char *rd; const u_char *vpn_ip; ND_TCHECK(pptr[0]); /* if the NLRI is not predefined length, quit.*/ if (*pptr != MDT_VPN_NLRI_LEN * 8) return -1; pptr++; /* RD */ ND_TCHECK2(pptr[0], 8); rd = pptr; pptr+=8; /* IPv4 address */ ND_TCHECK2(pptr[0], sizeof(struct in_addr)); vpn_ip = pptr; pptr+=sizeof(struct in_addr); /* MDT Group Address */ ND_TCHECK2(pptr[0], sizeof(struct in_addr)); snprintf(buf, buflen, "RD: %s, VPN IP Address: %s, MC Group Address: %s", bgp_vpn_rd_print(ndo, rd), ipaddr_string(ndo, vpn_ip), ipaddr_string(ndo, pptr)); return MDT_VPN_NLRI_LEN + 1; trunc: return -2; } #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7 static const struct tok bgp_multicast_vpn_route_type_values[] = { { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI, "Intra-AS I-PMSI"}, { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI, "Inter-AS I-PMSI"}, { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI, "S-PMSI"}, { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF, "Intra-AS Segment-Leaf"}, { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE, "Source-Active"}, { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN, "Shared Tree Join"}, { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN, "Source Tree Join"}, { 0, NULL} }; static int decode_multicast_vpn(netdissect_options *ndo, const u_char *pptr, char *buf, u_int buflen) { uint8_t route_type, route_length, addr_length, sg_length; u_int offset; ND_TCHECK2(pptr[0], 2); route_type = *pptr++; route_length = *pptr++; snprintf(buf, buflen, "Route-Type: %s (%u), length: %u", tok2str(bgp_multicast_vpn_route_type_values, "Unknown", route_type), route_type, route_length); switch(route_type) { case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI: ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN); offset = strlen(buf); snprintf(buf + offset, buflen - offset, ", RD: %s, Originator %s", bgp_vpn_rd_print(ndo, pptr), bgp_vpn_ip_print(ndo, pptr + BGP_VPN_RD_LEN, (route_length - BGP_VPN_RD_LEN) << 3)); break; case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI: ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN + 4); offset = strlen(buf); snprintf(buf + offset, buflen - offset, ", RD: %s, Source-AS %s", bgp_vpn_rd_print(ndo, pptr), as_printf(ndo, astostr, sizeof(astostr), EXTRACT_32BITS(pptr + BGP_VPN_RD_LEN))); break; case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI: ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN); offset = strlen(buf); snprintf(buf + offset, buflen - offset, ", RD: %s", bgp_vpn_rd_print(ndo, pptr)); pptr += BGP_VPN_RD_LEN; sg_length = bgp_vpn_sg_print(ndo, pptr, buf, buflen); addr_length = route_length - sg_length; ND_TCHECK2(pptr[0], addr_length); offset = strlen(buf); snprintf(buf + offset, buflen - offset, ", Originator %s", bgp_vpn_ip_print(ndo, pptr, addr_length << 3)); break; case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE: ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN); offset = strlen(buf); snprintf(buf + offset, buflen - offset, ", RD: %s", bgp_vpn_rd_print(ndo, pptr)); pptr += BGP_VPN_RD_LEN; bgp_vpn_sg_print(ndo, pptr, buf, buflen); break; case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN: /* fall through */ case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN: ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN + 4); offset = strlen(buf); snprintf(buf + offset, buflen - offset, ", RD: %s, Source-AS %s", bgp_vpn_rd_print(ndo, pptr), as_printf(ndo, astostr, sizeof(astostr), EXTRACT_32BITS(pptr + BGP_VPN_RD_LEN))); pptr += BGP_VPN_RD_LEN + 4; bgp_vpn_sg_print(ndo, pptr, buf, buflen); break; /* * no per route-type printing yet. */ case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF: default: break; } return route_length + 2; trunc: return -2; } /* * As I remember, some versions of systems have an snprintf() that * returns -1 if the buffer would have overflowed. If the return * value is negative, set buflen to 0, to indicate that we've filled * the buffer up. * * If the return value is greater than buflen, that means that * the buffer would have overflowed; again, set buflen to 0 in * that case. */ #define UPDATE_BUF_BUFLEN(buf, buflen, stringlen) \ if (stringlen<0) \ buflen=0; \ else if ((u_int)stringlen>buflen) \ buflen=0; \ else { \ buflen-=stringlen; \ buf+=stringlen; \ } static int decode_labeled_vpn_l2(netdissect_options *ndo, const u_char *pptr, char *buf, u_int buflen) { int plen,tlen,stringlen,tlv_type,tlv_len,ttlv_len; ND_TCHECK2(pptr[0], 2); plen=EXTRACT_16BITS(pptr); tlen=plen; pptr+=2; /* Old and new L2VPN NLRI share AFI/SAFI * -> Assume a 12 Byte-length NLRI is auto-discovery-only * and > 17 as old format. Complain for the middle case */ if (plen==12) { /* assume AD-only with RD, BGPNH */ ND_TCHECK2(pptr[0],12); buf[0]='\0'; stringlen=snprintf(buf, buflen, "RD: %s, BGPNH: %s", bgp_vpn_rd_print(ndo, pptr), ipaddr_string(ndo, pptr+8) ); UPDATE_BUF_BUFLEN(buf, buflen, stringlen); pptr+=12; tlen-=12; return plen; } else if (plen>17) { /* assume old format */ /* RD, ID, LBLKOFF, LBLBASE */ ND_TCHECK2(pptr[0],15); buf[0]='\0'; stringlen=snprintf(buf, buflen, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u", bgp_vpn_rd_print(ndo, pptr), EXTRACT_16BITS(pptr+8), EXTRACT_16BITS(pptr+10), EXTRACT_24BITS(pptr+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */ UPDATE_BUF_BUFLEN(buf, buflen, stringlen); pptr+=15; tlen-=15; /* ok now the variable part - lets read out TLVs*/ while (tlen>0) { if (tlen < 3) return -1; ND_TCHECK2(pptr[0], 3); tlv_type=*pptr++; tlv_len=EXTRACT_16BITS(pptr); ttlv_len=tlv_len; pptr+=2; switch(tlv_type) { case 1: if (buflen!=0) { stringlen=snprintf(buf,buflen, "\n\t\tcircuit status vector (%u) length: %u: 0x", tlv_type, tlv_len); UPDATE_BUF_BUFLEN(buf, buflen, stringlen); } ttlv_len=ttlv_len/8+1; /* how many bytes do we need to read ? */ while (ttlv_len>0) { ND_TCHECK(pptr[0]); if (buflen!=0) { stringlen=snprintf(buf,buflen, "%02x",*pptr++); UPDATE_BUF_BUFLEN(buf, buflen, stringlen); } ttlv_len--; } break; default: if (buflen!=0) { stringlen=snprintf(buf,buflen, "\n\t\tunknown TLV #%u, length: %u", tlv_type, tlv_len); UPDATE_BUF_BUFLEN(buf, buflen, stringlen); } break; } tlen-=(tlv_len<<3); /* the tlv-length is expressed in bits so lets shift it right */ } return plen+2; } else { /* complain bitterly ? */ /* fall through */ goto trunc; } trunc: return -2; } int decode_prefix6(netdissect_options *ndo, const u_char *pd, u_int itemlen, char *buf, u_int buflen) { struct in6_addr addr; u_int plen, plenbytes; ND_TCHECK(pd[0]); ITEMCHECK(1); plen = pd[0]; if (128 < plen) return -1; itemlen -= 1; memset(&addr, 0, sizeof(addr)); plenbytes = (plen + 7) / 8; ND_TCHECK2(pd[1], plenbytes); ITEMCHECK(plenbytes); memcpy(&addr, &pd[1], plenbytes); if (plen % 8) { addr.s6_addr[plenbytes - 1] &= ((0xff00 >> (plen % 8)) & 0xff); } snprintf(buf, buflen, "%s/%d", ip6addr_string(ndo, &addr), plen); return 1 + plenbytes; trunc: return -2; badtlv: return -3; } static int decode_labeled_prefix6(netdissect_options *ndo, const u_char *pptr, u_int itemlen, char *buf, u_int buflen) { struct in6_addr addr; u_int plen, plenbytes; /* prefix length and label = 4 bytes */ ND_TCHECK2(pptr[0], 4); ITEMCHECK(4); plen = pptr[0]; /* get prefix length */ if (24 > plen) return -1; plen-=24; /* adjust prefixlen - labellength */ if (128 < plen) return -1; itemlen -= 4; memset(&addr, 0, sizeof(addr)); plenbytes = (plen + 7) / 8; ND_TCHECK2(pptr[4], plenbytes); memcpy(&addr, &pptr[4], plenbytes); if (plen % 8) { addr.s6_addr[plenbytes - 1] &= ((0xff00 >> (plen % 8)) & 0xff); } /* the label may get offsetted by 4 bits so lets shift it right */ snprintf(buf, buflen, "%s/%d, label:%u %s", ip6addr_string(ndo, &addr), plen, EXTRACT_24BITS(pptr+1)>>4, ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" ); return 4 + plenbytes; trunc: return -2; badtlv: return -3; } static int decode_labeled_vpn_prefix6(netdissect_options *ndo, const u_char *pptr, char *buf, u_int buflen) { struct in6_addr addr; u_int plen; ND_TCHECK(pptr[0]); plen = pptr[0]; /* get prefix length */ if ((24+64) > plen) return -1; plen-=(24+64); /* adjust prefixlen - labellength - RD len*/ if (128 < plen) return -1; memset(&addr, 0, sizeof(addr)); ND_TCHECK2(pptr[12], (plen + 7) / 8); memcpy(&addr, &pptr[12], (plen + 7) / 8); if (plen % 8) { addr.s6_addr[(plen + 7) / 8 - 1] &= ((0xff00 >> (plen % 8)) & 0xff); } /* the label may get offsetted by 4 bits so lets shift it right */ snprintf(buf, buflen, "RD: %s, %s/%d, label:%u %s", bgp_vpn_rd_print(ndo, pptr+4), ip6addr_string(ndo, &addr), plen, EXTRACT_24BITS(pptr+1)>>4, ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" ); return 12 + (plen + 7) / 8; trunc: return -2; } static int decode_clnp_prefix(netdissect_options *ndo, const u_char *pptr, char *buf, u_int buflen) { uint8_t addr[19]; u_int plen; ND_TCHECK(pptr[0]); plen = pptr[0]; /* get prefix length */ if (152 < plen) return -1; memset(&addr, 0, sizeof(addr)); ND_TCHECK2(pptr[4], (plen + 7) / 8); memcpy(&addr, &pptr[4], (plen + 7) / 8); if (plen % 8) { addr[(plen + 7) / 8 - 1] &= ((0xff00 >> (plen % 8)) & 0xff); } snprintf(buf, buflen, "%s/%d", isonsap_string(ndo, addr,(plen + 7) / 8), plen); return 1 + (plen + 7) / 8; trunc: return -2; } static int decode_labeled_vpn_clnp_prefix(netdissect_options *ndo, const u_char *pptr, char *buf, u_int buflen) { uint8_t addr[19]; u_int plen; ND_TCHECK(pptr[0]); plen = pptr[0]; /* get prefix length */ if ((24+64) > plen) return -1; plen-=(24+64); /* adjust prefixlen - labellength - RD len*/ if (152 < plen) return -1; memset(&addr, 0, sizeof(addr)); ND_TCHECK2(pptr[12], (plen + 7) / 8); memcpy(&addr, &pptr[12], (plen + 7) / 8); if (plen % 8) { addr[(plen + 7) / 8 - 1] &= ((0xff00 >> (plen % 8)) & 0xff); } /* the label may get offsetted by 4 bits so lets shift it right */ snprintf(buf, buflen, "RD: %s, %s/%d, label:%u %s", bgp_vpn_rd_print(ndo, pptr+4), isonsap_string(ndo, addr,(plen + 7) / 8), plen, EXTRACT_24BITS(pptr+1)>>4, ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" ); return 12 + (plen + 7) / 8; trunc: return -2; } /* * bgp_attr_get_as_size * * Try to find the size of the ASs encoded in an as-path. It is not obvious, as * both Old speakers that do not support 4 byte AS, and the new speakers that do * support, exchange AS-Path with the same path-attribute type value 0x02. */ static int bgp_attr_get_as_size(netdissect_options *ndo, uint8_t bgpa_type, const u_char *pptr, int len) { const u_char *tptr = pptr; /* * If the path attribute is the optional AS4 path type, then we already * know, that ASs must be encoded in 4 byte format. */ if (bgpa_type == BGPTYPE_AS4_PATH) { return 4; } /* * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes * each. */ while (tptr < pptr + len) { ND_TCHECK(tptr[0]); /* * If we do not find a valid segment type, our guess might be wrong. */ if (tptr[0] < BGP_AS_SEG_TYPE_MIN || tptr[0] > BGP_AS_SEG_TYPE_MAX) { goto trunc; } ND_TCHECK(tptr[1]); tptr += 2 + tptr[1] * 2; } /* * If we correctly reached end of the AS path attribute data content, * then most likely ASs were indeed encoded as 2 bytes. */ if (tptr == pptr + len) { return 2; } trunc: /* * We can come here, either we did not have enough data, or if we * try to decode 4 byte ASs in 2 byte format. Either way, return 4, * so that calller can try to decode each AS as of 4 bytes. If indeed * there was not enough data, it will crib and end the parse anyways. */ return 4; } static int bgp_attr_print(netdissect_options *ndo, u_int atype, const u_char *pptr, u_int len, const unsigned attr_set_level) { int i; uint16_t af; uint8_t safi, snpa, nhlen; union { /* copy buffer for bandwidth values */ float f; uint32_t i; } bw; int advance; u_int tlen; const u_char *tptr; char buf[MAXHOSTNAMELEN + 100]; int as_size; tptr = pptr; tlen=len; switch (atype) { case BGPTYPE_ORIGIN: if (len != 1) ND_PRINT((ndo, "invalid len")); else { ND_TCHECK(*tptr); ND_PRINT((ndo, "%s", tok2str(bgp_origin_values, "Unknown Origin Typecode", tptr[0]))); } break; /* * Process AS4 byte path and AS2 byte path attributes here. */ case BGPTYPE_AS4_PATH: case BGPTYPE_AS_PATH: if (len % 2) { ND_PRINT((ndo, "invalid len")); break; } if (!len) { ND_PRINT((ndo, "empty")); break; } /* * BGP updates exchanged between New speakers that support 4 * byte AS, ASs are always encoded in 4 bytes. There is no * definitive way to find this, just by the packet's * contents. So, check for packet's TLV's sanity assuming * 2 bytes first, and it does not pass, assume that ASs are * encoded in 4 bytes format and move on. */ as_size = bgp_attr_get_as_size(ndo, atype, pptr, len); while (tptr < pptr + len) { ND_TCHECK(tptr[0]); ND_PRINT((ndo, "%s", tok2str(bgp_as_path_segment_open_values, "?", tptr[0]))); ND_TCHECK(tptr[1]); for (i = 0; i < tptr[1] * as_size; i += as_size) { ND_TCHECK2(tptr[2 + i], as_size); ND_PRINT((ndo, "%s ", as_printf(ndo, astostr, sizeof(astostr), as_size == 2 ? EXTRACT_16BITS(&tptr[2 + i]) : EXTRACT_32BITS(&tptr[2 + i])))); } ND_TCHECK(tptr[0]); ND_PRINT((ndo, "%s", tok2str(bgp_as_path_segment_close_values, "?", tptr[0]))); ND_TCHECK(tptr[1]); tptr += 2 + tptr[1] * as_size; } break; case BGPTYPE_NEXT_HOP: if (len != 4) ND_PRINT((ndo, "invalid len")); else { ND_TCHECK2(tptr[0], 4); ND_PRINT((ndo, "%s", ipaddr_string(ndo, tptr))); } break; case BGPTYPE_MULTI_EXIT_DISC: case BGPTYPE_LOCAL_PREF: if (len != 4) ND_PRINT((ndo, "invalid len")); else { ND_TCHECK2(tptr[0], 4); ND_PRINT((ndo, "%u", EXTRACT_32BITS(tptr))); } break; case BGPTYPE_ATOMIC_AGGREGATE: if (len != 0) ND_PRINT((ndo, "invalid len")); break; case BGPTYPE_AGGREGATOR: /* * Depending on the AS encoded is of 2 bytes or of 4 bytes, * the length of this PA can be either 6 bytes or 8 bytes. */ if (len != 6 && len != 8) { ND_PRINT((ndo, "invalid len")); break; } ND_TCHECK2(tptr[0], len); if (len == 6) { ND_PRINT((ndo, " AS #%s, origin %s", as_printf(ndo, astostr, sizeof(astostr), EXTRACT_16BITS(tptr)), ipaddr_string(ndo, tptr + 2))); } else { ND_PRINT((ndo, " AS #%s, origin %s", as_printf(ndo, astostr, sizeof(astostr), EXTRACT_32BITS(tptr)), ipaddr_string(ndo, tptr + 4))); } break; case BGPTYPE_AGGREGATOR4: if (len != 8) { ND_PRINT((ndo, "invalid len")); break; } ND_TCHECK2(tptr[0], 8); ND_PRINT((ndo, " AS #%s, origin %s", as_printf(ndo, astostr, sizeof(astostr), EXTRACT_32BITS(tptr)), ipaddr_string(ndo, tptr + 4))); break; case BGPTYPE_COMMUNITIES: if (len % 4) { ND_PRINT((ndo, "invalid len")); break; } while (tlen>0) { uint32_t comm; ND_TCHECK2(tptr[0], 4); comm = EXTRACT_32BITS(tptr); switch (comm) { case BGP_COMMUNITY_NO_EXPORT: ND_PRINT((ndo, " NO_EXPORT")); break; case BGP_COMMUNITY_NO_ADVERT: ND_PRINT((ndo, " NO_ADVERTISE")); break; case BGP_COMMUNITY_NO_EXPORT_SUBCONFED: ND_PRINT((ndo, " NO_EXPORT_SUBCONFED")); break; default: ND_PRINT((ndo, "%u:%u%s", (comm >> 16) & 0xffff, comm & 0xffff, (tlen>4) ? ", " : "")); break; } tlen -=4; tptr +=4; } break; case BGPTYPE_ORIGINATOR_ID: if (len != 4) { ND_PRINT((ndo, "invalid len")); break; } ND_TCHECK2(tptr[0], 4); ND_PRINT((ndo, "%s",ipaddr_string(ndo, tptr))); break; case BGPTYPE_CLUSTER_LIST: if (len % 4) { ND_PRINT((ndo, "invalid len")); break; } while (tlen>0) { ND_TCHECK2(tptr[0], 4); ND_PRINT((ndo, "%s%s", ipaddr_string(ndo, tptr), (tlen>4) ? ", " : "")); tlen -=4; tptr +=4; } break; case BGPTYPE_MP_REACH_NLRI: ND_TCHECK2(tptr[0], 3); af = EXTRACT_16BITS(tptr); safi = tptr[2]; ND_PRINT((ndo, "\n\t AFI: %s (%u), %sSAFI: %s (%u)", tok2str(af_values, "Unknown AFI", af), af, (safi>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */ tok2str(bgp_safi_values, "Unknown SAFI", safi), safi)); switch(af<<8 | safi) { case (AFNUM_INET<<8 | SAFNUM_UNICAST): case (AFNUM_INET<<8 | SAFNUM_MULTICAST): case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST): case (AFNUM_INET<<8 | SAFNUM_LABUNICAST): case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO): case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST): case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST): case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST): case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN): case (AFNUM_INET<<8 | SAFNUM_MDT): case (AFNUM_INET6<<8 | SAFNUM_UNICAST): case (AFNUM_INET6<<8 | SAFNUM_MULTICAST): case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST): case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST): case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST): case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST): case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST): case (AFNUM_NSAP<<8 | SAFNUM_UNICAST): case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST): case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST): case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST): case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST): case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST): case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST): case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST): case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST): case (AFNUM_VPLS<<8 | SAFNUM_VPLS): break; default: ND_TCHECK2(tptr[0], tlen); ND_PRINT((ndo, "\n\t no AFI %u / SAFI %u decoder", af, safi)); if (ndo->ndo_vflag <= 1) print_unknown_data(ndo, tptr, "\n\t ", tlen); goto done; break; } tptr +=3; ND_TCHECK(tptr[0]); nhlen = tptr[0]; tlen = nhlen; tptr++; if (tlen) { int nnh = 0; ND_PRINT((ndo, "\n\t nexthop: ")); while (tlen > 0) { if ( nnh++ > 0 ) { ND_PRINT((ndo, ", " )); } switch(af<<8 | safi) { case (AFNUM_INET<<8 | SAFNUM_UNICAST): case (AFNUM_INET<<8 | SAFNUM_MULTICAST): case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST): case (AFNUM_INET<<8 | SAFNUM_LABUNICAST): case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO): case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN): case (AFNUM_INET<<8 | SAFNUM_MDT): if (tlen < (int)sizeof(struct in_addr)) { ND_PRINT((ndo, "invalid len")); tlen = 0; } else { ND_TCHECK2(tptr[0], sizeof(struct in_addr)); ND_PRINT((ndo, "%s",ipaddr_string(ndo, tptr))); tlen -= sizeof(struct in_addr); tptr += sizeof(struct in_addr); } break; case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST): case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST): case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST): if (tlen < (int)(sizeof(struct in_addr)+BGP_VPN_RD_LEN)) { ND_PRINT((ndo, "invalid len")); tlen = 0; } else { ND_TCHECK2(tptr[0], sizeof(struct in_addr)+BGP_VPN_RD_LEN); ND_PRINT((ndo, "RD: %s, %s", bgp_vpn_rd_print(ndo, tptr), ipaddr_string(ndo, tptr+BGP_VPN_RD_LEN))); tlen -= (sizeof(struct in_addr)+BGP_VPN_RD_LEN); tptr += (sizeof(struct in_addr)+BGP_VPN_RD_LEN); } break; case (AFNUM_INET6<<8 | SAFNUM_UNICAST): case (AFNUM_INET6<<8 | SAFNUM_MULTICAST): case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST): case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST): if (tlen < (int)sizeof(struct in6_addr)) { ND_PRINT((ndo, "invalid len")); tlen = 0; } else { ND_TCHECK2(tptr[0], sizeof(struct in6_addr)); ND_PRINT((ndo, "%s", ip6addr_string(ndo, tptr))); tlen -= sizeof(struct in6_addr); tptr += sizeof(struct in6_addr); } break; case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST): case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST): case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST): if (tlen < (int)(sizeof(struct in6_addr)+BGP_VPN_RD_LEN)) { ND_PRINT((ndo, "invalid len")); tlen = 0; } else { ND_TCHECK2(tptr[0], sizeof(struct in6_addr)+BGP_VPN_RD_LEN); ND_PRINT((ndo, "RD: %s, %s", bgp_vpn_rd_print(ndo, tptr), ip6addr_string(ndo, tptr+BGP_VPN_RD_LEN))); tlen -= (sizeof(struct in6_addr)+BGP_VPN_RD_LEN); tptr += (sizeof(struct in6_addr)+BGP_VPN_RD_LEN); } break; case (AFNUM_VPLS<<8 | SAFNUM_VPLS): case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST): case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST): case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST): if (tlen < (int)sizeof(struct in_addr)) { ND_PRINT((ndo, "invalid len")); tlen = 0; } else { ND_TCHECK2(tptr[0], sizeof(struct in_addr)); ND_PRINT((ndo, "%s", ipaddr_string(ndo, tptr))); tlen -= (sizeof(struct in_addr)); tptr += (sizeof(struct in_addr)); } break; case (AFNUM_NSAP<<8 | SAFNUM_UNICAST): case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST): case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST): ND_TCHECK2(tptr[0], tlen); ND_PRINT((ndo, "%s", isonsap_string(ndo, tptr, tlen))); tptr += tlen; tlen = 0; break; case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST): case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST): case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST): if (tlen < BGP_VPN_RD_LEN+1) { ND_PRINT((ndo, "invalid len")); tlen = 0; } else { ND_TCHECK2(tptr[0], tlen); ND_PRINT((ndo, "RD: %s, %s", bgp_vpn_rd_print(ndo, tptr), isonsap_string(ndo, tptr+BGP_VPN_RD_LEN,tlen-BGP_VPN_RD_LEN))); /* rfc986 mapped IPv4 address ? */ if (tlen == BGP_VPN_RD_LEN + 4 + sizeof(struct in_addr) && EXTRACT_32BITS(tptr+BGP_VPN_RD_LEN) == 0x47000601) ND_PRINT((ndo, " = %s", ipaddr_string(ndo, tptr+BGP_VPN_RD_LEN+4))); /* rfc1888 mapped IPv6 address ? */ else if (tlen == BGP_VPN_RD_LEN + 3 + sizeof(struct in6_addr) && EXTRACT_24BITS(tptr+BGP_VPN_RD_LEN) == 0x350000) ND_PRINT((ndo, " = %s", ip6addr_string(ndo, tptr+BGP_VPN_RD_LEN+3))); tptr += tlen; tlen = 0; } break; default: ND_TCHECK2(tptr[0], tlen); ND_PRINT((ndo, "no AFI %u/SAFI %u decoder", af, safi)); if (ndo->ndo_vflag <= 1) print_unknown_data(ndo, tptr, "\n\t ", tlen); tptr += tlen; tlen = 0; goto done; break; } } } ND_PRINT((ndo, ", nh-length: %u", nhlen)); tptr += tlen; ND_TCHECK(tptr[0]); snpa = tptr[0]; tptr++; if (snpa) { ND_PRINT((ndo, "\n\t %u SNPA", snpa)); for (/*nothing*/; snpa > 0; snpa--) { ND_TCHECK(tptr[0]); ND_PRINT((ndo, "\n\t %d bytes", tptr[0])); tptr += tptr[0] + 1; } } else { ND_PRINT((ndo, ", no SNPA")); } while (tptr < pptr + len) { switch (af<<8 | safi) { case (AFNUM_INET<<8 | SAFNUM_UNICAST): case (AFNUM_INET<<8 | SAFNUM_MULTICAST): case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST): advance = decode_prefix4(ndo, tptr, len, buf, sizeof(buf)); if (advance == -1) ND_PRINT((ndo, "\n\t (illegal prefix length)")); else if (advance == -2) goto trunc; else if (advance == -3) break; /* bytes left, but not enough */ else ND_PRINT((ndo, "\n\t %s", buf)); break; case (AFNUM_INET<<8 | SAFNUM_LABUNICAST): advance = decode_labeled_prefix4(ndo, tptr, len, buf, sizeof(buf)); if (advance == -1) ND_PRINT((ndo, "\n\t (illegal prefix length)")); else if (advance == -2) goto trunc; else if (advance == -3) break; /* bytes left, but not enough */ else ND_PRINT((ndo, "\n\t %s", buf)); break; case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST): case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST): case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST): advance = decode_labeled_vpn_prefix4(ndo, tptr, buf, sizeof(buf)); if (advance == -1) ND_PRINT((ndo, "\n\t (illegal prefix length)")); else if (advance == -2) goto trunc; else ND_PRINT((ndo, "\n\t %s", buf)); break; case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO): advance = decode_rt_routing_info(ndo, tptr, buf, sizeof(buf)); if (advance == -1) ND_PRINT((ndo, "\n\t (illegal prefix length)")); else if (advance == -2) goto trunc; else ND_PRINT((ndo, "\n\t %s", buf)); break; case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN): /* fall through */ case (AFNUM_INET6<<8 | SAFNUM_MULTICAST_VPN): advance = decode_multicast_vpn(ndo, tptr, buf, sizeof(buf)); if (advance == -1) ND_PRINT((ndo, "\n\t (illegal prefix length)")); else if (advance == -2) goto trunc; else ND_PRINT((ndo, "\n\t %s", buf)); break; case (AFNUM_INET<<8 | SAFNUM_MDT): advance = decode_mdt_vpn_nlri(ndo, tptr, buf, sizeof(buf)); if (advance == -1) ND_PRINT((ndo, "\n\t (illegal prefix length)")); else if (advance == -2) goto trunc; else ND_PRINT((ndo, "\n\t %s", buf)); break; case (AFNUM_INET6<<8 | SAFNUM_UNICAST): case (AFNUM_INET6<<8 | SAFNUM_MULTICAST): case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST): advance = decode_prefix6(ndo, tptr, len, buf, sizeof(buf)); if (advance == -1) ND_PRINT((ndo, "\n\t (illegal prefix length)")); else if (advance == -2) goto trunc; else if (advance == -3) break; /* bytes left, but not enough */ else ND_PRINT((ndo, "\n\t %s", buf)); break; case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST): advance = decode_labeled_prefix6(ndo, tptr, len, buf, sizeof(buf)); if (advance == -1) ND_PRINT((ndo, "\n\t (illegal prefix length)")); else if (advance == -2) goto trunc; else if (advance == -3) break; /* bytes left, but not enough */ else ND_PRINT((ndo, "\n\t %s", buf)); break; case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST): case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST): case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST): advance = decode_labeled_vpn_prefix6(ndo, tptr, buf, sizeof(buf)); if (advance == -1) ND_PRINT((ndo, "\n\t (illegal prefix length)")); else if (advance == -2) goto trunc; else ND_PRINT((ndo, "\n\t %s", buf)); break; case (AFNUM_VPLS<<8 | SAFNUM_VPLS): case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST): case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST): case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST): advance = decode_labeled_vpn_l2(ndo, tptr, buf, sizeof(buf)); if (advance == -1) ND_PRINT((ndo, "\n\t (illegal length)")); else if (advance == -2) goto trunc; else ND_PRINT((ndo, "\n\t %s", buf)); break; case (AFNUM_NSAP<<8 | SAFNUM_UNICAST): case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST): case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST): advance = decode_clnp_prefix(ndo, tptr, buf, sizeof(buf)); if (advance == -1) ND_PRINT((ndo, "\n\t (illegal prefix length)")); else if (advance == -2) goto trunc; else ND_PRINT((ndo, "\n\t %s", buf)); break; case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST): case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST): case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST): advance = decode_labeled_vpn_clnp_prefix(ndo, tptr, buf, sizeof(buf)); if (advance == -1) ND_PRINT((ndo, "\n\t (illegal prefix length)")); else if (advance == -2) goto trunc; else ND_PRINT((ndo, "\n\t %s", buf)); break; default: ND_TCHECK2(*tptr,tlen); ND_PRINT((ndo, "\n\t no AFI %u / SAFI %u decoder", af, safi)); if (ndo->ndo_vflag <= 1) print_unknown_data(ndo, tptr, "\n\t ", tlen); advance = 0; tptr = pptr + len; break; } if (advance < 0) break; tptr += advance; } done: break; case BGPTYPE_MP_UNREACH_NLRI: ND_TCHECK2(tptr[0], BGP_MP_NLRI_MINSIZE); af = EXTRACT_16BITS(tptr); safi = tptr[2]; ND_PRINT((ndo, "\n\t AFI: %s (%u), %sSAFI: %s (%u)", tok2str(af_values, "Unknown AFI", af), af, (safi>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */ tok2str(bgp_safi_values, "Unknown SAFI", safi), safi)); if (len == BGP_MP_NLRI_MINSIZE) ND_PRINT((ndo, "\n\t End-of-Rib Marker (empty NLRI)")); tptr += 3; while (tptr < pptr + len) { switch (af<<8 | safi) { case (AFNUM_INET<<8 | SAFNUM_UNICAST): case (AFNUM_INET<<8 | SAFNUM_MULTICAST): case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST): advance = decode_prefix4(ndo, tptr, len, buf, sizeof(buf)); if (advance == -1) ND_PRINT((ndo, "\n\t (illegal prefix length)")); else if (advance == -2) goto trunc; else if (advance == -3) break; /* bytes left, but not enough */ else ND_PRINT((ndo, "\n\t %s", buf)); break; case (AFNUM_INET<<8 | SAFNUM_LABUNICAST): advance = decode_labeled_prefix4(ndo, tptr, len, buf, sizeof(buf)); if (advance == -1) ND_PRINT((ndo, "\n\t (illegal prefix length)")); else if (advance == -2) goto trunc; else if (advance == -3) break; /* bytes left, but not enough */ else ND_PRINT((ndo, "\n\t %s", buf)); break; case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST): case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST): case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST): advance = decode_labeled_vpn_prefix4(ndo, tptr, buf, sizeof(buf)); if (advance == -1) ND_PRINT((ndo, "\n\t (illegal prefix length)")); else if (advance == -2) goto trunc; else ND_PRINT((ndo, "\n\t %s", buf)); break; case (AFNUM_INET6<<8 | SAFNUM_UNICAST): case (AFNUM_INET6<<8 | SAFNUM_MULTICAST): case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST): advance = decode_prefix6(ndo, tptr, len, buf, sizeof(buf)); if (advance == -1) ND_PRINT((ndo, "\n\t (illegal prefix length)")); else if (advance == -2) goto trunc; else if (advance == -3) break; /* bytes left, but not enough */ else ND_PRINT((ndo, "\n\t %s", buf)); break; case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST): advance = decode_labeled_prefix6(ndo, tptr, len, buf, sizeof(buf)); if (advance == -1) ND_PRINT((ndo, "\n\t (illegal prefix length)")); else if (advance == -2) goto trunc; else if (advance == -3) break; /* bytes left, but not enough */ else ND_PRINT((ndo, "\n\t %s", buf)); break; case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST): case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST): case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST): advance = decode_labeled_vpn_prefix6(ndo, tptr, buf, sizeof(buf)); if (advance == -1) ND_PRINT((ndo, "\n\t (illegal prefix length)")); else if (advance == -2) goto trunc; else ND_PRINT((ndo, "\n\t %s", buf)); break; case (AFNUM_VPLS<<8 | SAFNUM_VPLS): case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST): case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST): case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST): advance = decode_labeled_vpn_l2(ndo, tptr, buf, sizeof(buf)); if (advance == -1) ND_PRINT((ndo, "\n\t (illegal length)")); else if (advance == -2) goto trunc; else ND_PRINT((ndo, "\n\t %s", buf)); break; case (AFNUM_NSAP<<8 | SAFNUM_UNICAST): case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST): case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST): advance = decode_clnp_prefix(ndo, tptr, buf, sizeof(buf)); if (advance == -1) ND_PRINT((ndo, "\n\t (illegal prefix length)")); else if (advance == -2) goto trunc; else ND_PRINT((ndo, "\n\t %s", buf)); break; case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST): case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST): case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST): advance = decode_labeled_vpn_clnp_prefix(ndo, tptr, buf, sizeof(buf)); if (advance == -1) ND_PRINT((ndo, "\n\t (illegal prefix length)")); else if (advance == -2) goto trunc; else ND_PRINT((ndo, "\n\t %s", buf)); break; case (AFNUM_INET<<8 | SAFNUM_MDT): advance = decode_mdt_vpn_nlri(ndo, tptr, buf, sizeof(buf)); if (advance == -1) ND_PRINT((ndo, "\n\t (illegal prefix length)")); else if (advance == -2) goto trunc; else ND_PRINT((ndo, "\n\t %s", buf)); break; case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN): /* fall through */ case (AFNUM_INET6<<8 | SAFNUM_MULTICAST_VPN): advance = decode_multicast_vpn(ndo, tptr, buf, sizeof(buf)); if (advance == -1) ND_PRINT((ndo, "\n\t (illegal prefix length)")); else if (advance == -2) goto trunc; else ND_PRINT((ndo, "\n\t %s", buf)); break; default: ND_TCHECK2(*(tptr-3),tlen); ND_PRINT((ndo, "no AFI %u / SAFI %u decoder", af, safi)); if (ndo->ndo_vflag <= 1) print_unknown_data(ndo, tptr-3, "\n\t ", tlen); advance = 0; tptr = pptr + len; break; } if (advance < 0) break; tptr += advance; } break; case BGPTYPE_EXTD_COMMUNITIES: if (len % 8) { ND_PRINT((ndo, "invalid len")); break; } while (tlen>0) { uint16_t extd_comm; ND_TCHECK2(tptr[0], 2); extd_comm=EXTRACT_16BITS(tptr); ND_PRINT((ndo, "\n\t %s (0x%04x), Flags [%s]", tok2str(bgp_extd_comm_subtype_values, "unknown extd community typecode", extd_comm), extd_comm, bittok2str(bgp_extd_comm_flag_values, "none", extd_comm))); ND_TCHECK2(*(tptr+2), 6); switch(extd_comm) { case BGP_EXT_COM_RT_0: case BGP_EXT_COM_RO_0: case BGP_EXT_COM_L2VPN_RT_0: ND_PRINT((ndo, ": %u:%u (= %s)", EXTRACT_16BITS(tptr+2), EXTRACT_32BITS(tptr+4), ipaddr_string(ndo, tptr+4))); break; case BGP_EXT_COM_RT_1: case BGP_EXT_COM_RO_1: case BGP_EXT_COM_L2VPN_RT_1: case BGP_EXT_COM_VRF_RT_IMP: ND_PRINT((ndo, ": %s:%u", ipaddr_string(ndo, tptr+2), EXTRACT_16BITS(tptr+6))); break; case BGP_EXT_COM_RT_2: case BGP_EXT_COM_RO_2: ND_PRINT((ndo, ": %s:%u", as_printf(ndo, astostr, sizeof(astostr), EXTRACT_32BITS(tptr+2)), EXTRACT_16BITS(tptr+6))); break; case BGP_EXT_COM_LINKBAND: bw.i = EXTRACT_32BITS(tptr+2); ND_PRINT((ndo, ": bandwidth: %.3f Mbps", bw.f*8/1000000)); break; case BGP_EXT_COM_VPN_ORIGIN: case BGP_EXT_COM_VPN_ORIGIN2: case BGP_EXT_COM_VPN_ORIGIN3: case BGP_EXT_COM_VPN_ORIGIN4: case BGP_EXT_COM_OSPF_RID: case BGP_EXT_COM_OSPF_RID2: ND_PRINT((ndo, "%s", ipaddr_string(ndo, tptr+2))); break; case BGP_EXT_COM_OSPF_RTYPE: case BGP_EXT_COM_OSPF_RTYPE2: ND_PRINT((ndo, ": area:%s, router-type:%s, metric-type:%s%s", ipaddr_string(ndo, tptr+2), tok2str(bgp_extd_comm_ospf_rtype_values, "unknown (0x%02x)", *(tptr+6)), (*(tptr+7) & BGP_OSPF_RTYPE_METRIC_TYPE) ? "E2" : "", ((*(tptr+6) == BGP_OSPF_RTYPE_EXT) || (*(tptr+6) == BGP_OSPF_RTYPE_NSSA)) ? "E1" : "")); break; case BGP_EXT_COM_L2INFO: ND_PRINT((ndo, ": %s Control Flags [0x%02x]:MTU %u", tok2str(l2vpn_encaps_values, "unknown encaps", *(tptr+2)), *(tptr+3), EXTRACT_16BITS(tptr+4))); break; case BGP_EXT_COM_SOURCE_AS: ND_PRINT((ndo, ": AS %u", EXTRACT_16BITS(tptr+2))); break; default: ND_TCHECK2(*tptr,8); print_unknown_data(ndo, tptr, "\n\t ", 8); break; } tlen -=8; tptr +=8; } break; case BGPTYPE_PMSI_TUNNEL: { uint8_t tunnel_type, flags; ND_TCHECK2(tptr[0], 5); tunnel_type = *(tptr+1); flags = *tptr; tlen = len; ND_PRINT((ndo, "\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u", tok2str(bgp_pmsi_tunnel_values, "Unknown", tunnel_type), tunnel_type, bittok2str(bgp_pmsi_flag_values, "none", flags), EXTRACT_24BITS(tptr+2)>>4)); tptr +=5; tlen -= 5; switch (tunnel_type) { case BGP_PMSI_TUNNEL_PIM_SM: /* fall through */ case BGP_PMSI_TUNNEL_PIM_BIDIR: ND_TCHECK2(tptr[0], 8); ND_PRINT((ndo, "\n\t Sender %s, P-Group %s", ipaddr_string(ndo, tptr), ipaddr_string(ndo, tptr+4))); break; case BGP_PMSI_TUNNEL_PIM_SSM: ND_TCHECK2(tptr[0], 8); ND_PRINT((ndo, "\n\t Root-Node %s, P-Group %s", ipaddr_string(ndo, tptr), ipaddr_string(ndo, tptr+4))); break; case BGP_PMSI_TUNNEL_INGRESS: ND_TCHECK2(tptr[0], 4); ND_PRINT((ndo, "\n\t Tunnel-Endpoint %s", ipaddr_string(ndo, tptr))); break; case BGP_PMSI_TUNNEL_LDP_P2MP: /* fall through */ case BGP_PMSI_TUNNEL_LDP_MP2MP: ND_TCHECK2(tptr[0], 8); ND_PRINT((ndo, "\n\t Root-Node %s, LSP-ID 0x%08x", ipaddr_string(ndo, tptr), EXTRACT_32BITS(tptr+4))); break; case BGP_PMSI_TUNNEL_RSVP_P2MP: ND_TCHECK2(tptr[0], 8); ND_PRINT((ndo, "\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x", ipaddr_string(ndo, tptr), EXTRACT_32BITS(tptr+4))); break; default: if (ndo->ndo_vflag <= 1) { print_unknown_data(ndo, tptr, "\n\t ", tlen); } } break; } case BGPTYPE_AIGP: { uint8_t type; uint16_t length; tlen = len; while (tlen >= 3) { ND_TCHECK2(tptr[0], 3); type = *tptr; length = EXTRACT_16BITS(tptr+1); tptr += 3; tlen -= 3; ND_PRINT((ndo, "\n\t %s TLV (%u), length %u", tok2str(bgp_aigp_values, "Unknown", type), type, length)); if (length < 3) goto trunc; length -= 3; /* * Check if we can read the TLV data. */ ND_TCHECK2(tptr[3], length); switch (type) { case BGP_AIGP_TLV: if (length < 8) goto trunc; ND_PRINT((ndo, ", metric %" PRIu64, EXTRACT_64BITS(tptr))); break; default: if (ndo->ndo_vflag <= 1) { print_unknown_data(ndo, tptr,"\n\t ", length); } } tptr += length; tlen -= length; } break; } case BGPTYPE_ATTR_SET: ND_TCHECK2(tptr[0], 4); if (len < 4) goto trunc; ND_PRINT((ndo, "\n\t Origin AS: %s", as_printf(ndo, astostr, sizeof(astostr), EXTRACT_32BITS(tptr)))); tptr+=4; len -=4; while (len) { u_int aflags, alenlen, alen; ND_TCHECK2(tptr[0], 2); if (len < 2) goto trunc; aflags = *tptr; atype = *(tptr + 1); tptr += 2; len -= 2; alenlen = bgp_attr_lenlen(aflags, tptr); ND_TCHECK2(tptr[0], alenlen); if (len < alenlen) goto trunc; alen = bgp_attr_len(aflags, tptr); tptr += alenlen; len -= alenlen; ND_PRINT((ndo, "\n\t %s (%u), length: %u", tok2str(bgp_attr_values, "Unknown Attribute", atype), atype, alen)); if (aflags) { ND_PRINT((ndo, ", Flags [%s%s%s%s", aflags & 0x80 ? "O" : "", aflags & 0x40 ? "T" : "", aflags & 0x20 ? "P" : "", aflags & 0x10 ? "E" : "")); if (aflags & 0xf) ND_PRINT((ndo, "+%x", aflags & 0xf)); ND_PRINT((ndo, "]: ")); } /* The protocol encoding per se allows ATTR_SET to be nested as many times * as the message can accommodate. This printer used to be able to recurse * into ATTR_SET contents until the stack exhaustion, but now there is a * limit on that (if live protocol exchange goes that many levels deep, * something is probably wrong anyway). Feel free to refine this value if * you can find the spec with respective normative text. */ if (attr_set_level == 10) ND_PRINT((ndo, "(too many nested levels, not recursing)")); else if (!bgp_attr_print(ndo, atype, tptr, alen, attr_set_level + 1)) return 0; tptr += alen; len -= alen; } break; case BGPTYPE_LARGE_COMMUNITY: if (len == 0 || len % 12) { ND_PRINT((ndo, "invalid len")); break; } ND_PRINT((ndo, "\n\t ")); while (len > 0) { ND_TCHECK2(*tptr, 12); ND_PRINT((ndo, "%u:%u:%u%s", EXTRACT_32BITS(tptr), EXTRACT_32BITS(tptr + 4), EXTRACT_32BITS(tptr + 8), (len > 12) ? ", " : "")); tptr += 12; len -= 12; } break; default: ND_TCHECK2(*pptr,len); ND_PRINT((ndo, "\n\t no Attribute %u decoder", atype)); /* we have no decoder for the attribute */ if (ndo->ndo_vflag <= 1) print_unknown_data(ndo, pptr, "\n\t ", len); break; } if (ndo->ndo_vflag > 1 && len) { /* omit zero length attributes*/ ND_TCHECK2(*pptr,len); print_unknown_data(ndo, pptr, "\n\t ", len); } return 1; trunc: return 0; } static void bgp_capabilities_print(netdissect_options *ndo, const u_char *opt, int caps_len) { int cap_type, cap_len, tcap_len, cap_offset; int i = 0; while (i < caps_len) { ND_TCHECK2(opt[i], BGP_CAP_HEADER_SIZE); cap_type=opt[i]; cap_len=opt[i+1]; tcap_len=cap_len; ND_PRINT((ndo, "\n\t %s (%u), length: %u", tok2str(bgp_capcode_values, "Unknown", cap_type), cap_type, cap_len)); ND_TCHECK2(opt[i+2], cap_len); switch (cap_type) { case BGP_CAPCODE_MP: /* AFI (16 bits), Reserved (8 bits), SAFI (8 bits) */ ND_TCHECK_8BITS(opt + i + 5); ND_PRINT((ndo, "\n\t\tAFI %s (%u), SAFI %s (%u)", tok2str(af_values, "Unknown", EXTRACT_16BITS(opt+i+2)), EXTRACT_16BITS(opt+i+2), tok2str(bgp_safi_values, "Unknown", opt[i+5]), opt[i+5])); break; case BGP_CAPCODE_RESTART: /* Restart Flags (4 bits), Restart Time in seconds (12 bits) */ ND_TCHECK_16BITS(opt + i + 2); ND_PRINT((ndo, "\n\t\tRestart Flags: [%s], Restart Time %us", ((opt[i+2])&0x80) ? "R" : "none", EXTRACT_16BITS(opt+i+2)&0xfff)); tcap_len-=2; cap_offset=4; while(tcap_len>=4) { ND_TCHECK_8BITS(opt + i + cap_offset + 3); ND_PRINT((ndo, "\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s", tok2str(af_values,"Unknown", EXTRACT_16BITS(opt+i+cap_offset)), EXTRACT_16BITS(opt+i+cap_offset), tok2str(bgp_safi_values,"Unknown", opt[i+cap_offset+2]), opt[i+cap_offset+2], ((opt[i+cap_offset+3])&0x80) ? "yes" : "no" )); tcap_len-=4; cap_offset+=4; } break; case BGP_CAPCODE_RR: case BGP_CAPCODE_RR_CISCO: break; case BGP_CAPCODE_AS_NEW: /* * Extract the 4 byte AS number encoded. */ if (cap_len == 4) { ND_PRINT((ndo, "\n\t\t 4 Byte AS %s", as_printf(ndo, astostr, sizeof(astostr), EXTRACT_32BITS(opt + i + 2)))); } break; case BGP_CAPCODE_ADD_PATH: cap_offset=2; if (tcap_len == 0) { ND_PRINT((ndo, " (bogus)")); /* length */ break; } while (tcap_len > 0) { if (tcap_len < 4) { ND_PRINT((ndo, "\n\t\t(invalid)")); break; } ND_PRINT((ndo, "\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s", tok2str(af_values,"Unknown",EXTRACT_16BITS(opt+i+cap_offset)), EXTRACT_16BITS(opt+i+cap_offset), tok2str(bgp_safi_values,"Unknown",opt[i+cap_offset+2]), opt[i+cap_offset+2], tok2str(bgp_add_path_recvsend,"Bogus (0x%02x)",opt[i+cap_offset+3]) )); tcap_len-=4; cap_offset+=4; } break; default: ND_PRINT((ndo, "\n\t\tno decoder for Capability %u", cap_type)); if (ndo->ndo_vflag <= 1) print_unknown_data(ndo, &opt[i+2], "\n\t\t", cap_len); break; } if (ndo->ndo_vflag > 1 && cap_len > 0) { print_unknown_data(ndo, &opt[i+2], "\n\t\t", cap_len); } i += BGP_CAP_HEADER_SIZE + cap_len; } return; trunc: ND_PRINT((ndo, "%s", tstr)); } static void bgp_open_print(netdissect_options *ndo, const u_char *dat, int length) { struct bgp_open bgpo; struct bgp_opt bgpopt; const u_char *opt; int i; ND_TCHECK2(dat[0], BGP_OPEN_SIZE); memcpy(&bgpo, dat, BGP_OPEN_SIZE); ND_PRINT((ndo, "\n\t Version %d, ", bgpo.bgpo_version)); ND_PRINT((ndo, "my AS %s, ", as_printf(ndo, astostr, sizeof(astostr), ntohs(bgpo.bgpo_myas)))); ND_PRINT((ndo, "Holdtime %us, ", ntohs(bgpo.bgpo_holdtime))); ND_PRINT((ndo, "ID %s", ipaddr_string(ndo, &bgpo.bgpo_id))); ND_PRINT((ndo, "\n\t Optional parameters, length: %u", bgpo.bgpo_optlen)); /* some little sanity checking */ if (length < bgpo.bgpo_optlen+BGP_OPEN_SIZE) return; /* ugly! */ opt = &((const struct bgp_open *)dat)->bgpo_optlen; opt++; i = 0; while (i < bgpo.bgpo_optlen) { ND_TCHECK2(opt[i], BGP_OPT_SIZE); memcpy(&bgpopt, &opt[i], BGP_OPT_SIZE); if (i + 2 + bgpopt.bgpopt_len > bgpo.bgpo_optlen) { ND_PRINT((ndo, "\n\t Option %d, length: %u", bgpopt.bgpopt_type, bgpopt.bgpopt_len)); break; } ND_PRINT((ndo, "\n\t Option %s (%u), length: %u", tok2str(bgp_opt_values,"Unknown", bgpopt.bgpopt_type), bgpopt.bgpopt_type, bgpopt.bgpopt_len)); /* now let's decode the options we know*/ switch(bgpopt.bgpopt_type) { case BGP_OPT_CAP: bgp_capabilities_print(ndo, &opt[i+BGP_OPT_SIZE], bgpopt.bgpopt_len); break; case BGP_OPT_AUTH: default: ND_PRINT((ndo, "\n\t no decoder for option %u", bgpopt.bgpopt_type)); break; } i += BGP_OPT_SIZE + bgpopt.bgpopt_len; } return; trunc: ND_PRINT((ndo, "%s", tstr)); } static void bgp_update_print(netdissect_options *ndo, const u_char *dat, int length) { struct bgp bgp; const u_char *p; int withdrawn_routes_len; int len; int i; ND_TCHECK2(dat[0], BGP_SIZE); if (length < BGP_SIZE) goto trunc; memcpy(&bgp, dat, BGP_SIZE); p = dat + BGP_SIZE; /*XXX*/ length -= BGP_SIZE; /* Unfeasible routes */ ND_TCHECK2(p[0], 2); if (length < 2) goto trunc; withdrawn_routes_len = EXTRACT_16BITS(p); p += 2; length -= 2; if (withdrawn_routes_len) { /* * Without keeping state from the original NLRI message, * it's not possible to tell if this a v4 or v6 route, * so only try to decode it if we're not v6 enabled. */ ND_TCHECK2(p[0], withdrawn_routes_len); if (length < withdrawn_routes_len) goto trunc; ND_PRINT((ndo, "\n\t Withdrawn routes: %d bytes", withdrawn_routes_len)); p += withdrawn_routes_len; length -= withdrawn_routes_len; } ND_TCHECK2(p[0], 2); if (length < 2) goto trunc; len = EXTRACT_16BITS(p); p += 2; length -= 2; if (withdrawn_routes_len == 0 && len == 0 && length == 0) { /* No withdrawn routes, no path attributes, no NLRI */ ND_PRINT((ndo, "\n\t End-of-Rib Marker (empty NLRI)")); return; } if (len) { /* do something more useful!*/ while (len) { int aflags, atype, alenlen, alen; ND_TCHECK2(p[0], 2); if (len < 2) goto trunc; if (length < 2) goto trunc; aflags = *p; atype = *(p + 1); p += 2; len -= 2; length -= 2; alenlen = bgp_attr_lenlen(aflags, p); ND_TCHECK2(p[0], alenlen); if (len < alenlen) goto trunc; if (length < alenlen) goto trunc; alen = bgp_attr_len(aflags, p); p += alenlen; len -= alenlen; length -= alenlen; ND_PRINT((ndo, "\n\t %s (%u), length: %u", tok2str(bgp_attr_values, "Unknown Attribute", atype), atype, alen)); if (aflags) { ND_PRINT((ndo, ", Flags [%s%s%s%s", aflags & 0x80 ? "O" : "", aflags & 0x40 ? "T" : "", aflags & 0x20 ? "P" : "", aflags & 0x10 ? "E" : "")); if (aflags & 0xf) ND_PRINT((ndo, "+%x", aflags & 0xf)); ND_PRINT((ndo, "]: ")); } if (len < alen) goto trunc; if (length < alen) goto trunc; if (!bgp_attr_print(ndo, atype, p, alen, 0)) goto trunc; p += alen; len -= alen; length -= alen; } } if (length) { /* * XXX - what if they're using the "Advertisement of * Multiple Paths in BGP" feature: * * https://datatracker.ietf.org/doc/draft-ietf-idr-add-paths/ * * http://tools.ietf.org/html/draft-ietf-idr-add-paths-06 */ ND_PRINT((ndo, "\n\t Updated routes:")); while (length) { char buf[MAXHOSTNAMELEN + 100]; i = decode_prefix4(ndo, p, length, buf, sizeof(buf)); if (i == -1) { ND_PRINT((ndo, "\n\t (illegal prefix length)")); break; } else if (i == -2) goto trunc; else if (i == -3) goto trunc; /* bytes left, but not enough */ else { ND_PRINT((ndo, "\n\t %s", buf)); p += i; length -= i; } } } return; trunc: ND_PRINT((ndo, "%s", tstr)); } static void bgp_notification_print(netdissect_options *ndo, const u_char *dat, int length) { struct bgp_notification bgpn; const u_char *tptr; ND_TCHECK2(dat[0], BGP_NOTIFICATION_SIZE); memcpy(&bgpn, dat, BGP_NOTIFICATION_SIZE); /* some little sanity checking */ if (length= BGP_NOTIFICATION_SIZE + 7) { tptr = dat + BGP_NOTIFICATION_SIZE; ND_TCHECK2(*tptr, 7); ND_PRINT((ndo, ", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u", tok2str(af_values, "Unknown", EXTRACT_16BITS(tptr)), EXTRACT_16BITS(tptr), tok2str(bgp_safi_values, "Unknown", *(tptr+2)), *(tptr+2), EXTRACT_32BITS(tptr+3))); } break; default: break; } return; trunc: ND_PRINT((ndo, "%s", tstr)); } static void bgp_route_refresh_print(netdissect_options *ndo, const u_char *pptr, int len) { const struct bgp_route_refresh *bgp_route_refresh_header; ND_TCHECK2(pptr[0], BGP_ROUTE_REFRESH_SIZE); /* some little sanity checking */ if (lenafi)), EXTRACT_16BITS(&bgp_route_refresh_header->afi), tok2str(bgp_safi_values,"Unknown", bgp_route_refresh_header->safi), bgp_route_refresh_header->safi)); if (ndo->ndo_vflag > 1) { ND_TCHECK2(*pptr, len); print_unknown_data(ndo, pptr, "\n\t ", len); } return; trunc: ND_PRINT((ndo, "%s", tstr)); } static int bgp_header_print(netdissect_options *ndo, const u_char *dat, int length) { struct bgp bgp; ND_TCHECK2(dat[0], BGP_SIZE); memcpy(&bgp, dat, BGP_SIZE); ND_PRINT((ndo, "\n\t%s Message (%u), length: %u", tok2str(bgp_msg_values, "Unknown", bgp.bgp_type), bgp.bgp_type, length)); switch (bgp.bgp_type) { case BGP_OPEN: bgp_open_print(ndo, dat, length); break; case BGP_UPDATE: bgp_update_print(ndo, dat, length); break; case BGP_NOTIFICATION: bgp_notification_print(ndo, dat, length); break; case BGP_KEEPALIVE: break; case BGP_ROUTE_REFRESH: bgp_route_refresh_print(ndo, dat, length); break; default: /* we have no decoder for the BGP message */ ND_TCHECK2(*dat, length); ND_PRINT((ndo, "\n\t no Message %u decoder", bgp.bgp_type)); print_unknown_data(ndo, dat, "\n\t ", length); break; } return 1; trunc: ND_PRINT((ndo, "%s", tstr)); return 0; } void bgp_print(netdissect_options *ndo, const u_char *dat, int length) { const u_char *p; const u_char *ep; const u_char *start; const u_char marker[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }; struct bgp bgp; uint16_t hlen; ep = dat + length; if (ndo->ndo_snapend < dat + length) ep = ndo->ndo_snapend; ND_PRINT((ndo, ": BGP")); if (ndo->ndo_vflag < 1) /* lets be less chatty */ return; p = dat; start = p; while (p < ep) { if (!ND_TTEST2(p[0], 1)) break; if (p[0] != 0xff) { p++; continue; } if (!ND_TTEST2(p[0], sizeof(marker))) break; if (memcmp(p, marker, sizeof(marker)) != 0) { p++; continue; } /* found BGP header */ ND_TCHECK2(p[0], BGP_SIZE); /*XXX*/ memcpy(&bgp, p, BGP_SIZE); if (start != p) ND_PRINT((ndo, " %s", tstr)); hlen = ntohs(bgp.bgp_len); if (hlen < BGP_SIZE) { ND_PRINT((ndo, "\n[|BGP Bogus header length %u < %u]", hlen, BGP_SIZE)); break; } if (ND_TTEST2(p[0], hlen)) { if (!bgp_header_print(ndo, p, hlen)) return; p += hlen; start = p; } else { ND_PRINT((ndo, "\n[|BGP %s]", tok2str(bgp_msg_values, "Unknown Message Type", bgp.bgp_type))); break; } } return; trunc: ND_PRINT((ndo, "%s", tstr)); } /* * Local Variables: * c-style: whitesmith * c-basic-offset: 4 * End: */ tcpdump-4.9.3/setsignal.c0000644000026300017510000000642313544412561013475 0ustar mcrmcr/* * Copyright (c) 1997 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of * the University nor the names of its contributors may be used to endorse * or promote products derived from this software without specific prior * written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #ifdef HAVE_SIGACTION #include #endif #ifdef HAVE_OS_PROTO_H #include "os-proto.h" #endif #include "setsignal.h" /* * An OS-independent signal() with, whenever possible, partial BSD * semantics, i.e. the signal handler is restored following service * of the signal, but system calls are *not* restarted, so that if * "pcap_breakloop()" is called in a signal handler in a live capture, * the read/recvfrom/whatever in the live capture doesn't get restarted, * it returns -1 and sets "errno" to EINTR, so we can break out of the * live capture loop. * * We use "sigaction()" if available. We don't specify that the signal * should restart system calls, so that should always do what we want. * * Otherwise, if "sigset()" is available, it probably has BSD semantics * while "signal()" has traditional semantics, so we use "sigset()"; it * might cause system calls to be restarted for the signal, however. * I don't know whether, in any systems where it did cause system calls to * be restarted, there was a way to ask it not to do so; there may no * longer be any interesting systems without "sigaction()", however, * and, if there are, they might have "sigvec()" with SV_INTERRUPT * (which I think first appeared in 4.3BSD). * * Otherwise, we use "signal()" - which means we might get traditional * semantics, wherein system calls don't get restarted *but* the * signal handler is reset to SIG_DFL and the signal is not blocked, * so that a subsequent signal would kill the process immediately. * * Did I mention that signals suck? At least in POSIX-compliant systems * they suck far less, as those systems have "sigaction()". */ RETSIGTYPE (*setsignal (int sig, RETSIGTYPE (*func)(int)))(int) { #ifdef HAVE_SIGACTION struct sigaction old, new; memset(&new, 0, sizeof(new)); new.sa_handler = func; if (sig == SIGCHLD) new.sa_flags = SA_RESTART; if (sigaction(sig, &new, &old) < 0) return (SIG_ERR); return (old.sa_handler); #else #ifdef HAVE_SIGSET return (sigset(sig, func)); #else return (signal(sig, func)); #endif #endif } tcpdump-4.9.3/print-otv.c0000644000026300017510000000414713544412561013447 0ustar mcrmcr/* * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code * distributions retain the above copyright notice and this paragraph * in its entirety, and (2) distributions including binary code include * the above copyright notice and this paragraph in its entirety in * the documentation or other materials provided with the distribution. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. * * Original code by Francesco Fondelli (francesco dot fondelli, gmail dot com) */ /* \summary: Overlay Transport Virtualization (OTV) printer */ /* specification: draft-hasmit-otv-04 */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #include "extract.h" /* * OTV header, draft-hasmit-otv-04 * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * |R|R|R|R|I|R|R|R| Overlay ID | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Instance ID | Reserved | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ void otv_print(netdissect_options *ndo, const u_char *bp, u_int len) { uint8_t flags; ND_PRINT((ndo, "OTV, ")); if (len < 8) goto trunc; ND_TCHECK(*bp); flags = *bp; ND_PRINT((ndo, "flags [%s] (0x%02x), ", flags & 0x08 ? "I" : ".", flags)); bp += 1; ND_TCHECK2(*bp, 3); ND_PRINT((ndo, "overlay %u, ", EXTRACT_24BITS(bp))); bp += 3; ND_TCHECK2(*bp, 3); ND_PRINT((ndo, "instance %u\n", EXTRACT_24BITS(bp))); bp += 3; /* Reserved */ ND_TCHECK(*bp); bp += 1; ether_print(ndo, bp, len - 8, ndo->ndo_snapend - bp, NULL, NULL); return; trunc: ND_PRINT((ndo, " [|OTV]")); } tcpdump-4.9.3/print-tipc.c0000644000026300017510000002703613544412561013600 0ustar mcrmcr/* * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of * the University nor the names of its contributors may be used to endorse * or promote products derived from this software without specific prior * written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* \summary: Transparent Inter-Process Communication (TIPC) protocol printer */ /* * specification: * http://tipc.sourceforge.net/doc/draft-spec-tipc-07.html * http://tipc.sourceforge.net/doc/tipc_message_formats.html */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #include "ether.h" #include "ethertype.h" #include "extract.h" static const char tstr[] = "[|TIPC]"; #define TIPC_USER_LOW_IMPORTANCE 0 #define TIPC_USER_MEDIUM_IMPORTANCE 1 #define TIPC_USER_HIGH_IMPORTANCE 2 #define TIPC_USER_CRITICAL_IMPORTANCE 3 #define TIPC_USER_BCAST_PROTOCOL 5 #define TIPC_USER_MSG_BUNDLER 6 #define TIPC_USER_LINK_PROTOCOL 7 #define TIPC_USER_CONN_MANAGER 8 #define TIPC_USER_CHANGEOVER_PROTOCOL 10 #define TIPC_USER_NAME_DISTRIBUTOR 11 #define TIPC_USER_MSG_FRAGMENTER 12 #define TIPC_USER_LINK_CONFIG 13 #define TIPC_CONN_MSG 0 #define TIPC_DIRECT_MSG 1 #define TIPC_NAMED_MSG 2 #define TIPC_MCAST_MSG 3 #define TIPC_ZONE(addr) (((addr) >> 24) & 0xFF) #define TIPC_CLUSTER(addr) (((addr) >> 12) & 0xFFF) #define TIPC_NODE(addr) (((addr) >> 0) & 0xFFF) struct tipc_pkthdr { uint32_t w0; uint32_t w1; }; #define TIPC_VER(w0) (((w0) >> 29) & 0x07) #define TIPC_USER(w0) (((w0) >> 25) & 0x0F) #define TIPC_HSIZE(w0) (((w0) >> 21) & 0x0F) #define TIPC_MSIZE(w0) (((w0) >> 0) & 0xFFFF) #define TIPC_MTYPE(w1) (((w1) >> 29) & 0x07) #define TIPC_BROADCAST_ACK(w1) (((w1) >> 0) & 0xFFFF) #define TIPC_LINK_ACK(w2) (((w2) >> 16) & 0xFFFF) #define TIPC_LINK_SEQ(w2) (((w2) >> 0) & 0xFFFF) static const struct tok tipcuser_values[] = { { TIPC_USER_LOW_IMPORTANCE, "Low Importance Data payload" }, { TIPC_USER_MEDIUM_IMPORTANCE, "Medium Importance Data payload" }, { TIPC_USER_HIGH_IMPORTANCE, "High Importance Data payload" }, { TIPC_USER_CRITICAL_IMPORTANCE, "Critical Importance Data payload" }, { TIPC_USER_BCAST_PROTOCOL, "Broadcast Link Protocol internal" }, { TIPC_USER_MSG_BUNDLER, "Message Bundler Protocol internal" }, { TIPC_USER_LINK_PROTOCOL, "Link State Protocol internal" }, { TIPC_USER_CONN_MANAGER, "Connection Manager internal" }, { TIPC_USER_CHANGEOVER_PROTOCOL, "Link Changeover Protocol internal" }, { TIPC_USER_NAME_DISTRIBUTOR, "Name Table Update Protocol internal" }, { TIPC_USER_MSG_FRAGMENTER, "Message Fragmentation Protocol internal" }, { TIPC_USER_LINK_CONFIG, "Neighbor Detection Protocol internal" }, { 0, NULL } }; static const struct tok tipcmtype_values[] = { { TIPC_CONN_MSG, "CONN_MSG" }, { TIPC_DIRECT_MSG, "MCAST_MSG" }, { TIPC_NAMED_MSG, "NAMED_MSG" }, { TIPC_MCAST_MSG, "DIRECT_MSG" }, { 0, NULL } }; static const struct tok tipc_linkconf_mtype_values[] = { { 0, "Link request" }, { 1, "Link response" }, { 0, NULL } }; struct payload_tipc_pkthdr { uint32_t w0; uint32_t w1; uint32_t w2; uint32_t prev_node; uint32_t orig_port; uint32_t dest_port; uint32_t orig_node; uint32_t dest_node; uint32_t name_type; uint32_t w9; uint32_t wA; }; struct internal_tipc_pkthdr { uint32_t w0; uint32_t w1; uint32_t w2; uint32_t prev_node; uint32_t w4; uint32_t w5; uint32_t orig_node; uint32_t dest_node; uint32_t trans_seq; uint32_t w9; }; #define TIPC_SEQ_GAP(w1) (((w1) >> 16) & 0x1FFF) #define TIPC_BC_GAP_AFTER(w2) (((w2) >> 16) & 0xFFFF) #define TIPC_BC_GAP_TO(w2) (((w2) >> 0) & 0xFFFF) #define TIPC_LAST_SENT_FRAG(w4) (((w4) >> 16) & 0xFFFF) #define TIPC_NEXT_SENT_FRAG(w4) (((w4) >> 0) & 0xFFFF) #define TIPC_SESS_NO(w5) (((w5) >> 16) & 0xFFFF) #define TIPC_MSG_CNT(w9) (((w9) >> 16) & 0xFFFF) #define TIPC_LINK_TOL(w9) (((w9) >> 0) & 0xFFFF) struct link_conf_tipc_pkthdr { uint32_t w0; uint32_t w1; uint32_t dest_domain; uint32_t prev_node; uint32_t ntwrk_id; uint32_t w5; uint8_t media_address[16]; }; #define TIPC_NODE_SIG(w1) (((w1) >> 0) & 0xFFFF) #define TIPC_MEDIA_ID(w5) (((w5) >> 0) & 0xFF) static void print_payload(netdissect_options *ndo, const struct payload_tipc_pkthdr *ap) { uint32_t w0, w1, w2; u_int user; u_int hsize; u_int msize; u_int mtype; u_int broadcast_ack; u_int link_ack; u_int link_seq; u_int prev_node; u_int orig_port; u_int dest_port; u_int orig_node; u_int dest_node; ND_TCHECK(ap->dest_port); w0 = EXTRACT_32BITS(&ap->w0); user = TIPC_USER(w0); hsize = TIPC_HSIZE(w0); msize = TIPC_MSIZE(w0); w1 = EXTRACT_32BITS(&ap->w1); mtype = TIPC_MTYPE(w1); prev_node = EXTRACT_32BITS(&ap->prev_node); orig_port = EXTRACT_32BITS(&ap->orig_port); dest_port = EXTRACT_32BITS(&ap->dest_port); if (hsize <= 6) { ND_PRINT((ndo, "TIPC v%u.0 %u.%u.%u:%u > %u, headerlength %u bytes, MessageSize %u bytes, %s, messageType %s", TIPC_VER(w0), TIPC_ZONE(prev_node), TIPC_CLUSTER(prev_node), TIPC_NODE(prev_node), orig_port, dest_port, hsize*4, msize, tok2str(tipcuser_values, "unknown", user), tok2str(tipcmtype_values, "Unknown", mtype))); } else { ND_TCHECK(ap->dest_node); orig_node = EXTRACT_32BITS(&ap->orig_node); dest_node = EXTRACT_32BITS(&ap->dest_node); ND_PRINT((ndo, "TIPC v%u.0 %u.%u.%u:%u > %u.%u.%u:%u, headerlength %u bytes, MessageSize %u bytes, %s, messageType %s", TIPC_VER(w0), TIPC_ZONE(orig_node), TIPC_CLUSTER(orig_node), TIPC_NODE(orig_node), orig_port, TIPC_ZONE(dest_node), TIPC_CLUSTER(dest_node), TIPC_NODE(dest_node), dest_port, hsize*4, msize, tok2str(tipcuser_values, "unknown", user), tok2str(tipcmtype_values, "Unknown", mtype))); if (ndo->ndo_vflag) { broadcast_ack = TIPC_BROADCAST_ACK(w1); w2 = EXTRACT_32BITS(&ap->w2); link_ack = TIPC_LINK_ACK(w2); link_seq = TIPC_LINK_SEQ(w2); ND_PRINT((ndo, "\n\tPrevious Node %u.%u.%u, Broadcast Ack %u, Link Ack %u, Link Sequence %u", TIPC_ZONE(prev_node), TIPC_CLUSTER(prev_node), TIPC_NODE(prev_node), broadcast_ack, link_ack, link_seq)); } } return; trunc: ND_PRINT((ndo, "%s", tstr)); } static void print_internal(netdissect_options *ndo, const struct internal_tipc_pkthdr *ap) { uint32_t w0, w1, w2, w4, w5, w9; u_int user; u_int hsize; u_int msize; u_int mtype; u_int seq_gap; u_int broadcast_ack; u_int bc_gap_after; u_int bc_gap_to; u_int prev_node; u_int last_sent_frag; u_int next_sent_frag; u_int sess_no; u_int orig_node; u_int dest_node; u_int trans_seq; u_int msg_cnt; u_int link_tol; ND_TCHECK(ap->dest_node); w0 = EXTRACT_32BITS(&ap->w0); user = TIPC_USER(w0); hsize = TIPC_HSIZE(w0); msize = TIPC_MSIZE(w0); w1 = EXTRACT_32BITS(&ap->w1); mtype = TIPC_MTYPE(w1); orig_node = EXTRACT_32BITS(&ap->orig_node); dest_node = EXTRACT_32BITS(&ap->dest_node); ND_PRINT((ndo, "TIPC v%u.0 %u.%u.%u > %u.%u.%u, headerlength %u bytes, MessageSize %u bytes, %s, messageType %s (0x%08x)", TIPC_VER(w0), TIPC_ZONE(orig_node), TIPC_CLUSTER(orig_node), TIPC_NODE(orig_node), TIPC_ZONE(dest_node), TIPC_CLUSTER(dest_node), TIPC_NODE(dest_node), hsize*4, msize, tok2str(tipcuser_values, "unknown", user), tok2str(tipcmtype_values, "Unknown", mtype), w1)); if (ndo->ndo_vflag) { ND_TCHECK(*ap); seq_gap = TIPC_SEQ_GAP(w1); broadcast_ack = TIPC_BROADCAST_ACK(w1); w2 = EXTRACT_32BITS(&ap->w2); bc_gap_after = TIPC_BC_GAP_AFTER(w2); bc_gap_to = TIPC_BC_GAP_TO(w2); prev_node = EXTRACT_32BITS(&ap->prev_node); w4 = EXTRACT_32BITS(&ap->w4); last_sent_frag = TIPC_LAST_SENT_FRAG(w4); next_sent_frag = TIPC_NEXT_SENT_FRAG(w4); w5 = EXTRACT_32BITS(&ap->w5); sess_no = TIPC_SESS_NO(w5); trans_seq = EXTRACT_32BITS(&ap->trans_seq); w9 = EXTRACT_32BITS(&ap->w9); msg_cnt = TIPC_MSG_CNT(w9); link_tol = TIPC_LINK_TOL(w9); ND_PRINT((ndo, "\n\tPrevious Node %u.%u.%u, Session No. %u, Broadcast Ack %u, Sequence Gap %u, Broadcast Gap After %u, Broadcast Gap To %u, Last Sent Packet No. %u, Next sent Packet No. %u, Transport Sequence %u, msg_count %u, Link Tolerance %u", TIPC_ZONE(prev_node), TIPC_CLUSTER(prev_node), TIPC_NODE(prev_node), sess_no, broadcast_ack, seq_gap, bc_gap_after, bc_gap_to, last_sent_frag, next_sent_frag, trans_seq, msg_cnt, link_tol)); } return; trunc: ND_PRINT((ndo, "%s", tstr)); } static void print_link_conf(netdissect_options *ndo, const struct link_conf_tipc_pkthdr *ap) { uint32_t w0, w1, w5; u_int user; u_int hsize; u_int msize; u_int mtype; u_int node_sig; u_int prev_node; u_int dest_domain; u_int ntwrk_id; u_int media_id; ND_TCHECK(ap->prev_node); w0 = EXTRACT_32BITS(&ap->w0); user = TIPC_USER(w0); hsize = TIPC_HSIZE(w0); msize = TIPC_MSIZE(w0); w1 = EXTRACT_32BITS(&ap->w1); mtype = TIPC_MTYPE(w1); dest_domain = EXTRACT_32BITS(&ap->dest_domain); prev_node = EXTRACT_32BITS(&ap->prev_node); ND_PRINT((ndo, "TIPC v%u.0 %u.%u.%u > %u.%u.%u, headerlength %u bytes, MessageSize %u bytes, %s, messageType %s", TIPC_VER(w0), TIPC_ZONE(prev_node), TIPC_CLUSTER(prev_node), TIPC_NODE(prev_node), TIPC_ZONE(dest_domain), TIPC_CLUSTER(dest_domain), TIPC_NODE(dest_domain), hsize*4, msize, tok2str(tipcuser_values, "unknown", user), tok2str(tipc_linkconf_mtype_values, "Unknown", mtype))); if (ndo->ndo_vflag) { ND_TCHECK(ap->w5); node_sig = TIPC_NODE_SIG(w1); ntwrk_id = EXTRACT_32BITS(&ap->ntwrk_id); w5 = EXTRACT_32BITS(&ap->w5); media_id = TIPC_MEDIA_ID(w5); ND_PRINT((ndo, "\n\tNodeSignature %u, network_id %u, media_id %u", node_sig, ntwrk_id, media_id)); } return; trunc: ND_PRINT((ndo, "%s", tstr)); } void tipc_print(netdissect_options *ndo, const u_char *bp, u_int length _U_, u_int caplen _U_) { const struct tipc_pkthdr *ap; uint32_t w0; u_int user; ap = (const struct tipc_pkthdr *)bp; ND_TCHECK(ap->w0); w0 = EXTRACT_32BITS(&ap->w0); user = TIPC_USER(w0); switch (user) { case TIPC_USER_LOW_IMPORTANCE: case TIPC_USER_MEDIUM_IMPORTANCE: case TIPC_USER_HIGH_IMPORTANCE: case TIPC_USER_CRITICAL_IMPORTANCE: case TIPC_USER_NAME_DISTRIBUTOR: case TIPC_USER_CONN_MANAGER: print_payload(ndo, (const struct payload_tipc_pkthdr *)bp); break; case TIPC_USER_LINK_CONFIG: print_link_conf(ndo, (const struct link_conf_tipc_pkthdr *)bp); break; case TIPC_USER_BCAST_PROTOCOL: case TIPC_USER_MSG_BUNDLER: case TIPC_USER_LINK_PROTOCOL: case TIPC_USER_CHANGEOVER_PROTOCOL: case TIPC_USER_MSG_FRAGMENTER: print_internal(ndo, (const struct internal_tipc_pkthdr *)bp); break; } return; trunc: ND_PRINT((ndo, "%s", tstr)); } /* * Local Variables: * c-style: bsd * End: */ tcpdump-4.9.3/atime.awk0000644000026300017510000000102113544412561013130 0ustar mcrmcr$6 ~ /^ack/ && $5 !~ /[SFR]/ { # given a tcpdump ftp trace, output one line for each ack # in the form # # where is the time packet was acked (in seconds with # zero at time of first packet) and is the tcp sequence # number of the ack divided by 1024 (i.e., Kbytes acked). # # convert time to seconds n = split ($1,t,":") tim = t[1]*3600 + t[2]*60 + t[3] if (! tzero) { tzero = tim OFS = "\t" } # get packet sequence number printf "%7.2f\t%g\n", tim-tzero, $7/1024 } tcpdump-4.9.3/print-snmp.c0000644000026300017510000012626113544412561013616 0ustar mcrmcr/* * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997 * John Robert LoVerso. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * * This implementation has been influenced by the CMU SNMP release, * by Steve Waldbusser. However, this shares no code with that system. * Additional ASN.1 insight gained from Marshall T. Rose's _The_Open_Book_. * Earlier forms of this implementation were derived and/or inspired by an * awk script originally written by C. Philip Wood of LANL (but later * heavily modified by John Robert LoVerso). The copyright notice for * that work is preserved below, even though it may not rightly apply * to this file. * * Support for SNMPv2c/SNMPv3 and the ability to link the module against * the libsmi was added by J. Schoenwaelder, Copyright (c) 1999. * * This started out as a very simple program, but the incremental decoding * (into the BE structure) complicated things. * # Los Alamos National Laboratory # # Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997 # This software was produced under a U.S. Government contract # (W-7405-ENG-36) by Los Alamos National Laboratory, which is # operated by the University of California for the U.S. Department # of Energy. The U.S. Government is licensed to use, reproduce, # and distribute this software. Permission is granted to the # public to copy and use this software without charge, provided # that this Notice and any statement of authorship are reproduced # on all copies. Neither the Government nor the University makes # any warranty, express or implied, or assumes any liability or # responsibility for the use of this software. # @(#)snmp.awk.x 1.1 (LANL) 1/15/90 */ /* \summary: Simple Network Management Protocol (SNMP) printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include #ifdef USE_LIBSMI #include #endif #include "netdissect.h" #undef OPAQUE /* defined in */ static const char tstr[] = "[|snmp]"; /* * Universal ASN.1 types * (we only care about the tag values for those allowed in the Internet SMI) */ static const char *Universal[] = { "U-0", "Boolean", "Integer", #define INTEGER 2 "Bitstring", "String", #define STRING 4 "Null", #define ASN_NULL 5 "ObjID", #define OBJECTID 6 "ObjectDes", "U-8","U-9","U-10","U-11", /* 8-11 */ "U-12","U-13","U-14","U-15", /* 12-15 */ "Sequence", #define SEQUENCE 16 "Set" }; /* * Application-wide ASN.1 types from the Internet SMI and their tags */ static const char *Application[] = { "IpAddress", #define IPADDR 0 "Counter", #define COUNTER 1 "Gauge", #define GAUGE 2 "TimeTicks", #define TIMETICKS 3 "Opaque", #define OPAQUE 4 "C-5", "Counter64" #define COUNTER64 6 }; /* * Context-specific ASN.1 types for the SNMP PDUs and their tags */ static const char *Context[] = { "GetRequest", #define GETREQ 0 "GetNextRequest", #define GETNEXTREQ 1 "GetResponse", #define GETRESP 2 "SetRequest", #define SETREQ 3 "Trap", #define TRAP 4 "GetBulk", #define GETBULKREQ 5 "Inform", #define INFORMREQ 6 "V2Trap", #define V2TRAP 7 "Report" #define REPORT 8 }; #define NOTIFY_CLASS(x) (x == TRAP || x == V2TRAP || x == INFORMREQ) #define READ_CLASS(x) (x == GETREQ || x == GETNEXTREQ || x == GETBULKREQ) #define WRITE_CLASS(x) (x == SETREQ) #define RESPONSE_CLASS(x) (x == GETRESP) #define INTERNAL_CLASS(x) (x == REPORT) /* * Context-specific ASN.1 types for the SNMP Exceptions and their tags */ static const char *Exceptions[] = { "noSuchObject", #define NOSUCHOBJECT 0 "noSuchInstance", #define NOSUCHINSTANCE 1 "endOfMibView", #define ENDOFMIBVIEW 2 }; /* * Private ASN.1 types * The Internet SMI does not specify any */ static const char *Private[] = { "P-0" }; /* * error-status values for any SNMP PDU */ static const char *ErrorStatus[] = { "noError", "tooBig", "noSuchName", "badValue", "readOnly", "genErr", "noAccess", "wrongType", "wrongLength", "wrongEncoding", "wrongValue", "noCreation", "inconsistentValue", "resourceUnavailable", "commitFailed", "undoFailed", "authorizationError", "notWritable", "inconsistentName" }; #define DECODE_ErrorStatus(e) \ ( e >= 0 && (size_t)e < sizeof(ErrorStatus)/sizeof(ErrorStatus[0]) \ ? ErrorStatus[e] \ : (snprintf(errbuf, sizeof(errbuf), "err=%u", e), errbuf)) /* * generic-trap values in the SNMP Trap-PDU */ static const char *GenericTrap[] = { "coldStart", "warmStart", "linkDown", "linkUp", "authenticationFailure", "egpNeighborLoss", "enterpriseSpecific" #define GT_ENTERPRISE 6 }; #define DECODE_GenericTrap(t) \ ( t >= 0 && (size_t)t < sizeof(GenericTrap)/sizeof(GenericTrap[0]) \ ? GenericTrap[t] \ : (snprintf(buf, sizeof(buf), "gt=%d", t), buf)) /* * ASN.1 type class table * Ties together the preceding Universal, Application, Context, and Private * type definitions. */ #define defineCLASS(x) { "x", x, sizeof(x)/sizeof(x[0]) } /* not ANSI-C */ static const struct { const char *name; const char **Id; int numIDs; } Class[] = { defineCLASS(Universal), #define UNIVERSAL 0 defineCLASS(Application), #define APPLICATION 1 defineCLASS(Context), #define CONTEXT 2 defineCLASS(Private), #define PRIVATE 3 defineCLASS(Exceptions), #define EXCEPTIONS 4 }; /* * defined forms for ASN.1 types */ static const char *Form[] = { "Primitive", #define PRIMITIVE 0 "Constructed", #define CONSTRUCTED 1 }; /* * A structure for the OID tree for the compiled-in MIB. * This is stored as a general-order tree. */ static struct obj { const char *desc; /* name of object */ u_char oid; /* sub-id following parent */ u_char type; /* object type (unused) */ struct obj *child, *next; /* child and next sibling pointers */ } *objp = NULL; /* * Include the compiled in SNMP MIB. "mib.h" is produced by feeding * RFC-1156 format files into "makemib". "mib.h" MUST define at least * a value for `mibroot'. * * In particular, this is gross, as this is including initialized structures, * and by right shouldn't be an "include" file. */ #include "mib.h" /* * This defines a list of OIDs which will be abbreviated on output. * Currently, this includes the prefixes for the Internet MIB, the * private enterprises tree, and the experimental tree. */ #define OID_FIRST_OCTET(x, y) (((x)*40) + (y)) /* X.690 8.19.4 */ #ifndef NO_ABREV_MIB static const uint8_t mib_oid[] = { OID_FIRST_OCTET(1, 3), 6, 1, 2, 1 }; #endif #ifndef NO_ABREV_ENTER static const uint8_t enterprises_oid[] = { OID_FIRST_OCTET(1, 3), 6, 1, 4, 1 }; #endif #ifndef NO_ABREV_EXPERI static const uint8_t experimental_oid[] = { OID_FIRST_OCTET(1, 3), 6, 1, 3 }; #endif #ifndef NO_ABBREV_SNMPMODS static const uint8_t snmpModules_oid[] = { OID_FIRST_OCTET(1, 3), 6, 1, 6, 3 }; #endif #define OBJ_ABBREV_ENTRY(prefix, obj) \ { prefix, &_ ## obj ## _obj, obj ## _oid, sizeof (obj ## _oid) } static const struct obj_abrev { const char *prefix; /* prefix for this abrev */ struct obj *node; /* pointer into object table */ const uint8_t *oid; /* ASN.1 encoded OID */ size_t oid_len; /* length of OID */ } obj_abrev_list[] = { #ifndef NO_ABREV_MIB /* .iso.org.dod.internet.mgmt.mib */ OBJ_ABBREV_ENTRY("", mib), #endif #ifndef NO_ABREV_ENTER /* .iso.org.dod.internet.private.enterprises */ OBJ_ABBREV_ENTRY("E:", enterprises), #endif #ifndef NO_ABREV_EXPERI /* .iso.org.dod.internet.experimental */ OBJ_ABBREV_ENTRY("X:", experimental), #endif #ifndef NO_ABBREV_SNMPMODS /* .iso.org.dod.internet.snmpV2.snmpModules */ OBJ_ABBREV_ENTRY("S:", snmpModules), #endif { 0,0,0,0 } }; /* * This is used in the OID print routine to walk down the object tree * rooted at `mibroot'. */ #define OBJ_PRINT(o, suppressdot) \ { \ if (objp) { \ do { \ if ((o) == objp->oid) \ break; \ } while ((objp = objp->next) != NULL); \ } \ if (objp) { \ ND_PRINT((ndo, suppressdot?"%s":".%s", objp->desc)); \ objp = objp->child; \ } else \ ND_PRINT((ndo, suppressdot?"%u":".%u", (o))); \ } /* * This is the definition for the Any-Data-Type storage used purely for * temporary internal representation while decoding an ASN.1 data stream. */ struct be { uint32_t asnlen; union { const uint8_t *raw; int32_t integer; uint32_t uns; const u_char *str; uint64_t uns64; } data; u_short id; u_char form, class; /* tag info */ u_char type; #define BE_ANY 255 #define BE_NONE 0 #define BE_NULL 1 #define BE_OCTET 2 #define BE_OID 3 #define BE_INT 4 #define BE_UNS 5 #define BE_STR 6 #define BE_SEQ 7 #define BE_INETADDR 8 #define BE_PDU 9 #define BE_UNS64 10 #define BE_NOSUCHOBJECT 128 #define BE_NOSUCHINST 129 #define BE_ENDOFMIBVIEW 130 }; /* * SNMP versions recognized by this module */ static const char *SnmpVersion[] = { "SNMPv1", #define SNMP_VERSION_1 0 "SNMPv2c", #define SNMP_VERSION_2 1 "SNMPv2u", #define SNMP_VERSION_2U 2 "SNMPv3" #define SNMP_VERSION_3 3 }; /* * Defaults for SNMP PDU components */ #define DEF_COMMUNITY "public" /* * constants for ASN.1 decoding */ #define OIDMUX 40 #define ASNLEN_INETADDR 4 #define ASN_SHIFT7 7 #define ASN_SHIFT8 8 #define ASN_BIT8 0x80 #define ASN_LONGLEN 0x80 #define ASN_ID_BITS 0x1f #define ASN_FORM_BITS 0x20 #define ASN_FORM_SHIFT 5 #define ASN_CLASS_BITS 0xc0 #define ASN_CLASS_SHIFT 6 #define ASN_ID_EXT 0x1f /* extension ID in tag field */ /* * This decodes the next ASN.1 object in the stream pointed to by "p" * (and of real-length "len") and stores the intermediate data in the * provided BE object. * * This returns -l if it fails (i.e., the ASN.1 stream is not valid). * O/w, this returns the number of bytes parsed from "p". */ static int asn1_parse(netdissect_options *ndo, register const u_char *p, u_int len, struct be *elem) { u_char form, class, id; int i, hdr; elem->asnlen = 0; elem->type = BE_ANY; if (len < 1) { ND_PRINT((ndo, "[nothing to parse]")); return -1; } ND_TCHECK(*p); /* * it would be nice to use a bit field, but you can't depend on them. * +---+---+---+---+---+---+---+---+ * + class |frm| id | * +---+---+---+---+---+---+---+---+ * 7 6 5 4 3 2 1 0 */ id = *p & ASN_ID_BITS; /* lower 5 bits, range 00-1f */ #ifdef notdef form = (*p & 0xe0) >> 5; /* move upper 3 bits to lower 3 */ class = form >> 1; /* bits 7&6 -> bits 1&0, range 0-3 */ form &= 0x1; /* bit 5 -> bit 0, range 0-1 */ #else form = (u_char)(*p & ASN_FORM_BITS) >> ASN_FORM_SHIFT; class = (u_char)(*p & ASN_CLASS_BITS) >> ASN_CLASS_SHIFT; #endif elem->form = form; elem->class = class; elem->id = id; p++; len--; hdr = 1; /* extended tag field */ if (id == ASN_ID_EXT) { /* * The ID follows, as a sequence of octets with the * 8th bit set and the remaining 7 bits being * the next 7 bits of the value, terminated with * an octet with the 8th bit not set. * * First, assemble all the octets with the 8th * bit set. XXX - this doesn't handle a value * that won't fit in 32 bits. */ id = 0; ND_TCHECK(*p); while (*p & ASN_BIT8) { if (len < 1) { ND_PRINT((ndo, "[Xtagfield?]")); return -1; } id = (id << 7) | (*p & ~ASN_BIT8); len--; hdr++; p++; ND_TCHECK(*p); } if (len < 1) { ND_PRINT((ndo, "[Xtagfield?]")); return -1; } ND_TCHECK(*p); elem->id = id = (id << 7) | *p; --len; ++hdr; ++p; } if (len < 1) { ND_PRINT((ndo, "[no asnlen]")); return -1; } ND_TCHECK(*p); elem->asnlen = *p; p++; len--; hdr++; if (elem->asnlen & ASN_BIT8) { uint32_t noct = elem->asnlen % ASN_BIT8; elem->asnlen = 0; if (len < noct) { ND_PRINT((ndo, "[asnlen? %d<%d]", len, noct)); return -1; } ND_TCHECK2(*p, noct); for (; noct-- > 0; len--, hdr++) elem->asnlen = (elem->asnlen << ASN_SHIFT8) | *p++; } if (len < elem->asnlen) { ND_PRINT((ndo, "[len%dasnlen)); return -1; } if (form >= sizeof(Form)/sizeof(Form[0])) { ND_PRINT((ndo, "[form?%d]", form)); return -1; } if (class >= sizeof(Class)/sizeof(Class[0])) { ND_PRINT((ndo, "[class?%c/%d]", *Form[form], class)); return -1; } if ((int)id >= Class[class].numIDs) { ND_PRINT((ndo, "[id?%c/%s/%d]", *Form[form], Class[class].name, id)); return -1; } ND_TCHECK2(*p, elem->asnlen); switch (form) { case PRIMITIVE: switch (class) { case UNIVERSAL: switch (id) { case STRING: elem->type = BE_STR; elem->data.str = p; break; case INTEGER: { register int32_t data; elem->type = BE_INT; data = 0; if (elem->asnlen == 0) { ND_PRINT((ndo, "[asnlen=0]")); return -1; } if (*p & ASN_BIT8) /* negative */ data = -1; for (i = elem->asnlen; i-- > 0; p++) data = (data << ASN_SHIFT8) | *p; elem->data.integer = data; break; } case OBJECTID: elem->type = BE_OID; elem->data.raw = (const uint8_t *)p; break; case ASN_NULL: elem->type = BE_NULL; elem->data.raw = NULL; break; default: elem->type = BE_OCTET; elem->data.raw = (const uint8_t *)p; ND_PRINT((ndo, "[P/U/%s]", Class[class].Id[id])); break; } break; case APPLICATION: switch (id) { case IPADDR: elem->type = BE_INETADDR; elem->data.raw = (const uint8_t *)p; break; case COUNTER: case GAUGE: case TIMETICKS: { register uint32_t data; elem->type = BE_UNS; data = 0; for (i = elem->asnlen; i-- > 0; p++) data = (data << 8) + *p; elem->data.uns = data; break; } case COUNTER64: { register uint64_t data64; elem->type = BE_UNS64; data64 = 0; for (i = elem->asnlen; i-- > 0; p++) data64 = (data64 << 8) + *p; elem->data.uns64 = data64; break; } default: elem->type = BE_OCTET; elem->data.raw = (const uint8_t *)p; ND_PRINT((ndo, "[P/A/%s]", Class[class].Id[id])); break; } break; case CONTEXT: switch (id) { case NOSUCHOBJECT: elem->type = BE_NOSUCHOBJECT; elem->data.raw = NULL; break; case NOSUCHINSTANCE: elem->type = BE_NOSUCHINST; elem->data.raw = NULL; break; case ENDOFMIBVIEW: elem->type = BE_ENDOFMIBVIEW; elem->data.raw = NULL; break; } break; default: ND_PRINT((ndo, "[P/%s/%s]", Class[class].name, Class[class].Id[id])); elem->type = BE_OCTET; elem->data.raw = (const uint8_t *)p; break; } break; case CONSTRUCTED: switch (class) { case UNIVERSAL: switch (id) { case SEQUENCE: elem->type = BE_SEQ; elem->data.raw = (const uint8_t *)p; break; default: elem->type = BE_OCTET; elem->data.raw = (const uint8_t *)p; ND_PRINT((ndo, "C/U/%s", Class[class].Id[id])); break; } break; case CONTEXT: elem->type = BE_PDU; elem->data.raw = (const uint8_t *)p; break; default: elem->type = BE_OCTET; elem->data.raw = (const uint8_t *)p; ND_PRINT((ndo, "C/%s/%s", Class[class].name, Class[class].Id[id])); break; } break; } p += elem->asnlen; len -= elem->asnlen; return elem->asnlen + hdr; trunc: ND_PRINT((ndo, "%s", tstr)); return -1; } static int asn1_print_octets(netdissect_options *ndo, struct be *elem) { const u_char *p = (const u_char *)elem->data.raw; uint32_t asnlen = elem->asnlen; uint32_t i; ND_TCHECK2(*p, asnlen); for (i = asnlen; i-- > 0; p++) ND_PRINT((ndo, "_%.2x", *p)); return 0; trunc: ND_PRINT((ndo, "%s", tstr)); return -1; } static int asn1_print_string(netdissect_options *ndo, struct be *elem) { register int printable = 1, first = 1; const u_char *p; uint32_t asnlen = elem->asnlen; uint32_t i; p = elem->data.str; ND_TCHECK2(*p, asnlen); for (i = asnlen; printable && i-- > 0; p++) printable = ND_ISPRINT(*p); p = elem->data.str; if (printable) { ND_PRINT((ndo, "\"")); if (fn_printn(ndo, p, asnlen, ndo->ndo_snapend)) { ND_PRINT((ndo, "\"")); goto trunc; } ND_PRINT((ndo, "\"")); } else { for (i = asnlen; i-- > 0; p++) { ND_PRINT((ndo, first ? "%.2x" : "_%.2x", *p)); first = 0; } } return 0; trunc: ND_PRINT((ndo, "%s", tstr)); return -1; } /* * Display the ASN.1 object represented by the BE object. * This used to be an integral part of asn1_parse() before the intermediate * BE form was added. */ static int asn1_print(netdissect_options *ndo, struct be *elem) { const u_char *p; uint32_t asnlen = elem->asnlen; uint32_t i; switch (elem->type) { case BE_OCTET: if (asn1_print_octets(ndo, elem) == -1) return -1; break; case BE_NULL: break; case BE_OID: { int o = 0, first = -1; p = (const u_char *)elem->data.raw; i = asnlen; if (!ndo->ndo_nflag && asnlen > 2) { const struct obj_abrev *a = &obj_abrev_list[0]; for (; a->node; a++) { if (i < a->oid_len) continue; if (!ND_TTEST2(*p, a->oid_len)) continue; if (memcmp(a->oid, p, a->oid_len) == 0) { objp = a->node->child; i -= a->oid_len; p += a->oid_len; ND_PRINT((ndo, "%s", a->prefix)); first = 1; break; } } } for (; i-- > 0; p++) { ND_TCHECK(*p); o = (o << ASN_SHIFT7) + (*p & ~ASN_BIT8); if (*p & ASN_LONGLEN) continue; /* * first subitem encodes two items with * 1st*OIDMUX+2nd * (see X.690:1997 clause 8.19 for the details) */ if (first < 0) { int s; if (!ndo->ndo_nflag) objp = mibroot; first = 0; s = o / OIDMUX; if (s > 2) s = 2; OBJ_PRINT(s, first); o -= s * OIDMUX; } OBJ_PRINT(o, first); if (--first < 0) first = 0; o = 0; } break; } case BE_INT: ND_PRINT((ndo, "%d", elem->data.integer)); break; case BE_UNS: ND_PRINT((ndo, "%u", elem->data.uns)); break; case BE_UNS64: ND_PRINT((ndo, "%" PRIu64, elem->data.uns64)); break; case BE_STR: if (asn1_print_string(ndo, elem) == -1) return -1; break; case BE_SEQ: ND_PRINT((ndo, "Seq(%u)", elem->asnlen)); break; case BE_INETADDR: if (asnlen != ASNLEN_INETADDR) ND_PRINT((ndo, "[inetaddr len!=%d]", ASNLEN_INETADDR)); p = (const u_char *)elem->data.raw; ND_TCHECK2(*p, asnlen); for (i = asnlen; i-- != 0; p++) { ND_PRINT((ndo, (i == asnlen-1) ? "%u" : ".%u", *p)); } break; case BE_NOSUCHOBJECT: case BE_NOSUCHINST: case BE_ENDOFMIBVIEW: ND_PRINT((ndo, "[%s]", Class[EXCEPTIONS].Id[elem->id])); break; case BE_PDU: ND_PRINT((ndo, "%s(%u)", Class[CONTEXT].Id[elem->id], elem->asnlen)); break; case BE_ANY: ND_PRINT((ndo, "[BE_ANY!?]")); break; default: ND_PRINT((ndo, "[be!?]")); break; } return 0; trunc: ND_PRINT((ndo, "%s", tstr)); return -1; } #ifdef notdef /* * This is a brute force ASN.1 printer: recurses to dump an entire structure. * This will work for any ASN.1 stream, not just an SNMP PDU. * * By adding newlines and spaces at the correct places, this would print in * Rose-Normal-Form. * * This is not currently used. */ static void asn1_decode(u_char *p, u_int length) { struct be elem; int i = 0; while (i >= 0 && length > 0) { i = asn1_parse(ndo, p, length, &elem); if (i >= 0) { ND_PRINT((ndo, " ")); if (asn1_print(ndo, &elem) < 0) return; if (elem.type == BE_SEQ || elem.type == BE_PDU) { ND_PRINT((ndo, " {")); asn1_decode(elem.data.raw, elem.asnlen); ND_PRINT((ndo, " }")); } length -= i; p += i; } } } #endif #ifdef USE_LIBSMI struct smi2be { SmiBasetype basetype; int be; }; static const struct smi2be smi2betab[] = { { SMI_BASETYPE_INTEGER32, BE_INT }, { SMI_BASETYPE_OCTETSTRING, BE_STR }, { SMI_BASETYPE_OCTETSTRING, BE_INETADDR }, { SMI_BASETYPE_OBJECTIDENTIFIER, BE_OID }, { SMI_BASETYPE_UNSIGNED32, BE_UNS }, { SMI_BASETYPE_INTEGER64, BE_NONE }, { SMI_BASETYPE_UNSIGNED64, BE_UNS64 }, { SMI_BASETYPE_FLOAT32, BE_NONE }, { SMI_BASETYPE_FLOAT64, BE_NONE }, { SMI_BASETYPE_FLOAT128, BE_NONE }, { SMI_BASETYPE_ENUM, BE_INT }, { SMI_BASETYPE_BITS, BE_STR }, { SMI_BASETYPE_UNKNOWN, BE_NONE } }; static int smi_decode_oid(netdissect_options *ndo, struct be *elem, unsigned int *oid, unsigned int oidsize, unsigned int *oidlen) { const u_char *p = (const u_char *)elem->data.raw; uint32_t asnlen = elem->asnlen; int o = 0, first = -1, i = asnlen; unsigned int firstval; for (*oidlen = 0; i-- > 0; p++) { ND_TCHECK(*p); o = (o << ASN_SHIFT7) + (*p & ~ASN_BIT8); if (*p & ASN_LONGLEN) continue; /* * first subitem encodes two items with 1st*OIDMUX+2nd * (see X.690:1997 clause 8.19 for the details) */ if (first < 0) { first = 0; firstval = o / OIDMUX; if (firstval > 2) firstval = 2; o -= firstval * OIDMUX; if (*oidlen < oidsize) { oid[(*oidlen)++] = firstval; } } if (*oidlen < oidsize) { oid[(*oidlen)++] = o; } o = 0; } return 0; trunc: ND_PRINT((ndo, "%s", tstr)); return -1; } static int smi_check_type(SmiBasetype basetype, int be) { int i; for (i = 0; smi2betab[i].basetype != SMI_BASETYPE_UNKNOWN; i++) { if (smi2betab[i].basetype == basetype && smi2betab[i].be == be) { return 1; } } return 0; } static int smi_check_a_range(SmiType *smiType, SmiRange *smiRange, struct be *elem) { int ok = 1; switch (smiType->basetype) { case SMI_BASETYPE_OBJECTIDENTIFIER: case SMI_BASETYPE_OCTETSTRING: if (smiRange->minValue.value.unsigned32 == smiRange->maxValue.value.unsigned32) { ok = (elem->asnlen == smiRange->minValue.value.unsigned32); } else { ok = (elem->asnlen >= smiRange->minValue.value.unsigned32 && elem->asnlen <= smiRange->maxValue.value.unsigned32); } break; case SMI_BASETYPE_INTEGER32: ok = (elem->data.integer >= smiRange->minValue.value.integer32 && elem->data.integer <= smiRange->maxValue.value.integer32); break; case SMI_BASETYPE_UNSIGNED32: ok = (elem->data.uns >= smiRange->minValue.value.unsigned32 && elem->data.uns <= smiRange->maxValue.value.unsigned32); break; case SMI_BASETYPE_UNSIGNED64: /* XXX */ break; /* case SMI_BASETYPE_INTEGER64: SMIng */ /* case SMI_BASETYPE_FLOAT32: SMIng */ /* case SMI_BASETYPE_FLOAT64: SMIng */ /* case SMI_BASETYPE_FLOAT128: SMIng */ case SMI_BASETYPE_ENUM: case SMI_BASETYPE_BITS: case SMI_BASETYPE_UNKNOWN: ok = 1; break; default: ok = 0; break; } return ok; } static int smi_check_range(SmiType *smiType, struct be *elem) { SmiRange *smiRange; int ok = 1; for (smiRange = smiGetFirstRange(smiType); smiRange; smiRange = smiGetNextRange(smiRange)) { ok = smi_check_a_range(smiType, smiRange, elem); if (ok) { break; } } if (ok) { SmiType *parentType; parentType = smiGetParentType(smiType); if (parentType) { ok = smi_check_range(parentType, elem); } } return ok; } static SmiNode * smi_print_variable(netdissect_options *ndo, struct be *elem, int *status) { unsigned int oid[128], oidlen; SmiNode *smiNode = NULL; unsigned int i; if (!nd_smi_module_loaded) { *status = asn1_print(ndo, elem); return NULL; } *status = smi_decode_oid(ndo, elem, oid, sizeof(oid) / sizeof(unsigned int), &oidlen); if (*status < 0) return NULL; smiNode = smiGetNodeByOID(oidlen, oid); if (! smiNode) { *status = asn1_print(ndo, elem); return NULL; } if (ndo->ndo_vflag) { ND_PRINT((ndo, "%s::", smiGetNodeModule(smiNode)->name)); } ND_PRINT((ndo, "%s", smiNode->name)); if (smiNode->oidlen < oidlen) { for (i = smiNode->oidlen; i < oidlen; i++) { ND_PRINT((ndo, ".%u", oid[i])); } } *status = 0; return smiNode; } static int smi_print_value(netdissect_options *ndo, SmiNode *smiNode, u_short pduid, struct be *elem) { unsigned int i, oid[128], oidlen; SmiType *smiType; SmiNamedNumber *nn; int done = 0; if (! smiNode || ! (smiNode->nodekind & (SMI_NODEKIND_SCALAR | SMI_NODEKIND_COLUMN))) { return asn1_print(ndo, elem); } if (elem->type == BE_NOSUCHOBJECT || elem->type == BE_NOSUCHINST || elem->type == BE_ENDOFMIBVIEW) { return asn1_print(ndo, elem); } if (NOTIFY_CLASS(pduid) && smiNode->access < SMI_ACCESS_NOTIFY) { ND_PRINT((ndo, "[notNotifyable]")); } if (READ_CLASS(pduid) && smiNode->access < SMI_ACCESS_READ_ONLY) { ND_PRINT((ndo, "[notReadable]")); } if (WRITE_CLASS(pduid) && smiNode->access < SMI_ACCESS_READ_WRITE) { ND_PRINT((ndo, "[notWritable]")); } if (RESPONSE_CLASS(pduid) && smiNode->access == SMI_ACCESS_NOT_ACCESSIBLE) { ND_PRINT((ndo, "[noAccess]")); } smiType = smiGetNodeType(smiNode); if (! smiType) { return asn1_print(ndo, elem); } if (! smi_check_type(smiType->basetype, elem->type)) { ND_PRINT((ndo, "[wrongType]")); } if (! smi_check_range(smiType, elem)) { ND_PRINT((ndo, "[outOfRange]")); } /* resolve bits to named bits */ /* check whether instance identifier is valid */ /* apply display hints (integer, octetstring) */ /* convert instance identifier to index type values */ switch (elem->type) { case BE_OID: if (smiType->basetype == SMI_BASETYPE_BITS) { /* print bit labels */ } else { if (nd_smi_module_loaded && smi_decode_oid(ndo, elem, oid, sizeof(oid)/sizeof(unsigned int), &oidlen) == 0) { smiNode = smiGetNodeByOID(oidlen, oid); if (smiNode) { if (ndo->ndo_vflag) { ND_PRINT((ndo, "%s::", smiGetNodeModule(smiNode)->name)); } ND_PRINT((ndo, "%s", smiNode->name)); if (smiNode->oidlen < oidlen) { for (i = smiNode->oidlen; i < oidlen; i++) { ND_PRINT((ndo, ".%u", oid[i])); } } done++; } } } break; case BE_INT: if (smiType->basetype == SMI_BASETYPE_ENUM) { for (nn = smiGetFirstNamedNumber(smiType); nn; nn = smiGetNextNamedNumber(nn)) { if (nn->value.value.integer32 == elem->data.integer) { ND_PRINT((ndo, "%s", nn->name)); ND_PRINT((ndo, "(%d)", elem->data.integer)); done++; break; } } } break; } if (! done) { return asn1_print(ndo, elem); } return 0; } #endif /* * General SNMP header * SEQUENCE { * version INTEGER {version-1(0)}, * community OCTET STRING, * data ANY -- PDUs * } * PDUs for all but Trap: (see rfc1157 from page 15 on) * SEQUENCE { * request-id INTEGER, * error-status INTEGER, * error-index INTEGER, * varbindlist SEQUENCE OF * SEQUENCE { * name ObjectName, * value ObjectValue * } * } * PDU for Trap: * SEQUENCE { * enterprise OBJECT IDENTIFIER, * agent-addr NetworkAddress, * generic-trap INTEGER, * specific-trap INTEGER, * time-stamp TimeTicks, * varbindlist SEQUENCE OF * SEQUENCE { * name ObjectName, * value ObjectValue * } * } */ /* * Decode SNMP varBind */ static void varbind_print(netdissect_options *ndo, u_short pduid, const u_char *np, u_int length) { struct be elem; int count = 0, ind; #ifdef USE_LIBSMI SmiNode *smiNode = NULL; #endif int status; /* Sequence of varBind */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_SEQ) { ND_PRINT((ndo, "[!SEQ of varbind]")); asn1_print(ndo, &elem); return; } if ((u_int)count < length) ND_PRINT((ndo, "[%d extra after SEQ of varbind]", length - count)); /* descend */ length = elem.asnlen; np = (const u_char *)elem.data.raw; for (ind = 1; length > 0; ind++) { const u_char *vbend; u_int vblength; ND_PRINT((ndo, " ")); /* Sequence */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_SEQ) { ND_PRINT((ndo, "[!varbind]")); asn1_print(ndo, &elem); return; } vbend = np + count; vblength = length - count; /* descend */ length = elem.asnlen; np = (const u_char *)elem.data.raw; /* objName (OID) */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_OID) { ND_PRINT((ndo, "[objName!=OID]")); asn1_print(ndo, &elem); return; } #ifdef USE_LIBSMI smiNode = smi_print_variable(ndo, &elem, &status); #else status = asn1_print(ndo, &elem); #endif if (status < 0) return; length -= count; np += count; if (pduid != GETREQ && pduid != GETNEXTREQ && pduid != GETBULKREQ) ND_PRINT((ndo, "=")); /* objVal (ANY) */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (pduid == GETREQ || pduid == GETNEXTREQ || pduid == GETBULKREQ) { if (elem.type != BE_NULL) { ND_PRINT((ndo, "[objVal!=NULL]")); if (asn1_print(ndo, &elem) < 0) return; } } else { if (elem.type != BE_NULL) { #ifdef USE_LIBSMI status = smi_print_value(ndo, smiNode, pduid, &elem); #else status = asn1_print(ndo, &elem); #endif } if (status < 0) return; } length = vblength; np = vbend; } } /* * Decode SNMP PDUs: GetRequest, GetNextRequest, GetResponse, SetRequest, * GetBulk, Inform, V2Trap, and Report */ static void snmppdu_print(netdissect_options *ndo, u_short pduid, const u_char *np, u_int length) { struct be elem; int count = 0, error_status; /* reqId (Integer) */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_INT) { ND_PRINT((ndo, "[reqId!=INT]")); asn1_print(ndo, &elem); return; } if (ndo->ndo_vflag) ND_PRINT((ndo, "R=%d ", elem.data.integer)); length -= count; np += count; /* errorStatus (Integer) */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_INT) { ND_PRINT((ndo, "[errorStatus!=INT]")); asn1_print(ndo, &elem); return; } error_status = 0; if ((pduid == GETREQ || pduid == GETNEXTREQ || pduid == SETREQ || pduid == INFORMREQ || pduid == V2TRAP || pduid == REPORT) && elem.data.integer != 0) { char errbuf[20]; ND_PRINT((ndo, "[errorStatus(%s)!=0]", DECODE_ErrorStatus(elem.data.integer))); } else if (pduid == GETBULKREQ) { ND_PRINT((ndo, " N=%d", elem.data.integer)); } else if (elem.data.integer != 0) { char errbuf[20]; ND_PRINT((ndo, " %s", DECODE_ErrorStatus(elem.data.integer))); error_status = elem.data.integer; } length -= count; np += count; /* errorIndex (Integer) */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_INT) { ND_PRINT((ndo, "[errorIndex!=INT]")); asn1_print(ndo, &elem); return; } if ((pduid == GETREQ || pduid == GETNEXTREQ || pduid == SETREQ || pduid == INFORMREQ || pduid == V2TRAP || pduid == REPORT) && elem.data.integer != 0) ND_PRINT((ndo, "[errorIndex(%d)!=0]", elem.data.integer)); else if (pduid == GETBULKREQ) ND_PRINT((ndo, " M=%d", elem.data.integer)); else if (elem.data.integer != 0) { if (!error_status) ND_PRINT((ndo, "[errorIndex(%d) w/o errorStatus]", elem.data.integer)); else ND_PRINT((ndo, "@%d", elem.data.integer)); } else if (error_status) { ND_PRINT((ndo, "[errorIndex==0]")); } length -= count; np += count; varbind_print(ndo, pduid, np, length); return; } /* * Decode SNMP Trap PDU */ static void trappdu_print(netdissect_options *ndo, const u_char *np, u_int length) { struct be elem; int count = 0, generic; ND_PRINT((ndo, " ")); /* enterprise (oid) */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_OID) { ND_PRINT((ndo, "[enterprise!=OID]")); asn1_print(ndo, &elem); return; } if (asn1_print(ndo, &elem) < 0) return; length -= count; np += count; ND_PRINT((ndo, " ")); /* agent-addr (inetaddr) */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_INETADDR) { ND_PRINT((ndo, "[agent-addr!=INETADDR]")); asn1_print(ndo, &elem); return; } if (asn1_print(ndo, &elem) < 0) return; length -= count; np += count; /* generic-trap (Integer) */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_INT) { ND_PRINT((ndo, "[generic-trap!=INT]")); asn1_print(ndo, &elem); return; } generic = elem.data.integer; { char buf[20]; ND_PRINT((ndo, " %s", DECODE_GenericTrap(generic))); } length -= count; np += count; /* specific-trap (Integer) */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_INT) { ND_PRINT((ndo, "[specific-trap!=INT]")); asn1_print(ndo, &elem); return; } if (generic != GT_ENTERPRISE) { if (elem.data.integer != 0) ND_PRINT((ndo, "[specific-trap(%d)!=0]", elem.data.integer)); } else ND_PRINT((ndo, " s=%d", elem.data.integer)); length -= count; np += count; ND_PRINT((ndo, " ")); /* time-stamp (TimeTicks) */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_UNS) { /* XXX */ ND_PRINT((ndo, "[time-stamp!=TIMETICKS]")); asn1_print(ndo, &elem); return; } if (asn1_print(ndo, &elem) < 0) return; length -= count; np += count; varbind_print(ndo, TRAP, np, length); return; } /* * Decode arbitrary SNMP PDUs. */ static void pdu_print(netdissect_options *ndo, const u_char *np, u_int length, int version) { struct be pdu; int count = 0; /* PDU (Context) */ if ((count = asn1_parse(ndo, np, length, &pdu)) < 0) return; if (pdu.type != BE_PDU) { ND_PRINT((ndo, "[no PDU]")); return; } if ((u_int)count < length) ND_PRINT((ndo, "[%d extra after PDU]", length - count)); if (ndo->ndo_vflag) { ND_PRINT((ndo, "{ ")); } if (asn1_print(ndo, &pdu) < 0) return; ND_PRINT((ndo, " ")); /* descend into PDU */ length = pdu.asnlen; np = (const u_char *)pdu.data.raw; if (version == SNMP_VERSION_1 && (pdu.id == GETBULKREQ || pdu.id == INFORMREQ || pdu.id == V2TRAP || pdu.id == REPORT)) { ND_PRINT((ndo, "[v2 PDU in v1 message]")); return; } if (version == SNMP_VERSION_2 && pdu.id == TRAP) { ND_PRINT((ndo, "[v1 PDU in v2 message]")); return; } switch (pdu.id) { case TRAP: trappdu_print(ndo, np, length); break; case GETREQ: case GETNEXTREQ: case GETRESP: case SETREQ: case GETBULKREQ: case INFORMREQ: case V2TRAP: case REPORT: snmppdu_print(ndo, pdu.id, np, length); break; } if (ndo->ndo_vflag) { ND_PRINT((ndo, " } ")); } } /* * Decode a scoped SNMP PDU. */ static void scopedpdu_print(netdissect_options *ndo, const u_char *np, u_int length, int version) { struct be elem; int count = 0; /* Sequence */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_SEQ) { ND_PRINT((ndo, "[!scoped PDU]")); asn1_print(ndo, &elem); return; } length = elem.asnlen; np = (const u_char *)elem.data.raw; /* contextEngineID (OCTET STRING) */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_STR) { ND_PRINT((ndo, "[contextEngineID!=STR]")); asn1_print(ndo, &elem); return; } length -= count; np += count; ND_PRINT((ndo, "E=")); if (asn1_print_octets(ndo, &elem) == -1) return; ND_PRINT((ndo, " ")); /* contextName (OCTET STRING) */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_STR) { ND_PRINT((ndo, "[contextName!=STR]")); asn1_print(ndo, &elem); return; } length -= count; np += count; ND_PRINT((ndo, "C=")); if (asn1_print_string(ndo, &elem) == -1) return; ND_PRINT((ndo, " ")); pdu_print(ndo, np, length, version); } /* * Decode SNMP Community Header (SNMPv1 and SNMPv2c) */ static void community_print(netdissect_options *ndo, const u_char *np, u_int length, int version) { struct be elem; int count = 0; /* Community (String) */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_STR) { ND_PRINT((ndo, "[comm!=STR]")); asn1_print(ndo, &elem); return; } /* default community */ if (!(elem.asnlen == sizeof(DEF_COMMUNITY) - 1 && strncmp((const char *)elem.data.str, DEF_COMMUNITY, sizeof(DEF_COMMUNITY) - 1) == 0)) { /* ! "public" */ ND_PRINT((ndo, "C=")); if (asn1_print_string(ndo, &elem) == -1) return; ND_PRINT((ndo, " ")); } length -= count; np += count; pdu_print(ndo, np, length, version); } /* * Decode SNMPv3 User-based Security Message Header (SNMPv3) */ static void usm_print(netdissect_options *ndo, const u_char *np, u_int length) { struct be elem; int count = 0; /* Sequence */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_SEQ) { ND_PRINT((ndo, "[!usm]")); asn1_print(ndo, &elem); return; } length = elem.asnlen; np = (const u_char *)elem.data.raw; /* msgAuthoritativeEngineID (OCTET STRING) */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_STR) { ND_PRINT((ndo, "[msgAuthoritativeEngineID!=STR]")); asn1_print(ndo, &elem); return; } length -= count; np += count; /* msgAuthoritativeEngineBoots (INTEGER) */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_INT) { ND_PRINT((ndo, "[msgAuthoritativeEngineBoots!=INT]")); asn1_print(ndo, &elem); return; } if (ndo->ndo_vflag) ND_PRINT((ndo, "B=%d ", elem.data.integer)); length -= count; np += count; /* msgAuthoritativeEngineTime (INTEGER) */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_INT) { ND_PRINT((ndo, "[msgAuthoritativeEngineTime!=INT]")); asn1_print(ndo, &elem); return; } if (ndo->ndo_vflag) ND_PRINT((ndo, "T=%d ", elem.data.integer)); length -= count; np += count; /* msgUserName (OCTET STRING) */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_STR) { ND_PRINT((ndo, "[msgUserName!=STR]")); asn1_print(ndo, &elem); return; } length -= count; np += count; ND_PRINT((ndo, "U=")); if (asn1_print_string(ndo, &elem) == -1) return; ND_PRINT((ndo, " ")); /* msgAuthenticationParameters (OCTET STRING) */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_STR) { ND_PRINT((ndo, "[msgAuthenticationParameters!=STR]")); asn1_print(ndo, &elem); return; } length -= count; np += count; /* msgPrivacyParameters (OCTET STRING) */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_STR) { ND_PRINT((ndo, "[msgPrivacyParameters!=STR]")); asn1_print(ndo, &elem); return; } length -= count; np += count; if ((u_int)count < length) ND_PRINT((ndo, "[%d extra after usm SEQ]", length - count)); } /* * Decode SNMPv3 Message Header (SNMPv3) */ static void v3msg_print(netdissect_options *ndo, const u_char *np, u_int length) { struct be elem; int count = 0; u_char flags; int model; const u_char *xnp = np; int xlength = length; /* Sequence */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_SEQ) { ND_PRINT((ndo, "[!message]")); asn1_print(ndo, &elem); return; } length = elem.asnlen; np = (const u_char *)elem.data.raw; if (ndo->ndo_vflag) { ND_PRINT((ndo, "{ ")); } /* msgID (INTEGER) */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_INT) { ND_PRINT((ndo, "[msgID!=INT]")); asn1_print(ndo, &elem); return; } length -= count; np += count; /* msgMaxSize (INTEGER) */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_INT) { ND_PRINT((ndo, "[msgMaxSize!=INT]")); asn1_print(ndo, &elem); return; } length -= count; np += count; /* msgFlags (OCTET STRING) */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_STR) { ND_PRINT((ndo, "[msgFlags!=STR]")); asn1_print(ndo, &elem); return; } if (elem.asnlen != 1) { ND_PRINT((ndo, "[msgFlags size %d]", elem.asnlen)); return; } flags = elem.data.str[0]; if (flags != 0x00 && flags != 0x01 && flags != 0x03 && flags != 0x04 && flags != 0x05 && flags != 0x07) { ND_PRINT((ndo, "[msgFlags=0x%02X]", flags)); return; } length -= count; np += count; ND_PRINT((ndo, "F=%s%s%s ", flags & 0x01 ? "a" : "", flags & 0x02 ? "p" : "", flags & 0x04 ? "r" : "")); /* msgSecurityModel (INTEGER) */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_INT) { ND_PRINT((ndo, "[msgSecurityModel!=INT]")); asn1_print(ndo, &elem); return; } model = elem.data.integer; length -= count; np += count; if ((u_int)count < length) ND_PRINT((ndo, "[%d extra after message SEQ]", length - count)); if (ndo->ndo_vflag) { ND_PRINT((ndo, "} ")); } if (model == 3) { if (ndo->ndo_vflag) { ND_PRINT((ndo, "{ USM ")); } } else { ND_PRINT((ndo, "[security model %d]", model)); return; } np = xnp + (np - xnp); length = xlength - (np - xnp); /* msgSecurityParameters (OCTET STRING) */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_STR) { ND_PRINT((ndo, "[msgSecurityParameters!=STR]")); asn1_print(ndo, &elem); return; } length -= count; np += count; if (model == 3) { usm_print(ndo, elem.data.str, elem.asnlen); if (ndo->ndo_vflag) { ND_PRINT((ndo, "} ")); } } if (ndo->ndo_vflag) { ND_PRINT((ndo, "{ ScopedPDU ")); } scopedpdu_print(ndo, np, length, 3); if (ndo->ndo_vflag) { ND_PRINT((ndo, "} ")); } } /* * Decode SNMP header and pass on to PDU printing routines */ void snmp_print(netdissect_options *ndo, const u_char *np, u_int length) { struct be elem; int count = 0; int version = 0; ND_PRINT((ndo, " ")); /* initial Sequence */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_SEQ) { ND_PRINT((ndo, "[!init SEQ]")); asn1_print(ndo, &elem); return; } if ((u_int)count < length) ND_PRINT((ndo, "[%d extra after iSEQ]", length - count)); /* descend */ length = elem.asnlen; np = (const u_char *)elem.data.raw; /* Version (INTEGER) */ if ((count = asn1_parse(ndo, np, length, &elem)) < 0) return; if (elem.type != BE_INT) { ND_PRINT((ndo, "[version!=INT]")); asn1_print(ndo, &elem); return; } switch (elem.data.integer) { case SNMP_VERSION_1: case SNMP_VERSION_2: case SNMP_VERSION_3: if (ndo->ndo_vflag) ND_PRINT((ndo, "{ %s ", SnmpVersion[elem.data.integer])); break; default: ND_PRINT((ndo, "SNMP [version = %d]", elem.data.integer)); return; } version = elem.data.integer; length -= count; np += count; switch (version) { case SNMP_VERSION_1: case SNMP_VERSION_2: community_print(ndo, np, length, version); break; case SNMP_VERSION_3: v3msg_print(ndo, np, length); break; default: ND_PRINT((ndo, "[version = %d]", elem.data.integer)); break; } if (ndo->ndo_vflag) { ND_PRINT((ndo, "} ")); } } tcpdump-4.9.3/print-usb.c0000644000026300017510000001027313544412561013425 0ustar mcrmcr/* * Copyright 2009 Bert Vermeulen * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by Paolo Abeni.'' * The name of author may not be used to endorse or promote products derived * from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * Support for USB packets * */ /* \summary: USB printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #if defined(HAVE_PCAP_USB_H) && defined(DLT_USB_LINUX) #include static const char tstr[] = "[|usb]"; /* returns direction: 1=inbound 2=outbound -1=invalid */ static int get_direction(int transfer_type, int event_type) { int direction; direction = -1; switch(transfer_type){ case URB_BULK: case URB_CONTROL: case URB_ISOCHRONOUS: switch(event_type) { case URB_SUBMIT: direction = 2; break; case URB_COMPLETE: case URB_ERROR: direction = 1; break; default: direction = -1; } break; case URB_INTERRUPT: switch(event_type) { case URB_SUBMIT: direction = 1; break; case URB_COMPLETE: case URB_ERROR: direction = 2; break; default: direction = -1; } break; default: direction = -1; } return direction; } static void usb_header_print(netdissect_options *ndo, const pcap_usb_header *uh) { int direction; switch(uh->transfer_type) { case URB_ISOCHRONOUS: ND_PRINT((ndo, "ISOCHRONOUS")); break; case URB_INTERRUPT: ND_PRINT((ndo, "INTERRUPT")); break; case URB_CONTROL: ND_PRINT((ndo, "CONTROL")); break; case URB_BULK: ND_PRINT((ndo, "BULK")); break; default: ND_PRINT((ndo, " ?")); } switch(uh->event_type) { case URB_SUBMIT: ND_PRINT((ndo, " SUBMIT")); break; case URB_COMPLETE: ND_PRINT((ndo, " COMPLETE")); break; case URB_ERROR: ND_PRINT((ndo, " ERROR")); break; default: ND_PRINT((ndo, " ?")); } direction = get_direction(uh->transfer_type, uh->event_type); if(direction == 1) ND_PRINT((ndo, " from")); else if(direction == 2) ND_PRINT((ndo, " to")); ND_PRINT((ndo, " %d:%d:%d", uh->bus_id, uh->device_address, uh->endpoint_number & 0x7f)); } /* * This is the top level routine of the printer for captures with a * 48-byte header. * * 'p' points to the header of the packet, 'h->ts' is the timestamp, * 'h->len' is the length of the packet off the wire, and 'h->caplen' * is the number of bytes actually captured. */ u_int usb_linux_48_byte_print(netdissect_options *ndo, const struct pcap_pkthdr *h, register const u_char *p) { if (h->caplen < sizeof(pcap_usb_header)) { ND_PRINT((ndo, "%s", tstr)); return(sizeof(pcap_usb_header)); } usb_header_print(ndo, (const pcap_usb_header *) p); return(sizeof(pcap_usb_header)); } #ifdef DLT_USB_LINUX_MMAPPED /* * This is the top level routine of the printer for captures with a * 64-byte header. * * 'p' points to the header of the packet, 'h->ts' is the timestamp, * 'h->len' is the length of the packet off the wire, and 'h->caplen' * is the number of bytes actually captured. */ u_int usb_linux_64_byte_print(netdissect_options *ndo, const struct pcap_pkthdr *h, register const u_char *p) { if (h->caplen < sizeof(pcap_usb_header_mmapped)) { ND_PRINT((ndo, "%s", tstr)); return(sizeof(pcap_usb_header_mmapped)); } usb_header_print(ndo, (const pcap_usb_header *) p); return(sizeof(pcap_usb_header_mmapped)); } #endif /* DLT_USB_LINUX_MMAPPED */ #endif /* defined(HAVE_PCAP_USB_H) && defined(DLT_USB_LINUX) */ tcpdump-4.9.3/ospf.h0000644000026300017510000002432313544412561012457 0ustar mcrmcr/* * Copyright (c) 1991, 1993, 1994, 1995, 1996, 1997 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of * the University nor the names of its contributors may be used to endorse * or promote products derived from this software without specific prior * written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * OSPF support contributed by Jeffrey Honig (jch@mitchell.cit.cornell.edu) */ #define OSPF_TYPE_UMD 0 /* UMd's special monitoring packets */ #define OSPF_TYPE_HELLO 1 /* Hello */ #define OSPF_TYPE_DD 2 /* Database Description */ #define OSPF_TYPE_LS_REQ 3 /* Link State Request */ #define OSPF_TYPE_LS_UPDATE 4 /* Link State Update */ #define OSPF_TYPE_LS_ACK 5 /* Link State Ack */ /* Options field * * +------------------------------------+ * | DN | O | DC | L | N/P | MC | E | T | * +------------------------------------+ * */ #define OSPF_OPTION_T 0x01 /* T bit: TOS support */ #define OSPF_OPTION_E 0x02 /* E bit: External routes advertised */ #define OSPF_OPTION_MC 0x04 /* MC bit: Multicast capable */ #define OSPF_OPTION_NP 0x08 /* N/P bit: NSSA capable */ #define OSPF_OPTION_EA 0x10 /* EA bit: External Attribute capable */ #define OSPF_OPTION_L 0x10 /* L bit: Packet contains LLS data block */ #define OSPF_OPTION_DC 0x20 /* DC bit: Demand circuit capable */ #define OSPF_OPTION_O 0x40 /* O bit: Opaque LSA capable */ #define OSPF_OPTION_DN 0x80 /* DN bit: Up/Down Bit capable - draft-ietf-ospf-2547-dnbit-04 */ /* ospf_authtype */ #define OSPF_AUTH_NONE 0 /* No auth-data */ #define OSPF_AUTH_SIMPLE 1 /* Simple password */ #define OSPF_AUTH_SIMPLE_LEN 8 /* max length of simple authentication */ #define OSPF_AUTH_MD5 2 /* MD5 authentication */ #define OSPF_AUTH_MD5_LEN 16 /* length of MD5 authentication */ /* db_flags */ #define OSPF_DB_INIT 0x04 #define OSPF_DB_MORE 0x02 #define OSPF_DB_MASTER 0x01 #define OSPF_DB_RESYNC 0x08 /* RFC4811 */ /* ls_type */ #define LS_TYPE_ROUTER 1 /* router link */ #define LS_TYPE_NETWORK 2 /* network link */ #define LS_TYPE_SUM_IP 3 /* summary link */ #define LS_TYPE_SUM_ABR 4 /* summary area link */ #define LS_TYPE_ASE 5 /* ASE */ #define LS_TYPE_GROUP 6 /* Group membership (multicast */ /* extensions 23 July 1991) */ #define LS_TYPE_NSSA 7 /* rfc3101 - Not so Stubby Areas */ #define LS_TYPE_OPAQUE_LL 9 /* rfc2370 - Opaque Link Local */ #define LS_TYPE_OPAQUE_AL 10 /* rfc2370 - Opaque Link Local */ #define LS_TYPE_OPAQUE_DW 11 /* rfc2370 - Opaque Domain Wide */ #define LS_OPAQUE_TYPE_TE 1 /* rfc3630 */ #define LS_OPAQUE_TYPE_GRACE 3 /* rfc3623 */ #define LS_OPAQUE_TYPE_RI 4 /* draft-ietf-ospf-cap-03 */ #define LS_OPAQUE_TE_TLV_ROUTER 1 /* rfc3630 */ #define LS_OPAQUE_TE_TLV_LINK 2 /* rfc3630 */ #define LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE 1 /* rfc3630 */ #define LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID 2 /* rfc3630 */ #define LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP 3 /* rfc3630 */ #define LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP 4 /* rfc3630 */ #define LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC 5 /* rfc3630 */ #define LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW 6 /* rfc3630 */ #define LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW 7 /* rfc3630 */ #define LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW 8 /* rfc3630 */ #define LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP 9 /* rfc3630 */ #define LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID 11 /* rfc4203 */ #define LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE 14 /* rfc4203 */ #define LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR 15 /* rfc4203 */ #define LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP 16 /* rfc4203 */ #define LS_OPAQUE_TE_LINK_SUBTLV_BW_CONSTRAINTS 17 /* rfc4124 */ #define LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP 1 /* rfc3630 */ #define LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA 2 /* rfc3630 */ #define LS_OPAQUE_GRACE_TLV_PERIOD 1 /* rfc3623 */ #define LS_OPAQUE_GRACE_TLV_REASON 2 /* rfc3623 */ #define LS_OPAQUE_GRACE_TLV_INT_ADDRESS 3 /* rfc3623 */ #define LS_OPAQUE_GRACE_TLV_REASON_UNKNOWN 0 /* rfc3623 */ #define LS_OPAQUE_GRACE_TLV_REASON_SW_RESTART 1 /* rfc3623 */ #define LS_OPAQUE_GRACE_TLV_REASON_SW_UPGRADE 2 /* rfc3623 */ #define LS_OPAQUE_GRACE_TLV_REASON_CP_SWITCH 3 /* rfc3623 */ #define LS_OPAQUE_RI_TLV_CAP 1 /* draft-ietf-ospf-cap-03 */ /* rla_link.link_type */ #define RLA_TYPE_ROUTER 1 /* point-to-point to another router */ #define RLA_TYPE_TRANSIT 2 /* connection to transit network */ #define RLA_TYPE_STUB 3 /* connection to stub network */ #define RLA_TYPE_VIRTUAL 4 /* virtual link */ /* rla_flags */ #define RLA_FLAG_B 0x01 #define RLA_FLAG_E 0x02 #define RLA_FLAG_W1 0x04 #define RLA_FLAG_W2 0x08 /* sla_tosmetric breakdown */ #define SLA_MASK_TOS 0x7f000000 #define SLA_MASK_METRIC 0x00ffffff #define SLA_SHIFT_TOS 24 /* asla_tosmetric breakdown */ #define ASLA_FLAG_EXTERNAL 0x80000000 #define ASLA_MASK_TOS 0x7f000000 #define ASLA_SHIFT_TOS 24 #define ASLA_MASK_METRIC 0x00ffffff /* multicast vertex type */ #define MCLA_VERTEX_ROUTER 1 #define MCLA_VERTEX_NETWORK 2 /* Link-Local-Signaling */ #define OSPF_LLS_HDRLEN 4U /* RFC5613 Section 2.2 */ #define OSPF_LLS_EO 1 /* RFC4811, RFC4812 */ #define OSPF_LLS_MD5 2 /* RFC4813 */ #define OSPF_LLS_EO_LR 0x00000001 /* RFC4811 */ #define OSPF_LLS_EO_RS 0x00000002 /* RFC4812 */ /* * TOS metric struct (will be 0 or more in router links update) */ struct tos_metric { uint8_t tos_type; uint8_t reserved; uint8_t tos_metric[2]; }; struct tos_link { uint8_t link_type; uint8_t link_tos_count; uint8_t tos_metric[2]; }; union un_tos { struct tos_link link; struct tos_metric metrics; }; /* link state advertisement header */ struct lsa_hdr { uint16_t ls_age; uint8_t ls_options; uint8_t ls_type; union { struct in_addr lsa_id; struct { /* opaque LSAs change the LSA-ID field */ uint8_t opaque_type; uint8_t opaque_id[3]; } opaque_field; } un_lsa_id; struct in_addr ls_router; uint32_t ls_seq; uint16_t ls_chksum; uint16_t ls_length; }; /* link state advertisement */ struct lsa { struct lsa_hdr ls_hdr; /* Link state types */ union { /* Router links advertisements */ struct { uint8_t rla_flags; uint8_t rla_zero[1]; uint16_t rla_count; struct rlalink { struct in_addr link_id; struct in_addr link_data; union un_tos un_tos; } rla_link[1]; /* may repeat */ } un_rla; /* Network links advertisements */ struct { struct in_addr nla_mask; struct in_addr nla_router[1]; /* may repeat */ } un_nla; /* Summary links advertisements */ struct { struct in_addr sla_mask; uint32_t sla_tosmetric[1]; /* may repeat */ } un_sla; /* AS external links advertisements */ struct { struct in_addr asla_mask; struct aslametric { uint32_t asla_tosmetric; struct in_addr asla_forward; struct in_addr asla_tag; } asla_metric[1]; /* may repeat */ } un_asla; /* Multicast group membership */ struct mcla { uint32_t mcla_vtype; struct in_addr mcla_vid; } un_mcla[1]; /* Opaque TE LSA */ struct { uint16_t type; uint16_t length; uint8_t data[1]; /* may repeat */ } un_te_lsa_tlv; /* Opaque Grace LSA */ struct { uint16_t type; uint16_t length; uint8_t data[1]; /* may repeat */ } un_grace_tlv; /* Opaque Router information LSA */ struct { uint16_t type; uint16_t length; uint8_t data[1]; /* may repeat */ } un_ri_tlv; /* Unknown LSA */ struct unknown { uint8_t data[1]; /* may repeat */ } un_unknown[1]; } lsa_un; }; #define OSPF_AUTH_SIZE 8 /* * the main header */ struct ospfhdr { uint8_t ospf_version; uint8_t ospf_type; uint16_t ospf_len; struct in_addr ospf_routerid; struct in_addr ospf_areaid; uint16_t ospf_chksum; uint16_t ospf_authtype; uint8_t ospf_authdata[OSPF_AUTH_SIZE]; union { /* Hello packet */ struct { struct in_addr hello_mask; uint16_t hello_helloint; uint8_t hello_options; uint8_t hello_priority; uint32_t hello_deadint; struct in_addr hello_dr; struct in_addr hello_bdr; struct in_addr hello_neighbor[1]; /* may repeat */ } un_hello; /* Database Description packet */ struct { uint16_t db_ifmtu; uint8_t db_options; uint8_t db_flags; uint32_t db_seq; struct lsa_hdr db_lshdr[1]; /* may repeat */ } un_db; /* Link State Request */ struct lsr { uint8_t ls_type[4]; union { struct in_addr ls_stateid; struct { /* opaque LSAs change the LSA-ID field */ uint8_t opaque_type; uint8_t opaque_id[3]; } opaque_field; } un_ls_stateid; struct in_addr ls_router; } un_lsr[1]; /* may repeat */ /* Link State Update */ struct { uint32_t lsu_count; struct lsa lsu_lsa[1]; /* may repeat */ } un_lsu; /* Link State Acknowledgement */ struct { struct lsa_hdr lsa_lshdr[1]; /* may repeat */ } un_lsa ; } ospf_un ; }; #define ospf_hello ospf_un.un_hello #define ospf_db ospf_un.un_db #define ospf_lsr ospf_un.un_lsr #define ospf_lsu ospf_un.un_lsu #define ospf_lsa ospf_un.un_lsa tcpdump-4.9.3/print-lmp.c0000644000026300017510000011416113544412724013426 0ustar mcrmcr/* * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code * distributions retain the above copyright notice and this paragraph * in its entirety, and (2) distributions including binary code include * the above copyright notice and this paragraph in its entirety in * the documentation or other materials provided with the distribution. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. * * Original code by Hannes Gredler (hannes@gredler.at) * Support for LMP service discovery extensions (defined by OIF UNI 1.0) * added by Manu Pathak (mapathak@cisco.com), May 2005 */ /* \summary: Link Management Protocol (LMP) printer */ /* specification: RFC 4204 */ /* OIF UNI 1.0: http://www.oiforum.com/public/documents/OIF-UNI-01.0.pdf */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #include "extract.h" #include "addrtoname.h" #include "gmpls.h" static const char tstr[] = " [|LMP]"; /* * LMP common header * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Vers | (Reserved) | Flags | Msg Type | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | LMP Length | (Reserved) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ struct lmp_common_header { uint8_t version_res[2]; uint8_t flags; uint8_t msg_type; uint8_t length[2]; uint8_t reserved[2]; }; #define LMP_VERSION 1 #define LMP_EXTRACT_VERSION(x) (((x)&0xf0)>>4) static const struct tok lmp_header_flag_values[] = { { 0x01, "Control Channel Down"}, { 0x02, "LMP restart"}, { 0, NULL} }; static const struct tok lmp_obj_te_link_flag_values[] = { { 0x01, "Fault Management Supported"}, { 0x02, "Link Verification Supported"}, { 0, NULL} }; static const struct tok lmp_obj_data_link_flag_values[] = { { 0x01, "Data Link Port"}, { 0x02, "Allocated for user traffic"}, { 0x04, "Failed link"}, { 0, NULL} }; static const struct tok lmp_obj_channel_status_values[] = { { 1, "Signal Okay"}, { 2, "Signal Degraded"}, { 3, "Signal Fail"}, { 0, NULL} }; static const struct tok lmp_obj_begin_verify_flag_values[] = { { 0x0001, "Verify all links"}, { 0x0002, "Data link type"}, { 0, NULL} }; static const struct tok lmp_obj_begin_verify_error_values[] = { { 0x01, "Link Verification Procedure Not supported"}, { 0x02, "Unwilling to verify"}, { 0x04, "Unsupported verification transport mechanism"}, { 0x08, "Link-Id configuration error"}, { 0x10, "Unknown object c-type"}, { 0, NULL} }; static const struct tok lmp_obj_link_summary_error_values[] = { { 0x01, "Unacceptable non-negotiable LINK-SUMMARY parameters"}, { 0x02, "Renegotiate LINK-SUMMARY parameters"}, { 0x04, "Invalid TE-LINK Object"}, { 0x08, "Invalid DATA-LINK Object"}, { 0x10, "Unknown TE-LINK Object c-type"}, { 0x20, "Unknown DATA-LINK Object c-type"}, { 0, NULL} }; /* Service Config Supported Protocols Flags */ static const struct tok lmp_obj_service_config_sp_flag_values[] = { { 0x01, "RSVP Supported"}, { 0x02, "LDP Supported"}, { 0, NULL} }; /* Service Config Client Port Service Attribute Transparency Flags */ static const struct tok lmp_obj_service_config_cpsa_tp_flag_values[] = { { 0x01, "Path/VC Overhead Transparency Supported"}, { 0x02, "Line/MS Overhead Transparency Supported"}, { 0x04, "Section/RS Overhead Transparency Supported"}, { 0, NULL} }; /* Service Config Client Port Service Attribute Contiguous Concatenation Types Flags */ static const struct tok lmp_obj_service_config_cpsa_cct_flag_values[] = { { 0x01, "Contiguous Concatenation Types Supported"}, { 0, NULL} }; /* Service Config Network Service Attributes Transparency Flags */ static const struct tok lmp_obj_service_config_nsa_transparency_flag_values[] = { { 0x01, "Standard SOH/RSOH Transparency Supported"}, { 0x02, "Standard LOH/MSOH Transparency Supported"}, { 0, NULL} }; /* Service Config Network Service Attributes TCM Monitoring Flags */ static const struct tok lmp_obj_service_config_nsa_tcm_flag_values[] = { { 0x01, "Transparent Tandem Connection Monitoring Supported"}, { 0, NULL} }; /* Network Service Attributes Network Diversity Flags */ static const struct tok lmp_obj_service_config_nsa_network_diversity_flag_values[] = { { 0x01, "Node Diversity Supported"}, { 0x02, "Link Diversity Supported"}, { 0x04, "SRLG Diversity Supported"}, { 0, NULL} }; #define LMP_MSGTYPE_CONFIG 1 #define LMP_MSGTYPE_CONFIG_ACK 2 #define LMP_MSGTYPE_CONFIG_NACK 3 #define LMP_MSGTYPE_HELLO 4 #define LMP_MSGTYPE_VERIFY_BEGIN 5 #define LMP_MSGTYPE_VERIFY_BEGIN_ACK 6 #define LMP_MSGTYPE_VERIFY_BEGIN_NACK 7 #define LMP_MSGTYPE_VERIFY_END 8 #define LMP_MSGTYPE_VERIFY_END_ACK 9 #define LMP_MSGTYPE_TEST 10 #define LMP_MSGTYPE_TEST_STATUS_SUCCESS 11 #define LMP_MSGTYPE_TEST_STATUS_FAILURE 12 #define LMP_MSGTYPE_TEST_STATUS_ACK 13 #define LMP_MSGTYPE_LINK_SUMMARY 14 #define LMP_MSGTYPE_LINK_SUMMARY_ACK 15 #define LMP_MSGTYPE_LINK_SUMMARY_NACK 16 #define LMP_MSGTYPE_CHANNEL_STATUS 17 #define LMP_MSGTYPE_CHANNEL_STATUS_ACK 18 #define LMP_MSGTYPE_CHANNEL_STATUS_REQ 19 #define LMP_MSGTYPE_CHANNEL_STATUS_RESP 20 /* LMP Service Discovery message types defined by UNI 1.0 */ #define LMP_MSGTYPE_SERVICE_CONFIG 50 #define LMP_MSGTYPE_SERVICE_CONFIG_ACK 51 #define LMP_MSGTYPE_SERVICE_CONFIG_NACK 52 static const struct tok lmp_msg_type_values[] = { { LMP_MSGTYPE_CONFIG, "Config"}, { LMP_MSGTYPE_CONFIG_ACK, "Config ACK"}, { LMP_MSGTYPE_CONFIG_NACK, "Config NACK"}, { LMP_MSGTYPE_HELLO, "Hello"}, { LMP_MSGTYPE_VERIFY_BEGIN, "Begin Verify"}, { LMP_MSGTYPE_VERIFY_BEGIN_ACK, "Begin Verify ACK"}, { LMP_MSGTYPE_VERIFY_BEGIN_NACK, "Begin Verify NACK"}, { LMP_MSGTYPE_VERIFY_END, "End Verify"}, { LMP_MSGTYPE_VERIFY_END_ACK, "End Verify ACK"}, { LMP_MSGTYPE_TEST, "Test"}, { LMP_MSGTYPE_TEST_STATUS_SUCCESS, "Test Status Success"}, { LMP_MSGTYPE_TEST_STATUS_FAILURE, "Test Status Failure"}, { LMP_MSGTYPE_TEST_STATUS_ACK, "Test Status ACK"}, { LMP_MSGTYPE_LINK_SUMMARY, "Link Summary"}, { LMP_MSGTYPE_LINK_SUMMARY_ACK, "Link Summary ACK"}, { LMP_MSGTYPE_LINK_SUMMARY_NACK, "Link Summary NACK"}, { LMP_MSGTYPE_CHANNEL_STATUS, "Channel Status"}, { LMP_MSGTYPE_CHANNEL_STATUS_ACK, "Channel Status ACK"}, { LMP_MSGTYPE_CHANNEL_STATUS_REQ, "Channel Status Request"}, { LMP_MSGTYPE_CHANNEL_STATUS_RESP, "Channel Status Response"}, { LMP_MSGTYPE_SERVICE_CONFIG, "Service Config"}, { LMP_MSGTYPE_SERVICE_CONFIG_ACK, "Service Config ACK"}, { LMP_MSGTYPE_SERVICE_CONFIG_NACK, "Service Config NACK"}, { 0, NULL} }; /* * LMP object header * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * |N| C-Type | Class | Length | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | * // (object contents) // * | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ struct lmp_object_header { uint8_t ctype; uint8_t class_num; uint8_t length[2]; }; #define LMP_OBJ_CC_ID 1 #define LMP_OBJ_NODE_ID 2 #define LMP_OBJ_LINK_ID 3 #define LMP_OBJ_INTERFACE_ID 4 #define LMP_OBJ_MESSAGE_ID 5 #define LMP_OBJ_CONFIG 6 #define LMP_OBJ_HELLO 7 #define LMP_OBJ_VERIFY_BEGIN 8 #define LMP_OBJ_VERIFY_BEGIN_ACK 9 #define LMP_OBJ_VERIFY_ID 10 #define LMP_OBJ_TE_LINK 11 #define LMP_OBJ_DATA_LINK 12 #define LMP_OBJ_CHANNEL_STATUS 13 #define LMP_OBJ_CHANNEL_STATUS_REQ 14 #define LMP_OBJ_ERROR_CODE 20 #define LMP_OBJ_SERVICE_CONFIG 51 /* defined in UNI 1.0 */ static const struct tok lmp_obj_values[] = { { LMP_OBJ_CC_ID, "Control Channel ID" }, { LMP_OBJ_NODE_ID, "Node ID" }, { LMP_OBJ_LINK_ID, "Link ID" }, { LMP_OBJ_INTERFACE_ID, "Interface ID" }, { LMP_OBJ_MESSAGE_ID, "Message ID" }, { LMP_OBJ_CONFIG, "Configuration" }, { LMP_OBJ_HELLO, "Hello" }, { LMP_OBJ_VERIFY_BEGIN, "Verify Begin" }, { LMP_OBJ_VERIFY_BEGIN_ACK, "Verify Begin ACK" }, { LMP_OBJ_VERIFY_ID, "Verify ID" }, { LMP_OBJ_TE_LINK, "TE Link" }, { LMP_OBJ_DATA_LINK, "Data Link" }, { LMP_OBJ_CHANNEL_STATUS, "Channel Status" }, { LMP_OBJ_CHANNEL_STATUS_REQ, "Channel Status Request" }, { LMP_OBJ_ERROR_CODE, "Error Code" }, { LMP_OBJ_SERVICE_CONFIG, "Service Config" }, { 0, NULL} }; #define INT_SWITCHING_TYPE_SUBOBJ 1 #define WAVELENGTH_SUBOBJ 2 static const struct tok lmp_data_link_subobj[] = { { INT_SWITCHING_TYPE_SUBOBJ, "Interface Switching Type" }, { WAVELENGTH_SUBOBJ , "Wavelength" }, { 0, NULL} }; #define LMP_CTYPE_IPV4 1 #define LMP_CTYPE_IPV6 2 #define LMP_CTYPE_LOC 1 #define LMP_CTYPE_RMT 2 #define LMP_CTYPE_UNMD 3 #define LMP_CTYPE_IPV4_LOC 1 #define LMP_CTYPE_IPV4_RMT 2 #define LMP_CTYPE_IPV6_LOC 3 #define LMP_CTYPE_IPV6_RMT 4 #define LMP_CTYPE_UNMD_LOC 5 #define LMP_CTYPE_UNMD_RMT 6 #define LMP_CTYPE_1 1 #define LMP_CTYPE_2 2 #define LMP_CTYPE_HELLO_CONFIG 1 #define LMP_CTYPE_HELLO 1 #define LMP_CTYPE_BEGIN_VERIFY_ERROR 1 #define LMP_CTYPE_LINK_SUMMARY_ERROR 2 /* C-Types for Service Config Object */ #define LMP_CTYPE_SERVICE_CONFIG_SP 1 #define LMP_CTYPE_SERVICE_CONFIG_CPSA 2 #define LMP_CTYPE_SERVICE_CONFIG_TRANSPARENCY_TCM 3 #define LMP_CTYPE_SERVICE_CONFIG_NETWORK_DIVERSITY 4 /* * Different link types allowed in the Client Port Service Attributes * subobject defined for LMP Service Discovery in the UNI 1.0 spec */ #define LMP_SD_SERVICE_CONFIG_CPSA_LINK_TYPE_SDH 5 /* UNI 1.0 Sec 9.4.2 */ #define LMP_SD_SERVICE_CONFIG_CPSA_LINK_TYPE_SONET 6 /* UNI 1.0 Sec 9.4.2 */ /* * the ctypes are not globally unique so for * translating it to strings we build a table based * on objects offsetted by the ctype */ static const struct tok lmp_ctype_values[] = { { 256*LMP_OBJ_CC_ID+LMP_CTYPE_LOC, "Local" }, { 256*LMP_OBJ_CC_ID+LMP_CTYPE_RMT, "Remote" }, { 256*LMP_OBJ_NODE_ID+LMP_CTYPE_LOC, "Local" }, { 256*LMP_OBJ_NODE_ID+LMP_CTYPE_RMT, "Remote" }, { 256*LMP_OBJ_LINK_ID+LMP_CTYPE_IPV4_LOC, "IPv4 Local" }, { 256*LMP_OBJ_LINK_ID+LMP_CTYPE_IPV4_RMT, "IPv4 Remote" }, { 256*LMP_OBJ_LINK_ID+LMP_CTYPE_IPV6_LOC, "IPv6 Local" }, { 256*LMP_OBJ_LINK_ID+LMP_CTYPE_IPV6_RMT, "IPv6 Remote" }, { 256*LMP_OBJ_LINK_ID+LMP_CTYPE_UNMD_LOC, "Unnumbered Local" }, { 256*LMP_OBJ_LINK_ID+LMP_CTYPE_UNMD_RMT, "Unnumbered Remote" }, { 256*LMP_OBJ_INTERFACE_ID+LMP_CTYPE_IPV4_LOC, "IPv4 Local" }, { 256*LMP_OBJ_INTERFACE_ID+LMP_CTYPE_IPV4_RMT, "IPv4 Remote" }, { 256*LMP_OBJ_INTERFACE_ID+LMP_CTYPE_IPV6_LOC, "IPv6 Local" }, { 256*LMP_OBJ_INTERFACE_ID+LMP_CTYPE_IPV6_RMT, "IPv6 Remote" }, { 256*LMP_OBJ_INTERFACE_ID+LMP_CTYPE_UNMD_LOC, "Unnumbered Local" }, { 256*LMP_OBJ_INTERFACE_ID+LMP_CTYPE_UNMD_RMT, "Unnumbered Remote" }, { 256*LMP_OBJ_MESSAGE_ID+LMP_CTYPE_1, "1" }, { 256*LMP_OBJ_MESSAGE_ID+LMP_CTYPE_2, "2" }, { 256*LMP_OBJ_CONFIG+LMP_CTYPE_1, "1" }, { 256*LMP_OBJ_HELLO+LMP_CTYPE_1, "1" }, { 256*LMP_OBJ_VERIFY_BEGIN+LMP_CTYPE_1, "1" }, { 256*LMP_OBJ_VERIFY_BEGIN_ACK+LMP_CTYPE_1, "1" }, { 256*LMP_OBJ_VERIFY_ID+LMP_CTYPE_1, "1" }, { 256*LMP_OBJ_TE_LINK+LMP_CTYPE_IPV4, "IPv4" }, { 256*LMP_OBJ_TE_LINK+LMP_CTYPE_IPV6, "IPv6" }, { 256*LMP_OBJ_TE_LINK+LMP_CTYPE_UNMD, "Unnumbered" }, { 256*LMP_OBJ_DATA_LINK+LMP_CTYPE_IPV4, "IPv4" }, { 256*LMP_OBJ_DATA_LINK+LMP_CTYPE_IPV6, "IPv6" }, { 256*LMP_OBJ_DATA_LINK+LMP_CTYPE_UNMD, "Unnumbered" }, { 256*LMP_OBJ_CHANNEL_STATUS+LMP_CTYPE_IPV4, "IPv4" }, { 256*LMP_OBJ_CHANNEL_STATUS+LMP_CTYPE_IPV6, "IPv6" }, { 256*LMP_OBJ_CHANNEL_STATUS+LMP_CTYPE_UNMD, "Unnumbered" }, { 256*LMP_OBJ_CHANNEL_STATUS_REQ+LMP_CTYPE_IPV4, "IPv4" }, { 256*LMP_OBJ_CHANNEL_STATUS_REQ+LMP_CTYPE_IPV6, "IPv6" }, { 256*LMP_OBJ_CHANNEL_STATUS_REQ+LMP_CTYPE_UNMD, "Unnumbered" }, { 256*LMP_OBJ_ERROR_CODE+LMP_CTYPE_1, "1" }, { 256*LMP_OBJ_ERROR_CODE+LMP_CTYPE_2, "2" }, { 256*LMP_OBJ_SERVICE_CONFIG+LMP_CTYPE_SERVICE_CONFIG_SP, "1" }, { 256*LMP_OBJ_SERVICE_CONFIG+LMP_CTYPE_SERVICE_CONFIG_CPSA, "2" }, { 256*LMP_OBJ_SERVICE_CONFIG+LMP_CTYPE_SERVICE_CONFIG_TRANSPARENCY_TCM, "3" }, { 256*LMP_OBJ_SERVICE_CONFIG+LMP_CTYPE_SERVICE_CONFIG_NETWORK_DIVERSITY, "4" }, { 0, NULL} }; static int lmp_print_data_link_subobjs(netdissect_options *ndo, const u_char *obj_tptr, int total_subobj_len, int offset) { int hexdump = FALSE; int subobj_type, subobj_len; union { /* int to float conversion buffer */ float f; uint32_t i; } bw; while (total_subobj_len > 0 && hexdump == FALSE ) { ND_TCHECK_16BITS(obj_tptr + offset); subobj_type = EXTRACT_8BITS(obj_tptr + offset); subobj_len = EXTRACT_8BITS(obj_tptr + offset + 1); ND_PRINT((ndo, "\n\t Subobject, Type: %s (%u), Length: %u", tok2str(lmp_data_link_subobj, "Unknown", subobj_type), subobj_type, subobj_len)); if (subobj_len < 4) { ND_PRINT((ndo, " (too short)")); break; } if ((subobj_len % 4) != 0) { ND_PRINT((ndo, " (not a multiple of 4)")); break; } if (total_subobj_len < subobj_len) { ND_PRINT((ndo, " (goes past the end of the object)")); break; } switch(subobj_type) { case INT_SWITCHING_TYPE_SUBOBJ: ND_TCHECK_8BITS(obj_tptr + offset + 2); ND_PRINT((ndo, "\n\t Switching Type: %s (%u)", tok2str(gmpls_switch_cap_values, "Unknown", EXTRACT_8BITS(obj_tptr + offset + 2)), EXTRACT_8BITS(obj_tptr + offset + 2))); ND_TCHECK_8BITS(obj_tptr + offset + 3); ND_PRINT((ndo, "\n\t Encoding Type: %s (%u)", tok2str(gmpls_encoding_values, "Unknown", EXTRACT_8BITS(obj_tptr + offset + 3)), EXTRACT_8BITS(obj_tptr + offset + 3))); ND_TCHECK_32BITS(obj_tptr + offset + 4); bw.i = EXTRACT_32BITS(obj_tptr+offset+4); ND_PRINT((ndo, "\n\t Min Reservable Bandwidth: %.3f Mbps", bw.f*8/1000000)); ND_TCHECK_32BITS(obj_tptr + offset + 8); bw.i = EXTRACT_32BITS(obj_tptr+offset+8); ND_PRINT((ndo, "\n\t Max Reservable Bandwidth: %.3f Mbps", bw.f*8/1000000)); break; case WAVELENGTH_SUBOBJ: ND_TCHECK_32BITS(obj_tptr + offset + 4); ND_PRINT((ndo, "\n\t Wavelength: %u", EXTRACT_32BITS(obj_tptr+offset+4))); break; default: /* Any Unknown Subobject ==> Exit loop */ hexdump=TRUE; break; } total_subobj_len-=subobj_len; offset+=subobj_len; } return (hexdump); trunc: return -1; } void lmp_print(netdissect_options *ndo, register const u_char *pptr, register u_int len) { const struct lmp_common_header *lmp_com_header; const struct lmp_object_header *lmp_obj_header; const u_char *tptr,*obj_tptr; u_int tlen,lmp_obj_len,lmp_obj_ctype,obj_tlen; int hexdump, ret; u_int offset; u_int link_type; union { /* int to float conversion buffer */ float f; uint32_t i; } bw; tptr=pptr; lmp_com_header = (const struct lmp_common_header *)pptr; ND_TCHECK(*lmp_com_header); /* * Sanity checking of the header. */ if (LMP_EXTRACT_VERSION(lmp_com_header->version_res[0]) != LMP_VERSION) { ND_PRINT((ndo, "LMP version %u packet not supported", LMP_EXTRACT_VERSION(lmp_com_header->version_res[0]))); return; } /* in non-verbose mode just lets print the basic Message Type*/ if (ndo->ndo_vflag < 1) { ND_PRINT((ndo, "LMPv%u %s Message, length: %u", LMP_EXTRACT_VERSION(lmp_com_header->version_res[0]), tok2str(lmp_msg_type_values, "unknown (%u)",lmp_com_header->msg_type), len)); return; } /* ok they seem to want to know everything - lets fully decode it */ tlen=EXTRACT_16BITS(lmp_com_header->length); ND_PRINT((ndo, "\n\tLMPv%u, msg-type: %s, Flags: [%s], length: %u", LMP_EXTRACT_VERSION(lmp_com_header->version_res[0]), tok2str(lmp_msg_type_values, "unknown, type: %u",lmp_com_header->msg_type), bittok2str(lmp_header_flag_values,"none",lmp_com_header->flags), tlen)); if (tlen < sizeof(const struct lmp_common_header)) { ND_PRINT((ndo, " (too short)")); return; } if (tlen > len) { ND_PRINT((ndo, " (too long)")); tlen = len; } tptr+=sizeof(const struct lmp_common_header); tlen-=sizeof(const struct lmp_common_header); while(tlen>0) { /* did we capture enough for fully decoding the object header ? */ ND_TCHECK2(*tptr, sizeof(struct lmp_object_header)); lmp_obj_header = (const struct lmp_object_header *)tptr; lmp_obj_len=EXTRACT_16BITS(lmp_obj_header->length); lmp_obj_ctype=(lmp_obj_header->ctype)&0x7f; ND_PRINT((ndo, "\n\t %s Object (%u), Class-Type: %s (%u) Flags: [%snegotiable], length: %u", tok2str(lmp_obj_values, "Unknown", lmp_obj_header->class_num), lmp_obj_header->class_num, tok2str(lmp_ctype_values, "Unknown", ((lmp_obj_header->class_num)<<8)+lmp_obj_ctype), lmp_obj_ctype, (lmp_obj_header->ctype)&0x80 ? "" : "non-", lmp_obj_len)); if (lmp_obj_len < 4) { ND_PRINT((ndo, " (too short)")); return; } if ((lmp_obj_len % 4) != 0) { ND_PRINT((ndo, " (not a multiple of 4)")); return; } obj_tptr=tptr+sizeof(struct lmp_object_header); obj_tlen=lmp_obj_len-sizeof(struct lmp_object_header); /* did we capture enough for fully decoding the object ? */ ND_TCHECK2(*tptr, lmp_obj_len); hexdump=FALSE; switch(lmp_obj_header->class_num) { case LMP_OBJ_CC_ID: switch(lmp_obj_ctype) { case LMP_CTYPE_LOC: case LMP_CTYPE_RMT: if (obj_tlen != 4) { ND_PRINT((ndo, " (not correct for object)")); break; } ND_PRINT((ndo, "\n\t Control Channel ID: %u (0x%08x)", EXTRACT_32BITS(obj_tptr), EXTRACT_32BITS(obj_tptr))); break; default: hexdump=TRUE; } break; case LMP_OBJ_LINK_ID: case LMP_OBJ_INTERFACE_ID: switch(lmp_obj_ctype) { case LMP_CTYPE_IPV4_LOC: case LMP_CTYPE_IPV4_RMT: if (obj_tlen != 4) { ND_PRINT((ndo, " (not correct for object)")); break; } ND_PRINT((ndo, "\n\t IPv4 Link ID: %s (0x%08x)", ipaddr_string(ndo, obj_tptr), EXTRACT_32BITS(obj_tptr))); break; case LMP_CTYPE_IPV6_LOC: case LMP_CTYPE_IPV6_RMT: if (obj_tlen != 16) { ND_PRINT((ndo, " (not correct for object)")); break; } ND_PRINT((ndo, "\n\t IPv6 Link ID: %s (0x%08x)", ip6addr_string(ndo, obj_tptr), EXTRACT_32BITS(obj_tptr))); break; case LMP_CTYPE_UNMD_LOC: case LMP_CTYPE_UNMD_RMT: if (obj_tlen != 4) { ND_PRINT((ndo, " (not correct for object)")); break; } ND_PRINT((ndo, "\n\t Link ID: %u (0x%08x)", EXTRACT_32BITS(obj_tptr), EXTRACT_32BITS(obj_tptr))); break; default: hexdump=TRUE; } break; case LMP_OBJ_MESSAGE_ID: switch(lmp_obj_ctype) { case LMP_CTYPE_1: if (obj_tlen != 4) { ND_PRINT((ndo, " (not correct for object)")); break; } ND_PRINT((ndo, "\n\t Message ID: %u (0x%08x)", EXTRACT_32BITS(obj_tptr), EXTRACT_32BITS(obj_tptr))); break; case LMP_CTYPE_2: if (obj_tlen != 4) { ND_PRINT((ndo, " (not correct for object)")); break; } ND_PRINT((ndo, "\n\t Message ID Ack: %u (0x%08x)", EXTRACT_32BITS(obj_tptr), EXTRACT_32BITS(obj_tptr))); break; default: hexdump=TRUE; } break; case LMP_OBJ_NODE_ID: switch(lmp_obj_ctype) { case LMP_CTYPE_LOC: case LMP_CTYPE_RMT: if (obj_tlen != 4) { ND_PRINT((ndo, " (not correct for object)")); break; } ND_PRINT((ndo, "\n\t Node ID: %s (0x%08x)", ipaddr_string(ndo, obj_tptr), EXTRACT_32BITS(obj_tptr))); break; default: hexdump=TRUE; } break; case LMP_OBJ_CONFIG: switch(lmp_obj_ctype) { case LMP_CTYPE_HELLO_CONFIG: if (obj_tlen != 4) { ND_PRINT((ndo, " (not correct for object)")); break; } ND_PRINT((ndo, "\n\t Hello Interval: %u\n\t Hello Dead Interval: %u", EXTRACT_16BITS(obj_tptr), EXTRACT_16BITS(obj_tptr+2))); break; default: hexdump=TRUE; } break; case LMP_OBJ_HELLO: switch(lmp_obj_ctype) { case LMP_CTYPE_HELLO: if (obj_tlen != 8) { ND_PRINT((ndo, " (not correct for object)")); break; } ND_PRINT((ndo, "\n\t Tx Seq: %u, Rx Seq: %u", EXTRACT_32BITS(obj_tptr), EXTRACT_32BITS(obj_tptr+4))); break; default: hexdump=TRUE; } break; case LMP_OBJ_TE_LINK: switch(lmp_obj_ctype) { case LMP_CTYPE_IPV4: if (obj_tlen != 12) { ND_PRINT((ndo, " (not correct for object)")); break; } ND_PRINT((ndo, "\n\t Flags: [%s]", bittok2str(lmp_obj_te_link_flag_values, "none", EXTRACT_8BITS(obj_tptr)))); ND_PRINT((ndo, "\n\t Local Link-ID: %s (0x%08x)" "\n\t Remote Link-ID: %s (0x%08x)", ipaddr_string(ndo, obj_tptr+4), EXTRACT_32BITS(obj_tptr+4), ipaddr_string(ndo, obj_tptr+8), EXTRACT_32BITS(obj_tptr+8))); break; case LMP_CTYPE_IPV6: if (obj_tlen != 36) { ND_PRINT((ndo, " (not correct for object)")); break; } ND_PRINT((ndo, "\n\t Flags: [%s]", bittok2str(lmp_obj_te_link_flag_values, "none", EXTRACT_8BITS(obj_tptr)))); ND_PRINT((ndo, "\n\t Local Link-ID: %s (0x%08x)" "\n\t Remote Link-ID: %s (0x%08x)", ip6addr_string(ndo, obj_tptr+4), EXTRACT_32BITS(obj_tptr+4), ip6addr_string(ndo, obj_tptr+20), EXTRACT_32BITS(obj_tptr+20))); break; case LMP_CTYPE_UNMD: if (obj_tlen != 12) { ND_PRINT((ndo, " (not correct for object)")); break; } ND_PRINT((ndo, "\n\t Flags: [%s]", bittok2str(lmp_obj_te_link_flag_values, "none", EXTRACT_8BITS(obj_tptr)))); ND_PRINT((ndo, "\n\t Local Link-ID: %u (0x%08x)" "\n\t Remote Link-ID: %u (0x%08x)", EXTRACT_32BITS(obj_tptr+4), EXTRACT_32BITS(obj_tptr+4), EXTRACT_32BITS(obj_tptr+8), EXTRACT_32BITS(obj_tptr+8))); break; default: hexdump=TRUE; } break; case LMP_OBJ_DATA_LINK: switch(lmp_obj_ctype) { case LMP_CTYPE_IPV4: if (obj_tlen < 12) { ND_PRINT((ndo, " (not correct for object)")); break; } ND_PRINT((ndo, "\n\t Flags: [%s]", bittok2str(lmp_obj_data_link_flag_values, "none", EXTRACT_8BITS(obj_tptr)))); ND_PRINT((ndo, "\n\t Local Interface ID: %s (0x%08x)" "\n\t Remote Interface ID: %s (0x%08x)", ipaddr_string(ndo, obj_tptr+4), EXTRACT_32BITS(obj_tptr+4), ipaddr_string(ndo, obj_tptr+8), EXTRACT_32BITS(obj_tptr+8))); ret = lmp_print_data_link_subobjs(ndo, obj_tptr, obj_tlen - 12, 12); if (ret == -1) goto trunc; if (ret == TRUE) hexdump=TRUE; break; case LMP_CTYPE_IPV6: if (obj_tlen < 36) { ND_PRINT((ndo, " (not correct for object)")); break; } ND_PRINT((ndo, "\n\t Flags: [%s]", bittok2str(lmp_obj_data_link_flag_values, "none", EXTRACT_8BITS(obj_tptr)))); ND_PRINT((ndo, "\n\t Local Interface ID: %s (0x%08x)" "\n\t Remote Interface ID: %s (0x%08x)", ip6addr_string(ndo, obj_tptr+4), EXTRACT_32BITS(obj_tptr+4), ip6addr_string(ndo, obj_tptr+20), EXTRACT_32BITS(obj_tptr+20))); ret = lmp_print_data_link_subobjs(ndo, obj_tptr, obj_tlen - 36, 36); if (ret == -1) goto trunc; if (ret == TRUE) hexdump=TRUE; break; case LMP_CTYPE_UNMD: if (obj_tlen < 12) { ND_PRINT((ndo, " (not correct for object)")); break; } ND_PRINT((ndo, "\n\t Flags: [%s]", bittok2str(lmp_obj_data_link_flag_values, "none", EXTRACT_8BITS(obj_tptr)))); ND_PRINT((ndo, "\n\t Local Interface ID: %u (0x%08x)" "\n\t Remote Interface ID: %u (0x%08x)", EXTRACT_32BITS(obj_tptr+4), EXTRACT_32BITS(obj_tptr+4), EXTRACT_32BITS(obj_tptr+8), EXTRACT_32BITS(obj_tptr+8))); ret = lmp_print_data_link_subobjs(ndo, obj_tptr, obj_tlen - 12, 12); if (ret == -1) goto trunc; if (ret == TRUE) hexdump=TRUE; break; default: hexdump=TRUE; } break; case LMP_OBJ_VERIFY_BEGIN: switch(lmp_obj_ctype) { case LMP_CTYPE_1: if (obj_tlen != 20) { ND_PRINT((ndo, " (not correct for object)")); break; } ND_PRINT((ndo, "\n\t Flags: %s", bittok2str(lmp_obj_begin_verify_flag_values, "none", EXTRACT_16BITS(obj_tptr)))); ND_PRINT((ndo, "\n\t Verify Interval: %u", EXTRACT_16BITS(obj_tptr+2))); ND_PRINT((ndo, "\n\t Data links: %u", EXTRACT_32BITS(obj_tptr+4))); ND_PRINT((ndo, "\n\t Encoding type: %s", tok2str(gmpls_encoding_values, "Unknown", *(obj_tptr+8)))); ND_PRINT((ndo, "\n\t Verify Transport Mechanism: %u (0x%x)%s", EXTRACT_16BITS(obj_tptr+10), EXTRACT_16BITS(obj_tptr+10), EXTRACT_16BITS(obj_tptr+10)&8000 ? " (Payload test messages capable)" : "")); bw.i = EXTRACT_32BITS(obj_tptr+12); ND_PRINT((ndo, "\n\t Transmission Rate: %.3f Mbps",bw.f*8/1000000)); ND_PRINT((ndo, "\n\t Wavelength: %u", EXTRACT_32BITS(obj_tptr+16))); break; default: hexdump=TRUE; } break; case LMP_OBJ_VERIFY_BEGIN_ACK: switch(lmp_obj_ctype) { case LMP_CTYPE_1: if (obj_tlen != 4) { ND_PRINT((ndo, " (not correct for object)")); break; } ND_PRINT((ndo, "\n\t Verify Dead Interval: %u" "\n\t Verify Transport Response: %u", EXTRACT_16BITS(obj_tptr), EXTRACT_16BITS(obj_tptr+2))); break; default: hexdump=TRUE; } break; case LMP_OBJ_VERIFY_ID: switch(lmp_obj_ctype) { case LMP_CTYPE_1: if (obj_tlen != 4) { ND_PRINT((ndo, " (not correct for object)")); break; } ND_PRINT((ndo, "\n\t Verify ID: %u", EXTRACT_32BITS(obj_tptr))); break; default: hexdump=TRUE; } break; case LMP_OBJ_CHANNEL_STATUS: switch(lmp_obj_ctype) { case LMP_CTYPE_IPV4: offset = 0; /* Decode pairs: */ while (offset+8 <= obj_tlen) { ND_PRINT((ndo, "\n\t Interface ID: %s (0x%08x)", ipaddr_string(ndo, obj_tptr+offset), EXTRACT_32BITS(obj_tptr+offset))); ND_PRINT((ndo, "\n\t\t Active: %s (%u)", (EXTRACT_32BITS(obj_tptr+offset+4)>>31) ? "Allocated" : "Non-allocated", (EXTRACT_32BITS(obj_tptr+offset+4)>>31))); ND_PRINT((ndo, "\n\t\t Direction: %s (%u)", (EXTRACT_32BITS(obj_tptr+offset+4)>>30)&0x1 ? "Transmit" : "Receive", (EXTRACT_32BITS(obj_tptr+offset+4)>>30)&0x1)); ND_PRINT((ndo, "\n\t\t Channel Status: %s (%u)", tok2str(lmp_obj_channel_status_values, "Unknown", EXTRACT_32BITS(obj_tptr+offset+4)&0x3FFFFFF), EXTRACT_32BITS(obj_tptr+offset+4)&0x3FFFFFF)); offset+=8; } break; case LMP_CTYPE_IPV6: offset = 0; /* Decode pairs: */ while (offset+20 <= obj_tlen) { ND_PRINT((ndo, "\n\t Interface ID: %s (0x%08x)", ip6addr_string(ndo, obj_tptr+offset), EXTRACT_32BITS(obj_tptr+offset))); ND_PRINT((ndo, "\n\t\t Active: %s (%u)", (EXTRACT_32BITS(obj_tptr+offset+16)>>31) ? "Allocated" : "Non-allocated", (EXTRACT_32BITS(obj_tptr+offset+16)>>31))); ND_PRINT((ndo, "\n\t\t Direction: %s (%u)", (EXTRACT_32BITS(obj_tptr+offset+16)>>30)&0x1 ? "Transmit" : "Receive", (EXTRACT_32BITS(obj_tptr+offset+16)>>30)&0x1)); ND_PRINT((ndo, "\n\t\t Channel Status: %s (%u)", tok2str(lmp_obj_channel_status_values, "Unknown", EXTRACT_32BITS(obj_tptr+offset+16)&0x3FFFFFF), EXTRACT_32BITS(obj_tptr+offset+16)&0x3FFFFFF)); offset+=20; } break; case LMP_CTYPE_UNMD: offset = 0; /* Decode pairs: */ while (offset+8 <= obj_tlen) { ND_PRINT((ndo, "\n\t Interface ID: %u (0x%08x)", EXTRACT_32BITS(obj_tptr+offset), EXTRACT_32BITS(obj_tptr+offset))); ND_PRINT((ndo, "\n\t\t Active: %s (%u)", (EXTRACT_32BITS(obj_tptr+offset+4)>>31) ? "Allocated" : "Non-allocated", (EXTRACT_32BITS(obj_tptr+offset+4)>>31))); ND_PRINT((ndo, "\n\t\t Direction: %s (%u)", (EXTRACT_32BITS(obj_tptr+offset+4)>>30)&0x1 ? "Transmit" : "Receive", (EXTRACT_32BITS(obj_tptr+offset+4)>>30)&0x1)); ND_PRINT((ndo, "\n\t\t Channel Status: %s (%u)", tok2str(lmp_obj_channel_status_values, "Unknown", EXTRACT_32BITS(obj_tptr+offset+4)&0x3FFFFFF), EXTRACT_32BITS(obj_tptr+offset+4)&0x3FFFFFF)); offset+=8; } break; default: hexdump=TRUE; } break; case LMP_OBJ_CHANNEL_STATUS_REQ: switch(lmp_obj_ctype) { case LMP_CTYPE_IPV4: offset = 0; while (offset+4 <= obj_tlen) { ND_PRINT((ndo, "\n\t Interface ID: %s (0x%08x)", ipaddr_string(ndo, obj_tptr+offset), EXTRACT_32BITS(obj_tptr+offset))); offset+=4; } break; case LMP_CTYPE_IPV6: offset = 0; while (offset+16 <= obj_tlen) { ND_PRINT((ndo, "\n\t Interface ID: %s (0x%08x)", ip6addr_string(ndo, obj_tptr+offset), EXTRACT_32BITS(obj_tptr+offset))); offset+=16; } break; case LMP_CTYPE_UNMD: offset = 0; while (offset+4 <= obj_tlen) { ND_PRINT((ndo, "\n\t Interface ID: %u (0x%08x)", EXTRACT_32BITS(obj_tptr+offset), EXTRACT_32BITS(obj_tptr+offset))); offset+=4; } break; default: hexdump=TRUE; } break; case LMP_OBJ_ERROR_CODE: switch(lmp_obj_ctype) { case LMP_CTYPE_BEGIN_VERIFY_ERROR: if (obj_tlen != 4) { ND_PRINT((ndo, " (not correct for object)")); break; } ND_PRINT((ndo, "\n\t Error Code: %s", bittok2str(lmp_obj_begin_verify_error_values, "none", EXTRACT_32BITS(obj_tptr)))); break; case LMP_CTYPE_LINK_SUMMARY_ERROR: if (obj_tlen != 4) { ND_PRINT((ndo, " (not correct for object)")); break; } ND_PRINT((ndo, "\n\t Error Code: %s", bittok2str(lmp_obj_link_summary_error_values, "none", EXTRACT_32BITS(obj_tptr)))); break; default: hexdump=TRUE; } break; case LMP_OBJ_SERVICE_CONFIG: switch (lmp_obj_ctype) { case LMP_CTYPE_SERVICE_CONFIG_SP: if (obj_tlen != 4) { ND_PRINT((ndo, " (not correct for object)")); break; } ND_PRINT((ndo, "\n\t Flags: %s", bittok2str(lmp_obj_service_config_sp_flag_values, "none", EXTRACT_8BITS(obj_tptr)))); ND_PRINT((ndo, "\n\t UNI Version: %u", EXTRACT_8BITS(obj_tptr + 1))); break; case LMP_CTYPE_SERVICE_CONFIG_CPSA: if (obj_tlen != 16) { ND_PRINT((ndo, " (not correct for object)")); break; } link_type = EXTRACT_8BITS(obj_tptr); ND_PRINT((ndo, "\n\t Link Type: %s (%u)", tok2str(lmp_sd_service_config_cpsa_link_type_values, "Unknown", link_type), link_type)); switch (link_type) { case LMP_SD_SERVICE_CONFIG_CPSA_LINK_TYPE_SDH: ND_PRINT((ndo, "\n\t Signal Type: %s (%u)", tok2str(lmp_sd_service_config_cpsa_signal_type_sdh_values, "Unknown", EXTRACT_8BITS(obj_tptr + 1)), EXTRACT_8BITS(obj_tptr + 1))); break; case LMP_SD_SERVICE_CONFIG_CPSA_LINK_TYPE_SONET: ND_PRINT((ndo, "\n\t Signal Type: %s (%u)", tok2str(lmp_sd_service_config_cpsa_signal_type_sonet_values, "Unknown", EXTRACT_8BITS(obj_tptr + 1)), EXTRACT_8BITS(obj_tptr + 1))); break; } ND_PRINT((ndo, "\n\t Transparency: %s", bittok2str(lmp_obj_service_config_cpsa_tp_flag_values, "none", EXTRACT_8BITS(obj_tptr + 2)))); ND_PRINT((ndo, "\n\t Contiguous Concatenation Types: %s", bittok2str(lmp_obj_service_config_cpsa_cct_flag_values, "none", EXTRACT_8BITS(obj_tptr + 3)))); ND_PRINT((ndo, "\n\t Minimum NCC: %u", EXTRACT_16BITS(obj_tptr+4))); ND_PRINT((ndo, "\n\t Maximum NCC: %u", EXTRACT_16BITS(obj_tptr+6))); ND_PRINT((ndo, "\n\t Minimum NVC:%u", EXTRACT_16BITS(obj_tptr+8))); ND_PRINT((ndo, "\n\t Maximum NVC:%u", EXTRACT_16BITS(obj_tptr+10))); ND_PRINT((ndo, "\n\t Local Interface ID: %s (0x%08x)", ipaddr_string(ndo, obj_tptr+12), EXTRACT_32BITS(obj_tptr+12))); break; case LMP_CTYPE_SERVICE_CONFIG_TRANSPARENCY_TCM: if (obj_tlen != 8) { ND_PRINT((ndo, " (not correct for object)")); break; } ND_PRINT((ndo, "\n\t Transparency Flags: %s", bittok2str( lmp_obj_service_config_nsa_transparency_flag_values, "none", EXTRACT_32BITS(obj_tptr)))); ND_PRINT((ndo, "\n\t TCM Monitoring Flags: %s", bittok2str( lmp_obj_service_config_nsa_tcm_flag_values, "none", EXTRACT_8BITS(obj_tptr + 7)))); break; case LMP_CTYPE_SERVICE_CONFIG_NETWORK_DIVERSITY: if (obj_tlen != 4) { ND_PRINT((ndo, " (not correct for object)")); break; } ND_PRINT((ndo, "\n\t Diversity: Flags: %s", bittok2str( lmp_obj_service_config_nsa_network_diversity_flag_values, "none", EXTRACT_8BITS(obj_tptr + 3)))); break; default: hexdump = TRUE; } break; default: if (ndo->ndo_vflag <= 1) print_unknown_data(ndo,obj_tptr,"\n\t ",obj_tlen); break; } /* do we want to see an additionally hexdump ? */ if (ndo->ndo_vflag > 1 || hexdump==TRUE) print_unknown_data(ndo,tptr+sizeof(struct lmp_object_header),"\n\t ", lmp_obj_len-sizeof(struct lmp_object_header)); tptr+=lmp_obj_len; tlen-=lmp_obj_len; } return; trunc: ND_PRINT((ndo, "%s", tstr)); } /* * Local Variables: * c-style: whitesmith * c-basic-offset: 8 * End: */ tcpdump-4.9.3/netdissect.h0000644000026300017510000007407613544412724013670 0ustar mcrmcr/* * Copyright (c) 1988-1997 * The Regents of the University of California. All rights reserved. * * Copyright (c) 1998-2012 Michael Richardson * The TCPDUMP project * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of * the University nor the names of its contributors may be used to endorse * or promote products derived from this software without specific prior * written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef netdissect_h #define netdissect_h #ifdef HAVE_OS_PROTO_H #include "os-proto.h" #endif #include #ifndef HAVE___ATTRIBUTE__ #define __attribute__(x) #endif /* * Data types corresponding to multi-byte integral values within data * structures. These are defined as arrays of octets, so that they're * not aligned on their "natural" boundaries, and so that you *must* * use the EXTRACT_ macros to extract them (which you should be doing * *anyway*, so as not to assume a particular byte order or alignment * in your code). */ typedef unsigned char nd_uint16_t[2]; typedef unsigned char nd_uint24_t[3]; typedef unsigned char nd_uint32_t[4]; typedef unsigned char nd_uint40_t[5]; typedef unsigned char nd_uint48_t[6]; typedef unsigned char nd_uint56_t[7]; typedef unsigned char nd_uint64_t[8]; /* * Use this for IPv4 addresses. It's defined as an array of octets, so * that it's not aligned on its "natural" boundary, and it's defined as * a structure in the hopes that this makes it harder to naively use * EXTRACT_32BITS() to extract the value - in many cases you just want * to use UNALIGNED_MEMCPY() to copy its value, so that it remains in * network byte order. */ typedef struct { unsigned char bytes[4]; } nd_ipv4; /* * Data types corresponding to single-byte integral values, for * completeness. */ typedef unsigned char nd_uint8_t; typedef signed char nd_int8_t; /* snprintf et al */ #include #include #include "ip.h" /* struct ip for nextproto4_cksum() */ #include "ip6.h" /* struct ip6 for nextproto6_cksum() */ extern int32_t thiszone; /* seconds offset from gmt to local time */ /* invalid string to print '(invalid)' for malformed or corrupted packets */ extern const char istr[]; #if !defined(HAVE_SNPRINTF) int snprintf (char *str, size_t sz, FORMAT_STRING(const char *format), ...) PRINTFLIKE(3, 4); #endif /* !defined(HAVE_SNPRINTF) */ #if !defined(HAVE_VSNPRINTF) int vsnprintf (char *str, size_t sz, FORMAT_STRING(const char *format), va_list ap) PRINTFLIKE(3, 0); #endif /* !defined(HAVE_VSNPRINTF) */ #ifndef HAVE_STRLCAT extern size_t strlcat (char *, const char *, size_t); #endif #ifndef HAVE_STRLCPY extern size_t strlcpy (char *, const char *, size_t); #endif #ifndef HAVE_STRDUP extern char *strdup (const char *str); #endif #ifndef HAVE_STRSEP extern char *strsep(char **, const char *); #endif struct tok { u_int v; /* value */ const char *s; /* string */ }; extern const char *tok2strbuf(const struct tok *, const char *, u_int, char *buf, size_t bufsize); /* tok2str is deprecated */ extern const char *tok2str(const struct tok *, const char *, u_int); extern char *bittok2str(const struct tok *, const char *, u_int); extern char *bittok2str_nosep(const struct tok *, const char *, u_int); /* Initialize netdissect. */ extern int nd_init(char *, size_t); /* Clean up netdissect. */ extern void nd_cleanup(void); /* Do we have libsmi support? */ extern int nd_have_smi_support(void); /* Load an SMI module. */ extern int nd_load_smi_module(const char *, char *, size_t); /* Flag indicating whether an SMI module has been loaded. */ extern int nd_smi_module_loaded; /* Version number of the SMI library, or NULL if we don't have libsmi support. */ extern const char *nd_smi_version_string(void); typedef struct netdissect_options netdissect_options; #define IF_PRINTER_ARGS (netdissect_options *, const struct pcap_pkthdr *, const u_char *) typedef u_int (*if_printer) IF_PRINTER_ARGS; struct netdissect_options { int ndo_bflag; /* print 4 byte ASes in ASDOT notation */ int ndo_eflag; /* print ethernet header */ int ndo_fflag; /* don't translate "foreign" IP address */ int ndo_Kflag; /* don't check TCP checksums */ int ndo_nflag; /* leave addresses as numbers */ int ndo_Nflag; /* remove domains from printed host names */ int ndo_qflag; /* quick (shorter) output */ int ndo_Sflag; /* print raw TCP sequence numbers */ int ndo_tflag; /* print packet arrival time */ int ndo_uflag; /* Print undecoded NFS handles */ int ndo_vflag; /* verbosity level */ int ndo_xflag; /* print packet in hex */ int ndo_Xflag; /* print packet in hex/ascii */ int ndo_Aflag; /* print packet only in ascii observing TAB, * LF, CR and SPACE as graphical chars */ int ndo_Hflag; /* dissect 802.11s draft mesh standard */ int ndo_packet_number; /* print a packet number in the beginning of line */ int ndo_suppress_default_print; /* don't use default_print() for unknown packet types */ int ndo_tstamp_precision; /* requested time stamp precision */ const char *program_name; /* Name of the program using the library */ char *ndo_espsecret; struct sa_list *ndo_sa_list_head; /* used by print-esp.c */ struct sa_list *ndo_sa_default; char *ndo_sigsecret; /* Signature verification secret key */ int ndo_packettype; /* as specified by -T */ int ndo_snaplen; /*global pointers to beginning and end of current packet (during printing) */ const u_char *ndo_packetp; const u_char *ndo_snapend; /* pointer to the if_printer function */ if_printer ndo_if_printer; /* pointer to void function to output stuff */ void (*ndo_default_print)(netdissect_options *, register const u_char *bp, register u_int length); /* pointer to function to do regular output */ int (*ndo_printf)(netdissect_options *, const char *fmt, ...) #ifdef __ATTRIBUTE___FORMAT_OK_FOR_FUNCTION_POINTERS __attribute__ ((format (printf, 2, 3))) #endif ; /* pointer to function to output errors */ void (*ndo_error)(netdissect_options *, const char *fmt, ...) #ifdef __ATTRIBUTE___NORETURN_OK_FOR_FUNCTION_POINTERS __attribute__ ((noreturn)) #endif /* __ATTRIBUTE___NORETURN_OK_FOR_FUNCTION_POINTERS */ #ifdef __ATTRIBUTE___FORMAT_OK_FOR_FUNCTION_POINTERS __attribute__ ((format (printf, 2, 3))) #endif /* __ATTRIBUTE___FORMAT_OK_FOR_FUNCTION_POINTERS */ ; /* pointer to function to output warnings */ void (*ndo_warning)(netdissect_options *, const char *fmt, ...) #ifdef __ATTRIBUTE___FORMAT_OK_FOR_FUNCTION_POINTERS __attribute__ ((format (printf, 2, 3))) #endif ; }; #define PT_VAT 1 /* Visual Audio Tool */ #define PT_WB 2 /* distributed White Board */ #define PT_RPC 3 /* Remote Procedure Call */ #define PT_RTP 4 /* Real-Time Applications protocol */ #define PT_RTCP 5 /* Real-Time Applications control protocol */ #define PT_SNMP 6 /* Simple Network Management Protocol */ #define PT_CNFP 7 /* Cisco NetFlow protocol */ #define PT_TFTP 8 /* trivial file transfer protocol */ #define PT_AODV 9 /* Ad-hoc On-demand Distance Vector Protocol */ #define PT_CARP 10 /* Common Address Redundancy Protocol */ #define PT_RADIUS 11 /* RADIUS authentication Protocol */ #define PT_ZMTP1 12 /* ZeroMQ Message Transport Protocol 1.0 */ #define PT_VXLAN 13 /* Virtual eXtensible Local Area Network */ #define PT_PGM 14 /* [UDP-encapsulated] Pragmatic General Multicast */ #define PT_PGM_ZMTP1 15 /* ZMTP/1.0 inside PGM (native or UDP-encapsulated) */ #define PT_LMP 16 /* Link Management Protocol */ #define PT_RESP 17 /* RESP */ #ifndef min #define min(a,b) ((a)>(b)?(b):(a)) #endif #ifndef max #define max(a,b) ((b)>(a)?(b):(a)) #endif /* For source or destination ports tests (UDP, TCP, ...) */ #define IS_SRC_OR_DST_PORT(p) (sport == (p) || dport == (p)) /* * Maximum snapshot length. This should be enough to capture the full * packet on most network interfaces. * * * Somewhat arbitrary, but chosen to be: * * 1) big enough for maximum-size Linux loopback packets (65549) * and some USB packets captured with USBPcap: * * http://desowin.org/usbpcap/ * * (> 131072, < 262144) * * and * * 2) small enough not to cause attempts to allocate huge amounts of * memory; some applications might use the snapshot length in a * savefile header to control the size of the buffer they allocate, * so a size of, say, 2^31-1 might not work well. * * XXX - does it need to be bigger still? */ #define MAXIMUM_SNAPLEN 262144 /* * The default snapshot length is the maximum. */ #define DEFAULT_SNAPLEN MAXIMUM_SNAPLEN #define ESRC(ep) ((ep)->ether_shost) #define EDST(ep) ((ep)->ether_dhost) #ifndef NTOHL #define NTOHL(x) (x) = ntohl(x) #define NTOHS(x) (x) = ntohs(x) #define HTONL(x) (x) = htonl(x) #define HTONS(x) (x) = htons(x) #endif /* * True if "l" bytes of "var" were captured. * * The "ndo->ndo_snapend - (l) <= ndo->ndo_snapend" checks to make sure * "l" isn't so large that "ndo->ndo_snapend - (l)" underflows. * * The check is for <= rather than < because "l" might be 0. * * We cast the pointers to uintptr_t to make sure that the compiler * doesn't optimize away any of these tests (which it is allowed to * do, as adding an integer to, or subtracting an integer from, a * pointer assumes that the pointer is a pointer to an element of an * array and that the result of the addition or subtraction yields a * pointer to another member of the array, so that, for example, if * you subtract a positive integer from a pointer, the result is * guaranteed to be less than the original pointer value). See * * http://www.kb.cert.org/vuls/id/162289 */ /* * Test in two parts to avoid these warnings: * comparison of unsigned expression >= 0 is always true [-Wtype-limits], * comparison is always true due to limited range of data type [-Wtype-limits]. */ #define IS_NOT_NEGATIVE(x) (((x) > 0) || ((x) == 0)) #define ND_TTEST2(var, l) \ (IS_NOT_NEGATIVE(l) && \ ((uintptr_t)ndo->ndo_snapend - (l) <= (uintptr_t)ndo->ndo_snapend && \ (uintptr_t)&(var) <= (uintptr_t)ndo->ndo_snapend - (l))) /* True if "var" was captured */ #define ND_TTEST(var) ND_TTEST2(var, sizeof(var)) /* Bail if "l" bytes of "var" were not captured */ #define ND_TCHECK2(var, l) if (!ND_TTEST2(var, l)) goto trunc /* Bail if "var" was not captured */ #define ND_TCHECK(var) ND_TCHECK2(var, sizeof(var)) #define ND_PRINT(STUFF) (*ndo->ndo_printf)STUFF #define ND_DEFAULTPRINT(ap, length) (*ndo->ndo_default_print)(ndo, ap, length) extern void ts_print(netdissect_options *, const struct timeval *); extern void signed_relts_print(netdissect_options *, int32_t); extern void unsigned_relts_print(netdissect_options *, uint32_t); extern void fn_print_char(netdissect_options *, u_char); extern int fn_print(netdissect_options *, const u_char *, const u_char *); extern u_int fn_printztn(netdissect_options *ndo, const u_char *, u_int, const u_char *); extern int fn_printn(netdissect_options *, const u_char *, u_int, const u_char *); extern int fn_printzp(netdissect_options *, const u_char *, u_int, const u_char *); /* * Flags for txtproto_print(). */ #define RESP_CODE_SECOND_TOKEN 0x00000001 /* response code is second token in response line */ extern void txtproto_print(netdissect_options *, const u_char *, u_int, const char *, const char **, u_int); /* * Locale-independent macros for testing character properties and * stripping the 8th bit from characters. Assumed to be handed * a value between 0 and 255, i.e. don't hand them a char, as * those might be in the range -128 to 127. */ #define ND_ISASCII(c) (!((c) & 0x80)) /* value is an ASCII code point */ #define ND_ISPRINT(c) ((c) >= 0x20 && (c) <= 0x7E) #define ND_ISGRAPH(c) ((c) > 0x20 && (c) <= 0x7E) #define ND_TOASCII(c) ((c) & 0x7F) extern void safeputchar(netdissect_options *, const u_char); extern void safeputs(netdissect_options *, const u_char *, const u_int); #ifdef LBL_ALIGN /* * The processor doesn't natively handle unaligned loads, * and the compiler might "helpfully" optimize memcpy() * and memcmp(), when handed pointers that would normally * be properly aligned, into sequences that assume proper * alignment. * * Do copies and compares of possibly-unaligned data by * calling routines that wrap memcpy() and memcmp(), to * prevent that optimization. */ extern void unaligned_memcpy(void *, const void *, size_t); extern int unaligned_memcmp(const void *, const void *, size_t); #define UNALIGNED_MEMCPY(p, q, l) unaligned_memcpy((p), (q), (l)) #define UNALIGNED_MEMCMP(p, q, l) unaligned_memcmp((p), (q), (l)) #else /* * The procesor natively handles unaligned loads, so just use memcpy() * and memcmp(), to enable those optimizations. */ #define UNALIGNED_MEMCPY(p, q, l) memcpy((p), (q), (l)) #define UNALIGNED_MEMCMP(p, q, l) memcmp((p), (q), (l)) #endif #define PLURAL_SUFFIX(n) \ (((n) != 1) ? "s" : "") extern const char *tok2strary_internal(const char **, int, const char *, int); #define tok2strary(a,f,i) tok2strary_internal(a, sizeof(a)/sizeof(a[0]),f,i) extern if_printer lookup_printer(int); /* The DLT printer routines */ extern u_int ap1394_if_print IF_PRINTER_ARGS; extern u_int arcnet_if_print IF_PRINTER_ARGS; extern u_int arcnet_linux_if_print IF_PRINTER_ARGS; extern u_int atm_if_print IF_PRINTER_ARGS; extern u_int bt_if_print IF_PRINTER_ARGS; extern u_int chdlc_if_print IF_PRINTER_ARGS; extern u_int cip_if_print IF_PRINTER_ARGS; extern u_int enc_if_print IF_PRINTER_ARGS; extern u_int ether_if_print IF_PRINTER_ARGS; extern u_int fddi_if_print IF_PRINTER_ARGS; extern u_int fr_if_print IF_PRINTER_ARGS; extern u_int ieee802_11_if_print IF_PRINTER_ARGS; extern u_int ieee802_11_radio_avs_if_print IF_PRINTER_ARGS; extern u_int ieee802_11_radio_if_print IF_PRINTER_ARGS; extern u_int ieee802_15_4_if_print IF_PRINTER_ARGS; extern u_int ipfc_if_print IF_PRINTER_ARGS; extern u_int ipnet_if_print IF_PRINTER_ARGS; extern u_int juniper_atm1_print IF_PRINTER_ARGS; extern u_int juniper_atm2_print IF_PRINTER_ARGS; extern u_int juniper_chdlc_print IF_PRINTER_ARGS; extern u_int juniper_es_print IF_PRINTER_ARGS; extern u_int juniper_ether_print IF_PRINTER_ARGS; extern u_int juniper_frelay_print IF_PRINTER_ARGS; extern u_int juniper_ggsn_print IF_PRINTER_ARGS; extern u_int juniper_mfr_print IF_PRINTER_ARGS; extern u_int juniper_mlfr_print IF_PRINTER_ARGS; extern u_int juniper_mlppp_print IF_PRINTER_ARGS; extern u_int juniper_monitor_print IF_PRINTER_ARGS; extern u_int juniper_ppp_print IF_PRINTER_ARGS; extern u_int juniper_pppoe_atm_print IF_PRINTER_ARGS; extern u_int juniper_pppoe_print IF_PRINTER_ARGS; extern u_int juniper_services_print IF_PRINTER_ARGS; extern u_int lane_if_print IF_PRINTER_ARGS; extern u_int ltalk_if_print IF_PRINTER_ARGS; extern u_int mfr_if_print IF_PRINTER_ARGS; extern u_int netanalyzer_if_print IF_PRINTER_ARGS; extern u_int netanalyzer_transparent_if_print IF_PRINTER_ARGS; extern u_int nflog_if_print IF_PRINTER_ARGS; extern u_int null_if_print IF_PRINTER_ARGS; extern u_int pflog_if_print IF_PRINTER_ARGS; extern u_int pktap_if_print IF_PRINTER_ARGS; extern u_int ppi_if_print IF_PRINTER_ARGS; extern u_int ppp_bsdos_if_print IF_PRINTER_ARGS; extern u_int ppp_hdlc_if_print IF_PRINTER_ARGS; extern u_int ppp_if_print IF_PRINTER_ARGS; extern u_int pppoe_if_print IF_PRINTER_ARGS; extern u_int prism_if_print IF_PRINTER_ARGS; extern u_int raw_if_print IF_PRINTER_ARGS; extern u_int sl_bsdos_if_print IF_PRINTER_ARGS; extern u_int sl_if_print IF_PRINTER_ARGS; extern u_int sll_if_print IF_PRINTER_ARGS; extern u_int sunatm_if_print IF_PRINTER_ARGS; extern u_int symantec_if_print IF_PRINTER_ARGS; extern u_int token_if_print IF_PRINTER_ARGS; extern u_int usb_linux_48_byte_print IF_PRINTER_ARGS; extern u_int usb_linux_64_byte_print IF_PRINTER_ARGS; /* * Structure passed to some printers to allow them to print * link-layer address information if ndo_eflag isn't set * (because they are for protocols that don't have their * own addresses, so that we'd want to report link-layer * address information). * * This contains a pointer to an address and a pointer to a routine * to which we pass that pointer in order to get a string. */ struct lladdr_info { const char *(*addr_string)(netdissect_options *, const u_char *); const u_char *addr; }; /* The printer routines. */ extern void aarp_print(netdissect_options *, const u_char *, u_int); extern int ah_print(netdissect_options *, register const u_char *); extern void ahcp_print(netdissect_options *, const u_char *, const u_int); extern void aodv_print(netdissect_options *, const u_char *, u_int, int); extern void aoe_print(netdissect_options *, const u_char *, const u_int); extern void arp_print(netdissect_options *, const u_char *, u_int, u_int); extern void ascii_print(netdissect_options *, const u_char *, u_int); extern void atalk_print(netdissect_options *, const u_char *, u_int); extern void atm_print(netdissect_options *, u_int, u_int, u_int, const u_char *, u_int, u_int); extern void babel_print(netdissect_options *, const u_char *, u_int); extern void beep_print(netdissect_options *, const u_char *, u_int); extern void bfd_print(netdissect_options *, const u_char *, u_int, u_int); extern void bgp_print(netdissect_options *, const u_char *, int); extern char *bgp_vpn_rd_print (netdissect_options *, const u_char *); extern void bootp_print(netdissect_options *, const u_char *, u_int); extern void calm_fast_print(netdissect_options *, const u_char *, u_int, const struct lladdr_info *); extern void carp_print(netdissect_options *, const u_char *, u_int, int); extern void cdp_print(netdissect_options *, const u_char *, u_int, u_int); extern void cfm_print(netdissect_options *, const u_char *, u_int); extern u_int chdlc_print(netdissect_options *, register const u_char *, u_int); extern void cisco_autorp_print(netdissect_options *, const u_char *, u_int); extern void cnfp_print(netdissect_options *, const u_char *); extern void dccp_print(netdissect_options *, const u_char *, const u_char *, u_int); extern void decnet_print(netdissect_options *, const u_char *, u_int, u_int); extern void dhcp6_print(netdissect_options *, const u_char *, u_int); extern int dstopt_print(netdissect_options *, const u_char *); extern void dtp_print(netdissect_options *, const u_char *, u_int); extern void dvmrp_print(netdissect_options *, const u_char *, u_int); extern void eap_print(netdissect_options *, const u_char *, u_int); extern void egp_print(netdissect_options *, const u_char *, u_int); extern void eigrp_print(netdissect_options *, const u_char *, u_int); extern int esp_print(netdissect_options *, const u_char *, const int, const u_char *, int *, int *); extern u_int ether_print(netdissect_options *, const u_char *, u_int, u_int, void (*)(netdissect_options *, const u_char *), const u_char *); extern int ethertype_print(netdissect_options *, u_short, const u_char *, u_int, u_int, const struct lladdr_info *, const struct lladdr_info *); extern u_int fddi_print(netdissect_options *, const u_char *, u_int, u_int); extern void forces_print(netdissect_options *, const u_char *, u_int); extern u_int fr_print(netdissect_options *, register const u_char *, u_int); extern int frag6_print(netdissect_options *, const u_char *, const u_char *); extern void ftp_print(netdissect_options *, const u_char *, u_int); extern void geneve_print(netdissect_options *, const u_char *, u_int); extern void geonet_print(netdissect_options *, const u_char *, u_int, const struct lladdr_info *); extern void gre_print(netdissect_options *, const u_char *, u_int); extern int hbhopt_print(netdissect_options *, const u_char *); extern void hex_and_ascii_print(netdissect_options *, const char *, const u_char *, u_int); extern void hex_and_ascii_print_with_offset(netdissect_options *, const char *, const u_char *, u_int, u_int); extern void hex_print(netdissect_options *, const char *ident, const u_char *cp, u_int); extern void hex_print_with_offset(netdissect_options *, const char *ident, const u_char *cp, u_int, u_int); extern void hncp_print(netdissect_options *, const u_char *, u_int); extern void hsrp_print(netdissect_options *, const u_char *, u_int); extern void http_print(netdissect_options *, const u_char *, u_int); extern void icmp6_print(netdissect_options *, const u_char *, u_int, const u_char *, int); extern void icmp_print(netdissect_options *, const u_char *, u_int, const u_char *, int); extern u_int ieee802_11_radio_print(netdissect_options *, const u_char *, u_int, u_int); extern void igmp_print(netdissect_options *, const u_char *, u_int); extern void igrp_print(netdissect_options *, const u_char *, u_int); extern void ip6_print(netdissect_options *, const u_char *, u_int); extern void ipN_print(netdissect_options *, const u_char *, u_int); extern void ip_print(netdissect_options *, const u_char *, u_int); extern void ip_print_inner(netdissect_options *, const u_char *, u_int, u_int nh, const u_char *); extern void ipcomp_print(netdissect_options *, register const u_char *); extern void ipx_netbios_print(netdissect_options *, const u_char *, u_int); extern void ipx_print(netdissect_options *, const u_char *, u_int); extern void isakmp_print(netdissect_options *, const u_char *, u_int, const u_char *); extern void isakmp_rfc3948_print(netdissect_options *, const u_char *, u_int, const u_char *); extern void isoclns_print(netdissect_options *, const u_char *, u_int); extern void krb_print(netdissect_options *, const u_char *); extern void l2tp_print(netdissect_options *, const u_char *, u_int); extern void lane_print(netdissect_options *, const u_char *, u_int, u_int); extern void ldp_print(netdissect_options *, const u_char *, u_int); extern void lisp_print(netdissect_options *, const u_char *, u_int); extern u_int llap_print(netdissect_options *, const u_char *, u_int); extern int llc_print(netdissect_options *, const u_char *, u_int, u_int, const struct lladdr_info *, const struct lladdr_info *); extern void lldp_print(netdissect_options *, const u_char *, u_int); extern void lmp_print(netdissect_options *, const u_char *, u_int); extern void loopback_print(netdissect_options *, const u_char *, const u_int); extern void lspping_print(netdissect_options *, const u_char *, u_int); extern void lwapp_control_print(netdissect_options *, const u_char *, u_int, int); extern void lwapp_data_print(netdissect_options *, const u_char *, u_int); extern void lwres_print(netdissect_options *, const u_char *, u_int); extern void m3ua_print(netdissect_options *, const u_char *, const u_int); extern void medsa_print(netdissect_options *, const u_char *, u_int, u_int, const struct lladdr_info *, const struct lladdr_info *); extern u_int mfr_print(netdissect_options *, register const u_char *, u_int); extern void mobile_print(netdissect_options *, const u_char *, u_int); extern int mobility_print(netdissect_options *, const u_char *, const u_char *); extern void mpcp_print(netdissect_options *, const u_char *, u_int); extern void mpls_print(netdissect_options *, const u_char *, u_int); extern int mptcp_print(netdissect_options *, const u_char *, u_int, u_char); extern void msdp_print(netdissect_options *, const u_char *, u_int); extern void msnlb_print(netdissect_options *, const u_char *); extern void nbt_tcp_print(netdissect_options *, const u_char *, int); extern void nbt_udp137_print(netdissect_options *, const u_char *, int); extern void nbt_udp138_print(netdissect_options *, const u_char *, int); extern void netbeui_print(netdissect_options *, u_short, const u_char *, int); extern void nfsreply_print(netdissect_options *, const u_char *, u_int, const u_char *); extern void nfsreply_print_noaddr(netdissect_options *, const u_char *, u_int, const u_char *); extern void nfsreq_print_noaddr(netdissect_options *, const u_char *, u_int, const u_char *); extern const u_char * ns_nprint (netdissect_options *, register const u_char *, register const u_char *); extern void ns_print(netdissect_options *, const u_char *, u_int, int); extern void nsh_print(netdissect_options *ndo, const u_char *bp, u_int len); extern void ntp_print(netdissect_options *, const u_char *, u_int); extern void oam_print(netdissect_options *, const u_char *, u_int, u_int); extern void olsr_print(netdissect_options *, const u_char *, u_int, int); extern void openflow_print(netdissect_options *, const u_char *, const u_int); extern void ospf6_print(netdissect_options *, const u_char *, u_int); extern void ospf_print(netdissect_options *, const u_char *, u_int, const u_char *); extern int ospf_print_grace_lsa(netdissect_options *, const uint8_t *, u_int); extern int ospf_print_te_lsa(netdissect_options *, const uint8_t *, u_int); extern void otv_print(netdissect_options *, const u_char *, u_int); extern void pgm_print(netdissect_options *, const u_char *, u_int, const u_char *); extern void pim_print(netdissect_options *, const u_char *, u_int, const u_char *); extern void pimv1_print(netdissect_options *, const u_char *, u_int); extern u_int ppp_print(netdissect_options *, register const u_char *, u_int); extern u_int pppoe_print(netdissect_options *, const u_char *, u_int); extern void pptp_print(netdissect_options *, const u_char *); extern int print_unknown_data(netdissect_options *, const u_char *, const char *, int); extern char *q922_string(netdissect_options *, const u_char *, u_int); extern void q933_print(netdissect_options *, const u_char *, u_int); extern void radius_print(netdissect_options *, const u_char *, u_int); extern void resp_print(netdissect_options *, const u_char *, u_int); extern void rip_print(netdissect_options *, const u_char *, u_int); extern void ripng_print(netdissect_options *, const u_char *, unsigned int); extern void rpki_rtr_print(netdissect_options *, const u_char *, u_int); extern void rrcp_print(netdissect_options *, const u_char *, u_int, const struct lladdr_info *, const struct lladdr_info *); extern void rsvp_print(netdissect_options *, const u_char *, u_int); extern int rt6_print(netdissect_options *, const u_char *, const u_char *); extern void rtsp_print(netdissect_options *, const u_char *, u_int); extern void rx_print(netdissect_options *, register const u_char *, int, int, int, const u_char *); extern void sctp_print(netdissect_options *, const u_char *, const u_char *, u_int); extern void sflow_print(netdissect_options *, const u_char *, u_int); extern void sip_print(netdissect_options *, const u_char *, u_int); extern void slow_print(netdissect_options *, const u_char *, u_int); extern void smb_print_data(netdissect_options *, const unsigned char *, int); extern void smb_tcp_print(netdissect_options *, const u_char *, int); extern void smtp_print(netdissect_options *, const u_char *, u_int); extern int snap_print(netdissect_options *, const u_char *, u_int, u_int, const struct lladdr_info *, const struct lladdr_info *, u_int); extern void snmp_print(netdissect_options *, const u_char *, u_int); extern void stp_print(netdissect_options *, const u_char *, u_int); extern void sunrpcrequest_print(netdissect_options *, const u_char *, u_int, const u_char *); extern void syslog_print(netdissect_options *, const u_char *, u_int); extern void tcp_print(netdissect_options *, const u_char *, u_int, const u_char *, int); extern void telnet_print(netdissect_options *, const u_char *, u_int); extern void tftp_print(netdissect_options *, const u_char *, u_int); extern void timed_print(netdissect_options *, const u_char *); extern void tipc_print(netdissect_options *, const u_char *, u_int, u_int); extern u_int token_print(netdissect_options *, const u_char *, u_int, u_int); extern void udld_print(netdissect_options *, const u_char *, u_int); extern void udp_print(netdissect_options *, const u_char *, u_int, const u_char *, int); extern int vjc_print(netdissect_options *, register const char *, u_short); extern void vqp_print(netdissect_options *, register const u_char *, register u_int); extern void vrrp_print(netdissect_options *, const u_char *, u_int, const u_char *, int); extern void vtp_print(netdissect_options *, const u_char *, u_int); extern void vxlan_gpe_print(netdissect_options *ndo, const u_char *bp, u_int len); extern void vxlan_print(netdissect_options *, const u_char *, u_int); extern void wb_print(netdissect_options *, const void *, u_int); extern void zephyr_print(netdissect_options *, const u_char *, int); extern void zmtp1_print(netdissect_options *, const u_char *, u_int); extern void zmtp1_print_datagram(netdissect_options *, const u_char *, const u_int); /* checksum routines */ extern void init_checksum(void); extern uint16_t verify_crc10_cksum(uint16_t, const u_char *, int); extern uint16_t create_osi_cksum(const uint8_t *, int, int); struct cksum_vec { const uint8_t *ptr; int len; }; extern uint16_t in_cksum(const struct cksum_vec *, int); extern uint16_t in_cksum_shouldbe(uint16_t, uint16_t); extern int nextproto4_cksum(netdissect_options *, const struct ip *, const uint8_t *, u_int, u_int, u_int); /* in print-ip6.c */ extern int nextproto6_cksum(netdissect_options *, const struct ip6_hdr *, const uint8_t *, u_int, u_int, u_int); /* Utilities */ extern int mask2plen(uint32_t); extern int mask62plen(const u_char *); extern const char *dnnum_string(netdissect_options *, u_short); extern char *smb_errstr(int, int); extern const char *nt_errstr(uint32_t); extern int decode_prefix4(netdissect_options *, const u_char *, u_int, char *, u_int); extern int decode_prefix6(netdissect_options *, const u_char *, u_int, char *, u_int); extern void esp_print_decodesecret(netdissect_options *); extern int esp_print_decrypt_buffer_by_ikev2(netdissect_options *, int, u_char spii[8], u_char spir[8], const u_char *, const u_char *); #endif /* netdissect_h */ tcpdump-4.9.3/oui.h0000644000026300017510000001007513544412561012303 0ustar mcrmcr/* * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code * distributions retain the above copyright notice and this paragraph * in its entirety, and (2) distributions including binary code include * the above copyright notice and this paragraph in its entirety in * the documentation or other materials provided with the distribution. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. * * Original code by Hannes Gredler (hannes@gredler.at) */ extern const struct tok oui_values[]; extern const struct tok smi_values[]; #define OUI_ENCAP_ETHER 0x000000 /* encapsulated Ethernet */ #define OUI_CISCO 0x00000c /* Cisco protocols */ #define OUI_IANA 0x00005E /* IANA */ #define OUI_NORTEL 0x000081 /* Nortel SONMP */ #define OUI_CISCO_90 0x0000f8 /* Cisco bridging */ #define OUI_RFC2684 0x0080c2 /* RFC 2427/2684 bridged Ethernet */ #define OUI_ATM_FORUM 0x00A03E /* ATM Forum */ #define OUI_CABLE_BPDU 0x00E02F /* DOCSIS spanning tree BPDU */ #define OUI_APPLETALK 0x080007 /* Appletalk */ #define OUI_JUNIPER 0x009069 /* Juniper */ #define OUI_HP 0x080009 /* Hewlett-Packard */ #define OUI_IEEE_8021_PRIVATE 0x0080c2 /* IEEE 802.1 Organisation Specific - Annex F */ #define OUI_IEEE_8023_PRIVATE 0x00120f /* IEEE 802.3 Organisation Specific - Annex G */ #define OUI_TIA 0x0012bb /* TIA - Telecommunications Industry Association - ANSI/TIA-1057- 2006 */ #define OUI_DCBX 0x001B21 /* DCBX */ #define OUI_NICIRA 0x002320 /* Nicira Networks */ #define OUI_BSN 0x5c16c7 /* Big Switch Networks */ #define OUI_VELLO 0xb0d2f5 /* Vello Systems */ #define OUI_HP2 0x002481 /* HP too */ #define OUI_HPLABS 0x0004ea /* HP-Labs */ #define OUI_INFOBLOX 0x748771 /* Infoblox Inc */ #define OUI_ONLAB 0xa42305 /* Open Networking Lab */ #define OUI_FREESCALE 0x00049f /* Freescale */ #define OUI_NETRONOME 0x0015ad /* Netronome */ /* * These are SMI Network Management Private Enterprise Codes for * organizations; see * * http://www.iana.org/assignments/enterprise-numbers * * for a list. * * List taken from Ethereal's epan/sminmpec.h. */ #define SMI_IETF 0 /* reserved - used by the IETF in L2TP? */ #define SMI_ACC 5 #define SMI_CISCO 9 #define SMI_HEWLETT_PACKARD 11 #define SMI_SUN_MICROSYSTEMS 42 #define SMI_MERIT 61 #define SMI_SHIVA 166 #define SMI_ERICSSON 193 #define SMI_CISCO_VPN5000 255 #define SMI_LIVINGSTON 307 #define SMI_MICROSOFT 311 #define SMI_3COM 429 #define SMI_ASCEND 529 #define SMI_BAY 1584 #define SMI_FOUNDRY 1991 #define SMI_VERSANET 2180 #define SMI_REDBACK 2352 #define SMI_JUNIPER 2636 #define SMI_APTIS 2637 #define SMI_CISCO_VPN3000 3076 #define SMI_COSINE 3085 #define SMI_SHASTA 3199 #define SMI_NETSCREEN 3224 #define SMI_NOMADIX 3309 #define SMI_SIEMENS 4329 #define SMI_CABLELABS 4491 #define SMI_UNISPHERE 4874 #define SMI_CISCO_BBSM 5263 #define SMI_THE3GPP2 5535 #define SMI_IP_UNPLUGGED 5925 #define SMI_ISSANNI 5948 #define SMI_QUINTUM 6618 #define SMI_INTERLINK 6728 #define SMI_COLUBRIS 8744 #define SMI_COLUMBIA_UNIVERSITY 11862 #define SMI_THE3GPP 10415 #define SMI_GEMTEK_SYSTEMS 10529 #define SMI_WIFI_ALLIANCE 14122 tcpdump-4.9.3/pcap-missing.h0000644000026300017510000000346313544412561014104 0ustar mcrmcr/* * Copyright (c) 1988-2002 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of * the University nor the names of its contributors may be used to endorse * or promote products derived from this software without specific prior * written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef netdissect_pcap_missing_h #define netdissect_pcap_missing_h /* * Declarations of functions that might be missing from libpcap. */ #ifndef HAVE_PCAP_LIST_DATALINKS extern int pcap_list_datalinks(pcap_t *, int **); #endif #ifndef HAVE_PCAP_DATALINK_NAME_TO_VAL /* * We assume no platform has one but not the other. */ extern int pcap_datalink_name_to_val(const char *); extern const char *pcap_datalink_val_to_name(int); #endif #ifndef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION extern const char *pcap_datalink_val_to_description(int); #endif #ifndef HAVE_PCAP_DUMP_FTELL extern long pcap_dump_ftell(pcap_dumper_t *); #endif #endif /* netdissect_pcap_missing_h */ tcpdump-4.9.3/print-rpki-rtr.c0000644000026300017510000002551613544412561014414 0ustar mcrmcr/* * Copyright (c) 1998-2011 The TCPDUMP project * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code * distributions retain the above copyright notice and this paragraph * in its entirety, and (2) distributions including binary code include * the above copyright notice and this paragraph in its entirety in * the documentation or other materials provided with the distribution. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. * * Original code by Hannes Gredler (hannes@gredler.at) */ /* \summary: Resource Public Key Infrastructure (RPKI) to Router Protocol printer */ /* specification: RFC 6810 */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include "netdissect.h" #include "extract.h" #include "addrtoname.h" static const char tstr[] = "[|RPKI-RTR]"; /* * RPKI/Router PDU header * * Here's what the PDU header looks like. * The length does include the version and length fields. */ typedef struct rpki_rtr_pdu_ { u_char version; /* Version number */ u_char pdu_type; /* PDU type */ union { u_char session_id[2]; /* Session id */ u_char error_code[2]; /* Error code */ } u; u_char length[4]; } rpki_rtr_pdu; #define RPKI_RTR_PDU_OVERHEAD (offsetof(rpki_rtr_pdu, rpki_rtr_pdu_msg)) /* * IPv4 Prefix PDU. */ typedef struct rpki_rtr_pdu_ipv4_prefix_ { rpki_rtr_pdu pdu_header; u_char flags; u_char prefix_length; u_char max_length; u_char zero; u_char prefix[4]; u_char as[4]; } rpki_rtr_pdu_ipv4_prefix; /* * IPv6 Prefix PDU. */ typedef struct rpki_rtr_pdu_ipv6_prefix_ { rpki_rtr_pdu pdu_header; u_char flags; u_char prefix_length; u_char max_length; u_char zero; u_char prefix[16]; u_char as[4]; } rpki_rtr_pdu_ipv6_prefix; /* * Error report PDU. */ typedef struct rpki_rtr_pdu_error_report_ { rpki_rtr_pdu pdu_header; u_char encapsulated_pdu_length[4]; /* Encapsulated PDU length */ /* Copy of Erroneous PDU (variable, optional) */ /* Length of Error Text (4 octets in network byte order) */ /* Arbitrary Text of Error Diagnostic Message (variable, optional) */ } rpki_rtr_pdu_error_report; /* * PDU type codes */ #define RPKI_RTR_SERIAL_NOTIFY_PDU 0 #define RPKI_RTR_SERIAL_QUERY_PDU 1 #define RPKI_RTR_RESET_QUERY_PDU 2 #define RPKI_RTR_CACHE_RESPONSE_PDU 3 #define RPKI_RTR_IPV4_PREFIX_PDU 4 #define RPKI_RTR_IPV6_PREFIX_PDU 6 #define RPKI_RTR_END_OF_DATA_PDU 7 #define RPKI_RTR_CACHE_RESET_PDU 8 #define RPKI_RTR_ERROR_REPORT_PDU 10 static const struct tok rpki_rtr_pdu_values[] = { { RPKI_RTR_SERIAL_NOTIFY_PDU, "Serial Notify" }, { RPKI_RTR_SERIAL_QUERY_PDU, "Serial Query" }, { RPKI_RTR_RESET_QUERY_PDU, "Reset Query" }, { RPKI_RTR_CACHE_RESPONSE_PDU, "Cache Response" }, { RPKI_RTR_IPV4_PREFIX_PDU, "IPV4 Prefix" }, { RPKI_RTR_IPV6_PREFIX_PDU, "IPV6 Prefix" }, { RPKI_RTR_END_OF_DATA_PDU, "End of Data" }, { RPKI_RTR_CACHE_RESET_PDU, "Cache Reset" }, { RPKI_RTR_ERROR_REPORT_PDU, "Error Report" }, { 0, NULL} }; static const struct tok rpki_rtr_error_codes[] = { { 0, "Corrupt Data" }, { 1, "Internal Error" }, { 2, "No Data Available" }, { 3, "Invalid Request" }, { 4, "Unsupported Protocol Version" }, { 5, "Unsupported PDU Type" }, { 6, "Withdrawal of Unknown Record" }, { 7, "Duplicate Announcement Received" }, { 0, NULL} }; /* * Build a indentation string for a given indentation level. * XXX this should be really in util.c */ static char * indent_string (u_int indent) { static char buf[20]; u_int idx; idx = 0; buf[idx] = '\0'; /* * Does the static buffer fit ? */ if (sizeof(buf) < ((indent/8) + (indent %8) + 2)) { return buf; } /* * Heading newline. */ buf[idx] = '\n'; idx++; while (indent >= 8) { buf[idx] = '\t'; idx++; indent -= 8; } while (indent > 0) { buf[idx] = ' '; idx++; indent--; } /* * Trailing zero. */ buf[idx] = '\0'; return buf; } /* * Print a single PDU. */ static u_int rpki_rtr_pdu_print (netdissect_options *ndo, const u_char *tptr, const u_int len, const u_char recurse, const u_int indent) { const rpki_rtr_pdu *pdu_header; u_int pdu_type, pdu_len, hexdump; const u_char *msg; /* Protocol Version */ ND_TCHECK_8BITS(tptr); if (*tptr != 0) { /* Skip the rest of the input buffer because even if this is * a well-formed PDU of a future RPKI-Router protocol version * followed by a well-formed PDU of RPKI-Router protocol * version 0, there is no way to know exactly how to skip the * current PDU. */ ND_PRINT((ndo, "%sRPKI-RTRv%u (unknown)", indent_string(8), *tptr)); return len; } if (len < sizeof(rpki_rtr_pdu)) { ND_PRINT((ndo, "(%u bytes is too few to decode)", len)); goto invalid; } ND_TCHECK2(*tptr, sizeof(rpki_rtr_pdu)); pdu_header = (const rpki_rtr_pdu *)tptr; pdu_type = pdu_header->pdu_type; pdu_len = EXTRACT_32BITS(pdu_header->length); /* Do not check bounds with pdu_len yet, do it in the case blocks * below to make it possible to decode at least the beginning of * a truncated Error Report PDU or a truncated encapsulated PDU. */ hexdump = FALSE; ND_PRINT((ndo, "%sRPKI-RTRv%u, %s PDU (%u), length: %u", indent_string(8), pdu_header->version, tok2str(rpki_rtr_pdu_values, "Unknown", pdu_type), pdu_type, pdu_len)); if (pdu_len < sizeof(rpki_rtr_pdu) || pdu_len > len) goto invalid; switch (pdu_type) { /* * The following PDUs share the message format. */ case RPKI_RTR_SERIAL_NOTIFY_PDU: case RPKI_RTR_SERIAL_QUERY_PDU: case RPKI_RTR_END_OF_DATA_PDU: if (pdu_len != sizeof(rpki_rtr_pdu) + 4) goto invalid; ND_TCHECK2(*tptr, pdu_len); msg = (const u_char *)(pdu_header + 1); ND_PRINT((ndo, "%sSession ID: 0x%04x, Serial: %u", indent_string(indent+2), EXTRACT_16BITS(pdu_header->u.session_id), EXTRACT_32BITS(msg))); break; /* * The following PDUs share the message format. */ case RPKI_RTR_RESET_QUERY_PDU: case RPKI_RTR_CACHE_RESET_PDU: if (pdu_len != sizeof(rpki_rtr_pdu)) goto invalid; /* no additional boundary to check */ /* * Zero payload PDUs. */ break; case RPKI_RTR_CACHE_RESPONSE_PDU: if (pdu_len != sizeof(rpki_rtr_pdu)) goto invalid; /* no additional boundary to check */ ND_PRINT((ndo, "%sSession ID: 0x%04x", indent_string(indent+2), EXTRACT_16BITS(pdu_header->u.session_id))); break; case RPKI_RTR_IPV4_PREFIX_PDU: { const rpki_rtr_pdu_ipv4_prefix *pdu; if (pdu_len != sizeof(rpki_rtr_pdu) + 12) goto invalid; ND_TCHECK2(*tptr, pdu_len); pdu = (const rpki_rtr_pdu_ipv4_prefix *)tptr; ND_PRINT((ndo, "%sIPv4 Prefix %s/%u-%u, origin-as %u, flags 0x%02x", indent_string(indent+2), ipaddr_string(ndo, pdu->prefix), pdu->prefix_length, pdu->max_length, EXTRACT_32BITS(pdu->as), pdu->flags)); } break; case RPKI_RTR_IPV6_PREFIX_PDU: { const rpki_rtr_pdu_ipv6_prefix *pdu; if (pdu_len != sizeof(rpki_rtr_pdu) + 24) goto invalid; ND_TCHECK2(*tptr, pdu_len); pdu = (const rpki_rtr_pdu_ipv6_prefix *)tptr; ND_PRINT((ndo, "%sIPv6 Prefix %s/%u-%u, origin-as %u, flags 0x%02x", indent_string(indent+2), ip6addr_string(ndo, pdu->prefix), pdu->prefix_length, pdu->max_length, EXTRACT_32BITS(pdu->as), pdu->flags)); } break; case RPKI_RTR_ERROR_REPORT_PDU: { const rpki_rtr_pdu_error_report *pdu; u_int encapsulated_pdu_length, text_length, tlen, error_code; tlen = sizeof(rpki_rtr_pdu); /* Do not test for the "Length of Error Text" data element yet. */ if (pdu_len < tlen + 4) goto invalid; ND_TCHECK2(*tptr, tlen + 4); /* Safe up to and including the "Length of Encapsulated PDU" * data element, more data elements may be present. */ pdu = (const rpki_rtr_pdu_error_report *)tptr; encapsulated_pdu_length = EXTRACT_32BITS(pdu->encapsulated_pdu_length); tlen += 4; error_code = EXTRACT_16BITS(pdu->pdu_header.u.error_code); ND_PRINT((ndo, "%sError code: %s (%u), Encapsulated PDU length: %u", indent_string(indent+2), tok2str(rpki_rtr_error_codes, "Unknown", error_code), error_code, encapsulated_pdu_length)); if (encapsulated_pdu_length) { /* Section 5.10 of RFC 6810 says: * "An Error Report PDU MUST NOT be sent for an Error Report PDU." * * However, as far as the protocol encoding goes Error Report PDUs can * happen to be nested in each other, however many times, in which case * the decoder should still print such semantically incorrect PDUs. * * That said, "the Erroneous PDU field MAY be truncated" (ibid), thus * to keep things simple this implementation decodes only the two * outermost layers of PDUs and makes bounds checks in the outer and * the inner PDU independently. */ if (pdu_len < tlen + encapsulated_pdu_length) goto invalid; if (! recurse) { ND_TCHECK2(*tptr, tlen + encapsulated_pdu_length); } else { ND_PRINT((ndo, "%s-----encapsulated PDU-----", indent_string(indent+4))); rpki_rtr_pdu_print(ndo, tptr + tlen, encapsulated_pdu_length, 0, indent + 2); } tlen += encapsulated_pdu_length; } if (pdu_len < tlen + 4) goto invalid; ND_TCHECK2(*tptr, tlen + 4); /* Safe up to and including the "Length of Error Text" data element, * one more data element may be present. */ /* * Extract, trail-zero and print the Error message. */ text_length = EXTRACT_32BITS(tptr + tlen); tlen += 4; if (text_length) { if (pdu_len < tlen + text_length) goto invalid; /* fn_printn() makes the bounds check */ ND_PRINT((ndo, "%sError text: ", indent_string(indent+2))); if (fn_printn(ndo, tptr + tlen, text_length, ndo->ndo_snapend)) goto trunc; } } break; default: ND_TCHECK2(*tptr, pdu_len); /* * Unknown data, please hexdump. */ hexdump = TRUE; } /* do we also want to see a hex dump ? */ if (ndo->ndo_vflag > 1 || (ndo->ndo_vflag && hexdump)) { print_unknown_data(ndo,tptr,"\n\t ", pdu_len); } return pdu_len; invalid: ND_PRINT((ndo, "%s", istr)); ND_TCHECK2(*tptr, len); return len; trunc: ND_PRINT((ndo, "\n\t%s", tstr)); return len; } void rpki_rtr_print(netdissect_options *ndo, register const u_char *pptr, register u_int len) { if (!ndo->ndo_vflag) { ND_PRINT((ndo, ", RPKI-RTR")); return; } while (len) { u_int pdu_len = rpki_rtr_pdu_print(ndo, pptr, len, 1, 8); len -= pdu_len; pptr += pdu_len; } } /* * Local Variables: * c-style: whitesmith * c-basic-offset: 4 * End: */ tcpdump-4.9.3/print-geonet.c0000644000026300017510000001533713544412561014123 0ustar mcrmcr/* * Copyright (c) 2013 The TCPDUMP project * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code * distributions retain the above copyright notice and this paragraph * in its entirety, and (2) distributions including binary code include * the above copyright notice and this paragraph in its entirety in * the documentation or other materials provided with the distribution. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. * * Original code by Ola Martin Lykkja (ola.lykkja@q-free.com) */ /* \summary: ISO CALM FAST and ETSI GeoNetworking printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #include "extract.h" #include "addrtoname.h" /* ETSI TS 102 636-5-1 V1.1.1 (2011-02) Intelligent Transport Systems (ITS); Vehicular Communications; GeoNetworking; Part 5: Transport Protocols; Sub-part 1: Basic Transport Protocol ETSI TS 102 636-4-1 V1.1.1 (2011-06) Intelligent Transport Systems (ITS); Vehicular communications; GeoNetworking; Part 4: Geographical addressing and forwarding for point-to-point and point-to-multipoint communications; Sub-part 1: Media-Independent Functionality */ #define GEONET_ADDR_LEN 8 static const struct tok msg_type_values[] = { { 0, "CAM" }, { 1, "DENM" }, { 101, "TPEGM" }, { 102, "TSPDM" }, { 103, "VPM" }, { 104, "SRM" }, { 105, "SLAM" }, { 106, "ecoCAM" }, { 107, "ITM" }, { 150, "SA" }, { 0, NULL } }; static void print_btp_body(netdissect_options *ndo, const u_char *bp) { int version; int msg_type; const char *msg_type_str; /* Assuming ItsDpuHeader */ version = bp[0]; msg_type = bp[1]; msg_type_str = tok2str(msg_type_values, "unknown (%u)", msg_type); ND_PRINT((ndo, "; ItsPduHeader v:%d t:%d-%s", version, msg_type, msg_type_str)); } static void print_btp(netdissect_options *ndo, const u_char *bp) { uint16_t dest = EXTRACT_16BITS(bp+0); uint16_t src = EXTRACT_16BITS(bp+2); ND_PRINT((ndo, "; BTP Dst:%u Src:%u", dest, src)); } static int print_long_pos_vector(netdissect_options *ndo, const u_char *bp) { uint32_t lat, lon; if (!ND_TTEST2(*bp, GEONET_ADDR_LEN)) return (-1); ND_PRINT((ndo, "GN_ADDR:%s ", linkaddr_string (ndo, bp, 0, GEONET_ADDR_LEN))); if (!ND_TTEST2(*(bp+12), 8)) return (-1); lat = EXTRACT_32BITS(bp+12); ND_PRINT((ndo, "lat:%d ", lat)); lon = EXTRACT_32BITS(bp+16); ND_PRINT((ndo, "lon:%d", lon)); return (0); } /* * This is the top level routine of the printer. 'p' points * to the geonet header of the packet. */ void geonet_print(netdissect_options *ndo, const u_char *bp, u_int length, const struct lladdr_info *src) { int version; int next_hdr; int hdr_type; int hdr_subtype; uint16_t payload_length; int hop_limit; const char *next_hdr_txt = "Unknown"; const char *hdr_type_txt = "Unknown"; int hdr_size = -1; ND_PRINT((ndo, "GeoNet ")); if (src != NULL) ND_PRINT((ndo, "src:%s", (src->addr_string)(ndo, src->addr))); ND_PRINT((ndo, "; ")); /* Process Common Header */ if (length < 36) goto invalid; ND_TCHECK2(*bp, 8); version = bp[0] >> 4; next_hdr = bp[0] & 0x0f; hdr_type = bp[1] >> 4; hdr_subtype = bp[1] & 0x0f; payload_length = EXTRACT_16BITS(bp+4); hop_limit = bp[7]; switch (next_hdr) { case 0: next_hdr_txt = "Any"; break; case 1: next_hdr_txt = "BTP-A"; break; case 2: next_hdr_txt = "BTP-B"; break; case 3: next_hdr_txt = "IPv6"; break; } switch (hdr_type) { case 0: hdr_type_txt = "Any"; break; case 1: hdr_type_txt = "Beacon"; break; case 2: hdr_type_txt = "GeoUnicast"; break; case 3: switch (hdr_subtype) { case 0: hdr_type_txt = "GeoAnycastCircle"; break; case 1: hdr_type_txt = "GeoAnycastRect"; break; case 2: hdr_type_txt = "GeoAnycastElipse"; break; } break; case 4: switch (hdr_subtype) { case 0: hdr_type_txt = "GeoBroadcastCircle"; break; case 1: hdr_type_txt = "GeoBroadcastRect"; break; case 2: hdr_type_txt = "GeoBroadcastElipse"; break; } break; case 5: switch (hdr_subtype) { case 0: hdr_type_txt = "TopoScopeBcast-SH"; break; case 1: hdr_type_txt = "TopoScopeBcast-MH"; break; } break; case 6: switch (hdr_subtype) { case 0: hdr_type_txt = "LocService-Request"; break; case 1: hdr_type_txt = "LocService-Reply"; break; } break; } ND_PRINT((ndo, "v:%d ", version)); ND_PRINT((ndo, "NH:%d-%s ", next_hdr, next_hdr_txt)); ND_PRINT((ndo, "HT:%d-%d-%s ", hdr_type, hdr_subtype, hdr_type_txt)); ND_PRINT((ndo, "HopLim:%d ", hop_limit)); ND_PRINT((ndo, "Payload:%d ", payload_length)); if (print_long_pos_vector(ndo, bp + 8) == -1) goto trunc; /* Skip Common Header */ length -= 36; bp += 36; /* Process Extended Headers */ switch (hdr_type) { case 0: /* Any */ hdr_size = 0; break; case 1: /* Beacon */ hdr_size = 0; break; case 2: /* GeoUnicast */ break; case 3: switch (hdr_subtype) { case 0: /* GeoAnycastCircle */ break; case 1: /* GeoAnycastRect */ break; case 2: /* GeoAnycastElipse */ break; } break; case 4: switch (hdr_subtype) { case 0: /* GeoBroadcastCircle */ break; case 1: /* GeoBroadcastRect */ break; case 2: /* GeoBroadcastElipse */ break; } break; case 5: switch (hdr_subtype) { case 0: /* TopoScopeBcast-SH */ hdr_size = 0; break; case 1: /* TopoScopeBcast-MH */ hdr_size = 68 - 36; break; } break; case 6: switch (hdr_subtype) { case 0: /* LocService-Request */ break; case 1: /* LocService-Reply */ break; } break; } /* Skip Extended headers */ if (hdr_size >= 0) { if (length < (u_int)hdr_size) goto invalid; ND_TCHECK2(*bp, hdr_size); length -= hdr_size; bp += hdr_size; switch (next_hdr) { case 0: /* Any */ break; case 1: case 2: /* BTP A/B */ if (length < 4) goto invalid; ND_TCHECK2(*bp, 4); print_btp(ndo, bp); length -= 4; bp += 4; if (length >= 2) { /* * XXX - did print_btp_body() * return if length < 2 * because this is optional, * or was that just not * reporting genuine errors? */ ND_TCHECK2(*bp, 2); print_btp_body(ndo, bp); } break; case 3: /* IPv6 */ break; } } /* Print user data part */ if (ndo->ndo_vflag) ND_DEFAULTPRINT(bp, length); return; invalid: ND_PRINT((ndo, " Malformed (small) ")); /* XXX - print the remaining data as hex? */ return; trunc: ND_PRINT((ndo, "[|geonet]")); } /* * Local Variables: * c-style: whitesmith * c-basic-offset: 8 * End: */ tcpdump-4.9.3/print-aodv.c0000644000026300017510000003775513544412561013603 0ustar mcrmcr/* * Copyright (c) 2003 Bruce M. Simpson * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Bruce M. Simpson. * 4. Neither the name of Bruce M. Simpson nor the names of co- * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY Bruce M. Simpson AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Bruce M. Simpson OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /* \summary: Ad hoc On-Demand Distance Vector (AODV) Routing printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #include "addrtoname.h" #include "extract.h" /* * RFC 3561 */ struct aodv_rreq { uint8_t rreq_type; /* AODV message type (1) */ uint8_t rreq_flags; /* various flags */ uint8_t rreq_zero0; /* reserved, set to zero */ uint8_t rreq_hops; /* number of hops from originator */ uint32_t rreq_id; /* request ID */ uint32_t rreq_da; /* destination IPv4 address */ uint32_t rreq_ds; /* destination sequence number */ uint32_t rreq_oa; /* originator IPv4 address */ uint32_t rreq_os; /* originator sequence number */ }; struct aodv_rreq6 { uint8_t rreq_type; /* AODV message type (1) */ uint8_t rreq_flags; /* various flags */ uint8_t rreq_zero0; /* reserved, set to zero */ uint8_t rreq_hops; /* number of hops from originator */ uint32_t rreq_id; /* request ID */ struct in6_addr rreq_da; /* destination IPv6 address */ uint32_t rreq_ds; /* destination sequence number */ struct in6_addr rreq_oa; /* originator IPv6 address */ uint32_t rreq_os; /* originator sequence number */ }; struct aodv_rreq6_draft_01 { uint8_t rreq_type; /* AODV message type (16) */ uint8_t rreq_flags; /* various flags */ uint8_t rreq_zero0; /* reserved, set to zero */ uint8_t rreq_hops; /* number of hops from originator */ uint32_t rreq_id; /* request ID */ uint32_t rreq_ds; /* destination sequence number */ uint32_t rreq_os; /* originator sequence number */ struct in6_addr rreq_da; /* destination IPv6 address */ struct in6_addr rreq_oa; /* originator IPv6 address */ }; #define RREQ_JOIN 0x80 /* join (reserved for multicast */ #define RREQ_REPAIR 0x40 /* repair (reserved for multicast */ #define RREQ_GRAT 0x20 /* gratuitous RREP */ #define RREQ_DEST 0x10 /* destination only */ #define RREQ_UNKNOWN 0x08 /* unknown destination sequence num */ #define RREQ_FLAGS_MASK 0xF8 /* mask for rreq_flags */ struct aodv_rrep { uint8_t rrep_type; /* AODV message type (2) */ uint8_t rrep_flags; /* various flags */ uint8_t rrep_ps; /* prefix size */ uint8_t rrep_hops; /* number of hops from o to d */ uint32_t rrep_da; /* destination IPv4 address */ uint32_t rrep_ds; /* destination sequence number */ uint32_t rrep_oa; /* originator IPv4 address */ uint32_t rrep_life; /* lifetime of this route */ }; struct aodv_rrep6 { uint8_t rrep_type; /* AODV message type (2) */ uint8_t rrep_flags; /* various flags */ uint8_t rrep_ps; /* prefix size */ uint8_t rrep_hops; /* number of hops from o to d */ struct in6_addr rrep_da; /* destination IPv6 address */ uint32_t rrep_ds; /* destination sequence number */ struct in6_addr rrep_oa; /* originator IPv6 address */ uint32_t rrep_life; /* lifetime of this route */ }; struct aodv_rrep6_draft_01 { uint8_t rrep_type; /* AODV message type (17) */ uint8_t rrep_flags; /* various flags */ uint8_t rrep_ps; /* prefix size */ uint8_t rrep_hops; /* number of hops from o to d */ uint32_t rrep_ds; /* destination sequence number */ struct in6_addr rrep_da; /* destination IPv6 address */ struct in6_addr rrep_oa; /* originator IPv6 address */ uint32_t rrep_life; /* lifetime of this route */ }; #define RREP_REPAIR 0x80 /* repair (reserved for multicast */ #define RREP_ACK 0x40 /* acknowledgement required */ #define RREP_FLAGS_MASK 0xC0 /* mask for rrep_flags */ #define RREP_PREFIX_MASK 0x1F /* mask for prefix size */ struct rerr_unreach { uint32_t u_da; /* IPv4 address */ uint32_t u_ds; /* sequence number */ }; struct rerr_unreach6 { struct in6_addr u_da; /* IPv6 address */ uint32_t u_ds; /* sequence number */ }; struct rerr_unreach6_draft_01 { struct in6_addr u_da; /* IPv6 address */ uint32_t u_ds; /* sequence number */ }; struct aodv_rerr { uint8_t rerr_type; /* AODV message type (3 or 18) */ uint8_t rerr_flags; /* various flags */ uint8_t rerr_zero0; /* reserved, set to zero */ uint8_t rerr_dc; /* destination count */ }; #define RERR_NODELETE 0x80 /* don't delete the link */ #define RERR_FLAGS_MASK 0x80 /* mask for rerr_flags */ struct aodv_rrep_ack { uint8_t ra_type; uint8_t ra_zero0; }; #define AODV_RREQ 1 /* route request */ #define AODV_RREP 2 /* route response */ #define AODV_RERR 3 /* error report */ #define AODV_RREP_ACK 4 /* route response acknowledgement */ #define AODV_V6_DRAFT_01_RREQ 16 /* IPv6 route request */ #define AODV_V6_DRAFT_01_RREP 17 /* IPv6 route response */ #define AODV_V6_DRAFT_01_RERR 18 /* IPv6 error report */ #define AODV_V6_DRAFT_01_RREP_ACK 19 /* IPV6 route response acknowledgment */ struct aodv_ext { uint8_t type; /* extension type */ uint8_t length; /* extension length */ }; struct aodv_hello { struct aodv_ext eh; /* extension header */ uint8_t interval[4]; /* expect my next hello in * (n) ms * NOTE: this is not aligned */ }; #define AODV_EXT_HELLO 1 static void aodv_extension(netdissect_options *ndo, const struct aodv_ext *ep, u_int length) { const struct aodv_hello *ah; ND_TCHECK(*ep); switch (ep->type) { case AODV_EXT_HELLO: ah = (const struct aodv_hello *)(const void *)ep; ND_TCHECK(*ah); if (length < sizeof(struct aodv_hello)) goto trunc; if (ep->length < 4) { ND_PRINT((ndo, "\n\text HELLO - bad length %u", ep->length)); break; } ND_PRINT((ndo, "\n\text HELLO %ld ms", (unsigned long)EXTRACT_32BITS(&ah->interval))); break; default: ND_PRINT((ndo, "\n\text %u %u", ep->type, ep->length)); break; } return; trunc: ND_PRINT((ndo, " [|hello]")); } static void aodv_rreq(netdissect_options *ndo, const u_char *dat, u_int length) { u_int i; const struct aodv_rreq *ap = (const struct aodv_rreq *)dat; ND_TCHECK(*ap); if (length < sizeof(*ap)) goto trunc; ND_PRINT((ndo, " rreq %u %s%s%s%s%shops %u id 0x%08lx\n" "\tdst %s seq %lu src %s seq %lu", length, ap->rreq_type & RREQ_JOIN ? "[J]" : "", ap->rreq_type & RREQ_REPAIR ? "[R]" : "", ap->rreq_type & RREQ_GRAT ? "[G]" : "", ap->rreq_type & RREQ_DEST ? "[D]" : "", ap->rreq_type & RREQ_UNKNOWN ? "[U] " : " ", ap->rreq_hops, (unsigned long)EXTRACT_32BITS(&ap->rreq_id), ipaddr_string(ndo, &ap->rreq_da), (unsigned long)EXTRACT_32BITS(&ap->rreq_ds), ipaddr_string(ndo, &ap->rreq_oa), (unsigned long)EXTRACT_32BITS(&ap->rreq_os))); i = length - sizeof(*ap); if (i >= sizeof(struct aodv_ext)) aodv_extension(ndo, (const struct aodv_ext *)(dat + sizeof(*ap)), i); return; trunc: ND_PRINT((ndo, " [|rreq")); } static void aodv_rrep(netdissect_options *ndo, const u_char *dat, u_int length) { u_int i; const struct aodv_rrep *ap = (const struct aodv_rrep *)dat; ND_TCHECK(*ap); if (length < sizeof(*ap)) goto trunc; ND_PRINT((ndo, " rrep %u %s%sprefix %u hops %u\n" "\tdst %s dseq %lu src %s %lu ms", length, ap->rrep_type & RREP_REPAIR ? "[R]" : "", ap->rrep_type & RREP_ACK ? "[A] " : " ", ap->rrep_ps & RREP_PREFIX_MASK, ap->rrep_hops, ipaddr_string(ndo, &ap->rrep_da), (unsigned long)EXTRACT_32BITS(&ap->rrep_ds), ipaddr_string(ndo, &ap->rrep_oa), (unsigned long)EXTRACT_32BITS(&ap->rrep_life))); i = length - sizeof(*ap); if (i >= sizeof(struct aodv_ext)) aodv_extension(ndo, (const struct aodv_ext *)(dat + sizeof(*ap)), i); return; trunc: ND_PRINT((ndo, " [|rreq")); } static void aodv_rerr(netdissect_options *ndo, const u_char *dat, u_int length) { u_int i, dc; const struct aodv_rerr *ap = (const struct aodv_rerr *)dat; const struct rerr_unreach *dp; ND_TCHECK(*ap); if (length < sizeof(*ap)) goto trunc; ND_PRINT((ndo, " rerr %s [items %u] [%u]:", ap->rerr_flags & RERR_NODELETE ? "[D]" : "", ap->rerr_dc, length)); dp = (const struct rerr_unreach *)(dat + sizeof(*ap)); i = length - sizeof(*ap); for (dc = ap->rerr_dc; dc != 0; dc--) { ND_TCHECK(*dp); if (i < sizeof(*dp)) goto trunc; ND_PRINT((ndo, " {%s}(%ld)", ipaddr_string(ndo, &dp->u_da), (unsigned long)EXTRACT_32BITS(&dp->u_ds))); dp++; i -= sizeof(*dp); } return; trunc: ND_PRINT((ndo, "[|rerr]")); } static void aodv_v6_rreq(netdissect_options *ndo, const u_char *dat, u_int length) { u_int i; const struct aodv_rreq6 *ap = (const struct aodv_rreq6 *)dat; ND_TCHECK(*ap); if (length < sizeof(*ap)) goto trunc; ND_PRINT((ndo, " v6 rreq %u %s%s%s%s%shops %u id 0x%08lx\n" "\tdst %s seq %lu src %s seq %lu", length, ap->rreq_type & RREQ_JOIN ? "[J]" : "", ap->rreq_type & RREQ_REPAIR ? "[R]" : "", ap->rreq_type & RREQ_GRAT ? "[G]" : "", ap->rreq_type & RREQ_DEST ? "[D]" : "", ap->rreq_type & RREQ_UNKNOWN ? "[U] " : " ", ap->rreq_hops, (unsigned long)EXTRACT_32BITS(&ap->rreq_id), ip6addr_string(ndo, &ap->rreq_da), (unsigned long)EXTRACT_32BITS(&ap->rreq_ds), ip6addr_string(ndo, &ap->rreq_oa), (unsigned long)EXTRACT_32BITS(&ap->rreq_os))); i = length - sizeof(*ap); if (i >= sizeof(struct aodv_ext)) aodv_extension(ndo, (const struct aodv_ext *)(dat + sizeof(*ap)), i); return; trunc: ND_PRINT((ndo, " [|rreq")); } static void aodv_v6_rrep(netdissect_options *ndo, const u_char *dat, u_int length) { u_int i; const struct aodv_rrep6 *ap = (const struct aodv_rrep6 *)dat; ND_TCHECK(*ap); if (length < sizeof(*ap)) goto trunc; ND_PRINT((ndo, " rrep %u %s%sprefix %u hops %u\n" "\tdst %s dseq %lu src %s %lu ms", length, ap->rrep_type & RREP_REPAIR ? "[R]" : "", ap->rrep_type & RREP_ACK ? "[A] " : " ", ap->rrep_ps & RREP_PREFIX_MASK, ap->rrep_hops, ip6addr_string(ndo, &ap->rrep_da), (unsigned long)EXTRACT_32BITS(&ap->rrep_ds), ip6addr_string(ndo, &ap->rrep_oa), (unsigned long)EXTRACT_32BITS(&ap->rrep_life))); i = length - sizeof(*ap); if (i >= sizeof(struct aodv_ext)) aodv_extension(ndo, (const struct aodv_ext *)(dat + sizeof(*ap)), i); return; trunc: ND_PRINT((ndo, " [|rreq")); } static void aodv_v6_rerr(netdissect_options *ndo, const u_char *dat, u_int length) { u_int i, dc; const struct aodv_rerr *ap = (const struct aodv_rerr *)dat; const struct rerr_unreach6 *dp6; ND_TCHECK(*ap); if (length < sizeof(*ap)) goto trunc; ND_PRINT((ndo, " rerr %s [items %u] [%u]:", ap->rerr_flags & RERR_NODELETE ? "[D]" : "", ap->rerr_dc, length)); dp6 = (const struct rerr_unreach6 *)(const void *)(ap + 1); i = length - sizeof(*ap); for (dc = ap->rerr_dc; dc != 0; dc--) { ND_TCHECK(*dp6); if (i < sizeof(*dp6)) goto trunc; ND_PRINT((ndo, " {%s}(%ld)", ip6addr_string(ndo, &dp6->u_da), (unsigned long)EXTRACT_32BITS(&dp6->u_ds))); dp6++; i -= sizeof(*dp6); } return; trunc: ND_PRINT((ndo, "[|rerr]")); } static void aodv_v6_draft_01_rreq(netdissect_options *ndo, const u_char *dat, u_int length) { u_int i; const struct aodv_rreq6_draft_01 *ap = (const struct aodv_rreq6_draft_01 *)dat; ND_TCHECK(*ap); if (length < sizeof(*ap)) goto trunc; ND_PRINT((ndo, " rreq %u %s%s%s%s%shops %u id 0x%08lx\n" "\tdst %s seq %lu src %s seq %lu", length, ap->rreq_type & RREQ_JOIN ? "[J]" : "", ap->rreq_type & RREQ_REPAIR ? "[R]" : "", ap->rreq_type & RREQ_GRAT ? "[G]" : "", ap->rreq_type & RREQ_DEST ? "[D]" : "", ap->rreq_type & RREQ_UNKNOWN ? "[U] " : " ", ap->rreq_hops, (unsigned long)EXTRACT_32BITS(&ap->rreq_id), ip6addr_string(ndo, &ap->rreq_da), (unsigned long)EXTRACT_32BITS(&ap->rreq_ds), ip6addr_string(ndo, &ap->rreq_oa), (unsigned long)EXTRACT_32BITS(&ap->rreq_os))); i = length - sizeof(*ap); if (i >= sizeof(struct aodv_ext)) aodv_extension(ndo, (const struct aodv_ext *)(dat + sizeof(*ap)), i); return; trunc: ND_PRINT((ndo, " [|rreq")); } static void aodv_v6_draft_01_rrep(netdissect_options *ndo, const u_char *dat, u_int length) { u_int i; const struct aodv_rrep6_draft_01 *ap = (const struct aodv_rrep6_draft_01 *)dat; ND_TCHECK(*ap); if (length < sizeof(*ap)) goto trunc; ND_PRINT((ndo, " rrep %u %s%sprefix %u hops %u\n" "\tdst %s dseq %lu src %s %lu ms", length, ap->rrep_type & RREP_REPAIR ? "[R]" : "", ap->rrep_type & RREP_ACK ? "[A] " : " ", ap->rrep_ps & RREP_PREFIX_MASK, ap->rrep_hops, ip6addr_string(ndo, &ap->rrep_da), (unsigned long)EXTRACT_32BITS(&ap->rrep_ds), ip6addr_string(ndo, &ap->rrep_oa), (unsigned long)EXTRACT_32BITS(&ap->rrep_life))); i = length - sizeof(*ap); if (i >= sizeof(struct aodv_ext)) aodv_extension(ndo, (const struct aodv_ext *)(dat + sizeof(*ap)), i); return; trunc: ND_PRINT((ndo, " [|rreq")); } static void aodv_v6_draft_01_rerr(netdissect_options *ndo, const u_char *dat, u_int length) { u_int i, dc; const struct aodv_rerr *ap = (const struct aodv_rerr *)dat; const struct rerr_unreach6_draft_01 *dp6; ND_TCHECK(*ap); if (length < sizeof(*ap)) goto trunc; ND_PRINT((ndo, " rerr %s [items %u] [%u]:", ap->rerr_flags & RERR_NODELETE ? "[D]" : "", ap->rerr_dc, length)); dp6 = (const struct rerr_unreach6_draft_01 *)(const void *)(ap + 1); i = length - sizeof(*ap); for (dc = ap->rerr_dc; dc != 0; dc--) { ND_TCHECK(*dp6); if (i < sizeof(*dp6)) goto trunc; ND_PRINT((ndo, " {%s}(%ld)", ip6addr_string(ndo, &dp6->u_da), (unsigned long)EXTRACT_32BITS(&dp6->u_ds))); dp6++; i -= sizeof(*dp6); } return; trunc: ND_PRINT((ndo, "[|rerr]")); } void aodv_print(netdissect_options *ndo, const u_char *dat, u_int length, int is_ip6) { uint8_t msg_type; /* * The message type is the first byte; make sure we have it * and then fetch it. */ ND_TCHECK(*dat); msg_type = *dat; ND_PRINT((ndo, " aodv")); switch (msg_type) { case AODV_RREQ: if (is_ip6) aodv_v6_rreq(ndo, dat, length); else aodv_rreq(ndo, dat, length); break; case AODV_RREP: if (is_ip6) aodv_v6_rrep(ndo, dat, length); else aodv_rrep(ndo, dat, length); break; case AODV_RERR: if (is_ip6) aodv_v6_rerr(ndo, dat, length); else aodv_rerr(ndo, dat, length); break; case AODV_RREP_ACK: ND_PRINT((ndo, " rrep-ack %u", length)); break; case AODV_V6_DRAFT_01_RREQ: aodv_v6_draft_01_rreq(ndo, dat, length); break; case AODV_V6_DRAFT_01_RREP: aodv_v6_draft_01_rrep(ndo, dat, length); break; case AODV_V6_DRAFT_01_RERR: aodv_v6_draft_01_rerr(ndo, dat, length); break; case AODV_V6_DRAFT_01_RREP_ACK: ND_PRINT((ndo, " rrep-ack %u", length)); break; default: ND_PRINT((ndo, " type %u %u", msg_type, length)); } return; trunc: ND_PRINT((ndo, " [|aodv]")); } tcpdump-4.9.3/print-juniper.c0000644000026300017510000014065313544412561014316 0ustar mcrmcr/* NetBSD: print-juniper.c,v 1.2 2007/07/24 11:53:45 drochner Exp */ /* * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code * distributions retain the above copyright notice and this paragraph * in its entirety, and (2) distributions including binary code include * the above copyright notice and this paragraph in its entirety in * the documentation or other materials provided with the distribution. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. * * Original code by Hannes Gredler (hannes@gredler.at) */ /* \summary: DLT_JUNIPER_* printers */ #ifndef lint #else __RCSID("NetBSD: print-juniper.c,v 1.3 2007/07/25 06:31:32 dogcow Exp "); #endif #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include "netdissect.h" #include "addrtoname.h" #include "extract.h" #include "ppp.h" #include "llc.h" #include "nlpid.h" #include "ethertype.h" #include "atm.h" #define JUNIPER_BPF_OUT 0 /* Outgoing packet */ #define JUNIPER_BPF_IN 1 /* Incoming packet */ #define JUNIPER_BPF_PKT_IN 0x1 /* Incoming packet */ #define JUNIPER_BPF_NO_L2 0x2 /* L2 header stripped */ #define JUNIPER_BPF_IIF 0x4 /* IIF is valid */ #define JUNIPER_BPF_FILTER 0x40 /* BPF filtering is supported */ #define JUNIPER_BPF_EXT 0x80 /* extensions present */ #define JUNIPER_MGC_NUMBER 0x4d4743 /* = "MGC" */ #define JUNIPER_LSQ_COOKIE_RE (1 << 3) #define JUNIPER_LSQ_COOKIE_DIR (1 << 2) #define JUNIPER_LSQ_L3_PROTO_SHIFT 4 #define JUNIPER_LSQ_L3_PROTO_MASK (0x17 << JUNIPER_LSQ_L3_PROTO_SHIFT) #define JUNIPER_LSQ_L3_PROTO_IPV4 (0 << JUNIPER_LSQ_L3_PROTO_SHIFT) #define JUNIPER_LSQ_L3_PROTO_IPV6 (1 << JUNIPER_LSQ_L3_PROTO_SHIFT) #define JUNIPER_LSQ_L3_PROTO_MPLS (2 << JUNIPER_LSQ_L3_PROTO_SHIFT) #define JUNIPER_LSQ_L3_PROTO_ISO (3 << JUNIPER_LSQ_L3_PROTO_SHIFT) #define AS_PIC_COOKIE_LEN 8 #define JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE 1 #define JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE 2 #define JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE 3 #define JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE 4 #define JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE 5 static const struct tok juniper_ipsec_type_values[] = { { JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE, "ESP ENCR-AUTH" }, { JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE, "ESP ENCR-AH AUTH" }, { JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE, "ESP AUTH" }, { JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE, "AH AUTH" }, { JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE, "ESP ENCR" }, { 0, NULL} }; static const struct tok juniper_direction_values[] = { { JUNIPER_BPF_IN, "In"}, { JUNIPER_BPF_OUT, "Out"}, { 0, NULL} }; /* codepoints for encoding extensions to a .pcap file */ enum { JUNIPER_EXT_TLV_IFD_IDX = 1, JUNIPER_EXT_TLV_IFD_NAME = 2, JUNIPER_EXT_TLV_IFD_MEDIATYPE = 3, JUNIPER_EXT_TLV_IFL_IDX = 4, JUNIPER_EXT_TLV_IFL_UNIT = 5, JUNIPER_EXT_TLV_IFL_ENCAPS = 6, JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE = 7, JUNIPER_EXT_TLV_TTP_IFL_ENCAPS = 8 }; /* 1 byte type and 1-byte length */ #define JUNIPER_EXT_TLV_OVERHEAD 2U static const struct tok jnx_ext_tlv_values[] = { { JUNIPER_EXT_TLV_IFD_IDX, "Device Interface Index" }, { JUNIPER_EXT_TLV_IFD_NAME,"Device Interface Name" }, { JUNIPER_EXT_TLV_IFD_MEDIATYPE, "Device Media Type" }, { JUNIPER_EXT_TLV_IFL_IDX, "Logical Interface Index" }, { JUNIPER_EXT_TLV_IFL_UNIT,"Logical Unit Number" }, { JUNIPER_EXT_TLV_IFL_ENCAPS, "Logical Interface Encapsulation" }, { JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE, "TTP derived Device Media Type" }, { JUNIPER_EXT_TLV_TTP_IFL_ENCAPS, "TTP derived Logical Interface Encapsulation" }, { 0, NULL } }; static const struct tok jnx_flag_values[] = { { JUNIPER_BPF_EXT, "Ext" }, { JUNIPER_BPF_FILTER, "Filter" }, { JUNIPER_BPF_IIF, "IIF" }, { JUNIPER_BPF_NO_L2, "no-L2" }, { JUNIPER_BPF_PKT_IN, "In" }, { 0, NULL } }; #define JUNIPER_IFML_ETHER 1 #define JUNIPER_IFML_FDDI 2 #define JUNIPER_IFML_TOKENRING 3 #define JUNIPER_IFML_PPP 4 #define JUNIPER_IFML_FRAMERELAY 5 #define JUNIPER_IFML_CISCOHDLC 6 #define JUNIPER_IFML_SMDSDXI 7 #define JUNIPER_IFML_ATMPVC 8 #define JUNIPER_IFML_PPP_CCC 9 #define JUNIPER_IFML_FRAMERELAY_CCC 10 #define JUNIPER_IFML_IPIP 11 #define JUNIPER_IFML_GRE 12 #define JUNIPER_IFML_PIM 13 #define JUNIPER_IFML_PIMD 14 #define JUNIPER_IFML_CISCOHDLC_CCC 15 #define JUNIPER_IFML_VLAN_CCC 16 #define JUNIPER_IFML_MLPPP 17 #define JUNIPER_IFML_MLFR 18 #define JUNIPER_IFML_ML 19 #define JUNIPER_IFML_LSI 20 #define JUNIPER_IFML_DFE 21 #define JUNIPER_IFML_ATM_CELLRELAY_CCC 22 #define JUNIPER_IFML_CRYPTO 23 #define JUNIPER_IFML_GGSN 24 #define JUNIPER_IFML_LSI_PPP 25 #define JUNIPER_IFML_LSI_CISCOHDLC 26 #define JUNIPER_IFML_PPP_TCC 27 #define JUNIPER_IFML_FRAMERELAY_TCC 28 #define JUNIPER_IFML_CISCOHDLC_TCC 29 #define JUNIPER_IFML_ETHERNET_CCC 30 #define JUNIPER_IFML_VT 31 #define JUNIPER_IFML_EXTENDED_VLAN_CCC 32 #define JUNIPER_IFML_ETHER_OVER_ATM 33 #define JUNIPER_IFML_MONITOR 34 #define JUNIPER_IFML_ETHERNET_TCC 35 #define JUNIPER_IFML_VLAN_TCC 36 #define JUNIPER_IFML_EXTENDED_VLAN_TCC 37 #define JUNIPER_IFML_CONTROLLER 38 #define JUNIPER_IFML_MFR 39 #define JUNIPER_IFML_LS 40 #define JUNIPER_IFML_ETHERNET_VPLS 41 #define JUNIPER_IFML_ETHERNET_VLAN_VPLS 42 #define JUNIPER_IFML_ETHERNET_EXTENDED_VLAN_VPLS 43 #define JUNIPER_IFML_LT 44 #define JUNIPER_IFML_SERVICES 45 #define JUNIPER_IFML_ETHER_VPLS_OVER_ATM 46 #define JUNIPER_IFML_FR_PORT_CCC 47 #define JUNIPER_IFML_FRAMERELAY_EXT_CCC 48 #define JUNIPER_IFML_FRAMERELAY_EXT_TCC 49 #define JUNIPER_IFML_FRAMERELAY_FLEX 50 #define JUNIPER_IFML_GGSNI 51 #define JUNIPER_IFML_ETHERNET_FLEX 52 #define JUNIPER_IFML_COLLECTOR 53 #define JUNIPER_IFML_AGGREGATOR 54 #define JUNIPER_IFML_LAPD 55 #define JUNIPER_IFML_PPPOE 56 #define JUNIPER_IFML_PPP_SUBORDINATE 57 #define JUNIPER_IFML_CISCOHDLC_SUBORDINATE 58 #define JUNIPER_IFML_DFC 59 #define JUNIPER_IFML_PICPEER 60 static const struct tok juniper_ifmt_values[] = { { JUNIPER_IFML_ETHER, "Ethernet" }, { JUNIPER_IFML_FDDI, "FDDI" }, { JUNIPER_IFML_TOKENRING, "Token-Ring" }, { JUNIPER_IFML_PPP, "PPP" }, { JUNIPER_IFML_PPP_SUBORDINATE, "PPP-Subordinate" }, { JUNIPER_IFML_FRAMERELAY, "Frame-Relay" }, { JUNIPER_IFML_CISCOHDLC, "Cisco-HDLC" }, { JUNIPER_IFML_SMDSDXI, "SMDS-DXI" }, { JUNIPER_IFML_ATMPVC, "ATM-PVC" }, { JUNIPER_IFML_PPP_CCC, "PPP-CCC" }, { JUNIPER_IFML_FRAMERELAY_CCC, "Frame-Relay-CCC" }, { JUNIPER_IFML_FRAMERELAY_EXT_CCC, "Extended FR-CCC" }, { JUNIPER_IFML_IPIP, "IP-over-IP" }, { JUNIPER_IFML_GRE, "GRE" }, { JUNIPER_IFML_PIM, "PIM-Encapsulator" }, { JUNIPER_IFML_PIMD, "PIM-Decapsulator" }, { JUNIPER_IFML_CISCOHDLC_CCC, "Cisco-HDLC-CCC" }, { JUNIPER_IFML_VLAN_CCC, "VLAN-CCC" }, { JUNIPER_IFML_EXTENDED_VLAN_CCC, "Extended-VLAN-CCC" }, { JUNIPER_IFML_MLPPP, "Multilink-PPP" }, { JUNIPER_IFML_MLFR, "Multilink-FR" }, { JUNIPER_IFML_MFR, "Multilink-FR-UNI-NNI" }, { JUNIPER_IFML_ML, "Multilink" }, { JUNIPER_IFML_LS, "LinkService" }, { JUNIPER_IFML_LSI, "LSI" }, { JUNIPER_IFML_ATM_CELLRELAY_CCC, "ATM-CCC-Cell-Relay" }, { JUNIPER_IFML_CRYPTO, "IPSEC-over-IP" }, { JUNIPER_IFML_GGSN, "GGSN" }, { JUNIPER_IFML_PPP_TCC, "PPP-TCC" }, { JUNIPER_IFML_FRAMERELAY_TCC, "Frame-Relay-TCC" }, { JUNIPER_IFML_FRAMERELAY_EXT_TCC, "Extended FR-TCC" }, { JUNIPER_IFML_CISCOHDLC_TCC, "Cisco-HDLC-TCC" }, { JUNIPER_IFML_ETHERNET_CCC, "Ethernet-CCC" }, { JUNIPER_IFML_VT, "VPN-Loopback-tunnel" }, { JUNIPER_IFML_ETHER_OVER_ATM, "Ethernet-over-ATM" }, { JUNIPER_IFML_ETHER_VPLS_OVER_ATM, "Ethernet-VPLS-over-ATM" }, { JUNIPER_IFML_MONITOR, "Monitor" }, { JUNIPER_IFML_ETHERNET_TCC, "Ethernet-TCC" }, { JUNIPER_IFML_VLAN_TCC, "VLAN-TCC" }, { JUNIPER_IFML_EXTENDED_VLAN_TCC, "Extended-VLAN-TCC" }, { JUNIPER_IFML_CONTROLLER, "Controller" }, { JUNIPER_IFML_ETHERNET_VPLS, "VPLS" }, { JUNIPER_IFML_ETHERNET_VLAN_VPLS, "VLAN-VPLS" }, { JUNIPER_IFML_ETHERNET_EXTENDED_VLAN_VPLS, "Extended-VLAN-VPLS" }, { JUNIPER_IFML_LT, "Logical-tunnel" }, { JUNIPER_IFML_SERVICES, "General-Services" }, { JUNIPER_IFML_PPPOE, "PPPoE" }, { JUNIPER_IFML_ETHERNET_FLEX, "Flexible-Ethernet-Services" }, { JUNIPER_IFML_FRAMERELAY_FLEX, "Flexible-FrameRelay" }, { JUNIPER_IFML_COLLECTOR, "Flow-collection" }, { JUNIPER_IFML_PICPEER, "PIC Peer" }, { JUNIPER_IFML_DFC, "Dynamic-Flow-Capture" }, {0, NULL} }; #define JUNIPER_IFLE_ATM_SNAP 2 #define JUNIPER_IFLE_ATM_NLPID 3 #define JUNIPER_IFLE_ATM_VCMUX 4 #define JUNIPER_IFLE_ATM_LLC 5 #define JUNIPER_IFLE_ATM_PPP_VCMUX 6 #define JUNIPER_IFLE_ATM_PPP_LLC 7 #define JUNIPER_IFLE_ATM_PPP_FUNI 8 #define JUNIPER_IFLE_ATM_CCC 9 #define JUNIPER_IFLE_FR_NLPID 10 #define JUNIPER_IFLE_FR_SNAP 11 #define JUNIPER_IFLE_FR_PPP 12 #define JUNIPER_IFLE_FR_CCC 13 #define JUNIPER_IFLE_ENET2 14 #define JUNIPER_IFLE_IEEE8023_SNAP 15 #define JUNIPER_IFLE_IEEE8023_LLC 16 #define JUNIPER_IFLE_PPP 17 #define JUNIPER_IFLE_CISCOHDLC 18 #define JUNIPER_IFLE_PPP_CCC 19 #define JUNIPER_IFLE_IPIP_NULL 20 #define JUNIPER_IFLE_PIM_NULL 21 #define JUNIPER_IFLE_GRE_NULL 22 #define JUNIPER_IFLE_GRE_PPP 23 #define JUNIPER_IFLE_PIMD_DECAPS 24 #define JUNIPER_IFLE_CISCOHDLC_CCC 25 #define JUNIPER_IFLE_ATM_CISCO_NLPID 26 #define JUNIPER_IFLE_VLAN_CCC 27 #define JUNIPER_IFLE_MLPPP 28 #define JUNIPER_IFLE_MLFR 29 #define JUNIPER_IFLE_LSI_NULL 30 #define JUNIPER_IFLE_AGGREGATE_UNUSED 31 #define JUNIPER_IFLE_ATM_CELLRELAY_CCC 32 #define JUNIPER_IFLE_CRYPTO 33 #define JUNIPER_IFLE_GGSN 34 #define JUNIPER_IFLE_ATM_TCC 35 #define JUNIPER_IFLE_FR_TCC 36 #define JUNIPER_IFLE_PPP_TCC 37 #define JUNIPER_IFLE_CISCOHDLC_TCC 38 #define JUNIPER_IFLE_ETHERNET_CCC 39 #define JUNIPER_IFLE_VT 40 #define JUNIPER_IFLE_ATM_EOA_LLC 41 #define JUNIPER_IFLE_EXTENDED_VLAN_CCC 42 #define JUNIPER_IFLE_ATM_SNAP_TCC 43 #define JUNIPER_IFLE_MONITOR 44 #define JUNIPER_IFLE_ETHERNET_TCC 45 #define JUNIPER_IFLE_VLAN_TCC 46 #define JUNIPER_IFLE_EXTENDED_VLAN_TCC 47 #define JUNIPER_IFLE_MFR 48 #define JUNIPER_IFLE_ETHERNET_VPLS 49 #define JUNIPER_IFLE_ETHERNET_VLAN_VPLS 50 #define JUNIPER_IFLE_ETHERNET_EXTENDED_VLAN_VPLS 51 #define JUNIPER_IFLE_SERVICES 52 #define JUNIPER_IFLE_ATM_ETHER_VPLS_ATM_LLC 53 #define JUNIPER_IFLE_FR_PORT_CCC 54 #define JUNIPER_IFLE_ATM_MLPPP_LLC 55 #define JUNIPER_IFLE_ATM_EOA_CCC 56 #define JUNIPER_IFLE_LT_VLAN 57 #define JUNIPER_IFLE_COLLECTOR 58 #define JUNIPER_IFLE_AGGREGATOR 59 #define JUNIPER_IFLE_LAPD 60 #define JUNIPER_IFLE_ATM_PPPOE_LLC 61 #define JUNIPER_IFLE_ETHERNET_PPPOE 62 #define JUNIPER_IFLE_PPPOE 63 #define JUNIPER_IFLE_PPP_SUBORDINATE 64 #define JUNIPER_IFLE_CISCOHDLC_SUBORDINATE 65 #define JUNIPER_IFLE_DFC 66 #define JUNIPER_IFLE_PICPEER 67 static const struct tok juniper_ifle_values[] = { { JUNIPER_IFLE_AGGREGATOR, "Aggregator" }, { JUNIPER_IFLE_ATM_CCC, "CCC over ATM" }, { JUNIPER_IFLE_ATM_CELLRELAY_CCC, "ATM CCC Cell Relay" }, { JUNIPER_IFLE_ATM_CISCO_NLPID, "CISCO compatible NLPID" }, { JUNIPER_IFLE_ATM_EOA_CCC, "Ethernet over ATM CCC" }, { JUNIPER_IFLE_ATM_EOA_LLC, "Ethernet over ATM LLC" }, { JUNIPER_IFLE_ATM_ETHER_VPLS_ATM_LLC, "Ethernet VPLS over ATM LLC" }, { JUNIPER_IFLE_ATM_LLC, "ATM LLC" }, { JUNIPER_IFLE_ATM_MLPPP_LLC, "MLPPP over ATM LLC" }, { JUNIPER_IFLE_ATM_NLPID, "ATM NLPID" }, { JUNIPER_IFLE_ATM_PPPOE_LLC, "PPPoE over ATM LLC" }, { JUNIPER_IFLE_ATM_PPP_FUNI, "PPP over FUNI" }, { JUNIPER_IFLE_ATM_PPP_LLC, "PPP over ATM LLC" }, { JUNIPER_IFLE_ATM_PPP_VCMUX, "PPP over ATM VCMUX" }, { JUNIPER_IFLE_ATM_SNAP, "ATM SNAP" }, { JUNIPER_IFLE_ATM_SNAP_TCC, "ATM SNAP TCC" }, { JUNIPER_IFLE_ATM_TCC, "ATM VCMUX TCC" }, { JUNIPER_IFLE_ATM_VCMUX, "ATM VCMUX" }, { JUNIPER_IFLE_CISCOHDLC, "C-HDLC" }, { JUNIPER_IFLE_CISCOHDLC_CCC, "C-HDLC CCC" }, { JUNIPER_IFLE_CISCOHDLC_SUBORDINATE, "C-HDLC via dialer" }, { JUNIPER_IFLE_CISCOHDLC_TCC, "C-HDLC TCC" }, { JUNIPER_IFLE_COLLECTOR, "Collector" }, { JUNIPER_IFLE_CRYPTO, "Crypto" }, { JUNIPER_IFLE_ENET2, "Ethernet" }, { JUNIPER_IFLE_ETHERNET_CCC, "Ethernet CCC" }, { JUNIPER_IFLE_ETHERNET_EXTENDED_VLAN_VPLS, "Extended VLAN VPLS" }, { JUNIPER_IFLE_ETHERNET_PPPOE, "PPPoE over Ethernet" }, { JUNIPER_IFLE_ETHERNET_TCC, "Ethernet TCC" }, { JUNIPER_IFLE_ETHERNET_VLAN_VPLS, "VLAN VPLS" }, { JUNIPER_IFLE_ETHERNET_VPLS, "VPLS" }, { JUNIPER_IFLE_EXTENDED_VLAN_CCC, "Extended VLAN CCC" }, { JUNIPER_IFLE_EXTENDED_VLAN_TCC, "Extended VLAN TCC" }, { JUNIPER_IFLE_FR_CCC, "FR CCC" }, { JUNIPER_IFLE_FR_NLPID, "FR NLPID" }, { JUNIPER_IFLE_FR_PORT_CCC, "FR CCC" }, { JUNIPER_IFLE_FR_PPP, "FR PPP" }, { JUNIPER_IFLE_FR_SNAP, "FR SNAP" }, { JUNIPER_IFLE_FR_TCC, "FR TCC" }, { JUNIPER_IFLE_GGSN, "GGSN" }, { JUNIPER_IFLE_GRE_NULL, "GRE NULL" }, { JUNIPER_IFLE_GRE_PPP, "PPP over GRE" }, { JUNIPER_IFLE_IPIP_NULL, "IPIP" }, { JUNIPER_IFLE_LAPD, "LAPD" }, { JUNIPER_IFLE_LSI_NULL, "LSI Null" }, { JUNIPER_IFLE_LT_VLAN, "LT VLAN" }, { JUNIPER_IFLE_MFR, "MFR" }, { JUNIPER_IFLE_MLFR, "MLFR" }, { JUNIPER_IFLE_MLPPP, "MLPPP" }, { JUNIPER_IFLE_MONITOR, "Monitor" }, { JUNIPER_IFLE_PIMD_DECAPS, "PIMd" }, { JUNIPER_IFLE_PIM_NULL, "PIM Null" }, { JUNIPER_IFLE_PPP, "PPP" }, { JUNIPER_IFLE_PPPOE, "PPPoE" }, { JUNIPER_IFLE_PPP_CCC, "PPP CCC" }, { JUNIPER_IFLE_PPP_SUBORDINATE, "" }, { JUNIPER_IFLE_PPP_TCC, "PPP TCC" }, { JUNIPER_IFLE_SERVICES, "General Services" }, { JUNIPER_IFLE_VLAN_CCC, "VLAN CCC" }, { JUNIPER_IFLE_VLAN_TCC, "VLAN TCC" }, { JUNIPER_IFLE_VT, "VT" }, {0, NULL} }; struct juniper_cookie_table_t { uint32_t pictype; /* pic type */ uint8_t cookie_len; /* cookie len */ const char *s; /* pic name */ }; static const struct juniper_cookie_table_t juniper_cookie_table[] = { #ifdef DLT_JUNIPER_ATM1 { DLT_JUNIPER_ATM1, 4, "ATM1"}, #endif #ifdef DLT_JUNIPER_ATM2 { DLT_JUNIPER_ATM2, 8, "ATM2"}, #endif #ifdef DLT_JUNIPER_MLPPP { DLT_JUNIPER_MLPPP, 2, "MLPPP"}, #endif #ifdef DLT_JUNIPER_MLFR { DLT_JUNIPER_MLFR, 2, "MLFR"}, #endif #ifdef DLT_JUNIPER_MFR { DLT_JUNIPER_MFR, 4, "MFR"}, #endif #ifdef DLT_JUNIPER_PPPOE { DLT_JUNIPER_PPPOE, 0, "PPPoE"}, #endif #ifdef DLT_JUNIPER_PPPOE_ATM { DLT_JUNIPER_PPPOE_ATM, 0, "PPPoE ATM"}, #endif #ifdef DLT_JUNIPER_GGSN { DLT_JUNIPER_GGSN, 8, "GGSN"}, #endif #ifdef DLT_JUNIPER_MONITOR { DLT_JUNIPER_MONITOR, 8, "MONITOR"}, #endif #ifdef DLT_JUNIPER_SERVICES { DLT_JUNIPER_SERVICES, 8, "AS"}, #endif #ifdef DLT_JUNIPER_ES { DLT_JUNIPER_ES, 0, "ES"}, #endif { 0, 0, NULL } }; struct juniper_l2info_t { uint32_t length; uint32_t caplen; uint32_t pictype; uint8_t direction; uint8_t header_len; uint8_t cookie_len; uint8_t cookie_type; uint8_t cookie[8]; uint8_t bundle; uint16_t proto; uint8_t flags; }; #define LS_COOKIE_ID 0x54 #define AS_COOKIE_ID 0x47 #define LS_MLFR_COOKIE_LEN 4 #define ML_MLFR_COOKIE_LEN 2 #define LS_MFR_COOKIE_LEN 6 #define ATM1_COOKIE_LEN 4 #define ATM2_COOKIE_LEN 8 #define ATM2_PKT_TYPE_MASK 0x70 #define ATM2_GAP_COUNT_MASK 0x3F #define JUNIPER_PROTO_NULL 1 #define JUNIPER_PROTO_IPV4 2 #define JUNIPER_PROTO_IPV6 6 #define MFR_BE_MASK 0xc0 static const struct tok juniper_protocol_values[] = { { JUNIPER_PROTO_NULL, "Null" }, { JUNIPER_PROTO_IPV4, "IPv4" }, { JUNIPER_PROTO_IPV6, "IPv6" }, { 0, NULL} }; static int ip_heuristic_guess(netdissect_options *, register const u_char *, u_int); static int juniper_ppp_heuristic_guess(netdissect_options *, register const u_char *, u_int); static int juniper_parse_header(netdissect_options *, const u_char *, const struct pcap_pkthdr *, struct juniper_l2info_t *); #ifdef DLT_JUNIPER_GGSN u_int juniper_ggsn_print(netdissect_options *ndo, const struct pcap_pkthdr *h, register const u_char *p) { struct juniper_l2info_t l2info; struct juniper_ggsn_header { uint8_t svc_id; uint8_t flags_len; uint8_t proto; uint8_t flags; uint8_t vlan_id[2]; uint8_t res[2]; }; const struct juniper_ggsn_header *gh; l2info.pictype = DLT_JUNIPER_GGSN; if (juniper_parse_header(ndo, p, h, &l2info) == 0) return l2info.header_len; p+=l2info.header_len; gh = (struct juniper_ggsn_header *)&l2info.cookie; ND_TCHECK(*gh); if (ndo->ndo_eflag) { ND_PRINT((ndo, "proto %s (%u), vlan %u: ", tok2str(juniper_protocol_values,"Unknown",gh->proto), gh->proto, EXTRACT_16BITS(&gh->vlan_id[0]))); } switch (gh->proto) { case JUNIPER_PROTO_IPV4: ip_print(ndo, p, l2info.length); break; case JUNIPER_PROTO_IPV6: ip6_print(ndo, p, l2info.length); break; default: if (!ndo->ndo_eflag) ND_PRINT((ndo, "unknown GGSN proto (%u)", gh->proto)); } return l2info.header_len; trunc: ND_PRINT((ndo, "[|juniper_services]")); return l2info.header_len; } #endif #ifdef DLT_JUNIPER_ES u_int juniper_es_print(netdissect_options *ndo, const struct pcap_pkthdr *h, register const u_char *p) { struct juniper_l2info_t l2info; struct juniper_ipsec_header { uint8_t sa_index[2]; uint8_t ttl; uint8_t type; uint8_t spi[4]; uint8_t src_ip[4]; uint8_t dst_ip[4]; }; u_int rewrite_len,es_type_bundle; const struct juniper_ipsec_header *ih; l2info.pictype = DLT_JUNIPER_ES; if (juniper_parse_header(ndo, p, h, &l2info) == 0) return l2info.header_len; p+=l2info.header_len; ih = (const struct juniper_ipsec_header *)p; ND_TCHECK(*ih); switch (ih->type) { case JUNIPER_IPSEC_O_ESP_ENCRYPT_ESP_AUTHEN_TYPE: case JUNIPER_IPSEC_O_ESP_ENCRYPT_AH_AUTHEN_TYPE: rewrite_len = 0; es_type_bundle = 1; break; case JUNIPER_IPSEC_O_ESP_AUTHENTICATION_TYPE: case JUNIPER_IPSEC_O_AH_AUTHENTICATION_TYPE: case JUNIPER_IPSEC_O_ESP_ENCRYPTION_TYPE: rewrite_len = 16; es_type_bundle = 0; break; default: ND_PRINT((ndo, "ES Invalid type %u, length %u", ih->type, l2info.length)); return l2info.header_len; } l2info.length-=rewrite_len; p+=rewrite_len; if (ndo->ndo_eflag) { if (!es_type_bundle) { ND_PRINT((ndo, "ES SA, index %u, ttl %u type %s (%u), spi %u, Tunnel %s > %s, length %u\n", EXTRACT_16BITS(&ih->sa_index), ih->ttl, tok2str(juniper_ipsec_type_values,"Unknown",ih->type), ih->type, EXTRACT_32BITS(&ih->spi), ipaddr_string(ndo, &ih->src_ip), ipaddr_string(ndo, &ih->dst_ip), l2info.length)); } else { ND_PRINT((ndo, "ES SA, index %u, ttl %u type %s (%u), length %u\n", EXTRACT_16BITS(&ih->sa_index), ih->ttl, tok2str(juniper_ipsec_type_values,"Unknown",ih->type), ih->type, l2info.length)); } } ip_print(ndo, p, l2info.length); return l2info.header_len; trunc: ND_PRINT((ndo, "[|juniper_services]")); return l2info.header_len; } #endif #ifdef DLT_JUNIPER_MONITOR u_int juniper_monitor_print(netdissect_options *ndo, const struct pcap_pkthdr *h, register const u_char *p) { struct juniper_l2info_t l2info; struct juniper_monitor_header { uint8_t pkt_type; uint8_t padding; uint8_t iif[2]; uint8_t service_id[4]; }; const struct juniper_monitor_header *mh; l2info.pictype = DLT_JUNIPER_MONITOR; if (juniper_parse_header(ndo, p, h, &l2info) == 0) return l2info.header_len; p+=l2info.header_len; mh = (const struct juniper_monitor_header *)p; ND_TCHECK(*mh); if (ndo->ndo_eflag) ND_PRINT((ndo, "service-id %u, iif %u, pkt-type %u: ", EXTRACT_32BITS(&mh->service_id), EXTRACT_16BITS(&mh->iif), mh->pkt_type)); /* no proto field - lets guess by first byte of IP header*/ ip_heuristic_guess (ndo, p, l2info.length); return l2info.header_len; trunc: ND_PRINT((ndo, "[|juniper_services]")); return l2info.header_len; } #endif #ifdef DLT_JUNIPER_SERVICES u_int juniper_services_print(netdissect_options *ndo, const struct pcap_pkthdr *h, register const u_char *p) { struct juniper_l2info_t l2info; struct juniper_services_header { uint8_t svc_id; uint8_t flags_len; uint8_t svc_set_id[2]; uint8_t dir_iif[4]; }; const struct juniper_services_header *sh; l2info.pictype = DLT_JUNIPER_SERVICES; if (juniper_parse_header(ndo, p, h, &l2info) == 0) return l2info.header_len; p+=l2info.header_len; sh = (const struct juniper_services_header *)p; ND_TCHECK(*sh); if (ndo->ndo_eflag) ND_PRINT((ndo, "service-id %u flags 0x%02x service-set-id 0x%04x iif %u: ", sh->svc_id, sh->flags_len, EXTRACT_16BITS(&sh->svc_set_id), EXTRACT_24BITS(&sh->dir_iif[1]))); /* no proto field - lets guess by first byte of IP header*/ ip_heuristic_guess (ndo, p, l2info.length); return l2info.header_len; trunc: ND_PRINT((ndo, "[|juniper_services]")); return l2info.header_len; } #endif #ifdef DLT_JUNIPER_PPPOE u_int juniper_pppoe_print(netdissect_options *ndo, const struct pcap_pkthdr *h, register const u_char *p) { struct juniper_l2info_t l2info; l2info.pictype = DLT_JUNIPER_PPPOE; if (juniper_parse_header(ndo, p, h, &l2info) == 0) return l2info.header_len; p+=l2info.header_len; /* this DLT contains nothing but raw ethernet frames */ ether_print(ndo, p, l2info.length, l2info.caplen, NULL, NULL); return l2info.header_len; } #endif #ifdef DLT_JUNIPER_ETHER u_int juniper_ether_print(netdissect_options *ndo, const struct pcap_pkthdr *h, register const u_char *p) { struct juniper_l2info_t l2info; l2info.pictype = DLT_JUNIPER_ETHER; if (juniper_parse_header(ndo, p, h, &l2info) == 0) return l2info.header_len; p+=l2info.header_len; /* this DLT contains nothing but raw Ethernet frames */ ether_print(ndo, p, l2info.length, l2info.caplen, NULL, NULL); return l2info.header_len; } #endif #ifdef DLT_JUNIPER_PPP u_int juniper_ppp_print(netdissect_options *ndo, const struct pcap_pkthdr *h, register const u_char *p) { struct juniper_l2info_t l2info; l2info.pictype = DLT_JUNIPER_PPP; if (juniper_parse_header(ndo, p, h, &l2info) == 0) return l2info.header_len; p+=l2info.header_len; /* this DLT contains nothing but raw ppp frames */ ppp_print(ndo, p, l2info.length); return l2info.header_len; } #endif #ifdef DLT_JUNIPER_FRELAY u_int juniper_frelay_print(netdissect_options *ndo, const struct pcap_pkthdr *h, register const u_char *p) { struct juniper_l2info_t l2info; l2info.pictype = DLT_JUNIPER_FRELAY; if (juniper_parse_header(ndo, p, h, &l2info) == 0) return l2info.header_len; p+=l2info.header_len; /* this DLT contains nothing but raw frame-relay frames */ fr_print(ndo, p, l2info.length); return l2info.header_len; } #endif #ifdef DLT_JUNIPER_CHDLC u_int juniper_chdlc_print(netdissect_options *ndo, const struct pcap_pkthdr *h, register const u_char *p) { struct juniper_l2info_t l2info; l2info.pictype = DLT_JUNIPER_CHDLC; if (juniper_parse_header(ndo, p, h, &l2info) == 0) return l2info.header_len; p+=l2info.header_len; /* this DLT contains nothing but raw c-hdlc frames */ chdlc_print(ndo, p, l2info.length); return l2info.header_len; } #endif #ifdef DLT_JUNIPER_PPPOE_ATM u_int juniper_pppoe_atm_print(netdissect_options *ndo, const struct pcap_pkthdr *h, register const u_char *p) { struct juniper_l2info_t l2info; uint16_t extracted_ethertype; l2info.pictype = DLT_JUNIPER_PPPOE_ATM; if (juniper_parse_header(ndo, p, h, &l2info) == 0) return l2info.header_len; p+=l2info.header_len; ND_TCHECK2(p[0], 2); extracted_ethertype = EXTRACT_16BITS(p); /* this DLT contains nothing but raw PPPoE frames, * prepended with a type field*/ if (ethertype_print(ndo, extracted_ethertype, p+ETHERTYPE_LEN, l2info.length-ETHERTYPE_LEN, l2info.caplen-ETHERTYPE_LEN, NULL, NULL) == 0) /* ether_type not known, probably it wasn't one */ ND_PRINT((ndo, "unknown ethertype 0x%04x", extracted_ethertype)); return l2info.header_len; trunc: ND_PRINT((ndo, "[|juniper_pppoe_atm]")); return l2info.header_len; } #endif #ifdef DLT_JUNIPER_MLPPP u_int juniper_mlppp_print(netdissect_options *ndo, const struct pcap_pkthdr *h, register const u_char *p) { struct juniper_l2info_t l2info; l2info.pictype = DLT_JUNIPER_MLPPP; if (juniper_parse_header(ndo, p, h, &l2info) == 0) return l2info.header_len; /* suppress Bundle-ID if frame was captured on a child-link * best indicator if the cookie looks like a proto */ if (ndo->ndo_eflag && EXTRACT_16BITS(&l2info.cookie) != PPP_OSI && EXTRACT_16BITS(&l2info.cookie) != (PPP_ADDRESS << 8 | PPP_CONTROL)) ND_PRINT((ndo, "Bundle-ID %u: ", l2info.bundle)); p+=l2info.header_len; /* first try the LSQ protos */ switch(l2info.proto) { case JUNIPER_LSQ_L3_PROTO_IPV4: /* IP traffic going to the RE would not have a cookie * -> this must be incoming IS-IS over PPP */ if (l2info.cookie[4] == (JUNIPER_LSQ_COOKIE_RE|JUNIPER_LSQ_COOKIE_DIR)) ppp_print(ndo, p, l2info.length); else ip_print(ndo, p, l2info.length); return l2info.header_len; case JUNIPER_LSQ_L3_PROTO_IPV6: ip6_print(ndo, p,l2info.length); return l2info.header_len; case JUNIPER_LSQ_L3_PROTO_MPLS: mpls_print(ndo, p, l2info.length); return l2info.header_len; case JUNIPER_LSQ_L3_PROTO_ISO: isoclns_print(ndo, p, l2info.length); return l2info.header_len; default: break; } /* zero length cookie ? */ switch (EXTRACT_16BITS(&l2info.cookie)) { case PPP_OSI: ppp_print(ndo, p - 2, l2info.length + 2); break; case (PPP_ADDRESS << 8 | PPP_CONTROL): /* fall through */ default: ppp_print(ndo, p, l2info.length); break; } return l2info.header_len; } #endif #ifdef DLT_JUNIPER_MFR u_int juniper_mfr_print(netdissect_options *ndo, const struct pcap_pkthdr *h, register const u_char *p) { struct juniper_l2info_t l2info; memset(&l2info, 0, sizeof(l2info)); l2info.pictype = DLT_JUNIPER_MFR; if (juniper_parse_header(ndo, p, h, &l2info) == 0) return l2info.header_len; p+=l2info.header_len; /* child-link ? */ if (l2info.cookie_len == 0) { mfr_print(ndo, p, l2info.length); return l2info.header_len; } /* first try the LSQ protos */ if (l2info.cookie_len == AS_PIC_COOKIE_LEN) { switch(l2info.proto) { case JUNIPER_LSQ_L3_PROTO_IPV4: ip_print(ndo, p, l2info.length); return l2info.header_len; case JUNIPER_LSQ_L3_PROTO_IPV6: ip6_print(ndo, p,l2info.length); return l2info.header_len; case JUNIPER_LSQ_L3_PROTO_MPLS: mpls_print(ndo, p, l2info.length); return l2info.header_len; case JUNIPER_LSQ_L3_PROTO_ISO: isoclns_print(ndo, p, l2info.length); return l2info.header_len; default: break; } return l2info.header_len; } /* suppress Bundle-ID if frame was captured on a child-link */ if (ndo->ndo_eflag && EXTRACT_32BITS(l2info.cookie) != 1) ND_PRINT((ndo, "Bundle-ID %u, ", l2info.bundle)); switch (l2info.proto) { case (LLCSAP_ISONS<<8 | LLCSAP_ISONS): isoclns_print(ndo, p + 1, l2info.length - 1); break; case (LLC_UI<<8 | NLPID_Q933): case (LLC_UI<<8 | NLPID_IP): case (LLC_UI<<8 | NLPID_IP6): /* pass IP{4,6} to the OSI layer for proper link-layer printing */ isoclns_print(ndo, p - 1, l2info.length + 1); break; default: ND_PRINT((ndo, "unknown protocol 0x%04x, length %u", l2info.proto, l2info.length)); } return l2info.header_len; } #endif #ifdef DLT_JUNIPER_MLFR u_int juniper_mlfr_print(netdissect_options *ndo, const struct pcap_pkthdr *h, register const u_char *p) { struct juniper_l2info_t l2info; l2info.pictype = DLT_JUNIPER_MLFR; if (juniper_parse_header(ndo, p, h, &l2info) == 0) return l2info.header_len; p+=l2info.header_len; /* suppress Bundle-ID if frame was captured on a child-link */ if (ndo->ndo_eflag && EXTRACT_32BITS(l2info.cookie) != 1) ND_PRINT((ndo, "Bundle-ID %u, ", l2info.bundle)); switch (l2info.proto) { case (LLC_UI): case (LLC_UI<<8): isoclns_print(ndo, p, l2info.length); break; case (LLC_UI<<8 | NLPID_Q933): case (LLC_UI<<8 | NLPID_IP): case (LLC_UI<<8 | NLPID_IP6): /* pass IP{4,6} to the OSI layer for proper link-layer printing */ isoclns_print(ndo, p - 1, l2info.length + 1); break; default: ND_PRINT((ndo, "unknown protocol 0x%04x, length %u", l2info.proto, l2info.length)); } return l2info.header_len; } #endif /* * ATM1 PIC cookie format * * +-----+-------------------------+-------------------------------+ * |fmtid| vc index | channel ID | * +-----+-------------------------+-------------------------------+ */ #ifdef DLT_JUNIPER_ATM1 u_int juniper_atm1_print(netdissect_options *ndo, const struct pcap_pkthdr *h, register const u_char *p) { int llc_hdrlen; struct juniper_l2info_t l2info; l2info.pictype = DLT_JUNIPER_ATM1; if (juniper_parse_header(ndo, p, h, &l2info) == 0) return l2info.header_len; p+=l2info.header_len; if (l2info.cookie[0] == 0x80) { /* OAM cell ? */ oam_print(ndo, p, l2info.length, ATM_OAM_NOHEC); return l2info.header_len; } ND_TCHECK2(p[0], 3); if (EXTRACT_24BITS(p) == 0xfefe03 || /* NLPID encaps ? */ EXTRACT_24BITS(p) == 0xaaaa03) { /* SNAP encaps ? */ llc_hdrlen = llc_print(ndo, p, l2info.length, l2info.caplen, NULL, NULL); if (llc_hdrlen > 0) return l2info.header_len; } if (p[0] == 0x03) { /* Cisco style NLPID encaps ? */ isoclns_print(ndo, p + 1, l2info.length - 1); /* FIXME check if frame was recognized */ return l2info.header_len; } if (ip_heuristic_guess(ndo, p, l2info.length) != 0) /* last try - vcmux encaps ? */ return l2info.header_len; return l2info.header_len; trunc: ND_PRINT((ndo, "[|juniper_atm1]")); return l2info.header_len; } #endif /* * ATM2 PIC cookie format * * +-------------------------------+---------+---+-----+-----------+ * | channel ID | reserv |AAL| CCRQ| gap cnt | * +-------------------------------+---------+---+-----+-----------+ */ #ifdef DLT_JUNIPER_ATM2 u_int juniper_atm2_print(netdissect_options *ndo, const struct pcap_pkthdr *h, register const u_char *p) { int llc_hdrlen; struct juniper_l2info_t l2info; l2info.pictype = DLT_JUNIPER_ATM2; if (juniper_parse_header(ndo, p, h, &l2info) == 0) return l2info.header_len; p+=l2info.header_len; if (l2info.cookie[7] & ATM2_PKT_TYPE_MASK) { /* OAM cell ? */ oam_print(ndo, p, l2info.length, ATM_OAM_NOHEC); return l2info.header_len; } ND_TCHECK2(p[0], 3); if (EXTRACT_24BITS(p) == 0xfefe03 || /* NLPID encaps ? */ EXTRACT_24BITS(p) == 0xaaaa03) { /* SNAP encaps ? */ llc_hdrlen = llc_print(ndo, p, l2info.length, l2info.caplen, NULL, NULL); if (llc_hdrlen > 0) return l2info.header_len; } if (l2info.direction != JUNIPER_BPF_PKT_IN && /* ether-over-1483 encaps ? */ (EXTRACT_32BITS(l2info.cookie) & ATM2_GAP_COUNT_MASK)) { ether_print(ndo, p, l2info.length, l2info.caplen, NULL, NULL); return l2info.header_len; } if (p[0] == 0x03) { /* Cisco style NLPID encaps ? */ isoclns_print(ndo, p + 1, l2info.length - 1); /* FIXME check if frame was recognized */ return l2info.header_len; } if(juniper_ppp_heuristic_guess(ndo, p, l2info.length) != 0) /* PPPoA vcmux encaps ? */ return l2info.header_len; if (ip_heuristic_guess(ndo, p, l2info.length) != 0) /* last try - vcmux encaps ? */ return l2info.header_len; return l2info.header_len; trunc: ND_PRINT((ndo, "[|juniper_atm2]")); return l2info.header_len; } #endif /* try to guess, based on all PPP protos that are supported in * a juniper router if the payload data is encapsulated using PPP */ static int juniper_ppp_heuristic_guess(netdissect_options *ndo, register const u_char *p, u_int length) { switch(EXTRACT_16BITS(p)) { case PPP_IP : case PPP_OSI : case PPP_MPLS_UCAST : case PPP_MPLS_MCAST : case PPP_IPCP : case PPP_OSICP : case PPP_MPLSCP : case PPP_LCP : case PPP_PAP : case PPP_CHAP : case PPP_ML : case PPP_IPV6 : case PPP_IPV6CP : ppp_print(ndo, p, length); break; default: return 0; /* did not find a ppp header */ break; } return 1; /* we printed a ppp packet */ } static int ip_heuristic_guess(netdissect_options *ndo, register const u_char *p, u_int length) { switch(p[0]) { case 0x45: case 0x46: case 0x47: case 0x48: case 0x49: case 0x4a: case 0x4b: case 0x4c: case 0x4d: case 0x4e: case 0x4f: ip_print(ndo, p, length); break; case 0x60: case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66: case 0x67: case 0x68: case 0x69: case 0x6a: case 0x6b: case 0x6c: case 0x6d: case 0x6e: case 0x6f: ip6_print(ndo, p, length); break; default: return 0; /* did not find a ip header */ break; } return 1; /* we printed an v4/v6 packet */ } static int juniper_read_tlv_value(const u_char *p, u_int tlv_type, u_int tlv_len) { int tlv_value; /* TLVs < 128 are little endian encoded */ if (tlv_type < 128) { switch (tlv_len) { case 1: tlv_value = *p; break; case 2: tlv_value = EXTRACT_LE_16BITS(p); break; case 3: tlv_value = EXTRACT_LE_24BITS(p); break; case 4: tlv_value = EXTRACT_LE_32BITS(p); break; default: tlv_value = -1; break; } } else { /* TLVs >= 128 are big endian encoded */ switch (tlv_len) { case 1: tlv_value = *p; break; case 2: tlv_value = EXTRACT_16BITS(p); break; case 3: tlv_value = EXTRACT_24BITS(p); break; case 4: tlv_value = EXTRACT_32BITS(p); break; default: tlv_value = -1; break; } } return tlv_value; } static int juniper_parse_header(netdissect_options *ndo, const u_char *p, const struct pcap_pkthdr *h, struct juniper_l2info_t *l2info) { const struct juniper_cookie_table_t *lp = juniper_cookie_table; u_int idx, jnx_ext_len, jnx_header_len = 0; uint8_t tlv_type,tlv_len; uint32_t control_word; int tlv_value; const u_char *tptr; l2info->header_len = 0; l2info->cookie_len = 0; l2info->proto = 0; l2info->length = h->len; l2info->caplen = h->caplen; ND_TCHECK2(p[0], 4); l2info->flags = p[3]; l2info->direction = p[3]&JUNIPER_BPF_PKT_IN; if (EXTRACT_24BITS(p) != JUNIPER_MGC_NUMBER) { /* magic number found ? */ ND_PRINT((ndo, "no magic-number found!")); return 0; } if (ndo->ndo_eflag) /* print direction */ ND_PRINT((ndo, "%3s ", tok2str(juniper_direction_values, "---", l2info->direction))); /* magic number + flags */ jnx_header_len = 4; if (ndo->ndo_vflag > 1) ND_PRINT((ndo, "\n\tJuniper PCAP Flags [%s]", bittok2str(jnx_flag_values, "none", l2info->flags))); /* extensions present ? - calculate how much bytes to skip */ if ((l2info->flags & JUNIPER_BPF_EXT ) == JUNIPER_BPF_EXT ) { tptr = p+jnx_header_len; /* ok to read extension length ? */ ND_TCHECK2(tptr[0], 2); jnx_ext_len = EXTRACT_16BITS(tptr); jnx_header_len += 2; tptr +=2; /* nail up the total length - * just in case something goes wrong * with TLV parsing */ jnx_header_len += jnx_ext_len; if (ndo->ndo_vflag > 1) ND_PRINT((ndo, ", PCAP Extension(s) total length %u", jnx_ext_len)); ND_TCHECK2(tptr[0], jnx_ext_len); while (jnx_ext_len > JUNIPER_EXT_TLV_OVERHEAD) { tlv_type = *(tptr++); tlv_len = *(tptr++); tlv_value = 0; /* sanity checks */ if (tlv_type == 0 || tlv_len == 0) break; if (tlv_len+JUNIPER_EXT_TLV_OVERHEAD > jnx_ext_len) goto trunc; if (ndo->ndo_vflag > 1) ND_PRINT((ndo, "\n\t %s Extension TLV #%u, length %u, value ", tok2str(jnx_ext_tlv_values,"Unknown",tlv_type), tlv_type, tlv_len)); tlv_value = juniper_read_tlv_value(tptr, tlv_type, tlv_len); switch (tlv_type) { case JUNIPER_EXT_TLV_IFD_NAME: /* FIXME */ break; case JUNIPER_EXT_TLV_IFD_MEDIATYPE: case JUNIPER_EXT_TLV_TTP_IFD_MEDIATYPE: if (tlv_value != -1) { if (ndo->ndo_vflag > 1) ND_PRINT((ndo, "%s (%u)", tok2str(juniper_ifmt_values, "Unknown", tlv_value), tlv_value)); } break; case JUNIPER_EXT_TLV_IFL_ENCAPS: case JUNIPER_EXT_TLV_TTP_IFL_ENCAPS: if (tlv_value != -1) { if (ndo->ndo_vflag > 1) ND_PRINT((ndo, "%s (%u)", tok2str(juniper_ifle_values, "Unknown", tlv_value), tlv_value)); } break; case JUNIPER_EXT_TLV_IFL_IDX: /* fall through */ case JUNIPER_EXT_TLV_IFL_UNIT: case JUNIPER_EXT_TLV_IFD_IDX: default: if (tlv_value != -1) { if (ndo->ndo_vflag > 1) ND_PRINT((ndo, "%u", tlv_value)); } break; } tptr+=tlv_len; jnx_ext_len -= tlv_len+JUNIPER_EXT_TLV_OVERHEAD; } if (ndo->ndo_vflag > 1) ND_PRINT((ndo, "\n\t-----original packet-----\n\t")); } if ((l2info->flags & JUNIPER_BPF_NO_L2 ) == JUNIPER_BPF_NO_L2 ) { if (ndo->ndo_eflag) ND_PRINT((ndo, "no-L2-hdr, ")); /* there is no link-layer present - * perform the v4/v6 heuristics * to figure out what it is */ ND_TCHECK2(p[jnx_header_len + 4], 1); if (ip_heuristic_guess(ndo, p + jnx_header_len + 4, l2info->length - (jnx_header_len + 4)) == 0) ND_PRINT((ndo, "no IP-hdr found!")); l2info->header_len=jnx_header_len+4; return 0; /* stop parsing the output further */ } l2info->header_len = jnx_header_len; p+=l2info->header_len; l2info->length -= l2info->header_len; l2info->caplen -= l2info->header_len; /* search through the cookie table and copy values matching for our PIC type */ ND_TCHECK(p[0]); while (lp->s != NULL) { if (lp->pictype == l2info->pictype) { l2info->cookie_len += lp->cookie_len; switch (p[0]) { case LS_COOKIE_ID: l2info->cookie_type = LS_COOKIE_ID; l2info->cookie_len += 2; break; case AS_COOKIE_ID: l2info->cookie_type = AS_COOKIE_ID; l2info->cookie_len = 8; break; default: l2info->bundle = l2info->cookie[0]; break; } #ifdef DLT_JUNIPER_MFR /* MFR child links don't carry cookies */ if (l2info->pictype == DLT_JUNIPER_MFR && (p[0] & MFR_BE_MASK) == MFR_BE_MASK) { l2info->cookie_len = 0; } #endif l2info->header_len += l2info->cookie_len; l2info->length -= l2info->cookie_len; l2info->caplen -= l2info->cookie_len; if (ndo->ndo_eflag) ND_PRINT((ndo, "%s-PIC, cookie-len %u", lp->s, l2info->cookie_len)); if (l2info->cookie_len > 8) { ND_PRINT((ndo, " (invalid)")); return 0; } if (l2info->cookie_len > 0) { ND_TCHECK2(p[0], l2info->cookie_len); if (ndo->ndo_eflag) ND_PRINT((ndo, ", cookie 0x")); for (idx = 0; idx < l2info->cookie_len; idx++) { l2info->cookie[idx] = p[idx]; /* copy cookie data */ if (ndo->ndo_eflag) ND_PRINT((ndo, "%02x", p[idx])); } } if (ndo->ndo_eflag) ND_PRINT((ndo, ": ")); /* print demarc b/w L2/L3*/ ND_TCHECK_16BITS(p+l2info->cookie_len); l2info->proto = EXTRACT_16BITS(p+l2info->cookie_len); break; } ++lp; } p+=l2info->cookie_len; /* DLT_ specific parsing */ switch(l2info->pictype) { #ifdef DLT_JUNIPER_MLPPP case DLT_JUNIPER_MLPPP: switch (l2info->cookie_type) { case LS_COOKIE_ID: l2info->bundle = l2info->cookie[1]; break; case AS_COOKIE_ID: l2info->bundle = (EXTRACT_16BITS(&l2info->cookie[6])>>3)&0xfff; l2info->proto = (l2info->cookie[5])&JUNIPER_LSQ_L3_PROTO_MASK; break; default: l2info->bundle = l2info->cookie[0]; break; } break; #endif #ifdef DLT_JUNIPER_MLFR case DLT_JUNIPER_MLFR: switch (l2info->cookie_type) { case LS_COOKIE_ID: ND_TCHECK2(p[0], 2); l2info->bundle = l2info->cookie[1]; l2info->proto = EXTRACT_16BITS(p); l2info->header_len += 2; l2info->length -= 2; l2info->caplen -= 2; break; case AS_COOKIE_ID: l2info->bundle = (EXTRACT_16BITS(&l2info->cookie[6])>>3)&0xfff; l2info->proto = (l2info->cookie[5])&JUNIPER_LSQ_L3_PROTO_MASK; break; default: l2info->bundle = l2info->cookie[0]; l2info->header_len += 2; l2info->length -= 2; l2info->caplen -= 2; break; } break; #endif #ifdef DLT_JUNIPER_MFR case DLT_JUNIPER_MFR: switch (l2info->cookie_type) { case LS_COOKIE_ID: ND_TCHECK2(p[0], 2); l2info->bundle = l2info->cookie[1]; l2info->proto = EXTRACT_16BITS(p); l2info->header_len += 2; l2info->length -= 2; l2info->caplen -= 2; break; case AS_COOKIE_ID: l2info->bundle = (EXTRACT_16BITS(&l2info->cookie[6])>>3)&0xfff; l2info->proto = (l2info->cookie[5])&JUNIPER_LSQ_L3_PROTO_MASK; break; default: l2info->bundle = l2info->cookie[0]; break; } break; #endif #ifdef DLT_JUNIPER_ATM2 case DLT_JUNIPER_ATM2: ND_TCHECK2(p[0], 4); /* ATM cell relay control word present ? */ if (l2info->cookie[7] & ATM2_PKT_TYPE_MASK) { control_word = EXTRACT_32BITS(p); /* some control word heuristics */ switch(control_word) { case 0: /* zero control word */ case 0x08000000: /* < JUNOS 7.4 control-word */ case 0x08380000: /* cntl word plus cell length (56) >= JUNOS 7.4*/ l2info->header_len += 4; break; default: break; } if (ndo->ndo_eflag) ND_PRINT((ndo, "control-word 0x%08x ", control_word)); } break; #endif #ifdef DLT_JUNIPER_GGSN case DLT_JUNIPER_GGSN: break; #endif #ifdef DLT_JUNIPER_ATM1 case DLT_JUNIPER_ATM1: break; #endif #ifdef DLT_JUNIPER_PPP case DLT_JUNIPER_PPP: break; #endif #ifdef DLT_JUNIPER_CHDLC case DLT_JUNIPER_CHDLC: break; #endif #ifdef DLT_JUNIPER_ETHER case DLT_JUNIPER_ETHER: break; #endif #ifdef DLT_JUNIPER_FRELAY case DLT_JUNIPER_FRELAY: break; #endif default: ND_PRINT((ndo, "Unknown Juniper DLT_ type %u: ", l2info->pictype)); break; } if (ndo->ndo_eflag > 1) ND_PRINT((ndo, "hlen %u, proto 0x%04x, ", l2info->header_len, l2info->proto)); return 1; /* everything went ok so far. continue parsing */ trunc: ND_PRINT((ndo, "[|juniper_hdr], length %u", h->len)); return 0; } /* * Local Variables: * c-style: whitesmith * c-basic-offset: 4 * End: */ tcpdump-4.9.3/lbl/0000755000026300017510000000000013544415543012107 5ustar mcrmcrtcpdump-4.9.3/lbl/os-solaris2.h0000644000026300017510000000254013544412561014433 0ustar mcrmcr/* * Copyright (c) 1993, 1994, 1995, 1996, 1997 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of * the University nor the names of its contributors may be used to endorse * or promote products derived from this software without specific prior * written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* Prototypes missing in SunOS 5 */ #if defined(_STDIO_H) && defined(HAVE_SETLINEBUF) int setlinebuf(FILE *); #endif char *strerror(int); int snprintf(char *, size_t, const char *, ...); tcpdump-4.9.3/lbl/os-sunos4.h0000644000026300017510000001366413544412561014141 0ustar mcrmcr/* * Copyright (c) 1989, 1990, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of * the University nor the names of its contributors may be used to endorse * or promote products derived from this software without specific prior * written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* Prototypes missing in SunOS 4 */ #ifdef FILE int _filbuf(FILE *); int _flsbuf(u_char, FILE *); int fclose(FILE *); int fflush(FILE *); int fgetc(FILE *); int fprintf(FILE *, const char *, ...); int fputc(int, FILE *); int fputs(const char *, FILE *); u_int fread(void *, u_int, u_int, FILE *); int fseek(FILE *, long, int); u_int fwrite(const void *, u_int, u_int, FILE *); int pclose(FILE *); void rewind(FILE *); void setbuf(FILE *, char *); int setlinebuf(FILE *); int ungetc(int, FILE *); int vfprintf(FILE *, const char *, ...); int vprintf(const char *, ...); #endif #if __GNUC__ <= 1 int read(int, char *, u_int); int write(int, char *, u_int); #endif long a64l(const char *); #ifdef __STDC__ struct sockaddr; #endif int accept(int, struct sockaddr *, int *); int bind(int, struct sockaddr *, int); int bcmp(const void *, const void *, u_int); void bcopy(const void *, void *, u_int); void bzero(void *, int); int chroot(const char *); int close(int); void closelog(void); int connect(int, struct sockaddr *, int); char *crypt(const char *, const char *); int daemon(int, int); int fchmod(int, int); int fchown(int, int, int); void endgrent(void); void endpwent(void); void endservent(void); #ifdef __STDC__ struct ether_addr; #endif struct ether_addr *ether_aton(const char *); int flock(int, int); #ifdef __STDC__ struct stat; #endif int fstat(int, struct stat *); #ifdef __STDC__ struct statfs; #endif int fstatfs(int, struct statfs *); int fsync(int); #ifdef __STDC__ struct timeb; #endif int ftime(struct timeb *); int ftruncate(int, off_t); int getdtablesize(void); long gethostid(void); int gethostname(char *, int); int getopt(int, char * const *, const char *); int getpagesize(void); char *getpass(char *); int getpeername(int, struct sockaddr *, int *); int getpriority(int, int); #ifdef __STDC__ struct rlimit; #endif int getrlimit(int, struct rlimit *); int getsockname(int, struct sockaddr *, int *); int getsockopt(int, int, int, char *, int *); #ifdef __STDC__ struct timeval; struct timezone; #endif int gettimeofday(struct timeval *, struct timezone *); char *getusershell(void); char *getwd(char *); int initgroups(const char *, int); int ioctl(int, int, caddr_t); int iruserok(u_long, int, char *, char *); int isatty(int); int killpg(int, int); int listen(int, int); #ifdef __STDC__ struct utmp; #endif void login(struct utmp *); int logout(const char *); off_t lseek(int, off_t, int); int lstat(const char *, struct stat *); int mkstemp(char *); char *mktemp(char *); int munmap(caddr_t, int); void openlog(const char *, int, int); void perror(const char *); int printf(const char *, ...); int puts(const char *); long random(void); int readlink(const char *, char *, int); #ifdef __STDC__ struct iovec; #endif int readv(int, struct iovec *, int); int recv(int, char *, u_int, int); int recvfrom(int, char *, u_int, int, struct sockaddr *, int *); int rename(const char *, const char *); int rcmd(char **, u_short, char *, char *, char *, int *); int rresvport(int *); int send(int, char *, u_int, int); int sendto(int, char *, u_int, int, struct sockaddr *, int); int setenv(const char *, const char *, int); int seteuid(int); int setpriority(int, int, int); int select(int, fd_set *, fd_set *, fd_set *, struct timeval *); int setpgrp(int, int); void setpwent(void); int setrlimit(int, struct rlimit *); void setservent(int); int setsockopt(int, int, int, char *, int); int shutdown(int, int); int sigblock(int); void (*signal (int, void (*) (int))) (int); int sigpause(int); int sigsetmask(int); #ifdef __STDC__ struct sigvec; #endif int sigvec(int, struct sigvec *, struct sigvec*); int snprintf(char *, size_t, const char *, ...); int socket(int, int, int); int socketpair(int, int, int, int *); int symlink(const char *, const char *); void srandom(int); int sscanf(char *, const char *, ...); int stat(const char *, struct stat *); int statfs(char *, struct statfs *); char *strerror(int); #ifdef __STDC__ struct tm; #endif int strftime(char *, int, char *, struct tm *); long strtol(const char *, char **, int); void sync(void); void syslog(int, const char *, ...); int system(const char *); long tell(int); time_t time(time_t *); char *timezone(int, int); int tolower(int); int toupper(int); int truncate(char *, off_t); void unsetenv(const char *); int vfork(void); int vsprintf(char *, const char *, ...); int writev(int, struct iovec *, int); #ifdef __STDC__ struct rusage; #endif int utimes(const char *, struct timeval *); #if __GNUC__ <= 1 int wait(int *); pid_t wait3(int *, int, struct rusage *); #endif /* Ugly signal hacking */ #ifdef SIG_ERR #undef SIG_ERR #define SIG_ERR (void (*)(int))-1 #undef SIG_DFL #define SIG_DFL (void (*)(int))0 #undef SIG_IGN #define SIG_IGN (void (*)(int))1 #ifdef KERNEL #undef SIG_CATCH #define SIG_CATCH (void (*)(int))2 #endif #undef SIG_HOLD #define SIG_HOLD (void (*)(int))3 #endif tcpdump-4.9.3/lbl/os-osf4.h0000644000026300017510000000246613544412561013557 0ustar mcrmcr/* * Copyright (c) 1993, 1994, 1995, 1996, 1997 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of * the University nor the names of its contributors may be used to endorse * or promote products derived from this software without specific prior * written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* Prototypes missing in Digital UNIX 4.x */ int snprintf(char *, size_t, const char *, ...); int vsnprintf(char *, size_t, const char *, va_list); tcpdump-4.9.3/lbl/os-ultrix4.h0000644000026300017510000000312713544412561014312 0ustar mcrmcr/* * Copyright (c) 1990, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of * the University nor the names of its contributors may be used to endorse * or promote products derived from this software without specific prior * written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* Prototypes missing in Ultrix 4 */ int bcmp(const char *, const char *, u_int); void bcopy(const void *, void *, u_int); void bzero(void *, u_int); void endservent(void); int getopt(int, char * const *, const char *); #ifdef __STDC__ struct timeval; struct timezone; #endif int gettimeofday(struct timeval *, struct timezone *); int ioctl(int, int, caddr_t); int pfopen(char *, int); int setlinebuf(FILE *); int socket(int, int, int); tcpdump-4.9.3/print-forces.c0000644000026300017510000013201113544412561014110 0ustar mcrmcr/* * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code * distributions retain the above copyright notice and this paragraph * in its entirety, and (2) distributions including binary code include * the above copyright notice and this paragraph in its entirety in * the documentation or other materials provided with the distribution. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. * * Copyright (c) 2009 Mojatatu Networks, Inc * */ /* \summary: Forwarding and Control Element Separation (ForCES) Protocol printer */ /* specification: RFC 5810 */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #include "extract.h" static const char tstr[] = "[|forces]"; #define ForCES_VERS 1 #define ForCES_HDRL 24 #define ForCES_ALNL 4U #define TLV_HDRL 4 #define ILV_HDRL 8 #define TOM_RSVD 0x0 #define TOM_ASSNSETUP 0x1 #define TOM_ASSNTEARD 0x2 #define TOM_CONFIG 0x3 #define TOM_QUERY 0x4 #define TOM_EVENTNOT 0x5 #define TOM_PKTREDIR 0x6 #define TOM_HEARTBT 0x0F #define TOM_ASSNSETREP 0x11 #define TOM_CONFIGREP 0x13 #define TOM_QUERYREP 0x14 /* * tom_h Flags: resv1(8b):maxtlvs(4b):resv2(2b):mintlv(2b) */ #define ZERO_TTLV 0x01 #define ZERO_MORE_TTLV 0x02 #define ONE_MORE_TTLV 0x04 #define ZERO_TLV 0x00 #define ONE_TLV 0x10 #define TWO_TLV 0x20 #define MAX_TLV 0xF0 #define TTLV_T1 (ONE_MORE_TTLV|ONE_TLV) #define TTLV_T2 (ONE_MORE_TTLV|MAX_TLV) struct tom_h { uint32_t v; uint16_t flags; uint16_t op_msk; const char *s; int (*print) (netdissect_options *ndo, register const u_char * pptr, register u_int len, uint16_t op_msk, int indent); }; enum { TOM_RSV_I, TOM_ASS_I, TOM_AST_I, TOM_CFG_I, TOM_QRY_I, TOM_EVN_I, TOM_RED_I, TOM_HBT_I, TOM_ASR_I, TOM_CNR_I, TOM_QRR_I, _TOM_RSV_MAX }; #define TOM_MAX_IND (_TOM_RSV_MAX - 1) static inline int tom_valid(uint8_t tom) { if (tom > 0) { if (tom >= 0x7 && tom <= 0xe) return 0; if (tom == 0x10) return 0; if (tom > 0x14) return 0; return 1; } else return 0; } static inline const char *ForCES_node(uint32_t node) { if (node <= 0x3FFFFFFF) return "FE"; if (node >= 0x40000000 && node <= 0x7FFFFFFF) return "CE"; if (node >= 0xC0000000 && node <= 0xFFFFFFEF) return "AllMulticast"; if (node == 0xFFFFFFFD) return "AllCEsBroadcast"; if (node == 0xFFFFFFFE) return "AllFEsBroadcast"; if (node == 0xFFFFFFFF) return "AllBroadcast"; return "ForCESreserved"; } static const struct tok ForCES_ACKs[] = { {0x0, "NoACK"}, {0x1, "SuccessACK"}, {0x2, "FailureACK"}, {0x3, "AlwaysACK"}, {0, NULL} }; static const struct tok ForCES_EMs[] = { {0x0, "EMReserved"}, {0x1, "execute-all-or-none"}, {0x2, "execute-until-failure"}, {0x3, "continue-execute-on-failure"}, {0, NULL} }; static const struct tok ForCES_ATs[] = { {0x0, "Standalone"}, {0x1, "2PCtransaction"}, {0, NULL} }; static const struct tok ForCES_TPs[] = { {0x0, "StartofTransaction"}, {0x1, "MiddleofTransaction"}, {0x2, "EndofTransaction"}, {0x3, "abort"}, {0, NULL} }; /* * Structure of forces header, naked of TLVs. */ struct forcesh { nd_uint8_t fm_vrsvd; /* version and reserved */ #define ForCES_V(forcesh) ((forcesh)->fm_vrsvd >> 4) nd_uint8_t fm_tom; /* type of message */ nd_uint16_t fm_len; /* total length * 4 bytes */ #define ForCES_BLN(forcesh) ((uint32_t)(EXTRACT_16BITS(&(forcesh)->fm_len) << 2)) nd_uint32_t fm_sid; /* Source ID */ #define ForCES_SID(forcesh) EXTRACT_32BITS(&(forcesh)->fm_sid) nd_uint32_t fm_did; /* Destination ID */ #define ForCES_DID(forcesh) EXTRACT_32BITS(&(forcesh)->fm_did) nd_uint8_t fm_cor[8]; /* correlator */ nd_uint32_t fm_flags; /* flags */ #define ForCES_ACK(forcesh) ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0xC0000000) >> 30) #define ForCES_PRI(forcesh) ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0x38000000) >> 27) #define ForCES_RS1(forcesh) ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0x07000000) >> 24) #define ForCES_EM(forcesh) ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0x00C00000) >> 22) #define ForCES_AT(forcesh) ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0x00200000) >> 21) #define ForCES_TP(forcesh) ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0x00180000) >> 19) #define ForCES_RS2(forcesh) ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0x0007FFFF) >> 0) }; #define ForCES_HLN_VALID(fhl,tlen) ((tlen) >= ForCES_HDRL && \ (fhl) >= ForCES_HDRL && \ (fhl) == (tlen)) #define F_LFB_RSVD 0x0 #define F_LFB_FEO 0x1 #define F_LFB_FEPO 0x2 static const struct tok ForCES_LFBs[] = { {F_LFB_RSVD, "Invalid TLV"}, {F_LFB_FEO, "FEObj LFB"}, {F_LFB_FEPO, "FEProtoObj LFB"}, {0, NULL} }; /* this is defined in RFC5810 section A.2 */ /* http://www.iana.org/assignments/forces/forces.xhtml#oper-tlv-types */ enum { F_OP_RSV = 0, F_OP_SET = 1, F_OP_SETPROP = 2, F_OP_SETRESP = 3, F_OP_SETPRESP = 4, F_OP_DEL = 5, F_OP_DELRESP = 6, F_OP_GET = 7, F_OP_GETPROP = 8, F_OP_GETRESP = 9, F_OP_GETPRESP = 10, F_OP_REPORT = 11, F_OP_COMMIT = 12, F_OP_RCOMMIT = 13, F_OP_RTRCOMP = 14, _F_OP_MAX }; #define F_OP_MAX (_F_OP_MAX - 1) enum { B_OP_SET = 1 << (F_OP_SET - 1), B_OP_SETPROP = 1 << (F_OP_SETPROP - 1), B_OP_SETRESP = 1 << (F_OP_SETRESP - 1), B_OP_SETPRESP = 1 << (F_OP_SETPRESP - 1), B_OP_DEL = 1 << (F_OP_DEL - 1), B_OP_DELRESP = 1 << (F_OP_DELRESP - 1), B_OP_GET = 1 << (F_OP_GET - 1), B_OP_GETPROP = 1 << (F_OP_GETPROP - 1), B_OP_GETRESP = 1 << (F_OP_GETRESP - 1), B_OP_GETPRESP = 1 << (F_OP_GETPRESP - 1), B_OP_REPORT = 1 << (F_OP_REPORT - 1), B_OP_COMMIT = 1 << (F_OP_COMMIT - 1), B_OP_RCOMMIT = 1 << (F_OP_RCOMMIT - 1), B_OP_RTRCOMP = 1 << (F_OP_RTRCOMP - 1) }; struct optlv_h { uint16_t flags; uint16_t op_msk; const char *s; int (*print) (netdissect_options *ndo, register const u_char * pptr, register u_int len, uint16_t op_msk, int indent); }; static int genoptlv_print(netdissect_options *, register const u_char * pptr, register u_int len, uint16_t op_msk, int indent); static int recpdoptlv_print(netdissect_options *, register const u_char * pptr, register u_int len, uint16_t op_msk, int indent); static int invoptlv_print(netdissect_options *, register const u_char * pptr, register u_int len, uint16_t op_msk, int indent); #define OP_MIN_SIZ 8 struct pathdata_h { nd_uint16_t pflags; nd_uint16_t pIDcnt; }; #define B_FULLD 0x1 #define B_SPARD 0x2 #define B_RESTV 0x4 #define B_KEYIN 0x8 #define B_APPND 0x10 #define B_TRNG 0x20 static const struct optlv_h OPTLV_msg[F_OP_MAX + 1] = { /* F_OP_RSV */ {ZERO_TTLV, 0, "Invalid OPTLV", invoptlv_print}, /* F_OP_SET */ {TTLV_T2, B_FULLD | B_SPARD, " Set", recpdoptlv_print}, /* F_OP_SETPROP */ {TTLV_T2, B_FULLD | B_SPARD, " SetProp", recpdoptlv_print}, /* F_OP_SETRESP */ {TTLV_T2, B_RESTV, " SetResp", recpdoptlv_print}, /* F_OP_SETPRESP */ {TTLV_T2, B_RESTV, " SetPropResp", recpdoptlv_print}, /* F_OP_DEL */ {ZERO_TTLV, 0, " Del", recpdoptlv_print}, /* F_OP_DELRESP */ {TTLV_T2, B_RESTV, " DelResp", recpdoptlv_print}, /* F_OP_GET */ {ZERO_TTLV, 0, " Get", recpdoptlv_print}, /* F_OP_GETPROP */ {ZERO_TTLV, 0, " GetProp", recpdoptlv_print}, /* F_OP_GETRESP */ {TTLV_T2, B_FULLD | B_SPARD | B_RESTV, " GetResp", recpdoptlv_print}, /* F_OP_GETPRESP */ {TTLV_T2, B_FULLD | B_RESTV, " GetPropResp", recpdoptlv_print}, /* F_OP_REPORT */ {TTLV_T2, B_FULLD | B_SPARD, " Report", recpdoptlv_print}, /* F_OP_COMMIT */ {ZERO_TTLV, 0, " Commit", NULL}, /* F_OP_RCOMMIT */ {TTLV_T1, B_RESTV, " RCommit", genoptlv_print}, /* F_OP_RTRCOMP */ {ZERO_TTLV, 0, " RTRCOMP", NULL}, }; static inline const struct optlv_h *get_forces_optlv_h(uint16_t opt) { if (opt > F_OP_MAX || opt <= F_OP_RSV) return &OPTLV_msg[F_OP_RSV]; return &OPTLV_msg[opt]; } #define IND_SIZE 256 #define IND_CHR ' ' #define IND_PREF '\n' #define IND_SUF 0x0 static char ind_buf[IND_SIZE]; static inline char *indent_pr(int indent, int nlpref) { int i = 0; char *r = ind_buf; if (indent > (IND_SIZE - 1)) indent = IND_SIZE - 1; if (nlpref) { r[i] = IND_PREF; i++; indent--; } while (--indent >= 0) r[i++] = IND_CHR; r[i] = IND_SUF; return r; } static inline int op_valid(uint16_t op, uint16_t mask) { int opb = 1 << (op - 1); if (op == 0) return 0; if (opb & mask) return 1; /* I guess we should allow vendor operations? */ if (op >= 0x8000) return 1; return 0; } #define F_TLV_RSVD 0x0000 #define F_TLV_REDR 0x0001 #define F_TLV_ASRS 0x0010 #define F_TLV_ASRT 0x0011 #define F_TLV_LFBS 0x1000 #define F_TLV_PDAT 0x0110 #define F_TLV_KEYI 0x0111 #define F_TLV_FULD 0x0112 #define F_TLV_SPAD 0x0113 #define F_TLV_REST 0x0114 #define F_TLV_METD 0x0115 #define F_TLV_REDD 0x0116 #define F_TLV_TRNG 0x0117 #define F_TLV_VNST 0x8000 static const struct tok ForCES_TLV[] = { {F_TLV_RSVD, "Invalid TLV"}, {F_TLV_REDR, "REDIRECT TLV"}, {F_TLV_ASRS, "ASResult TLV"}, {F_TLV_ASRT, "ASTreason TLV"}, {F_TLV_LFBS, "LFBselect TLV"}, {F_TLV_PDAT, "PATH-DATA TLV"}, {F_TLV_KEYI, "KEYINFO TLV"}, {F_TLV_FULD, "FULLDATA TLV"}, {F_TLV_SPAD, "SPARSEDATA TLV"}, {F_TLV_REST, "RESULT TLV"}, {F_TLV_METD, "METADATA TLV"}, {F_TLV_REDD, "REDIRECTDATA TLV"}, {0, NULL} }; #define TLV_HLN 4 static inline int ttlv_valid(uint16_t ttlv) { if (ttlv > 0) { if (ttlv == 1 || ttlv == 0x1000) return 1; if (ttlv >= 0x10 && ttlv <= 0x11) return 1; if (ttlv >= 0x110 && ttlv <= 0x116) return 1; if (ttlv >= 0x8000) return 0; /* XXX: */ } return 0; } struct forces_ilv { nd_uint32_t type; nd_uint32_t length; }; struct forces_tlv { nd_uint16_t type; nd_uint16_t length; }; #define F_ALN_LEN(len) ( ((len)+ForCES_ALNL-1) & ~(ForCES_ALNL-1) ) #define GET_TOP_TLV(fhdr) ((const struct forces_tlv *)((fhdr) + sizeof (struct forcesh))) #define TLV_SET_LEN(len) (F_ALN_LEN(TLV_HDRL) + (len)) #define TLV_ALN_LEN(len) F_ALN_LEN(TLV_SET_LEN(len)) #define TLV_RDAT_LEN(tlv) ((int)(EXTRACT_16BITS(&(tlv)->length) - TLV_SET_LEN(0)) #define TLV_DATA(tlvp) ((const void*)(((const char*)(tlvp)) + TLV_SET_LEN(0))) #define GO_NXT_TLV(tlv,rlen) ((rlen) -= F_ALN_LEN(EXTRACT_16BITS(&(tlv)->length)), \ (const struct forces_tlv*)(((const char*)(tlv)) \ + F_ALN_LEN(EXTRACT_16BITS(&(tlv)->length)))) #define ILV_SET_LEN(len) (F_ALN_LEN(ILV_HDRL) + (len)) #define ILV_ALN_LEN(len) F_ALN_LEN(ILV_SET_LEN(len)) #define ILV_RDAT_LEN(ilv) ((int)(EXTRACT_32BITS(&(ilv)->length)) - ILV_SET_LEN(0)) #define ILV_DATA(ilvp) ((const void*)(((const char*)(ilvp)) + ILV_SET_LEN(0))) #define GO_NXT_ILV(ilv,rlen) ((rlen) -= F_ALN_LEN(EXTRACT_32BITS(&(ilv)->length)), \ (const struct forces_ilv *)(((const char*)(ilv)) \ + F_ALN_LEN(EXTRACT_32BITS(&(ilv)->length)))) #define INVALID_RLEN 1 #define INVALID_STLN 2 #define INVALID_LTLN 3 #define INVALID_ALEN 4 static const struct tok ForCES_TLV_err[] = { {INVALID_RLEN, "Invalid total length"}, {INVALID_STLN, "xLV too short"}, {INVALID_LTLN, "xLV too long"}, {INVALID_ALEN, "data padding missing"}, {0, NULL} }; static inline u_int tlv_valid(const struct forces_tlv *tlv, u_int rlen) { if (rlen < TLV_HDRL) return INVALID_RLEN; if (EXTRACT_16BITS(&tlv->length) < TLV_HDRL) return INVALID_STLN; if (EXTRACT_16BITS(&tlv->length) > rlen) return INVALID_LTLN; if (rlen < F_ALN_LEN(EXTRACT_16BITS(&tlv->length))) return INVALID_ALEN; return 0; } static inline int ilv_valid(const struct forces_ilv *ilv, u_int rlen) { if (rlen < ILV_HDRL) return INVALID_RLEN; if (EXTRACT_32BITS(&ilv->length) < ILV_HDRL) return INVALID_STLN; if (EXTRACT_32BITS(&ilv->length) > rlen) return INVALID_LTLN; if (rlen < F_ALN_LEN(EXTRACT_32BITS(&ilv->length))) return INVALID_ALEN; return 0; } static int lfbselect_print(netdissect_options *, register const u_char * pptr, register u_int len, uint16_t op_msk, int indent); static int redirect_print(netdissect_options *, register const u_char * pptr, register u_int len, uint16_t op_msk, int indent); static int asrtlv_print(netdissect_options *, register const u_char * pptr, register u_int len, uint16_t op_msk, int indent); static int asttlv_print(netdissect_options *, register const u_char * pptr, register u_int len, uint16_t op_msk, int indent); struct forces_lfbsh { nd_uint32_t class; nd_uint32_t instance; }; #define ASSNS_OPS (B_OP_REPORT) #define CFG_OPS (B_OP_SET|B_OP_SETPROP|B_OP_DEL|B_OP_COMMIT|B_OP_RTRCOMP) #define CFG_ROPS (B_OP_SETRESP|B_OP_SETPRESP|B_OP_DELRESP|B_OP_RCOMMIT) #define CFG_QY (B_OP_GET|B_OP_GETPROP) #define CFG_QYR (B_OP_GETRESP|B_OP_GETPRESP) #define CFG_EVN (B_OP_REPORT) static const struct tom_h ForCES_msg[TOM_MAX_IND + 1] = { /* TOM_RSV_I */ {TOM_RSVD, ZERO_TTLV, 0, "Invalid message", NULL}, /* TOM_ASS_I */ {TOM_ASSNSETUP, ZERO_MORE_TTLV | TWO_TLV, ASSNS_OPS, "Association Setup", lfbselect_print}, /* TOM_AST_I */ {TOM_ASSNTEARD, TTLV_T1, 0, "Association TearDown", asttlv_print}, /* TOM_CFG_I */ {TOM_CONFIG, TTLV_T2, CFG_OPS, "Config", lfbselect_print}, /* TOM_QRY_I */ {TOM_QUERY, TTLV_T2, CFG_QY, "Query", lfbselect_print}, /* TOM_EVN_I */ {TOM_EVENTNOT, TTLV_T1, CFG_EVN, "Event Notification", lfbselect_print}, /* TOM_RED_I */ {TOM_PKTREDIR, TTLV_T2, 0, "Packet Redirect", redirect_print}, /* TOM_HBT_I */ {TOM_HEARTBT, ZERO_TTLV, 0, "HeartBeat", NULL}, /* TOM_ASR_I */ {TOM_ASSNSETREP, TTLV_T1, 0, "Association Response", asrtlv_print}, /* TOM_CNR_I */ {TOM_CONFIGREP, TTLV_T2, CFG_ROPS, "Config Response", lfbselect_print}, /* TOM_QRR_I */ {TOM_QUERYREP, TTLV_T2, CFG_QYR, "Query Response", lfbselect_print}, }; static inline const struct tom_h *get_forces_tom(uint8_t tom) { int i; for (i = TOM_RSV_I; i <= TOM_MAX_IND; i++) { const struct tom_h *th = &ForCES_msg[i]; if (th->v == tom) return th; } return &ForCES_msg[TOM_RSV_I]; } struct pdata_ops { uint32_t v; uint16_t flags; uint16_t op_msk; const char *s; int (*print) (netdissect_options *, register const u_char * pptr, register u_int len, uint16_t op_msk, int indent); }; enum { PD_RSV_I, PD_SEL_I, PD_FDT_I, PD_SDT_I, PD_RES_I, PD_PDT_I, _PD_RSV_MAX }; #define PD_MAX_IND (_TOM_RSV_MAX - 1) static inline int pd_valid(uint16_t pd) { if (pd >= F_TLV_PDAT && pd <= F_TLV_REST) return 1; return 0; } static inline void chk_op_type(netdissect_options *ndo, uint16_t type, uint16_t msk, uint16_t omsk) { if (type != F_TLV_PDAT) { if (msk & B_KEYIN) { if (type != F_TLV_KEYI) { ND_PRINT((ndo, "Based on flags expected KEYINFO TLV!\n")); } } else { if (!(msk & omsk)) { ND_PRINT((ndo, "Illegal DATA encoding for type 0x%x programmed %x got %x \n", type, omsk, msk)); } } } } #define F_SELKEY 1 #define F_SELTABRANGE 2 #define F_TABAPPEND 4 struct res_val { nd_uint8_t result; nd_uint8_t resv1; nd_uint16_t resv2; }; static int prestlv_print(netdissect_options *, register const u_char * pptr, register u_int len, uint16_t op_msk, int indent); static int pkeyitlv_print(netdissect_options *, register const u_char * pptr, register u_int len, uint16_t op_msk, int indent); static int fdatatlv_print(netdissect_options *, register const u_char * pptr, register u_int len, uint16_t op_msk, int indent); static int sdatatlv_print(netdissect_options *, register const u_char * pptr, register u_int len, uint16_t op_msk, int indent); static const struct pdata_ops ForCES_pdata[PD_MAX_IND + 1] = { /* PD_RSV_I */ {0, 0, 0, "Invalid message", NULL}, /* PD_SEL_I */ {F_TLV_KEYI, 0, 0, "KEYINFO TLV", pkeyitlv_print}, /* PD_FDT_I */ {F_TLV_FULD, 0, B_FULLD, "FULLDATA TLV", fdatatlv_print}, /* PD_SDT_I */ {F_TLV_SPAD, 0, B_SPARD, "SPARSEDATA TLV", sdatatlv_print}, /* PD_RES_I */ {F_TLV_REST, 0, B_RESTV, "RESULT TLV", prestlv_print}, /* PD_PDT_I */ {F_TLV_PDAT, 0, 0, "Inner PATH-DATA TLV", recpdoptlv_print}, }; static inline const struct pdata_ops *get_forces_pd(uint16_t pd) { int i; for (i = PD_RSV_I + 1; i <= PD_MAX_IND; i++) { const struct pdata_ops *pdo = &ForCES_pdata[i]; if (pdo->v == pd) return pdo; } return &ForCES_pdata[TOM_RSV_I]; } enum { E_SUCCESS, E_INVALID_HEADER, E_LENGTH_MISMATCH, E_VERSION_MISMATCH, E_INVALID_DESTINATION_PID, E_LFB_UNKNOWN, E_LFB_NOT_FOUND, E_LFB_INSTANCE_ID_NOT_FOUND, E_INVALID_PATH, E_COMPONENT_DOES_NOT_EXIST, E_EXISTS, E_NOT_FOUND, E_READ_ONLY, E_INVALID_ARRAY_CREATION, E_VALUE_OUT_OF_RANGE, E_CONTENTS_TOO_LONG, E_INVALID_PARAMETERS, E_INVALID_MESSAGE_TYPE, E_INVALID_FLAGS, E_INVALID_TLV, E_EVENT_ERROR, E_NOT_SUPPORTED, E_MEMORY_ERROR, E_INTERNAL_ERROR, /* 0x18-0xFE are reserved .. */ E_UNSPECIFIED_ERROR = 0XFF }; static const struct tok ForCES_errs[] = { {E_SUCCESS, "SUCCESS"}, {E_INVALID_HEADER, "INVALID HEADER"}, {E_LENGTH_MISMATCH, "LENGTH MISMATCH"}, {E_VERSION_MISMATCH, "VERSION MISMATCH"}, {E_INVALID_DESTINATION_PID, "INVALID DESTINATION PID"}, {E_LFB_UNKNOWN, "LFB UNKNOWN"}, {E_LFB_NOT_FOUND, "LFB NOT FOUND"}, {E_LFB_INSTANCE_ID_NOT_FOUND, "LFB INSTANCE ID NOT FOUND"}, {E_INVALID_PATH, "INVALID PATH"}, {E_COMPONENT_DOES_NOT_EXIST, "COMPONENT DOES NOT EXIST"}, {E_EXISTS, "EXISTS ALREADY"}, {E_NOT_FOUND, "NOT FOUND"}, {E_READ_ONLY, "READ ONLY"}, {E_INVALID_ARRAY_CREATION, "INVALID ARRAY CREATION"}, {E_VALUE_OUT_OF_RANGE, "VALUE OUT OF RANGE"}, {E_CONTENTS_TOO_LONG, "CONTENTS TOO LONG"}, {E_INVALID_PARAMETERS, "INVALID PARAMETERS"}, {E_INVALID_MESSAGE_TYPE, "INVALID MESSAGE TYPE"}, {E_INVALID_FLAGS, "INVALID FLAGS"}, {E_INVALID_TLV, "INVALID TLV"}, {E_EVENT_ERROR, "EVENT ERROR"}, {E_NOT_SUPPORTED, "NOT SUPPORTED"}, {E_MEMORY_ERROR, "MEMORY ERROR"}, {E_INTERNAL_ERROR, "INTERNAL ERROR"}, {E_UNSPECIFIED_ERROR, "UNSPECIFIED ERROR"}, {0, NULL} }; #define RESLEN 4 static int prestlv_print(netdissect_options *ndo, register const u_char * pptr, register u_int len, uint16_t op_msk _U_, int indent) { const struct forces_tlv *tlv = (const struct forces_tlv *)pptr; register const u_char *tdp = (const u_char *) TLV_DATA(tlv); const struct res_val *r = (const struct res_val *)tdp; u_int dlen; /* * pdatacnt_print() has ensured that len (the TLV length) * >= TLV_HDRL. */ dlen = len - TLV_HDRL; if (dlen != RESLEN) { ND_PRINT((ndo, "illegal RESULT-TLV: %d bytes!\n", dlen)); return -1; } ND_TCHECK(*r); if (r->result >= 0x18 && r->result <= 0xFE) { ND_PRINT((ndo, "illegal reserved result code: 0x%x!\n", r->result)); return -1; } if (ndo->ndo_vflag >= 3) { char *ib = indent_pr(indent, 0); ND_PRINT((ndo, "%s Result: %s (code 0x%x)\n", ib, tok2str(ForCES_errs, NULL, r->result), r->result)); } return 0; trunc: ND_PRINT((ndo, "%s", tstr)); return -1; } static int fdatatlv_print(netdissect_options *ndo, register const u_char * pptr, register u_int len, uint16_t op_msk _U_, int indent) { const struct forces_tlv *tlv = (const struct forces_tlv *)pptr; u_int rlen; register const u_char *tdp = (const u_char *) TLV_DATA(tlv); uint16_t type; /* * pdatacnt_print() or pkeyitlv_print() has ensured that len * (the TLV length) >= TLV_HDRL. */ rlen = len - TLV_HDRL; ND_TCHECK(*tlv); type = EXTRACT_16BITS(&tlv->type); if (type != F_TLV_FULD) { ND_PRINT((ndo, "Error: expecting FULLDATA!\n")); return -1; } if (ndo->ndo_vflag >= 3) { char *ib = indent_pr(indent + 2, 1); ND_PRINT((ndo, "%s[", &ib[1])); hex_print_with_offset(ndo, ib, tdp, rlen, 0); ND_PRINT((ndo, "\n%s]\n", &ib[1])); } return 0; trunc: ND_PRINT((ndo, "%s", tstr)); return -1; } static int sdatailv_print(netdissect_options *ndo, register const u_char * pptr, register u_int len, uint16_t op_msk _U_, int indent) { u_int rlen; const struct forces_ilv *ilv = (const struct forces_ilv *)pptr; int invilv; if (len < ILV_HDRL) { ND_PRINT((ndo, "Error: BAD SPARSEDATA-TLV!\n")); return -1; } rlen = len; indent += 1; while (rlen != 0) { #if 0 ND_PRINT((ndo, "Jamal - outstanding length <%d>\n", rlen)); #endif char *ib = indent_pr(indent, 1); register const u_char *tdp = (const u_char *) ILV_DATA(ilv); ND_TCHECK(*ilv); invilv = ilv_valid(ilv, rlen); if (invilv) { ND_PRINT((ndo, "%s[", &ib[1])); hex_print_with_offset(ndo, ib, tdp, rlen, 0); ND_PRINT((ndo, "\n%s]\n", &ib[1])); return -1; } if (ndo->ndo_vflag >= 3) { int ilvl = EXTRACT_32BITS(&ilv->length); ND_PRINT((ndo, "\n%s ILV: type %x length %d\n", &ib[1], EXTRACT_32BITS(&ilv->type), ilvl)); hex_print_with_offset(ndo, "\t\t[", tdp, ilvl-ILV_HDRL, 0); } ilv = GO_NXT_ILV(ilv, rlen); } return 0; trunc: ND_PRINT((ndo, "%s", tstr)); return -1; } static int sdatatlv_print(netdissect_options *ndo, register const u_char * pptr, register u_int len, uint16_t op_msk, int indent) { const struct forces_tlv *tlv = (const struct forces_tlv *)pptr; u_int rlen; register const u_char *tdp = (const u_char *) TLV_DATA(tlv); uint16_t type; /* * pdatacnt_print() has ensured that len (the TLV length) * >= TLV_HDRL. */ rlen = len - TLV_HDRL; ND_TCHECK(*tlv); type = EXTRACT_16BITS(&tlv->type); if (type != F_TLV_SPAD) { ND_PRINT((ndo, "Error: expecting SPARSEDATA!\n")); return -1; } return sdatailv_print(ndo, tdp, rlen, op_msk, indent); trunc: ND_PRINT((ndo, "%s", tstr)); return -1; } static int pkeyitlv_print(netdissect_options *ndo, register const u_char * pptr, register u_int len, uint16_t op_msk, int indent) { const struct forces_tlv *tlv = (const struct forces_tlv *)pptr; register const u_char *tdp = (const u_char *) TLV_DATA(tlv); register const u_char *dp = tdp + 4; const struct forces_tlv *kdtlv = (const struct forces_tlv *)dp; uint32_t id; char *ib = indent_pr(indent, 0); uint16_t type, tll; u_int invtlv; ND_TCHECK(*tdp); id = EXTRACT_32BITS(tdp); ND_PRINT((ndo, "%sKeyinfo: Key 0x%x\n", ib, id)); ND_TCHECK(*kdtlv); type = EXTRACT_16BITS(&kdtlv->type); invtlv = tlv_valid(kdtlv, len); if (invtlv) { ND_PRINT((ndo, "%s TLV type 0x%x len %d\n", tok2str(ForCES_TLV_err, NULL, invtlv), type, EXTRACT_16BITS(&kdtlv->length))); return -1; } /* * At this point, tlv_valid() has ensured that the TLV * length is large enough but not too large (it doesn't * go past the end of the containing TLV). */ tll = EXTRACT_16BITS(&kdtlv->length); dp = (const u_char *) TLV_DATA(kdtlv); return fdatatlv_print(ndo, dp, tll, op_msk, indent); trunc: ND_PRINT((ndo, "%s", tstr)); return -1; } #define PTH_DESC_SIZE 12 static int pdatacnt_print(netdissect_options *ndo, register const u_char * pptr, register u_int len, uint16_t IDcnt, uint16_t op_msk, int indent) { u_int i; uint32_t id; char *ib = indent_pr(indent, 0); if ((op_msk & B_APPND) && ndo->ndo_vflag >= 3) { ND_PRINT((ndo, "%sTABLE APPEND\n", ib)); } for (i = 0; i < IDcnt; i++) { ND_TCHECK2(*pptr, 4); if (len < 4) goto trunc; id = EXTRACT_32BITS(pptr); if (ndo->ndo_vflag >= 3) ND_PRINT((ndo, "%sID#%02u: %d\n", ib, i + 1, id)); len -= 4; pptr += 4; } if ((op_msk & B_TRNG) || (op_msk & B_KEYIN)) { if (op_msk & B_TRNG) { uint32_t starti, endi; if (len < PTH_DESC_SIZE) { ND_PRINT((ndo, "pathlength %d with key/range too short %d\n", len, PTH_DESC_SIZE)); return -1; } pptr += sizeof(struct forces_tlv); len -= sizeof(struct forces_tlv); starti = EXTRACT_32BITS(pptr); pptr += 4; len -= 4; endi = EXTRACT_32BITS(pptr); pptr += 4; len -= 4; if (ndo->ndo_vflag >= 3) ND_PRINT((ndo, "%sTable range: [%d,%d]\n", ib, starti, endi)); } if (op_msk & B_KEYIN) { const struct forces_tlv *keytlv; uint16_t tll; if (len < PTH_DESC_SIZE) { ND_PRINT((ndo, "pathlength %d with key/range too short %d\n", len, PTH_DESC_SIZE)); return -1; } /* skip keyid */ pptr += 4; len -= 4; keytlv = (const struct forces_tlv *)pptr; /* skip header */ pptr += sizeof(struct forces_tlv); len -= sizeof(struct forces_tlv); /* skip key content */ tll = EXTRACT_16BITS(&keytlv->length); if (tll < TLV_HDRL) { ND_PRINT((ndo, "key content length %u < %u\n", tll, TLV_HDRL)); return -1; } tll -= TLV_HDRL; if (len < tll) { ND_PRINT((ndo, "key content too short\n")); return -1; } pptr += tll; len -= tll; } } if (len) { const struct forces_tlv *pdtlv = (const struct forces_tlv *)pptr; uint16_t type; uint16_t tll; int pad = 0; u_int aln; u_int invtlv; ND_TCHECK(*pdtlv); type = EXTRACT_16BITS(&pdtlv->type); invtlv = tlv_valid(pdtlv, len); if (invtlv) { ND_PRINT((ndo, "%s Outstanding bytes %d for TLV type 0x%x TLV len %d\n", tok2str(ForCES_TLV_err, NULL, invtlv), len, type, EXTRACT_16BITS(&pdtlv->length))); goto pd_err; } /* * At this point, tlv_valid() has ensured that the TLV * length is large enough but not too large (it doesn't * go past the end of the containing TLV). */ tll = EXTRACT_16BITS(&pdtlv->length) - TLV_HDRL; aln = F_ALN_LEN(EXTRACT_16BITS(&pdtlv->length)); if (aln > EXTRACT_16BITS(&pdtlv->length)) { if (aln > len) { ND_PRINT((ndo, "Invalid padded pathdata TLV type 0x%x len %d missing %d pad bytes\n", type, EXTRACT_16BITS(&pdtlv->length), aln - len)); } else { pad = aln - EXTRACT_16BITS(&pdtlv->length); } } if (pd_valid(type)) { const struct pdata_ops *ops = get_forces_pd(type); if (ndo->ndo_vflag >= 3 && ops->v != F_TLV_PDAT) { if (pad) ND_PRINT((ndo, "%s %s (Length %d DataLen %d pad %d Bytes)\n", ib, ops->s, EXTRACT_16BITS(&pdtlv->length), tll, pad)); else ND_PRINT((ndo, "%s %s (Length %d DataLen %d Bytes)\n", ib, ops->s, EXTRACT_16BITS(&pdtlv->length), tll)); } chk_op_type(ndo, type, op_msk, ops->op_msk); if (ops->print(ndo, (const u_char *)pdtlv, tll + pad + TLV_HDRL, op_msk, indent + 2) == -1) return -1; len -= (TLV_HDRL + pad + tll); } else { ND_PRINT((ndo, "Invalid path data content type 0x%x len %d\n", type, EXTRACT_16BITS(&pdtlv->length))); pd_err: if (EXTRACT_16BITS(&pdtlv->length)) { hex_print_with_offset(ndo, "Bad Data val\n\t [", pptr, len, 0); ND_PRINT((ndo, "]\n")); return -1; } } } return len; trunc: ND_PRINT((ndo, "%s", tstr)); return -1; } static int pdata_print(netdissect_options *ndo, register const u_char * pptr, register u_int len, uint16_t op_msk, int indent) { const struct pathdata_h *pdh = (const struct pathdata_h *)pptr; char *ib = indent_pr(indent, 0); u_int minsize = 0; int more_pd = 0; uint16_t idcnt = 0; ND_TCHECK(*pdh); if (len < sizeof(struct pathdata_h)) goto trunc; if (ndo->ndo_vflag >= 3) { ND_PRINT((ndo, "\n%sPathdata: Flags 0x%x ID count %d\n", ib, EXTRACT_16BITS(&pdh->pflags), EXTRACT_16BITS(&pdh->pIDcnt))); } if (EXTRACT_16BITS(&pdh->pflags) & F_SELKEY) { op_msk |= B_KEYIN; } /* Table GET Range operation */ if (EXTRACT_16BITS(&pdh->pflags) & F_SELTABRANGE) { op_msk |= B_TRNG; } /* Table SET append operation */ if (EXTRACT_16BITS(&pdh->pflags) & F_TABAPPEND) { op_msk |= B_APPND; } pptr += sizeof(struct pathdata_h); len -= sizeof(struct pathdata_h); idcnt = EXTRACT_16BITS(&pdh->pIDcnt); minsize = idcnt * 4; if (len < minsize) { ND_PRINT((ndo, "\t\t\ttruncated IDs expected %uB got %uB\n", minsize, len)); hex_print_with_offset(ndo, "\t\t\tID Data[", pptr, len, 0); ND_PRINT((ndo, "]\n")); return -1; } if ((op_msk & B_TRNG) && (op_msk & B_KEYIN)) { ND_PRINT((ndo, "\t\t\tIllegal to have both Table ranges and keys\n")); return -1; } more_pd = pdatacnt_print(ndo, pptr, len, idcnt, op_msk, indent); if (more_pd > 0) { int consumed = len - more_pd; pptr += consumed; len = more_pd; /* XXX: Argh, recurse some more */ return recpdoptlv_print(ndo, pptr, len, op_msk, indent+1); } else return 0; trunc: ND_PRINT((ndo, "%s", tstr)); return -1; } static int genoptlv_print(netdissect_options *ndo, register const u_char * pptr, register u_int len, uint16_t op_msk, int indent) { const struct forces_tlv *pdtlv = (const struct forces_tlv *)pptr; uint16_t type; int tll; u_int invtlv; char *ib = indent_pr(indent, 0); ND_TCHECK(*pdtlv); type = EXTRACT_16BITS(&pdtlv->type); tll = EXTRACT_16BITS(&pdtlv->length) - TLV_HDRL; invtlv = tlv_valid(pdtlv, len); ND_PRINT((ndo, "genoptlvprint - %s TLV type 0x%x len %d\n", tok2str(ForCES_TLV, NULL, type), type, EXTRACT_16BITS(&pdtlv->length))); if (!invtlv) { /* * At this point, tlv_valid() has ensured that the TLV * length is large enough but not too large (it doesn't * go past the end of the containing TLV). */ register const u_char *dp = (const u_char *) TLV_DATA(pdtlv); if (!ttlv_valid(type)) { ND_PRINT((ndo, "%s TLV type 0x%x len %d\n", tok2str(ForCES_TLV_err, NULL, invtlv), type, EXTRACT_16BITS(&pdtlv->length))); return -1; } if (ndo->ndo_vflag >= 3) ND_PRINT((ndo, "%s%s, length %d (data length %d Bytes)", ib, tok2str(ForCES_TLV, NULL, type), EXTRACT_16BITS(&pdtlv->length), tll)); return pdata_print(ndo, dp, tll, op_msk, indent + 1); } else { ND_PRINT((ndo, "\t\t\tInvalid ForCES TLV type=%x", type)); return -1; } trunc: ND_PRINT((ndo, "%s", tstr)); return -1; } static int recpdoptlv_print(netdissect_options *ndo, register const u_char * pptr, register u_int len, uint16_t op_msk, int indent) { const struct forces_tlv *pdtlv = (const struct forces_tlv *)pptr; int tll; u_int invtlv; uint16_t type; register const u_char *dp; char *ib; while (len != 0) { ND_TCHECK(*pdtlv); invtlv = tlv_valid(pdtlv, len); if (invtlv) { break; } /* * At this point, tlv_valid() has ensured that the TLV * length is large enough but not too large (it doesn't * go past the end of the containing TLV). */ ib = indent_pr(indent, 0); type = EXTRACT_16BITS(&pdtlv->type); dp = (const u_char *) TLV_DATA(pdtlv); tll = EXTRACT_16BITS(&pdtlv->length) - TLV_HDRL; if (ndo->ndo_vflag >= 3) ND_PRINT((ndo, "%s%s, length %d (data encapsulated %d Bytes)", ib, tok2str(ForCES_TLV, NULL, type), EXTRACT_16BITS(&pdtlv->length), EXTRACT_16BITS(&pdtlv->length) - TLV_HDRL)); if (pdata_print(ndo, dp, tll, op_msk, indent + 1) == -1) return -1; pdtlv = GO_NXT_TLV(pdtlv, len); } if (len) { ND_PRINT((ndo, "\n\t\tMessy PATHDATA TLV header, type (0x%x)\n\t\texcess of %d Bytes ", EXTRACT_16BITS(&pdtlv->type), len - EXTRACT_16BITS(&pdtlv->length))); return -1; } return 0; trunc: ND_PRINT((ndo, "%s", tstr)); return -1; } static int invoptlv_print(netdissect_options *ndo, register const u_char * pptr, register u_int len, uint16_t op_msk _U_, int indent) { char *ib = indent_pr(indent, 1); if (ndo->ndo_vflag >= 3) { ND_PRINT((ndo, "%sData[", &ib[1])); hex_print_with_offset(ndo, ib, pptr, len, 0); ND_PRINT((ndo, "%s]\n", ib)); } return -1; } static int otlv_print(netdissect_options *ndo, const struct forces_tlv *otlv, uint16_t op_msk _U_, int indent) { int rc = 0; register const u_char *dp = (const u_char *) TLV_DATA(otlv); uint16_t type; int tll; char *ib = indent_pr(indent, 0); const struct optlv_h *ops; /* * lfbselect_print() has ensured that EXTRACT_16BITS(&otlv->length) * >= TLV_HDRL. */ ND_TCHECK(*otlv); type = EXTRACT_16BITS(&otlv->type); tll = EXTRACT_16BITS(&otlv->length) - TLV_HDRL; ops = get_forces_optlv_h(type); if (ndo->ndo_vflag >= 3) { ND_PRINT((ndo, "%sOper TLV %s(0x%x) length %d\n", ib, ops->s, type, EXTRACT_16BITS(&otlv->length))); } /* rest of ops must at least have 12B {pathinfo} */ if (tll < OP_MIN_SIZ) { ND_PRINT((ndo, "\t\tOper TLV %s(0x%x) length %d\n", ops->s, type, EXTRACT_16BITS(&otlv->length))); ND_PRINT((ndo, "\t\tTruncated data size %d minimum required %d\n", tll, OP_MIN_SIZ)); return invoptlv_print(ndo, dp, tll, ops->op_msk, indent); } /* XXX - do anything with ops->flags? */ if(ops->print) { rc = ops->print(ndo, dp, tll, ops->op_msk, indent + 1); } return rc; trunc: ND_PRINT((ndo, "%s", tstr)); return -1; } #define ASTDLN 4 #define ASTMCD 255 static int asttlv_print(netdissect_options *ndo, register const u_char * pptr, register u_int len, uint16_t op_msk _U_, int indent) { uint32_t rescode; u_int dlen; char *ib = indent_pr(indent, 0); /* * forces_type_print() has ensured that len (the TLV length) * >= TLV_HDRL. */ dlen = len - TLV_HDRL; if (dlen != ASTDLN) { ND_PRINT((ndo, "illegal ASTresult-TLV: %d bytes!\n", dlen)); return -1; } ND_TCHECK2(*pptr, 4); rescode = EXTRACT_32BITS(pptr); if (rescode > ASTMCD) { ND_PRINT((ndo, "illegal ASTresult result code: %d!\n", rescode)); return -1; } if (ndo->ndo_vflag >= 3) { ND_PRINT((ndo, "Teardown reason:\n%s", ib)); switch (rescode) { case 0: ND_PRINT((ndo, "Normal Teardown")); break; case 1: ND_PRINT((ndo, "Loss of Heartbeats")); break; case 2: ND_PRINT((ndo, "Out of bandwidth")); break; case 3: ND_PRINT((ndo, "Out of Memory")); break; case 4: ND_PRINT((ndo, "Application Crash")); break; default: ND_PRINT((ndo, "Unknown Teardown reason")); break; } ND_PRINT((ndo, "(%x)\n%s", rescode, ib)); } return 0; trunc: ND_PRINT((ndo, "%s", tstr)); return -1; } #define ASRDLN 4 #define ASRMCD 3 static int asrtlv_print(netdissect_options *ndo, register const u_char * pptr, register u_int len, uint16_t op_msk _U_, int indent) { uint32_t rescode; u_int dlen; char *ib = indent_pr(indent, 0); /* * forces_type_print() has ensured that len (the TLV length) * >= TLV_HDRL. */ dlen = len - TLV_HDRL; if (dlen != ASRDLN) { /* id, instance, oper tlv */ ND_PRINT((ndo, "illegal ASRresult-TLV: %d bytes!\n", dlen)); return -1; } ND_TCHECK2(*pptr, 4); rescode = EXTRACT_32BITS(pptr); if (rescode > ASRMCD) { ND_PRINT((ndo, "illegal ASRresult result code: %d!\n", rescode)); return -1; } if (ndo->ndo_vflag >= 3) { ND_PRINT((ndo, "\n%s", ib)); switch (rescode) { case 0: ND_PRINT((ndo, "Success ")); break; case 1: ND_PRINT((ndo, "FE ID invalid ")); break; case 2: ND_PRINT((ndo, "permission denied ")); break; default: ND_PRINT((ndo, "Unknown ")); break; } ND_PRINT((ndo, "(%x)\n%s", rescode, ib)); } return 0; trunc: ND_PRINT((ndo, "%s", tstr)); return -1; } #if 0 /* * XXX - not used. */ static int gentltlv_print(netdissect_options *ndo, register const u_char * pptr _U_, register u_int len, uint16_t op_msk _U_, int indent _U_) { u_int dlen = len - TLV_HDRL; if (dlen < 4) { /* at least 32 bits must exist */ ND_PRINT((ndo, "truncated TLV: %d bytes missing! ", 4 - dlen)); return -1; } return 0; } #endif #define RD_MIN 8 static int print_metailv(netdissect_options *ndo, register const u_char * pptr, uint16_t op_msk _U_, int indent) { u_int rlen; char *ib = indent_pr(indent, 0); /* XXX: check header length */ const struct forces_ilv *ilv = (const struct forces_ilv *)pptr; /* * print_metatlv() has ensured that len (what remains in the * ILV) >= ILV_HDRL. */ rlen = EXTRACT_32BITS(&ilv->length) - ILV_HDRL; ND_TCHECK(*ilv); ND_PRINT((ndo, "%sMetaID 0x%x length %d\n", ib, EXTRACT_32BITS(&ilv->type), EXTRACT_32BITS(&ilv->length))); if (ndo->ndo_vflag >= 3) { hex_print_with_offset(ndo, "\t\t[", ILV_DATA(ilv), rlen, 0); ND_PRINT((ndo, " ]\n")); } return 0; trunc: ND_PRINT((ndo, "%s", tstr)); return -1; } static int print_metatlv(netdissect_options *ndo, register const u_char * pptr, register u_int len, uint16_t op_msk _U_, int indent) { u_int dlen; char *ib = indent_pr(indent, 0); u_int rlen; const struct forces_ilv *ilv = (const struct forces_ilv *)pptr; int invilv; /* * redirect_print() has ensured that len (what remains in the * TLV) >= TLV_HDRL. */ dlen = len - TLV_HDRL; rlen = dlen; ND_PRINT((ndo, "\n%s METADATA length %d \n", ib, rlen)); while (rlen != 0) { ND_TCHECK(*ilv); invilv = ilv_valid(ilv, rlen); if (invilv) { break; } /* * At this point, ilv_valid() has ensured that the ILV * length is large enough but not too large (it doesn't * go past the end of the containing TLV). */ print_metailv(ndo, (const u_char *) ilv, 0, indent + 1); ilv = GO_NXT_ILV(ilv, rlen); } return 0; trunc: ND_PRINT((ndo, "%s", tstr)); return -1; } static int print_reddata(netdissect_options *ndo, register const u_char * pptr, register u_int len, uint16_t op_msk _U_, int indent) { u_int dlen; char *ib = indent_pr(indent, 0); u_int rlen; dlen = len - TLV_HDRL; rlen = dlen; ND_PRINT((ndo, "\n%s Redirect Data length %d \n", ib, rlen)); if (ndo->ndo_vflag >= 3) { ND_PRINT((ndo, "\t\t[")); hex_print_with_offset(ndo, "\n\t\t", pptr, rlen, 0); ND_PRINT((ndo, "\n\t\t]")); } return 0; } static int redirect_print(netdissect_options *ndo, register const u_char * pptr, register u_int len, uint16_t op_msk _U_, int indent) { const struct forces_tlv *tlv = (const struct forces_tlv *)pptr; u_int dlen; u_int rlen; u_int invtlv; /* * forces_type_print() has ensured that len (the TLV length) * >= TLV_HDRL. */ dlen = len - TLV_HDRL; if (dlen <= RD_MIN) { ND_PRINT((ndo, "\n\t\ttruncated Redirect TLV: %d bytes missing! ", RD_MIN - dlen)); return -1; } rlen = dlen; indent += 1; while (rlen != 0) { ND_TCHECK(*tlv); invtlv = tlv_valid(tlv, rlen); if (invtlv) { ND_PRINT((ndo, "Bad Redirect data\n")); break; } /* * At this point, tlv_valid() has ensured that the TLV * length is large enough but not too large (it doesn't * go past the end of the containing TLV). */ if (EXTRACT_16BITS(&tlv->type) == F_TLV_METD) { print_metatlv(ndo, (const u_char *) TLV_DATA(tlv), EXTRACT_16BITS(&tlv->length), 0, indent); } else if ((EXTRACT_16BITS(&tlv->type) == F_TLV_REDD)) { print_reddata(ndo, (const u_char *) TLV_DATA(tlv), EXTRACT_16BITS(&tlv->length), 0, indent); } else { ND_PRINT((ndo, "Unknown REDIRECT TLV 0x%x len %d\n", EXTRACT_16BITS(&tlv->type), EXTRACT_16BITS(&tlv->length))); } tlv = GO_NXT_TLV(tlv, rlen); } if (rlen) { ND_PRINT((ndo, "\n\t\tMessy Redirect TLV header, type (0x%x)\n\t\texcess of %d Bytes ", EXTRACT_16BITS(&tlv->type), rlen - EXTRACT_16BITS(&tlv->length))); return -1; } return 0; trunc: ND_PRINT((ndo, "%s", tstr)); return -1; } #define OP_OFF 8 #define OP_MIN 12 static int lfbselect_print(netdissect_options *ndo, register const u_char * pptr, register u_int len, uint16_t op_msk, int indent) { const struct forces_lfbsh *lfbs; const struct forces_tlv *otlv; char *ib = indent_pr(indent, 0); u_int dlen; u_int rlen; u_int invtlv; /* * forces_type_print() has ensured that len (the TLV length) * >= TLV_HDRL. */ dlen = len - TLV_HDRL; if (dlen <= OP_MIN) { /* id, instance, oper tlv header .. */ ND_PRINT((ndo, "\n\t\ttruncated lfb selector: %d bytes missing! ", OP_MIN - dlen)); return -1; } /* * At this point, we know that dlen > OP_MIN; OP_OFF < OP_MIN, so * we also know that it's > OP_OFF. */ rlen = dlen - OP_OFF; lfbs = (const struct forces_lfbsh *)pptr; ND_TCHECK(*lfbs); if (ndo->ndo_vflag >= 3) { ND_PRINT((ndo, "\n%s%s(Classid %x) instance %x\n", ib, tok2str(ForCES_LFBs, NULL, EXTRACT_32BITS(&lfbs->class)), EXTRACT_32BITS(&lfbs->class), EXTRACT_32BITS(&lfbs->instance))); } otlv = (const struct forces_tlv *)(lfbs + 1); indent += 1; while (rlen != 0) { ND_TCHECK(*otlv); invtlv = tlv_valid(otlv, rlen); if (invtlv) break; /* * At this point, tlv_valid() has ensured that the TLV * length is large enough but not too large (it doesn't * go past the end of the containing TLV). */ if (op_valid(EXTRACT_16BITS(&otlv->type), op_msk)) { otlv_print(ndo, otlv, 0, indent); } else { if (ndo->ndo_vflag < 3) ND_PRINT((ndo, "\n")); ND_PRINT((ndo, "\t\tINValid oper-TLV type 0x%x length %d for this ForCES message\n", EXTRACT_16BITS(&otlv->type), EXTRACT_16BITS(&otlv->length))); invoptlv_print(ndo, (const u_char *)otlv, rlen, 0, indent); } otlv = GO_NXT_TLV(otlv, rlen); } if (rlen) { ND_PRINT((ndo, "\n\t\tMessy oper TLV header, type (0x%x)\n\t\texcess of %d Bytes ", EXTRACT_16BITS(&otlv->type), rlen - EXTRACT_16BITS(&otlv->length))); return -1; } return 0; trunc: ND_PRINT((ndo, "%s", tstr)); return -1; } static int forces_type_print(netdissect_options *ndo, register const u_char * pptr, const struct forcesh *fhdr _U_, register u_int mlen, const struct tom_h *tops) { const struct forces_tlv *tltlv; u_int rlen; u_int invtlv; int rc = 0; int ttlv = 0; /* * forces_print() has already checked that mlen >= ForCES_HDRL * by calling ForCES_HLN_VALID(). */ rlen = mlen - ForCES_HDRL; if (rlen > TLV_HLN) { if (tops->flags & ZERO_TTLV) { ND_PRINT((ndo, "<0x%x>Illegal Top level TLV!\n", tops->flags)); return -1; } } else { if (tops->flags & ZERO_MORE_TTLV) return 0; if (tops->flags & ONE_MORE_TTLV) { ND_PRINT((ndo, "\tTop level TLV Data missing!\n")); return -1; } } if (tops->flags & ZERO_TTLV) { return 0; } ttlv = tops->flags >> 4; tltlv = GET_TOP_TLV(pptr); /*XXX: 15 top level tlvs will probably be fine You are nuts if you send more ;-> */ while (rlen != 0) { ND_TCHECK(*tltlv); invtlv = tlv_valid(tltlv, rlen); if (invtlv) break; /* * At this point, tlv_valid() has ensured that the TLV * length is large enough but not too large (it doesn't * go past the end of the packet). */ if (!ttlv_valid(EXTRACT_16BITS(&tltlv->type))) { ND_PRINT((ndo, "\n\tInvalid ForCES Top TLV type=0x%x", EXTRACT_16BITS(&tltlv->type))); return -1; } if (ndo->ndo_vflag >= 3) ND_PRINT((ndo, "\t%s, length %d (data length %d Bytes)", tok2str(ForCES_TLV, NULL, EXTRACT_16BITS(&tltlv->type)), EXTRACT_16BITS(&tltlv->length), EXTRACT_16BITS(&tltlv->length) - TLV_HDRL)); rc = tops->print(ndo, (const u_char *) TLV_DATA(tltlv), EXTRACT_16BITS(&tltlv->length), tops->op_msk, 9); if (rc < 0) { return -1; } tltlv = GO_NXT_TLV(tltlv, rlen); ttlv--; if (ttlv <= 0) break; } /* * XXX - if ttlv != 0, does that mean that the packet was too * short, and didn't have *enough* TLVs in it? */ if (rlen) { ND_PRINT((ndo, "\tMess TopTLV header: min %u, total %d advertised %d ", TLV_HDRL, rlen, EXTRACT_16BITS(&tltlv->length))); return -1; } return 0; trunc: ND_PRINT((ndo, "%s", tstr)); return -1; } void forces_print(netdissect_options *ndo, register const u_char * pptr, register u_int len) { const struct forcesh *fhdr; u_int mlen; uint32_t flg_raw; const struct tom_h *tops; int rc = 0; fhdr = (const struct forcesh *)pptr; ND_TCHECK(*fhdr); if (!tom_valid(fhdr->fm_tom)) { ND_PRINT((ndo, "Invalid ForCES message type %d\n", fhdr->fm_tom)); goto error; } mlen = ForCES_BLN(fhdr); tops = get_forces_tom(fhdr->fm_tom); if (tops->v == TOM_RSVD) { ND_PRINT((ndo, "\n\tUnknown ForCES message type=0x%x", fhdr->fm_tom)); goto error; } ND_PRINT((ndo, "\n\tForCES %s ", tops->s)); if (!ForCES_HLN_VALID(mlen, len)) { ND_PRINT((ndo, "Illegal ForCES pkt len - min %u, total recvd %d, advertised %d ", ForCES_HDRL, len, ForCES_BLN(fhdr))); goto error; } ND_TCHECK2(*(pptr + 20), 4); flg_raw = EXTRACT_32BITS(pptr + 20); if (ndo->ndo_vflag >= 1) { ND_PRINT((ndo, "\n\tForCES Version %d len %uB flags 0x%08x ", ForCES_V(fhdr), mlen, flg_raw)); ND_PRINT((ndo, "\n\tSrcID 0x%x(%s) DstID 0x%x(%s) Correlator 0x%" PRIx64, ForCES_SID(fhdr), ForCES_node(ForCES_SID(fhdr)), ForCES_DID(fhdr), ForCES_node(ForCES_DID(fhdr)), EXTRACT_64BITS(fhdr->fm_cor))); } if (ndo->ndo_vflag >= 2) { ND_PRINT((ndo, "\n\tForCES flags:\n\t %s(0x%x), prio=%d, %s(0x%x),\n\t %s(0x%x), %s(0x%x)\n", tok2str(ForCES_ACKs, "ACKUnknown", ForCES_ACK(fhdr)), ForCES_ACK(fhdr), ForCES_PRI(fhdr), tok2str(ForCES_EMs, "EMUnknown", ForCES_EM(fhdr)), ForCES_EM(fhdr), tok2str(ForCES_ATs, "ATUnknown", ForCES_AT(fhdr)), ForCES_AT(fhdr), tok2str(ForCES_TPs, "TPUnknown", ForCES_TP(fhdr)), ForCES_TP(fhdr))); ND_PRINT((ndo, "\t Extra flags: rsv(b5-7) 0x%x rsv(b13-31) 0x%x\n", ForCES_RS1(fhdr), ForCES_RS2(fhdr))); } rc = forces_type_print(ndo, pptr, fhdr, mlen, tops); if (rc < 0) { error: hex_print_with_offset(ndo, "\n\t[", pptr, len, 0); ND_PRINT((ndo, "\n\t]")); return; } if (ndo->ndo_vflag >= 4) { ND_PRINT((ndo, "\n\t Raw ForCES message\n\t [")); hex_print_with_offset(ndo, "\n\t ", pptr, len, 0); ND_PRINT((ndo, "\n\t ]")); } ND_PRINT((ndo, "\n")); return; trunc: ND_PRINT((ndo, "%s", tstr)); } /* * Local Variables: * c-style: whitesmith * c-basic-offset: 8 * End: */ tcpdump-4.9.3/print-gre.c0000644000026300017510000002334113544412561013411 0ustar mcrmcr/* $OpenBSD: print-gre.c,v 1.6 2002/10/30 03:04:04 fgsch Exp $ */ /* * Copyright (c) 2002 Jason L. Wright (jason@thought.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Jason L. Wright * 4. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /* \summary: Generic Routing Encapsulation (GRE) printer */ /* * netdissect printer for GRE - Generic Routing Encapsulation * RFC1701 (GRE), RFC1702 (GRE IPv4), and RFC2637 (Enhanced GRE) */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include "netdissect.h" #include "addrtostr.h" #include "extract.h" #include "ethertype.h" static const char tstr[] = "[|gre]"; #define GRE_CP 0x8000 /* checksum present */ #define GRE_RP 0x4000 /* routing present */ #define GRE_KP 0x2000 /* key present */ #define GRE_SP 0x1000 /* sequence# present */ #define GRE_sP 0x0800 /* source routing */ #define GRE_RECRS 0x0700 /* recursion count */ #define GRE_AP 0x0080 /* acknowledgment# present */ static const struct tok gre_flag_values[] = { { GRE_CP, "checksum present"}, { GRE_RP, "routing present"}, { GRE_KP, "key present"}, { GRE_SP, "sequence# present"}, { GRE_sP, "source routing present"}, { GRE_RECRS, "recursion count"}, { GRE_AP, "ack present"}, { 0, NULL } }; #define GRE_VERS_MASK 0x0007 /* protocol version */ /* source route entry types */ #define GRESRE_IP 0x0800 /* IP */ #define GRESRE_ASN 0xfffe /* ASN */ static void gre_print_0(netdissect_options *, const u_char *, u_int); static void gre_print_1(netdissect_options *, const u_char *, u_int); static int gre_sre_print(netdissect_options *, uint16_t, uint8_t, uint8_t, const u_char *, u_int); static int gre_sre_ip_print(netdissect_options *, uint8_t, uint8_t, const u_char *, u_int); static int gre_sre_asn_print(netdissect_options *, uint8_t, uint8_t, const u_char *, u_int); void gre_print(netdissect_options *ndo, const u_char *bp, u_int length) { u_int len = length, vers; ND_TCHECK2(*bp, 2); if (len < 2) goto trunc; vers = EXTRACT_16BITS(bp) & GRE_VERS_MASK; ND_PRINT((ndo, "GREv%u",vers)); switch(vers) { case 0: gre_print_0(ndo, bp, len); break; case 1: gre_print_1(ndo, bp, len); break; default: ND_PRINT((ndo, " ERROR: unknown-version")); break; } return; trunc: ND_PRINT((ndo, "%s", tstr)); return; } static void gre_print_0(netdissect_options *ndo, const u_char *bp, u_int length) { u_int len = length; uint16_t flags, prot; flags = EXTRACT_16BITS(bp); if (ndo->ndo_vflag) ND_PRINT((ndo, ", Flags [%s]", bittok2str(gre_flag_values,"none",flags))); len -= 2; bp += 2; ND_TCHECK2(*bp, 2); if (len < 2) goto trunc; prot = EXTRACT_16BITS(bp); len -= 2; bp += 2; if ((flags & GRE_CP) | (flags & GRE_RP)) { ND_TCHECK2(*bp, 2); if (len < 2) goto trunc; if (ndo->ndo_vflag) ND_PRINT((ndo, ", sum 0x%x", EXTRACT_16BITS(bp))); bp += 2; len -= 2; ND_TCHECK2(*bp, 2); if (len < 2) goto trunc; ND_PRINT((ndo, ", off 0x%x", EXTRACT_16BITS(bp))); bp += 2; len -= 2; } if (flags & GRE_KP) { ND_TCHECK2(*bp, 4); if (len < 4) goto trunc; ND_PRINT((ndo, ", key=0x%x", EXTRACT_32BITS(bp))); bp += 4; len -= 4; } if (flags & GRE_SP) { ND_TCHECK2(*bp, 4); if (len < 4) goto trunc; ND_PRINT((ndo, ", seq %u", EXTRACT_32BITS(bp))); bp += 4; len -= 4; } if (flags & GRE_RP) { for (;;) { uint16_t af; uint8_t sreoff; uint8_t srelen; ND_TCHECK2(*bp, 4); if (len < 4) goto trunc; af = EXTRACT_16BITS(bp); sreoff = *(bp + 2); srelen = *(bp + 3); bp += 4; len -= 4; if (af == 0 && srelen == 0) break; if (!gre_sre_print(ndo, af, sreoff, srelen, bp, len)) goto trunc; if (len < srelen) goto trunc; bp += srelen; len -= srelen; } } if (ndo->ndo_eflag) ND_PRINT((ndo, ", proto %s (0x%04x)", tok2str(ethertype_values,"unknown",prot), prot)); ND_PRINT((ndo, ", length %u",length)); if (ndo->ndo_vflag < 1) ND_PRINT((ndo, ": ")); /* put in a colon as protocol demarc */ else ND_PRINT((ndo, "\n\t")); /* if verbose go multiline */ switch (prot) { case ETHERTYPE_IP: ip_print(ndo, bp, len); break; case ETHERTYPE_IPV6: ip6_print(ndo, bp, len); break; case ETHERTYPE_MPLS: mpls_print(ndo, bp, len); break; case ETHERTYPE_IPX: ipx_print(ndo, bp, len); break; case ETHERTYPE_ATALK: atalk_print(ndo, bp, len); break; case ETHERTYPE_GRE_ISO: isoclns_print(ndo, bp, len); break; case ETHERTYPE_TEB: ether_print(ndo, bp, len, ndo->ndo_snapend - bp, NULL, NULL); break; default: ND_PRINT((ndo, "gre-proto-0x%x", prot)); } return; trunc: ND_PRINT((ndo, "%s", tstr)); } static void gre_print_1(netdissect_options *ndo, const u_char *bp, u_int length) { u_int len = length; uint16_t flags, prot; flags = EXTRACT_16BITS(bp); len -= 2; bp += 2; if (ndo->ndo_vflag) ND_PRINT((ndo, ", Flags [%s]", bittok2str(gre_flag_values,"none",flags))); ND_TCHECK2(*bp, 2); if (len < 2) goto trunc; prot = EXTRACT_16BITS(bp); len -= 2; bp += 2; if (flags & GRE_KP) { uint32_t k; ND_TCHECK2(*bp, 4); if (len < 4) goto trunc; k = EXTRACT_32BITS(bp); ND_PRINT((ndo, ", call %d", k & 0xffff)); len -= 4; bp += 4; } if (flags & GRE_SP) { ND_TCHECK2(*bp, 4); if (len < 4) goto trunc; ND_PRINT((ndo, ", seq %u", EXTRACT_32BITS(bp))); bp += 4; len -= 4; } if (flags & GRE_AP) { ND_TCHECK2(*bp, 4); if (len < 4) goto trunc; ND_PRINT((ndo, ", ack %u", EXTRACT_32BITS(bp))); bp += 4; len -= 4; } if ((flags & GRE_SP) == 0) ND_PRINT((ndo, ", no-payload")); if (ndo->ndo_eflag) ND_PRINT((ndo, ", proto %s (0x%04x)", tok2str(ethertype_values,"unknown",prot), prot)); ND_PRINT((ndo, ", length %u",length)); if ((flags & GRE_SP) == 0) return; if (ndo->ndo_vflag < 1) ND_PRINT((ndo, ": ")); /* put in a colon as protocol demarc */ else ND_PRINT((ndo, "\n\t")); /* if verbose go multiline */ switch (prot) { case ETHERTYPE_PPP: ppp_print(ndo, bp, len); break; default: ND_PRINT((ndo, "gre-proto-0x%x", prot)); break; } return; trunc: ND_PRINT((ndo, "%s", tstr)); } static int gre_sre_print(netdissect_options *ndo, uint16_t af, uint8_t sreoff, uint8_t srelen, const u_char *bp, u_int len) { int ret; switch (af) { case GRESRE_IP: ND_PRINT((ndo, ", (rtaf=ip")); ret = gre_sre_ip_print(ndo, sreoff, srelen, bp, len); ND_PRINT((ndo, ")")); break; case GRESRE_ASN: ND_PRINT((ndo, ", (rtaf=asn")); ret = gre_sre_asn_print(ndo, sreoff, srelen, bp, len); ND_PRINT((ndo, ")")); break; default: ND_PRINT((ndo, ", (rtaf=0x%x)", af)); ret = 1; } return (ret); } static int gre_sre_ip_print(netdissect_options *ndo, uint8_t sreoff, uint8_t srelen, const u_char *bp, u_int len) { const u_char *up = bp; char buf[INET_ADDRSTRLEN]; if (sreoff & 3) { ND_PRINT((ndo, ", badoffset=%u", sreoff)); return (1); } if (srelen & 3) { ND_PRINT((ndo, ", badlength=%u", srelen)); return (1); } if (sreoff >= srelen) { ND_PRINT((ndo, ", badoff/len=%u/%u", sreoff, srelen)); return (1); } while (srelen != 0) { if (!ND_TTEST2(*bp, 4)) return (0); if (len < 4) return (0); addrtostr(bp, buf, sizeof(buf)); ND_PRINT((ndo, " %s%s", ((bp - up) == sreoff) ? "*" : "", buf)); bp += 4; len -= 4; srelen -= 4; } return (1); } static int gre_sre_asn_print(netdissect_options *ndo, uint8_t sreoff, uint8_t srelen, const u_char *bp, u_int len) { const u_char *up = bp; if (sreoff & 1) { ND_PRINT((ndo, ", badoffset=%u", sreoff)); return (1); } if (srelen & 1) { ND_PRINT((ndo, ", badlength=%u", srelen)); return (1); } if (sreoff >= srelen) { ND_PRINT((ndo, ", badoff/len=%u/%u", sreoff, srelen)); return (1); } while (srelen != 0) { if (!ND_TTEST2(*bp, 2)) return (0); if (len < 2) return (0); ND_PRINT((ndo, " %s%x", ((bp - up) == sreoff) ? "*" : "", EXTRACT_16BITS(bp))); bp += 2; len -= 2; srelen -= 2; } return (1); } tcpdump-4.9.3/ah.h0000644000026300017510000000454013544412561012077 0ustar mcrmcr/* $NetBSD: ah.h,v 1.12 2000/07/23 05:23:04 itojun Exp $ */ /* $KAME: ah.h,v 1.12 2000/07/20 17:41:01 itojun Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the project nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * RFC1826/2402 authentication header. */ #ifndef _NETINET6_AH_H_ #define _NETINET6_AH_H_ struct ah { uint8_t ah_nxt; /* Next Header */ uint8_t ah_len; /* Length of data, in 32bit */ uint16_t ah_reserve; /* Reserved for future use */ uint32_t ah_spi; /* Security parameter index */ /* variable size, 32bit bound*/ /* Authentication data */ }; struct newah { uint8_t ah_nxt; /* Next Header */ uint8_t ah_len; /* Length of data + 1, in 32bit */ uint16_t ah_reserve; /* Reserved for future use */ uint32_t ah_spi; /* Security parameter index */ uint32_t ah_seq; /* Sequence number field */ /* variable size, 32bit bound*/ /* Authentication data */ }; #endif /*_NETINET6_AH_H_*/ tcpdump-4.9.3/print-cip.c0000644000026300017510000000500213544412561013401 0ustar mcrmcr/* * Marko Kiiskila carnil@cs.tut.fi * * Tampere University of Technology - Telecommunications Laboratory * * Permission to use, copy, modify and distribute this * software and its documentation is hereby granted, * provided that both the copyright notice and this * permission notice appear in all copies of the software, * derivative works or modified versions, and any portions * thereof, that both notices appear in supporting * documentation, and that the use of this software is * acknowledged in any publications resulting from using * the software. * * TUT ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION AND DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS * SOFTWARE. * */ /* \summary: Classical-IP over ATM printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include "netdissect.h" #include "addrtoname.h" static const unsigned char rfcllc[] = { 0xaa, /* DSAP: non-ISO */ 0xaa, /* SSAP: non-ISO */ 0x03, /* Ctrl: Unnumbered Information Command PDU */ 0x00, /* OUI: EtherType */ 0x00, 0x00 }; static inline void cip_print(netdissect_options *ndo, u_int length) { /* * There is no MAC-layer header, so just print the length. */ ND_PRINT((ndo, "%u: ", length)); } /* * This is the top level routine of the printer. 'p' points * to the LLC/SNAP or raw header of the packet, 'h->ts' is the timestamp, * 'h->len' is the length of the packet off the wire, and 'h->caplen' * is the number of bytes actually captured. */ u_int cip_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) { u_int caplen = h->caplen; u_int length = h->len; size_t cmplen; int llc_hdrlen; cmplen = sizeof(rfcllc); if (cmplen > caplen) cmplen = caplen; if (cmplen > length) cmplen = length; if (ndo->ndo_eflag) cip_print(ndo, length); if (cmplen == 0) { ND_PRINT((ndo, "[|cip]")); return 0; } if (memcmp(rfcllc, p, cmplen) == 0) { /* * LLC header is present. Try to print it & higher layers. */ llc_hdrlen = llc_print(ndo, p, length, caplen, NULL, NULL); if (llc_hdrlen < 0) { /* packet type not known, print raw packet */ if (!ndo->ndo_suppress_default_print) ND_DEFAULTPRINT(p, caplen); llc_hdrlen = -llc_hdrlen; } } else { /* * LLC header is absent; treat it as just IP. */ llc_hdrlen = 0; ip_print(ndo, p, length); } return (llc_hdrlen); } /* * Local Variables: * c-style: whitesmith * c-basic-offset: 8 * End: */ tcpdump-4.9.3/print-cdp.c0000644000026300017510000002625013544412561013404 0ustar mcrmcr/* * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of * the University nor the names of its contributors may be used to endorse * or promote products derived from this software without specific prior * written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * Code by Gert Doering, SpaceNet GmbH, gert@space.net * * Reference documentation: * http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/frames.htm */ /* \summary: Cisco Discovery Protocol (CDP) printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include "netdissect.h" #include "addrtoname.h" #include "extract.h" #include "nlpid.h" static const char tstr[] = "[|cdp]"; #define CDP_HEADER_LEN 4 #define CDP_HEADER_VERSION_OFFSET 0 #define CDP_HEADER_TTL_OFFSET 1 #define CDP_HEADER_CHECKSUM_OFFSET 2 #define CDP_TLV_HEADER_LEN 4 #define CDP_TLV_TYPE_OFFSET 0 #define CDP_TLV_LEN_OFFSET 2 static const struct tok cdp_tlv_values[] = { { 0x01, "Device-ID"}, { 0x02, "Address"}, { 0x03, "Port-ID"}, { 0x04, "Capability"}, { 0x05, "Version String"}, { 0x06, "Platform"}, { 0x07, "Prefixes"}, { 0x08, "Protocol-Hello option"}, { 0x09, "VTP Management Domain"}, { 0x0a, "Native VLAN ID"}, { 0x0b, "Duplex"}, { 0x0e, "ATA-186 VoIP VLAN request"}, { 0x0f, "ATA-186 VoIP VLAN assignment"}, { 0x10, "power consumption"}, { 0x11, "MTU"}, { 0x12, "AVVID trust bitmap"}, { 0x13, "AVVID untrusted ports CoS"}, { 0x14, "System Name"}, { 0x15, "System Object ID (not decoded)"}, { 0x16, "Management Addresses"}, { 0x17, "Physical Location"}, { 0, NULL} }; static const struct tok cdp_capability_values[] = { { 0x01, "Router" }, { 0x02, "Transparent Bridge" }, { 0x04, "Source Route Bridge" }, { 0x08, "L2 Switch" }, { 0x10, "L3 capable" }, { 0x20, "IGMP snooping" }, { 0x40, "L1 capable" }, { 0, NULL } }; static int cdp_print_addr(netdissect_options *, const u_char *, int); static int cdp_print_prefixes(netdissect_options *, const u_char *, int); static unsigned long cdp_get_number(const u_char *, int); void cdp_print(netdissect_options *ndo, const u_char *pptr, u_int length, u_int caplen) { int type, len, i, j; const u_char *tptr; if (caplen < CDP_HEADER_LEN) { ND_PRINT((ndo, "%s", tstr)); return; } tptr = pptr; /* temporary pointer */ ND_TCHECK2(*tptr, CDP_HEADER_LEN); ND_PRINT((ndo, "CDPv%u, ttl: %us", *(tptr + CDP_HEADER_VERSION_OFFSET), *(tptr + CDP_HEADER_TTL_OFFSET))); if (ndo->ndo_vflag) ND_PRINT((ndo, ", checksum: 0x%04x (unverified), length %u", EXTRACT_16BITS(tptr+CDP_HEADER_CHECKSUM_OFFSET), length)); tptr += CDP_HEADER_LEN; while (tptr < (pptr+length)) { ND_TCHECK2(*tptr, CDP_TLV_HEADER_LEN); /* read out Type and Length */ type = EXTRACT_16BITS(tptr+CDP_TLV_TYPE_OFFSET); len = EXTRACT_16BITS(tptr+CDP_TLV_LEN_OFFSET); /* object length includes the 4 bytes header length */ if (len < CDP_TLV_HEADER_LEN) { if (ndo->ndo_vflag) ND_PRINT((ndo, "\n\t%s (0x%02x), TLV length: %u byte%s (too short)", tok2str(cdp_tlv_values,"unknown field type", type), type, len, PLURAL_SUFFIX(len))); /* plural */ else ND_PRINT((ndo, ", %s TLV length %u too short", tok2str(cdp_tlv_values,"unknown field type", type), len)); break; } tptr += CDP_TLV_HEADER_LEN; len -= CDP_TLV_HEADER_LEN; ND_TCHECK2(*tptr, len); if (ndo->ndo_vflag || type == 1) { /* in non-verbose mode just print Device-ID */ if (ndo->ndo_vflag) ND_PRINT((ndo, "\n\t%s (0x%02x), value length: %u byte%s: ", tok2str(cdp_tlv_values,"unknown field type", type), type, len, PLURAL_SUFFIX(len))); /* plural */ switch (type) { case 0x01: /* Device-ID */ if (!ndo->ndo_vflag) ND_PRINT((ndo, ", Device-ID ")); ND_PRINT((ndo, "'")); (void)fn_printn(ndo, tptr, len, NULL); ND_PRINT((ndo, "'")); break; case 0x02: /* Address */ if (cdp_print_addr(ndo, tptr, len) < 0) goto trunc; break; case 0x03: /* Port-ID */ ND_PRINT((ndo, "'")); (void)fn_printn(ndo, tptr, len, NULL); ND_PRINT((ndo, "'")); break; case 0x04: /* Capabilities */ if (len < 4) goto trunc; ND_PRINT((ndo, "(0x%08x): %s", EXTRACT_32BITS(tptr), bittok2str(cdp_capability_values, "none", EXTRACT_32BITS(tptr)))); break; case 0x05: /* Version */ ND_PRINT((ndo, "\n\t ")); for (i=0;i 1) { ND_PRINT((ndo, "/")); (void)fn_printn(ndo, tptr + 1, len - 1, NULL); } break; default: print_unknown_data(ndo, tptr, "\n\t ", len); break; } } tptr = tptr+len; } if (ndo->ndo_vflag < 1) ND_PRINT((ndo, ", length %u", caplen)); return; trunc: ND_PRINT((ndo, "%s", tstr)); } /* * Protocol type values. * * PT_NLPID means that the protocol type field contains an OSI NLPID. * * PT_IEEE_802_2 means that the protocol type field contains an IEEE 802.2 * LLC header that specifies that the payload is for that protocol. */ #define PT_NLPID 1 /* OSI NLPID */ #define PT_IEEE_802_2 2 /* IEEE 802.2 LLC header */ static int cdp_print_addr(netdissect_options *ndo, const u_char * p, int l) { int pt, pl, al, num; const u_char *endp = p + l; static const u_char prot_ipv6[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x86, 0xdd }; ND_TCHECK2(*p, 4); if (p + 4 > endp) goto trunc; num = EXTRACT_32BITS(p); p += 4; while (p < endp && num >= 0) { ND_TCHECK2(*p, 2); if (p + 2 > endp) goto trunc; pt = p[0]; /* type of "protocol" field */ pl = p[1]; /* length of "protocol" field */ p += 2; ND_TCHECK2(p[pl], 2); if (p + pl + 2 > endp) goto trunc; al = EXTRACT_16BITS(&p[pl]); /* address length */ if (pt == PT_NLPID && pl == 1 && *p == NLPID_IP && al == 4) { /* * IPv4: protocol type = NLPID, protocol length = 1 * (1-byte NLPID), protocol = 0xcc (NLPID for IPv4), * address length = 4 */ p += 3; ND_TCHECK2(*p, 4); if (p + 4 > endp) goto trunc; ND_PRINT((ndo, "IPv4 (%u) %s", num, ipaddr_string(ndo, p))); p += 4; } else if (pt == PT_IEEE_802_2 && pl == 8 && memcmp(p, prot_ipv6, 8) == 0 && al == 16) { /* * IPv6: protocol type = IEEE 802.2 header, * protocol length = 8 (size of LLC+SNAP header), * protocol = LLC+SNAP header with the IPv6 * Ethertype, address length = 16 */ p += 10; ND_TCHECK2(*p, al); if (p + al > endp) goto trunc; ND_PRINT((ndo, "IPv6 (%u) %s", num, ip6addr_string(ndo, p))); p += al; } else { /* * Generic case: just print raw data */ ND_TCHECK2(*p, pl); if (p + pl > endp) goto trunc; ND_PRINT((ndo, "pt=0x%02x, pl=%d, pb=", *(p - 2), pl)); while (pl-- > 0) ND_PRINT((ndo, " %02x", *p++)); ND_TCHECK2(*p, 2); if (p + 2 > endp) goto trunc; al = (*p << 8) + *(p + 1); ND_PRINT((ndo, ", al=%d, a=", al)); p += 2; ND_TCHECK2(*p, al); if (p + al > endp) goto trunc; while (al-- > 0) ND_PRINT((ndo, " %02x", *p++)); } num--; if (num) ND_PRINT((ndo, " ")); } return 0; trunc: return -1; } static int cdp_print_prefixes(netdissect_options *ndo, const u_char * p, int l) { if (l % 5) goto trunc; ND_PRINT((ndo, " IPv4 Prefixes (%d):", l / 5)); while (l > 0) { ND_PRINT((ndo, " %u.%u.%u.%u/%u", p[0], p[1], p[2], p[3], p[4])); l -= 5; p += 5; } return 0; trunc: return -1; } /* read in a -byte number, MSB first * (of course this can handle max sizeof(long)) */ static unsigned long cdp_get_number(const u_char * p, int l) { unsigned long res=0; while( l>0 ) { res = (res<<8) + *p; p++; l--; } return res; } tcpdump-4.9.3/print-sunatm.c0000644000026300017510000000642213544412561014144 0ustar mcrmcr/* * Copyright (c) 1997 Yen Yen Lim and North Dakota State University * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Yen Yen Lim and North Dakota State University * 4. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /* \summary: SunATM DLPI capture printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include struct mbuf; struct rtentry; #include "netdissect.h" #include "extract.h" #include "atm.h" /* SunATM header for ATM packet */ #define DIR_POS 0 /* Direction (0x80 = transmit, 0x00 = receive) */ #define VPI_POS 1 /* VPI */ #define VCI_POS 2 /* VCI */ #define PKT_BEGIN_POS 4 /* Start of the ATM packet */ /* Protocol type values in the bottom for bits of the byte at SUNATM_DIR_POS. */ #define PT_LANE 0x01 /* LANE */ #define PT_LLC 0x02 /* LLC encapsulation */ /* * This is the top level routine of the printer. 'p' points * to the SunATM pseudo-header for the packet, 'h->ts' is the timestamp, * 'h->len' is the length of the packet off the wire, and 'h->caplen' * is the number of bytes actually captured. */ u_int sunatm_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) { u_int caplen = h->caplen; u_int length = h->len; u_short vci; u_char vpi; u_int traftype; if (caplen < PKT_BEGIN_POS) { ND_PRINT((ndo, "[|atm]")); return (caplen); } if (ndo->ndo_eflag) { ND_PRINT((ndo, p[DIR_POS] & 0x80 ? "Tx: " : "Rx: ")); } switch (p[DIR_POS] & 0x0f) { case PT_LANE: traftype = ATM_LANE; break; case PT_LLC: traftype = ATM_LLC; break; default: traftype = ATM_UNKNOWN; break; } vci = EXTRACT_16BITS(&p[VCI_POS]); vpi = p[VPI_POS]; p += PKT_BEGIN_POS; caplen -= PKT_BEGIN_POS; length -= PKT_BEGIN_POS; atm_print(ndo, vpi, vci, traftype, p, length, caplen); return (PKT_BEGIN_POS); } tcpdump-4.9.3/print-aoe.c0000644000026300017510000002620713544412724013405 0ustar mcrmcr/* * Copyright (c) 2014 The TCPDUMP project * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /* \summary: ATA over Ethernet (AoE) protocol printer */ /* specification: http://brantleycoilecompany.com/AoEr11.pdf */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #include "extract.h" #include "addrtoname.h" #include "ether.h" static const char tstr[] = " [|aoe]"; #define AOE_V1 1 #define ATA_SECTOR_SIZE 512 #define AOEV1_CMD_ISSUE_ATA_COMMAND 0 #define AOEV1_CMD_QUERY_CONFIG_INFORMATION 1 #define AOEV1_CMD_MAC_MASK_LIST 2 #define AOEV1_CMD_RESERVE_RELEASE 3 static const struct tok cmdcode_str[] = { { AOEV1_CMD_ISSUE_ATA_COMMAND, "Issue ATA Command" }, { AOEV1_CMD_QUERY_CONFIG_INFORMATION, "Query Config Information" }, { AOEV1_CMD_MAC_MASK_LIST, "MAC Mask List" }, { AOEV1_CMD_RESERVE_RELEASE, "Reserve/Release" }, { 0, NULL } }; #define AOEV1_COMMON_HDR_LEN 10U /* up to but w/o Arg */ #define AOEV1_ISSUE_ARG_LEN 12U /* up to but w/o Data */ #define AOEV1_QUERY_ARG_LEN 8U /* up to but w/o Config String */ #define AOEV1_MAC_ARG_LEN 4U /* up to but w/o Directive 0 */ #define AOEV1_RESERVE_ARG_LEN 2U /* up to but w/o Ethernet address 0 */ #define AOEV1_MAX_CONFSTR_LEN 1024U #define AOEV1_FLAG_R 0x08 #define AOEV1_FLAG_E 0x04 static const struct tok aoev1_flag_str[] = { { AOEV1_FLAG_R, "Response" }, { AOEV1_FLAG_E, "Error" }, { 0x02, "MBZ-0x02" }, { 0x01, "MBZ-0x01" }, { 0, NULL } }; static const struct tok aoev1_errcode_str[] = { { 1, "Unrecognized command code" }, { 2, "Bad argument parameter" }, { 3, "Device unavailable" }, { 4, "Config string present" }, { 5, "Unsupported version" }, { 6, "Target is reserved" }, { 0, NULL } }; #define AOEV1_AFLAG_E 0x40 #define AOEV1_AFLAG_D 0x10 #define AOEV1_AFLAG_A 0x02 #define AOEV1_AFLAG_W 0x01 static const struct tok aoev1_aflag_str[] = { { 0x08, "MBZ-0x08" }, { AOEV1_AFLAG_E, "Ext48" }, { 0x06, "MBZ-0x06" }, { AOEV1_AFLAG_D, "Device" }, { 0x04, "MBZ-0x04" }, { 0x03, "MBZ-0x03" }, { AOEV1_AFLAG_A, "Async" }, { AOEV1_AFLAG_W, "Write" }, { 0, NULL } }; static const struct tok aoev1_ccmd_str[] = { { 0, "read config string" }, { 1, "test config string" }, { 2, "test config string prefix" }, { 3, "set config string" }, { 4, "force set config string" }, { 0, NULL } }; static const struct tok aoev1_mcmd_str[] = { { 0, "Read Mac Mask List" }, { 1, "Edit Mac Mask List" }, { 0, NULL } }; static const struct tok aoev1_merror_str[] = { { 1, "Unspecified Error" }, { 2, "Bad DCmd directive" }, { 3, "Mask list full" }, { 0, NULL } }; static const struct tok aoev1_dcmd_str[] = { { 0, "No Directive" }, { 1, "Add mac address to mask list" }, { 2, "Delete mac address from mask list" }, { 0, NULL } }; static const struct tok aoev1_rcmd_str[] = { { 0, "Read reserve list" }, { 1, "Set reserve list" }, { 2, "Force set reserve list" }, { 0, NULL } }; static void aoev1_issue_print(netdissect_options *ndo, const u_char *cp, const u_int len) { const u_char *ep = cp + len; if (len < AOEV1_ISSUE_ARG_LEN) goto invalid; /* AFlags */ ND_TCHECK2(*cp, 1); ND_PRINT((ndo, "\n\tAFlags: [%s]", bittok2str(aoev1_aflag_str, "none", *cp))); cp += 1; /* Err/Feature */ ND_TCHECK2(*cp, 1); ND_PRINT((ndo, ", Err/Feature: %u", *cp)); cp += 1; /* Sector Count (not correlated with the length) */ ND_TCHECK2(*cp, 1); ND_PRINT((ndo, ", Sector Count: %u", *cp)); cp += 1; /* Cmd/Status */ ND_TCHECK2(*cp, 1); ND_PRINT((ndo, ", Cmd/Status: %u", *cp)); cp += 1; /* lba0 */ ND_TCHECK2(*cp, 1); ND_PRINT((ndo, "\n\tlba0: %u", *cp)); cp += 1; /* lba1 */ ND_TCHECK2(*cp, 1); ND_PRINT((ndo, ", lba1: %u", *cp)); cp += 1; /* lba2 */ ND_TCHECK2(*cp, 1); ND_PRINT((ndo, ", lba2: %u", *cp)); cp += 1; /* lba3 */ ND_TCHECK2(*cp, 1); ND_PRINT((ndo, ", lba3: %u", *cp)); cp += 1; /* lba4 */ ND_TCHECK2(*cp, 1); ND_PRINT((ndo, ", lba4: %u", *cp)); cp += 1; /* lba5 */ ND_TCHECK2(*cp, 1); ND_PRINT((ndo, ", lba5: %u", *cp)); cp += 1; /* Reserved */ ND_TCHECK2(*cp, 2); cp += 2; /* Data */ if (len > AOEV1_ISSUE_ARG_LEN) ND_PRINT((ndo, "\n\tData: %u bytes", len - AOEV1_ISSUE_ARG_LEN)); return; invalid: ND_PRINT((ndo, "%s", istr)); ND_TCHECK2(*cp, ep - cp); return; trunc: ND_PRINT((ndo, "%s", tstr)); } static void aoev1_query_print(netdissect_options *ndo, const u_char *cp, const u_int len) { const u_char *ep = cp + len; uint16_t cslen; if (len < AOEV1_QUERY_ARG_LEN) goto invalid; /* Buffer Count */ ND_TCHECK2(*cp, 2); ND_PRINT((ndo, "\n\tBuffer Count: %u", EXTRACT_16BITS(cp))); cp += 2; /* Firmware Version */ ND_TCHECK2(*cp, 2); ND_PRINT((ndo, ", Firmware Version: %u", EXTRACT_16BITS(cp))); cp += 2; /* Sector Count */ ND_TCHECK2(*cp, 1); ND_PRINT((ndo, ", Sector Count: %u", *cp)); cp += 1; /* AoE/CCmd */ ND_TCHECK2(*cp, 1); ND_PRINT((ndo, ", AoE: %u, CCmd: %s", (*cp & 0xF0) >> 4, tok2str(aoev1_ccmd_str, "Unknown (0x02x)", *cp & 0x0F))); cp += 1; /* Config String Length */ ND_TCHECK2(*cp, 2); cslen = EXTRACT_16BITS(cp); cp += 2; if (cslen > AOEV1_MAX_CONFSTR_LEN || AOEV1_QUERY_ARG_LEN + cslen > len) goto invalid; /* Config String */ ND_TCHECK2(*cp, cslen); if (cslen) { ND_PRINT((ndo, "\n\tConfig String (length %u): ", cslen)); if (fn_printn(ndo, cp, cslen, ndo->ndo_snapend)) goto trunc; } return; invalid: ND_PRINT((ndo, "%s", istr)); ND_TCHECK2(*cp, ep - cp); return; trunc: ND_PRINT((ndo, "%s", tstr)); } static void aoev1_mac_print(netdissect_options *ndo, const u_char *cp, const u_int len) { const u_char *ep = cp + len; uint8_t dircount, i; if (len < AOEV1_MAC_ARG_LEN) goto invalid; /* Reserved */ ND_TCHECK2(*cp, 1); cp += 1; /* MCmd */ ND_TCHECK2(*cp, 1); ND_PRINT((ndo, "\n\tMCmd: %s", tok2str(aoev1_mcmd_str, "Unknown (0x%02x)", *cp))); cp += 1; /* MError */ ND_TCHECK2(*cp, 1); ND_PRINT((ndo, ", MError: %s", tok2str(aoev1_merror_str, "Unknown (0x%02x)", *cp))); cp += 1; /* Dir Count */ ND_TCHECK2(*cp, 1); dircount = *cp; cp += 1; ND_PRINT((ndo, ", Dir Count: %u", dircount)); if (AOEV1_MAC_ARG_LEN + dircount * 8 > len) goto invalid; /* directives */ for (i = 0; i < dircount; i++) { /* Reserved */ ND_TCHECK2(*cp, 1); cp += 1; /* DCmd */ ND_TCHECK2(*cp, 1); ND_PRINT((ndo, "\n\t DCmd: %s", tok2str(aoev1_dcmd_str, "Unknown (0x%02x)", *cp))); cp += 1; /* Ethernet Address */ ND_TCHECK2(*cp, ETHER_ADDR_LEN); ND_PRINT((ndo, ", Ethernet Address: %s", etheraddr_string(ndo, cp))); cp += ETHER_ADDR_LEN; } return; invalid: ND_PRINT((ndo, "%s", istr)); ND_TCHECK2(*cp, ep - cp); return; trunc: ND_PRINT((ndo, "%s", tstr)); } static void aoev1_reserve_print(netdissect_options *ndo, const u_char *cp, const u_int len) { const u_char *ep = cp + len; uint8_t nmacs, i; if (len < AOEV1_RESERVE_ARG_LEN || (len - AOEV1_RESERVE_ARG_LEN) % ETHER_ADDR_LEN) goto invalid; /* RCmd */ ND_TCHECK2(*cp, 1); ND_PRINT((ndo, "\n\tRCmd: %s", tok2str(aoev1_rcmd_str, "Unknown (0x%02x)", *cp))); cp += 1; /* NMacs (correlated with the length) */ ND_TCHECK2(*cp, 1); nmacs = *cp; cp += 1; ND_PRINT((ndo, ", NMacs: %u", nmacs)); if (AOEV1_RESERVE_ARG_LEN + nmacs * ETHER_ADDR_LEN != len) goto invalid; /* addresses */ for (i = 0; i < nmacs; i++) { ND_TCHECK2(*cp, ETHER_ADDR_LEN); ND_PRINT((ndo, "\n\tEthernet Address %u: %s", i, etheraddr_string(ndo, cp))); cp += ETHER_ADDR_LEN; } return; invalid: ND_PRINT((ndo, "%s", istr)); ND_TCHECK2(*cp, ep - cp); return; trunc: ND_PRINT((ndo, "%s", tstr)); } /* cp points to the Ver/Flags octet */ static void aoev1_print(netdissect_options *ndo, const u_char *cp, const u_int len) { const u_char *ep = cp + len; uint8_t flags, command; void (*cmd_decoder)(netdissect_options *, const u_char *, const u_int); if (len < AOEV1_COMMON_HDR_LEN) goto invalid; /* Flags */ ND_TCHECK2(*cp, 1); flags = *cp & 0x0F; ND_PRINT((ndo, ", Flags: [%s]", bittok2str(aoev1_flag_str, "none", flags))); cp += 1; if (! ndo->ndo_vflag) return; /* Error */ ND_TCHECK2(*cp, 1); if (flags & AOEV1_FLAG_E) ND_PRINT((ndo, "\n\tError: %s", tok2str(aoev1_errcode_str, "Invalid (%u)", *cp))); cp += 1; /* Major */ ND_TCHECK2(*cp, 2); ND_PRINT((ndo, "\n\tMajor: 0x%04x", EXTRACT_16BITS(cp))); cp += 2; /* Minor */ ND_TCHECK2(*cp, 1); ND_PRINT((ndo, ", Minor: 0x%02x", *cp)); cp += 1; /* Command */ ND_TCHECK2(*cp, 1); command = *cp; cp += 1; ND_PRINT((ndo, ", Command: %s", tok2str(cmdcode_str, "Unknown (0x%02x)", command))); /* Tag */ ND_TCHECK2(*cp, 4); ND_PRINT((ndo, ", Tag: 0x%08x", EXTRACT_32BITS(cp))); cp += 4; /* Arg */ cmd_decoder = command == AOEV1_CMD_ISSUE_ATA_COMMAND ? aoev1_issue_print : command == AOEV1_CMD_QUERY_CONFIG_INFORMATION ? aoev1_query_print : command == AOEV1_CMD_MAC_MASK_LIST ? aoev1_mac_print : command == AOEV1_CMD_RESERVE_RELEASE ? aoev1_reserve_print : NULL; if (cmd_decoder != NULL) cmd_decoder(ndo, cp, len - AOEV1_COMMON_HDR_LEN); return; invalid: ND_PRINT((ndo, "%s", istr)); ND_TCHECK2(*cp, ep - cp); return; trunc: ND_PRINT((ndo, "%s", tstr)); } void aoe_print(netdissect_options *ndo, const u_char *cp, const u_int len) { const u_char *ep = cp + len; uint8_t ver; ND_PRINT((ndo, "AoE length %u", len)); if (len < 1) goto invalid; /* Ver/Flags */ ND_TCHECK2(*cp, 1); ver = (*cp & 0xF0) >> 4; /* Don't advance cp yet: low order 4 bits are version-specific. */ ND_PRINT((ndo, ", Ver %u", ver)); switch (ver) { case AOE_V1: aoev1_print(ndo, cp, len); break; } return; invalid: ND_PRINT((ndo, "%s", istr)); ND_TCHECK2(*cp, ep - cp); return; trunc: ND_PRINT((ndo, "%s", tstr)); } tcpdump-4.9.3/print-raw.c0000644000026300017510000000302713544412561013424 0ustar mcrmcr/* * Copyright (c) 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of * the University nor the names of its contributors may be used to endorse * or promote products derived from this software without specific prior * written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* \summary: Raw IP printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" /* * The DLT_RAW packet has no header. It contains a raw IP packet. */ u_int raw_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) { if (ndo->ndo_eflag) ND_PRINT((ndo, "ip: ")); ipN_print(ndo, p, h->len); return (0); } tcpdump-4.9.3/print-dtp.c0000644000026300017510000000603313544412561013422 0ustar mcrmcr/* * Copyright (c) 1998-2007 The TCPDUMP project * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code * distributions retain the above copyright notice and this paragraph * in its entirety, and (2) distributions including binary code include * the above copyright notice and this paragraph in its entirety in * the documentation or other materials provided with the distribution. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. * * Original code by Carles Kishimoto */ /* \summary: Dynamic Trunking Protocol (DTP) printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #include "addrtoname.h" #include "extract.h" static const char tstr[] = " [|dtp]"; #define DTP_HEADER_LEN 1 #define DTP_DOMAIN_TLV 0x0001 #define DTP_STATUS_TLV 0x0002 #define DTP_DTP_TYPE_TLV 0x0003 #define DTP_NEIGHBOR_TLV 0x0004 static const struct tok dtp_tlv_values[] = { { DTP_DOMAIN_TLV, "Domain TLV"}, { DTP_STATUS_TLV, "Status TLV"}, { DTP_DTP_TYPE_TLV, "DTP type TLV"}, { DTP_NEIGHBOR_TLV, "Neighbor TLV"}, { 0, NULL} }; void dtp_print (netdissect_options *ndo, const u_char *pptr, u_int length) { int type, len; const u_char *tptr; if (length < DTP_HEADER_LEN) goto trunc; tptr = pptr; ND_TCHECK2(*tptr, DTP_HEADER_LEN); ND_PRINT((ndo, "DTPv%u, length %u", (*tptr), length)); /* * In non-verbose mode, just print version. */ if (ndo->ndo_vflag < 1) { return; } tptr += DTP_HEADER_LEN; while (tptr < (pptr+length)) { ND_TCHECK2(*tptr, 4); type = EXTRACT_16BITS(tptr); len = EXTRACT_16BITS(tptr+2); /* XXX: should not be but sometimes it is, see the test captures */ if (type == 0) return; ND_PRINT((ndo, "\n\t%s (0x%04x) TLV, length %u", tok2str(dtp_tlv_values, "Unknown", type), type, len)); /* infinite loop check */ if (len < 4) goto invalid; ND_TCHECK2(*tptr, len); switch (type) { case DTP_DOMAIN_TLV: ND_PRINT((ndo, ", ")); fn_printzp(ndo, tptr+4, len-4, pptr+length); break; case DTP_STATUS_TLV: case DTP_DTP_TYPE_TLV: if (len < 5) goto invalid; ND_PRINT((ndo, ", 0x%x", *(tptr+4))); break; case DTP_NEIGHBOR_TLV: if (len < 10) goto invalid; ND_PRINT((ndo, ", %s", etheraddr_string(ndo, tptr+4))); break; default: break; } tptr += len; } return; invalid: ND_PRINT((ndo, "%s", istr)); return; trunc: ND_PRINT((ndo, "%s", tstr)); } /* * Local Variables: * c-style: whitesmith * c-basic-offset: 4 * End: */ tcpdump-4.9.3/config.h.in0000644000026300017510000002630613544412724013366 0ustar mcrmcr/* config.h.in. Generated from configure.ac by autoheader. */ /* define if you want to build the possibly-buggy SMB printer */ #undef ENABLE_SMB /* Define to 1 if you have the `alarm' function. */ #undef HAVE_ALARM /* Define to 1 if you have the `bpf_dump' function. */ #undef HAVE_BPF_DUMP /* capsicum support available */ #undef HAVE_CAPSICUM /* Define to 1 if you have the `cap_enter' function. */ #undef HAVE_CAP_ENTER /* Define to 1 if you have the `cap_ioctls_limit' function. */ #undef HAVE_CAP_IOCTLS_LIMIT /* Define to 1 if you have the header file. */ #undef HAVE_CAP_NG_H /* Define to 1 if you have the `cap_rights_limit' function. */ #undef HAVE_CAP_RIGHTS_LIMIT /* Define to 1 if you have the declaration of `ether_ntohost', and to 0 if you don't. */ #undef HAVE_DECL_ETHER_NTOHOST /* Define to 1 if you have the `ether_ntohost' function. */ #undef HAVE_ETHER_NTOHOST /* Define to 1 if you have the `EVP_CipherInit_ex' function. */ #undef HAVE_EVP_CIPHERINIT_EX /* Define to 1 if you have the `EVP_CIPHER_CTX_new' function. */ #undef HAVE_EVP_CIPHER_CTX_NEW /* Define to 1 if you have the header file. */ #undef HAVE_FCNTL_H /* Define to 1 if you have the `fork' function. */ #undef HAVE_FORK /* Define to 1 if you have the `getopt_long' function. */ #undef HAVE_GETOPT_LONG /* define if you have getrpcbynumber() */ #undef HAVE_GETRPCBYNUMBER /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H /* Define to 1 if you have the `cap-ng' library (-lcap-ng). */ #undef HAVE_LIBCAP_NG /* Define to 1 if you have the `crypto' library (-lcrypto). */ #undef HAVE_LIBCRYPTO /* Define to 1 if you have the `rpc' library (-lrpc). */ #undef HAVE_LIBRPC /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H /* Define to 1 if you have the header file. */ #undef HAVE_NETINET_ETHER_H /* Define to 1 if you have the header file. */ #undef HAVE_NETINET_IF_ETHER_H /* Define to 1 if you have the header file. */ #undef HAVE_NET_IF_PFLOG_H /* Define to 1 if you have the header file. */ #undef HAVE_NET_PFVAR_H /* Define to 1 if you have the `openat' function. */ #undef HAVE_OPENAT /* Define to 1 if you have the header file. */ #undef HAVE_OPENSSL_EVP_H /* define if the OS provides AF_INET6 and struct in6_addr */ #undef HAVE_OS_IPV6_SUPPORT /* if there's an os_proto.h for this platform, to use additional prototypes */ #undef HAVE_OS_PROTO_H /* Define to 1 if you have the header file. */ #undef HAVE_PCAP_BLUETOOTH_H /* Define to 1 if you have the `pcap_breakloop' function. */ #undef HAVE_PCAP_BREAKLOOP /* Define to 1 if you have the `pcap_create' function. */ #undef HAVE_PCAP_CREATE /* define if libpcap has pcap_datalink_name_to_val() */ #undef HAVE_PCAP_DATALINK_NAME_TO_VAL /* define if libpcap has pcap_datalink_val_to_description() */ #undef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION /* define if libpcap has pcap_debug */ #undef HAVE_PCAP_DEBUG /* Define to 1 if you have the `pcap_dump_flush' function. */ #undef HAVE_PCAP_DUMP_FLUSH /* define if libpcap has pcap_dump_ftell() */ #undef HAVE_PCAP_DUMP_FTELL /* Define to 1 if you have the `pcap_findalldevs' function. */ #undef HAVE_PCAP_FINDALLDEVS /* Define to 1 if you have the `pcap_free_datalinks' function. */ #undef HAVE_PCAP_FREE_DATALINKS /* Define to 1 if the system has the type `pcap_if_t'. */ #undef HAVE_PCAP_IF_T /* Define to 1 if you have the `pcap_lib_version' function. */ #undef HAVE_PCAP_LIB_VERSION /* define if libpcap has pcap_list_datalinks() */ #undef HAVE_PCAP_LIST_DATALINKS /* Define to 1 if you have the header file. */ #undef HAVE_PCAP_NFLOG_H /* Define to 1 if you have the `pcap_setdirection' function. */ #undef HAVE_PCAP_SETDIRECTION /* Define to 1 if you have the `pcap_set_datalink' function. */ #undef HAVE_PCAP_SET_DATALINK /* Define to 1 if you have the `pcap_set_immediate_mode' function. */ #undef HAVE_PCAP_SET_IMMEDIATE_MODE /* Define to 1 if you have the `pcap_set_optimizer_debug' function. */ #undef HAVE_PCAP_SET_OPTIMIZER_DEBUG /* Define to 1 if you have the `pcap_set_parser_debug' function. */ #undef HAVE_PCAP_SET_PARSER_DEBUG /* Define to 1 if you have the `pcap_set_tstamp_precision' function. */ #undef HAVE_PCAP_SET_TSTAMP_PRECISION /* Define to 1 if you have the `pcap_set_tstamp_type' function. */ #undef HAVE_PCAP_SET_TSTAMP_TYPE /* Define to 1 if you have the header file. */ #undef HAVE_PCAP_USB_H /* define if libpcap has pcap_version */ #undef HAVE_PCAP_VERSION /* Define to 1 if you have the `pfopen' function. */ #undef HAVE_PFOPEN /* Define to 1 if you have the header file. */ #undef HAVE_RPC_RPCENT_H /* Define to 1 if you have the header file. */ #undef HAVE_RPC_RPC_H /* Define to 1 if you have the `setlinebuf' function. */ #undef HAVE_SETLINEBUF /* Define to 1 if you have the `sigaction' function. */ #undef HAVE_SIGACTION /* Define to 1 if you have the `sigset' function. */ #undef HAVE_SIGSET /* Define to 1 if you have the `snprintf' function. */ #undef HAVE_SNPRINTF /* if struct sockaddr has the sa_len member */ #undef HAVE_SOCKADDR_SA_LEN /* Define to 1 if you have the header file. */ #undef HAVE_STDINT_H /* Define to 1 if you have the header file. */ #undef HAVE_STDLIB_H /* Define to 1 if you have the `strdup' function. */ #undef HAVE_STRDUP /* Define to 1 if you have the `strftime' function. */ #undef HAVE_STRFTIME /* Define to 1 if you have the header file. */ #undef HAVE_STRINGS_H /* Define to 1 if you have the header file. */ #undef HAVE_STRING_H /* Define to 1 if you have the `strlcat' function. */ #undef HAVE_STRLCAT /* Define to 1 if you have the `strlcpy' function. */ #undef HAVE_STRLCPY /* Define to 1 if you have the `strsep' function. */ #undef HAVE_STRSEP /* Define to 1 if the system has the type `struct ether_addr'. */ #undef HAVE_STRUCT_ETHER_ADDR /* Define to 1 if you have the header file. */ #undef HAVE_SYS_STAT_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TYPES_H /* Define to 1 if the system has the type `uintptr_t'. */ #undef HAVE_UINTPTR_T /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H /* Define to 1 if you have the `vfork' function. */ #undef HAVE_VFORK /* Define to 1 if you have the `vfprintf' function. */ #undef HAVE_VFPRINTF /* Define to 1 if you have the `vsnprintf' function. */ #undef HAVE_VSNPRINTF /* define if libpcap has yydebug */ #undef HAVE_YYDEBUG /* define if your compiler has __attribute__ */ #undef HAVE___ATTRIBUTE__ /* if unaligned access fails */ #undef LBL_ALIGN /* Define to 1 if netinet/ether.h declares `ether_ntohost' */ #undef NETINET_ETHER_H_DECLARES_ETHER_NTOHOST /* Define to 1 if netinet/if_ether.h declares `ether_ntohost' */ #undef NETINET_IF_ETHER_H_DECLARES_ETHER_NTOHOST /* Define to the address where bug reports for this package should be sent. */ #undef PACKAGE_BUGREPORT /* Define to the full name of this package. */ #undef PACKAGE_NAME /* Define to the full name and version of this package. */ #undef PACKAGE_STRING /* Define to the one symbol short name of this package. */ #undef PACKAGE_TARNAME /* Define to the home page for this package. */ #undef PACKAGE_URL /* Define to the version of this package. */ #undef PACKAGE_VERSION /* define if the platform doesn't define PRId64 */ #undef PRId64 /* define if the platform doesn't define PRIo64 */ #undef PRIo64 /* define if the platform doesn't define PRIx64 */ #undef PRIu64 /* define if the platform doesn't define PRIu64 */ #undef PRIx64 /* Define as the return type of signal handlers (`int' or `void'). */ #undef RETSIGTYPE /* return value of signal handlers */ #undef RETSIGVAL /* Define to 1 if you have the ANSI C header files. */ #undef STDC_HEADERS /* Define to 1 if you can safely include both and . */ #undef TIME_WITH_SYS_TIME /* define if you have ether_ntohost() and it works */ #undef USE_ETHER_NTOHOST /* Define if you enable support for libsmi */ #undef USE_LIBSMI /* define if should chroot when dropping privileges */ #undef WITH_CHROOT /* define if should drop privileges by default */ #undef WITH_USER /* get BSD semantics on Irix */ #undef _BSD_SIGNALS /* define on AIX to get certain functions */ #undef _SUN /* Define for Solaris 2.5.1 so the uint32_t typedef from , , or is not used. If the typedef were allowed, the #define below would cause a syntax error. */ #undef _UINT32_T /* Define for Solaris 2.5.1 so the uint64_t typedef from , , or is not used. If the typedef were allowed, the #define below would cause a syntax error. */ #undef _UINT64_T /* Define for Solaris 2.5.1 so the uint8_t typedef from , , or is not used. If the typedef were allowed, the #define below would cause a syntax error. */ #undef _UINT8_T /* define if your compiler allows __attribute__((format)) without a warning */ #undef __ATTRIBUTE___FORMAT_OK /* define if your compiler allows __attribute__((format)) to be applied to function pointers */ #undef __ATTRIBUTE___FORMAT_OK_FOR_FUNCTION_POINTERS /* define if your compiler allows __attribute__((noreturn)) to be applied to function pointers */ #undef __ATTRIBUTE___NORETURN_OK_FOR_FUNCTION_POINTERS /* to handle Ultrix compilers that don't support const in prototypes */ #undef const /* Define as token for inline if inlining supported */ #undef inline /* Define to the type of a signed integer type of width exactly 16 bits if such a type exists and the standard includes do not define it. */ #undef int16_t /* Define to the type of a signed integer type of width exactly 32 bits if such a type exists and the standard includes do not define it. */ #undef int32_t /* Define to the type of a signed integer type of width exactly 64 bits if such a type exists and the standard includes do not define it. */ #undef int64_t /* Define to the type of a signed integer type of width exactly 8 bits if such a type exists and the standard includes do not define it. */ #undef int8_t /* Define to `uint16_t' if u_int16_t not defined. */ #undef u_int16_t /* Define to `uint32_t' if u_int32_t not defined. */ #undef u_int32_t /* Define to `uint64_t' if u_int64_t not defined. */ #undef u_int64_t /* Define to `uint8_t' if u_int8_t not defined. */ #undef u_int8_t /* Define to the type of an unsigned integer type of width exactly 16 bits if such a type exists and the standard includes do not define it. */ #undef uint16_t /* Define to the type of an unsigned integer type of width exactly 32 bits if such a type exists and the standard includes do not define it. */ #undef uint32_t /* Define to the type of an unsigned integer type of width exactly 64 bits if such a type exists and the standard includes do not define it. */ #undef uint64_t /* Define to the type of an unsigned integer type of width exactly 8 bits if such a type exists and the standard includes do not define it. */ #undef uint8_t /* Define to the type of an unsigned integer type wide enough to hold a pointer, if such a type exists, and if the system does not define it. */ #undef uintptr_t tcpdump-4.9.3/print-igmp.c0000644000026300017510000002406413544412561013573 0ustar mcrmcr/* * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of * the University nor the names of its contributors may be used to endorse * or promote products derived from this software without specific prior * written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* \summary: Internet Group Management Protocol (IGMP) printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #include "addrtoname.h" #include "extract.h" #ifndef IN_CLASSD #define IN_CLASSD(i) (((int32_t)(i) & 0xf0000000) == 0xe0000000) #endif static const char tstr[] = "[|igmp]"; /* (following from ipmulti/mrouted/prune.h) */ /* * The packet format for a traceroute request. */ struct tr_query { uint32_t tr_src; /* traceroute source */ uint32_t tr_dst; /* traceroute destination */ uint32_t tr_raddr; /* traceroute response address */ uint32_t tr_rttlqid; /* response ttl and qid */ }; #define TR_GETTTL(x) (int)(((x) >> 24) & 0xff) #define TR_GETQID(x) ((x) & 0x00ffffff) /* * Traceroute response format. A traceroute response has a tr_query at the * beginning, followed by one tr_resp for each hop taken. */ struct tr_resp { uint32_t tr_qarr; /* query arrival time */ uint32_t tr_inaddr; /* incoming interface address */ uint32_t tr_outaddr; /* outgoing interface address */ uint32_t tr_rmtaddr; /* parent address in source tree */ uint32_t tr_vifin; /* input packet count on interface */ uint32_t tr_vifout; /* output packet count on interface */ uint32_t tr_pktcnt; /* total incoming packets for src-grp */ uint8_t tr_rproto; /* routing proto deployed on router */ uint8_t tr_fttl; /* ttl required to forward on outvif */ uint8_t tr_smask; /* subnet mask for src addr */ uint8_t tr_rflags; /* forwarding error codes */ }; /* defs within mtrace */ #define TR_QUERY 1 #define TR_RESP 2 /* fields for tr_rflags (forwarding error codes) */ #define TR_NO_ERR 0 #define TR_WRONG_IF 1 #define TR_PRUNED 2 #define TR_OPRUNED 3 #define TR_SCOPED 4 #define TR_NO_RTE 5 #define TR_NO_FWD 7 #define TR_NO_SPACE 0x81 #define TR_OLD_ROUTER 0x82 /* fields for tr_rproto (routing protocol) */ #define TR_PROTO_DVMRP 1 #define TR_PROTO_MOSPF 2 #define TR_PROTO_PIM 3 #define TR_PROTO_CBT 4 /* igmpv3 report types */ static const struct tok igmpv3report2str[] = { { 1, "is_in" }, { 2, "is_ex" }, { 3, "to_in" }, { 4, "to_ex" }, { 5, "allow" }, { 6, "block" }, { 0, NULL } }; static void print_mtrace(netdissect_options *ndo, register const u_char *bp, register u_int len) { register const struct tr_query *tr = (const struct tr_query *)(bp + 8); ND_TCHECK(*tr); if (len < 8 + sizeof (struct tr_query)) { ND_PRINT((ndo, " [invalid len %d]", len)); return; } ND_PRINT((ndo, "mtrace %u: %s to %s reply-to %s", TR_GETQID(EXTRACT_32BITS(&tr->tr_rttlqid)), ipaddr_string(ndo, &tr->tr_src), ipaddr_string(ndo, &tr->tr_dst), ipaddr_string(ndo, &tr->tr_raddr))); if (IN_CLASSD(EXTRACT_32BITS(&tr->tr_raddr))) ND_PRINT((ndo, " with-ttl %d", TR_GETTTL(EXTRACT_32BITS(&tr->tr_rttlqid)))); return; trunc: ND_PRINT((ndo, "%s", tstr)); } static void print_mresp(netdissect_options *ndo, register const u_char *bp, register u_int len) { register const struct tr_query *tr = (const struct tr_query *)(bp + 8); ND_TCHECK(*tr); if (len < 8 + sizeof (struct tr_query)) { ND_PRINT((ndo, " [invalid len %d]", len)); return; } ND_PRINT((ndo, "mresp %lu: %s to %s reply-to %s", (u_long)TR_GETQID(EXTRACT_32BITS(&tr->tr_rttlqid)), ipaddr_string(ndo, &tr->tr_src), ipaddr_string(ndo, &tr->tr_dst), ipaddr_string(ndo, &tr->tr_raddr))); if (IN_CLASSD(EXTRACT_32BITS(&tr->tr_raddr))) ND_PRINT((ndo, " with-ttl %d", TR_GETTTL(EXTRACT_32BITS(&tr->tr_rttlqid)))); return; trunc: ND_PRINT((ndo, "%s", tstr)); } static void print_igmpv3_report(netdissect_options *ndo, register const u_char *bp, register u_int len) { u_int group, nsrcs, ngroups; register u_int i, j; /* Minimum len is 16, and should be a multiple of 4 */ if (len < 16 || len & 0x03) { ND_PRINT((ndo, " [invalid len %d]", len)); return; } ND_TCHECK2(bp[6], 2); ngroups = EXTRACT_16BITS(&bp[6]); ND_PRINT((ndo, ", %d group record(s)", ngroups)); if (ndo->ndo_vflag > 0) { /* Print the group records */ group = 8; for (i=0; indo_vflag == 1) ND_PRINT((ndo, ", %d source(s)", nsrcs)); else { /* Print the sources */ ND_PRINT((ndo, " {")); for (j=0; j> 4) + 3); } if (mrc != 100) { ND_PRINT((ndo, " [max resp time ")); if (mrt < 600) { ND_PRINT((ndo, "%.1fs", mrt * 0.1)); } else { unsigned_relts_print(ndo, mrt / 10); } ND_PRINT((ndo, "]")); } ND_TCHECK2(bp[4], 4); if (EXTRACT_32BITS(&bp[4]) == 0) return; ND_PRINT((ndo, " [gaddr %s", ipaddr_string(ndo, &bp[4]))); ND_TCHECK2(bp[10], 2); nsrcs = EXTRACT_16BITS(&bp[10]); if (nsrcs > 0) { if (len < 12 + (nsrcs << 2)) ND_PRINT((ndo, " [invalid number of sources]")); else if (ndo->ndo_vflag > 1) { ND_PRINT((ndo, " {")); for (i=0; indo_qflag) { ND_PRINT((ndo, "igmp")); return; } ND_TCHECK(bp[0]); switch (bp[0]) { case 0x11: ND_PRINT((ndo, "igmp query")); if (len >= 12) print_igmpv3_query(ndo, bp, len); else { ND_TCHECK(bp[1]); if (bp[1]) { ND_PRINT((ndo, " v2")); if (bp[1] != 100) ND_PRINT((ndo, " [max resp time %d]", bp[1])); } else ND_PRINT((ndo, " v1")); ND_TCHECK2(bp[4], 4); if (EXTRACT_32BITS(&bp[4])) ND_PRINT((ndo, " [gaddr %s]", ipaddr_string(ndo, &bp[4]))); if (len != 8) ND_PRINT((ndo, " [len %d]", len)); } break; case 0x12: ND_TCHECK2(bp[4], 4); ND_PRINT((ndo, "igmp v1 report %s", ipaddr_string(ndo, &bp[4]))); if (len != 8) ND_PRINT((ndo, " [len %d]", len)); break; case 0x16: ND_TCHECK2(bp[4], 4); ND_PRINT((ndo, "igmp v2 report %s", ipaddr_string(ndo, &bp[4]))); break; case 0x22: ND_PRINT((ndo, "igmp v3 report")); print_igmpv3_report(ndo, bp, len); break; case 0x17: ND_TCHECK2(bp[4], 4); ND_PRINT((ndo, "igmp leave %s", ipaddr_string(ndo, &bp[4]))); break; case 0x13: ND_PRINT((ndo, "igmp dvmrp")); if (len < 8) ND_PRINT((ndo, " [len %d]", len)); else dvmrp_print(ndo, bp, len); break; case 0x14: ND_PRINT((ndo, "igmp pimv1")); pimv1_print(ndo, bp, len); break; case 0x1e: print_mresp(ndo, bp, len); break; case 0x1f: print_mtrace(ndo, bp, len); break; default: ND_PRINT((ndo, "igmp-%d", bp[0])); break; } if (ndo->ndo_vflag && len >= 4 && ND_TTEST2(bp[0], len)) { /* Check the IGMP checksum */ vec[0].ptr = bp; vec[0].len = len; if (in_cksum(vec, 1)) ND_PRINT((ndo, " bad igmp cksum %x!", EXTRACT_16BITS(&bp[2]))); } return; trunc: ND_PRINT((ndo, "%s", tstr)); } tcpdump-4.9.3/print-timed.c0000644000026300017510000001136713544412561013743 0ustar mcrmcr/* * Copyright (c) 2000 Ben Smithurst * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of * the University nor the names of its contributors may be used to endorse * or promote products derived from this software without specific prior * written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* \summary: BSD time daemon protocol printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #include "extract.h" /* * Time Synchronization Protocol * * http://docs.freebsd.org/44doc/smm/12.timed/paper.pdf */ struct tsp_timeval { uint32_t tv_sec; uint32_t tv_usec; }; struct tsp { uint8_t tsp_type; uint8_t tsp_vers; uint16_t tsp_seq; union { struct tsp_timeval tspu_time; int8_t tspu_hopcnt; } tsp_u; int8_t tsp_name[256]; }; #define tsp_time tsp_u.tspu_time #define tsp_hopcnt tsp_u.tspu_hopcnt /* * Command types. */ #define TSP_ANY 0 /* match any types */ #define TSP_ADJTIME 1 /* send adjtime */ #define TSP_ACK 2 /* generic acknowledgement */ #define TSP_MASTERREQ 3 /* ask for master's name */ #define TSP_MASTERACK 4 /* acknowledge master request */ #define TSP_SETTIME 5 /* send network time */ #define TSP_MASTERUP 6 /* inform slaves that master is up */ #define TSP_SLAVEUP 7 /* slave is up but not polled */ #define TSP_ELECTION 8 /* advance candidature for master */ #define TSP_ACCEPT 9 /* support candidature of master */ #define TSP_REFUSE 10 /* reject candidature of master */ #define TSP_CONFLICT 11 /* two or more masters present */ #define TSP_RESOLVE 12 /* masters' conflict resolution */ #define TSP_QUIT 13 /* reject candidature if master is up */ #define TSP_DATE 14 /* reset the time (date command) */ #define TSP_DATEREQ 15 /* remote request to reset the time */ #define TSP_DATEACK 16 /* acknowledge time setting */ #define TSP_TRACEON 17 /* turn tracing on */ #define TSP_TRACEOFF 18 /* turn tracing off */ #define TSP_MSITE 19 /* find out master's site */ #define TSP_MSITEREQ 20 /* remote master's site request */ #define TSP_TEST 21 /* for testing election algo */ #define TSP_SETDATE 22 /* New from date command */ #define TSP_SETDATEREQ 23 /* New remote for above */ #define TSP_LOOP 24 /* loop detection packet */ #define TSPTYPENUMBER 25 static const char tstr[] = "[|timed]"; static const char *tsptype[TSPTYPENUMBER] = { "ANY", "ADJTIME", "ACK", "MASTERREQ", "MASTERACK", "SETTIME", "MASTERUP", "SLAVEUP", "ELECTION", "ACCEPT", "REFUSE", "CONFLICT", "RESOLVE", "QUIT", "DATE", "DATEREQ", "DATEACK", "TRACEON", "TRACEOFF", "MSITE", "MSITEREQ", "TEST", "SETDATE", "SETDATEREQ", "LOOP" }; void timed_print(netdissect_options *ndo, register const u_char *bp) { const struct tsp *tsp = (const struct tsp *)bp; long sec, usec; ND_TCHECK(tsp->tsp_type); if (tsp->tsp_type < TSPTYPENUMBER) ND_PRINT((ndo, "TSP_%s", tsptype[tsp->tsp_type])); else ND_PRINT((ndo, "(tsp_type %#x)", tsp->tsp_type)); ND_TCHECK(tsp->tsp_vers); ND_PRINT((ndo, " vers %u", tsp->tsp_vers)); ND_TCHECK(tsp->tsp_seq); ND_PRINT((ndo, " seq %u", tsp->tsp_seq)); switch (tsp->tsp_type) { case TSP_LOOP: ND_TCHECK(tsp->tsp_hopcnt); ND_PRINT((ndo, " hopcnt %u", tsp->tsp_hopcnt)); break; case TSP_SETTIME: case TSP_ADJTIME: case TSP_SETDATE: case TSP_SETDATEREQ: ND_TCHECK(tsp->tsp_time); sec = EXTRACT_32BITS(&tsp->tsp_time.tv_sec); usec = EXTRACT_32BITS(&tsp->tsp_time.tv_usec); /* XXX The comparison below is always false? */ if (usec < 0) /* invalid, skip the rest of the packet */ return; ND_PRINT((ndo, " time ")); if (sec < 0 && usec != 0) { sec++; if (sec == 0) ND_PRINT((ndo, "-")); usec = 1000000 - usec; } ND_PRINT((ndo, "%ld.%06ld", sec, usec)); break; } ND_TCHECK(tsp->tsp_name); ND_PRINT((ndo, " name ")); if (fn_print(ndo, (const u_char *)tsp->tsp_name, (const u_char *)tsp->tsp_name + sizeof(tsp->tsp_name))) goto trunc; return; trunc: ND_PRINT((ndo, " %s", tstr)); } tcpdump-4.9.3/print-sctp.c0000644000026300017510000005620613544412561013613 0ustar mcrmcr/* Copyright (c) 2001 NETLAB, Temple University * Copyright (c) 2001 Protocol Engineering Lab, University of Delaware * * Jerry Heinz * John Fiore * Armando L. Caro Jr. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * 3. Neither the name of the University nor of the Laboratory may be used * to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* \summary: Stream Control Transmission Protocol (SCTP) printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #include "addrtoname.h" #include "extract.h" #include "ip.h" #include "ip6.h" /* Definitions from: * * SCTP reference Implementation Copyright (C) 1999 Cisco And Motorola * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * 3. Neither the name of Cisco nor of Motorola may be used * to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * This file is part of the SCTP reference Implementation * * * Please send any bug reports or fixes you make to one of the following email * addresses: * * rstewar1@email.mot.com * kmorneau@cisco.com * qxie1@email.mot.com * * Any bugs reported given to us we will try to fix... any fixes shared will * be incorperated into the next SCTP release. */ /* The valid defines for all message * types know to SCTP. 0 is reserved */ #define SCTP_DATA 0x00 #define SCTP_INITIATION 0x01 #define SCTP_INITIATION_ACK 0x02 #define SCTP_SELECTIVE_ACK 0x03 #define SCTP_HEARTBEAT_REQUEST 0x04 #define SCTP_HEARTBEAT_ACK 0x05 #define SCTP_ABORT_ASSOCIATION 0x06 #define SCTP_SHUTDOWN 0x07 #define SCTP_SHUTDOWN_ACK 0x08 #define SCTP_OPERATION_ERR 0x09 #define SCTP_COOKIE_ECHO 0x0a #define SCTP_COOKIE_ACK 0x0b #define SCTP_ECN_ECHO 0x0c #define SCTP_ECN_CWR 0x0d #define SCTP_SHUTDOWN_COMPLETE 0x0e #define SCTP_FORWARD_CUM_TSN 0xc0 #define SCTP_RELIABLE_CNTL 0xc1 #define SCTP_RELIABLE_CNTL_ACK 0xc2 static const struct tok sctp_chunkid_str[] = { { SCTP_DATA, "DATA" }, { SCTP_INITIATION, "INIT" }, { SCTP_INITIATION_ACK, "INIT ACK" }, { SCTP_SELECTIVE_ACK, "SACK" }, { SCTP_HEARTBEAT_REQUEST, "HB REQ" }, { SCTP_HEARTBEAT_ACK, "HB ACK" }, { SCTP_ABORT_ASSOCIATION, "ABORT" }, { SCTP_SHUTDOWN, "SHUTDOWN" }, { SCTP_SHUTDOWN_ACK, "SHUTDOWN ACK" }, { SCTP_OPERATION_ERR, "OP ERR" }, { SCTP_COOKIE_ECHO, "COOKIE ECHO" }, { SCTP_COOKIE_ACK, "COOKIE ACK" }, { SCTP_ECN_ECHO, "ECN ECHO" }, { SCTP_ECN_CWR, "ECN CWR" }, { SCTP_SHUTDOWN_COMPLETE, "SHUTDOWN COMPLETE" }, { SCTP_FORWARD_CUM_TSN, "FOR CUM TSN" }, { SCTP_RELIABLE_CNTL, "REL CTRL" }, { SCTP_RELIABLE_CNTL_ACK, "REL CTRL ACK" }, { 0, NULL } }; /* Data Chuck Specific Flags */ #define SCTP_DATA_FRAG_MASK 0x03 #define SCTP_DATA_MIDDLE_FRAG 0x00 #define SCTP_DATA_LAST_FRAG 0x01 #define SCTP_DATA_FIRST_FRAG 0x02 #define SCTP_DATA_NOT_FRAG 0x03 #define SCTP_DATA_UNORDERED 0x04 #define SCTP_ADDRMAX 60 #define CHAN_HP 6704 #define CHAN_MP 6705 #define CHAN_LP 6706 /* the sctp common header */ struct sctpHeader{ uint16_t source; uint16_t destination; uint32_t verificationTag; uint32_t adler32; }; /* various descriptor parsers */ struct sctpChunkDesc{ uint8_t chunkID; uint8_t chunkFlg; uint16_t chunkLength; }; struct sctpParamDesc{ uint16_t paramType; uint16_t paramLength; }; struct sctpRelChunkDesc{ struct sctpChunkDesc chk; uint32_t serialNumber; }; struct sctpVendorSpecificParam { struct sctpParamDesc p; /* type must be 0xfffe */ uint32_t vendorId; /* vendor ID from RFC 1700 */ uint16_t vendorSpecificType; uint16_t vendorSpecificLen; }; /* Structures for the control parts */ /* Sctp association init request/ack */ /* this is used for init ack, too */ struct sctpInitiation{ uint32_t initTag; /* tag of mine */ uint32_t rcvWindowCredit; /* rwnd */ uint16_t NumPreopenStreams; /* OS */ uint16_t MaxInboundStreams; /* MIS */ uint32_t initialTSN; /* optional param's follow in sctpParamDesc form */ }; struct sctpV4IpAddress{ struct sctpParamDesc p; /* type is set to SCTP_IPV4_PARAM_TYPE, len=10 */ uint32_t ipAddress; }; struct sctpV6IpAddress{ struct sctpParamDesc p; /* type is set to SCTP_IPV6_PARAM_TYPE, len=22 */ uint8_t ipAddress[16]; }; struct sctpDNSName{ struct sctpParamDesc param; uint8_t name[1]; }; struct sctpCookiePreserve{ struct sctpParamDesc p; /* type is set to SCTP_COOKIE_PRESERVE, len=8 */ uint32_t extraTime; }; struct sctpTimeStamp{ uint32_t ts_sec; uint32_t ts_usec; }; /* wire structure of my cookie */ struct cookieMessage{ uint32_t TieTag_curTag; /* copied from assoc if present */ uint32_t TieTag_hisTag; /* copied from assoc if present */ int32_t cookieLife; /* life I will award this cookie */ struct sctpTimeStamp timeEnteringState; /* the time I built cookie */ struct sctpInitiation initAckISent; /* the INIT-ACK that I sent to my peer */ uint32_t addressWhereISent[4]; /* I make this 4 ints so I get 128bits for future */ int32_t addrtype; /* address type */ uint16_t locScope; /* V6 local scope flag */ uint16_t siteScope; /* V6 site scope flag */ /* at the end is tacked on the INIT chunk sent in * its entirety and of course our * signature. */ }; /* this guy is for use when * I have a initiate message gloming the * things together. */ struct sctpUnifiedInit{ struct sctpChunkDesc uh; struct sctpInitiation initm; }; struct sctpSendableInit{ struct sctpHeader mh; struct sctpUnifiedInit msg; }; /* Selective Acknowledgement * has the following structure with * a optional ammount of trailing int's * on the last part (based on the numberOfDesc * field). */ struct sctpSelectiveAck{ uint32_t highestConseqTSN; uint32_t updatedRwnd; uint16_t numberOfdesc; uint16_t numDupTsns; }; struct sctpSelectiveFrag{ uint16_t fragmentStart; uint16_t fragmentEnd; }; struct sctpUnifiedSack{ struct sctpChunkDesc uh; struct sctpSelectiveAck sack; }; /* for both RTT request/response the * following is sent */ struct sctpHBrequest { uint32_t time_value_1; uint32_t time_value_2; }; /* here is what I read and respond with to. */ struct sctpHBunified{ struct sctpChunkDesc hdr; struct sctpParamDesc hb; }; /* here is what I send */ struct sctpHBsender{ struct sctpChunkDesc hdr; struct sctpParamDesc hb; struct sctpHBrequest rtt; int8_t addrFmt[SCTP_ADDRMAX]; uint16_t userreq; }; /* for the abort and shutdown ACK * we must carry the init tag in the common header. Just the * common header is all that is needed with a chunk descriptor. */ struct sctpUnifiedAbort{ struct sctpChunkDesc uh; }; struct sctpUnifiedAbortLight{ struct sctpHeader mh; struct sctpChunkDesc uh; }; struct sctpUnifiedAbortHeavy{ struct sctpHeader mh; struct sctpChunkDesc uh; uint16_t causeCode; uint16_t causeLen; }; /* For the graceful shutdown we must carry * the tag (in common header) and the highest consequitive acking value */ struct sctpShutdown { uint32_t TSN_Seen; }; struct sctpUnifiedShutdown{ struct sctpChunkDesc uh; struct sctpShutdown shut; }; /* in the unified message we add the trailing * stream id since it is the only message * that is defined as a operation error. */ struct sctpOpErrorCause{ uint16_t cause; uint16_t causeLen; }; struct sctpUnifiedOpError{ struct sctpChunkDesc uh; struct sctpOpErrorCause c; }; struct sctpUnifiedStreamError{ struct sctpHeader mh; struct sctpChunkDesc uh; struct sctpOpErrorCause c; uint16_t strmNum; uint16_t reserved; }; struct staleCookieMsg{ struct sctpHeader mh; struct sctpChunkDesc uh; struct sctpOpErrorCause c; uint32_t moretime; }; /* the following is used in all sends * where nothing is needed except the * chunk/type i.e. shutdownAck Abort */ struct sctpUnifiedSingleMsg{ struct sctpHeader mh; struct sctpChunkDesc uh; }; struct sctpDataPart{ uint32_t TSN; uint16_t streamId; uint16_t sequence; uint32_t payloadtype; }; struct sctpUnifiedDatagram{ struct sctpChunkDesc uh; struct sctpDataPart dp; }; struct sctpECN_echo{ struct sctpChunkDesc uh; uint32_t Lowest_TSN; }; struct sctpCWR{ struct sctpChunkDesc uh; uint32_t TSN_reduced_at; }; static const struct tok ForCES_channels[] = { { CHAN_HP, "ForCES HP" }, { CHAN_MP, "ForCES MP" }, { CHAN_LP, "ForCES LP" }, { 0, NULL } }; /* data chunk's payload protocol identifiers */ #define SCTP_PPID_IUA 1 #define SCTP_PPID_M2UA 2 #define SCTP_PPID_M3UA 3 #define SCTP_PPID_SUA 4 #define SCTP_PPID_M2PA 5 #define SCTP_PPID_V5UA 6 #define SCTP_PPID_H248 7 #define SCTP_PPID_BICC 8 #define SCTP_PPID_TALI 9 #define SCTP_PPID_DUA 10 #define SCTP_PPID_ASAP 11 #define SCTP_PPID_ENRP 12 #define SCTP_PPID_H323 13 #define SCTP_PPID_QIPC 14 #define SCTP_PPID_SIMCO 15 #define SCTP_PPID_DDPSC 16 #define SCTP_PPID_DDPSSC 17 #define SCTP_PPID_S1AP 18 #define SCTP_PPID_RUA 19 #define SCTP_PPID_HNBAP 20 #define SCTP_PPID_FORCES_HP 21 #define SCTP_PPID_FORCES_MP 22 #define SCTP_PPID_FORCES_LP 23 #define SCTP_PPID_SBC_AP 24 #define SCTP_PPID_NBAP 25 /* 26 */ #define SCTP_PPID_X2AP 27 static const struct tok PayloadProto_idents[] = { { SCTP_PPID_IUA, "ISDN Q.921" }, { SCTP_PPID_M2UA, "M2UA" }, { SCTP_PPID_M3UA, "M3UA" }, { SCTP_PPID_SUA, "SUA" }, { SCTP_PPID_M2PA, "M2PA" }, { SCTP_PPID_V5UA, "V5.2" }, { SCTP_PPID_H248, "H.248" }, { SCTP_PPID_BICC, "BICC" }, { SCTP_PPID_TALI, "TALI" }, { SCTP_PPID_DUA, "DUA" }, { SCTP_PPID_ASAP, "ASAP" }, { SCTP_PPID_ENRP, "ENRP" }, { SCTP_PPID_H323, "H.323" }, { SCTP_PPID_QIPC, "Q.IPC" }, { SCTP_PPID_SIMCO, "SIMCO" }, { SCTP_PPID_DDPSC, "DDPSC" }, { SCTP_PPID_DDPSSC, "DDPSSC" }, { SCTP_PPID_S1AP, "S1AP" }, { SCTP_PPID_RUA, "RUA" }, { SCTP_PPID_HNBAP, "HNBAP" }, { SCTP_PPID_FORCES_HP, "ForCES HP" }, { SCTP_PPID_FORCES_MP, "ForCES MP" }, { SCTP_PPID_FORCES_LP, "ForCES LP" }, { SCTP_PPID_SBC_AP, "SBc-AP" }, { SCTP_PPID_NBAP, "NBAP" }, /* 26 */ { SCTP_PPID_X2AP, "X2AP" }, { 0, NULL } }; static inline int isForCES_port(u_short Port) { if (Port == CHAN_HP) return 1; if (Port == CHAN_MP) return 1; if (Port == CHAN_LP) return 1; return 0; } void sctp_print(netdissect_options *ndo, const u_char *bp, /* beginning of sctp packet */ const u_char *bp2, /* beginning of enclosing */ u_int sctpPacketLength) /* ip packet */ { u_int sctpPacketLengthRemaining; const struct sctpHeader *sctpPktHdr; const struct ip *ip; const struct ip6_hdr *ip6; u_short sourcePort, destPort; int chunkCount; const struct sctpChunkDesc *chunkDescPtr; const char *sep; int isforces = 0; if (sctpPacketLength < sizeof(struct sctpHeader)) { ND_PRINT((ndo, "truncated-sctp - %ld bytes missing!", (long)(sizeof(struct sctpHeader) - sctpPacketLength))); return; } sctpPktHdr = (const struct sctpHeader*) bp; ND_TCHECK(*sctpPktHdr); sctpPacketLengthRemaining = sctpPacketLength; sourcePort = EXTRACT_16BITS(&sctpPktHdr->source); destPort = EXTRACT_16BITS(&sctpPktHdr->destination); ip = (const struct ip *)bp2; if (IP_V(ip) == 6) ip6 = (const struct ip6_hdr *)bp2; else ip6 = NULL; if (ip6) { ND_PRINT((ndo, "%s.%d > %s.%d: sctp", ip6addr_string(ndo, &ip6->ip6_src), sourcePort, ip6addr_string(ndo, &ip6->ip6_dst), destPort)); } else { ND_PRINT((ndo, "%s.%d > %s.%d: sctp", ipaddr_string(ndo, &ip->ip_src), sourcePort, ipaddr_string(ndo, &ip->ip_dst), destPort)); } if (isForCES_port(sourcePort)) { ND_PRINT((ndo, "[%s]", tok2str(ForCES_channels, NULL, sourcePort))); isforces = 1; } if (isForCES_port(destPort)) { ND_PRINT((ndo, "[%s]", tok2str(ForCES_channels, NULL, destPort))); isforces = 1; } bp += sizeof(struct sctpHeader); sctpPacketLengthRemaining -= sizeof(struct sctpHeader); if (ndo->ndo_vflag >= 2) sep = "\n\t"; else sep = " ("; /* cycle through all chunks, printing information on each one */ for (chunkCount = 0, chunkDescPtr = (const struct sctpChunkDesc *)bp; sctpPacketLengthRemaining != 0; chunkCount++) { uint16_t chunkLength, chunkLengthRemaining; uint16_t align; chunkDescPtr = (const struct sctpChunkDesc *)bp; if (sctpPacketLengthRemaining < sizeof(*chunkDescPtr)) { ND_PRINT((ndo, "%s%d) [chunk descriptor cut off at end of packet]", sep, chunkCount+1)); break; } ND_TCHECK(*chunkDescPtr); chunkLength = EXTRACT_16BITS(&chunkDescPtr->chunkLength); if (chunkLength < sizeof(*chunkDescPtr)) { ND_PRINT((ndo, "%s%d) [Bad chunk length %u, < size of chunk descriptor]", sep, chunkCount+1, chunkLength)); break; } chunkLengthRemaining = chunkLength; align = chunkLength % 4; if (align != 0) align = 4 - align; if (sctpPacketLengthRemaining < align) { ND_PRINT((ndo, "%s%d) [Bad chunk length %u, > remaining data in packet]", sep, chunkCount+1, chunkLength)); break; } ND_TCHECK2(*bp, chunkLength); bp += sizeof(*chunkDescPtr); sctpPacketLengthRemaining -= sizeof(*chunkDescPtr); chunkLengthRemaining -= sizeof(*chunkDescPtr); ND_PRINT((ndo, "%s%d) ", sep, chunkCount+1)); ND_PRINT((ndo, "[%s] ", tok2str(sctp_chunkid_str, "Unknown chunk type: 0x%x", chunkDescPtr->chunkID))); switch (chunkDescPtr->chunkID) { case SCTP_DATA : { const struct sctpDataPart *dataHdrPtr; uint32_t ppid; u_int payload_size; if ((chunkDescPtr->chunkFlg & SCTP_DATA_UNORDERED) == SCTP_DATA_UNORDERED) ND_PRINT((ndo, "(U)")); if ((chunkDescPtr->chunkFlg & SCTP_DATA_FIRST_FRAG) == SCTP_DATA_FIRST_FRAG) ND_PRINT((ndo, "(B)")); if ((chunkDescPtr->chunkFlg & SCTP_DATA_LAST_FRAG) == SCTP_DATA_LAST_FRAG) ND_PRINT((ndo, "(E)")); if( ((chunkDescPtr->chunkFlg & SCTP_DATA_UNORDERED) == SCTP_DATA_UNORDERED) || ((chunkDescPtr->chunkFlg & SCTP_DATA_FIRST_FRAG) == SCTP_DATA_FIRST_FRAG) || ((chunkDescPtr->chunkFlg & SCTP_DATA_LAST_FRAG) == SCTP_DATA_LAST_FRAG) ) ND_PRINT((ndo, " ")); if (chunkLengthRemaining < sizeof(*dataHdrPtr)) { ND_PRINT((ndo, "bogus chunk length %u]", chunkLength)); return; } dataHdrPtr=(const struct sctpDataPart*)bp; ppid = EXTRACT_32BITS(&dataHdrPtr->payloadtype); ND_PRINT((ndo, "[TSN: %u] ", EXTRACT_32BITS(&dataHdrPtr->TSN))); ND_PRINT((ndo, "[SID: %u] ", EXTRACT_16BITS(&dataHdrPtr->streamId))); ND_PRINT((ndo, "[SSEQ %u] ", EXTRACT_16BITS(&dataHdrPtr->sequence))); ND_PRINT((ndo, "[PPID %s] ", tok2str(PayloadProto_idents, "0x%x", ppid))); if (!isforces) { isforces = (ppid == SCTP_PPID_FORCES_HP) || (ppid == SCTP_PPID_FORCES_MP) || (ppid == SCTP_PPID_FORCES_LP); } bp += sizeof(*dataHdrPtr); sctpPacketLengthRemaining -= sizeof(*dataHdrPtr); chunkLengthRemaining -= sizeof(*dataHdrPtr); payload_size = chunkLengthRemaining; if (payload_size == 0) { ND_PRINT((ndo, "bogus chunk length %u]", chunkLength)); return; } if (isforces) { forces_print(ndo, bp, payload_size); } else if (ndo->ndo_vflag >= 2) { /* if verbose output is specified */ /* at the command line */ switch (ppid) { case SCTP_PPID_M3UA : m3ua_print(ndo, bp, payload_size); break; default: ND_PRINT((ndo, "[Payload")); if (!ndo->ndo_suppress_default_print) { ND_PRINT((ndo, ":")); ND_DEFAULTPRINT(bp, payload_size); } ND_PRINT((ndo, "]")); break; } } bp += payload_size; sctpPacketLengthRemaining -= payload_size; chunkLengthRemaining -= payload_size; break; } case SCTP_INITIATION : { const struct sctpInitiation *init; if (chunkLengthRemaining < sizeof(*init)) { ND_PRINT((ndo, "bogus chunk length %u]", chunkLength)); return; } init=(const struct sctpInitiation*)bp; ND_PRINT((ndo, "[init tag: %u] ", EXTRACT_32BITS(&init->initTag))); ND_PRINT((ndo, "[rwnd: %u] ", EXTRACT_32BITS(&init->rcvWindowCredit))); ND_PRINT((ndo, "[OS: %u] ", EXTRACT_16BITS(&init->NumPreopenStreams))); ND_PRINT((ndo, "[MIS: %u] ", EXTRACT_16BITS(&init->MaxInboundStreams))); ND_PRINT((ndo, "[init TSN: %u] ", EXTRACT_32BITS(&init->initialTSN))); bp += sizeof(*init); sctpPacketLengthRemaining -= sizeof(*init); chunkLengthRemaining -= sizeof(*init); #if 0 /* ALC you can add code for optional params here */ if( chunkLengthRemaining != 0 ) ND_PRINT((ndo, " @@@@@ UNFINISHED @@@@@@%s\n", "Optional params present, but not printed.")); #endif bp += chunkLengthRemaining; sctpPacketLengthRemaining -= chunkLengthRemaining; chunkLengthRemaining = 0; break; } case SCTP_INITIATION_ACK : { const struct sctpInitiation *init; if (chunkLengthRemaining < sizeof(*init)) { ND_PRINT((ndo, "bogus chunk length %u]", chunkLength)); return; } init=(const struct sctpInitiation*)bp; ND_PRINT((ndo, "[init tag: %u] ", EXTRACT_32BITS(&init->initTag))); ND_PRINT((ndo, "[rwnd: %u] ", EXTRACT_32BITS(&init->rcvWindowCredit))); ND_PRINT((ndo, "[OS: %u] ", EXTRACT_16BITS(&init->NumPreopenStreams))); ND_PRINT((ndo, "[MIS: %u] ", EXTRACT_16BITS(&init->MaxInboundStreams))); ND_PRINT((ndo, "[init TSN: %u] ", EXTRACT_32BITS(&init->initialTSN))); bp += sizeof(*init); sctpPacketLengthRemaining -= sizeof(*init); chunkLengthRemaining -= sizeof(*init); #if 0 /* ALC you can add code for optional params here */ if( chunkLengthRemaining != 0 ) ND_PRINT((ndo, " @@@@@ UNFINISHED @@@@@@%s\n", "Optional params present, but not printed.")); #endif bp += chunkLengthRemaining; sctpPacketLengthRemaining -= chunkLengthRemaining; chunkLengthRemaining = 0; break; } case SCTP_SELECTIVE_ACK: { const struct sctpSelectiveAck *sack; const struct sctpSelectiveFrag *frag; int fragNo, tsnNo; const u_char *dupTSN; if (chunkLengthRemaining < sizeof(*sack)) { ND_PRINT((ndo, "bogus chunk length %u]", chunkLength)); return; } sack=(const struct sctpSelectiveAck*)bp; ND_PRINT((ndo, "[cum ack %u] ", EXTRACT_32BITS(&sack->highestConseqTSN))); ND_PRINT((ndo, "[a_rwnd %u] ", EXTRACT_32BITS(&sack->updatedRwnd))); ND_PRINT((ndo, "[#gap acks %u] ", EXTRACT_16BITS(&sack->numberOfdesc))); ND_PRINT((ndo, "[#dup tsns %u] ", EXTRACT_16BITS(&sack->numDupTsns))); bp += sizeof(*sack); sctpPacketLengthRemaining -= sizeof(*sack); chunkLengthRemaining -= sizeof(*sack); /* print gaps */ for (fragNo=0; chunkLengthRemaining != 0 && fragNo < EXTRACT_16BITS(&sack->numberOfdesc); bp += sizeof(*frag), sctpPacketLengthRemaining -= sizeof(*frag), chunkLengthRemaining -= sizeof(*frag), fragNo++) { if (chunkLengthRemaining < sizeof(*frag)) { ND_PRINT((ndo, "bogus chunk length %u]", chunkLength)); return; } frag = (const struct sctpSelectiveFrag *)bp; ND_PRINT((ndo, "\n\t\t[gap ack block #%d: start = %u, end = %u] ", fragNo+1, EXTRACT_32BITS(&sack->highestConseqTSN) + EXTRACT_16BITS(&frag->fragmentStart), EXTRACT_32BITS(&sack->highestConseqTSN) + EXTRACT_16BITS(&frag->fragmentEnd))); } /* print duplicate TSNs */ for (tsnNo=0; chunkLengthRemaining != 0 && tsnNonumDupTsns); bp += 4, sctpPacketLengthRemaining -= 4, chunkLengthRemaining -= 4, tsnNo++) { if (chunkLengthRemaining < 4) { ND_PRINT((ndo, "bogus chunk length %u]", chunkLength)); return; } dupTSN = (const u_char *)bp; ND_PRINT((ndo, "\n\t\t[dup TSN #%u: %u] ", tsnNo+1, EXTRACT_32BITS(dupTSN))); } break; } default : { bp += chunkLengthRemaining; sctpPacketLengthRemaining -= chunkLengthRemaining; chunkLengthRemaining = 0; break; } } /* * Any extra stuff at the end of the chunk? * XXX - report this? */ bp += chunkLengthRemaining; sctpPacketLengthRemaining -= chunkLengthRemaining; if (ndo->ndo_vflag < 2) sep = ", ("; if (align != 0) { /* * Fail if the alignment padding isn't in the captured data. * Otherwise, skip it. */ ND_TCHECK2(*bp, align); bp += align; sctpPacketLengthRemaining -= align; } } return; trunc: ND_PRINT((ndo, "[|sctp]")); } tcpdump-4.9.3/print-pktap.c0000644000026300017510000001226513544412561013756 0ustar mcrmcr/* * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of * the University nor the names of its contributors may be used to endorse * or promote products derived from this software without specific prior * written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* \summary: Apple's DLT_PKTAP printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #include "extract.h" #ifdef DLT_PKTAP /* * XXX - these are little-endian in the captures I've seen, but Apple * no longer make any big-endian machines (Macs use x86, iOS machines * use ARM and run it little-endian), so that might be by definition * or they might be host-endian. * * If a big-endian PKTAP file ever shows up, and it comes from a * big-endian machine, presumably these are host-endian, and we need * to just fetch the fields directly in tcpdump but byte-swap them * to host byte order in libpcap. */ typedef struct pktap_header { uint32_t pkt_len; /* length of pktap header */ uint32_t pkt_rectype; /* type of record */ uint32_t pkt_dlt; /* DLT type of this packet */ char pkt_ifname[24]; /* interface name */ uint32_t pkt_flags; uint32_t pkt_pfamily; /* "protocol family" */ uint32_t pkt_llhdrlen; /* link-layer header length? */ uint32_t pkt_lltrlrlen; /* link-layer trailer length? */ uint32_t pkt_pid; /* process ID */ char pkt_cmdname[20]; /* command name */ uint32_t pkt_svc_class; /* "service class" */ uint16_t pkt_iftype; /* "interface type" */ uint16_t pkt_ifunit; /* unit number of interface? */ uint32_t pkt_epid; /* "effective process ID" */ char pkt_ecmdname[20]; /* "effective command name" */ } pktap_header_t; /* * Record types. */ #define PKT_REC_NONE 0 /* nothing follows the header */ #define PKT_REC_PACKET 1 /* a packet follows the header */ static inline void pktap_header_print(netdissect_options *ndo, const u_char *bp, u_int length) { const pktap_header_t *hdr; uint32_t dlt, hdrlen; const char *dltname; hdr = (const pktap_header_t *)bp; dlt = EXTRACT_LE_32BITS(&hdr->pkt_dlt); hdrlen = EXTRACT_LE_32BITS(&hdr->pkt_len); dltname = pcap_datalink_val_to_name(dlt); if (!ndo->ndo_qflag) { ND_PRINT((ndo,"DLT %s (%d) len %d", (dltname != NULL ? dltname : "UNKNOWN"), dlt, hdrlen)); } else { ND_PRINT((ndo,"%s", (dltname != NULL ? dltname : "UNKNOWN"))); } ND_PRINT((ndo, ", length %u: ", length)); } /* * This is the top level routine of the printer. 'p' points * to the ether header of the packet, 'h->ts' is the timestamp, * 'h->len' is the length of the packet off the wire, and 'h->caplen' * is the number of bytes actually captured. */ u_int pktap_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) { uint32_t dlt, hdrlen, rectype; u_int caplen = h->caplen; u_int length = h->len; if_printer printer; const pktap_header_t *hdr; struct pcap_pkthdr nhdr; if (caplen < sizeof(pktap_header_t) || length < sizeof(pktap_header_t)) { ND_PRINT((ndo, "[|pktap]")); return (0); } hdr = (const pktap_header_t *)p; dlt = EXTRACT_LE_32BITS(&hdr->pkt_dlt); hdrlen = EXTRACT_LE_32BITS(&hdr->pkt_len); if (hdrlen < sizeof(pktap_header_t)) { /* * Claimed header length < structure length. * XXX - does this just mean some fields aren't * being supplied, or is it truly an error (i.e., * is the length supplied so that the header can * be expanded in the future)? */ ND_PRINT((ndo, "[|pktap]")); return (0); } if (caplen < hdrlen || length < hdrlen) { ND_PRINT((ndo, "[|pktap]")); return (hdrlen); } if (ndo->ndo_eflag) pktap_header_print(ndo, p, length); length -= hdrlen; caplen -= hdrlen; p += hdrlen; rectype = EXTRACT_LE_32BITS(&hdr->pkt_rectype); switch (rectype) { case PKT_REC_NONE: ND_PRINT((ndo, "no data")); break; case PKT_REC_PACKET: if ((printer = lookup_printer(dlt)) != NULL) { nhdr = *h; nhdr.caplen = caplen; nhdr.len = length; hdrlen += printer(ndo, &nhdr, p); } else { if (!ndo->ndo_eflag) pktap_header_print(ndo, (const u_char *)hdr, length + hdrlen); if (!ndo->ndo_suppress_default_print) ND_DEFAULTPRINT(p, caplen); } break; } return (hdrlen); } /* * Local Variables: * c-style: whitesmith * c-basic-offset: 8 * End: */ #endif /* DLT_PKTAP */ tcpdump-4.9.3/print-eigrp.c0000644000026300017510000004676213544412724013757 0ustar mcrmcr/* * Copyright (c) 1998-2004 Hannes Gredler * The TCPDUMP project * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code * distributions retain the above copyright notice and this paragraph * in its entirety, and (2) distributions including binary code include * the above copyright notice and this paragraph in its entirety in * the documentation or other materials provided with the distribution. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. */ /* \summary: Enhanced Interior Gateway Routing Protocol (EIGRP) printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include "netdissect.h" #include "extract.h" #include "addrtoname.h" /* * packet format documented at * http://www.rhyshaden.com/eigrp.htm * RFC 7868 */ struct eigrp_common_header { uint8_t version; uint8_t opcode; uint8_t checksum[2]; uint8_t flags[4]; uint8_t seq[4]; uint8_t ack[4]; uint8_t asn[4]; }; #define EIGRP_VERSION 2 #define EIGRP_OPCODE_UPDATE 1 #define EIGRP_OPCODE_QUERY 3 #define EIGRP_OPCODE_REPLY 4 #define EIGRP_OPCODE_HELLO 5 #define EIGRP_OPCODE_IPXSAP 6 #define EIGRP_OPCODE_PROBE 7 static const struct tok eigrp_opcode_values[] = { { EIGRP_OPCODE_UPDATE, "Update" }, { EIGRP_OPCODE_QUERY, "Query" }, { EIGRP_OPCODE_REPLY, "Reply" }, { EIGRP_OPCODE_HELLO, "Hello" }, { EIGRP_OPCODE_IPXSAP, "IPX SAP" }, { EIGRP_OPCODE_PROBE, "Probe" }, { 0, NULL} }; static const struct tok eigrp_common_header_flag_values[] = { { 0x01, "Init" }, { 0x02, "Conditionally Received" }, { 0, NULL} }; struct eigrp_tlv_header { uint8_t type[2]; uint8_t length[2]; }; #define EIGRP_TLV_GENERAL_PARM 0x0001 #define EIGRP_TLV_AUTH 0x0002 #define EIGRP_TLV_SEQ 0x0003 #define EIGRP_TLV_SW_VERSION 0x0004 #define EIGRP_TLV_MCAST_SEQ 0x0005 #define EIGRP_TLV_IP_INT 0x0102 #define EIGRP_TLV_IP_EXT 0x0103 #define EIGRP_TLV_AT_INT 0x0202 #define EIGRP_TLV_AT_EXT 0x0203 #define EIGRP_TLV_AT_CABLE_SETUP 0x0204 #define EIGRP_TLV_IPX_INT 0x0302 #define EIGRP_TLV_IPX_EXT 0x0303 static const struct tok eigrp_tlv_values[] = { { EIGRP_TLV_GENERAL_PARM, "General Parameters"}, { EIGRP_TLV_AUTH, "Authentication"}, { EIGRP_TLV_SEQ, "Sequence"}, { EIGRP_TLV_SW_VERSION, "Software Version"}, { EIGRP_TLV_MCAST_SEQ, "Next Multicast Sequence"}, { EIGRP_TLV_IP_INT, "IP Internal routes"}, { EIGRP_TLV_IP_EXT, "IP External routes"}, { EIGRP_TLV_AT_INT, "AppleTalk Internal routes"}, { EIGRP_TLV_AT_EXT, "AppleTalk External routes"}, { EIGRP_TLV_AT_CABLE_SETUP, "AppleTalk Cable setup"}, { EIGRP_TLV_IPX_INT, "IPX Internal routes"}, { EIGRP_TLV_IPX_EXT, "IPX External routes"}, { 0, NULL} }; struct eigrp_tlv_general_parm_t { uint8_t k1; uint8_t k2; uint8_t k3; uint8_t k4; uint8_t k5; uint8_t res; uint8_t holdtime[2]; }; struct eigrp_tlv_sw_version_t { uint8_t ios_major; uint8_t ios_minor; uint8_t eigrp_major; uint8_t eigrp_minor; }; struct eigrp_tlv_ip_int_t { uint8_t nexthop[4]; uint8_t delay[4]; uint8_t bandwidth[4]; uint8_t mtu[3]; uint8_t hopcount; uint8_t reliability; uint8_t load; uint8_t reserved[2]; uint8_t plen; uint8_t destination; /* variable length [1-4] bytes encoding */ }; struct eigrp_tlv_ip_ext_t { uint8_t nexthop[4]; uint8_t origin_router[4]; uint8_t origin_as[4]; uint8_t tag[4]; uint8_t metric[4]; uint8_t reserved[2]; uint8_t proto_id; uint8_t flags; uint8_t delay[4]; uint8_t bandwidth[4]; uint8_t mtu[3]; uint8_t hopcount; uint8_t reliability; uint8_t load; uint8_t reserved2[2]; uint8_t plen; uint8_t destination; /* variable length [1-4] bytes encoding */ }; struct eigrp_tlv_at_cable_setup_t { uint8_t cable_start[2]; uint8_t cable_end[2]; uint8_t router_id[4]; }; struct eigrp_tlv_at_int_t { uint8_t nexthop[4]; uint8_t delay[4]; uint8_t bandwidth[4]; uint8_t mtu[3]; uint8_t hopcount; uint8_t reliability; uint8_t load; uint8_t reserved[2]; uint8_t cable_start[2]; uint8_t cable_end[2]; }; struct eigrp_tlv_at_ext_t { uint8_t nexthop[4]; uint8_t origin_router[4]; uint8_t origin_as[4]; uint8_t tag[4]; uint8_t proto_id; uint8_t flags; uint8_t metric[2]; uint8_t delay[4]; uint8_t bandwidth[4]; uint8_t mtu[3]; uint8_t hopcount; uint8_t reliability; uint8_t load; uint8_t reserved2[2]; uint8_t cable_start[2]; uint8_t cable_end[2]; }; static const struct tok eigrp_ext_proto_id_values[] = { { 0x01, "IGRP" }, { 0x02, "EIGRP" }, { 0x03, "Static" }, { 0x04, "RIP" }, { 0x05, "Hello" }, { 0x06, "OSPF" }, { 0x07, "IS-IS" }, { 0x08, "EGP" }, { 0x09, "BGP" }, { 0x0a, "IDRP" }, { 0x0b, "Connected" }, { 0, NULL} }; void eigrp_print(netdissect_options *ndo, register const u_char *pptr, register u_int len) { const struct eigrp_common_header *eigrp_com_header; const struct eigrp_tlv_header *eigrp_tlv_header; const u_char *tptr,*tlv_tptr; u_int tlen,eigrp_tlv_len,eigrp_tlv_type,tlv_tlen, byte_length, bit_length; uint8_t prefix[4]; union { const struct eigrp_tlv_general_parm_t *eigrp_tlv_general_parm; const struct eigrp_tlv_sw_version_t *eigrp_tlv_sw_version; const struct eigrp_tlv_ip_int_t *eigrp_tlv_ip_int; const struct eigrp_tlv_ip_ext_t *eigrp_tlv_ip_ext; const struct eigrp_tlv_at_cable_setup_t *eigrp_tlv_at_cable_setup; const struct eigrp_tlv_at_int_t *eigrp_tlv_at_int; const struct eigrp_tlv_at_ext_t *eigrp_tlv_at_ext; } tlv_ptr; tptr=pptr; eigrp_com_header = (const struct eigrp_common_header *)pptr; ND_TCHECK(*eigrp_com_header); /* * Sanity checking of the header. */ if (eigrp_com_header->version != EIGRP_VERSION) { ND_PRINT((ndo, "EIGRP version %u packet not supported",eigrp_com_header->version)); return; } /* in non-verbose mode just lets print the basic Message Type*/ if (ndo->ndo_vflag < 1) { ND_PRINT((ndo, "EIGRP %s, length: %u", tok2str(eigrp_opcode_values, "unknown (%u)",eigrp_com_header->opcode), len)); return; } /* ok they seem to want to know everything - lets fully decode it */ if (len < sizeof(struct eigrp_common_header)) { ND_PRINT((ndo, "EIGRP %s, length: %u (too short, < %u)", tok2str(eigrp_opcode_values, "unknown (%u)",eigrp_com_header->opcode), len, (u_int) sizeof(struct eigrp_common_header))); return; } tlen=len-sizeof(struct eigrp_common_header); /* FIXME print other header info */ ND_PRINT((ndo, "\n\tEIGRP v%u, opcode: %s (%u), chksum: 0x%04x, Flags: [%s]\n\tseq: 0x%08x, ack: 0x%08x, AS: %u, length: %u", eigrp_com_header->version, tok2str(eigrp_opcode_values, "unknown, type: %u",eigrp_com_header->opcode), eigrp_com_header->opcode, EXTRACT_16BITS(&eigrp_com_header->checksum), tok2str(eigrp_common_header_flag_values, "none", EXTRACT_32BITS(&eigrp_com_header->flags)), EXTRACT_32BITS(&eigrp_com_header->seq), EXTRACT_32BITS(&eigrp_com_header->ack), EXTRACT_32BITS(&eigrp_com_header->asn), tlen)); tptr+=sizeof(const struct eigrp_common_header); while(tlen>0) { /* did we capture enough for fully decoding the object header ? */ ND_TCHECK2(*tptr, sizeof(struct eigrp_tlv_header)); eigrp_tlv_header = (const struct eigrp_tlv_header *)tptr; eigrp_tlv_len=EXTRACT_16BITS(&eigrp_tlv_header->length); eigrp_tlv_type=EXTRACT_16BITS(&eigrp_tlv_header->type); if (eigrp_tlv_len < sizeof(struct eigrp_tlv_header) || eigrp_tlv_len > tlen) { print_unknown_data(ndo,tptr+sizeof(struct eigrp_tlv_header),"\n\t ",tlen); return; } ND_PRINT((ndo, "\n\t %s TLV (0x%04x), length: %u", tok2str(eigrp_tlv_values, "Unknown", eigrp_tlv_type), eigrp_tlv_type, eigrp_tlv_len)); if (eigrp_tlv_len < sizeof(struct eigrp_tlv_header)) { ND_PRINT((ndo, " (too short, < %u)", (u_int) sizeof(struct eigrp_tlv_header))); break; } tlv_tptr=tptr+sizeof(struct eigrp_tlv_header); tlv_tlen=eigrp_tlv_len-sizeof(struct eigrp_tlv_header); /* did we capture enough for fully decoding the object ? */ ND_TCHECK2(*tptr, eigrp_tlv_len); switch(eigrp_tlv_type) { case EIGRP_TLV_GENERAL_PARM: tlv_ptr.eigrp_tlv_general_parm = (const struct eigrp_tlv_general_parm_t *)tlv_tptr; if (tlv_tlen < sizeof(*tlv_ptr.eigrp_tlv_general_parm)) { ND_PRINT((ndo, " (too short, < %u)", (u_int) (sizeof(struct eigrp_tlv_header) + sizeof(*tlv_ptr.eigrp_tlv_general_parm)))); break; } ND_PRINT((ndo, "\n\t holdtime: %us, k1 %u, k2 %u, k3 %u, k4 %u, k5 %u", EXTRACT_16BITS(tlv_ptr.eigrp_tlv_general_parm->holdtime), tlv_ptr.eigrp_tlv_general_parm->k1, tlv_ptr.eigrp_tlv_general_parm->k2, tlv_ptr.eigrp_tlv_general_parm->k3, tlv_ptr.eigrp_tlv_general_parm->k4, tlv_ptr.eigrp_tlv_general_parm->k5)); break; case EIGRP_TLV_SW_VERSION: tlv_ptr.eigrp_tlv_sw_version = (const struct eigrp_tlv_sw_version_t *)tlv_tptr; if (tlv_tlen < sizeof(*tlv_ptr.eigrp_tlv_sw_version)) { ND_PRINT((ndo, " (too short, < %u)", (u_int) (sizeof(struct eigrp_tlv_header) + sizeof(*tlv_ptr.eigrp_tlv_sw_version)))); break; } ND_PRINT((ndo, "\n\t IOS version: %u.%u, EIGRP version %u.%u", tlv_ptr.eigrp_tlv_sw_version->ios_major, tlv_ptr.eigrp_tlv_sw_version->ios_minor, tlv_ptr.eigrp_tlv_sw_version->eigrp_major, tlv_ptr.eigrp_tlv_sw_version->eigrp_minor)); break; case EIGRP_TLV_IP_INT: tlv_ptr.eigrp_tlv_ip_int = (const struct eigrp_tlv_ip_int_t *)tlv_tptr; if (tlv_tlen < sizeof(*tlv_ptr.eigrp_tlv_ip_int)) { ND_PRINT((ndo, " (too short, < %u)", (u_int) (sizeof(struct eigrp_tlv_header) + sizeof(*tlv_ptr.eigrp_tlv_ip_int)))); break; } bit_length = tlv_ptr.eigrp_tlv_ip_int->plen; if (bit_length > 32) { ND_PRINT((ndo, "\n\t illegal prefix length %u",bit_length)); break; } byte_length = (bit_length + 7) / 8; /* variable length encoding */ memset(prefix, 0, 4); ND_TCHECK2(tlv_ptr.eigrp_tlv_ip_int->destination, byte_length); memcpy(prefix,&tlv_ptr.eigrp_tlv_ip_int->destination,byte_length); ND_PRINT((ndo, "\n\t IPv4 prefix: %15s/%u, nexthop: ", ipaddr_string(ndo, prefix), bit_length)); if (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_int->nexthop) == 0) ND_PRINT((ndo, "self")); else ND_PRINT((ndo, "%s",ipaddr_string(ndo, &tlv_ptr.eigrp_tlv_ip_int->nexthop))); ND_PRINT((ndo, "\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u", (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_int->delay)/100), EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_int->bandwidth), EXTRACT_24BITS(&tlv_ptr.eigrp_tlv_ip_int->mtu), tlv_ptr.eigrp_tlv_ip_int->hopcount, tlv_ptr.eigrp_tlv_ip_int->reliability, tlv_ptr.eigrp_tlv_ip_int->load)); break; case EIGRP_TLV_IP_EXT: tlv_ptr.eigrp_tlv_ip_ext = (const struct eigrp_tlv_ip_ext_t *)tlv_tptr; if (tlv_tlen < sizeof(*tlv_ptr.eigrp_tlv_ip_ext)) { ND_PRINT((ndo, " (too short, < %u)", (u_int) (sizeof(struct eigrp_tlv_header) + sizeof(*tlv_ptr.eigrp_tlv_ip_ext)))); break; } bit_length = tlv_ptr.eigrp_tlv_ip_ext->plen; if (bit_length > 32) { ND_PRINT((ndo, "\n\t illegal prefix length %u",bit_length)); break; } byte_length = (bit_length + 7) / 8; /* variable length encoding */ memset(prefix, 0, 4); ND_TCHECK2(tlv_ptr.eigrp_tlv_ip_ext->destination, byte_length); memcpy(prefix,&tlv_ptr.eigrp_tlv_ip_ext->destination,byte_length); ND_PRINT((ndo, "\n\t IPv4 prefix: %15s/%u, nexthop: ", ipaddr_string(ndo, prefix), bit_length)); if (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_ext->nexthop) == 0) ND_PRINT((ndo, "self")); else ND_PRINT((ndo, "%s",ipaddr_string(ndo, &tlv_ptr.eigrp_tlv_ip_ext->nexthop))); ND_PRINT((ndo, "\n\t origin-router %s, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u", ipaddr_string(ndo, tlv_ptr.eigrp_tlv_ip_ext->origin_router), EXTRACT_32BITS(tlv_ptr.eigrp_tlv_ip_ext->origin_as), tok2str(eigrp_ext_proto_id_values,"unknown",tlv_ptr.eigrp_tlv_ip_ext->proto_id), tlv_ptr.eigrp_tlv_ip_ext->flags, EXTRACT_32BITS(tlv_ptr.eigrp_tlv_ip_ext->tag), EXTRACT_32BITS(tlv_ptr.eigrp_tlv_ip_ext->metric))); ND_PRINT((ndo, "\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u", (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_ext->delay)/100), EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_ext->bandwidth), EXTRACT_24BITS(&tlv_ptr.eigrp_tlv_ip_ext->mtu), tlv_ptr.eigrp_tlv_ip_ext->hopcount, tlv_ptr.eigrp_tlv_ip_ext->reliability, tlv_ptr.eigrp_tlv_ip_ext->load)); break; case EIGRP_TLV_AT_CABLE_SETUP: tlv_ptr.eigrp_tlv_at_cable_setup = (const struct eigrp_tlv_at_cable_setup_t *)tlv_tptr; if (tlv_tlen < sizeof(*tlv_ptr.eigrp_tlv_at_cable_setup)) { ND_PRINT((ndo, " (too short, < %u)", (u_int) (sizeof(struct eigrp_tlv_header) + sizeof(*tlv_ptr.eigrp_tlv_at_cable_setup)))); break; } ND_PRINT((ndo, "\n\t Cable-range: %u-%u, Router-ID %u", EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_cable_setup->cable_start), EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_cable_setup->cable_end), EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_cable_setup->router_id))); break; case EIGRP_TLV_AT_INT: tlv_ptr.eigrp_tlv_at_int = (const struct eigrp_tlv_at_int_t *)tlv_tptr; if (tlv_tlen < sizeof(*tlv_ptr.eigrp_tlv_at_int)) { ND_PRINT((ndo, " (too short, < %u)", (u_int) (sizeof(struct eigrp_tlv_header) + sizeof(*tlv_ptr.eigrp_tlv_at_int)))); break; } ND_PRINT((ndo, "\n\t Cable-Range: %u-%u, nexthop: ", EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_int->cable_start), EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_int->cable_end))); if (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_int->nexthop) == 0) ND_PRINT((ndo, "self")); else ND_PRINT((ndo, "%u.%u", EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_int->nexthop), EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_int->nexthop[2]))); ND_PRINT((ndo, "\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u", (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_int->delay)/100), EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_int->bandwidth), EXTRACT_24BITS(&tlv_ptr.eigrp_tlv_at_int->mtu), tlv_ptr.eigrp_tlv_at_int->hopcount, tlv_ptr.eigrp_tlv_at_int->reliability, tlv_ptr.eigrp_tlv_at_int->load)); break; case EIGRP_TLV_AT_EXT: tlv_ptr.eigrp_tlv_at_ext = (const struct eigrp_tlv_at_ext_t *)tlv_tptr; if (tlv_tlen < sizeof(*tlv_ptr.eigrp_tlv_at_ext)) { ND_PRINT((ndo, " (too short, < %u)", (u_int) (sizeof(struct eigrp_tlv_header) + sizeof(*tlv_ptr.eigrp_tlv_at_ext)))); break; } ND_PRINT((ndo, "\n\t Cable-Range: %u-%u, nexthop: ", EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_ext->cable_start), EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_ext->cable_end))); if (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_ext->nexthop) == 0) ND_PRINT((ndo, "self")); else ND_PRINT((ndo, "%u.%u", EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_ext->nexthop), EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_ext->nexthop[2]))); ND_PRINT((ndo, "\n\t origin-router %u, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u", EXTRACT_32BITS(tlv_ptr.eigrp_tlv_at_ext->origin_router), EXTRACT_32BITS(tlv_ptr.eigrp_tlv_at_ext->origin_as), tok2str(eigrp_ext_proto_id_values,"unknown",tlv_ptr.eigrp_tlv_at_ext->proto_id), tlv_ptr.eigrp_tlv_at_ext->flags, EXTRACT_32BITS(tlv_ptr.eigrp_tlv_at_ext->tag), EXTRACT_16BITS(tlv_ptr.eigrp_tlv_at_ext->metric))); ND_PRINT((ndo, "\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u", (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_ext->delay)/100), EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_ext->bandwidth), EXTRACT_24BITS(&tlv_ptr.eigrp_tlv_at_ext->mtu), tlv_ptr.eigrp_tlv_at_ext->hopcount, tlv_ptr.eigrp_tlv_at_ext->reliability, tlv_ptr.eigrp_tlv_at_ext->load)); break; /* * FIXME those are the defined TLVs that lack a decoder * you are welcome to contribute code ;-) */ case EIGRP_TLV_AUTH: case EIGRP_TLV_SEQ: case EIGRP_TLV_MCAST_SEQ: case EIGRP_TLV_IPX_INT: case EIGRP_TLV_IPX_EXT: default: if (ndo->ndo_vflag <= 1) print_unknown_data(ndo,tlv_tptr,"\n\t ",tlv_tlen); break; } /* do we want to see an additionally hexdump ? */ if (ndo->ndo_vflag > 1) print_unknown_data(ndo,tptr+sizeof(struct eigrp_tlv_header),"\n\t ", eigrp_tlv_len-sizeof(struct eigrp_tlv_header)); tptr+=eigrp_tlv_len; tlen-=eigrp_tlv_len; } return; trunc: ND_PRINT((ndo, "\n\t\t packet exceeded snapshot")); } tcpdump-4.9.3/print-cfm.c0000644000026300017510000006027613544412561013411 0ustar mcrmcr/* * Copyright (c) 1998-2006 The TCPDUMP project * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code * distributions retain the above copyright notice and this paragraph * in its entirety, and (2) distributions including binary code include * the above copyright notice and this paragraph in its entirety in * the documentation or other materials provided with the distribution. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. * * Original code by Hannes Gredler (hannes@gredler.at) */ /* \summary: IEEE 802.1ag Connectivity Fault Management (CFM) protocols printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include "netdissect.h" #include "extract.h" #include "ether.h" #include "addrtoname.h" #include "oui.h" #include "af.h" struct cfm_common_header_t { uint8_t mdlevel_version; uint8_t opcode; uint8_t flags; uint8_t first_tlv_offset; }; #define CFM_VERSION 0 #define CFM_EXTRACT_VERSION(x) (((x)&0x1f)) #define CFM_EXTRACT_MD_LEVEL(x) (((x)&0xe0)>>5) #define CFM_OPCODE_CCM 1 #define CFM_OPCODE_LBR 2 #define CFM_OPCODE_LBM 3 #define CFM_OPCODE_LTR 4 #define CFM_OPCODE_LTM 5 static const struct tok cfm_opcode_values[] = { { CFM_OPCODE_CCM, "Continouity Check Message"}, { CFM_OPCODE_LBR, "Loopback Reply"}, { CFM_OPCODE_LBM, "Loopback Message"}, { CFM_OPCODE_LTR, "Linktrace Reply"}, { CFM_OPCODE_LTM, "Linktrace Message"}, { 0, NULL} }; /* * Message Formats. */ struct cfm_ccm_t { uint8_t sequence[4]; uint8_t ma_epi[2]; uint8_t names[48]; uint8_t itu_t_y_1731[16]; }; /* * Timer Bases for the CCM Interval field. * Expressed in units of seconds. */ static const float ccm_interval_base[8] = {0, 0.003333, 0.01, 0.1, 1, 10, 60, 600}; #define CCM_INTERVAL_MIN_MULTIPLIER 3.25 #define CCM_INTERVAL_MAX_MULTIPLIER 3.5 #define CFM_CCM_RDI_FLAG 0x80 #define CFM_EXTRACT_CCM_INTERVAL(x) (((x)&0x07)) #define CFM_CCM_MD_FORMAT_8021 0 #define CFM_CCM_MD_FORMAT_NONE 1 #define CFM_CCM_MD_FORMAT_DNS 2 #define CFM_CCM_MD_FORMAT_MAC 3 #define CFM_CCM_MD_FORMAT_CHAR 4 static const struct tok cfm_md_nameformat_values[] = { { CFM_CCM_MD_FORMAT_8021, "IEEE 802.1"}, { CFM_CCM_MD_FORMAT_NONE, "No MD Name present"}, { CFM_CCM_MD_FORMAT_DNS, "DNS string"}, { CFM_CCM_MD_FORMAT_MAC, "MAC + 16Bit Integer"}, { CFM_CCM_MD_FORMAT_CHAR, "Character string"}, { 0, NULL} }; #define CFM_CCM_MA_FORMAT_8021 0 #define CFM_CCM_MA_FORMAT_VID 1 #define CFM_CCM_MA_FORMAT_CHAR 2 #define CFM_CCM_MA_FORMAT_INT 3 #define CFM_CCM_MA_FORMAT_VPN 4 static const struct tok cfm_ma_nameformat_values[] = { { CFM_CCM_MA_FORMAT_8021, "IEEE 802.1"}, { CFM_CCM_MA_FORMAT_VID, "Primary VID"}, { CFM_CCM_MA_FORMAT_CHAR, "Character string"}, { CFM_CCM_MA_FORMAT_INT, "16Bit Integer"}, { CFM_CCM_MA_FORMAT_VPN, "RFC2685 VPN-ID"}, { 0, NULL} }; struct cfm_lbm_t { uint8_t transaction_id[4]; }; struct cfm_ltm_t { uint8_t transaction_id[4]; uint8_t ttl; uint8_t original_mac[ETHER_ADDR_LEN]; uint8_t target_mac[ETHER_ADDR_LEN]; }; static const struct tok cfm_ltm_flag_values[] = { { 0x80, "Use Forwarding-DB only"}, { 0, NULL} }; struct cfm_ltr_t { uint8_t transaction_id[4]; uint8_t ttl; uint8_t replay_action; }; static const struct tok cfm_ltr_flag_values[] = { { 0x80, "UseFDB Only"}, { 0x40, "FwdYes"}, { 0x20, "Terminal MEP"}, { 0, NULL} }; static const struct tok cfm_ltr_replay_action_values[] = { { 1, "Exact Match"}, { 2, "Filtering DB"}, { 3, "MIP CCM DB"}, { 0, NULL} }; #define CFM_TLV_END 0 #define CFM_TLV_SENDER_ID 1 #define CFM_TLV_PORT_STATUS 2 #define CFM_TLV_INTERFACE_STATUS 3 #define CFM_TLV_DATA 4 #define CFM_TLV_REPLY_INGRESS 5 #define CFM_TLV_REPLY_EGRESS 6 #define CFM_TLV_PRIVATE 31 static const struct tok cfm_tlv_values[] = { { CFM_TLV_END, "End"}, { CFM_TLV_SENDER_ID, "Sender ID"}, { CFM_TLV_PORT_STATUS, "Port status"}, { CFM_TLV_INTERFACE_STATUS, "Interface status"}, { CFM_TLV_DATA, "Data"}, { CFM_TLV_REPLY_INGRESS, "Reply Ingress"}, { CFM_TLV_REPLY_EGRESS, "Reply Egress"}, { CFM_TLV_PRIVATE, "Organization Specific"}, { 0, NULL} }; /* * TLVs */ struct cfm_tlv_header_t { uint8_t type; uint8_t length[2]; }; /* FIXME define TLV formats */ static const struct tok cfm_tlv_port_status_values[] = { { 1, "Blocked"}, { 2, "Up"}, { 0, NULL} }; static const struct tok cfm_tlv_interface_status_values[] = { { 1, "Up"}, { 2, "Down"}, { 3, "Testing"}, { 5, "Dormant"}, { 6, "not present"}, { 7, "lower Layer down"}, { 0, NULL} }; #define CFM_CHASSIS_ID_CHASSIS_COMPONENT 1 #define CFM_CHASSIS_ID_INTERFACE_ALIAS 2 #define CFM_CHASSIS_ID_PORT_COMPONENT 3 #define CFM_CHASSIS_ID_MAC_ADDRESS 4 #define CFM_CHASSIS_ID_NETWORK_ADDRESS 5 #define CFM_CHASSIS_ID_INTERFACE_NAME 6 #define CFM_CHASSIS_ID_LOCAL 7 static const struct tok cfm_tlv_senderid_chassisid_values[] = { { 0, "Reserved"}, { CFM_CHASSIS_ID_CHASSIS_COMPONENT, "Chassis component"}, { CFM_CHASSIS_ID_INTERFACE_ALIAS, "Interface alias"}, { CFM_CHASSIS_ID_PORT_COMPONENT, "Port component"}, { CFM_CHASSIS_ID_MAC_ADDRESS, "MAC address"}, { CFM_CHASSIS_ID_NETWORK_ADDRESS, "Network address"}, { CFM_CHASSIS_ID_INTERFACE_NAME, "Interface name"}, { CFM_CHASSIS_ID_LOCAL, "Locally assigned"}, { 0, NULL} }; static int cfm_network_addr_print(netdissect_options *ndo, register const u_char *tptr, const u_int length) { u_int network_addr_type; u_int hexdump = FALSE; /* * Altough AFIs are tpically 2 octects wide, * 802.1ab specifies that this field width * is only once octet */ if (length < 1) { ND_PRINT((ndo, "\n\t Network Address Type (invalid, no data")); return hexdump; } /* The calling function must make any due ND_TCHECK calls. */ network_addr_type = *tptr; ND_PRINT((ndo, "\n\t Network Address Type %s (%u)", tok2str(af_values, "Unknown", network_addr_type), network_addr_type)); /* * Resolve the passed in Address. */ switch(network_addr_type) { case AFNUM_INET: if (length != 1 + 4) { ND_PRINT((ndo, "(invalid IPv4 address length %u)", length - 1)); hexdump = TRUE; break; } ND_PRINT((ndo, ", %s", ipaddr_string(ndo, tptr + 1))); break; case AFNUM_INET6: if (length != 1 + 16) { ND_PRINT((ndo, "(invalid IPv6 address length %u)", length - 1)); hexdump = TRUE; break; } ND_PRINT((ndo, ", %s", ip6addr_string(ndo, tptr + 1))); break; default: hexdump = TRUE; break; } return hexdump; } void cfm_print(netdissect_options *ndo, register const u_char *pptr, register u_int length) { const struct cfm_common_header_t *cfm_common_header; const struct cfm_tlv_header_t *cfm_tlv_header; const uint8_t *tptr, *tlv_ptr; const uint8_t *namesp; u_int names_data_remaining; uint8_t md_nameformat, md_namelength; const uint8_t *md_name; uint8_t ma_nameformat, ma_namelength; const uint8_t *ma_name; u_int hexdump, tlen, cfm_tlv_len, cfm_tlv_type, ccm_interval; union { const struct cfm_ccm_t *cfm_ccm; const struct cfm_lbm_t *cfm_lbm; const struct cfm_ltm_t *cfm_ltm; const struct cfm_ltr_t *cfm_ltr; } msg_ptr; tptr=pptr; cfm_common_header = (const struct cfm_common_header_t *)pptr; if (length < sizeof(*cfm_common_header)) goto tooshort; ND_TCHECK(*cfm_common_header); /* * Sanity checking of the header. */ if (CFM_EXTRACT_VERSION(cfm_common_header->mdlevel_version) != CFM_VERSION) { ND_PRINT((ndo, "CFMv%u not supported, length %u", CFM_EXTRACT_VERSION(cfm_common_header->mdlevel_version), length)); return; } ND_PRINT((ndo, "CFMv%u %s, MD Level %u, length %u", CFM_EXTRACT_VERSION(cfm_common_header->mdlevel_version), tok2str(cfm_opcode_values, "unknown (%u)", cfm_common_header->opcode), CFM_EXTRACT_MD_LEVEL(cfm_common_header->mdlevel_version), length)); /* * In non-verbose mode just print the opcode and md-level. */ if (ndo->ndo_vflag < 1) { return; } ND_PRINT((ndo, "\n\tFirst TLV offset %u", cfm_common_header->first_tlv_offset)); tptr += sizeof(const struct cfm_common_header_t); tlen = length - sizeof(struct cfm_common_header_t); /* * Sanity check the first TLV offset. */ if (cfm_common_header->first_tlv_offset > tlen) { ND_PRINT((ndo, " (too large, must be <= %u)", tlen)); return; } switch (cfm_common_header->opcode) { case CFM_OPCODE_CCM: msg_ptr.cfm_ccm = (const struct cfm_ccm_t *)tptr; if (cfm_common_header->first_tlv_offset < sizeof(*msg_ptr.cfm_ccm)) { ND_PRINT((ndo, " (too small 1, must be >= %lu)", (unsigned long) sizeof(*msg_ptr.cfm_ccm))); return; } if (tlen < sizeof(*msg_ptr.cfm_ccm)) goto tooshort; ND_TCHECK(*msg_ptr.cfm_ccm); ccm_interval = CFM_EXTRACT_CCM_INTERVAL(cfm_common_header->flags); ND_PRINT((ndo, ", Flags [CCM Interval %u%s]", ccm_interval, cfm_common_header->flags & CFM_CCM_RDI_FLAG ? ", RDI" : "")); /* * Resolve the CCM interval field. */ if (ccm_interval) { ND_PRINT((ndo, "\n\t CCM Interval %.3fs" ", min CCM Lifetime %.3fs, max CCM Lifetime %.3fs", ccm_interval_base[ccm_interval], ccm_interval_base[ccm_interval] * CCM_INTERVAL_MIN_MULTIPLIER, ccm_interval_base[ccm_interval] * CCM_INTERVAL_MAX_MULTIPLIER)); } ND_PRINT((ndo, "\n\t Sequence Number 0x%08x, MA-End-Point-ID 0x%04x", EXTRACT_32BITS(msg_ptr.cfm_ccm->sequence), EXTRACT_16BITS(msg_ptr.cfm_ccm->ma_epi))); namesp = msg_ptr.cfm_ccm->names; names_data_remaining = sizeof(msg_ptr.cfm_ccm->names); /* * Resolve the MD fields. */ md_nameformat = *namesp; namesp++; names_data_remaining--; /* We know this is != 0 */ if (md_nameformat != CFM_CCM_MD_FORMAT_NONE) { md_namelength = *namesp; namesp++; names_data_remaining--; /* We know this is !=0 */ ND_PRINT((ndo, "\n\t MD Name Format %s (%u), MD Name length %u", tok2str(cfm_md_nameformat_values, "Unknown", md_nameformat), md_nameformat, md_namelength)); /* * -3 for the MA short name format and length and one byte * of MA short name. */ if (md_namelength > names_data_remaining - 3) { ND_PRINT((ndo, " (too large, must be <= %u)", names_data_remaining - 2)); return; } md_name = namesp; ND_PRINT((ndo, "\n\t MD Name: ")); switch (md_nameformat) { case CFM_CCM_MD_FORMAT_DNS: case CFM_CCM_MD_FORMAT_CHAR: safeputs(ndo, md_name, md_namelength); break; case CFM_CCM_MD_FORMAT_MAC: if (md_namelength == 6) { ND_PRINT((ndo, "\n\t MAC %s", etheraddr_string(ndo, md_name))); } else { ND_PRINT((ndo, "\n\t MAC (length invalid)")); } break; /* FIXME add printers for those MD formats - hexdump for now */ case CFM_CCM_MA_FORMAT_8021: default: print_unknown_data(ndo, md_name, "\n\t ", md_namelength); } namesp += md_namelength; names_data_remaining -= md_namelength; } else { ND_PRINT((ndo, "\n\t MD Name Format %s (%u)", tok2str(cfm_md_nameformat_values, "Unknown", md_nameformat), md_nameformat)); } /* * Resolve the MA fields. */ ma_nameformat = *namesp; namesp++; names_data_remaining--; /* We know this is != 0 */ ma_namelength = *namesp; namesp++; names_data_remaining--; /* We know this is != 0 */ ND_PRINT((ndo, "\n\t MA Name-Format %s (%u), MA name length %u", tok2str(cfm_ma_nameformat_values, "Unknown", ma_nameformat), ma_nameformat, ma_namelength)); if (ma_namelength > names_data_remaining) { ND_PRINT((ndo, " (too large, must be <= %u)", names_data_remaining)); return; } ma_name = namesp; ND_PRINT((ndo, "\n\t MA Name: ")); switch (ma_nameformat) { case CFM_CCM_MA_FORMAT_CHAR: safeputs(ndo, ma_name, ma_namelength); break; /* FIXME add printers for those MA formats - hexdump for now */ case CFM_CCM_MA_FORMAT_8021: case CFM_CCM_MA_FORMAT_VID: case CFM_CCM_MA_FORMAT_INT: case CFM_CCM_MA_FORMAT_VPN: default: print_unknown_data(ndo, ma_name, "\n\t ", ma_namelength); } break; case CFM_OPCODE_LTM: msg_ptr.cfm_ltm = (const struct cfm_ltm_t *)tptr; if (cfm_common_header->first_tlv_offset < sizeof(*msg_ptr.cfm_ltm)) { ND_PRINT((ndo, " (too small 4, must be >= %lu)", (unsigned long) sizeof(*msg_ptr.cfm_ltm))); return; } if (tlen < sizeof(*msg_ptr.cfm_ltm)) goto tooshort; ND_TCHECK(*msg_ptr.cfm_ltm); ND_PRINT((ndo, ", Flags [%s]", bittok2str(cfm_ltm_flag_values, "none", cfm_common_header->flags))); ND_PRINT((ndo, "\n\t Transaction-ID 0x%08x, ttl %u", EXTRACT_32BITS(msg_ptr.cfm_ltm->transaction_id), msg_ptr.cfm_ltm->ttl)); ND_PRINT((ndo, "\n\t Original-MAC %s, Target-MAC %s", etheraddr_string(ndo, msg_ptr.cfm_ltm->original_mac), etheraddr_string(ndo, msg_ptr.cfm_ltm->target_mac))); break; case CFM_OPCODE_LTR: msg_ptr.cfm_ltr = (const struct cfm_ltr_t *)tptr; if (cfm_common_header->first_tlv_offset < sizeof(*msg_ptr.cfm_ltr)) { ND_PRINT((ndo, " (too small 5, must be >= %lu)", (unsigned long) sizeof(*msg_ptr.cfm_ltr))); return; } if (tlen < sizeof(*msg_ptr.cfm_ltr)) goto tooshort; ND_TCHECK(*msg_ptr.cfm_ltr); ND_PRINT((ndo, ", Flags [%s]", bittok2str(cfm_ltr_flag_values, "none", cfm_common_header->flags))); ND_PRINT((ndo, "\n\t Transaction-ID 0x%08x, ttl %u", EXTRACT_32BITS(msg_ptr.cfm_ltr->transaction_id), msg_ptr.cfm_ltr->ttl)); ND_PRINT((ndo, "\n\t Replay-Action %s (%u)", tok2str(cfm_ltr_replay_action_values, "Unknown", msg_ptr.cfm_ltr->replay_action), msg_ptr.cfm_ltr->replay_action)); break; /* * No message decoder yet. * Hexdump everything up until the start of the TLVs */ case CFM_OPCODE_LBR: case CFM_OPCODE_LBM: default: print_unknown_data(ndo, tptr, "\n\t ", tlen - cfm_common_header->first_tlv_offset); break; } tptr += cfm_common_header->first_tlv_offset; tlen -= cfm_common_header->first_tlv_offset; while (tlen > 0) { cfm_tlv_header = (const struct cfm_tlv_header_t *)tptr; /* Enough to read the tlv type ? */ ND_TCHECK2(*tptr, 1); cfm_tlv_type=cfm_tlv_header->type; ND_PRINT((ndo, "\n\t%s TLV (0x%02x)", tok2str(cfm_tlv_values, "Unknown", cfm_tlv_type), cfm_tlv_type)); if (cfm_tlv_type == CFM_TLV_END) { /* Length is "Not present if the Type field is 0." */ return; } /* do we have the full tlv header ? */ if (tlen < sizeof(struct cfm_tlv_header_t)) goto tooshort; ND_TCHECK2(*tptr, sizeof(struct cfm_tlv_header_t)); cfm_tlv_len=EXTRACT_16BITS(&cfm_tlv_header->length); ND_PRINT((ndo, ", length %u", cfm_tlv_len)); tptr += sizeof(struct cfm_tlv_header_t); tlen -= sizeof(struct cfm_tlv_header_t); tlv_ptr = tptr; /* do we have the full tlv ? */ if (tlen < cfm_tlv_len) goto tooshort; ND_TCHECK2(*tptr, cfm_tlv_len); hexdump = FALSE; switch(cfm_tlv_type) { case CFM_TLV_PORT_STATUS: if (cfm_tlv_len < 1) { ND_PRINT((ndo, " (too short, must be >= 1)")); return; } ND_PRINT((ndo, ", Status: %s (%u)", tok2str(cfm_tlv_port_status_values, "Unknown", *tptr), *tptr)); break; case CFM_TLV_INTERFACE_STATUS: if (cfm_tlv_len < 1) { ND_PRINT((ndo, " (too short, must be >= 1)")); return; } ND_PRINT((ndo, ", Status: %s (%u)", tok2str(cfm_tlv_interface_status_values, "Unknown", *tptr), *tptr)); break; case CFM_TLV_PRIVATE: if (cfm_tlv_len < 4) { ND_PRINT((ndo, " (too short, must be >= 4)")); return; } ND_PRINT((ndo, ", Vendor: %s (%u), Sub-Type %u", tok2str(oui_values,"Unknown", EXTRACT_24BITS(tptr)), EXTRACT_24BITS(tptr), *(tptr + 3))); hexdump = TRUE; break; case CFM_TLV_SENDER_ID: { u_int chassis_id_type, chassis_id_length; u_int mgmt_addr_length; if (cfm_tlv_len < 1) { ND_PRINT((ndo, " (too short, must be >= 1)")); goto next_tlv; } /* * Get the Chassis ID length and check it. * IEEE 802.1Q-2014 Section 21.5.3.1 */ chassis_id_length = *tptr; tptr++; tlen--; cfm_tlv_len--; if (chassis_id_length) { /* * IEEE 802.1Q-2014 Section 21.5.3.2: Chassis ID Subtype, references * IEEE 802.1AB-2005 Section 9.5.2.2, subsequently * IEEE 802.1AB-2016 Section 8.5.2.2: chassis ID subtype */ if (cfm_tlv_len < 1) { ND_PRINT((ndo, "\n\t (TLV too short)")); goto next_tlv; } chassis_id_type = *tptr; cfm_tlv_len--; ND_PRINT((ndo, "\n\t Chassis-ID Type %s (%u), Chassis-ID length %u", tok2str(cfm_tlv_senderid_chassisid_values, "Unknown", chassis_id_type), chassis_id_type, chassis_id_length)); if (cfm_tlv_len < chassis_id_length) { ND_PRINT((ndo, "\n\t (TLV too short)")); goto next_tlv; } /* IEEE 802.1Q-2014 Section 21.5.3.3: Chassis ID */ switch (chassis_id_type) { case CFM_CHASSIS_ID_MAC_ADDRESS: if (chassis_id_length != ETHER_ADDR_LEN) { ND_PRINT((ndo, " (invalid MAC address length)")); hexdump = TRUE; break; } ND_PRINT((ndo, "\n\t MAC %s", etheraddr_string(ndo, tptr + 1))); break; case CFM_CHASSIS_ID_NETWORK_ADDRESS: hexdump |= cfm_network_addr_print(ndo, tptr + 1, chassis_id_length); break; case CFM_CHASSIS_ID_INTERFACE_NAME: /* fall through */ case CFM_CHASSIS_ID_INTERFACE_ALIAS: case CFM_CHASSIS_ID_LOCAL: case CFM_CHASSIS_ID_CHASSIS_COMPONENT: case CFM_CHASSIS_ID_PORT_COMPONENT: safeputs(ndo, tptr + 1, chassis_id_length); break; default: hexdump = TRUE; break; } cfm_tlv_len -= chassis_id_length; tptr += 1 + chassis_id_length; tlen -= 1 + chassis_id_length; } /* * Check if there is a Management Address. * IEEE 802.1Q-2014 Section 21.5.3.4: Management Address Domain Length * This and all subsequent fields are not present if the TLV length * allows only the above fields. */ if (cfm_tlv_len == 0) { /* No, there isn't; we're done. */ break; } /* Here mgmt_addr_length stands for the management domain length. */ mgmt_addr_length = *tptr; tptr++; tlen--; cfm_tlv_len--; ND_PRINT((ndo, "\n\t Management Address Domain Length %u", mgmt_addr_length)); if (mgmt_addr_length) { /* IEEE 802.1Q-2014 Section 21.5.3.5: Management Address Domain */ if (cfm_tlv_len < mgmt_addr_length) { ND_PRINT((ndo, "\n\t (TLV too short)")); goto next_tlv; } cfm_tlv_len -= mgmt_addr_length; /* * XXX - this is an OID; print it as such. */ hex_print(ndo, "\n\t Management Address Domain: ", tptr, mgmt_addr_length); tptr += mgmt_addr_length; tlen -= mgmt_addr_length; /* * IEEE 802.1Q-2014 Section 21.5.3.6: Management Address Length * This field is present if Management Address Domain Length is not 0. */ if (cfm_tlv_len < 1) { ND_PRINT((ndo, " (Management Address Length is missing)")); hexdump = TRUE; break; } /* Here mgmt_addr_length stands for the management address length. */ mgmt_addr_length = *tptr; tptr++; tlen--; cfm_tlv_len--; ND_PRINT((ndo, "\n\t Management Address Length %u", mgmt_addr_length)); if (mgmt_addr_length) { /* IEEE 802.1Q-2014 Section 21.5.3.7: Management Address */ if (cfm_tlv_len < mgmt_addr_length) { ND_PRINT((ndo, "\n\t (TLV too short)")); return; } cfm_tlv_len -= mgmt_addr_length; /* * XXX - this is a TransportDomain; print it as such. */ hex_print(ndo, "\n\t Management Address: ", tptr, mgmt_addr_length); tptr += mgmt_addr_length; tlen -= mgmt_addr_length; } } break; } /* * FIXME those are the defined TLVs that lack a decoder * you are welcome to contribute code ;-) */ case CFM_TLV_DATA: case CFM_TLV_REPLY_INGRESS: case CFM_TLV_REPLY_EGRESS: default: hexdump = TRUE; break; } /* do we want to see an additional hexdump ? */ if (hexdump || ndo->ndo_vflag > 1) print_unknown_data(ndo, tlv_ptr, "\n\t ", cfm_tlv_len); next_tlv: tptr+=cfm_tlv_len; tlen-=cfm_tlv_len; } return; tooshort: ND_PRINT((ndo, "\n\t\t packet is too short")); return; trunc: ND_PRINT((ndo, "\n\t\t packet exceeded snapshot")); } tcpdump-4.9.3/print-syslog.c0000644000026300017510000000773313544412561014163 0ustar mcrmcr/* * Copyright (c) 1998-2004 Hannes Gredler * The TCPDUMP project * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code * distributions retain the above copyright notice and this paragraph * in its entirety, and (2) distributions including binary code include * the above copyright notice and this paragraph in its entirety in * the documentation or other materials provided with the distribution. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. */ /* \summary: Syslog protocol printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #include "extract.h" static const char tstr[] = "[|syslog]"; /* * tokenlists and #defines taken from Ethereal - Network traffic analyzer * by Gerald Combs */ #define SYSLOG_SEVERITY_MASK 0x0007 /* 0000 0000 0000 0111 */ #define SYSLOG_FACILITY_MASK 0x03f8 /* 0000 0011 1111 1000 */ #define SYSLOG_MAX_DIGITS 3 /* The maximum number if priority digits to read in. */ static const struct tok syslog_severity_values[] = { { 0, "emergency" }, { 1, "alert" }, { 2, "critical" }, { 3, "error" }, { 4, "warning" }, { 5, "notice" }, { 6, "info" }, { 7, "debug" }, { 0, NULL }, }; static const struct tok syslog_facility_values[] = { { 0, "kernel" }, { 1, "user" }, { 2, "mail" }, { 3, "daemon" }, { 4, "auth" }, { 5, "syslog" }, { 6, "lpr" }, { 7, "news" }, { 8, "uucp" }, { 9, "cron" }, { 10, "authpriv" }, { 11, "ftp" }, { 12, "ntp" }, { 13, "security" }, { 14, "console" }, { 15, "cron" }, { 16, "local0" }, { 17, "local1" }, { 18, "local2" }, { 19, "local3" }, { 20, "local4" }, { 21, "local5" }, { 22, "local6" }, { 23, "local7" }, { 0, NULL }, }; void syslog_print(netdissect_options *ndo, register const u_char *pptr, register u_int len) { uint16_t msg_off = 0; uint16_t pri = 0; uint16_t facility,severity; /* extract decimal figures that are * encapsulated within < > tags * based on this decimal figure extract the * severity and facility values */ ND_TCHECK2(*pptr, 1); if (*(pptr+msg_off) == '<') { msg_off++; ND_TCHECK2(*(pptr + msg_off), 1); while ( *(pptr+msg_off) >= '0' && *(pptr+msg_off) <= '9' && msg_off <= SYSLOG_MAX_DIGITS) { pri = pri * 10 + (*(pptr+msg_off) - '0'); msg_off++; ND_TCHECK2(*(pptr + msg_off), 1); } if (*(pptr+msg_off) != '>') { ND_PRINT((ndo, "%s", tstr)); return; } msg_off++; } else { ND_PRINT((ndo, "%s", tstr)); return; } facility = (pri & SYSLOG_FACILITY_MASK) >> 3; severity = pri & SYSLOG_SEVERITY_MASK; if (ndo->ndo_vflag < 1 ) { ND_PRINT((ndo, "SYSLOG %s.%s, length: %u", tok2str(syslog_facility_values, "unknown (%u)", facility), tok2str(syslog_severity_values, "unknown (%u)", severity), len)); return; } ND_PRINT((ndo, "SYSLOG, length: %u\n\tFacility %s (%u), Severity %s (%u)\n\tMsg: ", len, tok2str(syslog_facility_values, "unknown (%u)", facility), facility, tok2str(syslog_severity_values, "unknown (%u)", severity), severity)); /* print the syslog text in verbose mode */ for (; msg_off < len; msg_off++) { ND_TCHECK2(*(pptr + msg_off), 1); safeputchar(ndo, *(pptr + msg_off)); } if (ndo->ndo_vflag > 1) print_unknown_data(ndo, pptr, "\n\t", len); return; trunc: ND_PRINT((ndo, "%s", tstr)); } tcpdump-4.9.3/print-sip.c0000644000026300017510000000245213544412561013427 0ustar mcrmcr/* * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code * distributions retain the above copyright notice and this paragraph * in its entirety, and (2) distributions including binary code include * the above copyright notice and this paragraph in its entirety in * the documentation or other materials provided with the distribution. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. * * Original code by Hannes Gredler (hannes@gredler.at) * Turned into common "text protocol" code, which this uses, by * Guy Harris. */ /* \summary: Session Initiation Protocol (SIP) printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #include "extract.h" static const char *sipcmds[] = { "ACK", "BYE", "CANCEL", "DO", "INFO", "INVITE", "MESSAGE", "NOTIFY", "OPTIONS", "PRACK", "QAUTH", "REFER", "REGISTER", "SPRACK", "SUBSCRIBE", "UPDATE", "PUBLISH", NULL }; void sip_print(netdissect_options *ndo, const u_char *pptr, u_int len) { txtproto_print(ndo, pptr, len, "sip", sipcmds, RESP_CODE_SECOND_TOKEN); } tcpdump-4.9.3/l2vpn.c0000644000026300017510000000656413544412561012553 0ustar mcrmcr/* * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code * distributions retain the above copyright notice and this paragraph * in its entirety, and (2) distributions including binary code include * the above copyright notice and this paragraph in its entirety in * the documentation or other materials provided with the distribution. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. * * Original code by Hannes Gredler (hannes@gredler.at) */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #include "l2vpn.h" /* * BGP Layer 2 Encapsulation Types * * RFC 6624 * * http://www.iana.org/assignments/bgp-parameters/bgp-parameters.xhtml#bgp-l2-encapsulation-types-registry */ const struct tok l2vpn_encaps_values[] = { { 0, "Reserved"}, { 1, "Frame Relay"}, { 2, "ATM AAL5 SDU VCC transport"}, { 3, "ATM transparent cell transport"}, { 4, "Ethernet (VLAN) Tagged Mode"}, { 5, "Ethernet Raw Mode"}, { 6, "Cisco HDLC"}, { 7, "PPP"}, { 8, "SONET/SDH Circuit Emulation Service over MPLS"}, { 9, "ATM n-to-one VCC cell transport"}, { 10, "ATM n-to-one VPC cell transport"}, { 11, "IP layer 2 transport"}, { 15, "Frame Relay Port mode"}, { 17, "Structure-agnostic E1 over packet"}, { 18, "Structure-agnostic T1 (DS1) over packet"}, { 19, "VPLS"}, { 20, "Structure-agnostic T3 (DS3) over packet"}, { 21, "Nx64kbit/s Basic Service using Structure-aware"}, { 25, "Frame Relay DLCI"}, { 40, "Structure-agnostic E3 over packet"}, { 41, "Octet-aligned playload for Structure-agnostic DS1 circuits"}, { 42, "E1 Nx64kbit/s with CAS using Structure-aware"}, { 43, "DS1 (ESF) Nx64kbit/s with CAS using Structure-aware"}, { 44, "DS1 (SF) Nx64kbit/s with CAS using Structure-aware"}, { 0, NULL} }; /* * MPLS Pseudowire Types * * RFC 4446 * * http://www.iana.org/assignments/pwe3-parameters/pwe3-parameters.xhtml#pwe3-parameters-2 */ const struct tok mpls_pw_types_values[] = { { 0x0000, "Reserved"}, { 0x0001, "Frame Relay DLCI (Martini Mode)"}, { 0x0002, "ATM AAL5 SDU VCC transport"}, { 0x0003, "ATM transparent cell transport"}, { 0x0004, "Ethernet VLAN"}, { 0x0005, "Ethernet"}, { 0x0006, "Cisco-HDLC"}, { 0x0007, "PPP"}, { 0x0008, "SONET/SDH Circuit Emulation Service over MPLS"}, { 0x0009, "ATM n-to-one VCC cell transport"}, { 0x000a, "ATM n-to-one VPC cell transport"}, { 0x000b, "IP Layer2 Transport"}, { 0x000c, "ATM one-to-one VCC Cell Mode"}, { 0x000d, "ATM one-to-one VPC Cell Mode"}, { 0x000e, "ATM AAL5 PDU VCC transport"}, { 0x000f, "Frame-Relay Port mode"}, { 0x0010, "SONET/SDH Circuit Emulation over Packet"}, { 0x0011, "Structure-agnostic E1 over Packet"}, { 0x0012, "Structure-agnostic T1 (DS1) over Packet"}, { 0x0013, "Structure-agnostic E3 over Packet"}, { 0x0014, "Structure-agnostic T3 (DS3) over Packet"}, { 0x0015, "CESoPSN basic mode"}, { 0x0016, "TDMoIP basic mode"}, { 0x0017, "CESoPSN TDM with CAS"}, { 0x0018, "TDMoIP TDM with CAS"}, { 0x0019, "Frame Relay DLCI"}, { 0x0040, "IP-interworking"}, { 0, NULL} }; tcpdump-4.9.3/print-udld.c0000644000026300017510000001274213544412561013567 0ustar mcrmcr/* * Copyright (c) 1998-2007 The TCPDUMP project * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code * distributions retain the above copyright notice and this paragraph * in its entirety, and (2) distributions including binary code include * the above copyright notice and this paragraph in its entirety in * the documentation or other materials provided with the distribution. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. * * Original code by Carles Kishimoto */ /* \summary: Cisco UniDirectional Link Detection (UDLD) protocol printer */ /* specification: RFC 5171 */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "netdissect.h" #include "extract.h" static const char tstr[] = " [|udld]"; #define UDLD_HEADER_LEN 4 #define UDLD_DEVICE_ID_TLV 0x0001 #define UDLD_PORT_ID_TLV 0x0002 #define UDLD_ECHO_TLV 0x0003 #define UDLD_MESSAGE_INTERVAL_TLV 0x0004 #define UDLD_TIMEOUT_INTERVAL_TLV 0x0005 #define UDLD_DEVICE_NAME_TLV 0x0006 #define UDLD_SEQ_NUMBER_TLV 0x0007 static const struct tok udld_tlv_values[] = { { UDLD_DEVICE_ID_TLV, "Device-ID TLV"}, { UDLD_PORT_ID_TLV, "Port-ID TLV"}, { UDLD_ECHO_TLV, "Echo TLV"}, { UDLD_MESSAGE_INTERVAL_TLV, "Message Interval TLV"}, { UDLD_TIMEOUT_INTERVAL_TLV, "Timeout Interval TLV"}, { UDLD_DEVICE_NAME_TLV, "Device Name TLV"}, { UDLD_SEQ_NUMBER_TLV,"Sequence Number TLV"}, { 0, NULL} }; static const struct tok udld_code_values[] = { { 0x00, "Reserved"}, { 0x01, "Probe message"}, { 0x02, "Echo message"}, { 0x03, "Flush message"}, { 0, NULL} }; static const struct tok udld_flags_values[] = { { 0x00, "RT"}, { 0x01, "RSY"}, { 0, NULL} }; /* * UDLD's Protocol Data Unit format: * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Ver | Opcode | Flags | Checksum | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | List of TLVs (variable length list) | * | ... | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * * TLV format: * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | TYPE | LENGTH | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | VALUE | * | ... | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * * LENGTH: Length in bytes of the Type, Length, and Value fields. */ #define UDLD_EXTRACT_VERSION(x) (((x)&0xe0)>>5) #define UDLD_EXTRACT_OPCODE(x) ((x)&0x1f) void udld_print (netdissect_options *ndo, const u_char *pptr, u_int length) { int code, type, len; const u_char *tptr; if (length < UDLD_HEADER_LEN) goto trunc; tptr = pptr; ND_TCHECK2(*tptr, UDLD_HEADER_LEN); code = UDLD_EXTRACT_OPCODE(*tptr); ND_PRINT((ndo, "UDLDv%u, Code %s (%x), Flags [%s] (0x%02x), length %u", UDLD_EXTRACT_VERSION(*tptr), tok2str(udld_code_values, "Reserved", code), code, bittok2str(udld_flags_values, "none", *(tptr+1)), *(tptr+1), length)); /* * In non-verbose mode, just print version and opcode type */ if (ndo->ndo_vflag < 1) { return; } ND_PRINT((ndo, "\n\tChecksum 0x%04x (unverified)", EXTRACT_16BITS(tptr+2))); tptr += UDLD_HEADER_LEN; while (tptr < (pptr+length)) { ND_TCHECK2(*tptr, 4); type = EXTRACT_16BITS(tptr); len = EXTRACT_16BITS(tptr+2); ND_PRINT((ndo, "\n\t%s (0x%04x) TLV, length %u", tok2str(udld_tlv_values, "Unknown", type), type, len)); if (type == 0) goto invalid; /* infinite loop check */ if (len <= 4) goto invalid; len -= 4; tptr += 4; ND_TCHECK2(*tptr, len); switch (type) { case UDLD_DEVICE_ID_TLV: case UDLD_PORT_ID_TLV: case UDLD_DEVICE_NAME_TLV: ND_PRINT((ndo, ", ")); fn_printzp(ndo, tptr, len, NULL); break; case UDLD_ECHO_TLV: ND_PRINT((ndo, ", ")); (void)fn_printn(ndo, tptr, len, NULL); break; case UDLD_MESSAGE_INTERVAL_TLV: case UDLD_TIMEOUT_INTERVAL_TLV: if (len != 1) goto invalid; ND_PRINT((ndo, ", %us", (*tptr))); break; case UDLD_SEQ_NUMBER_TLV: if (len != 4) goto invalid; ND_PRINT((ndo, ", %u", EXTRACT_32BITS(tptr))); break; default: break; } tptr += len; } return; invalid: ND_PRINT((ndo, "%s", istr)); return; trunc: ND_PRINT((ndo, "%s", tstr)); } /* * Local Variables: * c-style: whitesmith * c-basic-offset: 4 * End: */ tcpdump-4.9.3/README.md0000644000026300017510000002204513544412561012615 0ustar mcrmcr# tcpdump [![Build Status](https://travis-ci.org/the-tcpdump-group/tcpdump.png)](https://travis-ci.org/the-tcpdump-group/tcpdump) To report a security issue please send an e-mail to security@tcpdump.org. To report bugs and other problems, contribute patches, request a feature, provide generic feedback etc please see the file CONTRIBUTING in the tcpdump source tree root. TCPDUMP 4.x.y Now maintained by "The Tcpdump Group" See www.tcpdump.org Anonymous Git is available via: git clone git://bpf.tcpdump.org/tcpdump formerly from Lawrence Berkeley National Laboratory Network Research Group ftp://ftp.ee.lbl.gov/old/tcpdump.tar.Z (3.4) This directory contains source code for tcpdump, a tool for network monitoring and data acquisition. This software was originally developed by the Network Research Group at the Lawrence Berkeley National Laboratory. The original distribution is available via anonymous ftp to `ftp.ee.lbl.gov`, in `tcpdump.tar.Z`. More recent development is performed at tcpdump.org, http://www.tcpdump.org/ Tcpdump uses libpcap, a system-independent interface for user-level packet capture. Before building tcpdump, you must first retrieve and build libpcap, also originally from LBL and now being maintained by tcpdump.org; see http://www.tcpdump.org/ . Once libpcap is built (either install it or make sure it's in `../libpcap`), you can build tcpdump using the procedure in the `INSTALL.txt` file. The program is loosely based on SMI's "etherfind" although none of the etherfind code remains. It was originally written by Van Jacobson as part of an ongoing research project to investigate and improve tcp and internet gateway performance. The parts of the program originally taken from Sun's etherfind were later re-written by Steven McCanne of LBL. To insure that there would be no vestige of proprietary code in tcpdump, Steve wrote these pieces from the specification given by the manual entry, with no access to the source of tcpdump or etherfind. Over the past few years, tcpdump has been steadily improved by the excellent contributions from the Internet community (just browse through the `CHANGES` file). We are grateful for all the input. Richard Stevens gives an excellent treatment of the Internet protocols in his book *"TCP/IP Illustrated, Volume 1"*. If you want to learn more about tcpdump and how to interpret its output, pick up this book. Some tools for viewing and analyzing tcpdump trace files are available from the Internet Traffic Archive: * http://www.sigcomm.org/ITA/ Another tool that tcpdump users might find useful is tcpslice: * https://github.com/the-tcpdump-group/tcpslice It is a program that can be used to extract portions of tcpdump binary trace files. See the above distribution for further details and documentation. Current versions can be found at www.tcpdump.org. - The TCPdump team original text by: Steve McCanne, Craig Leres, Van Jacobson ------------------------------------- ``` This directory also contains some short awk programs intended as examples of ways to reduce tcpdump data when you're tracking particular network problems: send-ack.awk Simplifies the tcpdump trace for an ftp (or other unidirectional tcp transfer). Since we assume that one host only sends and the other only acks, all address information is left off and we just note if the packet is a "send" or an "ack". There is one output line per line of the original trace. Field 1 is the packet time in decimal seconds, relative to the start of the conversation. Field 2 is delta-time from last packet. Field 3 is packet type/direction. "Send" means data going from sender to receiver, "ack" means an ack going from the receiver to the sender. A preceding "*" indicates that the data is a retransmission. A preceding "-" indicates a hole in the sequence space (i.e., missing packet(s)), a "#" means an odd-size (not max seg size) packet. Field 4 has the packet flags (same format as raw trace). Field 5 is the sequence number (start seq. num for sender, next expected seq number for acks). The number in parens following an ack is the delta-time from the first send of the packet to the ack. A number in parens following a send is the delta-time from the first send of the packet to the current send (on duplicate packets only). Duplicate sends or acks have a number in square brackets showing the number of duplicates so far. Here is a short sample from near the start of an ftp: 3.00 0.20 send . 512 3.20 0.20 ack . 1024 (0.20) 3.20 0.00 send P 1024 3.40 0.20 ack . 1536 (0.20) 3.80 0.40 * send . 0 (3.80) [2] 3.82 0.02 * ack . 1536 (0.62) [2] Three seconds into the conversation, bytes 512 through 1023 were sent. 200ms later they were acked. Shortly thereafter bytes 1024-1535 were sent and again acked after 200ms. Then, for no apparent reason, 0-511 is retransmitted, 3.8 seconds after its initial send (the round trip time for this ftp was 1sec, +-500ms). Since the receiver is expecting 1536, 1536 is re-acked when 0 arrives. packetdat.awk Computes chunk summary data for an ftp (or similar unidirectional tcp transfer). [A "chunk" refers to a chunk of the sequence space -- essentially the packet sequence number divided by the max segment size.] A summary line is printed showing the number of chunks, the number of packets it took to send that many chunks (if there are no lost or duplicated packets, the number of packets should equal the number of chunks) and the number of acks. Following the summary line is one line of information per chunk. The line contains eight fields: 1 - the chunk number 2 - the start sequence number for this chunk 3 - time of first send 4 - time of last send 5 - time of first ack 6 - time of last ack 7 - number of times chunk was sent 8 - number of times chunk was acked (all times are in decimal seconds, relative to the start of the conversation.) As an example, here is the first part of the output for an ftp trace: # 134 chunks. 536 packets sent. 508 acks. 1 1 0.00 5.80 0.20 0.20 4 1 2 513 0.28 6.20 0.40 0.40 4 1 3 1025 1.16 6.32 1.20 1.20 4 1 4 1561 1.86 15.00 2.00 2.00 6 1 5 2049 2.16 15.44 2.20 2.20 5 1 6 2585 2.64 16.44 2.80 2.80 5 1 7 3073 3.00 16.66 3.20 3.20 4 1 8 3609 3.20 17.24 3.40 5.82 4 11 9 4097 6.02 6.58 6.20 6.80 2 5 This says that 134 chunks were transferred (about 70K since the average packet size was 512 bytes). It took 536 packets to transfer the data (i.e., on the average each chunk was transmitted four times). Looking at, say, chunk 4, we see it represents the 512 bytes of sequence space from 1561 to 2048. It was first sent 1.86 seconds into the conversation. It was last sent 15 seconds into the conversation and was sent a total of 6 times (i.e., it was retransmitted every 2 seconds on the average). It was acked once, 140ms after it first arrived. stime.awk atime.awk Output one line per send or ack, respectively, in the form