Skip to content

Support Ephemeral Networking for BSD#2127

Merged
holmanb merged 2 commits into
canonical:mainfrom
holmanb:holmanb/dhcp-bsd
May 31, 2023
Merged

Support Ephemeral Networking for BSD#2127
holmanb merged 2 commits into
canonical:mainfrom
holmanb:holmanb/dhcp-bsd

Conversation

@holmanb
Copy link
Copy Markdown
Member

@holmanb holmanb commented Apr 18, 2023

Support ephemeral network for BSDs

Currently ephemeral.py uses hardcoded iproute2
calls to setup ephemeral networking, which is
incompatible with BSDs. Refactor to support
pluggable network interface operations.

Additional Context

Blocked by #2130 and #2122 (context).

@holmanb
Copy link
Copy Markdown
Member Author

holmanb commented Apr 19, 2023

Perhaps netinfo.py (netdev_info(), _netdev_route_info_iproute(), route_info(), _netdev_route_info_netstat()) should also get support of this interface.

@holmanb holmanb added the wip Work in progress, do not land label Apr 19, 2023
@blackboxsw blackboxsw self-assigned this Apr 21, 2023
@holmanb holmanb force-pushed the holmanb/dhcp-bsd branch 2 times, most recently from dc62b64 to 00a2b25 Compare April 24, 2023 16:18
@holmanb holmanb removed the wip Work in progress, do not land label Apr 24, 2023
@holmanb holmanb requested a review from blackboxsw April 24, 2023 17:18
Implement linux via new iproute module.
Leave bsds unimplemented for future work.
@holmanb
Copy link
Copy Markdown
Member Author

holmanb commented Apr 24, 2023

Perhaps netinfo.py (netdev_info(), _netdev_route_info_iproute(), route_info(), _netdev_route_info_netstat()) should also get support of this interface.

This will be left for a separate pull request.

Copy link
Copy Markdown
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

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

Overall looks pretty good. Take the rest of my nits with a grain of salt, but we need minimally to fix the freebsd.py:build_dhclient_cmd.

Here's a consolidated diff with review comments:

  • dropping unneeded parens
  • adding capture=True to network config cmds
  • adding path in bsd dhclient cmd
diff --git a/cloudinit/distros/freebsd.py b/cloudinit/distros/freebsd.py
index a4c8097e4..4ed1356e9 100644
--- a/cloudinit/distros/freebsd.py
+++ b/cloudinit/distros/freebsd.py
@@ -203,6 +203,6 @@ class Distro(cloudinit.distros.bsd.BSD):
         interface: str,
         config_file: str,
     ) -> list:
-        return ["-l", lease_file, "-p", pid_file] + (
+        return [path, "-l", lease_file, "-p", pid_file] + (
             ["-c", config_file, interface] if config_file else [interface]
         )
diff --git a/cloudinit/net/netops/iproute2.py b/cloudinit/net/netops/iproute2.py
index 08d79b187..be2fa1055 100644
--- a/cloudinit/net/netops/iproute2.py
+++ b/cloudinit/net/netops/iproute2.py
@@ -10,7 +10,8 @@ class Iproute2(netops.NetOps):
         subp.subp(
             ["ip"]
             + (["-family", family] if family else [])
-            + ["link", "set", "dev", interface, "up"]
+            + ["link", "set", "dev", interface, "up"],
+            capture=True,
         )
 
     @staticmethod
@@ -18,7 +19,8 @@ class Iproute2(netops.NetOps):
         subp.subp(
             ["ip"]
             + (["-family", family] if family else [])
-            + ["link", "set", "dev", interface, "down"]
+            + ["link", "set", "dev", interface, "down"],
+            capture=True,
         )
 
     @staticmethod
@@ -31,20 +33,19 @@ class Iproute2(netops.NetOps):
     ):
         subp.subp(
             ["ip", "-4", "route", "add", route]
-            + (["via", gateway] if gateway and gateway != "0.0.0.0" else [])
-            + [
-                "dev",
-                interface,
-            ]
-            + (["src", source_address] if source_address else []),
+            + ["via", gateway] if gateway and gateway != "0.0.0.0" else []
+            + ["dev", interface]
+            + ["src", source_address] if source_address else [],
+            capture=True,
         )
 
     @staticmethod
     def append_route(interface: str, address: str, gateway: str):
         subp.subp(
             ["ip", "-4", "route", "append", address]
-            + (["via", gateway] if gateway and gateway != "0.0.0.0" else [])
-            + ["dev", interface]
+            + ["via", gateway] if gateway and gateway != "0.0.0.0" else []
+            + ["dev", interface],
+            capture=True,
         )
 
     @staticmethod
