projects
/
flowspec-xdp
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
36cf3e1
)
Drop ports_valid flag, it just wastes a register
author
Matt Corallo
<git@bluematt.me>
Tue, 25 May 2021 03:06:53 +0000
(
03:06
+0000)
committer
Matt Corallo
<git@bluematt.me>
Tue, 25 May 2021 03:06:53 +0000
(
03:06
+0000)
genrules.py
patch
|
blob
|
history
xdp.c
patch
|
blob
|
history
diff --git
a/genrules.py
b/genrules.py
index 37c533ea6832919253fdbd04d6d96887cfd8b7e4..5d90e8c773a414b218a7db7be03f2b5eb3e085f9 100755
(executable)
--- a/
genrules.py
+++ b/
genrules.py
@@
-239,10
+239,10
@@
def dscp_to_rule(proto, rules):
def port_to_rule(ty, rules):
if ty == "port" :
ast = parse_ast(rules, parse_numbers_expr, True)
def port_to_rule(ty, rules):
if ty == "port" :
ast = parse_ast(rules, parse_numbers_expr, True)
- return "if (
!ports_valid
) break;\nif (!( " + ast.write("sport", "dport") + " )) break;"
+ return "if (
sport == -1 || dport == -1
) break;\nif (!( " + ast.write("sport", "dport") + " )) break;"
ast = parse_ast(rules, parse_numbers_expr, True)
ast = parse_ast(rules, parse_numbers_expr, True)
- return "if (
!ports_valid
) break;\nif (!( " + ast.write(ty) + " )) break;"
+ return "if (
" + ty + " == -1
) break;\nif (!( " + ast.write(ty) + " )) break;"
def tcp_flags_to_rule(rules):
ast = parse_ast(rules, parse_bit_expr, False)
def tcp_flags_to_rule(rules):
ast = parse_ast(rules, parse_bit_expr, False)
diff --git
a/xdp.c
b/xdp.c
index a32f605d3c4219f8713dda28b83452f4a7ab8f03..75a44ff2a16d0a22a3cd462107feeec7dd3997c1 100644
(file)
--- a/
xdp.c
+++ b/
xdp.c
@@
-264,8
+264,7
@@
int xdp_drop_prog(struct xdp_md *ctx)
const void *l4hdr = NULL;
const struct tcphdr *tcp = NULL;
const void *l4hdr = NULL;
const struct tcphdr *tcp = NULL;
- uint8_t ports_valid = 0;
- uint16_t sport = 0, dport = 0; // Host Endian! Only valid with tcp || udp
+ int32_t sport = -1, dport = -1; // Host Endian! Only valid with tcp || udp
#ifdef NEED_V4_PARSE
if (eth_proto == BE16(ETH_P_IP)) {
#ifdef NEED_V4_PARSE
if (eth_proto == BE16(ETH_P_IP)) {
@@
-287,13
+286,11
@@
int xdp_drop_prog(struct xdp_md *ctx)
tcp = (struct tcphdr*) l4hdr;
sport = BE16(tcp->source);
dport = BE16(tcp->dest);
tcp = (struct tcphdr*) l4hdr;
sport = BE16(tcp->source);
dport = BE16(tcp->dest);
- ports_valid = 1;
} else if (ip->protocol == IP_PROTO_UDP) {
CHECK_LEN(l4hdr, udphdr);
const struct udphdr *udp = (struct udphdr*) l4hdr;
sport = BE16(udp->source);
dport = BE16(udp->dest);
} else if (ip->protocol == IP_PROTO_UDP) {
CHECK_LEN(l4hdr, udphdr);
const struct udphdr *udp = (struct udphdr*) l4hdr;
sport = BE16(udp->source);
dport = BE16(udp->dest);
- ports_valid = 1;
} else if (ip->protocol == IP_PROTO_ICMP) {
CHECK_LEN(l4hdr, icmphdr);
icmp = (struct icmphdr*) l4hdr;
} else if (ip->protocol == IP_PROTO_ICMP) {
CHECK_LEN(l4hdr, icmphdr);
icmp = (struct icmphdr*) l4hdr;
@@
-334,13
+331,11
@@
int xdp_drop_prog(struct xdp_md *ctx)
tcp = (struct tcphdr*) l4hdr;
sport = BE16(tcp->source);
dport = BE16(tcp->dest);
tcp = (struct tcphdr*) l4hdr;
sport = BE16(tcp->source);
dport = BE16(tcp->dest);
- ports_valid = 1;
} else if (v6nexthdr == IP_PROTO_UDP) {
CHECK_LEN(l4hdr, udphdr);
const struct udphdr *udp = (struct udphdr*) l4hdr;
sport = BE16(udp->source);
dport = BE16(udp->dest);
} else if (v6nexthdr == IP_PROTO_UDP) {
CHECK_LEN(l4hdr, udphdr);
const struct udphdr *udp = (struct udphdr*) l4hdr;
sport = BE16(udp->source);
dport = BE16(udp->dest);
- ports_valid = 1;
} else if (v6nexthdr == IP6_PROTO_ICMPV6) {
CHECK_LEN(l4hdr, icmp6hdr);
icmpv6 = (struct icmp6hdr*) l4hdr;
} else if (v6nexthdr == IP6_PROTO_ICMPV6) {
CHECK_LEN(l4hdr, icmp6hdr);
icmpv6 = (struct icmp6hdr*) l4hdr;