M. Lawrence Weikum > BGPmon-core-1 > BGPmon::Filter

Download:
BGPmon-core-1-092.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  1
View/Report Bugs
Module Version: 1.092   Source  

NAME ^

BGPmon::Filter

This module provides information of if a BGP message matches a set of IPv4 or IPv6 prefixes, or if it matches a specific autonymous system number.

SYNOPSIS ^

use BGPmon::Filter;

if(BGPmon::Filter::init()){

        my $err_code = BGPmon::Filter::get_error_code('init');
        
        my $err_msg = BGPmon::Filter::get_error_msg('init');
        
        print "$err_code : $err_msg\n";
        
        exit 1;
}
if(BGPmon::Filter::parse_config_file('config_file.txt')){
        
        my $err_code = BGPmon::Filter::get_error_code('parse_config_file');
        
        my $err_msg = BGPmon::Filter::get_error_msg('parse_config_file');
        
        print "$err_code : $err_msg\n";
        
        exit 1;
}
my $xml4msg = '<BGP_MESSAGE length="00001140" version="0.4" xmlns="urn:ietf:pa

rams:xml:ns:xfb-0.4" type_value="2" type="UPDATE"><BGPMON_SEQ id="127893688" se

q_num="1541418969"/><TIME timestamp="1346459370" datetime="2012-09-01T00:29:30Z

" precision_time="0"/><PEERING as_num_len="2"><SRC_ADDR><ADDRESS>187.16.217.154

</ADDRESS><AFI value="1">IPV4</AFI></SRC_ADDR><SRC_PORT>179</SRC_PORT><SRC_AS>5

3175</SRC_AS><DST_ADDR><ADDRESS>200.160.6.217</ADDRESS><AFI value="1">IPV4</AFI

></DST_ADDR><DST_PORT>179</DST_PORT><DST_AS>6447</DST_AS><BGPID>0.0.0.0</BGPID>

</PEERING><ASCII_MSG length="31"><MARKER length="16">FFFFFFFFFFFFFFFFFFFFFFFFFF

FFFFF/MARKER<UPDATE withdrawn_len="8" path_attr_len="0"><WITHDRAWN count="2"

><PREFIX label="WITH"><ADDRESS>150.196.29.0/24</ADDRESS><AFI value="1">IPV4

</AFI><SAFI value="1">UNICAST </SAFI></PREFIX><PREFIX label="WITH"><ADDRESS>

205.94.224.0/20</ADDRESS><AFI value="1">IPV4</AFI><SAFI value="1">UNICAST

</SAFI></PREFIX></WITHDRAWN><PATH_ATTRIBUTES count="0"/><NLRI count="0"/>

</UPDATE></ASCII_MSG><OCTET_MSG><OCTETS length="31">FFFFFFFFFFFFFFFFFFFFFFFFFFF

FFFFF001F0200081896C41D14CD5EE00000</OCTETS></OCTET_MSG></BGP_MESSAGE>';

if(BGPmon::Filter::matches($xml4msg)){

        print "Matches!\n";
        
        print BGPmon::Filter::toString(); #This will print out the parsed info

}

else{

        print "Does not match.\n";

}

EXPORT ^

init parse_xml_msg parse_config_file toString filterReset get_error_msg get_error_code matches printFilters

SUBROUTINES/METHODS ^

init

Will initilialize the module an its state variables. This only needs to be called once.

filterReset

Resets the module's state values.

get_error_msg

Will return the error message of the given function name.

Input: A string that contains the function name where an error occured.

Output: The message which represents the error stored from that function.

get_error_code

Will return the error code of the given function name.

Input: A string that represents the function name where an error occured.

Output: The code which represents the error stored from that function.

parse_config_file

Will parse the wanted IPv4 and IPv6 prefixes from a configuration file as well as any autonymous system numbers. These will be stored until BGPmon::Filter::filterReset() is called. This will also aggregate addresses where possible and setup a mult-layer hash lookup system for faster retrieval

Input: A string with the location of the configuration file to parse

Output: 0 if there is no error 1 if an error occured

get_num_IPv4_prefs

Will count the number of IPv4 prefixes it has parsed from the configuration file and return the integer

Input: None Output : Integer

get_num_IPv6_prefs

Will count the number of IPv6 prefixes it has parsed from the configuration file and return the integer

Input: None Output : Integer

get_num_ASes

Will count the number of ASes it has parsed from the configuration file and return the integer

Input: None Output : Integer

get_num_ip_addrs

Will count the number of IPv4 addresses it has parsed from the configuration file and return the integer

Input: None Output : Integer

get_total_num_filters

Will tally all filters the module will look for per message and return the interger

Input: None Output : Integer

printFilters

Will print to standard output the filters currently set for the module. For example, if your prefix file looked like

#IPv4

ipv4 192.168.1.0/24 ls

#IPv6

ipv6 ::0/32 ms

#AS

as 1

This will print

ipv4 192.168.1.0/24 ls

ipv6 ::0/32 ms

as 1

toString

Will return a string that prints the most recently filtered prefixes and autonymous system numbers in human-readable format.

E.g., IPv4 prefixes pulled from the message: 192.168.1.0/24 IPv6 prefixes pulled from the message: (none) AS numbers pulled from the message: 12345

matches

Will check to see if the BGPmon message passed to it has maching prefix or AS fields that were given earlier to the module.

Input: A BGPmon message in XML format

Output: 1 if there was at least one matching filed. 0 if no matches were found.

ERROR CODES AND MESSAGES ^

The following error codes and messages are defined:

        0:   There isn't an error.
             'No Error. Relax with some tea.'
        520: The name of the configuration file given doesn't exists or
             cannot be opened.
             'Invalid filename given for config file.'
        530: An IPv4 address given in the configuration file has on octet 
             out of range, is syntactly incorrect, or is otherwise invalid.
             'Invalid IPv4 given in config file.'
        531: An IPv6 address given in teh configuration file has a value
             out of range, is syntactly incorrect, or is otherwise invalid.
             'Invalid IPv6 given in config file.'
        532: An Autonymous System number given in the configuration file
             is out of range or otherwise invalid.
             'Invalid AS given in config file.'
        533: An unknown configuration was found in the configuration file.
             'Invalid line in config file.'
        540: A message was not passed to the BGPmon::Filter::matches method.
             'No XML message was given.'

AUTHOR ^

M. Lawrence Weikum <mweikum at rams.colostate.edu>

BUGS ^

Please report any bugs or feature requeues to bgpmon at netsec.colostate.edu or through the web interface at http://bgpmon.netsec.colostate.edu.

SUPPORT ^

You can find documentation on this module with the perldoc command.

        perldoc BGPmon::Filter

LICENSE AND COPYRIGHT ^

Copyright (c) 2012 Colorado State University

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\

File: Filter.pm Authors: M. Lawrence Weikum Date: 3 March 2013

syntax highlighting: