forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lkl: introduce raw socket based netdev backend
This patch introduces new backend for virtio net, which uses AF_PACKET socket (a.k.a. raw socket) to bypass host kernel and uses LKL network stack instead. it is convinient since we don't have to add additional net_device (e.g., tap) for LKL, and possibly faster than tuntap with PACKET_QDISC_BYPASS socket option (available after Linux 3.14). One drawback is it requires root privilege (sudo or suid bit on) to use this. example usage is like this: sudo LKL_HIJACK_NET_IFTYPE=raw LKL_HIJACK_NET_IFPARAMS=docker0 \ LKL_HIJACK_NET_IP=172.17.0.39 LKL_HIJACK_NET_NETMASK_LEN=24 \ ./bin/lkl-hijack.sh ping 172.17.0.2 some benchmarks with netperf: - TCP_RR raw(QDISC_BYPASS): 9519.31 Trans/sec tap: 9486.03 Trans/sec - TCP_STREAM raw(QDISC_BYPASS): 2184.79 Mbps tap: 2130.39 Mbps - UDP_STREAM raw(QDISC_BYPASS): 3654.32 Mbps tap: 3108.10 Mbps Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
- Loading branch information
Showing
7 changed files
with
100 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* raw socket based virtual network interface feature for LKL | ||
* Copyright (c) 2015,2016 Ryo Nakamura, Hajime Tazaki | ||
* | ||
* Author: Ryo Nakamura <upa@wide.ad.jp> | ||
* Hajime Tazaki <thehajime@gmail.com> | ||
* | ||
* Current implementation is linux-specific. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <errno.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
#include <net/if.h> | ||
#include <linux/if_ether.h> | ||
#include <linux/if_packet.h> | ||
#include <arpa/inet.h> | ||
#include <fcntl.h> | ||
|
||
#include "virtio.h" | ||
#include "virtio_net_linux_fdnet.h" | ||
|
||
/* since Linux 3.14 (man 7 packet) */ | ||
#ifndef PACKET_QDISC_BYPASS | ||
#define PACKET_QDISC_BYPASS 20 | ||
#endif | ||
|
||
struct lkl_netdev *lkl_netdev_raw_create(const char *ifname) | ||
{ | ||
struct lkl_netdev_linux_fdnet *nd; | ||
int ret; | ||
struct sockaddr_ll ll; | ||
int fd, fd_flags, val; | ||
|
||
fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); | ||
if (fd < 0) { | ||
perror("socket"); | ||
return NULL; | ||
} | ||
|
||
memset(&ll, 0, sizeof(ll)); | ||
ll.sll_family = PF_PACKET; | ||
ll.sll_ifindex = if_nametoindex(ifname); | ||
ll.sll_protocol = htons(ETH_P_ALL); | ||
ret = bind(fd, (struct sockaddr *)&ll, sizeof(ll)); | ||
if (ret) { | ||
perror("bind"); | ||
close(fd); | ||
return NULL; | ||
} | ||
|
||
val = 1; | ||
ret = setsockopt(fd, SOL_PACKET, PACKET_QDISC_BYPASS, &val, | ||
sizeof(val)); | ||
if (ret) | ||
perror("PACKET_QDISC_BYPASS, ignoring"); | ||
|
||
fd_flags = fcntl(fd, F_GETFD, NULL); | ||
fcntl(fd, F_SETFL, fd_flags | O_NONBLOCK); | ||
|
||
nd = lkl_register_netdev_linux_fdnet(fd); | ||
if (!nd) { | ||
perror("failed to register to."); | ||
return NULL; | ||
} | ||
|
||
return (struct lkl_netdev *)nd; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters