aboutgitcodebugslistschat
path: root/netlink.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2021-10-14 13:05:56 +0200
committerStefano Brivio <sbrivio@redhat.com>2021-10-14 13:20:34 +0200
commit3c6d24dd3021bb294a7aa182a95a9cb868ca6cb4 (patch)
tree921af8b7607879a5fa912f4663c5de17e7d80112 /netlink.c
parent54a19002df18d2f19fc455c9b1ef9f88b96b7bd1 (diff)
downloadpasst-3c6d24dd3021bb294a7aa182a95a9cb868ca6cb4.tar
passt-3c6d24dd3021bb294a7aa182a95a9cb868ca6cb4.tar.gz
passt-3c6d24dd3021bb294a7aa182a95a9cb868ca6cb4.tar.bz2
passt-3c6d24dd3021bb294a7aa182a95a9cb868ca6cb4.tar.lz
passt-3c6d24dd3021bb294a7aa182a95a9cb868ca6cb4.tar.xz
passt-3c6d24dd3021bb294a7aa182a95a9cb868ca6cb4.tar.zst
passt-3c6d24dd3021bb294a7aa182a95a9cb868ca6cb4.zip
netlink, pasta: Configure MTU of tap interface on --config-net
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'netlink.c')
-rw-r--r--netlink.c44
1 files changed, 28 insertions, 16 deletions
diff --git a/netlink.c b/netlink.c
index ca2e77f..a26078b 100644
--- a/netlink.c
+++ b/netlink.c
@@ -454,27 +454,28 @@ next:
* @ifi: Interface index
* @mac: MAC address to fill, if passed as zero, to set otherwise
* @up: If set, bring up the link
+ * @mtu: If non-zero, set interface MTU
*/
-void nl_link(int ns, unsigned int ifi, void *mac, int up)
+void nl_link(int ns, unsigned int ifi, void *mac, int up, int mtu)
{
- int change = !MAC_IS_ZERO(mac) || up;
+ int change = !MAC_IS_ZERO(mac) || up || mtu;
struct {
struct nlmsghdr nlh;
struct ifinfomsg ifm;
struct rtattr rta;
- unsigned char mac[ETH_ALEN];
+ union {
+ unsigned char mac[ETH_ALEN];
+ unsigned int mtu;
+ };
} req = {
- .nlh.nlmsg_type = change ? RTM_NEWLINK : RTM_GETLINK,
- .nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
- .nlh.nlmsg_flags = NLM_F_REQUEST | (change ? NLM_F_ACK : 0),
- .nlh.nlmsg_seq = nl_seq++,
- .ifm.ifi_family = AF_UNSPEC,
- .ifm.ifi_index = ifi,
- .ifm.ifi_flags = up ? IFF_UP : 0,
- .ifm.ifi_change = up ? IFF_UP : 0,
-
- .rta.rta_type = IFLA_ADDRESS,
- .rta.rta_len = RTA_LENGTH(ETH_ALEN),
+ .nlh.nlmsg_type = change ? RTM_NEWLINK : RTM_GETLINK,
+ .nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
+ .nlh.nlmsg_flags = NLM_F_REQUEST | (change ? NLM_F_ACK : 0),
+ .nlh.nlmsg_seq = nl_seq++,
+ .ifm.ifi_family = AF_UNSPEC,
+ .ifm.ifi_index = ifi,
+ .ifm.ifi_flags = up ? IFF_UP : 0,
+ .ifm.ifi_change = up ? IFF_UP : 0,
};
struct ifinfomsg *ifm;
struct nlmsghdr *nh;
@@ -485,13 +486,24 @@ void nl_link(int ns, unsigned int ifi, void *mac, int up)
if (!MAC_IS_ZERO(mac)) {
req.nlh.nlmsg_len = sizeof(req);
memcpy(req.mac, mac, ETH_ALEN);
+ req.rta.rta_type = IFLA_ADDRESS;
+ req.rta.rta_len = RTA_LENGTH(ETH_ALEN);
+ nl_req(ns, buf, &req, req.nlh.nlmsg_len);
}
- n = nl_req(ns, buf, &req, req.nlh.nlmsg_len);
+ if (mtu) {
+ req.nlh.nlmsg_len = sizeof(req);
+ req.mtu = mtu;
+ req.rta.rta_type = IFLA_MTU;
+ req.rta.rta_len = RTA_LENGTH(sizeof(unsigned int));
+ nl_req(ns, buf, &req, req.nlh.nlmsg_len);
+ }
- if (!MAC_IS_ZERO(mac) || up)
+ if (change)
return;
+ n = nl_req(ns, buf, &req, req.nlh.nlmsg_len);
+
nh = (struct nlmsghdr *)buf;
for ( ; NLMSG_OK(nh, n); nh = NLMSG_NEXT(nh, n)) {
if (nh->nlmsg_type != RTM_NEWLINK)