Struct rnetmgr_lib::client::NetInfoReport
source · pub struct NetInfoReport { /* private fields */ }Implementations§
source§impl NetInfoReport
impl NetInfoReport
sourcepub fn new(if_name: String) -> Self
pub fn new(if_name: String) -> Self
Examples found in repository?
src/client.rs (line 186)
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
pub fn run(
name: Option<&'static str>,
sender: Sender<Option<String>>,
ifname: Option<String>,
) -> Result<JoinHandle<Result<(), RnetmgrConError>>, RnetmgrConError> {
let handler = std::thread::spawn(move || -> Result<(), RnetmgrConError> {
let mut netinfo_hash = HashMap::<String, NetInfoReport>::new();
let ih = Ipcon::new(name, Some(IPF_SND_IF | IPF_RCV_IF))
.change_context(RnetmgrConError::IpconError)?;
ih.join_group(ipcon::IPCON_KERNEL_NAME, ipcon::IPCON_KERNEL_GROUP_NAME)
.change_context(RnetmgrConError::IpconError)?;
let netif_str = ifname.as_deref().unwrap_or("eth0");
let req_msg = NetInfoReqMessage::ReqAddress(netif_str.to_owned());
let try_send_request = || -> Result<(), RnetmgrConError> {
ih.join_group(NETINFO_IPCON, NETINFO_IPCON_GROUP)
.change_context(RnetmgrConError::IpconError)?;
jdebug!("joined {}@{} group", NETINFO_IPCON_GROUP, NETINFO_IPCON);
let buf = serde_json::to_string(&req_msg)
.into_report()
.change_context(RnetmgrConError::InvalidData)?;
let c_buf = CString::new(buf)
.into_report()
.change_context(RnetmgrConError::InvalidData)?;
jdebug!("send request: {:?}", req_msg);
ih.send_unicast_msg(NETINFO_IPCON, c_buf.as_bytes())
.change_context(RnetmgrConError::IpconError)
};
let _ = try_send_request();
loop {
jdebug!("Wait message");
let msg = ih
.receive_msg()
.change_context(RnetmgrConError::IpconError)?;
match msg {
IpconMsg::IpconMsgKevent(kevent) => {
if let Some((p, g)) = kevent.group_added() {
if (NETINFO_IPCON == p) && (NETINFO_IPCON_GROUP == g) {
jdebug!(
"{}@{} added, send request.",
NETINFO_IPCON_GROUP,
NETINFO_IPCON
);
let _ = try_send_request();
}
continue;
}
if let Some((p, g)) = kevent.group_removed() {
if (NETINFO_IPCON == p) && (NETINFO_IPCON_GROUP == g) {
jdebug!("{}@{} removed", NETINFO_IPCON_GROUP, NETINFO_IPCON);
netinfo_hash.clear();
sender
.send(None)
.into_report()
.change_context(RnetmgrConError::IpconError)?;
}
continue;
}
}
IpconMsg::IpconMsgUser(m)
if matches!(m.msg_type, IpconMsgType::IpconMsgTypeGroup) =>
{
let group = m.group.unwrap();
jdebug!(msg = "GroupMsg", peer = m.peer, group = group);
if (NETINFO_IPCON == m.peer) && (NETINFO_IPCON_GROUP == group) {
let c_str = CStr::from_bytes_with_nul(&m.buf).map(|a| a.to_str());
match c_str {
Ok(Ok(s)) => match serde_json::from_str::<NetInfoMessage>(s) {
Ok(NetInfoMessage::NewAddress(addr))
if addr.ifname.eq(netif_str) =>
{
let nim = netinfo_hash
.entry(netif_str.to_owned())
.or_insert_with(|| {
NetInfoReport::new(netif_str.to_owned())
});
nim.add(addr.ipv4addr);
sender
.send(nim.get())
.into_report()
.change_context(RnetmgrConError::IOError)?;
}
Ok(NetInfoMessage::DelAddress(addr))
if addr.ifname.eq(netif_str) =>
{
let nim = netinfo_hash
.entry(netif_str.to_owned())
.or_insert_with(|| {
NetInfoReport::new(netif_str.to_owned())
});
nim.del(addr.ipv4addr);
sender
.send(nim.get())
.into_report()
.change_context(RnetmgrConError::IOError)?;
}
_ => {}
},
Ok(Err(e)) => jwarn!("Invalid C string : {}", e),
Err(e) => jwarn!("Invalid string: {}", e),
}
}
}
IpconMsg::IpconMsgUser(m)
if matches!(m.msg_type, IpconMsgType::IpconMsgTypeNormal)
&& (NETINFO_IPCON == m.peer) =>
{
jdebug!(msg = "UsrMsg", peer = m.peer, buf_size = m.buf.len());
let c_str = CStr::from_bytes_with_nul(&m.buf).map(|a| a.to_str());
match c_str {
Ok(Ok(s)) => {
jdebug!("json: {}", s);
match serde_json::from_str::<NetInfoMessage>(s) {
Ok(NetInfoMessage::NewAddress(addr))
if addr.ifname.eq(netif_str) =>
{
let nim = netinfo_hash
.entry(netif_str.to_owned())
.or_insert_with(|| {
NetInfoReport::new(netif_str.to_owned())
});
nim.add(addr.ipv4addr);
sender
.send(nim.get())
.into_report()
.change_context(RnetmgrConError::IOError)?;
}
Ok(NetInfoMessage::NewAddress(addr)) => {
jdebug!(msg = "NewAddress", addr = format!("{:?}", addr));
}
Ok(NetInfoMessage::DelAddress(addr)) => {
jdebug!(msg = "DelAddress", addr = format!("{:?}", addr));
}
Ok(NetInfoMessage::NewLink(link)) => {
jdebug!(msg = "NewLink", link = format!("{:?}", link));
}
Ok(NetInfoMessage::DelLink(link)) => {
jdebug!(msg = "DelLink", link = format!("{:?}", link));
}
Ok(NetInfoMessage::NoInfo) => {
jdebug!(msg = "NoInfo");
}
Ok(NetInfoMessage::InvalidReq) => {
jdebug!(msg = "InvalidReq");
}
Err(e) => {
jerror!("{:?}", e);
}
}
}
Ok(Err(e)) => jwarn!("Invalid C string : {}", e),
Err(e) => jwarn!("Invalid string : {}", e),
}
}
_ => {
jdebug!("Unexpected message");
}
}
}
});
Ok(handler)
}sourcepub fn add(&mut self, ip: IpNetwork)
pub fn add(&mut self, ip: IpNetwork)
Examples found in repository?
src/client.rs (line 189)
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
pub fn run(
name: Option<&'static str>,
sender: Sender<Option<String>>,
ifname: Option<String>,
) -> Result<JoinHandle<Result<(), RnetmgrConError>>, RnetmgrConError> {
let handler = std::thread::spawn(move || -> Result<(), RnetmgrConError> {
let mut netinfo_hash = HashMap::<String, NetInfoReport>::new();
let ih = Ipcon::new(name, Some(IPF_SND_IF | IPF_RCV_IF))
.change_context(RnetmgrConError::IpconError)?;
ih.join_group(ipcon::IPCON_KERNEL_NAME, ipcon::IPCON_KERNEL_GROUP_NAME)
.change_context(RnetmgrConError::IpconError)?;
let netif_str = ifname.as_deref().unwrap_or("eth0");
let req_msg = NetInfoReqMessage::ReqAddress(netif_str.to_owned());
let try_send_request = || -> Result<(), RnetmgrConError> {
ih.join_group(NETINFO_IPCON, NETINFO_IPCON_GROUP)
.change_context(RnetmgrConError::IpconError)?;
jdebug!("joined {}@{} group", NETINFO_IPCON_GROUP, NETINFO_IPCON);
let buf = serde_json::to_string(&req_msg)
.into_report()
.change_context(RnetmgrConError::InvalidData)?;
let c_buf = CString::new(buf)
.into_report()
.change_context(RnetmgrConError::InvalidData)?;
jdebug!("send request: {:?}", req_msg);
ih.send_unicast_msg(NETINFO_IPCON, c_buf.as_bytes())
.change_context(RnetmgrConError::IpconError)
};
let _ = try_send_request();
loop {
jdebug!("Wait message");
let msg = ih
.receive_msg()
.change_context(RnetmgrConError::IpconError)?;
match msg {
IpconMsg::IpconMsgKevent(kevent) => {
if let Some((p, g)) = kevent.group_added() {
if (NETINFO_IPCON == p) && (NETINFO_IPCON_GROUP == g) {
jdebug!(
"{}@{} added, send request.",
NETINFO_IPCON_GROUP,
NETINFO_IPCON
);
let _ = try_send_request();
}
continue;
}
if let Some((p, g)) = kevent.group_removed() {
if (NETINFO_IPCON == p) && (NETINFO_IPCON_GROUP == g) {
jdebug!("{}@{} removed", NETINFO_IPCON_GROUP, NETINFO_IPCON);
netinfo_hash.clear();
sender
.send(None)
.into_report()
.change_context(RnetmgrConError::IpconError)?;
}
continue;
}
}
IpconMsg::IpconMsgUser(m)
if matches!(m.msg_type, IpconMsgType::IpconMsgTypeGroup) =>
{
let group = m.group.unwrap();
jdebug!(msg = "GroupMsg", peer = m.peer, group = group);
if (NETINFO_IPCON == m.peer) && (NETINFO_IPCON_GROUP == group) {
let c_str = CStr::from_bytes_with_nul(&m.buf).map(|a| a.to_str());
match c_str {
Ok(Ok(s)) => match serde_json::from_str::<NetInfoMessage>(s) {
Ok(NetInfoMessage::NewAddress(addr))
if addr.ifname.eq(netif_str) =>
{
let nim = netinfo_hash
.entry(netif_str.to_owned())
.or_insert_with(|| {
NetInfoReport::new(netif_str.to_owned())
});
nim.add(addr.ipv4addr);
sender
.send(nim.get())
.into_report()
.change_context(RnetmgrConError::IOError)?;
}
Ok(NetInfoMessage::DelAddress(addr))
if addr.ifname.eq(netif_str) =>
{
let nim = netinfo_hash
.entry(netif_str.to_owned())
.or_insert_with(|| {
NetInfoReport::new(netif_str.to_owned())
});
nim.del(addr.ipv4addr);
sender
.send(nim.get())
.into_report()
.change_context(RnetmgrConError::IOError)?;
}
_ => {}
},
Ok(Err(e)) => jwarn!("Invalid C string : {}", e),
Err(e) => jwarn!("Invalid string: {}", e),
}
}
}
IpconMsg::IpconMsgUser(m)
if matches!(m.msg_type, IpconMsgType::IpconMsgTypeNormal)
&& (NETINFO_IPCON == m.peer) =>
{
jdebug!(msg = "UsrMsg", peer = m.peer, buf_size = m.buf.len());
let c_str = CStr::from_bytes_with_nul(&m.buf).map(|a| a.to_str());
match c_str {
Ok(Ok(s)) => {
jdebug!("json: {}", s);
match serde_json::from_str::<NetInfoMessage>(s) {
Ok(NetInfoMessage::NewAddress(addr))
if addr.ifname.eq(netif_str) =>
{
let nim = netinfo_hash
.entry(netif_str.to_owned())
.or_insert_with(|| {
NetInfoReport::new(netif_str.to_owned())
});
nim.add(addr.ipv4addr);
sender
.send(nim.get())
.into_report()
.change_context(RnetmgrConError::IOError)?;
}
Ok(NetInfoMessage::NewAddress(addr)) => {
jdebug!(msg = "NewAddress", addr = format!("{:?}", addr));
}
Ok(NetInfoMessage::DelAddress(addr)) => {
jdebug!(msg = "DelAddress", addr = format!("{:?}", addr));
}
Ok(NetInfoMessage::NewLink(link)) => {
jdebug!(msg = "NewLink", link = format!("{:?}", link));
}
Ok(NetInfoMessage::DelLink(link)) => {
jdebug!(msg = "DelLink", link = format!("{:?}", link));
}
Ok(NetInfoMessage::NoInfo) => {
jdebug!(msg = "NoInfo");
}
Ok(NetInfoMessage::InvalidReq) => {
jdebug!(msg = "InvalidReq");
}
Err(e) => {
jerror!("{:?}", e);
}
}
}
Ok(Err(e)) => jwarn!("Invalid C string : {}", e),
Err(e) => jwarn!("Invalid string : {}", e),
}
}
_ => {
jdebug!("Unexpected message");
}
}
}
});
Ok(handler)
}sourcepub fn del(&mut self, ip: IpNetwork)
pub fn del(&mut self, ip: IpNetwork)
Examples found in repository?
src/client.rs (line 206)
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
pub fn run(
name: Option<&'static str>,
sender: Sender<Option<String>>,
ifname: Option<String>,
) -> Result<JoinHandle<Result<(), RnetmgrConError>>, RnetmgrConError> {
let handler = std::thread::spawn(move || -> Result<(), RnetmgrConError> {
let mut netinfo_hash = HashMap::<String, NetInfoReport>::new();
let ih = Ipcon::new(name, Some(IPF_SND_IF | IPF_RCV_IF))
.change_context(RnetmgrConError::IpconError)?;
ih.join_group(ipcon::IPCON_KERNEL_NAME, ipcon::IPCON_KERNEL_GROUP_NAME)
.change_context(RnetmgrConError::IpconError)?;
let netif_str = ifname.as_deref().unwrap_or("eth0");
let req_msg = NetInfoReqMessage::ReqAddress(netif_str.to_owned());
let try_send_request = || -> Result<(), RnetmgrConError> {
ih.join_group(NETINFO_IPCON, NETINFO_IPCON_GROUP)
.change_context(RnetmgrConError::IpconError)?;
jdebug!("joined {}@{} group", NETINFO_IPCON_GROUP, NETINFO_IPCON);
let buf = serde_json::to_string(&req_msg)
.into_report()
.change_context(RnetmgrConError::InvalidData)?;
let c_buf = CString::new(buf)
.into_report()
.change_context(RnetmgrConError::InvalidData)?;
jdebug!("send request: {:?}", req_msg);
ih.send_unicast_msg(NETINFO_IPCON, c_buf.as_bytes())
.change_context(RnetmgrConError::IpconError)
};
let _ = try_send_request();
loop {
jdebug!("Wait message");
let msg = ih
.receive_msg()
.change_context(RnetmgrConError::IpconError)?;
match msg {
IpconMsg::IpconMsgKevent(kevent) => {
if let Some((p, g)) = kevent.group_added() {
if (NETINFO_IPCON == p) && (NETINFO_IPCON_GROUP == g) {
jdebug!(
"{}@{} added, send request.",
NETINFO_IPCON_GROUP,
NETINFO_IPCON
);
let _ = try_send_request();
}
continue;
}
if let Some((p, g)) = kevent.group_removed() {
if (NETINFO_IPCON == p) && (NETINFO_IPCON_GROUP == g) {
jdebug!("{}@{} removed", NETINFO_IPCON_GROUP, NETINFO_IPCON);
netinfo_hash.clear();
sender
.send(None)
.into_report()
.change_context(RnetmgrConError::IpconError)?;
}
continue;
}
}
IpconMsg::IpconMsgUser(m)
if matches!(m.msg_type, IpconMsgType::IpconMsgTypeGroup) =>
{
let group = m.group.unwrap();
jdebug!(msg = "GroupMsg", peer = m.peer, group = group);
if (NETINFO_IPCON == m.peer) && (NETINFO_IPCON_GROUP == group) {
let c_str = CStr::from_bytes_with_nul(&m.buf).map(|a| a.to_str());
match c_str {
Ok(Ok(s)) => match serde_json::from_str::<NetInfoMessage>(s) {
Ok(NetInfoMessage::NewAddress(addr))
if addr.ifname.eq(netif_str) =>
{
let nim = netinfo_hash
.entry(netif_str.to_owned())
.or_insert_with(|| {
NetInfoReport::new(netif_str.to_owned())
});
nim.add(addr.ipv4addr);
sender
.send(nim.get())
.into_report()
.change_context(RnetmgrConError::IOError)?;
}
Ok(NetInfoMessage::DelAddress(addr))
if addr.ifname.eq(netif_str) =>
{
let nim = netinfo_hash
.entry(netif_str.to_owned())
.or_insert_with(|| {
NetInfoReport::new(netif_str.to_owned())
});
nim.del(addr.ipv4addr);
sender
.send(nim.get())
.into_report()
.change_context(RnetmgrConError::IOError)?;
}
_ => {}
},
Ok(Err(e)) => jwarn!("Invalid C string : {}", e),
Err(e) => jwarn!("Invalid string: {}", e),
}
}
}
IpconMsg::IpconMsgUser(m)
if matches!(m.msg_type, IpconMsgType::IpconMsgTypeNormal)
&& (NETINFO_IPCON == m.peer) =>
{
jdebug!(msg = "UsrMsg", peer = m.peer, buf_size = m.buf.len());
let c_str = CStr::from_bytes_with_nul(&m.buf).map(|a| a.to_str());
match c_str {
Ok(Ok(s)) => {
jdebug!("json: {}", s);
match serde_json::from_str::<NetInfoMessage>(s) {
Ok(NetInfoMessage::NewAddress(addr))
if addr.ifname.eq(netif_str) =>
{
let nim = netinfo_hash
.entry(netif_str.to_owned())
.or_insert_with(|| {
NetInfoReport::new(netif_str.to_owned())
});
nim.add(addr.ipv4addr);
sender
.send(nim.get())
.into_report()
.change_context(RnetmgrConError::IOError)?;
}
Ok(NetInfoMessage::NewAddress(addr)) => {
jdebug!(msg = "NewAddress", addr = format!("{:?}", addr));
}
Ok(NetInfoMessage::DelAddress(addr)) => {
jdebug!(msg = "DelAddress", addr = format!("{:?}", addr));
}
Ok(NetInfoMessage::NewLink(link)) => {
jdebug!(msg = "NewLink", link = format!("{:?}", link));
}
Ok(NetInfoMessage::DelLink(link)) => {
jdebug!(msg = "DelLink", link = format!("{:?}", link));
}
Ok(NetInfoMessage::NoInfo) => {
jdebug!(msg = "NoInfo");
}
Ok(NetInfoMessage::InvalidReq) => {
jdebug!(msg = "InvalidReq");
}
Err(e) => {
jerror!("{:?}", e);
}
}
}
Ok(Err(e)) => jwarn!("Invalid C string : {}", e),
Err(e) => jwarn!("Invalid string : {}", e),
}
}
_ => {
jdebug!("Unexpected message");
}
}
}
});
Ok(handler)
}sourcepub fn get(&self) -> Option<String>
pub fn get(&self) -> Option<String>
Examples found in repository?
src/client.rs (line 192)
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
pub fn run(
name: Option<&'static str>,
sender: Sender<Option<String>>,
ifname: Option<String>,
) -> Result<JoinHandle<Result<(), RnetmgrConError>>, RnetmgrConError> {
let handler = std::thread::spawn(move || -> Result<(), RnetmgrConError> {
let mut netinfo_hash = HashMap::<String, NetInfoReport>::new();
let ih = Ipcon::new(name, Some(IPF_SND_IF | IPF_RCV_IF))
.change_context(RnetmgrConError::IpconError)?;
ih.join_group(ipcon::IPCON_KERNEL_NAME, ipcon::IPCON_KERNEL_GROUP_NAME)
.change_context(RnetmgrConError::IpconError)?;
let netif_str = ifname.as_deref().unwrap_or("eth0");
let req_msg = NetInfoReqMessage::ReqAddress(netif_str.to_owned());
let try_send_request = || -> Result<(), RnetmgrConError> {
ih.join_group(NETINFO_IPCON, NETINFO_IPCON_GROUP)
.change_context(RnetmgrConError::IpconError)?;
jdebug!("joined {}@{} group", NETINFO_IPCON_GROUP, NETINFO_IPCON);
let buf = serde_json::to_string(&req_msg)
.into_report()
.change_context(RnetmgrConError::InvalidData)?;
let c_buf = CString::new(buf)
.into_report()
.change_context(RnetmgrConError::InvalidData)?;
jdebug!("send request: {:?}", req_msg);
ih.send_unicast_msg(NETINFO_IPCON, c_buf.as_bytes())
.change_context(RnetmgrConError::IpconError)
};
let _ = try_send_request();
loop {
jdebug!("Wait message");
let msg = ih
.receive_msg()
.change_context(RnetmgrConError::IpconError)?;
match msg {
IpconMsg::IpconMsgKevent(kevent) => {
if let Some((p, g)) = kevent.group_added() {
if (NETINFO_IPCON == p) && (NETINFO_IPCON_GROUP == g) {
jdebug!(
"{}@{} added, send request.",
NETINFO_IPCON_GROUP,
NETINFO_IPCON
);
let _ = try_send_request();
}
continue;
}
if let Some((p, g)) = kevent.group_removed() {
if (NETINFO_IPCON == p) && (NETINFO_IPCON_GROUP == g) {
jdebug!("{}@{} removed", NETINFO_IPCON_GROUP, NETINFO_IPCON);
netinfo_hash.clear();
sender
.send(None)
.into_report()
.change_context(RnetmgrConError::IpconError)?;
}
continue;
}
}
IpconMsg::IpconMsgUser(m)
if matches!(m.msg_type, IpconMsgType::IpconMsgTypeGroup) =>
{
let group = m.group.unwrap();
jdebug!(msg = "GroupMsg", peer = m.peer, group = group);
if (NETINFO_IPCON == m.peer) && (NETINFO_IPCON_GROUP == group) {
let c_str = CStr::from_bytes_with_nul(&m.buf).map(|a| a.to_str());
match c_str {
Ok(Ok(s)) => match serde_json::from_str::<NetInfoMessage>(s) {
Ok(NetInfoMessage::NewAddress(addr))
if addr.ifname.eq(netif_str) =>
{
let nim = netinfo_hash
.entry(netif_str.to_owned())
.or_insert_with(|| {
NetInfoReport::new(netif_str.to_owned())
});
nim.add(addr.ipv4addr);
sender
.send(nim.get())
.into_report()
.change_context(RnetmgrConError::IOError)?;
}
Ok(NetInfoMessage::DelAddress(addr))
if addr.ifname.eq(netif_str) =>
{
let nim = netinfo_hash
.entry(netif_str.to_owned())
.or_insert_with(|| {
NetInfoReport::new(netif_str.to_owned())
});
nim.del(addr.ipv4addr);
sender
.send(nim.get())
.into_report()
.change_context(RnetmgrConError::IOError)?;
}
_ => {}
},
Ok(Err(e)) => jwarn!("Invalid C string : {}", e),
Err(e) => jwarn!("Invalid string: {}", e),
}
}
}
IpconMsg::IpconMsgUser(m)
if matches!(m.msg_type, IpconMsgType::IpconMsgTypeNormal)
&& (NETINFO_IPCON == m.peer) =>
{
jdebug!(msg = "UsrMsg", peer = m.peer, buf_size = m.buf.len());
let c_str = CStr::from_bytes_with_nul(&m.buf).map(|a| a.to_str());
match c_str {
Ok(Ok(s)) => {
jdebug!("json: {}", s);
match serde_json::from_str::<NetInfoMessage>(s) {
Ok(NetInfoMessage::NewAddress(addr))
if addr.ifname.eq(netif_str) =>
{
let nim = netinfo_hash
.entry(netif_str.to_owned())
.or_insert_with(|| {
NetInfoReport::new(netif_str.to_owned())
});
nim.add(addr.ipv4addr);
sender
.send(nim.get())
.into_report()
.change_context(RnetmgrConError::IOError)?;
}
Ok(NetInfoMessage::NewAddress(addr)) => {
jdebug!(msg = "NewAddress", addr = format!("{:?}", addr));
}
Ok(NetInfoMessage::DelAddress(addr)) => {
jdebug!(msg = "DelAddress", addr = format!("{:?}", addr));
}
Ok(NetInfoMessage::NewLink(link)) => {
jdebug!(msg = "NewLink", link = format!("{:?}", link));
}
Ok(NetInfoMessage::DelLink(link)) => {
jdebug!(msg = "DelLink", link = format!("{:?}", link));
}
Ok(NetInfoMessage::NoInfo) => {
jdebug!(msg = "NoInfo");
}
Ok(NetInfoMessage::InvalidReq) => {
jdebug!(msg = "InvalidReq");
}
Err(e) => {
jerror!("{:?}", e);
}
}
}
Ok(Err(e)) => jwarn!("Invalid C string : {}", e),
Err(e) => jwarn!("Invalid string : {}", e),
}
}
_ => {
jdebug!("Unexpected message");
}
}
}
});
Ok(handler)
}pub fn if_name(&self) -> &str
Auto Trait Implementations§
impl RefUnwindSafe for NetInfoReport
impl Send for NetInfoReport
impl Sync for NetInfoReport
impl Unpin for NetInfoReport
impl UnwindSafe for NetInfoReport
Blanket Implementations§
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Set the foreground color generically Read more
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Set the background color generically. Read more
§fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
Change the background color to yellow
§fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
Change the foreground color to magenta
§fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
Change the background color to magenta
§fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
Change the background color to purple
§fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
Change the foreground color to the terminal default
§fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
Change the background color to the terminal default
§fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
Change the foreground color to bright black
§fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
Change the background color to bright black
§fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
Change the foreground color to bright red
§fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
Change the background color to bright red
§fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
Change the foreground color to bright green
§fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
Change the background color to bright green
§fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
Change the foreground color to bright yellow
§fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
Change the background color to bright yellow
§fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
Change the foreground color to bright blue
§fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
Change the background color to bright blue
§fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
Change the foreground color to bright magenta
§fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
Change the background color to bright magenta
§fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
Change the foreground color to bright purple
§fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
Change the background color to bright purple
§fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
Change the foreground color to bright cyan
§fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
Change the background color to bright cyan
§fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
Change the foreground color to bright white
§fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
Change the background color to bright white
§fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
Make the text blink (but fast!)
Hide the text
§fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
Cross out the text
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
Set the foreground color at runtime. Only use if you do not know which color will be used at
compile-time. If the color is constant, use either
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
Set the background color at runtime. Only use if you do not know what color to use at
compile-time. If the color is constant, use either
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more§fn fg_rgb<const R: u8, const G: u8, const B: u8>(
&self
) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>
fn fg_rgb<const R: u8, const G: u8, const B: u8>(
&self
) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>
Set the foreground color to a specific RGB value.
§fn bg_rgb<const R: u8, const G: u8, const B: u8>(
&self
) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>
fn bg_rgb<const R: u8, const G: u8, const B: u8>(
&self
) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>
Set the background color to a specific RGB value.
§fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>
fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>
Sets the foreground color to an RGB value.
§fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>
fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>
Sets the background color to an RGB value.
§fn if_supports_color<'a, Out, ApplyFn>(
&'a self,
stream: Stream,
apply: ApplyFn
) -> SupportsColorsDisplay<'a, Self, Out, ApplyFn>where
ApplyFn: Fn(&'a Self) -> Out,
fn if_supports_color<'a, Out, ApplyFn>(
&'a self,
stream: Stream,
apply: ApplyFn
) -> SupportsColorsDisplay<'a, Self, Out, ApplyFn>where
ApplyFn: Fn(&'a Self) -> Out,
Apply a given transformation function to all formatters if the given stream
supports at least basic ANSI colors, allowing you to conditionally apply
given styles/colors. Read more