Example #1
0
/*
 *  Pack the record 'rwrec' into an array of bytes 'ar'
 */
static int
ipv6ioRecordPack_V2(
    skstream_t             *rwIOS,
    const rwGenericRec_V5  *rwrec,
    uint8_t                *ar)
{
    uint32_t ip;
    int rv;

    /* Start time, TCP Flags, Protocol, TCP State */
    rv = rwpackPackTimesFlagsProto(rwrec, ar, rwIOS->hdr_starttime);
    if (rv) {
        return rv;
    }

    /* application */
    rwRecMemGetApplication(rwrec, &ar[6]);

    /* sPort, dPort */
    rwRecMemGetSPort(rwrec, &ar[ 8]);
    rwRecMemGetDPort(rwrec, &ar[10]);

    /* Elapsed */
    rwRecMemGetElapsed(rwrec, &ar[12]);

    /* packets, bytes */
    rwRecMemGetPkts(rwrec,  &ar[16]);
    rwRecMemGetBytes(rwrec, &ar[20]);

    /* sIP, dIP */
    if (rwRecIsIPv6(rwrec)) {
        /* Record is IPv6 */
#if !SK_ENABLE_IPV6
        return SKSTREAM_ERR_UNSUPPORT_IPV6;
#else
        ar[ 5] |= 0x80;
        rwRecMemGetSIPv6(rwrec, &ar[24]);
        rwRecMemGetDIPv6(rwrec, &ar[40]);
#endif /* SK_ENABLE_IPV6 */
    } else {
        /* Record is IPv4, but encode as IPv6 */
        ip = htonl(rwRecGetSIPv4(rwrec));
        memcpy(&ar[24], IP4in6_prefix, sizeof(IP4in6_prefix));
        memcpy(&ar[24+12], &ip, sizeof(ip));

        ip = htonl(rwRecGetDIPv4(rwrec));
        memcpy(&ar[40], IP4in6_prefix, sizeof(IP4in6_prefix));
        memcpy(&ar[40+12], &ip, sizeof(ip));
    }

    /* swap if required */
    if (rwIOS->swapFlag) {
        ipv6ioRecordSwap_V2(ar);
    }

    return SKSTREAM_OK;
}
Example #2
0
/*
 *  Pack the record 'rwrec' into an array of bytes 'ar'
 */
static int
ipv6ioRecordPack_V1(
    skstream_t             *rwIOS,
    const rwGenericRec_V5  *rwrec,
    uint8_t                *ar)
{
    uint32_t ip;

    rwRecMemGetStartTime(rwrec, &ar[0]);
    rwRecMemGetElapsed(rwrec, &ar[8]);
    rwRecMemGetSPort(rwrec, &ar[12]);
    rwRecMemGetDPort(rwrec, &ar[14]);
    rwRecMemGetProto(rwrec, &ar[16]);
    rwRecMemGetFlowType(rwrec, &ar[17]);
    rwRecMemGetSensor(rwrec, &ar[18]);
    rwRecMemGetFlags(rwrec, &ar[20]);
    rwRecMemGetInitFlags(rwrec, &ar[21]);
    rwRecMemGetRestFlags(rwrec, &ar[22]);
    rwRecMemGetTcpState(rwrec, &ar[23]);
    rwRecMemGetApplication(rwrec, &ar[24]);
    rwRecMemGetMemo(rwrec, &ar[26]);
    rwRecMemGetPkts(rwrec, &ar[28]);
    rwRecMemGetBytes(rwrec, &ar[32]);

    if (rwRecIsIPv6(rwrec)) {
        /* Record is IPv6 */
#if !SK_ENABLE_IPV6
        return SKSTREAM_ERR_UNSUPPORT_IPV6;
#else
        ar[23] |= 0x80;
        rwRecMemGetSIPv6(rwrec, &ar[36]);
        rwRecMemGetDIPv6(rwrec, &ar[52]);
#endif /* SK_ENABLE_IPV6 */
    } else {
        /* Record is IPv4, but encode as IPv6 */

        /* sIP */
        ip = htonl(rwRecGetSIPv4(rwrec));
        memcpy(&ar[36], IP4in6_prefix, sizeof(IP4in6_prefix));
        memcpy(&ar[48], &ip, sizeof(ip));

        /* dIP */
        ip = htonl(rwRecGetDIPv4(rwrec));
        memcpy(&ar[52], IP4in6_prefix, sizeof(IP4in6_prefix));
        memcpy(&ar[64], &ip, sizeof(ip));
    }

    /* swap if required */
    if (rwIOS->swapFlag) {
        ipv6ioRecordSwap_V1(ar);
    }

    return SKSTREAM_OK;
}
Example #3
0
/*
 *  Pack the record 'rwrec' into an array of bytes 'ar'
 */
