mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-10-29 17:54:14 +08:00
lacp: tidy up after review
Move port_bit() to rtl837x_common.h as PORT_BIT(), a uint16_t shift, and MAC_ADDR_LEN from rtl837x_lldp.h next to it, and use MAC_ADDR_LEN for every address in the LACP code instead of a literal 6. Define lacp_mux_update() before its first caller and drop the forward declaration, declare variables at the top of their blocks, put the operator at the end of a continued line, drop the field value comments of the LACPDU struct, and leave lacp_port_lag to lacp_init() instead of initialising it in the test environment.
This commit is contained in:
1 parent
6a31b4a279
commit
2404e7a9b6
7 files changed
+88
-90
No files matched your search
+2
-2
@@ -752,7 +752,7 @@ void send_lacp(void)
|
||||
slen += strtox(outbuf + slen, "\",\"aggValid\":");
|
||||
bool_to_html(lacp_agg_valid[l]);
|
||||
slen += strtox(outbuf + slen, ",\"agg\":\"");
|
||||
for (uint8_t j = 0; j < 6; j++)
|
||||
for (uint8_t j = 0; j < MAC_ADDR_LEN; j++)
|
||||
byte_to_html(lacp_agg_sys[l][j]);
|
||||
slen += strtox(outbuf + slen, "\",\"members\":\"");
|
||||
byte_to_html(lacp_members_last[l] >> 8);
|
||||
@@ -776,7 +776,7 @@ void send_lacp(void)
|
||||
byte_to_html(lacp_rx_count[i] >> 8);
|
||||
byte_to_html(lacp_rx_count[i]);
|
||||
slen += strtox(outbuf + slen, "\",\"psys\":\"");
|
||||
for (uint8_t j = 0; j < 6; j++)
|
||||
for (uint8_t j = 0; j < MAC_ADDR_LEN; j++)
|
||||
byte_to_html(lacp_partner_sys[i][j]);
|
||||
slen += strtox(outbuf + slen, "\"},");
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
#define TICKS_DUE(last, period) ((uint8_t)((uint8_t)ticks - (last)) >= (period))
|
||||
|
||||
#define CPU_PORT 9
|
||||
#define MAC_ADDR_LEN 6
|
||||
#define PORT_BIT(p) ((uint16_t)1 << (p))
|
||||
#define NUL '\0'
|
||||
|
||||
// Define Port-masks for 9-port devices and 6-port devices
|
||||
|
||||
+60
-61
@@ -26,7 +26,7 @@ extern __xdata uint8_t uip_buf[UIP_CONF_BUFFER_SIZE + 2];
|
||||
/* 20-byte Actor/Partner information body (802.3ad 43.4.2.2), network byte order */
|
||||
struct lacp_info {
|
||||
uint16_t sys_prio;
|
||||
uint8_t sys[6];
|
||||
uint8_t sys[MAC_ADDR_LEN];
|
||||
uint16_t key;
|
||||
uint16_t port_prio;
|
||||
uint16_t port;
|
||||
@@ -36,32 +36,32 @@ struct lacp_info {
|
||||
|
||||
/* Outgoing LACPDU (no VLAN tag on TX, as in stp_pkt) */
|
||||
struct lacpdu {
|
||||
uint8_t dst[6];
|
||||
uint8_t src[6];
|
||||
uint8_t dst[MAC_ADDR_LEN];
|
||||
uint8_t src[MAC_ADDR_LEN];
|
||||
struct rtl_tag rtl_tag;
|
||||
uint16_t ethertype; /* 0x8809 */
|
||||
uint8_t subtype; /* 0x01 */
|
||||
uint8_t version; /* 0x01 */
|
||||
uint8_t tlv_actor; /* 0x01 */
|
||||
uint8_t actor_len; /* 0x14 */
|
||||
uint16_t ethertype;
|
||||
uint8_t subtype;
|
||||
uint8_t version;
|
||||
uint8_t tlv_actor;
|
||||
uint8_t actor_len;
|
||||
struct lacp_info actor;
|
||||
uint8_t tlv_partner; /* 0x02 */
|
||||
uint8_t partner_len; /* 0x14 */
|
||||
uint8_t tlv_partner;
|
||||
uint8_t partner_len;
|
||||
struct lacp_info partner;
|
||||
uint8_t tlv_collector; /* 0x03 */
|
||||
uint8_t collector_len; /* 0x10 */
|
||||
uint8_t tlv_collector;
|
||||
uint8_t collector_len;
|
||||
uint16_t collector_max_delay;
|
||||
uint8_t collector_reserved[12];
|
||||
uint8_t tlv_terminator; /* 0x00 */
|
||||
uint8_t terminator_len; /* 0x00 */
|
||||
uint8_t tlv_terminator;
|
||||
uint8_t terminator_len;
|
||||
uint8_t terminator_reserved[50];
|
||||
};
|
||||
|
||||
/* Incoming LACPDU, split because a VLAN tag sits between the two only when the
|
||||
* frame was forwarded: a trapped one carries none (cf. stp_pkt_in) */
|
||||
struct lacpdu_in_hdr {
|
||||
uint8_t dst[6];
|
||||
uint8_t src[6];
|
||||
uint8_t dst[MAC_ADDR_LEN];
|
||||
uint8_t src[MAC_ADDR_LEN];
|
||||
struct rtl_tag rtl_tag;
|
||||
};
|
||||
|
||||
@@ -86,7 +86,7 @@ __xdata uint8_t lacp_rxbody;
|
||||
__xdata uint8_t lacp_actor_state[10];
|
||||
__xdata uint8_t lacp_rx_state[10];
|
||||
__xdata uint8_t lacp_partner_state[10];
|
||||
__xdata uint8_t lacp_partner_sys[10][6];
|
||||
__xdata uint8_t lacp_partner_sys[10][MAC_ADDR_LEN];
|
||||
__xdata uint16_t lacp_partner_key[10];
|
||||
__xdata uint16_t lacp_partner_port[10];
|
||||
__xdata uint16_t lacp_partner_sys_prio[10];
|
||||
@@ -102,7 +102,7 @@ extern volatile __xdata uint32_t ticks;
|
||||
|
||||
__xdata uint16_t lacp_lag_ports[LACP_NUM_LAGS];
|
||||
__xdata uint8_t lacp_port_lag[10];
|
||||
__xdata uint8_t lacp_agg_sys[LACP_NUM_LAGS][6];
|
||||
__xdata uint8_t lacp_agg_sys[LACP_NUM_LAGS][MAC_ADDR_LEN];
|
||||
__xdata uint8_t lacp_agg_valid[LACP_NUM_LAGS];
|
||||
__xdata uint16_t lacp_members_last[LACP_NUM_LAGS];
|
||||
|
||||
@@ -113,11 +113,9 @@ __xdata uint8_t lacp_scratch_lag;
|
||||
__xdata uint16_t lacp_rx_count[10];
|
||||
|
||||
|
||||
void lacp_mux_update(void) __banked;
|
||||
|
||||
static uint8_t lacp_sys_eq(__xdata uint8_t *a, __xdata uint8_t *b)
|
||||
{
|
||||
for (uint8_t i = 0; i < 6; i++) {
|
||||
for (uint8_t i = 0; i < MAC_ADDR_LEN; i++) {
|
||||
if (a[i] != b[i])
|
||||
return 0;
|
||||
}
|
||||
@@ -161,21 +159,41 @@ static uint8_t lacp_mux_machine(uint8_t port)
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define port_bit(p) (((uint8_t)1) << (p))
|
||||
void lacp_mux_update(void) __banked
|
||||
{
|
||||
for (uint8_t lag = 0; lag < LACP_NUM_LAGS; lag++) {
|
||||
if (!lacp_lag_ports[lag])
|
||||
continue;
|
||||
lacp_scratch_mask = 0;
|
||||
for (uint8_t i = machine.min_port; i <= machine.max_port; i++) {
|
||||
if (lacp_port_lag[i] != lag)
|
||||
continue;
|
||||
if ((lacp_actor_state[i] & LACP_STATE_FULL) == LACP_STATE_FULL
|
||||
&& (lacp_partner_state[i] & LACP_STATE_SYNC))
|
||||
lacp_scratch_mask |= PORT_BIT(i);
|
||||
}
|
||||
if (lacp_scratch_mask != lacp_members_last[lag]) {
|
||||
lacp_members_last[lag] = lacp_scratch_mask;
|
||||
port_lag_members_set(lag, lacp_scratch_mask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void lacp_send(uint8_t port) __banked
|
||||
{
|
||||
uint16_t saved_mgmt_vlan;
|
||||
|
||||
memset((__xdata uint8_t *)LACP_O, 0, sizeof(struct lacpdu));
|
||||
LACP_O->dst[0] = 0x01; LACP_O->dst[1] = 0x80; LACP_O->dst[2] = 0xc2;
|
||||
LACP_O->dst[3] = 0x00; LACP_O->dst[4] = 0x00; LACP_O->dst[5] = LACP_DST5;
|
||||
memcpy(LACP_O->src, uip_ethaddr.addr, 6);
|
||||
memcpy(LACP_O->src, uip_ethaddr.addr, MAC_ADDR_LEN);
|
||||
|
||||
LACP_O->rtl_tag.tag = HTONS(RTL_FRAME_TAG_ID);
|
||||
LACP_O->rtl_tag.version = RTL_FRAME_TAG_VERSION;
|
||||
LACP_O->rtl_tag.reason = 0x00;
|
||||
LACP_O->rtl_tag.flags = HTONS(RTL_TAG_LEARN_DIS | RTL_TAG_KEEP);
|
||||
LACP_O->rtl_tag.pmask = HTONS(port_bit(port));
|
||||
LACP_O->rtl_tag.pmask = HTONS(PORT_BIT(port));
|
||||
|
||||
LACP_O->ethertype = HTONS(SLOW_PROTO_ETHERTYPE);
|
||||
LACP_O->subtype = SLOW_PROTO_SUBTYPE_LACP;
|
||||
@@ -184,7 +202,7 @@ void lacp_send(uint8_t port) __banked
|
||||
LACP_O->tlv_actor = LACP_TLV_ACTOR;
|
||||
LACP_O->actor_len = LACP_TLV_LEN_INFO;
|
||||
LACP_O->actor.sys_prio = HTONS(LACP_SYS_PRIO);
|
||||
memcpy(LACP_O->actor.sys, uip_ethaddr.addr, 6);
|
||||
memcpy(LACP_O->actor.sys, uip_ethaddr.addr, MAC_ADDR_LEN);
|
||||
LACP_O->actor.key = HTONS((uint16_t)(lacp_port_lag[port] + 1));
|
||||
LACP_O->actor.port_prio = HTONS(LACP_DEF_PORT_PRIO);
|
||||
LACP_O->actor.port = HTONS((uint16_t)port + 1);
|
||||
@@ -193,7 +211,7 @@ void lacp_send(uint8_t port) __banked
|
||||
LACP_O->tlv_partner = LACP_TLV_PARTNER;
|
||||
LACP_O->partner_len = LACP_TLV_LEN_INFO;
|
||||
LACP_O->partner.sys_prio = HTONS(lacp_partner_sys_prio[port]);
|
||||
memcpy(LACP_O->partner.sys, lacp_partner_sys[port], 6);
|
||||
memcpy(LACP_O->partner.sys, lacp_partner_sys[port], MAC_ADDR_LEN);
|
||||
LACP_O->partner.key = HTONS(lacp_partner_key[port]);
|
||||
LACP_O->partner.port_prio = HTONS(lacp_partner_port_prio[port]);
|
||||
LACP_O->partner.port = HTONS(lacp_partner_port[port]);
|
||||
@@ -206,7 +224,7 @@ void lacp_send(uint8_t port) __banked
|
||||
LACP_O->terminator_len = 0x00;
|
||||
|
||||
lacp_ntt[port] = 0;
|
||||
uint16_t saved_mgmt_vlan = management_vlan;
|
||||
saved_mgmt_vlan = management_vlan;
|
||||
management_vlan = 0;
|
||||
uip_len = sizeof(struct lacpdu);
|
||||
tcpip_output();
|
||||
@@ -247,7 +265,7 @@ void lacp_in(void) __banked
|
||||
|
||||
lacp_rx_count[port]++;
|
||||
|
||||
memcpy(lacp_partner_sys[port], LACP_I->actor.sys, 6);
|
||||
memcpy(lacp_partner_sys[port], LACP_I->actor.sys, MAC_ADDR_LEN);
|
||||
lacp_scratch_mask = HTONS(LACP_I->actor.key);
|
||||
lacp_partner_key[port] = lacp_scratch_mask;
|
||||
lacp_scratch_mask = HTONS(LACP_I->actor.port);
|
||||
@@ -262,7 +280,7 @@ void lacp_in(void) __banked
|
||||
lacp_timeout[port] = LACP_SHORT_TIMEOUT;
|
||||
|
||||
if (!lacp_agg_valid[lag]) {
|
||||
memcpy(lacp_agg_sys[lag], LACP_I->actor.sys, 6);
|
||||
memcpy(lacp_agg_sys[lag], LACP_I->actor.sys, MAC_ADDR_LEN);
|
||||
lacp_agg_valid[lag] = 1;
|
||||
}
|
||||
|
||||
@@ -277,26 +295,6 @@ void lacp_in(void) __banked
|
||||
}
|
||||
|
||||
|
||||
void lacp_mux_update(void) __banked
|
||||
{
|
||||
for (uint8_t lag = 0; lag < LACP_NUM_LAGS; lag++) {
|
||||
if (!lacp_lag_ports[lag])
|
||||
continue;
|
||||
lacp_scratch_mask = 0;
|
||||
for (uint8_t i = machine.min_port; i <= machine.max_port; i++) {
|
||||
if (lacp_port_lag[i] != lag)
|
||||
continue;
|
||||
if ((lacp_actor_state[i] & LACP_STATE_FULL) == LACP_STATE_FULL
|
||||
&& (lacp_partner_state[i] & LACP_STATE_SYNC))
|
||||
lacp_scratch_mask |= port_bit(i);
|
||||
}
|
||||
if (lacp_scratch_mask != lacp_members_last[lag]) {
|
||||
lacp_members_last[lag] = lacp_scratch_mask;
|
||||
port_lag_members_set(lag, lacp_scratch_mask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void lacp_step(void)
|
||||
{
|
||||
@@ -307,8 +305,8 @@ static void lacp_step(void)
|
||||
if (lacp_periodic[i]) {
|
||||
lacp_periodic[i]--;
|
||||
} else {
|
||||
lacp_periodic[i] = (lacp_partner_state[i] & LACP_STATE_TIMEOUT)
|
||||
? LACP_FAST_PERIODIC : LACP_SLOW_PERIODIC;
|
||||
lacp_periodic[i] = (lacp_partner_state[i] & LACP_STATE_TIMEOUT) ?
|
||||
LACP_FAST_PERIODIC : LACP_SLOW_PERIODIC;
|
||||
lacp_ntt[i] = 1;
|
||||
}
|
||||
|
||||
@@ -326,9 +324,10 @@ static void lacp_step(void)
|
||||
}
|
||||
|
||||
for (uint8_t lag = 0; lag < LACP_NUM_LAGS; lag++) {
|
||||
uint8_t any_current = 0;
|
||||
|
||||
if (!lacp_agg_valid[lag])
|
||||
continue;
|
||||
uint8_t any_current = 0;
|
||||
for (uint8_t i = machine.min_port; i <= machine.max_port; i++) {
|
||||
if (lacp_port_lag[i] == lag && lacp_rx_state[i] == LACP_RX_CURRENT
|
||||
&& lacp_sys_eq(lacp_partner_sys[i], lacp_agg_sys[lag])) {
|
||||
@@ -356,11 +355,11 @@ void lacp_timers(void) __banked
|
||||
|
||||
static void lacp_port_init(uint8_t port)
|
||||
{
|
||||
lacp_actor_state[port] = LACP_STATE_ACTIVITY | LACP_STATE_AGGREGATION
|
||||
| LACP_STATE_TIMEOUT;
|
||||
lacp_actor_state[port] = LACP_STATE_ACTIVITY | LACP_STATE_AGGREGATION |
|
||||
LACP_STATE_TIMEOUT;
|
||||
lacp_rx_state[port] = LACP_RX_INITIALIZE;
|
||||
lacp_partner_state[port] = LACP_STATE_DEFAULTED;
|
||||
memset(lacp_partner_sys[port], 0, 6);
|
||||
memset(lacp_partner_sys[port], 0, MAC_ADDR_LEN);
|
||||
lacp_partner_key[port] = 0;
|
||||
lacp_partner_port[port] = 0;
|
||||
lacp_periodic[port] = LACP_FAST_PERIODIC;
|
||||
@@ -376,7 +375,7 @@ static void lacp_port_release(uint8_t port)
|
||||
lacp_partner_state[port] = 0;
|
||||
lacp_rx_state[port] = LACP_RX_INITIALIZE;
|
||||
lacp_rx_count[port] = 0;
|
||||
memset(lacp_partner_sys[port], 0, 6);
|
||||
memset(lacp_partner_sys[port], 0, MAC_ADDR_LEN);
|
||||
}
|
||||
|
||||
static uint8_t lacp_any_lag(void)
|
||||
@@ -424,7 +423,7 @@ void lacp_lag_set(uint8_t lag, __xdata uint16_t ports) __banked
|
||||
lacp_scratch_flag = lacp_any_lag();
|
||||
|
||||
for (uint8_t i = machine.min_port; i <= machine.max_port; i++) {
|
||||
if (lacp_port_lag[i] == lag && !(ports & port_bit(i))) {
|
||||
if (lacp_port_lag[i] == lag && !(ports & PORT_BIT(i))) {
|
||||
lacp_port_lag[i] = LACP_LAG_NONE;
|
||||
lacp_port_release(i);
|
||||
}
|
||||
@@ -440,12 +439,12 @@ void lacp_lag_set(uint8_t lag, __xdata uint16_t ports) __banked
|
||||
lacp_engine_on();
|
||||
|
||||
for (uint8_t i = machine.min_port; i <= machine.max_port; i++) {
|
||||
if (!(ports & port_bit(i)))
|
||||
if (!(ports & PORT_BIT(i)))
|
||||
continue;
|
||||
lacp_scratch_lag = lacp_port_lag[i];
|
||||
lacp_port_lag[i] = lag;
|
||||
if (lacp_scratch_lag != LACP_LAG_NONE && lacp_scratch_lag != lag) {
|
||||
lacp_scratch_mask = lacp_lag_ports[lacp_scratch_lag] & ~port_bit(i);
|
||||
lacp_scratch_mask = lacp_lag_ports[lacp_scratch_lag] & ~PORT_BIT(i);
|
||||
lacp_lag_ports[lacp_scratch_lag] = lacp_scratch_mask;
|
||||
if (!lacp_scratch_mask) {
|
||||
lacp_agg_valid[lacp_scratch_lag] = 0;
|
||||
@@ -483,7 +482,7 @@ void lacp_show(void) __banked
|
||||
print_string(" ports "); print_short(lacp_lag_ports[l]);
|
||||
print_string(" aggregator ");
|
||||
if (lacp_agg_valid[l]) {
|
||||
for (uint8_t j = 0; j < 6; j++)
|
||||
for (uint8_t j = 0; j < MAC_ADDR_LEN; j++)
|
||||
print_byte(lacp_agg_sys[l][j]);
|
||||
} else {
|
||||
print_string("(none)");
|
||||
@@ -498,7 +497,7 @@ void lacp_show(void) __banked
|
||||
print_string(" rxst "); print_byte(lacp_rx_state[i]);
|
||||
print_string(" rx "); print_short(lacp_rx_count[i]);
|
||||
print_string(" psys ");
|
||||
for (uint8_t j = 0; j < 6; j++)
|
||||
for (uint8_t j = 0; j < MAC_ADDR_LEN; j++)
|
||||
print_byte(lacp_partner_sys[i][j]);
|
||||
write_char('\n');
|
||||
}
|
||||
|
||||
+3
-2
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "rtl837x_common.h"
|
||||
|
||||
void lacp_init(void) __banked;
|
||||
void lacp_in(void) __banked;
|
||||
@@ -22,11 +23,11 @@ extern __xdata uint8_t lacpEnabled;
|
||||
extern __xdata uint8_t lacp_actor_state[10];
|
||||
extern __xdata uint8_t lacp_partner_state[10];
|
||||
extern __xdata uint8_t lacp_rx_state[10];
|
||||
extern __xdata uint8_t lacp_partner_sys[10][6];
|
||||
extern __xdata uint8_t lacp_partner_sys[10][MAC_ADDR_LEN];
|
||||
extern __xdata uint16_t lacp_rx_count[10];
|
||||
extern __xdata uint8_t lacp_port_lag[10];
|
||||
extern __xdata uint16_t lacp_lag_ports[LACP_NUM_LAGS];
|
||||
extern __xdata uint8_t lacp_agg_sys[LACP_NUM_LAGS][6];
|
||||
extern __xdata uint8_t lacp_agg_sys[LACP_NUM_LAGS][MAC_ADDR_LEN];
|
||||
extern __xdata uint8_t lacp_agg_valid[LACP_NUM_LAGS];
|
||||
extern __xdata uint16_t lacp_members_last[LACP_NUM_LAGS];
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#define LLDP_ETHERTYPE 0x88cc
|
||||
#define LLDP_ETHERTYPE_LENGTH 2
|
||||
#define LLDP_MAX_FRAME 256
|
||||
#define MAC_ADDR_LEN 6
|
||||
#define LLDP_TX_INTERVAL_TICKS 6000
|
||||
|
||||
#define LLDP_PORT_ID_TLV_TYPE 2
|
||||
|
||||
+3
-6
@@ -130,13 +130,10 @@ uint8_t lacpEnabled;
|
||||
uint8_t lacp_actor_state[10];
|
||||
uint8_t lacp_partner_state[10];
|
||||
uint8_t lacp_rx_state[10];
|
||||
uint8_t lacp_partner_sys[10][6];
|
||||
uint8_t lacp_partner_sys[10][MAC_ADDR_LEN];
|
||||
uint16_t lacp_rx_count[10];
|
||||
uint8_t lacp_port_lag[10] = {
|
||||
LACP_LAG_NONE, LACP_LAG_NONE, LACP_LAG_NONE, LACP_LAG_NONE, LACP_LAG_NONE,
|
||||
LACP_LAG_NONE, LACP_LAG_NONE, LACP_LAG_NONE, LACP_LAG_NONE, LACP_LAG_NONE,
|
||||
};
|
||||
uint8_t lacp_port_lag[10];
|
||||
uint16_t lacp_lag_ports[LACP_NUM_LAGS];
|
||||
uint8_t lacp_agg_sys[LACP_NUM_LAGS][6];
|
||||
uint8_t lacp_agg_sys[LACP_NUM_LAGS][MAC_ADDR_LEN];
|
||||
uint8_t lacp_agg_valid[LACP_NUM_LAGS];
|
||||
uint16_t lacp_members_last[LACP_NUM_LAGS];
|
||||
+18
-18
@@ -56,7 +56,7 @@ void trap_rma_set(uint16_t reg, uint8_t act)
|
||||
|
||||
struct wire_info {
|
||||
uint16_t sys_prio;
|
||||
uint8_t sys[6];
|
||||
uint8_t sys[MAC_ADDR_LEN];
|
||||
uint16_t key;
|
||||
uint16_t port_prio;
|
||||
uint16_t port;
|
||||
@@ -65,8 +65,8 @@ struct wire_info {
|
||||
};
|
||||
|
||||
struct wire_pdu_out { /* what lacp_send() writes at uip_buf+12 */
|
||||
uint8_t dst[6];
|
||||
uint8_t src[6];
|
||||
uint8_t dst[MAC_ADDR_LEN];
|
||||
uint8_t src[MAC_ADDR_LEN];
|
||||
struct rtl_tag rtl_tag;
|
||||
uint16_t ethertype;
|
||||
uint8_t subtype;
|
||||
@@ -83,8 +83,8 @@ struct wire_pdu_out { /* what lacp_send() writes at uip_buf+12 */
|
||||
};
|
||||
|
||||
struct wire_pdu_in { /* forwarded form: the hardware inserts a VLAN tag */
|
||||
uint8_t dst[6];
|
||||
uint8_t src[6];
|
||||
uint8_t dst[MAC_ADDR_LEN];
|
||||
uint8_t src[MAC_ADDR_LEN];
|
||||
struct rtl_tag rtl_tag;
|
||||
struct vlan_tag vlan_tag;
|
||||
uint16_t ethertype;
|
||||
@@ -123,14 +123,14 @@ void tcpip_output(void)
|
||||
/* Deliver a LACPDU into the switch on `port`, from partner system `sys`.
|
||||
* pstate = partner's Actor_State flags. If `echo`, the partner echoes the
|
||||
* switch's last-seen actor block back (fresh view) - required for quiescence. */
|
||||
static void partner_frame_full(uint8_t port, const uint8_t sys[6], uint8_t pstate,
|
||||
static void partner_frame_full(uint8_t port, const uint8_t sys[MAC_ADDR_LEN], uint8_t pstate,
|
||||
int echo, uint16_t len, int tagged)
|
||||
{
|
||||
struct wire_pdu_in in;
|
||||
memset(&in, 0, sizeof(in));
|
||||
|
||||
in.dst[0]=0x01; in.dst[1]=0x80; in.dst[2]=0xc2; in.dst[5]=0x02;
|
||||
memcpy(in.src, sys, 6);
|
||||
memcpy(in.src, sys, MAC_ADDR_LEN);
|
||||
in.rtl_tag.tag = HTONS(RTL_FRAME_TAG_ID);
|
||||
in.rtl_tag.pmask = HTONS(port); /* RX: 4-bit ingress port */
|
||||
in.vlan_tag.svlan = HTONS(0x8100); /* the tag's TPID, which marks the body offset */
|
||||
@@ -140,7 +140,7 @@ static void partner_frame_full(uint8_t port, const uint8_t sys[6], uint8_t pstat
|
||||
|
||||
in.tlv_actor = 0x01; in.actor_len = 0x14;
|
||||
in.actor.sys_prio = HTONS(0x8000);
|
||||
memcpy(in.actor.sys, sys, 6);
|
||||
memcpy(in.actor.sys, sys, MAC_ADDR_LEN);
|
||||
in.actor.key = HTONS(0x0011);
|
||||
in.actor.port_prio = HTONS(0x00ff);
|
||||
in.actor.port = HTONS((uint16_t)port + 101);
|
||||
@@ -149,7 +149,7 @@ static void partner_frame_full(uint8_t port, const uint8_t sys[6], uint8_t pstat
|
||||
in.tlv_partner = 0x02; in.partner_len = 0x14;
|
||||
if (echo) { /* fresh view of us, from our last TX */
|
||||
in.partner.sys_prio = last_tx[port].actor.sys_prio;
|
||||
memcpy(in.partner.sys, last_tx[port].actor.sys, 6);
|
||||
memcpy(in.partner.sys, last_tx[port].actor.sys, MAC_ADDR_LEN);
|
||||
in.partner.key = last_tx[port].actor.key;
|
||||
in.partner.port = last_tx[port].actor.port;
|
||||
in.partner.state = last_tx[port].actor.state;
|
||||
@@ -166,18 +166,18 @@ static void partner_frame_full(uint8_t port, const uint8_t sys[6], uint8_t pstat
|
||||
lacp_in();
|
||||
}
|
||||
|
||||
static void partner_frame_len(uint8_t port, const uint8_t sys[6], uint8_t pstate, int echo, uint16_t len)
|
||||
static void partner_frame_len(uint8_t port, const uint8_t sys[MAC_ADDR_LEN], uint8_t pstate, int echo, uint16_t len)
|
||||
{
|
||||
partner_frame_full(port, sys, pstate, echo, len, 1);
|
||||
}
|
||||
|
||||
static void partner_frame(uint8_t port, const uint8_t sys[6], uint8_t pstate, int echo)
|
||||
static void partner_frame(uint8_t port, const uint8_t sys[MAC_ADDR_LEN], uint8_t pstate, int echo)
|
||||
{
|
||||
partner_frame_full(port, sys, pstate, echo, sizeof(struct wire_pdu_in), 1);
|
||||
}
|
||||
|
||||
/* The same LACPDU as the reserved-multicast trap delivers it. */
|
||||
static void partner_frame_trap(uint8_t port, const uint8_t sys[6], uint8_t pstate, int echo)
|
||||
static void partner_frame_trap(uint8_t port, const uint8_t sys[MAC_ADDR_LEN], uint8_t pstate, int echo)
|
||||
{
|
||||
partner_frame_full(port, sys, pstate, echo, sizeof(struct wire_pdu_in), 0);
|
||||
}
|
||||
@@ -201,8 +201,8 @@ static int failures;
|
||||
#define P_DIST LACP_STATE_DISTRIBUTING
|
||||
#define P_TO LACP_STATE_TIMEOUT /* partner requests short (fast) timeout */
|
||||
|
||||
static const uint8_t SYS_A[6] = {0x02,0xaa,0xaa,0xaa,0xaa,0x01};
|
||||
static const uint8_t SYS_B[6] = {0x02,0xbb,0xbb,0xbb,0xbb,0x02};
|
||||
static const uint8_t SYS_A[MAC_ADDR_LEN] = {0x02,0xaa,0xaa,0xaa,0xaa,0x01};
|
||||
static const uint8_t SYS_B[MAC_ADDR_LEN] = {0x02,0xbb,0xbb,0xbb,0xbb,0x02};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
@@ -342,11 +342,11 @@ int main(int argc, char **argv)
|
||||
* carries, so its body sits four bytes earlier. Both forms must parse. */
|
||||
uint16_t rx_before = lacp_rx_count[0];
|
||||
lacp_partner_state[0] = 0; /* all three are written past the ethertype gate */
|
||||
memset(lacp_partner_sys[0], 0, 6);
|
||||
memset(lacp_partner_sys[0], 0, MAC_ADDR_LEN);
|
||||
partner_frame_trap(0, SYS_A, P_ACT|P_AGG|P_TO|P_SYNC, 1);
|
||||
int trap_ok = lacp_rx_count[0] == (uint16_t)(rx_before + 1)
|
||||
&& lacp_partner_state[0] == (P_ACT|P_AGG|P_TO|P_SYNC)
|
||||
&& !memcmp(lacp_partner_sys[0], SYS_A, 6);
|
||||
&& !memcmp(lacp_partner_sys[0], SYS_A, MAC_ADDR_LEN);
|
||||
partner_frame(0, SYS_A, P_ACT|P_AGG|P_TO|P_SYNC, 1);
|
||||
CHECK(trap_ok && lacp_rx_count[0] == (uint16_t)(rx_before + 2),
|
||||
"T15 trapped LACPDU parses like a forwarded one");
|
||||
@@ -376,7 +376,7 @@ int main(int argc, char **argv)
|
||||
partner_frame(1, SYS_B, P_ACT|P_AGG|P_TO|P_SYNC, 1);
|
||||
step(4 * 40);
|
||||
}
|
||||
CHECK(stayed_out && hw_members == 0x0003 && !memcmp(lacp_agg_sys[0], SYS_B, 6),
|
||||
CHECK(stayed_out && hw_members == 0x0003 && !memcmp(lacp_agg_sys[0], SYS_B, MAC_ADDR_LEN),
|
||||
"T16 re-cabling one port at a time: aggregator moves from A to B");
|
||||
|
||||
/* T17: a group that already has a STATIC trunk is put under LACP with the
|
||||
@@ -420,7 +420,7 @@ int main(int argc, char **argv)
|
||||
int had_partner = lacp_rx_state[4] == LACP_RX_CURRENT && lacp_rx_count[4] > 0;
|
||||
lacp_lag_set(1, 0);
|
||||
CHECK(had_partner && lacp_partner_state[4] == 0 && lacp_rx_state[4] == LACP_RX_INITIALIZE
|
||||
&& lacp_rx_count[4] == 0 && !memcmp(lacp_partner_sys[4], "\0\0\0\0\0\0", 6),
|
||||
&& lacp_rx_count[4] == 0 && !memcmp(lacp_partner_sys[4], "\0\0\0\0\0\0", MAC_ADDR_LEN),
|
||||
"T20 release: partner state, rx state, counter and system cleared");
|
||||
|
||||
/* T21: applying the same candidate set again (the LAG page resends it
|
||||
|
||||
Reference in new issue
Block a user