blob: 7681822e70e35fbe2ae80800855f19c5a3f6128b [file] [log] [blame]
Alexey Ivanovcc01a9c2019-01-16 09:50:46 -08001#!/usr/bin/python
Gerald Combsabdca972018-11-26 23:37:24 -07002# -*- coding: utf-8 -*-
Brendan Greggbbd9acd2018-03-20 18:35:12 -07003# @lint-avoid-python-3-compatibility-imports
4#
5# tcpstates Trace the TCP session state changes with durations.
6# For Linux, uses BCC, BPF. Embedded C.
7#
8# USAGE: tcpstates [-h] [-C] [-S] [interval [count]]
9#
10# This uses the sock:inet_sock_set_state tracepoint, added to Linux 4.16.
11# Linux 4.16 also adds more state transitions so that they can be traced.
12#
13# Copyright 2018 Netflix, Inc.
14# Licensed under the Apache License, Version 2.0 (the "License")
15#
16# 20-Mar-2018 Brendan Gregg Created this.
17
18from __future__ import print_function
19from bcc import BPF
20import argparse
21from socket import inet_ntop, AF_INET, AF_INET6
22from struct import pack
Gerald Combsabdca972018-11-26 23:37:24 -070023from time import strftime, time
24from os import getuid
Brendan Greggbbd9acd2018-03-20 18:35:12 -070025
26# arguments
27examples = """examples:
28 ./tcpstates # trace all TCP state changes
29 ./tcpstates -t # include timestamp column
30 ./tcpstates -T # include time column (HH:MM:SS)
Michael Prokopc14d02a2020-01-09 02:29:18 +010031 ./tcpstates -w # wider columns (fit IPv6)
Brendan Greggbbd9acd2018-03-20 18:35:12 -070032 ./tcpstates -stT # csv output, with times & timestamps
Gerald Combsabdca972018-11-26 23:37:24 -070033 ./tcpstates -Y # log events to the systemd journal
Brendan Greggbbd9acd2018-03-20 18:35:12 -070034 ./tcpstates -L 80 # only trace local port 80
35 ./tcpstates -L 80,81 # only trace local ports 80 and 81
36 ./tcpstates -D 80 # only trace remote port 80
37"""
38parser = argparse.ArgumentParser(
39 description="Trace TCP session state changes and durations",
40 formatter_class=argparse.RawDescriptionHelpFormatter,
41 epilog=examples)
42parser.add_argument("-T", "--time", action="store_true",
43 help="include time column on output (HH:MM:SS)")
44parser.add_argument("-t", "--timestamp", action="store_true",
45 help="include timestamp on output (seconds)")
46parser.add_argument("-w", "--wide", action="store_true",
47 help="wide column output (fits IPv6 addresses)")
48parser.add_argument("-s", "--csv", action="store_true",
49 help="comma separated values output")
50parser.add_argument("-L", "--localport",
51 help="comma-separated list of local ports to trace.")
52parser.add_argument("-D", "--remoteport",
53 help="comma-separated list of remote ports to trace.")
54parser.add_argument("--ebpf", action="store_true",
55 help=argparse.SUPPRESS)
Gerald Combsabdca972018-11-26 23:37:24 -070056parser.add_argument("-Y", "--journal", action="store_true",
57 help="log session state changes to the systemd journal")
Brendan Greggbbd9acd2018-03-20 18:35:12 -070058args = parser.parse_args()
59debug = 0
60
61# define BPF program
Daniel Poelzleithnerd0ec8a22020-03-12 12:31:39 +010062bpf_header = """
Brendan Greggbbd9acd2018-03-20 18:35:12 -070063#include <uapi/linux/ptrace.h>
64#define KBUILD_MODNAME "foo"
65#include <linux/tcp.h>
66#include <net/sock.h>
67#include <bcc/proto.h>
68
69BPF_HASH(last, struct sock *, u64);
70
71// separate data structs for ipv4 and ipv6
72struct ipv4_data_t {
Brendan Greggbbd9acd2018-03-20 18:35:12 -070073 u64 ts_us;
74 u64 skaddr;
Joe Yin36ce1122018-08-17 06:04:00 +080075 u32 saddr;
76 u32 daddr;
Brendan Greggbbd9acd2018-03-20 18:35:12 -070077 u64 span_us;
Brendan Gregg2b23de62018-03-21 15:41:16 -070078 u32 pid;
79 u32 ports;
80 u32 oldstate;
81 u32 newstate;
Brendan Greggbbd9acd2018-03-20 18:35:12 -070082 char task[TASK_COMM_LEN];
83};
84BPF_PERF_OUTPUT(ipv4_events);
85
86struct ipv6_data_t {
87 u64 ts_us;
88 u64 skaddr;
Brendan Greggbbd9acd2018-03-20 18:35:12 -070089 unsigned __int128 saddr;
90 unsigned __int128 daddr;
Brendan Greggbbd9acd2018-03-20 18:35:12 -070091 u64 span_us;
Brendan Gregg2b23de62018-03-21 15:41:16 -070092 u32 pid;
93 u32 ports;
94 u32 oldstate;
95 u32 newstate;
Brendan Greggbbd9acd2018-03-20 18:35:12 -070096 char task[TASK_COMM_LEN];
97};
98BPF_PERF_OUTPUT(ipv6_events);
99
100struct id_t {
101 u32 pid;
102 char task[TASK_COMM_LEN];
103};
Daniel Poelzleithnerd0ec8a22020-03-12 12:31:39 +0100104"""
105bpf_text_tracepoint = """
Brendan Greggbbd9acd2018-03-20 18:35:12 -0700106TRACEPOINT_PROBE(sock, inet_sock_set_state)
107{
108 if (args->protocol != IPPROTO_TCP)
109 return 0;
110
111 u32 pid = bpf_get_current_pid_tgid() >> 32;
112 // sk is used as a UUID
113 struct sock *sk = (struct sock *)args->skaddr;
114
115 // lport is either used in a filter here, or later
116 u16 lport = args->sport;
117 FILTER_LPORT
118
119 // dport is either used in a filter here, or later
120 u16 dport = args->dport;
121 FILTER_DPORT
122
123 // calculate delta
124 u64 *tsp, delta_us;
125 tsp = last.lookup(&sk);
126 if (tsp == 0)
127 delta_us = 0;
128 else
129 delta_us = (bpf_ktime_get_ns() - *tsp) / 1000;
130
131 if (args->family == AF_INET) {
132 struct ipv4_data_t data4 = {
133 .span_us = delta_us,
Marko Myllynenbfbf17e2018-09-11 21:49:58 +0300134 .oldstate = args->oldstate,
135 .newstate = args->newstate };
Brendan Greggbbd9acd2018-03-20 18:35:12 -0700136 data4.skaddr = (u64)args->skaddr;
137 data4.ts_us = bpf_ktime_get_ns() / 1000;
Joe Yin36ce1122018-08-17 06:04:00 +0800138 __builtin_memcpy(&data4.saddr, args->saddr, sizeof(data4.saddr));
139 __builtin_memcpy(&data4.daddr, args->daddr, sizeof(data4.daddr));
Brendan Greggbbd9acd2018-03-20 18:35:12 -0700140 // a workaround until data4 compiles with separate lport/dport
Xiaozhou Liu00213fc2019-06-17 23:28:16 +0800141 data4.ports = dport + ((0ULL + lport) << 16);
Brendan Greggbbd9acd2018-03-20 18:35:12 -0700142 data4.pid = pid;
143
144 bpf_get_current_comm(&data4.task, sizeof(data4.task));
145 ipv4_events.perf_submit(args, &data4, sizeof(data4));
146
147 } else /* 6 */ {
148 struct ipv6_data_t data6 = {
149 .span_us = delta_us,
Marko Myllynenbfbf17e2018-09-11 21:49:58 +0300150 .oldstate = args->oldstate,
151 .newstate = args->newstate };
Brendan Greggbbd9acd2018-03-20 18:35:12 -0700152 data6.skaddr = (u64)args->skaddr;
153 data6.ts_us = bpf_ktime_get_ns() / 1000;
Joe Yin36ce1122018-08-17 06:04:00 +0800154 __builtin_memcpy(&data6.saddr, args->saddr_v6, sizeof(data6.saddr));
155 __builtin_memcpy(&data6.daddr, args->daddr_v6, sizeof(data6.daddr));
Brendan Greggbbd9acd2018-03-20 18:35:12 -0700156 // a workaround until data6 compiles with separate lport/dport
Xiaozhou Liu00213fc2019-06-17 23:28:16 +0800157 data6.ports = dport + ((0ULL + lport) << 16);
Brendan Greggbbd9acd2018-03-20 18:35:12 -0700158 data6.pid = pid;
159 bpf_get_current_comm(&data6.task, sizeof(data6.task));
160 ipv6_events.perf_submit(args, &data6, sizeof(data6));
161 }
162
163 u64 ts = bpf_ktime_get_ns();
164 last.update(&sk, &ts);
165
166 return 0;
167}
168"""
169
Daniel Poelzleithnerd0ec8a22020-03-12 12:31:39 +0100170bpf_text_kprobe = """
171int kprobe__tcp_set_state(struct pt_regs *ctx, struct sock *sk, int state)
172{
173 // check this is TCP
174 u8 protocol = 0;
175
176 // Following comments add by Joe Yin:
177 // Unfortunately,it can not work since Linux 4.10,
178 // because the sk_wmem_queued is not following the bitfield of sk_protocol.
179 // And the following member is sk_gso_max_segs.
180 // So, we can use this:
Sumanth Korikkar7f6066d2020-05-20 10:49:56 -0500181 // bpf_probe_read_kernel(&protocol, 1, (void *)((u64)&newsk->sk_gso_max_segs) - 3);
Daniel Poelzleithnerd0ec8a22020-03-12 12:31:39 +0100182 // In order to diff the pre-4.10 and 4.10+ ,introduce the variables gso_max_segs_offset,sk_lingertime,
183 // sk_lingertime is closed to the gso_max_segs_offset,and
184 // the offset between the two members is 4
185
186 int gso_max_segs_offset = offsetof(struct sock, sk_gso_max_segs);
187 int sk_lingertime_offset = offsetof(struct sock, sk_lingertime);
188
189 if (sk_lingertime_offset - gso_max_segs_offset == 4)
190 // 4.10+ with little endian
191#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
Sumanth Korikkar7f6066d2020-05-20 10:49:56 -0500192 bpf_probe_read_kernel(&protocol, 1, (void *)((u64)&sk->sk_gso_max_segs) - 3);
Daniel Poelzleithnerd0ec8a22020-03-12 12:31:39 +0100193else
194 // pre-4.10 with little endian
Sumanth Korikkar7f6066d2020-05-20 10:49:56 -0500195 bpf_probe_read_kernel(&protocol, 1, (void *)((u64)&sk->sk_wmem_queued) - 3);
Daniel Poelzleithnerd0ec8a22020-03-12 12:31:39 +0100196#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
197 // 4.10+ with big endian
Sumanth Korikkar7f6066d2020-05-20 10:49:56 -0500198 bpf_probe_read_kernel(&protocol, 1, (void *)((u64)&sk->sk_gso_max_segs) - 1);
Daniel Poelzleithnerd0ec8a22020-03-12 12:31:39 +0100199else
200 // pre-4.10 with big endian
Sumanth Korikkar7f6066d2020-05-20 10:49:56 -0500201 bpf_probe_read_kernel(&protocol, 1, (void *)((u64)&sk->sk_wmem_queued) - 1);
Daniel Poelzleithnerd0ec8a22020-03-12 12:31:39 +0100202#else
203# error "Fix your compiler's __BYTE_ORDER__?!"
204#endif
205
206 if (protocol != IPPROTO_TCP)
207 return 0;
208
209 u32 pid = bpf_get_current_pid_tgid() >> 32;
210 // sk is used as a UUID
211
212 // lport is either used in a filter here, or later
213 u16 lport = sk->__sk_common.skc_num;
214 FILTER_LPORT
215
216 // dport is either used in a filter here, or later
217 u16 dport = sk->__sk_common.skc_dport;
218 FILTER_DPORT
219
220 // calculate delta
221 u64 *tsp, delta_us;
222 tsp = last.lookup(&sk);
223 if (tsp == 0)
224 delta_us = 0;
225 else
226 delta_us = (bpf_ktime_get_ns() - *tsp) / 1000;
227
228 u16 family = sk->__sk_common.skc_family;
229
230 if (family == AF_INET) {
231 struct ipv4_data_t data4 = {
232 .span_us = delta_us,
233 .oldstate = sk->__sk_common.skc_state,
234 .newstate = state };
235 data4.skaddr = (u64)sk;
236 data4.ts_us = bpf_ktime_get_ns() / 1000;
237 data4.saddr = sk->__sk_common.skc_rcv_saddr;
238 data4.daddr = sk->__sk_common.skc_daddr;
239 // a workaround until data4 compiles with separate lport/dport
240 data4.ports = dport + ((0ULL + lport) << 16);
241 data4.pid = pid;
242
243 bpf_get_current_comm(&data4.task, sizeof(data4.task));
244 ipv4_events.perf_submit(ctx, &data4, sizeof(data4));
245
246 } else /* 6 */ {
247 struct ipv6_data_t data6 = {
248 .span_us = delta_us,
249 .oldstate = sk->__sk_common.skc_state,
250 .newstate = state };
251 data6.skaddr = (u64)sk;
252 data6.ts_us = bpf_ktime_get_ns() / 1000;
Sumanth Korikkar7f6066d2020-05-20 10:49:56 -0500253 bpf_probe_read_kernel(&data6.saddr, sizeof(data6.saddr),
Daniel Poelzleithnerd0ec8a22020-03-12 12:31:39 +0100254 sk->__sk_common.skc_v6_rcv_saddr.in6_u.u6_addr32);
Sumanth Korikkar7f6066d2020-05-20 10:49:56 -0500255 bpf_probe_read_kernel(&data6.daddr, sizeof(data6.daddr),
Daniel Poelzleithnerd0ec8a22020-03-12 12:31:39 +0100256 sk->__sk_common.skc_v6_daddr.in6_u.u6_addr32);
257 // a workaround until data6 compiles with separate lport/dport
258 data6.ports = dport + ((0ULL + lport) << 16);
259 data6.pid = pid;
260 bpf_get_current_comm(&data6.task, sizeof(data6.task));
261 ipv6_events.perf_submit(ctx, &data6, sizeof(data6));
262 }
263
264 u64 ts = bpf_ktime_get_ns();
265 last.update(&sk, &ts);
266
267 return 0;
268
269};
270"""
271
272bpf_text = bpf_header
273if (BPF.tracepoint_exists("sock", "inet_sock_set_state")):
274 bpf_text += bpf_text_tracepoint
275else:
276 bpf_text += bpf_text_kprobe
Brendan Greggbbd9acd2018-03-20 18:35:12 -0700277
278# code substitutions
279if args.remoteport:
280 dports = [int(dport) for dport in args.remoteport.split(',')]
281 dports_if = ' && '.join(['dport != %d' % dport for dport in dports])
282 bpf_text = bpf_text.replace('FILTER_DPORT',
283 'if (%s) { last.delete(&sk); return 0; }' % dports_if)
284if args.localport:
285 lports = [int(lport) for lport in args.localport.split(',')]
286 lports_if = ' && '.join(['lport != %d' % lport for lport in lports])
287 bpf_text = bpf_text.replace('FILTER_LPORT',
288 'if (%s) { last.delete(&sk); return 0; }' % lports_if)
289bpf_text = bpf_text.replace('FILTER_DPORT', '')
290bpf_text = bpf_text.replace('FILTER_LPORT', '')
291
292if debug or args.ebpf:
293 print(bpf_text)
294 if args.ebpf:
295 exit()
296
Brendan Greggbbd9acd2018-03-20 18:35:12 -0700297#
298# Setup output formats
299#
300# Don't change the default output (next 2 lines): this fits in 80 chars. I
301# know it doesn't have NS or UIDs etc. I know. If you really, really, really
302# need to add columns, columns that solve real actual problems, I'd start by
303# adding an extended mode (-x) to included those columns.
304#
305header_string = "%-16s %-5s %-10.10s %s%-15s %-5s %-15s %-5s %-11s -> %-11s %s"
306format_string = ("%-16x %-5d %-10.10s %s%-15s %-5d %-15s %-5d %-11s " +
307 "-> %-11s %.3f")
308if args.wide:
309 header_string = ("%-16s %-5s %-16.16s %-2s %-26s %-5s %-26s %-5s %-11s " +
310 "-> %-11s %s")
311 format_string = ("%-16x %-5d %-16.16s %-2s %-26s %-5s %-26s %-5d %-11s " +
312 "-> %-11s %.3f")
313if args.csv:
314 header_string = "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s"
315 format_string = "%x,%d,%s,%s,%s,%s,%s,%d,%s,%s,%.3f"
316
Gerald Combsabdca972018-11-26 23:37:24 -0700317if args.journal:
318 try:
319 from systemd import journal
320 except ImportError:
321 print("ERROR: Journal logging requires the systemd.journal module")
322 exit(1)
323
324
Brendan Greggbbd9acd2018-03-20 18:35:12 -0700325def tcpstate2str(state):
326 # from include/net/tcp_states.h:
327 tcpstate = {
328 1: "ESTABLISHED",
329 2: "SYN_SENT",
330 3: "SYN_RECV",
331 4: "FIN_WAIT1",
332 5: "FIN_WAIT2",
333 6: "TIME_WAIT",
334 7: "CLOSE",
335 8: "CLOSE_WAIT",
336 9: "LAST_ACK",
337 10: "LISTEN",
338 11: "CLOSING",
339 12: "NEW_SYN_RECV",
340 }
341
342 if state in tcpstate:
343 return tcpstate[state]
344 else:
345 return str(state)
346
Gerald Combsabdca972018-11-26 23:37:24 -0700347def journal_fields(event, addr_family):
348 addr_pfx = 'IPV4'
349 if addr_family == AF_INET6:
350 addr_pfx = 'IPV6'
351
352 fields = {
353 # Standard fields described in systemd.journal-fields(7). journal.send
354 # will fill in CODE_LINE, CODE_FILE, and CODE_FUNC for us. If we're
355 # root and specify OBJECT_PID, systemd-journald will add other OBJECT_*
356 # fields for us.
357 'SYSLOG_IDENTIFIER': 'tcpstates',
358 'PRIORITY': 5,
359 '_SOURCE_REALTIME_TIMESTAMP': time() * 1000000,
360 'OBJECT_PID': str(event.pid),
361 'OBJECT_COMM': event.task.decode('utf-8', 'replace'),
362 # Custom fields, aka "stuff we sort of made up".
363 'OBJECT_' + addr_pfx + '_SOURCE_ADDRESS': inet_ntop(addr_family, pack("I", event.saddr)),
Xiaozhou Liu00213fc2019-06-17 23:28:16 +0800364 'OBJECT_TCP_SOURCE_PORT': str(event.ports >> 16),
Gerald Combsabdca972018-11-26 23:37:24 -0700365 'OBJECT_' + addr_pfx + '_DESTINATION_ADDRESS': inet_ntop(addr_family, pack("I", event.daddr)),
Xiaozhou Liu00213fc2019-06-17 23:28:16 +0800366 'OBJECT_TCP_DESTINATION_PORT': str(event.ports & 0xffff),
Gerald Combsabdca972018-11-26 23:37:24 -0700367 'OBJECT_TCP_OLD_STATE': tcpstate2str(event.oldstate),
368 'OBJECT_TCP_NEW_STATE': tcpstate2str(event.newstate),
369 'OBJECT_TCP_SPAN_TIME': str(event.span_us)
370 }
371
372 msg_format_string = (u"%(OBJECT_COMM)s " +
373 u"%(OBJECT_" + addr_pfx + "_SOURCE_ADDRESS)s " +
374 u"%(OBJECT_TCP_SOURCE_PORT)s → " +
375 u"%(OBJECT_" + addr_pfx + "_DESTINATION_ADDRESS)s " +
376 u"%(OBJECT_TCP_DESTINATION_PORT)s " +
377 u"%(OBJECT_TCP_OLD_STATE)s → %(OBJECT_TCP_NEW_STATE)s")
378 fields['MESSAGE'] = msg_format_string % (fields)
379
380 if getuid() == 0:
381 del fields['OBJECT_COMM'] # Handled by systemd-journald
382
383 return fields
384
Brendan Greggbbd9acd2018-03-20 18:35:12 -0700385# process event
386def print_ipv4_event(cpu, data, size):
Xiaozhou Liu51d62d32019-02-15 13:03:05 +0800387 event = b["ipv4_events"].event(data)
Brendan Greggbbd9acd2018-03-20 18:35:12 -0700388 global start_ts
389 if args.time:
390 if args.csv:
391 print("%s," % strftime("%H:%M:%S"), end="")
392 else:
393 print("%-8s " % strftime("%H:%M:%S"), end="")
394 if args.timestamp:
395 if start_ts == 0:
396 start_ts = event.ts_us
397 delta_s = (float(event.ts_us) - start_ts) / 1000000
398 if args.csv:
399 print("%.6f," % delta_s, end="")
400 else:
401 print("%-9.6f " % delta_s, end="")
jeromemarchandb96ebcd2018-10-10 01:58:15 +0200402 print(format_string % (event.skaddr, event.pid, event.task.decode('utf-8', 'replace'),
Brendan Greggbbd9acd2018-03-20 18:35:12 -0700403 "4" if args.wide or args.csv else "",
Xiaozhou Liu00213fc2019-06-17 23:28:16 +0800404 inet_ntop(AF_INET, pack("I", event.saddr)), event.ports >> 16,
405 inet_ntop(AF_INET, pack("I", event.daddr)), event.ports & 0xffff,
Brendan Greggbbd9acd2018-03-20 18:35:12 -0700406 tcpstate2str(event.oldstate), tcpstate2str(event.newstate),
407 float(event.span_us) / 1000))
Gerald Combsabdca972018-11-26 23:37:24 -0700408 if args.journal:
409 journal.send(**journal_fields(event, AF_INET))
Brendan Greggbbd9acd2018-03-20 18:35:12 -0700410
411def print_ipv6_event(cpu, data, size):
Xiaozhou Liu51d62d32019-02-15 13:03:05 +0800412 event = b["ipv6_events"].event(data)
Brendan Greggbbd9acd2018-03-20 18:35:12 -0700413 global start_ts
414 if args.time:
415 if args.csv:
416 print("%s," % strftime("%H:%M:%S"), end="")
417 else:
418 print("%-8s " % strftime("%H:%M:%S"), end="")
419 if args.timestamp:
420 if start_ts == 0:
421 start_ts = event.ts_us
422 delta_s = (float(event.ts_us) - start_ts) / 1000000
423 if args.csv:
424 print("%.6f," % delta_s, end="")
425 else:
426 print("%-9.6f " % delta_s, end="")
jeromemarchandb96ebcd2018-10-10 01:58:15 +0200427 print(format_string % (event.skaddr, event.pid, event.task.decode('utf-8', 'replace'),
Brendan Greggbbd9acd2018-03-20 18:35:12 -0700428 "6" if args.wide or args.csv else "",
Xiaozhou Liu00213fc2019-06-17 23:28:16 +0800429 inet_ntop(AF_INET6, event.saddr), event.ports >> 16,
430 inet_ntop(AF_INET6, event.daddr), event.ports & 0xffff,
Brendan Greggbbd9acd2018-03-20 18:35:12 -0700431 tcpstate2str(event.oldstate), tcpstate2str(event.newstate),
432 float(event.span_us) / 1000))
Gerald Combsabdca972018-11-26 23:37:24 -0700433 if args.journal:
434 journal.send(**journal_fields(event, AF_INET6))
Brendan Greggbbd9acd2018-03-20 18:35:12 -0700435
436# initialize BPF
437b = BPF(text=bpf_text)
438
439# header
440if args.time:
441 if args.csv:
442 print("%s," % ("TIME"), end="")
443 else:
444 print("%-8s " % ("TIME"), end="")
445if args.timestamp:
446 if args.csv:
447 print("%s," % ("TIME(s)"), end="")
448 else:
449 print("%-9s " % ("TIME(s)"), end="")
450print(header_string % ("SKADDR", "C-PID", "C-COMM",
451 "IP" if args.wide or args.csv else "",
452 "LADDR", "LPORT", "RADDR", "RPORT",
453 "OLDSTATE", "NEWSTATE", "MS"))
454
455start_ts = 0
456
457# read events
458b["ipv4_events"].open_perf_buffer(print_ipv4_event, page_cnt=64)
459b["ipv6_events"].open_perf_buffer(print_ipv6_event, page_cnt=64)
460while 1:
Jerome Marchand51671272018-12-19 01:57:24 +0100461 try:
462 b.perf_buffer_poll()
463 except KeyboardInterrupt:
464 exit()