netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [iproute PATCH] iproute: restrict hoplimit values to be in range [1;255]
@ 2015-11-10 12:54 Phil Sutter
  2015-11-23 23:48 ` Stephen Hemminger
  0 siblings, 1 reply; 3+ messages in thread
From: Phil Sutter @ 2015-11-10 12:54 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

Technically, the range of possible hoplimit values are defined by IPv4
and IPv6 header formats. Both define the field to be eight bits in size,
which leads to a value range of [0;255]. Setting a packet's hoplimit
field to 0 though makes not much sense, as the next hop would
immediately drop the packet. Therefore Linux uses 0 as a special value
indicating to use the system's default hoplimit (configurable via
sysctl). In iproute, setting the hoplimit of a route to 0 is equivalent
to omitting the hoplimit parameter alltogether, so it is not necessary
to allow that value to be specified.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 ip/iproute.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/ip/iproute.c b/ip/iproute.c
index c0ef7bf..e0c8e4c 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -931,7 +931,8 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
 				mxlock |= (1<<RTAX_HOPLIMIT);
 				NEXT_ARG();
 			}
-			if (get_unsigned(&hoplimit, *argv, 0))
+			if (get_unsigned(&hoplimit, *argv, 0) ||
+			    hoplimit < 1 || hoplimit > 255)
 				invarg("\"hoplimit\" value is invalid\n", *argv);
 			rta_addattr32(mxrta, sizeof(mxbuf), RTAX_HOPLIMIT, hoplimit);
 		} else if (strcmp(*argv, "advmss") == 0) {
-- 
2.1.2

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

* Re: [iproute PATCH] iproute: restrict hoplimit values to be in range [1;255]
  2015-11-10 12:54 [iproute PATCH] iproute: restrict hoplimit values to be in range [1;255] Phil Sutter
@ 2015-11-23 23:48 ` Stephen Hemminger
  2015-11-24 14:45   ` [iproute PATCH v2] iproute: restrict hoplimit values to be in range [0;255] Phil Sutter
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Hemminger @ 2015-11-23 23:48 UTC (permalink / raw)
  To: Phil Sutter; +Cc: netdev

On Tue, 10 Nov 2015 13:54:09 +0100
Phil Sutter <phil@nwl.cc> wrote:

> Technically, the range of possible hoplimit values are defined by IPv4
> and IPv6 header formats. Both define the field to be eight bits in size,
> which leads to a value range of [0;255]. Setting a packet's hoplimit
> field to 0 though makes not much sense, as the next hop would
> immediately drop the packet. Therefore Linux uses 0 as a special value
> indicating to use the system's default hoplimit (configurable via
> sysctl). In iproute, setting the hoplimit of a route to 0 is equivalent
> to omitting the hoplimit parameter alltogether, so it is not necessary
> to allow that value to be specified.
> 
> Signed-off-by: Phil Sutter <phil@nwl.cc>

Even though it doesn't make much sense to set hoplimit of 0;
I am concerned that some user is doing that now, and changing this
would break a working (but not optimum or sane) configuration.
Especially if actual config is auto-generated.

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

* [iproute PATCH v2] iproute: restrict hoplimit values to be in range [0;255]
  2015-11-23 23:48 ` Stephen Hemminger
@ 2015-11-24 14:45   ` Phil Sutter
  0 siblings, 0 replies; 3+ messages in thread
From: Phil Sutter @ 2015-11-24 14:45 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

Technically, the range of possible hoplimit values are defined by IPv4
and IPv6 header formats. Both define the field to be eight bits in size,
which leads to a value range of [0;255]. Setting a packet's hoplimit
field to 0 though makes not much sense, as the next hop would
immediately drop the packet. Therefore Linux uses 0 as a special value
indicating to use the system's default hoplimit (configurable via
sysctl). In iproute, setting the hoplimit of a route to 0 is equivalent
to omitting the hoplimit parameter alltogether, so it is actually not
necessary to allow that value to be specified, but keep it anyway for
backwards compatibility.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
Changes since v1:
- Allow hoplimit 0 for backwards compatibility.
- Adjust commit message accordingly.
---
 ip/iproute.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ip/iproute.c b/ip/iproute.c
index c0ef7bf..aed1038 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -931,7 +931,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
 				mxlock |= (1<<RTAX_HOPLIMIT);
 				NEXT_ARG();
 			}
-			if (get_unsigned(&hoplimit, *argv, 0))
+			if (get_unsigned(&hoplimit, *argv, 0) || hoplimit > 255)
 				invarg("\"hoplimit\" value is invalid\n", *argv);
 			rta_addattr32(mxrta, sizeof(mxbuf), RTAX_HOPLIMIT, hoplimit);
 		} else if (strcmp(*argv, "advmss") == 0) {
-- 
2.5.0

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

end of thread, other threads:[~2015-11-24 14:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-10 12:54 [iproute PATCH] iproute: restrict hoplimit values to be in range [1;255] Phil Sutter
2015-11-23 23:48 ` Stephen Hemminger
2015-11-24 14:45   ` [iproute PATCH v2] iproute: restrict hoplimit values to be in range [0;255] Phil Sutter

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).