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

Enable link-local in parallel with DHCP #1550

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -169,27 +169,36 @@ private void setConnectionDHCP(NetworkConfig config) {
String connName = "dhcp-" + config.networkManagerIface;

String addDHCPcommand = """
nmcli connection add
nmcli conn add
con-name "${connection}"
ifname "${interface}"
type ethernet
autoconnect no
""".replaceAll("[\\n]", " ");

String modDHCPCommand = """
nmcli conn modify "${connection}"
autoconnect yes
ipv4.method auto
ipv4.dhcp-timeout infinity
ipv4.link-local enabled
ipv6.method disabled
""";
addDHCPcommand = addDHCPcommand.replaceAll("[\\n]", " ");
""".replaceAll("[\\n]", " ");

var shell = new ShellExec();
try {
if (NetworkUtils.connDoesNotExist(connName)) {
// create connection
logger.info("Creating the DHCP connection " + connName );
logger.info("Updating the DHCP connection " + connName );
shell.executeBashCommand(
addDHCPcommand
.replace("${connection}", connName)
.replace("${interface}", config.networkManagerIface)
);
);
}
logger.info("Updating the DHCP connection " + connName );
shell.executeBashCommand(
modDHCPCommand
.replace("${connection}", connName)
);
// activate it
logger.info("Activating the DHCP connection " + connName );
shell.executeBashCommand("nmcli connection up \"${connection}\"".replace("${connection}", connName), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ public static NMDeviceInfo getNMinfoForDevName(String devName) {
public static boolean connDoesNotExist(String connName) {
var shell = new ShellExec(true, true);
try {
// set nmcli back to DHCP, and re-run dhclient -- this ought to grab a new IP address
shell.executeBashCommand("nmcli -f GENERAL.STATE connection show \"" + connName + "\"");
shell.executeBashCommand("nmcli -g GENERAL.STATE connection show \"" + connName + "\"");
return (shell.getExitCode() == 10);
} catch (Exception e) {
logger.error("Exception from nmcli!");
Expand Down
Loading