Esempio n. 1
0
int handle_udps_in(struct fio_nic *from, struct fio_nic *nic0, struct fio_nic *nic1, 
        struct fio_rxdata *rxdata, int avail, void *useless)
{
    (void)useless;
    struct fio_txdata *txdata;
    int txcount, i;
    uint16_t sport, recvport;

    for (i = 0; i < avail; i++, rxdata++)
    {
        txcount = fio_nic_reserve_tx(from, &txdata, rxdata);
        if (nm_unlikely(txcount != 1))
        {
            OD("tid %d reserve realtime tx error", NIC_EXTRA_CONTEXT(from)->me);
        }
        sport = ntohs(rxdata->sport);
		//if (sport == 9998)
		//	assert(0);
        recvport = ntohs(rxdata->dport);
        char str_sip[16];
        char str_dip[16];
        OD("tid %d: dsize %d sip %s sport %d dip %s recvport %d", 
                NIC_EXTRA_CONTEXT(from)->me, rxdata->size, 
		inet_ntop(AF_INET, (struct in_addr*)&rxdata->sip, str_sip, 16), 
		sport,
		inet_ntop(AF_INET, (struct in_addr*)&rxdata->dip, str_dip, 16), 
		recvport); 

        txdata->dstip = sysconfig.dst_ip[0].start.s_addr;
        txdata->dstport = htons(sysconfig.dst_port);
        txdata->srcip = 0;
        txdata->srcport = htons(sysconfig.src_port);
        fio_send(from, htons(fio_set_txmsg(from, txdata)), txdata, 0);
        //fio_nic_sendmsg_direct(from, sysconfig.dst_ip.start.s_addr, txdata);
        
        txcount = fio_nic_reserve_tx(from, &txdata, NULL);
        if (nm_unlikely(txcount != 1))
        {
            OD("tid %d reserve normal tx error", NIC_EXTRA_CONTEXT(from)->me);
        }
        else
        {
            txdata->dstip = sysconfig.dst_ip[0].start.s_addr;
            txdata->dstport = htons(sysconfig.dst_port - 1);
            txdata->srcip = 0;
            txdata->srcport = htons(sysconfig.src_port);
            fio_send(from, htons(fio_set_txmsg(from, txdata)), txdata, 0);
        }
    }

    return 0;
}
Esempio n. 2
0
inline int32_t fio_icmp_handle_req(struct fio_nic *nic, struct fio_rxdata *rxd, void *param)
{
    NOD("");
    //fprintf(stderr, "fio_icmp_handle_req\n");
    struct fio_txdata *m;
    struct icmp_packet *ppkt_rx = (struct icmp_packet*)rxd->pbuf;
    if ((uint8_t)ICMP_ECHOREPLY == ppkt_rx->icmp.icmp_type
            || !fio_nic_is_myip(nic, rxd->dip))
    {
        fio_stack_deliver(nic, rxd);
        goto suc;
    }

    uint32_t sip = 0, nip, get_ret = 0;
    int dev_idx;
    if (0 != fio_route_find(nic, ntohl(rxd->sip), &sip, &dev_idx, &nip))
        goto err;

    if (dev_idx != nic->type_id)
    {
        fio_stack_deliver(nic, rxd);
        goto suc;
    }
    if (fio_nic_reserve_tx(nic, &m, rxd) < 1)
        goto err;
    get_ret = fio_mac_get_bynip(nic, nip, &m->dmac, ntohl(rxd->dip));
    struct icmp_packet *ppkt_tx = (struct icmp_packet*)m->pbuf;
    struct ether_header *eh = &ppkt_tx->eh;
    if (fio_icmp_gen_resp(nic, ppkt_rx, ppkt_tx, rxd, m->type))
    {
        OD( "tid %d generate icmp reply packet error", NIC_EXTRA_CONTEXT(nic)->me);
        goto err;
    }
    m->size = rxd->size;
    if (0 == get_ret)
    {
        prmac((uint8_t*)m->dmac);
        bcopy(m->dmac, eh->ether_dhost, ETH_ALEN);
        fio_nic_commit(nic, m, 1);
    }
    else
    {
        OD( "tid %d generate icmp reply no dst mac", NIC_EXTRA_CONTEXT(nic)->me);
        memset(eh->ether_dhost, 0, ETH_ALEN);
        fio_mac_cache_pkt(nic, nip, m);
    }

suc:
    return 0;
err:
    return -1;
}
Esempio n. 3
0
int handle_dns_resp(struct fio_nic *from, struct fio_nic *nic0, struct fio_nic *nic1,
        struct fio_rxdata *rxdata, int avail, void *useless)
{
    (void)useless;
    int j, i;
    char str_sip[16];
    char str_dip[16];
    char str_x[1500] = {0};
    char str_byte[10];
    OD("tid %d pkt count %d avail", NIC_EXTRA_CONTEXT(from)->me, avail);
    //for (j = 0; j < avail; j++, rxdata++)
    //{
    //    str_x[0] = 0;
    //    inet_ntop(AF_INET, &rxdata->sip, str_sip, 16);
    //    inet_ntop(AF_INET, &rxdata->dip, str_dip, 16);
    //    D("tid %d pkt len %d sip %s, sport %d, dip %s, dport %d", 
    //            NIC_EXTRA_CONTEXT(from)->me, rxdata->size, 
    //            str_sip, ntohs(rxdata->sport),
    //            str_dip, ntohs(rxdata->dport));

    //    for (i = 0; i < rxdata->size; i++)
    //    {
    //        snprintf(str_byte, 10, "%02X ", (uint8_t)rxdata->pbuf[i]);
    //        if (i%8 == 0)
    //            strncat(str_x, "\n", 1500);
    //        strncat(str_x, str_byte, 1500);
    //    }
    //    D("%s", str_x);

