dscpPolicy.c - old/new_first_u32 is actually be32
Test: TreeHugger Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I10b19a010000f1f49c2a48448f413376045bfe1f
This commit is contained in:
parent
56dca4119a
commit
242af39425
1 changed files with 8 additions and 8 deletions
|
|
@ -62,8 +62,8 @@ static inline __always_inline void match_policy(struct __sk_buff* skb, bool ipv4
|
|||
uint8_t protocol = 0; // TODO: Use are reserved value? Or int (-1) and cast to uint below?
|
||||
struct in6_addr src_ip = {};
|
||||
struct in6_addr dst_ip = {};
|
||||
uint8_t tos = 0; // Only used for IPv4
|
||||
uint32_t old_first_u32 = 0; // Only used for IPv6
|
||||
uint8_t tos = 0; // Only used for IPv4
|
||||
__be32 old_first_be32 = 0; // Only used for IPv6
|
||||
if (ipv4) {
|
||||
const struct iphdr* const iph = (void*)(eth + 1);
|
||||
hdr_size = l2_header_size + sizeof(struct iphdr);
|
||||
|
|
@ -96,7 +96,7 @@ static inline __always_inline void match_policy(struct __sk_buff* skb, bool ipv4
|
|||
src_ip = ip6h->saddr;
|
||||
dst_ip = ip6h->daddr;
|
||||
protocol = ip6h->nexthdr;
|
||||
old_first_u32 = *(uint32_t*)ip6h;
|
||||
old_first_be32 = *(__be32*)ip6h;
|
||||
}
|
||||
|
||||
switch (protocol) {
|
||||
|
|
@ -135,9 +135,9 @@ static inline __always_inline void match_policy(struct __sk_buff* skb, bool ipv4
|
|||
sizeof(uint16_t));
|
||||
bpf_skb_store_bytes(skb, IP4_OFFSET(tos, l2_header_size), &newTos, sizeof(newTos), 0);
|
||||
} else {
|
||||
uint32_t new_first_u32 =
|
||||
htonl(ntohl(old_first_u32) & 0xF03FFFFF | (existing_rule->dscp_val << 22));
|
||||
bpf_skb_store_bytes(skb, l2_header_size, &new_first_u32, sizeof(uint32_t),
|
||||
__be32 new_first_be32 =
|
||||
htonl(ntohl(old_first_be32) & 0xF03FFFFF | (existing_rule->dscp_val << 22));
|
||||
bpf_skb_store_bytes(skb, l2_header_size, &new_first_be32, sizeof(__be32),
|
||||
BPF_F_RECOMPUTE_CSUM);
|
||||
}
|
||||
return;
|
||||
|
|
@ -214,8 +214,8 @@ static inline __always_inline void match_policy(struct __sk_buff* skb, bool ipv4
|
|||
bpf_l3_csum_replace(skb, IP4_OFFSET(check, l2_header_size), htons(tos), htons(new_tos), 2);
|
||||
bpf_skb_store_bytes(skb, IP4_OFFSET(tos, l2_header_size), &new_tos, sizeof(new_tos), 0);
|
||||
} else {
|
||||
uint32_t new_first_u32 = htonl(ntohl(old_first_u32) & 0xF03FFFFF | (new_dscp << 22));
|
||||
bpf_skb_store_bytes(skb, l2_header_size, &new_first_u32, sizeof(uint32_t),
|
||||
__be32 new_first_be32 = htonl(ntohl(old_first_be32) & 0xF03FFFFF | (new_dscp << 22));
|
||||
bpf_skb_store_bytes(skb, l2_header_size, &new_first_be32, sizeof(__be32),
|
||||
BPF_F_RECOMPUTE_CSUM);
|
||||
}
|
||||
return;
|
||||
|
|
|
|||
Loading…
Reference in a new issue