Skip to content

Commit 64c2a69

Browse files
committed
chore: format
1 parent 09f766b commit 64c2a69

File tree

15 files changed

+87
-210
lines changed

15 files changed

+87
-210
lines changed

.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ IndentWidth: 2
44
ContinuationIndentWidth: 2
55
ColumnLimit: 100
66
AttributeMacros: [br_unlikely, br_likely, fallthrough]
7+
AllowShortCaseLabelsOnASingleLine: true

bpf/egress.c

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,10 @@ static inline int mangle_data(struct __sk_buff* skb, __u16 offset, __be32* csum_
3838
((__u32*)buf)[i] = bpf_get_prandom_u32();
3939
// HACK: prevent usage of __builtin_memset against variable size
4040
switch (padding_len % 4) {
41-
case 1:
42-
buf[padding_len + 2] = 0;
43-
fallthrough;
44-
case 2:
45-
buf[padding_len + 1] = 0;
46-
fallthrough;
47-
case 3:
48-
buf[padding_len + 0] = 0;
49-
fallthrough;
50-
default:
51-
break;
41+
case 1: buf[padding_len + 2] = 0; fallthrough;
42+
case 2: buf[padding_len + 1] = 0; fallthrough;
43+
case 3: buf[padding_len + 0] = 0; fallthrough;
44+
default: break;
5245
}
5346
*csum_diff = bpf_csum_diff(NULL, 0, (__be32*)buf, round_to_mul(padding_len, 4), *csum_diff);
5447
try_shot(bpf_skb_store_bytes(skb, offset + TCP_UDP_HEADER_DIFF, buf, padding_len, 0));
@@ -81,32 +74,24 @@ int egress_handler(struct __sk_buff* skb) {
8174
decl_ok(struct ethhdr, eth, 0, skb);
8275
__u16 eth_proto = ntohs(eth->h_proto);
8376
switch (eth_proto) {
84-
case ETH_P_IP:
85-
redecl_shot(struct iphdr, ipv4, l2_end, skb);
86-
break;
87-
case ETH_P_IPV6:
88-
redecl_shot(struct ipv6hdr, ipv6, l2_end, skb);
89-
break;
90-
default:
91-
return TC_ACT_OK;
77+
case ETH_P_IP: redecl_shot(struct iphdr, ipv4, l2_end, skb); break;
78+
case ETH_P_IPV6: redecl_shot(struct ipv6hdr, ipv6, l2_end, skb); break;
79+
default: return TC_ACT_OK;
9280
}
9381
break;
9482
case LINK_NONE:
9583
l2_end = 0;
9684
redecl_ok(struct iphdr, ipv4, l2_end, skb);
9785
switch (ipv4->version) {
98-
case 4:
99-
break;
86+
case 4: break;
10087
case 6:
10188
ipv4 = NULL;
10289
redecl_ok(struct ipv6hdr, ipv6, 0, skb);
10390
break;
104-
default:
105-
return TC_ACT_OK;
91+
default: return TC_ACT_OK;
10692
}
10793
break;
108-
default:
109-
return TC_ACT_SHOT;
94+
default: return TC_ACT_SHOT;
11095
}
11196

11297
if (ipv4) {

bpf/ingress.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,32 +122,24 @@ int ingress_handler(struct xdp_md* xdp) {
122122
decl_pass(struct ethhdr, eth, 0, xdp);
123123
__u16 eth_proto = ntohs(eth->h_proto);
124124
switch (eth_proto) {
125-
case ETH_P_IP:
126-
redecl_drop(struct iphdr, ipv4, l2_end, xdp);
127-
break;
128-
case ETH_P_IPV6:
129-
redecl_drop(struct ipv6hdr, ipv6, l2_end, xdp);
130-
break;
131-
default:
132-
return XDP_PASS;
125+
case ETH_P_IP: redecl_drop(struct iphdr, ipv4, l2_end, xdp); break;
126+
case ETH_P_IPV6: redecl_drop(struct ipv6hdr, ipv6, l2_end, xdp); break;
127+
default: return XDP_PASS;
133128
}
134129
break;
135130
case LINK_NONE:
136131
l2_end = 0;
137132
redecl_pass(struct iphdr, ipv4, l2_end, xdp);
138133
switch (ipv4->version) {
139-
case 4:
140-
break;
134+
case 4: break;
141135
case 6:
142136
ipv4 = NULL;
143137
redecl_pass(struct ipv6hdr, ipv6, 0, xdp);
144138
break;
145-
default:
146-
return XDP_DROP;
139+
default: return XDP_DROP;
147140
}
148141
break;
149-
default:
150-
return XDP_DROP;
142+
default: return XDP_DROP;
151143
}
152144

153145
if (ipv4) {

bpf/main.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,8 @@ static inline bool ipv6_is_ext(__u8 nexthdr) {
153153
case IPPROTO_ROUTING:
154154
case IPPROTO_FRAGMENT:
155155
case IPPROTO_DSTOPTS:
156-
case IPPROTO_MH:
157-
return true;
158-
default:
159-
return false;
156+
case IPPROTO_MH: return true;
157+
default: return false;
160158
}
161159
}
162160

common/defs.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,10 @@ enum link_type {
320320

321321
static inline const char* link_type_str(enum link_type link) {
322322
switch (link) {
323-
case LINK_ETH:
324-
return "eth";
325-
case LINK_NONE:
326-
return "none";
323+
case LINK_ETH: return "eth";
324+
case LINK_NONE: return "none";
327325
case LINK_UNKNOWN:
328-
default:
329-
return "(unknown)";
326+
default: return "(unknown)";
330327
}
331328
}
332329

src/args.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,8 @@ static inline error_t args_parse_opt(int key, char* arg, struct argp_state* stat
6060
log_error(_("unknown command '%s'"), arg);
6161
exit(1);
6262
break;
63-
case ARGP_KEY_NO_ARGS:
64-
argp_usage(state);
65-
break;
66-
default:
67-
return ARGP_ERR_UNKNOWN;
63+
case ARGP_KEY_NO_ARGS: argp_usage(state); break;
64+
default: return ARGP_ERR_UNKNOWN;
6865
}
6966
return 0;
7067
}
@@ -100,10 +97,7 @@ void filter_list_destroy(struct filter_list* list) {
10097
void args_destroy(struct args* args) {
10198
switch (args->cmd) {
10299
case CMD_NULL:
103-
case CMD_SHOW:
104-
break;
105-
case CMD_RUN:
106-
filter_list_destroy(&args->run.filters);
107-
break;
100+
case CMD_SHOW: break;
101+
case CMD_RUN: filter_list_destroy(&args->run.filters); break;
108102
}
109103
}

src/config.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020
static inline bool is_whitespace(char c) {
2121
switch (c) {
2222
case '\t' ... '\r':
23-
case ' ':
24-
return true;
25-
default:
26-
return false;
23+
case ' ': return true;
24+
default: return false;
2725
}
2826
}
2927

src/libxdp.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111
#include "common/log.h"
1212
#include "libxdp.h"
1313

14-
static void *libxdp_dl = NULL;
14+
static void* libxdp_dl = NULL;
1515

1616
DLSYM_PROTOTYPE(libxdp_set_print) = NULL;
1717
DLSYM_PROTOTYPE(xdp_program__from_bpf_obj) = NULL;
1818
DLSYM_PROTOTYPE(xdp_program__attach) = NULL;
1919
DLSYM_PROTOTYPE(xdp_program__detach) = NULL;
2020
DLSYM_PROTOTYPE(xdp_program__close) = NULL;
2121

22-
static int dlsym_many_or_warnv(void *dl, va_list ap) {
22+
static int dlsym_many_or_warnv(void* dl, va_list ap) {
2323
void (**fn)(void);
2424

2525
while ((fn = va_arg(ap, typeof(fn)))) {
26-
const char *symbol = va_arg(ap, typeof(symbol));
26+
const char* symbol = va_arg(ap, typeof(symbol));
2727
void (*tfn)(void) = dlsym(dl, symbol);
2828
if (!tfn) {
2929
log_warn(_("cannot find symbol '%s': %s"), symbol, dlerror());
@@ -35,11 +35,11 @@ static int dlsym_many_or_warnv(void *dl, va_list ap) {
3535
return 0;
3636
}
3737

38-
static int dlopen_many_sym_or_warn_sentinel(void **dlp, const char *filename, ...) {
38+
static int dlopen_many_sym_or_warn_sentinel(void** dlp, const char* filename, ...) {
3939
int retcode;
4040
if (*dlp) return 0;
4141

42-
void *dl = dlopen(filename, RTLD_NOW | RTLD_NODELETE);
42+
void* dl = dlopen(filename, RTLD_NOW | RTLD_NODELETE);
4343
if (!dl) {
4444
log_warn(_("%s is not installed: %s"), filename, dlerror());
4545
return -EOPNOTSUPP;

src/log.c

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,11 @@ void log_destroy(enum log_level level, struct conn_tuple* conn, enum destroy_typ
6262
__u32 cooldown) {
6363
const char* reason;
6464
switch (type) {
65-
case DESTROY_RECV_RST:
66-
reason = _("received RST");
67-
break;
68-
case DESTROY_RECV_FIN:
69-
reason = _("received FIN");
70-
break;
71-
case DESTROY_TIMED_OUT:
72-
reason = _("timed out");
73-
break;
74-
case DESTROY_INVALID:
75-
reason = _("invalid TCP state");
76-
break;
77-
default:
78-
reason = _("unknown");
79-
break;
65+
case DESTROY_RECV_RST: reason = _("received RST"); break;
66+
case DESTROY_RECV_FIN: reason = _("received FIN"); break;
67+
case DESTROY_TIMED_OUT: reason = _("timed out"); break;
68+
case DESTROY_INVALID: reason = _("invalid TCP state"); break;
69+
default: reason = _("unknown"); break;
8070
}
8171
if (cooldown)
8272
log_conn(level, conn, _("connection destroyed (%s), retry in %u seconds"), reason, cooldown);
@@ -121,15 +111,9 @@ int libbpf_print_fn(enum libbpf_print_level bpf_level, const char* format, va_li
121111
(bpf_level == LIBBPF_DEBUG && LOG_ALLOW_TRACE)) {
122112
int level;
123113
switch (bpf_level) {
124-
case LIBBPF_WARN:
125-
level = LOG_WARN;
126-
break;
127-
case LIBBPF_INFO:
128-
level = LOG_INFO;
129-
break;
130-
case LIBBPF_DEBUG:
131-
level = LOG_TRACE;
132-
break;
114+
case LIBBPF_WARN: level = LOG_WARN; break;
115+
case LIBBPF_INFO: level = LOG_INFO; break;
116+
case LIBBPF_DEBUG: level = LOG_TRACE; break;
133117
}
134118
ret = fprintf(stderr, "%s%s " RESET, log_prefixes[level][0], gettext(log_prefixes[level][1]));
135119
if (level >= LOG_TRACE) ret = ret < 0 ? ret : fprintf(stderr, GRAY);
@@ -144,14 +128,10 @@ int libbpf_print_fn(enum libbpf_print_level bpf_level, const char* format, va_li
144128

145129
static inline const char* log_type_to_str(enum log_type type) {
146130
switch (type) {
147-
case LOG_CONN_INIT:
148-
return _("initializing connection");
149-
case LOG_CONN_ACCEPT:
150-
return _("accepting connection");
151-
case LOG_CONN_ESTABLISH:
152-
return _("connection established");
153-
default:
154-
return "";
131+
case LOG_CONN_INIT: return _("initializing connection");
132+
case LOG_CONN_ACCEPT: return _("accepting connection");
133+
case LOG_CONN_ESTABLISH: return _("connection established");
134+
default: return "";
155135
}
156136
}
157137

@@ -168,9 +148,7 @@ int handle_log_event(struct log_event* e) {
168148
case LOG_CONN_DESTROY:
169149
log_destroy(e->level, &e->info.conn, e->info.destroy_type, e->info.cooldown);
170150
break;
171-
default:
172-
log_conn(e->level, &e->info.conn, "%s", log_type_to_str(e->type));
173-
break;
151+
default: log_conn(e->level, &e->info.conn, "%s", log_type_to_str(e->type)); break;
174152
}
175153
}
176154
return 0;

src/log.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
void log_conn(int level, struct conn_tuple* conn, const char* fmt, ...);
1212
void log_tcp(enum log_level level, struct conn_tuple* conn, struct tcphdr* tcp, __u16 len);
13-
void log_destroy(enum log_level level, struct conn_tuple* conn, enum destroy_type type, __u32 cooldown);
13+
void log_destroy(enum log_level level, struct conn_tuple* conn, enum destroy_type type,
14+
__u32 cooldown);
1415

1516
int libbpf_print_fn(enum libbpf_print_level level, const char* format, va_list args);
1617
int handle_log_event(struct log_event* e);

0 commit comments

Comments
 (0)