netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [[PATCH iproute2/net-next v2] 0/4] tc: flower: SCTP and other port fixes
@ 2016-12-02  8:45 Simon Horman
  2016-12-02  8:45 ` [[PATCH iproute2/net-next v2] 1/4] tc: flower: remove references to eth_type in manpage Simon Horman
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Simon Horman @ 2016-12-02  8:45 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev, Simon Horman

Hi Stephen,

this short series:

* Makes some improvements to the documentation of flower;
  A follow-up to recent work by Paul Blakey and myself.
* Corrects some errors introduced when SCTP port matching support was
  recently added.

Changes since v2:
* Rebase

Simon Horman (4):
  tc: flower: remove references to eth_type in manpage
  tc: flower: document SCTP ip_proto
  tc: flower: correct name of ip_proto parameter to flower_parse_port()
  tc: flower: make use of flower_port_attr_type() safe and silent

 man/man8/tc-flower.8 | 37 ++++++++++++++++++-------------------
 tc/f_flower.c        | 32 +++++++++++++++++---------------
 2 files changed, 35 insertions(+), 34 deletions(-)

-- 
2.7.0.rc3.207.g0ac5344

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [[PATCH iproute2/net-next v2] 1/4] tc: flower: remove references to eth_type in manpage
  2016-12-02  8:45 [[PATCH iproute2/net-next v2] 0/4] tc: flower: SCTP and other port fixes Simon Horman
@ 2016-12-02  8:45 ` Simon Horman
  2016-12-02 23:05   ` Stephen Hemminger
  2016-12-02  8:45 ` [[PATCH iproute2/net-next v2] 2/4] tc: flower: document SCTP ip_proto Simon Horman
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Simon Horman @ 2016-12-02  8:45 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev, Simon Horman, Paul Blakey

Remove references to eth_type and ether_type (spelling error) in
the tc flower manpage.

Also correct formatting of boldface text with whitespace.

Cc: Paul Blakey <paulb@mellanox.com>
Signed-off-by: Simon Horman <simon.horman@netronome.com>
---
 man/man8/tc-flower.8 | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/man/man8/tc-flower.8 b/man/man8/tc-flower.8
index 16ef261797ab..56db42f983c1 100644
--- a/man/man8/tc-flower.8
+++ b/man/man8/tc-flower.8
@@ -103,8 +103,8 @@ or an unsigned 8bit value in hexadecimal format.
 Match on source or destination IP address.
 .I ADDRESS
 must be a valid IPv4 or IPv6 address, depending on
-.BR ether_type ,
-which has to be specified in beforehand.
+.BR protocol
+option of tc filter.
 .TP
 .BI dst_port " NUMBER"
 .TQ
@@ -114,16 +114,15 @@ Match on layer 4 protocol source or destination port number. Only available for
 which has to be specified in beforehand.
 .SH NOTES
 As stated above where applicable, matches of a certain layer implicitly depend
-on the matches of the next lower layer. Precisely, layer one and two matches (
-.BR indev , dst_mac , src_mac " and " eth_type )
-have no dependency, layer three matches (
-.BR ip_proto , dst_ip " and " src_ip )
-require
-.B eth_type
-being set to either
-.BR ipv4 " or " ipv6 ,
-and finally layer four matches (
-.BR dst_port " and " src_port )
+on the matches of the next lower layer. Precisely, layer one and two matches
+(\fBindev\fR,  \fBdst_mac\fR and \fBsrc_mac\fR)
+have no dependency, layer three matches
+(\fBip_proto\fR, \fBdst_ip\fR and \fBsrc_ip\fR)
+depend on the
+.B protocol
+option of tc filter
+and finally layer four matches
+(\fBdst_port\fR and \fBsrc_port\fR)
 depend on
 .B ip_proto
 being set to either
-- 
2.7.0.rc3.207.g0ac5344

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [[PATCH iproute2/net-next v2] 2/4] tc: flower: document SCTP ip_proto
  2016-12-02  8:45 [[PATCH iproute2/net-next v2] 0/4] tc: flower: SCTP and other port fixes Simon Horman
  2016-12-02  8:45 ` [[PATCH iproute2/net-next v2] 1/4] tc: flower: remove references to eth_type in manpage Simon Horman
@ 2016-12-02  8:45 ` Simon Horman
  2016-12-02 23:06   ` Stephen Hemminger
  2016-12-02  8:45 ` [[PATCH iproute2/net-next v2] 3/4] tc: flower: correct name of ip_proto parameter to flower_parse_port() Simon Horman
  2016-12-02  8:45 ` [[PATCH iproute2/net-next v2] 4/4] tc: flower: make use of flower_port_attr_type() safe and silent Simon Horman
  3 siblings, 1 reply; 8+ messages in thread
From: Simon Horman @ 2016-12-02  8:45 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev, Simon Horman

Add SCTP ip_proto to help text and man page.

Signed-off-by: Simon Horman <simon.horman@netronome.com>
---
 man/man8/tc-flower.8 | 14 +++++++-------
 tc/f_flower.c        |  2 +-
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/man/man8/tc-flower.8 b/man/man8/tc-flower.8
index 56db42f983c1..a401293fed50 100644
--- a/man/man8/tc-flower.8
+++ b/man/man8/tc-flower.8
@@ -29,7 +29,7 @@ flower \- flow based traffic control filter
 .IR PRIORITY " | "
 .BR vlan_eth_type " { " ipv4 " | " ipv6 " | "
 .IR ETH_TYPE " } | "
-.BR ip_proto " { " tcp " | " udp " | "
+.BR ip_proto " { " tcp " | " udp " | " sctp " | "
 .IR IP_PROTO " } | { "
 .BR dst_ip " | " src_ip " } { "
 .IR ipv4_address " | " ipv6_address " } | { "
@@ -93,8 +93,8 @@ or an unsigned 16bit value in hexadecimal format.
 .BI ip_proto " IP_PROTO"
 Match on layer four protocol.
 .I IP_PROTO
-may be either
-.BR tcp , udp
+may be
+.BR tcp ", " udp ", " sctp
 or an unsigned 8bit value in hexadecimal format.
 .TP
 .BI dst_ip " ADDRESS"
@@ -110,8 +110,8 @@ option of tc filter.
 .TQ
 .BI src_port " NUMBER"
 Match on layer 4 protocol source or destination port number. Only available for
-.BR ip_proto " values " udp " and " tcp ,
-which has to be specified in beforehand.
+.BR ip_proto " values " udp ", " tcp  " and " sctp
+which have to be specified in beforehand.
 .SH NOTES
 As stated above where applicable, matches of a certain layer implicitly depend
 on the matches of the next lower layer. Precisely, layer one and two matches
@@ -125,8 +125,8 @@ and finally layer four matches
 (\fBdst_port\fR and \fBsrc_port\fR)
 depend on
 .B ip_proto
-being set to either
-.BR tcp " or " udp .
+being set to
+.BR tcp ", " udp " or " sctp.
 .P
 There can be only used one mask per one prio. If user needs to specify different
 mask, he has to use different prio.
diff --git a/tc/f_flower.c b/tc/f_flower.c
index 1555764b9996..dacf24faf00e 100644
--- a/tc/f_flower.c
+++ b/tc/f_flower.c
@@ -37,7 +37,7 @@ static void explain(void)
 		"                       vlan_ethtype [ ipv4 | ipv6 | ETH-TYPE ] |\n"
 		"                       dst_mac MAC-ADDR |\n"
 		"                       src_mac MAC-ADDR |\n"
-		"                       ip_proto [tcp | udp | IP-PROTO ] |\n"
+		"                       ip_proto [tcp | udp | sctp | IP-PROTO ] |\n"
 		"                       dst_ip [ IPV4-ADDR | IPV6-ADDR ] |\n"
 		"                       src_ip [ IPV4-ADDR | IPV6-ADDR ] |\n"
 		"                       dst_port PORT-NUMBER |\n"
-- 
2.7.0.rc3.207.g0ac5344

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [[PATCH iproute2/net-next v2] 3/4] tc: flower: correct name of ip_proto parameter to flower_parse_port()
  2016-12-02  8:45 [[PATCH iproute2/net-next v2] 0/4] tc: flower: SCTP and other port fixes Simon Horman
  2016-12-02  8:45 ` [[PATCH iproute2/net-next v2] 1/4] tc: flower: remove references to eth_type in manpage Simon Horman
  2016-12-02  8:45 ` [[PATCH iproute2/net-next v2] 2/4] tc: flower: document SCTP ip_proto Simon Horman
@ 2016-12-02  8:45 ` Simon Horman
  2016-12-02  8:45 ` [[PATCH iproute2/net-next v2] 4/4] tc: flower: make use of flower_port_attr_type() safe and silent Simon Horman
  3 siblings, 0 replies; 8+ messages in thread
From: Simon Horman @ 2016-12-02  8:45 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev, Simon Horman

This corrects a typo.

Fixes: a1fb0d484237 ("tc: flower: Support matching on SCTP ports")
Signed-off-by: Simon Horman <simon.horman@netronome.com>
---
 tc/f_flower.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/tc/f_flower.c b/tc/f_flower.c
index dacf24faf00e..d86ccdc3d3f0 100644
--- a/tc/f_flower.c
+++ b/tc/f_flower.c
@@ -160,15 +160,15 @@ static int flower_parse_ip_addr(char *str, __be16 eth_type,
 	return 0;
 }
 
-static int flower_port_attr_type(__u8 ip_port, bool is_src)
+static int flower_port_attr_type(__u8 ip_proto, bool is_src)
 {
-	if (ip_port == IPPROTO_TCP) {
+	if (ip_proto == IPPROTO_TCP) {
 		return is_src ? TCA_FLOWER_KEY_TCP_SRC :
 			TCA_FLOWER_KEY_TCP_DST;
-	} else if (ip_port == IPPROTO_UDP) {
+	} else if (ip_proto == IPPROTO_UDP) {
 		return is_src ? TCA_FLOWER_KEY_UDP_SRC :
 			TCA_FLOWER_KEY_UDP_DST;
-	} else if (ip_port == IPPROTO_SCTP) {
+	} else if (ip_proto == IPPROTO_SCTP) {
 		return is_src ? TCA_FLOWER_KEY_SCTP_SRC :
 			TCA_FLOWER_KEY_SCTP_DST;
 	} else {
@@ -177,14 +177,14 @@ static int flower_port_attr_type(__u8 ip_port, bool is_src)
 	}
 }
 
-static int flower_parse_port(char *str, __u8 ip_port, bool is_src,
+static int flower_parse_port(char *str, __u8 ip_proto, bool is_src,
 			     struct nlmsghdr *n)
 {
 	int ret;
 	int type;
 	__be16 port;
 
-	type = flower_port_attr_type(ip_port, is_src);
+	type = flower_port_attr_type(ip_proto, is_src);
 	if (type < 0)
 		return -1;
 
-- 
2.7.0.rc3.207.g0ac5344

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [[PATCH iproute2/net-next v2] 4/4] tc: flower: make use of flower_port_attr_type() safe and silent
  2016-12-02  8:45 [[PATCH iproute2/net-next v2] 0/4] tc: flower: SCTP and other port fixes Simon Horman
                   ` (2 preceding siblings ...)
  2016-12-02  8:45 ` [[PATCH iproute2/net-next v2] 3/4] tc: flower: correct name of ip_proto parameter to flower_parse_port() Simon Horman
@ 2016-12-02  8:45 ` Simon Horman
  3 siblings, 0 replies; 8+ messages in thread
From: Simon Horman @ 2016-12-02  8:45 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev, Simon Horman

Make use of flower_port_attr_type() safe:
* flower_port_attr_type() may return a valid index into tb[] or -1.
  Only access tb[] in the case of the former.
* Do not access null entries in tb[]

Also make usage silent - it is valid for ip_proto to be invalid,
for example if it is not specified as part of the filter.

Fixes: a1fb0d484237 ("tc: flower: Support matching on SCTP ports")
Signed-off-by: Simon Horman <simon.horman@netronome.com>
---
 tc/f_flower.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/tc/f_flower.c b/tc/f_flower.c
index d86ccdc3d3f0..615e8f27bed2 100644
--- a/tc/f_flower.c
+++ b/tc/f_flower.c
@@ -162,19 +162,17 @@ static int flower_parse_ip_addr(char *str, __be16 eth_type,
 
 static int flower_port_attr_type(__u8 ip_proto, bool is_src)
 {
-	if (ip_proto == IPPROTO_TCP) {
+	if (ip_proto == IPPROTO_TCP)
 		return is_src ? TCA_FLOWER_KEY_TCP_SRC :
 			TCA_FLOWER_KEY_TCP_DST;
-	} else if (ip_proto == IPPROTO_UDP) {
+	else if (ip_proto == IPPROTO_UDP)
 		return is_src ? TCA_FLOWER_KEY_UDP_SRC :
 			TCA_FLOWER_KEY_UDP_DST;
-	} else if (ip_proto == IPPROTO_SCTP) {
+	else if (ip_proto == IPPROTO_SCTP)
 		return is_src ? TCA_FLOWER_KEY_SCTP_SRC :
 			TCA_FLOWER_KEY_SCTP_DST;
-	} else {
-		fprintf(stderr, "Illegal \"ip_proto\" for port\n");
+	else
 		return -1;
-	}
 }
 
 static int flower_parse_port(char *str, __u8 ip_proto, bool is_src,
@@ -511,7 +509,8 @@ static void flower_print_ip_addr(FILE *f, char *name, __be16 eth_type,
 
 static void flower_print_port(FILE *f, char *name, struct rtattr *attr)
 {
-	fprintf(f, "\n  %s %d", name, ntohs(rta_getattr_u16(attr)));
+	if (attr)
+		fprintf(f, "\n  %s %d", name, ntohs(rta_getattr_u16(attr)));
 }
 
 static int flower_print_opt(struct filter_util *qu, FILE *f,
@@ -520,6 +519,7 @@ static int flower_print_opt(struct filter_util *qu, FILE *f,
 	struct rtattr *tb[TCA_FLOWER_MAX + 1];
 	__be16 eth_type = 0;
 	__u8 ip_proto = 0xff;
+	int nl_type;
 
 	if (!opt)
 		return 0;
@@ -574,10 +574,12 @@ static int flower_print_opt(struct filter_util *qu, FILE *f,
 			     tb[TCA_FLOWER_KEY_IPV6_SRC],
 			     tb[TCA_FLOWER_KEY_IPV6_SRC_MASK]);
 
-	flower_print_port(f, "dst_port",
-			  tb[flower_port_attr_type(ip_proto, false)]);
-	flower_print_port(f, "src_port",
-			  tb[flower_port_attr_type(ip_proto, true)]);
+	nl_type = flower_port_attr_type(ip_proto, false);
+	if (nl_type >= 0)
+		flower_print_port(f, "dst_port", tb[nl_type]);
+	nl_type = flower_port_attr_type(ip_proto, true);
+	if (nl_type >= 0)
+		flower_print_port(f, "src_port", tb[nl_type]);
 
 	if (tb[TCA_FLOWER_FLAGS]) {
 		__u32 flags = rta_getattr_u32(tb[TCA_FLOWER_FLAGS]);
-- 
2.7.0.rc3.207.g0ac5344

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [[PATCH iproute2/net-next v2] 1/4] tc: flower: remove references to eth_type in manpage
  2016-12-02  8:45 ` [[PATCH iproute2/net-next v2] 1/4] tc: flower: remove references to eth_type in manpage Simon Horman
@ 2016-12-02 23:05   ` Stephen Hemminger
  0 siblings, 0 replies; 8+ messages in thread
From: Stephen Hemminger @ 2016-12-02 23:05 UTC (permalink / raw)
  To: Simon Horman; +Cc: netdev, Paul Blakey

On Fri,  2 Dec 2016 09:45:18 +0100
Simon Horman <simon.horman@netronome.com> wrote:

> Remove references to eth_type and ether_type (spelling error) in
> the tc flower manpage.
> 
> Also correct formatting of boldface text with whitespace.
> 
> Cc: Paul Blakey <paulb@mellanox.com>
> Signed-off-by: Simon Horman <simon.horman@netronome.com>

Applied this one. Later ones still need rebase.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [[PATCH iproute2/net-next v2] 2/4] tc: flower: document SCTP ip_proto
  2016-12-02  8:45 ` [[PATCH iproute2/net-next v2] 2/4] tc: flower: document SCTP ip_proto Simon Horman
@ 2016-12-02 23:06   ` Stephen Hemminger
  2016-12-03  8:53     ` Simon Horman
  0 siblings, 1 reply; 8+ messages in thread
From: Stephen Hemminger @ 2016-12-02 23:06 UTC (permalink / raw)
  To: Simon Horman; +Cc: netdev

On Fri,  2 Dec 2016 09:45:19 +0100
Simon Horman <simon.horman@netronome.com> wrote:

> Add SCTP ip_proto to help text and man page.
> 
> Signed-off-by: Simon Horman <simon.horman@netronome.com>

This doesn't apply cleanly to current net-next git.
Probably some of the other man page changes caused reject.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [[PATCH iproute2/net-next v2] 2/4] tc: flower: document SCTP ip_proto
  2016-12-02 23:06   ` Stephen Hemminger
@ 2016-12-03  8:53     ` Simon Horman
  0 siblings, 0 replies; 8+ messages in thread
From: Simon Horman @ 2016-12-03  8:53 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

On Fri, Dec 02, 2016 at 03:06:08PM -0800, Stephen Hemminger wrote:
> On Fri,  2 Dec 2016 09:45:19 +0100
> Simon Horman <simon.horman@netronome.com> wrote:
> 
> > Add SCTP ip_proto to help text and man page.
> > 
> > Signed-off-by: Simon Horman <simon.horman@netronome.com>
> 
> This doesn't apply cleanly to current net-next git.
> Probably some of the other man page changes caused reject.

Thanks, rebased and posted v3.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-12-03  8:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-02  8:45 [[PATCH iproute2/net-next v2] 0/4] tc: flower: SCTP and other port fixes Simon Horman
2016-12-02  8:45 ` [[PATCH iproute2/net-next v2] 1/4] tc: flower: remove references to eth_type in manpage Simon Horman
2016-12-02 23:05   ` Stephen Hemminger
2016-12-02  8:45 ` [[PATCH iproute2/net-next v2] 2/4] tc: flower: document SCTP ip_proto Simon Horman
2016-12-02 23:06   ` Stephen Hemminger
2016-12-03  8:53     ` Simon Horman
2016-12-02  8:45 ` [[PATCH iproute2/net-next v2] 3/4] tc: flower: correct name of ip_proto parameter to flower_parse_port() Simon Horman
2016-12-02  8:45 ` [[PATCH iproute2/net-next v2] 4/4] tc: flower: make use of flower_port_attr_type() safe and silent Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).