iPXE
ip.h
Go to the documentation of this file.
1 #ifndef _IPXE_IP_H
2 #define _IPXE_IP_H
3 
4 /** @file
5  *
6  * IP protocol
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 
12 #include <stdint.h>
13 #include <ipxe/in.h>
14 #include <ipxe/list.h>
15 #include <ipxe/retry.h>
16 #include <ipxe/netdevice.h>
17 
18 struct io_buffer;
19 
20 /* IP constants */
21 
22 #define IP_VER 0x40U
23 #define IP_MASK_VER 0xf0U
24 #define IP_MASK_HLEN 0x0fU
25 #define IP_MASK_OFFSET 0x1fffU
26 #define IP_MASK_DONOTFRAG 0x4000U
27 #define IP_MASK_MOREFRAGS 0x2000U
28 #define IP_PSHLEN 12
29 
30 /* IP header defaults */
31 #define IP_TOS 0
32 #define IP_TTL 64
33 
34 /** An IPv4 packet header */
35 struct iphdr {
44  struct in_addr src;
45  struct in_addr dest;
46 } __attribute__ (( packed ));
47 
48 /** An IPv4 pseudo header */
50  struct in_addr src;
51  struct in_addr dest;
55 };
56 
57 /** An IPv4 address/routing table entry
58  *
59  * Routing table entries are maintained in order of specificity. For
60  * a given destination address, the first matching table entry will be
61  * used as the egress route.
62  */
64  /** List of miniroutes */
65  struct list_head list;
66 
67  /** Network device
68  *
69  * When this routing table entry is matched, this is the
70  * egress network device to be used.
71  */
72  struct net_device *netdev;
73 
74  /** IPv4 address
75  *
76  * When this routing table entry is matched, this is the
77  * source address to be used.
78  *
79  * The presence of this routing table entry also indicates
80  * that this address is a valid local destination address for
81  * the matching network device.
82  */
83  struct in_addr address;
84  /** Subnet network address
85  *
86  * A subnet is a range of addresses defined by a network
87  * address and subnet mask. A destination address with all of
88  * the subnet mask bits in common with the network address is
89  * within the subnet and therefore matches this routing table
90  * entry.
91  */
92  struct in_addr network;
93  /** Subnet mask
94  *
95  * An address with all of these bits in common with the
96  * network address matches this routing table entry.
97  */
98  struct in_addr netmask;
99  /** Gateway address, or zero
100  *
101  * When this routing table entry is matched and this address
102  * is non-zero, it will be used as the next-hop address.
103  *
104  * When this routing table entry is matched and this address
105  * is zero, the subnet is local (on-link) and the next-hop
106  * address will be the original destination address.
107  */
108  struct in_addr gateway;
109  /** Host mask
110  *
111  * An address in a local subnet with all of these bits set to
112  * zero represents the network address, and an address in a
113  * local subnet with all of these bits set to one represents
114  * the local directed broadcast address. All other addresses
115  * in a local subnet are valid host addresses.
116  *
117  * For most local subnets, this is the inverse of the subnet
118  * mask. In a small subnet (/31 or /32) there is no network
119  * address or directed broadcast address, and all addresses in
120  * the subnet are valid host addresses.
121  *
122  * When this routing table entry is matched and the subnet is
123  * local, a next-hop address with all of these bits set to one
124  * will be treated as a local broadcast address. All other
125  * next-hop addresses will be treated as unicast addresses.
126  *
127  * When this routing table entry is matched and the subnet is
128  * non-local, the next-hop address is always a unicast
129  * address. The host mask for non-local subnets is therefore
130  * set to @c INADDR_NONE to allow the same logic to be used as
131  * for local subnets.
132  */
134 };
135 
136 extern struct list_head ipv4_miniroutes;
137 
138 extern struct net_protocol ipv4_protocol __net_protocol;
139 
140 extern struct ipv4_miniroute * ipv4_route ( unsigned int scope_id,
141  struct in_addr *dest );
142 extern int ipv4_has_any_addr ( struct net_device *netdev );
143 extern int parse_ipv4_setting ( const struct setting_type *type,
144  const char *value, void *buf, size_t len );
145 extern int format_ipv4_setting ( const struct setting_type *type,
146  const void *raw, size_t raw_len, char *buf,
147  size_t len );
148 
149 #endif /* _IPXE_IP_H */
struct in_addr netmask
Subnet mask.
Definition: ip.h:98
#define __attribute__(x)
Definition: compiler.h:10
unsigned short uint16_t
Definition: stdint.h:11
int ipv4_has_any_addr(struct net_device *netdev)
Check if network device has any IPv4 address.
Definition: ipv4.c:588
struct list_head list
List of miniroutes.
Definition: ip.h:65
struct in_addr src
Definition: ip.h:44
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
uint8_t zero_padding
Definition: ip.h:52
uint32_t type
Operating system type.
Definition: ena.h:12
Retry timers.
struct net_device * netdev
Network device.
Definition: ip.h:72
uint16_t chksum
Definition: ip.h:43
int format_ipv4_setting(const struct setting_type *type, const void *raw, size_t raw_len, char *buf, size_t len)
struct net_protocol ipv4_protocol __net_protocol
AoE protocol.
Definition: aoe.c:55
uint16_t ident
Definition: ip.h:39
uint16_t frags
Definition: ip.h:40
An IPv4 packet header.
Definition: ip.h:35
struct in_addr address
IPv4 address.
Definition: ip.h:83
struct in_addr hostmask
Host mask.
Definition: ip.h:133
A doubly-linked list entry (or list head)
Definition: list.h:18
uint16_t len
Definition: ip.h:54
struct in_addr dest
Definition: ip.h:51
An IPv4 address/routing table entry.
Definition: ip.h:63
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
uint16_t len
Definition: ip.h:38
struct in_addr gateway
Gateway address, or zero.
Definition: ip.h:108
ring len
Length.
Definition: dwmac.h:231
static struct net_device * netdev
Definition: gdbudp.c:52
uint8_t verhdrlen
Definition: ip.h:36
Linked lists.
static size_t raw_len
Definition: base16.h:53
struct list_head ipv4_miniroutes
List of IPv4 miniroutes.
Definition: ipv4.c:57
IP address structure.
Definition: in.h:41
A network device.
Definition: netdevice.h:352
int parse_ipv4_setting(const struct setting_type *type, const char *value, void *buf, size_t len)
unsigned char uint8_t
Definition: stdint.h:10
struct in_addr dest
Definition: ip.h:45
struct in_addr network
Subnet network address.
Definition: ip.h:92
An IPv4 pseudo header.
Definition: ip.h:49
A network-layer protocol.
Definition: netdevice.h:64
Network device management.
uint8_t protocol
Definition: ip.h:42
uint8_t protocol
Definition: ip.h:53
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
__be32 raw[7]
Definition: CIB_PRM.h:28
struct ipv4_miniroute * ipv4_route(unsigned int scope_id, struct in_addr *dest)
Perform IPv4 routing.
Definition: ipv4.c:309
uint8_t ttl
Definition: ip.h:41
struct in_addr src
Definition: ip.h:50
uint8_t service
Definition: ip.h:37
A setting type.
Definition: settings.h:191
A persistent I/O buffer.
Definition: iobuf.h:37