This is the IPv4 layer implementation for incoming and outgoing IP traffic.
#include "lwip/opt.h"
#include "lwip/ip.h"
#include "lwip/def.h"
#include "lwip/mem.h"
#include "lwip/ip_frag.h"
#include "lwip/inet_chksum.h"
#include "lwip/netif.h"
#include "lwip/icmp.h"
#include "lwip/igmp.h"
#include "lwip/raw.h"
#include "lwip/udp.h"
#include "lwip/tcp_impl.h"
#include "lwip/snmp.h"
#include "lwip/dhcp.h"
#include "lwip/autoip.h"
#include "lwip/stats.h"
#include "arch/perf.h"
#include <string.h>
Macros | |
#define | CHECKSUM_GEN_IP_INLINE 1 |
#define | IP_ACCEPT_LINK_LAYER_ADDRESSING 0 |
#define | LWIP_INLINE_IP_CHKSUM 1 |
Set this to 0 in the rare case of wanting to call an extra function to generate the IP checksum (in contrast to calculating it on-the-fly). More... | |
Functions | |
err_t | ip_input (struct pbuf *p, struct netif *inp) |
This function is called by the network interface device driver when an IP packet is received. More... | |
err_t | ip_output (struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, u8_t ttl, u8_t tos, u8_t proto) |
Simple interface to ip_output_if. More... | |
err_t | ip_output_if (struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, u8_t ttl, u8_t tos, u8_t proto, struct netif *netif) |
Sends an IP packet on a network interface. More... | |
struct netif * | ip_route (ip_addr_t *dest) |
Finds the appropriate network interface for a given IP address. More... | |
Variables | |
struct ip_hdr * | current_header |
Header of the input packet currently being processed. More... | |
ip_addr_t | current_iphdr_dest |
Destination IP address of current_header. More... | |
ip_addr_t | current_iphdr_src |
Source IP address of current_header. More... | |
struct netif * | current_netif |
The interface that provided the packet for the current callback invocation. More... | |
static u16_t | ip_id |
The IP header ID of the next outgoing IP packet. More... | |
#define CHECKSUM_GEN_IP_INLINE 1 |
#define IP_ACCEPT_LINK_LAYER_ADDRESSING 0 |
#define LWIP_INLINE_IP_CHKSUM 1 |
Set this to 0 in the rare case of wanting to call an extra function to generate the IP checksum (in contrast to calculating it on-the-fly).
This function is called by the network interface device driver when an IP packet is received.
The function does the basic checks of the IP header such as packet size being at least larger than the header size etc. If the packet was not destined for us, the packet is forwarded (using ip_forward). The IP checksum is always checked.
Finally, the packet is sent to the upper layer protocol input function.
p | the received IP packet (p->payload points to IP header) |
inp | the netif on which this packet was received |
References current_iphdr_dest, current_iphdr_src, ERR_OK, netif::flags, icmp_dest_unreach(), ICMP_DUR_PROTO, icmp_input(), if(), inet_chksum(), ip4_addr_get_u32, netif::ip_addr, ip_addr_cmp, ip_addr_copy, ip_addr_isany, ip_addr_isbroadcast, ip_addr_ismulticast, ip_addr_set_any, IP_DEBUG, ip_debug_print, IP_HLEN, IP_MF, IP_OFFMASK, IP_PROTO_ICMP, IP_PROTO_IGMP, IP_PROTO_TCP, IP_PROTO_UDP, IP_PROTO_UDPLITE, ip_reass(), IP_STATS_INC, IPH_HL, IPH_ID, IPH_LEN, IPH_OFFSET, IPH_PROTO, IPH_V, iphdr, pbuf::len, LWIP_DBG_LEVEL_SERIOUS, LWIP_DBG_LEVEL_WARNING, LWIP_DBG_TRACE, LWIP_DEBUGF, netif::name, NETIF_FLAG_IGMP, netif_is_up, netif_list, netif::netmask, netif::next, ntohs, NULL, pbuf::payload, pbuf_free(), pbuf_realloc(), PP_HTONS, snmp_inc_ipinaddrerrors, snmp_inc_ipindelivers, snmp_inc_ipindiscards, snmp_inc_ipinhdrerrors, snmp_inc_ipinreceives, snmp_inc_ipinunknownprotos, tcp_input(), pbuf::tot_len, udp_input(), X16_F, and X32_F.
Referenced by ethernet_input(), and netif_init().
err_t ip_output | ( | struct pbuf * | p, |
ip_addr_t * | src, | ||
ip_addr_t * | dest, | ||
u8_t | ttl, | ||
u8_t | tos, | ||
u8_t | proto | ||
) |
Simple interface to ip_output_if.
It finds the outgoing network interface and calls upon ip_output_if to do the actual work.
p | the packet to send (p->payload points to the data, e.g. next protocol header; if dest == IP_HDRINCL, p already includes an IP header and p->payload points to that IP header) |
src | the source IP address to send from (if src == IP_ADDR_ANY, the IP address of the netif used to send is used as source address) |
dest | the destination IP address to send the packet to |
ttl | the TTL value to be set in the IP header |
tos | the TOS value to be set in the IP header |
proto | the PROTOCOL to be set in the IP header |
References ERR_RTE, ip4_addr1_16, ip4_addr2_16, ip4_addr3_16, ip4_addr4_16, IP_DEBUG, ip_output_if(), ip_route(), IP_STATS_INC, LWIP_ASSERT, LWIP_DEBUGF, NULL, and pbuf::ref.
Referenced by icmp_send_response(), tcp_keepalive(), tcp_output_segment(), tcp_rst(), tcp_send_empty_ack(), and tcp_zero_window_probe().
err_t ip_output_if | ( | struct pbuf * | p, |
ip_addr_t * | src, | ||
ip_addr_t * | dest, | ||
u8_t | ttl, | ||
u8_t | tos, | ||
u8_t | proto, | ||
struct netif * | netif | ||
) |
Sends an IP packet on a network interface.
This function constructs the IP header and calculates the IP header checksum. If the source IP address is NULL, the IP address of the outgoing network interface is filled in as source address. If the destination IP address is IP_HDRINCL, p is assumed to already include an IP header and p->payload points to it instead of the data.
p | the packet to send (p->payload points to the data, e.g. next protocol header; if dest == IP_HDRINCL, p already includes an IP header and p->payload points to that IP header) |
src | the source IP address to send from (if src == IP_ADDR_ANY, the IP address of the netif used to send is used as source address) |
dest | the destination IP address to send the packet to |
ttl | the TTL value to be set in the IP header |
tos | the TOS value to be set in the IP header |
proto | the PROTOCOL to be set in the IP header |
netif | the netif on which to send this packet |
References NULL.
Referenced by icmp_input(), and ip_output().
Finds the appropriate network interface for a given IP address.
It searches the list of network interfaces linearly. A match is found if the masked IP address of the network interface equals the masked IP address given to the function.
dest | the destination IP address for which to find the route |
References ip4_addr1_16, ip4_addr2_16, ip4_addr3_16, ip4_addr4_16, netif::ip_addr, ip_addr_netcmp, IP_DEBUG, IP_STATS_INC, LWIP_DBG_LEVEL_SERIOUS, LWIP_DEBUGF, netif_default, netif_is_up, netif_list, netif::netmask, netif::next, NULL, snmp_inc_ipoutnoroutes, and U16_F.
Referenced by etharp_update_arp_entry(), ip_output(), tcp_connect(), tcp_eff_send_mss(), tcp_output_segment(), and udp_connect().
struct ip_hdr* current_header |
Header of the input packet currently being processed.
ip_addr_t current_iphdr_dest |
Destination IP address of current_header.
Referenced by icmp_input(), ip_input(), tcp_input(), tcp_listen_input(), and udp_input().
ip_addr_t current_iphdr_src |
Source IP address of current_header.
Referenced by ip_input(), tcp_input(), tcp_listen_input(), and udp_input().
struct netif* current_netif |
The interface that provided the packet for the current callback invocation.
|
static |
The IP header ID of the next outgoing IP packet.