h2olog: implement the header tracer func
@@ -11,6 +11,7 @@ import getopt, sys
bpf = """
#define MAX_STR_LEN 128
+#define MIN(x, y) (((x) < (y)) ? (x) : (y))
/*
* "req_line_t" represents an individual log line for a given request.
@@ -43,7 +44,30 @@ int trace_receive_req(struct pt_regs *ctx) {
return 0;
}
-int trace_receive_req_header(void *ctx) {
+int trace_receive_req_header(struct pt_regs *ctx) {
+ struct req_line_t line = {};
+ uint64_t conn_id, req_id = 0;
+ size_t n_len, v_len;
+ void *pos = NULL;
+
+ bpf_usdt_readarg(1, ctx, &line.conn_id);
+ bpf_usdt_readarg(2, ctx, &line.req_id);
+
+ // Extract the Header Name
+ bpf_usdt_readarg(3, ctx, &pos);
+ bpf_usdt_readarg(4, ctx, &n_len);
+ line.header_name_len = MIN(MAX_STR_LEN, n_len);
+ bpf_probe_read(&line.header_name, line.header_name_len, pos);
+
+ // Extract the Header Value
+ bpf_usdt_readarg(5, ctx, &pos);
+ bpf_usdt_readarg(6, ctx, &v_len);
+ line.header_value_len = MIN(MAX_STR_LEN, v_len);
+ bpf_probe_read(&line.header_value, line.header_value_len, pos);
+
+ if (reqbuf.perf_submit(ctx, &line, sizeof(line)) < 0)
+ bpf_trace_printk("failed to perf_submit\\n");
+
return 0;
}
"""
@@ -53,6 +77,8 @@ def print_req_line(cpu, data, size):
if line.http_version:
v = "HTTP/%d.%d" % (line.http_version / 256, line.http_version % 256)
print("%u %u: %s" % (line.conn_id, line.req_id, v))
+ else:
+ print("%u %u: %s %s" % (line.conn_id, line.req_id, line.header_name, line.header_value))
try:
h2o_pid = 0
