Skip to content

Commit

Permalink
fix: return error when keyexpr not found
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Nov 30, 2023
1 parent 07f8992 commit 327dd39
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/transport/raweth/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ const uint8_t _ZP_RAWETH_CFG_SMAC[_ZP_MAC_ADDR_LENGTH] = {0x30, 0x03, 0xc8, 0x37

// Should be generated
const _zp_raweth_cfg_entry _ZP_RAWETH_CFG_ARRAY[] = {
{{0, {0}, ""}, 0x0000, {0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}, false}, // Default mac addr
{{0, {0}, "some/key/expr"}, 0x8c00, {0x00, 0x11, 0x22, 0x33, 0x44, 0x55}, true}, // entry1
{{0, {0}, "another/keyexpr"}, 0x4300, {0x01, 0x23, 0x45, 0x67, 0x89, 0xab}, true}, // entry2
{{0, {0}, ""}, 0x0000, {0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}, false}, // Default mac addr
{{0, {0}, "some/key/expr"}, 0x8c00, {0x00, 0x11, 0x22, 0x33, 0x44, 0x55}, true}, // entry1
{{0, {0}, "demo/example/zenoh-pico-pub"}, 0xab00, {0x41, 0x55, 0xa8, 0x00, 0x9d, 0xc0}, true}, // entry2
{{0, {0}, "another/keyexpr"}, 0x4300, {0x01, 0x23, 0x45, 0x67, 0x89, 0xab}, true}, // entry3
};

// Should be generated
Expand Down
10 changes: 6 additions & 4 deletions src/transport/raweth/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ int8_t _zp_raweth_set_socket(const _z_keyexpr_t *keyexpr, _z_raweth_socket_t *so
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)) {
if (zp_keyexpr_intersect_null_terminated(keyexpr->_suffix, _ZP_RAWETH_CFG_ARRAY[i]._keyexpr._suffix) !=
_Z_RES_OK) {
continue;
}
// Store data into socket
Expand All @@ -61,6 +62,7 @@ int8_t _zp_raweth_set_socket(const _z_keyexpr_t *keyexpr, _z_raweth_socket_t *so
memcpy(&sock->_vlan, &vlan, sizeof(vlan));
}
ret = _Z_RES_OK;
break;
}
}
return ret;
Expand Down Expand Up @@ -149,7 +151,7 @@ int8_t _z_raweth_link_send_t_msg(const _z_link_t *zl, const _z_transport_message
// Discard const qualifier
_z_link_t *mzl = (_z_link_t *)zl;
// Set socket info
_zp_raweth_set_socket(NULL, &mzl->_socket._raweth);
_Z_RETURN_IF_ERR(_zp_raweth_set_socket(NULL, &mzl->_socket._raweth));
// Write the message header
_Z_RETURN_IF_ERR(__unsafe_z_raweth_write_header(mzl, &wbf));
// Encode the session message
Expand Down Expand Up @@ -178,7 +180,7 @@ int8_t _z_raweth_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport_me
_z_mutex_lock(&ztm->_mutex_tx);
#endif
// Set socket info
_zp_raweth_set_socket(NULL, &ztm->_link._socket._raweth);
_Z_RETURN_IF_ERR(_zp_raweth_set_socket(NULL, &ztm->_link._socket._raweth));
// Write the message header
_Z_RETURN_IF_ERR(__unsafe_z_raweth_write_header(&ztm->_link, &ztm->_wbuf));
// Encode the session message
Expand Down Expand Up @@ -233,7 +235,7 @@ int8_t _z_raweth_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg,
break;
}
// Set socket info
_zp_raweth_set_socket(keyexpr, &ztm->_link._socket._raweth);
_Z_RETURN_IF_ERR(_zp_raweth_set_socket(keyexpr, &ztm->_link._socket._raweth));
// Write the eth header
_Z_RETURN_IF_ERR(__unsafe_z_raweth_write_header(&ztm->_link, &ztm->_wbuf));
// Set the frame header
Expand Down

0 comments on commit 327dd39

Please sign in to comment.