From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=fail reason="key not found in DNS" header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202312 header.b=NhyQXB4+; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 7562B5A0275 for ; Thu, 15 Aug 2024 05:43:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1723693394; bh=Nrd9nf70BqX90l5HK7tcKO+z9Y/WiEctLKdV30sO1jc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=NhyQXB4+cUmQhvqDva4GSLXUQNqGvjPc2uhuKYbCJKlVr0uBtZkmhA+VMjOhba8Ci p++glABYlmd5RrAn1wWMiqbifJ1VjSOZUUwxqn7MqHQ2Z0NJCyyAZN0vBDdh6iNZYa 1UesptnjobHZzTWwNwVOxemdAPwrZZv2bI6x/DaVAaEFi/u4LO+z4G0ns+Bs/b+f0q RhOMGNiutjKFzuXXgJoWwCC4MlJSEbrjbUZDyZ6DdY+YTShwor2kbijEXfMTxivtuS YcRj6UUDZq2HuKHZoYx6jGaXK13Jf1aeEek/6YhhAV0e9/aXSMtu7oDYA3nsbZ5cg5 uY4vaild7MLcw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4WkrYt0BYKz4x1V; Thu, 15 Aug 2024 13:43:14 +1000 (AEST) Date: Thu, 15 Aug 2024 12:41:16 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 2/7] netlink, pasta: Split MTU setting functionality out of nl_link_up() Message-ID: References: <20240814225429.3707908-1-sbrivio@redhat.com> <20240814225429.3707908-3-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="IDOZHk/Cif/hhPHp" Content-Disposition: inline In-Reply-To: <20240814225429.3707908-3-sbrivio@redhat.com> Message-ID-Hash: SUONKR5MKJSQHRXRCWQ2KTPW7FADUFW3 X-Message-ID-Hash: SUONKR5MKJSQHRXRCWQ2KTPW7FADUFW3 X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top, Paul Holzinger X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --IDOZHk/Cif/hhPHp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Aug 15, 2024 at 12:54:24AM +0200, Stefano Brivio wrote: > As we'll use nl_link_up() for more than just bringing up devices, it > will become awkward to carry empty MTU values around whenever we call > it. I prefer clearer single purpose functions too. Reviewed-by: David Gibson >=20 > Signed-off-by: Stefano Brivio > --- > netlink.c | 35 +++++++++++++++++++++++++---------- > netlink.h | 3 ++- > pasta.c | 7 +++++-- > 3 files changed, 32 insertions(+), 13 deletions(-) >=20 > diff --git a/netlink.c b/netlink.c > index e6a315e..e33765e 100644 > --- a/netlink.c > +++ b/netlink.c > @@ -942,14 +942,14 @@ int nl_link_set_mac(int s, unsigned int ifi, const = void *mac) > } > =20 > /** > - * nl_link_up() - Bring link up > + * nl_link_set_mtu() - Set link MTU > * @s: Netlink socket > * @ifi: Interface index > - * @mtu: If non-zero, set interface MTU > + * @mtu: Interface MTU > * > * Return: 0 on success, negative error code on failure > */ > -int nl_link_up(int s, unsigned int ifi, int mtu) > +int nl_link_set_mtu(int s, unsigned int ifi, int mtu) > { > struct req_t { > struct nlmsghdr nlh; > @@ -959,17 +959,32 @@ int nl_link_up(int s, unsigned int ifi, int mtu) > } req =3D { > .ifm.ifi_family =3D AF_UNSPEC, > .ifm.ifi_index =3D ifi, > - .ifm.ifi_flags =3D IFF_UP, > - .ifm.ifi_change =3D IFF_UP, > .rta.rta_type =3D IFLA_MTU, > .rta.rta_len =3D RTA_LENGTH(sizeof(unsigned int)), > .mtu =3D mtu, > }; > - ssize_t len =3D sizeof(req); > =20 > - if (!mtu) > - /* Shorten request to drop MTU attribute */ > - len =3D offsetof(struct req_t, rta); > + return nl_do(s, &req, RTM_NEWLINK, 0, sizeof(req)); > +} > + > +/** > + * nl_link_up() - Bring link up > + * @s: Netlink socket > + * @ifi: Interface index > + * > + * Return: 0 on success, negative error code on failure > + */ > +int nl_link_up(int s, unsigned int ifi) > +{ > + struct req_t { > + struct nlmsghdr nlh; > + struct ifinfomsg ifm; > + } req =3D { > + .ifm.ifi_family =3D AF_UNSPEC, > + .ifm.ifi_index =3D ifi, > + .ifm.ifi_flags =3D IFF_UP, > + .ifm.ifi_change =3D IFF_UP, > + }; > =20 > - return nl_do(s, &req, RTM_NEWLINK, 0, len); > + return nl_do(s, &req, RTM_NEWLINK, 0, sizeof(req)); > } > diff --git a/netlink.h b/netlink.h > index 3a1f0de..87d27ae 100644 > --- a/netlink.h > +++ b/netlink.h > @@ -23,6 +23,7 @@ int nl_addr_dup(int s_src, unsigned int ifi_src, > int s_dst, unsigned int ifi_dst, sa_family_t af); > int nl_link_get_mac(int s, unsigned int ifi, void *mac); > int nl_link_set_mac(int s, unsigned int ifi, const void *mac); > -int nl_link_up(int s, unsigned int ifi, int mtu); > +int nl_link_set_mtu(int s, unsigned int ifi, int mtu); > +int nl_link_up(int s, unsigned int ifi); > =20 > #endif /* NETLINK_H */ > diff --git a/pasta.c b/pasta.c > index 615ff7b..3a0652e 100644 > --- a/pasta.c > +++ b/pasta.c > @@ -288,7 +288,7 @@ void pasta_ns_conf(struct ctx *c) > { > int rc =3D 0; > =20 > - rc =3D nl_link_up(nl_sock_ns, 1 /* lo */, 0); > + rc =3D nl_link_up(nl_sock_ns, 1 /* lo */); > if (rc < 0) > die("Couldn't bring up loopback interface in namespace: %s", > strerror(-rc)); > @@ -303,7 +303,10 @@ void pasta_ns_conf(struct ctx *c) > strerror(-rc)); > =20 > if (c->pasta_conf_ns) { > - nl_link_up(nl_sock_ns, c->pasta_ifi, c->mtu); > + if (c->mtu !=3D -1) > + nl_link_set_mtu(nl_sock_ns, c->pasta_ifi, c->mtu); > + > + nl_link_up(nl_sock_ns, c->pasta_ifi); > =20 > if (c->ifi4) { > if (c->ip4.no_copy_addrs) { --=20 David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson --IDOZHk/Cif/hhPHp Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAma9assACgkQzQJF27ox 2GcHTxAAiaJGFky56quqS5q0V+ayZJSA6remGfp4nz74IZ5zuhAC6gdUwAIyo9au inthlUqnzqQL/Jybdi4TPDgDDg4T201o5No0vGbc2P7Mnf0XiSeQITPCYCk7RYpj Pa2MF04s822FRNcItigh1nJ4uRulA59HCClFJQyUIQQNFAmtdCSqqh5GK8BqL+dp 73Bk8g0LgoALzzQJg8TWtF6QAHumN2wLXuGsWbEWbLV+1WJHoFx1EbzPd7wf+84N omeh+0minkOM0eUrPABpBi6udYAhwGLwNynrTf+lt0yhkEWUYAGc+uYipzOzzqrV HkO7EFVsRpAjNTJ+Ur4Irk6WFof7f2QVAVaPnEXK2hAWCyCWuTvJy+TlUw19pC79 2KP/Aq7iROxlg9LaN4aGsbsPwoANEUgmoPkPKXE5utlb2mbp9Z1zNvRPFHXH+wOV TYDm7xIA+uasbJO/5loMp5fSAwW7a25+fT2Tdw9hjtiPEdJGlBktb46QkWwJ1Nnd CHspiFRh9PU2Ap+cGqohBRsXQnNzFB1tF+bDsXp1FAL+rO0hAleE166Sz6WLOJSh vQn/IFCMPaft/r0dnCXZPgDBKveliEfXNIUIK4Jdjw5rmIRkX8mmdOTovDNwAAHi kq2Ylolh7HTPC6JojANxC/MVuhFaOML5Cc2LmEiV1RPizjd6MVs= =3hpr -----END PGP SIGNATURE----- --IDOZHk/Cif/hhPHp--