Epagris 8044d8a8b6 - RawPckt: force FCS computation feature added
- IGMP transmission reworked
- IPv4: method for filling in checksum in rendered binary data added
2024-10-20 15:38:36 +02:00

86 lines
2.5 KiB
C

#ifndef ETHERLIB_IPV4_PACKET_H
#define ETHERLIB_IPV4_PACKET_H
#include <stdint.h>
#include "../../packet_registry.h"
#include "../../packet_sieve.h"
#include "ipv4_types.h"
#define ETH_IPv4_PACKET_CLASS (0x0800)
#define ETH_IPv4_HEADER_SIZE (20)
typedef enum {
IP_FLAG_DNF = 0x02,
IP_FLAG_MF = 0x01
} IPv4Flags;
/**
* IPv4 header structure
*/
typedef struct {
PcktPropsHeader
// 1. 32-bit
uint8_t IHL; ///< header size
uint8_t Version; ///< version (always 4)
uint8_t DSF; ///< service type
uint16_t TotalLength; ///< total packet length
// 2. 32-bit
uint16_t Identification; ///< identification
uint8_t Flags; ///< packet flags
uint16_t FragmentOffset; ///< packet fragmentation offset
// 3. 32-bit
uint8_t TTL; ///< Time-To-Live
uint8_t Protocol; ///< Protocol
uint16_t HeaderChecksum; ///< header IP-checksum
// 4. 32-bit
uint32_t SourceIPAddr; ///< source IP-address
uint32_t DestIPAddr; ///< destination IP-address
} IPv4Props;
struct EthInterface_;
/**
* Parse raw IPv4 packets.
* @param hdr pointer to the IPv4 packet header
* @param size total packet size
* @param pcktHdrLe pointer to property storage
* @return Protocol on success or -1 on failure
*/
int parse_ipv4(const uint8_t *hdr, uint32_t size, PcktHeaderElement *pcktHdrLe, struct EthInterface_ *intf, PcktProcFnPassbackData * pb);
/**
* Insert IPv4 header.
* @param hdr space where the header is to be inserted
* @param headers linked list of header, top is always relevant
*/
void insert_ipv4_header(uint8_t *hdr, const PcktHeaderElement *headers, struct EthInterface_ *intf);
/**
* Calculate Ethernet IPv4 multicast address from multicast
* @param hwa
* @param ipa
*/
void ethmc_from_ipmc(uint8_t * hwa, ip4_addr ipa);
/**
* Fill IPv4 properties structure based on passed fields. Fields not listed among parameters is set to a default value.
* @param ipProps IPv4 properties structure to fill
* @param payloadSize payload size in bytes (contained header AND its payload size)
* @param protocol contained packet protocol
* @param srcIpA source IP address
* @param dstIpA destination IP address
*/
void ipv4_fill_props(IPv4Props *ipProps, uint32_t payloadSize, uint16_t protocol, ip4_addr srcIpA, ip4_addr dstIpA);
/**
* Fill in IPv4 checksum, based on header data.
* @param hdr Pointer to the IPv4 header's beginning. Checksum field's position will be written.
*/
void ipv4_fill_in_chksum(uint8_t * hdr);
#endif //ETHERLIB_IPV4_PACKET_H