Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.
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
59 changes: 47 additions & 12 deletions src/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,19 +405,20 @@ static int hyper_setup_route(struct rtnl_handle *rth,
return 0;
}

static int hyper_set_interface_name(struct rtnl_handle *rth,
static int hyper_set_interface_attr(struct rtnl_handle *rth,
int ifindex,
char *new_device_name)
void *data,
int len,
int type)
{
struct {
struct nlmsghdr n;
struct ifinfomsg i;
char buf[1024];
} req;
struct nlmsghdr n;
struct ifinfomsg i;
char buf[1024];
} req;

if (ifindex < 0 || !new_device_name) {
if (!rth || ifindex < 0)
return -1;
}

memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
Expand All @@ -428,21 +429,46 @@ static int hyper_set_interface_name(struct rtnl_handle *rth,
req.i.ifi_change = 0xFFFFFFFF;
req.i.ifi_index = ifindex;

if (addattr_l(&req.n, sizeof(req), IFLA_IFNAME,
new_device_name,
strlen(new_device_name) + 1)) {
if (addattr_l(&req.n, sizeof(req), type,
data,
len)) {
fprintf(stderr, "setup attr failed\n");
return -1;
}

if (rtnl_talk(rth, &req.n, 0, 0, NULL) < 0) {
if (rtnl_talk(rth, &req.n, 0, 0, NULL) < 0){
perror("rtnl_talk failed");
return -1;
}

return 0;
}

static int hyper_set_interface_name(struct rtnl_handle *rth,
int ifindex,
char *new_device_name)
{
if ( !rth || ifindex < 0 || !new_device_name) {
return -1;
}
return hyper_set_interface_attr(rth, ifindex,
new_device_name,
strlen(new_device_name)+1,
IFLA_IFNAME);
}

static int hyper_set_interface_mtu(struct rtnl_handle *rth,
int ifindex,
unsigned int mtu)
{
if (!rth || ifindex < 0) {
return -1;
}
return hyper_set_interface_attr(rth, ifindex, &mtu,
sizeof(mtu),
IFLA_MTU);
}

static int hyper_setup_interface(struct rtnl_handle *rth,
struct hyper_interface *iface)
{
Expand Down Expand Up @@ -505,6 +531,15 @@ static int hyper_setup_interface(struct rtnl_handle *rth,
hyper_set_interface_name(rth, ifindex, iface->new_device_name);
}

if (iface->mtu > 0) {
fprintf(stdout, "Setting interface MTU to %d\n", iface->mtu);
if (hyper_set_interface_mtu(rth, ifindex, iface->mtu) < 0) {
fprintf(stderr, "set mtu failed for interface %s\n",
iface->device);
return -1;
}
}

if (hyper_up_nic(rth, ifindex) < 0) {
fprintf(stderr, "up device %d failed\n", ifindex);
return -1;
Expand Down
1 change: 1 addition & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct hyper_interface {
char *device;
struct list_head ipaddresses;
char *new_device_name;
unsigned int mtu;
};

struct hyper_route {
Expand Down
3 changes: 3 additions & 0 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,9 @@ static int hyper_parse_interface(struct hyper_interface *iface,
}
ipaddr_oldf->mask = (json_token_str(json, &toks[++i]));
dbg_pr(stdout, "net mask is %s\n", ipaddr_oldf->mask);
} else if (json_token_streq(json, &toks[i], "mtu")) {
iface->mtu = (json_token_int(json, &toks[++i]));
dbg_pr(stdout, "mtu is %d\n", iface->mtu);
} else {
hyper_print_unknown_key(json, &toks[i]);
goto fail;
Expand Down