Skip to content

Commit

Permalink
gk: fix checksum issue
Browse files Browse the repository at this point in the history
Some examples that implement the RFC1624 [Eqn. 4] use the network order:
https://elixir.bootlin.com/linux/latest/source/net/ipv4/netfilter/ipt_ECN.c#L38

This patch removes the byte-order convertion for checksum.
  • Loading branch information
mengxiang0811 committed Aug 28, 2020
1 parent f64c4ef commit 0cfefaa
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions gk/bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,19 @@ update_pkt_priority(struct ipacket *packet, int priority,

if (packet->flow.proto == RTE_ETHER_TYPE_IPV4) {
struct rte_ipv4_hdr *ip4hdr = packet->l3_hdr;
uint16_t old_val = ntohs(*(uint16_t *)ip4hdr);
uint16_t old_val = *(uint16_t *)ip4hdr;
uint16_t new_val;

mask = (1 << 2) - 1;

ip4hdr->type_of_service = (priority << 2) |
(ip4hdr->type_of_service & mask);

new_val = ntohs(*(uint16_t *)ip4hdr);
new_val = *(uint16_t *)ip4hdr;

/* According to RFC1624 [Eqn. 4]. */
ip4hdr->hdr_checksum = htons(ntohs(ip4hdr->hdr_checksum) -
~old_val - new_val);
ip4hdr->hdr_checksum = ip4hdr->hdr_checksum -
~old_val - new_val;
} else if (likely(packet->flow.proto == RTE_ETHER_TYPE_IPV6)) {
struct rte_ipv6_hdr *ip6hdr = packet->l3_hdr;

Expand Down

0 comments on commit 0cfefaa

Please sign in to comment.