Skip to content
Snippets Groups Projects
Commit 42c33628 authored by Zhu Ken's avatar Zhu Ken
Browse files

Revert "[rstp] init rstp feed"


This reverts commit 8023e06e.
because this change is merged manually, it need merge automatically.
revert this

Change-Id: Icc913093ed0024e2fd140bee3d987a3509378307
Signed-off-by: default avatarZhu Ken <guigenz@codeaurora.org>
parent db66e75c
No related branches found
No related tags found
No related merge requests found
Showing with 0 additions and 2821 deletions
include $(TOPDIR)/rules.mk
PKG_NAME:=rstp
PKG_VERSION:=2011-10-11
PKG_RELEASE=$(PKG_SOURCE_VERSION)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=git://git.kernel.org/pub/scm/linux/kernel/git/shemminger/rstp.git
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE_VERSION:=434d24bae108dbb21461a13a4abcf014afa8b029
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_MAINTAINER:=Stephen Hemminger <shemminger@vyatta.com>
# PKG_MIRROR_MD5SUM:=
# CMAKE_INSTALL:=1
PKG_LICENSE:=GPLv2
PKG_LICENSE_FILES:=
PKG_BUILD_PARALLEL:=1
include $(INCLUDE_DIR)/package.mk
define Package/rstp
SECTION:=net
CATEGORY:=Network
MAINTAINER:=Stephen Hemminger <shemminger@vyatta.com>
URL:=http://git.kernel.org/cgit/linux/kernel/git/shemminger/rstp.git/
TITLE:=Rapid Spanning Tree Protocol implement
DEPENDS:=+kmod-qca-ssdk-hnat
endef
TARGET_CFLAGS += \
-I$(STAGING_DIR)/usr/include/qca-ssdk
define Package/rstp/install
$(INSTALL_DIR) $(1)/sbin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/bridge-stp $(1)/sbin/
$(INSTALL_BIN) $(PKG_BUILD_DIR)/rstpctl $(1)/sbin/
$(INSTALL_BIN) $(PKG_BUILD_DIR)/rstpd $(1)/sbin/
$(CP) ./files/* $(1)/
endef
$(eval $(call BuildPackage,rstp))
config rstp global
option enable '0'
option autoMode '1'
#!/bin/sh /etc/rc.common
# Copyright (C) 2006-2011 OpenWrt.org
START=55
SERVICE_USE_PID=1
SERVICE_DAEMONIZE=1
SERVICE_WRITE_PID=1
yes_or_no(){
local xboolean=$1
if [ "$xboolean" = "1" ]
then
echo "yes"
else
echo "no"
fi
}
ifname_exist=1
port_is_valid=1
option_cb()
{
local name="$1"
local value="$2"
if [ "$name" = "ifname" ]; then
[ -d "/sys/class/net/$value" ] || ifname_exist=0
fi
}
validate_port(){
local port_name=$1
local bridge ifname switch switchPortId
local bridge_ifname switch_ifname
config_get bridge $port_name bridge
config_get ifname $port_name ifname
config_get switch $port_name switch
config_get switchPortId $port_name switchPortId
[ -z "$bridge" ] && port_is_valid=0 && return
config_get bridge_ifname $bridge ifname
[ -z "$bridge_ifname" ] && port_is_valid=0 && return
[ -z "$ifname" ] && [ -z "$switch" ] && port_is_valid=0 && return
# [ -n "$ifname" ] && [ -n "$switch" ] && port_is_valid=0 && return
[ -n "$switch" ] && [ -z "$switchPortId" ] && port_is_valid=0 && return
if [ -n "$switch" ]; then
config_get switch_ifname $switch ifname
[ -z "$switch_ifname" ] && port_is_valid=0 && return
fi
}
validate_config(){
if [ "$ifname_exist" = "0" ]; then
echo "ifname of bridge or switch port not exist"
return -1
fi
config_foreach validate_port port
if [ "$port_is_valid" = "0" ]; then
echo "switch port configuration error"
return -1
fi
return 0
}
rstpctl_add_bridge(){
local bridge_name=$1
local enable=0
local bridge_ifname
local priority helloTime maxAge forwardDelay forceProtocolVersion
config_get enable $bridge_name enable
[ "$enable" = "0" ] && return
config_get bridge_ifname $bridge_name ifname
[ -z "$bridge_ifname" ] && return
/sbin/rstpctl addBridge $bridge_ifname
config_get priority $bridge_name priority
[ -n "$priority" ] && /sbin/rstpctl setbridgeprio $bridge_ifname $priority
config_get helloTime $bridge_name helloTime
[ -n "$helloTime" ] && /sbin/rstpctl sethello $bridge_ifname $helloTime
config_get maxAge $bridge_name maxAge
[ -n "$maxAge" ] && /sbin/rstpctl setmaxage $bridge_ifname $maxAge
config_get forwardDelay $bridge_name forwardDelay
[ -n "$forwardDelay" ] && /sbin/rstpctl setfdelay $bridge_ifname $forwardDelay
config_get forceProtocolVersion $bridge_name forceProtocolVersion
[ "$forceProtocolVersion" = "1" ] && /sbin/rstpctl setforcevers $bridge_ifname "slow"
[ "$forceProtocolVersion" = "2" ] && /sbin/rstpctl setforcevers $bridge_ifname "normal"
}
rstpctl_add_port(){
local port_name=$1
local bridge enable ifname switch switchPortId
local bridge_ifname switch_ifname
local priority pathCost edgePort p2pLink
config_get enable $port_name enable
[ "$enable" = "0" ] && return
enable=0
config_get bridge $port_name bridge
config_get bridge_ifname $bridge ifname
config_get enable $bridge enable
[ "$enable" = "0" ] && return
config_get ifname $port_name ifname
[ -z "$ifname" ] && ifname="no-exist"
config_get switch $port_name switch
config_get switchPortId $port_name switchPortId
if [ -n "$switch" ] && [ -n "$switchPortId" ] ; then
config_get switch_ifname $switch ifname
ifname="$switch_ifname.$port_name"
fi
/sbin/rstpctl addBridgePort $bridge_ifname $ifname
config_get priority $port_name priority
[ -n "$priority" ] && /sbin/rstpctl setportprio $bridge_ifname $ifname $priority
config_get pathCost $port_name pathCost
[ -n "$pathCost" ] && /sbin/rstpctl setportpathcost $bridge_ifname $ifname $pathCost
config_get edgePort $port_name edgePort
[ -n "$edgePort" ] && /sbin/rstpctl setportedge $bridge_ifname $ifname $(yes_or_no $edgePort)
config_get p2pLink $port_name p2pLink
[ -n "$p2pLink" ] && /sbin/rstpctl setportp2p $bridge_ifname $ifname $(yes_or_no $p2pLink)
}
rstpctl_start_bridge(){
local bridge_name=$1
local enable=0
local bridge_ifname
config_get enable $bridge_name enable
[ "$enable" = "0" ] && return
config_get bridge_ifname $bridge_name ifname
[ -z "$bridge_ifname" ] && return
brctl stp $bridge_ifname on
}
rstpctl_stop_bridge(){
local bridge_name=$1
local enable=0
local bridge_ifname
config_get enable $bridge_name enable
[ "$enable" = "0" ] && return
config_get bridge_ifname $bridge_name ifname
[ -z "$bridge_ifname" ] && return
brctl stp $bridge_ifname off
}
board_set() {
if [ -e /proc/sys/net/edma/enable_stp_rstp ]; then
echo 0xfefefefe > /proc/sys/net/edma/athr_hdr_eth_type
echo 1 > /proc/sys/net/edma/enable_stp_rstp
else
cpu_mirror=$(/lib/functions/rstp.sh get_cpu_mirror_port)
cpu=`echo $cpu_mirror |cut -d " " -f1`
mirror=`echo $cpu_mirror |cut -d " " -f2`
ssdk_sh port hdrtype set enable 0xfefe
if [ $cpu -ge 0 ]; then
ssdk_sh port txhdr set $cpu onlymanagement
ssdk_sh port rxhdr set $cpu onlymanagement
fi
if [ $mirror -ge 0 ]; then
ssdk_sh port txhdr set $mirror onlymanagement
ssdk_sh port rxhdr set $mirror onlymanagement
ssdk_sh mirror analyPt set $mirror
fi
fi
}
board_recover() {
if [ -e /proc/sys/net/edma/enable_stp_rstp ]; then
echo 0 > /proc/sys/net/edma/enable_stp_rstp
echo 0 > /proc/sys/net/edma/athr_hdr_eth_type
else
cpu_mirror=$(/lib/functions/rstp.sh get_cpu_mirror_port)
cpu=`echo $cpu_mirror |cut -d " " -f1`
mirror=`echo $cpu_mirror |cut -d " " -f2`
ssdk_sh port hdrtype set disable 0
if [ $cpu -ge 0 ]; then
ssdk_sh port txhdr set $cpu noheader
ssdk_sh port rxhdr set $cpu noheader
fi
if [ $mirror -ge 0 ]; then
ssdk_sh port txhdr set $mirror noheader
ssdk_sh port rxhdr set $mirror noheader
ssdk_sh mirror analyPt set 0xf
fi
fi
}
start() {
local rstp_enable autoMode ifname
config_load "rstp"
config_get rstp_enable global enable 0
[ "$rstp_enable" = "0" ] && return
config_get autoMode global autoMode 0
if [ "$autoMode" = "1" ] ; then
service_start /sbin/rstpd -a
sleep 1
. /lib/functions/network.sh
network_get_device ifname lan
brctl stp $ifname on
else
validate_config || return
service_start /sbin/rstpd
sleep 1
config_foreach rstpctl_start_bridge bridge
config_foreach rstpctl_add_bridge bridge
config_foreach rstpctl_add_port port
fi
board_set
}
stop() {
local rstp_enable autoMode ifname
config_load "rstp"
config_get rstp_enable global enable 0
board_recover
[ "$rstp_enable" = "0" ] && return
config_get autoMode global autoMode 0
if [ "$autoMode" = "1" ] ; then
. /lib/functions/network.sh
network_get_device ifname lan
brctl stp $ifname off
sleep 1
service_stop /sbin/rstpd
else
validate_config || return
config_foreach rstpctl_stop_bridge bridge
sleep 1
service_stop /sbin/rstpd
fi
}
#!/bin/sh
# Copyright (c) 2013 The Linux Foundation. All rights reserved.
. /lib/functions.sh
get_linkstatus_check_interval(){
echo 3
}
get_atheros_header_type(){
echo 0xfefe
}
get_cpu_mirror_port(){
. /lib/ipq806x.sh
board=$(ipq806x_board_name)
case "$board" in
*)
echo "0 6"
;;
esac
}
get_switch_config_auto(){
. /lib/ipq806x.sh
board=$(ipq806x_board_name)
case "$board" in
*)
echo "=qca eth1 eth1 1 port1"
echo "=qca eth1 eth1 2 port2"
echo "=qca eth1 eth1 3 port3"
echo "=qca eth1 eth1 4 port4"
echo "=qca eth1 eth0 5 eth0"
;;
esac
}
get_switch_port_config(){
local port_name=$1
local bridge enable switch switchPortId control_channel data_channel
config_get enable $port_name enable
[ "$enable" = "0" ] && return
enable=0
config_get bridge $port_name bridge
config_get enable $bridge enable
[ "$enable" = "0" ] && return
config_get switch $port_name switch
config_get switchPortId $port_name switchPortId
if [ -n "$switch" ] && [ -n "$switchPortId" ] ; then
config_get control_channel $switch ifname
config_get data_channel $port_name ifname
[ -z "$data_channel" ] && data_channel="$control_channel"
echo "=qca $control_channel $data_channel $switchPortId $port_name"
fi
}
get_switch_config_manual(){
config_foreach get_switch_port_config port
}
get_switch_ports(){
local autoMode
config_load "rstp"
config_get autoMode global autoMode
if [ "$autoMode" = "1" ] ; then
get_switch_config_auto
else
get_switch_config_manual
fi
}
func=$1
shift
$func $@
diff --git a/Makefile b/Makefile
index 3e04bea..f903f91 100644
--- a/Makefile
+++ b/Makefile
@@ -8,8 +8,7 @@ CTLSOURCES = ctl_main.c ctl_cli_wrap.c ctl_socket_client.c
CTLOBJECTS = $(CTLSOURCES:.c=.o)
-CC=gcc
-CFLAGS = -Wall -Werror -fno-strict-aliasing -O2 -g -D_REENTRANT -D__LINUX__ \
+CFLAGS += -Wall -Werror -fno-strict-aliasing -O2 -g -D_REENTRANT -D__LINUX__ \
-DVERSION=$(version) -DBUILD=$(build) -I. -I./include -I./rstplib
all: rstpd rstpctl
diff --git a/rstplib/Makefile b/rstplib/Makefile
index 1ecf211..0bc026d 100644
--- a/rstplib/Makefile
+++ b/rstplib/Makefile
@@ -21,9 +21,8 @@
#**********************************************************************/
DEFS=
-CC = gcc
#CFLAGS = -g -Wall -D_REENTRANT -D__LINUX__ -DSTP_DBG=1
-CFLAGS = -g -O -Wall -D_REENTRANT -D__LINUX__
+CFLAGS += -g -O -Wall -D_REENTRANT -D__LINUX__
INCLUDES = -I.
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CFLAGS)
diff --git a/bridge-stp b/bridge-stp
index e699b87..f9277df 100755
--- a/bridge-stp
+++ b/bridge-stp
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
#
# Script to start/stop spanning tree called from kernel
# Make sure umask is sane
diff --git a/epoll_loop.c b/epoll_loop.c
index 33c3068..9ecf778 100644
--- a/epoll_loop.c
+++ b/epoll_loop.c
@@ -36,6 +36,7 @@
// globals
int epoll_fd = -1;
struct timeval nexttimeout;
+static int epoll_should_stop = 0;
int init_epoll(void)
{
@@ -95,6 +96,11 @@ void run_timeouts(void)
nexttimeout.tv_sec++;
}
+void epoll_end_loop(void)
+{
+ epoll_should_stop = 1;
+}
+
int epoll_main_loop(void)
{
gettimeofday(&nexttimeout, NULL);
@@ -102,7 +108,7 @@ int epoll_main_loop(void)
#define EV_SIZE 8
struct epoll_event ev[EV_SIZE];
- while (1) {
+ while (!epoll_should_stop) {
int r, i;
int timeout;
diff --git a/epoll_loop.h b/epoll_loop.h
index 14d0423..c81f3a6 100644
--- a/epoll_loop.h
+++ b/epoll_loop.h
@@ -42,6 +42,8 @@ int init_epoll(void);
void clear_epoll(void);
+void epoll_end_loop(void);
+
int epoll_main_loop(void);
int add_epoll(struct epoll_event_handler *h);
diff --git a/main.c b/main.c
index a8c21ac..a8329b3 100644
--- a/main.c
+++ b/main.c
@@ -35,11 +35,31 @@
#include <getopt.h>
#include <syslog.h>
#include <errno.h>
+#include <string.h>
+#include <signal.h>
static int become_daemon = 1;
static int is_daemon = 0;
int log_level = LOG_LEVEL_DEFAULT;
+static void handle_signal(int signo)
+{
+ epoll_end_loop();
+}
+
+static int setup_signals(void)
+{
+ struct sigaction s;
+
+ memset(&s, 0, sizeof(s));
+ s.sa_handler = handle_signal;
+ s.sa_flags = 0;
+ sigaction(SIGINT, &s, NULL);
+ sigaction(SIGTERM, &s, NULL);
+
+ return 0;
+}
+
int main(int argc, char *argv[])
{
int c,ret;
@@ -66,6 +86,7 @@ int main(int argc, char *argv[])
}
}
+ TST(setup_signals() == 0, -1);
TST(init_epoll() == 0, -1);
TST(ctl_socket_init() == 0, -1);
TST(packet_sock_init() == 0, -1);
diff --git a/bridge_ctl.h b/bridge_ctl.h
index b0449ca..616a044 100644
--- a/bridge_ctl.h
+++ b/bridge_ctl.h
@@ -25,6 +25,14 @@
#ifndef BRIDGE_CTL_H
#define BRIDGE_CTL_H
+typedef enum {
+ AUTO_TOPOLOGY,
+ MANUAL_TOPOLOGY
+}topology_mode_t;
+
+void set_topology_mode(topology_mode_t mode);
+topology_mode_t get_topology_mode(void);
+
struct ifdata;
int init_bridge_ops(void);
@@ -33,6 +41,8 @@ void bridge_get_configuration(void);
int bridge_set_state(int ifindex, int state);
+int bridge_notify_simple(int br_index, int if_index, int newlink, unsigned flags);
+
int bridge_notify(int br_index, int if_index, int newlink, unsigned flags);
void bridge_bpdu_rcv(int ifindex, const unsigned char *data, int len);
diff --git a/bridge_track.c b/bridge_track.c
index 289fc41..2967d08 100644
--- a/bridge_track.c
+++ b/bridge_track.c
@@ -476,6 +476,28 @@ static void set_if_up(struct ifdata *ifc, int up)
/*------------------------------------------------------------*/
+int bridge_notify_simple(int br_index, int if_index, int newlink,
+ unsigned flags)
+{
+ struct ifdata *br = NULL;
+ struct ifdata *ifc = NULL;
+ int up;
+
+ if (br_index >= 0) {
+ br = find_if(br_index);
+ /* Bridge must be up if we get such notifications */
+ if (br && br->is_bridge && !br->up)
+ set_br_up(br, 1);
+ }
+
+ ifc = find_if(if_index);
+ up = (flags & (IFF_UP|IFF_RUNNING)) == (IFF_UP|IFF_RUNNING);
+ if (ifc && (!ifc->is_bridge) && ifc->up != up)
+ set_if_up(ifc, up); /* And speed and duplex */
+
+ return 0;
+}
+
int bridge_notify(int br_index, int if_index, int newlink,
unsigned flags)
{
@@ -976,5 +998,97 @@ int CTL_set_debug_level(int level)
return 0;
}
+int CTL_add_bridge(char *name)
+{
+ int br_index, up;
+ struct ifdata *br = NULL;
+
+ br_index = if_nametoindex(name);
+ if(br_index == 0) {
+ ERROR("bridge %s not exist", name);
+ return 0;
+ }
+
+ br = find_if(br_index);
+ if (br && !br->is_bridge) {
+ ERROR("Existed interface %s is not a bridge.", name);
+ return 0;
+ }
+
+ if (!br && is_bridge(name))
+ br = create_if(br_index, NULL);
+
+ if (!br) {
+ ERROR("Couldn't create data for bridge interface %s", name);
+ return 0;
+ }
+
+ up = get_link_status(name);
+ if(br->up != up)
+ set_br_up(br, up);
+
+ INFO("bridge %s created, if_index is %d, link status %d.", name, br_index, up);
+ return 0;
+}
+
+int CTL_add_bridge_port(char *br_name, char *pt_name)
+{
+ int br_index, if_index, up;
+ struct ifdata *br, *br_port;
+
+ br_index = if_nametoindex(br_name);
+ if(br_index == 0) {
+ ERROR("bridge %s not exist", br_name);
+ return 0;
+ }
+
+ if_index = if_nametoindex(pt_name);
+ if(if_index == 0) {
+ ERROR("bridge port %s not exist", pt_name);
+ return 0;
+ }
+
+ br = find_if(br_index);
+ if (br && !br->is_bridge) {
+ ERROR("Existed interface %s is not a bridge.", br_name);
+ return 0;
+ }
+
+ if (!br) {
+ ERROR("Couldn't find data for bridge interface %s", br_name);
+ return 0;
+ }
+
+ br_port = find_if(if_index);
+ if (br_port) {
+ if (br_port->is_bridge) {
+ ERROR("interface %s is a bridge, can't become a bridge port", pt_name);
+ return 0;
+ }
+
+ if (br_port->master != br) {
+ INFO("Device %d has come to bridge %d. Missed notify for deletion from bridge %d",
+ if_index, br_index, br_port->master->if_index);
+ delete_if(br_port);
+ br_port = NULL;
+ }
+ }
+
+ if (!br_port)
+ br_port = create_if(if_index, br);
+
+ if (!br_port) {
+ ERROR("Couldn't create data for interface %d (master %d)", if_index, br_index);
+ return 0;
+ }
+
+ up = get_link_status(pt_name);
+ if(br_port->up != up)
+ set_if_up(br_port, up);
+
+ INFO("bridge port %s created, master is %s, link status %d.", pt_name, br_name, up);
+ return 0;
+}
+
#undef CTL_CHECK_BRIDGE_PORT
#undef CTL_CHECK_BRIDGE
diff --git a/brmon.c b/brmon.c
index 4c4e490..96a1113 100644
--- a/brmon.c
+++ b/brmon.c
@@ -47,27 +47,12 @@ static int dump_msg(const struct sockaddr_nl *who, struct nlmsghdr *n,
if (len < 0)
return -1;
- if (ifi->ifi_family != AF_BRIDGE && ifi->ifi_family != AF_UNSPEC)
- return 0;
-
if (n->nlmsg_type != RTM_NEWLINK &&
n->nlmsg_type != RTM_DELLINK)
return 0;
parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
- /* Check if we got this from bonding */
- if (tb[IFLA_MASTER] && ifi->ifi_family != AF_BRIDGE)
- return 0;
-
- /* Check if hearing our own state changes */
- if (n->nlmsg_type == RTM_NEWLINK && tb[IFLA_PROTINFO]) {
- uint8_t state = *(uint8_t *)RTA_DATA(tb[IFLA_PROTINFO]);
-
- if (state != BR_STATE_DISABLED)
- return 0;
- }
-
if (tb[IFLA_IFNAME] == NULL) {
fprintf(stderr, "BUG: nil ifname\n");
return -1;
@@ -87,10 +72,10 @@ static int dump_msg(const struct sockaddr_nl *who, struct nlmsghdr *n,
fprintf(fp, "\n");
fflush(fp);
-
- bridge_notify(master, ifi->ifi_index,
- (n->nlmsg_type == RTM_NEWLINK),
- ifi->ifi_flags);
+ if(get_topology_mode() == AUTO_TOPOLOGY)
+ bridge_notify(master, ifi->ifi_index, (n->nlmsg_type == RTM_NEWLINK), ifi->ifi_flags);
+ else
+ bridge_notify_simple(master, ifi->ifi_index, (n->nlmsg_type == RTM_NEWLINK), ifi->ifi_flags);
return 0;
}
diff --git a/ctl_cli_wrap.c b/ctl_cli_wrap.c
index 72665a8..8ad65c4 100644
--- a/ctl_cli_wrap.c
+++ b/ctl_cli_wrap.c
@@ -33,6 +33,8 @@ CLIENT_SIDE_FUNCTION(enable_bridge_rstp)
CLIENT_SIDE_FUNCTION(get_port_state)
CLIENT_SIDE_FUNCTION(set_port_config)
CLIENT_SIDE_FUNCTION(set_debug_level)
+ CLIENT_SIDE_FUNCTION(add_bridge)
+ CLIENT_SIDE_FUNCTION(add_bridge_port)
#include <base.h>
const char *CTL_error_explanation(int err_no)
{
diff --git a/ctl_functions.h b/ctl_functions.h
index 9d630f6..4a04d62 100644
--- a/ctl_functions.h
+++ b/ctl_functions.h
@@ -42,6 +42,10 @@ int CTL_set_port_config(int br_index, int port_index, UID_STP_PORT_CFG_T * cfg);
int CTL_set_debug_level(int level);
+int CTL_add_bridge(char *name);
+
+int CTL_add_bridge_port(char *br_name, char *pt_name);
+
#define CTL_ERRORS \
CHOOSE(Err_Interface_not_a_bridge), \
CHOOSE(Err_Bridge_RSTP_not_enabled), \
diff --git a/ctl_main.c b/ctl_main.c
index 83dee9f..a90e185 100644
--- a/ctl_main.c
+++ b/ctl_main.c
@@ -728,6 +728,16 @@ static int cmd_debuglevel(int argc, char *const *argv)
return CTL_set_debug_level(getuint(argv[1]));
}
+static int cmd_addBridge(int argc, char *const *argv)
+{
+ return CTL_add_bridge(argv[1]);
+}
+
+static int cmd_addBridgePort(int argc, char *const *argv)
+{
+ return CTL_add_bridge_port(argv[1], argv[2]);
+}
+
struct command {
int nargs;
int optargs;
@@ -770,6 +780,10 @@ static const struct command commands[] = {
{2, 0, "portmcheck", cmd_portmcheck,
"<bridge> <port>\ttry to get back from STP to RSTP mode"},
{1, 0, "debuglevel", cmd_debuglevel, "<level>\t\tLevel of verbosity"},
+ {1, 0, "addBridge", cmd_addBridge,
+ "<bridge>\tadd new bridge"},
+ {2, 0, "addBridgePort", cmd_addBridgePort,
+ "<bridge> <port>\tadd new bridge port in an existed bridge"},
};
const struct command *command_lookup(const char *cmd)
diff --git a/ctl_socket.c b/ctl_socket.c
index f37e8b1..1438e5f 100644
--- a/ctl_socket.c
+++ b/ctl_socket.c
@@ -68,6 +68,8 @@ int handle_message(int cmd, void *inbuf, int lin, void *outbuf, int *lout)
SERVER_MESSAGE_CASE(get_port_state);
SERVER_MESSAGE_CASE(set_port_config);
SERVER_MESSAGE_CASE(set_debug_level);
+ SERVER_MESSAGE_CASE(add_bridge);
+ SERVER_MESSAGE_CASE(add_bridge_port);
default:
ERROR("CTL: Unknown command %d", cmd);
diff --git a/ctl_socket.h b/ctl_socket.h
index 089a717..a4b7c7a 100644
--- a/ctl_socket.h
+++ b/ctl_socket.h
@@ -149,6 +149,37 @@ struct set_debug_level_OUT {
#define set_debug_level_COPY_OUT ({ (void)0; })
#define set_debug_level_CALL (in->level)
+#if 0
+int CTL_add_bridge(char *name);
+#endif
+#define CMD_CODE_add_bridge 107
+#define add_bridge_ARGS (char *name)
+struct add_bridge_IN {
+ char name[64];
+};
+struct add_bridge_OUT {
+};
+#define add_bridge_COPY_IN \
+ ({ strncpy(in->name, name, sizeof(in->name)); })
+#define add_bridge_COPY_OUT ({ (void)0; })
+#define add_bridge_CALL (in->name)
+
+#if 0
+int CTL_add_bridge_port(char *br_name, char *pt_name);
+#endif
+#define CMD_CODE_add_bridge_port 108
+#define add_bridge_port_ARGS (char *br_name, char *pt_name)
+struct add_bridge_port_IN {
+ char br_name[64];
+ char pt_name[64];
+};
+struct add_bridge_port_OUT {
+};
+#define add_bridge_port_COPY_IN \
+ ({ strncpy(in->br_name, br_name, sizeof(in->br_name)); strncpy(in->pt_name, pt_name, sizeof(in->pt_name)); })
+#define add_bridge_port_COPY_OUT ({ (void)0; })
+#define add_bridge_port_CALL (in->br_name, in->pt_name)
+
/* General case part in ctl command server switch */
#define SERVER_MESSAGE_CASE(name) \
case CMD_CODE_ ## name : do { \
diff --git a/main.c b/main.c
index a8329b3..33eebec 100644
--- a/main.c
+++ b/main.c
@@ -41,6 +41,17 @@
static int become_daemon = 1;
static int is_daemon = 0;
int log_level = LOG_LEVEL_DEFAULT;
+static topology_mode_t topology_mode = MANUAL_TOPOLOGY;
+
+void set_topology_mode(topology_mode_t mode)
+{
+ topology_mode = mode;
+}
+
+topology_mode_t get_topology_mode(void)
+{
+ return topology_mode;
+}
static void handle_signal(int signo)
{
@@ -63,8 +74,11 @@ static int setup_signals(void)
int main(int argc, char *argv[])
{
int c,ret;
- while ((c = getopt(argc, argv, "dv:")) != -1) {
+ while ((c = getopt(argc, argv, "adv:")) != -1) {
switch (c) {
+ case 'a':
+ set_topology_mode(AUTO_TOPOLOGY);
+ break;
case 'd':
become_daemon = 0;
break;
diff --git a/netif_utils.c b/netif_utils.c
index 719581c..b3e7baa 100644
--- a/netif_utils.c
+++ b/netif_utils.c
@@ -86,6 +86,27 @@ int ethtool_get_speed_duplex(char *ifname, int *speed, int *duplex)
return 0;
}
+int get_link_status(const char *name)
+{
+ int s = -1;
+ struct ifreq ifr = {};
+
+ if(!name) return 0;
+
+ if((s = socket(AF_INET, SOCK_DGRAM, 0)) <= 0) return 0;
+
+ strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+
+ if(0 != ioctl(s, SIOCGIFFLAGS, &ifr)) {
+ close(s);
+ return 0;
+ }
+
+ close(s);
+
+ return ((ifr.ifr_flags & (IFF_UP|IFF_RUNNING)) == (IFF_UP|IFF_RUNNING));
+}
+
/********* Sysfs based utility functions *************/
/* This sysfs stuff might break with interface renames */
diff --git a/netif_utils.h b/netif_utils.h
index 99c99d5..cc45e02 100644
--- a/netif_utils.h
+++ b/netif_utils.h
@@ -32,6 +32,8 @@ int get_hwaddr(char *ifname, unsigned char *hwaddr);
int ethtool_get_speed_duplex(char *ifname, int *speed, int *duplex);
+int get_link_status(const char *name);
+
/********* Sysfs based utility functions *************/
int is_bridge(char *if_name);
This diff is collapsed.
diff --git a/ctl_socket.c b/ctl_socket.c
index 301d410..dafc86f 100644
--- a/ctl_socket.c
+++ b/ctl_socket.c
@@ -89,7 +89,7 @@ void ctl_rcv_handler(uint32_t events, struct epoll_event_handler *p)
struct msghdr msg;
struct sockaddr_un sa;
struct iovec iov[2];
- int l;
+ int l, cmd;
msg.msg_name = &sa;
msg.msg_namelen = sizeof(sa);
@@ -110,12 +110,15 @@ void ctl_rcv_handler(uint32_t events, struct epoll_event_handler *p)
return;
}
- if (mhdr.lout)
- mhdr.res = handle_message(mhdr.cmd, msg_inbuf, mhdr.lin,
- msg_outbuf, &mhdr.lout);
- else
- mhdr.res = handle_message(mhdr.cmd, msg_inbuf, mhdr.lin,
- NULL, NULL);
+ cmd = mhdr.cmd;
+ if(cmd != CMD_CODE_enable_bridge_rstp) {
+ if (mhdr.lout)
+ mhdr.res = handle_message(mhdr.cmd, msg_inbuf, mhdr.lin,
+ msg_outbuf, &mhdr.lout);
+ else
+ mhdr.res = handle_message(mhdr.cmd, msg_inbuf, mhdr.lin,
+ NULL, NULL);
+ }
if (mhdr.res < 0)
mhdr.lout = 0;
@@ -129,6 +132,11 @@ void ctl_rcv_handler(uint32_t events, struct epoll_event_handler *p)
("CTL: Couldn't send full response, sent %d bytes instead of %zd.",
l, sizeof(mhdr) + mhdr.lout);
}
+
+ if(cmd == CMD_CODE_enable_bridge_rstp){
+ handle_message(cmd, msg_inbuf, mhdr.lin,
+ NULL, NULL);
+ }
}
struct epoll_event_handler ctl_handler;
diff -Nur a/bridge_track.c b/bridge_track.c
--- a/bridge_track.c 2015-04-03 16:13:27.109884142 -0700
+++ b/bridge_track.c 2015-04-03 16:13:54.125884822 -0700
@@ -29,6 +29,7 @@
#include <unistd.h>
#include <net/if.h>
#include <stdlib.h>
+#include <netinet/in.h>
#include <linux/if_bridge.h>
#include <arpa/inet.h>
#include <sys/types.h>
diff -Nur a/qca_switch.c b/qca_switch.c
--- a/qca_switch.c 2015-04-03 16:13:27.109884142 -0700
+++ b/qca_switch.c 2015-04-03 16:14:04.325885079 -0700
@@ -1,6 +1,7 @@
#include <stdarg.h>
#include <unistd.h>
#include <net/if.h>
+#include <netinet/in.h>
#include <linux/if_bridge.h>
#include <sys/types.h>
#include <arpa/inet.h>
diff -Nur a/ctl_socket_client.c b/ctl_socket_client.c
--- a/ctl_socket_client.c 2015-05-20 16:17:57.458267282 -0700
+++ b/ctl_socket_client.c 2015-05-20 16:18:23.270267932 -0700
@@ -96,6 +96,7 @@
msg.msg_control = NULL;
msg.msg_controllen = 0;
+ mhdr.res = 0;
mhdr.cmd = cmd;
mhdr.lin = lin;
mhdr.lout = lout != NULL ? *lout : 0;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment