62#ifdef LWIP_HOOK_FILENAME
63#include LWIP_HOOK_FILENAME
68#ifndef LWIP_INLINE_IP_CHKSUM
69#if LWIP_CHECKSUM_CTRL_PER_NETIF
70#define LWIP_INLINE_IP_CHKSUM 0
72#define LWIP_INLINE_IP_CHKSUM 1
76#if LWIP_INLINE_IP_CHKSUM && CHECKSUM_GEN_IP
77#define CHECKSUM_GEN_IP_INLINE 1
79#define CHECKSUM_GEN_IP_INLINE 0
82#if LWIP_DHCP || defined(LWIP_IP_ACCEPT_UDP_PORT)
83#define IP_ACCEPT_LINK_LAYER_ADDRESSING 1
90#if LWIP_DHCP && defined(LWIP_IP_ACCEPT_UDP_PORT)
92#define IP_ACCEPT_LINK_LAYER_ADDRESSED_PORT(port) (((port) == PP_NTOHS(LWIP_IANA_PORT_DHCP_CLIENT)) \
93 || (LWIP_IP_ACCEPT_UDP_PORT(port)))
94#elif defined(LWIP_IP_ACCEPT_UDP_PORT)
96#define IP_ACCEPT_LINK_LAYER_ADDRESSED_PORT(port) (LWIP_IP_ACCEPT_UDP_PORT(port))
99#define IP_ACCEPT_LINK_LAYER_ADDRESSED_PORT(port) ((port) == PP_NTOHS(LWIP_IANA_PORT_DHCP_CLIENT))
103#define IP_ACCEPT_LINK_LAYER_ADDRESSING 0
109#if LWIP_MULTICAST_TX_OPTIONS
111static struct netif *ip4_default_multicast_netif;
117ip4_set_default_multicast_netif(
struct netif *default_multicast_netif)
119 ip4_default_multicast_netif = default_multicast_netif;
123#ifdef LWIP_HOOK_IP4_ROUTE_SRC
129ip4_route_src(
const ip4_addr_t *
src,
const ip4_addr_t *
dest)
138 return ip4_route(
dest);
152ip4_route(
const ip4_addr_t *
dest)
154#if !LWIP_SINGLE_NETIF
159#if LWIP_MULTICAST_TX_OPTIONS
161 if (ip4_addr_ismulticast(
dest) && ip4_default_multicast_netif) {
162 return ip4_default_multicast_netif;
174 if (ip4_addr_net_eq(
dest, netif_ip4_addr(
netif), netif_ip4_netmask(
netif))) {
186#if LWIP_NETIF_LOOPBACK && !LWIP_HAVE_LOOPIF
188 if (ip4_addr_isloopback(
dest)) {
203#ifdef LWIP_HOOK_IP4_ROUTE_SRC
208#elif defined(LWIP_HOOK_IP4_ROUTE)
217 ip4_addr_isany_val(*netif_ip4_addr(
netif_default)) || ip4_addr_isloopback(
dest)) {
221 ip4_addr1_16(
dest), ip4_addr2_16(
dest), ip4_addr3_16(
dest), ip4_addr4_16(
dest)));
239ip4_canforward(
struct pbuf *
p)
243#ifdef LWIP_HOOK_IP4_CANFORWARD
244 int ret = LWIP_HOOK_IP4_CANFORWARD(
p,
addr);
258 if (IP_EXPERIMENTAL(
addr)) {
261 if (IP_CLASSA(
addr)) {
263 if ((
net == 0) || (
net == ((
u32_t)IP_LOOPBACKNET << IP_CLASSA_NSHIFT))) {
288 if (!ip4_canforward(
p)) {
293 if (ip4_addr_islinklocal(ip4_current_dest_addr())) {
295 ip4_addr1_16(ip4_current_dest_addr()), ip4_addr2_16(ip4_current_dest_addr()),
296 ip4_addr3_16(ip4_current_dest_addr()), ip4_addr4_16(ip4_current_dest_addr())));
301 netif = ip4_route_src(ip4_current_src_addr(), ip4_current_dest_addr());
304 ip4_addr1_16(ip4_current_dest_addr()), ip4_addr2_16(ip4_current_dest_addr()),
305 ip4_addr3_16(ip4_current_dest_addr()), ip4_addr4_16(ip4_current_dest_addr())));
309#if !IP_FORWARD_ALLOW_TX_ON_RX_NETIF
313 LWIP_DEBUGF(
IP_DEBUG, (
"ip4_forward: not bouncing packets back on incoming interface.\n"));
374 ip4_addr1_16(ip4_current_dest_addr()), ip4_addr2_16(ip4_current_dest_addr()),
375 ip4_addr3_16(ip4_current_dest_addr()), ip4_addr4_16(ip4_current_dest_addr())));
386 ip4_frag(
p,
netif, ip4_current_dest_addr());
411 ip4_addr_get_u32(ip4_current_dest_addr()), ip4_addr_get_u32(netif_ip4_addr(
netif)),
412 ip4_addr_get_u32(ip4_current_dest_addr()) & ip4_addr_get_u32(netif_ip4_netmask(
netif)),
413 ip4_addr_get_u32(netif_ip4_addr(
netif)) & ip4_addr_get_u32(netif_ip4_netmask(
netif)),
414 ip4_addr_get_u32(ip4_current_dest_addr()) & ~ip4_addr_get_u32(netif_ip4_netmask(
netif))));
419 if (ip4_addr_eq(ip4_current_dest_addr(), netif_ip4_addr(
netif)) ||
421 ip4_addr_isbroadcast(ip4_current_dest_addr(),
netif)
423 || (ip4_addr_get_u32(ip4_current_dest_addr()) ==
PP_HTONL(IPADDR_LOOPBACK))
434 if (autoip_accept_packet(
netif, ip4_current_dest_addr())) {
462 const struct ip_hdr *iphdr;
466#if IP_ACCEPT_LINK_LAYER_ADDRESSING || LWIP_IGMP
467 int check_ip_src = 1;
470 raw_input_state_t raw_status;
479 iphdr = (
struct ip_hdr *)
p->payload;
490#ifdef LWIP_HOOK_IP4_INPUT
491 if (LWIP_HOOK_IP4_INPUT(
p, inp)) {
503 if (iphdr_len < p->tot_len) {
508 if ((iphdr_hlen >
p->len) || (iphdr_len >
p->tot_len) || (iphdr_hlen <
IP_HLEN)) {
511 (
"ip4_input: short IP header (%"U16_F" bytes) received, IP packet dropped\n", iphdr_hlen));
513 if (iphdr_hlen >
p->len) {
515 (
"IP header (len %"U16_F") does not fit in first pbuf (len %"U16_F"), IP packet dropped.\n",
516 iphdr_hlen,
p->len));
518 if (iphdr_len >
p->tot_len) {
520 (
"IP (len %"U16_F") is longer than pbuf (len %"U16_F"), IP packet dropped.\n",
521 iphdr_len,
p->tot_len));
537 (
"Checksum (0x%"X16_F") failed, IP packet dropped.\n",
inet_chksum(iphdr, iphdr_hlen)));
549 ip_addr_copy_from_ip4(
ip_data.current_iphdr_dest, iphdr->dest);
550 ip_addr_copy_from_ip4(
ip_data.current_iphdr_src, iphdr->src);
553 if (ip4_addr_ismulticast(ip4_current_dest_addr())) {
557 ip4_addr_t allsystems;
558 IP4_ADDR(&allsystems, 224, 0, 0, 1);
559 if (ip4_addr_eq(ip4_current_dest_addr(), &allsystems) &&
560 ip4_addr_isany(ip4_current_src_addr())) {
568 if ((
netif_is_up(inp)) && (!ip4_addr_isany_val(*netif_ip4_addr(inp)))) {
577 if (ip4_input_accept(inp)) {
581#if !LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF
585 if (!ip4_addr_isloopback(ip4_current_dest_addr()))
588#if !LWIP_SINGLE_NETIF
594 if (ip4_input_accept(
netif)) {
603#if IP_ACCEPT_LINK_LAYER_ADDRESSING
619 if (IP_ACCEPT_LINK_LAYER_ADDRESSED_PORT(
udphdr->dest)) {
629#if LWIP_IGMP || IP_ACCEPT_LINK_LAYER_ADDRESSING
631#
if IP_ACCEPT_LINK_LAYER_ADDRESSING
633 && !ip4_addr_isany_val(*ip4_current_src_addr())
638 if ((ip4_addr_isbroadcast(ip4_current_src_addr(), inp)) ||
639 (ip4_addr_ismulticast(ip4_current_src_addr()))) {
657 if (!ip4_addr_isbroadcast(ip4_current_dest_addr(), inp)) {
659 ip4_forward(
p, (
struct ip_hdr *)
p->payload, inp);
681 iphdr = (
const struct ip_hdr *)
p->payload;
694#if IP_OPTIONS_ALLOWED == 0
718 ip_data.current_input_netif = inp;
719 ip_data.current_ip4_header = iphdr;
724 raw_status = raw_input(
p, inp);
725 if (raw_status != RAW_INPUT_EATEN)
754 igmp_input(
p, inp, ip4_current_dest_addr());
759 if (raw_status == RAW_INPUT_DELIVERED) {
766 if (!ip4_addr_isbroadcast(ip4_current_dest_addr(),
netif) &&
767 !ip4_addr_ismulticast(ip4_current_dest_addr())) {
788 ip_data.current_ip_header_tot_len = 0;
789 ip4_addr_set_any(ip4_current_src_addr());
790 ip4_addr_set_any(ip4_current_dest_addr());
821ip4_output_if(
struct pbuf *
p,
const ip4_addr_t *
src,
const ip4_addr_t *
dest,
836ip4_output_if_opt(
struct pbuf *
p,
const ip4_addr_t *
src,
const ip4_addr_t *
dest,
841 const ip4_addr_t *src_used =
src;
843 if (ip4_addr_isany(
src)) {
844 src_used = netif_ip4_addr(
netif);
849 return ip4_output_if_opt_src(
p, src_used,
dest, ttl, tos,
proto,
netif,
861ip4_output_if_src(
struct pbuf *
p,
const ip4_addr_t *
src,
const ip4_addr_t *
dest,
874ip4_output_if_opt_src(
struct pbuf *
p,
const ip4_addr_t *
src,
const ip4_addr_t *
dest,
880 ip4_addr_t dest_addr;
881#if CHECKSUM_GEN_IP_INLINE
894 u16_t optlen_aligned = 0;
896#if CHECKSUM_GEN_IP_INLINE
907 optlen_aligned = (
u16_t)((optlen + 3) & ~3);
908 ip_hlen = (
u16_t)(ip_hlen + optlen_aligned);
916 MEMCPY(
p->payload, ip_options, optlen);
917 if (optlen < optlen_aligned) {
919 memset(((
char *)
p->payload) + optlen, 0, (
size_t)(optlen_aligned - optlen));
921#if CHECKSUM_GEN_IP_INLINE
922 for (
i = 0;
i < optlen_aligned / 2;
i++) {
923 chk_sum += ((
u16_t *)
p->payload)[
i];
937 iphdr = (
struct ip_hdr *)
p->payload;
938 LWIP_ASSERT(
"check that first pbuf can hold struct ip_hdr",
939 (
p->len >=
sizeof(
struct ip_hdr)));
943#if CHECKSUM_GEN_IP_INLINE
948 ip4_addr_copy(iphdr->dest, *
dest);
949#if CHECKSUM_GEN_IP_INLINE
950 chk_sum += ip4_addr_get_u32(&iphdr->dest) & 0xFFFF;
951 chk_sum += ip4_addr_get_u32(&iphdr->dest) >> 16;
956#if CHECKSUM_GEN_IP_INLINE
957 chk_sum +=
PP_NTOHS(tos | (iphdr->_v_hl << 8));
960#if CHECKSUM_GEN_IP_INLINE
961 chk_sum += iphdr->_len;
965#if CHECKSUM_GEN_IP_INLINE
966 chk_sum += iphdr->_id;
971 ip4_addr_copy(iphdr->src, *IP4_ADDR_ANY4);
974 ip4_addr_copy(iphdr->src, *
src);
977#if CHECKSUM_GEN_IP_INLINE
978 chk_sum += ip4_addr_get_u32(&iphdr->src) & 0xFFFF;
979 chk_sum += ip4_addr_get_u32(&iphdr->src) >> 16;
980 chk_sum = (chk_sum >> 16) + (chk_sum & 0xFFFF);
981 chk_sum = (chk_sum >> 16) + chk_sum;
984 iphdr->_chksum = (
u16_t)chk_sum;
986#if LWIP_CHECKSUM_CTRL_PER_NETIF
1007 iphdr = (
struct ip_hdr *)
p->payload;
1008 ip4_addr_copy(dest_addr, iphdr->dest);
1018 if (ip4_addr_eq(
dest, netif_ip4_addr(
netif))
1020 || ip4_addr_isloopback(
dest)
1025 return netif_loop_output(
netif,
p);
1027#if LWIP_MULTICAST_TX_OPTIONS
1029 netif_loop_output(
netif,
p);
1062ip4_output(
struct pbuf *
p,
const ip4_addr_t *
src,
const ip4_addr_t *
dest,
1071 ip4_addr1_16(
dest), ip4_addr2_16(
dest), ip4_addr3_16(
dest), ip4_addr4_16(
dest)));
1079#if LWIP_NETIF_USE_HINTS
1099ip4_output_hinted(
struct pbuf *
p,
const ip4_addr_t *
src,
const ip4_addr_t *
dest,
1109 ip4_addr1_16(
dest), ip4_addr2_16(
dest), ip4_addr3_16(
dest), ip4_addr4_16(
dest)));
1127ip4_debug_print(
struct pbuf *
p)
1152 ip4_addr1_16_val(iphdr->src),
1153 ip4_addr2_16_val(iphdr->src),
1154 ip4_addr3_16_val(iphdr->src),
1155 ip4_addr4_16_val(iphdr->src)));
1158 ip4_addr1_16_val(iphdr->dest),
1159 ip4_addr2_16_val(iphdr->dest),
1160 ip4_addr3_16_val(iphdr->dest),
1161 ip4_addr4_16_val(iphdr->dest)));
#define LWIP_DEBUGF(debug, message)
#define LWIP_ASSERT(message, assertion)
#define LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX(p)
struct ip_globals ip_data
GLenum const GLvoid * addr
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
#define LWIP_UNUSED_ARG(x)
#define LWIP_DBG_LEVEL_SERIOUS
#define LWIP_DBG_LEVEL_WARNING
#define CHECKSUM_GEN_ICMP
#define LWIP_ASSERT_CORE_LOCKED()
#define LWIP_NETIF_LOOPBACK
#define NETIF_FLAG_BROADCAST
#define netif_is_up(netif)
void pbuf_realloc(struct pbuf *p, u16_t new_len)
u8_t pbuf_free(struct pbuf *p)
u16_t inet_chksum(const void *dataptr, u16_t len)
#define MEMCPY(DST, SRC, BYTES)
struct netif * netif_default
#define netif_is_link_up(netif)
#define NETIF_FOREACH(netif)
#define NETIF_RESET_HINTS(netif)
#define NETIF_CHECKSUM_ENABLED(netif, chksumflag)
#define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag)
#define NETIF_SET_HINTS(netif, netifhint)
u8_t pbuf_add_header(struct pbuf *p, size_t header_size_increment)
u8_t pbuf_remove_header(struct pbuf *p, size_t header_size_decrement)
u8_t pbuf_header_force(struct pbuf *p, s16_t header_size_increment)
#define PBUF_FLAG_LLBCAST
#define PBUF_FLAG_MCASTLOOP
#define PBUF_FLAG_LLMCAST
#define IPH_VHL_SET(hdr, v, hl)
#define IPH_LEN_SET(hdr, len)
#define IPH_HL_BYTES(hdr)
#define IPH_ID_SET(hdr, id)
#define IPH_PROTO_SET(hdr, proto)
#define IPH_OFFSET_SET(hdr, off)
#define IPH_TTL_SET(hdr, ttl)
#define IPH_CHKSUM_SET(hdr, chksum)
#define IPH_TOS_SET(hdr, tos)
#define MIB2_STATS_INC(x)