| 35 | #include "../utils/ip.h" |
| 36 | |
| 37 | void IPChecksum::ProcessBatch(Context *ctx, bess::PacketBatch *batch) { |
| 38 | using bess::utils::Ethernet; |
| 39 | using bess::utils::Ipv4; |
| 40 | using bess::utils::Vlan; |
| 41 | using bess::utils::be16_t; |
| 42 | |
| 43 | int cnt = batch->cnt(); |
| 44 | |
| 45 | for (int i = 0; i < cnt; i++) { |
| 46 | Ethernet *eth = batch->pkts()[i]->head_data<Ethernet *>(); |
| 47 | void *data = eth + 1; |
| 48 | Ipv4 *ip; |
| 49 | |
| 50 | be16_t ether_type = eth->ether_type; |
| 51 | |
| 52 | if (ether_type == be16_t(Ethernet::Type::kQinQ)) { |
| 53 | Vlan *qinq = reinterpret_cast<Vlan *>(data); |
| 54 | data = qinq + 1; |
| 55 | ether_type = qinq->ether_type; |
| 56 | if (ether_type != be16_t(Ethernet::Type::kVlan)) { |
| 57 | continue; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | if (ether_type == be16_t(Ethernet::Type::kVlan)) { |
| 62 | Vlan *vlan = reinterpret_cast<Vlan *>(data); |
| 63 | data = vlan + 1; |
| 64 | ether_type = vlan->ether_type; |
| 65 | } |
| 66 | |
| 67 | if (ether_type == be16_t(Ethernet::Type::kIpv4)) { |
| 68 | ip = reinterpret_cast<Ipv4 *>(data); |
| 69 | } else { |
| 70 | continue; |
| 71 | } |
| 72 | |
| 73 | ip->checksum = CalculateIpv4Checksum(*ip); |
| 74 | } |
| 75 | |
| 76 | RunNextModule(ctx, batch); |
| 77 | } |
| 78 | |
| 79 | ADD_MODULE(IPChecksum, "ip_checksum", "recomputes the IPv4 checksum") |
nothing calls this directly
no test coverage detected