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
1 change: 1 addition & 0 deletions docs/development/style_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ int caller()
return DP_OK;
}
```
> There is also a `DP_SUCCESS(ret)` for the unlikely inverse test, e.g. `if (DP_SUCCESS(rte_hash_lookup(...)))`.

### Boolean-like calls
If a function returns `0` for failure and a non-zero for success, use this pattern:
Expand Down
2 changes: 2 additions & 0 deletions include/dp_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ extern "C" {
// NOTICE: these can be used directly with a function call, do not use RET multiple times
#define DP_FAILED(RET) \
((RET) < 0)
#define DP_SUCCESS(RET) \
(!DP_FAILED(RET))
#define DP_FAILED_LOG(RET, LOGGER, ...) \
(DP_FAILED(RET) ? LOGGER(__VA_ARGS__), true : false)

Expand Down
2 changes: 1 addition & 1 deletion src/dp_flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static __rte_always_inline void dp_mark_vnf_type(struct dp_flow *df, const struc
key->vnf_type = df->vnf_type;
else
key->vnf_type = DP_VNF_TYPE_UNDEFINED;
} else if (!DP_FAILED(dp_ipv6_from_ipaddr(&dst_ipv6, &key->l3_dst))) {
} else if (DP_SUCCESS(dp_ipv6_from_ipaddr(&dst_ipv6, &key->l3_dst))) {
// assuming key->l3_src is also IPv6 (no IPv4<->IPv6 packets exist)
if (dp_is_ipv6_nat64(&dst_ipv6))
key->vnf_type = DP_VNF_TYPE_NAT;
Expand Down
4 changes: 2 additions & 2 deletions src/dp_lb.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int dp_create_lb(struct dpgrpc_lb *lb, const union dp_ipv6 *ul_ip)
lb_key.vni = lb->vni;
dp_copy_ipaddr(&lb_key.ip, &lb->addr);

if (!DP_FAILED(rte_hash_lookup(lb_table, &lb_key)))
if (DP_SUCCESS(rte_hash_lookup(lb_table, &lb_key)))
return DP_GRPC_ERR_ALREADY_EXISTS;

lb_val = rte_zmalloc("lb_val", sizeof(struct lb_value), RTE_CACHE_LINE_SIZE);
Expand Down Expand Up @@ -203,7 +203,7 @@ bool dp_is_ip_lb(struct dp_flow *df, uint32_t vni)
else
return false;

return !DP_FAILED(rte_hash_lookup(lb_table, &lb_key));
return DP_SUCCESS(rte_hash_lookup(lb_table, &lb_key));
}

static bool dp_lb_is_back_ip_inserted(struct lb_value *val, const union dp_ipv6 *b_ip)
Expand Down
10 changes: 5 additions & 5 deletions src/dp_vnf.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ int dp_add_vnf(const union dp_ipv6 *ul_addr6, enum dp_vnf_type type,
int ret;

ret = rte_hash_lookup_with_hash(vnf_handle_tbl, ul_addr6, hash);
if (ret != -ENOENT) {
if (!DP_FAILED(ret))
DPS_LOG_WARNING("Underlay address already registered", DP_LOG_IPV6(*ul_addr6));
else
DPS_LOG_ERR("VNF hash table lookup failed", DP_LOG_RET(ret));
if (DP_SUCCESS(ret)) {
DPS_LOG_WARNING("Underlay address already registered", DP_LOG_IPV6(*ul_addr6));
return DP_ERROR;
} else if (ret != -ENOENT) {
DPS_LOG_ERR("VNF hash table lookup failed", DP_LOG_RET(ret));
return DP_ERROR;
}

Expand Down
2 changes: 1 addition & 1 deletion src/nodes/rx_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static uint64_t get_current_timestamp(void)
if (!port->allocated)
continue;
ret = rte_eth_read_clock(port->port_id, &timestamp);
if (!DP_FAILED(ret))
if (DP_SUCCESS(ret))
break;
}
return timestamp;
Expand Down
2 changes: 1 addition & 1 deletion tools/inspect/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ int main(int argc, char **argv)
}

ret = dp_inspect_init(dp_conf_get_table(), get_format(dp_conf_get_output_format()), &spec);
if (!DP_FAILED(ret)) {
if (DP_SUCCESS(ret)) {
if (!spec.table_name)
list_tables(dp_conf_get_output_format());
else
Expand Down
Loading