void sta_ip6addr_del(struct hostapd_data *hapd, struct sta_info *sta) { struct ip6addr *ip6addr, *prev; dl_list_for_each_safe(ip6addr, prev, &sta->ip6addr, struct ip6addr, list) { hostapd_drv_br_delete_ip_neigh(hapd, 6, (u8 *) &ip6addr->addr); os_free(ip6addr); } }
static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta) { ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); if (sta->ipaddr) hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr); ap_sta_ip6addr_del(hapd, sta); wpa_printf(MSG_DEBUG, "Removing STA " MACSTR " from kernel driver", MAC2STR(sta->addr)); if (hostapd_drv_sta_remove(hapd, sta->addr) && sta->flags & WLAN_STA_ASSOC) { wpa_printf(MSG_DEBUG, "Could not remove station " MACSTR " from kernel driver.", MAC2STR(sta->addr)); return -1; } return 0; }
static void handle_ndisc(void *ctx, const u8 *src_addr, const u8 *buf, size_t len) { struct hostapd_data *hapd = ctx; struct icmpv6_ndmsg *msg; struct in6_addr saddr; struct sta_info *sta; int res; char addrtxt[INET6_ADDRSTRLEN + 1]; if (len < ETH_HLEN + sizeof(struct ip6_hdr) + sizeof(struct icmp6_hdr)) return; msg = (struct icmpv6_ndmsg *) &buf[ETH_HLEN]; switch (msg->icmp6h.icmp6_type) { case NEIGHBOR_SOLICITATION: if (len < ETH_HLEN + sizeof(*msg)) return; if (msg->opt_type != SOURCE_LL_ADDR) return; /* * IPv6 header may not be 32-bit aligned in the buffer, so use * a local copy to avoid unaligned reads. */ os_memcpy(&saddr, &msg->ipv6h.ip6_src, sizeof(saddr)); if (!(saddr.s6_addr32[0] == 0 && saddr.s6_addr32[1] == 0 && saddr.s6_addr32[2] == 0 && saddr.s6_addr32[3] == 0)) { if (len < ETH_HLEN + sizeof(*msg) + ETH_ALEN) return; sta = ap_get_sta(hapd, msg->opt_lladdr); if (!sta) return; if (sta_has_ip6addr(sta, &saddr)) return; if (inet_ntop(AF_INET6, &saddr, addrtxt, sizeof(addrtxt)) == NULL) addrtxt[0] = '\0'; wpa_printf(MSG_DEBUG, "ndisc_snoop: Learned new IPv6 address %s for " MACSTR, addrtxt, MAC2STR(sta->addr)); hostapd_drv_br_delete_ip_neigh(hapd, 6, (u8 *) &saddr); res = hostapd_drv_br_add_ip_neigh(hapd, 6, (u8 *) &saddr, 128, sta->addr); if (res) { wpa_printf(MSG_ERROR, "ndisc_snoop: Adding ip neigh failed: %d", res); return; } if (sta_ip6addr_add(sta, &saddr)) return; } break; case ROUTER_ADVERTISEMENT: if (hapd->conf->disable_dgaf) ucast_to_stas(hapd, buf, len); break; case NEIGHBOR_ADVERTISEMENT: if (hapd->conf->na_mcast_to_ucast) ucast_to_stas(hapd, buf, len); break; default: break; } }
static void handle_dhcp(void *ctx, const u8 *src_addr, const u8 *buf, size_t len) { struct hostapd_data *hapd = ctx; const struct bootp_pkt *b; struct sta_info *sta; int exten_len; const u8 *end, *pos; int res, msgtype = 0, prefixlen = 32; u32 subnet_mask = 0; u16 tot_len; int dns_flag = 0; u32 dns1 = 0; u32 dns2 = 0; u8 *tmp; /* printPacketBuffer(buf, len); */ exten_len = len - ETH_HLEN - (sizeof(*b) - sizeof(b->exten)); if (exten_len < 4) return; b = (const struct bootp_pkt *) &buf[ETH_HLEN]; tot_len = ntohs(b->iph.tot_len); if (tot_len > (unsigned int) (len - ETH_HLEN)) return; if (os_memcmp(b->exten, ic_bootp_cookie, ARRAY_SIZE(ic_bootp_cookie))) return; printf("dhcp_snoop: Found DHCP IPv4 address %s/%d", ipaddr_str(ntohl(b->your_ip)), prefixlen); /* Parse DHCP options */ end = (const u8 *) b + tot_len; pos = &b->exten[4]; while (pos < end && *pos != 0xff) { const u8 *opt = pos++; if (*opt == 0) /* padding */ continue; pos += *pos + 1; if (pos >= end) break; switch (*opt) { case 1: /* subnet mask */ if (opt[1] == 4) subnet_mask = WPA_GET_BE32(&opt[2]); if (subnet_mask == 0) return; while (!(subnet_mask & 0x1)) { subnet_mask >>= 1; prefixlen--; } break; case 6: /* dns */ dns_flag = 1; if (opt[1] == 4) { dns1 = WPA_GET_BE32(&opt[2]); tmp = (u8 *)&dns1; wpa_printf(MSG_DEBUG, "%d.%d.%d.%d\n", tmp[0], tmp[1], tmp[2], tmp[3]); } if (opt[1] == 8) { dns1 = WPA_GET_BE32(&opt[2]); dns2 = WPA_GET_BE32(&opt[6]); tmp = (u8 *)&dns1; wpa_printf(MSG_DEBUG, "dns1 %d.%d.%d.%d\n", tmp[0], tmp[1], tmp[2], tmp[3]); tmp = (u8 *)&dns2; wpa_printf(MSG_DEBUG, "dns2 %d.%d.%d.%d\n", tmp[0], tmp[1], tmp[2], tmp[3]); } case 53: /* message type */ if (opt[1]) msgtype = opt[2]; break; default: break; } } if (msgtype == DHCPACK) { if (b->your_ip == 0) return; /* DHCPACK for DHCPREQUEST */ sta = ap_get_sta(hapd, b->hw_addr); if (!sta) return; wpa_printf(MSG_DEBUG, "dhcp_snoop: Found DHCPACK for " MACSTR " @ IPv4 address %s/%d", MAC2STR(sta->addr), ipaddr_str(ntohl(b->your_ip)), prefixlen); if (sta->ipaddr == b->your_ip) return; sta->ipaddr = b->your_ip; if (dns_flag) { sta->dns[0] = dns1; sta->dns[1] = dns2; } #if 0 /* temporarily close */ if (sta->ipaddr != 0) { wpa_printf(MSG_DEBUG, "dhcp_snoop: Removing IPv4 address %s from the ip neigh table", ipaddr_str(be_to_host32(sta->ipaddr))); hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr); } res = hostapd_drv_br_add_ip_neigh(hapd, 4, (u8 *) &b->your_ip, prefixlen, sta->addr); if (res) { wpa_printf(MSG_DEBUG, "dhcp_snoop: Adding ip neigh table failed: %d", res); return; } sta->ipaddr = b->your_ip; #endif send_msg_to_eag(hapd, sta, STA_ADD); } if (hapd->conf->disable_dgaf && is_broadcast_ether_addr(buf)) { for (sta = hapd->sta_list; sta; sta = sta->next) { if (!(sta->flags & WLAN_STA_AUTHORIZED)) continue; x_snoop_mcast_to_ucast_convert_send(hapd, sta, (u8 *) buf, len); } } }
void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta) { int set_beacon = 0; accounting_sta_stop(hapd, sta); /* just in case */ ap_sta_set_authorized(hapd, sta, 0); if (sta->flags & WLAN_STA_WDS) hostapd_set_wds_sta(hapd, NULL, sta->addr, sta->aid, 0); if (sta->ipaddr) hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr); ap_sta_ip6addr_del(hapd, sta); if (!hapd->iface->driver_ap_teardown && !(sta->flags & WLAN_STA_PREAUTH)) hostapd_drv_sta_remove(hapd, sta->addr); #ifndef CONFIG_NO_VLAN if (sta->vlan_id_bound) { /* * Need to remove the STA entry before potentially removing the * VLAN. */ if (hapd->iface->driver_ap_teardown && !(sta->flags & WLAN_STA_PREAUTH)) hostapd_drv_sta_remove(hapd, sta->addr); vlan_remove_dynamic(hapd, sta->vlan_id_bound); } #endif /* CONFIG_NO_VLAN */ ap_sta_hash_del(hapd, sta); ap_sta_list_del(hapd, sta); if (sta->aid > 0) hapd->sta_aid[(sta->aid - 1) / 32] &= ~BIT((sta->aid - 1) % 32); hapd->num_sta--; if (sta->nonerp_set) { sta->nonerp_set = 0; hapd->iface->num_sta_non_erp--; if (hapd->iface->num_sta_non_erp == 0) set_beacon++; } if (sta->no_short_slot_time_set) { sta->no_short_slot_time_set = 0; hapd->iface->num_sta_no_short_slot_time--; if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G && hapd->iface->num_sta_no_short_slot_time == 0) set_beacon++; } if (sta->no_short_preamble_set) { sta->no_short_preamble_set = 0; hapd->iface->num_sta_no_short_preamble--; if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G && hapd->iface->num_sta_no_short_preamble == 0) set_beacon++; } if (sta->no_ht_gf_set) { sta->no_ht_gf_set = 0; hapd->iface->num_sta_ht_no_gf--; } if (sta->no_ht_set) { sta->no_ht_set = 0; hapd->iface->num_sta_no_ht--; } if (sta->ht_20mhz_set) { sta->ht_20mhz_set = 0; hapd->iface->num_sta_ht_20mhz--; } #ifdef CONFIG_IEEE80211N ht40_intolerant_remove(hapd->iface, sta); #endif /* CONFIG_IEEE80211N */ #ifdef CONFIG_P2P if (sta->no_p2p_set) { sta->no_p2p_set = 0; hapd->num_sta_no_p2p--; if (hapd->num_sta_no_p2p == 0) hostapd_p2p_non_p2p_sta_disconnected(hapd); } #endif /* CONFIG_P2P */ #if defined(NEED_AP_MLME) && defined(CONFIG_IEEE80211N) if (hostapd_ht_operation_update(hapd->iface) > 0) set_beacon++; #endif /* NEED_AP_MLME && CONFIG_IEEE80211N */ #ifdef CONFIG_MESH if (hapd->mesh_sta_free_cb) hapd->mesh_sta_free_cb(sta); #endif /* CONFIG_MESH */ if (set_beacon) ieee802_11_set_beacons(hapd->iface); wpa_printf(MSG_DEBUG, "%s: cancel ap_handle_timer for " MACSTR, __func__, MAC2STR(sta->addr)); eloop_cancel_timeout(ap_handle_timer, hapd, sta); eloop_cancel_timeout(ap_handle_session_timer, hapd, sta); eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta); eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta); eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta); sae_clear_retransmit_timer(hapd, sta); ieee802_1x_free_station(sta); wpa_auth_sta_deinit(sta->wpa_sm); rsn_preauth_free_station(hapd, sta); #ifndef CONFIG_NO_RADIUS if (hapd->radius) radius_client_flush_auth(hapd->radius, sta->addr); #endif /* CONFIG_NO_RADIUS */ os_free(sta->challenge); #ifdef CONFIG_IEEE80211W os_free(sta->sa_query_trans_id); eloop_cancel_timeout(ap_sa_query_timer, hapd, sta); #endif /* CONFIG_IEEE80211W */ #ifdef CONFIG_P2P p2p_group_notif_disassoc(hapd->p2p_group, sta->addr); #endif /* CONFIG_P2P */ #ifdef CONFIG_INTERWORKING if (sta->gas_dialog) { int i; for (i = 0; i < GAS_DIALOG_MAX; i++) gas_serv_dialog_clear(&sta->gas_dialog[i]); os_free(sta->gas_dialog); } #endif /* CONFIG_INTERWORKING */ wpabuf_free(sta->wps_ie); wpabuf_free(sta->p2p_ie); wpabuf_free(sta->hs20_ie); os_free(sta->ht_capabilities); os_free(sta->vht_capabilities); hostapd_free_psk_list(sta->psk); os_free(sta->identity); os_free(sta->radius_cui); os_free(sta->remediation_url); wpabuf_free(sta->hs20_deauth_req); os_free(sta->hs20_session_info_url); #ifdef CONFIG_SAE sae_clear_data(sta->sae); os_free(sta->sae); #endif /* CONFIG_SAE */ os_free(sta); }