Commit 91dc866a authored by Alessandro Rubini's avatar Alessandro Rubini

userspace/wrsw_rtud: indented with Lindent

Stuff was seriously misaligned and hard to read. So Maciej agreed
about running ../../scripts/Lindent. This commit makes no modification
at all, even it changes both spaces/tabs and newlines.

Some comments still exceed 80 columns, which is bad for me, my screen and
my printer, but I'll only change if needed, at a later step.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent cb741022
......@@ -28,34 +28,36 @@
#include "mac.h"
#include <stdio.h>
/**
* \brief Helper function to convert mac address into a string
* WARNING: this returns static storage
*/
char *mac_to_string(uint8_t mac[ETH_ALEN])
{
static char str[40];
snprintf(str, 40, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]);
return str;
static char str[40];
snprintf(str, 40, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1],
mac[2], mac[3], mac[4], mac[5]);
return str;
}
/**
* \brief Write mac address into a buffer to avoid concurrent access on static variable.
*/
char *mac_to_buffer(uint8_t mac[ETH_ALEN],char buffer[ETH_ALEN_STR])
char *mac_to_buffer(uint8_t mac[ETH_ALEN], char buffer[ETH_ALEN_STR])
{
if(mac && buffer)
snprintf(buffer, ETH_ALEN_STR, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]);
return buffer;
if (mac && buffer)
snprintf(buffer, ETH_ALEN_STR, "%02x:%02x:%02x:%02x:%02x:%02x",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
return buffer;
}
/**
* \brief Function to retrieve mac address from text input (argument in terminal)
*/
int mac_from_str(uint8_t* tomac, const char *fromstr)
int mac_from_str(uint8_t * tomac, const char *fromstr)
{
if(tomac==0 || fromstr==0) return -1;
return sscanf(fromstr,"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",tomac+0,tomac+1,tomac+2,tomac+3,tomac+4,tomac+5);
if (tomac == 0 || fromstr == 0)
return -1;
return sscanf(fromstr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", tomac + 0,
tomac + 1, tomac + 2, tomac + 3, tomac + 4, tomac + 5);
}
......@@ -27,7 +27,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __WHITERABBIT_RTU_MAC_H
#define __WHITERABBIT_RTU_MAC_H
......@@ -43,34 +42,29 @@
*/
static inline int mac_equal(uint8_t a[ETH_ALEN], uint8_t b[ETH_ALEN])
{
return !memcmp(a, b, ETH_ALEN);
return !memcmp(a, b, ETH_ALEN);
}
/**
* \brief copies src mac address into dst mac address.
* @return pointer to dst mac address
*/
static inline uint8_t* mac_copy(uint8_t dst[ETH_ALEN], uint8_t src[ETH_ALEN])
static inline uint8_t *mac_copy(uint8_t dst[ETH_ALEN], uint8_t src[ETH_ALEN])
{
return memcpy(dst, src, ETH_ALEN);
return memcpy(dst, src, ETH_ALEN);
}
/**
* \brief Set MAC address to 00:00:00:00:00:00.
* @return pointer to mac address
*/
static inline uint8_t* mac_clean(uint8_t mac[ETH_ALEN])
static inline uint8_t *mac_clean(uint8_t mac[ETH_ALEN])
{
return memset(mac, 0x00, ETH_ALEN);
return memset(mac, 0x00, ETH_ALEN);
}
char *mac_to_string(uint8_t mac[ETH_ALEN]);
char *mac_to_buffer(uint8_t mac[ETH_ALEN],char buffer[ETH_ALEN_STR]);
int mac_from_str(uint8_t* tomac, const char *fromstr);
char *mac_to_buffer(uint8_t mac[ETH_ALEN], char buffer[ETH_ALEN_STR]);
int mac_from_str(uint8_t * tomac, const char *fromstr);
#endif /* __WHITERABBIT_RTU_MAC_H */
......@@ -70,11 +70,10 @@
#define TRACE_DBG(...)
#endif
/* RTU entry address */
struct rtu_addr {
int hash;
int bucket;
int hash;
int bucket;
};
/**
......@@ -82,94 +81,91 @@ struct rtu_addr {
*/
struct rtu_request {
int port_id; // physical port identifier
uint8_t src[ETH_ALEN]; // source MAC address
uint8_t dst[ETH_ALEN]; // destination MAC address
uint16_t vid; // VLAN ID from the packet header
int has_vid; // non-zero: VID is present,0:untagged packet (VID=0)
uint8_t prio; // packet priority (either assigned by the port
// or extracted from packet header)
int has_prio; // non-zero: priority present, 0:no priority defined
int port_id; // physical port identifier
uint8_t src[ETH_ALEN]; // source MAC address
uint8_t dst[ETH_ALEN]; // destination MAC address
uint16_t vid; // VLAN ID from the packet header
int has_vid; // non-zero: VID is present,0:untagged packet (VID=0)
uint8_t prio; // packet priority (either assigned by the port
// or extracted from packet header)
int has_prio; // non-zero: priority present, 0:no priority defined
};
/**
* \brief RTU Filtering Database Entry Object
*/
struct filtering_entry {
struct rtu_addr addr; // address of self in the RTU hashtable
int valid; // bit: 1 = entry is valid, 0: entry is
// invalid (empty)
int end_of_bucket; // bit: 1 = last entry in current bucket, stop
// search at this point
int is_bpdu; // bit: 1 = BPDU (or other non-STP-dependent
// packet)
uint8_t mac[ETH_ALEN]; // MAC address (for searching the bucketed
// hashtable)
uint8_t fid; // Filtering database ID (for searching the
// bucketed hashtable)
uint32_t port_mask_src; // port mask for source MAC addresses. Bits
// set to 1 indicate that packet having this
// MAC address can be forwarded from these
// corresponding ports. Ports having their
// bits set to 0 shall drop the packet.
uint32_t port_mask_dst; // port mask for destination MAC address. Bits
// set to 1 indicate to which physical ports
// the packet with matching destination MAC
// address shall be routed
int drop_when_source; // bit: 1 = drop the packet when source
// address matches
int drop_when_dest; // bit: 1 = drop the packet when destination
// address matches
int drop_unmatched_src_ports; // bit: 1 = drop the packet when it comes from
// source port different than specified in
// port_mask_src
uint32_t last_access_t; // time of last access to the rule (for aging)
int force_remove; // when true, the entry is to be removed immediately (
// aged out or destination port went down)
uint8_t prio_src; // priority (src MAC)
int has_prio_src; // priority value valid
int prio_override_src; // priority override (force per-MAC priority)
uint8_t prio_dst; // priority (dst MAC)
int has_prio_dst; // priority value valid
int prio_override_dst; // priority override (force per-MAC priority)
int dynamic;
int age;
struct rtu_addr addr; // address of self in the RTU hashtable
int valid; // bit: 1 = entry is valid, 0: entry is
// invalid (empty)
int end_of_bucket; // bit: 1 = last entry in current bucket, stop
// search at this point
int is_bpdu; // bit: 1 = BPDU (or other non-STP-dependent
// packet)
uint8_t mac[ETH_ALEN]; // MAC address (for searching the bucketed
// hashtable)
uint8_t fid; // Filtering database ID (for searching the
// bucketed hashtable)
uint32_t port_mask_src; // port mask for source MAC addresses. Bits
// set to 1 indicate that packet having this
// MAC address can be forwarded from these
// corresponding ports. Ports having their
// bits set to 0 shall drop the packet.
uint32_t port_mask_dst; // port mask for destination MAC address. Bits
// set to 1 indicate to which physical ports
// the packet with matching destination MAC
// address shall be routed
int drop_when_source; // bit: 1 = drop the packet when source
// address matches
int drop_when_dest; // bit: 1 = drop the packet when destination
// address matches
int drop_unmatched_src_ports; // bit: 1 = drop the packet when it comes from
// source port different than specified in
// port_mask_src
uint32_t last_access_t; // time of last access to the rule (for aging)
int force_remove; // when true, the entry is to be removed immediately (
// aged out or destination port went down)
uint8_t prio_src; // priority (src MAC)
int has_prio_src; // priority value valid
int prio_override_src; // priority override (force per-MAC priority)
uint8_t prio_dst; // priority (dst MAC)
int has_prio_dst; // priority value valid
int prio_override_dst; // priority override (force per-MAC priority)
int dynamic;
int age;
};
/**
* \brief RTU VLAN registration entry object
*/
struct vlan_table_entry {
uint32_t port_mask; // VLAN port mask: 1 = ports assigned to this VLAN
uint8_t fid; // Filtering Database Identifier
uint8_t prio; // VLAN priority
int has_prio; // priority defined;
int prio_override; // priority override (force per-VLAN priority)
int drop; // 1: drop the packet (VLAN not registered)
uint32_t port_mask; // VLAN port mask: 1 = ports assigned to this VLAN
uint8_t fid; // Filtering Database Identifier
uint8_t prio; // VLAN priority
int has_prio; // priority defined;
int prio_override; // priority override (force per-VLAN priority)
int drop; // 1: drop the packet (VLAN not registered)
};
/**
* \brief Copies src filtering entry body into dst filtering entry body.
* @return pointer to dst filtering entry.
*/
static inline
struct filtering_entry *rtu_fe_copy( struct filtering_entry *dst,
struct filtering_entry *src )
struct filtering_entry *rtu_fe_copy(struct filtering_entry *dst,
struct filtering_entry *src)
{
return memcpy( dst, src, sizeof(*src) );
return memcpy(dst, src, sizeof(*src));
}
/**
......@@ -177,19 +173,17 @@ struct filtering_entry *rtu_fe_copy( struct filtering_entry *dst,
* @param ent pointer to entry to clean (either in HCAM or HTAB)
* @return pointer to filtering entry that was cleaned
*/
static inline
struct filtering_entry *rtu_fe_clean(struct filtering_entry *ent)
static inline struct filtering_entry *rtu_fe_clean(struct filtering_entry *ent)
{
return memset( ent, 0, sizeof(*ent) );
return memset(ent, 0, sizeof(*ent));
}
/**
* \brief Returns number of seconds since the epoch.
*/
static inline
unsigned long now()
static inline unsigned long now()
{
return (unsigned long) time(NULL);
return (unsigned long)time(NULL);
}
int rtud_init_exports();
......
This diff is collapsed.
......@@ -27,7 +27,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __WHITERABBIT_RTU_DRV_H
#define __WHITERABBIT_RTU_DRV_H
......@@ -39,7 +38,7 @@
#define RTU_DEVNAME "/dev/wr_rtu"
int rtu_init(void)
__attribute__((warn_unused_result));
__attribute__ ((warn_unused_result));
void rtu_exit(void);
// UFIFO
......@@ -50,12 +49,13 @@ int rtu_read_learning_queue(struct rtu_request *req);
// HTAB access
void rtu_write_htab_entry(uint16_t zbt_addr, struct filtering_entry *ent, int flush);
void rtu_write_htab_entry(uint16_t zbt_addr, struct filtering_entry *ent,
int flush);
void rtu_clean_htab(void);
// AGING - HTAB
void rtu_read_aging_bitmap(uint32_t *bitmap);
void rtu_read_aging_bitmap(uint32_t * bitmap);
// VLAN TABLE
......@@ -76,17 +76,17 @@ void rtu_set_active_bank(uint8_t bank);
// PORT SETTINGS
int rtu_set_fixed_prio_on_port(int port, uint8_t prio)
__attribute__((warn_unused_result));
__attribute__ ((warn_unused_result));
int rtu_unset_fixed_prio_on_port(int port)
__attribute__((warn_unused_result));
__attribute__ ((warn_unused_result));
int rtu_learn_enable_on_port(int port, int flag)
__attribute__((warn_unused_result));
__attribute__ ((warn_unused_result));
int rtu_pass_bpdu_on_port(int port, int flag)
__attribute__((warn_unused_result));
__attribute__ ((warn_unused_result));
int rtu_pass_all_on_port(int port, int pass_all)
__attribute__((warn_unused_result));
__attribute__ ((warn_unused_result));
int rtu_set_unrecognised_behaviour_on_port(int port, int flag)
__attribute__((warn_unused_result));
__attribute__ ((warn_unused_result));
// IRQs
......@@ -94,5 +94,4 @@ void rtu_enable_irq(void);
void rtu_disable_irq(void);
void rtu_clear_irq(void);
#endif /*__WHITERABBIT_RTU_DRV_H*/
This diff is collapsed.
......@@ -25,7 +25,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __WHITERABBIT_RTU_EXT_DRV_H
#define __WHITERABBIT_RTU_EXT_DRV_H
......@@ -34,14 +33,15 @@
int rtux_init(void);
void rtux_add_ff_mac_single(int mac_id, int valid, uint8_t mac[ETH_ALEN]);
void rtux_add_ff_mac_range(int mac_id, int valid, uint8_t mac_lower[ETH_ALEN],
uint8_t mac_upper[ETH_ALEN]);
void rtux_set_port_mirror(uint32_t mirror_src_mask, uint32_t mirror_dst_mask, int rx, int tx);
uint8_t mac_upper[ETH_ALEN]);
void rtux_set_port_mirror(uint32_t mirror_src_mask, uint32_t mirror_dst_mask,
int rx, int tx);
void rtux_set_hp_prio_mask(uint8_t hp_prio_mask);
uint8_t rtux_get_hp_prio_mask();
int rtux_get_cpu_port();
void rtux_set_feature_ctrl(int mr, int mac_ptp, int mac_ll, int mac_single, int mac_range,
int mac_br, int at_fm);
void rtux_set_feature_ctrl(int mr, int mac_ptp, int mac_ll, int mac_single,
int mac_range, int mac_br, int at_fm);
void rtux_set_fw_to_CPU(int hp, int unrec);
void rtux_disp_ctrl(void);
......
This diff is collapsed.
......@@ -30,7 +30,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __WHITERABBIT_RTU_FD_H
#define __WHITERABBIT_RTU_FD_H
......@@ -49,30 +48,29 @@
#define ADD_TO_EXISTING 1
int rtu_fd_init(uint16_t poly, unsigned long aging)
__attribute__((warn_unused_result));
__attribute__ ((warn_unused_result));
int rtu_fd_create_entry(
uint8_t mac[ETH_ALEN],
uint16_t vid,
uint32_t port_map,
int dynamic,
int at_existing_entry
) __attribute__((warn_unused_result));
int rtu_fd_create_entry(uint8_t mac[ETH_ALEN],
uint16_t vid,
uint32_t port_map,
int dynamic,
int at_existing_entry)
__attribute__ ((warn_unused_result));
int rtu_fd_set_aging_time(unsigned long t) __attribute__((warn_unused_result));
int rtu_fd_set_aging_time(unsigned long t) __attribute__ ((warn_unused_result));
void rtu_fd_set_hash_poly(uint16_t poly);
void rtu_fd_flush(void);
void rtu_fd_clear_entries_for_port(int dest_port);
struct filtering_entry * rtu_fd_lookup_htab_entry(int index);
struct filtering_entry *rtu_fd_lookup_htab_entry(int index);
struct filtering_entry *rtu_fd_lookup_htab_entry(int index);
void rtu_fd_create_vlan_entry(int vid, uint32_t port_mask, uint8_t fid, uint8_t prio,
int has_prio,int prio_override, int drop);
void rtu_fd_create_vlan_entry(int vid, uint32_t port_mask, uint8_t fid,
uint8_t prio, int has_prio, int prio_override,
int drop);
void vlan_entry_rd(int vid);
struct vlan_table_entry *rtu_vlan_entry_get(int vid);
#endif /*__WHITERABBIT_RTU_FD_H*/
......@@ -39,19 +39,19 @@ static uint16_t crc16(uint16_t const init_crc, uint16_t const message);
void rtu_hash_set_poly(uint16_t poly)
{
hash_poly = ((0x10000 | poly) << 3 );
hash_poly = ((0x10000 | poly) << 3);
}
uint16_t rtu_hash(uint8_t mac[ETH_ALEN], uint8_t fid)
{
uint16_t hash = 0xFFFF;
uint16_t hash = 0xFFFF;
hash = crc16(hash, (0xFFFF & fid));
hash = crc16(hash, ((uint16_t)mac[0] << 8) | mac[1]);
hash = crc16(hash, ((uint16_t)mac[2] << 8) | mac[3]);
hash = crc16(hash, ((uint16_t)mac[4] << 8) | mac[5]);
hash = crc16(hash, (0xFFFF & fid));
hash = crc16(hash, ((uint16_t) mac[0] << 8) | mac[1]);
hash = crc16(hash, ((uint16_t) mac[2] << 8) | mac[3]);
hash = crc16(hash, ((uint16_t) mac[4] << 8) | mac[5]);
return hash & (HTAB_ENTRIES - 1); /* warning: assumes that HTAB_ENTRIES is a power of 2 */
return hash & (HTAB_ENTRIES - 1); /* warning: assumes that HTAB_ENTRIES is a power of 2 */
}
/*
......@@ -91,24 +91,21 @@ uint16_t rtu_hash(uint8_t mac[ETH_ALEN], uint8_t fid)
*/
static uint16_t crc16(uint16_t const init_crc, uint16_t const message)
{
uint32_t remainder;
int bit;
uint32_t remainder;
int bit;
// Initially, the dividend is the remainder.
remainder = message^init_crc;
// For each bit position in the message....
for (bit = 20; bit > 0; --bit) {
// If the uppermost bit is a 1...
if (remainder & 0x80000) {
// XOR the previous remainder with the divisor.
remainder ^= hash_poly;
}
//Shift the next bit of the message into the remainder.
remainder = (remainder << 1);
}
// Return only the relevant bits of the remainder as CRC.
return (remainder >> 4);
// Initially, the dividend is the remainder.
remainder = message ^ init_crc;
// For each bit position in the message....
for (bit = 20; bit > 0; --bit) {
// If the uppermost bit is a 1...
if (remainder & 0x80000) {
// XOR the previous remainder with the divisor.
remainder ^= hash_poly;
}
//Shift the next bit of the message into the remainder.
remainder = (remainder << 1);
}
// Return only the relevant bits of the remainder as CRC.
return (remainder >> 4);
}
......@@ -49,4 +49,3 @@ void rtu_hash_set_poly(uint16_t poly);
uint16_t rtu_hash(uint8_t mac[ETH_ALEN], uint8_t fid);
#endif /*__WHITERABBIT_RTU_HASH_H*/
This diff is collapsed.
......@@ -26,7 +26,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
......@@ -49,23 +48,20 @@ static struct minipc_ch *rtud_ch;
#define MINIPC_EXP_FUNC(stru,func) stru.f= func; \
if (minipc_export(rtud_ch, &stru) < 0) { TRACE(TRACE_FATAL,"Could not export %s (rtu_ch=%d)",stru.name,rtud_ch); }
/* The exported function */
int rtudexp_get_fd_list(const struct minipc_pd *pd,
uint32_t *args, void *ret)
int rtudexp_get_fd_list(const struct minipc_pd *pd, uint32_t * args, void *ret)
{
int i;
rtudexp_fd_list_t *list = ret;
int start_from = args[0];
TRACE(TRACE_INFO, "GetFDList start=%d", start_from);
TRACE(TRACE_INFO,"GetFDList start=%d",start_from);
for(i=0;i<8;i++)
{
struct filtering_entry *ent = rtu_fd_lookup_htab_entry(start_from + i);
if(!ent) break;
for (i = 0; i < 8; i++) {
struct filtering_entry *ent =
rtu_fd_lookup_htab_entry(start_from + i);
if (!ent)
break;
memcpy(list->list[i].mac, ent->mac, sizeof(ent->mac));
//printf("Ent: %s %x\n", mac_to_string(ent->mac), ent->port_mask_dst);
......@@ -81,82 +77,77 @@ int rtudexp_get_fd_list(const struct minipc_pd *pd,
}
list->num_rules = i;
list->next = (i < 8 ? 0 : start_from+i);
list->next = (i < 8 ? 0 : start_from + i);
return 0;
}
/* The exported vlan */
int rtudexp_get_vd_list(const struct minipc_pd *pd,
uint32_t *args, void *ret)
int rtudexp_get_vd_list(const struct minipc_pd *pd, uint32_t * args, void *ret)
{
int i = 0;
rtudexp_vd_list_t *list = ret;
int current = args[0];
TRACE(TRACE_INFO,"GetVDList start=%d",current);
do
{
struct vlan_table_entry *ent = rtu_vlan_entry_get(current);
if(!ent) break;
if(ent->drop == 0 || ent->port_mask != 0x0)
{
list->list[i].vid = current;
list->list[i].port_mask = ent->port_mask;
list->list[i].drop = ent->drop;
list->list[i].fid = ent->fid;
list->list[i].has_prio = ent->has_prio;
list->list[i].prio_override = ent->prio_override;
list->list[i].prio = ent->prio;
TRACE(TRACE_INFO, "vlan_entry_vd: vid %d, drop=%d, fid=%d, port_mask 0x%x",
list->list[i].vid ,
list->list[i].drop,
list->list[i].fid,
list->list[i].port_mask
);
i++;
TRACE(TRACE_INFO, "GetVDList start=%d", current);
do {
struct vlan_table_entry *ent = rtu_vlan_entry_get(current);
if (!ent)
break;
if (ent->drop == 0 || ent->port_mask != 0x0) {
list->list[i].vid = current;
list->list[i].port_mask = ent->port_mask;
list->list[i].drop = ent->drop;
list->list[i].fid = ent->fid;
list->list[i].has_prio = ent->has_prio;
list->list[i].prio_override = ent->prio_override;
list->list[i].prio = ent->prio;
TRACE(TRACE_INFO,
"vlan_entry_vd: vid %d, drop=%d, fid=%d, port_mask 0x%x",
list->list[i].vid, list->list[i].drop,
list->list[i].fid, list->list[i].port_mask);
i++;
}
current++;
if(current == NUM_VLANS) break;
} while(i < 8);
if (current == NUM_VLANS)
break;
} while (i < 8);
list->num_entries = i;
list->next = (i < 8 ? 0 : current);
return 0;
}
int rtudexp_clear_entries(const struct minipc_pd *pd,
uint32_t *args, void *ret)
uint32_t * args, void *ret)
{
int iface_num=(int)args[0];
int force=(int)args[1];
int *p_ret=(int*)ret; //force pointed to int type
int iface_num = (int)args[0];
int force = (int)args[1];
int *p_ret = (int *)ret; //force pointed to int type
TRACE(TRACE_INFO,"iface=%d, force=%d",iface_num,force);
TRACE(TRACE_INFO, "iface=%d, force=%d", iface_num, force);
//Do nothing
if(force) TRACE(TRACE_INFO,"wr%d > force %d is not implemented",iface_num,force);
if (force)
TRACE(TRACE_INFO, "wr%d > force %d is not implemented",
iface_num, force);
rtu_fd_clear_entries_for_port(iface_num);
*p_ret=0;
*p_ret = 0;
return *p_ret;
}
int rtudexp_add_entry(const struct minipc_pd *pd,
uint32_t *args, void *ret)
int rtudexp_add_entry(const struct minipc_pd *pd, uint32_t * args, void *ret)
{
uint8_t mac_tmp[ETH_ALEN] = {0};
uint8_t mac_tmp[ETH_ALEN] = { 0 };
hexp_port_list_t ports;
char *strEHA;
int port, mode;
int *p_ret=(int*)ret; //force pointed to int type
int *p_ret = (int *)ret; //force pointed to int type
strEHA = (char *)args;
args = minipc_get_next_arg(args, pd->args[0]);
......@@ -167,30 +158,33 @@ int rtudexp_add_entry(const struct minipc_pd *pd,
halexp_query_ports(&ports);
if(mac_from_str(mac_tmp,strEHA)!=ETH_ALEN)
TRACE(TRACE_ERROR,"%s is an invalid MAC format (XX:XX:XX:XX:XX:XX)",strEHA);
if (mac_from_str(mac_tmp, strEHA) != ETH_ALEN)
TRACE(TRACE_ERROR,
"%s is an invalid MAC format (XX:XX:XX:XX:XX:XX)",
strEHA);
TRACE(TRACE_INFO,"Create entry for (MAC=%s) port %x, mode:%s",mac_to_string(mac_tmp),1 << port,(mode)?"DYNAMIC":"STATIC");
*p_ret=rtu_fd_create_entry(mac_tmp, 0, 1 << port, mode, OVERRIDE_EXISTING);
TRACE(TRACE_INFO, "Create entry for (MAC=%s) port %x, mode:%s",
mac_to_string(mac_tmp), 1 << port, (mode) ? "DYNAMIC" : "STATIC");
*p_ret =
rtu_fd_create_entry(mac_tmp, 0, 1 << port, mode, OVERRIDE_EXISTING);
return *p_ret;
}
int rtudexp_vlan_entry(const struct minipc_pd *pd,
uint32_t *args, void *ret)
int rtudexp_vlan_entry(const struct minipc_pd *pd, uint32_t * args, void *ret)
{
int vid, fid, mask, drop, prio, has_prio, prio_override;
int *p_ret=(int*)ret; //force pointed to int type
int *p_ret = (int *)ret; //force pointed to int type
*p_ret = 0;
vid = (int)args[0];
fid = (int)args[1];
mask= (int)args[2];
drop= (int)args[3];
prio= (int)args[4];
has_prio= (int)args[5];
prio_override= (int)args[6];
rtu_fd_create_vlan_entry(vid, (uint32_t)mask, (uint8_t)fid, (uint8_t)prio, has_prio,prio_override, drop);
vid = (int)args[0];
fid = (int)args[1];
mask = (int)args[2];
drop = (int)args[3];
prio = (int)args[4];
has_prio = (int)args[5];
prio_override = (int)args[6];
rtu_fd_create_vlan_entry(vid, (uint32_t) mask, (uint8_t) fid,
(uint8_t) prio, has_prio, prio_override, drop);
return *p_ret;
}
......@@ -198,17 +192,17 @@ int rtud_init_exports()
{
rtud_ch = minipc_server_create("rtud", 0);
if(!rtud_ch < 0)
if (!rtud_ch < 0)
return -1;
TRACE(TRACE_INFO,"wripc server created [fd %d]",
minipc_fileno(rtud_ch));
TRACE(TRACE_INFO, "wripc server created [fd %d]",
minipc_fileno(rtud_ch));
MINIPC_EXP_FUNC(rtud_export_get_fd_list,rtudexp_get_fd_list);
MINIPC_EXP_FUNC(rtud_export_get_vd_list,rtudexp_get_vd_list);
MINIPC_EXP_FUNC(rtud_export_clear_entries,rtudexp_clear_entries);
MINIPC_EXP_FUNC(rtud_export_add_entry,rtudexp_add_entry);
MINIPC_EXP_FUNC(rtud_export_vlan_entry,rtudexp_vlan_entry);
MINIPC_EXP_FUNC(rtud_export_get_fd_list, rtudexp_get_fd_list);
MINIPC_EXP_FUNC(rtud_export_get_vd_list, rtudexp_get_vd_list);
MINIPC_EXP_FUNC(rtud_export_clear_entries, rtudexp_clear_entries);
MINIPC_EXP_FUNC(rtud_export_add_entry, rtudexp_add_entry);
MINIPC_EXP_FUNC(rtud_export_vlan_entry, rtudexp_vlan_entry);
return 0;
}
......
......@@ -25,27 +25,25 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __RTUD_EXPORTS_H
#define __RTUD_EXPORTS_H
#include <stdint.h>
#include <minipc.h>
typedef struct
{
uint8_t mac[8];
uint32_t dpm;
uint32_t spm;
uint8_t priority;
int dynamic;
uint16_t hash;
int bucket;
int age;
int fid;
typedef struct {
uint8_t mac[8];
uint32_t dpm;
uint32_t spm;
uint8_t priority;
int dynamic;
uint16_t hash;
int bucket;
int age;
int fid;
} rtudexp_fd_entry_t;
typedef struct {
typedef struct {
rtudexp_fd_entry_t list[8];
int num_rules;
......@@ -53,34 +51,32 @@ typedef struct {
} rtudexp_fd_list_t;
///// VLAN export
typedef struct
{
int vid;
uint32_t port_mask;
uint8_t fid;
uint8_t prio;
int has_prio;
int prio_override;
int drop;
typedef struct {
int vid;
uint32_t port_mask;
uint8_t fid;
uint8_t prio;
int has_prio;
int prio_override;
int drop;
} rtudexp_vd_entry_t;
typedef struct {
typedef struct {
rtudexp_vd_entry_t list[8];
int num_entries;
int next;
} rtudexp_vd_list_t;
/* Export this function: it returns a structure */
struct minipc_pd rtud_export_get_fd_list = {
.name = "get_fd_list",
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_STRUCT,
rtudexp_fd_list_t),
.args = {
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_END,
},
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_END,
},
};
/* Export this function: it returns a structure */
struct minipc_pd rtud_export_get_vd_list = {
......@@ -88,49 +84,48 @@ struct minipc_pd rtud_export_get_vd_list = {
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_STRUCT,
rtudexp_vd_list_t),
.args = {
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_END,
},
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_END,
},
};
/* Export of a function to set remove entry in rtu */
struct minipc_pd rtud_export_clear_entries = {
.name = "clear_entries",
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT,int),
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
.args = {
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_END,
},
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_END,
},
};
/* Export of a function to add entry in rtu */
struct minipc_pd rtud_export_add_entry = {
.name = "add_entry",
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT,int),
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
.args = {
MINIPC_ARG_ENCODE(MINIPC_ATYPE_STRING,char *),
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_END,
},
MINIPC_ARG_ENCODE(MINIPC_ATYPE_STRING, char *),
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_END,
},
};
/* Export of a function to add vlan entry in rtu */
struct minipc_pd rtud_export_vlan_entry = {
.name = "vlan_entry",
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT,int),
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
.args = {
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int), // 0: vid
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int), // 1: fid
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int), // 2: mask
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int), // 3: drop
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int), // 4: prio
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int), // 5: has_prio
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int), // 6: prio_override
MINIPC_ARG_END,
},
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int), // 0: vid
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int), // 1: fid
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int), // 2: mask
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int), // 3: drop
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int), // 4: prio
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int), // 5: has_prio
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int), // 6: prio_override
MINIPC_ARG_END,
},
};
#endif
......@@ -26,7 +26,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......@@ -38,54 +37,55 @@
void daemonize(void)
{
pid_t pid, sid;
pid_t pid, sid;
/* already a daemon */
if ( getppid() == 1 ) return;
/* already a daemon */
if (getppid() == 1)
return;
/* Fork off the parent process */
pid = fork();
if (pid < 0) {
exit(EXIT_FAILURE);
}
/* If we got a good PID, then we can exit the parent process. */
if (pid > 0) {
exit(EXIT_SUCCESS);
}
/* Fork off the parent process */
pid = fork();
if (pid < 0) {
exit(EXIT_FAILURE);
}
/* If we got a good PID, then we can exit the parent process. */
if (pid > 0) {
exit(EXIT_SUCCESS);
}
/* At this point we are executing as the child process */
/* At this point we are executing as the child process */
/* Change the file mode mask */
umask(0);
/* Change the file mode mask */
umask(0);
/* Create a new SID for the child process */
sid = setsid();
if (sid < 0) {
exit(EXIT_FAILURE);
}
/* Create a new SID for the child process */
sid = setsid();
if (sid < 0) {
exit(EXIT_FAILURE);
}
/* Change the current working directory. This prevents the current
directory from being locked; hence not being able to remove it. */
if ((chdir("/")) < 0) {
exit(EXIT_FAILURE);
}
/* Change the current working directory. This prevents the current
directory from being locked; hence not being able to remove it. */
if ((chdir("/")) < 0) {
exit(EXIT_FAILURE);
}
/* Redirect standard files to /dev/null */
freopen( "/dev/null", "r", stdin);
freopen( "/dev/null", "w", stdout);
freopen( "/dev/null", "w", stderr);
/* Redirect standard files to /dev/null */
freopen("/dev/null", "r", stdin);
freopen("/dev/null", "w", stdout);
freopen("/dev/null", "w", stderr);
}
void usage(char *name)
{
fprintf(stderr,
"Usage: %s [-dh] [-p <polly>] [-r <time>] [-t <time>]\n"
"\t-d daemonize\n"
"\t-h help\n"
"\t-p polynomial for hash calculation. Possible values are CCITT, IBM, DECT\n"
"\t-r aging resolution (in sec). 20 sec by default\n"
"\t-t aging time (10 to 10000 sec). 300 sec by default.\n",
name);
exit(1);
fprintf(stderr,
"Usage: %s [-dh] [-p <polly>] [-r <time>] [-t <time>]\n"
"\t-d daemonize\n"
"\t-h help\n"
"\t-p polynomial for hash calculation. Possible values are CCITT, IBM, DECT\n"
"\t-r aging resolution (in sec). 20 sec by default\n"
"\t-t aging time (10 to 10000 sec). 300 sec by default.\n",
name);
exit(1);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment