Skip to content

Commit

Permalink
vrouter: use uint64_t in vr_get_time and vr_get_mono_time
Browse files Browse the repository at this point in the history
Changes required to support Contrail on Windows.
- use uint64_t in vr_get_time, instead of unsigned long
  (which is 32 bit on Windows)
- use uint64_t in vr_get_mono_time, instead of unsigned long
  (which is 32 bit on Windows)
- add missing __attribute__packed__open__ on vr_pbb_itag
- remove forward declaration of rtable_families in dp-core/vr_route.c
  (MSVC does not support forward declaring an array without a size)
- miscellaneous compilation fixes

Change-Id: Ibe8ab1f1e5e820430de75c8651cfbd1d2e4f0947
Partial-Bug: #1734699
  • Loading branch information
Dariusz Sosnowski committed Nov 30, 2017
1 parent 7e1320e commit d241c61
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 62 deletions.
4 changes: 2 additions & 2 deletions dp-core/vr_bridge.c
Expand Up @@ -634,7 +634,7 @@ bridge_table_init(struct vr_rtable *rtable, struct rtable_fspec *fs)
vr_bridge_table = vr_huge_page_mem_get(VR_BRIDGE_TABLE_SIZE +
VR_BRIDGE_OFLOW_TABLE_SIZE);
if (vr_bridge_table)
vr_bridge_otable = vr_bridge_table + VR_BRIDGE_TABLE_SIZE;
vr_bridge_otable = (unsigned char *)vr_bridge_table + VR_BRIDGE_TABLE_SIZE;
}

