diff options
author | Daniel Borkmann <dborkman@redhat.com> | 2013-06-25 12:17:27 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-06-25 19:33:04 -0400 |
commit | 52db882f3fc2903014e638ee91e690085fe37fdb (patch) | |
tree | da6cd52645dca68bf16d40387421cc93fd094ea4 /net/sctp/sm_make_chunk.c | |
parent | d36f82b2435690d8742235d7bdc5bb5e878077e3 (diff) |
net: sctp: migrate cookie life from timeval to ktime
Currently, SCTP code defines its own timeval functions (since timeval
is rarely used inside the kernel by others), namely tv_lt() and
TIMEVAL_ADD() macros, that operate on SCTP cookie expiration.
We might as well remove all those, and operate directly on ktime
structures for a couple of reasons: ktime is available on all archs;
complexity of ktime calculations depending on the arch is less than
(reduces to a simple arithmetic operations on archs with
BITS_PER_LONG == 64 or CONFIG_KTIME_SCALAR) or equal to timeval
functions (other archs); code becomes more readable; macros can be
thrown out.
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Acked-by: Vlad Yasevich <vyasevich@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/sctp/sm_make_chunk.c')
-rw-r--r-- | net/sctp/sm_make_chunk.c | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c index fc8548743ed5..dd71f1f9ba10 100644 --- a/net/sctp/sm_make_chunk.c +++ b/net/sctp/sm_make_chunk.c | |||
@@ -1630,8 +1630,8 @@ static sctp_cookie_param_t *sctp_pack_cookie(const struct sctp_endpoint *ep, | |||
1630 | cookie->c.adaptation_ind = asoc->peer.adaptation_ind; | 1630 | cookie->c.adaptation_ind = asoc->peer.adaptation_ind; |
1631 | 1631 | ||
1632 | /* Set an expiration time for the cookie. */ | 1632 | /* Set an expiration time for the cookie. */ |
1633 | do_gettimeofday(&cookie->c.expiration); | 1633 | cookie->c.expiration = ktime_add(asoc->cookie_life, |
1634 | TIMEVAL_ADD(asoc->cookie_life, cookie->c.expiration); | 1634 | ktime_get()); |
1635 | 1635 | ||
1636 | /* Copy the peer's init packet. */ | 1636 | /* Copy the peer's init packet. */ |
1637 | memcpy(&cookie->c.peer_init[0], init_chunk->chunk_hdr, | 1637 | memcpy(&cookie->c.peer_init[0], init_chunk->chunk_hdr, |
@@ -1680,7 +1680,7 @@ struct sctp_association *sctp_unpack_cookie( | |||
1680 | unsigned int len; | 1680 | unsigned int len; |
1681 | sctp_scope_t scope; | 1681 | sctp_scope_t scope; |
1682 | struct sk_buff *skb = chunk->skb; | 1682 | struct sk_buff *skb = chunk->skb; |
1683 | struct timeval tv; | 1683 | ktime_t kt; |
1684 | struct hash_desc desc; | 1684 | struct hash_desc desc; |
1685 | 1685 | ||
1686 | /* Header size is static data prior to the actual cookie, including | 1686 | /* Header size is static data prior to the actual cookie, including |
@@ -1757,11 +1757,11 @@ no_hmac: | |||
1757 | * down the new association establishment instead of every packet. | 1757 | * down the new association establishment instead of every packet. |
1758 | */ | 1758 | */ |
1759 | if (sock_flag(ep->base.sk, SOCK_TIMESTAMP)) | 1759 | if (sock_flag(ep->base.sk, SOCK_TIMESTAMP)) |
1760 | skb_get_timestamp(skb, &tv); | 1760 | kt = skb_get_ktime(skb); |
1761 | else | 1761 | else |
1762 | do_gettimeofday(&tv); | 1762 | kt = ktime_get(); |
1763 | 1763 | ||
1764 | if (!asoc && tv_lt(bear_cookie->expiration, tv)) { | 1764 | if (!asoc && ktime_compare(bear_cookie->expiration, kt) < 0) { |
1765 | /* | 1765 | /* |
1766 | * Section 3.3.10.3 Stale Cookie Error (3) | 1766 | * Section 3.3.10.3 Stale Cookie Error (3) |
1767 | * | 1767 | * |
@@ -1773,9 +1773,7 @@ no_hmac: | |||
1773 | len = ntohs(chunk->chunk_hdr->length); | 1773 | len = ntohs(chunk->chunk_hdr->length); |
1774 | *errp = sctp_make_op_error_space(asoc, chunk, len); | 1774 | *errp = sctp_make_op_error_space(asoc, chunk, len); |
1775 | if (*errp) { | 1775 | if (*errp) { |
1776 | suseconds_t usecs = (tv.tv_sec - | 1776 | suseconds_t usecs = ktime_to_us(ktime_sub(kt, bear_cookie->expiration)); |
1777 | bear_cookie->expiration.tv_sec) * 1000000L + | ||
1778 | tv.tv_usec - bear_cookie->expiration.tv_usec; | ||
1779 | __be32 n = htonl(usecs); | 1777 | __be32 n = htonl(usecs); |
1780 | 1778 | ||
1781 | sctp_init_cause(*errp, SCTP_ERROR_STALE_COOKIE, | 1779 | sctp_init_cause(*errp, SCTP_ERROR_STALE_COOKIE, |
@@ -2514,8 +2512,7 @@ do_addr_param: | |||
2514 | /* Suggested Cookie Life span increment's unit is msec, | 2512 | /* Suggested Cookie Life span increment's unit is msec, |
2515 | * (1/1000sec). | 2513 | * (1/1000sec). |
2516 | */ | 2514 | */ |
2517 | asoc->cookie_life.tv_sec += stale / 1000; | 2515 | asoc->cookie_life = ktime_add_ms(asoc->cookie_life, stale); |
2518 | asoc->cookie_life.tv_usec += (stale % 1000) * 1000; | ||
2519 | break; | 2516 | break; |
2520 | 2517 | ||
2521 | case SCTP_PARAM_HOST_NAME_ADDRESS: | 2518 | case SCTP_PARAM_HOST_NAME_ADDRESS: |