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)
 
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 22 of file ip.h.

◆ IP_MASK_VER

#define IP_MASK_VER   0xf0U

Definition at line 23 of file ip.h.

◆ IP_MASK_HLEN

#define IP_MASK_HLEN   0x0fU

Definition at line 24 of file ip.h.

◆ IP_MASK_OFFSET

#define IP_MASK_OFFSET   0x1fffU

Definition at line 25 of file ip.h.

◆ IP_MASK_DONOTFRAG

#define IP_MASK_DONOTFRAG   0x4000U

Definition at line 26 of file ip.h.

◆ IP_MASK_MOREFRAGS

#define IP_MASK_MOREFRAGS   0x2000U

Definition at line 27 of file ip.h.

◆ IP_PSHLEN

#define IP_PSHLEN   12

Definition at line 28 of file ip.h.

◆ IP_TOS

#define IP_TOS   0

Definition at line 31 of file ip.h.

◆ IP_TTL

#define IP_TTL   64

Definition at line 32 of file ip.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ 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 309 of file ipv4.c.

310  {
311  struct ipv4_miniroute *miniroute;
312 
313  /* Find first usable route in routing table */
314  list_for_each_entry ( miniroute, &ipv4_miniroutes, list ) {
315 
316  /* Skip closed network devices */
317  if ( ! netdev_is_open ( miniroute->netdev ) )
318  continue;
319 
320  if ( IN_IS_MULTICAST ( dest->s_addr ) ) {
321 
322  /* If destination is non-global, and the scope
323  * ID matches this network device, then use
324  * the first matching route.
325  */
326  if ( miniroute->netdev->scope_id == scope_id )
327  return miniroute;
328 
329  } else {
330 
331  /* If destination is global, then use the
332  * first matching route (via its gateway if
333  * specified).
334  */
335  if ( ( ( dest->s_addr ^ miniroute->network.s_addr )
336  & miniroute->netmask.s_addr ) == 0 ) {
337  if ( miniroute->gateway.s_addr )
338  *dest = miniroute->gateway;
339  return miniroute;
340  }
341  }
342  }
343 
344  return NULL;
345 }
struct in_addr netmask
Subnet mask.
Definition: ip.h:98
struct list_head list
List of miniroutes.
Definition: ip.h:65
struct net_device * netdev
Network device.
Definition: ip.h:72
unsigned int scope_id
Scope ID.
Definition: netdevice.h:360
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
Definition: netdevice.h:661
An IPv4 address/routing table entry.
Definition: ip.h:63
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:431
struct in_addr gateway
Gateway address, or zero.
Definition: ip.h:108
struct in_addr network
Subnet network address.
Definition: ip.h:92
struct list_head ipv4_miniroutes
List of IPv4 miniroutes.
Definition: ipv4.c:57
uint32_t s_addr
Definition: in.h:42
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:150
#define IN_IS_MULTICAST(addr)
Definition: in.h:33
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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 588 of file ipv4.c.

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

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 57 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 55 of file aoe.c.