static bool test_function_build_ipv4_frag_off_field(void) { bool success = true; success &= assert_equals_u16(0x400F, be16_to_cpu(build_ipv4_frag_off_field(1, 0, 120)), "Simple 1"); success &= assert_equals_u16(0x202B, be16_to_cpu(build_ipv4_frag_off_field(0, 1, 344)), "Simple 2"); return success; }
int init_ipv4_hdr(void *l3_hdr, u16 payload_len, u8 nexthdr, struct tuple *tuple4, bool df, bool mf, u16 frag_offset, u8 ttl) { struct iphdr *hdr = l3_hdr; hdr->version = 4; hdr->ihl = 5; hdr->tos = 0; hdr->tot_len = cpu_to_be16(sizeof(*hdr) + payload_len); hdr->id = (frag_offset != 0 || mf) ? cpu_to_be16(4321) : 0; hdr->frag_off = build_ipv4_frag_off_field(df, mf, frag_offset); hdr->ttl = ttl; hdr->protocol = nexthdr; hdr->saddr = tuple4->src.addr4.l3.s_addr; hdr->daddr = tuple4->dst.addr4.l3.s_addr; hdr->check = 0; hdr->check = ip_fast_csum(hdr, hdr->ihl); return 0; }