Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.
Closed
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
31 changes: 27 additions & 4 deletions src/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ static int rtnl_talk(struct rtnl_handle *rtnl,
return 0;
}

static int hyper_up_nic(struct rtnl_handle *rth, int ifindex)
static int hyper_up_nic(struct rtnl_handle *rth, int ifindex, unsigned int mtu)
{
struct {
struct nlmsghdr n;
Expand All @@ -277,6 +277,22 @@ static int hyper_up_nic(struct rtnl_handle *rth, int ifindex)
req.i.ifi_flags |= IFF_UP;
req.i.ifi_index = ifindex;


// As per Wiki:
// https://en.wikipedia.org/wiki/Maximum_transmission_unit#Table_of_MTUs_of_common_media
//
// The minimum and maximum value of MTU is (68, 2^32-1)
if (mtu < 68 || mtu > 4294967295)
mtu = 1500;

// creating a rtnetlink message to set the MTU of the device
struct rtattr *rta;
rta = (struct rtattr *)(((char *) &req) + NLMSG_ALIGN(req.n.nlmsg_len));
rta->rta_type = IFLA_MTU;
rta->rta_len = RTA_LENGTH(sizeof(unsigned int));
req.n.nlmsg_len = NLMSG_ALIGN(req.n.nlmsg_len) + RTA_LENGTH(sizeof(mtu));
memcpy(RTA_DATA(rta), &mtu, sizeof(mtu));

if (rtnl_talk(rth, &req.n, 0, 0, NULL) < 0)
return -1;

Expand Down Expand Up @@ -567,8 +583,15 @@ static int hyper_setup_interface(struct rtnl_handle *rth,
char buf[256];
} req;

// TODO(HuKeping): We don't check the value of mtu here because
// the external caller may not set the MTU. In the meantime, we could
// set it to 1500 as default if it was not provided.
//
// Feel free to dissucss about it if anybody think we should ask for the
// MTU value here.
if (!(iface->device && iface->ipaddr && iface->mask)) {
fprintf(stderr, "interface information incorrect\n");
fprintf(stderr, "interface information for setting up is incorrect, device:%s,ipaddr:%s,mask:%s\n",
iface->device, iface->ipaddr, iface->mask);
return -1;
}

Expand Down Expand Up @@ -604,7 +627,7 @@ static int hyper_setup_interface(struct rtnl_handle *rth,
return -1;
}

if (hyper_up_nic(rth, iface->ifindex) < 0) {
if (hyper_up_nic(rth, iface->ifindex, iface->mtu) < 0) {
fprintf(stderr, "up device %d failed\n", iface->ifindex);
return -1;
}
Expand Down Expand Up @@ -719,7 +742,7 @@ int hyper_setup_network(struct hyper_pod *pod)
}
}

ret = hyper_up_nic(&rth, 1);
ret = hyper_up_nic(&rth, 1, 1500);
if (ret < 0) {
fprintf(stderr, "link up lo device failed\n");
goto out;
Expand Down
1 change: 1 addition & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ struct hyper_interface {
int ifindex;
char *ipaddr;
char *mask;
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 @@ -776,6 +776,9 @@ static int hyper_parse_interface(struct hyper_interface *iface,
} else if (json_token_streq(json, &toks[i], "netMask")) {
iface->mask = (json_token_str(json, &toks[++i]));
fprintf(stdout, "net mask is %s\n", iface->mask);
} else if (json_token_streq(json, &toks[i], "mtu")) {
iface->mtu = (json_token_int(json, &toks[++i]));
fprintf(stdout, "net mtu is %u\n", iface->mtu);
} else {
fprintf(stderr, "get unknown section %s in interfaces\n",
json_token_str(json, &toks[i]));
Expand Down