Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config endpoint in raweth locator #364

Merged
merged 13 commits into from
Mar 14, 2024
1 change: 0 additions & 1 deletion include/zenoh-pico/session/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ void _z_reply_data_clear(_z_reply_data_t *rd);

_Z_ELEM_DEFINE(_z_reply_data, _z_reply_data_t, _z_noop_size, _z_reply_data_clear, _z_noop_copy)
_Z_LIST_DEFINE(_z_reply_data, _z_reply_data_t)
_Z_ARRAY_DEFINE(_z_reply_data, _z_reply_data_t)

/**
* An reply to a :c:func:`z_query`.
Expand Down
29 changes: 27 additions & 2 deletions include/zenoh-pico/system/link/raweth.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <stdint.h>

#include "zenoh-pico/collections/string.h"
#include "zenoh-pico/protocol/core.h"
#include "zenoh-pico/system/platform.h"

#if Z_FEATURE_RAWETH_TRANSPORT == 1
Expand All @@ -31,6 +32,27 @@
// Max frame size
#define _ZP_MAX_ETH_FRAME_SIZE 1514

// Endpoing config types
typedef struct {
_z_keyexpr_t _keyexpr;
uint16_t _vlan; // vlan tag (pcp + dei + id), big endian
uint8_t _dmac[_ZP_MAC_ADDR_LENGTH];
_Bool _has_vlan;
} _zp_raweth_mapping_entry_t;

void _z_raweth_clear_mapping_entry(_zp_raweth_mapping_entry_t *entry);

_Z_ELEM_DEFINE(_zp_raweth_mapping, _zp_raweth_mapping_entry_t, _z_noop_size, _z_raweth_clear_mapping_entry,

Check warning

Code scanning / Cppcheck (reported by Codacy)

There is an unknown macro here somewhere. Configuration is required. If _Z_ELEM_DEFINE is a macro then please configure it. Warning

There is an unknown macro here somewhere. Configuration is required. If _Z_ELEM_DEFINE is a macro then please configure it.
_z_noop_copy)
_Z_ARRAY_DEFINE(_zp_raweth_mapping, _zp_raweth_mapping_entry_t)

typedef struct {
uint8_t _mac[_ZP_MAC_ADDR_LENGTH];
} _zp_raweth_whitelist_entry_t;

_Z_ELEM_DEFINE(_zp_raweth_whitelist, _zp_raweth_whitelist_entry_t, _z_noop_size, _z_noop_clear, _z_noop_copy)
_Z_ARRAY_DEFINE(_zp_raweth_whitelist, _zp_raweth_whitelist_entry_t)

// Ethernet header structure type
typedef struct {
uint8_t dmac[_ZP_MAC_ADDR_LENGTH]; // Destination mac address
Expand All @@ -51,8 +73,10 @@
typedef struct {
const char *_interface;
_z_sys_net_socket_t _sock;
_zp_raweth_mapping_array_t _mapping;
_zp_raweth_whitelist_array_t _whitelist;
uint16_t _vlan;
uint16_t ethtype;
uint16_t _ethtype;
uint8_t _dmac[_ZP_MAC_ADDR_LENGTH];
uint8_t _smac[_ZP_MAC_ADDR_LENGTH];
_Bool _has_vlan;
Expand All @@ -61,7 +85,8 @@
int8_t _z_get_smac_raweth(_z_raweth_socket_t *resock);
int8_t _z_open_raweth(_z_sys_net_socket_t *sock, const char *interface);
size_t _z_send_raweth(const _z_sys_net_socket_t *sock, const void *buff, size_t buff_len);
size_t _z_receive_raweth(const _z_sys_net_socket_t *sock, void *buff, size_t buff_len, _z_bytes_t *addr);
size_t _z_receive_raweth(const _z_sys_net_socket_t *sock, void *buff, size_t buff_len, _z_bytes_t *addr,
const _zp_raweth_whitelist_array_t *whitelist);
int8_t _z_close_raweth(_z_sys_net_socket_t *sock);
size_t _z_raweth_ntohs(size_t val);
size_t _z_raweth_htons(size_t val);
Expand Down
58 changes: 0 additions & 58 deletions include/zenoh-pico/transport/raweth/config.h

This file was deleted.

26 changes: 17 additions & 9 deletions src/system/unix/link/raweth.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@

#include "zenoh-pico/collections/string.h"
#include "zenoh-pico/config.h"
#include "zenoh-pico/protocol/keyexpr.h"
#include "zenoh-pico/system/link/raweth.h"
#include "zenoh-pico/system/platform/unix.h"
#include "zenoh-pico/transport/raweth/config.h"
#include "zenoh-pico/utils/logging.h"
#include "zenoh-pico/utils/pointers.h"

Expand All @@ -43,6 +44,8 @@
#else
#include <linux/if_packet.h>

void _z_raweth_clear_mapping_entry(_zp_raweth_mapping_entry_t *entry) { _z_keyexpr_clear(&entry->_keyexpr); }

Check warning

Code scanning / Cppcheck (reported by Codacy)

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

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

int8_t _z_open_raweth(_z_sys_net_socket_t *sock, const char *interface) {
int8_t ret = _Z_RES_OK;
// Open a raw network socket in promiscuous mode
Expand Down Expand Up @@ -89,19 +92,24 @@
return (size_t)wb;
}

size_t _z_receive_raweth(const _z_sys_net_socket_t *sock, void *buff, size_t buff_len, _z_bytes_t *addr) {
size_t _z_receive_raweth(const _z_sys_net_socket_t *sock, void *buff, size_t buff_len, _z_bytes_t *addr,

Check warning

Code scanning / Cppcheck (reported by Codacy)

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

misra violation 804 with no text in the supplied rule-texts-file
const _zp_raweth_whitelist_array_t *whitelist) {
// Read from socket
ssize_t bytesRead = recvfrom(sock->_fd, buff, buff_len, 0, NULL, NULL);
if ((bytesRead < 0) || (bytesRead < sizeof(_zp_eth_header_t))) {
return SIZE_MAX;
}
// Address filtering
_zp_eth_header_t *header = (_zp_eth_header_t *)buff;
_Bool is_valid = false;
for (size_t i = 0; i < _ZP_RAWETH_CFG_WHITELIST_SIZE; i++) {
if (memcmp(&header->smac, _ZP_RAWETH_CFG_WHITELIST[i]._mac, _ZP_MAC_ADDR_LENGTH) == 0) { // Test byte ordering
is_valid = true;
break;
_Bool is_valid = true;
// Address filtering (only if there is a whitelist)
if (_zp_raweth_whitelist_array_len(whitelist) > 0) {
is_valid = false;
const _zp_eth_header_t *header = (_zp_eth_header_t *)buff;
for (size_t i = 0; i < _zp_raweth_whitelist_array_len(whitelist); i++) {
const _zp_raweth_whitelist_entry_t *entry = _zp_raweth_whitelist_array_get(whitelist, i);
if (memcmp(&header->smac, entry->_mac, _ZP_MAC_ADDR_LENGTH) == 0) {
is_valid = true;
break;
}
}
}
// Ignore packet from unknown sources
Expand Down
47 changes: 0 additions & 47 deletions src/transport/raweth/config.c

This file was deleted.

Loading
Loading