    //}
    return 0;
}
Esempio n. 4
0
int32_t fio_icmp_gen_resp(struct fio_nic *nic, struct icmp_packet *icmp_from, struct icmp_packet *icmp_to, struct fio_rxdata *rxd, int realtime)
{
    if (TXDATA_TYPE_REALTIME != realtime)
        memcpy(icmp_to, icmp_from, rxd->size); 

    memcpy(&icmp_to->eh.ether_dhost, &rxd->smac, ETH_ALEN);
    memcpy(&icmp_to->eh.ether_shost, &nic->if_mac, ETH_ALEN);

    struct ip *ip = &icmp_to->ip;
    ip->ip_len = ntohs(rxd->size - sizeof(struct ether_header));
    ip->ip_dst.s_addr = rxd->sip;
    ip->ip_src.s_addr = rxd->dip;
    ip->ip_sum = 0;
    ip->ip_sum = ip_fast_csum((char*)ip, ip->ip_hl);

    struct icmp *icmp = &icmp_to->icmp;
    OD( "icmp_type = %x", icmp->icmp_type);
    icmp->icmp_type = ICMP_ECHOREPLY;//0
    uint8_t *ptr = (uint8_t*)&icmp->icmp_cksum;
    if (*ptr > (0xff-0x08))
	    (*(ptr+1))++;
    *ptr += 0x08;
    
    //snprintf((char*)icmp_to->padding, 100, "%s", nic->alise);
    return 0;
}
Esempio n. 5
0
static struct IPMAC * get_ipmac(FILE *fp)
{
	char line_buf[1024] = {0};
	char key[64] = {0};
	char *p = NULL;
	char value[1024] = {0};
	int complete = 0;

	struct IPMAC *ptr = (struct IPMAC*)malloc(sizeof(struct IPMAC));
	if (!ptr)
	{
        OD("error, alloc ipmac error out of memory!");
		exit(0);
	}

	while(1)
    {
        if (fgets(line_buf, sizeof(line_buf), fp) == NULL)
            break;
        p = line_buf;
        while(isspace(*p))
            p++;
        if (*p == '\0' || *p == '#')
            continue;

        GetArg(key, sizeof(key), &p);

        if (!strcasecmp(key, "ip"))
            get_str(ptr->ip, value, sizeof(value), p);
        else if (!strcasecmp(key, "mac"))
            get_str(ptr->mac, value, sizeof(value), p);
        else if (!strcasecmp(key, "via"))
            get_str(ptr->via, value, sizeof(value), p);
        else if (!strcasecmp(key, "</ip_mac>"))
        {
            //在这里转换ip,mac
            inet_aton(ptr->ip, &ptr->_ip);
            bcopy(ether_aton(ptr->mac), &ptr->_mac, ETH_ALEN);
            complete = 1;
            break;
        }
    }

    if (!complete)
    {
        free(ptr);
        ptr = NULL;
    }
    return ptr; 
}
Esempio n. 6
0
void translate_proto(char **names, int len, int dowhat)
{
	int i, j, k;
	for (i = 0, j = 0; i < 256 && i < len; i++)
	{
        if (-1 != (k=proto_str2int(names[i])))
        {
            switch (dowhat)
            {
                case 1:
                    sysconfig.interested_protos[j++] = k;
                    break;
                case 2:
                    sysconfig.def_protos[j++] = k;
                    break;
            }
        }
        else
            OD("<WARN> proto %s unknown", names[i]);
	}
}
Esempio n. 7
0
int handle_udps(struct fio_nic *from, struct fio_nic *nic0, struct fio_nic *nic1, 
        struct fio_rxdata *rxdata, int avail, void *useless)
{
    (void)useless;
    struct fio_txdata *txdata;
    int txcount, i;
    //uint32_t sip;
    //uint16_t sport, recvport;

    struct fio_nic *to = nic0;
    if (NIC_EXTRA_TYPEID(from) == NIC_EXTRA_TYPEID(nic0))
        to = nic1;

    for (i = 0; i < avail; i++, rxdata++)
    {
        txcount = fio_nic_reserve_tx(to, &txdata, rxdata);
        if (nm_unlikely(txcount != 1))
        {
            OD("tid %d reserve realtime tx error", NIC_EXTRA_CONTEXT(to)->me);
        }
        //sport = ntohs(rxdata->sport);
		//if (sport == 9998)
		//	assert(0);
        //recvport = ntohs(rxdata->dport);
        //char str_sip[16];
        NOD("tid %d: dsize %d sip %s sport %d recvport %d", 
                NIC_EXTRA_CONTEXT(to)->me, rxdata->size, inet_ntop(AF_INET,
                    (struct in_addr*)&rxdata->sip, str_sip, 16), sport, recvport); 

        txdata->dstip = sysconfig.dst_ip[0].start.s_addr;
        txdata->dstport = htons(sysconfig.dst_port);
        txdata->srcip = 0;
        txdata->srcport = htons(sysconfig.src_port);
        fio_send(to, htons(fio_set_txmsg(to, txdata)), txdata, 0);
        //fio_nic_sendmsg_direct(to, sysconfig.dst_ip.start.s_addr, txdata);
    }

    return 0;
}
Esempio n. 8
0
int handle_udps_2cards(struct fio_nic *from, struct fio_nic *nic0, struct fio_nic *nic1, 
        struct fio_rxdata *rxdata, int avail, void *useless)
{
    (void)useless;
    struct fio_txdata *txdata;
    int txcount, i;
    //uint32_t sip;
    //uint16_t sport, recvport;

    uint32_t dstip = 0;

    if (NIC_EXTRA_CONTEXT(from)->nics[0].fd == from->fd)
       dstip = sysconfig.dst_ip[0].start.s_addr;
    else
       dstip = sysconfig.dst_ip[1].start.s_addr;

    for (i = 0; i < avail; i++, rxdata++)
    {
        txcount = fio_nic_reserve_tx(from, &txdata, rxdata);
        if (nm_unlikely(txcount != 1))
        {
            OD("tid %d reserve realtime tx error", NIC_EXTRA_CONTEXT(from)->me);
        }
        //sport = ntohs(rxdata->sport);
        //recvport = ntohs(rxdata->dport);
        //char str_sip[16];
        NOD("tid %d: dsize %d sip %s sport %d recvport %d", 
                NIC_EXTRA_CONTEXT(from)->me, rxdata->size, inet_ntop(AF_INET,
                    (struct in_addr*)&rxdata->sip, str_sip, 16), sport, recvport); 

        txdata->dstip = dstip;
        txdata->dstport = htons(sysconfig.dst_port);
        txdata->srcip = 0;
        txdata->srcport = htons(sysconfig.src_port);
        fio_send(from, htons(fio_set_txmsg(from, txdata)), txdata, 0);
    }

