Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize: replace c arithmetic operators with bitwise ones #628

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions control/kern/tproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ static __always_inline __u8 ipv4_get_dscp(const struct iphdr *iph)

static __always_inline __u8 ipv6_get_dscp(const struct ipv6hdr *ipv6h)
{
return (ipv6h->priority << 2) + (ipv6h->flow_lbl[0] >> 6);
return (ipv6h->priority << 2) | (ipv6h->flow_lbl[0] >> 6);
}

static __always_inline void
Expand Down Expand Up @@ -1112,9 +1112,9 @@ int tproxy_lan_ingress(struct __sk_buff *skb)
__be32 mac[4] = {
0,
0,
bpf_htonl((ethh.h_source[0] << 8) + (ethh.h_source[1])),
bpf_htonl((ethh.h_source[2] << 24) + (ethh.h_source[3] << 16) +
(ethh.h_source[4] << 8) + (ethh.h_source[5])),
bpf_htonl((ethh.h_source[0] << 8) | (ethh.h_source[1])),
bpf_htonl((ethh.h_source[2] << 24) | (ethh.h_source[3] << 16) |
(ethh.h_source[4] << 8) | (ethh.h_source[5])),
};
__s64 s64_ret;

Expand Down Expand Up @@ -1405,11 +1405,11 @@ int tproxy_wan_egress(struct __sk_buff *skb)
__be32 mac[4] = {
0,
0,
bpf_htonl((ethh.h_source[0] << 8) +
bpf_htonl((ethh.h_source[0] << 8) |
(ethh.h_source[1])),
bpf_htonl((ethh.h_source[2] << 24) +
(ethh.h_source[3] << 16) +
(ethh.h_source[4] << 8) +
bpf_htonl((ethh.h_source[2] << 24) |
(ethh.h_source[3] << 16) |
(ethh.h_source[4] << 8) |
(ethh.h_source[5])),
};
__s64 s64_ret;
Expand Down Expand Up @@ -1532,10 +1532,10 @@ int tproxy_wan_egress(struct __sk_buff *skb)
__be32 mac[4] = {
0,
0,
bpf_htonl((ethh.h_source[0] << 8) + (ethh.h_source[1])),
bpf_htonl((ethh.h_source[2] << 24) +
(ethh.h_source[3] << 16) +
(ethh.h_source[4] << 8) + (ethh.h_source[5])),
bpf_htonl((ethh.h_source[0] << 8) | (ethh.h_source[1])),
bpf_htonl((ethh.h_source[2] << 24) |
(ethh.h_source[3] << 16) |
(ethh.h_source[4] << 8) | (ethh.h_source[5])),
};
__s64 s64_ret;

Expand Down
Loading