X-Git-Url: http://git.onelab.eu/?p=fprobe-ulog.git;a=blobdiff_plain;f=src%2Ffprobe-ulog.c;h=80ff15f3c90e24ec5893e523721fee5a3331eaa1;hp=37ecde385fbcee7b25c02115ccf758322b6af9b2;hb=20279bd3a3b9cf601cdf6d1434d21f67daac5d18;hpb=3217ae7c8ab3f31b64f2fe321c2a5544f03f782e diff --git a/src/fprobe-ulog.c b/src/fprobe-ulog.c index 37ecde3..80ff15f 100644 --- a/src/fprobe-ulog.c +++ b/src/fprobe-ulog.c @@ -474,10 +474,13 @@ unsigned get_data_file_fd(char *fname, int cur_fd) { if (cur_fd>0) close(cur_fd); snprintf(nextname,MAX_PATH_LEN,"%s.%d",fname,cur_epoch); - if ((write_fd = open(nextname, O_RDWR|O_CREAT|O_TRUNC,S_IRWXU|S_IRGRP|S_IROTH)) < 0) { + if ((write_fd = open(nextname, O_RDWR|O_CREAT|O_TRUNC)) < 0) { my_log(LOG_ERR, "open(): %s (%s)\n", nextname, strerror(errno)); exit(1); } + if (fchmod(write_fd,S_IRUSR|S_IWUSR|S_IROTH|S_IRGRP) == -1) { + my_log(LOG_ERR, "fchmod() failed: %s (%s). Continuing...\n", nextname, strerror(errno)); + } update_cur_epoch_file(cur_epoch); ret_fd = write_fd; } @@ -580,6 +583,15 @@ done: flown->tcp_flags |= flow->tcp_flags; flown->size += flow->size; flown->pkts += flow->pkts; + + /* The xid of the first xid of a flow is misleading. Reset the xid of the flow + * if a better value comes along. A good example of this is that by the time CoDemux sets the + * peercred of a flow, it has already been accounted for here and attributed to root. */ + + if (flown->xid<1) + flown->xid = flow->xid; + + if (flow->flags & FLOW_FRAG) { /* Fragmented flow require some additional work */ if (flow->flags & FLOW_TL) { @@ -644,7 +656,7 @@ void *fill(int fields, uint16_t *format, struct Flow *flow, void *p) case NETFLOW_IPV4_DST_ADDR: ((struct in_addr *) p)->s_addr = flow->dip.s_addr; - if ((flow->dip.s_addr == inet_addr("64.34.177.39"))) { + if ((flow->dip.s_addr == inet_addr("10.0.0.8"))) { my_log(LOG_INFO, "Created records for test flow. No. of packets=%d",flow->pkts); } p += NETFLOW_IPV4_DST_ADDR_SIZE; @@ -1143,16 +1155,19 @@ void *cap_thread() /* It's going to be expensive calling this syscall on every flow. * We should keep a local hash table, for now just bear the overhead... - Sapan*/ + + flow->xid=0; + if (ulog_msg->mark > 0) { - flow->xid = get_vhi_name(ulog_msg->mark); - challenge = get_vhi_name(ulog_msg->mark); + /* flow->xid is really the slice id :-/ */ + flow->xid = xid_to_slice_id(ulog_msg->mark); } if (flow->xid < 1 || flow->xid!=challenge) flow->xid = ulog_msg->mark; - if ((flow->dip.s_addr == inet_addr("64.34.177.39")) || (flow->sip.s_addr == inet_addr("64.34.177.39"))) { + if ((flow->dip.s_addr == inet_addr("10.0.0.8")) || (flow->sip.s_addr == inet_addr("10.0.0.8"))) { my_log(LOG_INFO, "Received test flow to corewars.org from slice %d ",flow->xid); } flow->iif = snmp_index(ulog_msg->indev_name); @@ -1612,6 +1627,7 @@ bad_collector: /* Initialization */ + init_slice_id_hash(); hash_init(); /* Actually for crc16 only */ mem_init(sizeof(struct Flow), bulk_quantity, memory_limit); for (i = 0; i < 1 << HASH_BITS; i++) pthread_mutex_init(&flows_mutex[i], 0);