2014-11-01 02:33:41 -04:00
|
|
|
/*
|
|
|
|
* Neighbor Discovery snooping for Proxy ARP
|
|
|
|
* Copyright (c) 2014, Qualcomm Atheros, Inc.
|
|
|
|
*
|
|
|
|
* This software may be distributed under the terms of the BSD license.
|
|
|
|
* See README for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "utils/includes.h"
|
2014-11-25 09:58:21 -05:00
|
|
|
#include <netinet/ip6.h>
|
|
|
|
#include <netinet/icmp6.h>
|
2014-11-01 02:33:41 -04:00
|
|
|
|
|
|
|
#include "utils/common.h"
|
|
|
|
#include "l2_packet/l2_packet.h"
|
|
|
|
#include "hostapd.h"
|
|
|
|
#include "sta_info.h"
|
|
|
|
#include "ap_drv_ops.h"
|
|
|
|
#include "list.h"
|
|
|
|
#include "x_snoop.h"
|
|
|
|
|
|
|
|
struct ip6addr {
|
|
|
|
struct in6_addr addr;
|
|
|
|
struct dl_list list;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct icmpv6_ndmsg {
|
2014-11-25 09:58:21 -05:00
|
|
|
struct ip6_hdr ipv6h;
|
|
|
|
struct icmp6_hdr icmp6h;
|
2014-11-01 02:33:41 -04:00
|
|
|
struct in6_addr target_addr;
|
|
|
|
u8 opt_type;
|
|
|
|
u8 len;
|
|
|
|
u8 opt_lladdr[0];
|
2014-11-25 18:05:24 -05:00
|
|
|
} STRUCT_PACKED;
|
2014-11-01 02:33:41 -04:00
|
|
|
|
2014-11-03 17:10:24 -05:00
|
|
|
#define ROUTER_ADVERTISEMENT 134
|
2014-11-01 02:33:41 -04:00
|
|
|
#define NEIGHBOR_SOLICITATION 135
|
|
|
|
#define NEIGHBOR_ADVERTISEMENT 136
|
|
|
|
#define SOURCE_LL_ADDR 1
|
|
|
|
|
|
|
|
static int sta_ip6addr_add(struct sta_info *sta, struct in6_addr *addr)
|
|
|
|
{
|
|
|
|
struct ip6addr *ip6addr;
|
|
|
|
|
|
|
|
ip6addr = os_zalloc(sizeof(*ip6addr));
|
|
|
|
if (!ip6addr)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
os_memcpy(&ip6addr->addr, addr, sizeof(*addr));
|
|
|
|
|
|
|
|
dl_list_add_tail(&sta->ip6addr, &ip6addr->list);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 sta_has_ip6addr(struct sta_info *sta, struct in6_addr *addr)
|
|
|
|
{
|
|
|
|
struct ip6addr *ip6addr;
|
|
|
|
|
|
|
|
dl_list_for_each(ip6addr, &sta->ip6addr, struct ip6addr, list) {
|
|
|
|
if (ip6addr->addr.s6_addr32[0] == addr->s6_addr32[0] &&
|
|
|
|
ip6addr->addr.s6_addr32[1] == addr->s6_addr32[1] &&
|
|
|
|
ip6addr->addr.s6_addr32[2] == addr->s6_addr32[2] &&
|
|
|
|
ip6addr->addr.s6_addr32[3] == addr->s6_addr32[3])
|
|
|
|
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;
|
2014-11-25 18:06:56 -05:00
|
|
|
char addrtxt[INET6_ADDRSTRLEN + 1];
|
2014-11-01 02:33:41 -04:00
|
|
|
|
|
|
|
if (len < ETH_HLEN + sizeof(*msg))
|
|
|
|
return;
|
|
|
|
msg = (struct icmpv6_ndmsg *) &buf[ETH_HLEN];
|
|
|
|
switch (msg->icmp6h.icmp6_type) {
|
|
|
|
case NEIGHBOR_SOLICITATION:
|
|
|
|
if (msg->opt_type != SOURCE_LL_ADDR)
|
|
|
|
return;
|
|
|
|
|
2014-11-25 09:58:21 -05:00
|
|
|
saddr = &msg->ipv6h.ip6_src;
|
2014-11-01 02:33:41 -04:00
|
|
|
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;
|
|
|
|
|
2014-11-25 18:06:56 -05:00
|
|
|
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));
|
2014-11-01 02:33:41 -04:00
|
|
|
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;
|
2014-11-03 17:10:24 -05:00
|
|
|
case ROUTER_ADVERTISEMENT:
|
|
|
|
if (!hapd->conf->disable_dgaf)
|
|
|
|
return;
|
|
|
|
/* fall through */
|
2014-11-01 02:33:41 -04:00
|
|
|
case NEIGHBOR_ADVERTISEMENT:
|
|
|
|
for (sta = hapd->sta_list; sta; sta = sta->next) {
|
2014-11-28 11:36:40 -05:00
|
|
|
if (!(sta->flags & WLAN_STA_AUTHORIZED))
|
|
|
|
continue;
|
2014-11-01 02:33:41 -04:00
|
|
|
x_snoop_mcast_to_ucast_convert_send(hapd, sta,
|
|
|
|
(u8 *) buf, len);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ndisc_snoop_init(struct hostapd_data *hapd)
|
|
|
|
{
|
|
|
|
hapd->sock_ndisc = x_snoop_get_l2_packet(hapd, handle_ndisc,
|
|
|
|
L2_PACKET_FILTER_NDISC);
|
|
|
|
if (hapd->sock_ndisc == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"ndisc_snoop: Failed to initialize L2 packet processing for NDISC packets: %s",
|
|
|
|
strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ndisc_snoop_deinit(struct hostapd_data *hapd)
|
|
|
|
{
|
|
|
|
l2_packet_deinit(hapd->sock_ndisc);
|
|
|
|
}
|