-
Notifications
You must be signed in to change notification settings - Fork 20
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
Add VRRP checks for if instance is an owner. #37
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ pub struct InstanceState { | |
pub timer: VrrpTimer, | ||
pub last_adv_src: Option<Ipv4Addr>, | ||
pub statistics: Statistics, | ||
pub is_owner: bool, | ||
} | ||
|
||
#[derive(Debug)] | ||
|
@@ -165,7 +166,8 @@ impl Instance { | |
match InstanceNet::new(interface, &self.mvlan) { | ||
Ok(net) => { | ||
self.net = Some(net); | ||
if self.config.priority == 255 { | ||
self.state.is_owner = self.check_is_owner(interface.system); | ||
if self.config.priority == 255 || self.state.is_owner { | ||
let src_ip = | ||
interface.system.addresses.first().unwrap().ip(); | ||
self.send_vrrp_advertisement(src_ip); | ||
|
@@ -314,11 +316,18 @@ impl Instance { | |
ip_addresses.push(addr.ip()); | ||
} | ||
|
||
// RFC 3768 -> 5.3.4. Priority | ||
let priority = if self.state.is_owner { | ||
255 | ||
} else { | ||
self.config.priority | ||
}; | ||
|
||
let mut packet = VrrpHdr { | ||
version: 2, | ||
hdr_type: 1, | ||
vrid: self.vrid, | ||
priority: self.config.priority, | ||
priority, | ||
count_ip: self.config.virtual_addresses.len() as u8, | ||
auth_type: 0, | ||
adver_int: self.config.advertise_interval, | ||
|
@@ -403,6 +412,16 @@ impl Instance { | |
let _ = net.net_tx_packetp.send(msg); | ||
} | ||
} | ||
|
||
/// an instance is an owner if the ip address of the parent interface is | ||
/// part of the virutal addresses held by the instance. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo (s/virutal/virtual/) |
||
pub(crate) fn check_is_owner(&self, interface_sys: &InterfaceSys) -> bool { | ||
self.config | ||
.virtual_addresses | ||
.iter() | ||
.any(|addr| interface_sys.addresses.contains(addr)); | ||
false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should return the result of the last expression instead of always returning false |
||
} | ||
} | ||
|
||
impl Drop for Instance { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -222,6 +222,10 @@ impl Provider for Interface { | |
); | ||
instance.timer_set(&interface); | ||
} | ||
|
||
// owner status may change when virtual address is added | ||
instance.state.is_owner = | ||
instance.check_is_owner(interface.system); | ||
} | ||
Event::VirtualAddressDelete { vrid, addr } => { | ||
let (interface, instance) = self.get_instance(vrid).unwrap(); | ||
|
@@ -234,6 +238,9 @@ impl Provider for Interface { | |
); | ||
instance.timer_set(&interface); | ||
} | ||
// owner status may change when virtual address is added | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Owner status can also change when an IP address is added to or removed from the interface. For simplicity, we could compute the owner status on demand whenever necessary, instead of caching and continuously updating it. There's only a few places where we need to consult the owner status, and computing it is a cheap operation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rwestphal You're right, the owner status can also change when an IP address is added or removed from an interface. I will add the My thought process was I wanted to cover cases where we have access to |
||
instance.state.is_owner = | ||
instance.check_is_owner(interface.system); | ||
} | ||
Event::ResetTimer { vrid } => { | ||
let (_, instance) = self.get_instance(vrid).unwrap(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments should start with an uppercase for consistency with the rest of the codebase