blob: e76a984642fe218ed9e63a13ce5aad95684dafa7 [file] [log] [blame]
// Copyright (c) 2017, Google Inc.
//
// P4_16 specification for IPv4 checksum verify and update.
// Status: WORK IN PROGRESS
// Note: This code has not been tested and is expected to contain bugs.
#include "headers.p4"
control verify_checksum(in parsed_packet_t hdr,
inout local_metadata_t local_metadata) {
Checksum16() ipv4_checksum;
bit<16> ck;
apply {
if (hdr.ipv4_base.isValid()) {
ck = ipv4_checksum.get(
{
hdr.ipv4_base.version, hdr.ipv4_base.ihl,
hdr.ipv4_base.diffserv, hdr.ipv4_base.total_len,
hdr.ipv4_base.identification, hdr.ipv4_base.flags,
hdr.ipv4_base.frag_offset, hdr.ipv4_base.ttl,
hdr.ipv4_base.protocol, hdr.ipv4_base.src_addr,
hdr.ipv4_base.dst_addr
});
if (hdr.ipv4_base.hdr_checksum != ck) {
mark_to_drop();
}
}
}
}
control compute_checksum(inout parsed_packet_t hdr,
inout local_metadata_t local_metadata) {
Checksum16() ipv4_checksum;
apply {
if (hdr.ipv4_base.isValid()) {
hdr.ipv4_base.hdr_checksum = ipv4_checksum.get(
{
hdr.ipv4_base.version, hdr.ipv4_base.ihl,
hdr.ipv4_base.diffserv, hdr.ipv4_base.total_len,
hdr.ipv4_base.identification, hdr.ipv4_base.flags,
hdr.ipv4_base.frag_offset, hdr.ipv4_base.ttl,
hdr.ipv4_base.protocol, hdr.ipv4_base.src_addr,
hdr.ipv4_base.dst_addr
});
}
}
}