Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/csp/csp_iflist.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ void csp_iflist_add(csp_iface_t * iface);
*/
void csp_iflist_remove(csp_iface_t * ifc);

/**
* Iterate over the list of interfaces.
*
* @param[in] ifc Previous interface to continue iteration, or NULL to start at the head of the list.
* @return Pointer to the next interface, or NULL if the end of the list is reached.
*/
csp_iface_t * csp_iflist_iterate(csp_iface_t * ifc);

csp_iface_t * csp_iflist_get_by_name(const char * name);
csp_iface_t * csp_iflist_get_by_addr(uint16_t addr);
csp_iface_t * csp_iflist_get_by_broadcast(uint16_t addr);
Expand Down
4 changes: 2 additions & 2 deletions include/csp/interfaces/csp_if_zmqhub.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ void * csp_zmqhub_fixup_cspv1_del_dest_addr(uint8_t * rx_data, size_t * datalen)
*
* Safe to call after `csp_zmqhub_init_filter2()` to change promiscuity.
*/
void csp_zmqhub_remove_filters(csp_iface_t * zmq_iface);
int csp_zmqhub_remove_filters(csp_iface_t * zmq_iface);

/**
* Make `zmq_iface` unpromiscuous, only parse matching unicast and broadcast addresses.
*
* Safe to call after `csp_zmqhub_init_filter2()` to change promiscuity.
*/
void csp_zmqhub_add_filters(csp_iface_t * zmq_iface);
int csp_zmqhub_add_filters(csp_iface_t * zmq_iface);


#ifdef __cplusplus
Expand Down
4 changes: 2 additions & 2 deletions src/csp_iflist.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ int csp_iflist_is_within_subnet(uint16_t addr, csp_iface_t * ifc) {
if (ifc == NULL) {
return 0;
}

uint16_t netmask = ((1 << ifc->netmask) - 1) << (csp_id_get_host_bits() - ifc->netmask);
uint16_t network_a = ifc->addr & netmask;
uint16_t network_b = addr & netmask;
Expand Down Expand Up @@ -87,7 +87,7 @@ csp_iface_t * csp_iflist_get_by_isdfl(csp_iface_t * ifc) {

}

static csp_iface_t * csp_iflist_iterate(csp_iface_t * ifc) {
csp_iface_t * csp_iflist_iterate(csp_iface_t * ifc) {

/* Head of list */
if (ifc == NULL) {
Expand Down
19 changes: 13 additions & 6 deletions src/interfaces/csp_if_zmqhub.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,11 @@ int csp_zmqhub_init_w_name_endpoints_rxfilter(const char * ifname, uint16_t addr
return CSP_ERR_NONE;
}

void csp_zmqhub_remove_filters(csp_iface_t * zmq_iface) {
int csp_zmqhub_remove_filters(csp_iface_t * zmq_iface) {

if(zmq_iface == NULL || zmq_iface->driver_data == NULL || zmq_iface->nexthop != csp_zmqhub_tx) {
return -1;
}

int ret = 0;
zmq_driver_t * drv = zmq_iface->driver_data;
Expand All @@ -290,7 +294,7 @@ void csp_zmqhub_remove_filters(csp_iface_t * zmq_iface) {
/* subscribe to all packets - no filter */
ret = zmq_setsockopt(drv->subscriber, ZMQ_SUBSCRIBE, NULL, 0);
assert(ret == 0);
(void)ret;
return ret;
}

static int csp_zmqhub_add_filter(void * driver_data, uint16_t addr) {
Expand All @@ -307,8 +311,11 @@ static int csp_zmqhub_add_filter(void * driver_data, uint16_t addr) {
return ret;
}

void csp_zmqhub_add_filters(csp_iface_t * zmq_iface) {
int csp_zmqhub_add_filters(csp_iface_t * zmq_iface) {

if(zmq_iface == NULL || zmq_iface->driver_data == NULL || zmq_iface->nexthop != csp_zmqhub_tx) {
return -1;
}
int ret = 0;
zmq_driver_t * drv = zmq_iface->driver_data;
const uint16_t addr = zmq_iface->addr;
Expand All @@ -329,11 +336,11 @@ void csp_zmqhub_add_filters(csp_iface_t * zmq_iface) {
ret = zmq_setsockopt(drv->subscriber, ZMQ_SUBSCRIBE, &drv->filt[i][2], 2);
}
assert(ret == 0);
(void)ret;
return ret;
}

int csp_zmqhub_init_filter2(const char * ifname, const char * host, uint16_t addr, uint16_t netmask, int promisc, csp_iface_t ** return_interface, char * sec_key, uint16_t subport, uint16_t pubport) {

/* ZMQ will cause valgrind errors if `sec_key` isn't exactly 40 characters long.
For now we deliberately parse an empty string as if no sec_key was specified. */
const ssize_t sec_key_len = sec_key ? strnlen(sec_key, CURVE_KEYLEN-1) : 0;
Expand Down Expand Up @@ -411,7 +418,7 @@ int csp_zmqhub_init_filter2(const char * ifname, const char * host, uint16_t add
zmq_setsockopt(drv->subscriber, ZMQ_TCP_KEEPALIVE_IDLE, &idle, sizeof(idle));
zmq_setsockopt(drv->subscriber, ZMQ_TCP_KEEPALIVE_CNT, &cnt, sizeof(cnt));
zmq_setsockopt(drv->subscriber, ZMQ_TCP_KEEPALIVE_INTVL, &intvl, sizeof(intvl));

/* Connect to server */
ret = zmq_connect(drv->publisher, pub);
assert(ret == 0);
Expand Down