Merge "dscpPolicy - sport is network endian, dport is host endian"

This commit is contained in:
Maciej Żenczykowski
2022-08-10 11:35:47 +00:00
committed by Gerrit Code Review
2 changed files with 10 additions and 10 deletions

View File

@@ -57,7 +57,7 @@ static inline __always_inline void match_policy(struct __sk_buff* skb, bool ipv4
uint64_t cookie = bpf_get_socket_cookie(skb);
if (!cookie) return;
uint16_t sport = 0;
__be16 sport = 0;
uint16_t dport = 0;
uint8_t protocol = 0; // TODO: Use are reserved value? Or int (-1) and cast to uint below?
struct in6_addr src_ip = {};
@@ -106,14 +106,14 @@ static inline __always_inline void match_policy(struct __sk_buff* skb, bool ipv4
udp = data + hdr_size;
if ((void*)(udp + 1) > data_end) return;
sport = udp->source;
dport = udp->dest;
dport = ntohs(udp->dest);
} break;
case IPPROTO_TCP: {
struct tcphdr* tcp;
tcp = data + hdr_size;
if ((void*)(tcp + 1) > data_end) return;
sport = tcp->source;
dport = tcp->dest;
dport = ntohs(tcp->dest);
} break;
default:
return;
@@ -183,8 +183,8 @@ static inline __always_inline void match_policy(struct __sk_buff* skb, bool ipv4
if (sport != policy->src_port) continue;
score += 0xFFFF;
}
if (ntohs(dport) < policy->dst_port_start) continue;
if (ntohs(dport) > policy->dst_port_end) continue;
if (dport < policy->dst_port_start) continue;
if (dport > policy->dst_port_end) continue;
score += 0xFFFF + policy->dst_port_start - policy->dst_port_end;
if (score > best_score) {

View File

@@ -65,11 +65,11 @@ STRUCT_SIZE(DscpPolicy, 2 * 16 + 4 + 3 * 2 + 3 * 1 + 3); // 48
typedef struct {
struct in6_addr src_ip;
struct in6_addr dst_ip;
__u32 ifindex;
uint32_t ifindex;
__be16 src_port;
__be16 dst_port;
__u8 proto;
__s8 dscp_val; // -1 none, or 0..63 DSCP value
__u8 pad[2];
uint16_t dst_port;
uint8_t proto;
int8_t dscp_val; // -1 none, or 0..63 DSCP value
uint8_t pad[2];
} RuleEntry;
STRUCT_SIZE(RuleEntry, 2 * 16 + 1 * 4 + 2 * 2 + 2 * 1 + 2); // 44