64 #ifndef LWIP_INLINE_IP_CHKSUM 65 #if LWIP_CHECKSUM_CTRL_PER_NETIF 66 #define LWIP_INLINE_IP_CHKSUM 0 68 #define LWIP_INLINE_IP_CHKSUM 1 72 #if LWIP_INLINE_IP_CHKSUM && CHECKSUM_GEN_IP 73 #define CHECKSUM_GEN_IP_INLINE 1 75 #define CHECKSUM_GEN_IP_INLINE 0 78 #if LWIP_DHCP || defined(LWIP_IP_ACCEPT_UDP_PORT) 79 #define IP_ACCEPT_LINK_LAYER_ADDRESSING 1 86 #if LWIP_DHCP && defined(LWIP_IP_ACCEPT_UDP_PORT) 88 #define IP_ACCEPT_LINK_LAYER_ADDRESSED_PORT(port) (((port) == PP_NTOHS(DHCP_CLIENT_PORT)) \ 89 || (LWIP_IP_ACCEPT_UDP_PORT(port))) 90 #elif defined(LWIP_IP_ACCEPT_UDP_PORT) 92 #define IP_ACCEPT_LINK_LAYER_ADDRESSED_PORT(port) (LWIP_IP_ACCEPT_UDP_PORT(port)) 95 #define IP_ACCEPT_LINK_LAYER_ADDRESSED_PORT(port) ((port) == PP_NTOHS(DHCP_CLIENT_PORT)) 99 #define IP_ACCEPT_LINK_LAYER_ADDRESSING 0 108 #if LWIP_MULTICAST_TX_OPTIONS 110 static struct netif* ip4_default_multicast_netif;
114 ip4_set_default_multicast_netif(
struct netif* default_multicast_netif)
116 ip4_default_multicast_netif = default_multicast_netif;
120 #ifdef LWIP_HOOK_IP4_ROUTE_SRC 126 ip4_route_src(
const ip4_addr_t *dest,
const ip4_addr_t *src)
129 struct netif *
netif = LWIP_HOOK_IP4_ROUTE_SRC(dest, src);
134 return ip4_route(dest);
148 ip4_route(
const ip4_addr_t *dest)
152 #ifdef LWIP_HOOK_IP4_ROUTE_SRC 153 netif = LWIP_HOOK_IP4_ROUTE_SRC(dest,
NULL);
157 #elif defined(LWIP_HOOK_IP4_ROUTE) 158 netif = LWIP_HOOK_IP4_ROUTE(dest);
164 #if LWIP_MULTICAST_TX_OPTIONS 166 if (ip4_addr_ismulticast(dest) && ip4_default_multicast_netif) {
167 return ip4_default_multicast_netif;
176 if (ip4_addr_netcmp(dest, netif_ip4_addr(netif), netif_ip4_netmask(netif))) {
188 #if LWIP_NETIF_LOOPBACK && !LWIP_HAVE_LOOPIF 190 if (ip4_addr_isloopback(dest)) {
210 ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest)));
229 ip4_canforward(
struct pbuf *p)
231 u32_t addr =
htonl(ip4_addr_get_u32(ip4_current_dest_addr()));
242 if (IP_EXPERIMENTAL(addr)) {
245 if (IP_CLASSA(addr)) {
246 u32_t net = addr & IP_CLASSA_NET;
247 if ((net == 0) || (net == ((
u32_t)IP_LOOPBACKNET << IP_CLASSA_NSHIFT))) {
265 ip4_forward(
struct pbuf *p,
struct ip_hdr *iphdr,
struct netif *inp)
271 if (!ip4_canforward(p)) {
276 if (ip4_addr_islinklocal(ip4_current_dest_addr())) {
277 LWIP_DEBUGF(
IP_DEBUG, (
"ip_forward: not forwarding LLA %"U16_F
".%"U16_F
".%"U16_F
".%"U16_F
"\n",
278 ip4_addr1_16(ip4_current_dest_addr()), ip4_addr2_16(ip4_current_dest_addr()),
279 ip4_addr3_16(ip4_current_dest_addr()), ip4_addr4_16(ip4_current_dest_addr())));
284 netif = ip4_route_src(ip4_current_dest_addr(), ip4_current_src_addr());
286 LWIP_DEBUGF(
IP_DEBUG, (
"ip_forward: no forwarding route for %"U16_F
".%"U16_F
".%"U16_F
".%"U16_F
" found\n",
287 ip4_addr1_16(ip4_current_dest_addr()), ip4_addr2_16(ip4_current_dest_addr()),
288 ip4_addr3_16(ip4_current_dest_addr()), ip4_addr4_16(ip4_current_dest_addr())));
292 #if !IP_FORWARD_ALLOW_TX_ON_RX_NETIF 302 IPH_TTL_SET(iphdr, IPH_TTL(iphdr) - 1);
304 if (IPH_TTL(iphdr) == 0) {
316 if (IPH_CHKSUM(iphdr) >=
PP_HTONS(0xffffU - 0x100)) {
317 IPH_CHKSUM_SET(iphdr, IPH_CHKSUM(iphdr) +
PP_HTONS(0x100) + 1);
319 IPH_CHKSUM_SET(iphdr, IPH_CHKSUM(iphdr) +
PP_HTONS(0x100));
322 LWIP_DEBUGF(
IP_DEBUG, (
"ip_forward: forwarding packet to %"U16_F
".%"U16_F
".%"U16_F
".%"U16_F
"\n",
323 ip4_addr1_16(ip4_current_dest_addr()), ip4_addr2_16(ip4_current_dest_addr()),
324 ip4_addr3_16(ip4_current_dest_addr()), ip4_addr4_16(ip4_current_dest_addr())));
333 if ((IPH_OFFSET(iphdr) &
PP_NTOHS(IP_DF)) == 0) {
335 ip4_frag(p, netif, ip4_current_dest_addr());
348 netif->output(netif, p, ip4_current_dest_addr());
365 return ip6_input(p, inp);
367 return ip4_input(p, inp);
371 return ip4_input(p, inp);
377 u16_t UDANTE_UDPPort = 0;
395 ip4_input(
struct pbuf *p,
struct netif *inp)
397 struct ip_hdr *iphdr;
401 #if IP_ACCEPT_LINK_LAYER_ADDRESSING || LWIP_IGMP 402 int check_ip_src = 1;
413 iphdr = (
struct ip_hdr *)p->
payload;
414 if (IPH_V(iphdr) != 4) {
424 #ifdef LWIP_HOOK_IP4_INPUT 425 if (LWIP_HOOK_IP4_INPUT(p, inp)) {
432 iphdr_hlen = IPH_HL(iphdr);
436 iphdr_len =
ntohs(IPH_LEN(iphdr));
439 if (iphdr_len < p->tot_len) {
444 if ((iphdr_hlen > p->
len) || (iphdr_len > p->
tot_len)) {
445 if (iphdr_hlen > p->
len) {
447 (
"IP header (len %"U16_F
") does not fit in first pbuf (len %"U16_F
"), IP packet dropped.\n",
448 iphdr_hlen, p->
len));
452 (
"IP (len %"U16_F
") is longer than pbuf (len %"U16_F
"), IP packet dropped.\n",
464 #if CHECKSUM_CHECK_IP 469 (
"Checksum (0x%"X16_F") failed, IP packet dropped.\n",
inet_chksum(iphdr, iphdr_hlen)));
489 unsigned char *udp = (
unsigned char *)p->
payload;
491 UDANTE_UDPPort = *udp++ << 8;
492 UDANTE_UDPPort |= *udp;
493 if ((UDANTE_UDPPort >= 14336) && (UDANTE_UDPPort <= 14600))
495 ip_addr_copy_from_ip4(UDANTE_IPAddr, iphdr->dest);
502 if (ip4_addr_ismulticast(ip4_current_dest_addr())) {
505 ip4_addr_t allsystems;
506 IP4_ADDR(&allsystems, 224, 0, 0, 1);
507 if (ip4_addr_cmp(ip4_current_dest_addr(), &allsystems) &&
525 ip4_addr_get_u32(&iphdr->dest), ip4_addr_get_u32(netif_ip4_addr(netif)),
526 ip4_addr_get_u32(&iphdr->dest) & ip4_addr_get_u32(netif_ip4_netmask(netif)),
527 ip4_addr_get_u32(netif_ip4_addr(netif)) & ip4_addr_get_u32(netif_ip4_netmask(netif)),
528 ip4_addr_get_u32(&iphdr->dest) & ~ip4_addr_get_u32(netif_ip4_netmask(netif))));
531 if ((
netif_is_up(netif)) && (!ip4_addr_isany_val(*netif_ip4_addr(netif)))) {
533 if (ip4_addr_cmp(ip4_current_dest_addr(), netif_ip4_addr(netif)) ||
537 || (ip4_addr_get_u32(ip4_current_dest_addr()) ==
PP_HTONL(IPADDR_LOOPBACK))
548 if ((netif->autoip !=
NULL) &&
549 ip4_addr_cmp(ip4_current_dest_addr(), &(netif->autoip->llipaddr))) {
566 }
while (netif !=
NULL);
569 #if IP_ACCEPT_LINK_LAYER_ADDRESSING 582 struct udp_hdr *udphdr = (
struct udp_hdr *)((
u8_t *)iphdr + iphdr_hlen);
584 ntohs(udphdr->dest)));
585 if (IP_ACCEPT_LINK_LAYER_ADDRESSED_PORT(udphdr->dest)) {
595 #if LWIP_IGMP || IP_ACCEPT_LINK_LAYER_ADDRESSING 597 #
if IP_ACCEPT_LINK_LAYER_ADDRESSING
625 ip4_forward(p, iphdr, inp);
636 if ((IPH_OFFSET(iphdr) &
PP_HTONS(IP_OFFMASK | IP_MF)) != 0) {
638 LWIP_DEBUGF(
IP_DEBUG, (
"IP packet is a fragment (id=0x%04"X16_F" tot_len=%"U16_F
" len=%"U16_F
" MF=%"U16_F
" offset=%"U16_F
"), calling ip4_reass()\n",
646 iphdr = (
struct ip_hdr *)p->
payload;
650 ntohs(IPH_OFFSET(iphdr))));
659 #if IP_OPTIONS_ALLOWED == 0 663 if ((iphdr_hlen > IP_HLEN) && (IPH_PROTO(iphdr) !=
IP_PROTO_IGMP)) {
665 if (iphdr_hlen > IP_HLEN) {
684 ip_data.current_ip4_header = iphdr;
689 if (raw_input(p, inp) == 0)
694 switch (IPH_PROTO(iphdr)) {
718 igmp_input(p, inp, ip4_current_dest_addr());
746 ip4_addr_set_any(ip4_current_src_addr());
747 ip4_addr_set_any(ip4_current_dest_addr());
778 ip4_output_if(
struct pbuf *p,
const ip4_addr_t *src,
const ip4_addr_t *dest,
780 u8_t proto,
struct netif *netif)
783 return ip4_output_if_opt(p, src, dest, ttl, tos, proto, netif,
NULL, 0);
792 err_t ip4_output_if_opt(
struct pbuf *p,
const ip4_addr_t *src,
const ip4_addr_t *dest,
793 u8_t ttl,
u8_t tos,
u8_t proto,
struct netif *netif,
void *ip_options,
797 const ip4_addr_t *src_used = src;
799 if (ip4_addr_isany(src)) {
800 src_used = netif_ip4_addr(netif);
805 return ip4_output_if_opt_src(p, src_used, dest, ttl, tos, proto, netif,
808 return ip4_output_if_src(p, src_used, dest, ttl, tos, proto, netif);
817 ip4_output_if_src(
struct pbuf *p,
const ip4_addr_t *src,
const ip4_addr_t *dest,
819 u8_t proto,
struct netif *netif)
822 return ip4_output_if_opt_src(p, src, dest, ttl, tos, proto, netif,
NULL, 0);
829 err_t ip4_output_if_opt_src(
struct pbuf *p,
const ip4_addr_t *src,
const ip4_addr_t *dest,
830 u8_t ttl,
u8_t tos,
u8_t proto,
struct netif *netif,
void *ip_options,
834 struct ip_hdr *iphdr;
835 ip4_addr_t dest_addr;
836 #if CHECKSUM_GEN_IP_INLINE 846 u16_t ip_hlen = IP_HLEN;
848 u16_t optlen_aligned = 0;
850 #if CHECKSUM_GEN_IP_INLINE 854 optlen_aligned = ((optlen + 3) & ~3);
855 ip_hlen += optlen_aligned;
864 if (optlen < optlen_aligned) {
866 memset(((
char*)p->
payload) + optlen, 0, optlen_aligned - optlen);
868 #if CHECKSUM_GEN_IP_INLINE 869 for (i = 0; i < optlen_aligned/2; i++) {
884 iphdr = (
struct ip_hdr *)p->
payload;
885 LWIP_ASSERT(
"check that first pbuf can hold struct ip_hdr",
886 (p->
len >=
sizeof(
struct ip_hdr)));
888 IPH_TTL_SET(iphdr, ttl);
889 IPH_PROTO_SET(iphdr, proto);
890 #if CHECKSUM_GEN_IP_INLINE 895 ip4_addr_copy(iphdr->dest, *dest);
896 #if CHECKSUM_GEN_IP_INLINE 897 chk_sum += ip4_addr_get_u32(&iphdr->dest) & 0xFFFF;
898 chk_sum += ip4_addr_get_u32(&iphdr->dest) >> 16;
901 IPH_VHL_SET(iphdr, 4, ip_hlen / 4);
902 IPH_TOS_SET(iphdr, tos);
903 #if CHECKSUM_GEN_IP_INLINE 907 #if CHECKSUM_GEN_IP_INLINE 908 chk_sum += iphdr->_len;
910 IPH_OFFSET_SET(iphdr, 0);
911 IPH_ID_SET(iphdr,
htons(ip_id));
912 #if CHECKSUM_GEN_IP_INLINE 913 chk_sum += iphdr->_id;
918 ip4_addr_copy(iphdr->src, *IP4_ADDR_ANY);
921 ip4_addr_copy(iphdr->src, *src);
924 #if CHECKSUM_GEN_IP_INLINE 925 chk_sum += ip4_addr_get_u32(&iphdr->src) & 0xFFFF;
926 chk_sum += ip4_addr_get_u32(&iphdr->src) >> 16;
927 chk_sum = (chk_sum >> 16) + (chk_sum & 0xFFFF);
928 chk_sum = (chk_sum >> 16) + chk_sum;
931 iphdr->_chksum = (
u16_t)chk_sum;
933 #if LWIP_CHECKSUM_CTRL_PER_NETIF 935 IPH_CHKSUM_SET(iphdr, 0);
939 IPH_CHKSUM_SET(iphdr, 0);
942 IPH_CHKSUM_SET(iphdr,
inet_chksum(iphdr, ip_hlen));
948 iphdr = (
struct ip_hdr *)p->
payload;
949 ip4_addr_copy(dest_addr, iphdr->dest);
959 if (ip4_addr_cmp(dest, netif_ip4_addr(netif))
961 || ip4_addr_isloopback(dest)
966 return netif_loop_output(netif, p);
968 #if LWIP_MULTICAST_TX_OPTIONS 970 netif_loop_output(netif, p);
977 return ip4_frag(p, netif, dest);
982 return netif->output(netif, p, dest);
1003 ip4_output(
struct pbuf *p,
const ip4_addr_t *src,
const ip4_addr_t *dest,
1006 struct netif *netif;
1010 if ((netif = ip4_route_src(dest, src)) ==
NULL) {
1012 ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest)));
1017 return ip4_output_if(p, src, dest, ttl, tos, proto, netif);
1020 #if LWIP_NETIF_HWADDRHINT 1040 ip4_output_hinted(
struct pbuf *p,
const ip4_addr_t *src,
const ip4_addr_t *dest,
1043 struct netif *netif;
1048 if ((netif = ip4_route_src(dest, src)) ==
NULL) {
1050 ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest)));
1056 err = ip4_output_if(p, src, dest, ttl, tos, proto, netif);
1068 ip4_debug_print(
struct pbuf *p)
1070 struct ip_hdr *iphdr = (
struct ip_hdr *)p->
payload;
1078 ntohs(IPH_LEN(iphdr))));
1080 LWIP_DEBUGF(
IP_DEBUG, (
"| %5"U16_F
" |%"U16_F
"%"U16_F
"%"U16_F
"| %4"U16_F
" | (id, flags, offset)\n",
1081 ntohs(IPH_ID(iphdr)),
1082 ntohs(IPH_OFFSET(iphdr)) >> 15 & 1,
1083 ntohs(IPH_OFFSET(iphdr)) >> 14 & 1,
1084 ntohs(IPH_OFFSET(iphdr)) >> 13 & 1,
1085 ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK));
1090 ntohs(IPH_CHKSUM(iphdr))));
1093 ip4_addr1_16(&iphdr->src),
1094 ip4_addr2_16(&iphdr->src),
1095 ip4_addr3_16(&iphdr->src),
1096 ip4_addr4_16(&iphdr->src)));
1099 ip4_addr1_16(&iphdr->dest),
1100 ip4_addr2_16(&iphdr->dest),
1101 ip4_addr3_16(&iphdr->dest),
1102 ip4_addr4_16(&iphdr->dest)));
#define MIB2_STATS_INC(x)
struct netif * netif_list
#define LWIP_DBG_LEVEL_SERIOUS
#define ip_addr_isany(ipaddr)
struct netif * netif_default
#define LWIP_DBG_LEVEL_WARNING
#define ip_addr_isany_val(ipaddr)
u8_t pbuf_header(struct pbuf *p, s16_t header_size_increment)
void pbuf_realloc(struct pbuf *p, u16_t new_len)
#define netif_is_link_up(netif)
ip_addr_t current_iphdr_dest
err_t ip_input(struct pbuf *p, struct netif *inp)
#define PBUF_FLAG_LLBCAST
#define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag)
#define MEMCPY(dst, src, len)
#define ip_addr_isbroadcast(addr, netif)
#define ip_current_dest_addr()
u16_t current_ip_header_tot_len
#define ip_addr_ismulticast(ipaddr)
u16_t inet_chksum(const void *dataptr, u16_t len)
ip_addr_t current_iphdr_src
#define PBUF_FLAG_MCASTLOOP
struct netif * current_netif
u8_t pbuf_free(struct pbuf *p)
#define LWIP_NETIF_LOOPBACK
#define NETIF_SET_HWADDRHINT(netif, hint)
#define NETIF_FLAG_BROADCAST
#define LWIP_ASSERT(message, assertion)
#define PBUF_FLAG_LLMCAST
struct ip_globals ip_data
#define LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX(p)
#define ip_current_src_addr()
u8_t pbuf_header_force(struct pbuf *p, s16_t header_size_increment)
#define netif_is_up(netif)
#define IP_HDR_GET_VERSION(ptr)
#define LWIP_MAKE_U16(a, b)
#define LWIP_DEBUGF(debug, message)
struct netif * current_input_netif