Skip to content

Commit

Permalink
feat: send to default address if key not found
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Dec 20, 2023
1 parent 636f088 commit c15abca
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions src/transport/raweth/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ static void _zp_raweth_unlock_tx_mutex(_z_transport_multicast_t *ztm) { _z_mutex
static void _zp_raweth_unlock_tx_mutex(_z_transport_multicast_t *ztm) { _ZP_UNUSED(ztm); }
#endif

static int _zp_raweth_find_map_entry(const _z_keyexpr_t *keyexpr, _z_raweth_socket_t *sock) {

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 207 with no text in the supplied rule-texts-file Warning

misra violation 207 with no text in the supplied rule-texts-file
for (int i = 1; i < _ZP_RAWETH_CFG_SIZE; i++) {
// Find matching keyexpr
if (zp_keyexpr_intersect_null_terminated(keyexpr->_suffix, _ZP_RAWETH_CFG_ARRAY[i]._keyexpr._suffix) !=
_Z_RES_OK) {
continue;
}
return i;

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 15.5 rule Note

MISRA 15.5 rule
}
return -1;
}

static int8_t _zp_raweth_set_socket(const _z_keyexpr_t *keyexpr, _z_raweth_socket_t *sock) {
int8_t ret = _Z_RES_OK;

Expand All @@ -53,22 +65,18 @@ static int8_t _zp_raweth_set_socket(const _z_keyexpr_t *keyexpr, _z_raweth_socke
}
} else {
// Find config entry (linear)
ret = _Z_ERR_GENERIC; // Key not found case
for (int i = 1; i < _ZP_RAWETH_CFG_SIZE; i++) {
// Find matching keyexpr
if (zp_keyexpr_intersect_null_terminated(keyexpr->_suffix, _ZP_RAWETH_CFG_ARRAY[i]._keyexpr._suffix) !=
_Z_RES_OK) {
continue;
}
// Store data into socket
memcpy(&sock->_dmac, &_ZP_RAWETH_CFG_ARRAY[i]._dmac, _ZP_MAC_ADDR_LENGTH);
uint16_t vlan = _ZP_RAWETH_CFG_ARRAY[i]._vlan;
sock->_has_vlan = _ZP_RAWETH_CFG_ARRAY[i]._has_vlan;
if (sock->_has_vlan) {
memcpy(&sock->_vlan, &vlan, sizeof(vlan));
}
ret = _Z_RES_OK;
break;
int idx = _zp_raweth_find_map_entry(keyexpr, sock);
// Key not found case
if (idx < 0) {
idx = 0; // Set to default entry
_Z_DEBUG("Key '%s' wasn't found in config mapping, sending to default address\n", keyexpr->_suffix);
}
// Store data into socket
memcpy(&sock->_dmac, &_ZP_RAWETH_CFG_ARRAY[idx]._dmac, _ZP_MAC_ADDR_LENGTH);

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 17.7 rule Note

MISRA 17.7 rule
uint16_t vlan = _ZP_RAWETH_CFG_ARRAY[idx]._vlan;
sock->_has_vlan = _ZP_RAWETH_CFG_ARRAY[idx]._has_vlan;
if (sock->_has_vlan) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 14.4 rule Note

MISRA 14.4 rule
memcpy(&sock->_vlan, &vlan, sizeof(vlan));

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 17.7 rule Note

MISRA 17.7 rule
}
}
return ret;
Expand Down

0 comments on commit c15abca

Please sign in to comment.