aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Borkmann <dborkman@redhat.com>2013-06-25 12:17:27 -0400
committerDavid S. Miller <davem@davemloft.net>2013-06-25 19:33:04 -0400
commit52db882f3fc2903014e638ee91e690085fe37fdb (patch)
treeda6cd52645dca68bf16d40387421cc93fd094ea4
parentd36f82b2435690d8742235d7bdc5bb5e878077e3 (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>
-rw-r--r--include/net/sctp/sctp.h18
-rw-r--r--include/net/sctp/structs.h6
-rw-r--r--net/sctp/associola.c8
-rw-r--r--net/sctp/sm_make_chunk.c19
-rw-r--r--net/sctp/socket.c14
5 files changed, 15 insertions, 50 deletions
diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index 15214a825f92..e6b95bc4d8e6 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -560,24 +560,6 @@ for (pos = chunk->subh.fwdtsn_hdr->skip;\
560/* Round an int up to the next multiple of 4. */ 560/* Round an int up to the next multiple of 4. */
561#define WORD_ROUND(s) (((s)+3)&~3) 561#define WORD_ROUND(s) (((s)+3)&~3)
562 562
563/* Compare two timevals. */
564#define tv_lt(s, t) \
565 (s.tv_sec < t.tv_sec || (s.tv_sec == t.tv_sec && s.tv_usec < t.tv_usec))
566
567/* Add tv1 to tv2. */
568#define TIMEVAL_ADD(tv1, tv2) \
569({ \
570 suseconds_t usecs = (tv2).tv_usec + (tv1).tv_usec; \
571 time_t secs = (tv2).tv_sec + (tv1).tv_sec; \
572\
573 if (usecs >= 1000000) { \
574 usecs -= 1000000; \
575 secs++; \
576 } \
577 (tv2).tv_sec = secs; \
578 (tv2).tv_usec = usecs; \
579})
580
581/* External references. */ 563/* External references. */
582 564
583extern struct proto sctp_prot; 565extern struct proto sctp_prot;
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index 1bd4c4144fe8..e745c92a1532 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -54,7 +54,7 @@
54#ifndef __sctp_structs_h__ 54#ifndef __sctp_structs_h__
55#define __sctp_structs_h__ 55#define __sctp_structs_h__
56 56
57#include <linux/time.h> /* We get struct timespec. */ 57#include <linux/ktime.h>
58#include <linux/socket.h> /* linux/in.h needs this!! */ 58#include <linux/socket.h> /* linux/in.h needs this!! */
59#include <linux/in.h> /* We get struct sockaddr_in. */ 59#include <linux/in.h> /* We get struct sockaddr_in. */
60#include <linux/in6.h> /* We get struct in6_addr */ 60#include <linux/in6.h> /* We get struct in6_addr */
@@ -284,7 +284,7 @@ struct sctp_cookie {
284 __u32 peer_ttag; 284 __u32 peer_ttag;
285 285
286 /* When does this cookie expire? */ 286 /* When does this cookie expire? */
287 struct timeval expiration; 287 ktime_t expiration;
288 288
289 /* Number of inbound/outbound streams which are set 289 /* Number of inbound/outbound streams which are set
290 * and negotiated during the INIT process. 290 * and negotiated during the INIT process.
@@ -1537,7 +1537,7 @@ struct sctp_association {
1537 sctp_state_t state; 1537 sctp_state_t state;
1538 1538
1539 /* The cookie life I award for any cookie. */ 1539 /* The cookie life I award for any cookie. */
1540 struct timeval cookie_life; 1540 ktime_t cookie_life;
1541 1541
1542 /* Overall : The overall association error count. 1542 /* Overall : The overall association error count.
1543 * Error Count : [Clear this any time I get something.] 1543 * Error Count : [Clear this any time I get something.]
diff --git a/net/sctp/associola.c b/net/sctp/associola.c
index bf6e6bd553c0..9a383a8774e8 100644
--- a/net/sctp/associola.c
+++ b/net/sctp/associola.c
@@ -102,13 +102,7 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
102 sctp_bind_addr_init(&asoc->base.bind_addr, ep->base.bind_addr.port); 102 sctp_bind_addr_init(&asoc->base.bind_addr, ep->base.bind_addr.port);
103 103
104 asoc->state = SCTP_STATE_CLOSED; 104 asoc->state = SCTP_STATE_CLOSED;
105 105 asoc->cookie_life = ms_to_ktime(sp->assocparams.sasoc_cookie_life);
106 /* Set these values from the socket values, a conversion between
107 * millsecons to seconds/microseconds must also be done.
108 */
109 asoc->cookie_life.tv_sec = sp->assocparams.sasoc_cookie_life / 1000;
110 asoc->cookie_life.tv_usec = (sp->assocparams.sasoc_cookie_life % 1000)
111 * 1000;
112 asoc->frag_point = 0; 106 asoc->frag_point = 0;
113 asoc->user_frag = sp->user_frag; 107 asoc->user_frag = sp->user_frag;
114 108
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:
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 32db19ba4a21..4c47e5578d71 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -2910,13 +2910,8 @@ static int sctp_setsockopt_associnfo(struct sock *sk, char __user *optval, unsig
2910 asoc->max_retrans = assocparams.sasoc_asocmaxrxt; 2910 asoc->max_retrans = assocparams.sasoc_asocmaxrxt;
2911 } 2911 }
2912 2912
2913 if (assocparams.sasoc_cookie_life != 0) { 2913 if (assocparams.sasoc_cookie_life != 0)
2914 asoc->cookie_life.tv_sec = 2914 asoc->cookie_life = ms_to_ktime(assocparams.sasoc_cookie_life);
2915 assocparams.sasoc_cookie_life / 1000;
2916 asoc->cookie_life.tv_usec =
2917 (assocparams.sasoc_cookie_life % 1000)
2918 * 1000;
2919 }
2920 } else { 2915 } else {
2921 /* Set the values to the endpoint */ 2916 /* Set the values to the endpoint */
2922 struct sctp_sock *sp = sctp_sk(sk); 2917 struct sctp_sock *sp = sctp_sk(sk);
@@ -5074,10 +5069,7 @@ static int sctp_getsockopt_associnfo(struct sock *sk, int len,
5074 assocparams.sasoc_asocmaxrxt = asoc->max_retrans; 5069 assocparams.sasoc_asocmaxrxt = asoc->max_retrans;
5075 assocparams.sasoc_peer_rwnd = asoc->peer.rwnd; 5070 assocparams.sasoc_peer_rwnd = asoc->peer.rwnd;
5076 assocparams.sasoc_local_rwnd = asoc->a_rwnd; 5071 assocparams.sasoc_local_rwnd = asoc->a_rwnd;
5077 assocparams.sasoc_cookie_life = (asoc->cookie_life.tv_sec 5072 assocparams.sasoc_cookie_life = ktime_to_ms(asoc->cookie_life);
5078 * 1000) +
5079 (asoc->cookie_life.tv_usec
5080 / 1000);
5081 5073
5082 list_for_each(pos, &asoc->peer.transport_addr_list) { 5074 list_for_each(pos, &asoc->peer.transport_addr_list) {
5083 cnt ++; 5075 cnt ++;