Skip to content

Commit 3017e02

Browse files
committed
DCP handle alias id request
Do not store alias name for each LLDP peer. Instead build and check alias when alias is part of id request received. Exclude alias name from DCP response as it shall only be used for filtering requests.
1 parent 1177f53 commit 3017e02

File tree

5 files changed

+132
-52
lines changed

5 files changed

+132
-52
lines changed

src/common/pf_dcp.c

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ static int pf_dcp_put_block (
369369
* @param sub In: Sub-option key.
370370
* @param request_is_identify In: Usage in response to Identify request
371371
* (skips some blocks)
372-
* @param append_alias_name In: Append alias name
372+
* @param alias_name In: Alias name appended if != NULL
373373
* @return
374374
*/
375375
static int pf_dcp_get_req (
@@ -380,7 +380,7 @@ static int pf_dcp_get_req (
380380
uint8_t opt,
381381
uint8_t sub,
382382
bool request_is_identify,
383-
bool append_alias_name)
383+
const char * alias_name)
384384
{
385385
int ret = 0; /* Assume all OK */
386386
uint8_t block_error = PF_DCP_BLOCK_ERROR_NO_ERROR;
@@ -492,8 +492,13 @@ static int pf_dcp_get_req (
492492
value_length = (uint16_t)strlen ((char *)p_value);
493493
break;
494494
case PF_DCP_SUB_DEV_PROP_ALIAS:
495-
skip = append_alias_name ? 0 : 1;
496-
value_length = (uint16_t)strlen ((char *)p_value);
495+
skip = alias_name ? 0 : 1;
496+
if (skip == 0)
497+
{
498+
value_length = (uint16_t)strlen (alias_name);
499+
p_value = (uint8_t *)alias_name;
500+
ret = 0;
501+
}
497502
break;
498503
case PF_DCP_SUB_DEV_PROP_VENDOR:
499504
value_length = (uint16_t)strlen ((char *)p_value);
@@ -1442,7 +1447,6 @@ static int pf_dcp_identify_req (
14421447
bool first = true; /* First of the blocks */
14431448
bool match = false; /* Is it for us? */
14441449
bool filter = false; /* Is it IdentifyFilter or IdentifyAll? */
1445-
bool alias_request = false; /*Is this a request via an alias name?*/
14461450
uint8_t * p_src;
14471451
uint16_t src_pos = 0;
14481452
pf_ethhdr_t * p_src_ethhdr;
@@ -1463,6 +1467,8 @@ static int pf_dcp_identify_req (
14631467
uint8_t * p_value;
14641468
uint8_t block_error;
14651469
const pnet_ethaddr_t * mac_address = pf_cmina_get_device_macaddr (net);
1470+
char alias[PF_ALIAS_NAME_MAX_SIZE]; /** Terminated */
1471+
char * p_req_alias_name = NULL;
14661472

14671473
/* For diagnostic logging */
14681474
bool identify_all = false;
@@ -1754,24 +1760,6 @@ static int pf_dcp_identify_req (
17541760
ret = -1;
17551761
}
17561762
break;
1757-
case PF_DCP_SUB_DEV_PROP_ALIAS:
1758-
alias_position = src_pos;
1759-
alias_len = src_block_len;
1760-
if (
1761-
(memcmp (p_value, &p_src[src_pos], value_length) != 0) ||
1762-
(src_block_len != value_length))
1763-
{
1764-
if (first == true)
1765-
{
1766-
alias_request = true;
1767-
filter = true;
1768-
}
1769-
}
1770-
else
1771-
{
1772-
match = false;
1773-
}
1774-
break;
17751763
case PF_DCP_SUB_DEV_PROP_INSTANCE:
17761764
if (filter == true)
17771765
{
@@ -1840,6 +1828,46 @@ static int pf_dcp_identify_req (
18401828
src_block_len = ntohs (p_src_block_hdr->block_length);
18411829
src_pos += sizeof (*p_src_block_hdr);
18421830
}
1831+
else if (
1832+
(p_src_block_hdr->option == PF_DCP_OPT_DEVICE_PROPERTIES) &&
1833+
(p_src_block_hdr->sub_option == PF_DCP_SUB_DEV_PROP_ALIAS))
1834+
{
1835+
alias_position = src_pos;
1836+
alias_len = src_block_len;
1837+
if (src_block_len < PF_ALIAS_NAME_MAX_SIZE)
1838+
{
1839+
memcpy (alias, &p_src[src_pos], src_block_len);
1840+
alias[src_block_len] = '\0';
1841+
if (pf_lldp_is_alias_matching (net, alias))
1842+
{
1843+
if (first == true)
1844+
{
1845+
p_req_alias_name = alias;
1846+
filter = true;
1847+
}
1848+
}
1849+
else
1850+
{
1851+
match = false;
1852+
}
1853+
}
1854+
else
1855+
{
1856+
match = false;
1857+
}
1858+
1859+
src_pos += src_block_len;
1860+
1861+
/* Skip padding to align on uint16_t */
1862+
while (src_pos & 1)
1863+
{
1864+
src_pos++;
1865+
}
1866+
/* Prepare for the next round */
1867+
p_src_block_hdr = (pf_dcp_block_hdr_t *)&p_src[src_pos];
1868+
src_block_len = ntohs (p_src_block_hdr->block_length);
1869+
src_pos += sizeof (*p_src_block_hdr);
1870+
}
18431871
else
18441872
{
18451873
LOG_DEBUG (
@@ -1866,7 +1894,7 @@ static int pf_dcp_identify_req (
18661894
device_options[ix].opt,
18671895
device_options[ix].sub,
18681896
true,
1869-
alias_request);
1897+
p_req_alias_name);
18701898
}
18711899

18721900
/* Insert final response length and ship it! */

src/common/pf_lldp.c

Lines changed: 69 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,11 @@ static void pf_lldp_receive_timeout (
502502
pf_port_t * p_port_data = (pf_port_t *)arg;
503503

504504
p_port_data->lldp.rx_timeout = 0;
505-
LOG_WARNING (PF_LLDP_LOG, "LLDP(%d): Receive timeout expired\n", __LINE__);
505+
LOG_INFO (
506+
PF_LLDP_LOG,
507+
"LLDP(%d): Port %d, receive timeout expired\n",
508+
__LINE__,
509+
p_port_data->port_num);
506510

507511
pf_pdport_peer_lldp_timeout (net, p_port_data->port_num);
508512
pf_lldp_invalidate_peer_info (net, p_port_data->port_num);
@@ -1816,6 +1820,37 @@ int pf_lldp_generate_alias_name (
18161820
return 0;
18171821
}
18181822

1823+
bool pf_lldp_is_alias_matching (pnet_t * net, const char * alias)
1824+
{
1825+
char port_alias[PF_ALIAS_NAME_MAX_SIZE]; /** Terminated */
1826+
int port;
1827+
pf_port_iterator_t port_iterator;
1828+
pf_port_t * p_port_data = NULL;
1829+
1830+
pf_port_init_iterator_over_ports (net, &port_iterator);
1831+
port = pf_port_get_next (&port_iterator);
1832+
while (port != 0)
1833+
{
1834+
p_port_data = pf_port_get_state (net, port);
1835+
if (
1836+
p_port_data->lldp.is_peer_info_received &&
1837+
(pf_lldp_generate_alias_name (
1838+
p_port_data->lldp.peer_info.port_id.string,
1839+
p_port_data->lldp.peer_info.chassis_id.string,
1840+
port_alias,
1841+
sizeof (port_alias)) == 0))
1842+
{
1843+
if (strcmp (alias, port_alias) == 0)
1844+
{
1845+
return true;
1846+
}
1847+
}
1848+
1849+
port = pf_port_get_next (&port_iterator);
1850+
}
1851+
return false;
1852+
}
1853+
18191854
/**
18201855
* @internal
18211856
* Store peer information
@@ -1865,8 +1900,6 @@ void pf_lldp_update_peer (
18651900
int loc_port_num,
18661901
const pf_lldp_peer_info_t * lldp_peer_info)
18671902
{
1868-
int error = 0;
1869-
char new_alias[PF_ALIAS_NAME_MAX_SIZE]; /** Terminated */
18701903
pf_port_t * p_port_data = pf_port_get_state (net, loc_port_num);
18711904

18721905
pf_lldp_reset_peer_timeout (net, loc_port_num, lldp_peer_info->ttl);
@@ -1881,27 +1914,41 @@ void pf_lldp_update_peer (
18811914
return;
18821915
}
18831916

1884-
error = pf_lldp_generate_alias_name (
1885-
lldp_peer_info->port_id.string,
1886-
lldp_peer_info->chassis_id.string,
1887-
new_alias,
1888-
sizeof (new_alias));
1889-
if (!error && (strcmp (new_alias, net->cmina_current_dcp_ase.alias_name) != 0))
1890-
{
1891-
LOG_INFO (
1892-
PF_LLDP_LOG,
1893-
"LLDP(%d): Updating alias name: %s -> %s\n",
1894-
__LINE__,
1895-
net->cmina_current_dcp_ase.alias_name,
1896-
new_alias);
1917+
LOG_INFO (
1918+
PF_LLDP_LOG,
1919+
"LLDP(%d): Port %d, peer info changed\n",
1920+
__LINE__,
1921+
loc_port_num);
18971922

1898-
strncpy (
1899-
net->cmina_current_dcp_ase.alias_name,
1900-
new_alias,
1901-
sizeof (net->cmina_current_dcp_ase.alias_name));
1923+
LOG_INFO (
1924+
PF_LLDP_LOG,
1925+
"LLDP(%d): Old peer info - MAC: %02X:%02X:%02X:%02X:%02X:%02X "
1926+
"Chassis ID: %s Port ID: %s\n",
1927+
__LINE__,
1928+
p_port_data->lldp.peer_info.mac_address.addr[0],
1929+
p_port_data->lldp.peer_info.mac_address.addr[1],
1930+
p_port_data->lldp.peer_info.mac_address.addr[2],
1931+
p_port_data->lldp.peer_info.mac_address.addr[3],
1932+
p_port_data->lldp.peer_info.mac_address.addr[4],
1933+
p_port_data->lldp.peer_info.mac_address.addr[5],
1934+
p_port_data->lldp.peer_info.chassis_id.string,
1935+
p_port_data->lldp.peer_info.port_id.string);
1936+
1937+
LOG_INFO (
1938+
PF_LLDP_LOG,
1939+
"LLDP(%d): New peer info - MAC: %02X:%02X:%02X:%02X:%02X:%02X "
1940+
"Chassis ID: %s Port ID: %s\n",
1941+
__LINE__,
1942+
lldp_peer_info->mac_address.addr[0],
1943+
lldp_peer_info->mac_address.addr[1],
1944+
lldp_peer_info->mac_address.addr[2],
1945+
lldp_peer_info->mac_address.addr[3],
1946+
lldp_peer_info->mac_address.addr[4],
1947+
lldp_peer_info->mac_address.addr[5],
1948+
lldp_peer_info->chassis_id.string,
1949+
lldp_peer_info->port_id.string);
19021950

1903-
pf_pdport_peer_indication (net, loc_port_num, lldp_peer_info);
1904-
}
1951+
pf_pdport_peer_indication (net, loc_port_num, lldp_peer_info);
19051952

19061953
pf_lldp_store_peer_info (net, loc_port_num, lldp_peer_info);
19071954
}

src/common/pf_lldp.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,16 @@ int pf_lldp_recv (
430430
pnal_buf_t * p_frame_buf,
431431
uint16_t offset);
432432

433+
/**
434+
* Check if an alias name matches any of the LLDP peers.
435+
*
436+
* @param net InOut: The p-net stack instance
437+
* @param alias In: Alias to be compared with LLDP peers
438+
* return true if the alias matches any of the peers,
439+
* false if not.
440+
*/
441+
bool pf_lldp_is_alias_matching (pnet_t * net, const char * alias);
442+
433443
/************ Internal functions, made available for unit testing ************/
434444

435445
int pf_lldp_generate_alias_name (

src/device/pf_cmina.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,10 +1150,6 @@ int pf_cmina_dcp_get_req (
11501150
*p_block_error = PF_DCP_BLOCK_ERROR_SUBOPTION_NOT_SUPPORTED;
11511151
ret = -1;
11521152
break;
1153-
case PF_DCP_SUB_DEV_PROP_ALIAS:
1154-
*p_value_length = sizeof (net->cmina_current_dcp_ase.alias_name);
1155-
*pp_value = (uint8_t *)&net->cmina_current_dcp_ase.alias_name;
1156-
break;
11571153
case PF_DCP_SUB_DEV_PROP_INSTANCE:
11581154
*p_value_length = sizeof (net->cmina_current_dcp_ase.instance_id);
11591155
*pp_value = (uint8_t *)&net->cmina_current_dcp_ase.instance_id;
@@ -1167,6 +1163,7 @@ int pf_cmina_dcp_get_req (
11671163
sizeof (net->cmina_current_dcp_ase.standard_gw_value);
11681164
*pp_value = (uint8_t *)&net->cmina_current_dcp_ase.standard_gw_value;
11691165
break;
1166+
case PF_DCP_SUB_DEV_PROP_ALIAS:
11701167
default:
11711168
*p_block_error = PF_DCP_BLOCK_ERROR_SUBOPTION_NOT_SUPPORTED;
11721169
ret = -1;

src/pf_types.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,8 +1103,6 @@ typedef struct pf_cmina_dcp_ase
11031103
uint8_t device_role; /* Only value "1" supported */
11041104
uint16_t device_initiative; /* 1: Should send hello. 0: No sending of hello
11051105
*/
1106-
1107-
char alias_name[PF_ALIAS_NAME_MAX_SIZE]; /** Terminated */
11081106
struct
11091107
{
11101108
/* Order is important!! */

0 commit comments

Comments
 (0)