@@ -57,9 +58,10 @@ class Iproute2(netops.NetOps):
     ):
         subp.subp(
             ["ip", "-4", "route", "del", address]
-            + (["via", gateway] if gateway and gateway != "0.0.0.0" else [])
+            + ["via", gateway] if gateway and gateway != "0.0.0.0" else []
             + ["dev", interface]
-            + (["src", source_address] if source_address else [])
+            + ["src", source_address] if source_address else [],
+            capture=True,
         )
 
     @staticmethod
@@ -83,11 +85,13 @@ class Iproute2(netops.NetOps):
                 "dev",
                 interface,
             ],
+            capture=True,
             update_env={"LANG": "C"},
         )
 
     @staticmethod
     def del_addr(interface: str, address: str):
         subp.subp(
-            ["ip", "-family", "inet", "addr", "del", address, "dev", interface]
+            ["ip", "-family", "inet", "addr", "del", address, "dev", interface],
+            capture=True,
         )

Comment thread cloudinit/distros/__init__.py
Comment thread cloudinit/distros/freebsd.py Outdated
Comment thread cloudinit/net/netops/iproute2.py
@igalic
Copy link
Copy Markdown
Collaborator

igalic commented May 1, 2023

thanks for the review, @blackboxsw
i have started working on bsd side of this change

@igalic igalic mentioned this pull request May 3, 2023
3 tasks
Copy link
Copy Markdown
Collaborator

@igalic igalic left a comment

Choose a reason for hiding this comment

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

],
capture=True,
self.distro.net_ops.add_route(
self.interface, self.router, source_address=self.ip
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

what exactly does this do?
how is this route different from one without src self.ip?

Copy link
Copy Markdown
Member Author

@holmanb holmanb May 5, 2023

Choose a reason for hiding this comment

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

I think adding src self.ip allows the route to force outgoing traffic to use the specified source address, which is otherwise unopinionated by a route that only specifies an interface.

Co-authored-by: Chad Smith <chad.smith@canonical.com>
@holmanb
Copy link
Copy Markdown
Member Author

holmanb commented May 5, 2023

Thanks for the review @blackboxsw! I fixed the issue with the freebsd dhclient command. I think that the rest of the issues have also been addressed.

I did get an external review via email by someone who tested this out. It seems that this breaks something that worked before. I'm going to set this PR to WIP while I dig into the issue they found while testing.

@holmanb holmanb added the wip Work in progress, do not land label May 5, 2023
@github-actions
Copy link
Copy Markdown

Hello! Thank you for this proposed change to cloud-init. This pull request is now marked as stale as it has not seen any activity in 14 days. If no activity occurs within the next 7 days, this pull request will automatically close.

If you are waiting for code review and you are seeing this message, apologies! Please reply, tagging TheRealFalcon, and he will ensure that someone takes a look soon.

(If the pull request is closed and you would like to continue working on it, please do tag TheRealFalcon to reopen it.)

@github-actions github-actions Bot added the stale-pr Pull request is stale; will be auto-closed soon label May 20, 2023
@holmanb holmanb removed the stale-pr Pull request is stale; will be auto-closed soon label May 22, 2023
Copy link
Copy Markdown
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

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

This changeset looks good to me, it fixes the missing path issue on freebsd.py.'s build_dhclient_cmd. Are we are waiting on a potential failure path seen on BSD outside of this?

@holmanb
Copy link
Copy Markdown
Member Author

holmanb commented May 31, 2023

This changeset looks good to me, it fixes the missing path issue on freebsd.py.'s build_dhclient_cmd. Are we are waiting on a potential failure path seen on BSD outside of this?

I made some changes to this PR after that report and haven't heard an update on that. I'd like to merge this so that we can unblock @igalic from working on the bsd implementation. I'll reach out to the reported to see if they have an update on the latest version of this, but in the meantime I'll merge.

@holmanb holmanb removed the wip Work in progress, do not land label May 31, 2023
@holmanb holmanb merged commit 95364bb into canonical:main May 31, 2023
holmanb pushed a commit that referenced this pull request Jun 12, 2023
Implement ephemeral networking for BSD

After #2127 lay the foundation, we now implement the BSD side of this

Sponsored by: The FreeBSD Foundation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants