Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set mac address for macvtap if specified #231

Merged
merged 1 commit into from
Nov 11, 2021
Merged

fix: set mac address for macvtap if specified #231

merged 1 commit into from
Nov 11, 2021

Conversation

richardcase
Copy link
Member

@richardcase richardcase commented Nov 9, 2021

What this PR does / why we need it:

There is a problem with using an auto generated mac address with a macvtap interface. The
kernel appears to change the mac address from what it was originally
created with. The firecracker and cloud init configuration contain the original mac address.
When the guest boots and cloud-init gets to configure the network the
mac address has changed and this then causes the network configuration to fail as it can't
match on the mac address.

We need to find actual evidence of the above, but this has been a known
behaviour with other types of interface and for the those the advice is
to specify a mac address when you create the interface.

This change will use the guest_mac if it's specified for the mac
address on the host if the interface type is macvtap. For macvtap the
mac address on the host is the same as in the guest.

Also removed an erroneous comment about a block of code not being hit.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:

Checklist:

  • squashed commits into logical changes

@richardcase richardcase added the kind/bug Something isn't working label Nov 9, 2021
@codecov-commenter
Copy link

codecov-commenter commented Nov 9, 2021

Codecov Report

Merging #231 (b467e07) into main (fe9bb9f) will increase coverage by 0.45%.
The diff coverage is 70.83%.

❗ Current head b467e07 differs from pull request most recent head fdeae41. Consider uploading reports for the commit fdeae41 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main     #231      +/-   ##
==========================================
+ Coverage   55.81%   56.27%   +0.45%     
==========================================
  Files          44       44              
  Lines        2012     1985      -27     
==========================================
- Hits         1123     1117       -6     
+ Misses        781      767      -14     
+ Partials      108      101       -7     
Impacted Files Coverage Δ
core/application/commands.go 71.66% <ø> (+2.70%) ⬆️
core/steps/network/interface_create.go 96.29% <ø> (ø)
pkg/validation/validate.go 100.00% <ø> (+12.50%) ⬆️
core/plans/microvm_create_update.go 57.53% <36.36%> (+2.65%) ⬆️
core/plans/microvm_delete.go 58.49% <100.00%> (+1.62%) ⬆️
core/steps/microvm/create.go 100.00% <100.00%> (ø)
core/steps/microvm/start.go 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update da2cb50...fdeae41. Read the comment docs.

@@ -80,14 +90,15 @@ func (n *networkService) IfaceCreate(ctx context.Context, input ports.IfaceCreat
return nil, fmt.Errorf("creating interface %s using netlink: %w", link.Attrs().Name, err)
}

macIf, err := netlink.LinkByName(link.Attrs().Name)
macIf, err := netlink.LinkByName(input.DeviceName)
if err != nil {
return nil, fmt.Errorf("getting interface %s using netlink: %w", link.Attrs().Name, err)
Copy link
Member

@Callisto13 Callisto13 Nov 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this error still "correct"? input.DeviceName now? (i get they are the same, but for clarity maybe since you changed the above?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it back as there was no need to change that part. And with the original its more obvious that we are re-getting the link we just added.

Callisto13
Callisto13 previously approved these changes Nov 10, 2021
Copy link
Member

@Callisto13 Callisto13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zero tests for this file 😆 so adding an issue to backfill #244

Callisto13
Callisto13 previously approved these changes Nov 10, 2021
jmickey
jmickey previously approved these changes Nov 10, 2021
There is a problem with using an auto generated mac address with a macvtap interface. The
kernel appears to change the mac address from what it was originally
created with. The firecracker and cloud init configuration contain the aoriginal mac address.
When the guest boots and cloud-init gets to configured the network the
mac address has changed and this then causes the network configuration to fail as it can't
match on the mac address.

We need to find actual evidence of the above but this has been a known
behaviour with other types of interface and for the those the advice is
to specify a mac address when you create the interface.

This change will use the `guest_mac` if its specified for the mac
address on the host if the interface type is macvtap. For macvtap the
mac address on the host is the same as in the guest.

Signed-off-by: Richard Case <richard@weave.works>
Comment on lines -91 to -94
// This whole block is unreachable right now, because
// the Do function is called only if ShouldDo returns
// true. It retruns false if IfaceExists returns true.
// Line 76 will never return exists=true
Copy link
Contributor

@yitsushi yitsushi Nov 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still a half-dead code here and I left this comment it here:

  1. It's visible we try to do that and in case we call Do without ShouldDo, it works
  2. If the device status is not update and we someone checks the code "but hey we do an update here", they can see "nope we don't" and don't start debugging for hours to get to the same results that it's not executed if it's called only on ShouldDo==true

@richardcase richardcase merged commit 6bcae78 into liquidmetal-dev:main Nov 11, 2021
@richardcase richardcase deleted the net_cloudinit_issue branch November 11, 2021 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants