My Kernel v0.1.0
ethernet.h
Go to the documentation of this file.
1
13#ifndef KERNEL_NET_ETHERNET_H
14#define KERNEL_NET_ETHERNET_H
15
16#include <kernel/error.h>
17#include <kernel/types.h>
18
19#include <utils/compiler.h>
20
22#define ETHERNET_ADDR_SIZE 6
24#define ETHERNET_HEADER_SIZE 14
25
30
31struct packet;
32
37 __be uint16_t protocol;
38};
39
40static_assert(sizeof(struct ethernet_header) == ETHERNET_HEADER_SIZE);
41
46 ETH_PROTO_IP = 0x0800,
47 ETH_PROTO_ARP = 0x0806,
48};
49
51void ethernet_fill_packet(struct packet *, enum ethernet_type,
52 const mac_address_t dst);
53
55error_t ethernet_receive_packet(struct packet *);
56
57static inline void ethernet_fill_mac(mac_address_t mac, uint64_t mac_raw)
58{
59 mac[5] = mac_raw;
60 mac[4] = mac_raw >> 8;
61 mac[3] = mac_raw >> 16;
62 mac[2] = mac_raw >> 24;
63 mac[1] = mac_raw >> 32;
64 mac[0] = mac_raw >> 40;
65}
66
67#define LOG_MAC_ARG(_mac) mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]
68#define FMT_MAC "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx"
69
70#endif /* KERNEL_NET_ETHERNET_H */
71
error_t ethernet_receive_packet(struct packet *)
Process a packet received by an ethernet network device.
Definition: ethernet.c:28
ethernet_type
Supported ethernet protocols, as defined by IANA.
Definition: ethernet.h:45
#define ETHERNET_ADDR_SIZE
Size of an ethernet MAC address.
Definition: ethernet.h:22
#define ETHERNET_HEADER_SIZE
Size of an ethernet header.
Definition: ethernet.h:24
void ethernet_fill_packet(struct packet *, enum ethernet_type, const mac_address_t dst)
Insert headers for layer 2 inside a packet over ethernet.
Definition: ethernet.c:13
uint8_t mac_address_t[ETHERNET_ADDR_SIZE]
Represents an ethernet MAC address.
Definition: ethernet.h:29
@ ETH_PROTO_IP
IPv4.
Definition: ethernet.h:46
@ ETH_PROTO_ARP
Address resolution protocol.
Definition: ethernet.h:47
Structure of the page fault's error code https://wiki.osdev.org/Exceptions#Page_Fault.
Definition: mmu.c:587
An ethernet frame.
Definition: ethernet.h:34
mac_address_t src
Sender's ethernet MAC address.
Definition: ethernet.h:36
mac_address_t dst
Receiver's ethernet MAC address.
Definition: ethernet.h:35
__be uint16_t protocol
The L3 protocol of the payload's packet.
Definition: ethernet.h:37
A network packet.
Definition: packet.h:51