Skip to content

Commit

Permalink
Added type conversion compiler checks
Browse files Browse the repository at this point in the history
  • Loading branch information
PlagueCZ committed Nov 21, 2023
1 parent 3479854 commit 17c13c9
Show file tree
Hide file tree
Showing 42 changed files with 203 additions and 134 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ COPY hack/*.patch hack/
RUN cd $DPDK_DIR && patch -p1 < ../hack/dpdk_22_11_gcc12.patch
RUN cd $DPDK_DIR && patch -p1 < ../hack/dpdk_22_11_log.patch
RUN cd $DPDK_DIR && patch -p1 < ../hack/dpdk_22_11_telemetry_key.patch
RUN cd $DPDK_DIR && patch -p1 < ../hack/dpdk_22_11_ethdev_conversion.patch

# Compile DPDK
RUN cd $DPDK_DIR && meson setup -Dmax_ethports=132 -Dplatform=generic -Ddisable_drivers=common/dpaax,\
Expand Down
1 change: 1 addition & 0 deletions docs/development/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ cd dpdk-stable-22.11.3
patch -p1 < ../net-dpservice/hack/dpdk_22_11_gcc12.patch
patch -p1 < ../net-dpservice/hack/dpdk_22_11_log.patch
patch -p1 < ../net-dpservice/hack/dpdk_22_11_telemetry_key.patch
patch -p1 < ../net-dpservice/hack/dpdk_22_11_ethdev_conversion.patch
meson setup build
ninja -C build
sudo ninja -C build install
Expand Down
26 changes: 26 additions & 0 deletions hack/dpdk_22_11_ethdev_conversion.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index 5d5e18db1e..d8908b722a 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -387,7 +387,7 @@ eth_is_valid_owner_id(uint64_t owner_id)
return 1;
}

-uint64_t
+uint16_t
rte_eth_find_next_owned_by(uint16_t port_id, const uint64_t owner_id)
{
port_id = rte_eth_find_next(port_id);
diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h
index c129ca1eaf..a92fe1259e 100644
--- a/lib/ethdev/rte_ethdev.h
+++ b/lib/ethdev/rte_ethdev.h
@@ -2059,7 +2059,7 @@ struct rte_eth_dev_owner {
* @return
* Next valid port ID owned by owner_id, RTE_MAX_ETHPORTS if there is none.
*/
-uint64_t rte_eth_find_next_owned_by(uint16_t port_id,
+uint16_t rte_eth_find_next_owned_by(uint16_t port_id,
const uint64_t owner_id);

/**
2 changes: 1 addition & 1 deletion include/dp_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct dp_conf_virtual_services {
#endif

struct dp_conf_dhcp_dns {
int len;
uint8_t len;
uint8_t *array;
};

Expand Down
2 changes: 1 addition & 1 deletion include/dp_flow.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ int dp_build_flow_key(struct flow_key *key /* out */, struct rte_mbuf *m /* in *
void dp_invert_flow_key(const struct flow_key *key /* in */, struct flow_key *inv_key /* out */);
int dp_flow_init(int socket_id);
void dp_flow_free(void);
void dp_process_aged_flows(int port_id);
void dp_process_aged_flows(uint16_t port_id);
void dp_process_aged_flows_non_offload(void);
void dp_free_flow(struct dp_ref *ref);
void dp_free_network_nat_port(const struct flow_value *cntrack);
Expand Down
4 changes: 2 additions & 2 deletions include/dp_mbuf_dyn.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ struct dp_flow {
rte_be32_t nat_addr;
uint16_t nat_port;

uint8_t nxt_hop;

uint8_t l4_type;
union {
struct {
Expand All @@ -88,6 +86,8 @@ struct dp_flow {
uint32_t dst_vni;
} tun_info;

uint16_t nxt_hop; // this can be brought down to only one byte (low DP_MAX_PORTS)

struct flow_value *conntrack;
#ifdef ENABLE_VIRTSVC
struct dp_virtsvc *virtsvc;
Expand Down
8 changes: 4 additions & 4 deletions include/dp_vnf.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ enum dp_vnf_type {

struct dp_vnf_prefix {
uint32_t ip;
uint16_t length;
uint8_t length;
};

struct dp_vnf {
Expand All @@ -42,13 +42,13 @@ int dp_vnf_init(int socket_id);
void dp_vnf_free(void);

int dp_add_vnf(const uint8_t ul_addr6[DP_VNF_IPV6_ADDR_SIZE], enum dp_vnf_type type,
uint16_t port_id, uint32_t vni, uint32_t prefix_ip, uint16_t prefix_len);
uint16_t port_id, uint32_t vni, uint32_t prefix_ip, uint8_t prefix_len);
const struct dp_vnf *dp_get_vnf(const uint8_t ul_addr6[DP_VNF_IPV6_ADDR_SIZE]);
int dp_del_vnf(const uint8_t ul_addr6[DP_VNF_IPV6_ADDR_SIZE]);

bool dp_vnf_lbprefix_exists(uint16_t port_id, uint32_t vni, uint32_t prefix_ip, uint16_t prefix_len);
bool dp_vnf_lbprefix_exists(uint16_t port_id, uint32_t vni, uint32_t prefix_ip, uint8_t prefix_len);

int dp_del_vnf_by_value(enum dp_vnf_type type, uint16_t port_id, uint32_t vni, uint32_t prefix_ip, uint16_t prefix_len);
int dp_del_vnf_by_value(enum dp_vnf_type type, uint16_t port_id, uint32_t vni, uint32_t prefix_ip, uint8_t prefix_len);

int dp_list_vnf_alias_prefixes(uint16_t port_id, enum dp_vnf_type type, struct dp_grpc_responder *responder);

Expand Down
20 changes: 10 additions & 10 deletions include/grpc/dp_grpc_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ struct dpgrpc_address {

struct dpgrpc_prefix {
struct dpgrpc_address addr;
uint32_t length;
uint8_t length;
char iface_id[DP_IFACE_ID_MAX_LEN];
};

struct dpgrpc_route {
struct dpgrpc_address pfx_addr;
uint32_t pfx_length;
uint8_t pfx_length;
uint32_t vni;
struct dpgrpc_address trgt_addr;
uint32_t trgt_vni;
Expand Down Expand Up @@ -181,8 +181,8 @@ struct dpgrpc_capture_interface {
struct dpgrpc_capture {
uint8_t dst_addr6[DP_VNF_IPV6_ADDR_SIZE];
uint8_t interface_count;
uint32_t udp_src_port;
uint32_t udp_dst_port;
uint16_t udp_src_port;
uint16_t udp_dst_port;
struct dpgrpc_capture_interface interfaces[DP_CAPTURE_MAX_PORT_NUM];
bool is_active;
};
Expand All @@ -192,7 +192,7 @@ struct dpgrpc_capture_stop {
};

struct dpgrpc_request {
uint16_t type; // enum dpgrpc_request_type
enum dpgrpc_request_type type;
union {
struct dpgrpc_iface add_iface;
struct dpgrpc_iface_id del_iface;
Expand Down Expand Up @@ -251,12 +251,12 @@ struct dpgrpc_vni_in_use {
};

struct dpgrpc_reply {
uint8_t type; // copied enum dpgrpc_request_type
uint8_t is_chained;
uint16_t msg_count;
uint32_t err_code;
enum dpgrpc_request_type type; // copied enum dpgrpc_request_type
bool is_chained;
uint16_t msg_count;
uint32_t err_code;
union {
uint8_t messages[0]; // used for multiresponse mode
uint8_t messages[0]; // used for multiresponse mode
struct dpgrpc_ul_addr ul_addr;
struct dpgrpc_iface iface;
struct dpgrpc_vf_pci vf_pci;
Expand Down
7 changes: 3 additions & 4 deletions include/grpc/dp_grpc_responder.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ struct dp_grpc_responder {
struct dpgrpc_reply *rep;
size_t rep_max_size;
size_t msg_size;
int rep_capacity;
int rep_msgcount;
size_t rep_capacity;
uint16_t rep_msgcount;
};

// returns request's type
uint16_t dp_grpc_init_responder(struct dp_grpc_responder *responder, struct rte_mbuf *req_mbuf);
enum dpgrpc_request_type dp_grpc_init_responder(struct dp_grpc_responder *responder, struct rte_mbuf *req_mbuf);

static inline void *dp_grpc_single_reply(struct dp_grpc_responder *responder)
{
Expand Down
6 changes: 3 additions & 3 deletions include/monitoring/dp_monitoring.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ struct dp_event_msg {

struct dp_capture_hdr_config {
uint8_t capture_node_ipv6_addr[16];
uint32_t capture_udp_src_port;
uint32_t capture_udp_dst_port;
uint16_t capture_udp_src_port;
uint16_t capture_udp_dst_port;
};

void dp_process_event_msg(struct rte_mbuf *m);


void dp_set_capture_hdr_config(uint8_t *addr, uint32_t udp_src_port, uint32_t udp_dst_port);
void dp_set_capture_hdr_config(uint8_t *addr, uint16_t udp_src_port, uint16_t udp_dst_port);
const struct dp_capture_hdr_config *dp_get_capture_hdr_config(void);

void dp_set_capture_enabled(bool enabled);
Expand Down
4 changes: 3 additions & 1 deletion include/rte_flow/dp_rte_flow_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,9 @@ void dp_set_flow_age_action(struct rte_flow_action *action,
struct rte_flow_action_age *flow_age_action,
uint32_t timeout, void *age_context)
{
flow_age_action->timeout = timeout;
// timeout has only 24 bits
// mask should be safe, this is a defined constant unless in testing mode
flow_age_action->timeout = timeout & 0x00FFFFFF;
flow_age_action->reserved = 0;
flow_age_action->context = age_context;
action->type = RTE_FLOW_ACTION_TYPE_AGE;
Expand Down
4 changes: 2 additions & 2 deletions include/rte_flow/dp_rte_flow_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ extern "C" {
#include <rte_flow.h>
#include "dp_port.h"

int dp_install_isolated_mode_ipip(int port_id, uint8_t proto_id);
int dp_install_isolated_mode_ipip(uint16_t port_id, uint8_t proto_id);

#ifdef ENABLE_VIRTSVC
int dp_install_isolated_mode_virtsvc(int port_id, uint8_t proto_id, const uint8_t svc_ipv6[16], uint16_t svc_port);
int dp_install_isolated_mode_virtsvc(uint16_t port_id, uint8_t proto_id, const uint8_t svc_ipv6[16], uint16_t svc_port);
#endif

#ifdef __cplusplus
Expand Down
3 changes: 2 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ if get_option('warning_level').to_int() >= 2
common_flags = [
# -Werror provided by 'werror=true' in default project options
# -Wall -Wextra provided by 'warning_level=2' in default project options
'-Wunused', '-Wshadow', '-Wundef', '-Wcast-qual', '-Wwrite-strings', '-Wpointer-arith',
'-Wunused', '-Wshadow', '-Wundef', '-Wcast-qual', '-Wwrite-strings', '-Wpointer-arith',
'-Wconversion', '-Wno-sign-conversion'
]
cflags += common_flags + [
'-Wbad-function-cast', '-Wmissing-declarations', '-Wstrict-prototypes', '-Wmissing-prototypes',
Expand Down
2 changes: 1 addition & 1 deletion src/dp_argparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int dp_argparse_enum(const char *arg, int *dst, const char *choices[], size_t ch
{
for (size_t i = 0; i < choice_count; ++i) {
if (!strcmp(choices[i], arg)) {
*dst = i;
*dst = (int)i;
return DP_OK;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/dp_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static int add_virtsvc(uint8_t proto, const char *str)
DP_EARLY_ERR("Invalid virtual service IPv4 port '%s'", tok);
return DP_ERROR;
}
from_port = htons(longport);
from_port = htons((uint16_t)longport);

tok = strtok(NULL, ",");
if (!tok) {
Expand All @@ -158,7 +158,7 @@ static int add_virtsvc(uint8_t proto, const char *str)
DP_EARLY_ERR("Invalid virtual service IPv6 port '%s'", tok);
return DP_ERROR;
}
to_port = htons(longport);
to_port = htons((uint16_t)longport);

// prevent virtual/service address duplicates
for (int i = 0; i < virtual_services.nb_entries; ++i) {
Expand Down
7 changes: 4 additions & 3 deletions src/dp_flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ int dp_destroy_rte_flow_agectx(struct flow_age_ctx *agectx)
return DP_OK;
}

void dp_process_aged_flows(int port_id)
void dp_process_aged_flows(uint16_t port_id)
{
int total, fetched;
struct flow_age_ctx *agectx;
Expand Down Expand Up @@ -485,10 +485,11 @@ hash_sig_t dp_get_conntrack_flow_hash_value(const struct flow_key *key)

int dp_add_rte_age_ctx(struct flow_value *cntrack, struct flow_age_ctx *ctx)
{
for (size_t i = 0; i < sizeof(cntrack->rte_age_ctxs); ++i) {
static_assert(RTE_DIM(cntrack->rte_age_ctxs) <= UINT8_MAX, "Conntrack age context storage is too large");
for (size_t i = 0; i < RTE_DIM(cntrack->rte_age_ctxs); ++i) {
if (!cntrack->rte_age_ctxs[i]) {
cntrack->rte_age_ctxs[i] = ctx;
ctx->ref_index_in_cntrack = i;
ctx->ref_index_in_cntrack = (uint8_t)i;
return DP_OK;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/dp_hairpin.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

static int setup_hairpin_rx_tx_queues(uint16_t port_id,
uint16_t peer_port_id,
uint8_t hairpin_queue_id,
uint8_t peer_hairpin_queue_id)
uint16_t hairpin_queue_id,
uint16_t peer_hairpin_queue_id)
{
int ret;

Expand Down
2 changes: 1 addition & 1 deletion src/dp_lb.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ uint8_t *dp_lb_get_backend_ip(uint32_t ol_ip, uint32_t vni, rte_be16_t port, uin
if (pos < 0)
return NULL;

lb_val->last_sel_pos = pos;
lb_val->last_sel_pos = (uint16_t)pos;
return (uint8_t *)&lb_val->back_end_ips[pos][0];
}

Expand Down
4 changes: 2 additions & 2 deletions src/dp_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ static const char *json_escape(const char *message, char *buf, size_t bufsize)
buf[bufpos++] = 'u';
buf[bufpos++] = '0';
buf[bufpos++] = '0';
buf[bufpos++] = '0' + hi;
buf[bufpos++] = lo >= 10 ? 'a' + (lo-10) : '0' + lo;
buf[bufpos++] = (char)('0' + hi);
buf[bufpos++] = (char)(lo >= 10 ? 'a' + (lo-10) : '0' + lo);
} else if (c == '\\' || c == '\"') {
if (bufpos + 2 >= bufsize)
break;
Expand Down
6 changes: 3 additions & 3 deletions src/dp_lpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ static int dp_list_route_entry(struct rte_rib_node *node,
// can only fail when any argument is NULL
rte_rib_get_nh(node, &next_hop);

dst_port = dp_get_port_by_id(next_hop);
dst_port = dp_get_port_by_id((uint16_t)next_hop);
if (unlikely(!dst_port))
return DP_GRPC_ERR_NO_VM;

Expand Down Expand Up @@ -297,7 +297,7 @@ const struct dp_port *dp_get_ip4_out_port(const struct dp_port *in_port,
if (DP_FAILED(rte_rib_get_nh(node, &next_hop)))
return NULL;

dst_port = dp_get_port_by_id(next_hop);
dst_port = dp_get_port_by_id((uint16_t)next_hop);
if (!dst_port)
return NULL;

Expand Down Expand Up @@ -334,7 +334,7 @@ const struct dp_port *dp_get_ip6_out_port(const struct dp_port *in_port,
if (DP_FAILED(rte_rib6_get_nh(node, &next_hop)))
return NULL;

dst_port = dp_get_port_by_id(next_hop);
dst_port = dp_get_port_by_id((uint16_t)next_hop);
if (!dst_port)
return NULL;

Expand Down
10 changes: 5 additions & 5 deletions src/dp_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static int dp_read_neigh(struct nlmsghdr *nh, __u32 nll, struct rte_ether_addr *
{
struct rtattr *rt_attr;
struct ndmsg *rt_msg;
int rtl, ndm_family;
size_t rtl, ndm_family;

for (; NLMSG_OK(nh, nll); nh = NLMSG_NEXT(nh, nll)) {
rt_msg = (struct ndmsg *)NLMSG_DATA(nh);
Expand All @@ -40,13 +40,13 @@ static int dp_read_neigh(struct nlmsghdr *nh, __u32 nll, struct rte_ether_addr *
static int dp_recv_msg(struct sockaddr_nl sock_addr, int sock, char *buf, int bufsize)
{
struct nlmsghdr *nh;
int recv_len;
int msg_len = 0;
ssize_t recv_len;
ssize_t msg_len = 0;

for (;;) {
recv_len = recv(sock, buf, bufsize - msg_len, 0);
if (recv_len < 0)
return recv_len;
return (int)recv_len;

nh = (struct nlmsghdr *)buf;
if (nh->nlmsg_type == NLMSG_DONE)
Expand All @@ -60,7 +60,7 @@ static int dp_recv_msg(struct sockaddr_nl sock_addr, int sock, char *buf, int bu
if ((sock_addr.nl_groups & RTMGRP_IPV6_ROUTE) == RTMGRP_IPV6_ROUTE)
break;
}
return msg_len;
return (int)msg_len;
}

int dp_get_pf_neigh_mac(int if_idx, struct rte_ether_addr *neigh, const struct rte_ether_addr *own_mac)
Expand Down
Loading

0 comments on commit 17c13c9

Please sign in to comment.