]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Harmonize TCP source or destination ports tests with UDP ones
authorFrancois-Xavier Le Bail <[email protected]>
Mon, 14 Dec 2015 19:28:14 +0000 (20:28 +0100)
committerFrancois-Xavier Le Bail <[email protected]>
Mon, 14 Dec 2015 19:28:14 +0000 (20:28 +0100)
netdissect.h
print-tcp.c
print-udp.c

index b2f824d3ea37acceeabeb7db5846e3f877f24b9a..c2f9bd0add82c180a5021a3b43792c8f5d4c5fdf 100644 (file)
@@ -223,6 +223,9 @@ struct netdissect_options {
 #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.
index 98dc07d1b1f6efa325174b2000a85238d5515b9e..cbee3d8d93242230028046e73babeb8237ffc749 100644 (file)
@@ -645,53 +645,50 @@ tcp_print(netdissect_options *ndo,
                 return;
         }
 
-        if (sport == TELNET_PORT || dport == TELNET_PORT) {
+        if (IS_SRC_OR_DST_PORT(TELNET_PORT)) {
                 telnet_print(ndo, bp, length);
-        } else if (sport == SMTP_PORT || dport == SMTP_PORT) {
+        } else if (IS_SRC_OR_DST_PORT(SMTP_PORT)) {
                 ND_PRINT((ndo, ": "));
                 smtp_print(ndo, bp, length);
-        } else if (sport == BGP_PORT || dport == BGP_PORT)
+        } else if (IS_SRC_OR_DST_PORT(BGP_PORT))
                 bgp_print(ndo, bp, length);
-        else if (sport == PPTP_PORT || dport == PPTP_PORT)
+        else if (IS_SRC_OR_DST_PORT(PPTP_PORT))
                 pptp_print(ndo, bp);
 #ifdef ENABLE_SMB
-        else if (sport == NETBIOS_SSN_PORT || dport == NETBIOS_SSN_PORT)
+        else if (IS_SRC_OR_DST_PORT(NETBIOS_SSN_PORT))
                 nbt_tcp_print(ndo, bp, length);
-       else if (sport == SMB_PORT || dport == SMB_PORT)
+       else if (IS_SRC_OR_DST_PORT(SMB_PORT))
                smb_tcp_print(ndo, bp, length);
 #endif
-        else if (sport == BEEP_PORT || dport == BEEP_PORT)
+        else if (IS_SRC_OR_DST_PORT(BEEP_PORT))
                 beep_print(ndo, bp, length);
-        else if (sport == OPENFLOW_PORT_OLD || dport == OPENFLOW_PORT_OLD ||
-                 sport == OPENFLOW_PORT_IANA || dport == OPENFLOW_PORT_IANA)
+        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 (sport == FTP_PORT || dport == FTP_PORT) {
+        else if (IS_SRC_OR_DST_PORT(FTP_PORT)) {
                 ND_PRINT((ndo, ": "));
                 ftp_print(ndo, bp, length);
-        } else if (sport == HTTP_PORT || dport == HTTP_PORT ||
-            sport == HTTP_PORT_ALT || dport == HTTP_PORT_ALT) {
+        } 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 (sport == RTSP_PORT || dport == RTSP_PORT ||
-            sport == RTSP_PORT_ALT || dport == RTSP_PORT_ALT) {
+        } 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 &&
-                 (sport == NAMESERVER_PORT || dport == NAMESERVER_PORT)) {
+                 (IS_SRC_OR_DST_PORT(NAMESERVER_PORT))) {
                 /*
                  * 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 (sport == MSDP_PORT || dport == MSDP_PORT) {
+        } else if (IS_SRC_OR_DST_PORT(MSDP_PORT)) {
                 msdp_print(ndo, bp, length);
-        } else if (sport == RPKI_RTR_PORT || dport == RPKI_RTR_PORT) {
+        } else if (IS_SRC_OR_DST_PORT(RPKI_RTR_PORT)) {
                 rpki_rtr_print(ndo, bp, length);
         }
-        else if (length > 0 && (sport == LDP_PORT || dport == LDP_PORT)) {
+        else if (length > 0 && (IS_SRC_OR_DST_PORT(LDP_PORT))) {
                 ldp_print(ndo, bp, length);
         }
-        else if ((sport == NFS_PORT || dport == NFS_PORT) &&
+        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,
index 2b63318a41954a08afff19ebedcc3cc7628a88c7..313a332c2d21b4fd8bfe7c45773f339ab8f6d799 100644 (file)
@@ -545,47 +545,46 @@ udp_print(netdissect_options *ndo, register const u_char *bp, u_int length,
        }
 
        if (!ndo->ndo_qflag) {
-#define ISPORT(p) (dport == (p) || sport == (p))
-               if (ISPORT(NAMESERVER_PORT))
+               if (IS_SRC_OR_DST_PORT(NAMESERVER_PORT))
                        ns_print(ndo, (const u_char *)(up + 1), length, 0);
-               else if (ISPORT(MULTICASTDNS_PORT))
+               else if (IS_SRC_OR_DST_PORT(MULTICASTDNS_PORT))
                        ns_print(ndo, (const u_char *)(up + 1), length, 1);
-               else if (ISPORT(TIMED_PORT))
+               else if (IS_SRC_OR_DST_PORT(TIMED_PORT))
                        timed_print(ndo, (const u_char *)(up + 1));
-               else if (ISPORT(TFTP_PORT))
+               else if (IS_SRC_OR_DST_PORT(TFTP_PORT))
                        tftp_print(ndo, (const u_char *)(up + 1), length);
-               else if (ISPORT(BOOTPC_PORT) || ISPORT(BOOTPS_PORT))
+               else if (IS_SRC_OR_DST_PORT(BOOTPC_PORT) || IS_SRC_OR_DST_PORT(BOOTPS_PORT))
                        bootp_print(ndo, (const u_char *)(up + 1), length);
-               else if (ISPORT(RIP_PORT))
+               else if (IS_SRC_OR_DST_PORT(RIP_PORT))
                        rip_print(ndo, (const u_char *)(up + 1), length);
-               else if (ISPORT(AODV_PORT))
+               else if (IS_SRC_OR_DST_PORT(AODV_PORT))
                        aodv_print(ndo, (const u_char *)(up + 1), length,
                            ip6 != NULL);
-               else if (ISPORT(ISAKMP_PORT))
+               else if (IS_SRC_OR_DST_PORT(ISAKMP_PORT))
                         isakmp_print(ndo, (const u_char *)(up + 1), length, bp2);
-               else if (ISPORT(ISAKMP_PORT_NATT))
+               else if (IS_SRC_OR_DST_PORT(ISAKMP_PORT_NATT))
                         isakmp_rfc3948_print(ndo, (const u_char *)(up + 1), length, bp2);
 #if 1 /*???*/
-               else if (ISPORT(ISAKMP_PORT_USER1) || ISPORT(ISAKMP_PORT_USER2))
+               else if (IS_SRC_OR_DST_PORT(ISAKMP_PORT_USER1) || IS_SRC_OR_DST_PORT(ISAKMP_PORT_USER2))
                        isakmp_print(ndo, (const u_char *)(up + 1), length, bp2);
 #endif
-               else if (ISPORT(SNMP_PORT) || ISPORT(SNMPTRAP_PORT))
+               else if (IS_SRC_OR_DST_PORT(SNMP_PORT) || IS_SRC_OR_DST_PORT(SNMPTRAP_PORT))
                        snmp_print(ndo, (const u_char *)(up + 1), length);
-               else if (ISPORT(NTP_PORT))
+               else if (IS_SRC_OR_DST_PORT(NTP_PORT))
                        ntp_print(ndo, (const u_char *)(up + 1), length);
-               else if (ISPORT(KERBEROS_PORT) || ISPORT(KERBEROS_SEC_PORT))
+               else if (IS_SRC_OR_DST_PORT(KERBEROS_PORT) || IS_SRC_OR_DST_PORT(KERBEROS_SEC_PORT))
                        krb_print(ndo, (const void *)(up + 1));
-               else if (ISPORT(L2TP_PORT))
+               else if (IS_SRC_OR_DST_PORT(L2TP_PORT))
                        l2tp_print(ndo, (const u_char *)(up + 1), length);
 #ifdef ENABLE_SMB
-               else if (ISPORT(NETBIOS_NS_PORT))
+               else if (IS_SRC_OR_DST_PORT(NETBIOS_NS_PORT))
                        nbt_udp137_print(ndo, (const u_char *)(up + 1), length);
-               else if (ISPORT(NETBIOS_DGRAM_PORT))
+               else if (IS_SRC_OR_DST_PORT(NETBIOS_DGRAM_PORT))
                        nbt_udp138_print(ndo, (const u_char *)(up + 1), length);
 #endif
                else if (dport == VAT_PORT)
                        vat_print(ndo, (const void *)(up + 1), up);
-               else if (ISPORT(ZEPHYR_SRV_PORT) || ISPORT(ZEPHYR_CLT_PORT))
+               else if (IS_SRC_OR_DST_PORT(ZEPHYR_SRV_PORT) || IS_SRC_OR_DST_PORT(ZEPHYR_CLT_PORT))
                        zephyr_print(ndo, (const void *)(up + 1), length);
                /*
                 * Since there are 10 possible ports to check, I think
@@ -595,64 +594,64 @@ udp_print(netdissect_options *ndo, register const u_char *bp, u_int length,
                         (dport >= RX_PORT_LOW && dport <= RX_PORT_HIGH))
                        rx_print(ndo, (const void *)(up + 1), length, sport, dport,
                                 (const u_char *) ip);
-               else if (ISPORT(RIPNG_PORT))
+               else if (IS_SRC_OR_DST_PORT(RIPNG_PORT))
                        ripng_print(ndo, (const u_char *)(up + 1), length);
-               else if (ISPORT(DHCP6_SERV_PORT) || ISPORT(DHCP6_CLI_PORT))
+               else if (IS_SRC_OR_DST_PORT(DHCP6_SERV_PORT) || IS_SRC_OR_DST_PORT(DHCP6_CLI_PORT))
                        dhcp6_print(ndo, (const u_char *)(up + 1), length);
-               else if (ISPORT(AHCP_PORT))
+               else if (IS_SRC_OR_DST_PORT(AHCP_PORT))
                        ahcp_print(ndo, (const u_char *)(up + 1), length);
-               else if (ISPORT(BABEL_PORT) || ISPORT(BABEL_PORT_OLD))
+               else if (IS_SRC_OR_DST_PORT(BABEL_PORT) || IS_SRC_OR_DST_PORT(BABEL_PORT_OLD))
                        babel_print(ndo, (const u_char *)(up + 1), length);
                /*
                 * Kludge in test for whiteboard packets.
                 */
                else if (dport == WB_PORT)
                        wb_print(ndo, (const void *)(up + 1), length);
-               else if (ISPORT(CISCO_AUTORP_PORT))
+               else if (IS_SRC_OR_DST_PORT(CISCO_AUTORP_PORT))
                        cisco_autorp_print(ndo, (const void *)(up + 1), length);
-               else if (ISPORT(RADIUS_PORT) ||
-                        ISPORT(RADIUS_NEW_PORT) ||
-                        ISPORT(RADIUS_ACCOUNTING_PORT) ||
-                        ISPORT(RADIUS_NEW_ACCOUNTING_PORT) ||
-                        ISPORT(RADIUS_COA_PORT) )
+               else if (IS_SRC_OR_DST_PORT(RADIUS_PORT) ||
+                        IS_SRC_OR_DST_PORT(RADIUS_NEW_PORT) ||
+                        IS_SRC_OR_DST_PORT(RADIUS_ACCOUNTING_PORT) ||
+                        IS_SRC_OR_DST_PORT(RADIUS_NEW_ACCOUNTING_PORT) ||
+                        IS_SRC_OR_DST_PORT(RADIUS_COA_PORT) )
                        radius_print(ndo, (const u_char *)(up+1), length);
                else if (dport == HSRP_PORT)
                        hsrp_print(ndo, (const u_char *)(up + 1), length);
-               else if (ISPORT(LWRES_PORT))
+               else if (IS_SRC_OR_DST_PORT(LWRES_PORT))
                        lwres_print(ndo, (const u_char *)(up + 1), length);
-               else if (ISPORT(LDP_PORT))
+               else if (IS_SRC_OR_DST_PORT(LDP_PORT))
                        ldp_print(ndo, (const u_char *)(up + 1), length);
-               else if (ISPORT(OLSR_PORT))
+               else if (IS_SRC_OR_DST_PORT(OLSR_PORT))
                        olsr_print(ndo, (const u_char *)(up + 1), length,
                                        (IP_V(ip) == 6) ? 1 : 0);
-               else if (ISPORT(MPLS_LSP_PING_PORT))
+               else if (IS_SRC_OR_DST_PORT(MPLS_LSP_PING_PORT))
                        lspping_print(ndo, (const u_char *)(up + 1), length);
                else if (dport == BFD_CONTROL_PORT ||
                         dport == BFD_ECHO_PORT )
                        bfd_print(ndo, (const u_char *)(up+1), length, dport);
-                else if (ISPORT(LMP_PORT))
+                else if (IS_SRC_OR_DST_PORT(LMP_PORT))
                        lmp_print(ndo, (const u_char *)(up + 1), length);
-               else if (ISPORT(VQP_PORT))
+               else if (IS_SRC_OR_DST_PORT(VQP_PORT))
                        vqp_print(ndo, (const u_char *)(up + 1), length);
-                else if (ISPORT(SFLOW_PORT))
+                else if (IS_SRC_OR_DST_PORT(SFLOW_PORT))
                         sflow_print(ndo, (const u_char *)(up + 1), length);
                else if (dport == LWAPP_CONTROL_PORT)
                        lwapp_control_print(ndo, (const u_char *)(up + 1), length, 1);
                 else if (sport == LWAPP_CONTROL_PORT)
                         lwapp_control_print(ndo, (const u_char *)(up + 1), length, 0);
-                else if (ISPORT(LWAPP_DATA_PORT))
+                else if (IS_SRC_OR_DST_PORT(LWAPP_DATA_PORT))
                         lwapp_data_print(ndo, (const u_char *)(up + 1), length);
-                else if (ISPORT(SIP_PORT))
+                else if (IS_SRC_OR_DST_PORT(SIP_PORT))
                        sip_print(ndo, (const u_char *)(up + 1), length);
-                else if (ISPORT(SYSLOG_PORT))
+                else if (IS_SRC_OR_DST_PORT(SYSLOG_PORT))
                        syslog_print(ndo, (const u_char *)(up + 1), length);
-                else if (ISPORT(OTV_PORT))
+                else if (IS_SRC_OR_DST_PORT(OTV_PORT))
                        otv_print(ndo, (const u_char *)(up + 1), length);
-                else if (ISPORT(VXLAN_PORT))
+                else if (IS_SRC_OR_DST_PORT(VXLAN_PORT))
                        vxlan_print(ndo, (const u_char *)(up + 1), length);
-                else if (ISPORT(GENEVE_PORT))
+                else if (IS_SRC_OR_DST_PORT(GENEVE_PORT))
                        geneve_print(ndo, (const u_char *)(up + 1), length);
-               else if (ISPORT(LISP_CONTROL_PORT))
+               else if (IS_SRC_OR_DST_PORT(LISP_CONTROL_PORT))
                        lisp_print(ndo, (const u_char *)(up + 1), length);
                else {
                        if (ulen > length)
@@ -661,7 +660,6 @@ udp_print(netdissect_options *ndo, register const u_char *bp, u_int length,
                        else
                                ND_PRINT((ndo, "UDP, length %u", ulen));
                }
-#undef ISPORT
        } else {
                if (ulen > length)
                        ND_PRINT((ndo, "UDP, bad length %u > %u",