I have a problem getting this to work. Server only recieves half of the data being sent. Whats wrong

Dependencies:   mbed

Committer:
tax
Date:
Tue Mar 29 13:20:15 2011 +0000
Revision:
0:66300c77c6e9

        

Who changed what in which revision?

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