• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /barrelfish-2018-10-04/lib/lwip2/src/core/

Lines Matching refs:netif

5  * @defgroup netif Network interface (NETIF)
9 * @ingroup netif
12 * @ingroup netif
15 * Store data (void*) on a netif for application usage.
17 * @ingroup netif
59 #include "lwip/netif.h"
75 #include "netif/ethernet.h"
105 struct netif *netif_list;
106 struct netif *netif_default;
116 static void netif_issue_reports(struct netif* netif, u8_t report_type);
119 static err_t netif_null_output_ip6(struct netif *netif, struct pbuf *p, const ip6_addr_t *ipaddr);
124 static err_t netif_loop_output_ipv4(struct netif *netif, struct pbuf *p, const ip4_addr_t* addr);
127 static err_t netif_loop_output_ipv6(struct netif *netif, struct pbuf *p, const ip6_addr_t* addr);
131 static struct netif loop_netif;
136 * @param netif the lwip network interface structure for this loopif
141 netif_loopif_init(struct netif *netif)
143 /* initialize the snmp variables and counters inside the struct netif
146 MIB2_INIT_NETIF(netif, snmp_ifType_softwareLoopback, 0);
148 netif->name[0] = 'l';
149 netif->name[1] = 'o';
151 netif->output = netif_loop_output_ipv4;
154 netif->output_ip6 = netif_loop_output_ipv6;
157 netif->flags |= NETIF_FLAG_IGMP;
197 * ethernet_input() or ip_input() depending on netif flags.
199 * netif->input().
200 * Only works if the netif driver correctly sets
204 netif_input(struct pbuf *p, struct netif *inp)
215 * @ingroup netif
218 * @param netif a pre-allocated netif structure
219 * @param ipaddr IP address for the new netif
220 * @param netmask network mask for the new netif
221 * @param gw default gateway IP address for the new netif
222 * @param state opaque data passed to the new netif
229 * These functions use netif flags NETIF_FLAG_ETHARP and NETIF_FLAG_ETHERNET
231 * In other words, the functions only work when the netif
233 * Most members of struct netif should be be initialized by the
234 * netif init function = netif driver (init parameter of this function).\n
236 * setting the MAC address in struct netif.hwaddr
239 * @return netif, or NULL if failed.
241 struct netif *
242 netif_add(struct netif *netif,
256 ip_addr_set_zero_ip4(&netif->ip_addr);
257 ip_addr_set_zero_ip4(&netif->netmask);
258 ip_addr_set_zero_ip4(&netif->gw);
262 ip_addr_set_zero_ip6(&netif->ip6_addr[i]);
263 netif->ip6_addr_state[i] = IP6_ADDR_INVALID;
265 netif->output_ip6 = netif_null_output_ip6;
267 NETIF_SET_CHECKSUM_CTRL(netif, NETIF_CHECKSUM_ENABLE_ALL);
268 netif->flags = 0;
270 memset(netif->client_data, 0, sizeof(netif->client_data));
274 netif->ip6_autoconfig_enabled = 0;
277 netif->rs_count = LWIP_ND6_MAX_MULTICAST_SOLICIT;
280 netif->status_callback = NULL;
283 netif->link_callback = NULL;
286 netif->igmp_mac_filter = NULL;
289 netif->mld_mac_filter = NULL;
292 netif->loop_first = NULL;
293 netif->loop_last = NULL;
296 /* remember netif specific state information data */
297 netif->state = state;
298 netif->num = netif_num++;
299 netif->input = input;
301 NETIF_SET_HWADDRHINT(netif, NULL);
303 netif->loop_cnt_current = 0;
307 netif_set_addr(netif, ipaddr, netmask, gw);
310 /* call user specified initialization function for netif */
311 if (init(netif) != ERR_OK) {
315 /* add this netif to the list */
316 netif->next = netif_list;
317 netif_list = netif;
318 mib2_netif_added(netif);
322 if (netif->flags & NETIF_FLAG_IGMP) {
323 igmp_start(netif);
327 LWIP_DEBUGF(NETIF_DEBUG, ("netif: added interface %c%c IP",
328 netif->name[0], netif->name[1]));
338 return netif;
347 * @param netif the network interface to change
353 netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask,
359 netif_set_ipaddr(netif, ipaddr);
360 netif_set_netmask(netif, netmask);
361 netif_set_gw(netif, gw);
363 netif_set_netmask(netif, netmask);
364 netif_set_gw(netif, gw);
366 netif_set_ipaddr(netif, ipaddr);
372 * @ingroup netif
375 * @param netif the network interface to remove
378 netif_remove(struct netif *netif)
384 if (netif == NULL) {
389 if (!ip4_addr_isany_val(*netif_ip4_addr(netif))) {
391 tcp_netif_ip_addr_changed(netif_ip_addr4(netif), NULL);
394 udp_netif_ip_addr_changed(netif_ip_addr4(netif), NULL);
397 raw_netif_ip_addr_changed(netif_ip_addr4(netif), NULL);
403 if (netif->flags & NETIF_FLAG_IGMP) {
404 igmp_stop(netif);
411 if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i))) {
413 tcp_netif_ip_addr_changed(netif_ip_addr6(netif, i), NULL);
416 udp_netif_ip_addr_changed(netif_ip_addr6(netif, i), NULL);
419 raw_netif_ip_addr_changed(netif_ip_addr6(netif, i), NULL);
425 mld6_stop(netif);
428 if (netif_is_up(netif)) {
429 /* set netif down before removing (call callback function) */
430 netif_set_down(netif);
433 mib2_remove_ip4(netif);
435 /* this netif is default? */
436 if (netif_default == netif) {
437 /* reset default netif */
440 /* is it the first netif? */
441 if (netif_list == netif) {
442 netif_list = netif->next;
444 /* look for netif further down the list */
445 struct netif * tmp_netif;
447 if (tmp_netif->next == netif) {
448 tmp_netif->next = netif->next;
453 return; /* netif is not on the list */
456 mib2_netif_removed(netif);
458 if (netif->remove_callback) {
459 netif->remove_callback(netif);
462 LWIP_DEBUGF( NETIF_DEBUG, ("netif_remove: removed netif\n") );
466 * @ingroup netif
469 * @param name the name of the netif (like netif->name) plus concatenated number
472 struct netif *
475 struct netif *netif;
484 for (netif = netif_list; netif != NULL; netif = netif->next) {
485 if (num == netif->num &&
486 name[0] == netif->name[0] &&
487 name[1] == netif->name[1]) {
489 return netif;
501 * @param netif the network interface to change
508 netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr)
515 if (ip4_addr_cmp(ip_2_ip4(&new_addr), netif_ip4_addr(netif)) == 0) {
516 LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_set_ipaddr: netif address being changed\n"));
518 tcp_netif_ip_addr_changed(netif_ip_addr4(netif), &new_addr);
521 udp_netif_ip_addr_changed(netif_ip_addr4(netif), &new_addr);
524 raw_netif_ip_addr_changed(netif_ip_addr4(netif), &new_addr);
527 mib2_remove_ip4(netif);
528 mib2_remove_route_ip4(0, netif);
529 /* set new IP address to netif */
530 ip4_addr_set(ip_2_ip4(&netif->ip_addr), ipaddr);
531 IP_SET_TYPE_VAL(netif->ip_addr, IPADDR_TYPE_V4);
532 mib2_add_ip4(netif);
533 mib2_add_route_ip4(0, netif);
535 netif_issue_reports(netif, NETIF_REPORT_TYPE_IPV4);
537 NETIF_STATUS_CALLBACK(netif);
540 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",
541 netif->name[0], netif->name[1],
542 ip4_addr1_16(netif_ip4_addr(netif)),
543 ip4_addr2_16(netif_ip4_addr(netif)),
544 ip4_addr3_16(netif_ip4_addr(netif)),
545 ip4_addr4_16(netif_ip4_addr(netif))));
552 * @param netif the network interface to change
558 netif_set_gw(struct netif *netif, const ip4_addr_t *gw)
560 ip4_addr_set(ip_2_ip4(&netif->gw), gw);
561 IP_SET_TYPE_VAL(netif->gw, IPADDR_TYPE_V4);
562 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",
563 netif->name[0], netif->name[1],
564 ip4_addr1_16(netif_ip4_gw(netif)),
565 ip4_addr2_16(netif_ip4_gw(netif)),
566 ip4_addr3_16(netif_ip4_gw(netif)),
567 ip4_addr4_16(netif_ip4_gw(netif))));
574 * @param netif the network interface to change
581 netif_set_netmask(struct netif *netif, const ip4_addr_t *netmask)
583 mib2_remove_route_ip4(0, netif);
584 /* set new netmask to netif */
585 ip4_addr_set(ip_2_ip4(&netif->netmask), netmask);
586 IP_SET_TYPE_VAL(netif->netmask, IPADDR_TYPE_V4);
587 mib2_add_route_ip4(0, netif);
588 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",
589 netif->name[0], netif->name[1],
590 ip4_addr1_16(netif_ip4_netmask(netif)),
591 ip4_addr2_16(netif_ip4_netmask(netif)),
592 ip4_addr3_16(netif_ip4_netmask(netif)),
593 ip4_addr4_16(netif_ip4_netmask(netif))));
598 * @ingroup netif
602 * @param netif the default network interface
605 netif_set_default(struct netif *netif)
607 if (netif == NULL) {
609 mib2_remove_route_ip4(1, netif);
612 mib2_add_route_ip4(1, netif);
614 netif_default = netif;
615 LWIP_DEBUGF(NETIF_DEBUG, ("netif: setting default interface %c%c\n",
616 netif ? netif->name[0] : '\'', netif ? netif->name[1] : '\''));
620 * @ingroup netif
625 netif_set_up(struct netif *netif)
627 if (!(netif->flags & NETIF_FLAG_UP)) {
628 netif->flags |= NETIF_FLAG_UP;
630 MIB2_COPY_SYSUPTIME_TO(&netif->ts);
632 NETIF_STATUS_CALLBACK(netif);
634 if (netif->flags & NETIF_FLAG_LINK_UP) {
635 netif_issue_reports(netif, NETIF_REPORT_TYPE_IPV4|NETIF_REPORT_TYPE_IPV6);
640 /** Send ARP/IGMP/MLD/RS events, e.g. on link-up/netif-up or addr-change
643 netif_issue_reports(struct netif* netif, u8_t report_type)
647 !ip4_addr_isany_val(*netif_ip4_addr(netif))) {
650 if (netif->flags & (NETIF_FLAG_ETHARP)) {
651 etharp_gratuitous(netif);
657 if (netif->flags & NETIF_FLAG_IGMP) {
658 igmp_report_groups(netif);
668 mld6_report_groups(netif);
672 netif->rs_count = LWIP_ND6_MAX_MULTICAST_SOLICIT;
679 * @ingroup netif
683 netif_set_down(struct netif *netif)
685 if (netif->flags & NETIF_FLAG_UP) {
686 netif->flags &= ~NETIF_FLAG_UP;
687 MIB2_COPY_SYSUPTIME_TO(&netif->ts);
690 if (netif->flags & NETIF_FLAG_ETHARP) {
691 etharp_cleanup_netif(netif);
696 nd6_cleanup_netif(netif);
699 NETIF_STATUS_CALLBACK(netif);
705 * @ingroup netif
709 netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback)
711 if (netif) {
712 netif->status_callback = status_callback;
719 * @ingroup netif
723 netif_set_remove_callback(struct netif *netif, netif_status_callback_fn remove_callback)
725 if (netif) {
726 netif->remove_callback = remove_callback;
732 * @ingroup netif
736 netif_set_link_up(struct netif *netif)
738 if (!(netif->flags & NETIF_FLAG_LINK_UP)) {
739 netif->flags |= NETIF_FLAG_LINK_UP;
742 dhcp_network_changed(netif);
746 autoip_network_changed(netif);
749 if (netif->flags & NETIF_FLAG_UP) {
750 netif_issue_reports(netif, NETIF_REPORT_TYPE_IPV4|NETIF_REPORT_TYPE_IPV6);
752 NETIF_LINK_CALLBACK(netif);
757 * @ingroup netif
761 netif_set_link_down(struct netif *netif )
763 if (netif->flags & NETIF_FLAG_LINK_UP) {
764 netif->flags &= ~NETIF_FLAG_LINK_UP;
765 NETIF_LINK_CALLBACK(netif);
771 * @ingroup netif
775 netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_callback)
777 if (netif) {
778 netif->link_callback = link_callback;
785 * @ingroup netif
786 * Send an IP packet to be received on the same netif (loopif-like).
787 * The pbuf is simply copied and handed back to netif->input.
788 * In multithreaded mode, this is done directly since netif->input must put
791 * netif->input by netif_poll().
793 * @param netif the lwip network interface structure
799 netif_loop_output(struct netif *netif, struct pbuf *p)
808 * if not they are adjusted for 'netif'. */
811 struct netif *stats_if = &loop_netif;
813 struct netif *stats_if = netif;
829 if (((netif->loop_cnt_current + clen) < netif->loop_cnt_current) ||
830 ((netif->loop_cnt_current + clen) > LWIP_LOOPBACK_MAX_PBUFS)) {
837 netif->loop_cnt_current += clen;
856 if (netif->loop_first != NULL) {
857 LWIP_ASSERT("if first != NULL, last must also be != NULL", netif->loop_last != NULL);
858 netif->loop_last->next = r;
859 netif->loop_last = last;
861 netif->loop_first = r;
862 netif->loop_last = last;
872 tcpip_callback_with_block((tcpip_callback_fn)netif_poll, netif, 0);
882 netif_loop_output_ipv4(struct netif *netif, struct pbuf *p, const ip4_addr_t* addr)
885 return netif_loop_output(netif, p);
891 netif_loop_output_ipv6(struct netif *netif, struct pbuf *p, const ip6_addr_t* addr)
894 return netif_loop_output(netif, p);
903 * netif_loop_output() are put on a list that is passed to netif->input() by
907 netif_poll(struct netif *netif)
910 * if not they are adjusted for 'netif'. */
913 struct netif *stats_if = &loop_netif;
915 struct netif *stats_if = netif;
922 while (netif->loop_first != NULL) {
928 in = in_end = netif->loop_first;
938 LWIP_ASSERT("netif->loop_cnt_current underflow",
939 ((netif->loop_cnt_current - clen) < netif->loop_cnt_current));
940 netif->loop_cnt_current -= clen;
944 if (in_end == netif->loop_last) {
946 netif->loop_first = netif->loop_last = NULL;
949 netif->loop_first = in_end->next;
950 LWIP_ASSERT("should not be null since first != last!", netif->loop_first != NULL);
960 if (ip_input(in, netif) != ERR_OK) {
970 * Calls netif_poll() for every netif on the netif_list.
975 struct netif *netif = netif_list;
977 while (netif != NULL) {
978 netif_poll(netif);
980 netif = netif->next;
989 * Allocate an index to store data in client_data member of struct netif.
1009 * @param netif the network interface to change
1016 netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, const ip6_addr_t *addr6)
1019 netif_ip6_addr_set_parts(netif, addr_idx, addr6->addr[0], addr6->addr[1],
1026 * @param netif the network interface to change
1034 netif_ip6_addr_set_parts(struct netif *netif, s8_t addr_idx, u32_t i0, u32_t i1, u32_t i2, u32_t i3)
1037 LWIP_ASSERT("netif != NULL", netif != NULL);
1040 old_addr = netif_ip6_addr(netif, addr_idx);
1044 LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_ip6_addr_set: netif address being changed\n"));
1046 if (netif_ip6_addr_state(netif, addr_idx) & IP6_ADDR_VALID) {
1052 tcp_netif_ip_addr_changed(netif_ip_addr6(netif, addr_idx), &new_ipaddr);
1055 udp_netif_ip_addr_changed(netif_ip_addr6(netif, addr_idx), &new_ipaddr);
1058 raw_netif_ip_addr_changed(netif_ip_addr6(netif, addr_idx), &new_ipaddr);
1063 IP6_ADDR(ip_2_ip6(&(netif->ip6_addr[addr_idx])), i0, i1, i2, i3);
1064 IP_SET_TYPE_VAL(netif->ip6_addr[addr_idx], IPADDR_TYPE_V6);
1066 if (netif_ip6_addr_state(netif, addr_idx) & IP6_ADDR_VALID) {
1067 netif_issue_reports(netif, NETIF_REPORT_TYPE_IPV6);
1068 NETIF_STATUS_CALLBACK(netif);
1072 LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: IPv6 address %d of interface %c%c set to %s/0x%"X8_F"\n",
1073 addr_idx, netif->name[0], netif->name[1], ip6addr_ntoa(netif_ip6_addr(netif, addr_idx)),
1074 netif_ip6_addr_state(netif, addr_idx)));
1083 * @param netif the network interface to change
1088 netif_ip6_addr_set_state(struct netif* netif, s8_t addr_idx, u8_t state)
1091 LWIP_ASSERT("netif != NULL", netif != NULL);
1094 old_state = netif_ip6_addr_state(netif, addr_idx);
1099 LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_ip6_addr_set_state: netif address state being changed\n"));
1103 if (netif->flags & NETIF_FLAG_MLD6) {
1104 nd6_adjust_mld_membership(netif, addr_idx, state);
1111 tcp_netif_ip_addr_changed(netif_ip_addr6(netif, addr_idx), NULL);
1114 udp_netif_ip_addr_changed(netif_ip_addr6(netif, addr_idx), NULL);
1117 raw_netif_ip_addr_changed(netif_ip_addr6(netif, addr_idx), NULL);
1121 netif->ip6_addr_state[addr_idx] = state;
1126 netif_issue_reports(netif, NETIF_REPORT_TYPE_IPV6);
1131 NETIF_STATUS_CALLBACK(netif);
1135 LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: IPv6 address %d of interface %c%c set to %s/0x%"X8_F"\n",
1136 addr_idx, netif->name[0], netif->name[1], ip6addr_ntoa(netif_ip6_addr(netif, addr_idx)),
1137 netif_ip6_addr_state(netif, addr_idx)));
1141 * Checks if a specific address is assigned to the netif and returns its
1144 * @param netif the netif to check
1147 * -1: address not found on this netif
1150 netif_get_ip6_addr_match(struct netif *netif, const ip6_addr_t *ip6addr)
1154 if (!ip6_addr_isinvalid(netif_ip6_addr_state(netif, i)) &&
1155 ip6_addr_cmp(netif_ip6_addr(netif, i), ip6addr)) {
1164 * Create a link-local IPv6 address on a netif (stored in slot 0)
1166 * @param netif the netif to create the address on
1171 netif_create_ip6_linklocal_address(struct netif *netif, u8_t from_mac_48bit)
1176 ip_2_ip6(&netif->ip6_addr[0])->addr[0] = PP_HTONL(0xfe800000ul);
1177 ip_2_ip6(&netif->ip6_addr[0])->addr[1] = 0;
1182 ip_2_ip6(&netif->ip6_addr[0])->addr[2] = lwip_htonl((((u32_t)(netif->hwaddr[0] ^ 0x02)) << 24) |
1183 ((u32_t)(netif->hwaddr[1]) << 16) |
1184 ((u32_t)(netif->hwaddr[2]) << 8) |
1186 ip_2_ip6(&netif->ip6_addr[0])->addr[3] = lwip_htonl((0xfeul << 24) |
1187 ((u32_t)(netif->hwaddr[3]) << 16) |
1188 ((u32_t)(netif->hwaddr[4]) << 8) |
1189 (netif->hwaddr[5]));
1192 ip_2_ip6(&netif->ip6_addr[0])->addr[2] = 0;
1193 ip_2_ip6(&netif->ip6_addr[0])->addr[3] = 0;
1196 for (i = 0; (i < 8) && (i < netif->hwaddr_len); i++) {
1200 ip_2_ip6(&netif->ip6_addr[0])->addr[addr_index] |= ((u32_t)(netif->hwaddr[netif->hwaddr_len - i - 1])) << (8 * (i & 0x03));
1207 netif_ip6_addr_set_state(netif, 0, IP6_ADDR_TENTATIVE);
1210 netif_ip6_addr_set_state(netif, 0, IP6_ADDR_PREFERRED);
1220 * @param netif netif to add the address on
1225 netif_add_ip6_address(struct netif *netif, const ip6_addr_t *ip6addr, s8_t *chosen_idx)
1229 i = netif_get_ip6_addr_match(netif, ip6addr);
1240 if (ip6_addr_isinvalid(netif_ip6_addr_state(netif, i))) {
1241 ip_addr_copy_from_ip6(netif->ip6_addr[i], *ip6addr);
1242 netif_ip6_addr_set_state(netif, i, IP6_ADDR_TENTATIVE);
1259 netif_null_output_ip6(struct netif *netif, struct pbuf *p, const ip6_addr_t *ipaddr)
1261 LWIP_UNUSED_ARG(netif);