Netservices modded to read fragmented HTTP respsonse/payload from special purpose server - 180 bytes only

Committer:
RodColeman
Date:
Thu Sep 08 10:48:09 2011 +0000
Revision:
0:850eacf3e945
revised fixed length to 178 bytes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RodColeman 0:850eacf3e945 1 /**
RodColeman 0:850eacf3e945 2 * @file
RodColeman 0:850eacf3e945 3 * lwIP network interface abstraction
RodColeman 0:850eacf3e945 4 *
RodColeman 0:850eacf3e945 5 */
RodColeman 0:850eacf3e945 6
RodColeman 0:850eacf3e945 7 /*
RodColeman 0:850eacf3e945 8 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
RodColeman 0:850eacf3e945 9 * All rights reserved.
RodColeman 0:850eacf3e945 10 *
RodColeman 0:850eacf3e945 11 * Redistribution and use in source and binary forms, with or without modification,
RodColeman 0:850eacf3e945 12 * are permitted provided that the following conditions are met:
RodColeman 0:850eacf3e945 13 *
RodColeman 0:850eacf3e945 14 * 1. Redistributions of source code must retain the above copyright notice,
RodColeman 0:850eacf3e945 15 * this list of conditions and the following disclaimer.
RodColeman 0:850eacf3e945 16 * 2. Redistributions in binary form must reproduce the above copyright notice,
RodColeman 0:850eacf3e945 17 * this list of conditions and the following disclaimer in the documentation
RodColeman 0:850eacf3e945 18 * and/or other materials provided with the distribution.
RodColeman 0:850eacf3e945 19 * 3. The name of the author may not be used to endorse or promote products
RodColeman 0:850eacf3e945 20 * derived from this software without specific prior written permission.
RodColeman 0:850eacf3e945 21 *
RodColeman 0:850eacf3e945 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
RodColeman 0:850eacf3e945 23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
RodColeman 0:850eacf3e945 24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
RodColeman 0:850eacf3e945 25 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
RodColeman 0:850eacf3e945 26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
RodColeman 0:850eacf3e945 27 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
RodColeman 0:850eacf3e945 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
RodColeman 0:850eacf3e945 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
RodColeman 0:850eacf3e945 30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
RodColeman 0:850eacf3e945 31 * OF SUCH DAMAGE.
RodColeman 0:850eacf3e945 32 *
RodColeman 0:850eacf3e945 33 * This file is part of the lwIP TCP/IP stack.
RodColeman 0:850eacf3e945 34 *
RodColeman 0:850eacf3e945 35 * Author: Adam Dunkels <adam@sics.se>
RodColeman 0:850eacf3e945 36 *
RodColeman 0:850eacf3e945 37 */
RodColeman 0:850eacf3e945 38
RodColeman 0:850eacf3e945 39 #include "lwip/opt.h"
RodColeman 0:850eacf3e945 40
RodColeman 0:850eacf3e945 41 #include "lwip/def.h"
RodColeman 0:850eacf3e945 42 #include "lwip/ip_addr.h"
RodColeman 0:850eacf3e945 43 #include "lwip/netif.h"
RodColeman 0:850eacf3e945 44 #include "lwip/tcp_impl.h"
RodColeman 0:850eacf3e945 45 #include "lwip/snmp.h"
RodColeman 0:850eacf3e945 46 #include "lwip/igmp.h"
RodColeman 0:850eacf3e945 47 #include "netif/etharp.h"
RodColeman 0:850eacf3e945 48 #include "lwip/stats.h"
RodColeman 0:850eacf3e945 49 #if ENABLE_LOOPBACK
RodColeman 0:850eacf3e945 50 #include "lwip/sys.h"
RodColeman 0:850eacf3e945 51 #if LWIP_NETIF_LOOPBACK_MULTITHREADING
RodColeman 0:850eacf3e945 52 #include "lwip/tcpip.h"
RodColeman 0:850eacf3e945 53 #endif /* LWIP_NETIF_LOOPBACK_MULTITHREADING */
RodColeman 0:850eacf3e945 54 #endif /* ENABLE_LOOPBACK */
RodColeman 0:850eacf3e945 55
RodColeman 0:850eacf3e945 56 #if LWIP_AUTOIP
RodColeman 0:850eacf3e945 57 #include "lwip/autoip.h"
RodColeman 0:850eacf3e945 58 #endif /* LWIP_AUTOIP */
RodColeman 0:850eacf3e945 59 #if LWIP_DHCP
RodColeman 0:850eacf3e945 60 #include "lwip/dhcp.h"
RodColeman 0:850eacf3e945 61 #endif /* LWIP_DHCP */
RodColeman 0:850eacf3e945 62
RodColeman 0:850eacf3e945 63 #if LWIP_NETIF_STATUS_CALLBACK
RodColeman 0:850eacf3e945 64 #define NETIF_STATUS_CALLBACK(n) do{ if (n->status_callback) { (n->status_callback)(n); }}while(0)
RodColeman 0:850eacf3e945 65 #else
RodColeman 0:850eacf3e945 66 #define NETIF_STATUS_CALLBACK(n)
RodColeman 0:850eacf3e945 67 #endif /* LWIP_NETIF_STATUS_CALLBACK */
RodColeman 0:850eacf3e945 68
RodColeman 0:850eacf3e945 69 #if LWIP_NETIF_LINK_CALLBACK
RodColeman 0:850eacf3e945 70 #define NETIF_LINK_CALLBACK(n) do{ if (n->link_callback) { (n->link_callback)(n); }}while(0)
RodColeman 0:850eacf3e945 71 #else
RodColeman 0:850eacf3e945 72 #define NETIF_LINK_CALLBACK(n)
RodColeman 0:850eacf3e945 73 #endif /* LWIP_NETIF_LINK_CALLBACK */
RodColeman 0:850eacf3e945 74
RodColeman 0:850eacf3e945 75 struct netif *netif_list;
RodColeman 0:850eacf3e945 76 struct netif *netif_default;
RodColeman 0:850eacf3e945 77
RodColeman 0:850eacf3e945 78 #if LWIP_HAVE_LOOPIF
RodColeman 0:850eacf3e945 79 static struct netif loop_netif;
RodColeman 0:850eacf3e945 80
RodColeman 0:850eacf3e945 81 /**
RodColeman 0:850eacf3e945 82 * Initialize a lwip network interface structure for a loopback interface
RodColeman 0:850eacf3e945 83 *
RodColeman 0:850eacf3e945 84 * @param netif the lwip network interface structure for this loopif
RodColeman 0:850eacf3e945 85 * @return ERR_OK if the loopif is initialized
RodColeman 0:850eacf3e945 86 * ERR_MEM if private data couldn't be allocated
RodColeman 0:850eacf3e945 87 */
RodColeman 0:850eacf3e945 88 static err_t
RodColeman 0:850eacf3e945 89 netif_loopif_init(struct netif *netif)
RodColeman 0:850eacf3e945 90 {
RodColeman 0:850eacf3e945 91 /* initialize the snmp variables and counters inside the struct netif
RodColeman 0:850eacf3e945 92 * ifSpeed: no assumption can be made!
RodColeman 0:850eacf3e945 93 */
RodColeman 0:850eacf3e945 94 NETIF_INIT_SNMP(netif, snmp_ifType_softwareLoopback, 0);
RodColeman 0:850eacf3e945 95
RodColeman 0:850eacf3e945 96 netif->name[0] = 'l';
RodColeman 0:850eacf3e945 97 netif->name[1] = 'o';
RodColeman 0:850eacf3e945 98 netif->output = netif_loop_output;
RodColeman 0:850eacf3e945 99 return ERR_OK;
RodColeman 0:850eacf3e945 100 }
RodColeman 0:850eacf3e945 101 #endif /* LWIP_HAVE_LOOPIF */
RodColeman 0:850eacf3e945 102
RodColeman 0:850eacf3e945 103 void
RodColeman 0:850eacf3e945 104 netif_init(void)
RodColeman 0:850eacf3e945 105 {
RodColeman 0:850eacf3e945 106 #if LWIP_HAVE_LOOPIF
RodColeman 0:850eacf3e945 107 ip_addr_t loop_ipaddr, loop_netmask, loop_gw;
RodColeman 0:850eacf3e945 108 IP4_ADDR(&loop_gw, 127,0,0,1);
RodColeman 0:850eacf3e945 109 IP4_ADDR(&loop_ipaddr, 127,0,0,1);
RodColeman 0:850eacf3e945 110 IP4_ADDR(&loop_netmask, 255,0,0,0);
RodColeman 0:850eacf3e945 111
RodColeman 0:850eacf3e945 112 #if NO_SYS
RodColeman 0:850eacf3e945 113 netif_add(&loop_netif, &loop_ipaddr, &loop_netmask, &loop_gw, NULL, netif_loopif_init, ip_input);
RodColeman 0:850eacf3e945 114 #else /* NO_SYS */
RodColeman 0:850eacf3e945 115 netif_add(&loop_netif, &loop_ipaddr, &loop_netmask, &loop_gw, NULL, netif_loopif_init, tcpip_input);
RodColeman 0:850eacf3e945 116 #endif /* NO_SYS */
RodColeman 0:850eacf3e945 117 netif_set_up(&loop_netif);
RodColeman 0:850eacf3e945 118
RodColeman 0:850eacf3e945 119 #endif /* LWIP_HAVE_LOOPIF */
RodColeman 0:850eacf3e945 120 }
RodColeman 0:850eacf3e945 121
RodColeman 0:850eacf3e945 122 /**
RodColeman 0:850eacf3e945 123 * Add a network interface to the list of lwIP netifs.
RodColeman 0:850eacf3e945 124 *
RodColeman 0:850eacf3e945 125 * @param netif a pre-allocated netif structure
RodColeman 0:850eacf3e945 126 * @param ipaddr IP address for the new netif
RodColeman 0:850eacf3e945 127 * @param netmask network mask for the new netif
RodColeman 0:850eacf3e945 128 * @param gw default gateway IP address for the new netif
RodColeman 0:850eacf3e945 129 * @param state opaque data passed to the new netif
RodColeman 0:850eacf3e945 130 * @param init callback function that initializes the interface
RodColeman 0:850eacf3e945 131 * @param input callback function that is called to pass
RodColeman 0:850eacf3e945 132 * ingress packets up in the protocol layer stack.
RodColeman 0:850eacf3e945 133 *
RodColeman 0:850eacf3e945 134 * @return netif, or NULL if failed.
RodColeman 0:850eacf3e945 135 */
RodColeman 0:850eacf3e945 136 struct netif *
RodColeman 0:850eacf3e945 137 netif_add(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask,
RodColeman 0:850eacf3e945 138 ip_addr_t *gw, void *state, netif_init_fn init, netif_input_fn input)
RodColeman 0:850eacf3e945 139 {
RodColeman 0:850eacf3e945 140 static u8_t netifnum = 0;
RodColeman 0:850eacf3e945 141
RodColeman 0:850eacf3e945 142 LWIP_ASSERT("No init function given", init != NULL);
RodColeman 0:850eacf3e945 143
RodColeman 0:850eacf3e945 144 /* reset new interface configuration state */
RodColeman 0:850eacf3e945 145 ip_addr_set_zero(&netif->ip_addr);
RodColeman 0:850eacf3e945 146 ip_addr_set_zero(&netif->netmask);
RodColeman 0:850eacf3e945 147 ip_addr_set_zero(&netif->gw);
RodColeman 0:850eacf3e945 148 netif->flags = 0;
RodColeman 0:850eacf3e945 149 #if LWIP_DHCP
RodColeman 0:850eacf3e945 150 /* netif not under DHCP control by default */
RodColeman 0:850eacf3e945 151 netif->dhcp = NULL;
RodColeman 0:850eacf3e945 152 #endif /* LWIP_DHCP */
RodColeman 0:850eacf3e945 153 #if LWIP_AUTOIP
RodColeman 0:850eacf3e945 154 /* netif not under AutoIP control by default */
RodColeman 0:850eacf3e945 155 netif->autoip = NULL;
RodColeman 0:850eacf3e945 156 #endif /* LWIP_AUTOIP */
RodColeman 0:850eacf3e945 157 #if LWIP_NETIF_STATUS_CALLBACK
RodColeman 0:850eacf3e945 158 netif->status_callback = NULL;
RodColeman 0:850eacf3e945 159 #endif /* LWIP_NETIF_STATUS_CALLBACK */
RodColeman 0:850eacf3e945 160 #if LWIP_NETIF_LINK_CALLBACK
RodColeman 0:850eacf3e945 161 netif->link_callback = NULL;
RodColeman 0:850eacf3e945 162 #endif /* LWIP_NETIF_LINK_CALLBACK */
RodColeman 0:850eacf3e945 163 #if LWIP_IGMP
RodColeman 0:850eacf3e945 164 netif->igmp_mac_filter = NULL;
RodColeman 0:850eacf3e945 165 #endif /* LWIP_IGMP */
RodColeman 0:850eacf3e945 166 #if ENABLE_LOOPBACK
RodColeman 0:850eacf3e945 167 netif->loop_first = NULL;
RodColeman 0:850eacf3e945 168 netif->loop_last = NULL;
RodColeman 0:850eacf3e945 169 #endif /* ENABLE_LOOPBACK */
RodColeman 0:850eacf3e945 170
RodColeman 0:850eacf3e945 171 /* remember netif specific state information data */
RodColeman 0:850eacf3e945 172 netif->state = state;
RodColeman 0:850eacf3e945 173 netif->num = netifnum++;
RodColeman 0:850eacf3e945 174 netif->input = input;
RodColeman 0:850eacf3e945 175 #if LWIP_NETIF_HWADDRHINT
RodColeman 0:850eacf3e945 176 netif->addr_hint = NULL;
RodColeman 0:850eacf3e945 177 #endif /* LWIP_NETIF_HWADDRHINT*/
RodColeman 0:850eacf3e945 178 #if ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS
RodColeman 0:850eacf3e945 179 netif->loop_cnt_current = 0;
RodColeman 0:850eacf3e945 180 #endif /* ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS */
RodColeman 0:850eacf3e945 181
RodColeman 0:850eacf3e945 182 netif_set_addr(netif, ipaddr, netmask, gw);
RodColeman 0:850eacf3e945 183
RodColeman 0:850eacf3e945 184 /* call user specified initialization function for netif */
RodColeman 0:850eacf3e945 185 if (init(netif) != ERR_OK) {
RodColeman 0:850eacf3e945 186 return NULL;
RodColeman 0:850eacf3e945 187 }
RodColeman 0:850eacf3e945 188
RodColeman 0:850eacf3e945 189 /* add this netif to the list */
RodColeman 0:850eacf3e945 190 netif->next = netif_list;
RodColeman 0:850eacf3e945 191 netif_list = netif;
RodColeman 0:850eacf3e945 192 snmp_inc_iflist();
RodColeman 0:850eacf3e945 193
RodColeman 0:850eacf3e945 194 #if LWIP_IGMP
RodColeman 0:850eacf3e945 195 /* start IGMP processing */
RodColeman 0:850eacf3e945 196 if (netif->flags & NETIF_FLAG_IGMP) {
RodColeman 0:850eacf3e945 197 igmp_start(netif);
RodColeman 0:850eacf3e945 198 }
RodColeman 0:850eacf3e945 199 #endif /* LWIP_IGMP */
RodColeman 0:850eacf3e945 200
RodColeman 0:850eacf3e945 201 LWIP_DEBUGF(NETIF_DEBUG, ("netif: added interface %c%c IP addr ",
RodColeman 0:850eacf3e945 202 netif->name[0], netif->name[1]));
RodColeman 0:850eacf3e945 203 ip_addr_debug_print(NETIF_DEBUG, ipaddr);
RodColeman 0:850eacf3e945 204 LWIP_DEBUGF(NETIF_DEBUG, (" netmask "));
RodColeman 0:850eacf3e945 205 ip_addr_debug_print(NETIF_DEBUG, netmask);
RodColeman 0:850eacf3e945 206 LWIP_DEBUGF(NETIF_DEBUG, (" gw "));
RodColeman 0:850eacf3e945 207 ip_addr_debug_print(NETIF_DEBUG, gw);
RodColeman 0:850eacf3e945 208 LWIP_DEBUGF(NETIF_DEBUG, ("\n"));
RodColeman 0:850eacf3e945 209 return netif;
RodColeman 0:850eacf3e945 210 }
RodColeman 0:850eacf3e945 211
RodColeman 0:850eacf3e945 212 /**
RodColeman 0:850eacf3e945 213 * Change IP address configuration for a network interface (including netmask
RodColeman 0:850eacf3e945 214 * and default gateway).
RodColeman 0:850eacf3e945 215 *
RodColeman 0:850eacf3e945 216 * @param netif the network interface to change
RodColeman 0:850eacf3e945 217 * @param ipaddr the new IP address
RodColeman 0:850eacf3e945 218 * @param netmask the new netmask
RodColeman 0:850eacf3e945 219 * @param gw the new default gateway
RodColeman 0:850eacf3e945 220 */
RodColeman 0:850eacf3e945 221 void
RodColeman 0:850eacf3e945 222 netif_set_addr(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask,
RodColeman 0:850eacf3e945 223 ip_addr_t *gw)
RodColeman 0:850eacf3e945 224 {
RodColeman 0:850eacf3e945 225 netif_set_ipaddr(netif, ipaddr);
RodColeman 0:850eacf3e945 226 netif_set_netmask(netif, netmask);
RodColeman 0:850eacf3e945 227 netif_set_gw(netif, gw);
RodColeman 0:850eacf3e945 228 }
RodColeman 0:850eacf3e945 229
RodColeman 0:850eacf3e945 230 /**
RodColeman 0:850eacf3e945 231 * Remove a network interface from the list of lwIP netifs.
RodColeman 0:850eacf3e945 232 *
RodColeman 0:850eacf3e945 233 * @param netif the network interface to remove
RodColeman 0:850eacf3e945 234 */
RodColeman 0:850eacf3e945 235 void
RodColeman 0:850eacf3e945 236 netif_remove(struct netif *netif)
RodColeman 0:850eacf3e945 237 {
RodColeman 0:850eacf3e945 238 if (netif == NULL) {
RodColeman 0:850eacf3e945 239 return;
RodColeman 0:850eacf3e945 240 }
RodColeman 0:850eacf3e945 241
RodColeman 0:850eacf3e945 242 #if LWIP_IGMP
RodColeman 0:850eacf3e945 243 /* stop IGMP processing */
RodColeman 0:850eacf3e945 244 if (netif->flags & NETIF_FLAG_IGMP) {
RodColeman 0:850eacf3e945 245 igmp_stop(netif);
RodColeman 0:850eacf3e945 246 }
RodColeman 0:850eacf3e945 247 #endif /* LWIP_IGMP */
RodColeman 0:850eacf3e945 248 if (netif_is_up(netif)) {
RodColeman 0:850eacf3e945 249 /* set netif down before removing (call callback function) */
RodColeman 0:850eacf3e945 250 netif_set_down(netif);
RodColeman 0:850eacf3e945 251 }
RodColeman 0:850eacf3e945 252
RodColeman 0:850eacf3e945 253 snmp_delete_ipaddridx_tree(netif);
RodColeman 0:850eacf3e945 254
RodColeman 0:850eacf3e945 255 /* is it the first netif? */
RodColeman 0:850eacf3e945 256 if (netif_list == netif) {
RodColeman 0:850eacf3e945 257 netif_list = netif->next;
RodColeman 0:850eacf3e945 258 } else {
RodColeman 0:850eacf3e945 259 /* look for netif further down the list */
RodColeman 0:850eacf3e945 260 struct netif * tmpNetif;
RodColeman 0:850eacf3e945 261 for (tmpNetif = netif_list; tmpNetif != NULL; tmpNetif = tmpNetif->next) {
RodColeman 0:850eacf3e945 262 if (tmpNetif->next == netif) {
RodColeman 0:850eacf3e945 263 tmpNetif->next = netif->next;
RodColeman 0:850eacf3e945 264 break;
RodColeman 0:850eacf3e945 265 }
RodColeman 0:850eacf3e945 266 }
RodColeman 0:850eacf3e945 267 if (tmpNetif == NULL)
RodColeman 0:850eacf3e945 268 return; /* we didn't find any netif today */
RodColeman 0:850eacf3e945 269 }
RodColeman 0:850eacf3e945 270 snmp_dec_iflist();
RodColeman 0:850eacf3e945 271 /* this netif is default? */
RodColeman 0:850eacf3e945 272 if (netif_default == netif) {
RodColeman 0:850eacf3e945 273 /* reset default netif */
RodColeman 0:850eacf3e945 274 netif_set_default(NULL);
RodColeman 0:850eacf3e945 275 }
RodColeman 0:850eacf3e945 276 LWIP_DEBUGF( NETIF_DEBUG, ("netif_remove: removed netif\n") );
RodColeman 0:850eacf3e945 277 }
RodColeman 0:850eacf3e945 278
RodColeman 0:850eacf3e945 279 /**
RodColeman 0:850eacf3e945 280 * Find a network interface by searching for its name
RodColeman 0:850eacf3e945 281 *
RodColeman 0:850eacf3e945 282 * @param name the name of the netif (like netif->name) plus concatenated number
RodColeman 0:850eacf3e945 283 * in ascii representation (e.g. 'en0')
RodColeman 0:850eacf3e945 284 */
RodColeman 0:850eacf3e945 285 struct netif *
RodColeman 0:850eacf3e945 286 netif_find(char *name)
RodColeman 0:850eacf3e945 287 {
RodColeman 0:850eacf3e945 288 struct netif *netif;
RodColeman 0:850eacf3e945 289 u8_t num;
RodColeman 0:850eacf3e945 290
RodColeman 0:850eacf3e945 291 if (name == NULL) {
RodColeman 0:850eacf3e945 292 return NULL;
RodColeman 0:850eacf3e945 293 }
RodColeman 0:850eacf3e945 294
RodColeman 0:850eacf3e945 295 num = name[2] - '0';
RodColeman 0:850eacf3e945 296
RodColeman 0:850eacf3e945 297 for(netif = netif_list; netif != NULL; netif = netif->next) {
RodColeman 0:850eacf3e945 298 if (num == netif->num &&
RodColeman 0:850eacf3e945 299 name[0] == netif->name[0] &&
RodColeman 0:850eacf3e945 300 name[1] == netif->name[1]) {
RodColeman 0:850eacf3e945 301 LWIP_DEBUGF(NETIF_DEBUG, ("netif_find: found %c%c\n", name[0], name[1]));
RodColeman 0:850eacf3e945 302 return netif;
RodColeman 0:850eacf3e945 303 }
RodColeman 0:850eacf3e945 304 }
RodColeman 0:850eacf3e945 305 LWIP_DEBUGF(NETIF_DEBUG, ("netif_find: didn't find %c%c\n", name[0], name[1]));
RodColeman 0:850eacf3e945 306 return NULL;
RodColeman 0:850eacf3e945 307 }
RodColeman 0:850eacf3e945 308
RodColeman 0:850eacf3e945 309 /**
RodColeman 0:850eacf3e945 310 * Change the IP address of a network interface
RodColeman 0:850eacf3e945 311 *
RodColeman 0:850eacf3e945 312 * @param netif the network interface to change
RodColeman 0:850eacf3e945 313 * @param ipaddr the new IP address
RodColeman 0:850eacf3e945 314 *
RodColeman 0:850eacf3e945 315 * @note call netif_set_addr() if you also want to change netmask and
RodColeman 0:850eacf3e945 316 * default gateway
RodColeman 0:850eacf3e945 317 */
RodColeman 0:850eacf3e945 318 void
RodColeman 0:850eacf3e945 319 netif_set_ipaddr(struct netif *netif, ip_addr_t *ipaddr)
RodColeman 0:850eacf3e945 320 {
RodColeman 0:850eacf3e945 321 /* TODO: Handling of obsolete pcbs */
RodColeman 0:850eacf3e945 322 /* See: http://mail.gnu.org/archive/html/lwip-users/2003-03/msg00118.html */
RodColeman 0:850eacf3e945 323 #if LWIP_TCP
RodColeman 0:850eacf3e945 324 struct tcp_pcb *pcb;
RodColeman 0:850eacf3e945 325 struct tcp_pcb_listen *lpcb;
RodColeman 0:850eacf3e945 326
RodColeman 0:850eacf3e945 327 /* address is actually being changed? */
RodColeman 0:850eacf3e945 328 if ((ip_addr_cmp(ipaddr, &(netif->ip_addr))) == 0) {
RodColeman 0:850eacf3e945 329 /* extern struct tcp_pcb *tcp_active_pcbs; defined by tcp.h */
RodColeman 0:850eacf3e945 330 LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_set_ipaddr: netif address being changed\n"));
RodColeman 0:850eacf3e945 331 pcb = tcp_active_pcbs;
RodColeman 0:850eacf3e945 332 while (pcb != NULL) {
RodColeman 0:850eacf3e945 333 /* PCB bound to current local interface address? */
RodColeman 0:850eacf3e945 334 if (ip_addr_cmp(&(pcb->local_ip), &(netif->ip_addr))
RodColeman 0:850eacf3e945 335 #if LWIP_AUTOIP
RodColeman 0:850eacf3e945 336 /* connections to link-local addresses must persist (RFC3927 ch. 1.9) */
RodColeman 0:850eacf3e945 337 && !ip_addr_islinklocal(&(pcb->local_ip))
RodColeman 0:850eacf3e945 338 #endif /* LWIP_AUTOIP */
RodColeman 0:850eacf3e945 339 ) {
RodColeman 0:850eacf3e945 340 /* this connection must be aborted */
RodColeman 0:850eacf3e945 341 struct tcp_pcb *next = pcb->next;
RodColeman 0:850eacf3e945 342 LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_set_ipaddr: aborting TCP pcb %p\n", (void *)pcb));
RodColeman 0:850eacf3e945 343 tcp_abort(pcb);
RodColeman 0:850eacf3e945 344 pcb = next;
RodColeman 0:850eacf3e945 345 } else {
RodColeman 0:850eacf3e945 346 pcb = pcb->next;
RodColeman 0:850eacf3e945 347 }
RodColeman 0:850eacf3e945 348 }
RodColeman 0:850eacf3e945 349 for (lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = lpcb->next) {
RodColeman 0:850eacf3e945 350 /* PCB bound to current local interface address? */
RodColeman 0:850eacf3e945 351 if ((!(ip_addr_isany(&(lpcb->local_ip)))) &&
RodColeman 0:850eacf3e945 352 (ip_addr_cmp(&(lpcb->local_ip), &(netif->ip_addr)))) {
RodColeman 0:850eacf3e945 353 /* The PCB is listening to the old ipaddr and
RodColeman 0:850eacf3e945 354 * is set to listen to the new one instead */
RodColeman 0:850eacf3e945 355 ip_addr_set(&(lpcb->local_ip), ipaddr);
RodColeman 0:850eacf3e945 356 }
RodColeman 0:850eacf3e945 357 }
RodColeman 0:850eacf3e945 358 }
RodColeman 0:850eacf3e945 359 #endif
RodColeman 0:850eacf3e945 360 snmp_delete_ipaddridx_tree(netif);
RodColeman 0:850eacf3e945 361 snmp_delete_iprteidx_tree(0,netif);
RodColeman 0:850eacf3e945 362 /* set new IP address to netif */
RodColeman 0:850eacf3e945 363 ip_addr_set(&(netif->ip_addr), ipaddr);
RodColeman 0:850eacf3e945 364 snmp_insert_ipaddridx_tree(netif);
RodColeman 0:850eacf3e945 365 snmp_insert_iprteidx_tree(0,netif);
RodColeman 0:850eacf3e945 366
RodColeman 0:850eacf3e945 367 LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: IP address of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
RodColeman 0:850eacf3e945 368 netif->name[0], netif->name[1],
RodColeman 0:850eacf3e945 369 ip4_addr1_16(&netif->ip_addr),
RodColeman 0:850eacf3e945 370 ip4_addr2_16(&netif->ip_addr),
RodColeman 0:850eacf3e945 371 ip4_addr3_16(&netif->ip_addr),
RodColeman 0:850eacf3e945 372 ip4_addr4_16(&netif->ip_addr)));
RodColeman 0:850eacf3e945 373 }
RodColeman 0:850eacf3e945 374
RodColeman 0:850eacf3e945 375 /**
RodColeman 0:850eacf3e945 376 * Change the default gateway for a network interface
RodColeman 0:850eacf3e945 377 *
RodColeman 0:850eacf3e945 378 * @param netif the network interface to change
RodColeman 0:850eacf3e945 379 * @param gw the new default gateway
RodColeman 0:850eacf3e945 380 *
RodColeman 0:850eacf3e945 381 * @note call netif_set_addr() if you also want to change ip address and netmask
RodColeman 0:850eacf3e945 382 */
RodColeman 0:850eacf3e945 383 void
RodColeman 0:850eacf3e945 384 netif_set_gw(struct netif *netif, ip_addr_t *gw)
RodColeman 0:850eacf3e945 385 {
RodColeman 0:850eacf3e945 386 ip_addr_set(&(netif->gw), gw);
RodColeman 0:850eacf3e945 387 LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: GW address of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
RodColeman 0:850eacf3e945 388 netif->name[0], netif->name[1],
RodColeman 0:850eacf3e945 389 ip4_addr1_16(&netif->gw),
RodColeman 0:850eacf3e945 390 ip4_addr2_16(&netif->gw),
RodColeman 0:850eacf3e945 391 ip4_addr3_16(&netif->gw),
RodColeman 0:850eacf3e945 392 ip4_addr4_16(&netif->gw)));
RodColeman 0:850eacf3e945 393 }
RodColeman 0:850eacf3e945 394
RodColeman 0:850eacf3e945 395 /**
RodColeman 0:850eacf3e945 396 * Change the netmask of a network interface
RodColeman 0:850eacf3e945 397 *
RodColeman 0:850eacf3e945 398 * @param netif the network interface to change
RodColeman 0:850eacf3e945 399 * @param netmask the new netmask
RodColeman 0:850eacf3e945 400 *
RodColeman 0:850eacf3e945 401 * @note call netif_set_addr() if you also want to change ip address and
RodColeman 0:850eacf3e945 402 * default gateway
RodColeman 0:850eacf3e945 403 */
RodColeman 0:850eacf3e945 404 void
RodColeman 0:850eacf3e945 405 netif_set_netmask(struct netif *netif, ip_addr_t *netmask)
RodColeman 0:850eacf3e945 406 {
RodColeman 0:850eacf3e945 407 snmp_delete_iprteidx_tree(0, netif);
RodColeman 0:850eacf3e945 408 /* set new netmask to netif */
RodColeman 0:850eacf3e945 409 ip_addr_set(&(netif->netmask), netmask);
RodColeman 0:850eacf3e945 410 snmp_insert_iprteidx_tree(0, netif);
RodColeman 0:850eacf3e945 411 LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: netmask of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
RodColeman 0:850eacf3e945 412 netif->name[0], netif->name[1],
RodColeman 0:850eacf3e945 413 ip4_addr1_16(&netif->netmask),
RodColeman 0:850eacf3e945 414 ip4_addr2_16(&netif->netmask),
RodColeman 0:850eacf3e945 415 ip4_addr3_16(&netif->netmask),
RodColeman 0:850eacf3e945 416 ip4_addr4_16(&netif->netmask)));
RodColeman 0:850eacf3e945 417 }
RodColeman 0:850eacf3e945 418
RodColeman 0:850eacf3e945 419 /**
RodColeman 0:850eacf3e945 420 * Set a network interface as the default network interface
RodColeman 0:850eacf3e945 421 * (used to output all packets for which no specific route is found)
RodColeman 0:850eacf3e945 422 *
RodColeman 0:850eacf3e945 423 * @param netif the default network interface
RodColeman 0:850eacf3e945 424 */
RodColeman 0:850eacf3e945 425 void
RodColeman 0:850eacf3e945 426 netif_set_default(struct netif *netif)
RodColeman 0:850eacf3e945 427 {
RodColeman 0:850eacf3e945 428 if (netif == NULL) {
RodColeman 0:850eacf3e945 429 /* remove default route */
RodColeman 0:850eacf3e945 430 snmp_delete_iprteidx_tree(1, netif);
RodColeman 0:850eacf3e945 431 } else {
RodColeman 0:850eacf3e945 432 /* install default route */
RodColeman 0:850eacf3e945 433 snmp_insert_iprteidx_tree(1, netif);
RodColeman 0:850eacf3e945 434 }
RodColeman 0:850eacf3e945 435 netif_default = netif;
RodColeman 0:850eacf3e945 436 LWIP_DEBUGF(NETIF_DEBUG, ("netif: setting default interface %c%c\n",
RodColeman 0:850eacf3e945 437 netif ? netif->name[0] : '\'', netif ? netif->name[1] : '\''));
RodColeman 0:850eacf3e945 438 }
RodColeman 0:850eacf3e945 439
RodColeman 0:850eacf3e945 440 /**
RodColeman 0:850eacf3e945 441 * Bring an interface up, available for processing
RodColeman 0:850eacf3e945 442 * traffic.
RodColeman 0:850eacf3e945 443 *
RodColeman 0:850eacf3e945 444 * @note: Enabling DHCP on a down interface will make it come
RodColeman 0:850eacf3e945 445 * up once configured.
RodColeman 0:850eacf3e945 446 *
RodColeman 0:850eacf3e945 447 * @see dhcp_start()
RodColeman 0:850eacf3e945 448 */
RodColeman 0:850eacf3e945 449 void netif_set_up(struct netif *netif)
RodColeman 0:850eacf3e945 450 {
RodColeman 0:850eacf3e945 451 if (!(netif->flags & NETIF_FLAG_UP)) {
RodColeman 0:850eacf3e945 452 netif->flags |= NETIF_FLAG_UP;
RodColeman 0:850eacf3e945 453
RodColeman 0:850eacf3e945 454 #if LWIP_SNMP
RodColeman 0:850eacf3e945 455 snmp_get_sysuptime(&netif->ts);
RodColeman 0:850eacf3e945 456 #endif /* LWIP_SNMP */
RodColeman 0:850eacf3e945 457
RodColeman 0:850eacf3e945 458 NETIF_STATUS_CALLBACK(netif);
RodColeman 0:850eacf3e945 459
RodColeman 0:850eacf3e945 460 if (netif->flags & NETIF_FLAG_LINK_UP) {
RodColeman 0:850eacf3e945 461 #if LWIP_ARP
RodColeman 0:850eacf3e945 462 /* For Ethernet network interfaces, we would like to send a "gratuitous ARP" */
RodColeman 0:850eacf3e945 463 if (netif->flags & (NETIF_FLAG_ETHARP)) {
RodColeman 0:850eacf3e945 464 etharp_gratuitous(netif);
RodColeman 0:850eacf3e945 465 }
RodColeman 0:850eacf3e945 466 #endif /* LWIP_ARP */
RodColeman 0:850eacf3e945 467
RodColeman 0:850eacf3e945 468 #if LWIP_IGMP
RodColeman 0:850eacf3e945 469 /* resend IGMP memberships */
RodColeman 0:850eacf3e945 470 if (netif->flags & NETIF_FLAG_IGMP) {
RodColeman 0:850eacf3e945 471 igmp_report_groups( netif);
RodColeman 0:850eacf3e945 472 }
RodColeman 0:850eacf3e945 473 #endif /* LWIP_IGMP */
RodColeman 0:850eacf3e945 474 }
RodColeman 0:850eacf3e945 475 }
RodColeman 0:850eacf3e945 476 }
RodColeman 0:850eacf3e945 477
RodColeman 0:850eacf3e945 478 /**
RodColeman 0:850eacf3e945 479 * Bring an interface down, disabling any traffic processing.
RodColeman 0:850eacf3e945 480 *
RodColeman 0:850eacf3e945 481 * @note: Enabling DHCP on a down interface will make it come
RodColeman 0:850eacf3e945 482 * up once configured.
RodColeman 0:850eacf3e945 483 *
RodColeman 0:850eacf3e945 484 * @see dhcp_start()
RodColeman 0:850eacf3e945 485 */
RodColeman 0:850eacf3e945 486 void netif_set_down(struct netif *netif)
RodColeman 0:850eacf3e945 487 {
RodColeman 0:850eacf3e945 488 if (netif->flags & NETIF_FLAG_UP) {
RodColeman 0:850eacf3e945 489 netif->flags &= ~NETIF_FLAG_UP;
RodColeman 0:850eacf3e945 490 #if LWIP_SNMP
RodColeman 0:850eacf3e945 491 snmp_get_sysuptime(&netif->ts);
RodColeman 0:850eacf3e945 492 #endif
RodColeman 0:850eacf3e945 493
RodColeman 0:850eacf3e945 494 NETIF_STATUS_CALLBACK(netif);
RodColeman 0:850eacf3e945 495 }
RodColeman 0:850eacf3e945 496 }
RodColeman 0:850eacf3e945 497
RodColeman 0:850eacf3e945 498 #if LWIP_NETIF_STATUS_CALLBACK
RodColeman 0:850eacf3e945 499 /**
RodColeman 0:850eacf3e945 500 * Set callback to be called when interface is brought up/down
RodColeman 0:850eacf3e945 501 */
RodColeman 0:850eacf3e945 502 void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback)
RodColeman 0:850eacf3e945 503 {
RodColeman 0:850eacf3e945 504 if (netif) {
RodColeman 0:850eacf3e945 505 netif->status_callback = status_callback;
RodColeman 0:850eacf3e945 506 }
RodColeman 0:850eacf3e945 507 }
RodColeman 0:850eacf3e945 508 #endif /* LWIP_NETIF_STATUS_CALLBACK */
RodColeman 0:850eacf3e945 509
RodColeman 0:850eacf3e945 510 /**
RodColeman 0:850eacf3e945 511 * Called by a driver when its link goes up
RodColeman 0:850eacf3e945 512 */
RodColeman 0:850eacf3e945 513 void netif_set_link_up(struct netif *netif )
RodColeman 0:850eacf3e945 514 {
RodColeman 0:850eacf3e945 515 if (!(netif->flags & NETIF_FLAG_LINK_UP)) {
RodColeman 0:850eacf3e945 516 netif->flags |= NETIF_FLAG_LINK_UP;
RodColeman 0:850eacf3e945 517
RodColeman 0:850eacf3e945 518 #if LWIP_DHCP
RodColeman 0:850eacf3e945 519 if (netif->dhcp) {
RodColeman 0:850eacf3e945 520 dhcp_network_changed(netif);
RodColeman 0:850eacf3e945 521 }
RodColeman 0:850eacf3e945 522 #endif /* LWIP_DHCP */
RodColeman 0:850eacf3e945 523
RodColeman 0:850eacf3e945 524 #if LWIP_AUTOIP
RodColeman 0:850eacf3e945 525 if (netif->autoip) {
RodColeman 0:850eacf3e945 526 autoip_network_changed(netif);
RodColeman 0:850eacf3e945 527 }
RodColeman 0:850eacf3e945 528 #endif /* LWIP_AUTOIP */
RodColeman 0:850eacf3e945 529
RodColeman 0:850eacf3e945 530 if (netif->flags & NETIF_FLAG_UP) {
RodColeman 0:850eacf3e945 531 #if LWIP_ARP
RodColeman 0:850eacf3e945 532 /* For Ethernet network interfaces, we would like to send a "gratuitous ARP" */
RodColeman 0:850eacf3e945 533 if (netif->flags & NETIF_FLAG_ETHARP) {
RodColeman 0:850eacf3e945 534 etharp_gratuitous(netif);
RodColeman 0:850eacf3e945 535 }
RodColeman 0:850eacf3e945 536 #endif /* LWIP_ARP */
RodColeman 0:850eacf3e945 537
RodColeman 0:850eacf3e945 538 #if LWIP_IGMP
RodColeman 0:850eacf3e945 539 /* resend IGMP memberships */
RodColeman 0:850eacf3e945 540 if (netif->flags & NETIF_FLAG_IGMP) {
RodColeman 0:850eacf3e945 541 igmp_report_groups( netif);
RodColeman 0:850eacf3e945 542 }
RodColeman 0:850eacf3e945 543 #endif /* LWIP_IGMP */
RodColeman 0:850eacf3e945 544 }
RodColeman 0:850eacf3e945 545 NETIF_LINK_CALLBACK(netif);
RodColeman 0:850eacf3e945 546 }
RodColeman 0:850eacf3e945 547 }
RodColeman 0:850eacf3e945 548
RodColeman 0:850eacf3e945 549 /**
RodColeman 0:850eacf3e945 550 * Called by a driver when its link goes down
RodColeman 0:850eacf3e945 551 */
RodColeman 0:850eacf3e945 552 void netif_set_link_down(struct netif *netif )
RodColeman 0:850eacf3e945 553 {
RodColeman 0:850eacf3e945 554 if (netif->flags & NETIF_FLAG_LINK_UP) {
RodColeman 0:850eacf3e945 555 netif->flags &= ~NETIF_FLAG_LINK_UP;
RodColeman 0:850eacf3e945 556 NETIF_LINK_CALLBACK(netif);
RodColeman 0:850eacf3e945 557 }
RodColeman 0:850eacf3e945 558 }
RodColeman 0:850eacf3e945 559
RodColeman 0:850eacf3e945 560 #if LWIP_NETIF_LINK_CALLBACK
RodColeman 0:850eacf3e945 561 /**
RodColeman 0:850eacf3e945 562 * Set callback to be called when link is brought up/down
RodColeman 0:850eacf3e945 563 */
RodColeman 0:850eacf3e945 564 void netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_callback)
RodColeman 0:850eacf3e945 565 {
RodColeman 0:850eacf3e945 566 if (netif) {
RodColeman 0:850eacf3e945 567 netif->link_callback = link_callback;
RodColeman 0:850eacf3e945 568 }
RodColeman 0:850eacf3e945 569 }
RodColeman 0:850eacf3e945 570 #endif /* LWIP_NETIF_LINK_CALLBACK */
RodColeman 0:850eacf3e945 571
RodColeman 0:850eacf3e945 572 #if ENABLE_LOOPBACK
RodColeman 0:850eacf3e945 573 /**
RodColeman 0:850eacf3e945 574 * Send an IP packet to be received on the same netif (loopif-like).
RodColeman 0:850eacf3e945 575 * The pbuf is simply copied and handed back to netif->input.
RodColeman 0:850eacf3e945 576 * In multithreaded mode, this is done directly since netif->input must put
RodColeman 0:850eacf3e945 577 * the packet on a queue.
RodColeman 0:850eacf3e945 578 * In callback mode, the packet is put on an internal queue and is fed to
RodColeman 0:850eacf3e945 579 * netif->input by netif_poll().
RodColeman 0:850eacf3e945 580 *
RodColeman 0:850eacf3e945 581 * @param netif the lwip network interface structure
RodColeman 0:850eacf3e945 582 * @param p the (IP) packet to 'send'
RodColeman 0:850eacf3e945 583 * @param ipaddr the ip address to send the packet to (not used)
RodColeman 0:850eacf3e945 584 * @return ERR_OK if the packet has been sent
RodColeman 0:850eacf3e945 585 * ERR_MEM if the pbuf used to copy the packet couldn't be allocated
RodColeman 0:850eacf3e945 586 */
RodColeman 0:850eacf3e945 587 err_t
RodColeman 0:850eacf3e945 588 netif_loop_output(struct netif *netif, struct pbuf *p,
RodColeman 0:850eacf3e945 589 ip_addr_t *ipaddr)
RodColeman 0:850eacf3e945 590 {
RodColeman 0:850eacf3e945 591 struct pbuf *r;
RodColeman 0:850eacf3e945 592 err_t err;
RodColeman 0:850eacf3e945 593 struct pbuf *last;
RodColeman 0:850eacf3e945 594 #if LWIP_LOOPBACK_MAX_PBUFS
RodColeman 0:850eacf3e945 595 u8_t clen = 0;
RodColeman 0:850eacf3e945 596 #endif /* LWIP_LOOPBACK_MAX_PBUFS */
RodColeman 0:850eacf3e945 597 /* If we have a loopif, SNMP counters are adjusted for it,
RodColeman 0:850eacf3e945 598 * if not they are adjusted for 'netif'. */
RodColeman 0:850eacf3e945 599 #if LWIP_SNMP
RodColeman 0:850eacf3e945 600 #if LWIP_HAVE_LOOPIF
RodColeman 0:850eacf3e945 601 struct netif *stats_if = &loop_netif;
RodColeman 0:850eacf3e945 602 #else /* LWIP_HAVE_LOOPIF */
RodColeman 0:850eacf3e945 603 struct netif *stats_if = netif;
RodColeman 0:850eacf3e945 604 #endif /* LWIP_HAVE_LOOPIF */
RodColeman 0:850eacf3e945 605 #endif /* LWIP_SNMP */
RodColeman 0:850eacf3e945 606 SYS_ARCH_DECL_PROTECT(lev);
RodColeman 0:850eacf3e945 607 LWIP_UNUSED_ARG(ipaddr);
RodColeman 0:850eacf3e945 608
RodColeman 0:850eacf3e945 609 /* Allocate a new pbuf */
RodColeman 0:850eacf3e945 610 r = pbuf_alloc(PBUF_LINK, p->tot_len, PBUF_RAM);
RodColeman 0:850eacf3e945 611 if (r == NULL) {
RodColeman 0:850eacf3e945 612 LINK_STATS_INC(link.memerr);
RodColeman 0:850eacf3e945 613 LINK_STATS_INC(link.drop);
RodColeman 0:850eacf3e945 614 snmp_inc_ifoutdiscards(stats_if);
RodColeman 0:850eacf3e945 615 return ERR_MEM;
RodColeman 0:850eacf3e945 616 }
RodColeman 0:850eacf3e945 617 #if LWIP_LOOPBACK_MAX_PBUFS
RodColeman 0:850eacf3e945 618 clen = pbuf_clen(r);
RodColeman 0:850eacf3e945 619 /* check for overflow or too many pbuf on queue */
RodColeman 0:850eacf3e945 620 if(((netif->loop_cnt_current + clen) < netif->loop_cnt_current) ||
RodColeman 0:850eacf3e945 621 ((netif->loop_cnt_current + clen) > LWIP_LOOPBACK_MAX_PBUFS)) {
RodColeman 0:850eacf3e945 622 pbuf_free(r);
RodColeman 0:850eacf3e945 623 LINK_STATS_INC(link.memerr);
RodColeman 0:850eacf3e945 624 LINK_STATS_INC(link.drop);
RodColeman 0:850eacf3e945 625 snmp_inc_ifoutdiscards(stats_if);
RodColeman 0:850eacf3e945 626 return ERR_MEM;
RodColeman 0:850eacf3e945 627 }
RodColeman 0:850eacf3e945 628 netif->loop_cnt_current += clen;
RodColeman 0:850eacf3e945 629 #endif /* LWIP_LOOPBACK_MAX_PBUFS */
RodColeman 0:850eacf3e945 630
RodColeman 0:850eacf3e945 631 /* Copy the whole pbuf queue p into the single pbuf r */
RodColeman 0:850eacf3e945 632 if ((err = pbuf_copy(r, p)) != ERR_OK) {
RodColeman 0:850eacf3e945 633 pbuf_free(r);
RodColeman 0:850eacf3e945 634 LINK_STATS_INC(link.memerr);
RodColeman 0:850eacf3e945 635 LINK_STATS_INC(link.drop);
RodColeman 0:850eacf3e945 636 snmp_inc_ifoutdiscards(stats_if);
RodColeman 0:850eacf3e945 637 return err;
RodColeman 0:850eacf3e945 638 }
RodColeman 0:850eacf3e945 639
RodColeman 0:850eacf3e945 640 /* Put the packet on a linked list which gets emptied through calling
RodColeman 0:850eacf3e945 641 netif_poll(). */
RodColeman 0:850eacf3e945 642
RodColeman 0:850eacf3e945 643 /* let last point to the last pbuf in chain r */
RodColeman 0:850eacf3e945 644 for (last = r; last->next != NULL; last = last->next);
RodColeman 0:850eacf3e945 645
RodColeman 0:850eacf3e945 646 SYS_ARCH_PROTECT(lev);
RodColeman 0:850eacf3e945 647 if(netif->loop_first != NULL) {
RodColeman 0:850eacf3e945 648 LWIP_ASSERT("if first != NULL, last must also be != NULL", netif->loop_last != NULL);
RodColeman 0:850eacf3e945 649 netif->loop_last->next = r;
RodColeman 0:850eacf3e945 650 netif->loop_last = last;
RodColeman 0:850eacf3e945 651 } else {
RodColeman 0:850eacf3e945 652 netif->loop_first = r;
RodColeman 0:850eacf3e945 653 netif->loop_last = last;
RodColeman 0:850eacf3e945 654 }
RodColeman 0:850eacf3e945 655 SYS_ARCH_UNPROTECT(lev);
RodColeman 0:850eacf3e945 656
RodColeman 0:850eacf3e945 657 LINK_STATS_INC(link.xmit);
RodColeman 0:850eacf3e945 658 snmp_add_ifoutoctets(stats_if, p->tot_len);
RodColeman 0:850eacf3e945 659 snmp_inc_ifoutucastpkts(stats_if);
RodColeman 0:850eacf3e945 660
RodColeman 0:850eacf3e945 661 #if LWIP_NETIF_LOOPBACK_MULTITHREADING
RodColeman 0:850eacf3e945 662 /* For multithreading environment, schedule a call to netif_poll */
RodColeman 0:850eacf3e945 663 tcpip_callback((tcpip_callback_fn)netif_poll, netif);
RodColeman 0:850eacf3e945 664 #endif /* LWIP_NETIF_LOOPBACK_MULTITHREADING */
RodColeman 0:850eacf3e945 665
RodColeman 0:850eacf3e945 666 return ERR_OK;
RodColeman 0:850eacf3e945 667 }
RodColeman 0:850eacf3e945 668
RodColeman 0:850eacf3e945 669 /**
RodColeman 0:850eacf3e945 670 * Call netif_poll() in the main loop of your application. This is to prevent
RodColeman 0:850eacf3e945 671 * reentering non-reentrant functions like tcp_input(). Packets passed to
RodColeman 0:850eacf3e945 672 * netif_loop_output() are put on a list that is passed to netif->input() by
RodColeman 0:850eacf3e945 673 * netif_poll().
RodColeman 0:850eacf3e945 674 */
RodColeman 0:850eacf3e945 675 void
RodColeman 0:850eacf3e945 676 netif_poll(struct netif *netif)
RodColeman 0:850eacf3e945 677 {
RodColeman 0:850eacf3e945 678 struct pbuf *in;
RodColeman 0:850eacf3e945 679 /* If we have a loopif, SNMP counters are adjusted for it,
RodColeman 0:850eacf3e945 680 * if not they are adjusted for 'netif'. */
RodColeman 0:850eacf3e945 681 #if LWIP_SNMP
RodColeman 0:850eacf3e945 682 #if LWIP_HAVE_LOOPIF
RodColeman 0:850eacf3e945 683 struct netif *stats_if = &loop_netif;
RodColeman 0:850eacf3e945 684 #else /* LWIP_HAVE_LOOPIF */
RodColeman 0:850eacf3e945 685 struct netif *stats_if = netif;
RodColeman 0:850eacf3e945 686 #endif /* LWIP_HAVE_LOOPIF */
RodColeman 0:850eacf3e945 687 #endif /* LWIP_SNMP */
RodColeman 0:850eacf3e945 688 SYS_ARCH_DECL_PROTECT(lev);
RodColeman 0:850eacf3e945 689
RodColeman 0:850eacf3e945 690 do {
RodColeman 0:850eacf3e945 691 /* Get a packet from the list. With SYS_LIGHTWEIGHT_PROT=1, this is protected */
RodColeman 0:850eacf3e945 692 SYS_ARCH_PROTECT(lev);
RodColeman 0:850eacf3e945 693 in = netif->loop_first;
RodColeman 0:850eacf3e945 694 if (in != NULL) {
RodColeman 0:850eacf3e945 695 struct pbuf *in_end = in;
RodColeman 0:850eacf3e945 696 #if LWIP_LOOPBACK_MAX_PBUFS
RodColeman 0:850eacf3e945 697 u8_t clen = pbuf_clen(in);
RodColeman 0:850eacf3e945 698 /* adjust the number of pbufs on queue */
RodColeman 0:850eacf3e945 699 LWIP_ASSERT("netif->loop_cnt_current underflow",
RodColeman 0:850eacf3e945 700 ((netif->loop_cnt_current - clen) < netif->loop_cnt_current));
RodColeman 0:850eacf3e945 701 netif->loop_cnt_current -= clen;
RodColeman 0:850eacf3e945 702 #endif /* LWIP_LOOPBACK_MAX_PBUFS */
RodColeman 0:850eacf3e945 703 while (in_end->len != in_end->tot_len) {
RodColeman 0:850eacf3e945 704 LWIP_ASSERT("bogus pbuf: len != tot_len but next == NULL!", in_end->next != NULL);
RodColeman 0:850eacf3e945 705 in_end = in_end->next;
RodColeman 0:850eacf3e945 706 }
RodColeman 0:850eacf3e945 707 /* 'in_end' now points to the last pbuf from 'in' */
RodColeman 0:850eacf3e945 708 if (in_end == netif->loop_last) {
RodColeman 0:850eacf3e945 709 /* this was the last pbuf in the list */
RodColeman 0:850eacf3e945 710 netif->loop_first = netif->loop_last = NULL;
RodColeman 0:850eacf3e945 711 } else {
RodColeman 0:850eacf3e945 712 /* pop the pbuf off the list */
RodColeman 0:850eacf3e945 713 netif->loop_first = in_end->next;
RodColeman 0:850eacf3e945 714 LWIP_ASSERT("should not be null since first != last!", netif->loop_first != NULL);
RodColeman 0:850eacf3e945 715 }
RodColeman 0:850eacf3e945 716 /* De-queue the pbuf from its successors on the 'loop_' list. */
RodColeman 0:850eacf3e945 717 in_end->next = NULL;
RodColeman 0:850eacf3e945 718 }
RodColeman 0:850eacf3e945 719 SYS_ARCH_UNPROTECT(lev);
RodColeman 0:850eacf3e945 720
RodColeman 0:850eacf3e945 721 if (in != NULL) {
RodColeman 0:850eacf3e945 722 LINK_STATS_INC(link.recv);
RodColeman 0:850eacf3e945 723 snmp_add_ifinoctets(stats_if, in->tot_len);
RodColeman 0:850eacf3e945 724 snmp_inc_ifinucastpkts(stats_if);
RodColeman 0:850eacf3e945 725 /* loopback packets are always IP packets! */
RodColeman 0:850eacf3e945 726 if (ip_input(in, netif) != ERR_OK) {
RodColeman 0:850eacf3e945 727 pbuf_free(in);
RodColeman 0:850eacf3e945 728 }
RodColeman 0:850eacf3e945 729 /* Don't reference the packet any more! */
RodColeman 0:850eacf3e945 730 in = NULL;
RodColeman 0:850eacf3e945 731 }
RodColeman 0:850eacf3e945 732 /* go on while there is a packet on the list */
RodColeman 0:850eacf3e945 733 } while (netif->loop_first != NULL);
RodColeman 0:850eacf3e945 734 }
RodColeman 0:850eacf3e945 735
RodColeman 0:850eacf3e945 736 #if !LWIP_NETIF_LOOPBACK_MULTITHREADING
RodColeman 0:850eacf3e945 737 /**
RodColeman 0:850eacf3e945 738 * Calls netif_poll() for every netif on the netif_list.
RodColeman 0:850eacf3e945 739 */
RodColeman 0:850eacf3e945 740 void
RodColeman 0:850eacf3e945 741 netif_poll_all(void)
RodColeman 0:850eacf3e945 742 {
RodColeman 0:850eacf3e945 743 struct netif *netif = netif_list;
RodColeman 0:850eacf3e945 744 /* loop through netifs */
RodColeman 0:850eacf3e945 745 while (netif != NULL) {
RodColeman 0:850eacf3e945 746 netif_poll(netif);
RodColeman 0:850eacf3e945 747 /* proceed to next network interface */
RodColeman 0:850eacf3e945 748 netif = netif->next;
RodColeman 0:850eacf3e945 749 }
RodColeman 0:850eacf3e945 750 }
RodColeman 0:850eacf3e945 751 #endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
RodColeman 0:850eacf3e945 752 #endif /* ENABLE_LOOPBACK */