Re: [squid-users] tcp_outgoing_tos doesn't work in 3.2?

From: Andrew Beverley <andy_at_andybev.com>
Date: Tue, 01 Jan 2013 15:15:47 +0000

On Mon, 2012-12-31 at 11:27 -0800, Nick Rogers wrote:
> On Fri, Dec 28, 2012 at 6:59 PM, Amos Jeffries <squid3_at_treenet.co.nz> wrote:
> > On 29/12/2012 3:49 p.m., Andrew Beverley wrote:
> >>
> >> On Fri, 2012-12-28 at 18:13 -0800, Nick Rogers wrote:
> >>>
> >>> I was able to come up with a patch that works in my environment by
> >>> looking at some of the changes between 3.1 and 3.2. It seems that
> >>> sizeof(tos_t) does not result in a valid setsockopt() argument,
> >>> whereas sizeof(int) that was used in 3.1.x does.
> >>
> >> Thanks for that. I vaguely remember making that change when creating the
> >> v3.2 patch set, probably for no reason other than tidying up the code.
> >> I'll have a closer look in the next couple of weeks, unless anyone else
> >> does before then.
> >
> > This is a bit of a strange error. Since the tos_t type is an 8-bit char.
> > Passing in a larger size than the object being passed means some garbage off
> > the stack will be passed to the setsockopt() internals.
>
> FWIW I've created a bug report.
>
> http://bugs.squid-cache.org/show_bug.cgi?id=3731
>
> So far the patch I mentioned has worked beautifully on my production machines.

Thanks for filing the bug report. The problem appears to be that FreeBSD
expects a TOS value as an integer, not a char. I can't find any official
documentation stating this, but I've found a couple of similar bug
reports in other software.

Therefore, could you please try the following (untested) patch? This
keeps it as a char for all other operating systems, but changes tos_t to
an integer for FreeBSD. Defining the type for all the code will
initialise the variable properly and stop garbage being passed in.

diff -rupN squid-3.2.5-20130101-r11743/src/typedefs.h squid-3.2.5-20130101-r11743-tos/src/typedefs.h
--- squid-3.2.5-20130101-r11743/src/typedefs.h 2013-01-01 05:54:59.000000000 +0000
+++ squid-3.2.5-20130101-r11743-tos/src/typedefs.h 2013-01-01 15:09:04.501850487 +0000
@@ -40,7 +40,12 @@ typedef int32_t sfileno;
 typedef signed int sdirno;
 
 typedef uint32_t nfmark_t;
-typedef unsigned char tos_t;
+/* FreeBSD requires TOS values as an integer */
+#if defined(_SQUID_FREEBSD_)
+ typedef unsigned int tos_t;
+#else
+ typedef unsigned char tos_t;
+#endif
 
 typedef struct {
     size_t bytes;

Andy
Received on Tue Jan 01 2013 - 15:16:39 MST

This archive was generated by hypermail 2.2.0 : Tue Jan 01 2013 - 12:00:10 MST