Retro Rocket Kernel BASIC-Powered Operating System

Data Structures | Macros | Enumerations | Functions | Variables
ip.h File Reference
`#include "kernel.h"`

## Data Structures
union | ip_frag
| Structure and bitfields for representing IP fragmentation. Used within an ip_packet_t. More...
union | tos_flags
struct | ip_packet
| Structure for an IP packet. More...
struct | ip_packet_frag_t
struct | ip_fragmented_packet_parts_t
struct | packet_queue_item_t

## Macros
#define | ETHERNET_TYPE_IP 0x0800
#define | ETHERNET_TYPE_IP6 0x86DD

## Enumerations
enum | ip_type_t { IP_IPV4 = 4 }
| IP protocol types. More...
enum | ip_proto_t { PROTOCOL_ICMP = 1 , PROTOCOL_TCP = 6 , PROTOCOL_UDP = 17 }
| Sub-protocols, TCP and UDP. More...

## Functions
union ip_frag | __attribute__ ((packed)) ip_frag_t
| Structure and bitfields for representing IP fragmentation. Used within an ip_packet_t. More...
void | get_ip_str (char *ip_str, const uint8_t *ip)
| Convert network byte order IP to a string form for display. More...
uint32_t | str_to_ip (const char *ip_str)
| Convert a string IP to host byte order IP address. More...
uint16_t | ip_calculate_checksum (ip_packet_t *packet)
| Calculate checksum for IP packet. More...
void | ip_send_packet (uint8_t *dst_ip, void *data, uint16_t len, uint8_t protocol)
| Send IP packet to the ethernet driver. More...
int | gethostaddr (unsigned char *ip)
| Get the current IP address. This could be allocated by DHCP or statically. More...
void | sethostaddr (const unsigned char *ip)
| Set the current IP address. More...
void | setdnsaddr (uint32_t dns)
| Set DNS address This could be allocated by DHCP or statically. More...
void | setgatewayaddr (uint32_t gateway)
| Set gateway address This could be allocated by DHCP or statically. More...
uint32_t | getdnsaddr ()
| Get DNS address This could be allocated by DHCP or statically. More...
uint32_t | getgatewayaddr ()
| Get gateway address This could be allocated by DHCP or statically. More...
void | setnetmask (uint32_t nm)
| Set network mask. More...
uint32_t | getnetmask ()
| Get network mask. More...
void | ip_init ()
| Initialise IP protocol. More...
void | ip_idle ()
| Called from the local APIC timer interrupt 50 times a second. Attempts to resolve ARP requests for queued packets that we don't have ARP for yet, and retries ARP requests up to 3 times before dropping packets we cannot route. More...

## Variables
uint16_t | bits
struct {
uint8_t reserved_zero: 1
uint8_t dont_fragment: 1
uint8_t more_fragments_follow: 1
uint8_t fragment_offset_high: 5
uint8_t fragment_offset_low: 8
}; |
struct {
uint8_t dscp:6
uint8_t ecn:2
}; |
char | version_ihl_ptr [0]
uint8_t | version
uint8_t | ihl
tos_flags_t | tos
uint16_t | length
uint16_t | id
char | flags_fragment_ptr [0]
ip_frag_t | frag
uint8_t | ttl
uint8_t | protocol
uint16_t | header_checksum
uint8_t | src_ip [4]
uint8_t | dst_ip [4]
uint8_t | options [0]
uint8_t | data []

## Detailed Description

Author
  Craig Edwards (craig.nosp@m.edwa.nosp@m.rds@b.nosp@m.rain.nosp@m.box.c.nosp@m.c)

Copyright
  Copyright (c) 2012-2023

## Macro Definition Documentation

## ◆ ETHERNET_TYPE_IP

#define ETHERNET_TYPE_IP 0x0800

## ◆ ETHERNET_TYPE_IP6

#define ETHERNET_TYPE_IP6 0x86DD

## Enumeration Type Documentation

## ◆ ip_proto_t

enum ip_proto_t

Sub-protocols, TCP and UDP.

Enumerator
PROTOCOL_ICMP |
PROTOCOL_TCP |
PROTOCOL_UDP |

## ◆ ip_type_t

enum ip_type_t

IP protocol types.

Enumerator
IP_IPV4 |

## Function Documentation

## ◆ __attribute__()

union ip_frag __attribute__ | ( | (packed) |  | ) |

Structure and bitfields for representing IP fragmentation. Used within an ip_packet_t.

