Merge "dscpPolicy - sport is network endian, dport is host endian"
This commit is contained in:
@@ -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);
|
uint64_t cookie = bpf_get_socket_cookie(skb);
|
||||||
if (!cookie) return;
|
if (!cookie) return;
|
||||||
|
|
||||||
uint16_t sport = 0;
|
__be16 sport = 0;
|
||||||
uint16_t dport = 0;
|
uint16_t dport = 0;
|
||||||
uint8_t protocol = 0; // TODO: Use are reserved value? Or int (-1) and cast to uint below?
|
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 src_ip = {};
|
||||||
@@ -106,14 +106,14 @@ static inline __always_inline void match_policy(struct __sk_buff* skb, bool ipv4
|
|||||||
udp = data + hdr_size;
|
udp = data + hdr_size;
|
||||||
if ((void*)(udp + 1) > data_end) return;
|
if ((void*)(udp + 1) > data_end) return;
|
||||||
sport = udp->source;
|
sport = udp->source;
|
||||||
dport = udp->dest;
|
dport = ntohs(udp->dest);
|
||||||
} break;
|
} break;
|
||||||
case IPPROTO_TCP: {
|
case IPPROTO_TCP: {
|
||||||
struct tcphdr* tcp;
|
struct tcphdr* tcp;
|
||||||
tcp = data + hdr_size;
|
tcp = data + hdr_size;
|
||||||
if ((void*)(tcp + 1) > data_end) return;
|
if ((void*)(tcp + 1) > data_end) return;
|
||||||
sport = tcp->source;
|
sport = tcp->source;
|
||||||
dport = tcp->dest;
|
dport = ntohs(tcp->dest);
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
@@ -183,8 +183,8 @@ static inline __always_inline void match_policy(struct __sk_buff* skb, bool ipv4
|
|||||||
if (sport != policy->src_port) continue;
|
if (sport != policy->src_port) continue;
|
||||||
score += 0xFFFF;
|
score += 0xFFFF;
|
||||||
}
|
}
|
||||||
if (ntohs(dport) < policy->dst_port_start) continue;
|
if (dport < policy->dst_port_start) continue;
|
||||||
if (ntohs(dport) > policy->dst_port_end) continue;
|
if (dport > policy->dst_port_end) continue;
|
||||||
score += 0xFFFF + policy->dst_port_start - policy->dst_port_end;
|
score += 0xFFFF + policy->dst_port_start - policy->dst_port_end;
|
||||||
|
|
||||||
if (score > best_score) {
|
if (score > best_score) {
|
||||||
|
|||||||
@@ -65,11 +65,11 @@ STRUCT_SIZE(DscpPolicy, 2 * 16 + 4 + 3 * 2 + 3 * 1 + 3); // 48
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
struct in6_addr src_ip;
|
struct in6_addr src_ip;
|
||||||
struct in6_addr dst_ip;
|
struct in6_addr dst_ip;
|
||||||
__u32 ifindex;
|
uint32_t ifindex;
|
||||||
__be16 src_port;
|
__be16 src_port;
|
||||||
__be16 dst_port;
|
uint16_t dst_port;
|
||||||
__u8 proto;
|
uint8_t proto;
|
||||||
__s8 dscp_val; // -1 none, or 0..63 DSCP value
|
int8_t dscp_val; // -1 none, or 0..63 DSCP value
|
||||||
__u8 pad[2];
|
uint8_t pad[2];
|
||||||
} RuleEntry;
|
} RuleEntry;
|
||||||
STRUCT_SIZE(RuleEntry, 2 * 16 + 1 * 4 + 2 * 2 + 2 * 1 + 2); // 44
|
STRUCT_SIZE(RuleEntry, 2 * 16 + 1 * 4 + 2 * 2 + 2 * 1 + 2); // 44
|
||||||
|
|||||||
Reference in New Issue
Block a user