Debian Codegraph @

src/libsystemd-network/ip-util.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include <netinet/ip.h>
5 #include <netinet/udp.h>
6
7 #include "sd-forward.h"
8
9 #include "sparse-endian.h"
10
11 /* RFC 791
12 * Fragmentation and Reassembly.
13 * Every internet destination must be able to receive a datagram of 576 octets either in one piece or in
14 * fragments to be reassembled. */
15 #define IPV4_MIN_REASSEMBLY_SIZE 576u
16
17 /* This is a maximal UDP payload size in a packet when its IP header does not contain options. When a packet
18 * contains some IP options, then of course the allowed UDP payload size in the packet becomes smaller. */
19 #define UDP_PAYLOAD_MAX_SIZE (UINT16_MAX - sizeof(struct iphdr) - sizeof(struct udphdr))
20
21 uint16_t ip_checksum(const void *buf, size_t len);
22
23 int udp_packet_build(
24 be32_t source_addr,
25 uint16_t source_port,
26 be32_t destination_addr,
27 uint16_t destination_port,
28 int ip_service_type,
29 const struct iovec_wrapper *payload,
30 struct iphdr *ret_iphdr,
31 struct udphdr *ret_udphdr);
32
33 int udp_packet_verify(
34 const struct iovec *packet,
35 uint16_t port,
36 bool checksum,
37 struct iovec *ret_payload);