From dac6774f824a2eca58d5b159213c25e5afda6e68 Mon Sep 17 00:00:00 2001 From: Jasper den Hertog Date: Sat, 8 Jun 2024 08:11:49 +0200 Subject: [PATCH] Add bincode derives --- Cargo.toml | 4 +++- src/bgp/aspath.rs | 4 ++++ src/bgp/communities.rs | 6 +++++ src/bgp/message/update.rs | 7 ++++++ src/bgp/message/update_builder.rs | 1 + src/bgp/nlri/afisafi.rs | 38 +++++++++++++++++++++++++++++++ src/bgp/nlri/common.rs | 2 ++ src/bgp/nlri/evpn.rs | 1 + src/bgp/nlri/flowspec.rs | 1 + src/bgp/nlri/mpls.rs | 2 ++ src/bgp/nlri/mpls_vpn.rs | 2 ++ src/bgp/nlri/nexthop.rs | 1 + src/bgp/nlri/routetarget.rs | 1 + src/bgp/nlri/vpls.rs | 1 + src/bgp/path_attributes.rs | 14 ++++++++++++ src/bgp/types.rs | 11 +++++++++ src/bgp/workshop/route.rs | 1 + src/bmp/message.rs | 8 +++++++ src/util/macros.rs | 1 + 19 files changed, 105 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 95815a7f..9e357fc8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,8 @@ keywords = ["routing", "bgp"] license = "BSD-3-Clause" [dependencies] -inetnum = { version = "0.1.0", features = ["arbitrary", "serde"] } +# inetnum = { version = "0.1.0", features = ["arbitrary", "serde"] } +inetnum = { path = "../inetnum", features = ["arbitrary", "serde", "bincode"] } arbitrary = { version = "1.3.1", optional = true, features = ["derive"] } bytes = { version = "1.2", optional = true } chrono = { version = "0.4.20", optional = true, default-features = false } @@ -22,6 +23,7 @@ octseq = { version = "0.4.0", optional = true, features = ["bytes"] } paste = { version = "1" } serde = { version = "1.0.165", optional = true, features = ["derive"] } tokio = { version = ">=1.24.2", optional = true, features = ["io-util", "macros", "net", "sync", "rt-multi-thread", "time"] } +bincode = { version = "2.0.0-rc.3", optional = true } [dev-dependencies] memmap2 = "0.9" diff --git a/src/bgp/aspath.rs b/src/bgp/aspath.rs index d4b6ebd1..d7e35401 100644 --- a/src/bgp/aspath.rs +++ b/src/bgp/aspath.rs @@ -63,6 +63,7 @@ pub trait SerializeForOperators: Serialize { /// #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[derive(Clone, Debug, Default, Eq, PartialEq, Hash)] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct HopPath { /// The hops in this HopPath. hops: Vec, @@ -803,6 +804,7 @@ impl<'a, Octs: Octets> Iterator for PathSegments<'a, Octs> { #[derive(Copy, Clone, Debug)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct Segment { stype: SegmentType, four_byte_asns: bool, @@ -1028,6 +1030,7 @@ impl fmt::Display for Segment { #[derive(Clone, Copy, Debug, Eq, PartialEq)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub enum SegmentType { Set, Sequence, @@ -1087,6 +1090,7 @@ impl fmt::Display for SegmentType { #[derive(Copy, Clone, Debug)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub enum Hop { Asn(Asn), Segment(Segment), diff --git a/src/bgp/communities.rs b/src/bgp/communities.rs index 26803cd0..bcb128f5 100644 --- a/src/bgp/communities.rs +++ b/src/bgp/communities.rs @@ -113,6 +113,7 @@ pub trait SerializeForOperators: Serialize { /// Standard and Extended/Large Communities variants. #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, )] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub enum Community { Standard(StandardCommunity), Extended(ExtendedCommunity), @@ -260,6 +261,7 @@ impl Display for Community { /// serializing our Community type and in turn the contained routecore /// Community type and its children. #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, )] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct HumanReadableCommunity(pub Community); impl From for HumanReadableCommunity { @@ -484,6 +486,7 @@ wellknown!(Wellknown, #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd )] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct StandardCommunity(pub(crate) [u8; 4]); impl StandardCommunity { @@ -754,6 +757,7 @@ impl Display for Tag { #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd )] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct ExtendedCommunity([u8; 8]); impl ExtendedCommunity { @@ -1313,6 +1317,7 @@ impl SerializeForOperators for ExtendedCommunity { #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd )] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct Ipv6ExtendedCommunity([u8; 20]); @@ -1442,6 +1447,7 @@ impl Display for Ipv6ExtendedCommunity { #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd )] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct LargeCommunity([u8; 12]); impl LargeCommunity { diff --git a/src/bgp/message/update.rs b/src/bgp/message/update.rs index fadabfe8..d2623220 100644 --- a/src/bgp/message/update.rs +++ b/src/bgp/message/update.rs @@ -34,6 +34,7 @@ use crate::util::parser::ParseError; /// BGP UPDATE message, variant of the [`Message`] enum. #[derive(Clone, Debug, Eq, Hash, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct UpdateMessage { octets: Octs, withdrawals: Range, @@ -1053,6 +1054,7 @@ impl UpdateMessage { #[derive(Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct SessionConfig { four_octet_asns: FourOctetAsns, ipv4unicast_in_mp: Ipv4UnicastInMp, @@ -1067,6 +1069,7 @@ pub struct SessionConfig { #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct PduParseInfo { four_octet_asns: FourOctetAsns, pdu_addpaths: PduAddpaths, @@ -1163,6 +1166,7 @@ impl Default for PduParseInfo { #[derive(Copy, Clone, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] struct PduAddpaths { conventional: bool, mp_reach: bool, @@ -1193,6 +1197,7 @@ impl PduAddpaths { #[derive(Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] struct SessionAddpaths(HashMap); impl SessionAddpaths { fn new() -> Self { @@ -1304,6 +1309,7 @@ impl SessionConfig { #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct FourOctetAsns(pub bool); /// Indicates whether Ipv4Unicast NLRI are carried in the MP attribute. @@ -1315,6 +1321,7 @@ pub struct FourOctetAsns(pub bool); #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct Ipv4UnicastInMp(pub bool); /// Iterator for BGP UPDATE Communities. diff --git a/src/bgp/message/update_builder.rs b/src/bgp/message/update_builder.rs index 5e34dfbb..06c8571f 100644 --- a/src/bgp/message/update_builder.rs +++ b/src/bgp/message/update_builder.rs @@ -1201,6 +1201,7 @@ impl MpUnreachNlriBuilder { #[derive(Clone, Debug, Eq, Hash, PartialEq)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct StandardCommunitiesList { communities: Vec, len: usize, // size of value, excluding path attribute flags+type_code+len diff --git a/src/bgp/nlri/afisafi.rs b/src/bgp/nlri/afisafi.rs index 81d900c7..0e5abc12 100644 --- a/src/bgp/nlri/afisafi.rs +++ b/src/bgp/nlri/afisafi.rs @@ -47,6 +47,7 @@ macro_rules! addpath { #[derive(Copy, Clone, Debug, Hash, PartialEq, Ord, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] + #[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct [<$nlri AddpathNlri>](PathId, [<$nlri Nlri>]); impl AfiSafiNlri for [<$nlri AddpathNlri>] { type Nlri = <[<$nlri Nlri>] as AfiSafiNlri>::Nlri; @@ -64,6 +65,7 @@ macro_rules! addpath { #[derive(Clone, Debug, Hash)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] + #[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct [<$nlri AddpathNlri>]<$gen>(PathId, [<$nlri Nlri>]<$gen>); impl<$gen> AfiSafiNlri for [<$nlri AddpathNlri>]<$gen> { type Nlri = <[<$nlri Nlri>]<$gen> as AfiSafiNlri>::Nlri; @@ -170,6 +172,7 @@ paste! { #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] + #[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub enum AfiSafiType { $( $( [<$afi_name $safi_name>] ,)+)+ Unsupported(u16, u8), @@ -331,6 +334,7 @@ paste! { #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] + #[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub enum NlriType { $($( [<$afi_name $safi_name>], @@ -518,6 +522,27 @@ impl Nlri<&[u8]> { } } +#[cfg(feature = "bincode")] +impl bincode::Encode for Nlri { + fn encode(&self, encoder: &mut E) -> Result<(), bincode::error::EncodeError> { + todo!() + } +} + +#[cfg(feature = "bincode")] +impl bincode::Decode for Nlri { + fn decode(decoder: &mut D) -> Result { + todo!() + } +} + +#[cfg(feature = "bincode")] +impl<'de, Octs: Octets> bincode::BorrowDecode<'de> for Nlri { + fn borrow_decode>(decoder: &mut D) -> Result { + todo!() + } +} + //------------ Traits --------------------------------------------------------- /// A type characterized by an AFI and SAFI. @@ -640,6 +665,7 @@ afisafi! { #[derive(Copy, Clone, Debug, Hash, PartialEq, Ord, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct Ipv4UnicastNlri(Prefix); impl AfiSafiNlri for Ipv4UnicastNlri { @@ -708,6 +734,7 @@ impl NlriCompose for Ipv4UnicastNlri { #[derive(Copy, Clone, Debug, Hash, PartialEq, Ord, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct Ipv4MulticastNlri(Prefix); impl AfiSafiNlri for Ipv4MulticastNlri { @@ -775,6 +802,7 @@ impl NlriCompose for Ipv4MulticastNlri { #[derive(Copy, Clone, Debug, Hash)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct Ipv4MplsUnicastNlri(MplsNlri); impl AfiSafiNlri for Ipv4MplsUnicastNlri { @@ -850,6 +878,7 @@ impl> Ord for Ipv4MplsUnicastNlri { #[derive(Copy, Clone, Debug, Hash)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct Ipv4MplsVpnUnicastNlri(MplsVpnNlri); impl AfiSafiNlri for Ipv4MplsVpnUnicastNlri { @@ -924,6 +953,7 @@ impl> Ord for Ipv4MplsVpnUnicastNlri { #[derive(Clone, Debug, Hash)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct Ipv4RouteTargetNlri(RouteTargetNlri); impl AfiSafiNlri for Ipv4RouteTargetNlri { @@ -996,6 +1026,7 @@ impl> Ord for Ipv4RouteTargetNlri { #[derive(Clone, Debug, Hash)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct Ipv4FlowSpecNlri(FlowSpecNlri); impl AfiSafiNlri for Ipv4FlowSpecNlri { @@ -1082,6 +1113,7 @@ impl> Ord for Ipv4FlowSpecNlri { #[derive(Copy, Clone, Debug, Hash, PartialEq, Ord, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct Ipv6UnicastNlri(Prefix); impl AfiSafiNlri for Ipv6UnicastNlri { type Nlri = Prefix; @@ -1148,6 +1180,7 @@ impl NlriCompose for Ipv6UnicastNlri { #[derive(Copy, Clone, Debug, Hash, PartialEq, Ord, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct Ipv6MulticastNlri(Prefix); impl FromStr for Ipv6MulticastNlri { @@ -1215,6 +1248,7 @@ impl NlriCompose for Ipv6MulticastNlri { #[derive(Copy, Clone, Debug, Hash)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct Ipv6MplsUnicastNlri(MplsNlri); impl AfiSafiNlri for Ipv6MplsUnicastNlri { @@ -1291,6 +1325,7 @@ impl> Ord for Ipv6MplsUnicastNlri { #[derive(Clone, Debug, Hash)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct Ipv6MplsVpnUnicastNlri(MplsVpnNlri); impl AfiSafiNlri for Ipv6MplsVpnUnicastNlri { @@ -1366,6 +1401,7 @@ impl> Ord for Ipv6MplsVpnUnicastNlri { #[derive(Clone, Debug, Hash)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct Ipv6FlowSpecNlri(FlowSpecNlri); impl AfiSafiNlri for Ipv6FlowSpecNlri { @@ -1474,6 +1510,7 @@ impl Ipv4MplsUnicastNlri { #[derive(Copy, Clone, Debug, Hash, PartialEq, Ord, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct L2VpnVplsNlri(VplsNlri); impl AfiSafiNlri for L2VpnVplsNlri { @@ -1514,6 +1551,7 @@ impl NlriCompose for L2VpnVplsNlri { #[derive(Clone, Debug, Hash)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct L2VpnEvpnNlri(EvpnNlri); impl AfiSafiNlri for L2VpnEvpnNlri { diff --git a/src/bgp/nlri/common.rs b/src/bgp/nlri/common.rs index e05295b8..efecce75 100644 --- a/src/bgp/nlri/common.rs +++ b/src/bgp/nlri/common.rs @@ -1,5 +1,6 @@ use octseq::{Octets, OctetsBuilder, Parser}; +use bincode::{Decode, Encode}; use crate::util::parser::ParseError; use inetnum::addr::Prefix; use super::afisafi::Afi; @@ -12,6 +13,7 @@ use std::fmt; /// /// Used in all AddpathNlri variants. #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] +#[cfg_attr(feature = "bincode", derive(Decode,Encode))] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct PathId(pub u32); diff --git a/src/bgp/nlri/evpn.rs b/src/bgp/nlri/evpn.rs index c2b238d5..7569641c 100644 --- a/src/bgp/nlri/evpn.rs +++ b/src/bgp/nlri/evpn.rs @@ -25,6 +25,7 @@ typeenum!( #[derive(Copy, Clone, Debug, Hash)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct EvpnNlri { #[allow(dead_code)] route_type: EvpnRouteType, diff --git a/src/bgp/nlri/flowspec.rs b/src/bgp/nlri/flowspec.rs index 3bd17ef3..ae6cafaf 100644 --- a/src/bgp/nlri/flowspec.rs +++ b/src/bgp/nlri/flowspec.rs @@ -14,6 +14,7 @@ use super::afisafi::Afi; #[derive(Copy, Clone, Debug, Hash)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct FlowSpecNlri { #[allow(dead_code)] afi: Afi, diff --git a/src/bgp/nlri/mpls.rs b/src/bgp/nlri/mpls.rs index 619df957..3dbb7f71 100644 --- a/src/bgp/nlri/mpls.rs +++ b/src/bgp/nlri/mpls.rs @@ -12,6 +12,7 @@ use super::afisafi::Afi; #[derive(Copy, Clone, Debug, Hash)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct MplsNlri { prefix: Prefix, labels: Labels, @@ -150,6 +151,7 @@ impl OctetsFrom> for MplsNlri #[derive(Copy, Clone, Debug, Hash)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct Labels { octets: Octs } diff --git a/src/bgp/nlri/mpls_vpn.rs b/src/bgp/nlri/mpls_vpn.rs index f177f28a..219e4773 100644 --- a/src/bgp/nlri/mpls_vpn.rs +++ b/src/bgp/nlri/mpls_vpn.rs @@ -17,6 +17,7 @@ use super::mpls::Labels; #[derive(Copy, Clone, Debug, Hash)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct MplsVpnNlri { prefix: Prefix, labels: Labels, @@ -148,6 +149,7 @@ impl fmt::Display for MplsVpnNlri { #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct RouteDistinguisher { bytes: [u8; 8] } diff --git a/src/bgp/nlri/nexthop.rs b/src/bgp/nlri/nexthop.rs index 595b80af..d4483bc0 100644 --- a/src/bgp/nlri/nexthop.rs +++ b/src/bgp/nlri/nexthop.rs @@ -12,6 +12,7 @@ use super::afisafi::AfiSafiType as AfiSafi; /// Conventional and BGP-MP Next Hop variants. #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub enum NextHop { Unicast(IpAddr), Multicast(IpAddr), diff --git a/src/bgp/nlri/routetarget.rs b/src/bgp/nlri/routetarget.rs index 163ce46d..bf9dbe15 100644 --- a/src/bgp/nlri/routetarget.rs +++ b/src/bgp/nlri/routetarget.rs @@ -10,6 +10,7 @@ use super::common::prefix_bits_to_bytes; #[derive(Clone, Debug, Hash)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct RouteTargetNlri { raw: Octs } diff --git a/src/bgp/nlri/vpls.rs b/src/bgp/nlri/vpls.rs index cca2f3c4..d8acfc4e 100644 --- a/src/bgp/nlri/vpls.rs +++ b/src/bgp/nlri/vpls.rs @@ -9,6 +9,7 @@ use super::mpls_vpn::RouteDistinguisher; #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Ord, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct VplsNlri { rd: RouteDistinguisher, ve_id: u16, diff --git a/src/bgp/path_attributes.rs b/src/bgp/path_attributes.rs index 8cb3b454..13d944ea 100644 --- a/src/bgp/path_attributes.rs +++ b/src/bgp/path_attributes.rs @@ -24,6 +24,7 @@ use crate::util::parser::{ParseError, parse_ipv4addr}; #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Ord, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct Flags(u8); impl core::ops::BitOr for Flags { @@ -105,6 +106,7 @@ pub type AttributesMap = BTreeMap; #[derive(Debug, Clone, Default, Eq, PartialEq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct PaMap { attributes: AttributesMap, } @@ -320,6 +322,8 @@ macro_rules! path_attributes { #[derive(Clone, Debug, Eq, Hash, PartialEq)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize))] + #[cfg_attr(feature = "bincode", derive(bincode::Decode, + bincode::Encode))] pub enum PathAttribute { $( $name($data) ),+, Unimplemented(UnimplementedPathAttribute), @@ -744,6 +748,7 @@ impl Default for PathAttribute { #[derive(Clone, Debug, Eq, Hash, PartialEq)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct UnimplementedPathAttribute { flags: Flags, type_code: u8, @@ -1174,6 +1179,7 @@ impl Display for crate::bgp::types::AtomicAggregate { #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct AggregatorInfo { asn: Asn, address: Ipv4Addr, @@ -1325,6 +1331,7 @@ impl Attribute for crate::bgp::types::OriginatorId { #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct BgpIdentifier([u8; 4]); impl From<[u8; 4]> for BgpIdentifier { @@ -1342,6 +1349,7 @@ impl From for [u8; 4] { #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct ClusterIds { cluster_ids: Vec } @@ -1700,6 +1708,7 @@ use crate::bgp::communities::ExtendedCommunity; #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct ExtendedCommunitiesList { communities: Vec } @@ -1874,6 +1883,7 @@ impl Attribute for crate::bgp::types::Connector { #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct AsPathLimitInfo { upper_bound: u8, attacher: Asn, @@ -1923,6 +1933,7 @@ use crate::bgp::communities::Ipv6ExtendedCommunity; #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct Ipv6ExtendedCommunitiesList { communities: Vec } @@ -1994,6 +2005,7 @@ use crate::bgp::communities::LargeCommunity; #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct LargeCommunitiesList { communities: Vec } @@ -2092,6 +2104,7 @@ impl Attribute for crate::bgp::types::Otc { #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct AttributeSet { origin: Asn, attributes: Vec, @@ -2147,6 +2160,7 @@ impl Attribute for AttributeSet { #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct ReservedRaw { raw: Vec, } diff --git a/src/bgp/types.rs b/src/bgp/types.rs index 25d0c11f..f224ef83 100644 --- a/src/bgp/types.rs +++ b/src/bgp/types.rs @@ -46,6 +46,7 @@ impl AddpathFamDir { #[derive(Clone, Copy, Debug, Hash, Eq, Ord, PartialEq, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub enum AddpathDirection { Receive = 1, Send = 2, @@ -150,6 +151,7 @@ typeenum!( #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct Origin(pub OriginType); impl From for Origin { @@ -168,6 +170,7 @@ impl std::fmt::Display for Origin { #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct MultiExitDisc(pub u32); impl std::fmt::Display for MultiExitDisc { @@ -180,6 +183,7 @@ impl std::fmt::Display for MultiExitDisc { #[derive(Debug, Eq, PartialEq, Clone, Copy, Hash)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct LocalPref(pub u32); impl From for u32 { @@ -198,12 +202,14 @@ impl std::fmt::Display for LocalPref { #[derive(Debug, Eq, PartialEq, Clone, Copy, Hash)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct AtomicAggregate; /// Wrapper for the 4 byte OnlyToCustomer (Otc) value in path attributes. #[derive(Debug, Eq, PartialEq, Clone, Copy, Hash)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct Otc(pub Asn); impl From for u32 { @@ -223,6 +229,7 @@ impl std::fmt::Display for Otc { #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct ConventionalNextHop(pub Ipv4Addr); impl std::fmt::Display for ConventionalNextHop { @@ -234,19 +241,23 @@ impl std::fmt::Display for ConventionalNextHop { #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct OriginatorId(pub Ipv4Addr); #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct Connector(pub Ipv4Addr); #[derive(Clone, Debug, Eq, Hash, PartialEq)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct As4Path(pub HopPath); #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct As4Aggregator(pub AggregatorInfo); diff --git a/src/bgp/workshop/route.rs b/src/bgp/workshop/route.rs index bec93105..82e34a06 100644 --- a/src/bgp/workshop/route.rs +++ b/src/bgp/workshop/route.rs @@ -85,6 +85,7 @@ impl From>> for PathAttribute { #[derive(Clone, Debug, Eq, Hash, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub struct RouteWorkshop(N, Option, PaMap); impl RouteWorkshop { diff --git a/src/bmp/message.rs b/src/bmp/message.rs index f0e199d9..e36e1e8a 100644 --- a/src/bmp/message.rs +++ b/src/bmp/message.rs @@ -61,6 +61,7 @@ impl Error for MessageError { } /// [`bgp::Message`](crate::bgp::Message)s. #[derive(Clone, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] pub enum Message> { RouteMonitoring(RouteMonitoring), StatisticsReport(StatisticsReport), @@ -552,6 +553,7 @@ typeenum!( /// Route Monitoring message. #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] #[derive(Clone, Debug, Eq, PartialEq)] pub struct RouteMonitoring> { @@ -604,6 +606,7 @@ impl RouteMonitoring { /// Statistics Report message. #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] #[derive(Clone, Eq, PartialEq)] pub struct StatisticsReport { octets: Octs, @@ -667,6 +670,7 @@ impl Debug for StatisticsReport { /// Peer Down Notification. #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] #[derive(Clone, Debug, Eq, PartialEq)] pub struct PeerDownNotification> { octets: Octets, @@ -776,6 +780,7 @@ impl PeerDownNotification { /// Peer Up Notification. #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] #[derive(Clone, Debug, Eq, PartialEq)] pub struct PeerUpNotification> { octets: Octets, @@ -1018,6 +1023,7 @@ impl PeerUpNotification { /// Initiation Message. #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] #[derive(Clone, Debug, Eq, PartialEq)] pub struct InitiationMessage> { octets: Octets, @@ -1059,6 +1065,7 @@ impl InitiationMessage { /// Termination message. #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] #[derive(Clone, Debug, Eq, PartialEq)] pub struct TerminationMessage> { octets: Octets, @@ -1105,6 +1112,7 @@ impl TerminationMessage { /// /// NB: Not well tested/supported at this moment! #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] #[derive(Clone, Debug, Eq, PartialEq)] pub struct RouteMirroring { octets: Octs, diff --git a/src/util/macros.rs b/src/util/macros.rs index 21e3d621..8ebd4ff5 100644 --- a/src/util/macros.rs +++ b/src/util/macros.rs @@ -64,6 +64,7 @@ macro_rules! typeenum { #[derive(Clone, Copy, Debug, Hash, Eq, Ord, PartialEq, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] + #[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))] $(#[$attr])* pub enum $name { $($y),+,