Interface for TCP Metrics
Subsystems (4)
v3 cover Interface for TCP Metrics
This patchset contains 3 patches, one for kernel
and two for iproute2. We add DUMP/GET/DEL support for genl "tcp_metrics" and minimal support for filtering by address prefix and family in user space.
I tested show/del/flush, filtering by family, IPv4 prefix,
output for metrics such as rtt, rttvar, cwnd, ssthresh (after modifying route). I didn't tested output for fast open.
May be some corrections in output can be desired.
v2:
- patch 1: remove rcu_assign_pointer, add tcp_metrics_flush_all
- patch 2: properly flush by specifying address, improve man page
v3:
- patch 1: remove synchronize_rcu
- patch 2: create libgenl.h and libgenl.c
- new patch 3: use libgenl.c also in ipl2tp.c
PATCH v3 1/3 tcp: add generic netlink support for tcp_metrics
Add support for genl "tcp_metrics". No locking
is changed, only that now we can unlink and delete entries after grace period. We implement get/del for single entry and dump to support show/flush filtering in user space. Del without address attribute causes flush for all addresses, sadly under genl_mutex.
v2:
- remove rcu_assign_pointer as suggested by Eric Dumazet, it is not needed because there are no other writes under lock
- move the flushing code in tcp_metrics_flush_all
v3:
- remove synchronize_rcu on flush as suggested by Eric Dumazet
--- include/linux/Kbuild | 1 + include/linux/tcp_metrics.h | 54 +++++++ net/ipv4/tcp_metrics.c | 354 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 396 insertions(+), 13 deletions(-) create mode 100644 include/linux/tcp_metrics.h
include/linux/Kbuild +1 -0
@@ -363,6 +363,7 @@ header-y += sysctl.h header-y += sysinfo.h header-y += taskstats.h header-y += tcp.h +header-y += tcp_metrics.h header-y += telephony.h header-y += termios.h header-y += time.h
include/linux/tcp_metrics.h new file +54 -0
54 lines not on this page · raw message
net/ipv4/tcp_metrics.c +341 -13
386 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH v3 2/3 iproute2: add support for tcp_metrics
In reply to Julian Anastasovip tcp_metrics/tcpmetrics
v2:
- On flush we should provide the address in req2
- "flush all" should use single del, just like when "all" is not provided
- Explain printed information in man page
v3:
- move genl code into new files: libgenl.h and libgenl.c
---
include/libgenl.h +25 -0
@@ -0,0 +1,25 @@ +#ifndef __LIBGENL_H__ +#define __LIBGENL_H__ + +#include "libnetlink.h" + +#define GENL_DEFINE_REQUEST (req, hdrsize, bufsiz) \ +struct { \ + struct nlmsghdr n; \ + struct genlmsghdr g; \ + char buf[NLMSG_ALIGN(hdrsize) + bufsiz]; \ +} req + +#define GENL_INIT_REQUEST (req, family, hdrsize, ver, cmd_, flags) \ + do { \ + memset(&req, 0, sizeof(req)); \ + req.n.nlmsg_type = family; \ + req.n.nlmsg_flags = flags; \ + req.n.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN + hdrsize); \ + req.g.cmd = cmd_; \ + req.g.version = ver; \ + } while (0) + +int libgenl_resolve_family (struct rtnl_handle *grth,const char *family); + +#endif /* __LIBGENL_H__ */
include/linux/tcp_metrics.h +54 -0
54 lines not on this page · raw message
ip/Makefile +1 -1
@@ -3,7 +3,7 @@ IPOBJ=ip.o ipaddress.o ipaddrlabel.o ipr ipmaddr.o ipmonitor.o ipmroute.o ipprefix.o iptuntap.o \ ipxfrm.o xfrm_state.o xfrm_policy.o xfrm_monitor.o \ iplink_vlan.o link_veth.o link_gre.o iplink_can.o \ - iplink_macvlan.o iplink_macvtap.o ipl2tp.o + iplink_macvlan.o iplink_macvtap.o ipl2tp.o tcp_metrics.o RTMONOBJ=rtmon.o
ip/ip.c +3 -1
@@ -45,7 +45,7 @@ static void usage(void)" ip [ -force ] -batch filename\n" "where OBJECT := { link | addr | addrlabel | route | rule | neigh | ntable |\n" " tunnel | tuntap | maddr | mroute | mrule | monitor | xfrm |\n" -" netns | l2tp }\n" +" netns | l2tp | tcp_metrics }\n" " OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |\n" " -f[amily] { inet | inet6 | ipx | dnet | link } |\n" " -l[oops] { maximum-addr-flush-attempts } |\n"
@@ -78,6 +78,8 @@ static const struct cmd { { "tunl", do_iptunnel }, { "tuntap", do_iptuntap }, { "tap", do_iptuntap }, + { "tcpmetrics", do_tcp_metrics }, + { "tcp_metrics",do_tcp_metrics }, { "monitor", do_ipmonitor }, { "xfrm", do_xfrm }, { "mroute", do_multiroute },
ip/ip_common.h +1 -0
@@ -42,6 +42,7 @@ extern int do_multirule(int argc, char *extern int do_netns (int argc,char **argv);extern int do_xfrm (int argc,char **argv);extern int do_ipl2tp (int argc,char **argv); +extern int do_tcp_metrics (int argc,char **argv);static inline int rtm_get_table (struct rtmsg *r,struct rtattr **tb) {
ip/tcp_metrics.c +434 -0
434 lines not on this page · raw message
lib/Makefile +1 -1
@@ -2,7 +2,7 @@ CFLAGS += -fPIC UTILOBJ=utils.o rt_names.o ll_types.o ll_proto.o ll_addr.o inet_proto.o -NLOBJ=ll_map.o libnetlink.o +NLOBJ=libgenl.o ll_map.o libnetlink.o all: libnetlink.a libutil.a
lib/libgenl.c +65 -0
65 lines not on this page · raw message
man/man8/Makefile +2 -1
@@ -7,7 +7,8 @@ MAN8PAGES = $(TARGETS) ip.8 arpd.8 lnsta bridge.8 rtstat.8 ctstat.8 nstat.8 routef.8 \ ip-tunnel.8 ip-rule.8 ip-ntable.8 \ ip-monitor.8 tc-stab.8 tc-hfsc.8 ip-xfrm.8 ip-netns.8 \ - ip-neighbour.8 ip-mroute.8 ip-maddress.8 ip-addrlabel.8 + ip-neighbour.8 ip-mroute.8 ip-maddress.8 ip-addrlabel.8 \ + ip-tcp_metrics.8 all: $(TARGETS)
man/man8/ip-tcp_metrics.8 +143 -0
143 lines not on this page · raw message
man/man8/ip.8 +6 -1
@@ -15,7 +15,7 @@ ip \- show / manipulate routing, devices .IR OBJECT " := { " .BR link " | " addr " | " addrlabel " | " route " | " rule " | " neigh " | "\ ntable " | " tunnel " | " tuntap " | " maddr " | " mroute " | " mrule " | "\ - monitor " | " xfrm " | " netns " | " l2tp " }" + monitor " | " xfrm " | " netns " | " l2tp " | " tcp_metrics " }" .sp .ti -8
@@ -156,6 +156,10 @@ host addresses. - rule in routing policy database. .TP +.B tcp_metrics/tcpmetrics +- manage TCP Metrics + +.TP .B tunnel - tunnel over IP.
@@ -215,6 +219,7 @@ was written by Alexey N. Kuznetsov and a .BR ip-ntable (8), .BR ip-route (8), .BR ip-rule (8), +.BR ip-tcp_metrics (8), .BR ip-tunnel (8), .BR ip-xfrm (8) .br
PATCH v3 3/3 iproute2: use libgenl for ipl2tp
In reply to Julian Anastasov Use the common code from libgenl.c
---
ip/ipl2tp.c +3 -62
@@ -25,6 +25,7 @@#include <linux/genetlink.h> #include <linux/l2tp.h> +#include "libgenl.h" #include "utils.h" #include "ip_common.h"
@@ -747,67 +748,6 @@ static int do_show(int argc, char **argvreturn 0 ; } -static int genl_parse_getfamily (struct nlmsghdr *nlh) -{ -struct rtattr *tb[CTRL_ATTR_MAX +1 ]; -struct genlmsghdr *ghdr =NLMSG_DATA (nlh); -int len = nlh->nlmsg_len; -struct rtattr *attrs; - -if (nlh->nlmsg_type !=GENL_ID_CTRL ) { -fprintf (stderr,"Not a controller message, nlmsg_len=%d " -"nlmsg_type=0x%x\n" , nlh->nlmsg_len, nlh->nlmsg_type); -return -1 ; - } - -if (ghdr->cmd !=CTRL_CMD_NEWFAMILY ) { -fprintf (stderr,"Unknown controller command %d\n" , ghdr->cmd); -return -1 ; - } - - len -=NLMSG_LENGTH (GENL_HDRLEN ); - -if (len <0 ) { -fprintf (stderr,"wrong controller message len %d\n" , len); -return -1 ; - } - - attrs = (struct rtattr *) ((char *) ghdr +GENL_HDRLEN ); -parse_rtattr (tb,CTRL_ATTR_MAX , attrs, len); - -if (tb[CTRL_ATTR_FAMILY_ID ] ==NULL ) { -fprintf (stderr,"Missing family id TLV\n" ); -return -1 ; - } - -return rta_getattr_u16 (tb[CTRL_ATTR_FAMILY_ID ]); -} - -int genl_ctrl_resolve_family (const char *family) -{ -struct { -struct nlmsghdr n; -struct genlmsghdr g; -char buf[1024 ]; - } req; - -memset (&req,0 ,sizeof (req)); - req.n.nlmsg_len =NLMSG_LENGTH (GENL_HDRLEN ); - req.n.nlmsg_flags =NLM_F_REQUEST ; - req.n.nlmsg_type =GENL_ID_CTRL ; - req.g.cmd =CTRL_CMD_GETFAMILY ; - -addattr_l (&req.n,1024 ,CTRL_ATTR_FAMILY_NAME , - family,strlen (family) +1 ); - -if (rtnl_talk (&genl_rth, &req.n,0 ,0 , &req.n) <0 ) { -fprintf (stderr,"Error talking to the kernel\n" ); -return -2 ; - } - -return genl_parse_getfamily (&req.n); -} -int do_ipl2tp (int argc,char **argv) {if (genl_family <0 ) {
@@ -816,7 +756,8 @@ int do_ipl2tp(int argc, char **argv)exit (1 ); } - genl_family =genl_ctrl_resolve_family (L2TP_GENL_NAME ); + genl_family =libgenl_resolve_family (&genl_rth, +L2TP_GENL_NAME );if (genl_family <0 )exit (1 ); }
David Miller
maintainerRe: [PATCH v3 1/3] tcp: add generic netlink support for tcp_metrics
In reply to Julian AnastasovFrom: Julian Anastasov <[email protected]>
Date: Wed, 5 Sep 2012 00:03:15 +0300
Quoted 12 lines
Add support for genl "
tcp_metrics". No locking
is changed, only that now we can unlink and delete entries after grace period. We implement get/del for single entry and dump to support show/flush filtering in user space. Del without address attribute causes flush for all addresses, sadly undergenl_mutex.v2:
- removercu_assign_pointeras suggested by Eric Dumazet, it is not needed because there are no other writes under lock
- move the flushing code intcp_metrics_flush_all
Quoted 4 lines
v3:
- removesynchronize_rcuon flush as suggested by Eric DumazetSigned-off-by Julian Anastasov <[email protected]>
Looks great, applied to net-next, thanks Julian.
Re: [PATCH v3 2/3] iproute2: add support for tcp_metrics
In reply to Julian AnastasovCould you resubmit this as two pieces. I can take the libgenl stuff
now (and the l2tp code). The tcp metrics support in iproute2 should be resent after the kernel support for that makes it to Linus's tree. (ie 3.7 merge window).