Skip to content

Commit

Permalink
Merge pull request #99 from jcronenberg/method_selection
Browse files Browse the repository at this point in the history
Fix ip method selection logic
  • Loading branch information
cfconrad authored Oct 11, 2024
2 parents f0cf339 + d8e3a79 commit 5c2b353
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 22 deletions.
47 changes: 34 additions & 13 deletions rust/migrate-wicked/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub struct Interface {
pub ipv4: Ipv4,
#[serde(rename = "ipv4-static")]
pub ipv4_static: Option<Ipv4Static>,
#[serde(rename = "ipv4-dhcp")]
pub ipv4_dhcp: Option<Ipv4Dhcp>,
pub ipv6: Ipv6,
#[serde(rename = "ipv6-static")]
pub ipv6_static: Option<Ipv6Static>,
Expand Down Expand Up @@ -61,18 +63,34 @@ pub struct Link {
pub mtu: Option<u32>,
}

#[derive(Debug, PartialEq, Default, Serialize, Deserialize)]
#[serde(default)]
fn default_true() -> bool {
true
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Ipv4 {
#[serde(default = "default_true")]
pub enabled: bool,
}

#[derive(Debug, PartialEq, Default, Serialize, Deserialize)]
#[serde(default)]
impl Default for Ipv4 {
fn default() -> Self {
Self { enabled: true }
}
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Ipv6 {
#[serde(default = "default_true")]
pub enabled: bool,
}

impl Default for Ipv6 {
fn default() -> Self {
Self { enabled: true }
}
}

#[skip_serializing_none]
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Ipv4Static {
Expand All @@ -82,6 +100,11 @@ pub struct Ipv4Static {
pub routes: Option<Vec<Route>>,
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Ipv4Dhcp {
pub enabled: bool,
}

#[skip_serializing_none]
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Ipv6Static {
Expand Down Expand Up @@ -242,19 +265,18 @@ impl Interface {
},
warnings: vec![],
};
let method4 = if self.ipv4.enabled && self.ipv4_static.is_some() {
let method4 = if self.ipv4_static.is_some() {
Ipv4Method::Manual
} else if !self.ipv4.enabled {
Ipv4Method::Disabled
} else {
} else if self.ipv4_dhcp.is_some() {
Ipv4Method::Auto
} else {
Ipv4Method::Disabled
};
let method6 = if self.ipv6.enabled && self.ipv6_static.is_some() {
let method6 = if self.ipv6_static.is_some() {
Ipv6Method::Manual
} else if self.ipv6.enabled
&& self.ipv6_dhcp.is_some()
&& self.ipv6_dhcp.as_ref().unwrap().mode == "managed"
{
} else if self.ipv6_dhcp.is_some() && self.ipv6_dhcp.as_ref().unwrap().mode == "managed" {
Ipv6Method::Dhcp
} else if !self.ipv6.enabled {
Ipv6Method::Disabled
Expand Down Expand Up @@ -451,8 +473,7 @@ mod tests {
fn test_dhcp_interface_to_connection() {
setup_default_migration_settings();
let static_interface = Interface {
ipv4: Ipv4 { enabled: true },
ipv6: Ipv6 { enabled: true },
ipv4_dhcp: Some(Ipv4Dhcp { enabled: true }),
..Default::default()
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ method=disabled

[ipv6]
addr-gen-mode=default
method=disabled
method=auto

[proxy]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[connection]
id=eth9
uuid=da886e32-22a9-4d83-8c04-421ec59d274b
type=ethernet
interface-name=eth9

[ethernet]

[match]

[ipv4]
address1=192.168.100.5/24
address2=192.168.101.5/24
method=manual

[ipv6]
addr-gen-mode=default
method=auto

[proxy]
23 changes: 23 additions & 0 deletions rust/migrate-wicked/tests/ipv4_static/wicked_xml/ipv4_static.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,26 @@
<accept-redirects>false</accept-redirects>
</ipv6>
</interface>
<interface origin="compat:suse:/etc/sysconfig/network/ifcfg-eth9">
<name>eth9</name>
<control>
<mode>boot</mode>
</control>
<firewall/>
<link/>
<ipv4>
<arp-verify>true</arp-verify>
</ipv4>
<ipv4:static>
<address>
<local>192.168.100.5/24</local>
</address>
<address>
<local>192.168.101.5/24</local>
</address>
</ipv4:static>
<ipv6>
<privacy>prefer-public</privacy>
<accept-redirects>false</accept-redirects>
</ipv6>
</interface>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface-name=eth7
[match]

[ipv4]
method=auto
method=disabled

[ipv6]
addr-gen-mode=default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface-name=eth5
[match]

[ipv4]
method=auto
method=disabled

[ipv6]
addr-gen-mode=default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface-name=eth6
[match]

[ipv4]
method=auto
method=disabled

[ipv6]
addr-gen-mode=default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface-name=eth5
[match]

[ipv4]
method=auto
method=disabled

[ipv6]
addr-gen-mode=default
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[connection]
id=eth6
uuid=f429f20c-8e87-4e84-8380-4fbcc1bcd371
type=ethernet
interface-name=eth6

[ethernet]

[match]

[ipv4]
method=disabled

[ipv6]
addr-gen-mode=default
address1=2001:db8:0:1::5/64
address2=2001:db8:0:2::5/64
method=manual

[proxy]
24 changes: 24 additions & 0 deletions rust/migrate-wicked/tests/ipv6_static/wicked_xml/ipv6_static.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,27 @@
</address>
</ipv6:static>
</interface>
<interface origin="compat:suse:/etc/sysconfig/network/ifcfg-eth6">
<name>eth6</name>
<control>
<mode>boot</mode>
</control>
<firewall/>
<link/>
<ipv4>
<enabled>true</enabled>
<arp-verify>true</arp-verify>
</ipv4>
<ipv6>
<privacy>prefer-public</privacy>
<accept-redirects>false</accept-redirects>
</ipv6>
<ipv6:static>
<address>
<local>2001:db8:0:1::5/64</local>
</address>
<address>
<local>2001:db8:0:2::5/64</local>
</address>
</ipv6:static>
</interface>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ method=disabled

[ipv6]
addr-gen-mode=default
method=disabled
method=auto

[proxy]
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ method=disabled

[ipv6]
addr-gen-mode=default
method=disabled
method=auto

[proxy]
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ method=disabled

[ipv6]
addr-gen-mode=default
method=disabled
method=auto

[proxy]
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ method=disabled

[ipv6]
addr-gen-mode=default
method=disabled
method=auto

[proxy]

0 comments on commit 5c2b353

Please sign in to comment.