summaryrefslogtreecommitdiffstats
path: root/net/bridge/br.c
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>1997-04-29 21:13:14 +0000
committer <ralf@linux-mips.org>1997-04-29 21:13:14 +0000
commit19c9bba94152148523ba0f7ef7cffe3d45656b11 (patch)
tree40b1cb534496a7f1ca0f5c314a523c69f1fee464 /net/bridge/br.c
parent7206675c40394c78a90e74812bbdbf8cf3cca1be (diff)
Import of Linux/MIPS 2.1.36
Diffstat (limited to 'net/bridge/br.c')
-rw-r--r--net/bridge/br.c396
1 files changed, 239 insertions, 157 deletions
diff --git a/net/bridge/br.c b/net/bridge/br.c
index 70e54dbc3..7e8cd2a23 100644
--- a/net/bridge/br.c
+++ b/net/bridge/br.c
@@ -14,6 +14,7 @@
* 2 of the License, or (at your option) any later version.
*
* Fixes:
+ * Yury Shevchuk : Bridge with non bridging ports
*
* Todo:
* Don't bring up devices automatically. Start ports disabled
@@ -30,6 +31,7 @@
#include <linux/types.h>
#include <linux/socket.h>
#include <linux/in.h>
+
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/timer.h>
@@ -40,30 +42,88 @@
#include <linux/string.h>
#include <linux/skbuff.h>
#include <linux/if_arp.h>
+#include <linux/init.h>
#include <asm/uaccess.h>
#include <asm/system.h>
#include <net/br.h>
+static void transmit_config(int port_no);
+static int root_bridge(void);
+static int supersedes_port_info(int port_no, Config_bpdu *config);
+static void record_config_information(int port_no, Config_bpdu *config);
+static void record_config_timeout_values(Config_bpdu *config);
+static void config_bpdu_generation(void);
+static int designated_port(int port_no);
+static void reply(int port_no);
+static void transmit_tcn(void);
+static void configuration_update(void);
+static void root_selection(void);
+static void designated_port_selection(void);
+static void become_designated_port(int port_no);
+static void port_state_selection(void);
+static void make_forwarding(int port_no);
+static void topology_change_detection(void);
+static void topology_change_acknowledged(void);
+static void acknowledge_topology_change(int port_no);
+static void make_blocking(int port_no);
+static void set_port_state(int port_no, int state);
+static void received_config_bpdu(int port_no, Config_bpdu *config);
+static void received_tcn_bpdu(int port_no, Tcn_bpdu *tcn);
+static void hello_timer_expiry(void);
+static void message_age_timer_expiry(int port_no);
+static void forward_delay_timer_expiry(int port_no);
+static int designated_for_some_port(void);
+static void tcn_timer_expiry(void);
+static void topology_change_timer_expiry(void);
+static void hold_timer_expiry(int port_no);
+static void br_init_port(int port_no);
+static void enable_port(int port_no);
+static void disable_port(int port_no);
+static void set_bridge_priority(bridge_id_t *new_bridge_id);
+static void set_port_priority(int port_no, unsigned short new_port_id);
+static void set_path_cost(int port_no, unsigned short path_cost);
+static void start_hello_timer(void);
+static void stop_hello_timer(void);
+static int hello_timer_expired(void);
+static void start_tcn_timer(void);
+static void stop_tcn_timer(void);
+static int tcn_timer_expired(void);
+static void start_topology_change_timer(void);
+static void stop_topology_change_timer(void);
+static int topology_change_timer_expired(void);
+static void start_message_age_timer(int port_no, unsigned short message_age);
+static void stop_message_age_timer(int port_no);
+static int message_age_timer_expired(int port_no);
+static void start_forward_delay_timer(int port_no);
+static void stop_forward_delay_timer(int port_no);
+static int forward_delay_timer_expired(int port_no);
+static void start_hold_timer(int port_no);
+static void stop_hold_timer(int port_no);
+static int hold_timer_expired(int port_no);
static int br_device_event(struct notifier_block *dnot, unsigned long event, void *ptr);
static void br_tick(unsigned long arg);
-int br_forward(struct sk_buff *skb, int port); /* 3.7 */
-int br_port_cost(struct device *dev); /* 4.10.2 */
-void br_bpdu(struct sk_buff *skb); /* consumes skb */
-int br_tx_frame(struct sk_buff *skb);
-int br_cmp(unsigned int *a, unsigned int *b);
-
-unsigned char bridge_ula[ETH_ALEN] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 };
-
-Bridge_data bridge_info; /* (4.5.3) */
+static int br_forward(struct sk_buff *skb, int port); /* 3.7 */
+static int br_port_cost(struct device *dev); /* 4.10.2 */
+static void br_bpdu(struct sk_buff *skb); /* consumes skb */
+static int br_cmp(unsigned int *a, unsigned int *b);
+static int send_tcn_bpdu(int port_no, Tcn_bpdu *bpdu);
+static int send_config_bpdu(int port_no, Config_bpdu *config_bpdu);
+static int find_port(struct device *dev);
+static int br_flood(struct sk_buff *skb, int port);
+static int br_drop(struct sk_buff *skb);
+static int br_learn(struct sk_buff *skb, int port); /* 3.8 */
+
+static unsigned char bridge_ula[ETH_ALEN] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 };
+static Bridge_data bridge_info; /* (4.5.3) */
Port_data port_info[All_ports]; /* (4.5.5) */
Config_bpdu config_bpdu[All_ports];
Tcn_bpdu tcn_bpdu[All_ports];
-Timer hello_timer; /* (4.5.4.1) */
-Timer tcn_timer; /* (4.5.4.2) */
-Timer topology_change_timer; /* (4.5.4.3) */
-Timer message_age_timer[All_ports]; /* (4.5.6.1) */
-Timer forward_delay_timer[All_ports]; /* (4.5.6.2) */
-Timer hold_timer[All_ports]; /* (4.5.6.3) */
+static Timer hello_timer; /* (4.5.4.1) */
+static Timer tcn_timer; /* (4.5.4.2) */
+static Timer topology_change_timer; /* (4.5.4.3) */
+static Timer message_age_timer[All_ports]; /* (4.5.6.1) */
+static Timer forward_delay_timer[All_ports]; /* (4.5.6.2) */
+static Timer hold_timer[All_ports]; /* (4.5.6.3) */
/* entries timeout after this many seconds */
unsigned int fdb_aging_time = FDB_TIMEOUT;
@@ -117,7 +177,7 @@ int br_protocol_ok(unsigned short protocol)
/* Add a protocol to be handled opposite to the standard policy of the bridge */
-int br_add_exempt_protocol(unsigned short p)
+static int br_add_exempt_protocol(unsigned short p)
{
unsigned x;
if (p == 0) return -EINVAL;
@@ -133,7 +193,7 @@ int br_add_exempt_protocol(unsigned short p)
}
/* Valid Policies are 0=No Protocols bridged 1=Bridge all protocols */
-int br_set_policy(int policy)
+static int br_set_policy(int policy)
{
if (policy>1) return -EINVAL;
br_stats.policy=policy;
@@ -154,7 +214,7 @@ int br_set_policy(int policy)
* 802.1d bridging protocol.
*/
-void transmit_config(int port_no) /* (4.6.1) */
+static void transmit_config(int port_no) /* (4.6.1) */
{
if (hold_timer[port_no].active) { /* (4.6.1.3.1) */
port_info[port_no].config_pending = TRUE; /* (4.6.1.3.1) */
@@ -197,13 +257,13 @@ void transmit_config(int port_no) /* (4.6.1) */
}
}
-int root_bridge(void)
+static int root_bridge(void)
{
return (br_cmp(bridge_info.designated_root.BRIDGE_ID,
bridge_info.bridge_id.BRIDGE_ID)?FALSE:TRUE);
}
-int supersedes_port_info(int port_no, Config_bpdu *config) /* (4.6.2.2) */
+static int supersedes_port_info(int port_no, Config_bpdu *config) /* (4.6.2.2) */
{
return (
(br_cmp(config->root_id.BRIDGE_ID,
@@ -240,7 +300,7 @@ int supersedes_port_info(int port_no, Config_bpdu *config) /* (4.6.2.2) */
);
}
-void record_config_information(int port_no, Config_bpdu *config) /* (4.6.2) */
+static void record_config_information(int port_no, Config_bpdu *config) /* (4.6.2) */
{
port_info[port_no].designated_root = config->root_id; /* (4.6.2.3.1) */
port_info[port_no].designated_cost = config->root_path_cost;
@@ -249,7 +309,7 @@ void record_config_information(int port_no, Config_bpdu *config) /* (4.6.2) *
start_message_age_timer(port_no, config->message_age); /* (4.6.2.3.2) */
}
-void record_config_timeout_values(Config_bpdu *config) /* (4.6.3) */
+static void record_config_timeout_values(Config_bpdu *config) /* (4.6.3) */
{
bridge_info.max_age = config->max_age; /* (4.6.3.3) */
bridge_info.hello_time = config->hello_time;
@@ -258,7 +318,7 @@ void record_config_timeout_values(Config_bpdu *config) /* (4.6.3) */
bridge_info.top_change = 1;
}
-void config_bpdu_generation(void)
+static void config_bpdu_generation(void)
{ /* (4.6.4) */
int port_no;
for (port_no = One; port_no <= No_of_ports; port_no++) { /* (4.6.4.3) */
@@ -271,7 +331,7 @@ void config_bpdu_generation(void)
}
}
-int designated_port(int port_no)
+static int designated_port(int port_no)
{
return ((br_cmp(port_info[port_no].designated_bridge.BRIDGE_ID,
bridge_info.bridge_id.BRIDGE_ID) == 0
@@ -283,12 +343,12 @@ int designated_port(int port_no)
);
}
-void reply(int port_no) /* (4.6.5) */
+static void reply(int port_no) /* (4.6.5) */
{
transmit_config(port_no); /* (4.6.5.3) */
}
-void transmit_tcn(void)
+static void transmit_tcn(void)
{ /* (4.6.6) */
int port_no;
@@ -297,7 +357,7 @@ void transmit_tcn(void)
send_tcn_bpdu(port_no, &tcn_bpdu[bridge_info.root_port]); /* (4.6.6.3) */
}
-void configuration_update(void) /* (4.6.7) */
+static void configuration_update(void) /* (4.6.7) */
{
root_selection(); /* (4.6.7.3.1) */
/* (4.6.8.2) */
@@ -305,7 +365,7 @@ void configuration_update(void) /* (4.6.7) */
/* (4.6.9.2) */
}
-void root_selection(void)
+static void root_selection(void)
{ /* (4.6.8) */
int root_port;
int port_no;
@@ -385,7 +445,7 @@ void root_selection(void)
}
}
-void designated_port_selection(void)
+static void designated_port_selection(void)
{ /* (4.6.9) */
int port_no;
@@ -422,7 +482,7 @@ void designated_port_selection(void)
}
}
-void become_designated_port(int port_no)
+static void become_designated_port(int port_no)
{ /* (4.6.10) */
/* (4.6.10.3.1) */
@@ -435,7 +495,7 @@ void become_designated_port(int port_no)
port_info[port_no].designated_port = port_info[port_no].port_id;
}
-void port_state_selection(void)
+static void port_state_selection(void)
{ /* (4.6.11) */
int port_no;
for (port_no = One; port_no <= No_of_ports; port_no++) {
@@ -455,7 +515,7 @@ void port_state_selection(void)
}
-void make_forwarding(int port_no)
+static void make_forwarding(int port_no)
{ /* (4.6.12) */
if (port_info[port_no].state == Blocking) { /* (4.6.12.3) */
set_port_state(port_no, Listening); /* (4.6.12.3.1) */
@@ -463,7 +523,7 @@ void make_forwarding(int port_no)
}
}
-void topology_change_detection(void)
+static void topology_change_detection(void)
{ /* (4.6.14) */
if (root_bridge()) { /* (4.6.14.3.1) */
bridge_info.top_change = 1;
@@ -475,19 +535,19 @@ void topology_change_detection(void)
bridge_info.top_change = 1;
}
-void topology_change_acknowledged(void)
+static void topology_change_acknowledged(void)
{ /* (4.6.15) */
bridge_info.top_change_detected = 0;
stop_tcn_timer(); /* (4.6.15.3.2) */
}
-void acknowledge_topology_change(int port_no)
+static void acknowledge_topology_change(int port_no)
{ /* (4.6.16) */
port_info[port_no].top_change_ack = 1;
transmit_config(port_no); /* (4.6.16.3.2) */
}
-void make_blocking(int port_no) /* (4.6.13) */
+static void make_blocking(int port_no) /* (4.6.13) */
{
if ((port_info[port_no].state != Disabled)
@@ -507,12 +567,12 @@ void make_blocking(int port_no) /* (4.6.13) */
}
}
-void set_port_state(int port_no, int state)
+static void set_port_state(int port_no, int state)
{
port_info[port_no].state = state;
}
-void received_config_bpdu(int port_no, Config_bpdu *config) /* (4.7.1) */
+static void received_config_bpdu(int port_no, Config_bpdu *config) /* (4.7.1) */
{
int root;
@@ -549,7 +609,7 @@ void received_config_bpdu(int port_no, Config_bpdu *config) /* (4.7.1) */
}
}
-void received_tcn_bpdu(int port_no, Tcn_bpdu *tcn) /* (4.7.2) */
+static void received_tcn_bpdu(int port_no, Tcn_bpdu *tcn) /* (4.7.2) */
{
if (port_info[port_no].state != Disabled) {
if (designated_port(port_no)) {
@@ -560,13 +620,13 @@ void received_tcn_bpdu(int port_no, Tcn_bpdu *tcn) /* (4.7.2) */
}
}
-void hello_timer_expiry(void)
+static void hello_timer_expiry(void)
{ /* (4.7.3) */
config_bpdu_generation(); /* (4.6.4.2.2) */
start_hello_timer();
}
-void message_age_timer_expiry(int port_no) /* (4.7.4) */
+static void message_age_timer_expiry(int port_no) /* (4.7.4) */
{
int root;
root = root_bridge();
@@ -591,7 +651,7 @@ void message_age_timer_expiry(int port_no) /* (4.7.4) */
}
}
-void forward_delay_timer_expiry(int port_no) /* (4.7.5) */
+static void forward_delay_timer_expiry(int port_no) /* (4.7.5) */
{
if (port_info[port_no].state == Listening) { /* (4.7.5.1) */
set_port_state(port_no, Learning); /* (4.7.5.1.1) */
@@ -605,7 +665,7 @@ void forward_delay_timer_expiry(int port_no) /* (4.7.5) */
}
}
-int designated_for_some_port(void)
+static int designated_for_some_port(void)
{
int port_no;
@@ -620,27 +680,27 @@ int designated_for_some_port(void)
return (FALSE);
}
-void tcn_timer_expiry(void)
+static void tcn_timer_expiry(void)
{ /* (4.7.6) */
transmit_tcn(); /* (4.7.6.1) */
start_tcn_timer(); /* (4.7.6.2) */
}
-void topology_change_timer_expiry(void)
+static void topology_change_timer_expiry(void)
{ /* (4.7.7) */
bridge_info.top_change_detected = 0;
bridge_info.top_change = 0;
/* (4.7.7.2) */
}
-void hold_timer_expiry(int port_no) /* (4.7.8) */
+static void hold_timer_expiry(int port_no) /* (4.7.8) */
{
if (port_info[port_no].config_pending) {
transmit_config(port_no); /* (4.7.8.1) */
} /* (4.6.1.2.3) */
}
-void br_init(void)
+__initfunc(void br_init(void))
{ /* (4.8.1) */
int port_no;
@@ -681,7 +741,7 @@ void br_init(void)
/*start_hello_timer();*/
}
-void br_init_port(int port_no)
+static void br_init_port(int port_no)
{
become_designated_port(port_no); /* (4.8.1.4.1) */
set_port_state(port_no, Blocking); /* (4.8.1.4.2) */
@@ -692,13 +752,13 @@ void br_init_port(int port_no)
stop_hold_timer(port_no); /* (4.8.1.4.7) */
}
-void enable_port(int port_no) /* (4.8.2) */
+static void enable_port(int port_no) /* (4.8.2) */
{
br_init_port(port_no);
port_state_selection(); /* (4.8.2.7) */
} /* */
-void disable_port(int port_no) /* (4.8.3) */
+static void disable_port(int port_no) /* (4.8.3) */
{
int root;
@@ -723,7 +783,8 @@ void disable_port(int port_no) /* (4.8.3) */
}
-void set_bridge_priority(bridge_id_t *new_bridge_id) /* (4.8.4) */
+static void set_bridge_priority(bridge_id_t *new_bridge_id)
+ /* (4.8.4) */
{
int root;
@@ -749,7 +810,8 @@ void set_bridge_priority(bridge_id_t *new_bridge_id) /* (4.8.4) */
}
}
-void set_port_priority(int port_no, unsigned short new_port_id) /* (4.8.5) */
+static void set_port_priority(int port_no, unsigned short new_port_id)
+ /* (4.8.5) */
{
if (designated_port(port_no)) { /* (4.8.5.2) */
port_info[port_no].designated_port = new_port_id;
@@ -769,7 +831,8 @@ void set_port_priority(int port_no, unsigned short new_port_id) /* (4.8.5) *
}
}
-void set_path_cost(int port_no, unsigned short path_cost) /* (4.8.6) */
+static void set_path_cost(int port_no, unsigned short path_cost)
+ /* (4.8.6) */
{
port_info[port_no].path_cost = path_cost; /* (4.8.6.1) */
configuration_update(); /* (4.8.6.2) */
@@ -806,18 +869,18 @@ static void br_tick(unsigned long arg)
add_timer(&tl);
}
-void start_hello_timer(void)
+static void start_hello_timer(void)
{
hello_timer.value = 0;
hello_timer.active = TRUE;
}
-void stop_hello_timer(void)
+static void stop_hello_timer(void)
{
hello_timer.active = FALSE;
}
-int hello_timer_expired(void)
+static int hello_timer_expired(void)
{
if (hello_timer.active && (++hello_timer.value >= bridge_info.hello_time)) {
hello_timer.active = FALSE;
@@ -826,18 +889,18 @@ int hello_timer_expired(void)
return (FALSE);
}
-void start_tcn_timer(void)
+static void start_tcn_timer(void)
{
tcn_timer.value = 0;
tcn_timer.active = TRUE;
}
-void stop_tcn_timer(void)
+static void stop_tcn_timer(void)
{
tcn_timer.active = FALSE;
}
-int tcn_timer_expired(void)
+static int tcn_timer_expired(void)
{
if (tcn_timer.active && (++tcn_timer.value >=
bridge_info.bridge_hello_time)) {
@@ -848,18 +911,18 @@ int tcn_timer_expired(void)
}
-void start_topology_change_timer(void)
+static void start_topology_change_timer(void)
{
topology_change_timer.value = 0;
topology_change_timer.active = TRUE;
}
-void stop_topology_change_timer(void)
+static void stop_topology_change_timer(void)
{
topology_change_timer.active = FALSE;
}
-int topology_change_timer_expired(void)
+static int topology_change_timer_expired(void)
{
if (topology_change_timer.active
&& (++topology_change_timer.value
@@ -871,18 +934,18 @@ int topology_change_timer_expired(void)
return (FALSE);
}
-void start_message_age_timer(int port_no, unsigned short message_age)
+static void start_message_age_timer(int port_no, unsigned short message_age)
{
message_age_timer[port_no].value = message_age;
message_age_timer[port_no].active = TRUE;
}
-void stop_message_age_timer(int port_no)
+static void stop_message_age_timer(int port_no)
{
message_age_timer[port_no].active = FALSE;
}
-int message_age_timer_expired(int port_no)
+static int message_age_timer_expired(int port_no)
{
if (message_age_timer[port_no].active &&
(++message_age_timer[port_no].value >= bridge_info.max_age)) {
@@ -892,18 +955,18 @@ int message_age_timer_expired(int port_no)
return (FALSE);
}
-void start_forward_delay_timer(int port_no)
+static void start_forward_delay_timer(int port_no)
{
forward_delay_timer[port_no].value = 0;
forward_delay_timer[port_no].active = TRUE;
}
-void stop_forward_delay_timer(int port_no)
+static void stop_forward_delay_timer(int port_no)
{
forward_delay_timer[port_no].active = FALSE;
}
-int forward_delay_timer_expired(int port_no)
+static int forward_delay_timer_expired(int port_no)
{
if (forward_delay_timer[port_no].active &&
(++forward_delay_timer[port_no].value >= bridge_info.forward_delay)) {
@@ -913,19 +976,18 @@ int forward_delay_timer_expired(int port_no)
return (FALSE);
}
-void start_hold_timer(int port_no)
+static void start_hold_timer(int port_no)
{
hold_timer[port_no].value = 0;
hold_timer[port_no].active = TRUE;
}
-void stop_hold_timer(int port_no)
+static void stop_hold_timer(int port_no)
{
hold_timer[port_no].active = FALSE;
}
-
-int hold_timer_expired(int port_no)
+static int hold_timer_expired(int port_no)
{
if (hold_timer[port_no].active &&
(++hold_timer[port_no].value >= bridge_info.hold_time)) {
@@ -936,12 +998,13 @@ int hold_timer_expired(int port_no)
}
-int send_config_bpdu(int port_no, Config_bpdu *config_bpdu)
+static int send_config_bpdu(int port_no, Config_bpdu *config_bpdu)
{
struct sk_buff *skb;
struct device *dev = port_info[port_no].dev;
int size;
unsigned long flags;
+struct ethhdr *eth;
if (port_info[port_no].state == Disabled) {
printk(KERN_DEBUG "send_config_bpdu: port %i not valid\n",port_no);
@@ -952,34 +1015,34 @@ unsigned long flags;
/*
* create and send the message
*/
- size = sizeof(Config_bpdu) + dev->hard_header_len;
+ size = dev->hard_header_len + sizeof(Config_bpdu);
skb = alloc_skb(size, GFP_ATOMIC);
if (skb == NULL) {
printk(KERN_DEBUG "send_config_bpdu: no skb available\n");
return(-1);
}
skb->dev = dev;
- skb->free = 1;
- skb->h.eth = (struct ethhdr *)skb_put(skb, size);
- memcpy(skb->h.eth->h_dest, bridge_ula, ETH_ALEN);
- memcpy(skb->h.eth->h_source, dev->dev_addr, ETH_ALEN);
+ skb->mac.raw = skb->h.raw = skb_put(skb, size);
+ eth = skb->mac.ethernet;
+ memcpy(eth->h_dest, bridge_ula, ETH_ALEN);
+ memcpy(eth->h_source, dev->dev_addr, ETH_ALEN);
if (br_stats.flags & BR_DEBUG)
printk("port %i src %02x:%02x:%02x:%02x:%02x:%02x\
dest %02x:%02x:%02x:%02x:%02x:%02x\n",
port_no,
- skb->h.eth->h_source[0],
- skb->h.eth->h_source[1],
- skb->h.eth->h_source[2],
- skb->h.eth->h_source[3],
- skb->h.eth->h_source[4],
- skb->h.eth->h_source[5],
- skb->h.eth->h_dest[0],
- skb->h.eth->h_dest[1],
- skb->h.eth->h_dest[2],
- skb->h.eth->h_dest[3],
- skb->h.eth->h_dest[4],
- skb->h.eth->h_dest[5]);
- skb->h.eth->h_proto = htonl(0x8038); /* XXX verify */
+ eth->h_source[0],
+ eth->h_source[1],
+ eth->h_source[2],
+ eth->h_source[3],
+ eth->h_source[4],
+ eth->h_source[5],
+ eth->h_dest[0],
+ eth->h_dest[1],
+ eth->h_dest[2],
+ eth->h_dest[3],
+ eth->h_dest[4],
+ eth->h_dest[5]);
+ eth->h_proto = htons(0x8038);
skb->h.raw += skb->dev->hard_header_len;
memcpy(skb->h.raw, config_bpdu, sizeof(Config_bpdu));
@@ -987,7 +1050,6 @@ unsigned long flags;
/* won't get bridged again... */
skb->pkt_bridged = IS_BRIDGED;
skb->arp = 1; /* do not resolve... */
- skb->h.raw = skb->data + ETH_HLEN;
save_flags(flags);
cli();
skb_queue_tail(dev->buffs, skb);
@@ -995,12 +1057,13 @@ unsigned long flags;
return(0);
}
-int send_tcn_bpdu(int port_no, Tcn_bpdu *bpdu)
+static int send_tcn_bpdu(int port_no, Tcn_bpdu *bpdu)
{
struct sk_buff *skb;
struct device *dev = port_info[port_no].dev;
int size;
unsigned long flags;
+struct ethhdr *eth;
if (port_info[port_no].state == Disabled) {
printk(KERN_DEBUG "send_tcn_bpdu: port %i not valid\n",port_no);
@@ -1015,35 +1078,34 @@ unsigned long flags;
return(-1);
}
skb->dev = dev;
- skb->free = 1;
- skb->h.eth = (struct ethhdr *)skb_put(skb,size);
- memcpy(skb->h.eth->h_dest, bridge_ula, ETH_ALEN);
- memcpy(skb->h.eth->h_source, dev->dev_addr, ETH_ALEN);
+ skb->mac.raw = skb->h.raw = skb_put(skb,size);
+ eth = skb->mac.ethernet;
+ memcpy(eth->h_dest, bridge_ula, ETH_ALEN);
+ memcpy(eth->h_source, dev->dev_addr, ETH_ALEN);
if (br_stats.flags & BR_DEBUG)
printk("port %i src %02x:%02x:%02x:%02x:%02x:%02x\
dest %02x:%02x:%02x:%02x:%02x:%02x\n",
port_no,
- skb->h.eth->h_source[0],
- skb->h.eth->h_source[1],
- skb->h.eth->h_source[2],
- skb->h.eth->h_source[3],
- skb->h.eth->h_source[4],
- skb->h.eth->h_source[5],
- skb->h.eth->h_dest[0],
- skb->h.eth->h_dest[1],
- skb->h.eth->h_dest[2],
- skb->h.eth->h_dest[3],
- skb->h.eth->h_dest[4],
- skb->h.eth->h_dest[5]);
- skb->h.eth->h_proto = 0x8038; /* XXX verify */
+ eth->h_source[0],
+ eth->h_source[1],
+ eth->h_source[2],
+ eth->h_source[3],
+ eth->h_source[4],
+ eth->h_source[5],
+ eth->h_dest[0],
+ eth->h_dest[1],
+ eth->h_dest[2],
+ eth->h_dest[3],
+ eth->h_dest[4],
+ eth->h_dest[5]);
+ eth->h_proto = htons(0x8038);
skb->h.raw += skb->dev->hard_header_len;
memcpy(skb->h.raw, bpdu, sizeof(Tcn_bpdu));
- /* mark that's we've been here... */
+ /* mark that we've been here... */
skb->pkt_bridged = IS_BRIDGED;
skb->arp = 1; /* do not resolve... */
- skb->h.raw = skb->data + ETH_HLEN;
save_flags(flags);
cli();
skb_queue_tail(dev->buffs, skb);
@@ -1119,6 +1181,7 @@ static int br_device_event(struct notifier_block *unused, unsigned long event, v
int br_receive_frame(struct sk_buff *skb) /* 3.5 */
{
int port;
+ struct ethhdr *eth;
if (br_stats.flags & BR_DEBUG)
printk("br_receive_frame: ");
@@ -1138,22 +1201,23 @@ int br_receive_frame(struct sk_buff *skb) /* 3.5 */
skb->arp = 1; /* Received frame so it is resolved */
skb->h.raw = skb->mac.raw;
+ eth = skb->mac.ethernet;
if (br_stats.flags & BR_DEBUG)
printk("port %i src %02x:%02x:%02x:%02x:%02x:%02x\
dest %02x:%02x:%02x:%02x:%02x:%02x\n",
port,
- skb->h.eth->h_source[0],
- skb->h.eth->h_source[1],
- skb->h.eth->h_source[2],
- skb->h.eth->h_source[3],
- skb->h.eth->h_source[4],
- skb->h.eth->h_source[5],
- skb->h.eth->h_dest[0],
- skb->h.eth->h_dest[1],
- skb->h.eth->h_dest[2],
- skb->h.eth->h_dest[3],
- skb->h.eth->h_dest[4],
- skb->h.eth->h_dest[5]);
+ eth->h_source[0],
+ eth->h_source[1],
+ eth->h_source[2],
+ eth->h_source[3],
+ eth->h_source[4],
+ eth->h_source[5],
+ eth->h_dest[0],
+ eth->h_dest[1],
+ eth->h_dest[2],
+ eth->h_dest[3],
+ eth->h_dest[4],
+ eth->h_dest[5]);
if (!port) {
if(br_stats.flags&BR_DEBUG)
@@ -1168,7 +1232,7 @@ int br_receive_frame(struct sk_buff *skb) /* 3.5 */
/* fall through */
case Listening:
/* process BPDUs */
- if (memcmp(skb->h.eth->h_dest, bridge_ula, 6) == 0) {
+ if (memcmp(eth->h_dest, bridge_ula, 6) == 0) {
br_bpdu(skb);
return(1); /* br_bpdu consumes skb */
}
@@ -1185,7 +1249,7 @@ int br_receive_frame(struct sk_buff *skb) /* 3.5 */
case Forwarding:
(void) br_learn(skb, port); /* 3.8 */
/* process BPDUs */
- if (memcmp(skb->h.eth->h_dest, bridge_ula,
+ if (memcmp(eth->h_dest, bridge_ula,
ETH_ALEN) == 0)
{
/*printk("frame bpdu processor for me!!!\n");*/
@@ -1193,7 +1257,7 @@ int br_receive_frame(struct sk_buff *skb) /* 3.5 */
return(1); /* br_bpdu consumes skb */
}
/* is frame for me? */
- if (memcmp(skb->h.eth->h_dest,
+ if (memcmp(eth->h_dest,
port_info[port].dev->dev_addr,
ETH_ALEN) == 0)
{
@@ -1202,7 +1266,13 @@ int br_receive_frame(struct sk_buff *skb) /* 3.5 */
return(0); /* pass frame up our stack (this will */
/* happen in net_bh() in dev.c) */
}
- /* ok, forward this frame... */
+ /* Now this frame came from one of bridged
+ ports, and it appears to be not for me;
+ this means we should attempt to forward it.
+ But actually this frame can still be for me
+ [as well] if it is destined to one of our
+ multicast groups. br_forward() will not
+ consume the frame if this is the case */
return(br_forward(skb, port));
default:
printk(KERN_DEBUG "br_receive_frame: port [%i] unknown state [%i]\n",
@@ -1220,6 +1290,7 @@ int br_receive_frame(struct sk_buff *skb) /* 3.5 */
int br_tx_frame(struct sk_buff *skb) /* 3.5 */
{
int port;
+ struct ethhdr *eth;
/* sanity */
if (!skb)
@@ -1238,24 +1309,30 @@ int br_tx_frame(struct sk_buff *skb) /* 3.5 */
if (skb->dev->flags & IFF_LOOPBACK)
return(0);
- skb->h.raw = skb->data;
+ /* if bridging is not enabled on the port we are going to send
+ to, we have nothing to do with this frame, hands off */
+ if (! find_port(skb->dev))
+ return(0);
+
+ skb->mac.raw = skb->h.raw = skb->data;
+ eth = skb->mac.ethernet;
port = 0; /* an impossible port */
if (br_stats.flags & BR_DEBUG)
printk("br_tx_fr : port %i src %02x:%02x:%02x:%02x:%02x:%02x\
dest %02x:%02x:%02x:%02x:%02x:%02x\n",
port,
- skb->h.eth->h_source[0],
- skb->h.eth->h_source[1],
- skb->h.eth->h_source[2],
- skb->h.eth->h_source[3],
- skb->h.eth->h_source[4],
- skb->h.eth->h_source[5],
- skb->h.eth->h_dest[0],
- skb->h.eth->h_dest[1],
- skb->h.eth->h_dest[2],
- skb->h.eth->h_dest[3],
- skb->h.eth->h_dest[4],
- skb->h.eth->h_dest[5]);
+ eth->h_source[0],
+ eth->h_source[1],
+ eth->h_source[2],
+ eth->h_source[3],
+ eth->h_source[4],
+ eth->h_source[5],
+ eth->h_dest[0],
+ eth->h_dest[1],
+ eth->h_dest[2],
+ eth->h_dest[3],
+ eth->h_dest[4],
+ eth->h_dest[5]);
return(br_forward(skb, port));
}
@@ -1265,7 +1342,7 @@ int br_tx_frame(struct sk_buff *skb) /* 3.5 */
* state or lack of resources...
*/
-int br_learn(struct sk_buff *skb, int port) /* 3.8 */
+static int br_learn(struct sk_buff *skb, int port) /* 3.8 */
{
struct fdb *f;
@@ -1279,7 +1356,7 @@ int br_learn(struct sk_buff *skb, int port) /* 3.8 */
case Learning:
case Forwarding:
/* don't keep group addresses in the tree */
- if (skb->h.eth->h_source[0] & 0x01)
+ if (skb->mac.ethernet->h_source[0] & 0x01)
return(-1);
f = (struct fdb *)kmalloc(sizeof(struct fdb),
@@ -1290,7 +1367,7 @@ int br_learn(struct sk_buff *skb, int port) /* 3.8 */
return(-1);
}
f->port = port; /* source port */
- memcpy(f->ula, skb->h.eth->h_source, 6);
+ memcpy(f->ula, skb->mac.ethernet->h_source, 6);
f->timer = CURRENT_TIME;
f->flags = FDB_ENT_VALID;
/*
@@ -1314,7 +1391,7 @@ int br_learn(struct sk_buff *skb, int port) /* 3.8 */
* this routine always consumes the frame
*/
-int br_drop(struct sk_buff *skb)
+static int br_drop(struct sk_buff *skb)
{
kfree_skb(skb, 0);
return(1);
@@ -1324,18 +1401,22 @@ int br_drop(struct sk_buff *skb)
* this routine always consumes the frame
*/
-int br_dev_drop(struct sk_buff *skb)
+static int br_dev_drop(struct sk_buff *skb)
{
dev_kfree_skb(skb, 0);
return(1);
}
/*
+ * Forward the frame SKB to proper port[s]. PORT is the port that the
+ * frame has come from; we will not send the frame back there. PORT == 0
+ * means we have been called from br_tx_fr(), not from br_receive_frame().
+ *
* this routine returns 1 if it consumes the frame, 0
* if not...
*/
-int br_forward(struct sk_buff *skb, int port) /* 3.7 */
+static int br_forward(struct sk_buff *skb, int port) /* 3.7 */
{
struct fdb *f;
@@ -1346,7 +1427,7 @@ int br_forward(struct sk_buff *skb, int port) /* 3.7 */
* Multicast frames will also need to be seen
* by our upper layers.
*/
- if (skb->h.eth->h_dest[0] & 0x01)
+ if (skb->mac.ethernet->h_dest[0] & 0x01)
{
/* group address */
br_flood(skb, port);
@@ -1360,7 +1441,7 @@ int br_forward(struct sk_buff *skb, int port) /* 3.7 */
return(0);
} else {
/* locate port to forward to */
- f = br_avl_find_addr(skb->h.eth->h_dest);
+ f = br_avl_find_addr(skb->mac.ethernet->h_dest);
/*
* Send flood and drop.
*/
@@ -1400,7 +1481,8 @@ int br_forward(struct sk_buff *skb, int port) /* 3.7 */
/*
* We send this still locked
*/
- dev_queue_xmit(skb, skb->dev,1);
+ skb->priority = 1;
+ dev_queue_xmit(skb);
return(1); /* skb has been consumed */
} else {
/*
@@ -1417,7 +1499,7 @@ int br_forward(struct sk_buff *skb, int port) /* 3.7 */
* consumes the original frame.
*/
-int br_flood(struct sk_buff *skb, int port)
+static int br_flood(struct sk_buff *skb, int port)
{
int i;
struct sk_buff *nskb;
@@ -1441,13 +1523,14 @@ int br_flood(struct sk_buff *skb, int port)
/* printk("Flood to port %d\n",i);*/
nskb->h.raw = nskb->data + ETH_HLEN;
- dev_queue_xmit(nskb,nskb->dev,1);
+ nskb->priority = 1;
+ dev_queue_xmit(nskb);
}
}
return(0);
}
-int find_port(struct device *dev)
+static int find_port(struct device *dev)
{
int i;
@@ -1458,7 +1541,7 @@ int find_port(struct device *dev)
return(0);
}
-int br_port_cost(struct device *dev) /* 4.10.2 */
+static int br_port_cost(struct device *dev) /* 4.10.2 */
{
if (strncmp(dev->name, "eth", 3) == 0) /* ethernet */
return(100);
@@ -1473,7 +1556,7 @@ int br_port_cost(struct device *dev) /* 4.10.2 */
* this routine always consumes the skb
*/
-void br_bpdu(struct sk_buff *skb) /* consumes skb */
+static void br_bpdu(struct sk_buff *skb) /* consumes skb */
{
Tcn_bpdu *bpdu;
int port;
@@ -1602,7 +1685,7 @@ int br_ioctl(unsigned int cmd, void *arg)
return 0;
}
-int br_cmp(unsigned int *a, unsigned int *b)
+static int br_cmp(unsigned int *a, unsigned int *b)
{
int i;
for (i=0; i<2; i++)
@@ -1616,4 +1699,3 @@ int br_cmp(unsigned int *a, unsigned int *b)
}
return(0);
}
-