fdsf

Dependents:   sisk_proj_stat MQTT Hello_FXOS8700Q WireFSHandControl ... more

Committer:
grzemich
Date:
Wed Dec 07 23:47:50 2016 +0000
Revision:
0:d7bd7384a37c
dgd

Who changed what in which revision?

UserRevisionLine numberNew contents of line
grzemich 0:d7bd7384a37c 1 /**
grzemich 0:d7bd7384a37c 2 * @file
grzemich 0:d7bd7384a37c 3 * This is the IPv4 layer implementation for incoming and outgoing IP traffic.
grzemich 0:d7bd7384a37c 4 *
grzemich 0:d7bd7384a37c 5 * @see ip_frag.c
grzemich 0:d7bd7384a37c 6 *
grzemich 0:d7bd7384a37c 7 */
grzemich 0:d7bd7384a37c 8
grzemich 0:d7bd7384a37c 9 /*
grzemich 0:d7bd7384a37c 10 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
grzemich 0:d7bd7384a37c 11 * All rights reserved.
grzemich 0:d7bd7384a37c 12 *
grzemich 0:d7bd7384a37c 13 * Redistribution and use in source and binary forms, with or without modification,
grzemich 0:d7bd7384a37c 14 * are permitted provided that the following conditions are met:
grzemich 0:d7bd7384a37c 15 *
grzemich 0:d7bd7384a37c 16 * 1. Redistributions of source code must retain the above copyright notice,
grzemich 0:d7bd7384a37c 17 * this list of conditions and the following disclaimer.
grzemich 0:d7bd7384a37c 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
grzemich 0:d7bd7384a37c 19 * this list of conditions and the following disclaimer in the documentation
grzemich 0:d7bd7384a37c 20 * and/or other materials provided with the distribution.
grzemich 0:d7bd7384a37c 21 * 3. The name of the author may not be used to endorse or promote products
grzemich 0:d7bd7384a37c 22 * derived from this software without specific prior written permission.
grzemich 0:d7bd7384a37c 23 *
grzemich 0:d7bd7384a37c 24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
grzemich 0:d7bd7384a37c 25 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
grzemich 0:d7bd7384a37c 26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
grzemich 0:d7bd7384a37c 27 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
grzemich 0:d7bd7384a37c 28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
grzemich 0:d7bd7384a37c 29 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
grzemich 0:d7bd7384a37c 30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
grzemich 0:d7bd7384a37c 31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
grzemich 0:d7bd7384a37c 32 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
grzemich 0:d7bd7384a37c 33 * OF SUCH DAMAGE.
grzemich 0:d7bd7384a37c 34 *
grzemich 0:d7bd7384a37c 35 * This file is part of the lwIP TCP/IP stack.
grzemich 0:d7bd7384a37c 36 *
grzemich 0:d7bd7384a37c 37 * Author: Adam Dunkels <adam@sics.se>
grzemich 0:d7bd7384a37c 38 *
grzemich 0:d7bd7384a37c 39 */
grzemich 0:d7bd7384a37c 40
grzemich 0:d7bd7384a37c 41 #include "lwip/opt.h"
grzemich 0:d7bd7384a37c 42 #include "lwip/ip.h"
grzemich 0:d7bd7384a37c 43 #include "lwip/def.h"
grzemich 0:d7bd7384a37c 44 #include "lwip/mem.h"
grzemich 0:d7bd7384a37c 45 #include "lwip/ip_frag.h"
grzemich 0:d7bd7384a37c 46 #include "lwip/inet_chksum.h"
grzemich 0:d7bd7384a37c 47 #include "lwip/netif.h"
grzemich 0:d7bd7384a37c 48 #include "lwip/icmp.h"
grzemich 0:d7bd7384a37c 49 #include "lwip/igmp.h"
grzemich 0:d7bd7384a37c 50 #include "lwip/raw.h"
grzemich 0:d7bd7384a37c 51 #include "lwip/udp.h"
grzemich 0:d7bd7384a37c 52 #include "lwip/tcp_impl.h"
grzemich 0:d7bd7384a37c 53 #include "lwip/snmp.h"
grzemich 0:d7bd7384a37c 54 #include "lwip/dhcp.h"
grzemich 0:d7bd7384a37c 55 #include "lwip/autoip.h"
grzemich 0:d7bd7384a37c 56 #include "lwip/stats.h"
grzemich 0:d7bd7384a37c 57 #include "arch/perf.h"
grzemich 0:d7bd7384a37c 58
grzemich 0:d7bd7384a37c 59 #include <string.h>
grzemich 0:d7bd7384a37c 60
grzemich 0:d7bd7384a37c 61 /** Set this to 0 in the rare case of wanting to call an extra function to
grzemich 0:d7bd7384a37c 62 * generate the IP checksum (in contrast to calculating it on-the-fly). */
grzemich 0:d7bd7384a37c 63 #ifndef LWIP_INLINE_IP_CHKSUM
grzemich 0:d7bd7384a37c 64 #define LWIP_INLINE_IP_CHKSUM 1
grzemich 0:d7bd7384a37c 65 #endif
grzemich 0:d7bd7384a37c 66 #if LWIP_INLINE_IP_CHKSUM && CHECKSUM_GEN_IP
grzemich 0:d7bd7384a37c 67 #define CHECKSUM_GEN_IP_INLINE 1
grzemich 0:d7bd7384a37c 68 #else
grzemich 0:d7bd7384a37c 69 #define CHECKSUM_GEN_IP_INLINE 0
grzemich 0:d7bd7384a37c 70 #endif
grzemich 0:d7bd7384a37c 71
grzemich 0:d7bd7384a37c 72 #if LWIP_DHCP || defined(LWIP_IP_ACCEPT_UDP_PORT)
grzemich 0:d7bd7384a37c 73 #define IP_ACCEPT_LINK_LAYER_ADDRESSING 1
grzemich 0:d7bd7384a37c 74
grzemich 0:d7bd7384a37c 75 /** Some defines for DHCP to let link-layer-addressed packets through while the
grzemich 0:d7bd7384a37c 76 * netif is down.
grzemich 0:d7bd7384a37c 77 * To use this in your own application/protocol, define LWIP_IP_ACCEPT_UDP_PORT
grzemich 0:d7bd7384a37c 78 * to return 1 if the port is accepted and 0 if the port is not accepted.
grzemich 0:d7bd7384a37c 79 */
grzemich 0:d7bd7384a37c 80 #if LWIP_DHCP && defined(LWIP_IP_ACCEPT_UDP_PORT)
grzemich 0:d7bd7384a37c 81 /* accept DHCP client port and custom port */
grzemich 0:d7bd7384a37c 82 #define IP_ACCEPT_LINK_LAYER_ADDRESSED_PORT(port) (((port) == PP_NTOHS(DHCP_CLIENT_PORT)) \
grzemich 0:d7bd7384a37c 83 || (LWIP_IP_ACCEPT_UDP_PORT(port)))
grzemich 0:d7bd7384a37c 84 #elif defined(LWIP_IP_ACCEPT_UDP_PORT) /* LWIP_DHCP && defined(LWIP_IP_ACCEPT_UDP_PORT) */
grzemich 0:d7bd7384a37c 85 /* accept custom port only */
grzemich 0:d7bd7384a37c 86 #define IP_ACCEPT_LINK_LAYER_ADDRESSED_PORT(port) (LWIP_IP_ACCEPT_UDP_PORT(dst_port))
grzemich 0:d7bd7384a37c 87 #else /* LWIP_DHCP && defined(LWIP_IP_ACCEPT_UDP_PORT) */
grzemich 0:d7bd7384a37c 88 /* accept DHCP client port only */
grzemich 0:d7bd7384a37c 89 #define IP_ACCEPT_LINK_LAYER_ADDRESSED_PORT(port) ((port) == PP_NTOHS(DHCP_CLIENT_PORT))
grzemich 0:d7bd7384a37c 90 #endif /* LWIP_DHCP && defined(LWIP_IP_ACCEPT_UDP_PORT) */
grzemich 0:d7bd7384a37c 91
grzemich 0:d7bd7384a37c 92 #else /* LWIP_DHCP */
grzemich 0:d7bd7384a37c 93 #define IP_ACCEPT_LINK_LAYER_ADDRESSING 0
grzemich 0:d7bd7384a37c 94 #endif /* LWIP_DHCP */
grzemich 0:d7bd7384a37c 95
grzemich 0:d7bd7384a37c 96 /**
grzemich 0:d7bd7384a37c 97 * The interface that provided the packet for the current callback
grzemich 0:d7bd7384a37c 98 * invocation.
grzemich 0:d7bd7384a37c 99 */
grzemich 0:d7bd7384a37c 100 struct netif *current_netif;
grzemich 0:d7bd7384a37c 101
grzemich 0:d7bd7384a37c 102 /**
grzemich 0:d7bd7384a37c 103 * Header of the input packet currently being processed.
grzemich 0:d7bd7384a37c 104 */
grzemich 0:d7bd7384a37c 105 const struct ip_hdr *current_header;
grzemich 0:d7bd7384a37c 106 /** Source IP address of current_header */
grzemich 0:d7bd7384a37c 107 ip_addr_t current_iphdr_src;
grzemich 0:d7bd7384a37c 108 /** Destination IP address of current_header */
grzemich 0:d7bd7384a37c 109 ip_addr_t current_iphdr_dest;
grzemich 0:d7bd7384a37c 110
grzemich 0:d7bd7384a37c 111 /** The IP header ID of the next outgoing IP packet */
grzemich 0:d7bd7384a37c 112 static u16_t ip_id;
grzemich 0:d7bd7384a37c 113
grzemich 0:d7bd7384a37c 114 /**
grzemich 0:d7bd7384a37c 115 * Finds the appropriate network interface for a given IP address. It
grzemich 0:d7bd7384a37c 116 * searches the list of network interfaces linearly. A match is found
grzemich 0:d7bd7384a37c 117 * if the masked IP address of the network interface equals the masked
grzemich 0:d7bd7384a37c 118 * IP address given to the function.
grzemich 0:d7bd7384a37c 119 *
grzemich 0:d7bd7384a37c 120 * @param dest the destination IP address for which to find the route
grzemich 0:d7bd7384a37c 121 * @return the netif on which to send to reach dest
grzemich 0:d7bd7384a37c 122 */
grzemich 0:d7bd7384a37c 123 struct netif *
grzemich 0:d7bd7384a37c 124 ip_route(ip_addr_t *dest)
grzemich 0:d7bd7384a37c 125 {
grzemich 0:d7bd7384a37c 126 struct netif *netif;
grzemich 0:d7bd7384a37c 127
grzemich 0:d7bd7384a37c 128 /* iterate through netifs */
grzemich 0:d7bd7384a37c 129 for(netif = netif_list; netif != NULL; netif = netif->next) {
grzemich 0:d7bd7384a37c 130 /* network mask matches? */
grzemich 0:d7bd7384a37c 131 if (netif_is_up(netif)) {
grzemich 0:d7bd7384a37c 132 if (ip_addr_netcmp(dest, &(netif->ip_addr), &(netif->netmask))) {
grzemich 0:d7bd7384a37c 133 /* return netif on which to forward IP packet */
grzemich 0:d7bd7384a37c 134 return netif;
grzemich 0:d7bd7384a37c 135 }
grzemich 0:d7bd7384a37c 136 }
grzemich 0:d7bd7384a37c 137 }
grzemich 0:d7bd7384a37c 138 if ((netif_default == NULL) || (!netif_is_up(netif_default))) {
grzemich 0:d7bd7384a37c 139 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip_route: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
grzemich 0:d7bd7384a37c 140 ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest)));
grzemich 0:d7bd7384a37c 141 IP_STATS_INC(ip.rterr);
grzemich 0:d7bd7384a37c 142 snmp_inc_ipoutnoroutes();
grzemich 0:d7bd7384a37c 143 return NULL;
grzemich 0:d7bd7384a37c 144 }
grzemich 0:d7bd7384a37c 145 /* no matching netif found, use default netif */
grzemich 0:d7bd7384a37c 146 return netif_default;
grzemich 0:d7bd7384a37c 147 }
grzemich 0:d7bd7384a37c 148
grzemich 0:d7bd7384a37c 149 #if IP_FORWARD
grzemich 0:d7bd7384a37c 150 /**
grzemich 0:d7bd7384a37c 151 * Forwards an IP packet. It finds an appropriate route for the
grzemich 0:d7bd7384a37c 152 * packet, decrements the TTL value of the packet, adjusts the
grzemich 0:d7bd7384a37c 153 * checksum and outputs the packet on the appropriate interface.
grzemich 0:d7bd7384a37c 154 *
grzemich 0:d7bd7384a37c 155 * @param p the packet to forward (p->payload points to IP header)
grzemich 0:d7bd7384a37c 156 * @param iphdr the IP header of the input packet
grzemich 0:d7bd7384a37c 157 * @param inp the netif on which this packet was received
grzemich 0:d7bd7384a37c 158 */
grzemich 0:d7bd7384a37c 159 static void
grzemich 0:d7bd7384a37c 160 ip_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
grzemich 0:d7bd7384a37c 161 {
grzemich 0:d7bd7384a37c 162 struct netif *netif;
grzemich 0:d7bd7384a37c 163
grzemich 0:d7bd7384a37c 164 PERF_START;
grzemich 0:d7bd7384a37c 165
grzemich 0:d7bd7384a37c 166 /* RFC3927 2.7: do not forward link-local addresses */
grzemich 0:d7bd7384a37c 167 if (ip_addr_islinklocal(&current_iphdr_dest)) {
grzemich 0:d7bd7384a37c 168 LWIP_DEBUGF(IP_DEBUG, ("ip_forward: not forwarding LLA %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
grzemich 0:d7bd7384a37c 169 ip4_addr1_16(&current_iphdr_dest), ip4_addr2_16(&current_iphdr_dest),
grzemich 0:d7bd7384a37c 170 ip4_addr3_16(&current_iphdr_dest), ip4_addr4_16(&current_iphdr_dest)));
grzemich 0:d7bd7384a37c 171 goto return_noroute;
grzemich 0:d7bd7384a37c 172 }
grzemich 0:d7bd7384a37c 173
grzemich 0:d7bd7384a37c 174 /* Find network interface where to forward this IP packet to. */
grzemich 0:d7bd7384a37c 175 netif = ip_route(&current_iphdr_dest);
grzemich 0:d7bd7384a37c 176 if (netif == NULL) {
grzemich 0:d7bd7384a37c 177 LWIP_DEBUGF(IP_DEBUG, ("ip_forward: no forwarding route for %"U16_F".%"U16_F".%"U16_F".%"U16_F" found\n",
grzemich 0:d7bd7384a37c 178 ip4_addr1_16(&current_iphdr_dest), ip4_addr2_16(&current_iphdr_dest),
grzemich 0:d7bd7384a37c 179 ip4_addr3_16(&current_iphdr_dest), ip4_addr4_16(&current_iphdr_dest)));
grzemich 0:d7bd7384a37c 180 goto return_noroute;
grzemich 0:d7bd7384a37c 181 }
grzemich 0:d7bd7384a37c 182 /* Do not forward packets onto the same network interface on which
grzemich 0:d7bd7384a37c 183 * they arrived. */
grzemich 0:d7bd7384a37c 184 if (netif == inp) {
grzemich 0:d7bd7384a37c 185 LWIP_DEBUGF(IP_DEBUG, ("ip_forward: not bouncing packets back on incoming interface.\n"));
grzemich 0:d7bd7384a37c 186 goto return_noroute;
grzemich 0:d7bd7384a37c 187 }
grzemich 0:d7bd7384a37c 188
grzemich 0:d7bd7384a37c 189 /* decrement TTL */
grzemich 0:d7bd7384a37c 190 IPH_TTL_SET(iphdr, IPH_TTL(iphdr) - 1);
grzemich 0:d7bd7384a37c 191 /* send ICMP if TTL == 0 */
grzemich 0:d7bd7384a37c 192 if (IPH_TTL(iphdr) == 0) {
grzemich 0:d7bd7384a37c 193 snmp_inc_ipinhdrerrors();
grzemich 0:d7bd7384a37c 194 #if LWIP_ICMP
grzemich 0:d7bd7384a37c 195 /* Don't send ICMP messages in response to ICMP messages */
grzemich 0:d7bd7384a37c 196 if (IPH_PROTO(iphdr) != IP_PROTO_ICMP) {
grzemich 0:d7bd7384a37c 197 icmp_time_exceeded(p, ICMP_TE_TTL);
grzemich 0:d7bd7384a37c 198 }
grzemich 0:d7bd7384a37c 199 #endif /* LWIP_ICMP */
grzemich 0:d7bd7384a37c 200 return;
grzemich 0:d7bd7384a37c 201 }
grzemich 0:d7bd7384a37c 202
grzemich 0:d7bd7384a37c 203 /* Incrementally update the IP checksum. */
grzemich 0:d7bd7384a37c 204 if (IPH_CHKSUM(iphdr) >= PP_HTONS(0xffffU - 0x100)) {
grzemich 0:d7bd7384a37c 205 IPH_CHKSUM_SET(iphdr, IPH_CHKSUM(iphdr) + PP_HTONS(0x100) + 1);
grzemich 0:d7bd7384a37c 206 } else {
grzemich 0:d7bd7384a37c 207 IPH_CHKSUM_SET(iphdr, IPH_CHKSUM(iphdr) + PP_HTONS(0x100));
grzemich 0:d7bd7384a37c 208 }
grzemich 0:d7bd7384a37c 209
grzemich 0:d7bd7384a37c 210 LWIP_DEBUGF(IP_DEBUG, ("ip_forward: forwarding packet to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
grzemich 0:d7bd7384a37c 211 ip4_addr1_16(&current_iphdr_dest), ip4_addr2_16(&current_iphdr_dest),
grzemich 0:d7bd7384a37c 212 ip4_addr3_16(&current_iphdr_dest), ip4_addr4_16(&current_iphdr_dest)));
grzemich 0:d7bd7384a37c 213
grzemich 0:d7bd7384a37c 214 IP_STATS_INC(ip.fw);
grzemich 0:d7bd7384a37c 215 IP_STATS_INC(ip.xmit);
grzemich 0:d7bd7384a37c 216 snmp_inc_ipforwdatagrams();
grzemich 0:d7bd7384a37c 217
grzemich 0:d7bd7384a37c 218 PERF_STOP("ip_forward");
grzemich 0:d7bd7384a37c 219 /* transmit pbuf on chosen interface */
grzemich 0:d7bd7384a37c 220 netif->output(netif, p, &current_iphdr_dest);
grzemich 0:d7bd7384a37c 221 return;
grzemich 0:d7bd7384a37c 222 return_noroute:
grzemich 0:d7bd7384a37c 223 snmp_inc_ipoutnoroutes();
grzemich 0:d7bd7384a37c 224 }
grzemich 0:d7bd7384a37c 225 #endif /* IP_FORWARD */
grzemich 0:d7bd7384a37c 226
grzemich 0:d7bd7384a37c 227 /**
grzemich 0:d7bd7384a37c 228 * This function is called by the network interface device driver when
grzemich 0:d7bd7384a37c 229 * an IP packet is received. The function does the basic checks of the
grzemich 0:d7bd7384a37c 230 * IP header such as packet size being at least larger than the header
grzemich 0:d7bd7384a37c 231 * size etc. If the packet was not destined for us, the packet is
grzemich 0:d7bd7384a37c 232 * forwarded (using ip_forward). The IP checksum is always checked.
grzemich 0:d7bd7384a37c 233 *
grzemich 0:d7bd7384a37c 234 * Finally, the packet is sent to the upper layer protocol input function.
grzemich 0:d7bd7384a37c 235 *
grzemich 0:d7bd7384a37c 236 * @param p the received IP packet (p->payload points to IP header)
grzemich 0:d7bd7384a37c 237 * @param inp the netif on which this packet was received
grzemich 0:d7bd7384a37c 238 * @return ERR_OK if the packet was processed (could return ERR_* if it wasn't
grzemich 0:d7bd7384a37c 239 * processed, but currently always returns ERR_OK)
grzemich 0:d7bd7384a37c 240 */
grzemich 0:d7bd7384a37c 241 err_t
grzemich 0:d7bd7384a37c 242 ip_input(struct pbuf *p, struct netif *inp)
grzemich 0:d7bd7384a37c 243 {
grzemich 0:d7bd7384a37c 244 struct ip_hdr *iphdr;
grzemich 0:d7bd7384a37c 245 struct netif *netif;
grzemich 0:d7bd7384a37c 246 u16_t iphdr_hlen;
grzemich 0:d7bd7384a37c 247 u16_t iphdr_len;
grzemich 0:d7bd7384a37c 248 #if IP_ACCEPT_LINK_LAYER_ADDRESSING
grzemich 0:d7bd7384a37c 249 int check_ip_src=1;
grzemich 0:d7bd7384a37c 250 #endif /* IP_ACCEPT_LINK_LAYER_ADDRESSING */
grzemich 0:d7bd7384a37c 251
grzemich 0:d7bd7384a37c 252 IP_STATS_INC(ip.recv);
grzemich 0:d7bd7384a37c 253 snmp_inc_ipinreceives();
grzemich 0:d7bd7384a37c 254
grzemich 0:d7bd7384a37c 255 /* identify the IP header */
grzemich 0:d7bd7384a37c 256 iphdr = (struct ip_hdr *)p->payload;
grzemich 0:d7bd7384a37c 257 if (IPH_V(iphdr) != 4) {
grzemich 0:d7bd7384a37c 258 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_WARNING, ("IP packet dropped due to bad version number %"U16_F"\n", IPH_V(iphdr)));
grzemich 0:d7bd7384a37c 259 ip_debug_print(p);
grzemich 0:d7bd7384a37c 260 pbuf_free(p);
grzemich 0:d7bd7384a37c 261 IP_STATS_INC(ip.err);
grzemich 0:d7bd7384a37c 262 IP_STATS_INC(ip.drop);
grzemich 0:d7bd7384a37c 263 snmp_inc_ipinhdrerrors();
grzemich 0:d7bd7384a37c 264 return ERR_OK;
grzemich 0:d7bd7384a37c 265 }
grzemich 0:d7bd7384a37c 266
grzemich 0:d7bd7384a37c 267 /* obtain IP header length in number of 32-bit words */
grzemich 0:d7bd7384a37c 268 iphdr_hlen = IPH_HL(iphdr);
grzemich 0:d7bd7384a37c 269 /* calculate IP header length in bytes */
grzemich 0:d7bd7384a37c 270 iphdr_hlen *= 4;
grzemich 0:d7bd7384a37c 271 /* obtain ip length in bytes */
grzemich 0:d7bd7384a37c 272 iphdr_len = ntohs(IPH_LEN(iphdr));
grzemich 0:d7bd7384a37c 273
grzemich 0:d7bd7384a37c 274 /* header length exceeds first pbuf length, or ip length exceeds total pbuf length? */
grzemich 0:d7bd7384a37c 275 if ((iphdr_hlen > p->len) || (iphdr_len > p->tot_len)) {
grzemich 0:d7bd7384a37c 276 if (iphdr_hlen > p->len) {
grzemich 0:d7bd7384a37c 277 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS,
grzemich 0:d7bd7384a37c 278 ("IP header (len %"U16_F") does not fit in first pbuf (len %"U16_F"), IP packet dropped.\n",
grzemich 0:d7bd7384a37c 279 iphdr_hlen, p->len));
grzemich 0:d7bd7384a37c 280 }
grzemich 0:d7bd7384a37c 281 if (iphdr_len > p->tot_len) {
grzemich 0:d7bd7384a37c 282 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS,
grzemich 0:d7bd7384a37c 283 ("IP (len %"U16_F") is longer than pbuf (len %"U16_F"), IP packet dropped.\n",
grzemich 0:d7bd7384a37c 284 iphdr_len, p->tot_len));
grzemich 0:d7bd7384a37c 285 }
grzemich 0:d7bd7384a37c 286 /* free (drop) packet pbufs */
grzemich 0:d7bd7384a37c 287 pbuf_free(p);
grzemich 0:d7bd7384a37c 288 IP_STATS_INC(ip.lenerr);
grzemich 0:d7bd7384a37c 289 IP_STATS_INC(ip.drop);
grzemich 0:d7bd7384a37c 290 snmp_inc_ipindiscards();
grzemich 0:d7bd7384a37c 291 return ERR_OK;
grzemich 0:d7bd7384a37c 292 }
grzemich 0:d7bd7384a37c 293
grzemich 0:d7bd7384a37c 294 /* verify checksum */
grzemich 0:d7bd7384a37c 295 #if CHECKSUM_CHECK_IP
grzemich 0:d7bd7384a37c 296 if (inet_chksum(iphdr, iphdr_hlen) != 0) {
grzemich 0:d7bd7384a37c 297
grzemich 0:d7bd7384a37c 298 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS,
grzemich 0:d7bd7384a37c 299 ("Checksum (0x%"X16_F") failed, IP packet dropped.\n", inet_chksum(iphdr, iphdr_hlen)));
grzemich 0:d7bd7384a37c 300 ip_debug_print(p);
grzemich 0:d7bd7384a37c 301 pbuf_free(p);
grzemich 0:d7bd7384a37c 302 IP_STATS_INC(ip.chkerr);
grzemich 0:d7bd7384a37c 303 IP_STATS_INC(ip.drop);
grzemich 0:d7bd7384a37c 304 snmp_inc_ipinhdrerrors();
grzemich 0:d7bd7384a37c 305 return ERR_OK;
grzemich 0:d7bd7384a37c 306 }
grzemich 0:d7bd7384a37c 307 #endif
grzemich 0:d7bd7384a37c 308
grzemich 0:d7bd7384a37c 309 /* Trim pbuf. This should have been done at the netif layer,
grzemich 0:d7bd7384a37c 310 * but we'll do it anyway just to be sure that its done. */
grzemich 0:d7bd7384a37c 311 pbuf_realloc(p, iphdr_len);
grzemich 0:d7bd7384a37c 312
grzemich 0:d7bd7384a37c 313 /* copy IP addresses to aligned ip_addr_t */
grzemich 0:d7bd7384a37c 314 ip_addr_copy(current_iphdr_dest, iphdr->dest);
grzemich 0:d7bd7384a37c 315 ip_addr_copy(current_iphdr_src, iphdr->src);
grzemich 0:d7bd7384a37c 316
grzemich 0:d7bd7384a37c 317 /* match packet against an interface, i.e. is this packet for us? */
grzemich 0:d7bd7384a37c 318 #if LWIP_IGMP
grzemich 0:d7bd7384a37c 319 if (ip_addr_ismulticast(&current_iphdr_dest)) {
grzemich 0:d7bd7384a37c 320 if ((inp->flags & NETIF_FLAG_IGMP) && (igmp_lookfor_group(inp, &current_iphdr_dest))) {
grzemich 0:d7bd7384a37c 321 netif = inp;
grzemich 0:d7bd7384a37c 322 } else {
grzemich 0:d7bd7384a37c 323 netif = NULL;
grzemich 0:d7bd7384a37c 324 }
grzemich 0:d7bd7384a37c 325 } else
grzemich 0:d7bd7384a37c 326 #endif /* LWIP_IGMP */
grzemich 0:d7bd7384a37c 327 {
grzemich 0:d7bd7384a37c 328 /* start trying with inp. if that's not acceptable, start walking the
grzemich 0:d7bd7384a37c 329 list of configured netifs.
grzemich 0:d7bd7384a37c 330 'first' is used as a boolean to mark whether we started walking the list */
grzemich 0:d7bd7384a37c 331 int first = 1;
grzemich 0:d7bd7384a37c 332 netif = inp;
grzemich 0:d7bd7384a37c 333 do {
grzemich 0:d7bd7384a37c 334 LWIP_DEBUGF(IP_DEBUG, ("ip_input: iphdr->dest 0x%"X32_F" netif->ip_addr 0x%"X32_F" (0x%"X32_F", 0x%"X32_F", 0x%"X32_F")\n",
grzemich 0:d7bd7384a37c 335 ip4_addr_get_u32(&iphdr->dest), ip4_addr_get_u32(&netif->ip_addr),
grzemich 0:d7bd7384a37c 336 ip4_addr_get_u32(&iphdr->dest) & ip4_addr_get_u32(&netif->netmask),
grzemich 0:d7bd7384a37c 337 ip4_addr_get_u32(&netif->ip_addr) & ip4_addr_get_u32(&netif->netmask),
grzemich 0:d7bd7384a37c 338 ip4_addr_get_u32(&iphdr->dest) & ~ip4_addr_get_u32(&netif->netmask)));
grzemich 0:d7bd7384a37c 339
grzemich 0:d7bd7384a37c 340 /* interface is up and configured? */
grzemich 0:d7bd7384a37c 341 if ((netif_is_up(netif)) && (!ip_addr_isany(&(netif->ip_addr)))) {
grzemich 0:d7bd7384a37c 342 /* unicast to this interface address? */
grzemich 0:d7bd7384a37c 343 if (ip_addr_cmp(&current_iphdr_dest, &(netif->ip_addr)) ||
grzemich 0:d7bd7384a37c 344 /* or broadcast on this interface network address? */
grzemich 0:d7bd7384a37c 345 ip_addr_isbroadcast(&current_iphdr_dest, netif)) {
grzemich 0:d7bd7384a37c 346 LWIP_DEBUGF(IP_DEBUG, ("ip_input: packet accepted on interface %c%c\n",
grzemich 0:d7bd7384a37c 347 netif->name[0], netif->name[1]));
grzemich 0:d7bd7384a37c 348 /* break out of for loop */
grzemich 0:d7bd7384a37c 349 break;
grzemich 0:d7bd7384a37c 350 }
grzemich 0:d7bd7384a37c 351 #if LWIP_AUTOIP
grzemich 0:d7bd7384a37c 352 /* connections to link-local addresses must persist after changing
grzemich 0:d7bd7384a37c 353 the netif's address (RFC3927 ch. 1.9) */
grzemich 0:d7bd7384a37c 354 if ((netif->autoip != NULL) &&
grzemich 0:d7bd7384a37c 355 ip_addr_cmp(&current_iphdr_dest, &(netif->autoip->llipaddr))) {
grzemich 0:d7bd7384a37c 356 LWIP_DEBUGF(IP_DEBUG, ("ip_input: LLA packet accepted on interface %c%c\n",
grzemich 0:d7bd7384a37c 357 netif->name[0], netif->name[1]));
grzemich 0:d7bd7384a37c 358 /* break out of for loop */
grzemich 0:d7bd7384a37c 359 break;
grzemich 0:d7bd7384a37c 360 }
grzemich 0:d7bd7384a37c 361 #endif /* LWIP_AUTOIP */
grzemich 0:d7bd7384a37c 362 }
grzemich 0:d7bd7384a37c 363 if (first) {
grzemich 0:d7bd7384a37c 364 first = 0;
grzemich 0:d7bd7384a37c 365 netif = netif_list;
grzemich 0:d7bd7384a37c 366 } else {
grzemich 0:d7bd7384a37c 367 netif = netif->next;
grzemich 0:d7bd7384a37c 368 }
grzemich 0:d7bd7384a37c 369 if (netif == inp) {
grzemich 0:d7bd7384a37c 370 netif = netif->next;
grzemich 0:d7bd7384a37c 371 }
grzemich 0:d7bd7384a37c 372 } while(netif != NULL);
grzemich 0:d7bd7384a37c 373 }
grzemich 0:d7bd7384a37c 374
grzemich 0:d7bd7384a37c 375 #if IP_ACCEPT_LINK_LAYER_ADDRESSING
grzemich 0:d7bd7384a37c 376 /* Pass DHCP messages regardless of destination address. DHCP traffic is addressed
grzemich 0:d7bd7384a37c 377 * using link layer addressing (such as Ethernet MAC) so we must not filter on IP.
grzemich 0:d7bd7384a37c 378 * According to RFC 1542 section 3.1.1, referred by RFC 2131).
grzemich 0:d7bd7384a37c 379 *
grzemich 0:d7bd7384a37c 380 * If you want to accept private broadcast communication while a netif is down,
grzemich 0:d7bd7384a37c 381 * define LWIP_IP_ACCEPT_UDP_PORT(dst_port), e.g.:
grzemich 0:d7bd7384a37c 382 *
grzemich 0:d7bd7384a37c 383 * #define LWIP_IP_ACCEPT_UDP_PORT(dst_port) ((dst_port) == PP_NTOHS(12345))
grzemich 0:d7bd7384a37c 384 */
grzemich 0:d7bd7384a37c 385 if (netif == NULL) {
grzemich 0:d7bd7384a37c 386 /* remote port is DHCP server? */
grzemich 0:d7bd7384a37c 387 if (IPH_PROTO(iphdr) == IP_PROTO_UDP) {
grzemich 0:d7bd7384a37c 388 struct udp_hdr *udphdr = (struct udp_hdr *)((u8_t *)iphdr + iphdr_hlen);
grzemich 0:d7bd7384a37c 389 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_TRACE, ("ip_input: UDP packet to DHCP client port %"U16_F"\n",
grzemich 0:d7bd7384a37c 390 ntohs(udphdr->dest)));
grzemich 0:d7bd7384a37c 391 if (IP_ACCEPT_LINK_LAYER_ADDRESSED_PORT(udphdr->dest)) {
grzemich 0:d7bd7384a37c 392 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_TRACE, ("ip_input: DHCP packet accepted.\n"));
grzemich 0:d7bd7384a37c 393 netif = inp;
grzemich 0:d7bd7384a37c 394 check_ip_src = 0;
grzemich 0:d7bd7384a37c 395 }
grzemich 0:d7bd7384a37c 396 }
grzemich 0:d7bd7384a37c 397 }
grzemich 0:d7bd7384a37c 398 #endif /* IP_ACCEPT_LINK_LAYER_ADDRESSING */
grzemich 0:d7bd7384a37c 399
grzemich 0:d7bd7384a37c 400 /* broadcast or multicast packet source address? Compliant with RFC 1122: 3.2.1.3 */
grzemich 0:d7bd7384a37c 401 #if IP_ACCEPT_LINK_LAYER_ADDRESSING
grzemich 0:d7bd7384a37c 402 /* DHCP servers need 0.0.0.0 to be allowed as source address (RFC 1.1.2.2: 3.2.1.3/a) */
grzemich 0:d7bd7384a37c 403 if (check_ip_src && current_iphdr_src.addr != IPADDR_ANY)
grzemich 0:d7bd7384a37c 404 #endif /* IP_ACCEPT_LINK_LAYER_ADDRESSING */
grzemich 0:d7bd7384a37c 405 { if ((ip_addr_isbroadcast(&current_iphdr_src, inp)) ||
grzemich 0:d7bd7384a37c 406 (ip_addr_ismulticast(&current_iphdr_src))) {
grzemich 0:d7bd7384a37c 407 /* packet source is not valid */
grzemich 0:d7bd7384a37c 408 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING, ("ip_input: packet source is not valid.\n"));
grzemich 0:d7bd7384a37c 409 /* free (drop) packet pbufs */
grzemich 0:d7bd7384a37c 410 pbuf_free(p);
grzemich 0:d7bd7384a37c 411 IP_STATS_INC(ip.drop);
grzemich 0:d7bd7384a37c 412 snmp_inc_ipinaddrerrors();
grzemich 0:d7bd7384a37c 413 snmp_inc_ipindiscards();
grzemich 0:d7bd7384a37c 414 return ERR_OK;
grzemich 0:d7bd7384a37c 415 }
grzemich 0:d7bd7384a37c 416 }
grzemich 0:d7bd7384a37c 417
grzemich 0:d7bd7384a37c 418 /* packet not for us? */
grzemich 0:d7bd7384a37c 419 if (netif == NULL) {
grzemich 0:d7bd7384a37c 420 /* packet not for us, route or discard */
grzemich 0:d7bd7384a37c 421 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_TRACE, ("ip_input: packet not for us.\n"));
grzemich 0:d7bd7384a37c 422 #if IP_FORWARD
grzemich 0:d7bd7384a37c 423 /* non-broadcast packet? */
grzemich 0:d7bd7384a37c 424 if (!ip_addr_isbroadcast(&current_iphdr_dest, inp)) {
grzemich 0:d7bd7384a37c 425 /* try to forward IP packet on (other) interfaces */
grzemich 0:d7bd7384a37c 426 ip_forward(p, iphdr, inp);
grzemich 0:d7bd7384a37c 427 } else
grzemich 0:d7bd7384a37c 428 #endif /* IP_FORWARD */
grzemich 0:d7bd7384a37c 429 {
grzemich 0:d7bd7384a37c 430 snmp_inc_ipinaddrerrors();
grzemich 0:d7bd7384a37c 431 snmp_inc_ipindiscards();
grzemich 0:d7bd7384a37c 432 }
grzemich 0:d7bd7384a37c 433 pbuf_free(p);
grzemich 0:d7bd7384a37c 434 return ERR_OK;
grzemich 0:d7bd7384a37c 435 }
grzemich 0:d7bd7384a37c 436 /* packet consists of multiple fragments? */
grzemich 0:d7bd7384a37c 437 if ((IPH_OFFSET(iphdr) & PP_HTONS(IP_OFFMASK | IP_MF)) != 0) {
grzemich 0:d7bd7384a37c 438 #if IP_REASSEMBLY /* packet fragment reassembly code present? */
grzemich 0:d7bd7384a37c 439 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 ip_reass()\n",
grzemich 0:d7bd7384a37c 440 ntohs(IPH_ID(iphdr)), p->tot_len, ntohs(IPH_LEN(iphdr)), !!(IPH_OFFSET(iphdr) & PP_HTONS(IP_MF)), (ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK)*8));
grzemich 0:d7bd7384a37c 441 /* reassemble the packet*/
grzemich 0:d7bd7384a37c 442 p = ip_reass(p);
grzemich 0:d7bd7384a37c 443 /* packet not fully reassembled yet? */
grzemich 0:d7bd7384a37c 444 if (p == NULL) {
grzemich 0:d7bd7384a37c 445 return ERR_OK;
grzemich 0:d7bd7384a37c 446 }
grzemich 0:d7bd7384a37c 447 iphdr = (struct ip_hdr *)p->payload;
grzemich 0:d7bd7384a37c 448 #else /* IP_REASSEMBLY == 0, no packet fragment reassembly code present */
grzemich 0:d7bd7384a37c 449 pbuf_free(p);
grzemich 0:d7bd7384a37c 450 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("IP packet dropped since it was fragmented (0x%"X16_F") (while IP_REASSEMBLY == 0).\n",
grzemich 0:d7bd7384a37c 451 ntohs(IPH_OFFSET(iphdr))));
grzemich 0:d7bd7384a37c 452 IP_STATS_INC(ip.opterr);
grzemich 0:d7bd7384a37c 453 IP_STATS_INC(ip.drop);
grzemich 0:d7bd7384a37c 454 /* unsupported protocol feature */
grzemich 0:d7bd7384a37c 455 snmp_inc_ipinunknownprotos();
grzemich 0:d7bd7384a37c 456 return ERR_OK;
grzemich 0:d7bd7384a37c 457 #endif /* IP_REASSEMBLY */
grzemich 0:d7bd7384a37c 458 }
grzemich 0:d7bd7384a37c 459
grzemich 0:d7bd7384a37c 460 #if IP_OPTIONS_ALLOWED == 0 /* no support for IP options in the IP header? */
grzemich 0:d7bd7384a37c 461
grzemich 0:d7bd7384a37c 462 #if LWIP_IGMP
grzemich 0:d7bd7384a37c 463 /* there is an extra "router alert" option in IGMP messages which we allow for but do not police */
grzemich 0:d7bd7384a37c 464 if((iphdr_hlen > IP_HLEN) && (IPH_PROTO(iphdr) != IP_PROTO_IGMP)) {
grzemich 0:d7bd7384a37c 465 #else
grzemich 0:d7bd7384a37c 466 if (iphdr_hlen > IP_HLEN) {
grzemich 0:d7bd7384a37c 467 #endif /* LWIP_IGMP */
grzemich 0:d7bd7384a37c 468 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("IP packet dropped since there were IP options (while IP_OPTIONS_ALLOWED == 0).\n"));
grzemich 0:d7bd7384a37c 469 pbuf_free(p);
grzemich 0:d7bd7384a37c 470 IP_STATS_INC(ip.opterr);
grzemich 0:d7bd7384a37c 471 IP_STATS_INC(ip.drop);
grzemich 0:d7bd7384a37c 472 /* unsupported protocol feature */
grzemich 0:d7bd7384a37c 473 snmp_inc_ipinunknownprotos();
grzemich 0:d7bd7384a37c 474 return ERR_OK;
grzemich 0:d7bd7384a37c 475 }
grzemich 0:d7bd7384a37c 476 #endif /* IP_OPTIONS_ALLOWED == 0 */
grzemich 0:d7bd7384a37c 477
grzemich 0:d7bd7384a37c 478 /* send to upper layers */
grzemich 0:d7bd7384a37c 479 LWIP_DEBUGF(IP_DEBUG, ("ip_input: \n"));
grzemich 0:d7bd7384a37c 480 ip_debug_print(p);
grzemich 0:d7bd7384a37c 481 LWIP_DEBUGF(IP_DEBUG, ("ip_input: p->len %"U16_F" p->tot_len %"U16_F"\n", p->len, p->tot_len));
grzemich 0:d7bd7384a37c 482
grzemich 0:d7bd7384a37c 483 current_netif = inp;
grzemich 0:d7bd7384a37c 484 current_header = iphdr;
grzemich 0:d7bd7384a37c 485
grzemich 0:d7bd7384a37c 486 #if LWIP_RAW
grzemich 0:d7bd7384a37c 487 /* raw input did not eat the packet? */
grzemich 0:d7bd7384a37c 488 if (raw_input(p, inp) == 0)
grzemich 0:d7bd7384a37c 489 #endif /* LWIP_RAW */
grzemich 0:d7bd7384a37c 490 {
grzemich 0:d7bd7384a37c 491
grzemich 0:d7bd7384a37c 492 switch (IPH_PROTO(iphdr)) {
grzemich 0:d7bd7384a37c 493 #if LWIP_UDP
grzemich 0:d7bd7384a37c 494 case IP_PROTO_UDP:
grzemich 0:d7bd7384a37c 495 #if LWIP_UDPLITE
grzemich 0:d7bd7384a37c 496 case IP_PROTO_UDPLITE:
grzemich 0:d7bd7384a37c 497 #endif /* LWIP_UDPLITE */
grzemich 0:d7bd7384a37c 498 snmp_inc_ipindelivers();
grzemich 0:d7bd7384a37c 499 udp_input(p, inp);
grzemich 0:d7bd7384a37c 500 break;
grzemich 0:d7bd7384a37c 501 #endif /* LWIP_UDP */
grzemich 0:d7bd7384a37c 502 #if LWIP_TCP
grzemich 0:d7bd7384a37c 503 case IP_PROTO_TCP:
grzemich 0:d7bd7384a37c 504 snmp_inc_ipindelivers();
grzemich 0:d7bd7384a37c 505 tcp_input(p, inp);
grzemich 0:d7bd7384a37c 506 break;
grzemich 0:d7bd7384a37c 507 #endif /* LWIP_TCP */
grzemich 0:d7bd7384a37c 508 #if LWIP_ICMP
grzemich 0:d7bd7384a37c 509 case IP_PROTO_ICMP:
grzemich 0:d7bd7384a37c 510 snmp_inc_ipindelivers();
grzemich 0:d7bd7384a37c 511 icmp_input(p, inp);
grzemich 0:d7bd7384a37c 512 break;
grzemich 0:d7bd7384a37c 513 #endif /* LWIP_ICMP */
grzemich 0:d7bd7384a37c 514 #if LWIP_IGMP
grzemich 0:d7bd7384a37c 515 case IP_PROTO_IGMP:
grzemich 0:d7bd7384a37c 516 igmp_input(p, inp, &current_iphdr_dest);
grzemich 0:d7bd7384a37c 517 break;
grzemich 0:d7bd7384a37c 518 #endif /* LWIP_IGMP */
grzemich 0:d7bd7384a37c 519 default:
grzemich 0:d7bd7384a37c 520 #if LWIP_ICMP
grzemich 0:d7bd7384a37c 521 /* send ICMP destination protocol unreachable unless is was a broadcast */
grzemich 0:d7bd7384a37c 522 if (!ip_addr_isbroadcast(&current_iphdr_dest, inp) &&
grzemich 0:d7bd7384a37c 523 !ip_addr_ismulticast(&current_iphdr_dest)) {
grzemich 0:d7bd7384a37c 524 p->payload = iphdr;
grzemich 0:d7bd7384a37c 525 icmp_dest_unreach(p, ICMP_DUR_PROTO);
grzemich 0:d7bd7384a37c 526 }
grzemich 0:d7bd7384a37c 527 #endif /* LWIP_ICMP */
grzemich 0:d7bd7384a37c 528 pbuf_free(p);
grzemich 0:d7bd7384a37c 529
grzemich 0:d7bd7384a37c 530 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("Unsupported transport protocol %"U16_F"\n", IPH_PROTO(iphdr)));
grzemich 0:d7bd7384a37c 531
grzemich 0:d7bd7384a37c 532 IP_STATS_INC(ip.proterr);
grzemich 0:d7bd7384a37c 533 IP_STATS_INC(ip.drop);
grzemich 0:d7bd7384a37c 534 snmp_inc_ipinunknownprotos();
grzemich 0:d7bd7384a37c 535 }
grzemich 0:d7bd7384a37c 536 }
grzemich 0:d7bd7384a37c 537
grzemich 0:d7bd7384a37c 538 current_netif = NULL;
grzemich 0:d7bd7384a37c 539 current_header = NULL;
grzemich 0:d7bd7384a37c 540 ip_addr_set_any(&current_iphdr_src);
grzemich 0:d7bd7384a37c 541 ip_addr_set_any(&current_iphdr_dest);
grzemich 0:d7bd7384a37c 542
grzemich 0:d7bd7384a37c 543 return ERR_OK;
grzemich 0:d7bd7384a37c 544 }
grzemich 0:d7bd7384a37c 545
grzemich 0:d7bd7384a37c 546 /**
grzemich 0:d7bd7384a37c 547 * Sends an IP packet on a network interface. This function constructs
grzemich 0:d7bd7384a37c 548 * the IP header and calculates the IP header checksum. If the source
grzemich 0:d7bd7384a37c 549 * IP address is NULL, the IP address of the outgoing network
grzemich 0:d7bd7384a37c 550 * interface is filled in as source address.
grzemich 0:d7bd7384a37c 551 * If the destination IP address is IP_HDRINCL, p is assumed to already
grzemich 0:d7bd7384a37c 552 * include an IP header and p->payload points to it instead of the data.
grzemich 0:d7bd7384a37c 553 *
grzemich 0:d7bd7384a37c 554 * @param p the packet to send (p->payload points to the data, e.g. next
grzemich 0:d7bd7384a37c 555 protocol header; if dest == IP_HDRINCL, p already includes an IP
grzemich 0:d7bd7384a37c 556 header and p->payload points to that IP header)
grzemich 0:d7bd7384a37c 557 * @param src the source IP address to send from (if src == IP_ADDR_ANY, the
grzemich 0:d7bd7384a37c 558 * IP address of the netif used to send is used as source address)
grzemich 0:d7bd7384a37c 559 * @param dest the destination IP address to send the packet to
grzemich 0:d7bd7384a37c 560 * @param ttl the TTL value to be set in the IP header
grzemich 0:d7bd7384a37c 561 * @param tos the TOS value to be set in the IP header
grzemich 0:d7bd7384a37c 562 * @param proto the PROTOCOL to be set in the IP header
grzemich 0:d7bd7384a37c 563 * @param netif the netif on which to send this packet
grzemich 0:d7bd7384a37c 564 * @return ERR_OK if the packet was sent OK
grzemich 0:d7bd7384a37c 565 * ERR_BUF if p doesn't have enough space for IP/LINK headers
grzemich 0:d7bd7384a37c 566 * returns errors returned by netif->output
grzemich 0:d7bd7384a37c 567 *
grzemich 0:d7bd7384a37c 568 * @note ip_id: RFC791 "some host may be able to simply use
grzemich 0:d7bd7384a37c 569 * unique identifiers independent of destination"
grzemich 0:d7bd7384a37c 570 */
grzemich 0:d7bd7384a37c 571 err_t
grzemich 0:d7bd7384a37c 572 ip_output_if(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
grzemich 0:d7bd7384a37c 573 u8_t ttl, u8_t tos,
grzemich 0:d7bd7384a37c 574 u8_t proto, struct netif *netif)
grzemich 0:d7bd7384a37c 575 {
grzemich 0:d7bd7384a37c 576 #if IP_OPTIONS_SEND
grzemich 0:d7bd7384a37c 577 return ip_output_if_opt(p, src, dest, ttl, tos, proto, netif, NULL, 0);
grzemich 0:d7bd7384a37c 578 }
grzemich 0:d7bd7384a37c 579
grzemich 0:d7bd7384a37c 580 /**
grzemich 0:d7bd7384a37c 581 * Same as ip_output_if() but with the possibility to include IP options:
grzemich 0:d7bd7384a37c 582 *
grzemich 0:d7bd7384a37c 583 * @ param ip_options pointer to the IP options, copied into the IP header
grzemich 0:d7bd7384a37c 584 * @ param optlen length of ip_options
grzemich 0:d7bd7384a37c 585 */
grzemich 0:d7bd7384a37c 586 err_t ip_output_if_opt(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
grzemich 0:d7bd7384a37c 587 u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options,
grzemich 0:d7bd7384a37c 588 u16_t optlen)
grzemich 0:d7bd7384a37c 589 {
grzemich 0:d7bd7384a37c 590 #endif /* IP_OPTIONS_SEND */
grzemich 0:d7bd7384a37c 591 struct ip_hdr *iphdr;
grzemich 0:d7bd7384a37c 592 ip_addr_t dest_addr;
grzemich 0:d7bd7384a37c 593 #if CHECKSUM_GEN_IP_INLINE
grzemich 0:d7bd7384a37c 594 u32_t chk_sum = 0;
grzemich 0:d7bd7384a37c 595 #endif /* CHECKSUM_GEN_IP_INLINE */
grzemich 0:d7bd7384a37c 596
grzemich 0:d7bd7384a37c 597 /* pbufs passed to IP must have a ref-count of 1 as their payload pointer
grzemich 0:d7bd7384a37c 598 gets altered as the packet is passed down the stack */
grzemich 0:d7bd7384a37c 599 LWIP_ASSERT("p->ref == 1", p->ref == 1);
grzemich 0:d7bd7384a37c 600
grzemich 0:d7bd7384a37c 601 snmp_inc_ipoutrequests();
grzemich 0:d7bd7384a37c 602
grzemich 0:d7bd7384a37c 603 /* Should the IP header be generated or is it already included in p? */
grzemich 0:d7bd7384a37c 604 if (dest != IP_HDRINCL) {
grzemich 0:d7bd7384a37c 605 u16_t ip_hlen = IP_HLEN;
grzemich 0:d7bd7384a37c 606 #if IP_OPTIONS_SEND
grzemich 0:d7bd7384a37c 607 u16_t optlen_aligned = 0;
grzemich 0:d7bd7384a37c 608 if (optlen != 0) {
grzemich 0:d7bd7384a37c 609 #if CHECKSUM_GEN_IP_INLINE
grzemich 0:d7bd7384a37c 610 int i;
grzemich 0:d7bd7384a37c 611 #endif /* CHECKSUM_GEN_IP_INLINE */
grzemich 0:d7bd7384a37c 612 /* round up to a multiple of 4 */
grzemich 0:d7bd7384a37c 613 optlen_aligned = ((optlen + 3) & ~3);
grzemich 0:d7bd7384a37c 614 ip_hlen += optlen_aligned;
grzemich 0:d7bd7384a37c 615 /* First write in the IP options */
grzemich 0:d7bd7384a37c 616 if (pbuf_header(p, optlen_aligned)) {
grzemich 0:d7bd7384a37c 617 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip_output_if_opt: not enough room for IP options in pbuf\n"));
grzemich 0:d7bd7384a37c 618 IP_STATS_INC(ip.err);
grzemich 0:d7bd7384a37c 619 snmp_inc_ipoutdiscards();
grzemich 0:d7bd7384a37c 620 return ERR_BUF;
grzemich 0:d7bd7384a37c 621 }
grzemich 0:d7bd7384a37c 622 MEMCPY(p->payload, ip_options, optlen);
grzemich 0:d7bd7384a37c 623 if (optlen < optlen_aligned) {
grzemich 0:d7bd7384a37c 624 /* zero the remaining bytes */
grzemich 0:d7bd7384a37c 625 memset(((char*)p->payload) + optlen, 0, optlen_aligned - optlen);
grzemich 0:d7bd7384a37c 626 }
grzemich 0:d7bd7384a37c 627 #if CHECKSUM_GEN_IP_INLINE
grzemich 0:d7bd7384a37c 628 for (i = 0; i < optlen_aligned/2; i++) {
grzemich 0:d7bd7384a37c 629 chk_sum += ((u16_t*)p->payload)[i];
grzemich 0:d7bd7384a37c 630 }
grzemich 0:d7bd7384a37c 631 #endif /* CHECKSUM_GEN_IP_INLINE */
grzemich 0:d7bd7384a37c 632 }
grzemich 0:d7bd7384a37c 633 #endif /* IP_OPTIONS_SEND */
grzemich 0:d7bd7384a37c 634 /* generate IP header */
grzemich 0:d7bd7384a37c 635 if (pbuf_header(p, IP_HLEN)) {
grzemich 0:d7bd7384a37c 636 LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip_output: not enough room for IP header in pbuf\n"));
grzemich 0:d7bd7384a37c 637
grzemich 0:d7bd7384a37c 638 IP_STATS_INC(ip.err);
grzemich 0:d7bd7384a37c 639 snmp_inc_ipoutdiscards();
grzemich 0:d7bd7384a37c 640 return ERR_BUF;
grzemich 0:d7bd7384a37c 641 }
grzemich 0:d7bd7384a37c 642
grzemich 0:d7bd7384a37c 643 iphdr = (struct ip_hdr *)p->payload;
grzemich 0:d7bd7384a37c 644 LWIP_ASSERT("check that first pbuf can hold struct ip_hdr",
grzemich 0:d7bd7384a37c 645 (p->len >= sizeof(struct ip_hdr)));
grzemich 0:d7bd7384a37c 646
grzemich 0:d7bd7384a37c 647 IPH_TTL_SET(iphdr, ttl);
grzemich 0:d7bd7384a37c 648 IPH_PROTO_SET(iphdr, proto);
grzemich 0:d7bd7384a37c 649 #if CHECKSUM_GEN_IP_INLINE
grzemich 0:d7bd7384a37c 650 chk_sum += LWIP_MAKE_U16(proto, ttl);
grzemich 0:d7bd7384a37c 651 #endif /* CHECKSUM_GEN_IP_INLINE */
grzemich 0:d7bd7384a37c 652
grzemich 0:d7bd7384a37c 653 /* dest cannot be NULL here */
grzemich 0:d7bd7384a37c 654 ip_addr_copy(iphdr->dest, *dest);
grzemich 0:d7bd7384a37c 655 #if CHECKSUM_GEN_IP_INLINE
grzemich 0:d7bd7384a37c 656 chk_sum += ip4_addr_get_u32(&iphdr->dest) & 0xFFFF;
grzemich 0:d7bd7384a37c 657 chk_sum += ip4_addr_get_u32(&iphdr->dest) >> 16;
grzemich 0:d7bd7384a37c 658 #endif /* CHECKSUM_GEN_IP_INLINE */
grzemich 0:d7bd7384a37c 659
grzemich 0:d7bd7384a37c 660 IPH_VHLTOS_SET(iphdr, 4, ip_hlen / 4, tos);
grzemich 0:d7bd7384a37c 661 #if CHECKSUM_GEN_IP_INLINE
grzemich 0:d7bd7384a37c 662 chk_sum += iphdr->_v_hl_tos;
grzemich 0:d7bd7384a37c 663 #endif /* CHECKSUM_GEN_IP_INLINE */
grzemich 0:d7bd7384a37c 664 IPH_LEN_SET(iphdr, htons(p->tot_len));
grzemich 0:d7bd7384a37c 665 #if CHECKSUM_GEN_IP_INLINE
grzemich 0:d7bd7384a37c 666 chk_sum += iphdr->_len;
grzemich 0:d7bd7384a37c 667 #endif /* CHECKSUM_GEN_IP_INLINE */
grzemich 0:d7bd7384a37c 668 IPH_OFFSET_SET(iphdr, 0);
grzemich 0:d7bd7384a37c 669 IPH_ID_SET(iphdr, htons(ip_id));
grzemich 0:d7bd7384a37c 670 #if CHECKSUM_GEN_IP_INLINE
grzemich 0:d7bd7384a37c 671 chk_sum += iphdr->_id;
grzemich 0:d7bd7384a37c 672 #endif /* CHECKSUM_GEN_IP_INLINE */
grzemich 0:d7bd7384a37c 673 ++ip_id;
grzemich 0:d7bd7384a37c 674
grzemich 0:d7bd7384a37c 675 if (ip_addr_isany(src)) {
grzemich 0:d7bd7384a37c 676 ip_addr_copy(iphdr->src, netif->ip_addr);
grzemich 0:d7bd7384a37c 677 } else {
grzemich 0:d7bd7384a37c 678 /* src cannot be NULL here */
grzemich 0:d7bd7384a37c 679 ip_addr_copy(iphdr->src, *src);
grzemich 0:d7bd7384a37c 680 }
grzemich 0:d7bd7384a37c 681
grzemich 0:d7bd7384a37c 682 #if CHECKSUM_GEN_IP_INLINE
grzemich 0:d7bd7384a37c 683 chk_sum += ip4_addr_get_u32(&iphdr->src) & 0xFFFF;
grzemich 0:d7bd7384a37c 684 chk_sum += ip4_addr_get_u32(&iphdr->src) >> 16;
grzemich 0:d7bd7384a37c 685 chk_sum = (chk_sum >> 16) + (chk_sum & 0xFFFF);
grzemich 0:d7bd7384a37c 686 chk_sum = (chk_sum >> 16) + chk_sum;
grzemich 0:d7bd7384a37c 687 chk_sum = ~chk_sum;
grzemich 0:d7bd7384a37c 688 iphdr->_chksum = chk_sum; /* network order */
grzemich 0:d7bd7384a37c 689 #else /* CHECKSUM_GEN_IP_INLINE */
grzemich 0:d7bd7384a37c 690 IPH_CHKSUM_SET(iphdr, 0);
grzemich 0:d7bd7384a37c 691 #if CHECKSUM_GEN_IP
grzemich 0:d7bd7384a37c 692 IPH_CHKSUM_SET(iphdr, inet_chksum(iphdr, ip_hlen));
grzemich 0:d7bd7384a37c 693 #endif
grzemich 0:d7bd7384a37c 694 #endif /* CHECKSUM_GEN_IP_INLINE */
grzemich 0:d7bd7384a37c 695 } else {
grzemich 0:d7bd7384a37c 696 /* IP header already included in p */
grzemich 0:d7bd7384a37c 697 iphdr = (struct ip_hdr *)p->payload;
grzemich 0:d7bd7384a37c 698 ip_addr_copy(dest_addr, iphdr->dest);
grzemich 0:d7bd7384a37c 699 dest = &dest_addr;
grzemich 0:d7bd7384a37c 700 }
grzemich 0:d7bd7384a37c 701
grzemich 0:d7bd7384a37c 702 IP_STATS_INC(ip.xmit);
grzemich 0:d7bd7384a37c 703
grzemich 0:d7bd7384a37c 704 LWIP_DEBUGF(IP_DEBUG, ("ip_output_if: %c%c%"U16_F"\n", netif->name[0], netif->name[1], netif->num));
grzemich 0:d7bd7384a37c 705 ip_debug_print(p);
grzemich 0:d7bd7384a37c 706
grzemich 0:d7bd7384a37c 707 #if ENABLE_LOOPBACK
grzemich 0:d7bd7384a37c 708 if (ip_addr_cmp(dest, &netif->ip_addr)) {
grzemich 0:d7bd7384a37c 709 /* Packet to self, enqueue it for loopback */
grzemich 0:d7bd7384a37c 710 LWIP_DEBUGF(IP_DEBUG, ("netif_loop_output()"));
grzemich 0:d7bd7384a37c 711 return netif_loop_output(netif, p, dest);
grzemich 0:d7bd7384a37c 712 }
grzemich 0:d7bd7384a37c 713 #if LWIP_IGMP
grzemich 0:d7bd7384a37c 714 if ((p->flags & PBUF_FLAG_MCASTLOOP) != 0) {
grzemich 0:d7bd7384a37c 715 netif_loop_output(netif, p, dest);
grzemich 0:d7bd7384a37c 716 }
grzemich 0:d7bd7384a37c 717 #endif /* LWIP_IGMP */
grzemich 0:d7bd7384a37c 718 #endif /* ENABLE_LOOPBACK */
grzemich 0:d7bd7384a37c 719 #if IP_FRAG
grzemich 0:d7bd7384a37c 720 /* don't fragment if interface has mtu set to 0 [loopif] */
grzemich 0:d7bd7384a37c 721 if (netif->mtu && (p->tot_len > netif->mtu)) {
grzemich 0:d7bd7384a37c 722 return ip_frag(p, netif, dest);
grzemich 0:d7bd7384a37c 723 }
grzemich 0:d7bd7384a37c 724 #endif /* IP_FRAG */
grzemich 0:d7bd7384a37c 725
grzemich 0:d7bd7384a37c 726 LWIP_DEBUGF(IP_DEBUG, ("netif->output()"));
grzemich 0:d7bd7384a37c 727 return netif->output(netif, p, dest);
grzemich 0:d7bd7384a37c 728 }
grzemich 0:d7bd7384a37c 729
grzemich 0:d7bd7384a37c 730 /**
grzemich 0:d7bd7384a37c 731 * Simple interface to ip_output_if. It finds the outgoing network
grzemich 0:d7bd7384a37c 732 * interface and calls upon ip_output_if to do the actual work.
grzemich 0:d7bd7384a37c 733 *
grzemich 0:d7bd7384a37c 734 * @param p the packet to send (p->payload points to the data, e.g. next
grzemich 0:d7bd7384a37c 735 protocol header; if dest == IP_HDRINCL, p already includes an IP
grzemich 0:d7bd7384a37c 736 header and p->payload points to that IP header)
grzemich 0:d7bd7384a37c 737 * @param src the source IP address to send from (if src == IP_ADDR_ANY, the
grzemich 0:d7bd7384a37c 738 * IP address of the netif used to send is used as source address)
grzemich 0:d7bd7384a37c 739 * @param dest the destination IP address to send the packet to
grzemich 0:d7bd7384a37c 740 * @param ttl the TTL value to be set in the IP header
grzemich 0:d7bd7384a37c 741 * @param tos the TOS value to be set in the IP header
grzemich 0:d7bd7384a37c 742 * @param proto the PROTOCOL to be set in the IP header
grzemich 0:d7bd7384a37c 743 *
grzemich 0:d7bd7384a37c 744 * @return ERR_RTE if no route is found
grzemich 0:d7bd7384a37c 745 * see ip_output_if() for more return values
grzemich 0:d7bd7384a37c 746 */
grzemich 0:d7bd7384a37c 747 err_t
grzemich 0:d7bd7384a37c 748 ip_output(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
grzemich 0:d7bd7384a37c 749 u8_t ttl, u8_t tos, u8_t proto)
grzemich 0:d7bd7384a37c 750 {
grzemich 0:d7bd7384a37c 751 struct netif *netif;
grzemich 0:d7bd7384a37c 752
grzemich 0:d7bd7384a37c 753 /* pbufs passed to IP must have a ref-count of 1 as their payload pointer
grzemich 0:d7bd7384a37c 754 gets altered as the packet is passed down the stack */
grzemich 0:d7bd7384a37c 755 LWIP_ASSERT("p->ref == 1", p->ref == 1);
grzemich 0:d7bd7384a37c 756
grzemich 0:d7bd7384a37c 757 if ((netif = ip_route(dest)) == NULL) {
grzemich 0:d7bd7384a37c 758 LWIP_DEBUGF(IP_DEBUG, ("ip_output: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
grzemich 0:d7bd7384a37c 759 ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest)));
grzemich 0:d7bd7384a37c 760 IP_STATS_INC(ip.rterr);
grzemich 0:d7bd7384a37c 761 return ERR_RTE;
grzemich 0:d7bd7384a37c 762 }
grzemich 0:d7bd7384a37c 763
grzemich 0:d7bd7384a37c 764 return ip_output_if(p, src, dest, ttl, tos, proto, netif);
grzemich 0:d7bd7384a37c 765 }
grzemich 0:d7bd7384a37c 766
grzemich 0:d7bd7384a37c 767 #if LWIP_NETIF_HWADDRHINT
grzemich 0:d7bd7384a37c 768 /** Like ip_output, but takes and addr_hint pointer that is passed on to netif->addr_hint
grzemich 0:d7bd7384a37c 769 * before calling ip_output_if.
grzemich 0:d7bd7384a37c 770 *
grzemich 0:d7bd7384a37c 771 * @param p the packet to send (p->payload points to the data, e.g. next
grzemich 0:d7bd7384a37c 772 protocol header; if dest == IP_HDRINCL, p already includes an IP
grzemich 0:d7bd7384a37c 773 header and p->payload points to that IP header)
grzemich 0:d7bd7384a37c 774 * @param src the source IP address to send from (if src == IP_ADDR_ANY, the
grzemich 0:d7bd7384a37c 775 * IP address of the netif used to send is used as source address)
grzemich 0:d7bd7384a37c 776 * @param dest the destination IP address to send the packet to
grzemich 0:d7bd7384a37c 777 * @param ttl the TTL value to be set in the IP header
grzemich 0:d7bd7384a37c 778 * @param tos the TOS value to be set in the IP header
grzemich 0:d7bd7384a37c 779 * @param proto the PROTOCOL to be set in the IP header
grzemich 0:d7bd7384a37c 780 * @param addr_hint address hint pointer set to netif->addr_hint before
grzemich 0:d7bd7384a37c 781 * calling ip_output_if()
grzemich 0:d7bd7384a37c 782 *
grzemich 0:d7bd7384a37c 783 * @return ERR_RTE if no route is found
grzemich 0:d7bd7384a37c 784 * see ip_output_if() for more return values
grzemich 0:d7bd7384a37c 785 */
grzemich 0:d7bd7384a37c 786 err_t
grzemich 0:d7bd7384a37c 787 ip_output_hinted(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
grzemich 0:d7bd7384a37c 788 u8_t ttl, u8_t tos, u8_t proto, u8_t *addr_hint)
grzemich 0:d7bd7384a37c 789 {
grzemich 0:d7bd7384a37c 790 struct netif *netif;
grzemich 0:d7bd7384a37c 791 err_t err;
grzemich 0:d7bd7384a37c 792
grzemich 0:d7bd7384a37c 793 /* pbufs passed to IP must have a ref-count of 1 as their payload pointer
grzemich 0:d7bd7384a37c 794 gets altered as the packet is passed down the stack */
grzemich 0:d7bd7384a37c 795 LWIP_ASSERT("p->ref == 1", p->ref == 1);
grzemich 0:d7bd7384a37c 796
grzemich 0:d7bd7384a37c 797 if ((netif = ip_route(dest)) == NULL) {
grzemich 0:d7bd7384a37c 798 LWIP_DEBUGF(IP_DEBUG, ("ip_output: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
grzemich 0:d7bd7384a37c 799 ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest)));
grzemich 0:d7bd7384a37c 800 IP_STATS_INC(ip.rterr);
grzemich 0:d7bd7384a37c 801 return ERR_RTE;
grzemich 0:d7bd7384a37c 802 }
grzemich 0:d7bd7384a37c 803
grzemich 0:d7bd7384a37c 804 netif->addr_hint = addr_hint;
grzemich 0:d7bd7384a37c 805 err = ip_output_if(p, src, dest, ttl, tos, proto, netif);
grzemich 0:d7bd7384a37c 806 netif->addr_hint = NULL;
grzemich 0:d7bd7384a37c 807
grzemich 0:d7bd7384a37c 808 return err;
grzemich 0:d7bd7384a37c 809 }
grzemich 0:d7bd7384a37c 810 #endif /* LWIP_NETIF_HWADDRHINT*/
grzemich 0:d7bd7384a37c 811
grzemich 0:d7bd7384a37c 812 #if IP_DEBUG
grzemich 0:d7bd7384a37c 813 /* Print an IP header by using LWIP_DEBUGF
grzemich 0:d7bd7384a37c 814 * @param p an IP packet, p->payload pointing to the IP header
grzemich 0:d7bd7384a37c 815 */
grzemich 0:d7bd7384a37c 816 void
grzemich 0:d7bd7384a37c 817 ip_debug_print(struct pbuf *p)
grzemich 0:d7bd7384a37c 818 {
grzemich 0:d7bd7384a37c 819 struct ip_hdr *iphdr = (struct ip_hdr *)p->payload;
grzemich 0:d7bd7384a37c 820 u8_t *payload;
grzemich 0:d7bd7384a37c 821
grzemich 0:d7bd7384a37c 822 payload = (u8_t *)iphdr + IP_HLEN;
grzemich 0:d7bd7384a37c 823
grzemich 0:d7bd7384a37c 824 LWIP_DEBUGF(IP_DEBUG, ("IP header:\n"));
grzemich 0:d7bd7384a37c 825 LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
grzemich 0:d7bd7384a37c 826 LWIP_DEBUGF(IP_DEBUG, ("|%2"S16_F" |%2"S16_F" | 0x%02"X16_F" | %5"U16_F" | (v, hl, tos, len)\n",
grzemich 0:d7bd7384a37c 827 IPH_V(iphdr),
grzemich 0:d7bd7384a37c 828 IPH_HL(iphdr),
grzemich 0:d7bd7384a37c 829 IPH_TOS(iphdr),
grzemich 0:d7bd7384a37c 830 ntohs(IPH_LEN(iphdr))));
grzemich 0:d7bd7384a37c 831 LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
grzemich 0:d7bd7384a37c 832 LWIP_DEBUGF(IP_DEBUG, ("| %5"U16_F" |%"U16_F"%"U16_F"%"U16_F"| %4"U16_F" | (id, flags, offset)\n",
grzemich 0:d7bd7384a37c 833 ntohs(IPH_ID(iphdr)),
grzemich 0:d7bd7384a37c 834 ntohs(IPH_OFFSET(iphdr)) >> 15 & 1,
grzemich 0:d7bd7384a37c 835 ntohs(IPH_OFFSET(iphdr)) >> 14 & 1,
grzemich 0:d7bd7384a37c 836 ntohs(IPH_OFFSET(iphdr)) >> 13 & 1,
grzemich 0:d7bd7384a37c 837 ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK));
grzemich 0:d7bd7384a37c 838 LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
grzemich 0:d7bd7384a37c 839 LWIP_DEBUGF(IP_DEBUG, ("| %3"U16_F" | %3"U16_F" | 0x%04"X16_F" | (ttl, proto, chksum)\n",
grzemich 0:d7bd7384a37c 840 IPH_TTL(iphdr),
grzemich 0:d7bd7384a37c 841 IPH_PROTO(iphdr),
grzemich 0:d7bd7384a37c 842 ntohs(IPH_CHKSUM(iphdr))));
grzemich 0:d7bd7384a37c 843 LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
grzemich 0:d7bd7384a37c 844 LWIP_DEBUGF(IP_DEBUG, ("| %3"U16_F" | %3"U16_F" | %3"U16_F" | %3"U16_F" | (src)\n",
grzemich 0:d7bd7384a37c 845 ip4_addr1_16(&iphdr->src),
grzemich 0:d7bd7384a37c 846 ip4_addr2_16(&iphdr->src),
grzemich 0:d7bd7384a37c 847 ip4_addr3_16(&iphdr->src),
grzemich 0:d7bd7384a37c 848 ip4_addr4_16(&iphdr->src)));
grzemich 0:d7bd7384a37c 849 LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
grzemich 0:d7bd7384a37c 850 LWIP_DEBUGF(IP_DEBUG, ("| %3"U16_F" | %3"U16_F" | %3"U16_F" | %3"U16_F" | (dest)\n",
grzemich 0:d7bd7384a37c 851 ip4_addr1_16(&iphdr->dest),
grzemich 0:d7bd7384a37c 852 ip4_addr2_16(&iphdr->dest),
grzemich 0:d7bd7384a37c 853 ip4_addr3_16(&iphdr->dest),
grzemich 0:d7bd7384a37c 854 ip4_addr4_16(&iphdr->dest)));
grzemich 0:d7bd7384a37c 855 LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
grzemich 0:d7bd7384a37c 856 }
grzemich 0:d7bd7384a37c 857 #endif /* IP_DEBUG */