Skip to content

Commit

Permalink
OCPBUGS-48838: replace bpf_probe_read by bpf_probe_read_kernel()
Browse files Browse the repository at this point in the history
Because its not avaliable on s390x arch

Signed-off-by: Mohamed Mahmoud <[email protected]>
  • Loading branch information
msherif1234 committed Jan 24, 2025
1 parent f8b36f1 commit 3512dc6
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 23 deletions.
4 changes: 2 additions & 2 deletions bpf/network_events_monitoring.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static inline int lookup_and_update_existing_flow_network_events(flow_id *id, u8
u8 *user_cookie) {
u8 cookie[MAX_EVENT_MD];

bpf_probe_read(cookie, md_len, user_cookie);
bpf_probe_read_kernel(cookie, md_len, user_cookie);

additional_metrics *extra_metrics = bpf_map_lookup_elem(&additional_flow_metrics, id);
if (extra_metrics != NULL) {
Expand Down Expand Up @@ -112,7 +112,7 @@ static inline int trace_network_events(struct sk_buff *skb, struct rh_psample_me
.eth_protocol = eth_protocol,
.network_events_idx = 0,
};
bpf_probe_read(new_flow.network_events[0], md_len, user_cookie);
bpf_probe_read_kernel(new_flow.network_events[0], md_len, user_cookie);
new_flow.network_events_idx++;
ret = bpf_map_update_elem(&additional_flow_metrics, &id, &new_flow, BPF_NOEXIST);
if (ret != 0) {
Expand Down
2 changes: 1 addition & 1 deletion bpf/pkt_drops.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ int kfree_skb(struct trace_event_raw_kfree_skb *args) {
u8 state = 0;
if (sk) {
// pull in details from the packet headers and the sock struct
bpf_probe_read(&state, sizeof(u8), (u8 *)&sk->__sk_common.skc_state);
bpf_probe_read_kernel(&state, sizeof(u8), (u8 *)&sk->__sk_common.skc_state);
}
return trace_pkt_drop(args, state, skb, reason);
}
Expand Down
24 changes: 12 additions & 12 deletions bpf/pkt_translation.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ static void __always_inline parse_tuple(struct nf_conntrack_tuple *t,
case AF_INET:
__builtin_memcpy(flow->saddr, ip4in6, sizeof(ip4in6));
__builtin_memcpy(flow->daddr, ip4in6, sizeof(ip4in6));
bpf_probe_read(flow->daddr + sizeof(ip4in6), sizeof(u32), &t->src.u3.in.s_addr);
bpf_probe_read(flow->saddr + sizeof(ip4in6), sizeof(u32), &t->dst.u3.in.s_addr);
bpf_probe_read_kernel(flow->daddr + sizeof(ip4in6), sizeof(u32), &t->src.u3.in.s_addr);
bpf_probe_read_kernel(flow->saddr + sizeof(ip4in6), sizeof(u32), &t->dst.u3.in.s_addr);
break;

case AF_INET6:
bpf_probe_read(flow->daddr, IP_MAX_LEN, &t->src.u3.in6.s6_addr);
bpf_probe_read(flow->saddr, IP_MAX_LEN, &t->dst.u3.in6.s6_addr);
bpf_probe_read_kernel(flow->daddr, IP_MAX_LEN, &t->src.u3.in6.s6_addr);
bpf_probe_read_kernel(flow->saddr, IP_MAX_LEN, &t->dst.u3.in6.s6_addr);
break;
}
} else {
Expand All @@ -55,13 +55,13 @@ static void __always_inline parse_tuple(struct nf_conntrack_tuple *t,
case AF_INET:
__builtin_memcpy(flow->saddr, ip4in6, sizeof(ip4in6));
__builtin_memcpy(flow->daddr, ip4in6, sizeof(ip4in6));
bpf_probe_read(flow->daddr + sizeof(ip4in6), sizeof(u32), &t->dst.u3.in.s_addr);
bpf_probe_read(flow->saddr + sizeof(ip4in6), sizeof(u32), &t->src.u3.in.s_addr);
bpf_probe_read_kernel(flow->daddr + sizeof(ip4in6), sizeof(u32), &t->dst.u3.in.s_addr);
bpf_probe_read_kernel(flow->saddr + sizeof(ip4in6), sizeof(u32), &t->src.u3.in.s_addr);
break;

case AF_INET6:
bpf_probe_read(flow->daddr, IP_MAX_LEN, &t->dst.u3.in6.s6_addr);
bpf_probe_read(flow->saddr, IP_MAX_LEN, &t->src.u3.in6.s6_addr);
bpf_probe_read_kernel(flow->daddr, IP_MAX_LEN, &t->dst.u3.in6.s6_addr);
bpf_probe_read_kernel(flow->saddr, IP_MAX_LEN, &t->src.u3.in6.s6_addr);
break;
}
}
Expand Down Expand Up @@ -133,10 +133,10 @@ static inline int trace_nat_manip_pkt(struct nf_conn *ct, struct sk_buff *skb) {
}
__builtin_memset(&id, 0, sizeof(id));

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

bpf_probe_read(&zone_id, sizeof(zone_id), &ct->zone.id);
bpf_probe_read(&zone_id, sizeof(zone_id), &ct->zone.id);
bpf_probe_read_kernel(&zone_id, sizeof(zone_id), &ct->zone.id);
bpf_probe_read_kernel(&zone_id, sizeof(zone_id), &ct->zone.id);

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

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

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

Expand Down
18 changes: 10 additions & 8 deletions bpf/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ static inline void core_fill_in_l2(struct sk_buff *skb, u16 *eth_protocol, u16 *
u8 *skb_head = BPF_CORE_READ(skb, head);
u16 skb_mac_header = BPF_CORE_READ(skb, mac_header);

bpf_probe_read(&eth, sizeof(eth), (struct ethhdr *)(skb_head + skb_mac_header));
bpf_probe_read_kernel(&eth, sizeof(eth), (struct ethhdr *)(skb_head + skb_mac_header));
*eth_protocol = bpf_ntohs(eth.h_proto);
if (*eth_protocol == ETH_P_IP) {
*family = AF_INET;
Expand All @@ -257,7 +257,7 @@ static inline void core_fill_in_l3(struct sk_buff *skb, flow_id *id, u16 family,
case AF_INET: {
struct iphdr ip;
__builtin_memset(&ip, 0, sizeof(ip));
bpf_probe_read(&ip, sizeof(ip), (struct iphdr *)(skb_head + skb_network_header));
bpf_probe_read_kernel(&ip, sizeof(ip), (struct iphdr *)(skb_head + skb_network_header));
__builtin_memcpy(id->src_ip, ip4in6, sizeof(ip4in6));
__builtin_memcpy(id->dst_ip, ip4in6, sizeof(ip4in6));
__builtin_memcpy(id->src_ip + sizeof(ip4in6), &ip.saddr, sizeof(ip.saddr));
Expand All @@ -269,7 +269,7 @@ static inline void core_fill_in_l3(struct sk_buff *skb, flow_id *id, u16 family,
case AF_INET6: {
struct ipv6hdr ip;
__builtin_memset(&ip, 0, sizeof(ip));
bpf_probe_read(&ip, sizeof(ip), (struct ipv6hdr *)(skb_head + skb_network_header));
bpf_probe_read_kernel(&ip, sizeof(ip), (struct ipv6hdr *)(skb_head + skb_network_header));
__builtin_memcpy(id->src_ip, ip.saddr.in6_u.u6_addr8, IP_MAX_LEN);
__builtin_memcpy(id->dst_ip, ip.daddr.in6_u.u6_addr8, IP_MAX_LEN);
*dscp = ipv6_get_dscp(&ip);
Expand All @@ -289,7 +289,7 @@ static inline void core_fill_in_tcp(struct sk_buff *skb, flow_id *id, u16 *flags

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

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

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

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

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

bpf_probe_read(&sctp, sizeof(sctp), (struct sctphdr *)(skb_head + skb_transport_header));
bpf_probe_read_kernel(&sctp, sizeof(sctp), (struct sctphdr *)(skb_head + skb_transport_header));
sport = bpf_ntohs(sctp.source);
dport = bpf_ntohs(sctp.dest);
id->src_port = sport;
Expand All @@ -336,7 +336,8 @@ static inline void core_fill_in_icmpv4(struct sk_buff *skb, flow_id *id) {
struct icmphdr icmph;
__builtin_memset(&icmph, 0, sizeof(icmph));

bpf_probe_read(&icmph, sizeof(icmph), (struct icmphdr *)(skb_head + skb_transport_header));
bpf_probe_read_kernel(&icmph, sizeof(icmph),
(struct icmphdr *)(skb_head + skb_transport_header));
id->icmp_type = icmph.type;
id->icmp_code = icmph.code;
id->transport_protocol = IPPROTO_ICMP;
Expand All @@ -348,7 +349,8 @@ static inline void core_fill_in_icmpv6(struct sk_buff *skb, flow_id *id) {
struct icmp6hdr icmph;
__builtin_memset(&icmph, 0, sizeof(icmph));

bpf_probe_read(&icmph, sizeof(icmph), (struct icmp6hdr *)(skb_head + skb_transport_header));
bpf_probe_read_kernel(&icmph, sizeof(icmph),
(struct icmp6hdr *)(skb_head + skb_transport_header));
id->icmp_type = icmph.icmp6_type;
id->icmp_code = icmph.icmp6_code;
id->transport_protocol = IPPROTO_ICMPV6;
Expand Down
Binary file modified pkg/ebpf/bpf_arm64_bpfel.o
Binary file not shown.
Binary file modified pkg/ebpf/bpf_powerpc_bpfel.o
Binary file not shown.
Binary file modified pkg/ebpf/bpf_s390_bpfeb.o
Binary file not shown.
Binary file modified pkg/ebpf/bpf_x86_bpfel.o
Binary file not shown.

0 comments on commit 3512dc6

Please sign in to comment.