|
|
|
@ -10,6 +10,7 @@
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
#include <netpacket/packet.h>
|
|
|
|
|
#include <net/if.h>
|
|
|
|
|
#include <linux/filter.h>
|
|
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
#include "eloop.h"
|
|
|
|
@ -28,6 +29,32 @@ struct l2_packet_data {
|
|
|
|
|
* buffers */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Generated by 'sudo tcpdump -s 3000 -dd greater 278 and ip and udp and
|
|
|
|
|
* src port bootps and dst port bootpc'
|
|
|
|
|
*/
|
|
|
|
|
static struct sock_filter dhcp_sock_filter_insns[] = {
|
|
|
|
|
{ 0x80, 0, 0, 0x00000000 },
|
|
|
|
|
{ 0x35, 0, 12, 0x00000116 },
|
|
|
|
|
{ 0x28, 0, 0, 0x0000000c },
|
|
|
|
|
{ 0x15, 0, 10, 0x00000800 },
|
|
|
|
|
{ 0x30, 0, 0, 0x00000017 },
|
|
|
|
|
{ 0x15, 0, 8, 0x00000011 },
|
|
|
|
|
{ 0x28, 0, 0, 0x00000014 },
|
|
|
|
|
{ 0x45, 6, 0, 0x00001fff },
|
|
|
|
|
{ 0xb1, 0, 0, 0x0000000e },
|
|
|
|
|
{ 0x48, 0, 0, 0x0000000e },
|
|
|
|
|
{ 0x15, 0, 3, 0x00000043 },
|
|
|
|
|
{ 0x48, 0, 0, 0x00000010 },
|
|
|
|
|
{ 0x15, 0, 1, 0x00000044 },
|
|
|
|
|
{ 0x6, 0, 0, 0x00000bb8 },
|
|
|
|
|
{ 0x6, 0, 0, 0x00000000 },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const struct sock_fprog dhcp_sock_filter = {
|
|
|
|
|
.len = ARRAY_SIZE(dhcp_sock_filter_insns),
|
|
|
|
|
.filter = dhcp_sock_filter_insns,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int l2_packet_get_own_addr(struct l2_packet_data *l2, u8 *addr)
|
|
|
|
|
{
|
|
|
|
@ -202,3 +229,28 @@ int l2_packet_get_ip_addr(struct l2_packet_data *l2, char *buf, size_t len)
|
|
|
|
|
void l2_packet_notify_auth_start(struct l2_packet_data *l2)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int l2_packet_set_packet_filter(struct l2_packet_data *l2,
|
|
|
|
|
enum l2_packet_filter_type type)
|
|
|
|
|
{
|
|
|
|
|
const struct sock_fprog *sock_filter;
|
|
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
case L2_PACKET_FILTER_DHCP:
|
|
|
|
|
sock_filter = &dhcp_sock_filter;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (setsockopt(l2->fd, SOL_SOCKET, SO_ATTACH_FILTER,
|
|
|
|
|
sock_filter, sizeof(struct sock_fprog))) {
|
|
|
|
|
wpa_printf(MSG_ERROR,
|
|
|
|
|
"l2_packet_linux: setsockopt(SO_ATTACH_FILTER) failed: %s",
|
|
|
|
|
strerror(errno));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|