Skip to content

Commit 4008248

Browse files
committed
FIX: missing time string in default proccess
1 parent 25e037b commit 4008248

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/packet.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,19 @@ static void push_packet_to_vm(lua_State *vm, user_packet *packet) {
136136
vm_need_gc(vm);
137137
}
138138

139-
static void push_tcp_packet_to_user(server *srv, user_packet *packet) {
140-
char *type = "REQ";
139+
static void push_packet_to_user(server *srv, user_packet *packet) {
140+
char t_buf[64], *type = "REQ";
141141
if (srv->vm) {
142142
push_packet_to_vm(srv->vm, packet);
143143
return;
144144
}
145145
if (packet->size == 0) return;
146+
147+
strftime(t_buf,64,"%Y-%m-%d %H:%M:%S",localtime(&packet->tv->tv_sec));
146148
if (!packet->request) type = "RSP";
147149
if (packet->tcp) {
148150
rlog("%s %s:%d=>%s:%d %s %u %u %d %u %.*s",
149-
"abc",
151+
t_buf,
150152
inet_ntoa(packet->sip),
151153
packet->sport,
152154
inet_ntoa(packet->dip),
@@ -161,7 +163,7 @@ static void push_tcp_packet_to_user(server *srv, user_packet *packet) {
161163
);
162164
} else {
163165
rlog("%s %s:%d=>%s:%d %s %u %.*s",
164-
"abc",
166+
t_buf,
165167
inet_ntoa(packet->sip),
166168
packet->sport,
167169
inet_ntoa(packet->dip),
@@ -219,14 +221,22 @@ static void record_simple_latency(server *srv, user_packet *packet) {
219221

220222
static void process_tcp_packet(server *srv, user_packet *packet) {
221223
if (srv->opts->mode == P_RAW) {
222-
push_tcp_packet_to_user(srv, packet);
224+
push_packet_to_user(srv, packet);
223225
} else {
224226
record_simple_latency(srv, packet);
225227
}
226228
}
227229

228230
static void process_udp_packet(server *srv, user_packet *packet) {
229-
push_tcp_packet_to_user(srv, packet);
231+
push_packet_to_user(srv, packet);
232+
}
233+
234+
static int8_t is_request(server *srv, user_packet *packet) {
235+
if (packet->sport != packet->dport) {
236+
return port_in_target(srv, packet->dport) != -1;
237+
}
238+
// TODO; corner case src port == dst port
239+
return 1;
230240
}
231241

232242
void extract_packet_handler(unsigned char *user,
@@ -248,22 +258,25 @@ void extract_packet_handler(unsigned char *user,
248258
default:
249259
return; // do nothing with unknown link type packet
250260
}
261+
if (ip_packet->ip_p != IPPROTO_TCP && ip_packet->ip_p != IPPROTO_UDP) {
262+
return;
263+
}
251264
switch (ip_packet->ip_p) {
252265
case IPPROTO_TCP:
253266
upacket = gen_tcp_packet(&header->ts, ip_packet);
254-
upacket->request = port_in_target(srv, upacket->dport) != -1;
255-
stats_update_bytes(srv->st, upacket->request, upacket->size);
267+
upacket->request = is_request(srv, upacket);
256268
process_tcp_packet(srv, upacket);
269+
stats_update_bytes(srv->st, upacket->request, upacket->size);
257270
free(upacket);
258271
break;
259272
case IPPROTO_UDP:
260273
upacket = gen_udp_packet(&header->ts, ip_packet);
261-
upacket->request = port_in_target(srv, upacket->dport)!=-1;
262-
stats_update_bytes(srv->st, upacket->request, upacket->size);
274+
upacket->request = is_request(srv, upacket);
263275
process_udp_packet(srv, upacket);
276+
stats_update_bytes(srv->st, upacket->request, upacket->size);
264277
free(upacket);
265278
break;
266279
default:
267280
break;
268281
}
269-
}
282+
}

src/util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ void free_split_string(struct array *arr) {
6262
free(token);
6363
}
6464
array_dealloc(arr);
65-
}
65+
}

0 commit comments

Comments
 (0)