flex_dns/rdata/
csync.rs

1use crate::{Buffer, DnsMessage, DnsMessageError, MutBuffer};
2use crate::characters::Characters;
3use crate::parse::Parse;
4use crate::rdata::{RData, RDataParse};
5use crate::write::WriteBytes;
6
7/// # Child-to-Parent Synchronization (CSYNC) Record
8/// This record type is used to publish the synchronization state of a child zone to its parent zone.
9#[derive(Copy, Clone, Debug, PartialEq)]
10pub struct CSync<'a> {
11    /// serial is the serial number of the zone
12    pub serial: u32,
13    /// flags is a bitmap of flags (see [RFC 7477](https://tools.ietf.org/html/rfc7477))
14    pub flags: u16,
15    /// type_bit_maps is the set of RRset types present at the next owner name in the zone
16    pub type_bit_maps: Characters<'a>,
17}
18
19impl<'a> RDataParse<'a> for CSync<'a> {
20    #[inline]
21    fn parse(rdata: &RData<'a>, i: &mut usize) -> Result<Self, DnsMessageError> {
22        let serial = u32::parse(rdata, i)?;
23        let flags = u16::parse(rdata, i)?;
24        let type_bit_maps = Characters::parse(rdata, i)?;
25
26        Ok(Self {
27            serial,
28            flags,
29            type_bit_maps
30        })
31    }
32}
33
34impl<'a> WriteBytes for CSync<'a> {
35    #[inline]
36    fn write<
37        const PTR_STORAGE: usize,
38        const DNS_SECTION: usize,
39        B: MutBuffer + Buffer,
40    >(&self, message: &mut DnsMessage<PTR_STORAGE, DNS_SECTION, B>) -> Result<usize, DnsMessageError> {
41        let mut bytes = 0;
42
43        bytes += self.serial.write(message)?;
44        bytes += self.flags.write(message)?;
45        bytes += self.type_bit_maps.write(message)?;
46
47        Ok(bytes)
48    }
49}
50
51#[cfg(test)]
52mod test {
53    use crate::rdata::testutils::parse_write_test;
54
55    use super::*;
56
57    parse_write_test!(
58        10,
59        [
60            0x00, 0x01, 0x02, 0x03, // serial
61            0x10, 0x01, // flags
62            3, b'w', b'w', b'w', // type_bit_maps
63        ],
64        CSync {
65            serial: 0x00010203,
66            flags: 0x1001,
67            type_bit_maps: unsafe { Characters::new_unchecked(b"www") },
68        },
69    );
70}