Lines Matching refs:netif

43 #include "lwip/netif.h"
47 #include "netif/etharp.h"
75 struct netif *netif_list;
76 struct netif *netif_default;
81 static struct netif loop_netif;
86 * @param netif the lwip network interface structure for this loopif
91 netif_loopif_init(struct netif *netif)
93 /* initialize the snmp variables and counters inside the struct netif
96 NETIF_INIT_SNMP(netif, snmp_ifType_softwareLoopback, 0);
98 netif->name[0] = 'l';
99 netif->name[1] = 'o';
100 netif->output = netif_loop_output;
127 * @param netif a pre-allocated netif structure
128 * @param ipaddr IP address for the new netif
129 * @param netmask network mask for the new netif
130 * @param gw default gateway IP address for the new netif
131 * @param state opaque data passed to the new netif
136 * @return netif, or NULL if failed.
138 struct netif *
139 netif_add(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask,
146 ip_addr_set_zero(&netif->ip_addr);
147 ip_addr_set_zero(&netif->netmask);
148 ip_addr_set_zero(&netif->gw);
149 netif->flags = 0;
151 /* netif not under DHCP control by default */
152 netif->dhcp = NULL;
155 /* netif not under AutoIP control by default */
156 netif->autoip = NULL;
159 netif->status_callback = NULL;
162 netif->link_callback = NULL;
165 netif->igmp_mac_filter = NULL;
168 netif->loop_first = NULL;
169 netif->loop_last = NULL;
172 /* remember netif specific state information data */
173 netif->state = state;
174 netif->num = netif_num++;
175 netif->input = input;
176 NETIF_SET_HWADDRHINT(netif, NULL);
178 netif->loop_cnt_current = 0;
181 netif_set_addr(netif, ipaddr, netmask, gw);
183 /* call user specified initialization function for netif */
184 if (init(netif) != ERR_OK) {
188 /* add this netif to the list */
189 netif->next = netif_list;
190 netif_list = netif;
195 if (netif->flags & NETIF_FLAG_IGMP) {
196 igmp_start(netif);
200 LWIP_DEBUGF(NETIF_DEBUG, ("netif: added interface %c%c IP addr ",
201 netif->name[0], netif->name[1]));
208 return netif;
215 * @param netif the network interface to change
221 netif_set_addr(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask,
224 netif_set_ipaddr(netif, ipaddr);
225 netif_set_netmask(netif, netmask);
226 netif_set_gw(netif, gw);
232 * @param netif the network interface to remove
235 netif_remove(struct netif *netif)
237 if (netif == NULL) {
243 if (netif->flags & NETIF_FLAG_IGMP) {
244 igmp_stop(netif);
247 if (netif_is_up(netif)) {
248 /* set netif down before removing (call callback function) */
249 netif_set_down(netif);
252 snmp_delete_ipaddridx_tree(netif);
254 /* is it the first netif? */
255 if (netif_list == netif) {
256 netif_list = netif->next;
258 /* look for netif further down the list */
259 struct netif * tmpNetif;
261 if (tmpNetif->next == netif) {
262 tmpNetif->next = netif->next;
267 return; /* we didn't find any netif today */
270 /* this netif is default? */
271 if (netif_default == netif) {
272 /* reset default netif */
276 if (netif->remove_callback) {
277 netif->remove_callback(netif);
280 LWIP_DEBUGF( NETIF_DEBUG, ("netif_remove: removed netif\n") );
286 * @param name the name of the netif (like netif->name) plus concatenated number
289 struct netif *
292 struct netif *netif;
301 for(netif = netif_list; netif != NULL; netif = netif->next) {
302 if (num == netif->num &&
303 name[0] == netif->name[0] &&
304 name[1] == netif->name[1]) {
306 return netif;
316 * @param netif the network interface to change
323 netif_set_ipaddr(struct netif *netif, ip_addr_t *ipaddr)
332 if (ipaddr && (ip_addr_cmp(ipaddr, &(netif->ip_addr))) == 0) {
334 LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_set_ipaddr: netif address being changed\n"));
338 if (ip_addr_cmp(&(pcb->local_ip), &(netif->ip_addr))
356 (ip_addr_cmp(&(lpcb->local_ip), &(netif->ip_addr)))) {
364 snmp_delete_ipaddridx_tree(netif);
365 snmp_delete_iprteidx_tree(0,netif);
366 /* set new IP address to netif */
367 ip_addr_set(&(netif->ip_addr), ipaddr);
368 snmp_insert_ipaddridx_tree(netif);
369 snmp_insert_iprteidx_tree(0,netif);
371 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",
372 netif->name[0], netif->name[1],
373 ip4_addr1_16(&netif->ip_addr),
374 ip4_addr2_16(&netif->ip_addr),
375 ip4_addr3_16(&netif->ip_addr),
376 ip4_addr4_16(&netif->ip_addr)));
382 * @param netif the network interface to change
388 netif_set_gw(struct netif *netif, ip_addr_t *gw)
390 ip_addr_set(&(netif->gw), gw);
391 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",
392 netif->name[0], netif->name[1],
393 ip4_addr1_16(&netif->gw),
394 ip4_addr2_16(&netif->gw),
395 ip4_addr3_16(&netif->gw),
396 ip4_addr4_16(&netif->gw)));
402 * @param netif the network interface to change
409 netif_set_netmask(struct netif *netif, ip_addr_t *netmask)
411 snmp_delete_iprteidx_tree(0, netif);
412 /* set new netmask to netif */
413 ip_addr_set(&(netif->netmask), netmask);
414 snmp_insert_iprteidx_tree(0, netif);
415 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",
416 netif->name[0], netif->name[1],
417 ip4_addr1_16(&netif->netmask),
418 ip4_addr2_16(&netif->netmask),
419 ip4_addr3_16(&netif->netmask),
420 ip4_addr4_16(&netif->netmask)));
427 * @param netif the default network interface
430 netif_set_default(struct netif *netif)
432 if (netif == NULL) {
434 snmp_delete_iprteidx_tree(1, netif);
437 snmp_insert_iprteidx_tree(1, netif);
439 netif_default = netif;
440 LWIP_DEBUGF(NETIF_DEBUG, ("netif: setting default interface %c%c\n",
441 netif ? netif->name[0] : '\'', netif ? netif->name[1] : '\''));
453 void netif_set_up(struct netif *netif)
455 if (!(netif->flags & NETIF_FLAG_UP)) {
456 netif->flags |= NETIF_FLAG_UP;
459 snmp_get_sysuptime(&netif->ts);
462 NETIF_STATUS_CALLBACK(netif);
464 if (netif->flags & NETIF_FLAG_LINK_UP) {
467 if (netif->flags & (NETIF_FLAG_ETHARP)) {
468 etharp_gratuitous(netif);
474 if (netif->flags & NETIF_FLAG_IGMP) {
475 igmp_report_groups( netif);
490 void netif_set_down(struct netif *netif)
492 if (netif->flags & NETIF_FLAG_UP) {
493 netif->flags &= ~NETIF_FLAG_UP;
495 snmp_get_sysuptime(&netif->ts);
499 if (netif->flags & NETIF_FLAG_ETHARP) {
500 etharp_cleanup_netif(netif);
503 NETIF_STATUS_CALLBACK(netif);
511 void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback)
513 if (netif) {
514 netif->status_callback = status_callback;
524 netif_set_remove_callback(struct netif *netif, netif_status_callback_fn remove_callback)
526 if (netif) {
527 netif->remove_callback = remove_callback;
535 void netif_set_link_up(struct netif *netif )
537 if (!(netif->flags & NETIF_FLAG_LINK_UP)) {
538 netif->flags |= NETIF_FLAG_LINK_UP;
541 if (netif->dhcp) {
542 dhcp_network_changed(netif);
547 if (netif->autoip) {
548 autoip_network_changed(netif);
552 if (netif->flags & NETIF_FLAG_UP) {
555 if (netif->flags & NETIF_FLAG_ETHARP) {
556 etharp_gratuitous(netif);
562 if (netif->flags & NETIF_FLAG_IGMP) {
563 igmp_report_groups( netif);
567 NETIF_LINK_CALLBACK(netif);
574 void netif_set_link_down(struct netif *netif )
576 if (netif->flags & NETIF_FLAG_LINK_UP) {
577 netif->flags &= ~NETIF_FLAG_LINK_UP;
578 NETIF_LINK_CALLBACK(netif);
586 void netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_callback)
588 if (netif) {
589 netif->link_callback = link_callback;
596 * Send an IP packet to be received on the same netif (loopif-like).
597 * The pbuf is simply copied and handed back to netif->input.
598 * In multithreaded mode, this is done directly since netif->input must put
601 * netif->input by netif_poll().
603 * @param netif the lwip network interface structure
610 netif_loop_output(struct netif *netif, struct pbuf *p,
620 * if not they are adjusted for 'netif'. */
623 struct netif *stats_if = &loop_netif;
625 struct netif *stats_if = netif;
642 if(((netif->loop_cnt_current + clen) < netif->loop_cnt_current) ||
643 ((netif->loop_cnt_current + clen) > LWIP_LOOPBACK_MAX_PBUFS)) {
650 netif->loop_cnt_current += clen;
669 if(netif->loop_first != NULL) {
670 LWIP_ASSERT("if first != NULL, last must also be != NULL", netif->loop_last != NULL);
671 netif->loop_last->next = r;
672 netif->loop_last = last;
674 netif->loop_first = r;
675 netif->loop_last = last;
685 tcpip_callback((tcpip_callback_fn)netif_poll, netif);
694 * netif_loop_output() are put on a list that is passed to netif->input() by
698 netif_poll(struct netif *netif)
702 * if not they are adjusted for 'netif'. */
705 struct netif *stats_if = &loop_netif;
707 struct netif *stats_if = netif;
715 in = netif->loop_first;
721 LWIP_ASSERT("netif->loop_cnt_current underflow",
722 ((netif->loop_cnt_current - clen) < netif->loop_cnt_current));
723 netif->loop_cnt_current -= clen;
730 if (in_end == netif->loop_last) {
732 netif->loop_first = netif->loop_last = NULL;
735 netif->loop_first = in_end->next;
736 LWIP_ASSERT("should not be null since first != last!", netif->loop_first != NULL);
748 if (ip_input(in, netif) != ERR_OK) {
755 } while (netif->loop_first != NULL);
760 * Calls netif_poll() for every netif on the netif_list.
765 struct netif *netif = netif_list;
767 while (netif != NULL) {
768 netif_poll(netif);
770 netif = netif->next;