    return 0;
}
Esempio n. 9
0
int handle_audp(struct fio_nic *from, struct fio_nic *to, struct fio_rxdata *rxdata, 
        uint32_t sip, uint16_t sport, uint16_t recvport, void *useless)
{
    struct fio_txdata *txdata;
    int txcount;
    sport = ntohs(sport);
    recvport = ntohs(recvport);
    //char str_sip[16];
    NOD("tid %d: dsize %d sip %s sport %d recvport %d", 
            NIC_EXTRA_CONTEXT(from)->me, rxdata->size, inet_ntop(AF_INET,
                (struct in_addr*)&sip, str_sip, 16), sport, recvport); 

    txcount = fio_nic_reserve_tx(to, &txdata, rxdata);
    if (txcount == 1)
    {
        fio_nic_sendmsg_direct(to, sysconfig.dst_ip[0].start.s_addr, txdata);
        fio_stack_send_up(to, txdata->pbuf, txdata->size);
    }
    else
    {
        OD("tid %d reserve realtime tx error", NIC_EXTRA_CONTEXT(from)->me);
        exit(1);
    }

    //txcount = fio_reserve_tx(t, 1, &txdata, NULL, 1);
    //if (txcount == 1)
    //{
    //    fio_sendmsg(t, sysconfig.dst_ip.start.s_addr, htons(sysconfig.dst_port), 
    //            htons(sysconfig.src_port), htons(fio_set_txmsg(t, txdata)), txdata);
    //}
    //else
    //{
    //    D("tid %d reserve tx error", t->me);
    //    exit(1);
    //}

    return 0;
}
Esempio n. 10
0
File: VM.cpp Progetto: preda/pepper
// extern __thread jmp_buf jumpBuf;
int VM::call(Value A, int nEffArgs, Value *regs, Stack *stack) {
    Vector<RetInfo> retInfo; // only used if FAST_CALL

    if (!(IS_O_TYPE(A, O_FUNC) || IS_CF(A) || IS_O_TYPE(A, O_CFUNC))) { return -1; }
    regs  = stack->maybeGrow(regs, 256);
    int nExpectedArgs = IS_O_TYPE(A, O_FUNC) ? ((Func *)GET_OBJ(A))->proto->nArgs : NARGS_CFUNC;
    nEffArgs = prepareStackForCall(regs, nExpectedArgs, nEffArgs, gc);

    if (IS_CF(A) || IS_O_TYPE(A, O_CFUNC)) {
        if (IS_CF(A)) {
            tfunc f = GET_CF(A);
            *regs = f(this, CFunc::CFUNC_CALL, 0, regs, nEffArgs);
        } else {
            ((CFunc *) GET_OBJ(A))->call(this, regs, nEffArgs);
        }
        return 0;
    }

    unsigned code = 0;
    Value B;
    Value *ptrC;
    Func *activeFunc = (Func *) GET_OBJ(A);
    unsigned *pc = (unsigned *) activeFunc->proto->code.buf();

    static void *dispatch[] = {
#define _(name) &&name
#include "opcodes.inc"
#undef _
    };

    assert(sizeof(dispatch)/sizeof(dispatch[0]) == N_OPCODES);

    copyUpvals(activeFunc, regs);

    STEP;

 JMP:  pc += OD(code);    STEP;
 JT:   if (!IS_FALSE(*ptrC)) { pc += OD(code);  } STEP;
 JF:   if ( IS_FALSE(*ptrC)) { pc += OD(code);  } STEP;
 JLT:  if (lessThan(A, B))   { pc += OSC(code); } STEP;
 JNIS: if (A != B)           { pc += OSC(code); } STEP;

 FOR: 
    A = *(ptrC + 1);
    B = *(ptrC + 2);
    if (!IS_NUM(A) || !IS_NUM(B)) { goto error; } // E_FOR_NOT_NUMBER
    *ptrC = B;
    if (!(GET_NUM(B) < GET_NUM(A))) { pc += OD(code); }
    STEP;

 LOOP: {
        const double counter = GET_NUM(*ptrC) + 1;
        if (counter < GET_NUM(*(ptrC+1))) { pc += OD(code); }
        *ptrC = VAL_NUM(counter);
        STEP;
    }

 FUNC:
    assert(IS_PROTO(A));
    *ptrC = VAL_OBJ(Func::alloc(gc, PROTO(A), regs + 256, regs, OB(code)));
    STEP;

    // index, A[B]
 GETI: *ptrC = types->type(A)->indexGet(A, B); if (*ptrC == VERR) { goto error; } STEP;
 GETF: *ptrC = types->type(A)->fieldGet(A, B); if (*ptrC == VERR) { goto error; } STEP;
    
 SETI: if (!types->type(*ptrC)->indexSet(*ptrC, A, B)) { goto error; } STEP;
 SETF: if (!types->type(*ptrC)->fieldSet(*ptrC, A, B)) { goto error; } STEP;
    /*
      const int oa = OA(code);
      const int ob = OB(code);
      int top = max(oa, ob) + 1;
      top = max(top, activeFunc->proto->localsTop);
      Value *base = regs + top;
      printf("top %d\n", top);
      base[0] = A;
      base[1] = B;
      int cPos = ptrC - regs;
      DO_CALL(v, 2, regs, base, stack);
      regs[cPos] = base[0];
      break;
      if (*ptrC == VERR) { goto error; }
    */
        
 GETS: *ptrC = getSlice(gc, A, B, regs[OB(code)+1]); if (*ptrC==VERR) { goto error; } STEP;
 SETS: if (setSlice(*ptrC, A, regs[OA(code)+1], B)) { goto error; } STEP;

 RET: {
        regs[0] = A;
        Value *root = stack->base;
        gc->maybeCollect(root, regs - root + 1);
#if FAST_CALL
        if (!retInfo.size()) {
            return 0;
        }
        RetInfo *ri = retInfo.top();
        pc         = ri->pc;
        regs       = stack->base + ri->base;
        activeFunc = ri->func;
        retInfo.pop();
        copyUpvals(activeFunc, regs);
        STEP;
#else
        return 0;
#endif
    }

CALL: { 
        if (!IS_OBJ(A) && !IS_CF(A)) { goto error; } // E_CALL_NOT_FUNC
        int nEffArgs = OSB(code);
        assert(nEffArgs != 0);
        Value *base = ptrC;
#if FAST_CALL
        if (IS_O_TYPE(A, O_FUNC)) {
            Func *f = (Func *) GET_OBJ(A);
            Proto *proto = f->proto;
            prepareStackForCall(base, proto->nArgs, nEffArgs, gc);
            RetInfo *ret = retInfo.push();
            ret->pc    = pc;
            ret->base  = regs - stack->base;
            ret->func  = activeFunc;
            regs = stack->maybeGrow(base, 256);
            copyUpvals(f, regs);
            pc   = proto->code.buf();
            activeFunc = f;
        } else {
#endif
            int ret = DO_CALL(A, nEffArgs, regs, base, stack);
            if (ret) { goto error; }
#if FAST_CALL
        }
#endif
        STEP;
    }
    
 MOVEUP: {
        const int slot = regs + 256 - ptrC;
        activeFunc->setUp(slot, A);
    }
    
 MOVE_R: *ptrC = A; STEP;
 MOVE_I: *ptrC = VAL_NUM(OD(code)); STEP;
 MOVE_V: {
        int id = OA(code);
        *ptrC =
            id == CONST_NIL          ? VNIL :
            id == CONST_EMPTY_STRING ? EMPTY_STRING :
            id == CONST_EMPTY_ARRAY  ? VAL_OBJ(emptyArray->copy(gc)) :
            VAL_OBJ(emptyMap->copy(gc));
        STEP;
    }
    
 MOVE_C: {
        Value v = *pc | (((u64) *(pc+1)) << 32);
        pc += 2;
        if (IS_ARRAY(v)) {
            v = VAL_OBJ(ARRAY(v)->copy(gc));
        } else if (IS_MAP(v)) {
            v = VAL_OBJ(MAP(v)->copy(gc));
        }
        *ptrC = v;
        STEP;
    }
 LEN:    *ptrC = VAL_NUM(len(A)); STEP;
 NOTL:   *ptrC = IS_FALSE(A) ? TRUE : FALSE; STEP;
    // notb: *ptrC = IS_INT(A)? VAL_INT(~getInteger(A)):ERROR(E_WRONG_TYPE); STEP;

 ADD: *ptrC = doAdd(gc, A, B); if (*ptrC == VERR) { goto error; } STEP;
 SUB: *ptrC = BINOP(-, A, B); STEP;
 MUL: *ptrC = BINOP(*, A, B); STEP;
 DIV: *ptrC = BINOP(/, A, B); STEP;
 MOD: *ptrC = doMod(A, B); if (*ptrC == VERR) { goto error; } STEP;
 POW: *ptrC = doPow(A, B); if (*ptrC == VERR) { goto error; } STEP;

 AND: *ptrC = BITOP(&,  A, B); STEP;
 OR:  *ptrC = BITOP(|,  A, B); STEP;
 XOR: *ptrC = BITOP(^,  A, B); STEP;

 SHL_RR: ERR(!IS_NUM(B), E_WRONG_TYPE); *ptrC = doSHL(A, (int)GET_NUM(B)); STEP;
 SHR_RR: ERR(!IS_NUM(B), E_WRONG_TYPE); *ptrC = doSHR(A, (int)GET_NUM(B)); STEP;
 SHL_RI: *ptrC = doSHL(A, OSB(code));       STEP;
 SHR_RI: *ptrC = doSHR(A, OSB(code));       STEP;

 EQ:  *ptrC = equals(A, B)  ? TRUE : FALSE; STEP;
 NEQ: *ptrC = !equals(A, B) ? TRUE : FALSE; STEP;
 IS:  *ptrC = A == B ? TRUE : FALSE; STEP;
 NIS: *ptrC = A != B ? TRUE : FALSE; STEP;

 LT:  *ptrC = lessThan(A, B) ? TRUE : FALSE; STEP;
 LE:  *ptrC = (equals(A, B) || lessThan(A, B)) ? TRUE : FALSE; STEP;

 error: return pc - (unsigned *) activeFunc->proto->code.buf();
}
Esempio n. 11
0
#define CKM_INVALID_MECHANISM 0xffffffffUL

