diff options
author | David Decotigny | 2017-01-20 19:29:24 +0100 |
---|---|---|
committer | Michael Brown | 2017-01-22 15:02:54 +0100 |
commit | b6f524388ba5a02cf95ffa3fb3bfd5f0feae7bb6 (patch) | |
tree | 977cf8b17d5449370f5bc8e9e6db309a5b10f558 /src/arch | |
parent | [build] Return const char * from uuid_ntoa() (diff) | |
download | ipxe-b6f524388ba5a02cf95ffa3fb3bfd5f0feae7bb6.tar.gz ipxe-b6f524388ba5a02cf95ffa3fb3bfd5f0feae7bb6.tar.xz ipxe-b6f524388ba5a02cf95ffa3fb3bfd5f0feae7bb6.zip |
[af_packet] Add new AF_PACKET driver for Linux
This code largely inspired by tap.c. Allows for testing iPXE on real
NICs from within Linux. For example:
make bin-x86_64-linux/af_packet.linux
valgrind ./bin-x86_64-linux/af_packet.linux --net af_packet,if=eth3
Tested as x86_64 and i386 binary.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/arch')
-rw-r--r-- | src/arch/x86/core/linux/linux_api.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/arch/x86/core/linux/linux_api.c b/src/arch/x86/core/linux/linux_api.c index 0bed9fd5..17b1f3fd 100644 --- a/src/arch/x86/core/linux/linux_api.c +++ b/src/arch/x86/core/linux/linux_api.c @@ -108,3 +108,42 @@ void * linux_mremap ( void *old_address, __kernel_size_t old_size, int linux_munmap ( void *addr, __kernel_size_t length ) { return linux_syscall ( __NR_munmap, addr, length ); } + +int linux_socket ( int domain, int type_, int protocol ) { +#ifdef __NR_socket + return linux_syscall ( __NR_socket, domain, type_, protocol ); +#else +#ifndef SOCKOP_socket +# define SOCKOP_socket 1 +#endif + unsigned long sc_args[] = { domain, type_, protocol }; + return linux_syscall ( __NR_socketcall, SOCKOP_socket, sc_args ); +#endif +} + +int linux_bind ( int fd, const struct sockaddr *addr, socklen_t addrlen ) { +#ifdef __NR_bind + return linux_syscall ( __NR_bind, fd, addr, addrlen ); +#else +#ifndef SOCKOP_bind +# define SOCKOP_bind 2 +#endif + unsigned long sc_args[] = { fd, (unsigned long)addr, addrlen }; + return linux_syscall ( __NR_socketcall, SOCKOP_bind, sc_args ); +#endif +} + +ssize_t linux_sendto ( int fd, const void *buf, size_t len, int flags, + const struct sockaddr *daddr, socklen_t addrlen ) { +#ifdef __NR_sendto + return linux_syscall ( __NR_sendto, fd, buf, len, flags, + daddr, addrlen ); +#else +#ifndef SOCKOP_sendto +# define SOCKOP_sendto 11 +#endif + unsigned long sc_args[] = { fd, (unsigned long)buf, len, + flags, (unsigned long)daddr, addrlen }; + return linux_syscall ( __NR_socketcall, SOCKOP_sendto, sc_args ); +#endif +} |