iPXE
Data Structures | Macros | Functions | Variables
ip.h File Reference

IP protocol. More...

#include <stdint.h>
#include <ipxe/in.h>
#include <ipxe/list.h>
#include <ipxe/retry.h>
#include <ipxe/netdevice.h>

Go to the source code of this file.

Data Structures

struct  iphdr
 An IPv4 packet header. More...
 
struct  ipv4_pseudo_header
 An IPv4 pseudo header. More...
 
struct  ipv4_miniroute
 An IPv4 address/routing table entry. More...
 

Macros

#define IP_VER   0x40U
 
#define IP_MASK_VER   0xf0U
 
#define IP_MASK_HLEN   0x0fU
 
#define IP_MASK_OFFSET   0x1fffU
 
#define IP_MASK_DONOTFRAG   0x4000U
 
#define IP_MASK_MOREFRAGS   0x2000U
 
#define IP_PSHLEN   12
 
#define IP_TOS   0
 
#define IP_TTL   64
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 FILE_SECBOOT (PERMITTED)
 
struct ipv4_minirouteipv4_route (unsigned int scope_id, struct in_addr *dest)
 Perform IPv4 routing. More...
 
int ipv4_has_any_addr (struct net_device *netdev)
 Check if network device has any IPv4 address. More...
 
int parse_ipv4_setting (const struct setting_type *type, const char *value, void *buf, size_t len)
 
int format_ipv4_setting (const struct setting_type *type, const void *raw, size_t raw_len, char *buf, size_t len)
 

Variables

struct list_head ipv4_miniroutes
 List of IPv4 miniroutes. More...
 
struct net_protocol ipv4_protocol __net_protocol
 AoE protocol. More...
 

Detailed Description

IP protocol.

Definition in file ip.h.

Macro Definition Documentation

◆ IP_VER

#define IP_VER   0x40U

Definition at line 23 of file ip.h.

◆ IP_MASK_VER

#define IP_MASK_VER   0xf0U

Definition at line 24 of file ip.h.

◆ IP_MASK_HLEN

#define IP_MASK_HLEN   0x0fU

Definition at line 25 of file ip.h.

◆ IP_MASK_OFFSET

#define IP_MASK_OFFSET   0x1fffU

Definition at line 26 of file ip.h.

◆ IP_MASK_DONOTFRAG

#define IP_MASK_DONOTFRAG   0x4000U

Definition at line 27 of file ip.h.

◆ IP_MASK_MOREFRAGS

#define IP_MASK_MOREFRAGS   0x2000U

Definition at line 28 of file ip.h.

◆ IP_PSHLEN

#define IP_PSHLEN   12

Definition at line 29 of file ip.h.

◆ IP_TOS

#define IP_TOS   0

Definition at line 32 of file ip.h.

◆ IP_TTL

#define IP_TTL   64

Definition at line 33 of file ip.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ ipv4_route()

struct ipv4_miniroute* ipv4_route ( unsigned int  scope_id,
struct in_addr dest 
)

Perform IPv4 routing.

Parameters
scope_idDestination address scope ID
destFinal destination address
Return values
destNext hop destination address
minirouteRouting table entry to use, or NULL if no route

If the route requires use of a gateway, the next hop destination address will be overwritten with the gateway address.

Definition at line 310 of file ipv4.c.

311  {
312  struct ipv4_miniroute *miniroute;
313 
314  /* Find first usable route in routing table */
315  list_for_each_entry ( miniroute, &ipv4_miniroutes, list ) {
316 
317  /* Skip closed network devices */
318  if ( ! netdev_is_open ( miniroute->netdev ) )
319  continue;
320 
321  if ( IN_IS_MULTICAST ( dest->s_addr ) ) {
322 
323  /* If destination is non-global, and the scope
324  * ID matches this network device, then use
325  * the first matching route.
326  */
327  if ( miniroute->netdev->scope_id == scope_id )
328  return miniroute;
329 
330  } else {
331 
332  /* If destination is global, then use the
333  * first matching route (via its gateway if
334  * specified).
335  */
336  if ( ( ( dest->s_addr ^ miniroute->network.s_addr )
337  & miniroute->netmask.s_addr ) == 0 ) {
338  if ( miniroute->gateway.s_addr )
339  *dest = miniroute->gateway;
340  return miniroute;
341  }
342  }
343  }
344 
345  return NULL;
346 }
struct in_addr netmask
Subnet mask.
Definition: ip.h:99
struct list_head list
List of miniroutes.
Definition: ip.h:66
struct net_device * netdev
Network device.
Definition: ip.h:73
unsigned int scope_id
Scope ID.
Definition: netdevice.h:361
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
Definition: netdevice.h:662
An IPv4 address/routing table entry.
Definition: ip.h:64
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:432
struct in_addr gateway
Gateway address, or zero.
Definition: ip.h:109
struct in_addr network
Subnet network address.
Definition: ip.h:93
struct list_head ipv4_miniroutes
List of IPv4 miniroutes.
Definition: ipv4.c:58
uint32_t s_addr
Definition: in.h:43
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" return dest
Definition: string.h:151
#define IN_IS_MULTICAST(addr)
Definition: in.h:34
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References dest, ipv4_miniroute::gateway, IN_IS_MULTICAST, ipv4_miniroutes, ipv4_miniroute::list, list_for_each_entry, ipv4_miniroute::netdev, netdev_is_open(), ipv4_miniroute::netmask, ipv4_miniroute::network, NULL, in_addr::s_addr, and net_device::scope_id.

Referenced by ipv4_netdev(), ipv4_route_okx(), and ipv4_tx().

◆ ipv4_has_any_addr()

int ipv4_has_any_addr ( struct net_device netdev)

Check if network device has any IPv4 address.

Parameters
netdevNetwork device
Return values
has_any_addrNetwork device has any IPv4 address

Definition at line 589 of file ipv4.c.

589  {
590  struct ipv4_miniroute *miniroute;
591 
592  list_for_each_entry ( miniroute, &ipv4_miniroutes, list ) {
593  if ( miniroute->netdev == netdev )
594  return 1;
595  }
596  return 0;
597 }
struct list_head list
List of miniroutes.
Definition: ip.h:66
struct net_device * netdev
Network device.
Definition: ip.h:73
An IPv4 address/routing table entry.
Definition: ip.h:64
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:432
static struct net_device * netdev
Definition: gdbudp.c:52
struct list_head ipv4_miniroutes
List of IPv4 miniroutes.
Definition: ipv4.c:58

References ipv4_miniroutes, ipv4_miniroute::list, list_for_each_entry, netdev, and ipv4_miniroute::netdev.

Referenced by dhcp_create_packet(), and ipv4_rx().

◆ parse_ipv4_setting()

int parse_ipv4_setting ( const struct setting_type type,
const char *  value,
void *  buf,
size_t  len 
)

◆ format_ipv4_setting()

int format_ipv4_setting ( const struct setting_type type,
const void *  raw,
size_t  raw_len,
char *  buf,
size_t  len 
)

Variable Documentation

◆ ipv4_miniroutes

struct list_head ipv4_miniroutes

List of IPv4 miniroutes.

Definition at line 58 of file ipv4.c.

Referenced by ipv4_add_miniroute(), ipv4_del_miniroutes(), ipv4_has_addr(), ipv4_has_any_addr(), ipv4_route(), and route_ipv4_print().

◆ __net_protocol

struct net_protocol ipv4_protocol __net_protocol

AoE protocol.

AoE protocol.

AoE protocol.

FIP protocol.

Definition at line 56 of file aoe.c.