History

tcp: prepare CC get_info() access from getsockopt()

We would like that optional info provided by Congestion Control modules using netlink can also be read using getsockopt() This patch changes get_info() to put this information in a buffer, instead of skb, like tcp_get_info(), so that following patch can reuse this common infrastructure.

Eric Dumazet committed 11 years ago

Commit 64f40ff1 parent bdd1f9e7 files · +46 −34Browse files

Unified · Split

7 files
  1. include/net/tcp.h +4 −1
  2. include/uapi/linux/inet_diag.h +4 −0
  3. net/ipv4/inet_diag.c +5 −3
  4. net/ipv4/tcp_dctcp.c +10 −10
  5. net/ipv4/tcp_illinois.c +11 −10
  6. net/ipv4/tcp_vegas.c +10 −9
  7. net/ipv4/tcp_vegas.h +2 −1
include/net/tcp.h+4−1
@@ -804,6 +804,8 @@ enum tcp_ca_ack_event_flags { · 803 unmodified lines
804804 /* Requires ECN/ECT set on all packets */
805805 #define TCP_CONG_NEEDS_ECN 0x2
806806
807+union tcp_cc_info;
808+
807809 struct tcp_congestion_ops {
808810 struct list_head list;
809811 u32 key;
@@ -829,7 +831,8 @@ struct tcp_congestion_ops { · 19 unmodified lines
829831 /* hook for packet ack accounting (optional) */
830832 void (*pkts_acked)(struct sock *sk, u32 num_acked, s32 rtt_us);
831833 /* get info for inet_diag (optional) */
832− int (*get_info)(struct sock *sk, u32 ext, struct sk_buff *skb);
834+ size_t (*get_info)(struct sock *sk, u32 ext, int *attr,
835+ union tcp_cc_info *info);
833836
834837 char name[TCP_CA_NAME_MAX];
835838 struct module *owner;
include/uapi/linux/inet_diag.h+4−0
@@ -143,4 +143,8 @@ struct tcp_dctcp_info { · 142 unmodified lines
143143 __u32 dctcp_ab_tot;
144144 };
145145
146+union tcp_cc_info {
147+ struct tcpvegas_info vegas;
148+ struct tcp_dctcp_info dctcp;
149+};
146150 #endif /* _UAPI_INET_DIAG_H_ */
net/ipv4/inet_diag.c+5−3
@@ -224,14 +224,16 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk, · 223 unmodified lines
224224 handler->idiag_get_info(sk, r, info);
225225
226226 if (sk->sk_state < TCP_TIME_WAIT) {
227− int err = 0;
227+ union tcp_cc_info info;
228+ size_t sz = 0;
229+ int attr;
228230
229231 rcu_read_lock();
230232 ca_ops = READ_ONCE(icsk->icsk_ca_ops);
231233 if (ca_ops && ca_ops->get_info)
232− err = ca_ops->get_info(sk, ext, skb);
234+ sz = ca_ops->get_info(sk, ext, &attr, &info);
233235 rcu_read_unlock();
234− if (err < 0)
236+ if (sz && nla_put(skb, attr, sz, &info) < 0)
235237 goto errout;
236238 }
237239
net/ipv4/tcp_dctcp.c+10−10
@@ -277,7 +277,8 @@ static void dctcp_cwnd_event(struct sock *sk, enum tcp_ca_event ev) · 276 unmodified lines
277277 }
278278 }
279279
280−static int dctcp_get_info(struct sock *sk, u32 ext, struct sk_buff *skb)
280+static size_t dctcp_get_info(struct sock *sk, u32 ext, int *attr,
281+ union tcp_cc_info *info)
281282 {
282283 const struct dctcp *ca = inet_csk_ca(sk);
283284
@@ -286,18 +287,17 @@ static int dctcp_get_info(struct sock *sk, u32 ext, struct sk_buff *skb) · 2 unmodified lines
286287 */
287288 if (ext & (1 << (INET_DIAG_DCTCPINFO - 1)) ||
288289 ext & (1 << (INET_DIAG_VEGASINFO - 1))) {
289− struct tcp_dctcp_info info;
290−
291− memset(&info, 0, sizeof(info));
290+ memset(info, 0, sizeof(struct tcp_dctcp_info));
292291 if (inet_csk(sk)->icsk_ca_ops != &dctcp_reno) {
293− info.dctcp_enabled = 1;
294− info.dctcp_ce_state = (u16) ca->ce_state;
295− info.dctcp_alpha = ca->dctcp_alpha;
296− info.dctcp_ab_ecn = ca->acked_bytes_ecn;
297− info.dctcp_ab_tot = ca->acked_bytes_total;
292+ info->dctcp.dctcp_enabled = 1;
293+ info->dctcp.dctcp_ce_state = (u16) ca->ce_state;
294+ info->dctcp.dctcp_alpha = ca->dctcp_alpha;
295+ info->dctcp.dctcp_ab_ecn = ca->acked_bytes_ecn;
296+ info->dctcp.dctcp_ab_tot = ca->acked_bytes_total;
298297 }
299298
300− return nla_put(skb, INET_DIAG_DCTCPINFO, sizeof(info), &info);
299+ *attr = INET_DIAG_DCTCPINFO;
300+ return sizeof(*info);
301301 }
302302 return 0;
303303 }
net/ipv4/tcp_illinois.c+11−10
@@ -300,24 +300,25 @@ static u32 tcp_illinois_ssthresh(struct sock *sk) · 299 unmodified lines
300300 }
301301
302302 /* Extract info for Tcp socket info provided via netlink. */
303−static int tcp_illinois_info(struct sock *sk, u32 ext, struct sk_buff *skb)
303+static size_t tcp_illinois_info(struct sock *sk, u32 ext, int *attr,
304+ union tcp_cc_info *info)
304305 {
305306 const struct illinois *ca = inet_csk_ca(sk);
306307
307308 if (ext & (1 << (INET_DIAG_VEGASINFO - 1))) {
308− struct tcpvegas_info info = {
309− .tcpv_enabled = 1,
310− .tcpv_rttcnt = ca->cnt_rtt,
311− .tcpv_minrtt = ca->base_rtt,
312− };
309+ info->vegas.tcpv_enabled = 1;
310+ info->vegas.tcpv_rttcnt = ca->cnt_rtt;
311+ info->vegas.tcpv_minrtt = ca->base_rtt;
312+ info->vegas.tcpv_rtt = 0;
313313
314− if (info.tcpv_rttcnt > 0) {
314+ if (info->vegas.tcpv_rttcnt > 0) {
315315 u64 t = ca->sum_rtt;
316316
317− do_div(t, info.tcpv_rttcnt);
318− info.tcpv_rtt = t;
317+ do_div(t, info->vegas.tcpv_rttcnt);
318+ info->vegas.tcpv_rtt = t;
319319 }
320− return nla_put(skb, INET_DIAG_VEGASINFO, sizeof(info), &info);
320+ *attr = INET_DIAG_VEGASINFO;
321+ return sizeof(struct tcpvegas_info);
321322 }
322323 return 0;
323324 }
net/ipv4/tcp_vegas.c+10−9
@@ -286,18 +286,19 @@ static void tcp_vegas_cong_avoid(struct sock *sk, u32 ack, u32 acked) · 285 unmodified lines
286286 }
287287
288288 /* Extract info for Tcp socket info provided via netlink. */
289−int tcp_vegas_get_info(struct sock *sk, u32 ext, struct sk_buff *skb)
289+size_t tcp_vegas_get_info(struct sock *sk, u32 ext, int *attr,
290+ union tcp_cc_info *info)
290291 {
291292 const struct vegas *ca = inet_csk_ca(sk);
293+
292294 if (ext & (1 << (INET_DIAG_VEGASINFO - 1))) {
293− struct tcpvegas_info info = {
294− .tcpv_enabled = ca->doing_vegas_now,
295− .tcpv_rttcnt = ca->cntRTT,
296− .tcpv_rtt = ca->baseRTT,
297− .tcpv_minrtt = ca->minRTT,
298− };
299−
300− return nla_put(skb, INET_DIAG_VEGASINFO, sizeof(info), &info);
295+ info->vegas.tcpv_enabled = ca->doing_vegas_now,
296+ info->vegas.tcpv_rttcnt = ca->cntRTT,
297+ info->vegas.tcpv_rtt = ca->baseRTT,
298+ info->vegas.tcpv_minrtt = ca->minRTT,
299+
300+ *attr = INET_DIAG_VEGASINFO;
301+ return sizeof(struct tcpvegas_info);
301302 }
302303 return 0;
303304 }
net/ipv4/tcp_vegas.h+2−1
@@ -19,6 +19,7 @@ void tcp_vegas_init(struct sock *sk); · 18 unmodified lines
1919 void tcp_vegas_state(struct sock *sk, u8 ca_state);
2020 void tcp_vegas_pkts_acked(struct sock *sk, u32 cnt, s32 rtt_us);
2121 void tcp_vegas_cwnd_event(struct sock *sk, enum tcp_ca_event event);
22−int tcp_vegas_get_info(struct sock *sk, u32 ext, struct sk_buff *skb);
22+size_t tcp_vegas_get_info(struct sock *sk, u32 ext, int *attr,
23+ union tcp_cc_info *info);
2324
2425 #endif /* __TCP_VEGAS_H */