Skip to content

Commit 7ab0c5b

Browse files
authored
OCPBUGS-48838: replace bpf_probe_read by bpf_probe_read_kernel() (#523)
Because its not avaliable on s390x arch Signed-off-by: Mohamed Mahmoud <[email protected]>
1 parent a61144f commit 7ab0c5b

File tree

8 files changed

+25
-23
lines changed

8 files changed

+25
-23
lines changed

bpf/network_events_monitoring.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static inline int lookup_and_update_existing_flow_network_events(flow_id *id, u8
3333
u8 *user_cookie) {
3434
u8 cookie[MAX_EVENT_MD];
3535

36-
bpf_probe_read(cookie, md_len, user_cookie);
36+
bpf_probe_read_kernel(cookie, md_len, user_cookie);
3737

3838
additional_metrics *extra_metrics = bpf_map_lookup_elem(&additional_flow_metrics, id);
3939
if (extra_metrics != NULL) {
@@ -112,7 +112,7 @@ static inline int trace_network_events(struct sk_buff *skb, struct rh_psample_me
112112
.eth_protocol = eth_protocol,
113113
.network_events_idx = 0,
114114
};
115-
bpf_probe_read(new_flow.network_events[0], md_len, user_cookie);
115+
bpf_probe_read_kernel(new_flow.network_events[0], md_len, user_cookie);
116116
new_flow.network_events_idx++;
117117
ret = bpf_map_update_elem(&additional_flow_metrics, &id, &new_flow, BPF_NOEXIST);
118118
if (ret != 0) {

bpf/pkt_drops.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ int kfree_skb(struct trace_event_raw_kfree_skb *args) {
118118
u8 state = 0;
119119
if (sk) {
120120
// pull in details from the packet headers and the sock struct
121-
bpf_probe_read(&state, sizeof(u8), (u8 *)&sk->__sk_common.skc_state);
121+
bpf_probe_read_kernel(&state, sizeof(u8), (u8 *)&sk->__sk_common.skc_state);
122122
}
123123
return trace_pkt_drop(args, state, skb, reason);
124124
}

bpf/pkt_translation.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ static void __always_inline parse_tuple(struct nf_conntrack_tuple *t,
3636
case AF_INET:
3737
__builtin_memcpy(flow->saddr, ip4in6, sizeof(ip4in6));
3838
__builtin_memcpy(flow->daddr, ip4in6, sizeof(ip4in6));
39-
bpf_probe_read(flow->daddr + sizeof(ip4in6), sizeof(u32), &t->src.u3.in.s_addr);
40-
bpf_probe_read(flow->saddr + sizeof(ip4in6), sizeof(u32), &t->dst.u3.in.s_addr);
39+
bpf_probe_read_kernel(flow->daddr + sizeof(ip4in6), sizeof(u32), &t->src.u3.in.s_addr);
40+
bpf_probe_read_kernel(flow->saddr + sizeof(ip4in6), sizeof(u32), &t->dst.u3.in.s_addr);
4141
break;
4242

4343
case AF_INET6:
44-
bpf_probe_read(flow->daddr, IP_MAX_LEN, &t->src.u3.in6.s6_addr);
45-
bpf_probe_read(flow->saddr, IP_MAX_LEN, &t->dst.u3.in6.s6_addr);
44+
bpf_probe_read_kernel(flow->daddr, IP_MAX_LEN, &t->src.u3.in6.s6_addr);
45+
bpf_probe_read_kernel(flow->saddr, IP_MAX_LEN, &t->dst.u3.in6.s6_addr);
4646
break;
4747
}
4848
} else {
@@ -55,13 +55,13 @@ static void __always_inline parse_tuple(struct nf_conntrack_tuple *t,
5555
case AF_INET:
5656
__builtin_memcpy(flow->saddr, ip4in6, sizeof(ip4in6));
5757
__builtin_memcpy(flow->daddr, ip4in6, sizeof(ip4in6));
58-
bpf_probe_read(flow->daddr + sizeof(ip4in6), sizeof(u32), &t->dst.u3.in.s_addr);
59-
bpf_probe_read(flow->saddr + sizeof(ip4in6), sizeof(u32), &t->src.u3.in.s_addr);
58+
bpf_probe_read_kernel(flow->daddr + sizeof(ip4in6), sizeof(u32), &t->dst.u3.in.s_addr);
59+
bpf_probe_read_kernel(flow->saddr + sizeof(ip4in6), sizeof(u32), &t->src.u3.in.s_addr);
6060
break;
6161

6262
case AF_INET6:
63-
bpf_probe_read(flow->daddr, IP_MAX_LEN, &t->dst.u3.in6.s6_addr);
64-
bpf_probe_read(flow->saddr, IP_MAX_LEN, &t->src.u3.in6.s6_addr);
63+
bpf_probe_read_kernel(flow->daddr, IP_MAX_LEN, &t->dst.u3.in6.s6_addr);
64+
bpf_probe_read_kernel(flow->saddr, IP_MAX_LEN, &t->src.u3.in6.s6_addr);
6565
break;
6666
}
6767
}
@@ -133,10 +133,10 @@ static inline int trace_nat_manip_pkt(struct nf_conn *ct, struct sk_buff *skb) {
133133
}
134134
__builtin_memset(&id, 0, sizeof(id));
135135

136-
bpf_probe_read(&tuplehash, sizeof(tuplehash), &ct->tuplehash);
136+
bpf_probe_read_kernel(&tuplehash, sizeof(tuplehash), &ct->tuplehash);
137137

138-
bpf_probe_read(&zone_id, sizeof(zone_id), &ct->zone.id);
139-
bpf_probe_read(&zone_id, sizeof(zone_id), &ct->zone.id);
138+
bpf_probe_read_kernel(&zone_id, sizeof(zone_id), &ct->zone.id);
139+
bpf_probe_read_kernel(&zone_id, sizeof(zone_id), &ct->zone.id);
140140

141141
struct nf_conntrack_tuple *orig_tuple = &tuplehash[IP_CT_DIR_ORIGINAL].tuple;
142142
struct nf_conntrack_tuple *reply_tuple = &tuplehash[IP_CT_DIR_REPLY].tuple;
@@ -176,7 +176,7 @@ static inline int trace_nat_manip_pkt(struct nf_conn *ct, struct sk_buff *skb) {
176176

177177
BPF_PRINTK("Xlat: protocol %d flags 0x%x family %d dscp %d\n", protocol, flags, family, dscp);
178178

179-
bpf_probe_read(&zone_id, sizeof(zone_id), &ct->zone.id);
179+
bpf_probe_read_kernel(&zone_id, sizeof(zone_id), &ct->zone.id);
180180
ret = translate_lookup_and_update_flow(&id, flags, orig_tuple, reply_tuple, zone_id, family,
181181
eth_protocol);
182182

bpf/utils.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ static inline void core_fill_in_l2(struct sk_buff *skb, u16 *eth_protocol, u16 *
231231
u8 *skb_head = BPF_CORE_READ(skb, head);
232232
u16 skb_mac_header = BPF_CORE_READ(skb, mac_header);
233233

234-
bpf_probe_read(&eth, sizeof(eth), (struct ethhdr *)(skb_head + skb_mac_header));
234+
bpf_probe_read_kernel(&eth, sizeof(eth), (struct ethhdr *)(skb_head + skb_mac_header));
235235
*eth_protocol = bpf_ntohs(eth.h_proto);
236236
if (*eth_protocol == ETH_P_IP) {
237237
*family = AF_INET;
@@ -249,7 +249,7 @@ static inline void core_fill_in_l3(struct sk_buff *skb, flow_id *id, u16 family,
249249
case AF_INET: {
250250
struct iphdr ip;
251251
__builtin_memset(&ip, 0, sizeof(ip));
252-
bpf_probe_read(&ip, sizeof(ip), (struct iphdr *)(skb_head + skb_network_header));
252+
bpf_probe_read_kernel(&ip, sizeof(ip), (struct iphdr *)(skb_head + skb_network_header));
253253
__builtin_memcpy(id->src_ip, ip4in6, sizeof(ip4in6));
254254
__builtin_memcpy(id->dst_ip, ip4in6, sizeof(ip4in6));
255255
__builtin_memcpy(id->src_ip + sizeof(ip4in6), &ip.saddr, sizeof(ip.saddr));
@@ -261,7 +261,7 @@ static inline void core_fill_in_l3(struct sk_buff *skb, flow_id *id, u16 family,
261261
case AF_INET6: {
262262
struct ipv6hdr ip;
263263
__builtin_memset(&ip, 0, sizeof(ip));
264-
bpf_probe_read(&ip, sizeof(ip), (struct ipv6hdr *)(skb_head + skb_network_header));
264+
bpf_probe_read_kernel(&ip, sizeof(ip), (struct ipv6hdr *)(skb_head + skb_network_header));
265265
__builtin_memcpy(id->src_ip, ip.saddr.in6_u.u6_addr8, IP_MAX_LEN);
266266
__builtin_memcpy(id->dst_ip, ip.daddr.in6_u.u6_addr8, IP_MAX_LEN);
267267
*dscp = ipv6_get_dscp(&ip);
@@ -281,7 +281,7 @@ static inline void core_fill_in_tcp(struct sk_buff *skb, flow_id *id, u16 *flags
281281

282282
__builtin_memset(&tcp, 0, sizeof(tcp));
283283

284-
bpf_probe_read(&tcp, sizeof(tcp), (struct tcphdr *)(skb_head + skb_transport_header));
284+
bpf_probe_read_kernel(&tcp, sizeof(tcp), (struct tcphdr *)(skb_head + skb_transport_header));
285285
sport = bpf_ntohs(tcp.source);
286286
dport = bpf_ntohs(tcp.dest);
287287
id->src_port = sport;
@@ -298,7 +298,7 @@ static inline void core_fill_in_udp(struct sk_buff *skb, flow_id *id) {
298298

299299
__builtin_memset(&udp, 0, sizeof(udp));
300300

301-
bpf_probe_read(&udp, sizeof(udp), (struct udphdr *)(skb_head + skb_transport_header));
301+
bpf_probe_read_kernel(&udp, sizeof(udp), (struct udphdr *)(skb_head + skb_transport_header));
302302
sport = bpf_ntohs(udp.source);
303303
dport = bpf_ntohs(udp.dest);
304304
id->src_port = sport;
@@ -314,7 +314,7 @@ static inline void core_fill_in_sctp(struct sk_buff *skb, flow_id *id) {
314314

315315
__builtin_memset(&sctp, 0, sizeof(sctp));
316316

317-
bpf_probe_read(&sctp, sizeof(sctp), (struct sctphdr *)(skb_head + skb_transport_header));
317+
bpf_probe_read_kernel(&sctp, sizeof(sctp), (struct sctphdr *)(skb_head + skb_transport_header));
318318
sport = bpf_ntohs(sctp.source);
319319
dport = bpf_ntohs(sctp.dest);
320320
id->src_port = sport;
@@ -328,7 +328,8 @@ static inline void core_fill_in_icmpv4(struct sk_buff *skb, flow_id *id) {
328328
struct icmphdr icmph;
329329
__builtin_memset(&icmph, 0, sizeof(icmph));
330330

331-
bpf_probe_read(&icmph, sizeof(icmph), (struct icmphdr *)(skb_head + skb_transport_header));
331+
bpf_probe_read_kernel(&icmph, sizeof(icmph),
332+
(struct icmphdr *)(skb_head + skb_transport_header));
332333
id->icmp_type = icmph.type;
333334
id->icmp_code = icmph.code;
334335
id->transport_protocol = IPPROTO_ICMP;
@@ -340,7 +341,8 @@ static inline void core_fill_in_icmpv6(struct sk_buff *skb, flow_id *id) {
340341
struct icmp6hdr icmph;
341342
__builtin_memset(&icmph, 0, sizeof(icmph));
342343

343-
bpf_probe_read(&icmph, sizeof(icmph), (struct icmp6hdr *)(skb_head + skb_transport_header));
344+
bpf_probe_read_kernel(&icmph, sizeof(icmph),
345+
(struct icmp6hdr *)(skb_head + skb_transport_header));
344346
id->icmp_type = icmph.icmp6_type;
345347
id->icmp_code = icmph.icmp6_code;
346348
id->transport_protocol = IPPROTO_ICMPV6;

pkg/ebpf/bpf_arm64_bpfel.o

152 Bytes
Binary file not shown.

pkg/ebpf/bpf_powerpc_bpfel.o

152 Bytes
Binary file not shown.

pkg/ebpf/bpf_s390_bpfeb.o

152 Bytes
Binary file not shown.

pkg/ebpf/bpf_x86_bpfel.o

152 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)