Modified version of NetServices. Fixes an issue where connections failed should the HTTP response status line be received in a packet on its own prior to any further headers. Changes are made to the HTTPClient.cpp file's readHeaders method.

Committer:
andrewbonney
Date:
Fri Apr 08 14:39:41 2011 +0000
Revision:
0:ec559500a63f

        

Who changed what in which revision?

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