- Timestamping management added - Errors due to reading uninitialized data in ARP fixed - EthInterface reworked, incoming packet notification and payload readout separated (through which fixing concurrent access problems) - RX and TX offloads added - Capability to add a packet sieve layer without prior registration of specific packet class added (this makes it possible to register arbitrary EtherType connection blocks, for example)
80 lines
2.3 KiB
C
80 lines
2.3 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);
|
|
|
|
#endif //ETHERLIB_IPV4_PACKET_H
|