From b3b28afb7bef9094d05fcc8c1be4a41f9f1d5bfe Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 11 Aug 2008 13:44:29 -0700 Subject: [PATCH] Use signal-based timekeeping functions throughout the source base. --- lib/dhcp-client.c | 13 +++++++------ lib/learning-switch.c | 5 +++-- lib/netlink.c | 3 ++- lib/rconn.c | 28 ++++++++++++++-------------- lib/vlog-socket.c | 2 +- lib/vlog.c | 5 +++-- secchan/secchan.c | 2 +- switch/datapath.c | 15 ++++++++------- switch/switch-flow.c | 5 +++-- 9 files changed, 42 insertions(+), 36 deletions(-) diff --git a/lib/dhcp-client.c b/lib/dhcp-client.c index 3bed59101..97ae318d8 100644 --- a/lib/dhcp-client.c +++ b/lib/dhcp-client.c @@ -51,6 +51,7 @@ #include "netdev.h" #include "ofp-print.h" #include "poll-loop.h" +#include "timeval.h" #define THIS_MODULE VLM_dhcp_client #include "vlog.h" @@ -194,7 +195,7 @@ dhclient_create(const char *netdev_name, cli->aux = aux; cli->netdev = netdev; cli->state = S_RELEASED; - cli->state_entered = time(0); + cli->state_entered = time_now(); cli->xid = random_uint32(); cli->ipaddr = 0; cli->server_ip = 0; @@ -238,7 +239,7 @@ dhclient_release(struct dhclient *cli) static void do_force_renew(struct dhclient *cli, int deadline) { - time_t now = time(0); + time_t now = time_now(); unsigned int lease_left = sat_sub(cli->lease_expiration, now); if (lease_left <= deadline) { if (cli->state & (S_RENEWING | S_REBINDING)) { @@ -672,7 +673,7 @@ receive_ack(struct dhclient *cli) t1 = calc_t1(lease, t2); } - cli->lease_expiration = sat_add(time(0), lease); + cli->lease_expiration = sat_add(time_now(), lease); cli->bound_timeout = t1; cli->renewing_timeout = t2 - t1; cli->rebinding_timeout = lease - t2; @@ -777,7 +778,7 @@ state_transition(struct dhclient *cli, enum dhclient_state state) VLOG_DBG("entering %s", state_name(state)); cli->state = state; } - cli->state_entered = time(0); + cli->state_entered = time_now(); cli->retransmit = cli->delay = 0; am_bound = dhclient_is_bound(cli); if (was_bound != am_bound) { @@ -838,14 +839,14 @@ dhclient_msg_init(struct dhclient *cli, enum dhcp_msg_type type, static unsigned int elapsed_in_this_state(const struct dhclient *cli) { - return time(0) - cli->state_entered; + return time_now() - cli->state_entered; } static bool timeout(struct dhclient *cli, unsigned int secs) { cli->min_timeout = MIN(cli->min_timeout, secs); - return time(0) >= sat_add(cli->state_entered, secs); + return time_now() >= sat_add(cli->state_entered, secs); } static bool diff --git a/lib/learning-switch.c b/lib/learning-switch.c index 0dfdeae5a..d41602d6b 100644 --- a/lib/learning-switch.c +++ b/lib/learning-switch.c @@ -47,6 +47,7 @@ #include "openflow.h" #include "queue.h" #include "rconn.h" +#include "timeval.h" #include "vconn.h" #include "xtoxll.h" @@ -88,7 +89,7 @@ lswitch_create(struct rconn *rconn, bool learn_macs, int max_idle) memset(sw, 0, sizeof *sw); sw->max_idle = max_idle; sw->datapath_id = 0; - sw->last_features_request = time(0) - 1; + sw->last_features_request = time_now() - 1; sw->ml = learn_macs ? mac_learning_create() : NULL; send_features_request(sw, rconn); return sw; @@ -148,7 +149,7 @@ lswitch_process_packet(struct lswitch *sw, struct rconn *rconn, static void send_features_request(struct lswitch *sw, struct rconn *rconn) { - time_t now = time(0); + time_t now = time_now(); if (now >= sw->last_features_request + 1) { struct buffer *b; struct ofp_header *ofr; diff --git a/lib/netlink.c b/lib/netlink.c index d9dd435c0..9abe26a55 100644 --- a/lib/netlink.c +++ b/lib/netlink.c @@ -44,6 +44,7 @@ #include "buffer.h" #include "netlink-protocol.h" #include "dynamic-string.h" +#include "timeval.h" #include "util.h" #include "vlog.h" @@ -99,7 +100,7 @@ nl_sock_create(int protocol, int multicast_group, if (next_seq == 0) { /* Pick initial sequence number. */ - next_seq = getpid() ^ time(0); + next_seq = getpid() ^ time_now(); } *sockp = NULL; diff --git a/lib/rconn.c b/lib/rconn.c index 9bb2b5c5b..0093c3ab5 100644 --- a/lib/rconn.c +++ b/lib/rconn.c @@ -161,7 +161,7 @@ rconn_create(int txq_limit, int probe_interval, int max_backoff) struct rconn *rc = xcalloc(1, sizeof *rc); rc->state = S_VOID; - rc->state_entered = time(0); + rc->state_entered = time_now(); rc->vconn = NULL; rc->name = xstrdup("void"); @@ -174,13 +174,13 @@ rconn_create(int txq_limit, int probe_interval, int max_backoff) rc->backoff = 0; rc->max_backoff = max_backoff ? max_backoff : 60; rc->backoff_deadline = TIME_MIN; - rc->last_received = time(0); - rc->last_connected = time(0); + rc->last_received = time_now(); + rc->last_connected = time_now(); rc->packets_sent = 0; rc->questionable_connectivity = false; - rc->last_questioned = time(0); + rc->last_questioned = time_now(); rc->probe_interval = probe_interval ? MAX(5, probe_interval) : 0; @@ -207,7 +207,7 @@ rconn_connect_unreliably(struct rconn *rc, rc->name = xstrdup(name); rc->reliable = false; rc->vconn = vconn; - rc->last_connected = time(0); + rc->last_connected = time_now(); state_transition(rc, S_ACTIVE); } @@ -260,7 +260,7 @@ reconnect(struct rconn *rc) VLOG_WARN("%s: connecting...", rc->name); retval = vconn_open(rc->name, &rc->vconn); if (!retval) { - rc->backoff_deadline = time(0) + rc->backoff; + rc->backoff_deadline = time_now() + rc->backoff; state_transition(rc, S_CONNECTING); } else { VLOG_WARN("%s: connection failed (%s)", rc->name, strerror(retval)); @@ -341,7 +341,7 @@ run_ACTIVE(struct rconn *rc) unsigned int base = MAX(rc->last_received, rc->state_entered); queue_push_tail(&rc->txq, make_echo_request()); VLOG_DBG("%s: idle %u seconds, sending inactivity probe", - rc->name, (unsigned int) (time(0) - base)); + rc->name, (unsigned int) (time_now() - base)); state_transition(rc, S_IDLE); return; } @@ -413,7 +413,7 @@ rconn_recv(struct rconn *rc) struct buffer *buffer; int error = vconn_recv(rc->vconn, &buffer); if (!error) { - rc->last_received = time(0); + rc->last_received = time_now(); if (rc->state == S_IDLE) { state_transition(rc, S_ACTIVE); } @@ -522,7 +522,7 @@ rconn_is_connected(const struct rconn *rconn) int rconn_disconnected_duration(const struct rconn *rconn) { - return rconn_is_connected(rconn) ? 0 : time(0) - rconn->last_received; + return rconn_is_connected(rconn) ? 0 : time_now() - rconn->last_received; } /* Returns the IP address of the peer, or 0 if the peer is not connected over @@ -575,7 +575,7 @@ static void disconnect(struct rconn *rc, int error) { if (rc->reliable) { - time_t now = time(0); + time_t now = time_now(); if (rc->state & (S_CONNECTING | S_ACTIVE | S_IDLE)) { if (error > 0) { @@ -613,7 +613,7 @@ disconnect(struct rconn *rc, int error) static unsigned int elapsed_in_this_state(const struct rconn *rc) { - return time(0) - rc->state_entered; + return time_now() - rc->state_entered; } static unsigned int @@ -631,7 +631,7 @@ timeout(const struct rconn *rc) static bool timed_out(const struct rconn *rc) { - return time(0) >= sat_add(rc->state_entered, timeout(rc)); + return time_now() >= sat_add(rc->state_entered, timeout(rc)); } static void @@ -639,7 +639,7 @@ state_transition(struct rconn *rc, enum state state) { VLOG_DBG("%s: entering %s", rc->name, state_name(state)); rc->state = state; - rc->state_entered = time(0); + rc->state_entered = time_now(); } static unsigned int @@ -658,7 +658,7 @@ sat_mul(unsigned int x, unsigned int y) static void question_connectivity(struct rconn *rc) { - time_t now = time(0); + time_t now = time_now(); if (now - rc->last_questioned > 60) { rc->questionable_connectivity = true; rc->last_questioned = now; diff --git a/lib/vlog-socket.c b/lib/vlog-socket.c index a9f8a520b..49d9589d1 100644 --- a/lib/vlog-socket.c +++ b/lib/vlog-socket.c @@ -212,7 +212,7 @@ recv_with_creds(const struct vlog_server *server, fprintf(stderr, "vlog: config message not from a socket\n"); return -1; } - recent = time(0) - 30; + recent = time_now() - 30; if (s.st_atime < recent || s.st_ctime < recent || s.st_mtime < recent) { fprintf(stderr, "vlog: config socket too old\n"); return -1; diff --git a/lib/vlog.c b/lib/vlog.c index 6e098ef96..5216981b8 100644 --- a/lib/vlog.c +++ b/lib/vlog.c @@ -43,6 +43,7 @@ #include #include #include "dynamic-string.h" +#include "timeval.h" #include "util.h" #define THIS_MODULE VLM_vlog @@ -255,7 +256,7 @@ vlog_init(void) openlog(program_name, LOG_NDELAY, LOG_DAEMON); vlog_set_levels(VLM_ANY_MODULE, VLF_ANY_FACILITY, VLL_WARN); - now = time(0); + now = time_now(); if (now < 0) { struct tm tm; char s[128]; @@ -323,7 +324,7 @@ vlog(enum vlog_module module, enum vlog_level level, const char *message, ...) char s[1024]; size_t len, time_len; - now = time(0); + now = time_now(); localtime_r(&now, &tm); len = time_len = strftime(s, sizeof s, "%b %d %H:%M:%S|", &tm); diff --git a/secchan/secchan.c b/secchan/secchan.c index 6c0a70d25..e4fc62f66 100644 --- a/secchan/secchan.c +++ b/secchan/secchan.c @@ -462,7 +462,7 @@ get_controller_mac(struct netdev *netdev, struct rconn *controller) uint32_t last_ip = ip; - time_t now = time(0); + time_t now = time_now(); ip = rconn_get_ip(controller); if (last_ip != ip || !next_refresh || now >= next_refresh) { diff --git a/switch/datapath.c b/switch/datapath.c index d0013d847..31b9af2f5 100644 --- a/switch/datapath.c +++ b/switch/datapath.c @@ -48,6 +48,7 @@ #include "rconn.h" #include "vconn.h" #include "table.h" +#include "timeval.h" #include "xtoxll.h" #define THIS_MODULE VLM_datapath @@ -191,7 +192,7 @@ dp_new(struct datapath **dp_, uint64_t dpid, struct rconn *rconn) return ENOMEM; } - dp->last_timeout = time(0); + dp->last_timeout = time_now(); list_init(&dp->remotes); dp->controller = remote_create(dp, rconn); dp->listen_vconn = NULL; @@ -269,7 +270,7 @@ dp_add_listen_vconn(struct datapath *dp, struct vconn *listen_vconn) void dp_run(struct datapath *dp) { - time_t now = time(0); + time_t now = time_now(); struct sw_port *p, *pn; struct remote *r, *rn; struct buffer *buffer = NULL; @@ -697,7 +698,7 @@ send_flow_expired(struct datapath *dp, struct sw_flow *flow, ofe->reason = reason; memset(ofe->pad, 0, sizeof ofe->pad); - ofe->duration = htonl(time(0) - flow->created); + ofe->duration = htonl(time_now() - flow->created); memset(ofe->pad2, 0, sizeof ofe->pad2); ofe->packet_count = htonll(flow->packet_count); ofe->byte_count = htonll(flow->byte_count); @@ -1078,7 +1079,7 @@ add_flow(struct datapath *dp, const struct ofp_flow_mod *ofm) flow->priority = flow->key.wildcards ? ntohs(ofm->priority) : -1; flow->idle_timeout = ntohs(ofm->idle_timeout); flow->hard_timeout = ntohs(ofm->hard_timeout); - flow->used = flow->created = time(0); + flow->used = flow->created = time_now(); flow->n_actions = n_acts; flow->byte_count = 0; flow->packet_count = 0; @@ -1174,7 +1175,7 @@ static int flow_stats_dump(struct datapath *dp, void *state, flow_extract_match(&match_key, &s->rq.match); s->buffer = buffer; - s->now = time(0); + s->now = time_now(); while (s->table_idx < dp->chain->n_tables && (s->rq.table_id == 0xff || s->rq.table_id == s->table_idx)) { @@ -1585,7 +1586,7 @@ uint32_t save_buffer(struct buffer *buffer) if (p->buffer) { /* Don't buffer packet if existing entry is less than * OVERWRITE_SECS old. */ - if (time(0) < p->timeout) { /* FIXME */ + if (time_now() < p->timeout) { /* FIXME */ return -1; } else { buffer_delete(p->buffer); @@ -1596,7 +1597,7 @@ uint32_t save_buffer(struct buffer *buffer) if (++p->cookie >= (1u << PKT_COOKIE_BITS) - 1) p->cookie = 0; p->buffer = buffer_clone(buffer); /* FIXME */ - p->timeout = time(0) + OVERWRITE_SECS; /* FIXME */ + p->timeout = time_now() + OVERWRITE_SECS; /* FIXME */ id = buffer_idx | (p->cookie << PKT_BUFFER_BITS); return id; diff --git a/switch/switch-flow.c b/switch/switch-flow.c index 42ede871b..eea201c0a 100644 --- a/switch/switch-flow.c +++ b/switch/switch-flow.c @@ -40,6 +40,7 @@ #include "buffer.h" #include "openflow.h" #include "packets.h" +#include "timeval.h" /* Internal function used to compare fields in flow. */ static inline @@ -194,7 +195,7 @@ void print_flow(const struct sw_flow_key *key) bool flow_timeout(struct sw_flow *flow) { - time_t now = time(0); + time_t now = time_now(); if (flow->idle_timeout != OFP_FLOW_PERMANENT && now > flow->used + flow->idle_timeout) { flow->reason = OFPER_IDLE_TIMEOUT; @@ -210,7 +211,7 @@ bool flow_timeout(struct sw_flow *flow) void flow_used(struct sw_flow *flow, struct buffer *buffer) { - flow->used = time(0); + flow->used = time_now(); flow->packet_count++; flow->byte_count += buffer->size; } -- 2.43.0