The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

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 $xml_msg = '...

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

        print "Matches!\n";
        

}

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: 10 October 2013