rtable->algo_data = vr_htable_attach(vrouter_get(0), vr_bridge_entries,
Expand Down Expand Up @@ -696,7 +696,7 @@ bridge_table_lock(struct vr_interface *vif, uint8_t *mac)
{
uint8_t lock = 1, *bridge_table_lock = vif->vif_bridge_table_lock;
uint32_t hash;
unsigned long t1s, t1ns, t2s, t2ns, diff;
uint64_t t1s, t1ns, t2s, t2ns, diff;

if (!bridge_table_lock)
return -EINVAL;
Expand Down
2 changes: 1 addition & 1 deletion dp-core/vr_datapath.c
Expand Up @@ -413,7 +413,7 @@ vr_mac_reply_send(struct vr_packet *pkt, struct vr_forwarding_md *fmd)
bool vif_tx = false;
struct vr_forwarding_md fmd_new;
struct vr_route_req rt;
struct vr_nexthop *nh;
struct vr_nexthop *nh = NULL;
struct vr_interface *vif = pkt->vp_if;

vr_init_forwarding_md(&fmd_new);
Expand Down
7 changes: 1 addition & 6 deletions dp-core/vr_flow.c
Expand Up @@ -70,12 +70,7 @@ unsigned int vr_trap_flow(struct vrouter *, struct vr_flow_entry *,

void get_random_bytes(void *buf, int nbytes);

#ifdef __FreeBSD__
uint32_t
jhash(void *key, uint32_t length, uint32_t initval);
#endif

#ifdef __FreeBSD__
#if defined(__FreeBSD__) || defined(_WIN32)
uint32_t
jhash(void *key, uint32_t length, uint32_t initval)
{
Expand Down
10 changes: 5 additions & 5 deletions dp-core/vr_fragment.c
Expand Up @@ -134,7 +134,7 @@ static inline void
fragment_entry_set(struct vr_fragment *fe, struct vr_fragment_key *key,
unsigned short sport, unsigned short dport)
{
unsigned long sec, nsec;
uint64_t sec, nsec;

fe->f_sip_u = key->fk_sip_u;
fe->f_sip_l = key->fk_sip_l;
Expand Down Expand Up @@ -208,7 +208,7 @@ unsigned int
vr_assembler_table_scan(struct vr_fragment **head)
{
unsigned int scanned = 0;
unsigned long sec, nsec, dest;
uint64_t sec, nsec, dest;
struct vr_fragment *frag = *head, *next, **prev;

prev = head;
Expand Down Expand Up @@ -307,7 +307,7 @@ vr_fragment_assembler(struct vr_fragment **head_p,
struct vr_fragment_queue_element *vfqe)
{
int ret = 0;
unsigned long sec, nsec;
uint64_t sec, nsec;
unsigned int list_length = 0, drop_reason;
bool found = false, frag_head = false;
uint64_t *v6_addr;
Expand Down Expand Up @@ -613,7 +613,7 @@ vr_v6_fragment_add(struct vrouter *router, unsigned short vrf,
struct vr_fragment *
vr_fragment_get(struct vrouter *router, unsigned short vrf, struct vr_ip *ip)
{
unsigned long sec, nsec;
uint64_t sec, nsec;
uint64_t *v6_addr;
struct vr_ip6 *ip6;
struct vr_ip6_frag *v6_frag;
Expand Down Expand Up @@ -660,7 +660,7 @@ static void
__fragment_reap(vr_htable_t table, vr_hentry_t *ent,
unsigned int index, void *data)
{
unsigned long sec, nsec;
uint64_t sec, nsec;
struct vr_fragment *fe;

fe = VR_FRAGMENT_FROM_HENTRY(ent);
Expand Down
2 changes: 1 addition & 1 deletion dp-core/vr_index_table.c
Expand Up @@ -4,7 +4,7 @@
#include <vr_index_table.h>
#include <vr_os.h>
#include <vrouter.h>
#if defined(__linux__)
#if defined(__linux__) || defined(_WIN32)
#include <stdarg.h>
#elif defined(__FreeBSD__)
#include <machine/stdarg.h>
Expand Down
8 changes: 4 additions & 4 deletions dp-core/vr_message.c
Expand Up @@ -62,7 +62,7 @@ vr_message_request(struct vr_message *message)
return -ENETRESET;

if (vr_not_ready)
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) || defined(_WIN32)
return -EBADF;
#else
return -EBADFD;
Expand Down Expand Up @@ -189,8 +189,8 @@ vr_message_multi_response(struct vr_message_multi *objects)
char *buf = NULL;
int ret = 0;
unsigned int i, buf_len = 0, len = 0;
struct vr_mproto *proto;
struct vr_mtransport *trans;
struct vr_mproto *proto = NULL;
struct vr_mtransport *trans = NULL;

if ((!objects) ||
(objects->vr_mm_object_count >= VR_MESSAGE_MULTI_MAX_OBJECTS))
Expand Down Expand Up @@ -228,7 +228,7 @@ vr_message_multi_response(struct vr_message_multi *objects)
return vr_message_queue_response(buf, len, false);

response_fail:
if (buf)
if (trans && buf)
trans->mtrans_free(buf);
vr_send_response(ret);

Expand Down
4 changes: 2 additions & 2 deletions dp-core/vr_mirror.c
Expand Up @@ -343,8 +343,8 @@ vr_mirror(struct vrouter *router, uint8_t mirror_id, struct vr_packet *pkt,
struct vr_forwarding_md *fmd, mirror_type_t mtype)
{
bool reset = true;
void *mirror_md;
unsigned char *buf, default_mme[2] = {0xff, 0x0};
void *mirror_md = NULL;
unsigned char *buf = NULL, default_mme[2] = {0xff, 0x0};
unsigned int captured_len, clone_len = 0;
unsigned int mirror_md_len = 0, drop_reason;
struct vr_nexthop *nh, *pkt_nh;
Expand Down
2 changes: 1 addition & 1 deletion dp-core/vr_qos.c
Expand Up @@ -630,7 +630,7 @@ vr_fc_map_get(vr_fc_map_req *req)
{
int ret = 0;

vr_fc_map_req *resp;
vr_fc_map_req *resp = NULL;
struct vrouter *router = vrouter_get(req->fmr_rid);
struct vr_forwarding_class *fc_p;

Expand Down
67 changes: 35 additions & 32 deletions dp-core/vr_route.c
Expand Up @@ -12,12 +12,16 @@

unsigned int vr_vrfs = VR_DEF_VRFS;

static struct rtable_fspec rtable_families[];
extern int mtrie_algo_init(struct vr_rtable *, struct rtable_fspec *);
extern void mtrie_algo_deinit(struct vr_rtable *, struct rtable_fspec *, bool);
extern int bridge_table_init(struct vr_rtable *, struct rtable_fspec *);
extern void bridge_table_deinit(struct vr_rtable *, struct rtable_fspec *, bool);

static int inet_rtb_family_init(struct rtable_fspec *fs, struct vrouter *router);
static void inet_rtb_family_deinit(struct rtable_fspec *fs, struct vrouter *router, bool soft_reset);
static int bridge_rtb_family_init(struct rtable_fspec *fs, struct vrouter *router);
static void bridge_rtb_family_deinit(struct rtable_fspec *fs, struct vrouter *router, bool soft_reset);

int vr_route_delete(vr_route_req *);
int vr_route_get(vr_route_req *);
int vr_route_dump(vr_route_req *);
Expand All @@ -28,6 +32,36 @@ int inet_route_del(struct rtable_fspec *, struct vr_route_req *);
int bridge_entry_add(struct rtable_fspec *, struct vr_route_req *);
int bridge_entry_del(struct rtable_fspec *, struct vr_route_req *);

/* hopefully we can afford a bit of bloat while loading ? */
static struct rtable_fspec rtable_families[] = {
{
.rtb_family = AF_INET,
.rtb_family_init = inet_rtb_family_init,
.rtb_family_deinit = inet_rtb_family_deinit,
.route_add = inet_route_add,
.route_del = inet_route_del,
.algo_init = mtrie_algo_init,
.algo_deinit = mtrie_algo_deinit,
},
{
.rtb_family = AF_BRIDGE,
.rtb_family_init = bridge_rtb_family_init,
.rtb_family_deinit = bridge_rtb_family_deinit,
.route_add = bridge_entry_add,
.route_del = bridge_entry_del,
.algo_init = bridge_table_init,
.algo_deinit = bridge_table_deinit,
},
{
.rtb_family = AF_INET6,
.rtb_family_init = inet_rtb_family_init,
.rtb_family_deinit = inet_rtb_family_deinit,
.route_add = inet_route_add,
.route_del = inet_route_del,
.algo_init = mtrie_algo_init,
.algo_deinit = mtrie_algo_deinit,
}
};

static struct rtable_fspec *
vr_get_family(unsigned int family)
Expand Down Expand Up @@ -564,37 +598,6 @@ bridge_rtb_family_deinit(struct rtable_fspec *fs, struct vrouter *router,
}
}

/* hopefully we can afford a bit of bloat while loading ? */
static struct rtable_fspec rtable_families[] = {
{
.rtb_family = AF_INET,
.rtb_family_init = inet_rtb_family_init,
.rtb_family_deinit = inet_rtb_family_deinit,
.route_add = inet_route_add,
.route_del = inet_route_del,
.algo_init = mtrie_algo_init,
.algo_deinit = mtrie_algo_deinit,
},
{
.rtb_family = AF_BRIDGE,
.rtb_family_init = bridge_rtb_family_init,
.rtb_family_deinit = bridge_rtb_family_deinit,
.route_add = bridge_entry_add,
.route_del = bridge_entry_del,
.algo_init = bridge_table_init,
.algo_deinit = bridge_table_deinit,
},
{
.rtb_family = AF_INET6,
.rtb_family_init = inet_rtb_family_init,
.rtb_family_deinit = inet_rtb_family_deinit,
.route_add = inet_route_add,
.route_del = inet_route_del,
.algo_init = mtrie_algo_init,
.algo_deinit = mtrie_algo_deinit,
}
};

void
vr_fib_exit(struct vrouter *router, bool soft_reset)
{
Expand Down
4 changes: 2 additions & 2 deletions dpdk/vr_dpdk_host.c
Expand Up @@ -570,7 +570,7 @@ dpdk_delete_timer(struct vr_timer *vtimer)
}

static void
dpdk_get_time(unsigned long *sec, unsigned long *usec)
dpdk_get_time(uint64_t *sec, uint64_t *usec)
{
struct timespec ts;

Expand All @@ -585,7 +585,7 @@ dpdk_get_time(unsigned long *sec, unsigned long *usec)
}

static void
dpdk_get_mono_time(unsigned long *sec, unsigned long *nsec)
dpdk_get_mono_time(uint64_t *sec, uint64_t *nsec)
{
struct timespec ts;

Expand Down
4 changes: 2 additions & 2 deletions freebsd/vrouter_mod.c
Expand Up @@ -369,7 +369,7 @@ fh_set_defer_data(void *data)
}

static void
fh_get_time(unsigned long *sec, unsigned long *usec)
fh_get_time(uint64_t *sec, uint64_t *usec)
{
struct timespec tsp;

Expand All @@ -382,7 +382,7 @@ fh_get_time(unsigned long *sec, unsigned long *usec)
}

static void
fh_get_mono_time(unsigned int *sec, unsigned int *nsec)
fh_get_mono_time(uint64_t *sec, uint64_t *nsec)
{
struct timespec tsp;

Expand Down
1 change: 1 addition & 0 deletions include/vr_packet.h
Expand Up @@ -245,6 +245,7 @@ struct vr_vlan_hdr {
unsigned short vlan_proto;
} __attribute__packed__close__;

__attribute__packed__open__
struct vr_pbb_itag {
uint8_t pbbi_pcp:3,
pbbi_dei:1,
Expand Down
4 changes: 2 additions & 2 deletions include/vrouter.h
Expand Up @@ -182,8 +182,8 @@ struct host_os {
void (*hos_defer)(struct vrouter *, vr_defer_cb, void *);
void *(*hos_get_defer_data)(unsigned int);
void (*hos_put_defer_data)(void *);
void (*hos_get_time)(unsigned long *, unsigned long *);
void (*hos_get_mono_time)(unsigned long *, unsigned long *);
void (*hos_get_time)(uint64_t *, uint64_t *);
void (*hos_get_mono_time)(uint64_t *, uint64_t *);
int (*hos_create_timer)(struct vr_timer *);
int (*hos_restart_timer)(struct vr_timer *);
void (*hos_delete_timer)(struct vr_timer *);
Expand Down
4 changes: 2 additions & 2 deletions linux/vrouter_mod.c
Expand Up @@ -397,7 +397,7 @@ lh_phead_len(struct vr_packet *pkt)
}

static void
lh_get_time(unsigned long *sec, unsigned long *usec)
lh_get_time(uint64_t *sec, uint64_t *usec)
{
struct timeval t;

Expand Down Expand Up @@ -429,7 +429,7 @@ lh_pfree_skb(struct sk_buff *skb, struct vr_interface *vif,


static void
lh_get_mono_time(unsigned long *sec, unsigned long *nsec)
lh_get_mono_time(uint64_t *sec, uint64_t *nsec)
{
struct timespec t;
uint64_t jiffies = get_jiffies_64();
Expand Down

0 comments on commit d241c61

Please sign in to comment.