36#include <linux/socket.h>
38#include <linux/if_ether.h>
39#include <linux/if_packet.h>
44#define LINUX_AF_PACKET 17
45#define LINUX_SOCK_RAW 3
46#define LINUX_SIOCGIFINDEX 0x8933
47#define LINUX_SIOCGIFHWADDR 0x8927
49#define RX_BUF_SIZE 1536
71 struct sockaddr_ll socket_address;
78 DBGC(
nic,
"af_packet %p socket(AF_PACKET) = %d (%s)\n",
84 memset(&if_data, 0,
sizeof(if_data));
85 strncpy(if_data.ifr_name,
nic->ifname,
sizeof(if_data.ifr_name));
88 DBGC(
nic,
"af_packet %p ioctl(SIOCGIFINDEX) = %d (%s)\n",
94 nic->ifindex = if_data.ifr_ifindex;
97 memset(&socket_address, 0,
sizeof(socket_address));
99 socket_address.sll_ifindex =
nic->ifindex;
100 socket_address.sll_protocol =
htons(ETH_P_ALL);
102 sizeof(socket_address));
104 DBGC(
nic,
"af_packet %p bind() = %d (%s)\n",
113 DBGC(
nic,
"af_packet %p fcntl(%d, ...) = %d (%s)\n",
138 struct sockaddr_ll socket_address;
142 memset(&socket_address, 0,
sizeof(socket_address));
144 socket_address.sll_ifindex =
nic->ifindex;
145 socket_address.sll_halen =
ETH_ALEN;
151 0, (
struct sockaddr *)&socket_address,
152 sizeof(socket_address));
171 DBGC(
nic,
"af_packet %p poll failed (%s)\n",
175 if ((pfd.revents & POLLIN) == 0)
199 DBGC(
nic,
"af_packet %p alloc_iob failed\n",
nic);
211 DBGC(
nic,
"af_packet %p irq enable = %d\n",
nic, enable);
218 struct ifreq if_data;
224 DBGC(
nic,
"af_packet %p cannot create raw socket (%s)\n",
230 memset(&if_data, 0,
sizeof(if_data));
231 strncpy(if_data.ifr_name,
nic->ifname,
sizeof(if_data.ifr_name));
234 DBGC(
nic,
"af_packet %p cannot get mac addr (%s)\n",
280 printf(
"af_packet missing a mandatory if setting\n");
static struct net_device_operations af_packet_nic_operations
AF_PACKET operations.
#define LINUX_SIOCGIFHWADDR
static void af_packet_nic_poll(struct net_device *netdev)
Poll for new packets.
static int af_packet_nic_probe(struct linux_device *device, struct linux_device_request *request)
Handle a device request for the af_packet driver.
static void af_packet_nic_close(struct net_device *netdev)
Close the packet socket.
static void af_packet_nic_irq(struct net_device *netdev, int enable)
Set irq.
static int af_packet_update_properties(struct net_device *netdev)
static int af_packet_nic_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit an ethernet packet.
static int af_packet_nic_open(struct net_device *netdev)
Open the linux interface.
#define LINUX_SIOCGIFINDEX
static void af_packet_nic_remove(struct linux_device *device)
Remove the device.
struct arbelprm_rc_send_wqe rc
#define BUS_TYPE_TAP
TAP bus type.
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
static struct net_device * netdev
#define EINVAL
Invalid argument.
#define ENOMEM
Not enough space.
u8 request[0]
List of IEs requested.
Linux devices, drivers and device requests.
static void linux_set_drvdata(struct linux_device *device, void *priv)
Set linux device driver-private data.
#define LINUX_ROM(_name, _desc)
Define build rules for a Linux driver.
void linux_apply_settings(struct list_head *new_settings, struct settings *settings_block)
Apply a list of linux settings to a settings block.
#define __linux_driver
Declare a Linux driver.
static void * linux_get_drvdata(struct linux_device *device)
Get linux device driver-private data.
struct linux_setting * linux_find_setting(char *name, struct list_head *settings)
Look for the last occurrence of a setting with the specified name.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * memset(void *dest, int character, size_t len) __nonnull
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
#define iob_put(iobuf, len)
int __asmcall linux_bind(int sockfd, const struct sockaddr *addr, size_t addrlen)
int __asmcall linux_ioctl(int fd, unsigned long request,...)
int __asmcall linux_close(int fd)
int __asmcall linux_fcntl(int fd, int cmd,...)
ssize_t __asmcall linux_sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, size_t addrlen)
ssize_t __asmcall linux_read(int fd, void *buf, size_t count)
int __asmcall linux_socket(int domain, int type, int protocol)
int __asmcall linux_poll(struct pollfd *fds, unsigned int nfds, int timeout)
const char *__asmcall linux_strerror(int linux_errno)
Dynamic memory allocation.
static const uint8_t r[3][4]
MD4 shift amounts.
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
void unregister_netdev(struct net_device *netdev)
Unregister network device.
int register_netdev(struct net_device *netdev)
Register network device.
Network device management.
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
static void netdev_tx_complete(struct net_device *netdev, struct io_buffer *iobuf)
Complete network transmission.
char * strncpy(char *dest, const char *src, size_t max)
Copy string.
int fd
Packet socket descriptor.
char * ifname
Linux network interface name.
unsigned int bus_type
Bus type.
struct device_description desc
Device description.
An Ethernet link-layer header.
uint8_t h_dest[ETH_ALEN]
Destination MAC address.
void * data
Start of data.
A device request setting.
int applied
Was the setting already applied?
Network device operations.
Generalized socket address structure.
int printf(const char *fmt,...)
Write a formatted string to the console.
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.