/* XXX this is incorrect */
#define INVALID_CERT_EXTENSION 1

#define CKM_ECDSA                      0x00001041
#define CKM_ECDSA_SHA1                 0x00001042
#define CKM_ECDH1_DERIVE               0x00001050

static SECOidData ANSI_prime_oids[] = {
    { { siDEROID, NULL, 0 }, ECCurve_noName,
        "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },

    OD( ansiX962prime192v1, ECCurve_NIST_P192,
        "ANSI X9.62 elliptic curve prime192v1 (aka secp192r1, NIST P-192)",
        CKM_INVALID_MECHANISM,
        INVALID_CERT_EXTENSION ),
    OD( ansiX962prime192v2, ECCurve_X9_62_PRIME_192V2,
        "ANSI X9.62 elliptic curve prime192v2",
        CKM_INVALID_MECHANISM,
        INVALID_CERT_EXTENSION ),
    OD( ansiX962prime192v3, ECCurve_X9_62_PRIME_192V3,
        "ANSI X9.62 elliptic curve prime192v3",
        CKM_INVALID_MECHANISM,
        INVALID_CERT_EXTENSION ),
    OD( ansiX962prime239v1, ECCurve_X9_62_PRIME_239V1,
        "ANSI X9.62 elliptic curve prime239v1",
        CKM_INVALID_MECHANISM,
        INVALID_CERT_EXTENSION ),
    OD( ansiX962prime239v2, ECCurve_X9_62_PRIME_239V2,
        "ANSI X9.62 elliptic curve prime239v2",
Esempio n. 12
0
static void * fio_dns_send(struct fio_context *context)
{
    //uint16_t sport_rang = 5000;
    uint32_t sip_rang[2];
    struct fio_nic *nics[2];
    struct pollfd fds[2+1];
    uint32_t dirs[2];
    int all_move, limit;
    int m, num_ready, i, j, num_nic = context->num_nic;
    struct netmap_if *nifp;
    struct netmap_ring *txring;
    struct fio_nic *tn;
    struct fio_poll_data pd;
    //uint32_t dst_ips[] = {(ntohl((uint32_t)(sysconfig.dst_ip[0].start.s_addr)) & 0xFFFFFF00), 
    //    (ntohl((uint32_t)(sysconfig.dst_ip[1].start.s_addr)) & 0xFFFFFF00)};
    //uint32_t dst_ips[] = {(ntohl((uint32_t)(sysconfig.src_ip.start.s_addr)) & 0xFFFFFF00), 
    //    (ntohl((uint32_t)(sysconfig.src_ip.start.s_addr)) & 0xFFFFFF00)};
    char donames[][255] = {
        "www.likunxiang.com", 
        "www.likunxiang.com", 
        "www.likunxiang.com", 
        "www.likunxiang.com", 
        "www.likunxiang.com", 
        "www.likunxiang.com", 
        "www.likunxiang.com", 
        "www.likunxiang.com", 
        "www.likunxiang.com", 
        "www.likunxiang.com", 
        "www.likunxiang.com", 
        "www.likunxiang.com", 
        "www.likunxiang.com", 
        "www.likunxiang.com", 
        "www.likunxiang.com", 
        "www.likunxiang.com", 
        "www.likunxiang.com", 
        "www.likunxiang.com", 
        "www.likunxiang.com", 
        "www.likunxiang.com", 
        "www.likunxiang.com", 
        "www.likunxiang.com", 
        "www.likunxiang.com", 
        "www.likunxiang.com" 
    };
    int donames_len[] = {
        strlen("www.likunxiang.com"), 
        strlen("www.likunxiang.com"), 
        strlen("www.likunxiang.com"), 
        strlen("www.likunxiang.com"), 
        strlen("www.likunxiang.com"), 
        strlen("www.likunxiang.com"), 
        strlen("www.likunxiang.com"), 
        strlen("www.likunxiang.com"), 
        strlen("www.likunxiang.com"), 
        strlen("www.likunxiang.com"), 
        strlen("www.likunxiang.com"), 
        strlen("www.likunxiang.com"), 
        strlen("www.likunxiang.com"), 
        strlen("www.likunxiang.com"), 
        strlen("www.likunxiang.com"), 
        strlen("www.likunxiang.com"), 
        strlen("www.likunxiang.com"), 
        strlen("www.likunxiang.com"), 
        strlen("www.likunxiang.com"), 
        strlen("www.likunxiang.com"), 
        strlen("www.likunxiang.com"), 
        strlen("www.likunxiang.com"), 
        strlen("www.likunxiang.com"), 
        strlen("www.likunxiang.com")
    };
    struct fio_txdata txds[2][24];
    char buf_if_necessary[2*24][MAX_PKT_SIZE];
    struct pktudp *pkt4test[] = {&g_pkt4test, &g_pkt4test2};

    for (j = 0; j < num_nic; j++)
    {
        sip_rang[j] = 126;
        for (i = 0; i < 24; i++)
        {
            struct fio_txdata *txd = &txds[j][i];
            memset(txd, 0, sizeof(struct fio_txdata));
            txd->type = TXDATA_TYPE_NORMAL;
            //txd->pbuf = txd->buf;
            txd->pbuf = buf_if_necessary[j*24+i];
            txd->pdata = txd->pbuf+g_payload_offset;
            memcpy(txd->pbuf, (char*)pkt4test[j], sysconfig.pkt_size);
            int paylen = dns_pack_head(txd->pdata, donames[i], donames_len[i]);
            txd->size = g_payload_offset+paylen;
            *(uint16_t*)(txd->pbuf+38) = htons(paylen+8);
            *(uint16_t*)(txd->pbuf+16) = htons(paylen+8+20);

            struct pktudp *ppkt = (struct pktudp*)txd->pbuf;
            //*(uint32_t*)(txd->pbuf+g_sip_offset) = htonl(dst_ips[j]|sip_rang[j]++);
            *(uint32_t*)(txd->pbuf+g_sip_offset) = sysconfig.src_ip.start.s_addr;
            bcopy(&sysconfig.src_mac.start, txd->pbuf+g_eth_smac, 6);

            struct ip *ip = &ppkt->ip;                                                 
            ip->ip_sum = 0;
            ip->ip_sum = ip_fast_csum((char*)ip, ip->ip_hl);
        }
    }

    for (i = 0; i < num_nic; i++)
    {
        nics[i] = &context->nics[i];
        dirs[i] = FIO_DIR_TX;
        sip_rang[i] = 0;
    }


    OD( "tid %d Wait %d secs for phy reset", context->me, 5);
    sleep(5);
    OD( "tid %d Ready... num_nic %d", context->me, num_nic);
    gettimeofday(&context->tic, NULL);

    pd.nics = nics;
    pd.fds = fds;
    pd.dirs = dirs;
    pd.num_nic = num_nic;
    pd.notifyfds = context->notifyfds;
    pd.num_notify = 0;
#ifdef _BREAKh_
    int breakh = 0;
#endif
    while (sysconfig.working) 
    {
        if ( (num_ready=context->vtbl.polls(&pd, 500)) < 0) 
        {
            gettimeofday(&context->toc, NULL);
            context->toc.tv_sec -= 1; /* Subtract timeout time. */
            OD( "<error> poll error!!!!!");
            continue;
        }
#ifdef _BREAKh_
        if (breakh)
            break;
#endif

        if (num_ready == 0)
        {
            continue;
        }

        for (i = 0; i < num_nic; i++)
        {
            tn = nics[i];
            fio_nic_send_arpbuf(tn);
            fio_nic_send_txbuf(tn);
            if (tn->nictxavl < 1)
                continue;

            all_move = 0;
            m = 0;
            nifp = tn->nifp;
            limit = tn->nictxavl;

#ifdef _SND_LIMIT_
            //D("limit %d", limit);
            limit = sysconfig.snd_pkts_per_sec;
#endif

            while(limit > 0)
            {
                txring = NETMAP_TXRING(nifp, tn->cur_tx_head);
                if (txring->avail == 0)
                {
                    tn->cur_tx_head = (tn->cur_tx_head+1 == tn->qtxlast ? 
                            tn->qtxfirst : tn->cur_tx_head+1);
                    if (++sip_rang[i] >= 24)
                        sip_rang[i] = 0;
                }
                else
                {
                    m = fio_fill_dns_pkt(txring, &txds[i][sip_rang[i]], limit);
                    all_move += m;
                    limit -= m;
                }
            }
            if (nm_likely(all_move > 0))
            {
                tn->txcount += all_move;
                tn->nictxavl -= all_move;
            }
        }
#ifdef _BREAKh_
        //breakh = 1;
#endif

#ifdef _SND_LIMIT_
        sleep(2);
#endif
    }

    /* reset the ``used`` flag. */
    context->used = 0;
    OD( "I'll shutdown");

    return NULL;
}
Esempio n. 13
0
void * fio_dns_recv(struct fio_context *context)
{
    struct fio_context *s_ct = &g_contexts[0];
    struct fio_nic *nics[2];
    struct pollfd fds[2+1];
    uint32_t dirs[2];
    struct fio_asted_rxs rxbufs[T_FIO_PKT_DISCARD];
    int limit = MAX_PKT_COPY_ONCE;
    int num_ready, i, num_nic = context->num_nic;
    struct fio_nic *rn, *tn;
    struct fio_poll_data pd;

    memset(rxbufs, 0, T_FIO_PKT_DISCARD*sizeof(struct fio_asted_rxs));
    for (i = T_FIO_PKT_INTD; i < T_FIO_PKT_DISCARD; i++)
        rxbufs[i].cb_type = i;

    for (i = 0; i < num_nic; i++)
    {
        nics[i] = &context->nics[i];
        dirs[i] = (FIO_DIR_RX);
    }

    OD( "tid %d Wait %d secs for phy reset", context->me, 5);
    sleep(5);
    OD( "tid %d Ready... num_nic %d", context->me, num_nic);
    gettimeofday(&context->tic, NULL);

    pd.nics = nics;
    pd.fds = fds;
    pd.dirs = dirs;
    pd.num_nic = num_nic;
    pd.notifyfds = context->notifyfds;
    pd.num_notify = 0;

    while (sysconfig.working) 
    {
//sleep(2);
//continue;
        if ( (num_ready=context->vtbl.polls(&pd, 2000)) < 0) 
        {
            gettimeofday(&context->toc, NULL);
            context->toc.tv_sec -= 1; /* Subtract timeout time. */
            OD( "<error> poll error!!!!!");
            continue;
        }

        if (num_ready == 0)
        {
            continue;
        }

        for (i = 0; i < num_nic; i++)
        {
            rn = nics[i];
            tn = &s_ct->nics[i];

            if (rn->rxavl > 0)
            {
                if (context->vtbl.recv(rn, NULL, rxbufs, limit, FIO_LIMIT_FROM) > 0)
                    process_data(rn, tn, nics, num_nic, rxbufs, TXDATA_TYPE_NORMAL, 0);
            }
        }
    }

    /* reset the ``used`` flag. */
    context->used = 0;
    OD( "I'll shutdown");

    return (NULL);
}
Esempio n. 14
0
static int CheckValid()
{
	char temp_arr[1024];
	char *temp_strs[1024];
    int i, l, len_strs;
	char *port_strs[1024];
	char port_range[1024];
	char mybuf[] = "00:00:00:00:00:00";

	if (strlen(sysconfig.if_in) < 1 || strlen(sysconfig.if_out) < 1)
	{
        OD("missing ifnames");
		return -1;
	}

	if (sysconfig.is_test)
	{
		if (strlen(sysconfig.src_mac.name) < 1)
		{
			/* retrieve source mac address. */
			if (source_hwaddr(sysconfig.if_out, mybuf) == -1) {
                OD("Unable to retrieve source mac");
				return -1;
				// continue, fail later
			}
			strcpy(sysconfig.src_mac.name, mybuf);
		}
		/* extract address ranges */
		extract_ip_range(&sysconfig.src_ip);
		extract_mac_range(&sysconfig.src_mac);

        for (i = 0; i < sysconfig.dst_count && i < FIO_MAX_DST_TEST; i++)
        {
            extract_ip_range(&sysconfig.dst_ip[i]);
            extract_mac_range(&sysconfig.dst_mac[i]);
        }
	}

	if (source_hwaddr(sysconfig.if_in, mybuf) == -1) {
        OD("Unable to retrieve source mac %s", sysconfig.if_in);
		return -1;
	}
	bcopy(ether_aton(mybuf), &sysconfig.if_macs[0], ETH_ALEN);
    OD("if %s mac %s", sysconfig.if_in, mybuf);
	if (source_hwaddr(sysconfig.if_out, mybuf) == -1) {
        OD("Unable to retrieve source mac %s", sysconfig.if_out);
		return -1;
	}
	bcopy(ether_aton(mybuf), &sysconfig.if_macs[1], ETH_ALEN);
    OD("if %s mac %s", sysconfig.if_out, mybuf);

    extract_mac_range(&sysconfig.defgw_mac);
    OD("defgw mac %s", sysconfig.defgw_mac.name);

	if (get_if_ip(sysconfig.if_in, &sysconfig.if_ips[0]))
        OD("<error> %s get ip", sysconfig.if_in);
	if (get_if_ip(sysconfig.if_out, &sysconfig.if_ips[1]))
        OD("<error> %s get ip", sysconfig.if_out);

    OD("read %d ipmac", g_mac_num);

	len_strs = splite_str(sysconfig.str_interested_proto, 
			sizeof(sysconfig.str_interested_proto), temp_arr, 
			1024, temp_strs, 1024, ' ');
	translate_proto(temp_strs, len_strs, 1);

	len_strs = splite_str(sysconfig.str_def_proto, 
			sizeof(sysconfig.str_def_proto), temp_arr, 
			1024, temp_strs, 1024, ' ');
	translate_proto(temp_strs, len_strs, 2);

	len_strs = splite_str(sysconfig.str_interested_port, 
			sizeof(sysconfig.str_interested_port), temp_arr, 
			1024, temp_strs, 1024, ' ');

    for (i = 0; i < len_strs; i++)
    {
        l = splite_str(temp_strs[i], strlen(temp_strs[i])+1, 
                port_range, 1024, port_strs, 1024, '~');
        translate_port(port_strs, l, i);
    }
    sysconfig.mac_lifetime *= 1000000;
    sysconfig.mac_buddy_lifetime *= 1000000;
    //sysconfig.multip_checktime *= 1000000;

    if (strlen(sysconfig.if_in))
        strncpy(sysconfig.nic_names[sysconfig.num_nic++], sysconfig.if_in, FIO_MAX_NAME_LEN);
    if (strlen(sysconfig.if_out) && strcmp(sysconfig.if_out, sysconfig.if_in))
        strncpy(sysconfig.nic_names[sysconfig.num_nic++], sysconfig.if_out, FIO_MAX_NAME_LEN);

	return 0;
}
Esempio n. 15
0
int parse_config(const char *file_name)
{
    pid_t pid = getpid();                                                                                                                                                                             
    snprintf(sysconfig.error_path_, MAX_FIO_PATH, "/var/log/error_nfio_%d.log", pid); 
    snprintf(sysconfig.trace_path_, MAX_FIO_PATH, "/var/log/trace_nfio_%d.log", pid);                                                                                                                          
    FILE *fp;
    if ((fp = fopen(file_name, "r")) == NULL)
    {
        printf("fopen() failed\n");
        return -1;
    }

    char line_buf[1024] = {0};
    char key[64] = {0};
    char value[1024] = {0};
    char *p = NULL;
    int pos = 0, md = FM_STR;
    struct fetch_method *pfm;

    while(1)
    {
        if (fgets(line_buf, sizeof(line_buf), fp) == NULL)
            break;
        p = line_buf;
        while(isspace(*p))
            p++;
        if (*p == '\0' || *p == '#')
            continue;

        GetArg(key, sizeof(key), &p);

        for (pfm = g_fms; pfm->key_name; pfm++)
        {
            if (!strcasecmp(key, pfm->key_name))
            {
                md = pfm->fm;
                break;
            }
        }

        if (!pfm->key_name)
        {
            OD("%s doesn't been implemented!", key);
            continue;
        }

        if (pfm->flag&FML_STRUCT)
        {
            if (1 == g_struct)
            {
                OD("<error> Already in a struct");
                goto config_error;
            }
            else
                g_struct = 1;
        }

        switch (md)
        {
            case FM_STR:
                get_str((char*)pfm->dst, value, sizeof(value), p);
                break;
            case FM_INT:
                get_int((int*)pfm->dst, value, sizeof(value), p);
                break;
            case FM_IPMAC:
                {
                    struct IPMAC *ptr;
                    if (NULL != (ptr=get_ipmac(fp)))
                    {
                        g_struct = 0;
                        g_ip_macs[pos++] = ptr;
                        g_mac_num++;
                    }
                }
                break;
            case FM_DST:
                {
                    struct IPDST ipdst;
                    if (NULL != get_dst(fp, &ipdst))
                    {
                        if (sysconfig.dst_count + 1 > FIO_MAX_DST_TEST)
                        {
                            OD("<error> too many dst tags");
                            goto config_error;
                        }
                        strcpy(sysconfig.dst_ip[sysconfig.dst_count].name, ipdst.ip);
                        strcpy(sysconfig.dst_mac[sysconfig.dst_count].name, ipdst.mac);
                        sysconfig.dst_count++;
                        g_struct = 0;
                    }
                    else
                    {
                        OD("<error> get dst tags");
                        goto config_error;
                    }
                }
                break;
            default:
                break;
        }
    }

    fclose(fp);
	return CheckValid();

config_error:
    fclose(fp);
	 return -1;
}
Esempio n. 16
0
void * fio_count(void *data)
{
    int i;
    uint64_t my_rxcount = 0, my_txcount = 0, unuse_count = 0, prev_rx = 0, prev_tx = 0;
    struct timeval tic, toc;
    int report_interval = 1*1000;	/* report interval */
    char dump_buf_rx[2000] = {0};
    char dump_buf_tx[2000] = {0};
    char dump_buf[1000] = {0};
	
	g_logfac = syslog_get_facility(g_str_logfac);
    g_log_host_name = sysconfig.src_ip.name;

    int bucfd = buc_open(sysconfig.dst_ip[0].name, sysconfig.src_port);
    if (bucfd == -1)
        return NULL;

    gettimeofday(&toc, NULL);
    while (sysconfig.working)
    {
        struct timeval delta;
        uint64_t pps_rx, pps_tx;
        int done = 0;
        dump_buf_rx[0] = '\0';
        dump_buf_tx[0] = '\0';

        delta.tv_sec = report_interval/1000;
        delta.tv_usec = (report_interval%1000)*1000;

        //计时== 
        select(0, NULL, NULL, NULL, &delta);

        tv_update_date();
        timersub(&fio_now, &toc, &toc);
        my_rxcount = 0;
        my_txcount = 0;
        unuse_count = 0;
        for (i = 0; i < sysconfig.nthreads; i++) {
            my_rxcount += g_contexts[i].nics[0].rxcount;
            my_rxcount += g_contexts[i].nics[1].rxcount;
            my_txcount += g_contexts[i].nics[0].txcount;
            my_txcount += g_contexts[i].nics[1].txcount;
            unuse_count += g_contexts[i].nics[0].unuse_count;
            unuse_count += g_contexts[i].nics[1].unuse_count;
            sprintf(dump_buf, "%"LU64" ", g_contexts[i].nics[0].rxcount 
                    + g_contexts[i].nics[1].rxcount);
            strcat(dump_buf_rx, dump_buf);
            sprintf(dump_buf, "%"LU64" ", g_contexts[i].nics[0].txcount
                    + g_contexts[i].nics[1].txcount);
            strcat(dump_buf_tx, dump_buf);
            if (g_contexts[i].used == 0)
                done++;
        }
        pps_tx = pps_rx = toc.tv_sec* 1000000 + toc.tv_usec;
        if (pps_rx < 10000)
            continue;
        pps_rx = (my_rxcount - prev_rx)*1000000 / pps_rx;
        OD( "rx %"LU64" ppsrx %s", pps_rx, dump_buf_rx);
        pps_tx = (my_txcount - prev_tx)*1000000 / pps_tx;
        OD( "tx %"LU64" ppstx %s", pps_tx, dump_buf_tx);
        OD( "rx useless pkt %"LU64"\n", unuse_count);
        syslog_format(bucfd, "rx %"LU64" ppsrx %s\ntx %"LU64" ppstx %s\nrx useless pkt %"LU64,
                pps_rx, dump_buf_rx, pps_tx, dump_buf_tx, unuse_count);
        prev_rx = my_rxcount;
        prev_tx = my_txcount;
        toc = fio_now;
        fio_gnow++;
        if (done == sysconfig.nthreads)
            break;
    }

    timerclear(&tic);
    timerclear(&toc);
    OD( "I'll shutdown");

    return NULL;
}
Esempio n. 17
0
int CCopyBlock::CopyTagBlocks()
  {
  CWaitCursor Wait;
//  ASSERT(eSrc!=CB_List); //this src type not allowed
//  ASSERT(eDst!=CB_Tag); //this dst type not allowed
  ASSERT(pEO);
  CProfINIFile SrcPF(bSrcDatalib ? CfgFiles() : PrjFiles(), (char*)CopyBlkFileName);
  CheckCopyBlockVer(SrcPF);
  CProfINIFile DstPF(bDstDatalib ? CfgFiles() : PrjFiles(), (char*)CopyBlkFileName);
  if (!CheckCopyBlockVer(DstPF, true))
    return 0;
  int Cnt = 0;
  //gs_pTheSFELib->FE_SetHoldGlobalLinks(true);
  //gs_Exec.SetHoldValidateData(true, true, true);
  gs_Exec.BeginBulkChange();

  Strng Section;
  if (eSrc==CB_SelectedTag)
    Section = TempBlockName;
  else
    Section.Set("%s(%s)", sSrc(), sModelClass());
  char Buff[16384];
  DWORD dw = SrcPF.RdSection(Section(), Buff, sizeof(Buff));
  ASSERT(dw<sizeof(Buff)-2); //section too large!!!
  if (eDst==CB_Block)
    {
    Strng DstSection;
    DstSection.Set("%s(%s)", sDst(), sModelClass());
    DstPF.WrSection(DstSection(), Buff);
    }
  else
    {
    Strng_List sStrList;
    CXM_Route Route;
    CXM_ObjectData ObjData;
    char* p = Buff;
    while (p[0])
      {
      int len = strlen(p);
      char* Nextp = p;
      Nextp += (len + 1);
      char* pp = strchr(p, '=');
      if (pp)
        {
        pp[0] = 0;
        char* pValue = &pp[1];
        char* ppp = strchr(p, '.');
        Strng PartTag;
        PartTag = (ppp==NULL ? p : ppp);
        for (int i=0; i<TagList.GetSize(); i++)
          {
          Strng WrkTag(TagList[i]());
          WrkTag += PartTag;
          //CXM_ObjectTag ObjTag(WrkTag(), 0);
          //need to use TABOpt_AllInfoOnce because of tags that contain a strList!
          CXM_ObjectTag ObjTag(WrkTag(), TABOpt_AllInfoOnce);//0);//TABOpt_Exists);//TABOpt_Parms);//TABOpt_ValCnvsOnce);
          Route.Clear();
          if (pEO->XReadTaggedItem(ObjTag, ObjData, Route))
            {
            CPkDataItem * pItem = ObjData.FirstItem();
            byte cType = pItem->Type();
            PkDataUnion DU;
            if (IsStrng(cType))
              DU.SetTypeString(cType, pValue);
            else if (IsFloatData(cType))
              DU.SetTypeDouble(cType, SafeAtoF(pValue));
            else if (IsIntData(cType) && pItem->Contains(PDI_StrList))
              {
              pItem->GetStrList(sStrList);
              pStrng pS = sStrList.Find(pValue);
              //const int Indx = (pS==NULL ? 0 : sStrList.Index(pS));
              const int Indx = (pS==NULL ? 0 : pS->Index());
              DU.SetTypeLong(cType, Indx);
              }
            else
              DU.SetTypeLong(cType, SafeAtoL(pValue));
            CXM_ObjectData OD(0, 0, WrkTag(), 0, DU);
            if (pEO->XWriteTaggedItem(OD, Route)==TOData_NotFound)
              LogWarning(WrkTag(), 0, "Write tag failed");
            else
              Cnt++;
            //if (pEO->XWriteTaggedItem(OD, Route)!=TOData_OK)
            //  LogWarning(WrkTag(), 0, "Write tag failed (possibly invalid data)");
            }
          else
            LogWarning(WrkTag(), 0, "Unable to read tag");
          }
        }
      p = Nextp;
      }
    }
  
  //TaggedObject::SetHoldValidateData(false);
  //gs_Exec.SetHoldValidateData(false, true, true);
  //gs_pTheSFELib->FE_SetHoldGlobalLinks(false);
  gs_Exec.EndBulkChange();


  //TaggedObject::SetXWritesBusy(false);
  return Cnt;
  }