00001 /* 00002 * White Rabbit RTU (Routing Table Unit) 00003 * Copyright (C) 2010, CERN. 00004 * 00005 * Version: wrsw_rtud v1.0 00006 * 00007 * Authors: Juan Luis Manas (juan.manas@integrasys.es) 00008 * Maciej Lipinski (maciej.lipinski@cern.ch) 00009 * 00010 * Description: RTU data structures definition. 00011 * 00012 * Fixes: 00013 * Tomasz Wlostowski 00014 * 00015 * 00016 * This program is free software; you can redistribute it and/or 00017 * modify it under the terms of the GNU General Public License 00018 * as published by the Free Software Foundation; either version 00019 * 2 of the License, or (at your option) any later version. 00020 * 00021 * This program is distributed in the hope that it will be useful, 00022 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00024 * GNU General Public License for more details. 00025 * 00026 * You should have received a copy of the GNU General Public License 00027 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00028 */ 00029 00030 #ifndef __WHITERABBIT_RTU_H 00031 #define __WHITERABBIT_RTU_H 00032 00033 #include <stdint.h> 00034 #include <errno.h> 00035 #include <string.h> 00036 #include <time.h> 00037 #include <linux/if_ether.h> 00038 #include <stdio.h> 00039 00040 #include "mac.h" 00041 00042 #define RTU_BANKS 2 00043 #define RTU_BUCKETS 4 00044 #define LAST_RTU_BUCKET ((RTU_BUCKETS)-1) 00045 #define RTU_ENTRIES (16384/(RTU_BANKS)) 00046 #define HTAB_ENTRIES ((RTU_ENTRIES)/(RTU_BUCKETS)) 00047 #define LAST_HTAB_ENTRY ((HTAB_ENTRIES)-1) 00048 00049 #define ENTRY_WORDS 8 00050 #define CAM_ENTRIES (((RTU_HCAM_WORDS)/(ENTRY_WORDS))/(RTU_BANKS)) 00051 #define LAST_CAM_ENTRY ((CAM_ENTRIES)-1) 00052 00053 #define MIN_PORT 0 00054 #define MAX_PORT 9 00055 #define NIC_PORT 10 00056 00057 // Maximum number of supported VLANs 00058 #define NUM_VLANS 4096 00059 00060 #define NUM_RESERVED_ADDR 16 00061 00062 // Default aging time for dynamic entries at filtering database [secs] 00063 #define DEFAULT_AGING_TIME 300 00064 #define MIN_AGING_TIME 10 00065 #define MAX_AGING_TIME 10000 00066 // Default aging time resolution [secs] 00067 #define DEFAULT_AGING_RES 20 00068 00069 // Keeping in mind year 2038 00070 #define time_after(a,b) ((long)(b) - (long)(a) < 0) 00071 00072 #ifdef TRACE_ALL 00073 #define TRACE_DBG(...) TRACE(__VA_ARGS__) 00074 #else 00075 #define TRACE_DBG(...) 00076 #endif 00077 00081 struct rtu_request { 00082 int port_id; // physical port identifier 00083 uint8_t src[ETH_ALEN]; // source MAC address 00084 uint8_t dst[ETH_ALEN]; // destination MAC address 00085 uint16_t vid; // VLAN ID from the packet header 00086 int has_vid; // non-zero: VID is present,0:untagged packet (VID=0) 00087 uint8_t prio; // packet priority (either assigned by the port 00088 // or extracted from packet header) 00089 int has_prio; // non-zero: priority present, 0:no priority defined 00090 }; 00091 00095 struct filtering_entry { 00096 int valid; // bit: 1 = entry is valid, 0: entry is 00097 // invalid (empty) 00098 int end_of_bucket; // bit: 1 = last entry in current bucket, stop 00099 // search at this point 00100 int is_bpdu; // bit: 1 = BPDU (or other non-STP-dependent 00101 // packet) 00102 00103 uint8_t mac[ETH_ALEN]; // MAC address (for searching the bucketed 00104 // hashtable) 00105 uint8_t fid; // Filtering database ID (for searching the 00106 // bucketed hashtable) 00107 00108 uint32_t port_mask_src; // port mask for source MAC addresses. Bits 00109 // set to 1 indicate that packet having this 00110 // MAC address can be forwarded from these 00111 // corresponding ports. Ports having their 00112 // bits set to 0 shall drop the packet. 00113 00114 uint32_t port_mask_dst; // port mask for destination MAC address. Bits 00115 // set to 1 indicate to which physical ports 00116 // the packet with matching destination MAC 00117 // address shall be routed 00118 00119 int drop_when_source; // bit: 1 = drop the packet when source 00120 // address matches 00121 int drop_when_dest; // bit: 1 = drop the packet when destination 00122 // address matches 00123 int drop_unmatched_src_ports; // bit: 1 = drop the packet when it comes from 00124 // source port different than specified in 00125 // port_mask_src 00126 00127 uint32_t last_access_t; // time of last access to the rule (for aging) 00128 00129 uint8_t prio_src; // priority (src MAC) 00130 int has_prio_src; // priority value valid 00131 int prio_override_src; // priority override (force per-MAC priority) 00132 00133 uint8_t prio_dst; // priority (dst MAC) 00134 int has_prio_dst; // priority value valid 00135 int prio_override_dst; // priority override (force per-MAC priority) 00136 00137 int go_to_cam; // 1 : there are more entries outside the 00138 // bucket 00139 00140 uint16_t cam_addr; // address of the first entry in CAM memory 00141 // (2 words) 00142 00143 int dynamic; 00144 }; 00145 00149 struct vlan_table_entry { 00150 uint32_t port_mask; // VLAN port mask: 1 = ports assigned to this VLAN 00151 uint8_t fid; // Filtering Database Identifier 00152 uint8_t prio; // VLAN priority 00153 int has_prio; // priority defined; 00154 int prio_override; // priority override (force per-VLAN priority) 00155 int drop; // 1: drop the packet (VLAN not registered) 00156 }; 00157 00162 static inline 00163 struct filtering_entry *rtu_fe_copy( struct filtering_entry *dst, 00164 struct filtering_entry *src ) 00165 { 00166 return memcpy( dst, src, sizeof(*src) ); 00167 } 00168 00174 static inline 00175 struct filtering_entry *rtu_fe_clean(struct filtering_entry *ent) 00176 { 00177 return memset( ent, 0, sizeof(*ent) ); 00178 } 00179 00183 static inline 00184 unsigned long now() 00185 { 00186 return (unsigned long) time(NULL); 00187 } 00188 00189 int rtud_init_exports(); 00190 void rtud_handle_wripc(); 00191 00192 #endif /*__WHITERABBIT_RTU_H*/