AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
ether.c File Reference

Ethernet, and the Internet checksum. More...

#include <core/system.h>
#include <core/string.h>
#include <net/byteorder.h>
#include <net/inet.h>

Go to the source code of this file.

Functions

void ether_input (struct netif *netif, struct netbuf *nb)
 Takes in a frame that an interface received, and passes it to ARP or IPv4.
int ether_output (struct netif *netif, const uint8_t dst[6], uint16_t type, struct netbuf *nb)
 Sends a frame: adds its Ethernet header and gives it to the interface.
uint16_t inet_checksum (const void *data, size_t len)
 Computes the Internet checksum (RFC 1071): the ones' complement of the ones' complement sum of the data's 16-bit words.
uint16_t inet_checksum_pseudo (uint32_t src, uint32_t dst, uint8_t proto, const void *data, size_t len)
 Computes the Internet checksum of data with the IPv4 pseudo-header before it (the addresses, the protocol and the length), as UDP and TCP do.

Detailed Description

Ethernet, and the Internet checksum.

A frame that arrives goes to the protocol its type says (ARP or IPv4); a frame to send gets its Ethernet header here. The Internet checksum, which IPv4, ICMP, UDP and TCP use, is here too.

Definition in file ether.c.

Function Documentation

◆ ether_input()

void ether_input ( struct netif * netif,
struct netbuf * nb )

Takes in a frame that an interface received, and passes it to ARP or IPv4.

A frame of another type, or too short, is dropped.

Parameters
netifthe interface it came in on
nbthe frame; it is freed or passed on

Definition at line 21 of file ether.c.

References arp_input(), ether_input(), ETHER_TYPE_ARP, ETHER_TYPE_IPV4, ipv4_input(), netbuf_free(), netbuf_pull(), ntohs, ether_hdr::src, netif::stats, and ether_hdr::type.

Referenced by ether_input(), and net_main().

◆ ether_output()

int ether_output ( struct netif * netif,
const uint8_t dst[6],
uint16_t type,
struct netbuf * nb )

Sends a frame: adds its Ethernet header and gives it to the interface.

The netbuf is freed in every case.

Parameters
netifthe interface to send it on
dstthe destination MAC address
typethe frame's type (ETHER_TYPE_*)
nbthe frame's data, with room for the header before it
Returns
0, or a negative errno from the interface

Definition at line 54 of file ether.c.

References ether_hdr::dst, ether_output(), htons, netif::mac, memcpy(), netbuf_free(), netbuf_push(), netif_output(), ether_hdr::src, and ether_hdr::type.

Referenced by arp_input(), arp_request(), ether_output(), ipv4_output(), and pending_flush().

◆ inet_checksum()

uint16_t inet_checksum ( const void * data,
size_t len )

Computes the Internet checksum (RFC 1071): the ones' complement of the ones' complement sum of the data's 16-bit words.

Parameters
datathe data
lenits length, in bytes
Returns
the checksum, in network byte order (0 if the data includes a correct checksum)

Definition at line 76 of file ether.c.

References htons, and inet_checksum().

Referenced by icmp_input(), icmp_unreachable(), inet_checksum(), ipv4_input(), ipv4_output(), and socket_inet_send().

◆ inet_checksum_pseudo()

uint16_t inet_checksum_pseudo ( uint32_t src,
uint32_t dst,
uint8_t proto,
const void * data,
size_t len )

Computes the Internet checksum of data with the IPv4 pseudo-header before it (the addresses, the protocol and the length), as UDP and TCP do.

Parameters
srcthe source address
dstthe destination address
protothe protocol (IP_PROTO_*)
datathe UDP or TCP header and data
lentheir length, in bytes
Returns
the checksum, in network byte order (0 if the data includes a correct checksum)

Definition at line 106 of file ether.c.

References __packed, ether_hdr::dst, htons, inet_checksum_pseudo(), and ether_hdr::src.

Referenced by inet_checksum_pseudo(), segment(), socket_inet_send(), tcp_input(), tcp_reply_rst(), and udp_input().