Git Product home page Git Product logo

rpsl-parser's Introduction

rpsl-parser


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 parse_rpsl_object function.

use rpsl_parser::parse_rpsl_object;

let role_acme = "
role:        ACME Company
address:     Packet Street 6
address:     128 Series of Tubes
address:     Internet
email:       [email protected]
nic-hdl:     RPSL1-RIPE
source:      RIPE
";
let parsed = parse_rpsl_object(role_acme)?;

This returns an rpsl::Object consisting of multiple rpsl::Attributes:

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("[email protected]",),],
    },
    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.

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 parse_rpsl_object 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:

$ 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 [email protected]
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 parse_whois_server_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

  • More descriptive error messages

    When invalid RPSL is parsed, the current error messages do not properly convey where exactly the error is located in the parsed text.

rpsl-parser's People

Contributors

srv6d avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.