rpsl-parser

CI status Cargo version


An [RFC 2622] conformant Routing Policy Specification Language (RPSL) parser with a focus on speed and correctness.

โšก๏ธ Outperforms other parsers by a factor of 33-60x\ ๐Ÿ“ฐ Complete implementation for multiline RPSL values\ ๐Ÿ’ฌ Able to parse objects directly from whois server responses\ ๐Ÿง  Low memory footprint by leveraging zero-copy\ ๐Ÿงช Robust parsing of any valid input ensured by Property Based Tests\ ๐Ÿ Python usage is supported

[!WARNING] This project is still in early stages of development and its API is not yet stable.

Examples

Parsing RPSL

A string containing an object in RPSL notation can be parsed to a [rpsl::Object] struct using the [parserpslobject] function.

```rust,ignore use rpslparser::parserpsl_object;

let roleacme = " role: ACME Company address: Packet Street 6 address: 128 Series of Tubes address: Internet email: rpsl-parser@github.com nic-hdl: RPSL1-RIPE source: RIPE "; let parsed = parserpslobject(roleacme)?; ```

This returns an [rpsl::Object] consisting of multiple [rpsl::Attribute]s:

```rust,ignore println!("{:#?}", parsed);

Object( [ Attribute { name: "role", values: [Some("ACME Company",),], }, Attribute { name: "address", values: [Some("Packet Street 6",),], }, Attribute { name: "address", values: [Some("128 Series of Tubes",),], }, Attribute { name: "address", values: [Some("Internet",),], }, Attribute { name: "email", values: [Some("irrdb@github.com",),], }, Attribute { name: "nic-hdl", values: [Some("IRRD2-RIPE",),], }, Attribute { name: "source", values: [Some("RIPE",),], }, ], ) ```

Each [rpsl::Attribute] can be accessed by it's index and has a name and an optional set of values.

```rust,ignore println!("{:#?}", parsed[1]);

Attribute { name: "role", values: [Some("ACME Company",),], } ```

Since RPSL attribute values may be spread over multiple lines and values consisting only of whitespace are valid, the Vec<Option<String>> type is used to represent them. For more information and examples, please view the [parserpslobject] documentation.

Parsing a WHOIS server response

Whois servers often respond to queres with multiple objects. An example ARIN query for AS32934 will return with the requested ASNumber object first, followed by it's associated OrgName:

```sh $ whois -h whois.arin.net AS32934 ASNumber: 32934 ASName: FACEBOOK ASHandle: AS32934 RegDate: 2004-08-24 Updated: 2012-02-24 Comment: Please send abuse reports to abuse@facebook.com Ref: https://rdap.arin.net/registry/autnum/32934

OrgName: Facebook, Inc. OrgId: THEFA-3 Address: 1601 Willow Rd. City: Menlo Park StateProv: CA PostalCode: 94025 Country: US RegDate: 2004-08-11 Updated: 2012-04-17 Ref: https://rdap.arin.net/registry/entity/THEFA-3 ```

To extract each individual object, the [parsewhoisserver_response] function can be used to parse the response into a [rpsl::ObjectCollection] containing all objects within the response. Examples can be found in the function documentation.

Python bindings

To use this parser in Python, see the rpsl-parser PyPi Package.

๐Ÿšง Work in progress