Changeset 83e0a25


Ignore:
Timestamp:
10/06/04 14:16:40 (16 years ago)
Author:
Daniel Lawson <dlawson@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
cd6034c
Parents:
10814d7
Message:

poink

Location:
lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lib/libtrace.h

    r10814d7 r83e0a25  
    385385                struct libtrace_packet_t *packet);
    386386
     387
     388typedef enum {USE_DEST, USE_SOURCE} serverport_t;
     389
     390/** hint at the server port in specified protocol
     391 * @param protocol      the IP layer protocol, eg 6 (tcp), 17 (udp)
     392 * @param source        the source port from the packet
     393 * @param dest          the destination port from the packet
     394 * @returns one of USE_SOURCE or USE_DEST depending on which one you should use
     395 * @author Daniel Lawson
     396 */
     397int8_t trace_get_server_port(uint8_t protocol, uint16_t source, uint16_t dest);
     398
    387399#ifdef __cplusplus
    388400} // extern "C"
  • lib/trace.c

    r36f563c r83e0a25  
    11961196}
    11971197
     1198typedef enum {USE_DEST, USE_SOURCE} serverport_t;
     1199
     1200/** Attempt to deduce the 'server' port
     1201 * @param protocol the IP protocol (eg, 6 or 17 for TCP or UDP)
     1202 * @param source the TCP or UDP source port
     1203 * @param dest the TCP or UDP destination port
     1204 * @returns a hint as to which port is the server port
     1205 * @author Daniel Lawson
     1206 */
     1207#define ROOT_SERVER(x) (x < 512)
     1208#define ROOT_CLIENT(x) (512 <= x < 1024)
     1209#define NONROOT_SERVER(x) (x >= 5000)
     1210#define NONROOT_CLIENT(x) (1024 <= x < 5000)
     1211#define DYNAMIC(x) (49152 < x < 65535)
     1212#define SERVER(x) ROOT_SERVER(x) || NONROOT_SERVER(x)
     1213#define CLIENT(x) ROOT_CLIENT(x) || NONROOT_CLIENT(x) || DYNAMIC(x)
     1214
     1215int8_t trace_get_server_port(uint8_t protocol, uint16_t source, uint16_t dest) {
     1216        /*
     1217         * * If the ports are equal, return DEST
     1218         * * Check for well-known ports in the given protocol
     1219         * * Root server ports: 0 - 511
     1220         * * Root client ports: 512 - 1023
     1221         * * non-root client ports: 1024 - 4999
     1222         * * non-root server ports: 5000+
     1223         * * Check for static ranges: 1024 - 49151
     1224         * * Check for dynamic ranges: 49152 - 65535
     1225         * * flip a coin.
     1226         */
     1227
     1228        int8_t server, client;
     1229
     1230        if (SERVER(source) && CLIENT(dest)) {
     1231                return USE_SOURCE;
     1232        } else if (SERVER(dest) && CLIENT(SOURCE)) {
     1233                return USE_DEST;
     1234        } else if (ROOT_SERVER(source) && !ROOT_SERVER(dest)) {
     1235                return USE_SOURCE;
     1236        } else if (ROOT_SERVER(dest) && !ROOT_SERVER(source)) {
     1237                return USE_DEST;
     1238        }
     1239       
     1240        // failing that test...
     1241        if (source < dest) {
     1242                return USE_SOURCE;
     1243        }
     1244        return USE_DEST;
     1245       
     1246}
Note: See TracChangeset for help on using the changeset viewer.