uc-sdk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ip.c File Reference
#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>

Go to the source code of this file.

Macros

#define LWIP_INLINE_IP_CHKSUM   1
 
#define CHECKSUM_GEN_IP_INLINE   0
 
#define IP_ACCEPT_LINK_LAYER_ADDRESSING   0
 

Functions

struct netifip_route (ip_addr_t *dest)
 
err_t ip_input (struct pbuf *p, struct netif *inp)
 
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)
 
err_t ip_output (struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, u8_t ttl, u8_t tos, u8_t proto)
 

Variables

struct netifcurrent_netif
 
struct ip_hdrcurrent_header
 
ip_addr_t current_iphdr_src
 
ip_addr_t current_iphdr_dest
 

Detailed Description

This is the IPv4 layer implementation for incoming and outgoing IP traffic.

See Also
ip_frag.c

Definition in file ip.c.

Macro Definition Documentation

#define CHECKSUM_GEN_IP_INLINE   0

Definition at line 69 of file ip.c.

#define IP_ACCEPT_LINK_LAYER_ADDRESSING   0

Definition at line 93 of file ip.c.

#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).

Definition at line 64 of file ip.c.

Function Documentation

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. 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.

Parameters
pthe received IP packet (p->payload points to IP header)
inpthe netif on which this packet was received
Returns
ERR_OK if the packet was processed (could return ERR_* if it wasn't processed, but currently always returns ERR_OK)

Definition at line 242 of file ip.c.

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.

Parameters
pthe 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)
srcthe 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)
destthe destination IP address to send the packet to
ttlthe TTL value to be set in the IP header
tosthe TOS value to be set in the IP header
protothe PROTOCOL to be set in the IP header
Returns
ERR_RTE if no route is found see ip_output_if() for more return values

Definition at line 748 of file ip.c.

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.

Parameters
pthe 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)
srcthe 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)
destthe destination IP address to send the packet to
ttlthe TTL value to be set in the IP header
tosthe TOS value to be set in the IP header
protothe PROTOCOL to be set in the IP header
netifthe netif on which to send this packet
Returns
ERR_OK if the packet was sent OK ERR_BUF if p doesn't have enough space for IP/LINK headers returns errors returned by netif->output
Note
ip_id: RFC791 "some host may be able to simply use unique identifiers independent of destination"

Definition at line 572 of file ip.c.

struct netif* ip_route ( ip_addr_t dest)

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.

Parameters
destthe destination IP address for which to find the route
Returns
the netif on which to send to reach dest

Definition at line 124 of file ip.c.

Variable Documentation

struct ip_hdr* current_header

Header of the input packet currently being processed.

Definition at line 105 of file ip.c.

ip_addr_t current_iphdr_dest

Destination IP address of current_header

Definition at line 109 of file ip.c.

ip_addr_t current_iphdr_src

Source IP address of current_header

Definition at line 107 of file ip.c.

struct netif* current_netif

The interface that provided the packet for the current callback invocation.

Definition at line 100 of file ip.c.