dscpPolicy - sport is network endian, dport is host endian

be more consistent, and thus also less htons() calls

Test: TreeHugger, atest DscpPolicyTest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia331a33a615a598e061db53ae180fffaef7a4342
diff --git a/bpf_progs/dscpPolicy.c b/bpf_progs/dscpPolicy.c
index 08fbcb1..3e4456f 100644
--- a/bpf_progs/dscpPolicy.c
+++ b/bpf_progs/dscpPolicy.c
@@ -57,7 +57,7 @@
     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 @@
             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 @@
             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) {
diff --git a/bpf_progs/dscpPolicy.h b/bpf_progs/dscpPolicy.h
index 9680670..e565966 100644
--- a/bpf_progs/dscpPolicy.h
+++ b/bpf_progs/dscpPolicy.h
@@ -65,11 +65,11 @@
 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