Structure for an IP packet.

## ◆ get_ip_str()

void get_ip_str | ( | char * | ip_str,
|  | const uint8_t * | ip
| ) |  |

Convert network byte order IP to a string form for display.

Parameters

  ip_str | character buffer to fill, should be at least 13 bytes
  ip | raw 4 byte IP

## ◆ getdnsaddr()

uint32_t getdnsaddr | ( |  | ) |

Get DNS address This could be allocated by DHCP or statically.

Returns
  uint32_t DNS address

## ◆ getgatewayaddr()

uint32_t getgatewayaddr | ( |  | ) |

Get gateway address This could be allocated by DHCP or statically.

Returns
  uint32_t gateway address

## ◆ gethostaddr()

int gethostaddr | ( | unsigned char * | ip | ) |

Get the current IP address. This could be allocated by DHCP or statically.

Parameters

  ip | IP address buffer, should be at least 4 bytes

Returns
  int nonzero if an IP address is available for use

## ◆ getnetmask()

uint32_t getnetmask | ( |  | ) |

Get network mask.

Returns
  uint32_t network mask

## ◆ ip_calculate_checksum()

uint16_t ip_calculate_checksum | ( | ip_packet_t * | packet | ) |

Calculate checksum for IP packet.

Parameters

  packet | IP packet structure

Returns
  uint16_t Checksum

## ◆ ip_idle()

void ip_idle | ( |  | ) |

Called from the local APIC timer interrupt 50 times a second. Attempts to resolve ARP requests for queued packets that we don't have ARP for yet, and retries ARP requests up to 3 times before dropping packets we cannot route.

## ◆ ip_init()

void ip_init | ( |  | ) |

Initialise IP protocol.

## ◆ ip_send_packet()

void ip_send_packet | ( | uint8_t * | dst_ip,
|  | void * | data,
|  | uint16_t | len,
|  | uint8_t | protocol
| ) |  |

Send IP packet to the ethernet driver.

Parameters

  dst_ip | IP to send the packet to (255.255.255.255 for broadcast)
  data | raw IP packet to send
  len | data length
  protocol | Sub-protocol encapsulated inside the packet, e.g. UDP, TCP

## ◆ setdnsaddr()

void setdnsaddr | ( | uint32_t | dns | ) |

Set DNS address This could be allocated by DHCP or statically.

Parameters

  dns | DNS address

## ◆ setgatewayaddr()

void setgatewayaddr | ( | uint32_t | gateway | ) |

Set gateway address This could be allocated by DHCP or statically.

Parameters

  dns | Gateway address

## ◆ sethostaddr()

void sethostaddr | ( | const unsigned char * | ip | ) |

Set the current IP address.

Parameters

  ip | 4 byte buffer for IP address

## ◆ setnetmask()

void setnetmask | ( | uint32_t | nm | ) |

Set network mask.

Parameters

  nm | network mask

## ◆ str_to_ip()

uint32_t str_to_ip | ( | const char * | ip_str | ) |

Convert a string IP to host byte order IP address.

Parameters

  ip_str | ip as string e.g. "127.0.0.1"

Returns
  uint32_t IP in host byte order

## Variable Documentation

## ◆

struct { ... }

## ◆

struct { ... }

## ◆ bits

uint8_t bits

## ◆ data

uint8_t data[]

## ◆ dont_fragment

uint8_t dont_fragment

## ◆ dscp

uint8_t dscp

## ◆ dst_ip

uint8_t dst_ip[4]

## ◆ ecn

uint8_t ecn

## ◆ flags_fragment_ptr

char flags_fragment_ptr[0]

## ◆ frag

ip_frag_t frag

## ◆ fragment_offset_high

uint8_t fragment_offset_high

## ◆ fragment_offset_low

uint8_t fragment_offset_low

## ◆ header_checksum

uint16_t header_checksum

## ◆ id

uint16_t id

## ◆ ihl

uint8_t ihl

## ◆ length

uint16_t length

## ◆ more_fragments_follow

uint8_t more_fragments_follow

## ◆ options

uint8_t options[0]

## ◆ protocol

uint8_t protocol

## ◆ reserved_zero

uint8_t reserved_zero

## ◆ src_ip

uint8_t src_ip[4]

## ◆ tos

tos_flags_t tos

## ◆ ttl

uint8_t ttl

## ◆ version

uint8_t version

## ◆ version_ihl_ptr

char version_ihl_ptr[0]