Re: lapi: Add pkt_cls.h fallback

Cyril Hrubis <[email protected]>
Newsgroups gmane.linux.ltp
Message-ID <[email protected]>
Hi!
>   TCA_PEDIT_UNSPEC  = 0
>   TCA_PEDIT_TM      = 1
>   TCA_PEDIT_PARMS   = 2
>   TCA_PEDIT_PAD     = 3   <-- 3 is PAD, not KEY_EX
>   TCA_PEDIT_PARMS_EX = 4
>   TCA_PEDIT_KEYS_EX  = 5
>   TCA_PEDIT_KEY_EX   = 6  <-- should be 6
> 
> With value 3 the kernel would receive a TCA_PEDIT_PAD attribute where
> TCA_PEDIT_KEY_EX is expected and reject the filter with "Unknown
> attribute, expected extended key".
> 
> This also breaks the test in patch 4/4 which uses TCA_PEDIT_KEY_EX
> as a netlink attribute type.
> 
> > +#ifndef TCA_PEDIT_PARMS_EX
> > +# define TCA_PEDIT_PARMS_EX		4
> > +#endif
> > +
> > +#ifndef TCA_PEDIT_KEYS_EX
> > +# define TCA_PEDIT_KEYS_EX		5
> > +#endif
> > +
> > +#ifndef TCA_PEDIT_KEY_EX
> > +# define TCA_PEDIT_KEY_EX		3
> > +#endif
> > +
> > +#ifndef TCA_PEDIT_KEY_EX_HTYPE
> > +# define TCA_PEDIT_KEY_EX_HTYPE		1
> > +#endif
> > +
> > +#ifndef TCA_PEDIT_KEY_EX_CMD
> > +# define TCA_PEDIT_KEY_EX_CMD		2
> > +#endif
> 
> All five of these are anonymous enum values in the kernel header, not
> preprocessor macros. A #ifndef guard tests the preprocessor symbol
> table, which does not include enum constants. So every one of these
> #define lines executes unconditionally even on systems that already
> have the full kernel header -- the enum values are silently shadowed
> by the macros.
> 
> For the four correctly-valued ones this has no observable impact
> today, but the guard gives a false sense of safety. For
> TCA_PEDIT_KEY_EX the wrong value makes the situation permanent on
> every system.
> 
> The correct approach for enum-valued constants is to use
> AC_CHECK_DECLS in configure.ac, the same way this patch already uses
> AC_CHECK_TYPES for the two enum types:
> 
>   AC_CHECK_DECLS([TCA_PEDIT_PARMS_EX, TCA_PEDIT_KEYS_EX,
>                   TCA_PEDIT_KEY_EX, TCA_PEDIT_KEY_EX_HTYPE,
>                   TCA_PEDIT_KEY_EX_CMD],,,[
>   #include <linux/tc_act/tc_pedit.h>])

Maybe we can use the TCA_PEDIT_MAX:

#if !defined(TCA_PEDI_MAX) || TCA_PEDIT_MAX < 4
# define TCA_PEDIT_PARMS_EX 4
#endif

#if !defined(TCA_PEDI_MAX) || TCA_PEDIT_MAX < 5
# define TCA_PEDIT_KEYS_EX 5
#endif

And we can use the same pattern with the rest of the enums. 

-- 
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.