static int
ipv6routingioRecordPack_V3(
    skstream_t         *stream,
    const rwRec        *rwrec,
    uint8_t            *ar)
{
    uint32_t u32;
    uint64_t u64;

    rwRecMemGetStartTime(rwrec, &ar[0]);
    rwRecMemGetElapsed(rwrec, &ar[8]);
    rwRecMemGetSPort(rwrec, &ar[12]);
    rwRecMemGetDPort(rwrec, &ar[14]);
    rwRecMemGetProto(rwrec, &ar[16]);
    rwRecMemGetFlowType(rwrec, &ar[17]);
    rwRecMemGetSensor(rwrec, &ar[18]);
    rwRecMemGetFlags(rwrec, &ar[20]);
    rwRecMemGetInitFlags(rwrec, &ar[21]);
    rwRecMemGetRestFlags(rwrec, &ar[22]);
    rwRecMemGetTcpState(rwrec, &ar[23]);
    rwRecMemGetApplication(rwrec, &ar[24]);
    rwRecMemGetMemo(rwrec, &ar[26]);

    u32 = rwRecGetInput(rwrec);
    memcpy(&ar[28], &u32, sizeof(u32));

    u64 = rwRecGetPkts(rwrec);
    memcpy(&ar[32], &u64, sizeof(u64));

    u64 = rwRecGetBytes(rwrec);
    memcpy(&ar[40], &u64, sizeof(u64));

    u32 = rwRecGetOutput(rwrec);
    memcpy(&ar[96], &u32, sizeof(u32));

    if (rwRecIsIPv6(rwrec)) {
        /* Record is IPv6 */
#if !SK_ENABLE_IPV6
        return SKSTREAM_ERR_UNSUPPORT_IPV6;
#else
        ar[23] |= 0x80;
        rwRecMemGetSIPv6(rwrec, &ar[48]);
        rwRecMemGetDIPv6(rwrec, &ar[64]);
        rwRecMemGetNhIPv6(rwrec, &ar[80]);
#endif  /* SK_ENABLE_IPV6 */
    } else {
        /* Record is IPv4, but encode as IPv6 */
        uint32_t ip;

        /* sIP */
        ip = htonl(rwRecGetSIPv4(rwrec));
        memcpy(&ar[48], IP4in6_prefix, sizeof(IP4in6_prefix));
        memcpy(&ar[60], &ip, sizeof(ip));

        /* dIP */
        ip = htonl(rwRecGetDIPv4(rwrec));
        memcpy(&ar[64], IP4in6_prefix, sizeof(IP4in6_prefix));
        memcpy(&ar[76], &ip, sizeof(ip));

        /* nhIP */
        ip = htonl(rwRecGetNhIPv4(rwrec));
        memcpy(&ar[80], IP4in6_prefix, sizeof(IP4in6_prefix));
        memcpy(&ar[92], &ip, sizeof(ip));
    }

    /* swap if required */
    if (stream->swapFlag) {
        ipv6routingioRecordSwap_V3(ar);
    }

    return SKSTREAM_OK;
}