Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions arch/lkl/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ config LKL
select HIGH_RES_TIMERS
select NET_SCHED
select NET_SCH_FQ
select IP_MULTICAST
select IPV6_MULTICAST
select IP_MULTIPLE_TABLES
select IPV6_MULTIPLE_TABLES
select IP_ROUTE_MULTIPATH
select IPV6_ROUTE_MULTIPATH
select IP_ADVANCED_ROUTER
select IPV6_ADVANCED_ROUTER

config OUTPUTFORMAT
string
Expand Down
1 change: 1 addition & 0 deletions arch/lkl/include/uapi/asm/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ struct sockaddr {
#include <linux/netlink.h>
#include <linux/neighbour.h>
#include <linux/rtnetlink.h>
#include <linux/fib_rules.h>

#include <linux/kdev_t.h>
#include <asm/irq.h>
Expand Down
61 changes: 61 additions & 0 deletions tools/lkl/include/lkl.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,18 @@ int lkl_if_set_ipv4(int ifindex, unsigned int addr, unsigned int netmask_len);
*/
int lkl_set_ipv4_gateway(unsigned int addr);

/**
* lkl_if_set_ipv4_gateway - add an IPv4 default route in rule table
*
* @ifindex - the ifindex of the interface, used for tableid calculation
* @addr - 4-byte IP address of the interface
* @netmask_len - prefix length of the @addr
* @gw_addr - 4-byte IP address of the gateway
* @returns - return 0 if no error: otherwise negative value returns
*/
int lkl_if_set_ipv4_gateway(int ifindex, unsigned int addr,
unsigned int netmask_len, unsigned int gw_addr);

/**
* lkl_if_set_ipv6 - set IPv6 address on interface
* must be called after interface is up.
Expand All @@ -326,6 +338,18 @@ int lkl_if_set_ipv6(int ifindex, void* addr, unsigned int netprefix_len);
*/
int lkl_set_ipv6_gateway(void* addr);

/**
* lkl_if_set_ipv6_gateway - add an IPv6 default route in rule table
*
* @ifindex - the ifindex of the interface, used for tableid calculation
* @addr - 16-byte IP address of the interface
* @netmask_len - prefix length of the @addr
* @gw_addr - 16-byte IP address of the gateway (i.e., struct in_addr)
* @returns - return 0 if no error: otherwise negative value returns
*/
int lkl_if_set_ipv6_gateway(int ifindex, void *addr,
unsigned int netmask_len, void *gw_addr);

/**
* lkl_netdev - host network device handle, defined in lkl_host.h.
*/
Expand Down Expand Up @@ -471,6 +495,43 @@ int lkl_if_add_ip(int ifindex, int af, void *addr, unsigned int netprefix_len);
*/
int lkl_if_del_ip(int ifindex, int af, void *addr, unsigned int netprefix_len);

/**
* lkl_add_gateway - add a gateway
* @af - address family of the ip address. Must be LKL_AF_INET or LKL_AF_INET6
* @gwaddr - 4-byte IP address of the gateway (i.e., struct in_addr)
*/
int lkl_add_gateway(int af, void *gwaddr);

/**
* XXX Should I use OIF selector?
* temporary table idx = ifindex * 2 + 0 <- ipv4
* temporary table idx = ifindex * 2 + 1 <- ipv6
*/
/**
* lkl_if_add_rule_from_addr - create an ip rule table with "from" selector
* @ifindex - the ifindex of the interface, used for table id calculation
* @af - address family of the ip address. Must be LKL_AF_INET or LKL_AF_INET6
* @saddr - network byte order ip address, "from" selector address of this rule
*/
int lkl_if_add_rule_from_saddr(int ifindex, int af, void *saddr);

/**
* lkl_if_add_gateway - add gateway to rule table
* @ifindex - the ifindex of the interface, used for table id calculation
* @af - address family of the ip address. Must be LKL_AF_INET or LKL_AF_INET6
* @gwaddr - 4-byte IP address of the gateway (i.e., struct in_addr)
*/
int lkl_if_add_gateway(int ifindex, int af, void *gwaddr);

/**
* lkl_if_add_linklocal - add linklocal route to rule table
* @ifindex - the ifindex of the interface, used for table id calculation
* @af - address family of the ip address. Must be LKL_AF_INET or LKL_AF_INET6
* @addr - ip address of the entry in network byte order
* @netprefix_len - prefix length of the @addr
*/
int lkl_if_add_linklocal(int ifindex, int af, void *addr, int netprefix_len);

/**
* lkl_if_wait_ipv6_dad - wait for DAD to be done for a ipv6 address
* must be called after interface is up
Expand Down
43 changes: 36 additions & 7 deletions tools/lkl/lib/hijack/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ hijack_init(void)
char *mac_str = getenv("LKL_HIJACK_NET_MAC");
char *netmask_len = getenv("LKL_HIJACK_NET_NETMASK_LEN");
char *netmask6_len = getenv("LKL_HIJACK_NET_NETMASK6_LEN");
char *ifgateway = getenv("LKL_HIJACK_NET_IFGATEWAY");
char *ifgateway6 = getenv("LKL_HIJACK_NET_IFGATEWAY6");
char *gateway = getenv("LKL_HIJACK_NET_GATEWAY");
char *gateway6 = getenv("LKL_HIJACK_NET_GATEWAY6");
char *debug = getenv("LKL_HIJACK_DEBUG");
Expand Down Expand Up @@ -398,13 +400,25 @@ hijack_init(void)
fprintf(stderr, "failed to set IPv4 address: %s\n",
lkl_strerror(ret));
}
if (ifgateway) {
unsigned int gwaddr = inet_addr(ifgateway);

if (gwaddr != INADDR_NONE) {
ret = lkl_if_set_ipv4_gateway(nd_ifindex,
addr, nmlen, gwaddr);
if (ret < 0)
fprintf(stderr,
"failed to set v4 if gw: %s\n",
lkl_strerror(ret));
}
}
}

if (nd_ifindex >= 0 && gateway) {
unsigned int addr = inet_addr(gateway);
unsigned int gwaddr = inet_addr(gateway);

if (addr != INADDR_NONE) {
ret = lkl_set_ipv4_gateway(addr);
if (gwaddr != INADDR_NONE) {
ret = lkl_set_ipv4_gateway(gwaddr);
if (ret< 0)
fprintf(stderr, "failed to set IPv4 gateway: %s\n",
lkl_strerror(ret));
Expand All @@ -423,16 +437,31 @@ hijack_init(void)
fprintf(stderr, "failed to set IPv6address: %s\n",
lkl_strerror(ret));
}
if (ifgateway6) {
char gwaddr[16];

if (inet_pton(AF_INET6, ifgateway6, gwaddr) != 1) {
fprintf(stderr, "Invalid ipv6 gateway: %s\n",
ifgateway6);
} else {
ret = lkl_if_set_ipv6_gateway(nd_ifindex,
&addr, pflen, gwaddr);
if (ret < 0)
fprintf(stderr,
"failed to set v6 if gw: %s\n",
lkl_strerror(ret));
}
}
}

if (nd_ifindex >= 0 && gateway6) {
char gw[16];
char gwaddr[16];

if (inet_pton(AF_INET6, gateway6, gw) != 1) {
if (inet_pton(AF_INET6, gateway6, gwaddr) != 1) {
fprintf(stderr, "Invalid ipv6 gateway: %s\n", gateway6);
} else {
ret = lkl_set_ipv6_gateway(gw);
if (ret< 0)
ret = lkl_set_ipv6_gateway(gwaddr);
if (ret < 0)
fprintf(stderr, "failed to set IPv6 gateway: %s\n",
lkl_strerror(ret));
}
Expand Down
Loading