OpenNSL API Guide and Reference Manual
Macros | Functions | Variables
example_l2_firewall.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sal/driver.h>
#include <opennsl/error.h>
#include <opennsl/l2.h>
#include <opennsl/switch.h>
#include <opennsl/vlan.h>
#include <examples/util.h>

Go to the source code of this file.

Macros

#define DEFAULT_UNIT   0
 
#define DEFAULT_VLAN   1
 
#define MAX_DIGITS_IN_CHOICE   5
 

Functions

int _opennsl_l2_traverse_cb (int unit, opennsl_l2_addr_t *info, void *user_data)
 Callback function to show L2 table information.
 
int example_l2_firewall_allow_station (int unit, opennsl_mac_t mac, opennsl_vlan_t vlan)
 Unblock the given station MAC address in the given VLAN.
 
int example_l2_firewall_block_station (int unit, opennsl_mac_t mac, opennsl_vlan_t vlan)
 Block the given station MAC address in the given VLAN.
 
int main (int argc, char *argv[])
 Main function for Layer2 firewall application.
 

Variables

char example_usage []
 
int max_l2_count = 0
 

Macro Definition Documentation

#define DEFAULT_UNIT   0

Definition at line 52 of file example_l2_firewall.c.

Referenced by main().

#define DEFAULT_VLAN   1

Definition at line 53 of file example_l2_firewall.c.

#define MAX_DIGITS_IN_CHOICE   5

Definition at line 54 of file example_l2_firewall.c.

Function Documentation

int _opennsl_l2_traverse_cb ( int  unit,
opennsl_l2_addr_t info,
void *  user_data 
)

Callback function to show L2 table information.

Parameters
unit[IN] unit number
info[IN] L2 address structure
*user_data[IN] User specified cookie
Returns
OPENNSL_E_NONE

Definition at line 131 of file example_l2_firewall.c.

References opennsl_l2_addr_s::mac, max_l2_count, OPENNSL_E_NONE, opennsl_l2_addr_s::port, and opennsl_l2_addr_s::vid.

Referenced by main().

int example_l2_firewall_allow_station ( int  unit,
opennsl_mac_t  mac,
opennsl_vlan_t  vlan 
)

Unblock the given station MAC address in the given VLAN.

Parameters
unit[IN] Unit number
mac[IN] 802.3 MAC address
vlan[IN] VLAN ID
Returns
OPENNSL_E_XXX OpenNSL API return code

Definition at line 105 of file example_l2_firewall.c.

References OPENNSL_E_NONE, opennsl_l2_addr_delete(), and opennsl_l2_addr_get().

Referenced by main().

int example_l2_firewall_block_station ( int  unit,
opennsl_mac_t  mac,
opennsl_vlan_t  vlan 
)

Block the given station MAC address in the given VLAN.

Parameters
unit[IN] Unit number
mac[IN] 802.3 MAC address
vlan[IN] VLAN ID
Returns
OPENNSL_E_XXX OpenNSL API return code

Definition at line 78 of file example_l2_firewall.c.

References opennsl_l2_addr_s::flags, opennsl_l2_addr_add(), opennsl_l2_addr_t_init(), OPENNSL_L2_DISCARD_DST, OPENNSL_L2_DISCARD_SRC, and OPENNSL_L2_STATIC.

Referenced by main().

int main ( int  argc,
char *  argv[] 
)

Variable Documentation

char example_usage[]
Initial value:
=
"Syntax: example_l2_firewall \n\r"
" \n\r"
"Paramaters: None. \n\r"
" \n\r"
"Example: The following command is used to allow or block station A \n\r"
"and station D that are part of VLAN 1 with MAC addresses \n\r"
"00:00:00:00:00:01 and 00:00:00:00:00:04 respectively. \n\r"
" example_l2_firewall \n\r"
" \n\r"
"Usage Guidelines: None. \n\r"

Definition at line 57 of file example_l2_firewall.c.

int max_l2_count = 0

Definition at line 56 of file example_l2_firewall.c.

Referenced by _opennsl_l2_traverse_cb(), and main().