1 /** 2 * @file 3 * netif API (to be used from TCPIP thread) 4 */ 5 6 /* 7 * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without modification, 11 * are permitted provided that the following conditions are met: 12 * 13 * 1. Redistributions of source code must retain the above copyright notice, 14 * this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright notice, 16 * this list of conditions and the following disclaimer in the documentation 17 * and/or other materials provided with the distribution. 18 * 3. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 24 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 30 * OF SUCH DAMAGE. 31 * 32 * This file is part of the lwIP TCP/IP stack. 33 * 34 * Author: Adam Dunkels <adam@sics.se> 35 * 36 */ 37 #ifndef LWIP_HDR_NETIF_H 38 #define LWIP_HDR_NETIF_H 39 40 #include "lwip/opt.h" 41 42 #define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF) 43 44 #include "lwip/err.h" 45 46 #include "lwip/ip_addr.h" 47 48 #include "lwip/def.h" 49 #include "lwip/pbuf.h" 50 #include "lwip/stats.h" 51 #ifdef LOSCFG_NET_CONTAINER 52 #include "lwip/net_group.h" 53 #endif 54 55 #ifdef __cplusplus 56 extern "C" { 57 #endif 58 59 /* Throughout this file, IP addresses are expected to be in 60 * the same byte order as in IP_PCB. */ 61 62 /** Must be the maximum of all used hardware address lengths 63 across all types of interfaces in use. 64 This does not have to be changed, normally. */ 65 #ifndef NETIF_MAX_HWADDR_LEN 66 #define NETIF_MAX_HWADDR_LEN 6U 67 #endif 68 69 /** The size of a fully constructed netif name which the 70 * netif can be identified by in APIs. Composed of 71 * 2 chars, 3 (max) digits, and 1 \0 72 */ 73 #define NETIF_NAMESIZE 6 74 75 /** 76 * @defgroup netif_flags Flags 77 * @ingroup netif 78 * @{ 79 */ 80 81 /** Whether the network interface is 'up'. This is 82 * a software flag used to control whether this network 83 * interface is enabled and processes traffic. 84 * It must be set by the startup code before this netif can be used 85 * (also for dhcp/autoip). 86 */ 87 #define NETIF_FLAG_UP 0x01U 88 /** If set, the netif has broadcast capability. 89 * Set by the netif driver in its init function. */ 90 #define NETIF_FLAG_BROADCAST 0x02U 91 /** If set, the interface has an active link 92 * (set by the network interface driver). 93 * Either set by the netif driver in its init function (if the link 94 * is up at that time) or at a later point once the link comes up 95 * (if link detection is supported by the hardware). */ 96 #define NETIF_FLAG_LINK_UP 0x04U 97 /** If set, the netif is an ethernet device using ARP. 98 * Set by the netif driver in its init function. 99 * Used to check input packet types and use of DHCP. */ 100 #define NETIF_FLAG_ETHARP 0x08U 101 /** If set, the netif is an ethernet device. It might not use 102 * ARP or TCP/IP if it is used for PPPoE only. 103 */ 104 #define NETIF_FLAG_ETHERNET 0x10U 105 /** If set, the netif has IGMP capability. 106 * Set by the netif driver in its init function. */ 107 #define NETIF_FLAG_IGMP 0x20U 108 /** If set, the netif has MLD6 capability. 109 * Set by the netif driver in its init function. */ 110 #define NETIF_FLAG_MLD6 0x40U 111 112 /** 113 * @} 114 */ 115 116 enum lwip_internal_netif_client_data_index 117 { 118 #if LWIP_IPV4 119 #if LWIP_DHCP 120 LWIP_NETIF_CLIENT_DATA_INDEX_DHCP, 121 #endif 122 #if LWIP_AUTOIP 123 LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP, 124 #endif 125 #if LWIP_ACD 126 LWIP_NETIF_CLIENT_DATA_INDEX_ACD, 127 #endif 128 #if LWIP_IGMP 129 LWIP_NETIF_CLIENT_DATA_INDEX_IGMP, 130 #endif 131 #endif /* LWIP_IPV4 */ 132 #if LWIP_IPV6 133 #if LWIP_IPV6_DHCP6 134 LWIP_NETIF_CLIENT_DATA_INDEX_DHCP6, 135 #endif 136 #if LWIP_IPV6_MLD 137 LWIP_NETIF_CLIENT_DATA_INDEX_MLD6, 138 #endif 139 #endif /* LWIP_IPV6 */ 140 LWIP_NETIF_CLIENT_DATA_INDEX_MAX 141 }; 142 143 #if LWIP_CHECKSUM_CTRL_PER_NETIF 144 #define NETIF_CHECKSUM_GEN_IP 0x0001 145 #define NETIF_CHECKSUM_GEN_UDP 0x0002 146 #define NETIF_CHECKSUM_GEN_TCP 0x0004 147 #define NETIF_CHECKSUM_GEN_ICMP 0x0008 148 #define NETIF_CHECKSUM_GEN_ICMP6 0x0010 149 #define NETIF_CHECKSUM_CHECK_IP 0x0100 150 #define NETIF_CHECKSUM_CHECK_UDP 0x0200 151 #define NETIF_CHECKSUM_CHECK_TCP 0x0400 152 #define NETIF_CHECKSUM_CHECK_ICMP 0x0800 153 #define NETIF_CHECKSUM_CHECK_ICMP6 0x1000 154 #define NETIF_CHECKSUM_ENABLE_ALL 0xFFFF 155 #define NETIF_CHECKSUM_DISABLE_ALL 0x0000 156 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */ 157 158 struct netif; 159 160 /** MAC Filter Actions, these are passed to a netif's igmp_mac_filter or 161 * mld_mac_filter callback function. */ 162 enum netif_mac_filter_action { 163 /** Delete a filter entry */ 164 NETIF_DEL_MAC_FILTER = 0, 165 /** Add a filter entry */ 166 NETIF_ADD_MAC_FILTER = 1 167 }; 168 169 /** Function prototype for netif init functions. Set up flags and output/linkoutput 170 * callback functions in this function. 171 * 172 * @param netif The netif to initialize 173 */ 174 typedef err_t (*netif_init_fn)(struct netif *netif); 175 /** Function prototype for netif->input functions. This function is saved as 'input' 176 * callback function in the netif struct. Call it when a packet has been received. 177 * 178 * @param p The received packet, copied into a pbuf 179 * @param inp The netif which received the packet 180 * @return ERR_OK if the packet was handled 181 * != ERR_OK is the packet was NOT handled, in this case, the caller has 182 * to free the pbuf 183 */ 184 typedef err_t (*netif_input_fn)(struct pbuf *p, struct netif *inp); 185 186 #if LWIP_IPV4 187 /** Function prototype for netif->output functions. Called by lwIP when a packet 188 * shall be sent. For ethernet netif, set this to 'etharp_output' and set 189 * 'linkoutput'. 190 * 191 * @param netif The netif which shall send a packet 192 * @param p The packet to send (p->payload points to IP header) 193 * @param ipaddr The IP address to which the packet shall be sent 194 */ 195 typedef err_t (*netif_output_fn)(struct netif *netif, struct pbuf *p, 196 const ip4_addr_t *ipaddr); 197 #endif /* LWIP_IPV4*/ 198 199 #if LWIP_IPV6 200 /** Function prototype for netif->output_ip6 functions. Called by lwIP when a packet 201 * shall be sent. For ethernet netif, set this to 'ethip6_output' and set 202 * 'linkoutput'. 203 * 204 * @param netif The netif which shall send a packet 205 * @param p The packet to send (p->payload points to IP header) 206 * @param ipaddr The IPv6 address to which the packet shall be sent 207 */ 208 typedef err_t (*netif_output_ip6_fn)(struct netif *netif, struct pbuf *p, 209 const ip6_addr_t *ipaddr); 210 #endif /* LWIP_IPV6 */ 211 212 /** Function prototype for netif->linkoutput functions. Only used for ethernet 213 * netifs. This function is called by ARP when a packet shall be sent. 214 * 215 * @param netif The netif which shall send a packet 216 * @param p The packet to send (raw ethernet packet) 217 */ 218 typedef err_t (*netif_linkoutput_fn)(struct netif *netif, struct pbuf *p); 219 /** Function prototype for netif status- or link-callback functions. */ 220 typedef void (*netif_status_callback_fn)(struct netif *netif); 221 #if LWIP_IPV4 && LWIP_IGMP 222 /** Function prototype for netif igmp_mac_filter functions */ 223 typedef err_t (*netif_igmp_mac_filter_fn)(struct netif *netif, 224 const ip4_addr_t *group, enum netif_mac_filter_action action); 225 #endif /* LWIP_IPV4 && LWIP_IGMP */ 226 #if LWIP_IPV6 && LWIP_IPV6_MLD 227 /** Function prototype for netif mld_mac_filter functions */ 228 typedef err_t (*netif_mld_mac_filter_fn)(struct netif *netif, 229 const ip6_addr_t *group, enum netif_mac_filter_action action); 230 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ 231 232 #if LWIP_DHCP || LWIP_AUTOIP || LWIP_IGMP || LWIP_IPV6_MLD || LWIP_IPV6_DHCP6 || (LWIP_NUM_NETIF_CLIENT_DATA > 0) 233 #if LWIP_NUM_NETIF_CLIENT_DATA > 0 234 u8_t netif_alloc_client_data_id(void); 235 #endif 236 /** @ingroup netif_cd 237 * Set client data. Obtain ID from netif_alloc_client_data_id(). 238 */ 239 #define netif_set_client_data(netif, id, data) netif_get_client_data(netif, id) = (data) 240 /** @ingroup netif_cd 241 * Get client data. Obtain ID from netif_alloc_client_data_id(). 242 */ 243 #define netif_get_client_data(netif, id) (netif)->client_data[(id)] 244 #endif 245 246 #if (LWIP_IPV4 && LWIP_ARP && (ARP_TABLE_SIZE > 0x7f)) || (LWIP_IPV6 && (LWIP_ND6_NUM_DESTINATIONS > 0x7f)) 247 typedef u16_t netif_addr_idx_t; 248 #define NETIF_ADDR_IDX_MAX 0x7FFF 249 #else 250 typedef u8_t netif_addr_idx_t; 251 #define NETIF_ADDR_IDX_MAX 0x7F 252 #endif 253 254 #if LWIP_NETIF_HWADDRHINT || LWIP_VLAN_PCP 255 #define LWIP_NETIF_USE_HINTS 1 256 struct netif_hint { 257 #if LWIP_NETIF_HWADDRHINT 258 u8_t addr_hint; 259 #endif 260 #if LWIP_VLAN_PCP 261 /** VLAN hader is set if this is >= 0 (but must be <= 0xFFFF) */ 262 s32_t tci; 263 #endif 264 }; 265 #else /* LWIP_NETIF_HWADDRHINT || LWIP_VLAN_PCP */ 266 #define LWIP_NETIF_USE_HINTS 0 267 #endif /* LWIP_NETIF_HWADDRHINT || LWIP_VLAN_PCP*/ 268 269 /** Generic data structure used for all lwIP network interfaces. 270 * The following fields should be filled in by the initialization 271 * function for the device driver: hwaddr_len, hwaddr[], mtu, flags */ 272 struct netif { 273 #if !LWIP_SINGLE_NETIF 274 /** pointer to next in linked list */ 275 struct netif *next; 276 #endif 277 278 #if LWIP_IPV4 279 /** IP address configuration in network byte order */ 280 ip_addr_t ip_addr; 281 ip_addr_t netmask; 282 ip_addr_t gw; 283 #endif /* LWIP_IPV4 */ 284 #if LWIP_IPV6 285 /** Array of IPv6 addresses for this netif. */ 286 ip_addr_t ip6_addr[LWIP_IPV6_NUM_ADDRESSES]; 287 /** The state of each IPv6 address (Tentative, Preferred, etc). 288 * @see ip6_addr.h */ 289 u8_t ip6_addr_state[LWIP_IPV6_NUM_ADDRESSES]; 290 #if LWIP_IPV6_ADDRESS_LIFETIMES 291 /** Remaining valid and preferred lifetime of each IPv6 address, in seconds. 292 * For valid lifetimes, the special value of IP6_ADDR_LIFE_STATIC (0) 293 * indicates the address is static and has no lifetimes. */ 294 u32_t ip6_addr_valid_life[LWIP_IPV6_NUM_ADDRESSES]; 295 u32_t ip6_addr_pref_life[LWIP_IPV6_NUM_ADDRESSES]; 296 #endif /* LWIP_IPV6_ADDRESS_LIFETIMES */ 297 #endif /* LWIP_IPV6 */ 298 /** This function is called by the network device driver 299 * to pass a packet up the TCP/IP stack. */ 300 netif_input_fn input; 301 #if LWIP_IPV4 302 /** This function is called by the IP module when it wants 303 * to send a packet on the interface. This function typically 304 * first resolves the hardware address, then sends the packet. 305 * For ethernet physical layer, this is usually etharp_output() */ 306 netif_output_fn output; 307 #endif /* LWIP_IPV4 */ 308 /** This function is called by ethernet_output() when it wants 309 * to send a packet on the interface. This function outputs 310 * the pbuf as-is on the link medium. */ 311 netif_linkoutput_fn linkoutput; 312 #if LWIP_IPV6 313 /** This function is called by the IPv6 module when it wants 314 * to send a packet on the interface. This function typically 315 * first resolves the hardware address, then sends the packet. 316 * For ethernet physical layer, this is usually ethip6_output() */ 317 netif_output_ip6_fn output_ip6; 318 #endif /* LWIP_IPV6 */ 319 #if LWIP_NETIF_STATUS_CALLBACK 320 /** This function is called when the netif state is set to up or down 321 */ 322 netif_status_callback_fn status_callback; 323 #endif /* LWIP_NETIF_STATUS_CALLBACK */ 324 #if LWIP_NETIF_LINK_CALLBACK 325 /** This function is called when the netif link is set to up or down 326 */ 327 netif_status_callback_fn link_callback; 328 #endif /* LWIP_NETIF_LINK_CALLBACK */ 329 #if LWIP_NETIF_REMOVE_CALLBACK 330 /** This function is called when the netif has been removed */ 331 netif_status_callback_fn remove_callback; 332 #endif /* LWIP_NETIF_REMOVE_CALLBACK */ 333 /** This field can be set by the device driver and could point 334 * to state information for the device. */ 335 void *state; 336 #ifdef netif_get_client_data 337 void* client_data[LWIP_NETIF_CLIENT_DATA_INDEX_MAX + LWIP_NUM_NETIF_CLIENT_DATA]; 338 #endif 339 #if LWIP_NETIF_HOSTNAME 340 /* the hostname for this netif, NULL is a valid value */ 341 const char* hostname; 342 #endif /* LWIP_NETIF_HOSTNAME */ 343 #if LWIP_CHECKSUM_CTRL_PER_NETIF 344 u16_t chksum_flags; 345 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF*/ 346 /** maximum transfer unit (in bytes) */ 347 u16_t mtu; 348 #if LWIP_IPV6 && LWIP_ND6_ALLOW_RA_UPDATES 349 /** maximum transfer unit (in bytes), updated by RA */ 350 u16_t mtu6; 351 #endif /* LWIP_IPV6 && LWIP_ND6_ALLOW_RA_UPDATES */ 352 /** link level hardware address of this interface */ 353 u8_t hwaddr[NETIF_MAX_HWADDR_LEN]; 354 /** number of bytes used in hwaddr */ 355 u8_t hwaddr_len; 356 /** flags (@see @ref netif_flags) */ 357 u8_t flags; 358 /** descriptive abbreviation */ 359 char name[2]; 360 /** number of this interface. Used for @ref if_api and @ref netifapi_netif, 361 * as well as for IPv6 zones */ 362 u8_t num; 363 #if LWIP_IPV6_AUTOCONFIG 364 /** is this netif enabled for IPv6 autoconfiguration */ 365 u8_t ip6_autoconfig_enabled; 366 #endif /* LWIP_IPV6_AUTOCONFIG */ 367 #if LWIP_IPV6_SEND_ROUTER_SOLICIT 368 /** Number of Router Solicitation messages that remain to be sent. */ 369 u8_t rs_count; 370 #endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */ 371 #if MIB2_STATS 372 /** link type (from "snmp_ifType" enum from snmp_mib2.h) */ 373 u8_t link_type; 374 /** (estimate) link speed */ 375 u32_t link_speed; 376 /** timestamp at last change made (up/down) */ 377 u32_t ts; 378 /** counters */ 379 struct stats_mib2_netif_ctrs mib2_counters; 380 #endif /* MIB2_STATS */ 381 #if LWIP_IPV4 && LWIP_IGMP 382 /** This function could be called to add or delete an entry in the multicast 383 filter table of the ethernet MAC.*/ 384 netif_igmp_mac_filter_fn igmp_mac_filter; 385 #endif /* LWIP_IPV4 && LWIP_IGMP */ 386 #if LWIP_IPV6 && LWIP_IPV6_MLD 387 /** This function could be called to add or delete an entry in the IPv6 multicast 388 filter table of the ethernet MAC. */ 389 netif_mld_mac_filter_fn mld_mac_filter; 390 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ 391 #if LWIP_ACD 392 struct acd *acd_list; 393 #endif /* LWIP_ACD */ 394 #if LWIP_NETIF_USE_HINTS 395 struct netif_hint *hints; 396 #endif /* LWIP_NETIF_USE_HINTS */ 397 #if ENABLE_LOOPBACK 398 /* List of packets to be queued for ourselves. */ 399 struct pbuf *loop_first; 400 struct pbuf *loop_last; 401 #if LWIP_LOOPBACK_MAX_PBUFS 402 u16_t loop_cnt_current; 403 #endif /* LWIP_LOOPBACK_MAX_PBUFS */ 404 #if LWIP_NETIF_LOOPBACK_MULTITHREADING 405 /* Used if the original scheduling failed. */ 406 u8_t reschedule_poll; 407 #endif /* LWIP_NETIF_LOOPBACK_MULTITHREADING */ 408 #endif /* ENABLE_LOOPBACK */ 409 }; 410 411 #if LWIP_CHECKSUM_CTRL_PER_NETIF 412 #define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags) do { \ 413 (netif)->chksum_flags = chksumflags; } while(0) 414 #define NETIF_CHECKSUM_ENABLED(netif, chksumflag) (((netif) == NULL) || (((netif)->chksum_flags & (chksumflag)) != 0)) 415 #define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag) if NETIF_CHECKSUM_ENABLED(netif, chksumflag) 416 #else /* LWIP_CHECKSUM_CTRL_PER_NETIF */ 417 #define NETIF_CHECKSUM_ENABLED(netif, chksumflag) 0 418 #define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags) 419 #define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag) 420 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */ 421 422 #if LWIP_SINGLE_NETIF 423 #ifdef LOSCFG_NET_CONTAINER 424 #define NETIF_FOREACH(netif, group) if (((netif) = group->netif_default) != NULL) 425 #else 426 #define NETIF_FOREACH(netif) if (((netif) = netif_default) != NULL) 427 #endif 428 #else /* LWIP_SINGLE_NETIF */ 429 #ifdef LOSCFG_NET_CONTAINER 430 #define NETIF_FOREACH(netif, group) for ((netif) = group->netif_list; (netif) != NULL; (netif) = (netif)->next) 431 #else 432 /** The list of network interfaces. */ 433 extern struct netif *netif_list; 434 #define NETIF_FOREACH(netif) for ((netif) = netif_list; (netif) != NULL; (netif) = (netif)->next) 435 #endif 436 437 #endif /* LWIP_SINGLE_NETIF */ 438 #ifndef LOSCFG_NET_CONTAINER 439 /** The default network interface. */ 440 extern struct netif *netif_default; 441 #endif 442 443 #ifdef LOSCFG_NET_CONTAINER 444 struct net_group *get_net_group_from_netif(struct netif *netif); 445 void netif_init(struct net_group *group); 446 #else 447 void netif_init(void); 448 #endif 449 450 #ifdef LOSCFG_NET_CONTAINER 451 struct netif *netif_add_noaddr(struct netif *netif, struct net_group *group, 452 void *state, netif_init_fn init, netif_input_fn input); 453 #else 454 struct netif *netif_add_noaddr(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input); 455 #endif 456 457 #if LWIP_IPV4 458 #ifdef LOSCFG_NET_CONTAINER 459 struct netif *netif_add(struct netif *netif, struct net_group *group, 460 #else 461 struct netif *netif_add(struct netif *netif, 462 #endif 463 const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw, 464 void *state, netif_init_fn init, netif_input_fn input); 465 void netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, 466 const ip4_addr_t *gw); 467 #else /* LWIP_IPV4 */ 468 struct netif *netif_add(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input); 469 #endif /* LWIP_IPV4 */ 470 void netif_remove(struct netif * netif); 471 472 /* Returns a network interface given its name. The name is of the form 473 "et0", where the first two letters are the "name" field in the 474 netif structure, and the digit is in the num field in the same 475 structure. */ 476 struct netif *netif_find(const char *name); 477 478 #ifdef LOSCFG_NET_CONTAINER 479 void netif_set_default(struct netif *netif, struct net_group *group); 480 void netif_set_default2(struct netif *netif); 481 #else 482 void netif_set_default(struct netif *netif); 483 #endif 484 485 #if LWIP_IPV4 486 void netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr); 487 void netif_set_netmask(struct netif *netif, const ip4_addr_t *netmask); 488 void netif_set_gw(struct netif *netif, const ip4_addr_t *gw); 489 /** @ingroup netif_ip4 */ 490 #define netif_ip4_addr(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->ip_addr))) 491 /** @ingroup netif_ip4 */ 492 #define netif_ip4_netmask(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->netmask))) 493 /** @ingroup netif_ip4 */ 494 #define netif_ip4_gw(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->gw))) 495 /** @ingroup netif_ip4 */ 496 #define netif_ip_addr4(netif) ((const ip_addr_t*)&((netif)->ip_addr)) 497 /** @ingroup netif_ip4 */ 498 #define netif_ip_netmask4(netif) ((const ip_addr_t*)&((netif)->netmask)) 499 /** @ingroup netif_ip4 */ 500 #define netif_ip_gw4(netif) ((const ip_addr_t*)&((netif)->gw)) 501 #endif /* LWIP_IPV4 */ 502 503 #define netif_set_flags(netif, set_flags) do { (netif)->flags = (u8_t)((netif)->flags | (set_flags)); } while(0) 504 #define netif_clear_flags(netif, clr_flags) do { (netif)->flags = (u8_t)((netif)->flags & (u8_t)(~(clr_flags) & 0xff)); } while(0) 505 #define netif_is_flag_set(netif, flag) (((netif)->flags & (flag)) != 0) 506 507 void netif_set_up(struct netif *netif); 508 void netif_set_down(struct netif *netif); 509 /** @ingroup netif 510 * Ask if an interface is up 511 */ 512 #define netif_is_up(netif) (((netif)->flags & NETIF_FLAG_UP) ? (u8_t)1 : (u8_t)0) 513 514 #if LWIP_NETIF_STATUS_CALLBACK 515 void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback); 516 #endif /* LWIP_NETIF_STATUS_CALLBACK */ 517 #if LWIP_NETIF_REMOVE_CALLBACK 518 void netif_set_remove_callback(struct netif *netif, netif_status_callback_fn remove_callback); 519 #endif /* LWIP_NETIF_REMOVE_CALLBACK */ 520 521 void netif_set_link_up(struct netif *netif); 522 void netif_set_link_down(struct netif *netif); 523 /** Ask if a link is up */ 524 #define netif_is_link_up(netif) (((netif)->flags & NETIF_FLAG_LINK_UP) ? (u8_t)1 : (u8_t)0) 525 526 #if LWIP_NETIF_LINK_CALLBACK 527 void netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_callback); 528 #endif /* LWIP_NETIF_LINK_CALLBACK */ 529 530 #if LWIP_NETIF_HOSTNAME 531 /** @ingroup netif */ 532 #define netif_set_hostname(netif, name) do { if((netif) != NULL) { (netif)->hostname = name; }}while(0) 533 /** @ingroup netif */ 534 #define netif_get_hostname(netif) (((netif) != NULL) ? ((netif)->hostname) : NULL) 535 #endif /* LWIP_NETIF_HOSTNAME */ 536 537 #if LWIP_IGMP 538 /** @ingroup netif 539 * Set igmp mac filter function for a netif. */ 540 #define netif_set_igmp_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->igmp_mac_filter = function; }}while(0) 541 /** Get the igmp mac filter function for a netif. */ 542 #define netif_get_igmp_mac_filter(netif) (((netif) != NULL) ? ((netif)->igmp_mac_filter) : NULL) 543 #endif /* LWIP_IGMP */ 544 545 #if LWIP_IPV6 && LWIP_IPV6_MLD 546 /** @ingroup netif 547 * Set mld mac filter function for a netif. */ 548 #define netif_set_mld_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->mld_mac_filter = function; }}while(0) 549 /** Get the mld mac filter function for a netif. */ 550 #define netif_get_mld_mac_filter(netif) (((netif) != NULL) ? ((netif)->mld_mac_filter) : NULL) 551 #define netif_mld_mac_filter(netif, addr, action) do { if((netif) && (netif)->mld_mac_filter) { (netif)->mld_mac_filter((netif), (addr), (action)); }}while(0) 552 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ 553 554 #if ENABLE_LOOPBACK 555 err_t netif_loop_output(struct netif *netif, struct pbuf *p); 556 void netif_poll(struct netif *netif); 557 #if !LWIP_NETIF_LOOPBACK_MULTITHREADING 558 void netif_poll_all(void); 559 #endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */ 560 #endif /* ENABLE_LOOPBACK */ 561 562 err_t netif_input(struct pbuf *p, struct netif *inp); 563 564 #if LWIP_IPV6 565 /** @ingroup netif_ip6 */ 566 #define netif_ip_addr6(netif, i) ((const ip_addr_t*)(&((netif)->ip6_addr[i]))) 567 /** @ingroup netif_ip6 */ 568 #define netif_ip6_addr(netif, i) ((const ip6_addr_t*)ip_2_ip6(&((netif)->ip6_addr[i]))) 569 void netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, const ip6_addr_t *addr6); 570 void netif_ip6_addr_set_parts(struct netif *netif, s8_t addr_idx, u32_t i0, u32_t i1, u32_t i2, u32_t i3); 571 #define netif_ip6_addr_state(netif, i) ((netif)->ip6_addr_state[i]) 572 void netif_ip6_addr_set_state(struct netif* netif, s8_t addr_idx, u8_t state); 573 s8_t netif_get_ip6_addr_match(struct netif *netif, const ip6_addr_t *ip6addr); 574 void netif_create_ip6_linklocal_address(struct netif *netif, u8_t from_mac_48bit); 575 err_t netif_add_ip6_address(struct netif *netif, const ip6_addr_t *ip6addr, s8_t *chosen_idx); 576 #define netif_set_ip6_autoconfig_enabled(netif, action) do { if(netif) { (netif)->ip6_autoconfig_enabled = (action); }}while(0) 577 #if LWIP_IPV6_ADDRESS_LIFETIMES 578 #define netif_ip6_addr_valid_life(netif, i) \ 579 (((netif) != NULL) ? ((netif)->ip6_addr_valid_life[i]) : IP6_ADDR_LIFE_STATIC) 580 #define netif_ip6_addr_set_valid_life(netif, i, secs) \ 581 do { if (netif != NULL) { (netif)->ip6_addr_valid_life[i] = (secs); }} while (0) 582 #define netif_ip6_addr_pref_life(netif, i) \ 583 (((netif) != NULL) ? ((netif)->ip6_addr_pref_life[i]) : IP6_ADDR_LIFE_STATIC) 584 #define netif_ip6_addr_set_pref_life(netif, i, secs) \ 585 do { if (netif != NULL) { (netif)->ip6_addr_pref_life[i] = (secs); }} while (0) 586 #define netif_ip6_addr_isstatic(netif, i) \ 587 (netif_ip6_addr_valid_life((netif), (i)) == IP6_ADDR_LIFE_STATIC) 588 #else /* !LWIP_IPV6_ADDRESS_LIFETIMES */ 589 #define netif_ip6_addr_isstatic(netif, i) (1) /* all addresses are static */ 590 #endif /* !LWIP_IPV6_ADDRESS_LIFETIMES */ 591 #if LWIP_ND6_ALLOW_RA_UPDATES 592 #define netif_mtu6(netif) ((netif)->mtu6) 593 #else /* LWIP_ND6_ALLOW_RA_UPDATES */ 594 #define netif_mtu6(netif) ((netif)->mtu) 595 #endif /* LWIP_ND6_ALLOW_RA_UPDATES */ 596 #endif /* LWIP_IPV6 */ 597 598 #if LWIP_NETIF_USE_HINTS 599 #define NETIF_SET_HINTS(netif, netifhint) (netif)->hints = (netifhint) 600 #define NETIF_RESET_HINTS(netif) (netif)->hints = NULL 601 #else /* LWIP_NETIF_USE_HINTS */ 602 #define NETIF_SET_HINTS(netif, netifhint) 603 #define NETIF_RESET_HINTS(netif) 604 #endif /* LWIP_NETIF_USE_HINTS */ 605 606 u8_t netif_name_to_index(const char *name); 607 #ifdef LOSCFG_NET_CONTAINER 608 char * netif_index_to_name(u8_t idx, char *name, struct net_group *group); 609 struct netif* netif_get_by_index(u8_t idx, struct net_group *group); 610 #else 611 char * netif_index_to_name(u8_t idx, char *name); 612 struct netif* netif_get_by_index(u8_t idx); 613 #endif 614 615 /* Interface indexes always start at 1 per RFC 3493, section 4, num starts at 0 (internal index is 0..254)*/ 616 #define netif_get_index(netif) ((u8_t)((netif)->num + 1)) 617 #define NETIF_NO_INDEX (0) 618 619 /** 620 * @ingroup netif 621 * Extended netif status callback (NSC) reasons flags. 622 * May be extended in the future! 623 */ 624 typedef u16_t netif_nsc_reason_t; 625 626 /* used for initialization only */ 627 #define LWIP_NSC_NONE 0x0000 628 /** netif was added. arg: NULL. Called AFTER netif was added. */ 629 #define LWIP_NSC_NETIF_ADDED 0x0001 630 /** netif was removed. arg: NULL. Called BEFORE netif is removed. */ 631 #define LWIP_NSC_NETIF_REMOVED 0x0002 632 /** link changed */ 633 #define LWIP_NSC_LINK_CHANGED 0x0004 634 /** netif administrative status changed.<br> 635 * up is called AFTER netif is set up.<br> 636 * down is called BEFORE the netif is actually set down. */ 637 #define LWIP_NSC_STATUS_CHANGED 0x0008 638 /** IPv4 address has changed */ 639 #define LWIP_NSC_IPV4_ADDRESS_CHANGED 0x0010 640 /** IPv4 gateway has changed */ 641 #define LWIP_NSC_IPV4_GATEWAY_CHANGED 0x0020 642 /** IPv4 netmask has changed */ 643 #define LWIP_NSC_IPV4_NETMASK_CHANGED 0x0040 644 /** called AFTER IPv4 address/gateway/netmask changes have been applied */ 645 #define LWIP_NSC_IPV4_SETTINGS_CHANGED 0x0080 646 /** IPv6 address was added */ 647 #define LWIP_NSC_IPV6_SET 0x0100 648 /** IPv6 address state has changed */ 649 #define LWIP_NSC_IPV6_ADDR_STATE_CHANGED 0x0200 650 /** IPv4 settings: valid address set, application may start to communicate */ 651 #define LWIP_NSC_IPV4_ADDR_VALID 0x0400 652 653 /** @ingroup netif 654 * Argument supplied to netif_ext_callback_fn. 655 */ 656 typedef union 657 { 658 /** Args to LWIP_NSC_LINK_CHANGED callback */ 659 struct link_changed_s 660 { 661 /** 1: up; 0: down */ 662 u8_t state; 663 } link_changed; 664 /** Args to LWIP_NSC_STATUS_CHANGED callback */ 665 struct status_changed_s 666 { 667 /** 1: up; 0: down */ 668 u8_t state; 669 } status_changed; 670 /** Args to LWIP_NSC_IPV4_ADDRESS_CHANGED|LWIP_NSC_IPV4_GATEWAY_CHANGED|LWIP_NSC_IPV4_NETMASK_CHANGED|LWIP_NSC_IPV4_SETTINGS_CHANGED callback */ 671 struct ipv4_changed_s 672 { 673 /** Old IPv4 address */ 674 const ip_addr_t* old_address; 675 const ip_addr_t* old_netmask; 676 const ip_addr_t* old_gw; 677 } ipv4_changed; 678 /** Args to LWIP_NSC_IPV6_SET callback */ 679 struct ipv6_set_s 680 { 681 /** Index of changed IPv6 address */ 682 s8_t addr_index; 683 /** Old IPv6 address */ 684 const ip_addr_t* old_address; 685 } ipv6_set; 686 /** Args to LWIP_NSC_IPV6_ADDR_STATE_CHANGED callback */ 687 struct ipv6_addr_state_changed_s 688 { 689 /** Index of affected IPv6 address */ 690 s8_t addr_index; 691 /** Old IPv6 address state */ 692 u8_t old_state; 693 /** Affected IPv6 address */ 694 const ip_addr_t* address; 695 } ipv6_addr_state_changed; 696 } netif_ext_callback_args_t; 697 698 /** 699 * @ingroup netif 700 * Function used for extended netif status callbacks 701 * Note: When parsing reason argument, keep in mind that more reasons may be added in the future! 702 * @param netif netif that is affected by change 703 * @param reason change reason 704 * @param args depends on reason, see reason description 705 */ 706 typedef void (*netif_ext_callback_fn)(struct netif* netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t* args); 707 708 #if LWIP_NETIF_EXT_STATUS_CALLBACK 709 struct netif_ext_callback; 710 typedef struct netif_ext_callback 711 { 712 netif_ext_callback_fn callback_fn; 713 struct netif_ext_callback* next; 714 } netif_ext_callback_t; 715 716 #define NETIF_DECLARE_EXT_CALLBACK(name) static netif_ext_callback_t name; 717 void netif_add_ext_callback(netif_ext_callback_t* callback, netif_ext_callback_fn fn); 718 void netif_remove_ext_callback(netif_ext_callback_t* callback); 719 void netif_invoke_ext_callback(struct netif* netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t* args); 720 #else 721 #define NETIF_DECLARE_EXT_CALLBACK(name) 722 #define netif_add_ext_callback(callback, fn) 723 #define netif_remove_ext_callback(callback) 724 #define netif_invoke_ext_callback(netif, reason, args) 725 #endif 726 727 #if LWIP_TESTMODE && LWIP_HAVE_LOOPIF 728 struct netif* netif_get_loopif(void); 729 #endif 730 731 732 #ifdef __cplusplus 733 } 734 #endif 735 736 #endif /* LWIP_HDR_NETIF_H */ 737